@agentica/chat 0.32.1 → 0.32.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.
- package/dist/assets/{VendorConfigurationMovie-Be-18QBU.js → VendorConfigurationMovie-DGYbrAHL.js} +1 -1
- package/dist/assets/bbs/{index-D2TiDtkT.js → index-LNBpZubV.js} +1 -1
- package/dist/assets/shopping/{index.html-1zW8eZhf.js → index.html-BrdQr8x5.js} +1 -1
- package/dist/assets/uploader/{index.html-3iPazxVL.js → index.html-E_l0bEa0.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/{VendorConfigurationMovie-Be-18QBU.js → VendorConfigurationMovie-DGYbrAHL.js}
RENAMED
|
@@ -1449,7 +1449,7 @@ You have been provided with \`IValidation.IError[][]\` containing **previous his
|
|
|
1449
1449
|
- Redesign the entire AST structure using proper architectural patterns
|
|
1450
1450
|
- Enhance with comprehensive business context and realistic data
|
|
1451
1451
|
|
|
1452
|
-
**Success means: the error path never appears in future correction cycles.**`};var vDn={};const _Dn=new HIe(()=>{var o;return SIe()?((o=vDn.LANG)==null?void 0:o.split(".")[0])??"en-US":navigator.language}),xDn=new HIe(()=>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 I6.COMMON.replace("${locale}",s).replace("${timezone}",p).replace("${datetime}",new Date().toISOString())}const o$={write:EDn};function TDn(o){return typeof o.initialize=="function"}class kDn extends Error{constructor(s){super(s),this.name="AsyncQueueClosedError"}}class SDn{constructor(){this.queue=[],this.resolvers=[],this.closeResolvers=[],this.emptyResolvers=[],this.closed=!1}enqueue(s){var p;if(this.closed){console.error(new kDn("Cannot enqueue item: queue is closed."));return}this.queue.push(s),this.resolvers.length>0&&((p=this.resolvers.shift())==null||p({value:this.queue.shift(),done:!1}))}async dequeue(){const s=this.isEmpty()?this.isClosed()?{value:void 0,done:!0}:null:{value:this.queue.shift(),done:!1};return this.isEmpty()&&this.emptyResolvers.length!==0&&(this.emptyResolvers.forEach(p=>p()),this.emptyResolvers=[]),s!==null?s:new Promise(p=>this.resolvers.push(p))}isEmpty(){return this.queue.length===0}isClosed(){return this.closed}done(){return this.isClosed()&&this.isEmpty()}close(){var s;for(this.closed=!0;this.resolvers.length>0;)(s=this.resolvers.shift())==null||s({value:void 0,done:!0});this.closeResolvers.forEach(p=>p())}async waitUntilEmpty(){return this.isEmpty()?Promise.resolve():new Promise(s=>{this.emptyResolvers.push(s)})}async waitClosed(){return this.isClosed()?Promise.resolve():new Promise(s=>{this.closeResolvers.push(s)})}}var eFt;(o=>{function s(p){return new TextDecoder().decode(p)}o.toUtf8=s})(eFt||(eFt={}));function zIe(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 UIe(o,s){return{audio_tokens:(o.audio_tokens??0)+(s.audio_tokens??0),cached_tokens:(o.cached_tokens??0)+(s.cached_tokens??0)}}function CDn(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:zIe(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:UIe(o.prompt_tokens_details??{audio_tokens:0,cached_tokens:0},s.prompt_tokens_details??{audio_tokens:0,cached_tokens:0})}}const ADn={sum:CDn,sumCompletionTokenDetail:zIe,sumPromptTokenDetail:UIe};function IDn(o){const s=o instanceof Uint8Array?eFt.toUtf8(o):o;return JSON.parse(s)}function qIe(o,s){const p=o.choices;s.choices.forEach(C=>{const N=p[C.index];if(N!=null){p[C.index]=WIe(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:ADn.sum(o.usage,s.usage);return{...o,choices:p,usage:y}}function ODn(o){const s=o[0];if(s===void 0)throw new Error("No chunks received");const p=o.reduce(qIe,{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 WIe(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]=KIe(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 KIe(o,s){return s.function!=null&&(o.function.arguments+=s.function.arguments??"",o.function.name+=s.function.name??""),o.id+=s.id??"",o}const L3={transformCompletionChunk:IDn,accumulate:qIe,merge:ODn,mergeChoice:WIe,mergeToolCalls:KIe};class Qmt{constructor(){this.queue=new SDn,this.consumer=new ReadableStream({pull:async s=>{const{value:p,done:y}=await this.queue.dequeue();if(y===!0){s.close();return}s.enqueue(p)}})}produce(s){this.queue.enqueue(s)}close(){this.queue.close()}done(){return this.queue.done()}async waitClosed(){await this.queue.waitClosed()}async waitUntilEmpty(){await this.queue.waitUntilEmpty()}}async function NDn(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 PDn(o,s,p){const y=o.getReader(),C=c$(y);let N=p??null;for await(const L of C){if(N===null){N=L;continue}N=s(N,L)}return N}function LDn(o){return new ReadableStream({start:p=>{p.enqueue(o),p.close()}})}async function*GIe(o){yield o}async function*c$(o){for(;;){const{done:s,value:p}=await o.read();if(s)break;yield p}}function MDn(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:NDn,reduce:PDn,from:LDn,transform:MDn};function Jmt(o){return{operation:o.operation,reason:o.reason,toJSON:()=>({operation:o.operation.toJSON(),reason:o.reason})}}function YIe(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:Jmt({operation:y.operation,reason:s.reason})});o.dispatch(C)}async function RDn(o,s){var q,et,tt,nt,st,at;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$)},...((et=(q=o.config)==null?void 0:q.systemPrompt)==null?void 0:et.execute)===null?[]:[{role:"system",content:((st=(nt=(tt=o.config)==null?void 0:tt.systemPrompt)==null?void 0:nt.execute)==null?void 0:st.call(nt,o.histories))??I6.EXECUTE}]],tools:s.map(kt=>({type:"function",function:{name:kt.name,description:kt.function.description,parameters:"separated"in kt.function&&kt.function.separated!==void 0?kt.function.separated.llm??{type:"object",properties:{},required:[],additionalProperties:!1,$defs:{}}:kt.function.parameters}})),tool_choice:"auto"}),y=[],N=await _C.reduce(p,async(kt,Rt)=>{const At=await kt,ae=ee=>{var xe;for(const rn of ee){if(rn.finish_reason!=null){(xe=y[rn.index])==null||xe.mpsc.close();continue}if(rn.delta.content==null||rn.delta.content==="")continue;if(y[rn.index]!=null){y[rn.index].content+=rn.delta.content,y[rn.index].mpsc.produce(rn.delta.content);continue}const de=new Qmt;y[rn.index]={content:rn.delta.content,mpsc:de},de.produce(rn.delta.content);const bn=WQ({stream:c$(de.consumer.getReader()),done:()=>de.done(),get:()=>{var ir;return((ir=y[rn.index])==null?void 0:ir.content)??""},join:async()=>(await de.waitClosed(),y[rn.index].content)});o.dispatch(bn)}};return At.object==="chat.completion.chunk"?(ae([At,Rt].flatMap(ee=>ee.choices)),L3.merge([At,Rt])):(ae(Rt.choices),L3.accumulate(At,Rt))}),L=N.choices.filter(kt=>kt.message.tool_calls==null&&kt.message.content==="");if(L.length>0)return L.forEach(kt=>{const Rt=WQ({stream:GIe(kt.message.content??""),done:()=>!0,get:()=>kt.message.content??"",join:async()=>kt.message.content??""});o.dispatch(Rt)}),[];const z=[],G=((at=o.config)==null?void 0:at.retry)??yk.RETRY;for(const kt of N.choices)for(const Rt of kt.message.tool_calls??[])if(Rt.type==="function"){const At=s.find(ee=>ee.name===Rt.function.name);if(At===void 0)continue;const ae=await VIe(o,At,Rt,[],G);o.dispatch(ae),z.push(ae),TDn(o)&&YIe(o,{name:ae.operation.name,reason:"completed"})}return z}async function VIe(o,s,p,y,C){const N=FDn(s,p);if(o.dispatch(N),N.type==="jsonParseError")return BDn(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),DDn(o,N,z,[...y,z],C-1)}return $Dn(N,s)}async function DDn(o,s,p,y,C){var N,L,z;return XIe(o,{giveUp:()=>ymt({operation:s.operation,arguments:s.arguments,value:{name:"ValidationError",message:`Invalid arguments. The validation failed after ${yk.RETRY} retries.`,errors:p.result.errors},success:!1}),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)))??[I6.VALIDATE,...y.length>1?["",I6.VALIDATE_REPEATED.replace("${{HISTORICAL_ERRORS}}",JSON.stringify(y.slice(0,-1).map(G=>G.result.errors)))]:[]].join(`
|
|
1452
|
+
**Success means: the error path never appears in future correction cycles.**`};var vDn={};const _Dn=new HIe(()=>{var o;return SIe()?((o=vDn.LANG)==null?void 0:o.split(".")[0])??"en-US":navigator.language}),xDn=new HIe(()=>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 I6.COMMON.replace("${locale}",s).replace("${timezone}",p).replace("${datetime}",new Date().toISOString())}const o$={write:EDn};function TDn(o){return typeof o.initialize=="function"}class kDn extends Error{constructor(s){super(s),this.name="AsyncQueueClosedError"}}class SDn{constructor(){this.queue=[],this.resolvers=[],this.closeResolvers=[],this.emptyResolvers=[],this.closed=!1}enqueue(s){var p;if(this.closed){console.error(new kDn("Cannot enqueue item: queue is closed."));return}this.queue.push(s),this.resolvers.length>0&&((p=this.resolvers.shift())==null||p({value:this.queue.shift(),done:!1}))}async dequeue(){const s=this.isEmpty()?this.isClosed()?{value:void 0,done:!0}:null:{value:this.queue.shift(),done:!1};return this.isEmpty()&&this.emptyResolvers.length!==0&&(this.emptyResolvers.forEach(p=>p()),this.emptyResolvers=[]),s!==null?s:new Promise(p=>this.resolvers.push(p))}isEmpty(){return this.queue.length===0}isClosed(){return this.closed}done(){return this.isClosed()&&this.isEmpty()}close(){var s;for(this.closed=!0;this.resolvers.length>0;)(s=this.resolvers.shift())==null||s({value:void 0,done:!0});this.closeResolvers.forEach(p=>p())}async waitUntilEmpty(){return this.isEmpty()?Promise.resolve():new Promise(s=>{this.emptyResolvers.push(s)})}async waitClosed(){return this.isClosed()?Promise.resolve():new Promise(s=>{this.closeResolvers.push(s)})}}var eFt;(o=>{function s(p){return new TextDecoder().decode(p)}o.toUtf8=s})(eFt||(eFt={}));function zIe(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 UIe(o,s){return{audio_tokens:(o.audio_tokens??0)+(s.audio_tokens??0),cached_tokens:(o.cached_tokens??0)+(s.cached_tokens??0)}}function CDn(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:zIe(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:UIe(o.prompt_tokens_details??{audio_tokens:0,cached_tokens:0},s.prompt_tokens_details??{audio_tokens:0,cached_tokens:0})}}const ADn={sum:CDn,sumCompletionTokenDetail:zIe,sumPromptTokenDetail:UIe};function IDn(o){const s=o instanceof Uint8Array?eFt.toUtf8(o):o;return JSON.parse(s)}function qIe(o,s){const p=o.choices;s.choices.forEach(C=>{const N=p[C.index];if(N!=null){p[C.index]=WIe(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",reasoning:C.delta.reasoning??null}}});const y=s.usage==null?o.usage:o.usage==null?s.usage:ADn.sum(o.usage,s.usage);return{...o,choices:p,usage:y}}function ODn(o){const s=o[0];if(s===void 0)throw new Error("No chunks received");const p=o.reduce(qIe,{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 WIe(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.reasoning!=null&&(o.message.reasoning==null?o.message.reasoning=s.delta.reasoning:o.message.reasoning+=s.delta.reasoning),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]=KIe(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 KIe(o,s){return s.function!=null&&(o.function.arguments+=s.function.arguments??"",o.function.name+=s.function.name??""),o.id+=s.id??"",o}const L3={transformCompletionChunk:IDn,accumulate:qIe,merge:ODn,mergeChoice:WIe,mergeToolCalls:KIe};class Qmt{constructor(){this.queue=new SDn,this.consumer=new ReadableStream({pull:async s=>{const{value:p,done:y}=await this.queue.dequeue();if(y===!0){s.close();return}s.enqueue(p)}})}produce(s){this.queue.enqueue(s)}close(){this.queue.close()}done(){return this.queue.done()}async waitClosed(){await this.queue.waitClosed()}async waitUntilEmpty(){await this.queue.waitUntilEmpty()}}async function NDn(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 PDn(o,s,p){const y=o.getReader(),C=c$(y);let N=p??null;for await(const L of C){if(N===null){N=L;continue}N=s(N,L)}return N}function LDn(o){return new ReadableStream({start:p=>{p.enqueue(o),p.close()}})}async function*GIe(o){yield o}async function*c$(o){for(;;){const{done:s,value:p}=await o.read();if(s)break;yield p}}function MDn(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:NDn,reduce:PDn,from:LDn,transform:MDn};function Jmt(o){return{operation:o.operation,reason:o.reason,toJSON:()=>({operation:o.operation.toJSON(),reason:o.reason})}}function YIe(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:Jmt({operation:y.operation,reason:s.reason})});o.dispatch(C)}async function RDn(o,s){var q,et,tt,nt,st,at;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$)},...((et=(q=o.config)==null?void 0:q.systemPrompt)==null?void 0:et.execute)===null?[]:[{role:"system",content:((st=(nt=(tt=o.config)==null?void 0:tt.systemPrompt)==null?void 0:nt.execute)==null?void 0:st.call(nt,o.histories))??I6.EXECUTE}]],tools:s.map(kt=>({type:"function",function:{name:kt.name,description:kt.function.description,parameters:"separated"in kt.function&&kt.function.separated!==void 0?kt.function.separated.llm??{type:"object",properties:{},required:[],additionalProperties:!1,$defs:{}}:kt.function.parameters}})),tool_choice:"auto"}),y=[],N=await _C.reduce(p,async(kt,Rt)=>{const At=await kt,ae=ee=>{var xe;for(const rn of ee){if(rn.finish_reason!=null){(xe=y[rn.index])==null||xe.mpsc.close();continue}if(rn.delta.content==null||rn.delta.content==="")continue;if(y[rn.index]!=null){y[rn.index].content+=rn.delta.content,y[rn.index].mpsc.produce(rn.delta.content);continue}const de=new Qmt;y[rn.index]={content:rn.delta.content,mpsc:de},de.produce(rn.delta.content);const bn=WQ({stream:c$(de.consumer.getReader()),done:()=>de.done(),get:()=>{var ir;return((ir=y[rn.index])==null?void 0:ir.content)??""},join:async()=>(await de.waitClosed(),y[rn.index].content)});o.dispatch(bn)}};return At.object==="chat.completion.chunk"?(ae([At,Rt].flatMap(ee=>ee.choices)),L3.merge([At,Rt])):(ae(Rt.choices),L3.accumulate(At,Rt))}),L=N.choices.filter(kt=>kt.message.tool_calls==null&&kt.message.content==="");if(L.length>0)return L.forEach(kt=>{const Rt=WQ({stream:GIe(kt.message.content??""),done:()=>!0,get:()=>kt.message.content??"",join:async()=>kt.message.content??""});o.dispatch(Rt)}),[];const z=[],G=((at=o.config)==null?void 0:at.retry)??yk.RETRY;for(const kt of N.choices)for(const Rt of kt.message.tool_calls??[])if(Rt.type==="function"){const At=s.find(ee=>ee.name===Rt.function.name);if(At===void 0)continue;const ae=await VIe(o,At,Rt,[],G);o.dispatch(ae),z.push(ae),TDn(o)&&YIe(o,{name:ae.operation.name,reason:"completed"})}return z}async function VIe(o,s,p,y,C){const N=FDn(s,p);if(o.dispatch(N),N.type==="jsonParseError")return BDn(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),DDn(o,N,z,[...y,z],C-1)}return $Dn(N,s)}async function DDn(o,s,p,y,C){var N,L,z;return XIe(o,{giveUp:()=>ymt({operation:s.operation,arguments:s.arguments,value:{name:"ValidationError",message:`Invalid arguments. The validation failed after ${yk.RETRY} retries.`,errors:p.result.errors},success:!1}),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)))??[I6.VALIDATE,...y.length>1?["",I6.VALIDATE_REPEATED.replace("${{HISTORICAL_ERRORS}}",JSON.stringify(y.slice(0,-1).map(G=>G.result.errors)))]:[]].join(`
|
|
1453
1453
|
`),life:C,previousValidationErrors:y})}async function BDn(o,s,p,y){var C,N,L;return XIe(o,{giveUp:()=>ymt({operation:s.operation,arguments:{},value:{name:"JsonParseError",message:`Invalid JSON format. The parsing failed after ${yk.RETRY} retries.`,arguments:s.arguments,errorMessage:s.errorMessage},success:!1}),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))??I6.JSON_PARSE_ERROR.replace("${{ERROR_MESSAGE}}",s.errorMessage),life:y,previousValidationErrors:p})}function FDn(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 XIe(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))??I6.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=L3.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():VIe(o,s.operation,N,s.previousValidationErrors,s.life)}async function $Dn(o,s){try{const p=await(async()=>{switch(s.protocol){case"class":return jDn(o,s);case"http":return HDn(o,s);case"mcp":return zDn(o,s);default:throw new Error("Unknown protocol")}})();return ymt({operation:o.operation,arguments:o.arguments,value:p,success:!0})}catch(p){return ymt({operation:o.operation,arguments:o.arguments,value:p instanceof Error?{...p,name:p.name,message:p.message}:p,success:!1})}}async function jDn(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 HDn(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 tFt.propagate({connection:s.controller.connection,application:s.controller.application,function:s.function,input:o.arguments})}async function zDn(o,s){return s.controller.client.callTool({method:s.function.name,name:s.function.name,arguments:o.arguments}).then(p=>p.content)}var XFt={};Object.defineProperty(XFt,"__esModule",{value:!0});var u$=XFt._validateReport=void 0;const UDn=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(`
|
|
1454
1454
|
`))),o.push(y)),!1}};u$=XFt._validateReport=UDn;const WDt={functions:[{name:"cancelFunctions",parameters:{description:` Properties of the function
|
|
1455
1455
|
|
|
@@ -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-
|
|
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-DGYbrAHL.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.
|