dal-code 1.0.59 → 1.0.61

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 (134) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/bundle/chunks/account-REEBP4XX.js +1 -0
  3. package/dist/bundle/chunks/{anthropic-messages-HVFHIIGX.js → anthropic-messages-FFHN77YO.js} +1 -1
  4. package/dist/bundle/chunks/{azure-openai-responses-RMWKIGFW.js → azure-openai-responses-XMVXFFRW.js} +1 -1
  5. package/dist/bundle/chunks/bedrock-converse-stream.js +1 -1
  6. package/dist/bundle/chunks/{chunk-TPOKZ2EU.js → chunk-3UVUVPDJ.js} +1 -1
  7. package/dist/bundle/chunks/{chunk-IONGABQF.js → chunk-46A3CZG4.js} +1 -1
  8. package/dist/bundle/chunks/{chunk-BBNE2TWS.js → chunk-4PE5FX77.js} +1 -1
  9. package/dist/bundle/chunks/{chunk-4BOWD7PQ.js → chunk-5DM5CSLU.js} +1 -1
  10. package/dist/bundle/chunks/chunk-5VVKJ7N6.js +9 -0
  11. package/dist/bundle/chunks/chunk-7FEAO2PW.js +2 -0
  12. package/dist/bundle/chunks/{chunk-HF334NQU.js → chunk-B66W54NL.js} +1 -1
  13. package/dist/bundle/chunks/chunk-CVSK7HIR.js +1 -0
  14. package/dist/bundle/chunks/{chunk-VDPDHGGJ.js → chunk-DM37LCOU.js} +1 -1
  15. package/dist/bundle/chunks/{chunk-PMFHJN7I.js → chunk-HDE7XZW5.js} +1 -1
  16. package/dist/bundle/chunks/{chunk-MPLE6M5C.js → chunk-KV7HXJIS.js} +1 -1
  17. package/dist/bundle/chunks/{chunk-4PBY6OYS.js → chunk-LBVJMXG6.js} +1 -1
  18. package/dist/bundle/chunks/{chunk-F5SIUTR7.js → chunk-LGD3AMTG.js} +1 -1
  19. package/dist/bundle/chunks/{chunk-KT7CXVDN.js → chunk-M4QINYHM.js} +9 -9
  20. package/dist/bundle/chunks/{chunk-YOQ3KBG5.js → chunk-MOBJIVPU.js} +1 -1
  21. package/dist/bundle/chunks/{chunk-KQRRELCF.js → chunk-NBRVYUIG.js} +1 -1
  22. package/dist/bundle/chunks/{chunk-AL3DFAIM.js → chunk-NRQYSXAU.js} +1 -1
  23. package/dist/bundle/chunks/{chunk-GZJEAFRS.js → chunk-O4KJ5UE4.js} +1 -1
  24. package/dist/bundle/chunks/{chunk-IKSSB5ZJ.js → chunk-OLTY5TDX.js} +1 -1
  25. package/dist/bundle/chunks/{chunk-R47JBGS3.js → chunk-QM5JU2GS.js} +1 -1
  26. package/dist/bundle/chunks/{chunk-XQF5XDEM.js → chunk-RRAXQWE3.js} +2 -2
  27. package/dist/bundle/chunks/{chunk-J6H2LYOZ.js → chunk-TLYT7KXA.js} +1 -1
  28. package/dist/bundle/chunks/{chunk-QU2VEHMW.js → chunk-XIF7O6UG.js} +3 -3
  29. package/dist/bundle/chunks/{chunk-F52JQCLE.js → chunk-XKOYUKPQ.js} +1 -1
  30. package/dist/bundle/chunks/{chunk-X63WCLSX.js → chunk-ZLZHK7BO.js} +274 -274
  31. package/dist/bundle/chunks/{chunk-C5ELI234.js → chunk-ZVMXRMIH.js} +1 -1
  32. package/dist/bundle/chunks/{cli-BFWJUYZ5.js → cli-4VML7NOW.js} +1 -1
  33. package/dist/bundle/chunks/cli-RJETLDQ5.js +30 -0
  34. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-RXFI2EBV.js → cloudflare-workers-ai-system-one-63ASD4MS.js} +1 -1
  35. package/dist/bundle/chunks/{easter-egg-3d-W2F3ROZ6.js → easter-egg-3d-JQUBBOXE.js} +1 -1
  36. package/dist/bundle/chunks/{execute-NJRE4WBO.js → execute-ZIFT667Q.js} +1 -1
  37. package/dist/bundle/chunks/{google-generative-ai-5F5544G4.js → google-generative-ai-4T6TSKGZ.js} +1 -1
  38. package/dist/bundle/chunks/{google-vertex-4PSVELDG.js → google-vertex-Z2AJIOKJ.js} +1 -1
  39. package/dist/bundle/chunks/{llama-cpp-classify-IPNT4VOW.js → llama-cpp-classify-UD7L3OEZ.js} +1 -1
  40. package/dist/bundle/chunks/{mcp-F3BQ6MQW.js → mcp-7W2PZMFF.js} +1 -1
  41. package/dist/bundle/chunks/{mistral-conversations-RSYLYGE4.js → mistral-conversations-W4M2WAFU.js} +1 -1
  42. package/dist/bundle/chunks/{office-UBOUFRAU.js → office-FIY2WQ2K.js} +1 -1
  43. package/dist/bundle/chunks/oidc-WQ64R7RE.js +1 -0
  44. package/dist/bundle/chunks/{openai-codex-responses-OKPZLYIS.js → openai-codex-responses-NYZACUJQ.js} +1 -1
  45. package/dist/bundle/chunks/{openai-completions-BFCQZRZ2.js → openai-completions-GOZT4TOU.js} +1 -1
  46. package/dist/bundle/chunks/{openai-decisions-RJ4MH5XI.js → openai-decisions-ZJSAGWHI.js} +1 -1
  47. package/dist/bundle/chunks/{openai-responses-PT5MXG3Q.js → openai-responses-ZVECOLDP.js} +1 -1
  48. package/dist/bundle/chunks/{openrouter-images-ICCH2YHW.js → openrouter-images-BOGEFLXU.js} +1 -1
  49. package/dist/bundle/chunks/{pi-messages-Z2XWHIYT.js → pi-messages-XDGHAFKO.js} +1 -1
  50. package/dist/bundle/chunks/{review-WTYIVWYR.js → review-ESZWG3ID.js} +1 -1
  51. package/dist/bundle/chunks/{router-V3EIAYOF.js → router-ZQ7UPIHA.js} +1 -1
  52. package/dist/bundle/chunks/{runtime-FNCZJKOC.js → runtime-KHMBKDP7.js} +1 -1
  53. package/dist/bundle/chunks/{sdk-32L63XRF.js → sdk-6F6YIKOL.js} +1 -1
  54. package/dist/bundle/chunks/src-TVUSERYE.js +3 -0
  55. package/dist/bundle/chunks/{sync-Z5USQ7AN.js → sync-F7N6C6RF.js} +1 -1
  56. package/dist/bundle/chunks/{typesafe-system-one-6UYWINOZ.js → typesafe-system-one-NSQNXICI.js} +1 -1
  57. package/dist/bundle/chunks/{usage-JODQIC2H.js → usage-5VHK66HK.js} +1 -1
  58. package/dist/bundle/chunks/{virtual-modules-ERCLFZEY.js → virtual-modules-ABFE2KKD.js} +1 -1
  59. package/dist/bundle/cli-runtime.js +1 -1
  60. package/dist/bundle/index.js +1 -1
  61. package/dist/bundle/rpc-entry.js +1 -1
  62. package/dist/config.d.ts +1 -0
  63. package/dist/config.js +1 -1
  64. package/dist/index.d.ts +1 -1
  65. package/dist/index.js +1 -1
  66. package/dist/main.js +4 -4
  67. package/dist/node_modules/@dalcode/dal-advisor/package.json +3 -3
  68. package/dist/node_modules/@dalcode/dal-awake/package.json +2 -2
  69. package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
  70. package/dist/node_modules/@dalcode/dal-bridge/src/index.js +1 -1
  71. package/dist/node_modules/@dalcode/dal-capabilities/package.json +4 -4
  72. package/dist/node_modules/@dalcode/dal-codeindex/package.json +2 -2
  73. package/dist/node_modules/@dalcode/dal-compat/package.json +2 -2
  74. package/dist/node_modules/@dalcode/dal-dap/package.json +2 -2
  75. package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
  76. package/dist/node_modules/@dalcode/dal-goal/package.json +3 -3
  77. package/dist/node_modules/@dalcode/dal-guard/package.json +4 -4
  78. package/dist/node_modules/@dalcode/dal-guard/src/attribution.js +1 -1
  79. package/dist/node_modules/@dalcode/dal-guard/src/index.js +4 -4
  80. package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
  81. package/dist/node_modules/@dalcode/dal-interactive/package.json +2 -2
  82. package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
  83. package/dist/node_modules/@dalcode/dal-learn/package.json +2 -2
  84. package/dist/node_modules/@dalcode/dal-lsp/package.json +4 -4
  85. package/dist/node_modules/@dalcode/dal-mcp/package.json +6 -6
  86. package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
  87. package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +4 -4
  88. package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
  89. package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +4 -4
  90. package/dist/node_modules/@dalcode/dal-plugins/package.json +4 -4
  91. package/dist/node_modules/@dalcode/dal-recall/package.json +2 -2
  92. package/dist/node_modules/@dalcode/dal-remote/package.json +3 -2
  93. package/dist/node_modules/@dalcode/dal-remote/src/account.js +2 -0
  94. package/dist/node_modules/@dalcode/dal-remote/src/cli.js +13 -13
  95. package/dist/node_modules/@dalcode/dal-remote/src/install.js +2 -2
  96. package/dist/node_modules/@dalcode/dal-remote/src/spec.js +1 -1
  97. package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
  98. package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
  99. package/dist/node_modules/@dalcode/dal-router/package.json +6 -6
  100. package/dist/node_modules/@dalcode/dal-rtk/package.json +2 -2
  101. package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
  102. package/dist/node_modules/@dalcode/dal-statusline/package.json +2 -2
  103. package/dist/node_modules/@dalcode/dal-structured/package.json +2 -2
  104. package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
  105. package/dist/node_modules/@dalcode/dal-sync/package.json +4 -4
  106. package/dist/node_modules/@dalcode/dal-telemetry/package.json +4 -4
  107. package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
  108. package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
  109. package/dist/node_modules/@dalcode/dal-usage/package.json +2 -2
  110. package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
  111. package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
  112. package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
  113. package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  114. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  115. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  116. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
  117. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.d.ts +1 -1
  118. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.js +1 -1
  119. package/dist/node_modules/@earendil-works/pi-ai/package.json +3 -3
  120. package/dist/node_modules/@earendil-works/pi-codemode/package.json +1 -1
  121. package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
  122. package/dist/node_modules/@earendil-works/pi-mcp/package.json +1 -1
  123. package/dist/node_modules/@earendil-works/pi-schema/package.json +1 -1
  124. package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  125. package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
  126. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  127. package/examples/extensions/gondolin/package-lock.json +2 -2
  128. package/examples/extensions/gondolin/package.json +1 -1
  129. package/examples/extensions/with-deps/package-lock.json +2 -2
  130. package/examples/extensions/with-deps/package.json +1 -1
  131. package/npm-shrinkwrap.json +2 -2
  132. package/package.json +1 -1
  133. package/dist/bundle/chunks/chunk-WLQ33LIH.js +0 -9
  134. package/dist/bundle/chunks/cli-NQ7B7BGV.js +0 -30
