wi-chat 0.6.2 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/core/index.cjs +1 -1
  2. package/dist/core/index.d.ts +12 -0
  3. package/dist/core/index.js +921 -342
  4. package/dist/core/useAnswerActions.d.ts +61 -0
  5. package/dist/core/useChat.d.ts +29 -3
  6. package/dist/core/useChatAuth.d.ts +175 -0
  7. package/dist/core/useChatRooms.d.ts +66 -0
  8. package/dist/core/useKeepAlive.d.ts +41 -0
  9. package/dist/core/useLlm.d.ts +73 -0
  10. package/dist/core/useRunningGroups.d.ts +58 -0
  11. package/dist/index.cjs +1 -1
  12. package/dist/index.d.ts +3 -1
  13. package/dist/index.js +119 -108
  14. package/dist/mobile-ui/chat/ChatContainer.vue.d.ts +3 -3
  15. package/dist/mobile-ui/inputbox/Inputbox.vue.d.ts +1 -1
  16. package/dist/parser/answerCom/generic/parseGeneric.d.ts +52 -0
  17. package/dist/parser/answerCom/generic/types.d.ts +75 -0
  18. package/dist/parser/answerCom/outputFile/parseOutputFile.d.ts +7 -6
  19. package/dist/parser/answerCom/outputFile/types.d.ts +15 -5
  20. package/dist/parser/answerCom/presentFiles/parsePresentFiles.d.ts +58 -0
  21. package/dist/parser/answerCom/presentFiles/types.d.ts +27 -0
  22. package/dist/parser/answerMeta.d.ts +71 -0
  23. package/dist/parser/deepThinking/parseDeepThinking.d.ts +8 -0
  24. package/dist/parser/history/history.d.ts +9 -0
  25. package/dist/parser/history/index.d.ts +1 -1
  26. package/dist/parser/index.cjs +6 -2
  27. package/dist/parser/index.d.ts +11 -2
  28. package/dist/parser/index.js +591 -366
  29. package/dist/parser/message.d.ts +9 -0
  30. package/dist/parser/runTime.d.ts +29 -0
  31. package/dist/renderers/TextAnswer-BgKGvG_o.cjs +2 -0
  32. package/dist/renderers/TextAnswer-PQwV3K7v.js +5 -0
  33. package/dist/renderers/answerCard/AnswerCard.vue.d.ts +65 -0
  34. package/dist/renderers/answerCard/AnswerToolbar.vue.d.ts +42 -0
  35. package/dist/renderers/answerConfig.d.ts +33 -0
  36. package/dist/renderers/deviceLastValue/DeviceLastValue.vue.d.ts +37 -0
  37. package/dist/renderers/index.cjs +6 -1
  38. package/dist/renderers/index.d.ts +14 -0
  39. package/dist/renderers/index.js +1485 -574
  40. package/dist/renderers/media/MediaAnswer.vue.d.ts +19 -0
  41. package/dist/renderers/outputFile/OutputFileLink.vue.d.ts +19 -0
  42. package/dist/renderers/outputFile/localFile.d.ts +46 -0
  43. package/dist/renderers/outputFile/useOutputFile.d.ts +32 -3
  44. package/dist/renderers/presentFiles/PresentFiles.vue.d.ts +19 -0
  45. package/dist/renderers/recordset/RecordsetView.vue.d.ts +19 -0
  46. package/dist/renderers/sqlQuery/SqlQuery.vue.d.ts +19 -0
  47. package/dist/renderers/style.css +1 -1
  48. package/dist/renderers/text/TextAnswer.vue.d.ts +19 -0
  49. package/dist/request/api.d.ts +121 -1
  50. package/dist/request/client.d.ts +12 -0
  51. package/dist/request/index.cjs +4 -2
  52. package/dist/request/index.d.ts +6 -4
  53. package/dist/request/index.js +780 -179
  54. package/dist/request/login.d.ts +36 -0
  55. package/dist/request/ws.d.ts +11 -86
  56. package/dist/request/wsCore.d.ts +104 -0
  57. package/dist/request/wsSession.d.ts +353 -0
  58. package/dist/right-panel/RightPanelTabs.vue.d.ts +4 -0
  59. package/dist/right-panel/index.cjs +1 -1
  60. package/dist/right-panel/index.d.ts +1 -1
  61. package/dist/right-panel/index.js +598 -499
  62. package/dist/right-panel/style.css +1 -1
  63. package/dist/right-panel/types.d.ts +10 -0
  64. package/dist/tools/index.cjs +5 -5
  65. package/dist/tools/index.d.ts +2 -2
  66. package/dist/tools/index.js +323 -208
  67. package/dist/tools/markdown/index.d.ts +2 -0
  68. package/dist/tools/markdown/interactions.d.ts +39 -0
  69. package/dist/tools/markdown/sanitize.d.ts +6 -0
  70. package/dist/tools/style.css +1 -1
  71. package/dist/web-ui/attach/AttachmentCard.vue.d.ts +1 -1
  72. package/dist/web-ui/attach/AttachmentList.vue.d.ts +1 -1
  73. package/dist/web-ui/chat/ChatContainer.vue.d.ts +5 -5
  74. package/dist/web-ui/envswitch/EnvSwitch.vue.d.ts +1 -1
  75. package/dist/web-ui/index.cjs +1 -1
  76. package/dist/web-ui/index.js +1 -1
  77. package/dist/web-ui/inputbox/Inputbox.vue.d.ts +5 -5
  78. package/dist/web-ui/style.css +1 -1
  79. package/package.json +2 -2
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("vue"),h=require("wi-chat/parser"),Z=require("wi-chat/request"),me=e=>{const u={requestId:e,sender:null,queue:[],closed:!1,reply:w=>le(u,w)};return u},le=(e,u,w)=>{if(e.closed)return!1;const G=typeof u=="string"?u:JSON.stringify(u)??"";return e.sender?e.sender(G,w)!==!1:(e.queue.push({payloadText:G,chunkSize:w}),!0)},ne=e=>{e.closed||(e.closed=!0,e.queue.length=0,e.sender=null,h.expirePendingClarificationsForReply(e.reply))},ue=e=>{const u=e.login,w=e.defaultGroupTitle??"新对话",G=e.lastCount??10,o=e.autoSetGroupTitleOnFirstQuestion??!0,A={beforeKnowledgeRender:e.beforeKnowledgeRender,parsers:e.parsers,actionExecute:{...e.actionExecute,reply:()=>!1}},y=n.ref(""),i=n.ref([]),I=n.ref(""),U=n.ref(e.incPrevQuestion??"Y"),r=n.ref(!1),c=n.ref(!1),t=n.ref(""),l=n.ref(!1),m=n.ref(""),d=n.ref(!0),p=n.ref(!1),C=n.ref(0),W=e.api?null:Z.createRequest({baseURL:e.baseURL??"",getWisession:()=>y.value}),P=e.api??Z.createChatApi(W);let b=null,R=null,D=0,_=0,V=0,E=null;const Y=async()=>{if(m.value="",!W||!u){l.value=!0;return}try{const s=await Z.login(W,u);return y.value=s.wisession||"",l.value=!0,s}catch(s){throw m.value=s instanceof Error?s.message:String(s),s}},a=s=>s===D,g=s=>{typeof URL>"u"||typeof URL.revokeObjectURL!="function"||s.forEach(L=>{L.role!=="user"||!L.attachments||L.attachments.forEach(x=>{var S;const q=(S=x.attachContent)==null?void 0:S.url;q&&q.startsWith("blob:")&&URL.revokeObjectURL(q)})})},O=s=>({beforeKnowledgeRender:e.beforeKnowledgeRender,parsers:e.parsers,actionExecute:{...e.actionExecute,reply:s.reply}}),F=async s=>{const L=++_;V+=1,r.value=!0,g(i.value),E&&h.clearPendingClarifications(E.reply),i.value=[],t.value=s,d.value=!0,p.value=!1,C.value=0;const x=[],q=()=>{const v=[];x.forEach(T=>{v.push(T.user),T.assistant&&v.push(T.assistant)}),L===_&&(i.value=v)},S=v=>{L===_&&(v.type==="users"?(x.length=0,v.users.forEach(T=>x.push({user:T}))):x[v.index]&&(v.user&&(x[v.index].user=v.user),x[v.index].assistant=v.assistant),q())};try{await h.loadGroupMessagesByStep(P,s,G,S,0,A),q(),L===_&&(C.value=x.length,x.length<G&&(d.value=!1))}finally{V-=1,V<=0&&(V=0,r.value=!1)}},z=async()=>{if(!t.value||r.value||!d.value||p.value)return;const s=t.value,L=_,x=C.value;p.value=!0;try{const q=await h.loadGroupMessagesByStep(P,s,G,void 0,x,A),S=q.filter(v=>v.role==="user").length;if(S<G&&(d.value=!1),L===_&&t.value===s){const v=new Set;i.value.forEach(M=>{M.historyId&&v.add(M.historyId),M.id&&v.add(M.id)});const T=q.filter(M=>!(M.historyId&&v.has(M.historyId)||M.id&&v.has(M.id)));i.value=[...T,...i.value],C.value+=S}}finally{p.value=!1}},ce=async(s=w)=>{const L=await h.createHistoryGroup(P,s);return t.value=L,L},ee=()=>{D+=1,_+=1,R&&(R.stopped=!0,R.thinking.expanded=!1),b==null||b.abort(),b=null,E&&ne(E),E=null,R=null,c.value=!1},fe=()=>{R&&(R.error=!0,R.thinking.expanded=!1)},de=async s=>{var ae,re;const L=typeof s=="string"?{text:s}:s||{},{text:x,entryId:q,files:S,attachments:v,extArgs:T,...M}=L,j=(x!==void 0?x:I.value).trim(),ye=T??e.extArgs??{},pe=S&&S.length>0?S:(v??[]).map(H=>{var X;return(X=H.attachContent)==null?void 0:X.raw}).filter(H=>!!H);if(!j||c.value||!t.value)return;const K=D+1;D=K,_+=1;const k=me(K);E=k;const he=O(k);let te=!1;try{c.value=!0;const H=t.value,X=v||(S||[]).map(f=>{var B;const J=f.name.includes(".")&&((B=f.name.split(".").pop())==null?void 0:B.toLowerCase())||"";return{type:"file",name:f.name,description:J?J.toUpperCase():"",attachContent:{file_name:f.name,size:f.size,suffix:J,raw:f}}}),we=C.value===0&&!i.value.some(f=>f.role==="user"),$=H,se=n.reactive({id:h.nextLocalMessageId("user"),role:"user",content:j,attachments:X.length>0?X:void 0});i.value.push(se);const Q=n.reactive({id:h.nextLocalMessageId("answer"),role:"assistant",answer:h.createEmptyAnswerValues("",j),error:!1,stopped:!1,thinking:{steps:[],expanded:!0}});if(R=Q,i.value.push(Q),I.value="",(ae=e.onSubmitQuestion)==null||ae.call(e,j),we&&$){const f=h.buildChatTitle(j);e.onFirstQuestion?e.onFirstQuestion({question:f,groupId:$}):o&&f&&P.setHistoryGroupTitle($,f).catch(()=>{})}b=new AbortController;const Ge=await P.questionStream({...M,question:j,historyGroupId:H,entryId:q,files:pe,ext_args:JSON.stringify(ye),incPrevQuestion:U.value,onOpen:f=>{if(!a(K)||k.closed)return;k.sender=f;const J=k.queue;k.queue=[],J.forEach(({payloadText:B,chunkSize:N})=>f(B,N))}},b.signal);C.value+=1,await h.consumeStream(Ge,f=>{var B;if(!a(K))return;if(f.mode==="history_id"){const N=typeof f.value=="object"&&f.value!==null?f.value.history_id:f.value;N&&(se.historyId=String(N),Q.historyId=String(N),Q.answer&&(Q.answer.id=String(N)))}h.applyAnswerChunk(Q.answer,f,he).includes("deep_thinking")&&(Q.thinking.steps=h.collectThinkingSteps(Q.answer)),f.mode==="finish"&&(Q.thinking.expanded=!1),(B=e.onChunk)==null||B.call(e,f)}),a(K)&&(Q.thinking.expanded=!1),a(K)&&(te=!0)}catch(H){a(K)&&!Z.isCancelError(H)&&fe()}finally{ne(k),E===k&&(E=null),a(K)&&(c.value=!1,b=null,R=null)}te&&((re=e.onFinish)==null||re.call(e))},ge=(s,L)=>!c.value||!E?!1:le(E,s,L),ve=e.autoLogin!==!1?Y().then(()=>{}).catch(()=>{}):Promise.resolve();return n.getCurrentInstance()&&n.onBeforeUnmount(()=>{ee(),g(i.value)}),{messages:i,question:I,incPrevQuestion:U,talking:c,loading:r,session:y,autoLoginDone:l,autoLoginError:m,loginDone:ve,historyGroupId:t,selfRequest:W,api:P,doAutoLogin:Y,loadGroup:F,loadOlder:z,hasMore:d,loadMoreLoading:p,createGroup:ce,submitQuestion:de,sendWsMessage:ge,stopQuestion:ee}},Le="wi-chat-history-groups",oe=e=>{var Y;const{api:u,defaultGroupTitle:w="新对话",lastCount:G=10,ensureGroup:o=!0,autoSelectFirst:A=!0,autoLoadMessages:y=!0}=e,i=e.persistGroups??!1,I=e.storageKey??Le,U=e.beforeKnowledgeRender||(Y=e.parsers)!=null&&Y.length?{beforeKnowledgeRender:e.beforeKnowledgeRender,parsers:e.parsers}:void 0,r=n.ref([]),c=n.ref(""),t=n.ref([]),l=n.ref(!1);let m=!1,d=null;const p=()=>{if(d===!1)return null;let a;try{a=localStorage.getItem(I)}catch{return d=!1,null}if(a===null)return[];try{const g=JSON.parse(a);return Array.isArray(g)?g:[]}catch{return[]}},C=a=>{if(d!==!1)try{localStorage.setItem(I,JSON.stringify(a))}catch{d=!1}},W=a=>{const g=p();g!==null&&C([...g,a])},P=async(a,g=G)=>{l.value=!0;try{t.value=a?await h.loadGroupMessages(u,a,g,0,U):[]}finally{l.value=!1}},b=async a=>{c.value=a,y&&await P(a)},R=async()=>{if(!m){m=!0;try{r.value.length===0?o&&await _(w):!c.value&&A&&await b(r.value[0].group_id)}finally{m=!1}}},D=async()=>{l.value=!0;try{const a=await h.getHistoryGroups(u);if(i){const g=p();if(g===null)r.value=a;else{const O=new Set(g.map(z=>z.group_id)),F=a.filter(z=>O.has(z.group_id));C(F),r.value=F}}else r.value=a;await R()}finally{l.value=!1}},_=async(a=w)=>{const g=await h.createHistoryGroup(u,a);return i&&W({group_id:g,group_title:a}),await D(),c.value!==g&&await b(g),g};return{groups:r,activeGroupId:c,messages:t,loading:l,loadGroups:D,createGroup:_,renameGroup:async(a,g)=>{await h.setHistoryGroupTitle(u,a,g);const O=r.value.find(F=>F.group_id===a);O&&(O.group_title=g),i&&C(r.value)},deleteGroup:async a=>{const g=r.value.findIndex(F=>F.group_id===a);if(await h.deleteHistoryGroup(u,a),r.value=r.value.filter(F=>F.group_id!==a),i&&C(r.value),c.value!==a)return;const O=r.value[g]??r.value[r.value.length-1];if(O){await b(O.group_id);return}o?await _(w):(c.value="",t.value=[])},selectGroup:b,loadMessages:P}},ie=e=>{const{api:u,defaultEntryId:w,entryGroup:G="智能助手",autoLoad:o=!0}=e,A=n.ref([]),y=n.ref(null),i=n.ref(!1),I=c=>c?typeof u.getFileUrl=="function"?u.getFileUrl(c):h.resolveRemoteFileUrl(c,"","/algorithm/get_file_data"):"",U=c=>{y.value=c},r=async()=>{var c;i.value=!0;try{let t=w||((c=y.value)==null?void 0:c.entry_id);if(!t)try{const p=await u.getDefaultLlmId();t=p==null?void 0:p.default_entry_id}catch(p){console.warn("[useAgent] 获取默认智能体 ID 失败:",p)}const l=await u.getLlmEntryListByRole({entry_group:G}),d=((l==null?void 0:l.values)||[]).filter(p=>p.entry_enable!==!1);if(A.value=d,t){const p=d.find(C=>C.entry_id===t);p?y.value=p:d.length>0&&(y.value=d[0])}else d.length>0&&!y.value&&(y.value=d[0])}finally{i.value=!1}};return o&&(n.getCurrentInstance()?n.onMounted(()=>{r()}):r()),{agentList:A,currentAgent:y,loading:i,getFileUrl:I,loadAgents:r,selectAgent:U}},Ae=(e={})=>{const u=e.parsers??[];let w=null,G;const o=ue({...e.chat,parsers:u,onFirstQuestion:({question:t,groupId:l})=>{G==null||G(l,t)}}),A=oe({...e.history,api:o.api,autoLoadMessages:!1,parsers:u});G=(t,l)=>{w=A.renameGroup(t,l).catch(m=>{var d;(d=e.onError)==null||d.call(e,m,"groups")})};const y=ie({...e.agent,api:o.api,autoLoad:!1}),i=(t,l)=>{var m;(m=e.onError)==null||m.call(e,t,l)},I=async()=>{try{await A.loadGroups()}catch(t){i(t,"groups")}},U=async t=>{try{await o.loadGroup(t)}catch(l){i(l,"messages")}},r=async()=>{try{await y.loadAgents()}catch(t){i(t,"agents")}},c=async t=>{var d;const l=typeof t=="string"?{text:t}:t;await o.submitQuestion({...l,entryId:(l==null?void 0:l.entryId)??((d=y.currentAgent.value)==null?void 0:d.entry_id)});const m=w;w=null,m&&await m,await I()};return n.watch(o.session,t=>{t&&(I(),r())}),n.watch(A.activeGroupId,t=>{t&&U(t)}),{chat:o,history:A,agent:y,parsers:u,messages:o.messages,question:o.question,incPrevQuestion:o.incPrevQuestion,talking:o.talking,loading:o.loading,session:o.session,groups:A.groups,activeGroupId:A.activeGroupId,historyLoading:A.loading,agentList:y.agentList,currentAgent:y.currentAgent,agentLoading:y.loading,hasMore:o.hasMore,loadMoreLoading:o.loadMoreLoading,loadGroup:U,loadOlder:o.loadOlder,refreshGroups:I,loadAgents:r,selectAgent:y.selectAgent,getFileUrl:y.getFileUrl,submitQuestion:c,sendWsMessage:o.sendWsMessage,stopQuestion:o.stopQuestion}};exports.useAgent=ie;exports.useChat=ue;exports.useChatSession=Ae;exports.useHistory=oe;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("vue"),E=require("wi-chat/parser"),T=require("wi-chat/request"),_e=e=>{const{api:t,interval:y=5*60*1e3,renew:w,onExpired:l,immediate:R=!0}=e,p=v.ref(!1),u=v.ref(0);let L=null,x=null;const S=async()=>{const d=w?await w().catch(()=>!1):!1;return d||l==null||l(),d},c=()=>x||(x=(async()=>{if(!t.pingLogin)return!0;try{const d=await t.pingLogin();return u.value=Date.now(),(d==null?void 0:d.is_login)===!1?S():!0}catch(d){return d instanceof T.AuthExpiredError?S():!0}finally{x=null}})(),x),n=()=>{L||(p.value=!0,L=setInterval(()=>void c(),y))},f=()=>{L&&clearInterval(L),L=null,p.value=!1};return R&&n(),v.getCurrentInstance()&&v.onBeforeUnmount(f),{active:p,lastPingAt:u,start:n,stop:f,pingNow:c}},j={get(e){try{return typeof localStorage<"u"?localStorage.getItem(e):null}catch{return null}},set(e,t){try{typeof localStorage<"u"&&localStorage.setItem(e,t)}catch{}},remove(e){try{typeof localStorage<"u"&&localStorage.removeItem(e)}catch{}}},Ge=e=>btoa(unescape(encodeURIComponent(e))),Ie=e=>decodeURIComponent(escape(atob(e))),de=24*60*60*1e3,Me=15*1e3,Re=e=>{let t=null;return()=>(t||(t=Promise.resolve().then(e).catch(()=>!1).finally(()=>{setTimeout(()=>t=null,0)})),t)},ye=e=>{if(!e||typeof e!="object")return!1;const t=e;return t.err_code==="AUTH"||t.error_code==="AUTH"||t.err_no_login===!0},ke=e=>({get(){const t=j.get(e);if(!t)return null;try{const y=JSON.parse(t);return y!=null&&y.encryptKey?y:null}catch{return null}},set(t){j.set(e,JSON.stringify(t))},clear(){j.remove(e)}}),be=e=>({get(){const t=j.get(e);if(!t)return null;try{const y=JSON.parse(Ie(t));return y!=null&&y.user&&(y!=null&&y.pass)?y:null}catch{return null}},set(t){j.set(e,Ge(JSON.stringify(t)))},clear(){j.remove(e)}}),Ue=()=>{let e=null;return{get:()=>e,set:t=>{e=t},clear:()=>{e=null}}},qe=()=>{let e=null;return{get:()=>e,set:t=>{e=t},clear:()=>{e=null}}},Te=(e,t)=>{if(!Number.isFinite(e)||e<=0||!Number.isFinite(t)||t<=e)throw new Error("登录密钥有效期必须大于保持登录窗口,且两者必须为正数");return{rememberDays:e,encryptKeyDays:t}},Ke=e=>{const t=e.sessionKey===void 0?"wi-chat-session":e.sessionKey,y=e.remember??!1,{rememberDays:w,encryptKeyDays:l}=Te(e.rememberDays??7,e.encryptKeyDays??10),R=e.touchInterval??30*60*1e3,p=e.touchMinInterval??6*60*60*1e3,u=e.keyStore??(y&&t?ke(`${t}-encrypt-key`):Ue()),L=e.credentialStore??(y&&t?be(`${t}-account`):qe()),x=t?`${t}-user`:null,S=y&&t?`${t}-signed-out`:null,c=()=>!!(S&&j.get(S)),n=()=>{S&&j.set(S,"1")},f=()=>{S&&j.remove(S)},d=v.ref(t?j.get(t)??"":""),s=v.ref(null);if(x)try{s.value=JSON.parse(j.get(x)||"null")}catch{s.value=null}const g=v.computed(()=>!!d.value),m=o=>{d.value=o.wisession||"",s.value=o,t&&j.set(t,d.value),x&&j.set(x,JSON.stringify(o)),f()},G=()=>{d.value="",s.value=null,t&&j.remove(t),x&&j.remove(x)},M=T.createRequest({baseURL:e.baseURL}),K=o=>T.createRequest({baseURL:e.baseURL,getWisession:()=>o});let I=0,P=null,D=0;const F=async({session:o,userId:a})=>{if(!o)return{ok:!1,reason:"missing"};const b=I;D=Date.now();try{const i=await T.makeEncryptLoginStatus(K(o),l);if(b!==I)return{ok:!1,reason:"superseded"};const h=i==null?void 0:i.encrypt_key;if(i!=null&&i.json_ok&&h){const J=await u.get(),B=await T.pwdEncrypt(String(h));if(b!==I)return{ok:!1,reason:"superseded"};const V=Date.now();return await u.set({encryptKey:B,userId:a!=null?String(a):(J==null?void 0:J.userId)||"",createdAt:V,expiresAt:Math.min(V+w*de,V+l*de),keyExpiresAt:V+l*de}),P=null,await L.clear(),{ok:!0,reason:"ok",session:o}}const ee=ye(i);return P&&await L.set(P),console.warn("[wi-chat auth] 签发登录密钥失败,回退账号密码兜底:",(i==null?void 0:i.json_msg)||(i==null?void 0:i.err_code)||""),{ok:!1,reason:ee?"credential_rejected":"login_failed",session:o}}catch(i){return b!==I?{ok:!1,reason:"superseded"}:i instanceof T.AuthExpiredError?(P&&await L.set(P),console.warn("[wi-chat auth] 签发登录密钥被后端拒绝(无权限),回退账号密码兜底"),{ok:!1,reason:"credential_rejected",session:o}):(console.warn("[wi-chat auth] 签发登录密钥网络异常,保留原有凭据:",i),{ok:!1,reason:"network_error",session:o})}},Y=async o=>{var b;const a=I;try{const i=await T.loginByEncryptKey(M,{encrypt_key:o.encryptKey,client:e.client});return a!==I?{ok:!1,reason:"superseded"}:{ok:!0,reason:"ok",session:i.wisession,userInfo:i}}catch(i){return a!==I?{ok:!1,reason:"superseded"}:i instanceof T.AuthExpiredError||ye((b=i==null?void 0:i.response)==null?void 0:b.data)?{ok:!1,reason:"credential_rejected"}:(console.warn("[wi-chat auth] 用登录密钥续期失败(保留凭据):",i),{ok:!1,reason:"network_error"})}},Q=async o=>{var b;const a=I;try{const i=await T.login(M,{user:o.user,pass:o.pass,client:e.client});return a!==I?{ok:!1,reason:"superseded"}:{ok:!0,reason:"ok",session:i.wisession,userInfo:i}}catch(i){return a!==I?{ok:!1,reason:"superseded"}:i instanceof T.AuthExpiredError||ye((b=i==null?void 0:i.response)==null?void 0:b.data)?{ok:!1,reason:"credential_rejected"}:(console.warn("[wi-chat auth] 用账号密码续期失败(保留凭据):",i),{ok:!1,reason:"network_error"})}};let A=null,k=0;const H=async()=>{var b,i;const o=await u.get();if(o!=null&&o.encryptKey){const h=await Y(o);if(h.ok)return m({...h.userInfo||{},wisession:h.session}),F({session:h.session||"",userId:(b=h.userInfo)==null?void 0:b.id}),h;if(h.reason==="superseded"||h.reason==="network_error")return h}const a=await L.get()??P;if(a!=null&&a.user&&(a!=null&&a.pass)){const h=await Q(a);return h.ok&&(m({...h.userInfo||{},wisession:h.session}),F({session:h.session||"",userId:(i=h.userInfo)==null?void 0:i.id})),h}return{ok:!1,reason:"missing"}};let U=null,N=-1;const W=o=>{if(!y)return Promise.resolve(d.value?{ok:!1,reason:"credential_rejected"}:{ok:!1,reason:"missing"});if(c())return Promise.resolve({ok:!1,reason:"missing"});const a=String(o||"");if(a&&(A!=null&&A.ok)&&A.session===a&&(A=null,k=0),A&&Date.now()-k<Me)return Promise.resolve(A);if(U&&N===I)return U;const b=I,i=H().finally(()=>{U===i&&(U=null,N=-1)}).then(h=>(h.reason==="superseded"||h.ok&&(A=h,k=Date.now()),h));return U=i,N=b,i},te=o=>o==="missing"||o==="credential_rejected",re=()=>{var o;d.value&&(G(),$.stop(),ue(),(o=e.onExpired)==null||o.call(e))},oe=async o=>{const a=await W(o);return a.ok?!0:(te(a.reason)&&re(),!1)},ne=T.createRequest({baseURL:e.baseURL,getWisession:()=>d.value,onAuthExpired:o=>oe(o==null?void 0:o.rejectedSession)}),ie=T.createChatApi(ne,{resumable:e.resumable??!0,refreshSession:()=>oe()}),$=_e({api:ie,interval:e.pingInterval||5*60*1e3,renew:async()=>{if(!d.value)return!1;const o=await W(d.value);return o.ok||!te(o.reason)},onExpired:()=>re(),immediate:!1}),le=async()=>await u.get()||await L.get()?!0:!!P,X=async(o=p)=>{var h;const a=d.value;if(!a)return await le()?W():{ok:!1,reason:"missing"};if(!y)return{ok:!0,reason:"ok",session:a};if(c())return{ok:!1,reason:"missing"};const b=await u.get();if(b){if(o>0&&Date.now()-b.createdAt<o)return{ok:!0,reason:"ok",session:a}}else if(o>0&&Date.now()-D<o)return{ok:!0,reason:"ok",session:a};const i=await F({session:a,userId:(h=s.value)==null?void 0:h.id});return i.ok?(A={ok:!0,reason:"ok",session:a},k=Date.now(),i):i.reason==="credential_rejected"?await le()?{ok:!0,reason:"ok",session:a}:W(a):i};let Z=null,se=!1;const ce=async()=>{if(!(se||!d.value)){se=!0;try{const o=await X();!o.ok&&te(o.reason)&&re()}finally{se=!1}}},ae=()=>{!y||R<=0||Z||(Z=setInterval(()=>void ce(),R))},ue=()=>{Z&&clearInterval(Z),Z=null},r=()=>{e.pingInterval!==0&&$.start()},C=async(o,a,b={})=>{const i={...b,user:o,pass:a,client:e.client},h=await T.login(M,i);return m(h),y?(P={user:o,pass:a},await F({session:h.wisession||"",userId:h.id}),r(),ae(),h):(r(),h)},_=async()=>{if(!y)return!1;const o=await W();return o.ok&&(r(),ae(),X()),o.ok},q=async(o=!0)=>{n(),I+=1,G(),$.stop(),ue(),A=null,k=0,U=null,N=-1,o&&(P=null,await u.clear(),await L.clear())};return d.value&&(r(),ae(),$.pingNow()),{session:d,userInfo:s,isLoggedIn:g,request:ne,api:ie,keepAlive:$,login:C,autoLogin:_,renew:async()=>(await W()).ok,restore:W,touch:X,logout:q}},Oe=e=>{const t={requestId:e,sender:null,queue:[],closed:!1,reply:y=>Le(t,y)};return t},Le=(e,t,y)=>{if(e.closed)return!1;const w=typeof t=="string"?t:JSON.stringify(t)??"";return e.sender?e.sender(w,y)!==!1:(e.queue.push({payloadText:w,chunkSize:y}),!0)},Se=e=>{e.closed||(e.closed=!0,e.queue.length=0,e.sender=null,E.expirePendingClarificationsForReply(e.reply))},ge=e=>{const t=e.login,y=e.defaultGroupTitle??"新对话",w=e.lastCount??10,l=e.autoSetGroupTitleOnFirstQuestion??!0,R={beforeKnowledgeRender:e.beforeKnowledgeRender,parsers:e.parsers,actionExecute:{...e.actionExecute,reply:()=>!1}},p=v.ref(""),u=v.ref([]),L=v.ref(""),x=v.ref(e.incPrevQuestion??"Y"),S=v.ref(!1),c=v.ref(!1),n=v.ref(""),f=v.ref(!1),d=v.ref(""),s=v.ref(!0),g=v.ref(!1),m=v.ref(0),G=e.api?null:T.createRequest({baseURL:e.baseURL??"",getWisession:()=>p.value,onAuthExpired:()=>I()}),M=e.api??T.createChatApi(G,{resumable:e.resumable,refreshSession:()=>I()}),K=G?T.createRequest({baseURL:e.baseURL??""}):null,I=Re(async()=>{if(e.onAuthExpired)return e.onAuthExpired();if(!G||!t||!K)return!1;const r=await T.login(K,t);return p.value=r.wisession||"",!!p.value}),P=(r,C)=>{var _;r&&((_=e.onRunningChange)==null||_.call(e,r,C))};let D=null,F=null,Y=0,Q=0,A=0,k=null;const H=async()=>{if(d.value="",!G||!t){f.value=!0;return}try{const r=await T.login(K??G,t);return p.value=r.wisession||"",f.value=!0,r}catch(r){throw d.value=r instanceof Error?r.message:String(r),r}},U=r=>r===Y,N=r=>{typeof URL>"u"||typeof URL.revokeObjectURL!="function"||r.forEach(C=>{C.role!=="user"||!C.attachments||C.attachments.forEach(_=>{var o;const q=(o=_.attachContent)==null?void 0:o.url;q&&q.startsWith("blob:")&&URL.revokeObjectURL(q)})})},W=r=>({beforeKnowledgeRender:e.beforeKnowledgeRender,parsers:e.parsers,actionExecute:{...e.actionExecute,reply:r.reply}}),te=async r=>{const C=++Q;A+=1,S.value=!0,N(u.value),k&&E.clearPendingClarifications(k.reply),u.value=[],n.value=r,s.value=!0,g.value=!1,m.value=0;const _=[],q=()=>{const a=[];_.forEach(b=>{a.push(b.user),b.assistant&&a.push(b.assistant)}),C===Q&&(u.value=a)},o=a=>{C===Q&&(a.type==="users"?(_.length=0,a.users.forEach(b=>_.push({user:b}))):_[a.index]&&(a.user&&(_[a.index].user=a.user),_[a.index].assistant=a.assistant),q())};try{await E.loadGroupMessagesByStep(M,r,w,o,0,R),q(),C===Q&&(m.value=_.length,_.length<w&&(s.value=!1))}finally{A-=1,A<=0&&(A=0,S.value=!1)}},re=async()=>{if(!n.value||S.value||!s.value||g.value)return;const r=n.value,C=Q,_=m.value;g.value=!0;try{const q=await E.loadGroupMessagesByStep(M,r,w,void 0,_,R),o=q.filter(a=>a.role==="user").length;if(o<w&&(s.value=!1),C===Q&&n.value===r){const a=new Set;u.value.forEach(i=>{i.historyId&&a.add(i.historyId),i.id&&a.add(i.id)});const b=q.filter(i=>!(i.historyId&&a.has(i.historyId)||i.id&&a.has(i.id)));u.value=[...b,...u.value],m.value+=o}}finally{g.value=!1}},oe=async(r=y)=>{const C=await E.createHistoryGroup(M,r);return n.value=C,C},ne=(r=!0)=>{var C;r!==!1&&c.value&&n.value&&((C=M.stopChat)==null||C.call(M,n.value)),Y+=1,Q+=1,F&&(F.stopped=!0,F.thinking.expanded=!1,X(F)),D==null||D.abort(),D=null,k&&Se(k),k=null,F=null,c.value=!1},ie=()=>{F&&(F.error=!0,F.thinking.expanded=!1,X(F))},$=async(r,C,_,q)=>{const o=Y+1;Y=o,Q+=1;const a=Oe(o);k=a;const b=W(a),i=q||n.value;F=r,c.value=!0,P(i,!0);let h=!1;try{D=new AbortController;const ee=await _(J=>{if(!U(o)||a.closed)return;a.sender=J;const B=a.queue;a.queue=[],B.forEach(({payloadText:V,chunkSize:fe})=>J(V,fe))},D.signal);await E.consumeStream(ee,J=>{var B;U(o)&&(le(r,C,J,b),(B=e.onChunk)==null||B.call(e,J))}),U(o)&&(h=!0,r.thinking.expanded=!1,X(r))}catch(ee){U(o)&&!T.isCancelError(ee)&&ie()}finally{Se(a),k===a&&(k=null),P(i,!1),U(o)&&(c.value=!1,D=null,F=null)}return h&&Z(r),h},le=(r,C,_,q)=>{if(_.mode==="history_id"){const a=typeof _.value=="object"&&_.value!==null?_.value.history_id:_.value;a&&(C&&(C.historyId=String(a)),r.historyId=String(a),r.answer.id=String(a));return}if(_.mode==="start"){const a=E.parseServerStartTime(_.value??_.time,r.runStartAt);a!=null&&r.runStartAt!=null&&(r.runStartAt=a);return}if(_.mode==="history_answer"){const a=E.normalizeAnswer(_.value,r.historyId??"",r.answer.question??"",R);r.answer=a,r.thinking.steps=E.collectThinkingSteps(a);return}E.applyAnswerChunk(r.answer,_,q).includes("deep_thinking")&&(r.thinking.steps=E.collectThinkingSteps(r.answer)),_.mode==="finish"&&(r.thinking.expanded=!1)},X=r=>{!r||r.runStartAt==null||(r.runMs=Math.max(0,Date.now()-r.runStartAt),delete r.runStartAt)},Z=async r=>{if(!(!e.syncMetaOnFinish||!r.historyId))try{const C=await M.getHistoryAnswer(r.historyId);E.mergeAnswerMeta(r.answer,C);const _=E.readAnswerMeta(r.answer).runMs;_!=null&&(r.runMs=_)}catch{}},se=async r=>{var we,pe;const C=typeof r=="string"?{text:r}:r||{},{text:_,entryId:q,files:o,attachments:a,extArgs:b,...i}=C,h=(_!==void 0?_:L.value).trim(),ee=b??e.extArgs??{},J=o&&o.length>0?o:(a??[]).map(O=>{var z;return(z=O.attachContent)==null?void 0:z.raw}).filter(O=>!!O);if(!h||c.value||!n.value)return;const B=n.value,V=a||(o||[]).map(O=>{var me;const z=O.name.includes(".")&&((me=O.name.split(".").pop())==null?void 0:me.toLowerCase())||"";return{type:"file",name:O.name,description:z?z.toUpperCase():"",attachContent:{file_name:O.name,size:O.size,suffix:z,raw:O}}}),fe=m.value===0&&!u.value.some(O=>O.role==="user"),ve=v.reactive({id:E.nextLocalMessageId("user"),role:"user",content:h,attachments:V.length>0?V:void 0});u.value.push(ve);const he=v.reactive({id:E.nextLocalMessageId("answer"),role:"assistant",answer:E.createEmptyAnswerValues("",h),error:!1,stopped:!1,runStartAt:Date.now(),thinking:{steps:[],expanded:!0}});if(u.value.push(he),L.value="",(we=e.onSubmitQuestion)==null||we.call(e,h),fe){const O=E.buildChatTitle(h);e.onFirstQuestion?e.onFirstQuestion({question:O,groupId:B}):l&&O&&M.setHistoryGroupTitle(B,O).catch(()=>{})}m.value+=1,await $(he,ve,(O,z)=>M.questionStream({...i,question:h,historyGroupId:B,entryId:q,files:J,ext_args:JSON.stringify(ee),incPrevQuestion:x.value,onOpen:O},z))&&((pe=e.onFinish)==null||pe.call(e))},ce=async r=>{var b;if(c.value||!(r!=null&&r.history_id)||n.value&&r.history_group_id&&r.history_group_id!==n.value)return!1;!n.value&&r.history_group_id&&(n.value=r.history_group_id);const C=u.value.find(i=>i.role==="user"&&i.historyId===r.history_id);u.value=u.value.filter(i=>!(i.role==="assistant"&&i.historyId===r.history_id));let _=C??null;_||(_=v.reactive({id:r.history_id,historyId:r.history_id,role:"user",content:r.question??""}),u.value.push(_),m.value+=1);const q=v.reactive({id:`${r.history_id}-answer`,historyId:r.history_id,role:"assistant",answer:E.createEmptyAnswerValues(r.history_id,r.question??""),error:!1,stopped:!1,runStartAt:Date.now(),thinking:{steps:[],expanded:!0}}),o=u.value.indexOf(_);u.value.splice(o+1,0,q);const a=await $(q,_,(i,h)=>M.questionStream({question:r.question??"",historyGroupId:r.history_group_id||n.value,resumeTask:r,onOpen:i},h),r.history_group_id||n.value);return a&&((b=e.onFinish)==null||b.call(e)),a},ae=(r,C)=>!c.value||!k?!1:Le(k,r,C),ue=e.autoLogin!==!1?H().then(()=>{}).catch(()=>{}):Promise.resolve();return v.getCurrentScope()&&v.onScopeDispose(()=>{ne(!1),N(u.value)}),{messages:u,question:L,incPrevQuestion:x,talking:c,loading:S,session:p,autoLoginDone:f,autoLoginError:d,loginDone:ue,historyGroupId:n,selfRequest:G,api:M,doAutoLogin:H,loadGroup:te,loadOlder:re,hasMore:s,loadMoreLoading:g,createGroup:oe,submitQuestion:se,sendWsMessage:ae,stopQuestion:ne,resumeTask:ce,renewSession:I}},Fe="wi-chat-history-groups",Ce=e=>{var Q;const{api:t,defaultGroupTitle:y="新对话",lastCount:w=10,ensureGroup:l=!0,autoSelectFirst:R=!0,autoLoadMessages:p=!0}=e,u=e.persistGroups??!1,L=e.storageKey??Fe,x=e.beforeKnowledgeRender||(Q=e.parsers)!=null&&Q.length?{beforeKnowledgeRender:e.beforeKnowledgeRender,parsers:e.parsers}:void 0,S=v.ref([]),c=v.ref(""),n=v.ref([]),f=v.ref(!1);let d=!1,s=null;const g=()=>{if(s===!1)return null;let A;try{A=localStorage.getItem(L)}catch{return s=!1,null}if(A===null)return[];try{const k=JSON.parse(A);return Array.isArray(k)?k:[]}catch{return[]}},m=A=>{if(s!==!1)try{localStorage.setItem(L,JSON.stringify(A))}catch{s=!1}},G=A=>{const k=g();k!==null&&m([...k,A])},M=async(A,k=w)=>{f.value=!0;try{n.value=A?await E.loadGroupMessages(t,A,k,0,x):[]}finally{f.value=!1}},K=async A=>{c.value=A,p&&await M(A)},I=async()=>{if(!d){d=!0;try{S.value.length===0?l&&await D(y):!c.value&&R&&await K(S.value[0].group_id)}finally{d=!1}}},P=async()=>{f.value=!0;try{const A=await E.getHistoryGroups(t);if(u){const k=g();if(k===null)S.value=A;else{const H=new Set(k.map(N=>N.group_id)),U=A.filter(N=>H.has(N.group_id));m(U),S.value=U}}else S.value=A;await I()}finally{f.value=!1}},D=async(A=y)=>{const k=await E.createHistoryGroup(t,A);return u&&G({group_id:k,group_title:A}),await P(),c.value!==k&&await K(k),k};return{groups:S,activeGroupId:c,messages:n,loading:f,loadGroups:P,createGroup:D,renameGroup:async(A,k)=>{await E.setHistoryGroupTitle(t,A,k);const H=S.value.find(U=>U.group_id===A);H&&(H.group_title=k),u&&m(S.value)},deleteGroup:async A=>{const k=S.value.findIndex(U=>U.group_id===A);if(await E.deleteHistoryGroup(t,A),S.value=S.value.filter(U=>U.group_id!==A),u&&m(S.value),c.value!==A)return;const H=S.value[k]??S.value[S.value.length-1];if(H){await K(H.group_id);return}l?await D(y):(c.value="",n.value=[])},selectGroup:K,loadMessages:M}},xe=e=>{const{api:t,defaultEntryId:y,entryGroup:w="智能助手",autoLoad:l=!0}=e,R=v.ref([]),p=v.ref(null),u=v.ref(!1),L=c=>c?typeof t.getFileUrl=="function"?t.getFileUrl(c):E.resolveRemoteFileUrl(c,"","/algorithm/get_file_data"):"",x=c=>{p.value=c},S=async()=>{var c;u.value=!0;try{let n=y||((c=p.value)==null?void 0:c.entry_id);if(!n)try{const g=await t.getDefaultLlmId();n=g==null?void 0:g.default_entry_id}catch(g){console.warn("[useAgent] 获取默认智能体 ID 失败:",g)}const f=await t.getLlmEntryListByRole({entry_group:w}),s=((f==null?void 0:f.values)||[]).filter(g=>g.entry_enable!==!1);if(R.value=s,n){const g=s.find(m=>m.entry_id===n);g?p.value=g:s.length>0&&(p.value=s[0])}else s.length>0&&!p.value&&(p.value=s[0])}finally{u.value=!1}};return l&&(v.getCurrentInstance()?v.onMounted(()=>{S()}):S()),{agentList:R,currentAgent:p,loading:u,getFileUrl:L,loadAgents:S,selectAgent:x}},Ee=e=>{const{api:t,interval:y=5e3,immediate:w=!1}=e,l=v.ref([]),R=v.ref(new Set);let p=null,u=null;const L=v.computed(()=>{const s=new Set(R.value);return l.value.forEach(g=>g.history_group&&s.add(String(g.history_group))),s}),x=s=>!!s&&L.value.has(s),S=(s,g)=>{if(!s)return;const m=new Set(R.value);if(g?m.add(s):m.delete(s),R.value=m,!g){const G=u;(async()=>(G&&await G,await n()))()}},c=s=>l.value.find(g=>String(g.history_group)===s&&g.is_connected!==!0&&!R.value.has(s)),n=()=>u||(u=(async()=>{if(!t.getChatTaskList)return l.value;try{const s=(await t.getChatTaskList()).filter(g=>g&&g.is_stop!==!0);if(l.value=s,e.onUnknownGroups&&e.isKnownGroup){const g=s.map(m=>String(m.history_group)).filter(m=>m&&!e.isKnownGroup(m));g.length&&e.onUnknownGroups(g)}}catch{}finally{u=null}return l.value})(),u),f=()=>{p||!y||(n(),p=setInterval(()=>void n(),y))},d=()=>{p&&clearInterval(p),p=null,l.value=[]};return w&&f(),v.getCurrentInstance()&&v.onBeforeUnmount(d),{tasks:l,runningIds:L,isRunning:x,setLocalRunning:S,findResumableTask:c,refresh:n,start:f,stop:d}},Pe=e=>{const{api:t,maxRooms:y=10}=e,w=v.shallowReactive(new Map),l=v.ref(""),R=Ee({api:t,interval:e.taskPollInterval??5e3,onUnknownGroups:e.onUnknownGroups,isKnownGroup:e.isKnownGroup}),p=n=>{if(w.size<=y)return;const f=[...w.entries()].filter(([d,s])=>d!==l.value&&d!==n&&!s.chat.talking.value).sort((d,s)=>d[1].touchedAt-s[1].touchedAt);for(;w.size>y&&f.length;){const[d]=f.shift();x(d)}},u=n=>{const f=w.get(n);if(f)return f.touchedAt=Date.now(),f.chat;const d=v.effectScope(!0),s=d.run(()=>{var m;return ge({...(m=e.roomOptions)==null?void 0:m.call(e,n),api:t,autoLogin:!1,parsers:e.parsers,beforeKnowledgeRender:e.beforeKnowledgeRender,actionExecute:e.actionExecute,lastCount:e.lastCount,syncMetaOnFinish:!0,onRunningChange:R.setLocalRunning})}),g={chat:s,scope:d,loaded:s.loadGroup(n).catch(()=>{}),touchedAt:Date.now()};return w.set(n,g),p(n),s},L=async n=>{var s;if(l.value=n,!n)return;const f=u(n);if(await((s=w.get(n))==null?void 0:s.loaded),f.talking.value)return;await R.refresh();const d=R.findResumableTask(n);d&&l.value===n&&f.resumeTask({history_id:d.history_id,history_group_id:String(d.history_group),question:d.question})},x=n=>{const f=w.get(n);f&&(f.chat.stopQuestion(!1),f.scope.stop(),w.delete(n),l.value===n&&(l.value=""))},S=()=>{[...w.keys()].forEach(x),R.stop()},c=v.computed(()=>{var n;return l.value?((n=w.get(l.value))==null?void 0:n.chat)??null:null});return v.getCurrentScope()&&v.onScopeDispose(S),{activeId:l,active:c,running:R,getRoom:u,open:L,dispose:x,disposeAll:S}},je=e=>{if(!e||typeof localStorage>"u")return{};try{const t=JSON.parse(localStorage.getItem(e)||"{}");return t&&typeof t=="object"?t:{}}catch{return{}}},De=(e,t)=>{if(!(!e||typeof localStorage>"u"))try{localStorage.setItem(e,JSON.stringify(t))}catch{}},Qe=e=>{const t=e.storageKey===void 0?"wi-chat-room-llm":e.storageKey,y=v.ref([]),w=v.ref(!1),l=v.ref(je(t)),R=v.computed(()=>new Set(y.value.flatMap(s=>(s.children??[]).map(g=>g.id)))),p=s=>{l.value=s,De(t,s)};let u=null;const L=()=>w.value?Promise.resolve():u||(u=(async()=>{var s,g;try{const m=await((g=(s=e.api).getLlmInfoList)==null?void 0:g.call(s));if(!m)return;const G=m.connections??[];y.value=(m.factorys??[]).map(K=>({id:K.factory_id,name:K.factory_title,type:"factory",children:G.filter(I=>I.factory_id===K.factory_id).map(I=>({id:I.connect_id,name:I.connect_title,type:"connection"}))})).filter(K=>K.children.length>0),w.value=!0;const M=Object.entries(l.value).filter(([,K])=>R.value.has(K));M.length!==Object.keys(l.value).length&&p(Object.fromEntries(M))}catch{}finally{u=null}})(),u),x=s=>!!s&&(!w.value||R.value.has(s));return{llmTree:y,loaded:w,roomLlmMap:l,validIds:R,load:L,resolve:(s,g)=>{const m=s?l.value[s]:"";return m&&x(m)?m:g||""},select:(s,g,m)=>{if(!s)return;const G={...l.value};g&&g!==m?G[s]=g:delete G[s],p(G)},migrate:(s,g)=>{const m=l.value[s];if(!m||s===g)return;const G={...l.value,[g]:m};delete G[s],p(G)},nameOf:s=>{var g;if(!s)return"";for(const m of y.value){const G=(g=m.children)==null?void 0:g.find(M=>M.id===s);if(G)return G.name}return""},isUnavailable:s=>!!s&&w.value&&!R.value.has(s)}},Ae=async e=>{var w;if(typeof navigator<"u"&&((w=navigator.clipboard)!=null&&w.writeText))try{await navigator.clipboard.writeText(e);return}catch{}if(typeof document>"u")throw new Error("当前环境不支持剪贴板");const t=document.createElement("textarea");t.value=e,t.style.position="fixed",t.style.opacity="0",document.body.appendChild(t),t.select();const y=document.execCommand("copy");if(document.body.removeChild(t),!y)throw new Error("复制失败")},He=e=>{const{api:t,buildShareUrl:y,shareDays:w=1}=e,l=c=>!!E.collectAnswerMarkdown(c.answer),R=async(c,n=!1)=>{const f=E.collectAnswerMarkdown(c.answer);if(!f)return!1;try{return await Ae(n?f:E.markdownToPlainText(f)),!0}catch{return!1}},p=c=>E.readAnswerMeta(c.answer).state,u=new WeakSet;return{canCopy:l,copy:R,stateOf:p,toggleState:async(c,n)=>{if(!(!c.historyId||!t.setHistoryAnswerState||u.has(c))){u.add(c);try{const f=p(c)===n?null:n;await t.setHistoryAnswerState(c.historyId,f),c.answer.answer||(c.answer.answer={reports:[]}),c.answer.answer.state=f}finally{u.delete(c)}}},feedback:async(c,n)=>{!c.historyId||!n.trim()||!t.reportHistoryProblem||await t.reportHistoryProblem(c.historyId,n.trim())},share:async c=>{if(!c.historyId||!t.shareChatHistory)throw new Error("当前回答暂不支持分享");const n=await t.shareChatHistory([c.historyId],w),f=y(n);return await Ae(f),f}}},Ne=(e={})=>{const t=e.parsers??[];let y=null,w;const l=ge({...e.chat,parsers:t,onFirstQuestion:({question:n,groupId:f})=>{w==null||w(f,n)}}),R=Ce({...e.history,api:l.api,autoLoadMessages:!1,parsers:t});w=(n,f)=>{y=R.renameGroup(n,f).catch(d=>{var s;(s=e.onError)==null||s.call(e,d,"groups")})};const p=xe({...e.agent,api:l.api,autoLoad:!1}),u=(n,f)=>{var d;(d=e.onError)==null||d.call(e,n,f)},L=async()=>{try{await R.loadGroups()}catch(n){u(n,"groups")}},x=async n=>{try{await l.loadGroup(n)}catch(f){u(f,"messages")}},S=async()=>{try{await p.loadAgents()}catch(n){u(n,"agents")}},c=async n=>{var s;const f=typeof n=="string"?{text:n}:n;await l.submitQuestion({...f,entryId:(f==null?void 0:f.entryId)??((s=p.currentAgent.value)==null?void 0:s.entry_id)});const d=y;y=null,d&&await d,await L()};return v.watch(l.session,n=>{n&&(L(),S())}),v.watch(R.activeGroupId,n=>{n&&x(n)}),{chat:l,history:R,agent:p,parsers:t,messages:l.messages,question:l.question,incPrevQuestion:l.incPrevQuestion,talking:l.talking,loading:l.loading,session:l.session,groups:R.groups,activeGroupId:R.activeGroupId,historyLoading:R.loading,agentList:p.agentList,currentAgent:p.currentAgent,agentLoading:p.loading,hasMore:l.hasMore,loadMoreLoading:l.loadMoreLoading,loadGroup:x,loadOlder:l.loadOlder,refreshGroups:L,loadAgents:S,selectAgent:p.selectAgent,getFileUrl:p.getFileUrl,submitQuestion:c,sendWsMessage:l.sendWsMessage,stopQuestion:l.stopQuestion}};exports.createLocalCredentialStore=be;exports.createLocalKeyCredentialStore=ke;exports.createRenewer=Re;exports.useAgent=xe;exports.useAnswerActions=He;exports.useChat=ge;exports.useChatAuth=Ke;exports.useChatRooms=Pe;exports.useChatSession=Ne;exports.useHistory=Ce;exports.useKeepAlive=_e;exports.useLlm=Qe;exports.useRunningGroups=Ee;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -9,5 +9,17 @@ export { useHistory } from './useHistory';
9
9
  export type { UseHistoryOptions, UseHistoryReturn } from './useHistory';
