@treasuredata/tdx 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/dist/build-info.json +2 -2
  2. package/dist/cli.js +1 -1
  3. package/dist/cli.js.map +1 -1
  4. package/dist/client/cdp-api-client.js +1 -1
  5. package/dist/client/http-client.js +1 -1
  6. package/dist/client/llm-api-client.d.ts +129 -1
  7. package/dist/client/llm-api-client.d.ts.map +1 -1
  8. package/dist/client/llm-api-client.js +1 -1
  9. package/dist/client/llm-api-client.js.map +1 -1
  10. package/dist/client/rate-limiter.js +1 -1
  11. package/dist/client/td-api-client.js +1 -1
  12. package/dist/client/trino-api-client.js +1 -1
  13. package/dist/client/workflow-client.js +1 -1
  14. package/dist/commands/activations.js +1 -1
  15. package/dist/commands/api-command.js +1 -1
  16. package/dist/commands/auth-command.js +1 -1
  17. package/dist/commands/chat-command.js +1 -1
  18. package/dist/commands/claude-command.js +1 -1
  19. package/dist/commands/command.js +1 -1
  20. package/dist/commands/context-command.js +1 -1
  21. package/dist/commands/databases.js +1 -1
  22. package/dist/commands/describe.js +1 -1
  23. package/dist/commands/job-command.js +1 -1
  24. package/dist/commands/llm-command.d.ts +18 -0
  25. package/dist/commands/llm-command.d.ts.map +1 -1
  26. package/dist/commands/llm-command.js +1 -1
  27. package/dist/commands/llm-command.js.map +1 -1
  28. package/dist/commands/llm-proxy.js +1 -1
  29. package/dist/commands/parent-segment-command.js +1 -1
  30. package/dist/commands/profiles-command.js +1 -1
  31. package/dist/commands/query-command.js +1 -1
  32. package/dist/commands/segment-command.d.ts +9 -6
  33. package/dist/commands/segment-command.d.ts.map +1 -1
  34. package/dist/commands/segment-command.js +1 -1
  35. package/dist/commands/segment-command.js.map +1 -1
  36. package/dist/commands/segment-create-command.js +1 -1
  37. package/dist/commands/segment-fields-command.d.ts +3 -1
  38. package/dist/commands/segment-fields-command.d.ts.map +1 -1
  39. package/dist/commands/segment-fields-command.js +1 -1
  40. package/dist/commands/segment-fields-command.js.map +1 -1
  41. package/dist/commands/segment-pwd-command.js +1 -1
  42. package/dist/commands/segment-update-command.js +1 -1
  43. package/dist/commands/segment-use-command.js +1 -1
  44. package/dist/commands/segments.js +1 -1
  45. package/dist/commands/show.js +1 -1
  46. package/dist/commands/tables.js +1 -1
  47. package/dist/commands/use-command.js +1 -1
  48. package/dist/commands/workflow-command.js +1 -1
  49. package/dist/core/auth.js +1 -1
  50. package/dist/core/config.js +1 -1
  51. package/dist/core/credential-cache.js +1 -1
  52. package/dist/core/global-context.js +1 -1
  53. package/dist/core/keychain.d.ts +19 -0
  54. package/dist/core/keychain.d.ts.map +1 -1
  55. package/dist/core/keychain.js +1 -1
  56. package/dist/core/keychain.js.map +1 -1
  57. package/dist/core/profile.js +1 -1
  58. package/dist/core/project-config.js +1 -1
  59. package/dist/core/session.js +1 -1
  60. package/dist/index.js +1 -1
  61. package/dist/proxy/anthropic-adapter.js +1 -1
  62. package/dist/proxy/server.js +1 -1
  63. package/dist/proxy/session-cache.js +1 -1
  64. package/dist/sdk/api.js +1 -1
  65. package/dist/sdk/errors.js +1 -1
  66. package/dist/sdk/index.js +1 -1
  67. package/dist/sdk/job.js +1 -1
  68. package/dist/sdk/llm.d.ts +90 -1
  69. package/dist/sdk/llm.d.ts.map +1 -1
  70. package/dist/sdk/llm.js +1 -1
  71. package/dist/sdk/llm.js.map +1 -1
  72. package/dist/sdk/query.js +1 -1
  73. package/dist/sdk/segment.js +1 -1
  74. package/dist/sdk/workflow.js +1 -1
  75. package/dist/types/endpoints.js +1 -1
  76. package/dist/types/index.d.ts +1 -1
  77. package/dist/types/index.d.ts.map +1 -1
  78. package/dist/types/index.js +1 -1
  79. package/dist/types/llm.d.ts +241 -0
  80. package/dist/types/llm.d.ts.map +1 -1
  81. package/dist/utils/agent-ref-parser.js +1 -1
  82. package/dist/utils/chat-cache.js +1 -1
  83. package/dist/utils/colors.js +1 -1
  84. package/dist/utils/command-output.d.ts.map +1 -1
  85. package/dist/utils/command-output.js +1 -1
  86. package/dist/utils/command-output.js.map +1 -1
  87. package/dist/utils/constants.js +1 -1
  88. package/dist/utils/file-permissions.js +1 -1
  89. package/dist/utils/format-detector.js +1 -1
  90. package/dist/utils/formatters.js +1 -1
  91. package/dist/utils/json-loader.js +1 -1
  92. package/dist/utils/llm-backup-utils.d.ts +37 -0
  93. package/dist/utils/llm-backup-utils.d.ts.map +1 -0
  94. package/dist/utils/llm-backup-utils.js +1 -0
  95. package/dist/utils/llm-backup-utils.js.map +1 -0
  96. package/dist/utils/model-aliases.js +1 -1
  97. package/dist/utils/option-validation.js +1 -1
  98. package/dist/utils/port.js +1 -1
  99. package/dist/utils/process.js +1 -1
  100. package/dist/utils/prompt.js +1 -1
  101. package/dist/utils/segment-path-parser.js +1 -1
  102. package/dist/utils/segment-ref-parser.js +1 -1
  103. package/dist/utils/spinner.js +1 -1
  104. package/dist/utils/sql-parser.js +1 -1
  105. package/dist/utils/sse-parser.js +1 -1
  106. package/dist/utils/string-utils.js +1 -1
  107. package/dist/utils/table-ref-parser.js +1 -1
  108. package/dist/utils/tdx-logger.js +1 -1
  109. package/dist/utils/tree-formatter.js +1 -1
  110. package/dist/utils/version-check.js +1 -1
  111. package/dist/utils/workflow-utils.js +1 -1
  112. package/package.json +1 -1