@@ -1,4 +1,4 @@
1
- var O=Object.defineProperty;var i=(t,e)=>O(t,"name",{value:e,configurable:!0});import{createRequire as j}from"node:module";const we=j(import.meta.url);import{combineAbortSignals as L}from"./chunk-RDZVAGPR.js";import{shortHash as N}from"./chunk-PJACZCIR.js";import{buildBaseOptions as D,getJsonSchemaToolParameters as U,resolveJsonSchemaStrictSampling as H,transformMessages as q}from"./chunk-TPOKZ2EU.js";import{sanitizeSurrogates as x}from"./chunk-L2ZPNLYD.js";import{truncateErrorText as z}from"./chunk-BBNE2TWS.js";import{headersToRecord as J}from"./chunk-UTB4DTYQ.js";import{ToolCallArgumentsStream as B}from"./chunk-FFMDRXC4.js";import{calculateCost as K,clampThinkingLevel as W,getCurrentTools as F,resolveTranscript as Z}from"./chunk-VDPDHGGJ.js";import{AssistantMessageEventStream as G}from"./chunk-4LDEEFCY.js";import{getIdentityHeaders as X,getSystemMessageText as Y,renderSystemMessageUpdate as Q}from"./chunk-F52JQCLE.js";import"./chunk-JXWJOIH4.js";var T=9,V=4e3,v=i((t,e,n)=>{let r=new G,a=Z(e,t.compat?.supportsMidConvoSystemMessages);return(async()=>{let o=te(t);try{let d=n?.apiKey;if(!d)throw new Error(`No API key for provider: ${t.provider}`);let p=ne(),f=q(a.messages,t,m=>p(m)),s=fe(t,a,f,n),l=await n?.onPayload?.(s,t);l!==void 0&&(s=l);let c=await oe(t,s,d,n);if(r.push({type:"start",partial:o}),await me(t,o,r,c,n?.onProviderStreamEvent),n?.signal?.aborted)throw new Error("Request was aborted");if(o.stopReason==="pending")throw new Error("Mistral stream ended without a finish reason");if(o.stopReason==="aborted"||o.stopReason==="error")throw new Error(o.errorMessage||"An unknown error occurred");r.push({type:"done",reason:o.stopReason,message:o}),r.end()}catch(d){o.stopReason=n?.signal?.aborted?"aborted":"error",o.errorMessage=re(d),r.push({type:"error",reason:o.stopReason,error:o}),r.end()}})(),r},"stream"),ee=i((t,e,n)=>{let r=n?.apiKey;if(!r)throw new Error(`No API key for provider: ${t.provider}`);let a={...D(t,e,n,r),toolChoice:n?.toolChoice},o=n?.reasoning?W(t,n.reasoning):void 0,d=o==="off"?void 0:o,p=t.reasoning?t.thinkingLevelMap:void 0,f=p?d?p[d]??"high":p.off??void 0:void 0;return v(t,e,{...a,promptMode:t.reasoning&&!p&&d?"reasoning":void 0,reasoningEffort:f})},"streamSimple");function te(t){return{role:"assistant",content:[],api:t.api,provider:t.provider,model:t.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"pending",timestamp:Date.now()}}i(te,"createOutput");function ne(){let t=new Map,e=new Map;return n=>{let r=t.get(n);if(r)return r;let a=0;for(;;){let o=R(n,a),d=e.get(o);if(!d||d===n)return t.set(n,o),e.set(o,n),o;a++}}}i(ne,"createMistralToolCallIdNormalizer");function R(t,e){let n=t.replace(/[^a-zA-Z0-9]/g,"");if(e===0&&n.length===T)return n;let r=n||t,a=e===0?r:`${r}:${e}`;return N(a).replace(/[^a-zA-Z0-9]/g,"").slice(0,T)}i(R,"deriveMistralToolCallId");function re(t){if(t instanceof Error){let e=t,n=typeof e.statusCode=="number"?e.statusCode:void 0,r=typeof e.body=="string"?e.body.trim():void 0;return n!==void 0&&r?`Mistral API error (${n}): ${z(r,V)}`:n!==void 0?`Mistral API error (${n}): ${t.message}`:t.message}return ae(t)}i(re,"formatMistralError");function ae(t){try{let e=JSON.stringify(t);return e===void 0?String(t):e}catch{return String(t)}}i(ae,"safeJsonStringify");async function oe(t,e,n,r){let a=new URL(t.baseUrl);a.pathname=`${a.pathname.replace(/\/+$/u,"")}/`;let o=new URL("v1/chat/completions",a),d=ie(t,n,r),p=r?.timeoutMs??6e4,f=AbortSignal.timeout(p),s=L([r?.signal,f]),l;try{l=await(r?.fetch??globalThis.fetch)(o,{method:"POST",headers:d,body:JSON.stringify(le(e)),signal:s.signal})}catch(c){throw f.aborted&&!r?.signal?.aborted?new Error(`Mistral response headers timed out after ${p}ms`):c}finally{s.cleanup()}if(await r?.onResponse?.({status:l.status,headers:J(l.headers)},t),!l.ok){let c=await l.text();throw new se(l.status,c,l.statusText)}if(!l.body)throw new Error("Mistral response has no body");return pe(l.body,r?.signal)}i(oe,"requestMistralStream");var se=class extends Error{static{i(this,"MistralHttpError")}statusCode;body;constructor(t,e,n){super(n||`Request failed with status ${t}`),this.name="MistralHttpError",this.statusCode=t,this.body=e}};function ie(t,e,n){let r=new Headers({...X(t,n?.identity),accept:"text/event-stream",authorization:`Bearer ${e}`,"content-type":"application/json"});S(r,t.headers),S(r,n?.headers);let a=I(t.headers,"x-affinity")||I(n?.headers,"x-affinity");return P(n)&&!a&&r.set("x-affinity",n.sessionId),r}i(ie,"buildMistralHeaders");function S(t,e){if(e)for(let[n,r]of Object.entries(e))r===null?t.delete(n):t.set(n,r)}i(S,"applyMistralHeaderOverrides");function I(t,e){return!!t&&Object.keys(t).some(n=>n.toLowerCase()===e)}i(I,"hasMistralHeaderOverride");function le(t){let e={...t};for(let[r,a]of[["topP","top_p"],["maxTokens","max_tokens"],["randomSeed","random_seed"],["responseFormat","response_format"],["toolChoice","tool_choice"],["presencePenalty","presence_penalty"],["frequencyPenalty","frequency_penalty"],["parallelToolCalls","parallel_tool_calls"],["reasoningEffort","reasoning_effort"],["promptMode","prompt_mode"],["promptCacheKey","prompt_cache_key"],["safePrompt","safe_prompt"]])k(e,r,a);e.messages=t.messages.map(r=>ce(r));let n=e.response_format;if(w(n)){let r={...n};k(r,"jsonSchema","json_schema");let a=r.json_schema;if(w(a)){let o={...a};k(o,"schemaDefinition","schema"),r.json_schema=o}e.response_format=r}return e}i(le,"toMistralWirePayload");function ce(t){let e={...t};return k(e,"toolCalls","tool_calls"),k(e,"toolCallId","tool_call_id"),Array.isArray(t.content)&&(e.content=t.content.map(n=>de(n))),e}i(ce,"toMistralWireMessage");function de(t){let e={...t};for(let[n,r]of[["imageUrl","image_url"],["documentUrl","document_url"],["documentName","document_name"],["fileId","file_id"],["referenceIds","reference_ids"],["inputAudio","input_audio"]])k(e,n,r);return e}i(de,"toMistralWireContentChunk");function k(t,e,n){e in t&&(t[n]=t[e],delete t[e])}i(k,"remapMistralProperty");function w(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}i(w,"isMistralRecord");var b=Symbol("mistral-stream-done");async function*pe(t,e){let n=t.getReader(),r=new TextDecoder,a="",o=i(()=>{n.cancel().catch(()=>{})},"onAbort");e?.addEventListener("abort",o,{once:!0});try{for(;;){if(e?.aborted)throw e.reason;let{done:d,value:p}=await n.read();if(e?.aborted)throw e.reason;a+=d?r.decode():r.decode(p,{stream:!0});let f=E(a);for(;f;){let s=A(a.slice(0,f.index));if(a=a.slice(f.index+f.length),s===b)return;s&&(yield s),f=E(a)}if(d)break}if(a.trim()){let d=A(a);d!==b&&d&&(yield d)}}finally{e?.removeEventListener("abort",o);try{await n.cancel()}catch{}try{n.releaseLock()}catch{}}}i(pe,"readMistralEvents");function E(t){let e=/\r\n\r\n|\r\n\r|\r\n\n|\r\r\n|\n\r\n|\r\r|\n\r|\n\n/u.exec(t);return e?.index===void 0?void 0:{index:e.index,length:e[0].length}}i(E,"findMistralEventBoundary");function A(t){let e=t.split(/\r\n|\r|\n/u).filter(r=>r.startsWith("data:")).map(r=>r.slice(5).trimStart()).join(`
1
+ var O=Object.defineProperty;var i=(t,e)=>O(t,"name",{value:e,configurable:!0});import{createRequire as j}from"node:module";const we=j(import.meta.url);import{combineAbortSignals as L}from"./chunk-RDZVAGPR.js";import{shortHash as N}from"./chunk-PJACZCIR.js";import{buildBaseOptions as D,getJsonSchemaToolParameters as U,resolveJsonSchemaStrictSampling as H,transformMessages as q}from"./chunk-3UVUVPDJ.js";import{sanitizeSurrogates as x}from"./chunk-L2ZPNLYD.js";import{truncateErrorText as z}from"./chunk-4PE5FX77.js";import{headersToRecord as J}from"./chunk-UTB4DTYQ.js";import{ToolCallArgumentsStream as B}from"./chunk-FFMDRXC4.js";import{calculateCost as K,clampThinkingLevel as W,getCurrentTools as F,resolveTranscript as Z}from"./chunk-DM37LCOU.js";import{AssistantMessageEventStream as G}from"./chunk-4LDEEFCY.js";import{getIdentityHeaders as X,getSystemMessageText as Y,renderSystemMessageUpdate as Q}from"./chunk-XKOYUKPQ.js";import"./chunk-JXWJOIH4.js";var T=9,V=4e3,v=i((t,e,n)=>{let r=new G,a=Z(e,t.compat?.supportsMidConvoSystemMessages);return(async()=>{let o=te(t);try{let d=n?.apiKey;if(!d)throw new Error(`No API key for provider: ${t.provider}`);let p=ne(),f=q(a.messages,t,m=>p(m)),s=fe(t,a,f,n),l=await n?.onPayload?.(s,t);l!==void 0&&(s=l);let c=await oe(t,s,d,n);if(r.push({type:"start",partial:o}),await me(t,o,r,c,n?.onProviderStreamEvent),n?.signal?.aborted)throw new Error("Request was aborted");if(o.stopReason==="pending")throw new Error("Mistral stream ended without a finish reason");if(o.stopReason==="aborted"||o.stopReason==="error")throw new Error(o.errorMessage||"An unknown error occurred");r.push({type:"done",reason:o.stopReason,message:o}),r.end()}catch(d){o.stopReason=n?.signal?.aborted?"aborted":"error",o.errorMessage=re(d),r.push({type:"error",reason:o.stopReason,error:o}),r.end()}})(),r},"stream"),ee=i((t,e,n)=>{let r=n?.apiKey;if(!r)throw new Error(`No API key for provider: ${t.provider}`);let a={...D(t,e,n,r),toolChoice:n?.toolChoice},o=n?.reasoning?W(t,n.reasoning):void 0,d=o==="off"?void 0:o,p=t.reasoning?t.thinkingLevelMap:void 0,f=p?d?p[d]??"high":p.off??void 0:void 0;return v(t,e,{...a,promptMode:t.reasoning&&!p&&d?"reasoning":void 0,reasoningEffort:f})},"streamSimple");function te(t){return{role:"assistant",content:[],api:t.api,provider:t.provider,model:t.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"pending",timestamp:Date.now()}}i(te,"createOutput");function ne(){let t=new Map,e=new Map;return n=>{let r=t.get(n);if(r)return r;let a=0;for(;;){let o=R(n,a),d=e.get(o);if(!d||d===n)return t.set(n,o),e.set(o,n),o;a++}}}i(ne,"createMistralToolCallIdNormalizer");function R(t,e){let n=t.replace(/[^a-zA-Z0-9]/g,"");if(e===0&&n.length===T)return n;let r=n||t,a=e===0?r:`${r}:${e}`;return N(a).replace(/[^a-zA-Z0-9]/g,"").slice(0,T)}i(R,"deriveMistralToolCallId");function re(t){if(t instanceof Error){let e=t,n=typeof e.statusCode=="number"?e.statusCode:void 0,r=typeof e.body=="string"?e.body.trim():void 0;return n!==void 0&&r?`Mistral API error (${n}): ${z(r,V)}`:n!==void 0?`Mistral API error (${n}): ${t.message}`:t.message}return ae(t)}i(re,"formatMistralError");function ae(t){try{let e=JSON.stringify(t);return e===void 0?String(t):e}catch{return String(t)}}i(ae,"safeJsonStringify");async function oe(t,e,n,r){let a=new URL(t.baseUrl);a.pathname=`${a.pathname.replace(/\/+$/u,"")}/`;let o=new URL("v1/chat/completions",a),d=ie(t,n,r),p=r?.timeoutMs??6e4,f=AbortSignal.timeout(p),s=L([r?.signal,f]),l;try{l=await(r?.fetch??globalThis.fetch)(o,{method:"POST",headers:d,body:JSON.stringify(le(e)),signal:s.signal})}catch(c){throw f.aborted&&!r?.signal?.aborted?new Error(`Mistral response headers timed out after ${p}ms`):c}finally{s.cleanup()}if(await r?.onResponse?.({status:l.status,headers:J(l.headers)},t),!l.ok){let c=await l.text();throw new se(l.status,c,l.statusText)}if(!l.body)throw new Error("Mistral response has no body");return pe(l.body,r?.signal)}i(oe,"requestMistralStream");var se=class extends Error{static{i(this,"MistralHttpError")}statusCode;body;constructor(t,e,n){super(n||`Request failed with status ${t}`),this.name="MistralHttpError",this.statusCode=t,this.body=e}};function ie(t,e,n){let r=new Headers({...X(t,n?.identity),accept:"text/event-stream",authorization:`Bearer ${e}`,"content-type":"application/json"});S(r,t.headers),S(r,n?.headers);let a=I(t.headers,"x-affinity")||I(n?.headers,"x-affinity");return P(n)&&!a&&r.set("x-affinity",n.sessionId),r}i(ie,"buildMistralHeaders");function S(t,e){if(e)for(let[n,r]of Object.entries(e))r===null?t.delete(n):t.set(n,r)}i(S,"applyMistralHeaderOverrides");function I(t,e){return!!t&&Object.keys(t).some(n=>n.toLowerCase()===e)}i(I,"hasMistralHeaderOverride");function le(t){let e={...t};for(let[r,a]of[["topP","top_p"],["maxTokens","max_tokens"],["randomSeed","random_seed"],["responseFormat","response_format"],["toolChoice","tool_choice"],["presencePenalty","presence_penalty"],["frequencyPenalty","frequency_penalty"],["parallelToolCalls","parallel_tool_calls"],["reasoningEffort","reasoning_effort"],["promptMode","prompt_mode"],["promptCacheKey","prompt_cache_key"],["safePrompt","safe_prompt"]])k(e,r,a);e.messages=t.messages.map(r=>ce(r));let n=e.response_format;if(w(n)){let r={...n};k(r,"jsonSchema","json_schema");let a=r.json_schema;if(w(a)){let o={...a};k(o,"schemaDefinition","schema"),r.json_schema=o}e.response_format=r}return e}i(le,"toMistralWirePayload");function ce(t){let e={...t};return k(e,"toolCalls","tool_calls"),k(e,"toolCallId","tool_call_id"),Array.isArray(t.content)&&(e.content=t.content.map(n=>de(n))),e}i(ce,"toMistralWireMessage");function de(t){let e={...t};for(let[n,r]of[["imageUrl","image_url"],["documentUrl","document_url"],["documentName","document_name"],["fileId","file_id"],["referenceIds","reference_ids"],["inputAudio","input_audio"]])k(e,n,r);return e}i(de,"toMistralWireContentChunk");function k(t,e,n){e in t&&(t[n]=t[e],delete t[e])}i(k,"remapMistralProperty");function w(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}i(w,"isMistralRecord");var b=Symbol("mistral-stream-done");async function*pe(t,e){let n=t.getReader(),r=new TextDecoder,a="",o=i(()=>{n.cancel().catch(()=>{})},"onAbort");e?.addEventListener("abort",o,{once:!0});try{for(;;){if(e?.aborted)throw e.reason;let{done:d,value:p}=await n.read();if(e?.aborted)throw e.reason;a+=d?r.decode():r.decode(p,{stream:!0});let f=E(a);for(;f;){let s=A(a.slice(0,f.index));if(a=a.slice(f.index+f.length),s===b)return;s&&(yield s),f=E(a)}if(d)break}if(a.trim()){let d=A(a);d!==b&&d&&(yield d)}}finally{e?.removeEventListener("abort",o);try{await n.cancel()}catch{}try{n.releaseLock()}catch{}}}i(pe,"readMistralEvents");function E(t){let e=/\r\n\r\n|\r\n\r|\r\n\n|\r\r\n|\n\r\n|\r\r|\n\r|\n\n/u.exec(t);return e?.index===void 0?void 0:{index:e.index,length:e[0].length}}i(E,"findMistralEventBoundary");function A(t){let e=t.split(/\r\n|\r|\n/u).filter(r=>r.startsWith("data:")).map(r=>r.slice(5).trimStart()).join(`
2
2
  `).trim();if(!e)return;if(e==="[DONE]")return b;let n=JSON.parse(e);if(!w(n)||!Array.isArray(n.choices))throw new Error("Invalid Mistral streaming event");return{data:n}}i(A,"parseMistralEvent");function fe(t,e,n,r){let a={model:t.id,stream:!0,messages:ge(n,t.input.includes("image"))},o=F(e.messages);return o.length>0&&(a.tools=he(o)),r?.temperature!==void 0&&(a.temperature=r.temperature),r?.maxTokens!==void 0&&(a.maxTokens=r.maxTokens),r?.toolChoice&&(a.toolChoice=xe(r.toolChoice)),r?.promptMode&&(a.promptMode=r.promptMode),r?.reasoningEffort&&(a.reasoningEffort=r.reasoningEffort),P(r)&&(a.promptCacheKey=r.sessionId),a}i(fe,"buildChatPayload");function P(t){return t?.cacheRetention!=="none"&&!!t?.sessionId}i(P,"shouldUsePromptCaching");function ue(t,e){let n=t,r=n.promptTokensDetails?.cachedTokens??n.prompt_tokens_details?.cached_tokens??n.promptTokenDetails?.cachedTokens??n.prompt_token_details?.cached_tokens??n.numCachedTokens??n.num_cached_tokens??0,a=typeof r=="number"&&Number.isFinite(r)?r:0;return Math.min(e,Math.max(0,a))}i(ue,"getMistralCachedPromptTokens");async function me(t,e,n,r,a){let o=null,d=e.content,p=i(()=>d.length-1,"blockIndex"),f=new Map,s=i(l=>{if(l){if(l.type==="text"){n.push({type:"text_end",contentIndex:p(),content:l.text,partial:e});return}l.type==="thinking"&&n.push({type:"thinking_end",contentIndex:p(),content:l.thinking,partial:e})}},"finishCurrentBlock");for await(let l of r){let c=l.data;if(await a?.(c,t),e.responseId||=c.id,c.usage){let u=c.usage.prompt_tokens||0,h=ue(c.usage,u);e.usage.input=Math.max(0,u-h),e.usage.output=c.usage.completion_tokens||0,e.usage.cacheRead=h,e.usage.cacheWrite=0,e.usage.totalTokens=c.usage.total_tokens||e.usage.input+e.usage.output+e.usage.cacheRead+e.usage.cacheWrite,K(t,e.usage)}let m=c.choices[0];if(!m)continue;if(m.finish_reason){e.rawStopReason=m.finish_reason;let u=_e(m.finish_reason);e.stopReason=u.stopReason,u.errorMessage&&(e.errorMessage=u.errorMessage)}let _=m.delta;if(_.content!==null&&_.content!==void 0){let u=typeof _.content=="string"?[_.content]:_.content;for(let h of u){if(typeof h=="string"){let g=x(h);if(!g)continue;(!o||o.type!=="text")&&(s(o),o={type:"text",text:""},e.content.push(o),n.push({type:"text_start",contentIndex:p(),partial:e})),o.text+=g,n.push({type:"text_delta",contentIndex:p(),delta:g,partial:e});continue}if(h.type==="thinking"){let g=(h.thinking??[]).map(M=>M.text??"").filter(M=>M.length>0).join(""),y=x(g);if(!y)continue;(!o||o.type!=="thinking")&&(s(o),o={type:"thinking",thinking:""},e.content.push(o),n.push({type:"thinking_start",contentIndex:p(),partial:e})),o.thinking+=y,n.push({type:"thinking_delta",contentIndex:p(),delta:y,partial:e});continue}if(h.type==="text"){let g=x(h.text??"");if(!g)continue;(!o||o.type!=="text")&&(s(o),o={type:"text",text:""},e.content.push(o),n.push({type:"text_start",contentIndex:p(),partial:e})),o.text+=g,n.push({type:"text_delta",contentIndex:p(),delta:g,partial:e})}}}let $=_.tool_calls||[];for(let u of $){o&&(s(o),o=null);let h=u.id&&u.id!=="null"?u.id:R(`toolcall:${u.index??0}`,0),g=u.index??h,y=f.get(g);y||(e.content.push({type:"toolCall",id:h,name:u.function.name,arguments:{}}),y={contentIndex:e.content.length-1,arguments:new B},f.set(g,y),n.push({type:"toolcall_start",contentIndex:y.contentIndex,partial:e}));let M=typeof u.function.arguments=="string"?u.function.arguments:JSON.stringify(u.function.arguments||{});e.content[y.contentIndex].arguments=y.arguments.append(M),n.push({type:"toolcall_delta",contentIndex:y.contentIndex,delta:M,partial:e})}}s(o);for(let l of f.values()){let c=e.content[l.contentIndex];Object.assign(c,l.arguments.finish()),n.push({type:"toolcall_end",contentIndex:l.contentIndex,toolCall:c,partial:e})}}i(me,"consumeChatStream");function he(t){return t.map(e=>{let n=H(e,!0);return{type:"function",function:{name:e.name,description:e.description,parameters:C(U(e,n)),strict:n??!1}}})}i(he,"toFunctionTools");function C(t){if(Array.isArray(t))return t.map(e=>C(e));if(t&&typeof t=="object"){let e={};for(let[n,r]of Object.entries(t))e[n]=C(r);return e}return t}i(C,"stripSymbolKeys");function ge(t,e){let n=[];for(let[r,a]of t.entries()){if(a.role==="system"){let s=r===0?Y(a):Q(a);s.length>0&&n.push({role:"system",content:x(s)});continue}if(a.role==="user"){if(typeof a.content=="string"){n.push({role:"user",content:x(a.content)});continue}let s=a.content.some(c=>c.type==="image"),l=a.content.filter(c=>c.type==="text"||e).map(c=>c.type==="text"?{type:"text",text:x(c.text)}:{type:"image_url",imageUrl:`data:${c.mimeType};base64,${c.data}`});if(l.length>0){n.push({role:"user",content:l});continue}s&&!e&&n.push({role:"user",content:"(image omitted: model does not support images)"});continue}if(a.role==="assistant"){let s=[],l=[];for(let m of a.content){if(m.type==="text"){m.text.trim().length>0&&s.push({type:"text",text:x(m.text)});continue}if(m.type==="thinking"){m.thinking.trim().length>0&&s.push({type:"thinking",thinking:[{type:"text",text:x(m.thinking)}]});continue}l.push({id:m.id,type:"function",function:{name:m.name,arguments:JSON.stringify(m.arguments||{})},index:0})}let c={role:"assistant",prefix:!1};s.length>0&&(c.content=s),l.length>0&&(c.toolCalls=l),(s.length>0||l.length>0)&&n.push(c);continue}let o=[],d=a.content.filter(s=>s.type==="text").map(s=>s.type==="text"?x(s.text):"").join(`
3
3
  `),p=a.content.some(s=>s.type==="image"),f=ye(d,p,e,a.isError);o.push({type:"text",text:f});for(let s of a.content)e&&s.type==="image"&&o.push({type:"image_url",imageUrl:`data:${s.mimeType};base64,${s.data}`});n.push({role:"tool",toolCallId:a.toolCallId,name:a.toolName,content:o})}return n}i(ge,"toChatMessages");function ye(t,e,n,r){let a=t.trim(),o=r?"[tool error] ":"";return a.length>0?`${o}${a}${e&&!n?`
4
4
  [tool image omitted: model does not support images]`:""}`:e?n?r?"[tool error] (see attached image)":"(see attached image)":r?"[tool error] (image omitted: model does not support images)":"(image omitted: model does not support images)":r?"[tool error] (no tool output)":"(no tool output)"}i(ye,"buildToolResultText");function xe(t){if(t)return t==="auto"||t==="none"||t==="any"||t==="required"?t:{type:"function",function:{name:t.function.name}}}i(xe,"mapToolChoice");function _e(t){if(t===null)return{stopReason:"stop"};switch(t){case"stop":return{stopReason:"stop"};case"length":case"model_length":return{stopReason:"length"};case"tool_calls":return{stopReason:"toolUse"};case"error":return{stopReason:"error",errorMessage:"Provider stopped with: error (server error)"};default:return{stopReason:"error",errorMessage:`Provider stopped with: ${t}`}}}i(_e,"mapChatStopReason");export{v as stream,ee as streamSimple};