10
10
  export { useAgent } from './useAgent';
11
11
  export type { UseAgentOptions, UseAgentReturn } from './useAgent';
12
+ export { useKeepAlive } from './useKeepAlive';
13
+ export type { UseKeepAliveOptions, UseKeepAliveReturn } from './useKeepAlive';
14
+ export { useRunningGroups } from './useRunningGroups';
15
+ export type { UseRunningGroupsOptions, UseRunningGroupsReturn } from './useRunningGroups';
16
+ export { useChatAuth, createLocalCredentialStore, createLocalKeyCredentialStore, createRenewer } from './useChatAuth';
17
+ export type { UseChatAuthOptions, UseChatAuthReturn, CredentialStore, RememberedCredential, KeyCredentialStore, RememberedKeyCredential, AuthRestoreResult, AuthRestoreReason, } from './useChatAuth';
18
+ export { useChatRooms } from './useChatRooms';
19
+ export type { UseChatRoomsOptions, UseChatRoomsReturn } from './useChatRooms';
20
+ export { useLlm } from './useLlm';
21
+ export type { LlmTreeNode, UseLlmOptions, UseLlmReturn } from './useLlm';
22
+ export { useAnswerActions } from './useAnswerActions';
23
+ export type { UseAnswerActionsOptions, UseAnswerActionsReturn } from './useAnswerActions';
12
24
  export { useChatSession } from './useChatSession';
13
25
  export type { UseChatSessionAgentOptions, UseChatSessionChatOptions, UseChatSessionErrorScope, UseChatSessionHistoryOptions, UseChatSessionOptions, UseChatSessionReturn, } from './useChatSession';