dal-code 1.0.56 → 1.0.58
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/CHANGELOG.md +8 -0
- package/dist/bundle/chunks/{anthropic-messages-HHQLDDZH.js → anthropic-messages-FOIJU7LX.js} +1 -1
- package/dist/bundle/chunks/{azure-openai-responses-S7VKEJTH.js → azure-openai-responses-7NBJZKX5.js} +1 -1
- package/dist/bundle/chunks/bedrock-converse-stream.js +1 -1
- package/dist/bundle/chunks/{chunk-QCT6OHUR.js → chunk-3QG7FIE4.js} +1 -1
- package/dist/bundle/chunks/chunk-4BOWD7PQ.js +1 -0
- package/dist/bundle/chunks/{chunk-UULAEZ3H.js → chunk-4PBY6OYS.js} +1 -1
- package/dist/bundle/chunks/{chunk-BIY5HTFI.js → chunk-5MF5GEDD.js} +1 -1
- package/dist/bundle/chunks/{chunk-3XMZ5UC3.js → chunk-B7KZDIWA.js} +1 -1
- package/dist/bundle/chunks/chunk-C5ELI234.js +17 -0
- package/dist/bundle/chunks/{chunk-RX6CC5RH.js → chunk-CCU76UL3.js} +443 -472
- package/dist/bundle/chunks/{chunk-PH42AQ66.js → chunk-DVEPGKL5.js} +1 -1
- package/dist/bundle/chunks/chunk-G5AMLGXC.js +1 -0
- package/dist/bundle/chunks/chunk-HF334NQU.js +21 -0
- package/dist/bundle/chunks/{chunk-Z64M4Q7A.js → chunk-IONGABQF.js} +1 -1
- package/dist/bundle/chunks/{chunk-F37JXTCY.js → chunk-JK74OC6W.js} +1 -1
- package/dist/bundle/chunks/chunk-JUUJCOIR.js +7 -0
- package/dist/bundle/chunks/chunk-JXAFVEE4.js +17 -0
- package/dist/bundle/chunks/chunk-LMZYTWXD.js +14 -0
- package/dist/bundle/chunks/chunk-NJDCSLWK.js +1 -0
- package/dist/bundle/chunks/{chunk-BCFLC6CK.js → chunk-NYSVXLKF.js} +1 -1
- package/dist/bundle/chunks/{chunk-P4IBZA6D.js → chunk-PMFHJN7I.js} +1 -1
- package/dist/bundle/chunks/chunk-QFBU27TM.js +30 -0
- package/dist/bundle/chunks/{chunk-SZZVJTVX.js → chunk-QU2VEHMW.js} +1 -1
- package/dist/bundle/chunks/chunk-SCZEDPDC.js +9 -0
- package/dist/bundle/chunks/{chunk-VGMP27KM.js → chunk-T5PI6B5P.js} +1 -1
- package/dist/bundle/chunks/{chunk-ZR6PGIL7.js → chunk-X7I3V6OA.js} +1 -1
- package/dist/bundle/chunks/{chunk-3HGUIN22.js → chunk-XQF5XDEM.js} +2 -2
- package/dist/bundle/chunks/{cli-TVPE43YN.js → cli-NQ7B7BGV.js} +1 -1
- package/dist/bundle/chunks/{cli-NGGC23SK.js → cli-RY666QAD.js} +1 -1
- package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-RK2YCJXC.js → cloudflare-workers-ai-system-one-CFGOMWWZ.js} +1 -1
- package/dist/bundle/chunks/{execute-MGTKJB44.js → execute-NJRE4WBO.js} +2 -2
- package/dist/bundle/chunks/{google-generative-ai-ZPA4VBXP.js → google-generative-ai-ZA2RHPNE.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-IWHW2RX7.js → google-vertex-Y2GRWOK7.js} +1 -1
- package/dist/bundle/chunks/{llama-cpp-classify-FXJM52Q3.js → llama-cpp-classify-G2JDOFHY.js} +1 -1
- package/dist/bundle/chunks/{mcp-RLFUDVHN.js → mcp-45D7KCZZ.js} +1 -1
- package/dist/bundle/chunks/{mistral-conversations-JXVPTO5Y.js → mistral-conversations-MLV32BRV.js} +1 -1
- package/dist/bundle/chunks/{office-RTREQQ7W.js → office-UBOUFRAU.js} +1 -1
- package/dist/bundle/chunks/{openai-codex-responses-EYW27UUE.js → openai-codex-responses-BDK3PY6G.js} +1 -1
- package/dist/bundle/chunks/{openai-completions-ROBKXDOC.js → openai-completions-BLXHKAB3.js} +1 -1
- package/dist/bundle/chunks/{openai-decisions-4T5LPJRA.js → openai-decisions-IGVID576.js} +1 -1
- package/dist/bundle/chunks/{openai-responses-ZVFZ75QW.js → openai-responses-KHZOEDF2.js} +1 -1
- package/dist/bundle/chunks/{openrouter-images-6VJYTLAX.js → openrouter-images-SA6PUASF.js} +1 -1
- package/dist/bundle/chunks/{pi-messages-Y6HBOGKH.js → pi-messages-3VAOLQ2Y.js} +1 -1
- package/dist/bundle/chunks/{review-USSKCVWP.js → review-RZXLHPUZ.js} +2 -2
- package/dist/bundle/chunks/{router-4JLK3BTT.js → router-YBVXODIL.js} +1 -1
- package/dist/bundle/chunks/runtime-FNCZJKOC.js +1 -0
- package/dist/bundle/chunks/sdk-X6RX7FNE.js +1 -0
- package/dist/bundle/chunks/{sync-UCHKAOUU.js → sync-CRV6BXXC.js} +3 -3
- package/dist/bundle/chunks/{typesafe-system-one-XPDE7VYD.js → typesafe-system-one-ER3DLYNF.js} +1 -1
- package/dist/bundle/chunks/usage-LMRFS2HV.js +1 -0
- package/dist/bundle/chunks/virtual-modules-XIUNRFOZ.js +1 -0
- package/dist/bundle/cli-runtime.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/node_modules/@dalcode/dal-advisor/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-awake/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-bridge/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-capabilities/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-codeindex/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-compat/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-dap/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-gateway/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-goal/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-guard/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-halo/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-interactive/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-lang/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-learn/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-learn/src/engine.js +3 -3
- package/dist/node_modules/@dalcode/dal-learn/src/index.js +11 -11
- package/dist/node_modules/@dalcode/dal-learn/src/lessons.js +4 -4
- package/dist/node_modules/@dalcode/dal-learn/src/project-map.js +2 -2
- package/dist/node_modules/@dalcode/dal-learn/src/signals.js +6 -6
- package/dist/node_modules/@dalcode/dal-learn/src/store.js +3 -3
- package/dist/node_modules/@dalcode/dal-lsp/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-mcp/package.json +6 -6
- package/dist/node_modules/@dalcode/dal-office/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/agent-dir.js +1 -0
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/i18n.js +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/dist/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/package.json +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/agent-dir.js +1 -0
- package/dist/node_modules/@dalcode/dal-pi-kit/src/i18n.js +1 -1
- package/dist/node_modules/@dalcode/dal-pi-kit/src/index.js +1 -1
- package/dist/node_modules/@dalcode/dal-plugins/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-recall/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-remote/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-review/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-rewind/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-router/package.json +6 -6
- package/dist/node_modules/@dalcode/dal-rtk/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-skills/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-statusline/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-structured/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-subagent/package.json +5 -5
- package/dist/node_modules/@dalcode/dal-sync/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-telemetry/package.json +4 -4
- package/dist/node_modules/@dalcode/dal-terminal/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-tool-catalog/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-usage/package.json +2 -2
- package/dist/node_modules/@dalcode/dal-web/package.json +3 -3
- package/dist/node_modules/@dalcode/dal-workflow/package.json +2 -2
- package/dist/node_modules/@dalcode/deepailab/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.d.ts +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/dist/utils/version.js +1 -1
- package/dist/node_modules/@earendil-works/pi-ai/package.json +3 -3
- package/dist/node_modules/@earendil-works/pi-codemode/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-coding-agent/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-mcp/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-schema/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/dist/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/gondolin/package-lock.json +2 -2
- package/examples/extensions/gondolin/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/dist/bundle/chunks/chunk-3YGHTGYM.js +0 -7
- package/dist/bundle/chunks/chunk-MKMLENQD.js +0 -17
- package/dist/bundle/chunks/chunk-SE42OS3U.js +0 -21
- package/dist/bundle/chunks/chunk-T3TEURLR.js +0 -30
- package/dist/bundle/chunks/chunk-XTN2LDU3.js +0 -9
- package/dist/bundle/chunks/runtime-G7F6UQLA.js +0 -1
- package/dist/bundle/chunks/sdk-CEIRR6KD.js +0 -1
- package/dist/bundle/chunks/usage-3ACOJWR3.js +0 -1
- package/dist/bundle/chunks/virtual-modules-P4JE2EA6.js +0 -1
package/dist/bundle/chunks/{mistral-conversations-JXVPTO5Y.js → mistral-conversations-MLV32BRV.js}
RENAMED
|
@@ -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-
|
|
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-B7KZDIWA.js";import{sanitizeSurrogates as x}from"./chunk-L2ZPNLYD.js";import{truncateErrorText as z}from"./chunk-X7I3V6OA.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-5MF5GEDD.js";import{AssistantMessageEventStream as G}from"./chunk-4LDEEFCY.js";import{getIdentityHeaders as X,getSystemMessageText as Y,renderSystemMessageUpdate as Q}from"./chunk-JK74OC6W.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};
|