@treasuredata/tdx 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build-info.json +2 -2
- package/dist/cli.js +1 -1
- package/dist/client/cdp-client.js +1 -1
- package/dist/client/http-client.js +1 -1
- package/dist/client/llm-client.d.ts +1 -0
- package/dist/client/llm-client.d.ts.map +1 -1
- package/dist/client/llm-client.js +1 -1
- package/dist/client/llm-client.js.map +1 -1
- package/dist/client/rate-limiter.js +1 -1
- package/dist/client/td-client.js +1 -1
- package/dist/client/trino-client.js +1 -1
- package/dist/client/workflow-client.js +1 -1
- package/dist/commands/activations.js +1 -1
- package/dist/commands/api-command.js +1 -1
- package/dist/commands/chat-command.js +1 -1
- package/dist/commands/claude-command.js +1 -1
- package/dist/commands/command.js +1 -1
- package/dist/commands/context-command.js +1 -1
- package/dist/commands/databases.js +1 -1
- package/dist/commands/describe.js +1 -1
- package/dist/commands/job-command.js +1 -1
- package/dist/commands/llm-command.js +1 -1
- package/dist/commands/llm-proxy.js +1 -1
- package/dist/commands/parent-segment-command.js +1 -1
- package/dist/commands/profiles-command.js +1 -1
- package/dist/commands/query-command.js +1 -1
- package/dist/commands/segment-command.js +1 -1
- package/dist/commands/segment-create-command.js +1 -1
- package/dist/commands/segment-fields-command.js +1 -1
- package/dist/commands/segment-pwd-command.js +1 -1
- package/dist/commands/segment-update-command.js +1 -1
- package/dist/commands/segment-use-command.js +1 -1
- package/dist/commands/segments.js +1 -1
- package/dist/commands/show.js +1 -1
- package/dist/commands/tables.js +1 -1
- package/dist/commands/use-command.js +1 -1
- package/dist/commands/workflow-command.js +1 -1
- package/dist/core/auth.js +1 -1
- package/dist/core/config.js +1 -1
- package/dist/core/global-context.js +1 -1
- package/dist/core/profile.js +1 -1
- package/dist/core/project-config.js +1 -1
- package/dist/core/session.js +1 -1
- package/dist/index.js +1 -1
- package/dist/proxy/anthropic-adapter.d.ts +9 -1
- package/dist/proxy/anthropic-adapter.d.ts.map +1 -1
- package/dist/proxy/anthropic-adapter.js +1 -1
- package/dist/proxy/anthropic-adapter.js.map +1 -1
- package/dist/proxy/server.d.ts.map +1 -1
- package/dist/proxy/server.js +1 -1
- package/dist/proxy/server.js.map +1 -1
- package/dist/proxy/session-cache.js +1 -1
- package/dist/sdk/api.js +1 -1
- package/dist/sdk/database.js +1 -1
- package/dist/sdk/errors.js +1 -1
- package/dist/sdk/index.js +1 -1
- package/dist/sdk/job.js +1 -1
- package/dist/sdk/llm.js +1 -1
- package/dist/sdk/query.js +1 -1
- package/dist/sdk/segment.js +1 -1
- package/dist/sdk/table.js +1 -1
- package/dist/sdk/workflow.js +1 -1
- package/dist/types/anthropic.d.ts +3 -2
- package/dist/types/anthropic.d.ts.map +1 -1
- package/dist/types/endpoints.js +1 -1
- package/dist/types/index.js +1 -1
- package/dist/utils/agent-ref-parser.js +1 -1
- package/dist/utils/chat-cache.js +1 -1
- package/dist/utils/colors.js +1 -1
- package/dist/utils/command-output.js +1 -1
- package/dist/utils/constants.js +1 -1
- package/dist/utils/file-permissions.js +1 -1
- package/dist/utils/format-detector.js +1 -1
- package/dist/utils/formatters.js +1 -1
- package/dist/utils/json-loader.js +1 -1
- package/dist/utils/model-aliases.js +1 -1
- package/dist/utils/option-validation.js +1 -1
- package/dist/utils/port.js +1 -1
- package/dist/utils/process.js +1 -1
- package/dist/utils/prompt.js +1 -1
- package/dist/utils/segment-path-parser.js +1 -1
- package/dist/utils/segment-ref-parser.js +1 -1
- package/dist/utils/spinner.js +1 -1
- package/dist/utils/sql-parser.js +1 -1
- package/dist/utils/sse-parser.js +1 -1
- package/dist/utils/string-utils.js +1 -1
- package/dist/utils/table-ref-parser.js +1 -1
- package/dist/utils/tdx-logger.js +1 -1
- package/dist/utils/tree-formatter.js +1 -1
- package/dist/utils/version-check.js +1 -1
- package/dist/utils/workflow-utils.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const a35_0x32757a=a35_0x498f;(function(_0x47f890,_0x184700){const _0x3f4383=a35_0x498f,_0x4abf13=_0x47f890();while(!![]){try{const _0x2cf210=parseInt(_0x3f4383(0xd3))/0x1+parseInt(_0x3f4383(0xb0))/0x2*(parseInt(_0x3f4383(0xe4))/0x3)+parseInt(_0x3f4383(0xd4))/0x4*(-parseInt(_0x3f4383(0xb7))/0x5)+parseInt(_0x3f4383(0xcb))/0x6*(parseInt(_0x3f4383(0xe3))/0x7)+-parseInt(_0x3f4383(0xe9))/0x8*(parseInt(_0x3f4383(0xde))/0x9)+-parseInt(_0x3f4383(0xe5))/0xa+parseInt(_0x3f4383(0xe1))/0xb;if(_0x2cf210===_0x184700)break;else _0x4abf13['push'](_0x4abf13['shift']());}catch(_0x4499c4){_0x4abf13['push'](_0x4abf13['shift']());}}}(a35_0x47fc,0x700e2));import{resolveSite,getAPIKey,getConfigDir}from'./config.js';import{loadSessionContext}from'./session.js';import{loadProjectConfig,findProjectConfigPath}from'./project-config.js';import{getActiveProfile,loadProfile}from'./profile.js';import{LogLevel}from'../utils/tdx-logger.js';function a35_0x498f(_0x29d734,_0xe0d093){const _0x47fced=a35_0x47fc();return a35_0x498f=function(_0x498f93,_0x4255e5){_0x498f93=_0x498f93-0xab;let _0x36f6aa=_0x47fced[_0x498f93];return _0x36f6aa;},a35_0x498f(_0x29d734,_0xe0d093);}function a35_0x47fc(){const _0xab5b4b=['8421435xnTrwE','displayWithSources','28UvpwPh','58173KVEehr','9073820KAeXBK','INFO','config','sessionId','11912DhYXYA','profile:\x20','configFiles','log','toString',':\x20none','database','segmentPath','display','session','10lkxYPP','getParameters','loadGlobalConfig','.env','[context]','utf-8','replace','30pgGpLl','parse','verbose','parentSegment','logLevel','Global\x20Credentials','Session','segment_path','llmProject','Global','layers','activeProfile','us01','.json','default','globalCredentials','apiKey','parent_segment','(session:\x20','tdx.json','854448SxFXBf','string','llm_project','Profile\x20Credentials','getSource','sessions','profiles','Project','844223rGpUTQ','157012ZfYWcr','entries','injectIntoOptions','readFileSync','join','(active)','project','site','not\x20set','existsSync','4077orEZQT','profile','global'];a35_0x47fc=function(){return _0xab5b4b;};return a35_0x47fc();}import*as a35_0x405dec from'node:fs';import*as a35_0x581336 from'node:path';export class GlobalContext{[a35_0x32757a(0xdb)];[a35_0x32757a(0xac)];['parent_segment'];['segment_path'];[a35_0x32757a(0xcd)];[a35_0x32757a(0xc7)];[a35_0x32757a(0xb9)];[a35_0x32757a(0xbb)];[a35_0x32757a(0xc1)];['activeProfile'];['sessionId'];[a35_0x32757a(0xeb)];constructor(_0x5a54c8){const _0x1350e6=a35_0x32757a;this[_0x1350e6(0xe8)]=_0x5a54c8[_0x1350e6(0xaf)]||process['ppid'][_0x1350e6(0xed)]();const _0x2c954e=loadSessionContext(_0x5a54c8[_0x1350e6(0xaf)]),_0x34d380=loadProjectConfig(),_0x57b9a3=this[_0x1350e6(0xb2)]();this[_0x1350e6(0xc2)]=_0x5a54c8['profile']||_0x2c954e?.[_0x1350e6(0xdf)]||_0x57b9a3[_0x1350e6(0xdf)]||getActiveProfile();const _0x343268=this['activeProfile']?loadProfile(this[_0x1350e6(0xc2)]):null,_0x26ccc7=_0x4ff5a1=>{const _0x1673b3=_0x1350e6;if(!_0x4ff5a1)return{};const _0x2388ff=_0x4ff5a1,_0x5925e9={};for(const [_0x9e7c8b,_0xb5c5d8]of Object[_0x1673b3(0xd5)](_0x2388ff)){typeof _0xb5c5d8===_0x1673b3(0xcc)&&(_0x5925e9[_0x9e7c8b]=_0xb5c5d8);}return _0x5925e9;},_0xea74f3={};if(_0x5a54c8[_0x1350e6(0xdb)]&&_0x5a54c8['site']!==_0x1350e6(0xc3))_0xea74f3[_0x1350e6(0xdb)]=_0x5a54c8[_0x1350e6(0xdb)];const _0x471554=_0x2c954e?.[_0x1350e6(0xac)],_0x3031c9=_0x34d380?.[_0x1350e6(0xac)],_0x5155df=_0x343268?.['config']?.[_0x1350e6(0xac)],_0x51bf4e=_0x57b9a3[_0x1350e6(0xac)];_0x5a54c8['database']&&(_0x5a54c8[_0x1350e6(0xac)]!==_0x471554&&_0x5a54c8[_0x1350e6(0xac)]!==_0x3031c9&&_0x5a54c8['database']!==_0x5155df&&_0x5a54c8[_0x1350e6(0xac)]!==_0x51bf4e)&&(_0xea74f3[_0x1350e6(0xac)]=_0x5a54c8[_0x1350e6(0xac)]);if(_0x5a54c8[_0x1350e6(0xba)])_0xea74f3[_0x1350e6(0xc8)]=_0x5a54c8[_0x1350e6(0xba)];if(_0x5a54c8[_0x1350e6(0xbf)])_0xea74f3[_0x1350e6(0xcd)]=_0x5a54c8[_0x1350e6(0xbf)];if(_0x5a54c8[_0x1350e6(0xdf)])_0xea74f3[_0x1350e6(0xdf)]=_0x5a54c8[_0x1350e6(0xdf)];this[_0x1350e6(0xc1)]={'cliFlags':_0xea74f3,'session':_0x26ccc7(_0x2c954e),'project':_0x26ccc7(_0x34d380),'profile':_0x26ccc7(_0x343268?.[_0x1350e6(0xe7)]),'global':_0x26ccc7(_0x57b9a3)};const _0x1ec17a={...this[_0x1350e6(0xc1)][_0x1350e6(0xe0)],...this[_0x1350e6(0xc1)][_0x1350e6(0xdf)],...this[_0x1350e6(0xc1)][_0x1350e6(0xda)],...this[_0x1350e6(0xc1)][_0x1350e6(0xaf)],...this['layers']['cliFlags']},_0x17801a=_0x1ec17a[_0x1350e6(0xdb)]||_0x1350e6(0xc3);this[_0x1350e6(0xdb)]=resolveSite(_0x17801a),this[_0x1350e6(0xac)]=_0x1ec17a['database'],this[_0x1350e6(0xc8)]=_0x1ec17a[_0x1350e6(0xc8)],this[_0x1350e6(0xbe)]=_0x1ec17a[_0x1350e6(0xbe)],this[_0x1350e6(0xcd)]=_0x1ec17a['llm_project'],this['verbose']=_0x5a54c8['verbose']||![],this['logLevel']=_0x5a54c8['logLevel']??LogLevel[_0x1350e6(0xe6)],this[_0x1350e6(0xc7)]=getAPIKey(this['site'],this[_0x1350e6(0xc2)]||undefined);const _0x110639=getConfigDir(),_0x4a7540=a35_0x581336['join'](_0x110639,_0x1350e6(0xd0),this[_0x1350e6(0xe8)]+_0x1350e6(0xc4)),_0x5673a9=findProjectConfigPath(),_0x3c3ba1=a35_0x581336[_0x1350e6(0xd8)](_0x110639,_0x1350e6(0xca)),_0x2a747b=a35_0x581336[_0x1350e6(0xd8)](_0x110639,_0x1350e6(0xb3));let _0x51fde2=null,_0x2d0b5d=null;this[_0x1350e6(0xc2)]&&(_0x51fde2=a35_0x581336[_0x1350e6(0xd8)](_0x110639,_0x1350e6(0xd1),this['activeProfile'],_0x1350e6(0xca)),_0x2d0b5d=a35_0x581336[_0x1350e6(0xd8)](_0x110639,_0x1350e6(0xd1),this[_0x1350e6(0xc2)],_0x1350e6(0xb3))),this['configFiles']={'session':a35_0x405dec[_0x1350e6(0xdd)](_0x4a7540)?_0x4a7540:null,'project':_0x5673a9,'profile':_0x51fde2&&a35_0x405dec[_0x1350e6(0xdd)](_0x51fde2)?_0x51fde2:null,'profileCredentials':_0x2d0b5d&&a35_0x405dec['existsSync'](_0x2d0b5d)?_0x2d0b5d:null,'global':a35_0x405dec[_0x1350e6(0xdd)](_0x3c3ba1)?_0x3c3ba1:null,'globalCredentials':a35_0x405dec[_0x1350e6(0xdd)](_0x2a747b)?_0x2a747b:null};}[a35_0x32757a(0xcf)](_0x3a8762,_0x543d8f){const _0x429997=a35_0x32757a;if(!_0x543d8f)return _0x429997(0xdc);const _0x1c3943=_0x543d8f;if(this['layers']['cliFlags'][_0x3a8762]===_0x1c3943){if(_0x3a8762===_0x429997(0xdb)&&_0x1c3943===_0x429997(0xc3)&&!this['layers'][_0x429997(0xaf)]['site']&&!this[_0x429997(0xc1)][_0x429997(0xda)][_0x429997(0xdb)]&&!this[_0x429997(0xc1)]['profile'][_0x429997(0xdb)]&&!this[_0x429997(0xc1)]['global'][_0x429997(0xdb)])return _0x429997(0xc5);return'CLI\x20flag:\x20--'+_0x3a8762[_0x429997(0xb6)](/_/g,'-');}if(this['layers'][_0x429997(0xaf)][_0x3a8762]===_0x1c3943)return _0x429997(0xaf);if(this[_0x429997(0xc1)][_0x429997(0xda)][_0x3a8762]===_0x1c3943)return'project';if(this['layers'][_0x429997(0xdf)][_0x3a8762]===_0x1c3943)return _0x429997(0xea)+this[_0x429997(0xc2)];if(this[_0x429997(0xc1)][_0x429997(0xe0)][_0x3a8762]===_0x1c3943)return _0x429997(0xe0);return _0x429997(0xc5);}[a35_0x32757a(0xb2)](){const _0x304697=a35_0x32757a,_0xd38a6c=a35_0x581336['join'](getConfigDir(),_0x304697(0xca));if(!a35_0x405dec[_0x304697(0xdd)](_0xd38a6c))return{};try{const _0x23c165=a35_0x405dec[_0x304697(0xd7)](_0xd38a6c,_0x304697(0xb5));return JSON[_0x304697(0xb8)](_0x23c165);}catch{return{};}}[a35_0x32757a(0xd6)](_0x12bbe4){const _0xa838c9=a35_0x32757a;_0x12bbe4[_0xa838c9(0xdb)]=this[_0xa838c9(0xdb)],!_0x12bbe4[_0xa838c9(0xac)]&&this[_0xa838c9(0xac)]&&(_0x12bbe4['database']=this[_0xa838c9(0xac)]),!_0x12bbe4[_0xa838c9(0xba)]&&this[_0xa838c9(0xc8)]&&(_0x12bbe4[_0xa838c9(0xba)]=this[_0xa838c9(0xc8)]),!_0x12bbe4[_0xa838c9(0xad)]&&this[_0xa838c9(0xbe)]&&(_0x12bbe4['segmentPath']=this['segment_path']),!_0x12bbe4['llmProject']&&this['llm_project']&&(_0x12bbe4[_0xa838c9(0xbf)]=this[_0xa838c9(0xcd)]);}[a35_0x32757a(0xb1)](){const _0x35870a=a35_0x32757a;return[{'key':_0x35870a(0xdb),'value':this[_0x35870a(0xdb)]},{'key':_0x35870a(0xac),'value':this[_0x35870a(0xac)]},{'key':_0x35870a(0xc8),'value':this[_0x35870a(0xc8)]},{'key':_0x35870a(0xbe),'value':this['segment_path']},{'key':_0x35870a(0xcd),'value':this['llm_project']},{'key':_0x35870a(0xdf),'value':this[_0x35870a(0xc2)]||undefined}];}[a35_0x32757a(0xae)](){const _0xe5cd1e=a35_0x32757a;console[_0xe5cd1e(0xec)]('[context]');for(const {key:_0x31c3b7,value:_0x181082}of this[_0xe5cd1e(0xb1)]()){_0x181082&&console['log'](_0x31c3b7+':\x20'+_0x181082);}}[a35_0x32757a(0xe2)](){const _0x5dc89b=a35_0x32757a;console['log'](_0x5dc89b(0xb4));for(const {key:_0x4d2b39,value:_0x2cc3a9}of this[_0x5dc89b(0xb1)]()){if(_0x2cc3a9){const _0x142509=_0x4d2b39===_0x5dc89b(0xdf)?_0x5dc89b(0xd9):'('+this[_0x5dc89b(0xcf)](_0x4d2b39,_0x2cc3a9)+')';console[_0x5dc89b(0xec)](_0x4d2b39+':\x20'+_0x2cc3a9+'\x20'+_0x142509);}}console[_0x5dc89b(0xec)]('\x0a[configuration\x20files]');const _0x4e6290=[{'label':_0x5dc89b(0xbd),'path':this['configFiles'][_0x5dc89b(0xaf)],'extra':_0x5dc89b(0xc9)+this[_0x5dc89b(0xe8)]+')'},{'label':'Project','path':this[_0x5dc89b(0xeb)][_0x5dc89b(0xda)]},{'label':'Profile','path':this[_0x5dc89b(0xeb)][_0x5dc89b(0xdf)]},{'label':_0x5dc89b(0xce),'path':this[_0x5dc89b(0xeb)]['profileCredentials']},{'label':'Global','path':this[_0x5dc89b(0xeb)][_0x5dc89b(0xe0)]},{'label':_0x5dc89b(0xbc),'path':this[_0x5dc89b(0xeb)][_0x5dc89b(0xc6)]}];for(const {label:_0x163302,path:_0x533517,extra:_0x18028b}of _0x4e6290){if(_0x533517)console['log'](_0x163302+':\x20'+_0x533517+'\x20✓'+(_0x18028b?'\x20'+_0x18028b:''));else{if(_0x163302==='Session')console[_0x5dc89b(0xec)](_0x163302+':\x20none\x20(using\x20session:\x20'+this['sessionId']+')');else(_0x163302===_0x5dc89b(0xd2)||_0x163302===_0x5dc89b(0xc0))&&console[_0x5dc89b(0xec)](_0x163302+_0x5dc89b(0xab));}}}}
|
package/dist/core/profile.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function a36_0x22c0(_0x211f7b,_0x55306c){const _0x1eec0c=a36_0x1eec();return a36_0x22c0=function(_0x22c091,_0x1d9824){_0x22c091=_0x22c091-0x14f;let _0x29726d=_0x1eec0c[_0x22c091];return _0x29726d;},a36_0x22c0(_0x211f7b,_0x55306c);}(function(_0x4c897e,_0x3b11e0){const _0x5514d8=a36_0x22c0,_0x41110b=_0x4c897e();while(!![]){try{const _0x45d631=-parseInt(_0x5514d8(0x169))/0x1*(-parseInt(_0x5514d8(0x184))/0x2)+-parseInt(_0x5514d8(0x182))/0x3+-parseInt(_0x5514d8(0x195))/0x4*(-parseInt(_0x5514d8(0x165))/0x5)+-parseInt(_0x5514d8(0x183))/0x6+-parseInt(_0x5514d8(0x19c))/0x7*(-parseInt(_0x5514d8(0x162))/0x8)+-parseInt(_0x5514d8(0x186))/0x9+parseInt(_0x5514d8(0x190))/0xa;if(_0x45d631===_0x3b11e0)break;else _0x41110b['push'](_0x41110b['shift']());}catch(_0x47c3a0){_0x41110b['push'](_0x41110b['shift']());}}}(a36_0x1eec,0x2487a));import*as a36_0x483fc9 from'node:fs';function a36_0x1eec(){const _0x394b8e=['includes','apiKey','\x0aWarning:\x20Failed\x20to\x20load\x20profiles\x20from\x20','.env','API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20profile\x20configuration.\x20Use\x20.env\x20file\x20instead.','\x0aWarning:\x20Skipping\x20invalid\x20profile\x20in\x20','message','parent_segment','description','\x20\x201.\x20Edit:\x20','warn','directory','llm_project','tdx.json','\x27:\x20\x27site\x27\x20must\x20be\x20a\x20string','local','profile','To\x20migrate:','push','58254Vfkruk','1371648AQMZBW','2EQmyhD','set','2217564dDphBi','has','Invalid\x20profile\x20name:\x20','\x27\x20will\x20be\x20ignored','sort','TD_API_KEY','readdirSync','Warning:\x20Profile\x20\x27','profiles','parse','399570CFYKAf','utf-8','\x27:\x20\x27description\x27\x20must\x20be\x20a\x20string','readFileSync','\x20already\x20exists','12GLqXDs','site','test','existsSync','Profile\x20','Profile\x20\x27','llm_agent','777NgPjOa','find','length','from','\x27:\x20unknown\x20config\x20key\x20\x27','api_key','string','database','Please\x20migrate\x20to\x20~/.config/tdx/tdx.json:','\x20\x203.\x20Move\x20credentials:\x20mv\x20~/.config/tdx/profiles/<name>/.env\x20~/.config/tdx/.env.<name>\x0a','.\x20Must\x20contain\x20only\x20alphanumeric\x20characters,\x20dash,\x20and\x20underscore.','map','join','values','isDirectory','entries','\x22\x20\x22','Error:\x20','\x27:\x20\x27parent_segment\x27\x20must\x20be\x20a\x20string','\x20\x202.\x20Add\x20profiles\x20under\x20a\x20\x22profiles\x22\x20key\x20(see\x20\x27tdx\x20profiles\x27\x20for\x20current\x20config)','12248iHdedT','toISOString','rmSync','476635GbCVKY','stringify','\x20does\x20not\x20exist','some','148169yflEUG','writeFileSync',':\x20Invalid\x20JSON\x20syntax','user','.env.','name'];a36_0x1eec=function(){return _0x394b8e;};return a36_0x1eec();}import*as a36_0x27b34e from'node:path';import{getConfigDir}from'./config.js';import{createSecureDirectory,writeSecureFile}from'../utils/file-permissions.js';import{findProjectConfigPath}from'./project-config.js';export function getProfileParams(_0x120d14){const _0x305414=a36_0x22c0,_0x3971a1={};if(!_0x120d14)return _0x3971a1;for(const [_0x390181,_0x3199b3]of Object[_0x305414(0x15d)](_0x120d14)){_0x390181!=='description'&&_0x3199b3!==undefined&&(_0x3971a1[_0x390181]=_0x3199b3);}return _0x3971a1;}export function getProfilesDir(){const _0x2e9853=a36_0x22c0;return a36_0x27b34e[_0x2e9853(0x15a)](getConfigDir(),_0x2e9853(0x18e));}function getProfileDir(_0x149ed4){const _0x1f6e68=a36_0x22c0;return a36_0x27b34e[_0x1f6e68(0x15a)](getProfilesDir(),_0x149ed4);}function getProfileConfigPath(_0x39e12c){const _0x231ca3=a36_0x22c0;return a36_0x27b34e[_0x231ca3(0x15a)](getProfileDir(_0x39e12c),_0x231ca3(0x17c));}function getProfileEnvPath(_0x4e2090){const _0x5ed2e7=a36_0x22c0;return a36_0x27b34e['join'](getProfileDir(_0x4e2090),_0x5ed2e7(0x172));}function getGlobalConfigPath(){const _0x4ab39c=a36_0x22c0;return a36_0x27b34e[_0x4ab39c(0x15a)](getConfigDir(),_0x4ab39c(0x17c));}function validateProfileName(_0xa8af5a){const _0x3535f2=a36_0x22c0;if(!/^[a-zA-Z0-9_-]+$/[_0x3535f2(0x197)](_0xa8af5a))throw new Error(_0x3535f2(0x188)+_0xa8af5a+_0x3535f2(0x158));}function validateProfileConfig(_0x21b903,_0x8b2574){const _0x411061=a36_0x22c0;if(typeof _0x21b903!=='object'||_0x21b903===null)throw new Error(_0x411061(0x19a)+_0x8b2574+'\x27:\x20config\x20must\x20be\x20an\x20object');const _0x14584d=['description',_0x411061(0x196),_0x411061(0x155),'parent_segment','llm_project',_0x411061(0x19b)],_0x1c4812=_0x21b903;for(const _0x1d616b of Object['keys'](_0x1c4812)){!_0x14584d[_0x411061(0x16f)](_0x1d616b)&&console[_0x411061(0x179)](_0x411061(0x18d)+_0x8b2574+_0x411061(0x152)+_0x1d616b+_0x411061(0x189));}if(_0x1c4812[_0x411061(0x177)]!==undefined&&typeof _0x1c4812[_0x411061(0x177)]!==_0x411061(0x154))throw new Error(_0x411061(0x19a)+_0x8b2574+_0x411061(0x192));if(_0x1c4812[_0x411061(0x196)]!==undefined&&typeof _0x1c4812[_0x411061(0x196)]!==_0x411061(0x154))throw new Error(_0x411061(0x19a)+_0x8b2574+_0x411061(0x17d));if(_0x1c4812[_0x411061(0x155)]!==undefined&&typeof _0x1c4812[_0x411061(0x155)]!==_0x411061(0x154))throw new Error(_0x411061(0x19a)+_0x8b2574+'\x27:\x20\x27database\x27\x20must\x20be\x20a\x20string');if(_0x1c4812[_0x411061(0x176)]!==undefined&&typeof _0x1c4812[_0x411061(0x176)]!=='string')throw new Error(_0x411061(0x19a)+_0x8b2574+_0x411061(0x160));if(_0x1c4812[_0x411061(0x17b)]!==undefined&&typeof _0x1c4812[_0x411061(0x17b)]!==_0x411061(0x154))throw new Error(_0x411061(0x19a)+_0x8b2574+'\x27:\x20\x27llm_project\x27\x20must\x20be\x20a\x20string');if(_0x1c4812[_0x411061(0x19b)]!==undefined&&typeof _0x1c4812[_0x411061(0x19b)]!==_0x411061(0x154))throw new Error(_0x411061(0x19a)+_0x8b2574+'\x27:\x20\x27llm_agent\x27\x20must\x20be\x20a\x20string');return!![];}function loadProfilesFromTdxJson(_0x28a45b,_0x23e802){const _0x2a74aa=a36_0x22c0;if(!a36_0x483fc9['existsSync'](_0x28a45b))return[];try{const _0x3f0868=a36_0x483fc9[_0x2a74aa(0x193)](_0x28a45b,'utf-8'),_0x44fe89=JSON[_0x2a74aa(0x18f)](_0x3f0868);if(!_0x44fe89[_0x2a74aa(0x18e)]||typeof _0x44fe89[_0x2a74aa(0x18e)]!=='object')return[];const _0x1ba33d=[];for(const [_0x32b902,_0x4241a6]of Object['entries'](_0x44fe89['profiles'])){try{validateProfileConfig(_0x4241a6,_0x32b902);const _0x530349=getNewCredentialPath(_0x32b902),_0x163ea7=getOldCredentialPath(_0x32b902),_0x478d66=a36_0x483fc9[_0x2a74aa(0x198)](_0x530349)||a36_0x483fc9[_0x2a74aa(0x198)](_0x163ea7);_0x1ba33d[_0x2a74aa(0x181)]({'name':_0x32b902,'config':_0x4241a6,'metadata':{'name':_0x32b902,'createdAt':new Date()[_0x2a74aa(0x163)]()},'hasCredentials':_0x478d66,'scope':_0x23e802});}catch(_0x3c9a4b){_0x3c9a4b instanceof Error&&(console[_0x2a74aa(0x179)](_0x2a74aa(0x174)+_0x28a45b+':'),console[_0x2a74aa(0x179)]('\x20\x20'+_0x3c9a4b[_0x2a74aa(0x175)]+'\x0a'));}}return _0x1ba33d;}catch(_0x2033da){return _0x2033da instanceof SyntaxError?(console[_0x2a74aa(0x179)]('\x0aWarning:\x20Failed\x20to\x20parse\x20'+_0x28a45b+_0x2a74aa(0x16b)),console[_0x2a74aa(0x179)](_0x2a74aa(0x15f)+_0x2033da[_0x2a74aa(0x175)]+'\x0a')):console[_0x2a74aa(0x179)](_0x2a74aa(0x171)+_0x28a45b+':\x20'+_0x2033da+'\x0a'),[];}}export function getNewCredentialPath(_0x17c755){const _0x3f292a=a36_0x22c0;return a36_0x27b34e['join'](getConfigDir(),_0x3f292a(0x16d)+_0x17c755);}function getOldCredentialPath(_0x27ee37){const _0x2c82ca=a36_0x22c0;return a36_0x27b34e[_0x2c82ca(0x15a)](getProfilesDir(),_0x27ee37,_0x2c82ca(0x172));}function loadProfilesFromTdxJsonFiles(){const _0x1d9649=a36_0x22c0,_0x144248=[],_0x3f2ffb=findProjectConfigPath();_0x3f2ffb&&_0x144248['push'](...loadProfilesFromTdxJson(_0x3f2ffb,_0x1d9649(0x17e)));const _0x3665b0=a36_0x27b34e[_0x1d9649(0x15a)](getConfigDir(),_0x1d9649(0x17c));return _0x144248['push'](...loadProfilesFromTdxJson(_0x3665b0,_0x1d9649(0x16c))),_0x144248;}function loadProfilesFromDirectories(){const _0x2da46e=a36_0x22c0,_0xb755ea=getProfilesDir();if(!a36_0x483fc9['existsSync'](_0xb755ea))return[];try{return a36_0x483fc9[_0x2da46e(0x18c)](_0xb755ea,{'withFileTypes':!![]})['filter'](_0x384ded=>_0x384ded[_0x2da46e(0x15c)]())['map'](_0x16abe0=>_0x16abe0[_0x2da46e(0x16e)])['filter'](_0xe14ad6=>{const _0x5d8295=_0x2da46e,_0x29992b=getProfileConfigPath(_0xe14ad6),_0x4e0ded=getProfileEnvPath(_0xe14ad6);return a36_0x483fc9[_0x5d8295(0x198)](_0x29992b)||a36_0x483fc9[_0x5d8295(0x198)](_0x4e0ded);})['map'](_0x491ab9=>{const _0x89a8f7=_0x2da46e,_0xf2f901=loadProfileFromDirectory(_0x491ab9);if(_0xf2f901)return{..._0xf2f901,'scope':_0x89a8f7(0x17a)};return null;})['filter'](_0x435c6e=>_0x435c6e!==null);}catch{return[];}}function loadProfileFromDirectory(_0xd00467){const _0x253896=a36_0x22c0,_0x4c8cf5=getProfileConfigPath(_0xd00467),_0x88f0f3=getOldCredentialPath(_0xd00467);if(!a36_0x483fc9['existsSync'](_0x4c8cf5)&&!a36_0x483fc9[_0x253896(0x198)](_0x88f0f3))return null;let _0xdeb228={},_0x205f20={'name':_0xd00467,'createdAt':new Date()[_0x253896(0x163)]()};if(a36_0x483fc9[_0x253896(0x198)](_0x4c8cf5))try{const _0x5cb1cf=a36_0x483fc9['readFileSync'](_0x4c8cf5,'utf-8'),_0xbf36a3=JSON[_0x253896(0x18f)](_0x5cb1cf),{metadata:_0x11e942,..._0x2dd99b}=_0xbf36a3;_0xdeb228=_0x2dd99b,_0x11e942&&(_0x205f20=_0x11e942);}catch{}return{'name':_0xd00467,'config':_0xdeb228,'metadata':_0x205f20,'hasCredentials':a36_0x483fc9['existsSync'](_0x88f0f3),'scope':_0x253896(0x17a)};}export function listProfiles(){const _0x5971d6=a36_0x22c0,_0x13a0f0=loadProfilesFromTdxJsonFiles(),_0x5d7c4d=loadProfilesFromDirectories();if(_0x5d7c4d[_0x5971d6(0x150)]>0x0){const _0x4ac49c=_0x5d7c4d[_0x5971d6(0x159)](_0x3f923e=>_0x3f923e[_0x5971d6(0x16e)])['join'](',\x20'),_0x3e960b=getConfigDir();console['warn']('\x0aWarning:\x20Profiles\x20in\x20directories\x20are\x20deprecated:\x20'+_0x4ac49c),console[_0x5971d6(0x179)](_0x5971d6(0x156)),console[_0x5971d6(0x179)](_0x5971d6(0x178)+a36_0x27b34e[_0x5971d6(0x15a)](_0x3e960b,_0x5971d6(0x17c))),console[_0x5971d6(0x179)](_0x5971d6(0x161)),console[_0x5971d6(0x179)](_0x5971d6(0x157));}const _0xed2b35=[..._0x13a0f0,..._0x5d7c4d],_0x3ac087=new Map();for(const _0x4b403a of _0xed2b35){!_0x3ac087[_0x5971d6(0x187)](_0x4b403a[_0x5971d6(0x16e)])&&_0x3ac087[_0x5971d6(0x185)](_0x4b403a[_0x5971d6(0x16e)],_0x4b403a);}return Array[_0x5971d6(0x151)](_0x3ac087[_0x5971d6(0x15b)]())[_0x5971d6(0x18a)]((_0x46158f,_0x1c6bd0)=>_0x46158f[_0x5971d6(0x16e)]['localeCompare'](_0x1c6bd0['name']));}export function profileExists(_0x14b385){const _0x5b59ee=a36_0x22c0,_0xbe1606=listProfiles();return _0xbe1606[_0x5b59ee(0x168)](_0x3b5479=>_0x3b5479['name']===_0x14b385);}export function loadProfile(_0x2e89dd){const _0x900c0c=a36_0x22c0;validateProfileName(_0x2e89dd);const _0x21fa8d=listProfiles(),_0x326b6b=_0x21fa8d[_0x900c0c(0x14f)](_0x3ef7b1=>_0x3ef7b1['name']===_0x2e89dd);return _0x326b6b||null;}export function saveProfile(_0x4955d0,_0x21e86b,_0x30ff1a=![]){const _0xf30fa1=a36_0x22c0;validateProfileName(_0x4955d0);const _0x7699ae=getProfileDir(_0x4955d0),_0x2d29a5=getProfileConfigPath(_0x4955d0);createSecureDirectory(_0x7699ae);let _0x37a1b1;const _0x3200f6=loadProfile(_0x4955d0);_0x3200f6?(_0x37a1b1=_0x3200f6['metadata'],_0x30ff1a&&(_0x37a1b1['lastUsed']=new Date()['toISOString']())):_0x37a1b1={'name':_0x4955d0,'createdAt':new Date()['toISOString']()};const _0x18c3eb=JSON[_0xf30fa1(0x166)](_0x21e86b);if(_0x18c3eb['includes'](_0xf30fa1(0x18b))||_0x18c3eb['includes'](_0xf30fa1(0x170))||_0x18c3eb[_0xf30fa1(0x16f)](_0xf30fa1(0x153)))throw new Error(_0xf30fa1(0x173));const _0x42a6b2={..._0x21e86b,'metadata':_0x37a1b1};a36_0x483fc9[_0xf30fa1(0x16a)](_0x2d29a5,JSON[_0xf30fa1(0x166)](_0x42a6b2,null,0x2));}export function deleteProfile(_0x45d1fd){const _0x3a2cda=a36_0x22c0;validateProfileName(_0x45d1fd);const _0x4b5f6b=getProfileDir(_0x45d1fd);if(!a36_0x483fc9[_0x3a2cda(0x198)](_0x4b5f6b))throw new Error(_0x3a2cda(0x199)+_0x45d1fd+_0x3a2cda(0x167));a36_0x483fc9[_0x3a2cda(0x164)](_0x4b5f6b,{'recursive':!![],'force':!![]});}export function getActiveProfile(){const _0x1a49ee=a36_0x22c0,_0x912578=getGlobalConfigPath();if(!a36_0x483fc9[_0x1a49ee(0x198)](_0x912578))return null;try{const _0x12fea0=a36_0x483fc9[_0x1a49ee(0x193)](_0x912578,_0x1a49ee(0x191)),_0x1ce6e7=JSON[_0x1a49ee(0x18f)](_0x12fea0);return _0x1ce6e7[_0x1a49ee(0x17f)]||null;}catch{return null;}}export function createProfile(_0x4f83d8,_0x3c0a85){const _0x430c55=a36_0x22c0;validateProfileName(_0x4f83d8);if(profileExists(_0x4f83d8))throw new Error(_0x430c55(0x199)+_0x4f83d8+_0x430c55(0x194));saveProfile(_0x4f83d8,_0x3c0a85);}export function saveProfileCredentials(_0x1472c7,_0x14bd65){const _0x5fc5df=a36_0x22c0;validateProfileName(_0x1472c7);if(!profileExists(_0x1472c7))throw new Error(_0x5fc5df(0x199)+_0x1472c7+'\x20does\x20not\x20exist');const _0x4d8e28=getNewCredentialPath(_0x1472c7);writeSecureFile(_0x4d8e28,_0x14bd65);}export function loadProfileCredentials(_0x2e41c7){const _0xd0e2fd=a36_0x22c0;validateProfileName(_0x2e41c7);const _0x125ec8=getNewCredentialPath(_0x2e41c7);if(a36_0x483fc9[_0xd0e2fd(0x198)](_0x125ec8))try{return a36_0x483fc9['readFileSync'](_0x125ec8,_0xd0e2fd(0x191));}catch{}const _0x23f66f=getOldCredentialPath(_0x2e41c7);if(a36_0x483fc9['existsSync'](_0x23f66f)){console['warn']('\x0aWarning:\x20Using\x20deprecated\x20credential\x20location\x20for\x20profile\x20\x27'+_0x2e41c7+'\x27'),console[_0xd0e2fd(0x179)](_0xd0e2fd(0x180)),console[_0xd0e2fd(0x179)]('\x20\x20mv\x20\x22'+_0x23f66f+_0xd0e2fd(0x15e)+_0x125ec8+'\x22'),console[_0xd0e2fd(0x179)]('Then\x20define\x20profiles\x20in\x20~/.config/tdx/tdx.json\x0a');try{return a36_0x483fc9[_0xd0e2fd(0x193)](_0x23f66f,'utf-8');}catch{return null;}}return null;}
|
|
1
|
+
(function(_0x1525a4,_0x31104e){const _0x462ec7=a36_0x1038,_0x196036=_0x1525a4();while(!![]){try{const _0x4b8b0a=-parseInt(_0x462ec7(0xe8))/0x1+-parseInt(_0x462ec7(0xc2))/0x2+parseInt(_0x462ec7(0xdb))/0x3+parseInt(_0x462ec7(0xce))/0x4*(parseInt(_0x462ec7(0x9e))/0x5)+-parseInt(_0x462ec7(0xa8))/0x6*(parseInt(_0x462ec7(0xb4))/0x7)+-parseInt(_0x462ec7(0xe0))/0x8*(parseInt(_0x462ec7(0xab))/0x9)+parseInt(_0x462ec7(0xdf))/0xa*(parseInt(_0x462ec7(0xb2))/0xb);if(_0x4b8b0a===_0x31104e)break;else _0x196036['push'](_0x196036['shift']());}catch(_0x3806fa){_0x196036['push'](_0x196036['shift']());}}}(a36_0x15b2,0x3a0b0));import*as a36_0x519f72 from'node:fs';import*as a36_0x45c650 from'node:path';import{getConfigDir}from'./config.js';import{createSecureDirectory,writeSecureFile}from'../utils/file-permissions.js';import{findProjectConfigPath}from'./project-config.js';export function getProfileParams(_0x4a00ab){const _0x30d341=a36_0x1038,_0x3f9dfb={};if(!_0x4a00ab)return _0x3f9dfb;for(const [_0x23e002,_0x1f5b12]of Object[_0x30d341(0xe7)](_0x4a00ab)){_0x23e002!==_0x30d341(0xa9)&&_0x1f5b12!==undefined&&(_0x3f9dfb[_0x23e002]=_0x1f5b12);}return _0x3f9dfb;}export function getProfilesDir(){const _0x41ca01=a36_0x1038;return a36_0x45c650[_0x41ca01(0xb9)](getConfigDir(),'profiles');}function getProfileDir(_0x136109){return a36_0x45c650['join'](getProfilesDir(),_0x136109);}function getProfileConfigPath(_0x1879b3){const _0x5933cb=a36_0x1038;return a36_0x45c650[_0x5933cb(0xb9)](getProfileDir(_0x1879b3),_0x5933cb(0xb8));}function getProfileEnvPath(_0x23c93f){const _0x7a49a5=a36_0x1038;return a36_0x45c650[_0x7a49a5(0xb9)](getProfileDir(_0x23c93f),'.env');}function getGlobalConfigPath(){return a36_0x45c650['join'](getConfigDir(),'tdx.json');}function a36_0x1038(_0x539519,_0x523872){const _0x15b286=a36_0x15b2();return a36_0x1038=function(_0x1038be,_0x45ec10){_0x1038be=_0x1038be-0x97;let _0x948daf=_0x15b286[_0x1038be];return _0x948daf;},a36_0x1038(_0x539519,_0x523872);}function validateProfileName(_0x2ded87){const _0x2241ab=a36_0x1038;if(!/^[a-zA-Z0-9_-]+$/[_0x2241ab(0xa7)](_0x2ded87))throw new Error(_0x2241ab(0xbc)+_0x2ded87+_0x2241ab(0x9d));}function validateProfileConfig(_0x21d64b,_0x3b4725){const _0x2bb207=a36_0x1038;if(typeof _0x21d64b!=='object'||_0x21d64b===null)throw new Error(_0x2bb207(0xa2)+_0x3b4725+_0x2bb207(0xe3));const _0x16c514=[_0x2bb207(0xa9),_0x2bb207(0xd2),_0x2bb207(0xd6),'parent_segment',_0x2bb207(0xd3),_0x2bb207(0xc7)],_0x203326=_0x21d64b;for(const _0x23de59 of Object[_0x2bb207(0xdd)](_0x203326)){!_0x16c514[_0x2bb207(0x9c)](_0x23de59)&&console['warn'](_0x2bb207(0xe1)+_0x3b4725+_0x2bb207(0xdc)+_0x23de59+_0x2bb207(0xe5));}if(_0x203326[_0x2bb207(0xa9)]!==undefined&&typeof _0x203326[_0x2bb207(0xa9)]!==_0x2bb207(0xb6))throw new Error(_0x2bb207(0xa2)+_0x3b4725+_0x2bb207(0xa4));if(_0x203326[_0x2bb207(0xd2)]!==undefined&&typeof _0x203326[_0x2bb207(0xd2)]!==_0x2bb207(0xb6))throw new Error(_0x2bb207(0xa2)+_0x3b4725+'\x27:\x20\x27site\x27\x20must\x20be\x20a\x20string');if(_0x203326[_0x2bb207(0xd6)]!==undefined&&typeof _0x203326['database']!=='string')throw new Error('Profile\x20\x27'+_0x3b4725+_0x2bb207(0xbe));if(_0x203326[_0x2bb207(0xbf)]!==undefined&&typeof _0x203326[_0x2bb207(0xbf)]!==_0x2bb207(0xb6))throw new Error(_0x2bb207(0xa2)+_0x3b4725+'\x27:\x20\x27parent_segment\x27\x20must\x20be\x20a\x20string');if(_0x203326[_0x2bb207(0xd3)]!==undefined&&typeof _0x203326['llm_project']!==_0x2bb207(0xb6))throw new Error(_0x2bb207(0xa2)+_0x3b4725+_0x2bb207(0xac));if(_0x203326[_0x2bb207(0xc7)]!==undefined&&typeof _0x203326[_0x2bb207(0xc7)]!==_0x2bb207(0xb6))throw new Error('Profile\x20\x27'+_0x3b4725+'\x27:\x20\x27llm_agent\x27\x20must\x20be\x20a\x20string');return!![];}function loadProfilesFromTdxJson(_0x48624a,_0x31d79f){const _0x541dfa=a36_0x1038;if(!a36_0x519f72['existsSync'](_0x48624a))return[];try{const _0x161d0b=a36_0x519f72[_0x541dfa(0xc5)](_0x48624a,_0x541dfa(0xd8)),_0x5d417a=JSON[_0x541dfa(0x97)](_0x161d0b);if(!_0x5d417a['profiles']||typeof _0x5d417a['profiles']!==_0x541dfa(0x9a))return[];const _0x5c1474=[];for(const [_0x4d4fa6,_0x2a6c9a]of Object[_0x541dfa(0xe7)](_0x5d417a[_0x541dfa(0xda)])){try{validateProfileConfig(_0x2a6c9a,_0x4d4fa6);const _0x31ac96=getNewCredentialPath(_0x4d4fa6),_0x4cf4c1=getOldCredentialPath(_0x4d4fa6),_0x22adb8=a36_0x519f72[_0x541dfa(0xa5)](_0x31ac96)||a36_0x519f72[_0x541dfa(0xa5)](_0x4cf4c1);_0x5c1474[_0x541dfa(0xc0)]({'name':_0x4d4fa6,'config':_0x2a6c9a,'metadata':{'name':_0x4d4fa6,'createdAt':new Date()[_0x541dfa(0x9f)]()},'hasCredentials':_0x22adb8,'scope':_0x31d79f});}catch(_0x3f523b){_0x3f523b instanceof Error&&(console[_0x541dfa(0xbd)](_0x541dfa(0xb3)+_0x48624a+':'),console[_0x541dfa(0xbd)]('\x20\x20'+_0x3f523b['message']+'\x0a'));}}return _0x5c1474;}catch(_0x540d9f){return _0x540d9f instanceof SyntaxError?(console[_0x541dfa(0xbd)]('\x0aWarning:\x20Failed\x20to\x20parse\x20'+_0x48624a+':\x20Invalid\x20JSON\x20syntax'),console[_0x541dfa(0xbd)](_0x541dfa(0xba)+_0x540d9f['message']+'\x0a')):console[_0x541dfa(0xbd)]('\x0aWarning:\x20Failed\x20to\x20load\x20profiles\x20from\x20'+_0x48624a+':\x20'+_0x540d9f+'\x0a'),[];}}export function getNewCredentialPath(_0x2ec9fe){const _0xafac66=a36_0x1038;return a36_0x45c650[_0xafac66(0xb9)](getConfigDir(),_0xafac66(0xae)+_0x2ec9fe);}function getOldCredentialPath(_0x6449a6){const _0x3ebb49=a36_0x1038;return a36_0x45c650[_0x3ebb49(0xb9)](getProfilesDir(),_0x6449a6,_0x3ebb49(0xc8));}function loadProfilesFromTdxJsonFiles(){const _0x5b68d6=a36_0x1038,_0x66cab9=[],_0x8128aa=findProjectConfigPath();_0x8128aa&&_0x66cab9[_0x5b68d6(0xc0)](...loadProfilesFromTdxJson(_0x8128aa,_0x5b68d6(0xb7)));const _0x457cda=a36_0x45c650[_0x5b68d6(0xb9)](getConfigDir(),_0x5b68d6(0xb8));return _0x66cab9['push'](...loadProfilesFromTdxJson(_0x457cda,_0x5b68d6(0xaa))),_0x66cab9;}function loadProfilesFromDirectories(){const _0x3829d3=a36_0x1038,_0x225a44=getProfilesDir();if(!a36_0x519f72[_0x3829d3(0xa5)](_0x225a44))return[];try{return a36_0x519f72[_0x3829d3(0xaf)](_0x225a44,{'withFileTypes':!![]})[_0x3829d3(0xc9)](_0x5ae520=>_0x5ae520['isDirectory']())['map'](_0x1996f1=>_0x1996f1['name'])[_0x3829d3(0xc9)](_0x543a45=>{const _0x6e33c2=_0x3829d3,_0x416540=getProfileConfigPath(_0x543a45),_0x3b0937=getProfileEnvPath(_0x543a45);return a36_0x519f72[_0x6e33c2(0xa5)](_0x416540)||a36_0x519f72[_0x6e33c2(0xa5)](_0x3b0937);})[_0x3829d3(0xbb)](_0x4a6c03=>{const _0x22faeb=_0x3829d3,_0x579ebb=loadProfileFromDirectory(_0x4a6c03);if(_0x579ebb)return{..._0x579ebb,'scope':_0x22faeb(0xcc)};return null;})['filter'](_0x2c1bf3=>_0x2c1bf3!==null);}catch{return[];}}function loadProfileFromDirectory(_0x113a3a){const _0x50e3ba=a36_0x1038,_0x5ea105=getProfileConfigPath(_0x113a3a),_0x2d0aa1=getOldCredentialPath(_0x113a3a);if(!a36_0x519f72[_0x50e3ba(0xa5)](_0x5ea105)&&!a36_0x519f72[_0x50e3ba(0xa5)](_0x2d0aa1))return null;let _0x3245c2={},_0xc3e9d={'name':_0x113a3a,'createdAt':new Date()[_0x50e3ba(0x9f)]()};if(a36_0x519f72[_0x50e3ba(0xa5)](_0x5ea105))try{const _0x5b0120=a36_0x519f72[_0x50e3ba(0xc5)](_0x5ea105,'utf-8'),_0x391a33=JSON['parse'](_0x5b0120),{metadata:_0x39a5ed,..._0x5c0517}=_0x391a33;_0x3245c2=_0x5c0517,_0x39a5ed&&(_0xc3e9d=_0x39a5ed);}catch{}return{'name':_0x113a3a,'config':_0x3245c2,'metadata':_0xc3e9d,'hasCredentials':a36_0x519f72['existsSync'](_0x2d0aa1),'scope':'directory'};}export function listProfiles(){const _0x57ce5c=a36_0x1038,_0x258eec=loadProfilesFromTdxJsonFiles(),_0x5d673b=loadProfilesFromDirectories();if(_0x5d673b[_0x57ce5c(0xd7)]>0x0){const _0x5ee70f=_0x5d673b[_0x57ce5c(0xbb)](_0x8ee5f4=>_0x8ee5f4['name'])[_0x57ce5c(0xb9)](',\x20'),_0x34cb8c=getConfigDir();console['warn'](_0x57ce5c(0xd9)+_0x5ee70f),console[_0x57ce5c(0xbd)](_0x57ce5c(0xde)),console['warn'](_0x57ce5c(0xcd)+a36_0x45c650['join'](_0x34cb8c,_0x57ce5c(0xb8))),console[_0x57ce5c(0xbd)](_0x57ce5c(0x98)),console[_0x57ce5c(0xbd)]('\x20\x203.\x20Move\x20credentials:\x20mv\x20~/.config/tdx/profiles/<name>/.env\x20~/.config/tdx/.env.<name>\x0a');}const _0x43972f=[..._0x258eec,..._0x5d673b],_0xbb97b=new Map();for(const _0x1947b9 of _0x43972f){!_0xbb97b['has'](_0x1947b9['name'])&&_0xbb97b[_0x57ce5c(0xcb)](_0x1947b9['name'],_0x1947b9);}return Array['from'](_0xbb97b[_0x57ce5c(0xcf)]())[_0x57ce5c(0xe6)]((_0x48d50d,_0x3fcfd3)=>_0x48d50d[_0x57ce5c(0xd0)][_0x57ce5c(0xd5)](_0x3fcfd3[_0x57ce5c(0xd0)]));}function a36_0x15b2(){const _0x1bf63f=['test','36678UDEQyI','description','user','1995093Oqbprc','\x27:\x20\x27llm_project\x27\x20must\x20be\x20a\x20string','stringify','.env.','readdirSync','Then\x20define\x20profiles\x20in\x20~/.config/tdx/tdx.json\x0a','find','1397fyJRMM','\x0aWarning:\x20Skipping\x20invalid\x20profile\x20in\x20','287Fdaiux','rmSync','string','local','tdx.json','join','Error:\x20','map','Invalid\x20profile\x20name:\x20','warn','\x27:\x20\x27database\x27\x20must\x20be\x20a\x20string','parent_segment','push','Profile\x20','842748oYSnoY','\x20already\x20exists','writeFileSync','readFileSync','api_key','llm_agent','.env','filter','\x22\x20\x22','set','directory','\x20\x201.\x20Edit:\x20','1436wsWHcJ','values','name','TD_API_KEY','site','llm_project','profile','localeCompare','database','length','utf-8','\x0aWarning:\x20Profiles\x20in\x20directories\x20are\x20deprecated:\x20','profiles','1138320RAMTqO','\x27:\x20unknown\x20config\x20key\x20\x27','keys','Please\x20migrate\x20to\x20~/.config/tdx/tdx.json:','63250MHWLAd','8DWeowv','Warning:\x20Profile\x20\x27','apiKey','\x27:\x20config\x20must\x20be\x20an\x20object','API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20profile\x20configuration.\x20Use\x20.env\x20file\x20instead.','\x27\x20will\x20be\x20ignored','sort','entries','347821mjlQnP','parse','\x20\x202.\x20Add\x20profiles\x20under\x20a\x20\x22profiles\x22\x20key\x20(see\x20\x27tdx\x20profiles\x27\x20for\x20current\x20config)','lastUsed','object','metadata','includes','.\x20Must\x20contain\x20only\x20alphanumeric\x20characters,\x20dash,\x20and\x20underscore.','4130dXiqSU','toISOString','\x0aWarning:\x20Using\x20deprecated\x20credential\x20location\x20for\x20profile\x20\x27','\x20does\x20not\x20exist','Profile\x20\x27','To\x20migrate:','\x27:\x20\x27description\x27\x20must\x20be\x20a\x20string','existsSync','some'];a36_0x15b2=function(){return _0x1bf63f;};return a36_0x15b2();}export function profileExists(_0x49befd){const _0x108079=a36_0x1038,_0x6cf622=listProfiles();return _0x6cf622[_0x108079(0xa6)](_0x3e9e85=>_0x3e9e85[_0x108079(0xd0)]===_0x49befd);}export function loadProfile(_0x22a0e4){const _0x167034=a36_0x1038;validateProfileName(_0x22a0e4);const _0x5c91dc=listProfiles(),_0x59087d=_0x5c91dc[_0x167034(0xb1)](_0x6ac2d4=>_0x6ac2d4['name']===_0x22a0e4);return _0x59087d||null;}export function saveProfile(_0x15efad,_0x4caf79,_0x72b4c=![]){const _0x1b3c0e=a36_0x1038;validateProfileName(_0x15efad);const _0x365a0c=getProfileDir(_0x15efad),_0x12f8d2=getProfileConfigPath(_0x15efad);createSecureDirectory(_0x365a0c);let _0x362c3b;const _0xf9f0a8=loadProfile(_0x15efad);_0xf9f0a8?(_0x362c3b=_0xf9f0a8[_0x1b3c0e(0x9b)],_0x72b4c&&(_0x362c3b[_0x1b3c0e(0x99)]=new Date()[_0x1b3c0e(0x9f)]())):_0x362c3b={'name':_0x15efad,'createdAt':new Date()['toISOString']()};const _0x38d582=JSON[_0x1b3c0e(0xad)](_0x4caf79);if(_0x38d582[_0x1b3c0e(0x9c)](_0x1b3c0e(0xd1))||_0x38d582[_0x1b3c0e(0x9c)](_0x1b3c0e(0xe2))||_0x38d582[_0x1b3c0e(0x9c)](_0x1b3c0e(0xc6)))throw new Error(_0x1b3c0e(0xe4));const _0x2d147c={..._0x4caf79,'metadata':_0x362c3b};a36_0x519f72[_0x1b3c0e(0xc4)](_0x12f8d2,JSON['stringify'](_0x2d147c,null,0x2));}export function deleteProfile(_0x1bb49f){const _0x5284d6=a36_0x1038;validateProfileName(_0x1bb49f);const _0x3d1a43=getProfileDir(_0x1bb49f);if(!a36_0x519f72['existsSync'](_0x3d1a43))throw new Error(_0x5284d6(0xc1)+_0x1bb49f+_0x5284d6(0xa1));a36_0x519f72[_0x5284d6(0xb5)](_0x3d1a43,{'recursive':!![],'force':!![]});}export function getActiveProfile(){const _0x3f0d5a=a36_0x1038,_0x32d5d5=getGlobalConfigPath();if(!a36_0x519f72[_0x3f0d5a(0xa5)](_0x32d5d5))return null;try{const _0x788c99=a36_0x519f72[_0x3f0d5a(0xc5)](_0x32d5d5,_0x3f0d5a(0xd8)),_0x5ec531=JSON[_0x3f0d5a(0x97)](_0x788c99);return _0x5ec531[_0x3f0d5a(0xd4)]||null;}catch{return null;}}export function createProfile(_0x5e0218,_0x5b7be8){const _0x58bef5=a36_0x1038;validateProfileName(_0x5e0218);if(profileExists(_0x5e0218))throw new Error(_0x58bef5(0xc1)+_0x5e0218+_0x58bef5(0xc3));saveProfile(_0x5e0218,_0x5b7be8);}export function saveProfileCredentials(_0x14f22e,_0x37aebc){const _0x39576a=a36_0x1038;validateProfileName(_0x14f22e);if(!profileExists(_0x14f22e))throw new Error('Profile\x20'+_0x14f22e+_0x39576a(0xa1));const _0x3b7931=getNewCredentialPath(_0x14f22e);writeSecureFile(_0x3b7931,_0x37aebc);}export function loadProfileCredentials(_0x5f270e){const _0x1d4881=a36_0x1038;validateProfileName(_0x5f270e);const _0x34968b=getNewCredentialPath(_0x5f270e);if(a36_0x519f72['existsSync'](_0x34968b))try{return a36_0x519f72[_0x1d4881(0xc5)](_0x34968b,_0x1d4881(0xd8));}catch{}const _0x4b43f7=getOldCredentialPath(_0x5f270e);if(a36_0x519f72[_0x1d4881(0xa5)](_0x4b43f7)){console['warn'](_0x1d4881(0xa0)+_0x5f270e+'\x27'),console[_0x1d4881(0xbd)](_0x1d4881(0xa3)),console[_0x1d4881(0xbd)]('\x20\x20mv\x20\x22'+_0x4b43f7+_0x1d4881(0xca)+_0x34968b+'\x22'),console['warn'](_0x1d4881(0xb0));try{return a36_0x519f72[_0x1d4881(0xc5)](_0x4b43f7,_0x1d4881(0xd8));}catch{return null;}}return null;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const a37_0x2e8ae4=a37_0x224e;function a37_0x5f3d(){const _0x3110fe=['code','1WdWOeM','existsSync','15728dZlwyY','TD_API_KEY','API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20project\x20configuration.\x20Use\x20.env\x20files\x20instead.','Active\x20profile\x20is\x20set\x20in\x20~/.config/tdx/tdx.json','join','utf-8','3189852aWIxhh','Security\x20error:\x20API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20project\x20config\x20(','cwd','46472426Lrrbpz','includes','4326196DakKFF','Failed\x20to\x20load\x20project\x20config\x20from\x20','readFileSync','apiKey','stringify','\x27profile\x27\x20should\x20not\x20be\x20set\x20in\x20project\x20config.\x20Use\x20\x27tdx\x20profile\x20use\x27\x20instead.','74846bvLRLj','dirname','Warning:\x20\x27profile\x27\x20field\x20in\x20','api_key','4581CtoDbz','5KtAZmx','tdx.json','Use\x20~/.config/tdx/.env\x20or\x20profile\x20.env\x20files\x20instead.','6353676bgICet','4YtjWPy','9940340MOoMnw','writeFileSync','profile'];a37_0x5f3d=function(){return _0x3110fe;};return a37_0x5f3d();}(function(_0x2641c3,_0x39d5fb){const _0xe4fed8=a37_0x224e,_0x5a0c49=_0x2641c3();while(!![]){try{const _0x3a82e5=-parseInt(_0xe4fed8(0x9f))/0x1*(-parseInt(_0xe4fed8(0x91))/0x2)+-parseInt(_0xe4fed8(0x86))/0x3*(-parseInt(_0xe4fed8(0x9a))/0x4)+-parseInt(_0xe4fed8(0x96))/0x5*(-parseInt(_0xe4fed8(0x99))/0x6)+parseInt(_0xe4fed8(0x8b))/0x7+parseInt(_0xe4fed8(0x80))/0x8*(parseInt(_0xe4fed8(0x95))/0x9)+parseInt(_0xe4fed8(0x9b))/0xa+-parseInt(_0xe4fed8(0x89))/0xb;if(_0x3a82e5===_0x39d5fb)break;else _0x5a0c49['push'](_0x5a0c49['shift']());}catch(_0x1d57f1){_0x5a0c49['push'](_0x5a0c49['shift']());}}}(a37_0x5f3d,0x85b3b));import*as a37_0x14ac5b from'node:fs';import*as a37_0x10ba28 from'node:path';const PROJECT_CONFIG_FILENAME=a37_0x2e8ae4(0x97);export function findProjectConfigPath(_0x475f49){const _0x31ffaa=a37_0x2e8ae4;let _0x2947ef=_0x475f49||process['cwd']();while(!![]){const _0x1ef33f=a37_0x10ba28['join'](_0x2947ef,PROJECT_CONFIG_FILENAME);if(a37_0x14ac5b[_0x31ffaa(0xa0)](_0x1ef33f))return _0x1ef33f;const _0x560849=a37_0x10ba28[_0x31ffaa(0x92)](_0x2947ef);if(_0x560849===_0x2947ef)return null;_0x2947ef=_0x560849;}}function a37_0x224e(_0x540f06,_0x470374){const _0x5f3de8=a37_0x5f3d();return a37_0x224e=function(_0x224ed3,_0x4e5c9c){_0x224ed3=_0x224ed3-0x80;let _0x4d7b9c=_0x5f3de8[_0x224ed3];return _0x4d7b9c;},a37_0x224e(_0x540f06,_0x470374);}export function loadProjectConfig(_0x2e4309){const _0x2635ef=a37_0x2e8ae4,_0x58c93e=findProjectConfigPath(_0x2e4309);if(!_0x58c93e)return null;try{const _0x380325=a37_0x14ac5b[_0x2635ef(0x8d)](_0x58c93e,_0x2635ef(0x85)),_0x17bc5e=JSON['parse'](_0x380325),_0x1eb5d7=JSON[_0x2635ef(0x8f)](_0x17bc5e);if(_0x1eb5d7[_0x2635ef(0x8a)](_0x2635ef(0x81))||_0x1eb5d7[_0x2635ef(0x8a)](_0x2635ef(0x8e))||_0x1eb5d7['includes'](_0x2635ef(0x94)))throw new Error(_0x2635ef(0x87)+_0x58c93e+').\x20'+_0x2635ef(0x98));const {metadata:_0xde7cda,profile:_0x1202f,..._0x45b02b}=_0x17bc5e;return _0x1202f&&console['warn'](_0x2635ef(0x93)+_0x58c93e+'\x20is\x20ignored.\x20'+_0x2635ef(0x83)),_0x45b02b;}catch(_0x139ebe){if(_0x139ebe instanceof Error&&_0x2635ef(0x9e)in _0x139ebe&&_0x139ebe[_0x2635ef(0x9e)]==='ENOENT')return null;throw new Error(_0x2635ef(0x8c)+_0x58c93e+':\x20'+_0x139ebe);}}export function saveProjectConfig(_0x272342,_0x33ef9a){const _0x345c15=a37_0x2e8ae4,_0x5bc1c7=_0x33ef9a||process[_0x345c15(0x88)](),_0x4e24eb=a37_0x10ba28[_0x345c15(0x84)](_0x5bc1c7,PROJECT_CONFIG_FILENAME),_0x3eeb54=JSON['stringify'](_0x272342);if(_0x3eeb54['includes']('TD_API_KEY')||_0x3eeb54['includes'](_0x345c15(0x8e))||_0x3eeb54[_0x345c15(0x8a)](_0x345c15(0x94)))throw new Error(_0x345c15(0x82));if(_0x345c15(0x9d)in _0x272342)throw new Error(_0x345c15(0x90));a37_0x14ac5b[_0x345c15(0x9c)](_0x4e24eb,JSON[_0x345c15(0x8f)](_0x272342,null,0x2));}export function hasProjectConfig(_0x30b926){return findProjectConfigPath(_0x30b926)!==null;}export function getProjectRoot(_0xa16503){const _0x1c8e5d=a37_0x2e8ae4,_0x14dea3=findProjectConfigPath(_0xa16503);return _0x14dea3?a37_0x10ba28[_0x1c8e5d(0x92)](_0x14dea3):null;}
|
package/dist/core/session.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(_0x59bb99,_0x4275f9){const _0xbd564c=a38_0x5c13,_0x1d5dae=_0x59bb99();while(!![]){try{const _0x4dafe5=-parseInt(_0xbd564c(0x18b))/0x1*(parseInt(_0xbd564c(0x17e))/0x2)+-parseInt(_0xbd564c(0x16b))/0x3*(-parseInt(_0xbd564c(0x196))/0x4)+-parseInt(_0xbd564c(0x179))/0x5*(parseInt(_0xbd564c(0x17a))/0x6)+-parseInt(_0xbd564c(0x189))/0x7+parseInt(_0xbd564c(0x171))/0x8*(parseInt(_0xbd564c(0x180))/0x9)+-parseInt(_0xbd564c(0x18f))/0xa*(-parseInt(_0xbd564c(0x18e))/0xb)+-parseInt(_0xbd564c(0x188))/0xc;if(_0x4dafe5===_0x4275f9)break;else _0x1d5dae['push'](_0x1d5dae['shift']());}catch(_0x11df17){_0x1d5dae['push'](_0x1d5dae['shift']());}}}(a38_0x3df7,0x3118d));function a38_0x5c13(_0x57b4fe,_0xadb810){const _0x3df7e0=a38_0x3df7();return a38_0x5c13=function(_0x5c13cd,_0x4646cc){_0x5c13cd=_0x5c13cd-0x16a;let _0x5a4803=_0x3df7e0[_0x5c13cd];return _0x5a4803;},a38_0x5c13(_0x57b4fe,_0xadb810);}import*as a38_0x4afd80 from'node:fs';import*as a38_0x51b236 from'node:path';import*as a38_0x19d7cd from'node:os';import{getPPID,isProcessRunning}from'../utils/process.js';import{createSecureDirectory}from'../utils/file-permissions.js';const SESSION_EXPIRATION_MS=0x18*0x3c*0x3c*0x3e8;function getSessionsDir(){const _0x16a9ea=a38_0x5c13,_0x3a66d7=process[_0x16a9ea(0x177)][_0x16a9ea(0x175)]||a38_0x51b236['join'](a38_0x19d7cd[_0x16a9ea(0x178)](),_0x16a9ea(0x174),_0x16a9ea(0x16d));return a38_0x51b236[_0x16a9ea(0x190)](_0x3a66d7,_0x16a9ea(0x18a));}function a38_0x3df7(){const _0x47297c=['replace','parse','stringify','existsSync','endsWith','TD_API_KEY','readFileSync','2944224jRPojO','2523556KSunPa','sessions','1033LjOpoM','warn','toISOString','59972KXfoVu','610kcPOLe','join','.json','includes','test','.\x20This\x20is\x20insecure.\x20Removing\x20session.','apiKey','1349876eFkRHv','api_key','toString','3zYrlmm','API\x20keys\x20must\x20not\x20be\x20stored\x20in\x20session\x20context.\x20Use\x20.env\x20files\x20instead.','tdx','readdirSync','writeFileSync','Warning:\x20API\x20keys\x20found\x20in\x20session\x20file\x20','1251176moDSxj','unlinkSync','createdAt','.config','TDX_CONFIG_DIR','push','env','homedir','19410loAvQg','192HfiwCv','now','getTime','utf-8','100FRqVgr','sort','18sDHaUO'];a38_0x3df7=function(){return _0x47297c;};return a38_0x3df7();}function getSessionPath(_0x311ec2){const _0x12e8c4=a38_0x5c13;return a38_0x51b236['join'](getSessionsDir(),_0x311ec2+_0x12e8c4(0x191));}export function getCurrentSessionPID(){return getPPID();}export function getSessionID(_0x20bf8e){const _0xc6eae8=a38_0x5c13;if(_0x20bf8e)return _0x20bf8e;return getCurrentSessionPID()[_0xc6eae8(0x16a)]();}export function loadSessionContext(_0x559abc){const _0x17b672=a38_0x5c13,_0x54b3dd=_0x559abc||getCurrentSessionPID()[_0x17b672(0x16a)](),_0x1b3c34=/^\d+$/[_0x17b672(0x193)](_0x54b3dd)?parseInt(_0x54b3dd,0xa):null;return _0x1b3c34!==null?loadSessionContextByPID(_0x1b3c34):loadSessionContextByString(_0x54b3dd);}export function loadSessionContextByPID(_0x5d6cac){const _0x4d4138=a38_0x5c13,_0x10e175=getSessionPath(_0x5d6cac);if(!a38_0x4afd80[_0x4d4138(0x184)](_0x10e175))return null;try{const _0x39ebef=a38_0x4afd80['readFileSync'](_0x10e175,_0x4d4138(0x17d)),_0x1d5c0d=JSON[_0x4d4138(0x182)](_0x39ebef),_0x22c393=new Date(_0x1d5c0d[_0x4d4138(0x173)])[_0x4d4138(0x17c)](),_0x53fcd7=Date['now']();if(_0x53fcd7-_0x22c393>SESSION_EXPIRATION_MS)return a38_0x4afd80[_0x4d4138(0x172)](_0x10e175),null;const _0x358e7f=JSON[_0x4d4138(0x183)](_0x1d5c0d);if(_0x358e7f['includes']('TD_API_KEY')||_0x358e7f[_0x4d4138(0x192)]('apiKey')||_0x358e7f['includes'](_0x4d4138(0x197)))return console[_0x4d4138(0x18c)](_0x4d4138(0x170)+_0x10e175+_0x4d4138(0x194)),a38_0x4afd80[_0x4d4138(0x172)](_0x10e175),null;return _0x1d5c0d;}catch{try{a38_0x4afd80[_0x4d4138(0x172)](_0x10e175);}catch{}return null;}}function loadSessionContextByString(_0x49423e){const _0x9e0b65=a38_0x5c13,_0x5e1ea6=a38_0x51b236['join'](getSessionsDir(),_0x49423e+_0x9e0b65(0x191));if(!a38_0x4afd80[_0x9e0b65(0x184)](_0x5e1ea6))return null;try{const _0x154053=a38_0x4afd80[_0x9e0b65(0x187)](_0x5e1ea6,_0x9e0b65(0x17d)),_0x5857ef=JSON[_0x9e0b65(0x182)](_0x154053),_0x5186b6=new Date(_0x5857ef['createdAt'])[_0x9e0b65(0x17c)](),_0x279834=Date[_0x9e0b65(0x17b)]();if(_0x279834-_0x5186b6>SESSION_EXPIRATION_MS)return a38_0x4afd80[_0x9e0b65(0x172)](_0x5e1ea6),null;const _0x4e0f33=JSON[_0x9e0b65(0x183)](_0x5857ef);if(_0x4e0f33[_0x9e0b65(0x192)](_0x9e0b65(0x186))||_0x4e0f33[_0x9e0b65(0x192)]('apiKey')||_0x4e0f33[_0x9e0b65(0x192)](_0x9e0b65(0x197)))return console[_0x9e0b65(0x18c)]('Warning:\x20API\x20keys\x20found\x20in\x20session\x20file\x20'+_0x5e1ea6+_0x9e0b65(0x194)),a38_0x4afd80[_0x9e0b65(0x172)](_0x5e1ea6),null;return _0x5857ef;}catch{try{a38_0x4afd80['unlinkSync'](_0x5e1ea6);}catch{}return null;}}export function saveSessionContext(_0x33b33c,_0xfb9709){const _0x13be0b=a38_0x5c13,_0x46a001=_0xfb9709||getCurrentSessionPID()[_0x13be0b(0x16a)](),_0x219377=/^\d+$/[_0x13be0b(0x193)](_0x46a001)?parseInt(_0x46a001,0xa):getCurrentSessionPID(),_0xf46765=a38_0x51b236[_0x13be0b(0x190)](getSessionsDir(),_0x46a001+_0x13be0b(0x191)),_0x3d1f93=getSessionsDir();createSecureDirectory(_0x3d1f93);const _0x276eab=JSON['stringify'](_0x33b33c);if(_0x276eab[_0x13be0b(0x192)](_0x13be0b(0x186))||_0x276eab[_0x13be0b(0x192)](_0x13be0b(0x195))||_0x276eab[_0x13be0b(0x192)](_0x13be0b(0x197)))throw new Error(_0x13be0b(0x16c));let _0x2e134c;const _0x26653b=/^\d+$/[_0x13be0b(0x193)](_0x46a001)?loadSessionContextByPID(parseInt(_0x46a001,0xa)):loadSessionContextByString(_0x46a001);_0x26653b?_0x2e134c={..._0x26653b,..._0x33b33c,'pid':_0x219377,'sessionId':_0x46a001!==_0x219377[_0x13be0b(0x16a)]()?_0x46a001:undefined,'updatedAt':new Date()[_0x13be0b(0x18d)]()}:_0x2e134c={'pid':_0x219377,'sessionId':_0x46a001!==_0x219377['toString']()?_0x46a001:undefined,..._0x33b33c,'createdAt':new Date()['toISOString'](),'updatedAt':new Date()['toISOString']()},a38_0x4afd80[_0x13be0b(0x16f)](_0xf46765,JSON[_0x13be0b(0x183)](_0x2e134c,null,0x2));}export function clearSessionContext(_0x4c2de7){const _0x5d119e=a38_0x5c13,_0x58ef9e=_0x4c2de7||getCurrentSessionPID()[_0x5d119e(0x16a)](),_0x174d5c=a38_0x51b236['join'](getSessionsDir(),_0x58ef9e+'.json');a38_0x4afd80[_0x5d119e(0x184)](_0x174d5c)&&a38_0x4afd80[_0x5d119e(0x172)](_0x174d5c);}export function cleanExpiredSessions(){const _0xcd67ef=a38_0x5c13,_0x5402b1=getSessionsDir();if(!a38_0x4afd80['existsSync'](_0x5402b1))return 0x0;let _0x18aa8e=0x0;const _0x3242b3=Date[_0xcd67ef(0x17b)]();try{const _0x14e86a=a38_0x4afd80['readdirSync'](_0x5402b1);for(const _0x257cc1 of _0x14e86a){if(!_0x257cc1[_0xcd67ef(0x185)](_0xcd67ef(0x191)))continue;const _0x4636be=a38_0x51b236[_0xcd67ef(0x190)](_0x5402b1,_0x257cc1),_0x4b4f41=_0x257cc1[_0xcd67ef(0x181)](_0xcd67ef(0x191),''),_0x18cbb3=parseInt(_0x4b4f41,0xa),_0x50778d=!isNaN(_0x18cbb3);if(_0x50778d){if(!isProcessRunning(_0x18cbb3)){a38_0x4afd80[_0xcd67ef(0x172)](_0x4636be),_0x18aa8e++;continue;}}try{const _0x4d7abd=a38_0x4afd80[_0xcd67ef(0x187)](_0x4636be,_0xcd67ef(0x17d)),_0x549207=JSON[_0xcd67ef(0x182)](_0x4d7abd),_0x591847=new Date(_0x549207[_0xcd67ef(0x173)])[_0xcd67ef(0x17c)]();_0x3242b3-_0x591847>SESSION_EXPIRATION_MS&&(a38_0x4afd80['unlinkSync'](_0x4636be),_0x18aa8e++);}catch{a38_0x4afd80[_0xcd67ef(0x172)](_0x4636be),_0x18aa8e++;}}}catch{}return _0x18aa8e;}export function listActiveSessions(){const _0x4ae967=a38_0x5c13,_0x2fbdc0=getSessionsDir();if(!a38_0x4afd80[_0x4ae967(0x184)](_0x2fbdc0))return[];try{const _0x1cdf4f=a38_0x4afd80[_0x4ae967(0x16e)](_0x2fbdc0),_0x4a7867=[];for(const _0x380d7f of _0x1cdf4f){if(!_0x380d7f[_0x4ae967(0x185)](_0x4ae967(0x191)))continue;const _0x4c7e60=_0x380d7f[_0x4ae967(0x181)](_0x4ae967(0x191),''),_0x502ae3=parseInt(_0x4c7e60,0xa);!isNaN(_0x502ae3)&&isProcessRunning(_0x502ae3)&&_0x4a7867[_0x4ae967(0x176)](_0x502ae3);}return _0x4a7867[_0x4ae967(0x17f)]((_0x2035b1,_0x536cde)=>_0x2035b1-_0x536cde);}catch{return[];}}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(_0x583b3d,_0x1e956a){var _0x37a2a5=a39_0x4b72,_0x1260ef=_0x583b3d();while(!![]){try{var _0x480a53=-parseInt(_0x37a2a5(0x157))/0x1+-parseInt(_0x37a2a5(0x153))/0x2+-parseInt(_0x37a2a5(0x15b))/0x3*(parseInt(_0x37a2a5(0x15a))/0x4)+parseInt(_0x37a2a5(0x152))/0x5*(parseInt(_0x37a2a5(0x159))/0x6)+parseInt(_0x37a2a5(0x154))/0x7+parseInt(_0x37a2a5(0x156))/0x8*(-parseInt(_0x37a2a5(0x155))/0x9)+parseInt(_0x37a2a5(0x15c))/0xa*(parseInt(_0x37a2a5(0x158))/0xb);if(_0x480a53===_0x1e956a)break;else _0x1260ef['push'](_0x1260ef['shift']());}catch(_0x5f2cc7){_0x1260ef['push'](_0x1260ef['shift']());}}}(a39_0x2bfc,0x2e42e));export*from'./types/index.js';export*from'./core/config.js';function a39_0x2bfc(){var _0x1ec8c4=['710QyHpae','1792330ixsTGF','161704hAxOBL','1585948gJGQWI','1035sdsAKd','8904ZkjnJN','250256crciyg','46849RPrKfI','6NAZrsm','5028wxurHz','570EMxImj'];a39_0x2bfc=function(){return _0x1ec8c4;};return a39_0x2bfc();}export*from'./core/auth.js';export*from'./client/http-client.js';export*from'./client/td-client.js';export{TrinoClient}from'./client/trino-client.js';export*from'./client/rate-limiter.js';export*from'./types/trino.js';export*from'./commands/command.js';export*from'./commands/query-command.js';export*from'./commands/databases.js';export*from'./commands/tables.js';export*from'./commands/segments.js';function a39_0x4b72(_0x83451d,_0x5e4ba0){var _0x2bfc7b=a39_0x2bfc();return a39_0x4b72=function(_0x4b7248,_0x5e363b){_0x4b7248=_0x4b7248-0x152;var _0x1bfd1d=_0x2bfc7b[_0x4b7248];return _0x1bfd1d;},a39_0x4b72(_0x83451d,_0x5e4ba0);}export*from'./commands/activations.js';export*from'./commands/show.js';export*from'./commands/describe.js';export*from'./sdk/index.js';
|
|
@@ -19,6 +19,14 @@
|
|
|
19
19
|
import type { AnthropicMessage, AnthropicMessagesRequest, AnthropicStreamEvent, AnthropicTool, AnthropicContentBlock } from '../types/anthropic.js';
|
|
20
20
|
import type { ChatEvent } from '../types/index.js';
|
|
21
21
|
import type { TDXLogger } from '../utils/tdx-logger.js';
|
|
22
|
+
/**
|
|
23
|
+
* Determine error type and log all errors
|
|
24
|
+
*
|
|
25
|
+
* @param errorMessage - The error message from TD LLM API
|
|
26
|
+
* @param logger - Optional logger for error logging
|
|
27
|
+
* @returns The appropriate Anthropic error type
|
|
28
|
+
*/
|
|
29
|
+
export declare function determineErrorType(errorMessage: string, logger?: TDXLogger): 'request_too_large' | 'invalid_request_error' | 'api_error';
|
|
22
30
|
/**
|
|
23
31
|
* Estimate total input tokens from Anthropic request
|
|
24
32
|
* Includes system prompts, tool definitions, and full message history
|
|
@@ -113,7 +121,7 @@ export declare function generateToolCallEvents(toolCall: {
|
|
|
113
121
|
id: string;
|
|
114
122
|
name: string;
|
|
115
123
|
input: Record<string, unknown>;
|
|
116
|
-
}, contentIndex: number): Generator<AnthropicStreamEvent, void, unknown>;
|
|
124
|
+
}, contentIndex: number, inputTokens: number): Generator<AnthropicStreamEvent, void, unknown>;
|
|
117
125
|
/**
|
|
118
126
|
* Process TD stream and detect tool calls in text content
|
|
119
127
|
* Buffers text to detect JSON patterns and emits appropriate events
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-adapter.d.ts","sourceRoot":"","sources":["../../src/proxy/anthropic-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACxB,oBAAoB,EAOpB,aAAa,EACb,qBAAqB,EACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,SAAS,EAAuD,MAAM,mBAAmB,CAAC;AAExG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"anthropic-adapter.d.ts","sourceRoot":"","sources":["../../src/proxy/anthropic-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACxB,oBAAoB,EAOpB,aAAa,EACb,qBAAqB,EACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,SAAS,EAAuD,MAAM,mBAAmB,CAAC;AAExG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AA2BxD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,MAAM,EACpB,MAAM,CAAC,EAAE,SAAS,GACjB,mBAAmB,GAAG,uBAAuB,GAAG,WAAW,CAc7D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,8BAA8B,CAAC,OAAO,EAAE;IACtD,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,GAAG,qBAAqB,EAAE,CAAC;IAC1C,KAAK,CAAC,EAAE,aAAa,EAAE,CAAC;CACzB,GAAG,MAAM,CA0DT;AAED;;GAEG;AACH,iBAAS,iBAAiB,IAAI,MAAM,CAEnC;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAqBjF;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,eAAe,EAAE,gBAAgB,EAAE,EACnC,gBAAgB,EAAE,gBAAgB,EAAE,GACnC,gBAAgB,EAAE,CAYpB;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,wBAAwB,EACjC,gBAAgB,EAAE,gBAAgB,EAAE,GACnC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,gBAAgB,EAAE,CAAA;CAAE,CAgB5D;AAED;;;;;;;;;;;GAWG;AACH,wBAAuB,4BAA4B,CACjD,QAAQ,EAAE,cAAc,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,EAClD,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,WAAW,SAAK,EAChB,WAAW,SAAI,GACd,cAAc,CAAC,oBAAoB,EAAE,IAAI,EAAE,OAAO,CAAC,CAqIrD;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,CAEtE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAiBpE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,aAAa,EAAE,GAAG,MAAM,CAwEjE;AAWD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,MAAM,CA6DvE;AA8HD;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG;IACvE,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,IAAI,CAmIP;AAED;;;GAGG;AACH,wBAAiB,sBAAsB,CACrC,QAAQ,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,EACtE,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,GAClB,SAAS,CAAC,oBAAoB,EAAE,IAAI,EAAE,OAAO,CAAC,CAqDhD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAuB,kCAAkC,CACvD,QAAQ,EAAE,cAAc,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,EAClD,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,SAAS,EAClB,WAAW,SAAK,EAChB,WAAW,SAAI,GACd,cAAc,CAAC,oBAAoB,EAAE,IAAI,EAAE,OAAO,CAAC,CAocrD;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(_0x25f9e8,_0x44b644){const _0x4c934c=a40_0x24aa,_0x24ec88=_0x25f9e8();while(!![]){try{const _0x3f12ca=-parseInt(_0x4c934c(0x230))/0x1+-parseInt(_0x4c934c(0x1fb))/0x2+parseInt(_0x4c934c(0x21b))/0x3*(-parseInt(_0x4c934c(0x223))/0x4)+parseInt(_0x4c934c(0x20e))/0x5*(-parseInt(_0x4c934c(0x1e7))/0x6)+-parseInt(_0x4c934c(0x239))/0x7+parseInt(_0x4c934c(0x1f2))/0x8+-parseInt(_0x4c934c(0x217))/0x9*(-parseInt(_0x4c934c(0x21e))/0xa);if(_0x3f12ca===_0x44b644)break;else _0x24ec88['push'](_0x24ec88['shift']());}catch(_0xfd32a9){_0x24ec88['push'](_0x24ec88['shift']());}}}(a40_0x2fe1,0x47f22));import{SDKError,ErrorCode}from'../sdk/errors.js';function estimateTokenCount(_0x324eda){const _0x1c9c6e=a40_0x24aa;if(!_0x324eda||_0x324eda[_0x1c9c6e(0x1ee)]===0x0)return 0x0;return Math[_0x1c9c6e(0x224)](_0x324eda[_0x1c9c6e(0x1ee)]/3.7);}function determineErrorType(_0xa34e32,_0x5a8055){const _0x10f106=a40_0x24aa,_0x42fa7a=_0xa34e32[_0x10f106(0x1f1)]('Input\x20is\x20too\x20long')||_0xa34e32['includes'](_0x10f106(0x240))||_0xa34e32[_0x10f106(0x1f1)](_0x10f106(0x22d));if(_0x42fa7a)return _0x5a8055?.['error'](_0x10f106(0x1f3)+_0xa34e32),_0x10f106(0x1f0);return _0x5a8055?.['error'](_0x10f106(0x214)+_0xa34e32),_0x10f106(0x1f5);}export function estimateInputTokensFromRequest(_0x56dc45){const _0x3632ed=a40_0x24aa;let _0x415bea=0x0;if(typeof _0x56dc45['system']==='string')_0x415bea+=_0x56dc45['system'][_0x3632ed(0x1ee)];else{if(Array['isArray'](_0x56dc45['system']))for(const _0x4317ec of _0x56dc45[_0x3632ed(0x1f4)]){_0x4317ec&&typeof _0x4317ec[_0x3632ed(0x232)]===_0x3632ed(0x222)&&(_0x415bea+=_0x4317ec[_0x3632ed(0x232)]['length']);}}if(Array[_0x3632ed(0x200)](_0x56dc45[_0x3632ed(0x236)]))for(const _0x1fda2d of _0x56dc45[_0x3632ed(0x236)]){_0x1fda2d&&(_0x415bea+=_0x1fda2d[_0x3632ed(0x209)][_0x3632ed(0x1ee)],_0x415bea+=_0x1fda2d[_0x3632ed(0x1e3)]?.['length']||0x0,_0x415bea+=JSON[_0x3632ed(0x243)](_0x1fda2d[_0x3632ed(0x22b)])['length']);}if(Array[_0x3632ed(0x200)](_0x56dc45[_0x3632ed(0x202)]))for(const _0x29ed8b of _0x56dc45[_0x3632ed(0x202)]){if(!_0x29ed8b)continue;if(typeof _0x29ed8b['content']===_0x3632ed(0x222))_0x415bea+=_0x29ed8b[_0x3632ed(0x247)][_0x3632ed(0x1ee)];else{if(Array[_0x3632ed(0x200)](_0x29ed8b[_0x3632ed(0x247)]))for(const _0x49f8d8 of _0x29ed8b[_0x3632ed(0x247)]){if(!_0x49f8d8)continue;if(_0x49f8d8[_0x3632ed(0x1fe)]===_0x3632ed(0x232)&&_0x49f8d8[_0x3632ed(0x232)])_0x415bea+=_0x49f8d8['text'][_0x3632ed(0x1ee)];else{if(_0x49f8d8['type']===_0x3632ed(0x225)&&_0x49f8d8['input'])_0x415bea+=JSON[_0x3632ed(0x243)](_0x49f8d8['input'])['length'];else{if(_0x49f8d8['type']===_0x3632ed(0x238)&&_0x49f8d8[_0x3632ed(0x247)]){if(typeof _0x49f8d8[_0x3632ed(0x247)]===_0x3632ed(0x222))_0x415bea+=_0x49f8d8[_0x3632ed(0x247)][_0x3632ed(0x1ee)];else{if(Array[_0x3632ed(0x200)](_0x49f8d8[_0x3632ed(0x247)]))for(const _0x526067 of _0x49f8d8[_0x3632ed(0x247)]){_0x526067&&_0x526067['type']===_0x3632ed(0x232)&&_0x526067[_0x3632ed(0x232)]&&(_0x415bea+=_0x526067[_0x3632ed(0x232)][_0x3632ed(0x1ee)]);}}}}}}}}return Math[_0x3632ed(0x224)](_0x415bea/3.7);}function generateMessageId(){const _0x33c41e=a40_0x24aa;return _0x33c41e(0x204)+Math['random']()['toString'](0x24)[_0x33c41e(0x210)](0x2,0xf)+Math[_0x33c41e(0x211)]()[_0x33c41e(0x241)](0x24)[_0x33c41e(0x210)](0x2,0xf);}export function extractTextFromAnthropicMessage(_0x39d290){const _0x176bb7=a40_0x24aa;if(typeof _0x39d290['content']===_0x176bb7(0x222))return _0x39d290[_0x176bb7(0x247)];if(_0x39d290['content']==null)return'';if(!Array[_0x176bb7(0x200)](_0x39d290[_0x176bb7(0x247)]))throw new SDKError(ErrorCode['LLM_MALFORMED_MESSAGE'],'Invalid\x20message.content\x20type:\x20expected\x20string\x20or\x20array,\x20got\x20'+typeof _0x39d290['content']);return _0x39d290[_0x176bb7(0x247)][_0x176bb7(0x215)](_0x20f99f=>_0x20f99f&&_0x20f99f[_0x176bb7(0x1fe)]==='text'&&_0x20f99f[_0x176bb7(0x232)])['map'](_0x2ccff1=>_0x2ccff1[_0x176bb7(0x232)])['join']('\x0a');}export function calculateConversationDelta(_0x3e4019,_0x1d88a6){const _0x5e3035=a40_0x24aa;if(_0x1d88a6[_0x5e3035(0x1ee)]===0x0)return _0x3e4019;const _0x2d2a08=_0x1d88a6[_0x5e3035(0x1ee)];return _0x3e4019[_0x5e3035(0x1e6)](_0x2d2a08);}export function transformAnthropicRequestToTD(_0x498c93,_0xd741ae){const _0x531afc=a40_0x24aa,_0x28bbc5=calculateConversationDelta(_0x498c93[_0x531afc(0x202)],_0xd741ae),_0x2000eb=_0x28bbc5['filter'](_0x41b217=>_0x41b217['role']===_0x531afc(0x206))[_0x531afc(0x1eb)]();if(!_0x2000eb)throw new Error(_0x531afc(0x1f7));const _0x69f9a7=extractTextFromAnthropicMessage(_0x2000eb);return{'userMessage':_0x69f9a7,'deltaMessages':_0x28bbc5};}export async function*transformTDStreamToAnthropic(_0x2f0ffe,_0x48eeb3,_0x2486cf,_0x4c8bb0='',_0x1562b4=0x0){const _0x4e1402=a40_0x24aa,_0x55b9b0=_0x1562b4>0x0?_0x1562b4:estimateTokenCount(_0x4c8bb0);let _0xd7e243=0x0,_0x14b41e=0x0,_0xcbc21c=![];const _0x2130e7={'type':'message_start','message':{'id':_0x48eeb3,'type':_0x4e1402(0x21d),'role':_0x4e1402(0x237),'content':[],'model':_0x2486cf,'stop_reason':null,'stop_sequence':null,'usage':{'input_tokens':_0x55b9b0,'output_tokens':0x0}}};yield _0x2130e7;for await(const _0x48205f of _0x2f0ffe){if(_0x4e1402(0x247)in _0x48205f){const _0x329853=_0x48205f;if(!_0xcbc21c){const _0x4c3c0a={'type':'content_block_start','index':_0x14b41e,'content_block':{'type':'text','text':''}};yield _0x4c3c0a,_0xcbc21c=!![];}const _0x469545={'type':'content_block_delta','index':_0x14b41e,'delta':{'type':_0x4e1402(0x208),'text':_0x329853[_0x4e1402(0x247)]}};yield _0x469545,_0xd7e243+=estimateTokenCount(_0x329853[_0x4e1402(0x247)]);}else{if(_0x4e1402(0x1ea)in _0x48205f){const _0x522f84=_0x48205f;console['warn']('Tool\x20calls\x20not\x20yet\x20supported\x20in\x20proxy:',_0x522f84);}else{if('error'in _0x48205f){const _0xdfab15=_0x48205f,_0x1d6a7d=determineErrorType(_0xdfab15[_0x4e1402(0x228)]);yield{'type':_0x4e1402(0x228),'error':{'type':_0x1d6a7d,'message':_0xdfab15[_0x4e1402(0x228)]},'request_id':_0x48eeb3};return;}}}}if(_0xcbc21c){const _0x304a7c={'type':'content_block_stop','index':_0x14b41e};yield _0x304a7c;}const _0x4d8613={'type':_0x4e1402(0x245),'delta':{'stop_reason':_0x4e1402(0x20d),'stop_sequence':null},'usage':{'output_tokens':_0xd7e243}};yield _0x4d8613;const _0x1731ec={'type':'message_stop'};yield _0x1731ec;}export function formatAnthropicSSE(_0x4ac26b){const _0x4c9eed=a40_0x24aa;return _0x4c9eed(0x1ff)+_0x4ac26b[_0x4c9eed(0x1fe)]+_0x4c9eed(0x1ef)+JSON['stringify'](_0x4ac26b)+'\x0a\x0a';}export function mapAnthropicModelToTD(_0x1835c3){const _0x196bfc=a40_0x24aa,_0x23e76b={'sonnet':'sonnet','claude-sonnet':_0x196bfc(0x1fd),'claude-3-5-sonnet':_0x196bfc(0x1fd),'claude-3-sonnet':_0x196bfc(0x1fd),'haiku':'haiku','claude-haiku':'haiku','claude-3-5-haiku':_0x196bfc(0x205),'claude-3-haiku':_0x196bfc(0x205),'opus':_0x196bfc(0x1e5),'claude-opus':_0x196bfc(0x1e5),'claude-3-opus':_0x196bfc(0x1e5)},_0x183000=_0x1835c3['toLowerCase']();return _0x23e76b[_0x183000]||_0x196bfc(0x1fd);}export function generateToolPrompt(_0x1bd4ee){const _0x116237=a40_0x24aa;if(_0x1bd4ee==null)return'';if(!Array['isArray'](_0x1bd4ee))throw new SDKError(ErrorCode['LLM_MALFORMED_MESSAGE'],_0x116237(0x1fc)+typeof _0x1bd4ee);if(_0x1bd4ee['length']===0x0)return'';const _0x381563=_0x1bd4ee[_0x116237(0x215)](_0x5ce866=>_0x5ce866!=null)[_0x116237(0x234)](_0x4ba23d=>{const _0x41d285=_0x116237,_0x229f25=JSON[_0x41d285(0x243)](_0x4ba23d[_0x41d285(0x22b)],null,0x2);return _0x41d285(0x1ed)+_0x4ba23d['name']+_0x41d285(0x218)+(_0x4ba23d[_0x41d285(0x1e3)]||_0x41d285(0x23d))+_0x41d285(0x20f)+_0x229f25+_0x41d285(0x21f);})['join']('\x0a\x0a');return _0x116237(0x1e9)+_0x381563+_0x116237(0x20c);}function a40_0x2fe1(){const _0xb40d59=['message_stop','Malformed\x20tool_use\x20JSON\x20detected','\x0a---\x0a','end_turn','1517665oUzzxA','\x0a\x0a**Input\x20Schema:**\x0a```json\x0a','substring','random','toolu_','content_block_delta','[API\x20ERROR]\x20','filter','is_error','153tAptfI','\x0a\x0a**Description:**\x20','Invalid\x20messages\x20type:\x20expected\x20array,\x20got\x20','```tool_use','7221qnGKtx','Multiple\x20tool\x20calls\x20detected,\x20using\x20only\x20the\x20last\x20one:\x20','message','977570zLGtNd','\x0a```','Malformed\x20content:','warn','string','508EnitJu','ceil','tool_use','\x20error=true','push','error','parse','tool_use_id','input_schema','debug','maximum\x20context','min','index','557830AeZEpN','{\x22tool_use\x22:','text','startIndex','map','exec','tools','assistant','tool_result','1986481FQgUWG','\x0a\x0aPlease\x20continue\x20your\x20response\x20based\x20on\x20the\x20tool\x20results\x20above.\x0a\x0a','message_start','LLM_MALFORMED_MESSAGE','No\x20description','\x0a[After]:\x0a','input','context\x20length','toString','replace','stringify','endsWith','message_delta','endIndex','content','```','description','join','opus','slice','6ZKSOSr','indexOf','\x0a#\x20How\x20to\x20Use\x20Tools\x0a\x0aTo\x20use\x20a\x20tool,\x20output\x20the\x20tool\x20call\x20in\x20a\x20markdown\x20code\x20block:\x0a\x0a```tool_use\x0a{\x22tool_use\x22:{\x22id\x22:\x22toolu_<random>\x22,\x22name\x22:\x22<tool_name>\x22,\x22input\x22:{<parameters>}}}\x0a```\x0a\x0a**IMPORTANT:**\x0a-\x20**Output\x20only\x20ONE\x20tool_use\x20at\x20a\x20time**\x20-\x20Never\x20output\x20multiple\x20tool\x20calls\x20in\x20a\x20single\x20response\x0a-\x20Use\x20the\x20precise\x20parameter\x20names\x20and\x20types\x20as\x20defined\x20in\x20the\x20JSON\x20schema.\x0a-\x20Wrap\x20the\x20JSON\x20in\x20a\x20markdown\x20code\x20block\x20with\x20```tool_use\x0a-\x20The\x20JSON\x20must\x20be\x20valid\x20and\x20properly\x20formatted.\x20Ensure\x20all\x20strings\x20are\x20double\x20quoted.\x0a-\x20Generate\x20a\x20unique\x20random\x20ID\x20starting\x20with\x20\x22toolu_\x22\x0a-\x20After\x20outputting\x20the\x20tool\x20use,\x20stop\x20and\x20wait\x20for\x20the\x20tool\x20result\x0a-\x20Tool\x20results\x20will\x20be\x20provided\x20in\x20markdown\x20code\x20blocks\x20with\x20```tool_result\x20tool_use_id=<id>\x0a-\x20Once\x20you\x20receive\x20a\x20tool\x20result,\x20you\x20may\x20call\x20another\x20tool\x20if\x20needed,\x20or\x20continue\x20your\x20response\x20naturally\x0a\x0a**Example\x201\x20-\x20Simple\x20tool:**\x0aUser:\x20\x22What\x27s\x2025\x20*\x204?\x22\x0aAssistant:\x20I\x27ll\x20calculate\x20that\x20for\x20you.\x0a\x0a```tool_use\x0a{\x22tool_use\x22:{\x22id\x22:\x22toolu_abc123\x22,\x22name\x22:\x22calculator\x22,\x22input\x22:{\x22expression\x22:\x2225\x20*\x204\x22}}}\x0a```\x0a\x0a**Example\x202\x20-\x20Tool\x20with\x20multiline\x20strings\x20(proper\x20escaping):**\x0aUser:\x20\x22Edit\x20the\x20file\x20to\x20add\x20a\x20newline\x22\x0aAssistant:\x20I\x27ll\x20edit\x20the\x20file\x20with\x20proper\x20JSON\x20escaping.\x0a\x0a```tool_use\x0a{\x22tool_use\x22:{\x22id\x22:\x22toolu_def456\x22,\x22name\x22:\x22Edit\x22,\x22input\x22:{\x22file_path\x22:\x22test.ts\x22,\x22old_string\x22:\x22const\x20x\x20=\x201;\x22,\x22new_string\x22:\x22const\x20x\x20=\x201;\x5cnconst\x20y\x20=\x202;\x22}}}\x0a```\x0a\x0a#\x20Available\x20Tools\x0a\x0a','tool_call','pop','[MALFORMED\x20JSON]\x20Tool\x20use\x20JSON\x20could\x20not\x20be\x20parsed\x20or\x20repaired:\x0a','##\x20Tool:\x20','length','\x0adata:\x20','invalid_request_error','includes','4194232bfJwry','[CONTEXT\x20LENGTH\x20ERROR]\x20','system','api_error','Invalid\x20message.content\x20type\x20for\x20user\x20role:\x20expected\x20array,\x20got\x20','No\x20user\x20message\x20found\x20in\x20request\x20delta','content_block_start','content_block_stop','usage','881246OJGzgx','Invalid\x20tools\x20type:\x20expected\x20array,\x20got\x20','sonnet','type','event:\x20','isArray','[JSON\x20REPAIR]\x20Successfully\x20repaired\x20malformed\x20JSON\x0a[Before]:\x0a','messages','arguments','msg_','haiku','user','trim','text_delta','name'];a40_0x2fe1=function(){return _0xb40d59;};return a40_0x2fe1();}function escapeMarkdownCodeBlock(_0x226188){const _0x4796c0=a40_0x24aa;return _0x226188[_0x4796c0(0x242)](/```/g,'\x5c`\x5c`\x5c`');}export function extractToolResults(_0x51f4ab){const _0x4eb9e3=a40_0x24aa;if(_0x51f4ab==null)return'';if(!Array['isArray'](_0x51f4ab))throw new SDKError(ErrorCode[_0x4eb9e3(0x23c)],_0x4eb9e3(0x219)+typeof _0x51f4ab);const _0x1f8a85=[];for(const _0xd85ebb of _0x51f4ab){if(!_0xd85ebb)continue;if(_0xd85ebb['role']==='user'&&typeof _0xd85ebb[_0x4eb9e3(0x247)]!==_0x4eb9e3(0x222)){if(!Array[_0x4eb9e3(0x200)](_0xd85ebb[_0x4eb9e3(0x247)]))throw new SDKError(ErrorCode['LLM_MALFORMED_MESSAGE'],_0x4eb9e3(0x1f6)+typeof _0xd85ebb['content']);for(const _0x571ae5 of _0xd85ebb[_0x4eb9e3(0x247)]){if(!_0x571ae5)continue;if(_0x571ae5['type']===_0x4eb9e3(0x238)&&_0x571ae5[_0x4eb9e3(0x22a)]){let _0x141daa='';if(typeof _0x571ae5['content']===_0x4eb9e3(0x222))_0x141daa=_0x571ae5['content'];else _0x571ae5[_0x4eb9e3(0x247)]!=null&&Array[_0x4eb9e3(0x200)](_0x571ae5[_0x4eb9e3(0x247)])&&(_0x141daa=_0x571ae5[_0x4eb9e3(0x247)][_0x4eb9e3(0x215)](_0x5881ce=>_0x5881ce&&_0x5881ce[_0x4eb9e3(0x1fe)]===_0x4eb9e3(0x232)&&_0x5881ce['text'])[_0x4eb9e3(0x234)](_0x11f76b=>_0x11f76b[_0x4eb9e3(0x232)])[_0x4eb9e3(0x1e4)]('\x0a'));const _0x4d6522=escapeMarkdownCodeBlock(_0x141daa),_0x5748d0=_0x571ae5[_0x4eb9e3(0x216)]?_0x4eb9e3(0x226):'';_0x1f8a85[_0x4eb9e3(0x227)]('```tool_result\x20tool_use_id='+_0x571ae5['tool_use_id']+_0x5748d0+'\x0a'+_0x4d6522+_0x4eb9e3(0x21f));}}}}if(_0x1f8a85['length']===0x0)return'';return _0x1f8a85[_0x4eb9e3(0x1e4)]('\x0a\x0a')+_0x4eb9e3(0x23a);}function findJsonEndIndex(_0xbfce53,_0x4c1077){let _0x1cad80=0x0,_0x384c63=![],_0x35eb11=![];for(let _0x3016b3=_0x4c1077;_0x3016b3<_0xbfce53['length'];_0x3016b3++){const _0x6d8c8b=_0xbfce53[_0x3016b3];if(_0x35eb11){_0x35eb11=![];continue;}if(_0x6d8c8b==='\x5c'){_0x35eb11=!![];continue;}if(_0x6d8c8b==='\x22'){_0x384c63=!_0x384c63;continue;}if(!_0x384c63){if(_0x6d8c8b==='{')_0x1cad80++;else{if(_0x6d8c8b==='}'){_0x1cad80--;if(_0x1cad80===0x0)return _0x3016b3+0x1;}}}}return-0x1;}function a40_0x24aa(_0x47e796,_0x2ead3c){const _0x2fe1ec=a40_0x2fe1();return a40_0x24aa=function(_0x24aaa7,_0x384d25){_0x24aaa7=_0x24aaa7-0x1e2;let _0x3c4b75=_0x2fe1ec[_0x24aaa7];return _0x3c4b75;},a40_0x24aa(_0x47e796,_0x2ead3c);}function generateToolCallId(){const _0x25a3f0=a40_0x24aa;return _0x25a3f0(0x212)+Math[_0x25a3f0(0x211)]()[_0x25a3f0(0x241)](0x24)[_0x25a3f0(0x210)](0x2,0xf);}function repairIncompleteJson(_0x4d0db6,_0x33e600){const _0x202838=a40_0x24aa;try{return JSON['parse'](_0x4d0db6),_0x4d0db6;}catch{const _0x5f476a=[];let _0x521a19=![],_0x1135dd=![];for(const _0x1f89de of _0x4d0db6){if(_0x1135dd){_0x1135dd=![];continue;}if(_0x1f89de==='\x5c'){_0x1135dd=!![];continue;}if(_0x1f89de==='\x22'){_0x521a19=!_0x521a19;continue;}if(!_0x521a19){if(_0x1f89de==='{')_0x5f476a[_0x202838(0x227)]('{');else{if(_0x1f89de==='[')_0x5f476a['push']('[');else{if(_0x1f89de==='}'&&_0x5f476a[_0x5f476a[_0x202838(0x1ee)]-0x1]==='{')_0x5f476a['pop']();else _0x1f89de===']'&&_0x5f476a[_0x5f476a['length']-0x1]==='['&&_0x5f476a[_0x202838(0x1eb)]();}}}}let _0x40f06a=_0x4d0db6;_0x521a19&&(_0x40f06a+='\x22');while(_0x5f476a[_0x202838(0x1ee)]>0x0){const _0x33f39e=_0x5f476a[_0x202838(0x1eb)]();_0x40f06a+=_0x33f39e==='{'?'}':']';}try{return JSON['parse'](_0x40f06a),_0x33e600&&_0x40f06a!==_0x4d0db6&&_0x33e600[_0x202838(0x221)](_0x202838(0x201)+_0x4d0db6+_0x202838(0x23e)+_0x40f06a),_0x40f06a;}catch{return null;}}}export function parseToolCallFromText(_0x5cc3ca,_0x520bb6){const _0x202d67=a40_0x24aa,_0x3a0494=/```tool_use[\s]*\n([\s\S]*)\n?```/,_0x565f2b=_0x3a0494[_0x202d67(0x235)](_0x5cc3ca);if(_0x565f2b){if(!_0x565f2b[0x0][_0x202d67(0x244)](_0x202d67(0x1e2))){}else{const _0x2dacf8=_0x565f2b[0x1][_0x202d67(0x207)](),_0xa520c6=_0x565f2b[_0x202d67(0x22f)],_0xa62da1=_0xa520c6+_0x565f2b[0x0][_0x202d67(0x1ee)];try{const _0x4b21b3=JSON[_0x202d67(0x229)](_0x2dacf8);if(_0x4b21b3['tool_use']&&_0x4b21b3['tool_use'][_0x202d67(0x209)])return{'id':_0x4b21b3['tool_use']['id']||generateToolCallId(),'name':_0x4b21b3[_0x202d67(0x225)]['name'],'input':_0x4b21b3[_0x202d67(0x225)][_0x202d67(0x23f)]||{},'startIndex':_0xa520c6,'endIndex':_0xa62da1};if(_0x4b21b3[_0x202d67(0x209)]&&typeof _0x4b21b3[_0x202d67(0x209)]===_0x202d67(0x222)&&_0x4b21b3[_0x202d67(0x209)][_0x202d67(0x207)]()['length']>0x0)return{'id':_0x4b21b3['id']||generateToolCallId(),'name':_0x4b21b3[_0x202d67(0x209)],'input':_0x4b21b3[_0x202d67(0x23f)]||_0x4b21b3[_0x202d67(0x203)]||{},'startIndex':_0xa520c6,'endIndex':_0xa62da1};}catch{const _0x66ada2=repairIncompleteJson(_0x2dacf8,_0x520bb6);if(_0x66ada2)try{const _0x4ed83c=JSON[_0x202d67(0x229)](_0x66ada2);if(_0x4ed83c[_0x202d67(0x225)]&&_0x4ed83c[_0x202d67(0x225)][_0x202d67(0x209)])return{'id':_0x4ed83c[_0x202d67(0x225)]['id']||generateToolCallId(),'name':_0x4ed83c[_0x202d67(0x225)][_0x202d67(0x209)],'input':_0x4ed83c[_0x202d67(0x225)][_0x202d67(0x23f)]||{},'startIndex':_0xa520c6,'endIndex':_0xa62da1};if(_0x4ed83c[_0x202d67(0x209)]&&typeof _0x4ed83c[_0x202d67(0x209)]===_0x202d67(0x222)&&_0x4ed83c[_0x202d67(0x209)][_0x202d67(0x207)]()['length']>0x0)return{'id':_0x4ed83c['id']||generateToolCallId(),'name':_0x4ed83c[_0x202d67(0x209)],'input':_0x4ed83c['input']||_0x4ed83c[_0x202d67(0x203)]||{},'startIndex':_0xa520c6,'endIndex':_0xa62da1};}catch{}}}}const _0x462c9a=/\{"tool_use":/g,_0x323552=_0x462c9a[_0x202d67(0x235)](_0x5cc3ca);if(!_0x323552)return null;const _0x4e4816=_0x323552['index'];let _0x17a3aa=findJsonEndIndex(_0x5cc3ca,_0x4e4816);if(_0x17a3aa===-0x1)return null;const _0xa000c6=_0x5cc3ca[_0x202d67(0x210)](_0x4e4816,_0x17a3aa);try{const _0x4f8783=JSON[_0x202d67(0x229)](_0xa000c6);if(_0x4f8783[_0x202d67(0x225)]&&_0x4f8783['tool_use']['id']&&_0x4f8783[_0x202d67(0x225)]['name'])return{'id':_0x4f8783[_0x202d67(0x225)]['id'],'name':_0x4f8783[_0x202d67(0x225)][_0x202d67(0x209)],'input':_0x4f8783[_0x202d67(0x225)]['input']||{},'startIndex':_0x4e4816,'endIndex':_0x17a3aa};}catch{const _0x1b1625=repairIncompleteJson(_0xa000c6,_0x520bb6);if(_0x1b1625)try{const _0xe254a1=JSON['parse'](_0x1b1625);if(_0xe254a1[_0x202d67(0x225)]&&_0xe254a1[_0x202d67(0x225)]['id']&&_0xe254a1[_0x202d67(0x225)][_0x202d67(0x209)])return{'id':_0xe254a1[_0x202d67(0x225)]['id'],'name':_0xe254a1[_0x202d67(0x225)]['name'],'input':_0xe254a1[_0x202d67(0x225)][_0x202d67(0x23f)]||{},'startIndex':_0x4e4816,'endIndex':_0x17a3aa};}catch{return null;}return null;}return null;}export function*generateToolCallEvents(_0x539f1e,_0x11263e){const _0x183103=a40_0x24aa,_0x522917={'type':_0x183103(0x1f8),'index':_0x11263e,'content_block':{'type':_0x183103(0x225),'id':_0x539f1e['id'],'name':_0x539f1e['name'],'input':{}}};yield _0x522917;const _0x5eec1b=JSON[_0x183103(0x243)](_0x539f1e[_0x183103(0x23f)]),_0x5817c6={'type':_0x183103(0x213),'index':_0x11263e,'delta':{'type':'input_json_delta','partial_json':_0x5eec1b}};yield _0x5817c6;const _0xecb881={'type':'content_block_stop','index':_0x11263e};yield _0xecb881;const _0x91c713={'type':_0x183103(0x245),'delta':{'stop_reason':_0x183103(0x225),'stop_sequence':null},'usage':{'output_tokens':0x0}};yield _0x91c713;const _0x358f76={'type':_0x183103(0x20a)};yield _0x358f76;}export async function*transformTDStreamWithToolDetection(_0x35e2d4,_0x3e2443,_0x293b19,_0x49ee2f,_0x3d0b4f='',_0x51e039=0x0){const _0x1d3a16=a40_0x24aa,_0x17a80f=_0x51e039>0x0?_0x51e039:estimateTokenCount(_0x3d0b4f);let _0x240439=0x0,_0x2de014=0x0,_0x4f61f8=![],_0x325062='',_0x2e25da=0x0,_0x53ad00=![];const _0x46dbd9=0xc8,_0x15459c={'type':_0x1d3a16(0x23b),'message':{'id':_0x3e2443,'type':'message','role':_0x1d3a16(0x237),'content':[],'model':_0x293b19,'stop_reason':null,'stop_sequence':null,'usage':{'input_tokens':_0x17a80f,'output_tokens':0x0}}};yield _0x15459c;for await(const _0x4c4e7e of _0x35e2d4){if(_0x1d3a16(0x247)in _0x4c4e7e){const _0x436210=_0x4c4e7e;_0x325062+=_0x436210[_0x1d3a16(0x247)];const _0x2bf7f3=_0x325062[_0x1d3a16(0x1e8)]('```tool_use'),_0x4e4ce3=_0x325062['indexOf'](_0x1d3a16(0x231)),_0x9c7839=_0x2bf7f3!==-0x1?_0x4e4ce3!==-0x1?Math[_0x1d3a16(0x22e)](_0x2bf7f3,_0x4e4ce3):_0x2bf7f3:_0x4e4ce3;if(_0x9c7839!==-0x1){const _0x3c63cd=[];let _0x4cfb7f=0x0;while(!![]){const _0x47a83f=_0x325062[_0x1d3a16(0x210)](_0x4cfb7f),_0x1c21d7=parseToolCallFromText(_0x47a83f,_0x49ee2f);if(!_0x1c21d7)break;_0x3c63cd[_0x1d3a16(0x227)]({'id':_0x1c21d7['id'],'name':_0x1c21d7['name'],'input':_0x1c21d7[_0x1d3a16(0x23f)],'startIndex':_0x4cfb7f+_0x1c21d7[_0x1d3a16(0x233)],'endIndex':_0x4cfb7f+_0x1c21d7[_0x1d3a16(0x246)]}),_0x4cfb7f+=_0x1c21d7[_0x1d3a16(0x246)];}if(_0x3c63cd[_0x1d3a16(0x1ee)]>0x0){const _0x1fac84=_0x3c63cd[_0x3c63cd[_0x1d3a16(0x1ee)]-0x1];_0x53ad00=!![];_0x3c63cd[_0x1d3a16(0x1ee)]>0x1?_0x49ee2f?.[_0x1d3a16(0x22c)](_0x1d3a16(0x21c)+_0x1fac84[_0x1d3a16(0x209)]):_0x49ee2f?.[_0x1d3a16(0x22c)]('Tool\x20call\x20detected:\x20'+_0x1fac84['name']);const _0x5e3058=_0x325062[_0x1d3a16(0x210)](_0x2e25da,_0x1fac84[_0x1d3a16(0x233)])[_0x1d3a16(0x207)]();if(_0x5e3058){if(!_0x4f61f8){const _0x40d159={'type':_0x1d3a16(0x1f8),'index':_0x2de014,'content_block':{'type':_0x1d3a16(0x232),'text':''}};yield _0x40d159,_0x4f61f8=!![];}const _0x12165e={'type':'content_block_delta','index':_0x2de014,'delta':{'type':_0x1d3a16(0x208),'text':_0x5e3058}};yield _0x12165e,_0x240439+=estimateTokenCount(_0x5e3058);}if(_0x4f61f8){const _0x5d5055={'type':_0x1d3a16(0x1f9),'index':_0x2de014};yield _0x5d5055,_0x2de014++,_0x4f61f8=![];}for(const _0x3a4183 of generateToolCallEvents(_0x1fac84,_0x2de014)){_0x3a4183[_0x1d3a16(0x1fe)]===_0x1d3a16(0x245)&&(_0x3a4183[_0x1d3a16(0x1fa)]['output_tokens']=_0x240439),yield _0x3a4183;}return;}const _0x56a341=_0x325062['includes'](_0x1d3a16(0x21a))&&_0x325062[_0x1d3a16(0x1e8)](_0x1d3a16(0x1e2),_0x325062[_0x1d3a16(0x1e8)]('```tool_use')+0xb)!==-0x1,_0xe2c2f1=_0x325062['includes'](_0x1d3a16(0x231))&&findJsonEndIndex(_0x325062,_0x325062[_0x1d3a16(0x1e8)]('{\x22tool_use\x22:'))!==-0x1;if(_0x56a341||_0xe2c2f1){_0x53ad00=!![];let _0x2ebb51='';if(_0x56a341){const _0x15414a=_0x325062['indexOf'](_0x1d3a16(0x21a)),_0xe44fa9=_0x325062['indexOf'](_0x1d3a16(0x1e2),_0x15414a+0xb);_0xe44fa9!==-0x1?_0x2ebb51=_0x325062[_0x1d3a16(0x210)](_0x15414a,_0xe44fa9+0x3):_0x2ebb51=_0x325062[_0x1d3a16(0x210)](_0x15414a);}else{if(_0xe2c2f1){const _0x288150=_0x325062['indexOf'](_0x1d3a16(0x231)),_0x3fe33b=findJsonEndIndex(_0x325062,_0x288150);_0x3fe33b!==-0x1?_0x2ebb51=_0x325062[_0x1d3a16(0x210)](_0x288150,_0x3fe33b):_0x2ebb51=_0x325062[_0x1d3a16(0x210)](_0x288150);}}_0x49ee2f&&_0x49ee2f[_0x1d3a16(0x228)](_0x1d3a16(0x1ec)+_0x2ebb51);_0x49ee2f?.[_0x1d3a16(0x22c)](_0x1d3a16(0x20b)),_0x49ee2f?.[_0x1d3a16(0x22c)](_0x1d3a16(0x220),_0x2ebb51);const _0x182f2c=_0x325062[_0x1d3a16(0x210)](_0x2e25da,_0x9c7839)['trim']();if(_0x182f2c){if(!_0x4f61f8){const _0x4c1cb6={'type':_0x1d3a16(0x1f8),'index':_0x2de014,'content_block':{'type':'text','text':''}};yield _0x4c1cb6,_0x4f61f8=!![];}const _0x14465e={'type':_0x1d3a16(0x213),'index':_0x2de014,'delta':{'type':_0x1d3a16(0x208),'text':_0x182f2c}};yield _0x14465e,_0x240439+=estimateTokenCount(_0x182f2c);}if(_0x4f61f8){const _0x864522={'type':_0x1d3a16(0x1f9),'index':_0x2de014};yield _0x864522,_0x2de014++,_0x4f61f8=![];}const _0x19e249='\x0a\x0a[tdx\x20error]\x20Malformed\x20tool_use\x20JSON\x20detected.\x20Please\x20fix\x20the\x20JSON\x20below:\x0a\x0a'+_0x2ebb51+'\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',_0x535873={'type':'content_block_start','index':_0x2de014,'content_block':{'type':'text','text':''}};yield _0x535873;const _0xa7e5ce={'type':'content_block_delta','index':_0x2de014,'delta':{'type':'text_delta','text':_0x19e249}};yield _0xa7e5ce;const _0x1dbc6c={'type':'content_block_stop','index':_0x2de014};yield _0x1dbc6c;const _0x36b95c={'type':_0x1d3a16(0x245),'delta':{'stop_reason':_0x1d3a16(0x20d),'stop_sequence':null},'usage':{'output_tokens':_0x240439}};yield _0x36b95c;const _0x210070={'type':_0x1d3a16(0x20a)};yield _0x210070;return;}const _0x4567dc=_0x325062[_0x1d3a16(0x210)](_0x2e25da,_0x9c7839);if(_0x4567dc){if(!_0x4f61f8){const _0x2f8bd4={'type':_0x1d3a16(0x1f8),'index':_0x2de014,'content_block':{'type':_0x1d3a16(0x232),'text':''}};yield _0x2f8bd4,_0x4f61f8=!![];}const _0x1687c5={'type':'content_block_delta','index':_0x2de014,'delta':{'type':_0x1d3a16(0x208),'text':_0x4567dc}};yield _0x1687c5,_0x240439+=estimateTokenCount(_0x4567dc),_0x2e25da=_0x9c7839;}continue;}const _0x52611b=_0x325062[_0x1d3a16(0x1ee)]-_0x46dbd9;if(_0x52611b>_0x2e25da){const _0x534a08=_0x325062[_0x1d3a16(0x210)](_0x2e25da,_0x52611b);if(_0x534a08){if(!_0x4f61f8){const _0x434c38={'type':'content_block_start','index':_0x2de014,'content_block':{'type':_0x1d3a16(0x232),'text':''}};yield _0x434c38,_0x4f61f8=!![];}const _0x5914d2={'type':_0x1d3a16(0x213),'index':_0x2de014,'delta':{'type':'text_delta','text':_0x534a08}};yield _0x5914d2,_0x240439+=estimateTokenCount(_0x534a08),_0x2e25da=_0x52611b;}}}else{if(_0x1d3a16(0x228)in _0x4c4e7e){const _0x370c7e=_0x4c4e7e,_0x48f25a=determineErrorType(_0x370c7e[_0x1d3a16(0x228)],_0x49ee2f);yield{'type':_0x1d3a16(0x228),'error':{'type':_0x48f25a,'message':_0x370c7e['error']},'request_id':_0x3e2443};return;}}}if(!_0x53ad00){const _0x14f9a0=_0x325062[_0x1d3a16(0x210)](_0x2e25da);if(_0x14f9a0){if(!_0x4f61f8){const _0x1cadde={'type':_0x1d3a16(0x1f8),'index':_0x2de014,'content_block':{'type':_0x1d3a16(0x232),'text':''}};yield _0x1cadde,_0x4f61f8=!![];}const _0x4e355f={'type':'content_block_delta','index':_0x2de014,'delta':{'type':_0x1d3a16(0x208),'text':_0x14f9a0}};yield _0x4e355f,_0x240439+=estimateTokenCount(_0x14f9a0);}if(_0x4f61f8){const _0x421c66={'type':_0x1d3a16(0x1f9),'index':_0x2de014};yield _0x421c66;}const _0x32f558={'type':_0x1d3a16(0x245),'delta':{'stop_reason':'end_turn','stop_sequence':null},'usage':{'output_tokens':_0x240439}};yield _0x32f558;const _0x5349f4={'type':_0x1d3a16(0x20a)};yield _0x5349f4;}}export{generateMessageId};
|
|
1
|
+
function a40_0x5bcc(_0xcd15f2,_0x223030){const _0xff961d=a40_0xff96();return a40_0x5bcc=function(_0x5bcc3a,_0x2b2ad7){_0x5bcc3a=_0x5bcc3a-0xe2;let _0xa38c4=_0xff961d[_0x5bcc3a];return _0xa38c4;},a40_0x5bcc(_0xcd15f2,_0x223030);}(function(_0x1d0ba9,_0x9294cd){const _0xb4c86=a40_0x5bcc,_0x2c0984=_0x1d0ba9();while(!![]){try{const _0x35c9e9=parseInt(_0xb4c86(0x12e))/0x1+parseInt(_0xb4c86(0x12d))/0x2+parseInt(_0xb4c86(0x120))/0x3+-parseInt(_0xb4c86(0x10c))/0x4+parseInt(_0xb4c86(0x125))/0x5+parseInt(_0xb4c86(0x13e))/0x6*(-parseInt(_0xb4c86(0xe5))/0x7)+-parseInt(_0xb4c86(0x136))/0x8*(parseInt(_0xb4c86(0x147))/0x9);if(_0x35c9e9===_0x9294cd)break;else _0x2c0984['push'](_0x2c0984['shift']());}catch(_0x36c225){_0x2c0984['push'](_0x2c0984['shift']());}}}(a40_0xff96,0xe8dd3));import{SDKError,ErrorCode}from'../sdk/errors.js';function estimateTokenCount(_0x5fa2de){const _0x5d3f50=a40_0x5bcc;if(!_0x5fa2de||_0x5fa2de['length']===0x0)return 0x0;return Math[_0x5d3f50(0x144)](_0x5fa2de[_0x5d3f50(0x106)]/3.7);}export function determineErrorType(_0x2d1e91,_0x1af03f){const _0x16893f=a40_0x5bcc,_0x28822a=_0x2d1e91[_0x16893f(0x11e)](_0x16893f(0xf4))||_0x2d1e91[_0x16893f(0x11e)](_0x16893f(0x10f))||_0x2d1e91[_0x16893f(0x11e)](_0x16893f(0xef));if(_0x28822a)return _0x1af03f?.[_0x16893f(0xfe)](_0x16893f(0x13b)+_0x2d1e91),_0x16893f(0x113);return _0x1af03f?.[_0x16893f(0xfe)](_0x16893f(0x128)+_0x2d1e91),'api_error';}export function estimateInputTokensFromRequest(_0x1f9523){const _0x1de016=a40_0x5bcc;let _0x2300d3=0x0;if(typeof _0x1f9523[_0x1de016(0x139)]===_0x1de016(0x119))_0x2300d3+=_0x1f9523['system'][_0x1de016(0x106)];else{if(Array[_0x1de016(0x11d)](_0x1f9523[_0x1de016(0x139)]))for(const _0x4b62fc of _0x1f9523[_0x1de016(0x139)]){_0x4b62fc&&typeof _0x4b62fc['text']===_0x1de016(0x119)&&(_0x2300d3+=_0x4b62fc['text'][_0x1de016(0x106)]);}}if(Array[_0x1de016(0x11d)](_0x1f9523['tools']))for(const _0x296870 of _0x1f9523[_0x1de016(0xff)]){_0x296870&&(_0x2300d3+=_0x296870['name'][_0x1de016(0x106)],_0x2300d3+=_0x296870[_0x1de016(0x110)]?.[_0x1de016(0x106)]||0x0,_0x2300d3+=JSON['stringify'](_0x296870[_0x1de016(0x111)])[_0x1de016(0x106)]);}if(Array[_0x1de016(0x11d)](_0x1f9523[_0x1de016(0x13d)]))for(const _0x4398ea of _0x1f9523[_0x1de016(0x13d)]){if(!_0x4398ea)continue;if(typeof _0x4398ea['content']==='string')_0x2300d3+=_0x4398ea[_0x1de016(0x103)]['length'];else{if(Array[_0x1de016(0x11d)](_0x4398ea['content']))for(const _0x17aa4e of _0x4398ea[_0x1de016(0x103)]){if(!_0x17aa4e)continue;if(_0x17aa4e[_0x1de016(0x10d)]===_0x1de016(0x13f)&&_0x17aa4e[_0x1de016(0x13f)])_0x2300d3+=_0x17aa4e[_0x1de016(0x13f)][_0x1de016(0x106)];else{if(_0x17aa4e[_0x1de016(0x10d)]==='tool_use'&&_0x17aa4e[_0x1de016(0xe7)])_0x2300d3+=JSON[_0x1de016(0xe3)](_0x17aa4e['input'])['length'];else{if(_0x17aa4e[_0x1de016(0x10d)]==='tool_result'&&_0x17aa4e[_0x1de016(0x103)]){if(typeof _0x17aa4e[_0x1de016(0x103)]===_0x1de016(0x119))_0x2300d3+=_0x17aa4e['content'][_0x1de016(0x106)];else{if(Array[_0x1de016(0x11d)](_0x17aa4e[_0x1de016(0x103)]))for(const _0x298d54 of _0x17aa4e[_0x1de016(0x103)]){_0x298d54&&_0x298d54[_0x1de016(0x10d)]===_0x1de016(0x13f)&&_0x298d54[_0x1de016(0x13f)]&&(_0x2300d3+=_0x298d54['text'][_0x1de016(0x106)]);}}}}}}}}return Math[_0x1de016(0x144)](_0x2300d3/3.7);}function generateMessageId(){const _0x290a02=a40_0x5bcc;return _0x290a02(0x11b)+Math[_0x290a02(0x109)]()[_0x290a02(0xf1)](0x24)[_0x290a02(0xf0)](0x2,0xf)+Math[_0x290a02(0x109)]()[_0x290a02(0xf1)](0x24)['substring'](0x2,0xf);}export function extractTextFromAnthropicMessage(_0x11131d){const _0x45b6ea=a40_0x5bcc;if(typeof _0x11131d[_0x45b6ea(0x103)]==='string')return _0x11131d[_0x45b6ea(0x103)];if(_0x11131d['content']==null)return'';if(!Array[_0x45b6ea(0x11d)](_0x11131d['content']))throw new SDKError(ErrorCode[_0x45b6ea(0x108)],'Invalid\x20message.content\x20type:\x20expected\x20string\x20or\x20array,\x20got\x20'+typeof _0x11131d['content']);return _0x11131d['content'][_0x45b6ea(0xfa)](_0x4d2539=>_0x4d2539&&_0x4d2539['type']==='text'&&_0x4d2539[_0x45b6ea(0x13f)])[_0x45b6ea(0xf7)](_0x2e314c=>_0x2e314c[_0x45b6ea(0x13f)])[_0x45b6ea(0x112)]('\x0a');}export function calculateConversationDelta(_0x18ea0d,_0x571bdc){const _0x1c35eb=a40_0x5bcc;if(_0x571bdc[_0x1c35eb(0x106)]===0x0)return _0x18ea0d;const _0x15c7a3=_0x571bdc[_0x1c35eb(0x106)];return _0x18ea0d['slice'](_0x15c7a3);}function a40_0xff96(){const _0x1aa7f=['Invalid\x20tools\x20type:\x20expected\x20array,\x20got\x20','min','filter','tool_use_id','usage','assistant','error','tools','Malformed\x20tool_use\x20JSON\x20detected','content_block_stop','input_json_delta','content','name','endsWith','length','content_block_delta','LLM_MALFORMED_MESSAGE','random','debug','##\x20Tool:\x20','3603508KwRkXR','type','Invalid\x20messages\x20type:\x20expected\x20array,\x20got\x20','context\x20length','description','input_schema','join','request_too_large','```','haiku','warn','\x5c`\x5c`\x5c`','sonnet','string','indexOf','msg_','Multiple\x20tool\x20calls\x20detected,\x20using\x20only\x20the\x20last\x20one:\x20','isArray','includes','\x0a#\x20How\x20to\x20Use\x20Tools\x0a\x0aTo\x20use\x20a\x20tool,\x20output\x20the\x20tool\x20call\x20in\x20a\x20markdown\x20code\x20block:\x0a\x0a```tool_use\x0a{\x22tool_use\x22:{\x22id\x22:\x22toolu_<random>\x22,\x22name\x22:\x22<tool_name>\x22,\x22input\x22:{<parameters>}}}\x0a```\x0a\x0a**IMPORTANT:**\x0a-\x20**Output\x20only\x20ONE\x20tool_use\x20at\x20a\x20time**\x20-\x20Never\x20output\x20multiple\x20tool\x20calls\x20in\x20a\x20single\x20response\x0a-\x20Use\x20the\x20precise\x20parameter\x20names\x20and\x20types\x20as\x20defined\x20in\x20the\x20JSON\x20schema.\x0a-\x20Wrap\x20the\x20JSON\x20in\x20a\x20markdown\x20code\x20block\x20with\x20```tool_use\x0a-\x20The\x20JSON\x20must\x20be\x20valid\x20and\x20properly\x20formatted.\x20Ensure\x20all\x20strings\x20are\x20double\x20quoted.\x0a-\x20Generate\x20a\x20unique\x20random\x20ID\x20starting\x20with\x20\x22toolu_\x22\x0a-\x20After\x20outputting\x20the\x20tool\x20use,\x20stop\x20and\x20wait\x20for\x20the\x20tool\x20result\x0a-\x20Tool\x20results\x20will\x20be\x20provided\x20in\x20markdown\x20code\x20blocks\x20with\x20```tool_result\x20tool_use_id=<id>\x0a-\x20Once\x20you\x20receive\x20a\x20tool\x20result,\x20you\x20may\x20call\x20another\x20tool\x20if\x20needed,\x20or\x20continue\x20your\x20response\x20naturally\x0a\x0a**Example\x201\x20-\x20Simple\x20tool:**\x0aUser:\x20\x22What\x27s\x2025\x20*\x204?\x22\x0aAssistant:\x20I\x27ll\x20calculate\x20that\x20for\x20you.\x0a\x0a```tool_use\x0a{\x22tool_use\x22:{\x22id\x22:\x22toolu_abc123\x22,\x22name\x22:\x22calculator\x22,\x22input\x22:{\x22expression\x22:\x2225\x20*\x204\x22}}}\x0a```\x0a\x0a**Example\x202\x20-\x20Tool\x20with\x20multiline\x20strings\x20(proper\x20escaping):**\x0aUser:\x20\x22Edit\x20the\x20file\x20to\x20add\x20a\x20newline\x22\x0aAssistant:\x20I\x27ll\x20edit\x20the\x20file\x20with\x20proper\x20JSON\x20escaping.\x0a\x0a```tool_use\x0a{\x22tool_use\x22:{\x22id\x22:\x22toolu_def456\x22,\x22name\x22:\x22Edit\x22,\x22input\x22:{\x22file_path\x22:\x22test.ts\x22,\x22old_string\x22:\x22const\x20x\x20=\x201;\x22,\x22new_string\x22:\x22const\x20x\x20=\x201;\x5cnconst\x20y\x20=\x202;\x22}}}\x0a```\x0a\x0a#\x20Available\x20Tools\x0a\x0a','1872324FsTlxP','message_start','pop','```tool_use','opus','8611335akkime','model_context_window_exceeded','exec','[API\x20ERROR]\x20','user','\x0adata:\x20','Malformed\x20content:','\x20error=true','100596cSXmjI','1574303lCLfhg','\x0a```','event:\x20','message_delta','Tool\x20call\x20detected:\x20','end_turn','message','endIndex','32LGDxKi','push','trim','system','\x0a\x0a[tdx\x20error]\x20Malformed\x20tool_use\x20JSON\x20detected.\x20Please\x20fix\x20the\x20JSON\x20below:\x0a\x0a','[CONTEXT\x20LENGTH\x20ERROR]\x20','startIndex','messages','482280awsSlw','text','No\x20description','parse','output_tokens','message_stop','ceil','replace','Tool\x20calls\x20not\x20yet\x20supported\x20in\x20proxy:','1687113uTIWhc','\x0a\x0aPlease\x20continue\x20your\x20response\x20based\x20on\x20the\x20tool\x20results\x20above.\x0a\x0a','toLowerCase','stringify','is_error','119sBMZfJ','tool_call','input','role','index','```tool_result\x20tool_use_id=','content_block_start','arguments','tool_use','text_delta','maximum\x20context','substring','toString','{\x22tool_use\x22:','\x0a[After]:\x0a','Input\x20is\x20too\x20long','\x0a\x0aCommon\x20issues:\x0a-\x20All\x20strings\x20must\x20use\x20double\x20quotes\x20(not\x20single\x20quotes)\x0a-\x20All\x20braces\x20and\x20brackets\x20must\x20be\x20balanced\x0a-\x20No\x20trailing\x20commas\x0a-\x20Newlines\x20in\x20strings\x20must\x20be\x20escaped\x20as\x20\x5cn\x0a-\x20Backslashes\x20must\x20be\x20escaped\x20as\x20\x5c\x5c\x0a','[MALFORMED\x20JSON]\x20Tool\x20use\x20JSON\x20could\x20not\x20be\x20parsed\x20or\x20repaired:\x0a','map'];a40_0xff96=function(){return _0x1aa7f;};return a40_0xff96();}export function transformAnthropicRequestToTD(_0x44d632,_0x5b7fac){const _0x533e12=a40_0x5bcc,_0xc0e8ec=calculateConversationDelta(_0x44d632[_0x533e12(0x13d)],_0x5b7fac),_0x43a759=_0xc0e8ec['filter'](_0x27655c=>_0x27655c[_0x533e12(0xe8)]===_0x533e12(0x129))['pop']();if(!_0x43a759)throw new Error('No\x20user\x20message\x20found\x20in\x20request\x20delta');const _0x3a4158=extractTextFromAnthropicMessage(_0x43a759);return{'userMessage':_0x3a4158,'deltaMessages':_0xc0e8ec};}export async function*transformTDStreamToAnthropic(_0x305fdb,_0x3174e9,_0x4f33d4,_0xc0b5a2='',_0x468bed=0x0){const _0x44745e=a40_0x5bcc,_0x53f09a=_0x468bed>0x0?_0x468bed:estimateTokenCount(_0xc0b5a2);let _0x28384a=0x0,_0x1981a0=0x0,_0x3f6131=![];const _0x15794b={'type':_0x44745e(0x121),'message':{'id':_0x3174e9,'type':_0x44745e(0x134),'role':_0x44745e(0xfd),'content':[],'model':_0x4f33d4,'stop_reason':null,'stop_sequence':null,'usage':{'input_tokens':_0x53f09a,'output_tokens':0x0}}};yield _0x15794b;for await(const _0xe393f of _0x305fdb){if(_0x44745e(0x103)in _0xe393f){const _0x3d3fc4=_0xe393f;if(!_0x3f6131){const _0x4f8e4e={'type':_0x44745e(0xeb),'index':_0x1981a0,'content_block':{'type':_0x44745e(0x13f),'text':''}};yield _0x4f8e4e,_0x3f6131=!![];}const _0x43022c={'type':'content_block_delta','index':_0x1981a0,'delta':{'type':'text_delta','text':_0x3d3fc4[_0x44745e(0x103)]}};yield _0x43022c,_0x28384a+=estimateTokenCount(_0x3d3fc4[_0x44745e(0x103)]);}else{if(_0x44745e(0xe6)in _0xe393f){const _0x41a0db=_0xe393f;console[_0x44745e(0x116)](_0x44745e(0x146),_0x41a0db);}else{if(_0x44745e(0xfe)in _0xe393f){const _0x25acea=_0xe393f,_0xebe2b9=determineErrorType(_0x25acea[_0x44745e(0xfe)]),_0x5a2b55=_0xebe2b9===_0x44745e(0x113)?_0x44745e(0x126):_0x44745e(0x133),_0x4bce1a={'type':'message_delta','delta':{'stop_reason':_0x5a2b55,'stop_sequence':null},'usage':{'input_tokens':_0x53f09a,'output_tokens':_0x28384a}};yield _0x4bce1a,yield{'type':'error','error':{'type':_0xebe2b9,'message':_0x25acea[_0x44745e(0xfe)]},'request_id':_0x3174e9};const _0x21cafb={'type':_0x44745e(0x143)};yield _0x21cafb;return;}}}}if(_0x3f6131){const _0x56770a={'type':'content_block_stop','index':_0x1981a0};yield _0x56770a;}const _0x4ef1d8={'type':_0x44745e(0x131),'delta':{'stop_reason':_0x44745e(0x133),'stop_sequence':null},'usage':{'input_tokens':_0x53f09a,'output_tokens':_0x28384a}};yield _0x4ef1d8;const _0x3d3992={'type':_0x44745e(0x143)};yield _0x3d3992;}export function formatAnthropicSSE(_0x5abaca){const _0x4e87c0=a40_0x5bcc;return _0x4e87c0(0x130)+_0x5abaca[_0x4e87c0(0x10d)]+_0x4e87c0(0x12a)+JSON[_0x4e87c0(0xe3)](_0x5abaca)+'\x0a\x0a';}export function mapAnthropicModelToTD(_0x102839){const _0x20e5a9=a40_0x5bcc,_0x30f824={'sonnet':_0x20e5a9(0x118),'claude-sonnet':'sonnet','claude-3-5-sonnet':_0x20e5a9(0x118),'claude-3-sonnet':_0x20e5a9(0x118),'haiku':_0x20e5a9(0x115),'claude-haiku':_0x20e5a9(0x115),'claude-3-5-haiku':_0x20e5a9(0x115),'claude-3-haiku':_0x20e5a9(0x115),'opus':'opus','claude-opus':_0x20e5a9(0x124),'claude-3-opus':_0x20e5a9(0x124)},_0x36a28f=_0x102839[_0x20e5a9(0xe2)]();return _0x30f824[_0x36a28f]||_0x20e5a9(0x118);}export function generateToolPrompt(_0x3e0c7e){const _0x2ff402=a40_0x5bcc;if(_0x3e0c7e==null)return'';if(!Array[_0x2ff402(0x11d)](_0x3e0c7e))throw new SDKError(ErrorCode['LLM_MALFORMED_MESSAGE'],_0x2ff402(0xf8)+typeof _0x3e0c7e);if(_0x3e0c7e[_0x2ff402(0x106)]===0x0)return'';const _0x2b583f=_0x3e0c7e['filter'](_0x2a286d=>_0x2a286d!=null)[_0x2ff402(0xf7)](_0x1453ed=>{const _0xb3ed52=_0x2ff402,_0x357ba0=JSON[_0xb3ed52(0xe3)](_0x1453ed['input_schema']);return _0xb3ed52(0x10b)+_0x1453ed[_0xb3ed52(0x104)]+'\x0a\x0a**Description:**\x20'+(_0x1453ed[_0xb3ed52(0x110)]||_0xb3ed52(0x140))+'\x0a\x0a**Input\x20Schema:**\x0a```json\x0a'+_0x357ba0+_0xb3ed52(0x12f);})[_0x2ff402(0x112)]('\x0a\x0a');return _0x2ff402(0x11f)+_0x2b583f+'\x0a---\x0a';}function escapeMarkdownCodeBlock(_0x5bd951){const _0x5a0aad=a40_0x5bcc;return _0x5bd951[_0x5a0aad(0x145)](/```/g,_0x5a0aad(0x117));}export function extractToolResults(_0x54c371){const _0x42b971=a40_0x5bcc;if(_0x54c371==null)return'';if(!Array[_0x42b971(0x11d)](_0x54c371))throw new SDKError(ErrorCode['LLM_MALFORMED_MESSAGE'],_0x42b971(0x10e)+typeof _0x54c371);const _0x41ceb0=[];for(const _0x2d7af0 of _0x54c371){if(!_0x2d7af0)continue;if(_0x2d7af0[_0x42b971(0xe8)]===_0x42b971(0x129)&&typeof _0x2d7af0[_0x42b971(0x103)]!==_0x42b971(0x119)){if(!Array[_0x42b971(0x11d)](_0x2d7af0['content']))throw new SDKError(ErrorCode[_0x42b971(0x108)],'Invalid\x20message.content\x20type\x20for\x20user\x20role:\x20expected\x20array,\x20got\x20'+typeof _0x2d7af0[_0x42b971(0x103)]);for(const _0x311d3f of _0x2d7af0[_0x42b971(0x103)]){if(!_0x311d3f)continue;if(_0x311d3f[_0x42b971(0x10d)]==='tool_result'&&_0x311d3f[_0x42b971(0xfb)]){let _0x27a067='';if(typeof _0x311d3f[_0x42b971(0x103)]===_0x42b971(0x119))_0x27a067=_0x311d3f[_0x42b971(0x103)];else _0x311d3f[_0x42b971(0x103)]!=null&&Array[_0x42b971(0x11d)](_0x311d3f[_0x42b971(0x103)])&&(_0x27a067=_0x311d3f[_0x42b971(0x103)][_0x42b971(0xfa)](_0x13a970=>_0x13a970&&_0x13a970[_0x42b971(0x10d)]===_0x42b971(0x13f)&&_0x13a970[_0x42b971(0x13f)])[_0x42b971(0xf7)](_0x21b89f=>_0x21b89f[_0x42b971(0x13f)])[_0x42b971(0x112)]('\x0a'));const _0x37eba2=escapeMarkdownCodeBlock(_0x27a067),_0x4b6142=_0x311d3f[_0x42b971(0xe4)]?_0x42b971(0x12c):'';_0x41ceb0['push'](_0x42b971(0xea)+_0x311d3f[_0x42b971(0xfb)]+_0x4b6142+'\x0a'+_0x37eba2+_0x42b971(0x12f));}}}}if(_0x41ceb0[_0x42b971(0x106)]===0x0)return'';return _0x41ceb0[_0x42b971(0x112)]('\x0a\x0a')+_0x42b971(0x148);}function findJsonEndIndex(_0x2c71ae,_0x32efa0){let _0x4bdac0=0x0,_0x37354a=![],_0x14ff37=![];for(let _0x14c253=_0x32efa0;_0x14c253<_0x2c71ae['length'];_0x14c253++){const _0x2e5596=_0x2c71ae[_0x14c253];if(_0x14ff37){_0x14ff37=![];continue;}if(_0x2e5596==='\x5c'){_0x14ff37=!![];continue;}if(_0x2e5596==='\x22'){_0x37354a=!_0x37354a;continue;}if(!_0x37354a){if(_0x2e5596==='{')_0x4bdac0++;else{if(_0x2e5596==='}'){_0x4bdac0--;if(_0x4bdac0===0x0)return _0x14c253+0x1;}}}}return-0x1;}function generateToolCallId(){const _0x709728=a40_0x5bcc;return'toolu_'+Math['random']()[_0x709728(0xf1)](0x24)[_0x709728(0xf0)](0x2,0xf);}function repairIncompleteJson(_0x56a05f,_0x2d997f){const _0xe3e2f8=a40_0x5bcc;try{return JSON[_0xe3e2f8(0x141)](_0x56a05f),_0x56a05f;}catch{const _0x102306=[];let _0x3008d9=![],_0x1a0b1a=![];for(const _0x83099a of _0x56a05f){if(_0x1a0b1a){_0x1a0b1a=![];continue;}if(_0x83099a==='\x5c'){_0x1a0b1a=!![];continue;}if(_0x83099a==='\x22'){_0x3008d9=!_0x3008d9;continue;}if(!_0x3008d9){if(_0x83099a==='{')_0x102306[_0xe3e2f8(0x137)]('{');else{if(_0x83099a==='[')_0x102306[_0xe3e2f8(0x137)]('[');else{if(_0x83099a==='}'&&_0x102306[_0x102306[_0xe3e2f8(0x106)]-0x1]==='{')_0x102306['pop']();else _0x83099a===']'&&_0x102306[_0x102306[_0xe3e2f8(0x106)]-0x1]==='['&&_0x102306[_0xe3e2f8(0x122)]();}}}}let _0xb6b677=_0x56a05f;_0x3008d9&&(_0xb6b677+='\x22');while(_0x102306['length']>0x0){const _0x3907e5=_0x102306[_0xe3e2f8(0x122)]();_0xb6b677+=_0x3907e5==='{'?'}':']';}try{return JSON[_0xe3e2f8(0x141)](_0xb6b677),_0x2d997f&&_0xb6b677!==_0x56a05f&&_0x2d997f[_0xe3e2f8(0x116)]('[JSON\x20REPAIR]\x20Successfully\x20repaired\x20malformed\x20JSON\x0a[Before]:\x0a'+_0x56a05f+_0xe3e2f8(0xf3)+_0xb6b677),_0xb6b677;}catch{return null;}}}export function parseToolCallFromText(_0x3466bc,_0x26e03){const _0x1d34bc=a40_0x5bcc,_0xe2090b=/```tool_use[\s]*\n([\s\S]*)\n?```/,_0x475d9b=_0xe2090b[_0x1d34bc(0x127)](_0x3466bc);if(_0x475d9b){if(!_0x475d9b[0x0][_0x1d34bc(0x105)](_0x1d34bc(0x114))){}else{const _0x2a3db4=_0x475d9b[0x1][_0x1d34bc(0x138)](),_0x11c67a=_0x475d9b[_0x1d34bc(0xe9)],_0x40244a=_0x11c67a+_0x475d9b[0x0][_0x1d34bc(0x106)];try{const _0x486c9c=JSON[_0x1d34bc(0x141)](_0x2a3db4);if(_0x486c9c[_0x1d34bc(0xed)]&&_0x486c9c[_0x1d34bc(0xed)][_0x1d34bc(0x104)])return{'id':_0x486c9c[_0x1d34bc(0xed)]['id']||generateToolCallId(),'name':_0x486c9c['tool_use'][_0x1d34bc(0x104)],'input':_0x486c9c['tool_use']['input']||{},'startIndex':_0x11c67a,'endIndex':_0x40244a};if(_0x486c9c[_0x1d34bc(0x104)]&&typeof _0x486c9c[_0x1d34bc(0x104)]===_0x1d34bc(0x119)&&_0x486c9c[_0x1d34bc(0x104)]['trim']()[_0x1d34bc(0x106)]>0x0)return{'id':_0x486c9c['id']||generateToolCallId(),'name':_0x486c9c['name'],'input':_0x486c9c['input']||_0x486c9c[_0x1d34bc(0xec)]||{},'startIndex':_0x11c67a,'endIndex':_0x40244a};}catch{const _0x26b371=repairIncompleteJson(_0x2a3db4,_0x26e03);if(_0x26b371)try{const _0x29b3b8=JSON['parse'](_0x26b371);if(_0x29b3b8[_0x1d34bc(0xed)]&&_0x29b3b8[_0x1d34bc(0xed)][_0x1d34bc(0x104)])return{'id':_0x29b3b8[_0x1d34bc(0xed)]['id']||generateToolCallId(),'name':_0x29b3b8[_0x1d34bc(0xed)][_0x1d34bc(0x104)],'input':_0x29b3b8['tool_use']['input']||{},'startIndex':_0x11c67a,'endIndex':_0x40244a};if(_0x29b3b8[_0x1d34bc(0x104)]&&typeof _0x29b3b8['name']==='string'&&_0x29b3b8[_0x1d34bc(0x104)]['trim']()[_0x1d34bc(0x106)]>0x0)return{'id':_0x29b3b8['id']||generateToolCallId(),'name':_0x29b3b8['name'],'input':_0x29b3b8[_0x1d34bc(0xe7)]||_0x29b3b8[_0x1d34bc(0xec)]||{},'startIndex':_0x11c67a,'endIndex':_0x40244a};}catch{}}}}const _0x19b575=/\{"tool_use":/g,_0x39603c=_0x19b575[_0x1d34bc(0x127)](_0x3466bc);if(!_0x39603c)return null;const _0x368714=_0x39603c[_0x1d34bc(0xe9)];let _0x24e071=findJsonEndIndex(_0x3466bc,_0x368714);if(_0x24e071===-0x1)return null;const _0x56b9d1=_0x3466bc['substring'](_0x368714,_0x24e071);try{const _0x1b0ba4=JSON['parse'](_0x56b9d1);if(_0x1b0ba4[_0x1d34bc(0xed)]&&_0x1b0ba4[_0x1d34bc(0xed)]['id']&&_0x1b0ba4[_0x1d34bc(0xed)]['name'])return{'id':_0x1b0ba4['tool_use']['id'],'name':_0x1b0ba4[_0x1d34bc(0xed)][_0x1d34bc(0x104)],'input':_0x1b0ba4[_0x1d34bc(0xed)][_0x1d34bc(0xe7)]||{},'startIndex':_0x368714,'endIndex':_0x24e071};}catch{const _0x5c0334=repairIncompleteJson(_0x56b9d1,_0x26e03);if(_0x5c0334)try{const _0xe5aec1=JSON['parse'](_0x5c0334);if(_0xe5aec1['tool_use']&&_0xe5aec1[_0x1d34bc(0xed)]['id']&&_0xe5aec1[_0x1d34bc(0xed)][_0x1d34bc(0x104)])return{'id':_0xe5aec1[_0x1d34bc(0xed)]['id'],'name':_0xe5aec1[_0x1d34bc(0xed)][_0x1d34bc(0x104)],'input':_0xe5aec1[_0x1d34bc(0xed)][_0x1d34bc(0xe7)]||{},'startIndex':_0x368714,'endIndex':_0x24e071};}catch{return null;}return null;}return null;}export function*generateToolCallEvents(_0x1fcc9a,_0x386393,_0x2ae162){const _0x55ff75=a40_0x5bcc,_0x546192={'type':'content_block_start','index':_0x386393,'content_block':{'type':'tool_use','id':_0x1fcc9a['id'],'name':_0x1fcc9a[_0x55ff75(0x104)],'input':{}}};yield _0x546192;const _0x39e4a5=JSON['stringify'](_0x1fcc9a[_0x55ff75(0xe7)]),_0x3a8132={'type':_0x55ff75(0x107),'index':_0x386393,'delta':{'type':_0x55ff75(0x102),'partial_json':_0x39e4a5}};yield _0x3a8132;const _0x39909e={'type':_0x55ff75(0x101),'index':_0x386393};yield _0x39909e;const _0x454115={'type':'message_delta','delta':{'stop_reason':'tool_use','stop_sequence':null},'usage':{'input_tokens':_0x2ae162,'output_tokens':0x0}};yield _0x454115;const _0x5d2991={'type':_0x55ff75(0x143)};yield _0x5d2991;}export async function*transformTDStreamWithToolDetection(_0x13a0e1,_0x10d264,_0x4519a6,_0x5c932a,_0x240a76='',_0x317f02=0x0){const _0x143652=a40_0x5bcc,_0x574ab0=_0x317f02>0x0?_0x317f02:estimateTokenCount(_0x240a76);let _0x2b39ab=0x0,_0xf12774=0x0,_0x353868=![],_0x4bb60d='',_0x2fafb2=0x0,_0x2bd6f4=![];const _0x23c940=0xc8,_0x1f9a06={'type':_0x143652(0x121),'message':{'id':_0x10d264,'type':_0x143652(0x134),'role':_0x143652(0xfd),'content':[],'model':_0x4519a6,'stop_reason':null,'stop_sequence':null,'usage':{'input_tokens':_0x574ab0,'output_tokens':0x0}}};yield _0x1f9a06;for await(const _0x5735da of _0x13a0e1){if(_0x143652(0x103)in _0x5735da){const _0x2834e4=_0x5735da;_0x4bb60d+=_0x2834e4[_0x143652(0x103)];const _0x19f291=_0x4bb60d[_0x143652(0x11a)]('```tool_use'),_0x4431d6=_0x4bb60d[_0x143652(0x11a)](_0x143652(0xf2)),_0x10d015=_0x19f291!==-0x1?_0x4431d6!==-0x1?Math[_0x143652(0xf9)](_0x19f291,_0x4431d6):_0x19f291:_0x4431d6;if(_0x10d015!==-0x1){const _0x38f57b=[];let _0x5b52d8=0x0;while(!![]){const _0x16bf5b=_0x4bb60d['substring'](_0x5b52d8),_0x4c26e4=parseToolCallFromText(_0x16bf5b,_0x5c932a);if(!_0x4c26e4)break;_0x38f57b[_0x143652(0x137)]({'id':_0x4c26e4['id'],'name':_0x4c26e4['name'],'input':_0x4c26e4[_0x143652(0xe7)],'startIndex':_0x5b52d8+_0x4c26e4[_0x143652(0x13c)],'endIndex':_0x5b52d8+_0x4c26e4[_0x143652(0x135)]}),_0x5b52d8+=_0x4c26e4[_0x143652(0x135)];}if(_0x38f57b[_0x143652(0x106)]>0x0){const _0xa7325c=_0x38f57b[_0x38f57b[_0x143652(0x106)]-0x1];_0x2bd6f4=!![];_0x38f57b[_0x143652(0x106)]>0x1?_0x5c932a?.[_0x143652(0x10a)](_0x143652(0x11c)+_0xa7325c[_0x143652(0x104)]):_0x5c932a?.[_0x143652(0x10a)](_0x143652(0x132)+_0xa7325c[_0x143652(0x104)]);const _0x3cd184=_0x4bb60d['substring'](_0x2fafb2,_0xa7325c['startIndex'])[_0x143652(0x138)]();if(_0x3cd184){if(!_0x353868){const _0x3ec721={'type':_0x143652(0xeb),'index':_0xf12774,'content_block':{'type':_0x143652(0x13f),'text':''}};yield _0x3ec721,_0x353868=!![];}const _0x43c542={'type':_0x143652(0x107),'index':_0xf12774,'delta':{'type':'text_delta','text':_0x3cd184}};yield _0x43c542,_0x2b39ab+=estimateTokenCount(_0x3cd184);}if(_0x353868){const _0x1e1dc9={'type':'content_block_stop','index':_0xf12774};yield _0x1e1dc9,_0xf12774++,_0x353868=![];}for(const _0x1f5bce of generateToolCallEvents(_0xa7325c,_0xf12774,_0x574ab0)){_0x1f5bce[_0x143652(0x10d)]===_0x143652(0x131)&&(_0x1f5bce[_0x143652(0xfc)][_0x143652(0x142)]=_0x2b39ab),yield _0x1f5bce;}return;}const _0x2d6ecd=_0x4bb60d[_0x143652(0x11e)](_0x143652(0x123))&&_0x4bb60d[_0x143652(0x11a)]('```',_0x4bb60d[_0x143652(0x11a)](_0x143652(0x123))+0xb)!==-0x1,_0x195883=_0x4bb60d[_0x143652(0x11e)](_0x143652(0xf2))&&findJsonEndIndex(_0x4bb60d,_0x4bb60d[_0x143652(0x11a)](_0x143652(0xf2)))!==-0x1;if(_0x2d6ecd||_0x195883){_0x2bd6f4=!![];let _0x30f801='';if(_0x2d6ecd){const _0xf172e9=_0x4bb60d['indexOf']('```tool_use'),_0x459e99=_0x4bb60d[_0x143652(0x11a)](_0x143652(0x114),_0xf172e9+0xb);_0x459e99!==-0x1?_0x30f801=_0x4bb60d['substring'](_0xf172e9,_0x459e99+0x3):_0x30f801=_0x4bb60d[_0x143652(0xf0)](_0xf172e9);}else{if(_0x195883){const _0xef3789=_0x4bb60d[_0x143652(0x11a)](_0x143652(0xf2)),_0x1add8b=findJsonEndIndex(_0x4bb60d,_0xef3789);_0x1add8b!==-0x1?_0x30f801=_0x4bb60d['substring'](_0xef3789,_0x1add8b):_0x30f801=_0x4bb60d['substring'](_0xef3789);}}_0x5c932a&&_0x5c932a['error'](_0x143652(0xf6)+_0x30f801);_0x5c932a?.[_0x143652(0x10a)](_0x143652(0x100)),_0x5c932a?.[_0x143652(0x10a)](_0x143652(0x12b),_0x30f801);const _0x508ae3=_0x4bb60d[_0x143652(0xf0)](_0x2fafb2,_0x10d015)[_0x143652(0x138)]();if(_0x508ae3){if(!_0x353868){const _0x48cf5e={'type':_0x143652(0xeb),'index':_0xf12774,'content_block':{'type':_0x143652(0x13f),'text':''}};yield _0x48cf5e,_0x353868=!![];}const _0x5d2e1b={'type':_0x143652(0x107),'index':_0xf12774,'delta':{'type':_0x143652(0xee),'text':_0x508ae3}};yield _0x5d2e1b,_0x2b39ab+=estimateTokenCount(_0x508ae3);}if(_0x353868){const _0x440b30={'type':'content_block_stop','index':_0xf12774};yield _0x440b30,_0xf12774++,_0x353868=![];}const _0x25eb36=_0x143652(0x13a)+_0x30f801+_0x143652(0xf5),_0x2d85cd={'type':_0x143652(0xeb),'index':_0xf12774,'content_block':{'type':'text','text':''}};yield _0x2d85cd;const _0x551d7c={'type':_0x143652(0x107),'index':_0xf12774,'delta':{'type':'text_delta','text':_0x25eb36}};yield _0x551d7c;const _0x3dd335={'type':_0x143652(0x101),'index':_0xf12774};yield _0x3dd335;const _0x1ef55e={'type':'message_delta','delta':{'stop_reason':'end_turn','stop_sequence':null},'usage':{'input_tokens':_0x574ab0,'output_tokens':_0x2b39ab}};yield _0x1ef55e;const _0x3f9a57={'type':'message_stop'};yield _0x3f9a57;return;}const _0x48e21c=_0x4bb60d[_0x143652(0xf0)](_0x2fafb2,_0x10d015);if(_0x48e21c){if(!_0x353868){const _0x57b8ea={'type':'content_block_start','index':_0xf12774,'content_block':{'type':'text','text':''}};yield _0x57b8ea,_0x353868=!![];}const _0x39f329={'type':_0x143652(0x107),'index':_0xf12774,'delta':{'type':_0x143652(0xee),'text':_0x48e21c}};yield _0x39f329,_0x2b39ab+=estimateTokenCount(_0x48e21c),_0x2fafb2=_0x10d015;}continue;}const _0x202fbd=_0x4bb60d[_0x143652(0x106)]-_0x23c940;if(_0x202fbd>_0x2fafb2){const _0x2ce44e=_0x4bb60d['substring'](_0x2fafb2,_0x202fbd);if(_0x2ce44e){if(!_0x353868){const _0x1160c3={'type':_0x143652(0xeb),'index':_0xf12774,'content_block':{'type':_0x143652(0x13f),'text':''}};yield _0x1160c3,_0x353868=!![];}const _0x2d0046={'type':'content_block_delta','index':_0xf12774,'delta':{'type':_0x143652(0xee),'text':_0x2ce44e}};yield _0x2d0046,_0x2b39ab+=estimateTokenCount(_0x2ce44e),_0x2fafb2=_0x202fbd;}}}else{if(_0x143652(0xfe)in _0x5735da){const _0x52acfe=_0x5735da,_0x39a4ad=determineErrorType(_0x52acfe['error'],_0x5c932a),_0xd94c48=_0x39a4ad===_0x143652(0x113)?_0x143652(0x126):_0x143652(0x133),_0x593a2f={'type':_0x143652(0x131),'delta':{'stop_reason':_0xd94c48,'stop_sequence':null},'usage':{'input_tokens':_0x574ab0,'output_tokens':_0x2b39ab}};yield _0x593a2f,yield{'type':_0x143652(0xfe),'error':{'type':_0x39a4ad,'message':_0x52acfe[_0x143652(0xfe)]},'request_id':_0x10d264};const _0x8b6016={'type':'message_stop'};yield _0x8b6016;return;}}}if(!_0x2bd6f4){const _0x3550f4=_0x4bb60d[_0x143652(0xf0)](_0x2fafb2);if(_0x3550f4){if(!_0x353868){const _0x1303fc={'type':'content_block_start','index':_0xf12774,'content_block':{'type':'text','text':''}};yield _0x1303fc,_0x353868=!![];}const _0x247adc={'type':_0x143652(0x107),'index':_0xf12774,'delta':{'type':'text_delta','text':_0x3550f4}};yield _0x247adc,_0x2b39ab+=estimateTokenCount(_0x3550f4);}if(_0x353868){const _0x46df34={'type':_0x143652(0x101),'index':_0xf12774};yield _0x46df34;}const _0x2a96c3={'type':'message_delta','delta':{'stop_reason':'end_turn','stop_sequence':null},'usage':{'input_tokens':_0x574ab0,'output_tokens':_0x2b39ab}};yield _0x2a96c3;const _0x516546={'type':_0x143652(0x143)};yield _0x516546;}}export{generateMessageId};
|