1!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},t=(new e.Error).stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="a0e5ae4f-2452-4cbe-8096-1aa9908724b8",e._sentryDebugIdIdentifier="sentry-dbid-a0e5ae4f-2452-4cbe-8096-1aa9908724b8")}catch(e){}}();"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4863],{64863:(e,t,s)=>{s.d(t,{tH:()=>n.tH,MP:()=>n.MP,q0:()=>D,Wd:()=>E,HX:()=>n.HX,g6:()=>n.g6,Cz:()=>G,_o:()=>f._o,q2:()=>n.q2,ZG:()=>n.ZG,Yx:()=>M,um:()=>n.um,fJ:()=>L,ih:()=>n.ih,WD:()=>n.Dg,Rn:()=>f.Rn,UN:()=>n.UN,Je:()=>n.Je,W1:()=>w,yx:()=>z,ON:()=>f.ON});var n=s(29717),i=s(9208),r=s(36965),a=s(3723);function l(e,t,s){let n=null!=e?e:"",i=null!=t?t:"";if(s){let e=n+s;return i.length>=e.length?i:e}return i||n}function o(e){if("number"==typeof e&&e>0)return e<1e3?Math.round(1e3*e):e}function h(e,t){let s=e=>"number"==typeof e&&Number.isFinite(e)&&e>0;return s(e)?e:s(t)?t:e}function d(e,t){return"number"==typeof t&&Number.isFinite(t)&&t>0?t:null!=e?e:null}var u=s(75127);let c="[åéæ¶æ¯å¤±è´¥]";function g(e,t){var s,n,i,c,g,v,p,f,I,S,T,A;let b={thinkingPhase:null!==(v=e.thinkingPhase)&&void 0!==v?v:t.thinkingPhase,thinkingTrail:null!==(p=e.thinkingTrail)&&void 0!==p?p:t.thinkingTrail,thinkMs:function(e,t){let s=o(t),n=o(e);return null!=s&&null!=n?Math.max(s,n):null!=s?s:n}(e.thinkMs,t.thinkMs)},y=l(null!==(n=e.message)&&void 0!==n?n:"",t.message,t.deltaMessage),k=l(null!==(i=e.reasoningContent)&&void 0!==i?i:"",t.reasoningContent,t.deltaReasoningContent),C=(f=e.toolContent,null==(I=null!==(c=t.toolContent)&&void 0!==c?c:t.deltaToolContent)?null!=f?f:void 0:null!==(S=(0,a.ZB)(I))&&void 0!==S?S:I),E=(T=e.parts,void 0===(A=t.parts)?T:A),L={processStartTime:h(e.processStartTime,t.processStartTime),processEndTime:d(e.processEndTime,t.processEndTime),answerStartTime:h(e.answerStartTime,t.answerStartTime),answerEndTime:d(e.answerEndTime,t.answerEndTime)},M=function(e){let{thinkMs:t,nextMessage:s,prevMessage:n,createTime:i,now:r=Date.now()}=e,a=!!(s.trim()&&!(null!=n?n:"").trim()),l=o(t);if(a&&i){let e=Math.max(0,r-i);return null!=l?Math.max(l,e):e}return l}({thinkMs:b.thinkMs,nextMessage:(0,u.Vf)({...e,message:y,parts:E}),prevMessage:(0,u.Vf)(e),createTime:e.createTime}),w=(null===(s=t.blockId)||void 0===s?void 0:s.trim())||e.blockId,P={...e,...t,blockId:w,status:null!==(g=t.status)&&void 0!==g?g:e.status,createTime:e.createTime>0?e.createTime:t.createTime>0?t.createTime:e.createTime||t.createTime,message:y,reasoningContent:k,toolContent:C,parts:E,thinkingPhase:b.thinkingPhase,thinkingTrail:b.thinkingTrail,thinkMs:M,...L,deltaMessage:void 0,deltaReasoningContent:void 0,deltaToolContent:void 0,answerSummarizing:void 0};return P.status===r.AtQ.ABORTED?m(P):P}function m(e){var t;let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now(),n=(0,i.A$)(e,s);return{...e,status:r.AtQ.ABORTED,thinkMs:n,errorCode:null!==(t=e.errorCode)&&void 0!==t?t:"aborted:user"}}function v(e,t){if(0===e.length)return[t.status===r.AtQ.ABORTED?m(t):t];if(t.blockId){let s=e.findIndex(e=>e.blockId===t.blockId);if(s>=0){let n=[...e];return(n[s]=g(n[s],t),s!==n.length-1)?function(e,t){let s=e[e.length-1];return(null==s?void 0:s.role)===r.ooL.ASSISTANT&&((0,i.jg)(s.status)||!s.blockId||s.blockId.startsWith("pending-")||s.blockId===t)?e.slice(0,-1):e}(n,t.blockId):n}}let s=e[e.length-1];return(null==s?void 0:s.role)===r.ooL.ASSISTANT&&((0,i.jg)(s.status)||!s.blockId||t.blockId&&t.blockId===s.blockId)?[...e.slice(0,-1),g(s,t)]:[...e,t.status===r.AtQ.ABORTED?m(t):t]}function p(e){for(let t=e.length-1;t>=0;t-=1){let s=e[t];if((null==s?void 0:s.role)===r.ooL.ASSISTANT){if(s.status===r.AtQ.RUNNING&&s.blockId)return s;if((0,i.yG)(s.status))break}}}var f=s(78147),I=s(12869);let S={enabled:!1,loaded:!1,userId:null},T=S,A=new Set,b=null,y=null;function k(e){T=e,A.forEach(e=>e())}function C(e){return A.add(e),()=>A.delete(e)}function E(e){T.enabled&&(e[r.kfu]=(0,r.rjt)(e[r.kfu]))}function L(){b=null,y=null,k(S)}async function M(e,t){let s=e.trim();if(!s){L();return}if(T.userId!==s&&k({enabled:!1,loaded:!1,userId:s}),!T.loaded||T.userId!==s)return b&&y===s?b:(y=s,b=(async()=>{try{let e=await t()===!0;if(y!==s)return;k({enabled:e,loaded:!0,userId:s})}catch(e){if(y!==s)return;k({enabled:!1,loaded:!0,userId:s})}finally{y===s&&(b=null)}})())}function w(){return(0,I.useSyncExternalStore)(C,()=>T.enabled,()=>!1)}s(6468),s(24056),s(11101),s(35602),s(35230),s(57447),s(48628);let P={isStreaming:!1,isConnecting:!1,retryCount:0,lastError:null};function R(e,t){switch(t.type){case"send_started":return{...e,isConnecting:!0,isStreaming:!1,lastError:null};case"streaming_started":if(!e.isConnecting&&e.isStreaming)return e;return{...e,isConnecting:!1,isStreaming:!0};case"send_completed":return{...e,isConnecting:!1,isStreaming:!1,retryCount:0};case"send_error":return{...e,isConnecting:!1,isStreaming:!1,lastError:t.payload};case"retry_incremented":return{...e,retryCount:e.retryCount+1};case"cancelled":return{...e,isConnecting:!1,isStreaming:!1,lastError:null};case"session_reset":return P;default:return e}}function N(e,t){var s;if(!e)return t;let n=v([e],t);return null!==(s=n[n.length-1])&&void 0!==s?s:t}let B=new Set(["ã","ï¼","ï¼","!","?","â¦"]),x=new Set(["ï¼","ã","ï¼","ï¼",",",";",":"]),U=new Set(["*","_","`","#",">","|","[","]","(",")","~","-","+"]),D={minRate:28,maxRate:62,finishMinRate:58,finishMaxRate:170,drainTargetMs:1200,drainTargetFinis
1hMs:700,smoothing:.25,maxElapsedMs:240,maxCarryBudget:1.5},_={rate:0,budget:0};async function O(e){let{message:t,isStreaming:s,chatId:n,contextBlockIds:i,replaceBlockId:r,attachments:a,attachmentCards:l,chatEngine:o,prependNewChat:h,setMessages:d,onSendStarted:u,onSendError:c,onMessage:g,onError:m,onComplete:v,scrollToBottom:p,customScrollToBottom:f}=e;if(!t.trim()||s)return!1;let I=f||p;I&&I();let{userMessage:S,pendingMessage:T}=o.createUserAndPending(n||"",t,l);d(e=>[...e,S,T]),u();try{n||h({chatId:"",title:"\uD83D\uDE80New Chat",time:Date.now()}),await o.send({chatId:n||void 0,message:t,contextBlockIds:i,replaceBlockId:r,attachments:a},{onMessage:g,onError:m,onComplete:v})}catch(e){c(e instanceof Error?e.message:"åéæ¶æ¯å¤±è´¥"),d(e=>o.applyFailure(e))}return!0}var F=s(31850),Q=s(9251);let W=e=>e.startsWith("draft-");class j{async hydrate(){var e;let t=await (null===(e=this.deps.persist)||void 0===e?void 0:e.read(this.id));t&&0===this.messages.length&&(this.messages=t.messages,this.contextBlockIds=t.contextBlockIds,this.emit())}ready(){return this.readyPromise}cachedTailText(){let e=this.messages[this.messages.length-1];return e&&e.role===r.ooL.ASSISTANT?(0,u.Vf)(e):""}cachedTailLength(){return this.cachedTailText().length}hiddenLength(){return null==this.revealedLength?0:Math.max(0,this.cachedTailLength()-this.revealedLength)}updateView(){if(null==this.revealedLength||0>=this.hiddenLength()){this.view=this.messages;return}let e=this.messages[this.messages.length-1];this.view=[...this.messages.slice(0,-1),{...e,message:this.cachedTailText().slice(0,this.revealedLength)}]}computeSnapshot(){return{messages:this.view,contextBlockIds:this.contextBlockIds,sendUi:this.sendUi,resolvedChatId:this.resolvedChatId,version:this.version,isRevealing:this.hiddenLength()>0}}emit(){this.version+=1,this.updateView(),this.snapshot=this.computeSnapshot(),this.listeners.forEach(e=>e())}commitCache(e){this.messages=e,this.schedulePersist(),this.emit()}clearPacingTimer(){null!=this.pacingTimer&&(clearTimeout(this.pacingTimer),this.pacingTimer=null)}applyMessages(e){let t=this.deps.pacing;if(!t){this.commitCache(e);return}if(this.abortInFlight){this.stopPacing();let t=e[e.length-1];if((null==t?void 0:t.status)===r.AtQ.ABORTED){this.revealedLength=null,this.commitCache(e);return}if(null!=this.revealedLength&&this.hiddenLength()>0){let s=this.view[this.view.length-1];if((null==s?void 0:s.role)===r.ooL.ASSISTANT&&(null==t?void 0:t.role)===r.ooL.ASSISTANT){let n=(0,u.Vf)(s);this.messages=[...e.slice(0,-1),{...t,message:n||t.message}],this.schedulePersist(),this.emit();return}}this.commitCache(e);return}let s=this.messages[this.messages.length-1],n=e[e.length-1];if(!(this.messages.length===e.length&&(null==s?void 0:s.role)===r.ooL.ASSISTANT&&(null==n?void 0:n.role)===r.ooL.ASSISTANT)){this.stopPacing(),this.revealedLength=null,this.commitCache(e);return}let i=s?(0,u.Vf)(s):"",a=n?(0,u.Vf)(n):"";null==this.revealedLength?this.revealedLength=Math.min(i.length,a.length):this.revealedLength=Math.min(this.revealedLength,function(e,t){let s=Math.min(e.length,t.length),n=0;for(;n<s&&e[n]===t[n];)n+=1;return n}(i,a)),this.messages=e,this.schedulePersist(),this.emit(),this.hiddenLength()>0&&this.schedulePacingFlush(t)}schedulePacingFlush(e){null==this.pacingTimer&&(this.pacingTimer=setTimeout(()=>this.flushPacing(e),e.renderIntervalMs))}flushPacing(e){var t,s;if(this.pacingTimer=null,null==this.revealedLength)return;let n=this.cachedTailText(),i=Math.min(this.revealedLength,n.length);if(i>=n.length){this.finishPacingRound();return}let r=this.now(),a=this.paceLastAt>0?r-this.paceLastAt:e.renderIntervalMs;this.paceLastAt=r;let l=function(e){var t;let s=null!==(t=e.tuning)&&void 0!==t?t:D,{fullText:n,streamEnded:i}=e,r=Math.max(0,Math.min(e.revealedLength,n.length)),a=n.length-r;if(a<=0)return{revealedLength:r,state:{rate:e.state.rate,budget:0},done:!0};let l=function(e,t,s){let n=t?s.drainTargetFinishMs:s.drainTargetMs,i=t?s.finishMinRate:s.minRate;return Math.min(t?s.finishMaxRate:s.maxRate,Math.max(i,e/n*1e3))}(a,i,s),o=e.state.rate>0?e.state.rate+(l-e.state.rate)*s.smoothing:l,h=Math.max(0,Math.min(e.elapsedMs,s.maxElapsedMs)),d=e.state.budget+o*h/1e3,u=r;for(;u<n.length;){let e=String.fromCodePoint(n.codePointAt(u)),t=function(e){var t;let s=null!==(t=e.codePointAt(0))&&void 0!==t?t:0;return"\n"===e||" "===e||" "===e||"\r"===e?.25:U.has(e)?.08:s>=12352&&s<=12543||s>=13312&&s<=19903||s>=19968&&s<=40959||s>=63744&&s<=64255||s>=65280&&s<=65519||s>65535?1:s>=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122?.45:.5}(e);if(d<t)break;d-=t;let s=(u+=e.length)<n.length?String.fromCodePoint(n.codePointAt(u)):void 0,i="\n"===e?"\n"===s?180:60:B.has(e)?130:x.has(e)?60:0;if(i>0&&(d-=i*o/1e3)<0){d=0;break}}let c=u>=n.length;return{revealedLength:u,state:{rate:o,budget:c?0:Math.min(d,s.maxCarryBudget)},done:c}}({fullText:n,revealedLength:i,elapsedMs:a,streamEnded:!this.isSending(),state:this.paceState,tuning:e.tuning});this.paceState=l.state;let o=l.revealedLength>i;if(null===(t=(s=this.deps).onPaceTick)||void 0===t||t.call(s,{buffered:n.length,revealedBefore:i,revealedAfter:l.revealedLength,elapsedMs:a,rate:l.state.rate,streamEnded:!this.isSending(),done:l.done,skippedCommit:!o}
1),o&&(this.revealedLength=l.revealedLength,this.emit()),l.done){this.finishPacingRound();return}this.schedulePacingFlush(e)}finishPacingRound(){this.clearPacingTimer(),this.paceLastAt=0}stopPacing(){this.clearPacingTimer(),this.paceState=_,this.paceLastAt=0}freezeAtRevealed(){this.stopPacing(),null!=this.revealedLength&&this.hiddenLength()>0&&(this.messages=this.view),this.revealedLength=null}currentPersistSnapshot(){return{messages:this.messages,contextBlockIds:this.contextBlockIds}}schedulePersist(){var e;null===(e=this.deps.persist)||void 0===e||e.scheduleWrite(this.id,this.currentPersistSnapshot())}flushPersist(){var e;null===(e=this.deps.persist)||void 0===e||e.flushWrite(this.id,this.currentPersistSnapshot())}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}getSnapshot(){return this.snapshot}getId(){return this.id}messageCount(){return this.messages.length}isSending(){return this.sendUi.isStreaming||this.sendUi.isConnecting}isBusy(){return this.isSending()}isPlaying(){return this.isSending()||this.hiddenLength()>0}setMessages(e){this.stopPacing(),this.revealedLength=null,this.messages=e,this.schedulePersist(),this.emit()}getCachedMessages(){return this.messages}updateCachedMessages(e){let t=e(this.messages);t!==this.messages&&this.applyMessages(t)}setContextBlockIds(e){this.contextBlockIds=e,this.emit()}adoptId(e){(0,Q.nZ)(this.id,e),this.id=e,this.isDraftId(e)||(this.resolvedChatId=e)}notifyQueryResponseOnce(e,t){if(this.queryResponseNotifiedEpoch===this.streamEpoch)return;this.queryResponseNotifiedEpoch=this.streamEpoch;let s=[...this.messages].reverse().find(e=>e.role===r.ooL.ASSISTANT),n=s?(0,u.Vf)(s):"";(0,F.J)({conversation_id:this.resolvedChatId||this.id,status:e,response_length:"string"==typeof n?n.length:0,fail_reason:t})}buildStreamCallbacks(){var e;let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},s=++this.streamEpoch,n=()=>s===this.streamEpoch,i=e=>{n()&&this.applyMessages(e(this.messages))},{onMessage:a,onComplete:l,onError:o}=function(e){let{chatEngine:t,setMessages:s,setChatId:n,onStreamingStarted:i,onSendError:a,onSendCompleted:l,onAfterComplete:o,onApplySessionEffects:h,onSessionChatIdResolved:d,flushMinIntervalMs:u=0,isCurrent:c=()=>!0}=e,g=null,m=null,v=null,p=0,f=!1,I=!1,S=()=>{null!=m&&(cancelAnimationFrame(m),m=null),null!=v&&(clearTimeout(v),v=null)},T=()=>{if(S(),!g)return;if(!c()){g=null;return}let e=g;g=null,s(s=>t.reduceIncoming(s,e).messages),p=Date.now()},A=()=>{if(null!=m||null!=v)return;let e=Date.now(),t=u>0&&p>0?Math.max(0,u-(e-p)):0,s=()=>{m=null,v=null,T()};if(t>0){v=setTimeout(s,t);return}m=requestAnimationFrame(s)};return{onMessage:e=>{var t,s;if(!c())return;f||(i(),f=!0);let n=null===(t=e.chatId)||void 0===t?void 0:t.trim();if(n&&!I&&(I=!0,null==d||d(n)),e.error&&e.status!==r.AtQ.ABORTED&&"aborted:user"!==e.errorCode&&"PRO_BUSY"!==e.errorCode){T(),f=!1;let t=(null===(s=e.message)||void 0===s?void 0:s.trim())||(e.error.startsWith("traceback:")?"":e.error.trim())||"æ±æï¼è¿æ¡å夿ªè½å®æ´çæï¼è¯·åè¯ä¸æ¬¡";g=N(g,{...e,status:r.AtQ.FINAL,message:t}),T();return}if(g=N(g,e),e.status===r.AtQ.ABORTED){T();return}A()},onComplete:async e=>{if(!c()){S(),g=null;return}T(),c()&&(f=!1,s(e=>t.finalizePending(e)),l(),o&&await o(),e&&(s(t=>t.map(t=>({...t,chatId:""===t.chatId?e:t.chatId}))),n(e),null==h||h(e)))},onError:e=>{if(!c()){S(),g=null;return}T(),f=!1,I=!1,a(e.message)}}}({chatEngine:this.engine,setMessages:i,setChatId:e=>{(0,Q.nZ)(this.resolvedChatId||this.id,e),this.resolvedChatId=e},onStreamingStarted:()=>{n()&&(this.sendUi=R(this.sendUi,{type:"streaming_started"}),this.emit())},onSendError:e=>{n()&&(this.abortInFlight=!1,this.sendUi=R(this.sendUi,{type:"send_error",payload:e}),this.notifyQueryResponseOnce("fail",e),this.emit())},onSendCompleted:()=>{n()&&(this.abortInFlight=!1,this.sendUi=R(this.sendUi,{type:"send_completed"}),this.notifyQueryResponseOnce("success"),this.flushPersist(),this.emit())},onSessionChatIdResolved:e=>{var s;n()&&(null===(s=t.onChatIdResolved)||void 0===s||s.call(t,e))},onApplySessionEffects:e=>{var s;n()&&(null===(s=t.onApplySessionEffects)||void 0===s||s.call(t,e))},flushMinIntervalMs:null!==(e=this.deps.flushMinIntervalMs)&&void 0!==e?e:0,isCurrent:n}),h=()=>{s===this.streamEpoch&&this.streamEpoch++,this.engine.cancel()};return{setMessages:i,onMessage:e=>{var t,s,i,l;
1if(n()){if("PRO_BUSY"===e.errorCode){this.abortInFlight=!1,this.messages=this.messages.slice(0,-2),this.sendUi=R(this.sendUi,{type:"send_completed"}),this.emit(),h(),null===(t=(s=this.deps).onNotify)||void 0===t||t.call(s,"ä¸ä¸æ¡åå¤è¿å¨çæä¸ï¼è¯·ç¨ååè¯");let e=p(this.messages);(null==e?void 0:e.blockId)&&this.resumeRunningBlock(e.blockId);return}if("PRO_STREAM_GONE"===e.errorCode){let t=e.error||e.message||"åå¤çæå·²ä¸æï¼è¯·éæ°åé";null===(i=(l=this.deps).onNotify)||void 0===i||i.call(l,t),a({...e,status:r.AtQ.FINAL,message:t,error:void 0});return}a(e),e.status===r.AtQ.ABORTED&&n()&&(this.stopPacing(),this.revealedLength=null,this.abortInFlight=!1,this.sendUi=R(this.sendUi,{type:"cancelled"}),this.notifyQueryResponseOnce("partial"),this.emit(),h())}},onComplete:l,onError:e=>{n()&&(o(e),n()&&(this.freezeAtRevealed(),this.messages=this.engine.applyFailure(this.messages),this.flushPersist(),this.emit()))}}}async send(e){var t,s;let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!e.trim()||this.isBusy())return!1;this.lastSendOptions=n;let i=null!==(t=n.contextBlockIds)&&void 0!==t?t:this.contextBlockIds,r=this.isDraftId(this.id)?this.id:void 0,{setMessages:a,onMessage:l,onComplete:o,onError:h}=this.buildStreamCallbacks(n);return O({message:e,isStreaming:this.isBusy(),chatId:null!==(s=this.resolvedChatId)&&void 0!==s?s:"",contextBlockIds:i,replaceBlockId:n.replaceBlockId,attachments:n.attachments,attachmentCards:n.attachmentCards,chatEngine:this.engine,prependNewChat:e=>{var t,s;null===(t=n.prependNewChat)||void 0===t||t.call(n,{...e,chatId:null!=r?r:e.chatId,title:null!==(s=n.placeholderTitle)&&void 0!==s?s:e.title})},setMessages:a,onSendStarted:()=>{this.sendUi=R(this.sendUi,{type:"send_started"}),this.emit()},onSendError:e=>{this.sendUi=R(this.sendUi,{type:"send_error",payload:e}),this.emit()},onMessage:l,onError:h,onComplete:o})}async resumeRunningBlock(e){var t;if(this.isSending())return!1;let s=null!==(t=e?this.messages.find(t=>t.blockId===e&&t.status===r.AtQ.RUNNING):p(this.messages))&&void 0!==t?t:void 0;if(!(null==s?void 0:s.blockId)||s.blockId.startsWith("pending-"))return!1;let n=this.resolvedChatId||s.chatId;if(!n||this.isDraftId(n))return!1;let{onMessage:i,onComplete:a,onError:l}=this.buildStreamCallbacks(this.lastSendOptions);this.sendUi=R(this.sendUi,{type:"send_started"}),this.emit();try{return await this.engine.resumeStream({chatId:n,blockId:s.blockId},{onMessage:i,onComplete:a,onError:l}),!0}catch(e){return l(e instanceof Error?e:Error("ç»æµå¤±è´¥")),!1}}resumeIfNeeded(){let e=p(this.messages);return null!=e&&!!e.blockId&&(this.resumeRunningBlock(e.blockId),!0)}async retry(){var e;if(this.isBusy())return!1;let t=null===(e=this.messages.filter(e=>e.role===r.ooL.USER).pop())||void 0===e?void 0:e.message;if(!t)return!1;let s=this.messages[this.messages.length-1],n=(null==s?void 0:s.role)===r.ooL.ASSISTANT&&s.status===r.AtQ.ABORTED&&s.blockId&&!s.blockId.startsWith("pending-")?s.blockId:void 0;return this.sendUi=R(this.sendUi,{type:"retry_incremented"}),this.stopPacing(),this.revealedLength=null,this.messages=this.messages.slice(0,-2),this.emit(),this.send(t,{...this.lastSendOptions,replaceBlockId:n})}async editResend(e,t){var s;let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},a=t.trim();if(!a)return!1;let l=this.messages.findIndex(t=>t.blockId===e&&t.role===r.ooL.USER);if(l<0)return!1;let o=this.messages[l],h=this.messages[l+1],d=(null==h?void 0:h.role)===r.ooL.ASSISTANT?h:void 0,u=(null==d?void 0:d.blockId)&&!d.blockId.startsWith("pending-")?d.blockId:void 0,c=this.resolvedChatId||(null==d?void 0:d.chatId)||o.chatId,g=n.replaceBlockId;if(!g&&u&&(null==d?void 0:d.status)===r.AtQ.ABORTED)g=u;else if(!g&&u&&c&&this.deps.abortBlock&&(0,i.jg)(null==d?void 0:d.status))try{await this.deps.abortBlock(c,u),g=u}catch(e){}else this.isSending()&&this.cancel();this.streamEpoch++,this.engine.cancel(),this.abortInFlight=!1,this.stopPacing(),this.revealedLength=null,this.sendUi=R(this.sendUi,{type:"cancelled"}
1),this.messages=this.messages.slice(0,l),this.emit(),this.flushPersist();let m=n.attachmentCards,v=void 0!==m?m.length?m:void 0:(null===(s=o.attachments)||void 0===s?void 0:s.length)?o.attachments:void 0,p=null==v?void 0:v.map(e=>{var t;return null===(t=e.attachmentId)||void 0===t?void 0:t.trim()}).filter(e=>!!e).map(e=>({attachmentId:e}));return this.send(a,{...this.lastSendOptions,...n,replaceBlockId:g,...(null==p?void 0:p.length)?{attachments:p,attachmentCards:v}:{attachments:void 0,attachmentCards:void 0}})}cancel(){if(this.abortInFlight||!this.isSending())return;let e=this.messages[this.messages.length-1];if((null==e?void 0:e.role)===r.ooL.ASSISTANT&&(e.status===r.AtQ.FINAL||e.status===r.AtQ.ABORTED))return;let t=this.resolvedChatId||(null==e?void 0:e.chatId),s=(null==e?void 0:e.role)===r.ooL.ASSISTANT?e.blockId:void 0,n=!!t&&!!s&&!s.startsWith("pending-")&&!!this.deps.abortBlock&&((null==e?void 0:e.status)==null||e.status===r.AtQ.PENDING||e.status===r.AtQ.RUNNING);if(this.streamEpoch++,this.engine.cancel(),this.stopPacing(),this.freezeAtRevealed(),this.messages=this.engine.applyCancel(this.messages),this.sendUi=R(this.sendUi,{type:"cancelled"}),this.flushPersist(),this.emit(),!n){this.abortInFlight=!1;return}this.abortInFlight=!0,this.deps.abortBlock(t,s).catch(()=>{}).finally(()=>{this.abortInFlight=!1})}abortTransport(){this.engine.cancel(),this.stopPacing()}constructor(e,t){var s,n;this.deps=t,this.messages=[],this.queryResponseNotifiedEpoch=-1,this.contextBlockIds=[],this.sendUi=P,this.listeners=new Set,this.lastSendOptions={},this.version=0,this.pacingTimer=null,this.revealedLength=null,this.view=[],this.paceState=_,this.paceLastAt=0,this.abortInFlight=!1,this.streamEpoch=0,this.id=e,this.now=null!==(s=t.now)&&void 0!==s?s:()=>Date.now(),this.isDraftId=null!==(n=t.isDraftId)&&void 0!==n?n:W,this.resolvedChatId=this.isDraftId(e)?void 0:e,this.engine=function(e){var t,s;let n=null!==(t=e.now)&&void 0!==t?t:()=>Date.now(),a=null!==(s=e.createId)&&void 0!==s?s:()=>"".concat(Date.now().toString()).concat(Math.random().toString(36).slice(2));return{createUserAndPending:(e,t,s)=>{var i,l;return i=n(),{userMessage:{blockId:l=a(),message:t,createTime:i,reasoningContent:"",role:r.ooL.USER,chatId:e,...(null==s?void 0:s.length)?{attachments:s}:{}},pendingMessage:{blockId:"pending-".concat(l),message:"",createTime:i,reasoningContent:"",role:r.ooL.ASSISTANT,status:r.AtQ.PENDING,chatId:e}}},reduceIncoming:(e,t)=>({phase:t.error&&t.status!==r.AtQ.ABORTED?"error":t.status===r.AtQ.ABORTED?"cancelled":t.status===r.AtQ.FINAL?"completed":"streaming",messages:v(e,t)}),applyFailure(t){var s;return function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:c;return e.map(e=>e.role===r.ooL.ASSISTANT&&(0,i.jg)(e.status)?{...e,message:t,status:r.AtQ.FINAL}:e)}(t,null===(s=e.pendingErrorMessage)||void 0===s?void 0:s.call(e))},applyCancel:e=>(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:Date.now();return e.map(e=>e.role===r.ooL.ASSISTANT&&(0,i.jg)(e.status)?m({...e},t):e)})(e),finalizePending(t){var s;return function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:c,s=!1,n=e.map(e=>{var n,a;return e.role===r.ooL.ASSISTANT&&(0,i.jg)(e.status)&&e.status!==r.AtQ.ABORTED?(s=!0,{...e,status:r.AtQ.FINAL,message:null!==(n=e.message)&&void 0!==n&&n.trim()||(null===(a=e.parts)||void 0===a?void 0:a.some(e=>{var t;return"text"===e.type&&(null===(t=e.text)||void 0===t?void 0:t.trim())}))?e.message:t}):e});return s?n:e}(t,null===(s=e.pendingErrorMessage)||void 0===s?void 0:s.call(e))},async send(t,s){await e.transport.send(t,s)},async resumeStream(t,s){if(!e.transport.resumeStream){s.onError(Error("resumeStream is not supported"));return}await e.transport.resumeStream(t,s)},cancel(){var t,s;null===(t=(s=e.transport).cancel)||void 0===t||t.call(s)}}}({transport:t.createTransport(),now:t.now,createId:t.createId,pendingErrorMessage:t.pendingErrorMessage}),this.snapshot=this.computeSnapshot(),this.readyPromise=this.hydrate()}}function G(e){let t=new Map,s=new Map;function n(e){let t=e.trim(),n=new Set;for(;s.has(t)&&!n.has(t);)n.add(t),t=s.get(t);return t}return{getOrCreate:function(s){let i=n(s),r=t.get(i);return r||(r=new j(i,e),t.set(i,r)),r},get:function(e){return t.get(n(e))},resolve:n,rename:function(n,i){var r,a,l,o;let h;let d=n.trim(),u=i.trim();if(!d||!u||d===u||s.get(d)===u)return;let c=t.get(d),g=t.get(u);if(!c&&!g){s.set(d,u);return}if(c&&g){let e=c.isSending(),t=g.isSending(),s=e||!t&&c.messageCount()>=g.messageCount();h=s?c:g,(s?g:c).abortTransport()}else h=null!=c?c:g;h.adoptId(u),t.delete(d),t.delete(u),t.set(u,h),s.set(d,u),null===(r=e.persist)||void 0===r||r.cancelScheduledWrite(d),null===(a=e.persist)||void 0===a||a.cancelScheduledWrite(u),null===(l=e.persist)||void 0===l||l.rename(d,u),null===(o=e.persist)||void 0===o||o.flushWrite(u,{messages:h.getSnapshot().messages,contextBlockIds:h.getSnapshot().contextBlockIds})},dispose:function(e){var s;let n=e.trim();null===(s=t.get(n))||void 0===s||s.abortTransport(),t.delete(n)},disposeAll:function(){for(let e of t.values())e.abortTransport();t.clear(),s.clear()}}}let V={messages:[],contextBlockIds:[],sendUi:P,resolvedChatId:void 0,version:0,isRevealing:!1},q=()=>()=>{};function z(e,t){let s=null==e?void 0:e.trim(),n=s?t.resolve(s):void 0,i=(0,I.useMemo)(()=>n?t.getOrCreate(n):void 0,[n,t]),r=(0,I.useSyncExternalStore)(i?e=>i.subscribe(e):q,()=>{var e;return null!==(e=null==i?void 0:i.getSnapshot())&&void 0!==e?e:V},()=>V);return{session:i,resolvedId:n,...r}}},31850:(e,t,s)=>{s.d(t,{J:()=>r,Y:()=>i});let n=null;function i(e){n=e}function r(e){try{null==n||n(e)}catch(e){}}},48628:(e,t,s)=>{s.d(t,{NL:()=>a});var n=s(36965),i=s(3723);function r(e){return!!e&&"object"==typeof e}function a(e){var t;if(!r(e)||r(e)&&"phase"===e.object)return null;let s={...e};return s.role||(s.role=n.ooL.ASSISTANT),null==s.toolContent&&null!=s.deltaToolContent&&(s.toolContent=s.deltaToolContent),null!=s.toolContent&&(s.toolContent=null!==(t=(0,i.ZB)(s.toolContent))&&void 0!==t?t:s.toolContent),s.deltaToolContent=void 0,Array.isArray(s.parts)||(s.parts=void 0,s.reasoningContent="",s.deltaReasoningContent=void 0),s}}}]);
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.