@agentica/chat 0.12.9 → 0.12.12
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/{AgenticaChatApplication-UHEs9ToN.js → AgenticaChatApplication-BbUZT3m4.js} +1 -1
- package/dist/assets/bbs/{index-DmHdvBBg.js → index-BI4BtPBi.js} +1 -1
- package/dist/assets/shopping/{index.html-BZhwbAoG.js → index.html-DpixCA0B.js} +1 -1
- package/dist/assets/uploader/{index.html-CS-qsvNk.js → index.html-DUd1F-Ro.js} +1 -1
- package/dist/bbs/index.html +2 -2
- package/dist/shopping/index.html +2 -2
- package/dist/uploader/index.html +2 -2
- package/package.json +2 -2
package/dist/assets/{AgenticaChatApplication-UHEs9ToN.js → AgenticaChatApplication-BbUZT3m4.js}
RENAMED
|
@@ -2448,7 +2448,7 @@ them all into the \`functions\` property.
|
|
|
2448
2448
|
Also, if you A.I. agent can't specify a specific function to call due to lack
|
|
2449
2449
|
of specificity or homogeneity of candidate functions, just assign all of them
|
|
2450
2450
|
by in the\` functions\` property\` too. Instead, when you A.I. agent can specify
|
|
2451
|
-
a specific function to call, the others would be eliminated.`}]};var dBt;(o=>{o.execute=h=>async b=>{const k=[];if(b.ready()===!1){if((h==null?void 0:h.initialize)===null)await b.initialize();else if(k.push(...await((h==null?void 0:h.initialize)??hBt.execute)(b)),b.ready()===!1)return k}if(b.stack.length!==0&&k.push(...await((h==null?void 0:h.cancel)??SX.execute)(b)),k.push(...await((h==null?void 0:h.select)??fBt.execute)(b)),b.stack.length===0)return k;for(;;){const O=await((h==null?void 0:h.call)??uBt.execute)(b);k.push(...O);const N=O.filter(B=>B.type==="execute");for(const B of N)await SX.cancelFunction(b,{reason:"completed",name:B.operation.name});if(k.push(...await((h==null?void 0:h.describe)??lBt.execute)(b,N)),N.length===0||b.stack.length===0)break}return k}})(dBt||(dBt={}));var pBt;(o=>{o.aggregate=h=>{var N,B,q,Z,U;if(!h.completionUsage)return;const b=h.usage[h.kind];b.total+=h.completionUsage.total_tokens,b.input.total+=h.completionUsage.prompt_tokens,b.input.total+=((N=h.completionUsage.prompt_tokens_details)==null?void 0:N.audio_tokens)??0,b.input.cached+=((B=h.completionUsage.prompt_tokens_details)==null?void 0:B.cached_tokens)??0,b.output.total+=h.completionUsage.completion_tokens,b.output.accepted_prediction+=((q=h.completionUsage.completion_tokens_details)==null?void 0:q.accepted_prediction_tokens)??0,b.output.reasoning+=((Z=h.completionUsage.completion_tokens_details)==null?void 0:Z.reasoning_tokens)??0,b.output.rejected_prediction+=((U=h.completionUsage.completion_tokens_details)==null?void 0:U.rejected_prediction_tokens)??0;const k=tt=>Object.entries(h.usage).filter(([at])=>at!=="aggregate").map(([,at])=>tt(at)).reduce((at,rt)=>at+rt,0),O=h.usage.aggregate;O.total=k(tt=>tt.total),O.input.total=k(tt=>tt.input.total),O.input.cached=k(tt=>tt.input.cached),O.output.total=k(tt=>tt.output.total),O.output.reasoning=k(tt=>tt.output.reasoning),O.output.accepted_prediction=k(tt=>tt.output.accepted_prediction),O.output.rejected_prediction=k(tt=>tt.output.rejected_prediction)}})(pBt||(pBt={}));class IMn extends tC{constructor(){super("initialize")}toJSON(){return{type:"initialize"}}}const O7e=(o,h,b)=>{const k=o.get(h);if(k)return k;const O=b();return o.set(h,O),O};var gBt;(o=>{o.compose=b=>{var U;const k=b.controllers.length===1||(()=>{const tt=b.controllers.map(at=>at.application.functions.map(rt=>rt.name)).flat();return new Set(tt).size===tt.length})(),O=(tt,at)=>k?tt:`_${at}_${tt}`,N=b.controllers.map((tt,at)=>tt.protocol==="http"?tt.application.functions.map(rt=>({protocol:"http",controller:tt,function:rt,name:O(rt.name,at),toJSON:()=>({protocol:"http",controller:tt.name,function:rt.name,name:O(rt.name,at)})})):tt.application.functions.map(rt=>({protocol:"class",controller:tt,function:rt,name:O(rt.name,at),toJSON:()=>({protocol:"class",controller:tt.name,function:rt.name,name:O(rt.name,at)})}))).flat(),B=(U=b.config)!=null&&U.capacity&&N.length>b.config.capacity?h({array:N,capacity:b.config.capacity}):void 0,q=new Map,Z=new Map;for(const tt of N)q.set(tt.name,tt),O7e(Z,tt.controller.name,()=>new Map).set(tt.name,tt);return{array:N,divided:B,flat:q,group:Z}};const h=b=>{const k=Math.ceil(b.array.length/b.capacity),O=Math.ceil(b.array.length/k),N=b.array.slice();return new Array(k).fill(0).map(()=>N.splice(0,O))}})(gBt||(gBt={}));var mBt;(o=>{o.transform=h=>{if(h.prompt.type==="text")return(0,o.transformText)({prompt:h.prompt});if(h.prompt.type==="select")return(0,o.transformSelect)({operations:h.operations,prompt:h.prompt});if(h.prompt.type==="cancel")return(0,o.transformCancel)({operations:h.operations,prompt:h.prompt});if(h.prompt.type==="execute")return(0,o.transformExecute)({operations:h.operations,prompt:h.prompt});if(h.prompt.type==="describe")return(0,o.transformDescribe)({operations:h.operations,prompt:h.prompt});throw new Error("Invalid prompt type.")},o.transformText=h=>new qj(h.prompt),o.transformSelect=h=>new Dmt({id:h.prompt.id,selections:h.prompt.selections.map(b=>new VP({operation:QDt({operations:h.operations,input:b.operation}),reason:b.reason}))}),o.transformCancel=h=>new JNn({id:h.prompt.id,selections:h.prompt.selections.map(b=>new VP({operation:QDt({operations:h.operations,input:b.operation}),reason:b.reason}))}),o.transformExecute=h=>new HP({id:h.prompt.id,operation:QDt({operations:h.operations,input:h.prompt.operation}),arguments:h.prompt.arguments,value:h.prompt.value}),o.transformDescribe=h=>new ojt({text:h.prompt.text,executes:h.prompt.executes.map(b=>(0,o.transformExecute)({operations:h.operations,prompt:b}))})})(mBt||(mBt={}));const QDt=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};class P7e{constructor(h){var b,k;this.props=h,this.operations_=gBt.compose({controllers:h.controllers,config:h.config}),this.stack_=[],this.listeners_=new Map,this.prompt_histories_=(h.histories??[]).map(O=>mBt.transform({operations:this.operations_.group,prompt:O})),this.token_usage_=lX.zero(),this.ready_=!1,this.executor_=typeof((b=h.config)==null?void 0:b.executor)=="function"?h.config.executor:dBt.execute(((k=h.config)==null?void 0:k.executor)??null)}clone(){var h;return new P7e({...this.props,histories:(h=this.props.histories)==null?void 0:h.slice()})}async conversate(h){const b=new qj({role:"user",text:h});await this.dispatch(new abt({role:"user",stream:kw.to(h),done:()=>!0,get:()=>h,join:()=>Promise.resolve(h)}));const k=await this.executor_(this.getContext({prompt:b,usage:this.token_usage_}));return this.prompt_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}getPromptHistories(){return this.prompt_histories_}getTokenUsage(){return this.token_usage_}getContext(h){const b=k=>this.dispatch(k);return{operations:this.operations_,config:this.props.config,histories:this.prompt_histories_,stack:this.stack_,ready:()=>this.ready_,prompt:h.prompt,dispatch:k=>this.dispatch(k),request:async(k,O)=>{const N=new ZNn({source:k,body:{...O,model:this.props.vendor.model,stream:!0,stream_options:{include_usage:!0}},options:this.props.vendor.options});await b(N);const B=await this.props.vendor.api.chat.completions.create(N.body,N.options),[q,Z]=kw.transform(B.toReadableStream(),at=>E3.transformCompletionChunk(at)).tee(),[U,tt]=Z.tee();return(async()=>{const at=U.getReader();for(;;){const rt=await at.read();if(rt.done)break;rt.value.usage&&pBt.aggregate({kind:k,completionUsage:rt.value.usage,usage:h.usage})}})(),await b({type:"response",source:k,stream:q,body:N.body,options:N.options,join:async()=>{const at=await kw.readAll(q);return E3.merge(at)}}),tt},initialize:async()=>{this.ready_=!0,await b(new IMn)}}}on(h,b){return O7e(this.listeners_,h,()=>new Set).add(b),this}off(h,b){const k=this.listeners_.get(h);return k&&(k.delete(b),k.size===0&&this.listeners_.delete(h)),this}async dispatch(h){const b=this.listeners_.get(h.type);b&&await Promise.all(Array.from(b).map(async k=>{try{await k(h)}catch{}}))}}const bBt="RFC3986",yBt={RFC1738:o=>String(o).replace(/%20/g,"+"),RFC3986:o=>String(o)},CMn="RFC1738",AMn=Array.isArray,u6=(()=>{const o=[];for(let h=0;h<256;++h)o.push("%"+((h<16?"0":"")+h.toString(16)).toUpperCase());return o})(),ZDt=1024,OMn=(o,h,b,k,O)=>{if(o.length===0)return o;let N=o;if(typeof o=="symbol"?N=Symbol.prototype.toString.call(o):typeof o!="string"&&(N=String(o)),b==="iso-8859-1")return escape(N).replace(/%u[0-9a-f]{4}/gi,function(q){return"%26%23"+parseInt(q.slice(2),16)+"%3B"});let B="";for(let q=0;q<N.length;q+=ZDt){const Z=N.length>=ZDt?N.slice(q,q+ZDt):N,U=[];for(let tt=0;tt<Z.length;++tt){let at=Z.charCodeAt(tt);if(at===45||at===46||at===95||at===126||at>=48&&at<=57||at>=65&&at<=90||at>=97&&at<=122||O===CMn&&(at===40||at===41)){U[U.length]=Z.charAt(tt);continue}if(at<128){U[U.length]=u6[at];continue}if(at<2048){U[U.length]=u6[192|at>>6]+u6[128|at&63];continue}if(at<55296||at>=57344){U[U.length]=u6[224|at>>12]+u6[128|at>>6&63]+u6[128|at&63];continue}tt+=1,at=65536+((at&1023)<<10|Z.charCodeAt(tt)&1023),U[U.length]=u6[240|at>>18]+u6[128|at>>12&63]+u6[128|at>>6&63]+u6[128|at&63]}B+=U.join("")}return B};function PMn(o){return!o||typeof o!="object"?!1:!!(o.constructor&&o.constructor.isBuffer&&o.constructor.isBuffer(o))}function eCe(o,h){if(AMn(o)){const b=[];for(let k=0;k<o.length;k+=1)b.push(h(o[k]));return b}return h(o)}const NMn=Object.prototype.hasOwnProperty,N7e={brackets(o){return String(o)+"[]"},comma:"comma",indices(o,h){return String(o)+"["+h+"]"},repeat(o){return String(o)}},h6=Array.isArray,LMn=Array.prototype.push,L7e=function(o,h){LMn.apply(o,h6(h)?h:[h])},MMn=Date.prototype.toISOString,Jp={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:OMn,encodeValuesOnly:!1,format:bBt,formatter:yBt[bBt],indices:!1,serializeDate(o){return MMn.call(o)},skipNulls:!1,strictNullHandling:!1};function DMn(o){return typeof o=="string"||typeof o=="number"||typeof o=="boolean"||typeof o=="symbol"||typeof o=="bigint"}const tRt={};function M7e(o,h,b,k,O,N,B,q,Z,U,tt,at,rt,st,et,kt,Lt,Dt){let ie=o,Kt=Dt,ge=0,cn=!1;for(;(Kt=Kt.get(tRt))!==void 0&&!cn;){const yr=Kt.get(o);if(ge+=1,typeof yr<"u"){if(yr===ge)throw new RangeError("Cyclic object value");cn=!0}typeof Kt.get(tRt)>"u"&&(ge=0)}if(typeof U=="function"?ie=U(h,ie):ie instanceof Date?ie=rt==null?void 0:rt(ie):b==="comma"&&h6(ie)&&(ie=eCe(ie,function(yr){return yr instanceof Date?rt==null?void 0:rt(yr):yr})),ie===null){if(N)return Z&&!kt?Z(h,Jp.encoder,Lt,"key",st):h;ie=""}if(DMn(ie)||PMn(ie)){if(Z){const yr=kt?h:Z(h,Jp.encoder,Lt,"key",st);return[(et==null?void 0:et(yr))+"="+(et==null?void 0:et(Z(ie,Jp.encoder,Lt,"value",st)))]}return[(et==null?void 0:et(h))+"="+(et==null?void 0:et(String(ie)))]}const he=[];if(typeof ie>"u")return he;let qn;if(b==="comma"&&h6(ie))kt&&Z&&(ie=eCe(ie,Z)),qn=[{value:ie.length>0?ie.join(",")||null:void 0}];else if(h6(U))qn=U;else{const yr=Object.keys(ie);qn=tt?yr.sort(tt):yr}const jr=q?String(h).replace(/\./g,"%2E"):String(h),Lr=k&&h6(ie)&&ie.length===1?jr+"[]":jr;if(O&&h6(ie)&&ie.length===0)return Lr+"[]";for(let yr=0;yr<qn.length;++yr){const wn=qn[yr],je=typeof wn=="object"&&typeof wn.value<"u"?wn.value:ie[wn];if(B&&je===null)continue;const lr=at&&q?wn.replace(/\./g,"%2E"):wn,Yt=h6(ie)?typeof b=="function"?b(Lr,lr):Lr:Lr+(at?"."+lr:"["+lr+"]");Dt.set(o,ge);const Oe=new WeakMap;Oe.set(tRt,Dt),L7e(he,M7e(je,Yt,b,k,O,N,B,q,b==="comma"&&kt&&h6(ie)?null:Z,U,tt,at,rt,st,et,kt,Lt,Oe))}return he}function RMn(o=Jp){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||Jp.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=bBt;if(typeof o.format<"u"){if(!NMn.call(yBt,o.format))throw new TypeError("Unknown format option provided.");b=o.format}const k=yBt[b];let O=Jp.filter;(typeof o.filter=="function"||h6(o.filter))&&(O=o.filter);let N;if(o.arrayFormat&&o.arrayFormat in N7e?N=o.arrayFormat:"indices"in o?N=o.indices?"indices":"repeat":N=Jp.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:Jp.allowDots:!!o.allowDots;return{addQueryPrefix:typeof o.addQueryPrefix=="boolean"?o.addQueryPrefix:Jp.addQueryPrefix,allowDots:B,allowEmptyArrays:typeof o.allowEmptyArrays=="boolean"?!!o.allowEmptyArrays:Jp.allowEmptyArrays,arrayFormat:N,charset:h,charsetSentinel:typeof o.charsetSentinel=="boolean"?o.charsetSentinel:Jp.charsetSentinel,commaRoundTrip:!!o.commaRoundTrip,delimiter:typeof o.delimiter>"u"?Jp.delimiter:o.delimiter,encode:typeof o.encode=="boolean"?o.encode:Jp.encode,encodeDotInKeys:typeof o.encodeDotInKeys=="boolean"?o.encodeDotInKeys:Jp.encodeDotInKeys,encoder:typeof o.encoder=="function"?o.encoder:Jp.encoder,encodeValuesOnly:typeof o.encodeValuesOnly=="boolean"?o.encodeValuesOnly:Jp.encodeValuesOnly,filter:O,format:b,formatter:k,serializeDate:typeof o.serializeDate=="function"?o.serializeDate:Jp.serializeDate,skipNulls:typeof o.skipNulls=="boolean"?o.skipNulls:Jp.skipNulls,sort:typeof o.sort=="function"?o.sort:null,strictNullHandling:typeof o.strictNullHandling=="boolean"?o.strictNullHandling:Jp.strictNullHandling}}function BMn(o,h={}){let b=o;const k=RMn(h);let O,N;typeof k.filter=="function"?(N=k.filter,b=N("",b)):h6(k.filter)&&(N=k.filter,O=N);const B=[];if(typeof b!="object"||b===null)return"";const q=N7e[k.arrayFormat],Z=q==="comma"&&k.commaRoundTrip;O||(O=Object.keys(b)),k.sort&&O.sort(k.sort);const U=new WeakMap;for(let rt=0;rt<O.length;++rt){const st=O[rt];k.skipNulls&&b[st]===null||L7e(B,M7e(b[st],st,q,Z,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 tt=B.join(k.delimiter);let at=k.addQueryPrefix===!0?"?":"";return k.charsetSentinel&&(k.charset==="iso-8859-1"?at+="utf8=%26%2310003%3B&":at+="utf8=%E2%9C%93&"),tt.length>0?at+tt:""}const xj="4.87.4";let nCe=!1,hX,D7e,R7e,wBt,B7e,j7e,F7e,$7e,H7e;function jMn(o,h={auto:!1}){if(nCe)throw new Error(`you must \`import 'openai/shims/${o.kind}'\` before importing anything else from openai`);if(hX)throw new Error(`can't \`import 'openai/shims/${o.kind}'\` after \`import 'openai/shims/${hX}'\``);nCe=h.auto,hX=o.kind,D7e=o.fetch,R7e=o.FormData,wBt=o.File,B7e=o.ReadableStream,j7e=o.getMultipartRequestOptions,F7e=o.getDefaultAgent,$7e=o.fileFromPath,H7e=o.isFsReadStream}class FMn{constructor(h){this.body=h}get[Symbol.toStringTag](){return"MultipartBody"}}function $Mn({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,N;try{b=fetch,k=Request,O=Response,N=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:N,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,q)=>({...q,body:new FMn(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}}hX||jMn($Mn(),{auto:!0});class As extends Error{}class Cg extends As{constructor(h,b,k,O){super(`${Cg.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 N=b;this.code=N==null?void 0:N.code,this.param=N==null?void 0:N.param,this.type=N==null?void 0:N.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 obt({message:k,cause:xBt(b)});const N=b==null?void 0:b.error;return h===400?new z7e(h,N,k,O):h===401?new U7e(h,N,k,O):h===403?new G7e(h,N,k,O):h===404?new q7e(h,N,k,O):h===409?new W7e(h,N,k,O):h===422?new K7e(h,N,k,O):h===429?new Y7e(h,N,k,O):h>=500?new V7e(h,N,k,O):new Cg(h,N,k,O)}}class k3 extends Cg{constructor({message:h}={}){super(void 0,void 0,h||"Request was aborted.",void 0)}}class obt extends Cg{constructor({message:h,cause:b}){super(void 0,void 0,h||"Connection error.",void 0),b&&(this.cause=b)}}class fjt extends obt{constructor({message:h}={}){super({message:h??"Request timed out."})}}class z7e extends Cg{}class U7e extends Cg{}class G7e extends Cg{}class q7e extends Cg{}class W7e extends Cg{}class K7e extends Cg{}class Y7e extends Cg{}class V7e extends Cg{}class J7e extends As{constructor(){super("Could not parse response content as the length limit was reached")}}class X7e 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},jP=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)},mw;class sbt{constructor(){mw.set(this,void 0),this.buffer=new Uint8Array,cmt(this,mw,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 N;for(;(N=HMn(this.buffer,jP(this,mw,"f")))!=null;){if(N.carriage&&jP(this,mw,"f")==null){cmt(this,mw,N.index,"f");continue}if(jP(this,mw,"f")!=null&&(N.index!==jP(this,mw,"f")+1||N.carriage)){O.push(this.decodeText(this.buffer.slice(0,jP(this,mw,"f")-1))),this.buffer=this.buffer.slice(jP(this,mw,"f")),cmt(this,mw,null,"f");continue}const B=jP(this,mw,"f")!==null?N.preceding-1:N.preceding,q=this.decodeText(this.buffer.slice(0,B));O.push(q),this.buffer=this.buffer.slice(N.index),cmt(this,mw,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(`
|
|
2451
|
+
a specific function to call, the others would be eliminated.`}]};var dBt;(o=>{o.execute=h=>async b=>{const k=[];if(b.ready()===!1){if((h==null?void 0:h.initialize)===null)await b.initialize();else if(k.push(...await((h==null?void 0:h.initialize)??hBt.execute)(b)),b.ready()===!1)return k}if(b.stack.length!==0&&k.push(...await((h==null?void 0:h.cancel)??SX.execute)(b)),k.push(...await((h==null?void 0:h.select)??fBt.execute)(b)),b.stack.length===0)return k;for(;;){const O=await((h==null?void 0:h.call)??uBt.execute)(b);k.push(...O);const N=O.filter(B=>B.type==="execute");for(const B of N)await SX.cancelFunction(b,{reason:"completed",name:B.operation.name});if(k.push(...await((h==null?void 0:h.describe)??lBt.execute)(b,N)),N.length===0||b.stack.length===0)break}return k}})(dBt||(dBt={}));var pBt;(o=>{o.aggregate=h=>{var N,B,q,Z,U;if(!h.completionUsage)return;const b=h.usage[h.kind];b.total+=h.completionUsage.total_tokens,b.input.total+=h.completionUsage.prompt_tokens,b.input.total+=((N=h.completionUsage.prompt_tokens_details)==null?void 0:N.audio_tokens)??0,b.input.cached+=((B=h.completionUsage.prompt_tokens_details)==null?void 0:B.cached_tokens)??0,b.output.total+=h.completionUsage.completion_tokens,b.output.accepted_prediction+=((q=h.completionUsage.completion_tokens_details)==null?void 0:q.accepted_prediction_tokens)??0,b.output.reasoning+=((Z=h.completionUsage.completion_tokens_details)==null?void 0:Z.reasoning_tokens)??0,b.output.rejected_prediction+=((U=h.completionUsage.completion_tokens_details)==null?void 0:U.rejected_prediction_tokens)??0;const k=tt=>Object.entries(h.usage).filter(([at])=>at!=="aggregate").map(([,at])=>tt(at)).reduce((at,rt)=>at+rt,0),O=h.usage.aggregate;O.total=k(tt=>tt.total),O.input.total=k(tt=>tt.input.total),O.input.cached=k(tt=>tt.input.cached),O.output.total=k(tt=>tt.output.total),O.output.reasoning=k(tt=>tt.output.reasoning),O.output.accepted_prediction=k(tt=>tt.output.accepted_prediction),O.output.rejected_prediction=k(tt=>tt.output.rejected_prediction)}})(pBt||(pBt={}));class IMn extends tC{constructor(){super("initialize")}toJSON(){return{type:"initialize"}}}const O7e=(o,h,b)=>{const k=o.get(h);if(k)return k;const O=b();return o.set(h,O),O};var gBt;(o=>{o.compose=b=>{var U;const k=b.controllers.length===1||(()=>{const tt=b.controllers.map(at=>at.application.functions.map(rt=>rt.name)).flat();return new Set(tt).size===tt.length})(),O=(tt,at)=>k?tt:`_${at}_${tt}`,N=b.controllers.map((tt,at)=>tt.protocol==="http"?tt.application.functions.map(rt=>({protocol:"http",controller:tt,function:rt,name:O(rt.name,at),toJSON:()=>({protocol:"http",controller:tt.name,function:rt.name,name:O(rt.name,at)})})):tt.application.functions.map(rt=>({protocol:"class",controller:tt,function:rt,name:O(rt.name,at),toJSON:()=>({protocol:"class",controller:tt.name,function:rt.name,name:O(rt.name,at)})}))).flat(),B=(U=b.config)!=null&&U.capacity&&N.length>b.config.capacity?h({array:N,capacity:b.config.capacity}):void 0,q=new Map,Z=new Map;for(const tt of N)q.set(tt.name,tt),O7e(Z,tt.controller.name,()=>new Map).set(tt.name,tt);return{array:N,divided:B,flat:q,group:Z}};const h=b=>{const k=Math.ceil(b.array.length/b.capacity),O=Math.ceil(b.array.length/k),N=b.array.slice();return new Array(k).fill(0).map(()=>N.splice(0,O))}})(gBt||(gBt={}));var mBt;(o=>{o.transform=h=>{if(h.prompt.type==="text")return(0,o.transformText)({prompt:h.prompt});if(h.prompt.type==="select")return(0,o.transformSelect)({operations:h.operations,prompt:h.prompt});if(h.prompt.type==="cancel")return(0,o.transformCancel)({operations:h.operations,prompt:h.prompt});if(h.prompt.type==="execute")return(0,o.transformExecute)({operations:h.operations,prompt:h.prompt});if(h.prompt.type==="describe")return(0,o.transformDescribe)({operations:h.operations,prompt:h.prompt});throw new Error("Invalid prompt type.")},o.transformText=h=>new qj(h.prompt),o.transformSelect=h=>new Dmt({id:h.prompt.id,selections:h.prompt.selections.map(b=>new VP({operation:QDt({operations:h.operations,input:b.operation}),reason:b.reason}))}),o.transformCancel=h=>new JNn({id:h.prompt.id,selections:h.prompt.selections.map(b=>new VP({operation:QDt({operations:h.operations,input:b.operation}),reason:b.reason}))}),o.transformExecute=h=>new HP({id:h.prompt.id,operation:QDt({operations:h.operations,input:h.prompt.operation}),arguments:h.prompt.arguments,value:h.prompt.value}),o.transformDescribe=h=>new ojt({text:h.prompt.text,executes:h.prompt.executes.map(b=>(0,o.transformExecute)({operations:h.operations,prompt:b}))})})(mBt||(mBt={}));const QDt=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};class P7e{constructor(h){var b,k;this.props=h,this.operations_=gBt.compose({controllers:h.controllers,config:h.config}),this.stack_=[],this.listeners_=new Map,this.prompt_histories_=(h.histories??[]).map(O=>mBt.transform({operations:this.operations_.group,prompt:O})),this.token_usage_=lX.zero(),this.ready_=!1,this.executor_=typeof((b=h.config)==null?void 0:b.executor)=="function"?h.config.executor:dBt.execute(((k=h.config)==null?void 0:k.executor)??null)}clone(){var h;return new P7e({...this.props,histories:(h=this.props.histories)==null?void 0:h.slice()})}async conversate(h){const b=new qj({role:"user",text:h});await this.dispatch(new abt({role:"user",stream:kw.to(h),done:()=>!0,get:()=>h,join:()=>Promise.resolve(h)}));const k=await this.executor_(this.getContext({prompt:b,usage:this.token_usage_}));return this.prompt_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}getPromptHistories(){return this.prompt_histories_}getTokenUsage(){return this.token_usage_}getContext(h){const b=k=>this.dispatch(k);return{operations:this.operations_,config:this.props.config,histories:this.prompt_histories_,stack:this.stack_,ready:()=>this.ready_,prompt:h.prompt,dispatch:k=>this.dispatch(k),request:async(k,O)=>{const N=new ZNn({source:k,body:{...O,model:this.props.vendor.model,stream:!0,stream_options:{include_usage:!0}},options:this.props.vendor.options});await b(N);const B=await this.props.vendor.api.chat.completions.create(N.body,N.options),[q,Z]=kw.transform(B.toReadableStream(),at=>E3.transformCompletionChunk(at)).tee(),[U,tt]=Z.tee();return(async()=>{const at=U.getReader();for(;;){const rt=await at.read();if(rt.done)break;rt.value.usage&&pBt.aggregate({kind:k,completionUsage:rt.value.usage,usage:h.usage})}})(),await b({type:"response",source:k,stream:q,body:N.body,options:N.options,join:async()=>{const at=await kw.readAll(q);return E3.merge(at)}}),tt},initialize:async()=>{this.ready_=!0,await b(new IMn)}}}on(h,b){return O7e(this.listeners_,h,()=>new Set).add(b),this}off(h,b){const k=this.listeners_.get(h);return k&&(k.delete(b),k.size===0&&this.listeners_.delete(h)),this}async dispatch(h){const b=this.listeners_.get(h.type);b&&await Promise.all(Array.from(b).map(async k=>{try{await k(h)}catch{}}))}}const bBt="RFC3986",yBt={RFC1738:o=>String(o).replace(/%20/g,"+"),RFC3986:o=>String(o)},CMn="RFC1738",AMn=Array.isArray,u6=(()=>{const o=[];for(let h=0;h<256;++h)o.push("%"+((h<16?"0":"")+h.toString(16)).toUpperCase());return o})(),ZDt=1024,OMn=(o,h,b,k,O)=>{if(o.length===0)return o;let N=o;if(typeof o=="symbol"?N=Symbol.prototype.toString.call(o):typeof o!="string"&&(N=String(o)),b==="iso-8859-1")return escape(N).replace(/%u[0-9a-f]{4}/gi,function(q){return"%26%23"+parseInt(q.slice(2),16)+"%3B"});let B="";for(let q=0;q<N.length;q+=ZDt){const Z=N.length>=ZDt?N.slice(q,q+ZDt):N,U=[];for(let tt=0;tt<Z.length;++tt){let at=Z.charCodeAt(tt);if(at===45||at===46||at===95||at===126||at>=48&&at<=57||at>=65&&at<=90||at>=97&&at<=122||O===CMn&&(at===40||at===41)){U[U.length]=Z.charAt(tt);continue}if(at<128){U[U.length]=u6[at];continue}if(at<2048){U[U.length]=u6[192|at>>6]+u6[128|at&63];continue}if(at<55296||at>=57344){U[U.length]=u6[224|at>>12]+u6[128|at>>6&63]+u6[128|at&63];continue}tt+=1,at=65536+((at&1023)<<10|Z.charCodeAt(tt)&1023),U[U.length]=u6[240|at>>18]+u6[128|at>>12&63]+u6[128|at>>6&63]+u6[128|at&63]}B+=U.join("")}return B};function PMn(o){return!o||typeof o!="object"?!1:!!(o.constructor&&o.constructor.isBuffer&&o.constructor.isBuffer(o))}function eCe(o,h){if(AMn(o)){const b=[];for(let k=0;k<o.length;k+=1)b.push(h(o[k]));return b}return h(o)}const NMn=Object.prototype.hasOwnProperty,N7e={brackets(o){return String(o)+"[]"},comma:"comma",indices(o,h){return String(o)+"["+h+"]"},repeat(o){return String(o)}},h6=Array.isArray,LMn=Array.prototype.push,L7e=function(o,h){LMn.apply(o,h6(h)?h:[h])},MMn=Date.prototype.toISOString,Jp={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:OMn,encodeValuesOnly:!1,format:bBt,formatter:yBt[bBt],indices:!1,serializeDate(o){return MMn.call(o)},skipNulls:!1,strictNullHandling:!1};function DMn(o){return typeof o=="string"||typeof o=="number"||typeof o=="boolean"||typeof o=="symbol"||typeof o=="bigint"}const tRt={};function M7e(o,h,b,k,O,N,B,q,Z,U,tt,at,rt,st,et,kt,Lt,Dt){let ie=o,Kt=Dt,ge=0,cn=!1;for(;(Kt=Kt.get(tRt))!==void 0&&!cn;){const yr=Kt.get(o);if(ge+=1,typeof yr<"u"){if(yr===ge)throw new RangeError("Cyclic object value");cn=!0}typeof Kt.get(tRt)>"u"&&(ge=0)}if(typeof U=="function"?ie=U(h,ie):ie instanceof Date?ie=rt==null?void 0:rt(ie):b==="comma"&&h6(ie)&&(ie=eCe(ie,function(yr){return yr instanceof Date?rt==null?void 0:rt(yr):yr})),ie===null){if(N)return Z&&!kt?Z(h,Jp.encoder,Lt,"key",st):h;ie=""}if(DMn(ie)||PMn(ie)){if(Z){const yr=kt?h:Z(h,Jp.encoder,Lt,"key",st);return[(et==null?void 0:et(yr))+"="+(et==null?void 0:et(Z(ie,Jp.encoder,Lt,"value",st)))]}return[(et==null?void 0:et(h))+"="+(et==null?void 0:et(String(ie)))]}const he=[];if(typeof ie>"u")return he;let qn;if(b==="comma"&&h6(ie))kt&&Z&&(ie=eCe(ie,Z)),qn=[{value:ie.length>0?ie.join(",")||null:void 0}];else if(h6(U))qn=U;else{const yr=Object.keys(ie);qn=tt?yr.sort(tt):yr}const jr=q?String(h).replace(/\./g,"%2E"):String(h),Lr=k&&h6(ie)&&ie.length===1?jr+"[]":jr;if(O&&h6(ie)&&ie.length===0)return Lr+"[]";for(let yr=0;yr<qn.length;++yr){const wn=qn[yr],je=typeof wn=="object"&&typeof wn.value<"u"?wn.value:ie[wn];if(B&&je===null)continue;const lr=at&&q?wn.replace(/\./g,"%2E"):wn,Yt=h6(ie)?typeof b=="function"?b(Lr,lr):Lr:Lr+(at?"."+lr:"["+lr+"]");Dt.set(o,ge);const Oe=new WeakMap;Oe.set(tRt,Dt),L7e(he,M7e(je,Yt,b,k,O,N,B,q,b==="comma"&&kt&&h6(ie)?null:Z,U,tt,at,rt,st,et,kt,Lt,Oe))}return he}function RMn(o=Jp){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||Jp.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=bBt;if(typeof o.format<"u"){if(!NMn.call(yBt,o.format))throw new TypeError("Unknown format option provided.");b=o.format}const k=yBt[b];let O=Jp.filter;(typeof o.filter=="function"||h6(o.filter))&&(O=o.filter);let N;if(o.arrayFormat&&o.arrayFormat in N7e?N=o.arrayFormat:"indices"in o?N=o.indices?"indices":"repeat":N=Jp.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:Jp.allowDots:!!o.allowDots;return{addQueryPrefix:typeof o.addQueryPrefix=="boolean"?o.addQueryPrefix:Jp.addQueryPrefix,allowDots:B,allowEmptyArrays:typeof o.allowEmptyArrays=="boolean"?!!o.allowEmptyArrays:Jp.allowEmptyArrays,arrayFormat:N,charset:h,charsetSentinel:typeof o.charsetSentinel=="boolean"?o.charsetSentinel:Jp.charsetSentinel,commaRoundTrip:!!o.commaRoundTrip,delimiter:typeof o.delimiter>"u"?Jp.delimiter:o.delimiter,encode:typeof o.encode=="boolean"?o.encode:Jp.encode,encodeDotInKeys:typeof o.encodeDotInKeys=="boolean"?o.encodeDotInKeys:Jp.encodeDotInKeys,encoder:typeof o.encoder=="function"?o.encoder:Jp.encoder,encodeValuesOnly:typeof o.encodeValuesOnly=="boolean"?o.encodeValuesOnly:Jp.encodeValuesOnly,filter:O,format:b,formatter:k,serializeDate:typeof o.serializeDate=="function"?o.serializeDate:Jp.serializeDate,skipNulls:typeof o.skipNulls=="boolean"?o.skipNulls:Jp.skipNulls,sort:typeof o.sort=="function"?o.sort:null,strictNullHandling:typeof o.strictNullHandling=="boolean"?o.strictNullHandling:Jp.strictNullHandling}}function BMn(o,h={}){let b=o;const k=RMn(h);let O,N;typeof k.filter=="function"?(N=k.filter,b=N("",b)):h6(k.filter)&&(N=k.filter,O=N);const B=[];if(typeof b!="object"||b===null)return"";const q=N7e[k.arrayFormat],Z=q==="comma"&&k.commaRoundTrip;O||(O=Object.keys(b)),k.sort&&O.sort(k.sort);const U=new WeakMap;for(let rt=0;rt<O.length;++rt){const st=O[rt];k.skipNulls&&b[st]===null||L7e(B,M7e(b[st],st,q,Z,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 tt=B.join(k.delimiter);let at=k.addQueryPrefix===!0?"?":"";return k.charsetSentinel&&(k.charset==="iso-8859-1"?at+="utf8=%26%2310003%3B&":at+="utf8=%E2%9C%93&"),tt.length>0?at+tt:""}const xj="4.88.0";let nCe=!1,hX,D7e,R7e,wBt,B7e,j7e,F7e,$7e,H7e;function jMn(o,h={auto:!1}){if(nCe)throw new Error(`you must \`import 'openai/shims/${o.kind}'\` before importing anything else from openai`);if(hX)throw new Error(`can't \`import 'openai/shims/${o.kind}'\` after \`import 'openai/shims/${hX}'\``);nCe=h.auto,hX=o.kind,D7e=o.fetch,R7e=o.FormData,wBt=o.File,B7e=o.ReadableStream,j7e=o.getMultipartRequestOptions,F7e=o.getDefaultAgent,$7e=o.fileFromPath,H7e=o.isFsReadStream}class FMn{constructor(h){this.body=h}get[Symbol.toStringTag](){return"MultipartBody"}}function $Mn({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,N;try{b=fetch,k=Request,O=Response,N=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:N,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,q)=>({...q,body:new FMn(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}}hX||jMn($Mn(),{auto:!0});class As extends Error{}class Cg extends As{constructor(h,b,k,O){super(`${Cg.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 N=b;this.code=N==null?void 0:N.code,this.param=N==null?void 0:N.param,this.type=N==null?void 0:N.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 obt({message:k,cause:xBt(b)});const N=b==null?void 0:b.error;return h===400?new z7e(h,N,k,O):h===401?new U7e(h,N,k,O):h===403?new G7e(h,N,k,O):h===404?new q7e(h,N,k,O):h===409?new W7e(h,N,k,O):h===422?new K7e(h,N,k,O):h===429?new Y7e(h,N,k,O):h>=500?new V7e(h,N,k,O):new Cg(h,N,k,O)}}class k3 extends Cg{constructor({message:h}={}){super(void 0,void 0,h||"Request was aborted.",void 0)}}class obt extends Cg{constructor({message:h,cause:b}){super(void 0,void 0,h||"Connection error.",void 0),b&&(this.cause=b)}}class fjt extends obt{constructor({message:h}={}){super({message:h??"Request timed out."})}}class z7e extends Cg{}class U7e extends Cg{}class G7e extends Cg{}class q7e extends Cg{}class W7e extends Cg{}class K7e extends Cg{}class Y7e extends Cg{}class V7e extends Cg{}class J7e extends As{constructor(){super("Could not parse response content as the length limit was reached")}}class X7e 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},jP=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)},mw;class sbt{constructor(){mw.set(this,void 0),this.buffer=new Uint8Array,cmt(this,mw,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 N;for(;(N=HMn(this.buffer,jP(this,mw,"f")))!=null;){if(N.carriage&&jP(this,mw,"f")==null){cmt(this,mw,N.index,"f");continue}if(jP(this,mw,"f")!=null&&(N.index!==jP(this,mw,"f")+1||N.carriage)){O.push(this.decodeText(this.buffer.slice(0,jP(this,mw,"f")-1))),this.buffer=this.buffer.slice(jP(this,mw,"f")),cmt(this,mw,null,"f");continue}const B=jP(this,mw,"f")!==null?N.preceding-1:N.preceding,q=this.decodeText(this.buffer.slice(0,B));O.push(q),this.buffer=this.buffer.slice(N.index),cmt(this,mw,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(`
|
|
2452
2452
|
`):[]}}mw=new WeakMap;sbt.NEWLINE_CHARS=new Set([`
|
|
2453
2453
|
`,"\r"]);sbt.NEWLINE_REGEXP=/\r\n|[\n\r]/g;function HMn(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 zMn(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 Q7e(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 g6{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 N=!1;try{for await(const B of UMn(h,b))if(!N){if(B.data.startsWith("[DONE]")){N=!0;continue}if(B.event===null||B.event.startsWith("response.")){let q;try{q=JSON.parse(B.data)}catch(Z){throw console.error("Could not parse message into JSON:",B.data),console.error("From chunk:",B.raw),Z}if(q&&q.error)throw new Cg(void 0,q.error,void 0,void 0);yield q}else{let q;try{q=JSON.parse(B.data)}catch(Z){throw console.error("Could not parse message into JSON:",B.data),console.error("From chunk:",B.raw),Z}if(B.event=="error")throw new Cg(void 0,q.error,q.message,void 0);yield{event:B.event,data:q}}}N=!0}catch(B){if(B instanceof Error&&B.name==="AbortError")return;throw B}finally{N||b.abort()}}return new g6(O,b)}static fromReadableStream(h,b){let k=!1;async function*O(){const B=new sbt,q=Q7e(h);for await(const Z of q)for(const U of B.decode(Z))yield U;for(const Z of B.flush())yield Z}async function*N(){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 q of O())B||q&&(yield JSON.parse(q));B=!0}catch(q){if(q instanceof Error&&q.name==="AbortError")return;throw q}finally{B||b.abort()}}return new g6(N,b)}[Symbol.asyncIterator](){return this.iterator()}tee(){const h=[],b=[],k=this.iterator(),O=N=>({next:()=>{if(N.length===0){const B=k.next();h.push(B),b.push(B)}return N.shift()}});return[new g6(()=>O(h),this.controller),new g6(()=>O(b),this.controller)]}toReadableStream(){const h=this;let b;const k=new TextEncoder;return new B7e({async start(){b=h[Symbol.asyncIterator]()},async pull(O){try{const{value:N,done:B}=await b.next();if(B)return O.close();const q=k.encode(JSON.stringify(N)+`
|
|
2454
2454
|
`);O.enqueue(q)}catch(N){O.error(N)}},async cancel(){var O;await((O=b.return)==null?void 0:O.call(b))}})}}async function*UMn(o,h){if(!o.body)throw h.abort(),new As("Attempted to iterate over a response with no body");const b=new qMn,k=new sbt,O=Q7e(o.body);for await(const N of GMn(O))for(const B of k.decode(N)){const q=b.decode(B);q&&(yield q)}for(const N of k.flush()){const B=b.decode(N);B&&(yield B)}}async function*GMn(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 N;for(;(N=zMn(h))!==-1;)yield h.slice(0,N),h=h.slice(N)}h.length>0&&(yield h)}class qMn{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 N={event:this.event,data:this.data.join(`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as a,o as B,r as y,T as g}from"../client-BVv4NBtY.js";import{v as T,A as C,e as w,_ as v,f as R,F as S,T as I,R as _,c as x,d as j,B as P}from"../AgenticaChatApplication-
|
|
1
|
+
import{j as a,o as B,r as y,T as g}from"../client-BVv4NBtY.js";import{v as T,A as C,e as w,_ as v,f as R,F as S,T as I,R as _,c as x,d as j,B as P}from"../AgenticaChatApplication-BbUZT3m4.js";import{a as f,_ as b}from"../_isFormatUri-YqTfGpHo.js";import{D as U}from"../Divider-DaLcPLlq.js";class k{constructor(){this.articles=[]}index(){return this.articles}create(o){const l={id:T(),title:o.input.title,body:o.input.body,thumbnail:o.input.thumbnail,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return this.articles.push(l),l}update(o){const l=this.articles.find(d=>d.id===o.id);if(l===void 0)throw new Error("Unable to find the matched article.");o.input.title!==void 0&&(l.title=o.input.title),o.input.body!==void 0&&(l.body=o.input.body),o.input.thumbnail!==void 0&&(l.thumbnail=o.input.thumbnail),l.updated_at=new Date().toISOString()}erase(o){const l=this.articles.findIndex(d=>d.id===o.id);if(l===-1)throw new Error("Unable to find the matched article.");this.articles.splice(l,1)}}const F=u=>{const o=new k,l=new C({model:"chatgpt",vendor:{api:new w({apiKey:u.apiKey,dangerouslyAllowBrowser:!0}),model:u.model??"gpt-4o-mini"},controllers:[{protocol:"class",name:"bbs",application:{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:"Article entity.\n\n`IBbsArticle` is an entity representing an article in the BBS (Bulletin Board System).",type:"object",properties:{id:{title:"Primary Key",description:`Primary Key.
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
@format uuid`,type:"string"},created_at:{title:"Creation time of the article",description:`Creation time of the article.
|