wi-chat 0.6.1 → 0.6.2

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 (59) hide show
  1. package/dist/core/index.cjs +1 -1
  2. package/dist/core/index.js +273 -261
  3. package/dist/core/useChat.d.ts +61 -12
  4. package/dist/index.cjs +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +33 -33
  7. package/dist/mobile-ui/chat/ChatContainer.vue.d.ts +6 -6
  8. package/dist/mobile-ui/chat/ChatMessagesView.vue.d.ts +6 -6
  9. package/dist/mobile-ui/index.cjs +1 -1
  10. package/dist/mobile-ui/index.js +104 -104
  11. package/dist/mobile-ui/inputbox/Inputbox.vue.d.ts +5 -5
  12. package/dist/page-context/index.js +2 -4
  13. package/dist/parser/answerCom/actionExecute/actionProtocol.d.ts +1 -7
  14. package/dist/parser/answerCom/actionExecute/clarification.d.ts +15 -3
  15. package/dist/parser/answerCom/actionExecute/constants.d.ts +10 -0
  16. package/dist/parser/answerCom/actionExecute/parseCollectClarifications.d.ts +3 -2
  17. package/dist/parser/answerCom/actionExecute/parseHostAction.d.ts +3 -2
  18. package/dist/parser/answerCom/actionExecute/types.d.ts +3 -3
  19. package/dist/parser/index.cjs +2 -2
  20. package/dist/parser/index.d.ts +2 -2
  21. package/dist/parser/index.js +216 -258
  22. package/dist/parser/registry.d.ts +1 -1
  23. package/dist/renderers/aiAnswer/AiAnswerBubble.vue.d.ts +4 -4
  24. package/dist/renderers/clarification/ClarificationCard.vue.d.ts +3 -3
  25. package/dist/renderers/deepThinking/DeepThinkingSteps.vue.d.ts +4 -4
  26. package/dist/renderers/hostAction/HostActionStatus.vue.d.ts +3 -3
  27. package/dist/renderers/iframePage/IframePage.vue.d.ts +3 -3
  28. package/dist/renderers/index.cjs +1 -1
  29. package/dist/renderers/index.js +484 -498
  30. package/dist/renderers/knowledgeStream/KnowledgeStreamResult.vue.d.ts +3 -3
  31. package/dist/renderers/outputFile/OutputFile.vue.d.ts +3 -3
  32. package/dist/renderers/style.css +1 -1
  33. package/dist/request/index.cjs +2 -2
  34. package/dist/request/index.js +6 -13
  35. package/dist/request/ws.d.ts +3 -3
  36. package/dist/right-panel/RightPanel.vue.d.ts +6 -6
  37. package/dist/right-panel/RightPanelIcon.vue.d.ts +4 -4
  38. package/dist/right-panel/RightPanelTabs.vue.d.ts +5 -5
  39. package/dist/right-panel/index.cjs +1 -1
  40. package/dist/right-panel/index.js +397 -416
  41. package/dist/right-panel/panels/newtab/NewTabPanel.vue.d.ts +4 -4
  42. package/dist/right-panel/panels/web/WebPanel.vue.d.ts +3 -3
  43. package/dist/right-panel/shared/BrowserToolbar.vue.d.ts +3 -3
  44. package/dist/right-panel/shared/RightPanelToolList.vue.d.ts +5 -5
  45. package/dist/theme/index.js +2 -4
  46. package/dist/tools/index.cjs +2 -2
  47. package/dist/tools/index.js +10 -19
  48. package/dist/tools/markdown/MarkdownContent.vue.d.ts +5 -5
  49. package/dist/tools/useAutoScroll.d.ts +3 -3
  50. package/dist/web-ui/attach/AttachmentCard.vue.d.ts +6 -6
  51. package/dist/web-ui/attach/AttachmentList.vue.d.ts +6 -6
  52. package/dist/web-ui/chat/ChatContainer.vue.d.ts +6 -6
  53. package/dist/web-ui/chat/ChatMessagesView.vue.d.ts +6 -6
  54. package/dist/web-ui/envswitch/EnvSwitch.vue.d.ts +5 -5
  55. package/dist/web-ui/index.cjs +1 -1
  56. package/dist/web-ui/index.js +630 -635
  57. package/dist/web-ui/inputbox/Inputbox.vue.d.ts +7 -7
  58. package/dist/web-ui/recordset/RecordsetTable.vue.d.ts +4 -4
  59. package/package.json +2 -1
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("vue"),p=require("wi-chat/parser"),X=require("wi-chat/request"),ne=e=>{const w=e.login,b=e.defaultGroupTitle??"新对话",A=e.lastCount??10,i=e.autoSetGroupTitleOnFirstQuestion??!0,m={beforeKnowledgeRender:e.beforeKnowledgeRender,parsers:e.parsers,actionExecute:{...e.actionExecute,reply:s=>ee(s)}},v=l.ref(""),o=l.ref([]),I=l.ref(""),q=l.ref(e.incPrevQuestion??"Y"),r=l.ref(!1),c=l.ref(!1),t=l.ref(""),u=l.ref(!1),L=l.ref(""),d=l.ref(!0),y=l.ref(!1),x=l.ref(0),D=e.api?null:X.createRequest({baseURL:e.baseURL??"",getWisession:()=>v.value}),T=e.api??X.createChatApi(D);let C=null,M=null,H=0,S=0,V=0,B=null,P=[];const a=async()=>{if(L.value="",!D||!w){u.value=!0;return}try{const s=await X.login(D,w);return v.value=s.wisession||"",u.value=!0,s}catch(s){throw L.value=s instanceof Error?s.message:String(s),s}},n=s=>s===H,R=s=>{typeof URL>"u"||typeof URL.revokeObjectURL!="function"||s.forEach(G=>{G.role!=="user"||!G.attachments||G.attachments.forEach(h=>{var _;const E=(_=h.attachContent)==null?void 0:_.url;E&&E.startsWith("blob:")&&URL.revokeObjectURL(E)})})},F=async s=>{const G=++S;V+=1,r.value=!0,R(o.value),p.clearPendingClarifications(),o.value=[],t.value=s,d.value=!0,y.value=!1,x.value=0;const h=[],E=()=>{const g=[];h.forEach(O=>{g.push(O.user),O.assistant&&g.push(O.assistant)}),G===S&&(o.value=g)},_=g=>{G===S&&(g.type==="users"?(h.length=0,g.users.forEach(O=>h.push({user:O}))):h[g.index]&&(g.user&&(h[g.index].user=g.user),h[g.index].assistant=g.assistant),E())};try{await p.loadGroupMessagesByStep(T,s,A,_,0,m),E(),G===S&&(x.value=h.length,h.length<A&&(d.value=!1))}finally{V-=1,V<=0&&(V=0,r.value=!1)}},Y=async()=>{if(!t.value||r.value||!d.value||y.value)return;const s=t.value,G=S,h=x.value;y.value=!0;try{const E=await p.loadGroupMessagesByStep(T,s,A,void 0,h,m),_=E.filter(g=>g.role==="user").length;if(_<A&&(d.value=!1),G===S&&t.value===s){const g=new Set;o.value.forEach(Q=>{Q.historyId&&g.add(Q.historyId),Q.id&&g.add(Q.id)});const O=E.filter(Q=>!(Q.historyId&&g.has(Q.historyId)||Q.id&&g.has(Q.id)));o.value=[...O,...o.value],x.value+=_}}finally{y.value=!1}},ie=async(s=b)=>{const G=await p.createHistoryGroup(T,s);return t.value=G,G},$=()=>{H+=1,S+=1,M&&(M.stopped=!0,M.thinking.expanded=!1),C==null||C.abort(),C=null,B=null,P=[],p.clearPendingClarifications(),M=null,c.value=!1},oe=()=>{M&&(M.error=!0,M.thinking.expanded=!1)},ce=async s=>{var ae,se;const G=typeof s=="string"?{text:s}:s||{},{text:h,entryId:E,files:_,attachments:g,extArgs:O,...Q}=G,j=(h!==void 0?h:I.value).trim(),de=O??e.extArgs??{},ge=_&&_.length>0?_:(g??[]).map(k=>{var z;return(z=k.attachContent)==null?void 0:z.raw}).filter(k=>!!k);if(!j||c.value||!t.value)return;const K=H+1;H=K,S+=1;let te=!1;try{c.value=!0;const k=t.value,z=g||(_||[]).map(f=>{var W;const J=f.name.includes(".")&&((W=f.name.split(".").pop())==null?void 0:W.toLowerCase())||"";return{type:"file",name:f.name,description:J?J.toUpperCase():"",attachContent:{file_name:f.name,size:f.size,suffix:J,raw:f}}}),ve=x.value===0&&!o.value.some(f=>f.role==="user"),Z=k,re=l.reactive({id:p.nextLocalMessageId("user"),role:"user",content:j,attachments:z.length>0?z:void 0});o.value.push(re);const U=l.reactive({id:p.nextLocalMessageId("answer"),role:"assistant",answer:p.createEmptyAnswerValues("",j),error:!1,stopped:!1,thinking:{steps:[],expanded:!0}});if(M=U,o.value.push(U),I.value="",(ae=e.onSubmitQuestion)==null||ae.call(e,j),ve&&Z){const f=p.buildChatTitle(j);e.onFirstQuestion?e.onFirstQuestion({question:f,groupId:Z}):i&&f&&T.setHistoryGroupTitle(Z,f).catch(()=>{})}C=new AbortController;const ye=await T.questionStream({...Q,question:j,historyGroupId:k,entryId:E,files:ge,ext_args:JSON.stringify(de),incPrevQuestion:q.value,onOpen:f=>{if(!n(K))return;B=f;const J=P;P=[],J.forEach(({payloadText:W,chunkSize:N})=>f(W,N))}},C.signal);x.value+=1,await p.consumeStream(ye,f=>{var W;if(!n(K))return;if(f.mode==="history_id"){const N=typeof f.value=="object"&&f.value!==null?f.value.history_id:f.value;N&&(re.historyId=String(N),U.historyId=String(N),U.answer&&(U.answer.id=String(N)))}p.applyAnswerChunk(U.answer,f,m).includes("deep_thinking")&&(U.thinking.steps=p.collectThinkingSteps(U.answer)),f.mode==="finish"&&(U.thinking.expanded=!1),(W=e.onChunk)==null||W.call(e,f)}),n(K)&&(U.thinking.expanded=!1),n(K)&&(te=!0)}catch(k){n(K)&&!X.isCancelError(k)&&oe()}finally{n(K)&&(c.value=!1,C=null,M=null,B=null,P=[])}te&&((se=e.onFinish)==null||se.call(e))},ee=(s,G)=>{if(!c.value)return!1;const h=typeof s=="string"?s:JSON.stringify(s)??"";return B?B(h,G):P.push({payloadText:h,chunkSize:G}),!0},fe=e.autoLogin!==!1?a().then(()=>{}).catch(()=>{}):Promise.resolve();return l.getCurrentInstance()&&l.onBeforeUnmount(()=>{$(),R(o.value)}),{messages:o,question:I,incPrevQuestion:q,talking:c,loading:r,session:v,autoLoginDone:u,autoLoginError:L,loginDone:fe,historyGroupId:t,selfRequest:D,api:T,doAutoLogin:a,loadGroup:F,loadOlder:Y,hasMore:d,loadMoreLoading:y,createGroup:ie,submitQuestion:ce,sendWsMessage:ee,stopQuestion:$}},he="wi-chat-history-groups",le=e=>{var P;const{api:w,defaultGroupTitle:b="新对话",lastCount:A=10,ensureGroup:i=!0,autoSelectFirst:m=!0,autoLoadMessages:v=!0}=e,o=e.persistGroups??!1,I=e.storageKey??he,q=e.beforeKnowledgeRender||(P=e.parsers)!=null&&P.length?{beforeKnowledgeRender:e.beforeKnowledgeRender,parsers:e.parsers}:void 0,r=l.ref([]),c=l.ref(""),t=l.ref([]),u=l.ref(!1);let L=!1,d=null;const y=()=>{if(d===!1)return null;let a;try{a=localStorage.getItem(I)}catch{return d=!1,null}if(a===null)return[];try{const n=JSON.parse(a);return Array.isArray(n)?n:[]}catch{return[]}},x=a=>{if(d!==!1)try{localStorage.setItem(I,JSON.stringify(a))}catch{d=!1}},D=a=>{const n=y();n!==null&&x([...n,a])},T=async(a,n=A)=>{u.value=!0;try{t.value=a?await p.loadGroupMessages(w,a,n,0,q):[]}finally{u.value=!1}},C=async a=>{c.value=a,v&&await T(a)},M=async()=>{if(!L){L=!0;try{r.value.length===0?i&&await S(b):!c.value&&m&&await C(r.value[0].group_id)}finally{L=!1}}},H=async()=>{u.value=!0;try{const a=await p.getHistoryGroups(w);if(o){const n=y();if(n===null)r.value=a;else{const R=new Set(n.map(Y=>Y.group_id)),F=a.filter(Y=>R.has(Y.group_id));x(F),r.value=F}}else r.value=a;await M()}finally{u.value=!1}},S=async(a=b)=>{const n=await p.createHistoryGroup(w,a);return o&&D({group_id:n,group_title:a}),await H(),c.value!==n&&await C(n),n};return{groups:r,activeGroupId:c,messages:t,loading:u,loadGroups:H,createGroup:S,renameGroup:async(a,n)=>{await p.setHistoryGroupTitle(w,a,n);const R=r.value.find(F=>F.group_id===a);R&&(R.group_title=n),o&&x(r.value)},deleteGroup:async a=>{const n=r.value.findIndex(F=>F.group_id===a);if(await p.deleteHistoryGroup(w,a),r.value=r.value.filter(F=>F.group_id!==a),o&&x(r.value),c.value!==a)return;const R=r.value[n]??r.value[r.value.length-1];if(R){await C(R.group_id);return}i?await S(b):(c.value="",t.value=[])},selectGroup:C,loadMessages:T}},ue=e=>{const{api:w,defaultEntryId:b,entryGroup:A="智能助手",autoLoad:i=!0}=e,m=l.ref([]),v=l.ref(null),o=l.ref(!1),I=c=>c?typeof w.getFileUrl=="function"?w.getFileUrl(c):p.resolveRemoteFileUrl(c,"","/algorithm/get_file_data"):"",q=c=>{v.value=c},r=async()=>{var c;o.value=!0;try{let t=b||((c=v.value)==null?void 0:c.entry_id);if(!t)try{const y=await w.getDefaultLlmId();t=y==null?void 0:y.default_entry_id}catch(y){console.warn("[useAgent] 获取默认智能体 ID 失败:",y)}const u=await w.getLlmEntryListByRole({entry_group:A}),d=((u==null?void 0:u.values)||[]).filter(y=>y.entry_enable!==!1);if(m.value=d,t){const y=d.find(x=>x.entry_id===t);y?v.value=y:d.length>0&&(v.value=d[0])}else d.length>0&&!v.value&&(v.value=d[0])}finally{o.value=!1}};return i&&(l.getCurrentInstance()?l.onMounted(()=>{r()}):r()),{agentList:m,currentAgent:v,loading:o,getFileUrl:I,loadAgents:r,selectAgent:q}},pe=(e={})=>{const w=e.parsers??[];let b=null,A;const i=ne({...e.chat,parsers:w,onFirstQuestion:({question:t,groupId:u})=>{A==null||A(u,t)}}),m=le({...e.history,api:i.api,autoLoadMessages:!1,parsers:w});A=(t,u)=>{b=m.renameGroup(t,u).catch(L=>{var d;(d=e.onError)==null||d.call(e,L,"groups")})};const v=ue({...e.agent,api:i.api,autoLoad:!1}),o=(t,u)=>{var L;(L=e.onError)==null||L.call(e,t,u)},I=async()=>{try{await m.loadGroups()}catch(t){o(t,"groups")}},q=async t=>{try{await i.loadGroup(t)}catch(u){o(u,"messages")}},r=async()=>{try{await v.loadAgents()}catch(t){o(t,"agents")}},c=async t=>{var d;const u=typeof t=="string"?{text:t}:t;await i.submitQuestion({...u,entryId:(u==null?void 0:u.entryId)??((d=v.currentAgent.value)==null?void 0:d.entry_id)});const L=b;b=null,L&&await L,await I()};return l.watch(i.session,t=>{t&&(I(),r())}),l.watch(m.activeGroupId,t=>{t&&q(t)}),{chat:i,history:m,agent:v,parsers:w,messages:i.messages,question:i.question,incPrevQuestion:i.incPrevQuestion,talking:i.talking,loading:i.loading,session:i.session,groups:m.groups,activeGroupId:m.activeGroupId,historyLoading:m.loading,agentList:v.agentList,currentAgent:v.currentAgent,agentLoading:v.loading,hasMore:i.hasMore,loadMoreLoading:i.loadMoreLoading,loadGroup:q,loadOlder:i.loadOlder,refreshGroups:I,loadAgents:r,selectAgent:v.selectAgent,getFileUrl:v.getFileUrl,submitQuestion:c,sendWsMessage:i.sendWsMessage,stopQuestion:i.stopQuestion}};exports.useAgent=ue;exports.useChat=ne;exports.useChatSession=pe;exports.useHistory=le;
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;
2
2
  //# sourceMappingURL=index.cjs.map