@treasuredata/tdx 0.2.4 → 0.2.6

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.
Files changed (84) hide show
  1. package/dist/build-info.json +2 -2
  2. package/dist/cli.js +1 -1
  3. package/dist/client/cdp-client.js +1 -1
  4. package/dist/client/http-client.js +1 -1
  5. package/dist/client/llm-client.js +1 -1
  6. package/dist/client/rate-limiter.js +1 -1
  7. package/dist/client/td-client.js +1 -1
  8. package/dist/client/trino-client.js +1 -1
  9. package/dist/client/workflow-client.js +1 -1
  10. package/dist/commands/activations.js +1 -1
  11. package/dist/commands/api-command.js +1 -1
  12. package/dist/commands/chat-command.js +1 -1
  13. package/dist/commands/claude-command.js +1 -1
  14. package/dist/commands/command.js +1 -1
  15. package/dist/commands/context-command.js +1 -1
  16. package/dist/commands/databases.js +1 -1
  17. package/dist/commands/describe.js +1 -1
  18. package/dist/commands/job-command.js +1 -1
  19. package/dist/commands/llm-command.js +1 -1
  20. package/dist/commands/llm-proxy.js +1 -1
  21. package/dist/commands/parent-segment-command.js +1 -1
  22. package/dist/commands/profiles-command.js +1 -1
  23. package/dist/commands/query-command.js +1 -1
  24. package/dist/commands/segment-command.js +1 -1
  25. package/dist/commands/segment-create-command.js +1 -1
  26. package/dist/commands/segment-fields-command.js +1 -1
  27. package/dist/commands/segment-pwd-command.js +1 -1
  28. package/dist/commands/segment-update-command.js +1 -1
  29. package/dist/commands/segment-use-command.js +1 -1
  30. package/dist/commands/segments.js +1 -1
  31. package/dist/commands/show.js +1 -1
  32. package/dist/commands/tables.js +1 -1
  33. package/dist/commands/use-command.js +1 -1
  34. package/dist/commands/workflow-command.js +1 -1
  35. package/dist/core/auth.js +1 -1
  36. package/dist/core/config.js +1 -1
  37. package/dist/core/global-context.js +1 -1
  38. package/dist/core/profile.js +1 -1
  39. package/dist/core/project-config.js +1 -1
  40. package/dist/core/session.js +1 -1
  41. package/dist/index.js +1 -1
  42. package/dist/proxy/anthropic-adapter.js +1 -1
  43. package/dist/proxy/server.d.ts.map +1 -1
  44. package/dist/proxy/server.js +1 -1
  45. package/dist/proxy/server.js.map +1 -1
  46. package/dist/proxy/session-cache.js +1 -1
  47. package/dist/sdk/api.js +1 -1
  48. package/dist/sdk/database.js +1 -1
  49. package/dist/sdk/errors.js +1 -1
  50. package/dist/sdk/index.js +1 -1
  51. package/dist/sdk/job.js +1 -1
  52. package/dist/sdk/llm.js +1 -1
  53. package/dist/sdk/query.js +1 -1
  54. package/dist/sdk/segment.js +1 -1
  55. package/dist/sdk/table.js +1 -1
  56. package/dist/sdk/workflow.js +1 -1
  57. package/dist/types/endpoints.js +1 -1
  58. package/dist/types/index.js +1 -1
  59. package/dist/utils/agent-ref-parser.js +1 -1
  60. package/dist/utils/chat-cache.js +1 -1
  61. package/dist/utils/colors.js +1 -1
  62. package/dist/utils/command-output.js +1 -1
  63. package/dist/utils/constants.js +1 -1
  64. package/dist/utils/file-permissions.js +1 -1
  65. package/dist/utils/format-detector.js +1 -1
  66. package/dist/utils/formatters.js +1 -1
  67. package/dist/utils/json-loader.js +1 -1
  68. package/dist/utils/model-aliases.js +1 -1
  69. package/dist/utils/option-validation.js +1 -1
  70. package/dist/utils/port.js +1 -1
  71. package/dist/utils/process.js +1 -1
  72. package/dist/utils/prompt.js +1 -1
  73. package/dist/utils/segment-path-parser.js +1 -1
  74. package/dist/utils/segment-ref-parser.js +1 -1
  75. package/dist/utils/spinner.js +1 -1
  76. package/dist/utils/sql-parser.js +1 -1
  77. package/dist/utils/sse-parser.js +1 -1
  78. package/dist/utils/string-utils.js +1 -1
  79. package/dist/utils/table-ref-parser.js +1 -1
  80. package/dist/utils/tdx-logger.js +1 -1
  81. package/dist/utils/tree-formatter.js +1 -1
  82. package/dist/utils/version-check.js +1 -1
  83. package/dist/utils/workflow-utils.js +1 -1
  84. package/package.json +1 -1
