@agentica/chat 0.30.7 → 0.30.8

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.
@@ -1436,7 +1436,7 @@ You have been provided with \`IValidation.IError[][]\` containing **previous his
1436
1436
  - Redesign the entire AST structure using proper architectural patterns
1437
1437
  - Enhance with comprehensive business context and realistic data
1438
1438
 
1439
- **Success means: the error path never appears in future correction cycles.**`};var vDn={};const _Dn=new jIe(()=>{var o;return kIe()?((o=vDn.LANG)==null?void 0:o.split(".")[0])??"en-US":navigator.language}),xDn=new jIe(()=>Intl.DateTimeFormat().resolvedOptions().timeZone);function EDn(o){var y;if(((y=o==null?void 0:o.systemPrompt)==null?void 0:y.common)!==void 0)return o.systemPrompt.common(o);const s=(o==null?void 0:o.locale)??_Dn.get(),p=(o==null?void 0:o.timezone)??xDn.get();return A6.COMMON.replace("${locale}",s).replace("${timezone}",p).replace("${datetime}",new Date().toISOString())}const o$={write:EDn};function TDn(o){return typeof o.initialize=="function"}var ZBt;(o=>{function s(p){return new TextDecoder().decode(p)}o.toUtf8=s})(ZBt||(ZBt={}));function HIe(o,s){return{accepted_prediction_tokens:(o.accepted_prediction_tokens??0)+(s.accepted_prediction_tokens??0),reasoning_tokens:(o.reasoning_tokens??0)+(s.reasoning_tokens??0),rejected_prediction_tokens:(o.rejected_prediction_tokens??0)+(s.rejected_prediction_tokens??0)}}function zIe(o,s){return{audio_tokens:(o.audio_tokens??0)+(s.audio_tokens??0),cached_tokens:(o.cached_tokens??0)+(s.cached_tokens??0)}}function kDn(o,s){return{prompt_tokens:(o.prompt_tokens??0)+(s.prompt_tokens??0),completion_tokens:(o.completion_tokens??0)+(s.completion_tokens??0),total_tokens:(o.total_tokens??0)+(s.total_tokens??0),completion_tokens_details:HIe(o.completion_tokens_details??{accepted_prediction_tokens:0,reasoning_tokens:0,rejected_prediction_tokens:0},s.completion_tokens_details??{accepted_prediction_tokens:0,reasoning_tokens:0,rejected_prediction_tokens:0}),prompt_tokens_details:zIe(o.prompt_tokens_details??{audio_tokens:0,cached_tokens:0},s.prompt_tokens_details??{audio_tokens:0,cached_tokens:0})}}const SDn={sum:kDn,sumCompletionTokenDetail:HIe,sumPromptTokenDetail:zIe};function CDn(o){const s=o instanceof Uint8Array?ZBt.toUtf8(o):o;return JSON.parse(s)}function UIe(o,s){const p=o.choices;s.choices.forEach(C=>{const N=p[C.index];if(N!=null){p[C.index]=qIe(N,C);return}p[C.index]={index:C.index,finish_reason:C.finish_reason??null,logprobs:C.logprobs??null,message:{tool_calls:C.delta.tool_calls!==void 0?C.delta.tool_calls.reduce((L,z)=>{var G,q;return L[z.index]={id:z.id??"",type:"function",function:{name:((G=z.function)==null?void 0:G.name)??"",arguments:((q=z.function)==null?void 0:q.arguments)??""}},L},[]):void 0,content:C.delta.content??null,refusal:C.delta.refusal??null,role:"assistant"}}});const y=s.usage==null?o.usage:o.usage==null?s.usage:SDn.sum(o.usage,s.usage);return{...o,choices:p,usage:y}}function ADn(o){const s=o[0];if(s===void 0)throw new Error("No chunks received");return o.reduce(UIe,{id:s.id,choices:[],created:s.created,model:s.model,object:"chat.completion",usage:void 0,service_tier:s.service_tier,system_fingerprint:s.system_fingerprint})}function qIe(o,s){var p;if(o.finish_reason==null&&s.finish_reason!=null&&(o.finish_reason=s.finish_reason),o.logprobs==null&&s.logprobs!=null&&(o.logprobs=s.logprobs),s.delta.content!=null&&(o.message.content==null?o.message.content=s.delta.content:o.message.content+=s.delta.content),s.delta.refusal!=null&&(o.message.refusal==null?o.message.refusal=s.delta.refusal:o.message.refusal+=s.delta.refusal),s.delta.tool_calls!=null){(p=o.message).tool_calls??(p.tool_calls=[]);const y=o.message.tool_calls;s.delta.tool_calls.forEach(C=>{var L,z;const N=y[C.index];if(N!=null){y[C.index]=WIe(N,C);return}y[C.index]={id:C.id??"",type:"function",function:{name:((L=C.function)==null?void 0:L.name)??"",arguments:((z=C.function)==null?void 0:z.arguments)??""}}})}return o}function WIe(o,s){return s.function!=null&&(o.function.arguments+=s.function.arguments??"",o.function.name+=s.function.name??""),o.id+=s.id??"",o}const I6={transformCompletionChunk:CDn,accumulate:UIe,merge:ADn,mergeChoice:qIe,mergeToolCalls:WIe};async function IDn(o){const s=o.getReader(),p=[];for(;;){const{done:y,value:C}=await s.read();if(y)break;p.push(C)}return p}async function ODn(o,s,p){const y=o.getReader(),C=Vmt(y);let N=p??null;for await(const L of C){if(N===null){N=L;continue}N=s(N,L)}return N}function NDn(o){return new ReadableStream({start:p=>{p.enqueue(o),p.close()}})}async function*KIe(o){yield o}async function*Vmt(o){for(;;){const{done:s,value:p}=await o.read();if(s)break;yield p}}function PDn(o,s){const p=o.getReader();return new ReadableStream({pull:async y=>{const{done:C,value:N}=await p.read();C?y.close():y.enqueue(s(N))}})}const _C={readAll:IDn,reduce:ODn,from:NDn,transform:PDn};function Xmt(o){return{operation:o.operation,reason:o.reason,toJSON:()=>({operation:o.operation.toJSON(),reason:o.reason})}}function GIe(o,s){const p=o.stack.findIndex(N=>N.operation.name===s.name);if(p===-1)return;const y=o.stack[p];o.stack.splice(p,1);const C=nRn({selection:Xmt({operation:y.operation,reason:s.reason})});o.dispatch(C)}async function LDn(o,s){var z,G,q,et,tt,nt;const p=await o.request("call",{messages:[{role:"system",content:o$.write(o.config)},...o.histories.map(a$).flat(),{role:"user",content:o.prompt.contents.map(s$)},...((G=(z=o.config)==null?void 0:z.systemPrompt)==null?void 0:G.execute)===null?[]:[{role:"system",content:((tt=(et=(q=o.config)==null?void 0:q.systemPrompt)==null?void 0:et.execute)==null?void 0:tt.call(et,o.histories))??A6.EXECUTE}]],tools:s.map(st=>({type:"function",function:{name:st.name,description:st.function.description,parameters:"separated"in st.function&&st.function.separated!==void 0?st.function.separated.llm??{type:"object",properties:{},required:[],additionalProperties:!1,$defs:{}}:st.function.parameters}})),tool_choice:"auto"}),y=await _C.readAll(p),C=I6.merge(y),N=[],L=((nt=o.config)==null?void 0:nt.retry)??yk.RETRY;for(const st of C.choices){for(const at of st.message.tool_calls??[])if(at.type==="function"){const Ot=s.find(St=>St.name===at.function.name);if(Ot===void 0)continue;const Dt=await YIe(o,Ot,at,[],L);o.dispatch(Dt),N.push(Dt),TDn(o)&&GIe(o,{name:Dt.operation.name,reason:"completed"})}if(st.message.role==="assistant"&&st.message.content!=null&&st.message.content.length!==0){const at=st.message.content,Ot=YFt({get:()=>at,done:()=>!0,stream:KIe(at),join:async()=>Promise.resolve(at)});o.dispatch(Ot)}}return N}async function YIe(o,s,p,y,C){const N=DDn(s,p);if(o.dispatch(N),N.type==="jsonParseError")return RDn(o,N,y,C-1);const L=s.function.validate(N.arguments);if(L.success===!1){const z=aRn({id:p.id,operation:s,result:L});return o.dispatch(z),MDn(o,N,z,[...y,z],C-1)}return BDn(N,s)}async function MDn(o,s,p,y,C){var N,L,z;return VIe(o,{giveUp:()=>bmt({operation:s.operation,arguments:s.arguments,value:{name:"ValidationError",message:`Invalid arguments. The validation failed after ${yk.RETRY} retries.`,errors:p.result.errors}}),operation:s.operation,toolCall:{id:s.id,arguments:JSON.stringify(s.arguments),result:JSON.stringify(p.result.errors)},systemPrompt:((z=(L=(N=o.config)==null?void 0:N.systemPrompt)==null?void 0:L.validate)==null?void 0:z.call(L,y.slice(0,-1)))??[A6.VALIDATE,...y.length>1?["",A6.VALIDATE_REPEATED.replace("${{HISTORICAL_ERRORS}}",JSON.stringify(y.slice(0,-1).map(G=>G.result.errors)))]:[]].join(`
1439
+ **Success means: the error path never appears in future correction cycles.**`};var vDn={};const _Dn=new jIe(()=>{var o;return kIe()?((o=vDn.LANG)==null?void 0:o.split(".")[0])??"en-US":navigator.language}),xDn=new jIe(()=>Intl.DateTimeFormat().resolvedOptions().timeZone);function EDn(o){var y;if(((y=o==null?void 0:o.systemPrompt)==null?void 0:y.common)!==void 0)return o.systemPrompt.common(o);const s=(o==null?void 0:o.locale)??_Dn.get(),p=(o==null?void 0:o.timezone)??xDn.get();return A6.COMMON.replace("${locale}",s).replace("${timezone}",p).replace("${datetime}",new Date().toISOString())}const o$={write:EDn};function TDn(o){return typeof o.initialize=="function"}var ZBt;(o=>{function s(p){return new TextDecoder().decode(p)}o.toUtf8=s})(ZBt||(ZBt={}));function HIe(o,s){return{accepted_prediction_tokens:(o.accepted_prediction_tokens??0)+(s.accepted_prediction_tokens??0),reasoning_tokens:(o.reasoning_tokens??0)+(s.reasoning_tokens??0),rejected_prediction_tokens:(o.rejected_prediction_tokens??0)+(s.rejected_prediction_tokens??0)}}function zIe(o,s){return{audio_tokens:(o.audio_tokens??0)+(s.audio_tokens??0),cached_tokens:(o.cached_tokens??0)+(s.cached_tokens??0)}}function kDn(o,s){return{prompt_tokens:(o.prompt_tokens??0)+(s.prompt_tokens??0),completion_tokens:(o.completion_tokens??0)+(s.completion_tokens??0),total_tokens:(o.total_tokens??0)+(s.total_tokens??0),completion_tokens_details:HIe(o.completion_tokens_details??{accepted_prediction_tokens:0,reasoning_tokens:0,rejected_prediction_tokens:0},s.completion_tokens_details??{accepted_prediction_tokens:0,reasoning_tokens:0,rejected_prediction_tokens:0}),prompt_tokens_details:zIe(o.prompt_tokens_details??{audio_tokens:0,cached_tokens:0},s.prompt_tokens_details??{audio_tokens:0,cached_tokens:0})}}const SDn={sum:kDn,sumCompletionTokenDetail:HIe,sumPromptTokenDetail:zIe};function CDn(o){const s=o instanceof Uint8Array?ZBt.toUtf8(o):o;return JSON.parse(s)}function UIe(o,s){const p=o.choices;s.choices.forEach(C=>{const N=p[C.index];if(N!=null){p[C.index]=qIe(N,C);return}p[C.index]={index:C.index,finish_reason:C.finish_reason??null,logprobs:C.logprobs??null,message:{tool_calls:C.delta.tool_calls!==void 0?C.delta.tool_calls.reduce((L,z)=>{var G,q;return L[z.index]={id:z.id??"",type:"function",function:{name:((G=z.function)==null?void 0:G.name)??"",arguments:((q=z.function)==null?void 0:q.arguments)??""}},L},[]):void 0,content:C.delta.content??null,refusal:C.delta.refusal??null,role:"assistant"}}});const y=s.usage==null?o.usage:o.usage==null?s.usage:SDn.sum(o.usage,s.usage);return{...o,choices:p,usage:y}}function ADn(o){const s=o[0];if(s===void 0)throw new Error("No chunks received");const p=o.reduce(UIe,{id:s.id,choices:[],created:s.created,model:s.model,object:"chat.completion",usage:void 0,service_tier:s.service_tier,system_fingerprint:s.system_fingerprint});return p.choices.forEach(y=>{var C;(C=y.message.tool_calls)==null||C.forEach(N=>{N.function.arguments===""&&(N.function.arguments="{}")})}),p}function qIe(o,s){var p;if(o.finish_reason==null&&s.finish_reason!=null&&(o.finish_reason=s.finish_reason),o.logprobs==null&&s.logprobs!=null&&(o.logprobs=s.logprobs),s.delta.content!=null&&(o.message.content==null?o.message.content=s.delta.content:o.message.content+=s.delta.content),s.delta.refusal!=null&&(o.message.refusal==null?o.message.refusal=s.delta.refusal:o.message.refusal+=s.delta.refusal),s.delta.tool_calls!=null){(p=o.message).tool_calls??(p.tool_calls=[]);const y=o.message.tool_calls;s.delta.tool_calls.forEach(C=>{var L,z;const N=y[C.index];if(N!=null){y[C.index]=WIe(N,C);return}y[C.index]={id:C.id??"",type:"function",function:{name:((L=C.function)==null?void 0:L.name)??"",arguments:((z=C.function)==null?void 0:z.arguments)??""}}})}return o}function WIe(o,s){return s.function!=null&&(o.function.arguments+=s.function.arguments??"",o.function.name+=s.function.name??""),o.id+=s.id??"",o}const I6={transformCompletionChunk:CDn,accumulate:UIe,merge:ADn,mergeChoice:qIe,mergeToolCalls:WIe};async function IDn(o){const s=o.getReader(),p=[];for(;;){const{done:y,value:C}=await s.read();if(y)break;p.push(C)}return p}async function ODn(o,s,p){const y=o.getReader(),C=Vmt(y);let N=p??null;for await(const L of C){if(N===null){N=L;continue}N=s(N,L)}return N}function NDn(o){return new ReadableStream({start:p=>{p.enqueue(o),p.close()}})}async function*KIe(o){yield o}async function*Vmt(o){for(;;){const{done:s,value:p}=await o.read();if(s)break;yield p}}function PDn(o,s){const p=o.getReader();return new ReadableStream({pull:async y=>{const{done:C,value:N}=await p.read();C?y.close():y.enqueue(s(N))}})}const _C={readAll:IDn,reduce:ODn,from:NDn,transform:PDn};function Xmt(o){return{operation:o.operation,reason:o.reason,toJSON:()=>({operation:o.operation.toJSON(),reason:o.reason})}}function GIe(o,s){const p=o.stack.findIndex(N=>N.operation.name===s.name);if(p===-1)return;const y=o.stack[p];o.stack.splice(p,1);const C=nRn({selection:Xmt({operation:y.operation,reason:s.reason})});o.dispatch(C)}async function LDn(o,s){var z,G,q,et,tt,nt;const p=await o.request("call",{messages:[{role:"system",content:o$.write(o.config)},...o.histories.map(a$).flat(),{role:"user",content:o.prompt.contents.map(s$)},...((G=(z=o.config)==null?void 0:z.systemPrompt)==null?void 0:G.execute)===null?[]:[{role:"system",content:((tt=(et=(q=o.config)==null?void 0:q.systemPrompt)==null?void 0:et.execute)==null?void 0:tt.call(et,o.histories))??A6.EXECUTE}]],tools:s.map(st=>({type:"function",function:{name:st.name,description:st.function.description,parameters:"separated"in st.function&&st.function.separated!==void 0?st.function.separated.llm??{type:"object",properties:{},required:[],additionalProperties:!1,$defs:{}}:st.function.parameters}})),tool_choice:"auto"}),y=await _C.readAll(p),C=I6.merge(y),N=[],L=((nt=o.config)==null?void 0:nt.retry)??yk.RETRY;for(const st of C.choices){for(const at of st.message.tool_calls??[])if(at.type==="function"){const Ot=s.find(St=>St.name===at.function.name);if(Ot===void 0)continue;const Dt=await YIe(o,Ot,at,[],L);o.dispatch(Dt),N.push(Dt),TDn(o)&&GIe(o,{name:Dt.operation.name,reason:"completed"})}if(st.message.role==="assistant"&&st.message.content!=null&&st.message.content.length!==0){const at=st.message.content,Ot=YFt({get:()=>at,done:()=>!0,stream:KIe(at),join:async()=>Promise.resolve(at)});o.dispatch(Ot)}}return N}async function YIe(o,s,p,y,C){const N=DDn(s,p);if(o.dispatch(N),N.type==="jsonParseError")return RDn(o,N,y,C-1);const L=s.function.validate(N.arguments);if(L.success===!1){const z=aRn({id:p.id,operation:s,result:L});return o.dispatch(z),MDn(o,N,z,[...y,z],C-1)}return BDn(N,s)}async function MDn(o,s,p,y,C){var N,L,z;return VIe(o,{giveUp:()=>bmt({operation:s.operation,arguments:s.arguments,value:{name:"ValidationError",message:`Invalid arguments. The validation failed after ${yk.RETRY} retries.`,errors:p.result.errors}}),operation:s.operation,toolCall:{id:s.id,arguments:JSON.stringify(s.arguments),result:JSON.stringify(p.result.errors)},systemPrompt:((z=(L=(N=o.config)==null?void 0:N.systemPrompt)==null?void 0:L.validate)==null?void 0:z.call(L,y.slice(0,-1)))??[A6.VALIDATE,...y.length>1?["",A6.VALIDATE_REPEATED.replace("${{HISTORICAL_ERRORS}}",JSON.stringify(y.slice(0,-1).map(G=>G.result.errors)))]:[]].join(`
1440
1440
  `),life:C,previousValidationErrors:y})}async function RDn(o,s,p,y){var C,N,L;return VIe(o,{giveUp:()=>bmt({operation:s.operation,arguments:{},value:{name:"JsonParseError",message:`Invalid JSON format. The parsing failed after ${yk.RETRY} retries.`,arguments:s.arguments,errorMessage:s.errorMessage}}),operation:s.operation,toolCall:{id:s.id,arguments:s.arguments,result:s.errorMessage},systemPrompt:((L=(N=(C=o.config)==null?void 0:C.systemPrompt)==null?void 0:N.jsonParseError)==null?void 0:L.call(N,s))??A6.JSON_PARSE_ERROR.replace("${{ERROR_MESSAGE}}",s.errorMessage),life:y,previousValidationErrors:p})}function DDn(o,s){try{const p=JSON.parse(s.function.arguments);return rRn({id:s.id,operation:o,arguments:p})}catch(p){return iRn({id:s.id,operation:o,arguments:s.function.arguments,errorMessage:p instanceof Error?p.message:String(p)})}}async function VIe(o,s){var L,z,G,q,et,tt;if(s.life<=0)return s.giveUp();const p=await o.request("call",{messages:[{role:"system",content:o$.write(o.config)},...o.histories.map(a$).flat(),{role:"user",content:o.prompt.contents.map(s$)},{role:"system",content:((G=(z=(L=o.config)==null?void 0:L.systemPrompt)==null?void 0:z.execute)==null?void 0:G.call(z,o.histories))??A6.EXECUTE},{role:"assistant",tool_calls:[{type:"function",id:s.toolCall.id,function:{name:s.operation.name,arguments:s.toolCall.arguments}}]},{role:"tool",content:s.toolCall.result,tool_call_id:s.toolCall.id},{role:"system",content:s.systemPrompt}],tools:[{type:"function",function:{name:s.operation.name,description:s.operation.function.description,parameters:"separated"in s.operation.function&&s.operation.function.separated!==void 0?((q=s.operation.function.separated)==null?void 0:q.llm)??{$defs:{},type:"object",properties:{},additionalProperties:!1,required:[]}:s.operation.function.parameters}}],tool_choice:"required"}),y=await _C.readAll(p),N=(tt=(et=I6.merge(y).choices[0])==null?void 0:et.message.tool_calls)==null?void 0:tt.find(nt=>nt.function.name===s.operation.name);return N===void 0?s.giveUp():YIe(o,s.operation,N,s.previousValidationErrors,s.life)}async function BDn(o,s){try{const p=await(async()=>{switch(s.protocol){case"class":return FDn(o,s);case"http":return $Dn(o,s);case"mcp":return jDn(o,s);default:throw new Error("Unknown protocol")}})();return bmt({operation:o.operation,arguments:o.arguments,value:p})}catch(p){return bmt({operation:o.operation,arguments:o.arguments,value:p instanceof Error?{...p,name:p.name,message:p.message}:p})}}async function FDn(o,s){const p=s.controller.execute;return typeof p=="function"?await p({application:s.controller.application,function:s.function,arguments:o.arguments}):await p[s.function.name](o.arguments)}async function $Dn(o,s){const p=s.controller.execute;return typeof p=="function"?await p({connection:s.controller.connection,application:s.controller.application,function:s.function,arguments:o.arguments}):await JBt.propagate({connection:s.controller.connection,application:s.controller.application,function:s.function,input:o.arguments})}async function jDn(o,s){return s.controller.client.callTool({method:s.function.name,name:s.function.name,arguments:o.arguments}).then(p=>p.content)}var VFt={};Object.defineProperty(VFt,"__esModule",{value:!0});var c$=VFt._validateReport=void 0;const HDn=o=>{const s=p=>{if(o.length===0)return!0;const y=o[o.length-1].path;return p.length>y.length||y.substring(0,p.length)!==p};return(p,y)=>{var C;return p&&s(y.path)&&(y.value===void 0&&((C=y.description)!==null&&C!==void 0||(y.description=["The value at this path is `undefined`.","",`Please fill the \`${y.expected}\` typed value next time.`].join(`
1441
1441
  `))),o.push(y)),!1}};c$=VFt._validateReport=HDn;const UDt={functions:[{name:"cancelFunctions",parameters:{description:` Properties of the function
1442
1442
 
@@ -1,4 +1,4 @@
1
- import{j as y,o as U,r as v,T as I}from"../client-B3aq8qpT.js";import{q as k,t as $,r as B,s as F,w as M,x as S,y as q,z as D,E as L,J as C,K as T,M as O,N as E,v as x,d as K,_ as m,V as j,c as N,F as G,T as W,B as z}from"../VendorConfigurationMovie-Ar2QHcqt.js";import{a as u,_ as p}from"../_isFormatUri-YqTfGpHo.js";import{D as H}from"../Divider-DX1xhf0M.js";class A{constructor(o){this.props=o,this.operations_=k.compose({controllers:o.controllers,config:o.config}),this.histories_=(o.histories??[]).map(d=>$({operations:this.operations_.group,history:d})),this.token_usage_=this.props.tokenUsage!==void 0?this.props.tokenUsage instanceof B?this.props.tokenUsage:new B(this.props.tokenUsage):B.zero(),this.listeners_=new Map,this.semaphore_=o.vendor.semaphore!=null?typeof o.vendor.semaphore=="object"?o.vendor.semaphore:new F(o.vendor.semaphore):null}clone(){var o;return new A({...this.props,histories:(o=this.props.histories)==null?void 0:o.slice()})}async conversate(o){var t,i,n,h;const d=[],s=f=>{this.dispatch(f).catch(()=>{}),"toHistory"in f&&("join"in f?d.push(async()=>(await f.join(),f.toHistory())):d.push(async()=>f.toHistory()))},l=M({contents:Array.isArray(o)?o:typeof o=="string"?[{type:"text",text:o}]:[o]});s(l);const a=this.getContext({prompt:l,dispatch:s,usage:this.token_usage_}),r=await S(a,this.operations_.array);r.length&&((i=(t=this.props.config)==null?void 0:t.executor)==null?void 0:i.describe)!==null&&((h=(n=this.props.config)==null?void 0:n.executor)==null?void 0:h.describe)!==!1&&await q(a,r);const e=await Promise.all(d.map(async f=>f()));return this.histories_.push(...e),e}getConfig(){return this.props.config}getVendor(){return this.props.vendor}getOperations(){return this.operations_.array}getControllers(){return this.props.controllers}getHistories(){return this.histories_}getTokenUsage(){return this.token_usage_}getContext(o){const d=async(s,l)=>{var w;const a=L({source:s,body:{...l,model:this.props.vendor.model,stream:!0,stream_options:{include_usage:!0}},options:this.props.vendor.options});o.dispatch(a);const r=((w=this.props.config)==null?void 0:w.backoffStrategy)??(b=>{throw b.error}),e=await(async()=>{let b=0;for(;;)try{return await this.props.vendor.api.chat.completions.create(a.body,a.options)}catch(g){const R=r({count:b,error:g});await new Promise(P=>setTimeout(P,R)),b++}})(),[t,i]=C.transform(e.toReadableStream(),b=>T.transformCompletionChunk(b)).tee(),[n,h]=i.tee();(async()=>{const b=n.getReader();for(;;){const g=await b.read();if(g.done)break;g.value.usage!=null&&O.aggregate({kind:s,completionUsage:g.value.usage,usage:o.usage})}})().catch(()=>{});const[f,_]=t.tee();return o.dispatch({id:x(),type:"response",source:s,stream:E(f.getReader()),body:a.body,options:a.options,join:async()=>{const b=await C.readAll(_);return T.merge(b)},created_at:new Date().toISOString()}),h};return{operations:this.operations_,config:this.props.config,histories:this.histories_,prompt:o.prompt,dispatch:o.dispatch,request:this.semaphore_===null?d:async(s,l)=>{await this.semaphore_.acquire();try{return await d(s,l)}finally{this.semaphore_.release().catch(()=>{})}}}}on(o,d){return D(this.listeners_,o,()=>new Set).add(d),this}off(o,d){const s=this.listeners_.get(o);return s!==void 0&&(s.delete(d),s.size===0&&this.listeners_.delete(o)),this}async dispatch(o){const d=this.listeners_.get(o.type);d!==void 0&&await Promise.all(Array.from(d).map(async s=>{try{await s(o)}catch{}}))}}class V{constructor(){this.articles=[]}index(){return this.articles}create(o){const d={id:x(),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(d),d}update(o){const d=this.articles.find(s=>s.id===o.id);if(d===void 0)throw new Error("Unable to find the matched article.");o.input.title!==void 0&&(d.title=o.input.title),o.input.body!==void 0&&(d.body=o.input.body),o.input.thumbnail!==void 0&&(d.thumbnail=o.input.thumbnail),d.updated_at=new Date().toISOString()}erase(o){const d=this.articles.findIndex(s=>s.id===o.id);if(d===-1)throw new Error("Unable to find the matched article.");this.articles.splice(d,1)}}const J={chatgpt:{model:"chatgpt",options:{reference:!0,strict:!1,separate:null},functions:[{name:"index",parameters:{type:"object",properties:{},additionalProperties:!1,required:[],$defs:{IBbsArticle:{description:"Article entity.\n\n`IBbsArticle` is an entity representing an article in the BBS (Bulletin Board System).",type:"object",properties:{id:{description:`Primary Key.
1
+ import{j as y,o as U,r as v,T as I}from"../client-B3aq8qpT.js";import{q as k,t as $,r as B,s as F,w as M,x as S,y as q,z as D,E as L,J as C,K as T,M as O,N as E,v as x,d as K,_ as m,V as j,c as N,F as G,T as W,B as z}from"../VendorConfigurationMovie-BkTqlVMv.js";import{a as u,_ as p}from"../_isFormatUri-YqTfGpHo.js";import{D as H}from"../Divider-DX1xhf0M.js";class A{constructor(o){this.props=o,this.operations_=k.compose({controllers:o.controllers,config:o.config}),this.histories_=(o.histories??[]).map(d=>$({operations:this.operations_.group,history:d})),this.token_usage_=this.props.tokenUsage!==void 0?this.props.tokenUsage instanceof B?this.props.tokenUsage:new B(this.props.tokenUsage):B.zero(),this.listeners_=new Map,this.semaphore_=o.vendor.semaphore!=null?typeof o.vendor.semaphore=="object"?o.vendor.semaphore:new F(o.vendor.semaphore):null}clone(){var o;return new A({...this.props,histories:(o=this.props.histories)==null?void 0:o.slice()})}async conversate(o){var t,i,n,h;const d=[],s=f=>{this.dispatch(f).catch(()=>{}),"toHistory"in f&&("join"in f?d.push(async()=>(await f.join(),f.toHistory())):d.push(async()=>f.toHistory()))},l=M({contents:Array.isArray(o)?o:typeof o=="string"?[{type:"text",text:o}]:[o]});s(l);const a=this.getContext({prompt:l,dispatch:s,usage:this.token_usage_}),r=await S(a,this.operations_.array);r.length&&((i=(t=this.props.config)==null?void 0:t.executor)==null?void 0:i.describe)!==null&&((h=(n=this.props.config)==null?void 0:n.executor)==null?void 0:h.describe)!==!1&&await q(a,r);const e=await Promise.all(d.map(async f=>f()));return this.histories_.push(...e),e}getConfig(){return this.props.config}getVendor(){return this.props.vendor}getOperations(){return this.operations_.array}getControllers(){return this.props.controllers}getHistories(){return this.histories_}getTokenUsage(){return this.token_usage_}getContext(o){const d=async(s,l)=>{var w;const a=L({source:s,body:{...l,model:this.props.vendor.model,stream:!0,stream_options:{include_usage:!0}},options:this.props.vendor.options});o.dispatch(a);const r=((w=this.props.config)==null?void 0:w.backoffStrategy)??(b=>{throw b.error}),e=await(async()=>{let b=0;for(;;)try{return await this.props.vendor.api.chat.completions.create(a.body,a.options)}catch(g){const R=r({count:b,error:g});await new Promise(P=>setTimeout(P,R)),b++}})(),[t,i]=C.transform(e.toReadableStream(),b=>T.transformCompletionChunk(b)).tee(),[n,h]=i.tee();(async()=>{const b=n.getReader();for(;;){const g=await b.read();if(g.done)break;g.value.usage!=null&&O.aggregate({kind:s,completionUsage:g.value.usage,usage:o.usage})}})().catch(()=>{});const[f,_]=t.tee();return o.dispatch({id:x(),type:"response",source:s,stream:E(f.getReader()),body:a.body,options:a.options,join:async()=>{const b=await C.readAll(_);return T.merge(b)},created_at:new Date().toISOString()}),h};return{operations:this.operations_,config:this.props.config,histories:this.histories_,prompt:o.prompt,dispatch:o.dispatch,request:this.semaphore_===null?d:async(s,l)=>{await this.semaphore_.acquire();try{return await d(s,l)}finally{this.semaphore_.release().catch(()=>{})}}}}on(o,d){return D(this.listeners_,o,()=>new Set).add(d),this}off(o,d){const s=this.listeners_.get(o);return s!==void 0&&(s.delete(d),s.size===0&&this.listeners_.delete(o)),this}async dispatch(o){const d=this.listeners_.get(o.type);d!==void 0&&await Promise.all(Array.from(d).map(async s=>{try{await s(o)}catch{}}))}}class V{constructor(){this.articles=[]}index(){return this.articles}create(o){const d={id:x(),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(d),d}update(o){const d=this.articles.find(s=>s.id===o.id);if(d===void 0)throw new Error("Unable to find the matched article.");o.input.title!==void 0&&(d.title=o.input.title),o.input.body!==void 0&&(d.body=o.input.body),o.input.thumbnail!==void 0&&(d.thumbnail=o.input.thumbnail),d.updated_at=new Date().toISOString()}erase(o){const d=this.articles.findIndex(s=>s.id===o.id);if(d===-1)throw new Error("Unable to find the matched article.");this.articles.splice(d,1)}}const J={chatgpt:{model:"chatgpt",options:{reference:!0,strict:!1,separate:null},functions:[{name:"index",parameters:{type:"object",properties:{},additionalProperties:!1,required:[],$defs:{IBbsArticle:{description:"Article entity.\n\n`IBbsArticle` is an entity representing an article in the BBS (Bulletin Board System).",type:"object",properties:{id:{description:`Primary Key.
2
2
 
3
3
 
4
4
  @format uuid`,type:"string"},created_at:{description:`Creation time of the article.