@fungi.computer/grove 0.2.2 → 0.3.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/{anthropic-messages-CR0lgZ06.js → anthropic-messages-BrTyy87S.js} +3 -3
- package/dist/assets/{azure-openai-responses-CiHqTiGl.js → azure-openai-responses-CxbiKRMB.js} +1 -1
- package/dist/assets/burger-Zw2lKYST.js +1 -0
- package/dist/assets/cat-Dg3HQp8e.js +1 -0
- package/dist/assets/{compat-CXSKceKx.js → compat-DgqxVOn_.js} +2 -2
- 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/{google-generative-ai-DoROu52Y.js → google-generative-ai-0DBJk_8o.js} +1 -1
- package/dist/assets/{google-shared-BnaBv9x_.js → google-shared-BL1Pe-wK.js} +1 -1
- package/dist/assets/{google-vertex-BJP4zrLk.js → google-vertex-DFCQBu0N.js} +1 -1
- 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/{mushroom-CEqJ08xM.js → mushroom-DcQ2lek6.js} +1 -1
- package/dist/assets/{node.browser-CAoro5uc.js → node.browser-C4Y5T0IC.js} +1 -1
- package/dist/assets/{openai-codex-responses-DRHaefx8.js → openai-codex-responses-CK2Z6kMm.js} +1 -1
- package/dist/assets/{openai-completions-BnHZlDfo.js → openai-completions-C35dP-q-.js} +1 -1
- package/dist/assets/{openai-responses-DYr89tDb.js → openai-responses-DPFd_3HO.js} +1 -1
- package/dist/assets/{openai-responses-shared-CIO9CkHC.js → openai-responses-shared-DaKV5GAS.js} +1 -1
- package/dist/assets/parakeet-conversation-Di3EPCdu.js +4 -0
- package/dist/assets/{renderer-BHkhGf2O.js → renderer-cVoUiOqk.js} +1 -1
- package/dist/assets/runtime-core-DOL1texL.js +1 -0
- package/dist/assets/{transform-messages-iF4VkV1V.js → transform-messages-utWG7TCG.js} +1 -1
- package/dist/index.html +3 -3
- package/package.json +10 -10
- 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};
|
|
@@ -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};
|
package/dist/assets/{openai-codex-responses-DRHaefx8.js → openai-codex-responses-CK2Z6kMm.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-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
2
|
|
|
3
3
|
`);let o=i.indexOf(`
|
|
4
4
|
|
|
@@ -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-utWG7TCG.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(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as e,o as t,u as n}from"./preload-helper-DY31Aviq.js";import{t as r}from"./provider-env-CcCbsTJq.js";import{a as i}from"./diagnostics-CxvqSC4Q.js";import{n as a}from"./models-BM_0GHMS.js";import{t as o}from"./headers-FK4rgixo.js";import{h as s,i as c,s as l,u}from"./transform-messages-
|
|
1
|
+
import{d as e,o as t,u as n}from"./preload-helper-DY31Aviq.js";import{t as r}from"./provider-env-CcCbsTJq.js";import{a as i}from"./diagnostics-CxvqSC4Q.js";import{n as a}from"./models-BM_0GHMS.js";import{t as o}from"./headers-FK4rgixo.js";import{h as s,i as c,s as l,u}from"./transform-messages-utWG7TCG.js";import{t as d}from"./provider-retry-RVfYd5Vz.js";import{n as f,t as p}from"./github-copilot-headers-DRgtIyTm.js";import{n as m}from"./openai-Cpe0uoXQ.js";import{n as h,t as g}from"./error-body-pkrba6pf.js";import{t as _}from"./openai-prompt-cache-DXo9f3w5.js";import{n as v,r as y,t as b}from"./openai-responses-shared-DaKV5GAS.js";var x=new Set([`openai`,`openai-codex`,`opencode`]),S=16,C=`https://chatgpt.com/settings/usage`,w=`medium`;function T(e,t){return e.provider===`openai`&&e.baseUrl===`https://api.openai.com/v1`&&t!==void 0&&!t.startsWith(`sk-`)}function E(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 D(e,t,n){if(t)return t;if(E(n,`authorization`)||E(n,`cf-aig-authorization`))return`unused`;throw Error(`No API key for provider: ${e}`)}function O(e){return e.provider===`openrouter`||e.baseUrl.includes(`openrouter.ai`)?`openrouter`:`openai`}function k(e,t){return e||(r(`PI_CACHE_RETENTION`,t)===`long`?`long`:`short`)}function A(e){return{supportsDeveloperRole:e.compat?.supportsDeveloperRole??!0,supportsMidConvoSystemMessages:e.compat?.supportsMidConvoSystemMessages??!1,sessionAffinityFormat:e.compat?.sessionAffinityFormat??O(e),supportsLongCacheRetention:e.compat?.supportsLongCacheRetention??!0,supportsStrictMode:e.compat?.supportsStrictMode??!1,supportsOpenAIGrammarTools:e.compat?.supportsOpenAIGrammarTools??!1,supportsAdditionalTools:e.compat?.supportsAdditionalTools??!1,supportsToolSearch:e.compat?.supportsToolSearch??!1,supportsExplicitPromptCacheMode:e.compat?.supportsExplicitPromptCacheMode??!1,supportsMaxOutputTokens:e.compat?.supportsMaxOutputTokens??!0,supportsMidConvoEffort:e.compat?.supportsMidConvoEffort??!1}}function j(e,t,n){if(!(!n.supportsMidConvoEffort||!t?.reasoningEffort||T(e,t.apiKey)))return e.thinkingLevelMap?.[t.reasoningEffort]??t.reasoningEffort}function M(e,t){return t===`long`&&e.supportsLongCacheRetention&&!e.supportsExplicitPromptCacheMode?`24h`:void 0}function N(e,t){if(e.supportsExplicitPromptCacheMode){if(t===`none`)return{mode:`explicit`};if(t===`long`&&e.supportsLongCacheRetention)return{ttl:`30m`}}}var P=(e,r,a)=>{let s=new i,c=n(r,A(e).supportsMidConvoSystemMessages);return(async()=>{let n=A(e),r=j(e,a,n),i={role:`assistant`,content:[],api:e.api,provider:e.provider,model:e.id,...r===void 0?{}:{providerThinkingLevel:r},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 l=D(e.provider,a?.apiKey,a?.headers),f=k(a?.cacheRetention,a?.env)===`none`?void 0:a?.sessionId,p=u(t(c.messages),n.supportsOpenAIGrammarTools),m=I(e,c,l,a?.headers,a?.fetch,f),h=L(e,c,a,n,p,r),g=await a?.onPayload?.(h,e);g!==void 0&&(h=g);let _={...a?.signal?{signal:a.signal}:{},...a?.timeoutMs===void 0?{}:{timeout:a.timeoutMs},maxRetries:0},{data:v,response:b}=await d(()=>m.responses.create(h,_).withResponse(),{maxRetries:a?.maxRetries,maxRetryDelayMs:a?.maxRetryDelayMs,signal:a?.signal});if(await a?.onResponse?.({status:b.status,headers:o(b.headers)},e),s.push({type:`start`,partial:i}),await y(v,i,s,e,{onProviderStreamEvent:a?.onProviderStreamEvent,serviceTier:a?.serviceTier,grammarToolInputProperties:p,applyServiceTierPricing:(t,n)=>z(t,n,e)}),a?.signal?.aborted)throw Error(`Request was aborted`);if(i.stopReason===`pending`)throw Error(`OpenAI Responses stream ended without a stop reason`);if(i.stopReason===`aborted`||i.stopReason===`error`)throw Error(i.errorMessage||`An unknown error occurred`);s.push({type:`done`,reason:i.stopReason,message:i}),s.end()}catch(t){for(let e of i.content)delete e.index,delete e.partialJson,delete e.customInput;i.stopReason=a?.signal?.aborted?`aborted`:`error`;let n=g(h(t),`${e.provider===`openai`?`OpenAI`:e.provider} API error`);i.errorMessage=n.includes(`subscription_sharing_usage_limit_exceeded`)?`${n}\nCheck your ChatGPT usage: ${C}`:n,s.push({type:`error`,reason:i.stopReason,error:i}),s.end()}})(),s},F=(e,t,n)=>{D(e.provider,n?.apiKey,n?.headers);let r={...c(e,t,n,n?.apiKey),toolChoice:n?.toolChoice},i=n?.reasoning?a(e,n.reasoning):void 0,o=i===`off`?void 0:i;return P(e,t,{...r,reasoningEffort:o})};function I(e,t,n,r,i,a){let o=A(e),c={"User-Agent":s(),...e.headers};if(e.provider===`github-copilot`){let e=f(t.messages),n=p({messages:t.messages,hasImages:e});Object.assign(c,n)}return a&&(o.sessionAffinityFormat===`openrouter`?c[`x-session-id`]=a:(o.sessionAffinityFormat===`openai`&&(c.session_id=a),c[`x-client-request-id`]=a)),r&&Object.assign(c,r),new m({apiKey:n,baseURL:e.baseUrl,dangerouslyAllowBrowser:!0,fetch:i,defaultHeaders:c})}function L(t,n,r,i,a,o){let s=e(n.messages,i.supportsAdditionalTools||i.supportsToolSearch),c=b(t,n,x,{grammarToolInputProperties:a,supportsMidConvoSystemMessages:i.supportsMidConvoSystemMessages,supportsAdditionalTools:i.supportsAdditionalTools,supportsToolSearch:i.supportsToolSearch,toolOptions:{supportsStrictMode:i.supportsStrictMode,supportsOpenAIGrammarTools:i.supportsOpenAIGrammarTools},configurationUpdateEffort:o}),u=k(r?.cacheRetention,r?.env),d=T(t,r?.apiKey),f={model:t.id,input:c,stream:!0,prompt_cache_key:u===`none`?void 0:_(r?.sessionId),prompt_cache_retention:d?void 0:M(i,u),prompt_cache_options:d?void 0:N(i,u),store:!1};r?.maxTokens&&i.supportsMaxOutputTokens&&!d&&(f.max_output_tokens=Math.max(r.maxTokens,S)),r?.temperature!==void 0&&!d&&(f.temperature=r?.temperature),r?.serviceTier!==void 0&&(f.service_tier=r.serviceTier),s.requestTools.length>0&&(f.tools=v(s.requestTools,{supportsStrictMode:i.supportsStrictMode,supportsOpenAIGrammarTools:i.supportsOpenAIGrammarTools})),r?.toolChoice!==void 0&&(f.tool_choice=r.toolChoice);let p=r?.reasoningEffort??(r?.reasoningSummary?`medium`:void 0);if(t.reasoning){if(p){let e=r?.reasoningEffort?t.thinkingLevelMap?.[r.reasoningEffort]??r.reasoningEffort:p;f.reasoning={effort:o===void 0?e:w,summary:r?.reasoningSummary||`auto`},f.include=[`reasoning.encrypted_content`]}else t.provider!==`github-copilot`&&t.thinkingLevelMap?.off!==null&&(f.reasoning={effort:t.thinkingLevelMap?.off??`none`});t.provider===`xai`&&(f.include=[`reasoning.encrypted_content`])}let m=l(t,p??`off`,r?.samplingParams);return m&&Object.assign(f,m),f}function R(e,t){switch(t){case`flex`:return .5;case`priority`:case`fast`:return e.id===`gpt-5.5`?2.5:2;default:return 1}}function z(e,t,n){let r=R(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)}export{P as stream,F as streamSimple};
|
package/dist/assets/{openai-responses-shared-CIO9CkHC.js → openai-responses-shared-DaKV5GAS.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{d as e,h as t,m as n,u as r}from"./preload-helper-DY31Aviq.js";import{t as i}from"./models-BM_0GHMS.js";import{n as a,r as o}from"./json-parse-M7s0500m.js";import{d as s,f as c,l,m as u,n as d,p as f}from"./transform-messages-
|
|
1
|
+
import{d as e,h as t,m as n,u as r}from"./preload-helper-DY31Aviq.js";import{t as i}from"./models-BM_0GHMS.js";import{n as a,r as o}from"./json-parse-M7s0500m.js";import{d as s,f as c,l,m as u,n as d,p as f}from"./transform-messages-utWG7TCG.js";import{t as p}from"./sanitize-unicode-DmIE6hZJ.js";import{t as m}from"./hash-yQufAZII.js";function h(e,t){let n={v:1,id:e};return t&&(n.phase=t),JSON.stringify(n)}function g(e){if(e){if(e.startsWith(`{`))try{let t=JSON.parse(e);if(t.v===1&&typeof t.id==`string`)return t.phase===`commentary`||t.phase===`final_answer`?{id:t.id,phase:t.phase}:{id:t.id}}catch{}return{id:e}}}function _(e,t){let n=t.filter(e=>e.type===`text`).map(e=>e.text).join(`
|
|
2
2
|
`),r=t.filter(e=>e.type===`image`),i=n.length>0;if(r.length===0||!e.input.includes(`image`))return p(i?n:r.length>0?`(see attached image)`:`(no tool output)`);let a=[];i&&a.push({type:`input_text`,text:p(n)});for(let e of r)a.push({type:`input_image`,detail:`auto`,image_url:`data:${e.mimeType};base64,${e.data}`});return a}function v(i,a,o,c){let l=r(a,c?.supportsMidConvoSystemMessages),u=[],f=e=>{let t=e.replace(/[^a-zA-Z0-9_-]/g,`_`);return(t.length>64?t.slice(0,64):t).replace(/_+$/,``)},h=e=>{let t=`fc_${m(e)}`;return t.length>64?t.slice(0,64):t},v=d(l.messages,i,(e,t,n)=>{if(!o.has(i.provider)||!e.includes(`|`))return f(e);let[r,a]=e.split(`|`),s=f(r),c=n.provider!==i.provider||n.api!==i.api?h(a):f(a);return c.startsWith(`fc_`)||(c=f(`fc_${c}`)),`${s}|${c}`}),b=e(l.messages,(c?.supportsAdditionalTools??!1)||(c?.supportsToolSearch??!1)),x=(e,t)=>{let n=b.anchorsAdditions?e.toolsAdded??[]:[];if(n.length===0)return;if(c?.supportsAdditionalTools){u.push({type:`additional_tools`,role:`developer`,tools:y(n,c.toolOptions)});return}if(!c?.supportsToolSearch)return;let r=n.map(e=>e.name),i=`pi_tool_load_${m(`${t}:${r.join(`,`)}`)}`;u.push({type:`tool_search_call`,call_id:i,execution:`client`,status:`completed`,arguments:{query:r.join(` `),limit:r.length}}),u.push({type:`tool_search_output`,call_id:i,execution:`client`,status:`completed`,tools:y(n,{...c.toolOptions,toolSearchResult:!0})})},S=c?.includeSystemPrompt??!0,C=e=>{u.push({type:`configuration_update`,reasoning:{effort:e}})},w=i.compat,T=i.reasoning&&w?.supportsDeveloperRole!==!1?`developer`:`system`,E=0,D=0;for(let e of v){let r=D++===0&&e.role===`system`;if(e.role===`system`){if(r||x(e,`system:${E}`),!r||S){let i=r?n(e):t(e);i.length>0&&u.push({role:T,content:p(i)})}}else if(e.role===`user`){if(typeof e.content==`string`)u.push({role:`user`,content:[{type:`input_text`,text:p(e.content)}]});else{let t=e.content.map(e=>e.type===`text`?{type:`input_text`,text:p(e.text)}:{type:`input_image`,detail:`auto`,image_url:`data:${e.mimeType};base64,${e.data}`});if(t.length===0)continue;u.push({role:`user`,content:t})}}else if(e.role===`assistant`){let t=[],n=e,r=n.provider===i.provider&&n.api===i.api,a=r&&n.model===i.id,o=r&&n.model!==i.id,l=0;for(let n of e.content)if(n.type===`thinking`){if(n.thinkingSignature){let e=JSON.parse(n.thinkingSignature);t.push(e)}}else if(n.type===`text`){let e=n,r=g(e.textSignature),i=l===0?`msg_pi_${E}`:`msg_pi_${E}_${l}`;l++;let a=r?.id;a?a.length>64&&(a=`msg_${m(a)}`):a=i,t.push({type:`message`,role:`assistant`,content:[{type:`output_text`,text:p(e.text),annotations:[]}],status:`completed`,id:a,phase:r?.phase})}else if(n.type===`toolCall`){let e=n,[r,i]=e.id.split(`|`),l=c?.grammarToolInputProperties?.get(e.name),u=i,d=l===void 0?`fc_`:`ctc_`;(o||!u?.startsWith(d))&&(u=void 0),l===void 0?t.push({type:`function_call`,id:u,call_id:r,name:e.name,arguments:JSON.stringify(e.arguments),...a&&e.namespace!==void 0?{namespace:e.namespace}:{}}):t.push({type:`custom_tool_call`,id:u,call_id:r,name:e.name,input:p(s(e.name,e.arguments,l)),...a&&e.namespace!==void 0?{namespace:e.namespace}:{}})}if(t.length===0)continue;c?.configurationUpdateEffort!==void 0&&a&&e.providerThinkingLevel!==void 0&&C(e.providerThinkingLevel),u.push(...t)}else if(e.role===`toolResult`){let[t]=e.toolCallId.split(`|`),n=_(i,e.content);c?.grammarToolInputProperties?.has(e.toolName)?u.push({type:`custom_tool_call_output`,call_id:t,output:n}):u.push({type:`function_call_output`,call_id:t,output:n})}r||E++}return c?.configurationUpdateEffort!==void 0&&C(c.configurationUpdateEffort),u}function y(e,t){let n=t?.strict!==void 0&&t.strict,r=t?.supportsStrictMode??!0,i=t?.supportsOpenAIGrammarTools??!1;return e.map(e=>{let a=f(e,i);if(a)return{type:`custom`,name:e.name,description:e.description,format:{type:`grammar`,syntax:a.format,definition:a.definition},...t?.toolSearchResult?{defer_loading:!0}:{}};let o=u(e,r)??n,s={type:`function`,name:e.name,description:e.description,parameters:c(e,o===!0),...t?.toolSearchResult?{defer_loading:!0}:{}};return r&&(s.strict=o),s})}function b(e){let t=e.customInput?.property;if(t===void 0)return``;let n=e.arguments[t];return typeof n==`string`?n:``}function x(e,t,n){let r=e.customInput;if(!r)return;let i=l(r.jsonBuffer,r.property,t,n);return e.arguments={[r.property]:t},i}async function S(e,t,n,r,s){let c=!1,l=new Map,u=new Map,d=e=>{e.type===`message`&&e.phase===`final_answer`&&(t.stopReason=`stop`)},f=(e,t)=>{let n=l.get(e);return n?.type===t?n:void 0},p=(e,r)=>{r!==void 0&&n.push({type:`toolcall_delta`,contentIndex:e.contentIndex,delta:r,partial:t})},m=(e,r)=>{if(r.type===`reasoning`){let r={type:`thinking`,thinking:``};t.content.push(r);let i={type:`thinking`,block:r,contentIndex:t.content.length-1};return l.set(e,i),n.push({type:`thinking_start`,contentIndex:i.contentIndex,partial:t}),i}if(r.type===`message`){d(r);let i={type:`text`,text:``};t.content.push(i);let a={type:`text`,block:i,contentIndex:t.content.length-1};return l.set(e,a),n.push({type:`text_start`,contentIndex:a.contentIndex,partial:t}),a}if(r.type===`function_call`){let i={type:`toolCall`,id:`${r.call_id}|${r.id}`,name:r.name,arguments:{},...r.namespace===void 0?{}:{namespace:r.namespace},partialJson:r.arguments||``};t.content.push(i);let a={type:`toolCall`,block:i,contentIndex:t.content.length-1};return l.set(e,a),n.push({type:`toolcall_start`,contentIndex:a.contentIndex,partial:t}),a}if(r.type===`custom_tool_call`){let i=s?.grammarToolInputProperties?.get(r.name)??`input`,a=r.input||``,o={type:`toolCall`,id:`${r.call_id}|${r.id}`,name:r.name,arguments:{[i]:a},...r.namespace===void 0?{}:{namespace:r.namespace},customInput:{property:i,jsonBuffer:{input:``,started:!1,closed:!1}}};t.content.push(o);let c={type:`toolCall`,block:o,contentIndex:t.content.length-1};return l.set(e,c),n.push({type:`toolcall_start`,contentIndex:c.contentIndex,partial:t}),c}},g=(e,t)=>l.get(e)??m(e,t),_=e=>{for(let t of e){if(t.type!==`reasoning`||!t.encrypted_content)continue;let e=u.get(t.id);if(!e?.thinkingSignature)continue;let n=JSON.parse(e.thinkingSignature);n.encrypted_content||(e.thinkingSignature=JSON.stringify({...n,encrypted_content:t.encrypted_content}))}},v=e=>{if(c=!0,_(e.output??[]),e?.id&&(t.responseId=e.id),e?.usage){let n=e.usage.input_tokens_details,r=n?.cached_tokens||0,i=n?.cache_write_tokens||0;t.usage={input:Math.max(0,(e.usage.input_tokens||0)-r-i),output:e.usage.output_tokens||0,cacheRead:r,cacheWrite:i,reasoning:e.usage.output_tokens_details?.reasoning_tokens||0,totalTokens:e.usage.total_tokens||0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}}}if(i(r,t.usage),s?.applyServiceTierPricing){let n=s.resolveServiceTier?s.resolveServiceTier(e?.service_tier,s.serviceTier):e?.service_tier??s.serviceTier;s.applyServiceTierPricing(t.usage,n)}let n=e?.status,a=e?.incomplete_details,o=typeof a?.reason==`string`?a.reason:void 0;t.rawStopReason=o?`${n}.${o}`:n;let l=C(n,o);t.stopReason=l.stopReason,l.errorMessage===void 0?delete t.errorMessage:t.errorMessage=l.errorMessage,t.content.some(e=>e.type===`toolCall`)&&t.stopReason===`stop`&&(t.stopReason=`toolUse`)};for await(let i of e)if(await s?.onProviderStreamEvent?.(i,r),i.type===`response.created`)t.responseId=i.response.id;else if(i.type===`response.output_item.added`)m(i.output_index,i.item);else if(i.type===`response.reasoning_summary_text.delta`){let e=f(i.output_index,`thinking`);if(!e)continue;e.block.thinking+=i.delta,n.push({type:`thinking_delta`,contentIndex:e.contentIndex,delta:i.delta,partial:t})}else if(i.type===`response.reasoning_summary_part.done`){let e=f(i.output_index,`thinking`);if(!e)continue;e.block.thinking+=`
|
|
3
3
|
|
|
4
4
|
`,n.push({type:`thinking_delta`,contentIndex:e.contentIndex,delta:`
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{Qn as t,Wi as n,aa as r,ca as i,er as a,ia as o,la as s,ma as c,pa as l,pt as u,va as d,ya as f}from"./Effect-BY0T-p9d.js";import{$i as p,Ai as m,Ar as h,Dr as ee,Er as g,Gi as _,Gr as te,Ir as v,Kr as y,Li as b,Lr as x,Ni as S,Nr as C,Or as w,Pr as ne,Ur as T,Vi as E,Wr as D,Yi as O,ei as k,fi as A,i as j,ia as M,ii as re,mi as ie,na as ae,qr as N,ra as P,ri as F,ti as oe,ui as se,vi as I,xi as ce}from"./extension-hook-CBuX_bUG.js";import{$ as le,J as ue,K as de,Q as L,X as fe,Y as pe,Z as me,_ as R,a as he,at as ge,c as _e,et as ve,g as ye,h as be,i as xe,it as Se,l as Ce,m as we,nt as z,o as Te,ot as Ee,p as De,q as Oe,r as ke,rt as Ae,s as je,tt as Me,v as B}from"./index-HgPChePI.js";import"./extensions-DEfvRHbZ.js";var V=y.check(O(1),_(256)),Ne=C.check(S(1),E(2**53-1)),Pe=C.check(S(0),E(2**53-1)),Fe=x([`write`,`external`]),Ie=N({module:T(V),access:Fe}),Le=N({agentId:T(V)}),Re=N({principalId:V,agentId:T(V),sessionId:T(V),displayName:V}),ze=N({title:y.check(O(1),_(512)),inputBytes:C.check(S(0)),inputSha256:y.check(p(/^[a-f0-9]{64}$/))}),Be=N({kind:v(`pending_approval`),recordId:V,description:ze}),Ve=x([`requested`,`pending`,`approved`,`claimed`,`applied`,`denied`,`expired`,`outcome_unknown`]),He=x([`not-found`,`not-eligible`,`already-answered`,`stale-revision`,`expired`,`declined`,`fenced`,`not-granted`,`read-only`,`pending`,`in-flight`,`outcome-unknown`,`identity-conflict`]),Ue=y.check(O(1),_(512),p(/^(?=.*\S)[^\p{Cc}\u2028\u2029]*$/u)),We=w(N({kind:v(`artifact`),ref:y.check(p(/^sha256:[a-f0-9]{64}$/)),mediaType:v(`image/png`),bytes:C.check(S(1),E(5242880))})).check(_(4)),Ge=N({recordId:V,requester:Re,module:V,operation:V,access:Fe,description:ze,evidence:M(We),authorityFence:V,reversibility:x([`reversible`,`irreversible-external`]),state:Ve,by:T(k([N({kind:v(`human`),memberId:V}),N({kind:v(`policy`)})])),reason:T(He),denialNote:M(Ue),requestedAt:Pe,expiresAt:Pe,updatedAt:Pe,revision:Ne}),Ke=N({record:Ge,canAnswer:h,canSetAutoApprove:h});N({state:M(Ve),cursor:M(V),limit:M(C.check(S(1),E(100)))}),N({recordId:V}),N({recordId:V,decision:x([`approve`,`deny`]),expectedRevision:Ne,denialNote:M(Ue)});var qe=N({scope:Le,family:Ie,enabled:h}),Je=N({kind:v(`refused`),reason:He,denialNote:M(Ue)});A(I(Ge),{onExcessProperty:`error`}),ie(I(Ge)),A(N({record_json:y})),A(I(ne)),ie(I(ne)),A(N({input_json:y,output_json:T(y)}));var Ye=Je,Xe=N({items:w(Ke),nextCursor:T(y)}),Ze=k([N({kind:v(`answered`),view:Ke}),Ye]),Qe=k([N({kind:v(`updated`),rule:qe}),Ye]),H=e=>ve(d().transform(t=>A(e,{onExcessProperty:`error`})(t))),U=Ae(`approvals`,1,o(()=>Me({list:z(H(Xe)),get:z(H(T(Ke))),answer:z(H(Ze)),setAutoApprove:z(H(Qe))}))),W=re(e=>ye.safeParse(e).success,{representation:{id:`@fungi.computer/whistle/catalog-step/v1`,payload:null}});u(()=>g());var G=y.pipe(F(O(1)),F(_(4e3)),F(p(/\S/u,{message:`Goal objective is blank`}))),$e=y.pipe(F(O(1)),F(_(1e3)),F(p(/\S/u))),et=y.pipe(F(O(1)),F(_(256))),tt=C.check(S(0)),nt=N({kind:x([`person`,`blocked`,`stalled`,`cancelled`,`failed`,`no-terminal`]),detail:T(y)}),K=N({revision:y,objective:G,state:x([`active`,`paused`]),startedAt:tt,pauseCause:T(nt)}),rt=N({sequence:C.check(m(0)),objective:G,outcome:x([`achieved`,`cleared`]),reason:T($e),endedAt:tt,afterSequence:C.check(S(0))}),it=k([N({action:v(`set`),objective:G,requestId:et,expectedRevision:P(T(y)),confirmed:P(h)}),N({action:x([`pause`,`resume`,`replace`,`clear`,`clear-ask`]),confirmed:P(h)}),N({})]),at=N({goal:T(K),ended:w(rt).check(_(16)),omitted:C.check(S(0))}),ot={id:j.make(`botanical-session-goal`),commands:{goal:{scope:`session`,input:it,output:W},pause:{scope:`session`,input:N({}),output:K},resume:{scope:`session`,input:N({}),output:K},clear:{scope:`session`,input:N({}),output:N({})},set:{scope:`session`,input:N({objective:G,expectedRevision:T(y),requestId:et}),output:N({goal:K,accepted:N({status:v(`accepted`),commandId:y})})}},projection:{schema:at}},q=e=>{let t=e.replace(/\s+/gu,` `).trim();return t.length<=80?t:`${t.slice(0,79)}…`},st=e=>{let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`};function ct(e){let t=e.state===`active`,n=t?`Pursuing goal since ${st(e.startedAt)}`:`Goal paused (/goal resume)`,r=!t&&e.pauseCause?.detail!=null?[q(e.pauseCause.detail)]:[],i={id:`goal`,title:[n,q(e.objective),...r].join(` · `),tone:t?`running`:`muted`,actions:[{id:`goal`,label:t?`Pause goal`:`Resume goal`,input:{action:t?`pause`:`resume`}}]};return q(e.objective)===e.objective?i:{...i,detail:e.objective.slice(0,1024)}}function lt(e){let t={id:`goal-ended`,title:`${e.outcome===`achieved`?`Goal achieved`:`Goal cleared`} · ${q(e.objective)}`,tone:e.outcome===`achieved`?`settled`:`muted`},n=e.reason===null?t:{...t,detail:e.reason};return{id:String(e.sequence),sequence:e.sequence,at:e.endedAt,commandId:null,afterSequence:e.afterSequence,rows:[n]}}var ut=R(ot,{promptPresentation:`footer`,contribute:e=>{if(e.status!==`running`||e.value===null)return{chips:[],panel:[],timeline:{cells:[],omitted:0},waiting:null};let{goal:t,ended:n,omitted:r}=e.value;return{chips:[],panel:t===null?[]:[ct(t)],timeline:{cells:n.map(lt),omitted:r},waiting:null}}}),J=y.pipe(F(O(1)),F(_(262144))),dt=y.pipe(F(O(1)),F(_(200))),ft=N({expression:y.pipe(F(O(1)),F(_(256))),timeZone:y.pipe(F(O(1)),F(_(128)))}),Y=N({loopId:y,origin:x([`human`,`model`]),expiresAt:T(C),prompt:J,mode:x([`self_paced`,`fixed_interval`]),cron:T(ft),state:x([`active`,`paused`,`finished`,`failed`,`cancelled`]),commandId:y,reason:T(y),nextDueAt:T(C),lastError:T(y),consecutiveFailures:C.pipe(F(S(0)))}),pt=N({loop:Y,accepted:N({status:v(`accepted`),commandId:y})}),mt=k([N({action:v(`start`),text:J,requestId:dt}),N({action:x([`status`,`pause`,`resume`,`stop`,`stop-ask`,`new`]),confirmed:P(h)}),N({})]),ht=N({loop:Y}),gt={id:j.make(`botanical-session-loop`),commands:{loop:{scope:`session`,input:mt,output:W},startSelfPaced:{scope:`session`,input:N({prompt:J,requestId:dt}),output:pt},startFixedInterval:{scope:`session`,input:N({prompt:J,requestId:dt,...ft.fields}),output:pt},pause:{scope:`session`,input:N({}),output:Y},resume:{scope:`session`,input:N({}),output:Y},stop:{scope:`session`,input:N({}),output:Y}},projection:{schema:ht}},_t=e=>{let t=e.replace(/\s+/gu,` `).trim();return t.length<=60?t:`${t.slice(0,59)}…`},vt=e=>e.state===`failed`?`error`:e.state===`active`?`running`:e.state===`paused`?`muted`:`settled`,yt=e=>new Intl.DateTimeFormat(void 0,{year:`numeric`,month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,timeZoneName:`short`}).format(e),bt=R(gt,{promptPresentation:`footer`,contribute:e=>{if(e.status!==`running`||e.value===null)return{chips:[],panel:[],timeline:{cells:[],omitted:0},waiting:null};let{loop:t}=e.value,n=t.state===`active`&&t.nextDueAt!==null;return{chips:t.state!==`active`&&t.state!==`paused`?[]:[{id:`loop`,order:2,row:{id:`loop`,title:`Loop ${t.mode===`self_paced`?`self-paced`:`fixed`}${n?` (waiting)`:``}`,tone:vt(t)}}],panel:[{id:`loop`,title:`Loop · ${t.state} · ${t.mode===`self_paced`?`self-paced`:`${t.cron?.expression??`fixed`} ${t.cron?.timeZone??``}`}${t.nextDueAt===null?``:` · Next ${yt(t.nextDueAt)}`} · ${_t(t.prompt)}`,detail:[t.reason,t.prompt].filter(e=>e!==null).join(`
|
|
2
|
+
`).slice(0,1024),tone:vt(t)},...t.lastError===null?[]:[{id:`error`,title:t.lastError.slice(0,4096),tone:`error`}]],timeline:{cells:[],omitted:0},waiting:n?{summary:`Waiting until ${yt(t.nextDueAt)}`,cancel:{id:`loop`,label:`stop loop`,input:{action:`stop-ask`}}}:null}}});function xt(e){return N({nextSequence:C.check(m(0)),omitted:C.check(S(0)),events:w(N({id:y,sequence:C,at:C,commandId:T(y),event:e}))})}new TextEncoder;var St=N({explanation:M(y.pipe(F(_(2e3)))),steps:w(N({step:y.pipe(F(O(1)),F(_(500))),status:x([`pending`,`in_progress`,`completed`])})).pipe(F(_(50)))});St.pipe(F(ae(e=>e.steps.filter(e=>e.status===`in_progress`).length<=1||`At most one plan step may be in progress`)));function Ct(e){return e.steps.some(e=>e.status!==`completed`)}var wt=N({plan:St,history:xt(St)}),Tt=k([N({action:v(`clear`)}),N({})]),Et={id:j.make(`botanical-session-plan`),commands:{plan:{scope:`session`,input:Tt,output:W}},projection:{schema:wt}},Dt=e=>{let t=e.steps.findIndex(e=>e.status===`in_progress`),n=e.steps.filter(e=>e.status===`completed`).length;return{title:(t<0?e.steps.find(e=>e.status===`pending`):e.steps[t])?.step??`Plan complete`,detail:`${String(t<0?n:t+1)}/${String(e.steps.length)}`}},Ot=e=>e.steps.map((e,t)=>({id:String(t),title:e.step,tone:e.status===`completed`?`settled`:e.status===`in_progress`?`running`:`muted`})),kt=R(Et,{contribute:e=>({chips:[],panel:e.status!==`running`||e.value===null||!Ct(e.value.plan)?[]:[{id:`plan`,...Dt(e.value.plan),actions:[{id:`plan`,label:`Clear plan`,input:{action:`clear`}}],inspection:{commandId:`plan`,title:`Plan`,rows:Ot(e.value.plan)}}],timeline:{cells:[],omitted:0},waiting:null})}),X=e=>y.check(O(1),_(e),p(/\S/u)),At=N({id:X(32).check(p(/^[a-z][a-z0-9]*(?:[-_.][a-z0-9]+)*$/u)),header:X(12),question:X(1e3),options:w(N({label:X(60),description:X(300)})).check(O(2),_(4),ae(e=>new Set(e.map(e=>e.label)).size===e.length||`Option labels must be unique`,{representation:{id:`botanical/ask/unique-option-labels`,payload:null}})),multiple:M(h)}),jt=w(At).check(O(1),_(4),ae(e=>new Set(e.map(e=>e.id)).size===e.length||`Question ids must be unique`,{representation:{id:`botanical/ask/unique-question-ids`,payload:null}})),Mt=N({askId:y,questions:jt,status:x([`live`,`parked`]),createdAt:D,expiresAt:T(D)}),Nt=N({asks:w(Mt).check(_(4))}),Z=X(256),Pt=te(At.fields.id,N({selected:w(X(60)).check(_(4)),text:M(y.check(_(4e3)))})),Ft=N({askId:X(256),requestId:Z,answers:Pt}),It=N({askId:X(256),requestId:Z,note:M(y.check(_(4e3)))}),Lt=x([`answered`,`declined`,`withdrawn`,`expired`,`cancelled`,`undeliverable`]),Rt=k([N({result:v(`accepted`),via:x([`in_turn`,`follow_up`])}),N({result:v(`closed`),status:Lt}),N({result:v(`not_found`)})]),zt={askId:Ft.fields.askId,requestId:Z,index:D.check(b(),ce({minimum:0,maximum:3})),answers:Pt},Bt=k([N({stage:v(`multiple`),...zt,selection:y.check(_(1e3))}),N({stage:v(`selection`),...zt,selection:y.check(_(1e3))}),N({stage:v(`text`),...zt,selected:Pt.value.fields.selected,text:y.check(_(4e3))}),N({askId:Ft.fields.askId}),N({})]),Vt={id:j.make(`botanical-session-question`),commands:{answerFlow:{scope:`session`,input:Bt,output:W},answer:{scope:`session`,input:Ft,output:Rt},decline:{scope:`session`,input:It,output:Rt},list:{scope:`session`,input:N({}),output:Nt}},projection:{schema:Nt}},Ht=R(Vt,{contribute:e=>({chips:[],panel:e.status!==`running`||e.value===null?[]:e.value.asks.map(e=>{let t=e.questions[0];return{id:e.askId,title:`${t?.question??`Question`}${e.questions.length>1?` (+${String(e.questions.length-1)} more)`:``}`,detail:t?.options.map(e=>e.label).join(` · `)??``,tone:`attention`,actions:[{id:`answerFlow`,label:`Answer`,input:{askId:e.askId}}]}}),timeline:{cells:[],omitted:0},waiting:null})}),Ut=y.check(O(1),_(256)),Wt=x([`working`,`waiting`,`idle`,`failed`,`unavailable`]),Gt=N({agentId:Ut,name:Ut,sessionId:T(Ut),state:Wt,attention:M(y.check(_(200)))}),Kt=N({agents:w(Gt).check(_(16)),more:C.check(S(0)),expanded:h}),qt={agents:{scope:`session`,input:N({}),output:W}},Jt={id:j.make(`botanical-session-subagents`),commands:qt,projection:{schema:Kt}},Yt={working:{label:`working`,tone:`running`,status:`info`},waiting:{label:`waiting on you`,tone:`attention`,status:`warning`},idle:{label:`idle`,tone:`settled`,status:`success`},failed:{label:`failed`,tone:`error`,status:`error`},unavailable:{label:`unavailable`,tone:`muted`,status:`neutral`}};function Xt(e){let t=Yt[e.state],n={id:e.agentId,title:`${e.name} · ${t.label}`,tone:t.tone,status:{label:t.label,tone:t.status}},r=e.attention===void 0?n:{...n,detail:e.attention};return e.sessionId===null?{...r,detail:e.attention??`not messaged yet`}:{...r,open:{params:[{key:`agent`,value:e.agentId},{key:`session`,value:e.sessionId}]}}}function Zt(e){let t=t=>e.agents.filter(e=>e.state===t).length,n=[`working`,`waiting`,`failed`,`unavailable`].map(e=>[e,t(e)]).filter(([,e])=>e>0).map(([e,t])=>`${String(t)} ${Yt[e].label}`),r=e.agents.length+e.more,i=t(`waiting`)>0?`attention`:t(`failed`)>0?`error`:t(`working`)>0?`running`:`muted`;return{id:`summary`,title:[`${String(r)} sub-agent${r===1?``:`s`}`,...n,`/agents shows them`].join(` · `),tone:i}}var Qt=R(Jt,{contribute:e=>({chips:[],panel:e.status!==`running`||e.value===null?[]:e.value.agents.length>0&&!e.value.expanded?[Zt(e.value)]:[...e.value.agents.map(Xt),...e.value.more===0?[]:[{id:`more`,title:`${String(e.value.more)} more sub-agent${e.value.more===1?``:`s`}`,tone:`muted`}]],timeline:{cells:[],omitted:0},waiting:null})});function $t(e,t){if(e===null||!URL.canParse(t))return!1;let n=new URL(t);return n.protocol!==`https:`||n.hash!==`#team-billing`?!1:(e.openTeamBilling().catch(t=>(console.error(`Chat Billing navigation failed`,t),e.showToast({message:`Billing could not be opened. Please try again.`,tone:`error`}))),!0)}function en(e,t){e!==null&&e.showToast({message:t.message,tone:t.variant}).catch(e=>{console.error(`Chat toast failed`,e)})}var Q=e(Ee(),1),$=ge();function tn(e){if(e.name!==`execute`||e.status!==`completed`)return;let n=e.result?.content;if(n?.length!==1||n[0]?.type!==`text`)return;let r=se(I(oe))(n[0].text);if(t(r))return;let i=be.safeParse(r.value);return i.success?i.data.file:void 0}function nn({item:e,ui:t}){let n=tn(e),[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(!1);if(!n)return null;let s=async()=>{i(!0),o(!1);try{await t.openNavigation(n)}catch(e){console.error(`Chat file navigation failed`,e),o(!0)}finally{i(!1)}};return(0,$.jsxs)(`div`,{className:`px-3 py-2`,children:[(0,$.jsx)(B,{variant:`ghost`,size:`sm`,disabled:r,onClick:()=>void s(),type:`button`,children:r?`Opening file…`:`Open ${n.path} in Inkcap`}),a?(0,$.jsx)(`p`,{role:`alert`,children:`The file could not be opened. Try again.`}):null]})}var rn=l({kind:r(`generated`),file:l({computerId:c().min(1),path:c().min(1)}),format:n([`png`,`jpeg`,`gif`,`webp`,`mp4`]),width:i(),height:i(),bytes:i(),costMilliunits:i(),receipt:c()});function an(e){if(e.name!==`execute`||e.status!==`completed`)return;let n=e.result?.content??[],r=n.at(0);if(r?.type!==`text`||n.slice(1).some(e=>e.type!==`image`))return;let i=se(I(oe))(r.text);if(t(i))return;let a=rn.safeParse(i.value);return a.success?a.data:void 0}function on({item:e,ui:t}){let n=an(e),[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(!1);if(!n)return null;let s=async()=>{i(!0),o(!1);try{await t.openNavigation(n.file)}catch(e){console.error(`Chat image navigation failed`,e),o(!0)}finally{i(!1)}};return(0,$.jsxs)(`div`,{className:`px-3 py-2`,children:[(0,$.jsx)(B,{variant:`ghost`,size:`sm`,disabled:r,onClick:()=>void s(),type:`button`,children:r?`Opening file…`:`Open ${n.file.path} in Inkcap`}),a?(0,$.jsx)(`p`,{role:`alert`,children:`The file could not be opened. Try again.`}):null]})}var sn={requested:`Approval requested.`,pending:`Pending approval.`,approved:`Approved. Waiting to run.`,applied:`Done.`,denied:`Denied.`,expired:`Expired. Nothing ran.`,claimed:`Dispatch in progress.`,outcome_unknown:`Outcome unknown. Check before trying again.`};function cn(e){let{view:t,scope:n}=e,r=JSON.stringify([t.record.recordId,t.record.revision,t.canAnswer,t.canSetAutoApprove,n.agentId]);return(0,$.jsx)(ln,{...e},r)}function ln({view:e,scope:t,capabilities:n,onViewChange:r}){let{record:i}=e,a=(0,Q.useRef)(!0);(0,Q.useEffect)(()=>(a.current=!0,()=>{a.current=!1}),[]);let o=(0,Q.useRef)(!1),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(),[d,f]=(0,Q.useState)(),[p,m]=(0,Q.useState)(!1),[h,ee]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(!1),[te,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(``),x=e.canAnswer&&i.state===`pending`&&!p&&!g;async function S(e,t){if(!o.current){o.current=!0,c(!0),u(void 0),f(void 0);try{await e()}catch{u(t)}finally{o.current=!1,c(!1)}}}function C(e,t){if(x)return S(async()=>{let o={recordId:i.recordId,decision:e,expectedRevision:i.revision},s=await n.require(U).answer(t===void 0?o:{...o,denialNote:t});m(!0),s.kind===`answered`&&a.current?r(s.view):s.kind===`refused`&&u(`Decision refused. Refresh this approval before answering again.`)},`Couldn't submit the decision. Try again.`)}function w(){if(!(!e.canSetAutoApprove||h||g))return S(async()=>{let e=await n.require(U).setAutoApprove({scope:t,family:{module:i.module,access:i.access},enabled:!0});ee(!0),e.kind===`updated`?f(`Automatic approval enabled for this family.`):u(`Policy change refused. Refresh this approval before trying again.`)},`Couldn't change approval policy. Try again.`)}function ne(){return S(async()=>{let e=n.require(U),t=(await e.list({state:`pending`,limit:100})).items.find(e=>e.record.recordId===i.recordId)??await e.get({recordId:i.recordId});a.current&&(_(t===null),t!==null&&(m(!1),ee(!1),r(t)))},`Couldn't refresh this approval. Try again.`)}let T=(0,$.jsx)(B,{variant:`ghost`,disabled:s,onClick:()=>void ne(),children:`Refresh approval`});return g?(0,$.jsxs)(Oe,{role:`group`,"aria-label":`Approval request`,"aria-busy":s,density:`compact`,children:[(0,$.jsxs)(ue,{children:[(0,$.jsx)(`p`,{role:`status`,children:`Approval unavailable.`}),l===void 0?null:(0,$.jsx)(`p`,{role:`alert`,children:l})]}),(0,$.jsx)(pe,{children:T})]}):(0,$.jsxs)(Oe,{role:`group`,"aria-label":`Approval request`,"aria-busy":s,density:`compact`,children:[(0,$.jsxs)(fe,{children:[(0,$.jsxs)(me,{children:[x?`Allow `:``,i.module,` · `,i.operation,x?`?`:``]}),(0,$.jsxs)(`p`,{children:[i.requester.displayName,` wants to use a connected tool.`]})]}),(0,$.jsxs)(ue,{className:`min-w-0 space-y-2`,children:[(0,$.jsxs)(`p`,{children:[`Effect`,` `,i.access===`write`?`Changes data in Fungi`:`Changes things outside Fungi`,i.reversibility===`irreversible-external`?` · can't be undone`:``]}),x?null:(0,$.jsx)(`p`,{role:`status`,children:sn[i.state]}),te&&x?(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`label`,{htmlFor:`denial-note-${i.recordId}`,children:`Why deny?`}),(0,$.jsx)(`input`,{id:`denial-note-${i.recordId}`,"aria-label":`Why deny?`,type:`text`,maxLength:512,value:y,onChange:e=>{b(e.target.value)},onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),v(!1),b(``)):e.key===`Enter`&&(e.preventDefault(),C(`deny`,y.trim()||void 0))}}),(0,$.jsx)(B,{disabled:s,onClick:()=>void C(`deny`,y.trim()||void 0),children:`Send denial`})]}):null,(0,$.jsxs)(`details`,{children:[(0,$.jsx)(`summary`,{children:`Details`}),(0,$.jsxs)(`p`,{children:[`Requester: `,i.requester.principalId]}),(0,$.jsxs)(`p`,{children:[`Agent: `,i.requester.displayName,` ·`,` `,i.requester.agentId??`none`]}),(0,$.jsxs)(`p`,{children:[`Session: `,i.requester.sessionId??`none`]}),(0,$.jsxs)(`p`,{children:[`Request: `,i.module,`.`,i.operation,` · `,i.access]}),(0,$.jsxs)(`p`,{children:[`Undo:`,` `,i.reversibility===`irreversible-external`?`Can't be undone`:`Can be undone`]}),(0,$.jsxs)(`p`,{children:[`Can answer: `,e.canAnswer?`Yes`:`No`]}),(0,$.jsxs)(`p`,{children:[`Can set auto-approve: `,e.canSetAutoApprove?`Yes`:`No`]}),i.by?.kind===`policy`?(0,$.jsx)(`p`,{children:`Auto-approved by policy`}):null,(0,$.jsx)(`p`,{children:i.description.title}),(0,$.jsxs)(`p`,{className:`break-all`,children:[`Input: `,i.description.inputBytes,` bytes · SHA-256`,` `,i.description.inputSha256]}),(0,$.jsxs)(`p`,{children:[`Record: `,i.recordId,` · revision `,i.revision]}),e.canSetAutoApprove?(0,$.jsxs)(`p`,{children:[`Policy scope:`,` `,t.agentId===null?`whole home`:`agent ${t.agentId}`]}):null]}),d===void 0?null:(0,$.jsx)(`p`,{role:`status`,children:d}),l===void 0?null:(0,$.jsx)(`p`,{role:`alert`,children:l})]}),(0,$.jsxs)(pe,{className:`flex flex-wrap gap-2`,children:[(0,$.jsx)(B,{disabled:s||!x,onClick:()=>void C(`approve`),children:`Approve once`}),(0,$.jsx)(B,{variant:`outline`,disabled:s||!x,onClick:()=>void C(`deny`),children:`Deny`}),(0,$.jsx)(B,{variant:`outline`,disabled:s||!x,onClick:()=>{b(``),v(!0)},children:`Deny and say why…`}),e.canSetAutoApprove?(0,$.jsx)(B,{variant:`ghost`,disabled:s||h,onClick:()=>void w(),children:`Always approve this family`}):null,T]})]})}var un=(0,Q.forwardRef)(function({heading:e,eyebrow:t,cover:n,action:r,children:i,className:a,...o},s){return(0,$.jsxs)(Oe,{...o,className:L(`caps-game-share`,a),ref:s,children:[n?(0,$.jsx)(`div`,{className:`caps-game-share-cover`,children:n}):null,(0,$.jsxs)(fe,{children:[t,(0,$.jsx)(`h3`,{className:`caps-game-share-heading`,children:e})]}),(0,$.jsx)(ue,{className:`gap-sm`,children:i}),(0,$.jsx)(pe,{children:(0,$.jsx)(B,{asChild:!0,variant:`primary`,className:`caps-game-share-action`,children:r})})]})});function dn(e){let t=0;return e.map(e=>{let n={...e,offset:t};return t+=e.text.length,n})}function fn({value:e,label:t,fieldLabel:n,displayValue:r,layout:i,title:a,tokens:o,className:s,...c}){let l=(0,Q.useId)(),[u,d]=(0,Q.useState)({kind:`ready`}),f=o?o.map(e=>e.text).join(``):e,p=async()=>{d(await navigator.clipboard.writeText(f).then(()=>({kind:`copied`}),e=>({kind:`failed`,cause:e})))};if(n!==void 0)return(0,$.jsxs)(`div`,{...c,className:L(`caps-copy-field-input`,s),children:[(0,$.jsx)(je,{htmlFor:l,children:n}),(0,$.jsxs)(Te,{children:[(0,$.jsx)(he,{className:`caps-copy-field-control`,"aria-label":n,id:l,onFocus:e=>{e.currentTarget.select()},readOnly:!0,value:r??f}),(0,$.jsx)(B,{onClick:()=>void p(),size:`sm`,variant:`outline`,children:u.kind===`copied`?`Copied`:t??`Copy`})]}),u.kind===`failed`?(0,$.jsx)(`span`,{role:`status`,children:`Could not copy. Select the text to copy it.`}):null]});let m=u.kind===`copied`?`Copied`:u.kind===`failed`?`Copy failed`:t??`Copy`;return i===`block`?(0,$.jsxs)(`figure`,{...c,className:L(`caps-copy-field-block`,s),"data-state":u.kind,children:[(0,$.jsxs)(`figcaption`,{className:`caps-copy-field-header`,children:[(0,$.jsx)(`span`,{className:`caps-copy-field-title`,children:a}),(0,$.jsxs)(B,{onClick:()=>void p(),size:`sm`,variant:u.kind===`copied`?`ghost`:`outline`,children:[u.kind===`copied`?(0,$.jsx)(Ce,{"aria-hidden":`true`,size:15}):(0,$.jsx)(_e,{"aria-hidden":`true`,size:15}),m]}),(0,$.jsx)(de,{role:`status`,children:u.kind===`copied`?`Copied to the clipboard`:u.kind===`failed`?`Could not copy. Select the code to copy it.`:``})]}),(0,$.jsx)(`pre`,{className:`caps-copy-field-code`,tabIndex:0,children:(0,$.jsx)(`code`,{children:o?dn(o).map(e=>(0,$.jsx)(`span`,{className:`caps-copy-field-token`,"data-kind":e.kind,children:e.text},e.offset)):f})})]}):(0,$.jsxs)(`div`,{...c,className:L(`caps-copy-field`,s),children:[(0,$.jsx)(`code`,{className:`caps-copy-field-value`,children:f}),(0,$.jsxs)(B,{"aria-label":`${m}: ${f}`,onClick:()=>void p(),size:`sm`,variant:`outline`,children:[u.kind===`copied`?(0,$.jsx)(Ce,{size:15}):(0,$.jsx)(_e,{size:15}),m]})]})}var pn=s({game:s({title:c().min(1),summary:c(),coverUrl:f().nullable(),shareUrl:f()})});function mn(e){let t=/(?:^|\n)\s*Share:\s*(https?:\/\/[^\s<>]+)/iu.exec(e);if(!t?.[1])return null;let n=t[1].replace(/[.,;!?]+$/u,``);if(!URL.canParse(n))return null;let r=new URL(n);return r.username||r.password||r.hash||r.protocol===`http:`&&![`localhost`,`127.0.0.1`].includes(r.hostname)?null:r.href}function hn(e){return mn(e)?e.split(`
|
|
3
|
+
`).filter(e=>!/^\s*Share:\s*/iu.test(e)).join(`
|
|
4
|
+
`).trim():e}function gn(e){let t=new URL(e),n=/^\/([a-z0-9]+(?:-[a-z0-9]+)*)\/?$/u.exec(t.pathname)?.[1];return!n||t.search?null:new URL(`/api/games/${n}`,t.origin)}function _n({reply:e,previewGame:t}){let n=mn(e),r=n?gn(n):null,{data:i}=Se({queryKey:le.of(null,`game-share`,n),enabled:r!==null&&t===void 0,queryFn:async({signal:e})=>{if(!r)return null;let t=await fetch(r,{signal:e});if(!t.ok)return null;let i=pn.safeParse(await t.json());return i.success&&i.data.game.shareUrl===n?i.data.game:null}}),a=t??i;if(!n)return null;let o=new URL(n),s=`${o.host}${o.pathname.replace(/\/$/u,``)}`,c=a?.coverUrl&&r?t?a.coverUrl:new URL(`${r.pathname}/cover`,r.origin).href:null;return(0,$.jsxs)(un,{"data-game-share-card":`true`,"data-theme":`vishnu`,heading:a?.title??`Your game is ready`,eyebrow:(0,$.jsx)(xe,{tone:`secondary`,variant:`quiet`,children:`Made with your Agent`}),cover:c?(0,$.jsx)(`img`,{alt:`A scene from ${a?.title??`your game`}`,src:c}):null,action:(0,$.jsx)(`a`,{href:n,rel:`noopener noreferrer`,target:`_blank`,children:`Play ↗`}),children:[a?.summary?(0,$.jsx)(`p`,{className:`text-sm`,children:a.summary}):null,(0,$.jsx)(fn,{displayValue:s,fieldLabel:`Share link`,label:`Copy link`,value:n})]})}var vn=se(I(Be),{onExcessProperty:`error`});function yn(e){if(!(e.status!==`completed`||e.result?.isError))for(let t of e.result?.content??[]){if(t.type!==`text`)continue;let e=vn(t.text);if(a(e))return e.value.recordId}}function bn({recordId:e,agentId:t,capabilities:n}){let[r,i]=(0,Q.useState)(),[a,o]=(0,Q.useState)(0);return(0,Q.useEffect)(()=>{let t=!0;async function r(){try{let r=await n.require(U).get({recordId:e});t&&i({capabilities:n,recordId:e,view:r,failed:!1})}catch(r){console.warn(`Grove could not read the approval`,r),t&&i({capabilities:n,recordId:e,view:null,failed:!0})}}return r(),()=>{t=!1}},[n,e,a]),r?.capabilities!==n||r.recordId!==e?null:r.failed?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{role:`alert`,children:`Couldn't load this approval. Try again.`}),(0,$.jsx)(B,{variant:`ghost`,onClick:()=>{o(e=>e+1)},children:`Refresh approval`})]}):r.view===null||r.view.record.state===`expired`?null:(0,$.jsx)(cn,{view:r.view,scope:{agentId:t},capabilities:n,onViewChange:t=>{i({capabilities:n,recordId:e,view:t,failed:!1})}})}var xn=[ut,bt,kt,Ht,Qt],Sn=e=>(0,$.jsx)(_n,{reply:e});function Cn({prefill:e,onPrefilled:t}){let n=we(),r=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{!e||r.current===e.requestId||(r.current=e.requestId,n.setDraft(e.text),t())},[n.setDraft,t,e]),null}function wn({session:e,draftIdentity:t,connection:n,commands:r,prefill:i=null,onPrefilled:a=()=>void 0,onOpen:o}){let s=n?.ui??null,c=n?.capabilities,l=(0,Q.useCallback)(e=>$t(s,e),[s]),u=(0,Q.useCallback)(e=>{let n=yn(e);return n!==void 0&&c!==void 0?(0,$.jsx)(bn,{recordId:n,agentId:t.agentId,capabilities:c},n):s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(nn,{item:e,ui:s}),(0,$.jsx)(on,{item:e,ui:s})]}):null},[s,c,t.agentId]),d=(0,Q.useCallback)(e=>{en(s,e)},[s]);return(0,$.jsxs)(De,{session:e,draftIdentity:t,clients:xn,authorOf:ee,onToast:d,children:[(0,$.jsx)(Cn,{prefill:i,onPrefilled:a}),(0,$.jsx)(ke,{onLink:l,onOpen:o,composerActionVariant:`outline`,commands:r,renderAssistantAttachment:Sn,formatAssistantText:hn,renderToolActions:u})]})}export{wn as ParakeetConversation};
|