dal-code 1.0.55 → 1.0.57

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 (177) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/bundle/chunks/{anthropic-messages-LJWWEQIU.js → anthropic-messages-ASQGS6BL.js} +1 -1
  3. package/dist/bundle/chunks/{azure-openai-responses-GK4VH6GM.js → azure-openai-responses-ZSCUJBSU.js} +1 -1
  4. package/dist/bundle/chunks/bedrock-converse-stream.js +1 -1
  5. package/dist/bundle/chunks/{chunk-DBT5OS5V.js → chunk-2E7RGBKM.js} +1 -1
  6. package/dist/bundle/chunks/{chunk-3ANBT7AT.js → chunk-34D4KVPX.js} +1 -1
  7. package/dist/bundle/chunks/chunk-6PQZ4KMC.js +17 -0
  8. package/dist/bundle/chunks/chunk-6SPX3U36.js +1 -0
  9. package/dist/bundle/chunks/{chunk-DWMC4U2M.js → chunk-F577XLVZ.js} +1 -1
  10. package/dist/bundle/chunks/{chunk-6U37J6E7.js → chunk-FSX34SAZ.js} +340 -366
  11. package/dist/bundle/chunks/chunk-G5AMLGXC.js +1 -0
  12. package/dist/bundle/chunks/{chunk-44EXLOHK.js → chunk-GPI2GHBH.js} +1 -1
  13. package/dist/bundle/chunks/chunk-HF334NQU.js +21 -0
  14. package/dist/bundle/chunks/{chunk-5TGFM4KW.js → chunk-IRSW3MVW.js} +2 -2
  15. package/dist/bundle/chunks/chunk-JPBJUBY4.js +17 -0
  16. package/dist/bundle/chunks/chunk-JPCWLZUZ.js +30 -0
  17. package/dist/bundle/chunks/chunk-JUUJCOIR.js +7 -0
  18. package/dist/bundle/chunks/{chunk-KSF7BFGS.js → chunk-KP7CMLOT.js} +1 -1
  19. package/dist/bundle/chunks/chunk-LZTZWS3N.js +9 -0
  20. package/dist/bundle/chunks/{chunk-ZYP3V3TD.js → chunk-MAJODFX6.js} +1 -1
  21. package/dist/bundle/chunks/{chunk-SNBVCTMQ.js → chunk-MZ7O6YLD.js} +3 -3
  22. package/dist/bundle/chunks/chunk-NJDCSLWK.js +1 -0
  23. package/dist/bundle/chunks/{chunk-SCSGNIU5.js → chunk-O3XFDBJ3.js} +1 -1
  24. package/dist/bundle/chunks/{chunk-2XX4WZT6.js → chunk-PD6QS7YD.js} +1 -1
  25. package/dist/bundle/chunks/{chunk-SMPERFJU.js → chunk-S7K3JBWA.js} +1 -1
  26. package/dist/bundle/chunks/{chunk-PRBATF6B.js → chunk-TNSXMGQB.js} +1 -1
  27. package/dist/bundle/chunks/chunk-XIJS4F22.js +14 -0
  28. package/dist/bundle/chunks/{chunk-GX37DI5S.js → chunk-YTDTROS5.js} +1 -1
  29. package/dist/bundle/chunks/{cli-Z44UHMMU.js → cli-IDAZVEZ2.js} +1 -1
  30. package/dist/bundle/chunks/{cli-VKNCK5P5.js → cli-NP7QEFQE.js} +1 -1
  31. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-G4E4L26A.js → cloudflare-workers-ai-system-one-WLKVTF6I.js} +1 -1
  32. package/dist/bundle/chunks/{execute-3FWM3EMV.js → execute-VXSJSHXH.js} +2 -2
  33. package/dist/bundle/chunks/github-copilot.js +1 -1
  34. package/dist/bundle/chunks/{google-generative-ai-HVFDKPI3.js → google-generative-ai-3HIBMVL4.js} +1 -1
  35. package/dist/bundle/chunks/{google-vertex-6E4HATAC.js → google-vertex-7PIUZFM3.js} +1 -1
  36. package/dist/bundle/chunks/{llama-cpp-classify-3HAEJDKO.js → llama-cpp-classify-5OLOZHKT.js} +1 -1
  37. package/dist/bundle/chunks/mcp-GHYUCPI4.js +10 -0
  38. package/dist/bundle/chunks/{mistral-conversations-6UC2WYUC.js → mistral-conversations-6Y33SI3U.js} +1 -1
  39. package/dist/bundle/chunks/{office-2F4B572E.js → office-2JSKOL7V.js} +1 -1
  40. package/dist/bundle/chunks/{openai-codex-responses-WPSZR4EE.js → openai-codex-responses-BYGMMTPH.js} +1 -1
  41. package/dist/bundle/chunks/{openai-completions-2RGIFVKJ.js → openai-completions-UWYQMOLR.js} +1 -1
  42. package/dist/bundle/chunks/{openai-decisions-BLZVYNRQ.js → openai-decisions-I5J7OD62.js} +1 -1
  43. package/dist/bundle/chunks/{openai-responses-N65DO7MB.js → openai-responses-LWVKQGLT.js} +1 -1
  44. package/dist/bundle/chunks/{openrouter-images-LQ4VP5P7.js → openrouter-images-BDUFN6XX.js} +1 -1
  45. package/dist/bundle/chunks/{pi-messages-VYTRLMVB.js → pi-messages-64FHWMQR.js} +1 -1
  46. package/dist/bundle/chunks/{review-MKITXKSI.js → review-OQEOVDLP.js} +2 -2
  47. package/dist/bundle/chunks/{router-RL7OYANY.js → router-3UQE4LBN.js} +1 -1
  48. package/dist/bundle/chunks/runtime-E7KOB62K.js +1 -0
  49. package/dist/bundle/chunks/sdk-5V64WBOZ.js +1 -0
  50. package/dist/bundle/chunks/sync-INSWGFSB.js +21 -0
  51. package/dist/bundle/chunks/{typesafe-system-one-6ZFGVJMV.js → typesafe-system-one-7QFJ5JNW.js} +1 -1
  52. package/dist/bundle/chunks/usage-MG7QDPG2.js +1 -0
  53. package/dist/bundle/chunks/virtual-modules-73ZLFCNE.js +1 -0
  54. package/dist/bundle/cli-runtime.js +1 -1
  55. package/dist/bundle/index.js +1 -1
  56. package/dist/bundle/rpc-entry.js +1 -1
  57. package/dist/core/agent-session-runtime.d.ts +1 -0
  58. package/dist/core/agent-session-runtime.js +1 -1
  59. package/dist/core/headless-approver.d.ts +3 -0
  60. package/dist/core/headless-approver.js +1 -0
  61. package/dist/dal/manifest.js +1 -1
  62. package/dist/index.d.ts +2 -1
  63. package/dist/index.js +1 -1
  64. package/dist/main.js +3 -3
  65. package/dist/modes/acp/acp-mapping.js +3 -2
  66. package/dist/modes/acp/acp-mode.js +1 -1
  67. package/dist/modes/acp/acp-permissions.js +1 -0
  68. package/dist/modes/acp/acp-session-options.d.ts +24 -0
  69. package/dist/modes/acp/acp-session-options.js +3 -0
  70. package/dist/modes/index.d.ts +1 -0
  71. package/dist/modes/index.js +1 -1
  72. package/dist/node_modules/@dalcode/dal-advisor/package.json +3 -3
  73. package/dist/node_modules/@dalcode/dal-awake/package.json +2 -2
  74. package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
  75. package/dist/node_modules/@dalcode/dal-capabilities/package.json +4 -4
  76. package/dist/node_modules/@dalcode/dal-codeindex/package.json +2 -2
  77. package/dist/node_modules/@dalcode/dal-compat/package.json +2 -2
  78. package/dist/node_modules/@dalcode/dal-dap/package.json +2 -2
  79. package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
  80. package/dist/node_modules/@dalcode/dal-goal/package.json +3 -3
  81. package/dist/node_modules/@dalcode/dal-guard/package.json +4 -4
  82. package/dist/node_modules/@dalcode/dal-guard/src/index.js +4 -4
  83. package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
  84. package/dist/node_modules/@dalcode/dal-interactive/package.json +2 -2
  85. package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
  86. package/dist/node_modules/@dalcode/dal-learn/package.json +2 -2
  87. package/dist/node_modules/@dalcode/dal-learn/src/store.js +3 -3
  88. package/dist/node_modules/@dalcode/dal-lsp/package.json +4 -4
  89. package/dist/node_modules/@dalcode/dal-mcp/package.json +6 -6
  90. package/dist/node_modules/@dalcode/dal-mcp/src/config.js +1 -1
  91. package/dist/node_modules/@dalcode/dal-mcp/src/index.js +16 -16
  92. package/dist/node_modules/@dalcode/dal-mcp/src/types.d.ts +2 -0
  93. package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
  94. package/dist/node_modules/@dalcode/dal-pi-kit/dist/agent-dir.js +1 -0
  95. package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +2 -2
  96. package/dist/node_modules/@dalcode/dal-pi-kit/dist/index.js +1 -1
  97. package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
  98. package/dist/node_modules/@dalcode/dal-pi-kit/src/agent-dir.js +1 -0
  99. package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +2 -2
  100. package/dist/node_modules/@dalcode/dal-pi-kit/src/index.js +1 -1
  101. package/dist/node_modules/@dalcode/dal-plugins/package.json +4 -4
  102. package/dist/node_modules/@dalcode/dal-recall/package.json +2 -2
  103. package/dist/node_modules/@dalcode/dal-remote/package.json +2 -2
  104. package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
  105. package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
  106. package/dist/node_modules/@dalcode/dal-router/package.json +6 -6
  107. package/dist/node_modules/@dalcode/dal-rtk/package.json +2 -2
  108. package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
  109. package/dist/node_modules/@dalcode/dal-statusline/package.json +2 -2
  110. package/dist/node_modules/@dalcode/dal-structured/package.json +2 -2
  111. package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
  112. package/dist/node_modules/@dalcode/dal-sync/package.json +7 -5
  113. package/dist/node_modules/@dalcode/dal-sync/src/client.d.ts +2 -0
  114. package/dist/node_modules/@dalcode/dal-sync/src/client.js +1 -1
  115. package/dist/node_modules/@dalcode/dal-sync/src/host.d.ts +11 -1
  116. package/dist/node_modules/@dalcode/dal-sync/src/host.js +2 -2
  117. package/dist/node_modules/@dalcode/dal-sync/src/index.js +3 -3
  118. package/dist/node_modules/@dalcode/dal-sync/src/sessions.d.ts +153 -0
  119. package/dist/node_modules/@dalcode/dal-sync/src/sessions.js +15 -0
  120. package/dist/node_modules/@dalcode/dal-telemetry/package.json +4 -4
  121. package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
  122. package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
  123. package/dist/node_modules/@dalcode/dal-usage/package.json +2 -2
  124. package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
  125. package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
  126. package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
  127. package/dist/node_modules/@dalcode/deepailab/src/index.js +3 -3
  128. package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  129. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  130. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/azure.json +1 -1
  131. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
  132. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
  133. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
  134. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -1
  135. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
  136. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
  137. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.json +1 -1
  138. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
  139. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
  140. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  141. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  142. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan-cn.json +1 -1
  143. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/qwen-token-plan.json +1 -1
  144. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
  145. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/together.json +1 -1
  146. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  147. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai-coding-cn.json +1 -1
  148. package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
  149. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.d.ts +1 -1
  150. package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.js +1 -1
  151. package/dist/node_modules/@earendil-works/pi-ai/package.json +3 -3
  152. package/dist/node_modules/@earendil-works/pi-codemode/package.json +1 -1
  153. package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
  154. package/dist/node_modules/@earendil-works/pi-mcp/package.json +1 -1
  155. package/dist/node_modules/@earendil-works/pi-schema/package.json +1 -1
  156. package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  157. package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
  158. package/dist/sdk/sync.d.ts +8 -1
  159. package/dist/sdk/sync.js +1 -1
  160. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  161. package/examples/extensions/gondolin/package-lock.json +2 -2
  162. package/examples/extensions/gondolin/package.json +1 -1
  163. package/examples/extensions/with-deps/package-lock.json +2 -2
  164. package/examples/extensions/with-deps/package.json +1 -1
  165. package/npm-shrinkwrap.json +2 -2
  166. package/package.json +1 -1
  167. package/dist/bundle/chunks/chunk-3YGHTGYM.js +0 -7
  168. package/dist/bundle/chunks/chunk-D3HKK2ZD.js +0 -17
  169. package/dist/bundle/chunks/chunk-NMU45EFT.js +0 -9
  170. package/dist/bundle/chunks/chunk-SE42OS3U.js +0 -21
  171. package/dist/bundle/chunks/chunk-YDOF6JVP.js +0 -30
  172. package/dist/bundle/chunks/mcp-SGBPG7LV.js +0 -10
  173. package/dist/bundle/chunks/runtime-KB5ZUQB6.js +0 -1
  174. package/dist/bundle/chunks/sdk-C5BAFGNR.js +0 -1
  175. package/dist/bundle/chunks/sync-AQUDRXHM.js +0 -7
  176. package/dist/bundle/chunks/usage-CK3QZLTW.js +0 -1
  177. package/dist/bundle/chunks/virtual-modules-GRXCAWTO.js +0 -1
@@ -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-KSF7BFGS.js";import{sanitizeSurrogates as x}from"./chunk-L2ZPNLYD.js";import{truncateErrorText as z}from"./chunk-SMPERFJU.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-2XX4WZT6.js";import{AssistantMessageEventStream as G}from"./chunk-4LDEEFCY.js";import{getIdentityHeaders as X,getSystemMessageText as Y,renderSystemMessageUpdate as Q}from"./chunk-44EXLOHK.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-KP7CMLOT.js";import{sanitizeSurrogates as x}from"./chunk-L2ZPNLYD.js";import{truncateErrorText as z}from"./chunk-S7K3JBWA.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-PD6QS7YD.js";import{AssistantMessageEventStream as G}from"./chunk-4LDEEFCY.js";import{getIdentityHeaders as X,getSystemMessageText as Y,renderSystemMessageUpdate as Q}from"./chunk-GPI2GHBH.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};