@agentica/chat 0.33.0 → 0.33.1
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-DxDFpSTX.js → VendorConfigurationMovie-A-2G3I__.js} +1 -1
- package/dist/assets/bbs/{index-B8EIoBMc.js → index-DGJk5lD_.js} +1 -1
- package/dist/assets/shopping/{index.html-D345_Wng.js → index.html-2i6nPiRm.js} +1 -1
- package/dist/assets/uploader/{index.html-RdAljVX2.js → index.html-CuliKe31.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-DxDFpSTX.js → VendorConfigurationMovie-A-2G3I__.js}
RENAMED
|
@@ -1451,7 +1451,7 @@ You have been provided with \`IValidation.IError[][]\` containing **previous his
|
|
|
1451
1451
|
|
|
1452
1452
|
**Success means: the error path never appears in future correction cycles.**`};var uBn={};const lBn=new gOe(()=>{var s;return tOe()?((s=uBn.LANG)==null?void 0:s.split(".")[0])??"en-US":navigator.language}),hBn=new gOe(()=>Intl.DateTimeFormat().resolvedOptions().timeZone);function fBn(s){var y;if(((y=s==null?void 0:s.systemPrompt)==null?void 0:y.common)!==void 0)return s.systemPrompt.common(s);const o=(s==null?void 0:s.locale)??lBn.get(),d=(s==null?void 0:s.timezone)??hBn.get();return I6.COMMON.replace("${locale}",o).replace("${timezone}",d).replace("${datetime}",new Date().toISOString())}const c$={write:fBn};function dBn(s){return typeof s.initialize=="function"}function bOe(s){const o=async(d,y,C=0)=>{try{return await d(y)}catch(O){if(C>=s-1)throw O;return o(d,O,C+1)}};return o}class VQ extends Error{constructor(){super();const o=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,o):this.__proto__=o}}class Imt extends VQ{constructor(o){super(),this.reasoning=o}}var dFt;(s=>{function o(d){return new TextDecoder().decode(d)}s.toUtf8=o})(dFt||(dFt={}));function mOe(s,o){return{accepted_prediction_tokens:(s.accepted_prediction_tokens??0)+(o.accepted_prediction_tokens??0),reasoning_tokens:(s.reasoning_tokens??0)+(o.reasoning_tokens??0),rejected_prediction_tokens:(s.rejected_prediction_tokens??0)+(o.rejected_prediction_tokens??0)}}function yOe(s,o){return{audio_tokens:(s.audio_tokens??0)+(o.audio_tokens??0),cached_tokens:(s.cached_tokens??0)+(o.cached_tokens??0)}}function pBn(s,o){return{prompt_tokens:(s.prompt_tokens??0)+(o.prompt_tokens??0),completion_tokens:(s.completion_tokens??0)+(o.completion_tokens??0),total_tokens:(s.total_tokens??0)+(o.total_tokens??0),completion_tokens_details:mOe(s.completion_tokens_details??{accepted_prediction_tokens:0,reasoning_tokens:0,rejected_prediction_tokens:0},o.completion_tokens_details??{accepted_prediction_tokens:0,reasoning_tokens:0,rejected_prediction_tokens:0}),prompt_tokens_details:yOe(s.prompt_tokens_details??{audio_tokens:0,cached_tokens:0},o.prompt_tokens_details??{audio_tokens:0,cached_tokens:0})}}const gBn={sum:pBn,sumCompletionTokenDetail:mOe,sumPromptTokenDetail:yOe};var Wbt={},wOe={},l$t={};Object.defineProperty(l$t,"__esModule",{value:!0});l$t.addMissingBraces=bBn;function bBn(s){const o={s:"OUT",stack:[],line:1,col:0,edits:[]},d=Array.from(s).reduce((C,O,L)=>{var H;const G=O===`
|
|
1453
1453
|
`?Object.assign(Object.assign({},C),{line:C.line+1,col:0}):Object.assign(Object.assign({},C),{col:C.col+1}),z=wBn(O),tt=(H=vBn[G.s])===null||H===void 0?void 0:H[z];return tt?tt(G,O,L):G},o);if(d.s!=="OUT")return s;const y=d.stack.length===0?d:(()=>{const C=d.stack.slice().reverse().map(O=>vOe[O.type]).join("");return Object.assign(Object.assign({},d),{edits:[...d.edits,{op:"insert",index:s.length,text:C}],stack:[]})})();return mBn(s,y.edits)}function mBn(s,o){const y=[...o].sort((C,O)=>C.index-O.index).reduce((C,O)=>{const L=s.slice(C.cursor,O.index),H={out:C.out+L,cursor:O.index};return O.op==="delete"?{out:H.out,cursor:H.cursor+1}:O.op==="replace"?{out:H.out+O.text,cursor:H.cursor+1}:{out:H.out+O.text,cursor:H.cursor}},{out:"",cursor:0});return y.out+s.slice(y.cursor)}const yBn=Object.freeze({"}":"{","]":"["}),vOe=Object.freeze({"{":"}","[":"]"}),wBn=s=>{switch(s){case'"':return"DQUOTE";case"\\":return"BSLASH";case"{":return"OCB";case"[":return"OSB";case"}":return"CCB";case"]":return"CSB";case`
|
|
1454
|
-
`:return"NEWLINE";default:return"CHAR"}},u9e=(s,o,d)=>Object.assign(Object.assign({},s),{stack:[...s.stack,{type:o,index:d}]}),l9e=(s,o)=>Object.assign(Object.assign({},s),{edits:[...s.edits,o]}),h9e=(s,o,d)=>(()=>{if(s.stack.length===0)return l9e(s,{op:"delete",index:d});const y=s.stack[s.stack.length-1];if(y!==void 0&&y.type!==yBn[o]){const C=vOe[y.type];return l9e(Object.assign(Object.assign({},s),{stack:s.stack.slice(0,-1)}),{op:"replace",index:d,text:C})}return Object.assign(Object.assign({},s),{stack:s.stack.slice(0,-1)})})(),vBn={OUT:{DQUOTE:s=>Object.assign(Object.assign({},s),{s:"IN"}),OCB:(s,o,d)=>u9e(s,"{",d),OSB:(s,o,d)=>u9e(s,"[",d),CCB:(s,o,d)=>h9e(s,"}",d),CSB:(s,o,d)=>h9e(s,"]",d)},IN:{BSLASH:s=>Object.assign(Object.assign({},s),{s:"ESC"}),DQUOTE:s=>Object.assign(Object.assign({},s),{s:"OUT"})},ESC:{DQUOTE:s=>Object.assign(Object.assign({},s),{s:"IN"}),BSLASH:s=>Object.assign(Object.assign({},s),{s:"IN"}),OCB:s=>Object.assign(Object.assign({},s),{s:"IN"}),OSB:s=>Object.assign(Object.assign({},s),{s:"IN"}),CCB:s=>Object.assign(Object.assign({},s),{s:"IN"}),CSB:s=>Object.assign(Object.assign({},s),{s:"IN"}),CHAR:s=>Object.assign(Object.assign({},s),{s:"IN"}),NEWLINE:s=>Object.assign(Object.assign({},s),{s:"IN"})}};var h$t={};Object.defineProperty(h$t,"__esModule",{value:!0});h$t.removeEmptyObjectPrefix=_Bn;function _Bn(s){return RegExp("^{}.").test(s)===!0?s.substring(2):s}var f$t={};Object.defineProperty(f$t,"__esModule",{value:!0});f$t.removeTrailingCommas=xBn;function xBn(s){const o=Array.from(s),d=z=>z==='"',y=z=>z==="\\",C=z=>/\s/.test(z),O=z=>z==="]"||z==="}",L=(z,tt)=>tt>=z.length||z[tt]===void 0?null:C(z[tt])||z[tt]===","?L(z,tt+1):z[tt],H={out:"",inString:!1,escaping:!1,skippingTrailingCommas:!1};return o.reduce((z,tt,et,nt)=>{if(z.inString){const st=z.out+tt;return y(tt)?Object.assign(Object.assign({},z),{out:st,escaping:!z.escaping}):d(tt)&&!z.escaping?Object.assign(Object.assign({},z),{out:st,inString:!1,escaping:!1}):Object.assign(Object.assign({},z),{out:st,escaping:!1})}if(z.skippingTrailingCommas){if(tt===",")return z;if(C(tt)){const st=L(nt,et+1);return O(st)?Object.assign(Object.assign({},z),{out:z.out+tt}):z}return O(tt)?Object.assign(Object.assign({},z),{out:z.out+tt,skippingTrailingCommas:!1}):Object.assign(Object.assign({},z),{out:z.out+tt,skippingTrailingCommas:!1})}if(d(tt))return Object.assign(Object.assign({},z),{out:z.out+tt,inString:!0,escaping:!1});if(tt===","){const st=L(nt,et+1);if(O(st))return Object.assign(Object.assign({},z),{skippingTrailingCommas:!0})}return Object.assign(Object.assign({},z),{out:z.out+tt})},H).out}(function(s){var o=N1&&N1.__createBinding||(Object.create?function(y,C,O,L){L===void 0&&(L=O);var H=Object.getOwnPropertyDescriptor(C,O);(!H||("get"in H?!C.__esModule:H.writable||H.configurable))&&(H={enumerable:!0,get:function(){return C[O]}}),Object.defineProperty(y,L,H)}:function(y,C,O,L){L===void 0&&(L=O),y[L]=C[O]}),d=N1&&N1.__exportStar||function(y,C){for(var O in y)O!=="default"&&!Object.prototype.hasOwnProperty.call(C,O)&&o(C,y,O)};Object.defineProperty(s,"__esModule",{value:!0}),d(l$t,s),d(h$t,s),d(f$t,s)})(wOe);(function(s){var o=N1&&N1.__createBinding||(Object.create?function(y,C,O,L){L===void 0&&(L=O);var H=Object.getOwnPropertyDescriptor(C,O);(!H||("get"in H?!C.__esModule:H.writable||H.configurable))&&(H={enumerable:!0,get:function(){return C[O]}}),Object.defineProperty(y,L,H)}:function(y,C,O,L){L===void 0&&(L=O),y[L]=C[O]}),d=N1&&N1.__exportStar||function(y,C){for(var O in y)O!=="default"&&!Object.prototype.hasOwnProperty.call(C,O)&&o(C,y,O)};Object.defineProperty(s,"__esModule",{value:!0}),d(wOe,s)})(Wbt);const a2t={parse:TBn},EBn=(...s)=>o=>s.reduce((d,y)=>y(d),o);function TBn(s){const o=EBn(Wbt.removeEmptyObjectPrefix,Wbt.addMissingBraces,Wbt.removeTrailingCommas)(s);return JSON.parse(o)}function kBn(s){const o=s instanceof Uint8Array?dFt.toUtf8(s):s;return a2t.parse(o)}function _Oe(s,o){const d=s.choices;o.choices.forEach(C=>{const O=d[C.index];if(O!=null){d[C.index]=xOe(O,C);return}d[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,H)=>{var G,z;return L[H.index]={id:H.id??"",type:"function",function:{name:((G=H.function)==null?void 0:G.name)??"",arguments:((z=H.function)==null?void 0:z.arguments)??""}},L},[]):void 0,content:C.delta.content??null,refusal:C.delta.refusal??null,role:"assistant",reasoning:C.delta.reasoning??null}}});const y=o.usage==null?s.usage:s.usage==null?o.usage:gBn.sum(s.usage,o.usage);return{...s,choices:d,usage:y}}function SBn(s){const o=s[0];if(o===void 0)throw new Error("No chunks received");const d=s.reduce(_Oe,{id:o.id,choices:[],created:o.created,model:o.model,object:"chat.completion",usage:void 0,service_tier:o.service_tier,system_fingerprint:o.system_fingerprint});return d.choices.forEach(y=>{var C;(C=y.message.tool_calls)==null||C.filter(O=>O.type==="function").forEach(O=>{O.function.arguments===""&&(O.function.arguments="{}")})}),d}function xOe(s,o){var d;if(s.finish_reason==null&&o.finish_reason!=null&&(s.finish_reason=o.finish_reason),s.logprobs==null&&o.logprobs!=null&&(s.logprobs=o.logprobs),o.delta.content!=null&&(s.message.content==null?s.message.content=o.delta.content:s.message.content+=o.delta.content),o.delta.refusal!=null&&(s.message.refusal==null?s.message.refusal=o.delta.refusal:s.message.refusal+=o.delta.refusal),o.delta.reasoning!=null&&(s.message.reasoning==null?s.message.reasoning=o.delta.reasoning:s.message.reasoning+=o.delta.reasoning),o.delta.tool_calls!=null){(d=s.message).tool_calls??(d.tool_calls=[]);const y=s.message.tool_calls;o.delta.tool_calls.forEach(C=>{var L,H;const O=y[C.index];if(O!=null&&O.type==="function"){y[C.index]=EOe(O,C);return}y[C.index]={id:C.id??"",type:"function",function:{name:((L=C.function)==null?void 0:L.name)??"",arguments:((H=C.function)==null?void 0:H.arguments)??""}}})}return s}function EOe(s,o){return o.function!=null&&o.type==="function"&&(s.function.arguments+=o.function.arguments??"",s.function.name+=o.function.name??""),s.id+=o.id??"",s}const dP={transformCompletionChunk:kBn,accumulate:_Oe,merge:SBn,mergeChoice:xOe,mergeToolCalls:EOe};class CBn extends Error{constructor(o){super(o),this.name="AsyncQueueClosedError"}}class ABn{constructor(){this.queue=[],this.resolvers=[],this.closeResolvers=[],this.emptyResolvers=[],this.closed=!1}enqueue(o){var d;if(this.closed){console.error(new CBn("Cannot enqueue item: queue is closed."));return}this.queue.push(o),this.resolvers.length>0&&((d=this.resolvers.shift())==null||d({value:this.queue.shift(),done:!1}))}async dequeue(){const o=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(d=>d()),this.emptyResolvers=[]),o!==null?o:new Promise(d=>this.resolvers.push(d))}isEmpty(){return this.queue.length===0}isClosed(){return this.closed}done(){return this.isClosed()&&this.isEmpty()}close(){var o;for(this.closed=!0;this.resolvers.length>0;)(o=this.resolvers.shift())==null||o({value:void 0,done:!0});this.closeResolvers.forEach(d=>d())}async waitUntilEmpty(){return this.isEmpty()?Promise.resolve():new Promise(o=>{this.emptyResolvers.push(o)})}async waitClosed(){return this.isClosed()?Promise.resolve():new Promise(o=>{this.closeResolvers.push(o)})}}class IBn{constructor(){this.queue=new ABn,this.consumer=new ReadableStream({start:async o=>{for(;;){const{value:d,done:y}=await this.queue.dequeue();if(y===!0){o.close();return}o.enqueue(d)}}})}produce(o){this.queue.enqueue(o)}close(){this.queue.close()}done(){return this.queue.done()}async waitClosed(){await this.queue.waitClosed()}async waitUntilEmpty(){await this.queue.waitUntilEmpty()}}async function OBn(s,o){const d=s.getReader(),y=[];for(;;){const{done:C,value:O}=await d.read();if(C||(o==null?void 0:o.aborted)===!0)break;y.push(O)}return y}async function NBn(s,o,d){var L;const y=s.getReader(),C=p$t(y);let O=d.initial??null;for await(const H of C){if(((L=d.abortSignal)==null?void 0:L.aborted)===!0)break;if(O===null){O=H;continue}O=o(O,H)}return O}function PBn(...s){return new ReadableStream({start:d=>{s.forEach(y=>d.enqueue(y)),d.close()}})}async function*d$t(s){yield s}async function*p$t(s,o){for(;;){const{done:d,value:y}=await s.read();if(d||(o==null?void 0:o.aborted)===!0)break;yield y}}function LBn(s,o,d){const y=s.getReader();return new ReadableStream({pull:async C=>{const{done:O,value:L}=await y.read();if(O===!0||(d==null?void 0:d.aborted)===!0){C.close();return}C.enqueue(o(L))}})}const XQ={readAll:OBn,reduce:NBn,from:PBn,transform:LBn};async function s2t(s,o,d){const y=new Map,C=await XQ.reduce(s,async(O,L)=>{const H=await O,G=z=>{for(const tt of z){if(tt.delta.content!=null&&tt.delta.content!=="")if(y.has(tt.index)){const et=y.get(tt.index);et.content+=tt.delta.content,et.mpsc.produce(tt.delta.content)}else{const et=new IBn;y.set(tt.index,{content:tt.delta.content,mpsc:et}),et.produce(tt.delta.content),o({stream:p$t(et.consumer.getReader()),done:()=>et.done(),get:()=>{var nt;return((nt=y.get(tt.index))==null?void 0:nt.content)??""},join:async()=>(await et.waitClosed(),y.get(tt.index).content)})}if(tt.finish_reason!=null){const et=y.get(tt.index);et!=null&&et.mpsc.close()}}};return H.object==="chat.completion.chunk"?(G([H,L].flatMap(z=>z.choices)),dP.merge([H,L])):(G(L.choices),dP.accumulate(H,L))},{abortSignal:d});if(C==null)throw new Error(`StreamUtil.reduce did not produce a ChatCompletion. Possible causes: the input stream was empty, invalid, or closed prematurely. To debug: check that the stream is properly initialized and contains valid ChatCompletionChunk data. You may also enable verbose logging upstream to inspect the stream contents. Stream locked: ${s.locked}.`);if(C.object==="chat.completion.chunk"){const O=dP.merge([C]);return O.choices.forEach(L=>{L.message.content!=null&&L.message.content!==""&&o({stream:d$t(L.message.content),done:()=>!0,get:()=>L.message.content,join:async()=>L.message.content})}),O}return C}function o2t(s){return{operation:s.operation,reason:s.reason,toJSON:()=>({operation:s.operation.toJSON(),reason:s.reason})}}function TOe(s,o){const d=s.stack.findIndex(O=>O.operation.name===o.name);if(d===-1)return;const y=s.stack[d];s.stack.splice(d,1);const C=WRn({selection:o2t({operation:y.operation,reason:o.reason})});s.dispatch(C).catch(()=>{})}async function MBn(s,o){var H;const d=bOe(1),C=await(async G=>d(G).catch(z=>{if(z instanceof VQ)return Symbol("emptyAssistantMessage");throw z}))(async G=>{var nt,st,at,Ot,Dt,Tt,ae;const z=await s.request("call",{messages:[{role:"system",content:c$.write(s.config)},...s.histories.map(s$).flat(),{role:"user",content:s.prompt.contents.map(o$)},...G instanceof Imt?[{role:"assistant",content:G.reasoning}]:[],...((st=(nt=s.config)==null?void 0:nt.systemPrompt)==null?void 0:st.execute)===null?[]:[{role:"system",content:((Dt=(Ot=(at=s.config)==null?void 0:at.systemPrompt)==null?void 0:Ot.execute)==null?void 0:Dt.call(Ot,s.histories))??I6.EXECUTE}]],tools:o.map(ee=>({type:"function",function:{name:ee.name,description:ee.function.description,parameters:"separated"in ee.function&&ee.function.separated!==void 0?ee.function.separated.llm??{type:"object",properties:{},required:[],additionalProperties:!1,$defs:{}}:ee.function.parameters}})),tool_choice:"auto"}),tt=await s2t(z,ee=>{const ge=GQ(ee);s.dispatch(ge).catch(()=>{})});if(tt.choices.every(ee=>ee.message.tool_calls==null&&ee.message.content==="")){const ee=tt.choices.at(0);throw((Tt=ee==null?void 0:ee.message)==null?void 0:Tt.reasoning)!=null?new Imt(((ae=ee==null?void 0:ee.message)==null?void 0:ae.reasoning)??""):new VQ}return tt});if(typeof C=="symbol"){const G=GQ({stream:d$t(""),done:()=>!0,get:()=>"",join:async()=>""});return s.dispatch(G).catch(()=>{}),[]}const O=[],L=((H=s.config)==null?void 0:H.retry)??yk.RETRY;for(const G of C.choices)for(const z of G.message.tool_calls??[])if(z.type==="function"){const tt=o.find(nt=>nt.name===z.function.name);if(tt===void 0)continue;const et=await kOe(s,tt,z,[],L);await s.dispatch(et),O.push(et),dBn(s)&&TOe(s,{name:et.operation.name,reason:"completed"})}return O}async function kOe(s,o,d,y,C){const O=BBn(o,d,C);if(await s.dispatch(O),O.type==="jsonParseError")return DBn(s,d,O,y,C-1);const L=o.function.validate(O.arguments);if(L.success===!1){const H=YRn({call_id:d.id,operation:o,result:L,life:C});return await s.dispatch(H),RBn(s,O,H,[...y,H],C-1)}return FBn(O,o)}async function RBn(s,o,d,y,C){var O,L,H;return SOe(s,{giveUp:()=>Emt({call_id:o.id,operation:o.operation,arguments:o.arguments,value:{name:"ValidationError",message:`Invalid arguments. The validation failed after ${yk.RETRY} retries.`,errors:d.result.errors},success:!1}),operation:o.operation,toolCall:{id:o.id,arguments:JSON.stringify(o.arguments),result:JSON.stringify(d.result.errors)},systemPrompt:((H=(L=(O=s.config)==null?void 0:O.systemPrompt)==null?void 0:L.validate)==null?void 0:H.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(`
|
|
1454
|
+
`:return"NEWLINE";default:return"CHAR"}},u9e=(s,o,d)=>Object.assign(Object.assign({},s),{stack:[...s.stack,{type:o,index:d}]}),l9e=(s,o)=>Object.assign(Object.assign({},s),{edits:[...s.edits,o]}),h9e=(s,o,d)=>(()=>{if(s.stack.length===0)return l9e(s,{op:"delete",index:d});const y=s.stack[s.stack.length-1];if(y!==void 0&&y.type!==yBn[o]){const C=vOe[y.type];return l9e(Object.assign(Object.assign({},s),{stack:s.stack.slice(0,-1)}),{op:"replace",index:d,text:C})}return Object.assign(Object.assign({},s),{stack:s.stack.slice(0,-1)})})(),vBn={OUT:{DQUOTE:s=>Object.assign(Object.assign({},s),{s:"IN"}),OCB:(s,o,d)=>u9e(s,"{",d),OSB:(s,o,d)=>u9e(s,"[",d),CCB:(s,o,d)=>h9e(s,"}",d),CSB:(s,o,d)=>h9e(s,"]",d)},IN:{BSLASH:s=>Object.assign(Object.assign({},s),{s:"ESC"}),DQUOTE:s=>Object.assign(Object.assign({},s),{s:"OUT"})},ESC:{DQUOTE:s=>Object.assign(Object.assign({},s),{s:"IN"}),BSLASH:s=>Object.assign(Object.assign({},s),{s:"IN"}),OCB:s=>Object.assign(Object.assign({},s),{s:"IN"}),OSB:s=>Object.assign(Object.assign({},s),{s:"IN"}),CCB:s=>Object.assign(Object.assign({},s),{s:"IN"}),CSB:s=>Object.assign(Object.assign({},s),{s:"IN"}),CHAR:s=>Object.assign(Object.assign({},s),{s:"IN"}),NEWLINE:s=>Object.assign(Object.assign({},s),{s:"IN"})}};var h$t={};Object.defineProperty(h$t,"__esModule",{value:!0});h$t.removeEmptyObjectPrefix=_Bn;function _Bn(s){return RegExp("^{}.").test(s)===!0?s.substring(2):s}var f$t={};Object.defineProperty(f$t,"__esModule",{value:!0});f$t.removeTrailingCommas=xBn;function xBn(s){const o=Array.from(s),d=z=>z==='"',y=z=>z==="\\",C=z=>/\s/.test(z),O=z=>z==="]"||z==="}",L=(z,tt)=>tt>=z.length||z[tt]===void 0?null:C(z[tt])||z[tt]===","?L(z,tt+1):z[tt],H={out:"",inString:!1,escaping:!1,skippingTrailingCommas:!1};return o.reduce((z,tt,et,nt)=>{if(z.inString){const st=z.out+tt;return y(tt)?Object.assign(Object.assign({},z),{out:st,escaping:!z.escaping}):d(tt)&&!z.escaping?Object.assign(Object.assign({},z),{out:st,inString:!1,escaping:!1}):Object.assign(Object.assign({},z),{out:st,escaping:!1})}if(z.skippingTrailingCommas){if(tt===",")return z;if(C(tt)){const st=L(nt,et+1);return O(st)?Object.assign(Object.assign({},z),{out:z.out+tt}):z}return O(tt)?Object.assign(Object.assign({},z),{out:z.out+tt,skippingTrailingCommas:!1}):Object.assign(Object.assign({},z),{out:z.out+tt,skippingTrailingCommas:!1})}if(d(tt))return Object.assign(Object.assign({},z),{out:z.out+tt,inString:!0,escaping:!1});if(tt===","){const st=L(nt,et+1);if(O(st))return Object.assign(Object.assign({},z),{skippingTrailingCommas:!0})}return Object.assign(Object.assign({},z),{out:z.out+tt})},H).out}(function(s){var o=N1&&N1.__createBinding||(Object.create?function(y,C,O,L){L===void 0&&(L=O);var H=Object.getOwnPropertyDescriptor(C,O);(!H||("get"in H?!C.__esModule:H.writable||H.configurable))&&(H={enumerable:!0,get:function(){return C[O]}}),Object.defineProperty(y,L,H)}:function(y,C,O,L){L===void 0&&(L=O),y[L]=C[O]}),d=N1&&N1.__exportStar||function(y,C){for(var O in y)O!=="default"&&!Object.prototype.hasOwnProperty.call(C,O)&&o(C,y,O)};Object.defineProperty(s,"__esModule",{value:!0}),d(l$t,s),d(h$t,s),d(f$t,s)})(wOe);(function(s){var o=N1&&N1.__createBinding||(Object.create?function(y,C,O,L){L===void 0&&(L=O);var H=Object.getOwnPropertyDescriptor(C,O);(!H||("get"in H?!C.__esModule:H.writable||H.configurable))&&(H={enumerable:!0,get:function(){return C[O]}}),Object.defineProperty(y,L,H)}:function(y,C,O,L){L===void 0&&(L=O),y[L]=C[O]}),d=N1&&N1.__exportStar||function(y,C){for(var O in y)O!=="default"&&!Object.prototype.hasOwnProperty.call(C,O)&&o(C,y,O)};Object.defineProperty(s,"__esModule",{value:!0}),d(wOe,s)})(Wbt);const a2t={parse:TBn},EBn=(...s)=>o=>s.reduce((d,y)=>y(d),o);function TBn(s){const o=EBn(Wbt.removeEmptyObjectPrefix,Wbt.addMissingBraces,Wbt.removeTrailingCommas)(s);return JSON.parse(o)}function kBn(s){const o=s instanceof Uint8Array?dFt.toUtf8(s):s;return a2t.parse(o)}function _Oe(s,o){const d=s.choices;o.choices.forEach(C=>{const O=d[C.index];if(O!=null){d[C.index]=xOe(O,C);return}d[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,H)=>{var G,z;return L[H.index]={id:H.id??"",type:"function",function:{name:((G=H.function)==null?void 0:G.name)??"",arguments:((z=H.function)==null?void 0:z.arguments)??""}},L},[]):void 0,content:C.delta.content??null,refusal:C.delta.refusal??null,role:"assistant",reasoning:C.delta.reasoning??null}}});const y=o.usage==null?s.usage:s.usage==null?o.usage:gBn.sum(s.usage,o.usage);return{...s,choices:d,usage:y}}function SBn(s){const o=s[0];if(o===void 0)throw new Error("No chunks received");const d=s.reduce(_Oe,{id:o.id,choices:[],created:o.created,model:o.model,object:"chat.completion",usage:void 0,service_tier:o.service_tier,system_fingerprint:o.system_fingerprint});return d.choices.forEach(y=>{var C;(C=y.message.tool_calls)==null||C.filter(O=>O.type==="function").forEach(O=>{O.function.arguments===""&&(O.function.arguments="{}")})}),d}function xOe(s,o){var d;if(s.finish_reason==null&&o.finish_reason!=null&&(s.finish_reason=o.finish_reason),s.logprobs==null&&o.logprobs!=null&&(s.logprobs=o.logprobs),o.delta.content!=null&&(s.message.content==null?s.message.content=o.delta.content:s.message.content+=o.delta.content),o.delta.refusal!=null&&(s.message.refusal==null?s.message.refusal=o.delta.refusal:s.message.refusal+=o.delta.refusal),o.delta.reasoning!=null&&(s.message.reasoning==null?s.message.reasoning=o.delta.reasoning:s.message.reasoning+=o.delta.reasoning),o.delta.tool_calls!=null){(d=s.message).tool_calls??(d.tool_calls=[]);const y=s.message.tool_calls;o.delta.tool_calls.forEach(C=>{var L,H;const O=y[C.index];if(O!=null&&O.type==="function"){y[C.index]=EOe(O,C);return}y[C.index]={id:C.id??"",type:"function",function:{name:((L=C.function)==null?void 0:L.name)??"",arguments:((H=C.function)==null?void 0:H.arguments)??""}}})}return s}function EOe(s,o){return o.function!=null&&(s.function.arguments+=o.function.arguments??"",s.function.name+=o.function.name??""),s.id+=o.id??"",s}const dP={transformCompletionChunk:kBn,accumulate:_Oe,merge:SBn,mergeChoice:xOe,mergeToolCalls:EOe};class CBn extends Error{constructor(o){super(o),this.name="AsyncQueueClosedError"}}class ABn{constructor(){this.queue=[],this.resolvers=[],this.closeResolvers=[],this.emptyResolvers=[],this.closed=!1}enqueue(o){var d;if(this.closed){console.error(new CBn("Cannot enqueue item: queue is closed."));return}this.queue.push(o),this.resolvers.length>0&&((d=this.resolvers.shift())==null||d({value:this.queue.shift(),done:!1}))}async dequeue(){const o=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(d=>d()),this.emptyResolvers=[]),o!==null?o:new Promise(d=>this.resolvers.push(d))}isEmpty(){return this.queue.length===0}isClosed(){return this.closed}done(){return this.isClosed()&&this.isEmpty()}close(){var o;for(this.closed=!0;this.resolvers.length>0;)(o=this.resolvers.shift())==null||o({value:void 0,done:!0});this.closeResolvers.forEach(d=>d())}async waitUntilEmpty(){return this.isEmpty()?Promise.resolve():new Promise(o=>{this.emptyResolvers.push(o)})}async waitClosed(){return this.isClosed()?Promise.resolve():new Promise(o=>{this.closeResolvers.push(o)})}}class IBn{constructor(){this.queue=new ABn,this.consumer=new ReadableStream({start:async o=>{for(;;){const{value:d,done:y}=await this.queue.dequeue();if(y===!0){o.close();return}o.enqueue(d)}}})}produce(o){this.queue.enqueue(o)}close(){this.queue.close()}done(){return this.queue.done()}async waitClosed(){await this.queue.waitClosed()}async waitUntilEmpty(){await this.queue.waitUntilEmpty()}}async function OBn(s,o){const d=s.getReader(),y=[];for(;;){const{done:C,value:O}=await d.read();if(C||(o==null?void 0:o.aborted)===!0)break;y.push(O)}return y}async function NBn(s,o,d){var L;const y=s.getReader(),C=p$t(y);let O=d.initial??null;for await(const H of C){if(((L=d.abortSignal)==null?void 0:L.aborted)===!0)break;if(O===null){O=H;continue}O=o(O,H)}return O}function PBn(...s){return new ReadableStream({start:d=>{s.forEach(y=>d.enqueue(y)),d.close()}})}async function*d$t(s){yield s}async function*p$t(s,o){for(;;){const{done:d,value:y}=await s.read();if(d||(o==null?void 0:o.aborted)===!0)break;yield y}}function LBn(s,o,d){const y=s.getReader();return new ReadableStream({pull:async C=>{const{done:O,value:L}=await y.read();if(O===!0||(d==null?void 0:d.aborted)===!0){C.close();return}C.enqueue(o(L))}})}const XQ={readAll:OBn,reduce:NBn,from:PBn,transform:LBn};async function s2t(s,o,d){const y=new Map,C=await XQ.reduce(s,async(O,L)=>{const H=await O,G=z=>{for(const tt of z){if(tt.delta.content!=null&&tt.delta.content!=="")if(y.has(tt.index)){const et=y.get(tt.index);et.content+=tt.delta.content,et.mpsc.produce(tt.delta.content)}else{const et=new IBn;y.set(tt.index,{content:tt.delta.content,mpsc:et}),et.produce(tt.delta.content),o({stream:p$t(et.consumer.getReader()),done:()=>et.done(),get:()=>{var nt;return((nt=y.get(tt.index))==null?void 0:nt.content)??""},join:async()=>(await et.waitClosed(),y.get(tt.index).content)})}if(tt.finish_reason!=null){const et=y.get(tt.index);et!=null&&et.mpsc.close()}}};return H.object==="chat.completion.chunk"?(G([H,L].flatMap(z=>z.choices)),dP.merge([H,L])):(G(L.choices),dP.accumulate(H,L))},{abortSignal:d});if(C==null)throw new Error(`StreamUtil.reduce did not produce a ChatCompletion. Possible causes: the input stream was empty, invalid, or closed prematurely. To debug: check that the stream is properly initialized and contains valid ChatCompletionChunk data. You may also enable verbose logging upstream to inspect the stream contents. Stream locked: ${s.locked}.`);if(C.object==="chat.completion.chunk"){const O=dP.merge([C]);return O.choices.forEach(L=>{L.message.content!=null&&L.message.content!==""&&o({stream:d$t(L.message.content),done:()=>!0,get:()=>L.message.content,join:async()=>L.message.content})}),O}return C}function o2t(s){return{operation:s.operation,reason:s.reason,toJSON:()=>({operation:s.operation.toJSON(),reason:s.reason})}}function TOe(s,o){const d=s.stack.findIndex(O=>O.operation.name===o.name);if(d===-1)return;const y=s.stack[d];s.stack.splice(d,1);const C=WRn({selection:o2t({operation:y.operation,reason:o.reason})});s.dispatch(C).catch(()=>{})}async function MBn(s,o){var H;const d=bOe(1),C=await(async G=>d(G).catch(z=>{if(z instanceof VQ)return Symbol("emptyAssistantMessage");throw z}))(async G=>{var nt,st,at,Ot,Dt,Tt,ae;const z=await s.request("call",{messages:[{role:"system",content:c$.write(s.config)},...s.histories.map(s$).flat(),{role:"user",content:s.prompt.contents.map(o$)},...G instanceof Imt?[{role:"assistant",content:G.reasoning}]:[],...((st=(nt=s.config)==null?void 0:nt.systemPrompt)==null?void 0:st.execute)===null?[]:[{role:"system",content:((Dt=(Ot=(at=s.config)==null?void 0:at.systemPrompt)==null?void 0:Ot.execute)==null?void 0:Dt.call(Ot,s.histories))??I6.EXECUTE}]],tools:o.map(ee=>({type:"function",function:{name:ee.name,description:ee.function.description,parameters:"separated"in ee.function&&ee.function.separated!==void 0?ee.function.separated.llm??{type:"object",properties:{},required:[],additionalProperties:!1,$defs:{}}:ee.function.parameters}})),tool_choice:"auto"}),tt=await s2t(z,ee=>{const ge=GQ(ee);s.dispatch(ge).catch(()=>{})});if(tt.choices.every(ee=>ee.message.tool_calls==null&&ee.message.content==="")){const ee=tt.choices.at(0);throw((Tt=ee==null?void 0:ee.message)==null?void 0:Tt.reasoning)!=null?new Imt(((ae=ee==null?void 0:ee.message)==null?void 0:ae.reasoning)??""):new VQ}return tt});if(typeof C=="symbol"){const G=GQ({stream:d$t(""),done:()=>!0,get:()=>"",join:async()=>""});return s.dispatch(G).catch(()=>{}),[]}const O=[],L=((H=s.config)==null?void 0:H.retry)??yk.RETRY;for(const G of C.choices)for(const z of G.message.tool_calls??[])if(z.type==="function"){const tt=o.find(nt=>nt.name===z.function.name);if(tt===void 0)continue;const et=await kOe(s,tt,z,[],L);await s.dispatch(et),O.push(et),dBn(s)&&TOe(s,{name:et.operation.name,reason:"completed"})}return O}async function kOe(s,o,d,y,C){const O=BBn(o,d,C);if(await s.dispatch(O),O.type==="jsonParseError")return DBn(s,d,O,y,C-1);const L=o.function.validate(O.arguments);if(L.success===!1){const H=YRn({call_id:d.id,operation:o,result:L,life:C});return await s.dispatch(H),RBn(s,O,H,[...y,H],C-1)}return FBn(O,o)}async function RBn(s,o,d,y,C){var O,L,H;return SOe(s,{giveUp:()=>Emt({call_id:o.id,operation:o.operation,arguments:o.arguments,value:{name:"ValidationError",message:`Invalid arguments. The validation failed after ${yk.RETRY} retries.`,errors:d.result.errors},success:!1}),operation:o.operation,toolCall:{id:o.id,arguments:JSON.stringify(o.arguments),result:JSON.stringify(d.result.errors)},systemPrompt:((H=(L=(O=s.config)==null?void 0:O.systemPrompt)==null?void 0:L.validate)==null?void 0:H.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(`
|
|
1455
1455
|
`),life:C,previousValidationErrors:y})}async function DBn(s,o,d,y,C){var O,L,H;return SOe(s,{giveUp:()=>Emt({call_id:o.id,operation:d.operation,arguments:{},value:{name:"JsonParseError",message:`Invalid JSON format. The parsing failed after ${yk.RETRY} retries.`,arguments:d.arguments,errorMessage:d.errorMessage},success:!1}),operation:d.operation,toolCall:{id:d.id,arguments:d.arguments,result:d.errorMessage},systemPrompt:((H=(L=(O=s.config)==null?void 0:O.systemPrompt)==null?void 0:L.jsonParseError)==null?void 0:H.call(L,d))??I6.JSON_PARSE_ERROR.replace("${{ERROR_MESSAGE}}",d.errorMessage),life:C,previousValidationErrors:y})}function BBn(s,o,d){try{const y=a2t.parse(o.function.arguments);return KRn({id:o.id,operation:s,arguments:y})}catch(y){return GRn({call_id:o.id,operation:s,arguments:o.function.arguments,errorMessage:y instanceof Error?y.message:String(y),life:d})}}async function SOe(s,o){var L,H,G,z,tt,et;if(o.life<=0)return o.giveUp();const d=await s.request("call",{messages:[{role:"system",content:c$.write(s.config)},...s.histories.map(s$).flat(),{role:"user",content:s.prompt.contents.map(o$)},{role:"system",content:((G=(H=(L=s.config)==null?void 0:L.systemPrompt)==null?void 0:H.execute)==null?void 0:G.call(H,s.histories))??I6.EXECUTE},{role:"assistant",tool_calls:[{type:"function",id:o.toolCall.id,function:{name:o.operation.name,arguments:o.toolCall.arguments}}]},{role:"tool",content:o.toolCall.result,tool_call_id:o.toolCall.id},{role:"system",content:o.systemPrompt}],tools:[{type:"function",function:{name:o.operation.name,description:o.operation.function.description,parameters:"separated"in o.operation.function&&o.operation.function.separated!==void 0?((z=o.operation.function.separated)==null?void 0:z.llm)??{$defs:{},type:"object",properties:{},additionalProperties:!1,required:[]}:o.operation.function.parameters}}],tool_choice:"required"}),y=await XQ.readAll(d),O=(et=(tt=dP.merge(y).choices[0])==null?void 0:tt.message.tool_calls)==null?void 0:et.filter(nt=>nt.type==="function").find(nt=>nt.function.name===o.operation.name);return O===void 0?o.giveUp():kOe(s,o.operation,O,o.previousValidationErrors,o.life)}async function FBn(s,o){try{const d=await(async()=>{switch(o.protocol){case"class":return $Bn(s,o);case"http":return jBn(s,o);case"mcp":return HBn(s,o);default:throw new Error("Unknown protocol")}})();return Emt({call_id:s.id,operation:s.operation,arguments:s.arguments,value:d,success:!0})}catch(d){return Emt({call_id:s.id,operation:s.operation,arguments:s.arguments,value:d instanceof Error?{...d,name:d.name,message:d.message}:d,success:!1})}}async function $Bn(s,o){const d=o.controller.execute;return typeof d=="function"?await d({application:o.controller.application,function:o.function,arguments:s.arguments}):await d[o.function.name](s.arguments)}async function jBn(s,o){const d=o.controller.execute;return typeof d=="function"?await d({connection:o.controller.connection,application:o.controller.application,function:o.function,arguments:s.arguments}):await fFt.propagate({connection:o.controller.connection,application:o.controller.application,function:o.function,input:s.arguments})}async function HBn(s,o){return o.controller.client.callTool({method:o.function.name,name:o.function.name,arguments:s.arguments}).then(d=>d.content)}var g$t={};Object.defineProperty(g$t,"__esModule",{value:!0});var u$=g$t._validateReport=void 0;const zBn=s=>{const o=d=>{if(s.length===0)return!0;const y=s[s.length-1].path;return d.length>y.length||y.substring(0,d.length)!==d};return(d,y)=>{var C;return d&&o(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(`
|
|
1456
1456
|
`))),s.push(y)),!1}};u$=g$t._validateReport=zBn;const rBt={functions:[{name:"cancelFunctions",parameters:{description:` Properties of the function
|
|
1457
1457
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as m,o as C,r as b,T as g}from"../client-B3aq8qpT.js";import{q as w,t as T,r as v,s as j,w as x,x as _,y as P,z as R,E as U,v as $,d as k,_ as y,V as A,c as F,F as M,T as q,B as S}from"../VendorConfigurationMovie-
|
|
1
|
+
import{j as m,o as C,r as b,T as g}from"../client-B3aq8qpT.js";import{q as w,t as T,r as v,s as j,w as x,x as _,y as P,z as R,E as U,v as $,d as k,_ as y,V as A,c as F,F as M,T as q,B as S}from"../VendorConfigurationMovie-A-2G3I__.js";import{a as u,_ as p}from"../_isFormatUri-YqTfGpHo.js";import{D}from"../Divider-DX1xhf0M.js";class I{constructor(o){this.props=o,this.operations_=w.compose({controllers:o.controllers,config:o.config}),this.histories_=(o.histories??[]).map(d=>T({operations:this.operations_.group,history:d})),this.token_usage_=this.props.tokenUsage!==void 0?this.props.tokenUsage instanceof v?this.props.tokenUsage:new v(this.props.tokenUsage):v.zero(),this.listeners_=new Map,this.semaphore_=o.vendor.semaphore!=null?typeof o.vendor.semaphore=="object"?o.vendor.semaphore:new j(o.vendor.semaphore):null}clone(){var o;return new I({...this.props,histories:(o=this.props.histories)==null?void 0:o.slice()})}async conversate(o,d={}){var i,n,h,B;const s=[],l=async f=>{try{await this.dispatch(f),"toHistory"in f&&("join"in f?s.push(async()=>(await f.join(),f.toHistory())):s.push(async()=>f.toHistory()))}catch{}},a=x({contents:Array.isArray(o)?o:typeof o=="string"?[{type:"text",text:o}]:[o]});l(a).catch(()=>{});const r=this.getContext({prompt:a,dispatch:l,usage:this.token_usage_,abortSignal:d.abortSignal}),e=await _(r,this.operations_.array);e.length&&((n=(i=this.props.config)==null?void 0:i.executor)==null?void 0:n.describe)!==null&&((B=(h=this.props.config)==null?void 0:h.executor)==null?void 0:B.describe)!==!1&&await P(r,e);const t=await Promise.all(s.map(async f=>f()));return this.histories_.push(...t),t}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=R({vendor:this.props.vendor,config:this.props.config,dispatch:o.dispatch,abortSignal:o.abortSignal,usage:this.token_usage_});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 U(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 L{constructor(){this.articles=[]}index(){return this.articles}create(o){const d={id:$(),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 O={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.
|