@@ -1 +1 @@
1
- const a35_0x32757a=a35_0x498f;(function(_0x47f890,_0x184700){const _0x3f4383=a35_0x498f,_0x4abf13=_0x47f890();while(!![]){try{const _0x2cf210=parseInt(_0x3f4383(0xd3))/0x1+parseInt(_0x3f4383(0xb0))/0x2*(parseInt(_0x3f4383(0xe4))/0x3)+parseInt(_0x3f4383(0xd4))/0x4*(-parseInt(_0x3f4383(0xb7))/0x5)+parseInt(_0x3f4383(0xcb))/0x6*(parseInt(_0x3f4383(0xe3))/0x7)+-parseInt(_0x3f4383(0xe9))/0x8*(parseInt(_0x3f4383(0xde))/0x9)+-parseInt(_0x3f4383(0xe5))/0xa+parseInt(_0x3f4383(0xe1))/0xb;if(_0x2cf210===_0x184700)break;else _0x4abf13['push'](_0x4abf13['shift']());}catch(_0x4499c4){_0x4abf13['push'](_0x4abf13['shift']());}}}(a35_0x47fc,0x700e2));import{resolveSite,getAPIKey,getConfigDir}from'./config.js';import{loadSessionContext}from'./session.js';import{loadProjectConfig,findProjectConfigPath}from'./project-config.js';import{getActiveProfile,loadProfile}from'./profile.js';import{LogLevel}from'../utils/tdx-logger.js';function a35_0x498f(_0x29d734,_0xe0d093){const _0x47fced=a35_0x47fc();return a35_0x498f=function(_0x498f93,_0x4255e5){_0x498f93=_0x498f93-0xab;let _0x36f6aa=_0x47fced[_0x498f93];return _0x36f6aa;},a35_0x498f(_0x29d734,_0xe0d093);}function a35_0x47fc(){const _0xab5b4b=['8421435xnTrwE','displayWithSources','28UvpwPh','58173KVEehr','9073820KAeXBK','INFO','config','sessionId','11912DhYXYA','profile:\x20','configFiles','log','toString',':\x20none','database','segmentPath','display','session','10lkxYPP','getParameters','loadGlobalConfig','.env','[context]','utf-8','replace','30pgGpLl','parse','verbose','parentSegment','logLevel','Global\x20Credentials','Session','segment_path','llmProject','Global','layers','activeProfile','us01','.json','default','globalCredentials','apiKey','parent_segment','(session:\x20','tdx.json','854448SxFXBf','string','llm_project','Profile\x20Credentials','getSource','sessions','profiles','Project','844223rGpUTQ','157012ZfYWcr','entries','injectIntoOptions','readFileSync','join','(active)','project','site','not\x20set','existsSync','4077orEZQT','profile','global'];a35_0x47fc=function(){return _0xab5b4b;};return a35_0x47fc();}import*as a35_0x405dec from'node:fs';import*as a35_0x581336 from'node:path';export class GlobalContext{[a35_0x32757a(0xdb)];[a35_0x32757a(0xac)];['parent_segment'];['segment_path'];[a35_0x32757a(0xcd)];[a35_0x32757a(0xc7)];[a35_0x32757a(0xb9)];[a35_0x32757a(0xbb)];[a35_0x32757a(0xc1)];['activeProfile'];['sessionId'];[a35_0x32757a(0xeb)];constructor(_0x5a54c8){const _0x1350e6=a35_0x32757a;this[_0x1350e6(0xe8)]=_0x5a54c8[_0x1350e6(0xaf)]||process['ppid'][_0x1350e6(0xed)]();const _0x2c954e=loadSessionContext(_0x5a54c8[_0x1350e6(0xaf)]),_0x34d380=loadProjectConfig(),_0x57b9a3=this[_0x1350e6(0xb2)]();this[_0x1350e6(0xc2)]=_0x5a54c8['profile']||_0x2c954e?.[_0x1350e6(0xdf)]||_0x57b9a3[_0x1350e6(0xdf)]||getActiveProfile();const _0x343268=this['activeProfile']?loadProfile(this[_0x1350e6(0xc2)]):null,_0x26ccc7=_0x4ff5a1=>{const _0x1673b3=_0x1350e6;if(!_0x4ff5a1)return{};const _0x2388ff=_0x4ff5a1,_0x5925e9={};for(const [_0x9e7c8b,_0xb5c5d8]of Object[_0x1673b3(0xd5)](_0x2388ff)){typeof _0xb5c5d8===_0x1673b3(0xcc)&&(_0x5925e9[_0x9e7c8b]=_0xb5c5d8);}return _0x5925e9;},_0xea74f3={};if(_0x5a54c8[_0x1350e6(0xdb)]&&_0x5a54c8['site']!==_0x1350e6(0xc3))_0xea74f3[_0x1350e6(0xdb)]=_0x5a54c8[_0x1350e6(0xdb)];const _0x471554=_0x2c954e?.[_0x1350e6(0xac)],_0x3031c9=_0x34d380?.[_0x1350e6(0xac)],_0x5155df=_0x343268?.['config']?.[_0x1350e6(0xac)],_0x51bf4e=_0x57b9a3[_0x1350e6(0xac)];_0x5a54c8['database']&&(_0x5a54c8[_0x1350e6(0xac)]!==_0x471554&&_0x5a54c8[_0x1350e6(0xac)]!==_0x3031c9&&_0x5a54c8['database']!==_0x5155df&&_0x5a54c8[_0x1350e6(0xac)]!==_0x51bf4e)&&(_0xea74f3[_0x1350e6(0xac)]=_0x5a54c8[_0x1350e6(0xac)]);if(_0x5a54c8[_0x1350e6(0xba)])_0xea74f3[_0x1350e6(0xc8)]=_0x5a54c8[_0x1350e6(0xba)];if(_0x5a54c8[_0x1350e6(0xbf)])_0xea74f3[_0x1350e6(0xcd)]=_0x5a54c8[_0x1350e6(0xbf)];if(_0x5a54c8[_0x1350e6(0xdf)])_0xea74f3[_0x1350e6(0xdf)]=_0x5a54c8[_0x1350e6(0xdf)];this[_0x1350e6(0xc1)]={'cliFlags':_0xea74f3,'session':_0x26ccc7(_0x2c954e),'project':_0x26ccc7(_0x34d380),'profile':_0x26ccc7(_0x343268?.[_0x1350e6(0xe7)]),'global':_0x26ccc7(_0x57b9a3)};const _0x1ec17a={...this[_0x1350e6(0xc1)][_0x1350e6(0xe0)],...this[_0x1350e6(0xc1)][_0x1350e6(0xdf)],...this[_0x1350e6(0xc1)][_0x1350e6(0xda)],...this[_0x1350e6(0xc1)][_0x1350e6(0xaf)],...this['layers']['cliFlags']},_0x17801a=_0x1ec17a[_0x1350e6(0xdb)]||_0x1350e6(0xc3);this[_0x1350e6(0xdb)]=resolveSite(_0x17801a),this[_0x1350e6(0xac)]=_0x1ec17a['database'],this[_0x1350e6(0xc8)]=_0x1ec17a[_0x1350e6(0xc8)],this[_0x1350e6(0xbe)]=_0x1ec17a[_0x1350e6(0xbe)],this[_0x1350e6(0xcd)]=_0x1ec17a['llm_project'],this['verbose']=_0x5a54c8['verbose']||![],this['logLevel']=_0x5a54c8['logLevel']??LogLevel[_0x1350e6(0xe6)],this[_0x1350e6(0xc7)]=getAPIKey(this['site'],this[_0x1350e6(0xc2)]||undefined);const _0x110639=getConfigDir(),_0x4a7540=a35_0x581336['join'](_0x110639,_0x1350e6(0xd0),this[_0x1350e6(0xe8)]+_0x1350e6(0xc4)),_0x5673a9=findProjectConfigPath(),_0x3c3ba1=a35_0x581336[_0x1350e6(0xd8)](_0x110639,_0x1350e6(0xca)),_0x2a747b=a35_0x581336[_0x1350e6(0xd8)](_0x110639,_0x1350e6(0xb3));let _0x51fde2=null,_0x2d0b5d=null;this[_0x1350e6(0xc2)]&&(_0x51fde2=a35_0x581336[_0x1350e6(0xd8)](_0x110639,_0x1350e6(0xd1),this['activeProfile'],_0x1350e6(0xca)),_0x2d0b5d=a35_0x581336[_0x1350e6(0xd8)](_0x110639,_0x1350e6(0xd1),this[_0x1350e6(0xc2)],_0x1350e6(0xb3))),this['configFiles']={'session':a35_0x405dec[_0x1350e6(0xdd)](_0x4a7540)?_0x4a7540:null,'project':_0x5673a9,'profile':_0x51fde2&&a35_0x405dec[_0x1350e6(0xdd)](_0x51fde2)?_0x51fde2:null,'profileCredentials':_0x2d0b5d&&a35_0x405dec['existsSync'](_0x2d0b5d)?_0x2d0b5d:null,'global':a35_0x405dec[_0x1350e6(0xdd)](_0x3c3ba1)?_0x3c3ba1:null,'globalCredentials':a35_0x405dec[_0x1350e6(0xdd)](_0x2a747b)?_0x2a747b:null};}[a35_0x32757a(0xcf)](_0x3a8762,_0x543d8f){const _0x429997=a35_0x32757a;if(!_0x543d8f)return _0x429997(0xdc);const _0x1c3943=_0x543d8f;if(this['layers']['cliFlags'][_0x3a8762]===_0x1c3943){if(_0x3a8762===_0x429997(0xdb)&&_0x1c3943===_0x429997(0xc3)&&!this['layers'][_0x429997(0xaf)]['site']&&!this[_0x429997(0xc1)][_0x429997(0xda)][_0x429997(0xdb)]&&!this[_0x429997(0xc1)]['profile'][_0x429997(0xdb)]&&!this[_0x429997(0xc1)]['global'][_0x429997(0xdb)])return _0x429997(0xc5);return'CLI\x20flag:\x20--'+_0x3a8762[_0x429997(0xb6)](/_/g,'-');}if(this['layers'][_0x429997(0xaf)][_0x3a8762]===_0x1c3943)return _0x429997(0xaf);if(this[_0x429997(0xc1)][_0x429997(0xda)][_0x3a8762]===_0x1c3943)return'project';if(this['layers'][_0x429997(0xdf)][_0x3a8762]===_0x1c3943)return _0x429997(0xea)+this[_0x429997(0xc2)];if(this[_0x429997(0xc1)][_0x429997(0xe0)][_0x3a8762]===_0x1c3943)return _0x429997(0xe0);return _0x429997(0xc5);}[a35_0x32757a(0xb2)](){const _0x304697=a35_0x32757a,_0xd38a6c=a35_0x581336['join'](getConfigDir(),_0x304697(0xca));if(!a35_0x405dec[_0x304697(0xdd)](_0xd38a6c))return{};try{const _0x23c165=a35_0x405dec[_0x304697(0xd7)](_0xd38a6c,_0x304697(0xb5));return JSON[_0x304697(0xb8)](_0x23c165);}catch{return{};}}[a35_0x32757a(0xd6)](_0x12bbe4){const _0xa838c9=a35_0x32757a;_0x12bbe4[_0xa838c9(0xdb)]=this[_0xa838c9(0xdb)],!_0x12bbe4[_0xa838c9(0xac)]&&this[_0xa838c9(0xac)]&&(_0x12bbe4['database']=this[_0xa838c9(0xac)]),!_0x12bbe4[_0xa838c9(0xba)]&&this[_0xa838c9(0xc8)]&&(_0x12bbe4[_0xa838c9(0xba)]=this[_0xa838c9(0xc8)]),!_0x12bbe4[_0xa838c9(0xad)]&&this[_0xa838c9(0xbe)]&&(_0x12bbe4['segmentPath']=this['segment_path']),!_0x12bbe4['llmProject']&&this['llm_project']&&(_0x12bbe4[_0xa838c9(0xbf)]=this[_0xa838c9(0xcd)]);}[a35_0x32757a(0xb1)](){const _0x35870a=a35_0x32757a;return[{'key':_0x35870a(0xdb),'value':this[_0x35870a(0xdb)]},{'key':_0x35870a(0xac),'value':this[_0x35870a(0xac)]},{'key':_0x35870a(0xc8),'value':this[_0x35870a(0xc8)]},{'key':_0x35870a(0xbe),'value':this['segment_path']},{'key':_0x35870a(0xcd),'value':this['llm_project']},{'key':_0x35870a(0xdf),'value':this[_0x35870a(0xc2)]||undefined}];}[a35_0x32757a(0xae)](){const _0xe5cd1e=a35_0x32757a;console[_0xe5cd1e(0xec)]('[context]');for(const {key:_0x31c3b7,value:_0x181082}of this[_0xe5cd1e(0xb1)]()){_0x181082&&console['log'](_0x31c3b7+':\x20'+_0x181082);}}[a35_0x32757a(0xe2)](){const _0x5dc89b=a35_0x32757a;console['log'](_0x5dc89b(0xb4));for(const {key:_0x4d2b39,value:_0x2cc3a9}of this[_0x5dc89b(0xb1)]()){if(_0x2cc3a9){const _0x142509=_0x4d2b39===_0x5dc89b(0xdf)?_0x5dc89b(0xd9):'('+this[_0x5dc89b(0xcf)](_0x4d2b39,_0x2cc3a9)+')';console[_0x5dc89b(0xec)](_0x4d2b39+':\x20'+_0x2cc3a9+'\x20'+_0x142509);}}console[_0x5dc89b(0xec)]('\x0a[configuration\x20files]');const _0x4e6290=[{'label':_0x5dc89b(0xbd),'path':this['configFiles'][_0x5dc89b(0xaf)],'extra':_0x5dc89b(0xc9)+this[_0x5dc89b(0xe8)]+')'},{'label':'Project','path':this[_0x5dc89b(0xeb)][_0x5dc89b(0xda)]},{'label':'Profile','path':this[_0x5dc89b(0xeb)][_0x5dc89b(0xdf)]},{'label':_0x5dc89b(0xce),'path':this[_0x5dc89b(0xeb)]['profileCredentials']},{'label':'Global','path':this[_0x5dc89b(0xeb)][_0x5dc89b(0xe0)]},{'label':_0x5dc89b(0xbc),'path':this[_0x5dc89b(0xeb)][_0x5dc89b(0xc6)]}];for(const {label:_0x163302,path:_0x533517,extra:_0x18028b}of _0x4e6290){if(_0x533517)console['log'](_0x163302+':\x20'+_0x533517+'\x20✓'+(_0x18028b?'\x20'+_0x18028b:''));else{if(_0x163302==='Session')console[_0x5dc89b(0xec)](_0x163302+':\x20none\x20(using\x20session:\x20'+this['sessionId']+')');else(_0x163302===_0x5dc89b(0xd2)||_0x163302===_0x5dc89b(0xc0))&&console[_0x5dc89b(0xec)](_0x163302+_0x5dc89b(0xab));}}}}
1
+ const a35_0x5dda74=a35_0x2ee5;function a35_0x523c(){const _0x4d4bc6=['Session','apiKey','join','9zaGgAg','9548ayIQIV','entries','layers','llmProject','session','110467bgTHzA','toString','string','getSource',':\x20none','(session:\x20','global','6kgrXUC','getParameters','project','3690nJdejy','INFO','profiles','1558859VAPwyQ','1573IBCAOX','existsSync','activeProfile','not\x20set','parentSegment','36410xJovCh','log','segmentPath','profileCredentials','us01','globalCredentials','config','parent_segment','\x0a[configuration\x20files]','[context]','Profile','displayWithSources','segment_path','configFiles','parse','database','replace','Global\x20Credentials','ppid','loadGlobalConfig','sessionId','injectIntoOptions','.env','readFileSync','892688jnDzSf','default','logLevel','tdx.json','cliFlags','sessions','Profile\x20Credentials','llm_project','2220972DGpRul','profile','.json','site','verbose','311314yGjuJj','Project','Global'];a35_0x523c=function(){return _0x4d4bc6;};return a35_0x523c();}(function(_0x111d1a,_0x335ad0){const _0x57b377=a35_0x2ee5,_0x3585ab=_0x111d1a();while(!![]){try{const _0x3c12d2=parseInt(_0x57b377(0x94))/0x1+-parseInt(_0x57b377(0xbf))/0x2*(-parseInt(_0x57b377(0xd2))/0x3)+-parseInt(_0x57b377(0xc6))/0x4*(parseInt(_0x57b377(0x91))/0x5)+parseInt(_0x57b377(0xba))/0x6+parseInt(_0x57b377(0xcb))/0x7+-parseInt(_0x57b377(0xb2))/0x8*(parseInt(_0x57b377(0xc5))/0x9)+parseInt(_0x57b377(0x9a))/0xa*(parseInt(_0x57b377(0x95))/0xb);if(_0x3c12d2===_0x335ad0)break;else _0x3585ab['push'](_0x3585ab['shift']());}catch(_0x19440a){_0x3585ab['push'](_0x3585ab['shift']());}}}(a35_0x523c,0xdc9a3));import{resolveSite,getAPIKey,getConfigDir}from'./config.js';import{loadSessionContext}from'./session.js';function a35_0x2ee5(_0x185868,_0x222385){const _0x523c2b=a35_0x523c();return a35_0x2ee5=function(_0x2ee5f9,_0x333650){_0x2ee5f9=_0x2ee5f9-0x8f;let _0x2d83c1=_0x523c2b[_0x2ee5f9];return _0x2d83c1;},a35_0x2ee5(_0x185868,_0x222385);}import{loadProjectConfig,findProjectConfigPath}from'./project-config.js';import{getActiveProfile,loadProfile}from'./profile.js';import{LogLevel}from'../utils/tdx-logger.js';import*as a35_0x557864 from'node:fs';import*as a35_0x390ed6 from'node:path';export class GlobalContext{[a35_0x5dda74(0xbd)];[a35_0x5dda74(0xa9)];['parent_segment'];['segment_path'];['llm_project'];['apiKey'];[a35_0x5dda74(0xbe)];[a35_0x5dda74(0xb4)];[a35_0x5dda74(0xc8)];[a35_0x5dda74(0x97)];[a35_0x5dda74(0xae)];[a35_0x5dda74(0xa7)];constructor(_0x288b01){const _0x5e63f4=a35_0x5dda74;this[_0x5e63f4(0xae)]=_0x288b01['session']||process[_0x5e63f4(0xac)][_0x5e63f4(0xcc)]();const _0x43b6b=loadSessionContext(_0x288b01[_0x5e63f4(0xca)]),_0x16fb2c=loadProjectConfig(),_0x1bbfd0=this[_0x5e63f4(0xad)]();this[_0x5e63f4(0x97)]=_0x288b01['profile']||_0x43b6b?.[_0x5e63f4(0xbb)]||_0x1bbfd0['profile']||getActiveProfile();const _0x5e87df=this['activeProfile']?loadProfile(this[_0x5e63f4(0x97)]):null,_0x2d2bf2=_0xbfb84=>{const _0xd93f7c=_0x5e63f4;if(!_0xbfb84)return{};const _0x16b459=_0xbfb84,_0x54947c={};for(const [_0x433bcb,_0xd25068]of Object[_0xd93f7c(0xc7)](_0x16b459)){typeof _0xd25068===_0xd93f7c(0xcd)&&(_0x54947c[_0x433bcb]=_0xd25068);}return _0x54947c;},_0x4112cb={};if(_0x288b01[_0x5e63f4(0xbd)]&&_0x288b01[_0x5e63f4(0xbd)]!==_0x5e63f4(0x9e))_0x4112cb[_0x5e63f4(0xbd)]=_0x288b01['site'];const _0x2eef28=_0x43b6b?.[_0x5e63f4(0xa9)],_0x53e2c4=_0x16fb2c?.['database'],_0x4327a9=_0x5e87df?.[_0x5e63f4(0xa0)]?.[_0x5e63f4(0xa9)],_0x5a64ea=_0x1bbfd0[_0x5e63f4(0xa9)];_0x288b01[_0x5e63f4(0xa9)]&&(_0x288b01['database']!==_0x2eef28&&_0x288b01[_0x5e63f4(0xa9)]!==_0x53e2c4&&_0x288b01['database']!==_0x4327a9&&_0x288b01[_0x5e63f4(0xa9)]!==_0x5a64ea)&&(_0x4112cb[_0x5e63f4(0xa9)]=_0x288b01[_0x5e63f4(0xa9)]);if(_0x288b01[_0x5e63f4(0x99)])_0x4112cb['parent_segment']=_0x288b01[_0x5e63f4(0x99)];if(_0x288b01[_0x5e63f4(0xc9)])_0x4112cb[_0x5e63f4(0xb9)]=_0x288b01['llmProject'];if(_0x288b01[_0x5e63f4(0xbb)])_0x4112cb[_0x5e63f4(0xbb)]=_0x288b01[_0x5e63f4(0xbb)];this[_0x5e63f4(0xc8)]={'cliFlags':_0x4112cb,'session':_0x2d2bf2(_0x43b6b),'project':_0x2d2bf2(_0x16fb2c),'profile':_0x2d2bf2(_0x5e87df?.[_0x5e63f4(0xa0)]),'global':_0x2d2bf2(_0x1bbfd0)};const _0x3383d1={...this[_0x5e63f4(0xc8)][_0x5e63f4(0xd1)],...this[_0x5e63f4(0xc8)]['profile'],...this[_0x5e63f4(0xc8)][_0x5e63f4(0x90)],...this[_0x5e63f4(0xc8)]['session'],...this[_0x5e63f4(0xc8)]['cliFlags']},_0x53db67=_0x3383d1[_0x5e63f4(0xbd)]||_0x5e63f4(0x9e);this[_0x5e63f4(0xbd)]=resolveSite(_0x53db67),this[_0x5e63f4(0xa9)]=_0x3383d1['database'],this[_0x5e63f4(0xa1)]=_0x3383d1[_0x5e63f4(0xa1)],this['segment_path']=_0x3383d1[_0x5e63f4(0xa6)],this[_0x5e63f4(0xb9)]=_0x3383d1[_0x5e63f4(0xb9)],this[_0x5e63f4(0xbe)]=_0x288b01['verbose']||![],this[_0x5e63f4(0xb4)]=_0x288b01[_0x5e63f4(0xb4)]??LogLevel[_0x5e63f4(0x92)],this[_0x5e63f4(0xc3)]=getAPIKey(this['site'],this[_0x5e63f4(0x97)]||undefined);const _0x3cc1f4=getConfigDir(),_0x5ddb7c=a35_0x390ed6['join'](_0x3cc1f4,_0x5e63f4(0xb7),this['sessionId']+_0x5e63f4(0xbc)),_0x512a46=findProjectConfigPath(),_0x4dedb8=a35_0x390ed6[_0x5e63f4(0xc4)](_0x3cc1f4,_0x5e63f4(0xb5)),_0x12c696=a35_0x390ed6[_0x5e63f4(0xc4)](_0x3cc1f4,_0x5e63f4(0xb0));let _0x4ba0b3=null,_0x4be689=null;this[_0x5e63f4(0x97)]&&(_0x4ba0b3=a35_0x390ed6[_0x5e63f4(0xc4)](_0x3cc1f4,_0x5e63f4(0x93),this[_0x5e63f4(0x97)],_0x5e63f4(0xb5)),_0x4be689=a35_0x390ed6[_0x5e63f4(0xc4)](_0x3cc1f4,_0x5e63f4(0x93),this[_0x5e63f4(0x97)],'.env')),this[_0x5e63f4(0xa7)]={'session':a35_0x557864[_0x5e63f4(0x96)](_0x5ddb7c)?_0x5ddb7c:null,'project':_0x512a46,'profile':_0x4ba0b3&&a35_0x557864[_0x5e63f4(0x96)](_0x4ba0b3)?_0x4ba0b3:null,'profileCredentials':_0x4be689&&a35_0x557864['existsSync'](_0x4be689)?_0x4be689:null,'global':a35_0x557864[_0x5e63f4(0x96)](_0x4dedb8)?_0x4dedb8:null,'globalCredentials':a35_0x557864['existsSync'](_0x12c696)?_0x12c696:null};}[a35_0x5dda74(0xce)](_0x2f490b,_0x31ef87){const _0x10a4ba=a35_0x5dda74;if(!_0x31ef87)return _0x10a4ba(0x98);const _0x531faa=_0x31ef87;if(this[_0x10a4ba(0xc8)][_0x10a4ba(0xb6)][_0x2f490b]===_0x531faa){if(_0x2f490b==='site'&&_0x531faa===_0x10a4ba(0x9e)&&!this['layers']['session'][_0x10a4ba(0xbd)]&&!this[_0x10a4ba(0xc8)][_0x10a4ba(0x90)][_0x10a4ba(0xbd)]&&!this[_0x10a4ba(0xc8)][_0x10a4ba(0xbb)][_0x10a4ba(0xbd)]&&!this[_0x10a4ba(0xc8)][_0x10a4ba(0xd1)][_0x10a4ba(0xbd)])return _0x10a4ba(0xb3);return'CLI\x20flag:\x20--'+_0x2f490b[_0x10a4ba(0xaa)](/_/g,'-');}if(this[_0x10a4ba(0xc8)][_0x10a4ba(0xca)][_0x2f490b]===_0x531faa)return _0x10a4ba(0xca);if(this[_0x10a4ba(0xc8)][_0x10a4ba(0x90)][_0x2f490b]===_0x531faa)return _0x10a4ba(0x90);if(this[_0x10a4ba(0xc8)]['profile'][_0x2f490b]===_0x531faa)return'profile:\x20'+this[_0x10a4ba(0x97)];if(this['layers'][_0x10a4ba(0xd1)][_0x2f490b]===_0x531faa)return _0x10a4ba(0xd1);return _0x10a4ba(0xb3);}[a35_0x5dda74(0xad)](){const _0x14ae2a=a35_0x5dda74,_0x33b8f0=a35_0x390ed6[_0x14ae2a(0xc4)](getConfigDir(),_0x14ae2a(0xb5));if(!a35_0x557864[_0x14ae2a(0x96)](_0x33b8f0))return{};try{const _0x34a63c=a35_0x557864[_0x14ae2a(0xb1)](_0x33b8f0,'utf-8');return JSON[_0x14ae2a(0xa8)](_0x34a63c);}catch{return{};}}[a35_0x5dda74(0xaf)](_0x4b1ffa){const _0x335834=a35_0x5dda74;_0x4b1ffa[_0x335834(0xbd)]=this[_0x335834(0xbd)],!_0x4b1ffa[_0x335834(0xa9)]&&this['database']&&(_0x4b1ffa[_0x335834(0xa9)]=this['database']),!_0x4b1ffa[_0x335834(0x99)]&&this[_0x335834(0xa1)]&&(_0x4b1ffa['parentSegment']=this['parent_segment']),!_0x4b1ffa[_0x335834(0x9c)]&&this[_0x335834(0xa6)]&&(_0x4b1ffa[_0x335834(0x9c)]=this[_0x335834(0xa6)]),!_0x4b1ffa[_0x335834(0xc9)]&&this[_0x335834(0xb9)]&&(_0x4b1ffa['llmProject']=this['llm_project']);}[a35_0x5dda74(0x8f)](){const _0x34bec3=a35_0x5dda74;return[{'key':_0x34bec3(0xbd),'value':this[_0x34bec3(0xbd)]},{'key':_0x34bec3(0xa9),'value':this[_0x34bec3(0xa9)]},{'key':'parent_segment','value':this['parent_segment']},{'key':_0x34bec3(0xa6),'value':this[_0x34bec3(0xa6)]},{'key':_0x34bec3(0xb9),'value':this['llm_project']},{'key':_0x34bec3(0xbb),'value':this[_0x34bec3(0x97)]||undefined}];}['display'](){const _0x18f819=a35_0x5dda74;console[_0x18f819(0x9b)](_0x18f819(0xa3));for(const {key:_0x5bfa88,value:_0x2b0c12}of this[_0x18f819(0x8f)]()){_0x2b0c12&&console[_0x18f819(0x9b)](_0x5bfa88+':\x20'+_0x2b0c12);}}[a35_0x5dda74(0xa5)](){const _0x392683=a35_0x5dda74;console[_0x392683(0x9b)](_0x392683(0xa3));for(const {key:_0x54a62d,value:_0x5fd85f}of this[_0x392683(0x8f)]()){if(_0x5fd85f){const _0x216c2d=_0x54a62d===_0x392683(0xbb)?'(active)':'('+this[_0x392683(0xce)](_0x54a62d,_0x5fd85f)+')';console[_0x392683(0x9b)](_0x54a62d+':\x20'+_0x5fd85f+'\x20'+_0x216c2d);}}console[_0x392683(0x9b)](_0x392683(0xa2));const _0x15ecdd=[{'label':_0x392683(0xc2),'path':this['configFiles']['session'],'extra':_0x392683(0xd0)+this[_0x392683(0xae)]+')'},{'label':_0x392683(0xc0),'path':this[_0x392683(0xa7)][_0x392683(0x90)]},{'label':_0x392683(0xa4),'path':this[_0x392683(0xa7)][_0x392683(0xbb)]},{'label':_0x392683(0xb8),'path':this['configFiles'][_0x392683(0x9d)]},{'label':_0x392683(0xc1),'path':this[_0x392683(0xa7)]['global']},{'label':_0x392683(0xab),'path':this[_0x392683(0xa7)][_0x392683(0x9f)]}];for(const {label:_0x26e369,path:_0x23f2a2,extra:_0x3c2ff7}of _0x15ecdd){if(_0x23f2a2)console[_0x392683(0x9b)](_0x26e369+':\x20'+_0x23f2a2+'\x20✓'+(_0x3c2ff7?'\x20'+_0x3c2ff7:''));else{if(_0x26e369===_0x392683(0xc2))console['log'](_0x26e369+':\x20none\x20(using\x20session:\x20'+this[_0x392683(0xae)]+')');else(_0x26e369===_0x392683(0xc0)||_0x26e369==='Global')&&console[_0x392683(0x9b)](_0x26e369+_0x392683(0xcf));}}}}
@@ -1 +1 @@
1
- (function(_0x1525a4,_0x31104e){const _0x462ec7=a36_0x1038,_0x196036=_0x1525a4();while(!![]){try{const _0x4b8b0a=-parseInt(_0x462ec7(0xe8))/0x1+-parseInt(_0x462ec7(0xc2))/0x2+parseInt(_0x462ec7(0xdb))/0x3+parseInt(_0x462ec7(0xce))/0x4*(parseInt(_0x462ec7(0x9e))/0x5)+-parseInt(_0x462ec7(0xa8))/0x6*(parseInt(_0x462ec7(0xb4))/0x7)+-parseInt(_0x462ec7(0xe0))/0x8*(parseInt(_0x462ec7(0xab))/0x9)+parseInt(_0x462ec7(0xdf))/0xa*(parseInt(_0x462ec7(0xb2))/0xb);if(_0x4b8b0a===_0x31104e)break;else _0x196036['push'](_0x196036['shift']());}catch(_0x3806fa){_0x196036['push'](_0x196036['shift']());}}}(a36_0x15b2,0x3a0b0));import*as a36_0x519f72 from'node:fs';import*as a36_0x45c650 from'node:path';import{getConfigDir}from'./config.js';import{createSecureDirectory,writeSecureFile}from'../utils/file-permissions.js';import{findProjectConfigPath}from'./project-config.js';export function getProfileParams(_0x4a00ab){const _0x30d341=a36_0x1038,_0x3f9dfb={};if(!_0x4a00ab)return _0x3f9dfb;for(const [_0x23e002,_0x1f5b12]of Object[_0x30d341(0xe7)](_0x4a00ab)){_0x23e002!==_0x30d341(0xa9)&&_0x1f5b12!==undefined&&(_0x3f9dfb[_0x23e002]=_0x1f5b12);}return _0x3f9dfb;}export function getProfilesDir(){const _0x41ca01=a36_0x1038;return a36_0x45c650[_0x41ca01(0xb9)](getConfigDir(),'profiles');}function getProfileDir(_0x136109){return a36_0x45c650['join'](getProfilesDir(),_0x136109);}function getProfileConfigPath(_0x1879b3){const _0x5933cb=a36_0x1038;return a36_0x45c650[_0x5933cb(0xb9)](getProfileDir(_0x1879b3),_0x5933cb(0xb8));}function getProfileEnvPath(_0x23c93f){const _0x7a49a5=a36_0x1038;return a36_0x45c650[_0x7a49a5(0xb9)](getProfileDir(_0x23c93f),'.env');}function getGlobalConfigPath(){return a36_0x45c650['join'](getConfigDir(),'tdx.json');}function a36_0x1038(_0x539519,_0x523872){const _0x15b286=a36_0x15b2();return a36_0x1038=function(_0x1038be,_0x45ec10){_0x1038be=_0x1038be-0x97;let _0x948daf=_0x15b286[_0x1038be];return _0x948daf;},a36_0x1038(_0x539519,_0x523872);}function validateProfileName(_0x2ded87){const _0x2241ab=a36_0x1038;if(!/^[a-zA-Z0-9_-]+$/[_0x2241ab(0xa7)](_0x2ded87))throw new Error(_0x2241ab(0xbc)+_0x2ded87+_0x2241ab(0x9d));}function validateProfileConfig(_0x21d64b,_0x3b4725){const _0x2bb207=a36_0x1038;if(typeof _0x21d64b!=='object'||_0x21d64b===null)throw new Error(_0x2bb207(0xa2)+_0x3b4725+_0x2bb207(0xe3));const _0x16c514=[_0x2bb207(0xa9),_0x2bb207(0xd2),_0x2bb207(0xd6),'parent_segment',_0x2bb207(0xd3),_0x2bb207(0xc7)],_0x203326=_0x21d64b;for(const _0x23de59 of Object[_0x2bb207(0xdd)](_0x203326)){!_0x16c514[_0x2bb207(0x9c)](_0x23de59)&&console['warn'](_0x2bb207(0xe1)+_0x3b4725+_0x2bb207(0xdc)+_0x23de59+_0x2bb207(0xe5));}if(_0x203326[_0x2bb207(0xa9)]!==undefined&&typeof _0x203326[_0x2bb207(0xa9)]!==_0x2bb207(0xb6))throw new Error(_0x2bb207(0xa2)+_0x3b4725+_0x2bb207(0xa4));if(_0x203326[_0x2bb207(0xd2)]!==undefined&&typeof _0x203326[_0x2bb207(0xd2)]!==_0x2bb207(0xb6))throw new Error(_0x2bb207(0xa2)+_0x3b4725+'\x27:\x20\x27site\x27\x20must\x20be\x20a\x20string');if(_0x203326[_0x2bb207(0xd6)]!==undefined&&typeof _0x203326['database']!=='string')throw new Error('Profile\x20\x27'+_0x3b4725+_0x2bb207(0xbe));if(_0x203326[_0x2bb207(0xbf)]!==undefined&&typeof _0x203326[_0x2bb207(0xbf)]!==_0x2bb207(0xb6))throw new Error(_0x2bb207(0xa2)+_0x3b4725+'\x27:\x20\x27parent_segment\x27\x20must\x20be\x20a\x20string');if(_0x203326[_0x2bb207(0xd3)]!==undefined&&typeof _0x203326['llm_project']!==_0x2bb207(0xb6))throw new Error(_0x2bb207(0xa2)+_0x3b4725+_0x2bb207(0xac));if(_0x203326[_0x2bb207(0xc7)]!==undefined&&typeof _0x203326[_0x2bb207(0xc7)]!==_0x2bb207(0xb6))throw new Error('Profile\x20\x27'+_0x3b4725+'\x27:\x20\x27llm_agent\x27\x20must\x20be\x20a\x20string');return!![];}function loadProfilesFromTdxJson(_0x48624a,_0x31d79f){const _0x541dfa=a36_0x1038;if(!a36_0x519f72['existsSync'](_0x48624a))return[];try{const _0x161d0b=a36_0x519f72[_0x541dfa(0xc5)](_0x48624a,_0x541dfa(0xd8)),_0x5d417a=JSON[_0x541dfa(0x97)](_0x161d0b);if(!_0x5d417a['profiles']||typeof _0x5d417a['profiles']!==_0x541dfa(0x9a))return[];const _0x5c1474=[];for(const [_0x4d4fa6,_0x2a6c9a]of Object[_0x541dfa(0xe7)](_0x5d417a[_0x541dfa(0xda)])){try{validateProfileConfig(_0x2a6c9a,_0x4d4fa6);const _0x31ac96=getNewCredentialPath(_0x4d4fa6),_0x4cf4c1=getOldCredentialPath(_0x4d4fa6),_0x22adb8=a36_0x519f72[_0x541dfa(0xa5)](_0x31ac96)||a36_0x519f72[_0x541dfa(0xa5)](_0x4cf4c1);_0x5c1474[_0x541dfa(0xc0)]({'name':_0x4d4fa6,'config':_0x2a6c9a,'metadata':{'name':_0x4d4fa6,'createdAt':new Date()[_0x541dfa(0x9f)]()},'hasCredentials':_0x22adb8,'scope':_0x31d79f});}catch(_0x3f523b){_0x3f523b instanceof Error&&(console[_0x541dfa(0xbd)](_0x541dfa(0xb3)+_0x48624a+':'),console[_0x541dfa(0xbd)]('\x20\x20'+_0x3f523b['message']+'\x0a'));}}return _0x5c1474;}catch(_0x540d9f){return _0x540d9f instanceof SyntaxError?(console[_0x541dfa(0xbd)]('\x0aWarning:\x20Failed\x20to\x20parse\x20'+_0x48624a+':\x20Invalid\x20JSON\x20syntax'),console[_0x541dfa(0xbd)](_0x541dfa(0xba)+_0x540d9f['message']+'\x0a')):console[_0x541dfa(0xbd)]('\x0aWarning:\x20Failed\x20to\x20load\x20profiles\x20from\x20'+_0x48624a+':\x20'+_0x540d9f+'\x0a'),[];}}export function getNewCredentialPath(_0x2ec9fe){const _0xafac66=a36_0x1038;return a36_0x45c650[_0xafac66(0xb9)](getConfigDir(),_0xafac66(0xae)+_0x2ec9fe);}function getOldCredentialPath(_0x6449a6){const _0x3ebb49=a36_0x1038;return a36_0x45c650[_0x3ebb49(0xb9)](getProfilesDir(),_0x6449a6,_0x3ebb49(0xc8));}function loadProfilesFromTdxJsonFiles(){const _0x5b68d6=a36_0x1038,_0x66cab9=[],_0x8128aa=findProjectConfigPath();_0x8128aa&&_0x66cab9[_0x5b68d6(0xc0)](...loadProfilesFromTdxJson(_0x8128aa,_0x5b68d6(0xb7)));const _0x457cda=a36_0x45c650[_0x5b68d6(0xb9)](getConfigDir(),_0x5b68d6(0xb8));return _0x66cab9['push'](...loadProfilesFromTdxJson(_0x457cda,_0x5b68d6(0xaa))),_0x66cab9;}function loadProfilesFromDirectories(){const _0x3829d3=a36_0x1038,_0x225a44=getProfilesDir();if(!a36_0x519f72[_0x3829d3(0xa5)](_0x225a44))return[];try{return a36_0x519f72[_0x3829d3(0xaf)](_0x225a44,{'withFileTypes':!![]})[_0x3829d3(0xc9)](_0x5ae520=>_0x5ae520['isDirectory']())['map'](_0x1996f1=>_0x1996f1['name'])[_0x3829d3(0xc9)](_0x543a45=>{const _0x6e33c2=_0x3829d3,_0x416540=getProfileConfigPath(_0x543a45),_0x3b0937=getProfileEnvPath(_0x543a45);return a36_0x519f72[_0x6e33c2(0xa5)](_0x416540)||a36_0x519f72[_0x6e33c2(0xa5)](_0x3b0937);})[_0x3829d3(0xbb)](_0x4a6c03=>{const _0x22faeb=_0x3829d3,_0x579ebb=loadProfileFromDirectory(_0x4a6c03);if(_0x579ebb)return{..._0x579ebb,'scope':_0x22faeb(0xcc)};return null;})['filter'](_0x2c1bf3=>_0x2c1bf3!==null);}catch{return[];}}function loadProfileFromDirectory(_0x113a3a){const _0x50e3ba=a36_0x1038,_0x5ea105=getProfileConfigPath(_0x113a3a),_0x2d0aa1=getOldCredentialPath(_0x113a3a);if(!a36_0x519f72[_0x50e3ba(0xa5)](_0x5ea105)&&!a36_0x519f72[_0x50e3ba(0xa5)](_0x2d0aa1))return null;let _0x3245c2={},_0xc3e9d={'name':_0x113a3a,'createdAt':new Date()[_0x50e3ba(0x9f)]()};if(a36_0x519f72[_0x50e3ba(0xa5)](_0x5ea105))try{const _0x5b0120=a36_0x519f72[_0x50e3ba(0xc5)](_0x5ea105,'utf-8'),_0x391a33=JSON['parse'](_0x5b0120),{metadata:_0x39a5ed,..._0x5c0517}=_0x391a33;_0x3245c2=_0x5c0517,_0x39a5ed&&(_0xc3e9d=_0x39a5ed);}catch{}return{'name':_0x113a3a,'config':_0x3245c2,'metadata':_0xc3e9d,'hasCredentials':a36_0x519f72['existsSync'](_0x2d0aa1),'scope':'directory'};}export function listProfiles(){const _0x57ce5c=a36_0x1038,_0x258eec=loadProfilesFromTdxJsonFiles(),_0x5d673b=loadProfilesFromDirectories();if(_0x5d673b[_0x57ce5c(0xd7)]>0x0){const _0x5ee70f=_0x5d673b[_0x57ce5c(0xbb)](_0x8ee5f4=>_0x8ee5f4['name'])[_0x57ce5c(0xb9)](',\x20'),_0x34cb8c=getConfigDir();console['warn'](_0x57ce5c(0xd9)+_0x5ee70f),console[_0x57ce5c(0xbd)](_0x57ce5c(0xde)),console['warn'](_0x57ce5c(0xcd)+a36_0x45c650['join'](_0x34cb8c,_0x57ce5c(0xb8))),console[_0x57ce5c(0xbd)](_0x57ce5c(0x98)),console[_0x57ce5c(0xbd)]('\x20\x203.\x20Move\x20credentials:\x20mv\x20~/.config/tdx/profiles/<name>/.env\x20~/.config/tdx/.env.<name>\x0a');}const _0x43972f=[..._0x258eec,..._0x5d673b],_0xbb97b=new Map();for(const _0x1947b9 of _0x43972f){!_0xbb97b['has'](_0x1947b9['name'])&&_0xbb97b[_0x57ce5c(0xcb)](_0x1947b9['name'],_0x1947b9);}return Array['from'](_0xbb97b[_0x57ce5c(0xcf)]())[_0x57ce5c(0xe6)]((_0x48d50d,_0x3fcfd3)=>_0x48d50d[_0x57ce5c(0xd0)][_0x57ce5c(0xd5)](_0x3fcfd3[_0x57ce5c(0xd0)]));}function a36_0x15b2(){const _0x1bf63f=['test','36678UDEQyI','description','user','1995093Oqbprc','\x27:\x20\x27llm_project\x27\x20must\x20be\x20a\x20string','stringify','.env.','readdirSync','Then\x20define\x20profiles\x20in\x20~/.config/tdx/tdx.json\x0a','find','1397fyJRMM','\x0aWarning:\x20Skipping\x20invalid\x20profile\x20in\x20','287Fdaiux','rmSync','string','local','tdx.json','join','Error:\x20','map','Invalid\x20profile\x20name:\x20','warn','\x27:\x20\x27database\x27\x20must\x20be\x20a\x20string','parent_segment','push','Profile\x20','842748oYSnoY','\x20already\x20exists','writeFileSync','readFileSync','api_key','llm_agent','.env','filter','\x22\x20\x22','set','directory','\x20\x201.\x20Edit:\x20','1436wsWHcJ','values','name','TD_API_KEY','site','llm_project','profile','localeCompare','database','length','utf-8','\x0aWarning:\x20Profiles\x20in\x20directories\x20are\x20deprecated:\x20','profiles','1138320RAMTqO','\x27:\x20unknown\x20config\x20key\x20\x27','keys','Please\x20migrate\x20to\x20~/.config/tdx/tdx.json:','63250MHWLAd','8DWeowv','Warning:\x20Profile\x20\x27','apiKey','\x27:\x20config\x20must\x20be\x20an\x20object','API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20profile\x20configuration.\x20Use\x20.env\x20file\x20instead.','\x27\x20will\x20be\x20ignored','sort','entries','347821mjlQnP','parse','\x20\x202.\x20Add\x20profiles\x20under\x20a\x20\x22profiles\x22\x20key\x20(see\x20\x27tdx\x20profiles\x27\x20for\x20current\x20config)','lastUsed','object','metadata','includes','.\x20Must\x20contain\x20only\x20alphanumeric\x20characters,\x20dash,\x20and\x20underscore.','4130dXiqSU','toISOString','\x0aWarning:\x20Using\x20deprecated\x20credential\x20location\x20for\x20profile\x20\x27','\x20does\x20not\x20exist','Profile\x20\x27','To\x20migrate:','\x27:\x20\x27description\x27\x20must\x20be\x20a\x20string','existsSync','some'];a36_0x15b2=function(){return _0x1bf63f;};return a36_0x15b2();}export function profileExists(_0x49befd){const _0x108079=a36_0x1038,_0x6cf622=listProfiles();return _0x6cf622[_0x108079(0xa6)](_0x3e9e85=>_0x3e9e85[_0x108079(0xd0)]===_0x49befd);}export function loadProfile(_0x22a0e4){const _0x167034=a36_0x1038;validateProfileName(_0x22a0e4);const _0x5c91dc=listProfiles(),_0x59087d=_0x5c91dc[_0x167034(0xb1)](_0x6ac2d4=>_0x6ac2d4['name']===_0x22a0e4);return _0x59087d||null;}export function saveProfile(_0x15efad,_0x4caf79,_0x72b4c=![]){const _0x1b3c0e=a36_0x1038;validateProfileName(_0x15efad);const _0x365a0c=getProfileDir(_0x15efad),_0x12f8d2=getProfileConfigPath(_0x15efad);createSecureDirectory(_0x365a0c);let _0x362c3b;const _0xf9f0a8=loadProfile(_0x15efad);_0xf9f0a8?(_0x362c3b=_0xf9f0a8[_0x1b3c0e(0x9b)],_0x72b4c&&(_0x362c3b[_0x1b3c0e(0x99)]=new Date()[_0x1b3c0e(0x9f)]())):_0x362c3b={'name':_0x15efad,'createdAt':new Date()['toISOString']()};const _0x38d582=JSON[_0x1b3c0e(0xad)](_0x4caf79);if(_0x38d582[_0x1b3c0e(0x9c)](_0x1b3c0e(0xd1))||_0x38d582[_0x1b3c0e(0x9c)](_0x1b3c0e(0xe2))||_0x38d582[_0x1b3c0e(0x9c)](_0x1b3c0e(0xc6)))throw new Error(_0x1b3c0e(0xe4));const _0x2d147c={..._0x4caf79,'metadata':_0x362c3b};a36_0x519f72[_0x1b3c0e(0xc4)](_0x12f8d2,JSON['stringify'](_0x2d147c,null,0x2));}export function deleteProfile(_0x1bb49f){const _0x5284d6=a36_0x1038;validateProfileName(_0x1bb49f);const _0x3d1a43=getProfileDir(_0x1bb49f);if(!a36_0x519f72['existsSync'](_0x3d1a43))throw new Error(_0x5284d6(0xc1)+_0x1bb49f+_0x5284d6(0xa1));a36_0x519f72[_0x5284d6(0xb5)](_0x3d1a43,{'recursive':!![],'force':!![]});}export function getActiveProfile(){const _0x3f0d5a=a36_0x1038,_0x32d5d5=getGlobalConfigPath();if(!a36_0x519f72[_0x3f0d5a(0xa5)](_0x32d5d5))return null;try{const _0x788c99=a36_0x519f72[_0x3f0d5a(0xc5)](_0x32d5d5,_0x3f0d5a(0xd8)),_0x5ec531=JSON[_0x3f0d5a(0x97)](_0x788c99);return _0x5ec531[_0x3f0d5a(0xd4)]||null;}catch{return null;}}export function createProfile(_0x5e0218,_0x5b7be8){const _0x58bef5=a36_0x1038;validateProfileName(_0x5e0218);if(profileExists(_0x5e0218))throw new Error(_0x58bef5(0xc1)+_0x5e0218+_0x58bef5(0xc3));saveProfile(_0x5e0218,_0x5b7be8);}export function saveProfileCredentials(_0x14f22e,_0x37aebc){const _0x39576a=a36_0x1038;validateProfileName(_0x14f22e);if(!profileExists(_0x14f22e))throw new Error('Profile\x20'+_0x14f22e+_0x39576a(0xa1));const _0x3b7931=getNewCredentialPath(_0x14f22e);writeSecureFile(_0x3b7931,_0x37aebc);}export function loadProfileCredentials(_0x5f270e){const _0x1d4881=a36_0x1038;validateProfileName(_0x5f270e);const _0x34968b=getNewCredentialPath(_0x5f270e);if(a36_0x519f72['existsSync'](_0x34968b))try{return a36_0x519f72[_0x1d4881(0xc5)](_0x34968b,_0x1d4881(0xd8));}catch{}const _0x4b43f7=getOldCredentialPath(_0x5f270e);if(a36_0x519f72[_0x1d4881(0xa5)](_0x4b43f7)){console['warn'](_0x1d4881(0xa0)+_0x5f270e+'\x27'),console[_0x1d4881(0xbd)](_0x1d4881(0xa3)),console[_0x1d4881(0xbd)]('\x20\x20mv\x20\x22'+_0x4b43f7+_0x1d4881(0xca)+_0x34968b+'\x22'),console['warn'](_0x1d4881(0xb0));try{return a36_0x519f72[_0x1d4881(0xc5)](_0x4b43f7,_0x1d4881(0xd8));}catch{return null;}}return null;}
1
+ (function(_0x1fd10e,_0x7be02c){const _0x370b6a=a36_0x2b18,_0x233303=_0x1fd10e();while(!![]){try{const _0x5eff9c=parseInt(_0x370b6a(0x98))/0x1*(parseInt(_0x370b6a(0x8b))/0x2)+parseInt(_0x370b6a(0xcf))/0x3+-parseInt(_0x370b6a(0xb2))/0x4+parseInt(_0x370b6a(0xc7))/0x5*(-parseInt(_0x370b6a(0xa6))/0x6)+parseInt(_0x370b6a(0xcc))/0x7+-parseInt(_0x370b6a(0x93))/0x8*(-parseInt(_0x370b6a(0xc4))/0x9)+parseInt(_0x370b6a(0xa1))/0xa;if(_0x5eff9c===_0x7be02c)break;else _0x233303['push'](_0x233303['shift']());}catch(_0x4f4016){_0x233303['push'](_0x233303['shift']());}}}(a36_0x2197,0x73ea1));import*as a36_0x4f8319 from'node:fs';import*as a36_0x13522c from'node:path';import{getConfigDir}from'./config.js';import{createSecureDirectory,writeSecureFile}from'../utils/file-permissions.js';import{findProjectConfigPath}from'./project-config.js';export function getProfileParams(_0x16fe8e){const _0x17b0f8=a36_0x2b18,_0x2d57df={};if(!_0x16fe8e)return _0x2d57df;for(const [_0xf7e4ff,_0x5c0a71]of Object[_0x17b0f8(0xa4)](_0x16fe8e)){_0xf7e4ff!==_0x17b0f8(0xad)&&_0x5c0a71!==undefined&&(_0x2d57df[_0xf7e4ff]=_0x5c0a71);}return _0x2d57df;}export function getProfilesDir(){const _0x217168=a36_0x2b18;return a36_0x13522c['join'](getConfigDir(),_0x217168(0xb4));}function getProfileDir(_0x3e370c){const _0x38bd0c=a36_0x2b18;return a36_0x13522c[_0x38bd0c(0xbd)](getProfilesDir(),_0x3e370c);}function getProfileConfigPath(_0x1355f4){const _0x5a581c=a36_0x2b18;return a36_0x13522c[_0x5a581c(0xbd)](getProfileDir(_0x1355f4),_0x5a581c(0x8c));}function getProfileEnvPath(_0x4dcf9f){const _0xe7989c=a36_0x2b18;return a36_0x13522c[_0xe7989c(0xbd)](getProfileDir(_0x4dcf9f),_0xe7989c(0xa3));}function getGlobalConfigPath(){const _0x22ccb1=a36_0x2b18;return a36_0x13522c[_0x22ccb1(0xbd)](getConfigDir(),_0x22ccb1(0x8c));}function validateProfileName(_0x5a9cdd){const _0x1b1ce2=a36_0x2b18;if(!/^[a-zA-Z0-9_-]+$/[_0x1b1ce2(0xa5)](_0x5a9cdd))throw new Error(_0x1b1ce2(0xd2)+_0x5a9cdd+_0x1b1ce2(0x9c));}function validateProfileConfig(_0x36f996,_0x41c7d2){const _0x242735=a36_0x2b18;if(typeof _0x36f996!==_0x242735(0x88)||_0x36f996===null)throw new Error(_0x242735(0xd0)+_0x41c7d2+_0x242735(0x97));const _0x17f27b=[_0x242735(0xad),'site','database','parent_segment',_0x242735(0x9e),'llm_agent'],_0x240b5e=_0x36f996;for(const _0xca30d6 of Object['keys'](_0x240b5e)){!_0x17f27b[_0x242735(0xa0)](_0xca30d6)&&console[_0x242735(0xbe)]('Warning:\x20Profile\x20\x27'+_0x41c7d2+_0x242735(0xa2)+_0xca30d6+_0x242735(0xc1));}if(_0x240b5e['description']!==undefined&&typeof _0x240b5e[_0x242735(0xad)]!==_0x242735(0xa9))throw new Error(_0x242735(0xd0)+_0x41c7d2+_0x242735(0x91));if(_0x240b5e[_0x242735(0xbb)]!==undefined&&typeof _0x240b5e[_0x242735(0xbb)]!==_0x242735(0xa9))throw new Error(_0x242735(0xd0)+_0x41c7d2+_0x242735(0x99));if(_0x240b5e[_0x242735(0xa7)]!==undefined&&typeof _0x240b5e['database']!==_0x242735(0xa9))throw new Error(_0x242735(0xd0)+_0x41c7d2+_0x242735(0x92));if(_0x240b5e[_0x242735(0x87)]!==undefined&&typeof _0x240b5e['parent_segment']!==_0x242735(0xa9))throw new Error(_0x242735(0xd0)+_0x41c7d2+_0x242735(0xb1));if(_0x240b5e[_0x242735(0x9e)]!==undefined&&typeof _0x240b5e[_0x242735(0x9e)]!=='string')throw new Error('Profile\x20\x27'+_0x41c7d2+'\x27:\x20\x27llm_project\x27\x20must\x20be\x20a\x20string');if(_0x240b5e['llm_agent']!==undefined&&typeof _0x240b5e['llm_agent']!==_0x242735(0xa9))throw new Error(_0x242735(0xd0)+_0x41c7d2+_0x242735(0x90));return!![];}function loadProfilesFromTdxJson(_0x57ad3c,_0x3ada0b){const _0x5d4143=a36_0x2b18;if(!a36_0x4f8319['existsSync'](_0x57ad3c))return[];try{const _0x1147b5=a36_0x4f8319[_0x5d4143(0x96)](_0x57ad3c,'utf-8'),_0x2b2b4f=JSON['parse'](_0x1147b5);if(!_0x2b2b4f['profiles']||typeof _0x2b2b4f['profiles']!=='object')return[];const _0x1591fa=[];for(const [_0xf48e5,_0x55c7d0]of Object['entries'](_0x2b2b4f[_0x5d4143(0xb4)])){try{validateProfileConfig(_0x55c7d0,_0xf48e5);const _0x122896=getNewCredentialPath(_0xf48e5),_0x327c33=getOldCredentialPath(_0xf48e5),_0xe26a6d=a36_0x4f8319[_0x5d4143(0xc2)](_0x122896)||a36_0x4f8319[_0x5d4143(0xc2)](_0x327c33);_0x1591fa[_0x5d4143(0xc0)]({'name':_0xf48e5,'config':_0x55c7d0,'metadata':{'name':_0xf48e5,'createdAt':new Date()[_0x5d4143(0xaf)]()},'hasCredentials':_0xe26a6d,'scope':_0x3ada0b});}catch(_0x2e8892){_0x2e8892 instanceof Error&&(console[_0x5d4143(0xbe)](_0x5d4143(0x8d)+_0x57ad3c+':'),console[_0x5d4143(0xbe)]('\x20\x20'+_0x2e8892['message']+'\x0a'));}}return _0x1591fa;}catch(_0x28e1b8){return _0x28e1b8 instanceof SyntaxError?(console[_0x5d4143(0xbe)](_0x5d4143(0xcd)+_0x57ad3c+_0x5d4143(0xce)),console[_0x5d4143(0xbe)](_0x5d4143(0x9f)+_0x28e1b8[_0x5d4143(0x9a)]+'\x0a')):console[_0x5d4143(0xbe)](_0x5d4143(0xc8)+_0x57ad3c+':\x20'+_0x28e1b8+'\x0a'),[];}}function a36_0x2b18(_0x26211f,_0x1afdb4){const _0x2197b4=a36_0x2197();return a36_0x2b18=function(_0x2b186f,_0x1d55a8){_0x2b186f=_0x2b186f-0x83;let _0x4b4626=_0x2197b4[_0x2b186f];return _0x4b4626;},a36_0x2b18(_0x26211f,_0x1afdb4);}export function getNewCredentialPath(_0x50022d){const _0x5e2703=a36_0x2b18;return a36_0x13522c['join'](getConfigDir(),_0x5e2703(0xb7)+_0x50022d);}function getOldCredentialPath(_0x5a8518){const _0x28e5ca=a36_0x2b18;return a36_0x13522c['join'](getProfilesDir(),_0x5a8518,_0x28e5ca(0xa3));}function loadProfilesFromTdxJsonFiles(){const _0x473a53=a36_0x2b18,_0x2db69e=[],_0x51e406=findProjectConfigPath();_0x51e406&&_0x2db69e[_0x473a53(0xc0)](...loadProfilesFromTdxJson(_0x51e406,'local'));const _0x2a3c4e=a36_0x13522c[_0x473a53(0xbd)](getConfigDir(),_0x473a53(0x8c));return _0x2db69e[_0x473a53(0xc0)](...loadProfilesFromTdxJson(_0x2a3c4e,_0x473a53(0xc9))),_0x2db69e;}function loadProfilesFromDirectories(){const _0xd9e3d2=a36_0x2b18,_0x2d189a=getProfilesDir();if(!a36_0x4f8319[_0xd9e3d2(0xc2)](_0x2d189a))return[];try{return a36_0x4f8319[_0xd9e3d2(0xae)](_0x2d189a,{'withFileTypes':!![]})[_0xd9e3d2(0xa8)](_0x18d2ce=>_0x18d2ce[_0xd9e3d2(0xb5)]())[_0xd9e3d2(0x84)](_0x4e0880=>_0x4e0880[_0xd9e3d2(0x89)])[_0xd9e3d2(0xa8)](_0x4a6bb0=>{const _0x3bbcbf=_0xd9e3d2,_0x5b79cd=getProfileConfigPath(_0x4a6bb0),_0x2e6eb6=getProfileEnvPath(_0x4a6bb0);return a36_0x4f8319[_0x3bbcbf(0xc2)](_0x5b79cd)||a36_0x4f8319['existsSync'](_0x2e6eb6);})[_0xd9e3d2(0x84)](_0x32c8dd=>{const _0x14633f=_0xd9e3d2,_0x18c11b=loadProfileFromDirectory(_0x32c8dd);if(_0x18c11b)return{..._0x18c11b,'scope':_0x14633f(0xb9)};return null;})[_0xd9e3d2(0xa8)](_0x451023=>_0x451023!==null);}catch{return[];}}function loadProfileFromDirectory(_0x14ccc3){const _0x49ea2a=a36_0x2b18,_0x75528b=getProfileConfigPath(_0x14ccc3),_0x35370c=getOldCredentialPath(_0x14ccc3);if(!a36_0x4f8319[_0x49ea2a(0xc2)](_0x75528b)&&!a36_0x4f8319[_0x49ea2a(0xc2)](_0x35370c))return null;let _0x481bc7={},_0x3505ae={'name':_0x14ccc3,'createdAt':new Date()['toISOString']()};if(a36_0x4f8319[_0x49ea2a(0xc2)](_0x75528b))try{const _0xc1ae75=a36_0x4f8319[_0x49ea2a(0x96)](_0x75528b,'utf-8'),_0x12285d=JSON['parse'](_0xc1ae75),{metadata:_0x1bf315,..._0x465773}=_0x12285d;_0x481bc7=_0x465773,_0x1bf315&&(_0x3505ae=_0x1bf315);}catch{}return{'name':_0x14ccc3,'config':_0x481bc7,'metadata':_0x3505ae,'hasCredentials':a36_0x4f8319[_0x49ea2a(0xc2)](_0x35370c),'scope':_0x49ea2a(0xb9)};}export function listProfiles(){const _0x382bec=a36_0x2b18,_0x3e893a=loadProfilesFromTdxJsonFiles(),_0x10b4e2=loadProfilesFromDirectories();if(_0x10b4e2[_0x382bec(0xcb)]>0x0){const _0x5380e5=_0x10b4e2['map'](_0x4251f1=>_0x4251f1[_0x382bec(0x89)])[_0x382bec(0xbd)](',\x20'),_0x377000=getConfigDir();console['warn'](_0x382bec(0xb3)+_0x5380e5),console[_0x382bec(0xbe)]('Please\x20migrate\x20to\x20~/.config/tdx/tdx.json:'),console['warn'](_0x382bec(0x86)+a36_0x13522c[_0x382bec(0xbd)](_0x377000,_0x382bec(0x8c))),console['warn'](_0x382bec(0xd1)),console[_0x382bec(0xbe)](_0x382bec(0xc5));}const _0x1f2171=[..._0x3e893a,..._0x10b4e2],_0x17649b=new Map();for(const _0x17a8f2 of _0x1f2171){!_0x17649b[_0x382bec(0x95)](_0x17a8f2[_0x382bec(0x89)])&&_0x17649b['set'](_0x17a8f2[_0x382bec(0x89)],_0x17a8f2);}return Array['from'](_0x17649b[_0x382bec(0x9d)]())[_0x382bec(0xbf)]((_0x5f57e1,_0x2f307a)=>_0x5f57e1[_0x382bec(0x89)][_0x382bec(0xbc)](_0x2f307a[_0x382bec(0x89)]));}function a36_0x2197(){const _0x460301=['131MGjTsz','\x27:\x20\x27site\x27\x20must\x20be\x20a\x20string','message','Then\x20define\x20profiles\x20in\x20~/.config/tdx/tdx.json\x0a','.\x20Must\x20contain\x20only\x20alphanumeric\x20characters,\x20dash,\x20and\x20underscore.','values','llm_project','Error:\x20','includes','3677090wkzYii','\x27:\x20unknown\x20config\x20key\x20\x27','.env','entries','test','131610UdhRhb','database','filter','string','\x22\x20\x22','stringify','TD_API_KEY','description','readdirSync','toISOString','utf-8','\x27:\x20\x27parent_segment\x27\x20must\x20be\x20a\x20string','411024HMGqMF','\x0aWarning:\x20Profiles\x20in\x20directories\x20are\x20deprecated:\x20','profiles','isDirectory','rmSync','.env.','writeFileSync','directory','\x20does\x20not\x20exist','site','localeCompare','join','warn','sort','push','\x27\x20will\x20be\x20ignored','existsSync','\x20\x20mv\x20\x22','567NUdSZl','\x20\x203.\x20Move\x20credentials:\x20mv\x20~/.config/tdx/profiles/<name>/.env\x20~/.config/tdx/.env.<name>\x0a','apiKey','205fzPlag','\x0aWarning:\x20Failed\x20to\x20load\x20profiles\x20from\x20','user','api_key','length','1738688cgYpsb','\x0aWarning:\x20Failed\x20to\x20parse\x20',':\x20Invalid\x20JSON\x20syntax','38106nsVxnH','Profile\x20\x27','\x20\x202.\x20Add\x20profiles\x20under\x20a\x20\x22profiles\x22\x20key\x20(see\x20\x27tdx\x20profiles\x27\x20for\x20current\x20config)','Invalid\x20profile\x20name:\x20','find','map','Profile\x20','\x20\x201.\x20Edit:\x20','parent_segment','object','name','metadata','6290JyDeNl','tdx.json','\x0aWarning:\x20Skipping\x20invalid\x20profile\x20in\x20','To\x20migrate:','profile','\x27:\x20\x27llm_agent\x27\x20must\x20be\x20a\x20string','\x27:\x20\x27description\x27\x20must\x20be\x20a\x20string','\x27:\x20\x27database\x27\x20must\x20be\x20a\x20string','55376sgPakU','API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20profile\x20configuration.\x20Use\x20.env\x20file\x20instead.','has','readFileSync','\x27:\x20config\x20must\x20be\x20an\x20object'];a36_0x2197=function(){return _0x460301;};return a36_0x2197();}export function profileExists(_0xcca252){const _0x538c12=listProfiles();return _0x538c12['some'](_0x2b96cd=>_0x2b96cd['name']===_0xcca252);}export function loadProfile(_0xcc1c82){const _0x4f0bc5=a36_0x2b18;validateProfileName(_0xcc1c82);const _0x441a2b=listProfiles(),_0x11f3a4=_0x441a2b[_0x4f0bc5(0x83)](_0xc19b73=>_0xc19b73[_0x4f0bc5(0x89)]===_0xcc1c82);return _0x11f3a4||null;}export function saveProfile(_0x5740dc,_0x1a488f,_0x2618f2=![]){const _0xdc5656=a36_0x2b18;validateProfileName(_0x5740dc);const _0x2e063d=getProfileDir(_0x5740dc),_0x5e3a5e=getProfileConfigPath(_0x5740dc);createSecureDirectory(_0x2e063d);let _0x547312;const _0x2ebcf2=loadProfile(_0x5740dc);_0x2ebcf2?(_0x547312=_0x2ebcf2[_0xdc5656(0x8a)],_0x2618f2&&(_0x547312['lastUsed']=new Date()[_0xdc5656(0xaf)]())):_0x547312={'name':_0x5740dc,'createdAt':new Date()[_0xdc5656(0xaf)]()};const _0x3305a7=JSON['stringify'](_0x1a488f);if(_0x3305a7[_0xdc5656(0xa0)](_0xdc5656(0xac))||_0x3305a7[_0xdc5656(0xa0)](_0xdc5656(0xc6))||_0x3305a7['includes'](_0xdc5656(0xca)))throw new Error(_0xdc5656(0x94));const _0x403347={..._0x1a488f,'metadata':_0x547312};a36_0x4f8319[_0xdc5656(0xb8)](_0x5e3a5e,JSON[_0xdc5656(0xab)](_0x403347,null,0x2));}export function deleteProfile(_0x498d0f){const _0x13a3e3=a36_0x2b18;validateProfileName(_0x498d0f);const _0x34ec53=getProfileDir(_0x498d0f);if(!a36_0x4f8319['existsSync'](_0x34ec53))throw new Error(_0x13a3e3(0x85)+_0x498d0f+_0x13a3e3(0xba));a36_0x4f8319[_0x13a3e3(0xb6)](_0x34ec53,{'recursive':!![],'force':!![]});}export function getActiveProfile(){const _0x394668=a36_0x2b18,_0x271891=getGlobalConfigPath();if(!a36_0x4f8319[_0x394668(0xc2)](_0x271891))return null;try{const _0x4f4829=a36_0x4f8319[_0x394668(0x96)](_0x271891,'utf-8'),_0x4e2626=JSON['parse'](_0x4f4829);return _0x4e2626[_0x394668(0x8f)]||null;}catch{return null;}}export function createProfile(_0x28ae8b,_0x475218){const _0x510450=a36_0x2b18;validateProfileName(_0x28ae8b);if(profileExists(_0x28ae8b))throw new Error(_0x510450(0x85)+_0x28ae8b+'\x20already\x20exists');saveProfile(_0x28ae8b,_0x475218);}export function saveProfileCredentials(_0x340279,_0x8df804){const _0x156ea2=a36_0x2b18;validateProfileName(_0x340279);if(!profileExists(_0x340279))throw new Error(_0x156ea2(0x85)+_0x340279+'\x20does\x20not\x20exist');const _0x1422c3=getNewCredentialPath(_0x340279);writeSecureFile(_0x1422c3,_0x8df804);}export function loadProfileCredentials(_0x35e511){const _0xc6273d=a36_0x2b18;validateProfileName(_0x35e511);const _0x30f2c8=getNewCredentialPath(_0x35e511);if(a36_0x4f8319[_0xc6273d(0xc2)](_0x30f2c8))try{return a36_0x4f8319['readFileSync'](_0x30f2c8,_0xc6273d(0xb0));}catch{}const _0x2f1f94=getOldCredentialPath(_0x35e511);if(a36_0x4f8319['existsSync'](_0x2f1f94)){console[_0xc6273d(0xbe)]('\x0aWarning:\x20Using\x20deprecated\x20credential\x20location\x20for\x20profile\x20\x27'+_0x35e511+'\x27'),console[_0xc6273d(0xbe)](_0xc6273d(0x8e)),console[_0xc6273d(0xbe)](_0xc6273d(0xc3)+_0x2f1f94+_0xc6273d(0xaa)+_0x30f2c8+'\x22'),console['warn'](_0xc6273d(0x9b));try{return a36_0x4f8319[_0xc6273d(0x96)](_0x2f1f94,_0xc6273d(0xb0));}catch{return null;}}return null;}
@@ -1 +1 @@
1
- const a37_0x2e8ae4=a37_0x224e;function a37_0x5f3d(){const _0x3110fe=['code','1WdWOeM','existsSync','15728dZlwyY','TD_API_KEY','API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20project\x20configuration.\x20Use\x20.env\x20files\x20instead.','Active\x20profile\x20is\x20set\x20in\x20~/.config/tdx/tdx.json','join','utf-8','3189852aWIxhh','Security\x20error:\x20API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20project\x20config\x20(','cwd','46472426Lrrbpz','includes','4326196DakKFF','Failed\x20to\x20load\x20project\x20config\x20from\x20','readFileSync','apiKey','stringify','\x27profile\x27\x20should\x20not\x20be\x20set\x20in\x20project\x20config.\x20Use\x20\x27tdx\x20profile\x20use\x27\x20instead.','74846bvLRLj','dirname','Warning:\x20\x27profile\x27\x20field\x20in\x20','api_key','4581CtoDbz','5KtAZmx','tdx.json','Use\x20~/.config/tdx/.env\x20or\x20profile\x20.env\x20files\x20instead.','6353676bgICet','4YtjWPy','9940340MOoMnw','writeFileSync','profile'];a37_0x5f3d=function(){return _0x3110fe;};return a37_0x5f3d();}(function(_0x2641c3,_0x39d5fb){const _0xe4fed8=a37_0x224e,_0x5a0c49=_0x2641c3();while(!![]){try{const _0x3a82e5=-parseInt(_0xe4fed8(0x9f))/0x1*(-parseInt(_0xe4fed8(0x91))/0x2)+-parseInt(_0xe4fed8(0x86))/0x3*(-parseInt(_0xe4fed8(0x9a))/0x4)+-parseInt(_0xe4fed8(0x96))/0x5*(-parseInt(_0xe4fed8(0x99))/0x6)+parseInt(_0xe4fed8(0x8b))/0x7+parseInt(_0xe4fed8(0x80))/0x8*(parseInt(_0xe4fed8(0x95))/0x9)+parseInt(_0xe4fed8(0x9b))/0xa+-parseInt(_0xe4fed8(0x89))/0xb;if(_0x3a82e5===_0x39d5fb)break;else _0x5a0c49['push'](_0x5a0c49['shift']());}catch(_0x1d57f1){_0x5a0c49['push'](_0x5a0c49['shift']());}}}(a37_0x5f3d,0x85b3b));import*as a37_0x14ac5b from'node:fs';import*as a37_0x10ba28 from'node:path';const PROJECT_CONFIG_FILENAME=a37_0x2e8ae4(0x97);export function findProjectConfigPath(_0x475f49){const _0x31ffaa=a37_0x2e8ae4;let _0x2947ef=_0x475f49||process['cwd']();while(!![]){const _0x1ef33f=a37_0x10ba28['join'](_0x2947ef,PROJECT_CONFIG_FILENAME);if(a37_0x14ac5b[_0x31ffaa(0xa0)](_0x1ef33f))return _0x1ef33f;const _0x560849=a37_0x10ba28[_0x31ffaa(0x92)](_0x2947ef);if(_0x560849===_0x2947ef)return null;_0x2947ef=_0x560849;}}function a37_0x224e(_0x540f06,_0x470374){const _0x5f3de8=a37_0x5f3d();return a37_0x224e=function(_0x224ed3,_0x4e5c9c){_0x224ed3=_0x224ed3-0x80;let _0x4d7b9c=_0x5f3de8[_0x224ed3];return _0x4d7b9c;},a37_0x224e(_0x540f06,_0x470374);}export function loadProjectConfig(_0x2e4309){const _0x2635ef=a37_0x2e8ae4,_0x58c93e=findProjectConfigPath(_0x2e4309);if(!_0x58c93e)return null;try{const _0x380325=a37_0x14ac5b[_0x2635ef(0x8d)](_0x58c93e,_0x2635ef(0x85)),_0x17bc5e=JSON['parse'](_0x380325),_0x1eb5d7=JSON[_0x2635ef(0x8f)](_0x17bc5e);if(_0x1eb5d7[_0x2635ef(0x8a)](_0x2635ef(0x81))||_0x1eb5d7[_0x2635ef(0x8a)](_0x2635ef(0x8e))||_0x1eb5d7['includes'](_0x2635ef(0x94)))throw new Error(_0x2635ef(0x87)+_0x58c93e+').\x20'+_0x2635ef(0x98));const {metadata:_0xde7cda,profile:_0x1202f,..._0x45b02b}=_0x17bc5e;return _0x1202f&&console['warn'](_0x2635ef(0x93)+_0x58c93e+'\x20is\x20ignored.\x20'+_0x2635ef(0x83)),_0x45b02b;}catch(_0x139ebe){if(_0x139ebe instanceof Error&&_0x2635ef(0x9e)in _0x139ebe&&_0x139ebe[_0x2635ef(0x9e)]==='ENOENT')return null;throw new Error(_0x2635ef(0x8c)+_0x58c93e+':\x20'+_0x139ebe);}}export function saveProjectConfig(_0x272342,_0x33ef9a){const _0x345c15=a37_0x2e8ae4,_0x5bc1c7=_0x33ef9a||process[_0x345c15(0x88)](),_0x4e24eb=a37_0x10ba28[_0x345c15(0x84)](_0x5bc1c7,PROJECT_CONFIG_FILENAME),_0x3eeb54=JSON['stringify'](_0x272342);if(_0x3eeb54['includes']('TD_API_KEY')||_0x3eeb54['includes'](_0x345c15(0x8e))||_0x3eeb54[_0x345c15(0x8a)](_0x345c15(0x94)))throw new Error(_0x345c15(0x82));if(_0x345c15(0x9d)in _0x272342)throw new Error(_0x345c15(0x90));a37_0x14ac5b[_0x345c15(0x9c)](_0x4e24eb,JSON[_0x345c15(0x8f)](_0x272342,null,0x2));}export function hasProjectConfig(_0x30b926){return findProjectConfigPath(_0x30b926)!==null;}export function getProjectRoot(_0xa16503){const _0x1c8e5d=a37_0x2e8ae4,_0x14dea3=findProjectConfigPath(_0xa16503);return _0x14dea3?a37_0x10ba28[_0x1c8e5d(0x92)](_0x14dea3):null;}
1
+ function a37_0x1428(){const _0x3ea60d=['84iuGZQQ','writeFileSync','19904wbDmdH','existsSync','25907130VBjOst','API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20project\x20configuration.\x20Use\x20.env\x20files\x20instead.',').\x20','parse','warn','176980TXXhMX','code','Warning:\x20\x27profile\x27\x20field\x20in\x20','cwd','join','2528734ZiTrJi','apiKey','Security\x20error:\x20API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20project\x20config\x20(','api_key','93RfAkxY','includes','Active\x20profile\x20is\x20set\x20in\x20~/.config/tdx/tdx.json','stringify','339695mRPsXN','ENOENT','1559245epByuR','Use\x20~/.config/tdx/.env\x20or\x20profile\x20.env\x20files\x20instead.','3530592fZQxLB','profile','TD_API_KEY','dirname','30gDBTXn','Failed\x20to\x20load\x20project\x20config\x20from\x20','\x20is\x20ignored.\x20'];a37_0x1428=function(){return _0x3ea60d;};return a37_0x1428();}(function(_0x2a8720,_0x334c84){const _0x3345c7=a37_0x31e7,_0x259ed5=_0x2a8720();while(!![]){try{const _0x117273=parseInt(_0x3345c7(0xe7))/0x1+parseInt(_0x3345c7(0x100))/0x2+parseInt(_0x3345c7(0xe3))/0x3*(-parseInt(_0x3345c7(0xfb))/0x4)+parseInt(_0x3345c7(0xe9))/0x5*(-parseInt(_0x3345c7(0xef))/0x6)+parseInt(_0x3345c7(0xf2))/0x7*(parseInt(_0x3345c7(0xf4))/0x8)+-parseInt(_0x3345c7(0xeb))/0x9+parseInt(_0x3345c7(0xf6))/0xa;if(_0x117273===_0x334c84)break;else _0x259ed5['push'](_0x259ed5['shift']());}catch(_0x41bdb5){_0x259ed5['push'](_0x259ed5['shift']());}}}(a37_0x1428,0xdc17f));import*as a37_0x2cf9eb from'node:fs';import*as a37_0x20b8e6 from'node:path';const PROJECT_CONFIG_FILENAME='tdx.json';export function findProjectConfigPath(_0x33bbdd){const _0x34dcf9=a37_0x31e7;let _0x386893=_0x33bbdd||process[_0x34dcf9(0xfe)]();while(!![]){const _0x1dc0ff=a37_0x20b8e6[_0x34dcf9(0xff)](_0x386893,PROJECT_CONFIG_FILENAME);if(a37_0x2cf9eb[_0x34dcf9(0xf5)](_0x1dc0ff))return _0x1dc0ff;const _0x2639cd=a37_0x20b8e6[_0x34dcf9(0xee)](_0x386893);if(_0x2639cd===_0x386893)return null;_0x386893=_0x2639cd;}}export function loadProjectConfig(_0x46ddde){const _0x1a52da=a37_0x31e7,_0x2b9cf1=findProjectConfigPath(_0x46ddde);if(!_0x2b9cf1)return null;try{const _0x2e2981=a37_0x2cf9eb['readFileSync'](_0x2b9cf1,'utf-8'),_0x218eb6=JSON[_0x1a52da(0xf9)](_0x2e2981),_0x162e93=JSON[_0x1a52da(0xe6)](_0x218eb6);if(_0x162e93['includes'](_0x1a52da(0xed))||_0x162e93[_0x1a52da(0xe4)](_0x1a52da(0x101))||_0x162e93[_0x1a52da(0xe4)]('api_key'))throw new Error(_0x1a52da(0xe1)+_0x2b9cf1+_0x1a52da(0xf8)+_0x1a52da(0xea));const {metadata:_0x23dea0,profile:_0x308548,..._0x55dc0a}=_0x218eb6;return _0x308548&&console[_0x1a52da(0xfa)](_0x1a52da(0xfd)+_0x2b9cf1+_0x1a52da(0xf1)+_0x1a52da(0xe5)),_0x55dc0a;}catch(_0x558c86){if(_0x558c86 instanceof Error&&_0x1a52da(0xfc)in _0x558c86&&_0x558c86[_0x1a52da(0xfc)]===_0x1a52da(0xe8))return null;throw new Error(_0x1a52da(0xf0)+_0x2b9cf1+':\x20'+_0x558c86);}}export function saveProjectConfig(_0x371918,_0x2fda2d){const _0x1e63af=a37_0x31e7,_0x43f9b2=_0x2fda2d||process[_0x1e63af(0xfe)](),_0x4b886e=a37_0x20b8e6['join'](_0x43f9b2,PROJECT_CONFIG_FILENAME),_0x3e837c=JSON[_0x1e63af(0xe6)](_0x371918);if(_0x3e837c[_0x1e63af(0xe4)]('TD_API_KEY')||_0x3e837c[_0x1e63af(0xe4)](_0x1e63af(0x101))||_0x3e837c[_0x1e63af(0xe4)](_0x1e63af(0xe2)))throw new Error(_0x1e63af(0xf7));if(_0x1e63af(0xec)in _0x371918)throw new Error('\x27profile\x27\x20should\x20not\x20be\x20set\x20in\x20project\x20config.\x20Use\x20\x27tdx\x20profile\x20use\x27\x20instead.');a37_0x2cf9eb[_0x1e63af(0xf3)](_0x4b886e,JSON['stringify'](_0x371918,null,0x2));}function a37_0x31e7(_0x5a970d,_0x484b3d){const _0x142835=a37_0x1428();return a37_0x31e7=function(_0x31e736,_0x50d7b5){_0x31e736=_0x31e736-0xe1;let _0x54bd96=_0x142835[_0x31e736];return _0x54bd96;},a37_0x31e7(_0x5a970d,_0x484b3d);}export function hasProjectConfig(_0x55dcb1){return findProjectConfigPath(_0x55dcb1)!==null;}export function getProjectRoot(_0x1bb255){const _0x23a958=a37_0x31e7,_0x2fcd23=findProjectConfigPath(_0x1bb255);return _0x2fcd23?a37_0x20b8e6[_0x23a958(0xee)](_0x2fcd23):null;}
@@ -1 +1 @@
1
- (function(_0x59bb99,_0x4275f9){const _0xbd564c=a38_0x5c13,_0x1d5dae=_0x59bb99();while(!![]){try{const _0x4dafe5=-parseInt(_0xbd564c(0x18b))/0x1*(parseInt(_0xbd564c(0x17e))/0x2)+-parseInt(_0xbd564c(0x16b))/0x3*(-parseInt(_0xbd564c(0x196))/0x4)+-parseInt(_0xbd564c(0x179))/0x5*(parseInt(_0xbd564c(0x17a))/0x6)+-parseInt(_0xbd564c(0x189))/0x7+parseInt(_0xbd564c(0x171))/0x8*(parseInt(_0xbd564c(0x180))/0x9)+-parseInt(_0xbd564c(0x18f))/0xa*(-parseInt(_0xbd564c(0x18e))/0xb)+-parseInt(_0xbd564c(0x188))/0xc;if(_0x4dafe5===_0x4275f9)break;else _0x1d5dae['push'](_0x1d5dae['shift']());}catch(_0x11df17){_0x1d5dae['push'](_0x1d5dae['shift']());}}}(a38_0x3df7,0x3118d));function a38_0x5c13(_0x57b4fe,_0xadb810){const _0x3df7e0=a38_0x3df7();return a38_0x5c13=function(_0x5c13cd,_0x4646cc){_0x5c13cd=_0x5c13cd-0x16a;let _0x5a4803=_0x3df7e0[_0x5c13cd];return _0x5a4803;},a38_0x5c13(_0x57b4fe,_0xadb810);}import*as a38_0x4afd80 from'node:fs';import*as a38_0x51b236 from'node:path';import*as a38_0x19d7cd from'node:os';import{getPPID,isProcessRunning}from'../utils/process.js';import{createSecureDirectory}from'../utils/file-permissions.js';const SESSION_EXPIRATION_MS=0x18*0x3c*0x3c*0x3e8;function getSessionsDir(){const _0x16a9ea=a38_0x5c13,_0x3a66d7=process[_0x16a9ea(0x177)][_0x16a9ea(0x175)]||a38_0x51b236['join'](a38_0x19d7cd[_0x16a9ea(0x178)](),_0x16a9ea(0x174),_0x16a9ea(0x16d));return a38_0x51b236[_0x16a9ea(0x190)](_0x3a66d7,_0x16a9ea(0x18a));}function a38_0x3df7(){const _0x47297c=['replace','parse','stringify','existsSync','endsWith','TD_API_KEY','readFileSync','2944224jRPojO','2523556KSunPa','sessions','1033LjOpoM','warn','toISOString','59972KXfoVu','610kcPOLe','join','.json','includes','test','.\x20This\x20is\x20insecure.\x20Removing\x20session.','apiKey','1349876eFkRHv','api_key','toString','3zYrlmm','API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20session\x20context.\x20Use\x20.env\x20files\x20instead.','tdx','readdirSync','writeFileSync','Warning:\x20API\x20keys\x20found\x20in\x20session\x20file\x20','1251176moDSxj','unlinkSync','createdAt','.config','TDX_CONFIG_DIR','push','env','homedir','19410loAvQg','192HfiwCv','now','getTime','utf-8','100FRqVgr','sort','18sDHaUO'];a38_0x3df7=function(){return _0x47297c;};return a38_0x3df7();}function getSessionPath(_0x311ec2){const _0x12e8c4=a38_0x5c13;return a38_0x51b236['join'](getSessionsDir(),_0x311ec2+_0x12e8c4(0x191));}export function getCurrentSessionPID(){return getPPID();}export function getSessionID(_0x20bf8e){const _0xc6eae8=a38_0x5c13;if(_0x20bf8e)return _0x20bf8e;return getCurrentSessionPID()[_0xc6eae8(0x16a)]();}export function loadSessionContext(_0x559abc){const _0x17b672=a38_0x5c13,_0x54b3dd=_0x559abc||getCurrentSessionPID()[_0x17b672(0x16a)](),_0x1b3c34=/^\d+$/[_0x17b672(0x193)](_0x54b3dd)?parseInt(_0x54b3dd,0xa):null;return _0x1b3c34!==null?loadSessionContextByPID(_0x1b3c34):loadSessionContextByString(_0x54b3dd);}export function loadSessionContextByPID(_0x5d6cac){const _0x4d4138=a38_0x5c13,_0x10e175=getSessionPath(_0x5d6cac);if(!a38_0x4afd80[_0x4d4138(0x184)](_0x10e175))return null;try{const _0x39ebef=a38_0x4afd80['readFileSync'](_0x10e175,_0x4d4138(0x17d)),_0x1d5c0d=JSON[_0x4d4138(0x182)](_0x39ebef),_0x22c393=new Date(_0x1d5c0d[_0x4d4138(0x173)])[_0x4d4138(0x17c)](),_0x53fcd7=Date['now']();if(_0x53fcd7-_0x22c393>SESSION_EXPIRATION_MS)return a38_0x4afd80[_0x4d4138(0x172)](_0x10e175),null;const _0x358e7f=JSON[_0x4d4138(0x183)](_0x1d5c0d);if(_0x358e7f['includes']('TD_API_KEY')||_0x358e7f[_0x4d4138(0x192)]('apiKey')||_0x358e7f['includes'](_0x4d4138(0x197)))return console[_0x4d4138(0x18c)](_0x4d4138(0x170)+_0x10e175+_0x4d4138(0x194)),a38_0x4afd80[_0x4d4138(0x172)](_0x10e175),null;return _0x1d5c0d;}catch{try{a38_0x4afd80[_0x4d4138(0x172)](_0x10e175);}catch{}return null;}}function loadSessionContextByString(_0x49423e){const _0x9e0b65=a38_0x5c13,_0x5e1ea6=a38_0x51b236['join'](getSessionsDir(),_0x49423e+_0x9e0b65(0x191));if(!a38_0x4afd80[_0x9e0b65(0x184)](_0x5e1ea6))return null;try{const _0x154053=a38_0x4afd80[_0x9e0b65(0x187)](_0x5e1ea6,_0x9e0b65(0x17d)),_0x5857ef=JSON[_0x9e0b65(0x182)](_0x154053),_0x5186b6=new Date(_0x5857ef['createdAt'])[_0x9e0b65(0x17c)](),_0x279834=Date[_0x9e0b65(0x17b)]();if(_0x279834-_0x5186b6>SESSION_EXPIRATION_MS)return a38_0x4afd80[_0x9e0b65(0x172)](_0x5e1ea6),null;const _0x4e0f33=JSON[_0x9e0b65(0x183)](_0x5857ef);if(_0x4e0f33[_0x9e0b65(0x192)](_0x9e0b65(0x186))||_0x4e0f33[_0x9e0b65(0x192)]('apiKey')||_0x4e0f33[_0x9e0b65(0x192)](_0x9e0b65(0x197)))return console[_0x9e0b65(0x18c)]('Warning:\x20API\x20keys\x20found\x20in\x20session\x20file\x20'+_0x5e1ea6+_0x9e0b65(0x194)),a38_0x4afd80[_0x9e0b65(0x172)](_0x5e1ea6),null;return _0x5857ef;}catch{try{a38_0x4afd80['unlinkSync'](_0x5e1ea6);}catch{}return null;}}export function saveSessionContext(_0x33b33c,_0xfb9709){const _0x13be0b=a38_0x5c13,_0x46a001=_0xfb9709||getCurrentSessionPID()[_0x13be0b(0x16a)](),_0x219377=/^\d+$/[_0x13be0b(0x193)](_0x46a001)?parseInt(_0x46a001,0xa):getCurrentSessionPID(),_0xf46765=a38_0x51b236[_0x13be0b(0x190)](getSessionsDir(),_0x46a001+_0x13be0b(0x191)),_0x3d1f93=getSessionsDir();createSecureDirectory(_0x3d1f93);const _0x276eab=JSON['stringify'](_0x33b33c);if(_0x276eab[_0x13be0b(0x192)](_0x13be0b(0x186))||_0x276eab[_0x13be0b(0x192)](_0x13be0b(0x195))||_0x276eab[_0x13be0b(0x192)](_0x13be0b(0x197)))throw new Error(_0x13be0b(0x16c));let _0x2e134c;const _0x26653b=/^\d+$/[_0x13be0b(0x193)](_0x46a001)?loadSessionContextByPID(parseInt(_0x46a001,0xa)):loadSessionContextByString(_0x46a001);_0x26653b?_0x2e134c={..._0x26653b,..._0x33b33c,'pid':_0x219377,'sessionId':_0x46a001!==_0x219377[_0x13be0b(0x16a)]()?_0x46a001:undefined,'updatedAt':new Date()[_0x13be0b(0x18d)]()}:_0x2e134c={'pid':_0x219377,'sessionId':_0x46a001!==_0x219377['toString']()?_0x46a001:undefined,..._0x33b33c,'createdAt':new Date()['toISOString'](),'updatedAt':new Date()['toISOString']()},a38_0x4afd80[_0x13be0b(0x16f)](_0xf46765,JSON[_0x13be0b(0x183)](_0x2e134c,null,0x2));}export function clearSessionContext(_0x4c2de7){const _0x5d119e=a38_0x5c13,_0x58ef9e=_0x4c2de7||getCurrentSessionPID()[_0x5d119e(0x16a)](),_0x174d5c=a38_0x51b236['join'](getSessionsDir(),_0x58ef9e+'.json');a38_0x4afd80[_0x5d119e(0x184)](_0x174d5c)&&a38_0x4afd80[_0x5d119e(0x172)](_0x174d5c);}export function cleanExpiredSessions(){const _0xcd67ef=a38_0x5c13,_0x5402b1=getSessionsDir();if(!a38_0x4afd80['existsSync'](_0x5402b1))return 0x0;let _0x18aa8e=0x0;const _0x3242b3=Date[_0xcd67ef(0x17b)]();try{const _0x14e86a=a38_0x4afd80['readdirSync'](_0x5402b1);for(const _0x257cc1 of _0x14e86a){if(!_0x257cc1[_0xcd67ef(0x185)](_0xcd67ef(0x191)))continue;const _0x4636be=a38_0x51b236[_0xcd67ef(0x190)](_0x5402b1,_0x257cc1),_0x4b4f41=_0x257cc1[_0xcd67ef(0x181)](_0xcd67ef(0x191),''),_0x18cbb3=parseInt(_0x4b4f41,0xa),_0x50778d=!isNaN(_0x18cbb3);if(_0x50778d){if(!isProcessRunning(_0x18cbb3)){a38_0x4afd80[_0xcd67ef(0x172)](_0x4636be),_0x18aa8e++;continue;}}try{const _0x4d7abd=a38_0x4afd80[_0xcd67ef(0x187)](_0x4636be,_0xcd67ef(0x17d)),_0x549207=JSON[_0xcd67ef(0x182)](_0x4d7abd),_0x591847=new Date(_0x549207[_0xcd67ef(0x173)])[_0xcd67ef(0x17c)]();_0x3242b3-_0x591847>SESSION_EXPIRATION_MS&&(a38_0x4afd80['unlinkSync'](_0x4636be),_0x18aa8e++);}catch{a38_0x4afd80[_0xcd67ef(0x172)](_0x4636be),_0x18aa8e++;}}}catch{}return _0x18aa8e;}export function listActiveSessions(){const _0x4ae967=a38_0x5c13,_0x2fbdc0=getSessionsDir();if(!a38_0x4afd80[_0x4ae967(0x184)](_0x2fbdc0))return[];try{const _0x1cdf4f=a38_0x4afd80[_0x4ae967(0x16e)](_0x2fbdc0),_0x4a7867=[];for(const _0x380d7f of _0x1cdf4f){if(!_0x380d7f[_0x4ae967(0x185)](_0x4ae967(0x191)))continue;const _0x4c7e60=_0x380d7f[_0x4ae967(0x181)](_0x4ae967(0x191),''),_0x502ae3=parseInt(_0x4c7e60,0xa);!isNaN(_0x502ae3)&&isProcessRunning(_0x502ae3)&&_0x4a7867[_0x4ae967(0x176)](_0x502ae3);}return _0x4a7867[_0x4ae967(0x17f)]((_0x2035b1,_0x536cde)=>_0x2035b1-_0x536cde);}catch{return[];}}
1
+ (function(_0x5c93ff,_0x26454f){const _0x20e11e=a38_0x283e,_0x5ee78e=_0x5c93ff();while(!![]){try{const _0x408a22=-parseInt(_0x20e11e(0xad))/0x1*(-parseInt(_0x20e11e(0x9d))/0x2)+-parseInt(_0x20e11e(0x92))/0x3+parseInt(_0x20e11e(0x9c))/0x4+-parseInt(_0x20e11e(0xa5))/0x5+parseInt(_0x20e11e(0xa6))/0x6+parseInt(_0x20e11e(0x9b))/0x7*(parseInt(_0x20e11e(0xa3))/0x8)+-parseInt(_0x20e11e(0x99))/0x9;if(_0x408a22===_0x26454f)break;else _0x5ee78e['push'](_0x5ee78e['shift']());}catch(_0x11ddd2){_0x5ee78e['push'](_0x5ee78e['shift']());}}}(a38_0x4354,0xb81d5));import*as a38_0x32877f from'node:fs';import*as a38_0x22ae6d from'node:path';function a38_0x283e(_0x1cb215,_0x588727){const _0x43544b=a38_0x4354();return a38_0x283e=function(_0x283e90,_0xdaaa52){_0x283e90=_0x283e90-0x8b;let _0x4b77d8=_0x43544b[_0x283e90];return _0x4b77d8;},a38_0x283e(_0x1cb215,_0x588727);}import*as a38_0x4d50fd from'node:os';import{getPPID,isProcessRunning}from'../utils/process.js';import{createSecureDirectory}from'../utils/file-permissions.js';const SESSION_EXPIRATION_MS=0x18*0x3c*0x3c*0x3e8;function getSessionsDir(){const _0x238a0b=a38_0x283e,_0x2a014d=process[_0x238a0b(0x90)][_0x238a0b(0xaf)]||a38_0x22ae6d[_0x238a0b(0xa7)](a38_0x4d50fd[_0x238a0b(0x9e)](),_0x238a0b(0x8e),_0x238a0b(0xa0));return a38_0x22ae6d[_0x238a0b(0xa7)](_0x2a014d,'sessions');}function getSessionPath(_0x68f099){const _0x3914fa=a38_0x283e;return a38_0x22ae6d[_0x3914fa(0xa7)](getSessionsDir(),_0x68f099+_0x3914fa(0x8d));}export function getCurrentSessionPID(){return getPPID();}export function getSessionID(_0x4e2079){if(_0x4e2079)return _0x4e2079;return getCurrentSessionPID()['toString']();}export function loadSessionContext(_0xdac643){const _0x1ec99f=a38_0x283e,_0x323f48=_0xdac643||getCurrentSessionPID()[_0x1ec99f(0x9f)](),_0x1b871f=/^\d+$/[_0x1ec99f(0xa9)](_0x323f48)?parseInt(_0x323f48,0xa):null;return _0x1b871f!==null?loadSessionContextByPID(_0x1b871f):loadSessionContextByString(_0x323f48);}function a38_0x4354(){const _0x184733=['createdAt','existsSync','utf-8','replace','17043597CNnSke','toISOString','21ToAyUu','5030140AsPOGL','4228amJneD','homedir','toString','tdx','Warning:\x20API\x20keys\x20found\x20in\x20session\x20file\x20','TD_API_KEY','3734264QHKziS','push','4381095ZrXWdV','8332074mmFEfc','join','unlinkSync','test','endsWith','stringify','sort','206gtJGGS','api_key','TDX_CONFIG_DIR','parse','warn','apiKey','getTime','writeFileSync','readFileSync','.json','.config','readdirSync','env','.\x20This\x20is\x20insecure.\x20Removing\x20session.','2873886zbcbby','includes','now'];a38_0x4354=function(){return _0x184733;};return a38_0x4354();}export function loadSessionContextByPID(_0x2a0b43){const _0x1a9cd2=a38_0x283e,_0x3923ea=getSessionPath(_0x2a0b43);if(!a38_0x32877f[_0x1a9cd2(0x96)](_0x3923ea))return null;try{const _0x2cdc93=a38_0x32877f[_0x1a9cd2(0x8c)](_0x3923ea,_0x1a9cd2(0x97)),_0x4b00b6=JSON[_0x1a9cd2(0xb0)](_0x2cdc93),_0x4455b1=new Date(_0x4b00b6['createdAt'])[_0x1a9cd2(0xb3)](),_0x3b57dd=Date[_0x1a9cd2(0x94)]();if(_0x3b57dd-_0x4455b1>SESSION_EXPIRATION_MS)return a38_0x32877f[_0x1a9cd2(0xa8)](_0x3923ea),null;const _0x4aa7f5=JSON[_0x1a9cd2(0xab)](_0x4b00b6);if(_0x4aa7f5[_0x1a9cd2(0x93)](_0x1a9cd2(0xa2))||_0x4aa7f5[_0x1a9cd2(0x93)](_0x1a9cd2(0xb2))||_0x4aa7f5[_0x1a9cd2(0x93)](_0x1a9cd2(0xae)))return console['warn'](_0x1a9cd2(0xa1)+_0x3923ea+_0x1a9cd2(0x91)),a38_0x32877f[_0x1a9cd2(0xa8)](_0x3923ea),null;return _0x4b00b6;}catch{try{a38_0x32877f['unlinkSync'](_0x3923ea);}catch{}return null;}}function loadSessionContextByString(_0x23e70e){const _0x56fff1=a38_0x283e,_0x35d17a=a38_0x22ae6d['join'](getSessionsDir(),_0x23e70e+_0x56fff1(0x8d));if(!a38_0x32877f['existsSync'](_0x35d17a))return null;try{const _0x395f77=a38_0x32877f['readFileSync'](_0x35d17a,_0x56fff1(0x97)),_0x4648fb=JSON[_0x56fff1(0xb0)](_0x395f77),_0x1d5792=new Date(_0x4648fb[_0x56fff1(0x95)])['getTime'](),_0x3369b8=Date['now']();if(_0x3369b8-_0x1d5792>SESSION_EXPIRATION_MS)return a38_0x32877f[_0x56fff1(0xa8)](_0x35d17a),null;const _0x37a668=JSON[_0x56fff1(0xab)](_0x4648fb);if(_0x37a668['includes'](_0x56fff1(0xa2))||_0x37a668['includes'](_0x56fff1(0xb2))||_0x37a668[_0x56fff1(0x93)](_0x56fff1(0xae)))return console[_0x56fff1(0xb1)]('Warning:\x20API\x20keys\x20found\x20in\x20session\x20file\x20'+_0x35d17a+_0x56fff1(0x91)),a38_0x32877f[_0x56fff1(0xa8)](_0x35d17a),null;return _0x4648fb;}catch{try{a38_0x32877f[_0x56fff1(0xa8)](_0x35d17a);}catch{}return null;}}export function saveSessionContext(_0x3054df,_0x2cd952){const _0x26ea0c=a38_0x283e,_0x16af9b=_0x2cd952||getCurrentSessionPID()['toString'](),_0x1eae9c=/^\d+$/[_0x26ea0c(0xa9)](_0x16af9b)?parseInt(_0x16af9b,0xa):getCurrentSessionPID(),_0x4f0067=a38_0x22ae6d['join'](getSessionsDir(),_0x16af9b+'.json'),_0x3d2bdb=getSessionsDir();createSecureDirectory(_0x3d2bdb);const _0x21e812=JSON[_0x26ea0c(0xab)](_0x3054df);if(_0x21e812[_0x26ea0c(0x93)](_0x26ea0c(0xa2))||_0x21e812[_0x26ea0c(0x93)](_0x26ea0c(0xb2))||_0x21e812[_0x26ea0c(0x93)]('api_key'))throw new Error('API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20session\x20context.\x20Use\x20.env\x20files\x20instead.');let _0x2046f1;const _0x1f302b=/^\d+$/['test'](_0x16af9b)?loadSessionContextByPID(parseInt(_0x16af9b,0xa)):loadSessionContextByString(_0x16af9b);_0x1f302b?_0x2046f1={..._0x1f302b,..._0x3054df,'pid':_0x1eae9c,'sessionId':_0x16af9b!==_0x1eae9c['toString']()?_0x16af9b:undefined,'updatedAt':new Date()[_0x26ea0c(0x9a)]()}:_0x2046f1={'pid':_0x1eae9c,'sessionId':_0x16af9b!==_0x1eae9c[_0x26ea0c(0x9f)]()?_0x16af9b:undefined,..._0x3054df,'createdAt':new Date()[_0x26ea0c(0x9a)](),'updatedAt':new Date()[_0x26ea0c(0x9a)]()},a38_0x32877f[_0x26ea0c(0x8b)](_0x4f0067,JSON['stringify'](_0x2046f1,null,0x2));}export function clearSessionContext(_0x25f31a){const _0x1507ca=a38_0x283e,_0x2e4c94=_0x25f31a||getCurrentSessionPID()[_0x1507ca(0x9f)](),_0x8a3310=a38_0x22ae6d[_0x1507ca(0xa7)](getSessionsDir(),_0x2e4c94+_0x1507ca(0x8d));a38_0x32877f[_0x1507ca(0x96)](_0x8a3310)&&a38_0x32877f['unlinkSync'](_0x8a3310);}export function cleanExpiredSessions(){const _0x163489=a38_0x283e,_0x2e895b=getSessionsDir();if(!a38_0x32877f['existsSync'](_0x2e895b))return 0x0;let _0x3e97b0=0x0;const _0x23b729=Date[_0x163489(0x94)]();try{const _0x297970=a38_0x32877f['readdirSync'](_0x2e895b);for(const _0x25aeee of _0x297970){if(!_0x25aeee[_0x163489(0xaa)](_0x163489(0x8d)))continue;const _0x31bc19=a38_0x22ae6d['join'](_0x2e895b,_0x25aeee),_0x5de315=_0x25aeee[_0x163489(0x98)](_0x163489(0x8d),''),_0x21974f=parseInt(_0x5de315,0xa),_0x129452=!isNaN(_0x21974f);if(_0x129452){if(!isProcessRunning(_0x21974f)){a38_0x32877f['unlinkSync'](_0x31bc19),_0x3e97b0++;continue;}}try{const _0x58e8a7=a38_0x32877f[_0x163489(0x8c)](_0x31bc19,'utf-8'),_0x333dce=JSON[_0x163489(0xb0)](_0x58e8a7),_0x335037=new Date(_0x333dce['createdAt'])[_0x163489(0xb3)]();_0x23b729-_0x335037>SESSION_EXPIRATION_MS&&(a38_0x32877f[_0x163489(0xa8)](_0x31bc19),_0x3e97b0++);}catch{a38_0x32877f[_0x163489(0xa8)](_0x31bc19),_0x3e97b0++;}}}catch{}return _0x3e97b0;}export function listActiveSessions(){const _0x3e1b62=a38_0x283e,_0x174d92=getSessionsDir();if(!a38_0x32877f[_0x3e1b62(0x96)](_0x174d92))return[];try{const _0x52c729=a38_0x32877f[_0x3e1b62(0x8f)](_0x174d92),_0x1580eb=[];for(const _0x234a7b of _0x52c729){if(!_0x234a7b['endsWith'](_0x3e1b62(0x8d)))continue;const _0x5ad037=_0x234a7b[_0x3e1b62(0x98)]('.json',''),_0x45c599=parseInt(_0x5ad037,0xa);!isNaN(_0x45c599)&&isProcessRunning(_0x45c599)&&_0x1580eb[_0x3e1b62(0xa4)](_0x45c599);}return _0x1580eb[_0x3e1b62(0xac)]((_0x10d59f,_0x4bf88c)=>_0x10d59f-_0x4bf88c);}catch{return[];}}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- (function(_0x583b3d,_0x1e956a){var _0x37a2a5=a39_0x4b72,_0x1260ef=_0x583b3d();while(!![]){try{var _0x480a53=-parseInt(_0x37a2a5(0x157))/0x1+-parseInt(_0x37a2a5(0x153))/0x2+-parseInt(_0x37a2a5(0x15b))/0x3*(parseInt(_0x37a2a5(0x15a))/0x4)+parseInt(_0x37a2a5(0x152))/0x5*(parseInt(_0x37a2a5(0x159))/0x6)+parseInt(_0x37a2a5(0x154))/0x7+parseInt(_0x37a2a5(0x156))/0x8*(-parseInt(_0x37a2a5(0x155))/0x9)+parseInt(_0x37a2a5(0x15c))/0xa*(parseInt(_0x37a2a5(0x158))/0xb);if(_0x480a53===_0x1e956a)break;else _0x1260ef['push'](_0x1260ef['shift']());}catch(_0x5f2cc7){_0x1260ef['push'](_0x1260ef['shift']());}}}(a39_0x2bfc,0x2e42e));export*from'./types/index.js';export*from'./core/config.js';function a39_0x2bfc(){var _0x1ec8c4=['710QyHpae','1792330ixsTGF','161704hAxOBL','1585948gJGQWI','1035sdsAKd','8904ZkjnJN','250256crciyg','46849RPrKfI','6NAZrsm','5028wxurHz','570EMxImj'];a39_0x2bfc=function(){return _0x1ec8c4;};return a39_0x2bfc();}export*from'./core/auth.js';export*from'./client/http-client.js';export*from'./client/td-client.js';export{TrinoClient}from'./client/trino-client.js';export*from'./client/rate-limiter.js';export*from'./types/trino.js';export*from'./commands/command.js';export*from'./commands/query-command.js';export*from'./commands/databases.js';export*from'./commands/tables.js';export*from'./commands/segments.js';function a39_0x4b72(_0x83451d,_0x5e4ba0){var _0x2bfc7b=a39_0x2bfc();return a39_0x4b72=function(_0x4b7248,_0x5e363b){_0x4b7248=_0x4b7248-0x152;var _0x1bfd1d=_0x2bfc7b[_0x4b7248];return _0x1bfd1d;},a39_0x4b72(_0x83451d,_0x5e4ba0);}export*from'./commands/activations.js';export*from'./commands/show.js';export*from'./commands/describe.js';export*from'./sdk/index.js';
1
+ function a39_0x190a(_0x1f2298,_0x2d7b42){var _0x45a00a=a39_0x45a0();return a39_0x190a=function(_0x190ad2,_0x3c7320){_0x190ad2=_0x190ad2-0x198;var _0x56a438=_0x45a00a[_0x190ad2];return _0x56a438;},a39_0x190a(_0x1f2298,_0x2d7b42);}(function(_0x40b839,_0xab1852){var _0x5ab8a3=a39_0x190a,_0x15a028=_0x40b839();while(!![]){try{var _0x5c4630=-parseInt(_0x5ab8a3(0x19e))/0x1*(parseInt(_0x5ab8a3(0x198))/0x2)+parseInt(_0x5ab8a3(0x19c))/0x3*(parseInt(_0x5ab8a3(0x19d))/0x4)+parseInt(_0x5ab8a3(0x1a2))/0x5*(parseInt(_0x5ab8a3(0x1a3))/0x6)+parseInt(_0x5ab8a3(0x19f))/0x7+-parseInt(_0x5ab8a3(0x19b))/0x8*(-parseInt(_0x5ab8a3(0x199))/0x9)+-parseInt(_0x5ab8a3(0x1a0))/0xa*(-parseInt(_0x5ab8a3(0x1a1))/0xb)+-parseInt(_0x5ab8a3(0x19a))/0xc;if(_0x5c4630===_0xab1852)break;else _0x15a028['push'](_0x15a028['shift']());}catch(_0x1f20a7){_0x15a028['push'](_0x15a028['shift']());}}}(a39_0x45a0,0xa0d7f));export*from'./types/index.js';export*from'./core/config.js';export*from'./core/auth.js';export*from'./client/http-client.js';export*from'./client/td-client.js';export{TrinoClient}from'./client/trino-client.js';export*from'./client/rate-limiter.js';export*from'./types/trino.js';export*from'./commands/command.js';export*from'./commands/query-command.js';export*from'./commands/databases.js';export*from'./commands/tables.js';function a39_0x45a0(){var _0x5ce229=['25441164rAxXXt','163216gXybzW','15cHtvxC','404836BfyDqm','10033PGQFdO','5800676Yamcbe','30GBHkHT','48147gRUcSL','3455KuvRNC','8610ZpsovL','10gfhoei','216YGspsg'];a39_0x45a0=function(){return _0x5ce229;};return a39_0x45a0();}export*from'./commands/segments.js';export*from'./commands/activations.js';export*from'./commands/show.js';export*from'./commands/describe.js';export*from'./sdk/index.js';
@@ -1 +1 @@
1
- function a40_0x5bcc(_0xcd15f2,_0x223030){const _0xff961d=a40_0xff96();return a40_0x5bcc=function(_0x5bcc3a,_0x2b2ad7){_0x5bcc3a=_0x5bcc3a-0xe2;let _0xa38c4=_0xff961d[_0x5bcc3a];return _0xa38c4;},a40_0x5bcc(_0xcd15f2,_0x223030);}(function(_0x1d0ba9,_0x9294cd){const _0xb4c86=a40_0x5bcc,_0x2c0984=_0x1d0ba9();while(!![]){try{const _0x35c9e9=parseInt(_0xb4c86(0x12e))/0x1+parseInt(_0xb4c86(0x12d))/0x2+parseInt(_0xb4c86(0x120))/0x3+-parseInt(_0xb4c86(0x10c))/0x4+parseInt(_0xb4c86(0x125))/0x5+parseInt(_0xb4c86(0x13e))/0x6*(-parseInt(_0xb4c86(0xe5))/0x7)+-parseInt(_0xb4c86(0x136))/0x8*(parseInt(_0xb4c86(0x147))/0x9);if(_0x35c9e9===_0x9294cd)break;else _0x2c0984['push'](_0x2c0984['shift']());}catch(_0x36c225){_0x2c0984['push'](_0x2c0984['shift']());}}}(a40_0xff96,0xe8dd3));import{SDKError,ErrorCode}from'../sdk/errors.js';function estimateTokenCount(_0x5fa2de){const _0x5d3f50=a40_0x5bcc;if(!_0x5fa2de||_0x5fa2de['length']===0x0)return 0x0;return Math[_0x5d3f50(0x144)](_0x5fa2de[_0x5d3f50(0x106)]/3.7);}export function determineErrorType(_0x2d1e91,_0x1af03f){const _0x16893f=a40_0x5bcc,_0x28822a=_0x2d1e91[_0x16893f(0x11e)](_0x16893f(0xf4))||_0x2d1e91[_0x16893f(0x11e)](_0x16893f(0x10f))||_0x2d1e91[_0x16893f(0x11e)](_0x16893f(0xef));if(_0x28822a)return _0x1af03f?.[_0x16893f(0xfe)](_0x16893f(0x13b)+_0x2d1e91),_0x16893f(0x113);return _0x1af03f?.[_0x16893f(0xfe)](_0x16893f(0x128)+_0x2d1e91),'api_error';}export function estimateInputTokensFromRequest(_0x1f9523){const _0x1de016=a40_0x5bcc;let _0x2300d3=0x0;if(typeof _0x1f9523[_0x1de016(0x139)]===_0x1de016(0x119))_0x2300d3+=_0x1f9523['system'][_0x1de016(0x106)];else{if(Array[_0x1de016(0x11d)](_0x1f9523[_0x1de016(0x139)]))for(const _0x4b62fc of _0x1f9523[_0x1de016(0x139)]){_0x4b62fc&&typeof _0x4b62fc['text']===_0x1de016(0x119)&&(_0x2300d3+=_0x4b62fc['text'][_0x1de016(0x106)]);}}if(Array[_0x1de016(0x11d)](_0x1f9523['tools']))for(const _0x296870 of _0x1f9523[_0x1de016(0xff)]){_0x296870&&(_0x2300d3+=_0x296870['name'][_0x1de016(0x106)],_0x2300d3+=_0x296870[_0x1de016(0x110)]?.[_0x1de016(0x106)]||0x0,_0x2300d3+=JSON['stringify'](_0x296870[_0x1de016(0x111)])[_0x1de016(0x106)]);}if(Array[_0x1de016(0x11d)](_0x1f9523[_0x1de016(0x13d)]))for(const _0x4398ea of _0x1f9523[_0x1de016(0x13d)]){if(!_0x4398ea)continue;if(typeof _0x4398ea['content']==='string')_0x2300d3+=_0x4398ea[_0x1de016(0x103)]['length'];else{if(Array[_0x1de016(0x11d)](_0x4398ea['content']))for(const _0x17aa4e of _0x4398ea[_0x1de016(0x103)]){if(!_0x17aa4e)continue;if(_0x17aa4e[_0x1de016(0x10d)]===_0x1de016(0x13f)&&_0x17aa4e[_0x1de016(0x13f)])_0x2300d3+=_0x17aa4e[_0x1de016(0x13f)][_0x1de016(0x106)];else{if(_0x17aa4e[_0x1de016(0x10d)]==='tool_use'&&_0x17aa4e[_0x1de016(0xe7)])_0x2300d3+=JSON[_0x1de016(0xe3)](_0x17aa4e['input'])['length'];else{if(_0x17aa4e[_0x1de016(0x10d)]==='tool_result'&&_0x17aa4e[_0x1de016(0x103)]){if(typeof _0x17aa4e[_0x1de016(0x103)]===_0x1de016(0x119))_0x2300d3+=_0x17aa4e['content'][_0x1de016(0x106)];else{if(Array[_0x1de016(0x11d)](_0x17aa4e[_0x1de016(0x103)]))for(const _0x298d54 of _0x17aa4e[_0x1de016(0x103)]){_0x298d54&&_0x298d54[_0x1de016(0x10d)]===_0x1de016(0x13f)&&_0x298d54[_0x1de016(0x13f)]&&(_0x2300d3+=_0x298d54['text'][_0x1de016(0x106)]);}}}}}}}}return Math[_0x1de016(0x144)](_0x2300d3/3.7);}function generateMessageId(){const _0x290a02=a40_0x5bcc;return _0x290a02(0x11b)+Math[_0x290a02(0x109)]()[_0x290a02(0xf1)](0x24)[_0x290a02(0xf0)](0x2,0xf)+Math[_0x290a02(0x109)]()[_0x290a02(0xf1)](0x24)['substring'](0x2,0xf);}export function extractTextFromAnthropicMessage(_0x11131d){const _0x45b6ea=a40_0x5bcc;if(typeof _0x11131d[_0x45b6ea(0x103)]==='string')return _0x11131d[_0x45b6ea(0x103)];if(_0x11131d['content']==null)return'';if(!Array[_0x45b6ea(0x11d)](_0x11131d['content']))throw new SDKError(ErrorCode[_0x45b6ea(0x108)],'Invalid\x20message.content\x20type:\x20expected\x20string\x20or\x20array,\x20got\x20'+typeof _0x11131d['content']);return _0x11131d['content'][_0x45b6ea(0xfa)](_0x4d2539=>_0x4d2539&&_0x4d2539['type']==='text'&&_0x4d2539[_0x45b6ea(0x13f)])[_0x45b6ea(0xf7)](_0x2e314c=>_0x2e314c[_0x45b6ea(0x13f)])[_0x45b6ea(0x112)]('\x0a');}export function calculateConversationDelta(_0x18ea0d,_0x571bdc){const _0x1c35eb=a40_0x5bcc;if(_0x571bdc[_0x1c35eb(0x106)]===0x0)return _0x18ea0d;const _0x15c7a3=_0x571bdc[_0x1c35eb(0x106)];return _0x18ea0d['slice'](_0x15c7a3);}function a40_0xff96(){const _0x1aa7f=['Invalid\x20tools\x20type:\x20expected\x20array,\x20got\x20','min','filter','tool_use_id','usage','assistant','error','tools','Malformed\x20tool_use\x20JSON\x20detected','content_block_stop','input_json_delta','content','name','endsWith','length','content_block_delta','LLM_MALFORMED_MESSAGE','random','debug','##\x20Tool:\x20','3603508KwRkXR','type','Invalid\x20messages\x20type:\x20expected\x20array,\x20got\x20','context\x20length','description','input_schema','join','request_too_large','```','haiku','warn','\x5c`\x5c`\x5c`','sonnet','string','indexOf','msg_','Multiple\x20tool\x20calls\x20detected,\x20using\x20only\x20the\x20last\x20one:\x20','isArray','includes','\x0a#\x20How\x20to\x20Use\x20Tools\x0a\x0aTo\x20use\x20a\x20tool,\x20output\x20the\x20tool\x20call\x20in\x20a\x20markdown\x20code\x20block:\x0a\x0a```tool_use\x0a{\x22tool_use\x22:{\x22id\x22:\x22toolu_<random>\x22,\x22name\x22:\x22<tool_name>\x22,\x22input\x22:{<parameters>}}}\x0a```\x0a\x0a**IMPORTANT:**\x0a-\x20**Output\x20only\x20ONE\x20tool_use\x20at\x20a\x20time**\x20-\x20Never\x20output\x20multiple\x20tool\x20calls\x20in\x20a\x20single\x20response\x0a-\x20Use\x20the\x20precise\x20parameter\x20names\x20and\x20types\x20as\x20defined\x20in\x20the\x20JSON\x20schema.\x0a-\x20Wrap\x20the\x20JSON\x20in\x20a\x20markdown\x20code\x20block\x20with\x20```tool_use\x0a-\x20The\x20JSON\x20must\x20be\x20valid\x20and\x20properly\x20formatted.\x20Ensure\x20all\x20strings\x20are\x20double\x20quoted.\x0a-\x20Generate\x20a\x20unique\x20random\x20ID\x20starting\x20with\x20\x22toolu_\x22\x0a-\x20After\x20outputting\x20the\x20tool\x20use,\x20stop\x20and\x20wait\x20for\x20the\x20tool\x20result\x0a-\x20Tool\x20results\x20will\x20be\x20provided\x20in\x20markdown\x20code\x20blocks\x20with\x20```tool_result\x20tool_use_id=<id>\x0a-\x20Once\x20you\x20receive\x20a\x20tool\x20result,\x20you\x20may\x20call\x20another\x20tool\x20if\x20needed,\x20or\x20continue\x20your\x20response\x20naturally\x0a\x0a**Example\x201\x20-\x20Simple\x20tool:**\x0aUser:\x20\x22What\x27s\x2025\x20*\x204?\x22\x0aAssistant:\x20I\x27ll\x20calculate\x20that\x20for\x20you.\x0a\x0a```tool_use\x0a{\x22tool_use\x22:{\x22id\x22:\x22toolu_abc123\x22,\x22name\x22:\x22calculator\x22,\x22input\x22:{\x22expression\x22:\x2225\x20*\x204\x22}}}\x0a```\x0a\x0a**Example\x202\x20-\x20Tool\x20with\x20multiline\x20strings\x20(proper\x20escaping):**\x0aUser:\x20\x22Edit\x20the\x20file\x20to\x20add\x20a\x20newline\x22\x0aAssistant:\x20I\x27ll\x20edit\x20the\x20file\x20with\x20proper\x20JSON\x20escaping.\x0a\x0a```tool_use\x0a{\x22tool_use\x22:{\x22id\x22:\x22toolu_def456\x22,\x22name\x22:\x22Edit\x22,\x22input\x22:{\x22file_path\x22:\x22test.ts\x22,\x22old_string\x22:\x22const\x20x\x20=\x201;\x22,\x22new_string\x22:\x22const\x20x\x20=\x201;\x5cnconst\x20y\x20=\x202;\x22}}}\x0a```\x0a\x0a#\x20Available\x20Tools\x0a\x0a','1872324FsTlxP','message_start','pop','```tool_use','opus','8611335akkime','model_context_window_exceeded','exec','[API\x20ERROR]\x20','user','\x0adata:\x20','Malformed\x20content:','\x20error=true','100596cSXmjI','1574303lCLfhg','\x0a```','event:\x20','message_delta','Tool\x20call\x20detected:\x20','end_turn','message','endIndex','32LGDxKi','push','trim','system','\x0a\x0a[tdx\x20error]\x20Malformed\x20tool_use\x20JSON\x20detected.\x20Please\x20fix\x20the\x20JSON\x20below:\x0a\x0a','[CONTEXT\x20LENGTH\x20ERROR]\x20','startIndex','messages','482280awsSlw','text','No\x20description','parse','output_tokens','message_stop','ceil','replace','Tool\x20calls\x20not\x20yet\x20supported\x20in\x20proxy:','1687113uTIWhc','\x0a\x0aPlease\x20continue\x20your\x20response\x20based\x20on\x20the\x20tool\x20results\x20above.\x0a\x0a','toLowerCase','stringify','is_error','119sBMZfJ','tool_call','input','role','index','```tool_result\x20tool_use_id=','content_block_start','arguments','tool_use','text_delta','maximum\x20context','substring','toString','{\x22tool_use\x22:','\x0a[After]:\x0a','Input\x20is\x20too\x20long','\x0a\x0aCommon\x20issues:\x0a-\x20All\x20strings\x20must\x20use\x20double\x20quotes\x20(not\x20single\x20quotes)\x0a-\x20All\x20braces\x20and\x20brackets\x20must\x20be\x20balanced\x0a-\x20No\x20trailing\x20commas\x0a-\x20Newlines\x20in\x20strings\x20must\x20be\x20escaped\x20as\x20\x5cn\x0a-\x20Backslashes\x20must\x20be\x20escaped\x20as\x20\x5c\x5c\x0a','[MALFORMED\x20JSON]\x20Tool\x20use\x20JSON\x20could\x20not\x20be\x20parsed\x20or\x20repaired:\x0a','map'];a40_0xff96=function(){return _0x1aa7f;};return a40_0xff96();}export function transformAnthropicRequestToTD(_0x44d632,_0x5b7fac){const _0x533e12=a40_0x5bcc,_0xc0e8ec=calculateConversationDelta(_0x44d632[_0x533e12(0x13d)],_0x5b7fac),_0x43a759=_0xc0e8ec['filter'](_0x27655c=>_0x27655c[_0x533e12(0xe8)]===_0x533e12(0x129))['pop']();if(!_0x43a759)throw new Error('No\x20user\x20message\x20found\x20in\x20request\x20delta');const _0x3a4158=extractTextFromAnthropicMessage(_0x43a759);return{'userMessage':_0x3a4158,'deltaMessages':_0xc0e8ec};}export async function*transformTDStreamToAnthropic(_0x305fdb,_0x3174e9,_0x4f33d4,_0xc0b5a2='',_0x468bed=0x0){const _0x44745e=a40_0x5bcc,_0x53f09a=_0x468bed>0x0?_0x468bed:estimateTokenCount(_0xc0b5a2);let _0x28384a=0x0,_0x1981a0=0x0,_0x3f6131=![];const _0x15794b={'type':_0x44745e(0x121),'message':{'id':_0x3174e9,'type':_0x44745e(0x134),'role':_0x44745e(0xfd),'content':[],'model':_0x4f33d4,'stop_reason':null,'stop_sequence':null,'usage':{'input_tokens':_0x53f09a,'output_tokens':0x0}}};yield _0x15794b;for await(const _0xe393f of _0x305fdb){if(_0x44745e(0x103)in _0xe393f){const _0x3d3fc4=_0xe393f;if(!_0x3f6131){const _0x4f8e4e={'type':_0x44745e(0xeb),'index':_0x1981a0,'content_block':{'type':_0x44745e(0x13f),'text':''}};yield _0x4f8e4e,_0x3f6131=!![];}const _0x43022c={'type':'content_block_delta','index':_0x1981a0,'delta':{'type':'text_delta','text':_0x3d3fc4[_0x44745e(0x103)]}};yield _0x43022c,_0x28384a+=estimateTokenCount(_0x3d3fc4[_0x44745e(0x103)]);}else{if(_0x44745e(0xe6)in _0xe393f){const _0x41a0db=_0xe393f;console[_0x44745e(0x116)](_0x44745e(0x146),_0x41a0db);}else{if(_0x44745e(0xfe)in _0xe393f){const _0x25acea=_0xe393f,_0xebe2b9=determineErrorType(_0x25acea[_0x44745e(0xfe)]),_0x5a2b55=_0xebe2b9===_0x44745e(0x113)?_0x44745e(0x126):_0x44745e(0x133),_0x4bce1a={'type':'message_delta','delta':{'stop_reason':_0x5a2b55,'stop_sequence':null},'usage':{'input_tokens':_0x53f09a,'output_tokens':_0x28384a}};yield _0x4bce1a,yield{'type':'error','error':{'type':_0xebe2b9,'message':_0x25acea[_0x44745e(0xfe)]},'request_id':_0x3174e9};const _0x21cafb={'type':_0x44745e(0x143)};yield _0x21cafb;return;}}}}if(_0x3f6131){const _0x56770a={'type':'content_block_stop','index':_0x1981a0};yield _0x56770a;}const _0x4ef1d8={'type':_0x44745e(0x131),'delta':{'stop_reason':_0x44745e(0x133),'stop_sequence':null},'usage':{'input_tokens':_0x53f09a,'output_tokens':_0x28384a}};yield _0x4ef1d8;const _0x3d3992={'type':_0x44745e(0x143)};yield _0x3d3992;}export function formatAnthropicSSE(_0x5abaca){const _0x4e87c0=a40_0x5bcc;return _0x4e87c0(0x130)+_0x5abaca[_0x4e87c0(0x10d)]+_0x4e87c0(0x12a)+JSON[_0x4e87c0(0xe3)](_0x5abaca)+'\x0a\x0a';}export function mapAnthropicModelToTD(_0x102839){const _0x20e5a9=a40_0x5bcc,_0x30f824={'sonnet':_0x20e5a9(0x118),'claude-sonnet':'sonnet','claude-3-5-sonnet':_0x20e5a9(0x118),'claude-3-sonnet':_0x20e5a9(0x118),'haiku':_0x20e5a9(0x115),'claude-haiku':_0x20e5a9(0x115),'claude-3-5-haiku':_0x20e5a9(0x115),'claude-3-haiku':_0x20e5a9(0x115),'opus':'opus','claude-opus':_0x20e5a9(0x124),'claude-3-opus':_0x20e5a9(0x124)},_0x36a28f=_0x102839[_0x20e5a9(0xe2)]();return _0x30f824[_0x36a28f]||_0x20e5a9(0x118);}export function generateToolPrompt(_0x3e0c7e){const _0x2ff402=a40_0x5bcc;if(_0x3e0c7e==null)return'';if(!Array[_0x2ff402(0x11d)](_0x3e0c7e))throw new SDKError(ErrorCode['LLM_MALFORMED_MESSAGE'],_0x2ff402(0xf8)+typeof _0x3e0c7e);if(_0x3e0c7e[_0x2ff402(0x106)]===0x0)return'';const _0x2b583f=_0x3e0c7e['filter'](_0x2a286d=>_0x2a286d!=null)[_0x2ff402(0xf7)](_0x1453ed=>{const _0xb3ed52=_0x2ff402,_0x357ba0=JSON[_0xb3ed52(0xe3)](_0x1453ed['input_schema']);return _0xb3ed52(0x10b)+_0x1453ed[_0xb3ed52(0x104)]+'\x0a\x0a**Description:**\x20'+(_0x1453ed[_0xb3ed52(0x110)]||_0xb3ed52(0x140))+'\x0a\x0a**Input\x20Schema:**\x0a```json\x0a'+_0x357ba0+_0xb3ed52(0x12f);})[_0x2ff402(0x112)]('\x0a\x0a');return _0x2ff402(0x11f)+_0x2b583f+'\x0a---\x0a';}function escapeMarkdownCodeBlock(_0x5bd951){const _0x5a0aad=a40_0x5bcc;return _0x5bd951[_0x5a0aad(0x145)](/```/g,_0x5a0aad(0x117));}export function extractToolResults(_0x54c371){const _0x42b971=a40_0x5bcc;if(_0x54c371==null)return'';if(!Array[_0x42b971(0x11d)](_0x54c371))throw new SDKError(ErrorCode['LLM_MALFORMED_MESSAGE'],_0x42b971(0x10e)+typeof _0x54c371);const _0x41ceb0=[];for(const _0x2d7af0 of _0x54c371){if(!_0x2d7af0)continue;if(_0x2d7af0[_0x42b971(0xe8)]===_0x42b971(0x129)&&typeof _0x2d7af0[_0x42b971(0x103)]!==_0x42b971(0x119)){if(!Array[_0x42b971(0x11d)](_0x2d7af0['content']))throw new SDKError(ErrorCode[_0x42b971(0x108)],'Invalid\x20message.content\x20type\x20for\x20user\x20role:\x20expected\x20array,\x20got\x20'+typeof _0x2d7af0[_0x42b971(0x103)]);for(const _0x311d3f of _0x2d7af0[_0x42b971(0x103)]){if(!_0x311d3f)continue;if(_0x311d3f[_0x42b971(0x10d)]==='tool_result'&&_0x311d3f[_0x42b971(0xfb)]){let _0x27a067='';if(typeof _0x311d3f[_0x42b971(0x103)]===_0x42b971(0x119))_0x27a067=_0x311d3f[_0x42b971(0x103)];else _0x311d3f[_0x42b971(0x103)]!=null&&Array[_0x42b971(0x11d)](_0x311d3f[_0x42b971(0x103)])&&(_0x27a067=_0x311d3f[_0x42b971(0x103)][_0x42b971(0xfa)](_0x13a970=>_0x13a970&&_0x13a970[_0x42b971(0x10d)]===_0x42b971(0x13f)&&_0x13a970[_0x42b971(0x13f)])[_0x42b971(0xf7)](_0x21b89f=>_0x21b89f[_0x42b971(0x13f)])[_0x42b971(0x112)]('\x0a'));const _0x37eba2=escapeMarkdownCodeBlock(_0x27a067),_0x4b6142=_0x311d3f[_0x42b971(0xe4)]?_0x42b971(0x12c):'';_0x41ceb0['push'](_0x42b971(0xea)+_0x311d3f[_0x42b971(0xfb)]+_0x4b6142+'\x0a'+_0x37eba2+_0x42b971(0x12f));}}}}if(_0x41ceb0[_0x42b971(0x106)]===0x0)return'';return _0x41ceb0[_0x42b971(0x112)]('\x0a\x0a')+_0x42b971(0x148);}function findJsonEndIndex(_0x2c71ae,_0x32efa0){let _0x4bdac0=0x0,_0x37354a=![],_0x14ff37=![];for(let _0x14c253=_0x32efa0;_0x14c253<_0x2c71ae['length'];_0x14c253++){const _0x2e5596=_0x2c71ae[_0x14c253];if(_0x14ff37){_0x14ff37=![];continue;}if(_0x2e5596==='\x5c'){_0x14ff37=!![];continue;}if(_0x2e5596==='\x22'){_0x37354a=!_0x37354a;continue;}if(!_0x37354a){if(_0x2e5596==='{')_0x4bdac0++;else{if(_0x2e5596==='}'){_0x4bdac0--;if(_0x4bdac0===0x0)return _0x14c253+0x1;}}}}return-0x1;}function generateToolCallId(){const _0x709728=a40_0x5bcc;return'toolu_'+Math['random']()[_0x709728(0xf1)](0x24)[_0x709728(0xf0)](0x2,0xf);}function repairIncompleteJson(_0x56a05f,_0x2d997f){const _0xe3e2f8=a40_0x5bcc;try{return JSON[_0xe3e2f8(0x141)](_0x56a05f),_0x56a05f;}catch{const _0x102306=[];let _0x3008d9=![],_0x1a0b1a=![];for(const _0x83099a of _0x56a05f){if(_0x1a0b1a){_0x1a0b1a=![];continue;}if(_0x83099a==='\x5c'){_0x1a0b1a=!![];continue;}if(_0x83099a==='\x22'){_0x3008d9=!_0x3008d9;continue;}if(!_0x3008d9){if(_0x83099a==='{')_0x102306[_0xe3e2f8(0x137)]('{');else{if(_0x83099a==='[')_0x102306[_0xe3e2f8(0x137)]('[');else{if(_0x83099a==='}'&&_0x102306[_0x102306[_0xe3e2f8(0x106)]-0x1]==='{')_0x102306['pop']();else _0x83099a===']'&&_0x102306[_0x102306[_0xe3e2f8(0x106)]-0x1]==='['&&_0x102306[_0xe3e2f8(0x122)]();}}}}let _0xb6b677=_0x56a05f;_0x3008d9&&(_0xb6b677+='\x22');while(_0x102306['length']>0x0){const _0x3907e5=_0x102306[_0xe3e2f8(0x122)]();_0xb6b677+=_0x3907e5==='{'?'}':']';}try{return JSON[_0xe3e2f8(0x141)](_0xb6b677),_0x2d997f&&_0xb6b677!==_0x56a05f&&_0x2d997f[_0xe3e2f8(0x116)]('[JSON\x20REPAIR]\x20Successfully\x20repaired\x20malformed\x20JSON\x0a[Before]:\x0a'+_0x56a05f+_0xe3e2f8(0xf3)+_0xb6b677),_0xb6b677;}catch{return null;}}}export function parseToolCallFromText(_0x3466bc,_0x26e03){const _0x1d34bc=a40_0x5bcc,_0xe2090b=/```tool_use[\s]*\n([\s\S]*)\n?```/,_0x475d9b=_0xe2090b[_0x1d34bc(0x127)](_0x3466bc);if(_0x475d9b){if(!_0x475d9b[0x0][_0x1d34bc(0x105)](_0x1d34bc(0x114))){}else{const _0x2a3db4=_0x475d9b[0x1][_0x1d34bc(0x138)](),_0x11c67a=_0x475d9b[_0x1d34bc(0xe9)],_0x40244a=_0x11c67a+_0x475d9b[0x0][_0x1d34bc(0x106)];try{const _0x486c9c=JSON[_0x1d34bc(0x141)](_0x2a3db4);if(_0x486c9c[_0x1d34bc(0xed)]&&_0x486c9c[_0x1d34bc(0xed)][_0x1d34bc(0x104)])return{'id':_0x486c9c[_0x1d34bc(0xed)]['id']||generateToolCallId(),'name':_0x486c9c['tool_use'][_0x1d34bc(0x104)],'input':_0x486c9c['tool_use']['input']||{},'startIndex':_0x11c67a,'endIndex':_0x40244a};if(_0x486c9c[_0x1d34bc(0x104)]&&typeof _0x486c9c[_0x1d34bc(0x104)]===_0x1d34bc(0x119)&&_0x486c9c[_0x1d34bc(0x104)]['trim']()[_0x1d34bc(0x106)]>0x0)return{'id':_0x486c9c['id']||generateToolCallId(),'name':_0x486c9c['name'],'input':_0x486c9c['input']||_0x486c9c[_0x1d34bc(0xec)]||{},'startIndex':_0x11c67a,'endIndex':_0x40244a};}catch{const _0x26b371=repairIncompleteJson(_0x2a3db4,_0x26e03);if(_0x26b371)try{const _0x29b3b8=JSON['parse'](_0x26b371);if(_0x29b3b8[_0x1d34bc(0xed)]&&_0x29b3b8[_0x1d34bc(0xed)][_0x1d34bc(0x104)])return{'id':_0x29b3b8[_0x1d34bc(0xed)]['id']||generateToolCallId(),'name':_0x29b3b8[_0x1d34bc(0xed)][_0x1d34bc(0x104)],'input':_0x29b3b8['tool_use']['input']||{},'startIndex':_0x11c67a,'endIndex':_0x40244a};if(_0x29b3b8[_0x1d34bc(0x104)]&&typeof _0x29b3b8['name']==='string'&&_0x29b3b8[_0x1d34bc(0x104)]['trim']()[_0x1d34bc(0x106)]>0x0)return{'id':_0x29b3b8['id']||generateToolCallId(),'name':_0x29b3b8['name'],'input':_0x29b3b8[_0x1d34bc(0xe7)]||_0x29b3b8[_0x1d34bc(0xec)]||{},'startIndex':_0x11c67a,'endIndex':_0x40244a};}catch{}}}}const _0x19b575=/\{"tool_use":/g,_0x39603c=_0x19b575[_0x1d34bc(0x127)](_0x3466bc);if(!_0x39603c)return null;const _0x368714=_0x39603c[_0x1d34bc(0xe9)];let _0x24e071=findJsonEndIndex(_0x3466bc,_0x368714);if(_0x24e071===-0x1)return null;const _0x56b9d1=_0x3466bc['substring'](_0x368714,_0x24e071);try{const _0x1b0ba4=JSON['parse'](_0x56b9d1);if(_0x1b0ba4[_0x1d34bc(0xed)]&&_0x1b0ba4[_0x1d34bc(0xed)]['id']&&_0x1b0ba4[_0x1d34bc(0xed)]['name'])return{'id':_0x1b0ba4['tool_use']['id'],'name':_0x1b0ba4[_0x1d34bc(0xed)][_0x1d34bc(0x104)],'input':_0x1b0ba4[_0x1d34bc(0xed)][_0x1d34bc(0xe7)]||{},'startIndex':_0x368714,'endIndex':_0x24e071};}catch{const _0x5c0334=repairIncompleteJson(_0x56b9d1,_0x26e03);if(_0x5c0334)try{const _0xe5aec1=JSON['parse'](_0x5c0334);if(_0xe5aec1['tool_use']&&_0xe5aec1[_0x1d34bc(0xed)]['id']&&_0xe5aec1[_0x1d34bc(0xed)][_0x1d34bc(0x104)])return{'id':_0xe5aec1[_0x1d34bc(0xed)]['id'],'name':_0xe5aec1[_0x1d34bc(0xed)][_0x1d34bc(0x104)],'input':_0xe5aec1[_0x1d34bc(0xed)][_0x1d34bc(0xe7)]||{},'startIndex':_0x368714,'endIndex':_0x24e071};}catch{return null;}return null;}return null;}export function*generateToolCallEvents(_0x1fcc9a,_0x386393,_0x2ae162){const _0x55ff75=a40_0x5bcc,_0x546192={'type':'content_block_start','index':_0x386393,'content_block':{'type':'tool_use','id':_0x1fcc9a['id'],'name':_0x1fcc9a[_0x55ff75(0x104)],'input':{}}};yield _0x546192;const _0x39e4a5=JSON['stringify'](_0x1fcc9a[_0x55ff75(0xe7)]),_0x3a8132={'type':_0x55ff75(0x107),'index':_0x386393,'delta':{'type':_0x55ff75(0x102),'partial_json':_0x39e4a5}};yield _0x3a8132;const _0x39909e={'type':_0x55ff75(0x101),'index':_0x386393};yield _0x39909e;const _0x454115={'type':'message_delta','delta':{'stop_reason':'tool_use','stop_sequence':null},'usage':{'input_tokens':_0x2ae162,'output_tokens':0x0}};yield _0x454115;const _0x5d2991={'type':_0x55ff75(0x143)};yield _0x5d2991;}export async function*transformTDStreamWithToolDetection(_0x13a0e1,_0x10d264,_0x4519a6,_0x5c932a,_0x240a76='',_0x317f02=0x0){const _0x143652=a40_0x5bcc,_0x574ab0=_0x317f02>0x0?_0x317f02:estimateTokenCount(_0x240a76);let _0x2b39ab=0x0,_0xf12774=0x0,_0x353868=![],_0x4bb60d='',_0x2fafb2=0x0,_0x2bd6f4=![];const _0x23c940=0xc8,_0x1f9a06={'type':_0x143652(0x121),'message':{'id':_0x10d264,'type':_0x143652(0x134),'role':_0x143652(0xfd),'content':[],'model':_0x4519a6,'stop_reason':null,'stop_sequence':null,'usage':{'input_tokens':_0x574ab0,'output_tokens':0x0}}};yield _0x1f9a06;for await(const _0x5735da of _0x13a0e1){if(_0x143652(0x103)in _0x5735da){const _0x2834e4=_0x5735da;_0x4bb60d+=_0x2834e4[_0x143652(0x103)];const _0x19f291=_0x4bb60d[_0x143652(0x11a)]('```tool_use'),_0x4431d6=_0x4bb60d[_0x143652(0x11a)](_0x143652(0xf2)),_0x10d015=_0x19f291!==-0x1?_0x4431d6!==-0x1?Math[_0x143652(0xf9)](_0x19f291,_0x4431d6):_0x19f291:_0x4431d6;if(_0x10d015!==-0x1){const _0x38f57b=[];let _0x5b52d8=0x0;while(!![]){const _0x16bf5b=_0x4bb60d['substring'](_0x5b52d8),_0x4c26e4=parseToolCallFromText(_0x16bf5b,_0x5c932a);if(!_0x4c26e4)break;_0x38f57b[_0x143652(0x137)]({'id':_0x4c26e4['id'],'name':_0x4c26e4['name'],'input':_0x4c26e4[_0x143652(0xe7)],'startIndex':_0x5b52d8+_0x4c26e4[_0x143652(0x13c)],'endIndex':_0x5b52d8+_0x4c26e4[_0x143652(0x135)]}),_0x5b52d8+=_0x4c26e4[_0x143652(0x135)];}if(_0x38f57b[_0x143652(0x106)]>0x0){const _0xa7325c=_0x38f57b[_0x38f57b[_0x143652(0x106)]-0x1];_0x2bd6f4=!![];_0x38f57b[_0x143652(0x106)]>0x1?_0x5c932a?.[_0x143652(0x10a)](_0x143652(0x11c)+_0xa7325c[_0x143652(0x104)]):_0x5c932a?.[_0x143652(0x10a)](_0x143652(0x132)+_0xa7325c[_0x143652(0x104)]);const _0x3cd184=_0x4bb60d['substring'](_0x2fafb2,_0xa7325c['startIndex'])[_0x143652(0x138)]();if(_0x3cd184){if(!_0x353868){const _0x3ec721={'type':_0x143652(0xeb),'index':_0xf12774,'content_block':{'type':_0x143652(0x13f),'text':''}};yield _0x3ec721,_0x353868=!![];}const _0x43c542={'type':_0x143652(0x107),'index':_0xf12774,'delta':{'type':'text_delta','text':_0x3cd184}};yield _0x43c542,_0x2b39ab+=estimateTokenCount(_0x3cd184);}if(_0x353868){const _0x1e1dc9={'type':'content_block_stop','index':_0xf12774};yield _0x1e1dc9,_0xf12774++,_0x353868=![];}for(const _0x1f5bce of generateToolCallEvents(_0xa7325c,_0xf12774,_0x574ab0)){_0x1f5bce[_0x143652(0x10d)]===_0x143652(0x131)&&(_0x1f5bce[_0x143652(0xfc)][_0x143652(0x142)]=_0x2b39ab),yield _0x1f5bce;}return;}const _0x2d6ecd=_0x4bb60d[_0x143652(0x11e)](_0x143652(0x123))&&_0x4bb60d[_0x143652(0x11a)]('```',_0x4bb60d[_0x143652(0x11a)](_0x143652(0x123))+0xb)!==-0x1,_0x195883=_0x4bb60d[_0x143652(0x11e)](_0x143652(0xf2))&&findJsonEndIndex(_0x4bb60d,_0x4bb60d[_0x143652(0x11a)](_0x143652(0xf2)))!==-0x1;if(_0x2d6ecd||_0x195883){_0x2bd6f4=!![];let _0x30f801='';if(_0x2d6ecd){const _0xf172e9=_0x4bb60d['indexOf']('```tool_use'),_0x459e99=_0x4bb60d[_0x143652(0x11a)](_0x143652(0x114),_0xf172e9+0xb);_0x459e99!==-0x1?_0x30f801=_0x4bb60d['substring'](_0xf172e9,_0x459e99+0x3):_0x30f801=_0x4bb60d[_0x143652(0xf0)](_0xf172e9);}else{if(_0x195883){const _0xef3789=_0x4bb60d[_0x143652(0x11a)](_0x143652(0xf2)),_0x1add8b=findJsonEndIndex(_0x4bb60d,_0xef3789);_0x1add8b!==-0x1?_0x30f801=_0x4bb60d['substring'](_0xef3789,_0x1add8b):_0x30f801=_0x4bb60d['substring'](_0xef3789);}}_0x5c932a&&_0x5c932a['error'](_0x143652(0xf6)+_0x30f801);_0x5c932a?.[_0x143652(0x10a)](_0x143652(0x100)),_0x5c932a?.[_0x143652(0x10a)](_0x143652(0x12b),_0x30f801);const _0x508ae3=_0x4bb60d[_0x143652(0xf0)](_0x2fafb2,_0x10d015)[_0x143652(0x138)]();if(_0x508ae3){if(!_0x353868){const _0x48cf5e={'type':_0x143652(0xeb),'index':_0xf12774,'content_block':{'type':_0x143652(0x13f),'text':''}};yield _0x48cf5e,_0x353868=!![];}const _0x5d2e1b={'type':_0x143652(0x107),'index':_0xf12774,'delta':{'type':_0x143652(0xee),'text':_0x508ae3}};yield _0x5d2e1b,_0x2b39ab+=estimateTokenCount(_0x508ae3);}if(_0x353868){const _0x440b30={'type':'content_block_stop','index':_0xf12774};yield _0x440b30,_0xf12774++,_0x353868=![];}const _0x25eb36=_0x143652(0x13a)+_0x30f801+_0x143652(0xf5),_0x2d85cd={'type':_0x143652(0xeb),'index':_0xf12774,'content_block':{'type':'text','text':''}};yield _0x2d85cd;const _0x551d7c={'type':_0x143652(0x107),'index':_0xf12774,'delta':{'type':'text_delta','text':_0x25eb36}};yield _0x551d7c;const _0x3dd335={'type':_0x143652(0x101),'index':_0xf12774};yield _0x3dd335;const _0x1ef55e={'type':'message_delta','delta':{'stop_reason':'end_turn','stop_sequence':null},'usage':{'input_tokens':_0x574ab0,'output_tokens':_0x2b39ab}};yield _0x1ef55e;const _0x3f9a57={'type':'message_stop'};yield _0x3f9a57;return;}const _0x48e21c=_0x4bb60d[_0x143652(0xf0)](_0x2fafb2,_0x10d015);if(_0x48e21c){if(!_0x353868){const _0x57b8ea={'type':'content_block_start','index':_0xf12774,'content_block':{'type':'text','text':''}};yield _0x57b8ea,_0x353868=!![];}const _0x39f329={'type':_0x143652(0x107),'index':_0xf12774,'delta':{'type':_0x143652(0xee),'text':_0x48e21c}};yield _0x39f329,_0x2b39ab+=estimateTokenCount(_0x48e21c),_0x2fafb2=_0x10d015;}continue;}const _0x202fbd=_0x4bb60d[_0x143652(0x106)]-_0x23c940;if(_0x202fbd>_0x2fafb2){const _0x2ce44e=_0x4bb60d['substring'](_0x2fafb2,_0x202fbd);if(_0x2ce44e){if(!_0x353868){const _0x1160c3={'type':_0x143652(0xeb),'index':_0xf12774,'content_block':{'type':_0x143652(0x13f),'text':''}};yield _0x1160c3,_0x353868=!![];}const _0x2d0046={'type':'content_block_delta','index':_0xf12774,'delta':{'type':_0x143652(0xee),'text':_0x2ce44e}};yield _0x2d0046,_0x2b39ab+=estimateTokenCount(_0x2ce44e),_0x2fafb2=_0x202fbd;}}}else{if(_0x143652(0xfe)in _0x5735da){const _0x52acfe=_0x5735da,_0x39a4ad=determineErrorType(_0x52acfe['error'],_0x5c932a),_0xd94c48=_0x39a4ad===_0x143652(0x113)?_0x143652(0x126):_0x143652(0x133),_0x593a2f={'type':_0x143652(0x131),'delta':{'stop_reason':_0xd94c48,'stop_sequence':null},'usage':{'input_tokens':_0x574ab0,'output_tokens':_0x2b39ab}};yield _0x593a2f,yield{'type':_0x143652(0xfe),'error':{'type':_0x39a4ad,'message':_0x52acfe[_0x143652(0xfe)]},'request_id':_0x10d264};const _0x8b6016={'type':'message_stop'};yield _0x8b6016;return;}}}if(!_0x2bd6f4){const _0x3550f4=_0x4bb60d[_0x143652(0xf0)](_0x2fafb2);if(_0x3550f4){if(!_0x353868){const _0x1303fc={'type':'content_block_start','index':_0xf12774,'content_block':{'type':'text','text':''}};yield _0x1303fc,_0x353868=!![];}const _0x247adc={'type':_0x143652(0x107),'index':_0xf12774,'delta':{'type':'text_delta','text':_0x3550f4}};yield _0x247adc,_0x2b39ab+=estimateTokenCount(_0x3550f4);}if(_0x353868){const _0x46df34={'type':_0x143652(0x101),'index':_0xf12774};yield _0x46df34;}const _0x2a96c3={'type':'message_delta','delta':{'stop_reason':'end_turn','stop_sequence':null},'usage':{'input_tokens':_0x574ab0,'output_tokens':_0x2b39ab}};yield _0x2a96c3;const _0x516546={'type':_0x143652(0x143)};yield _0x516546;}}export{generateMessageId};
1
+ function a40_0x1e4a(_0x2bf55a,_0x4cb420){const _0x74267e=a40_0x7426();return a40_0x1e4a=function(_0x1e4a86,_0x1b1582){_0x1e4a86=_0x1e4a86-0xd0;let _0x19b2a8=_0x74267e[_0x1e4a86];return _0x19b2a8;},a40_0x1e4a(_0x2bf55a,_0x4cb420);}(function(_0x28cc30,_0x544edd){const _0x314e73=a40_0x1e4a,_0x5921f0=_0x28cc30();while(!![]){try{const _0x47fc0d=parseInt(_0x314e73(0x113))/0x1+-parseInt(_0x314e73(0x125))/0x2*(parseInt(_0x314e73(0xf3))/0x3)+parseInt(_0x314e73(0x120))/0x4+-parseInt(_0x314e73(0x11d))/0x5*(-parseInt(_0x314e73(0x106))/0x6)+parseInt(_0x314e73(0x12d))/0x7+parseInt(_0x314e73(0x11c))/0x8+parseInt(_0x314e73(0xe9))/0x9*(parseInt(_0x314e73(0x10c))/0xa);if(_0x47fc0d===_0x544edd)break;else _0x5921f0['push'](_0x5921f0['shift']());}catch(_0x1a1f52){_0x5921f0['push'](_0x5921f0['shift']());}}}(a40_0x7426,0x1bb00));function a40_0x7426(){const _0x37d08b=['debug','isArray','Input\x20is\x20too\x20long','push','6rsDLMs','ceil','\x5c`\x5c`\x5c`','event:\x20','Invalid\x20message.content\x20type\x20for\x20user\x20role:\x20expected\x20array,\x20got\x20','No\x20user\x20message\x20found\x20in\x20request\x20delta','system','description','444388ApzdSv','msg_','model_context_window_exceeded','Tool\x20call\x20detected:\x20','end_turn','indexOf','random','\x0a---\x0a','output_tokens','haiku','length','request_too_large','Invalid\x20message.content\x20type:\x20expected\x20string\x20or\x20array,\x20got\x20','\x20error=true','substring','context\x20length','Malformed\x20tool_use\x20JSON\x20detected','name','LLM_MALFORMED_MESSAGE','message_stop','role','message','text','input','toString','pop','\x0a\x0aCommon\x20issues:\x0a-\x20All\x20strings\x20must\x20use\x20double\x20quotes\x20(not\x20single\x20quotes)\x0a-\x20All\x20braces\x20and\x20brackets\x20must\x20be\x20balanced\x0a-\x20No\x20trailing\x20commas\x0a-\x20Newlines\x20in\x20strings\x20must\x20be\x20escaped\x20as\x20\x5cn\x0a-\x20Backslashes\x20must\x20be\x20escaped\x20as\x20\x5c\x5c\x0a','slice','content','endIndex','warn','549yMoIdQ','type','trim','index','[CONTEXT\x20LENGTH\x20ERROR]\x20','```tool_use','input_schema','toLowerCase','min','tool_use','103419XCVFlR','\x0a\x0a**Input\x20Schema:**\x0a```json\x0a','endsWith','No\x20description','stringify','[JSON\x20REPAIR]\x20Successfully\x20repaired\x20malformed\x20JSON\x0a[Before]:\x0a','content_block_start','```tool_result\x20tool_use_id=','content_block_delta','[MALFORMED\x20JSON]\x20Tool\x20use\x20JSON\x20could\x20not\x20be\x20parsed\x20or\x20repaired:\x0a','Multiple\x20tool\x20calls\x20detected,\x20using\x20only\x20the\x20last\x20one:\x20','messages','filter','error','message_delta','join','message_start','text_delta','user','77892jyGXIe','startIndex','parse','string','{\x22tool_use\x22:','api_error','5730YODetu','usage','tool_use_id','sonnet','exec','opus','is_error','24401nmrSvx','Malformed\x20content:','tools','content_block_stop','includes','replace','\x0a\x0a**Description:**\x20','\x0a```','map','65624LQVAxM','5nyyQuM','```','toolu_','291216FbyiRD'];a40_0x7426=function(){return _0x37d08b;};return a40_0x7426();}import{SDKError,ErrorCode}from'../sdk/errors.js';function estimateTokenCount(_0x3acbe5){const _0x1b56dd=a40_0x1e4a;if(!_0x3acbe5||_0x3acbe5['length']===0x0)return 0x0;return Math['ceil'](_0x3acbe5[_0x1b56dd(0xd4)]/3.7);}export function determineErrorType(_0x21fd55,_0x2e7d10){const _0x2e217e=a40_0x1e4a,_0x10abe4=_0x21fd55[_0x2e217e(0x117)](_0x2e217e(0x123))||_0x21fd55[_0x2e217e(0x117)](_0x2e217e(0xd9))||_0x21fd55[_0x2e217e(0x117)]('maximum\x20context');if(_0x10abe4)return _0x2e7d10?.['error'](_0x2e217e(0xed)+_0x21fd55),_0x2e217e(0xd5);return _0x2e7d10?.[_0x2e217e(0x100)]('[API\x20ERROR]\x20'+_0x21fd55),_0x2e217e(0x10b);}export function estimateInputTokensFromRequest(_0x88ae31){const _0x384b38=a40_0x1e4a;let _0x383fd3=0x0;if(typeof _0x88ae31[_0x384b38(0x12b)]==='string')_0x383fd3+=_0x88ae31[_0x384b38(0x12b)][_0x384b38(0xd4)];else{if(Array[_0x384b38(0x122)](_0x88ae31[_0x384b38(0x12b)]))for(const _0x5b6c38 of _0x88ae31[_0x384b38(0x12b)]){_0x5b6c38&&typeof _0x5b6c38['text']===_0x384b38(0x109)&&(_0x383fd3+=_0x5b6c38[_0x384b38(0xe0)][_0x384b38(0xd4)]);}}if(Array[_0x384b38(0x122)](_0x88ae31[_0x384b38(0x115)]))for(const _0x5ce31b of _0x88ae31[_0x384b38(0x115)]){_0x5ce31b&&(_0x383fd3+=_0x5ce31b[_0x384b38(0xdb)][_0x384b38(0xd4)],_0x383fd3+=_0x5ce31b[_0x384b38(0x12c)]?.['length']||0x0,_0x383fd3+=JSON['stringify'](_0x5ce31b['input_schema'])['length']);}if(Array[_0x384b38(0x122)](_0x88ae31[_0x384b38(0xfe)]))for(const _0x30127d of _0x88ae31[_0x384b38(0xfe)]){if(!_0x30127d)continue;if(typeof _0x30127d[_0x384b38(0xe6)]===_0x384b38(0x109))_0x383fd3+=_0x30127d[_0x384b38(0xe6)][_0x384b38(0xd4)];else{if(Array[_0x384b38(0x122)](_0x30127d[_0x384b38(0xe6)]))for(const _0x225c95 of _0x30127d[_0x384b38(0xe6)]){if(!_0x225c95)continue;if(_0x225c95[_0x384b38(0xea)]==='text'&&_0x225c95[_0x384b38(0xe0)])_0x383fd3+=_0x225c95[_0x384b38(0xe0)][_0x384b38(0xd4)];else{if(_0x225c95[_0x384b38(0xea)]==='tool_use'&&_0x225c95[_0x384b38(0xe1)])_0x383fd3+=JSON[_0x384b38(0xf7)](_0x225c95[_0x384b38(0xe1)])['length'];else{if(_0x225c95[_0x384b38(0xea)]==='tool_result'&&_0x225c95[_0x384b38(0xe6)]){if(typeof _0x225c95[_0x384b38(0xe6)]===_0x384b38(0x109))_0x383fd3+=_0x225c95['content'][_0x384b38(0xd4)];else{if(Array[_0x384b38(0x122)](_0x225c95[_0x384b38(0xe6)]))for(const _0x37d479 of _0x225c95[_0x384b38(0xe6)]){_0x37d479&&_0x37d479[_0x384b38(0xea)]===_0x384b38(0xe0)&&_0x37d479[_0x384b38(0xe0)]&&(_0x383fd3+=_0x37d479['text'][_0x384b38(0xd4)]);}}}}}}}}return Math[_0x384b38(0x126)](_0x383fd3/3.7);}function generateMessageId(){const _0xe0c104=a40_0x1e4a;return _0xe0c104(0x12e)+Math[_0xe0c104(0xd0)]()[_0xe0c104(0xe2)](0x24)[_0xe0c104(0xd8)](0x2,0xf)+Math[_0xe0c104(0xd0)]()[_0xe0c104(0xe2)](0x24)['substring'](0x2,0xf);}export function extractTextFromAnthropicMessage(_0x5444d3){const _0x37c3d8=a40_0x1e4a;if(typeof _0x5444d3[_0x37c3d8(0xe6)]===_0x37c3d8(0x109))return _0x5444d3[_0x37c3d8(0xe6)];if(_0x5444d3[_0x37c3d8(0xe6)]==null)return'';if(!Array[_0x37c3d8(0x122)](_0x5444d3[_0x37c3d8(0xe6)]))throw new SDKError(ErrorCode['LLM_MALFORMED_MESSAGE'],_0x37c3d8(0xd6)+typeof _0x5444d3[_0x37c3d8(0xe6)]);return _0x5444d3['content']['filter'](_0x173ec2=>_0x173ec2&&_0x173ec2[_0x37c3d8(0xea)]==='text'&&_0x173ec2[_0x37c3d8(0xe0)])[_0x37c3d8(0x11b)](_0x9f3a1b=>_0x9f3a1b['text'])[_0x37c3d8(0x102)]('\x0a');}export function calculateConversationDelta(_0x36c03c,_0x1bf126){const _0x3f5fc4=a40_0x1e4a;if(_0x1bf126['length']===0x0)return _0x36c03c;const _0x12b974=_0x1bf126[_0x3f5fc4(0xd4)];return _0x36c03c[_0x3f5fc4(0xe5)](_0x12b974);}export function transformAnthropicRequestToTD(_0xb4c2e4,_0x46e552){const _0x348599=a40_0x1e4a,_0x38251f=calculateConversationDelta(_0xb4c2e4['messages'],_0x46e552),_0x583322=_0x38251f[_0x348599(0xff)](_0x33c7bb=>_0x33c7bb[_0x348599(0xde)]===_0x348599(0x105))[_0x348599(0xe3)]();if(!_0x583322)throw new Error(_0x348599(0x12a));const _0x5f3a4c=extractTextFromAnthropicMessage(_0x583322);return{'userMessage':_0x5f3a4c,'deltaMessages':_0x38251f};}export async function*transformTDStreamToAnthropic(_0x5c298e,_0x32a985,_0x5060d3,_0x421190='',_0x30e2be=0x0){const _0x1ffda6=a40_0x1e4a,_0x12589f=_0x30e2be>0x0?_0x30e2be:estimateTokenCount(_0x421190);let _0x4ecd27=0x0,_0x4bbcda=0x0,_0x3b22d8=![];const _0x3df36f={'type':'message_start','message':{'id':_0x32a985,'type':_0x1ffda6(0xdf),'role':'assistant','content':[],'model':_0x5060d3,'stop_reason':null,'stop_sequence':null,'usage':{'input_tokens':_0x12589f,'output_tokens':0x0}}};yield _0x3df36f;for await(const _0x589c04 of _0x5c298e){if('content'in _0x589c04){const _0x59172c=_0x589c04;if(!_0x3b22d8){const _0x34796f={'type':'content_block_start','index':_0x4bbcda,'content_block':{'type':'text','text':''}};yield _0x34796f,_0x3b22d8=!![];}const _0x8c0888={'type':'content_block_delta','index':_0x4bbcda,'delta':{'type':'text_delta','text':_0x59172c[_0x1ffda6(0xe6)]}};yield _0x8c0888,_0x4ecd27+=estimateTokenCount(_0x59172c[_0x1ffda6(0xe6)]);}else{if('tool_call'in _0x589c04){const _0x305dad=_0x589c04;console[_0x1ffda6(0xe8)]('Tool\x20calls\x20not\x20yet\x20supported\x20in\x20proxy:',_0x305dad);}else{if('error'in _0x589c04){const _0x247bb2=_0x589c04,_0x2bfde5=determineErrorType(_0x247bb2[_0x1ffda6(0x100)]),_0x4fd869=_0x2bfde5==='request_too_large'?_0x1ffda6(0x12f):_0x1ffda6(0x131),_0x292e38={'type':'message_delta','delta':{'stop_reason':_0x4fd869,'stop_sequence':null},'usage':{'input_tokens':_0x12589f,'output_tokens':_0x4ecd27}};yield _0x292e38,yield{'type':_0x1ffda6(0x100),'error':{'type':_0x2bfde5,'message':_0x247bb2['error']},'request_id':_0x32a985};const _0x234eac={'type':'message_stop'};yield _0x234eac;return;}}}}if(_0x3b22d8){const _0x2747dd={'type':_0x1ffda6(0x116),'index':_0x4bbcda};yield _0x2747dd;}const _0x524aa5={'type':_0x1ffda6(0x101),'delta':{'stop_reason':_0x1ffda6(0x131),'stop_sequence':null},'usage':{'input_tokens':_0x12589f,'output_tokens':_0x4ecd27}};yield _0x524aa5;const _0x596cd7={'type':_0x1ffda6(0xdd)};yield _0x596cd7;}export function formatAnthropicSSE(_0x1d6e8f){const _0x883634=a40_0x1e4a;return _0x883634(0x128)+_0x1d6e8f[_0x883634(0xea)]+'\x0adata:\x20'+JSON[_0x883634(0xf7)](_0x1d6e8f)+'\x0a\x0a';}export function mapAnthropicModelToTD(_0x391e01){const _0x57c564=a40_0x1e4a,_0xe9ee7e={'sonnet':_0x57c564(0x10f),'claude-sonnet':'sonnet','claude-3-5-sonnet':_0x57c564(0x10f),'claude-3-sonnet':_0x57c564(0x10f),'haiku':'haiku','claude-haiku':_0x57c564(0xd3),'claude-3-5-haiku':_0x57c564(0xd3),'claude-3-haiku':'haiku','opus':_0x57c564(0x111),'claude-opus':_0x57c564(0x111),'claude-3-opus':_0x57c564(0x111)},_0x5564a4=_0x391e01[_0x57c564(0xf0)]();return _0xe9ee7e[_0x5564a4]||'sonnet';}export function generateToolPrompt(_0x34c259){const _0x5ddaa5=a40_0x1e4a;if(_0x34c259==null)return'';if(!Array[_0x5ddaa5(0x122)](_0x34c259))throw new SDKError(ErrorCode[_0x5ddaa5(0xdc)],'Invalid\x20tools\x20type:\x20expected\x20array,\x20got\x20'+typeof _0x34c259);if(_0x34c259[_0x5ddaa5(0xd4)]===0x0)return'';const _0x577868=_0x34c259[_0x5ddaa5(0xff)](_0x26a313=>_0x26a313!=null)[_0x5ddaa5(0x11b)](_0x2b49ef=>{const _0x38753a=_0x5ddaa5,_0x5aa973=JSON[_0x38753a(0xf7)](_0x2b49ef[_0x38753a(0xef)]);return'##\x20Tool:\x20'+_0x2b49ef[_0x38753a(0xdb)]+_0x38753a(0x119)+(_0x2b49ef['description']||_0x38753a(0xf6))+_0x38753a(0xf4)+_0x5aa973+'\x0a```';})['join']('\x0a\x0a');return'\x0a#\x20How\x20to\x20Use\x20Tools\x0a\x0aTo\x20use\x20a\x20tool,\x20output\x20the\x20tool\x20call\x20in\x20a\x20markdown\x20code\x20block:\x0a\x0a```tool_use\x0a{\x22tool_use\x22:{\x22id\x22:\x22toolu_<random>\x22,\x22name\x22:\x22<tool_name>\x22,\x22input\x22:{<parameters>}}}\x0a```\x0a\x0a**IMPORTANT:**\x0a-\x20**Output\x20only\x20ONE\x20tool_use\x20at\x20a\x20time**\x20-\x20Never\x20output\x20multiple\x20tool\x20calls\x20in\x20a\x20single\x20response\x0a-\x20Use\x20the\x20precise\x20parameter\x20names\x20and\x20types\x20as\x20defined\x20in\x20the\x20JSON\x20schema.\x0a-\x20Wrap\x20the\x20JSON\x20in\x20a\x20markdown\x20code\x20block\x20with\x20```tool_use\x0a-\x20The\x20JSON\x20must\x20be\x20valid\x20and\x20properly\x20formatted.\x20Ensure\x20all\x20strings\x20are\x20double\x20quoted.\x0a-\x20Generate\x20a\x20unique\x20random\x20ID\x20starting\x20with\x20\x22toolu_\x22\x0a-\x20After\x20outputting\x20the\x20tool\x20use,\x20stop\x20and\x20wait\x20for\x20the\x20tool\x20result\x0a-\x20Tool\x20results\x20will\x20be\x20provided\x20in\x20markdown\x20code\x20blocks\x20with\x20```tool_result\x20tool_use_id=<id>\x0a-\x20Once\x20you\x20receive\x20a\x20tool\x20result,\x20you\x20may\x20call\x20another\x20tool\x20if\x20needed,\x20or\x20continue\x20your\x20response\x20naturally\x0a\x0a**Example\x201\x20-\x20Simple\x20tool:**\x0aUser:\x20\x22What\x27s\x2025\x20*\x204?\x22\x0aAssistant:\x20I\x27ll\x20calculate\x20that\x20for\x20you.\x0a\x0a```tool_use\x0a{\x22tool_use\x22:{\x22id\x22:\x22toolu_abc123\x22,\x22name\x22:\x22calculator\x22,\x22input\x22:{\x22expression\x22:\x2225\x20*\x204\x22}}}\x0a```\x0a\x0a**Example\x202\x20-\x20Tool\x20with\x20multiline\x20strings\x20(proper\x20escaping):**\x0aUser:\x20\x22Edit\x20the\x20file\x20to\x20add\x20a\x20newline\x22\x0aAssistant:\x20I\x27ll\x20edit\x20the\x20file\x20with\x20proper\x20JSON\x20escaping.\x0a\x0a```tool_use\x0a{\x22tool_use\x22:{\x22id\x22:\x22toolu_def456\x22,\x22name\x22:\x22Edit\x22,\x22input\x22:{\x22file_path\x22:\x22test.ts\x22,\x22old_string\x22:\x22const\x20x\x20=\x201;\x22,\x22new_string\x22:\x22const\x20x\x20=\x201;\x5cnconst\x20y\x20=\x202;\x22}}}\x0a```\x0a\x0a#\x20Available\x20Tools\x0a\x0a'+_0x577868+_0x5ddaa5(0xd1);}function escapeMarkdownCodeBlock(_0x50de98){const _0x4e5568=a40_0x1e4a;return _0x50de98[_0x4e5568(0x118)](/```/g,_0x4e5568(0x127));}export function extractToolResults(_0x7ef243){const _0x471ff9=a40_0x1e4a;if(_0x7ef243==null)return'';if(!Array['isArray'](_0x7ef243))throw new SDKError(ErrorCode[_0x471ff9(0xdc)],'Invalid\x20messages\x20type:\x20expected\x20array,\x20got\x20'+typeof _0x7ef243);const _0x528172=[];for(const _0x392546 of _0x7ef243){if(!_0x392546)continue;if(_0x392546[_0x471ff9(0xde)]==='user'&&typeof _0x392546[_0x471ff9(0xe6)]!==_0x471ff9(0x109)){if(!Array[_0x471ff9(0x122)](_0x392546[_0x471ff9(0xe6)]))throw new SDKError(ErrorCode[_0x471ff9(0xdc)],_0x471ff9(0x129)+typeof _0x392546['content']);for(const _0x20be7c of _0x392546[_0x471ff9(0xe6)]){if(!_0x20be7c)continue;if(_0x20be7c[_0x471ff9(0xea)]==='tool_result'&&_0x20be7c[_0x471ff9(0x10e)]){let _0x13d51c='';if(typeof _0x20be7c['content']===_0x471ff9(0x109))_0x13d51c=_0x20be7c[_0x471ff9(0xe6)];else _0x20be7c[_0x471ff9(0xe6)]!=null&&Array[_0x471ff9(0x122)](_0x20be7c[_0x471ff9(0xe6)])&&(_0x13d51c=_0x20be7c[_0x471ff9(0xe6)]['filter'](_0x363ad7=>_0x363ad7&&_0x363ad7[_0x471ff9(0xea)]===_0x471ff9(0xe0)&&_0x363ad7[_0x471ff9(0xe0)])[_0x471ff9(0x11b)](_0x378b72=>_0x378b72[_0x471ff9(0xe0)])[_0x471ff9(0x102)]('\x0a'));const _0x3c7941=escapeMarkdownCodeBlock(_0x13d51c),_0x19e06a=_0x20be7c[_0x471ff9(0x112)]?_0x471ff9(0xd7):'';_0x528172[_0x471ff9(0x124)](_0x471ff9(0xfa)+_0x20be7c[_0x471ff9(0x10e)]+_0x19e06a+'\x0a'+_0x3c7941+_0x471ff9(0x11a));}}}}if(_0x528172[_0x471ff9(0xd4)]===0x0)return'';return _0x528172['join']('\x0a\x0a')+'\x0a\x0aPlease\x20continue\x20your\x20response\x20based\x20on\x20the\x20tool\x20results\x20above.\x0a\x0a';}function findJsonEndIndex(_0x24bf0d,_0x265972){const _0x3d4e16=a40_0x1e4a;let _0x53c727=0x0,_0x3301d8=![],_0x30925a=![];for(let _0x286360=_0x265972;_0x286360<_0x24bf0d[_0x3d4e16(0xd4)];_0x286360++){const _0x27b44b=_0x24bf0d[_0x286360];if(_0x30925a){_0x30925a=![];continue;}if(_0x27b44b==='\x5c'){_0x30925a=!![];continue;}if(_0x27b44b==='\x22'){_0x3301d8=!_0x3301d8;continue;}if(!_0x3301d8){if(_0x27b44b==='{')_0x53c727++;else{if(_0x27b44b==='}'){_0x53c727--;if(_0x53c727===0x0)return _0x286360+0x1;}}}}return-0x1;}function generateToolCallId(){const _0x13dd99=a40_0x1e4a;return _0x13dd99(0x11f)+Math[_0x13dd99(0xd0)]()[_0x13dd99(0xe2)](0x24)[_0x13dd99(0xd8)](0x2,0xf);}function repairIncompleteJson(_0x58b24a,_0x3cdfe4){const _0x46ea03=a40_0x1e4a;try{return JSON[_0x46ea03(0x108)](_0x58b24a),_0x58b24a;}catch{const _0x19877e=[];let _0x220a53=![],_0x421f5d=![];for(const _0x1503b1 of _0x58b24a){if(_0x421f5d){_0x421f5d=![];continue;}if(_0x1503b1==='\x5c'){_0x421f5d=!![];continue;}if(_0x1503b1==='\x22'){_0x220a53=!_0x220a53;continue;}if(!_0x220a53){if(_0x1503b1==='{')_0x19877e['push']('{');else{if(_0x1503b1==='[')_0x19877e[_0x46ea03(0x124)]('[');else{if(_0x1503b1==='}'&&_0x19877e[_0x19877e['length']-0x1]==='{')_0x19877e[_0x46ea03(0xe3)]();else _0x1503b1===']'&&_0x19877e[_0x19877e[_0x46ea03(0xd4)]-0x1]==='['&&_0x19877e[_0x46ea03(0xe3)]();}}}}let _0x10c45f=_0x58b24a;_0x220a53&&(_0x10c45f+='\x22');while(_0x19877e[_0x46ea03(0xd4)]>0x0){const _0x12bf6a=_0x19877e[_0x46ea03(0xe3)]();_0x10c45f+=_0x12bf6a==='{'?'}':']';}try{return JSON['parse'](_0x10c45f),_0x3cdfe4&&_0x10c45f!==_0x58b24a&&_0x3cdfe4[_0x46ea03(0xe8)](_0x46ea03(0xf8)+_0x58b24a+'\x0a[After]:\x0a'+_0x10c45f),_0x10c45f;}catch{return null;}}}export function parseToolCallFromText(_0x1b8032,_0x37c721){const _0x5d7422=a40_0x1e4a,_0x5f46b5=/```tool_use[\s]*\n([\s\S]*)\n?```/,_0xfce31a=_0x5f46b5['exec'](_0x1b8032);if(_0xfce31a){if(!_0xfce31a[0x0][_0x5d7422(0xf5)](_0x5d7422(0x11e))){}else{const _0x217ccc=_0xfce31a[0x1]['trim'](),_0x355b2f=_0xfce31a[_0x5d7422(0xec)],_0x260d80=_0x355b2f+_0xfce31a[0x0][_0x5d7422(0xd4)];try{const _0x5a3274=JSON[_0x5d7422(0x108)](_0x217ccc);if(_0x5a3274['tool_use']&&_0x5a3274[_0x5d7422(0xf2)][_0x5d7422(0xdb)])return{'id':_0x5a3274[_0x5d7422(0xf2)]['id']||generateToolCallId(),'name':_0x5a3274[_0x5d7422(0xf2)]['name'],'input':_0x5a3274[_0x5d7422(0xf2)][_0x5d7422(0xe1)]||{},'startIndex':_0x355b2f,'endIndex':_0x260d80};if(_0x5a3274[_0x5d7422(0xdb)]&&typeof _0x5a3274['name']===_0x5d7422(0x109)&&_0x5a3274[_0x5d7422(0xdb)][_0x5d7422(0xeb)]()['length']>0x0)return{'id':_0x5a3274['id']||generateToolCallId(),'name':_0x5a3274['name'],'input':_0x5a3274['input']||_0x5a3274['arguments']||{},'startIndex':_0x355b2f,'endIndex':_0x260d80};}catch{const _0x2c98cc=repairIncompleteJson(_0x217ccc,_0x37c721);if(_0x2c98cc)try{const _0x884e98=JSON['parse'](_0x2c98cc);if(_0x884e98[_0x5d7422(0xf2)]&&_0x884e98['tool_use'][_0x5d7422(0xdb)])return{'id':_0x884e98['tool_use']['id']||generateToolCallId(),'name':_0x884e98[_0x5d7422(0xf2)]['name'],'input':_0x884e98[_0x5d7422(0xf2)][_0x5d7422(0xe1)]||{},'startIndex':_0x355b2f,'endIndex':_0x260d80};if(_0x884e98['name']&&typeof _0x884e98[_0x5d7422(0xdb)]==='string'&&_0x884e98[_0x5d7422(0xdb)][_0x5d7422(0xeb)]()[_0x5d7422(0xd4)]>0x0)return{'id':_0x884e98['id']||generateToolCallId(),'name':_0x884e98[_0x5d7422(0xdb)],'input':_0x884e98['input']||_0x884e98['arguments']||{},'startIndex':_0x355b2f,'endIndex':_0x260d80};}catch{}}}}const _0x1849f0=/\{"tool_use":/g,_0x38d18f=_0x1849f0[_0x5d7422(0x110)](_0x1b8032);if(!_0x38d18f)return null;const _0xefe546=_0x38d18f[_0x5d7422(0xec)];let _0x19a298=findJsonEndIndex(_0x1b8032,_0xefe546);if(_0x19a298===-0x1)return null;const _0x1fbd97=_0x1b8032['substring'](_0xefe546,_0x19a298);try{const _0x293b56=JSON[_0x5d7422(0x108)](_0x1fbd97);if(_0x293b56[_0x5d7422(0xf2)]&&_0x293b56['tool_use']['id']&&_0x293b56['tool_use'][_0x5d7422(0xdb)])return{'id':_0x293b56['tool_use']['id'],'name':_0x293b56[_0x5d7422(0xf2)][_0x5d7422(0xdb)],'input':_0x293b56[_0x5d7422(0xf2)]['input']||{},'startIndex':_0xefe546,'endIndex':_0x19a298};}catch{const _0x18c4df=repairIncompleteJson(_0x1fbd97,_0x37c721);if(_0x18c4df)try{const _0x5ae556=JSON[_0x5d7422(0x108)](_0x18c4df);if(_0x5ae556['tool_use']&&_0x5ae556[_0x5d7422(0xf2)]['id']&&_0x5ae556[_0x5d7422(0xf2)][_0x5d7422(0xdb)])return{'id':_0x5ae556['tool_use']['id'],'name':_0x5ae556['tool_use'][_0x5d7422(0xdb)],'input':_0x5ae556['tool_use'][_0x5d7422(0xe1)]||{},'startIndex':_0xefe546,'endIndex':_0x19a298};}catch{return null;}return null;}return null;}export function*generateToolCallEvents(_0x405a6a,_0x2e6909,_0x340a40){const _0x15c714=a40_0x1e4a,_0x5c3456={'type':_0x15c714(0xf9),'index':_0x2e6909,'content_block':{'type':_0x15c714(0xf2),'id':_0x405a6a['id'],'name':_0x405a6a[_0x15c714(0xdb)],'input':{}}};yield _0x5c3456;const _0x21c91e=JSON['stringify'](_0x405a6a[_0x15c714(0xe1)]),_0x317aeb={'type':_0x15c714(0xfb),'index':_0x2e6909,'delta':{'type':'input_json_delta','partial_json':_0x21c91e}};yield _0x317aeb;const _0x4d370d={'type':_0x15c714(0x116),'index':_0x2e6909};yield _0x4d370d;const _0x2e45eb={'type':'message_delta','delta':{'stop_reason':'tool_use','stop_sequence':null},'usage':{'input_tokens':_0x340a40,'output_tokens':0x0}};yield _0x2e45eb;const _0x44d109={'type':'message_stop'};yield _0x44d109;}export async function*transformTDStreamWithToolDetection(_0x39f49d,_0x8b8d9a,_0x1a64da,_0x386fdb,_0x4b41ab='',_0x5ebbb5=0x0){const _0x2196f9=a40_0x1e4a,_0x59b413=_0x5ebbb5>0x0?_0x5ebbb5:estimateTokenCount(_0x4b41ab);let _0x31630b=0x0,_0x37fab5=0x0,_0x4eaa51=![],_0x5edadf='',_0xc9c773=0x0,_0x2e5627=![];const _0x8ed0f7=0xc8,_0x3655de={'type':_0x2196f9(0x103),'message':{'id':_0x8b8d9a,'type':_0x2196f9(0xdf),'role':'assistant','content':[],'model':_0x1a64da,'stop_reason':null,'stop_sequence':null,'usage':{'input_tokens':_0x59b413,'output_tokens':0x0}}};yield _0x3655de;for await(const _0x2a961a of _0x39f49d){if(_0x2196f9(0xe6)in _0x2a961a){const _0xb51ebe=_0x2a961a;_0x5edadf+=_0xb51ebe[_0x2196f9(0xe6)];const _0x27f793=_0x5edadf[_0x2196f9(0x132)](_0x2196f9(0xee)),_0x23ecf8=_0x5edadf[_0x2196f9(0x132)]('{\x22tool_use\x22:'),_0x471062=_0x27f793!==-0x1?_0x23ecf8!==-0x1?Math[_0x2196f9(0xf1)](_0x27f793,_0x23ecf8):_0x27f793:_0x23ecf8;if(_0x471062!==-0x1){const _0x3588fa=[];let _0x1d5aa1=0x0;while(!![]){const _0x31fe8e=_0x5edadf[_0x2196f9(0xd8)](_0x1d5aa1),_0x4455f8=parseToolCallFromText(_0x31fe8e,_0x386fdb);if(!_0x4455f8)break;_0x3588fa[_0x2196f9(0x124)]({'id':_0x4455f8['id'],'name':_0x4455f8[_0x2196f9(0xdb)],'input':_0x4455f8[_0x2196f9(0xe1)],'startIndex':_0x1d5aa1+_0x4455f8[_0x2196f9(0x107)],'endIndex':_0x1d5aa1+_0x4455f8['endIndex']}),_0x1d5aa1+=_0x4455f8[_0x2196f9(0xe7)];}if(_0x3588fa[_0x2196f9(0xd4)]>0x0){const _0x2d6407=_0x3588fa[_0x3588fa[_0x2196f9(0xd4)]-0x1];_0x2e5627=!![];_0x3588fa[_0x2196f9(0xd4)]>0x1?_0x386fdb?.[_0x2196f9(0x121)](_0x2196f9(0xfd)+_0x2d6407[_0x2196f9(0xdb)]):_0x386fdb?.['debug'](_0x2196f9(0x130)+_0x2d6407[_0x2196f9(0xdb)]);const _0x5eb6f9=_0x5edadf[_0x2196f9(0xd8)](_0xc9c773,_0x2d6407['startIndex'])[_0x2196f9(0xeb)]();if(_0x5eb6f9){if(!_0x4eaa51){const _0x46bfc4={'type':_0x2196f9(0xf9),'index':_0x37fab5,'content_block':{'type':_0x2196f9(0xe0),'text':''}};yield _0x46bfc4,_0x4eaa51=!![];}const _0x44f7aa={'type':'content_block_delta','index':_0x37fab5,'delta':{'type':_0x2196f9(0x104),'text':_0x5eb6f9}};yield _0x44f7aa,_0x31630b+=estimateTokenCount(_0x5eb6f9);}if(_0x4eaa51){const _0x13ed07={'type':_0x2196f9(0x116),'index':_0x37fab5};yield _0x13ed07,_0x37fab5++,_0x4eaa51=![];}for(const _0x43451c of generateToolCallEvents(_0x2d6407,_0x37fab5,_0x59b413)){_0x43451c['type']==='message_delta'&&(_0x43451c[_0x2196f9(0x10d)][_0x2196f9(0xd2)]=_0x31630b),yield _0x43451c;}return;}const _0x955936=_0x5edadf[_0x2196f9(0x117)](_0x2196f9(0xee))&&_0x5edadf['indexOf']('```',_0x5edadf['indexOf'](_0x2196f9(0xee))+0xb)!==-0x1,_0x438e0f=_0x5edadf[_0x2196f9(0x117)](_0x2196f9(0x10a))&&findJsonEndIndex(_0x5edadf,_0x5edadf['indexOf'](_0x2196f9(0x10a)))!==-0x1;if(_0x955936||_0x438e0f){_0x2e5627=!![];let _0x5d5c0f='';if(_0x955936){const _0xf9584b=_0x5edadf['indexOf']('```tool_use'),_0x37faea=_0x5edadf[_0x2196f9(0x132)](_0x2196f9(0x11e),_0xf9584b+0xb);_0x37faea!==-0x1?_0x5d5c0f=_0x5edadf['substring'](_0xf9584b,_0x37faea+0x3):_0x5d5c0f=_0x5edadf[_0x2196f9(0xd8)](_0xf9584b);}else{if(_0x438e0f){const _0x1579cb=_0x5edadf[_0x2196f9(0x132)](_0x2196f9(0x10a)),_0x23cf03=findJsonEndIndex(_0x5edadf,_0x1579cb);_0x23cf03!==-0x1?_0x5d5c0f=_0x5edadf[_0x2196f9(0xd8)](_0x1579cb,_0x23cf03):_0x5d5c0f=_0x5edadf[_0x2196f9(0xd8)](_0x1579cb);}}_0x386fdb&&_0x386fdb[_0x2196f9(0x100)](_0x2196f9(0xfc)+_0x5d5c0f);_0x386fdb?.[_0x2196f9(0x121)](_0x2196f9(0xda)),_0x386fdb?.[_0x2196f9(0x121)](_0x2196f9(0x114),_0x5d5c0f);const _0x344131=_0x5edadf[_0x2196f9(0xd8)](_0xc9c773,_0x471062)[_0x2196f9(0xeb)]();if(_0x344131){if(!_0x4eaa51){const _0x5d7956={'type':_0x2196f9(0xf9),'index':_0x37fab5,'content_block':{'type':_0x2196f9(0xe0),'text':''}};yield _0x5d7956,_0x4eaa51=!![];}const _0x4d615c={'type':'content_block_delta','index':_0x37fab5,'delta':{'type':_0x2196f9(0x104),'text':_0x344131}};yield _0x4d615c,_0x31630b+=estimateTokenCount(_0x344131);}if(_0x4eaa51){const _0x5d5881={'type':_0x2196f9(0x116),'index':_0x37fab5};yield _0x5d5881,_0x37fab5++,_0x4eaa51=![];}const _0x12e561='\x0a\x0a[tdx\x20error]\x20Malformed\x20tool_use\x20JSON\x20detected.\x20Please\x20fix\x20the\x20JSON\x20below:\x0a\x0a'+_0x5d5c0f+_0x2196f9(0xe4),_0x21bd23={'type':'content_block_start','index':_0x37fab5,'content_block':{'type':_0x2196f9(0xe0),'text':''}};yield _0x21bd23;const _0x399d03={'type':_0x2196f9(0xfb),'index':_0x37fab5,'delta':{'type':'text_delta','text':_0x12e561}};yield _0x399d03;const _0xa5b992={'type':_0x2196f9(0x116),'index':_0x37fab5};yield _0xa5b992;const _0x4f56f3={'type':_0x2196f9(0x101),'delta':{'stop_reason':_0x2196f9(0x131),'stop_sequence':null},'usage':{'input_tokens':_0x59b413,'output_tokens':_0x31630b}};yield _0x4f56f3;const _0x3253f8={'type':_0x2196f9(0xdd)};yield _0x3253f8;return;}const _0x12cd77=_0x5edadf[_0x2196f9(0xd8)](_0xc9c773,_0x471062);if(_0x12cd77){if(!_0x4eaa51){const _0x4900aa={'type':_0x2196f9(0xf9),'index':_0x37fab5,'content_block':{'type':_0x2196f9(0xe0),'text':''}};yield _0x4900aa,_0x4eaa51=!![];}const _0x238482={'type':_0x2196f9(0xfb),'index':_0x37fab5,'delta':{'type':'text_delta','text':_0x12cd77}};yield _0x238482,_0x31630b+=estimateTokenCount(_0x12cd77),_0xc9c773=_0x471062;}continue;}const _0x335fa3=_0x5edadf[_0x2196f9(0xd4)]-_0x8ed0f7;if(_0x335fa3>_0xc9c773){const _0x644b65=_0x5edadf[_0x2196f9(0xd8)](_0xc9c773,_0x335fa3);if(_0x644b65){if(!_0x4eaa51){const _0x3ccd8a={'type':_0x2196f9(0xf9),'index':_0x37fab5,'content_block':{'type':_0x2196f9(0xe0),'text':''}};yield _0x3ccd8a,_0x4eaa51=!![];}const _0x1ff9fc={'type':_0x2196f9(0xfb),'index':_0x37fab5,'delta':{'type':_0x2196f9(0x104),'text':_0x644b65}};yield _0x1ff9fc,_0x31630b+=estimateTokenCount(_0x644b65),_0xc9c773=_0x335fa3;}}}else{if(_0x2196f9(0x100)in _0x2a961a){const _0x5cdee6=_0x2a961a,_0x15aa2e=determineErrorType(_0x5cdee6[_0x2196f9(0x100)],_0x386fdb),_0x556fb0=_0x15aa2e===_0x2196f9(0xd5)?_0x2196f9(0x12f):_0x2196f9(0x131),_0x4909be={'type':_0x2196f9(0x101),'delta':{'stop_reason':_0x556fb0,'stop_sequence':null},'usage':{'input_tokens':_0x59b413,'output_tokens':_0x31630b}};yield _0x4909be,yield{'type':_0x2196f9(0x100),'error':{'type':_0x15aa2e,'message':_0x5cdee6[_0x2196f9(0x100)]},'request_id':_0x8b8d9a};const _0x37a4b6={'type':_0x2196f9(0xdd)};yield _0x37a4b6;return;}}}if(!_0x2e5627){const _0x3fad8d=_0x5edadf[_0x2196f9(0xd8)](_0xc9c773);if(_0x3fad8d){if(!_0x4eaa51){const _0x536b39={'type':_0x2196f9(0xf9),'index':_0x37fab5,'content_block':{'type':_0x2196f9(0xe0),'text':''}};yield _0x536b39,_0x4eaa51=!![];}const _0x16a320={'type':_0x2196f9(0xfb),'index':_0x37fab5,'delta':{'type':_0x2196f9(0x104),'text':_0x3fad8d}};yield _0x16a320,_0x31630b+=estimateTokenCount(_0x3fad8d);}if(_0x4eaa51){const _0x5b9173={'type':_0x2196f9(0x116),'index':_0x37fab5};yield _0x5b9173;}const _0x18b24d={'type':'message_delta','delta':{'stop_reason':_0x2196f9(0x131),'stop_sequence':null},'usage':{'input_tokens':_0x59b413,'output_tokens':_0x31630b}};yield _0x18b24d;const _0x341224={'type':_0x2196f9(0xdd)};yield _0x341224;}}export{generateMessageId};
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/proxy/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAoB3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AA6ExD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,GAAG,CAAC;IACT,MAAM,EAAE,SAAS,CAAC;CACnB;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,eAAe,CAAC,CAAiB;IACzC,OAAO,CAAC,MAAM,CAAY;gBAEd,MAAM,EAAE,iBAAiB;IAiBrC;;;;OAIG;YACW,gBAAgB;IAuB9B;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAI3B;;OAEG;IACH,OAAO,CAAC,eAAe;IAoBvB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAcxB;;OAEG;IACH,OAAO,CAAC,WAAW;IAqBnB;;;OAGG;YACW,cAAc;IAqf5B;;;OAGG;YACW,iBAAiB;IAa/B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB5B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAU3B;;OAEG;IACH,UAAU,IAAI,MAAM;CAUrB"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/proxy/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAqB3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAuFxD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,EAAE,GAAG,CAAC;IACT,MAAM,EAAE,SAAS,CAAC;CACnB;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,eAAe,CAAC,CAAiB;IACzC,OAAO,CAAC,MAAM,CAAY;gBAEd,MAAM,EAAE,iBAAiB;IAiBrC;;;;OAIG;YACW,gBAAgB;IAuB9B;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAI3B;;OAEG;IACH,OAAO,CAAC,eAAe;IAoBvB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAcxB;;OAEG;IACH,OAAO,CAAC,WAAW;IAqBnB;;;OAGG;YACW,cAAc;IAsf5B;;;OAGG;YACW,iBAAiB;IAa/B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB5B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAU3B;;OAEG;IACH,UAAU,IAAI,MAAM;CAUrB"}
@@ -1 +1 @@
1
- const a41_0x57a0f4=a41_0x7c62;function a41_0x59d6(){const _0x1e7800=['no-cache','required','close','warn','catch','2784879DeMWbz','[Previous\x20conversation]\x0a\x0a<conversation>\x0a','substring','length','server','cleanupInterval','sort','listen','user','set','code','chatId','stream','TD\x20LLM\x20Proxy\x20Server','[PROXY\x20ERROR]\x20Streaming\x20error:','pop','text/event-stream','new\x20system\x20prompt(s)','Failed\x20to\x20extract\x20tool\x20results:','362075Izaixx','Creating/looking\x20up\x20agent\x20for:\x20','embeddedToolsByName','register','\x20->\x20','sha256','method','agentId','messageHistory','\x0a</conversation>',',\x20context\x20signature:\x20','Model\x20normalization:\x20','metadata','unknown','x-api-key','new\x20tool(s)','Final\x20message\x20reconstructed\x20after\x20context\x20reset:','keys','join','\x20SSE\x20events.','Started\x20cache\x20cleanup\x20interval\x20(runs\x20every\x20','body','string','System\x20prompts:\x20','0.0.0.0','message','url','Agent\x20cached:\x20','clear','Assistant','update','size','1303242kswkTn','\x20system\x20prompts,\x20','Including\x20tool\x20results','has','type','\x0a---\x0a\x0a','Context:','isArray','headers',',\x20context:\x20','sent','Project\x20ID\x20must\x20be\x20configured','\x20tools',':\x20estimated\x20input_tokens=','Embedding','trim','\x20limit','trace','[session:\x20','[PROXY\x20ERROR]\x20Uncaught\x20error\x20in\x20','[PROXY\x20ERROR]\x20Unhandled\x20error\x20in\x20','now','handleMessages',',\x20is\x20new\x20context:\x20',',\x20tools:\x20','message.content\x20must\x20be\x20a\x20string\x20or\x20array','User','setupRoutes','No\x20user\x20message\x20found\x20in\x20request','push','Failed\x20to\x20reconstruct\x20message\x20-\x20all\x20parts\x20are\x20empty,\x20using\x20fallback','Embedded\x20in\x20chat\x20-\x20system\x20prompts:\x20','delete','add','Stream\x20complete.\x20Sent\x20','port','info','user_id','embeddedSystemPrompts','handleRouteError','http://','Failed\x20to\x20initialize\x20chat\x20stream.\x20Please\x20try\x20again.','startChat','10FQFUkG','properties','chats','name','12949783kRyYqj','filter','api_error','Added\x20system\x20prompt\x20previews:','attributes','system','/v1/messages','Authorization','keep-alive','slice','end','POST','model','[Current\x20message]\x0a\x0a','cleanupExpiredChats','20JMtYvG','get','raw','tdx','map','GET','not_supported_error','[PROXY\x20ERROR]\x20Non-streaming\x20responses\x20are\x20not\x20yet\x20supported','Unknown\x20error','[PROXY\x20ERROR]\x20Configuration\x20error:\x20Project\x20ID\x20must\x20be\x20configured','config','\x20|\x20','event','send','New\x20-\x20system\x20prompts:\x20','Failed\x20to\x20start\x20proxy\x20server:\x20','write','getAddress','OPTIONS','Using\x20agent:\x20','...','stringify','lastUsedAt','508107fanrbz','http://localhost:','data','Reset\x20chat\x20state\x20to\x20recover\x20on\x20next\x20request','chat','New\x20context\x20-\x20including\x20full\x20context','\x20(model:\x20','llm','Added\x20tool\x20names:','tools',',\x20model=','Chat\x20ID:\x20','content','text','writeHead','invalid_request_error','Final\x20message\x20is\x20empty\x20after\x20construction\x20-\x20starting\x20fresh\x20conversation','role','setErrorHandler','Created\x20new\x20chat:\x20','post','105Xehffr','address','[PROXY\x20ERROR]\x20Validation\x20failed:\x20message.content\x20must\x20be\x20a\x20string\x20or\x20array,\x20got:','agentCache','debug','Failed\x20to\x20generate\x20tool\x20prompt:','15AKulmP','sessionCache','setupMiddleware','input_schema','messages','messages\x20array\x20is\x20required\x20and\x20must\x20not\x20be\x20empty','getOrCreateSession','s,\x20expires\x20after\x20','[PROXY\x20ERROR]\x20Validation\x20failed:\x20No\x20user\x20message\x20found\x20in\x20request','[PROXY\x20ERROR]\x20Chat\x20stream\x20is\x20undefined','getAgentForModel','handleCountTokens','anthropic-version','300164XzXGlf',':\x20messages=','logger','/v1/messages/count_tokens','515608mSXCWP','error','/health'];a41_0x59d6=function(){return _0x1e7800;};return a41_0x59d6();}(function(_0x140e87,_0x5d4289){const _0x4cc173=a41_0x7c62,_0x2d182d=_0x140e87();while(!![]){try{const _0x5be525=parseInt(_0x4cc173(0x200))/0x1+-parseInt(_0x4cc173(0x29d))/0x2+-parseInt(_0x4cc173(0x275))/0x3*(parseInt(_0x4cc173(0x25e))/0x4)+parseInt(_0x4cc173(0x290))/0x5*(-parseInt(_0x4cc173(0x220))/0x6)+-parseInt(_0x4cc173(0x28a))/0x7*(-parseInt(_0x4cc173(0x1e5))/0x8)+parseInt(_0x4cc173(0x1ed))/0x9*(-parseInt(_0x4cc173(0x24b))/0xa)+parseInt(_0x4cc173(0x24f))/0xb;if(_0x5be525===_0x5d4289)break;else _0x2d182d['push'](_0x2d182d['shift']());}catch(_0x51b44d){_0x2d182d['push'](_0x2d182d['shift']());}}}(a41_0x59d6,0x85d12));import a41_0x2b3a88 from'fastify';import a41_0xe94ac8 from'@fastify/cors';import{createHash}from'crypto';import{transformTDStreamWithToolDetection,formatAnthropicSSE,generateMessageId,generateToolPrompt,extractToolResults,estimateInputTokensFromRequest}from'./anthropic-adapter.js';import{colorizeJSON,colorizeJSONCompact}from'../utils/colors.js';import{extractModelAlias,resolveModelAlias}from'../utils/model-aliases.js';import{SessionCache}from'./session-cache.js';function formatConversationHistory(_0x16e364){const _0x5d2fd7=a41_0x7c62;if(!_0x16e364||!Array[_0x5d2fd7(0x227)](_0x16e364))return'';return _0x16e364[_0x5d2fd7(0x250)](_0x5f2c70=>_0x5f2c70!=null)[_0x5d2fd7(0x262)](_0x1db892=>{const _0x23abd6=_0x5d2fd7,_0x24a9e7=_0x1db892['content']!=null&&Array[_0x23abd6(0x227)](_0x1db892[_0x23abd6(0x281)])?_0x1db892[_0x23abd6(0x281)][_0x23abd6(0x250)](_0x558803=>_0x558803&&_0x558803[_0x23abd6(0x224)]===_0x23abd6(0x282))[_0x23abd6(0x262)](_0x53f932=>_0x53f932['text'])[_0x23abd6(0x212)]('\x0a'):_0x1db892[_0x23abd6(0x281)]||'',_0x4a5fb4=_0x1db892[_0x23abd6(0x286)]===_0x23abd6(0x1f5)?_0x23abd6(0x23a):_0x23abd6(0x21d);return _0x4a5fb4+':\x20'+_0x24a9e7;})['join']('\x0a\x0a');}function calculateContextSignature(_0x1de622,_0x163710,_0x4b198f){const _0x2e7ee3=a41_0x7c62,_0x4a49f8=extractModelAlias(_0x1de622),_0x42b083=resolveModelAlias(_0x4a49f8),_0x207ab9=[..._0x163710||[]][_0x2e7ee3(0x1f3)](),_0x5c7b0a=(_0x4b198f||[])[_0x2e7ee3(0x250)](_0x233fcb=>_0x233fcb!=null)[_0x2e7ee3(0x262)](_0x5f5d40=>({'name':_0x5f5d40['name'],'params':Object[_0x2e7ee3(0x211)](_0x5f5d40['input_schema']?.[_0x2e7ee3(0x24c)]||{})[_0x2e7ee3(0x1f3)](),'required':(_0x5f5d40[_0x2e7ee3(0x293)]?.[_0x2e7ee3(0x1e9)]||[])[_0x2e7ee3(0x1f3)]()}))[_0x2e7ee3(0x1f3)]((_0x4dd4d9,_0x22e007)=>_0x4dd4d9[_0x2e7ee3(0x24e)]['localeCompare'](_0x22e007['name'])),_0x314ee2=JSON[_0x2e7ee3(0x273)]({'model':_0x42b083,'prompts':_0x207ab9,'tools':_0x5c7b0a});return createHash(_0x2e7ee3(0x205))[_0x2e7ee3(0x21e)](_0x314ee2)['digest']('hex')[_0x2e7ee3(0x1ef)](0x0,0x10);}function a41_0x7c62(_0x12beab,_0x5ba860){const _0x59d681=a41_0x59d6();return a41_0x7c62=function(_0x7c629c,_0xca1760){_0x7c629c=_0x7c629c-0x1e3;let _0x42c9b3=_0x59d681[_0x7c629c];return _0x42c9b3;},a41_0x7c62(_0x12beab,_0x5ba860);}const MAX_CHATS_PER_SESSION=0xa,CACHE_EXPIRATION_MS=0xa*0x3c*0x3e8,CLEANUP_INTERVAL_MS=0x3c*0x3e8;export class ProxyServer{[a41_0x57a0f4(0x1f1)];[a41_0x57a0f4(0x291)];[a41_0x57a0f4(0x28d)];['config'];[a41_0x57a0f4(0x1f2)];['logger'];constructor(_0x364377){const _0x339f82=a41_0x57a0f4;this[_0x339f82(0x1e3)]=_0x364377['logger'],this[_0x339f82(0x268)]=_0x364377,this[_0x339f82(0x291)]=new SessionCache({'maxChatsPerSession':MAX_CHATS_PER_SESSION,'cacheExpirationMs':CACHE_EXPIRATION_MS}),this[_0x339f82(0x28d)]=new Map(),this[_0x339f82(0x1f1)]=a41_0x2b3a88({'logger':![],'bodyLimit':0x40*0x400*0x400}),this[_0x339f82(0x292)](),this[_0x339f82(0x23b)]();}async['getAgentForModel'](_0x2eb426){const _0x11b230=a41_0x57a0f4,_0xab60c8=extractModelAlias(_0x2eb426),_0x11eb5b=resolveModelAlias(_0xab60c8);let _0xc14bf4=this[_0x11b230(0x28d)]['get'](_0x11eb5b);if(!_0xc14bf4){this['logger'][_0x11b230(0x28e)](_0x11b230(0x20b)+_0x2eb426+_0x11b230(0x204)+_0xab60c8+_0x11b230(0x204)+_0x11eb5b),this[_0x11b230(0x1e3)][_0x11b230(0x28e)](_0x11b230(0x201)+_0x11eb5b);const _0x4a1678=await this['config']['tdx']['llm']['getOrCreateDefaultAgent'](_0x11eb5b);_0xc14bf4=_0x4a1678['id'],this[_0x11b230(0x28d)][_0x11b230(0x1f6)](_0x11eb5b,_0xc14bf4),this[_0x11b230(0x1e3)][_0x11b230(0x28e)](_0x11b230(0x21b)+_0x11eb5b+_0x11b230(0x204)+_0xc14bf4+'\x20('+_0x4a1678[_0x11b230(0x253)]['name']+')');}return _0xc14bf4;}[a41_0x57a0f4(0x25d)](){const _0x33b682=a41_0x57a0f4;this[_0x33b682(0x291)][_0x33b682(0x25d)]();}[a41_0x57a0f4(0x292)](){const _0x469dd4=a41_0x57a0f4;this['server'][_0x469dd4(0x203)](a41_0xe94ac8,{'origin':!![],'methods':[_0x469dd4(0x263),_0x469dd4(0x25a),_0x469dd4(0x270)],'allowedHeaders':['Content-Type',_0x469dd4(0x256),_0x469dd4(0x29c),_0x469dd4(0x20e)]}),this[_0x469dd4(0x1f1)][_0x469dd4(0x287)]((_0xee23c1,_0x18c817,_0x241563)=>{const _0x5ea9cc=_0x469dd4,_0x59227f=_0xee23c1 instanceof Error?_0xee23c1['message']:_0x5ea9cc(0x266);this[_0x5ea9cc(0x1e3)][_0x5ea9cc(0x1e6)](_0x5ea9cc(0x234)+_0x18c817[_0x5ea9cc(0x206)]+'\x20'+_0x18c817[_0x5ea9cc(0x21a)]+':',_0xee23c1),_0x241563[_0x5ea9cc(0x1f7)](0x1f4)[_0x5ea9cc(0x26b)]({'type':_0x5ea9cc(0x1e6),'error':{'type':_0x5ea9cc(0x251),'message':_0x59227f}});});}[a41_0x57a0f4(0x247)](_0x763ea7,_0xfa7f1e,_0xfb60d1){const _0x52db7f=a41_0x57a0f4,_0x348089=_0xfa7f1e instanceof Error?_0xfa7f1e[_0x52db7f(0x219)]:_0x52db7f(0x266);this[_0x52db7f(0x1e3)][_0x52db7f(0x1e6)](_0x52db7f(0x233)+_0x763ea7+':',_0xfa7f1e),!_0xfb60d1[_0x52db7f(0x22a)]&&_0xfb60d1['code'](0x1f4)[_0x52db7f(0x26b)]({'type':_0x52db7f(0x1e6),'error':{'type':_0x52db7f(0x251),'message':_0x348089}});}[a41_0x57a0f4(0x23b)](){const _0x37d867=a41_0x57a0f4;this['server'][_0x37d867(0x25f)](_0x37d867(0x1e7),async()=>{const _0x189a14=_0x37d867;return{'status':'ok','message':_0x189a14(0x1fa)};}),this[_0x37d867(0x1f1)]['post'](_0x37d867(0x255),async(_0x4ee9ff,_0x4f0f27)=>{const _0xab389f=_0x37d867;return this[_0xab389f(0x236)](_0x4ee9ff,_0x4f0f27)[_0xab389f(0x1ec)](_0x54838a=>{const _0xe79d23=_0xab389f;this[_0xe79d23(0x247)](_0xe79d23(0x255),_0x54838a,_0x4f0f27);});}),this[_0x37d867(0x1f1)][_0x37d867(0x289)]('/v1/messages/count_tokens',async(_0x4ba8bf,_0x483d5d)=>{const _0x18bc1d=_0x37d867;return this['handleCountTokens'](_0x4ba8bf)[_0x18bc1d(0x1ec)](_0x5418bc=>{const _0x5c51da=_0x18bc1d;this[_0x5c51da(0x247)](_0x5c51da(0x1e4),_0x5418bc,_0x483d5d);});});}async[a41_0x57a0f4(0x236)](_0x4bb92c,_0x3b1085){const _0x546bf0=a41_0x57a0f4,_0x462192=_0x4bb92c[_0x546bf0(0x215)];if(!_0x462192[_0x546bf0(0x294)]||!Array[_0x546bf0(0x227)](_0x462192['messages'])||_0x462192[_0x546bf0(0x294)][_0x546bf0(0x1f0)]===0x0){this[_0x546bf0(0x1e3)][_0x546bf0(0x1e6)]('[PROXY\x20ERROR]\x20Validation\x20failed:\x20messages\x20array\x20is\x20required\x20and\x20must\x20not\x20be\x20empty'),_0x3b1085['code'](0x190)['send']({'type':_0x546bf0(0x1e6),'error':{'type':_0x546bf0(0x284),'message':_0x546bf0(0x295)}});return;}if(_0x462192[_0x546bf0(0x27e)]&&!Array['isArray'](_0x462192['tools'])){this[_0x546bf0(0x1e3)][_0x546bf0(0x1e6)]('[PROXY\x20ERROR]\x20Validation\x20failed:\x20tools\x20must\x20be\x20an\x20array\x20if\x20provided'),_0x3b1085[_0x546bf0(0x1f7)](0x190)[_0x546bf0(0x26b)]({'type':_0x546bf0(0x1e6),'error':{'type':'invalid_request_error','message':'tools\x20must\x20be\x20an\x20array\x20if\x20provided'}});return;}const _0xe0b8de=_0x462192[_0x546bf0(0x294)]?.[_0x546bf0(0x1f0)]??0x0,_0x436ac7=_0x462192[_0x546bf0(0x25b)]||_0x546bf0(0x20d);this[_0x546bf0(0x1e3)][_0x546bf0(0x244)](_0x4bb92c[_0x546bf0(0x206)]+'\x20'+_0x4bb92c['url']+_0x546bf0(0x29e)+_0xe0b8de+_0x546bf0(0x27f)+_0x436ac7),this[_0x546bf0(0x1e3)][_0x546bf0(0x28e)]('header:\x20'+colorizeJSONCompact(_0x4bb92c[_0x546bf0(0x228)]));this[_0x546bf0(0x1e3)][_0x546bf0(0x231)]&&this[_0x546bf0(0x1e3)][_0x546bf0(0x231)](colorizeJSON(_0x462192,{'color':!![]}));const _0x5ec753=_0x462192[_0x546bf0(0x20c)]?.[_0x546bf0(0x245)]||'default',_0x230f92=this[_0x546bf0(0x268)]['projectId'];if(!_0x230f92){this[_0x546bf0(0x1e3)][_0x546bf0(0x1e6)](_0x546bf0(0x267)),_0x3b1085[_0x546bf0(0x1f7)](0x1f4)['send']({'type':_0x546bf0(0x1e6),'error':{'type':_0x546bf0(0x251),'message':_0x546bf0(0x22b)}});return;}const _0xcd8768=this[_0x546bf0(0x291)][_0x546bf0(0x296)](_0x5ec753,_0x230f92),_0x1b8c81=_0xcd8768[_0x546bf0(0x208)][_0x546bf0(0x1f0)],_0x5d07ba=_0x462192[_0x546bf0(0x294)][_0x546bf0(0x258)](_0x1b8c81);let _0x1afc6f=_0x5d07ba['filter'](_0x6f554a=>_0x6f554a[_0x546bf0(0x286)]==='user')[_0x546bf0(0x1fc)]();if(!_0x1afc6f){_0x1afc6f=_0x462192[_0x546bf0(0x294)][_0x546bf0(0x250)](_0x16a158=>_0x16a158[_0x546bf0(0x286)]==='user')[_0x546bf0(0x1fc)]();if(!_0x1afc6f){this[_0x546bf0(0x1e3)][_0x546bf0(0x1e6)](_0x546bf0(0x298)),_0x3b1085[_0x546bf0(0x1f7)](0x190)['send']({'type':_0x546bf0(0x1e6),'error':{'type':_0x546bf0(0x284),'message':_0x546bf0(0x23c)}});return;}}let _0x1d9394;if(typeof _0x1afc6f['content']===_0x546bf0(0x216))_0x1d9394=_0x1afc6f[_0x546bf0(0x281)];else{if(_0x1afc6f[_0x546bf0(0x281)]!=null&&Array['isArray'](_0x1afc6f['content']))_0x1d9394=_0x1afc6f['content']['filter'](_0xc3989e=>_0xc3989e&&_0xc3989e[_0x546bf0(0x224)]===_0x546bf0(0x282)&&_0xc3989e[_0x546bf0(0x282)])[_0x546bf0(0x262)](_0x1b42bb=>_0x1b42bb[_0x546bf0(0x282)])[_0x546bf0(0x212)]('\x0a');else{this[_0x546bf0(0x1e3)][_0x546bf0(0x1e6)](_0x546bf0(0x28c),typeof _0x1afc6f[_0x546bf0(0x281)],_0x1afc6f[_0x546bf0(0x281)]),_0x3b1085['code'](0x190)[_0x546bf0(0x26b)]({'type':'error','error':{'type':_0x546bf0(0x284),'message':_0x546bf0(0x239)}});return;}}const _0x54c474=[];if(_0x462192[_0x546bf0(0x254)]){if(typeof _0x462192[_0x546bf0(0x254)]===_0x546bf0(0x216))_0x54c474['push'](_0x462192['system']);else{if(Array[_0x546bf0(0x227)](_0x462192[_0x546bf0(0x254)]))for(const _0x1f0822 of _0x462192[_0x546bf0(0x254)]){_0x1f0822[_0x546bf0(0x224)]===_0x546bf0(0x282)&&_0x1f0822[_0x546bf0(0x282)]&&_0x54c474[_0x546bf0(0x23d)](_0x1f0822[_0x546bf0(0x282)]);}}}const _0x3158e0=_0x462192[_0x546bf0(0x27e)]||[],_0x52c374=calculateContextSignature(_0x462192[_0x546bf0(0x25b)],_0x54c474,_0x3158e0);let _0x5c1af5=_0xcd8768['chats'][_0x546bf0(0x25f)](_0x52c374);const _0x20dc00=!_0x5c1af5;if(!_0x5c1af5){const _0x2ccf44=await this[_0x546bf0(0x29a)](_0x462192[_0x546bf0(0x25b)]);_0x5c1af5={'chatId':'','agentId':_0x2ccf44,'contextSignature':_0x52c374,'embeddedSystemPrompts':new Set(),'embeddedToolsByName':new Map(),'lastUsedAt':Date[_0x546bf0(0x235)]()},_0xcd8768['chats'][_0x546bf0(0x1f6)](_0x52c374,_0x5c1af5);if(_0xcd8768[_0x546bf0(0x24d)]['size']>MAX_CHATS_PER_SESSION){let _0x5450c0=null,_0x49004e=Date[_0x546bf0(0x235)]();for(const [_0x8b4825,_0x5bdcb2]of _0xcd8768[_0x546bf0(0x24d)]){_0x5bdcb2['lastUsedAt']<_0x49004e&&(_0x49004e=_0x5bdcb2[_0x546bf0(0x274)],_0x5450c0=_0x8b4825);}_0x5450c0&&(_0xcd8768['chats'][_0x546bf0(0x240)](_0x5450c0),this[_0x546bf0(0x1e3)][_0x546bf0(0x28e)]('Evicted\x20oldest\x20chat\x20(signature:\x20'+_0x5450c0+')\x20to\x20stay\x20under\x20'+MAX_CHATS_PER_SESSION+_0x546bf0(0x230)));}}else _0x5c1af5[_0x546bf0(0x274)]=Date[_0x546bf0(0x235)]();if(!_0x5c1af5[_0x546bf0(0x1f8)])try{const _0xc5a235=await this[_0x546bf0(0x268)][_0x546bf0(0x261)][_0x546bf0(0x27c)][_0x546bf0(0x24a)](_0x5c1af5[_0x546bf0(0x207)]);_0x5c1af5['chatId']=_0xc5a235['id'],this[_0x546bf0(0x1e3)][_0x546bf0(0x28e)](_0x546bf0(0x288)+_0xc5a235['id']+'\x20for\x20context:\x20'+_0x52c374),this['logger'][_0x546bf0(0x28e)](_0x546bf0(0x271)+_0x5c1af5[_0x546bf0(0x207)]+_0x546bf0(0x27b)+_0x462192[_0x546bf0(0x25b)]+')');}catch(_0x4e64e0){this[_0x546bf0(0x1e3)][_0x546bf0(0x1e6)]('Chat\x20creation\x20failed,\x20will\x20fall\x20back\x20to\x20lazy\x20creation:',_0x4e64e0);}const _0x346c16=_0x54c474[_0x546bf0(0x250)](_0x4a11f4=>!_0x5c1af5[_0x546bf0(0x246)][_0x546bf0(0x223)](_0x4a11f4)),_0x2ce463=_0x3158e0[_0x546bf0(0x250)](_0x35b159=>!_0x5c1af5[_0x546bf0(0x202)][_0x546bf0(0x223)](_0x35b159['name']));this[_0x546bf0(0x1e3)][_0x546bf0(0x28e)](_0x546bf0(0x232)+_0x5ec753+']\x20model:\x20'+_0x462192[_0x546bf0(0x25b)]+_0x546bf0(0x20a)+_0x52c374+_0x546bf0(0x237)+_0x20dc00),this[_0x546bf0(0x1e3)][_0x546bf0(0x28e)](_0x546bf0(0x280)+_0x5c1af5[_0x546bf0(0x1f8)]),this[_0x546bf0(0x1e3)][_0x546bf0(0x28e)](_0x546bf0(0x217)+_0x54c474['length']+_0x546bf0(0x238)+_0x3158e0[_0x546bf0(0x1f0)]),this['logger'][_0x546bf0(0x28e)](_0x546bf0(0x23f)+_0x5c1af5[_0x546bf0(0x246)]['size']+_0x546bf0(0x238)+_0x5c1af5[_0x546bf0(0x202)][_0x546bf0(0x21f)]),this[_0x546bf0(0x1e3)][_0x546bf0(0x28e)](_0x546bf0(0x26c)+_0x346c16[_0x546bf0(0x1f0)]+_0x546bf0(0x238)+_0x2ce463[_0x546bf0(0x1f0)]);_0x346c16[_0x546bf0(0x1f0)]>0x0&&this['logger']['debug'](_0x546bf0(0x252),_0x346c16[_0x546bf0(0x262)](_0x487bfd=>_0x487bfd[_0x546bf0(0x1ef)](0x0,0x32)+_0x546bf0(0x272))[_0x546bf0(0x212)](_0x546bf0(0x269)));_0x2ce463[_0x546bf0(0x1f0)]>0x0&&this['logger']['debug'](_0x546bf0(0x27d),_0x2ce463[_0x546bf0(0x262)](_0x41c4ee=>_0x41c4ee[_0x546bf0(0x24e)])[_0x546bf0(0x212)](',\x20'));_0x20dc00&&this[_0x546bf0(0x1e3)]['info']('Created\x20a\x20new\x20chat\x20id:\x20'+_0x5c1af5[_0x546bf0(0x1f8)]+',\x20model='+_0x462192['model']+',\x20'+_0x54c474['length']+_0x546bf0(0x221)+_0x3158e0[_0x546bf0(0x1f0)]+_0x546bf0(0x22c));const _0x34e79b=()=>{const _0x5d49ce=_0x546bf0,_0x7df6f2=[];_0x54c474[_0x5d49ce(0x1f0)]>0x0&&_0x7df6f2[_0x5d49ce(0x23d)](_0x54c474[_0x5d49ce(0x212)]('\x0a\x0a'));_0x3158e0['length']>0x0&&_0x7df6f2['push'](generateToolPrompt(_0x3158e0));if(_0x462192[_0x5d49ce(0x294)]&&_0x462192[_0x5d49ce(0x294)][_0x5d49ce(0x1f0)]>0x1){const _0xe6ea88=formatConversationHistory(_0x462192['messages']);_0xe6ea88&&_0x7df6f2[_0x5d49ce(0x23d)](_0x5d49ce(0x1ee)+_0xe6ea88+_0x5d49ce(0x209));}return _0x7df6f2[_0x5d49ce(0x23d)](_0x5d49ce(0x25c)+_0x1d9394),_0x7df6f2[_0x5d49ce(0x212)](_0x5d49ce(0x225));};let _0x2b1d3f;if(_0x20dc00)this['logger'][_0x546bf0(0x28e)](_0x546bf0(0x27a)),_0x2b1d3f=_0x34e79b();else{const _0x4bb610=[];_0x346c16[_0x546bf0(0x1f0)]>0x0&&(_0x4bb610[_0x546bf0(0x23d)](_0x346c16['join']('\x0a\x0a')),this[_0x546bf0(0x1e3)][_0x546bf0(0x28e)](_0x546bf0(0x22e),_0x346c16[_0x546bf0(0x1f0)],_0x546bf0(0x1fe)));if(_0x2ce463['length']>0x0)try{_0x4bb610['push'](generateToolPrompt(_0x2ce463)),this[_0x546bf0(0x1e3)][_0x546bf0(0x28e)](_0x546bf0(0x22e),_0x2ce463['length'],_0x546bf0(0x20f));}catch(_0x6c7798){this[_0x546bf0(0x1e3)][_0x546bf0(0x1e6)](_0x546bf0(0x28f),_0x6c7798);}try{const _0x286e8d=extractToolResults(_0x5d07ba);_0x286e8d&&(_0x4bb610[_0x546bf0(0x23d)](_0x286e8d),this[_0x546bf0(0x1e3)][_0x546bf0(0x28e)](_0x546bf0(0x222)));}catch(_0x1258e4){this[_0x546bf0(0x1e3)][_0x546bf0(0x1e6)](_0x546bf0(0x1ff),_0x1258e4);}_0x4bb610['push'](_0x1d9394),_0x2b1d3f=_0x4bb610[_0x546bf0(0x1f0)]>0x1?_0x4bb610[_0x546bf0(0x212)](_0x546bf0(0x225)):_0x1d9394;for(const _0x96b965 of _0x346c16){_0x5c1af5[_0x546bf0(0x246)][_0x546bf0(0x241)](_0x96b965);}for(const _0x10e9b2 of _0x2ce463){_0x5c1af5[_0x546bf0(0x202)][_0x546bf0(0x1f6)](_0x10e9b2['name'],_0x10e9b2);}}let _0x23f559=![];(!_0x2b1d3f||!_0x2b1d3f[_0x546bf0(0x22f)]())&&(this['logger']['warn'](_0x546bf0(0x285)),this[_0x546bf0(0x1e3)][_0x546bf0(0x1eb)](_0x546bf0(0x226),{'isNewContext':_0x20dc00,'userMessageLength':_0x1d9394?.[_0x546bf0(0x1f0)]||0x0,'systemPromptsCount':_0x54c474[_0x546bf0(0x1f0)],'toolsCount':_0x3158e0[_0x546bf0(0x1f0)],'messagesCount':_0x462192[_0x546bf0(0x294)]?.['length']||0x0,'newMessagesCount':_0x5d07ba['length']}),_0x5c1af5['chatId']='',_0x5c1af5[_0x546bf0(0x246)]['clear'](),_0x5c1af5[_0x546bf0(0x202)][_0x546bf0(0x21c)](),_0x23f559=!![],_0x2b1d3f=_0x34e79b(),(!_0x2b1d3f||!_0x2b1d3f[_0x546bf0(0x22f)]())&&(this[_0x546bf0(0x1e3)][_0x546bf0(0x1e6)](_0x546bf0(0x23e)),this[_0x546bf0(0x1e3)][_0x546bf0(0x1e6)]('Debug\x20info:',{'systemPromptsCount':_0x54c474[_0x546bf0(0x1f0)],'toolsCount':_0x3158e0[_0x546bf0(0x1f0)],'messagesCount':_0x462192['messages']?.[_0x546bf0(0x1f0)]||0x0,'userMessageLength':_0x1d9394?.['length']||0x0}),_0x2b1d3f='continue'),this[_0x546bf0(0x1e3)]['info'](_0x546bf0(0x210),_0x2b1d3f[_0x546bf0(0x1ef)](0x0,0x64)+_0x546bf0(0x272)));const _0x300eac=_0x462192[_0x546bf0(0x1f9)]!==![];if(_0x300eac){_0x3b1085[_0x546bf0(0x260)][_0x546bf0(0x283)](0xc8,{'Content-Type':_0x546bf0(0x1fd),'Cache-Control':_0x546bf0(0x1e8),'Connection':_0x546bf0(0x257),'X-Accel-Buffering':'no'});const _0x443dea=generateMessageId();try{const _0xc570e1=this['config'][_0x546bf0(0x261)][_0x546bf0(0x27c)][_0x546bf0(0x279)](_0x2b1d3f,{'chatId':_0x5c1af5[_0x546bf0(0x1f8)]||undefined,'agentId':_0x5c1af5[_0x546bf0(0x1f8)]?undefined:_0x5c1af5[_0x546bf0(0x207)]});if(!_0xc570e1){this[_0x546bf0(0x1e3)][_0x546bf0(0x1e6)](_0x546bf0(0x299)),this[_0x546bf0(0x1e3)][_0x546bf0(0x1e6)](_0x546bf0(0x226),JSON[_0x546bf0(0x273)]({'chatId':_0x5c1af5['chatId'],'agentId':_0x5c1af5[_0x546bf0(0x207)],'model':_0x462192[_0x546bf0(0x25b)],'sessionId':_0x5ec753,'contextSignature':_0x52c374})),_0x5c1af5[_0x546bf0(0x1f8)]='',this[_0x546bf0(0x1e3)]['warn'](_0x546bf0(0x278));const _0x395cf7=formatAnthropicSSE({'type':_0x546bf0(0x1e6),'error':{'type':'api_error','message':_0x546bf0(0x249)},'request_id':_0x443dea});_0x3b1085[_0x546bf0(0x260)][_0x546bf0(0x26e)](_0x395cf7),_0x3b1085[_0x546bf0(0x260)]['end']();return;}_0xcd8768[_0x546bf0(0x208)]=_0x462192['messages'];const _0x4fb374=_0x5c1af5,_0x4af81b=_0x20dc00||_0x23f559;async function*_0x4f7456(_0x1de72d){const _0x3c2ab7=_0x546bf0;for await(const _0x40c7a4 of _0x1de72d){if(_0x40c7a4[_0x3c2ab7(0x224)]===_0x3c2ab7(0x20c)){if(_0x40c7a4[_0x3c2ab7(0x277)][_0x3c2ab7(0x1f8)]&&!_0x4fb374[_0x3c2ab7(0x1f8)]){_0x4fb374['chatId']=_0x40c7a4[_0x3c2ab7(0x277)]['chatId'];if(_0x4af81b){for(const _0x5321bb of _0x54c474){_0x4fb374[_0x3c2ab7(0x246)][_0x3c2ab7(0x241)](_0x5321bb);}for(const _0x25e063 of _0x3158e0){_0x4fb374['embeddedToolsByName'][_0x3c2ab7(0x1f6)](_0x25e063[_0x3c2ab7(0x24e)],_0x25e063);}}}}else _0x40c7a4['type']===_0x3c2ab7(0x26a)&&(yield _0x40c7a4[_0x3c2ab7(0x277)]);}}const _0x170a7e=_0x4f7456(_0xc570e1),_0x36e517=estimateInputTokensFromRequest(_0x462192),_0x15e81d=transformTDStreamWithToolDetection(_0x170a7e,_0x443dea,_0x462192[_0x546bf0(0x25b)],this[_0x546bf0(0x1e3)],_0x1d9394,_0x36e517);let _0x4c0e7a=0x0;for await(const _0x2b8ab0 of _0x15e81d){const _0x42e5ad=formatAnthropicSSE(_0x2b8ab0);_0x4c0e7a++,this[_0x546bf0(0x1e3)][_0x546bf0(0x28e)](colorizeJSONCompact(_0x2b8ab0,{'color':!![]})),_0x2b8ab0[_0x546bf0(0x224)]===_0x546bf0(0x1e6)&&_0x2b8ab0['error'][_0x546bf0(0x224)]==='request_too_large'&&(_0x5c1af5['chatId']='',this[_0x546bf0(0x1e3)]['warn']('[CONTEXT\x20LENGTH\x20ERROR]\x20Cleared\x20chat\x20ID\x20for\x20session\x20'+_0x5ec753+_0x546bf0(0x229)+_0x52c374)),_0x3b1085['raw']['write'](_0x42e5ad);}this[_0x546bf0(0x1e3)]['debug'](_0x546bf0(0x242)+_0x4c0e7a+_0x546bf0(0x213)),_0x3b1085[_0x546bf0(0x260)]['end']();}catch(_0x2f9660){const _0x43a453=_0x2f9660 instanceof Error?_0x2f9660[_0x546bf0(0x219)]:_0x546bf0(0x266);this[_0x546bf0(0x1e3)][_0x546bf0(0x1e6)](_0x546bf0(0x1fb),_0x2f9660),this[_0x546bf0(0x1e3)]['error'](_0x546bf0(0x226),JSON[_0x546bf0(0x273)]({'chatId':_0x5c1af5[_0x546bf0(0x1f8)],'agentId':_0x5c1af5['agentId'],'model':_0x462192[_0x546bf0(0x25b)],'sessionId':_0x5ec753,'contextSignature':_0x52c374})),_0x5c1af5['chatId']='',this[_0x546bf0(0x1e3)][_0x546bf0(0x1eb)](_0x546bf0(0x278));const _0xfa06c0=formatAnthropicSSE({'type':_0x546bf0(0x1e6),'error':{'type':_0x546bf0(0x251),'message':_0x43a453},'request_id':_0x443dea});_0x3b1085[_0x546bf0(0x260)][_0x546bf0(0x26e)](_0xfa06c0),_0x3b1085[_0x546bf0(0x260)][_0x546bf0(0x259)]();}}else this[_0x546bf0(0x1e3)][_0x546bf0(0x1e6)](_0x546bf0(0x265)),_0x3b1085[_0x546bf0(0x1f7)](0x1f5)['send']({'type':_0x546bf0(0x1e6),'error':{'type':_0x546bf0(0x264),'message':'Non-streaming\x20responses\x20are\x20not\x20yet\x20supported'}});}async[a41_0x57a0f4(0x29b)](_0x507812){const _0xe45370=a41_0x57a0f4,_0x19add8=_0x507812['body'],_0x114c06=estimateInputTokensFromRequest(_0x19add8);return this['logger']['info'](_0x507812[_0xe45370(0x206)]+'\x20'+_0x507812[_0xe45370(0x21a)]+_0xe45370(0x22d)+_0x114c06),{'input_tokens':_0x114c06};}async['start'](){const _0x56ccc0=a41_0x57a0f4;try{await this[_0x56ccc0(0x1f1)][_0x56ccc0(0x1f4)]({'port':this['config'][_0x56ccc0(0x243)],'host':_0x56ccc0(0x218)}),this['cleanupInterval']=setInterval(()=>{const _0x468ba2=_0x56ccc0;this[_0x468ba2(0x25d)]();},CLEANUP_INTERVAL_MS),this[_0x56ccc0(0x1e3)][_0x56ccc0(0x28e)](_0x56ccc0(0x214)+CLEANUP_INTERVAL_MS/0x3e8+_0x56ccc0(0x297)+CACHE_EXPIRATION_MS/0x3e8+'s)');}catch(_0x163a86){const _0x1550f0=_0x163a86 instanceof Error?_0x163a86[_0x56ccc0(0x219)]:_0x56ccc0(0x266);throw new Error(_0x56ccc0(0x26d)+_0x1550f0);}}async['stop'](){const _0x4dfc60=a41_0x57a0f4;this[_0x4dfc60(0x1f2)]&&(clearInterval(this[_0x4dfc60(0x1f2)]),this[_0x4dfc60(0x1f2)]=undefined),await this[_0x4dfc60(0x1f1)][_0x4dfc60(0x1ea)]();}[a41_0x57a0f4(0x26f)](){const _0x40f7e4=a41_0x57a0f4,_0x151773=this[_0x40f7e4(0x1f1)][_0x40f7e4(0x1f1)][_0x40f7e4(0x28b)]();if(typeof _0x151773===_0x40f7e4(0x216))return _0x151773;if(_0x151773)return _0x40f7e4(0x248)+_0x151773[_0x40f7e4(0x28b)]+':'+_0x151773['port'];return _0x40f7e4(0x276)+this[_0x40f7e4(0x268)]['port'];}}
1
+ const a41_0x473c7e=a41_0xbad8;(function(_0x2ee2ee,_0x2550c4){const _0x5e0bdb=a41_0xbad8,_0x3451f0=_0x2ee2ee();while(!![]){try{const _0xf38891=-parseInt(_0x5e0bdb(0x1b3))/0x1+-parseInt(_0x5e0bdb(0x1c0))/0x2+parseInt(_0x5e0bdb(0x1b6))/0x3+-parseInt(_0x5e0bdb(0x110))/0x4+-parseInt(_0x5e0bdb(0x170))/0x5+-parseInt(_0x5e0bdb(0x15f))/0x6*(parseInt(_0x5e0bdb(0x146))/0x7)+parseInt(_0x5e0bdb(0x14d))/0x8;if(_0xf38891===_0x2550c4)break;else _0x3451f0['push'](_0x3451f0['shift']());}catch(_0x3357ec){_0x3451f0['push'](_0x3451f0['shift']());}}}(a41_0x2c33,0xcc3bf));function a41_0x2c33(){const _0x1c0a2f=['send','3236780ovWJQi','tools\x20must\x20be\x20an\x20array\x20if\x20provided',',\x20context:\x20','messageHistory','has','tdx','sort','map','Failed\x20to\x20reconstruct\x20message\x20-\x20all\x20parts\x20are\x20empty,\x20using\x20fallback','user','Added\x20system\x20prompt\x20previews:','write','\x20tools','4546300ZaUeax','\x20for\x20context:\x20','\x20system\x20prompts,\x20','raw','port','url','...','chats','server','model','code','logger','end','/v1/messages','[Previous\x20conversation]\x0a\x0a<conversation>\x0a','filter','[PROXY\x20ERROR]\x20Uncaught\x20error\x20in\x20','setErrorHandler','Final\x20message\x20is\x20empty\x20after\x20construction\x20-\x20starting\x20fresh\x20conversation','Failed\x20to\x20initialize\x20chat\x20stream.\x20Please\x20try\x20again.','Assistant','handleCountTokens','size','Failed\x20to\x20start\x20proxy\x20server:\x20','Project\x20ID\x20must\x20be\x20configured','headers','Authorization','llm','[PROXY\x20ERROR]\x20Validation\x20failed:\x20No\x20user\x20message\x20found\x20in\x20request','set','cleanupExpiredChats','string','new\x20tool(s)','warn','chat','sessionCache','delete','trace','handleMessages','Stream\x20complete.\x20Sent\x20','Non-streaming\x20responses\x20are\x20not\x20yet\x20supported','agentCache','clear','No\x20user\x20message\x20found\x20in\x20request','\x20limit','unknown','system','slice','\x0a---\x0a\x0a','New\x20-\x20system\x20prompts:\x20','Chat\x20creation\x20failed,\x20will\x20fall\x20back\x20to\x20lazy\x20creation:','get','isArray',',\x20is\x20new\x20context:\x20','7bRRkSU','0.0.0.0','anthropic-version','error','debug',':\x20estimated\x20input_tokens=','attributes','49708224XgUeKM','keys','setupMiddleware','chatId','embeddedSystemPrompts','Context:','setupRoutes',':\x20messages=','TD\x20LLM\x20Proxy\x20Server','hex','\x20(model:\x20','continue','pop','catch','\x20|\x20','Chat\x20ID:\x20','info','body','9553872ymXPti','address','/health','Created\x20a\x20new\x20chat\x20id:\x20','http://',')\x20to\x20stay\x20under\x20','tools','\x20chars.\x20Cleared\x20chat\x20state\x20for\x20session\x20','Failed\x20to\x20generate\x20tool\x20prompt:','trim','config','[PROXY\x20ERROR]\x20Validation\x20failed:\x20messages\x20array\x20is\x20required\x20and\x20must\x20not\x20be\x20empty','content','Created\x20new\x20chat:\x20','api_error','Reset\x20chat\x20ID\x20to\x20recover\x20on\x20next\x20request','Reset\x20chat\x20state\x20to\x20recover\x20on\x20next\x20request','7540205NOezla','embeddedToolsByName','message','Creating/looking\x20up\x20agent\x20for:\x20','text','writeHead','sha256','length','getAgentForModel',',\x20tools:\x20','Including\x20tool\x20results','type','Unknown\x20error','data','listen','[session:\x20','[PROXY\x20ERROR]\x20Streaming\x20error:','Model\x20normalization:\x20','s,\x20expires\x20after\x20','text/event-stream','Embedded\x20in\x20chat\x20-\x20system\x20prompts:\x20','getOrCreateSession','[PROXY\x20ERROR]\x20Validation\x20failed:\x20message.content\x20must\x20be\x20a\x20string\x20or\x20array,\x20got:','Added\x20tool\x20names:','stream','not_supported_error','substring','Debug\x20info:','close','role','push','getOrCreateDefaultAgent','update','method','no-cache','invalid_request_error','Evicted\x20oldest\x20chat\x20(signature:\x20','startChat',',\x20model=','request_too_large','[PROXY\x20ERROR]\x20Chat\x20stream\x20is\x20undefined','Started\x20cache\x20cleanup\x20interval\x20(runs\x20every\x20','name','System\x20prompts:\x20','now','input_schema',',\x20context\x20signature:\x20','new\x20system\x20prompt(s)','\x0a</conversation>','join','POST','Content-Type','\x20Input\x20size:\x20','cleanupInterval','post','Embedding','sent','[PROXY\x20ERROR]\x20Unhandled\x20error\x20in\x20','add','messages\x20array\x20is\x20required\x20and\x20must\x20not\x20be\x20empty','messages','header:\x20','agentId','/v1/messages/count_tokens','stringify','getAddress','User','548659SMjYNy','\x20->\x20','user_id','3080976bAkmEN','handleRouteError','\x20SSE\x20events.','lastUsedAt','register','metadata','default','digest','start'];a41_0x2c33=function(){return _0x1c0a2f;};return a41_0x2c33();}import a41_0x1ef548 from'fastify';import a41_0x21ff19 from'@fastify/cors';import{createHash}from'crypto';import{transformTDStreamWithToolDetection,formatAnthropicSSE,generateMessageId,generateToolPrompt,extractToolResults,estimateInputTokensFromRequest}from'./anthropic-adapter.js';import{colorizeJSON,colorizeJSONCompact}from'../utils/colors.js';import{extractModelAlias,resolveModelAlias}from'../utils/model-aliases.js';import{SessionCache}from'./session-cache.js';function a41_0xbad8(_0x3f316b,_0x19dff8){const _0x2c3380=a41_0x2c33();return a41_0xbad8=function(_0xbad8bf,_0x127e4b){_0xbad8bf=_0xbad8bf-0x10b;let _0x564e83=_0x2c3380[_0xbad8bf];return _0x564e83;},a41_0xbad8(_0x3f316b,_0x19dff8);}function formatConversationHistory(_0xd0a506){const _0x148696=a41_0xbad8;if(!_0xd0a506||!Array[_0x148696(0x144)](_0xd0a506))return'';return _0xd0a506[_0x148696(0x11f)](_0x34609e=>_0x34609e!=null)[_0x148696(0x1c7)](_0x6c17a7=>{const _0x5650fd=_0x148696,_0x991cf0=_0x6c17a7['content']!=null&&Array[_0x5650fd(0x144)](_0x6c17a7[_0x5650fd(0x16b)])?_0x6c17a7[_0x5650fd(0x16b)]['filter'](_0x3a93ff=>_0x3a93ff&&_0x3a93ff[_0x5650fd(0x17b)]===_0x5650fd(0x174))[_0x5650fd(0x1c7)](_0x299a8f=>_0x299a8f['text'])[_0x5650fd(0x1a1)]('\x0a'):_0x6c17a7[_0x5650fd(0x16b)]||'',_0x2a2a8b=_0x6c17a7[_0x5650fd(0x18d)]===_0x5650fd(0x10c)?_0x5650fd(0x1b2):_0x5650fd(0x124);return _0x2a2a8b+':\x20'+_0x991cf0;})[_0x148696(0x1a1)]('\x0a\x0a');}function calculateContextSignature(_0x5a4ca8,_0x182c19,_0x1bd663){const _0x30a9b4=a41_0xbad8,_0x275be8=extractModelAlias(_0x5a4ca8),_0x145c61=resolveModelAlias(_0x275be8),_0x2078a9=[..._0x182c19||[]][_0x30a9b4(0x1c6)](),_0x194438=(_0x1bd663||[])[_0x30a9b4(0x11f)](_0x32b720=>_0x32b720!=null)[_0x30a9b4(0x1c7)](_0x4f5223=>({'name':_0x4f5223[_0x30a9b4(0x19a)],'params':Object[_0x30a9b4(0x14e)](_0x4f5223[_0x30a9b4(0x19d)]?.['properties']||{})[_0x30a9b4(0x1c6)](),'required':(_0x4f5223['input_schema']?.['required']||[])[_0x30a9b4(0x1c6)]()}))[_0x30a9b4(0x1c6)]((_0x357f86,_0x2602b3)=>_0x357f86['name']['localeCompare'](_0x2602b3[_0x30a9b4(0x19a)])),_0x291f1f=JSON['stringify']({'model':_0x145c61,'prompts':_0x2078a9,'tools':_0x194438});return createHash(_0x30a9b4(0x176))[_0x30a9b4(0x190)](_0x291f1f)[_0x30a9b4(0x1bd)](_0x30a9b4(0x156))[_0x30a9b4(0x18a)](0x0,0x10);}function clearChatState(_0x6f2467){const _0xac22ba=a41_0xbad8;_0x6f2467[_0xac22ba(0x150)]='',_0x6f2467[_0xac22ba(0x151)][_0xac22ba(0x13a)](),_0x6f2467[_0xac22ba(0x171)][_0xac22ba(0x13a)]();}const MAX_CHATS_PER_SESSION=0xa,CACHE_EXPIRATION_MS=0xa*0x3c*0x3e8,CLEANUP_INTERVAL_MS=0x3c*0x3e8;export class ProxyServer{[a41_0x473c7e(0x118)];['sessionCache'];[a41_0x473c7e(0x139)];['config'];[a41_0x473c7e(0x1a5)];['logger'];constructor(_0x2add78){const _0x2fcb25=a41_0x473c7e;this[_0x2fcb25(0x11b)]=_0x2add78[_0x2fcb25(0x11b)],this[_0x2fcb25(0x169)]=_0x2add78,this[_0x2fcb25(0x133)]=new SessionCache({'maxChatsPerSession':MAX_CHATS_PER_SESSION,'cacheExpirationMs':CACHE_EXPIRATION_MS}),this[_0x2fcb25(0x139)]=new Map(),this[_0x2fcb25(0x118)]=a41_0x1ef548({'logger':![],'bodyLimit':0x40*0x400*0x400}),this['setupMiddleware'](),this[_0x2fcb25(0x153)]();}async['getAgentForModel'](_0x5ea30c){const _0x3046c6=a41_0x473c7e,_0x1348e2=extractModelAlias(_0x5ea30c),_0x2dcf65=resolveModelAlias(_0x1348e2);let _0x13d335=this[_0x3046c6(0x139)][_0x3046c6(0x143)](_0x2dcf65);if(!_0x13d335){this[_0x3046c6(0x11b)][_0x3046c6(0x14a)](_0x3046c6(0x181)+_0x5ea30c+_0x3046c6(0x1b4)+_0x1348e2+_0x3046c6(0x1b4)+_0x2dcf65),this['logger'][_0x3046c6(0x14a)](_0x3046c6(0x173)+_0x2dcf65);const _0x15ce9b=await this[_0x3046c6(0x169)][_0x3046c6(0x1c5)][_0x3046c6(0x12b)][_0x3046c6(0x18f)](_0x2dcf65);_0x13d335=_0x15ce9b['id'],this['agentCache']['set'](_0x2dcf65,_0x13d335),this['logger'][_0x3046c6(0x14a)]('Agent\x20cached:\x20'+_0x2dcf65+_0x3046c6(0x1b4)+_0x13d335+'\x20('+_0x15ce9b[_0x3046c6(0x14c)]['name']+')');}return _0x13d335;}[a41_0x473c7e(0x12e)](){const _0x4d0274=a41_0x473c7e;this[_0x4d0274(0x133)]['cleanupExpiredChats']();}[a41_0x473c7e(0x14f)](){const _0x640c13=a41_0x473c7e;this[_0x640c13(0x118)][_0x640c13(0x1ba)](a41_0x21ff19,{'origin':!![],'methods':['GET',_0x640c13(0x1a2),'OPTIONS'],'allowedHeaders':[_0x640c13(0x1a3),_0x640c13(0x12a),_0x640c13(0x148),'x-api-key']}),this[_0x640c13(0x118)][_0x640c13(0x121)]((_0x27fc48,_0x3503c9,_0x843c6b)=>{const _0x4b0b41=_0x640c13,_0x3a1ca5=_0x27fc48 instanceof Error?_0x27fc48[_0x4b0b41(0x172)]:_0x4b0b41(0x17c);this[_0x4b0b41(0x11b)][_0x4b0b41(0x149)](_0x4b0b41(0x1a9)+_0x3503c9[_0x4b0b41(0x191)]+'\x20'+_0x3503c9[_0x4b0b41(0x115)]+':',_0x27fc48),_0x843c6b['code'](0x1f4)['send']({'type':_0x4b0b41(0x149),'error':{'type':_0x4b0b41(0x16d),'message':_0x3a1ca5}});});}['handleRouteError'](_0x2646a8,_0x339962,_0x12bf79){const _0x5f3437=a41_0x473c7e,_0x525642=_0x339962 instanceof Error?_0x339962[_0x5f3437(0x172)]:'Unknown\x20error';this[_0x5f3437(0x11b)]['error'](_0x5f3437(0x120)+_0x2646a8+':',_0x339962),!_0x12bf79[_0x5f3437(0x1a8)]&&_0x12bf79['code'](0x1f4)['send']({'type':'error','error':{'type':_0x5f3437(0x16d),'message':_0x525642}});}[a41_0x473c7e(0x153)](){const _0x34125f=a41_0x473c7e;this[_0x34125f(0x118)][_0x34125f(0x143)](_0x34125f(0x161),async()=>{const _0x431ea4=_0x34125f;return{'status':'ok','message':_0x431ea4(0x155)};}),this['server'][_0x34125f(0x1a6)](_0x34125f(0x11d),async(_0x48ab86,_0x415567)=>{const _0x12173d=_0x34125f;return this[_0x12173d(0x136)](_0x48ab86,_0x415567)[_0x12173d(0x15a)](_0x509df0=>{const _0x34eb4d=_0x12173d;this[_0x34eb4d(0x1b7)](_0x34eb4d(0x11d),_0x509df0,_0x415567);});}),this['server'][_0x34125f(0x1a6)](_0x34125f(0x1af),async(_0x330a4c,_0x4325bd)=>{const _0x4ebfc0=_0x34125f;return this[_0x4ebfc0(0x125)](_0x330a4c)[_0x4ebfc0(0x15a)](_0x4f16b6=>{const _0x55f1c0=_0x4ebfc0;this[_0x55f1c0(0x1b7)](_0x55f1c0(0x1af),_0x4f16b6,_0x4325bd);});});}async[a41_0x473c7e(0x136)](_0x51a183,_0x23bb48){const _0x562958=a41_0x473c7e,_0x5d3fe6=_0x51a183[_0x562958(0x15e)];if(!_0x5d3fe6[_0x562958(0x1ac)]||!Array['isArray'](_0x5d3fe6[_0x562958(0x1ac)])||_0x5d3fe6[_0x562958(0x1ac)][_0x562958(0x177)]===0x0){this[_0x562958(0x11b)]['error'](_0x562958(0x16a)),_0x23bb48[_0x562958(0x11a)](0x190)['send']({'type':_0x562958(0x149),'error':{'type':_0x562958(0x193),'message':_0x562958(0x1ab)}});return;}if(_0x5d3fe6[_0x562958(0x165)]&&!Array[_0x562958(0x144)](_0x5d3fe6[_0x562958(0x165)])){this[_0x562958(0x11b)][_0x562958(0x149)]('[PROXY\x20ERROR]\x20Validation\x20failed:\x20tools\x20must\x20be\x20an\x20array\x20if\x20provided'),_0x23bb48[_0x562958(0x11a)](0x190)[_0x562958(0x1bf)]({'type':_0x562958(0x149),'error':{'type':_0x562958(0x193),'message':_0x562958(0x1c1)}});return;}const _0x4d9db5=_0x5d3fe6[_0x562958(0x1ac)]?.['length']??0x0,_0x228d80=_0x5d3fe6[_0x562958(0x119)]||_0x562958(0x13d);this[_0x562958(0x11b)][_0x562958(0x15d)](_0x51a183[_0x562958(0x191)]+'\x20'+_0x51a183[_0x562958(0x115)]+_0x562958(0x154)+_0x4d9db5+_0x562958(0x196)+_0x228d80),this[_0x562958(0x11b)][_0x562958(0x14a)](_0x562958(0x1ad)+colorizeJSONCompact(_0x51a183[_0x562958(0x129)]));this[_0x562958(0x11b)][_0x562958(0x135)]&&this[_0x562958(0x11b)][_0x562958(0x135)](colorizeJSON(_0x5d3fe6,{'color':!![]}));const _0x1fe445=_0x5d3fe6[_0x562958(0x1bb)]?.[_0x562958(0x1b5)]||_0x562958(0x1bc),_0x393d67=this[_0x562958(0x169)]['projectId'];if(!_0x393d67){this['logger'][_0x562958(0x149)]('[PROXY\x20ERROR]\x20Configuration\x20error:\x20Project\x20ID\x20must\x20be\x20configured'),_0x23bb48[_0x562958(0x11a)](0x1f4)[_0x562958(0x1bf)]({'type':'error','error':{'type':_0x562958(0x16d),'message':_0x562958(0x128)}});return;}const _0x14114c=this[_0x562958(0x133)][_0x562958(0x185)](_0x1fe445,_0x393d67),_0x3b948e=_0x14114c[_0x562958(0x1c3)][_0x562958(0x177)],_0x560085=_0x5d3fe6['messages'][_0x562958(0x13f)](_0x3b948e);let _0x3d0b84=_0x560085[_0x562958(0x11f)](_0x4595d9=>_0x4595d9[_0x562958(0x18d)]===_0x562958(0x10c))[_0x562958(0x159)]();if(!_0x3d0b84){_0x3d0b84=_0x5d3fe6[_0x562958(0x1ac)][_0x562958(0x11f)](_0x4f6cf9=>_0x4f6cf9['role']===_0x562958(0x10c))[_0x562958(0x159)]();if(!_0x3d0b84){this[_0x562958(0x11b)]['error'](_0x562958(0x12c)),_0x23bb48['code'](0x190)['send']({'type':_0x562958(0x149),'error':{'type':'invalid_request_error','message':_0x562958(0x13b)}});return;}}let _0x310003;if(typeof _0x3d0b84[_0x562958(0x16b)]===_0x562958(0x12f))_0x310003=_0x3d0b84[_0x562958(0x16b)];else{if(_0x3d0b84['content']!=null&&Array[_0x562958(0x144)](_0x3d0b84[_0x562958(0x16b)]))_0x310003=_0x3d0b84[_0x562958(0x16b)][_0x562958(0x11f)](_0x3b3b33=>_0x3b3b33&&_0x3b3b33['type']==='text'&&_0x3b3b33[_0x562958(0x174)])[_0x562958(0x1c7)](_0x307e8e=>_0x307e8e[_0x562958(0x174)])[_0x562958(0x1a1)]('\x0a');else{this['logger'][_0x562958(0x149)](_0x562958(0x186),typeof _0x3d0b84[_0x562958(0x16b)],_0x3d0b84[_0x562958(0x16b)]),_0x23bb48[_0x562958(0x11a)](0x190)[_0x562958(0x1bf)]({'type':'error','error':{'type':_0x562958(0x193),'message':'message.content\x20must\x20be\x20a\x20string\x20or\x20array'}});return;}}const _0x13a4bc=[];if(_0x5d3fe6[_0x562958(0x13e)]){if(typeof _0x5d3fe6['system']===_0x562958(0x12f))_0x13a4bc['push'](_0x5d3fe6['system']);else{if(Array[_0x562958(0x144)](_0x5d3fe6[_0x562958(0x13e)]))for(const _0x3a59e1 of _0x5d3fe6['system']){_0x3a59e1[_0x562958(0x17b)]===_0x562958(0x174)&&_0x3a59e1[_0x562958(0x174)]&&_0x13a4bc[_0x562958(0x18e)](_0x3a59e1[_0x562958(0x174)]);}}}const _0x5c7d99=_0x5d3fe6[_0x562958(0x165)]||[],_0x22dae9=calculateContextSignature(_0x5d3fe6[_0x562958(0x119)],_0x13a4bc,_0x5c7d99);let _0x33e9dd=_0x14114c[_0x562958(0x117)][_0x562958(0x143)](_0x22dae9);const _0x45d1a0=!_0x33e9dd;if(!_0x33e9dd){const _0x4c28bb=await this[_0x562958(0x178)](_0x5d3fe6['model']);_0x33e9dd={'chatId':'','agentId':_0x4c28bb,'contextSignature':_0x22dae9,'embeddedSystemPrompts':new Set(),'embeddedToolsByName':new Map(),'lastUsedAt':Date[_0x562958(0x19c)]()},_0x14114c['chats']['set'](_0x22dae9,_0x33e9dd);if(_0x14114c[_0x562958(0x117)][_0x562958(0x126)]>MAX_CHATS_PER_SESSION){let _0x521fef=null,_0x43c4fc=Date[_0x562958(0x19c)]();for(const [_0x215118,_0x2167fd]of _0x14114c[_0x562958(0x117)]){_0x2167fd[_0x562958(0x1b9)]<_0x43c4fc&&(_0x43c4fc=_0x2167fd['lastUsedAt'],_0x521fef=_0x215118);}_0x521fef&&(_0x14114c[_0x562958(0x117)][_0x562958(0x134)](_0x521fef),this['logger'][_0x562958(0x14a)](_0x562958(0x194)+_0x521fef+_0x562958(0x164)+MAX_CHATS_PER_SESSION+_0x562958(0x13c)));}}else _0x33e9dd['lastUsedAt']=Date[_0x562958(0x19c)]();if(!_0x33e9dd['chatId'])try{const _0x28e384=await this[_0x562958(0x169)][_0x562958(0x1c5)][_0x562958(0x12b)][_0x562958(0x195)](_0x33e9dd['agentId']);_0x33e9dd['chatId']=_0x28e384['id'],this[_0x562958(0x11b)][_0x562958(0x14a)](_0x562958(0x16c)+_0x28e384['id']+_0x562958(0x111)+_0x22dae9),this[_0x562958(0x11b)][_0x562958(0x14a)]('Using\x20agent:\x20'+_0x33e9dd[_0x562958(0x1ae)]+_0x562958(0x157)+_0x5d3fe6[_0x562958(0x119)]+')');}catch(_0x1c36e9){this[_0x562958(0x11b)][_0x562958(0x149)](_0x562958(0x142),_0x1c36e9);}const _0x591e4a=_0x13a4bc[_0x562958(0x11f)](_0x471c27=>!_0x33e9dd[_0x562958(0x151)][_0x562958(0x1c4)](_0x471c27)),_0x64825e=_0x5c7d99[_0x562958(0x11f)](_0x37bea2=>!_0x33e9dd[_0x562958(0x171)][_0x562958(0x1c4)](_0x37bea2['name']));this['logger'][_0x562958(0x14a)](_0x562958(0x17f)+_0x1fe445+']\x20model:\x20'+_0x5d3fe6[_0x562958(0x119)]+_0x562958(0x19e)+_0x22dae9+_0x562958(0x145)+_0x45d1a0),this[_0x562958(0x11b)][_0x562958(0x14a)](_0x562958(0x15c)+_0x33e9dd['chatId']),this[_0x562958(0x11b)][_0x562958(0x14a)](_0x562958(0x19b)+_0x13a4bc[_0x562958(0x177)]+_0x562958(0x179)+_0x5c7d99['length']),this[_0x562958(0x11b)][_0x562958(0x14a)](_0x562958(0x184)+_0x33e9dd['embeddedSystemPrompts']['size']+',\x20tools:\x20'+_0x33e9dd['embeddedToolsByName'][_0x562958(0x126)]),this[_0x562958(0x11b)][_0x562958(0x14a)](_0x562958(0x141)+_0x591e4a[_0x562958(0x177)]+',\x20tools:\x20'+_0x64825e['length']);_0x591e4a[_0x562958(0x177)]>0x0&&this[_0x562958(0x11b)]['debug'](_0x562958(0x10d),_0x591e4a[_0x562958(0x1c7)](_0x3b565b=>_0x3b565b['substring'](0x0,0x32)+_0x562958(0x116))['join'](_0x562958(0x15b)));_0x64825e[_0x562958(0x177)]>0x0&&this[_0x562958(0x11b)]['debug'](_0x562958(0x187),_0x64825e['map'](_0x3f3e1f=>_0x3f3e1f['name'])[_0x562958(0x1a1)](',\x20'));_0x45d1a0&&this[_0x562958(0x11b)][_0x562958(0x15d)](_0x562958(0x162)+_0x33e9dd[_0x562958(0x150)]+',\x20model='+_0x5d3fe6[_0x562958(0x119)]+',\x20'+_0x13a4bc[_0x562958(0x177)]+_0x562958(0x112)+_0x5c7d99[_0x562958(0x177)]+_0x562958(0x10f));const _0x2f9db3=()=>{const _0x442ce9=_0x562958,_0x418da5=[];_0x13a4bc[_0x442ce9(0x177)]>0x0&&_0x418da5['push'](_0x13a4bc[_0x442ce9(0x1a1)]('\x0a\x0a'));_0x5c7d99[_0x442ce9(0x177)]>0x0&&_0x418da5[_0x442ce9(0x18e)](generateToolPrompt(_0x5c7d99));if(_0x5d3fe6[_0x442ce9(0x1ac)]&&_0x5d3fe6['messages'][_0x442ce9(0x177)]>0x1){const _0x304716=formatConversationHistory(_0x5d3fe6[_0x442ce9(0x1ac)]);_0x304716&&_0x418da5[_0x442ce9(0x18e)](_0x442ce9(0x11e)+_0x304716+_0x442ce9(0x1a0));}return _0x418da5[_0x442ce9(0x18e)]('[Current\x20message]\x0a\x0a'+_0x310003),_0x418da5[_0x442ce9(0x1a1)](_0x442ce9(0x140));};let _0x5528d2;if(_0x45d1a0)this[_0x562958(0x11b)][_0x562958(0x14a)]('New\x20context\x20-\x20including\x20full\x20context'),_0x5528d2=_0x2f9db3();else{const _0x35158f=[];_0x591e4a['length']>0x0&&(_0x35158f['push'](_0x591e4a['join']('\x0a\x0a')),this[_0x562958(0x11b)]['debug'](_0x562958(0x1a7),_0x591e4a['length'],_0x562958(0x19f)));if(_0x64825e[_0x562958(0x177)]>0x0)try{_0x35158f[_0x562958(0x18e)](generateToolPrompt(_0x64825e)),this['logger'][_0x562958(0x14a)]('Embedding',_0x64825e[_0x562958(0x177)],_0x562958(0x130));}catch(_0x4432c1){this[_0x562958(0x11b)][_0x562958(0x149)](_0x562958(0x167),_0x4432c1);}try{const _0x29289a=extractToolResults(_0x560085);_0x29289a&&(_0x35158f[_0x562958(0x18e)](_0x29289a),this[_0x562958(0x11b)][_0x562958(0x14a)](_0x562958(0x17a)));}catch(_0x27728a){this[_0x562958(0x11b)][_0x562958(0x149)]('Failed\x20to\x20extract\x20tool\x20results:',_0x27728a);}_0x35158f[_0x562958(0x18e)](_0x310003),_0x5528d2=_0x35158f[_0x562958(0x177)]>0x1?_0x35158f[_0x562958(0x1a1)](_0x562958(0x140)):_0x310003;for(const _0x5d5722 of _0x591e4a){_0x33e9dd[_0x562958(0x151)][_0x562958(0x1aa)](_0x5d5722);}for(const _0x440a56 of _0x64825e){_0x33e9dd[_0x562958(0x171)][_0x562958(0x12d)](_0x440a56[_0x562958(0x19a)],_0x440a56);}}let _0x5743ef=![];(!_0x5528d2||!_0x5528d2[_0x562958(0x168)]())&&(this[_0x562958(0x11b)][_0x562958(0x131)](_0x562958(0x122)),this[_0x562958(0x11b)][_0x562958(0x131)](_0x562958(0x152),{'isNewContext':_0x45d1a0,'userMessageLength':_0x310003?.['length']||0x0,'systemPromptsCount':_0x13a4bc[_0x562958(0x177)],'toolsCount':_0x5c7d99['length'],'messagesCount':_0x5d3fe6['messages']?.[_0x562958(0x177)]||0x0,'newMessagesCount':_0x560085[_0x562958(0x177)]}),clearChatState(_0x33e9dd),_0x5743ef=!![],_0x5528d2=_0x2f9db3(),(!_0x5528d2||!_0x5528d2['trim']())&&(this[_0x562958(0x11b)][_0x562958(0x149)](_0x562958(0x10b)),this[_0x562958(0x11b)][_0x562958(0x149)](_0x562958(0x18b),{'systemPromptsCount':_0x13a4bc[_0x562958(0x177)],'toolsCount':_0x5c7d99[_0x562958(0x177)],'messagesCount':_0x5d3fe6[_0x562958(0x1ac)]?.[_0x562958(0x177)]||0x0,'userMessageLength':_0x310003?.[_0x562958(0x177)]||0x0}),_0x5528d2=_0x562958(0x158)),this[_0x562958(0x11b)]['info']('Final\x20message\x20reconstructed\x20after\x20context\x20reset:',_0x5528d2[_0x562958(0x18a)](0x0,0x64)+'...'));const _0x43cedb=_0x5d3fe6[_0x562958(0x188)]!==![];if(_0x43cedb){_0x23bb48['raw'][_0x562958(0x175)](0xc8,{'Content-Type':_0x562958(0x183),'Cache-Control':_0x562958(0x192),'Connection':'keep-alive','X-Accel-Buffering':'no'});const _0x5037e1=generateMessageId();try{const _0x292375=this['config'][_0x562958(0x1c5)][_0x562958(0x12b)][_0x562958(0x132)](_0x5528d2,{'chatId':_0x33e9dd[_0x562958(0x150)]||undefined,'agentId':_0x33e9dd['chatId']?undefined:_0x33e9dd[_0x562958(0x1ae)]});if(!_0x292375){this[_0x562958(0x11b)][_0x562958(0x149)](_0x562958(0x198)),this['logger'][_0x562958(0x149)]('Context:',JSON[_0x562958(0x1b0)]({'chatId':_0x33e9dd[_0x562958(0x150)],'agentId':_0x33e9dd[_0x562958(0x1ae)],'model':_0x5d3fe6[_0x562958(0x119)],'sessionId':_0x1fe445,'contextSignature':_0x22dae9})),_0x33e9dd[_0x562958(0x150)]='',this[_0x562958(0x11b)][_0x562958(0x131)](_0x562958(0x16e));const _0x4fec4d=formatAnthropicSSE({'type':_0x562958(0x149),'error':{'type':'api_error','message':_0x562958(0x123)},'request_id':_0x5037e1});_0x23bb48['raw']['write'](_0x4fec4d),_0x23bb48[_0x562958(0x113)][_0x562958(0x11c)]();return;}_0x14114c[_0x562958(0x1c3)]=_0x5d3fe6[_0x562958(0x1ac)];const _0x5cc4f3=_0x33e9dd,_0x48591e=_0x45d1a0||_0x5743ef;async function*_0x544ca6(_0x41667e){const _0x3eab9e=_0x562958;for await(const _0x3c5e82 of _0x41667e){if(_0x3c5e82['type']===_0x3eab9e(0x1bb)){if(_0x3c5e82[_0x3eab9e(0x17d)]['chatId']&&!_0x5cc4f3['chatId']){_0x5cc4f3[_0x3eab9e(0x150)]=_0x3c5e82[_0x3eab9e(0x17d)][_0x3eab9e(0x150)];if(_0x48591e){for(const _0x17fa09 of _0x13a4bc){_0x5cc4f3[_0x3eab9e(0x151)][_0x3eab9e(0x1aa)](_0x17fa09);}for(const _0x5ae248 of _0x5c7d99){_0x5cc4f3[_0x3eab9e(0x171)]['set'](_0x5ae248[_0x3eab9e(0x19a)],_0x5ae248);}}}}else _0x3c5e82[_0x3eab9e(0x17b)]==='event'&&(yield _0x3c5e82['data']);}}const _0x4730c3=_0x544ca6(_0x292375),_0x3c8d66=estimateInputTokensFromRequest(_0x5d3fe6),_0x19d2f0=transformTDStreamWithToolDetection(_0x4730c3,_0x5037e1,_0x5d3fe6['model'],this['logger'],_0x310003,_0x3c8d66),_0x2bcd56=_0x5528d2['length'];let _0x389069=0x0;for await(const _0x1465d5 of _0x19d2f0){const _0x351828=formatAnthropicSSE(_0x1465d5);_0x389069++,this[_0x562958(0x11b)][_0x562958(0x14a)](colorizeJSONCompact(_0x1465d5,{'color':!![]})),_0x1465d5[_0x562958(0x17b)]===_0x562958(0x149)&&_0x1465d5[_0x562958(0x149)][_0x562958(0x17b)]===_0x562958(0x197)&&(clearChatState(_0x33e9dd),this[_0x562958(0x11b)][_0x562958(0x131)]('[CONTEXT\x20LENGTH\x20ERROR]\x20'+_0x1465d5[_0x562958(0x149)][_0x562958(0x172)]+_0x562958(0x1a4)+_0x2bcd56+_0x562958(0x166)+_0x1fe445+_0x562958(0x1c2)+_0x22dae9)),_0x23bb48[_0x562958(0x113)][_0x562958(0x10e)](_0x351828);}this[_0x562958(0x11b)][_0x562958(0x14a)](_0x562958(0x137)+_0x389069+_0x562958(0x1b8)),_0x23bb48[_0x562958(0x113)][_0x562958(0x11c)]();}catch(_0x334e51){const _0x400fcb=_0x334e51 instanceof Error?_0x334e51[_0x562958(0x172)]:_0x562958(0x17c);this[_0x562958(0x11b)][_0x562958(0x149)](_0x562958(0x180),_0x334e51),this['logger'][_0x562958(0x149)](_0x562958(0x152),JSON[_0x562958(0x1b0)]({'chatId':_0x33e9dd[_0x562958(0x150)],'agentId':_0x33e9dd['agentId'],'model':_0x5d3fe6[_0x562958(0x119)],'sessionId':_0x1fe445,'contextSignature':_0x22dae9})),_0x33e9dd['chatId']='',this[_0x562958(0x11b)][_0x562958(0x131)](_0x562958(0x16f));const _0x5bae03=formatAnthropicSSE({'type':_0x562958(0x149),'error':{'type':_0x562958(0x16d),'message':_0x400fcb},'request_id':_0x5037e1});_0x23bb48[_0x562958(0x113)][_0x562958(0x10e)](_0x5bae03),_0x23bb48[_0x562958(0x113)][_0x562958(0x11c)]();}}else this[_0x562958(0x11b)][_0x562958(0x149)]('[PROXY\x20ERROR]\x20Non-streaming\x20responses\x20are\x20not\x20yet\x20supported'),_0x23bb48['code'](0x1f5)['send']({'type':_0x562958(0x149),'error':{'type':_0x562958(0x189),'message':_0x562958(0x138)}});}async[a41_0x473c7e(0x125)](_0x1d3c7a){const _0xc7c220=a41_0x473c7e,_0x2e34c2=_0x1d3c7a[_0xc7c220(0x15e)],_0x150479=estimateInputTokensFromRequest(_0x2e34c2);return this[_0xc7c220(0x11b)][_0xc7c220(0x15d)](_0x1d3c7a[_0xc7c220(0x191)]+'\x20'+_0x1d3c7a['url']+_0xc7c220(0x14b)+_0x150479),{'input_tokens':_0x150479};}async[a41_0x473c7e(0x1be)](){const _0x897290=a41_0x473c7e;try{await this[_0x897290(0x118)][_0x897290(0x17e)]({'port':this[_0x897290(0x169)]['port'],'host':_0x897290(0x147)}),this[_0x897290(0x1a5)]=setInterval(()=>{this['cleanupExpiredChats']();},CLEANUP_INTERVAL_MS),this[_0x897290(0x11b)][_0x897290(0x14a)](_0x897290(0x199)+CLEANUP_INTERVAL_MS/0x3e8+_0x897290(0x182)+CACHE_EXPIRATION_MS/0x3e8+'s)');}catch(_0x28e13e){const _0x46a97f=_0x28e13e instanceof Error?_0x28e13e['message']:'Unknown\x20error';throw new Error(_0x897290(0x127)+_0x46a97f);}}async['stop'](){const _0x4af1ba=a41_0x473c7e;this[_0x4af1ba(0x1a5)]&&(clearInterval(this[_0x4af1ba(0x1a5)]),this['cleanupInterval']=undefined),await this[_0x4af1ba(0x118)][_0x4af1ba(0x18c)]();}[a41_0x473c7e(0x1b1)](){const _0x461294=a41_0x473c7e,_0x44e64f=this[_0x461294(0x118)][_0x461294(0x118)][_0x461294(0x160)]();if(typeof _0x44e64f===_0x461294(0x12f))return _0x44e64f;if(_0x44e64f)return _0x461294(0x163)+_0x44e64f[_0x461294(0x160)]+':'+_0x44e64f[_0x461294(0x114)];return'http://localhost:'+this[_0x461294(0x169)]['port'];}}