@shumai-one/shumai-agent 0.6.0 → 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 (99) hide show
  1. package/bin/chunk-023w4q1f.js +2 -0
  2. package/bin/chunk-29r6a67p.js +2 -0
  3. package/bin/chunk-2exf93nx.js +3 -0
  4. package/bin/chunk-3ev1fh2w.js +3 -0
  5. package/bin/chunk-3kt4k4jg.js +11 -0
  6. package/bin/chunk-62n25c3m.js +2 -0
  7. package/bin/chunk-6pf9rgk6.js +2 -0
  8. package/bin/{chunk-yk14703k.js → chunk-7bn1mjf2.js} +2 -2
  9. package/bin/chunk-7pwsjw9r.js +8 -0
  10. package/bin/{chunk-vnn8sej7.js → chunk-847yv5m2.js} +10 -10
  11. package/bin/chunk-9fqyh49m.js +2 -0
  12. package/bin/chunk-a5rn622e.js +7 -0
  13. package/bin/chunk-akj1v1zj.js +5 -0
  14. package/bin/{chunk-w5h5ctmd.js → chunk-am25vkck.js} +2 -2
  15. package/bin/chunk-at5qzp08.js +7 -0
  16. package/bin/chunk-b2n9g75s.js +2 -0
  17. package/bin/chunk-b767451d.js +3 -0
  18. package/bin/chunk-bsxxt20c.js +2 -0
  19. package/bin/{chunk-yd3kbedy.js → chunk-crc78aby.js} +2 -2
  20. package/bin/chunk-ee8rt9we.js +2 -0
  21. package/bin/chunk-eh6xcwvv.js +16 -0
  22. package/bin/chunk-fgabndrh.js +4 -0
  23. package/bin/chunk-fq1tf20c.js +45 -0
  24. package/bin/chunk-g7ad4dw4.js +2 -0
  25. package/bin/chunk-g7v8pfhe.js +2 -0
  26. package/bin/chunk-gx33h4rt.js +3 -0
  27. package/bin/chunk-hnpr396w.js +12 -0
  28. package/bin/chunk-hssdv3mc.js +2 -0
  29. package/bin/chunk-m3saxrzj.js +13 -0
  30. package/bin/chunk-mnd4dn3q.js +2 -0
  31. package/bin/chunk-nmygzasv.js +2 -0
  32. package/bin/chunk-nwz9f1dy.js +2 -0
  33. package/bin/chunk-p5nhcxwg.js +3 -0
  34. package/bin/chunk-pbdctjg4.js +2 -0
  35. package/bin/chunk-pphsqcqt.js +2 -0
  36. package/bin/chunk-pqa01d4g.js +2 -0
  37. package/bin/{chunk-7w6jsrka.js → chunk-q0x8yqms.js} +2 -2
  38. package/bin/chunk-q5w77y3e.js +2 -0
  39. package/bin/chunk-rf428t28.js +2 -0
  40. package/bin/chunk-rkcsrrvy.js +497 -0
  41. package/bin/chunk-rtqengn3.js +2 -0
  42. package/bin/chunk-rx0fmt6n.js +4 -0
  43. package/bin/chunk-ss91akc0.js +2 -0
  44. package/bin/{chunk-dsa7hrkt.js → chunk-stex0y7j.js} +2 -2
  45. package/bin/chunk-vngxwvwv.js +2 -0
  46. package/bin/chunk-w0e5ek1r.js +2 -0
  47. package/bin/chunk-x71z4a2a.js +3 -0
  48. package/bin/chunk-z19gfsnw.js +3 -0
  49. package/bin/chunk-z3gbypjs.js +2 -0
  50. package/bin/chunk-zphx997k.js +8 -0
  51. package/bin/shumai-agent-app.js +862 -1062
  52. package/package.json +7 -7
  53. package/prisma/migrations/20261026024507_hash_api_tokens/migration.sql +28 -0
  54. package/prisma/migrations/20261026031904_add_audit_log_via/migration.sql +2 -0
  55. package/prisma/migrations/20261029024626_add_oauth_and_jwks/migration.sql +205 -0
  56. package/prisma/migrations/20261029030321_default_empty_arrays_oauth/migration.sql +25 -0
  57. package/prisma/schema.prisma +186 -1
  58. package/bin/chunk-28e1j4am.js +0 -2
  59. package/bin/chunk-2gyngq15.js +0 -11
  60. package/bin/chunk-2n1dj1cv.js +0 -2
  61. package/bin/chunk-46jd4vhk.js +0 -45
  62. package/bin/chunk-56c9m0pd.js +0 -2
  63. package/bin/chunk-5yd2h4j1.js +0 -2
  64. package/bin/chunk-6ddtb9e6.js +0 -2
  65. package/bin/chunk-7qprxs9y.js +0 -2
  66. package/bin/chunk-8kyt2vpr.js +0 -7
  67. package/bin/chunk-8z4drz4c.js +0 -8
  68. package/bin/chunk-av6bexjx.js +0 -3
  69. package/bin/chunk-bhgneh6h.js +0 -2
  70. package/bin/chunk-c26v3b7f.js +0 -3
  71. package/bin/chunk-cam5rwb7.js +0 -2
  72. package/bin/chunk-e5amq469.js +0 -16
  73. package/bin/chunk-e5s9dk8d.js +0 -2
  74. package/bin/chunk-g80kdkky.js +0 -2
  75. package/bin/chunk-gmfm23kd.js +0 -2
  76. package/bin/chunk-h3dvj1c7.js +0 -12
  77. package/bin/chunk-hg8pmr2h.js +0 -2
  78. package/bin/chunk-jheky96k.js +0 -3
  79. package/bin/chunk-jtsbe34h.js +0 -4
  80. package/bin/chunk-k71cxhsn.js +0 -2
  81. package/bin/chunk-m4801ex4.js +0 -2
  82. package/bin/chunk-mfyektx6.js +0 -2
  83. package/bin/chunk-mryt63fx.js +0 -2
  84. package/bin/chunk-n75x7as6.js +0 -3
  85. package/bin/chunk-p0sycvda.js +0 -3
  86. package/bin/chunk-ph0978mm.js +0 -3
  87. package/bin/chunk-q032segv.js +0 -2
  88. package/bin/chunk-qnh6wt00.js +0 -2
  89. package/bin/chunk-qve2p771.js +0 -2
  90. package/bin/chunk-sgv9dhyw.js +0 -2
  91. package/bin/chunk-sk26g8gq.js +0 -5
  92. package/bin/chunk-tsfemjnp.js +0 -4
  93. package/bin/chunk-w2xc1r8f.js +0 -3
  94. package/bin/chunk-w5jhww1y.js +0 -8
  95. package/bin/chunk-w82m268v.js +0 -2
  96. package/bin/chunk-xpx7v1cz.js +0 -2
  97. package/bin/chunk-ynv1dwvb.js +0 -7
  98. package/bin/chunk-ywmjzwj6.js +0 -13
  99. package/bin/chunk-z65d9fhw.js +0 -2
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{Nt,Ut}from"./chunk-rkcsrrvy.js";import{A}from"./chunk-mnd4dn3q.js";var j=A(function(v,f){var{defineProperty:i,getOwnPropertyDescriptor:s,getOwnPropertyNames:_}=Object,k=Object.prototype.hasOwnProperty,l=(t,e)=>{for(var o in e)i(t,o,{get:e[o],enumerable:!0})},u=(t,e,o,n)=>{if(e&&typeof e==="object"||typeof e==="function"){for(let r of _(e))if(!k.call(t,r)&&r!==o)i(t,r,{get:()=>e[r],enumerable:!(n=s(e,r))||n.enumerable})}return t},d=(t)=>u(i({},"__esModule",{value:!0}),t),p={};l(p,{refreshToken:()=>O});f.exports=d(p);var c=Nt(),a=Ut();async function O(t){let e=t?.project,o=t?.team;if(!e&&!o){let r=(0,a.findProjectInfo)();e=r.projectId,o=r.teamId}else if(!e||!o){let r=(0,a.findProjectInfo)();e=e??r.projectId,o=o??r.teamId}if(!e)throw new c.VercelOidcTokenError("Failed to refresh OIDC token: No project specified. Try re-linking your project with `vc link`");let n=(0,a.loadToken)(e);if(!n||(0,a.isExpired)((0,a.getTokenPayload)(n.token),t?.expirationBufferMs)){let r=await(0,a.getVercelToken)({expirationBufferMs:t?.expirationBufferMs});if(n=await(0,a.getVercelOidcToken)(r,e,o),!n)throw new c.VercelOidcTokenError("Failed to refresh OIDC token");(0,a.saveToken)(n,e)}process.env.VERCEL_OIDC_TOKEN=n.token;return}});export default j();
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{rr,nr,Wr,Jr,Yr,xr}from"./chunk-rkcsrrvy.js";function p(e){return`'${e.replaceAll("'","''")}'`}function f(e){return async(t)=>{if(t.length===0)return[];let n=(await e.batch(t.map((r)=>e.prepare(`PRAGMA index_list(${p(r)})`)))).flatMap((r,o)=>{let i=t[o];if(!i)return[];return r.results.map((u)=>({...u,tableName:i}))});if(n.length===0)return[];let l=await e.batch(n.map((r)=>e.prepare(`PRAGMA index_info(${p(r.name)})`)));return n.map((r,o)=>({columns:(l[o]?.results??[]).map((i)=>({fullLength:i.name!==null,name:i.name,position:i.seqno})),name:r.name,partial:r.partial!==0,table:r.tableName,unique:r.unique!==0,valid:!0}))}}var h=class extends nr{get supportsMultipleConnections(){return!0}},m=class{#e;#t;constructor(e){this.#e={...e}}async init(){if(this.#t=new w(this.#e.database),this.#e.onCreateConnection)await this.#e.onCreateConnection(this.#t)}async acquireConnection(){return this.#t}async beginTransaction(){throw Error("D1 does not support interactive transactions. Use the D1 batch() API instead.")}async commitTransaction(){throw Error("D1 does not support interactive transactions. Use the D1 batch() API instead.")}async rollbackTransaction(){throw Error("D1 does not support interactive transactions. Use the D1 batch() API instead.")}async releaseConnection(){}async destroy(){}},w=class{#e;constructor(e){this.#e=e}async executeQuery(e){let t=await this.#e.prepare(e.sql).bind(...e.parameters).all(),n=t.meta.changes!=null?BigInt(t.meta.changes):void 0;return{insertId:t.meta.last_row_id===void 0||t.meta.last_row_id===null?void 0:BigInt(t.meta.last_row_id),rows:t?.results||[],numAffectedRows:n}}async*streamQuery(){throw Error("D1 does not support streaming queries.")}},d=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}async getSchemas(){return[]}async getTables(e={withInternalKyselyTables:!1}){let t=this.#e.selectFrom("sqlite_master").where("type","in",["table","view"]).where("name","not like","sqlite_%").where("name","not like","_cf_%").select(["name","type"]).$castTo();if(!e.withInternalKyselyTables)t=t.where("name","!=",Wr).where("name","!=",Jr);let n=await t.execute();if(n.length===0)return[];let l=n.map((a)=>this.#t.prepare("SELECT * FROM pragma_table_info(?)").bind(a.name)),r=await this.#t.batch(l),o=n.flatMap((a,s)=>{let c=Yr(r[s]?.results??[]);return c?[{index:s,tableName:a.name,column:c}]:[]}),i=o.length?await this.#t.batch(o.map(({tableName:a})=>this.#t.prepare(`PRAGMA index_list(${p(a)})`))):[],u=new Map(o.filter((a,s)=>!i[s]?.results?.some((c)=>c.origin==="pk")).map(({index:a,column:s})=>[a,s]));return n.map((a,s)=>xr(a,r[s]?.results??[],u.get(s)))}async getMetadata(e){return{tables:await this.getTables(e)}}},y=class extends rr{},q=class{#e;constructor(e){this.#e={...e}}createDriver(){return new m(this.#e)}createQueryCompiler(){return new y}createAdapter(){return new h}createIntrospector(e){return new d(e,this.#e.database)}};export{q as D1SqliteDialect,f as createD1IndexIntrospector};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{a}from"./chunk-6ddtb9e6.js";var n=null;function c(e){if(typeof process>"u"||!process.versions?.bun||Object.keys(process.env).length>0)return;if(n===null){n=new Map;try{let{readFileSync:t}=a("fs"),s=t("/proc/self/environ","utf-8");for(let r of s.split("\x00")){let o=r.indexOf("=");if(o>0)n.set(r.slice(0,o),r.slice(o+1))}}catch{}}return n.get(e)}function y(e,t){return t?.[e]||(typeof process<"u"?process.env[e]:void 0)||c(e)||void 0}
3
- export{y};
2
+ import{C}from"./chunk-mnd4dn3q.js";var n=null;function c(e){if(typeof process>"u"||!process.versions?.bun||Object.keys(process.env).length>0)return;if(n===null){n=new Map;try{let{readFileSync:t}=C("fs"),s=t("/proc/self/environ","utf-8");for(let r of s.split("\x00")){let o=r.indexOf("=");if(o>0)n.set(r.slice(0,o),r.slice(o+1))}}catch{}}return n.get(e)}function F(e,t){return t?.[e]||(typeof process<"u"?process.env[e]:void 0)||c(e)||void 0}
3
+ export{F};
@@ -0,0 +1,8 @@
1
+ // @bun
2
+ import{Z}from"./chunk-akj1v1zj.js";import{F}from"./chunk-7bn1mjf2.js";import{ne,lt}from"./chunk-2exf93nx.js";import{gr,Mt,Q}from"./chunk-rkcsrrvy.js";class g extends Error{code;diagnosticDetails;constructor(r,t,n){super(r);this.name="PiMessagesResponseError",this.code=t,this.diagnosticDetails=n}}function x(r){try{let t=JSON.parse(r),n=t?.error;return t&&typeof n==="object"&&n!==null&&!Array.isArray(n)?t:void 0}catch{return}}function m(r){return r.length>8192?`${r.slice(0,8192)}\u2026`:r}function y(r,t,n){let e=typeof n?.error?.message==="string"?n.error.message:void 0,s=typeof n?.error?.code==="string"?n.error.code:void 0,a=e??t,o=s?` (${s})`:"";return`${r.status} ${r.statusText}: ${a}${o}`}function w(r,t,n,e){let s=x(e),a=typeof s?.error?.code==="string"?s.error.code:void 0;return new g(y(n,e,s),a,{version:1,provider:r.provider,model:r.id,url:t.toString(),status:n.status,statusText:n.statusText,error:s?.error,body:s?void 0:m(e),timestampMs:Date.now()})}function h(){return{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}}}function l(r,t){if(!t)return;Mt(r,{type:"pi_messages_rewrite",timestamp:Date.now(),details:{...t}})}function b(r){let t={role:"assistant",content:[],api:r.api,provider:r.provider,model:r.id,usage:h(),stopReason:"stop",timestamp:Date.now()},n=new Map;return(e)=>{switch(e.type){case"done":return Object.assign(t,{stopReason:e.reason,usage:e.usage,responseId:e.responseId}),l(t,e.rewrite),{type:"done",reason:e.reason,message:t};case"error":return Object.assign(t,{stopReason:e.reason,usage:e.usage,errorMessage:e.errorMessage,responseId:e.responseId}),l(t,e.rewrite),{type:"error",reason:e.reason,error:t};case"start":break;case"text_start":t.content[e.contentIndex]={type:"text",text:""};break;case"text_delta":t.content[e.contentIndex].text+=e.delta;break;case"text_end":Object.assign(t.content[e.contentIndex],{text:e.content,textSignature:e.contentSignature});break;case"thinking_start":t.content[e.contentIndex]={type:"thinking",thinking:""};break;case"thinking_delta":t.content[e.contentIndex].thinking+=e.delta;break;case"thinking_end":Object.assign(t.content[e.contentIndex],{thinking:e.content,thinkingSignature:e.contentSignature,redacted:e.redacted});break;case"toolcall_start":t.content[e.contentIndex]={type:"toolCall",id:e.id,name:e.toolName,arguments:{}},n.set(e.contentIndex,"");break;case"toolcall_delta":{let s=`${n.get(e.contentIndex)??""}${e.delta}`;n.set(e.contentIndex,s),t.content[e.contentIndex].arguments=Z(s);break}case"toolcall_end":return Object.assign(t.content[e.contentIndex],e.toolCall),n.delete(e.contentIndex),{type:"toolcall_end",contentIndex:e.contentIndex,toolCall:t.content[e.contentIndex],partial:t}}return{...e,partial:t}}}async function*I(r){let t=new TextDecoder,n=r.getReader(),e="";try{while(!0){let{done:s,value:a}=await n.read();e+=s?t.decode():t.decode(a,{stream:!0}),e=e.replace(/\r\n/g,`
3
+ `);let o=e.indexOf(`
4
+
5
+ `);while(o!==-1){let c=f(e.slice(0,o));if(c)yield c;e=e.slice(o+2),o=e.indexOf(`
6
+
7
+ `)}if(s)break}if(e.trim()){let s=f(e);if(s)yield s}}finally{n.releaseLock()}}function f(r){let t=r.split(`
8
+ `).find((n)=>n.startsWith("data:"))?.slice(5).trim();return t&&t!=="[DONE]"?JSON.parse(t):void 0}function k(r,t,n){let e=n?"aborted":"error",s={role:"assistant",content:[],api:r.api,provider:r.provider,model:r.id,usage:h(),stopReason:e,errorMessage:t instanceof Error?t.message:String(t),timestamp:Date.now()};if(!n&&t instanceof g)Mt(s,gr("pi_messages_response_failure",t,t.diagnosticDetails));return{type:"error",reason:e,error:s}}function E(r,t){if(r)return r;return F("PI_CACHE_RETENTION",t)==="long"?"long":void 0}var R=(r,t,n)=>{let e=new Q,s=b(r);return(async()=>{try{let a=n?.apiKey;if(!a)throw Error(`No API key provided for provider "${r.provider}"`);let o=new URL(`${r.baseUrl.replace(/\/+$/u,"")}/messages`);if(n?.debug)o.searchParams.set("debug","1");let c={model:r.id,context:t,options:{temperature:n?.temperature,maxTokens:n?.maxTokens,reasoning:n?.reasoning,cacheRetention:E(n?.cacheRetention,n?.env),sessionId:n?.sessionId,toolChoice:n?.toolChoice}},p=await n?.onPayload?.(c,r);if(p!==void 0)c=p;let i=await fetch(o,{method:"POST",headers:{authorization:`Bearer ${a}`,accept:"text/event-stream","content-type":"application/json",...lt(n?.headers)},body:JSON.stringify(c),signal:n?.signal});if(await n?.onResponse?.({status:i.status,headers:ne(i.headers)},r),!i.ok){let d=await i.text();throw w(r,o,i,d)}if(!i.body)throw Error(`${r.provider} response has no body`);for await(let d of I(i.body)){let u=s(d);if(e.push(u),u.type==="done"||u.type==="error")return}throw Error(`${r.provider} stream ended without a terminal event`)}catch(a){e.push(k(r,a,n?.signal?.aborted??!1))}})(),e},P=(r,t,n)=>{let e=n;return R(r,t,{...n,reasoning:n?.reasoning,toolChoice:e?.toolChoice,debug:e?.debug})};export{g as PiMessagesResponseError,R as stream,P as streamSimple};