@agentica/chat 0.22.0 → 0.24.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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  <!-- https://github.com/user-attachments/assets/5326cc59-5129-470d-abcb-c3f458b5c488 -->
4
4
 
5
- ![Logo](https://wrtnlabs.io/agentica/og.jpg?refresh)
5
+ ![Logo](https://wrtnlabs.io/agentica/og.jpg)
6
6
 
7
7
  [![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/wrtnlabs/agentica/blob/master/LICENSE)
8
8
  [![NPM Version](https://img.shields.io/npm/v/@agentica/core.svg)](https://www.npmjs.com/package/@agentica/core)
@@ -26,7 +26,7 @@ Are you a TypeScript developer? Then you're already an AI developer. Familiar wi
26
26
  <!-- eslint-skip -->
27
27
 
28
28
  ```typescript
29
- import { Agentica, assertHttpLlmApplication } from "@agentica/core";
29
+ import { Agentica, assertHttpController } from "@agentica/core";
30
30
  import OpenAI from "openai";
31
31
  import typia from "typia";
32
32
 
@@ -40,24 +40,23 @@ const agent = new Agentica({
40
40
  controllers: [
41
41
  // functions from TypeScript class
42
42
  {
43
- protocol: "http",
43
+ protocol: "class",
44
+ name: "filesystem",
44
45
  application: typia.llm.application<MobileFileSystem, "chatgpt">(),
45
46
  execute: new MobileFileSystem(),
46
47
  },
47
48
  // functions from Swagger/OpenAPI
48
- {
49
- protocol: "http",
50
- application: assertHttpLlmApplication({
51
- model: "chatgpt",
52
- document: await fetch(
53
- "https://shopping-be.wrtn.ai/editor/swagger.json",
54
- ).then(r => r.json()),
55
- }),
49
+ assertHttpController({
50
+ name: "shopping",
51
+ model: "chatgpt",
52
+ document: await fetch(
53
+ "https://shopping-be.wrtn.ai/editor/swagger.json",
54
+ ).then(r => r.json()),
56
55
  connection: {
57
56
  host: "https://shopping-be.wrtn.ai",
58
57
  headers: { Authorization: "Bearer ********" },
59
58
  },
60
- },
59
+ }),
61
60
  ],
62
61
  });
63
62
  await agent.conversate("I wanna buy MacBook Pro");
@@ -3196,7 +3196,7 @@ Also, if you A.I. agent can't specify a specific function to call due to lack
3196
3196
  of specificity or homogeneity of candidate functions, just assign all of them
3197
3197
  by in the\` functions\` property\` too. Instead, when you A.I. agent can specify
3198
3198
  a specific function to call, the others would be eliminated.`,validate:(()=>{const o=G=>Array.isArray(G.functions)&&G.functions.every(J=>typeof J=="object"&&J!==null&&h(J)),h=G=>typeof G.reason=="string"&&typeof G.name=="string",b=(G,J,U=!0)=>[(Array.isArray(G.functions)||B(U,{path:J+".functions",expected:"Array<___IChatFunctionReference>",value:G.functions}))&&G.functions.map((nt,et)=>(typeof nt=="object"&&nt!==null||B(U,{path:J+".functions["+et+"]",expected:"___IChatFunctionReference",value:nt}))&&k(nt,J+".functions["+et+"]",U)||B(U,{path:J+".functions["+et+"]",expected:"___IChatFunctionReference",value:nt})).every(nt=>nt)||B(U,{path:J+".functions",expected:"Array<___IChatFunctionReference>",value:G.functions})].every(nt=>nt),k=(G,J,U=!0)=>[typeof G.reason=="string"||B(U,{path:J+".reason",expected:"string",value:G.reason}),typeof G.name=="string"||B(U,{path:J+".name",expected:"string",value:G.name})].every(nt=>nt),O=G=>typeof G=="object"&&G!==null&&o(G);let P,B;return G=>{if(O(G)===!1){P=[],B=rP(P),((U,nt,et=!0)=>(typeof U=="object"&&U!==null||B(!0,{path:nt+"",expected:"__IChatFunctionReference.IProps",value:U}))&&b(U,nt+"",!0)||B(!0,{path:nt+"",expected:"__IChatFunctionReference.IProps",value:U}))(G,"$input",!0);const J=P.length===0;return J?{success:J,data:G}:{success:J,errors:P,data:G}}return{success:!0,data:G}}})()}]};async function bDn(o){var P;if(o.operations.divided===void 0)return Tmt(o,o.operations.array,0);const h=o.operations.divided.map(()=>[]),b=[],k=await Promise.all(o.operations.divided.map(async(B,G)=>Tmt({...o,stack:h[G],dispatch:async J=>{b.push(J)}},B,0)));if(h.every(B=>B.length===0))return k[0];if((((P=o.config)==null?void 0:P.eliticism)??rT.ELITICISM)===!0)return Tmt(o,h.flat().map(B=>o.operations.group.get(B.operation.controller.name).get(B.operation.function.name)),0);const O=ubt({id:ejt(),selections:[]});for(const B of b)B.type==="select"&&(O.selections.push(B.selection),await B7e(o,{name:B.selection.operation.name,reason:B.selection.reason}));return[O]}async function Tmt(o,h,b,k){var J,U,nt,et;const O=await o.request("select",{messages:[{role:"system",content:Kj.write(o.config)},{role:"assistant",tool_calls:[{type:"function",id:"getApiFunctions",function:{name:"getApiFunctions",arguments:JSON.stringify({})}}]},{role:"tool",tool_call_id:"getApiFunctions",content:JSON.stringify(h.map(tt=>({name:tt.name,description:tt.function.description,...tt.protocol==="http"?{method:tt.function.method,path:tt.function.path,tags:tt.function.tags}:{}})))},...o.histories.map(qj).flat(),{role:"user",content:o.prompt.contents},{role:"system",content:((nt=(U=(J=o.config)==null?void 0:J.systemPrompt)==null?void 0:U.select)==null?void 0:nt.call(U,o.histories))??nP.SELECT},...yDn(k??[])],tools:mDn.functions.map(tt=>({type:"function",function:{name:tt.name,description:tt.description,parameters:tt.parameters}})),tool_choice:"auto",parallel_tool_calls:!1}),P=await Z8.readAll(O),B=p6.merge(P);if(b++<(((et=o.config)==null?void 0:et.retry)??rT.RETRY)){const tt=[];for(const st of B.choices)for(const it of st.message.tool_calls??[]){if(it.function.name!=="selectFunctions")continue;const At=JSON.parse(it.function.arguments),Dt=(()=>{const Ot=Kn=>Array.isArray(Kn.functions)&&Kn.functions.every(jn=>typeof jn=="object"&&jn!==null&&oe(jn)),oe=Kn=>typeof Kn.reason=="string"&&typeof Kn.name=="string",ie=(Kn,jn,Gn=!0)=>[(Array.isArray(Kn.functions)||Ln(Gn,{path:jn+".functions",expected:"Array<___IChatFunctionReference>",value:Kn.functions}))&&Kn.functions.map((Vn,ur)=>(typeof Vn=="object"&&Vn!==null||Ln(Gn,{path:jn+".functions["+ur+"]",expected:"___IChatFunctionReference",value:Vn}))&&Le(Vn,jn+".functions["+ur+"]",Gn)||Ln(Gn,{path:jn+".functions["+ur+"]",expected:"___IChatFunctionReference",value:Vn})).every(Vn=>Vn)||Ln(Gn,{path:jn+".functions",expected:"Array<___IChatFunctionReference>",value:Kn.functions})].every(Vn=>Vn),Le=(Kn,jn,Gn=!0)=>[typeof Kn.reason=="string"||Ln(Gn,{path:jn+".reason",expected:"string",value:Kn.reason}),typeof Kn.name=="string"||Ln(Gn,{path:jn+".name",expected:"string",value:Kn.name})].every(Vn=>Vn),mn=Kn=>typeof Kn=="object"&&Kn!==null&&Ot(Kn);let ge,Ln;return Kn=>{if(mn(Kn)===!1){ge=[],Ln=rP(ge),((Gn,Vn,ur=!0)=>(typeof Gn=="object"&&Gn!==null||Ln(!0,{path:Vn+"",expected:"__IChatFunctionReference.IProps",value:Gn}))&&ie(Gn,Vn+"",!0)||Ln(!0,{path:Vn+"",expected:"__IChatFunctionReference.IProps",value:Gn}))(Kn,"$input",!0);const jn=ge.length===0;return jn?{success:jn,data:Kn}:{success:jn,errors:ge,data:Kn}}return{success:!0,data:Kn}}})()(At);Dt.success===!1&&tt.push({id:it.id,name:it.function.name,validation:Dt})}if(tt.length>0)return Tmt(o,h,b,tt)}const G=[];for(const tt of B.choices){if(tt.message.tool_calls!=null)for(const st of tt.message.tool_calls){if(st.type!=="function"||st.function.name!=="selectFunctions")continue;const it=(()=>{const Dt=ie=>Array.isArray(ie.functions)&&ie.functions.every(Le=>typeof Le=="object"&&Le!==null&&Ot(Le)),Ot=ie=>typeof ie.reason=="string"&&typeof ie.name=="string",oe=ie=>typeof ie=="object"&&ie!==null&&Dt(ie);return ie=>(ie=JSON.parse(ie),oe(ie)?ie:null)})()(st.function.arguments);if(it===null)continue;const At=ubt({id:st.id,selections:[]});for(const Dt of it.functions){const Ot=await B7e(o,Dt);Ot!==null&&At.selections.push(Wj({operation:Ot,reason:Dt.reason}))}At.selections.length!==0&&G.push(At)}if(tt.message.role==="assistant"&&tt.message.content!=null&&tt.message.content.length!==0){const st=cbt({text:tt.message.content});G.push(st),o.dispatch(njt({stream:M7e(st.text),join:async()=>Promise.resolve(st.text),done:()=>!0,get:()=>st.text})).catch(()=>{})}}return G}function yDn(o){return o.map(h=>[{role:"assistant",tool_calls:[{type:"function",id:h.id,function:{name:h.name,arguments:JSON.stringify(h.validation.data)}}]},{role:"tool",content:JSON.stringify(h.validation.errors),tool_call_id:h.id},{role:"system",content:["You A.I. assistant has composed wrong typed arguments.","","Correct it at the next function calling."].join(`
3199
- `)}]).flat()}function wDn(o){return async h=>{const b=[];if(h.ready()===!1){if((o==null?void 0:o.initialize)!==!0&&typeof(o==null?void 0:o.initialize)!="function")await h.initialize();else if(b.push(...await(typeof(o==null?void 0:o.initialize)=="function"?o.initialize:gDn)(h)),h.ready()===!1)return b}if(h.stack.length!==0&&b.push(...await((o==null?void 0:o.cancel)??lDn)(h)),b.push(...await((o==null?void 0:o.select)??bDn)(h)),h.stack.length===0)return b;for(;;){const k=await((o==null?void 0:o.call)??eDn)(h,h.stack.map(P=>P.operation));b.push(...k);const O=k.filter(P=>P.type==="execute");if((o==null?void 0:o.describe)!==null&&(o==null?void 0:o.describe)!==!1&&b.push(...await(typeof(o==null?void 0:o.describe)=="function"?o.describe:pDn)(h,O)),O.length===0||h.stack.length===0)break}return b}}function vDn(o){if(o.history.type==="text")return j7e({history:o.history});if(o.history.type==="select")return F7e({operations:o.operations,history:o.history});if(o.history.type==="cancel")return $7e({operations:o.operations,history:o.history});if(o.history.type==="execute")return ojt({operations:o.operations,history:o.history});if(o.history.type==="describe")return H7e({operations:o.operations,history:o.history});throw new Error("Invalid prompt type.")}function j7e(o){return cbt(o.history)}function F7e(o){return ubt({id:o.history.id,selections:o.history.selections.map(h=>Wj({operation:sjt({operations:o.operations,input:h.operation}),reason:h.reason}))})}function $7e(o){return lbt({id:o.history.id,selections:o.history.selections.map(h=>Wj({operation:sjt({operations:o.operations,input:h.operation}),reason:h.reason}))})}function ojt(o){return eT({id:o.history.id,operation:sjt({operations:o.operations,input:o.history.operation}),arguments:o.history.arguments,value:o.history.value})}function H7e(o){return S7e({text:o.history.text,executes:o.history.executes.map(h=>ojt({operations:o.operations,history:h}))})}function sjt(o){var b;const h=(b=o.operations.get(o.input.controller))==null?void 0:b.get(o.input.function);if(h===void 0)throw new Error(`No operation found: (controller: ${o.input.controller}, function: ${o.input.function})`);return h}const xDn={transform:vDn,transformText:j7e,transformSelect:F7e,transformCancel:$7e,transformExecute:ojt,transformDescribe:H7e};class z7e{constructor(h){var b,k;this.props=h,this.operations_=gLn.compose({controllers:h.controllers,config:h.config}),this.stack_=[],this.listeners_=new Map,this.histories_=(h.histories??[]).map(O=>xDn.transform({operations:this.operations_.group,history:O})),this.token_usage_=fX.zero(),this.ready_=!1,this.executor_=typeof((b=h.config)==null?void 0:b.executor)=="function"?h.config.executor:wDn(((k=h.config)==null?void 0:k.executor)??null)}clone(){var h;return new z7e({...this.props,histories:(h=this.props.histories)==null?void 0:h.slice()})}async conversate(h){const b=T7e({contents:Array.isArray(h)?h:typeof h=="string"?[{type:"text",text:h}]:[h]});this.dispatch(_Ln({contents:b.contents})).catch(()=>{});const k=await this.executor_(this.getContext({prompt:b,usage:this.token_usage_}));return this.histories_.push(b,...k),[b,...k]}getConfig(){return this.props.config}getVendor(){return this.props.vendor}getControllers(){return this.props.controllers}getOperations(){return this.operations_.array}getHistories(){return this.histories_}getTokenUsage(){return this.token_usage_}getContext(h){const b=async k=>this.dispatch(k);return{operations:this.operations_,config:this.props.config,histories:this.histories_,stack:this.stack_,ready:()=>this.ready_,prompt:h.prompt,dispatch:async k=>this.dispatch(k),request:async(k,O)=>{const P=CLn({source:k,body:{...O,model:this.props.vendor.model,stream:!0,stream_options:{include_usage:!0}},options:this.props.vendor.options});await b(P);const B=await this.props.vendor.api.chat.completions.create(P.body,P.options),[G,J]=Z8.transform(B.toReadableStream(),st=>p6.transformCompletionChunk(st)).tee(),[U,nt]=J.tee();(async()=>{const st=U.getReader();for(;;){const it=await st.read();if(it.done)break;it.value.usage!=null&&bLn.aggregate({kind:k,completionUsage:it.value.usage,usage:h.usage})}})().catch(()=>{});const[et,tt]=G.tee();return await b({type:"response",source:k,stream:hbt(et.getReader()),body:P.body,options:P.options,join:async()=>{const st=await Z8.readAll(tt);return p6.merge(st)}}),nt},initialize:async()=>{this.ready_=!0,await b(kLn())}}}on(h,b){return E7e(this.listeners_,h,()=>new Set).add(b),this}off(h,b){const k=this.listeners_.get(h);return k!==void 0&&(k.delete(b),k.size===0&&this.listeners_.delete(h)),this}async dispatch(h){const b=this.listeners_.get(h.type);b!==void 0&&await Promise.all(Array.from(b).map(async k=>{try{await k(h)}catch{}}))}}const pBt="RFC3986",gBt={RFC1738:o=>String(o).replace(/%20/g,"+"),RFC3986:o=>String(o)},kDn="RFC1738",_Dn=Array.isArray,o6=(()=>{const o=[];for(let h=0;h<256;++h)o.push("%"+((h<16?"0":"")+h.toString(16)).toUpperCase());return o})(),aRt=1024,EDn=(o,h,b,k,O)=>{if(o.length===0)return o;let P=o;if(typeof o=="symbol"?P=Symbol.prototype.toString.call(o):typeof o!="string"&&(P=String(o)),b==="iso-8859-1")return escape(P).replace(/%u[0-9a-f]{4}/gi,function(G){return"%26%23"+parseInt(G.slice(2),16)+"%3B"});let B="";for(let G=0;G<P.length;G+=aRt){const J=P.length>=aRt?P.slice(G,G+aRt):P,U=[];for(let nt=0;nt<J.length;++nt){let et=J.charCodeAt(nt);if(et===45||et===46||et===95||et===126||et>=48&&et<=57||et>=65&&et<=90||et>=97&&et<=122||O===kDn&&(et===40||et===41)){U[U.length]=J.charAt(nt);continue}if(et<128){U[U.length]=o6[et];continue}if(et<2048){U[U.length]=o6[192|et>>6]+o6[128|et&63];continue}if(et<55296||et>=57344){U[U.length]=o6[224|et>>12]+o6[128|et>>6&63]+o6[128|et&63];continue}nt+=1,et=65536+((et&1023)<<10|J.charCodeAt(nt)&1023),U[U.length]=o6[240|et>>18]+o6[128|et>>12&63]+o6[128|et>>6&63]+o6[128|et&63]}B+=U.join("")}return B};function TDn(o){return!o||typeof o!="object"?!1:!!(o.constructor&&o.constructor.isBuffer&&o.constructor.isBuffer(o))}function J8e(o,h){if(_Dn(o)){const b=[];for(let k=0;k<o.length;k+=1)b.push(h(o[k]));return b}return h(o)}const SDn=Object.prototype.hasOwnProperty,U7e={brackets(o){return String(o)+"[]"},comma:"comma",indices(o,h){return String(o)+"["+h+"]"},repeat(o){return String(o)}},c6=Array.isArray,IDn=Array.prototype.push,G7e=function(o,h){IDn.apply(o,c6(h)?h:[h])},CDn=Date.prototype.toISOString,Xp={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:EDn,encodeValuesOnly:!1,format:pBt,formatter:gBt[pBt],indices:!1,serializeDate(o){return CDn.call(o)},skipNulls:!1,strictNullHandling:!1};function ADn(o){return typeof o=="string"||typeof o=="number"||typeof o=="boolean"||typeof o=="symbol"||typeof o=="bigint"}const oRt={};function q7e(o,h,b,k,O,P,B,G,J,U,nt,et,tt,st,it,At,Dt,Ot){let oe=o,ie=Ot,Le=0,mn=!1;for(;(ie=ie.get(oRt))!==void 0&&!mn;){const Gn=ie.get(o);if(Le+=1,typeof Gn<"u"){if(Gn===Le)throw new RangeError("Cyclic object value");mn=!0}typeof ie.get(oRt)>"u"&&(Le=0)}if(typeof U=="function"?oe=U(h,oe):oe instanceof Date?oe=tt==null?void 0:tt(oe):b==="comma"&&c6(oe)&&(oe=J8e(oe,function(Gn){return Gn instanceof Date?tt==null?void 0:tt(Gn):Gn})),oe===null){if(P)return J&&!At?J(h,Xp.encoder,Dt,"key",st):h;oe=""}if(ADn(oe)||TDn(oe)){if(J){const Gn=At?h:J(h,Xp.encoder,Dt,"key",st);return[(it==null?void 0:it(Gn))+"="+(it==null?void 0:it(J(oe,Xp.encoder,Dt,"value",st)))]}return[(it==null?void 0:it(h))+"="+(it==null?void 0:it(String(oe)))]}const ge=[];if(typeof oe>"u")return ge;let Ln;if(b==="comma"&&c6(oe))At&&J&&(oe=J8e(oe,J)),Ln=[{value:oe.length>0?oe.join(",")||null:void 0}];else if(c6(U))Ln=U;else{const Gn=Object.keys(oe);Ln=nt?Gn.sort(nt):Gn}const Kn=G?String(h).replace(/\./g,"%2E"):String(h),jn=k&&c6(oe)&&oe.length===1?Kn+"[]":Kn;if(O&&c6(oe)&&oe.length===0)return jn+"[]";for(let Gn=0;Gn<Ln.length;++Gn){const Vn=Ln[Gn],ur=typeof Vn=="object"&&typeof Vn.value<"u"?Vn.value:oe[Vn];if(B&&ur===null)continue;const ci=et&&G?Vn.replace(/\./g,"%2E"):Vn,$n=c6(oe)?typeof b=="function"?b(jn,ci):jn:jn+(et?"."+ci:"["+ci+"]");Ot.set(o,Le);const Kt=new WeakMap;Kt.set(oRt,Ot),G7e(ge,q7e(ur,$n,b,k,O,P,B,G,b==="comma"&&At&&c6(oe)?null:J,U,nt,et,tt,st,it,At,Dt,Kt))}return ge}function ODn(o=Xp){if(typeof o.allowEmptyArrays<"u"&&typeof o.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof o.encodeDotInKeys<"u"&&typeof o.encodeDotInKeys!="boolean")throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(o.encoder!==null&&typeof o.encoder<"u"&&typeof o.encoder!="function")throw new TypeError("Encoder has to be a function.");const h=o.charset||Xp.charset;if(typeof o.charset<"u"&&o.charset!=="utf-8"&&o.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");let b=pBt;if(typeof o.format<"u"){if(!SDn.call(gBt,o.format))throw new TypeError("Unknown format option provided.");b=o.format}const k=gBt[b];let O=Xp.filter;(typeof o.filter=="function"||c6(o.filter))&&(O=o.filter);let P;if(o.arrayFormat&&o.arrayFormat in U7e?P=o.arrayFormat:"indices"in o?P=o.indices?"indices":"repeat":P=Xp.arrayFormat,"commaRoundTrip"in o&&typeof o.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");const B=typeof o.allowDots>"u"?o.encodeDotInKeys?!0:Xp.allowDots:!!o.allowDots;return{addQueryPrefix:typeof o.addQueryPrefix=="boolean"?o.addQueryPrefix:Xp.addQueryPrefix,allowDots:B,allowEmptyArrays:typeof o.allowEmptyArrays=="boolean"?!!o.allowEmptyArrays:Xp.allowEmptyArrays,arrayFormat:P,charset:h,charsetSentinel:typeof o.charsetSentinel=="boolean"?o.charsetSentinel:Xp.charsetSentinel,commaRoundTrip:!!o.commaRoundTrip,delimiter:typeof o.delimiter>"u"?Xp.delimiter:o.delimiter,encode:typeof o.encode=="boolean"?o.encode:Xp.encode,encodeDotInKeys:typeof o.encodeDotInKeys=="boolean"?o.encodeDotInKeys:Xp.encodeDotInKeys,encoder:typeof o.encoder=="function"?o.encoder:Xp.encoder,encodeValuesOnly:typeof o.encodeValuesOnly=="boolean"?o.encodeValuesOnly:Xp.encodeValuesOnly,filter:O,format:b,formatter:k,serializeDate:typeof o.serializeDate=="function"?o.serializeDate:Xp.serializeDate,skipNulls:typeof o.skipNulls=="boolean"?o.skipNulls:Xp.skipNulls,sort:typeof o.sort=="function"?o.sort:null,strictNullHandling:typeof o.strictNullHandling=="boolean"?o.strictNullHandling:Xp.strictNullHandling}}function NDn(o,h={}){let b=o;const k=ODn(h);let O,P;typeof k.filter=="function"?(P=k.filter,b=P("",b)):c6(k.filter)&&(P=k.filter,O=P);const B=[];if(typeof b!="object"||b===null)return"";const G=U7e[k.arrayFormat],J=G==="comma"&&k.commaRoundTrip;O||(O=Object.keys(b)),k.sort&&O.sort(k.sort);const U=new WeakMap;for(let tt=0;tt<O.length;++tt){const st=O[tt];k.skipNulls&&b[st]===null||G7e(B,q7e(b[st],st,G,J,k.allowEmptyArrays,k.strictNullHandling,k.skipNulls,k.encodeDotInKeys,k.encode?k.encoder:null,k.filter,k.sort,k.allowDots,k.serializeDate,k.format,k.formatter,k.encodeValuesOnly,k.charset,U))}const nt=B.join(k.delimiter);let et=k.addQueryPrefix===!0?"?":"";return k.charsetSentinel&&(k.charset==="iso-8859-1"?et+="utf8=%26%2310003%3B&":et+="utf8=%E2%9C%93&"),nt.length>0?et+nt:""}const kj="4.91.1";let X8e=!1,dX,W7e,K7e,mBt,Y7e,V7e,J7e,X7e,Q7e;function PDn(o,h={auto:!1}){if(X8e)throw new Error(`you must \`import 'openai/shims/${o.kind}'\` before importing anything else from openai`);if(dX)throw new Error(`can't \`import 'openai/shims/${o.kind}'\` after \`import 'openai/shims/${dX}'\``);X8e=h.auto,dX=o.kind,W7e=o.fetch,K7e=o.FormData,mBt=o.File,Y7e=o.ReadableStream,V7e=o.getMultipartRequestOptions,J7e=o.getDefaultAgent,X7e=o.fileFromPath,Q7e=o.isFsReadStream}class LDn{constructor(h){this.body=h}get[Symbol.toStringTag](){return"MultipartBody"}}function MDn({manuallyImported:o}={}){const h=o?"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 b,k,O,P;try{b=fetch,k=Request,O=Response,P=Headers}catch(B){throw new Error(`this environment is missing the following Web Fetch API type: ${B.message}. ${h}`)}return{kind:"web",fetch:b,Request:k,Response:O,Headers:P,FormData:typeof FormData<"u"?FormData:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'FormData' is undefined. ${h}`)}},Blob:typeof Blob<"u"?Blob:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'Blob' is undefined. ${h}`)}},File:typeof File<"u"?File:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'File' is undefined. ${h}`)}},ReadableStream:typeof ReadableStream<"u"?ReadableStream:class{constructor(){throw new Error(`streaming isn't supported in this environment yet as 'ReadableStream' is undefined. ${h}`)}},getMultipartRequestOptions:async(B,G)=>({...G,body:new LDn(B)}),getDefaultAgent:B=>{},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:B=>!1}}const Z7e=()=>{dX||PDn(MDn(),{auto:!0})};Z7e();class As extends Error{}class Ig extends As{constructor(h,b,k,O){super(`${Ig.makeMessage(h,b,k)}`),this.status=h,this.headers=O,this.request_id=O==null?void 0:O["x-request-id"],this.error=b;const P=b;this.code=P==null?void 0:P.code,this.param=P==null?void 0:P.param,this.type=P==null?void 0:P.type}static makeMessage(h,b,k){const O=b!=null&&b.message?typeof b.message=="string"?b.message:JSON.stringify(b.message):b?JSON.stringify(b):k;return h&&O?`${h} ${O}`:h?`${h} status code (no body)`:O||"(no status code or body)"}static generate(h,b,k,O){if(!h||!O)return new fbt({message:k,cause:yBt(b)});const P=b==null?void 0:b.error;return h===400?new t9e(h,P,k,O):h===401?new e9e(h,P,k,O):h===403?new n9e(h,P,k,O):h===404?new r9e(h,P,k,O):h===409?new i9e(h,P,k,O):h===422?new a9e(h,P,k,O):h===429?new o9e(h,P,k,O):h>=500?new s9e(h,P,k,O):new Ig(h,P,k,O)}}class x3 extends Ig{constructor({message:h}={}){super(void 0,void 0,h||"Request was aborted.",void 0)}}class fbt extends Ig{constructor({message:h,cause:b}){super(void 0,void 0,h||"Connection error.",void 0),b&&(this.cause=b)}}class cjt extends fbt{constructor({message:h}={}){super({message:h??"Request timed out."})}}class t9e extends Ig{}class e9e extends Ig{}class n9e extends Ig{}class r9e extends Ig{}class i9e extends Ig{}class a9e extends Ig{}class o9e extends Ig{}class s9e extends Ig{}class c9e extends As{constructor(){super("Could not parse response content as the length limit was reached")}}class u9e extends As{constructor(){super("Could not parse response content as the request was rejected by the content filter")}}var cmt=function(o,h,b,k,O){if(k==="m")throw new TypeError("Private method is not writable");if(k==="a"&&!O)throw new TypeError("Private accessor was defined without a setter");if(typeof h=="function"?o!==h||!O:!h.has(o))throw new TypeError("Cannot write private member to an object whose class did not declare it");return k==="a"?O.call(o,b):O?O.value=b:h.set(o,b),b},jN=function(o,h,b,k){if(b==="a"&&!k)throw new TypeError("Private accessor was defined without a getter");if(typeof h=="function"?o!==h||!k:!h.has(o))throw new TypeError("Cannot read private member from an object whose class did not declare it");return b==="m"?k:b==="a"?k.call(o):k?k.value:h.get(o)},gw;class dbt{constructor(){gw.set(this,void 0),this.buffer=new Uint8Array,cmt(this,gw,null,"f")}decode(h){if(h==null)return[];const b=h instanceof ArrayBuffer?new Uint8Array(h):typeof h=="string"?new TextEncoder().encode(h):h;let k=new Uint8Array(this.buffer.length+b.length);k.set(this.buffer),k.set(b,this.buffer.length),this.buffer=k;const O=[];let P;for(;(P=DDn(this.buffer,jN(this,gw,"f")))!=null;){if(P.carriage&&jN(this,gw,"f")==null){cmt(this,gw,P.index,"f");continue}if(jN(this,gw,"f")!=null&&(P.index!==jN(this,gw,"f")+1||P.carriage)){O.push(this.decodeText(this.buffer.slice(0,jN(this,gw,"f")-1))),this.buffer=this.buffer.slice(jN(this,gw,"f")),cmt(this,gw,null,"f");continue}const B=jN(this,gw,"f")!==null?P.preceding-1:P.preceding,G=this.decodeText(this.buffer.slice(0,B));O.push(G),this.buffer=this.buffer.slice(P.index),cmt(this,gw,null,"f")}return O}decodeText(h){if(h==null)return"";if(typeof h=="string")return h;if(typeof Buffer<"u"){if(h instanceof Buffer)return h.toString();if(h instanceof Uint8Array)return Buffer.from(h).toString();throw new As(`Unexpected: received non-Uint8Array (${h.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(h instanceof Uint8Array||h instanceof ArrayBuffer)return this.textDecoder??(this.textDecoder=new TextDecoder("utf8")),this.textDecoder.decode(h);throw new As(`Unexpected: received non-Uint8Array/ArrayBuffer (${h.constructor.name}) in a web platform. Please report this error.`)}throw new As("Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.")}flush(){return this.buffer.length?this.decode(`
3199
+ `)}]).flat()}function wDn(o){return async h=>{const b=[];if(h.ready()===!1){if((o==null?void 0:o.initialize)!==!0&&typeof(o==null?void 0:o.initialize)!="function")await h.initialize();else if(b.push(...await(typeof(o==null?void 0:o.initialize)=="function"?o.initialize:gDn)(h)),h.ready()===!1)return b}if(h.stack.length!==0&&b.push(...await((o==null?void 0:o.cancel)??lDn)(h)),b.push(...await((o==null?void 0:o.select)??bDn)(h)),h.stack.length===0)return b;for(;;){const k=await((o==null?void 0:o.call)??eDn)(h,h.stack.map(P=>P.operation));b.push(...k);const O=k.filter(P=>P.type==="execute");if((o==null?void 0:o.describe)!==null&&(o==null?void 0:o.describe)!==!1&&b.push(...await(typeof(o==null?void 0:o.describe)=="function"?o.describe:pDn)(h,O)),O.length===0||h.stack.length===0)break}return b}}function vDn(o){if(o.history.type==="text")return j7e({history:o.history});if(o.history.type==="select")return F7e({operations:o.operations,history:o.history});if(o.history.type==="cancel")return $7e({operations:o.operations,history:o.history});if(o.history.type==="execute")return ojt({operations:o.operations,history:o.history});if(o.history.type==="describe")return H7e({operations:o.operations,history:o.history});throw new Error("Invalid prompt type.")}function j7e(o){return cbt(o.history)}function F7e(o){return ubt({id:o.history.id,selections:o.history.selections.map(h=>Wj({operation:sjt({operations:o.operations,input:h.operation}),reason:h.reason}))})}function $7e(o){return lbt({id:o.history.id,selections:o.history.selections.map(h=>Wj({operation:sjt({operations:o.operations,input:h.operation}),reason:h.reason}))})}function ojt(o){return eT({id:o.history.id,operation:sjt({operations:o.operations,input:o.history.operation}),arguments:o.history.arguments,value:o.history.value})}function H7e(o){return S7e({text:o.history.text,executes:o.history.executes.map(h=>ojt({operations:o.operations,history:h}))})}function sjt(o){var b;const h=(b=o.operations.get(o.input.controller))==null?void 0:b.get(o.input.function);if(h===void 0)throw new Error(`No operation found: (controller: ${o.input.controller}, function: ${o.input.function})`);return h}const xDn={transform:vDn,transformText:j7e,transformSelect:F7e,transformCancel:$7e,transformExecute:ojt,transformDescribe:H7e};class z7e{constructor(h){var b,k;this.props=h,this.operations_=gLn.compose({controllers:h.controllers,config:h.config}),this.stack_=[],this.listeners_=new Map,this.histories_=(h.histories??[]).map(O=>xDn.transform({operations:this.operations_.group,history:O})),this.token_usage_=fX.zero(),this.ready_=!1,this.executor_=typeof((b=h.config)==null?void 0:b.executor)=="function"?h.config.executor:wDn(((k=h.config)==null?void 0:k.executor)??null)}clone(){var h;return new z7e({...this.props,histories:(h=this.props.histories)==null?void 0:h.slice()})}async conversate(h,b={}){const k=T7e({contents:Array.isArray(h)?h:typeof h=="string"?[{type:"text",text:h}]:[h]});this.dispatch(_Ln({contents:k.contents})).catch(()=>{});const O=await this.executor_(this.getContext({prompt:k,abortSignal:b.abortSignal,usage:this.token_usage_}));return this.histories_.push(k,...O),[k,...O]}getConfig(){return this.props.config}getVendor(){return this.props.vendor}getControllers(){return this.props.controllers}getOperations(){return this.operations_.array}getHistories(){return this.histories_}getTokenUsage(){return this.token_usage_}getContext(h){const b=async k=>this.dispatch(k);return{operations:this.operations_,config:this.props.config,histories:this.histories_,stack:this.stack_,ready:()=>this.ready_,prompt:h.prompt,abortSignal:h.abortSignal,dispatch:async k=>this.dispatch(k),request:async(k,O)=>{const P=CLn({source:k,body:{...O,model:this.props.vendor.model,stream:!0,stream_options:{include_usage:!0}},options:{...this.props.vendor.options,signal:h.abortSignal}});await b(P);const B=await this.props.vendor.api.chat.completions.create(P.body,P.options),[G,J]=Z8.transform(B.toReadableStream(),st=>p6.transformCompletionChunk(st)).tee(),[U,nt]=J.tee();(async()=>{const st=U.getReader();for(;;){const it=await st.read();if(it.done)break;it.value.usage!=null&&bLn.aggregate({kind:k,completionUsage:it.value.usage,usage:h.usage})}})().catch(()=>{});const[et,tt]=G.tee();return await b({type:"response",source:k,stream:hbt(et.getReader()),body:P.body,options:P.options,join:async()=>{const st=await Z8.readAll(tt);return p6.merge(st)}}),nt},initialize:async()=>{this.ready_=!0,await b(kLn())}}}on(h,b){return E7e(this.listeners_,h,()=>new Set).add(b),this}off(h,b){const k=this.listeners_.get(h);return k!==void 0&&(k.delete(b),k.size===0&&this.listeners_.delete(h)),this}async dispatch(h){const b=this.listeners_.get(h.type);b!==void 0&&await Promise.all(Array.from(b).map(async k=>{try{await k(h)}catch{}}))}}const pBt="RFC3986",gBt={RFC1738:o=>String(o).replace(/%20/g,"+"),RFC3986:o=>String(o)},kDn="RFC1738",_Dn=Array.isArray,o6=(()=>{const o=[];for(let h=0;h<256;++h)o.push("%"+((h<16?"0":"")+h.toString(16)).toUpperCase());return o})(),aRt=1024,EDn=(o,h,b,k,O)=>{if(o.length===0)return o;let P=o;if(typeof o=="symbol"?P=Symbol.prototype.toString.call(o):typeof o!="string"&&(P=String(o)),b==="iso-8859-1")return escape(P).replace(/%u[0-9a-f]{4}/gi,function(G){return"%26%23"+parseInt(G.slice(2),16)+"%3B"});let B="";for(let G=0;G<P.length;G+=aRt){const J=P.length>=aRt?P.slice(G,G+aRt):P,U=[];for(let nt=0;nt<J.length;++nt){let et=J.charCodeAt(nt);if(et===45||et===46||et===95||et===126||et>=48&&et<=57||et>=65&&et<=90||et>=97&&et<=122||O===kDn&&(et===40||et===41)){U[U.length]=J.charAt(nt);continue}if(et<128){U[U.length]=o6[et];continue}if(et<2048){U[U.length]=o6[192|et>>6]+o6[128|et&63];continue}if(et<55296||et>=57344){U[U.length]=o6[224|et>>12]+o6[128|et>>6&63]+o6[128|et&63];continue}nt+=1,et=65536+((et&1023)<<10|J.charCodeAt(nt)&1023),U[U.length]=o6[240|et>>18]+o6[128|et>>12&63]+o6[128|et>>6&63]+o6[128|et&63]}B+=U.join("")}return B};function TDn(o){return!o||typeof o!="object"?!1:!!(o.constructor&&o.constructor.isBuffer&&o.constructor.isBuffer(o))}function J8e(o,h){if(_Dn(o)){const b=[];for(let k=0;k<o.length;k+=1)b.push(h(o[k]));return b}return h(o)}const SDn=Object.prototype.hasOwnProperty,U7e={brackets(o){return String(o)+"[]"},comma:"comma",indices(o,h){return String(o)+"["+h+"]"},repeat(o){return String(o)}},c6=Array.isArray,IDn=Array.prototype.push,G7e=function(o,h){IDn.apply(o,c6(h)?h:[h])},CDn=Date.prototype.toISOString,Xp={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:EDn,encodeValuesOnly:!1,format:pBt,formatter:gBt[pBt],indices:!1,serializeDate(o){return CDn.call(o)},skipNulls:!1,strictNullHandling:!1};function ADn(o){return typeof o=="string"||typeof o=="number"||typeof o=="boolean"||typeof o=="symbol"||typeof o=="bigint"}const oRt={};function q7e(o,h,b,k,O,P,B,G,J,U,nt,et,tt,st,it,At,Dt,Ot){let oe=o,ie=Ot,Le=0,mn=!1;for(;(ie=ie.get(oRt))!==void 0&&!mn;){const Gn=ie.get(o);if(Le+=1,typeof Gn<"u"){if(Gn===Le)throw new RangeError("Cyclic object value");mn=!0}typeof ie.get(oRt)>"u"&&(Le=0)}if(typeof U=="function"?oe=U(h,oe):oe instanceof Date?oe=tt==null?void 0:tt(oe):b==="comma"&&c6(oe)&&(oe=J8e(oe,function(Gn){return Gn instanceof Date?tt==null?void 0:tt(Gn):Gn})),oe===null){if(P)return J&&!At?J(h,Xp.encoder,Dt,"key",st):h;oe=""}if(ADn(oe)||TDn(oe)){if(J){const Gn=At?h:J(h,Xp.encoder,Dt,"key",st);return[(it==null?void 0:it(Gn))+"="+(it==null?void 0:it(J(oe,Xp.encoder,Dt,"value",st)))]}return[(it==null?void 0:it(h))+"="+(it==null?void 0:it(String(oe)))]}const ge=[];if(typeof oe>"u")return ge;let Ln;if(b==="comma"&&c6(oe))At&&J&&(oe=J8e(oe,J)),Ln=[{value:oe.length>0?oe.join(",")||null:void 0}];else if(c6(U))Ln=U;else{const Gn=Object.keys(oe);Ln=nt?Gn.sort(nt):Gn}const Kn=G?String(h).replace(/\./g,"%2E"):String(h),jn=k&&c6(oe)&&oe.length===1?Kn+"[]":Kn;if(O&&c6(oe)&&oe.length===0)return jn+"[]";for(let Gn=0;Gn<Ln.length;++Gn){const Vn=Ln[Gn],ur=typeof Vn=="object"&&typeof Vn.value<"u"?Vn.value:oe[Vn];if(B&&ur===null)continue;const ci=et&&G?Vn.replace(/\./g,"%2E"):Vn,$n=c6(oe)?typeof b=="function"?b(jn,ci):jn:jn+(et?"."+ci:"["+ci+"]");Ot.set(o,Le);const Kt=new WeakMap;Kt.set(oRt,Ot),G7e(ge,q7e(ur,$n,b,k,O,P,B,G,b==="comma"&&At&&c6(oe)?null:J,U,nt,et,tt,st,it,At,Dt,Kt))}return ge}function ODn(o=Xp){if(typeof o.allowEmptyArrays<"u"&&typeof o.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof o.encodeDotInKeys<"u"&&typeof o.encodeDotInKeys!="boolean")throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(o.encoder!==null&&typeof o.encoder<"u"&&typeof o.encoder!="function")throw new TypeError("Encoder has to be a function.");const h=o.charset||Xp.charset;if(typeof o.charset<"u"&&o.charset!=="utf-8"&&o.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");let b=pBt;if(typeof o.format<"u"){if(!SDn.call(gBt,o.format))throw new TypeError("Unknown format option provided.");b=o.format}const k=gBt[b];let O=Xp.filter;(typeof o.filter=="function"||c6(o.filter))&&(O=o.filter);let P;if(o.arrayFormat&&o.arrayFormat in U7e?P=o.arrayFormat:"indices"in o?P=o.indices?"indices":"repeat":P=Xp.arrayFormat,"commaRoundTrip"in o&&typeof o.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");const B=typeof o.allowDots>"u"?o.encodeDotInKeys?!0:Xp.allowDots:!!o.allowDots;return{addQueryPrefix:typeof o.addQueryPrefix=="boolean"?o.addQueryPrefix:Xp.addQueryPrefix,allowDots:B,allowEmptyArrays:typeof o.allowEmptyArrays=="boolean"?!!o.allowEmptyArrays:Xp.allowEmptyArrays,arrayFormat:P,charset:h,charsetSentinel:typeof o.charsetSentinel=="boolean"?o.charsetSentinel:Xp.charsetSentinel,commaRoundTrip:!!o.commaRoundTrip,delimiter:typeof o.delimiter>"u"?Xp.delimiter:o.delimiter,encode:typeof o.encode=="boolean"?o.encode:Xp.encode,encodeDotInKeys:typeof o.encodeDotInKeys=="boolean"?o.encodeDotInKeys:Xp.encodeDotInKeys,encoder:typeof o.encoder=="function"?o.encoder:Xp.encoder,encodeValuesOnly:typeof o.encodeValuesOnly=="boolean"?o.encodeValuesOnly:Xp.encodeValuesOnly,filter:O,format:b,formatter:k,serializeDate:typeof o.serializeDate=="function"?o.serializeDate:Xp.serializeDate,skipNulls:typeof o.skipNulls=="boolean"?o.skipNulls:Xp.skipNulls,sort:typeof o.sort=="function"?o.sort:null,strictNullHandling:typeof o.strictNullHandling=="boolean"?o.strictNullHandling:Xp.strictNullHandling}}function NDn(o,h={}){let b=o;const k=ODn(h);let O,P;typeof k.filter=="function"?(P=k.filter,b=P("",b)):c6(k.filter)&&(P=k.filter,O=P);const B=[];if(typeof b!="object"||b===null)return"";const G=U7e[k.arrayFormat],J=G==="comma"&&k.commaRoundTrip;O||(O=Object.keys(b)),k.sort&&O.sort(k.sort);const U=new WeakMap;for(let tt=0;tt<O.length;++tt){const st=O[tt];k.skipNulls&&b[st]===null||G7e(B,q7e(b[st],st,G,J,k.allowEmptyArrays,k.strictNullHandling,k.skipNulls,k.encodeDotInKeys,k.encode?k.encoder:null,k.filter,k.sort,k.allowDots,k.serializeDate,k.format,k.formatter,k.encodeValuesOnly,k.charset,U))}const nt=B.join(k.delimiter);let et=k.addQueryPrefix===!0?"?":"";return k.charsetSentinel&&(k.charset==="iso-8859-1"?et+="utf8=%26%2310003%3B&":et+="utf8=%E2%9C%93&"),nt.length>0?et+nt:""}const kj="4.91.1";let X8e=!1,dX,W7e,K7e,mBt,Y7e,V7e,J7e,X7e,Q7e;function PDn(o,h={auto:!1}){if(X8e)throw new Error(`you must \`import 'openai/shims/${o.kind}'\` before importing anything else from openai`);if(dX)throw new Error(`can't \`import 'openai/shims/${o.kind}'\` after \`import 'openai/shims/${dX}'\``);X8e=h.auto,dX=o.kind,W7e=o.fetch,K7e=o.FormData,mBt=o.File,Y7e=o.ReadableStream,V7e=o.getMultipartRequestOptions,J7e=o.getDefaultAgent,X7e=o.fileFromPath,Q7e=o.isFsReadStream}class LDn{constructor(h){this.body=h}get[Symbol.toStringTag](){return"MultipartBody"}}function MDn({manuallyImported:o}={}){const h=o?"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 b,k,O,P;try{b=fetch,k=Request,O=Response,P=Headers}catch(B){throw new Error(`this environment is missing the following Web Fetch API type: ${B.message}. ${h}`)}return{kind:"web",fetch:b,Request:k,Response:O,Headers:P,FormData:typeof FormData<"u"?FormData:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'FormData' is undefined. ${h}`)}},Blob:typeof Blob<"u"?Blob:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'Blob' is undefined. ${h}`)}},File:typeof File<"u"?File:class{constructor(){throw new Error(`file uploads aren't supported in this environment yet as 'File' is undefined. ${h}`)}},ReadableStream:typeof ReadableStream<"u"?ReadableStream:class{constructor(){throw new Error(`streaming isn't supported in this environment yet as 'ReadableStream' is undefined. ${h}`)}},getMultipartRequestOptions:async(B,G)=>({...G,body:new LDn(B)}),getDefaultAgent:B=>{},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:B=>!1}}const Z7e=()=>{dX||PDn(MDn(),{auto:!0})};Z7e();class As extends Error{}class Ig extends As{constructor(h,b,k,O){super(`${Ig.makeMessage(h,b,k)}`),this.status=h,this.headers=O,this.request_id=O==null?void 0:O["x-request-id"],this.error=b;const P=b;this.code=P==null?void 0:P.code,this.param=P==null?void 0:P.param,this.type=P==null?void 0:P.type}static makeMessage(h,b,k){const O=b!=null&&b.message?typeof b.message=="string"?b.message:JSON.stringify(b.message):b?JSON.stringify(b):k;return h&&O?`${h} ${O}`:h?`${h} status code (no body)`:O||"(no status code or body)"}static generate(h,b,k,O){if(!h||!O)return new fbt({message:k,cause:yBt(b)});const P=b==null?void 0:b.error;return h===400?new t9e(h,P,k,O):h===401?new e9e(h,P,k,O):h===403?new n9e(h,P,k,O):h===404?new r9e(h,P,k,O):h===409?new i9e(h,P,k,O):h===422?new a9e(h,P,k,O):h===429?new o9e(h,P,k,O):h>=500?new s9e(h,P,k,O):new Ig(h,P,k,O)}}class x3 extends Ig{constructor({message:h}={}){super(void 0,void 0,h||"Request was aborted.",void 0)}}class fbt extends Ig{constructor({message:h,cause:b}){super(void 0,void 0,h||"Connection error.",void 0),b&&(this.cause=b)}}class cjt extends fbt{constructor({message:h}={}){super({message:h??"Request timed out."})}}class t9e extends Ig{}class e9e extends Ig{}class n9e extends Ig{}class r9e extends Ig{}class i9e extends Ig{}class a9e extends Ig{}class o9e extends Ig{}class s9e extends Ig{}class c9e extends As{constructor(){super("Could not parse response content as the length limit was reached")}}class u9e extends As{constructor(){super("Could not parse response content as the request was rejected by the content filter")}}var cmt=function(o,h,b,k,O){if(k==="m")throw new TypeError("Private method is not writable");if(k==="a"&&!O)throw new TypeError("Private accessor was defined without a setter");if(typeof h=="function"?o!==h||!O:!h.has(o))throw new TypeError("Cannot write private member to an object whose class did not declare it");return k==="a"?O.call(o,b):O?O.value=b:h.set(o,b),b},jN=function(o,h,b,k){if(b==="a"&&!k)throw new TypeError("Private accessor was defined without a getter");if(typeof h=="function"?o!==h||!k:!h.has(o))throw new TypeError("Cannot read private member from an object whose class did not declare it");return b==="m"?k:b==="a"?k.call(o):k?k.value:h.get(o)},gw;class dbt{constructor(){gw.set(this,void 0),this.buffer=new Uint8Array,cmt(this,gw,null,"f")}decode(h){if(h==null)return[];const b=h instanceof ArrayBuffer?new Uint8Array(h):typeof h=="string"?new TextEncoder().encode(h):h;let k=new Uint8Array(this.buffer.length+b.length);k.set(this.buffer),k.set(b,this.buffer.length),this.buffer=k;const O=[];let P;for(;(P=DDn(this.buffer,jN(this,gw,"f")))!=null;){if(P.carriage&&jN(this,gw,"f")==null){cmt(this,gw,P.index,"f");continue}if(jN(this,gw,"f")!=null&&(P.index!==jN(this,gw,"f")+1||P.carriage)){O.push(this.decodeText(this.buffer.slice(0,jN(this,gw,"f")-1))),this.buffer=this.buffer.slice(jN(this,gw,"f")),cmt(this,gw,null,"f");continue}const B=jN(this,gw,"f")!==null?P.preceding-1:P.preceding,G=this.decodeText(this.buffer.slice(0,B));O.push(G),this.buffer=this.buffer.slice(P.index),cmt(this,gw,null,"f")}return O}decodeText(h){if(h==null)return"";if(typeof h=="string")return h;if(typeof Buffer<"u"){if(h instanceof Buffer)return h.toString();if(h instanceof Uint8Array)return Buffer.from(h).toString();throw new As(`Unexpected: received non-Uint8Array (${h.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(h instanceof Uint8Array||h instanceof ArrayBuffer)return this.textDecoder??(this.textDecoder=new TextDecoder("utf8")),this.textDecoder.decode(h);throw new As(`Unexpected: received non-Uint8Array/ArrayBuffer (${h.constructor.name}) in a web platform. Please report this error.`)}throw new As("Unexpected: neither Buffer nor TextDecoder are available as globals. Please report this error.")}flush(){return this.buffer.length?this.decode(`
3200
3200
  `):[]}}gw=new WeakMap;dbt.NEWLINE_CHARS=new Set([`
3201
3201
  `,"\r"]);dbt.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function DDn(o,h){for(let O=h??0;O<o.length;O++){if(o[O]===10)return{preceding:O,index:O+1,carriage:!1};if(o[O]===13)return{preceding:O,index:O+1,carriage:!0}}return null}function RDn(o){for(let k=0;k<o.length-1;k++){if(o[k]===10&&o[k+1]===10||o[k]===13&&o[k+1]===13)return k+2;if(o[k]===13&&o[k+1]===10&&k+3<o.length&&o[k+2]===13&&o[k+3]===10)return k+4}return-1}function l9e(o){if(o[Symbol.asyncIterator])return o;const h=o.getReader();return{async next(){try{const b=await h.read();return b!=null&&b.done&&h.releaseLock(),b}catch(b){throw h.releaseLock(),b}},async return(){const b=h.cancel();return h.releaseLock(),await b,{done:!0,value:void 0}},[Symbol.asyncIterator](){return this}}}class f6{constructor(h,b){this.iterator=h,this.controller=b}static fromSSEResponse(h,b){let k=!1;async function*O(){if(k)throw new Error("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");k=!0;let P=!1;try{for await(const B of BDn(h,b))if(!P){if(B.data.startsWith("[DONE]")){P=!0;continue}if(B.event===null||B.event.startsWith("response.")||B.event.startsWith("transcript.")){let G;try{G=JSON.parse(B.data)}catch(J){throw console.error("Could not parse message into JSON:",B.data),console.error("From chunk:",B.raw),J}if(G&&G.error)throw new Ig(void 0,G.error,void 0,b9e(h.headers));yield G}else{let G;try{G=JSON.parse(B.data)}catch(J){throw console.error("Could not parse message into JSON:",B.data),console.error("From chunk:",B.raw),J}if(B.event=="error")throw new Ig(void 0,G.error,G.message,void 0);yield{event:B.event,data:G}}}P=!0}catch(B){if(B instanceof Error&&B.name==="AbortError")return;throw B}finally{P||b.abort()}}return new f6(O,b)}static fromReadableStream(h,b){let k=!1;async function*O(){const B=new dbt,G=l9e(h);for await(const J of G)for(const U of B.decode(J))yield U;for(const J of B.flush())yield J}async function*P(){if(k)throw new Error("Cannot iterate over a consumed stream, use `.tee()` to split the stream.");k=!0;let B=!1;try{for await(const G of O())B||G&&(yield JSON.parse(G));B=!0}catch(G){if(G instanceof Error&&G.name==="AbortError")return;throw G}finally{B||b.abort()}}return new f6(P,b)}[Symbol.asyncIterator](){return this.iterator()}tee(){const h=[],b=[],k=this.iterator(),O=P=>({next:()=>{if(P.length===0){const B=k.next();h.push(B),b.push(B)}return P.shift()}});return[new f6(()=>O(h),this.controller),new f6(()=>O(b),this.controller)]}toReadableStream(){const h=this;let b;const k=new TextEncoder;return new Y7e({async start(){b=h[Symbol.asyncIterator]()},async pull(O){try{const{value:P,done:B}=await b.next();if(B)return O.close();const G=k.encode(JSON.stringify(P)+`
3202
3202
  `);O.enqueue(G)}catch(P){O.error(P)}},async cancel(){var O;await((O=b.return)==null?void 0:O.call(b))}})}}async function*BDn(o,h){if(!o.body)throw h.abort(),new As("Attempted to iterate over a response with no body");const b=new FDn,k=new dbt,O=l9e(o.body);for await(const P of jDn(O))for(const B of k.decode(P)){const G=b.decode(B);G&&(yield G)}for(const P of k.flush()){const B=b.decode(P);B&&(yield B)}}async function*jDn(o){let h=new Uint8Array;for await(const b of o){if(b==null)continue;const k=b instanceof ArrayBuffer?new Uint8Array(b):typeof b=="string"?new TextEncoder().encode(b):b;let O=new Uint8Array(h.length+k.length);O.set(h),O.set(k,h.length),h=O;let P;for(;(P=RDn(h))!==-1;)yield h.slice(0,P),h=h.slice(P)}h.length>0&&(yield h)}class FDn{constructor(){this.event=null,this.data=[],this.chunks=[]}decode(h){if(h.endsWith("\r")&&(h=h.substring(0,h.length-1)),!h){if(!this.event&&!this.data.length)return null;const P={event:this.event,data:this.data.join(`
@@ -1,4 +1,4 @@
1
- import{j as y,o as v,r as f,T as b}from"../client-B3aq8qpT.js";import{v as I,A as B,d as T,_ as m,V as g,c as C,F as A,T as j,B as w}from"../VendorConfigurationMovie-Cfbgmegt.js";import{a as u,_ as p}from"../_isFormatUri-YqTfGpHo.js";import{D as x}from"../Divider-DX1xhf0M.js";class R{constructor(){this.articles=[]}index(){return this.articles}create(c){const d={id:I(),title:c.input.title,body:c.input.body,thumbnail:c.input.thumbnail,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return this.articles.push(d),d}update(c){const d=this.articles.find(s=>s.id===c.id);if(d===void 0)throw new Error("Unable to find the matched article.");c.input.title!==void 0&&(d.title=c.input.title),c.input.body!==void 0&&(d.body=c.input.body),c.input.thumbnail!==void 0&&(d.thumbnail=c.input.thumbnail),d.updated_at=new Date().toISOString()}erase(c){const d=this.articles.findIndex(s=>s.id===c.id);if(d===-1)throw new Error("Unable to find the matched article.");this.articles.splice(d,1)}}const U={chatgpt:{model:"chatgpt",options:{reference:!1,strict:!1,separate:null},functions:[{name:"index",parameters:{type:"object",properties:{},additionalProperties:!1,required:[],$defs:{}},output:{description:"List of every articles",type:"array",items:{description:`Description of the current {@link IBbsArticle} type:
1
+ import{j as y,o as v,r as f,T as b}from"../client-B3aq8qpT.js";import{v as I,A as B,d as T,_ as m,V as g,c as C,F as A,T as j,B as w}from"../VendorConfigurationMovie-DxkJlPnf.js";import{a as u,_ as p}from"../_isFormatUri-YqTfGpHo.js";import{D as x}from"../Divider-DX1xhf0M.js";class R{constructor(){this.articles=[]}index(){return this.articles}create(c){const d={id:I(),title:c.input.title,body:c.input.body,thumbnail:c.input.thumbnail,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return this.articles.push(d),d}update(c){const d=this.articles.find(s=>s.id===c.id);if(d===void 0)throw new Error("Unable to find the matched article.");c.input.title!==void 0&&(d.title=c.input.title),c.input.body!==void 0&&(d.body=c.input.body),c.input.thumbnail!==void 0&&(d.thumbnail=c.input.thumbnail),d.updated_at=new Date().toISOString()}erase(c){const d=this.articles.findIndex(s=>s.id===c.id);if(d===-1)throw new Error("Unable to find the matched article.");this.articles.splice(d,1)}}const U={chatgpt:{model:"chatgpt",options:{reference:!1,strict:!1,separate:null},functions:[{name:"index",parameters:{type:"object",properties:{},additionalProperties:!1,required:[],$defs:{}},output:{description:"List of every articles",type:"array",items:{description:`Description of the current {@link IBbsArticle} type:
2
2
 
3
3
  > Article entity.
4
4
  >