@myagentroam/node 0.9.62 → 0.9.65
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/LICENSE +202 -0
- package/NOTICE +4 -0
- package/dist/capabilities.js +110 -2
- package/dist/claude-agent-sdk.js +330 -2
- package/dist/claude-channel.js +44 -2
- package/dist/codex-app-server.js +510 -2
- package/dist/config.js +106 -2
- package/dist/connector/node-connector-options.js +1 -2
- package/dist/connector/node-operation-router.js +22 -2
- package/dist/connector.js +1736 -2
- package/dist/control-outbound-scheduler.js +153 -2
- package/dist/database.js +639 -2
- package/dist/fake-runner.js +129 -2
- package/dist/git-askpass.js +12 -0
- package/dist/git-execution-helper.js +266 -0
- package/dist/health.js +3 -2
- package/dist/main.js +57 -2
- package/dist/mcp-installation-model.js +1 -2
- package/dist/migrations/v004.js +55 -3
- package/dist/migrations/v005.js +13 -3
- package/dist/migrations/v006.js +90 -3
- package/dist/migrations/v007.js +22 -3
- package/dist/migrations/v008.js +18 -3
- package/dist/migrations/v009.js +70 -4
- package/dist/migrations/v010.js +43 -3
- package/dist/migrations/v011.js +20 -3
- package/dist/migrations/v012.js +8 -0
- package/dist/native-jsonl-reader.js +186 -2
- package/dist/native-session-history.js +1143 -2
- package/dist/opencode-runtime.js +80 -2
- package/dist/opencode-server.js +259 -2
- package/dist/operational.js +122 -2
- package/dist/process-tree.js +18 -2
- package/dist/ripgrep-binary.js +31 -2
- package/dist/rotating-log.js +67 -2
- package/dist/runner/abstract-runner.js +260 -2
- package/dist/runner/claude/managed-run-controller.js +355 -2
- package/dist/runner/claude/tool-normalizer.js +120 -2
- package/dist/runner/claude-code-runner.js +303 -2
- package/dist/runner/codex/composer-image-markers.js +8 -2
- package/dist/runner/codex/conversation-parser.js +913 -2
- package/dist/runner/codex/managed-run-controller.js +494 -2
- package/dist/runner/codex/tool-normalizer.js +214 -2
- package/dist/runner/codex-runner.js +585 -2
- package/dist/runner/fake-test-runner.js +47 -2
- package/dist/runner/mar-agent/conversation-normalizer.js +644 -2
- package/dist/runner/mar-agent/executor-stdio-client-transport.js +139 -2
- package/dist/runner/mar-agent/generated-images.js +41 -2
- package/dist/runner/mar-agent/history-projection.js +106 -2
- package/dist/runner/mar-agent/hosted-conversation-runtime.js +446 -2
- package/dist/runner/mar-agent/managed-run-controller.js +785 -2
- package/dist/runner/mar-agent/mcp-client-pool.js +233 -2
- package/dist/runner/mar-agent/runtime-model-factory.js +326 -2
- package/dist/runner/mar-agent-runner.js +458 -2
- package/dist/runner/opencode/conversation-parser.js +221 -2
- package/dist/runner/opencode/managed-run-controller.js +588 -2
- package/dist/runner/opencode/tool-normalizer.js +80 -2
- package/dist/runner/opencode-runner.js +426 -2
- package/dist/runner/runner-registry.js +87 -2
- package/dist/runner-command-engine.js +71 -2
- package/dist/runner-profiles.js +323 -2
- package/dist/runner-usage.js +190 -2
- package/dist/runtime-command-detector.js +73 -2
- package/dist/runtime-model.js +1 -2
- package/dist/runtime-state.js +1509 -2
- package/dist/service/attachment-domain-state.js +7 -2
- package/dist/service/bubblewrap-sandbox-executor.js +543 -2
- package/dist/service/continuous-run-coordinator.js +425 -2
- package/dist/service/conversation-history-service.js +552 -2
- package/dist/service/conversation-hosting-capability-service.js +61 -2
- package/dist/service/conversation-hosting-enablement-service.js +91 -2
- package/dist/service/conversation-hosting-maintenance-service.js +174 -2
- package/dist/service/conversation-segment-service.js +162 -2
- package/dist/service/conversation-template-node-service.js +992 -2
- package/dist/service/external-session-resume-service.js +152 -2
- package/dist/service/fake-managed-run-service.js +60 -2
- package/dist/service/git-execution-service.js +418 -0
- package/dist/service/git-operation-service.js +57 -0
- package/dist/service/hosted-conversation-node-service.js +1982 -2
- package/dist/service/hosted-conversation-store.js +1405 -2
- package/dist/service/managed-runner-session-service.js +35 -2
- package/dist/service/mar-agent-model-transport-test-service.js +88 -2
- package/dist/service/mcp-installation-verifier.js +87 -2
- package/dist/service/mcp-node-operation-service.js +90 -2
- package/dist/service/mission-mcp-server.js +124 -2
- package/dist/service/mission-mcp-stdio.js +40 -2
- package/dist/service/mission-runtime.js +142 -2
- package/dist/service/native-session-projection-service.js +274 -2
- package/dist/service/native-session-watch-service.js +683 -2
- package/dist/service/node-connection-lifecycle-service.js +88 -2
- package/dist/service/node-control-channel.js +85 -2
- package/dist/service/node-control-message-service.js +109 -2
- package/dist/service/node-request-service.js +62 -2
- package/dist/service/node-run-event-bridge.js +88 -2
- package/dist/service/node-terminal-channel.js +202 -2
- package/dist/service/node-upgrade-coordinator.js +137 -2
- package/dist/service/node-workspace-coordinator.js +97 -2
- package/dist/service/recent-run-projection-service.js +99 -2
- package/dist/service/run-attachment-service.js +321 -2
- package/dist/service/run-domain-state.js +4 -2
- package/dist/service/run-event-service.js +246 -2
- package/dist/service/run-ownership-policy.js +22 -2
- package/dist/service/run-workbench-service.js +120 -2
- package/dist/service/runner-channel-message-service.js +20 -2
- package/dist/service/runner-interaction-service.js +243 -2
- package/dist/service/runner-service.js +69 -2
- package/dist/service/runtime-credential-control-service.js +95 -2
- package/dist/service/session-catalog-service.js +404 -2
- package/dist/service/session-command-service.js +125 -2
- package/dist/service/session-context-service.js +128 -2
- package/dist/service/session-domain-state.js +9 -2
- package/dist/service/session-identity-service.js +86 -2
- package/dist/service/session-lifecycle-service.js +248 -2
- package/dist/service/session-message-service.js +270 -2
- package/dist/service/session-presentation-service.js +43 -2
- package/dist/service/session-query-service.js +82 -2
- package/dist/service/session-watch-slot-coordinator.js +21 -2
- package/dist/service/skill-directory-service.js +238 -2
- package/dist/service/skill-install-service.js +434 -2
- package/dist/service/skill-node-operation-service.js +206 -2
- package/dist/service/terminal-relay-state.js +3 -2
- package/dist/service/terminal-service.js +90 -2
- package/dist/service/web-search-error.js +40 -2
- package/dist/service/workbench-event-service.js +21 -2
- package/dist/service/workbench-manifest-service.js +69 -2
- package/dist/service/workspace-change-service.js +290 -2
- package/dist/service/workspace-content-search-service.js +457 -2
- package/dist/service/workspace-domain-state.js +41 -2
- package/dist/service/workspace-file-service.js +150 -2
- package/dist/service/workspace-git-exclude-service.js +119 -2
- package/dist/service/workspace-queue-workbench-service.js +176 -2
- package/dist/service/workspace-service.js +92 -2
- package/dist/service/workspace-session-service.js +154 -2
- package/dist/service/workspace-upload-service.js +262 -2
- package/dist/service/workspace-watch-controller.js +68 -2
- package/dist/service/workspace-watch-service.js +170 -2
- package/dist/service/workspace-watch-snapshot-service.js +218 -2
- package/dist/service/workspace-workbench-service.js +239 -2
- package/dist/service.js +91 -2
- package/dist/storage.js +32 -2
- package/dist/supervisor.js +136 -2
- package/dist/terminal.js +496 -2
- package/dist/util/git-credential-client.js +32 -0
- package/dist/util/node-operation-data.js +9 -2
- package/dist/util/node-operation-parsers.js +382 -2
- package/dist/util/personal-instructions.js +34 -2
- package/dist/util/runner-error.js +70 -2
- package/dist/util/runner-native-session-parsers.js +510 -2
- package/dist/util/safe-error.js +8 -2
- package/dist/util/secret-environment.js +25 -2
- package/dist/workspace.js +1793 -2
- package/package.json +11 -8
- package/vendor/ripgrep/darwin-arm64/rg +0 -0
- package/vendor/ripgrep/darwin-x64/rg +0 -0
- package/vendor/ripgrep/manifest.json +12 -0
- package/README.md +0 -42
- package/dist/event-buffer.js +0 -2
- package/dist/migrations/v001.js +0 -107
- package/dist/migrations/v002.js +0 -2
- package/dist/migrations/v003.js +0 -2
- package/dist/service/mcp-package-installer.js +0 -2
|
@@ -1,2 +1,382 @@
|
|
|
1
|
-
|
|
2
|
-
const _0xfc1fd6=_0x3a17;(function(_0x348757,_0x26e661){const _0x3d0d58=_0x3a17,_0x2069b6=_0x348757();while(!![]){try{const _0x546ed7=-parseInt(_0x3d0d58(0x65))/(0x95d+-0x18*-0xeb+-0x2*0xfb2)+parseInt(_0x3d0d58(0xcd))/(0x2a6+0x1b01*0x1+-0x1da5)*(parseInt(_0x3d0d58(0x97))/(0x6b9*0x4+0x9c7+-0xc*0x30e))+parseInt(_0x3d0d58(0x9c))/(-0xe7f+-0xff*0x1+0xa*0x18d)*(-parseInt(_0x3d0d58(0x89))/(-0x8cb*-0x4+-0x1*-0x18a7+-0x2*0x1de7))+parseInt(_0x3d0d58(0xce))/(0x9*0x19b+-0x117e*0x2+0x148f)+-parseInt(_0x3d0d58(0x67))/(-0x1a1a*0x1+0x8*0x262+-0x43*-0x1b)*(parseInt(_0x3d0d58(0xc4))/(-0x2567+0x10e5+0x148a))+parseInt(_0x3d0d58(0xa7))/(0x237+-0x2453*0x1+0x2225*0x1)*(-parseInt(_0x3d0d58(0x7f))/(-0x1*0xad9+0x1c14+-0x1131*0x1))+-parseInt(_0x3d0d58(0x87))/(0x26e6+0xece+0x2d3*-0x13)*(-parseInt(_0x3d0d58(0x6f))/(-0x132e+-0x2285+0x35bf));if(_0x546ed7===_0x26e661)break;else _0x2069b6['push'](_0x2069b6['shift']());}catch(_0x340289){_0x2069b6['push'](_0x2069b6['shift']());}}}(_0x24e5,-0xb2918+0xd7f65+0x6e806));function _0x3a17(_0x2e3f3d,_0xed20b5){_0x2e3f3d=_0x2e3f3d-(0x228f+-0x14c0+0x2*-0x6b5);const _0x5ccc31=_0x24e5();let _0x2f29c5=_0x5ccc31[_0x2e3f3d];if(_0x3a17['rqhhns']===undefined){var _0x2d9fd0=function(_0x1e4cc8){const _0x1400c2='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x509d93='',_0xeeca89='';for(let _0x450b67=-0x24f3+0x11*-0xd+0x25d0,_0x23ecbd,_0x91d233,_0x2895ae=-0xce3*-0x1+0x2*0x10a2+-0x2e27;_0x91d233=_0x1e4cc8['charAt'](_0x2895ae++);~_0x91d233&&(_0x23ecbd=_0x450b67%(-0x20f3+-0x14d5*-0x1+0xc22)?_0x23ecbd*(-0x337*-0x6+-0x3*0x3bb+-0x7*0x11f)+_0x91d233:_0x91d233,_0x450b67++%(0x1325+0x1*-0x17c1+0x4a0))?_0x509d93+=String['fromCharCode'](-0x57b+0xdb8+-0x73e&_0x23ecbd>>(-(0x6a8+-0x395*0x7+0x126d)*_0x450b67&-0x48d*0x3+0x12*0xb+0x9*0x16f)):-0xf*0xcd+0xf40+0x1*-0x33d){_0x91d233=_0x1400c2['indexOf'](_0x91d233);}for(let _0x3428dd=0x1d21*-0x1+-0x8d9+-0x12fd*-0x2,_0x13cba7=_0x509d93['length'];_0x3428dd<_0x13cba7;_0x3428dd++){_0xeeca89+='%'+('00'+_0x509d93['charCodeAt'](_0x3428dd)['toString'](-0x271+0x97*0xb+0x154*-0x3))['slice'](-(0x1f10+-0xdd*-0x28+-0xe6*0x49));}return decodeURIComponent(_0xeeca89);};_0x3a17['SNYeTy']=_0x2d9fd0,_0x3a17['cTQPyg']={},_0x3a17['rqhhns']=!![];}const _0x206751=_0x5ccc31[0x4e*0x79+0x44d*0x4+-0x301*0x12];_0x3a17['JOTgeF']!==_0x206751&&(_0x3a17['cTQPyg']={},_0x3a17['JOTgeF']=_0x206751);const _0x3b823e=_0x3a17['cTQPyg'][_0x2e3f3d];return _0x3b823e===undefined?(_0x2f29c5=_0x3a17['SNYeTy'](_0x2f29c5),_0x3a17['cTQPyg'][_0x2e3f3d]=_0x2f29c5):_0x2f29c5=_0x3b823e,_0x2f29c5;}import{nodeCapabilitiesSchema}from'@myagentroam/protocol';const MAX_COMPOSER_ATTACHMENT_BYTES=(0x1679*0x1+-0x822*0x1+0xd*-0x11a)*(-0x20b6*0x1+-0x4b5*0x7+0x45a9)*(-0x337*-0x6+-0x3*0x3bb+-0x1*0x419),MAX_COMPOSER_ATTACHMENTS_BYTES=(0x1325+0x1*-0x17c1+0x4a6)*(-0x57b+0xdb8+-0x43d)*(0x6a8+-0x395*0x7+0x166b),USER_AUTHORIZATION_CLOCK_SKEW_MS=-0x48d*0x3+0x12*0xb+0x1*0x2069,NON_IMAGE_ATTACHMENT_PROMPT_PREFIX=_0xfc1fd6(0x76),COMPOSER_IMAGE_MIME_TYPES=new Set([_0xfc1fd6(0x8e),_0xfc1fd6(0x7e),_0xfc1fd6(0x99),_0xfc1fd6(0x98)]);export const DEFAULT_SESSION_PAGE_SIZE=-0xf*0xcd+0xf40+0x1*-0x333;export const MAX_SESSION_PAGE_SIZE=0x1d21*-0x1+-0x8d9+-0xcca*-0x3;export function sessionPage(_0x42a6cb,_0x3b5df5){const _0x30660d=_0xfc1fd6,_0x58d7a6=typeof _0x3b5df5[_0x30660d(0x82)]===_0x30660d(0x96)&&Number[_0x30660d(0xac)](_0x3b5df5[_0x30660d(0x82)])&&_0x3b5df5[_0x30660d(0x82)]>=-0x271+0x97*0xb+0x159*-0x3&&_0x3b5df5[_0x30660d(0x82)]<=MAX_SESSION_PAGE_SIZE?_0x3b5df5[_0x30660d(0x82)]:DEFAULT_SESSION_PAGE_SIZE,_0x45cf41=typeof _0x3b5df5[_0x30660d(0xba)]===_0x30660d(0x6b)?_0x3b5df5[_0x30660d(0xba)]:undefined,_0x150556=[..._0x42a6cb][_0x30660d(0x86)](compareSessionPageEntries),_0x753d2a=_0x45cf41===undefined?undefined:parseSessionPageCursor(_0x45cf41),_0x4088e7=_0x45cf41===undefined?_0x150556:_0x753d2a===undefined?[]:_0x150556[_0x30660d(0x7d)](_0x19185e=>compareSessionPageEntries(_0x19185e,_0x753d2a)>0x1f10+-0xdd*-0x28+-0x833*0x8),_0x58d834=_0x150556[_0x30660d(0x7d)](_0x15a35f=>_0x15a35f[_0x30660d(0xb6)]!==null&&_0x15a35f[_0x30660d(0xb6)]!==undefined),_0x19fc55=new Map(_0x58d834[_0x30660d(0x6e)]((_0x5cbe61,_0x2f8936)=>[_0x5cbe61['id'],_0x2f8936])),_0x20d646=_0x4088e7[_0x30660d(0xa0)](0x4e*0x79+0x44d*0x4+-0x301*0x12,_0x58d7a6)[_0x30660d(0x6e)](_0x552a7b=>{const _0x1bcd4c=_0x30660d,_0x2b8022=_0x19fc55[_0x1bcd4c(0xbc)](_0x552a7b['id']);if(_0x2b8022===undefined)return _0x552a7b;return{..._0x552a7b,'canMovePinUp':_0x2b8022>-0x1*0x12e+-0x1aee+0x1c1c,'canMovePinDown':_0x2b8022<_0x58d834[_0x1bcd4c(0xae)]-(0x9af+-0x209*0x7+-0x1*-0x491)};}),_0x66580f=_0x20d646['at'](-(-0x1f9b*0x1+-0x5*0x12a+-0x3*-0xc7a));return{'sessions':_0x20d646,'nextCursor':_0x66580f!==undefined&&_0x4088e7[_0x30660d(0xae)]>_0x20d646[_0x30660d(0xae)]?createSessionPageCursor(_0x66580f):null};}export function parseSessionPageCursor(_0xd21843){const _0x1a83e3=_0xfc1fd6;try{const _0x43a3af=JSON[_0x1a83e3(0xd4)](decodeURIComponent(_0xd21843));if(!Array[_0x1a83e3(0x9d)](_0x43a3af)||_0x43a3af[_0x1a83e3(0xae)]!==-0xe11+-0xb93*-0x1+0x1*0x281)return undefined;const [_0x174204,_0x3e38d8,_0x2a408f]=_0x43a3af;if(_0x174204!==null&&(typeof _0x174204!==_0x1a83e3(0x96)||!Number[_0x1a83e3(0x70)](_0x174204))||_0x3e38d8!==null&&(typeof _0x3e38d8!==_0x1a83e3(0x96)||!Number[_0x1a83e3(0x70)](_0x3e38d8))||typeof _0x2a408f!==_0x1a83e3(0x6b))return undefined;return{'id':_0x2a408f,'lastActivityAt':_0x3e38d8??-0x68f*0x1+-0xb5*-0x25+-0x139a,'pinOrder':_0x174204,'externalDiscovered':_0x3e38d8!==null};}catch{return undefined;}}export function createSessionPageCursor(_0x295e14){const _0x2c3bd1=_0xfc1fd6;return encodeURIComponent(JSON[_0x2c3bd1(0x80)]([_0x295e14[_0x2c3bd1(0xb6)]??null,_0x295e14[_0x2c3bd1(0x93)]===![]?null:_0x295e14[_0x2c3bd1(0x77)],_0x295e14['id']]));}export function compareSessionPageEntries(_0x42b3a2,_0x148a73){const _0x3a45f2=_0xfc1fd6,_0x5e0c62=_0x42b3a2[_0x3a45f2(0xb6)]!==null&&_0x42b3a2[_0x3a45f2(0xb6)]!==undefined,_0x48d401=_0x148a73[_0x3a45f2(0xb6)]!==null&&_0x148a73[_0x3a45f2(0xb6)]!==undefined;if(_0x5e0c62!==_0x48d401)return _0x5e0c62?-(-0x2e1*0xb+-0xf3f+-0x2eeb*-0x1):-0x21d6+-0xa*0x357+0x433d;if(_0x5e0c62&&_0x48d401)return _0x42b3a2[_0x3a45f2(0xb6)]-_0x148a73[_0x3a45f2(0xb6)]||_0x42b3a2['id'][_0x3a45f2(0x92)](_0x148a73['id']);const _0xfeeef0=_0x42b3a2[_0x3a45f2(0x93)]!==![],_0x412b47=_0x148a73[_0x3a45f2(0x93)]!==![];if(_0xfeeef0!==_0x412b47)return _0xfeeef0?-(0x82*-0x30+-0x3*-0x49d+-0x2*-0x545):0x32b+-0x1d90+0x1a66;return _0x148a73[_0x3a45f2(0x77)]-_0x42b3a2[_0x3a45f2(0x77)]||_0x42b3a2['id'][_0x3a45f2(0x92)](_0x148a73['id'],'en');}export function compactRunnerText(_0x53ec35,_0x4da8af){const _0x54ddac=_0xfc1fd6;return _0x53ec35[_0x54ddac(0xae)]<=_0x4da8af?_0x53ec35:_0x53ec35[_0x54ddac(0xa0)](-0x9f0+-0xc0b+0x15fb,Math[_0x54ddac(0xa5)](0x1*-0x5a+0x7*-0x2cd+-0x27*-0x83,_0x4da8af-(0x2492+-0x110b+0x165*-0xe)))+'…';}export function compactRunnerValue(_0x5dabe1,_0x3361cb){const _0xae739b=_0xfc1fd6;if(_0x5dabe1===undefined||_0x5dabe1===null)return{'text':'','truncated':![]};let _0x224220;if(typeof _0x5dabe1===_0xae739b(0x6b))_0x224220=_0x5dabe1;else try{_0x224220=JSON[_0xae739b(0x80)](_0x5dabe1);}catch{return{'text':_0xae739b(0x8c),'truncated':![]};}return{'text':compactRunnerText(_0x224220,_0x3361cb),'truncated':_0x224220[_0xae739b(0xae)]>_0x3361cb};}export function codexTimestamp(_0x4fc552){const _0x1816a8=_0xfc1fd6;if(typeof _0x4fc552===_0x1816a8(0x96)&&Number[_0x1816a8(0x70)](_0x4fc552))return _0x4fc552<-0x4354dc*-0x1a0+0x4893b6d7c+-0x2a2996efc?_0x4fc552*(0x454*-0x5+-0x4c8+-0x4*-0x795):_0x4fc552;if(typeof _0x4fc552===_0x1816a8(0x6b)){const _0x4216f6=Date[_0x1816a8(0xd4)](_0x4fc552);return Number[_0x1816a8(0x8d)](_0x4216f6)?null:_0x4216f6;}return null;}export function nativePageEnd(_0x347c6a,_0x40c635,_0x107f7c){const _0x533226=_0xfc1fd6;if(_0x347c6a===undefined)return _0x107f7c;try{const _0x1fefae=JSON[_0x533226(0xd4)](Buffer[_0x533226(0xb7)](_0x347c6a,_0x533226(0xb3))[_0x533226(0xcb)](_0x533226(0x7a)));return _0x1fefae[_0x533226(0x6c)]===_0x40c635&&Number[_0x533226(0xac)](_0x1fefae[_0x533226(0xb2)])&&_0x1fefae[_0x533226(0xb2)]>=-0x4*0x48e+-0x2*-0xe41+-0xa4a?Math[_0x533226(0xcc)](_0x1fefae[_0x533226(0xb2)],_0x107f7c):_0x107f7c;}catch{return _0x107f7c;}}export function extractClaudeText(_0x223aa1){const _0x146454=_0xfc1fd6;return claudeContentBlocks(_0x223aa1)[_0x146454(0x78)](_0x2bcd92=>_0x2bcd92[_0x146454(0x91)]===_0x146454(0x9b)&&typeof _0x2bcd92[_0x146454(0x9b)]===_0x146454(0x6b)?[_0x2bcd92[_0x146454(0x9b)]]:[])[_0x146454(0x8f)]('');}export function extractClaudeThinkingSummaries(_0x191959){const _0x149745=_0xfc1fd6;return claudeContentBlocks(_0x191959)[_0x149745(0x78)](_0xc45af0=>{const _0x4e5a77=_0x149745;if(_0xc45af0[_0x4e5a77(0x91)]!==_0x4e5a77(0x72)||typeof _0xc45af0[_0x4e5a77(0x72)]!==_0x4e5a77(0x6b))return[];const _0x55df88=compactRunnerText(_0xc45af0[_0x4e5a77(0x72)][_0x4e5a77(0x8a)](),-0x1*-0x29e9+0x1f3*0xf+0x2*-0x100b);return _0x55df88[_0x4e5a77(0xae)]===-0x126*0x22+-0x44c+-0x56b*-0x8?[]:[_0x55df88];});}export function extractClaudeToolUses(_0x14bffd){const _0x173e15=_0xfc1fd6;return claudeContentBlocks(_0x14bffd)[_0x173e15(0x78)](_0x5f3b3d=>{const _0x4cb03e=_0x173e15;if(_0x5f3b3d[_0x4cb03e(0x91)]!==_0x4cb03e(0xc2)||typeof _0x5f3b3d['id']!==_0x4cb03e(0x6b)||typeof _0x5f3b3d[_0x4cb03e(0xbe)]!==_0x4cb03e(0x6b))return[];const _0x3267db=_0x5f3b3d[_0x4cb03e(0x88)],_0x721a92=isPlainRecord(_0x3267db)&&typeof _0x3267db[_0x4cb03e(0xd2)]===_0x4cb03e(0x6b)?_0x3267db[_0x4cb03e(0xd2)]:undefined;return[{'id':_0x5f3b3d['id'],'name':_0x5f3b3d[_0x4cb03e(0xbe)],'input':_0x3267db,..._0x721a92===undefined?{}:{'command':_0x721a92},'inputTruncated':compactRunnerValue(_0x3267db,0x1375*-0x1+-0x333a+0x15f3*0x5)[_0x4cb03e(0xcf)]}];});}export function extractClaudeToolResults(_0x5e78a2){const _0x2799b0=_0xfc1fd6,_0x5d7fe6=typeof _0x5e78a2[_0x2799b0(0x90)]===_0x2799b0(0x6b)?_0x5e78a2[_0x2799b0(0x90)]:null,_0x164e87=compactRunnerValue(_0x5e78a2[_0x2799b0(0x6a)],0x19e6+-0x328d+0x3fb7);if(_0x5d7fe6!==null&&_0x164e87[_0x2799b0(0x9b)][_0x2799b0(0xae)]>0x3b5*0x1+0xaa6+-0xe5b)return[{'toolUseId':_0x5d7fe6,'output':_0x164e87[_0x2799b0(0x9b)],'failed':![],'truncated':_0x164e87[_0x2799b0(0xcf)]}];return claudeContentBlocks(_0x5e78a2)[_0x2799b0(0x78)](_0x4c9676=>{const _0x27580f=_0x2799b0;if(_0x4c9676[_0x27580f(0x91)]!==_0x27580f(0x9e)||typeof _0x4c9676[_0x27580f(0xaf)]!==_0x27580f(0x6b))return[];const _0x2938b0=compactRunnerValue(_0x4c9676[_0x27580f(0x9f)],0x9b*-0x1+-0x296+-0x1*-0x2a41);return[{'toolUseId':_0x4c9676[_0x27580f(0xaf)],'output':_0x2938b0[_0x27580f(0x9b)],'failed':_0x4c9676[_0x27580f(0x68)]===!![],'truncated':_0x2938b0[_0x27580f(0xcf)]}];});}export function claudeContentBlocks(_0x4a8fed){const _0x39b0d4=_0xfc1fd6,_0x49c00e=_0x4a8fed[_0x39b0d4(0x7c)];if(!isPlainRecord(_0x49c00e)||!Array[_0x39b0d4(0x9d)](_0x49c00e[_0x39b0d4(0x9f)]))return[];return _0x49c00e[_0x39b0d4(0x9f)][_0x39b0d4(0x7d)](isPlainRecord);}export function isClaudeCommandTool(_0x60c39a){const _0x58fdbb=_0xfc1fd6;return _0x60c39a===_0x58fdbb(0xa4)||_0x60c39a===_0x58fdbb(0xc1)||_0x60c39a===_0x58fdbb(0xab);}export function nativeClaudeCommand(_0x221e09){const _0x29d745=_0xfc1fd6;if(isPlainRecord(_0x221e09[_0x29d745(0x88)])&&typeof _0x221e09[_0x29d745(0x88)][_0x29d745(0xd2)]===_0x29d745(0x6b))return compactRunnerText(_0x221e09[_0x29d745(0x88)][_0x29d745(0xd2)],-0x1*-0x30d1+0x236d*0x2+0x509b*-0x1);return _0x221e09[_0x29d745(0xbb)]??_0x221e09[_0x29d745(0xb1)];}export function boundedConversationItemId(_0x171b8f,_0xc46e09){const _0x4c4ff1=_0xfc1fd6,_0xcadf1=_0x171b8f+':'+_0xc46e09;if(_0xcadf1[_0x4c4ff1(0xae)]<=-0x110c+-0x3ab+0x150f)return _0xcadf1;return _0x171b8f+':'+Buffer[_0x4c4ff1(0xb7)](_0xc46e09)[_0x4c4ff1(0xcb)](_0x4c4ff1(0xb3))[_0x4c4ff1(0xa0)](0x2237+-0x1c95+0x1*-0x5a2,-0x1*0x6c5+-0x61a+0xd37-_0x171b8f[_0x4c4ff1(0xae)]-(0x23b2+-0x42a+0x7*-0x481));}export function validUserAuthorization(_0xd05f55,_0x58456c,_0x16b57b,_0x4b39c8,_0x436bd6=Date[_0xfc1fd6(0xa1)]()){const _0x4f4fb0=_0xfc1fd6;if(typeof _0xd05f55!==_0x4f4fb0(0x85)||_0xd05f55===null||_0x4b39c8===undefined)return![];const _0x45c53c=_0xd05f55;return typeof _0x45c53c[_0x4f4fb0(0xa8)]===_0x4f4fb0(0x96)&&Number[_0x4f4fb0(0xa6)](_0x45c53c[_0x4f4fb0(0xa8)])&&_0x45c53c[_0x4f4fb0(0xa8)]>-0x21fb+0x8b5*-0x3+0x3c1a&&typeof _0x45c53c[_0x4f4fb0(0x81)]===_0x4f4fb0(0x6b)&&/^[A-Za-z0-9_-]{43}$/[_0x4f4fb0(0xbd)](_0x45c53c[_0x4f4fb0(0x81)])&&_0x45c53c[_0x4f4fb0(0xb0)]===_0x4b39c8&&_0x45c53c[_0x4f4fb0(0xb4)]===_0x16b57b&&_0x45c53c[_0x4f4fb0(0x6d)]===_0x58456c['id']&&typeof _0x45c53c[_0x4f4fb0(0xc7)]===_0x4f4fb0(0x96)&&typeof _0x45c53c[_0x4f4fb0(0xad)]===_0x4f4fb0(0x96)&&Number[_0x4f4fb0(0xa6)](_0x45c53c[_0x4f4fb0(0xc7)])&&Number[_0x4f4fb0(0xa6)](_0x45c53c[_0x4f4fb0(0xad)])&&_0x45c53c[_0x4f4fb0(0xc7)]<=_0x436bd6+USER_AUTHORIZATION_CLOCK_SKEW_MS&&_0x45c53c[_0x4f4fb0(0xad)]>=_0x436bd6-USER_AUTHORIZATION_CLOCK_SKEW_MS&&_0x45c53c[_0x4f4fb0(0xad)]-_0x45c53c[_0x4f4fb0(0xc7)]<=-0x5b49+0x1*0x755+-0x8e8c*-0x1;}export function isTerminalRunStatus(_0x3f0369){const _0x38cc83=_0xfc1fd6;return _0x3f0369===_0x38cc83(0xd6)||_0x3f0369===_0x38cc83(0xa2)||_0x3f0369===_0x38cc83(0x94)||_0x3f0369===_0x38cc83(0x69);}export function validSessionOption(_0x1c9a3e){const _0x3f8428=_0xfc1fd6;return _0x1c9a3e===undefined||typeof _0x1c9a3e===_0x3f8428(0x6b)&&_0x1c9a3e[_0x3f8428(0x8a)]()[_0x3f8428(0xae)]>-0x8*0x14+-0x1*0x1c4b+0x1ceb&&_0x1c9a3e[_0x3f8428(0xae)]<=0x1fe+-0x1*0x9cb+0x845;}export function validSessionEffort(_0x52e334){const _0x50bbc7=_0xfc1fd6;return _0x52e334===undefined||typeof _0x52e334===_0x50bbc7(0x6b)&&_0x52e334[_0x50bbc7(0xae)]<=-0xac6+0xa26+0x118;}export function validSessionTitle(_0x3493a1){const _0x1b86c8=_0xfc1fd6;return _0x3493a1===undefined||typeof _0x3493a1===_0x1b86c8(0x6b)&&_0x3493a1[_0x1b86c8(0x8a)]()[_0x1b86c8(0xae)]>-0x1616+0xa85+0xb91&&_0x3493a1[_0x1b86c8(0xae)]<=0x243f+0x2564+-0x4903;}export function sessionTitleFromFirstMessage(_0x3a6816){const _0x415b8a=_0xfc1fd6;return _0x3a6816[_0x415b8a(0x8a)]()[_0x415b8a(0xa9)](/\s+/g,'\x20')[_0x415b8a(0xa0)](-0x214f*-0x1+0x1*-0x1f51+-0x1fe,-0x4a*0x1d+-0x1*-0x4f7+0x17*0x2d);}function _0x24e5(){const _0x56a344=['C3rHCNrZv2L0Aa','zgf0yujHC2u2na','yMfZAa','Dg9VBf91C2u','C29Tzq','ntu4ody3mMn2u3jAyq','ChjVDg9JB2W','tuvtu0fhrv9bvfrbq0Hnru5uu19jtLzbteLe','AxnZDwvKqxq','Ahr0Chm6','Aw5JBhvKzxm','y2HHCKnVzgvbDa','Dg9tDhjPBMC','BwLU','nJK4og5hyuLHtW','mJi0mta2mgHzvwzYvG','Dhj1BMnHDgvK','AgfZAa','AgfZ','y29TBwfUza','D3m6','CgfYC2u','Cgf0Ag5HBwu','u1vdq0vfreve','mtiWnJi2nvLqrKHvza','l2fWAs9UB2rLl3rLCM1PBMfSlwnVBM5Ly3q','n1fUA3DLsW','AxnFzxjYB3i','su5urvjsvvburuq','Dg9VBf91C2vFCMvZDwX0','C3rYAw5N','C2vZC2LVBKLK','CMvXDwvZDeLK','BwfW','mZaWCxLoqKLj','AxngAw5PDgu','l2fWAs9UB2rLl2nVBM5Ly3q','DgHPBMTPBMC','y29TCg9ZzxjbDhrHy2HTzw50swq','yNL0zuXLBMD0Aa','C2L6zq','cGPbDhrHy2HTzw50CYbHDMfPBgfIBguGAw4GDgHLifDVCMTZCgfJztOk','BgfZDefJDgL2Axr5qxq','zMXHDe1HCa','Ahr0CdO','DxrMoa','AxrLBxm','BwvZC2fNzq','zMLSDgvY','Aw1Hz2uVANbLzW','ntbxDM9RzLC','C3rYAw5NAwz5','C2vZC2LVBKHHC2G','BgLTAxq','C3rHDhvZ','C2vHCMnO','B2jQzwn0','C29YDa','mtu0mJy5nxrOugHHuG','Aw5WDxq','mty2nJC3mfLLtfj6za','DhjPBq','pd46iNW/kG','kfvUywjSzsb0BYbKAxnWBgf5kq','Axnoyu4','Aw1Hz2uVCg5N','AM9PBG','CgfYzw50x3rVB2XFDxnLx2LK','DhLWzq','Bg9JywXLq29TCgfYzq','zxH0zxjUywXeAxnJB3zLCMvK','q0foq0vmteve','D3nZoG','BNvTyMvY','mZbKrLnqrNO','Aw1Hz2uVD2vICa','Aw1Hz2uVz2LM','BwLTzq','Dgv4Da','mtjpuLvdvha','AxnbCNjHEq','Dg9VBf9Yzxn1Bhq','y29UDgvUDa','C2XPy2u','BM93','rKfjteve','Aw1Hz2uV','qMfZAa','Bwf4','AxntywzLsw50zwDLCG','nZi2otKZzxDMrKPH','DxnLCKLK','CMvWBgfJzq','yMfZzty0','u2HLBgW','AxnjBNrLz2vY','zxHWAxjLC0f0','BgvUz3rO','Dg9VBf91C2vFAwq','BM9KzuLK','Dg9VBe5HBwu','zw5K','yMfZzty0DxjS','B3bLCMf0Aw9U','u0vsvKvsx1vstf9jtLzbteLe','CgLUt3jKzxi','zNjVBq','tuvtu0fhrv9bvfrbq0Hnru5ux1vou1vque9sveve','q09nue9trvjFqvruqunituvovf9jtLzbteLe','y3vYC29Y','Aw5WDxrtDw1Tyxj5','z2v0','DgvZDa','BMfTzq'];_0x24e5=function(){return _0x56a344;};return _0x24e5();}export function parseComposerAttachmentUpload(_0x3c2474){const _0x210845=_0xfc1fd6;if(_0x3c2474[_0x210845(0x73)]===undefined&&_0x3c2474[_0x210845(0x9a)]===undefined)return undefined;if(typeof _0x3c2474[_0x210845(0x73)]!==_0x210845(0x6b)||!isUuid(_0x3c2474[_0x210845(0x73)])||typeof _0x3c2474[_0x210845(0xbe)]!==_0x210845(0x6b)||!validComposerAttachmentName(_0x3c2474[_0x210845(0xbe)])||typeof _0x3c2474[_0x210845(0x9a)]!==_0x210845(0x6b)||_0x3c2474[_0x210845(0x9a)][_0x210845(0xae)]===0xcd*-0x25+-0xf92*0x1+-0x85*-0x57||_0x3c2474[_0x210845(0x9a)][_0x210845(0xae)]>0xbf8*-0x3+0x1d4*-0x1+-0x2*-0x131a)throw new Error(_0x210845(0xb9));return{'id':_0x3c2474[_0x210845(0x73)],'name':_0x3c2474[_0x210845(0xbe)],'mime':_0x3c2474[_0x210845(0x9a)]};}export function parseComposerAttachmentIds(_0x3aa0fd){const _0x23bbba=_0xfc1fd6;if(_0x3aa0fd===undefined)return[];if(!Array[_0x23bbba(0x9d)](_0x3aa0fd)||_0x3aa0fd[_0x23bbba(0xae)]>-0x1*0x25af+-0x170f*0x1+-0x11*-0x393||_0x3aa0fd[_0x23bbba(0xc3)](_0x407aba=>typeof _0x407aba!==_0x23bbba(0x6b)))throw new Error(_0x23bbba(0xc6));const _0x3d7264=_0x3aa0fd;if(_0x3d7264[_0x23bbba(0xc3)](_0x19e50d=>!isUuid(_0x19e50d))||new Set(_0x3d7264)[_0x23bbba(0x75)]!==_0x3d7264[_0x23bbba(0xae)])throw new Error(_0x23bbba(0xc6));return _0x3d7264;}export function validComposerAttachmentName(_0x250b96){const _0x5aa756=_0xfc1fd6;return _0x250b96[_0x5aa756(0x8a)]()[_0x5aa756(0xae)]>-0x11*-0x2+-0x1bb*-0x2+-0x398&&_0x250b96[_0x5aa756(0xae)]<=0x1325+0x37c*0xb+0x1*-0x387a&&_0x250b96!=='.'&&_0x250b96!=='..'&&!_0x250b96[_0x5aa756(0xc9)]('/')&&!_0x250b96[_0x5aa756(0xc9)]('\x5c')&&!Array[_0x5aa756(0xb7)](_0x250b96)[_0x5aa756(0xc3)](_0x2f4055=>{const _0xd351=_0x5aa756,_0x2224f2=_0x2f4055[_0xd351(0xca)](0x5*0x78d+-0xb5a*-0x3+-0x47cf*0x1);return _0x2224f2<=-0x905+-0x1*-0x55a+0xc2*0x5||_0x2224f2===-0x2*0xa45+-0x170e+0x2c17||_0xd351(0x8b)[_0xd351(0xc9)](_0x2f4055);});}export function isUuid(_0x5b141d){const _0x4053b3=_0xfc1fd6;return/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i[_0x4053b3(0xbd)](_0x5b141d);}export function parseMessageAttachments(_0x3bc638){const _0xabeb78=_0xfc1fd6;if(_0x3bc638===undefined)return[];if(!Array[_0xabeb78(0x9d)](_0x3bc638)||_0x3bc638[_0xabeb78(0xae)]>0x1*0xf28+-0x4bb*-0x1+-0x13de)throw new Error(_0xabeb78(0xc6));let _0x5d613d=-0xc83+-0x2350+0x2fd3*0x1;return _0x3bc638[_0xabeb78(0x6e)](_0x1d099f=>{const _0xc322d3=_0xabeb78;if(!isPlainRecord(_0x1d099f))throw new Error(_0xc322d3(0xc6));if(typeof _0x1d099f[_0xc322d3(0xbe)]!==_0xc322d3(0x6b)||typeof _0x1d099f[_0xc322d3(0x9a)]!==_0xc322d3(0x6b)||typeof _0x1d099f[_0xc322d3(0xc0)]!==_0xc322d3(0x6b))throw new Error(_0xc322d3(0xc6));if(!validComposerAttachmentName(_0x1d099f[_0xc322d3(0xbe)])||_0x1d099f[_0xc322d3(0x9a)][_0xc322d3(0xae)]===-0x1bfa+0x569+0x1691||_0x1d099f[_0xc322d3(0x9a)][_0xc322d3(0xae)]>0x528*-0x6+-0x22eb+-0x1*-0x4253||!isCanonicalBase64(_0x1d099f[_0xc322d3(0xc0)]))throw new Error(_0xc322d3(0xc6));const _0x5314e8=Buffer[_0xc322d3(0x74)](_0x1d099f[_0xc322d3(0xc0)],_0xc322d3(0xaa));if(_0x5314e8===-0x1*-0x17b+0x692+-0x9*0xe5||_0x5314e8>MAX_COMPOSER_ATTACHMENT_BYTES)throw new Error(_0xc322d3(0xc6));_0x5d613d+=_0x5314e8;if(_0x5d613d>MAX_COMPOSER_ATTACHMENTS_BYTES)throw new Error(_0xc322d3(0xc6));return{'name':_0x1d099f[_0xc322d3(0xbe)],'mime':_0x1d099f[_0xc322d3(0x9a)],'dataBase64':_0x1d099f[_0xc322d3(0xc0)]};});}export function parseRunnerImageAttachments(_0x5551e1){const _0x385527=_0xfc1fd6;return parseMessageAttachments(_0x5551e1)[_0x385527(0x6e)](_0x1b1a33=>{const _0x1e7735=_0x385527;if(!isRunnerImageAttachment(_0x1b1a33))throw new Error(_0x1e7735(0xb8));return _0x1b1a33;});}export function isRunnerImageAttachment(_0x2d7602){const _0x1e5c18=_0xfc1fd6;return COMPOSER_IMAGE_MIME_TYPES[_0x1e5c18(0xd1)](_0x2d7602[_0x1e5c18(0x9a)]);}export function isImageAttachment(_0x1f3f42){const _0x483a2e=_0xfc1fd6;return _0x1f3f42[_0x483a2e(0x9a)][_0x483a2e(0xbf)](_0x483a2e(0xa3));}export function withNonImageAttachmentPrompt(_0x369e75,_0x55ae93){const _0x56f4ca=_0xfc1fd6;if(_0x55ae93[_0x56f4ca(0xae)]===0x23ee+0x192b+0x3d19*-0x1)return _0x369e75;return''+_0x369e75+NON_IMAGE_ATTACHMENT_PROMPT_PREFIX+_0x55ae93[_0x56f4ca(0x6e)](_0x2eefdb=>'-\x20'+_0x2eefdb)[_0x56f4ca(0x8f)]('\x0a');}export function isCanonicalBase64(_0x3fbe0f){const _0x171fd6=_0xfc1fd6;return _0x3fbe0f[_0x171fd6(0xae)]>0xe8a+0xb3e+-0x258*0xb&&_0x3fbe0f[_0x171fd6(0xae)]%(-0xe9*-0x25+0x17cd+-0x3976)===-0x210*-0x10+0x2*0x61b+0x789*-0x6&&/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/[_0x171fd6(0xbd)](_0x3fbe0f);}export function validatedCapabilities(_0x508c4c){const _0x40a849=_0xfc1fd6;return nodeCapabilitiesSchema[_0x40a849(0xd4)](_0x508c4c);}export function nodeConnectEndpoint(_0x3aba17){const _0x92b2ff=_0xfc1fd6,_0x257630=new URL(_0x3aba17);if(_0x257630[_0x92b2ff(0xc5)]===_0x92b2ff(0x79))_0x257630[_0x92b2ff(0xc5)]=_0x92b2ff(0xd3);if(_0x257630[_0x92b2ff(0xc5)]===_0x92b2ff(0xc8))_0x257630[_0x92b2ff(0xc5)]=_0x92b2ff(0x95);if(_0x257630[_0x92b2ff(0xc5)]!==_0x92b2ff(0xd3)&&_0x257630[_0x92b2ff(0xc5)]!==_0x92b2ff(0x95))throw new Error(_0x92b2ff(0xb5));return _0x257630[_0x92b2ff(0xd5)]=_0x257630[_0x92b2ff(0xd5)][_0x92b2ff(0xa9)](/\/$/,'')+_0x92b2ff(0x71),_0x257630[_0x92b2ff(0x84)]='',_0x257630[_0x92b2ff(0xd0)]='',_0x257630[_0x92b2ff(0xcb)]();}export function nodeTerminalConnectEndpoint(_0x4448a0){const _0x4fce3f=_0xfc1fd6,_0x22aed0=new URL(_0x4448a0);if(_0x22aed0[_0x4fce3f(0xc5)]===_0x4fce3f(0x79))_0x22aed0[_0x4fce3f(0xc5)]=_0x4fce3f(0xd3);if(_0x22aed0[_0x4fce3f(0xc5)]===_0x4fce3f(0xc8))_0x22aed0[_0x4fce3f(0xc5)]=_0x4fce3f(0x95);if(_0x22aed0[_0x4fce3f(0xc5)]!==_0x4fce3f(0xd3)&&_0x22aed0[_0x4fce3f(0xc5)]!==_0x4fce3f(0x95))throw new Error(_0x4fce3f(0xb5));return _0x22aed0[_0x4fce3f(0xd5)]=_0x22aed0[_0x4fce3f(0xd5)][_0x4fce3f(0xa9)](/\/$/,'')+_0x4fce3f(0x66),_0x22aed0[_0x4fce3f(0x84)]='',_0x22aed0[_0x4fce3f(0xd0)]='',_0x22aed0[_0x4fce3f(0xcb)]();}export function isPlainRecord(_0x5e0781){const _0x2b865d=_0xfc1fd6;return typeof _0x5e0781===_0x2b865d(0x85)&&_0x5e0781!==null&&!Array[_0x2b865d(0x9d)](_0x5e0781);}export function isNodeAgentRun(_0x1bbda6){const _0x3e52bc=_0xfc1fd6;return isPlainRecord(_0x1bbda6)&&typeof _0x1bbda6['id']===_0x3e52bc(0x6b)&&typeof _0x1bbda6[_0x3e52bc(0x6c)]===_0x3e52bc(0x6b)&&typeof _0x1bbda6[_0x3e52bc(0x83)]===_0x3e52bc(0x6b);}export function isNodeConversationTurn(_0x129755){const _0x161f33=_0xfc1fd6;return isPlainRecord(_0x129755)&&typeof _0x129755['id']===_0x161f33(0x6b)&&typeof _0x129755[_0x161f33(0x6c)]===_0x161f33(0x6b)&&Array[_0x161f33(0x9d)](_0x129755[_0x161f33(0x7b)]);}
|
|
1
|
+
import { nodeCapabilitiesSchema } from '@myagentroam/protocol';
|
|
2
|
+
const MAX_COMPOSER_ATTACHMENT_BYTES = 5 * 1024 * 1024;
|
|
3
|
+
const MAX_COMPOSER_ATTACHMENTS_BYTES = 10 * 1024 * 1024;
|
|
4
|
+
const USER_AUTHORIZATION_CLOCK_SKEW_MS = 5_000;
|
|
5
|
+
const NON_IMAGE_ATTACHMENT_PROMPT_PREFIX = '\n\nAttachments available in the Workspace:\n';
|
|
6
|
+
const COMPOSER_IMAGE_MIME_TYPES = new Set([
|
|
7
|
+
'image/png',
|
|
8
|
+
'image/jpeg',
|
|
9
|
+
'image/gif',
|
|
10
|
+
'image/webp'
|
|
11
|
+
]);
|
|
12
|
+
export const DEFAULT_SESSION_PAGE_SIZE = 10;
|
|
13
|
+
export const MAX_SESSION_PAGE_SIZE = 100;
|
|
14
|
+
export function sessionPage(sessions, input) {
|
|
15
|
+
const limit = typeof input.limit === 'number' &&
|
|
16
|
+
Number.isInteger(input.limit) &&
|
|
17
|
+
input.limit >= 1 &&
|
|
18
|
+
input.limit <= MAX_SESSION_PAGE_SIZE
|
|
19
|
+
? input.limit
|
|
20
|
+
: DEFAULT_SESSION_PAGE_SIZE;
|
|
21
|
+
const cursor = typeof input.cursor === 'string' ? input.cursor : undefined;
|
|
22
|
+
const ordered = [...sessions].sort(compareSessionPageEntries);
|
|
23
|
+
const cursorEntry = cursor === undefined ? undefined : parseSessionPageCursor(cursor);
|
|
24
|
+
const afterCursor = cursor === undefined
|
|
25
|
+
? ordered
|
|
26
|
+
: cursorEntry === undefined
|
|
27
|
+
? []
|
|
28
|
+
: ordered.filter((session) => compareSessionPageEntries(session, cursorEntry) > 0);
|
|
29
|
+
const pinned = ordered.filter((session) => session.pinOrder !== null && session.pinOrder !== undefined);
|
|
30
|
+
const pinnedIndexes = new Map(pinned.map((session, index) => [session.id, index]));
|
|
31
|
+
const page = afterCursor.slice(0, limit).map((session) => {
|
|
32
|
+
const pinIndex = pinnedIndexes.get(session.id);
|
|
33
|
+
if (pinIndex === undefined)
|
|
34
|
+
return session;
|
|
35
|
+
return {
|
|
36
|
+
...session,
|
|
37
|
+
canMovePinUp: pinIndex > 0,
|
|
38
|
+
canMovePinDown: pinIndex < pinned.length - 1
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
const last = page.at(-1);
|
|
42
|
+
return {
|
|
43
|
+
sessions: page,
|
|
44
|
+
nextCursor: last !== undefined && afterCursor.length > page.length ? createSessionPageCursor(last) : null
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export function parseSessionPageCursor(cursor) {
|
|
48
|
+
try {
|
|
49
|
+
const value = JSON.parse(decodeURIComponent(cursor));
|
|
50
|
+
if (!Array.isArray(value) || value.length !== 3)
|
|
51
|
+
return undefined;
|
|
52
|
+
const [pinOrder, lastActivityAt, id] = value;
|
|
53
|
+
if ((pinOrder !== null && (typeof pinOrder !== 'number' || !Number.isFinite(pinOrder))) ||
|
|
54
|
+
(lastActivityAt !== null &&
|
|
55
|
+
(typeof lastActivityAt !== 'number' || !Number.isFinite(lastActivityAt))) ||
|
|
56
|
+
typeof id !== 'string')
|
|
57
|
+
return undefined;
|
|
58
|
+
return {
|
|
59
|
+
id,
|
|
60
|
+
lastActivityAt: lastActivityAt ?? 0,
|
|
61
|
+
pinOrder,
|
|
62
|
+
externalDiscovered: lastActivityAt !== null
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export function createSessionPageCursor(session) {
|
|
70
|
+
return encodeURIComponent(JSON.stringify([
|
|
71
|
+
session.pinOrder ?? null,
|
|
72
|
+
session.externalDiscovered === false ? null : session.lastActivityAt,
|
|
73
|
+
session.id
|
|
74
|
+
]));
|
|
75
|
+
}
|
|
76
|
+
export function compareSessionPageEntries(left, right) {
|
|
77
|
+
const leftPinned = left.pinOrder !== null && left.pinOrder !== undefined;
|
|
78
|
+
const rightPinned = right.pinOrder !== null && right.pinOrder !== undefined;
|
|
79
|
+
if (leftPinned !== rightPinned)
|
|
80
|
+
return leftPinned ? -1 : 1;
|
|
81
|
+
if (leftPinned && rightPinned)
|
|
82
|
+
return (left.pinOrder - right.pinOrder || left.id.localeCompare(right.id));
|
|
83
|
+
const leftFound = left.externalDiscovered !== false;
|
|
84
|
+
const rightFound = right.externalDiscovered !== false;
|
|
85
|
+
if (leftFound !== rightFound)
|
|
86
|
+
return leftFound ? -1 : 1;
|
|
87
|
+
return right.lastActivityAt - left.lastActivityAt || left.id.localeCompare(right.id, 'en');
|
|
88
|
+
}
|
|
89
|
+
export function compactRunnerText(value, limit) {
|
|
90
|
+
return value.length <= limit ? value : `${value.slice(0, Math.max(0, limit - 1))}…`;
|
|
91
|
+
}
|
|
92
|
+
export function compactRunnerValue(value, limit) {
|
|
93
|
+
if (value === undefined || value === null)
|
|
94
|
+
return { text: '', truncated: false };
|
|
95
|
+
let text;
|
|
96
|
+
if (typeof value === 'string')
|
|
97
|
+
text = value;
|
|
98
|
+
else {
|
|
99
|
+
try {
|
|
100
|
+
text = JSON.stringify(value);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return { text: '(Unable to display)', truncated: false };
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return { text: compactRunnerText(text, limit), truncated: text.length > limit };
|
|
107
|
+
}
|
|
108
|
+
export function codexTimestamp(value) {
|
|
109
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
110
|
+
return value < 10_000_000_000 ? value * 1_000 : value;
|
|
111
|
+
if (typeof value === 'string') {
|
|
112
|
+
const timestamp = Date.parse(value);
|
|
113
|
+
return Number.isNaN(timestamp) ? null : timestamp;
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
export function nativePageEnd(cursor, sessionId, fallback) {
|
|
118
|
+
if (cursor === undefined)
|
|
119
|
+
return fallback;
|
|
120
|
+
try {
|
|
121
|
+
const value = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8'));
|
|
122
|
+
return value.sessionId === sessionId &&
|
|
123
|
+
Number.isInteger(value.end) &&
|
|
124
|
+
value.end >= 0
|
|
125
|
+
? Math.min(value.end, fallback)
|
|
126
|
+
: fallback;
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return fallback;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
export function extractClaudeText(message) {
|
|
133
|
+
return claudeContentBlocks(message)
|
|
134
|
+
.flatMap((block) => block.type === 'text' && typeof block.text === 'string' ? [block.text] : [])
|
|
135
|
+
.join('');
|
|
136
|
+
}
|
|
137
|
+
export function extractClaudeThinkingSummaries(message) {
|
|
138
|
+
return claudeContentBlocks(message).flatMap((block) => {
|
|
139
|
+
// `showThinkingSummaries` asks the SDK/API for exactly these public
|
|
140
|
+
// summaries. Partial raw thinking events are intentionally not read.
|
|
141
|
+
if (block.type !== 'thinking' || typeof block.thinking !== 'string')
|
|
142
|
+
return [];
|
|
143
|
+
const text = compactRunnerText(block.thinking.trim(), 10_000);
|
|
144
|
+
return text.length === 0 ? [] : [text];
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
export function extractClaudeToolUses(message) {
|
|
148
|
+
return claudeContentBlocks(message).flatMap((block) => {
|
|
149
|
+
if (block.type !== 'tool_use' || typeof block.id !== 'string' || typeof block.name !== 'string')
|
|
150
|
+
return [];
|
|
151
|
+
const input = block.input;
|
|
152
|
+
const command = isPlainRecord(input) && typeof input.command === 'string' ? input.command : undefined;
|
|
153
|
+
return [
|
|
154
|
+
{
|
|
155
|
+
id: block.id,
|
|
156
|
+
name: block.name,
|
|
157
|
+
input,
|
|
158
|
+
...(command === undefined ? {} : { command }),
|
|
159
|
+
inputTruncated: compactRunnerValue(input, 10_000).truncated
|
|
160
|
+
}
|
|
161
|
+
];
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
export function extractClaudeToolResults(message) {
|
|
165
|
+
const parentId = typeof message.parent_tool_use_id === 'string' ? message.parent_tool_use_id : null;
|
|
166
|
+
const direct = compactRunnerValue(message.tool_use_result, 10_000);
|
|
167
|
+
if (parentId !== null && direct.text.length > 0)
|
|
168
|
+
return [
|
|
169
|
+
{ toolUseId: parentId, output: direct.text, failed: false, truncated: direct.truncated }
|
|
170
|
+
];
|
|
171
|
+
return claudeContentBlocks(message).flatMap((block) => {
|
|
172
|
+
if (block.type !== 'tool_result' || typeof block.tool_use_id !== 'string')
|
|
173
|
+
return [];
|
|
174
|
+
const result = compactRunnerValue(block.content, 10_000);
|
|
175
|
+
return [
|
|
176
|
+
{
|
|
177
|
+
toolUseId: block.tool_use_id,
|
|
178
|
+
output: result.text,
|
|
179
|
+
failed: block.is_error === true,
|
|
180
|
+
truncated: result.truncated
|
|
181
|
+
}
|
|
182
|
+
];
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
export function claudeContentBlocks(message) {
|
|
186
|
+
const content = message.message;
|
|
187
|
+
if (!isPlainRecord(content) || !Array.isArray(content.content))
|
|
188
|
+
return [];
|
|
189
|
+
return content.content.filter(isPlainRecord);
|
|
190
|
+
}
|
|
191
|
+
export function isClaudeCommandTool(name) {
|
|
192
|
+
return name === 'Bash' || name === 'bash' || name === 'Shell';
|
|
193
|
+
}
|
|
194
|
+
export function nativeClaudeCommand(entry) {
|
|
195
|
+
if (isPlainRecord(entry.input) && typeof entry.input.command === 'string')
|
|
196
|
+
return compactRunnerText(entry.input.command, 10_000);
|
|
197
|
+
return entry.inputSummary ?? entry.toolName;
|
|
198
|
+
}
|
|
199
|
+
export function boundedConversationItemId(prefix, value) {
|
|
200
|
+
const candidate = `${prefix}:${value}`;
|
|
201
|
+
if (candidate.length <= 88)
|
|
202
|
+
return candidate;
|
|
203
|
+
return `${prefix}:${Buffer.from(value)
|
|
204
|
+
.toString('base64url')
|
|
205
|
+
.slice(0, 88 - prefix.length - 1)}`;
|
|
206
|
+
}
|
|
207
|
+
export function validUserAuthorization(value, envelope, operation, nodeId, now = Date.now()) {
|
|
208
|
+
if (typeof value !== 'object' || value === null || nodeId === undefined)
|
|
209
|
+
return false;
|
|
210
|
+
const authorization = value;
|
|
211
|
+
return (typeof authorization.userId === 'number' &&
|
|
212
|
+
Number.isSafeInteger(authorization.userId) &&
|
|
213
|
+
authorization.userId > 0 &&
|
|
214
|
+
typeof authorization.sessionHash === 'string' &&
|
|
215
|
+
/^[A-Za-z0-9_-]{43}$/.test(authorization.sessionHash) &&
|
|
216
|
+
authorization.nodeId === nodeId &&
|
|
217
|
+
authorization.operation === operation &&
|
|
218
|
+
authorization.requestId === envelope.id &&
|
|
219
|
+
typeof authorization.issuedAt === 'number' &&
|
|
220
|
+
typeof authorization.expiresAt === 'number' &&
|
|
221
|
+
Number.isSafeInteger(authorization.issuedAt) &&
|
|
222
|
+
Number.isSafeInteger(authorization.expiresAt) &&
|
|
223
|
+
authorization.issuedAt <= now + USER_AUTHORIZATION_CLOCK_SKEW_MS &&
|
|
224
|
+
authorization.expiresAt >= now - USER_AUTHORIZATION_CLOCK_SKEW_MS &&
|
|
225
|
+
authorization.expiresAt - authorization.issuedAt <= 15_000);
|
|
226
|
+
}
|
|
227
|
+
export function isTerminalRunStatus(status) {
|
|
228
|
+
return (status === 'SUCCEEDED' ||
|
|
229
|
+
status === 'FAILED' ||
|
|
230
|
+
status === 'CANCELLED' ||
|
|
231
|
+
status === 'INTERRUPTED');
|
|
232
|
+
}
|
|
233
|
+
export function validSessionOption(value) {
|
|
234
|
+
return (value === undefined ||
|
|
235
|
+
(typeof value === 'string' && value.trim().length > 0 && value.length <= 120));
|
|
236
|
+
}
|
|
237
|
+
export function validSessionEffort(value) {
|
|
238
|
+
return value === undefined || (typeof value === 'string' && value.length <= 120);
|
|
239
|
+
}
|
|
240
|
+
export function validSessionTitle(value) {
|
|
241
|
+
return (value === undefined ||
|
|
242
|
+
(typeof value === 'string' && value.trim().length > 0 && value.length <= 160));
|
|
243
|
+
}
|
|
244
|
+
export function sessionTitleFromFirstMessage(content) {
|
|
245
|
+
return content.trim().replace(/\s+/g, ' ').slice(0, 160);
|
|
246
|
+
}
|
|
247
|
+
export function parseComposerAttachmentUpload(input) {
|
|
248
|
+
if (input.composerAttachmentId === undefined && input.mime === undefined)
|
|
249
|
+
return undefined;
|
|
250
|
+
if (typeof input.composerAttachmentId !== 'string' ||
|
|
251
|
+
!isUuid(input.composerAttachmentId) ||
|
|
252
|
+
typeof input.name !== 'string' ||
|
|
253
|
+
!validComposerAttachmentName(input.name) ||
|
|
254
|
+
typeof input.mime !== 'string' ||
|
|
255
|
+
input.mime.length === 0 ||
|
|
256
|
+
input.mime.length > 120)
|
|
257
|
+
throw new Error('COMPOSER_ATTACHMENT_INVALID');
|
|
258
|
+
return { id: input.composerAttachmentId, name: input.name, mime: input.mime };
|
|
259
|
+
}
|
|
260
|
+
export function parseComposerAttachmentIds(value) {
|
|
261
|
+
if (value === undefined)
|
|
262
|
+
return [];
|
|
263
|
+
if (!Array.isArray(value) || value.length > 5 || value.some((id) => typeof id !== 'string'))
|
|
264
|
+
throw new Error('MESSAGE_ATTACHMENTS_INVALID');
|
|
265
|
+
const ids = value;
|
|
266
|
+
if (ids.some((id) => !isUuid(id)) || new Set(ids).size !== ids.length)
|
|
267
|
+
throw new Error('MESSAGE_ATTACHMENTS_INVALID');
|
|
268
|
+
return ids;
|
|
269
|
+
}
|
|
270
|
+
export function validComposerAttachmentName(name) {
|
|
271
|
+
return (name.trim().length > 0 &&
|
|
272
|
+
name.length <= 255 &&
|
|
273
|
+
name !== '.' &&
|
|
274
|
+
name !== '..' &&
|
|
275
|
+
!name.includes('/') &&
|
|
276
|
+
!name.includes('\\') &&
|
|
277
|
+
!Array.from(name).some((character) => {
|
|
278
|
+
const code = character.charCodeAt(0);
|
|
279
|
+
return code <= 31 || code === 127 || '<>:"|?*'.includes(character);
|
|
280
|
+
}));
|
|
281
|
+
}
|
|
282
|
+
export function isUuid(value) {
|
|
283
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value);
|
|
284
|
+
}
|
|
285
|
+
export function parseMessageAttachments(value) {
|
|
286
|
+
if (value === undefined)
|
|
287
|
+
return [];
|
|
288
|
+
if (!Array.isArray(value) || value.length > 5)
|
|
289
|
+
throw new Error('MESSAGE_ATTACHMENTS_INVALID');
|
|
290
|
+
let totalBytes = 0;
|
|
291
|
+
return value.map((attachment) => {
|
|
292
|
+
if (!isPlainRecord(attachment))
|
|
293
|
+
throw new Error('MESSAGE_ATTACHMENTS_INVALID');
|
|
294
|
+
if (typeof attachment.name !== 'string' ||
|
|
295
|
+
typeof attachment.mime !== 'string' ||
|
|
296
|
+
typeof attachment.dataBase64 !== 'string')
|
|
297
|
+
throw new Error('MESSAGE_ATTACHMENTS_INVALID');
|
|
298
|
+
if (!validComposerAttachmentName(attachment.name) ||
|
|
299
|
+
attachment.mime.length === 0 ||
|
|
300
|
+
attachment.mime.length > 120 ||
|
|
301
|
+
!isCanonicalBase64(attachment.dataBase64))
|
|
302
|
+
throw new Error('MESSAGE_ATTACHMENTS_INVALID');
|
|
303
|
+
const byteSize = Buffer.byteLength(attachment.dataBase64, 'base64');
|
|
304
|
+
if (byteSize === 0 || byteSize > MAX_COMPOSER_ATTACHMENT_BYTES)
|
|
305
|
+
throw new Error('MESSAGE_ATTACHMENTS_INVALID');
|
|
306
|
+
totalBytes += byteSize;
|
|
307
|
+
if (totalBytes > MAX_COMPOSER_ATTACHMENTS_BYTES)
|
|
308
|
+
throw new Error('MESSAGE_ATTACHMENTS_INVALID');
|
|
309
|
+
return { name: attachment.name, mime: attachment.mime, dataBase64: attachment.dataBase64 };
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
export function parseRunnerImageAttachments(value) {
|
|
313
|
+
return parseMessageAttachments(value).map((attachment) => {
|
|
314
|
+
if (!isRunnerImageAttachment(attachment))
|
|
315
|
+
throw new Error('MESSAGE_ATTACHMENT_UNSUPPORTED');
|
|
316
|
+
return attachment;
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
export function isRunnerImageAttachment(attachment) {
|
|
320
|
+
return COMPOSER_IMAGE_MIME_TYPES.has(attachment.mime);
|
|
321
|
+
}
|
|
322
|
+
export function isImageAttachment(attachment) {
|
|
323
|
+
return attachment.mime.startsWith('image/');
|
|
324
|
+
}
|
|
325
|
+
export function withNonImageAttachmentPrompt(input, paths) {
|
|
326
|
+
if (paths.length === 0)
|
|
327
|
+
return input;
|
|
328
|
+
return `${input}${NON_IMAGE_ATTACHMENT_PROMPT_PREFIX}${paths
|
|
329
|
+
.map((path) => `- ${path}`)
|
|
330
|
+
.join('\n')}`;
|
|
331
|
+
}
|
|
332
|
+
export function isCanonicalBase64(value) {
|
|
333
|
+
return (value.length > 0 &&
|
|
334
|
+
value.length % 4 === 0 &&
|
|
335
|
+
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value));
|
|
336
|
+
}
|
|
337
|
+
export function validatedCapabilities(value) {
|
|
338
|
+
return nodeCapabilitiesSchema.parse(value);
|
|
339
|
+
}
|
|
340
|
+
export function nodeConnectEndpoint(serverUrl) {
|
|
341
|
+
const endpoint = new URL(serverUrl);
|
|
342
|
+
if (endpoint.protocol === 'http:')
|
|
343
|
+
endpoint.protocol = 'ws:';
|
|
344
|
+
if (endpoint.protocol === 'https:')
|
|
345
|
+
endpoint.protocol = 'wss:';
|
|
346
|
+
if (endpoint.protocol !== 'ws:' && endpoint.protocol !== 'wss:') {
|
|
347
|
+
throw new Error('SERVER_URL_INVALID');
|
|
348
|
+
}
|
|
349
|
+
endpoint.pathname = `${endpoint.pathname.replace(/\/$/, '')}/api/node/connect`;
|
|
350
|
+
endpoint.search = '';
|
|
351
|
+
endpoint.hash = '';
|
|
352
|
+
return endpoint.toString();
|
|
353
|
+
}
|
|
354
|
+
export function nodeTerminalConnectEndpoint(serverUrl) {
|
|
355
|
+
const endpoint = new URL(serverUrl);
|
|
356
|
+
if (endpoint.protocol === 'http:')
|
|
357
|
+
endpoint.protocol = 'ws:';
|
|
358
|
+
if (endpoint.protocol === 'https:')
|
|
359
|
+
endpoint.protocol = 'wss:';
|
|
360
|
+
if (endpoint.protocol !== 'ws:' && endpoint.protocol !== 'wss:') {
|
|
361
|
+
throw new Error('SERVER_URL_INVALID');
|
|
362
|
+
}
|
|
363
|
+
endpoint.pathname = `${endpoint.pathname.replace(/\/$/, '')}/api/node/terminal-connect`;
|
|
364
|
+
endpoint.search = '';
|
|
365
|
+
endpoint.hash = '';
|
|
366
|
+
return endpoint.toString();
|
|
367
|
+
}
|
|
368
|
+
export function isPlainRecord(value) {
|
|
369
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
370
|
+
}
|
|
371
|
+
export function isNodeAgentRun(value) {
|
|
372
|
+
return (isPlainRecord(value) &&
|
|
373
|
+
typeof value.id === 'string' &&
|
|
374
|
+
typeof value.sessionId === 'string' &&
|
|
375
|
+
typeof value.status === 'string');
|
|
376
|
+
}
|
|
377
|
+
export function isNodeConversationTurn(value) {
|
|
378
|
+
return (isPlainRecord(value) &&
|
|
379
|
+
typeof value.id === 'string' &&
|
|
380
|
+
typeof value.sessionId === 'string' &&
|
|
381
|
+
Array.isArray(value.items));
|
|
382
|
+
}
|
|
@@ -1,2 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const MAX_CONTENT_LENGTH = 20_000;
|
|
2
|
+
export function personalInstructionsForRunner(value, runner) {
|
|
3
|
+
if (value === undefined)
|
|
4
|
+
return undefined;
|
|
5
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
6
|
+
throw new Error('PERSONAL_INSTRUCTION_INVALID');
|
|
7
|
+
const record = value;
|
|
8
|
+
const instructions = {
|
|
9
|
+
common: content(record['common']),
|
|
10
|
+
codex: content(record['codex']),
|
|
11
|
+
claudeCode: content(record['claudeCode']),
|
|
12
|
+
openCode: content(record['openCode']),
|
|
13
|
+
marAgent: content(record['marAgent'])
|
|
14
|
+
};
|
|
15
|
+
const specialized = runner === 'codex'
|
|
16
|
+
? instructions.codex
|
|
17
|
+
: runner === 'claude-code'
|
|
18
|
+
? instructions.claudeCode
|
|
19
|
+
: runner === 'opencode'
|
|
20
|
+
? instructions.openCode
|
|
21
|
+
: instructions.marAgent;
|
|
22
|
+
const merged = [instructions.common, specialized].filter((item) => item.length > 0).join('\n\n');
|
|
23
|
+
return merged.length === 0 ? undefined : merged;
|
|
24
|
+
}
|
|
25
|
+
function content(value) {
|
|
26
|
+
if (value === undefined)
|
|
27
|
+
return '';
|
|
28
|
+
if (typeof value !== 'string')
|
|
29
|
+
throw new Error('PERSONAL_INSTRUCTION_INVALID');
|
|
30
|
+
const normalized = value.trim();
|
|
31
|
+
if (normalized.length > MAX_CONTENT_LENGTH)
|
|
32
|
+
throw new Error('PERSONAL_INSTRUCTION_INVALID');
|
|
33
|
+
return normalized;
|
|
34
|
+
}
|
|
@@ -1,2 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const MAX_RUNNER_ERROR_MESSAGE = 1000;
|
|
2
|
+
const MAX_RUNNER_ERROR_CODE = 80;
|
|
3
|
+
export function runnerErrorProjection(error, fallbackCode) {
|
|
4
|
+
const httpStatus = findHttpStatus(error);
|
|
5
|
+
const providerCode = findCode(error);
|
|
6
|
+
const message = findMessage(error) ?? fallbackCode;
|
|
7
|
+
return {
|
|
8
|
+
code: providerCode ?? (httpStatus === null ? fallbackCode : `HTTP_${httpStatus}`),
|
|
9
|
+
message: message.slice(0, MAX_RUNNER_ERROR_MESSAGE),
|
|
10
|
+
httpStatus
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function findCode(value, depth = 0) {
|
|
14
|
+
if (depth > 3 || value === null || typeof value !== 'object')
|
|
15
|
+
return undefined;
|
|
16
|
+
const record = value;
|
|
17
|
+
for (const key of ['error', 'data', 'response', 'cause']) {
|
|
18
|
+
const nested = findCode(record[key], depth + 1);
|
|
19
|
+
if (nested !== undefined)
|
|
20
|
+
return nested;
|
|
21
|
+
}
|
|
22
|
+
for (const key of ['code', 'errorCode', 'error_code']) {
|
|
23
|
+
const candidate = record[key];
|
|
24
|
+
if (typeof candidate === 'string' && candidate.trim())
|
|
25
|
+
return [...candidate.trim()].slice(0, MAX_RUNNER_ERROR_CODE).join('');
|
|
26
|
+
if (typeof candidate === 'number' && Number.isFinite(candidate))
|
|
27
|
+
return String(candidate);
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
function findHttpStatus(value, depth = 0) {
|
|
32
|
+
if (depth > 3 || value === null || typeof value !== 'object')
|
|
33
|
+
return null;
|
|
34
|
+
const record = value;
|
|
35
|
+
for (const key of ['status', 'statusCode', 'status_code', 'httpStatus', 'http_status']) {
|
|
36
|
+
const candidate = record[key];
|
|
37
|
+
if (((typeof candidate === 'number' && Number.isInteger(candidate)) ||
|
|
38
|
+
(typeof candidate === 'string' && /^\d{3}$/u.test(candidate))) &&
|
|
39
|
+
Number(candidate) >= 100 &&
|
|
40
|
+
Number(candidate) <= 599)
|
|
41
|
+
return Number(candidate);
|
|
42
|
+
}
|
|
43
|
+
const match = findMessage(value)?.match(/(?:^|\b(?:http(?:\s+status)?|status(?:\s+code)?|error)\s*[:=_-]?\s*)([1-5]\d{2})\b/iu);
|
|
44
|
+
if (match !== null && match !== undefined)
|
|
45
|
+
return Number(match[1]);
|
|
46
|
+
for (const key of ['error', 'cause', 'response', 'data']) {
|
|
47
|
+
const nested = findHttpStatus(record[key], depth + 1);
|
|
48
|
+
if (nested !== null)
|
|
49
|
+
return nested;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
function findMessage(value, depth = 0) {
|
|
54
|
+
if (typeof value === 'string')
|
|
55
|
+
return value.trim() || undefined;
|
|
56
|
+
if (depth > 3 || value === null || typeof value !== 'object')
|
|
57
|
+
return undefined;
|
|
58
|
+
const record = value;
|
|
59
|
+
for (const key of ['error', 'data', 'response', 'cause']) {
|
|
60
|
+
const nested = findMessage(record[key], depth + 1);
|
|
61
|
+
if (nested !== undefined)
|
|
62
|
+
return nested;
|
|
63
|
+
}
|
|
64
|
+
for (const key of ['message', 'error_description', 'detail', 'result']) {
|
|
65
|
+
const candidate = record[key];
|
|
66
|
+
if (typeof candidate === 'string' && candidate.trim())
|
|
67
|
+
return candidate.trim();
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|