@@ -1 +1 @@
1
- const a40_0x241a52=a40_0x3e21;(function(_0x32892a,_0x3f8293){const _0x4f3bed=a40_0x3e21,_0x33f5e8=_0x32892a();while(!![]){try{const _0x51acf4=-parseInt(_0x4f3bed(0xb4))/0x1*(parseInt(_0x4f3bed(0xc5))/0x2)+-parseInt(_0x4f3bed(0xac))/0x3+-parseInt(_0x4f3bed(0xc6))/0x4*(parseInt(_0x4f3bed(0xaf))/0x5)+-parseInt(_0x4f3bed(0xba))/0x6*(parseInt(_0x4f3bed(0xc0))/0x7)+-parseInt(_0x4f3bed(0xc2))/0x8+-parseInt(_0x4f3bed(0xb8))/0x9+parseInt(_0x4f3bed(0xbc))/0xa*(parseInt(_0x4f3bed(0xab))/0xb);if(_0x51acf4===_0x3f8293)break;else _0x33f5e8['push'](_0x33f5e8['shift']());}catch(_0x4f49c9){_0x33f5e8['push'](_0x33f5e8['shift']());}}}(a40_0x2a79,0xcf3fb));import*as a40_0x19339b from'node:fs';import*as a40_0x367afb from'node:path';const PROJECT_CONFIG_FILENAME=a40_0x241a52(0xb2);export function findProjectConfigPath(_0x5bab74){const _0x594f04=a40_0x241a52;let _0x2540cc=_0x5bab74||process['cwd']();while(!![]){const _0x40dc0b=a40_0x367afb[_0x594f04(0xb3)](_0x2540cc,PROJECT_CONFIG_FILENAME);if(a40_0x19339b['existsSync'](_0x40dc0b))return _0x40dc0b;const _0x51169d=a40_0x367afb[_0x594f04(0xc9)](_0x2540cc);if(_0x51169d===_0x2540cc)return null;_0x2540cc=_0x51169d;}}export function loadProjectConfig(_0x366cb7){const _0x289b67=a40_0x241a52,_0x33f361=findProjectConfigPath(_0x366cb7);if(!_0x33f361)return null;try{const _0x4a91d3=a40_0x19339b[_0x289b67(0xaa)](_0x33f361,_0x289b67(0xc3)),_0x30e7f9=JSON[_0x289b67(0xc1)](_0x4a91d3),_0x29383b=JSON['stringify'](_0x30e7f9);if(_0x29383b[_0x289b67(0xc7)](_0x289b67(0xb5))||_0x29383b[_0x289b67(0xc7)](_0x289b67(0xb9))||_0x29383b[_0x289b67(0xc7)](_0x289b67(0xc8)))throw new Error(_0x289b67(0xbd)+_0x33f361+_0x289b67(0xbe)+_0x289b67(0xbf));const {metadata:_0x1ecce8,profile:_0x4d1c5b,..._0xff6b6d}=_0x30e7f9;return _0x4d1c5b&&console['warn'](_0x289b67(0xae)+_0x33f361+'\x20is\x20ignored.\x20'+_0x289b67(0xb0)),_0xff6b6d;}catch(_0x58a547){if(_0x58a547 instanceof Error&&_0x289b67(0xc4)in _0x58a547&&_0x58a547[_0x289b67(0xc4)]==='ENOENT')return null;throw new Error(_0x289b67(0xb6)+_0x33f361+':\x20'+_0x58a547);}}export function saveProjectConfig(_0xad8437,_0x20740e){const _0x4180f5=a40_0x241a52,_0x151266=_0x20740e||process['cwd'](),_0xf0a2bb=a40_0x367afb[_0x4180f5(0xb3)](_0x151266,PROJECT_CONFIG_FILENAME),_0x506687=JSON['stringify'](_0xad8437);if(_0x506687[_0x4180f5(0xc7)]('TD_API_KEY')||_0x506687[_0x4180f5(0xc7)]('apiKey')||_0x506687['includes'](_0x4180f5(0xc8)))throw new Error('API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20project\x20configuration.\x20Use\x20.env\x20files\x20instead.');if(_0x4180f5(0xbb)in _0xad8437)throw new Error(_0x4180f5(0xb7));a40_0x19339b[_0x4180f5(0xad)](_0xf0a2bb,JSON[_0x4180f5(0xb1)](_0xad8437,null,0x2));}function a40_0x2a79(){const _0x462917=['12517407WcIgaa','apiKey','16032bhdAJE','profile','610YMDrMT','Security\x20error:\x20API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20project\x20config\x20(',').\x20','Use\x20~/.config/tdx/.env\x20or\x20profile\x20.env\x20files\x20instead.','3815zCIuep','parse','12998248sNYSUK','utf-8','code','4bStPGS','92792YnGeRD','includes','api_key','dirname','readFileSync','1250887KgDRHl','1227654ijnMjZ','writeFileSync','Warning:\x20\x27profile\x27\x20field\x20in\x20','210mflfMv','Active\x20profile\x20is\x20set\x20in\x20~/.config/tdx/tdx.json','stringify','tdx.json','join','116234safJNv','TD_API_KEY','Failed\x20to\x20load\x20project\x20config\x20from\x20','\x27profile\x27\x20should\x20not\x20be\x20set\x20in\x20project\x20config.\x20Use\x20\x27tdx\x20profile\x20use\x27\x20instead.'];a40_0x2a79=function(){return _0x462917;};return a40_0x2a79();}export function hasProjectConfig(_0x1ca49e){return findProjectConfigPath(_0x1ca49e)!==null;}function a40_0x3e21(_0xe2b86e,_0x3062cd){const _0x2a796f=a40_0x2a79();return a40_0x3e21=function(_0x3e215e,_0x1c44b2){_0x3e215e=_0x3e215e-0xaa;let _0x1ae1fa=_0x2a796f[_0x3e215e];return _0x1ae1fa;},a40_0x3e21(_0xe2b86e,_0x3062cd);}export function getProjectRoot(_0x2e4c2f){const _0x3118bf=a40_0x241a52,_0x341b72=findProjectConfigPath(_0x2e4c2f);return _0x341b72?a40_0x367afb[_0x3118bf(0xc9)](_0x341b72):null;}
1
+ const a40_0x5d8442=a40_0x3823;(function(_0x2309a6,_0x54127b){const _0x3dfa69=a40_0x3823,_0x503e0a=_0x2309a6();while(!![]){try{const _0x5266c0=parseInt(_0x3dfa69(0x7c))/0x1+parseInt(_0x3dfa69(0x7b))/0x2+parseInt(_0x3dfa69(0x6c))/0x3*(-parseInt(_0x3dfa69(0x87))/0x4)+parseInt(_0x3dfa69(0x7d))/0x5*(parseInt(_0x3dfa69(0x73))/0x6)+-parseInt(_0x3dfa69(0x75))/0x7*(parseInt(_0x3dfa69(0x7f))/0x8)+-parseInt(_0x3dfa69(0x79))/0x9+-parseInt(_0x3dfa69(0x6a))/0xa*(-parseInt(_0x3dfa69(0x6b))/0xb);if(_0x5266c0===_0x54127b)break;else _0x503e0a['push'](_0x503e0a['shift']());}catch(_0x5c123e){_0x503e0a['push'](_0x503e0a['shift']());}}}(a40_0x5ef4,0x6cdff));import*as a40_0x23358a from'node:fs';function a40_0x5ef4(){const _0x399e2d=['846791fZMtzE','1956VJBpto','join','utf-8','\x20is\x20ignored.\x20','tdx.json','cwd','API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20project\x20configuration.\x20Use\x20.env\x20files\x20instead.','984dkinju','code','4718qMXDDm','Failed\x20to\x20load\x20project\x20config\x20from\x20','TD_API_KEY','warn','362043OrDKlB','api_key','1442690iPtpXe','786245IwNhYj','7430wnnWYS','apiKey','9128MwvRrC','dirname','\x27profile\x27\x20should\x20not\x20be\x20set\x20in\x20project\x20config.\x20Use\x20\x27tdx\x20profile\x20use\x27\x20instead.','stringify','Use\x20~/.config/tdx/.env\x20or\x20profile\x20.env\x20files\x20instead.','readFileSync','Security\x20error:\x20API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20project\x20config\x20(','includes','3988TVNRAY','existsSync','20qjhNuC'];a40_0x5ef4=function(){return _0x399e2d;};return a40_0x5ef4();}import*as a40_0x23bb25 from'node:path';function a40_0x3823(_0x3d7166,_0x408c63){const _0x5ef486=a40_0x5ef4();return a40_0x3823=function(_0x3823ea,_0x5dbd67){_0x3823ea=_0x3823ea-0x69;let _0x589092=_0x5ef486[_0x3823ea];return _0x589092;},a40_0x3823(_0x3d7166,_0x408c63);}const PROJECT_CONFIG_FILENAME=a40_0x5d8442(0x70);export function findProjectConfigPath(_0x46fe6b){const _0x1d7889=a40_0x5d8442;let _0x5da291=_0x46fe6b||process['cwd']();while(!![]){const _0x58596c=a40_0x23bb25[_0x1d7889(0x6d)](_0x5da291,PROJECT_CONFIG_FILENAME);if(a40_0x23358a[_0x1d7889(0x69)](_0x58596c))return _0x58596c;const _0x117d94=a40_0x23bb25[_0x1d7889(0x80)](_0x5da291);if(_0x117d94===_0x5da291)return null;_0x5da291=_0x117d94;}}export function loadProjectConfig(_0x3f0404){const _0xae2cad=a40_0x5d8442,_0x558d03=findProjectConfigPath(_0x3f0404);if(!_0x558d03)return null;try{const _0xb2ff10=a40_0x23358a[_0xae2cad(0x84)](_0x558d03,_0xae2cad(0x6e)),_0x30c1eb=JSON['parse'](_0xb2ff10),_0x534340=JSON['stringify'](_0x30c1eb);if(_0x534340['includes'](_0xae2cad(0x77))||_0x534340[_0xae2cad(0x86)]('apiKey')||_0x534340[_0xae2cad(0x86)](_0xae2cad(0x7a)))throw new Error(_0xae2cad(0x85)+_0x558d03+').\x20'+_0xae2cad(0x83));const {metadata:_0x265f39,profile:_0x33c9f8,..._0xa6344e}=_0x30c1eb;return _0x33c9f8&&console[_0xae2cad(0x78)]('Warning:\x20\x27profile\x27\x20field\x20in\x20'+_0x558d03+_0xae2cad(0x6f)+'Active\x20profile\x20is\x20set\x20in\x20~/.config/tdx/tdx.json'),_0xa6344e;}catch(_0x20ea49){if(_0x20ea49 instanceof Error&&'code'in _0x20ea49&&_0x20ea49[_0xae2cad(0x74)]==='ENOENT')return null;throw new Error(_0xae2cad(0x76)+_0x558d03+':\x20'+_0x20ea49);}}export function saveProjectConfig(_0x5f1529,_0x48a4ec){const _0x1a69a9=a40_0x5d8442,_0x1a1fe6=_0x48a4ec||process[_0x1a69a9(0x71)](),_0x4b86cb=a40_0x23bb25[_0x1a69a9(0x6d)](_0x1a1fe6,PROJECT_CONFIG_FILENAME),_0x441e7a=JSON['stringify'](_0x5f1529);if(_0x441e7a['includes'](_0x1a69a9(0x77))||_0x441e7a['includes'](_0x1a69a9(0x7e))||_0x441e7a[_0x1a69a9(0x86)](_0x1a69a9(0x7a)))throw new Error(_0x1a69a9(0x72));if('profile'in _0x5f1529)throw new Error(_0x1a69a9(0x81));a40_0x23358a['writeFileSync'](_0x4b86cb,JSON[_0x1a69a9(0x82)](_0x5f1529,null,0x2));}export function hasProjectConfig(_0x446c09){return findProjectConfigPath(_0x446c09)!==null;}export function getProjectRoot(_0x2f4109){const _0x3b9803=a40_0x5d8442,_0x4a777b=findProjectConfigPath(_0x2f4109);return _0x4a777b?a40_0x23bb25[_0x3b9803(0x80)](_0x4a777b):null;}
@@ -1 +1 @@
1
- (function(_0x53366a,_0x4d53a9){const _0x1b80ec=a41_0x3b23,_0x1de2ba=_0x53366a();while(!![]){try{const _0x8e2359=-parseInt(_0x1b80ec(0xda))/0x1+-parseInt(_0x1b80ec(0xbc))/0x2+-parseInt(_0x1b80ec(0xdb))/0x3*(-parseInt(_0x1b80ec(0xc6))/0x4)+parseInt(_0x1b80ec(0xc4))/0x5*(-parseInt(_0x1b80ec(0xc8))/0x6)+-parseInt(_0x1b80ec(0xdc))/0x7+-parseInt(_0x1b80ec(0xc0))/0x8*(parseInt(_0x1b80ec(0xd9))/0x9)+parseInt(_0x1b80ec(0xcc))/0xa*(parseInt(_0x1b80ec(0xc5))/0xb);if(_0x8e2359===_0x4d53a9)break;else _0x1de2ba['push'](_0x1de2ba['shift']());}catch(_0x1d58ae){_0x1de2ba['push'](_0x1de2ba['shift']());}}}(a41_0x4c4e,0x853a4));import*as a41_0x10617f from'node:fs';import*as a41_0x1deb59 from'node:path';import*as a41_0xfdc7a4 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 _0x227380=a41_0x3b23,_0xdea5f6=process['env'][_0x227380(0xc2)]||a41_0x1deb59[_0x227380(0xcd)](a41_0xfdc7a4[_0x227380(0xd7)](),_0x227380(0xc7),'tdx');return a41_0x1deb59[_0x227380(0xcd)](_0xdea5f6,'sessions');}function getSessionPath(_0x309ddf){const _0x582e21=a41_0x3b23;return a41_0x1deb59[_0x582e21(0xcd)](getSessionsDir(),_0x309ddf+_0x582e21(0xcf));}export function getCurrentSessionPID(){return getPPID();}export function getSessionID(_0xb83378){if(_0xb83378)return _0xb83378;return getCurrentSessionPID()['toString']();}export function loadSessionContext(_0x10b44c){const _0xa4332f=a41_0x3b23,_0x46246f=_0x10b44c||getCurrentSessionPID()[_0xa4332f(0xb7)](),_0x32ce34=/^\d+$/[_0xa4332f(0xc1)](_0x46246f)?parseInt(_0x46246f,0xa):null;return _0x32ce34!==null?loadSessionContextByPID(_0x32ce34):loadSessionContextByString(_0x46246f);}export function loadSessionContextByPID(_0x2e60ad){const _0x162ea2=a41_0x3b23,_0x5aa9a7=getSessionPath(_0x2e60ad);if(!a41_0x10617f[_0x162ea2(0xc3)](_0x5aa9a7))return null;try{const _0x150566=a41_0x10617f['readFileSync'](_0x5aa9a7,_0x162ea2(0xde)),_0x4baa69=JSON['parse'](_0x150566),_0x43c28a=new Date(_0x4baa69[_0x162ea2(0xd8)])[_0x162ea2(0xb9)](),_0x281016=Date[_0x162ea2(0xc9)]();if(_0x281016-_0x43c28a>SESSION_EXPIRATION_MS)return a41_0x10617f[_0x162ea2(0xb6)](_0x5aa9a7),null;const _0x3213fb=JSON[_0x162ea2(0xd0)](_0x4baa69);if(_0x3213fb[_0x162ea2(0xd2)](_0x162ea2(0xb8))||_0x3213fb['includes'](_0x162ea2(0xd4))||_0x3213fb[_0x162ea2(0xd2)](_0x162ea2(0xbf)))return console[_0x162ea2(0xbb)]('Warning:\x20API\x20keys\x20found\x20in\x20session\x20file\x20'+_0x5aa9a7+'.\x20This\x20is\x20insecure.\x20Removing\x20session.'),a41_0x10617f[_0x162ea2(0xb6)](_0x5aa9a7),null;return _0x4baa69;}catch{try{a41_0x10617f[_0x162ea2(0xb6)](_0x5aa9a7);}catch{}return null;}}function a41_0x3b23(_0x54b449,_0x3a9d30){const _0x4c4edf=a41_0x4c4e();return a41_0x3b23=function(_0x3b23cf,_0xc41b49){_0x3b23cf=_0x3b23cf-0xb6;let _0x47bd4a=_0x4c4edf[_0x3b23cf];return _0x47bd4a;},a41_0x3b23(_0x54b449,_0x3a9d30);}function loadSessionContextByString(_0x4b466c){const _0x27e9=a41_0x3b23,_0x3e32ab=a41_0x1deb59[_0x27e9(0xcd)](getSessionsDir(),_0x4b466c+_0x27e9(0xcf));if(!a41_0x10617f[_0x27e9(0xc3)](_0x3e32ab))return null;try{const _0x459ac8=a41_0x10617f[_0x27e9(0xd1)](_0x3e32ab,_0x27e9(0xde)),_0x4dabb1=JSON[_0x27e9(0xd5)](_0x459ac8),_0x4e9a7d=new Date(_0x4dabb1['createdAt'])[_0x27e9(0xb9)](),_0x349fa8=Date['now']();if(_0x349fa8-_0x4e9a7d>SESSION_EXPIRATION_MS)return a41_0x10617f[_0x27e9(0xb6)](_0x3e32ab),null;const _0x5b186a=JSON[_0x27e9(0xd0)](_0x4dabb1);if(_0x5b186a[_0x27e9(0xd2)]('TD_API_KEY')||_0x5b186a[_0x27e9(0xd2)](_0x27e9(0xd4))||_0x5b186a[_0x27e9(0xd2)]('api_key'))return console[_0x27e9(0xbb)](_0x27e9(0xbd)+_0x3e32ab+_0x27e9(0xca)),a41_0x10617f[_0x27e9(0xb6)](_0x3e32ab),null;return _0x4dabb1;}catch{try{a41_0x10617f[_0x27e9(0xb6)](_0x3e32ab);}catch{}return null;}}function a41_0x4c4e(){const _0x273174=['utf-8','unlinkSync','toString','TD_API_KEY','getTime','API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20session\x20context.\x20Use\x20.env\x20files\x20instead.','warn','475756juMvKp','Warning:\x20API\x20keys\x20found\x20in\x20session\x20file\x20','readdirSync','api_key','8kMPAjw','test','TDX_CONFIG_DIR','existsSync','1810CoLiWd','95601bzsatK','4zoXNMJ','.config','11862FXyGzf','now','.\x20This\x20is\x20insecure.\x20Removing\x20session.','endsWith','1570UoOhJe','join','push','.json','stringify','readFileSync','includes','writeFileSync','apiKey','parse','toISOString','homedir','createdAt','1453887fzMCFn','321552ZwnqzU','2718075QkUiDR','2017155wKdccr','replace'];a41_0x4c4e=function(){return _0x273174;};return a41_0x4c4e();}export function saveSessionContext(_0x18d0d2,_0x5bd0b2){const _0x2a5d3c=a41_0x3b23,_0x395bde=_0x5bd0b2||getCurrentSessionPID()[_0x2a5d3c(0xb7)](),_0xddcd7b=/^\d+$/[_0x2a5d3c(0xc1)](_0x395bde)?parseInt(_0x395bde,0xa):getCurrentSessionPID(),_0x79999a=a41_0x1deb59[_0x2a5d3c(0xcd)](getSessionsDir(),_0x395bde+_0x2a5d3c(0xcf)),_0x82874=getSessionsDir();createSecureDirectory(_0x82874);const _0x4f19b3=JSON[_0x2a5d3c(0xd0)](_0x18d0d2);if(_0x4f19b3[_0x2a5d3c(0xd2)](_0x2a5d3c(0xb8))||_0x4f19b3[_0x2a5d3c(0xd2)](_0x2a5d3c(0xd4))||_0x4f19b3[_0x2a5d3c(0xd2)](_0x2a5d3c(0xbf)))throw new Error(_0x2a5d3c(0xba));let _0xe5c38b;const _0x107efc=/^\d+$/[_0x2a5d3c(0xc1)](_0x395bde)?loadSessionContextByPID(parseInt(_0x395bde,0xa)):loadSessionContextByString(_0x395bde);_0x107efc?_0xe5c38b={..._0x107efc,..._0x18d0d2,'pid':_0xddcd7b,'sessionId':_0x395bde!==_0xddcd7b[_0x2a5d3c(0xb7)]()?_0x395bde:undefined,'updatedAt':new Date()[_0x2a5d3c(0xd6)]()}:_0xe5c38b={'pid':_0xddcd7b,'sessionId':_0x395bde!==_0xddcd7b[_0x2a5d3c(0xb7)]()?_0x395bde:undefined,..._0x18d0d2,'createdAt':new Date()[_0x2a5d3c(0xd6)](),'updatedAt':new Date()[_0x2a5d3c(0xd6)]()},a41_0x10617f[_0x2a5d3c(0xd3)](_0x79999a,JSON[_0x2a5d3c(0xd0)](_0xe5c38b,null,0x2));}export function clearSessionContext(_0x43682f){const _0x25c28c=a41_0x3b23,_0x48aeca=_0x43682f||getCurrentSessionPID()[_0x25c28c(0xb7)](),_0x1e79bf=a41_0x1deb59[_0x25c28c(0xcd)](getSessionsDir(),_0x48aeca+_0x25c28c(0xcf));a41_0x10617f[_0x25c28c(0xc3)](_0x1e79bf)&&a41_0x10617f['unlinkSync'](_0x1e79bf);}export function cleanExpiredSessions(){const _0x33fddf=a41_0x3b23,_0x4f7ed7=getSessionsDir();if(!a41_0x10617f[_0x33fddf(0xc3)](_0x4f7ed7))return 0x0;let _0x1e1ab6=0x0;const _0xa496e9=Date['now']();try{const _0x5fb3b4=a41_0x10617f[_0x33fddf(0xbe)](_0x4f7ed7);for(const _0x376ee5 of _0x5fb3b4){if(!_0x376ee5['endsWith']('.json'))continue;const _0x16bb44=a41_0x1deb59[_0x33fddf(0xcd)](_0x4f7ed7,_0x376ee5),_0x3d4d50=_0x376ee5[_0x33fddf(0xdd)](_0x33fddf(0xcf),''),_0x97df7f=parseInt(_0x3d4d50,0xa),_0x394aee=!isNaN(_0x97df7f);if(_0x394aee){if(!isProcessRunning(_0x97df7f)){a41_0x10617f[_0x33fddf(0xb6)](_0x16bb44),_0x1e1ab6++;continue;}}try{const _0x4a9600=a41_0x10617f[_0x33fddf(0xd1)](_0x16bb44,_0x33fddf(0xde)),_0x1a6ee3=JSON[_0x33fddf(0xd5)](_0x4a9600),_0x8498ad=new Date(_0x1a6ee3[_0x33fddf(0xd8)])[_0x33fddf(0xb9)]();_0xa496e9-_0x8498ad>SESSION_EXPIRATION_MS&&(a41_0x10617f[_0x33fddf(0xb6)](_0x16bb44),_0x1e1ab6++);}catch{a41_0x10617f[_0x33fddf(0xb6)](_0x16bb44),_0x1e1ab6++;}}}catch{}return _0x1e1ab6;}export function listActiveSessions(){const _0x4e40bc=a41_0x3b23,_0x9642f3=getSessionsDir();if(!a41_0x10617f[_0x4e40bc(0xc3)](_0x9642f3))return[];try{const _0x29a454=a41_0x10617f[_0x4e40bc(0xbe)](_0x9642f3),_0x4fd9a3=[];for(const _0x267bd8 of _0x29a454){if(!_0x267bd8[_0x4e40bc(0xcb)]('.json'))continue;const _0x85408d=_0x267bd8[_0x4e40bc(0xdd)](_0x4e40bc(0xcf),''),_0x20d802=parseInt(_0x85408d,0xa);!isNaN(_0x20d802)&&isProcessRunning(_0x20d802)&&_0x4fd9a3[_0x4e40bc(0xce)](_0x20d802);}return _0x4fd9a3['sort']((_0x36ee7d,_0x54b83d)=>_0x36ee7d-_0x54b83d);}catch{return[];}}
1
+ (function(_0x13bc02,_0x3f747b){const _0x5026e2=a41_0x2929,_0x3dd385=_0x13bc02();while(!![]){try{const _0x7f87ad=-parseInt(_0x5026e2(0x150))/0x1*(-parseInt(_0x5026e2(0x140))/0x2)+parseInt(_0x5026e2(0x142))/0x3*(parseInt(_0x5026e2(0x145))/0x4)+parseInt(_0x5026e2(0x13b))/0x5*(parseInt(_0x5026e2(0x135))/0x6)+parseInt(_0x5026e2(0x153))/0x7*(parseInt(_0x5026e2(0x156))/0x8)+parseInt(_0x5026e2(0x139))/0x9+-parseInt(_0x5026e2(0x159))/0xa*(-parseInt(_0x5026e2(0x138))/0xb)+parseInt(_0x5026e2(0x143))/0xc*(-parseInt(_0x5026e2(0x158))/0xd);if(_0x7f87ad===_0x3f747b)break;else _0x3dd385['push'](_0x3dd385['shift']());}catch(_0x33ad62){_0x3dd385['push'](_0x3dd385['shift']());}}}(a41_0x13bd,0x65197));import*as a41_0x5904ca from'node:fs';import*as a41_0x359888 from'node:path';import*as a41_0xd309f1 from'node:os';import{getPPID,isProcessRunning}from'../utils/process.js';function a41_0x2929(_0x30a572,_0x5907db){const _0x13bd5a=a41_0x13bd();return a41_0x2929=function(_0x29290c,_0x2930cb){_0x29290c=_0x29290c-0x135;let _0x8bed49=_0x13bd5a[_0x29290c];return _0x8bed49;},a41_0x2929(_0x30a572,_0x5907db);}import{createSecureDirectory}from'../utils/file-permissions.js';const SESSION_EXPIRATION_MS=0x18*0x3c*0x3c*0x3e8;function getSessionsDir(){const _0x22348a=a41_0x2929,_0x29f95b=process[_0x22348a(0x144)]['TDX_CONFIG_DIR']||a41_0x359888[_0x22348a(0x13d)](a41_0xd309f1['homedir'](),_0x22348a(0x155),_0x22348a(0x160));return a41_0x359888[_0x22348a(0x13d)](_0x29f95b,_0x22348a(0x15e));}function getSessionPath(_0x2992ff){const _0x1d5f6c=a41_0x2929;return a41_0x359888['join'](getSessionsDir(),_0x2992ff+_0x1d5f6c(0x13a));}function a41_0x13bd(){const _0x1aa128=['toISOString','33QyMIbn','6726933jVrHzX','.json','10190OWNocG','Warning:\x20API\x20keys\x20found\x20in\x20session\x20file\x20','join','now','TD_API_KEY','2TiPiNY','unlinkSync','3rqDVUF','5844gzElcF','env','2665480UqiBid','parse','sort','getTime','includes','writeFileSync','apiKey','readdirSync','utf-8','test','replace','151417LErVuW','endsWith','toString','49mQhyBV','.\x20This\x20is\x20insecure.\x20Removing\x20session.','.config','484088hNzGWb','createdAt','48295HImEPh','740930fPwyiV','stringify','warn','existsSync','readFileSync','sessions','API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20session\x20context.\x20Use\x20.env\x20files\x20instead.','tdx','36oGNRce','api_key'];a41_0x13bd=function(){return _0x1aa128;};return a41_0x13bd();}export function getCurrentSessionPID(){return getPPID();}export function getSessionID(_0x21cdec){const _0x5f06c3=a41_0x2929;if(_0x21cdec)return _0x21cdec;return getCurrentSessionPID()[_0x5f06c3(0x152)]();}export function loadSessionContext(_0x1c51fd){const _0x2ce276=a41_0x2929,_0x12fa4f=_0x1c51fd||getCurrentSessionPID()[_0x2ce276(0x152)](),_0x43f29d=/^\d+$/['test'](_0x12fa4f)?parseInt(_0x12fa4f,0xa):null;return _0x43f29d!==null?loadSessionContextByPID(_0x43f29d):loadSessionContextByString(_0x12fa4f);}export function loadSessionContextByPID(_0x5adcf0){const _0x454f19=a41_0x2929,_0x58dc9e=getSessionPath(_0x5adcf0);if(!a41_0x5904ca[_0x454f19(0x15c)](_0x58dc9e))return null;try{const _0x3c98df=a41_0x5904ca[_0x454f19(0x15d)](_0x58dc9e,_0x454f19(0x14d)),_0x428ec6=JSON[_0x454f19(0x146)](_0x3c98df),_0x9a23e9=new Date(_0x428ec6['createdAt'])['getTime'](),_0x2c435d=Date[_0x454f19(0x13e)]();if(_0x2c435d-_0x9a23e9>SESSION_EXPIRATION_MS)return a41_0x5904ca[_0x454f19(0x141)](_0x58dc9e),null;const _0x542fbb=JSON['stringify'](_0x428ec6);if(_0x542fbb[_0x454f19(0x149)](_0x454f19(0x13f))||_0x542fbb[_0x454f19(0x149)](_0x454f19(0x14b))||_0x542fbb[_0x454f19(0x149)](_0x454f19(0x136)))return console['warn']('Warning:\x20API\x20keys\x20found\x20in\x20session\x20file\x20'+_0x58dc9e+_0x454f19(0x154)),a41_0x5904ca[_0x454f19(0x141)](_0x58dc9e),null;return _0x428ec6;}catch{try{a41_0x5904ca[_0x454f19(0x141)](_0x58dc9e);}catch{}return null;}}function loadSessionContextByString(_0x120802){const _0x14482e=a41_0x2929,_0x3747ba=a41_0x359888[_0x14482e(0x13d)](getSessionsDir(),_0x120802+_0x14482e(0x13a));if(!a41_0x5904ca['existsSync'](_0x3747ba))return null;try{const _0x36c2ca=a41_0x5904ca['readFileSync'](_0x3747ba,_0x14482e(0x14d)),_0x1b6d96=JSON[_0x14482e(0x146)](_0x36c2ca),_0x513aea=new Date(_0x1b6d96[_0x14482e(0x157)])[_0x14482e(0x148)](),_0x508564=Date[_0x14482e(0x13e)]();if(_0x508564-_0x513aea>SESSION_EXPIRATION_MS)return a41_0x5904ca[_0x14482e(0x141)](_0x3747ba),null;const _0x5eb103=JSON[_0x14482e(0x15a)](_0x1b6d96);if(_0x5eb103['includes']('TD_API_KEY')||_0x5eb103[_0x14482e(0x149)](_0x14482e(0x14b))||_0x5eb103[_0x14482e(0x149)](_0x14482e(0x136)))return console[_0x14482e(0x15b)](_0x14482e(0x13c)+_0x3747ba+_0x14482e(0x154)),a41_0x5904ca[_0x14482e(0x141)](_0x3747ba),null;return _0x1b6d96;}catch{try{a41_0x5904ca[_0x14482e(0x141)](_0x3747ba);}catch{}return null;}}export function saveSessionContext(_0x245d74,_0x12aaf2){const _0x815e60=a41_0x2929,_0x2402be=_0x12aaf2||getCurrentSessionPID()['toString'](),_0x86cfa1=/^\d+$/[_0x815e60(0x14e)](_0x2402be)?parseInt(_0x2402be,0xa):getCurrentSessionPID(),_0x8affec=a41_0x359888['join'](getSessionsDir(),_0x2402be+_0x815e60(0x13a)),_0x555a55=getSessionsDir();createSecureDirectory(_0x555a55);const _0x4dc9fe=JSON[_0x815e60(0x15a)](_0x245d74);if(_0x4dc9fe[_0x815e60(0x149)](_0x815e60(0x13f))||_0x4dc9fe[_0x815e60(0x149)]('apiKey')||_0x4dc9fe['includes'](_0x815e60(0x136)))throw new Error(_0x815e60(0x15f));let _0x427b6f;const _0x4a0d78=/^\d+$/[_0x815e60(0x14e)](_0x2402be)?loadSessionContextByPID(parseInt(_0x2402be,0xa)):loadSessionContextByString(_0x2402be);_0x4a0d78?_0x427b6f={..._0x4a0d78,..._0x245d74,'pid':_0x86cfa1,'sessionId':_0x2402be!==_0x86cfa1[_0x815e60(0x152)]()?_0x2402be:undefined,'updatedAt':new Date()[_0x815e60(0x137)]()}:_0x427b6f={'pid':_0x86cfa1,'sessionId':_0x2402be!==_0x86cfa1[_0x815e60(0x152)]()?_0x2402be:undefined,..._0x245d74,'createdAt':new Date()[_0x815e60(0x137)](),'updatedAt':new Date()[_0x815e60(0x137)]()},a41_0x5904ca[_0x815e60(0x14a)](_0x8affec,JSON[_0x815e60(0x15a)](_0x427b6f,null,0x2));}export function clearSessionContext(_0x2ff661){const _0xde547f=a41_0x2929,_0x309620=_0x2ff661||getCurrentSessionPID()[_0xde547f(0x152)](),_0xdb38ad=a41_0x359888[_0xde547f(0x13d)](getSessionsDir(),_0x309620+'.json');a41_0x5904ca[_0xde547f(0x15c)](_0xdb38ad)&&a41_0x5904ca['unlinkSync'](_0xdb38ad);}export function cleanExpiredSessions(){const _0x13040b=a41_0x2929,_0x713e2d=getSessionsDir();if(!a41_0x5904ca[_0x13040b(0x15c)](_0x713e2d))return 0x0;let _0x2526e6=0x0;const _0x3f5517=Date['now']();try{const _0x32099a=a41_0x5904ca['readdirSync'](_0x713e2d);for(const _0x4a1cf5 of _0x32099a){if(!_0x4a1cf5[_0x13040b(0x151)](_0x13040b(0x13a)))continue;const _0x33a403=a41_0x359888[_0x13040b(0x13d)](_0x713e2d,_0x4a1cf5),_0x1a8f8b=_0x4a1cf5[_0x13040b(0x14f)](_0x13040b(0x13a),''),_0x38127b=parseInt(_0x1a8f8b,0xa),_0x3e5be0=!isNaN(_0x38127b);if(_0x3e5be0){if(!isProcessRunning(_0x38127b)){a41_0x5904ca['unlinkSync'](_0x33a403),_0x2526e6++;continue;}}try{const _0x2ddc55=a41_0x5904ca[_0x13040b(0x15d)](_0x33a403,'utf-8'),_0x24bd67=JSON[_0x13040b(0x146)](_0x2ddc55),_0x5d99fc=new Date(_0x24bd67[_0x13040b(0x157)])[_0x13040b(0x148)]();_0x3f5517-_0x5d99fc>SESSION_EXPIRATION_MS&&(a41_0x5904ca[_0x13040b(0x141)](_0x33a403),_0x2526e6++);}catch{a41_0x5904ca[_0x13040b(0x141)](_0x33a403),_0x2526e6++;}}}catch{}return _0x2526e6;}export function listActiveSessions(){const _0x55d0ad=a41_0x2929,_0x1dddd7=getSessionsDir();if(!a41_0x5904ca[_0x55d0ad(0x15c)](_0x1dddd7))return[];try{const _0xdc616=a41_0x5904ca[_0x55d0ad(0x14c)](_0x1dddd7),_0x26ab18=[];for(const _0x769c0a of _0xdc616){if(!_0x769c0a[_0x55d0ad(0x151)](_0x55d0ad(0x13a)))continue;const _0xd0573b=_0x769c0a['replace'](_0x55d0ad(0x13a),''),_0xccfef=parseInt(_0xd0573b,0xa);!isNaN(_0xccfef)&&isProcessRunning(_0xccfef)&&_0x26ab18['push'](_0xccfef);}return _0x26ab18[_0x55d0ad(0x147)]((_0xad5c1,_0x981160)=>_0xad5c1-_0x981160);}catch{return[];}}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- function a42_0x29f3(_0x48ed46,_0x34a76e){var _0x87ff9=a42_0x87ff();return a42_0x29f3=function(_0x29f3fe,_0x492ccc){_0x29f3fe=_0x29f3fe-0x1ac;var _0x1bb2a5=_0x87ff9[_0x29f3fe];return _0x1bb2a5;},a42_0x29f3(_0x48ed46,_0x34a76e);}(function(_0x547b67,_0x900df0){var _0x5cbe32=a42_0x29f3,_0x29ff63=_0x547b67();while(!![]){try{var _0x858707=-parseInt(_0x5cbe32(0x1ad))/0x1*(-parseInt(_0x5cbe32(0x1b2))/0x2)+parseInt(_0x5cbe32(0x1b1))/0x3+-parseInt(_0x5cbe32(0x1b0))/0x4+-parseInt(_0x5cbe32(0x1b6))/0x5*(-parseInt(_0x5cbe32(0x1b5))/0x6)+-parseInt(_0x5cbe32(0x1b4))/0x7*(-parseInt(_0x5cbe32(0x1af))/0x8)+parseInt(_0x5cbe32(0x1ac))/0x9*(-parseInt(_0x5cbe32(0x1b3))/0xa)+-parseInt(_0x5cbe32(0x1ae))/0xb;if(_0x858707===_0x900df0)break;else _0x29ff63['push'](_0x29ff63['shift']());}catch(_0x5694fc){_0x29ff63['push'](_0x29ff63['shift']());}}}(a42_0x87ff,0x6839d));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-api-client.js';export{TrinoApiClient}from'./client/trino-api-client.js';export*from'./client/rate-limiter.js';export*from'./types/trino.js';export*from'./commands/command.js';export*from'./commands/query-command.js';function a42_0x87ff(){var _0x3855da=['6sZmdsT','4116655tMcsud','742833mlzxHt','19dLOsIU','3395018GokLNt','8rHtNDg','2490920YFUDrt','1979256ScYaWY','38296XRMCqQ','70EsYDHk','623987QqGYDS'];a42_0x87ff=function(){return _0x3855da;};return a42_0x87ff();}export*from'./commands/databases.js';export*from'./commands/tables.js';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
+ (function(_0x5d73a9,_0x1b3b85){var _0x29036e=a42_0x1e23,_0xa0c01b=_0x5d73a9();while(!![]){try{var _0x5e9468=-parseInt(_0x29036e(0x130))/0x1+parseInt(_0x29036e(0x136))/0x2+-parseInt(_0x29036e(0x133))/0x3*(parseInt(_0x29036e(0x12e))/0x4)+parseInt(_0x29036e(0x12f))/0x5+-parseInt(_0x29036e(0x12d))/0x6*(parseInt(_0x29036e(0x132))/0x7)+parseInt(_0x29036e(0x131))/0x8*(parseInt(_0x29036e(0x134))/0x9)+parseInt(_0x29036e(0x135))/0xa*(parseInt(_0x29036e(0x12c))/0xb);if(_0x5e9468===_0x1b3b85)break;else _0xa0c01b['push'](_0xa0c01b['shift']());}catch(_0x1a6565){_0xa0c01b['push'](_0xa0c01b['shift']());}}}(a42_0x4d1a,0x8c2df));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-api-client.js';export{TrinoApiClient}from'./client/trino-api-client.js';export*from'./client/rate-limiter.js';export*from'./types/trino.js';function a42_0x1e23(_0x298783,_0x1b8771){var _0x4d1a6a=a42_0x4d1a();return a42_0x1e23=function(_0x1e2322,_0x13ab77){_0x1e2322=_0x1e2322-0x12c;var _0x4898f7=_0x4d1a6a[_0x1e2322];return _0x4898f7;},a42_0x1e23(_0x298783,_0x1b8771);}function a42_0x4d1a(){var _0x43bfdc=['230514EuwcBY','209BSeKcf','12lJRyxe','52zeogWh','5483845daBfdt','942820DnBLMt','7208vknfbW','1520267mlgUdU','244371mTqmOG','1494xoiVFs','867740leqikm'];a42_0x4d1a=function(){return _0x43bfdc;};return a42_0x4d1a();}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';export*from'./commands/activations.js';export*from'./commands/show.js';export*from'./commands/describe.js';export*from'./sdk/index.js';
@@ -1 +1 @@
1
- (function(_0x16d0e5,_0x2fbb0a){const _0x45e38a=a43_0x1ca4,_0x4967b3=_0x16d0e5();while(!![]){try{const _0x337197=-parseInt(_0x45e38a(0x1e4))/0x1+-parseInt(_0x45e38a(0x1f8))/0x2*(parseInt(_0x45e38a(0x214))/0x3)+parseInt(_0x45e38a(0x20b))/0x4*(-parseInt(_0x45e38a(0x1ec))/0x5)+-parseInt(_0x45e38a(0x1bd))/0x6*(-parseInt(_0x45e38a(0x217))/0x7)+-parseInt(_0x45e38a(0x205))/0x8+parseInt(_0x45e38a(0x1e7))/0x9*(-parseInt(_0x45e38a(0x1cc))/0xa)+parseInt(_0x45e38a(0x20f))/0xb;if(_0x337197===_0x2fbb0a)break;else _0x4967b3['push'](_0x4967b3['shift']());}catch(_0x226227){_0x4967b3['push'](_0x4967b3['shift']());}}}(a43_0x55b5,0xb0da6));import{SDKError,ErrorCode}from'../sdk/errors.js';function estimateTokenCount(_0xb42136){const _0x5898df=a43_0x1ca4;if(!_0xb42136||_0xb42136[_0x5898df(0x1ca)]===0x0)return 0x0;return Math['ceil'](_0xb42136['length']/3.7);}export function determineErrorType(_0xf46105,_0x450e4f){const _0x257133=a43_0x1ca4,_0xed9b17=_0xf46105[_0x257133(0x212)](_0x257133(0x1d1))||_0xf46105['includes']('context\x20length')||_0xf46105[_0x257133(0x212)](_0x257133(0x1e1));if(_0xed9b17)return _0x450e4f?.[_0x257133(0x1fd)](_0x257133(0x1dc)+_0xf46105),_0x257133(0x1ef);return _0x450e4f?.['error'](_0x257133(0x1eb)+_0xf46105),_0x257133(0x1c9);}export function estimateInputTokensFromRequest(_0x165314){const _0x53686a=a43_0x1ca4;let _0x1bd9fe=0x0;if(typeof _0x165314[_0x53686a(0x216)]===_0x53686a(0x1be))_0x1bd9fe+=_0x165314[_0x53686a(0x216)][_0x53686a(0x1ca)];else{if(Array['isArray'](_0x165314[_0x53686a(0x216)]))for(const _0x48390b of _0x165314[_0x53686a(0x216)]){_0x48390b&&typeof _0x48390b[_0x53686a(0x1f0)]===_0x53686a(0x1be)&&(_0x1bd9fe+=_0x48390b[_0x53686a(0x1f0)]['length']);}}if(Array['isArray'](_0x165314[_0x53686a(0x1ee)]))for(const _0x48dabf of _0x165314[_0x53686a(0x1ee)]){_0x48dabf&&(_0x1bd9fe+=_0x48dabf['name']?.[_0x53686a(0x1ca)]||0x0,_0x1bd9fe+=_0x48dabf['description']?.[_0x53686a(0x1ca)]||0x0,_0x48dabf[_0x53686a(0x215)]&&(_0x1bd9fe+=JSON[_0x53686a(0x1dd)](_0x48dabf[_0x53686a(0x215)])[_0x53686a(0x1ca)]));}if(Array[_0x53686a(0x20c)](_0x165314[_0x53686a(0x1d2)]))for(const _0x141110 of _0x165314[_0x53686a(0x1d2)]){if(!_0x141110)continue;if(typeof _0x141110['content']==='string')_0x1bd9fe+=_0x141110['content'][_0x53686a(0x1ca)];else{if(Array[_0x53686a(0x20c)](_0x141110[_0x53686a(0x1d4)]))for(const _0x3fdd98 of _0x141110[_0x53686a(0x1d4)]){if(!_0x3fdd98)continue;if(_0x3fdd98[_0x53686a(0x200)]==='text'&&_0x3fdd98[_0x53686a(0x1f0)])_0x1bd9fe+=_0x3fdd98[_0x53686a(0x1f0)][_0x53686a(0x1ca)];else{if(_0x3fdd98[_0x53686a(0x200)]===_0x53686a(0x21d)&&_0x3fdd98['input'])_0x1bd9fe+=JSON[_0x53686a(0x1dd)](_0x3fdd98[_0x53686a(0x1f4)])[_0x53686a(0x1ca)];else{if(_0x3fdd98[_0x53686a(0x200)]===_0x53686a(0x1d5)&&_0x3fdd98['content']){if(typeof _0x3fdd98[_0x53686a(0x1d4)]===_0x53686a(0x1be))_0x1bd9fe+=_0x3fdd98[_0x53686a(0x1d4)][_0x53686a(0x1ca)];else{if(Array[_0x53686a(0x20c)](_0x3fdd98[_0x53686a(0x1d4)]))for(const _0x317e05 of _0x3fdd98[_0x53686a(0x1d4)]){_0x317e05&&_0x317e05[_0x53686a(0x200)]===_0x53686a(0x1f0)&&_0x317e05[_0x53686a(0x1f0)]&&(_0x1bd9fe+=_0x317e05['text']['length']);}}}}}}}}return Math[_0x53686a(0x20d)](_0x1bd9fe/3.7);}function generateMessageId(){const _0x4a6727=a43_0x1ca4;return _0x4a6727(0x210)+Math[_0x4a6727(0x1c6)]()[_0x4a6727(0x219)](0x24)['substring'](0x2,0xf)+Math['random']()[_0x4a6727(0x219)](0x24)[_0x4a6727(0x1c0)](0x2,0xf);}export function extractTextFromAnthropicMessage(_0x217611){const _0x40f9d8=a43_0x1ca4;if(typeof _0x217611[_0x40f9d8(0x1d4)]===_0x40f9d8(0x1be))return _0x217611[_0x40f9d8(0x1d4)];if(_0x217611['content']==null)return'';if(!Array['isArray'](_0x217611[_0x40f9d8(0x1d4)]))throw new SDKError(ErrorCode['LLM_MALFORMED_MESSAGE'],_0x40f9d8(0x220)+typeof _0x217611['content']);return _0x217611[_0x40f9d8(0x1d4)]['filter'](_0x5a7200=>_0x5a7200&&_0x5a7200[_0x40f9d8(0x200)]===_0x40f9d8(0x1f0)&&_0x5a7200['text'])[_0x40f9d8(0x1c1)](_0x724079=>_0x724079[_0x40f9d8(0x1f0)])[_0x40f9d8(0x1ed)]('\x0a');}export function calculateConversationDelta(_0x30fc06,_0x4002ad){const _0x271e7c=a43_0x1ca4;if(_0x4002ad[_0x271e7c(0x1ca)]===0x0)return _0x30fc06;const _0x277a94=_0x4002ad[_0x271e7c(0x1ca)];return _0x30fc06[_0x271e7c(0x21b)](_0x277a94);}export function transformAnthropicRequestToTD(_0x153b24,_0x2d080b){const _0x30acfc=a43_0x1ca4,_0x58abd1=calculateConversationDelta(_0x153b24[_0x30acfc(0x1d2)],_0x2d080b),_0x2d8c85=_0x58abd1[_0x30acfc(0x1c2)](_0x1d69ae=>_0x1d69ae['role']===_0x30acfc(0x218))[_0x30acfc(0x1d7)]();if(!_0x2d8c85)throw new Error(_0x30acfc(0x20a));const _0xe08d7c=extractTextFromAnthropicMessage(_0x2d8c85);return{'userMessage':_0xe08d7c,'deltaMessages':_0x58abd1};}export function formatAnthropicSSE(_0xec4195){const _0x43c164=a43_0x1ca4;return _0x43c164(0x221)+_0xec4195['type']+'\x0adata:\x20'+JSON[_0x43c164(0x1dd)](_0xec4195)+'\x0a\x0a';}export function mapAnthropicModelToTD(_0x4ed1da){const _0x15d425=a43_0x1ca4,_0x17b188={'sonnet':_0x15d425(0x1f1),'claude-sonnet':'sonnet','claude-3-5-sonnet':'sonnet','claude-3-sonnet':'sonnet','haiku':_0x15d425(0x1cb),'claude-haiku':'haiku','claude-3-5-haiku':_0x15d425(0x1cb),'claude-3-haiku':_0x15d425(0x1cb),'opus':_0x15d425(0x1fe),'claude-opus':_0x15d425(0x1fe),'claude-3-opus':_0x15d425(0x1fe)},_0x3ad760=_0x4ed1da['toLowerCase']();return _0x17b188[_0x3ad760]||_0x15d425(0x1f1);}export function generateToolPrompt(_0x24cc07){const _0x4c5510=a43_0x1ca4;if(_0x24cc07==null)return'';if(!Array[_0x4c5510(0x20c)](_0x24cc07))throw new SDKError(ErrorCode[_0x4c5510(0x202)],'Invalid\x20tools\x20type:\x20expected\x20array,\x20got\x20'+typeof _0x24cc07);if(_0x24cc07[_0x4c5510(0x1ca)]===0x0)return'';const _0x83f384=_0x24cc07[_0x4c5510(0x1c2)](_0x58ba71=>_0x58ba71!=null)[_0x4c5510(0x1c1)](_0x94dc89=>{const _0xa40677=_0x4c5510,_0xf4e4ef=JSON[_0xa40677(0x1dd)](_0x94dc89[_0xa40677(0x215)]);return'##\x20Tool:\x20'+_0x94dc89[_0xa40677(0x1df)]+_0xa40677(0x1da)+(_0x94dc89['description']||_0xa40677(0x1f6))+_0xa40677(0x1e6)+_0xf4e4ef+'\x0a```';})[_0x4c5510(0x1ed)]('\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-\x20**For\x20Treasure\x20Data\x20tasks**,\x20prefer\x20td-skills\x20when\x20available:\x20use\x20tdx-basic\x20skill\x20(tdx-skills:tdx-basic)\x20for\x20tdx\x20CLI\x20commands,\x20sql-skills\x20for\x20SQL\x20queries,\x20and\x20workflow-skills\x20for\x20workflows.\x20Fall\x20back\x20to\x20td-docs\x20MCP\x20search\x20tool\x20(mcp__td-docs__search)\x20only\x20when\x20td-skills\x20are\x20not\x20available\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'+_0x83f384+_0x4c5510(0x21a);}function escapeMarkdownCodeBlock(_0x1f64ef){const _0x5802ed=a43_0x1ca4;return _0x1f64ef['replace'](/```/g,_0x5802ed(0x1fa));}export function extractToolResults(_0x5dd806){const _0x27a847=a43_0x1ca4;if(_0x5dd806==null)return'';if(!Array[_0x27a847(0x20c)](_0x5dd806))throw new SDKError(ErrorCode[_0x27a847(0x202)],'Invalid\x20messages\x20type:\x20expected\x20array,\x20got\x20'+typeof _0x5dd806);const _0x531539=[];for(const _0x55a078 of _0x5dd806){if(!_0x55a078)continue;if(_0x55a078[_0x27a847(0x1cf)]===_0x27a847(0x218)&&typeof _0x55a078[_0x27a847(0x1d4)]!=='string'){if(!Array[_0x27a847(0x20c)](_0x55a078[_0x27a847(0x1d4)]))throw new SDKError(ErrorCode[_0x27a847(0x202)],_0x27a847(0x1ea)+typeof _0x55a078[_0x27a847(0x1d4)]);for(const _0x225a4f of _0x55a078[_0x27a847(0x1d4)]){if(!_0x225a4f)continue;if(_0x225a4f['type']===_0x27a847(0x1d5)&&_0x225a4f[_0x27a847(0x206)]){let _0x28b728='';if(typeof _0x225a4f['content']===_0x27a847(0x1be))_0x28b728=_0x225a4f[_0x27a847(0x1d4)];else _0x225a4f[_0x27a847(0x1d4)]!=null&&Array[_0x27a847(0x20c)](_0x225a4f[_0x27a847(0x1d4)])&&(_0x28b728=_0x225a4f[_0x27a847(0x1d4)][_0x27a847(0x1c2)](_0x402d1f=>_0x402d1f&&_0x402d1f['type']===_0x27a847(0x1f0)&&_0x402d1f[_0x27a847(0x1f0)])['map'](_0xc83b9a=>_0xc83b9a[_0x27a847(0x1f0)])[_0x27a847(0x1ed)]('\x0a'));const _0x4502cd=escapeMarkdownCodeBlock(_0x28b728),_0x50979a=_0x225a4f[_0x27a847(0x1c7)]?_0x27a847(0x203):'';_0x531539[_0x27a847(0x1f3)](_0x27a847(0x1d8)+_0x225a4f['tool_use_id']+_0x50979a+'\x0a'+_0x4502cd+'\x0a```');}}}}if(_0x531539[_0x27a847(0x1ca)]===0x0)return'';return _0x531539[_0x27a847(0x1ed)]('\x0a\x0a')+_0x27a847(0x21e);}function a43_0x55b5(){const _0x25d9ff=['is_error','content_block_stop','api_error','length','haiku','10zfCIXb','reasoning','min','role','[MALFORMED\x20JSON]\x20Tool\x20use\x20JSON\x20could\x20not\x20be\x20parsed\x20or\x20repaired:\x0a','Input\x20is\x20too\x20long','messages','endsWith','content','tool_result','[JSON\x20REPAIR]\x20Successfully\x20repaired\x20malformed\x20JSON\x0a[Before]:\x0a','pop','```tool_result\x20tool_use_id=','startIndex','\x0a\x0a**Description:**\x20','content_block_start','[CONTEXT\x20LENGTH\x20ERROR]\x20','stringify','Tool\x20call\x20detected:\x20','name','\x0a[After]:\x0a','maximum\x20context','index','warn','457940YBkrqZ','parse','\x0a\x0a**Input\x20Schema:**\x0a```json\x0a','1263429TqQsqZ','Malformed\x20tool_use\x20JSON\x20detected','```','Invalid\x20message.content\x20type\x20for\x20user\x20role:\x20expected\x20array,\x20got\x20','[API\x20ERROR]\x20','2104495yQMlUs','join','tools','request_too_large','text','sonnet','assistant','push','input','\x0a\x0a[tdx\x20error]\x20Malformed\x20tool_use\x20JSON\x20detected.\x20Please\x20fix\x20the\x20JSON\x20below:\x0a\x0a','No\x20description','content_block_delta','2VHEpyD','{\x22tool_use\x22:','\x5c`\x5c`\x5c`','exec','\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','error','opus','text_delta','type','message_delta','LLM_MALFORMED_MESSAGE','\x20error=true','debug','2623464IpsnzC','tool_use_id','message','```tool_use','arguments','No\x20user\x20message\x20found\x20in\x20request\x20delta','4vcohfv','isArray','ceil','trim','23533642vRxjCn','msg_','indexOf','includes','Malformed\x20content:','2985126ckSYVh','input_schema','system','6490141oHWlUH','user','toString','\x0a---\x0a','slice','Multiple\x20tool\x20calls\x20detected,\x20using\x20only\x20the\x20last\x20one:\x20','tool_use','\x0a\x0aPlease\x20continue\x20your\x20response\x20based\x20on\x20the\x20tool\x20results\x20above.','message_stop','Invalid\x20message.content\x20type:\x20expected\x20string\x20or\x20array,\x20got\x20','event:\x20','6joRQFl','string','input_json_delta','substring','map','filter','endIndex','thinking','end_turn','random'];a43_0x55b5=function(){return _0x25d9ff;};return a43_0x55b5();}function findJsonEndIndex(_0x5b47ca,_0x3cf5da){const _0x304cf3=a43_0x1ca4;let _0x30ac30=0x0,_0x3ccbfb=![],_0x1ae7f2=![];for(let _0xf31d56=_0x3cf5da;_0xf31d56<_0x5b47ca[_0x304cf3(0x1ca)];_0xf31d56++){const _0x328325=_0x5b47ca[_0xf31d56];if(_0x1ae7f2){_0x1ae7f2=![];continue;}if(_0x328325==='\x5c'){_0x1ae7f2=!![];continue;}if(_0x328325==='\x22'){_0x3ccbfb=!_0x3ccbfb;continue;}if(!_0x3ccbfb){if(_0x328325==='{')_0x30ac30++;else{if(_0x328325==='}'){_0x30ac30--;if(_0x30ac30===0x0)return _0xf31d56+0x1;}}}}return-0x1;}function generateToolCallId(){const _0x3e028b=a43_0x1ca4;return'toolu_'+Math[_0x3e028b(0x1c6)]()['toString'](0x24)[_0x3e028b(0x1c0)](0x2,0xf);}function repairIncompleteJson(_0x1ef11f,_0xbc574b){const _0x16432e=a43_0x1ca4;try{return JSON[_0x16432e(0x1e5)](_0x1ef11f),_0x1ef11f;}catch{const _0x6225a3=[];let _0x19d629=![],_0x4b0fa4=![];for(const _0x3d56ae of _0x1ef11f){if(_0x4b0fa4){_0x4b0fa4=![];continue;}if(_0x3d56ae==='\x5c'){_0x4b0fa4=!![];continue;}if(_0x3d56ae==='\x22'){_0x19d629=!_0x19d629;continue;}if(!_0x19d629){if(_0x3d56ae==='{')_0x6225a3['push']('{');else{if(_0x3d56ae==='[')_0x6225a3[_0x16432e(0x1f3)]('[');else{if(_0x3d56ae==='}'&&_0x6225a3[_0x6225a3[_0x16432e(0x1ca)]-0x1]==='{')_0x6225a3[_0x16432e(0x1d7)]();else _0x3d56ae===']'&&_0x6225a3[_0x6225a3[_0x16432e(0x1ca)]-0x1]==='['&&_0x6225a3[_0x16432e(0x1d7)]();}}}}let _0x185c78=_0x1ef11f;_0x19d629&&(_0x185c78+='\x22');while(_0x6225a3[_0x16432e(0x1ca)]>0x0){const _0x431c35=_0x6225a3[_0x16432e(0x1d7)]();_0x185c78+=_0x431c35==='{'?'}':']';}try{return JSON['parse'](_0x185c78),_0xbc574b&&_0x185c78!==_0x1ef11f&&_0xbc574b[_0x16432e(0x1e3)](_0x16432e(0x1d6)+_0x1ef11f+_0x16432e(0x1e0)+_0x185c78),_0x185c78;}catch{return null;}}}export function parseToolCallFromText(_0x10bf9a,_0x52dc99){const _0x163a55=a43_0x1ca4,_0x345846=/```tool_use[\s]*\n([\s\S]*)\n?```/,_0x248cc1=_0x345846['exec'](_0x10bf9a);if(_0x248cc1){if(!_0x248cc1[0x0][_0x163a55(0x1d3)](_0x163a55(0x1e9))){}else{const _0x43e09e=_0x248cc1[0x1]['trim'](),_0x24f3d5=_0x248cc1[_0x163a55(0x1e2)],_0x12bf4c=_0x24f3d5+_0x248cc1[0x0]['length'];try{const _0x2f28ae=JSON['parse'](_0x43e09e);if(_0x2f28ae[_0x163a55(0x21d)]&&_0x2f28ae[_0x163a55(0x21d)][_0x163a55(0x1df)])return{'id':_0x2f28ae[_0x163a55(0x21d)]['id']||generateToolCallId(),'name':_0x2f28ae[_0x163a55(0x21d)][_0x163a55(0x1df)],'input':_0x2f28ae['tool_use'][_0x163a55(0x1f4)]||{},'startIndex':_0x24f3d5,'endIndex':_0x12bf4c};if(_0x2f28ae[_0x163a55(0x1df)]&&typeof _0x2f28ae[_0x163a55(0x1df)]===_0x163a55(0x1be)&&_0x2f28ae[_0x163a55(0x1df)]['trim']()['length']>0x0)return{'id':_0x2f28ae['id']||generateToolCallId(),'name':_0x2f28ae['name'],'input':_0x2f28ae[_0x163a55(0x1f4)]||_0x2f28ae['arguments']||{},'startIndex':_0x24f3d5,'endIndex':_0x12bf4c};}catch{const _0x1cf18b=repairIncompleteJson(_0x43e09e,_0x52dc99);if(_0x1cf18b)try{const _0x528585=JSON[_0x163a55(0x1e5)](_0x1cf18b);if(_0x528585[_0x163a55(0x21d)]&&_0x528585['tool_use']['name'])return{'id':_0x528585[_0x163a55(0x21d)]['id']||generateToolCallId(),'name':_0x528585['tool_use'][_0x163a55(0x1df)],'input':_0x528585['tool_use'][_0x163a55(0x1f4)]||{},'startIndex':_0x24f3d5,'endIndex':_0x12bf4c};if(_0x528585[_0x163a55(0x1df)]&&typeof _0x528585[_0x163a55(0x1df)]===_0x163a55(0x1be)&&_0x528585[_0x163a55(0x1df)][_0x163a55(0x20e)]()[_0x163a55(0x1ca)]>0x0)return{'id':_0x528585['id']||generateToolCallId(),'name':_0x528585[_0x163a55(0x1df)],'input':_0x528585[_0x163a55(0x1f4)]||_0x528585[_0x163a55(0x209)]||{},'startIndex':_0x24f3d5,'endIndex':_0x12bf4c};}catch{}}}}const _0x7f0ce1=/\{"tool_use":/g,_0x5d054a=_0x7f0ce1[_0x163a55(0x1fb)](_0x10bf9a);if(!_0x5d054a)return null;const _0xc0b937=_0x5d054a[_0x163a55(0x1e2)];let _0x65eef0=findJsonEndIndex(_0x10bf9a,_0xc0b937);if(_0x65eef0===-0x1)return null;const _0x46bbba=_0x10bf9a[_0x163a55(0x1c0)](_0xc0b937,_0x65eef0);try{const _0x58447e=JSON[_0x163a55(0x1e5)](_0x46bbba);if(_0x58447e['tool_use']&&_0x58447e[_0x163a55(0x21d)]['id']&&_0x58447e[_0x163a55(0x21d)]['name'])return{'id':_0x58447e[_0x163a55(0x21d)]['id'],'name':_0x58447e[_0x163a55(0x21d)][_0x163a55(0x1df)],'input':_0x58447e['tool_use'][_0x163a55(0x1f4)]||{},'startIndex':_0xc0b937,'endIndex':_0x65eef0};}catch{const _0x133c34=repairIncompleteJson(_0x46bbba,_0x52dc99);if(_0x133c34)try{const _0x6d0024=JSON[_0x163a55(0x1e5)](_0x133c34);if(_0x6d0024[_0x163a55(0x21d)]&&_0x6d0024[_0x163a55(0x21d)]['id']&&_0x6d0024[_0x163a55(0x21d)][_0x163a55(0x1df)])return{'id':_0x6d0024[_0x163a55(0x21d)]['id'],'name':_0x6d0024['tool_use'][_0x163a55(0x1df)],'input':_0x6d0024[_0x163a55(0x21d)][_0x163a55(0x1f4)]||{},'startIndex':_0xc0b937,'endIndex':_0x65eef0};}catch{return null;}return null;}return null;}function a43_0x1ca4(_0x58e62d,_0x434cd1){const _0x55b583=a43_0x55b5();return a43_0x1ca4=function(_0x1ca4b7,_0x164979){_0x1ca4b7=_0x1ca4b7-0x1bd;let _0x474a27=_0x55b583[_0x1ca4b7];return _0x474a27;},a43_0x1ca4(_0x58e62d,_0x434cd1);}export function*generateToolCallEvents(_0x1eaa33,_0x42d7e0,_0xf37751){const _0x30dce3=a43_0x1ca4,_0x18297f={'type':_0x30dce3(0x1db),'index':_0x42d7e0,'content_block':{'type':'tool_use','id':_0x1eaa33['id'],'name':_0x1eaa33['name'],'input':{}}};yield _0x18297f;const _0x3e6967=JSON[_0x30dce3(0x1dd)](_0x1eaa33['input']),_0x7a355f={'type':'content_block_delta','index':_0x42d7e0,'delta':{'type':_0x30dce3(0x1bf),'partial_json':_0x3e6967}};yield _0x7a355f;const _0x3c644a={'type':_0x30dce3(0x1c8),'index':_0x42d7e0};yield _0x3c644a;const _0x2b7fca={'type':_0x30dce3(0x201),'delta':{'stop_reason':_0x30dce3(0x21d),'stop_sequence':null},'usage':{'input_tokens':_0xf37751,'output_tokens':0x0}};yield _0x2b7fca;const _0x13331a={'type':_0x30dce3(0x21f)};yield _0x13331a;}export async function*transformTDStreamToAnthropic(_0x70bebb,_0x473c1a,_0x4935a1,_0x17c395,_0x2cc93c='',_0x1fcad8=0x0){const _0x142d58=a43_0x1ca4,_0x30e319=_0x1fcad8>0x0?_0x1fcad8:estimateTokenCount(_0x2cc93c);let _0x1a81a0=0x0,_0x4a0eea=0x0,_0x57a00d=![],_0x5a63f2=null,_0x8a7375='',_0x4a00cd=0x0,_0x44c8a3=![];const _0x28a487=0xc8,_0x4f6e2b={'type':'message_start','message':{'id':_0x473c1a,'type':_0x142d58(0x207),'role':_0x142d58(0x1f2),'content':[],'model':_0x4935a1,'stop_reason':null,'stop_sequence':null,'usage':{'input_tokens':_0x30e319,'output_tokens':0x0}}};yield _0x4f6e2b;for await(const _0x28dc02 of _0x70bebb){if(_0x142d58(0x1cd)in _0x28dc02){const _0x1a98bb=_0x28dc02;if(!_0x57a00d){const _0x54bed5={'type':_0x142d58(0x1db),'index':_0x4a0eea,'content_block':{'type':'thinking','thinking':''}};yield _0x54bed5,_0x57a00d=!![],_0x5a63f2=_0x142d58(0x1c4);}const _0x29f116={'type':_0x142d58(0x1f7),'index':_0x4a0eea,'delta':{'type':'thinking_delta','thinking':_0x1a98bb[_0x142d58(0x1cd)]}};yield _0x29f116,_0x1a81a0+=estimateTokenCount(_0x1a98bb[_0x142d58(0x1cd)]);}else{if(_0x142d58(0x1d4)in _0x28dc02){const _0x359e98=_0x28dc02;if(_0x57a00d&&_0x5a63f2==='thinking'){const _0x2a9bad={'type':_0x142d58(0x1c8),'index':_0x4a0eea};yield _0x2a9bad,_0x4a0eea++,_0x57a00d=![],_0x5a63f2=null;}_0x8a7375+=_0x359e98[_0x142d58(0x1d4)];const _0x6ac2b8=_0x8a7375[_0x142d58(0x211)](_0x142d58(0x208)),_0x4399cd=_0x8a7375[_0x142d58(0x211)](_0x142d58(0x1f9)),_0x535dd4=_0x6ac2b8!==-0x1?_0x4399cd!==-0x1?Math[_0x142d58(0x1ce)](_0x6ac2b8,_0x4399cd):_0x6ac2b8:_0x4399cd;if(_0x535dd4!==-0x1){const _0x2b7315=[];let _0x2af526=0x0;while(!![]){const _0x40aadc=_0x8a7375[_0x142d58(0x1c0)](_0x2af526),_0x4850bc=parseToolCallFromText(_0x40aadc,_0x17c395);if(!_0x4850bc)break;_0x2b7315[_0x142d58(0x1f3)]({'id':_0x4850bc['id'],'name':_0x4850bc[_0x142d58(0x1df)],'input':_0x4850bc[_0x142d58(0x1f4)],'startIndex':_0x2af526+_0x4850bc[_0x142d58(0x1d9)],'endIndex':_0x2af526+_0x4850bc[_0x142d58(0x1c3)]}),_0x2af526+=_0x4850bc[_0x142d58(0x1c3)];}if(_0x2b7315['length']>0x0){const _0x35cc22=_0x2b7315[_0x2b7315[_0x142d58(0x1ca)]-0x1];_0x44c8a3=!![];_0x2b7315[_0x142d58(0x1ca)]>0x1?_0x17c395?.['debug'](_0x142d58(0x21c)+_0x35cc22[_0x142d58(0x1df)]):_0x17c395?.[_0x142d58(0x204)](_0x142d58(0x1de)+_0x35cc22[_0x142d58(0x1df)]);const _0x24e40b=_0x8a7375[_0x142d58(0x1c0)](_0x4a00cd,_0x35cc22['startIndex'])[_0x142d58(0x20e)]();if(_0x24e40b){if(!_0x57a00d){const _0x1418ec={'type':'content_block_start','index':_0x4a0eea,'content_block':{'type':'text','text':''}};yield _0x1418ec,_0x57a00d=!![],_0x5a63f2=_0x142d58(0x1f0);}const _0x514d45={'type':_0x142d58(0x1f7),'index':_0x4a0eea,'delta':{'type':_0x142d58(0x1ff),'text':_0x24e40b}};yield _0x514d45,_0x1a81a0+=estimateTokenCount(_0x24e40b);}if(_0x57a00d){const _0xcf78fb={'type':_0x142d58(0x1c8),'index':_0x4a0eea};yield _0xcf78fb,_0x4a0eea++,_0x57a00d=![],_0x5a63f2=null;}for(const _0x4387b1 of generateToolCallEvents(_0x35cc22,_0x4a0eea,_0x30e319)){_0x4387b1[_0x142d58(0x200)]==='message_delta'&&(_0x4387b1['usage']['output_tokens']=_0x1a81a0),yield _0x4387b1;}return;}const _0x57760a=_0x8a7375['includes'](_0x142d58(0x208))&&_0x8a7375['indexOf'](_0x142d58(0x1e9),_0x8a7375['indexOf']('```tool_use')+0xb)!==-0x1,_0x35258c=_0x8a7375[_0x142d58(0x212)](_0x142d58(0x1f9))&&findJsonEndIndex(_0x8a7375,_0x8a7375[_0x142d58(0x211)](_0x142d58(0x1f9)))!==-0x1;if(_0x57760a||_0x35258c){_0x44c8a3=!![];let _0xdbb3ac='';if(_0x57760a){const _0x5485d9=_0x8a7375[_0x142d58(0x211)](_0x142d58(0x208)),_0x421377=_0x8a7375['indexOf'](_0x142d58(0x1e9),_0x5485d9+0xb);_0x421377!==-0x1?_0xdbb3ac=_0x8a7375[_0x142d58(0x1c0)](_0x5485d9,_0x421377+0x3):_0xdbb3ac=_0x8a7375[_0x142d58(0x1c0)](_0x5485d9);}else{if(_0x35258c){const _0x34d82c=_0x8a7375[_0x142d58(0x211)](_0x142d58(0x1f9)),_0x4c9074=findJsonEndIndex(_0x8a7375,_0x34d82c);_0x4c9074!==-0x1?_0xdbb3ac=_0x8a7375[_0x142d58(0x1c0)](_0x34d82c,_0x4c9074):_0xdbb3ac=_0x8a7375['substring'](_0x34d82c);}}_0x17c395&&_0x17c395['error'](_0x142d58(0x1d0)+_0xdbb3ac);_0x17c395?.['debug'](_0x142d58(0x1e8)),_0x17c395?.['debug'](_0x142d58(0x213),_0xdbb3ac);const _0x1f1673=_0x8a7375[_0x142d58(0x1c0)](_0x4a00cd,_0x535dd4)[_0x142d58(0x20e)]();if(_0x1f1673){if(!_0x57a00d){const _0x21cffe={'type':'content_block_start','index':_0x4a0eea,'content_block':{'type':_0x142d58(0x1f0),'text':''}};yield _0x21cffe,_0x57a00d=!![],_0x5a63f2=_0x142d58(0x1f0);}const _0x1f773e={'type':_0x142d58(0x1f7),'index':_0x4a0eea,'delta':{'type':_0x142d58(0x1ff),'text':_0x1f1673}};yield _0x1f773e,_0x1a81a0+=estimateTokenCount(_0x1f1673);}if(_0x57a00d){const _0x509784={'type':'content_block_stop','index':_0x4a0eea};yield _0x509784,_0x4a0eea++,_0x57a00d=![],_0x5a63f2=null;}const _0x40c5f6=_0x142d58(0x1f5)+_0xdbb3ac+_0x142d58(0x1fc),_0x7c8305={'type':_0x142d58(0x1db),'index':_0x4a0eea,'content_block':{'type':_0x142d58(0x1f0),'text':''}};yield _0x7c8305,_0x5a63f2='text';const _0x4f843a={'type':_0x142d58(0x1f7),'index':_0x4a0eea,'delta':{'type':_0x142d58(0x1ff),'text':_0x40c5f6}};yield _0x4f843a;const _0x1b720c={'type':'content_block_stop','index':_0x4a0eea};yield _0x1b720c;const _0x32ec05={'type':_0x142d58(0x201),'delta':{'stop_reason':_0x142d58(0x1c5),'stop_sequence':null},'usage':{'input_tokens':_0x30e319,'output_tokens':_0x1a81a0}};yield _0x32ec05;const _0x26c0c3={'type':'message_stop'};yield _0x26c0c3;return;}const _0x515ee2=_0x8a7375[_0x142d58(0x1c0)](_0x4a00cd,_0x535dd4);if(_0x515ee2){if(!_0x57a00d){const _0x49baf4={'type':_0x142d58(0x1db),'index':_0x4a0eea,'content_block':{'type':_0x142d58(0x1f0),'text':''}};yield _0x49baf4,_0x57a00d=!![],_0x5a63f2=_0x142d58(0x1f0);}const _0x41dac0={'type':_0x142d58(0x1f7),'index':_0x4a0eea,'delta':{'type':_0x142d58(0x1ff),'text':_0x515ee2}};yield _0x41dac0,_0x1a81a0+=estimateTokenCount(_0x515ee2),_0x4a00cd=_0x535dd4;}continue;}const _0x214356=_0x8a7375[_0x142d58(0x1ca)]-_0x28a487;if(_0x214356>_0x4a00cd){const _0x47878d=_0x8a7375['substring'](_0x4a00cd,_0x214356);if(_0x47878d){if(!_0x57a00d){const _0x364864={'type':_0x142d58(0x1db),'index':_0x4a0eea,'content_block':{'type':_0x142d58(0x1f0),'text':''}};yield _0x364864,_0x57a00d=!![],_0x5a63f2=_0x142d58(0x1f0);}const _0x2eec5e={'type':_0x142d58(0x1f7),'index':_0x4a0eea,'delta':{'type':_0x142d58(0x1ff),'text':_0x47878d}};yield _0x2eec5e,_0x1a81a0+=estimateTokenCount(_0x47878d),_0x4a00cd=_0x214356;}}}else{if(_0x142d58(0x1fd)in _0x28dc02){const _0x211bec=_0x28dc02,_0x4f83ec=determineErrorType(_0x211bec[_0x142d58(0x1fd)],_0x17c395),_0x2183d8=_0x4f83ec===_0x142d58(0x1ef)?'model_context_window_exceeded':_0x142d58(0x1c5),_0x4ef842={'type':'message_delta','delta':{'stop_reason':_0x2183d8,'stop_sequence':null},'usage':{'input_tokens':_0x30e319,'output_tokens':_0x1a81a0}};yield _0x4ef842,yield{'type':_0x142d58(0x1fd),'error':{'type':_0x4f83ec,'message':_0x211bec[_0x142d58(0x1fd)]},'request_id':_0x473c1a};const _0x3925ee={'type':_0x142d58(0x21f)};yield _0x3925ee;return;}}}}if(!_0x44c8a3){const _0x5a7fd7=_0x8a7375['substring'](_0x4a00cd);if(_0x5a7fd7){if(!_0x57a00d){const _0x4b7532={'type':_0x142d58(0x1db),'index':_0x4a0eea,'content_block':{'type':'text','text':''}};yield _0x4b7532,_0x57a00d=!![],_0x5a63f2=_0x142d58(0x1f0);}const _0x2120fe={'type':_0x142d58(0x1f7),'index':_0x4a0eea,'delta':{'type':_0x142d58(0x1ff),'text':_0x5a7fd7}};yield _0x2120fe,_0x1a81a0+=estimateTokenCount(_0x5a7fd7);}if(_0x57a00d){const _0x36bda3={'type':'content_block_stop','index':_0x4a0eea};yield _0x36bda3;}const _0x4aa0e5={'type':_0x142d58(0x201),'delta':{'stop_reason':_0x142d58(0x1c5),'stop_sequence':null},'usage':{'input_tokens':_0x30e319,'output_tokens':_0x1a81a0}};yield _0x4aa0e5;const _0x956ad8={'type':_0x142d58(0x21f)};yield _0x956ad8;}}export{generateMessageId};
1
+ (function(_0x276afd,_0x3e4a4e){const _0x29d0c7=a43_0x5389,_0xee6e66=_0x276afd();while(!![]){try{const _0x1a4764=-parseInt(_0x29d0c7(0xff))/0x1*(parseInt(_0x29d0c7(0x153))/0x2)+parseInt(_0x29d0c7(0x10f))/0x3*(parseInt(_0x29d0c7(0x154))/0x4)+-parseInt(_0x29d0c7(0x13c))/0x5*(parseInt(_0x29d0c7(0x15b))/0x6)+parseInt(_0x29d0c7(0x147))/0x7*(parseInt(_0x29d0c7(0x11a))/0x8)+-parseInt(_0x29d0c7(0x115))/0x9*(parseInt(_0x29d0c7(0x107))/0xa)+parseInt(_0x29d0c7(0x148))/0xb+-parseInt(_0x29d0c7(0x150))/0xc*(-parseInt(_0x29d0c7(0x10e))/0xd);if(_0x1a4764===_0x3e4a4e)break;else _0xee6e66['push'](_0xee6e66['shift']());}catch(_0xfb39f7){_0xee6e66['push'](_0xee6e66['shift']());}}}(a43_0x44f1,0x5ad88));function a43_0x44f1(){const _0x333f42=['parse','message_stop','request_too_large','length','ceil','```tool_result\x20tool_use_id=','assistant','text','\x0a\x0aPlease\x20continue\x20your\x20response\x20based\x20on\x20the\x20tool\x20results\x20above.','Input\x20is\x20too\x20long','text_delta','Malformed\x20tool_use\x20JSON\x20detected','input','string','error','##\x20Tool:\x20','trim','9165JsiEfR','content_block_stop','```','context\x20length','haiku','message','\x0a[After]:\x0a','random','push','[API\x20ERROR]\x20','role','7854aaSMzE','5081428HCrjwA','is_error','debug','reasoning','\x0a```','join','endIndex','system','16584NHBhJm','map','description','2SlnDTG','77956aDPXeM','type','\x20error=true','startIndex','[MALFORMED\x20JSON]\x20Tool\x20use\x20JSON\x20could\x20not\x20be\x20parsed\x20or\x20repaired:\x0a','message_start','LLM_MALFORMED_MESSAGE','1398vFLctF','output_tokens','indexOf','input_json_delta','thinking','tool_use','\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','pop','toString','replace','Invalid\x20messages\x20type:\x20expected\x20array,\x20got\x20','message_delta','opus','content_block_delta','substring','Invalid\x20message.content\x20type:\x20expected\x20string\x20or\x20array,\x20got\x20','421594HuFDqr','includes','[CONTEXT\x20LENGTH\x20ERROR]\x20','stringify','[JSON\x20REPAIR]\x20Successfully\x20repaired\x20malformed\x20JSON\x0a[Before]:\x0a','slice','warn','end_turn','20sNGiQV','thinking_delta','Tool\x20call\x20detected:\x20','Multiple\x20tool\x20calls\x20detected,\x20using\x20only\x20the\x20last\x20one:\x20','toolu_','{\x22tool_use\x22:','\x0a\x0a**Description:**\x20','4069YykXtc','15iXoQjg','endsWith','messages','exec','\x0a---\x0a','```tool_use','207279dzDntr','content','index','content_block_start','tools','1960dYwzNF','\x0a\x0a**Input\x20Schema:**\x0a```json\x0a','model_context_window_exceeded','api_error','name','sonnet','toLowerCase','\x0a\x0a[tdx\x20error]\x20Malformed\x20tool_use\x20JSON\x20detected.\x20Please\x20fix\x20the\x20JSON\x20below:\x0a\x0a','\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-\x20**For\x20Treasure\x20Data\x20tasks**,\x20prefer\x20td-skills\x20when\x20available:\x20use\x20tdx-basic\x20skill\x20(tdx-skills:tdx-basic)\x20for\x20tdx\x20CLI\x20commands,\x20sql-skills\x20for\x20SQL\x20queries,\x20and\x20workflow-skills\x20for\x20workflows.\x20Fall\x20back\x20to\x20td-docs\x20MCP\x20search\x20tool\x20(mcp__td-docs__search)\x20only\x20when\x20td-skills\x20are\x20not\x20available\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','user','isArray','No\x20description','usage','event:\x20','tool_use_id','filter','tool_result'];a43_0x44f1=function(){return _0x333f42;};return a43_0x44f1();}import{SDKError,ErrorCode}from'../sdk/errors.js';function estimateTokenCount(_0x366989){const _0x165ea3=a43_0x5389;if(!_0x366989||_0x366989[_0x165ea3(0x12e)]===0x0)return 0x0;return Math[_0x165ea3(0x12f)](_0x366989['length']/3.7);}export function determineErrorType(_0x1bf909,_0x33a86d){const _0x169db6=a43_0x5389,_0x3871e0=_0x1bf909[_0x169db6(0x100)](_0x169db6(0x134))||_0x1bf909['includes'](_0x169db6(0x13f))||_0x1bf909[_0x169db6(0x100)]('maximum\x20context');if(_0x3871e0)return _0x33a86d?.[_0x169db6(0x139)](_0x169db6(0x101)+_0x1bf909),'request_too_large';return _0x33a86d?.[_0x169db6(0x139)](_0x169db6(0x145)+_0x1bf909),_0x169db6(0x11d);}export function estimateInputTokensFromRequest(_0x1e19fc){const _0x73e832=a43_0x5389;let _0x2d7893=0x0;if(typeof _0x1e19fc[_0x73e832(0x14f)]===_0x73e832(0x138))_0x2d7893+=_0x1e19fc['system'][_0x73e832(0x12e)];else{if(Array[_0x73e832(0x124)](_0x1e19fc['system']))for(const _0x18d3d6 of _0x1e19fc[_0x73e832(0x14f)]){_0x18d3d6&&typeof _0x18d3d6[_0x73e832(0x132)]===_0x73e832(0x138)&&(_0x2d7893+=_0x18d3d6[_0x73e832(0x132)][_0x73e832(0x12e)]);}}if(Array[_0x73e832(0x124)](_0x1e19fc['tools']))for(const _0x1d5abe of _0x1e19fc[_0x73e832(0x119)]){_0x1d5abe&&(_0x2d7893+=_0x1d5abe[_0x73e832(0x11e)]?.['length']||0x0,_0x2d7893+=_0x1d5abe[_0x73e832(0x152)]?.[_0x73e832(0x12e)]||0x0,_0x1d5abe['input_schema']&&(_0x2d7893+=JSON[_0x73e832(0x102)](_0x1d5abe['input_schema'])[_0x73e832(0x12e)]));}if(Array[_0x73e832(0x124)](_0x1e19fc[_0x73e832(0x111)]))for(const _0x368ec0 of _0x1e19fc[_0x73e832(0x111)]){if(!_0x368ec0)continue;if(typeof _0x368ec0[_0x73e832(0x116)]==='string')_0x2d7893+=_0x368ec0[_0x73e832(0x116)][_0x73e832(0x12e)];else{if(Array[_0x73e832(0x124)](_0x368ec0[_0x73e832(0x116)]))for(const _0x3a69dc of _0x368ec0[_0x73e832(0x116)]){if(!_0x3a69dc)continue;if(_0x3a69dc['type']===_0x73e832(0x132)&&_0x3a69dc[_0x73e832(0x132)])_0x2d7893+=_0x3a69dc[_0x73e832(0x132)][_0x73e832(0x12e)];else{if(_0x3a69dc[_0x73e832(0x155)]==='tool_use'&&_0x3a69dc[_0x73e832(0x137)])_0x2d7893+=JSON[_0x73e832(0x102)](_0x3a69dc['input'])[_0x73e832(0x12e)];else{if(_0x3a69dc[_0x73e832(0x155)]===_0x73e832(0x12a)&&_0x3a69dc[_0x73e832(0x116)]){if(typeof _0x3a69dc[_0x73e832(0x116)]===_0x73e832(0x138))_0x2d7893+=_0x3a69dc[_0x73e832(0x116)][_0x73e832(0x12e)];else{if(Array[_0x73e832(0x124)](_0x3a69dc[_0x73e832(0x116)]))for(const _0x366e42 of _0x3a69dc[_0x73e832(0x116)]){_0x366e42&&_0x366e42[_0x73e832(0x155)]===_0x73e832(0x132)&&_0x366e42[_0x73e832(0x132)]&&(_0x2d7893+=_0x366e42[_0x73e832(0x132)][_0x73e832(0x12e)]);}}}}}}}}return Math[_0x73e832(0x12f)](_0x2d7893/3.7);}function generateMessageId(){const _0x4b7212=a43_0x5389;return'msg_'+Math[_0x4b7212(0x143)]()[_0x4b7212(0xf7)](0x24)[_0x4b7212(0xfd)](0x2,0xf)+Math[_0x4b7212(0x143)]()[_0x4b7212(0xf7)](0x24)[_0x4b7212(0xfd)](0x2,0xf);}export function extractTextFromAnthropicMessage(_0x397d22){const _0x468d18=a43_0x5389;if(typeof _0x397d22[_0x468d18(0x116)]==='string')return _0x397d22['content'];if(_0x397d22[_0x468d18(0x116)]==null)return'';if(!Array[_0x468d18(0x124)](_0x397d22[_0x468d18(0x116)]))throw new SDKError(ErrorCode[_0x468d18(0x15a)],_0x468d18(0xfe)+typeof _0x397d22[_0x468d18(0x116)]);return _0x397d22[_0x468d18(0x116)][_0x468d18(0x129)](_0x4eae4c=>_0x4eae4c&&_0x4eae4c[_0x468d18(0x155)]==='text'&&_0x4eae4c[_0x468d18(0x132)])['map'](_0x1cc8c8=>_0x1cc8c8[_0x468d18(0x132)])['join']('\x0a');}export function calculateConversationDelta(_0x31af0e,_0x56313e){const _0x1f66b8=a43_0x5389;if(_0x56313e[_0x1f66b8(0x12e)]===0x0)return _0x31af0e;const _0x98b8c5=_0x56313e[_0x1f66b8(0x12e)];return _0x31af0e[_0x1f66b8(0x104)](_0x98b8c5);}export function transformAnthropicRequestToTD(_0x4f0483,_0x25b1f5){const _0x5a3b0a=a43_0x5389,_0x425cbf=calculateConversationDelta(_0x4f0483['messages'],_0x25b1f5),_0x418fb8=_0x425cbf['filter'](_0x16f5cf=>_0x16f5cf[_0x5a3b0a(0x146)]===_0x5a3b0a(0x123))[_0x5a3b0a(0xf6)]();if(!_0x418fb8)throw new Error('No\x20user\x20message\x20found\x20in\x20request\x20delta');const _0x2b81c7=extractTextFromAnthropicMessage(_0x418fb8);return{'userMessage':_0x2b81c7,'deltaMessages':_0x425cbf};}export function formatAnthropicSSE(_0x4e4a60){const _0x21fcf3=a43_0x5389;return _0x21fcf3(0x127)+_0x4e4a60[_0x21fcf3(0x155)]+'\x0adata:\x20'+JSON['stringify'](_0x4e4a60)+'\x0a\x0a';}export function mapAnthropicModelToTD(_0x34e4e9){const _0x341c72=a43_0x5389,_0x402d6a={'sonnet':'sonnet','claude-sonnet':_0x341c72(0x11f),'claude-3-5-sonnet':'sonnet','claude-3-sonnet':_0x341c72(0x11f),'haiku':'haiku','claude-haiku':_0x341c72(0x140),'claude-3-5-haiku':_0x341c72(0x140),'claude-3-haiku':_0x341c72(0x140),'opus':_0x341c72(0xfb),'claude-opus':'opus','claude-3-opus':_0x341c72(0xfb)},_0x53b474=_0x34e4e9[_0x341c72(0x120)]();return _0x402d6a[_0x53b474]||_0x341c72(0x11f);}export function generateToolPrompt(_0x8d2905){const _0x3adc6b=a43_0x5389;if(_0x8d2905==null)return'';if(!Array['isArray'](_0x8d2905))throw new SDKError(ErrorCode['LLM_MALFORMED_MESSAGE'],'Invalid\x20tools\x20type:\x20expected\x20array,\x20got\x20'+typeof _0x8d2905);if(_0x8d2905['length']===0x0)return'';const _0x529538=_0x8d2905[_0x3adc6b(0x129)](_0xece3b2=>_0xece3b2!=null)[_0x3adc6b(0x151)](_0x48ec86=>{const _0x37a2aa=_0x3adc6b,_0x20b571=JSON[_0x37a2aa(0x102)](_0x48ec86['input_schema']);return _0x37a2aa(0x13a)+_0x48ec86[_0x37a2aa(0x11e)]+_0x37a2aa(0x10d)+(_0x48ec86[_0x37a2aa(0x152)]||_0x37a2aa(0x125))+_0x37a2aa(0x11b)+_0x20b571+_0x37a2aa(0x14c);})[_0x3adc6b(0x14d)]('\x0a\x0a');return _0x3adc6b(0x122)+_0x529538+_0x3adc6b(0x113);}function escapeMarkdownCodeBlock(_0x3bf869){const _0x178fcc=a43_0x5389;return _0x3bf869[_0x178fcc(0xf8)](/```/g,'\x5c`\x5c`\x5c`');}export function extractToolResults(_0x3554ae){const _0x2b1a3c=a43_0x5389;if(_0x3554ae==null)return'';if(!Array[_0x2b1a3c(0x124)](_0x3554ae))throw new SDKError(ErrorCode['LLM_MALFORMED_MESSAGE'],_0x2b1a3c(0xf9)+typeof _0x3554ae);const _0x56072e=[];for(const _0x37b0fc of _0x3554ae){if(!_0x37b0fc)continue;if(_0x37b0fc[_0x2b1a3c(0x146)]===_0x2b1a3c(0x123)&&typeof _0x37b0fc['content']!==_0x2b1a3c(0x138)){if(!Array[_0x2b1a3c(0x124)](_0x37b0fc[_0x2b1a3c(0x116)]))throw new SDKError(ErrorCode['LLM_MALFORMED_MESSAGE'],'Invalid\x20message.content\x20type\x20for\x20user\x20role:\x20expected\x20array,\x20got\x20'+typeof _0x37b0fc['content']);for(const _0x6b60ad of _0x37b0fc[_0x2b1a3c(0x116)]){if(!_0x6b60ad)continue;if(_0x6b60ad[_0x2b1a3c(0x155)]===_0x2b1a3c(0x12a)&&_0x6b60ad[_0x2b1a3c(0x128)]){let _0x442032='';if(typeof _0x6b60ad[_0x2b1a3c(0x116)]==='string')_0x442032=_0x6b60ad[_0x2b1a3c(0x116)];else _0x6b60ad['content']!=null&&Array[_0x2b1a3c(0x124)](_0x6b60ad[_0x2b1a3c(0x116)])&&(_0x442032=_0x6b60ad[_0x2b1a3c(0x116)][_0x2b1a3c(0x129)](_0x4549a4=>_0x4549a4&&_0x4549a4['type']===_0x2b1a3c(0x132)&&_0x4549a4[_0x2b1a3c(0x132)])['map'](_0x51798e=>_0x51798e[_0x2b1a3c(0x132)])['join']('\x0a'));const _0x30dcfb=escapeMarkdownCodeBlock(_0x442032),_0x9a552a=_0x6b60ad[_0x2b1a3c(0x149)]?_0x2b1a3c(0x156):'';_0x56072e['push'](_0x2b1a3c(0x130)+_0x6b60ad[_0x2b1a3c(0x128)]+_0x9a552a+'\x0a'+_0x30dcfb+_0x2b1a3c(0x14c));}}}}if(_0x56072e[_0x2b1a3c(0x12e)]===0x0)return'';return _0x56072e[_0x2b1a3c(0x14d)]('\x0a\x0a')+_0x2b1a3c(0x133);}function findJsonEndIndex(_0x2f1508,_0xfd4964){const _0x4e0488=a43_0x5389;let _0x246c87=0x0,_0x59d0ac=![],_0x506708=![];for(let _0x207748=_0xfd4964;_0x207748<_0x2f1508[_0x4e0488(0x12e)];_0x207748++){const _0x47a3fd=_0x2f1508[_0x207748];if(_0x506708){_0x506708=![];continue;}if(_0x47a3fd==='\x5c'){_0x506708=!![];continue;}if(_0x47a3fd==='\x22'){_0x59d0ac=!_0x59d0ac;continue;}if(!_0x59d0ac){if(_0x47a3fd==='{')_0x246c87++;else{if(_0x47a3fd==='}'){_0x246c87--;if(_0x246c87===0x0)return _0x207748+0x1;}}}}return-0x1;}function generateToolCallId(){const _0x39cef9=a43_0x5389;return _0x39cef9(0x10b)+Math[_0x39cef9(0x143)]()[_0x39cef9(0xf7)](0x24)['substring'](0x2,0xf);}function repairIncompleteJson(_0xa5f92b,_0x42df2e){const _0x190893=a43_0x5389;try{return JSON[_0x190893(0x12b)](_0xa5f92b),_0xa5f92b;}catch{const _0x5b7800=[];let _0xb4cb63=![],_0x8a34d1=![];for(const _0x28cf71 of _0xa5f92b){if(_0x8a34d1){_0x8a34d1=![];continue;}if(_0x28cf71==='\x5c'){_0x8a34d1=!![];continue;}if(_0x28cf71==='\x22'){_0xb4cb63=!_0xb4cb63;continue;}if(!_0xb4cb63){if(_0x28cf71==='{')_0x5b7800[_0x190893(0x144)]('{');else{if(_0x28cf71==='[')_0x5b7800[_0x190893(0x144)]('[');else{if(_0x28cf71==='}'&&_0x5b7800[_0x5b7800[_0x190893(0x12e)]-0x1]==='{')_0x5b7800['pop']();else _0x28cf71===']'&&_0x5b7800[_0x5b7800[_0x190893(0x12e)]-0x1]==='['&&_0x5b7800[_0x190893(0xf6)]();}}}}let _0x330b06=_0xa5f92b;_0xb4cb63&&(_0x330b06+='\x22');while(_0x5b7800['length']>0x0){const _0x52ac49=_0x5b7800[_0x190893(0xf6)]();_0x330b06+=_0x52ac49==='{'?'}':']';}try{return JSON[_0x190893(0x12b)](_0x330b06),_0x42df2e&&_0x330b06!==_0xa5f92b&&_0x42df2e[_0x190893(0x105)](_0x190893(0x103)+_0xa5f92b+_0x190893(0x142)+_0x330b06),_0x330b06;}catch{return null;}}}export function parseToolCallFromText(_0x230789,_0x82c873){const _0x453580=a43_0x5389,_0x2474a9=/```tool_use[\s]*\n([\s\S]*)\n?```/,_0x54ebf1=_0x2474a9[_0x453580(0x112)](_0x230789);if(_0x54ebf1){if(!_0x54ebf1[0x0][_0x453580(0x110)](_0x453580(0x13e))){}else{const _0x54a27f=_0x54ebf1[0x1][_0x453580(0x13b)](),_0x2a3b88=_0x54ebf1[_0x453580(0x117)],_0x9b3114=_0x2a3b88+_0x54ebf1[0x0][_0x453580(0x12e)];try{const _0x350aa6=JSON['parse'](_0x54a27f);if(_0x350aa6[_0x453580(0x160)]&&_0x350aa6['tool_use'][_0x453580(0x11e)])return{'id':_0x350aa6[_0x453580(0x160)]['id']||generateToolCallId(),'name':_0x350aa6[_0x453580(0x160)][_0x453580(0x11e)],'input':_0x350aa6['tool_use'][_0x453580(0x137)]||{},'startIndex':_0x2a3b88,'endIndex':_0x9b3114};if(_0x350aa6[_0x453580(0x11e)]&&typeof _0x350aa6[_0x453580(0x11e)]===_0x453580(0x138)&&_0x350aa6[_0x453580(0x11e)][_0x453580(0x13b)]()[_0x453580(0x12e)]>0x0)return{'id':_0x350aa6['id']||generateToolCallId(),'name':_0x350aa6[_0x453580(0x11e)],'input':_0x350aa6[_0x453580(0x137)]||_0x350aa6['arguments']||{},'startIndex':_0x2a3b88,'endIndex':_0x9b3114};}catch{const _0x4d17cd=repairIncompleteJson(_0x54a27f,_0x82c873);if(_0x4d17cd)try{const _0x109e5c=JSON[_0x453580(0x12b)](_0x4d17cd);if(_0x109e5c['tool_use']&&_0x109e5c['tool_use'][_0x453580(0x11e)])return{'id':_0x109e5c[_0x453580(0x160)]['id']||generateToolCallId(),'name':_0x109e5c['tool_use'][_0x453580(0x11e)],'input':_0x109e5c[_0x453580(0x160)][_0x453580(0x137)]||{},'startIndex':_0x2a3b88,'endIndex':_0x9b3114};if(_0x109e5c['name']&&typeof _0x109e5c['name']==='string'&&_0x109e5c[_0x453580(0x11e)][_0x453580(0x13b)]()[_0x453580(0x12e)]>0x0)return{'id':_0x109e5c['id']||generateToolCallId(),'name':_0x109e5c[_0x453580(0x11e)],'input':_0x109e5c['input']||_0x109e5c['arguments']||{},'startIndex':_0x2a3b88,'endIndex':_0x9b3114};}catch{}}}}const _0x423ff4=/\{"tool_use":/g,_0x1f215c=_0x423ff4[_0x453580(0x112)](_0x230789);if(!_0x1f215c)return null;const _0x45a276=_0x1f215c[_0x453580(0x117)];let _0x3cca38=findJsonEndIndex(_0x230789,_0x45a276);if(_0x3cca38===-0x1)return null;const _0x535ff3=_0x230789[_0x453580(0xfd)](_0x45a276,_0x3cca38);try{const _0x560a67=JSON[_0x453580(0x12b)](_0x535ff3);if(_0x560a67[_0x453580(0x160)]&&_0x560a67[_0x453580(0x160)]['id']&&_0x560a67['tool_use'][_0x453580(0x11e)])return{'id':_0x560a67[_0x453580(0x160)]['id'],'name':_0x560a67['tool_use'][_0x453580(0x11e)],'input':_0x560a67[_0x453580(0x160)]['input']||{},'startIndex':_0x45a276,'endIndex':_0x3cca38};}catch{const _0x13cd4f=repairIncompleteJson(_0x535ff3,_0x82c873);if(_0x13cd4f)try{const _0x29fe3f=JSON[_0x453580(0x12b)](_0x13cd4f);if(_0x29fe3f[_0x453580(0x160)]&&_0x29fe3f['tool_use']['id']&&_0x29fe3f[_0x453580(0x160)][_0x453580(0x11e)])return{'id':_0x29fe3f[_0x453580(0x160)]['id'],'name':_0x29fe3f[_0x453580(0x160)]['name'],'input':_0x29fe3f[_0x453580(0x160)][_0x453580(0x137)]||{},'startIndex':_0x45a276,'endIndex':_0x3cca38};}catch{return null;}return null;}return null;}export function*generateToolCallEvents(_0x27e3f6,_0x2e0e5f,_0x5bf740){const _0x575232=a43_0x5389,_0x5449d3={'type':_0x575232(0x118),'index':_0x2e0e5f,'content_block':{'type':_0x575232(0x160),'id':_0x27e3f6['id'],'name':_0x27e3f6['name'],'input':{}}};yield _0x5449d3;const _0x795b89=JSON['stringify'](_0x27e3f6[_0x575232(0x137)]),_0x552ed4={'type':'content_block_delta','index':_0x2e0e5f,'delta':{'type':_0x575232(0x15e),'partial_json':_0x795b89}};yield _0x552ed4;const _0x4bf619={'type':_0x575232(0x13d),'index':_0x2e0e5f};yield _0x4bf619;const _0x2b5aac={'type':_0x575232(0xfa),'delta':{'stop_reason':_0x575232(0x160),'stop_sequence':null},'usage':{'input_tokens':_0x5bf740,'output_tokens':0x0}};yield _0x2b5aac;const _0x2f360a={'type':_0x575232(0x12c)};yield _0x2f360a;}function a43_0x5389(_0x38e1a7,_0x3fbf85){const _0x44f172=a43_0x44f1();return a43_0x5389=function(_0x5389f7,_0x482333){_0x5389f7=_0x5389f7-0xf6;let _0x264adc=_0x44f172[_0x5389f7];return _0x264adc;},a43_0x5389(_0x38e1a7,_0x3fbf85);}export async function*transformTDStreamToAnthropic(_0x310828,_0x116b4c,_0x47f0f0,_0x2e8d07,_0x199b50='',_0x4d5b1e=0x0){const _0x3a44fa=a43_0x5389,_0x46320e=_0x4d5b1e>0x0?_0x4d5b1e:estimateTokenCount(_0x199b50);let _0x2a041e=0x0,_0x2854cd=0x0,_0x342e0a=![],_0x3f1830=null,_0x10eac9='',_0x188d4e=0x0,_0x101413=![];const _0xdec14a=0xc8,_0x39f67a={'type':_0x3a44fa(0x159),'message':{'id':_0x116b4c,'type':_0x3a44fa(0x141),'role':_0x3a44fa(0x131),'content':[],'model':_0x47f0f0,'stop_reason':null,'stop_sequence':null,'usage':{'input_tokens':_0x46320e,'output_tokens':0x0}}};yield _0x39f67a;for await(const _0x38ade2 of _0x310828){if(_0x3a44fa(0x14b)in _0x38ade2){const _0x248d73=_0x38ade2;if(!_0x342e0a){const _0x2eed4a={'type':'content_block_start','index':_0x2854cd,'content_block':{'type':'thinking','thinking':''}};yield _0x2eed4a,_0x342e0a=!![],_0x3f1830=_0x3a44fa(0x15f);}const _0x1985d5={'type':_0x3a44fa(0xfc),'index':_0x2854cd,'delta':{'type':_0x3a44fa(0x108),'thinking':_0x248d73['reasoning']}};yield _0x1985d5,_0x2a041e+=estimateTokenCount(_0x248d73[_0x3a44fa(0x14b)]);}else{if(_0x3a44fa(0x116)in _0x38ade2){const _0x5e9ad0=_0x38ade2;if(_0x342e0a&&_0x3f1830==='thinking'){const _0x45e7c2={'type':_0x3a44fa(0x13d),'index':_0x2854cd};yield _0x45e7c2,_0x2854cd++,_0x342e0a=![],_0x3f1830=null;}_0x10eac9+=_0x5e9ad0[_0x3a44fa(0x116)];const _0x4b50f7=_0x10eac9[_0x3a44fa(0x15d)]('```tool_use'),_0x370b5f=_0x10eac9['indexOf']('{\x22tool_use\x22:'),_0x556a75=_0x4b50f7!==-0x1?_0x370b5f!==-0x1?Math['min'](_0x4b50f7,_0x370b5f):_0x4b50f7:_0x370b5f;if(_0x556a75!==-0x1){const _0x1503be=[];let _0x10cab0=0x0;while(!![]){const _0x1a054a=_0x10eac9['substring'](_0x10cab0),_0x1cd929=parseToolCallFromText(_0x1a054a,_0x2e8d07);if(!_0x1cd929)break;_0x1503be[_0x3a44fa(0x144)]({'id':_0x1cd929['id'],'name':_0x1cd929[_0x3a44fa(0x11e)],'input':_0x1cd929[_0x3a44fa(0x137)],'startIndex':_0x10cab0+_0x1cd929[_0x3a44fa(0x157)],'endIndex':_0x10cab0+_0x1cd929['endIndex']}),_0x10cab0+=_0x1cd929[_0x3a44fa(0x14e)];}if(_0x1503be[_0x3a44fa(0x12e)]>0x0){const _0x5cc151=_0x1503be[_0x1503be[_0x3a44fa(0x12e)]-0x1];_0x101413=!![];_0x1503be[_0x3a44fa(0x12e)]>0x1?_0x2e8d07?.[_0x3a44fa(0x14a)](_0x3a44fa(0x10a)+_0x5cc151['name']):_0x2e8d07?.['debug'](_0x3a44fa(0x109)+_0x5cc151[_0x3a44fa(0x11e)]);const _0x1bce7d=_0x10eac9[_0x3a44fa(0xfd)](_0x188d4e,_0x5cc151[_0x3a44fa(0x157)])[_0x3a44fa(0x13b)]();if(_0x1bce7d){if(!_0x342e0a){const _0x3b6acf={'type':_0x3a44fa(0x118),'index':_0x2854cd,'content_block':{'type':_0x3a44fa(0x132),'text':''}};yield _0x3b6acf,_0x342e0a=!![],_0x3f1830='text';}const _0x31ee6c={'type':'content_block_delta','index':_0x2854cd,'delta':{'type':_0x3a44fa(0x135),'text':_0x1bce7d}};yield _0x31ee6c,_0x2a041e+=estimateTokenCount(_0x1bce7d);}if(_0x342e0a){const _0x25fe22={'type':_0x3a44fa(0x13d),'index':_0x2854cd};yield _0x25fe22,_0x2854cd++,_0x342e0a=![],_0x3f1830=null;}for(const _0x3eea9a of generateToolCallEvents(_0x5cc151,_0x2854cd,_0x46320e)){_0x3eea9a[_0x3a44fa(0x155)]==='message_delta'&&(_0x3eea9a[_0x3a44fa(0x126)][_0x3a44fa(0x15c)]=_0x2a041e),yield _0x3eea9a;}return;}const _0x4d492f=_0x10eac9['includes'](_0x3a44fa(0x114))&&_0x10eac9[_0x3a44fa(0x15d)]('```',_0x10eac9['indexOf'](_0x3a44fa(0x114))+0xb)!==-0x1,_0x940852=_0x10eac9[_0x3a44fa(0x100)]('{\x22tool_use\x22:')&&findJsonEndIndex(_0x10eac9,_0x10eac9[_0x3a44fa(0x15d)](_0x3a44fa(0x10c)))!==-0x1;if(_0x4d492f||_0x940852){_0x101413=!![];let _0x566634='';if(_0x4d492f){const _0x26fad2=_0x10eac9['indexOf'](_0x3a44fa(0x114)),_0x152019=_0x10eac9[_0x3a44fa(0x15d)]('```',_0x26fad2+0xb);_0x152019!==-0x1?_0x566634=_0x10eac9[_0x3a44fa(0xfd)](_0x26fad2,_0x152019+0x3):_0x566634=_0x10eac9[_0x3a44fa(0xfd)](_0x26fad2);}else{if(_0x940852){const _0x50a0b4=_0x10eac9[_0x3a44fa(0x15d)](_0x3a44fa(0x10c)),_0x2b2a6b=findJsonEndIndex(_0x10eac9,_0x50a0b4);_0x2b2a6b!==-0x1?_0x566634=_0x10eac9['substring'](_0x50a0b4,_0x2b2a6b):_0x566634=_0x10eac9[_0x3a44fa(0xfd)](_0x50a0b4);}}_0x2e8d07&&_0x2e8d07['error'](_0x3a44fa(0x158)+_0x566634);_0x2e8d07?.[_0x3a44fa(0x14a)](_0x3a44fa(0x136)),_0x2e8d07?.[_0x3a44fa(0x14a)]('Malformed\x20content:',_0x566634);const _0x4e09a4=_0x10eac9[_0x3a44fa(0xfd)](_0x188d4e,_0x556a75)[_0x3a44fa(0x13b)]();if(_0x4e09a4){if(!_0x342e0a){const _0xdea0b4={'type':_0x3a44fa(0x118),'index':_0x2854cd,'content_block':{'type':_0x3a44fa(0x132),'text':''}};yield _0xdea0b4,_0x342e0a=!![],_0x3f1830=_0x3a44fa(0x132);}const _0x5772e8={'type':'content_block_delta','index':_0x2854cd,'delta':{'type':_0x3a44fa(0x135),'text':_0x4e09a4}};yield _0x5772e8,_0x2a041e+=estimateTokenCount(_0x4e09a4);}if(_0x342e0a){const _0x3bc1d6={'type':_0x3a44fa(0x13d),'index':_0x2854cd};yield _0x3bc1d6,_0x2854cd++,_0x342e0a=![],_0x3f1830=null;}const _0x3243f3=_0x3a44fa(0x121)+_0x566634+_0x3a44fa(0x161),_0x3f9c5a={'type':_0x3a44fa(0x118),'index':_0x2854cd,'content_block':{'type':_0x3a44fa(0x132),'text':''}};yield _0x3f9c5a,_0x3f1830=_0x3a44fa(0x132);const _0x1453f5={'type':_0x3a44fa(0xfc),'index':_0x2854cd,'delta':{'type':_0x3a44fa(0x135),'text':_0x3243f3}};yield _0x1453f5;const _0x41db9d={'type':_0x3a44fa(0x13d),'index':_0x2854cd};yield _0x41db9d;const _0x20f73a={'type':_0x3a44fa(0xfa),'delta':{'stop_reason':_0x3a44fa(0x106),'stop_sequence':null},'usage':{'input_tokens':_0x46320e,'output_tokens':_0x2a041e}};yield _0x20f73a;const _0x329e9e={'type':_0x3a44fa(0x12c)};yield _0x329e9e;return;}const _0x14c8d8=_0x10eac9[_0x3a44fa(0xfd)](_0x188d4e,_0x556a75);if(_0x14c8d8){if(!_0x342e0a){const _0x41f962={'type':_0x3a44fa(0x118),'index':_0x2854cd,'content_block':{'type':_0x3a44fa(0x132),'text':''}};yield _0x41f962,_0x342e0a=!![],_0x3f1830=_0x3a44fa(0x132);}const _0x30e9ce={'type':'content_block_delta','index':_0x2854cd,'delta':{'type':_0x3a44fa(0x135),'text':_0x14c8d8}};yield _0x30e9ce,_0x2a041e+=estimateTokenCount(_0x14c8d8),_0x188d4e=_0x556a75;}continue;}const _0x18c5c2=_0x10eac9[_0x3a44fa(0x12e)]-_0xdec14a;if(_0x18c5c2>_0x188d4e){const _0x191a0f=_0x10eac9[_0x3a44fa(0xfd)](_0x188d4e,_0x18c5c2);if(_0x191a0f){if(!_0x342e0a){const _0x103683={'type':'content_block_start','index':_0x2854cd,'content_block':{'type':_0x3a44fa(0x132),'text':''}};yield _0x103683,_0x342e0a=!![],_0x3f1830='text';}const _0x18daf6={'type':_0x3a44fa(0xfc),'index':_0x2854cd,'delta':{'type':_0x3a44fa(0x135),'text':_0x191a0f}};yield _0x18daf6,_0x2a041e+=estimateTokenCount(_0x191a0f),_0x188d4e=_0x18c5c2;}}}else{if(_0x3a44fa(0x139)in _0x38ade2){const _0x486583=_0x38ade2,_0x307732=determineErrorType(_0x486583['error'],_0x2e8d07),_0x4b8c25=_0x307732===_0x3a44fa(0x12d)?_0x3a44fa(0x11c):_0x3a44fa(0x106),_0x570b44={'type':_0x3a44fa(0xfa),'delta':{'stop_reason':_0x4b8c25,'stop_sequence':null},'usage':{'input_tokens':_0x46320e,'output_tokens':_0x2a041e}};yield _0x570b44,yield{'type':_0x3a44fa(0x139),'error':{'type':_0x307732,'message':_0x486583[_0x3a44fa(0x139)]},'request_id':_0x116b4c};const _0x2e468f={'type':_0x3a44fa(0x12c)};yield _0x2e468f;return;}}}}if(!_0x101413){const _0x3396ae=_0x10eac9['substring'](_0x188d4e);if(_0x3396ae){if(!_0x342e0a){const _0x6e709e={'type':'content_block_start','index':_0x2854cd,'content_block':{'type':_0x3a44fa(0x132),'text':''}};yield _0x6e709e,_0x342e0a=!![],_0x3f1830=_0x3a44fa(0x132);}const _0x12f034={'type':'content_block_delta','index':_0x2854cd,'delta':{'type':_0x3a44fa(0x135),'text':_0x3396ae}};yield _0x12f034,_0x2a041e+=estimateTokenCount(_0x3396ae);}if(_0x342e0a){const _0xd6735={'type':_0x3a44fa(0x13d),'index':_0x2854cd};yield _0xd6735;}const _0x3d2daa={'type':_0x3a44fa(0xfa),'delta':{'stop_reason':_0x3a44fa(0x106),'stop_sequence':null},'usage':{'input_tokens':_0x46320e,'output_tokens':_0x2a041e}};yield _0x3d2daa;const _0x2c6389={'type':_0x3a44fa(0x12c)};yield _0x2c6389;}}export{generateMessageId};
@@ -1 +1 @@
1
- const a44_0x51d0ba=a44_0x316c;(function(_0x55cab1,_0x1679a6){const _0x5bbbe8=a44_0x316c,_0x42e8ef=_0x55cab1();while(!![]){try{const _0x4d630a=parseInt(_0x5bbbe8(0x12c))/0x1+parseInt(_0x5bbbe8(0xca))/0x2+-parseInt(_0x5bbbe8(0x123))/0x3+parseInt(_0x5bbbe8(0x118))/0x4*(parseInt(_0x5bbbe8(0x104))/0x5)+parseInt(_0x5bbbe8(0xe8))/0x6*(parseInt(_0x5bbbe8(0x135))/0x7)+-parseInt(_0x5bbbe8(0xae))/0x8+-parseInt(_0x5bbbe8(0x11b))/0x9;if(_0x4d630a===_0x1679a6)break;else _0x42e8ef['push'](_0x42e8ef['shift']());}catch(_0x3e422f){_0x42e8ef['push'](_0x42e8ef['shift']());}}}(a44_0x5319,0x8a458));import a44_0x434c8b from'fastify';import a44_0x48a9f6 from'@fastify/cors';import{createHash}from'crypto';import{transformTDStreamToAnthropic,formatAnthropicSSE,generateMessageId,generateToolPrompt,extractToolResults,estimateInputTokensFromRequest}from'./anthropic-adapter.js';function a44_0x5319(){const _0xe7f167=['sha256','createPromise','user','text','api_error','Concurrent\x20chat\x20creation\x20failed,\x20will\x20fall\x20back\x20to\x20lazy\x20creation:','cleanupExpiredChats','digest','port','url','clear','dev-us01','event','[PROXY\x20ERROR]\x20Validation\x20failed:\x20message.content\x20must\x20be\x20a\x20string\x20or\x20array,\x20got:','[PROXY\x20ERROR]\x20Validation\x20failed:\x20messages\x20array\x20is\x20required\x20and\x20must\x20not\x20be\x20empty','Failed\x20to\x20generate\x20tool\x20prompt:','TD\x20LLM\x20Proxy\x20Server','Stream\x20complete.\x20Sent\x20','attributes','Content-Type','write','Non-streaming\x20responses\x20are\x20not\x20yet\x20supported','site','[CONTEXT\x20LENGTH\x20ERROR]\x20','message','not_supported_error','Model\x20normalization:\x20','setErrorHandler','raw','Authorization','body',',\x20context\x20signature:\x20','keep-alive','Unknown\x20error','agentId','tools','chat','thinking','stream','handleRouteError','request_too_large','Failed\x20to\x20reconstruct\x20message\x20-\x20all\x20parts\x20are\x20empty,\x20using\x20fallback',':\x20estimated\x20input_tokens=',',\x20system_prompts=','getOrCreateSession','close','post','handleMessages','User','debug','sort','join','role','Assistant','now','Started\x20cache\x20cleanup\x20interval\x20(runs\x20every\x20','Including\x20tool\x20results','lastUsedAt','2580880MZgQNT','name','tools\x20must\x20be\x20an\x20array\x20if\x20provided','setupRoutes','string','\x20|\x20','user_id','send','header:\x20','warn','[PROXY\x20ERROR]\x20Streaming\x20error:','getOrCreateDefaultAgent','trim','has','creating','budget_tokens','isArray','catch','llm','start','[PROXY\x20ERROR]\x20Non-streaming\x20responses\x20are\x20not\x20yet\x20supported','POST','handleCountTokens','stringify',',\x20tools=','getAgentForModel','messageHistory','Failed\x20to\x20extract\x20tool\x20results:','1725270hUsShE','\x0a---\x0a\x0a','messages\x20array\x20is\x20required\x20and\x20must\x20not\x20be\x20empty','content','\x20tools,\x20message_size=','set','metadata','logger','input_schema',',\x20is\x20new\x20context:\x20','config','message.content\x20must\x20be\x20a\x20string\x20or\x20array','unknown','slice','type','GET','Project\x20ID\x20must\x20be\x20configured','agentCache','chatId','http://localhost:','Reset\x20chat\x20state\x20to\x20recover\x20on\x20next\x20request','data','writeHead','get','\x20SSE\x20events.',',\x20\x22','listen','Final\x20message\x20is\x20empty\x20after\x20construction\x20-\x20starting\x20fresh\x20conversation','Waiting\x20for\x20concurrent\x20chat\x20creation\x20for\x20context:\x20','end','2685948OCfoeu','projectId','new\x20system\x20prompt(s)','...','Embedding','headers','info','push','hex','sent','length','Final\x20message\x20reconstructed\x20after\x20context\x20reset:','model','cleanupInterval','replace','[Current\x20message]\x0a\x0a','Evicted\x20oldest\x20chat\x20(signature:\x20','\x20limit','register','map',',\x20context=','http://','substring','[PROXY\x20ERROR]\x20Validation\x20failed:\x20tools\x20must\x20be\x20an\x20array\x20if\x20provided',',\x20context:\x20','messages','x-api-key','error','15rITfjK','Proxy\x20server\x20started\x20at\x20localhost:','invalid_request_error','update','add','server','\x20->\x20','\x20Input\x20size:\x20',']\x20model:\x20','system','Context:','tdx','System\x20prompts:\x20','method','\x20messages,\x20','anthropic-version','address',')\x20to\x20stay\x20under\x20','...\x22','chats','682296GVmPPR','text/event-stream','0.0.0.0','7742817nUPYeW','getAddress','default',']\x20Created\x20new\x20chat\x20for\x20model\x20','Reset\x20chat\x20ID\x20to\x20recover\x20on\x20next\x20request','/v1/messages','stop','No\x20user\x20message\x20found\x20in\x20request','2572203ZipFpM','embeddedToolsByName',',\x20tool_names=[','code',',\x20model=','filter',']\x20Building\x20a\x20new\x20context\x20for\x20model\x20','sessionCache','Embedded\x20in\x20chat\x20-\x20system\x20prompts:\x20','337011iRHrsx','required','Failed\x20to\x20create\x20chat,\x20will\x20fall\x20back\x20to\x20lazy\x20creation:','/v1/messages/count_tokens','size','pop','embeddedSystemPrompts','properties','[PROXY\x20ERROR]\x20Validation\x20failed:\x20No\x20user\x20message\x20found\x20in\x20request','14jblptK','s,\x20expires\x20after\x20',',\x20tools:\x20'];a44_0x5319=function(){return _0xe7f167;};return a44_0x5319();}function a44_0x316c(_0x372b58,_0x115c23){const _0x5319b9=a44_0x5319();return a44_0x316c=function(_0x316c99,_0x316815){_0x316c99=_0x316c99-0xa8;let _0x26799d=_0x5319b9[_0x316c99];return _0x26799d;},a44_0x316c(_0x372b58,_0x115c23);}import{colorizeJSON,colorizeJSONCompact}from'../utils/colors.js';import{extractModelAlias,resolveModelAlias}from'../utils/model-aliases.js';import{SessionCache}from'./session-cache.js';function formatConversationHistory(_0x23be08){const _0xfe781=a44_0x316c;if(!_0x23be08||!Array[_0xfe781(0xbe)](_0x23be08))return'';return _0x23be08['filter'](_0x4e014a=>_0x4e014a!=null)[_0xfe781(0xfb)](_0x3bdcd4=>{const _0x19cedb=_0xfe781,_0x1911d8=_0x3bdcd4[_0x19cedb(0xcd)]!=null&&Array['isArray'](_0x3bdcd4[_0x19cedb(0xcd)])?_0x3bdcd4['content'][_0x19cedb(0x128)](_0x10c567=>_0x10c567&&_0x10c567[_0x19cedb(0xd8)]===_0x19cedb(0x13b))['map'](_0x46ca87=>_0x46ca87[_0x19cedb(0x13b)])[_0x19cedb(0x16b)]('\x0a'):_0x3bdcd4[_0x19cedb(0xcd)]||'',_0x1ce11f=_0x3bdcd4['role']===_0x19cedb(0x13a)?_0x19cedb(0x168):_0x19cedb(0xa9);return _0x1ce11f+':\x20'+_0x1911d8;})[_0xfe781(0x16b)]('\x0a\x0a');}function calculateContextSignature(_0x439d70,_0x5415a7,_0x2cfff4,_0x3e4ef1){const _0x16c134=a44_0x316c,_0x42aaa9=extractModelAlias(_0x439d70),_0x3276f7=resolveModelAlias(_0x42aaa9),_0x1dc485=[..._0x5415a7||[]]['sort'](),_0x330364=(_0x2cfff4||[])[_0x16c134(0x128)](_0x4beb7f=>_0x4beb7f!=null)[_0x16c134(0xfb)](_0x198e97=>({'name':_0x198e97[_0x16c134(0xaf)],'params':Object['keys'](_0x198e97[_0x16c134(0xd2)]?.[_0x16c134(0x133)]||{})[_0x16c134(0x16a)](),'required':(_0x198e97[_0x16c134(0xd2)]?.[_0x16c134(0x12d)]||[])['sort']()}))[_0x16c134(0x16a)]((_0x31a610,_0xe35e04)=>_0x31a610['name']['localeCompare'](_0xe35e04[_0x16c134(0xaf)])),_0x34810b=JSON[_0x16c134(0xc5)]({'model':_0x3276f7,'prompts':_0x1dc485,'tools':_0x330364,'reasoning':_0x3e4ef1});return createHash(_0x16c134(0x138))[_0x16c134(0x107)](_0x34810b)[_0x16c134(0x13f)](_0x16c134(0xf0))[_0x16c134(0xfe)](0x0,0x10);}function clearChatState(_0x551b65){const _0x5975d7=a44_0x316c;_0x551b65[_0x5975d7(0xdc)]='',_0x551b65['embeddedSystemPrompts'][_0x5975d7(0x142)](),_0x551b65[_0x5975d7(0x124)][_0x5975d7(0x142)]();}function mapBudgetTokensToReasoningEffort(_0x4909b1,_0x1114ae){const _0x3f82b5=a44_0x316c;if(_0x1114ae!==_0x3f82b5(0x143))return 0x0;if(!_0x4909b1||_0x4909b1===0x0)return 0x0;if(_0x4909b1<=0x400)return 0x1;if(_0x4909b1<=0x800)return 0x2;if(_0x4909b1<=0x1000)return 0x3;return 0x4;}const MAX_CHATS_PER_SESSION=0xa,CACHE_EXPIRATION_MS=0xa*0x3c*0x3e8,CLEANUP_INTERVAL_MS=0x3c*0x3e8;export class ProxyServer{[a44_0x51d0ba(0x109)];[a44_0x51d0ba(0x12a)];[a44_0x51d0ba(0xdb)];[a44_0x51d0ba(0xd4)];['cleanupInterval'];[a44_0x51d0ba(0xd1)];constructor(_0x21a421){const _0x186b29=a44_0x51d0ba;this[_0x186b29(0xd1)]=_0x21a421['logger'],this['config']=_0x21a421,this[_0x186b29(0x12a)]=new SessionCache({'maxChatsPerSession':MAX_CHATS_PER_SESSION,'cacheExpirationMs':CACHE_EXPIRATION_MS}),this[_0x186b29(0xdb)]=new Map(),this['server']=a44_0x434c8b({'logger':![],'bodyLimit':0x40*0x400*0x400}),this['setupMiddleware'](),this[_0x186b29(0xb1)]();}async[a44_0x51d0ba(0xc7)](_0xe4f98c,_0x5044c1=0x0){const _0x20632f=a44_0x51d0ba,_0x597ff9=extractModelAlias(_0xe4f98c),_0x48c00c=resolveModelAlias(_0x597ff9),_0x4feb87=_0x48c00c+'_'+_0x5044c1;let _0x4f419c=this[_0x20632f(0xdb)]['get'](_0x4feb87);if(!_0x4f419c){this[_0x20632f(0xd1)][_0x20632f(0x169)](_0x20632f(0x152)+_0xe4f98c+_0x20632f(0x10a)+_0x597ff9+_0x20632f(0x10a)+_0x48c00c),this[_0x20632f(0xd1)][_0x20632f(0x169)]('Creating/looking\x20up\x20agent\x20for:\x20'+_0x48c00c+'\x20(reasoning:\x20'+_0x5044c1+')');const _0x3a7618=await this['config'][_0x20632f(0x10f)][_0x20632f(0xc0)][_0x20632f(0xb9)](_0x48c00c,_0x5044c1);_0x4f419c=_0x3a7618['id'],this[_0x20632f(0xdb)][_0x20632f(0xcf)](_0x4feb87,_0x4f419c),this[_0x20632f(0xd1)]['debug']('Agent\x20cached:\x20'+_0x4feb87+_0x20632f(0x10a)+_0x4f419c+'\x20('+_0x3a7618[_0x20632f(0x14a)][_0x20632f(0xaf)]+')');}return _0x4f419c;}[a44_0x51d0ba(0x13e)](){const _0xb53a18=a44_0x51d0ba;this[_0xb53a18(0x12a)][_0xb53a18(0x13e)]();}['setupMiddleware'](){const _0x45d194=a44_0x51d0ba;this[_0x45d194(0x109)][_0x45d194(0xfa)](a44_0x48a9f6,{'origin':!![],'methods':[_0x45d194(0xd9),_0x45d194(0xc3),'OPTIONS'],'allowedHeaders':[_0x45d194(0x14b),_0x45d194(0x155),_0x45d194(0x113),_0x45d194(0x102)]}),this['server'][_0x45d194(0x153)]((_0x350cde,_0x26f74e,_0x1228d7)=>{const _0x19173b=_0x45d194,_0x361795=_0x350cde instanceof Error?_0x350cde[_0x19173b(0x150)]:_0x19173b(0x159);this['logger'][_0x19173b(0x103)]('[PROXY\x20ERROR]\x20Unhandled\x20error\x20in\x20'+_0x26f74e['method']+'\x20'+_0x26f74e[_0x19173b(0x141)]+':',_0x350cde),_0x1228d7[_0x19173b(0x126)](0x1f4)['send']({'type':_0x19173b(0x103),'error':{'type':_0x19173b(0x13c),'message':_0x361795}});});}[a44_0x51d0ba(0x15f)](_0x32eeb4,_0x2d5844,_0x29c941){const _0x279a4b=a44_0x51d0ba,_0x53c741=_0x2d5844 instanceof Error?_0x2d5844[_0x279a4b(0x150)]:_0x279a4b(0x159);this[_0x279a4b(0xd1)][_0x279a4b(0x103)]('[PROXY\x20ERROR]\x20Uncaught\x20error\x20in\x20'+_0x32eeb4+':',_0x2d5844),!_0x29c941[_0x279a4b(0xf1)]&&_0x29c941['code'](0x1f4)['send']({'type':_0x279a4b(0x103),'error':{'type':_0x279a4b(0x13c),'message':_0x53c741}});}[a44_0x51d0ba(0xb1)](){const _0x3dd807=a44_0x51d0ba;this[_0x3dd807(0x109)][_0x3dd807(0xe1)]('/health',async()=>{const _0x2f337f=_0x3dd807;return{'status':'ok','message':_0x2f337f(0x148)};}),this['server'][_0x3dd807(0x166)]('/v1/messages',async(_0x24a297,_0x3ba6c4)=>{const _0x5c7cdf=_0x3dd807;return this[_0x5c7cdf(0x167)](_0x24a297,_0x3ba6c4)[_0x5c7cdf(0xbf)](_0x125f49=>{const _0x52f3d9=_0x5c7cdf;this['handleRouteError'](_0x52f3d9(0x120),_0x125f49,_0x3ba6c4);});}),this[_0x3dd807(0x109)][_0x3dd807(0x166)]('/v1/messages/count_tokens',async(_0x2ab6cd,_0x5bd5f6)=>{const _0x41da20=_0x3dd807;return this[_0x41da20(0xc4)](_0x2ab6cd)[_0x41da20(0xbf)](_0x22df5d=>{const _0x20e372=_0x41da20;this[_0x20e372(0x15f)](_0x20e372(0x12f),_0x22df5d,_0x5bd5f6);});});}async[a44_0x51d0ba(0x167)](_0x388a4e,_0x5b2401){const _0x210bde=a44_0x51d0ba,_0x24131a=_0x388a4e[_0x210bde(0x156)];if(!_0x24131a[_0x210bde(0x101)]||!Array[_0x210bde(0xbe)](_0x24131a['messages'])||_0x24131a['messages'][_0x210bde(0xf2)]===0x0){this[_0x210bde(0xd1)]['error'](_0x210bde(0x146)),_0x5b2401[_0x210bde(0x126)](0x190)[_0x210bde(0xb5)]({'type':'error','error':{'type':_0x210bde(0x106),'message':_0x210bde(0xcc)}});return;}if(_0x24131a[_0x210bde(0x15b)]&&!Array[_0x210bde(0xbe)](_0x24131a['tools'])){this['logger'][_0x210bde(0x103)](_0x210bde(0xff)),_0x5b2401[_0x210bde(0x126)](0x190)[_0x210bde(0xb5)]({'type':_0x210bde(0x103),'error':{'type':_0x210bde(0x106),'message':_0x210bde(0xb0)}});return;}const _0x5ba97e=_0x24131a[_0x210bde(0x101)]?.['length']??0x0,_0x670187=_0x24131a[_0x210bde(0xf4)]||_0x210bde(0xd6);this['logger'][_0x210bde(0xee)](_0x388a4e[_0x210bde(0x111)]+'\x20'+_0x388a4e['url']+':\x20messages='+_0x5ba97e+_0x210bde(0x127)+_0x670187),this[_0x210bde(0xd1)][_0x210bde(0x169)](_0x210bde(0xb6)+colorizeJSONCompact(_0x388a4e[_0x210bde(0xed)]));this[_0x210bde(0xd1)]['trace']&&this[_0x210bde(0xd1)]['trace'](colorizeJSON(_0x24131a,{'color':!![]}));const _0xd9ed94=_0x24131a[_0x210bde(0xd0)]?.[_0x210bde(0xb4)]||_0x210bde(0x11d),_0x2a1672=this[_0x210bde(0xd4)][_0x210bde(0xe9)];if(!_0x2a1672){this[_0x210bde(0xd1)][_0x210bde(0x103)]('[PROXY\x20ERROR]\x20Configuration\x20error:\x20Project\x20ID\x20must\x20be\x20configured'),_0x5b2401[_0x210bde(0x126)](0x1f4)[_0x210bde(0xb5)]({'type':_0x210bde(0x103),'error':{'type':_0x210bde(0x13c),'message':_0x210bde(0xda)}});return;}const _0x40f7df=this[_0x210bde(0x12a)][_0x210bde(0x164)](_0xd9ed94,_0x2a1672),_0x441d4c=[];if(_0x24131a[_0x210bde(0x10d)]){if(typeof _0x24131a[_0x210bde(0x10d)]===_0x210bde(0xb2))_0x441d4c[_0x210bde(0xef)](_0x24131a[_0x210bde(0x10d)]);else{if(Array[_0x210bde(0xbe)](_0x24131a[_0x210bde(0x10d)]))for(const _0x19b2b6 of _0x24131a['system']){_0x19b2b6[_0x210bde(0xd8)]===_0x210bde(0x13b)&&_0x19b2b6['text']&&_0x441d4c[_0x210bde(0xef)](_0x19b2b6[_0x210bde(0x13b)]);}}}const _0x457ce1=_0x24131a['tools']||[],_0x246c40=_0x24131a[_0x210bde(0x15d)]?.[_0x210bde(0xbd)],_0x267d75=mapBudgetTokensToReasoningEffort(_0x246c40,this['config'][_0x210bde(0x14e)]),_0x55654f=calculateContextSignature(_0x24131a[_0x210bde(0xf4)],_0x441d4c,_0x457ce1,_0x267d75);let _0x2e6468=_0x40f7df[_0x210bde(0x117)][_0x210bde(0xe1)](_0x55654f);const _0xe406b5=!_0x2e6468;if(!_0x2e6468){const _0x34d524=await this['getAgentForModel'](_0x24131a[_0x210bde(0xf4)],_0x267d75);_0x2e6468={'chatId':'','agentId':_0x34d524,'contextSignature':_0x55654f,'embeddedSystemPrompts':new Set(),'embeddedToolsByName':new Map(),'messageHistory':[],'lastUsedAt':Date[_0x210bde(0xaa)]()},_0x40f7df[_0x210bde(0x117)]['set'](_0x55654f,_0x2e6468);if(_0x40f7df[_0x210bde(0x117)][_0x210bde(0x130)]>MAX_CHATS_PER_SESSION){let _0x276032=null,_0x1899bb=Date[_0x210bde(0xaa)]();for(const [_0x242f3f,_0x9c8ec0]of _0x40f7df[_0x210bde(0x117)]){_0x9c8ec0[_0x210bde(0xad)]<_0x1899bb&&(_0x1899bb=_0x9c8ec0['lastUsedAt'],_0x276032=_0x242f3f);}_0x276032&&(_0x40f7df[_0x210bde(0x117)]['delete'](_0x276032),this[_0x210bde(0xd1)][_0x210bde(0x169)](_0x210bde(0xf8)+_0x276032+_0x210bde(0x115)+MAX_CHATS_PER_SESSION+_0x210bde(0xf9)));}}else _0x2e6468[_0x210bde(0xad)]=Date[_0x210bde(0xaa)]();if(!_0x2e6468[_0x210bde(0xdc)]){if(_0x2e6468['creating']&&_0x2e6468[_0x210bde(0x139)]){this[_0x210bde(0xd1)][_0x210bde(0x169)](_0x210bde(0xe6)+_0x55654f);try{_0x2e6468[_0x210bde(0xdc)]=await _0x2e6468['createPromise'];}catch(_0x1a3fda){this[_0x210bde(0xd1)][_0x210bde(0x103)](_0x210bde(0x13d),_0x1a3fda);}}else{if(!_0x2e6468[_0x210bde(0xbc)]){_0x2e6468[_0x210bde(0xbc)]=!![],_0x2e6468[_0x210bde(0x139)]=((async()=>{const _0x364090=_0x210bde;try{const _0x2994da=await this['config'][_0x364090(0x10f)]['llm']['startChat'](_0x2e6468[_0x364090(0x15a)]);return this[_0x364090(0xd1)]['info']('['+_0x2994da['id']+_0x364090(0x11e)+_0x24131a[_0x364090(0xf4)]+_0x364090(0xfc)+_0x55654f),_0x2994da['id'];}catch(_0x5d92e9){this[_0x364090(0xd1)][_0x364090(0x103)](_0x364090(0x12e),_0x5d92e9);throw _0x5d92e9;}finally{_0x2e6468['creating']=![],_0x2e6468[_0x364090(0x139)]=undefined;}})());try{_0x2e6468[_0x210bde(0xdc)]=await _0x2e6468[_0x210bde(0x139)];}catch{}}}}const _0x638090=_0x441d4c[_0x210bde(0x128)](_0x171d2f=>!_0x2e6468[_0x210bde(0x132)][_0x210bde(0xbb)](_0x171d2f)),_0x8673fb=_0x457ce1[_0x210bde(0x128)](_0x214231=>!_0x2e6468['embeddedToolsByName'][_0x210bde(0xbb)](_0x214231['name']));this['logger']['debug']('[session:\x20'+_0xd9ed94+_0x210bde(0x10c)+_0x24131a[_0x210bde(0xf4)]+_0x210bde(0x157)+_0x55654f+_0x210bde(0xd3)+_0xe406b5),this[_0x210bde(0xd1)][_0x210bde(0x169)]('Chat\x20ID:\x20'+_0x2e6468[_0x210bde(0xdc)]),this[_0x210bde(0xd1)][_0x210bde(0x169)](_0x210bde(0x110)+_0x441d4c[_0x210bde(0xf2)]+_0x210bde(0x137)+_0x457ce1[_0x210bde(0xf2)]),this[_0x210bde(0xd1)]['debug'](_0x210bde(0x12b)+_0x2e6468[_0x210bde(0x132)]['size']+_0x210bde(0x137)+_0x2e6468['embeddedToolsByName'][_0x210bde(0x130)]),this[_0x210bde(0xd1)][_0x210bde(0x169)]('New\x20-\x20system\x20prompts:\x20'+_0x638090[_0x210bde(0xf2)]+',\x20tools:\x20'+_0x8673fb[_0x210bde(0xf2)]);_0x638090[_0x210bde(0xf2)]>0x0&&this[_0x210bde(0xd1)][_0x210bde(0x169)]('Added\x20system\x20prompt\x20previews:',_0x638090[_0x210bde(0xfb)](_0x6008f5=>_0x6008f5['substring'](0x0,0x32)+_0x210bde(0xeb))[_0x210bde(0x16b)](_0x210bde(0xb3)));_0x8673fb[_0x210bde(0xf2)]>0x0&&this[_0x210bde(0xd1)]['debug']('Added\x20tool\x20names:',_0x8673fb['map'](_0x37193d=>_0x37193d['name'])[_0x210bde(0x16b)](',\x20'));const _0x42129b=_0x2e6468[_0x210bde(0xc8)][_0x210bde(0xf2)],_0x190336=_0x24131a[_0x210bde(0x101)][_0x210bde(0xd7)](_0x42129b);let _0x2a7dab=_0x190336[_0x210bde(0x128)](_0x376b69=>_0x376b69[_0x210bde(0xa8)]===_0x210bde(0x13a))[_0x210bde(0x131)]();if(!_0x2a7dab){_0x2a7dab=_0x24131a['messages']['filter'](_0x1c2117=>_0x1c2117[_0x210bde(0xa8)]===_0x210bde(0x13a))[_0x210bde(0x131)]();if(!_0x2a7dab){this[_0x210bde(0xd1)][_0x210bde(0x103)](_0x210bde(0x134)),_0x5b2401[_0x210bde(0x126)](0x190)[_0x210bde(0xb5)]({'type':_0x210bde(0x103),'error':{'type':_0x210bde(0x106),'message':_0x210bde(0x122)}});return;}}let _0x120f46;if(typeof _0x2a7dab['content']===_0x210bde(0xb2))_0x120f46=_0x2a7dab[_0x210bde(0xcd)];else{if(_0x2a7dab['content']!=null&&Array[_0x210bde(0xbe)](_0x2a7dab['content']))_0x120f46=_0x2a7dab[_0x210bde(0xcd)][_0x210bde(0x128)](_0x5669bf=>_0x5669bf&&_0x5669bf[_0x210bde(0xd8)]===_0x210bde(0x13b)&&_0x5669bf[_0x210bde(0x13b)])[_0x210bde(0xfb)](_0x334a16=>_0x334a16[_0x210bde(0x13b)])[_0x210bde(0x16b)]('\x0a');else{this[_0x210bde(0xd1)][_0x210bde(0x103)](_0x210bde(0x145),typeof _0x2a7dab[_0x210bde(0xcd)],_0x2a7dab['content']),_0x5b2401[_0x210bde(0x126)](0x190)[_0x210bde(0xb5)]({'type':_0x210bde(0x103),'error':{'type':_0x210bde(0x106),'message':_0x210bde(0xd5)}});return;}}const _0x2f94e2=()=>{const _0x43d79d=_0x210bde,_0x452ba1=[];_0x441d4c[_0x43d79d(0xf2)]>0x0&&_0x452ba1['push'](_0x441d4c[_0x43d79d(0x16b)]('\x0a\x0a'));_0x457ce1[_0x43d79d(0xf2)]>0x0&&_0x452ba1[_0x43d79d(0xef)](generateToolPrompt(_0x457ce1));if(_0x24131a['messages']&&_0x24131a[_0x43d79d(0x101)][_0x43d79d(0xf2)]>0x1){const _0x440e64=formatConversationHistory(_0x24131a[_0x43d79d(0x101)]);_0x440e64&&_0x452ba1[_0x43d79d(0xef)]('[Previous\x20conversation]\x0a\x0a<conversation>\x0a'+_0x440e64+'\x0a</conversation>');}return _0x452ba1['push'](_0x43d79d(0xf7)+_0x120f46),_0x452ba1[_0x43d79d(0x16b)]('\x0a---\x0a\x0a');};let _0x19c8c0;if(_0xe406b5){this['logger'][_0x210bde(0xee)]('['+_0x2e6468[_0x210bde(0xdc)]+_0x210bde(0x129)+_0x24131a['model']+_0x210bde(0x163)+_0x441d4c[_0x210bde(0xf2)]+_0x210bde(0xc6)+_0x457ce1[_0x210bde(0xf2)]+_0x210bde(0x125)+_0x457ce1[_0x210bde(0xfb)](_0x50ca7=>_0x50ca7[_0x210bde(0xaf)])[_0x210bde(0x16b)](',\x20')+']'),_0x19c8c0=_0x2f94e2();for(const _0x46742c of _0x441d4c){_0x2e6468[_0x210bde(0x132)][_0x210bde(0x108)](_0x46742c);}for(const _0x1416a9 of _0x457ce1){_0x2e6468[_0x210bde(0x124)][_0x210bde(0xcf)](_0x1416a9[_0x210bde(0xaf)],_0x1416a9);}}else{const _0x23ab55=[];_0x638090[_0x210bde(0xf2)]>0x0&&(_0x23ab55[_0x210bde(0xef)](_0x638090[_0x210bde(0x16b)]('\x0a\x0a')),this['logger']['debug'](_0x210bde(0xec),_0x638090[_0x210bde(0xf2)],_0x210bde(0xea)));if(_0x8673fb['length']>0x0)try{_0x23ab55[_0x210bde(0xef)](generateToolPrompt(_0x8673fb)),this[_0x210bde(0xd1)][_0x210bde(0x169)](_0x210bde(0xec),_0x8673fb[_0x210bde(0xf2)],'new\x20tool(s)');}catch(_0x29db90){this['logger'][_0x210bde(0x103)](_0x210bde(0x147),_0x29db90);}try{const _0x46ed76=extractToolResults(_0x190336);_0x46ed76&&(_0x23ab55[_0x210bde(0xef)](_0x46ed76),this['logger'][_0x210bde(0x169)](_0x210bde(0xac)));}catch(_0xa0917e){this[_0x210bde(0xd1)]['error'](_0x210bde(0xc9),_0xa0917e);}_0x23ab55[_0x210bde(0xef)](_0x120f46),_0x19c8c0=_0x23ab55[_0x210bde(0xf2)]>0x1?_0x23ab55[_0x210bde(0x16b)](_0x210bde(0xcb)):_0x120f46;for(const _0x3aa361 of _0x638090){_0x2e6468[_0x210bde(0x132)][_0x210bde(0x108)](_0x3aa361);}for(const _0x31710c of _0x8673fb){_0x2e6468[_0x210bde(0x124)][_0x210bde(0xcf)](_0x31710c[_0x210bde(0xaf)],_0x31710c);}}(!_0x19c8c0||!_0x19c8c0[_0x210bde(0xba)]())&&(this[_0x210bde(0xd1)][_0x210bde(0xb7)](_0x210bde(0xe5)),this[_0x210bde(0xd1)][_0x210bde(0xb7)](_0x210bde(0x10e),{'isNewContext':_0xe406b5,'userMessageLength':_0x120f46?.[_0x210bde(0xf2)]||0x0,'systemPromptsCount':_0x441d4c[_0x210bde(0xf2)],'toolsCount':_0x457ce1[_0x210bde(0xf2)],'messagesCount':_0x24131a['messages']?.['length']||0x0,'newMessagesCount':_0x190336[_0x210bde(0xf2)]}),clearChatState(_0x2e6468),_0x19c8c0=_0x2f94e2(),(!_0x19c8c0||!_0x19c8c0[_0x210bde(0xba)]())&&(this[_0x210bde(0xd1)][_0x210bde(0x103)](_0x210bde(0x161)),this[_0x210bde(0xd1)][_0x210bde(0x103)]('Debug\x20info:',{'systemPromptsCount':_0x441d4c[_0x210bde(0xf2)],'toolsCount':_0x457ce1['length'],'messagesCount':_0x24131a[_0x210bde(0x101)]?.[_0x210bde(0xf2)]||0x0,'userMessageLength':_0x120f46?.['length']||0x0}),_0x19c8c0='continue'),this[_0x210bde(0xd1)][_0x210bde(0xee)](_0x210bde(0xf3),_0x19c8c0[_0x210bde(0xfe)](0x0,0x64)+_0x210bde(0xeb)));const _0x3c0b5d=_0x24131a[_0x210bde(0x15e)]!==![];if(_0x3c0b5d){_0x5b2401[_0x210bde(0x154)][_0x210bde(0xe0)](0xc8,{'Content-Type':_0x210bde(0x119),'Cache-Control':'no-cache','Connection':_0x210bde(0x158),'X-Accel-Buffering':'no'});const _0x3bee8b=generateMessageId();try{if(_0x2e6468[_0x210bde(0xdc)]){const _0x40ff0b=_0x19c8c0[_0x210bde(0xfe)](0x0,0x32)[_0x210bde(0xf6)](/\n/g,'\x20');this[_0x210bde(0xd1)]['info']('['+_0x2e6468['chatId']+']\x20Continue\x20chat\x20for\x20model\x20'+_0x24131a[_0x210bde(0xf4)]+_0x210bde(0xfc)+_0x55654f+',\x20'+_0x24131a[_0x210bde(0x101)]['length']+_0x210bde(0x112)+_0x441d4c[_0x210bde(0xf2)]+'\x20system\x20prompts,\x20'+_0x457ce1[_0x210bde(0xf2)]+_0x210bde(0xce)+_0x19c8c0['length']+_0x210bde(0xe3)+_0x40ff0b+_0x210bde(0x116));}const _0x2340ff=this[_0x210bde(0xd4)][_0x210bde(0x10f)]['llm'][_0x210bde(0x15c)](_0x19c8c0,{'chatId':_0x2e6468[_0x210bde(0xdc)]||undefined,'agentId':_0x2e6468['chatId']?undefined:_0x2e6468[_0x210bde(0x15a)]});if(!_0x2340ff){this[_0x210bde(0xd1)][_0x210bde(0x103)]('[PROXY\x20ERROR]\x20Chat\x20stream\x20is\x20undefined'),this[_0x210bde(0xd1)][_0x210bde(0x103)](_0x210bde(0x10e),JSON['stringify']({'chatId':_0x2e6468[_0x210bde(0xdc)],'agentId':_0x2e6468['agentId'],'model':_0x24131a[_0x210bde(0xf4)],'sessionId':_0xd9ed94,'contextSignature':_0x55654f})),_0x2e6468[_0x210bde(0xdc)]='',this[_0x210bde(0xd1)][_0x210bde(0xb7)](_0x210bde(0x11f));const _0x1376fc=formatAnthropicSSE({'type':_0x210bde(0x103),'error':{'type':_0x210bde(0x13c),'message':'Failed\x20to\x20initialize\x20chat\x20stream.\x20Please\x20try\x20again.'},'request_id':_0x3bee8b});_0x5b2401[_0x210bde(0x154)]['write'](_0x1376fc),_0x5b2401[_0x210bde(0x154)]['end']();return;}_0x2e6468[_0x210bde(0xc8)]=_0x24131a[_0x210bde(0x101)];const _0xfa6bd4=_0x2e6468;async function*_0x561eaa(_0x177ad4){const _0x4c9346=_0x210bde;for await(const _0x46070e of _0x177ad4){if(_0x46070e[_0x4c9346(0xd8)]===_0x4c9346(0xd0))_0x46070e[_0x4c9346(0xdf)][_0x4c9346(0xdc)]&&!_0xfa6bd4[_0x4c9346(0xdc)]&&(_0xfa6bd4['chatId']=_0x46070e[_0x4c9346(0xdf)][_0x4c9346(0xdc)]);else _0x46070e['type']===_0x4c9346(0x144)&&(yield _0x46070e['data']);}}const _0x4e060d=_0x561eaa(_0x2340ff),_0x3b9cee=estimateInputTokensFromRequest(_0x24131a),_0x197696=transformTDStreamToAnthropic(_0x4e060d,_0x3bee8b,_0x24131a[_0x210bde(0xf4)],this['logger'],_0x120f46,_0x3b9cee),_0x5d743f=_0x19c8c0[_0x210bde(0xf2)];let _0x45453c=0x0;for await(const _0x1f4c15 of _0x197696){const _0x13e6bc=formatAnthropicSSE(_0x1f4c15);_0x45453c++,this[_0x210bde(0xd1)][_0x210bde(0x169)](colorizeJSONCompact(_0x1f4c15,{'color':!![]})),_0x1f4c15[_0x210bde(0xd8)]===_0x210bde(0x103)&&_0x1f4c15[_0x210bde(0x103)][_0x210bde(0xd8)]===_0x210bde(0x160)&&(clearChatState(_0x2e6468),this[_0x210bde(0xd1)][_0x210bde(0xb7)](_0x210bde(0x14f)+_0x1f4c15['error'][_0x210bde(0x150)]+_0x210bde(0x10b)+_0x5d743f+'\x20chars.\x20Cleared\x20chat\x20state\x20for\x20session\x20'+_0xd9ed94+_0x210bde(0x100)+_0x55654f)),_0x5b2401[_0x210bde(0x154)][_0x210bde(0x14c)](_0x13e6bc);}this[_0x210bde(0xd1)][_0x210bde(0x169)](_0x210bde(0x149)+_0x45453c+_0x210bde(0xe2)),_0x5b2401[_0x210bde(0x154)][_0x210bde(0xe7)]();}catch(_0x43e420){const _0x1e8e14=_0x43e420 instanceof Error?_0x43e420[_0x210bde(0x150)]:'Unknown\x20error';this[_0x210bde(0xd1)][_0x210bde(0x103)](_0x210bde(0xb8),_0x43e420),this['logger'][_0x210bde(0x103)](_0x210bde(0x10e),JSON[_0x210bde(0xc5)]({'chatId':_0x2e6468[_0x210bde(0xdc)],'agentId':_0x2e6468[_0x210bde(0x15a)],'model':_0x24131a['model'],'sessionId':_0xd9ed94,'contextSignature':_0x55654f})),_0x2e6468['chatId']='',this[_0x210bde(0xd1)][_0x210bde(0xb7)](_0x210bde(0xde));const _0x2b7e95=formatAnthropicSSE({'type':_0x210bde(0x103),'error':{'type':_0x210bde(0x13c),'message':_0x1e8e14},'request_id':_0x3bee8b});_0x5b2401[_0x210bde(0x154)][_0x210bde(0x14c)](_0x2b7e95),_0x5b2401[_0x210bde(0x154)][_0x210bde(0xe7)]();}}else this[_0x210bde(0xd1)][_0x210bde(0x103)](_0x210bde(0xc2)),_0x5b2401[_0x210bde(0x126)](0x1f5)['send']({'type':'error','error':{'type':_0x210bde(0x151),'message':_0x210bde(0x14d)}});}async[a44_0x51d0ba(0xc4)](_0xa90e6){const _0x4cfb84=a44_0x51d0ba,_0x45163b=_0xa90e6[_0x4cfb84(0x156)],_0x3f34f1=estimateInputTokensFromRequest(_0x45163b);return this[_0x4cfb84(0xd1)]['info'](_0xa90e6[_0x4cfb84(0x111)]+'\x20'+_0xa90e6[_0x4cfb84(0x141)]+_0x4cfb84(0x162)+_0x3f34f1),{'input_tokens':_0x3f34f1};}async[a44_0x51d0ba(0xc1)](){const _0x201a84=a44_0x51d0ba;try{await this[_0x201a84(0x109)][_0x201a84(0xe4)]({'port':this[_0x201a84(0xd4)]['port'],'host':_0x201a84(0x11a)}),this[_0x201a84(0xd1)][_0x201a84(0xee)](_0x201a84(0x105)+this[_0x201a84(0xd4)][_0x201a84(0x140)]),this['cleanupInterval']=setInterval(()=>{const _0x2984db=_0x201a84;this[_0x2984db(0x13e)]();},CLEANUP_INTERVAL_MS),this[_0x201a84(0xd1)][_0x201a84(0x169)](_0x201a84(0xab)+CLEANUP_INTERVAL_MS/0x3e8+_0x201a84(0x136)+CACHE_EXPIRATION_MS/0x3e8+'s)');}catch(_0x4ce8cb){const _0x1d2651=_0x4ce8cb instanceof Error?_0x4ce8cb['message']:_0x201a84(0x159);throw new Error('Failed\x20to\x20start\x20proxy\x20server:\x20'+_0x1d2651);}}async[a44_0x51d0ba(0x121)](){const _0x2e6a21=a44_0x51d0ba;this['cleanupInterval']&&(clearInterval(this[_0x2e6a21(0xf5)]),this['cleanupInterval']=undefined),await this['server'][_0x2e6a21(0x165)]();}[a44_0x51d0ba(0x11c)](){const _0x2e8dac=a44_0x51d0ba,_0x180b0c=this['server']['server'][_0x2e8dac(0x114)]();if(typeof _0x180b0c==='string')return _0x180b0c;if(_0x180b0c)return _0x2e8dac(0xfd)+_0x180b0c['address']+':'+_0x180b0c[_0x2e8dac(0x140)];return _0x2e8dac(0xdd)+this[_0x2e8dac(0xd4)][_0x2e8dac(0x140)];}}
1
+ const a44_0xa20526=a44_0x56cb;(function(_0x470d6f,_0x55020a){const _0x31f4d7=a44_0x56cb,_0x4d52ec=_0x470d6f();while(!![]){try{const _0x58af65=parseInt(_0x31f4d7(0x18b))/0x1*(parseInt(_0x31f4d7(0x207))/0x2)+parseInt(_0x31f4d7(0x19c))/0x3*(-parseInt(_0x31f4d7(0x21d))/0x4)+-parseInt(_0x31f4d7(0x1f2))/0x5*(parseInt(_0x31f4d7(0x1e5))/0x6)+parseInt(_0x31f4d7(0x1c1))/0x7*(parseInt(_0x31f4d7(0x161))/0x8)+-parseInt(_0x31f4d7(0x16e))/0x9+parseInt(_0x31f4d7(0x1be))/0xa+-parseInt(_0x31f4d7(0x20f))/0xb;if(_0x58af65===_0x55020a)break;else _0x4d52ec['push'](_0x4d52ec['shift']());}catch(_0x4a867a){_0x4d52ec['push'](_0x4d52ec['shift']());}}}(a44_0x383f,0x35eaf));import a44_0x2ac25e from'fastify';function a44_0x383f(){const _0x5e9bc2=['getOrCreateDefaultAgent','clear',']\x20model:\x20','Failed\x20to\x20extract\x20tool\x20results:','chatId','substring','embeddedSystemPrompts','metadata','getAgentForModel','port','[Previous\x20conversation]\x0a\x0a<conversation>\x0a','push','[PROXY\x20ERROR]\x20Non-streaming\x20responses\x20are\x20not\x20yet\x20supported','\x20|\x20','[PROXY\x20ERROR]\x20Unhandled\x20error\x20in\x20','data','System\x20prompts:\x20','3838150mhAmoU','raw','Reset\x20chat\x20ID\x20to\x20recover\x20on\x20next\x20request','9541VZNySg','agentId','string','register','map','pop','end','getOrCreateSession','content','name','Embedding','Assistant','request_too_large','invalid_request_error','catch','model',',\x20model=','headers','sent',',\x20\x22','isArray','\x20->\x20','\x20Input\x20size:\x20','filter','site',',\x20tools=','Final\x20message\x20is\x20empty\x20after\x20construction\x20-\x20starting\x20fresh\x20conversation','/v1/messages/count_tokens','lastUsedAt','message','address','budget_tokens','messages',',\x20context:\x20','Embedded\x20in\x20chat\x20-\x20system\x20prompts:\x20','Added\x20system\x20prompt\x20previews:','12FTiZDU','text/event-stream','Failed\x20to\x20generate\x20tool\x20prompt:','\x20messages,\x20','url','Waiting\x20for\x20concurrent\x20chat\x20creation\x20for\x20context:\x20','text','cleanupInterval','error','handleCountTokens','writeHead','no-cache',']\x20Created\x20new\x20chat\x20for\x20model\x20','284390PNHnrR',',\x20is\x20new\x20context:\x20','header:\x20','sort','No\x20user\x20message\x20found\x20in\x20request','Including\x20tool\x20results','post','digest','info','body','trace',',\x20context=','hex','Unknown\x20error',']\x20Building\x20a\x20new\x20context\x20for\x20model\x20','stringify','Reset\x20chat\x20state\x20to\x20recover\x20on\x20next\x20request','GET','\x20chars.\x20Cleared\x20chat\x20state\x20for\x20session\x20','event','update','665090FBJjik','\x20tools,\x20message_size=','chats','projectId','embeddedToolsByName','now','\x0a---\x0a\x0a','startChat','648285BdoWxq','dev-us01',',\x20system_prompts=','\x20(reasoning:\x20','Context:','keys','[CONTEXT\x20LENGTH\x20ERROR]\x20','Stream\x20complete.\x20Sent\x20','write','start','replace','getAddress','Failed\x20to\x20create\x20chat,\x20will\x20fall\x20back\x20to\x20lazy\x20creation:','get','44940plygPV','api_error','attributes',')\x20to\x20stay\x20under\x20',',\x20tools:\x20','stream','[PROXY\x20ERROR]\x20Streaming\x20error:','1848EeOtUN','input_schema','New\x20-\x20system\x20prompts:\x20','user','slice','Agent\x20cached:\x20',',\x20tool_names=[','localeCompare','agentCache','x-api-key','[PROXY\x20ERROR]\x20Uncaught\x20error\x20in\x20','sha256','join','3110085xdjfaj','[PROXY\x20ERROR]\x20Validation\x20failed:\x20message.content\x20must\x20be\x20a\x20string\x20or\x20array,\x20got:','sessionCache','server','Debug\x20info:','setupRoutes','role',']\x20Continue\x20chat\x20for\x20model\x20','Started\x20cache\x20cleanup\x20interval\x20(runs\x20every\x20','trim','Model\x20normalization:\x20','Project\x20ID\x20must\x20be\x20configured','Creating/looking\x20up\x20agent\x20for:\x20','Proxy\x20server\x20started\x20at\x20localhost:','length',':\x20messages=',':\x20estimated\x20input_tokens=','tools','cleanupExpiredChats','Chat\x20ID:\x20','messageHistory','delete','Concurrent\x20chat\x20creation\x20failed,\x20will\x20fall\x20back\x20to\x20lazy\x20creation:','/v1/messages','messages\x20array\x20is\x20required\x20and\x20must\x20not\x20be\x20empty','Failed\x20to\x20initialize\x20chat\x20stream.\x20Please\x20try\x20again.','\x20SSE\x20events.','handleMessages','warn','1CVxMXF','chat','Authorization','/health','config','type','setupMiddleware','logger','system','tools\x20must\x20be\x20an\x20array\x20if\x20provided','[PROXY\x20ERROR]\x20Chat\x20stream\x20is\x20undefined','[PROXY\x20ERROR]\x20Configuration\x20error:\x20Project\x20ID\x20must\x20be\x20configured','unknown','tdx','...\x22','has','code','78sKCBmJ','send','createPromise','add','OPTIONS',',\x20context\x20signature:\x20','debug','setErrorHandler','handleRouteError','default','set','llm','Content-Type','http://localhost:','continue','method','[Current\x20message]\x0a\x0a'];a44_0x383f=function(){return _0x5e9bc2;};return a44_0x383f();}import a44_0x1929df from'@fastify/cors';function a44_0x56cb(_0x1ce3d9,_0x25ff93){const _0x383fdb=a44_0x383f();return a44_0x56cb=function(_0x56cbb0,_0xd83431){_0x56cbb0=_0x56cbb0-0x160;let _0x25defc=_0x383fdb[_0x56cbb0];return _0x25defc;},a44_0x56cb(_0x1ce3d9,_0x25ff93);}import{createHash}from'crypto';import{transformTDStreamToAnthropic,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(_0x49bd40){const _0x367525=a44_0x56cb;if(!_0x49bd40||!Array['isArray'](_0x49bd40))return'';return _0x49bd40[_0x367525(0x1d8)](_0x5ab6e8=>_0x5ab6e8!=null)[_0x367525(0x1c5)](_0x63ac23=>{const _0x349f9e=_0x367525,_0x178b87=_0x63ac23[_0x349f9e(0x1c9)]!=null&&Array[_0x349f9e(0x1d5)](_0x63ac23[_0x349f9e(0x1c9)])?_0x63ac23[_0x349f9e(0x1c9)][_0x349f9e(0x1d8)](_0x3649e3=>_0x3649e3&&_0x3649e3[_0x349f9e(0x190)]===_0x349f9e(0x1eb))[_0x349f9e(0x1c5)](_0x1aeb46=>_0x1aeb46[_0x349f9e(0x1eb)])[_0x349f9e(0x16d)]('\x0a'):_0x63ac23['content']||'',_0x9687a0=_0x63ac23[_0x349f9e(0x174)]===_0x349f9e(0x164)?'User':_0x349f9e(0x1cc);return _0x9687a0+':\x20'+_0x178b87;})[_0x367525(0x16d)]('\x0a\x0a');}function calculateContextSignature(_0x30ec68,_0x2cf68e,_0x25bc99,_0x4afd8e){const _0x169a62=a44_0x56cb,_0x3f4bf7=extractModelAlias(_0x30ec68),_0x53faf8=resolveModelAlias(_0x3f4bf7),_0x154e89=[..._0x2cf68e||[]][_0x169a62(0x1f5)](),_0x3569e1=(_0x25bc99||[])['filter'](_0x22acd6=>_0x22acd6!=null)[_0x169a62(0x1c5)](_0x6b92ff=>({'name':_0x6b92ff[_0x169a62(0x1ca)],'params':Object[_0x169a62(0x214)](_0x6b92ff[_0x169a62(0x162)]?.['properties']||{})[_0x169a62(0x1f5)](),'required':(_0x6b92ff[_0x169a62(0x162)]?.['required']||[])['sort']()}))[_0x169a62(0x1f5)]((_0x44c518,_0x384380)=>_0x44c518[_0x169a62(0x1ca)][_0x169a62(0x168)](_0x384380['name'])),_0x3b67eb=JSON[_0x169a62(0x201)]({'model':_0x53faf8,'prompts':_0x154e89,'tools':_0x3569e1,'reasoning':_0x4afd8e});return createHash(_0x169a62(0x16c))[_0x169a62(0x206)](_0x3b67eb)[_0x169a62(0x1f9)](_0x169a62(0x1fe))['substring'](0x0,0x10);}function clearChatState(_0x516af1){const _0x687c59=a44_0x56cb;_0x516af1[_0x687c59(0x1b1)]='',_0x516af1[_0x687c59(0x1b3)][_0x687c59(0x1ae)](),_0x516af1[_0x687c59(0x20b)][_0x687c59(0x1ae)]();}function mapBudgetTokensToReasoningEffort(_0x25a488,_0x22e693){const _0x207202=a44_0x56cb;if(_0x22e693!==_0x207202(0x210))return 0x0;if(!_0x25a488||_0x25a488===0x0)return 0x0;if(_0x25a488<=0x400)return 0x1;if(_0x25a488<=0x800)return 0x2;if(_0x25a488<=0x1000)return 0x3;return 0x4;}const MAX_CHATS_PER_SESSION=0xa,CACHE_EXPIRATION_MS=0xa*0x3c*0x3e8,CLEANUP_INTERVAL_MS=0x3c*0x3e8;export class ProxyServer{[a44_0xa20526(0x171)];[a44_0xa20526(0x170)];[a44_0xa20526(0x169)];[a44_0xa20526(0x18f)];['cleanupInterval'];['logger'];constructor(_0x36ac4c){const _0x357776=a44_0xa20526;this[_0x357776(0x192)]=_0x36ac4c[_0x357776(0x192)],this[_0x357776(0x18f)]=_0x36ac4c,this[_0x357776(0x170)]=new SessionCache({'maxChatsPerSession':MAX_CHATS_PER_SESSION,'cacheExpirationMs':CACHE_EXPIRATION_MS}),this[_0x357776(0x169)]=new Map(),this['server']=a44_0x2ac25e({'logger':![],'bodyLimit':0x40*0x400*0x400}),this[_0x357776(0x191)](),this['setupRoutes']();}async['getAgentForModel'](_0x3cd3e5,_0x3bd863=0x0){const _0x45207c=a44_0xa20526,_0x16d2e9=extractModelAlias(_0x3cd3e5),_0x4ab5f3=resolveModelAlias(_0x16d2e9),_0x436705=_0x4ab5f3+'_'+_0x3bd863;let _0x4a8a3f=this[_0x45207c(0x169)][_0x45207c(0x21c)](_0x436705);if(!_0x4a8a3f){this[_0x45207c(0x192)]['debug'](_0x45207c(0x178)+_0x3cd3e5+_0x45207c(0x1d6)+_0x16d2e9+_0x45207c(0x1d6)+_0x4ab5f3),this['logger'][_0x45207c(0x1a2)](_0x45207c(0x17a)+_0x4ab5f3+_0x45207c(0x212)+_0x3bd863+')');const _0x2e0ac6=await this[_0x45207c(0x18f)][_0x45207c(0x198)][_0x45207c(0x1a7)][_0x45207c(0x1ad)](_0x4ab5f3,_0x3bd863);_0x4a8a3f=_0x2e0ac6['id'],this['agentCache'][_0x45207c(0x1a6)](_0x436705,_0x4a8a3f),this[_0x45207c(0x192)][_0x45207c(0x1a2)](_0x45207c(0x166)+_0x436705+_0x45207c(0x1d6)+_0x4a8a3f+'\x20('+_0x2e0ac6[_0x45207c(0x21f)][_0x45207c(0x1ca)]+')');}return _0x4a8a3f;}[a44_0xa20526(0x180)](){const _0x37604f=a44_0xa20526;this[_0x37604f(0x170)][_0x37604f(0x180)]();}[a44_0xa20526(0x191)](){const _0x172d8a=a44_0xa20526;this['server'][_0x172d8a(0x1c4)](a44_0x1929df,{'origin':!![],'methods':[_0x172d8a(0x203),'POST',_0x172d8a(0x1a0)],'allowedHeaders':[_0x172d8a(0x1a8),_0x172d8a(0x18d),'anthropic-version',_0x172d8a(0x16a)]}),this['server'][_0x172d8a(0x1a3)]((_0x2f259a,_0x15863a,_0x1c390e)=>{const _0xb51eb9=_0x172d8a,_0x4e40f8=_0x2f259a instanceof Error?_0x2f259a[_0xb51eb9(0x1de)]:_0xb51eb9(0x1ff);this[_0xb51eb9(0x192)]['error'](_0xb51eb9(0x1bb)+_0x15863a[_0xb51eb9(0x1ab)]+'\x20'+_0x15863a[_0xb51eb9(0x1e9)]+':',_0x2f259a),_0x1c390e[_0xb51eb9(0x19b)](0x1f4)[_0xb51eb9(0x19d)]({'type':_0xb51eb9(0x1ed),'error':{'type':_0xb51eb9(0x21e),'message':_0x4e40f8}});});}[a44_0xa20526(0x1a4)](_0x626e79,_0x1b0f71,_0x16a4b0){const _0xaa2cdf=a44_0xa20526,_0xb750f6=_0x1b0f71 instanceof Error?_0x1b0f71['message']:_0xaa2cdf(0x1ff);this['logger']['error'](_0xaa2cdf(0x16b)+_0x626e79+':',_0x1b0f71),!_0x16a4b0[_0xaa2cdf(0x1d3)]&&_0x16a4b0['code'](0x1f4)['send']({'type':_0xaa2cdf(0x1ed),'error':{'type':_0xaa2cdf(0x21e),'message':_0xb750f6}});}[a44_0xa20526(0x173)](){const _0x242c2c=a44_0xa20526;this[_0x242c2c(0x171)][_0x242c2c(0x21c)](_0x242c2c(0x18e),async()=>{return{'status':'ok','message':'TD\x20LLM\x20Proxy\x20Server'};}),this['server'][_0x242c2c(0x1f8)](_0x242c2c(0x185),async(_0x36d3d0,_0x3409de)=>{const _0x2f2f69=_0x242c2c;return this[_0x2f2f69(0x189)](_0x36d3d0,_0x3409de)[_0x2f2f69(0x1cf)](_0x2e66ed=>{const _0x147c66=_0x2f2f69;this[_0x147c66(0x1a4)](_0x147c66(0x185),_0x2e66ed,_0x3409de);});}),this[_0x242c2c(0x171)][_0x242c2c(0x1f8)](_0x242c2c(0x1dc),async(_0x2d6cc1,_0x405dfe)=>{const _0x321ec7=_0x242c2c;return this[_0x321ec7(0x1ee)](_0x2d6cc1)[_0x321ec7(0x1cf)](_0x5ba0b2=>{const _0x2ce0bb=_0x321ec7;this[_0x2ce0bb(0x1a4)](_0x2ce0bb(0x1dc),_0x5ba0b2,_0x405dfe);});});}async['handleMessages'](_0x521db3,_0x1642a7){const _0x1b66f5=a44_0xa20526,_0x5a8300=_0x521db3[_0x1b66f5(0x1fb)];if(!_0x5a8300[_0x1b66f5(0x1e1)]||!Array[_0x1b66f5(0x1d5)](_0x5a8300[_0x1b66f5(0x1e1)])||_0x5a8300[_0x1b66f5(0x1e1)][_0x1b66f5(0x17c)]===0x0){this[_0x1b66f5(0x192)]['error']('[PROXY\x20ERROR]\x20Validation\x20failed:\x20messages\x20array\x20is\x20required\x20and\x20must\x20not\x20be\x20empty'),_0x1642a7[_0x1b66f5(0x19b)](0x190)[_0x1b66f5(0x19d)]({'type':_0x1b66f5(0x1ed),'error':{'type':_0x1b66f5(0x1ce),'message':_0x1b66f5(0x186)}});return;}if(_0x5a8300[_0x1b66f5(0x17f)]&&!Array[_0x1b66f5(0x1d5)](_0x5a8300[_0x1b66f5(0x17f)])){this[_0x1b66f5(0x192)][_0x1b66f5(0x1ed)]('[PROXY\x20ERROR]\x20Validation\x20failed:\x20tools\x20must\x20be\x20an\x20array\x20if\x20provided'),_0x1642a7['code'](0x190)[_0x1b66f5(0x19d)]({'type':_0x1b66f5(0x1ed),'error':{'type':'invalid_request_error','message':_0x1b66f5(0x194)}});return;}const _0x281828=_0x5a8300[_0x1b66f5(0x1e1)]?.[_0x1b66f5(0x17c)]??0x0,_0x433724=_0x5a8300[_0x1b66f5(0x1d0)]||_0x1b66f5(0x197);this[_0x1b66f5(0x192)][_0x1b66f5(0x1fa)](_0x521db3[_0x1b66f5(0x1ab)]+'\x20'+_0x521db3[_0x1b66f5(0x1e9)]+_0x1b66f5(0x17d)+_0x281828+_0x1b66f5(0x1d1)+_0x433724),this[_0x1b66f5(0x192)]['debug'](_0x1b66f5(0x1f4)+colorizeJSONCompact(_0x521db3[_0x1b66f5(0x1d2)]));this[_0x1b66f5(0x192)][_0x1b66f5(0x1fc)]&&this[_0x1b66f5(0x192)]['trace'](colorizeJSON(_0x5a8300,{'color':!![]}));const _0x45257b=_0x5a8300['metadata']?.['user_id']||_0x1b66f5(0x1a5),_0x4f4bf1=this[_0x1b66f5(0x18f)][_0x1b66f5(0x20a)];if(!_0x4f4bf1){this[_0x1b66f5(0x192)]['error'](_0x1b66f5(0x196)),_0x1642a7[_0x1b66f5(0x19b)](0x1f4)[_0x1b66f5(0x19d)]({'type':_0x1b66f5(0x1ed),'error':{'type':'api_error','message':_0x1b66f5(0x179)}});return;}const _0x212d9=this['sessionCache'][_0x1b66f5(0x1c8)](_0x45257b,_0x4f4bf1),_0x27ac05=[];if(_0x5a8300[_0x1b66f5(0x193)]){if(typeof _0x5a8300[_0x1b66f5(0x193)]==='string')_0x27ac05['push'](_0x5a8300[_0x1b66f5(0x193)]);else{if(Array[_0x1b66f5(0x1d5)](_0x5a8300[_0x1b66f5(0x193)]))for(const _0x5c871c of _0x5a8300[_0x1b66f5(0x193)]){_0x5c871c['type']===_0x1b66f5(0x1eb)&&_0x5c871c[_0x1b66f5(0x1eb)]&&_0x27ac05[_0x1b66f5(0x1b8)](_0x5c871c[_0x1b66f5(0x1eb)]);}}}const _0x5f90dc=_0x5a8300[_0x1b66f5(0x17f)]||[],_0x46f8e0=_0x5a8300['thinking']?.[_0x1b66f5(0x1e0)],_0x516238=mapBudgetTokensToReasoningEffort(_0x46f8e0,this['config'][_0x1b66f5(0x1d9)]),_0x3d240a=calculateContextSignature(_0x5a8300[_0x1b66f5(0x1d0)],_0x27ac05,_0x5f90dc,_0x516238);let _0xd82fcf=_0x212d9[_0x1b66f5(0x209)][_0x1b66f5(0x21c)](_0x3d240a);const _0x5b051d=!_0xd82fcf;if(!_0xd82fcf){const _0x1d498a=await this[_0x1b66f5(0x1b5)](_0x5a8300[_0x1b66f5(0x1d0)],_0x516238);_0xd82fcf={'chatId':'','agentId':_0x1d498a,'contextSignature':_0x3d240a,'embeddedSystemPrompts':new Set(),'embeddedToolsByName':new Map(),'messageHistory':[],'lastUsedAt':Date[_0x1b66f5(0x20c)]()},_0x212d9['chats']['set'](_0x3d240a,_0xd82fcf);if(_0x212d9[_0x1b66f5(0x209)]['size']>MAX_CHATS_PER_SESSION){let _0x275762=null,_0x59108e=Date[_0x1b66f5(0x20c)]();for(const [_0x5edeaf,_0x22e723]of _0x212d9[_0x1b66f5(0x209)]){_0x22e723[_0x1b66f5(0x1dd)]<_0x59108e&&(_0x59108e=_0x22e723[_0x1b66f5(0x1dd)],_0x275762=_0x5edeaf);}_0x275762&&(_0x212d9[_0x1b66f5(0x209)][_0x1b66f5(0x183)](_0x275762),this[_0x1b66f5(0x192)][_0x1b66f5(0x1a2)]('Evicted\x20oldest\x20chat\x20(signature:\x20'+_0x275762+_0x1b66f5(0x220)+MAX_CHATS_PER_SESSION+'\x20limit'));}}else _0xd82fcf[_0x1b66f5(0x1dd)]=Date['now']();if(!_0xd82fcf['chatId']){if(_0xd82fcf['creating']&&_0xd82fcf[_0x1b66f5(0x19e)]){this[_0x1b66f5(0x192)]['debug'](_0x1b66f5(0x1ea)+_0x3d240a);try{_0xd82fcf[_0x1b66f5(0x1b1)]=await _0xd82fcf[_0x1b66f5(0x19e)];}catch(_0x45869a){this['logger'][_0x1b66f5(0x1ed)](_0x1b66f5(0x184),_0x45869a);}}else{if(!_0xd82fcf['creating']){_0xd82fcf['creating']=!![],_0xd82fcf[_0x1b66f5(0x19e)]=((async()=>{const _0x362d81=_0x1b66f5;try{const _0x1312cb=await this[_0x362d81(0x18f)]['tdx'][_0x362d81(0x1a7)][_0x362d81(0x20e)](_0xd82fcf[_0x362d81(0x1c2)]);return this[_0x362d81(0x192)][_0x362d81(0x1fa)]('['+_0x1312cb['id']+_0x362d81(0x1f1)+_0x5a8300[_0x362d81(0x1d0)]+_0x362d81(0x1fd)+_0x3d240a),_0x1312cb['id'];}catch(_0x1d6bc0){this[_0x362d81(0x192)][_0x362d81(0x1ed)](_0x362d81(0x21b),_0x1d6bc0);throw _0x1d6bc0;}finally{_0xd82fcf['creating']=![],_0xd82fcf[_0x362d81(0x19e)]=undefined;}})());try{_0xd82fcf['chatId']=await _0xd82fcf[_0x1b66f5(0x19e)];}catch{}}}}const _0x8ea13=_0x27ac05[_0x1b66f5(0x1d8)](_0x3b1a12=>!_0xd82fcf[_0x1b66f5(0x1b3)][_0x1b66f5(0x19a)](_0x3b1a12)),_0x2bdf3c=_0x5f90dc[_0x1b66f5(0x1d8)](_0x27b9fe=>!_0xd82fcf['embeddedToolsByName'][_0x1b66f5(0x19a)](_0x27b9fe['name']));this['logger'][_0x1b66f5(0x1a2)]('[session:\x20'+_0x45257b+_0x1b66f5(0x1af)+_0x5a8300[_0x1b66f5(0x1d0)]+_0x1b66f5(0x1a1)+_0x3d240a+_0x1b66f5(0x1f3)+_0x5b051d),this[_0x1b66f5(0x192)][_0x1b66f5(0x1a2)](_0x1b66f5(0x181)+_0xd82fcf[_0x1b66f5(0x1b1)]),this['logger']['debug'](_0x1b66f5(0x1bd)+_0x27ac05['length']+',\x20tools:\x20'+_0x5f90dc['length']),this[_0x1b66f5(0x192)]['debug'](_0x1b66f5(0x1e3)+_0xd82fcf[_0x1b66f5(0x1b3)]['size']+',\x20tools:\x20'+_0xd82fcf[_0x1b66f5(0x20b)]['size']),this[_0x1b66f5(0x192)][_0x1b66f5(0x1a2)](_0x1b66f5(0x163)+_0x8ea13[_0x1b66f5(0x17c)]+_0x1b66f5(0x221)+_0x2bdf3c[_0x1b66f5(0x17c)]);_0x8ea13[_0x1b66f5(0x17c)]>0x0&&this[_0x1b66f5(0x192)][_0x1b66f5(0x1a2)](_0x1b66f5(0x1e4),_0x8ea13['map'](_0x5133ad=>_0x5133ad[_0x1b66f5(0x1b2)](0x0,0x32)+'...')['join'](_0x1b66f5(0x1ba)));_0x2bdf3c[_0x1b66f5(0x17c)]>0x0&&this[_0x1b66f5(0x192)][_0x1b66f5(0x1a2)]('Added\x20tool\x20names:',_0x2bdf3c[_0x1b66f5(0x1c5)](_0x505786=>_0x505786[_0x1b66f5(0x1ca)])[_0x1b66f5(0x16d)](',\x20'));const _0x3aeeae=_0xd82fcf['messageHistory'][_0x1b66f5(0x17c)],_0x566e98=_0x5a8300[_0x1b66f5(0x1e1)][_0x1b66f5(0x165)](_0x3aeeae);let _0x4a8820=_0x566e98[_0x1b66f5(0x1d8)](_0xddc9f5=>_0xddc9f5['role']==='user')[_0x1b66f5(0x1c6)]();if(!_0x4a8820){_0x4a8820=_0x5a8300['messages'][_0x1b66f5(0x1d8)](_0x1169d9=>_0x1169d9[_0x1b66f5(0x174)]==='user')['pop']();if(!_0x4a8820){this[_0x1b66f5(0x192)]['error']('[PROXY\x20ERROR]\x20Validation\x20failed:\x20No\x20user\x20message\x20found\x20in\x20request'),_0x1642a7[_0x1b66f5(0x19b)](0x190)[_0x1b66f5(0x19d)]({'type':_0x1b66f5(0x1ed),'error':{'type':_0x1b66f5(0x1ce),'message':_0x1b66f5(0x1f6)}});return;}}let _0x3bbc06;if(typeof _0x4a8820[_0x1b66f5(0x1c9)]===_0x1b66f5(0x1c3))_0x3bbc06=_0x4a8820[_0x1b66f5(0x1c9)];else{if(_0x4a8820[_0x1b66f5(0x1c9)]!=null&&Array['isArray'](_0x4a8820['content']))_0x3bbc06=_0x4a8820[_0x1b66f5(0x1c9)][_0x1b66f5(0x1d8)](_0x484236=>_0x484236&&_0x484236[_0x1b66f5(0x190)]===_0x1b66f5(0x1eb)&&_0x484236[_0x1b66f5(0x1eb)])[_0x1b66f5(0x1c5)](_0x14447b=>_0x14447b[_0x1b66f5(0x1eb)])[_0x1b66f5(0x16d)]('\x0a');else{this['logger'][_0x1b66f5(0x1ed)](_0x1b66f5(0x16f),typeof _0x4a8820[_0x1b66f5(0x1c9)],_0x4a8820[_0x1b66f5(0x1c9)]),_0x1642a7['code'](0x190)['send']({'type':_0x1b66f5(0x1ed),'error':{'type':_0x1b66f5(0x1ce),'message':'message.content\x20must\x20be\x20a\x20string\x20or\x20array'}});return;}}const _0x585b91=()=>{const _0x381e1d=_0x1b66f5,_0x435358=[];_0x27ac05[_0x381e1d(0x17c)]>0x0&&_0x435358[_0x381e1d(0x1b8)](_0x27ac05[_0x381e1d(0x16d)]('\x0a\x0a'));_0x5f90dc['length']>0x0&&_0x435358[_0x381e1d(0x1b8)](generateToolPrompt(_0x5f90dc));if(_0x5a8300[_0x381e1d(0x1e1)]&&_0x5a8300[_0x381e1d(0x1e1)][_0x381e1d(0x17c)]>0x1){const _0x44cb60=formatConversationHistory(_0x5a8300['messages']);_0x44cb60&&_0x435358[_0x381e1d(0x1b8)](_0x381e1d(0x1b7)+_0x44cb60+'\x0a</conversation>');}return _0x435358[_0x381e1d(0x1b8)](_0x381e1d(0x1ac)+_0x3bbc06),_0x435358[_0x381e1d(0x16d)](_0x381e1d(0x20d));};let _0x5521cb;if(_0x5b051d){this[_0x1b66f5(0x192)][_0x1b66f5(0x1fa)]('['+_0xd82fcf[_0x1b66f5(0x1b1)]+_0x1b66f5(0x200)+_0x5a8300[_0x1b66f5(0x1d0)]+_0x1b66f5(0x211)+_0x27ac05[_0x1b66f5(0x17c)]+_0x1b66f5(0x1da)+_0x5f90dc['length']+_0x1b66f5(0x167)+_0x5f90dc[_0x1b66f5(0x1c5)](_0x2b87d7=>_0x2b87d7['name'])[_0x1b66f5(0x16d)](',\x20')+']'),_0x5521cb=_0x585b91();for(const _0x28b81d of _0x27ac05){_0xd82fcf[_0x1b66f5(0x1b3)][_0x1b66f5(0x19f)](_0x28b81d);}for(const _0x2812e2 of _0x5f90dc){_0xd82fcf[_0x1b66f5(0x20b)][_0x1b66f5(0x1a6)](_0x2812e2[_0x1b66f5(0x1ca)],_0x2812e2);}}else{const _0x1c8a49=[];_0x8ea13[_0x1b66f5(0x17c)]>0x0&&(_0x1c8a49[_0x1b66f5(0x1b8)](_0x8ea13[_0x1b66f5(0x16d)]('\x0a\x0a')),this['logger'][_0x1b66f5(0x1a2)](_0x1b66f5(0x1cb),_0x8ea13['length'],'new\x20system\x20prompt(s)'));if(_0x2bdf3c[_0x1b66f5(0x17c)]>0x0)try{_0x1c8a49[_0x1b66f5(0x1b8)](generateToolPrompt(_0x2bdf3c)),this[_0x1b66f5(0x192)][_0x1b66f5(0x1a2)](_0x1b66f5(0x1cb),_0x2bdf3c[_0x1b66f5(0x17c)],'new\x20tool(s)');}catch(_0x4c82af){this[_0x1b66f5(0x192)][_0x1b66f5(0x1ed)](_0x1b66f5(0x1e7),_0x4c82af);}try{const _0x4204a5=extractToolResults(_0x566e98);_0x4204a5&&(_0x1c8a49[_0x1b66f5(0x1b8)](_0x4204a5),this[_0x1b66f5(0x192)][_0x1b66f5(0x1a2)](_0x1b66f5(0x1f7)));}catch(_0x3d6317){this[_0x1b66f5(0x192)][_0x1b66f5(0x1ed)](_0x1b66f5(0x1b0),_0x3d6317);}_0x1c8a49['push'](_0x3bbc06),_0x5521cb=_0x1c8a49[_0x1b66f5(0x17c)]>0x1?_0x1c8a49[_0x1b66f5(0x16d)](_0x1b66f5(0x20d)):_0x3bbc06;for(const _0x48fb9c of _0x8ea13){_0xd82fcf['embeddedSystemPrompts'][_0x1b66f5(0x19f)](_0x48fb9c);}for(const _0x1b6666 of _0x2bdf3c){_0xd82fcf[_0x1b66f5(0x20b)][_0x1b66f5(0x1a6)](_0x1b6666[_0x1b66f5(0x1ca)],_0x1b6666);}}(!_0x5521cb||!_0x5521cb[_0x1b66f5(0x177)]())&&(this[_0x1b66f5(0x192)][_0x1b66f5(0x18a)](_0x1b66f5(0x1db)),this[_0x1b66f5(0x192)][_0x1b66f5(0x18a)]('Context:',{'isNewContext':_0x5b051d,'userMessageLength':_0x3bbc06?.[_0x1b66f5(0x17c)]||0x0,'systemPromptsCount':_0x27ac05[_0x1b66f5(0x17c)],'toolsCount':_0x5f90dc['length'],'messagesCount':_0x5a8300[_0x1b66f5(0x1e1)]?.[_0x1b66f5(0x17c)]||0x0,'newMessagesCount':_0x566e98[_0x1b66f5(0x17c)]}),clearChatState(_0xd82fcf),_0x5521cb=_0x585b91(),(!_0x5521cb||!_0x5521cb[_0x1b66f5(0x177)]())&&(this[_0x1b66f5(0x192)][_0x1b66f5(0x1ed)]('Failed\x20to\x20reconstruct\x20message\x20-\x20all\x20parts\x20are\x20empty,\x20using\x20fallback'),this[_0x1b66f5(0x192)]['error'](_0x1b66f5(0x172),{'systemPromptsCount':_0x27ac05[_0x1b66f5(0x17c)],'toolsCount':_0x5f90dc['length'],'messagesCount':_0x5a8300['messages']?.[_0x1b66f5(0x17c)]||0x0,'userMessageLength':_0x3bbc06?.[_0x1b66f5(0x17c)]||0x0}),_0x5521cb=_0x1b66f5(0x1aa)),this[_0x1b66f5(0x192)][_0x1b66f5(0x1fa)]('Final\x20message\x20reconstructed\x20after\x20context\x20reset:',_0x5521cb[_0x1b66f5(0x1b2)](0x0,0x64)+'...'));const _0x43f0a5=_0x5a8300[_0x1b66f5(0x222)]!==![];if(_0x43f0a5){_0x1642a7[_0x1b66f5(0x1bf)][_0x1b66f5(0x1ef)](0xc8,{'Content-Type':_0x1b66f5(0x1e6),'Cache-Control':_0x1b66f5(0x1f0),'Connection':'keep-alive','X-Accel-Buffering':'no'});const _0x300b12=generateMessageId();try{if(_0xd82fcf['chatId']){const _0x1de763=_0x5521cb[_0x1b66f5(0x1b2)](0x0,0x32)[_0x1b66f5(0x219)](/\n/g,'\x20');this['logger'][_0x1b66f5(0x1fa)]('['+_0xd82fcf[_0x1b66f5(0x1b1)]+_0x1b66f5(0x175)+_0x5a8300[_0x1b66f5(0x1d0)]+',\x20context='+_0x3d240a+',\x20'+_0x5a8300[_0x1b66f5(0x1e1)]['length']+_0x1b66f5(0x1e8)+_0x27ac05[_0x1b66f5(0x17c)]+'\x20system\x20prompts,\x20'+_0x5f90dc[_0x1b66f5(0x17c)]+_0x1b66f5(0x208)+_0x5521cb[_0x1b66f5(0x17c)]+_0x1b66f5(0x1d4)+_0x1de763+_0x1b66f5(0x199));}const _0x5c7e88=this['config'][_0x1b66f5(0x198)]['llm'][_0x1b66f5(0x18c)](_0x5521cb,{'chatId':_0xd82fcf[_0x1b66f5(0x1b1)]||undefined,'agentId':_0xd82fcf[_0x1b66f5(0x1b1)]?undefined:_0xd82fcf[_0x1b66f5(0x1c2)]});if(!_0x5c7e88){this['logger'][_0x1b66f5(0x1ed)](_0x1b66f5(0x195)),this['logger'][_0x1b66f5(0x1ed)]('Context:',JSON[_0x1b66f5(0x201)]({'chatId':_0xd82fcf[_0x1b66f5(0x1b1)],'agentId':_0xd82fcf[_0x1b66f5(0x1c2)],'model':_0x5a8300[_0x1b66f5(0x1d0)],'sessionId':_0x45257b,'contextSignature':_0x3d240a})),_0xd82fcf['chatId']='',this[_0x1b66f5(0x192)][_0x1b66f5(0x18a)](_0x1b66f5(0x1c0));const _0x9b1305=formatAnthropicSSE({'type':_0x1b66f5(0x1ed),'error':{'type':_0x1b66f5(0x21e),'message':_0x1b66f5(0x187)},'request_id':_0x300b12});_0x1642a7[_0x1b66f5(0x1bf)]['write'](_0x9b1305),_0x1642a7[_0x1b66f5(0x1bf)][_0x1b66f5(0x1c7)]();return;}_0xd82fcf[_0x1b66f5(0x182)]=_0x5a8300[_0x1b66f5(0x1e1)];const _0x41ec45=_0xd82fcf;async function*_0x34750a(_0x52fccc){const _0x11a63f=_0x1b66f5;for await(const _0x1b2ead of _0x52fccc){if(_0x1b2ead[_0x11a63f(0x190)]===_0x11a63f(0x1b4))_0x1b2ead[_0x11a63f(0x1bc)][_0x11a63f(0x1b1)]&&!_0x41ec45[_0x11a63f(0x1b1)]&&(_0x41ec45[_0x11a63f(0x1b1)]=_0x1b2ead[_0x11a63f(0x1bc)][_0x11a63f(0x1b1)]);else _0x1b2ead[_0x11a63f(0x190)]===_0x11a63f(0x205)&&(yield _0x1b2ead[_0x11a63f(0x1bc)]);}}const _0x94522=_0x34750a(_0x5c7e88),_0xd93a21=estimateInputTokensFromRequest(_0x5a8300),_0x5a88b4=transformTDStreamToAnthropic(_0x94522,_0x300b12,_0x5a8300[_0x1b66f5(0x1d0)],this['logger'],_0x3bbc06,_0xd93a21),_0x35e065=_0x5521cb[_0x1b66f5(0x17c)];let _0x5451ab=0x0;for await(const _0x575614 of _0x5a88b4){const _0x2f53cb=formatAnthropicSSE(_0x575614);_0x5451ab++,this[_0x1b66f5(0x192)][_0x1b66f5(0x1a2)](colorizeJSONCompact(_0x575614,{'color':!![]})),_0x575614[_0x1b66f5(0x190)]===_0x1b66f5(0x1ed)&&_0x575614[_0x1b66f5(0x1ed)][_0x1b66f5(0x190)]===_0x1b66f5(0x1cd)&&(clearChatState(_0xd82fcf),this[_0x1b66f5(0x192)]['warn'](_0x1b66f5(0x215)+_0x575614[_0x1b66f5(0x1ed)][_0x1b66f5(0x1de)]+_0x1b66f5(0x1d7)+_0x35e065+_0x1b66f5(0x204)+_0x45257b+_0x1b66f5(0x1e2)+_0x3d240a)),_0x1642a7['raw']['write'](_0x2f53cb);}this[_0x1b66f5(0x192)][_0x1b66f5(0x1a2)](_0x1b66f5(0x216)+_0x5451ab+_0x1b66f5(0x188)),_0x1642a7['raw']['end']();}catch(_0x80351){const _0x5cb0b9=_0x80351 instanceof Error?_0x80351[_0x1b66f5(0x1de)]:_0x1b66f5(0x1ff);this['logger'][_0x1b66f5(0x1ed)](_0x1b66f5(0x160),_0x80351),this[_0x1b66f5(0x192)]['error'](_0x1b66f5(0x213),JSON[_0x1b66f5(0x201)]({'chatId':_0xd82fcf[_0x1b66f5(0x1b1)],'agentId':_0xd82fcf[_0x1b66f5(0x1c2)],'model':_0x5a8300[_0x1b66f5(0x1d0)],'sessionId':_0x45257b,'contextSignature':_0x3d240a})),_0xd82fcf[_0x1b66f5(0x1b1)]='',this[_0x1b66f5(0x192)]['warn'](_0x1b66f5(0x202));const _0x3e1702=formatAnthropicSSE({'type':_0x1b66f5(0x1ed),'error':{'type':'api_error','message':_0x5cb0b9},'request_id':_0x300b12});_0x1642a7['raw'][_0x1b66f5(0x217)](_0x3e1702),_0x1642a7[_0x1b66f5(0x1bf)][_0x1b66f5(0x1c7)]();}}else this[_0x1b66f5(0x192)][_0x1b66f5(0x1ed)](_0x1b66f5(0x1b9)),_0x1642a7[_0x1b66f5(0x19b)](0x1f5)[_0x1b66f5(0x19d)]({'type':_0x1b66f5(0x1ed),'error':{'type':'not_supported_error','message':'Non-streaming\x20responses\x20are\x20not\x20yet\x20supported'}});}async[a44_0xa20526(0x1ee)](_0x3daf67){const _0x428c01=a44_0xa20526,_0x46a946=_0x3daf67[_0x428c01(0x1fb)],_0x5d96a5=estimateInputTokensFromRequest(_0x46a946);return this[_0x428c01(0x192)][_0x428c01(0x1fa)](_0x3daf67[_0x428c01(0x1ab)]+'\x20'+_0x3daf67['url']+_0x428c01(0x17e)+_0x5d96a5),{'input_tokens':_0x5d96a5};}async[a44_0xa20526(0x218)](){const _0x5c76c8=a44_0xa20526;try{await this[_0x5c76c8(0x171)]['listen']({'port':this['config']['port'],'host':'0.0.0.0'}),this[_0x5c76c8(0x192)][_0x5c76c8(0x1fa)](_0x5c76c8(0x17b)+this[_0x5c76c8(0x18f)][_0x5c76c8(0x1b6)]),this[_0x5c76c8(0x1ec)]=setInterval(()=>{const _0x4c37a4=_0x5c76c8;this[_0x4c37a4(0x180)]();},CLEANUP_INTERVAL_MS),this[_0x5c76c8(0x192)]['debug'](_0x5c76c8(0x176)+CLEANUP_INTERVAL_MS/0x3e8+'s,\x20expires\x20after\x20'+CACHE_EXPIRATION_MS/0x3e8+'s)');}catch(_0x4c2b78){const _0x12dc7b=_0x4c2b78 instanceof Error?_0x4c2b78['message']:_0x5c76c8(0x1ff);throw new Error('Failed\x20to\x20start\x20proxy\x20server:\x20'+_0x12dc7b);}}async['stop'](){const _0x191256=a44_0xa20526;this[_0x191256(0x1ec)]&&(clearInterval(this[_0x191256(0x1ec)]),this[_0x191256(0x1ec)]=undefined),await this[_0x191256(0x171)]['close']();}[a44_0xa20526(0x21a)](){const _0x3e3501=a44_0xa20526,_0x31d636=this['server']['server'][_0x3e3501(0x1df)]();if(typeof _0x31d636===_0x3e3501(0x1c3))return _0x31d636;if(_0x31d636)return'http://'+_0x31d636[_0x3e3501(0x1df)]+':'+_0x31d636['port'];return _0x3e3501(0x1a9)+this[_0x3e3501(0x18f)][_0x3e3501(0x1b6)];}}
@@ -1 +1 @@
1
- const a45_0x406b51=a45_0x4a26;(function(_0x3782e5,_0x1aebab){const _0x275924=a45_0x4a26,_0x334544=_0x3782e5();while(!![]){try{const _0x583bf2=parseInt(_0x275924(0x1cf))/0x1+parseInt(_0x275924(0x1cd))/0x2+parseInt(_0x275924(0x1d1))/0x3+parseInt(_0x275924(0x1d9))/0x4+parseInt(_0x275924(0x1e0))/0x5+parseInt(_0x275924(0x1de))/0x6*(parseInt(_0x275924(0x1d0))/0x7)+-parseInt(_0x275924(0x1cb))/0x8;if(_0x583bf2===_0x1aebab)break;else _0x334544['push'](_0x334544['shift']());}catch(_0x19c59e){_0x334544['push'](_0x334544['shift']());}}}(a45_0x1ed9,0xa02f9));function a45_0x1ed9(){const _0x45c525=['889986tdXofX','cacheExpirationMs','2816740dyQfAV','size','lastUsedAt','sessions','22274424VDqhoo','set','552366FIZLVf','getOrCreateChat','890614dgebcz','7lLAEjU','1127094KkvzXL','cleanupExpiredChats','getSession','getSessionCount','clear','delete','get','values','4745000dkAkDs','chats','config','now','\x20not\x20found'];a45_0x1ed9=function(){return _0x45c525;};return a45_0x1ed9();}function a45_0x4a26(_0x577772,_0xc57fee){const _0x1ed9b9=a45_0x1ed9();return a45_0x4a26=function(_0x4a26d2,_0x18f0a6){_0x4a26d2=_0x4a26d2-0x1ca;let _0x33c992=_0x1ed9b9[_0x4a26d2];return _0x33c992;},a45_0x4a26(_0x577772,_0xc57fee);}export class SessionCache{[a45_0x406b51(0x1ca)];[a45_0x406b51(0x1db)];constructor(_0x26f52e){const _0x59f880=a45_0x406b51;this[_0x59f880(0x1db)]=_0x26f52e,this[_0x59f880(0x1ca)]=new Map();}['getOrCreateSession'](_0x52729f,_0x1f14d9){const _0x50cb46=a45_0x406b51;let _0x5080f9=this[_0x50cb46(0x1ca)][_0x50cb46(0x1d7)](_0x52729f);return!_0x5080f9&&(_0x5080f9={'projectId':_0x1f14d9,'chats':new Map()},this[_0x50cb46(0x1ca)][_0x50cb46(0x1cc)](_0x52729f,_0x5080f9)),_0x5080f9;}[a45_0x406b51(0x1d3)](_0x44c53a){const _0x361fb9=a45_0x406b51;return this[_0x361fb9(0x1ca)]['get'](_0x44c53a);}[a45_0x406b51(0x1ce)](_0x2059ee,_0x3d897b,_0x37abe6){const _0x58bc6c=a45_0x406b51,_0x1037a9=this[_0x58bc6c(0x1ca)][_0x58bc6c(0x1d7)](_0x2059ee);if(!_0x1037a9)throw new Error('Session\x20'+_0x2059ee+_0x58bc6c(0x1dd));let _0x2caf45=_0x1037a9['chats']['get'](_0x3d897b);if(!_0x2caf45){_0x2caf45={'chatId':'','agentId':_0x37abe6,'contextSignature':_0x3d897b,'embeddedSystemPrompts':new Set(),'embeddedToolsByName':new Map(),'messageHistory':[],'lastUsedAt':Date[_0x58bc6c(0x1dc)]()},_0x1037a9[_0x58bc6c(0x1da)][_0x58bc6c(0x1cc)](_0x3d897b,_0x2caf45);if(_0x1037a9[_0x58bc6c(0x1da)][_0x58bc6c(0x1e1)]>this[_0x58bc6c(0x1db)]['maxChatsPerSession']){let _0x40cff3=null,_0x1c29d5=Date[_0x58bc6c(0x1dc)]();for(const [_0x374cce,_0xcf1627]of _0x1037a9[_0x58bc6c(0x1da)]){_0xcf1627[_0x58bc6c(0x1e2)]<_0x1c29d5&&(_0x1c29d5=_0xcf1627[_0x58bc6c(0x1e2)],_0x40cff3=_0x374cce);}_0x40cff3&&_0x1037a9[_0x58bc6c(0x1da)][_0x58bc6c(0x1d6)](_0x40cff3);}}else _0x2caf45[_0x58bc6c(0x1e2)]=Date['now']();return _0x2caf45;}[a45_0x406b51(0x1d2)](){const _0x5d6078=a45_0x406b51,_0x128f87=Date[_0x5d6078(0x1dc)]();let _0x26bfa4=0x0;for(const [_0x4cf1fc,_0x368bc4]of this[_0x5d6078(0x1ca)]){const _0x38d5f6=[];for(const [_0x808ed3,_0x2f611b]of _0x368bc4['chats']){_0x128f87-_0x2f611b[_0x5d6078(0x1e2)]>this[_0x5d6078(0x1db)][_0x5d6078(0x1df)]&&_0x38d5f6['push'](_0x808ed3);}for(const _0x53de2f of _0x38d5f6){_0x368bc4[_0x5d6078(0x1da)][_0x5d6078(0x1d6)](_0x53de2f),_0x26bfa4++;}_0x368bc4[_0x5d6078(0x1da)][_0x5d6078(0x1e1)]===0x0&&this[_0x5d6078(0x1ca)][_0x5d6078(0x1d6)](_0x4cf1fc);}return _0x26bfa4;}[a45_0x406b51(0x1d4)](){return this['sessions']['size'];}['getTotalChatCount'](){const _0x2b818a=a45_0x406b51;let _0x39f708=0x0;for(const _0x129715 of this['sessions'][_0x2b818a(0x1d8)]()){_0x39f708+=_0x129715[_0x2b818a(0x1da)][_0x2b818a(0x1e1)];}return _0x39f708;}[a45_0x406b51(0x1d5)](){const _0x3b94cf=a45_0x406b51;this[_0x3b94cf(0x1ca)]['clear']();}}
1
+ const a45_0x32b425=a45_0x5ef5;(function(_0x441af4,_0x2fc603){const _0x23878a=a45_0x5ef5,_0x1db3f4=_0x441af4();while(!![]){try{const _0x579de3=-parseInt(_0x23878a(0xcc))/0x1*(-parseInt(_0x23878a(0xd3))/0x2)+-parseInt(_0x23878a(0xb5))/0x3+-parseInt(_0x23878a(0xcf))/0x4*(-parseInt(_0x23878a(0xc1))/0x5)+parseInt(_0x23878a(0xbc))/0x6*(parseInt(_0x23878a(0xb6))/0x7)+-parseInt(_0x23878a(0xca))/0x8+parseInt(_0x23878a(0xb9))/0x9+-parseInt(_0x23878a(0xc9))/0xa*(-parseInt(_0x23878a(0xbb))/0xb);if(_0x579de3===_0x2fc603)break;else _0x1db3f4['push'](_0x1db3f4['shift']());}catch(_0x163031){_0x1db3f4['push'](_0x1db3f4['shift']());}}}(a45_0x2e0a,0x5a957));export class SessionCache{[a45_0x32b425(0xc8)];['config'];constructor(_0xc64fc6){const _0x4fc5d4=a45_0x32b425;this[_0x4fc5d4(0xd2)]=_0xc64fc6,this[_0x4fc5d4(0xc8)]=new Map();}[a45_0x32b425(0xc2)](_0x4e5a7e,_0x47261){const _0x2f9639=a45_0x32b425;let _0x3484b0=this[_0x2f9639(0xc8)][_0x2f9639(0xd1)](_0x4e5a7e);return!_0x3484b0&&(_0x3484b0={'projectId':_0x47261,'chats':new Map()},this[_0x2f9639(0xc8)][_0x2f9639(0xce)](_0x4e5a7e,_0x3484b0)),_0x3484b0;}[a45_0x32b425(0xb8)](_0x41eed9){const _0x3c3570=a45_0x32b425;return this[_0x3c3570(0xc8)][_0x3c3570(0xd1)](_0x41eed9);}[a45_0x32b425(0xcd)](_0x1a4d93,_0x148cb8,_0x2bfbc9){const _0x1bd110=a45_0x32b425,_0x1f3490=this[_0x1bd110(0xc8)][_0x1bd110(0xd1)](_0x1a4d93);if(!_0x1f3490)throw new Error(_0x1bd110(0xbf)+_0x1a4d93+'\x20not\x20found');let _0x3c0697=_0x1f3490[_0x1bd110(0xc0)][_0x1bd110(0xd1)](_0x148cb8);if(!_0x3c0697){_0x3c0697={'chatId':'','agentId':_0x2bfbc9,'contextSignature':_0x148cb8,'embeddedSystemPrompts':new Set(),'embeddedToolsByName':new Map(),'messageHistory':[],'lastUsedAt':Date[_0x1bd110(0xd0)]()},_0x1f3490[_0x1bd110(0xc0)][_0x1bd110(0xce)](_0x148cb8,_0x3c0697);if(_0x1f3490[_0x1bd110(0xc0)][_0x1bd110(0xbe)]>this[_0x1bd110(0xd2)]['maxChatsPerSession']){let _0x3ce985=null,_0x4cd9f2=Date[_0x1bd110(0xd0)]();for(const [_0x270227,_0x1924d8]of _0x1f3490[_0x1bd110(0xc0)]){_0x1924d8['lastUsedAt']<_0x4cd9f2&&(_0x4cd9f2=_0x1924d8[_0x1bd110(0xc7)],_0x3ce985=_0x270227);}_0x3ce985&&_0x1f3490[_0x1bd110(0xc0)][_0x1bd110(0xcb)](_0x3ce985);}}else _0x3c0697[_0x1bd110(0xc7)]=Date[_0x1bd110(0xd0)]();return _0x3c0697;}[a45_0x32b425(0xbd)](){const _0x1af8df=a45_0x32b425,_0x5399ce=Date[_0x1af8df(0xd0)]();let _0x5ad266=0x0;for(const [_0x14f686,_0x20d91e]of this[_0x1af8df(0xc8)]){const _0x10c551=[];for(const [_0x294026,_0x26bdee]of _0x20d91e[_0x1af8df(0xc0)]){_0x5399ce-_0x26bdee[_0x1af8df(0xc7)]>this['config'][_0x1af8df(0xc4)]&&_0x10c551[_0x1af8df(0xc3)](_0x294026);}for(const _0x38edb1 of _0x10c551){_0x20d91e['chats'][_0x1af8df(0xcb)](_0x38edb1),_0x5ad266++;}_0x20d91e['chats'][_0x1af8df(0xbe)]===0x0&&this[_0x1af8df(0xc8)]['delete'](_0x14f686);}return _0x5ad266;}[a45_0x32b425(0xb7)](){const _0xa8fbd5=a45_0x32b425;return this['sessions'][_0xa8fbd5(0xbe)];}[a45_0x32b425(0xc6)](){const _0x3c6f8d=a45_0x32b425;let _0x417f50=0x0;for(const _0x38ca22 of this['sessions'][_0x3c6f8d(0xba)]()){_0x417f50+=_0x38ca22[_0x3c6f8d(0xc0)][_0x3c6f8d(0xbe)];}return _0x417f50;}[a45_0x32b425(0xc5)](){const _0x2d1d94=a45_0x32b425;this['sessions'][_0x2d1d94(0xc5)]();}}function a45_0x5ef5(_0x406202,_0x2804fb){const _0x2e0aaf=a45_0x2e0a();return a45_0x5ef5=function(_0x5ef5c5,_0x2da045){_0x5ef5c5=_0x5ef5c5-0xb5;let _0x53e624=_0x2e0aaf[_0x5ef5c5];return _0x53e624;},a45_0x5ef5(_0x406202,_0x2804fb);}function a45_0x2e0a(){const _0x4c597d=['delete','4VmPBIA','getOrCreateChat','set','92JiXQnR','now','get','config','106380bYXDye','1504512mtyGEB','7VLQiZK','getSessionCount','getSession','1135629Ntndwo','values','7161iGKIkF','2178966qGSgMl','cleanupExpiredChats','size','Session\x20','chats','5045wQmyjk','getOrCreateSession','push','cacheExpirationMs','clear','getTotalChatCount','lastUsedAt','sessions','8450vWluTd','3222952gcmVzE'];a45_0x2e0a=function(){return _0x4c597d;};return a45_0x2e0a();}
package/dist/sdk/api.js CHANGED
@@ -1 +1 @@
1
- const a46_0x18265f=a46_0x4b3e;function a46_0x4b3e(_0x1c3da0,_0x48a094){const _0x31eac6=a46_0x31ea();return a46_0x4b3e=function(_0x4b3ea0,_0x124530){_0x4b3ea0=_0x4b3ea0-0x152;let _0x52e7d7=_0x31eac6[_0x4b3ea0];return _0x52e7d7;},a46_0x4b3e(_0x1c3da0,_0x48a094);}(function(_0x41a32f,_0x570af5){const _0x27dd20=a46_0x4b3e,_0x51825a=_0x41a32f();while(!![]){try{const _0x41e8e6=parseInt(_0x27dd20(0x156))/0x1*(parseInt(_0x27dd20(0x15b))/0x2)+parseInt(_0x27dd20(0x162))/0x3+-parseInt(_0x27dd20(0x167))/0x4*(-parseInt(_0x27dd20(0x153))/0x5)+parseInt(_0x27dd20(0x15e))/0x6+parseInt(_0x27dd20(0x16b))/0x7+parseInt(_0x27dd20(0x154))/0x8*(-parseInt(_0x27dd20(0x16c))/0x9)+-parseInt(_0x27dd20(0x159))/0xa;if(_0x41e8e6===_0x570af5)break;else _0x51825a['push'](_0x51825a['shift']());}catch(_0x456075){_0x51825a['push'](_0x51825a['shift']());}}}(a46_0x31ea,0x61977));import{HTTPClient}from'../client/http-client.js';import{getEndpoint}from'../types/index.js';import{getAuthHeaders,getTrinoHeaders,toHeaderRecord}from'../core/auth.js';function a46_0x31ea(){const _0x3f23d6=['site','Failed\x20to\x20read\x20request\x20body\x20from\x20file:\x20','4vrXVMi','request','utf-8','apiKey','2795247aHeNbj','423PEZwNO','data','2201290QflYuu','26968OlZRvb','application/json','4VQnXnB','string','readBodyFromFile','11216470IzEoHI','GET','51706LClxxS','startsWith','stringify','3318omqFmw','context','status','Error:\x20','2208825XDTJCT','Content-Type','Endpoint\x20must\x20start\x20with\x20/:\x20'];a46_0x31ea=function(){return _0x3f23d6;};return a46_0x31ea();}import{readFileSync}from'fs';export class RawAPI{[a46_0x18265f(0x15f)];constructor(_0x1dee6b){const _0x333fe5=a46_0x18265f;this[_0x333fe5(0x15f)]=_0x1dee6b;}async[a46_0x18265f(0x168)](_0x48279a,_0x1282b7={}){const _0x4744f0=a46_0x18265f,{method:method=_0x4744f0(0x15a),body:_0x3e4a39,headers:_0x1ed94d={},apiType:apiType='td',includeHeaders:includeHeaders=![]}=_0x1282b7;if(!_0x48279a[_0x4744f0(0x15c)]('/'))throw new Error(_0x4744f0(0x164)+_0x48279a);const _0x1b9f51=getEndpoint(this['context'][_0x4744f0(0x165)],apiType);let _0x14b020;if(apiType==='trino'){const _0xb9e1ab=getTrinoHeaders(this[_0x4744f0(0x15f)][_0x4744f0(0x165)],this[_0x4744f0(0x15f)]['apiKey']);_0x14b020={..._0xb9e1ab,..._0x1ed94d};}else{const _0xb0304d=getAuthHeaders(this[_0x4744f0(0x15f)][_0x4744f0(0x165)],this[_0x4744f0(0x15f)][_0x4744f0(0x16a)]);_0x14b020={...toHeaderRecord(_0xb0304d),..._0x1ed94d};}const _0x177cc0=_0x14b020;let _0x48f2d3;_0x3e4a39!==undefined&&(_0x48f2d3=typeof _0x3e4a39===_0x4744f0(0x157)?_0x3e4a39:JSON[_0x4744f0(0x15d)](_0x3e4a39),!_0x177cc0[_0x4744f0(0x163)]&&(_0x177cc0['Content-Type']=_0x4744f0(0x155)));const _0x235389=new HTTPClient(_0x1b9f51,_0x177cc0,this[_0x4744f0(0x15f)]['logger']),_0x29086d=await _0x235389[_0x4744f0(0x168)](method,_0x48279a,{'body':_0x48f2d3,'includeHeaders':!![]});return includeHeaders?{'data':_0x29086d[_0x4744f0(0x152)],'status':_0x29086d['status'],'headers':_0x29086d['headers']}:{'data':_0x29086d[_0x4744f0(0x152)],'status':_0x29086d[_0x4744f0(0x160)]};}static[a46_0x18265f(0x158)](_0x9e7a30){const _0x4ecc61=a46_0x18265f;try{return readFileSync(_0x9e7a30,_0x4ecc61(0x169));}catch(_0x5a209a){throw new Error(_0x4ecc61(0x166)+_0x9e7a30+'.\x20'+(_0x4ecc61(0x161)+(_0x5a209a instanceof Error?_0x5a209a['message']:String(_0x5a209a))));}}}
1
+ const a46_0x530707=a46_0x1a89;(function(_0x2408d2,_0x19225e){const _0x401a53=a46_0x1a89,_0x3ee771=_0x2408d2();while(!![]){try{const _0x1bdbb1=-parseInt(_0x401a53(0x149))/0x1+-parseInt(_0x401a53(0x14d))/0x2+parseInt(_0x401a53(0x14f))/0x3+-parseInt(_0x401a53(0x154))/0x4*(parseInt(_0x401a53(0x155))/0x5)+-parseInt(_0x401a53(0x146))/0x6+parseInt(_0x401a53(0x140))/0x7*(-parseInt(_0x401a53(0x150))/0x8)+parseInt(_0x401a53(0x14c))/0x9;if(_0x1bdbb1===_0x19225e)break;else _0x3ee771['push'](_0x3ee771['shift']());}catch(_0x334f84){_0x3ee771['push'](_0x3ee771['shift']());}}}(a46_0x5478,0x6e0e9));function a46_0x1a89(_0x19b617,_0x581204){const _0x5478af=a46_0x5478();return a46_0x1a89=function(_0x1a89e8,_0x3bbb7a){_0x1a89e8=_0x1a89e8-0x13f;let _0x2329d7=_0x5478af[_0x1a89e8];return _0x2329d7;},a46_0x1a89(_0x19b617,_0x581204);}import{HTTPClient}from'../client/http-client.js';import{getEndpoint}from'../types/index.js';import{getAuthHeaders,getTrinoHeaders,toHeaderRecord}from'../core/auth.js';function a46_0x5478(){const _0x3e8a3c=['29864610RjVmXM','1696420waQKCj','status','571410uMwOyc','16HsHmSn','data','apiKey','utf-8','12GMsqVN','358335vnsEKb','headers','site','context','2759687TPsSSs','logger','stringify','Error:\x20','message','readBodyFromFile','4427628luQHJR','string','Content-Type','468336kkppsk','Endpoint\x20must\x20start\x20with\x20/:\x20','request'];a46_0x5478=function(){return _0x3e8a3c;};return a46_0x5478();}import{readFileSync}from'fs';export class RawAPI{[a46_0x530707(0x13f)];constructor(_0x4be78d){const _0x2cef1e=a46_0x530707;this[_0x2cef1e(0x13f)]=_0x4be78d;}async[a46_0x530707(0x14b)](_0x925880,_0xdfdbbf={}){const _0x16e44e=a46_0x530707,{method:method='GET',body:_0x52748f,headers:_0x418ba1={},apiType:apiType='td',includeHeaders:includeHeaders=![]}=_0xdfdbbf;if(!_0x925880['startsWith']('/'))throw new Error(_0x16e44e(0x14a)+_0x925880);const _0x5f1431=getEndpoint(this['context'][_0x16e44e(0x157)],apiType);let _0x5899fd;if(apiType==='trino'){const _0x228e66=getTrinoHeaders(this[_0x16e44e(0x13f)][_0x16e44e(0x157)],this['context'][_0x16e44e(0x152)]);_0x5899fd={..._0x228e66,..._0x418ba1};}else{const _0x173a84=getAuthHeaders(this['context'][_0x16e44e(0x157)],this[_0x16e44e(0x13f)][_0x16e44e(0x152)]);_0x5899fd={...toHeaderRecord(_0x173a84),..._0x418ba1};}const _0x263a91=_0x5899fd;let _0x2aa4fd;_0x52748f!==undefined&&(_0x2aa4fd=typeof _0x52748f===_0x16e44e(0x147)?_0x52748f:JSON[_0x16e44e(0x142)](_0x52748f),!_0x263a91[_0x16e44e(0x148)]&&(_0x263a91['Content-Type']='application/json'));const _0x3a53b3=new HTTPClient(_0x5f1431,_0x263a91,this[_0x16e44e(0x13f)][_0x16e44e(0x141)]),_0x23c7fb=await _0x3a53b3[_0x16e44e(0x14b)](method,_0x925880,{'body':_0x2aa4fd,'includeHeaders':!![]});return includeHeaders?{'data':_0x23c7fb[_0x16e44e(0x151)],'status':_0x23c7fb[_0x16e44e(0x14e)],'headers':_0x23c7fb[_0x16e44e(0x156)]}:{'data':_0x23c7fb[_0x16e44e(0x151)],'status':_0x23c7fb['status']};}static[a46_0x530707(0x145)](_0x530309){const _0x58ba98=a46_0x530707;try{return readFileSync(_0x530309,_0x58ba98(0x153));}catch(_0x146f9c){throw new Error('Failed\x20to\x20read\x20request\x20body\x20from\x20file:\x20'+_0x530309+'.\x20'+(_0x58ba98(0x143)+(_0x146f9c instanceof Error?_0x146f9c[_0x58ba98(0x144)]:String(_0x146f9c))));}}}
@@ -1 +1 @@
1
- const a47_0x572d2b=a47_0x18e7;(function(_0x2102e0,_0x21b002){const _0x71c0a7=a47_0x18e7,_0xe1a45a=_0x2102e0();while(!![]){try{const _0x1a4b3f=-parseInt(_0x71c0a7(0xb3))/0x1*(-parseInt(_0x71c0a7(0xcc))/0x2)+-parseInt(_0x71c0a7(0xda))/0x3+parseInt(_0x71c0a7(0xc4))/0x4+parseInt(_0x71c0a7(0xbc))/0x5*(-parseInt(_0x71c0a7(0xd4))/0x6)+parseInt(_0x71c0a7(0xb9))/0x7*(-parseInt(_0x71c0a7(0xb6))/0x8)+parseInt(_0x71c0a7(0xe5))/0x9*(parseInt(_0x71c0a7(0xba))/0xa)+-parseInt(_0x71c0a7(0xbb))/0xb;if(_0x1a4b3f===_0x21b002)break;else _0xe1a45a['push'](_0xe1a45a['shift']());}catch(_0x3dad37){_0xe1a45a['push'](_0xe1a45a['shift']());}}}(a47_0x5c6d,0xa73f8));export var ErrorCategory;(function(_0x30b48c){const _0x3b08e8=a47_0x18e7;_0x30b48c['USER_ERROR']=_0x3b08e8(0xc7),_0x30b48c[_0x3b08e8(0xdd)]=_0x3b08e8(0xdd);}(ErrorCategory||(ErrorCategory={})));export var ErrorCode;function a47_0x5c6d(){const _0x2c49bd=['name','COMMAND_NOT_FOUND','MISSING_ARGUMENT','code','stack','originalMessage','TRINO_NOT_FOUND','3748492qRPPjV','CHAT_NOT_FOUND','TRINO_INVALID_ARGUMENT','USER_ERROR','LLM_CHAT_CREATION_FAILURE','WORKFLOW_PROJECT_NOT_FOUND','LLM_EMPTY_MESSAGE','CANCELLED','12KpSozw','UNAUTHENTICATED','LLM_PROJECT_NOT_FOUND','TIMEOUT','some','isRetryable','category','NOT_FOUND','24qAUHpK','TRINO_USER_CANCELLED','LLM_MALFORMED_MESSAGE','TABLE_NOT_FOUND','SDKError','includes','1100838dldcVi','\x0aCaused\x20by:\x20','INSTALLATION_FAILED','INTERNAL_ERROR','LLM_STREAM_ERROR','RATE_LIMITED','replace','HTTP_REQUEST_FAILURE','PERMISSION_DENIED','TRINO_INSUFFICIENT_RESOURCES','message','11822616OZMtzC','DATABASE_NOT_FOUND','UNAVAILABLE','AGENT_NOT_FOUND','ALREADY_EXISTS','206509hdemxB','INTERNAL','INVALID_ARGUMENT','43424LKzHxw','cause','TRINO_INTERNAL_ERROR','854NpzQWk','10bdTxbE','12199429EBlmLf','833190mEXXxB'];a47_0x5c6d=function(){return _0x2c49bd;};return a47_0x5c6d();}(function(_0x302575){const _0x171bd7=a47_0x18e7;_0x302575['MISSING_ARGUMENT']='MISSING_ARGUMENT',_0x302575[_0x171bd7(0xb5)]=_0x171bd7(0xb5),_0x302575[_0x171bd7(0xd3)]=_0x171bd7(0xd3),_0x302575[_0x171bd7(0xe6)]=_0x171bd7(0xe6),_0x302575['TABLE_NOT_FOUND']=_0x171bd7(0xd7),_0x302575[_0x171bd7(0xce)]=_0x171bd7(0xce),_0x302575[_0x171bd7(0xe8)]=_0x171bd7(0xe8),_0x302575[_0x171bd7(0xc9)]='WORKFLOW_PROJECT_NOT_FOUND',_0x302575[_0x171bd7(0xc5)]='CHAT_NOT_FOUND',_0x302575[_0x171bd7(0xca)]=_0x171bd7(0xca),_0x302575[_0x171bd7(0xbe)]='COMMAND_NOT_FOUND',_0x302575[_0x171bd7(0xdc)]='INSTALLATION_FAILED',_0x302575[_0x171bd7(0xe2)]='PERMISSION_DENIED',_0x302575[_0x171bd7(0xcd)]=_0x171bd7(0xcd),_0x302575['ALREADY_EXISTS']='ALREADY_EXISTS',_0x302575[_0x171bd7(0xcb)]=_0x171bd7(0xcb),_0x302575['TRINO_SYNTAX_ERROR']='TRINO_SYNTAX_ERROR',_0x302575[_0x171bd7(0xc3)]=_0x171bd7(0xc3),_0x302575[_0x171bd7(0xc6)]='TRINO_INVALID_ARGUMENT',_0x302575['TRINO_USER_CANCELLED']=_0x171bd7(0xd5),_0x302575[_0x171bd7(0xe7)]=_0x171bd7(0xe7),_0x302575[_0x171bd7(0xcf)]='TIMEOUT',_0x302575[_0x171bd7(0xe1)]=_0x171bd7(0xe1),_0x302575[_0x171bd7(0xb4)]=_0x171bd7(0xb4),_0x302575[_0x171bd7(0xdf)]=_0x171bd7(0xdf),_0x302575[_0x171bd7(0xb8)]='TRINO_INTERNAL_ERROR',_0x302575[_0x171bd7(0xe3)]=_0x171bd7(0xe3),_0x302575[_0x171bd7(0xd6)]=_0x171bd7(0xd6),_0x302575[_0x171bd7(0xde)]=_0x171bd7(0xde),_0x302575[_0x171bd7(0xc8)]=_0x171bd7(0xc8);}(ErrorCode||(ErrorCode={})));const ERROR_CODE_CATEGORY={[ErrorCode[a47_0x572d2b(0xbf)]]:ErrorCategory[a47_0x572d2b(0xc7)],[ErrorCode[a47_0x572d2b(0xb5)]]:ErrorCategory[a47_0x572d2b(0xc7)],[ErrorCode[a47_0x572d2b(0xd3)]]:ErrorCategory[a47_0x572d2b(0xc7)],[ErrorCode[a47_0x572d2b(0xe6)]]:ErrorCategory['USER_ERROR'],[ErrorCode[a47_0x572d2b(0xd7)]]:ErrorCategory[a47_0x572d2b(0xc7)],[ErrorCode[a47_0x572d2b(0xce)]]:ErrorCategory['USER_ERROR'],[ErrorCode[a47_0x572d2b(0xe8)]]:ErrorCategory[a47_0x572d2b(0xc7)],[ErrorCode[a47_0x572d2b(0xc9)]]:ErrorCategory['USER_ERROR'],[ErrorCode[a47_0x572d2b(0xc5)]]:ErrorCategory['USER_ERROR'],[ErrorCode[a47_0x572d2b(0xca)]]:ErrorCategory[a47_0x572d2b(0xc7)],[ErrorCode['COMMAND_NOT_FOUND']]:ErrorCategory[a47_0x572d2b(0xc7)],[ErrorCode['INSTALLATION_FAILED']]:ErrorCategory[a47_0x572d2b(0xc7)],[ErrorCode[a47_0x572d2b(0xe2)]]:ErrorCategory[a47_0x572d2b(0xc7)],[ErrorCode[a47_0x572d2b(0xcd)]]:ErrorCategory[a47_0x572d2b(0xc7)],[ErrorCode[a47_0x572d2b(0xb2)]]:ErrorCategory['USER_ERROR'],[ErrorCode[a47_0x572d2b(0xcb)]]:ErrorCategory[a47_0x572d2b(0xc7)],[ErrorCode['TRINO_SYNTAX_ERROR']]:ErrorCategory[a47_0x572d2b(0xc7)],[ErrorCode['TRINO_NOT_FOUND']]:ErrorCategory[a47_0x572d2b(0xc7)],[ErrorCode['TRINO_INVALID_ARGUMENT']]:ErrorCategory[a47_0x572d2b(0xc7)],[ErrorCode['TRINO_USER_CANCELLED']]:ErrorCategory['USER_ERROR'],[ErrorCode[a47_0x572d2b(0xe7)]]:ErrorCategory[a47_0x572d2b(0xdd)],[ErrorCode[a47_0x572d2b(0xcf)]]:ErrorCategory[a47_0x572d2b(0xdd)],[ErrorCode[a47_0x572d2b(0xe1)]]:ErrorCategory[a47_0x572d2b(0xdd)],[ErrorCode['INTERNAL']]:ErrorCategory[a47_0x572d2b(0xdd)],[ErrorCode[a47_0x572d2b(0xdf)]]:ErrorCategory[a47_0x572d2b(0xdd)],[ErrorCode[a47_0x572d2b(0xb8)]]:ErrorCategory[a47_0x572d2b(0xdd)],[ErrorCode['TRINO_INSUFFICIENT_RESOURCES']]:ErrorCategory[a47_0x572d2b(0xdd)],[ErrorCode['LLM_MALFORMED_MESSAGE']]:ErrorCategory[a47_0x572d2b(0xdd)],[ErrorCode[a47_0x572d2b(0xde)]]:ErrorCategory[a47_0x572d2b(0xdd)],[ErrorCode[a47_0x572d2b(0xc8)]]:ErrorCategory[a47_0x572d2b(0xdd)]};export function getErrorCategory(_0x4afc80){return ERROR_CODE_CATEGORY[_0x4afc80];}function a47_0x18e7(_0x143b64,_0x34be0c){const _0x5c6dad=a47_0x5c6d();return a47_0x18e7=function(_0x18e705,_0x530c9f){_0x18e705=_0x18e705-0xb2;let _0x12475b=_0x5c6dad[_0x18e705];return _0x12475b;},a47_0x18e7(_0x143b64,_0x34be0c);}export function isRetryableError(_0x11478d){const _0x67662b=a47_0x572d2b;return getErrorCategory(_0x11478d)===ErrorCategory[_0x67662b(0xdd)];}export class SDKError extends Error{[a47_0x572d2b(0xc0)];['helpText'];[a47_0x572d2b(0xb7)];constructor(_0x105b54,_0x55a69d,_0x590fa6,_0x2e821c){const _0x1d8508=a47_0x572d2b;super('['+_0x105b54+']\x20'+_0x55a69d),this[_0x1d8508(0xbd)]=_0x1d8508(0xd8),this['code']=_0x105b54,this['helpText']=_0x2e821c?.['helpText'],this['cause']=_0x590fa6,_0x590fa6 instanceof Error&&(this[_0x1d8508(0xc1)]=this['stack']+_0x1d8508(0xdb)+_0x590fa6[_0x1d8508(0xc1)]);}get[a47_0x572d2b(0xd2)](){const _0x58c50d=a47_0x572d2b;return getErrorCategory(this[_0x58c50d(0xc0)]);}[a47_0x572d2b(0xd1)](){const _0x482568=a47_0x572d2b;return isRetryableError(this[_0x482568(0xc0)]);}get[a47_0x572d2b(0xc2)](){const _0x50a88e=a47_0x572d2b;return this['message'][_0x50a88e(0xe0)](/^\[.*?\]\s*/,'');}}export function errorContains(_0x478d3d,..._0xb70621){const _0x1264fb=a47_0x572d2b,_0x3189cf=_0x478d3d?.['message']||'',_0x24a499=_0x478d3d?.['cause'],_0x148710=_0x24a499?.[_0x1264fb(0xe4)]||'';return _0xb70621[_0x1264fb(0xd0)](_0x3611ed=>_0x3189cf[_0x1264fb(0xd9)](_0x3611ed)||_0x148710[_0x1264fb(0xd9)](_0x3611ed));}
1
+ const a47_0x4385df=a47_0x2a27;function a47_0x2a27(_0x12e72e,_0x383dac){const _0x1790b9=a47_0x1790();return a47_0x2a27=function(_0x2a276e,_0xb35b5c){_0x2a276e=_0x2a276e-0x112;let _0x393f06=_0x1790b9[_0x2a276e];return _0x393f06;},a47_0x2a27(_0x12e72e,_0x383dac);}(function(_0x5b47b8,_0x2cc229){const _0x37db7a=a47_0x2a27,_0x68e466=_0x5b47b8();while(!![]){try{const _0x3b1fae=parseInt(_0x37db7a(0x12a))/0x1*(parseInt(_0x37db7a(0x141))/0x2)+-parseInt(_0x37db7a(0x11e))/0x3*(parseInt(_0x37db7a(0x134))/0x4)+parseInt(_0x37db7a(0x12e))/0x5*(-parseInt(_0x37db7a(0x120))/0x6)+-parseInt(_0x37db7a(0x125))/0x7+parseInt(_0x37db7a(0x143))/0x8+parseInt(_0x37db7a(0x11b))/0x9+parseInt(_0x37db7a(0x11f))/0xa*(parseInt(_0x37db7a(0x140))/0xb);if(_0x3b1fae===_0x2cc229)break;else _0x68e466['push'](_0x68e466['shift']());}catch(_0x393dcd){_0x68e466['push'](_0x68e466['shift']());}}}(a47_0x1790,0x4dfc6));export var ErrorCategory;(function(_0x2c2d5a){const _0x6076e=a47_0x2a27;_0x2c2d5a['USER_ERROR']=_0x6076e(0x145),_0x2c2d5a['INTERNAL_ERROR']=_0x6076e(0x123);}(ErrorCategory||(ErrorCategory={})));export var ErrorCode;function a47_0x1790(){const _0x4cd7fc=['category','message','code','CANCELLED','replace','TRINO_INTERNAL_ERROR','UNAUTHENTICATED','\x0aCaused\x20by:\x20','CHAT_NOT_FOUND','ALREADY_EXISTS','1809855YmvToJ','NOT_FOUND','LLM_EMPTY_MESSAGE','408XkyPQu','5023270fGecIL','6wPRkpn','LLM_PROJECT_NOT_FOUND','AGENT_NOT_FOUND','INTERNAL_ERROR','INTERNAL','2055060nefawp','RATE_LIMITED','isRetryable','UNAVAILABLE','helpText','37594SiCDmT','INSTALLATION_FAILED','COMMAND_NOT_FOUND','originalMessage','998365uJgRue','TIMEOUT','HTTP_REQUEST_FAILURE','cause','includes','LLM_MALFORMED_MESSAGE','10016JHWAbc','PERMISSION_DENIED','stack','LLM_STREAM_ERROR','TABLE_NOT_FOUND','TRINO_INSUFFICIENT_RESOURCES','TRINO_USER_CANCELLED','TRINO_INVALID_ARGUMENT','MISSING_ARGUMENT','DATABASE_NOT_FOUND','WORKFLOW_PROJECT_NOT_FOUND','TRINO_SYNTAX_ERROR','11VyEjLI','20yRgpfh','INVALID_ARGUMENT','590920USjdUE','name','USER_ERROR','LLM_CHAT_CREATION_FAILURE','some','TRINO_NOT_FOUND'];a47_0x1790=function(){return _0x4cd7fc;};return a47_0x1790();}(function(_0x1c97de){const _0x580495=a47_0x2a27;_0x1c97de[_0x580495(0x13c)]=_0x580495(0x13c),_0x1c97de['INVALID_ARGUMENT']=_0x580495(0x142),_0x1c97de[_0x580495(0x11c)]='NOT_FOUND',_0x1c97de[_0x580495(0x13d)]=_0x580495(0x13d),_0x1c97de[_0x580495(0x138)]=_0x580495(0x138),_0x1c97de[_0x580495(0x121)]='LLM_PROJECT_NOT_FOUND',_0x1c97de[_0x580495(0x122)]=_0x580495(0x122),_0x1c97de[_0x580495(0x13e)]=_0x580495(0x13e),_0x1c97de[_0x580495(0x119)]='CHAT_NOT_FOUND',_0x1c97de[_0x580495(0x11d)]=_0x580495(0x11d),_0x1c97de[_0x580495(0x12c)]=_0x580495(0x12c),_0x1c97de[_0x580495(0x12b)]=_0x580495(0x12b),_0x1c97de[_0x580495(0x135)]=_0x580495(0x135),_0x1c97de['UNAUTHENTICATED']=_0x580495(0x117),_0x1c97de[_0x580495(0x11a)]=_0x580495(0x11a),_0x1c97de[_0x580495(0x114)]='CANCELLED',_0x1c97de[_0x580495(0x13f)]=_0x580495(0x13f),_0x1c97de['TRINO_NOT_FOUND']=_0x580495(0x148),_0x1c97de[_0x580495(0x13b)]=_0x580495(0x13b),_0x1c97de[_0x580495(0x13a)]='TRINO_USER_CANCELLED',_0x1c97de[_0x580495(0x128)]='UNAVAILABLE',_0x1c97de[_0x580495(0x12f)]=_0x580495(0x12f),_0x1c97de[_0x580495(0x130)]=_0x580495(0x130),_0x1c97de[_0x580495(0x124)]=_0x580495(0x124),_0x1c97de[_0x580495(0x126)]=_0x580495(0x126),_0x1c97de[_0x580495(0x116)]=_0x580495(0x116),_0x1c97de[_0x580495(0x139)]=_0x580495(0x139),_0x1c97de[_0x580495(0x133)]=_0x580495(0x133),_0x1c97de[_0x580495(0x137)]=_0x580495(0x137),_0x1c97de[_0x580495(0x146)]=_0x580495(0x146);}(ErrorCode||(ErrorCode={})));const ERROR_CODE_CATEGORY={[ErrorCode[a47_0x4385df(0x13c)]]:ErrorCategory['USER_ERROR'],[ErrorCode[a47_0x4385df(0x142)]]:ErrorCategory[a47_0x4385df(0x145)],[ErrorCode['NOT_FOUND']]:ErrorCategory[a47_0x4385df(0x145)],[ErrorCode[a47_0x4385df(0x13d)]]:ErrorCategory['USER_ERROR'],[ErrorCode[a47_0x4385df(0x138)]]:ErrorCategory[a47_0x4385df(0x145)],[ErrorCode['LLM_PROJECT_NOT_FOUND']]:ErrorCategory['USER_ERROR'],[ErrorCode[a47_0x4385df(0x122)]]:ErrorCategory[a47_0x4385df(0x145)],[ErrorCode[a47_0x4385df(0x13e)]]:ErrorCategory[a47_0x4385df(0x145)],[ErrorCode['CHAT_NOT_FOUND']]:ErrorCategory[a47_0x4385df(0x145)],[ErrorCode[a47_0x4385df(0x11d)]]:ErrorCategory[a47_0x4385df(0x145)],[ErrorCode[a47_0x4385df(0x12c)]]:ErrorCategory[a47_0x4385df(0x145)],[ErrorCode[a47_0x4385df(0x12b)]]:ErrorCategory['USER_ERROR'],[ErrorCode[a47_0x4385df(0x135)]]:ErrorCategory[a47_0x4385df(0x145)],[ErrorCode[a47_0x4385df(0x117)]]:ErrorCategory[a47_0x4385df(0x145)],[ErrorCode[a47_0x4385df(0x11a)]]:ErrorCategory[a47_0x4385df(0x145)],[ErrorCode['CANCELLED']]:ErrorCategory[a47_0x4385df(0x145)],[ErrorCode[a47_0x4385df(0x13f)]]:ErrorCategory[a47_0x4385df(0x145)],[ErrorCode[a47_0x4385df(0x148)]]:ErrorCategory[a47_0x4385df(0x145)],[ErrorCode[a47_0x4385df(0x13b)]]:ErrorCategory[a47_0x4385df(0x145)],[ErrorCode['TRINO_USER_CANCELLED']]:ErrorCategory[a47_0x4385df(0x145)],[ErrorCode['UNAVAILABLE']]:ErrorCategory['INTERNAL_ERROR'],[ErrorCode[a47_0x4385df(0x12f)]]:ErrorCategory[a47_0x4385df(0x123)],[ErrorCode[a47_0x4385df(0x130)]]:ErrorCategory[a47_0x4385df(0x123)],[ErrorCode[a47_0x4385df(0x124)]]:ErrorCategory[a47_0x4385df(0x123)],[ErrorCode[a47_0x4385df(0x126)]]:ErrorCategory[a47_0x4385df(0x123)],[ErrorCode['TRINO_INTERNAL_ERROR']]:ErrorCategory[a47_0x4385df(0x123)],[ErrorCode['TRINO_INSUFFICIENT_RESOURCES']]:ErrorCategory['INTERNAL_ERROR'],[ErrorCode[a47_0x4385df(0x133)]]:ErrorCategory[a47_0x4385df(0x123)],[ErrorCode['LLM_STREAM_ERROR']]:ErrorCategory[a47_0x4385df(0x123)],[ErrorCode[a47_0x4385df(0x146)]]:ErrorCategory[a47_0x4385df(0x123)]};export function getErrorCategory(_0x3f7ec8){return ERROR_CODE_CATEGORY[_0x3f7ec8];}export function isRetryableError(_0x653604){const _0xd8ea04=a47_0x4385df;return getErrorCategory(_0x653604)===ErrorCategory[_0xd8ea04(0x123)];}export class SDKError extends Error{[a47_0x4385df(0x113)];[a47_0x4385df(0x129)];[a47_0x4385df(0x131)];constructor(_0x48d094,_0x3d877d,_0x29c2ac,_0x154d49){const _0x20a86b=a47_0x4385df;super('['+_0x48d094+']\x20'+_0x3d877d),this[_0x20a86b(0x144)]='SDKError',this[_0x20a86b(0x113)]=_0x48d094,this[_0x20a86b(0x129)]=_0x154d49?.['helpText'],this[_0x20a86b(0x131)]=_0x29c2ac,_0x29c2ac instanceof Error&&(this[_0x20a86b(0x136)]=this[_0x20a86b(0x136)]+_0x20a86b(0x118)+_0x29c2ac[_0x20a86b(0x136)]);}get[a47_0x4385df(0x149)](){return getErrorCategory(this['code']);}[a47_0x4385df(0x127)](){const _0x583c1d=a47_0x4385df;return isRetryableError(this[_0x583c1d(0x113)]);}get[a47_0x4385df(0x12d)](){const _0x52b6dd=a47_0x4385df;return this[_0x52b6dd(0x112)][_0x52b6dd(0x115)](/^\[.*?\]\s*/,'');}}export function errorContains(_0x46e988,..._0x503990){const _0x1a5905=a47_0x4385df,_0x27bc86=_0x46e988?.['message']||'',_0x5e25e1=_0x46e988?.[_0x1a5905(0x131)],_0x53b6bb=_0x5e25e1?.[_0x1a5905(0x112)]||'';return _0x503990[_0x1a5905(0x147)](_0x9739e9=>_0x27bc86['includes'](_0x9739e9)||_0x53b6bb[_0x1a5905(0x132)](_0x9739e9));}
package/dist/sdk/index.js CHANGED
@@ -1 +1 @@
1
- const a48_0x5ec918=a48_0x1a9d;(function(_0x259331,_0x2efb7a){const _0x490555=a48_0x1a9d,_0x5f00f0=_0x259331();while(!![]){try{const _0x2f92ee=parseInt(_0x490555(0x83))/0x1*(parseInt(_0x490555(0x7b))/0x2)+-parseInt(_0x490555(0x8c))/0x3*(parseInt(_0x490555(0x91))/0x4)+-parseInt(_0x490555(0x8e))/0x5*(parseInt(_0x490555(0x7f))/0x6)+parseInt(_0x490555(0x8a))/0x7+parseInt(_0x490555(0x85))/0x8+-parseInt(_0x490555(0x8f))/0x9+parseInt(_0x490555(0x87))/0xa;if(_0x2f92ee===_0x2efb7a)break;else _0x5f00f0['push'](_0x5f00f0['shift']());}catch(_0x19b6a9){_0x5f00f0['push'](_0x5f00f0['shift']());}}}(a48_0x333b,0x23560));import{loadUserConfigOnce,getAPIKey}from'../core/config.js';import{SegmentSDK}from'./segment.js';import{WorkflowSDK}from'./workflow.js';import{LLMSDK}from'./llm.js';import{JobSDK}from'./job.js';import{RawAPI}from'./api.js';import{QuerySDK}from'./query.js';function a48_0x333b(){const _0x3765a5=['us01','workflow','1166123ECDryN','jobs','723BMiKNo','create','3475YjAKaR','1774053rgSGhz','logLevel','1252SfblQK','init','26goZUTV','api','INFO','llm','60cyOOSZ','apiKey','logger','context','577XJCxsL','query','773576ICEzpc','catch','1534490lYgcmx'];a48_0x333b=function(){return _0x3765a5;};return a48_0x333b();}import{LogLevel,TDXLogger}from'../utils/tdx-logger.js';export*from'./errors.js';export*from'./segment.js';export*from'./workflow.js';export*from'./llm.js';export*from'./job.js';export*from'./api.js';export*from'./query.js';function a48_0x1a9d(_0x3ea6fc,_0x4cf839){const _0x333b9e=a48_0x333b();return a48_0x1a9d=function(_0x1a9dfe,_0x40a152){_0x1a9dfe=_0x1a9dfe-0x7b;let _0x41218e=_0x333b9e[_0x1a9dfe];return _0x41218e;},a48_0x1a9d(_0x3ea6fc,_0x4cf839);}export{LogLevel}from'../utils/tdx-logger.js';export class TDX{[a48_0x5ec918(0x82)];[a48_0x5ec918(0x84)];['segment'];[a48_0x5ec918(0x89)];['llm'];[a48_0x5ec918(0x8b)];['api'];static[a48_0x5ec918(0x8d)](_0x2e321a={}){const _0x23883f=a48_0x5ec918,_0x1574db=_0x2e321a['site']||_0x23883f(0x88),_0x720501=_0x2e321a[_0x23883f(0x90)]??LogLevel[_0x23883f(0x7d)];let _0x2d2fe3=_0x2e321a[_0x23883f(0x80)];!_0x2d2fe3&&(loadUserConfigOnce(),_0x2d2fe3=getAPIKey(_0x1574db));const _0x30ae0d=new TDXLogger(_0x720501,!![]);return _0x30ae0d[_0x23883f(0x92)]()[_0x23883f(0x86)](()=>{}),new TDX({'site':_0x1574db,'apiKey':_0x2d2fe3,'logLevel':_0x720501,'logger':_0x30ae0d});}constructor(_0x3f3f62){const _0x5cef1e=a48_0x5ec918;this[_0x5cef1e(0x82)]=_0x3f3f62,this[_0x5cef1e(0x84)]=new QuerySDK(_0x3f3f62),this['segment']=new SegmentSDK(_0x3f3f62),this[_0x5cef1e(0x89)]=new WorkflowSDK(_0x3f3f62),this[_0x5cef1e(0x7e)]=new LLMSDK(_0x3f3f62),this[_0x5cef1e(0x8b)]=new JobSDK(_0x3f3f62),this[_0x5cef1e(0x7c)]=new RawAPI(_0x3f3f62);}get[a48_0x5ec918(0x81)](){const _0x1a9223=a48_0x5ec918;return this[_0x1a9223(0x82)]['logger'];}}
1
+ const a48_0x1a3b13=a48_0x5b3d;(function(_0x38955a,_0x5ea0c3){const _0x48163d=a48_0x5b3d,_0x571502=_0x38955a();while(!![]){try{const _0x324829=parseInt(_0x48163d(0x13b))/0x1*(parseInt(_0x48163d(0x139))/0x2)+-parseInt(_0x48163d(0x12f))/0x3*(parseInt(_0x48163d(0x12d))/0x4)+-parseInt(_0x48163d(0x13e))/0x5+-parseInt(_0x48163d(0x135))/0x6*(parseInt(_0x48163d(0x138))/0x7)+-parseInt(_0x48163d(0x129))/0x8*(-parseInt(_0x48163d(0x12b))/0x9)+parseInt(_0x48163d(0x128))/0xa+-parseInt(_0x48163d(0x134))/0xb*(-parseInt(_0x48163d(0x133))/0xc);if(_0x324829===_0x5ea0c3)break;else _0x571502['push'](_0x571502['shift']());}catch(_0x569466){_0x571502['push'](_0x571502['shift']());}}}(a48_0x2671,0xb16db));import{loadUserConfigOnce,getAPIKey}from'../core/config.js';import{SegmentSDK}from'./segment.js';import{WorkflowSDK}from'./workflow.js';import{LLMSDK}from'./llm.js';import{JobSDK}from'./job.js';import{RawAPI}from'./api.js';import{QuerySDK}from'./query.js';import{LogLevel,TDXLogger}from'../utils/tdx-logger.js';export*from'./errors.js';export*from'./segment.js';function a48_0x2671(){const _0x537b80=['apiKey','1216845xhLbJw','catch','site','11372980UZqwot','101856nnutiI','INFO','9BAsGpW','jobs','2228TcnppM','api','4155kBydCp','logger','segment','logLevel','9708YGCduF','341AxXkhH','6HFonPt','workflow','query','4214959cpwkkC','218uvwjns','context','10721MCIUdq','create'];a48_0x2671=function(){return _0x537b80;};return a48_0x2671();}export*from'./workflow.js';export*from'./llm.js';function a48_0x5b3d(_0x5f5bab,_0xb9866){const _0x26711c=a48_0x2671();return a48_0x5b3d=function(_0x5b3d73,_0x286cd3){_0x5b3d73=_0x5b3d73-0x126;let _0x2ccb60=_0x26711c[_0x5b3d73];return _0x2ccb60;},a48_0x5b3d(_0x5f5bab,_0xb9866);}export*from'./job.js';export*from'./api.js';export*from'./query.js';export{LogLevel}from'../utils/tdx-logger.js';export class TDX{[a48_0x1a3b13(0x13a)];[a48_0x1a3b13(0x137)];[a48_0x1a3b13(0x131)];[a48_0x1a3b13(0x136)];['llm'];[a48_0x1a3b13(0x12c)];['api'];static[a48_0x1a3b13(0x13c)](_0x58804b={}){const _0x49496e=a48_0x1a3b13,_0x31cdf3=_0x58804b[_0x49496e(0x127)]||'us01',_0x20488e=_0x58804b[_0x49496e(0x132)]??LogLevel[_0x49496e(0x12a)];let _0x14d0d3=_0x58804b[_0x49496e(0x13d)];!_0x14d0d3&&(loadUserConfigOnce(),_0x14d0d3=getAPIKey(_0x31cdf3));const _0x113887=new TDXLogger(_0x20488e,!![]);return _0x113887['init']()[_0x49496e(0x126)](()=>{}),new TDX({'site':_0x31cdf3,'apiKey':_0x14d0d3,'logLevel':_0x20488e,'logger':_0x113887});}constructor(_0x42e730){const _0x4e46c9=a48_0x1a3b13;this[_0x4e46c9(0x13a)]=_0x42e730,this[_0x4e46c9(0x137)]=new QuerySDK(_0x42e730),this[_0x4e46c9(0x131)]=new SegmentSDK(_0x42e730),this[_0x4e46c9(0x136)]=new WorkflowSDK(_0x42e730),this['llm']=new LLMSDK(_0x42e730),this[_0x4e46c9(0x12c)]=new JobSDK(_0x42e730),this[_0x4e46c9(0x12e)]=new RawAPI(_0x42e730);}get[a48_0x1a3b13(0x130)](){const _0x117c91=a48_0x1a3b13;return this['context'][_0x117c91(0x130)];}}