@shumai-one/shumai-agent 0.4.1 → 0.4.3
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/bin/chunk-115gx56y.js +12 -0
- package/bin/chunk-24s58f6x.js +11 -0
- package/bin/chunk-2mj5h53m.js +5 -0
- package/bin/chunk-3dr4h1df.js +16 -0
- package/bin/chunk-3mdhkfgq.js +3 -0
- package/bin/chunk-5axrg8rz.js +2 -0
- package/bin/chunk-5vk5pgxq.js +45 -0
- package/bin/chunk-7hkzk9pe.js +3 -0
- package/bin/chunk-7z62cgr7.js +3 -0
- package/bin/chunk-8cz84wva.js +4 -0
- package/bin/chunk-97avgejq.js +2 -0
- package/bin/chunk-avm8xsd8.js +3 -0
- package/bin/chunk-b5hbfteg.js +2 -0
- package/bin/chunk-c8vf5ezv.js +24 -0
- package/bin/chunk-caw017nc.js +3 -0
- package/bin/chunk-dak3e9js.js +2 -0
- package/bin/chunk-dpd0zpsp.js +3 -0
- package/bin/chunk-gkwywrkk.js +2 -0
- package/bin/chunk-gqvwjf6q.js +2 -0
- package/bin/chunk-hme2crct.js +2 -0
- package/bin/chunk-hyc2kn1w.js +8 -0
- package/bin/chunk-kvt13jb9.js +2 -0
- package/bin/chunk-m51y6s92.js +2 -0
- package/bin/chunk-p7sczpks.js +3 -0
- package/bin/chunk-phjnj6x5.js +3 -0
- package/bin/chunk-ptxcc9bv.js +2 -0
- package/bin/chunk-q7ypqj4c.js +2 -0
- package/bin/chunk-r8hcdypf.js +2 -0
- package/bin/chunk-rv0jkz1g.js +8 -0
- package/bin/chunk-shv0zdbp.js +4 -0
- package/bin/chunk-smv5ztx4.js +2 -0
- package/bin/chunk-spcaxtg5.js +7 -0
- package/bin/chunk-sxrz8e3j.js +3 -0
- package/bin/chunk-v8rxcp9h.js +2 -0
- package/bin/chunk-xmq8pwcp.js +13379 -0
- package/bin/chunk-y6h80xaa.js +13 -0
- package/bin/chunk-zcx3awzq.js +3 -0
- package/bin/shumai-agent-app.js +660 -441
- package/package.json +18 -18
- package/prisma/migrations/20260904022457_add_agent_id_to_assets_and_audit_logs/migration.sql +17 -0
- package/prisma/migrations/20260906081230_default_denied_tools_delete_asset/migration.sql +15 -0
- package/prisma/schema.prisma +9 -0
- package/bin/chunk-1ep7nnzp.js +0 -5
- package/bin/chunk-1jq2vgrd.js +0 -3
- package/bin/chunk-2ntm65jn.js +0 -3
- package/bin/chunk-3nh1p64q.js +0 -12
- package/bin/chunk-41gh01qj.js +0 -3
- package/bin/chunk-4n1309xp.js +0 -2
- package/bin/chunk-616f7y5x.js +0 -8
- package/bin/chunk-6a9h5d64.js +0 -3
- package/bin/chunk-6dp3ybh2.js +0 -3
- package/bin/chunk-6nd8f70y.js +0 -4
- package/bin/chunk-6vs3gb9g.js +0 -2
- package/bin/chunk-7dyx5m0f.js +0 -6
- package/bin/chunk-7j3qbvwc.js +0 -7
- package/bin/chunk-7rx7p2wf.js +0 -12225
- package/bin/chunk-9h5qhgqx.js +0 -13
- package/bin/chunk-b9s67nd8.js +0 -2
- package/bin/chunk-c14kvr2r.js +0 -11
- package/bin/chunk-ccx6803n.js +0 -44
- package/bin/chunk-cm4dpd3k.js +0 -4
- package/bin/chunk-dd2tfwzy.js +0 -45
- package/bin/chunk-dk9vz5tv.js +0 -4
- package/bin/chunk-e6691p0v.js +0 -3
- package/bin/chunk-e9d2ah8y.js +0 -3
- package/bin/chunk-fvmb8en4.js +0 -24
- package/bin/chunk-gegf6d3m.js +0 -2
- package/bin/chunk-gx9vdcbm.js +0 -2
- package/bin/chunk-j427r7a5.js +0 -2
- package/bin/chunk-jperx2a8.js +0 -6
- package/bin/chunk-k4jm2gt4.js +0 -3
- package/bin/chunk-m29dphbf.js +0 -3
- package/bin/chunk-mpgy1y53.js +0 -3
- package/bin/chunk-n1t3he2k.js +0 -3
- package/bin/chunk-pmdb6y7t.js +0 -2
- package/bin/chunk-qx9njyk7.js +0 -3
- package/bin/chunk-r5h7vczc.js +0 -3
- package/bin/chunk-spm76160.js +0 -2
- package/bin/chunk-t8k09sgb.js +0 -3
- package/bin/chunk-tvef1ck8.js +0 -2
- package/bin/chunk-v4j6yxch.js +0 -3
- package/bin/chunk-vjzrmneg.js +0 -2
- package/bin/chunk-x25enwfz.js +0 -3
- package/bin/chunk-xg9xscqz.js +0 -1
- package/bin/chunk-xqg06q7q.js +0 -2
- package/bin/chunk-xvbd9e2b.js +0 -8
- package/bin/chunk-y2z3xj0m.js +0 -12
- package/bin/chunk-ywhrsshf.js +0 -2
- package/bin/chunk-z512b49m.js +0 -3
- package/bin/chunk-z58rb52r.js +0 -3
- package/bin/chunk-zazbsz25.js +0 -3
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{E}from"./chunk-2mj5h53m.js";import{_}from"./shumai-agent-app.js";import{Z}from"./chunk-caw017nc.js";import{u,Me,Oe,w,Ie,N}from"./chunk-dpd0zpsp.js";function J(i,o){let a={v:1,id:i};if(o)a.phase=o;return JSON.stringify(a)}function R(i){if(!i)return;if(i.startsWith("{"))try{let o=JSON.parse(i);if(o.v===1&&typeof o.id==="string"){if(o.phase==="commentary"||o.phase==="final_answer")return{id:o.id,phase:o.phase};return{id:o.id}}}catch{}return{id:i}}function P(i,o){let a=o.filter((l)=>l.type==="text").map((l)=>l.text).join(`
|
|
3
|
+
`),f=o.filter((l)=>l.type==="image"),p=a.length>0;if(f.length===0||!i.input.includes("image"))return u(p?a:f.length>0?"(see attached image)":"(no tool output)");let g=[];if(p)g.push({type:"input_text",text:u(a)});for(let l of f)g.push({type:"input_image",detail:"auto",image_url:`data:${l.mimeType};base64,${l.data}`});return g}function K(i,o,a,f){let p=[],g=new Set,l=(r)=>{let c=r.replace(/[^a-zA-Z0-9_-]/g,"_");return(c.length>64?c.slice(0,64):c).replace(/_+$/,"")},k=(r)=>{let c=`fc_${Z(r)}`;return c.length>64?c.slice(0,64):c},h=(r,c,t)=>{if(!a.has(i.provider))return l(r);if(!r.includes("|"))return l(r);let[e,n]=r.split("|"),s=l(e),m=t.provider!==i.provider||t.api!==i.api?k(n):l(n);if(!m.startsWith("fc_"))m=l(`fc_${m}`);return`${s}|${m}`},x=N(o.messages,i,h);if((f?.includeSystemPrompt??!0)&&o.systemPrompt){let r=i.compat,c=i.reasoning&&r?.supportsDeveloperRole!==!1?"developer":"system";p.push({role:c,content:u(o.systemPrompt)})}let I=0;for(let r of x){if(r.role==="user")if(typeof r.content==="string")p.push({role:"user",content:[{type:"input_text",text:u(r.content)}]});else{let c=r.content.map((t)=>{if(t.type==="text")return{type:"input_text",text:u(t.text)};return{type:"input_image",detail:"auto",image_url:`data:${t.mimeType};base64,${t.data}`}});if(c.length===0)continue;p.push({role:"user",content:c})}else if(r.role==="assistant"){let c=[],t=r,e=t.model!==i.id&&t.provider===i.provider&&t.api===i.api,n=0;for(let s of r.content)if(s.type==="thinking"){if(s.thinkingSignature){let d=JSON.parse(s.thinkingSignature);c.push(d)}}else if(s.type==="text"){let d=s,m=R(d.textSignature),T=n===0?`msg_pi_${I}`:`msg_pi_${I}_${n}`;n++;let y=m?.id;if(!y)y=T;else if(y.length>64)y=`msg_${Z(y)}`;c.push({type:"message",role:"assistant",content:[{type:"output_text",text:u(d.text),annotations:[]}],status:"completed",id:y,phase:m?.phase})}else if(s.type==="toolCall"){let d=s,[m,T]=d.id.split("|"),y=f?.grammarToolInputProperties?.get(d.name),b=T;if(e&&b?.startsWith("fc_")||y===void 0&&!b?.startsWith("fc_"))b=void 0;if(y!==void 0)c.push({type:"custom_tool_call",id:b,call_id:m,name:d.name,input:u(Me(d.name,d.arguments,y))});else c.push({type:"function_call",id:b,call_id:m,name:d.name,arguments:JSON.stringify(d.arguments)})}if(c.length===0)continue;p.push(...c)}else if(r.role==="toolResult"){let[c]=r.toolCallId.split("|"),t=P(i,r.content);if(f?.grammarToolInputProperties?.has(r.toolName))p.push({type:"custom_tool_call_output",call_id:c,output:t});else p.push({type:"function_call_output",call_id:c,output:t});let e=[];for(let n of r.addedToolNames??[]){let s=f?.deferredTools?.get(n);if(!s||g.has(n))continue;g.add(n),e.push(s)}if(e.length>0){let n=e.map((d)=>d.name),s=`pi_tool_load_${Z(`${r.toolCallId}:${n.join(",")}`)}`;p.push({type:"tool_search_call",call_id:s,execution:"client",status:"completed",arguments:{query:n.join(" "),limit:n.length}}),p.push({type:"tool_search_output",call_id:s,execution:"client",status:"completed",tools:q(e,{...f?.toolOptions,deferLoading:!0})})}}I++}return p}function q(i,o){let a=o?.strict===void 0?!1:o.strict,f=o?.supportsStrictMode??!0,p=o?.supportsOpenAIGrammarTools??!1;return i.map((g)=>{let l=Ie(g,p);if(l)return{type:"custom",name:g.name,description:g.description,format:{type:"grammar",syntax:l.format,definition:l.definition},...o?.deferLoading?{defer_loading:!0}:{}};let k=w(g,f),h={type:"function",name:g.name,description:g.description,parameters:g.parameters,...o?.deferLoading?{defer_loading:!0}:{}};if(f)h.strict=k??a;return h})}function C(i){let o=i.customInput?.property;if(o===void 0)return"";let a=i.arguments[o];return typeof a==="string"?a:""}function v(i,o,a){let f=i.customInput;if(!f)return;let p=Oe(f.jsonBuffer,f.property,o,a);return i.arguments={[f.property]:o},p}async function ee(i,o,a,f,p){let g=!1,l=new Map,k=new Map,h=(t,e)=>{let n=l.get(t);return n?.type===e?n:void 0},x=(t,e)=>{if(e===void 0)return;a.push({type:"toolcall_delta",contentIndex:t.contentIndex,delta:e,partial:o})},S=(t,e)=>{if(e.type==="reasoning"){let n={type:"thinking",thinking:""};o.content.push(n);let s={type:"thinking",block:n,contentIndex:o.content.length-1};return l.set(t,s),a.push({type:"thinking_start",contentIndex:s.contentIndex,partial:o}),s}if(e.type==="message"){let n={type:"text",text:""};o.content.push(n);let s={type:"text",block:n,contentIndex:o.content.length-1};return l.set(t,s),a.push({type:"text_start",contentIndex:s.contentIndex,partial:o}),s}if(e.type==="function_call"){let n={type:"toolCall",id:`${e.call_id}|${e.id}`,name:e.name,arguments:{},partialJson:e.arguments||""};o.content.push(n);let s={type:"toolCall",block:n,contentIndex:o.content.length-1};return l.set(t,s),a.push({type:"toolcall_start",contentIndex:s.contentIndex,partial:o}),s}if(e.type==="custom_tool_call"){let n=p?.grammarToolInputProperties?.get(e.name)??"input",s=e.input||"",d={type:"toolCall",id:`${e.call_id}|${e.id}`,name:e.name,arguments:{[n]:s},customInput:{property:n,jsonBuffer:{input:"",started:!1,closed:!1}}};o.content.push(d);let m={type:"toolCall",block:d,contentIndex:o.content.length-1};return l.set(t,m),a.push({type:"toolcall_start",contentIndex:m.contentIndex,partial:o}),m}return},I=(t,e)=>l.get(t)??S(t,e),r=(t)=>{for(let e of t){if(e.type!=="reasoning"||!e.encrypted_content)continue;let n=k.get(e.id);if(!n?.thinkingSignature)continue;let s=JSON.parse(n.thinkingSignature);if(s.encrypted_content)continue;n.thinkingSignature=JSON.stringify({...s,encrypted_content:e.encrypted_content})}},c=(t)=>{if(g=!0,r(t.output??[]),t?.id)o.responseId=t.id;if(t?.usage){let e=t.usage.input_tokens_details,n=e?.cached_tokens||0,s=e?.cache_write_tokens||0;o.usage={input:Math.max(0,(t.usage.input_tokens||0)-n-s),output:t.usage.output_tokens||0,cacheRead:n,cacheWrite:s,reasoning:t.usage.output_tokens_details?.reasoning_tokens||0,totalTokens:t.usage.total_tokens||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}}}if(_(f,o.usage),p?.applyServiceTierPricing){let e=p.resolveServiceTier?p.resolveServiceTier(t?.service_tier,p.serviceTier):t?.service_tier??p.serviceTier;p.applyServiceTierPricing(o.usage,e)}if(o.stopReason=O(t?.status),o.content.some((e)=>e.type==="toolCall")&&o.stopReason==="stop")o.stopReason="toolUse"};for await(let t of i)if(t.type==="response.created")o.responseId=t.response.id;else if(t.type==="response.output_item.added")S(t.output_index,t.item);else if(t.type==="response.reasoning_summary_text.delta"){let e=h(t.output_index,"thinking");if(!e)continue;e.block.thinking+=t.delta,a.push({type:"thinking_delta",contentIndex:e.contentIndex,delta:t.delta,partial:o})}else if(t.type==="response.reasoning_summary_part.done"){let e=h(t.output_index,"thinking");if(!e)continue;e.block.thinking+=`
|
|
4
|
+
|
|
5
|
+
`,a.push({type:"thinking_delta",contentIndex:e.contentIndex,delta:`
|
|
6
|
+
|
|
7
|
+
`,partial:o})}else if(t.type==="response.reasoning_text.delta"){let e=h(t.output_index,"thinking");if(!e)continue;e.block.thinking+=t.delta,a.push({type:"thinking_delta",contentIndex:e.contentIndex,delta:t.delta,partial:o})}else if(t.type==="response.output_text.delta"){let e=h(t.output_index,"text");if(!e)continue;e.block.text+=t.delta,a.push({type:"text_delta",contentIndex:e.contentIndex,delta:t.delta,partial:o})}else if(t.type==="response.refusal.delta"){let e=h(t.output_index,"text");if(!e)continue;e.block.text+=t.delta,a.push({type:"text_delta",contentIndex:e.contentIndex,delta:t.delta,partial:o})}else if(t.type==="response.function_call_arguments.delta"){let e=h(t.output_index,"toolCall");if(!e||e.block.partialJson===void 0)continue;e.block.partialJson+=t.delta,e.block.arguments=E(e.block.partialJson),x(e,t.delta)}else if(t.type==="response.function_call_arguments.done"){let e=h(t.output_index,"toolCall");if(!e||e.block.partialJson===void 0)continue;let n=e.block.partialJson;if(e.block.partialJson=t.arguments,e.block.arguments=E(e.block.partialJson),t.arguments.startsWith(n)){let s=t.arguments.slice(n.length);if(s.length>0)x(e,s)}}else if(t.type==="response.custom_tool_call_input.delta"){let e=h(t.output_index,"toolCall");if(!e||!e.block.customInput)continue;x(e,v(e.block,C(e.block)+t.delta,!1))}else if(t.type==="response.custom_tool_call_input.done"){let e=h(t.output_index,"toolCall");if(!e||!e.block.customInput)continue;x(e,v(e.block,t.input,!0))}else if(t.type==="response.output_item.done"){let e=t.item,n=I(t.output_index,e);if(e.type==="reasoning"&&n?.type==="thinking"){let s=e.summary?.map((m)=>m.text).join(`
|
|
8
|
+
|
|
9
|
+
`)||"",d=e.content?.map((m)=>m.text).join(`
|
|
10
|
+
|
|
11
|
+
`)||"";n.block.thinking=s||d||n.block.thinking,n.block.thinkingSignature=JSON.stringify(e),k.set(e.id,n.block),a.push({type:"thinking_end",contentIndex:n.contentIndex,content:n.block.thinking,partial:o}),l.delete(t.output_index)}else if(e.type==="message"&&n?.type==="text")n.block.text=e.content?.map((s)=>s.type==="output_text"?s.text:s.refusal).join("")||"",n.block.textSignature=J(e.id,e.phase??void 0),a.push({type:"text_end",contentIndex:n.contentIndex,content:n.block.text,partial:o}),l.delete(t.output_index);else if(e.type==="function_call"&&n?.type==="toolCall"&&n.block.partialJson!==void 0)n.block.arguments=E(e.arguments||n.block.partialJson||"{}"),delete n.block.partialJson,a.push({type:"toolcall_end",contentIndex:n.contentIndex,toolCall:n.block,partial:o}),l.delete(t.output_index);else if(e.type==="custom_tool_call"&&n?.type==="toolCall"&&n.block.customInput)x(n,v(n.block,e.input??C(n.block),!0)),delete n.block.customInput,a.push({type:"toolcall_end",contentIndex:n.contentIndex,toolCall:n.block,partial:o}),l.delete(t.output_index)}else if(t.type==="response.completed"||t.type==="response.incomplete")c(t.response);else if(t.type==="error")throw Error(`Error Code ${t.code}: ${t.message}`||"Unknown error");else if(t.type==="response.failed"){g=!0;let e=t.response?.error,n=t.response?.incomplete_details,s=e?`${e.code||"unknown"}: ${e.message||"no message"}`:n?.reason?`incomplete: ${n.reason}`:"Unknown error (no error details in response)";throw Error(s)}if(!g)throw Error("OpenAI Responses stream ended before a terminal response event")}function O(i){if(!i)return"stop";switch(i){case"completed":return"stop";case"incomplete":return"length";case"failed":case"cancelled":return"error";case"in_progress":case"queued":return"stop";default:throw Error(`Unhandled stop reason: ${i}`)}}
|
|
12
|
+
export{K,q,ee};
|