@tangle-network/sandbox 0.9.2 → 0.9.3-develop.20260627012805.bf68a85
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/agent/index.d.ts +2 -2
- package/dist/agent/index.js +1026 -1
- package/dist/auth/index.js +273 -1
- package/dist/{client-D3FqPlde.d.ts → client-BBb2p7y5.d.ts} +1 -1
- package/dist/client-CjqJUa22.js +2193 -0
- package/dist/collaboration/index.js +2 -1
- package/dist/collaboration-BxlfZ2Uh.js +201 -1
- package/dist/core.d.ts +2 -2
- package/dist/core.js +4 -1
- package/dist/errors-DZsfJUuc.js +262 -1
- package/dist/{index-Dy1fHLYz.d.ts → index-BY1_6xI7.d.ts} +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1180 -1
- package/dist/intelligence/index.js +225 -1
- package/dist/openai/index.js +1760 -1
- package/dist/{sandbox-B55j2q9K.d.ts → sandbox-BQQ2jhV3.d.ts} +14 -26
- package/dist/sandbox-FcVsLeUJ.js +4500 -0
- package/dist/session-gateway/index.js +667 -1
- package/dist/tangle/index.d.ts +1 -1
- package/dist/tangle/index.js +2 -1
- package/dist/tangle-DvdKAK94.js +831 -0
- package/package.json +4 -4
- package/dist/client-BBZ7YLmq.js +0 -1
- package/dist/sandbox-joKtQ5y3.js +0 -1
- package/dist/tangle-DM0o66lW.js +0 -1
package/dist/openai/index.js
CHANGED
|
@@ -1 +1,1760 @@
|
|
|
1
|
-
const a0_0x5cfbcf=a0_0x19c9;(function(_0x55d1cf,_0x20954f){const _0x3bfbfe=a0_0x19c9,_0x9ee117=_0x55d1cf();while(!![]){try{const _0x27cd3d=parseInt(_0x3bfbfe(0x266))/0x1*(-parseInt(_0x3bfbfe(0x1ff))/0x2)+parseInt(_0x3bfbfe(0x39b))/0x3*(-parseInt(_0x3bfbfe(0x3a6))/0x4)+parseInt(_0x3bfbfe(0x393))/0x5+-parseInt(_0x3bfbfe(0x303))/0x6+-parseInt(_0x3bfbfe(0x36c))/0x7*(parseInt(_0x3bfbfe(0x2be))/0x8)+-parseInt(_0x3bfbfe(0x287))/0x9*(parseInt(_0x3bfbfe(0x210))/0xa)+parseInt(_0x3bfbfe(0x253))/0xb*(parseInt(_0x3bfbfe(0x340))/0xc);if(_0x27cd3d===_0x20954f)break;else _0x9ee117['push'](_0x9ee117['shift']());}catch(_0x108ead){_0x9ee117['push'](_0x9ee117['shift']());}}}(a0_0x3325,0x2b096));var HookChain=class{[a0_0x5cfbcf(0x341)];constructor(_0x158c71=[]){const _0x4b3868=a0_0x5cfbcf;this[_0x4b3868(0x341)]=_0x158c71;}get[a0_0x5cfbcf(0x220)](){const _0x585328=a0_0x5cfbcf;return this['\x68\x6f\x6f\x6b\x73'][_0x585328(0x2a8)];}async[a0_0x5cfbcf(0x252)](_0x3c0d4f){const _0x36cc11=a0_0x5cfbcf,_0x1644b6={'\x48\x73\x59\x6a\x75':function(_0x4aa5e2,_0x5bd1a1){return _0x4aa5e2===_0x5bd1a1;},'\x6c\x47\x72\x53\x42':'\x62\x6c\x6f\x63\x6b','\x43\x7a\x73\x47\x74':'\x72\x65\x77\x72\x69\x74\x65','\x4f\x6d\x68\x4f\x4f':function(_0x43a344,_0x4b31e8){return _0x43a344??_0x4b31e8;},'\x67\x52\x4c\x56\x44':_0x36cc11(0x21c)};let _0x4097e8=_0x3c0d4f,_0x508266=null;for(const _0x52b13c of this[_0x36cc11(0x341)]){if(!_0x52b13c['\x62\x65\x66\x6f\x72\x65\x54\x6f\x6f\x6c\x43\x61\x6c\x6c'])continue;const _0x30b16d=await _0x52b13c[_0x36cc11(0x209)](_0x4097e8);if(_0x1644b6[_0x36cc11(0x387)](_0x30b16d['\x61\x63\x74\x69\x6f\x6e'],_0x1644b6[_0x36cc11(0x35a)]))return _0x30b16d;_0x30b16d[_0x36cc11(0x330)]===_0x1644b6[_0x36cc11(0x35b)]&&(_0x4097e8={..._0x4097e8,'\x61\x72\x67\x73':_0x30b16d[_0x36cc11(0x32f)]},_0x508266=_0x30b16d);}return _0x1644b6[_0x36cc11(0x2bb)](_0x508266,{'\x61\x63\x74\x69\x6f\x6e':_0x1644b6[_0x36cc11(0x31b)]});}async['\x72\x75\x6e\x41\x66\x74\x65\x72'](_0x13e8ea,_0x243b44){const _0x3a7366=a0_0x5cfbcf,_0x5a44f0={'\x4c\x57\x44\x69\x42':function(_0x200b2d,_0x36aa7b){return _0x200b2d===_0x36aa7b;},'\x4e\x4e\x69\x59\x53':'\x6f\x76\x65\x72\x72\x69\x64\x65'};let _0x393615=_0x243b44,_0x2d7135=null;for(const _0x21184f of this['\x68\x6f\x6f\x6b\x73']){if(!_0x21184f[_0x3a7366(0x33a)])continue;const _0x4536de=await _0x21184f[_0x3a7366(0x33a)](_0x13e8ea,_0x393615);if(_0x5a44f0[_0x3a7366(0x2b9)](_0x4536de['\x61\x63\x74\x69\x6f\x6e'],'\x74\x65\x72\x6d\x69\x6e\x61\x74\x65'))return _0x4536de;_0x4536de[_0x3a7366(0x330)]===_0x5a44f0[_0x3a7366(0x1fa)]&&(_0x393615=_0x4536de[_0x3a7366(0x2d4)],_0x2d7135=_0x4536de);}return _0x2d7135??{'\x61\x63\x74\x69\x6f\x6e':_0x3a7366(0x223)};}};function auditLogHook(_0x25c446={}){const _0x3ea4a2=a0_0x5cfbcf,_0x3d7b0a={'\x48\x6d\x47\x77\x6b':_0x3ea4a2(0x3c3),'\x5a\x7a\x4c\x49\x77':_0x3ea4a2(0x223)},_0x55421d=_0x25c446[_0x3ea4a2(0x1e6)]??(_0xb97e1c=>{const _0x20f859=_0x3ea4a2;console[_0x20f859(0x216)](_0x20f859(0x37e),_0xb97e1c);});return{async '\x62\x65\x66\x6f\x72\x65\x54\x6f\x6f\x6c\x43\x61\x6c\x6c'(_0x4629dc){const _0xbbdb7c=_0x3ea4a2;return await _0x55421d({'\x70\x68\x61\x73\x65':_0x3d7b0a[_0xbbdb7c(0x32a)],'\x72\x75\x6e\x49\x64':_0x4629dc[_0xbbdb7c(0x37c)],'\x74\x68\x72\x65\x61\x64\x49\x64':_0x4629dc[_0xbbdb7c(0x21e)],'\x70\x61\x72\x74\x6e\x65\x72\x49\x64':_0x4629dc['\x70\x61\x72\x74\x6e\x65\x72\x49\x64'],'\x74\x6f\x6f\x6c\x4e\x61\x6d\x65':_0x4629dc[_0xbbdb7c(0x351)],'\x63\x61\x6c\x6c\x49\x64':_0x4629dc['\x63\x61\x6c\x6c\x49\x64'],'\x74\x69\x6d\x65\x73\x74\x61\x6d\x70':_0x4629dc[_0xbbdb7c(0x34e)],'\x61\x72\x67\x73':_0x4629dc[_0xbbdb7c(0x32f)]}),{'\x61\x63\x74\x69\x6f\x6e':_0xbbdb7c(0x21c)};},async '\x61\x66\x74\x65\x72\x54\x6f\x6f\x6c\x43\x61\x6c\x6c'(_0x44ee5f,_0x1c0c52){const _0x1c8d29=_0x3ea4a2;return await _0x55421d({'\x70\x68\x61\x73\x65':_0x1c8d29(0x29e),'\x72\x75\x6e\x49\x64':_0x44ee5f[_0x1c8d29(0x37c)],'\x74\x68\x72\x65\x61\x64\x49\x64':_0x44ee5f['\x74\x68\x72\x65\x61\x64\x49\x64'],'\x70\x61\x72\x74\x6e\x65\x72\x49\x64':_0x44ee5f[_0x1c8d29(0x34c)],'\x74\x6f\x6f\x6c\x4e\x61\x6d\x65':_0x44ee5f[_0x1c8d29(0x351)],'\x63\x61\x6c\x6c\x49\x64':_0x44ee5f[_0x1c8d29(0x273)],'\x74\x69\x6d\x65\x73\x74\x61\x6d\x70':_0x44ee5f[_0x1c8d29(0x34e)],'\x72\x65\x73\x75\x6c\x74':_0x1c0c52}),{'\x61\x63\x74\x69\x6f\x6e':_0x3d7b0a[_0x1c8d29(0x25e)]};}};}const NETWORK_TOOL_REGEX=/^(fetch|http|https|browser|playwright|curl|wget|computer-use:click|computer-use:type)/i,URL_FIELD_NAMES=new Set([a0_0x5cfbcf(0x24e),'\x75\x72\x69','\x65\x6e\x64\x70\x6f\x69\x6e\x74',a0_0x5cfbcf(0x211),a0_0x5cfbcf(0x369),a0_0x5cfbcf(0x2c4),a0_0x5cfbcf(0x23e)]);function extractUrlsFromArgs(_0x5d0698){const _0x3fd99c={'\x43\x49\x47\x6b\x6e':function(_0x15ec14,_0x459f91){return _0x15ec14!==_0x459f91;},'\x5a\x4b\x42\x79\x45':function(_0x4c45f5,_0x2ed99c){return _0x4c45f5===_0x2ed99c;},'\x58\x6a\x6b\x51\x44':'\x73\x74\x72\x69\x6e\x67'},_0x10f7d8=[],_0x9728f6=_0x3add88=>{const _0x2e6f20=a0_0x19c9;if(typeof _0x3add88===_0x2e6f20(0x2c6)){if(/^https?:\/\//i[_0x2e6f20(0x26f)](_0x3add88))try{const _0x2e7459=new URL(_0x3add88);_0x10f7d8[_0x2e6f20(0x376)]({'\x72\x61\x77':_0x3add88,'\x68\x6f\x73\x74':_0x2e7459[_0x2e6f20(0x1fd)]});}catch{_0x10f7d8[_0x2e6f20(0x376)]({'\x72\x61\x77':_0x3add88,'\x68\x6f\x73\x74':null});}return;}if(_0x3add88===null||_0x3fd99c[_0x2e6f20(0x383)](typeof _0x3add88,_0x2e6f20(0x256)))return;if(Array[_0x2e6f20(0x24f)](_0x3add88)){for(const _0x3e163c of _0x3add88)_0x9728f6(_0x3e163c);return;}for(const [_0x38ec04,_0x22d6ec]of Object[_0x2e6f20(0x205)](_0x3add88)){if(URL_FIELD_NAMES[_0x2e6f20(0x23d)](_0x38ec04[_0x2e6f20(0x238)]())&&_0x3fd99c[_0x2e6f20(0x302)](typeof _0x22d6ec,_0x3fd99c[_0x2e6f20(0x36f)])){try{const _0x69f5a=new URL(_0x22d6ec);_0x10f7d8[_0x2e6f20(0x376)]({'\x72\x61\x77':_0x22d6ec,'\x68\x6f\x73\x74':_0x69f5a[_0x2e6f20(0x1fd)]});}catch{_0x10f7d8['\x70\x75\x73\x68']({'\x72\x61\x77':_0x22d6ec,'\x68\x6f\x73\x74':null});}continue;}_0x9728f6(_0x22d6ec);}};return _0x9728f6(_0x5d0698),_0x10f7d8;}function isNetworkLike(_0x3f3303,_0x4ab5aa){const _0x5b416e=a0_0x5cfbcf,_0x1f2df2={'\x79\x75\x79\x66\x51':function(_0x6b34ac,_0x3d7405){return _0x6b34ac>_0x3d7405;}};if(NETWORK_TOOL_REGEX['\x74\x65\x73\x74'](_0x3f3303[_0x5b416e(0x351)]))return!![];return _0x1f2df2['\x79\x75\x79\x66\x51'](_0x4ab5aa['\x6c\x65\x6e\x67\x74\x68'],0x0);}function hostMatches(_0x482c35,_0x596ffb){const _0xdf8c74=a0_0x5cfbcf,_0x490429={'\x57\x76\x73\x49\x50':function(_0x349cb6,_0x2d8b27){return _0x349cb6===_0x2d8b27;}};if(_0x490429[_0xdf8c74(0x286)](_0x596ffb,_0x482c35))return!![];if(_0x596ffb[_0xdf8c74(0x2a9)]('\x2a\x2e')){const _0x186128=_0x596ffb[_0xdf8c74(0x362)](0x1);return _0x482c35[_0xdf8c74(0x1ea)](_0x186128);}return![];}function egressPolicyHook(_0x1699f3={}){const _0x23b96d=a0_0x5cfbcf,_0x50697d={'\x76\x6a\x77\x45\x6f':function(_0x10b985,_0x5902de){return _0x10b985(_0x5902de);},'\x56\x54\x67\x4a\x70':'\x61\x6c\x6c\x6f\x77','\x4d\x48\x48\x44\x6f':_0x23b96d(0x250),'\x7a\x43\x70\x63\x76':_0x23b96d(0x22a)},_0x1aba34=_0x1699f3[_0x23b96d(0x37d)]??[],_0x33b193=_0x1699f3[_0x23b96d(0x33b)];return{async '\x62\x65\x66\x6f\x72\x65\x54\x6f\x6f\x6c\x43\x61\x6c\x6c'(_0x5d0f02){const _0x1e3b30=_0x23b96d,_0x336252=_0x50697d[_0x1e3b30(0x260)](extractUrlsFromArgs,_0x5d0f02['\x61\x72\x67\x73']);if(!isNetworkLike(_0x5d0f02,_0x336252))return{'\x61\x63\x74\x69\x6f\x6e':_0x50697d['\x56\x54\x67\x4a\x70']};if(_0x1699f3[_0x1e3b30(0x2ca)])return await _0x1699f3['\x61\x6c\x6c\x6f\x77\x46\x6e'](_0x5d0f02)?{'\x61\x63\x74\x69\x6f\x6e':_0x50697d[_0x1e3b30(0x1f1)]}:{'\x61\x63\x74\x69\x6f\x6e':_0x50697d['\x4d\x48\x48\x44\x6f'],'\x72\x65\x61\x73\x6f\x6e':_0x50697d[_0x1e3b30(0x35d)]};for(const _0x1816df of _0x336252){if(!_0x1816df[_0x1e3b30(0x1fd)])continue;for(const _0x21ee6e of _0x1aba34)if(hostMatches(_0x1816df[_0x1e3b30(0x1fd)],_0x21ee6e))return{'\x61\x63\x74\x69\x6f\x6e':_0x50697d[_0x1e3b30(0x271)],'\x72\x65\x61\x73\x6f\x6e':_0x1e3b30(0x33c)+_0x1816df[_0x1e3b30(0x1fd)]+_0x1e3b30(0x2e3)+_0x21ee6e+'\x22'};}if(_0x33b193&&_0x33b193['\x6c\x65\x6e\x67\x74\x68']>0x0)for(const _0x531d0e of _0x336252){const _0x4d0232=_0x531d0e[_0x1e3b30(0x1fd)];if(!_0x4d0232)return{'\x61\x63\x74\x69\x6f\x6e':_0x1e3b30(0x250),'\x72\x65\x61\x73\x6f\x6e':'\x65\x67\x72\x65\x73\x73\x20\x64\x65\x6e\x69\x65\x64\x3a\x20\x75\x6e\x70\x61\x72\x73\x65\x61\x62\x6c\x65\x20\x75\x72\x6c'};if(!_0x33b193['\x73\x6f\x6d\x65'](_0xdb6845=>hostMatches(_0x4d0232,_0xdb6845)))return{'\x61\x63\x74\x69\x6f\x6e':_0x1e3b30(0x250),'\x72\x65\x61\x73\x6f\x6e':'\x65\x67\x72\x65\x73\x73\x20\x64\x65\x6e\x69\x65\x64\x3a\x20\x68\x6f\x73\x74\x20\x22'+_0x4d0232+_0x1e3b30(0x30f)};}return{'\x61\x63\x74\x69\x6f\x6e':_0x50697d['\x56\x54\x67\x4a\x70']};}};}function costCapHook(_0x446107){const _0x279487=a0_0x5cfbcf,_0x537e9d={'\x63\x51\x75\x52\x42':_0x279487(0x250),'\x77\x4d\x6a\x4a\x76':function(_0x18f931,_0x30c692){return _0x18f931(_0x30c692);},'\x58\x67\x62\x6d\x75':function(_0x1636e8,_0x138f03){return _0x1636e8>=_0x138f03;},'\x51\x6d\x64\x67\x6d':_0x279487(0x368),'\x4c\x6c\x53\x5a\x69':_0x279487(0x223)},_0x485a6c=_0x446107[_0x279487(0x213)]??(async()=>0x0);return{async '\x62\x65\x66\x6f\x72\x65\x54\x6f\x6f\x6c\x43\x61\x6c\x6c'(_0x37c652){const _0x4117ae=_0x279487,_0x9268=await _0x485a6c(_0x37c652[_0x4117ae(0x34c)]);if(_0x9268>=_0x446107['\x63\x65\x69\x6c\x69\x6e\x67'])return{'\x61\x63\x74\x69\x6f\x6e':_0x537e9d[_0x4117ae(0x33d)],'\x72\x65\x61\x73\x6f\x6e':_0x4117ae(0x291)+_0x9268+_0x4117ae(0x2ec)+_0x446107['\x63\x65\x69\x6c\x69\x6e\x67']};return{'\x61\x63\x74\x69\x6f\x6e':_0x4117ae(0x21c)};},async '\x61\x66\x74\x65\x72\x54\x6f\x6f\x6c\x43\x61\x6c\x6c'(_0x5ccebd){const _0x503ab8=_0x279487,_0x25d1a2=await _0x537e9d[_0x503ab8(0x221)](_0x485a6c,_0x5ccebd[_0x503ab8(0x34c)]);if(_0x537e9d[_0x503ab8(0x29c)](_0x25d1a2,_0x446107[_0x503ab8(0x26d)]))return{'\x61\x63\x74\x69\x6f\x6e':_0x537e9d[_0x503ab8(0x255)],'\x72\x65\x61\x73\x6f\x6e':'\x63\x6f\x73\x74\x20\x63\x61\x70\x20\x72\x65\x61\x63\x68\x65\x64\x20\x61\x66\x74\x65\x72\x20\x74\x6f\x6f\x6c\x20\x63\x61\x6c\x6c\x3a\x20'+_0x25d1a2+_0x503ab8(0x2ec)+_0x446107[_0x503ab8(0x26d)]};return{'\x61\x63\x74\x69\x6f\x6e':_0x537e9d[_0x503ab8(0x1ec)]};}};}function actionRateLimitHook(_0x3f7b97){const _0x58c2ee=a0_0x5cfbcf,_0x1fed75={'\x6f\x63\x72\x46\x78':'\x63\x6f\x6d\x70\x75\x74\x65\x72\x2d\x75\x73\x65\x3a','\x72\x50\x64\x6e\x4b':function(_0x1c4924,_0x1fa5f7){return _0x1c4924-_0x1fa5f7;},'\x55\x63\x68\x64\x73':function(_0xa60963,_0x212f68){return _0xa60963*_0x212f68;},'\x76\x4b\x70\x74\x48':function(_0x167f32,_0x12f5bd){return _0x167f32<_0x12f5bd;},'\x6f\x62\x52\x69\x4e':_0x58c2ee(0x250)},_0x984478=_0x3f7b97[_0x58c2ee(0x23b)]??Date[_0x58c2ee(0x23b)],_0x1fafda=Math[_0x58c2ee(0x37f)](0x1,Math['\x66\x6c\x6f\x6f\x72'](_0x3f7b97['\x70\x65\x72\x53\x65\x63\x6f\x6e\x64\x50\x65\x72\x53\x65\x73\x73\x69\x6f\x6e'])),_0x4fcd46=_0x3f7b97[_0x58c2ee(0x23f)]/0x3e8,_0x82df03=new Map();return{async '\x62\x65\x66\x6f\x72\x65\x54\x6f\x6f\x6c\x43\x61\x6c\x6c'(_0x2517e7){const _0x43c6b3=_0x58c2ee;if(!_0x2517e7[_0x43c6b3(0x351)][_0x43c6b3(0x2a9)](_0x1fed75[_0x43c6b3(0x1e5)]))return{'\x61\x63\x74\x69\x6f\x6e':_0x43c6b3(0x21c)};const _0x534431=_0x2517e7[_0x43c6b3(0x37c)],_0x558f30=_0x984478(),_0x765c34=_0x82df03[_0x43c6b3(0x247)](_0x534431)??{'\x74\x6f\x6b\x65\x6e\x73':_0x1fafda,'\x6c\x61\x73\x74\x52\x65\x66\x69\x6c\x6c\x4d\x73':_0x558f30},_0x4b008b=Math[_0x43c6b3(0x37f)](0x0,_0x1fed75[_0x43c6b3(0x241)](_0x558f30,_0x765c34[_0x43c6b3(0x3c2)]));_0x765c34['\x74\x6f\x6b\x65\x6e\x73']=Math['\x6d\x69\x6e'](_0x1fafda,_0x765c34[_0x43c6b3(0x2f4)]+_0x1fed75['\x55\x63\x68\x64\x73'](_0x4b008b,_0x4fcd46)),_0x765c34[_0x43c6b3(0x3c2)]=_0x558f30;if(_0x1fed75['\x76\x4b\x70\x74\x48'](_0x765c34[_0x43c6b3(0x2f4)],0x1))return _0x82df03[_0x43c6b3(0x21a)](_0x534431,_0x765c34),{'\x61\x63\x74\x69\x6f\x6e':_0x1fed75[_0x43c6b3(0x374)],'\x72\x65\x61\x73\x6f\x6e':_0x43c6b3(0x21b)+_0x3f7b97[_0x43c6b3(0x23f)]+'\x2f\x73'};return _0x765c34['\x74\x6f\x6b\x65\x6e\x73']-=0x1,_0x82df03[_0x43c6b3(0x21a)](_0x534431,_0x765c34),{'\x61\x63\x74\x69\x6f\x6e':_0x43c6b3(0x21c)};}};}function a0_0x19c9(_0x3e02dc,_0x230d6e){_0x3e02dc=_0x3e02dc-0x1e5;const _0x33250e=a0_0x3325();let _0x19c9e6=_0x33250e[_0x3e02dc];if(a0_0x19c9['\x77\x59\x65\x50\x54\x4f']===undefined){var _0x48bd87=function(_0x433c73){const _0x528727='\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x2b\x2f\x3d';let _0x185016='',_0x1aabe2='';for(let _0x4ad195=0x0,_0x476eab,_0x151d11,_0x36f932=0x0;_0x151d11=_0x433c73['\x63\x68\x61\x72\x41\x74'](_0x36f932++);~_0x151d11&&(_0x476eab=_0x4ad195%0x4?_0x476eab*0x40+_0x151d11:_0x151d11,_0x4ad195++%0x4)?_0x185016+=String['\x66\x72\x6f\x6d\x43\x68\x61\x72\x43\x6f\x64\x65'](0xff&_0x476eab>>(-0x2*_0x4ad195&0x6)):0x0){_0x151d11=_0x528727['\x69\x6e\x64\x65\x78\x4f\x66'](_0x151d11);}for(let _0x5d0bd2=0x0,_0x5a1c48=_0x185016['\x6c\x65\x6e\x67\x74\x68'];_0x5d0bd2<_0x5a1c48;_0x5d0bd2++){_0x1aabe2+='\x25'+('\x30\x30'+_0x185016['\x63\x68\x61\x72\x43\x6f\x64\x65\x41\x74'](_0x5d0bd2)['\x74\x6f\x53\x74\x72\x69\x6e\x67'](0x10))['\x73\x6c\x69\x63\x65'](-0x2);}return decodeURIComponent(_0x1aabe2);};a0_0x19c9['\x67\x72\x61\x6b\x55\x76']=_0x48bd87,a0_0x19c9['\x51\x64\x72\x4b\x4d\x79']={},a0_0x19c9['\x77\x59\x65\x50\x54\x4f']=!![];}const _0xb663db=_0x33250e[0x0],_0x1415a4=_0x3e02dc+_0xb663db,_0x210420=a0_0x19c9['\x51\x64\x72\x4b\x4d\x79'][_0x1415a4];return!_0x210420?(_0x19c9e6=a0_0x19c9['\x67\x72\x61\x6b\x55\x76'](_0x19c9e6),a0_0x19c9['\x51\x64\x72\x4b\x4d\x79'][_0x1415a4]=_0x19c9e6):_0x19c9e6=_0x210420,_0x19c9e6;}function readScreenshotPayload(_0x1c5d87){const _0x4326bc=a0_0x5cfbcf,_0x48e82b={'\x66\x48\x7a\x4a\x4f':function(_0xe6dc94,_0x4538ef){return _0xe6dc94===_0x4538ef;},'\x7a\x59\x4f\x6f\x53':_0x4326bc(0x2c6)},_0x3eb6ef=[_0x1c5d87[_0x4326bc(0x23c)],_0x1c5d87['\x64\x65\x74\x61\x69\x6c\x73']?.['\x73\x63\x72\x65\x65\x6e\x73\x68\x6f\x74'],_0x1c5d87['\x64\x65\x74\x61\x69\x6c\x73']];for(const _0x4d1d9d of _0x3eb6ef)if(_0x4d1d9d&&typeof _0x4d1d9d===_0x4326bc(0x256)){if(_0x48e82b['\x66\x48\x7a\x4a\x4f'](typeof _0x4d1d9d[_0x4326bc(0x29d)],_0x48e82b['\x7a\x59\x4f\x6f\x53']))return _0x4d1d9d;}return null;}function screenshotRedactionHook(_0x258d09={}){const _0x342bcc=a0_0x5cfbcf,_0x5229bf={'\x5a\x67\x48\x67\x7a':_0x342bcc(0x297),'\x53\x49\x66\x47\x43':'\x70\x61\x73\x73','\x42\x6b\x41\x73\x58':'\x5b\x73\x63\x72\x65\x65\x6e\x73\x68\x6f\x74\x52\x65\x64\x61\x63\x74\x69\x6f\x6e\x48\x6f\x6f\x6b\x5d\x20\x72\x65\x67\x69\x6f\x6e\x73\x20\x63\x6f\x6e\x66\x69\x67\x75\x72\x65\x64\x20\x62\x75\x74\x20\x60\x73\x68\x61\x72\x70\x60\x20\x69\x73\x20\x6e\x6f\x74\x20\x61\x20\x64\x65\x70\x65\x6e\x64\x65\x6e\x63\x79\x20\x69\x6e\x20\x76\x31\x3b\x20\x70\x61\x73\x73\x69\x6e\x67\x20\x73\x63\x72\x65\x65\x6e\x73\x68\x6f\x74\x20\x74\x68\x72\x6f\x75\x67\x68\x20\x75\x6e\x6d\x6f\x64\x69\x66\x69\x65\x64','\x57\x61\x56\x72\x42':function(_0x14795a,_0x4d8a64){return _0x14795a>_0x4d8a64;}},_0x90b8a3=_0x258d09[_0x342bcc(0x2d0)]??(_0x4bcbf1=>console[_0x342bcc(0x2d0)](_0x4bcbf1)),_0x33a9a9=_0x5229bf[_0x342bcc(0x2a0)](_0x258d09['\x72\x65\x67\x69\x6f\x6e\x73']?.['\x6c\x65\x6e\x67\x74\x68']??0x0,0x0);let _0x2c0c97=![];return{async '\x61\x66\x74\x65\x72\x54\x6f\x6f\x6c\x43\x61\x6c\x6c'(_0x2deadf,_0x5e7da2){const _0x3f547c=_0x342bcc,_0x2f7a88=_0x3f547c(0x246)['\x73\x70\x6c\x69\x74']('\x7c');let _0x2be190=0x0;while(!![]){switch(_0x2f7a88[_0x2be190++]){case'\x30':if(_0x2deadf['\x74\x6f\x6f\x6c\x4e\x61\x6d\x65']!==_0x5229bf[_0x3f547c(0x360)])return{'\x61\x63\x74\x69\x6f\x6e':_0x5229bf[_0x3f547c(0x288)]};continue;case'\x31':!_0x2c0c97&&(_0x2c0c97=!![],_0x90b8a3(_0x5229bf[_0x3f547c(0x3b7)]));continue;case'\x32':return{'\x61\x63\x74\x69\x6f\x6e':'\x70\x61\x73\x73'};case'\x33':if(!_0x33a9a9)return{'\x61\x63\x74\x69\x6f\x6e':_0x5229bf[_0x3f547c(0x288)]};continue;case'\x34':if(!readScreenshotPayload(_0x5e7da2))return{'\x61\x63\x74\x69\x6f\x6e':_0x5229bf[_0x3f547c(0x288)]};continue;}break;}}};}const TYPE_TEXT_FIELDS=[a0_0x5cfbcf(0x20f),a0_0x5cfbcf(0x207),'\x69\x6e\x70\x75\x74','\x71\x75\x65\x72\x79'],CLICK_LABEL_FIELDS=[a0_0x5cfbcf(0x2e8),a0_0x5cfbcf(0x2eb),a0_0x5cfbcf(0x249),a0_0x5cfbcf(0x311),a0_0x5cfbcf(0x30d)];function readStringField(_0x1c089b,_0x53cc80){const _0xfae60c=a0_0x5cfbcf,_0x312c91={'\x44\x49\x78\x6d\x46':_0xfae60c(0x256)};if(!_0x1c089b||typeof _0x1c089b!==_0x312c91[_0xfae60c(0x2f2)])return null;const _0x59fc69=_0x1c089b;for(const _0x4b72ff of _0x53cc80){const _0x20249a=_0x59fc69[_0x4b72ff];if(typeof _0x20249a===_0xfae60c(0x2c6)&&_0x20249a[_0xfae60c(0x2a8)]>0x0)return _0x20249a;}return null;}function destructiveActionGuardHook(_0x387454){const _0x1db710=a0_0x5cfbcf,_0x329aa7={'\x49\x77\x4a\x41\x6d':'\x63\x6f\x6d\x70\x75\x74\x65\x72\x2d\x75\x73\x65\x3a\x74\x79\x70\x65','\x79\x77\x7a\x73\x72':_0x1db710(0x2e6),'\x63\x56\x4c\x6f\x57':function(_0x9fdc92,_0x45165c,_0x317a02){return _0x9fdc92(_0x45165c,_0x317a02);},'\x58\x71\x44\x53\x62':'\x61\x6c\x6c\x6f\x77'},_0x45a9ea=_0x387454[_0x1db710(0x363)];return{async '\x62\x65\x66\x6f\x72\x65\x54\x6f\x6f\x6c\x43\x61\x6c\x6c'(_0x95056b){const _0x3345a7=_0x1db710;let _0x40ea7e=null;if(_0x95056b[_0x3345a7(0x351)]===_0x329aa7['\x49\x77\x4a\x41\x6d'])_0x40ea7e=readStringField(_0x95056b[_0x3345a7(0x32f)],TYPE_TEXT_FIELDS);else{if(_0x95056b[_0x3345a7(0x351)]===_0x329aa7['\x79\x77\x7a\x73\x72'])_0x40ea7e=_0x329aa7['\x63\x56\x4c\x6f\x57'](readStringField,_0x95056b['\x61\x72\x67\x73'],CLICK_LABEL_FIELDS);else return{'\x61\x63\x74\x69\x6f\x6e':_0x329aa7['\x58\x71\x44\x53\x62']};}if(!_0x40ea7e)return{'\x61\x63\x74\x69\x6f\x6e':_0x3345a7(0x21c)};for(const _0x2f5658 of _0x45a9ea)if(_0x2f5658[_0x3345a7(0x26f)](_0x40ea7e))return{'\x61\x63\x74\x69\x6f\x6e':_0x3345a7(0x250),'\x72\x65\x61\x73\x6f\x6e':_0x3345a7(0x337)+_0x2f5658[_0x3345a7(0x1fc)]()};return{'\x61\x63\x74\x69\x6f\x6e':'\x61\x6c\x6c\x6f\x77'};}};}var InMemoryResponseStore=class{[a0_0x5cfbcf(0x2c7)]=new Map();async[a0_0x5cfbcf(0x2b1)](_0x493681){const _0xcb47ec=a0_0x5cfbcf,_0x355da0=this[_0xcb47ec(0x2c7)][_0xcb47ec(0x247)](_0x493681);return _0x355da0?_0x355da0['\x6d\x61\x70'](_0x22c745=>({..._0x22c745})):null;}async[a0_0x5cfbcf(0x2dc)](_0x5d6a37,_0x3e8c66){const _0x560017=a0_0x5cfbcf;this[_0x560017(0x2c7)][_0x560017(0x21a)](_0x5d6a37,_0x3e8c66[_0x560017(0x236)](_0x2daf55=>({..._0x2daf55})));}[a0_0x5cfbcf(0x220)](){const _0x2519c8=a0_0x5cfbcf;return this[_0x2519c8(0x2c7)][_0x2519c8(0x220)];}[a0_0x5cfbcf(0x377)](_0x65b182){const _0x36ab0f=a0_0x5cfbcf;return this[_0x36ab0f(0x2c7)]['\x64\x65\x6c\x65\x74\x65'](_0x65b182);}[a0_0x5cfbcf(0x35f)](){const _0x2db05c=a0_0x5cfbcf;this[_0x2db05c(0x2c7)][_0x2db05c(0x35f)]();}};const TERMINAL_STATUSES=new Set([a0_0x5cfbcf(0x2e7),a0_0x5cfbcf(0x385),'\x63\x61\x6e\x63\x65\x6c\x6c\x65\x64',a0_0x5cfbcf(0x26a)]);function isTerminal(_0x3a743e){const _0x44a2f0=a0_0x5cfbcf;return TERMINAL_STATUSES[_0x44a2f0(0x23d)](_0x3a743e);}async function*runEvents(_0x5ac101,_0x5aeefc,_0x2b07e2){const _0x1b7d07=a0_0x5cfbcf;for await(const _0x2e000d of _0x2b07e2[_0x1b7d07(0x313)](_0x5ac101,_0x5aeefc))yield _0x2e000d;}function readToolCallFromFrame(_0x2ad2b2){const _0x2a3109=a0_0x5cfbcf,_0x4e31f9={'\x7a\x79\x5a\x72\x61':_0x2a3109(0x334),'\x75\x52\x4c\x62\x4a':function(_0x5dc76b,_0x35ea32){return _0x5dc76b(_0x35ea32);},'\x73\x57\x47\x71\x53':function(_0x3ab3df,_0xc9fdc0){return _0x3ab3df!==_0xc9fdc0;},'\x41\x47\x4d\x67\x59':_0x2a3109(0x25f),'\x58\x6e\x6e\x71\x57':function(_0x140c1e,_0x10a11c){return _0x140c1e===_0x10a11c;},'\x4f\x58\x69\x61\x78':_0x2a3109(0x2c6),'\x61\x49\x78\x63\x42':function(_0x598659,_0x303295){return _0x598659===_0x303295;},'\x64\x7a\x65\x42\x45':_0x2a3109(0x2fb),'\x62\x6b\x75\x67\x50':function(_0x5db6f6,_0x4c5615){return _0x5db6f6===_0x4c5615;},'\x49\x43\x47\x61\x68':_0x2a3109(0x33f)};if(_0x2ad2b2[_0x2a3109(0x382)]===_0x4e31f9[_0x2a3109(0x35e)]||_0x2ad2b2[_0x2a3109(0x382)]===_0x2a3109(0x2f5)){const _0x24543c=_0x2ad2b2[_0x2a3109(0x321)]??_0x2ad2b2,_0x3657c9=String(_0x24543c[_0x2a3109(0x273)]??_0x24543c['\x63\x61\x6c\x6c\x5f\x69\x64']??_0x24543c['\x69\x64']??''),_0x516f56=_0x4e31f9['\x75\x52\x4c\x62\x4a'](String,_0x24543c[_0x2a3109(0x351)]??_0x24543c[_0x2a3109(0x308)]??_0x24543c[_0x2a3109(0x306)]??'');if(!_0x3657c9||!_0x516f56)return null;return{'\x63\x61\x6c\x6c\x49\x64':_0x3657c9,'\x74\x6f\x6f\x6c\x4e\x61\x6d\x65':_0x516f56,'\x61\x72\x67\x73':_0x24543c[_0x2a3109(0x32f)]??_0x24543c[_0x2a3109(0x2b7)]??_0x24543c[_0x2a3109(0x28c)]??{},'\x72\x65\x71\x75\x69\x72\x65\x73\x41\x63\x74\x69\x6f\x6e':!![]};}if(_0x4e31f9[_0x2a3109(0x397)](_0x2ad2b2[_0x2a3109(0x382)],_0x4e31f9[_0x2a3109(0x1e7)]))return null;const _0x28fc5e=_0x2ad2b2['\x64\x61\x74\x61']??_0x2ad2b2,_0x245f6d=_0x4e31f9[_0x2a3109(0x3b2)](typeof _0x28fc5e[_0x2a3109(0x382)],_0x4e31f9['\x4f\x58\x69\x61\x78'])?_0x28fc5e['\x74\x79\x70\x65']:'';if(!(_0x245f6d==='\x74\x6f\x6f\x6c\x2d\x69\x6e\x76\x6f\x63\x61\x74\x69\x6f\x6e'||_0x245f6d===_0x2a3109(0x2dd)||_0x4e31f9[_0x2a3109(0x22d)](_0x245f6d,_0x4e31f9[_0x2a3109(0x2fe)])||_0x4e31f9[_0x2a3109(0x344)](_0x245f6d,_0x4e31f9['\x49\x43\x47\x61\x68'])))return null;const _0x4f4aeb=_0x28fc5e[_0x2a3109(0x354)]??_0x28fc5e['\x74\x6f\x6f\x6c\x5f\x69\x6e\x76\x6f\x63\x61\x74\x69\x6f\x6e']??_0x28fc5e[_0x2a3109(0x3d0)]??_0x28fc5e[_0x2a3109(0x293)]??_0x28fc5e,_0x24469b=String(_0x4f4aeb[_0x2a3109(0x234)]??_0x4f4aeb['\x74\x6f\x6f\x6c\x5f\x63\x61\x6c\x6c\x5f\x69\x64']??_0x4f4aeb[_0x2a3109(0x273)]??_0x4f4aeb['\x69\x64']??''),_0x356e4c=_0x245f6d===_0x4e31f9['\x64\x7a\x65\x42\x45']||_0x4e31f9['\x61\x49\x78\x63\x42'](_0x245f6d,'\x63\x6f\x6d\x70\x75\x74\x65\x72\x5f\x63\x61\x6c\x6c')?_0x2a3109(0x3bf)+String(_0x4f4aeb[_0x2a3109(0x330)]?.['\x74\x79\x70\x65']??_0x2a3109(0x330)):String(_0x4f4aeb[_0x2a3109(0x351)]??_0x4f4aeb[_0x2a3109(0x308)]??_0x4f4aeb[_0x2a3109(0x306)]??'');if(!_0x24469b||!_0x356e4c)return null;return{'\x63\x61\x6c\x6c\x49\x64':_0x24469b,'\x74\x6f\x6f\x6c\x4e\x61\x6d\x65':_0x356e4c,'\x61\x72\x67\x73':_0x4f4aeb[_0x2a3109(0x32f)]??_0x4f4aeb[_0x2a3109(0x2b7)]??_0x4f4aeb[_0x2a3109(0x28c)]??{},'\x72\x65\x71\x75\x69\x72\x65\x73\x41\x63\x74\x69\x6f\x6e':![]};}function readTerminal(_0xb24002){const _0x31e068=a0_0x5cfbcf,_0x39d89d={'\x59\x47\x48\x6d\x4d':function(_0x13ecb6,_0x3da120){return _0x13ecb6===_0x3da120;},'\x69\x4d\x49\x66\x53':'\x73\x75\x63\x63\x65\x65\x64\x65\x64','\x54\x59\x7a\x54\x6e':function(_0x39e530,_0xe6036a){return _0x39e530===_0xe6036a;},'\x79\x71\x6d\x78\x6a':'\x63\x6f\x6d\x70\x6c\x65\x74\x65\x64','\x52\x51\x54\x62\x4d':_0x31e068(0x2c6),'\x6a\x70\x4a\x71\x43':'\x73\x74\x72\x65\x61\x6d\x20\x65\x72\x72\x6f\x72'};if(_0x39d89d[_0x31e068(0x2a2)](_0xb24002['\x74\x79\x70\x65'],_0x31e068(0x38d))){const _0x260a12=typeof _0xb24002['\x6f\x75\x74\x63\x6f\x6d\x65']==='\x73\x74\x72\x69\x6e\x67'&&_0xb24002[_0x31e068(0x2fd)]||_0x31e068(0x3cb);if(_0x39d89d[_0x31e068(0x2a2)](_0x260a12,_0x31e068(0x3cb))||_0x39d89d[_0x31e068(0x2a2)](_0x260a12,_0x31e068(0x2e7))||_0x39d89d['\x59\x47\x48\x6d\x4d'](_0x260a12,_0x39d89d[_0x31e068(0x3c4)])||_0x39d89d[_0x31e068(0x39d)](_0x260a12,_0x31e068(0x38d)))return{'\x73\x74\x61\x74\x75\x73':_0x39d89d[_0x31e068(0x2ff)]};return{'\x73\x74\x61\x74\x75\x73':'\x66\x61\x69\x6c\x65\x64','\x72\x65\x61\x73\x6f\x6e':typeof _0xb24002[_0x31e068(0x227)]===_0x31e068(0x2c6)?_0xb24002[_0x31e068(0x227)]:_0x260a12};}if(_0xb24002[_0x31e068(0x382)]==='\x65\x72\x72\x6f\x72')return{'\x73\x74\x61\x74\x75\x73':'\x66\x61\x69\x6c\x65\x64','\x72\x65\x61\x73\x6f\x6e':_0x39d89d[_0x31e068(0x39d)](typeof _0xb24002[_0x31e068(0x2d7)],_0x39d89d['\x52\x51\x54\x62\x4d'])&&_0xb24002[_0x31e068(0x2d7)]||typeof _0xb24002['\x65\x72\x72\x6f\x72']===_0x31e068(0x2c6)&&_0xb24002[_0x31e068(0x227)]||_0x39d89d[_0x31e068(0x279)]};return null;}var EventQueue=class{[a0_0x5cfbcf(0x356)]=[];['\x77\x61\x69\x74\x65\x72\x73']=[];[a0_0x5cfbcf(0x2d6)]=![];['\x69\x74\x65\x72\x61\x74\x6f\x72\x43\x72\x65\x61\x74\x65\x64']=![];['\x70\x75\x73\x68'](_0x2dafa6){const _0x513702=a0_0x5cfbcf;if(this[_0x513702(0x2d6)])return;const _0x15c080=this[_0x513702(0x22f)][_0x513702(0x391)]();if(_0x15c080){_0x15c080({'\x76\x61\x6c\x75\x65':_0x2dafa6,'\x64\x6f\x6e\x65':![]});return;}this[_0x513702(0x356)]['\x70\x75\x73\x68'](_0x2dafa6);}[a0_0x5cfbcf(0x3b5)](){const _0x16acf0=a0_0x5cfbcf;if(this[_0x16acf0(0x2d6)])return;this[_0x16acf0(0x2d6)]=!![];while(this[_0x16acf0(0x22f)][_0x16acf0(0x2a8)]>0x0)this[_0x16acf0(0x22f)][_0x16acf0(0x391)]()?.({'\x76\x61\x6c\x75\x65':void 0x0,'\x64\x6f\x6e\x65':!![]});}[a0_0x5cfbcf(0x218)](){const _0x95af94=a0_0x5cfbcf,_0x225952={'\x58\x65\x78\x51\x6a':'\x52\x75\x6e\x2e\x65\x76\x65\x6e\x74\x73\x28\x29\x20\x6d\x61\x79\x20\x6f\x6e\x6c\x79\x20\x62\x65\x20\x63\x6f\x6e\x73\x75\x6d\x65\x64\x20\x6f\x6e\x63\x65\x2e\x20\x4d\x75\x6c\x74\x69\x70\x6c\x65\x20\x69\x74\x65\x72\x61\x74\x6f\x72\x73\x20\x6f\x6e\x20\x74\x68\x65\x20\x73\x61\x6d\x65\x20\x52\x75\x6e\x20\x73\x68\x61\x72\x65\x20\x73\x74\x61\x74\x65\x20\x61\x6e\x64\x20\x77\x6f\x75\x6c\x64\x20\x69\x6e\x74\x65\x72\x6c\x65\x61\x76\x65\x2f\x73\x74\x65\x61\x6c\x20\x65\x76\x65\x6e\x74\x73\x2e'};if(this['\x69\x74\x65\x72\x61\x74\x6f\x72\x43\x72\x65\x61\x74\x65\x64'])throw new Error(_0x225952[_0x95af94(0x282)]);this['\x69\x74\x65\x72\x61\x74\x6f\x72\x43\x72\x65\x61\x74\x65\x64']=!![];const _0xb4e6e2=this;return{[Symbol[_0x95af94(0x38a)]](){return this;},'\x6e\x65\x78\x74'(){const _0x5e06ad=_0x95af94;if(_0xb4e6e2[_0x5e06ad(0x356)][_0x5e06ad(0x2a8)]>0x0){const _0x1862d9=_0xb4e6e2[_0x5e06ad(0x356)][_0x5e06ad(0x391)]();return Promise[_0x5e06ad(0x301)]({'\x76\x61\x6c\x75\x65':_0x1862d9,'\x64\x6f\x6e\x65':![]});}if(_0xb4e6e2[_0x5e06ad(0x2d6)])return Promise[_0x5e06ad(0x301)]({'\x76\x61\x6c\x75\x65':void 0x0,'\x64\x6f\x6e\x65':!![]});return new Promise(_0x4f9b9a=>{const _0x1e79c4=_0x5e06ad;_0xb4e6e2[_0x1e79c4(0x22f)][_0x1e79c4(0x376)](_0x4f9b9a);});},'\x72\x65\x74\x75\x72\x6e'(){const _0x243c39=_0x95af94;return _0xb4e6e2[_0x243c39(0x3b5)](),Promise[_0x243c39(0x301)]({'\x76\x61\x6c\x75\x65':void 0x0,'\x64\x6f\x6e\x65':!![]});}};}},Run=class{['\x69\x64'];[a0_0x5cfbcf(0x21e)];['\x70\x61\x72\x74\x6e\x65\x72\x49\x64'];[a0_0x5cfbcf(0x32c)]=a0_0x5cfbcf(0x229);['\x73\x6f\x75\x72\x63\x65'];['\x68\x6f\x6f\x6b\x73'];[a0_0x5cfbcf(0x258)];[a0_0x5cfbcf(0x263)];[a0_0x5cfbcf(0x27f)]=new EventQueue();[a0_0x5cfbcf(0x329)]=null;[a0_0x5cfbcf(0x3c9)]=new Map();[a0_0x5cfbcf(0x237)]=![];constructor(_0x2697b8){const _0x4ef0a2=a0_0x5cfbcf,_0xec8682='\x34\x7c\x32\x7c\x33\x7c\x35\x7c\x30\x7c\x36\x7c\x31'['\x73\x70\x6c\x69\x74']('\x7c');let _0x449607=0x0;while(!![]){switch(_0xec8682[_0x449607++]){case'\x30':this[_0x4ef0a2(0x341)]=_0x2697b8[_0x4ef0a2(0x341)];continue;case'\x31':this[_0x4ef0a2(0x263)]=_0x2697b8[_0x4ef0a2(0x263)];continue;case'\x32':this['\x74\x68\x72\x65\x61\x64\x49\x64']=_0x2697b8[_0x4ef0a2(0x21e)];continue;case'\x33':this[_0x4ef0a2(0x34c)]=_0x2697b8[_0x4ef0a2(0x34c)];continue;case'\x34':this['\x69\x64']=_0x2697b8['\x69\x64'];continue;case'\x35':this[_0x4ef0a2(0x2ad)]=_0x2697b8[_0x4ef0a2(0x2ad)];continue;case'\x36':this[_0x4ef0a2(0x258)]=_0x2697b8[_0x4ef0a2(0x258)];continue;}break;}}get['\x73\x74\x61\x74\x75\x73'](){return this['\x5f\x73\x74\x61\x74\x75\x73'];}[a0_0x5cfbcf(0x215)](){const _0x41084f=a0_0x5cfbcf;return this['\x71\x75\x65\x75\x65'][_0x41084f(0x218)]();}[a0_0x5cfbcf(0x30b)](){const _0x4a8876=a0_0x5cfbcf;if(this[_0x4a8876(0x329)])return this[_0x4a8876(0x329)];return this[_0x4a8876(0x329)]=this[_0x4a8876(0x30a)](),this[_0x4a8876(0x329)];}async[a0_0x5cfbcf(0x379)](_0x1751f4){const _0x31adb8=a0_0x5cfbcf,_0x15d8f2={'\x68\x7a\x4b\x6c\x79':_0x31adb8(0x212)},_0x238365=_0x15d8f2[_0x31adb8(0x2a1)][_0x31adb8(0x2f6)]('\x7c');let _0x5a1534=0x0;while(!![]){switch(_0x238365[_0x5a1534++]){case'\x30':if(this[_0x31adb8(0x2ad)][_0x31adb8(0x379)])try{await this['\x73\x6f\x75\x72\x63\x65']['\x63\x61\x6e\x63\x65\x6c'](this['\x74\x68\x72\x65\x61\x64\x49\x64'],this['\x69\x64']);}catch{}continue;case'\x31':this['\x71\x75\x65\x75\x65'][_0x31adb8(0x376)]({'\x74\x79\x70\x65':'\x63\x61\x6e\x63\x65\x6c\x6c\x65\x64','\x72\x65\x61\x73\x6f\x6e':_0x1751f4});continue;case'\x32':this[_0x31adb8(0x27f)]['\x63\x6c\x6f\x73\x65']();continue;case'\x33':this[_0x31adb8(0x237)]=!![];continue;case'\x34':this['\x74\x72\x61\x6e\x73\x69\x74\x69\x6f\x6e'](_0x31adb8(0x2de));continue;case'\x35':if(isTerminal(this[_0x31adb8(0x32c)]))return;continue;}break;}}async[a0_0x5cfbcf(0x1ef)](_0x47d252){const _0x10b564=a0_0x5cfbcf,_0x497ada={'\x57\x47\x49\x45\x4f':_0x10b564(0x283)};if(!this['\x73\x6f\x75\x72\x63\x65'][_0x10b564(0x1ef)])throw new Error(_0x497ada[_0x10b564(0x39f)]);if(isTerminal(this[_0x10b564(0x32c)]))throw new Error(_0x10b564(0x300)+this[_0x10b564(0x32c)]+_0x10b564(0x26c));await this['\x73\x6f\x75\x72\x63\x65'][_0x10b564(0x1ef)](this[_0x10b564(0x21e)],this['\x69\x64'],_0x47d252);if(this[_0x10b564(0x32c)]==='\x72\x65\x71\x75\x69\x72\x65\x73\x5f\x61\x63\x74\x69\x6f\x6e')this[_0x10b564(0x2b2)](_0x10b564(0x389));this['\x73\x74\x61\x72\x74\x50\x72\x6f\x6d\x69\x73\x65']=this[_0x10b564(0x30a)](),await this[_0x10b564(0x329)];}async[a0_0x5cfbcf(0x32b)](_0x388d2f){const _0x571084=a0_0x5cfbcf,_0x5de3cf={'\x57\x79\x7a\x73\x69':_0x571084(0x334),'\x43\x50\x53\x71\x56':_0x571084(0x204),'\x46\x70\x42\x4c\x43':_0x571084(0x389)};if(this[_0x571084(0x32c)]!==_0x5de3cf[_0x571084(0x384)])throw new Error(_0x571084(0x299)+this[_0x571084(0x32c)]);if(!this[_0x571084(0x2ad)][_0x571084(0x32b)])throw new Error(_0x5de3cf[_0x571084(0x2df)]);for(const _0x10def2 of _0x388d2f)this[_0x571084(0x3c9)][_0x571084(0x377)](_0x10def2[_0x571084(0x234)]);await this[_0x571084(0x2ad)][_0x571084(0x32b)](this['\x74\x68\x72\x65\x61\x64\x49\x64'],this['\x69\x64'],_0x388d2f),this[_0x571084(0x2b2)](_0x5de3cf[_0x571084(0x333)]),this[_0x571084(0x329)]=this[_0x571084(0x30a)](),await this[_0x571084(0x329)];}[a0_0x5cfbcf(0x348)](){const _0x522148=a0_0x5cfbcf,_0x243797={'\x75\x69\x44\x65\x51':function(_0x38c0fb,_0x4fc01f){return _0x38c0fb(_0x4fc01f);}};if(_0x243797[_0x522148(0x251)](isTerminal,this[_0x522148(0x32c)]))return;this[_0x522148(0x2b2)](_0x522148(0x26a)),this[_0x522148(0x27f)][_0x522148(0x376)]({'\x74\x79\x70\x65':_0x522148(0x385),'\x72\x65\x61\x73\x6f\x6e':_0x522148(0x26a)}),this[_0x522148(0x27f)]['\x63\x6c\x6f\x73\x65']();}['\x74\x72\x61\x6e\x73\x69\x74\x69\x6f\x6e'](_0x4b70a1){const _0x1b48da=a0_0x5cfbcf,_0x547479={'\x79\x58\x48\x47\x4d':function(_0x4cb782,_0x3d727f){return _0x4cb782===_0x3d727f;},'\x42\x68\x68\x5a\x43':_0x1b48da(0x2d8)};if(_0x547479[_0x1b48da(0x294)](this[_0x1b48da(0x32c)],_0x4b70a1))return;const _0x59f140=this['\x5f\x73\x74\x61\x74\x75\x73'];this['\x5f\x73\x74\x61\x74\x75\x73']=_0x4b70a1,this[_0x1b48da(0x27f)]['\x70\x75\x73\x68']({'\x74\x79\x70\x65':_0x547479[_0x1b48da(0x312)],'\x73\x74\x61\x74\x75\x73':_0x4b70a1,'\x70\x72\x65\x76\x69\x6f\x75\x73':_0x59f140}),this[_0x1b48da(0x263)]?.(_0x4b70a1,_0x59f140);}async[a0_0x5cfbcf(0x30a)](){const _0x319ca9=a0_0x5cfbcf,_0xc2aaaa={'\x74\x46\x52\x7a\x6c':_0x319ca9(0x389),'\x69\x79\x6a\x53\x67':'\x73\x74\x72\x65\x61\x6d','\x78\x64\x50\x53\x4f':function(_0x547610,_0x196ebb){return _0x547610(_0x196ebb);},'\x70\x4c\x48\x58\x77':_0x319ca9(0x368),'\x66\x58\x62\x6b\x6f':function(_0x790136,_0xe8361b){return _0x790136===_0xe8361b;},'\x77\x73\x50\x53\x6b':_0x319ca9(0x2e7),'\x4a\x75\x45\x56\x4e':function(_0x100287,_0x37573a){return _0x100287(_0x37573a);},'\x6c\x77\x79\x45\x64':_0x319ca9(0x385)};try{for await(const _0x5a7b1b of runEvents(this['\x74\x68\x72\x65\x61\x64\x49\x64'],this['\x69\x64'],this[_0x319ca9(0x2ad)])){if(this[_0x319ca9(0x237)])return;if(this['\x5f\x73\x74\x61\x74\x75\x73']===_0x319ca9(0x229))this['\x74\x72\x61\x6e\x73\x69\x74\x69\x6f\x6e'](_0xc2aaaa[_0x319ca9(0x257)]);this[_0x319ca9(0x27f)][_0x319ca9(0x376)]({'\x74\x79\x70\x65':_0xc2aaaa[_0x319ca9(0x219)],'\x65\x76\x65\x6e\x74':_0x5a7b1b});const _0x329e6f=_0xc2aaaa['\x78\x64\x50\x53\x4f'](readToolCallFromFrame,_0x5a7b1b);if(_0x329e6f){const _0x5c903f=await this[_0x319ca9(0x235)](_0x329e6f);if(_0x5c903f===_0xc2aaaa[_0x319ca9(0x32e)])return;if(_0xc2aaaa[_0x319ca9(0x1ee)](_0x5c903f,'\x72\x65\x71\x75\x69\x72\x65\x73\x5f\x61\x63\x74\x69\x6f\x6e'))return;continue;}const _0x1168ef=readTerminal(_0x5a7b1b);if(_0x1168ef){_0x1168ef['\x73\x74\x61\x74\x75\x73']===_0xc2aaaa[_0x319ca9(0x200)]?(this[_0x319ca9(0x2b2)](_0xc2aaaa[_0x319ca9(0x200)]),this['\x71\x75\x65\x75\x65'][_0x319ca9(0x376)]({'\x74\x79\x70\x65':_0x319ca9(0x2e7)})):(this[_0x319ca9(0x2b2)](_0x319ca9(0x385)),this[_0x319ca9(0x27f)][_0x319ca9(0x376)]({'\x74\x79\x70\x65':_0x319ca9(0x385),'\x72\x65\x61\x73\x6f\x6e':_0x1168ef[_0x319ca9(0x25d)]??_0x319ca9(0x365)}));this[_0x319ca9(0x27f)][_0x319ca9(0x3b5)]();return;}}!isTerminal(this[_0x319ca9(0x32c)])&&(this[_0x319ca9(0x2b2)](_0x319ca9(0x2e7)),this[_0x319ca9(0x27f)][_0x319ca9(0x376)]({'\x74\x79\x70\x65':'\x63\x6f\x6d\x70\x6c\x65\x74\x65\x64'}),this[_0x319ca9(0x27f)][_0x319ca9(0x3b5)]());}catch(_0x1e6bad){if(isTerminal(this[_0x319ca9(0x32c)]))return;const _0x4f99b2=_0x1e6bad instanceof Error?_0x1e6bad[_0x319ca9(0x2d7)]:_0xc2aaaa[_0x319ca9(0x222)](String,_0x1e6bad);this['\x74\x72\x61\x6e\x73\x69\x74\x69\x6f\x6e'](_0x319ca9(0x385)),this[_0x319ca9(0x27f)][_0x319ca9(0x376)]({'\x74\x79\x70\x65':_0xc2aaaa[_0x319ca9(0x3c6)],'\x72\x65\x61\x73\x6f\x6e':_0x4f99b2}),this[_0x319ca9(0x27f)][_0x319ca9(0x3b5)]();}}async[a0_0x5cfbcf(0x235)](_0x3004f7){const _0x1b6540=a0_0x5cfbcf,_0xde48d4={'\x6b\x55\x79\x73\x69':function(_0x4d1482,_0x33967b){return _0x4d1482>_0x33967b;},'\x59\x6a\x54\x64\x5a':_0x1b6540(0x209),'\x4d\x78\x78\x51\x61':'\x72\x65\x71\x75\x69\x72\x65\x73\x5f\x61\x63\x74\x69\x6f\x6e','\x48\x45\x57\x70\x58':function(_0x2caf46,_0x58abfe){return _0x2caf46===_0x58abfe;},'\x51\x78\x4e\x43\x43':_0x1b6540(0x2dd),'\x62\x5a\x45\x44\x59':function(_0x287703,_0x3bb869){return _0x287703>_0x3bb869;},'\x67\x70\x79\x63\x52':function(_0x3a9048,_0x436200){return _0x3a9048===_0x436200;},'\x61\x65\x74\x47\x74':_0x1b6540(0x349),'\x44\x6a\x47\x70\x64':_0x1b6540(0x385),'\x78\x5a\x68\x46\x53':function(_0xa933e3,_0x22d8b3){return _0xa933e3===_0x22d8b3;},'\x5a\x42\x64\x67\x43':_0x1b6540(0x261)},_0x250700={'\x72\x75\x6e\x49\x64':this['\x69\x64'],'\x74\x68\x72\x65\x61\x64\x49\x64':this[_0x1b6540(0x21e)],'\x70\x61\x72\x74\x6e\x65\x72\x49\x64':this['\x70\x61\x72\x74\x6e\x65\x72\x49\x64'],'\x74\x6f\x6f\x6c\x4e\x61\x6d\x65':_0x3004f7['\x74\x6f\x6f\x6c\x4e\x61\x6d\x65'],'\x61\x72\x67\x73':_0x3004f7['\x61\x72\x67\x73'],'\x63\x61\x6c\x6c\x49\x64':_0x3004f7[_0x1b6540(0x273)],'\x74\x69\x6d\x65\x73\x74\x61\x6d\x70':Date['\x6e\x6f\x77']()};let _0x15975c=_0x250700;if(this['\x68\x6f\x6f\x6b\x73']&&_0xde48d4[_0x1b6540(0x3b8)](this[_0x1b6540(0x341)][_0x1b6540(0x220)],0x0)){const _0x3c5b47=await this[_0x1b6540(0x341)]['\x72\x75\x6e\x42\x65\x66\x6f\x72\x65'](_0x250700);if(_0x3c5b47[_0x1b6540(0x330)]===_0x1b6540(0x250)){const _0x5566b2={'\x63\x6f\x6e\x74\x65\x6e\x74':{'\x65\x72\x72\x6f\x72':_0x3c5b47[_0x1b6540(0x25d)]},'\x69\x73\x45\x72\x72\x6f\x72':!![],'\x64\x65\x74\x61\x69\x6c\x73':{'\x62\x6c\x6f\x63\x6b\x65\x64\x42\x79':_0xde48d4[_0x1b6540(0x25b)]}};this[_0x1b6540(0x27f)][_0x1b6540(0x376)]({'\x74\x79\x70\x65':_0x1b6540(0x327),'\x63\x74\x78':_0x250700,'\x72\x65\x61\x73\x6f\x6e':_0x3c5b47[_0x1b6540(0x25d)]}),this[_0x1b6540(0x27f)]['\x70\x75\x73\x68']({'\x74\x79\x70\x65':_0x1b6540(0x349),'\x63\x74\x78':_0x250700,'\x72\x65\x73\x75\x6c\x74':_0x5566b2});if(_0x3004f7[_0x1b6540(0x3a9)])return this[_0x1b6540(0x3c9)]['\x73\x65\x74'](_0x3004f7[_0x1b6540(0x273)],_0x250700),this[_0x1b6540(0x2b2)](_0x1b6540(0x334)),this['\x71\x75\x65\x75\x65'][_0x1b6540(0x376)]({'\x74\x79\x70\x65':'\x72\x65\x71\x75\x69\x72\x65\x73\x5f\x61\x63\x74\x69\x6f\x6e','\x70\x65\x6e\x64\x69\x6e\x67\x43\x61\x6c\x6c\x49\x64\x73':Array['\x66\x72\x6f\x6d'](this['\x70\x65\x6e\x64\x69\x6e\x67\x43\x61\x6c\x6c\x73'][_0x1b6540(0x3bd)]())}),_0xde48d4[_0x1b6540(0x1eb)];return _0x1b6540(0x359);}if(_0xde48d4[_0x1b6540(0x20d)](_0x3c5b47[_0x1b6540(0x330)],'\x72\x65\x77\x72\x69\x74\x65'))_0x15975c={..._0x250700,'\x61\x72\x67\x73':_0x3c5b47[_0x1b6540(0x32f)]};}if(_0x3004f7['\x72\x65\x71\x75\x69\x72\x65\x73\x41\x63\x74\x69\x6f\x6e'])return this['\x70\x65\x6e\x64\x69\x6e\x67\x43\x61\x6c\x6c\x73'][_0x1b6540(0x21a)](_0x3004f7[_0x1b6540(0x273)],_0x15975c),this[_0x1b6540(0x2b2)](_0x1b6540(0x334)),this[_0x1b6540(0x27f)]['\x70\x75\x73\x68']({'\x74\x79\x70\x65':_0x1b6540(0x2dd),'\x63\x74\x78':_0x15975c}),this[_0x1b6540(0x27f)][_0x1b6540(0x376)]({'\x74\x79\x70\x65':_0xde48d4[_0x1b6540(0x1eb)],'\x70\x65\x6e\x64\x69\x6e\x67\x43\x61\x6c\x6c\x49\x64\x73':Array[_0x1b6540(0x202)](this[_0x1b6540(0x3c9)]['\x6b\x65\x79\x73']())}),_0xde48d4['\x4d\x78\x78\x51\x61'];if(!this[_0x1b6540(0x258)])return this[_0x1b6540(0x27f)][_0x1b6540(0x376)]({'\x74\x79\x70\x65':_0xde48d4['\x51\x78\x4e\x43\x43'],'\x63\x74\x78':_0x15975c}),_0x1b6540(0x359);this[_0x1b6540(0x27f)][_0x1b6540(0x376)]({'\x74\x79\x70\x65':'\x74\x6f\x6f\x6c\x5f\x63\x61\x6c\x6c','\x63\x74\x78':_0x15975c});let _0x27b6d6;try{_0x27b6d6=await this['\x65\x78\x65\x63\x75\x74\x65\x54\x6f\x6f\x6c'](_0x15975c);}catch(_0x278b57){_0x27b6d6={'\x63\x6f\x6e\x74\x65\x6e\x74':{'\x65\x72\x72\x6f\x72':_0x278b57 instanceof Error?_0x278b57['\x6d\x65\x73\x73\x61\x67\x65']:String(_0x278b57)},'\x69\x73\x45\x72\x72\x6f\x72':!![]};}let _0x2fd6da=_0x27b6d6;if(this['\x68\x6f\x6f\x6b\x73']&&_0xde48d4[_0x1b6540(0x2e4)](this[_0x1b6540(0x341)]['\x73\x69\x7a\x65'],0x0)){const _0x3bbd7a=await this[_0x1b6540(0x341)][_0x1b6540(0x371)](_0x15975c,_0x27b6d6);if(_0xde48d4[_0x1b6540(0x39c)](_0x3bbd7a[_0x1b6540(0x330)],_0x1b6540(0x368)))return this[_0x1b6540(0x27f)][_0x1b6540(0x376)]({'\x74\x79\x70\x65':_0xde48d4[_0x1b6540(0x2ce)],'\x63\x74\x78':_0x15975c,'\x72\x65\x73\x75\x6c\x74':_0x27b6d6}),this[_0x1b6540(0x2b2)](_0xde48d4[_0x1b6540(0x345)]),this[_0x1b6540(0x27f)][_0x1b6540(0x376)]({'\x74\x79\x70\x65':_0x1b6540(0x385),'\x72\x65\x61\x73\x6f\x6e':_0x3bbd7a[_0x1b6540(0x25d)]}),this[_0x1b6540(0x27f)][_0x1b6540(0x3b5)](),_0x1b6540(0x368);if(_0xde48d4[_0x1b6540(0x233)](_0x3bbd7a[_0x1b6540(0x330)],_0xde48d4[_0x1b6540(0x2bf)]))_0x2fd6da=_0x3bbd7a[_0x1b6540(0x2d4)];}return this[_0x1b6540(0x27f)][_0x1b6540(0x376)]({'\x74\x79\x70\x65':_0x1b6540(0x349),'\x63\x74\x78':_0x15975c,'\x72\x65\x73\x75\x6c\x74':_0x2fd6da}),_0x1b6540(0x359);}};function outcomeToFinishReason(_0x6ad156,_0x2b9b03){const _0x6f3968=a0_0x5cfbcf,_0xb5445={'\x53\x69\x63\x42\x68':'\x74\x6f\x6f\x6c\x5f\x63\x61\x6c\x6c\x73','\x6f\x7a\x61\x78\x57':'\x6c\x65\x6e\x67\x74\x68','\x6d\x73\x41\x61\x4f':_0x6f3968(0x1ed),'\x50\x57\x4e\x70\x69':_0x6f3968(0x332),'\x41\x6f\x45\x65\x47':_0x6f3968(0x2da)};switch(_0x6ad156){case'\x73\x75\x63\x63\x65\x73\x73':case _0x6f3968(0x326):case _0x6f3968(0x2e7):case _0x6f3968(0x38d):return _0x2b9b03?_0xb5445[_0x6f3968(0x328)]:_0x6f3968(0x201);case _0x6f3968(0x31c):case _0xb5445[_0x6f3968(0x1f7)]:case _0xb5445['\x6d\x73\x41\x61\x4f']:return'\x6c\x65\x6e\x67\x74\x68';case'\x63\x6f\x6e\x74\x65\x6e\x74\x5f\x66\x69\x6c\x74\x65\x72\x65\x64':case _0x6f3968(0x2da):case _0xb5445[_0x6f3968(0x2cc)]:return _0xb5445[_0x6f3968(0x29a)];default:return _0x6f3968(0x201);}}function readTokenDelta(_0x2130ce){const _0x58f1a8=a0_0x5cfbcf,_0x1defe4={'\x68\x61\x46\x52\x45':_0x58f1a8(0x2c6),'\x67\x4c\x52\x7a\x41':function(_0x44b946,_0x4da06c){return _0x44b946===_0x4da06c;}};if(typeof _0x2130ce[_0x58f1a8(0x1fe)]==='\x73\x74\x72\x69\x6e\x67')return _0x2130ce['\x64\x65\x6c\x74\x61'];if(typeof _0x2130ce['\x74\x65\x78\x74']===_0x1defe4[_0x58f1a8(0x3ab)])return _0x2130ce['\x74\x65\x78\x74'];if(_0x1defe4[_0x58f1a8(0x347)](typeof _0x2130ce[_0x58f1a8(0x28b)],_0x58f1a8(0x2c6)))return _0x2130ce[_0x58f1a8(0x28b)];return null;}function readToolInvocation(_0x1c3f7f){const _0x5766b0=a0_0x5cfbcf,_0x39e6da={'\x63\x59\x4e\x63\x7a':function(_0x1cc3e2,_0x3d1938){return _0x1cc3e2===_0x3d1938;},'\x64\x56\x67\x41\x63':_0x5766b0(0x2c6),'\x53\x7a\x4b\x74\x69':_0x5766b0(0x256),'\x78\x56\x4b\x47\x4b':function(_0x5de7cc,_0x5c9693){return _0x5de7cc===_0x5c9693;},'\x42\x48\x5a\x66\x65':function(_0x171e97,_0x2b0e88){return _0x171e97===_0x2b0e88;},'\x48\x46\x55\x4c\x57':function(_0x3acabd,_0x223daa){return _0x3acabd===_0x223daa;},'\x48\x67\x42\x72\x51':function(_0x417f08,_0x560b07){return _0x417f08||_0x560b07;}};if(_0x1c3f7f['\x74\x79\x70\x65']!==_0x5766b0(0x25f))return null;const _0x447657=_0x1c3f7f[_0x5766b0(0x321)]??_0x1c3f7f,_0x35b4e9=_0x39e6da[_0x5766b0(0x2f0)](typeof _0x447657[_0x5766b0(0x382)],_0x5766b0(0x2c6))?_0x447657[_0x5766b0(0x382)]:typeof _0x1c3f7f[_0x5766b0(0x382)]===_0x39e6da[_0x5766b0(0x38f)]?_0x1c3f7f['\x74\x79\x70\x65']:'';if(!(_0x35b4e9===_0x5766b0(0x20a)||_0x35b4e9==='\x74\x6f\x6f\x6c\x5f\x63\x61\x6c\x6c'||_0x39e6da['\x63\x59\x4e\x63\x7a'](typeof _0x447657[_0x5766b0(0x354)],_0x5766b0(0x256))||typeof _0x447657[_0x5766b0(0x3be)]===_0x39e6da['\x53\x7a\x4b\x74\x69']))return null;const _0x965949=_0x447657['\x74\x6f\x6f\x6c\x49\x6e\x76\x6f\x63\x61\x74\x69\x6f\x6e']??_0x447657[_0x5766b0(0x3be)]??_0x447657,_0x42f4e8=_0x39e6da[_0x5766b0(0x254)](typeof _0x965949[_0x5766b0(0x234)],_0x39e6da[_0x5766b0(0x38f)])?_0x965949[_0x5766b0(0x234)]:typeof _0x965949[_0x5766b0(0x20e)]===_0x39e6da[_0x5766b0(0x38f)]?_0x965949['\x74\x6f\x6f\x6c\x5f\x63\x61\x6c\x6c\x5f\x69\x64']:_0x39e6da[_0x5766b0(0x375)](typeof _0x965949['\x69\x64'],_0x5766b0(0x2c6))?_0x965949['\x69\x64']:typeof _0x965949['\x63\x61\x6c\x6c\x49\x64']===_0x5766b0(0x2c6)?_0x965949[_0x5766b0(0x273)]:'',_0x488555=typeof _0x965949[_0x5766b0(0x351)]===_0x5766b0(0x2c6)?_0x965949['\x74\x6f\x6f\x6c\x4e\x61\x6d\x65']:_0x39e6da[_0x5766b0(0x2b4)](typeof _0x965949[_0x5766b0(0x308)],'\x73\x74\x72\x69\x6e\x67')?_0x965949[_0x5766b0(0x308)]:typeof _0x965949['\x6e\x61\x6d\x65']===_0x39e6da['\x64\x56\x67\x41\x63']?_0x965949['\x6e\x61\x6d\x65']:'',_0x3fb7b1=_0x965949['\x61\x72\x67\x73']??_0x965949[_0x5766b0(0x2b7)]??_0x965949[_0x5766b0(0x28c)]??{};if(_0x39e6da['\x48\x67\x42\x72\x51'](!_0x42f4e8,!_0x488555))return null;return{'\x69\x64':_0x42f4e8,'\x6e\x61\x6d\x65':_0x488555,'\x61\x72\x67\x75\x6d\x65\x6e\x74\x73':typeof _0x3fb7b1==='\x73\x74\x72\x69\x6e\x67'?_0x3fb7b1:JSON[_0x5766b0(0x2f9)](_0x3fb7b1)};}function readUsage(_0x28082a){const _0x1590dd=a0_0x5cfbcf,_0x424980={'\x50\x43\x57\x67\x46':function(_0x2f38ce,_0x501003){return _0x2f38ce(_0x501003);},'\x6f\x4e\x52\x67\x59':function(_0x1ecd07,_0x31e2ed){return _0x1ecd07===_0x31e2ed;},'\x50\x6f\x6c\x4c\x54':function(_0x50410a,_0x269ff2){return _0x50410a+_0x269ff2;}},_0x2c0472=_0x28082a[_0x1590dd(0x353)]??_0x28082a,_0x59f63d=Number(_0x2c0472[_0x1590dd(0x277)]??_0x2c0472[_0x1590dd(0x25c)]??_0x2c0472[_0x1590dd(0x342)]??0x0),_0x5e4aba=_0x424980[_0x1590dd(0x335)](Number,_0x2c0472['\x63\x6f\x6d\x70\x6c\x65\x74\x69\x6f\x6e\x5f\x74\x6f\x6b\x65\x6e\x73']??_0x2c0472[_0x1590dd(0x343)]??_0x2c0472[_0x1590dd(0x26e)]??0x0);if(_0x59f63d===0x0&&_0x424980[_0x1590dd(0x296)](_0x5e4aba,0x0))return null;return{'\x70\x72\x6f\x6d\x70\x74\x5f\x74\x6f\x6b\x65\x6e\x73':_0x59f63d,'\x63\x6f\x6d\x70\x6c\x65\x74\x69\x6f\x6e\x5f\x74\x6f\x6b\x65\x6e\x73':_0x5e4aba,'\x74\x6f\x74\x61\x6c\x5f\x74\x6f\x6b\x65\x6e\x73':Number(_0x2c0472[_0x1590dd(0x2bc)]??_0x424980[_0x1590dd(0x2ef)](_0x59f63d,_0x5e4aba))};}function readOutcome(_0x368e99){const _0x34c2f4=a0_0x5cfbcf,_0x1154f0={'\x52\x72\x55\x78\x4e':function(_0x117976,_0x20e092){return _0x117976===_0x20e092;},'\x7a\x6a\x42\x65\x67':function(_0x7ef184,_0x5a685a){return _0x7ef184===_0x5a685a;}};if(typeof _0x368e99[_0x34c2f4(0x2fd)]===_0x34c2f4(0x2c6))return _0x368e99['\x6f\x75\x74\x63\x6f\x6d\x65'];if(_0x1154f0['\x52\x72\x55\x78\x4e'](typeof _0x368e99[_0x34c2f4(0x2d8)],_0x34c2f4(0x2c6)))return _0x368e99[_0x34c2f4(0x2d8)];if(_0x1154f0[_0x34c2f4(0x278)](_0x368e99[_0x34c2f4(0x3cb)],![]))return _0x34c2f4(0x285);return _0x34c2f4(0x3cb);}function chatBaseChunk(_0x248966){const _0x5cc6de=a0_0x5cfbcf;return _0x248966[_0x5cc6de(0x338)]+=0x1,{'\x69\x64':_0x248966[_0x5cc6de(0x37c)],'\x63\x72\x65\x61\x74\x65\x64':_0x248966[_0x5cc6de(0x2e2)],'\x6d\x6f\x64\x65\x6c':_0x248966['\x6d\x6f\x64\x65\x6c\x49\x64'],'\x6f\x62\x6a\x65\x63\x74':'\x63\x68\x61\x74\x2e\x63\x6f\x6d\x70\x6c\x65\x74\x69\x6f\x6e\x2e\x63\x68\x75\x6e\x6b'};}function sandboxEventToChatChunk(_0x5f006e,_0x591202){const _0x4ecbd4=a0_0x5cfbcf,_0x339078={'\x55\x73\x68\x65\x4f':_0x4ecbd4(0x2d8),'\x50\x6b\x69\x6b\x64':function(_0x582dc2,_0xfc4a3f){return _0x582dc2===_0xfc4a3f;},'\x46\x68\x79\x7a\x57':function(_0x2152b5,_0x3965c0){return _0x2152b5(_0x3965c0);},'\x70\x65\x75\x78\x66':_0x4ecbd4(0x25f),'\x68\x6a\x45\x6f\x62':function(_0x28fb2f,_0x2607dd){return _0x28fb2f>_0x2607dd;},'\x62\x68\x51\x79\x52':function(_0x42573c,_0x3567e0){return _0x42573c(_0x3567e0);},'\x70\x6c\x7a\x4d\x6a':function(_0xc7bf46,_0x17b2ee,_0x2c67d7){return _0xc7bf46(_0x17b2ee,_0x2c67d7);},'\x73\x64\x4c\x69\x51':_0x4ecbd4(0x227)};switch(_0x5f006e[_0x4ecbd4(0x382)]){case _0x4ecbd4(0x30b):return null;case'\x65\x78\x65\x63\x75\x74\x69\x6f\x6e\x2e\x73\x74\x61\x72\x74\x65\x64':return null;case _0x339078[_0x4ecbd4(0x239)]:return null;case _0x4ecbd4(0x3cc):return null;case _0x4ecbd4(0x24c):return null;case _0x4ecbd4(0x28b):{const _0x30ba44=readTokenDelta(_0x5f006e);if(_0x30ba44==null||_0x339078[_0x4ecbd4(0x240)](_0x30ba44[_0x4ecbd4(0x2a8)],0x0))return null;return{..._0x339078[_0x4ecbd4(0x3b0)](chatBaseChunk,_0x591202),'\x63\x68\x6f\x69\x63\x65\x73':[{'\x69\x6e\x64\x65\x78':0x0,'\x64\x65\x6c\x74\x61':{'\x72\x6f\x6c\x65':_0x4ecbd4(0x2cd),'\x63\x6f\x6e\x74\x65\x6e\x74':_0x30ba44},'\x66\x69\x6e\x69\x73\x68\x5f\x72\x65\x61\x73\x6f\x6e':null}]};}case _0x339078[_0x4ecbd4(0x2f3)]:{const _0x5aa2db=readToolInvocation(_0x5f006e);if(!_0x5aa2db)return null;const _0x53bd5b=_0x591202[_0x4ecbd4(0x33e)][_0x4ecbd4(0x247)](_0x5aa2db['\x69\x64']),_0x4fe906=_0x53bd5b?_0x53bd5b[_0x4ecbd4(0x27b)]:_0x591202[_0x4ecbd4(0x33e)][_0x4ecbd4(0x220)];return _0x591202[_0x4ecbd4(0x33e)][_0x4ecbd4(0x21a)](_0x5aa2db['\x69\x64'],{'\x69\x6e\x64\x65\x78':_0x4fe906,'\x69\x64':_0x5aa2db['\x69\x64'],'\x6e\x61\x6d\x65':_0x5aa2db[_0x4ecbd4(0x306)],'\x61\x72\x67\x75\x6d\x65\x6e\x74\x73':_0x5aa2db[_0x4ecbd4(0x2b7)]}),{...chatBaseChunk(_0x591202),'\x63\x68\x6f\x69\x63\x65\x73':[{'\x69\x6e\x64\x65\x78':0x0,'\x64\x65\x6c\x74\x61':{'\x72\x6f\x6c\x65':_0x4ecbd4(0x2cd),'\x74\x6f\x6f\x6c\x5f\x63\x61\x6c\x6c\x73':[{'\x69\x6e\x64\x65\x78':_0x4fe906,'\x69\x64':_0x5aa2db['\x69\x64'],'\x74\x79\x70\x65':_0x4ecbd4(0x30e),'\x66\x75\x6e\x63\x74\x69\x6f\x6e':{'\x6e\x61\x6d\x65':_0x5aa2db['\x6e\x61\x6d\x65'],'\x61\x72\x67\x75\x6d\x65\x6e\x74\x73':_0x5aa2db[_0x4ecbd4(0x2b7)]}}]},'\x66\x69\x6e\x69\x73\x68\x5f\x72\x65\x61\x73\x6f\x6e':null}]};}case _0x4ecbd4(0x227):{const _0x3035d1=_0x339078[_0x4ecbd4(0x1e8)](_0x591202[_0x4ecbd4(0x33e)][_0x4ecbd4(0x220)],0x0);return{..._0x339078[_0x4ecbd4(0x370)](chatBaseChunk,_0x591202),'\x63\x68\x6f\x69\x63\x65\x73':[{'\x69\x6e\x64\x65\x78':0x0,'\x64\x65\x6c\x74\x61':{},'\x66\x69\x6e\x69\x73\x68\x5f\x72\x65\x61\x73\x6f\x6e':_0x339078['\x70\x6c\x7a\x4d\x6a'](outcomeToFinishReason,_0x339078[_0x4ecbd4(0x304)],_0x3035d1)}]};}case'\x64\x6f\x6e\x65':{const _0x31d20d=_0x591202['\x74\x6f\x6f\x6c\x43\x61\x6c\x6c\x42\x75\x66\x66\x65\x72'][_0x4ecbd4(0x220)]>0x0,_0x7d1870=outcomeToFinishReason(readOutcome(_0x5f006e),_0x31d20d),_0x43646e=readUsage(_0x5f006e),_0x40c62c={..._0x339078[_0x4ecbd4(0x370)](chatBaseChunk,_0x591202),'\x63\x68\x6f\x69\x63\x65\x73':[{'\x69\x6e\x64\x65\x78':0x0,'\x64\x65\x6c\x74\x61':{},'\x66\x69\x6e\x69\x73\x68\x5f\x72\x65\x61\x73\x6f\x6e':_0x7d1870}]};if(_0x43646e)_0x40c62c['\x75\x73\x61\x67\x65']=_0x43646e;return _0x40c62c;}default:return null;}}function completionBaseChunk(_0x384e3d){const _0x20eff7=a0_0x5cfbcf,_0x270efc={'\x4a\x71\x45\x69\x6a':'\x74\x65\x78\x74\x5f\x63\x6f\x6d\x70\x6c\x65\x74\x69\x6f\x6e'};return _0x384e3d[_0x20eff7(0x338)]+=0x1,{'\x69\x64':_0x384e3d['\x72\x75\x6e\x49\x64'],'\x63\x72\x65\x61\x74\x65\x64':_0x384e3d[_0x20eff7(0x2e2)],'\x6d\x6f\x64\x65\x6c':_0x384e3d[_0x20eff7(0x2c0)],'\x6f\x62\x6a\x65\x63\x74':_0x270efc[_0x20eff7(0x320)]};}function sandboxEventToCompletionChunk(_0x3bd4df,_0x571b27){const _0x2fc212=a0_0x5cfbcf,_0x465f70={'\x6b\x68\x79\x78\x4d':_0x2fc212(0x214),'\x6f\x59\x4c\x54\x61':'\x73\x74\x61\x74\x75\x73','\x42\x42\x6f\x6d\x42':_0x2fc212(0x24c),'\x4b\x65\x4d\x57\x67':function(_0xf95f49,_0x3e3acc){return _0xf95f49===_0x3e3acc;},'\x46\x59\x71\x47\x58':_0x2fc212(0x25f),'\x66\x77\x53\x4b\x73':_0x2fc212(0x28b),'\x70\x70\x58\x5a\x58':function(_0x4cd9a9,_0x46076f){return _0x4cd9a9(_0x46076f);},'\x52\x4d\x48\x6b\x47':_0x2fc212(0x227)};switch(_0x3bd4df[_0x2fc212(0x382)]){case'\x73\x74\x61\x72\x74':case _0x465f70[_0x2fc212(0x38c)]:case _0x465f70[_0x2fc212(0x2c3)]:case _0x2fc212(0x3cc):case _0x465f70[_0x2fc212(0x357)]:case _0x2fc212(0x25f):if(_0x465f70[_0x2fc212(0x2af)](_0x3bd4df[_0x2fc212(0x382)],_0x465f70[_0x2fc212(0x292)])){const _0x1aba89=readToolInvocation(_0x3bd4df);if(_0x1aba89){const _0x580c28=_0x571b27[_0x2fc212(0x33e)][_0x2fc212(0x247)](_0x1aba89['\x69\x64']),_0x253511=_0x580c28?_0x580c28['\x69\x6e\x64\x65\x78']:_0x571b27[_0x2fc212(0x33e)][_0x2fc212(0x220)];_0x571b27[_0x2fc212(0x33e)]['\x73\x65\x74'](_0x1aba89['\x69\x64'],{'\x69\x6e\x64\x65\x78':_0x253511,'\x69\x64':_0x1aba89['\x69\x64'],'\x6e\x61\x6d\x65':_0x1aba89[_0x2fc212(0x306)],'\x61\x72\x67\x75\x6d\x65\x6e\x74\x73':_0x1aba89[_0x2fc212(0x2b7)]});}}return null;case _0x465f70['\x66\x77\x53\x4b\x73']:{const _0x1eb131=readTokenDelta(_0x3bd4df);if(_0x1eb131==null||_0x1eb131[_0x2fc212(0x2a8)]===0x0)return null;return{..._0x465f70[_0x2fc212(0x1f9)](completionBaseChunk,_0x571b27),'\x63\x68\x6f\x69\x63\x65\x73':[{'\x69\x6e\x64\x65\x78':0x0,'\x74\x65\x78\x74':_0x1eb131,'\x66\x69\x6e\x69\x73\x68\x5f\x72\x65\x61\x73\x6f\x6e':null,'\x6c\x6f\x67\x70\x72\x6f\x62\x73':null}]};}case _0x465f70['\x52\x4d\x48\x6b\x47']:case _0x2fc212(0x38d):{const _0x1eb3a5=outcomeToFinishReason(_0x3bd4df[_0x2fc212(0x382)]==='\x65\x72\x72\x6f\x72'?_0x465f70[_0x2fc212(0x3c7)]:_0x465f70['\x70\x70\x58\x5a\x58'](readOutcome,_0x3bd4df),![]),_0x23475e=_0x1eb3a5===_0x2fc212(0x272)?_0x2fc212(0x201):_0x1eb3a5,_0x4a2e72=readUsage(_0x3bd4df),_0x53e195={...completionBaseChunk(_0x571b27),'\x63\x68\x6f\x69\x63\x65\x73':[{'\x69\x6e\x64\x65\x78':0x0,'\x74\x65\x78\x74':'','\x66\x69\x6e\x69\x73\x68\x5f\x72\x65\x61\x73\x6f\x6e':_0x23475e,'\x6c\x6f\x67\x70\x72\x6f\x62\x73':null}]};if(_0x4a2e72)_0x53e195[_0x2fc212(0x353)]=_0x4a2e72;return _0x53e195;}default:return null;}}function getResponsesExtras(_0xcab261){const _0x3da03c=a0_0x5cfbcf,_0x37c0e3=_0xcab261;if(!_0x37c0e3[_0x3da03c(0x264)])_0x37c0e3['\x5f\x5f\x72\x65\x73\x70\x6f\x6e\x73\x65\x73\x45\x78\x74\x72\x61\x73']={'\x73\x65\x71\x75\x65\x6e\x63\x65':0x0,'\x74\x6f\x6f\x6c\x4f\x75\x74\x70\x75\x74\x49\x6e\x64\x65\x78':new Map()};return _0x37c0e3[_0x3da03c(0x264)];}function nextSeq(_0x2e7b91){const _0x545eb7=a0_0x5cfbcf;return _0x2e7b91[_0x545eb7(0x29b)]+=0x1,_0x2e7b91[_0x545eb7(0x29b)];}function emptyResponseUsage(){return{'\x69\x6e\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73':0x0,'\x6f\x75\x74\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73':0x0,'\x74\x6f\x74\x61\x6c\x5f\x74\x6f\x6b\x65\x6e\x73':0x0,'\x69\x6e\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73\x5f\x64\x65\x74\x61\x69\x6c\x73':{'\x63\x61\x63\x68\x65\x64\x5f\x74\x6f\x6b\x65\x6e\x73':0x0},'\x6f\x75\x74\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73\x5f\x64\x65\x74\x61\x69\x6c\x73':{'\x72\x65\x61\x73\x6f\x6e\x69\x6e\x67\x5f\x74\x6f\x6b\x65\x6e\x73':0x0}};}function usageFromTokens(_0x82423d){const _0x4be04d=a0_0x5cfbcf;return{'\x69\x6e\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73':_0x82423d[_0x4be04d(0x277)],'\x6f\x75\x74\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73':_0x82423d[_0x4be04d(0x20b)],'\x74\x6f\x74\x61\x6c\x5f\x74\x6f\x6b\x65\x6e\x73':_0x82423d[_0x4be04d(0x2bc)],'\x69\x6e\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73\x5f\x64\x65\x74\x61\x69\x6c\x73':{'\x63\x61\x63\x68\x65\x64\x5f\x74\x6f\x6b\x65\x6e\x73':0x0},'\x6f\x75\x74\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73\x5f\x64\x65\x74\x61\x69\x6c\x73':{'\x72\x65\x61\x73\x6f\x6e\x69\x6e\x67\x5f\x74\x6f\x6b\x65\x6e\x73':0x0}};}function sandboxEventToResponsesEvent(_0x4e0d3d,_0x54becb){const _0x33cb08=a0_0x5cfbcf,_0x5ea06d={'\x79\x43\x6e\x6a\x6e':_0x33cb08(0x28b),'\x42\x52\x59\x7a\x4a':'\x72\x65\x73\x70\x6f\x6e\x73\x65\x2e\x6f\x75\x74\x70\x75\x74\x5f\x74\x65\x78\x74\x2e\x64\x65\x6c\x74\x61','\x58\x56\x6a\x6b\x69':function(_0x36beab,_0x4cf639){return _0x36beab(_0x4cf639);},'\x66\x59\x68\x44\x51':_0x33cb08(0x3b4),'\x61\x4a\x66\x71\x5a':_0x33cb08(0x2ae),'\x6d\x41\x6a\x45\x6c':_0x33cb08(0x2d7),'\x53\x63\x73\x67\x56':_0x33cb08(0x36a),'\x77\x4e\x42\x75\x62':function(_0x1947dd,_0x1762ca){return _0x1947dd(_0x1762ca);},'\x68\x53\x69\x58\x4e':_0x33cb08(0x38d),'\x71\x70\x4a\x4c\x43':function(_0x5ea763,_0x2b7aef){return _0x5ea763(_0x2b7aef);}},_0x50ef75=getResponsesExtras(_0x54becb);switch(_0x4e0d3d[_0x33cb08(0x382)]){case _0x33cb08(0x30b):return null;case _0x33cb08(0x214):return null;case _0x33cb08(0x2d8):return null;case _0x33cb08(0x3cc):return null;case _0x33cb08(0x24c):return null;case _0x5ea06d[_0x33cb08(0x2a4)]:{const _0x500339=readTokenDelta(_0x4e0d3d);if(_0x500339==null||_0x500339[_0x33cb08(0x2a8)]===0x0)return null;_0x54becb[_0x33cb08(0x338)]+=0x1;if(_0x50ef75['\x6d\x65\x73\x73\x61\x67\x65\x4f\x75\x74\x70\x75\x74\x49\x6e\x64\x65\x78']===void 0x0)_0x50ef75['\x6d\x65\x73\x73\x61\x67\x65\x4f\x75\x74\x70\x75\x74\x49\x6e\x64\x65\x78']=_0x54becb['\x74\x6f\x6f\x6c\x43\x61\x6c\x6c\x42\x75\x66\x66\x65\x72']['\x73\x69\x7a\x65'];return{'\x74\x79\x70\x65':_0x5ea06d['\x42\x52\x59\x7a\x4a'],'\x63\x6f\x6e\x74\x65\x6e\x74\x5f\x69\x6e\x64\x65\x78':0x0,'\x64\x65\x6c\x74\x61':_0x500339,'\x69\x74\x65\x6d\x5f\x69\x64':'\x6d\x73\x67\x5f'+_0x54becb[_0x33cb08(0x37c)],'\x6c\x6f\x67\x70\x72\x6f\x62\x73':[],'\x6f\x75\x74\x70\x75\x74\x5f\x69\x6e\x64\x65\x78':_0x50ef75[_0x33cb08(0x2c5)],'\x73\x65\x71\x75\x65\x6e\x63\x65\x5f\x6e\x75\x6d\x62\x65\x72':_0x5ea06d[_0x33cb08(0x2b8)](nextSeq,_0x50ef75)};}case'\x72\x61\x77':{const _0x2b2969=_0x5ea06d[_0x33cb08(0x2b8)](readToolInvocation,_0x4e0d3d);if(!_0x2b2969)return null;_0x54becb['\x63\x68\x75\x6e\x6b\x49\x6e\x64\x65\x78']+=0x1;const _0x392642=_0x54becb[_0x33cb08(0x33e)]['\x67\x65\x74'](_0x2b2969['\x69\x64']),_0x4c657a=_0x392642?_0x392642[_0x33cb08(0x27b)]:_0x54becb['\x74\x6f\x6f\x6c\x43\x61\x6c\x6c\x42\x75\x66\x66\x65\x72'][_0x33cb08(0x220)];_0x54becb[_0x33cb08(0x33e)][_0x33cb08(0x21a)](_0x2b2969['\x69\x64'],{'\x69\x6e\x64\x65\x78':_0x4c657a,'\x69\x64':_0x2b2969['\x69\x64'],'\x6e\x61\x6d\x65':_0x2b2969[_0x33cb08(0x306)],'\x61\x72\x67\x75\x6d\x65\x6e\x74\x73':_0x2b2969['\x61\x72\x67\x75\x6d\x65\x6e\x74\x73']});const _0x268eb9=_0x50ef75[_0x33cb08(0x22b)][_0x33cb08(0x247)](_0x2b2969['\x69\x64'])??_0x50ef75[_0x33cb08(0x22b)][_0x33cb08(0x220)];return _0x50ef75[_0x33cb08(0x22b)]['\x73\x65\x74'](_0x2b2969['\x69\x64'],_0x268eb9),{'\x74\x79\x70\x65':_0x5ea06d[_0x33cb08(0x29f)],'\x69\x74\x65\x6d':{'\x74\x79\x70\x65':_0x5ea06d[_0x33cb08(0x1f8)],'\x69\x64':_0x33cb08(0x243)+_0x2b2969['\x69\x64'],'\x63\x61\x6c\x6c\x5f\x69\x64':_0x2b2969['\x69\x64'],'\x6e\x61\x6d\x65':_0x2b2969[_0x33cb08(0x306)],'\x61\x72\x67\x75\x6d\x65\x6e\x74\x73':_0x2b2969[_0x33cb08(0x2b7)],'\x73\x74\x61\x74\x75\x73':_0x33cb08(0x2e7)},'\x6f\x75\x74\x70\x75\x74\x5f\x69\x6e\x64\x65\x78':_0x268eb9,'\x73\x65\x71\x75\x65\x6e\x63\x65\x5f\x6e\x75\x6d\x62\x65\x72':nextSeq(_0x50ef75)};}case _0x33cb08(0x227):{const _0x4cf219=_0x50ef75['\x6d\x65\x73\x73\x61\x67\x65\x4f\x75\x74\x70\x75\x74\x49\x6e\x64\x65\x78']??0x0;return{'\x74\x79\x70\x65':'\x72\x65\x73\x70\x6f\x6e\x73\x65\x2e\x6f\x75\x74\x70\x75\x74\x5f\x69\x74\x65\x6d\x2e\x64\x6f\x6e\x65','\x69\x74\x65\x6d':{'\x74\x79\x70\x65':_0x5ea06d[_0x33cb08(0x24b)],'\x69\x64':'\x6d\x73\x67\x5f'+_0x54becb[_0x33cb08(0x37c)],'\x72\x6f\x6c\x65':_0x33cb08(0x2cd),'\x73\x74\x61\x74\x75\x73':_0x5ea06d[_0x33cb08(0x331)],'\x63\x6f\x6e\x74\x65\x6e\x74':[]},'\x6f\x75\x74\x70\x75\x74\x5f\x69\x6e\x64\x65\x78':_0x4cf219,'\x73\x65\x71\x75\x65\x6e\x63\x65\x5f\x6e\x75\x6d\x62\x65\x72':_0x5ea06d[_0x33cb08(0x3a7)](nextSeq,_0x50ef75)};}case _0x5ea06d[_0x33cb08(0x2c8)]:{const _0x1fdb95=_0x5ea06d['\x71\x70\x4a\x4c\x43'](readUsage,_0x4e0d3d),_0x5f41fd=_0x1fdb95?_0x5ea06d[_0x33cb08(0x2b8)](usageFromTokens,_0x1fdb95):emptyResponseUsage();return{'\x74\x79\x70\x65':_0x33cb08(0x245),'\x73\x65\x71\x75\x65\x6e\x63\x65\x5f\x6e\x75\x6d\x62\x65\x72':nextSeq(_0x50ef75),'\x72\x65\x73\x70\x6f\x6e\x73\x65':{'\x69\x64':_0x54becb[_0x33cb08(0x37c)],'\x6f\x62\x6a\x65\x63\x74':_0x33cb08(0x2b5),'\x63\x72\x65\x61\x74\x65\x64\x5f\x61\x74':_0x54becb['\x63\x72\x65\x61\x74\x65\x64\x41\x74'],'\x6f\x75\x74\x70\x75\x74\x5f\x74\x65\x78\x74':'','\x65\x72\x72\x6f\x72':null,'\x69\x6e\x63\x6f\x6d\x70\x6c\x65\x74\x65\x5f\x64\x65\x74\x61\x69\x6c\x73':null,'\x69\x6e\x73\x74\x72\x75\x63\x74\x69\x6f\x6e\x73':null,'\x6d\x65\x74\x61\x64\x61\x74\x61':null,'\x6d\x6f\x64\x65\x6c':_0x54becb[_0x33cb08(0x2c0)],'\x6f\x75\x74\x70\x75\x74':[],'\x70\x61\x72\x61\x6c\x6c\x65\x6c\x5f\x74\x6f\x6f\x6c\x5f\x63\x61\x6c\x6c\x73':![],'\x74\x65\x6d\x70\x65\x72\x61\x74\x75\x72\x65':null,'\x74\x6f\x6f\x6c\x5f\x63\x68\x6f\x69\x63\x65':_0x33cb08(0x3c5),'\x74\x6f\x6f\x6c\x73':[],'\x74\x6f\x70\x5f\x70':null,'\x73\x74\x61\x74\x75\x73':_0x33cb08(0x2e7),'\x75\x73\x61\x67\x65':_0x5f41fd}};}default:return null;}}var EmbeddingValidationError=class extends Error{[a0_0x5cfbcf(0x382)]='\x69\x6e\x76\x61\x6c\x69\x64\x5f\x72\x65\x71\x75\x65\x73\x74\x5f\x65\x72\x72\x6f\x72';[a0_0x5cfbcf(0x395)];[a0_0x5cfbcf(0x2d3)];constructor(_0x5d1942,_0x5f449e,_0x5b5ee4){const _0x5e9161=a0_0x5cfbcf;super(_0x5d1942),this['\x6e\x61\x6d\x65']=_0x5e9161(0x361),this[_0x5e9161(0x395)]=_0x5f449e,this[_0x5e9161(0x2d3)]=_0x5b5ee4;}};const MAX_BATCH=0x800;function reject(_0x1d6f91,_0x13b8f9,_0x4c3df7){throw new EmbeddingValidationError(_0x1d6f91,_0x13b8f9,_0x4c3df7);}function normalizeInput(_0x5ab0db){const _0x35a015=a0_0x5cfbcf,_0x3e8f72={'\x6b\x52\x42\x6a\x65':function(_0xab5a84,_0x32a717){return _0xab5a84===_0x32a717;},'\x52\x77\x74\x69\x51':function(_0x2dcab7,_0x3ef857,_0x32af06,_0x674d24){return _0x2dcab7(_0x3ef857,_0x32af06,_0x674d24);},'\x78\x58\x79\x74\x6f':'\x49\x6e\x70\x75\x74\x20\x6d\x75\x73\x74\x20\x62\x65\x20\x61\x20\x73\x74\x72\x69\x6e\x67\x2c\x20\x61\x72\x72\x61\x79\x20\x6f\x66\x20\x73\x74\x72\x69\x6e\x67\x73\x2c\x20\x6f\x72\x20\x61\x72\x72\x61\x79\x20\x6f\x66\x20\x74\x6f\x6b\x65\x6e\x20\x61\x72\x72\x61\x79\x73','\x6f\x52\x6f\x50\x4b':_0x35a015(0x34f),'\x57\x52\x49\x4c\x70':_0x35a015(0x38b),'\x72\x49\x57\x69\x6a':function(_0x2c210d,_0x45525b,_0x59c193,_0xa7d7d8){return _0x2c210d(_0x45525b,_0x59c193,_0xa7d7d8);},'\x4a\x45\x66\x6e\x6d':_0x35a015(0x28c),'\x44\x6d\x77\x4b\x58':function(_0x568a35,_0x2405b9){return _0x568a35===_0x2405b9;},'\x72\x45\x63\x7a\x68':'\x73\x74\x72\x69\x6e\x67','\x49\x77\x6f\x49\x49':_0x35a015(0x21f),'\x61\x58\x78\x50\x66':function(_0x36677b,_0x217ef0){return _0x36677b===_0x217ef0;},'\x70\x68\x79\x6d\x68':_0x35a015(0x31a),'\x7a\x6d\x78\x53\x42':function(_0x4f3784,_0x20d599){return _0x4f3784<_0x20d599;},'\x6c\x65\x4f\x4b\x4d':function(_0x3f6c92,_0x49f179){return _0x3f6c92===_0x49f179;},'\x61\x54\x63\x68\x6b':function(_0x4b7535,_0x50f759){return _0x4b7535!==_0x50f759;},'\x66\x71\x69\x75\x43':'\x69\x6e\x76\x61\x6c\x69\x64\x5f\x74\x6f\x6b\x65\x6e\x5f\x74\x79\x70\x65','\x77\x75\x63\x61\x51':_0x35a015(0x2f4)};if(typeof _0x5ab0db===_0x35a015(0x2c6)){if(_0x3e8f72[_0x35a015(0x3ba)](_0x5ab0db[_0x35a015(0x2a8)],0x0))_0x3e8f72[_0x35a015(0x37a)](reject,_0x35a015(0x2e9),'\x65\x6d\x70\x74\x79\x5f\x69\x6e\x70\x75\x74',_0x35a015(0x28c));return{'\x6b\x69\x6e\x64':_0x35a015(0x20f),'\x76\x61\x6c\x75\x65\x73':[_0x5ab0db]};}if(!Array[_0x35a015(0x24f)](_0x5ab0db))_0x3e8f72[_0x35a015(0x37a)](reject,_0x3e8f72[_0x35a015(0x34b)],_0x3e8f72[_0x35a015(0x3a1)],_0x35a015(0x28c));if(_0x5ab0db[_0x35a015(0x2a8)]===0x0)reject('\x49\x6e\x70\x75\x74\x20\x61\x72\x72\x61\x79\x20\x6d\x75\x73\x74\x20\x6e\x6f\x74\x20\x62\x65\x20\x65\x6d\x70\x74\x79',_0x3e8f72[_0x35a015(0x295)],_0x35a015(0x28c));if(_0x5ab0db[_0x35a015(0x2a8)]>MAX_BATCH)_0x3e8f72[_0x35a015(0x3b6)](reject,_0x35a015(0x28a)+MAX_BATCH,_0x35a015(0x36d),_0x3e8f72[_0x35a015(0x27e)]);const _0xca8ef6=_0x5ab0db[0x0];if(_0x3e8f72[_0x35a015(0x315)](typeof _0xca8ef6,_0x3e8f72[_0x35a015(0x31f)])){const _0x518ce2=[];for(let _0x5c6435=0x0;_0x5c6435<_0x5ab0db['\x6c\x65\x6e\x67\x74\x68'];_0x5c6435++){const _0x22b40a=_0x5ab0db[_0x5c6435];if(typeof _0x22b40a!==_0x35a015(0x2c6))reject(_0x35a015(0x380)+_0x5c6435+_0x35a015(0x37b),_0x3e8f72[_0x35a015(0x372)],_0x35a015(0x28c));if(_0x22b40a[_0x35a015(0x2a8)]===0x0)_0x3e8f72[_0x35a015(0x3b6)](reject,'\x49\x6e\x70\x75\x74\x20\x73\x74\x72\x69\x6e\x67\x20\x61\x74\x20\x69\x6e\x64\x65\x78\x20'+_0x5c6435+_0x35a015(0x355),_0x35a015(0x38b),'\x69\x6e\x70\x75\x74');_0x518ce2[_0x35a015(0x376)](_0x22b40a);}return{'\x6b\x69\x6e\x64':_0x35a015(0x20f),'\x76\x61\x6c\x75\x65\x73':_0x518ce2};}if(_0x3e8f72[_0x35a015(0x2c2)](typeof _0xca8ef6,_0x3e8f72[_0x35a015(0x3cf)])){for(let _0x4b6bca=0x0;_0x4b6bca<_0x5ab0db[_0x35a015(0x2a8)];_0x4b6bca++)if(typeof _0x5ab0db[_0x4b6bca]!=='\x6e\x75\x6d\x62\x65\x72')reject('\x54\x6f\x6b\x65\x6e\x20\x61\x72\x72\x61\x79\x20\x6d\x75\x73\x74\x20\x63\x6f\x6e\x74\x61\x69\x6e\x20\x6f\x6e\x6c\x79\x20\x6e\x75\x6d\x62\x65\x72\x73\x3b\x20\x69\x6e\x64\x65\x78\x20'+_0x4b6bca+_0x35a015(0x21d)+typeof _0x5ab0db[_0x4b6bca],_0x35a015(0x1e9),_0x3e8f72['\x4a\x45\x66\x6e\x6d']);return{'\x6b\x69\x6e\x64':'\x74\x6f\x6b\x65\x6e\x73','\x76\x61\x6c\x75\x65\x73':[_0x5ab0db]};}if(Array[_0x35a015(0x24f)](_0xca8ef6)){const _0x17e590=[];for(let _0x465a95=0x0;_0x3e8f72[_0x35a015(0x27a)](_0x465a95,_0x5ab0db[_0x35a015(0x2a8)]);_0x465a95++){const _0x4d1dc1=_0x5ab0db[_0x465a95];if(!Array['\x69\x73\x41\x72\x72\x61\x79'](_0x4d1dc1))reject(_0x35a015(0x380)+_0x465a95+_0x35a015(0x3b3),_0x35a015(0x21f),_0x3e8f72[_0x35a015(0x27e)]);if(_0x3e8f72[_0x35a015(0x2f8)](_0x4d1dc1[_0x35a015(0x2a8)],0x0))reject(_0x35a015(0x22c)+_0x465a95+'\x20\x6d\x75\x73\x74\x20\x6e\x6f\x74\x20\x62\x65\x20\x65\x6d\x70\x74\x79',_0x35a015(0x38b),'\x69\x6e\x70\x75\x74');for(let _0x428983=0x0;_0x428983<_0x4d1dc1['\x6c\x65\x6e\x67\x74\x68'];_0x428983++)if(_0x3e8f72[_0x35a015(0x2e5)](typeof _0x4d1dc1[_0x428983],'\x6e\x75\x6d\x62\x65\x72'))_0x3e8f72['\x72\x49\x57\x69\x6a'](reject,_0x35a015(0x22c)+_0x465a95+_0x35a015(0x28f)+_0x428983+'\x20\x69\x73\x20'+typeof _0x4d1dc1[_0x428983],_0x3e8f72[_0x35a015(0x27d)],_0x3e8f72[_0x35a015(0x27e)]);_0x17e590['\x70\x75\x73\x68'](_0x4d1dc1);}return{'\x6b\x69\x6e\x64':_0x3e8f72[_0x35a015(0x1f2)],'\x76\x61\x6c\x75\x65\x73':_0x17e590};}reject(_0x3e8f72['\x78\x58\x79\x74\x6f'],_0x35a015(0x34f),_0x35a015(0x28c));}function validateEmbeddingRequest(_0x5de1d3){const _0x100517=a0_0x5cfbcf,_0x6b90b4={'\x54\x4b\x77\x58\x58':function(_0x5021df,_0x30a83a){return _0x5021df!==_0x30a83a;},'\x73\x65\x77\x66\x73':_0x100517(0x256),'\x43\x4a\x7a\x48\x5a':_0x100517(0x2a3),'\x79\x69\x75\x6b\x6d':_0x100517(0x2d2),'\x49\x4d\x58\x69\x54':function(_0x3e7308,_0x1863de){return _0x3e7308===_0x1863de;},'\x52\x75\x5a\x4f\x64':_0x100517(0x394),'\x42\x67\x75\x59\x6d':function(_0x446d66,_0x244f39){return _0x446d66!==_0x244f39;},'\x59\x76\x50\x70\x4d':_0x100517(0x31a),'\x50\x59\x46\x68\x53':function(_0x1de08b,_0x2ac332){return _0x1de08b<=_0x2ac332;},'\x75\x53\x4f\x48\x56':_0x100517(0x318),'\x47\x71\x78\x6e\x6d':_0x100517(0x323),'\x65\x73\x70\x6b\x49':function(_0x431cbc,_0x17d4ab){return _0x431cbc!==_0x17d4ab;},'\x6a\x43\x66\x73\x43':_0x100517(0x2b6),'\x4f\x49\x51\x67\x41':function(_0xded9d5,_0x42f4d2){return _0xded9d5!==_0x42f4d2;}};if(!_0x5de1d3||_0x6b90b4['\x54\x4b\x77\x58\x58'](typeof _0x5de1d3,_0x6b90b4[_0x100517(0x2a5)]))reject(_0x6b90b4[_0x100517(0x381)],_0x6b90b4['\x79\x69\x75\x6b\x6d'],void 0x0);if(typeof _0x5de1d3[_0x100517(0x314)]!==_0x100517(0x2c6)||_0x6b90b4[_0x100517(0x39a)](_0x5de1d3[_0x100517(0x314)][_0x100517(0x2a8)],0x0))reject(_0x6b90b4[_0x100517(0x319)],_0x100517(0x316),_0x100517(0x314));if(_0x6b90b4[_0x100517(0x275)](_0x5de1d3[_0x100517(0x323)],void 0x0)){if(_0x6b90b4['\x42\x67\x75\x59\x6d'](typeof _0x5de1d3[_0x100517(0x323)],_0x6b90b4[_0x100517(0x364)])||!Number[_0x100517(0x310)](_0x5de1d3[_0x100517(0x323)])||_0x6b90b4[_0x100517(0x322)](_0x5de1d3[_0x100517(0x323)],0x0))reject(_0x6b90b4[_0x100517(0x206)],_0x100517(0x289),_0x6b90b4[_0x100517(0x30c)]);}const _0x382c7b=_0x5de1d3[_0x100517(0x388)]??_0x100517(0x3a3);if(_0x382c7b!==_0x100517(0x3a3)&&_0x6b90b4[_0x100517(0x281)](_0x382c7b,'\x62\x61\x73\x65\x36\x34'))reject(_0x100517(0x36b),_0x6b90b4[_0x100517(0x269)],_0x100517(0x388));const _0xa6aad2=normalizeInput(_0x5de1d3[_0x100517(0x28c)]),_0x193fef={'\x6d\x6f\x64\x65\x6c':_0x5de1d3[_0x100517(0x314)],'\x69\x6e\x70\x75\x74':_0xa6aad2,'\x65\x6e\x63\x6f\x64\x69\x6e\x67\x46\x6f\x72\x6d\x61\x74':_0x382c7b};if(_0x6b90b4[_0x100517(0x267)](_0x5de1d3[_0x100517(0x323)],void 0x0))_0x193fef[_0x100517(0x323)]=_0x5de1d3[_0x100517(0x323)];if(_0x5de1d3[_0x100517(0x2aa)]!==void 0x0)_0x193fef[_0x100517(0x2aa)]=_0x5de1d3[_0x100517(0x2aa)];return _0x193fef;}function resolveProviderId(_0x57fbdd){const _0x2ec622=a0_0x5cfbcf,_0x3e7313={'\x46\x70\x79\x63\x6d':function(_0xede479,_0x2cd22e){return _0xede479===_0x2cd22e;},'\x74\x43\x4e\x45\x71':function(_0x50bea8,_0x3dc69e){return _0x50bea8||_0x3dc69e;}},_0x487737=_0x57fbdd['\x74\x72\x69\x6d'](),_0x190574=_0x487737[_0x2ec622(0x2a9)](_0x2ec622(0x226))?_0x487737[_0x2ec622(0x362)](0x7):_0x487737;if(!_0x190574)throw new Error('\x49\x6e\x76\x61\x6c\x69\x64\x20\x6d\x6f\x64\x65\x6c\x20\x69\x64\x3a\x20'+JSON['\x73\x74\x72\x69\x6e\x67\x69\x66\x79'](_0x57fbdd));const _0x17d6b1=_0x190574[_0x2ec622(0x3bb)]('\x2f');if(_0x3e7313['\x46\x70\x79\x63\x6d'](_0x17d6b1,-0x1))return{'\x70\x72\x6f\x76\x69\x64\x65\x72':_0x190574};const _0x107ee0=_0x190574['\x73\x6c\x69\x63\x65'](0x0,_0x17d6b1),_0x214bc0=_0x190574[_0x2ec622(0x362)](_0x17d6b1+0x1);if(_0x3e7313[_0x2ec622(0x3ac)](!_0x107ee0,!_0x214bc0))throw new Error(_0x2ec622(0x31e)+JSON[_0x2ec622(0x2f9)](_0x57fbdd));return{'\x70\x72\x6f\x76\x69\x64\x65\x72':_0x107ee0,'\x76\x61\x72\x69\x61\x6e\x74':_0x214bc0};}function normalizeContent(_0xf0d3a9){const _0x586477=a0_0x5cfbcf,_0x2b8e26={'\x6e\x56\x78\x62\x47':_0x586477(0x2c6),'\x5a\x6f\x78\x55\x6b':_0x586477(0x20f)};if(_0xf0d3a9==null)return{'\x74\x65\x78\x74':'','\x70\x61\x72\x74\x73':[]};if(typeof _0xf0d3a9===_0x2b8e26[_0x586477(0x259)])return{'\x74\x65\x78\x74':_0xf0d3a9,'\x70\x61\x72\x74\x73':[]};const _0x404291=[],_0x22c041=[];for(const _0x6e8ed1 of _0xf0d3a9)if(_0x6e8ed1[_0x586477(0x382)]===_0x2b8e26[_0x586477(0x2f7)])_0x22c041[_0x586477(0x376)](_0x6e8ed1['\x74\x65\x78\x74']),_0x404291[_0x586477(0x376)]({'\x74\x79\x70\x65':_0x2b8e26[_0x586477(0x2f7)],'\x74\x65\x78\x74':_0x6e8ed1[_0x586477(0x20f)]});else{if(_0x6e8ed1[_0x586477(0x382)]==='\x69\x6d\x61\x67\x65\x5f\x75\x72\x6c')_0x404291[_0x586477(0x376)]({'\x74\x79\x70\x65':_0x586477(0x231),'\x69\x6d\x61\x67\x65\x5f\x75\x72\x6c':{'\x75\x72\x6c':_0x6e8ed1['\x69\x6d\x61\x67\x65\x5f\x75\x72\x6c'][_0x586477(0x24e)],'\x64\x65\x74\x61\x69\x6c':_0x6e8ed1[_0x586477(0x231)][_0x586477(0x325)]}});else{if(_0x6e8ed1['\x74\x79\x70\x65']===_0x586477(0x262))_0x404291[_0x586477(0x376)]({'\x74\x79\x70\x65':_0x586477(0x262),'\x69\x6e\x70\x75\x74\x5f\x61\x75\x64\x69\x6f':{'\x64\x61\x74\x61':_0x6e8ed1[_0x586477(0x262)][_0x586477(0x321)],'\x66\x6f\x72\x6d\x61\x74':_0x6e8ed1[_0x586477(0x262)][_0x586477(0x2fa)]}});}}return{'\x74\x65\x78\x74':_0x22c041['\x6a\x6f\x69\x6e']('\x0a'),'\x70\x61\x72\x74\x73':_0x404291};}function readAssistantText(_0x2e2e4a){const _0x276087=a0_0x5cfbcf,_0x33d5b6={'\x57\x70\x77\x6a\x43':function(_0x1e4a04,_0x5d2f81){return _0x1e4a04==_0x5d2f81;},'\x53\x50\x54\x64\x45':_0x276087(0x2c6),'\x75\x78\x69\x42\x74':function(_0x2f7932,_0x2af2c4){return _0x2f7932===_0x2af2c4;}};if(_0x33d5b6[_0x276087(0x386)](_0x2e2e4a,null))return'';if(typeof _0x2e2e4a===_0x33d5b6[_0x276087(0x208)])return _0x2e2e4a;const _0x4006cd=[];for(const _0x4bdd37 of _0x2e2e4a)if(_0x33d5b6['\x75\x78\x69\x42\x74'](_0x4bdd37[_0x276087(0x382)],_0x276087(0x20f)))_0x4006cd['\x70\x75\x73\x68'](_0x4bdd37[_0x276087(0x20f)]);else{if(_0x4bdd37[_0x276087(0x382)]==='\x72\x65\x66\x75\x73\x61\x6c')_0x4006cd[_0x276087(0x376)](_0x4bdd37[_0x276087(0x3c1)]);}return _0x4006cd[_0x276087(0x2d5)]('\x0a');}function readToolContent(_0x4c0159){const _0x3a20dd=a0_0x5cfbcf,_0x2e09f7={'\x58\x41\x73\x73\x77':_0x3a20dd(0x2c6)};if(typeof _0x4c0159===_0x2e09f7[_0x3a20dd(0x225)])return _0x4c0159;return _0x4c0159[_0x3a20dd(0x236)](_0x4a4be5=>_0x4a4be5[_0x3a20dd(0x20f)])['\x6a\x6f\x69\x6e']('\x0a');}function convertTools(_0x501652){const _0x29d34d=a0_0x5cfbcf,_0x3aaa69={'\x57\x6e\x69\x65\x4f':function(_0x26f67f,_0x4cc693){return _0x26f67f===_0x4cc693;},'\x78\x68\x61\x53\x79':function(_0x55ee3d,_0x26a876){return _0x55ee3d>_0x26a876;}};if(!_0x501652||_0x3aaa69[_0x29d34d(0x280)](_0x501652[_0x29d34d(0x2a8)],0x0))return void 0x0;const _0x1a838c=[];for(const _0x558035 of _0x501652)if(_0x3aaa69[_0x29d34d(0x280)](_0x558035['\x74\x79\x70\x65'],_0x29d34d(0x30e)))_0x1a838c[_0x29d34d(0x376)]({'\x74\x79\x70\x65':'\x66\x75\x6e\x63\x74\x69\x6f\x6e','\x66\x75\x6e\x63\x74\x69\x6f\x6e':{'\x6e\x61\x6d\x65':_0x558035[_0x29d34d(0x30e)][_0x29d34d(0x306)],'\x64\x65\x73\x63\x72\x69\x70\x74\x69\x6f\x6e':_0x558035[_0x29d34d(0x30e)][_0x29d34d(0x298)],'\x70\x61\x72\x61\x6d\x65\x74\x65\x72\x73':_0x558035[_0x29d34d(0x30e)][_0x29d34d(0x22e)]??null,'\x73\x74\x72\x69\x63\x74':_0x558035[_0x29d34d(0x30e)][_0x29d34d(0x2ab)]??null}});return _0x3aaa69[_0x29d34d(0x31d)](_0x1a838c[_0x29d34d(0x2a8)],0x0)?_0x1a838c:void 0x0;}function openaiMessagesToSandboxInput(_0x169a9b,_0x458baf,_0x597a51){const _0x29ccab=a0_0x5cfbcf,_0x27c94c={'\x50\x77\x46\x4e\x62':_0x29ccab(0x3aa),'\x66\x75\x73\x55\x5a':function(_0x4e5c51,_0x127e56){return _0x4e5c51(_0x127e56);},'\x51\x69\x4f\x49\x66':function(_0x51ddde,_0x43283e){return _0x51ddde===_0x43283e;},'\x4c\x52\x69\x63\x44':function(_0x4dffc7,_0x240317){return _0x4dffc7>_0x240317;},'\x72\x43\x42\x6c\x75':'\x74\x6f\x6f\x6c','\x53\x5a\x66\x42\x76':function(_0x2062c8,_0x8d5241){return _0x2062c8-_0x8d5241;}},{provider:_0x330ce4,variant:_0xa65607}=resolveProviderId(_0x597a51),_0x13dd60=[],_0x3362db=[],_0x4eef27=[];let _0x30e07a=null,_0x13768d=[],_0x13e550=[],_0x1eaa1f=![];const _0x5e9034=()=>{_0x30e07a&&(_0x4eef27['\x70\x75\x73\x68'](_0x30e07a),_0x30e07a=null);};let _0x284d66=-0x1;for(let _0x43d0ca=_0x169a9b[_0x29ccab(0x2a8)]-0x1;_0x43d0ca>=0x0;_0x43d0ca--)if(_0x169a9b[_0x43d0ca][_0x29ccab(0x242)]===_0x29ccab(0x2aa)){_0x284d66=_0x43d0ca;break;}if(_0x284d66===-0x1)throw new Error(_0x29ccab(0x1f5));for(let _0x520f1f=0x0;_0x520f1f<_0x169a9b[_0x29ccab(0x2a8)];_0x520f1f++){const _0x45dd0c=_0x169a9b[_0x520f1f];switch(_0x45dd0c[_0x29ccab(0x242)]){case _0x29ccab(0x305):case _0x27c94c['\x50\x77\x46\x4e\x62']:{const {text:_0x112f7d}=normalizeContent(_0x45dd0c[_0x29ccab(0x23c)]);if(_0x112f7d)_0x13dd60['\x70\x75\x73\x68'](_0x112f7d);break;}case _0x29ccab(0x2aa):{const {text:_0x964a73,parts:_0x4548e7}=_0x27c94c[_0x29ccab(0x317)](normalizeContent,_0x45dd0c[_0x29ccab(0x23c)]);if(_0x4548e7[_0x29ccab(0x3ce)](_0x3823e5=>_0x3823e5[_0x29ccab(0x382)]!==_0x29ccab(0x20f)))_0x1eaa1f=!![];if(_0x27c94c[_0x29ccab(0x390)](_0x520f1f,_0x284d66)){_0x3362db['\x70\x75\x73\x68'](_0x964a73);if(_0x4548e7[_0x29ccab(0x2a8)]>0x0)_0x13e550=_0x4548e7;}else{_0x5e9034();_0x4548e7[_0x29ccab(0x2a8)]>0x0?(_0x30e07a={'\x75\x73\x65\x72\x50\x61\x72\x74\x73':_0x4548e7},_0x13768d=_0x4548e7):(_0x30e07a={},_0x13768d=[]);if(_0x964a73)_0x3362db[_0x29ccab(0x376)](_0x964a73);}break;}case'\x61\x73\x73\x69\x73\x74\x61\x6e\x74':{if(!_0x30e07a)_0x30e07a={};const _0x53dc4a=readAssistantText(_0x45dd0c[_0x29ccab(0x23c)]);if(_0x53dc4a)_0x30e07a[_0x29ccab(0x3a8)]=_0x53dc4a;if(_0x45dd0c[_0x29ccab(0x272)]&&_0x45dd0c[_0x29ccab(0x272)][_0x29ccab(0x2a8)]>0x0){const _0x203863=[];for(const _0x46840e of _0x45dd0c[_0x29ccab(0x272)]){if(_0x46840e[_0x29ccab(0x382)]!==_0x29ccab(0x30e))continue;if(!_0x46840e['\x69\x64']||!_0x46840e[_0x29ccab(0x30e)]?.[_0x29ccab(0x306)]||typeof _0x46840e[_0x29ccab(0x30e)][_0x29ccab(0x2b7)]!==_0x29ccab(0x2c6))throw new Error(_0x29ccab(0x284)+_0x520f1f);_0x203863[_0x29ccab(0x376)]({'\x69\x64':_0x46840e['\x69\x64'],'\x6e\x61\x6d\x65':_0x46840e['\x66\x75\x6e\x63\x74\x69\x6f\x6e']['\x6e\x61\x6d\x65'],'\x61\x72\x67\x75\x6d\x65\x6e\x74\x73':_0x46840e[_0x29ccab(0x30e)][_0x29ccab(0x2b7)]});}if(_0x203863[_0x29ccab(0x2a8)]>0x0)_0x30e07a[_0x29ccab(0x2b0)]=_0x203863;}if(_0x27c94c[_0x29ccab(0x2ea)](_0x13768d[_0x29ccab(0x2a8)],0x0)&&!_0x30e07a[_0x29ccab(0x398)])_0x30e07a[_0x29ccab(0x398)]=_0x13768d;break;}case _0x27c94c[_0x29ccab(0x2fc)]:{const _0x36b0e4={'\x74\x6f\x6f\x6c\x43\x61\x6c\x6c\x49\x64':_0x45dd0c[_0x29ccab(0x20e)],'\x63\x6f\x6e\x74\x65\x6e\x74':_0x27c94c['\x66\x75\x73\x55\x5a'](readToolContent,_0x45dd0c[_0x29ccab(0x23c)])};let _0x5d4e7e=![];if(_0x30e07a?.[_0x29ccab(0x2b0)]?.['\x73\x6f\x6d\x65'](_0xbf5d55=>_0xbf5d55['\x69\x64']===_0x45dd0c['\x74\x6f\x6f\x6c\x5f\x63\x61\x6c\x6c\x5f\x69\x64'])){if(!_0x30e07a[_0x29ccab(0x396)])_0x30e07a[_0x29ccab(0x396)]=[];_0x30e07a['\x74\x6f\x6f\x6c\x52\x65\x73\x75\x6c\x74\x73'][_0x29ccab(0x376)](_0x36b0e4),_0x5d4e7e=!![];}else for(let _0x4529ee=_0x27c94c['\x53\x5a\x66\x42\x76'](_0x4eef27['\x6c\x65\x6e\x67\x74\x68'],0x1);_0x4529ee>=0x0;_0x4529ee--){const _0x3377a3=_0x4eef27[_0x4529ee];if(_0x3377a3[_0x29ccab(0x2b0)]?.[_0x29ccab(0x3ce)](_0x30f997=>_0x30f997['\x69\x64']===_0x45dd0c[_0x29ccab(0x20e)])){if(!_0x3377a3['\x74\x6f\x6f\x6c\x52\x65\x73\x75\x6c\x74\x73'])_0x3377a3[_0x29ccab(0x396)]=[];_0x3377a3[_0x29ccab(0x396)][_0x29ccab(0x376)](_0x36b0e4),_0x5d4e7e=!![];break;}}if(!_0x5d4e7e)throw new Error('\x6f\x70\x65\x6e\x61\x69\x4d\x65\x73\x73\x61\x67\x65\x73\x54\x6f\x53\x61\x6e\x64\x62\x6f\x78\x49\x6e\x70\x75\x74\x3a\x20\x74\x6f\x6f\x6c\x20\x6d\x65\x73\x73\x61\x67\x65\x20\x72\x65\x66\x65\x72\x65\x6e\x63\x65\x73\x20\x75\x6e\x6b\x6e\x6f\x77\x6e\x20\x74\x6f\x6f\x6c\x5f\x63\x61\x6c\x6c\x5f\x69\x64\x20'+_0x45dd0c[_0x29ccab(0x20e)]);break;}case _0x29ccab(0x30e):break;}if(_0x520f1f===_0x284d66)_0x5e9034();}_0x5e9034();const _0x4f5fa4={'\x70\x72\x6f\x76\x69\x64\x65\x72':_0x330ce4,'\x74\x61\x73\x6b':_0x3362db[_0x29ccab(0x2d5)]('\x0a\x0a')};if(_0xa65607)_0x4f5fa4[_0x29ccab(0x224)]=_0xa65607;const _0x5fff5f=_0x13dd60[_0x29ccab(0x2d5)]('\x0a\x0a');if(_0x5fff5f)_0x4f5fa4[_0x29ccab(0x378)]=_0x5fff5f;if(_0x27c94c['\x4c\x52\x69\x63\x44'](_0x13e550[_0x29ccab(0x2a8)],0x0))_0x4f5fa4[_0x29ccab(0x3d1)]=_0x13e550;if(_0x4eef27['\x6c\x65\x6e\x67\x74\x68']>0x0)_0x4f5fa4[_0x29ccab(0x339)]=_0x4eef27;const _0x2034d0=convertTools(_0x458baf);if(_0x2034d0)_0x4f5fa4[_0x29ccab(0x265)]=_0x2034d0;if(_0x1eaa1f)_0x4f5fa4['\x6d\x75\x6c\x74\x69\x6d\x6f\x64\x61\x6c']=!![];return _0x4f5fa4;}async function resolvePreviousResponseId(_0x34e261,_0x5e8aa7){const _0x4448dd=a0_0x5cfbcf;if(!_0x34e261)return{'\x70\x72\x69\x6f\x72\x54\x75\x72\x6e\x73':[]};const _0xd63291=await _0x5e8aa7[_0x4448dd(0x2b1)](_0x34e261);if(_0xd63291===null)throw new Error('\x55\x6e\x6b\x6e\x6f\x77\x6e\x20\x70\x72\x65\x76\x69\x6f\x75\x73\x5f\x72\x65\x73\x70\x6f\x6e\x73\x65\x5f\x69\x64\x3a\x20'+_0x34e261);return{'\x70\x72\x69\x6f\x72\x54\x75\x72\x6e\x73':_0xd63291};}function emptyUsage(){return{'\x69\x6e\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73':0x0,'\x6f\x75\x74\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73':0x0,'\x74\x6f\x74\x61\x6c\x5f\x74\x6f\x6b\x65\x6e\x73':0x0,'\x69\x6e\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73\x5f\x64\x65\x74\x61\x69\x6c\x73':{'\x63\x61\x63\x68\x65\x64\x5f\x74\x6f\x6b\x65\x6e\x73':0x0},'\x6f\x75\x74\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73\x5f\x64\x65\x74\x61\x69\x6c\x73':{'\x72\x65\x61\x73\x6f\x6e\x69\x6e\x67\x5f\x74\x6f\x6b\x65\x6e\x73':0x0}};}function readUsageFromEvent(_0x415312){const _0x2844b1=a0_0x5cfbcf,_0x67d20d={'\x72\x45\x6e\x71\x6e':function(_0x275c40,_0x2d4ede){return _0x275c40(_0x2d4ede);},'\x4e\x74\x54\x6e\x4b':function(_0x1be000,_0x21e2e7){return _0x1be000===_0x21e2e7;},'\x46\x4d\x53\x69\x47':function(_0x439c4c,_0x29b52b){return _0x439c4c in _0x29b52b;},'\x78\x69\x79\x51\x48':function(_0x5dc2fb,_0x4df5a9){return _0x5dc2fb(_0x4df5a9);}},_0x1212dd=_0x415312[_0x2844b1(0x353)]??_0x415312,_0x24f311=Number(_0x1212dd[_0x2844b1(0x25c)]??_0x1212dd[_0x2844b1(0x277)]??_0x1212dd['\x69\x6e\x70\x75\x74\x54\x6f\x6b\x65\x6e\x73']??0x0),_0x26c490=_0x67d20d[_0x2844b1(0x3c8)](Number,_0x1212dd[_0x2844b1(0x343)]??_0x1212dd['\x63\x6f\x6d\x70\x6c\x65\x74\x69\x6f\x6e\x5f\x74\x6f\x6b\x65\x6e\x73']??_0x1212dd[_0x2844b1(0x26e)]??0x0);if(_0x67d20d[_0x2844b1(0x2d1)](_0x24f311,0x0)&&_0x67d20d[_0x2844b1(0x2d1)](_0x26c490,0x0)&&!_0x67d20d[_0x2844b1(0x270)]('\x74\x6f\x74\x61\x6c\x5f\x74\x6f\x6b\x65\x6e\x73',_0x1212dd))return null;const _0x5dde92=_0x67d20d['\x78\x69\x79\x51\x48'](Number,_0x1212dd[_0x2844b1(0x2bc)]??_0x24f311+_0x26c490),_0x1ad43a=Number(_0x1212dd[_0x2844b1(0x25a)]?.['\x63\x61\x63\x68\x65\x64\x5f\x74\x6f\x6b\x65\x6e\x73']??_0x1212dd[_0x2844b1(0x24d)]??0x0),_0x12961a=Number(_0x1212dd[_0x2844b1(0x324)]?.[_0x2844b1(0x23a)]??_0x1212dd['\x72\x65\x61\x73\x6f\x6e\x69\x6e\x67\x5f\x74\x6f\x6b\x65\x6e\x73']??0x0);return{'\x69\x6e\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73':_0x24f311,'\x6f\x75\x74\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73':_0x26c490,'\x74\x6f\x74\x61\x6c\x5f\x74\x6f\x6b\x65\x6e\x73':_0x5dde92,'\x69\x6e\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73\x5f\x64\x65\x74\x61\x69\x6c\x73':{'\x63\x61\x63\x68\x65\x64\x5f\x74\x6f\x6b\x65\x6e\x73':_0x1ad43a},'\x6f\x75\x74\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73\x5f\x64\x65\x74\x61\x69\x6c\x73':{'\x72\x65\x61\x73\x6f\x6e\x69\x6e\x67\x5f\x74\x6f\x6b\x65\x6e\x73':_0x12961a}};}function readToolInvocationFromRaw(_0x1611b7){const _0x145e4f=a0_0x5cfbcf,_0x5f3cf1={'\x6a\x50\x49\x48\x4a':function(_0xadf084,_0x17f271){return _0xadf084!==_0x17f271;},'\x4c\x79\x45\x6e\x41':function(_0x11c796,_0x534c72){return _0x11c796===_0x534c72;},'\x64\x63\x47\x63\x6e':_0x145e4f(0x2fb),'\x59\x71\x51\x6d\x48':'\x6f\x62\x6a\x65\x63\x74','\x72\x65\x58\x58\x77':_0x145e4f(0x20a),'\x77\x7a\x51\x75\x6a':'\x74\x6f\x6f\x6c\x5f\x63\x61\x6c\x6c','\x53\x48\x52\x4e\x46':function(_0x2b0828,_0x3f2d95){return _0x2b0828===_0x3f2d95;},'\x7a\x54\x52\x58\x53':function(_0x411061,_0x5d48e1){return _0x411061===_0x5d48e1;},'\x51\x53\x76\x67\x71':_0x145e4f(0x2c6),'\x4c\x47\x4f\x41\x41':_0x145e4f(0x293)};if(_0x5f3cf1[_0x145e4f(0x24a)](_0x1611b7[_0x145e4f(0x382)],'\x72\x61\x77'))return null;const _0x4a1084=_0x1611b7[_0x145e4f(0x321)]??_0x1611b7,_0x852a62=_0x5f3cf1['\x4c\x79\x45\x6e\x41'](typeof _0x4a1084[_0x145e4f(0x382)],_0x145e4f(0x2c6))?_0x4a1084[_0x145e4f(0x382)]:'',_0x38f2f4=_0x852a62===_0x5f3cf1[_0x145e4f(0x230)]||_0x852a62==='\x63\x6f\x6d\x70\x75\x74\x65\x72\x5f\x63\x61\x6c\x6c'||typeof _0x4a1084[_0x145e4f(0x3d0)]===_0x5f3cf1['\x59\x71\x51\x6d\x48']||typeof _0x4a1084['\x63\x6f\x6d\x70\x75\x74\x65\x72\x5f\x75\x73\x65']===_0x5f3cf1['\x59\x71\x51\x6d\x48'];if(!(_0x852a62===_0x5f3cf1[_0x145e4f(0x2d9)]||_0x852a62===_0x5f3cf1[_0x145e4f(0x232)]||typeof _0x4a1084['\x74\x6f\x6f\x6c\x49\x6e\x76\x6f\x63\x61\x74\x69\x6f\x6e']===_0x5f3cf1[_0x145e4f(0x1f6)]||_0x5f3cf1[_0x145e4f(0x20c)](typeof _0x4a1084['\x74\x6f\x6f\x6c\x5f\x69\x6e\x76\x6f\x63\x61\x74\x69\x6f\x6e'],_0x145e4f(0x256)))&&!_0x38f2f4)return null;const _0x24a75b=_0x4a1084[_0x145e4f(0x354)]??_0x4a1084['\x74\x6f\x6f\x6c\x5f\x69\x6e\x76\x6f\x63\x61\x74\x69\x6f\x6e']??_0x4a1084['\x63\x6f\x6d\x70\x75\x74\x65\x72\x55\x73\x65']??_0x4a1084[_0x145e4f(0x293)]??_0x4a1084,_0x5d8c47=_0x5f3cf1[_0x145e4f(0x20c)](typeof _0x24a75b[_0x145e4f(0x234)],'\x73\x74\x72\x69\x6e\x67')?_0x24a75b[_0x145e4f(0x234)]:_0x5f3cf1[_0x145e4f(0x28e)](typeof _0x24a75b[_0x145e4f(0x20e)],_0x145e4f(0x2c6))?_0x24a75b[_0x145e4f(0x20e)]:_0x5f3cf1['\x53\x48\x52\x4e\x46'](typeof _0x24a75b['\x69\x64'],_0x145e4f(0x2c6))?_0x24a75b['\x69\x64']:_0x5f3cf1[_0x145e4f(0x1f0)](typeof _0x24a75b[_0x145e4f(0x273)],_0x5f3cf1['\x51\x53\x76\x67\x71'])?_0x24a75b['\x63\x61\x6c\x6c\x49\x64']:'',_0x7e0d73=_0x38f2f4?_0x5f3cf1[_0x145e4f(0x34a)]:typeof _0x24a75b[_0x145e4f(0x351)]===_0x145e4f(0x2c6)?_0x24a75b[_0x145e4f(0x351)]:typeof _0x24a75b[_0x145e4f(0x308)]===_0x5f3cf1[_0x145e4f(0x2a6)]?_0x24a75b['\x74\x6f\x6f\x6c\x5f\x6e\x61\x6d\x65']:_0x5f3cf1[_0x145e4f(0x20c)](typeof _0x24a75b['\x6e\x61\x6d\x65'],_0x5f3cf1[_0x145e4f(0x2a6)])?_0x24a75b[_0x145e4f(0x306)]:'',_0x4bef4f=_0x24a75b[_0x145e4f(0x32f)]??_0x24a75b[_0x145e4f(0x2b7)]??_0x24a75b[_0x145e4f(0x28c)]??{};if(!_0x5d8c47||!_0x7e0d73)return null;return{'\x69\x64':_0x5d8c47,'\x6e\x61\x6d\x65':_0x7e0d73,'\x61\x72\x67\x75\x6d\x65\x6e\x74\x73':typeof _0x4bef4f===_0x5f3cf1[_0x145e4f(0x2a6)]?_0x4bef4f:JSON[_0x145e4f(0x2f9)](_0x4bef4f),'\x69\x73\x43\x6f\x6d\x70\x75\x74\x65\x72\x55\x73\x65':_0x38f2f4,'\x63\x6f\x6d\x70\x75\x74\x65\x72\x41\x63\x74\x69\x6f\x6e':_0x38f2f4?_0x24a75b[_0x145e4f(0x330)]??void 0x0:void 0x0};}function readReasoningFromPart(_0x1909be){const _0x1c77b4=a0_0x5cfbcf,_0x21797e={'\x55\x6c\x64\x4c\x4a':function(_0x14b0b8,_0x18c13b){return _0x14b0b8!==_0x18c13b;},'\x41\x63\x79\x76\x63':_0x1c77b4(0x35c),'\x5a\x64\x54\x4d\x61':_0x1c77b4(0x2ba),'\x45\x4e\x59\x44\x79':function(_0x2b372b,_0x295da5){return _0x2b372b===_0x295da5;},'\x4f\x71\x51\x61\x6f':_0x1c77b4(0x2c6)};if(_0x1909be[_0x1c77b4(0x382)]!==_0x1c77b4(0x24c))return null;const _0x1e8bc9=_0x1909be['\x70\x61\x72\x74']??_0x1909be;if(_0x21797e[_0x1c77b4(0x2c1)](_0x1e8bc9[_0x1c77b4(0x382)],_0x21797e[_0x1c77b4(0x3ae)])&&_0x1e8bc9['\x74\x79\x70\x65']!==_0x21797e[_0x1c77b4(0x1fb)])return null;if(_0x21797e[_0x1c77b4(0x38e)](typeof _0x1e8bc9['\x74\x65\x78\x74'],_0x1c77b4(0x2c6)))return _0x1e8bc9['\x74\x65\x78\x74'];if(typeof _0x1e8bc9[_0x1c77b4(0x23c)]===_0x21797e[_0x1c77b4(0x373)])return _0x1e8bc9[_0x1c77b4(0x23c)];return null;}function assembleResponseOutput(_0x258262){const _0x1666bb=a0_0x5cfbcf,_0x50f8da={'\x5a\x63\x4c\x56\x72':function(_0x55c3d7){return _0x55c3d7();},'\x6c\x61\x73\x64\x45':_0x1666bb(0x28b),'\x41\x69\x46\x49\x4c':function(_0x5c2d33,_0x2552bc){return _0x5c2d33===_0x2552bc;},'\x57\x44\x77\x50\x4b':_0x1666bb(0x2c6),'\x6e\x74\x62\x52\x47':_0x1666bb(0x2e7),'\x45\x68\x6e\x62\x70':function(_0x515248,_0x184cf5){return _0x515248(_0x184cf5);},'\x66\x63\x7a\x4e\x68':function(_0x4f3f21,_0x5eb669,_0x160b3d){return _0x4f3f21(_0x5eb669,_0x160b3d);},'\x71\x7a\x48\x57\x77':_0x1666bb(0x2d7),'\x53\x79\x6e\x55\x74':_0x1666bb(0x2cd),'\x69\x65\x54\x52\x42':_0x1666bb(0x3ca)},_0x4936c2={'\x74\x65\x78\x74\x50\x69\x65\x63\x65\x73':[],'\x74\x6f\x6f\x6c\x43\x61\x6c\x6c\x73':new Map(),'\x74\x6f\x6f\x6c\x43\x61\x6c\x6c\x4f\x72\x64\x65\x72':[],'\x63\x6f\x6d\x70\x75\x74\x65\x72\x43\x61\x6c\x6c\x73':[],'\x72\x65\x61\x73\x6f\x6e\x69\x6e\x67\x50\x69\x65\x63\x65\x73':[],'\x75\x73\x61\x67\x65':_0x50f8da[_0x1666bb(0x36e)](emptyUsage),'\x68\x61\x73\x55\x73\x61\x67\x65':![]};for(const _0x2631d0 of _0x258262)switch(_0x2631d0[_0x1666bb(0x382)]){case _0x50f8da[_0x1666bb(0x2cb)]:{const _0x4073ab=_0x50f8da['\x41\x69\x46\x49\x4c'](typeof _0x2631d0[_0x1666bb(0x1fe)],_0x1666bb(0x2c6))&&_0x2631d0['\x64\x65\x6c\x74\x61']||typeof _0x2631d0[_0x1666bb(0x20f)]===_0x50f8da[_0x1666bb(0x2bd)]&&_0x2631d0[_0x1666bb(0x20f)]||typeof _0x2631d0[_0x1666bb(0x28b)]===_0x1666bb(0x2c6)&&_0x2631d0[_0x1666bb(0x28b)]||'';if(_0x4073ab)_0x4936c2[_0x1666bb(0x3a0)][_0x1666bb(0x376)](_0x4073ab);break;}case _0x1666bb(0x25f):{const _0x13028c=readToolInvocationFromRaw(_0x2631d0);if(!_0x13028c)break;if(_0x13028c['\x69\x73\x43\x6f\x6d\x70\x75\x74\x65\x72\x55\x73\x65'])_0x4936c2['\x63\x6f\x6d\x70\x75\x74\x65\x72\x43\x61\x6c\x6c\x73']['\x70\x75\x73\x68']({'\x74\x79\x70\x65':_0x1666bb(0x33f),'\x69\x64':'\x63\x63\x5f'+_0x13028c['\x69\x64'],'\x63\x61\x6c\x6c\x5f\x69\x64':_0x13028c['\x69\x64'],'\x73\x74\x61\x74\x75\x73':_0x50f8da['\x6e\x74\x62\x52\x47'],'\x70\x65\x6e\x64\x69\x6e\x67\x5f\x73\x61\x66\x65\x74\x79\x5f\x63\x68\x65\x63\x6b\x73':[],..._0x13028c['\x63\x6f\x6d\x70\x75\x74\x65\x72\x41\x63\x74\x69\x6f\x6e']?{'\x61\x63\x74\x69\x6f\x6e':_0x13028c[_0x1666bb(0x2ed)]}:{}});else{if(!_0x4936c2['\x74\x6f\x6f\x6c\x43\x61\x6c\x6c\x73']['\x68\x61\x73'](_0x13028c['\x69\x64']))_0x4936c2[_0x1666bb(0x3c0)][_0x1666bb(0x376)](_0x13028c['\x69\x64']);_0x4936c2['\x74\x6f\x6f\x6c\x43\x61\x6c\x6c\x73'][_0x1666bb(0x21a)](_0x13028c['\x69\x64'],{'\x74\x79\x70\x65':_0x1666bb(0x2ae),'\x69\x64':_0x1666bb(0x243)+_0x13028c['\x69\x64'],'\x63\x61\x6c\x6c\x5f\x69\x64':_0x13028c['\x69\x64'],'\x6e\x61\x6d\x65':_0x13028c['\x6e\x61\x6d\x65'],'\x61\x72\x67\x75\x6d\x65\x6e\x74\x73':_0x13028c['\x61\x72\x67\x75\x6d\x65\x6e\x74\x73'],'\x73\x74\x61\x74\x75\x73':_0x1666bb(0x2e7)});}break;}case _0x1666bb(0x24c):{const _0x4ba1a9=_0x50f8da[_0x1666bb(0x307)](readReasoningFromPart,_0x2631d0);if(_0x4ba1a9)_0x4936c2['\x72\x65\x61\x73\x6f\x6e\x69\x6e\x67\x50\x69\x65\x63\x65\x73'][_0x1666bb(0x376)](_0x4ba1a9);break;}case _0x1666bb(0x38d):{const _0x4723d7=readUsageFromEvent(_0x2631d0);_0x4723d7&&(_0x4936c2[_0x1666bb(0x353)]=_0x50f8da['\x66\x63\x7a\x4e\x68'](foldUsage,_0x4936c2[_0x1666bb(0x353)],_0x4723d7),_0x4936c2[_0x1666bb(0x2ee)]=!![]);break;}}const _0x1d7252=[];if(_0x4936c2['\x72\x65\x61\x73\x6f\x6e\x69\x6e\x67\x50\x69\x65\x63\x65\x73']['\x6c\x65\x6e\x67\x74\x68']>0x0){const _0x33c3b7={'\x74\x79\x70\x65':_0x1666bb(0x35c),'\x69\x64':_0x1666bb(0x26b),'\x73\x75\x6d\x6d\x61\x72\x79':[],'\x63\x6f\x6e\x74\x65\x6e\x74':_0x4936c2[_0x1666bb(0x1f3)][_0x1666bb(0x236)](_0x3cc0ef=>({'\x74\x79\x70\x65':_0x1666bb(0x32d),'\x74\x65\x78\x74':_0x3cc0ef})),'\x73\x74\x61\x74\x75\x73':_0x50f8da[_0x1666bb(0x367)]};_0x1d7252['\x70\x75\x73\x68'](_0x33c3b7);}if(_0x4936c2[_0x1666bb(0x3a0)][_0x1666bb(0x2a8)]>0x0){const _0x56d42f={'\x74\x79\x70\x65':_0x50f8da['\x71\x7a\x48\x57\x77'],'\x69\x64':_0x1666bb(0x3a5),'\x72\x6f\x6c\x65':_0x50f8da[_0x1666bb(0x3ad)],'\x73\x74\x61\x74\x75\x73':_0x1666bb(0x2e7),'\x63\x6f\x6e\x74\x65\x6e\x74':[{'\x74\x79\x70\x65':_0x50f8da[_0x1666bb(0x248)],'\x74\x65\x78\x74':_0x4936c2[_0x1666bb(0x3a0)][_0x1666bb(0x2d5)](''),'\x61\x6e\x6e\x6f\x74\x61\x74\x69\x6f\x6e\x73':[]}]};_0x1d7252[_0x1666bb(0x376)](_0x56d42f);}for(const _0x40dd29 of _0x4936c2['\x74\x6f\x6f\x6c\x43\x61\x6c\x6c\x4f\x72\x64\x65\x72']){const _0x130d51=_0x4936c2[_0x1666bb(0x2b0)][_0x1666bb(0x247)](_0x40dd29);if(_0x130d51)_0x1d7252[_0x1666bb(0x376)](_0x130d51);}for(const _0x1f3e47 of _0x4936c2['\x63\x6f\x6d\x70\x75\x74\x65\x72\x43\x61\x6c\x6c\x73'])_0x1d7252[_0x1666bb(0x376)](_0x1f3e47);return{'\x6f\x75\x74\x70\x75\x74':_0x1d7252,'\x75\x73\x61\x67\x65':_0x4936c2[_0x1666bb(0x353)]};}function foldUsage(_0x1cb44c,_0x49e372){const _0x175091=a0_0x5cfbcf,_0x13dbed={'\x4e\x73\x77\x56\x47':function(_0x597a11,_0x4ce994){return _0x597a11+_0x4ce994;}};return{'\x69\x6e\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73':_0x1cb44c['\x69\x6e\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73']+_0x49e372['\x69\x6e\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73'],'\x6f\x75\x74\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73':_0x1cb44c[_0x175091(0x343)]+_0x49e372[_0x175091(0x343)],'\x74\x6f\x74\x61\x6c\x5f\x74\x6f\x6b\x65\x6e\x73':_0x13dbed[_0x175091(0x3af)](_0x1cb44c[_0x175091(0x2bc)],_0x49e372[_0x175091(0x2bc)]),'\x69\x6e\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73\x5f\x64\x65\x74\x61\x69\x6c\x73':{'\x63\x61\x63\x68\x65\x64\x5f\x74\x6f\x6b\x65\x6e\x73':_0x1cb44c[_0x175091(0x25a)]['\x63\x61\x63\x68\x65\x64\x5f\x74\x6f\x6b\x65\x6e\x73']+_0x49e372[_0x175091(0x25a)]['\x63\x61\x63\x68\x65\x64\x5f\x74\x6f\x6b\x65\x6e\x73']},'\x6f\x75\x74\x70\x75\x74\x5f\x74\x6f\x6b\x65\x6e\x73\x5f\x64\x65\x74\x61\x69\x6c\x73':{'\x72\x65\x61\x73\x6f\x6e\x69\x6e\x67\x5f\x74\x6f\x6b\x65\x6e\x73':_0x1cb44c[_0x175091(0x324)][_0x175091(0x23a)]+_0x49e372[_0x175091(0x324)][_0x175091(0x23a)]}};}function usageFromEvents(_0x2f9352){const _0x3cd630=a0_0x5cfbcf,_0x17e8f5={'\x6c\x75\x4a\x74\x67':function(_0x9e3707){return _0x9e3707();},'\x51\x59\x62\x47\x70':_0x3cd630(0x38d)};let _0x56a20c=_0x17e8f5[_0x3cd630(0x34d)](emptyUsage);for(const _0x48acb3 of _0x2f9352){if(_0x48acb3[_0x3cd630(0x382)]!==_0x17e8f5[_0x3cd630(0x2ac)])continue;const _0x4262d5=readUsageFromEvent(_0x48acb3);if(_0x4262d5)_0x56a20c=foldUsage(_0x56a20c,_0x4262d5);}return _0x56a20c;}const SUPPORTED_TOOL_TYPES=new Set(['\x66\x75\x6e\x63\x74\x69\x6f\x6e',a0_0x5cfbcf(0x309),'\x63\x6f\x64\x65\x5f\x69\x6e\x74\x65\x72\x70\x72\x65\x74\x65\x72','\x77\x65\x62\x5f\x73\x65\x61\x72\x63\x68',a0_0x5cfbcf(0x2db),a0_0x5cfbcf(0x2a7)]),REJECTED_TOOL_TYPES=new Set(['\x66\x69\x6c\x65\x5f\x73\x65\x61\x72\x63\x68']);var ResponsesValidationError=class extends Error{[a0_0x5cfbcf(0x382)]=a0_0x5cfbcf(0x366);['\x63\x6f\x64\x65'];[a0_0x5cfbcf(0x2d3)];constructor(_0x1df63e,_0x212371,_0x204479){const _0x3b6e75=a0_0x5cfbcf,_0x16532a={'\x4f\x44\x67\x64\x74':_0x3b6e75(0x268)};super(_0x1df63e),this[_0x3b6e75(0x306)]=_0x16532a[_0x3b6e75(0x3a4)],this['\x63\x6f\x64\x65']=_0x212371,this['\x70\x61\x72\x61\x6d']=_0x204479;}};function validateResponsesRequest(_0x3d5ca9){const _0x2f76de=a0_0x5cfbcf,_0x229cf4={'\x69\x72\x57\x69\x53':function(_0x5b7011,_0x21ded2){return _0x5b7011===_0x21ded2;},'\x48\x7a\x64\x50\x55':function(_0x1360fe,_0x478e5){return _0x1360fe!==_0x478e5;},'\x61\x78\x50\x51\x55':_0x2f76de(0x228)},_0x358586=_0x3d5ca9[_0x2f76de(0x265)];if(!_0x358586||_0x229cf4['\x69\x72\x57\x69\x53'](_0x358586[_0x2f76de(0x2a8)],0x0))return;for(let _0x2e864e=0x0;_0x2e864e<_0x358586[_0x2f76de(0x2a8)];_0x2e864e++){const _0x41ba6c=_0x358586[_0x2e864e]['\x74\x79\x70\x65'];if(_0x229cf4[_0x2f76de(0x352)](typeof _0x41ba6c,'\x73\x74\x72\x69\x6e\x67'))throw new ResponsesValidationError(_0x2f76de(0x203)+_0x2e864e+_0x2f76de(0x2f1),_0x229cf4[_0x2f76de(0x276)],_0x2f76de(0x203)+_0x2e864e+_0x2f76de(0x1f4));if(REJECTED_TOOL_TYPES[_0x2f76de(0x23d)](_0x41ba6c))throw new ResponsesValidationError(_0x2f76de(0x3b1)+_0x41ba6c+_0x2f76de(0x346),_0x2f76de(0x28d),_0x2f76de(0x203)+_0x2e864e+_0x2f76de(0x1f4));if(!SUPPORTED_TOOL_TYPES[_0x2f76de(0x23d)](_0x41ba6c))throw new ResponsesValidationError(_0x2f76de(0x3b1)+_0x41ba6c+'\x22\x20\x69\x73\x20\x6e\x6f\x74\x20\x72\x65\x63\x6f\x67\x6e\x69\x7a\x65\x64',_0x2f76de(0x28d),_0x2f76de(0x203)+_0x2e864e+_0x2f76de(0x1f4));}}function normalizeResponsesWebSearchForTangleRouter(_0x5687ae,_0x4e56ff={}){const _0x5a11f8=a0_0x5cfbcf,_0xe8545d={'\x47\x4c\x78\x64\x7a':'\x77\x65\x62\x5f\x73\x65\x61\x72\x63\x68','\x41\x69\x6a\x72\x58':function(_0x15129c,_0x30bd59){return _0x15129c!==_0x30bd59;}},_0x537ffb=Array[_0x5a11f8(0x24f)](_0x5687ae[_0x5a11f8(0x265)])?_0x5687ae[_0x5a11f8(0x265)]:void 0x0;if(!_0x537ffb)return _0x5687ae;let _0x450a2c=![];const _0x592d5a=_0x537ffb['\x6d\x61\x70'](_0xccca6a=>{const _0x5a0609=_0x5a11f8;if(!_0xccca6a||typeof _0xccca6a!==_0x5a0609(0x256))return _0xccca6a;const _0x37101e=_0xccca6a['\x74\x79\x70\x65'];if(_0x37101e!==_0xe8545d[_0x5a0609(0x2e1)]&&_0xe8545d[_0x5a0609(0x3bc)](_0x37101e,_0x5a0609(0x2db)))return _0xccca6a;return _0x450a2c=!![],{'\x74\x79\x70\x65':_0x5a0609(0x2a7),'\x70\x61\x72\x61\x6d\x65\x74\x65\x72\x73':{...readNativeWebSearchParameters(_0xccca6a),..._0x4e56ff['\x70\x72\x6f\x76\x69\x64\x65\x72']?{'\x70\x72\x6f\x76\x69\x64\x65\x72':_0x4e56ff[_0x5a0609(0x2cf)]}:{},..._0x4e56ff[_0x5a0609(0x274)]?{'\x6d\x61\x78\x5f\x72\x65\x73\x75\x6c\x74\x73':_0x4e56ff['\x6d\x61\x78\x52\x65\x73\x75\x6c\x74\x73']}:{},..._0x4e56ff[_0x5a0609(0x2b3)]?{'\x6d\x61\x78\x5f\x74\x6f\x74\x61\x6c\x5f\x72\x65\x73\x75\x6c\x74\x73':_0x4e56ff[_0x5a0609(0x2b3)]}:{},..._0x4e56ff[_0x5a0609(0x350)]?{'\x73\x65\x61\x72\x63\x68\x5f\x63\x6f\x6e\x74\x65\x78\x74\x5f\x73\x69\x7a\x65':_0x4e56ff['\x73\x65\x61\x72\x63\x68\x43\x6f\x6e\x74\x65\x78\x74\x53\x69\x7a\x65']}:{}}};});return _0x450a2c?{..._0x5687ae,'\x74\x6f\x6f\x6c\x73':_0x592d5a}:_0x5687ae;}function readNativeWebSearchParameters(_0x53b7a3){const _0x391b65=a0_0x5cfbcf,_0x2ecb94={'\x56\x50\x42\x59\x6a':_0x391b65(0x399),'\x67\x73\x4d\x73\x63':_0x391b65(0x3cd),'\x66\x53\x51\x61\x4b':_0x391b65(0x256)},_0x1f7040=_0x53b7a3,_0x200387={},_0x27d962=_0x1f7040[_0x391b65(0x290)]??_0x1f7040[_0x391b65(0x350)];if(_0x27d962===_0x2ecb94['\x56\x50\x42\x59\x6a']||_0x27d962===_0x391b65(0x27c)||_0x27d962===_0x2ecb94[_0x391b65(0x39e)])_0x200387[_0x391b65(0x290)]=_0x27d962;const _0x166870=_0x1f7040[_0x391b65(0x336)]??_0x1f7040[_0x391b65(0x2c9)];if(_0x166870&&typeof _0x166870===_0x2ecb94[_0x391b65(0x244)])_0x200387[_0x391b65(0x336)]=_0x166870;return _0x200387;}function buildResponseShell(_0x3e898a){const _0xfd8e5d=a0_0x5cfbcf,_0x2ebf27=_0x3e898a[_0xfd8e5d(0x2e0)][_0xfd8e5d(0x217)](_0x5a97f4=>_0x5a97f4[_0xfd8e5d(0x382)]==='\x6d\x65\x73\x73\x61\x67\x65')[_0xfd8e5d(0x392)](_0xe1d2e3=>_0xe1d2e3['\x63\x6f\x6e\x74\x65\x6e\x74'])[_0xfd8e5d(0x217)](_0x18f3b7=>_0x18f3b7['\x74\x79\x70\x65']===_0xfd8e5d(0x3ca))[_0xfd8e5d(0x236)](_0x3e24c0=>_0x3e24c0[_0xfd8e5d(0x20f)])[_0xfd8e5d(0x2d5)]('');return{'\x69\x64':_0x3e898a['\x69\x64'],'\x6f\x62\x6a\x65\x63\x74':_0xfd8e5d(0x2b5),'\x63\x72\x65\x61\x74\x65\x64\x5f\x61\x74':_0x3e898a[_0xfd8e5d(0x2e2)],'\x6f\x75\x74\x70\x75\x74\x5f\x74\x65\x78\x74':_0x2ebf27,'\x65\x72\x72\x6f\x72':null,'\x69\x6e\x63\x6f\x6d\x70\x6c\x65\x74\x65\x5f\x64\x65\x74\x61\x69\x6c\x73':null,'\x69\x6e\x73\x74\x72\x75\x63\x74\x69\x6f\x6e\x73':_0x3e898a[_0xfd8e5d(0x378)]??null,'\x6d\x65\x74\x61\x64\x61\x74\x61':null,'\x6d\x6f\x64\x65\x6c':_0x3e898a['\x6d\x6f\x64\x65\x6c'],'\x6f\x75\x74\x70\x75\x74':_0x3e898a[_0xfd8e5d(0x2e0)],'\x70\x61\x72\x61\x6c\x6c\x65\x6c\x5f\x74\x6f\x6f\x6c\x5f\x63\x61\x6c\x6c\x73':![],'\x74\x65\x6d\x70\x65\x72\x61\x74\x75\x72\x65':null,'\x74\x6f\x6f\x6c\x5f\x63\x68\x6f\x69\x63\x65':'\x61\x75\x74\x6f','\x74\x6f\x6f\x6c\x73':[],'\x74\x6f\x70\x5f\x70':null,'\x73\x74\x61\x74\x75\x73':'\x63\x6f\x6d\x70\x6c\x65\x74\x65\x64','\x75\x73\x61\x67\x65':_0x3e898a[_0xfd8e5d(0x353)],'\x70\x72\x65\x76\x69\x6f\x75\x73\x5f\x72\x65\x73\x70\x6f\x6e\x73\x65\x5f\x69\x64':_0x3e898a[_0xfd8e5d(0x3a2)]??null};}function a0_0x3325(){const _0x59c050=['\x6d\x68\x57\x5a\x46\x64\x72\x38\x6d\x78\x57\x59','\x7a\x32\x76\x30','\x41\x77\x76\x75\x75\x4b\x69','\x44\x67\x4c\x30\x42\x67\x75','\x41\x4c\x62\x6a\x73\x65\x4f','\x42\x75\x66\x51\x72\x77\x57','\x42\x77\x76\x5a\x43\x32\x66\x4e\x7a\x73\x35\x57\x79\x78\x6a\x30\x6c\x4e\x76\x57\x7a\x67\x66\x30\x7a\x77\x71','\x79\x32\x66\x4a\x41\x67\x76\x4b\x78\x33\x72\x56\x41\x32\x76\x55\x43\x57','\x44\x78\x6a\x53','\x41\x78\x6e\x62\x43\x4e\x6a\x48\x45\x71','\x79\x4d\x58\x56\x79\x32\x53','\x44\x77\x4c\x65\x7a\x76\x65','\x43\x4e\x76\x55\x71\x4d\x76\x4d\x42\x33\x6a\x4c','\x6e\x4a\x75\x57\x6d\x4a\x66\x4c\x74\x77\x7a\x5a\x44\x68\x4b','\x45\x66\x7a\x6c\x72\x30\x53','\x75\x77\x31\x4b\x7a\x32\x30','\x42\x32\x6a\x51\x7a\x77\x6e\x30','\x44\x65\x7a\x73\x45\x4d\x57','\x7a\x78\x48\x4c\x79\x33\x76\x30\x7a\x76\x72\x56\x42\x32\x57','\x42\x4c\x7a\x34\x79\x4b\x43','\x41\x77\x35\x57\x44\x78\x72\x46\x44\x67\x39\x52\x7a\x77\x35\x5a\x78\x32\x72\x4c\x44\x67\x66\x50\x42\x68\x6d','\x77\x77\x50\x75\x7a\x66\x4f','\x41\x77\x35\x57\x44\x78\x72\x46\x44\x67\x39\x52\x7a\x77\x35\x5a','\x43\x4d\x76\x48\x43\x32\x39\x55','\x77\x4e\x50\x6d\x73\x78\x43','\x43\x4d\x66\x33','\x44\x4d\x50\x33\x72\x77\x38','\x42\x33\x7a\x4c\x43\x4e\x6a\x50\x7a\x67\x75','\x41\x77\x35\x57\x44\x78\x72\x46\x79\x78\x76\x4b\x41\x77\x38','\x42\x32\x35\x74\x44\x67\x66\x30\x44\x78\x6e\x64\x41\x67\x66\x55\x7a\x32\x75','\x78\x31\x39\x59\x7a\x78\x6e\x57\x42\x32\x35\x5a\x7a\x78\x6e\x66\x45\x68\x72\x59\x79\x78\x6d','\x44\x67\x39\x56\x42\x68\x6d','\x6e\x66\x50\x56\x76\x31\x72\x53\x71\x57','\x74\x30\x4c\x72\x7a\x30\x65','\x75\x4d\x76\x5a\x43\x67\x39\x55\x43\x32\x76\x5a\x76\x4d\x66\x53\x41\x77\x72\x48\x44\x67\x4c\x56\x42\x4b\x76\x59\x43\x4d\x39\x59','\x41\x4b\x6e\x4d\x43\x30\x6d','\x7a\x78\x48\x57\x41\x78\x6a\x4c\x7a\x61','\x43\x4e\x6e\x46\x6d\x61','\x69\x68\x6a\x31\x42\x47','\x79\x32\x76\x50\x42\x67\x4c\x55\x7a\x57','\x42\x33\x76\x30\x43\x68\x76\x30\x76\x67\x39\x52\x7a\x77\x35\x5a','\x44\x67\x76\x5a\x44\x61','\x72\x4b\x31\x74\x41\x75\x43','\x74\x75\x48\x69\x72\x67\x38','\x44\x67\x39\x56\x42\x66\x39\x4a\x79\x77\x58\x53\x43\x57','\x79\x32\x66\x53\x42\x65\x4c\x4b','\x42\x77\x66\x34\x75\x4d\x76\x5a\x44\x77\x58\x30\x43\x57','\x76\x65\x54\x33\x77\x66\x47','\x79\x78\x48\x71\x75\x76\x75','\x43\x68\x6a\x56\x42\x78\x62\x30\x78\x33\x72\x56\x41\x32\x76\x55\x43\x57','\x45\x4d\x50\x63\x7a\x77\x43','\x41\x4e\x62\x6b\x43\x75\x6d','\x45\x4d\x31\x34\x75\x30\x69','\x41\x77\x35\x4b\x7a\x78\x47','\x42\x77\x76\x4b\x41\x78\x76\x54','\x7a\x4e\x66\x50\x44\x75\x6d','\x73\x4b\x76\x4d\x42\x4d\x30','\x43\x78\x76\x4c\x44\x77\x75','\x76\x32\x35\x50\x7a\x75\x38','\x7a\x78\x6e\x57\x41\x30\x4b','\x77\x67\x76\x34\x75\x77\x4f','\x75\x4e\x76\x55\x72\x78\x7a\x4c\x42\x4e\x72\x74\x42\x33\x76\x59\x79\x32\x75\x47\x7a\x67\x39\x4c\x43\x59\x62\x55\x42\x33\x71\x47\x43\x33\x76\x57\x43\x67\x39\x59\x44\x63\x62\x5a\x44\x67\x76\x4c\x43\x47','\x42\x33\x62\x4c\x42\x4d\x66\x50\x74\x77\x76\x5a\x43\x32\x66\x4e\x7a\x78\x6e\x75\x42\x31\x6e\x48\x42\x4d\x72\x49\x42\x33\x48\x6a\x42\x4e\x62\x31\x44\x64\x4f\x47\x42\x77\x66\x53\x7a\x4d\x39\x59\x42\x77\x76\x4b\x69\x67\x66\x5a\x43\x32\x4c\x5a\x44\x67\x66\x55\x44\x63\x62\x30\x42\x32\x39\x53\x78\x32\x6e\x48\x42\x67\x57\x47\x79\x78\x71\x47\x41\x77\x35\x4b\x7a\x78\x47\x47','\x7a\x4d\x66\x50\x42\x68\x76\x59\x7a\x71','\x76\x33\x7a\x5a\x73\x76\x61','\x6d\x74\x61\x35\x6f\x67\x76\x78\x44\x75\x50\x76\x76\x57','\x75\x30\x4c\x4d\x72\x30\x6d','\x41\x77\x35\x32\x79\x77\x58\x50\x7a\x66\x39\x4b\x41\x77\x31\x4c\x42\x4e\x6e\x50\x42\x32\x35\x5a','\x73\x77\x35\x57\x44\x78\x71\x47\x79\x78\x6a\x59\x79\x78\x4b\x47\x7a\x78\x48\x4a\x7a\x77\x76\x4b\x43\x59\x62\x54\x79\x78\x48\x50\x42\x78\x76\x54\x69\x67\x6a\x48\x44\x67\x6e\x4f\x69\x68\x6e\x50\x45\x4d\x75\x47\x42\x32\x79\x47','\x44\x67\x39\x52\x7a\x77\x34','\x41\x77\x35\x57\x44\x78\x71','\x44\x77\x35\x5a\x44\x78\x62\x57\x42\x33\x6a\x30\x7a\x77\x72\x46\x44\x67\x39\x56\x42\x61','\x75\x30\x48\x73\x74\x4b\x79','\x69\x67\x31\x31\x43\x33\x71\x47\x79\x32\x39\x55\x44\x67\x66\x50\x42\x49\x62\x56\x42\x4d\x58\x35\x69\x67\x35\x31\x42\x77\x6a\x4c\x43\x4e\x6d\x37\x69\x67\x76\x53\x7a\x77\x31\x4c\x42\x4e\x71\x47','\x43\x32\x76\x48\x43\x4d\x6e\x4f\x78\x32\x6e\x56\x42\x4e\x72\x4c\x45\x68\x72\x46\x43\x32\x4c\x36\x7a\x71','\x79\x32\x39\x5a\x44\x63\x62\x4a\x79\x78\x61\x47\x43\x4d\x76\x48\x79\x32\x48\x4c\x7a\x64\x4f\x47','\x72\x4c\x4c\x58\x72\x31\x47','\x79\x32\x39\x54\x43\x68\x76\x30\x7a\x78\x6a\x46\x44\x78\x6e\x4c','\x45\x76\x48\x69\x72\x30\x30','\x76\x31\x6a\x6a\x74\x68\x61','\x42\x30\x35\x73\x7a\x31\x4b','\x79\x32\x39\x54\x43\x68\x76\x30\x7a\x78\x69\x54\x44\x78\x6e\x4c\x6f\x4e\x6e\x4a\x43\x4d\x76\x4c\x42\x4e\x6e\x4f\x42\x33\x71','\x7a\x67\x76\x5a\x79\x33\x6a\x50\x43\x68\x72\x50\x42\x32\x34','\x79\x32\x66\x55\x42\x4d\x39\x30\x69\x68\x6e\x31\x79\x4d\x31\x50\x44\x63\x62\x30\x42\x32\x39\x53\x69\x67\x39\x31\x44\x68\x62\x31\x44\x68\x6d\x47\x41\x77\x34\x47\x43\x33\x72\x48\x44\x68\x76\x5a\x69\x61','\x71\x77\x39\x66\x7a\x75\x43','\x43\x32\x76\x58\x44\x77\x76\x55\x79\x32\x75','\x77\x67\x44\x49\x42\x78\x75','\x43\x67\x35\x4e\x71\x4d\x66\x5a\x7a\x74\x79\x30','\x79\x77\x7a\x30\x7a\x78\x69','\x7a\x4c\x4c\x4f\x72\x66\x65','\x76\x32\x66\x77\x43\x4b\x69','\x41\x68\x50\x6c\x42\x68\x4b','\x77\x75\x44\x69\x42\x75\x30','\x75\x4d\x76\x58\x44\x77\x76\x5a\x44\x63\x62\x49\x42\x32\x72\x35\x69\x67\x31\x31\x43\x33\x71\x47\x79\x4d\x75\x47\x79\x77\x34\x47\x42\x32\x6a\x51\x7a\x77\x6e\x30','\x45\x75\x6e\x55\x41\x4d\x34','\x43\x32\x76\x33\x7a\x4e\x6d','\x75\x76\x6e\x32\x7a\x33\x65','\x42\x33\x62\x4c\x42\x4e\x6a\x56\x44\x78\x72\x4c\x43\x4a\x50\x33\x7a\x77\x6a\x46\x43\x32\x76\x48\x43\x4d\x6e\x4f','\x42\x67\x76\x55\x7a\x33\x72\x4f','\x43\x33\x72\x48\x43\x4e\x72\x5a\x76\x32\x4c\x30\x41\x61','\x44\x78\x6e\x4c\x43\x47','\x43\x33\x72\x59\x41\x77\x6e\x30','\x75\x76\x4c\x49\x72\x33\x61','\x43\x32\x39\x31\x43\x4d\x6e\x4c','\x7a\x4e\x76\x55\x79\x33\x72\x50\x42\x32\x35\x46\x79\x32\x66\x53\x42\x61','\x73\x32\x76\x6e\x76\x32\x43','\x44\x67\x39\x56\x42\x65\x6e\x48\x42\x67\x58\x5a','\x7a\x32\x76\x30\x75\x68\x6a\x50\x42\x33\x6a\x75\x44\x78\x6a\x55\x43\x57','\x44\x68\x6a\x48\x42\x4e\x6e\x50\x44\x67\x4c\x56\x42\x47','\x42\x77\x66\x34\x76\x67\x39\x30\x79\x77\x58\x73\x7a\x78\x6e\x31\x42\x68\x72\x5a','\x73\x65\x7a\x76\x74\x66\x43','\x43\x4d\x76\x5a\x43\x67\x39\x55\x43\x32\x75','\x41\x77\x35\x32\x79\x77\x58\x50\x7a\x66\x39\x4c\x42\x4d\x6e\x56\x7a\x67\x4c\x55\x7a\x31\x39\x4d\x42\x33\x6a\x54\x79\x78\x71','\x79\x78\x6a\x4e\x44\x77\x31\x4c\x42\x4e\x72\x5a','\x77\x66\x7a\x51\x41\x32\x4b','\x74\x66\x44\x65\x41\x75\x69','\x44\x67\x48\x50\x42\x4d\x54\x50\x42\x4d\x43','\x74\x32\x31\x4f\x74\x30\x38','\x44\x67\x39\x30\x79\x77\x58\x46\x44\x67\x39\x52\x7a\x77\x35\x5a','\x76\x30\x72\x33\x75\x65\x53','\x6d\x74\x75\x33\x6e\x4c\x6e\x67\x43\x77\x4c\x79\x41\x57','\x77\x4b\x6a\x4b\x7a\x30\x6d','\x42\x77\x39\x4b\x7a\x77\x58\x6a\x7a\x61','\x76\x77\x58\x4b\x74\x65\x4f','\x79\x76\x48\x34\x75\x67\x79','\x42\x31\x4c\x6d\x76\x67\x65','\x44\x67\x66\x59\x7a\x32\x76\x30','\x42\x77\x76\x5a\x43\x32\x66\x4e\x7a\x75\x39\x31\x44\x68\x62\x31\x44\x65\x4c\x55\x7a\x67\x76\x34','\x43\x33\x72\x59\x41\x77\x35\x4e','\x79\x32\x48\x48\x41\x77\x35\x5a','\x41\x66\x6e\x50\x77\x65\x34','\x44\x78\x6e\x4c\x43\x4b\x58\x56\x79\x32\x66\x30\x41\x77\x39\x55','\x79\x77\x58\x53\x42\x33\x44\x67\x42\x47','\x42\x67\x66\x5a\x7a\x65\x75','\x75\x66\x44\x6f\x43\x67\x4b','\x79\x78\x6e\x5a\x41\x78\x6e\x30\x79\x77\x35\x30','\x79\x77\x76\x30\x72\x33\x71','\x43\x68\x6a\x56\x44\x4d\x4c\x4b\x7a\x78\x69','\x44\x32\x66\x59\x42\x47','\x74\x4e\x72\x75\x42\x4b\x53','\x41\x77\x35\x32\x79\x77\x58\x50\x7a\x66\x39\x59\x7a\x78\x66\x31\x7a\x78\x6e\x30','\x43\x67\x66\x59\x79\x77\x30','\x43\x4d\x76\x5a\x44\x77\x58\x30','\x41\x4d\x39\x50\x42\x47','\x79\x32\x58\x56\x43\x32\x76\x4b','\x42\x77\x76\x5a\x43\x32\x66\x4e\x7a\x71','\x43\x33\x72\x48\x44\x68\x76\x5a','\x43\x4d\x76\x79\x77\x68\x43','\x79\x32\x39\x55\x44\x67\x76\x55\x44\x66\x39\x4d\x41\x77\x58\x30\x7a\x78\x69','\x44\x32\x76\x49\x78\x33\x6e\x4c\x79\x78\x6a\x4a\x41\x66\x39\x57\x43\x4d\x76\x32\x41\x77\x76\x33','\x43\x68\x76\x30\x75\x68\x6a\x50\x42\x33\x6a\x75\x44\x78\x6a\x55\x43\x57','\x44\x67\x39\x56\x42\x66\x39\x4a\x79\x77\x58\x53','\x79\x32\x66\x55\x79\x32\x76\x53\x42\x67\x76\x4b','\x71\x31\x62\x74\x43\x76\x79','\x42\x33\x76\x30\x43\x68\x76\x30','\x72\x30\x58\x34\x7a\x68\x4f','\x79\x33\x6a\x4c\x79\x78\x72\x4c\x7a\x65\x66\x30','\x69\x49\x62\x54\x79\x78\x72\x4a\x41\x67\x76\x5a\x69\x67\x72\x4c\x42\x4e\x4b\x47\x43\x67\x66\x30\x44\x67\x76\x59\x42\x49\x61\x49','\x79\x4c\x50\x66\x72\x66\x4b','\x79\x76\x72\x4a\x41\x67\x53','\x79\x32\x39\x54\x43\x68\x76\x30\x7a\x78\x69\x54\x44\x78\x6e\x4c\x6f\x4d\x6e\x53\x41\x77\x6e\x52','\x79\x32\x39\x54\x43\x67\x58\x4c\x44\x67\x76\x4b','\x42\x67\x66\x49\x7a\x77\x57','\x73\x77\x35\x57\x44\x78\x71\x47\x43\x33\x72\x59\x41\x77\x35\x4e\x69\x67\x31\x31\x43\x33\x71\x47\x42\x4d\x39\x30\x69\x67\x6a\x4c\x69\x67\x76\x54\x43\x68\x72\x35','\x74\x66\x6a\x50\x79\x30\x71','\x79\x77\x58\x30','\x69\x64\x34\x39\x69\x61','\x79\x32\x39\x54\x43\x68\x76\x30\x7a\x78\x6a\x62\x79\x33\x72\x50\x42\x32\x34','\x41\x67\x66\x5a\x76\x78\x6e\x48\x7a\x32\x75','\x75\x67\x39\x53\x74\x66\x71','\x79\x31\x4c\x6f\x79\x33\x4f','\x78\x73\x62\x50\x43\x59\x62\x54\x41\x78\x6e\x5a\x41\x77\x35\x4e\x69\x67\x65\x47\x44\x68\x4c\x57\x7a\x73\x62\x4b\x41\x78\x6e\x4a\x43\x4d\x4c\x54\x41\x77\x35\x48\x44\x67\x39\x59','\x72\x65\x4c\x34\x42\x75\x79','\x43\x67\x76\x31\x45\x67\x79','\x44\x67\x39\x52\x7a\x77\x35\x5a','\x44\x67\x39\x56\x42\x66\x39\x4a\x79\x77\x58\x53\x78\x33\x6a\x4c\x43\x78\x76\x4c\x43\x33\x72\x4c\x7a\x61','\x43\x33\x62\x53\x41\x78\x71','\x77\x4d\x39\x34\x76\x77\x53','\x42\x67\x76\x70\x73\x30\x30','\x43\x33\x72\x59\x41\x77\x35\x4e\x41\x77\x7a\x35','\x7a\x4d\x39\x59\x42\x77\x66\x30','\x79\x32\x39\x54\x43\x68\x76\x30\x7a\x78\x69\x54\x44\x78\x6e\x4c','\x43\x4b\x6e\x63\x42\x68\x75','\x42\x33\x76\x30\x79\x32\x39\x54\x7a\x71','\x7a\x68\x50\x4c\x71\x4b\x75','\x45\x78\x66\x54\x45\x67\x4f','\x79\x32\x66\x55\x42\x4d\x39\x30\x69\x68\x6e\x30\x7a\x77\x76\x59\x69\x67\x65\x47','\x43\x4d\x76\x5a\x42\x32\x58\x32\x7a\x71','\x77\x4b\x54\x63\x45\x75\x75','\x6d\x74\x65\x32\x6d\x74\x4b\x58\x6d\x4b\x66\x35\x42\x4b\x48\x50\x76\x71','\x43\x32\x72\x6d\x41\x76\x65','\x43\x33\x4c\x5a\x44\x67\x76\x54','\x42\x4d\x66\x54\x7a\x71','\x72\x77\x48\x55\x79\x4e\x61','\x44\x67\x39\x56\x42\x66\x39\x55\x79\x77\x31\x4c','\x79\x32\x39\x54\x43\x68\x76\x30\x7a\x78\x6a\x46\x44\x78\x6e\x4c\x78\x33\x62\x59\x7a\x78\x7a\x50\x7a\x78\x43','\x7a\x68\x6a\x50\x44\x4d\x76\x74\x44\x68\x6a\x4c\x79\x77\x30','\x43\x33\x72\x48\x43\x4e\x71','\x72\x33\x66\x34\x42\x4d\x30','\x42\x4d\x76\x48\x43\x47','\x7a\x4e\x76\x55\x79\x33\x72\x50\x42\x32\x34','\x69\x49\x62\x50\x43\x59\x62\x55\x42\x33\x71\x47\x42\x32\x34\x47\x44\x67\x48\x4c\x69\x67\x66\x53\x42\x67\x39\x33\x69\x67\x58\x50\x43\x33\x71','\x41\x78\x6e\x6a\x42\x4e\x72\x4c\x7a\x32\x76\x59','\x79\x78\x6a\x50\x79\x75\x58\x48\x79\x4d\x76\x53','\x71\x4d\x48\x4f\x77\x4b\x6d','\x42\x33\x62\x4c\x42\x47','\x42\x77\x39\x4b\x7a\x77\x57','\x72\x67\x31\x33\x73\x31\x47','\x42\x77\x39\x4b\x7a\x77\x58\x46\x43\x4d\x76\x58\x44\x77\x4c\x59\x7a\x77\x71','\x7a\x4e\x76\x5a\x76\x76\x4f','\x72\x67\x4c\x54\x7a\x77\x35\x5a\x41\x77\x39\x55\x43\x59\x62\x54\x44\x78\x6e\x30\x69\x67\x6a\x4c\x69\x67\x65\x47\x43\x67\x39\x5a\x41\x78\x72\x50\x44\x4d\x75\x47\x41\x77\x35\x30\x7a\x77\x44\x4c\x43\x47','\x75\x4e\x76\x41\x74\x32\x71','\x42\x4e\x76\x54\x79\x4d\x76\x59','\x7a\x31\x6a\x6d\x76\x4b\x71','\x42\x67\x76\x55\x7a\x33\x72\x4f\x78\x32\x76\x34\x79\x32\x76\x4c\x7a\x67\x76\x4b','\x45\x67\x48\x48\x75\x33\x4b','\x73\x77\x35\x32\x79\x77\x58\x50\x7a\x63\x62\x54\x42\x32\x72\x4c\x42\x63\x62\x50\x7a\x64\x4f\x47','\x43\x4b\x76\x4a\x45\x4d\x47','\x73\x4e\x66\x66\x41\x77\x4f','\x7a\x67\x66\x30\x79\x71','\x75\x66\x4c\x67\x41\x66\x6d','\x7a\x67\x4c\x54\x7a\x77\x35\x5a\x41\x77\x39\x55\x43\x57','\x42\x33\x76\x30\x43\x68\x76\x30\x78\x33\x72\x56\x41\x32\x76\x55\x43\x31\x39\x4b\x7a\x78\x72\x48\x41\x77\x58\x5a','\x7a\x67\x76\x30\x79\x77\x4c\x53','\x43\x33\x76\x4a\x79\x32\x76\x4c\x7a\x67\x76\x4b','\x44\x67\x39\x56\x42\x66\x39\x49\x42\x67\x39\x4a\x41\x32\x76\x4b','\x75\x32\x4c\x4a\x71\x4d\x47','\x43\x33\x72\x48\x43\x4e\x72\x71\x43\x4d\x39\x54\x41\x78\x6e\x4c','\x73\x67\x31\x68\x44\x32\x53','\x43\x33\x76\x49\x42\x77\x4c\x30\x76\x67\x39\x56\x42\x65\x39\x31\x44\x68\x62\x31\x44\x68\x6d','\x78\x33\x6e\x30\x79\x78\x72\x31\x43\x57','\x43\x4d\x76\x48\x43\x32\x39\x55\x41\x77\x35\x4e\x78\x33\x72\x4c\x45\x68\x71','\x43\x65\x58\x69\x77\x68\x43','\x79\x78\x6a\x4e\x43\x57','\x79\x77\x6e\x30\x41\x77\x39\x55','\x75\x32\x6e\x5a\x7a\x31\x79','\x7a\x4d\x4c\x53\x44\x67\x76\x59\x7a\x77\x71','\x72\x4e\x62\x63\x74\x65\x6d','\x43\x4d\x76\x58\x44\x77\x4c\x59\x7a\x78\x6e\x46\x79\x77\x6e\x30\x41\x77\x39\x55','\x75\x65\x6e\x78\x7a\x30\x79','\x44\x78\x6e\x4c\x43\x4c\x39\x53\x42\x32\x6e\x48\x44\x67\x4c\x56\x42\x47','\x7a\x67\x76\x5a\x44\x68\x6a\x31\x79\x33\x72\x50\x44\x4d\x75\x47\x79\x77\x6e\x30\x41\x77\x39\x55\x69\x67\x72\x4c\x42\x4d\x4c\x4c\x7a\x64\x4f\x47\x41\x77\x35\x57\x44\x78\x71\x47\x42\x77\x66\x30\x79\x32\x48\x4c\x43\x59\x61','\x79\x32\x48\x31\x42\x4d\x54\x6a\x42\x4d\x72\x4c\x45\x61','\x43\x68\x6a\x50\x42\x33\x6a\x75\x44\x78\x6a\x55\x43\x57','\x79\x77\x7a\x30\x7a\x78\x6a\x75\x42\x32\x39\x53\x71\x32\x66\x53\x42\x61','\x79\x77\x58\x53\x42\x33\x44\x6d\x41\x78\x6e\x30','\x7a\x77\x44\x59\x7a\x78\x6e\x5a\x69\x67\x72\x4c\x42\x4d\x4c\x4c\x7a\x64\x4f\x47\x41\x67\x39\x5a\x44\x63\x61\x49','\x79\x31\x66\x31\x75\x4b\x69','\x44\x67\x39\x56\x42\x65\x6e\x48\x42\x67\x58\x63\x44\x77\x7a\x4d\x7a\x78\x69','\x79\x32\x39\x54\x43\x68\x76\x30\x7a\x78\x6a\x46\x79\x32\x66\x53\x42\x61','\x6d\x4a\x61\x57\x6e\x65\x7a\x77\x75\x78\x48\x49\x7a\x61','\x41\x67\x39\x56\x41\x33\x6d','\x41\x77\x35\x57\x44\x78\x72\x75\x42\x32\x54\x4c\x42\x4e\x6d','\x42\x33\x76\x30\x43\x68\x76\x30\x78\x33\x72\x56\x41\x32\x76\x55\x43\x57','\x79\x4d\x54\x31\x7a\x31\x61','\x72\x67\x50\x68\x43\x67\x71','\x69\x49\x62\x50\x43\x59\x62\x55\x42\x33\x71\x47\x43\x33\x76\x57\x43\x67\x39\x59\x44\x67\x76\x4b\x69\x67\x6a\x35\x69\x68\x72\x4f\x41\x78\x6d\x47\x7a\x77\x35\x4b\x43\x67\x39\x50\x42\x4e\x71','\x7a\x30\x58\x73\x45\x4b\x65','\x7a\x78\x48\x57\x41\x78\x6a\x4c','\x44\x67\x39\x56\x42\x66\x39\x59\x7a\x78\x6e\x31\x42\x68\x71','\x74\x65\x44\x70\x71\x75\x65','\x45\x66\x48\x35\x44\x67\x38','\x43\x67\x66\x59\x44\x67\x35\x4c\x43\x4b\x4c\x4b','\x42\x68\x76\x6b\x44\x67\x43','\x44\x67\x4c\x54\x7a\x78\x6e\x30\x79\x77\x31\x57','\x41\x77\x35\x32\x79\x77\x58\x50\x7a\x66\x39\x50\x42\x4e\x62\x31\x44\x66\x39\x30\x45\x78\x62\x4c','\x43\x32\x76\x48\x43\x4d\x6e\x4f\x71\x32\x39\x55\x44\x67\x76\x34\x44\x66\x6e\x50\x45\x4d\x75','\x44\x67\x39\x56\x42\x65\x35\x48\x42\x77\x75','\x73\x68\x50\x4b\x75\x66\x75','\x44\x78\x6e\x48\x7a\x32\x75','\x44\x67\x39\x56\x42\x65\x4c\x55\x44\x4d\x39\x4a\x79\x78\x72\x50\x42\x32\x34','\x69\x67\x31\x31\x43\x33\x71\x47\x42\x4d\x39\x30\x69\x67\x6a\x4c\x69\x67\x76\x54\x43\x68\x72\x35','\x79\x4e\x76\x4d\x7a\x4d\x76\x59','\x71\x4b\x6a\x56\x42\x75\x69','\x7a\x4d\x58\x56\x42\x33\x69','\x79\x32\x39\x55\x44\x67\x4c\x55\x44\x77\x75','\x42\x65\x44\x59\x75\x30\x69','\x71\x33\x50\x5a\x72\x33\x71','\x43\x4d\x76\x48\x43\x32\x39\x55\x41\x77\x35\x4e','\x45\x4b\x6e\x57\x79\x33\x79','\x45\x4e\x4c\x41\x43\x4d\x65','\x79\x32\x58\x4c\x79\x78\x69','\x77\x4d\x44\x69\x7a\x33\x4f','\x72\x77\x31\x49\x7a\x77\x72\x4b\x41\x77\x35\x4e\x76\x4d\x66\x53\x41\x77\x72\x48\x44\x67\x4c\x56\x42\x4b\x76\x59\x43\x4d\x39\x59','\x43\x32\x58\x50\x79\x32\x75','\x7a\x67\x76\x55\x45\x76\x62\x48\x44\x68\x72\x4c\x43\x4d\x35\x5a','\x77\x78\x7a\x71\x43\x65\x30','\x44\x77\x35\x52\x42\x4d\x39\x33\x42\x49\x62\x4d\x79\x77\x4c\x53\x44\x78\x6a\x4c','\x41\x77\x35\x32\x79\x77\x58\x50\x7a\x66\x39\x59\x7a\x78\x66\x31\x7a\x78\x6e\x30\x78\x32\x76\x59\x43\x4d\x39\x59','\x42\x4e\x72\x49\x75\x4b\x43','\x44\x67\x76\x59\x42\x77\x4c\x55\x79\x78\x72\x4c','\x43\x33\x6a\x4a','\x41\x77\x35\x4a\x42\x32\x31\x57\x42\x67\x76\x30\x7a\x71','\x7a\x77\x35\x4a\x42\x32\x72\x50\x42\x4d\x44\x46\x7a\x4d\x39\x59\x42\x77\x66\x30\x69\x67\x31\x31\x43\x33\x71\x47\x79\x4d\x75\x47\x6a\x32\x7a\x53\x42\x32\x66\x30\x6a\x59\x62\x56\x43\x49\x61\x4e\x79\x4d\x66\x5a\x7a\x74\x79\x30\x6a\x57','\x6e\x74\x69\x31\x6e\x33\x6a\x49\x44\x67\x44\x70\x73\x61','\x79\x4d\x66\x30\x79\x32\x48\x46\x44\x67\x39\x56\x78\x32\x58\x48\x43\x4d\x44\x4c','\x77\x4d\x6e\x6d\x76\x4e\x69','\x77\x67\x50\x52\x75\x75\x71','\x79\x4d\x48\x72\x45\x76\x69','\x43\x4e\x76\x55\x71\x77\x7a\x30\x7a\x78\x69','\x73\x78\x44\x56\x73\x75\x4b','\x74\x33\x66\x72\x79\x77\x38','\x42\x32\x6a\x73\x41\x75\x34','\x71\x4b\x48\x41\x7a\x4d\x75','\x43\x68\x76\x5a\x41\x61','\x7a\x67\x76\x53\x7a\x78\x72\x4c','\x41\x77\x35\x5a\x44\x68\x6a\x31\x79\x33\x72\x50\x42\x32\x35\x5a','\x79\x32\x66\x55\x79\x32\x76\x53','\x75\x4e\x44\x30\x41\x76\x65','\x69\x67\x4c\x5a\x69\x67\x35\x56\x44\x63\x62\x48\x69\x68\x6e\x30\x43\x4d\x4c\x55\x7a\x57','\x43\x4e\x76\x55\x73\x77\x71','\x7a\x67\x76\x55\x45\x75\x58\x50\x43\x33\x71','\x77\x32\x66\x31\x7a\x67\x4c\x30\x78\x71','\x42\x77\x66\x34','\x73\x77\x35\x57\x44\x78\x71\x47\x79\x78\x6a\x59\x79\x78\x4b\x47\x42\x78\x76\x5a\x44\x63\x62\x49\x7a\x73\x62\x4f\x42\x32\x31\x56\x7a\x32\x76\x55\x7a\x77\x39\x31\x43\x5a\x53\x47\x41\x77\x35\x4b\x7a\x78\x47\x47','\x71\x30\x50\x36\x73\x66\x4f','\x44\x68\x4c\x57\x7a\x71','\x71\x30\x4c\x68\x41\x32\x34','\x76\x33\x4c\x36\x43\x32\x4b','\x7a\x4d\x66\x50\x42\x67\x76\x4b','\x76\x33\x62\x33\x41\x4b\x6d','\x73\x68\x6e\x7a\x41\x4e\x75','\x7a\x77\x35\x4a\x42\x32\x72\x50\x42\x4d\x44\x46\x7a\x4d\x39\x59\x42\x77\x66\x30','\x41\x77\x35\x46\x43\x68\x6a\x56\x7a\x33\x6a\x4c\x43\x33\x6d','\x79\x78\x6e\x35\x42\x4d\x6e\x6a\x44\x67\x76\x59\x79\x78\x72\x56\x43\x47','\x7a\x77\x31\x57\x44\x68\x4c\x46\x41\x77\x35\x57\x44\x78\x71','\x41\x32\x48\x35\x45\x65\x30','\x7a\x67\x39\x55\x7a\x71','\x72\x75\x35\x7a\x72\x68\x4b','\x7a\x66\x7a\x4e\x71\x77\x6d','\x75\x77\x4c\x70\x73\x77\x79','\x43\x32\x48\x50\x7a\x4e\x71','\x7a\x4d\x58\x48\x44\x65\x31\x48\x43\x61','\x6d\x74\x79\x58\x6e\x64\x71\x33\x6e\x76\x4c\x77\x75\x66\x62\x41\x7a\x61','\x74\x77\x39\x4b\x7a\x77\x57\x47\x41\x78\x6d\x47\x43\x4d\x76\x58\x44\x77\x4c\x59\x7a\x77\x71','\x79\x32\x39\x4b\x7a\x71','\x44\x67\x39\x56\x42\x66\x6a\x4c\x43\x33\x76\x53\x44\x68\x6d','\x43\x31\x44\x68\x43\x76\x6d','\x44\x78\x6e\x4c\x43\x4c\x62\x48\x43\x4e\x72\x5a','\x42\x67\x39\x33','\x73\x75\x31\x79\x41\x76\x71','\x6f\x64\x69\x59\x6d\x30\x48\x33\x72\x4e\x76\x48\x43\x61','\x7a\x33\x62\x35\x79\x31\x69','\x76\x66\x4c\x36\x76\x67\x34','\x7a\x33\x6e\x6e\x43\x32\x6d','\x76\x30\x44\x6a\x72\x75\x38','\x44\x67\x76\x34\x44\x66\x62\x50\x7a\x77\x6e\x4c\x43\x57','\x42\x31\x6a\x56\x75\x65\x53','\x43\x68\x6a\x4c\x44\x4d\x4c\x56\x44\x78\x6e\x73\x7a\x78\x6e\x57\x42\x32\x35\x5a\x7a\x75\x4c\x4b','\x7a\x4d\x58\x56\x79\x78\x71','\x74\x30\x72\x4e\x7a\x68\x71','\x42\x78\x6e\x4e\x78\x5a\x61','\x6d\x4a\x43\x32\x41\x67\x35\x68\x72\x68\x6a\x71','\x44\x30\x35\x63\x44\x77\x69','\x79\x78\x6e\x5a\x41\x78\x6e\x30\x79\x77\x35\x30\x76\x67\x76\x34\x44\x61','\x43\x4d\x76\x58\x44\x77\x4c\x59\x7a\x78\x6e\x62\x79\x33\x72\x50\x42\x32\x34','\x7a\x67\x76\x32\x7a\x77\x58\x56\x43\x67\x76\x59','\x41\x67\x66\x67\x75\x4b\x75','\x44\x65\x6e\x6f\x72\x78\x65','\x75\x33\x4c\x55\x76\x78\x71','\x71\x77\x6e\x35\x44\x4d\x6d','\x74\x4e\x6e\x33\x76\x4b\x43','\x72\x4d\x48\x35\x45\x4c\x43','\x76\x67\x39\x56\x42\x63\x62\x30\x45\x78\x62\x4c\x69\x63\x69','\x77\x67\x35\x55\x43\x76\x43','\x69\x67\x4c\x5a\x69\x67\x35\x56\x44\x63\x62\x48\x42\x49\x62\x48\x43\x4e\x6a\x48\x45\x71','\x43\x4d\x76\x5a\x43\x67\x39\x55\x43\x32\x75\x55\x42\x33\x76\x30\x43\x68\x76\x30\x78\x32\x4c\x30\x7a\x77\x30\x55\x79\x77\x72\x4b\x7a\x77\x71','\x79\x32\x58\x56\x43\x32\x75','\x43\x4b\x4c\x78\x41\x77\x4f','\x71\x4d\x54\x62\x43\x31\x47','\x41\x31\x76\x35\x43\x32\x4b','\x44\x4d\x72\x54\x76\x65\x75','\x41\x31\x6a\x63\x41\x4d\x75','\x41\x77\x35\x4b\x7a\x78\x48\x70\x7a\x47','\x71\x77\x4c\x51\x43\x4c\x47','\x41\x32\x76\x35\x43\x57','\x44\x67\x39\x56\x42\x66\x39\x50\x42\x4e\x7a\x56\x79\x32\x66\x30\x41\x77\x39\x55','\x79\x32\x39\x54\x43\x68\x76\x30\x7a\x78\x69\x54\x44\x78\x6e\x4c\x6f\x47','\x44\x67\x39\x56\x42\x65\x6e\x48\x42\x67\x58\x70\x43\x4d\x72\x4c\x43\x47','\x43\x4d\x76\x4d\x44\x78\x6e\x48\x42\x61','\x42\x67\x66\x5a\x44\x66\x6a\x4c\x7a\x4d\x4c\x53\x42\x65\x31\x5a','\x79\x4d\x76\x4d\x42\x33\x6a\x4c','\x41\x75\x31\x6a\x7a\x4c\x6d','\x79\x78\x76\x30\x42\x57','\x42\x68\x44\x35\x72\x77\x71','\x75\x4b\x31\x69\x41\x30\x43','\x43\x4b\x76\x55\x43\x77\x34','\x43\x67\x76\x55\x7a\x67\x4c\x55\x7a\x30\x6e\x48\x42\x67\x58\x5a','\x42\x33\x76\x30\x43\x68\x76\x30\x78\x33\x72\x4c\x45\x68\x71','\x43\x33\x76\x4a\x79\x32\x76\x5a\x43\x57','\x43\x32\x76\x5a\x43\x32\x4c\x56\x42\x49\x35\x31\x43\x67\x72\x48\x44\x67\x76\x4b','\x41\x67\x4c\x4e\x41\x61','\x43\x32\x39\x54\x7a\x71','\x43\x67\x48\x35\x42\x77\x47','\x79\x32\x39\x54\x43\x68\x76\x30\x7a\x78\x6a\x76\x43\x32\x75','\x44\x67\x66\x5a\x41\x31\x62\x48\x43\x4e\x72\x5a','\x42\x32\x6e\x59\x72\x4e\x47','\x43\x32\x4c\x55\x41\x57','\x71\x75\x44\x6e\x7a\x31\x4b','\x41\x67\x50\x66\x42\x32\x69','\x41\x77\x35\x32\x79\x77\x58\x50\x7a\x66\x39\x30\x42\x32\x54\x4c\x42\x4c\x39\x30\x45\x78\x62\x4c','\x7a\x77\x35\x4b\x43\x31\x44\x50\x44\x67\x47','\x74\x78\x48\x34\x75\x77\x65','\x74\x67\x58\x74\x77\x4d\x4b','\x42\x77\x66\x34\x78\x33\x72\x56\x41\x32\x76\x55\x43\x57','\x7a\x4c\x48\x49\x41\x32\x38','\x43\x33\x72\x4c\x7a\x78\x69','\x45\x4c\x72\x73\x77\x66\x6d','\x76\x4c\x72\x4e\x73\x4e\x61','\x44\x33\x76\x4a\x79\x76\x65','\x43\x4d\x76\x48\x43\x32\x39\x55\x41\x77\x35\x4e\x75\x67\x4c\x4c\x79\x32\x76\x5a','\x78\x73\x35\x30\x45\x78\x62\x4c','\x42\x33\x62\x4c\x42\x4d\x66\x50\x74\x77\x76\x5a\x43\x32\x66\x4e\x7a\x78\x6e\x75\x42\x31\x6e\x48\x42\x4d\x72\x49\x42\x33\x48\x6a\x42\x4e\x62\x31\x44\x64\x4f\x47\x42\x77\x76\x5a\x43\x32\x66\x4e\x7a\x78\x6d\x47\x42\x78\x76\x5a\x44\x63\x62\x4a\x42\x32\x35\x30\x79\x77\x4c\x55\x69\x67\x66\x30\x69\x67\x58\x4c\x79\x78\x6e\x30\x69\x67\x39\x55\x7a\x73\x62\x31\x43\x32\x76\x59\x69\x67\x31\x4c\x43\x33\x6e\x48\x7a\x32\x75','\x77\x78\x66\x72\x42\x75\x47','\x42\x33\x50\x48\x45\x66\x43','\x79\x75\x50\x4d\x43\x76\x4f','\x43\x68\x62\x79\x77\x4c\x47','\x74\x4b\x35\x50\x77\x76\x6d','\x77\x4d\x72\x75\x74\x77\x65','\x44\x67\x39\x74\x44\x68\x6a\x50\x42\x4d\x43','\x41\x67\x39\x5a\x44\x61','\x7a\x67\x76\x53\x44\x67\x65','\x6d\x74\x6d\x35\x6d\x64\x43\x57\x43\x32\x58\x6e\x44\x4e\x44\x74','\x44\x33\x6e\x71\x75\x32\x53','\x43\x33\x72\x56\x43\x61','\x7a\x4e\x6a\x56\x42\x71','\x44\x67\x39\x56\x42\x68\x6e\x42','\x75\x4e\x76\x55\x72\x78\x7a\x4c\x42\x4e\x72\x74\x42\x33\x76\x59\x79\x32\x75\x47\x7a\x67\x39\x4c\x43\x59\x62\x55\x42\x33\x71\x47\x43\x33\x76\x57\x43\x67\x39\x59\x44\x63\x62\x5a\x44\x77\x6a\x54\x41\x78\x72\x75\x42\x32\x39\x53\x74\x33\x76\x30\x43\x68\x76\x30\x43\x57','\x7a\x77\x35\x30\x43\x4d\x4c\x4c\x43\x57','\x44\x76\x6e\x70\x73\x66\x79','\x44\x4d\x66\x53\x44\x77\x75','\x75\x31\x62\x75\x7a\x65\x75','\x79\x4d\x76\x4d\x42\x33\x6a\x4c\x76\x67\x39\x56\x42\x65\x6e\x48\x42\x67\x57','\x44\x67\x39\x56\x42\x63\x31\x50\x42\x4e\x7a\x56\x79\x32\x66\x30\x41\x77\x39\x55','\x79\x32\x39\x54\x43\x67\x58\x4c\x44\x67\x4c\x56\x42\x4c\x39\x30\x42\x32\x54\x4c\x42\x4e\x6d','\x74\x68\x4c\x66\x42\x4b\x65','\x73\x65\x76\x78\x43\x66\x47','\x44\x67\x39\x56\x42\x66\x39\x4a\x79\x77\x58\x53\x78\x32\x4c\x4b','\x44\x67\x76\x34\x44\x61','\x6d\x4a\x79\x32\x6d\x5a\x62\x62\x43\x68\x72\x79\x75\x4b\x47','\x41\x68\x6a\x4c\x7a\x47','\x6e\x78\x57\x5a\x46\x64\x62\x38\x6e\x68\x57\x58\x46\x64\x69','\x7a\x32\x76\x30\x71\x33\x76\x59\x43\x4d\x76\x55\x44\x65\x6e\x56\x43\x33\x71','\x7a\x78\x48\x4c\x79\x33\x76\x30\x41\x77\x39\x55\x6c\x4e\x6e\x30\x79\x78\x6a\x30\x7a\x77\x71','\x7a\x78\x7a\x4c\x42\x4e\x72\x5a','\x41\x77\x35\x4d\x42\x57','\x7a\x4d\x4c\x53\x44\x67\x76\x59','\x41\x78\x72\x4c\x43\x4d\x66\x30\x42\x33\x69','\x41\x78\x4c\x51\x75\x32\x43','\x43\x32\x76\x30','\x79\x77\x6e\x30\x41\x77\x39\x55\x69\x68\x6a\x48\x44\x67\x75\x47\x42\x67\x4c\x54\x41\x78\x71\x47\x7a\x78\x48\x4a\x7a\x77\x76\x4b\x7a\x77\x71\x36\x69\x61','\x79\x77\x58\x53\x42\x33\x43','\x69\x67\x4c\x5a\x69\x61','\x44\x67\x48\x59\x7a\x77\x66\x4b\x73\x77\x71','\x42\x77\x4c\x34\x7a\x77\x72\x46\x41\x77\x35\x57\x44\x78\x72\x46\x44\x68\x4c\x57\x7a\x78\x6d','\x43\x32\x4c\x36\x7a\x71','\x44\x30\x31\x51\x73\x4e\x79','\x73\x4e\x76\x66\x76\x4b\x34','\x43\x67\x66\x5a\x43\x57','\x44\x4d\x66\x59\x41\x77\x66\x55\x44\x61','\x77\x65\x66\x5a\x43\x33\x43','\x44\x67\x66\x55\x7a\x32\x58\x4c\x6c\x57','\x7a\x78\x6a\x59\x42\x33\x69','\x41\x77\x35\x32\x79\x77\x58\x50\x7a\x66\x39\x30\x42\x32\x39\x53','\x43\x78\x76\x4c\x44\x77\x76\x4b','\x7a\x77\x44\x59\x7a\x78\x6e\x5a\x69\x67\x72\x4c\x42\x4d\x4c\x4c\x7a\x63\x62\x49\x45\x73\x62\x48\x42\x67\x58\x56\x44\x30\x7a\x55','\x44\x67\x39\x56\x42\x65\x39\x31\x44\x68\x62\x31\x44\x65\x4c\x55\x7a\x67\x76\x34','\x76\x67\x39\x52\x7a\x77\x34\x47\x79\x78\x6a\x59\x79\x78\x4b\x47\x79\x78\x71\x47\x41\x77\x35\x4b\x7a\x78\x47\x47','\x79\x75\x4c\x34\x79\x30\x69','\x43\x67\x66\x59\x79\x77\x31\x4c\x44\x67\x76\x59\x43\x57','\x44\x32\x66\x50\x44\x67\x76\x59\x43\x57','\x7a\x67\x6e\x68\x79\x32\x34','\x41\x77\x31\x48\x7a\x32\x76\x46\x44\x78\x6a\x53','\x44\x33\x50\x72\x44\x77\x4f','\x45\x66\x50\x4f\x72\x4c\x6d','\x44\x67\x39\x56\x42\x65\x6e\x48\x42\x67\x58\x6a\x7a\x61','\x41\x67\x66\x55\x7a\x67\x58\x4c\x76\x67\x39\x56\x42\x65\x6e\x48\x42\x67\x57','\x42\x77\x66\x57','\x79\x32\x66\x55\x79\x32\x76\x53\x75\x4d\x76\x58\x44\x77\x76\x5a\x44\x67\x76\x4b','\x44\x67\x39\x6d\x42\x33\x44\x4c\x43\x4b\x6e\x48\x43\x32\x75','\x76\x78\x6e\x4f\x7a\x75\x38','\x43\x4d\x76\x48\x43\x32\x39\x55\x41\x77\x35\x4e\x78\x33\x72\x56\x41\x32\x76\x55\x43\x57','\x42\x4d\x39\x33','\x79\x32\x39\x55\x44\x67\x76\x55\x44\x61','\x41\x67\x66\x5a','\x79\x77\x72\x4b\x43\x4d\x76\x5a\x43\x57','\x43\x67\x76\x59\x75\x32\x76\x4a\x42\x32\x35\x4b\x75\x67\x76\x59\x75\x32\x76\x5a\x43\x32\x4c\x56\x42\x47','\x75\x67\x54\x50\x41\x32\x71','\x43\x4c\x62\x4b\x42\x4b\x53','\x43\x4d\x39\x53\x7a\x71','\x7a\x4d\x6e\x46','\x7a\x4c\x6e\x72\x79\x75\x53','\x43\x4d\x76\x5a\x43\x67\x39\x55\x43\x32\x75\x55\x79\x32\x39\x54\x43\x67\x58\x4c\x44\x67\x76\x4b'];a0_0x3325=function(){return _0x59c050;};return a0_0x3325();}function createTranslatorContext(_0x22e594){const _0x387661=a0_0x5cfbcf,_0xa3cd28={'\x76\x64\x6d\x54\x45':function(_0x4128f4,_0x541021){return _0x4128f4/_0x541021;}};return{'\x63\x68\x75\x6e\x6b\x49\x6e\x64\x65\x78':0x0,'\x74\x6f\x6f\x6c\x43\x61\x6c\x6c\x42\x75\x66\x66\x65\x72':new Map(),'\x63\x72\x65\x61\x74\x65\x64\x41\x74':Math[_0x387661(0x358)](_0xa3cd28[_0x387661(0x3b9)](Date[_0x387661(0x23b)](),0x3e8)),..._0x22e594};}export{EmbeddingValidationError,HookChain,InMemoryResponseStore,ResponsesValidationError,Run,actionRateLimitHook,assembleResponseOutput,auditLogHook,buildResponseShell,costCapHook,createTranslatorContext,destructiveActionGuardHook,egressPolicyHook,normalizeResponsesWebSearchForTangleRouter,openaiMessagesToSandboxInput,outcomeToFinishReason,resolvePreviousResponseId,runEvents,sandboxEventToChatChunk,sandboxEventToCompletionChunk,sandboxEventToResponsesEvent,screenshotRedactionHook,usageFromEvents,validateEmbeddingRequest,validateResponsesRequest};
|
|
1
|
+
//#region src/openai/hooks.ts
|
|
2
|
+
/**
|
|
3
|
+
* Sequential hook composer. Hooks run in registration order; `block` and
|
|
4
|
+
* `terminate` short-circuit. `rewrite` and `override` thread their
|
|
5
|
+
* mutated payloads through to the remaining hooks so subsequent hooks
|
|
6
|
+
* observe the rewritten args / overridden result.
|
|
7
|
+
*/
|
|
8
|
+
var HookChain = class {
|
|
9
|
+
hooks;
|
|
10
|
+
constructor(hooks = []) {
|
|
11
|
+
this.hooks = hooks;
|
|
12
|
+
}
|
|
13
|
+
/** Number of hooks in the chain. */
|
|
14
|
+
get size() {
|
|
15
|
+
return this.hooks.length;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Run every `beforeToolCall` in registration order. Returns the first
|
|
19
|
+
* non-`allow` outcome (block/rewrite), or `allow` if the chain ran
|
|
20
|
+
* clean. `rewrite` outcomes are threaded forward so later hooks see
|
|
21
|
+
* the mutated args.
|
|
22
|
+
*/
|
|
23
|
+
async runBefore(ctx) {
|
|
24
|
+
let current = ctx;
|
|
25
|
+
let lastRewrite = null;
|
|
26
|
+
for (const hook of this.hooks) {
|
|
27
|
+
if (!hook.beforeToolCall) continue;
|
|
28
|
+
const outcome = await hook.beforeToolCall(current);
|
|
29
|
+
if (outcome.action === "block") return outcome;
|
|
30
|
+
if (outcome.action === "rewrite") {
|
|
31
|
+
current = {
|
|
32
|
+
...current,
|
|
33
|
+
args: outcome.args
|
|
34
|
+
};
|
|
35
|
+
lastRewrite = outcome;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return lastRewrite ?? { action: "allow" };
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Run every `afterToolCall` in registration order. Returns the first
|
|
42
|
+
* `terminate` outcome immediately. `override` outcomes are threaded
|
|
43
|
+
* forward so later hooks see the mutated result; the final result is
|
|
44
|
+
* surfaced as the last `override`, or `pass` if no hook overrode.
|
|
45
|
+
*/
|
|
46
|
+
async runAfter(ctx, result) {
|
|
47
|
+
let current = result;
|
|
48
|
+
let lastOverride = null;
|
|
49
|
+
for (const hook of this.hooks) {
|
|
50
|
+
if (!hook.afterToolCall) continue;
|
|
51
|
+
const outcome = await hook.afterToolCall(ctx, current);
|
|
52
|
+
if (outcome.action === "terminate") return outcome;
|
|
53
|
+
if (outcome.action === "override") {
|
|
54
|
+
current = outcome.result;
|
|
55
|
+
lastOverride = outcome;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return lastOverride ?? { action: "pass" };
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Emits a structured `AuditEvent` for every tool call (before + after).
|
|
63
|
+
* Default sink is `console.info`. The route layer swaps the sink for
|
|
64
|
+
* the eval-runs DuckDB writer.
|
|
65
|
+
*/
|
|
66
|
+
function auditLogHook(opts = {}) {
|
|
67
|
+
const sink = opts.sink ?? ((event) => {
|
|
68
|
+
console.info("[audit]", event);
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
async beforeToolCall(ctx) {
|
|
72
|
+
await sink({
|
|
73
|
+
phase: "before",
|
|
74
|
+
runId: ctx.runId,
|
|
75
|
+
threadId: ctx.threadId,
|
|
76
|
+
partnerId: ctx.partnerId,
|
|
77
|
+
toolName: ctx.toolName,
|
|
78
|
+
callId: ctx.callId,
|
|
79
|
+
timestamp: ctx.timestamp,
|
|
80
|
+
args: ctx.args
|
|
81
|
+
});
|
|
82
|
+
return { action: "allow" };
|
|
83
|
+
},
|
|
84
|
+
async afterToolCall(ctx, result) {
|
|
85
|
+
await sink({
|
|
86
|
+
phase: "after",
|
|
87
|
+
runId: ctx.runId,
|
|
88
|
+
threadId: ctx.threadId,
|
|
89
|
+
partnerId: ctx.partnerId,
|
|
90
|
+
toolName: ctx.toolName,
|
|
91
|
+
callId: ctx.callId,
|
|
92
|
+
timestamp: ctx.timestamp,
|
|
93
|
+
result
|
|
94
|
+
});
|
|
95
|
+
return { action: "pass" };
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
const NETWORK_TOOL_REGEX = /^(fetch|http|https|browser|playwright|curl|wget|computer-use:click|computer-use:type)/i;
|
|
100
|
+
const URL_FIELD_NAMES = new Set([
|
|
101
|
+
"url",
|
|
102
|
+
"uri",
|
|
103
|
+
"endpoint",
|
|
104
|
+
"href",
|
|
105
|
+
"src",
|
|
106
|
+
"target",
|
|
107
|
+
"address"
|
|
108
|
+
]);
|
|
109
|
+
function extractUrlsFromArgs(args) {
|
|
110
|
+
const out = [];
|
|
111
|
+
const visit = (val) => {
|
|
112
|
+
if (typeof val === "string") {
|
|
113
|
+
if (/^https?:\/\//i.test(val)) try {
|
|
114
|
+
const u = new URL(val);
|
|
115
|
+
out.push({
|
|
116
|
+
raw: val,
|
|
117
|
+
host: u.host
|
|
118
|
+
});
|
|
119
|
+
} catch {
|
|
120
|
+
out.push({
|
|
121
|
+
raw: val,
|
|
122
|
+
host: null
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (val === null || typeof val !== "object") return;
|
|
128
|
+
if (Array.isArray(val)) {
|
|
129
|
+
for (const item of val) visit(item);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
for (const [k, v] of Object.entries(val)) {
|
|
133
|
+
if (URL_FIELD_NAMES.has(k.toLowerCase()) && typeof v === "string") {
|
|
134
|
+
try {
|
|
135
|
+
const u = new URL(v);
|
|
136
|
+
out.push({
|
|
137
|
+
raw: v,
|
|
138
|
+
host: u.host
|
|
139
|
+
});
|
|
140
|
+
} catch {
|
|
141
|
+
out.push({
|
|
142
|
+
raw: v,
|
|
143
|
+
host: null
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
visit(v);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
visit(args);
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
function isNetworkLike(ctx, urls) {
|
|
155
|
+
if (NETWORK_TOOL_REGEX.test(ctx.toolName)) return true;
|
|
156
|
+
return urls.length > 0;
|
|
157
|
+
}
|
|
158
|
+
function hostMatches(host, pattern) {
|
|
159
|
+
if (pattern === host) return true;
|
|
160
|
+
if (pattern.startsWith("*.")) {
|
|
161
|
+
const suffix = pattern.slice(1);
|
|
162
|
+
return host.endsWith(suffix);
|
|
163
|
+
}
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Best-effort allow/deny filter for tool-call URLs.
|
|
168
|
+
*
|
|
169
|
+
* Block tool calls that look network-ish (toolName matches the network
|
|
170
|
+
* regex OR args contain url-like fields) when the resolved host hits
|
|
171
|
+
* the deny list. The allow list is treated as an explicit allowance —
|
|
172
|
+
* when set, only listed hosts pass; unmatched hosts are blocked.
|
|
173
|
+
* `allowFn` overrides both lists when present.
|
|
174
|
+
*
|
|
175
|
+
* **What this hook does NOT catch.** It inspects URL-shaped strings in
|
|
176
|
+
* the tool-call arguments only. The following bypass it silently:
|
|
177
|
+
*
|
|
178
|
+
* - URLs encoded as base64 / hex / `Buffer.from(...)` literals
|
|
179
|
+
* - URLs assembled at execution time from string fragments
|
|
180
|
+
* - URLs reached via redirects, DNS rebinding, or proxy hosts that
|
|
181
|
+
* match the allow list but forward to denied destinations
|
|
182
|
+
* - Network calls made by spawned subprocesses, generated code, or
|
|
183
|
+
* tools whose argument schema does not name a URL field
|
|
184
|
+
*
|
|
185
|
+
* Treat this hook as a UX guardrail (clearer error messages,
|
|
186
|
+
* short-circuiting obvious mistakes) on top of a real egress boundary
|
|
187
|
+
* — not as one. When egress containment is a security requirement
|
|
188
|
+
* (exfil prevention, data residency), enforce it at the runtime
|
|
189
|
+
* sandbox layer (egress firewall, CNI policy, outbound proxy with
|
|
190
|
+
* mTLS) where the agent cannot evade it.
|
|
191
|
+
*/
|
|
192
|
+
function egressPolicyHook(opts = {}) {
|
|
193
|
+
const denyList = opts.denyList ?? [];
|
|
194
|
+
const allowList = opts.allowList;
|
|
195
|
+
return { async beforeToolCall(ctx) {
|
|
196
|
+
const urls = extractUrlsFromArgs(ctx.args);
|
|
197
|
+
if (!isNetworkLike(ctx, urls)) return { action: "allow" };
|
|
198
|
+
if (opts.allowFn) return await opts.allowFn(ctx) ? { action: "allow" } : {
|
|
199
|
+
action: "block",
|
|
200
|
+
reason: "egress denied by allowFn"
|
|
201
|
+
};
|
|
202
|
+
for (const u of urls) {
|
|
203
|
+
if (!u.host) continue;
|
|
204
|
+
for (const pat of denyList) if (hostMatches(u.host, pat)) return {
|
|
205
|
+
action: "block",
|
|
206
|
+
reason: `egress denied: host "${u.host}" matches deny pattern "${pat}"`
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
if (allowList && allowList.length > 0) for (const u of urls) {
|
|
210
|
+
const host = u.host;
|
|
211
|
+
if (!host) return {
|
|
212
|
+
action: "block",
|
|
213
|
+
reason: "egress denied: unparseable url"
|
|
214
|
+
};
|
|
215
|
+
if (!allowList.some((pat) => hostMatches(host, pat))) return {
|
|
216
|
+
action: "block",
|
|
217
|
+
reason: `egress denied: host "${host}" is not on the allow list`
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
return { action: "allow" };
|
|
221
|
+
} };
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Terminates the run when the partner's accumulated cost is at or
|
|
225
|
+
* above `ceiling`. The cost lookup is injected so any usage ledger can
|
|
226
|
+
* back it.
|
|
227
|
+
*/
|
|
228
|
+
function costCapHook(opts) {
|
|
229
|
+
const getCurrentCost = opts.getCurrentCost ?? (async () => 0);
|
|
230
|
+
return {
|
|
231
|
+
async beforeToolCall(ctx) {
|
|
232
|
+
const current = await getCurrentCost(ctx.partnerId);
|
|
233
|
+
if (current >= opts.ceiling) return {
|
|
234
|
+
action: "block",
|
|
235
|
+
reason: `cost cap reached: ${current} >= ${opts.ceiling}`
|
|
236
|
+
};
|
|
237
|
+
return { action: "allow" };
|
|
238
|
+
},
|
|
239
|
+
async afterToolCall(ctx) {
|
|
240
|
+
const current = await getCurrentCost(ctx.partnerId);
|
|
241
|
+
if (current >= opts.ceiling) return {
|
|
242
|
+
action: "terminate",
|
|
243
|
+
reason: `cost cap reached after tool call: ${current} >= ${opts.ceiling}`
|
|
244
|
+
};
|
|
245
|
+
return { action: "pass" };
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Token-bucket rate limiter scoped per session id (`runId`) over
|
|
251
|
+
* `computer-use:*` tool calls. Excess calls are blocked with a clear
|
|
252
|
+
* reason. Non-`computer-use` tools pass through untouched.
|
|
253
|
+
*/
|
|
254
|
+
function actionRateLimitHook(opts) {
|
|
255
|
+
const now = opts.now ?? Date.now;
|
|
256
|
+
const capacity = Math.max(1, Math.floor(opts.perSecondPerSession));
|
|
257
|
+
const refillPerMs = opts.perSecondPerSession / 1e3;
|
|
258
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
259
|
+
return { async beforeToolCall(ctx) {
|
|
260
|
+
if (!ctx.toolName.startsWith("computer-use:")) return { action: "allow" };
|
|
261
|
+
const key = ctx.runId;
|
|
262
|
+
const t = now();
|
|
263
|
+
const bucket = buckets.get(key) ?? {
|
|
264
|
+
tokens: capacity,
|
|
265
|
+
lastRefillMs: t
|
|
266
|
+
};
|
|
267
|
+
const elapsed = Math.max(0, t - bucket.lastRefillMs);
|
|
268
|
+
bucket.tokens = Math.min(capacity, bucket.tokens + elapsed * refillPerMs);
|
|
269
|
+
bucket.lastRefillMs = t;
|
|
270
|
+
if (bucket.tokens < 1) {
|
|
271
|
+
buckets.set(key, bucket);
|
|
272
|
+
return {
|
|
273
|
+
action: "block",
|
|
274
|
+
reason: `action rate limit exceeded: ${opts.perSecondPerSession}/s`
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
bucket.tokens -= 1;
|
|
278
|
+
buckets.set(key, bucket);
|
|
279
|
+
return { action: "allow" };
|
|
280
|
+
} };
|
|
281
|
+
}
|
|
282
|
+
function readScreenshotPayload(result) {
|
|
283
|
+
const candidates = [
|
|
284
|
+
result.content,
|
|
285
|
+
result.details?.screenshot,
|
|
286
|
+
result.details
|
|
287
|
+
];
|
|
288
|
+
for (const c of candidates) if (c && typeof c === "object") {
|
|
289
|
+
if (typeof c.pngBase64 === "string") return c;
|
|
290
|
+
}
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Applied AFTER `computer-use:screenshot`. v1 ships without the
|
|
295
|
+
* `sharp` dependency: when regions are configured, we surface a warning
|
|
296
|
+
* exactly once per process and pass the screenshot through untouched.
|
|
297
|
+
* Pixel-blur lands in a follow-up that introduces `sharp` deliberately.
|
|
298
|
+
*/
|
|
299
|
+
function screenshotRedactionHook(opts = {}) {
|
|
300
|
+
const warn = opts.warn ?? ((msg) => console.warn(msg));
|
|
301
|
+
const hasRegions = (opts.regions?.length ?? 0) > 0;
|
|
302
|
+
let warned = false;
|
|
303
|
+
return { async afterToolCall(ctx, result) {
|
|
304
|
+
if (ctx.toolName !== "computer-use:screenshot") return { action: "pass" };
|
|
305
|
+
if (!hasRegions) return { action: "pass" };
|
|
306
|
+
if (!readScreenshotPayload(result)) return { action: "pass" };
|
|
307
|
+
if (!warned) {
|
|
308
|
+
warned = true;
|
|
309
|
+
warn("[screenshotRedactionHook] regions configured but `sharp` is not a dependency in v1; passing screenshot through unmodified");
|
|
310
|
+
}
|
|
311
|
+
return { action: "pass" };
|
|
312
|
+
} };
|
|
313
|
+
}
|
|
314
|
+
const TYPE_TEXT_FIELDS = [
|
|
315
|
+
"text",
|
|
316
|
+
"value",
|
|
317
|
+
"input",
|
|
318
|
+
"query"
|
|
319
|
+
];
|
|
320
|
+
const CLICK_LABEL_FIELDS = [
|
|
321
|
+
"label",
|
|
322
|
+
"alt",
|
|
323
|
+
"title",
|
|
324
|
+
"ariaLabel",
|
|
325
|
+
"near"
|
|
326
|
+
];
|
|
327
|
+
function readStringField(args, fields) {
|
|
328
|
+
if (!args || typeof args !== "object") return null;
|
|
329
|
+
const a = args;
|
|
330
|
+
for (const f of fields) {
|
|
331
|
+
const v = a[f];
|
|
332
|
+
if (typeof v === "string" && v.length > 0) return v;
|
|
333
|
+
}
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Block before-execute when a `computer-use:type` text or
|
|
338
|
+
* `computer-use:click` label matches any deny pattern. Mitigates
|
|
339
|
+
* destructive-action sequences (e.g. "delete account", "wire transfer")
|
|
340
|
+
* before they hit the OS.
|
|
341
|
+
*/
|
|
342
|
+
function destructiveActionGuardHook(opts) {
|
|
343
|
+
const patterns = opts.denyPatterns;
|
|
344
|
+
return { async beforeToolCall(ctx) {
|
|
345
|
+
let candidate = null;
|
|
346
|
+
if (ctx.toolName === "computer-use:type") candidate = readStringField(ctx.args, TYPE_TEXT_FIELDS);
|
|
347
|
+
else if (ctx.toolName === "computer-use:click") candidate = readStringField(ctx.args, CLICK_LABEL_FIELDS);
|
|
348
|
+
else return { action: "allow" };
|
|
349
|
+
if (!candidate) return { action: "allow" };
|
|
350
|
+
for (const re of patterns) if (re.test(candidate)) return {
|
|
351
|
+
action: "block",
|
|
352
|
+
reason: `destructive action denied: input matches ${re.toString()}`
|
|
353
|
+
};
|
|
354
|
+
return { action: "allow" };
|
|
355
|
+
} };
|
|
356
|
+
}
|
|
357
|
+
//#endregion
|
|
358
|
+
//#region src/openai/responses-store.ts
|
|
359
|
+
var InMemoryResponseStore = class {
|
|
360
|
+
chains = /* @__PURE__ */ new Map();
|
|
361
|
+
async getPriorTurns(responseId) {
|
|
362
|
+
const turns = this.chains.get(responseId);
|
|
363
|
+
return turns ? turns.map((t) => ({ ...t })) : null;
|
|
364
|
+
}
|
|
365
|
+
async putPriorTurns(responseId, priorTurns) {
|
|
366
|
+
this.chains.set(responseId, priorTurns.map((t) => ({ ...t })));
|
|
367
|
+
}
|
|
368
|
+
/** Convenience accessor for tests / debug; not part of `ResponseStore`. */
|
|
369
|
+
size() {
|
|
370
|
+
return this.chains.size;
|
|
371
|
+
}
|
|
372
|
+
/** Drop a chain. */
|
|
373
|
+
delete(responseId) {
|
|
374
|
+
return this.chains.delete(responseId);
|
|
375
|
+
}
|
|
376
|
+
/** Drop everything. Useful between test cases. */
|
|
377
|
+
clear() {
|
|
378
|
+
this.chains.clear();
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
//#endregion
|
|
382
|
+
//#region src/openai/runs.ts
|
|
383
|
+
const TERMINAL_STATUSES = new Set([
|
|
384
|
+
"completed",
|
|
385
|
+
"failed",
|
|
386
|
+
"cancelled",
|
|
387
|
+
"expired"
|
|
388
|
+
]);
|
|
389
|
+
function isTerminal(status) {
|
|
390
|
+
return TERMINAL_STATUSES.has(status);
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Pure async iterator over the underlying source. No state, no
|
|
394
|
+
* buffering. Iteration ends when the source closes or yields a
|
|
395
|
+
* terminal frame; the iterator itself does not classify frames.
|
|
396
|
+
*/
|
|
397
|
+
async function* runEvents(threadId, runId, source) {
|
|
398
|
+
for await (const event of source.open(threadId, runId)) yield event;
|
|
399
|
+
}
|
|
400
|
+
function readToolCallFromFrame(event) {
|
|
401
|
+
if (event.type === "requires_action" || event.type === "tool_call_requested") {
|
|
402
|
+
const data = event.data ?? event;
|
|
403
|
+
const id = String(data.callId ?? data.call_id ?? data.id ?? "");
|
|
404
|
+
const name = String(data.toolName ?? data.tool_name ?? data.name ?? "");
|
|
405
|
+
if (!id || !name) return null;
|
|
406
|
+
return {
|
|
407
|
+
callId: id,
|
|
408
|
+
toolName: name,
|
|
409
|
+
args: data.args ?? data.arguments ?? data.input ?? {},
|
|
410
|
+
requiresAction: true
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
if (event.type !== "raw") return null;
|
|
414
|
+
const data = event.data ?? event;
|
|
415
|
+
const inner = typeof data.type === "string" ? data.type : "";
|
|
416
|
+
if (!(inner === "tool-invocation" || inner === "tool_call" || inner === "computer-use" || inner === "computer_call")) return null;
|
|
417
|
+
const ti = data.toolInvocation ?? data.tool_invocation ?? data.computerUse ?? data.computer_use ?? data;
|
|
418
|
+
const id = String(ti.toolCallId ?? ti.tool_call_id ?? ti.callId ?? ti.id ?? "");
|
|
419
|
+
const name = inner === "computer-use" || inner === "computer_call" ? `computer-use:${String(ti.action?.type ?? "action")}` : String(ti.toolName ?? ti.tool_name ?? ti.name ?? "");
|
|
420
|
+
if (!id || !name) return null;
|
|
421
|
+
return {
|
|
422
|
+
callId: id,
|
|
423
|
+
toolName: name,
|
|
424
|
+
args: ti.args ?? ti.arguments ?? ti.input ?? {},
|
|
425
|
+
requiresAction: false
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
function readTerminal(event) {
|
|
429
|
+
if (event.type === "done") {
|
|
430
|
+
const outcome = typeof event.outcome === "string" && event.outcome || "success";
|
|
431
|
+
if (outcome === "success" || outcome === "completed" || outcome === "succeeded" || outcome === "done") return { status: "completed" };
|
|
432
|
+
return {
|
|
433
|
+
status: "failed",
|
|
434
|
+
reason: typeof event.error === "string" ? event.error : outcome
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
if (event.type === "error") return {
|
|
438
|
+
status: "failed",
|
|
439
|
+
reason: typeof event.message === "string" && event.message || typeof event.error === "string" && event.error || "stream error"
|
|
440
|
+
};
|
|
441
|
+
return null;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Internal queue helper: an async iterable backed by a bounded
|
|
445
|
+
* pending-list with a settle promise that resolves whenever a new
|
|
446
|
+
* event lands or the queue closes.
|
|
447
|
+
*
|
|
448
|
+
* Each iterator returned by `iterator()` shares the queue's buffer
|
|
449
|
+
* and waiter list. Two concurrent iterators would therefore steal
|
|
450
|
+
* events from each other (whichever called `next()` first wins),
|
|
451
|
+
* which silently drops events for the second consumer. Because there
|
|
452
|
+
* is only ever one consumer of `Run.events()` by design, this class
|
|
453
|
+
* enforces single-consumption explicitly: a second `iterator()` call
|
|
454
|
+
* throws so the contract violation is loud rather than silent.
|
|
455
|
+
*/
|
|
456
|
+
var EventQueue = class {
|
|
457
|
+
buffer = [];
|
|
458
|
+
waiters = [];
|
|
459
|
+
closed = false;
|
|
460
|
+
iteratorCreated = false;
|
|
461
|
+
push(value) {
|
|
462
|
+
if (this.closed) return;
|
|
463
|
+
const w = this.waiters.shift();
|
|
464
|
+
if (w) {
|
|
465
|
+
w({
|
|
466
|
+
value,
|
|
467
|
+
done: false
|
|
468
|
+
});
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
this.buffer.push(value);
|
|
472
|
+
}
|
|
473
|
+
close() {
|
|
474
|
+
if (this.closed) return;
|
|
475
|
+
this.closed = true;
|
|
476
|
+
while (this.waiters.length > 0) this.waiters.shift()?.({
|
|
477
|
+
value: void 0,
|
|
478
|
+
done: true
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
iterator() {
|
|
482
|
+
if (this.iteratorCreated) throw new Error("Run.events() may only be consumed once. Multiple iterators on the same Run share state and would interleave/steal events.");
|
|
483
|
+
this.iteratorCreated = true;
|
|
484
|
+
const self = this;
|
|
485
|
+
return {
|
|
486
|
+
[Symbol.asyncIterator]() {
|
|
487
|
+
return this;
|
|
488
|
+
},
|
|
489
|
+
next() {
|
|
490
|
+
if (self.buffer.length > 0) {
|
|
491
|
+
const value = self.buffer.shift();
|
|
492
|
+
return Promise.resolve({
|
|
493
|
+
value,
|
|
494
|
+
done: false
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
if (self.closed) return Promise.resolve({
|
|
498
|
+
value: void 0,
|
|
499
|
+
done: true
|
|
500
|
+
});
|
|
501
|
+
return new Promise((resolve) => {
|
|
502
|
+
self.waiters.push(resolve);
|
|
503
|
+
});
|
|
504
|
+
},
|
|
505
|
+
return() {
|
|
506
|
+
self.close();
|
|
507
|
+
return Promise.resolve({
|
|
508
|
+
value: void 0,
|
|
509
|
+
done: true
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
/**
|
|
516
|
+
* High-level `Run`. Drives the underlying `RunEventSource`, manages
|
|
517
|
+
* status transitions, dispatches tool calls through the hook chain,
|
|
518
|
+
* and surfaces a typed `RunEvent` stream to consumers.
|
|
519
|
+
*/
|
|
520
|
+
var Run = class {
|
|
521
|
+
id;
|
|
522
|
+
threadId;
|
|
523
|
+
partnerId;
|
|
524
|
+
_status = "queued";
|
|
525
|
+
source;
|
|
526
|
+
hooks;
|
|
527
|
+
executeTool;
|
|
528
|
+
onStatusChange;
|
|
529
|
+
queue = new EventQueue();
|
|
530
|
+
startPromise = null;
|
|
531
|
+
pendingCalls = /* @__PURE__ */ new Map();
|
|
532
|
+
cancelRequested = false;
|
|
533
|
+
constructor(opts) {
|
|
534
|
+
this.id = opts.id;
|
|
535
|
+
this.threadId = opts.threadId;
|
|
536
|
+
this.partnerId = opts.partnerId;
|
|
537
|
+
this.source = opts.source;
|
|
538
|
+
this.hooks = opts.hooks;
|
|
539
|
+
this.executeTool = opts.executeTool;
|
|
540
|
+
this.onStatusChange = opts.onStatusChange;
|
|
541
|
+
}
|
|
542
|
+
get status() {
|
|
543
|
+
return this._status;
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Subscribe to typed events. May only be consumed once per Run.
|
|
547
|
+
*
|
|
548
|
+
* The single-consumer constraint is permanent for the lifetime of
|
|
549
|
+
* the Run instance, including AFTER the run completes — calling
|
|
550
|
+
* `events()` a second time always throws, even if the first
|
|
551
|
+
* consumer drained the iterator to completion. This is intentional:
|
|
552
|
+
* the queue is a one-shot stream, not a re-readable buffer, and
|
|
553
|
+
* events are dropped after delivery to avoid unbounded retention.
|
|
554
|
+
* Callers that need to revisit terminal state should keep a handle
|
|
555
|
+
* to the original iterator's drained values, or use the Run's
|
|
556
|
+
* status/result accessors.
|
|
557
|
+
*/
|
|
558
|
+
events() {
|
|
559
|
+
return this.queue.iterator();
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Drive the underlying stream to completion. Idempotent: subsequent
|
|
563
|
+
* calls return the same in-flight promise.
|
|
564
|
+
*/
|
|
565
|
+
start() {
|
|
566
|
+
if (this.startPromise) return this.startPromise;
|
|
567
|
+
this.startPromise = this.driveStream();
|
|
568
|
+
return this.startPromise;
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Cancel an in-flight run. Sets status to `cancelled` and closes
|
|
572
|
+
* the event queue. Tries the source-level cancel hint as a
|
|
573
|
+
* best-effort heads-up to the upstream stream.
|
|
574
|
+
*/
|
|
575
|
+
async cancel(reason) {
|
|
576
|
+
if (isTerminal(this._status)) return;
|
|
577
|
+
this.cancelRequested = true;
|
|
578
|
+
if (this.source.cancel) try {
|
|
579
|
+
await this.source.cancel(this.threadId, this.id);
|
|
580
|
+
} catch {}
|
|
581
|
+
this.transition("cancelled");
|
|
582
|
+
this.queue.push({
|
|
583
|
+
type: "cancelled",
|
|
584
|
+
reason
|
|
585
|
+
});
|
|
586
|
+
this.queue.close();
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Append a user message to the thread and restart the stream. The
|
|
590
|
+
* source's `steer` hook is invoked when present; otherwise we throw
|
|
591
|
+
* because a stateless source cannot honor a steer.
|
|
592
|
+
*/
|
|
593
|
+
async steer(message) {
|
|
594
|
+
if (!this.source.steer) throw new Error("RunEventSource does not support steer");
|
|
595
|
+
if (isTerminal(this._status)) throw new Error(`cannot steer a ${this._status} run`);
|
|
596
|
+
await this.source.steer(this.threadId, this.id, message);
|
|
597
|
+
if (this._status === "requires_action") this.transition("in_progress");
|
|
598
|
+
this.startPromise = this.driveStream();
|
|
599
|
+
await this.startPromise;
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Resume a `requires_action` run by submitting tool outputs. The
|
|
603
|
+
* outputs are forwarded to the source so the upstream agent can
|
|
604
|
+
* continue. Status transitions back to `in_progress`.
|
|
605
|
+
*/
|
|
606
|
+
async submitToolOutputs(outputs) {
|
|
607
|
+
if (this._status !== "requires_action") throw new Error(`cannot submit tool outputs in status ${this._status}`);
|
|
608
|
+
if (!this.source.submitToolOutputs) throw new Error("RunEventSource does not support submitToolOutputs");
|
|
609
|
+
for (const o of outputs) this.pendingCalls.delete(o.toolCallId);
|
|
610
|
+
await this.source.submitToolOutputs(this.threadId, this.id, outputs);
|
|
611
|
+
this.transition("in_progress");
|
|
612
|
+
this.startPromise = this.driveStream();
|
|
613
|
+
await this.startPromise;
|
|
614
|
+
}
|
|
615
|
+
/** Externally drive the run into the `expired` terminal status. */
|
|
616
|
+
expire() {
|
|
617
|
+
if (isTerminal(this._status)) return;
|
|
618
|
+
this.transition("expired");
|
|
619
|
+
this.queue.push({
|
|
620
|
+
type: "failed",
|
|
621
|
+
reason: "expired"
|
|
622
|
+
});
|
|
623
|
+
this.queue.close();
|
|
624
|
+
}
|
|
625
|
+
transition(next) {
|
|
626
|
+
if (this._status === next) return;
|
|
627
|
+
const prev = this._status;
|
|
628
|
+
this._status = next;
|
|
629
|
+
this.queue.push({
|
|
630
|
+
type: "status",
|
|
631
|
+
status: next,
|
|
632
|
+
previous: prev
|
|
633
|
+
});
|
|
634
|
+
this.onStatusChange?.(next, prev);
|
|
635
|
+
}
|
|
636
|
+
async driveStream() {
|
|
637
|
+
try {
|
|
638
|
+
for await (const event of runEvents(this.threadId, this.id, this.source)) {
|
|
639
|
+
if (this.cancelRequested) return;
|
|
640
|
+
if (this._status === "queued") this.transition("in_progress");
|
|
641
|
+
this.queue.push({
|
|
642
|
+
type: "stream",
|
|
643
|
+
event
|
|
644
|
+
});
|
|
645
|
+
const tool = readToolCallFromFrame(event);
|
|
646
|
+
if (tool) {
|
|
647
|
+
const handled = await this.handleToolCall(tool);
|
|
648
|
+
if (handled === "terminate") return;
|
|
649
|
+
if (handled === "requires_action") return;
|
|
650
|
+
continue;
|
|
651
|
+
}
|
|
652
|
+
const terminal = readTerminal(event);
|
|
653
|
+
if (terminal) {
|
|
654
|
+
if (terminal.status === "completed") {
|
|
655
|
+
this.transition("completed");
|
|
656
|
+
this.queue.push({ type: "completed" });
|
|
657
|
+
} else {
|
|
658
|
+
this.transition("failed");
|
|
659
|
+
this.queue.push({
|
|
660
|
+
type: "failed",
|
|
661
|
+
reason: terminal.reason ?? "unknown failure"
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
this.queue.close();
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
if (!isTerminal(this._status)) {
|
|
669
|
+
this.transition("completed");
|
|
670
|
+
this.queue.push({ type: "completed" });
|
|
671
|
+
this.queue.close();
|
|
672
|
+
}
|
|
673
|
+
} catch (err) {
|
|
674
|
+
if (isTerminal(this._status)) return;
|
|
675
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
676
|
+
this.transition("failed");
|
|
677
|
+
this.queue.push({
|
|
678
|
+
type: "failed",
|
|
679
|
+
reason
|
|
680
|
+
});
|
|
681
|
+
this.queue.close();
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
async handleToolCall(tool) {
|
|
685
|
+
const ctx = {
|
|
686
|
+
runId: this.id,
|
|
687
|
+
threadId: this.threadId,
|
|
688
|
+
partnerId: this.partnerId,
|
|
689
|
+
toolName: tool.toolName,
|
|
690
|
+
args: tool.args,
|
|
691
|
+
callId: tool.callId,
|
|
692
|
+
timestamp: Date.now()
|
|
693
|
+
};
|
|
694
|
+
let dispatchCtx = ctx;
|
|
695
|
+
if (this.hooks && this.hooks.size > 0) {
|
|
696
|
+
const before = await this.hooks.runBefore(ctx);
|
|
697
|
+
if (before.action === "block") {
|
|
698
|
+
const blockedResult = {
|
|
699
|
+
content: { error: before.reason },
|
|
700
|
+
isError: true,
|
|
701
|
+
details: { blockedBy: "beforeToolCall" }
|
|
702
|
+
};
|
|
703
|
+
this.queue.push({
|
|
704
|
+
type: "tool_blocked",
|
|
705
|
+
ctx,
|
|
706
|
+
reason: before.reason
|
|
707
|
+
});
|
|
708
|
+
this.queue.push({
|
|
709
|
+
type: "tool_result",
|
|
710
|
+
ctx,
|
|
711
|
+
result: blockedResult
|
|
712
|
+
});
|
|
713
|
+
if (tool.requiresAction) {
|
|
714
|
+
this.pendingCalls.set(tool.callId, ctx);
|
|
715
|
+
this.transition("requires_action");
|
|
716
|
+
this.queue.push({
|
|
717
|
+
type: "requires_action",
|
|
718
|
+
pendingCallIds: Array.from(this.pendingCalls.keys())
|
|
719
|
+
});
|
|
720
|
+
return "requires_action";
|
|
721
|
+
}
|
|
722
|
+
return "continue";
|
|
723
|
+
}
|
|
724
|
+
if (before.action === "rewrite") dispatchCtx = {
|
|
725
|
+
...ctx,
|
|
726
|
+
args: before.args
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
if (tool.requiresAction) {
|
|
730
|
+
this.pendingCalls.set(tool.callId, dispatchCtx);
|
|
731
|
+
this.transition("requires_action");
|
|
732
|
+
this.queue.push({
|
|
733
|
+
type: "tool_call",
|
|
734
|
+
ctx: dispatchCtx
|
|
735
|
+
});
|
|
736
|
+
this.queue.push({
|
|
737
|
+
type: "requires_action",
|
|
738
|
+
pendingCallIds: Array.from(this.pendingCalls.keys())
|
|
739
|
+
});
|
|
740
|
+
return "requires_action";
|
|
741
|
+
}
|
|
742
|
+
if (!this.executeTool) {
|
|
743
|
+
this.queue.push({
|
|
744
|
+
type: "tool_call",
|
|
745
|
+
ctx: dispatchCtx
|
|
746
|
+
});
|
|
747
|
+
return "continue";
|
|
748
|
+
}
|
|
749
|
+
this.queue.push({
|
|
750
|
+
type: "tool_call",
|
|
751
|
+
ctx: dispatchCtx
|
|
752
|
+
});
|
|
753
|
+
let result;
|
|
754
|
+
try {
|
|
755
|
+
result = await this.executeTool(dispatchCtx);
|
|
756
|
+
} catch (err) {
|
|
757
|
+
result = {
|
|
758
|
+
content: { error: err instanceof Error ? err.message : String(err) },
|
|
759
|
+
isError: true
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
let finalResult = result;
|
|
763
|
+
if (this.hooks && this.hooks.size > 0) {
|
|
764
|
+
const after = await this.hooks.runAfter(dispatchCtx, result);
|
|
765
|
+
if (after.action === "terminate") {
|
|
766
|
+
this.queue.push({
|
|
767
|
+
type: "tool_result",
|
|
768
|
+
ctx: dispatchCtx,
|
|
769
|
+
result
|
|
770
|
+
});
|
|
771
|
+
this.transition("failed");
|
|
772
|
+
this.queue.push({
|
|
773
|
+
type: "failed",
|
|
774
|
+
reason: after.reason
|
|
775
|
+
});
|
|
776
|
+
this.queue.close();
|
|
777
|
+
return "terminate";
|
|
778
|
+
}
|
|
779
|
+
if (after.action === "override") finalResult = after.result;
|
|
780
|
+
}
|
|
781
|
+
this.queue.push({
|
|
782
|
+
type: "tool_result",
|
|
783
|
+
ctx: dispatchCtx,
|
|
784
|
+
result: finalResult
|
|
785
|
+
});
|
|
786
|
+
return "continue";
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
//#endregion
|
|
790
|
+
//#region src/openai/translate/finish-reason.ts
|
|
791
|
+
function outcomeToFinishReason(outcome, hasToolCall) {
|
|
792
|
+
switch (outcome) {
|
|
793
|
+
case "success":
|
|
794
|
+
case "succeeded":
|
|
795
|
+
case "completed":
|
|
796
|
+
case "done": return hasToolCall ? "tool_calls" : "stop";
|
|
797
|
+
case "length_exceeded":
|
|
798
|
+
case "length":
|
|
799
|
+
case "max_tokens": return "length";
|
|
800
|
+
case "content_filtered":
|
|
801
|
+
case "content_filter":
|
|
802
|
+
case "filtered": return "content_filter";
|
|
803
|
+
default: return "stop";
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
//#endregion
|
|
807
|
+
//#region src/openai/translate/chunks.ts
|
|
808
|
+
/**
|
|
809
|
+
* Read the text token from a `token` event. Tangle emits the delta as
|
|
810
|
+
* either `delta`, `text`, or `token`; tolerate all three so the
|
|
811
|
+
* translator stays decoupled from minor runtime variations.
|
|
812
|
+
*/
|
|
813
|
+
function readTokenDelta(event) {
|
|
814
|
+
if (typeof event.delta === "string") return event.delta;
|
|
815
|
+
if (typeof event.text === "string") return event.text;
|
|
816
|
+
if (typeof event.token === "string") return event.token;
|
|
817
|
+
return null;
|
|
818
|
+
}
|
|
819
|
+
function readToolInvocation(event) {
|
|
820
|
+
if (event.type !== "raw") return null;
|
|
821
|
+
const data = event.data ?? event;
|
|
822
|
+
const inner = typeof data.type === "string" ? data.type : typeof event.type === "string" ? event.type : "";
|
|
823
|
+
if (!(inner === "tool-invocation" || inner === "tool_call" || typeof data.toolInvocation === "object" || typeof data.tool_invocation === "object")) return null;
|
|
824
|
+
const ti = data.toolInvocation ?? data.tool_invocation ?? data;
|
|
825
|
+
const id = typeof ti.toolCallId === "string" ? ti.toolCallId : typeof ti.tool_call_id === "string" ? ti.tool_call_id : typeof ti.id === "string" ? ti.id : typeof ti.callId === "string" ? ti.callId : "";
|
|
826
|
+
const name = typeof ti.toolName === "string" ? ti.toolName : typeof ti.tool_name === "string" ? ti.tool_name : typeof ti.name === "string" ? ti.name : "";
|
|
827
|
+
const args = ti.args ?? ti.arguments ?? ti.input ?? {};
|
|
828
|
+
if (!id || !name) return null;
|
|
829
|
+
return {
|
|
830
|
+
id,
|
|
831
|
+
name,
|
|
832
|
+
arguments: typeof args === "string" ? args : JSON.stringify(args)
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Read a usage payload from a `done` event. The runtime emits usage
|
|
837
|
+
* either at the top level or under a `usage` key; try both.
|
|
838
|
+
*/
|
|
839
|
+
function readUsage(event) {
|
|
840
|
+
const u = event.usage ?? event;
|
|
841
|
+
const prompt = Number(u.prompt_tokens ?? u.input_tokens ?? u.inputTokens ?? 0);
|
|
842
|
+
const completion = Number(u.completion_tokens ?? u.output_tokens ?? u.outputTokens ?? 0);
|
|
843
|
+
if (prompt === 0 && completion === 0) return null;
|
|
844
|
+
return {
|
|
845
|
+
prompt_tokens: prompt,
|
|
846
|
+
completion_tokens: completion,
|
|
847
|
+
total_tokens: Number(u.total_tokens ?? prompt + completion)
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
function readOutcome(event) {
|
|
851
|
+
if (typeof event.outcome === "string") return event.outcome;
|
|
852
|
+
if (typeof event.status === "string") return event.status;
|
|
853
|
+
if (event.success === false) return "failure";
|
|
854
|
+
return "success";
|
|
855
|
+
}
|
|
856
|
+
function chatBaseChunk(ctx) {
|
|
857
|
+
ctx.chunkIndex += 1;
|
|
858
|
+
return {
|
|
859
|
+
id: ctx.runId,
|
|
860
|
+
created: ctx.createdAt,
|
|
861
|
+
model: ctx.modelId,
|
|
862
|
+
object: "chat.completion.chunk"
|
|
863
|
+
};
|
|
864
|
+
}
|
|
865
|
+
function sandboxEventToChatChunk(event, ctx) {
|
|
866
|
+
switch (event.type) {
|
|
867
|
+
case "start": return null;
|
|
868
|
+
case "execution.started": return null;
|
|
869
|
+
case "status": return null;
|
|
870
|
+
case "session.updated": return null;
|
|
871
|
+
case "message.part.updated": return null;
|
|
872
|
+
case "token": {
|
|
873
|
+
const delta = readTokenDelta(event);
|
|
874
|
+
if (delta == null || delta.length === 0) return null;
|
|
875
|
+
return {
|
|
876
|
+
...chatBaseChunk(ctx),
|
|
877
|
+
choices: [{
|
|
878
|
+
index: 0,
|
|
879
|
+
delta: {
|
|
880
|
+
role: "assistant",
|
|
881
|
+
content: delta
|
|
882
|
+
},
|
|
883
|
+
finish_reason: null
|
|
884
|
+
}]
|
|
885
|
+
};
|
|
886
|
+
}
|
|
887
|
+
case "raw": {
|
|
888
|
+
const tool = readToolInvocation(event);
|
|
889
|
+
if (!tool) return null;
|
|
890
|
+
const existing = ctx.toolCallBuffer.get(tool.id);
|
|
891
|
+
const index = existing ? existing.index : ctx.toolCallBuffer.size;
|
|
892
|
+
ctx.toolCallBuffer.set(tool.id, {
|
|
893
|
+
index,
|
|
894
|
+
id: tool.id,
|
|
895
|
+
name: tool.name,
|
|
896
|
+
arguments: tool.arguments
|
|
897
|
+
});
|
|
898
|
+
return {
|
|
899
|
+
...chatBaseChunk(ctx),
|
|
900
|
+
choices: [{
|
|
901
|
+
index: 0,
|
|
902
|
+
delta: {
|
|
903
|
+
role: "assistant",
|
|
904
|
+
tool_calls: [{
|
|
905
|
+
index,
|
|
906
|
+
id: tool.id,
|
|
907
|
+
type: "function",
|
|
908
|
+
function: {
|
|
909
|
+
name: tool.name,
|
|
910
|
+
arguments: tool.arguments
|
|
911
|
+
}
|
|
912
|
+
}]
|
|
913
|
+
},
|
|
914
|
+
finish_reason: null
|
|
915
|
+
}]
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
case "error": {
|
|
919
|
+
const hasToolCall = ctx.toolCallBuffer.size > 0;
|
|
920
|
+
return {
|
|
921
|
+
...chatBaseChunk(ctx),
|
|
922
|
+
choices: [{
|
|
923
|
+
index: 0,
|
|
924
|
+
delta: {},
|
|
925
|
+
finish_reason: outcomeToFinishReason("error", hasToolCall)
|
|
926
|
+
}]
|
|
927
|
+
};
|
|
928
|
+
}
|
|
929
|
+
case "done": {
|
|
930
|
+
const hasToolCall = ctx.toolCallBuffer.size > 0;
|
|
931
|
+
const finish = outcomeToFinishReason(readOutcome(event), hasToolCall);
|
|
932
|
+
const usage = readUsage(event);
|
|
933
|
+
const chunk = {
|
|
934
|
+
...chatBaseChunk(ctx),
|
|
935
|
+
choices: [{
|
|
936
|
+
index: 0,
|
|
937
|
+
delta: {},
|
|
938
|
+
finish_reason: finish
|
|
939
|
+
}]
|
|
940
|
+
};
|
|
941
|
+
if (usage) chunk.usage = usage;
|
|
942
|
+
return chunk;
|
|
943
|
+
}
|
|
944
|
+
default: return null;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
function completionBaseChunk(ctx) {
|
|
948
|
+
ctx.chunkIndex += 1;
|
|
949
|
+
return {
|
|
950
|
+
id: ctx.runId,
|
|
951
|
+
created: ctx.createdAt,
|
|
952
|
+
model: ctx.modelId,
|
|
953
|
+
object: "text_completion"
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
function sandboxEventToCompletionChunk(event, ctx) {
|
|
957
|
+
switch (event.type) {
|
|
958
|
+
case "start":
|
|
959
|
+
case "execution.started":
|
|
960
|
+
case "status":
|
|
961
|
+
case "session.updated":
|
|
962
|
+
case "message.part.updated":
|
|
963
|
+
case "raw":
|
|
964
|
+
if (event.type === "raw") {
|
|
965
|
+
const tool = readToolInvocation(event);
|
|
966
|
+
if (tool) {
|
|
967
|
+
const existing = ctx.toolCallBuffer.get(tool.id);
|
|
968
|
+
const index = existing ? existing.index : ctx.toolCallBuffer.size;
|
|
969
|
+
ctx.toolCallBuffer.set(tool.id, {
|
|
970
|
+
index,
|
|
971
|
+
id: tool.id,
|
|
972
|
+
name: tool.name,
|
|
973
|
+
arguments: tool.arguments
|
|
974
|
+
});
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
return null;
|
|
978
|
+
case "token": {
|
|
979
|
+
const delta = readTokenDelta(event);
|
|
980
|
+
if (delta == null || delta.length === 0) return null;
|
|
981
|
+
return {
|
|
982
|
+
...completionBaseChunk(ctx),
|
|
983
|
+
choices: [{
|
|
984
|
+
index: 0,
|
|
985
|
+
text: delta,
|
|
986
|
+
finish_reason: null,
|
|
987
|
+
logprobs: null
|
|
988
|
+
}]
|
|
989
|
+
};
|
|
990
|
+
}
|
|
991
|
+
case "error":
|
|
992
|
+
case "done": {
|
|
993
|
+
const finish = outcomeToFinishReason(event.type === "error" ? "error" : readOutcome(event), false);
|
|
994
|
+
const reason = finish === "tool_calls" ? "stop" : finish;
|
|
995
|
+
const usage = readUsage(event);
|
|
996
|
+
const chunk = {
|
|
997
|
+
...completionBaseChunk(ctx),
|
|
998
|
+
choices: [{
|
|
999
|
+
index: 0,
|
|
1000
|
+
text: "",
|
|
1001
|
+
finish_reason: reason,
|
|
1002
|
+
logprobs: null
|
|
1003
|
+
}]
|
|
1004
|
+
};
|
|
1005
|
+
if (usage) chunk.usage = usage;
|
|
1006
|
+
return chunk;
|
|
1007
|
+
}
|
|
1008
|
+
default: return null;
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
function getResponsesExtras(ctx) {
|
|
1012
|
+
const slot = ctx;
|
|
1013
|
+
if (!slot.__responsesExtras) slot.__responsesExtras = {
|
|
1014
|
+
sequence: 0,
|
|
1015
|
+
toolOutputIndex: /* @__PURE__ */ new Map()
|
|
1016
|
+
};
|
|
1017
|
+
return slot.__responsesExtras;
|
|
1018
|
+
}
|
|
1019
|
+
function nextSeq(extras) {
|
|
1020
|
+
extras.sequence += 1;
|
|
1021
|
+
return extras.sequence;
|
|
1022
|
+
}
|
|
1023
|
+
function emptyResponseUsage() {
|
|
1024
|
+
return {
|
|
1025
|
+
input_tokens: 0,
|
|
1026
|
+
output_tokens: 0,
|
|
1027
|
+
total_tokens: 0,
|
|
1028
|
+
input_tokens_details: { cached_tokens: 0 },
|
|
1029
|
+
output_tokens_details: { reasoning_tokens: 0 }
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
function usageFromTokens(usage) {
|
|
1033
|
+
return {
|
|
1034
|
+
input_tokens: usage.prompt_tokens,
|
|
1035
|
+
output_tokens: usage.completion_tokens,
|
|
1036
|
+
total_tokens: usage.total_tokens,
|
|
1037
|
+
input_tokens_details: { cached_tokens: 0 },
|
|
1038
|
+
output_tokens_details: { reasoning_tokens: 0 }
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
function sandboxEventToResponsesEvent(event, ctx) {
|
|
1042
|
+
const extras = getResponsesExtras(ctx);
|
|
1043
|
+
switch (event.type) {
|
|
1044
|
+
case "start": return null;
|
|
1045
|
+
case "execution.started": return null;
|
|
1046
|
+
case "status": return null;
|
|
1047
|
+
case "session.updated": return null;
|
|
1048
|
+
case "message.part.updated": return null;
|
|
1049
|
+
case "token": {
|
|
1050
|
+
const delta = readTokenDelta(event);
|
|
1051
|
+
if (delta == null || delta.length === 0) return null;
|
|
1052
|
+
ctx.chunkIndex += 1;
|
|
1053
|
+
if (extras.messageOutputIndex === void 0) extras.messageOutputIndex = ctx.toolCallBuffer.size;
|
|
1054
|
+
return {
|
|
1055
|
+
type: "response.output_text.delta",
|
|
1056
|
+
content_index: 0,
|
|
1057
|
+
delta,
|
|
1058
|
+
item_id: `msg_${ctx.runId}`,
|
|
1059
|
+
logprobs: [],
|
|
1060
|
+
output_index: extras.messageOutputIndex,
|
|
1061
|
+
sequence_number: nextSeq(extras)
|
|
1062
|
+
};
|
|
1063
|
+
}
|
|
1064
|
+
case "raw": {
|
|
1065
|
+
const tool = readToolInvocation(event);
|
|
1066
|
+
if (!tool) return null;
|
|
1067
|
+
ctx.chunkIndex += 1;
|
|
1068
|
+
const existing = ctx.toolCallBuffer.get(tool.id);
|
|
1069
|
+
const index = existing ? existing.index : ctx.toolCallBuffer.size;
|
|
1070
|
+
ctx.toolCallBuffer.set(tool.id, {
|
|
1071
|
+
index,
|
|
1072
|
+
id: tool.id,
|
|
1073
|
+
name: tool.name,
|
|
1074
|
+
arguments: tool.arguments
|
|
1075
|
+
});
|
|
1076
|
+
const outputIndex = extras.toolOutputIndex.get(tool.id) ?? extras.toolOutputIndex.size;
|
|
1077
|
+
extras.toolOutputIndex.set(tool.id, outputIndex);
|
|
1078
|
+
return {
|
|
1079
|
+
type: "response.output_item.added",
|
|
1080
|
+
item: {
|
|
1081
|
+
type: "function_call",
|
|
1082
|
+
id: `fc_${tool.id}`,
|
|
1083
|
+
call_id: tool.id,
|
|
1084
|
+
name: tool.name,
|
|
1085
|
+
arguments: tool.arguments,
|
|
1086
|
+
status: "completed"
|
|
1087
|
+
},
|
|
1088
|
+
output_index: outputIndex,
|
|
1089
|
+
sequence_number: nextSeq(extras)
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
case "error": {
|
|
1093
|
+
const outputIndex = extras.messageOutputIndex ?? 0;
|
|
1094
|
+
return {
|
|
1095
|
+
type: "response.output_item.done",
|
|
1096
|
+
item: {
|
|
1097
|
+
type: "message",
|
|
1098
|
+
id: `msg_${ctx.runId}`,
|
|
1099
|
+
role: "assistant",
|
|
1100
|
+
status: "incomplete",
|
|
1101
|
+
content: []
|
|
1102
|
+
},
|
|
1103
|
+
output_index: outputIndex,
|
|
1104
|
+
sequence_number: nextSeq(extras)
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
case "done": {
|
|
1108
|
+
const tokens = readUsage(event);
|
|
1109
|
+
const usage = tokens ? usageFromTokens(tokens) : emptyResponseUsage();
|
|
1110
|
+
return {
|
|
1111
|
+
type: "response.completed",
|
|
1112
|
+
sequence_number: nextSeq(extras),
|
|
1113
|
+
response: {
|
|
1114
|
+
id: ctx.runId,
|
|
1115
|
+
object: "response",
|
|
1116
|
+
created_at: ctx.createdAt,
|
|
1117
|
+
output_text: "",
|
|
1118
|
+
error: null,
|
|
1119
|
+
incomplete_details: null,
|
|
1120
|
+
instructions: null,
|
|
1121
|
+
metadata: null,
|
|
1122
|
+
model: ctx.modelId,
|
|
1123
|
+
output: [],
|
|
1124
|
+
parallel_tool_calls: false,
|
|
1125
|
+
temperature: null,
|
|
1126
|
+
tool_choice: "auto",
|
|
1127
|
+
tools: [],
|
|
1128
|
+
top_p: null,
|
|
1129
|
+
status: "completed",
|
|
1130
|
+
usage
|
|
1131
|
+
}
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
default: return null;
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
//#endregion
|
|
1138
|
+
//#region src/openai/translate/embeddings.ts
|
|
1139
|
+
/**
|
|
1140
|
+
* Error shape used for rejecting embedding requests. The route layer
|
|
1141
|
+
* lifts these into OpenAI's `{ error: { type, code, message } }` body.
|
|
1142
|
+
*/
|
|
1143
|
+
var EmbeddingValidationError = class extends Error {
|
|
1144
|
+
type = "invalid_request_error";
|
|
1145
|
+
code;
|
|
1146
|
+
param;
|
|
1147
|
+
constructor(message, code, param) {
|
|
1148
|
+
super(message);
|
|
1149
|
+
this.name = "EmbeddingValidationError";
|
|
1150
|
+
this.code = code;
|
|
1151
|
+
this.param = param;
|
|
1152
|
+
}
|
|
1153
|
+
};
|
|
1154
|
+
const MAX_BATCH = 2048;
|
|
1155
|
+
function reject(message, code, param) {
|
|
1156
|
+
throw new EmbeddingValidationError(message, code, param);
|
|
1157
|
+
}
|
|
1158
|
+
function normalizeInput(input) {
|
|
1159
|
+
if (typeof input === "string") {
|
|
1160
|
+
if (input.length === 0) reject("Input string must not be empty", "empty_input", "input");
|
|
1161
|
+
return {
|
|
1162
|
+
kind: "text",
|
|
1163
|
+
values: [input]
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
if (!Array.isArray(input)) reject("Input must be a string, array of strings, or array of token arrays", "invalid_input_type", "input");
|
|
1167
|
+
if (input.length === 0) reject("Input array must not be empty", "empty_input", "input");
|
|
1168
|
+
if (input.length > MAX_BATCH) reject(`Input array exceeds maximum batch size of ${MAX_BATCH}`, "batch_too_large", "input");
|
|
1169
|
+
const first = input[0];
|
|
1170
|
+
if (typeof first === "string") {
|
|
1171
|
+
const values = [];
|
|
1172
|
+
for (let i = 0; i < input.length; i++) {
|
|
1173
|
+
const v = input[i];
|
|
1174
|
+
if (typeof v !== "string") reject(`Input array must be homogeneous; index ${i} is not a string`, "mixed_input_types", "input");
|
|
1175
|
+
if (v.length === 0) reject(`Input string at index ${i} must not be empty`, "empty_input", "input");
|
|
1176
|
+
values.push(v);
|
|
1177
|
+
}
|
|
1178
|
+
return {
|
|
1179
|
+
kind: "text",
|
|
1180
|
+
values
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
if (typeof first === "number") {
|
|
1184
|
+
for (let i = 0; i < input.length; i++) if (typeof input[i] !== "number") reject(`Token array must contain only numbers; index ${i} is ${typeof input[i]}`, "invalid_token_type", "input");
|
|
1185
|
+
return {
|
|
1186
|
+
kind: "tokens",
|
|
1187
|
+
values: [input]
|
|
1188
|
+
};
|
|
1189
|
+
}
|
|
1190
|
+
if (Array.isArray(first)) {
|
|
1191
|
+
const values = [];
|
|
1192
|
+
for (let i = 0; i < input.length; i++) {
|
|
1193
|
+
const row = input[i];
|
|
1194
|
+
if (!Array.isArray(row)) reject(`Input array must be homogeneous; index ${i} is not an array`, "mixed_input_types", "input");
|
|
1195
|
+
if (row.length === 0) reject(`Token array at index ${i} must not be empty`, "empty_input", "input");
|
|
1196
|
+
for (let j = 0; j < row.length; j++) if (typeof row[j] !== "number") reject(`Token array at index ${i} must contain only numbers; element ${j} is ${typeof row[j]}`, "invalid_token_type", "input");
|
|
1197
|
+
values.push(row);
|
|
1198
|
+
}
|
|
1199
|
+
return {
|
|
1200
|
+
kind: "tokens",
|
|
1201
|
+
values
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
reject("Input must be a string, array of strings, or array of token arrays", "invalid_input_type", "input");
|
|
1205
|
+
}
|
|
1206
|
+
/**
|
|
1207
|
+
* Validate and normalize an embedding request. Throws
|
|
1208
|
+
* `EmbeddingValidationError` on any rejection.
|
|
1209
|
+
*/
|
|
1210
|
+
function validateEmbeddingRequest(req) {
|
|
1211
|
+
if (!req || typeof req !== "object") reject("Request body must be an object", "invalid_request", void 0);
|
|
1212
|
+
if (typeof req.model !== "string" || req.model.length === 0) reject("Model is required", "model_required", "model");
|
|
1213
|
+
if (req.dimensions !== void 0) {
|
|
1214
|
+
if (typeof req.dimensions !== "number" || !Number.isInteger(req.dimensions) || req.dimensions <= 0) reject("Dimensions must be a positive integer", "invalid_dimensions", "dimensions");
|
|
1215
|
+
}
|
|
1216
|
+
const encodingFormat = req.encoding_format ?? "float";
|
|
1217
|
+
if (encodingFormat !== "float" && encodingFormat !== "base64") reject("encoding_format must be 'float' or 'base64'", "invalid_encoding_format", "encoding_format");
|
|
1218
|
+
const input = normalizeInput(req.input);
|
|
1219
|
+
const out = {
|
|
1220
|
+
model: req.model,
|
|
1221
|
+
input,
|
|
1222
|
+
encodingFormat
|
|
1223
|
+
};
|
|
1224
|
+
if (req.dimensions !== void 0) out.dimensions = req.dimensions;
|
|
1225
|
+
if (req.user !== void 0) out.user = req.user;
|
|
1226
|
+
return out;
|
|
1227
|
+
}
|
|
1228
|
+
//#endregion
|
|
1229
|
+
//#region src/openai/translate/messages.ts
|
|
1230
|
+
/**
|
|
1231
|
+
* Strip the leading `tangle/` namespace from a model id and split off an
|
|
1232
|
+
* optional variant. Examples:
|
|
1233
|
+
* - `tangle/claude-code` → `{ provider: "claude-code" }`
|
|
1234
|
+
* - `tangle/opencode/sonnet` → `{ provider: "opencode", variant: "sonnet" }`
|
|
1235
|
+
* - `claude-code` → `{ provider: "claude-code" }` (no prefix)
|
|
1236
|
+
*/
|
|
1237
|
+
function resolveProviderId(model) {
|
|
1238
|
+
const trimmed = model.trim();
|
|
1239
|
+
const withoutPrefix = trimmed.startsWith("tangle/") ? trimmed.slice(7) : trimmed;
|
|
1240
|
+
if (!withoutPrefix) throw new Error(`Invalid model id: ${JSON.stringify(model)}`);
|
|
1241
|
+
const slash = withoutPrefix.indexOf("/");
|
|
1242
|
+
if (slash === -1) return { provider: withoutPrefix };
|
|
1243
|
+
const provider = withoutPrefix.slice(0, slash);
|
|
1244
|
+
const variant = withoutPrefix.slice(slash + 1);
|
|
1245
|
+
if (!provider || !variant) throw new Error(`Invalid model id: ${JSON.stringify(model)}`);
|
|
1246
|
+
return {
|
|
1247
|
+
provider,
|
|
1248
|
+
variant
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Coerce an OpenAI chat content field into a normalized text + parts pair.
|
|
1253
|
+
* Refusal parts are dropped — they only appear on assistant turns and the
|
|
1254
|
+
* sandbox runtime does not consume them; assistant text is the only field
|
|
1255
|
+
* we need from the assistant side.
|
|
1256
|
+
*/
|
|
1257
|
+
function normalizeContent(content) {
|
|
1258
|
+
if (content == null) return {
|
|
1259
|
+
text: "",
|
|
1260
|
+
parts: []
|
|
1261
|
+
};
|
|
1262
|
+
if (typeof content === "string") return {
|
|
1263
|
+
text: content,
|
|
1264
|
+
parts: []
|
|
1265
|
+
};
|
|
1266
|
+
const parts = [];
|
|
1267
|
+
const textPieces = [];
|
|
1268
|
+
for (const part of content) if (part.type === "text") {
|
|
1269
|
+
textPieces.push(part.text);
|
|
1270
|
+
parts.push({
|
|
1271
|
+
type: "text",
|
|
1272
|
+
text: part.text
|
|
1273
|
+
});
|
|
1274
|
+
} else if (part.type === "image_url") parts.push({
|
|
1275
|
+
type: "image_url",
|
|
1276
|
+
image_url: {
|
|
1277
|
+
url: part.image_url.url,
|
|
1278
|
+
detail: part.image_url.detail
|
|
1279
|
+
}
|
|
1280
|
+
});
|
|
1281
|
+
else if (part.type === "input_audio") parts.push({
|
|
1282
|
+
type: "input_audio",
|
|
1283
|
+
input_audio: {
|
|
1284
|
+
data: part.input_audio.data,
|
|
1285
|
+
format: part.input_audio.format
|
|
1286
|
+
}
|
|
1287
|
+
});
|
|
1288
|
+
return {
|
|
1289
|
+
text: textPieces.join("\n"),
|
|
1290
|
+
parts
|
|
1291
|
+
};
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* Read assistant text content. Assistant messages can carry an array of
|
|
1295
|
+
* text + refusal parts; refusal text is preserved as plain text so the
|
|
1296
|
+
* provider sees the full assistant turn.
|
|
1297
|
+
*/
|
|
1298
|
+
function readAssistantText(content) {
|
|
1299
|
+
if (content == null) return "";
|
|
1300
|
+
if (typeof content === "string") return content;
|
|
1301
|
+
const pieces = [];
|
|
1302
|
+
for (const part of content) if (part.type === "text") pieces.push(part.text);
|
|
1303
|
+
else if (part.type === "refusal") pieces.push(part.refusal);
|
|
1304
|
+
return pieces.join("\n");
|
|
1305
|
+
}
|
|
1306
|
+
/** Read tool message content (string or array of text parts). */
|
|
1307
|
+
function readToolContent(content) {
|
|
1308
|
+
if (typeof content === "string") return content;
|
|
1309
|
+
return content.map((p) => p.text).join("\n");
|
|
1310
|
+
}
|
|
1311
|
+
/**
|
|
1312
|
+
* Convert an OpenAI tool-spec array into the SDK's internal forwarding
|
|
1313
|
+
* shape. Custom (non-function) tools are dropped at this layer because
|
|
1314
|
+
* downstream providers only accept function-shaped tools; the route
|
|
1315
|
+
* layer is responsible for surfacing a 400 if the caller requested
|
|
1316
|
+
* something the provider can't run.
|
|
1317
|
+
*/
|
|
1318
|
+
function convertTools(tools) {
|
|
1319
|
+
if (!tools || tools.length === 0) return void 0;
|
|
1320
|
+
const out = [];
|
|
1321
|
+
for (const tool of tools) if (tool.type === "function") out.push({
|
|
1322
|
+
type: "function",
|
|
1323
|
+
function: {
|
|
1324
|
+
name: tool.function.name,
|
|
1325
|
+
description: tool.function.description,
|
|
1326
|
+
parameters: tool.function.parameters ?? null,
|
|
1327
|
+
strict: tool.function.strict ?? null
|
|
1328
|
+
}
|
|
1329
|
+
});
|
|
1330
|
+
return out.length > 0 ? out : void 0;
|
|
1331
|
+
}
|
|
1332
|
+
/**
|
|
1333
|
+
* Translate an OpenAI chat-shape message thread into a SandboxRunInput.
|
|
1334
|
+
*
|
|
1335
|
+
* @param messages Ordered messages as the OpenAI client would send them.
|
|
1336
|
+
* @param tools Optional function tool descriptors to forward unchanged.
|
|
1337
|
+
* @param model Caller-supplied model id (`tangle/<provider>[/<variant>]`).
|
|
1338
|
+
*
|
|
1339
|
+
* @throws when the resolved provider id is empty, when the message thread
|
|
1340
|
+
* lacks any user message, or when an `assistant` `tool_calls` item
|
|
1341
|
+
* is malformed (missing id/name/arguments).
|
|
1342
|
+
*/
|
|
1343
|
+
function openaiMessagesToSandboxInput(messages, tools, model) {
|
|
1344
|
+
const { provider, variant } = resolveProviderId(model);
|
|
1345
|
+
const instructionsPieces = [];
|
|
1346
|
+
const userPieces = [];
|
|
1347
|
+
const priorTurns = [];
|
|
1348
|
+
let pendingTurn = null;
|
|
1349
|
+
let pendingUserParts = [];
|
|
1350
|
+
let trailingUserParts = [];
|
|
1351
|
+
let multimodal = false;
|
|
1352
|
+
const flushPending = () => {
|
|
1353
|
+
if (pendingTurn) {
|
|
1354
|
+
priorTurns.push(pendingTurn);
|
|
1355
|
+
pendingTurn = null;
|
|
1356
|
+
}
|
|
1357
|
+
};
|
|
1358
|
+
let lastUserIndex = -1;
|
|
1359
|
+
for (let i = messages.length - 1; i >= 0; i--) if (messages[i].role === "user") {
|
|
1360
|
+
lastUserIndex = i;
|
|
1361
|
+
break;
|
|
1362
|
+
}
|
|
1363
|
+
if (lastUserIndex === -1) throw new Error("openaiMessagesToSandboxInput: messages must contain at least one user message");
|
|
1364
|
+
for (let i = 0; i < messages.length; i++) {
|
|
1365
|
+
const msg = messages[i];
|
|
1366
|
+
switch (msg.role) {
|
|
1367
|
+
case "system":
|
|
1368
|
+
case "developer": {
|
|
1369
|
+
const { text } = normalizeContent(msg.content);
|
|
1370
|
+
if (text) instructionsPieces.push(text);
|
|
1371
|
+
break;
|
|
1372
|
+
}
|
|
1373
|
+
case "user": {
|
|
1374
|
+
const { text, parts } = normalizeContent(msg.content);
|
|
1375
|
+
if (parts.some((p) => p.type !== "text")) multimodal = true;
|
|
1376
|
+
if (i === lastUserIndex) {
|
|
1377
|
+
userPieces.push(text);
|
|
1378
|
+
if (parts.length > 0) trailingUserParts = parts;
|
|
1379
|
+
} else {
|
|
1380
|
+
flushPending();
|
|
1381
|
+
if (parts.length > 0) {
|
|
1382
|
+
pendingTurn = { userParts: parts };
|
|
1383
|
+
pendingUserParts = parts;
|
|
1384
|
+
} else {
|
|
1385
|
+
pendingTurn = {};
|
|
1386
|
+
pendingUserParts = [];
|
|
1387
|
+
}
|
|
1388
|
+
if (text) userPieces.push(text);
|
|
1389
|
+
}
|
|
1390
|
+
break;
|
|
1391
|
+
}
|
|
1392
|
+
case "assistant": {
|
|
1393
|
+
if (!pendingTurn) pendingTurn = {};
|
|
1394
|
+
const text = readAssistantText(msg.content);
|
|
1395
|
+
if (text) pendingTurn.assistantText = text;
|
|
1396
|
+
if (msg.tool_calls && msg.tool_calls.length > 0) {
|
|
1397
|
+
const calls = [];
|
|
1398
|
+
for (const call of msg.tool_calls) {
|
|
1399
|
+
if (call.type !== "function") continue;
|
|
1400
|
+
if (!call.id || !call.function?.name || typeof call.function.arguments !== "string") throw new Error(`openaiMessagesToSandboxInput: malformed assistant tool_call at index ${i}`);
|
|
1401
|
+
calls.push({
|
|
1402
|
+
id: call.id,
|
|
1403
|
+
name: call.function.name,
|
|
1404
|
+
arguments: call.function.arguments
|
|
1405
|
+
});
|
|
1406
|
+
}
|
|
1407
|
+
if (calls.length > 0) pendingTurn.toolCalls = calls;
|
|
1408
|
+
}
|
|
1409
|
+
if (pendingUserParts.length > 0 && !pendingTurn.userParts) pendingTurn.userParts = pendingUserParts;
|
|
1410
|
+
break;
|
|
1411
|
+
}
|
|
1412
|
+
case "tool": {
|
|
1413
|
+
const result = {
|
|
1414
|
+
toolCallId: msg.tool_call_id,
|
|
1415
|
+
content: readToolContent(msg.content)
|
|
1416
|
+
};
|
|
1417
|
+
let attached = false;
|
|
1418
|
+
if (pendingTurn?.toolCalls?.some((c) => c.id === msg.tool_call_id)) {
|
|
1419
|
+
if (!pendingTurn.toolResults) pendingTurn.toolResults = [];
|
|
1420
|
+
pendingTurn.toolResults.push(result);
|
|
1421
|
+
attached = true;
|
|
1422
|
+
} else for (let j = priorTurns.length - 1; j >= 0; j--) {
|
|
1423
|
+
const turn = priorTurns[j];
|
|
1424
|
+
if (turn.toolCalls?.some((c) => c.id === msg.tool_call_id)) {
|
|
1425
|
+
if (!turn.toolResults) turn.toolResults = [];
|
|
1426
|
+
turn.toolResults.push(result);
|
|
1427
|
+
attached = true;
|
|
1428
|
+
break;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
if (!attached) throw new Error(`openaiMessagesToSandboxInput: tool message references unknown tool_call_id ${msg.tool_call_id}`);
|
|
1432
|
+
break;
|
|
1433
|
+
}
|
|
1434
|
+
case "function": break;
|
|
1435
|
+
}
|
|
1436
|
+
if (i === lastUserIndex) flushPending();
|
|
1437
|
+
}
|
|
1438
|
+
flushPending();
|
|
1439
|
+
const result = {
|
|
1440
|
+
provider,
|
|
1441
|
+
task: userPieces.join("\n\n")
|
|
1442
|
+
};
|
|
1443
|
+
if (variant) result.variant = variant;
|
|
1444
|
+
const instructions = instructionsPieces.join("\n\n");
|
|
1445
|
+
if (instructions) result.instructions = instructions;
|
|
1446
|
+
if (trailingUserParts.length > 0) result.taskParts = trailingUserParts;
|
|
1447
|
+
if (priorTurns.length > 0) result.priorTurns = priorTurns;
|
|
1448
|
+
const toolSpecs = convertTools(tools);
|
|
1449
|
+
if (toolSpecs) result.tools = toolSpecs;
|
|
1450
|
+
if (multimodal) result.multimodal = true;
|
|
1451
|
+
return result;
|
|
1452
|
+
}
|
|
1453
|
+
//#endregion
|
|
1454
|
+
//#region src/openai/translate/responses.ts
|
|
1455
|
+
/**
|
|
1456
|
+
* Resolve a `previous_response_id` into the prior-turns prefix that
|
|
1457
|
+
* gets prepended to the new request. Throws when the id is supplied but
|
|
1458
|
+
* unknown — silently dropping it would corrupt conversation continuity.
|
|
1459
|
+
*/
|
|
1460
|
+
async function resolvePreviousResponseId(prevId, store) {
|
|
1461
|
+
if (!prevId) return { priorTurns: [] };
|
|
1462
|
+
const turns = await store.getPriorTurns(prevId);
|
|
1463
|
+
if (turns === null) throw new Error(`Unknown previous_response_id: ${prevId}`);
|
|
1464
|
+
return { priorTurns: turns };
|
|
1465
|
+
}
|
|
1466
|
+
function emptyUsage() {
|
|
1467
|
+
return {
|
|
1468
|
+
input_tokens: 0,
|
|
1469
|
+
output_tokens: 0,
|
|
1470
|
+
total_tokens: 0,
|
|
1471
|
+
input_tokens_details: { cached_tokens: 0 },
|
|
1472
|
+
output_tokens_details: { reasoning_tokens: 0 }
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
function readUsageFromEvent(event) {
|
|
1476
|
+
const u = event.usage ?? event;
|
|
1477
|
+
const input = Number(u.input_tokens ?? u.prompt_tokens ?? u.inputTokens ?? 0);
|
|
1478
|
+
const output = Number(u.output_tokens ?? u.completion_tokens ?? u.outputTokens ?? 0);
|
|
1479
|
+
if (input === 0 && output === 0 && !("total_tokens" in u)) return null;
|
|
1480
|
+
const total = Number(u.total_tokens ?? input + output);
|
|
1481
|
+
const cached = Number(u.input_tokens_details?.cached_tokens ?? u.cached_tokens ?? 0);
|
|
1482
|
+
const reasoning = Number(u.output_tokens_details?.reasoning_tokens ?? u.reasoning_tokens ?? 0);
|
|
1483
|
+
return {
|
|
1484
|
+
input_tokens: input,
|
|
1485
|
+
output_tokens: output,
|
|
1486
|
+
total_tokens: total,
|
|
1487
|
+
input_tokens_details: { cached_tokens: cached },
|
|
1488
|
+
output_tokens_details: { reasoning_tokens: reasoning }
|
|
1489
|
+
};
|
|
1490
|
+
}
|
|
1491
|
+
function readToolInvocationFromRaw(event) {
|
|
1492
|
+
if (event.type !== "raw") return null;
|
|
1493
|
+
const data = event.data ?? event;
|
|
1494
|
+
const inner = typeof data.type === "string" ? data.type : "";
|
|
1495
|
+
const isComputerUse = inner === "computer-use" || inner === "computer_call" || typeof data.computerUse === "object" || typeof data.computer_use === "object";
|
|
1496
|
+
if (!(inner === "tool-invocation" || inner === "tool_call" || typeof data.toolInvocation === "object" || typeof data.tool_invocation === "object") && !isComputerUse) return null;
|
|
1497
|
+
const ti = data.toolInvocation ?? data.tool_invocation ?? data.computerUse ?? data.computer_use ?? data;
|
|
1498
|
+
const id = typeof ti.toolCallId === "string" ? ti.toolCallId : typeof ti.tool_call_id === "string" ? ti.tool_call_id : typeof ti.id === "string" ? ti.id : typeof ti.callId === "string" ? ti.callId : "";
|
|
1499
|
+
const name = isComputerUse ? "computer_use" : typeof ti.toolName === "string" ? ti.toolName : typeof ti.tool_name === "string" ? ti.tool_name : typeof ti.name === "string" ? ti.name : "";
|
|
1500
|
+
const args = ti.args ?? ti.arguments ?? ti.input ?? {};
|
|
1501
|
+
if (!id || !name) return null;
|
|
1502
|
+
return {
|
|
1503
|
+
id,
|
|
1504
|
+
name,
|
|
1505
|
+
arguments: typeof args === "string" ? args : JSON.stringify(args),
|
|
1506
|
+
isComputerUse,
|
|
1507
|
+
computerAction: isComputerUse ? ti.action ?? void 0 : void 0
|
|
1508
|
+
};
|
|
1509
|
+
}
|
|
1510
|
+
function readReasoningFromPart(event) {
|
|
1511
|
+
if (event.type !== "message.part.updated") return null;
|
|
1512
|
+
const part = event.part ?? event;
|
|
1513
|
+
if (part.type !== "reasoning" && part.type !== "thinking") return null;
|
|
1514
|
+
if (typeof part.text === "string") return part.text;
|
|
1515
|
+
if (typeof part.content === "string") return part.content;
|
|
1516
|
+
return null;
|
|
1517
|
+
}
|
|
1518
|
+
/**
|
|
1519
|
+
* Aggregate a Tangle SSE event sequence into the Responses-API output[]
|
|
1520
|
+
* array plus a usage envelope. This is the non-streaming path: callers
|
|
1521
|
+
* collect every event, hand them all in, and get back a settled response
|
|
1522
|
+
* payload ready to return as JSON.
|
|
1523
|
+
*/
|
|
1524
|
+
function assembleResponseOutput(events) {
|
|
1525
|
+
const accum = {
|
|
1526
|
+
textPieces: [],
|
|
1527
|
+
toolCalls: /* @__PURE__ */ new Map(),
|
|
1528
|
+
toolCallOrder: [],
|
|
1529
|
+
computerCalls: [],
|
|
1530
|
+
reasoningPieces: [],
|
|
1531
|
+
usage: emptyUsage(),
|
|
1532
|
+
hasUsage: false
|
|
1533
|
+
};
|
|
1534
|
+
for (const event of events) switch (event.type) {
|
|
1535
|
+
case "token": {
|
|
1536
|
+
const delta = typeof event.delta === "string" && event.delta || typeof event.text === "string" && event.text || typeof event.token === "string" && event.token || "";
|
|
1537
|
+
if (delta) accum.textPieces.push(delta);
|
|
1538
|
+
break;
|
|
1539
|
+
}
|
|
1540
|
+
case "raw": {
|
|
1541
|
+
const tool = readToolInvocationFromRaw(event);
|
|
1542
|
+
if (!tool) break;
|
|
1543
|
+
if (tool.isComputerUse) accum.computerCalls.push({
|
|
1544
|
+
type: "computer_call",
|
|
1545
|
+
id: `cc_${tool.id}`,
|
|
1546
|
+
call_id: tool.id,
|
|
1547
|
+
status: "completed",
|
|
1548
|
+
pending_safety_checks: [],
|
|
1549
|
+
...tool.computerAction ? { action: tool.computerAction } : {}
|
|
1550
|
+
});
|
|
1551
|
+
else {
|
|
1552
|
+
if (!accum.toolCalls.has(tool.id)) accum.toolCallOrder.push(tool.id);
|
|
1553
|
+
accum.toolCalls.set(tool.id, {
|
|
1554
|
+
type: "function_call",
|
|
1555
|
+
id: `fc_${tool.id}`,
|
|
1556
|
+
call_id: tool.id,
|
|
1557
|
+
name: tool.name,
|
|
1558
|
+
arguments: tool.arguments,
|
|
1559
|
+
status: "completed"
|
|
1560
|
+
});
|
|
1561
|
+
}
|
|
1562
|
+
break;
|
|
1563
|
+
}
|
|
1564
|
+
case "message.part.updated": {
|
|
1565
|
+
const reasoning = readReasoningFromPart(event);
|
|
1566
|
+
if (reasoning) accum.reasoningPieces.push(reasoning);
|
|
1567
|
+
break;
|
|
1568
|
+
}
|
|
1569
|
+
case "done": {
|
|
1570
|
+
const usage = readUsageFromEvent(event);
|
|
1571
|
+
if (usage) {
|
|
1572
|
+
accum.usage = foldUsage(accum.usage, usage);
|
|
1573
|
+
accum.hasUsage = true;
|
|
1574
|
+
}
|
|
1575
|
+
break;
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1578
|
+
const output = [];
|
|
1579
|
+
if (accum.reasoningPieces.length > 0) {
|
|
1580
|
+
const reasoning = {
|
|
1581
|
+
type: "reasoning",
|
|
1582
|
+
id: "rs_0",
|
|
1583
|
+
summary: [],
|
|
1584
|
+
content: accum.reasoningPieces.map((text) => ({
|
|
1585
|
+
type: "reasoning_text",
|
|
1586
|
+
text
|
|
1587
|
+
})),
|
|
1588
|
+
status: "completed"
|
|
1589
|
+
};
|
|
1590
|
+
output.push(reasoning);
|
|
1591
|
+
}
|
|
1592
|
+
if (accum.textPieces.length > 0) {
|
|
1593
|
+
const message = {
|
|
1594
|
+
type: "message",
|
|
1595
|
+
id: "msg_0",
|
|
1596
|
+
role: "assistant",
|
|
1597
|
+
status: "completed",
|
|
1598
|
+
content: [{
|
|
1599
|
+
type: "output_text",
|
|
1600
|
+
text: accum.textPieces.join(""),
|
|
1601
|
+
annotations: []
|
|
1602
|
+
}]
|
|
1603
|
+
};
|
|
1604
|
+
output.push(message);
|
|
1605
|
+
}
|
|
1606
|
+
for (const id of accum.toolCallOrder) {
|
|
1607
|
+
const call = accum.toolCalls.get(id);
|
|
1608
|
+
if (call) output.push(call);
|
|
1609
|
+
}
|
|
1610
|
+
for (const cc of accum.computerCalls) output.push(cc);
|
|
1611
|
+
return {
|
|
1612
|
+
output,
|
|
1613
|
+
usage: accum.usage
|
|
1614
|
+
};
|
|
1615
|
+
}
|
|
1616
|
+
function foldUsage(a, b) {
|
|
1617
|
+
return {
|
|
1618
|
+
input_tokens: a.input_tokens + b.input_tokens,
|
|
1619
|
+
output_tokens: a.output_tokens + b.output_tokens,
|
|
1620
|
+
total_tokens: a.total_tokens + b.total_tokens,
|
|
1621
|
+
input_tokens_details: { cached_tokens: a.input_tokens_details.cached_tokens + b.input_tokens_details.cached_tokens },
|
|
1622
|
+
output_tokens_details: { reasoning_tokens: a.output_tokens_details.reasoning_tokens + b.output_tokens_details.reasoning_tokens }
|
|
1623
|
+
};
|
|
1624
|
+
}
|
|
1625
|
+
/**
|
|
1626
|
+
* Fold every usage frame in a Tangle event sequence into a single
|
|
1627
|
+
* ResponseUsage envelope. Multiple `done` events are tolerated (e.g.
|
|
1628
|
+
* during retries) by summing.
|
|
1629
|
+
*/
|
|
1630
|
+
function usageFromEvents(events) {
|
|
1631
|
+
let total = emptyUsage();
|
|
1632
|
+
for (const event of events) {
|
|
1633
|
+
if (event.type !== "done") continue;
|
|
1634
|
+
const u = readUsageFromEvent(event);
|
|
1635
|
+
if (u) total = foldUsage(total, u);
|
|
1636
|
+
}
|
|
1637
|
+
return total;
|
|
1638
|
+
}
|
|
1639
|
+
const SUPPORTED_TOOL_TYPES = new Set([
|
|
1640
|
+
"function",
|
|
1641
|
+
"computer_use_preview",
|
|
1642
|
+
"code_interpreter",
|
|
1643
|
+
"web_search",
|
|
1644
|
+
"web_search_preview",
|
|
1645
|
+
"openrouter:web_search"
|
|
1646
|
+
]);
|
|
1647
|
+
const REJECTED_TOOL_TYPES = new Set(["file_search"]);
|
|
1648
|
+
var ResponsesValidationError = class extends Error {
|
|
1649
|
+
type = "invalid_request_error";
|
|
1650
|
+
code;
|
|
1651
|
+
param;
|
|
1652
|
+
constructor(message, code, param) {
|
|
1653
|
+
super(message);
|
|
1654
|
+
this.name = "ResponsesValidationError";
|
|
1655
|
+
this.code = code;
|
|
1656
|
+
this.param = param;
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1659
|
+
/**
|
|
1660
|
+
* Reject Responses requests that ask for unsupported tool types.
|
|
1661
|
+
* Function tools, computer-use preview, code interpreter, and
|
|
1662
|
+
* web_search/web_search_preview are accepted. file_search is rejected
|
|
1663
|
+
* (no vector-store backend). Unknown types are rejected.
|
|
1664
|
+
*/
|
|
1665
|
+
function validateResponsesRequest(req) {
|
|
1666
|
+
const tools = req.tools;
|
|
1667
|
+
if (!tools || tools.length === 0) return;
|
|
1668
|
+
for (let i = 0; i < tools.length; i++) {
|
|
1669
|
+
const type = tools[i].type;
|
|
1670
|
+
if (typeof type !== "string") throw new ResponsesValidationError(`tools[${i}] is missing a type discriminator`, "invalid_tool", `tools[${i}].type`);
|
|
1671
|
+
if (REJECTED_TOOL_TYPES.has(type)) throw new ResponsesValidationError(`Tool type "${type}" is not supported by this endpoint`, "unsupported_tool", `tools[${i}].type`);
|
|
1672
|
+
if (!SUPPORTED_TOOL_TYPES.has(type)) throw new ResponsesValidationError(`Tool type "${type}" is not recognized`, "unsupported_tool", `tools[${i}].type`);
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
/**
|
|
1676
|
+
* Tangle Router's `/v1/responses` supports web search through the
|
|
1677
|
+
* OpenRouter-compatible server-tool marker. Native OpenAI Responses
|
|
1678
|
+
* `web_search` / `web_search_preview` tools are not forwarded to OpenAI;
|
|
1679
|
+
* the router uses this marker to run Tangle-billed search first, inject
|
|
1680
|
+
* cited context, and strip the marker before the upstream Responses call.
|
|
1681
|
+
*/
|
|
1682
|
+
function normalizeResponsesWebSearchForTangleRouter(req, options = {}) {
|
|
1683
|
+
const tools = Array.isArray(req.tools) ? req.tools : void 0;
|
|
1684
|
+
if (!tools) return req;
|
|
1685
|
+
let changed = false;
|
|
1686
|
+
const normalized = tools.map((tool) => {
|
|
1687
|
+
if (!tool || typeof tool !== "object") return tool;
|
|
1688
|
+
const type = tool.type;
|
|
1689
|
+
if (type !== "web_search" && type !== "web_search_preview") return tool;
|
|
1690
|
+
changed = true;
|
|
1691
|
+
return {
|
|
1692
|
+
type: "openrouter:web_search",
|
|
1693
|
+
parameters: {
|
|
1694
|
+
...readNativeWebSearchParameters(tool),
|
|
1695
|
+
...options.provider ? { provider: options.provider } : {},
|
|
1696
|
+
...options.maxResults ? { max_results: options.maxResults } : {},
|
|
1697
|
+
...options.maxTotalResults ? { max_total_results: options.maxTotalResults } : {},
|
|
1698
|
+
...options.searchContextSize ? { search_context_size: options.searchContextSize } : {}
|
|
1699
|
+
}
|
|
1700
|
+
};
|
|
1701
|
+
});
|
|
1702
|
+
return changed ? {
|
|
1703
|
+
...req,
|
|
1704
|
+
tools: normalized
|
|
1705
|
+
} : req;
|
|
1706
|
+
}
|
|
1707
|
+
function readNativeWebSearchParameters(tool) {
|
|
1708
|
+
const input = tool;
|
|
1709
|
+
const result = {};
|
|
1710
|
+
const searchContextSize = input.search_context_size ?? input.searchContextSize;
|
|
1711
|
+
if (searchContextSize === "low" || searchContextSize === "medium" || searchContextSize === "high") result.search_context_size = searchContextSize;
|
|
1712
|
+
const userLocation = input.user_location ?? input.userLocation;
|
|
1713
|
+
if (userLocation && typeof userLocation === "object") result.user_location = userLocation;
|
|
1714
|
+
return result;
|
|
1715
|
+
}
|
|
1716
|
+
/**
|
|
1717
|
+
* Build a settled `Response` shell from an aggregated output + usage.
|
|
1718
|
+
* Caller fills in the runtime-specific fields (id, model, created_at,
|
|
1719
|
+
* status, instructions, etc.) to avoid having to re-derive them inside
|
|
1720
|
+
* the translator.
|
|
1721
|
+
*/
|
|
1722
|
+
function buildResponseShell(args) {
|
|
1723
|
+
const outputText = args.output.filter((item) => item.type === "message").flatMap((m) => m.content).filter((c) => c.type === "output_text").map((c) => c.text).join("");
|
|
1724
|
+
return {
|
|
1725
|
+
id: args.id,
|
|
1726
|
+
object: "response",
|
|
1727
|
+
created_at: args.createdAt,
|
|
1728
|
+
output_text: outputText,
|
|
1729
|
+
error: null,
|
|
1730
|
+
incomplete_details: null,
|
|
1731
|
+
instructions: args.instructions ?? null,
|
|
1732
|
+
metadata: null,
|
|
1733
|
+
model: args.model,
|
|
1734
|
+
output: args.output,
|
|
1735
|
+
parallel_tool_calls: false,
|
|
1736
|
+
temperature: null,
|
|
1737
|
+
tool_choice: "auto",
|
|
1738
|
+
tools: [],
|
|
1739
|
+
top_p: null,
|
|
1740
|
+
status: "completed",
|
|
1741
|
+
usage: args.usage,
|
|
1742
|
+
previous_response_id: args.previousResponseId ?? null
|
|
1743
|
+
};
|
|
1744
|
+
}
|
|
1745
|
+
//#endregion
|
|
1746
|
+
//#region src/openai/types.ts
|
|
1747
|
+
/**
|
|
1748
|
+
* Construct a fresh translator context. The factory is deliberately tiny
|
|
1749
|
+
* — call sites that need to override fields can do so via the partial.
|
|
1750
|
+
*/
|
|
1751
|
+
function createTranslatorContext(init) {
|
|
1752
|
+
return {
|
|
1753
|
+
chunkIndex: 0,
|
|
1754
|
+
toolCallBuffer: /* @__PURE__ */ new Map(),
|
|
1755
|
+
createdAt: Math.floor(Date.now() / 1e3),
|
|
1756
|
+
...init
|
|
1757
|
+
};
|
|
1758
|
+
}
|
|
1759
|
+
//#endregion
|
|
1760
|
+
export { EmbeddingValidationError, HookChain, InMemoryResponseStore, ResponsesValidationError, Run, actionRateLimitHook, assembleResponseOutput, auditLogHook, buildResponseShell, costCapHook, createTranslatorContext, destructiveActionGuardHook, egressPolicyHook, normalizeResponsesWebSearchForTangleRouter, openaiMessagesToSandboxInput, outcomeToFinishReason, resolvePreviousResponseId, runEvents, sandboxEventToChatChunk, sandboxEventToCompletionChunk, sandboxEventToResponsesEvent, screenshotRedactionHook, usageFromEvents, validateEmbeddingRequest, validateResponsesRequest };
|