agent-tool-chat 1.1.4 → 1.1.5

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/index.cjs CHANGED
@@ -23,7 +23,7 @@ ${l}`}function Di(e){const t=Qt(e.data);if(!(t!=null&&t.length))return"(无数
23
23
 
24
24
  ${Xo(R)}`:s:$o(_);J=`${J}
25
25
 
26
- ${mi}`;const z=new Zo({provider:E,providerConfig:x(),tools:K,systemPrompt:J,maxContextTokens:d,maxHistoryMessages:f});let $=[],ue=!1;const de=[];async function Se(y,T,W){const F={toolCallId:`${Date.now()}_${Math.random().toString(36).slice(2,6)}`,packageId:y.packageId,toolName:y.toolName,args:y.args};try{const H=await n(F);$.push({pkg:T,toolDef:W,data:H,args:y.args});const V=W.displayHints;return ue=(V==null?void 0:V.showModelContent)===!1&&(!!V.suggestComponent||["table","card","list"].includes(V.resultFormat)),{success:!0,result:typeof H=="string"?H:JSON.stringify(H)}}catch(H){return{success:!1,result:(H==null?void 0:H.message)||"工具执行失败"}}}async function Pe(y,T){try{const W=await qo(y.name,T);$.push({pkg:wt,toolDef:y,data:W,args:T});const F=y.displayHints;return ue=(F==null?void 0:F.showModelContent)===!1&&(!!F.suggestComponent||["table","card","list"].includes(F.resultFormat)),{success:!0,result:typeof W=="string"?W:JSON.stringify(W)}}catch(W){return{success:!1,result:(W==null?void 0:W.message)||"内置工具执行失败"}}}function _t(){var F,H;const y=h.value[h.value.length-1];if(!y||y.role!=="assistant"){$=[];return}const T=[];let W=!1;for(const{pkg:V,toolDef:fe,data:te,args:Ae}of $){const q=fe.displayHints;if(q){if(q.suggestComponent){let Ce=te;if(q.resultFormat==="map"){if((F=te==null?void 0:te.data)!=null&&F.fileId){const ae=I.get(te.data.fileId);ae&&(Ce=ae.name.endsWith(".geojson")||ae.name.endsWith(".json")?{data:{id:te.data.fileId,wkt:"",geojson:ae.data}}:{data:{id:te.data.fileId,wkt:ae.data,geojson:""}})}else if((H=te==null?void 0:te.data)!=null&&H.fileIds){const ae=te.data.fileIds.map(he=>I.get(he));if(ae.filter(he=>!he).length)continue;const Ne=[];ae.forEach(he=>{he.name.endsWith(".geojson")||he.name.endsWith(".json")?Ne.push({id:he.id,data:he.data,type:"geojson"}):he.name.endsWith(".txt")?Ne.push({id:he.id,data:he.data,type:"wkt"}):he.name.endsWith(".tif")?Ne.push({id:he.id,data:he,type:"tif"}):Ne.push({id:he.id,data:he.data,type:"unknown"})}),Ce={...te,data:Ne}}}T.push({type:"component",packageId:V.id,componentName:q.suggestComponent,data:Ce})}else if(q.resultFormat==="table"||q.resultFormat==="card"||q.resultFormat==="list"||q.resultFormat==="auto"){const Ce=Qt(te);if(Ce!=null&&Ce.length){const ae=q.resultFormat==="auto"?Qn(te):q.resultFormat;if(ae==="none")continue;T.push({type:ae,title:j(q.summaryTemplate,Ae),data:Ce,fields:q.previewFields,labelField:q.labelField,selectable:q.selectable})}}if(q.showModelContent===!1&&(q.suggestComponent||["table","card","list","auto"].includes(q.resultFormat))&&(W=!0),q.suggestedNext)if(q.suggestedNextEvent){const Ce=q.suggestedNextEvent,ae=B.on(Ce,()=>kt(Ce));de.push({event:Ce,text:q.suggestedNext,unsub:ae})}else y.suggestedNext=q.suggestedNext}}W&&!T.length&&(W=!1),y.renderBlocks=T,y.hideMarkdown=W,$=[]}function kt(y){const T=de.findIndex(F=>F.event===y);if(T===-1)return;const W=de[T];W.unsub(),de.splice(T,1);for(let F=h.value.length-1;F>=0;F--){const H=h.value[F];if(H.role==="assistant"){H.suggestedNext=W.text;break}}}function nt(){for(const y of de)y.unsub();de.length=0}function j(y,T){if(y)return y.replace(/\{(\w+)\}/g,(W,F)=>T[F]!==void 0?String(T[F]):W)}const le=new Map;z.on(y=>{var T,W;switch(y.type){case"message":{if(y.message.role==="tool")break;const F={id:mn(),role:y.message.role,content:y.message.content,reasoning:"",status:y.message.role==="assistant"?"streaming":"done",timestamp:Date.now(),tool_calls:y.message.tool_calls};y.message.role==="assistant"&&ue&&(F.hideMarkdown=!0,ue=!1),h.value.push(F);break}case"stream:delta":{const F=h.value[h.value.length-1];(F==null?void 0:F.role)==="assistant"&&F.status==="streaming"&&(y.delta.content&&(F.content+=y.delta.content),y.delta.reasoning&&(F.reasoning=(F.reasoning||"")+y.delta.reasoning));break}case"stream:end":{const F=h.value[h.value.length-1];(F==null?void 0:F.role)==="assistant"&&(F.content=y.content,y.reasoning&&(F.reasoning=y.reasoning),F.status==="streaming"&&(F.status="done"));break}case"tool:start":{const F=h.value[h.value.length-1];if(!F||F.role!=="assistant")break;F.tool_calls||(F.tool_calls=[]),F.toolResults||(F.toolResults=[]);const H=F.toolResults.length;F.toolResults.push({callId:y.call.id,name:y.call.function.name,arguments:y.call.function.arguments,result:"",success:!1,status:"running"}),le.set(y.call.id,{msgIndex:h.value.length-1,toolIndex:H}),F.tool_calls.find(V=>V.id===y.call.id)||F.tool_calls.push({id:y.call.id,type:"function",function:{name:y.call.function.name,arguments:y.call.function.arguments}});break}case"tool:end":{const F=le.get(y.call.id);if(!F)break;const H=(W=(T=h.value[F.msgIndex])==null?void 0:T.toolResults)==null?void 0:W[F.toolIndex];H&&(H.result=y.output.result,H.success=y.output.success,H.status=y.output.success?"success":"error"),le.delete(y.call.id);break}case"error":{g.value=y.error;const F=h.value[h.value.length-1];(F==null?void 0:F.role)==="assistant"&&(F.status="error",F.error=y.error);break}case"status":{if(b.value=y.loading,!y.loading){let F=null;for(const H of h.value)H.role==="assistant"&&H.status==="streaming"&&(H.status="done",!H.content&&!F&&(F=H));F&&(F.content="(已停止生成)"),_t()}break}}});function Be(){try{const y=localStorage.getItem(m.settings);k.value={...zt,...e.settings??{},...y?JSON.parse(y):{}}}catch{k.value={...zt,...e.settings??{}}}}function Fe(y){for(const T of y)if(T.files)for(const W of T.files)W.id&&I.set(W.id,W)}async function ze(){if(k.value.providerMode==="proxy"){try{const y=gn(k.value.proxyUrl);if(!y)return;const T=await fetch(`${y}/api/messages?device_id=${encodeURIComponent(Lt())}`,{method:"GET",credentials:"include"});if(!T.ok)return;const W=await T.json(),F=W==null?void 0:W.messages;Array.isArray(F)&&(h.value=F,Fe(F),z.initialize(Cn(F)))}catch{}return}try{const y=localStorage.getItem(m.messages);if(y){const T=JSON.parse(y);Array.isArray(T)&&(h.value=T,Fe(T),z.initialize(Cn(T)))}}catch{}}function ot(y){k.value={...y},localStorage.setItem(m.settings,JSON.stringify(y)),y.providerMode==="proxy"?z.updateProviderConfig({baseUrl:y.proxyUrl,apiKey:"",model:y.model,temperature:y.temperature}):z.updateProviderConfig({baseUrl:y.baseUrl,apiKey:y.apiKey,model:y.model,temperature:y.temperature})}async function Ye(){if(k.value.providerMode==="proxy"){try{const y=gn(k.value.proxyUrl);if(!y)return;await fetch(`${y}/api/messages`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_id:Lt(),messages:h.value})})}catch{}return}try{localStorage.setItem(m.messages,JSON.stringify(h.value))}catch{}}function rt(y){return y.startsWith("data:")}async function it(y,T){const W=y.trim();if(!W&&(!T||T.length===0))return;if(g.value="",k.value.providerMode==="direct"&&!k.value.apiKey){g.value="请先配置 API Key。";return}if(z.updateProviderConfig(x()),$=[],le.clear(),T&&T.length>0){for(const V of T)V.id=mn(),I.set(V.id,{...V});const H={id:mn(),role:"user",content:W,status:"done",timestamp:Date.now(),files:T};h.value.push(H),z.initialize(Cn(h.value))}let F=W;T&&T.length>0&&(A?F=`已上传文件:
26
+ ${mi}`;const z=new Zo({provider:E,providerConfig:x(),tools:K,systemPrompt:J,maxContextTokens:d,maxHistoryMessages:f});let $=[],ue=!1;const de=[];async function Se(y,T,W){const F={toolCallId:`${Date.now()}_${Math.random().toString(36).slice(2,6)}`,packageId:y.packageId,toolName:y.toolName,args:y.args};try{const H=await n(F);$.push({pkg:T,toolDef:W,data:H,args:y.args});const V=W.displayHints;return ue=(V==null?void 0:V.showModelContent)===!1&&(!!V.suggestComponent||["table","card","list"].includes(V.resultFormat)),{success:!0,result:typeof H=="string"?H:JSON.stringify(H)}}catch(H){return{success:!1,result:(H==null?void 0:H.message)||"工具执行失败"}}}async function Pe(y,T){try{const W=await qo(y.name,T);$.push({pkg:wt,toolDef:y,data:W,args:T});const F=y.displayHints;return ue=(F==null?void 0:F.showModelContent)===!1&&(!!F.suggestComponent||["table","card","list"].includes(F.resultFormat)),{success:!0,result:typeof W=="string"?W:JSON.stringify(W)}}catch(W){return{success:!1,result:(W==null?void 0:W.message)||"内置工具执行失败"}}}function _t(){var F,H;const y=h.value[h.value.length-1];if(!y||y.role!=="assistant"){$=[];return}const T=[];let W=!1;for(const{pkg:V,toolDef:fe,data:te,args:Ae}of $){const q=fe.displayHints;if(q){if(q.suggestComponent){let Ce=te;if(q.resultFormat==="map"){if((F=te==null?void 0:te.data)!=null&&F.fileId){const ae=I.get(te.data.fileId);ae&&(Ce=ae.name.endsWith(".geojson")||ae.name.endsWith(".json")?{data:{id:te.data.fileId,wkt:"",geojson:ae.data}}:{data:{id:te.data.fileId,wkt:ae.data,geojson:""}})}else if((H=te==null?void 0:te.data)!=null&&H.fileIds){const ae=te.data.fileIds.map(he=>I.get(he));if(ae.filter(he=>!he).length)continue;const Ne=[];ae.forEach(he=>{he.name.endsWith(".geojson")||he.name.endsWith(".json")?Ne.push({id:he.id,data:he.data,type:"geojson"}):he.name.endsWith(".txt")?Ne.push({id:he.id,data:he.data,type:"wkt"}):he.name.endsWith(".tif")?Ne.push({id:he.id,data:he,type:"tif"}):Ne.push({id:he.id,data:he.data,type:"unknown"})}),Ce={...te,data:Ne}}}T.push({type:"component",packageId:V.id,componentName:q.suggestComponent,data:Ce})}else if(q.resultFormat==="table"||q.resultFormat==="card"||q.resultFormat==="list"||q.resultFormat==="auto"){const Ce=Qt(te);if(Ce!=null&&Ce.length){const ae=q.resultFormat==="auto"?Qn(te):q.resultFormat;if(ae==="none")continue;T.push({type:ae,title:j(q.summaryTemplate,Ae),data:Ce,fields:q.previewFields,labelField:q.labelField,selectable:q.selectable})}}if(q.showModelContent===!1&&(q.suggestComponent||["table","card","list","auto"].includes(q.resultFormat))&&(W=!0),q.suggestedNext)if(q.suggestedNextEvent){const Ce=q.suggestedNextEvent,ae=B.on(Ce,()=>kt(Ce));de.push({event:Ce,text:q.suggestedNext,unsub:ae})}else y.suggestedNext=q.suggestedNext}}W&&!T.length&&(W=!1),y.renderBlocks=T,y.hideMarkdown=W,$=[]}function kt(y){const T=de.findIndex(F=>F.event===y);if(T===-1)return;const W=de[T];W.unsub(),de.splice(T,1);for(let F=h.value.length-1;F>=0;F--){const H=h.value[F];if(H.role==="assistant"){H.suggestedNext=W.text;break}}}function nt(){for(const y of de)y.unsub();de.length=0}function j(y,T){if(y)return y.replace(/\{(\w+)\}/g,(W,F)=>T[F]!==void 0?String(T[F]):W)}const le=new Map;z.on(y=>{var T,W;switch(y.type){case"message":{if(y.message.role==="tool")break;const F={id:mn(),role:y.message.role,content:y.message.content,reasoning:"",status:y.message.role==="assistant"?"streaming":"done",timestamp:Date.now(),tool_calls:y.message.tool_calls};y.message.role==="assistant"&&ue&&(F.hideMarkdown=!0,ue=!1),h.value.push(F);break}case"stream:delta":{const F=h.value[h.value.length-1];(F==null?void 0:F.role)==="assistant"&&F.status==="streaming"&&(y.delta.content&&(F.content+=y.delta.content),y.delta.reasoning&&(F.reasoning=(F.reasoning||"")+y.delta.reasoning));break}case"stream:end":{const F=h.value[h.value.length-1];(F==null?void 0:F.role)==="assistant"&&(F.content=y.content,y.reasoning&&(F.reasoning=y.reasoning),F.status==="streaming"&&(F.status="done"));break}case"tool:start":{const F=h.value[h.value.length-1];if(!F||F.role!=="assistant")break;F.tool_calls||(F.tool_calls=[]),F.toolResults||(F.toolResults=[]);const H=F.toolResults.length;F.toolResults.push({callId:y.call.id,name:y.call.function.name,arguments:y.call.function.arguments,result:"",success:!1,status:"running"}),le.set(y.call.id,{msgIndex:h.value.length-1,toolIndex:H}),F.tool_calls.find(V=>V.id===y.call.id)||F.tool_calls.push({id:y.call.id,type:"function",function:{name:y.call.function.name,arguments:y.call.function.arguments}});break}case"tool:end":{const F=le.get(y.call.id);if(!F)break;const H=(W=(T=h.value[F.msgIndex])==null?void 0:T.toolResults)==null?void 0:W[F.toolIndex];H&&(H.result=y.output.result,H.success=y.output.success,H.status=y.output.success?"success":"error"),le.delete(y.call.id);break}case"error":{g.value=y.error;const F=h.value[h.value.length-1];(F==null?void 0:F.role)==="assistant"&&(F.status="error",F.error=y.error);break}case"status":{if(b.value=y.loading,!y.loading){let F=null;for(const H of h.value)H.role==="assistant"&&H.status==="streaming"&&(H.status="done",!H.content&&!F&&(F=H));F&&(F.content="(已停止生成)"),_t()}break}}});function Be(){try{const y=localStorage.getItem(m.settings);k.value={...zt,...e.settings??{},...y?JSON.parse(y):{}}}catch{k.value={...zt,...e.settings??{}}}}function Fe(y){for(const T of y)if(T.files)for(const W of T.files)W.id&&I.set(W.id,W)}async function ze(){if(k.value.providerMode==="proxy"){try{const y=gn(k.value.proxyUrl);if(!y)return;const T=await fetch(`${y}/api/messages?device_id=${encodeURIComponent(Lt())}`,{method:"GET"});if(!T.ok)return;const W=await T.json(),F=W==null?void 0:W.messages;Array.isArray(F)&&(h.value=F,Fe(F),z.initialize(Cn(F)))}catch{}return}try{const y=localStorage.getItem(m.messages);if(y){const T=JSON.parse(y);Array.isArray(T)&&(h.value=T,Fe(T),z.initialize(Cn(T)))}}catch{}}function ot(y){k.value={...y},localStorage.setItem(m.settings,JSON.stringify(y)),y.providerMode==="proxy"?z.updateProviderConfig({baseUrl:y.proxyUrl,apiKey:"",model:y.model,temperature:y.temperature}):z.updateProviderConfig({baseUrl:y.baseUrl,apiKey:y.apiKey,model:y.model,temperature:y.temperature})}async function Ye(){if(k.value.providerMode==="proxy"){try{const y=gn(k.value.proxyUrl);if(!y)return;await fetch(`${y}/api/messages`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_id:Lt(),messages:h.value})})}catch{}return}try{localStorage.setItem(m.messages,JSON.stringify(h.value))}catch{}}function rt(y){return y.startsWith("data:")}async function it(y,T){const W=y.trim();if(!W&&(!T||T.length===0))return;if(g.value="",k.value.providerMode==="direct"&&!k.value.apiKey){g.value="请先配置 API Key。";return}if(z.updateProviderConfig(x()),$=[],le.clear(),T&&T.length>0){for(const V of T)V.id=mn(),I.set(V.id,{...V});const H={id:mn(),role:"user",content:W,status:"done",timestamp:Date.now(),files:T};h.value.push(H),z.initialize(Cn(h.value))}let F=W;T&&T.length>0&&(A?F=`已上传文件:
27
27
  ${T.map((V,fe)=>{const te=`${fe+1}. **${V.name}**(${V.type},${(V.size/1024).toFixed(1)}KB),文件ID:\`${V.id}\``;return rt(V.data)?`${te}
28
28
  ${V.data}`:`${te}
29
29
  \`\`\`
package/dist/index.js CHANGED
@@ -1049,9 +1049,8 @@ ${Ms}`;
1049
1049
  const N = await fetch(
1050
1050
  `${y}/api/messages?device_id=${encodeURIComponent(An())}`,
1051
1051
  {
1052
- method: "GET",
1053
- credentials: "include"
1054
- // 关键:允许携带跨域 Cookie
1052
+ method: "GET"
1053
+ // credentials: 'include', // 关键:允许携带跨域 Cookie
1055
1054
  }
1056
1055
  );
1057
1056
  if (!N.ok) return;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "agent-tool-chat",
3
3
  "description": "An agent-driven chat plugin with ToolPackage architecture and host-controlled execution",
4
4
  "author": "kangjinrui <1092014304@qq.com>",
5
- "version": "1.1.4",
5
+ "version": "1.1.5",
6
6
  "license": "MIT",
7
7
  "private": false,
8
8
  "type": "module",