PageSourceSearch

https://vc.ru/assets/index-C30mbp0T.js

js vc.ru collected 2026-09-24 07:40:20 UTC 18,266 bytes, 9 lines download raw bytes

1var $=Object.defineProperty;var _=s=>{throw TypeError(s)};var j=(s,t,e)=>t in s?$(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var M=(s,t,e)=>j(s,typeof t!="symbol"?t+"":t,e),K=(s,t,e)=>t.has(s)||_("Cannot "+e);var p=(s,t,e)=>(K(s,t,"read from private field"),e?e.call(s):t.get(s)),B=(s,t,e)=>t.has(s)?_("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(s):t.set(s,e);import{aT as z,r as m,bs as S,eM as O,bR as b,eN as W,eO as v,eP as G,eQ as Y,eR as V,eS as X,eT as q,eU as J,eV as N,eJ as A,eW as Q,eX as k,eY as Z}from"./index-DcSVvNrM.js";const Se=()=>z();function ee(){const s=m(null),t=m([]),e=m(null),r=m({}),n=m(null),i=m(null),o=m(0);return{get energy(){return s.value},set energy(a){s.value=a},get chats(){return t.value},set chats(a){t.value=a},get chatsCursor(){return e.value},set chatsCursor(a){e.value=a},get messagesByChatId(){return r.value},set messagesByChatId(a){r.value=a},get chatsMemory(){return n.value},set chatsMemory(a){n.value=a},get settings(){return i.value},set settings(a){i.value=a},get sessionEpoch(){return o.value},setMessages(a,h){r.value={...r.value,[a]:h}},clear(){s.value=null,t.value=[],e.value=null,r.value={},n.value=null,i.value=null,o.value+=1}}}var d;class te{constructor(){B(this,d,ee())}getEnergyBalance(){return p(this,d).energy}setEnergyBalance(t){p(this,d).energy=t}getChats(){return p(this,d).chats}setChats(t){p(this,d).chats=t}getChatsCursor(){return p(this,d).chatsCursor}setChatsCursor(t){p(this,d).chatsCursor=t}getMessages(t){return p(this,d).messagesByChatId[t]??[]}setMessages(t,e){p(this,d).setMessages(t,e)}getChatsMemory(){return p(this,d).chatsMemory}setChatsMemory(t){p(this,d).chatsMemory=t}getSettings(){return p(this,d).settings}setSettings(t){p(this,d).settings=t}getSessionEpoch(){return p(this,d).sessionEpoch}clear(){p(this,d).clear()}}d=new WeakMap;function x(s){return"andropov"in s}function se(s){const t=s.data.type.toLowerCase().replace(/^image\//,"").replace(/^\./,"");return`image/${t==="jpg"?"jpeg":t}`}function re(s){const t=s.data.filename,e=s.data.type.toLowerCase();return O(t)===".pdf"||e==="pdf"||e==="application/pdf"}function Ce(s){return s.type===S.Image?{andropov:s}:s.type===S.File&&re(s)?{andropov:s}:null}function F(s){if(x(s)){const{andropov:t}=s;if(t.type===S.Image){const e=se(t);return{type:"image",filename:`image.${e.replace("image/","")}`,mediaType:e,andropov:t}}return{type:"document",filename:t.data.filename.length>0?t.data.filename:"document.pdf",mediaType:"application/pdf",andropov:t}}return{type:s.type,filename:s.filename??"",mediaType:s.media_type}}function ne(s){return x(s)?s.andropov.type!==S.Image?"":b({uuid:s.andropov.data.uuid,format:"raw"}):s.type!=="image"?"":s.url!==void 0&&s.url.length>0?s.url:s.data!==void 0&&s.data.length>0?`data:${s.media_type};base64,${s.data}`:""}function Me(s,t){return s.andropov!==void 0&&s.andropov.type===S.Image?b({uuid:s.andropov.data.uuid,format:"raw"}):t!==void 0?ne(t):""}function ve(s,t){const e=O(s).replace(".","");if(e.length>0)return e.toUpperCase();if(t==="application/pdf")return"PDF";const r=t.split("/")[1];return r!==void 0&&r.length>0?r.toUpperCase():"FILE"}function ie(s){if(s===null||typeof s!="object")return;const t=s,e=t.data;if(e===null||typeof e!="object"||Array.isArray(e))return;const r=e;if((typeof r.uuid=="string"?r.uuid:"").length!==0&&(t.type===S.Image||t.type===S.File))return s}function E(s){if(s.attachments!==void 0&&s.attachments.length>0)return s.attachments;const t=[];for(const e of s.metadata)e.andropov!==void 0&&t.push({andropov:e.andropov});return t}function oe(s){if(!Array.isArray(s))return[];const t=[];for(const e of s){if(e===null||typeof e!="object")continue;const r=e,n=ie(r.andropov),i=r.type,o=typeof r.filename=="string"?r.filename:"",a=typeof r.mediaType=="string"?r.mediaType:"",h=typeof r.media_type=="string"?r.media_type:"",l=a.length>0?a:h;if(n!==void 0){const c=F({andropov:n});t.push({...c,filename:o.length>0?o:c.filename,mediaType:l.length>0?l:c.mediaType,type:i==="image"||i==="document"?i:c.type});continue}i!=="image"&&i!=="document"||t.push({type:i,filename:o,mediaType:l})}return t}function ae(s){let t="",e=!1,r="message",n=[],i;function o(){if(n.length===0){r="message",i=void 0;return}s({event:r,data:n.join(`
2`),id:i}),r="message",n=[],i=void 0}function a(l){if(l.length===0){o();return}if(l.startsWith(":"))return;const c=l.indexOf(":");let u,g;switch(c===-1?(u=l,g=""):(u=l.slice(0,c),g=l.slice(c+1),g.startsWith(" ")&&(g=g.slice(1))),u){case"event":r=g;break;case"data":n.push(g);break;case"id":i=g;break}}function h(l,c){const g=l.replaceAll(`\r
3`,`
4`).replaceAll("\r",`
5`).split(`
6`);c?t=g.pop()??"":t="";for(const f of g)a(f)}return{push(l){let c=l;e&&(c.startsWith(`
7`)&&(c=c.slice(1)),t+=`
8`,e=!1),t+=c,t.endsWith("\r")&&(e=!0,t=t.slice(0,-1)),h(t,!0)},end(){e&&(t+=`
9`,e=!1),t.length>0&&h(t,!1),o()}}}
9async function he(s,t){const e=s.getReader(),r=new TextDecoder,n=ae(t);let i=!1;try{for(;;){const{done:o,value:a}=await e.read();if(o){n.push(r.decode()),n.end();return}n.push(r.decode(a,{stream:!0}))}}catch(o){throw i=!0,o}finally{if(i)try{await e.cancel()}catch{}else e.releaseLock()}}class C extends Error{}const T={apiVersion:"v2.5",auth:"strict"};function y(s){return{...T,abortToken:s}}function ue(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`00000000-0000-4000-8000-${Date.now().toString(16).padStart(12,"0")}`}function ce(s,t,e){let r;try{r=JSON.parse(s.data)}catch{throw new Error(`Invalid stream event data: ${s.data}`)}if(s.event==="delta"){const n=r.text??"";n.length>0&&(t.content+=n,e==null||e(t.content));return}if(s.event==="done"){t.sawDone=!0;return}if(s.event==="error")throw new Error(r.message??"Stream error")}function w(s,t){const e=typeof(s==null?void 0:s.defaultModel)=="string"&&s.defaultModel.length>0?s.defaultModel:(t==null?void 0:t.defaultModel)??A,r=typeof(s==null?void 0:s.instruction)=="string"?s.instruction:(t==null?void 0:t.instruction)??"";return{defaultModel:e,instruction:r}}async function le(s,t){const e={content:"",sawDone:!1};if(await he(s,r=>{ce(r,e,t)}),!e.sawDone)throw new Error("Stream ended without done event");return{content:e.content}}function ge(s){return s instanceof DOMException&&s.name==="AbortError"||s instanceof Error&&s.name==="AbortError"}function de(s){const t=[];for(let e=0;e<s.length;e++){const r=s[e];if(r.isPending===!0){const n=s[e-1];r.role==="assistant"&&n!==void 0&&n.role==="user"&&n.localId!==void 0&&!t.includes(n)&&t.push(n),t.push(r);continue}r.isError===!0&&t.push(r)}return t}class pe extends W{constructor(e,r){super();M(this,"streamGeneration",0);M(this,"abortedGeneration",0);M(this,"messagesLoadByChatUuid",new Map);M(this,"loadedMessageChatUuids",new Set);this.transport=e,this.createStore=r}async refreshEnergyBalance(){const e=this.getSessionGeneration(),r=await this.transport.get("terminal/energy-balance",void 0,y(V));return this.isCurrentSession(e)&&this.store.setEnergyBalance(r),r}getEnergyBalance(){return this.store.getEnergyBalance()}async reportLlmUsage(e){await this.transport.post("terminal/llm-usage",e,y(Q))}async loadChats(e,r=!1){const n=this.getSessionGeneration(),i=e==null?void 0:{cursor:e},o=await this.transport.get("terminal/chats",i,y(X)),a=o.items??[],h=o.cursor??null;if(!this.isCurrentSession(n))return{items:a,cursor:h};if(r||e===void 0||e===null)this.store.setChats(a);else{const l=this.store.getChats(),c=new Set(l.map(g=>g.uuid)),u=[...l,...a.filter(g=>!c.has(g.uuid))];this.store.setChats(u)}return this.store.setChatsCursor(h),{items:a,cursor:h}}getChats(){return this.store.getChats()}getChatsCursor(){return this.store.getChatsCursor()}createChat(e={}){const r={uuid:e.uuid??ue(),userId:0,name:e.name??null,dateCreated:null,dateLastModified:null};return this.upsertChat(r),r}upsertChat(e){const r=this.store.getChats();this.store.setChats([e,...r.filter(n=>n.uuid!==e.uuid)])}async refreshChat(e){var u;const r=this.getSessionGeneration(),o=((await this.transport.get("terminal/chats",void 0,y(q))).items??[]).find(g=>g.uuid===e);if(o===void 0)return null;if(!this.isCurrentSession(r))return o;const a=this.store.getChats(),h=a.find(g=>g.uuid===e),l=((u=o.name)==null?void 0:u.trim())??"",c={...o,name:l.length>0?o.name:(h==null?void 0:h.name)??o.name};return h===void 0?this.upsertChat(c):this.store.setChats(a.map(g=>g.uuid!==e?g:c)),c}async loadMessages(e){const r=this.messagesLoadByChatUuid.get(e);if(r!==void 0)return await r;const n=this.fetchAndApplyMessages(e);this.messagesLoadByChatUuid.set(e,n);try{return await n}finally{this.messagesLoadByChatUuid.get(e)===n&&this.messagesLoadByChatUuid.delete(e)}}async ensureMessagesLoaded(e,r=!1){const n=this.messagesLoadByChatUuid.get(e);if(n!==void 0){await n;return}r||this.loadedMessageChatUuids.has(e)||await this.loadMessages(e)}async fetchAndApplyMessages(e){const r=this.getSessionGeneration(),i=((await this.transport.get(`terminal/chats/${e}/messages`,void 0,y(J))).items??[]).map(o=>({...o,metadata:oe(o.metadata)}));
9if(this.isCurrentSession(r)){const o=de(this.store.getMessages(e));this.store.setMessages(e,o.length>0?[...i,...o]:i),this.loadedMessageChatUuids.add(e)}return{items:i}}getMessages(e){return this.store.getMessages(e)}setMessages(e,r){this.store.setMessages(e,r)}async stream(e,r){const n=this.getSessionGeneration(),i=++this.streamGeneration;if(this.transport.abort(v),i<=this.abortedGeneration||!this.isCurrentSession(n))throw new C;try{const o=await this.transport.post("terminal/stream",e,{...T,abortToken:v,headers:{"Content-Type":"application/json",Accept:"text/event-stream"}});if(i<=this.abortedGeneration||!this.isCurrentSession(n))throw await this.cancelStreamBody(o),new C;return await le(o,a=>{this.isCurrentSession(n)&&(r==null||r(a))})}catch(o){throw o instanceof C?o:i<=this.abortedGeneration||!this.isCurrentSession(n)||ge(o)?new C:o}}async stopStream(e){if(this.abortedGeneration=Math.max(this.streamGeneration,1),this.transport.abort(v),e.chatId.length!==0)try{await this.transport.post("terminal/stream/stop",e,{...T,headers:{"Content-Type":"application/json"}})}catch(r){console.error(r)}}async cancelStreamBody(e){try{await e.cancel()}catch{}}async refreshChatsMemory(){const e=this.getSessionGeneration(),r=await this.transport.get("terminal/chats-memory",void 0,y(N));return this.isCurrentSession(e)&&this.store.setChatsMemory(r),r}getChatsMemory(){return this.store.getChatsMemory()}async removeChatsMemory(){const e=this.getSessionGeneration();await this.transport.post("terminal/chats-memory/remove",void 0,y(N)),this.isCurrentSession(e)&&this.store.setChatsMemory({chatsMemory:null})}async refreshSettings(){const e=this.getSessionGeneration(),r=await this.transport.get("terminal/settings",void 0,y(G)),n=w(r);return this.isCurrentSession(e)&&this.store.setSettings(n),n}getSettings(){return this.store.getSettings()}async saveSettings(e){const r=this.getSessionGeneration(),n=this.store.getSettings(),i=w(e);this.store.setSettings(i);try{const o=await this.transport.post("terminal/settings",i,{...y(G),headers:{"Content-Type":"application/json"}}),a=w(o,i);return this.isCurrentSession(r)&&this.store.setSettings(a),a}catch(o){throw this.isCurrentSession(r)&&this.store.setSettings(n),o}}resetSession(){this.abortedGeneration=this.streamGeneration,this.messagesLoadByChatUuid.clear(),this.loadedMessageChatUuids.clear();for(const e of Y)this.transport.abort(e);this.store.clear()}getSessionGeneration(){return this.store.getSessionEpoch()}isCurrentSession(e){return e===this.store.getSessionEpoch()}}class ye{constructor(t,e){var r;this.repository=t,this.eventBus=e,(r=this.eventBus)==null||r.addEventListener(k,async n=>{const{session:i,isPreferUserDataUpdate:o}=n.detail;if(i===null){this.resetSession();return}o&&(this.resetSession(),await Promise.allSettled([this.refreshEnergyBalance(),this.loadChats(void 0,!0),this.refreshChatsMemory(),this.refreshSettings()]))})}resetSession(){this.repository.resetSession()}getSessionEpoch(){return this.repository.getSessionGeneration()}getEnergyBalance(){return this.repository.getEnergyBalance()}isEnergyExhausted(){const t=this.repository.getEnergyBalance();return t!==null&&t.energyLeft<=0}async refreshEnergyBalance(){return await this.repository.refreshEnergyBalance()}async reportLlmUsageAndRefreshEnergy(t){if(t!==void 0)try{await this.repository.reportLlmUsage(t)}catch(e){console.error("Report LLM usage error:",e)}try{await this.repository.refreshEnergyBalance()}catch(e){console.error("Refresh energy balance error:",e)}}getChats(){return this.repository.getChats()}getChatsCursor(){return this.repository.getChatsCursor()}async loadChats(t,e=!1){return await this.repository.loadChats(t,e)}createChat(t){return this.repository.createChat(t)}getMessages(t){return this.repository.getMessages(t)}setMessages(t,e){this.repository.setMessages(t,e)}async loadMessages(t){return(await this.repository.loadMessages(t)).items}async ensureMessagesLoaded(t,e=!1){try{await this.repository.ensureMessagesLoaded(t,e)}catch(r){console.error(r)}}async sendMessage(t,e,r=A,n=[]){const i=this.repository.getSessionGeneration(),o=e.trim(),a=n.length>0;if(o.length===0&&!a)return{chatUuid:t,messages:t.length>0?this.repository.getMessages(t):[]};if(this.isEnergyExhausted())throw new Error("ENERGY_EXHAUSTED");const h=t.length>0?this.repository.getChats().find(H=>H.uuid===t):void 0,l=h??(t.length>0?this.repository.createChat({uuid:t}):this.repository.createChat()),c=h===void 0?t.length===0:h.userId===0,u=l.uuid;if(await this.ensureMessagesLoaded(u,c),!this.repository.isCurrentSession(i))return{chatUuid:u,messages:this.repository.getMessages(u)};const g=new Date().toISOString(),f=`local-user-${Date.now()}`,I=`local-pending-${Date.now()}`,L=this.repository.getMessages(u),P=n.map(F),U={role:"user",content:o,metadata:P,dateCreated:g,localId:f,...a?{attachments:n}:{}},D={role:"assistant",content:"",metadata:[],dateCreated:g,localId:I,isPending:!0};if(this.repository.setMessages(u,[...L,U,D]),this.repository.upsertChat(l),!this.repository.isCurrentSession(i))return{chatUuid:u,messages:this.repository.getMessages(u)};const R={role:"user",content:o};return a&&(R.attachments=n),await this.streamAssistantReply({chatUuid:u,userLocalId:f,pendingLocalId:I,model:r,sessionGeneration:i,history:[...this.toStreamHistory(L),R]})}async resendMessage(t,e,r=A){const n=this.repository.getSessionGeneration();if(this.isEnergyExhausted())throw new Error("ENERGY_EXHAUSTED");if(await this.ensureMessagesLoaded(t),!this.repository.isCurrentSession(n))return{chatUuid:t,messages:this.repository.getMessages(t)};const i=this.repository.getMessages(t),o=i.find(u=>u.localId===e&&u.role==="user");if(o===void 0)return{chatUuid:t,messages:i};if(o.content.trim().length===0&&E(o).length===0)return{chatUuid:t,messages:i};if(i.some(u=>u.isPending===!0))return{chatUuid:t,messages:i};const a=`local-pending-${Date.now()}`,h=new Date().toISOString(),l={role:"assistant",content:"",metadata:[],dateCreated:h,localId:a,isPending:!0},c=i.map(u=>u.localId!==e?u:{...u,isError:!1});return this.repository.setMessages(t,[...c,l]),this.repository.isCurrentSession(n)?await this.streamAssistantReply({chatUuid:t,userLocalId:e,pendingLocalId:a,model:r,sessionGeneration:n,history:this.toStreamHistory(c)}):{chatUuid:t,messages:this.repository.getMessages(t)}}toStreamHistory(t){return t.filter(e=>e.isPending!==!0&&e.isError!==!0&&(e.content.length>0||E(e).length>0||e.metadata.length>0)).map(e=>{const r={role:e.role,content:e.content},n=E(e);return n.length>0&&(r.attachments=n),r})}markUserMessageFailed(t,e,r){const n=this.repository.getMessages(t);
9this.repository.setMessages(t,n.filter(i=>i.localId!==r).map(i=>i.localId!==e?i:{...i,isError:!0}))}finalizeStoppedAssistant(t,e){const r=this.repository.getMessages(t),n=r.find(o=>o.localId===e);if(((n==null?void 0:n.content)??"").length===0){this.repository.setMessages(t,r.filter(o=>o.localId!==e));return}this.repository.setMessages(t,r.map(o=>o.localId!==e?o:{...o,isPending:!1}))}async stopStream(t){t.length!==0&&await this.repository.stopStream({chatId:t})}async streamAssistantReply(t){const{chatUuid:e,userLocalId:r,pendingLocalId:n,model:i,sessionGeneration:o,history:a}=t;try{const h=await this.repository.stream({chatId:e,model:i,messages:a},u=>{const g=this.repository.getMessages(e);this.repository.setMessages(e,g.map(f=>f.localId!==n?f:{...f,content:u}))});if(!this.repository.isCurrentSession(o))return{chatUuid:e,messages:this.repository.getMessages(e)};const l=this.repository.getMessages(e).filter(u=>u.localId!==n),c={role:"assistant",content:h.content,metadata:[],dateCreated:"",localId:n};return this.repository.setMessages(e,h.content.length>0?[...l,c]:l),this.syncUntitledChat(e),h.usage!==void 0?await this.reportLlmUsageAndRefreshEnergy({chatId:e,model:h.model??i,usage:h.usage}):await this.reportLlmUsageAndRefreshEnergy(),{chatUuid:e,messages:this.repository.getMessages(e)}}catch(h){if(!this.repository.isCurrentSession(o)){if(h instanceof C)return{chatUuid:e,messages:this.repository.getMessages(e)};throw h}if(h instanceof C)return this.finalizeStoppedAssistant(e,n),this.syncUntitledChat(e),await this.reportLlmUsageAndRefreshEnergy(),{chatUuid:e,messages:this.repository.getMessages(e)};throw this.markUserMessageFailed(e,r,n),h}}async syncUntitledChat(t){const e=this.repository.getChats().find(i=>i.uuid===t);if(!(e===void 0||e.name!==null&&e.name.trim().length>0||!this.repository.getMessages(t).some(i=>i.role==="assistant"&&i.isPending!==!0&&i.content.length>0)))try{await this.repository.refreshChat(t)}catch(i){console.error(i)}}getChatsMemory(){return this.repository.getChatsMemory()}async refreshChatsMemory(){return await this.repository.refreshChatsMemory()}async removeChatsMemory(){await this.repository.removeChatsMemory()}getSettings(){return this.repository.getSettings()}async refreshSettings(){return await this.repository.refreshSettings()}async saveSettings(t){return await this.repository.saveSettings(t)}}function Ee(){const s=Z();return s.isRegistered("TerminalService")||s.register("TerminalService",()=>{const{transport:t,eventBus:e}=s.resolve("ModuleInitOptions"),r=new pe(t,()=>new te);return new ye(r,e)}),s.resolve("TerminalService")}export{Ce as a,Me as b,ve as g,Ee as r,Se as u};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.