@agentica/chat 0.15.6 → 0.15.7
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/{_isFormatUri-Czmim0us.js → _isFormatUri-D80pJ-Bz.js} +1 -1
- package/dist/assets/bbs/{index-CdF6qCrg.js → index-rMAE1wxP.js} +1 -1
- package/dist/assets/shopping/{index.html-C5MFMT7t.js → index.html-DtefUuIq.js} +1 -1
- package/dist/bbs/index.html +2 -2
- package/dist/shopping/index.html +2 -2
- package/package.json +2 -2
|
@@ -25,7 +25,7 @@ Use the supplied tools to select some functions of \`getApiFunctions()\` returne
|
|
|
25
25
|
|
|
26
26
|
When selecting functions to call, pay attention to the relationship between functions. In particular, check the prerequisites between each function.
|
|
27
27
|
|
|
28
|
-
If you can't find any proper function to select, just type your own message. By the way, when typing your own message, please consider the user's language locale code. If your message is different with the user's language, please translate it to the user's.`};var jc={};const $c=new rr(()=>{const e=t=>typeof t=="object"&&t!==null;return typeof global=="object"&&e(global)&&e(global.process)&&e(global.process.versions)&&typeof global.process.versions.node<"u"}),qc=new rr(()=>{var e;return $c.get()?((e=jc.LANG)==null?void 0:e.split(".")[0])??"en-US":navigator.language}),Vc=new rr(()=>Intl.DateTimeFormat().resolvedOptions().timeZone);function zc(e){var i,r;if(((i=e==null?void 0:e.systemPrompt)==null?void 0:i.common)!==void 0)return(r=e==null?void 0:e.systemPrompt)==null?void 0:r.common(e);const t=(e==null?void 0:e.locale)??qc.get(),n=(e==null?void 0:e.timezone)??Vc.get();return _t.COMMON.replace("${locale}",t).replace("${timezone}",n)}const jt={write:zc};function Ot(e){return{operation:e.operation,reason:e.reason,toJSON:()=>({operation:e.operation.toJSON(),reason:e.reason})}}var ar={};class Wc extends Error{constructor(n){super(n.message||`Error on ${n.method}(): invalid type${n.path?` on ${n.path}`:""}, expect to be ${n.expected}`);Rt(this,"method");Rt(this,"path");Rt(this,"expected");Rt(this,"value");Rt(this,"fake_expected_typed_value_");const i=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,i):this.__proto__=i,this.method=n.method,this.path=n.path,this.expected=n.expected,this.value=n.value}}const Yc=Object.freeze(Object.defineProperty({__proto__:null,TypeGuardError:Wc},Symbol.toStringTag,{value:"Module"})),Kc=il(Yc);Object.defineProperty(ar,"__esModule",{value:!0});var q=ar._assertGuard=void 0;const Qc=Kc,Xc=(e,t,n)=>{if(e===!0)throw n?n(t):new Qc.TypeGuardError(t);return!1};q=ar._assertGuard=Xc;function Po(e,t){return{accepted_prediction_tokens:(e.accepted_prediction_tokens??0)+(t.accepted_prediction_tokens??0),reasoning_tokens:(e.reasoning_tokens??0)+(t.reasoning_tokens??0),rejected_prediction_tokens:(e.rejected_prediction_tokens??0)+(t.rejected_prediction_tokens??0)}}function Ro(e,t){return{audio_tokens:(e.audio_tokens??0)+(t.audio_tokens??0),cached_tokens:(e.cached_tokens??0)+(t.cached_tokens??0)}}function Zc(e,t){return{prompt_tokens:(e.prompt_tokens??0)+(t.prompt_tokens??0),completion_tokens:(e.completion_tokens??0)+(t.completion_tokens??0),total_tokens:(e.total_tokens??0)+(t.total_tokens??0),completion_tokens_details:Po(e.completion_tokens_details??{accepted_prediction_tokens:0,reasoning_tokens:0,rejected_prediction_tokens:0},t.completion_tokens_details??{accepted_prediction_tokens:0,reasoning_tokens:0,rejected_prediction_tokens:0}),prompt_tokens_details:Ro(e.prompt_tokens_details??{audio_tokens:0,cached_tokens:0},t.prompt_tokens_details??{audio_tokens:0,cached_tokens:0})}}const ep={sum:Zc,sumCompletionTokenDetail:Po,sumPromptTokenDetail:Ro};function tp(e){const t=e instanceof Uint8Array?$u.toUtf8(e):e;return(()=>{const n=h=>typeof h.id=="string"&&Array.isArray(h.choices)&&h.choices.every(C=>typeof C=="object"&&C!==null&&i(C))&&typeof h.created=="number"&&typeof h.model=="string"&&h.object==="chat.completion.chunk"&&(h.service_tier===null||h.service_tier===void 0||h.service_tier==="scale"||h.service_tier==="default")&&(h.system_fingerprint===void 0||typeof h.system_fingerprint=="string")&&(h.usage===null||h.usage===void 0||typeof h.usage=="object"&&h.usage!==null&&d(h.usage)),i=h=>typeof h.delta=="object"&&h.delta!==null&&Array.isArray(h.delta)===!1&&r(h.delta)&&(h.finish_reason===null||h.finish_reason==="stop"||h.finish_reason==="length"||h.finish_reason==="tool_calls"||h.finish_reason==="content_filter"||h.finish_reason==="function_call")&&typeof h.index=="number"&&(h.logprobs===null||h.logprobs===void 0||typeof h.logprobs=="object"&&h.logprobs!==null&&l(h.logprobs)),r=h=>(h.content===null||h.content===void 0||typeof h.content=="string")&&(h.function_call===void 0||typeof h.function_call=="object"&&h.function_call!==null&&Array.isArray(h.function_call)===!1&&a(h.function_call))&&(h.refusal===null||h.refusal===void 0||typeof h.refusal=="string")&&(h.role===void 0||h.role==="developer"||h.role==="system"||h.role==="user"||h.role==="assistant"||h.role==="tool")&&(h.tool_calls===void 0||Array.isArray(h.tool_calls)&&h.tool_calls.every(C=>typeof C=="object"&&C!==null&&o(C))),a=h=>(h.arguments===void 0||typeof h.arguments=="string")&&(h.name===void 0||typeof h.name=="string"),o=h=>typeof h.index=="number"&&(h.id===void 0||typeof h.id=="string")&&(h.function===void 0||typeof h.function=="object"&&h.function!==null&&Array.isArray(h.function)===!1&&u(h.function))&&(h.type===void 0||h.type==="function"),u=h=>(h.arguments===void 0||typeof h.arguments=="string")&&(h.name===void 0||typeof h.name=="string"),l=h=>(h.content===null||Array.isArray(h.content)&&h.content.every(C=>typeof C=="object"&&C!==null&&c(C)))&&(h.refusal===null||Array.isArray(h.refusal)&&h.refusal.every(C=>typeof C=="object"&&C!==null&&c(C))),c=h=>typeof h.token=="string"&&(h.bytes===null||Array.isArray(h.bytes)&&h.bytes.every(C=>typeof C=="number"))&&typeof h.logprob=="number"&&Array.isArray(h.top_logprobs)&&h.top_logprobs.every(C=>typeof C=="object"&&C!==null&&p(C)),p=h=>typeof h.token=="string"&&(h.bytes===null||Array.isArray(h.bytes)&&h.bytes.every(C=>typeof C=="number"))&&typeof h.logprob=="number",d=h=>typeof h.completion_tokens=="number"&&typeof h.prompt_tokens=="number"&&typeof h.total_tokens=="number"&&(h.completion_tokens_details===void 0||typeof h.completion_tokens_details=="object"&&h.completion_tokens_details!==null&&Array.isArray(h.completion_tokens_details)===!1&&g(h.completion_tokens_details))&&(h.prompt_tokens_details===void 0||typeof h.prompt_tokens_details=="object"&&h.prompt_tokens_details!==null&&Array.isArray(h.prompt_tokens_details)===!1&&m(h.prompt_tokens_details)),g=h=>(h.accepted_prediction_tokens===void 0||typeof h.accepted_prediction_tokens=="number")&&(h.audio_tokens===void 0||typeof h.audio_tokens=="number")&&(h.reasoning_tokens===void 0||typeof h.reasoning_tokens=="number")&&(h.rejected_prediction_tokens===void 0||typeof h.rejected_prediction_tokens=="number"),m=h=>(h.audio_tokens===void 0||typeof h.audio_tokens=="number")&&(h.cached_tokens===void 0||typeof h.cached_tokens=="number"),E=(h,C,O=!0)=>(typeof h.id=="string"||q(O,{method:"json.assertParse",path:C+".id",expected:"string",value:h.id},T))&&((Array.isArray(h.choices)||q(O,{method:"json.assertParse",path:C+".choices",expected:"Array<ChatCompletionChunk.Choice>",value:h.choices},T))&&h.choices.every((z,Y)=>(typeof z=="object"&&z!==null||q(O,{method:"json.assertParse",path:C+".choices["+Y+"]",expected:"ChatCompletionChunk.Choice",value:z},T))&&_(z,C+".choices["+Y+"]",O)||q(O,{method:"json.assertParse",path:C+".choices["+Y+"]",expected:"ChatCompletionChunk.Choice",value:z},T))||q(O,{method:"json.assertParse",path:C+".choices",expected:"Array<ChatCompletionChunk.Choice>",value:h.choices},T))&&(typeof h.created=="number"||q(O,{method:"json.assertParse",path:C+".created",expected:"number",value:h.created},T))&&(typeof h.model=="string"||q(O,{method:"json.assertParse",path:C+".model",expected:"string",value:h.model},T))&&(h.object==="chat.completion.chunk"||q(O,{method:"json.assertParse",path:C+".object",expected:'"chat.completion.chunk"',value:h.object},T))&&(h.service_tier===null||h.service_tier===void 0||h.service_tier==="scale"||h.service_tier==="default"||q(O,{method:"json.assertParse",path:C+".service_tier",expected:'("default" | "scale" | null | undefined)',value:h.service_tier},T))&&(h.system_fingerprint===void 0||typeof h.system_fingerprint=="string"||q(O,{method:"json.assertParse",path:C+".system_fingerprint",expected:"(string | undefined)",value:h.system_fingerprint},T))&&(h.usage===null||h.usage===void 0||(typeof h.usage=="object"&&h.usage!==null||q(O,{method:"json.assertParse",path:C+".usage",expected:"(CompletionUsage | null | undefined)",value:h.usage},T))&&j(h.usage,C+".usage",O)||q(O,{method:"json.assertParse",path:C+".usage",expected:"(CompletionUsage | null | undefined)",value:h.usage},T)),_=(h,C,O=!0)=>((typeof h.delta=="object"&&h.delta!==null&&Array.isArray(h.delta)===!1||q(O,{method:"json.assertParse",path:C+".delta",expected:"ChatCompletionChunk.Choice.Delta",value:h.delta},T))&&M(h.delta,C+".delta",O)||q(O,{method:"json.assertParse",path:C+".delta",expected:"ChatCompletionChunk.Choice.Delta",value:h.delta},T))&&(h.finish_reason===null||h.finish_reason==="stop"||h.finish_reason==="length"||h.finish_reason==="tool_calls"||h.finish_reason==="content_filter"||h.finish_reason==="function_call"||q(O,{method:"json.assertParse",path:C+".finish_reason",expected:'("content_filter" | "function_call" | "length" | "stop" | "tool_calls" | null)',value:h.finish_reason},T))&&(typeof h.index=="number"||q(O,{method:"json.assertParse",path:C+".index",expected:"number",value:h.index},T))&&(h.logprobs===null||h.logprobs===void 0||(typeof h.logprobs=="object"&&h.logprobs!==null||q(O,{method:"json.assertParse",path:C+".logprobs",expected:"(ChatCompletionChunk.Choice.Logprobs | null | undefined)",value:h.logprobs},T))&&K(h.logprobs,C+".logprobs",O)||q(O,{method:"json.assertParse",path:C+".logprobs",expected:"(ChatCompletionChunk.Choice.Logprobs | null | undefined)",value:h.logprobs},T)),M=(h,C,O=!0)=>(h.content===null||h.content===void 0||typeof h.content=="string"||q(O,{method:"json.assertParse",path:C+".content",expected:"(null | string | undefined)",value:h.content},T))&&(h.function_call===void 0||(typeof h.function_call=="object"&&h.function_call!==null&&Array.isArray(h.function_call)===!1||q(O,{method:"json.assertParse",path:C+".function_call",expected:"(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",value:h.function_call},T))&&x(h.function_call,C+".function_call",O)||q(O,{method:"json.assertParse",path:C+".function_call",expected:"(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",value:h.function_call},T))&&(h.refusal===null||h.refusal===void 0||typeof h.refusal=="string"||q(O,{method:"json.assertParse",path:C+".refusal",expected:"(null | string | undefined)",value:h.refusal},T))&&(h.role===void 0||h.role==="developer"||h.role==="system"||h.role==="user"||h.role==="assistant"||h.role==="tool"||q(O,{method:"json.assertParse",path:C+".role",expected:'("assistant" | "developer" | "system" | "tool" | "user" | undefined)',value:h.role},T))&&(h.tool_calls===void 0||(Array.isArray(h.tool_calls)||q(O,{method:"json.assertParse",path:C+".tool_calls",expected:"(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",value:h.tool_calls},T))&&h.tool_calls.every((z,Y)=>(typeof z=="object"&&z!==null||q(O,{method:"json.assertParse",path:C+".tool_calls["+Y+"]",expected:"ChatCompletionChunk.Choice.Delta.ToolCall",value:z},T))&&V(z,C+".tool_calls["+Y+"]",O)||q(O,{method:"json.assertParse",path:C+".tool_calls["+Y+"]",expected:"ChatCompletionChunk.Choice.Delta.ToolCall",value:z},T))||q(O,{method:"json.assertParse",path:C+".tool_calls",expected:"(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",value:h.tool_calls},T)),x=(h,C,O=!0)=>(h.arguments===void 0||typeof h.arguments=="string"||q(O,{method:"json.assertParse",path:C+".arguments",expected:"(string | undefined)",value:h.arguments},T))&&(h.name===void 0||typeof h.name=="string"||q(O,{method:"json.assertParse",path:C+".name",expected:"(string | undefined)",value:h.name},T)),V=(h,C,O=!0)=>(typeof h.index=="number"||q(O,{method:"json.assertParse",path:C+".index",expected:"number",value:h.index},T))&&(h.id===void 0||typeof h.id=="string"||q(O,{method:"json.assertParse",path:C+".id",expected:"(string | undefined)",value:h.id},T))&&(h.function===void 0||(typeof h.function=="object"&&h.function!==null&&Array.isArray(h.function)===!1||q(O,{method:"json.assertParse",path:C+'["function"]',expected:"(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",value:h.function},T))&&P(h.function,C+'["function"]',O)||q(O,{method:"json.assertParse",path:C+'["function"]',expected:"(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",value:h.function},T))&&(h.type===void 0||h.type==="function"||q(O,{method:"json.assertParse",path:C+".type",expected:'("function" | undefined)',value:h.type},T)),P=(h,C,O=!0)=>(h.arguments===void 0||typeof h.arguments=="string"||q(O,{method:"json.assertParse",path:C+".arguments",expected:"(string | undefined)",value:h.arguments},T))&&(h.name===void 0||typeof h.name=="string"||q(O,{method:"json.assertParse",path:C+".name",expected:"(string | undefined)",value:h.name},T)),K=(h,C,O=!0)=>(h.content===null||(Array.isArray(h.content)||q(O,{method:"json.assertParse",path:C+".content",expected:"(Array<ChatCompletionTokenLogprob> | null)",value:h.content},T))&&h.content.every((z,Y)=>(typeof z=="object"&&z!==null||q(O,{method:"json.assertParse",path:C+".content["+Y+"]",expected:"ChatCompletionTokenLogprob",value:z},T))&&X(z,C+".content["+Y+"]",O)||q(O,{method:"json.assertParse",path:C+".content["+Y+"]",expected:"ChatCompletionTokenLogprob",value:z},T))||q(O,{method:"json.assertParse",path:C+".content",expected:"(Array<ChatCompletionTokenLogprob> | null)",value:h.content},T))&&(h.refusal===null||(Array.isArray(h.refusal)||q(O,{method:"json.assertParse",path:C+".refusal",expected:"(Array<ChatCompletionTokenLogprob> | null)",value:h.refusal},T))&&h.refusal.every((z,Y)=>(typeof z=="object"&&z!==null||q(O,{method:"json.assertParse",path:C+".refusal["+Y+"]",expected:"ChatCompletionTokenLogprob",value:z},T))&&X(z,C+".refusal["+Y+"]",O)||q(O,{method:"json.assertParse",path:C+".refusal["+Y+"]",expected:"ChatCompletionTokenLogprob",value:z},T))||q(O,{method:"json.assertParse",path:C+".refusal",expected:"(Array<ChatCompletionTokenLogprob> | null)",value:h.refusal},T)),X=(h,C,O=!0)=>(typeof h.token=="string"||q(O,{method:"json.assertParse",path:C+".token",expected:"string",value:h.token},T))&&(h.bytes===null||(Array.isArray(h.bytes)||q(O,{method:"json.assertParse",path:C+".bytes",expected:"(Array<number> | null)",value:h.bytes},T))&&h.bytes.every((z,Y)=>typeof z=="number"||q(O,{method:"json.assertParse",path:C+".bytes["+Y+"]",expected:"number",value:z},T))||q(O,{method:"json.assertParse",path:C+".bytes",expected:"(Array<number> | null)",value:h.bytes},T))&&(typeof h.logprob=="number"||q(O,{method:"json.assertParse",path:C+".logprob",expected:"number",value:h.logprob},T))&&((Array.isArray(h.top_logprobs)||q(O,{method:"json.assertParse",path:C+".top_logprobs",expected:"Array<ChatCompletionTokenLogprob.TopLogprob>",value:h.top_logprobs},T))&&h.top_logprobs.every((z,Y)=>(typeof z=="object"&&z!==null||q(O,{method:"json.assertParse",path:C+".top_logprobs["+Y+"]",expected:"ChatCompletionTokenLogprob.TopLogprob",value:z},T))&&v(z,C+".top_logprobs["+Y+"]",O)||q(O,{method:"json.assertParse",path:C+".top_logprobs["+Y+"]",expected:"ChatCompletionTokenLogprob.TopLogprob",value:z},T))||q(O,{method:"json.assertParse",path:C+".top_logprobs",expected:"Array<ChatCompletionTokenLogprob.TopLogprob>",value:h.top_logprobs},T)),v=(h,C,O=!0)=>(typeof h.token=="string"||q(O,{method:"json.assertParse",path:C+".token",expected:"string",value:h.token},T))&&(h.bytes===null||(Array.isArray(h.bytes)||q(O,{method:"json.assertParse",path:C+".bytes",expected:"(Array<number> | null)",value:h.bytes},T))&&h.bytes.every((z,Y)=>typeof z=="number"||q(O,{method:"json.assertParse",path:C+".bytes["+Y+"]",expected:"number",value:z},T))||q(O,{method:"json.assertParse",path:C+".bytes",expected:"(Array<number> | null)",value:h.bytes},T))&&(typeof h.logprob=="number"||q(O,{method:"json.assertParse",path:C+".logprob",expected:"number",value:h.logprob},T)),j=(h,C,O=!0)=>(typeof h.completion_tokens=="number"||q(O,{method:"json.assertParse",path:C+".completion_tokens",expected:"number",value:h.completion_tokens},T))&&(typeof h.prompt_tokens=="number"||q(O,{method:"json.assertParse",path:C+".prompt_tokens",expected:"number",value:h.prompt_tokens},T))&&(typeof h.total_tokens=="number"||q(O,{method:"json.assertParse",path:C+".total_tokens",expected:"number",value:h.total_tokens},T))&&(h.completion_tokens_details===void 0||(typeof h.completion_tokens_details=="object"&&h.completion_tokens_details!==null&&Array.isArray(h.completion_tokens_details)===!1||q(O,{method:"json.assertParse",path:C+".completion_tokens_details",expected:"(CompletionUsage.CompletionTokensDetails | undefined)",value:h.completion_tokens_details},T))&&L(h.completion_tokens_details,C+".completion_tokens_details",O)||q(O,{method:"json.assertParse",path:C+".completion_tokens_details",expected:"(CompletionUsage.CompletionTokensDetails | undefined)",value:h.completion_tokens_details},T))&&(h.prompt_tokens_details===void 0||(typeof h.prompt_tokens_details=="object"&&h.prompt_tokens_details!==null&&Array.isArray(h.prompt_tokens_details)===!1||q(O,{method:"json.assertParse",path:C+".prompt_tokens_details",expected:"(CompletionUsage.PromptTokensDetails | undefined)",value:h.prompt_tokens_details},T))&&H(h.prompt_tokens_details,C+".prompt_tokens_details",O)||q(O,{method:"json.assertParse",path:C+".prompt_tokens_details",expected:"(CompletionUsage.PromptTokensDetails | undefined)",value:h.prompt_tokens_details},T)),L=(h,C,O=!0)=>(h.accepted_prediction_tokens===void 0||typeof h.accepted_prediction_tokens=="number"||q(O,{method:"json.assertParse",path:C+".accepted_prediction_tokens",expected:"(number | undefined)",value:h.accepted_prediction_tokens},T))&&(h.audio_tokens===void 0||typeof h.audio_tokens=="number"||q(O,{method:"json.assertParse",path:C+".audio_tokens",expected:"(number | undefined)",value:h.audio_tokens},T))&&(h.reasoning_tokens===void 0||typeof h.reasoning_tokens=="number"||q(O,{method:"json.assertParse",path:C+".reasoning_tokens",expected:"(number | undefined)",value:h.reasoning_tokens},T))&&(h.rejected_prediction_tokens===void 0||typeof h.rejected_prediction_tokens=="number"||q(O,{method:"json.assertParse",path:C+".rejected_prediction_tokens",expected:"(number | undefined)",value:h.rejected_prediction_tokens},T)),H=(h,C,O=!0)=>(h.audio_tokens===void 0||typeof h.audio_tokens=="number"||q(O,{method:"json.assertParse",path:C+".audio_tokens",expected:"(number | undefined)",value:h.audio_tokens},T))&&(h.cached_tokens===void 0||typeof h.cached_tokens=="number"||q(O,{method:"json.assertParse",path:C+".cached_tokens",expected:"(number | undefined)",value:h.cached_tokens},T)),J=h=>typeof h=="object"&&h!==null&&n(h);let T;const F=(h,C)=>(J(h)===!1&&(T=C,((O,z,Y=!0)=>(typeof O=="object"&&O!==null||q(!0,{method:"json.assertParse",path:z+"",expected:"ChatCompletionChunk & { usage: CompletionUsage | null | undefined; }",value:O},T))&&E(O,z+"",!0)||q(!0,{method:"json.assertParse",path:z+"",expected:"ChatCompletionChunk & { usage: CompletionUsage | null | undefined; }",value:O},T))(h,"$input",!0)),h);return(h,C)=>F(JSON.parse(h),C)})()(t)}function wo(e,t){const n=e.choices;t.choices.forEach(r=>{const a=n[r.index];if(a!=null){n[r.index]=Do(a,r);return}n[r.index]={index:r.index,finish_reason:r.finish_reason??null,logprobs:r.logprobs??null,message:{tool_calls:r.delta.tool_calls!==void 0?r.delta.tool_calls.reduce((o,u)=>{var l,c;return o[u.index]={id:u.id??"",type:"function",function:{name:((l=u.function)==null?void 0:l.name)??"",arguments:((c=u.function)==null?void 0:c.arguments)??""}},o},[]):void 0,content:r.delta.content??null,refusal:r.delta.refusal??null,role:"assistant"}}});const i=t.usage==null?e.usage:e.usage==null?t.usage:ep.sum(e.usage,t.usage);return{...e,choices:n,usage:i}}function np(e){const t=e[0];if(t===void 0)throw new Error("No chunks received");return e.reduce(wo,{id:t.id,choices:[],created:t.created,model:t.model,object:"chat.completion",usage:void 0,service_tier:t.service_tier,system_fingerprint:t.system_fingerprint})}function Do(e,t){var n;if(e.finish_reason==null&&t.finish_reason!=null&&(e.finish_reason=t.finish_reason),e.logprobs==null&&t.logprobs!=null&&(e.logprobs=t.logprobs),t.delta.content!=null&&(e.message.content==null?e.message.content=t.delta.content:e.message.content+=t.delta.content),t.delta.refusal!=null&&(e.message.refusal==null?e.message.refusal=t.delta.refusal:e.message.refusal+=t.delta.refusal),t.delta.tool_calls!=null){(n=e.message).tool_calls??(n.tool_calls=[]);const i=e.message.tool_calls;t.delta.tool_calls.forEach(r=>{var o,u;const a=i[r.index];if(a!=null){i[r.index]=Lo(a,r);return}i[r.index]={id:r.id??"",type:"function",function:{name:((o=r.function)==null?void 0:o.name)??"",arguments:((u=r.function)==null?void 0:u.arguments)??""}}})}return e}function Lo(e,t){return t.function!=null&&(e.function.arguments+=t.function.arguments??"",e.function.name+=t.function.name??""),e.id+=t.id??"",e}const rt={transformCompletionChunk:tp,accumulate:wo,merge:np,mergeChoice:Do,mergeToolCalls:Lo};async function ip(e){const t=e.getReader(),n=[];for(;;){const{done:i,value:r}=await t.read();if(i)break;n.push(r)}return n}async function rp(e,t,n){const i=e.getReader();let r=n??null;for(;;){const{done:a,value:o}=await i.read();if(a)break;if(r===null){r=o;continue}r=t(r,o)}return r}function ap(e){return new ReadableStream({start:n=>{n.enqueue(e),n.close()}})}function op(e,t){const n=e.getReader();return new ReadableStream({pull:async i=>{const{done:r,value:a}=await n.read();r?i.close():i.enqueue(t(a))}})}const Qe={readAll:ip,reduce:rp,to:ap,transform:op};async function ni(e,t){const n=e.stack.findIndex(r=>r.operation.name===t.name);if(n===-1)return null;const i=e.stack[n];return e.stack.splice(n,1),await e.dispatch(No({selection:Ot({operation:i.operation,reason:t.reason})})),i}async function sp(e){var a,o,u;const t=await e.request("call",{messages:[{role:"system",content:jt.write(e.config)},...e.histories.map(Ut).flat(),{role:"user",content:e.prompt.text},{role:"system",content:((u=(o=(a=e.config)==null?void 0:a.systemPrompt)==null?void 0:o.execute)==null?void 0:u.call(o,e.histories))??_t.EXECUTE}],tools:e.stack.map(l=>({type:"function",function:{name:l.operation.name,description:l.operation.function.description,parameters:l.operation.function.separated!==void 0?l.operation.function.separated.llm??{type:"object",properties:{},required:[],additionalProperties:!1,$defs:{}}:l.operation.function.parameters}})),tool_choice:"auto",parallel_tool_calls:!1}),n=[],i=await Qe.readAll(t),r=rt.merge(i);for(const l of r.choices){for(const c of l.message.tool_calls??[])if(c.type==="function"){const p=e.operations.flat.get(c.function.name);if(p===void 0)continue;n.push(async()=>{const d=vo({id:c.id,operation:p,arguments:JSON.parse(c.function.arguments)});d.operation.protocol==="http"&&cp({operation:d.operation,arguments:d.arguments}),await e.dispatch(d);const g=await Mo(e,d,0);return e.dispatch(Hc({id:d.id,operation:d.operation,arguments:g.arguments,value:g.value})),await ni(e,{name:d.operation.name,reason:"completed"}),e.dispatch(No({selection:Ot({operation:d.operation,reason:"complete"})})),[g,ei({id:d.id,selections:[Ot({operation:d.operation,reason:"complete"})]})]})}l.message.role==="assistant"&&l.message.content!==null&&l.message.content.length>0&&n.push(async()=>{const c=Sn({role:"assistant",text:l.message.content});return e.dispatch(ti({role:"assistant",get:()=>c.text,done:()=>!0,stream:Qe.to(c.text),join:async()=>Promise.resolve(c.text)})),[c]})}return(await Promise.all(n.map(async l=>l()))).flat()}async function Mo(e,t,n){var i,r,a;if(t.operation.protocol==="http"){const o=t.operation.function.validate(t.arguments);if(o.success===!1&&(e.dispatch(Xr({id:t.id,operation:t.operation,result:o})),n++<(((i=e.config)==null?void 0:i.retry)??Ct.RETRY))){const u=await Ii(e,t,n,o.errors);if(u!==null)return u}try{const u=await up(t.operation,t.arguments);return(((u.status===400||u.status===404||u.status===422)&&n++<(((r=e.config)==null?void 0:r.retry)??Ct.RETRY)&&typeof u.body)===!1===!1?await Ii(e,t,n,u.body):null)??At({operation:t.operation,id:t.id,arguments:t.arguments,value:u})}catch(u){return At({operation:t.operation,id:t.id,arguments:t.arguments,value:{status:500,headers:{},body:u instanceof Error?{...u,name:u.name,message:u.message}:u}})}}else{const o=t.operation.function.validate(t.arguments);if(o.success===!1)return e.dispatch(Xr({id:t.id,operation:t.operation,result:o})),(n++<(((a=e.config)==null?void 0:a.retry)??Ct.RETRY)?await Ii(e,t,n,o.errors):null)??At({id:t.id,operation:t.operation,arguments:t.arguments,value:{name:"TypeGuardError",message:"Invalid arguments.",errors:o.errors}});try{const u=await lp(t.operation,t.arguments);return At({id:t.id,operation:t.operation,arguments:t.arguments,value:u})}catch(u){return At({id:t.id,operation:t.operation,arguments:t.arguments,value:u instanceof Error?{...u,name:u.name,message:u.message}:u})}}}async function up(e,t){const n={connection:e.controller.connection,application:e.controller.application,function:e.function};return e.controller.execute!==void 0?e.controller.execute({...n,arguments:t}):qu.propagate({...n,input:t})}async function lp(e,t){const n=e.controller.execute;return typeof n=="function"?await n({application:e.controller.application,function:e.function,arguments:t}):n[e.function.name](t)}async function Ii(e,t,n,i){var l,c,p,d,g;const r=await e.request("call",{messages:[{role:"system",content:jt.write(e.config)},...e.histories.map(Ut).flat(),{role:"user",content:e.prompt.text},{role:"system",content:((p=(c=(l=e.config)==null?void 0:l.systemPrompt)==null?void 0:c.execute)==null?void 0:p.call(c,e.histories))??_t.EXECUTE},{role:"assistant",tool_calls:[{type:"function",id:t.id,function:{name:t.operation.name,arguments:JSON.stringify(t.arguments)}}]},{role:"tool",content:typeof i=="string"?i:JSON.stringify(i),tool_call_id:t.id},{role:"system",content:["You A.I. assistant has composed wrong arguments.","","Correct it at the next function calling."].join(`
|
|
28
|
+
If you can't find any proper function to select, just type your own message. By the way, when typing your own message, please consider the user's language locale code. If your message is different with the user's language, please translate it to the user's.`};var jc={};const $c=new rr(()=>{const e=t=>typeof t=="object"&&t!==null;return typeof global=="object"&&e(global)&&e(global.process)&&e(global.process.versions)&&typeof global.process.versions.node<"u"}),qc=new rr(()=>{var e;return $c.get()?((e=jc.LANG)==null?void 0:e.split(".")[0])??"en-US":navigator.language}),Vc=new rr(()=>Intl.DateTimeFormat().resolvedOptions().timeZone);function zc(e){var i,r;if(((i=e==null?void 0:e.systemPrompt)==null?void 0:i.common)!==void 0)return(r=e==null?void 0:e.systemPrompt)==null?void 0:r.common(e);const t=(e==null?void 0:e.locale)??qc.get(),n=(e==null?void 0:e.timezone)??Vc.get();return _t.COMMON.replace("${locale}",t).replace("${timezone}",n).replace("${datetime}",new Date().toISOString())}const jt={write:zc};function Ot(e){return{operation:e.operation,reason:e.reason,toJSON:()=>({operation:e.operation.toJSON(),reason:e.reason})}}var ar={};class Wc extends Error{constructor(n){super(n.message||`Error on ${n.method}(): invalid type${n.path?` on ${n.path}`:""}, expect to be ${n.expected}`);Rt(this,"method");Rt(this,"path");Rt(this,"expected");Rt(this,"value");Rt(this,"fake_expected_typed_value_");const i=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,i):this.__proto__=i,this.method=n.method,this.path=n.path,this.expected=n.expected,this.value=n.value}}const Yc=Object.freeze(Object.defineProperty({__proto__:null,TypeGuardError:Wc},Symbol.toStringTag,{value:"Module"})),Kc=il(Yc);Object.defineProperty(ar,"__esModule",{value:!0});var q=ar._assertGuard=void 0;const Qc=Kc,Xc=(e,t,n)=>{if(e===!0)throw n?n(t):new Qc.TypeGuardError(t);return!1};q=ar._assertGuard=Xc;function Po(e,t){return{accepted_prediction_tokens:(e.accepted_prediction_tokens??0)+(t.accepted_prediction_tokens??0),reasoning_tokens:(e.reasoning_tokens??0)+(t.reasoning_tokens??0),rejected_prediction_tokens:(e.rejected_prediction_tokens??0)+(t.rejected_prediction_tokens??0)}}function Ro(e,t){return{audio_tokens:(e.audio_tokens??0)+(t.audio_tokens??0),cached_tokens:(e.cached_tokens??0)+(t.cached_tokens??0)}}function Zc(e,t){return{prompt_tokens:(e.prompt_tokens??0)+(t.prompt_tokens??0),completion_tokens:(e.completion_tokens??0)+(t.completion_tokens??0),total_tokens:(e.total_tokens??0)+(t.total_tokens??0),completion_tokens_details:Po(e.completion_tokens_details??{accepted_prediction_tokens:0,reasoning_tokens:0,rejected_prediction_tokens:0},t.completion_tokens_details??{accepted_prediction_tokens:0,reasoning_tokens:0,rejected_prediction_tokens:0}),prompt_tokens_details:Ro(e.prompt_tokens_details??{audio_tokens:0,cached_tokens:0},t.prompt_tokens_details??{audio_tokens:0,cached_tokens:0})}}const ep={sum:Zc,sumCompletionTokenDetail:Po,sumPromptTokenDetail:Ro};function tp(e){const t=e instanceof Uint8Array?$u.toUtf8(e):e;return(()=>{const n=h=>typeof h.id=="string"&&Array.isArray(h.choices)&&h.choices.every(C=>typeof C=="object"&&C!==null&&i(C))&&typeof h.created=="number"&&typeof h.model=="string"&&h.object==="chat.completion.chunk"&&(h.service_tier===null||h.service_tier===void 0||h.service_tier==="scale"||h.service_tier==="default")&&(h.system_fingerprint===void 0||typeof h.system_fingerprint=="string")&&(h.usage===null||h.usage===void 0||typeof h.usage=="object"&&h.usage!==null&&d(h.usage)),i=h=>typeof h.delta=="object"&&h.delta!==null&&Array.isArray(h.delta)===!1&&r(h.delta)&&(h.finish_reason===null||h.finish_reason==="stop"||h.finish_reason==="length"||h.finish_reason==="tool_calls"||h.finish_reason==="content_filter"||h.finish_reason==="function_call")&&typeof h.index=="number"&&(h.logprobs===null||h.logprobs===void 0||typeof h.logprobs=="object"&&h.logprobs!==null&&l(h.logprobs)),r=h=>(h.content===null||h.content===void 0||typeof h.content=="string")&&(h.function_call===void 0||typeof h.function_call=="object"&&h.function_call!==null&&Array.isArray(h.function_call)===!1&&a(h.function_call))&&(h.refusal===null||h.refusal===void 0||typeof h.refusal=="string")&&(h.role===void 0||h.role==="developer"||h.role==="system"||h.role==="user"||h.role==="assistant"||h.role==="tool")&&(h.tool_calls===void 0||Array.isArray(h.tool_calls)&&h.tool_calls.every(C=>typeof C=="object"&&C!==null&&o(C))),a=h=>(h.arguments===void 0||typeof h.arguments=="string")&&(h.name===void 0||typeof h.name=="string"),o=h=>typeof h.index=="number"&&(h.id===void 0||typeof h.id=="string")&&(h.function===void 0||typeof h.function=="object"&&h.function!==null&&Array.isArray(h.function)===!1&&u(h.function))&&(h.type===void 0||h.type==="function"),u=h=>(h.arguments===void 0||typeof h.arguments=="string")&&(h.name===void 0||typeof h.name=="string"),l=h=>(h.content===null||Array.isArray(h.content)&&h.content.every(C=>typeof C=="object"&&C!==null&&c(C)))&&(h.refusal===null||Array.isArray(h.refusal)&&h.refusal.every(C=>typeof C=="object"&&C!==null&&c(C))),c=h=>typeof h.token=="string"&&(h.bytes===null||Array.isArray(h.bytes)&&h.bytes.every(C=>typeof C=="number"))&&typeof h.logprob=="number"&&Array.isArray(h.top_logprobs)&&h.top_logprobs.every(C=>typeof C=="object"&&C!==null&&p(C)),p=h=>typeof h.token=="string"&&(h.bytes===null||Array.isArray(h.bytes)&&h.bytes.every(C=>typeof C=="number"))&&typeof h.logprob=="number",d=h=>typeof h.completion_tokens=="number"&&typeof h.prompt_tokens=="number"&&typeof h.total_tokens=="number"&&(h.completion_tokens_details===void 0||typeof h.completion_tokens_details=="object"&&h.completion_tokens_details!==null&&Array.isArray(h.completion_tokens_details)===!1&&g(h.completion_tokens_details))&&(h.prompt_tokens_details===void 0||typeof h.prompt_tokens_details=="object"&&h.prompt_tokens_details!==null&&Array.isArray(h.prompt_tokens_details)===!1&&m(h.prompt_tokens_details)),g=h=>(h.accepted_prediction_tokens===void 0||typeof h.accepted_prediction_tokens=="number")&&(h.audio_tokens===void 0||typeof h.audio_tokens=="number")&&(h.reasoning_tokens===void 0||typeof h.reasoning_tokens=="number")&&(h.rejected_prediction_tokens===void 0||typeof h.rejected_prediction_tokens=="number"),m=h=>(h.audio_tokens===void 0||typeof h.audio_tokens=="number")&&(h.cached_tokens===void 0||typeof h.cached_tokens=="number"),E=(h,C,O=!0)=>(typeof h.id=="string"||q(O,{method:"json.assertParse",path:C+".id",expected:"string",value:h.id},T))&&((Array.isArray(h.choices)||q(O,{method:"json.assertParse",path:C+".choices",expected:"Array<ChatCompletionChunk.Choice>",value:h.choices},T))&&h.choices.every((z,Y)=>(typeof z=="object"&&z!==null||q(O,{method:"json.assertParse",path:C+".choices["+Y+"]",expected:"ChatCompletionChunk.Choice",value:z},T))&&_(z,C+".choices["+Y+"]",O)||q(O,{method:"json.assertParse",path:C+".choices["+Y+"]",expected:"ChatCompletionChunk.Choice",value:z},T))||q(O,{method:"json.assertParse",path:C+".choices",expected:"Array<ChatCompletionChunk.Choice>",value:h.choices},T))&&(typeof h.created=="number"||q(O,{method:"json.assertParse",path:C+".created",expected:"number",value:h.created},T))&&(typeof h.model=="string"||q(O,{method:"json.assertParse",path:C+".model",expected:"string",value:h.model},T))&&(h.object==="chat.completion.chunk"||q(O,{method:"json.assertParse",path:C+".object",expected:'"chat.completion.chunk"',value:h.object},T))&&(h.service_tier===null||h.service_tier===void 0||h.service_tier==="scale"||h.service_tier==="default"||q(O,{method:"json.assertParse",path:C+".service_tier",expected:'("default" | "scale" | null | undefined)',value:h.service_tier},T))&&(h.system_fingerprint===void 0||typeof h.system_fingerprint=="string"||q(O,{method:"json.assertParse",path:C+".system_fingerprint",expected:"(string | undefined)",value:h.system_fingerprint},T))&&(h.usage===null||h.usage===void 0||(typeof h.usage=="object"&&h.usage!==null||q(O,{method:"json.assertParse",path:C+".usage",expected:"(CompletionUsage | null | undefined)",value:h.usage},T))&&j(h.usage,C+".usage",O)||q(O,{method:"json.assertParse",path:C+".usage",expected:"(CompletionUsage | null | undefined)",value:h.usage},T)),_=(h,C,O=!0)=>((typeof h.delta=="object"&&h.delta!==null&&Array.isArray(h.delta)===!1||q(O,{method:"json.assertParse",path:C+".delta",expected:"ChatCompletionChunk.Choice.Delta",value:h.delta},T))&&M(h.delta,C+".delta",O)||q(O,{method:"json.assertParse",path:C+".delta",expected:"ChatCompletionChunk.Choice.Delta",value:h.delta},T))&&(h.finish_reason===null||h.finish_reason==="stop"||h.finish_reason==="length"||h.finish_reason==="tool_calls"||h.finish_reason==="content_filter"||h.finish_reason==="function_call"||q(O,{method:"json.assertParse",path:C+".finish_reason",expected:'("content_filter" | "function_call" | "length" | "stop" | "tool_calls" | null)',value:h.finish_reason},T))&&(typeof h.index=="number"||q(O,{method:"json.assertParse",path:C+".index",expected:"number",value:h.index},T))&&(h.logprobs===null||h.logprobs===void 0||(typeof h.logprobs=="object"&&h.logprobs!==null||q(O,{method:"json.assertParse",path:C+".logprobs",expected:"(ChatCompletionChunk.Choice.Logprobs | null | undefined)",value:h.logprobs},T))&&K(h.logprobs,C+".logprobs",O)||q(O,{method:"json.assertParse",path:C+".logprobs",expected:"(ChatCompletionChunk.Choice.Logprobs | null | undefined)",value:h.logprobs},T)),M=(h,C,O=!0)=>(h.content===null||h.content===void 0||typeof h.content=="string"||q(O,{method:"json.assertParse",path:C+".content",expected:"(null | string | undefined)",value:h.content},T))&&(h.function_call===void 0||(typeof h.function_call=="object"&&h.function_call!==null&&Array.isArray(h.function_call)===!1||q(O,{method:"json.assertParse",path:C+".function_call",expected:"(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",value:h.function_call},T))&&x(h.function_call,C+".function_call",O)||q(O,{method:"json.assertParse",path:C+".function_call",expected:"(ChatCompletionChunk.Choice.Delta.FunctionCall | undefined)",value:h.function_call},T))&&(h.refusal===null||h.refusal===void 0||typeof h.refusal=="string"||q(O,{method:"json.assertParse",path:C+".refusal",expected:"(null | string | undefined)",value:h.refusal},T))&&(h.role===void 0||h.role==="developer"||h.role==="system"||h.role==="user"||h.role==="assistant"||h.role==="tool"||q(O,{method:"json.assertParse",path:C+".role",expected:'("assistant" | "developer" | "system" | "tool" | "user" | undefined)',value:h.role},T))&&(h.tool_calls===void 0||(Array.isArray(h.tool_calls)||q(O,{method:"json.assertParse",path:C+".tool_calls",expected:"(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",value:h.tool_calls},T))&&h.tool_calls.every((z,Y)=>(typeof z=="object"&&z!==null||q(O,{method:"json.assertParse",path:C+".tool_calls["+Y+"]",expected:"ChatCompletionChunk.Choice.Delta.ToolCall",value:z},T))&&V(z,C+".tool_calls["+Y+"]",O)||q(O,{method:"json.assertParse",path:C+".tool_calls["+Y+"]",expected:"ChatCompletionChunk.Choice.Delta.ToolCall",value:z},T))||q(O,{method:"json.assertParse",path:C+".tool_calls",expected:"(Array<ChatCompletionChunk.Choice.Delta.ToolCall> | undefined)",value:h.tool_calls},T)),x=(h,C,O=!0)=>(h.arguments===void 0||typeof h.arguments=="string"||q(O,{method:"json.assertParse",path:C+".arguments",expected:"(string | undefined)",value:h.arguments},T))&&(h.name===void 0||typeof h.name=="string"||q(O,{method:"json.assertParse",path:C+".name",expected:"(string | undefined)",value:h.name},T)),V=(h,C,O=!0)=>(typeof h.index=="number"||q(O,{method:"json.assertParse",path:C+".index",expected:"number",value:h.index},T))&&(h.id===void 0||typeof h.id=="string"||q(O,{method:"json.assertParse",path:C+".id",expected:"(string | undefined)",value:h.id},T))&&(h.function===void 0||(typeof h.function=="object"&&h.function!==null&&Array.isArray(h.function)===!1||q(O,{method:"json.assertParse",path:C+'["function"]',expected:"(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",value:h.function},T))&&P(h.function,C+'["function"]',O)||q(O,{method:"json.assertParse",path:C+'["function"]',expected:"(ChatCompletionChunk.Choice.Delta.ToolCall.Function | undefined)",value:h.function},T))&&(h.type===void 0||h.type==="function"||q(O,{method:"json.assertParse",path:C+".type",expected:'("function" | undefined)',value:h.type},T)),P=(h,C,O=!0)=>(h.arguments===void 0||typeof h.arguments=="string"||q(O,{method:"json.assertParse",path:C+".arguments",expected:"(string | undefined)",value:h.arguments},T))&&(h.name===void 0||typeof h.name=="string"||q(O,{method:"json.assertParse",path:C+".name",expected:"(string | undefined)",value:h.name},T)),K=(h,C,O=!0)=>(h.content===null||(Array.isArray(h.content)||q(O,{method:"json.assertParse",path:C+".content",expected:"(Array<ChatCompletionTokenLogprob> | null)",value:h.content},T))&&h.content.every((z,Y)=>(typeof z=="object"&&z!==null||q(O,{method:"json.assertParse",path:C+".content["+Y+"]",expected:"ChatCompletionTokenLogprob",value:z},T))&&X(z,C+".content["+Y+"]",O)||q(O,{method:"json.assertParse",path:C+".content["+Y+"]",expected:"ChatCompletionTokenLogprob",value:z},T))||q(O,{method:"json.assertParse",path:C+".content",expected:"(Array<ChatCompletionTokenLogprob> | null)",value:h.content},T))&&(h.refusal===null||(Array.isArray(h.refusal)||q(O,{method:"json.assertParse",path:C+".refusal",expected:"(Array<ChatCompletionTokenLogprob> | null)",value:h.refusal},T))&&h.refusal.every((z,Y)=>(typeof z=="object"&&z!==null||q(O,{method:"json.assertParse",path:C+".refusal["+Y+"]",expected:"ChatCompletionTokenLogprob",value:z},T))&&X(z,C+".refusal["+Y+"]",O)||q(O,{method:"json.assertParse",path:C+".refusal["+Y+"]",expected:"ChatCompletionTokenLogprob",value:z},T))||q(O,{method:"json.assertParse",path:C+".refusal",expected:"(Array<ChatCompletionTokenLogprob> | null)",value:h.refusal},T)),X=(h,C,O=!0)=>(typeof h.token=="string"||q(O,{method:"json.assertParse",path:C+".token",expected:"string",value:h.token},T))&&(h.bytes===null||(Array.isArray(h.bytes)||q(O,{method:"json.assertParse",path:C+".bytes",expected:"(Array<number> | null)",value:h.bytes},T))&&h.bytes.every((z,Y)=>typeof z=="number"||q(O,{method:"json.assertParse",path:C+".bytes["+Y+"]",expected:"number",value:z},T))||q(O,{method:"json.assertParse",path:C+".bytes",expected:"(Array<number> | null)",value:h.bytes},T))&&(typeof h.logprob=="number"||q(O,{method:"json.assertParse",path:C+".logprob",expected:"number",value:h.logprob},T))&&((Array.isArray(h.top_logprobs)||q(O,{method:"json.assertParse",path:C+".top_logprobs",expected:"Array<ChatCompletionTokenLogprob.TopLogprob>",value:h.top_logprobs},T))&&h.top_logprobs.every((z,Y)=>(typeof z=="object"&&z!==null||q(O,{method:"json.assertParse",path:C+".top_logprobs["+Y+"]",expected:"ChatCompletionTokenLogprob.TopLogprob",value:z},T))&&v(z,C+".top_logprobs["+Y+"]",O)||q(O,{method:"json.assertParse",path:C+".top_logprobs["+Y+"]",expected:"ChatCompletionTokenLogprob.TopLogprob",value:z},T))||q(O,{method:"json.assertParse",path:C+".top_logprobs",expected:"Array<ChatCompletionTokenLogprob.TopLogprob>",value:h.top_logprobs},T)),v=(h,C,O=!0)=>(typeof h.token=="string"||q(O,{method:"json.assertParse",path:C+".token",expected:"string",value:h.token},T))&&(h.bytes===null||(Array.isArray(h.bytes)||q(O,{method:"json.assertParse",path:C+".bytes",expected:"(Array<number> | null)",value:h.bytes},T))&&h.bytes.every((z,Y)=>typeof z=="number"||q(O,{method:"json.assertParse",path:C+".bytes["+Y+"]",expected:"number",value:z},T))||q(O,{method:"json.assertParse",path:C+".bytes",expected:"(Array<number> | null)",value:h.bytes},T))&&(typeof h.logprob=="number"||q(O,{method:"json.assertParse",path:C+".logprob",expected:"number",value:h.logprob},T)),j=(h,C,O=!0)=>(typeof h.completion_tokens=="number"||q(O,{method:"json.assertParse",path:C+".completion_tokens",expected:"number",value:h.completion_tokens},T))&&(typeof h.prompt_tokens=="number"||q(O,{method:"json.assertParse",path:C+".prompt_tokens",expected:"number",value:h.prompt_tokens},T))&&(typeof h.total_tokens=="number"||q(O,{method:"json.assertParse",path:C+".total_tokens",expected:"number",value:h.total_tokens},T))&&(h.completion_tokens_details===void 0||(typeof h.completion_tokens_details=="object"&&h.completion_tokens_details!==null&&Array.isArray(h.completion_tokens_details)===!1||q(O,{method:"json.assertParse",path:C+".completion_tokens_details",expected:"(CompletionUsage.CompletionTokensDetails | undefined)",value:h.completion_tokens_details},T))&&L(h.completion_tokens_details,C+".completion_tokens_details",O)||q(O,{method:"json.assertParse",path:C+".completion_tokens_details",expected:"(CompletionUsage.CompletionTokensDetails | undefined)",value:h.completion_tokens_details},T))&&(h.prompt_tokens_details===void 0||(typeof h.prompt_tokens_details=="object"&&h.prompt_tokens_details!==null&&Array.isArray(h.prompt_tokens_details)===!1||q(O,{method:"json.assertParse",path:C+".prompt_tokens_details",expected:"(CompletionUsage.PromptTokensDetails | undefined)",value:h.prompt_tokens_details},T))&&H(h.prompt_tokens_details,C+".prompt_tokens_details",O)||q(O,{method:"json.assertParse",path:C+".prompt_tokens_details",expected:"(CompletionUsage.PromptTokensDetails | undefined)",value:h.prompt_tokens_details},T)),L=(h,C,O=!0)=>(h.accepted_prediction_tokens===void 0||typeof h.accepted_prediction_tokens=="number"||q(O,{method:"json.assertParse",path:C+".accepted_prediction_tokens",expected:"(number | undefined)",value:h.accepted_prediction_tokens},T))&&(h.audio_tokens===void 0||typeof h.audio_tokens=="number"||q(O,{method:"json.assertParse",path:C+".audio_tokens",expected:"(number | undefined)",value:h.audio_tokens},T))&&(h.reasoning_tokens===void 0||typeof h.reasoning_tokens=="number"||q(O,{method:"json.assertParse",path:C+".reasoning_tokens",expected:"(number | undefined)",value:h.reasoning_tokens},T))&&(h.rejected_prediction_tokens===void 0||typeof h.rejected_prediction_tokens=="number"||q(O,{method:"json.assertParse",path:C+".rejected_prediction_tokens",expected:"(number | undefined)",value:h.rejected_prediction_tokens},T)),H=(h,C,O=!0)=>(h.audio_tokens===void 0||typeof h.audio_tokens=="number"||q(O,{method:"json.assertParse",path:C+".audio_tokens",expected:"(number | undefined)",value:h.audio_tokens},T))&&(h.cached_tokens===void 0||typeof h.cached_tokens=="number"||q(O,{method:"json.assertParse",path:C+".cached_tokens",expected:"(number | undefined)",value:h.cached_tokens},T)),J=h=>typeof h=="object"&&h!==null&&n(h);let T;const F=(h,C)=>(J(h)===!1&&(T=C,((O,z,Y=!0)=>(typeof O=="object"&&O!==null||q(!0,{method:"json.assertParse",path:z+"",expected:"ChatCompletionChunk & { usage: CompletionUsage | null | undefined; }",value:O},T))&&E(O,z+"",!0)||q(!0,{method:"json.assertParse",path:z+"",expected:"ChatCompletionChunk & { usage: CompletionUsage | null | undefined; }",value:O},T))(h,"$input",!0)),h);return(h,C)=>F(JSON.parse(h),C)})()(t)}function wo(e,t){const n=e.choices;t.choices.forEach(r=>{const a=n[r.index];if(a!=null){n[r.index]=Do(a,r);return}n[r.index]={index:r.index,finish_reason:r.finish_reason??null,logprobs:r.logprobs??null,message:{tool_calls:r.delta.tool_calls!==void 0?r.delta.tool_calls.reduce((o,u)=>{var l,c;return o[u.index]={id:u.id??"",type:"function",function:{name:((l=u.function)==null?void 0:l.name)??"",arguments:((c=u.function)==null?void 0:c.arguments)??""}},o},[]):void 0,content:r.delta.content??null,refusal:r.delta.refusal??null,role:"assistant"}}});const i=t.usage==null?e.usage:e.usage==null?t.usage:ep.sum(e.usage,t.usage);return{...e,choices:n,usage:i}}function np(e){const t=e[0];if(t===void 0)throw new Error("No chunks received");return e.reduce(wo,{id:t.id,choices:[],created:t.created,model:t.model,object:"chat.completion",usage:void 0,service_tier:t.service_tier,system_fingerprint:t.system_fingerprint})}function Do(e,t){var n;if(e.finish_reason==null&&t.finish_reason!=null&&(e.finish_reason=t.finish_reason),e.logprobs==null&&t.logprobs!=null&&(e.logprobs=t.logprobs),t.delta.content!=null&&(e.message.content==null?e.message.content=t.delta.content:e.message.content+=t.delta.content),t.delta.refusal!=null&&(e.message.refusal==null?e.message.refusal=t.delta.refusal:e.message.refusal+=t.delta.refusal),t.delta.tool_calls!=null){(n=e.message).tool_calls??(n.tool_calls=[]);const i=e.message.tool_calls;t.delta.tool_calls.forEach(r=>{var o,u;const a=i[r.index];if(a!=null){i[r.index]=Lo(a,r);return}i[r.index]={id:r.id??"",type:"function",function:{name:((o=r.function)==null?void 0:o.name)??"",arguments:((u=r.function)==null?void 0:u.arguments)??""}}})}return e}function Lo(e,t){return t.function!=null&&(e.function.arguments+=t.function.arguments??"",e.function.name+=t.function.name??""),e.id+=t.id??"",e}const rt={transformCompletionChunk:tp,accumulate:wo,merge:np,mergeChoice:Do,mergeToolCalls:Lo};async function ip(e){const t=e.getReader(),n=[];for(;;){const{done:i,value:r}=await t.read();if(i)break;n.push(r)}return n}async function rp(e,t,n){const i=e.getReader();let r=n??null;for(;;){const{done:a,value:o}=await i.read();if(a)break;if(r===null){r=o;continue}r=t(r,o)}return r}function ap(e){return new ReadableStream({start:n=>{n.enqueue(e),n.close()}})}function op(e,t){const n=e.getReader();return new ReadableStream({pull:async i=>{const{done:r,value:a}=await n.read();r?i.close():i.enqueue(t(a))}})}const Qe={readAll:ip,reduce:rp,to:ap,transform:op};async function ni(e,t){const n=e.stack.findIndex(r=>r.operation.name===t.name);if(n===-1)return null;const i=e.stack[n];return e.stack.splice(n,1),await e.dispatch(No({selection:Ot({operation:i.operation,reason:t.reason})})),i}async function sp(e){var a,o,u;const t=await e.request("call",{messages:[{role:"system",content:jt.write(e.config)},...e.histories.map(Ut).flat(),{role:"user",content:e.prompt.text},{role:"system",content:((u=(o=(a=e.config)==null?void 0:a.systemPrompt)==null?void 0:o.execute)==null?void 0:u.call(o,e.histories))??_t.EXECUTE}],tools:e.stack.map(l=>({type:"function",function:{name:l.operation.name,description:l.operation.function.description,parameters:l.operation.function.separated!==void 0?l.operation.function.separated.llm??{type:"object",properties:{},required:[],additionalProperties:!1,$defs:{}}:l.operation.function.parameters}})),tool_choice:"auto",parallel_tool_calls:!1}),n=[],i=await Qe.readAll(t),r=rt.merge(i);for(const l of r.choices){for(const c of l.message.tool_calls??[])if(c.type==="function"){const p=e.operations.flat.get(c.function.name);if(p===void 0)continue;n.push(async()=>{const d=vo({id:c.id,operation:p,arguments:JSON.parse(c.function.arguments)});d.operation.protocol==="http"&&cp({operation:d.operation,arguments:d.arguments}),await e.dispatch(d);const g=await Mo(e,d,0);return e.dispatch(Hc({id:d.id,operation:d.operation,arguments:g.arguments,value:g.value})),await ni(e,{name:d.operation.name,reason:"completed"}),e.dispatch(No({selection:Ot({operation:d.operation,reason:"complete"})})),[g,ei({id:d.id,selections:[Ot({operation:d.operation,reason:"complete"})]})]})}l.message.role==="assistant"&&l.message.content!==null&&l.message.content.length>0&&n.push(async()=>{const c=Sn({role:"assistant",text:l.message.content});return e.dispatch(ti({role:"assistant",get:()=>c.text,done:()=>!0,stream:Qe.to(c.text),join:async()=>Promise.resolve(c.text)})),[c]})}return(await Promise.all(n.map(async l=>l()))).flat()}async function Mo(e,t,n){var i,r,a;if(t.operation.protocol==="http"){const o=t.operation.function.validate(t.arguments);if(o.success===!1&&(e.dispatch(Xr({id:t.id,operation:t.operation,result:o})),n++<(((i=e.config)==null?void 0:i.retry)??Ct.RETRY))){const u=await Ii(e,t,n,o.errors);if(u!==null)return u}try{const u=await up(t.operation,t.arguments);return(((u.status===400||u.status===404||u.status===422)&&n++<(((r=e.config)==null?void 0:r.retry)??Ct.RETRY)&&typeof u.body)===!1===!1?await Ii(e,t,n,u.body):null)??At({operation:t.operation,id:t.id,arguments:t.arguments,value:u})}catch(u){return At({operation:t.operation,id:t.id,arguments:t.arguments,value:{status:500,headers:{},body:u instanceof Error?{...u,name:u.name,message:u.message}:u}})}}else{const o=t.operation.function.validate(t.arguments);if(o.success===!1)return e.dispatch(Xr({id:t.id,operation:t.operation,result:o})),(n++<(((a=e.config)==null?void 0:a.retry)??Ct.RETRY)?await Ii(e,t,n,o.errors):null)??At({id:t.id,operation:t.operation,arguments:t.arguments,value:{name:"TypeGuardError",message:"Invalid arguments.",errors:o.errors}});try{const u=await lp(t.operation,t.arguments);return At({id:t.id,operation:t.operation,arguments:t.arguments,value:u})}catch(u){return At({id:t.id,operation:t.operation,arguments:t.arguments,value:u instanceof Error?{...u,name:u.name,message:u.message}:u})}}}async function up(e,t){const n={connection:e.controller.connection,application:e.controller.application,function:e.function};return e.controller.execute!==void 0?e.controller.execute({...n,arguments:t}):qu.propagate({...n,input:t})}async function lp(e,t){const n=e.controller.execute;return typeof n=="function"?await n({application:e.controller.application,function:e.function,arguments:t}):n[e.function.name](t)}async function Ii(e,t,n,i){var l,c,p,d,g;const r=await e.request("call",{messages:[{role:"system",content:jt.write(e.config)},...e.histories.map(Ut).flat(),{role:"user",content:e.prompt.text},{role:"system",content:((p=(c=(l=e.config)==null?void 0:l.systemPrompt)==null?void 0:c.execute)==null?void 0:p.call(c,e.histories))??_t.EXECUTE},{role:"assistant",tool_calls:[{type:"function",id:t.id,function:{name:t.operation.name,arguments:JSON.stringify(t.arguments)}}]},{role:"tool",content:typeof i=="string"?i:JSON.stringify(i),tool_call_id:t.id},{role:"system",content:["You A.I. assistant has composed wrong arguments.","","Correct it at the next function calling."].join(`
|
|
29
29
|
`)}],tools:[{type:"function",function:{name:t.operation.name,description:t.operation.function.description,parameters:t.operation.function.separated!==void 0?((d=t.operation.function.separated)==null?void 0:d.llm)??{$defs:{},type:"object",properties:{},additionalProperties:!1,required:[]}:t.operation.function.parameters}}],tool_choice:"auto",parallel_tool_calls:!1}),a=await Qe.readAll(r),u=(((g=rt.merge(a).choices[0])==null?void 0:g.message.tool_calls)??[]).find(m=>m.type==="function"&&m.function.name===t.operation.name);return u===void 0?null:Mo(e,vo({id:u.id,operation:t.operation,arguments:JSON.parse(u.function.arguments)}),n)}function cp(e){var n;if(e.operation.protocol!=="http")return;const t=e.operation.function.route();t.body!==null&&((n=t.operation().requestBody)==null?void 0:n.required)===!0&&"body"in e.arguments&&Li(e.operation.function.parameters.$defs,e.operation.function.parameters.properties.body)&&(e.arguments.body={}),t.query!==null&&"query"in e.arguments&&e.arguments.query===void 0&&(e.arguments.query={})}function Li(e,t){return mi.isObject(t)||mi.isReference(t)&&Li(e,e[t.$ref.split("/").at(-1)])||mi.isAnyOf(t)&&t.anyOf.every(n=>Li(e,n))}const pp={functions:[{name:"cancelFunctions",parameters:{description:` Properties of the function
|
|
30
30
|
|
|
31
31
|
------------------------------
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as I,o as as,r as Ue,T as bt}from"../client-nQAh1QKo.js";import{_ as xt,F as is,T as xn,R as os,c as Sn,d as An,B as ls}from"../index-af7ihIz8.js";import{v as cs,A as us,b as We,_ as Je,c as ds}from"../_isFormatUri-Czmim0us.js";import{D as hs}from"../Divider-U2p72sQ2.js";const Tt="RFC3986",kt={RFC1738:r=>String(r).replace(/%20/g,"+"),RFC3986:r=>String(r)},fs="RFC1738",ms=Array.isArray,z=(()=>{const r=[];for(let e=0;e<256;++e)r.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return r})(),St=1024,ps=(r,e,t,n,s)=>{if(r.length===0)return r;let a=r;if(typeof r=="symbol"?a=Symbol.prototype.toString.call(r):typeof r!="string"&&(a=String(r)),t==="iso-8859-1")return escape(a).replace(/%u[0-9a-f]{4}/gi,function(l){return"%26%23"+parseInt(l.slice(2),16)+"%3B"});let i="";for(let l=0;l<a.length;l+=St){const u=a.length>=St?a.slice(l,l+St):a,d=[];for(let o=0;o<u.length;++o){let c=u.charCodeAt(o);if(c===45||c===46||c===95||c===126||c>=48&&c<=57||c>=65&&c<=90||c>=97&&c<=122||s===fs&&(c===40||c===41)){d[d.length]=u.charAt(o);continue}if(c<128){d[d.length]=z[c];continue}if(c<2048){d[d.length]=z[192|c>>6]+z[128|c&63];continue}if(c<55296||c>=57344){d[d.length]=z[224|c>>12]+z[128|c>>6&63]+z[128|c&63];continue}o+=1,c=65536+((c&1023)<<10|u.charCodeAt(o)&1023),d[d.length]=z[240|c>>18]+z[128|c>>12&63]+z[128|c>>6&63]+z[128|c&63]}i+=d.join("")}return i};function gs(r){return!r||typeof r!="object"?!1:!!(r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer(r))}function Cn(r,e){if(ms(r)){const t=[];for(let n=0;n<r.length;n+=1)t.push(e(r[n]));return t}return e(r)}const _s=Object.prototype.hasOwnProperty,Vn={brackets(r){return String(r)+"[]"},comma:"comma",indices(r,e){return String(r)+"["+e+"]"},repeat(r){return String(r)}},Y=Array.isArray,ys=Array.prototype.push,Kn=function(r,e){ys.apply(r,Y(e)?e:[e])},ws=Date.prototype.toISOString,F={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:ps,encodeValuesOnly:!1,format:Tt,formatter:kt[Tt],indices:!1,serializeDate(r){return ws.call(r)},skipNulls:!1,strictNullHandling:!1};function bs(r){return typeof r=="string"||typeof r=="number"||typeof r=="boolean"||typeof r=="symbol"||typeof r=="bigint"}const At={};function Gn(r,e,t,n,s,a,i,l,u,d,o,c,h,f,w,g,_,N){let m=r,C=N,b=0,O=!1;for(;(C=C.get(At))!==void 0&&!O;){const $=C.get(r);if(b+=1,typeof $<"u"){if($===b)throw new RangeError("Cyclic object value");O=!0}typeof C.get(At)>"u"&&(b=0)}if(typeof d=="function"?m=d(e,m):m instanceof Date?m=h==null?void 0:h(m):t==="comma"&&Y(m)&&(m=Cn(m,function($){return $ instanceof Date?h==null?void 0:h($):$})),m===null){if(a)return u&&!g?u(e,F.encoder,_,"key",f):e;m=""}if(bs(m)||gs(m)){if(u){const $=g?e:u(e,F.encoder,_,"key",f);return[(w==null?void 0:w($))+"="+(w==null?void 0:w(u(m,F.encoder,_,"value",f)))]}return[(w==null?void 0:w(e))+"="+(w==null?void 0:w(String(m)))]}const v=[];if(typeof m>"u")return v;let A;if(t==="comma"&&Y(m))g&&u&&(m=Cn(m,u)),A=[{value:m.length>0?m.join(",")||null:void 0}];else if(Y(d))A=d;else{const $=Object.keys(m);A=o?$.sort(o):$}const H=l?String(e).replace(/\./g,"%2E"):String(e),T=n&&Y(m)&&m.length===1?H+"[]":H;if(s&&Y(m)&&m.length===0)return T+"[]";for(let $=0;$<A.length;++$){const P=A[$],ue=typeof P=="object"&&typeof P.value<"u"?P.value:m[P];if(i&&ue===null)continue;const wt=c&&l?P.replace(/\./g,"%2E"):P,ss=Y(m)?typeof t=="function"?t(T,wt):T:T+(c?"."+wt:"["+wt+"]");N.set(r,b);const bn=new WeakMap;bn.set(At,N),Kn(v,Gn(ue,ss,t,n,s,a,i,l,t==="comma"&&g&&Y(m)?null:u,d,o,c,h,f,w,g,_,bn))}return v}function xs(r=F){if(typeof r.allowEmptyArrays<"u"&&typeof r.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof r.encodeDotInKeys<"u"&&typeof r.encodeDotInKeys!="boolean")throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(r.encoder!==null&&typeof r.encoder<"u"&&typeof r.encoder!="function")throw new TypeError("Encoder has to be a function.");const e=r.charset||F.charset;if(typeof r.charset<"u"&&r.charset!=="utf-8"&&r.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");let t=Tt;if(typeof r.format<"u"){if(!_s.call(kt,r.format))throw new TypeError("Unknown format option provided.");t=r.format}const n=kt[t];let s=F.filter;(typeof r.filter=="function"||Y(r.filter))&&(s=r.filter);let a;if(r.arrayFormat&&r.arrayFormat in Vn?a=r.arrayFormat:"indices"in r?a=r.indices?"indices":"repeat":a=F.arrayFormat,"commaRoundTrip"in r&&typeof r.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");const i=typeof r.allowDots>"u"?r.encodeDotInKeys?!0:F.allowDots:!!r.allowDots;return{addQueryPrefix:typeof r.addQueryPrefix=="boolean"?r.addQueryPrefix:F.addQueryPrefix,allowDots:i,allowEmptyArrays:typeof r.allowEmptyArrays=="boolean"?!!r.allowEmptyArrays:F.allowEmptyArrays,arrayFormat:a,charset:e,charsetSentinel:typeof r.charsetSentinel=="boolean"?r.charsetSentinel:F.charsetSentinel,commaRoundTrip:!!r.commaRoundTrip,delimiter:typeof r.delimiter>"u"?F.delimiter:r.delimiter,encode:typeof r.encode=="boolean"?r.encode:F.encode,encodeDotInKeys:typeof r.encodeDotInKeys=="boolean"?r.encodeDotInKeys:F.encodeDotInKeys,encoder:typeof r.encoder=="function"?r.encoder:F.encoder,encodeValuesOnly:typeof r.encodeValuesOnly=="boolean"?r.encodeValuesOnly:F.encodeValuesOnly,filter:s,format:t,formatter:n,serializeDate:typeof r.serializeDate=="function"?r.serializeDate:F.serializeDate,skipNulls:typeof r.skipNulls=="boolean"?r.skipNulls:F.skipNulls,sort:typeof r.sort=="function"?r.sort:null,strictNullHandling:typeof r.strictNullHandling=="boolean"?r.strictNullHandling:F.strictNullHandling}}function Ss(r,e={}){let t=r;const n=xs(e);let s,a;typeof n.filter=="function"?(a=n.filter,t=a("",t)):Y(n.filter)&&(a=n.filter,s=a);const i=[];if(typeof t!="object"||t===null)return"";const l=Vn[n.arrayFormat],u=l==="comma"&&n.commaRoundTrip;s||(s=Object.keys(t)),n.sort&&s.sort(n.sort);const d=new WeakMap;for(let h=0;h<s.length;++h){const f=s[h];n.skipNulls&&t[f]===null||Kn(i,Gn(t[f],f,l,u,n.allowEmptyArrays,n.strictNullHandling,n.skipNulls,n.encodeDotInKeys,n.encode?n.encoder:null,n.filter,n.sort,n.allowDots,n.serializeDate,n.format,n.formatter,n.encodeValuesOnly,n.charset,d))}const o=i.join(n.delimiter);let c=n.addQueryPrefix===!0?"?":"";return n.charsetSentinel&&(n.charset==="iso-8859-1"?c+="utf8=%26%2310003%3B&":c+="utf8=%E2%9C%93&"),o.length>0?c+o:""}const pe="4.89.0";let vn=!1,Te,Qn,zn,Ft,Yn,Zn,er,tr,nr;function As(r,e={auto:!1}){if(vn)throw new Error(`you must \`import 'openai/shims/${r.kind}'\` before importing anything else from openai`);if(Te)throw new Error(`can't \`import 'openai/shims/${r.kind}'\` after \`import 'openai/shims/${Te}'\``);vn=e.auto,Te=r.kind,Qn=r.fetch,zn=r.FormData,Ft=r.File,Yn=r.ReadableStream,Zn=r.getMultipartRequestOptions,er=r.getDefaultAgent,tr=r.fileFromPath,nr=r.isFsReadStream}class Cs{constructor(e){this.body=e}get[Symbol.toStringTag](){return"MultipartBody"}}function vs({manuallyImported:r}={}){const e=r?"You may need to use polyfills":"Add one of these imports before your first `import … from 'openai'`:\n- `import 'openai/shims/node'` (if you're running on Node)\n- `import 'openai/shims/web'` (otherwise)\n";let t,n,s,a;try{t=fetch,n=Request,s=Response,a=Headers}catch(i){throw new Error(`this environment is missing the following Web Fetch API type: ${i.message}. ${e}`)}return{kind:"web",fetch:t,Request:n,Response:s,Headers:a,FormData:typeof FormData<"u"?FormData:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'FormData' is undefined. ${e}`)}},Blob:typeof Blob<"u"?Blob:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'Blob' is undefined. ${e}`)}},File:typeof File<"u"?File:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'File' is undefined. ${e}`)}},ReadableStream:typeof ReadableStream<"u"?ReadableStream:class{constructor(){throw new Error(`streaming isn't supported in this environment yet as 'ReadableStream' is undefined. ${e}`)}},getMultipartRequestOptions:async(i,l)=>({...l,body:new Cs(i)}),getDefaultAgent:i=>{},fileFromPath:()=>{throw new Error("The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/openai/openai-node#file-uploads")},isFsReadStream:i=>!1}}Te||As(vs(),{auto:!0});class y extends Error{}class j extends y{constructor(e,t,n,s){super(`${j.makeMessage(e,t,n)}`),this.status=e,this.headers=s,this.request_id=s==null?void 0:s["x-request-id"],this.error=t;const a=t;this.code=a==null?void 0:a.code,this.param=a==null?void 0:a.param,this.type=a==null?void 0:a.type}static makeMessage(e,t,n){const s=t!=null&&t.message?typeof t.message=="string"?t.message:JSON.stringify(t.message):t?JSON.stringify(t):n;return e&&s?`${e} ${s}`:e?`${e} status code (no body)`:s||"(no status code or body)"}static generate(e,t,n,s){if(!e||!s)return new ct({message:n,cause:Bt(t)});const a=t==null?void 0:t.error;return e===400?new rr(e,a,n,s):e===401?new sr(e,a,n,s):e===403?new ar(e,a,n,s):e===404?new ir(e,a,n,s):e===409?new or(e,a,n,s):e===422?new lr(e,a,n,s):e===429?new cr(e,a,n,s):e>=500?new ur(e,a,n,s):new j(e,a,n,s)}}class V extends j{constructor({message:e}={}){super(void 0,void 0,e||"Request was aborted.",void 0)}}class ct extends j{constructor({message:e,cause:t}){super(void 0,void 0,e||"Connection error.",void 0),t&&(this.cause=t)}}class Xt extends ct{constructor({message:e}={}){super({message:e??"Request timed out."})}}class rr extends j{}class sr extends j{}class ar extends j{}class ir extends j{}class or extends j{}class lr extends j{}class cr extends j{}class ur extends j{}class dr extends y{constructor(){super("Could not parse response content as the length limit was reached")}}class hr extends y{constructor(){super("Could not parse response content as the request was rejected by the content filter")}}var qe=function(r,e,t,n,s){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},oe=function(r,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(r):n?n.value:e.get(r)},q;class ut{constructor(){q.set(this,void 0),this.buffer=new Uint8Array,qe(this,q,null,"f")}decode(e){if(e==null)return[];const t=e instanceof ArrayBuffer?new Uint8Array(e):typeof e=="string"?new TextEncoder().encode(e):e;let n=new Uint8Array(this.buffer.length+t.length);n.set(this.buffer),n.set(t,this.buffer.length),this.buffer=n;const s=[];let a;for(;(a=Rs(this.buffer,oe(this,q,"f")))!=null;){if(a.carriage&&oe(this,q,"f")==null){qe(this,q,a.index,"f");continue}if(oe(this,q,"f")!=null&&(a.index!==oe(this,q,"f")+1||a.carriage)){s.push(this.decodeText(this.buffer.slice(0,oe(this,q,"f")-1))),this.buffer=this.buffer.slice(oe(this,q,"f")),qe(this,q,null,"f");continue}const i=oe(this,q,"f")!==null?a.preceding-1:a.preceding,l=this.decodeText(this.buffer.slice(0,i));s.push(l),this.buffer=this.buffer.slice(a.index),qe(this,q,null,"f")}return s}decodeText(e){if(e==null)return"";if(typeof e=="string")return e;if(typeof Buffer<"u"){if(e instanceof Buffer)return e.toString();if(e instanceof Uint8Array)return Buffer.from(e).toString();throw new y(`Unexpected: received non-Uint8Array (${e.constructor.name}) stream chunk in an environment with a global "Buffer" defined, which this library assumes to be Node. Please report this error.`)}if(typeof TextDecoder<"u"){if(e instanceof Uint8Array||e instanceof ArrayBuffer)return this.textDecoder??(this.textDecoder=new TextDecoder("utf8")),this.textDecoder.decode(e);throw new y(`Unexpected: received non-Uint8Array/ArrayBuffer (${e.constructor.name}) in a web platform. Please report this error.`)}throw new y("Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.")}flush(){return this.buffer.length?this.decode(`
|
|
1
|
+
import{j as I,o as as,r as Ue,T as bt}from"../client-nQAh1QKo.js";import{_ as xt,F as is,T as xn,R as os,c as Sn,d as An,B as ls}from"../index-af7ihIz8.js";import{v as cs,A as us,b as We,_ as Je,c as ds}from"../_isFormatUri-D80pJ-Bz.js";import{D as hs}from"../Divider-U2p72sQ2.js";const Tt="RFC3986",kt={RFC1738:r=>String(r).replace(/%20/g,"+"),RFC3986:r=>String(r)},fs="RFC1738",ms=Array.isArray,z=(()=>{const r=[];for(let e=0;e<256;++e)r.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return r})(),St=1024,ps=(r,e,t,n,s)=>{if(r.length===0)return r;let a=r;if(typeof r=="symbol"?a=Symbol.prototype.toString.call(r):typeof r!="string"&&(a=String(r)),t==="iso-8859-1")return escape(a).replace(/%u[0-9a-f]{4}/gi,function(l){return"%26%23"+parseInt(l.slice(2),16)+"%3B"});let i="";for(let l=0;l<a.length;l+=St){const u=a.length>=St?a.slice(l,l+St):a,d=[];for(let o=0;o<u.length;++o){let c=u.charCodeAt(o);if(c===45||c===46||c===95||c===126||c>=48&&c<=57||c>=65&&c<=90||c>=97&&c<=122||s===fs&&(c===40||c===41)){d[d.length]=u.charAt(o);continue}if(c<128){d[d.length]=z[c];continue}if(c<2048){d[d.length]=z[192|c>>6]+z[128|c&63];continue}if(c<55296||c>=57344){d[d.length]=z[224|c>>12]+z[128|c>>6&63]+z[128|c&63];continue}o+=1,c=65536+((c&1023)<<10|u.charCodeAt(o)&1023),d[d.length]=z[240|c>>18]+z[128|c>>12&63]+z[128|c>>6&63]+z[128|c&63]}i+=d.join("")}return i};function gs(r){return!r||typeof r!="object"?!1:!!(r.constructor&&r.constructor.isBuffer&&r.constructor.isBuffer(r))}function Cn(r,e){if(ms(r)){const t=[];for(let n=0;n<r.length;n+=1)t.push(e(r[n]));return t}return e(r)}const _s=Object.prototype.hasOwnProperty,Vn={brackets(r){return String(r)+"[]"},comma:"comma",indices(r,e){return String(r)+"["+e+"]"},repeat(r){return String(r)}},Y=Array.isArray,ys=Array.prototype.push,Kn=function(r,e){ys.apply(r,Y(e)?e:[e])},ws=Date.prototype.toISOString,F={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:ps,encodeValuesOnly:!1,format:Tt,formatter:kt[Tt],indices:!1,serializeDate(r){return ws.call(r)},skipNulls:!1,strictNullHandling:!1};function bs(r){return typeof r=="string"||typeof r=="number"||typeof r=="boolean"||typeof r=="symbol"||typeof r=="bigint"}const At={};function Gn(r,e,t,n,s,a,i,l,u,d,o,c,h,f,w,g,_,N){let m=r,C=N,b=0,O=!1;for(;(C=C.get(At))!==void 0&&!O;){const $=C.get(r);if(b+=1,typeof $<"u"){if($===b)throw new RangeError("Cyclic object value");O=!0}typeof C.get(At)>"u"&&(b=0)}if(typeof d=="function"?m=d(e,m):m instanceof Date?m=h==null?void 0:h(m):t==="comma"&&Y(m)&&(m=Cn(m,function($){return $ instanceof Date?h==null?void 0:h($):$})),m===null){if(a)return u&&!g?u(e,F.encoder,_,"key",f):e;m=""}if(bs(m)||gs(m)){if(u){const $=g?e:u(e,F.encoder,_,"key",f);return[(w==null?void 0:w($))+"="+(w==null?void 0:w(u(m,F.encoder,_,"value",f)))]}return[(w==null?void 0:w(e))+"="+(w==null?void 0:w(String(m)))]}const v=[];if(typeof m>"u")return v;let A;if(t==="comma"&&Y(m))g&&u&&(m=Cn(m,u)),A=[{value:m.length>0?m.join(",")||null:void 0}];else if(Y(d))A=d;else{const $=Object.keys(m);A=o?$.sort(o):$}const H=l?String(e).replace(/\./g,"%2E"):String(e),T=n&&Y(m)&&m.length===1?H+"[]":H;if(s&&Y(m)&&m.length===0)return T+"[]";for(let $=0;$<A.length;++$){const P=A[$],ue=typeof P=="object"&&typeof P.value<"u"?P.value:m[P];if(i&&ue===null)continue;const wt=c&&l?P.replace(/\./g,"%2E"):P,ss=Y(m)?typeof t=="function"?t(T,wt):T:T+(c?"."+wt:"["+wt+"]");N.set(r,b);const bn=new WeakMap;bn.set(At,N),Kn(v,Gn(ue,ss,t,n,s,a,i,l,t==="comma"&&g&&Y(m)?null:u,d,o,c,h,f,w,g,_,bn))}return v}function xs(r=F){if(typeof r.allowEmptyArrays<"u"&&typeof r.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof r.encodeDotInKeys<"u"&&typeof r.encodeDotInKeys!="boolean")throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(r.encoder!==null&&typeof r.encoder<"u"&&typeof r.encoder!="function")throw new TypeError("Encoder has to be a function.");const e=r.charset||F.charset;if(typeof r.charset<"u"&&r.charset!=="utf-8"&&r.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");let t=Tt;if(typeof r.format<"u"){if(!_s.call(kt,r.format))throw new TypeError("Unknown format option provided.");t=r.format}const n=kt[t];let s=F.filter;(typeof r.filter=="function"||Y(r.filter))&&(s=r.filter);let a;if(r.arrayFormat&&r.arrayFormat in Vn?a=r.arrayFormat:"indices"in r?a=r.indices?"indices":"repeat":a=F.arrayFormat,"commaRoundTrip"in r&&typeof r.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");const i=typeof r.allowDots>"u"?r.encodeDotInKeys?!0:F.allowDots:!!r.allowDots;return{addQueryPrefix:typeof r.addQueryPrefix=="boolean"?r.addQueryPrefix:F.addQueryPrefix,allowDots:i,allowEmptyArrays:typeof r.allowEmptyArrays=="boolean"?!!r.allowEmptyArrays:F.allowEmptyArrays,arrayFormat:a,charset:e,charsetSentinel:typeof r.charsetSentinel=="boolean"?r.charsetSentinel:F.charsetSentinel,commaRoundTrip:!!r.commaRoundTrip,delimiter:typeof r.delimiter>"u"?F.delimiter:r.delimiter,encode:typeof r.encode=="boolean"?r.encode:F.encode,encodeDotInKeys:typeof r.encodeDotInKeys=="boolean"?r.encodeDotInKeys:F.encodeDotInKeys,encoder:typeof r.encoder=="function"?r.encoder:F.encoder,encodeValuesOnly:typeof r.encodeValuesOnly=="boolean"?r.encodeValuesOnly:F.encodeValuesOnly,filter:s,format:t,formatter:n,serializeDate:typeof r.serializeDate=="function"?r.serializeDate:F.serializeDate,skipNulls:typeof r.skipNulls=="boolean"?r.skipNulls:F.skipNulls,sort:typeof r.sort=="function"?r.sort:null,strictNullHandling:typeof r.strictNullHandling=="boolean"?r.strictNullHandling:F.strictNullHandling}}function Ss(r,e={}){let t=r;const n=xs(e);let s,a;typeof n.filter=="function"?(a=n.filter,t=a("",t)):Y(n.filter)&&(a=n.filter,s=a);const i=[];if(typeof t!="object"||t===null)return"";const l=Vn[n.arrayFormat],u=l==="comma"&&n.commaRoundTrip;s||(s=Object.keys(t)),n.sort&&s.sort(n.sort);const d=new WeakMap;for(let h=0;h<s.length;++h){const f=s[h];n.skipNulls&&t[f]===null||Kn(i,Gn(t[f],f,l,u,n.allowEmptyArrays,n.strictNullHandling,n.skipNulls,n.encodeDotInKeys,n.encode?n.encoder:null,n.filter,n.sort,n.allowDots,n.serializeDate,n.format,n.formatter,n.encodeValuesOnly,n.charset,d))}const o=i.join(n.delimiter);let c=n.addQueryPrefix===!0?"?":"";return n.charsetSentinel&&(n.charset==="iso-8859-1"?c+="utf8=%26%2310003%3B&":c+="utf8=%E2%9C%93&"),o.length>0?c+o:""}const pe="4.89.0";let vn=!1,Te,Qn,zn,Ft,Yn,Zn,er,tr,nr;function As(r,e={auto:!1}){if(vn)throw new Error(`you must \`import 'openai/shims/${r.kind}'\` before importing anything else from openai`);if(Te)throw new Error(`can't \`import 'openai/shims/${r.kind}'\` after \`import 'openai/shims/${Te}'\``);vn=e.auto,Te=r.kind,Qn=r.fetch,zn=r.FormData,Ft=r.File,Yn=r.ReadableStream,Zn=r.getMultipartRequestOptions,er=r.getDefaultAgent,tr=r.fileFromPath,nr=r.isFsReadStream}class Cs{constructor(e){this.body=e}get[Symbol.toStringTag](){return"MultipartBody"}}function vs({manuallyImported:r}={}){const e=r?"You may need to use polyfills":"Add one of these imports before your first `import … from 'openai'`:\n- `import 'openai/shims/node'` (if you're running on Node)\n- `import 'openai/shims/web'` (otherwise)\n";let t,n,s,a;try{t=fetch,n=Request,s=Response,a=Headers}catch(i){throw new Error(`this environment is missing the following Web Fetch API type: ${i.message}. ${e}`)}return{kind:"web",fetch:t,Request:n,Response:s,Headers:a,FormData:typeof FormData<"u"?FormData:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'FormData' is undefined. ${e}`)}},Blob:typeof Blob<"u"?Blob:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'Blob' is undefined. ${e}`)}},File:typeof File<"u"?File:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'File' is undefined. ${e}`)}},ReadableStream:typeof ReadableStream<"u"?ReadableStream:class{constructor(){throw new Error(`streaming isn't supported in this environment yet as 'ReadableStream' is undefined. ${e}`)}},getMultipartRequestOptions:async(i,l)=>({...l,body:new Cs(i)}),getDefaultAgent:i=>{},fileFromPath:()=>{throw new Error("The `fileFromPath` function is only supported in Node. See the README for more details: https://www.github.com/openai/openai-node#file-uploads")},isFsReadStream:i=>!1}}Te||As(vs(),{auto:!0});class y extends Error{}class j extends y{constructor(e,t,n,s){super(`${j.makeMessage(e,t,n)}`),this.status=e,this.headers=s,this.request_id=s==null?void 0:s["x-request-id"],this.error=t;const a=t;this.code=a==null?void 0:a.code,this.param=a==null?void 0:a.param,this.type=a==null?void 0:a.type}static makeMessage(e,t,n){const s=t!=null&&t.message?typeof t.message=="string"?t.message:JSON.stringify(t.message):t?JSON.stringify(t):n;return e&&s?`${e} ${s}`:e?`${e} status code (no body)`:s||"(no status code or body)"}static generate(e,t,n,s){if(!e||!s)return new ct({message:n,cause:Bt(t)});const a=t==null?void 0:t.error;return e===400?new rr(e,a,n,s):e===401?new sr(e,a,n,s):e===403?new ar(e,a,n,s):e===404?new ir(e,a,n,s):e===409?new or(e,a,n,s):e===422?new lr(e,a,n,s):e===429?new cr(e,a,n,s):e>=500?new ur(e,a,n,s):new j(e,a,n,s)}}class V extends j{constructor({message:e}={}){super(void 0,void 0,e||"Request was aborted.",void 0)}}class ct extends j{constructor({message:e,cause:t}){super(void 0,void 0,e||"Connection error.",void 0),t&&(this.cause=t)}}class Xt extends ct{constructor({message:e}={}){super({message:e??"Request timed out."})}}class rr extends j{}class sr extends j{}class ar extends j{}class ir extends j{}class or extends j{}class lr extends j{}class cr extends j{}class ur extends j{}class dr extends y{constructor(){super("Could not parse response content as the length limit was reached")}}class hr extends y{constructor(){super("Could not parse response content as the request was rejected by the content filter")}}var qe=function(r,e,t,n,s){if(n==="m")throw new TypeError("Private method is not writable");if(n==="a"&&!s)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?r!==e||!s:!e.has(r))throw new TypeError("Cannot write private member to an object whose class did not declare it");return n==="a"?s.call(r,t):s?s.value=t:e.set(r,t),t},oe=function(r,e,t,n){if(t==="a"&&!n)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?r!==e||!n:!e.has(r))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?n:t==="a"?n.call(r):n?n.value:e.get(r)},q;class ut{constructor(){q.set(this,void 0),this.buffer=new Uint8Array,qe(this,q,null,"f")}decode(e){if(e==null)return[];const t=e instanceof ArrayBuffer?new Uint8Array(e):typeof e=="string"?new TextEncoder().encode(e):e;let n=new Uint8Array(this.buffer.length+t.length);n.set(this.buffer),n.set(t,this.buffer.length),this.buffer=n;const s=[];let a;for(;(a=Rs(this.buffer,oe(this,q,"f")))!=null;){if(a.carriage&&oe(this,q,"f")==null){qe(this,q,a.index,"f");continue}if(oe(this,q,"f")!=null&&(a.index!==oe(this,q,"f")+1||a.carriage)){s.push(this.decodeText(this.buffer.slice(0,oe(this,q,"f")-1))),this.buffer=this.buffer.slice(oe(this,q,"f")),qe(this,q,null,"f");continue}const i=oe(this,q,"f")!==null?a.preceding-1:a.preceding,l=this.decodeText(this.buffer.slice(0,i));s.push(l),this.buffer=this.buffer.slice(a.index),qe(this,q,null,"f")}return s}decodeText(e){if(e==null)return"";if(typeof e=="string")return e;if(typeof Buffer<"u"){if(e instanceof Buffer)return e.toString();if(e instanceof Uint8Array)return Buffer.from(e).toString();throw new y(`Unexpected: received non-Uint8Array (${e.constructor.name}) stream chunk in an environment with a global "Buffer" defined, which this library assumes to be Node. Please report this error.`)}if(typeof TextDecoder<"u"){if(e instanceof Uint8Array||e instanceof ArrayBuffer)return this.textDecoder??(this.textDecoder=new TextDecoder("utf8")),this.textDecoder.decode(e);throw new y(`Unexpected: received non-Uint8Array/ArrayBuffer (${e.constructor.name}) in a web platform. Please report this error.`)}throw new y("Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.")}flush(){return this.buffer.length?this.decode(`
|
|
2
2
|
`):[]}}q=new WeakMap;ut.NEWLINE_CHARS=new Set([`
|
|
3
3
|
`,"\r"]);ut.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function Rs(r,e){for(let s=e??0;s<r.length;s++){if(r[s]===10)return{preceding:s,index:s+1,carriage:!1};if(r[s]===13)return{preceding:s,index:s+1,carriage:!0}}return null}function Ps(r){for(let n=0;n<r.length-1;n++){if(r[n]===10&&r[n+1]===10||r[n]===13&&r[n+1]===13)return n+2;if(r[n]===13&&r[n+1]===10&&n+3<r.length&&r[n+2]===13&&r[n+3]===10)return n+4}return-1}function fr(r){if(r[Symbol.asyncIterator])return r;const e=r.getReader();return{async next(){try{const t=await e.read();return t!=null&&t.done&&e.releaseLock(),t}catch(t){throw e.releaseLock(),t}},async return(){const t=e.cancel();return e.releaseLock(),await t,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}class ee{constructor(e,t){this.iterator=e,this.controller=t}static fromSSEResponse(e,t){let n=!1;async function*s(){if(n)throw new Error("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");n=!0;let a=!1;try{for await(const i of Is(e,t))if(!a){if(i.data.startsWith("[DONE]")){a=!0;continue}if(i.event===null||i.event.startsWith("response.")){let l;try{l=JSON.parse(i.data)}catch(u){throw console.error("Could not parse message into JSON:",i.data),console.error("From chunk:",i.raw),u}if(l&&l.error)throw new j(void 0,l.error,void 0,void 0);yield l}else{let l;try{l=JSON.parse(i.data)}catch(u){throw console.error("Could not parse message into JSON:",i.data),console.error("From chunk:",i.raw),u}if(i.event=="error")throw new j(void 0,l.error,l.message,void 0);yield{event:i.event,data:l}}}a=!0}catch(i){if(i instanceof Error&&i.name==="AbortError")return;throw i}finally{a||t.abort()}}return new ee(s,t)}static fromReadableStream(e,t){let n=!1;async function*s(){const i=new ut,l=fr(e);for await(const u of l)for(const d of i.decode(u))yield d;for(const u of i.flush())yield u}async function*a(){if(n)throw new Error("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");n=!0;let i=!1;try{for await(const l of s())i||l&&(yield JSON.parse(l));i=!0}catch(l){if(l instanceof Error&&l.name==="AbortError")return;throw l}finally{i||t.abort()}}return new ee(a,t)}[Symbol.asyncIterator](){return this.iterator()}tee(){const e=[],t=[],n=this.iterator(),s=a=>({next:()=>{if(a.length===0){const i=n.next();e.push(i),t.push(i)}return a.shift()}});return[new ee(()=>s(e),this.controller),new ee(()=>s(t),this.controller)]}toReadableStream(){const e=this;let t;const n=new TextEncoder;return new Yn({async start(){t=e[Symbol.asyncIterator]()},async pull(s){try{const{value:a,done:i}=await t.next();if(i)return s.close();const l=n.encode(JSON.stringify(a)+`
|
|
4
4
|
`);s.enqueue(l)}catch(a){s.error(a)}},async cancel(){var s;await((s=t.return)==null?void 0:s.call(t))}})}}async function*Is(r,e){if(!r.body)throw e.abort(),new y("Attempted to iterate over a response with no body");const t=new $s,n=new ut,s=fr(r.body);for await(const a of Es(s))for(const i of n.decode(a)){const l=t.decode(i);l&&(yield l)}for(const a of n.flush()){const i=t.decode(a);i&&(yield i)}}async function*Es(r){let e=new Uint8Array;for await(const t of r){if(t==null)continue;const n=t instanceof ArrayBuffer?new Uint8Array(t):typeof t=="string"?new TextEncoder().encode(t):t;let s=new Uint8Array(e.length+n.length);s.set(e),s.set(n,e.length),e=s;let a;for(;(a=Ps(e))!==-1;)yield e.slice(0,a),e=e.slice(a)}e.length>0&&(yield e)}class $s{constructor(){this.event=null,this.data=[],this.chunks=[]}decode(e){if(e.endsWith("\r")&&(e=e.substring(0,e.length-1)),!e){if(!this.event&&!this.data.length)return null;const a={event:this.event,data:this.data.join(`
|