@agentica/chat 0.32.3-dev.1 → 0.32.3-dev.2

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.
@@ -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-CR6UFY6O.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-CBzeosTR.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.