@fungi.computer/grove 0.2.2 → 0.4.0
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/dist/assets/Effect-Bibd7o64.js +76 -0
- package/dist/assets/{anthropic-messages-CR0lgZ06.js → anthropic-messages-BC32dQ9I.js} +3 -3
- package/dist/assets/anthropic-messages-BrTyy87S.js +19 -0
- package/dist/assets/{azure-openai-responses-CiHqTiGl.js → azure-openai-responses-CxbiKRMB.js} +1 -1
- package/dist/assets/azure-openai-responses-Cxq6500u.js +1 -0
- package/dist/assets/base-face-BEjKYyJe.js +1 -0
- package/dist/assets/burger-DCM1Ryjl.js +1 -0
- package/dist/assets/burger-Zw2lKYST.js +1 -0
- package/dist/assets/cat-D2ceQOG1.js +1 -0
- package/dist/assets/cat-Dg3HQp8e.js +1 -0
- package/dist/assets/{compat-CXSKceKx.js → compat-CNGE3olg.js} +2 -2
- package/dist/assets/compat-DgqxVOn_.js +2 -0
- package/dist/assets/document-CI1e8oXD.js +1 -0
- package/dist/assets/extension-hook-C8RQgls9.js +741 -0
- package/dist/assets/{extension-hook-CvLFlxpr.js → extension-hook-CBuX_bUG.js} +107 -107
- package/dist/assets/extensions-DEfvRHbZ.js +1 -0
- package/dist/assets/extensions-DYjwCmO5.js +1 -0
- package/dist/assets/{google-generative-ai-DoROu52Y.js → google-generative-ai-0DBJk_8o.js} +1 -1
- package/dist/assets/google-generative-ai-C-fVQ8eG.js +1 -0
- package/dist/assets/{google-shared-BnaBv9x_.js → google-shared-BL1Pe-wK.js} +1 -1
- package/dist/assets/google-shared-CRsSlHta.js +8 -0
- package/dist/assets/{google-vertex-BJP4zrLk.js → google-vertex-CPgYcjfH.js} +1 -1
- package/dist/assets/google-vertex-DFCQBu0N.js +1 -0
- package/dist/assets/index-26gTYfVj.js +171 -0
- package/dist/assets/index-DIRtUgKp.css +1 -0
- package/dist/assets/index-HgPChePI.js +171 -0
- package/dist/assets/{index-BmdZJzrt.css → index-u-fIUxtz.css} +1 -1
- package/dist/assets/{mistral-conversations-Bx-ch8Fk.js → mistral-conversations-C3vHwl30.js} +1 -1
- package/dist/assets/mistral-conversations-Dx6vubnB.js +4 -0
- package/dist/assets/mushroom-D2oxknl9.js +1 -0
- package/dist/assets/{mushroom-CEqJ08xM.js → mushroom-DcQ2lek6.js} +1 -1
- package/dist/assets/{node.browser-CAoro5uc.js → node.browser-C4Y5T0IC.js} +1 -1
- package/dist/assets/node.browser-DF9afU1k.js +1 -0
- package/dist/assets/{openai-codex-responses-DRHaefx8.js → openai-codex-responses-BJGSPctB.js} +1 -1
- package/dist/assets/openai-codex-responses-CK2Z6kMm.js +9 -0
- package/dist/assets/{openai-completions-BnHZlDfo.js → openai-completions-2akGjxPU.js} +1 -1
- package/dist/assets/openai-completions-C35dP-q-.js +5 -0
- package/dist/assets/{openai-responses-DYr89tDb.js → openai-responses-D6H3TRtV.js} +1 -1
- package/dist/assets/openai-responses-DPFd_3HO.js +1 -0
- package/dist/assets/{openai-responses-shared-CIO9CkHC.js → openai-responses-shared-DZesysou.js} +1 -1
- package/dist/assets/openai-responses-shared-DaKV5GAS.js +10 -0
- package/dist/assets/parakeet-conversation-DKtvvfd-.js +4 -0
- package/dist/assets/parakeet-conversation-Di3EPCdu.js +4 -0
- package/dist/assets/renderer-BHU7Ec4o.js +1 -0
- package/dist/assets/{renderer-BHkhGf2O.js → renderer-cVoUiOqk.js} +1 -1
- package/dist/assets/runtime-core-COw0PWwZ.js +1 -0
- package/dist/assets/runtime-core-DOL1texL.js +1 -0
- package/dist/assets/{transform-messages-iF4VkV1V.js → transform-messages-CgFTI6NF.js} +1 -1
- package/dist/assets/transform-messages-utWG7TCG.js +1 -0
- package/dist/index.html +6 -6
- package/package.json +12 -11
- package/dist/assets/burger-DnR6BnTW.js +0 -1
- package/dist/assets/cat-CcSpd8IN.js +0 -1
- package/dist/assets/extensions-p1H5H7ha.js +0 -1
- package/dist/assets/index-DhPnd7iW.js +0 -171
- package/dist/assets/parakeet-conversation-B7BtxtaN.js +0 -4
- package/dist/assets/runtime-core-CLqMVcjU.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as e,h as t,m as n,u as r}from"./preload-helper-DY31Aviq.js";import{a as i}from"./diagnostics-CxvqSC4Q.js";import{n as a,t as o}from"./models-BM_0GHMS.js";import{t as s}from"./headers-FK4rgixo.js";import{n as c,r as l}from"./json-parse-M7s0500m.js";import{f as u,h as d,i as f,m as p,n as m}from"./transform-messages-
|
|
1
|
+
import{a as e,h as t,m as n,u as r}from"./preload-helper-DY31Aviq.js";import{a as i}from"./diagnostics-CxvqSC4Q.js";import{n as a,t as o}from"./models-BM_0GHMS.js";import{t as s}from"./headers-FK4rgixo.js";import{n as c,r as l}from"./json-parse-M7s0500m.js";import{f as u,h as d,i as f,m as p,n as m}from"./transform-messages-utWG7TCG.js";import{t as h}from"./sanitize-unicode-DmIE6hZJ.js";import{t as g}from"./hash-yQufAZII.js";import{t as _}from"./abort-signals-joV34wzR.js";var v=9,y=4e3,b=(e,t,n)=>{let a=new i,o=r(t,e.compat?.supportsMidConvoSystemMessages);return(async()=>{let t=S(e);try{let r=n?.apiKey;if(!r)throw Error(`No API key for provider: ${e.provider}`);let i=C(),s=m(o.messages,e,e=>i(e)),c=H(e,o,s,n),l=await n?.onPayload?.(c,e);l!==void 0&&(c=l);let u=await O(e,c,r,n);if(a.push({type:`start`,partial:t}),await G(e,t,a,u,n?.onProviderStreamEvent),n?.signal?.aborted)throw Error(`Request was aborted`);if(t.stopReason===`pending`)throw Error(`Mistral stream ended without a finish reason`);if(t.stopReason===`aborted`||t.stopReason===`error`)throw Error(t.errorMessage||`An unknown error occurred`);a.push({type:`done`,reason:t.stopReason,message:t}),a.end()}catch(e){for(let e of t.content)delete e.partialArgs;t.stopReason=n?.signal?.aborted?`aborted`:`error`,t.errorMessage=T(e),a.push({type:`error`,reason:t.stopReason,error:t}),a.end()}})(),a},x=(e,t,n)=>{let r=n?.apiKey;if(!r)throw Error(`No API key for provider: ${e.provider}`);let i={...f(e,t,n,r),toolChoice:n?.toolChoice},o=n?.reasoning?a(e,n.reasoning):void 0,s=o===`off`?void 0:o,c=e.reasoning?e.thinkingLevelMap:void 0,l=c?s?c[s]??`high`:c.off??void 0:void 0;return b(e,t,{...i,promptMode:e.reasoning&&!c&&s?`reasoning`:void 0,reasoningEffort:l})};function S(e){return{role:`assistant`,content:[],api:e.api,provider:e.provider,model:e.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()}}function C(){let e=new Map,t=new Map;return n=>{let r=e.get(n);if(r)return r;let i=0;for(;;){let r=w(n,i),a=t.get(r);if(!a||a===n)return e.set(n,r),t.set(r,n),r;i++}}}function w(e,t){let n=e.replace(/[^a-zA-Z0-9]/g,``);if(t===0&&n.length===v)return n;let r=n||e,i=t===0?r:`${r}:${t}`;return g(i).replace(/[^a-zA-Z0-9]/g,``).slice(0,v)}function T(e){if(e instanceof Error){let t=e,n=typeof t.statusCode==`number`?t.statusCode:void 0,r=typeof t.body==`string`?t.body.trim():void 0;return n!==void 0&&r?`Mistral API error (${n}): ${E(r,y)}`:n===void 0?e.message:`Mistral API error (${n}): ${e.message}`}return D(e)}function E(e,t){return e.length<=t?e:`${e.slice(0,t)}... [truncated ${e.length-t} chars]`}function D(e){try{let t=JSON.stringify(e);return t===void 0?String(e):t}catch{return String(e)}}async function O(e,t,n,r){let i=new URL(e.baseUrl);i.pathname=`${i.pathname.replace(/\/+$/u,``)}/`;let a=new URL(`v1/chat/completions`,i),o=A(e,n,r),c=r?.timeoutMs??6e4,l=AbortSignal.timeout(c),u=_([r?.signal,l]),d;try{d=await(r?.fetch??globalThis.fetch)(a,{method:`POST`,headers:o,body:JSON.stringify(N(t)),signal:u.signal})}catch(e){throw l.aborted&&!r?.signal?.aborted?Error(`Mistral response headers timed out after ${c}ms`):e}finally{u.cleanup()}if(await r?.onResponse?.({status:d.status,headers:s(d.headers)},e),!d.ok){let e=await d.text();throw new k(d.status,e,d.statusText)}if(!d.body)throw Error(`Mistral response has no body`);return z(d.body,r?.signal)}var k=class extends Error{statusCode;body;constructor(e,t,n){super(n||`Request failed with status ${e}`),this.name=`MistralHttpError`,this.statusCode=e,this.body=t}};function A(e,t,n){let r=new Headers({"User-Agent":d(),accept:`text/event-stream`,authorization:`Bearer ${t}`,"content-type":`application/json`});j(r,e.headers),j(r,n?.headers);let i=M(e.headers,`x-affinity`)||M(n?.headers,`x-affinity`);return U(n)&&!i&&r.set(`x-affinity`,n.sessionId),r}function j(e,t){if(t)for(let[n,r]of Object.entries(t))r===null?e.delete(n):e.set(n,r)}function M(e,t){return!!e&&Object.keys(e).some(e=>e.toLowerCase()===t)}function N(e){let t={...e};for(let[e,n]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`]])I(t,e,n);t.messages=e.messages.map(e=>P(e));let n=t.response_format;if(L(n)){let e={...n};I(e,`jsonSchema`,`json_schema`);let r=e.json_schema;if(L(r)){let t={...r};I(t,`schemaDefinition`,`schema`),e.json_schema=t}t.response_format=e}return t}function P(e){let t={...e};return I(t,`toolCalls`,`tool_calls`),I(t,`toolCallId`,`tool_call_id`),Array.isArray(e.content)&&(t.content=e.content.map(e=>F(e))),t}function F(e){let t={...e};for(let[e,n]of[[`imageUrl`,`image_url`],[`documentUrl`,`document_url`],[`documentName`,`document_name`],[`fileId`,`file_id`],[`referenceIds`,`reference_ids`],[`inputAudio`,`input_audio`]])I(t,e,n);return t}function I(e,t,n){t in e&&(e[n]=e[t],delete e[t])}function L(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var R=Symbol(`mistral-stream-done`);async function*z(e,t){let n=e.getReader(),r=new TextDecoder,i=``,a=()=>{n.cancel().catch(()=>{})};t?.addEventListener(`abort`,a,{once:!0});try{for(;;){if(t?.aborted)throw t.reason;let{done:e,value:a}=await n.read();if(t?.aborted)throw t.reason;i+=e?r.decode():r.decode(a,{stream:!0});let o=B(i);for(;o;){let e=V(i.slice(0,o.index));if(i=i.slice(o.index+o.length),e===R)return;e&&(yield e),o=B(i)}if(e)break}if(i.trim()){let e=V(i);e!==R&&e&&(yield e)}}finally{t?.removeEventListener(`abort`,a);try{await n.cancel()}catch{}try{n.releaseLock()}catch{}}}function B(e){let t=/\r\n\r\n|\r\n\r|\r\n\n|\r\r\n|\n\r\n|\r\r|\n\r|\n\n/u.exec(e);return t?.index===void 0?void 0:{index:t.index,length:t[0].length}}function V(e){let t=e.split(/\r\n|\r|\n/u).filter(e=>e.startsWith(`data:`)).map(e=>e.slice(5).trimStart()).join(`
|
|
2
2
|
`).trim();if(!t)return;if(t===`[DONE]`)return R;let n=JSON.parse(t);if(!L(n)||!Array.isArray(n.choices))throw Error(`Invalid Mistral streaming event`);return{data:n}}function H(t,n,r,i){let a={model:t.id,stream:!0,messages:J(r,t.input.includes(`image`))},o=e(n.messages);return o.length>0&&(a.tools=K(o)),i?.temperature!==void 0&&(a.temperature=i.temperature),i?.maxTokens!==void 0&&(a.maxTokens=i.maxTokens),i?.toolChoice&&(a.toolChoice=X(i.toolChoice)),i?.promptMode&&(a.promptMode=i.promptMode),i?.reasoningEffort&&(a.reasoningEffort=i.reasoningEffort),U(i)&&(a.promptCacheKey=i.sessionId),a}function U(e){return e?.cacheRetention!==`none`&&!!e?.sessionId}function W(e,t){let n=e,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;return Math.min(t,Math.max(0,typeof r==`number`&&Number.isFinite(r)?r:0))}async function G(e,t,n,r,i){let a=null,s=t.content,u=()=>s.length-1,d=new Map,f=e=>{if(e){if(e.type===`text`){n.push({type:`text_end`,contentIndex:u(),content:e.text,partial:t});return}e.type===`thinking`&&n.push({type:`thinking_end`,contentIndex:u(),content:e.thinking,partial:t})}};for await(let s of r){let r=s.data;if(await i?.(r,e),t.responseId||=r.id,r.usage){let n=r.usage.prompt_tokens||0,i=W(r.usage,n);t.usage.input=Math.max(0,n-i),t.usage.output=r.usage.completion_tokens||0,t.usage.cacheRead=i,t.usage.cacheWrite=0,t.usage.totalTokens=r.usage.total_tokens||t.usage.input+t.usage.output+t.usage.cacheRead+t.usage.cacheWrite,o(e,t.usage)}let l=r.choices[0];if(!l)continue;if(l.finish_reason){t.rawStopReason=l.finish_reason;let e=Z(l.finish_reason);t.stopReason=e.stopReason,e.errorMessage&&(t.errorMessage=e.errorMessage)}let p=l.delta;if(p.content!==null&&p.content!==void 0){let e=typeof p.content==`string`?[p.content]:p.content;for(let r of e){if(typeof r==`string`){let e=h(r);if(!e)continue;(!a||a.type!==`text`)&&(f(a),a={type:`text`,text:``},t.content.push(a),n.push({type:`text_start`,contentIndex:u(),partial:t})),a.text+=e,n.push({type:`text_delta`,contentIndex:u(),delta:e,partial:t});continue}if(r.type===`thinking`){let e=(r.thinking??[]).map(e=>e.text??``).filter(e=>e.length>0).join(``),i=h(e);if(!i)continue;(!a||a.type!==`thinking`)&&(f(a),a={type:`thinking`,thinking:``},t.content.push(a),n.push({type:`thinking_start`,contentIndex:u(),partial:t})),a.thinking+=i,n.push({type:`thinking_delta`,contentIndex:u(),delta:i,partial:t});continue}if(r.type===`text`){let e=h(r.text??``);if(!e)continue;(!a||a.type!==`text`)&&(f(a),a={type:`text`,text:``},t.content.push(a),n.push({type:`text_start`,contentIndex:u(),partial:t})),a.text+=e,n.push({type:`text_delta`,contentIndex:u(),delta:e,partial:t})}}}let m=p.tool_calls||[];for(let e of m){a&&=(f(a),null);let r=e.id&&e.id!==`null`?e.id:w(`toolcall:${e.index??0}`,0),i=e.index??r,o=d.get(i),s;if(o!==void 0){let e=t.content[o];e?.type===`toolCall`&&(s=e)}s||(s={type:`toolCall`,id:r,name:e.function.name,arguments:{},partialArgs:``},t.content.push(s),d.set(i,t.content.length-1),n.push({type:`toolcall_start`,contentIndex:t.content.length-1,partial:t}));let l=typeof e.function.arguments==`string`?e.function.arguments:JSON.stringify(e.function.arguments||{});s.partialArgs=(s.partialArgs||``)+l,s.arguments=c(s.partialArgs),n.push({type:`toolcall_delta`,contentIndex:d.get(i),delta:l,partial:t})}}f(a);for(let e of d.values()){let r=t.content[e];if(r.type!==`toolCall`)continue;let i=r;Object.assign(i,l(i.partialArgs)),delete i.partialArgs,n.push({type:`toolcall_end`,contentIndex:e,toolCall:i,partial:t})}}function K(e){return e.map(e=>{let t=p(e,!0);return{type:`function`,function:{name:e.name,description:e.description,parameters:q(u(e,t)),strict:t??!1}}})}function q(e){if(Array.isArray(e))return e.map(e=>q(e));if(e&&typeof e==`object`){let t={};for(let[n,r]of Object.entries(e))t[n]=q(r);return t}return e}function J(e,r){let i=[];for(let[a,o]of e.entries()){if(o.role===`system`){let e=a===0?n(o):t(o);e.length>0&&i.push({role:`system`,content:h(e)});continue}if(o.role===`user`){if(typeof o.content==`string`){i.push({role:`user`,content:h(o.content)});continue}let e=o.content.some(e=>e.type===`image`),t=o.content.filter(e=>e.type===`text`||r).map(e=>e.type===`text`?{type:`text`,text:h(e.text)}:{type:`image_url`,imageUrl:`data:${e.mimeType};base64,${e.data}`});if(t.length>0){i.push({role:`user`,content:t});continue}e&&!r&&i.push({role:`user`,content:`(image omitted: model does not support images)`});continue}if(o.role===`assistant`){let e=[],t=[];for(let n of o.content){if(n.type===`text`){n.text.trim().length>0&&e.push({type:`text`,text:h(n.text)});continue}if(n.type===`thinking`){n.thinking.trim().length>0&&e.push({type:`thinking`,thinking:[{type:`text`,text:h(n.thinking)}]});continue}t.push({id:n.id,type:`function`,function:{name:n.name,arguments:JSON.stringify(n.arguments||{})},index:0})}let n={role:`assistant`,prefix:!1};e.length>0&&(n.content=e),t.length>0&&(n.toolCalls=t),(e.length>0||t.length>0)&&i.push(n);continue}let e=[],s=Y(o.content.filter(e=>e.type===`text`).map(e=>e.type===`text`?h(e.text):``).join(`
|
|
3
3
|
`),o.content.some(e=>e.type===`image`),r,o.isError);e.push({type:`text`,text:s});for(let t of o.content)r&&t.type===`image`&&e.push({type:`image_url`,imageUrl:`data:${t.mimeType};base64,${t.data}`});i.push({role:`tool`,toolCallId:o.toolCallId,name:o.toolName,content:e})}return i}function Y(e,t,n,r){let i=e.trim(),a=r?`[tool error] `:``;return i.length>0?`${a}${i}${t&&!n?`
|
|
4
4
|
[tool image omitted: model does not support images]`:``}`:t?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)`}function X(e){if(e)return e===`auto`||e===`none`||e===`any`||e===`required`?e:{type:`function`,function:{name:e.function.name}}}function Z(e){if(e===null)return{stopReason:`stop`};switch(e){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: ${e}`}}}export{b as stream,x as streamSimple};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{a as e,h as t,m as n,u as r}from"./preload-helper-DY31Aviq.js";import{a as i}from"./diagnostics-CxvqSC4Q.js";import{n as a,t as o}from"./models-BM_0GHMS.js";import{t as s}from"./headers-FK4rgixo.js";import{n as c,r as l}from"./json-parse-M7s0500m.js";import{f as u,h as d,i as f,m as p,n as m}from"./transform-messages-CgFTI6NF.js";import{t as h}from"./sanitize-unicode-DmIE6hZJ.js";import{t as g}from"./hash-yQufAZII.js";import{t as _}from"./abort-signals-joV34wzR.js";var v=9,y=4e3,b=(e,t,n)=>{let a=new i,o=r(t,e.compat?.supportsMidConvoSystemMessages);return(async()=>{let t=S(e);try{let r=n?.apiKey;if(!r)throw Error(`No API key for provider: ${e.provider}`);let i=C(),s=m(o.messages,e,e=>i(e)),c=H(e,o,s,n),l=await n?.onPayload?.(c,e);l!==void 0&&(c=l);let u=await O(e,c,r,n);if(a.push({type:`start`,partial:t}),await G(e,t,a,u,n?.onProviderStreamEvent),n?.signal?.aborted)throw Error(`Request was aborted`);if(t.stopReason===`pending`)throw Error(`Mistral stream ended without a finish reason`);if(t.stopReason===`aborted`||t.stopReason===`error`)throw Error(t.errorMessage||`An unknown error occurred`);a.push({type:`done`,reason:t.stopReason,message:t}),a.end()}catch(e){for(let e of t.content)delete e.partialArgs;t.stopReason=n?.signal?.aborted?`aborted`:`error`,t.errorMessage=T(e),a.push({type:`error`,reason:t.stopReason,error:t}),a.end()}})(),a},x=(e,t,n)=>{let r=n?.apiKey;if(!r)throw Error(`No API key for provider: ${e.provider}`);let i={...f(e,t,n,r),toolChoice:n?.toolChoice},o=n?.reasoning?a(e,n.reasoning):void 0,s=o===`off`?void 0:o,c=e.reasoning?e.thinkingLevelMap:void 0,l=c?s?c[s]??`high`:c.off??void 0:void 0;return b(e,t,{...i,promptMode:e.reasoning&&!c&&s?`reasoning`:void 0,reasoningEffort:l})};function S(e){return{role:`assistant`,content:[],api:e.api,provider:e.provider,model:e.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()}}function C(){let e=new Map,t=new Map;return n=>{let r=e.get(n);if(r)return r;let i=0;for(;;){let r=w(n,i),a=t.get(r);if(!a||a===n)return e.set(n,r),t.set(r,n),r;i++}}}function w(e,t){let n=e.replace(/[^a-zA-Z0-9]/g,``);if(t===0&&n.length===v)return n;let r=n||e,i=t===0?r:`${r}:${t}`;return g(i).replace(/[^a-zA-Z0-9]/g,``).slice(0,v)}function T(e){if(e instanceof Error){let t=e,n=typeof t.statusCode==`number`?t.statusCode:void 0,r=typeof t.body==`string`?t.body.trim():void 0;return n!==void 0&&r?`Mistral API error (${n}): ${E(r,y)}`:n===void 0?e.message:`Mistral API error (${n}): ${e.message}`}return D(e)}function E(e,t){return e.length<=t?e:`${e.slice(0,t)}... [truncated ${e.length-t} chars]`}function D(e){try{let t=JSON.stringify(e);return t===void 0?String(e):t}catch{return String(e)}}async function O(e,t,n,r){let i=new URL(e.baseUrl);i.pathname=`${i.pathname.replace(/\/+$/u,``)}/`;let a=new URL(`v1/chat/completions`,i),o=A(e,n,r),c=r?.timeoutMs??6e4,l=AbortSignal.timeout(c),u=_([r?.signal,l]),d;try{d=await(r?.fetch??globalThis.fetch)(a,{method:`POST`,headers:o,body:JSON.stringify(N(t)),signal:u.signal})}catch(e){throw l.aborted&&!r?.signal?.aborted?Error(`Mistral response headers timed out after ${c}ms`):e}finally{u.cleanup()}if(await r?.onResponse?.({status:d.status,headers:s(d.headers)},e),!d.ok){let e=await d.text();throw new k(d.status,e,d.statusText)}if(!d.body)throw Error(`Mistral response has no body`);return z(d.body,r?.signal)}var k=class extends Error{statusCode;body;constructor(e,t,n){super(n||`Request failed with status ${e}`),this.name=`MistralHttpError`,this.statusCode=e,this.body=t}};function A(e,t,n){let r=new Headers({"User-Agent":d(),accept:`text/event-stream`,authorization:`Bearer ${t}`,"content-type":`application/json`});j(r,e.headers),j(r,n?.headers);let i=M(e.headers,`x-affinity`)||M(n?.headers,`x-affinity`);return U(n)&&!i&&r.set(`x-affinity`,n.sessionId),r}function j(e,t){if(t)for(let[n,r]of Object.entries(t))r===null?e.delete(n):e.set(n,r)}function M(e,t){return!!e&&Object.keys(e).some(e=>e.toLowerCase()===t)}function N(e){let t={...e};for(let[e,n]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`]])I(t,e,n);t.messages=e.messages.map(e=>P(e));let n=t.response_format;if(L(n)){let e={...n};I(e,`jsonSchema`,`json_schema`);let r=e.json_schema;if(L(r)){let t={...r};I(t,`schemaDefinition`,`schema`),e.json_schema=t}t.response_format=e}return t}function P(e){let t={...e};return I(t,`toolCalls`,`tool_calls`),I(t,`toolCallId`,`tool_call_id`),Array.isArray(e.content)&&(t.content=e.content.map(e=>F(e))),t}function F(e){let t={...e};for(let[e,n]of[[`imageUrl`,`image_url`],[`documentUrl`,`document_url`],[`documentName`,`document_name`],[`fileId`,`file_id`],[`referenceIds`,`reference_ids`],[`inputAudio`,`input_audio`]])I(t,e,n);return t}function I(e,t,n){t in e&&(e[n]=e[t],delete e[t])}function L(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var R=Symbol(`mistral-stream-done`);async function*z(e,t){let n=e.getReader(),r=new TextDecoder,i=``,a=()=>{n.cancel().catch(()=>{})};t?.addEventListener(`abort`,a,{once:!0});try{for(;;){if(t?.aborted)throw t.reason;let{done:e,value:a}=await n.read();if(t?.aborted)throw t.reason;i+=e?r.decode():r.decode(a,{stream:!0});let o=B(i);for(;o;){let e=V(i.slice(0,o.index));if(i=i.slice(o.index+o.length),e===R)return;e&&(yield e),o=B(i)}if(e)break}if(i.trim()){let e=V(i);e!==R&&e&&(yield e)}}finally{t?.removeEventListener(`abort`,a);try{await n.cancel()}catch{}try{n.releaseLock()}catch{}}}function B(e){let t=/\r\n\r\n|\r\n\r|\r\n\n|\r\r\n|\n\r\n|\r\r|\n\r|\n\n/u.exec(e);return t?.index===void 0?void 0:{index:t.index,length:t[0].length}}function V(e){let t=e.split(/\r\n|\r|\n/u).filter(e=>e.startsWith(`data:`)).map(e=>e.slice(5).trimStart()).join(`
|
|
2
|
+
`).trim();if(!t)return;if(t===`[DONE]`)return R;let n=JSON.parse(t);if(!L(n)||!Array.isArray(n.choices))throw Error(`Invalid Mistral streaming event`);return{data:n}}function H(t,n,r,i){let a={model:t.id,stream:!0,messages:J(r,t.input.includes(`image`))},o=e(n.messages);return o.length>0&&(a.tools=K(o)),i?.temperature!==void 0&&(a.temperature=i.temperature),i?.maxTokens!==void 0&&(a.maxTokens=i.maxTokens),i?.toolChoice&&(a.toolChoice=X(i.toolChoice)),i?.promptMode&&(a.promptMode=i.promptMode),i?.reasoningEffort&&(a.reasoningEffort=i.reasoningEffort),U(i)&&(a.promptCacheKey=i.sessionId),a}function U(e){return e?.cacheRetention!==`none`&&!!e?.sessionId}function W(e,t){let n=e,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;return Math.min(t,Math.max(0,typeof r==`number`&&Number.isFinite(r)?r:0))}async function G(e,t,n,r,i){let a=null,s=t.content,u=()=>s.length-1,d=new Map,f=e=>{if(e){if(e.type===`text`){n.push({type:`text_end`,contentIndex:u(),content:e.text,partial:t});return}e.type===`thinking`&&n.push({type:`thinking_end`,contentIndex:u(),content:e.thinking,partial:t})}};for await(let s of r){let r=s.data;if(await i?.(r,e),t.responseId||=r.id,r.usage){let n=r.usage.prompt_tokens||0,i=W(r.usage,n);t.usage.input=Math.max(0,n-i),t.usage.output=r.usage.completion_tokens||0,t.usage.cacheRead=i,t.usage.cacheWrite=0,t.usage.totalTokens=r.usage.total_tokens||t.usage.input+t.usage.output+t.usage.cacheRead+t.usage.cacheWrite,o(e,t.usage)}let l=r.choices[0];if(!l)continue;if(l.finish_reason){t.rawStopReason=l.finish_reason;let e=Z(l.finish_reason);t.stopReason=e.stopReason,e.errorMessage&&(t.errorMessage=e.errorMessage)}let p=l.delta;if(p.content!==null&&p.content!==void 0){let e=typeof p.content==`string`?[p.content]:p.content;for(let r of e){if(typeof r==`string`){let e=h(r);if(!e)continue;(!a||a.type!==`text`)&&(f(a),a={type:`text`,text:``},t.content.push(a),n.push({type:`text_start`,contentIndex:u(),partial:t})),a.text+=e,n.push({type:`text_delta`,contentIndex:u(),delta:e,partial:t});continue}if(r.type===`thinking`){let e=(r.thinking??[]).map(e=>e.text??``).filter(e=>e.length>0).join(``),i=h(e);if(!i)continue;(!a||a.type!==`thinking`)&&(f(a),a={type:`thinking`,thinking:``},t.content.push(a),n.push({type:`thinking_start`,contentIndex:u(),partial:t})),a.thinking+=i,n.push({type:`thinking_delta`,contentIndex:u(),delta:i,partial:t});continue}if(r.type===`text`){let e=h(r.text??``);if(!e)continue;(!a||a.type!==`text`)&&(f(a),a={type:`text`,text:``},t.content.push(a),n.push({type:`text_start`,contentIndex:u(),partial:t})),a.text+=e,n.push({type:`text_delta`,contentIndex:u(),delta:e,partial:t})}}}let m=p.tool_calls||[];for(let e of m){a&&=(f(a),null);let r=e.id&&e.id!==`null`?e.id:w(`toolcall:${e.index??0}`,0),i=e.index??r,o=d.get(i),s;if(o!==void 0){let e=t.content[o];e?.type===`toolCall`&&(s=e)}s||(s={type:`toolCall`,id:r,name:e.function.name,arguments:{},partialArgs:``},t.content.push(s),d.set(i,t.content.length-1),n.push({type:`toolcall_start`,contentIndex:t.content.length-1,partial:t}));let l=typeof e.function.arguments==`string`?e.function.arguments:JSON.stringify(e.function.arguments||{});s.partialArgs=(s.partialArgs||``)+l,s.arguments=c(s.partialArgs),n.push({type:`toolcall_delta`,contentIndex:d.get(i),delta:l,partial:t})}}f(a);for(let e of d.values()){let r=t.content[e];if(r.type!==`toolCall`)continue;let i=r;Object.assign(i,l(i.partialArgs)),delete i.partialArgs,n.push({type:`toolcall_end`,contentIndex:e,toolCall:i,partial:t})}}function K(e){return e.map(e=>{let t=p(e,!0);return{type:`function`,function:{name:e.name,description:e.description,parameters:q(u(e,t)),strict:t??!1}}})}function q(e){if(Array.isArray(e))return e.map(e=>q(e));if(e&&typeof e==`object`){let t={};for(let[n,r]of Object.entries(e))t[n]=q(r);return t}return e}function J(e,r){let i=[];for(let[a,o]of e.entries()){if(o.role===`system`){let e=a===0?n(o):t(o);e.length>0&&i.push({role:`system`,content:h(e)});continue}if(o.role===`user`){if(typeof o.content==`string`){i.push({role:`user`,content:h(o.content)});continue}let e=o.content.some(e=>e.type===`image`),t=o.content.filter(e=>e.type===`text`||r).map(e=>e.type===`text`?{type:`text`,text:h(e.text)}:{type:`image_url`,imageUrl:`data:${e.mimeType};base64,${e.data}`});if(t.length>0){i.push({role:`user`,content:t});continue}e&&!r&&i.push({role:`user`,content:`(image omitted: model does not support images)`});continue}if(o.role===`assistant`){let e=[],t=[];for(let n of o.content){if(n.type===`text`){n.text.trim().length>0&&e.push({type:`text`,text:h(n.text)});continue}if(n.type===`thinking`){n.thinking.trim().length>0&&e.push({type:`thinking`,thinking:[{type:`text`,text:h(n.thinking)}]});continue}t.push({id:n.id,type:`function`,function:{name:n.name,arguments:JSON.stringify(n.arguments||{})},index:0})}let n={role:`assistant`,prefix:!1};e.length>0&&(n.content=e),t.length>0&&(n.toolCalls=t),(e.length>0||t.length>0)&&i.push(n);continue}let e=[],s=Y(o.content.filter(e=>e.type===`text`).map(e=>e.type===`text`?h(e.text):``).join(`
|
|
3
|
+
`),o.content.some(e=>e.type===`image`),r,o.isError);e.push({type:`text`,text:s});for(let t of o.content)r&&t.type===`image`&&e.push({type:`image_url`,imageUrl:`data:${t.mimeType};base64,${t.data}`});i.push({role:`tool`,toolCallId:o.toolCallId,name:o.toolName,content:e})}return i}function Y(e,t,n,r){let i=e.trim(),a=r?`[tool error] `:``;return i.length>0?`${a}${i}${t&&!n?`
|
|
4
|
+
[tool image omitted: model does not support images]`:``}`:t?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)`}function X(e){if(e)return e===`auto`||e===`none`||e===`any`||e===`required`?e:{type:`function`,function:{name:e.function.name}}}function Z(e){if(e===null)return{stopReason:`stop`};switch(e){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: ${e}`}}}export{b as stream,x as streamSimple};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e}from"./document-CI1e8oXD.js";import{t}from"./renderer-BHU7Ec4o.js";var n={version:1,name:`mushroom`,renderer:`zdog`,controls:{body:{type:`color`,label:`body`,default:`#fff7e4`},cap:{type:`color`,label:`cap`,default:`#f98284`},capSpot:{type:`color`,label:`capSpot`,default:`#ffe6c6`},eye:{type:`color`,label:`eye`,default:`#28282e`},mouth:{type:`color`,label:`mouth`,default:`#28282e`},dead:{type:`color`,label:`dead`,default:`#6c5671`},deadTongue:{type:`color`,label:`deadTongue`,default:`#d9c8bf`},tongue:{type:`color`,label:`tongue`,default:`#f98284`},sweat:{type:`color`,label:`sweat`,default:`#accce4`},white:{type:`color`,label:`white`,default:`#ffffff`}},data:JSON.parse(`{"root":"node-0","nodes":[{"id":"node-0","kind":"group","options":{"name":"root"}},{"id":"node-1","parent":"node-0","kind":"group","options":{"name":"body","updateSort":true}},{"id":"node-2","parent":"node-1","kind":"hemisphere","options":{"name":"body.hemisphere","translate":{"y":2},"rotate":{"x":4.71238898038469},"color":"\\u0000sprite-color:body","stroke":false,"backface":"\\u0000sprite-color:cap","diameter":32}},{"id":"node-3","parent":"node-1","kind":"hemisphere","options":{"name":"cap.hemisphere","translate":{"y":2},"rotate":{"x":1.5707963267948966},"color":"\\u0000sprite-color:cap","stroke":false,"backface":"\\u0000sprite-color:capSpot","diameter":42}},{"id":"node-4","parent":"node-3","kind":"shape","options":{"name":"cap.spot.front","translate":{"x":-8,"y":8,"z":12},"color":"\\u0000sprite-color:capSpot","stroke":12,"path":[{"x":0,"y":0}]}},{"id":"node-5","parent":"node-3","kind":"shape","options":{"name":"cap.spot.top","translate":{"x":8,"y":-4,"z":13},"color":"\\u0000sprite-color:capSpot","stroke":18,"path":[{"x":0,"y":0}]}},{"id":"node-6","parent":"node-1","kind":"group","options":{"name":"face","translate":{"y":7,"z":8}}},{"id":"node-7","parent":"node-6","kind":"group","options":{"name":"eyes"}},{"id":"node-8","parent":"node-7","kind":"group","options":{"name":"eyes.normal"}},{"id":"node-9","parent":"node-8","kind":"group","options":{"translate":{"x":-6,"y":-2}}},{"id":"node-10","parent":"node-9","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-11","parent":"node-9","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-12","parent":"node-8","kind":"group","options":{"translate":{"x":6,"y":-2}}},{"id":"node-13","parent":"node-12","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-14","parent":"node-12","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-15","parent":"node-7","kind":"group","options":{"name":"eyes.sad"}},{"id":"node-16","parent":"node-15","kind":"group","options":{"translate":{"x":-6,"y":-1},"rotate":{"z":0.2}}},{"id":"node-17","parent":"node-16","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":4}},{"id":"node-18","parent":"node-16","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-19","parent":"node-15","kind":"group","options":{"translate":{"x":6,"y":-1},"rotate":{"z":-0.2}}},{"id":"node-20","parent":"node-19","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":4}},{"id":"node-21","parent":"node-19","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-22","parent":"node-7","kind":"group","options":{"name":"eyes.surprised"}},{"id":"node-23","parent":"node-22","kind":"group","options":{"translate":{"x":-6,"y":-2}}},{"id":"node-24","parent":"node-23","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":4,"height":5}},{"id":"node-25","parent":"node-23","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-26","parent":"node-22","kind":"group","options":{"translate":{"x":6,"y":-2}}},{"id":"node-27","parent":"node-26","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":4,"height":5}},{"id":"node-28","parent":"node-26","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-29","parent":"node-7","kind":"group","options":{"name":"eyes.happy"}},{"id":"node-30","parent":"node-29","kind":"shape","options":{"translate":{"x":-6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":-1,"y":-1.5},{"x":1,"y":-1.5},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-31","parent":"node-29","kind":"shape","options":{"translate":{"x":6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":-1,"y":-1.5},{"x":1,"y":-1.5},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-32","parent":"node-7","kind":"group","options":{"name":"eyes.angry"}},{"id":"node-33","parent":"node-32","kind":"group","options":{"translate":{"x":-6,"y":-1},"rotate":{"z":-0.3}}},{"id":"node-34","parent":"node-33","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":4}},{"id":"node-35","parent":"node-33","kind":"shape","options":{"translate":{"y":-1},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-3,"y":-3},{"x":3,"y":-2}]}},{"id":"node-36","parent":"node-32","kind":"group","options":{"translate":{"x":6,"y":-1},"rotate":{"z":0.3}}},{"id":"node-37","parent":"node-36","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":4}},{"id":"node-38","parent":"node-36","kind":"shape","options":{"translate":{"y":-1},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-3,"y":-3},{"x":3,"y":-2}]}},{"id":"node-39","parent":"node-7","kind":"group","options":{"name":"eyes.dead"}},{"id":"node-40","parent":"node-39","kind":"group","options":{"translate":{"x":-6,"y":-2}}},{"id":"node-41","parent":"node-40","kind":"shape","options":{"color":"\\u0000sprite-color:dead","stroke":1.5,"path":[{"x":-2,"y":-3},{"x":2,"y":3}]}},{"id":"node-42","parent":"node-40","kind":"shape","options":{"color":"\\u0000sprite-color:dead","stroke":1.5,"path":[{"x":2,"y":-3},{"x":-2,"y":3}]}},{"id":"node-43","parent":"node-39","kind":"group","options":{"translate":{"x":6,"y":-2}}},{"id":"node-44","parent":"node-43","kind":"shape","options":{"color":"\\u0000sprite-color:dead","stroke":1.5,"path":[{"x":-2,"y":-3},{"x":2,"y":3}]}},{"id":"node-45","parent":"node-43","kind":"shape","options":{"color":"\\u0000sprite-color:dead","stroke":1.5,"path":[{"x":2,"y":-3},{"x":-2,"y":3}]}},{"id":"node-46","parent":"node-7","kind":"group","options":{"name":"eyes.confused"}},{"id":"node-47","parent":"node-46","kind":"group","options":{"translate":{"x":-6,"y":-2}}},{"id":"node-48","parent":"node-47","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-49","parent":"node-47","kind":"shape","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-3,"y":-4},{"x":3,"y":-2}]}},{"id":"node-50","parent":"node-46","kind":"group","options":{"translate":{"x":6,"y":-2}}},{"id":"node-51","parent":"node-50","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-52","parent":"node-7","kind":"group","options":{"name":"eyes.sleepy"}},{"id":"node-53","parent":"node-52","kind":"shape","options":{"translate":{"x":-6,"y":-1},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":1},{"bezier":[{"x":-1,"y":0},{"x":1,"y":0},{"x":2.5,"y":1}]}],"closed":false}},{"id":"node-54","parent":"node-52","kind":"shape","options":{"translate":{"x":6,"y":-1},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":1},{"bezier":[{"x":-1,"y":0},{"x":1,"y":0},{"x":2.5,"y":1}]}],"closed":false}},{"id":"node-55","parent":"node-7","kind":"group","options":{"name":"eyes.nervous"}},{"id":"node-56","parent":"node-55","kind":"group","options":{"translate":{"x":-6,"y":-2}}},{"id":"node-57","parent":"node-56","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-58","parent":"node-55","kind":"group","options":{"translate":{"x":6,"y":-2}}},{"id":"node-59","parent":"node-58","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-60","parent":"node-55","kind":"group","options":{"translate":{"x":10,"y":4}}},{"id":"node-61","parent":"node-60","kind":"shape","options":{"color":"\\u0000sprite-color:sweat","stroke":2,"path":[{"x":0,"y":-4}]}},{"id":"node-62","parent":"node-60","kind":"ellipse","options":{"translate":{"y":2},"color":"\\u0000sprite-color:sweat","stroke":0,"fill":true,"width":3,"height":4}},{"id":"node-63","parent":"node-7","kind":"group","options":{"name":"eyes.shy"}},{"id":"node-64","parent":"node-63","kind":"ellipse","options":{"translate":{"x":-6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":2.5,"height":2}},{"id":"node-65","parent":"node-63","kind":"ellipse","options":{"translate":{"x":6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":2.5,"height":2}},{"id":"node-66","parent":"node-7","kind":"group","options":{"name":"eyes.cute"}},{"id":"node-67","parent":"node-66","kind":"group","options":{"translate":{"x":-6,"y":-1}}},{"id":"node-68","parent":"node-67","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":5,"height":6}},{"id":"node-69","parent":"node-67","kind":"ellipse","options":{"translate":{"y":-1.5,"z":1},"color":"\\u0000sprite-color:white","stroke":0,"fill":true,"width":2.5,"height":3}},{"id":"node-70","parent":"node-67","kind":"ellipse","options":{"translate":{"x":-1.5,"y":1.5,"z":1},"color":"\\u0000sprite-color:white","stroke":0,"fill":true,"width":1,"height":1}},{"id":"node-71","parent":"node-66","kind":"group","options":{"translate":{"x":6,"y":-1}}},{"id":"node-72","parent":"node-71","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":5,"height":6}},{"id":"node-73","parent":"node-71","kind":"ellipse","options":{"translate":{"y":-1.5,"z":1},"color":"\\u0000sprite-color:white","stroke":0,"fill":true,"width":2.5,"height":3}},{"id":"node-74","parent":"node-71","kind":"ellipse","options":{"translate":{"x":-1.5,"y":1.5,"z":1},"color":"\\u0000sprite-color:white","stroke":0,"fill":true,"width":1,"height":1}},{"id":"node-75","parent":"node-7","kind":"group","options":{"name":"eyes.wink"}},{"id":"node-76","parent":"node-75","kind":"group","options":{"name":"eyes.wink.left"}},{"id":"node-77","parent":"node-76","kind":"shape","options":{"translate":{"x":-6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":-1,"y":-1.5},{"x":1,"y":-1.5},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-78","parent":"node-76","kind":"ellipse","options":{"translate":{"x":6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-79","parent":"node-75","kind":"group","options":{"name":"eyes.wink.right"}},{"id":"node-80","parent":"node-79","kind":"shape","options":{"translate":{"x":6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":-1,"y":-1.5},{"x":1,"y":-1.5},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-81","parent":"node-79","kind":"ellipse","options":{"translate":{"x":-6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-82","parent":"node-6","kind":"group","options":{"name":"mouth"}},{"id":"node-83","parent":"node-82","kind":"shape","options":{"name":"mouth.normal","translate":{"y":2},"color":"\\u0000sprite-color:mouth","stroke":1.5,"path":[{"x":-2.5,"y":0},{"x":2.5,"y":0}],"closed":false}},{"id":"node-84","parent":"node-82","kind":"shape","options":{"name":"mouth.happy","translate":{"y":2},"color":"\\u0000sprite-color:mouth","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":0,"y":4},{"x":2.5,"y":2},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-85","parent":"node-82","kind":"shape","options":{"name":"mouth.sad","translate":{"y":2},"color":"\\u0000sprite-color:mouth","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":0,"y":0},{"x":2.5,"y":2},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-86","parent":"node-82","kind":"shape","options":{"name":"mouth.small","translate":{"y":2},"color":"\\u0000sprite-color:mouth","stroke":1,"path":[{"x":-1.5,"y":0},{"x":1.5,"y":0}],"closed":false}},{"id":"node-87","parent":"node-82","kind":"shape","options":{"name":"mouth.worried","translate":{"y":2},"color":"\\u0000sprite-color:mouth","stroke":1,"path":[{"x":-2,"y":1},{"bezier":[{"x":-0.5,"y":0.5},{"x":0.5,"y":0.5},{"x":2,"y":1}]}],"closed":false}},{"id":"node-88","parent":"node-82","kind":"ellipse","options":{"name":"mouth.pout","translate":{"y":3},"color":"\\u0000sprite-color:mouth","stroke":1.5,"fill":true,"width":2,"height":2.5}},{"id":"node-89","parent":"node-82","kind":"ellipse","options":{"name":"mouth.surprised","translate":{"y":3},"color":"\\u0000sprite-color:mouth","stroke":1.5,"fill":true,"width":3,"height":4}},{"id":"node-90","parent":"node-82","kind":"group","options":{"name":"mouth.dead","translate":{"y":5}}},{"id":"node-91","parent":"node-90","kind":"ellipse","options":{"color":"\\u0000sprite-color:dead","stroke":1.5,"fill":true,"width":3,"height":2}},{"id":"node-92","parent":"node-90","kind":"ellipse","options":{"translate":{"y":0.5},"color":"\\u0000sprite-color:deadTongue","stroke":0,"fill":true,"width":1.5,"height":1}},{"id":"node-93","parent":"node-82","kind":"group","options":{"name":"mouth.open","translate":{"y":2}}},{"id":"node-94","parent":"node-93","kind":"ellipse","options":{"color":"\\u0000sprite-color:mouth","stroke":1.5,"fill":true,"width":6,"height":4}},{"id":"node-95","parent":"node-93","kind":"ellipse","options":{"name":"mouth.tongue","translate":{"y":1},"color":"\\u0000sprite-color:tongue","stroke":0,"fill":true,"width":3,"height":1.5}},{"id":"node-96","parent":"node-6","kind":"group","options":{"name":"blush.off"}}],"palette":{"body":"#fff7e4","cap":"#f98284","capSpot":"#ffe6c6","eye":"#28282e","mouth":"#28282e","dead":"#6c5671","deadTongue":"#d9c8bf","tongue":"#f98284","sweat":"#accce4","white":"#ffffff"},"variants":{"eyes":{"normal":"node-8","happy":"node-29","sad":"node-15","angry":"node-32","surprised":"node-22","dead":"node-39","confused":"node-46","sleepy":"node-52","nervous":"node-55","shy":"node-63","wink":"node-76","cute":"node-66","wink.left":"node-76","wink.right":"node-79"},"mouth":{"normal":"node-83","happy":"node-84","sad":"node-85","angry":"node-85","surprised":"node-89","dead":"node-90","small":"node-86","worried":"node-87","pout":"node-88","open":"node-93"},"blush":{"off":"node-96","small":"node-96","medium":"node-96","big":"node-96"}},"expressions":{"angry":{"variants":{"eyes":"angry","mouth":"angry","blush":"off"},"motion":{"target":"root","translate":{"x":1,"y":0},"durationMs":150,"repeat":"none"}},"confused":{"variants":{"eyes":"confused","mouth":"normal","blush":"off"},"motion":{"target":"root","translate":{"x":0,"y":0.5},"durationMs":150,"repeat":"none"}},"cute":{"variants":{"eyes":"cute","mouth":"happy","blush":"big"},"motion":{"target":"root","translate":{"x":0,"y":-2.5},"durationMs":150,"repeat":"none"}},"dead":{"variants":{"eyes":"dead","mouth":"dead","blush":"off"}},"happy":{"variants":{"eyes":"happy","mouth":"happy","blush":"medium"},"motion":{"target":"root","translate":{"x":0,"y":-2},"durationMs":150,"repeat":"none"}},"nervous":{"variants":{"eyes":"nervous","mouth":"worried","blush":"off"},"motion":{"target":"root","translate":{"x":-0.5,"y":-1},"durationMs":150,"repeat":"none"}},"normal":{"variants":{"eyes":"normal","mouth":"normal","blush":"off"},"motion":{"target":"root","translate":{"x":0,"y":1},"durationMs":150,"repeat":"none"}},"pleading":{"variants":{"eyes":"cute","mouth":"pout","blush":"medium"},"motion":{"target":"root","translate":{"x":0,"y":-1},"durationMs":150,"repeat":"none"}},"sad":{"variants":{"eyes":"sad","mouth":"sad","blush":"off"},"motion":{"target":"root","translate":{"x":0,"y":2},"durationMs":150,"repeat":"none"}},"shy":{"variants":{"eyes":"shy","mouth":"small","blush":"small"},"motion":{"target":"root","translate":{"x":0,"y":1.5},"durationMs":150,"repeat":"none"}},"sleepy":{"variants":{"eyes":"sleepy","mouth":"small","blush":"off"},"motion":{"target":"root","translate":{"x":0,"y":2},"durationMs":150,"repeat":"none"}},"surprised":{"variants":{"eyes":"surprised","mouth":"surprised","blush":"off"},"motion":{"target":"root","translate":{"x":0,"y":-3},"durationMs":150,"repeat":"none"}},"wink":{"variants":{"mouth":"happy","blush":"small"},"variantChoices":{"eyes":["wink.left","wink.right"]},"motion":{"target":"root","translate":{"x":0,"y":-1.5},"durationMs":150,"repeat":"none"}}},"activities":{"idle":{"motion":{"target":"root","translate":{"y":0.5},"durationMs":2000,"repeat":"yoyo"},"mouseInfluence":1},"listening":{"motion":{"target":"root","rotate":{"x":-0.2},"durationMs":300,"repeat":"yoyo"},"mouseInfluence":0.3},"processing":{"mouseInfluence":0.2},"speaking":{"motion":{"target":"root","translate":{"y":0.5},"durationMs":1500,"repeat":"yoyo"},"mouseInfluence":0,"mouthCycle":[{"durationMs":100,"mouth":"open"},{"durationMs":150,"mouth":"base"},{"durationMs":100,"mouth":"open"},{"durationMs":200,"mouth":"base"}]},"thinking":{"motion":{"target":"root","rotate":{"z":0.1},"durationMs":800,"repeat":"yoyo"},"mouseInfluence":0},"error":{"motion":{"target":"root","rotate":{"x":0.9},"durationMs":600,"repeat":"none"},"mouseInfluence":0.1,"geometry":{"eyes":"dead","mouth":"dead"}}},"defaultPresentation":{"activity":"idle","expression":"sleepy"}}`)},r={document:e.parse(n),render:t};export{r as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./document-DjWTbvB5.js";import{t}from"./renderer-BHkhGf2O.js";var n={version:1,name:`mushroom`,renderer:`zdog`,controls:{body:{type:`color`,label:`body`,default:`#fff7e4`},cap:{type:`color`,label:`cap`,default:`#f98284`},capSpot:{type:`color`,label:`capSpot`,default:`#ffe6c6`},eye:{type:`color`,label:`eye`,default:`#28282e`},mouth:{type:`color`,label:`mouth`,default:`#28282e`},dead:{type:`color`,label:`dead`,default:`#6c5671`},deadTongue:{type:`color`,label:`deadTongue`,default:`#d9c8bf`},tongue:{type:`color`,label:`tongue`,default:`#f98284`},sweat:{type:`color`,label:`sweat`,default:`#accce4`},white:{type:`color`,label:`white`,default:`#ffffff`}},data:JSON.parse(`{"root":"node-0","nodes":[{"id":"node-0","kind":"group","options":{"name":"root"}},{"id":"node-1","parent":"node-0","kind":"group","options":{"name":"body","updateSort":true}},{"id":"node-2","parent":"node-1","kind":"hemisphere","options":{"name":"body.hemisphere","translate":{"y":2},"rotate":{"x":4.71238898038469},"color":"\\u0000sprite-color:body","stroke":false,"backface":"\\u0000sprite-color:cap","diameter":32}},{"id":"node-3","parent":"node-1","kind":"hemisphere","options":{"name":"cap.hemisphere","translate":{"y":2},"rotate":{"x":1.5707963267948966},"color":"\\u0000sprite-color:cap","stroke":false,"backface":"\\u0000sprite-color:capSpot","diameter":42}},{"id":"node-4","parent":"node-3","kind":"shape","options":{"name":"cap.spot.front","translate":{"x":-8,"y":8,"z":12},"color":"\\u0000sprite-color:capSpot","stroke":12,"path":[{"x":0,"y":0}]}},{"id":"node-5","parent":"node-3","kind":"shape","options":{"name":"cap.spot.top","translate":{"x":8,"y":-4,"z":13},"color":"\\u0000sprite-color:capSpot","stroke":18,"path":[{"x":0,"y":0}]}},{"id":"node-6","parent":"node-1","kind":"group","options":{"name":"face","translate":{"y":7,"z":8}}},{"id":"node-7","parent":"node-6","kind":"group","options":{"name":"eyes"}},{"id":"node-8","parent":"node-7","kind":"group","options":{"name":"eyes.normal"}},{"id":"node-9","parent":"node-8","kind":"group","options":{"translate":{"x":-6,"y":-2}}},{"id":"node-10","parent":"node-9","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-11","parent":"node-9","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-12","parent":"node-8","kind":"group","options":{"translate":{"x":6,"y":-2}}},{"id":"node-13","parent":"node-12","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-14","parent":"node-12","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-15","parent":"node-7","kind":"group","options":{"name":"eyes.sad"}},{"id":"node-16","parent":"node-15","kind":"group","options":{"translate":{"x":-6,"y":-1},"rotate":{"z":0.2}}},{"id":"node-17","parent":"node-16","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":4}},{"id":"node-18","parent":"node-16","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-19","parent":"node-15","kind":"group","options":{"translate":{"x":6,"y":-1},"rotate":{"z":-0.2}}},{"id":"node-20","parent":"node-19","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":4}},{"id":"node-21","parent":"node-19","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-22","parent":"node-7","kind":"group","options":{"name":"eyes.surprised"}},{"id":"node-23","parent":"node-22","kind":"group","options":{"translate":{"x":-6,"y":-2}}},{"id":"node-24","parent":"node-23","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":4,"height":5}},{"id":"node-25","parent":"node-23","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-26","parent":"node-22","kind":"group","options":{"translate":{"x":6,"y":-2}}},{"id":"node-27","parent":"node-26","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":4,"height":5}},{"id":"node-28","parent":"node-26","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-29","parent":"node-7","kind":"group","options":{"name":"eyes.happy"}},{"id":"node-30","parent":"node-29","kind":"shape","options":{"translate":{"x":-6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":-1,"y":-1.5},{"x":1,"y":-1.5},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-31","parent":"node-29","kind":"shape","options":{"translate":{"x":6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":-1,"y":-1.5},{"x":1,"y":-1.5},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-32","parent":"node-7","kind":"group","options":{"name":"eyes.angry"}},{"id":"node-33","parent":"node-32","kind":"group","options":{"translate":{"x":-6,"y":-1},"rotate":{"z":-0.3}}},{"id":"node-34","parent":"node-33","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":4}},{"id":"node-35","parent":"node-33","kind":"shape","options":{"translate":{"y":-1},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-3,"y":-3},{"x":3,"y":-2}]}},{"id":"node-36","parent":"node-32","kind":"group","options":{"translate":{"x":6,"y":-1},"rotate":{"z":0.3}}},{"id":"node-37","parent":"node-36","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":4}},{"id":"node-38","parent":"node-36","kind":"shape","options":{"translate":{"y":-1},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-3,"y":-3},{"x":3,"y":-2}]}},{"id":"node-39","parent":"node-7","kind":"group","options":{"name":"eyes.dead"}},{"id":"node-40","parent":"node-39","kind":"group","options":{"translate":{"x":-6,"y":-2}}},{"id":"node-41","parent":"node-40","kind":"shape","options":{"color":"\\u0000sprite-color:dead","stroke":1.5,"path":[{"x":-2,"y":-3},{"x":2,"y":3}]}},{"id":"node-42","parent":"node-40","kind":"shape","options":{"color":"\\u0000sprite-color:dead","stroke":1.5,"path":[{"x":2,"y":-3},{"x":-2,"y":3}]}},{"id":"node-43","parent":"node-39","kind":"group","options":{"translate":{"x":6,"y":-2}}},{"id":"node-44","parent":"node-43","kind":"shape","options":{"color":"\\u0000sprite-color:dead","stroke":1.5,"path":[{"x":-2,"y":-3},{"x":2,"y":3}]}},{"id":"node-45","parent":"node-43","kind":"shape","options":{"color":"\\u0000sprite-color:dead","stroke":1.5,"path":[{"x":2,"y":-3},{"x":-2,"y":3}]}},{"id":"node-46","parent":"node-7","kind":"group","options":{"name":"eyes.confused"}},{"id":"node-47","parent":"node-46","kind":"group","options":{"translate":{"x":-6,"y":-2}}},{"id":"node-48","parent":"node-47","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-49","parent":"node-47","kind":"shape","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-3,"y":-4},{"x":3,"y":-2}]}},{"id":"node-50","parent":"node-46","kind":"group","options":{"translate":{"x":6,"y":-2}}},{"id":"node-51","parent":"node-50","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-52","parent":"node-7","kind":"group","options":{"name":"eyes.sleepy"}},{"id":"node-53","parent":"node-52","kind":"shape","options":{"translate":{"x":-6,"y":-1},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":1},{"bezier":[{"x":-1,"y":0},{"x":1,"y":0},{"x":2.5,"y":1}]}],"closed":false}},{"id":"node-54","parent":"node-52","kind":"shape","options":{"translate":{"x":6,"y":-1},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":1},{"bezier":[{"x":-1,"y":0},{"x":1,"y":0},{"x":2.5,"y":1}]}],"closed":false}},{"id":"node-55","parent":"node-7","kind":"group","options":{"name":"eyes.nervous"}},{"id":"node-56","parent":"node-55","kind":"group","options":{"translate":{"x":-6,"y":-2}}},{"id":"node-57","parent":"node-56","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-58","parent":"node-55","kind":"group","options":{"translate":{"x":6,"y":-2}}},{"id":"node-59","parent":"node-58","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-60","parent":"node-55","kind":"group","options":{"translate":{"x":10,"y":4}}},{"id":"node-61","parent":"node-60","kind":"shape","options":{"color":"\\u0000sprite-color:sweat","stroke":2,"path":[{"x":0,"y":-4}]}},{"id":"node-62","parent":"node-60","kind":"ellipse","options":{"translate":{"y":2},"color":"\\u0000sprite-color:sweat","stroke":0,"fill":true,"width":3,"height":4}},{"id":"node-63","parent":"node-7","kind":"group","options":{"name":"eyes.shy"}},{"id":"node-64","parent":"node-63","kind":"ellipse","options":{"translate":{"x":-6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":2.5,"height":2}},{"id":"node-65","parent":"node-63","kind":"ellipse","options":{"translate":{"x":6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":2.5,"height":2}},{"id":"node-66","parent":"node-7","kind":"group","options":{"name":"eyes.cute"}},{"id":"node-67","parent":"node-66","kind":"group","options":{"translate":{"x":-6,"y":-1}}},{"id":"node-68","parent":"node-67","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":5,"height":6}},{"id":"node-69","parent":"node-67","kind":"ellipse","options":{"translate":{"y":-1.5,"z":1},"color":"\\u0000sprite-color:white","stroke":0,"fill":true,"width":2.5,"height":3}},{"id":"node-70","parent":"node-67","kind":"ellipse","options":{"translate":{"x":-1.5,"y":1.5,"z":1},"color":"\\u0000sprite-color:white","stroke":0,"fill":true,"width":1,"height":1}},{"id":"node-71","parent":"node-66","kind":"group","options":{"translate":{"x":6,"y":-1}}},{"id":"node-72","parent":"node-71","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":5,"height":6}},{"id":"node-73","parent":"node-71","kind":"ellipse","options":{"translate":{"y":-1.5,"z":1},"color":"\\u0000sprite-color:white","stroke":0,"fill":true,"width":2.5,"height":3}},{"id":"node-74","parent":"node-71","kind":"ellipse","options":{"translate":{"x":-1.5,"y":1.5,"z":1},"color":"\\u0000sprite-color:white","stroke":0,"fill":true,"width":1,"height":1}},{"id":"node-75","parent":"node-7","kind":"group","options":{"name":"eyes.wink"}},{"id":"node-76","parent":"node-75","kind":"group","options":{"name":"eyes.wink.left"}},{"id":"node-77","parent":"node-76","kind":"shape","options":{"translate":{"x":-6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":-1,"y":-1.5},{"x":1,"y":-1.5},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-78","parent":"node-76","kind":"ellipse","options":{"translate":{"x":6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-79","parent":"node-75","kind":"group","options":{"name":"eyes.wink.right"}},{"id":"node-80","parent":"node-79","kind":"shape","options":{"translate":{"x":6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":-1,"y":-1.5},{"x":1,"y":-1.5},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-81","parent":"node-79","kind":"ellipse","options":{"translate":{"x":-6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-82","parent":"node-6","kind":"group","options":{"name":"mouth"}},{"id":"node-83","parent":"node-82","kind":"shape","options":{"name":"mouth.normal","translate":{"y":2},"color":"\\u0000sprite-color:mouth","stroke":1.5,"path":[{"x":-2.5,"y":0},{"x":2.5,"y":0}],"closed":false}},{"id":"node-84","parent":"node-82","kind":"shape","options":{"name":"mouth.happy","translate":{"y":2},"color":"\\u0000sprite-color:mouth","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":0,"y":4},{"x":2.5,"y":2},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-85","parent":"node-82","kind":"shape","options":{"name":"mouth.sad","translate":{"y":2},"color":"\\u0000sprite-color:mouth","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":0,"y":0},{"x":2.5,"y":2},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-86","parent":"node-82","kind":"shape","options":{"name":"mouth.small","translate":{"y":2},"color":"\\u0000sprite-color:mouth","stroke":1,"path":[{"x":-1.5,"y":0},{"x":1.5,"y":0}],"closed":false}},{"id":"node-87","parent":"node-82","kind":"shape","options":{"name":"mouth.worried","translate":{"y":2},"color":"\\u0000sprite-color:mouth","stroke":1,"path":[{"x":-2,"y":1},{"bezier":[{"x":-0.5,"y":0.5},{"x":0.5,"y":0.5},{"x":2,"y":1}]}],"closed":false}},{"id":"node-88","parent":"node-82","kind":"ellipse","options":{"name":"mouth.pout","translate":{"y":3},"color":"\\u0000sprite-color:mouth","stroke":1.5,"fill":true,"width":2,"height":2.5}},{"id":"node-89","parent":"node-82","kind":"ellipse","options":{"name":"mouth.surprised","translate":{"y":3},"color":"\\u0000sprite-color:mouth","stroke":1.5,"fill":true,"width":3,"height":4}},{"id":"node-90","parent":"node-82","kind":"group","options":{"name":"mouth.dead","translate":{"y":5}}},{"id":"node-91","parent":"node-90","kind":"ellipse","options":{"color":"\\u0000sprite-color:dead","stroke":1.5,"fill":true,"width":3,"height":2}},{"id":"node-92","parent":"node-90","kind":"ellipse","options":{"translate":{"y":0.5},"color":"\\u0000sprite-color:deadTongue","stroke":0,"fill":true,"width":1.5,"height":1}},{"id":"node-93","parent":"node-82","kind":"group","options":{"name":"mouth.open","translate":{"y":2}}},{"id":"node-94","parent":"node-93","kind":"ellipse","options":{"color":"\\u0000sprite-color:mouth","stroke":1.5,"fill":true,"width":6,"height":4}},{"id":"node-95","parent":"node-93","kind":"ellipse","options":{"name":"mouth.tongue","translate":{"y":1},"color":"\\u0000sprite-color:tongue","stroke":0,"fill":true,"width":3,"height":1.5}},{"id":"node-96","parent":"node-6","kind":"group","options":{"name":"blush.off"}}],"palette":{"body":"#fff7e4","cap":"#f98284","capSpot":"#ffe6c6","eye":"#28282e","mouth":"#28282e","dead":"#6c5671","deadTongue":"#d9c8bf","tongue":"#f98284","sweat":"#accce4","white":"#ffffff"},"variants":{"eyes":{"normal":"node-8","happy":"node-29","sad":"node-15","angry":"node-32","surprised":"node-22","dead":"node-39","confused":"node-46","sleepy":"node-52","nervous":"node-55","shy":"node-63","wink":"node-76","cute":"node-66","wink.left":"node-76","wink.right":"node-79"},"mouth":{"normal":"node-83","happy":"node-84","sad":"node-85","angry":"node-85","surprised":"node-89","dead":"node-90","small":"node-86","worried":"node-87","pout":"node-88","open":"node-93"},"blush":{"off":"node-96","small":"node-96","medium":"node-96","big":"node-96"}},"expressions":{"angry":{"variants":{"eyes":"angry","mouth":"angry","blush":"off"},"motion":{"target":"root","translate":{"x":1,"y":0},"durationMs":150,"repeat":"none"}},"confused":{"variants":{"eyes":"confused","mouth":"normal","blush":"off"},"motion":{"target":"root","translate":{"x":0,"y":0.5},"durationMs":150,"repeat":"none"}},"cute":{"variants":{"eyes":"cute","mouth":"happy","blush":"big"},"motion":{"target":"root","translate":{"x":0,"y":-2.5},"durationMs":150,"repeat":"none"}},"dead":{"variants":{"eyes":"dead","mouth":"dead","blush":"off"}},"happy":{"variants":{"eyes":"happy","mouth":"happy","blush":"medium"},"motion":{"target":"root","translate":{"x":0,"y":-2},"durationMs":150,"repeat":"none"}},"nervous":{"variants":{"eyes":"nervous","mouth":"worried","blush":"off"},"motion":{"target":"root","translate":{"x":-0.5,"y":-1},"durationMs":150,"repeat":"none"}},"normal":{"variants":{"eyes":"normal","mouth":"normal","blush":"off"},"motion":{"target":"root","translate":{"x":0,"y":1},"durationMs":150,"repeat":"none"}},"pleading":{"variants":{"eyes":"cute","mouth":"pout","blush":"medium"},"motion":{"target":"root","translate":{"x":0,"y":-1},"durationMs":150,"repeat":"none"}},"sad":{"variants":{"eyes":"sad","mouth":"sad","blush":"off"},"motion":{"target":"root","translate":{"x":0,"y":2},"durationMs":150,"repeat":"none"}},"shy":{"variants":{"eyes":"shy","mouth":"small","blush":"small"},"motion":{"target":"root","translate":{"x":0,"y":1.5},"durationMs":150,"repeat":"none"}},"sleepy":{"variants":{"eyes":"sleepy","mouth":"small","blush":"off"},"motion":{"target":"root","translate":{"x":0,"y":2},"durationMs":150,"repeat":"none"}},"surprised":{"variants":{"eyes":"surprised","mouth":"surprised","blush":"off"},"motion":{"target":"root","translate":{"x":0,"y":-3},"durationMs":150,"repeat":"none"}},"wink":{"variants":{"mouth":"happy","blush":"small"},"variantChoices":{"eyes":["wink.left","wink.right"]},"motion":{"target":"root","translate":{"x":0,"y":-1.5},"durationMs":150,"repeat":"none"}}},"activities":{"idle":{"motion":{"target":"root","translate":{"y":0.5},"durationMs":2000,"repeat":"yoyo"},"mouseInfluence":1},"listening":{"motion":{"target":"root","rotate":{"x":-0.2},"durationMs":300,"repeat":"yoyo"},"mouseInfluence":0.3},"processing":{"mouseInfluence":0.2},"speaking":{"motion":{"target":"root","translate":{"y":0.5},"durationMs":1500,"repeat":"yoyo"},"mouseInfluence":0,"mouthCycle":[{"durationMs":100,"mouth":"open"},{"durationMs":150,"mouth":"base"},{"durationMs":100,"mouth":"open"},{"durationMs":200,"mouth":"base"}]},"thinking":{"motion":{"target":"root","rotate":{"z":0.1},"durationMs":800,"repeat":"yoyo"},"mouseInfluence":0},"error":{"motion":{"target":"root","rotate":{"x":0.9},"durationMs":600,"repeat":"none"},"mouseInfluence":0.1,"geometry":{"eyes":"dead","mouth":"dead"}}},"defaultPresentation":{"activity":"idle","expression":"sleepy"}}`)},r={document:e.parse(n),render:t};export{r as default};
|
|
1
|
+
import{a as e}from"./document-DjWTbvB5.js";import{t}from"./renderer-cVoUiOqk.js";var n={version:1,name:`mushroom`,renderer:`zdog`,controls:{body:{type:`color`,label:`body`,default:`#fff7e4`},cap:{type:`color`,label:`cap`,default:`#f98284`},capSpot:{type:`color`,label:`capSpot`,default:`#ffe6c6`},eye:{type:`color`,label:`eye`,default:`#28282e`},mouth:{type:`color`,label:`mouth`,default:`#28282e`},dead:{type:`color`,label:`dead`,default:`#6c5671`},deadTongue:{type:`color`,label:`deadTongue`,default:`#d9c8bf`},tongue:{type:`color`,label:`tongue`,default:`#f98284`},sweat:{type:`color`,label:`sweat`,default:`#accce4`},white:{type:`color`,label:`white`,default:`#ffffff`}},data:JSON.parse(`{"root":"node-0","nodes":[{"id":"node-0","kind":"group","options":{"name":"root"}},{"id":"node-1","parent":"node-0","kind":"group","options":{"name":"body","updateSort":true}},{"id":"node-2","parent":"node-1","kind":"hemisphere","options":{"name":"body.hemisphere","translate":{"y":2},"rotate":{"x":4.71238898038469},"color":"\\u0000sprite-color:body","stroke":false,"backface":"\\u0000sprite-color:cap","diameter":32}},{"id":"node-3","parent":"node-1","kind":"hemisphere","options":{"name":"cap.hemisphere","translate":{"y":2},"rotate":{"x":1.5707963267948966},"color":"\\u0000sprite-color:cap","stroke":false,"backface":"\\u0000sprite-color:capSpot","diameter":42}},{"id":"node-4","parent":"node-3","kind":"shape","options":{"name":"cap.spot.front","translate":{"x":-8,"y":8,"z":12},"color":"\\u0000sprite-color:capSpot","stroke":12,"path":[{"x":0,"y":0}]}},{"id":"node-5","parent":"node-3","kind":"shape","options":{"name":"cap.spot.top","translate":{"x":8,"y":-4,"z":13},"color":"\\u0000sprite-color:capSpot","stroke":18,"path":[{"x":0,"y":0}]}},{"id":"node-6","parent":"node-1","kind":"group","options":{"name":"face","translate":{"y":7,"z":8}}},{"id":"node-7","parent":"node-6","kind":"group","options":{"name":"eyes"}},{"id":"node-8","parent":"node-7","kind":"group","options":{"name":"eyes.normal"}},{"id":"node-9","parent":"node-8","kind":"group","options":{"translate":{"x":-6,"y":-2}}},{"id":"node-10","parent":"node-9","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-11","parent":"node-9","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-12","parent":"node-8","kind":"group","options":{"translate":{"x":6,"y":-2}}},{"id":"node-13","parent":"node-12","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-14","parent":"node-12","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-15","parent":"node-7","kind":"group","options":{"name":"eyes.sad"}},{"id":"node-16","parent":"node-15","kind":"group","options":{"translate":{"x":-6,"y":-1},"rotate":{"z":0.2}}},{"id":"node-17","parent":"node-16","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":4}},{"id":"node-18","parent":"node-16","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-19","parent":"node-15","kind":"group","options":{"translate":{"x":6,"y":-1},"rotate":{"z":-0.2}}},{"id":"node-20","parent":"node-19","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":4}},{"id":"node-21","parent":"node-19","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-22","parent":"node-7","kind":"group","options":{"name":"eyes.surprised"}},{"id":"node-23","parent":"node-22","kind":"group","options":{"translate":{"x":-6,"y":-2}}},{"id":"node-24","parent":"node-23","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":4,"height":5}},{"id":"node-25","parent":"node-23","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-26","parent":"node-22","kind":"group","options":{"translate":{"x":6,"y":-2}}},{"id":"node-27","parent":"node-26","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":4,"height":5}},{"id":"node-28","parent":"node-26","kind":"ellipse","options":{"translate":{"y":-1,"z":1},"color":"\\u0000sprite-color:white","stroke":0.5,"fill":true,"width":1.5,"height":2}},{"id":"node-29","parent":"node-7","kind":"group","options":{"name":"eyes.happy"}},{"id":"node-30","parent":"node-29","kind":"shape","options":{"translate":{"x":-6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":-1,"y":-1.5},{"x":1,"y":-1.5},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-31","parent":"node-29","kind":"shape","options":{"translate":{"x":6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":-1,"y":-1.5},{"x":1,"y":-1.5},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-32","parent":"node-7","kind":"group","options":{"name":"eyes.angry"}},{"id":"node-33","parent":"node-32","kind":"group","options":{"translate":{"x":-6,"y":-1},"rotate":{"z":-0.3}}},{"id":"node-34","parent":"node-33","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":4}},{"id":"node-35","parent":"node-33","kind":"shape","options":{"translate":{"y":-1},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-3,"y":-3},{"x":3,"y":-2}]}},{"id":"node-36","parent":"node-32","kind":"group","options":{"translate":{"x":6,"y":-1},"rotate":{"z":0.3}}},{"id":"node-37","parent":"node-36","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":4}},{"id":"node-38","parent":"node-36","kind":"shape","options":{"translate":{"y":-1},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-3,"y":-3},{"x":3,"y":-2}]}},{"id":"node-39","parent":"node-7","kind":"group","options":{"name":"eyes.dead"}},{"id":"node-40","parent":"node-39","kind":"group","options":{"translate":{"x":-6,"y":-2}}},{"id":"node-41","parent":"node-40","kind":"shape","options":{"color":"\\u0000sprite-color:dead","stroke":1.5,"path":[{"x":-2,"y":-3},{"x":2,"y":3}]}},{"id":"node-42","parent":"node-40","kind":"shape","options":{"color":"\\u0000sprite-color:dead","stroke":1.5,"path":[{"x":2,"y":-3},{"x":-2,"y":3}]}},{"id":"node-43","parent":"node-39","kind":"group","options":{"translate":{"x":6,"y":-2}}},{"id":"node-44","parent":"node-43","kind":"shape","options":{"color":"\\u0000sprite-color:dead","stroke":1.5,"path":[{"x":-2,"y":-3},{"x":2,"y":3}]}},{"id":"node-45","parent":"node-43","kind":"shape","options":{"color":"\\u0000sprite-color:dead","stroke":1.5,"path":[{"x":2,"y":-3},{"x":-2,"y":3}]}},{"id":"node-46","parent":"node-7","kind":"group","options":{"name":"eyes.confused"}},{"id":"node-47","parent":"node-46","kind":"group","options":{"translate":{"x":-6,"y":-2}}},{"id":"node-48","parent":"node-47","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-49","parent":"node-47","kind":"shape","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-3,"y":-4},{"x":3,"y":-2}]}},{"id":"node-50","parent":"node-46","kind":"group","options":{"translate":{"x":6,"y":-2}}},{"id":"node-51","parent":"node-50","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-52","parent":"node-7","kind":"group","options":{"name":"eyes.sleepy"}},{"id":"node-53","parent":"node-52","kind":"shape","options":{"translate":{"x":-6,"y":-1},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":1},{"bezier":[{"x":-1,"y":0},{"x":1,"y":0},{"x":2.5,"y":1}]}],"closed":false}},{"id":"node-54","parent":"node-52","kind":"shape","options":{"translate":{"x":6,"y":-1},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":1},{"bezier":[{"x":-1,"y":0},{"x":1,"y":0},{"x":2.5,"y":1}]}],"closed":false}},{"id":"node-55","parent":"node-7","kind":"group","options":{"name":"eyes.nervous"}},{"id":"node-56","parent":"node-55","kind":"group","options":{"translate":{"x":-6,"y":-2}}},{"id":"node-57","parent":"node-56","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-58","parent":"node-55","kind":"group","options":{"translate":{"x":6,"y":-2}}},{"id":"node-59","parent":"node-58","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-60","parent":"node-55","kind":"group","options":{"translate":{"x":10,"y":4}}},{"id":"node-61","parent":"node-60","kind":"shape","options":{"color":"\\u0000sprite-color:sweat","stroke":2,"path":[{"x":0,"y":-4}]}},{"id":"node-62","parent":"node-60","kind":"ellipse","options":{"translate":{"y":2},"color":"\\u0000sprite-color:sweat","stroke":0,"fill":true,"width":3,"height":4}},{"id":"node-63","parent":"node-7","kind":"group","options":{"name":"eyes.shy"}},{"id":"node-64","parent":"node-63","kind":"ellipse","options":{"translate":{"x":-6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":2.5,"height":2}},{"id":"node-65","parent":"node-63","kind":"ellipse","options":{"translate":{"x":6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":2.5,"height":2}},{"id":"node-66","parent":"node-7","kind":"group","options":{"name":"eyes.cute"}},{"id":"node-67","parent":"node-66","kind":"group","options":{"translate":{"x":-6,"y":-1}}},{"id":"node-68","parent":"node-67","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":5,"height":6}},{"id":"node-69","parent":"node-67","kind":"ellipse","options":{"translate":{"y":-1.5,"z":1},"color":"\\u0000sprite-color:white","stroke":0,"fill":true,"width":2.5,"height":3}},{"id":"node-70","parent":"node-67","kind":"ellipse","options":{"translate":{"x":-1.5,"y":1.5,"z":1},"color":"\\u0000sprite-color:white","stroke":0,"fill":true,"width":1,"height":1}},{"id":"node-71","parent":"node-66","kind":"group","options":{"translate":{"x":6,"y":-1}}},{"id":"node-72","parent":"node-71","kind":"ellipse","options":{"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":5,"height":6}},{"id":"node-73","parent":"node-71","kind":"ellipse","options":{"translate":{"y":-1.5,"z":1},"color":"\\u0000sprite-color:white","stroke":0,"fill":true,"width":2.5,"height":3}},{"id":"node-74","parent":"node-71","kind":"ellipse","options":{"translate":{"x":-1.5,"y":1.5,"z":1},"color":"\\u0000sprite-color:white","stroke":0,"fill":true,"width":1,"height":1}},{"id":"node-75","parent":"node-7","kind":"group","options":{"name":"eyes.wink"}},{"id":"node-76","parent":"node-75","kind":"group","options":{"name":"eyes.wink.left"}},{"id":"node-77","parent":"node-76","kind":"shape","options":{"translate":{"x":-6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":-1,"y":-1.5},{"x":1,"y":-1.5},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-78","parent":"node-76","kind":"ellipse","options":{"translate":{"x":6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-79","parent":"node-75","kind":"group","options":{"name":"eyes.wink.right"}},{"id":"node-80","parent":"node-79","kind":"shape","options":{"translate":{"x":6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":-1,"y":-1.5},{"x":1,"y":-1.5},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-81","parent":"node-79","kind":"ellipse","options":{"translate":{"x":-6,"y":-2},"color":"\\u0000sprite-color:eye","stroke":1.5,"fill":true,"width":3,"height":5}},{"id":"node-82","parent":"node-6","kind":"group","options":{"name":"mouth"}},{"id":"node-83","parent":"node-82","kind":"shape","options":{"name":"mouth.normal","translate":{"y":2},"color":"\\u0000sprite-color:mouth","stroke":1.5,"path":[{"x":-2.5,"y":0},{"x":2.5,"y":0}],"closed":false}},{"id":"node-84","parent":"node-82","kind":"shape","options":{"name":"mouth.happy","translate":{"y":2},"color":"\\u0000sprite-color:mouth","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":0,"y":4},{"x":2.5,"y":2},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-85","parent":"node-82","kind":"shape","options":{"name":"mouth.sad","translate":{"y":2},"color":"\\u0000sprite-color:mouth","stroke":1.5,"path":[{"x":-2.5,"y":2},{"bezier":[{"x":0,"y":0},{"x":2.5,"y":2},{"x":2.5,"y":2}]}],"closed":false}},{"id":"node-86","parent":"node-82","kind":"shape","options":{"name":"mouth.small","translate":{"y":2},"color":"\\u0000sprite-color:mouth","stroke":1,"path":[{"x":-1.5,"y":0},{"x":1.5,"y":0}],"closed":false}},{"id":"node-87","parent":"node-82","kind":"shape","options":{"name":"mouth.worried","translate":{"y":2},"color":"\\u0000sprite-color:mouth","stroke":1,"path":[{"x":-2,"y":1},{"bezier":[{"x":-0.5,"y":0.5},{"x":0.5,"y":0.5},{"x":2,"y":1}]}],"closed":false}},{"id":"node-88","parent":"node-82","kind":"ellipse","options":{"name":"mouth.pout","translate":{"y":3},"color":"\\u0000sprite-color:mouth","stroke":1.5,"fill":true,"width":2,"height":2.5}},{"id":"node-89","parent":"node-82","kind":"ellipse","options":{"name":"mouth.surprised","translate":{"y":3},"color":"\\u0000sprite-color:mouth","stroke":1.5,"fill":true,"width":3,"height":4}},{"id":"node-90","parent":"node-82","kind":"group","options":{"name":"mouth.dead","translate":{"y":5}}},{"id":"node-91","parent":"node-90","kind":"ellipse","options":{"color":"\\u0000sprite-color:dead","stroke":1.5,"fill":true,"width":3,"height":2}},{"id":"node-92","parent":"node-90","kind":"ellipse","options":{"translate":{"y":0.5},"color":"\\u0000sprite-color:deadTongue","stroke":0,"fill":true,"width":1.5,"height":1}},{"id":"node-93","parent":"node-82","kind":"group","options":{"name":"mouth.open","translate":{"y":2}}},{"id":"node-94","parent":"node-93","kind":"ellipse","options":{"color":"\\u0000sprite-color:mouth","stroke":1.5,"fill":true,"width":6,"height":4}},{"id":"node-95","parent":"node-93","kind":"ellipse","options":{"name":"mouth.tongue","translate":{"y":1},"color":"\\u0000sprite-color:tongue","stroke":0,"fill":true,"width":3,"height":1.5}},{"id":"node-96","parent":"node-6","kind":"group","options":{"name":"blush.off"}}],"palette":{"body":"#fff7e4","cap":"#f98284","capSpot":"#ffe6c6","eye":"#28282e","mouth":"#28282e","dead":"#6c5671","deadTongue":"#d9c8bf","tongue":"#f98284","sweat":"#accce4","white":"#ffffff"},"variants":{"eyes":{"normal":"node-8","happy":"node-29","sad":"node-15","angry":"node-32","surprised":"node-22","dead":"node-39","confused":"node-46","sleepy":"node-52","nervous":"node-55","shy":"node-63","wink":"node-76","cute":"node-66","wink.left":"node-76","wink.right":"node-79"},"mouth":{"normal":"node-83","happy":"node-84","sad":"node-85","angry":"node-85","surprised":"node-89","dead":"node-90","small":"node-86","worried":"node-87","pout":"node-88","open":"node-93"},"blush":{"off":"node-96","small":"node-96","medium":"node-96","big":"node-96"}},"expressions":{"angry":{"variants":{"eyes":"angry","mouth":"angry","blush":"off"},"motion":{"target":"root","translate":{"x":1,"y":0},"durationMs":150,"repeat":"none"}},"confused":{"variants":{"eyes":"confused","mouth":"normal","blush":"off"},"motion":{"target":"root","translate":{"x":0,"y":0.5},"durationMs":150,"repeat":"none"}},"cute":{"variants":{"eyes":"cute","mouth":"happy","blush":"big"},"motion":{"target":"root","translate":{"x":0,"y":-2.5},"durationMs":150,"repeat":"none"}},"dead":{"variants":{"eyes":"dead","mouth":"dead","blush":"off"}},"happy":{"variants":{"eyes":"happy","mouth":"happy","blush":"medium"},"motion":{"target":"root","translate":{"x":0,"y":-2},"durationMs":150,"repeat":"none"}},"nervous":{"variants":{"eyes":"nervous","mouth":"worried","blush":"off"},"motion":{"target":"root","translate":{"x":-0.5,"y":-1},"durationMs":150,"repeat":"none"}},"normal":{"variants":{"eyes":"normal","mouth":"normal","blush":"off"},"motion":{"target":"root","translate":{"x":0,"y":1},"durationMs":150,"repeat":"none"}},"pleading":{"variants":{"eyes":"cute","mouth":"pout","blush":"medium"},"motion":{"target":"root","translate":{"x":0,"y":-1},"durationMs":150,"repeat":"none"}},"sad":{"variants":{"eyes":"sad","mouth":"sad","blush":"off"},"motion":{"target":"root","translate":{"x":0,"y":2},"durationMs":150,"repeat":"none"}},"shy":{"variants":{"eyes":"shy","mouth":"small","blush":"small"},"motion":{"target":"root","translate":{"x":0,"y":1.5},"durationMs":150,"repeat":"none"}},"sleepy":{"variants":{"eyes":"sleepy","mouth":"small","blush":"off"},"motion":{"target":"root","translate":{"x":0,"y":2},"durationMs":150,"repeat":"none"}},"surprised":{"variants":{"eyes":"surprised","mouth":"surprised","blush":"off"},"motion":{"target":"root","translate":{"x":0,"y":-3},"durationMs":150,"repeat":"none"}},"wink":{"variants":{"mouth":"happy","blush":"small"},"variantChoices":{"eyes":["wink.left","wink.right"]},"motion":{"target":"root","translate":{"x":0,"y":-1.5},"durationMs":150,"repeat":"none"}}},"activities":{"idle":{"motion":{"target":"root","translate":{"y":0.5},"durationMs":2000,"repeat":"yoyo"},"mouseInfluence":1},"listening":{"motion":{"target":"root","rotate":{"x":-0.2},"durationMs":300,"repeat":"yoyo"},"mouseInfluence":0.3},"processing":{"mouseInfluence":0.2},"speaking":{"motion":{"target":"root","translate":{"y":0.5},"durationMs":1500,"repeat":"yoyo"},"mouseInfluence":0,"mouthCycle":[{"durationMs":100,"mouth":"open"},{"durationMs":150,"mouth":"base"},{"durationMs":100,"mouth":"open"},{"durationMs":200,"mouth":"base"}]},"thinking":{"motion":{"target":"root","rotate":{"z":0.1},"durationMs":800,"repeat":"yoyo"},"mouseInfluence":0},"error":{"motion":{"target":"root","rotate":{"x":0.9},"durationMs":600,"repeat":"none"},"mouseInfluence":0.1,"geometry":{"eyes":"dead","mouth":"dead"}}},"defaultPresentation":{"activity":"idle","expression":"sleepy"}}`)},r={document:e.parse(n),render:t};export{r as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as e}from"./error-BTdmRKoB.js";import{n as t,r as n}from"./anthropic-messages-
|
|
1
|
+
import{a as e}from"./error-BTdmRKoB.js";import{n as t,r as n}from"./anthropic-messages-BrTyy87S.js";function r(t){throw new e(`${t} requires Node.js or a Node-compatible runtime`)}var i=3e4,a=`.anthropic-memory-store`,o=class extends e{constructor(e,t){super(e),this.name=`SessionMemoryError`,t!==void 0&&(this.cause=t)}},s=class{constructor(e,t){r(`SessionMemoryStores`)}get roots(){return r(`SessionMemoryStores`)}get readOnlyRoots(){return r(`SessionMemoryStores`)}download(e){return r(`SessionMemoryStores`)}finish(){return r(`SessionMemoryStores`)}syncAll(e){return r(`SessionMemoryStores`)}syncIfDue(){return r(`SessionMemoryStores`)}flushWrites(e){return r(`SessionMemoryStores`)}dispose(){return r(`SessionMemoryStores`)}};function c(e){return r(`setupSkills`)}function l(e,t){return r(`extractSkillArchive`)}function u(e){return r(`betaAgentToolset20260401`)}function d(e,t){return r(`resolvePath`)}var f=class extends e{constructor(e){super(`bash command timed out after ${e}ms`),this.name=`BashTimeoutError`,this.timeoutMs=e}},p=class{constructor(e,t){r(`BashSession`)}get closed(){return r(`BashSession`)}exec(e,t={}){return r(`BashSession`)}close(){r(`BashSession`)}};function m(e){return r(`betaBashTool`)}function h(e){return r(`betaReadTool`)}function g(e){return r(`betaWriteTool`)}function _(e){return r(`betaEditTool`)}function v(e){return r(`betaGlobTool`)}function y(e){return r(`betaGrepTool`)}export{p as BashSession,f as BashTimeoutError,t as DEFAULT_MEMORY_SYNC_INTERVAL_MS,a as MARKER_PATH,i as MEMORY_FLUSH_TIMEOUT_MS,n as MIN_MEMORY_SYNC_INTERVAL_MS,o as SessionMemoryError,s as SessionMemoryStores,u as betaAgentToolset20260401,m as betaBashTool,_ as betaEditTool,v as betaGlobTool,y as betaGrepTool,h as betaReadTool,g as betaWriteTool,l as extractSkillArchive,d as resolvePath,c as setupSkills};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e}from"./error-BTdmRKoB.js";import{n as t,r as n}from"./anthropic-messages-BC32dQ9I.js";function r(t){throw new e(`${t} requires Node.js or a Node-compatible runtime`)}var i=3e4,a=`.anthropic-memory-store`,o=class extends e{constructor(e,t){super(e),this.name=`SessionMemoryError`,t!==void 0&&(this.cause=t)}},s=class{constructor(e,t){r(`SessionMemoryStores`)}get roots(){return r(`SessionMemoryStores`)}get readOnlyRoots(){return r(`SessionMemoryStores`)}download(e){return r(`SessionMemoryStores`)}finish(){return r(`SessionMemoryStores`)}syncAll(e){return r(`SessionMemoryStores`)}syncIfDue(){return r(`SessionMemoryStores`)}flushWrites(e){return r(`SessionMemoryStores`)}dispose(){return r(`SessionMemoryStores`)}};function c(e){return r(`setupSkills`)}function l(e,t){return r(`extractSkillArchive`)}function u(e){return r(`betaAgentToolset20260401`)}function d(e,t){return r(`resolvePath`)}var f=class extends e{constructor(e){super(`bash command timed out after ${e}ms`),this.name=`BashTimeoutError`,this.timeoutMs=e}},p=class{constructor(e,t){r(`BashSession`)}get closed(){return r(`BashSession`)}exec(e,t={}){return r(`BashSession`)}close(){r(`BashSession`)}};function m(e){return r(`betaBashTool`)}function h(e){return r(`betaReadTool`)}function g(e){return r(`betaWriteTool`)}function _(e){return r(`betaEditTool`)}function v(e){return r(`betaGlobTool`)}function y(e){return r(`betaGrepTool`)}export{p as BashSession,f as BashTimeoutError,t as DEFAULT_MEMORY_SYNC_INTERVAL_MS,a as MARKER_PATH,i as MEMORY_FLUSH_TIMEOUT_MS,n as MIN_MEMORY_SYNC_INTERVAL_MS,o as SessionMemoryError,s as SessionMemoryStores,u as betaAgentToolset20260401,m as betaBashTool,_ as betaEditTool,v as betaGlobTool,y as betaGrepTool,h as betaReadTool,g as betaWriteTool,l as extractSkillArchive,d as resolvePath,c as setupSkills};
|
package/dist/assets/{openai-codex-responses-DRHaefx8.js → openai-codex-responses-BJGSPctB.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{d as e,l as t,m as n,o as r,s as i,u as a}from"./preload-helper-DY31Aviq.js";import{t as o}from"./provider-env-CcCbsTJq.js";import{a as s,i as c,n as l,t as u}from"./diagnostics-CxvqSC4Q.js";import{n as d}from"./models-BM_0GHMS.js";import{t as f}from"./headers-FK4rgixo.js";import{h as p,i as m,u as h}from"./transform-messages-iF4VkV1V.js";import{n as g,t as _}from"./error-body-pkrba6pf.js";import{t as v}from"./openai-prompt-cache-DXo9f3w5.js";import{n as y,r as b,t as x}from"./openai-responses-shared-CIO9CkHC.js";import{t as S}from"./abort-signals-joV34wzR.js";import{n as C}from"./runtime-core-CLqMVcjU.js";var w=new Set;function T(e){return w.add(e),()=>{w.delete(e)}}var E={ftp:21,gopher:70,http:80,https:443,ws:80,wss:443};function D(e,t){let n=e.toLowerCase(),r=e.toUpperCase();return t?.[n]||t?.[r]||o(n)||o(r)||``}function O(e){if(e instanceof URL)return e;try{return new URL(e)}catch{return}}function k(e){return e.startsWith(`[`)&&e.endsWith(`]`)?e.slice(1,-1):e}function ee(e){let t=e.trim().toLowerCase();if(!t)return;if(t.startsWith(`[`)){let e=t.indexOf(`]`);if(e!==-1){let n=t.slice(1,e),r=t.slice(e+1);if(r.startsWith(`:`)){let e=Number.parseInt(r.slice(1),10);return{host:n,port:Number.isNaN(e)?0:e}}return{host:n,port:0}}}if(t.includes(`:`)&&t.split(`:`).length>2)return{host:t,port:0};let n=t.lastIndexOf(`:`);if(n!==-1&&n===t.indexOf(`:`)){let e=t.slice(0,n),r=Number.parseInt(t.slice(n+1),10);if(!Number.isNaN(r))return{host:e,port:r}}return{host:t,port:0}}function A(e,t,n){let r=D(`no_proxy`,n).toLowerCase();if(!r)return!0;if(r===`*`)return!1;let i=k(e.toLowerCase());return r.split(/[,\s]/).every(e=>{let n=ee(e);if(!n||n.port&&n.port!==t)return!0;let r=k(n.host);return r.startsWith(`*.`)?r=r.slice(2):(r.startsWith(`.`)||r.startsWith(`*`))&&(r=r.slice(1)),!r||!(i===r||i.endsWith(`.${r}`))})}function j(e,t){let n=O(e);if(!n?.protocol||!n.host)return``;let r=n.protocol.split(`:`,1)[0];if(!A(k(n.hostname||n.host.replace(/:\d*$/,``)),Number.parseInt(n.port,10)||E[r]||0,t))return``;let i=D(`${r}_proxy`,t)||D(`all_proxy`,t);return i&&!i.includes(`://`)&&(i=`${r}://${i}`),i}var M=`Unsupported proxy protocol. SOCKS and PAC proxy URLs are not supported; use an HTTP or HTTPS proxy URL.`;function te(e,t){let n=j(e,t);if(!n)return;let r;try{r=new URL(n)}catch(e){throw Error(`Invalid proxy URL ${JSON.stringify(n)}: ${e instanceof Error?e.message:String(e)}`)}if(r.protocol!==`http:`&&r.protocol!==`https:`)throw Error(`${M} Got ${r.protocol}`);return r}var ne=`https://chatgpt.com/backend-api`,re=`https://api.openai.com/auth`,ie=0,N=1e3,ae=6e4,oe=15e3,se=3,P=new Set([`openai`,`openai-codex`,`opencode`]),ce=1009,le=`websocket_connection_limit_reached`,ue=`previous_response_not_found`,de=new Set([`completed`,`incomplete`,`failed`,`cancelled`,`queued`,`in_progress`]);function F(e){if(e.stopReason===`pending`)throw Error(`Codex stream ended without a stop reason`);if(e.stopReason===`error`||e.stopReason===`aborted`)throw Error(e.errorMessage||`An unknown error occurred`)}function fe(e){return/GoUsageLimitError|FreeUsageLimitError|Monthly usage limit reached|available balance|insufficient_quota|out of budget|quota exceeded|billing/i.test(e)}function pe(e,t){return e===429&&fe(t)?!1:e===429||e===500||e===502||e===503||e===504||/rate.?limit|overloaded|service.?unavailable|upstream.?connect|connection.?refused/i.test(t)}function me(e){let t=e.get(`retry-after-ms`);if(t!==null){let e=Number(t);if(Number.isFinite(e))return Math.max(0,e)}let n=e.get(`retry-after`);if(!n)return;let r=Number(n);if(Number.isFinite(r))return Math.max(0,r*1e3);let i=Date.parse(n);if(!Number.isNaN(i))return Math.max(0,i-Date.now())}var I=class extends Error{};function he(e,t){let n=t?.maxRetryDelayMs??ae;if(n>0&&e>n)throw new I(`Server requested ${Math.ceil(e/1e3)}s retry delay (max: ${Math.ceil(n/1e3)}s)`);return e}function L(e,t){return new Promise((n,r)=>{if(t?.aborted){r(Error(`Request was aborted`));return}let i=setTimeout(n,e);t?.addEventListener(`abort`,()=>{clearTimeout(i),r(Error(`Request was aborted`))})})}function ge(e){if(e!==void 0){if(!Number.isFinite(e)||e<0)throw Error(`Invalid timeoutMs: ${String(e)}`);return Math.floor(e)}}function _e(){return typeof process>`u`||!(process.versions?.node||process.versions?.bun)?null:process.getBuiltinModule?.(`node:zlib`)??null}function ve(e){let t=_e();if(!t||typeof t.zstdCompressSync!=`function`)return null;try{let n=t.zstdCompressSync(e,{params:{[t.constants.ZSTD_c_compressionLevel]:se}});return new Uint8Array(n)}catch{return null}}var ye=(e,t,n)=>{let i=new s,o=a(t,e.compat?.supportsMidConvoSystemMessages);return(async()=>{let t={role:`assistant`,content:[],api:`openai-codex-responses`,provider:e.provider,model:e.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()};try{let a=n?.apiKey;if(!a)throw Error(`No API key for provider: ${e.provider}`);let s=it(a),c=h(r(o.messages),e.compat?.supportsOpenAIGrammarTools??!1),d=n?.cacheRetention===`none`?void 0:n?.sessionId,p=v(d),m=xe(e,o,n,p,c),g=await n?.onPayload?.(m,e);g!==void 0&&(m=g);let _=p||C(),y=at(e.headers,n?.headers,s,a,p),b=ot(e.headers,n?.headers,s,a,_),x=JSON.stringify(m),w=ge(n?.timeoutMs),T=ge(n?.websocketConnectTimeoutMs),E=n?.transport||`auto`,D=!1,O=E!==`sse`&&q(d);if(O&&J(d),E!==`sse`&&!O){let r=!1,a=!1,o=!1;for(;;){r=!1;try{if(await nt(Ee(e.baseUrl),m,b,t,i,e,()=>{r=!0,D||(D=!0,i.push({type:`start`,partial:t}))},w,T,d,s,c,n),n?.signal?.aborted)throw Error(`Request was aborted`);F(t),i.push({type:`done`,reason:t.stopReason,message:t}),i.end();return}catch(e){let i=n?.signal?.aborted,s=!r&&ke(e),c=Ae(e);if(!i&&c&&!o){o=!0;continue}if(!i&&s&&!a){a=!0;continue}if(i||Oe(e)&&!s||(u(t,l(`provider_transport_failure`,e,{configuredTransport:E,...r?{}:{fallbackTransport:`sse`},eventsEmitted:r,phase:r?`after_message_stream_start`:`before_message_stream_start`,requestBytes:new TextEncoder().encode(x).byteLength})),ze(d,e),r))throw e;J(d);break}}}let k=ve(x);k&&y.set(`content-encoding`,`zstd`);let ee=k??x,A,j,M=n?.maxRetries??ie;for(let t=0;t<=M;t++){if(n?.signal?.aborted)throw Error(`Request was aborted`);try{let r=w!==void 0&&w>0?AbortSignal.timeout(w):void 0,i=S([n?.signal,r]);try{A=await(n?.fetch??globalThis.fetch)(Te(e.baseUrl),{method:`POST`,headers:y,body:ee,signal:i.signal})}catch(e){throw r?.aborted&&!n?.signal?.aborted?Error(`Codex SSE response headers timed out after ${w}ms`):e}finally{i.cleanup()}if(await n?.onResponse?.({status:A.status,headers:f(A.headers)},e),A.ok)break;let a=await A.text();if(t<M&&pe(A.status,a)){let e=me(A.headers);await L(e===void 0?N*2**t:he(e,n),n?.signal);continue}let o=await rt(new Response(a,{status:A.status,statusText:A.statusText}));throw Error(o.friendlyMessage||o.message)}catch(e){if(e instanceof Error&&(e.name===`AbortError`||e.message===`Request was aborted`))throw Error(`Request was aborted`);if(j=e instanceof Error?e:Error(String(e)),t<M&&!(j instanceof I)&&!j.message.includes(`usage limit`)){await L(N*2**t,n?.signal);continue}throw j}}if(!A?.ok)throw j??Error(`Failed after retries`);if(!A.body)throw Error(`No response body`);if(D||(D=!0,i.push({type:`start`,partial:t})),await De(A,t,i,e,c,n),n?.signal?.aborted)throw Error(`Request was aborted`);F(t),i.push({type:`done`,reason:t.stopReason,message:t}),i.end()}catch(e){for(let e of t.content)delete e.partialJson,delete e.customInput;t.stopReason=n?.signal?.aborted?`aborted`:`error`,t.errorMessage=_(g(e)),i.push({type:`error`,reason:t.stopReason,error:t}),i.end()}})(),i},be=(e,t,n)=>{let r=n?.apiKey;if(!r)throw Error(`No API key for provider: ${e.provider}`);let i={...m(e,t,n,r),toolChoice:n?.toolChoice},a=n?.reasoning?d(e,n.reasoning):void 0,o=a===`off`?void 0:a;return ye(e,t,{...i,reasoningEffort:o})};function xe(t,a,o,s,c=h(r(a.messages),t.compat?.supportsOpenAIGrammarTools??!1)){let l=t.compat?.supportsStrictMode??!0,u=t.compat?.supportsOpenAIGrammarTools??!1,d=t.compat?.supportsAdditionalTools??!1,f=t.compat?.supportsToolSearch??!1,p=e(a.messages,d||f),m=x(t,a,P,{includeSystemPrompt:!1,grammarToolInputProperties:c,supportsMidConvoSystemMessages:t.compat?.supportsMidConvoSystemMessages??!1,supportsAdditionalTools:d,supportsToolSearch:f,toolOptions:{strict:null,supportsStrictMode:l,supportsOpenAIGrammarTools:u}}),g=i(a.messages),_=g?n(g):``,v={model:t.id,store:!1,stream:!0,instructions:_||`You are a helpful assistant.`,input:m,text:{verbosity:o?.textVerbosity||`low`},include:[`reasoning.encrypted_content`],prompt_cache_key:s,tool_choice:o?.toolChoice??`auto`,parallel_tool_calls:!0};if(o?.temperature!==void 0&&(v.temperature=o.temperature),o?.serviceTier!==void 0&&(v.service_tier=o.serviceTier),p.requestTools.length>0&&(v.tools=y(p.requestTools,{strict:null,supportsStrictMode:l,supportsOpenAIGrammarTools:u})),o?.reasoningEffort!==void 0){let e=o.reasoningEffort===`none`?t.thinkingLevelMap?.off===void 0?`none`:t.thinkingLevelMap.off:t.thinkingLevelMap?.[o.reasoningEffort]??o.reasoningEffort;e!==null&&(v.reasoning={effort:e,summary:o.reasoningSummary??`auto`})}else t.reasoning&&t.thinkingLevelMap?.off!==null&&(v.reasoning={effort:t.thinkingLevelMap?.off??`none`});return v}function Se(e,t){switch(t){case`flex`:return .5;case`priority`:return e.id===`gpt-5.5`?2.5:2;default:return 1}}function Ce(e,t,n){let r=Se(n,t);r!==1&&(e.cost.input*=r,e.cost.output*=r,e.cost.cacheRead*=r,e.cost.cacheWrite*=r,e.cost.total=e.cost.input+e.cost.output+e.cost.cacheRead+e.cost.cacheWrite)}function we(e,t){return e==="default"&&(t===`flex`||t===`priority`)?t:e??t}function Te(e){let t=(e&&e.trim().length>0?e:ne).replace(/\/+$/,``);return t.endsWith(`/codex/responses`)?t:t.endsWith(`/codex`)?`${t}/responses`:`${t}/codex/responses`}function Ee(e){let t=new URL(Te(e));return t.protocol===`https:`&&(t.protocol=`wss:`),t.protocol===`http:`&&(t.protocol=`ws:`),t.toString()}async function De(e,t,n,r,i,a){await b(V(Ne(e,a?.signal),t,r,a?.onProviderStreamEvent),t,n,r,{serviceTier:a?.serviceTier,grammarToolInputProperties:i,resolveServiceTier:we,applyServiceTierPricing:(e,t)=>Ce(e,t,r)})}var R=class extends Error{code;payload;constructor(e,t){super(e),this.name=`CodexApiError`,this.code=t?.code,this.payload=t?.payload,this.cause=t?.cause}},z=class extends Error{payload;constructor(e,t){super(e),this.name=`CodexProtocolError`,this.payload=t?.payload,this.cause=t?.cause}},B=class extends Error{constructor(e){super(c(e)),this.name=`ProviderStreamEventCallbackError`,this.cause=e}};function Oe(e){return e instanceof R||e instanceof z||e instanceof B}function ke(e){return e instanceof R&&e.code===le}function Ae(e){return e instanceof R&&e.code===ue}function je(e){let t=e.error&&typeof e.error==`object`?e.error:void 0;return{code:typeof e.code==`string`?e.code:typeof t?.code==`string`?t.code:void 0,message:typeof e.message==`string`?e.message:typeof t?.message==`string`?t.message:void 0}}async function*V(e,t,n,r){for await(let i of e){try{await r?.(i,n)}catch(e){throw new B(e)}let e=typeof i.type==`string`?i.type:void 0;if(e){if(e===`error`){let{code:e,message:t}=je(i);throw new R(`Codex error: ${t||e||JSON.stringify(i)}`,{code:e,payload:i})}if(e===`response.failed`){let e=i.response,t=e?.error?.code,n=e?.error?.message;throw new R(n||`Codex response failed`,{code:t,payload:i})}if(e===`response.done`||e===`response.completed`||e===`response.incomplete`){let e=i.response;typeof e?.end_turn==`boolean`&&(t.endTurn=e.end_turn);let n=e&&{...e,status:Me(e.status)};yield{...i,type:`response.completed`,response:n};return}yield i}}}function Me(e){if(typeof e==`string`)return de.has(e)?e:void 0}async function*Ne(e,t){if(!e.body)return;let n=e.body.getReader(),r=new TextDecoder,i=``,a=()=>{n.cancel().catch(()=>{})};t?.addEventListener(`abort`,a,{once:!0});try{for(;;){if(t?.aborted)throw Error(`Request was aborted`);let{done:e,value:a}=await n.read();if(t?.aborted)throw Error(`Request was aborted`);i+=e?r.decode():r.decode(a,{stream:!0}),e&&i.trim()&&(i+=`
|
|
1
|
+
import{d as e,l as t,m as n,o as r,s as i,u as a}from"./preload-helper-DY31Aviq.js";import{t as o}from"./provider-env-CcCbsTJq.js";import{a as s,i as c,n as l,t as u}from"./diagnostics-CxvqSC4Q.js";import{n as d}from"./models-BM_0GHMS.js";import{t as f}from"./headers-FK4rgixo.js";import{h as p,i as m,u as h}from"./transform-messages-CgFTI6NF.js";import{n as g,t as _}from"./error-body-pkrba6pf.js";import{t as v}from"./openai-prompt-cache-DXo9f3w5.js";import{n as y,r as b,t as x}from"./openai-responses-shared-DZesysou.js";import{t as S}from"./abort-signals-joV34wzR.js";import{n as C}from"./runtime-core-COw0PWwZ.js";var w=new Set;function T(e){return w.add(e),()=>{w.delete(e)}}var E={ftp:21,gopher:70,http:80,https:443,ws:80,wss:443};function D(e,t){let n=e.toLowerCase(),r=e.toUpperCase();return t?.[n]||t?.[r]||o(n)||o(r)||``}function O(e){if(e instanceof URL)return e;try{return new URL(e)}catch{return}}function k(e){return e.startsWith(`[`)&&e.endsWith(`]`)?e.slice(1,-1):e}function ee(e){let t=e.trim().toLowerCase();if(!t)return;if(t.startsWith(`[`)){let e=t.indexOf(`]`);if(e!==-1){let n=t.slice(1,e),r=t.slice(e+1);if(r.startsWith(`:`)){let e=Number.parseInt(r.slice(1),10);return{host:n,port:Number.isNaN(e)?0:e}}return{host:n,port:0}}}if(t.includes(`:`)&&t.split(`:`).length>2)return{host:t,port:0};let n=t.lastIndexOf(`:`);if(n!==-1&&n===t.indexOf(`:`)){let e=t.slice(0,n),r=Number.parseInt(t.slice(n+1),10);if(!Number.isNaN(r))return{host:e,port:r}}return{host:t,port:0}}function A(e,t,n){let r=D(`no_proxy`,n).toLowerCase();if(!r)return!0;if(r===`*`)return!1;let i=k(e.toLowerCase());return r.split(/[,\s]/).every(e=>{let n=ee(e);if(!n||n.port&&n.port!==t)return!0;let r=k(n.host);return r.startsWith(`*.`)?r=r.slice(2):(r.startsWith(`.`)||r.startsWith(`*`))&&(r=r.slice(1)),!r||!(i===r||i.endsWith(`.${r}`))})}function j(e,t){let n=O(e);if(!n?.protocol||!n.host)return``;let r=n.protocol.split(`:`,1)[0];if(!A(k(n.hostname||n.host.replace(/:\d*$/,``)),Number.parseInt(n.port,10)||E[r]||0,t))return``;let i=D(`${r}_proxy`,t)||D(`all_proxy`,t);return i&&!i.includes(`://`)&&(i=`${r}://${i}`),i}var M=`Unsupported proxy protocol. SOCKS and PAC proxy URLs are not supported; use an HTTP or HTTPS proxy URL.`;function te(e,t){let n=j(e,t);if(!n)return;let r;try{r=new URL(n)}catch(e){throw Error(`Invalid proxy URL ${JSON.stringify(n)}: ${e instanceof Error?e.message:String(e)}`)}if(r.protocol!==`http:`&&r.protocol!==`https:`)throw Error(`${M} Got ${r.protocol}`);return r}var ne=`https://chatgpt.com/backend-api`,re=`https://api.openai.com/auth`,ie=0,N=1e3,ae=6e4,oe=15e3,se=3,P=new Set([`openai`,`openai-codex`,`opencode`]),ce=1009,le=`websocket_connection_limit_reached`,ue=`previous_response_not_found`,de=new Set([`completed`,`incomplete`,`failed`,`cancelled`,`queued`,`in_progress`]);function F(e){if(e.stopReason===`pending`)throw Error(`Codex stream ended without a stop reason`);if(e.stopReason===`error`||e.stopReason===`aborted`)throw Error(e.errorMessage||`An unknown error occurred`)}function fe(e){return/GoUsageLimitError|FreeUsageLimitError|Monthly usage limit reached|available balance|insufficient_quota|out of budget|quota exceeded|billing/i.test(e)}function pe(e,t){return e===429&&fe(t)?!1:e===429||e===500||e===502||e===503||e===504||/rate.?limit|overloaded|service.?unavailable|upstream.?connect|connection.?refused/i.test(t)}function me(e){let t=e.get(`retry-after-ms`);if(t!==null){let e=Number(t);if(Number.isFinite(e))return Math.max(0,e)}let n=e.get(`retry-after`);if(!n)return;let r=Number(n);if(Number.isFinite(r))return Math.max(0,r*1e3);let i=Date.parse(n);if(!Number.isNaN(i))return Math.max(0,i-Date.now())}var I=class extends Error{};function he(e,t){let n=t?.maxRetryDelayMs??ae;if(n>0&&e>n)throw new I(`Server requested ${Math.ceil(e/1e3)}s retry delay (max: ${Math.ceil(n/1e3)}s)`);return e}function L(e,t){return new Promise((n,r)=>{if(t?.aborted){r(Error(`Request was aborted`));return}let i=setTimeout(n,e);t?.addEventListener(`abort`,()=>{clearTimeout(i),r(Error(`Request was aborted`))})})}function ge(e){if(e!==void 0){if(!Number.isFinite(e)||e<0)throw Error(`Invalid timeoutMs: ${String(e)}`);return Math.floor(e)}}function _e(){return typeof process>`u`||!(process.versions?.node||process.versions?.bun)?null:process.getBuiltinModule?.(`node:zlib`)??null}function ve(e){let t=_e();if(!t||typeof t.zstdCompressSync!=`function`)return null;try{let n=t.zstdCompressSync(e,{params:{[t.constants.ZSTD_c_compressionLevel]:se}});return new Uint8Array(n)}catch{return null}}var ye=(e,t,n)=>{let i=new s,o=a(t,e.compat?.supportsMidConvoSystemMessages);return(async()=>{let t={role:`assistant`,content:[],api:`openai-codex-responses`,provider:e.provider,model:e.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()};try{let a=n?.apiKey;if(!a)throw Error(`No API key for provider: ${e.provider}`);let s=it(a),c=h(r(o.messages),e.compat?.supportsOpenAIGrammarTools??!1),d=n?.cacheRetention===`none`?void 0:n?.sessionId,p=v(d),m=xe(e,o,n,p,c),g=await n?.onPayload?.(m,e);g!==void 0&&(m=g);let _=p||C(),y=at(e.headers,n?.headers,s,a,p),b=ot(e.headers,n?.headers,s,a,_),x=JSON.stringify(m),w=ge(n?.timeoutMs),T=ge(n?.websocketConnectTimeoutMs),E=n?.transport||`auto`,D=!1,O=E!==`sse`&&q(d);if(O&&J(d),E!==`sse`&&!O){let r=!1,a=!1,o=!1;for(;;){r=!1;try{if(await nt(Ee(e.baseUrl),m,b,t,i,e,()=>{r=!0,D||(D=!0,i.push({type:`start`,partial:t}))},w,T,d,s,c,n),n?.signal?.aborted)throw Error(`Request was aborted`);F(t),i.push({type:`done`,reason:t.stopReason,message:t}),i.end();return}catch(e){let i=n?.signal?.aborted,s=!r&&ke(e),c=Ae(e);if(!i&&c&&!o){o=!0;continue}if(!i&&s&&!a){a=!0;continue}if(i||Oe(e)&&!s||(u(t,l(`provider_transport_failure`,e,{configuredTransport:E,...r?{}:{fallbackTransport:`sse`},eventsEmitted:r,phase:r?`after_message_stream_start`:`before_message_stream_start`,requestBytes:new TextEncoder().encode(x).byteLength})),ze(d,e),r))throw e;J(d);break}}}let k=ve(x);k&&y.set(`content-encoding`,`zstd`);let ee=k??x,A,j,M=n?.maxRetries??ie;for(let t=0;t<=M;t++){if(n?.signal?.aborted)throw Error(`Request was aborted`);try{let r=w!==void 0&&w>0?AbortSignal.timeout(w):void 0,i=S([n?.signal,r]);try{A=await(n?.fetch??globalThis.fetch)(Te(e.baseUrl),{method:`POST`,headers:y,body:ee,signal:i.signal})}catch(e){throw r?.aborted&&!n?.signal?.aborted?Error(`Codex SSE response headers timed out after ${w}ms`):e}finally{i.cleanup()}if(await n?.onResponse?.({status:A.status,headers:f(A.headers)},e),A.ok)break;let a=await A.text();if(t<M&&pe(A.status,a)){let e=me(A.headers);await L(e===void 0?N*2**t:he(e,n),n?.signal);continue}let o=await rt(new Response(a,{status:A.status,statusText:A.statusText}));throw Error(o.friendlyMessage||o.message)}catch(e){if(e instanceof Error&&(e.name===`AbortError`||e.message===`Request was aborted`))throw Error(`Request was aborted`);if(j=e instanceof Error?e:Error(String(e)),t<M&&!(j instanceof I)&&!j.message.includes(`usage limit`)){await L(N*2**t,n?.signal);continue}throw j}}if(!A?.ok)throw j??Error(`Failed after retries`);if(!A.body)throw Error(`No response body`);if(D||(D=!0,i.push({type:`start`,partial:t})),await De(A,t,i,e,c,n),n?.signal?.aborted)throw Error(`Request was aborted`);F(t),i.push({type:`done`,reason:t.stopReason,message:t}),i.end()}catch(e){for(let e of t.content)delete e.partialJson,delete e.customInput;t.stopReason=n?.signal?.aborted?`aborted`:`error`,t.errorMessage=_(g(e)),i.push({type:`error`,reason:t.stopReason,error:t}),i.end()}})(),i},be=(e,t,n)=>{let r=n?.apiKey;if(!r)throw Error(`No API key for provider: ${e.provider}`);let i={...m(e,t,n,r),toolChoice:n?.toolChoice},a=n?.reasoning?d(e,n.reasoning):void 0,o=a===`off`?void 0:a;return ye(e,t,{...i,reasoningEffort:o})};function xe(t,a,o,s,c=h(r(a.messages),t.compat?.supportsOpenAIGrammarTools??!1)){let l=t.compat?.supportsStrictMode??!0,u=t.compat?.supportsOpenAIGrammarTools??!1,d=t.compat?.supportsAdditionalTools??!1,f=t.compat?.supportsToolSearch??!1,p=e(a.messages,d||f),m=x(t,a,P,{includeSystemPrompt:!1,grammarToolInputProperties:c,supportsMidConvoSystemMessages:t.compat?.supportsMidConvoSystemMessages??!1,supportsAdditionalTools:d,supportsToolSearch:f,toolOptions:{strict:null,supportsStrictMode:l,supportsOpenAIGrammarTools:u}}),g=i(a.messages),_=g?n(g):``,v={model:t.id,store:!1,stream:!0,instructions:_||`You are a helpful assistant.`,input:m,text:{verbosity:o?.textVerbosity||`low`},include:[`reasoning.encrypted_content`],prompt_cache_key:s,tool_choice:o?.toolChoice??`auto`,parallel_tool_calls:!0};if(o?.temperature!==void 0&&(v.temperature=o.temperature),o?.serviceTier!==void 0&&(v.service_tier=o.serviceTier),p.requestTools.length>0&&(v.tools=y(p.requestTools,{strict:null,supportsStrictMode:l,supportsOpenAIGrammarTools:u})),o?.reasoningEffort!==void 0){let e=o.reasoningEffort===`none`?t.thinkingLevelMap?.off===void 0?`none`:t.thinkingLevelMap.off:t.thinkingLevelMap?.[o.reasoningEffort]??o.reasoningEffort;e!==null&&(v.reasoning={effort:e,summary:o.reasoningSummary??`auto`})}else t.reasoning&&t.thinkingLevelMap?.off!==null&&(v.reasoning={effort:t.thinkingLevelMap?.off??`none`});return v}function Se(e,t){switch(t){case`flex`:return .5;case`priority`:return e.id===`gpt-5.5`?2.5:2;default:return 1}}function Ce(e,t,n){let r=Se(n,t);r!==1&&(e.cost.input*=r,e.cost.output*=r,e.cost.cacheRead*=r,e.cost.cacheWrite*=r,e.cost.total=e.cost.input+e.cost.output+e.cost.cacheRead+e.cost.cacheWrite)}function we(e,t){return e==="default"&&(t===`flex`||t===`priority`)?t:e??t}function Te(e){let t=(e&&e.trim().length>0?e:ne).replace(/\/+$/,``);return t.endsWith(`/codex/responses`)?t:t.endsWith(`/codex`)?`${t}/responses`:`${t}/codex/responses`}function Ee(e){let t=new URL(Te(e));return t.protocol===`https:`&&(t.protocol=`wss:`),t.protocol===`http:`&&(t.protocol=`ws:`),t.toString()}async function De(e,t,n,r,i,a){await b(V(Ne(e,a?.signal),t,r,a?.onProviderStreamEvent),t,n,r,{serviceTier:a?.serviceTier,grammarToolInputProperties:i,resolveServiceTier:we,applyServiceTierPricing:(e,t)=>Ce(e,t,r)})}var R=class extends Error{code;payload;constructor(e,t){super(e),this.name=`CodexApiError`,this.code=t?.code,this.payload=t?.payload,this.cause=t?.cause}},z=class extends Error{payload;constructor(e,t){super(e),this.name=`CodexProtocolError`,this.payload=t?.payload,this.cause=t?.cause}},B=class extends Error{constructor(e){super(c(e)),this.name=`ProviderStreamEventCallbackError`,this.cause=e}};function Oe(e){return e instanceof R||e instanceof z||e instanceof B}function ke(e){return e instanceof R&&e.code===le}function Ae(e){return e instanceof R&&e.code===ue}function je(e){let t=e.error&&typeof e.error==`object`?e.error:void 0;return{code:typeof e.code==`string`?e.code:typeof t?.code==`string`?t.code:void 0,message:typeof e.message==`string`?e.message:typeof t?.message==`string`?t.message:void 0}}async function*V(e,t,n,r){for await(let i of e){try{await r?.(i,n)}catch(e){throw new B(e)}let e=typeof i.type==`string`?i.type:void 0;if(e){if(e===`error`){let{code:e,message:t}=je(i);throw new R(`Codex error: ${t||e||JSON.stringify(i)}`,{code:e,payload:i})}if(e===`response.failed`){let e=i.response,t=e?.error?.code,n=e?.error?.message;throw new R(n||`Codex response failed`,{code:t,payload:i})}if(e===`response.done`||e===`response.completed`||e===`response.incomplete`){let e=i.response;typeof e?.end_turn==`boolean`&&(t.endTurn=e.end_turn);let n=e&&{...e,status:Me(e.status)};yield{...i,type:`response.completed`,response:n};return}yield i}}}function Me(e){if(typeof e==`string`)return de.has(e)?e:void 0}async function*Ne(e,t){if(!e.body)return;let n=e.body.getReader(),r=new TextDecoder,i=``,a=()=>{n.cancel().catch(()=>{})};t?.addEventListener(`abort`,a,{once:!0});try{for(;;){if(t?.aborted)throw Error(`Request was aborted`);let{done:e,value:a}=await n.read();if(t?.aborted)throw Error(`Request was aborted`);i+=e?r.decode():r.decode(a,{stream:!0}),e&&i.trim()&&(i+=`
|
|
2
2
|
|
|
3
3
|
`);let o=i.indexOf(`
|
|
4
4
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import{d as e,l as t,m as n,o as r,s as i,u as a}from"./preload-helper-DY31Aviq.js";import{t as o}from"./provider-env-CcCbsTJq.js";import{a as s,i as c,n as l,t as u}from"./diagnostics-CxvqSC4Q.js";import{n as d}from"./models-BM_0GHMS.js";import{t as f}from"./headers-FK4rgixo.js";import{h as p,i as m,u as h}from"./transform-messages-utWG7TCG.js";import{n as g,t as _}from"./error-body-pkrba6pf.js";import{t as v}from"./openai-prompt-cache-DXo9f3w5.js";import{n as y,r as b,t as x}from"./openai-responses-shared-DaKV5GAS.js";import{t as S}from"./abort-signals-joV34wzR.js";import{n as C}from"./runtime-core-DOL1texL.js";var w=new Set;function T(e){return w.add(e),()=>{w.delete(e)}}var E={ftp:21,gopher:70,http:80,https:443,ws:80,wss:443};function D(e,t){let n=e.toLowerCase(),r=e.toUpperCase();return t?.[n]||t?.[r]||o(n)||o(r)||``}function O(e){if(e instanceof URL)return e;try{return new URL(e)}catch{return}}function k(e){return e.startsWith(`[`)&&e.endsWith(`]`)?e.slice(1,-1):e}function ee(e){let t=e.trim().toLowerCase();if(!t)return;if(t.startsWith(`[`)){let e=t.indexOf(`]`);if(e!==-1){let n=t.slice(1,e),r=t.slice(e+1);if(r.startsWith(`:`)){let e=Number.parseInt(r.slice(1),10);return{host:n,port:Number.isNaN(e)?0:e}}return{host:n,port:0}}}if(t.includes(`:`)&&t.split(`:`).length>2)return{host:t,port:0};let n=t.lastIndexOf(`:`);if(n!==-1&&n===t.indexOf(`:`)){let e=t.slice(0,n),r=Number.parseInt(t.slice(n+1),10);if(!Number.isNaN(r))return{host:e,port:r}}return{host:t,port:0}}function A(e,t,n){let r=D(`no_proxy`,n).toLowerCase();if(!r)return!0;if(r===`*`)return!1;let i=k(e.toLowerCase());return r.split(/[,\s]/).every(e=>{let n=ee(e);if(!n||n.port&&n.port!==t)return!0;let r=k(n.host);return r.startsWith(`*.`)?r=r.slice(2):(r.startsWith(`.`)||r.startsWith(`*`))&&(r=r.slice(1)),!r||!(i===r||i.endsWith(`.${r}`))})}function j(e,t){let n=O(e);if(!n?.protocol||!n.host)return``;let r=n.protocol.split(`:`,1)[0];if(!A(k(n.hostname||n.host.replace(/:\d*$/,``)),Number.parseInt(n.port,10)||E[r]||0,t))return``;let i=D(`${r}_proxy`,t)||D(`all_proxy`,t);return i&&!i.includes(`://`)&&(i=`${r}://${i}`),i}var M=`Unsupported proxy protocol. SOCKS and PAC proxy URLs are not supported; use an HTTP or HTTPS proxy URL.`;function te(e,t){let n=j(e,t);if(!n)return;let r;try{r=new URL(n)}catch(e){throw Error(`Invalid proxy URL ${JSON.stringify(n)}: ${e instanceof Error?e.message:String(e)}`)}if(r.protocol!==`http:`&&r.protocol!==`https:`)throw Error(`${M} Got ${r.protocol}`);return r}var ne=`https://chatgpt.com/backend-api`,re=`https://api.openai.com/auth`,ie=0,N=1e3,ae=6e4,oe=15e3,se=3,P=new Set([`openai`,`openai-codex`,`opencode`]),ce=1009,le=`websocket_connection_limit_reached`,ue=`previous_response_not_found`,de=new Set([`completed`,`incomplete`,`failed`,`cancelled`,`queued`,`in_progress`]);function F(e){if(e.stopReason===`pending`)throw Error(`Codex stream ended without a stop reason`);if(e.stopReason===`error`||e.stopReason===`aborted`)throw Error(e.errorMessage||`An unknown error occurred`)}function fe(e){return/GoUsageLimitError|FreeUsageLimitError|Monthly usage limit reached|available balance|insufficient_quota|out of budget|quota exceeded|billing/i.test(e)}function pe(e,t){return e===429&&fe(t)?!1:e===429||e===500||e===502||e===503||e===504||/rate.?limit|overloaded|service.?unavailable|upstream.?connect|connection.?refused/i.test(t)}function me(e){let t=e.get(`retry-after-ms`);if(t!==null){let e=Number(t);if(Number.isFinite(e))return Math.max(0,e)}let n=e.get(`retry-after`);if(!n)return;let r=Number(n);if(Number.isFinite(r))return Math.max(0,r*1e3);let i=Date.parse(n);if(!Number.isNaN(i))return Math.max(0,i-Date.now())}var I=class extends Error{};function he(e,t){let n=t?.maxRetryDelayMs??ae;if(n>0&&e>n)throw new I(`Server requested ${Math.ceil(e/1e3)}s retry delay (max: ${Math.ceil(n/1e3)}s)`);return e}function L(e,t){return new Promise((n,r)=>{if(t?.aborted){r(Error(`Request was aborted`));return}let i=setTimeout(n,e);t?.addEventListener(`abort`,()=>{clearTimeout(i),r(Error(`Request was aborted`))})})}function ge(e){if(e!==void 0){if(!Number.isFinite(e)||e<0)throw Error(`Invalid timeoutMs: ${String(e)}`);return Math.floor(e)}}function _e(){return typeof process>`u`||!(process.versions?.node||process.versions?.bun)?null:process.getBuiltinModule?.(`node:zlib`)??null}function ve(e){let t=_e();if(!t||typeof t.zstdCompressSync!=`function`)return null;try{let n=t.zstdCompressSync(e,{params:{[t.constants.ZSTD_c_compressionLevel]:se}});return new Uint8Array(n)}catch{return null}}var ye=(e,t,n)=>{let i=new s,o=a(t,e.compat?.supportsMidConvoSystemMessages);return(async()=>{let t={role:`assistant`,content:[],api:`openai-codex-responses`,provider:e.provider,model:e.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()};try{let a=n?.apiKey;if(!a)throw Error(`No API key for provider: ${e.provider}`);let s=it(a),c=h(r(o.messages),e.compat?.supportsOpenAIGrammarTools??!1),d=n?.cacheRetention===`none`?void 0:n?.sessionId,p=v(d),m=xe(e,o,n,p,c),g=await n?.onPayload?.(m,e);g!==void 0&&(m=g);let _=p||C(),y=at(e.headers,n?.headers,s,a,p),b=ot(e.headers,n?.headers,s,a,_),x=JSON.stringify(m),w=ge(n?.timeoutMs),T=ge(n?.websocketConnectTimeoutMs),E=n?.transport||`auto`,D=!1,O=E!==`sse`&&q(d);if(O&&J(d),E!==`sse`&&!O){let r=!1,a=!1,o=!1;for(;;){r=!1;try{if(await nt(Ee(e.baseUrl),m,b,t,i,e,()=>{r=!0,D||(D=!0,i.push({type:`start`,partial:t}))},w,T,d,s,c,n),n?.signal?.aborted)throw Error(`Request was aborted`);F(t),i.push({type:`done`,reason:t.stopReason,message:t}),i.end();return}catch(e){let i=n?.signal?.aborted,s=!r&&ke(e),c=Ae(e);if(!i&&c&&!o){o=!0;continue}if(!i&&s&&!a){a=!0;continue}if(i||Oe(e)&&!s||(u(t,l(`provider_transport_failure`,e,{configuredTransport:E,...r?{}:{fallbackTransport:`sse`},eventsEmitted:r,phase:r?`after_message_stream_start`:`before_message_stream_start`,requestBytes:new TextEncoder().encode(x).byteLength})),ze(d,e),r))throw e;J(d);break}}}let k=ve(x);k&&y.set(`content-encoding`,`zstd`);let ee=k??x,A,j,M=n?.maxRetries??ie;for(let t=0;t<=M;t++){if(n?.signal?.aborted)throw Error(`Request was aborted`);try{let r=w!==void 0&&w>0?AbortSignal.timeout(w):void 0,i=S([n?.signal,r]);try{A=await(n?.fetch??globalThis.fetch)(Te(e.baseUrl),{method:`POST`,headers:y,body:ee,signal:i.signal})}catch(e){throw r?.aborted&&!n?.signal?.aborted?Error(`Codex SSE response headers timed out after ${w}ms`):e}finally{i.cleanup()}if(await n?.onResponse?.({status:A.status,headers:f(A.headers)},e),A.ok)break;let a=await A.text();if(t<M&&pe(A.status,a)){let e=me(A.headers);await L(e===void 0?N*2**t:he(e,n),n?.signal);continue}let o=await rt(new Response(a,{status:A.status,statusText:A.statusText}));throw Error(o.friendlyMessage||o.message)}catch(e){if(e instanceof Error&&(e.name===`AbortError`||e.message===`Request was aborted`))throw Error(`Request was aborted`);if(j=e instanceof Error?e:Error(String(e)),t<M&&!(j instanceof I)&&!j.message.includes(`usage limit`)){await L(N*2**t,n?.signal);continue}throw j}}if(!A?.ok)throw j??Error(`Failed after retries`);if(!A.body)throw Error(`No response body`);if(D||(D=!0,i.push({type:`start`,partial:t})),await De(A,t,i,e,c,n),n?.signal?.aborted)throw Error(`Request was aborted`);F(t),i.push({type:`done`,reason:t.stopReason,message:t}),i.end()}catch(e){for(let e of t.content)delete e.partialJson,delete e.customInput;t.stopReason=n?.signal?.aborted?`aborted`:`error`,t.errorMessage=_(g(e)),i.push({type:`error`,reason:t.stopReason,error:t}),i.end()}})(),i},be=(e,t,n)=>{let r=n?.apiKey;if(!r)throw Error(`No API key for provider: ${e.provider}`);let i={...m(e,t,n,r),toolChoice:n?.toolChoice},a=n?.reasoning?d(e,n.reasoning):void 0,o=a===`off`?void 0:a;return ye(e,t,{...i,reasoningEffort:o})};function xe(t,a,o,s,c=h(r(a.messages),t.compat?.supportsOpenAIGrammarTools??!1)){let l=t.compat?.supportsStrictMode??!0,u=t.compat?.supportsOpenAIGrammarTools??!1,d=t.compat?.supportsAdditionalTools??!1,f=t.compat?.supportsToolSearch??!1,p=e(a.messages,d||f),m=x(t,a,P,{includeSystemPrompt:!1,grammarToolInputProperties:c,supportsMidConvoSystemMessages:t.compat?.supportsMidConvoSystemMessages??!1,supportsAdditionalTools:d,supportsToolSearch:f,toolOptions:{strict:null,supportsStrictMode:l,supportsOpenAIGrammarTools:u}}),g=i(a.messages),_=g?n(g):``,v={model:t.id,store:!1,stream:!0,instructions:_||`You are a helpful assistant.`,input:m,text:{verbosity:o?.textVerbosity||`low`},include:[`reasoning.encrypted_content`],prompt_cache_key:s,tool_choice:o?.toolChoice??`auto`,parallel_tool_calls:!0};if(o?.temperature!==void 0&&(v.temperature=o.temperature),o?.serviceTier!==void 0&&(v.service_tier=o.serviceTier),p.requestTools.length>0&&(v.tools=y(p.requestTools,{strict:null,supportsStrictMode:l,supportsOpenAIGrammarTools:u})),o?.reasoningEffort!==void 0){let e=o.reasoningEffort===`none`?t.thinkingLevelMap?.off===void 0?`none`:t.thinkingLevelMap.off:t.thinkingLevelMap?.[o.reasoningEffort]??o.reasoningEffort;e!==null&&(v.reasoning={effort:e,summary:o.reasoningSummary??`auto`})}else t.reasoning&&t.thinkingLevelMap?.off!==null&&(v.reasoning={effort:t.thinkingLevelMap?.off??`none`});return v}function Se(e,t){switch(t){case`flex`:return .5;case`priority`:return e.id===`gpt-5.5`?2.5:2;default:return 1}}function Ce(e,t,n){let r=Se(n,t);r!==1&&(e.cost.input*=r,e.cost.output*=r,e.cost.cacheRead*=r,e.cost.cacheWrite*=r,e.cost.total=e.cost.input+e.cost.output+e.cost.cacheRead+e.cost.cacheWrite)}function we(e,t){return e==="default"&&(t===`flex`||t===`priority`)?t:e??t}function Te(e){let t=(e&&e.trim().length>0?e:ne).replace(/\/+$/,``);return t.endsWith(`/codex/responses`)?t:t.endsWith(`/codex`)?`${t}/responses`:`${t}/codex/responses`}function Ee(e){let t=new URL(Te(e));return t.protocol===`https:`&&(t.protocol=`wss:`),t.protocol===`http:`&&(t.protocol=`ws:`),t.toString()}async function De(e,t,n,r,i,a){await b(V(Ne(e,a?.signal),t,r,a?.onProviderStreamEvent),t,n,r,{serviceTier:a?.serviceTier,grammarToolInputProperties:i,resolveServiceTier:we,applyServiceTierPricing:(e,t)=>Ce(e,t,r)})}var R=class extends Error{code;payload;constructor(e,t){super(e),this.name=`CodexApiError`,this.code=t?.code,this.payload=t?.payload,this.cause=t?.cause}},z=class extends Error{payload;constructor(e,t){super(e),this.name=`CodexProtocolError`,this.payload=t?.payload,this.cause=t?.cause}},B=class extends Error{constructor(e){super(c(e)),this.name=`ProviderStreamEventCallbackError`,this.cause=e}};function Oe(e){return e instanceof R||e instanceof z||e instanceof B}function ke(e){return e instanceof R&&e.code===le}function Ae(e){return e instanceof R&&e.code===ue}function je(e){let t=e.error&&typeof e.error==`object`?e.error:void 0;return{code:typeof e.code==`string`?e.code:typeof t?.code==`string`?t.code:void 0,message:typeof e.message==`string`?e.message:typeof t?.message==`string`?t.message:void 0}}async function*V(e,t,n,r){for await(let i of e){try{await r?.(i,n)}catch(e){throw new B(e)}let e=typeof i.type==`string`?i.type:void 0;if(e){if(e===`error`){let{code:e,message:t}=je(i);throw new R(`Codex error: ${t||e||JSON.stringify(i)}`,{code:e,payload:i})}if(e===`response.failed`){let e=i.response,t=e?.error?.code,n=e?.error?.message;throw new R(n||`Codex response failed`,{code:t,payload:i})}if(e===`response.done`||e===`response.completed`||e===`response.incomplete`){let e=i.response;typeof e?.end_turn==`boolean`&&(t.endTurn=e.end_turn);let n=e&&{...e,status:Me(e.status)};yield{...i,type:`response.completed`,response:n};return}yield i}}}function Me(e){if(typeof e==`string`)return de.has(e)?e:void 0}async function*Ne(e,t){if(!e.body)return;let n=e.body.getReader(),r=new TextDecoder,i=``,a=()=>{n.cancel().catch(()=>{})};t?.addEventListener(`abort`,a,{once:!0});try{for(;;){if(t?.aborted)throw Error(`Request was aborted`);let{done:e,value:a}=await n.read();if(t?.aborted)throw Error(`Request was aborted`);i+=e?r.decode():r.decode(a,{stream:!0}),e&&i.trim()&&(i+=`
|
|
2
|
+
|
|
3
|
+
`);let o=i.indexOf(`
|
|
4
|
+
|
|
5
|
+
`);for(;o!==-1;){let e=i.slice(0,o);i=i.slice(o+2);let t=e.split(`
|
|
6
|
+
`).filter(e=>e.startsWith(`data:`)).map(e=>e.slice(5).trim());if(t.length>0){let e=t.join(`
|
|
7
|
+
`).trim();if(e&&e!==`[DONE]`)try{yield JSON.parse(e)}catch(t){throw new z(`Invalid Codex SSE JSON: ${c(t)}`,{cause:t,payload:e})}}o=i.indexOf(`
|
|
8
|
+
|
|
9
|
+
`)}if(e)break}}finally{t?.removeEventListener(`abort`,a);try{await n.cancel()}catch{}try{n.releaseLock()}catch{}}}var Pe=`responses_websockets=2026-02-06`,Fe=3e5,Ie=33e5,H=new Map,U=new Map,W=new Set;function G(e){let t=U.get(e);return t||(t={requests:0,connectionsCreated:0,connectionsReused:0,cachedContextRequests:0,storeTrueRequests:0,fullContextRequests:0,deltaRequests:0,lastInputItems:0,websocketFailures:0,sseFallbacks:0},U.set(e,t)),t}function Le(e){let t=U.get(e);return t?{...t}:void 0}function Re(e){if(e){U.delete(e),W.delete(e);return}U.clear(),W.clear()}function K(e){let t=e=>{e.idleTimer&&clearTimeout(e.idleTimer),Z(e.socket,1e3,`debug_close`)};if(e){for(let n of H.get(e)?.values()??[])t(n);H.delete(e);return}for(let e of H.values())for(let n of e.values())t(n);H.clear()}T(K);function q(e){return e?W.has(e):!1}function J(e){if(!e)return;let t=G(e);t.sseFallbacks++,t.websocketFallbackActive=q(e)}function ze(e,t){if(!e)return;W.add(e);let n=G(e);n.websocketFailures++,n.lastWebSocketError=c(t),n.websocketFallbackActive=!0}var Y=null;async function Be(e){if(!e&&Y)return Y;if(typeof process<`u`&&process.versions?.bun){let t=class extends WebSocket{constructor(t,n){let r={};r=Array.isArray(n)||typeof n==`string`?{protocols:n}:{...n};let i=te(t.toString().replace(/^wss:/,`https:`).replace(/^ws:/,`http:`),e);super(t,{...r,...i?{proxy:i.toString()}:{}})}};return e||(Y=t),t}let t=globalThis.WebSocket;return typeof t==`function`?t:null}var Ve=class extends Error{code;reason;wasClean;constructor(e,t){super(e),this.name=`WebSocketCloseError`,this.code=t?.code,this.reason=t?.reason,this.wasClean=t?.wasClean}};function He(e){let t=e.readyState;return typeof t==`number`?t:void 0}function X(e){let t=He(e);return t===void 0||t===1}function Ue(e){return Date.now()-e.createdAt>=Ie}function Z(e,t=1e3,n=`done`){try{e.close(t,n)}catch{}}function We(e,t,n){n.idleTimer&&clearTimeout(n.idleTimer),n.idleTimer=setTimeout(()=>{if(n.busy)return;Z(n.socket,1e3,`idle_timeout`);let r=H.get(e);r?.get(t)===n&&r.delete(t),r?.size===0&&H.delete(e)},Fe)}async function Q(e,t,n,r=oe,i){let a=await Be(i);if(!a)throw Error(`WebSocket transport is not available in this runtime`);let o=f(t);return delete o[`OpenAI-Beta`],new Promise((t,i)=>{let s=!1,c,l;try{l=new a(e,{headers:o})}catch(e){i(e instanceof Error?e:Error(String(e)));return}let u=()=>{c&&=(clearTimeout(c),void 0),l.removeEventListener(`open`,f),l.removeEventListener(`error`,p),l.removeEventListener(`close`,m),n?.removeEventListener(`abort`,h)},d=(e,t)=>{s||(s=!0,u(),t&&Z(l,1e3,t),i(e))},f=()=>{s||(s=!0,u(),t(l))},p=e=>{d(Ke(e))},m=e=>{d(qe(e))},h=()=>{d(Error(`Request was aborted`),`aborted`)};l.addEventListener(`open`,f),l.addEventListener(`error`,p),l.addEventListener(`close`,m),n?.addEventListener(`abort`,h),r>0&&(c=setTimeout(()=>{d(Error(`WebSocket connect timeout after ${r}ms`),`connect_timeout`)},r)),n?.aborted&&h()})}async function Ge(e,t,n,r,i,a,o){if(!n){let n=await Q(e,t,i,a,o);return{socket:n,reused:!1,release:()=>Z(n)}}let s=H.get(n),c=s?.get(r);if(c){if(c.idleTimer&&=(clearTimeout(c.idleTimer),void 0),!c.busy&&Ue(c))Z(c.socket,1e3,`connection_age_limit`),s?.delete(r),s?.size===0&&H.delete(n);else if(!c.busy&&X(c.socket))return c.busy=!0,{socket:c.socket,entry:c,reused:!0,release:({keep:e}={})=>{if(!e||!X(c.socket)){Z(c.socket);let e=H.get(n);e?.get(r)===c&&e.delete(r),e?.size===0&&H.delete(n);return}c.busy=!1,We(n,r,c)}};if(c.busy){let n=await Q(e,t,i,a,o);return{socket:n,reused:!1,release:()=>{Z(n)}}}X(c.socket)||(Z(c.socket),s?.delete(r),s?.size===0&&H.delete(n))}let l=await Q(e,t,i,a,o),u={socket:l,busy:!0,createdAt:Date.now()};return s=H.get(n),s||(s=new Map,H.set(n,s)),s.set(r,u),{socket:l,entry:u,reused:!1,release:({keep:e}={})=>{if(!e||!X(u.socket)){Z(u.socket),u.idleTimer&&clearTimeout(u.idleTimer);let e=H.get(n);e?.get(r)===u&&e.delete(r),e?.size===0&&H.delete(n);return}u.busy=!1,We(n,r,u)}}}function Ke(e){if(e&&typeof e==`object`){let t=`message`in e?e.message:void 0;if(typeof t==`string`&&t.length>0)return Error(t);let n=`error`in e?e.error:void 0;if(n instanceof Error&&n.message.length>0)return n;if(n&&typeof n==`object`&&`message`in n){let e=n.message;if(typeof e==`string`&&e.length>0)return Error(e)}}return Error(`WebSocket error`)}function qe(e){if(e&&typeof e==`object`){let t=`code`in e?e.code:void 0,n=`reason`in e?e.reason:void 0,r=`wasClean`in e?e.wasClean:void 0,i=typeof t==`number`?` ${t}`:``,a=typeof n==`string`&&n.length>0?` ${n}`:``;return!a&&t===ce&&(a=` message too big`),new Ve(`WebSocket closed${i}${a}`.trim(),{code:typeof t==`number`?t:void 0,reason:typeof n==`string`&&n.length>0?n:void 0,wasClean:typeof r==`boolean`?r:void 0})}return Error(`WebSocket closed`)}async function Je(e){if(typeof e==`string`)return e;if(e instanceof ArrayBuffer)return new TextDecoder().decode(new Uint8Array(e));if(ArrayBuffer.isView(e)){let t=e;return new TextDecoder().decode(new Uint8Array(t.buffer,t.byteOffset,t.byteLength))}if(e&&typeof e==`object`&&`arrayBuffer`in e){let t=await e.arrayBuffer();return new TextDecoder().decode(new Uint8Array(t))}return null}async function*Ye(e,t,n){let r=[],i=null,a=!1,o=null,s=!1,l=()=>{if(!i)return;let e=i;i=null,e()},u=e=>{(async()=>{let t=null;try{if(!e||typeof e!=`object`||!(`data`in e)||(t=await Je(e.data),!t))return;let n=JSON.parse(t),i=typeof n.type==`string`?n.type:``;(i===`response.completed`||i===`response.done`||i===`response.incomplete`)&&(s=!0,a=!0),r.push(n),l()}catch(e){o=new z(`Invalid Codex WebSocket JSON: ${c(e)}`,{cause:e,payload:t}),a=!0,l()}})()},d=e=>{o=Ke(e),a=!0,l()},f=e=>{if(s){a=!0,l();return}o||=qe(e),a=!0,l()},p=()=>{o=Error(`Request was aborted`),a=!0,l()};e.addEventListener(`message`,u),e.addEventListener(`error`,d),e.addEventListener(`close`,f),t?.addEventListener(`abort`,p);try{for(;;){if(t?.aborted)throw Error(`Request was aborted`);if(r.length>0){yield r.shift();continue}if(a)break;let s;await new Promise((t,r)=>{i=t,n!==void 0&&n>0&&(s=setTimeout(()=>{let t=Error(`WebSocket idle timeout after ${n}ms`);o=t,a=!0,i=null,Z(e,1e3,`idle_timeout`),r(t)},n))}).finally(()=>{s&&clearTimeout(s)})}if(o)throw o;if(!s)throw Error(`WebSocket stream closed before response.completed`)}finally{e.removeEventListener(`message`,u),e.removeEventListener(`error`,d),e.removeEventListener(`close`,f),t?.removeEventListener(`abort`,p)}}function Xe(e){let{input:t,previous_response_id:n,...r}=e;return r}function Ze(e,t){return JSON.stringify(e??[])===JSON.stringify(t??[])}function Qe(e,t){return JSON.stringify(Xe(e))===JSON.stringify(Xe(t))}function $e(e,t){if(!Qe(e,t.lastRequestBody))return;let n=e.input??[],r=[...t.lastRequestBody.input??[],...t.lastResponseItems];if(!(n.length<r.length)&&Ze(n.slice(0,r.length),r))return n.slice(r.length)}function et(e,t){let n=e.continuation;if(!n)return t;let r=$e(t,n);return!r||!n.lastResponseId?(e.continuation=void 0,t):{...t,previous_response_id:n.lastResponseId,input:r}}async function*tt(e,t){let n=!1;for await(let r of e)n||(n=!0,t()),yield r}async function nt(e,n,r,i,a,o,s,c,l,u,d,f,p){let{socket:m,entry:h,reused:g,release:_}=await Ge(e,r,u,d,p?.signal,l,p?.env),v=!0,y=p?.transport===`websocket-cached`||p?.transport===`auto`,S=n,C=y&&h?et(h,S):S,w=u?G(u):void 0;w&&(w.requests++,g?w.connectionsReused++:w.connectionsCreated++,y&&w.cachedContextRequests++,C.store===!0&&w.storeTrueRequests++,w.lastInputItems=C.input?.length??0,C.previous_response_id?(w.deltaRequests++,w.lastDeltaInputItems=C.input?.length??0,w.lastPreviousResponseId=C.previous_response_id):(w.fullContextRequests++,w.lastDeltaInputItems=void 0,w.lastPreviousResponseId=void 0));try{if(m.send(JSON.stringify({type:`response.create`,...C})),await b(tt(V(Ye(m,p?.signal,c),i,o,p?.onProviderStreamEvent),s),i,a,o,{serviceTier:p?.serviceTier,grammarToolInputProperties:f,resolveServiceTier:we,applyServiceTierPricing:(e,t)=>Ce(e,t,o)}),p?.signal?.aborted)v=!1;else if(y&&h&&i.responseId){let e=x(o,t({messages:[i]}),P,{includeSystemPrompt:!1,grammarToolInputProperties:f}).filter(e=>e.type!==`function_call_output`&&e.type!==`custom_tool_call_output`);h.continuation={lastRequestBody:S,lastResponseId:i.responseId,lastResponseItems:e}}}catch(e){throw h&&(h.continuation=void 0),v=!1,e}finally{_({keep:v})}}async function rt(e){let t=await e.text(),n=t||e.statusText||`Request failed`,r;try{let i=JSON.parse(t)?.error;if(i){let t=i.code||i.type||``;if(/usage_limit_reached|usage_not_included|rate_limit_exceeded/i.test(t)||e.status===429){let e=i.plan_type?` (${i.plan_type.toLowerCase()} plan)`:``,t=i.resets_at?Math.max(0,Math.round((i.resets_at*1e3-Date.now())/6e4)):void 0;r=`You have hit your ChatGPT usage limit${e}.${t===void 0?``:` Try again in ~${t} min.`}`.trim()}n=i.message||r||n}}catch{}return{message:n,friendlyMessage:r}}function it(e){try{let t=e.split(`.`);if(t.length!==3)throw Error(`Invalid token`);let n=JSON.parse(atob(t[1]))?.[re]?.chatgpt_account_id;if(!n)throw Error(`No account ID in token`);return n}catch{throw Error(`Failed to extract accountId from token`)}}function $(e,t,n,r){let i=new Headers({originator:`pi`,"User-Agent":p()});for(let[t,n]of Object.entries(e||{}))i.set(t,n);for(let[e,n]of Object.entries(t||{}))n===null?i.delete(e):i.set(e,n);return i.set(`Authorization`,`Bearer ${r}`),i.set(`chatgpt-account-id`,n),i}function at(e,t,n,r,i){let a=$(e,t,n,r);return a.set(`OpenAI-Beta`,`responses=experimental`),a.set(`accept`,`text/event-stream`),a.set(`content-type`,`application/json`),i&&(a.set(`session-id`,i),a.set(`x-client-request-id`,i)),a}function ot(e,t,n,r,i){let a=$(e,t,n,r);return a.delete(`accept`),a.delete(`content-type`),a.delete(`OpenAI-Beta`),a.delete(`openai-beta`),a.set(`OpenAI-Beta`,Pe),a.set(`x-client-request-id`,i),a.set(`session-id`,i),a}export{K as closeOpenAICodexWebSocketSessions,Le as getOpenAICodexWebSocketDebugStats,Re as resetOpenAICodexWebSocketDebugStats,ye as stream,be as streamSimple,T as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{d as e,h as t,m as n,o as r,u as i}from"./preload-helper-DY31Aviq.js";import{t as a}from"./provider-env-CcCbsTJq.js";import{a as o}from"./diagnostics-CxvqSC4Q.js";import{n as s,t as c}from"./models-BM_0GHMS.js";import{t as l}from"./headers-FK4rgixo.js";import{n as u,r as d}from"./json-parse-M7s0500m.js";import{c as f,d as p,f as m,h,i as g,l as _,m as v,n as y,o as b,p as x,s as S,u as C}from"./transform-messages-iF4VkV1V.js";import{t as ee}from"./provider-retry-RVfYd5Vz.js";import{t as w}from"./sanitize-unicode-DmIE6hZJ.js";import{n as T,t as E}from"./github-copilot-headers-DRgtIyTm.js";import{n as D}from"./openai-Cpe0uoXQ.js";import{n as O,t as k}from"./error-body-pkrba6pf.js";import{t as A}from"./openai-prompt-cache-DXo9f3w5.js";import{t as j}from"./hash-yQufAZII.js";function M(e,t){if(!e)return!1;let n=t.toLowerCase();for(let[t,r]of Object.entries(e))if(t.toLowerCase()===n&&r!==null&&r.trim().length>0)return!0;return!1}function N(e,t,n){if(t)return t;if(M(n,`authorization`)||M(n,`cf-aig-authorization`))return`unused`;throw Error(`No API key for provider: ${e}`)}function P(e){for(let t of e)if(t.role===`toolResult`||t.role===`assistant`&&t.content.some(e=>e.type===`toolCall`))return!0;return!1}function F(e){return e.type===`text`}function I(e){return e.type===`thinking`}function L(e){return e.type===`toolCall`}function te(e){return e.type===`image`}function R(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function z(e){return(e.id===void 0||e.id===null||typeof e.id==`string`)&&(e.format===void 0||typeof e.format==`string`)&&(e.index===void 0||typeof e.index==`number`)}function B(e){if(!R(e)||!z(e))return!1;switch(e.type){case`reasoning.summary`:return typeof e.summary==`string`;case`reasoning.encrypted`:return typeof e.data==`string`;case`reasoning.text`:return typeof e.text==`string`&&(e.signature===void 0||e.signature===null||typeof e.signature==`string`);default:return!1}}function ne(e){if(e)try{let t=JSON.parse(e);return Array.isArray(t)&&t.length>0&&t.every(B)?t:void 0}catch{return}}function re(e){if(e)try{let t=JSON.parse(e);return B(t)&&t.type===`reasoning.encrypted`&&typeof t.id==`string`&&t.id.length>0&&t.data.length>0?t:void 0}catch{return}}function V(e,t){e.id??=t.id,e.format||=t.format,e.index??=t.index}function ie(e,t){let n=e[e.length-1];if(t.type===`reasoning.text`&&n?.type===`reasoning.text`){n.text+=t.text,n.signature||=t.signature,V(n,t);return}if(t.type===`reasoning.summary`&&n?.type===`reasoning.summary`){n.summary+=t.summary,V(n,t);return}e.push({...t})}var ae=[`reasoning`,`reasoning_content`,`reasoning_text`];function oe(e){return ae.includes(e)}function H(e,t){return e||(a(`PI_CACHE_RETENTION`,t)===`long`?`long`:`short`)}var U=(e,t,n)=>{let a=new o,s=i(t,$(e).supportsMidConvoSystemMessages);return(async()=>{let t={role:`assistant`,content:[],api:e.api,provider:e.provider,model:e.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,o=e=>{i!==void 0&&(e.thinkingSignature=JSON.stringify(i))};try{let c=N(e.provider,n?.apiKey,n?.headers),f=$(e),p=C(r(s.messages),f.supportsOpenAIGrammarTools),m=H(n?.cacheRetention,n?.env),h=m===`none`?void 0:n?.sessionId,g=G(e,s,c,n?.headers,n?.fetch,h,f),v=K(e,s,n,f,m,p),y=await n?.onPayload?.(v,e);y!==void 0&&(v=y);let b={...n?.signal?{signal:n.signal}:{},...n?.timeoutMs===void 0?{}:{timeout:n.timeoutMs},maxRetries:0},{data:x,response:S}=await ee(()=>g.chat.completions.create(v,b).withResponse(),{maxRetries:n?.maxRetries,maxRetryDelayMs:n?.maxRetryDelayMs,signal:n?.signal});await n?.onResponse?.({status:S.status,headers:l(S.headers)},e),a.push({type:`start`,partial:t});let w=null,T=null,E=!1,D=new Map,O=new Map,k=t.content,A=e=>k.indexOf(e),j=e=>{let t=e.customInput?.property;if(t===void 0)return``;let n=e.arguments[t];return typeof n==`string`?n:``},M=(e,t,n)=>{let r=e.customInput;if(!r)return;let i=_(r.jsonBuffer,r.property,t,n);return e.arguments={[r.property]:t},i},P=e=>{let n=A(e);if(n!==-1){if(e.type===`text`)a.push({type:`text_end`,contentIndex:n,content:e.text,partial:t});else if(e.type===`thinking`)o(e),a.push({type:`thinking_end`,contentIndex:n,content:e.thinking,partial:t});else if(e.type===`toolCall`){if(e.customInput){let r=M(e,j(e),!0);r!==void 0&&a.push({type:`toolcall_delta`,contentIndex:n,delta:r,partial:t})}else Object.assign(e,d(e.partialArgs));delete e.partialArgs,delete e.customInput,delete e.streamIndex,a.push({type:`toolcall_end`,contentIndex:n,toolCall:e,partial:t})}}},F=()=>(w||(w={type:`text`,text:``},k.push(w),a.push({type:`text_start`,contentIndex:A(w),partial:t})),w),I=e=>(T||(T={type:`thinking`,thinking:``,thinkingSignature:e},k.push(T),a.push({type:`thinking_start`,contentIndex:A(T),partial:t})),T),L=e=>{let n=typeof e.index==`number`?e.index:void 0,r=e.function?.name??e.custom?.name??``,i=n===void 0?void 0:D.get(n);if(!i&&e.id&&(i=O.get(e.id)),!i){let o=e.custom&&!e.function?p.get(r)??`input`:void 0,s=o!==void 0;i={type:`toolCall`,id:e.id||``,name:r,arguments:s?{[o]:``}:{},partialArgs:s?void 0:``,customInput:s?{property:o,jsonBuffer:{input:``,started:!1,closed:!1}}:void 0,streamIndex:n},n!==void 0&&D.set(n,i),e.id&&O.set(e.id,i),k.push(i),a.push({type:`toolcall_start`,contentIndex:A(i),partial:t})}if(n!==void 0&&i.streamIndex===void 0&&(i.streamIndex=n,D.set(n,i)),e.id&&O.set(e.id,i),!i.name&&r&&(i.name=r),e.custom&&!e.function&&!i.customInput){let e=p.get(i.name)??`input`;i.arguments={[e]:``},i.customInput={property:e,jsonBuffer:{input:``,started:!1,closed:!1}},delete i.partialArgs}return i};for await(let r of x){if(await n?.onProviderStreamEvent?.(r,e),!r||typeof r!=`object`)continue;t.responseId||=r.id,typeof r.model==`string`&&r.model.length>0&&r.model!==e.id&&(t.responseModel||=r.model),r.usage&&(t.usage=Z(r.usage,e));let o=Array.isArray(r.choices)?r.choices[0]:void 0;if(o){if(!r.usage&&o.usage&&(t.usage=Z(o.usage,e)),o.finish_reason){t.rawStopReason=o.finish_reason;let e=_e(o.finish_reason);t.stopReason=e.stopReason,e.errorMessage&&(t.errorMessage=e.errorMessage),E=!0}if(o.delta){let n=[`reasoning_content`,`reasoning`,`reasoning_text`],r=o.delta,s=null;for(let e of n){let t=r[e];if(typeof t==`string`&&t.length>0){s=e;break}}if(s){let n=r[s];if(typeof n==`string`&&n.length>0){let r=I(e.provider===`opencode-go`&&s===`reasoning`?`reasoning_content`:s);r.thinking+=n,a.push({type:`thinking_delta`,contentIndex:A(r),delta:n,partial:t})}}let c=o.delta.reasoning_details;if(Array.isArray(c))for(let e of c)B(e)&&(I(``),i??=[],ie(i,e));if(o.delta.content!==null&&o.delta.content!==void 0&&o.delta.content.length>0){let e=F();e.text+=o.delta.content,a.push({type:`text_delta`,contentIndex:A(e),delta:o.delta.content,partial:t})}if(o?.delta?.tool_calls)for(let e of o.delta.tool_calls){let n=L(e);!n.id&&e.id&&(n.id=e.id,O.set(e.id,n));let r=e.function?.name??e.custom?.name;!n.name&&r&&(n.name=r);let i=``;e.function?.arguments?(i=e.function.arguments,n.partialArgs=(n.partialArgs??``)+e.function.arguments,n.arguments=u(n.partialArgs)):e.custom?.input&&(i=M(n,j(n)+e.custom.input,!1)??``),a.push({type:`toolcall_delta`,contentIndex:A(n),delta:i,partial:t})}}}}for(let e of k)P(e);if(n?.signal?.aborted||t.stopReason===`aborted`)throw Error(`Request was aborted`);if(!E&&!f.supportsFinishReason&&(t.stopReason=t.content.some(e=>e.type===`toolCall`)?`toolUse`:`stop`),t.stopReason===`error`)throw Error(t.errorMessage||`Provider returned an error stop reason`);if(f.supportsFinishReason&&!E||t.stopReason===`pending`)throw Error(`Stream ended without finish_reason`);a.push({type:`done`,reason:t.stopReason,message:t}),a.end()}catch(e){for(let e of t.content)e.type===`thinking`&&o(e),delete e.index,delete e.partialArgs,delete e.customInput,delete e.streamIndex;t.stopReason=n?.signal?.aborted?`aborted`:`error`,t.errorMessage=k(O(e));let r=e?.error?.metadata?.raw;r&&!t.errorMessage.includes(String(r))&&(t.errorMessage+=`\n${r}`),a.push({type:`error`,reason:t.stopReason,error:t}),a.end()}})(),a},W=(e,t,n)=>{N(e.provider,n?.apiKey,n?.headers);let r={...g(e,t,n,n?.apiKey),toolChoice:n?.toolChoice},i=n?.reasoning?s(e,n.reasoning):void 0,a=i===`off`?void 0:i;return U(e,t,{...r,reasoningEffort:a,thinkingBudgets:n?.thinkingBudgets})};function G(e,t,n,r,i,a,o=$(e)){let s={"User-Agent":h(),...e.headers};if(e.provider===`github-copilot`){let e=T(t.messages),n=E({messages:t.messages,hasImages:e});Object.assign(s,n)}return a&&o.sendSessionAffinityHeaders&&(o.sessionAffinityFormat===`openrouter`?s[`x-session-id`]=a:(o.sessionAffinityFormat===`openai`&&(s.session_id=a),s[`x-client-request-id`]=a,s[`x-session-affinity`]=a)),r&&Object.assign(s,r),new D({apiKey:n,baseURL:e.baseUrl,dangerouslyAllowBrowser:!0,fetch:i,defaultHeaders:s})}function K(t,n,i,a=$(t),o=H(i?.cacheRetention,i?.env),s=C(r(n.messages),a.supportsOpenAIGrammarTools)){let c=e(n.messages,a.supportsMidConvoSystemMessages===!0&&a.supportsMidConvoToolAdditions===!0),l=Y(t,n,a,{grammarToolInputProperties:s}),u=ue(a,o),d={model:t.id,messages:l,stream:!0,prompt_cache_key:t.baseUrl.includes(`api.openai.com`)&&o!==`none`||o===`long`&&a.supportsLongCacheRetention?A(i?.sessionId):void 0,prompt_cache_retention:o===`long`&&a.supportsLongCacheRetention?`24h`:void 0};a.supportsUsageInStreaming!==!1&&(d.stream_options={include_usage:!0}),a.supportsStore&&(d.store=!1),i?.maxTokens&&(a.maxTokensField===`max_tokens`?d.max_tokens=i.maxTokens:d.max_completion_tokens=i.maxTokens),i?.temperature!==void 0&&(d.temperature=i.temperature),c.requestTools.length>0?(d.tools=X(c.requestTools,a),a.zaiToolStream&&(d.tool_stream=!0)):P(n.messages)&&(d.tools=[]),u&&de(l,d.tools,u),i?.toolChoice&&(d.tool_choice=i.toolChoice),a.vllmPriority!==void 0&&(d.priority=a.vllmPriority);let f=se(a),p=ce(t,i,d);if(a.thinkingFormat===`zai`&&t.reasoning){let e=d;if(e.thinking=i?.reasoningEffort?{type:`enabled`,clear_thinking:!1}:{type:`disabled`},i?.reasoningEffort&&a.supportsReasoningEffort){let n=t.thinkingLevelMap?.[i.reasoningEffort],r=n===void 0?i.reasoningEffort:n;typeof r==`string`&&(e.reasoning_effort=r)}}else if(a.thinkingFormat===`qwen`&&t.reasoning){if(d.enable_thinking=!!i?.reasoningEffort,i?.reasoningEffort&&a.supportsReasoningEffort){let e=t.thinkingLevelMap?.[i.reasoningEffort]??i.reasoningEffort;typeof e==`string`&&(d.reasoning_effort=e)}}else if(a.thinkingFormat===`qwen-chat-template`&&t.reasoning)d.chat_template_kwargs={enable_thinking:!!i?.reasoningEffort,preserve_thinking:!0};else if(a.thinkingFormat===`chat-template`&&t.reasoning){let e=q(t,i,a.chatTemplateKwargs,p);e&&(d.chat_template_kwargs=e)}else if(a.thinkingFormat===`baseten`&&t.reasoning){let e=d,n=q(t,i,a.chatTemplateArgs,p);if(n&&(e.chat_template_args=n),a.supportsReasoningEffort){let n=i?.reasoningEffort,r=n?t.thinkingLevelMap?.[n]:t.thinkingLevelMap?.off,a=r===void 0?n:r;typeof a==`string`&&(e.reasoning_effort=a)}}else if(a.thinkingFormat===`deepseek`&&t.reasoning)i?.reasoningEffort?d.thinking={type:`enabled`}:t.thinkingLevelMap?.off!==null&&(d.thinking={type:`disabled`}),i?.reasoningEffort&&a.supportsReasoningEffort&&(d.reasoning_effort=t.thinkingLevelMap?.[i.reasoningEffort]??i.reasoningEffort);else if(a.thinkingFormat===`openrouter`&&t.reasoning){let e=d;i?.reasoningEffort?e.reasoning={effort:t.thinkingLevelMap?.[i.reasoningEffort]??i.reasoningEffort}:t.thinkingLevelMap?.off!==null&&(e.reasoning={effort:t.thinkingLevelMap?.off??`none`})}else if(a.thinkingFormat===`ant-ling`&&t.reasoning&&i?.reasoningEffort){let e=t.thinkingLevelMap?.[i.reasoningEffort];typeof e==`string`&&(d.reasoning={effort:e})}else if(a.thinkingFormat===`together`&&t.reasoning){let e=d;e.reasoning={enabled:!!i?.reasoningEffort},i?.reasoningEffort&&a.supportsReasoningEffort&&(e.reasoning_effort=t.thinkingLevelMap?.[i.reasoningEffort]??i.reasoningEffort)}else if(a.thinkingFormat===`string-thinking`&&t.reasoning){let e=d;i?.reasoningEffort?e.thinking=t.thinkingLevelMap?.[i.reasoningEffort]??i.reasoningEffort:t.thinkingLevelMap?.off!==null&&(e.thinking=t.thinkingLevelMap?.off??`none`)}else if(i?.reasoningEffort&&t.reasoning&&a.supportsReasoningEffort)d.reasoning_effort=t.thinkingLevelMap?.[i.reasoningEffort]??i.reasoningEffort;else if(!i?.reasoningEffort&&t.reasoning&&a.supportsReasoningEffort){let e=t.thinkingLevelMap?.off;typeof e==`string`&&(d.reasoning_effort=e)}if(f&&p!==void 0&&Object.assign(d,{[f]:p}),t.compat?.openRouterRouting&&(d.provider=t.compat.openRouterRouting),t.compat?.vercelGatewayRouting){let e=t.compat.vercelGatewayRouting;if(e.only||e.order){let t={};e.only&&(t.only=e.only),e.order&&(t.order=e.order),d.providerOptions={gateway:t}}}let m=S(t,i?.reasoningEffort??`off`,i?.samplingParams);return m&&Object.assign(d,m),d}function se(e){if(e.thinkingTokenBudgetField)return e.thinkingTokenBudgetField;if(e.supportsThinkingTokenBudget)return`thinking_token_budget`}function ce(e,t,n){if(!t?.reasoningEffort||!e.reasoning)return;let r=n.max_tokens??n.max_completion_tokens??e.maxTokens,i=b(f(t.reasoningEffort,t.thinkingBudgets),r);return i>0?i:void 0}function q(e,t,n,r){let i={};for(let[a,o]of Object.entries(n)){let n=le(e,t,o,r);n!==void 0&&(i[a]=n)}return Object.keys(i).length>0?i:void 0}function le(e,t,n,r){if(typeof n!=`object`||!n)return n;let i=t?.reasoningEffort;if(!i&&n.omitWhenOff)return;if(n.$var===`thinking.enabled`)return!!i;if(n.$var===`thinking.budget`)return r;let a=i?e.thinkingLevelMap?.[i]:e.thinkingLevelMap?.off;return a===void 0?i:typeof a==`string`?a:void 0}function ue(e,t){if(e.cacheControlFormat!==`anthropic`||t===`none`)return;let n=t===`long`&&e.supportsLongCacheRetention?`1h`:void 0;return{type:`ephemeral`,...n?{ttl:n}:{}}}function de(e,t,n){fe(e,n),me(t,n),pe(e,n)}function fe(e,t){for(let n of e)if(n.role===`system`||n.role===`developer`){he(n,t);return}}function pe(e,t){for(let n=e.length-1;n>=0;n--){let r=e[n];if((r.role===`user`||r.role===`assistant`||r.role===`tool`)&&ge(r,t))return}}function me(e,t){if(!e||e.length===0)return;let n=e[e.length-1];n.cache_control=t}function he(e,t){return J(e,t)}function ge(e,t){return e.role===`user`||e.role===`assistant`||e.role===`tool`?J(e,t):!1}function J(e,t){let n=e.content;if(typeof n==`string`)return n.length!==0&&(e.content=[{type:`text`,text:n,cache_control:t}],!0);if(!Array.isArray(n))return!1;for(let e=n.length-1;e>=0;e--){let r=n[e];if(r?.type===`text`){let e=r;return e.cache_control=t,!0}}return!1}function Y(r,a,o,s){let c=i(a,o.supportsMidConvoSystemMessages),l=[],u=e=>{if(e.includes(`|`)){let t=e.indexOf(`|`),n=e.slice(0,t).replace(/[^a-zA-Z0-9_-]/g,`_`),r=e.slice(t+1).replace(/[^a-zA-Z0-9_-]/g,`_`),i=r.length>0?`${n}_${r}`:n;if(i.length<=40)return i;let a=j(e).slice(0,8);return`${n.slice(0,Math.max(1,40-a.length-1))}_${a}`}return r.provider===`openai`&&e.length>40?e.slice(0,40):e},d=y(c.messages,r,e=>u(e)),f=e(c.messages,o.supportsMidConvoSystemMessages===!0&&o.supportsMidConvoToolAdditions===!0),m=r.reasoning&&o.supportsDeveloperRole?`developer`:`system`,h=null;for(let e=0;e<d.length;e++){let i=d[e];if(o.requiresAssistantAfterToolResult&&h===`toolResult`&&i.role===`user`&&l.push({role:`assistant`,content:`I have processed the tool results.`}),i.role===`system`){let r=e>0&&f.anchorsAdditions?i.toolsAdded??[]:[];if(r.length>0){let e={role:`system`,tools:X(r,o)};l.push(e)}let a=e===0?n(i):t(i);a.length>0&&l.push({role:m,content:w(a)})}else if(i.role===`user`){if(typeof i.content==`string`)l.push({role:`user`,content:w(i.content)});else{let e=i.content.filter(e=>e.type!==`text`||e.text.length>0).map(e=>e.type===`text`?{type:`text`,text:w(e.text)}:{type:`image_url`,image_url:{url:`data:${e.mimeType};base64,${e.data}`}});if(e.length===0)continue;l.push({role:`user`,content:e})}}else if(i.role===`assistant`){let e={role:`assistant`,content:o.requiresAssistantAfterToolResult?``:null},t=i.content.filter(F).filter(e=>e.text.trim().length>0).map(e=>({type:`text`,text:w(e.text)})),n=t.map(e=>e.text).join(``),a=i.content.filter(I),c=i.content.filter(L),u=a.map(e=>ne(e.thinkingSignature)).find(e=>e!==void 0),d=c.map(e=>re(e.thoughtSignature)).filter(e=>e!==void 0),f=u??(d.length>0?d:void 0),m=a.filter(e=>e.thinking.trim().length>0);if(m.length>0){if(o.requiresThinkingAsText)e.content=[{type:`text`,text:m.map(e=>w(e.thinking)).join(`
|
|
1
|
+
import{d as e,h as t,m as n,o as r,u as i}from"./preload-helper-DY31Aviq.js";import{t as a}from"./provider-env-CcCbsTJq.js";import{a as o}from"./diagnostics-CxvqSC4Q.js";import{n as s,t as c}from"./models-BM_0GHMS.js";import{t as l}from"./headers-FK4rgixo.js";import{n as u,r as d}from"./json-parse-M7s0500m.js";import{c as f,d as p,f as m,h,i as g,l as _,m as v,n as y,o as b,p as x,s as S,u as C}from"./transform-messages-CgFTI6NF.js";import{t as ee}from"./provider-retry-RVfYd5Vz.js";import{t as w}from"./sanitize-unicode-DmIE6hZJ.js";import{n as T,t as E}from"./github-copilot-headers-DRgtIyTm.js";import{n as D}from"./openai-Cpe0uoXQ.js";import{n as O,t as k}from"./error-body-pkrba6pf.js";import{t as A}from"./openai-prompt-cache-DXo9f3w5.js";import{t as j}from"./hash-yQufAZII.js";function M(e,t){if(!e)return!1;let n=t.toLowerCase();for(let[t,r]of Object.entries(e))if(t.toLowerCase()===n&&r!==null&&r.trim().length>0)return!0;return!1}function N(e,t,n){if(t)return t;if(M(n,`authorization`)||M(n,`cf-aig-authorization`))return`unused`;throw Error(`No API key for provider: ${e}`)}function P(e){for(let t of e)if(t.role===`toolResult`||t.role===`assistant`&&t.content.some(e=>e.type===`toolCall`))return!0;return!1}function F(e){return e.type===`text`}function I(e){return e.type===`thinking`}function L(e){return e.type===`toolCall`}function te(e){return e.type===`image`}function R(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function z(e){return(e.id===void 0||e.id===null||typeof e.id==`string`)&&(e.format===void 0||typeof e.format==`string`)&&(e.index===void 0||typeof e.index==`number`)}function B(e){if(!R(e)||!z(e))return!1;switch(e.type){case`reasoning.summary`:return typeof e.summary==`string`;case`reasoning.encrypted`:return typeof e.data==`string`;case`reasoning.text`:return typeof e.text==`string`&&(e.signature===void 0||e.signature===null||typeof e.signature==`string`);default:return!1}}function ne(e){if(e)try{let t=JSON.parse(e);return Array.isArray(t)&&t.length>0&&t.every(B)?t:void 0}catch{return}}function re(e){if(e)try{let t=JSON.parse(e);return B(t)&&t.type===`reasoning.encrypted`&&typeof t.id==`string`&&t.id.length>0&&t.data.length>0?t:void 0}catch{return}}function V(e,t){e.id??=t.id,e.format||=t.format,e.index??=t.index}function ie(e,t){let n=e[e.length-1];if(t.type===`reasoning.text`&&n?.type===`reasoning.text`){n.text+=t.text,n.signature||=t.signature,V(n,t);return}if(t.type===`reasoning.summary`&&n?.type===`reasoning.summary`){n.summary+=t.summary,V(n,t);return}e.push({...t})}var ae=[`reasoning`,`reasoning_content`,`reasoning_text`];function oe(e){return ae.includes(e)}function H(e,t){return e||(a(`PI_CACHE_RETENTION`,t)===`long`?`long`:`short`)}var U=(e,t,n)=>{let a=new o,s=i(t,$(e).supportsMidConvoSystemMessages);return(async()=>{let t={role:`assistant`,content:[],api:e.api,provider:e.provider,model:e.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,o=e=>{i!==void 0&&(e.thinkingSignature=JSON.stringify(i))};try{let c=N(e.provider,n?.apiKey,n?.headers),f=$(e),p=C(r(s.messages),f.supportsOpenAIGrammarTools),m=H(n?.cacheRetention,n?.env),h=m===`none`?void 0:n?.sessionId,g=G(e,s,c,n?.headers,n?.fetch,h,f),v=K(e,s,n,f,m,p),y=await n?.onPayload?.(v,e);y!==void 0&&(v=y);let b={...n?.signal?{signal:n.signal}:{},...n?.timeoutMs===void 0?{}:{timeout:n.timeoutMs},maxRetries:0},{data:x,response:S}=await ee(()=>g.chat.completions.create(v,b).withResponse(),{maxRetries:n?.maxRetries,maxRetryDelayMs:n?.maxRetryDelayMs,signal:n?.signal});await n?.onResponse?.({status:S.status,headers:l(S.headers)},e),a.push({type:`start`,partial:t});let w=null,T=null,E=!1,D=new Map,O=new Map,k=t.content,A=e=>k.indexOf(e),j=e=>{let t=e.customInput?.property;if(t===void 0)return``;let n=e.arguments[t];return typeof n==`string`?n:``},M=(e,t,n)=>{let r=e.customInput;if(!r)return;let i=_(r.jsonBuffer,r.property,t,n);return e.arguments={[r.property]:t},i},P=e=>{let n=A(e);if(n!==-1){if(e.type===`text`)a.push({type:`text_end`,contentIndex:n,content:e.text,partial:t});else if(e.type===`thinking`)o(e),a.push({type:`thinking_end`,contentIndex:n,content:e.thinking,partial:t});else if(e.type===`toolCall`){if(e.customInput){let r=M(e,j(e),!0);r!==void 0&&a.push({type:`toolcall_delta`,contentIndex:n,delta:r,partial:t})}else Object.assign(e,d(e.partialArgs));delete e.partialArgs,delete e.customInput,delete e.streamIndex,a.push({type:`toolcall_end`,contentIndex:n,toolCall:e,partial:t})}}},F=()=>(w||(w={type:`text`,text:``},k.push(w),a.push({type:`text_start`,contentIndex:A(w),partial:t})),w),I=e=>(T||(T={type:`thinking`,thinking:``,thinkingSignature:e},k.push(T),a.push({type:`thinking_start`,contentIndex:A(T),partial:t})),T),L=e=>{let n=typeof e.index==`number`?e.index:void 0,r=e.function?.name??e.custom?.name??``,i=n===void 0?void 0:D.get(n);if(!i&&e.id&&(i=O.get(e.id)),!i){let o=e.custom&&!e.function?p.get(r)??`input`:void 0,s=o!==void 0;i={type:`toolCall`,id:e.id||``,name:r,arguments:s?{[o]:``}:{},partialArgs:s?void 0:``,customInput:s?{property:o,jsonBuffer:{input:``,started:!1,closed:!1}}:void 0,streamIndex:n},n!==void 0&&D.set(n,i),e.id&&O.set(e.id,i),k.push(i),a.push({type:`toolcall_start`,contentIndex:A(i),partial:t})}if(n!==void 0&&i.streamIndex===void 0&&(i.streamIndex=n,D.set(n,i)),e.id&&O.set(e.id,i),!i.name&&r&&(i.name=r),e.custom&&!e.function&&!i.customInput){let e=p.get(i.name)??`input`;i.arguments={[e]:``},i.customInput={property:e,jsonBuffer:{input:``,started:!1,closed:!1}},delete i.partialArgs}return i};for await(let r of x){if(await n?.onProviderStreamEvent?.(r,e),!r||typeof r!=`object`)continue;t.responseId||=r.id,typeof r.model==`string`&&r.model.length>0&&r.model!==e.id&&(t.responseModel||=r.model),r.usage&&(t.usage=Z(r.usage,e));let o=Array.isArray(r.choices)?r.choices[0]:void 0;if(o){if(!r.usage&&o.usage&&(t.usage=Z(o.usage,e)),o.finish_reason){t.rawStopReason=o.finish_reason;let e=_e(o.finish_reason);t.stopReason=e.stopReason,e.errorMessage&&(t.errorMessage=e.errorMessage),E=!0}if(o.delta){let n=[`reasoning_content`,`reasoning`,`reasoning_text`],r=o.delta,s=null;for(let e of n){let t=r[e];if(typeof t==`string`&&t.length>0){s=e;break}}if(s){let n=r[s];if(typeof n==`string`&&n.length>0){let r=I(e.provider===`opencode-go`&&s===`reasoning`?`reasoning_content`:s);r.thinking+=n,a.push({type:`thinking_delta`,contentIndex:A(r),delta:n,partial:t})}}let c=o.delta.reasoning_details;if(Array.isArray(c))for(let e of c)B(e)&&(I(``),i??=[],ie(i,e));if(o.delta.content!==null&&o.delta.content!==void 0&&o.delta.content.length>0){let e=F();e.text+=o.delta.content,a.push({type:`text_delta`,contentIndex:A(e),delta:o.delta.content,partial:t})}if(o?.delta?.tool_calls)for(let e of o.delta.tool_calls){let n=L(e);!n.id&&e.id&&(n.id=e.id,O.set(e.id,n));let r=e.function?.name??e.custom?.name;!n.name&&r&&(n.name=r);let i=``;e.function?.arguments?(i=e.function.arguments,n.partialArgs=(n.partialArgs??``)+e.function.arguments,n.arguments=u(n.partialArgs)):e.custom?.input&&(i=M(n,j(n)+e.custom.input,!1)??``),a.push({type:`toolcall_delta`,contentIndex:A(n),delta:i,partial:t})}}}}for(let e of k)P(e);if(n?.signal?.aborted||t.stopReason===`aborted`)throw Error(`Request was aborted`);if(!E&&!f.supportsFinishReason&&(t.stopReason=t.content.some(e=>e.type===`toolCall`)?`toolUse`:`stop`),t.stopReason===`error`)throw Error(t.errorMessage||`Provider returned an error stop reason`);if(f.supportsFinishReason&&!E||t.stopReason===`pending`)throw Error(`Stream ended without finish_reason`);a.push({type:`done`,reason:t.stopReason,message:t}),a.end()}catch(e){for(let e of t.content)e.type===`thinking`&&o(e),delete e.index,delete e.partialArgs,delete e.customInput,delete e.streamIndex;t.stopReason=n?.signal?.aborted?`aborted`:`error`,t.errorMessage=k(O(e));let r=e?.error?.metadata?.raw;r&&!t.errorMessage.includes(String(r))&&(t.errorMessage+=`\n${r}`),a.push({type:`error`,reason:t.stopReason,error:t}),a.end()}})(),a},W=(e,t,n)=>{N(e.provider,n?.apiKey,n?.headers);let r={...g(e,t,n,n?.apiKey),toolChoice:n?.toolChoice},i=n?.reasoning?s(e,n.reasoning):void 0,a=i===`off`?void 0:i;return U(e,t,{...r,reasoningEffort:a,thinkingBudgets:n?.thinkingBudgets})};function G(e,t,n,r,i,a,o=$(e)){let s={"User-Agent":h(),...e.headers};if(e.provider===`github-copilot`){let e=T(t.messages),n=E({messages:t.messages,hasImages:e});Object.assign(s,n)}return a&&o.sendSessionAffinityHeaders&&(o.sessionAffinityFormat===`openrouter`?s[`x-session-id`]=a:(o.sessionAffinityFormat===`openai`&&(s.session_id=a),s[`x-client-request-id`]=a,s[`x-session-affinity`]=a)),r&&Object.assign(s,r),new D({apiKey:n,baseURL:e.baseUrl,dangerouslyAllowBrowser:!0,fetch:i,defaultHeaders:s})}function K(t,n,i,a=$(t),o=H(i?.cacheRetention,i?.env),s=C(r(n.messages),a.supportsOpenAIGrammarTools)){let c=e(n.messages,a.supportsMidConvoSystemMessages===!0&&a.supportsMidConvoToolAdditions===!0),l=Y(t,n,a,{grammarToolInputProperties:s}),u=ue(a,o),d={model:t.id,messages:l,stream:!0,prompt_cache_key:t.baseUrl.includes(`api.openai.com`)&&o!==`none`||o===`long`&&a.supportsLongCacheRetention?A(i?.sessionId):void 0,prompt_cache_retention:o===`long`&&a.supportsLongCacheRetention?`24h`:void 0};a.supportsUsageInStreaming!==!1&&(d.stream_options={include_usage:!0}),a.supportsStore&&(d.store=!1),i?.maxTokens&&(a.maxTokensField===`max_tokens`?d.max_tokens=i.maxTokens:d.max_completion_tokens=i.maxTokens),i?.temperature!==void 0&&(d.temperature=i.temperature),c.requestTools.length>0?(d.tools=X(c.requestTools,a),a.zaiToolStream&&(d.tool_stream=!0)):P(n.messages)&&(d.tools=[]),u&&de(l,d.tools,u),i?.toolChoice&&(d.tool_choice=i.toolChoice),a.vllmPriority!==void 0&&(d.priority=a.vllmPriority);let f=se(a),p=ce(t,i,d);if(a.thinkingFormat===`zai`&&t.reasoning){let e=d;if(e.thinking=i?.reasoningEffort?{type:`enabled`,clear_thinking:!1}:{type:`disabled`},i?.reasoningEffort&&a.supportsReasoningEffort){let n=t.thinkingLevelMap?.[i.reasoningEffort],r=n===void 0?i.reasoningEffort:n;typeof r==`string`&&(e.reasoning_effort=r)}}else if(a.thinkingFormat===`qwen`&&t.reasoning){if(d.enable_thinking=!!i?.reasoningEffort,i?.reasoningEffort&&a.supportsReasoningEffort){let e=t.thinkingLevelMap?.[i.reasoningEffort]??i.reasoningEffort;typeof e==`string`&&(d.reasoning_effort=e)}}else if(a.thinkingFormat===`qwen-chat-template`&&t.reasoning)d.chat_template_kwargs={enable_thinking:!!i?.reasoningEffort,preserve_thinking:!0};else if(a.thinkingFormat===`chat-template`&&t.reasoning){let e=q(t,i,a.chatTemplateKwargs,p);e&&(d.chat_template_kwargs=e)}else if(a.thinkingFormat===`baseten`&&t.reasoning){let e=d,n=q(t,i,a.chatTemplateArgs,p);if(n&&(e.chat_template_args=n),a.supportsReasoningEffort){let n=i?.reasoningEffort,r=n?t.thinkingLevelMap?.[n]:t.thinkingLevelMap?.off,a=r===void 0?n:r;typeof a==`string`&&(e.reasoning_effort=a)}}else if(a.thinkingFormat===`deepseek`&&t.reasoning)i?.reasoningEffort?d.thinking={type:`enabled`}:t.thinkingLevelMap?.off!==null&&(d.thinking={type:`disabled`}),i?.reasoningEffort&&a.supportsReasoningEffort&&(d.reasoning_effort=t.thinkingLevelMap?.[i.reasoningEffort]??i.reasoningEffort);else if(a.thinkingFormat===`openrouter`&&t.reasoning){let e=d;i?.reasoningEffort?e.reasoning={effort:t.thinkingLevelMap?.[i.reasoningEffort]??i.reasoningEffort}:t.thinkingLevelMap?.off!==null&&(e.reasoning={effort:t.thinkingLevelMap?.off??`none`})}else if(a.thinkingFormat===`ant-ling`&&t.reasoning&&i?.reasoningEffort){let e=t.thinkingLevelMap?.[i.reasoningEffort];typeof e==`string`&&(d.reasoning={effort:e})}else if(a.thinkingFormat===`together`&&t.reasoning){let e=d;e.reasoning={enabled:!!i?.reasoningEffort},i?.reasoningEffort&&a.supportsReasoningEffort&&(e.reasoning_effort=t.thinkingLevelMap?.[i.reasoningEffort]??i.reasoningEffort)}else if(a.thinkingFormat===`string-thinking`&&t.reasoning){let e=d;i?.reasoningEffort?e.thinking=t.thinkingLevelMap?.[i.reasoningEffort]??i.reasoningEffort:t.thinkingLevelMap?.off!==null&&(e.thinking=t.thinkingLevelMap?.off??`none`)}else if(i?.reasoningEffort&&t.reasoning&&a.supportsReasoningEffort)d.reasoning_effort=t.thinkingLevelMap?.[i.reasoningEffort]??i.reasoningEffort;else if(!i?.reasoningEffort&&t.reasoning&&a.supportsReasoningEffort){let e=t.thinkingLevelMap?.off;typeof e==`string`&&(d.reasoning_effort=e)}if(f&&p!==void 0&&Object.assign(d,{[f]:p}),t.compat?.openRouterRouting&&(d.provider=t.compat.openRouterRouting),t.compat?.vercelGatewayRouting){let e=t.compat.vercelGatewayRouting;if(e.only||e.order){let t={};e.only&&(t.only=e.only),e.order&&(t.order=e.order),d.providerOptions={gateway:t}}}let m=S(t,i?.reasoningEffort??`off`,i?.samplingParams);return m&&Object.assign(d,m),d}function se(e){if(e.thinkingTokenBudgetField)return e.thinkingTokenBudgetField;if(e.supportsThinkingTokenBudget)return`thinking_token_budget`}function ce(e,t,n){if(!t?.reasoningEffort||!e.reasoning)return;let r=n.max_tokens??n.max_completion_tokens??e.maxTokens,i=b(f(t.reasoningEffort,t.thinkingBudgets),r);return i>0?i:void 0}function q(e,t,n,r){let i={};for(let[a,o]of Object.entries(n)){let n=le(e,t,o,r);n!==void 0&&(i[a]=n)}return Object.keys(i).length>0?i:void 0}function le(e,t,n,r){if(typeof n!=`object`||!n)return n;let i=t?.reasoningEffort;if(!i&&n.omitWhenOff)return;if(n.$var===`thinking.enabled`)return!!i;if(n.$var===`thinking.budget`)return r;let a=i?e.thinkingLevelMap?.[i]:e.thinkingLevelMap?.off;return a===void 0?i:typeof a==`string`?a:void 0}function ue(e,t){if(e.cacheControlFormat!==`anthropic`||t===`none`)return;let n=t===`long`&&e.supportsLongCacheRetention?`1h`:void 0;return{type:`ephemeral`,...n?{ttl:n}:{}}}function de(e,t,n){fe(e,n),me(t,n),pe(e,n)}function fe(e,t){for(let n of e)if(n.role===`system`||n.role===`developer`){he(n,t);return}}function pe(e,t){for(let n=e.length-1;n>=0;n--){let r=e[n];if((r.role===`user`||r.role===`assistant`||r.role===`tool`)&&ge(r,t))return}}function me(e,t){if(!e||e.length===0)return;let n=e[e.length-1];n.cache_control=t}function he(e,t){return J(e,t)}function ge(e,t){return e.role===`user`||e.role===`assistant`||e.role===`tool`?J(e,t):!1}function J(e,t){let n=e.content;if(typeof n==`string`)return n.length!==0&&(e.content=[{type:`text`,text:n,cache_control:t}],!0);if(!Array.isArray(n))return!1;for(let e=n.length-1;e>=0;e--){let r=n[e];if(r?.type===`text`){let e=r;return e.cache_control=t,!0}}return!1}function Y(r,a,o,s){let c=i(a,o.supportsMidConvoSystemMessages),l=[],u=e=>{if(e.includes(`|`)){let t=e.indexOf(`|`),n=e.slice(0,t).replace(/[^a-zA-Z0-9_-]/g,`_`),r=e.slice(t+1).replace(/[^a-zA-Z0-9_-]/g,`_`),i=r.length>0?`${n}_${r}`:n;if(i.length<=40)return i;let a=j(e).slice(0,8);return`${n.slice(0,Math.max(1,40-a.length-1))}_${a}`}return r.provider===`openai`&&e.length>40?e.slice(0,40):e},d=y(c.messages,r,e=>u(e)),f=e(c.messages,o.supportsMidConvoSystemMessages===!0&&o.supportsMidConvoToolAdditions===!0),m=r.reasoning&&o.supportsDeveloperRole?`developer`:`system`,h=null;for(let e=0;e<d.length;e++){let i=d[e];if(o.requiresAssistantAfterToolResult&&h===`toolResult`&&i.role===`user`&&l.push({role:`assistant`,content:`I have processed the tool results.`}),i.role===`system`){let r=e>0&&f.anchorsAdditions?i.toolsAdded??[]:[];if(r.length>0){let e={role:`system`,tools:X(r,o)};l.push(e)}let a=e===0?n(i):t(i);a.length>0&&l.push({role:m,content:w(a)})}else if(i.role===`user`){if(typeof i.content==`string`)l.push({role:`user`,content:w(i.content)});else{let e=i.content.filter(e=>e.type!==`text`||e.text.length>0).map(e=>e.type===`text`?{type:`text`,text:w(e.text)}:{type:`image_url`,image_url:{url:`data:${e.mimeType};base64,${e.data}`}});if(e.length===0)continue;l.push({role:`user`,content:e})}}else if(i.role===`assistant`){let e={role:`assistant`,content:o.requiresAssistantAfterToolResult?``:null},t=i.content.filter(F).filter(e=>e.text.trim().length>0).map(e=>({type:`text`,text:w(e.text)})),n=t.map(e=>e.text).join(``),a=i.content.filter(I),c=i.content.filter(L),u=a.map(e=>ne(e.thinkingSignature)).find(e=>e!==void 0),d=c.map(e=>re(e.thoughtSignature)).filter(e=>e!==void 0),f=u??(d.length>0?d:void 0),m=a.filter(e=>e.thinking.trim().length>0);if(m.length>0){if(o.requiresThinkingAsText)e.content=[{type:`text`,text:m.map(e=>w(e.thinking)).join(`
|
|
2
2
|
|
|
3
3
|
`)},...t];else if(n.length>0&&(e.content=n),!f){let t=m[0].thinkingSignature;r.provider===`opencode-go`&&t===`reasoning`&&(t=`reasoning_content`),t&&oe(t)&&(e[t]=m.map(e=>e.thinking).join(`
|
|
4
4
|
`))}}else n.length>0&&(e.content=n);c.length>0&&(e.tool_calls=c.map(e=>{let t=s?.grammarToolInputProperties?.get(e.name);return t===void 0?{id:e.id,type:`function`,function:{name:e.name,arguments:JSON.stringify(e.arguments)}}:{id:e.id,type:`custom`,custom:{name:e.name,input:w(p(e.name,e.arguments,t))}}})),f&&(e.reasoning_details=f),o.requiresReasoningContentOnAssistantMessages&&r.reasoning&&e.reasoning_content===void 0&&(e.reasoning_content=``);let h=e.content;if(!(h!=null&&h.length>0)&&!e.tool_calls)continue;l.push(e)}else if(i.role===`toolResult`){let t=[],n=e;for(;n<d.length&&d[n].role===`toolResult`;n++){let e=d[n],i=e.content.filter(F).map(e=>e.text).join(`
|