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.
- package/dist/core/index.cjs +1 -1
- package/dist/core/index.js +273 -261
- package/dist/core/useChat.d.ts +61 -12
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +33 -33
- package/dist/mobile-ui/chat/ChatContainer.vue.d.ts +6 -6
- package/dist/mobile-ui/chat/ChatMessagesView.vue.d.ts +6 -6
- package/dist/mobile-ui/index.cjs +1 -1
- package/dist/mobile-ui/index.js +104 -104
- package/dist/mobile-ui/inputbox/Inputbox.vue.d.ts +5 -5
- package/dist/page-context/index.js +2 -4
- package/dist/parser/answerCom/actionExecute/actionProtocol.d.ts +1 -7
- package/dist/parser/answerCom/actionExecute/clarification.d.ts +15 -3
- package/dist/parser/answerCom/actionExecute/constants.d.ts +10 -0
- package/dist/parser/answerCom/actionExecute/parseCollectClarifications.d.ts +3 -2
- package/dist/parser/answerCom/actionExecute/parseHostAction.d.ts +3 -2
- package/dist/parser/answerCom/actionExecute/types.d.ts +3 -3
- package/dist/parser/index.cjs +2 -2
- package/dist/parser/index.d.ts +2 -2
- package/dist/parser/index.js +216 -258
- package/dist/parser/registry.d.ts +1 -1
- package/dist/renderers/aiAnswer/AiAnswerBubble.vue.d.ts +4 -4
- package/dist/renderers/clarification/ClarificationCard.vue.d.ts +3 -3
- package/dist/renderers/deepThinking/DeepThinkingSteps.vue.d.ts +4 -4
- package/dist/renderers/hostAction/HostActionStatus.vue.d.ts +3 -3
- package/dist/renderers/iframePage/IframePage.vue.d.ts +3 -3
- package/dist/renderers/index.cjs +1 -1
- package/dist/renderers/index.js +484 -498
- package/dist/renderers/knowledgeStream/KnowledgeStreamResult.vue.d.ts +3 -3
- package/dist/renderers/outputFile/OutputFile.vue.d.ts +3 -3
- package/dist/renderers/style.css +1 -1
- package/dist/request/index.cjs +2 -2
- package/dist/request/index.js +6 -13
- package/dist/request/ws.d.ts +3 -3
- package/dist/right-panel/RightPanel.vue.d.ts +6 -6
- package/dist/right-panel/RightPanelIcon.vue.d.ts +4 -4
- package/dist/right-panel/RightPanelTabs.vue.d.ts +5 -5
- package/dist/right-panel/index.cjs +1 -1
- package/dist/right-panel/index.js +397 -416
- package/dist/right-panel/panels/newtab/NewTabPanel.vue.d.ts +4 -4
- package/dist/right-panel/panels/web/WebPanel.vue.d.ts +3 -3
- package/dist/right-panel/shared/BrowserToolbar.vue.d.ts +3 -3
- package/dist/right-panel/shared/RightPanelToolList.vue.d.ts +5 -5
- package/dist/theme/index.js +2 -4
- package/dist/tools/index.cjs +2 -2
- package/dist/tools/index.js +10 -19
- package/dist/tools/markdown/MarkdownContent.vue.d.ts +5 -5
- package/dist/tools/useAutoScroll.d.ts +3 -3
- package/dist/web-ui/attach/AttachmentCard.vue.d.ts +6 -6
- package/dist/web-ui/attach/AttachmentList.vue.d.ts +6 -6
- package/dist/web-ui/chat/ChatContainer.vue.d.ts +6 -6
- package/dist/web-ui/chat/ChatMessagesView.vue.d.ts +6 -6
- package/dist/web-ui/envswitch/EnvSwitch.vue.d.ts +5 -5
- package/dist/web-ui/index.cjs +1 -1
- package/dist/web-ui/index.js +630 -635
- package/dist/web-ui/inputbox/Inputbox.vue.d.ts +7 -7
- package/dist/web-ui/recordset/RecordsetTable.vue.d.ts +4 -4
- package/package.json +2 -1
package/dist/core/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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
|