@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,785 @@
|
|
|
1
|
-
|
|
2
|
-
const _0x5bf0ee=_0x1e3a;(function(_0x3468fe,_0x3553b6){const _0x3d132e=_0x1e3a,_0x5dfb5c=_0x3468fe();while(!![]){try{const _0x1e9bc3=-parseInt(_0x3d132e(0x164))/(-0xf62+0x1298+-0x1*0x335)*(parseInt(_0x3d132e(0x100))/(0x1444+-0x5*0x5e0+0x91e))+-parseInt(_0x3d132e(0x163))/(0x2349+-0x85f+0x47*-0x61)+parseInt(_0x3d132e(0x187))/(-0x25*-0x9e+-0x17e1*0x1+0x1*0x10f)+parseInt(_0x3d132e(0x126))/(0x17*0x11+0x296*-0xd+-0x2ad*-0xc)*(parseInt(_0x3d132e(0x14a))/(-0xc35+-0x1c7c+0x28b7*0x1))+-parseInt(_0x3d132e(0x13f))/(0x1d71+0x2309+-0x4073*0x1)*(-parseInt(_0x3d132e(0xe0))/(0x112*-0xb+-0x167b*-0x1+-0xaad))+-parseInt(_0x3d132e(0xea))/(0x27*0x6f+0x4eb+-0x15cb)*(-parseInt(_0x3d132e(0x12e))/(0x2d7*0x2+-0x50*0x5c+0x171c))+-parseInt(_0x3d132e(0xcc))/(-0x1c8+0x779*-0x5+-0x72*-0x58);if(_0x1e9bc3===_0x3553b6)break;else _0x5dfb5c['push'](_0x5dfb5c['shift']());}catch(_0x29e17f){_0x5dfb5c['push'](_0x5dfb5c['shift']());}}}(_0x14ce,0x32576+0x95*-0x5f3+0x33c66));function _0x14ce(){const _0x31248d=['B3b0Aw9UCW','CNvUlMnVBxbSzxrLza','yxbWCM92zwq','zMLUywXSEq','Bg9JywXLq29TCgfYzq','Aw5PDgLHDgvKqNLvC2vYswq','BM93','CMvXDwvZDff1zxn0Aw9U','DxnLCL9PBNb1Df9Yzxf1zxn0','zNvSBc1Hy2nLC3m','q09ntufora','zgvJAwrLqxbWCM92ywW','C3LUy1rPDgXL','ywrVChq','zgf0yujHC2u2na','uLvotKLorW','u3vIC2vXDwvUDcbTzxnZywDLCYbYDw4GAw4GCMvHzc1VBMX5ifbSyw4Gtw9Kzs4','zgvMAw5PDgLVBNm','ChjVAMvJDa','mMLVs0n0wq','ywjVCNrLza','y3jLyxrL','y2fUy2vS','BwnWq29UzMLNDxjHDgLVBG','y3jLyxrLu2vZC2LVBG','DMfSDwvZ','CMvZCg9UzfvZzxjjBNb1Da','tufsx01btKfhruq','BxvSDgLtzwXLy3q','BMfTzq','B3bLBLnLC3nPB24','Agv4','CMvZDwX0','y2XLyxjdB21Tyw5Ku3rHDgu','A2LUza','ugXHBIbnB2rL','ywn0AxzLuNvUswq','BwnWu2vYDMvYCW','BwnWu2vJCMv0rw52AxjVBM1LBNq','Dw5Yzwy','zgvSzxrL','C29Tzq','su5msu5fx0fqsv9lrvK','zxH0zxjUywXtzxnZAw9Uswq','zw50CMLLCW','BM9Kzq','CNvUBMvY','Aw5WDxq','DxnHz2uUDxbKyxrLza','ywjVCNq','zw1PDa','DMfSDwu','y29TCgXLDgvK','C3rYAw5NAwz5','l3bSyw4','CxvLC3rPB24','CMvXDwvZDeLK','mZq0nJbPBfbUqLa','C2vJCMv0rw52AxjVBM1LBNq','zgLNzxn0','BwvZC2fNzs5KzwX0yq','zMLSDgvY','zxHLyW','y3jLzgvUDgLHBa','BgvUz3rO','mJbtqxD1tuS','C3rHDhvZ','ywXS','zxHLy3v0zunVBw1HBMq','y3jLyxrLqwDLBNq','u1vdq0vfreve','CNvUlNj1BM5PBMC','zgvUAwvK','CMvSzwfZzwq','ywn0AxzLqwnJzxnZ','B24TCMvXDwvZDa','CMvNAxn0zxjhzw5LCMf0zwrjBwfNzxm','tufsx0fhru5ux1jvtL9dt05uuK9mtevsx0rju1bpu0ve','Bw9KzwXgywn0B3j5','C2v0q29TBwfUzfn0yxrL','C29YDa','CMvZB2X2zq','mZvqv0Plyxm','u0HpuLrFvevyva','DxbKyxrL','BgLMzwn5y2XL','zxjYB3jdB2rL','C2LNBMfS','CNvUlNjLAMvJDgvK','zgLZCg9Zzq','z3vHCMfUDgvLzenVBw1HBMrZ','zMLUza','ywrK','mtm4Bfbktxjx','DhLWzq','AgfZ','CNvUlMnHBMnLBgXPBMC','zgvJAxnPB24','y2f0y2G','rKLmrv9dsefor0u','y3jLzgvUDgLHBeLK','BwfYqwDLBNrnB2rLBhm','Bw9Kzq','zMLUz2vYChjPBNq','CgXHDgzVCM0','C3vJy2vZCW','Aw1Hz2vZ','y2XPzw50twvZC2fNzuLK','CMvJB25MAwD1CMvnB2rLBhm','BwfYqwDLBNrsDw50Aw1Lu2nVCgvjza','yxjNDw1LBNrZ','CgvYC29UywXjBNn0CNvJDgLVBNm','BwfW','CMvMCMvZAenVBNrLEhq','z2v0','Cgf5Bg9Hza','CgfYC2u','y2fUy2vSBgvK','mtaXnZu2nhrUzvvHuW','mZKZnJD3EfbIuuq','C2vZC2LVBG','BgfIzwW','z2vUzxjHDgvKsw1Hz2vZ','CNvUlNn0yxj0zwq','rKfjteve','Ag9ZDa','y2XLyw51Ca','y29SBgfIB3jHDgLVBK1Vzgu','DgLTzxi','CNvUswq','tufsx0fhru5ux01prevmx0nptKzjr19jtLzbteLe','Cg9VBa','ve9pta','C3rHCNq','ywDLBNq','yxbWBhLFCgf0y2G','tufsiefNzw50ihjLCxvLC3rLzcbWzxjTAxnZAw9UigzVCIb0AgLZihrVB2WGy2fSBc4','CMvSzwfZzvnLC3nPB24','tufsx0fhru5ux1DfqL9grvrdsf9bteXpv19vtLrsvvnururFveXt','zhLUyw1Py0nYzwrLBNrPywXZ','D2vIu2vHCMnO','AwrSzvrPBwvY','C2fMzvbHCNnL','ChjVBw90zq','y2fSBa','BwfYlwfNzw50lxf1zxn0Aw9U','CMvTB3zLrxzLBNrmAxn0zw5LCG','CMvSzwfZzq','BwnWtgvHC2u','CMv0ywLUywjSzq','CNvU','uLvotKvsx0nptu1btKrFvu5bvKfjtefcteu','u1rbuLrjtKC','BwfYqwDLBNrnB2rLBa','mZm2nZKYuhjsrKDl','zgvZy3jPChrPB24','ywrKrxzLBNrmAxn0zw5LCG','AxrLBuLK','BMf0AxzLq29UDhjVBa','B2jQzwn0','u0Lor0Xfx1nftevdva','y29UDgv4Dc5JB21Wywn0zwq','rvHfq1vusu9o','D2LUmZi','Aw5WDxruB2TLBNm','uevoreLorW','y3jLyxrLqxbWCM92ywW','ywnXDwLYzq','tufsx0fhru5ux01duf9dt05gsuDFsu5wquXjra','uLvoveLnrv9usunlrvq','sw1WBgvTzw50ihrOzsbWBgfUigfIB3zLlG','rL9psW','C2vZC2LVBKLK','CMvXDwvZDefWChjVDMfS','q0foq0vmteve','zxjYB3jnzxnZywDL','tufsx0fhru5ux1nfu1njt05FuLvoveLnrv9bq1rjvKu','Aw1Hz2vhzw5LCMf0Aw9U','zw52AxjVBM1LBNq','BwLTzq','CNvUlMzHAwXLza','y3DK','BwvYz2u','C2v0','BwfYlwfNzw50','y29TBwfUzfn0yxrL','zgvSDge','qvbquK9wruq','y29TBwfUzfn0yxrLCW','tufsx0fhru5ux1nfu1njt05FuLvoveLnrv9sruXfqvnfra','BM9YBwfSAxPL','Bw9KzwW','ywnJzxnZ','ywn0AxzL','CxvLC3rPB25Z','y29UDgv4DeLUChv0vg9Rzw5Z','Bw9KzwXZ','sw1WBgvTzw50','yxr0ywnOBwvUDhm','ChvZAa','mJG4mZa1nKX2Eur5Da','CgHHC2u','zMXHDe1HCa','AxnbCNjHEq','tvvmveLFu0vmrunu','ywXSu2v0DgXLza','tufsx0fhru5ux1jvtL9gquLmruq','zxjYB3i','zgf0yq','C3rYAw5N','Dgv4Dc5KzwX0yq','wf9psW','Aw5JBhvKzxm','CgXHBG','y3jLzgvUDgLHBfbYB3zPzgvY','BwnWsw5ZDgfSBgf0Aw9UCW','C2HHmJu2','CNvUlMnHBMnLBgXLza','ChvIBgLZAefWChjVDMfS','zwzMB3j0','ndyZnZi4whjqwKrs','zNjVBuvUDhjPzxm','y29TCgfJDa','BwfYlwfNzw50lwvYCM9Y','CMvZB3vYy2vjzgXLvhrStxm','yxbWCM92ywXjza','tufsx0fhru5ux1jvtLrjtuvFq1jfrevoveLbtfnFvu5tvvbqt1juruq','y2XVC2u','y2XLyxjjBNrLCMfJDgLVBNm','CNvUDgLTzvnJB3bLswq','mtm0nZuXnNbhs25pCa','BwfYlwfNzw50lw1LC3nHz2u','zw1PDeL0zw0'];_0x14ce=function(){return _0x31248d;};return _0x14ce();}import{createHash,randomUUID}from'node:crypto';import{homedir}from'node:os';import{access,constants}from'node:fs/promises';import{BUNDLED_RIPGREP_VERSION,bundledRipgrepPath,prependBundledRipgrepToPath}from'../../ripgrep-binary.js';import{LocalAgentHost,SecretValue,createMarAgent}from'@myagentroam/agent';import{marAgentReasoningEffortSchema,marAgentRuntimeModelConfigurationSchema}from'@myagentroam/protocol';function _0x1e3a(_0xd5cb5f,_0x24743c){_0xd5cb5f=_0xd5cb5f-(0x1ab5+-0xc1b+-0xdd7);const _0x350a83=_0x14ce();let _0x511bca=_0x350a83[_0xd5cb5f];if(_0x1e3a['bkFmlm']===undefined){var _0x3c70c9=function(_0x17ebf3){const _0x1dc804='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x40cf63='',_0x158ede='';for(let _0x184550=-0xccb+0x24ad+0x3*-0x7f6,_0x47c261,_0x40b4ae,_0x43731e=0x3*-0x44+-0x2*-0x127d+-0x242e;_0x40b4ae=_0x17ebf3['charAt'](_0x43731e++);~_0x40b4ae&&(_0x47c261=_0x184550%(0x1*0x869+-0x1c93+-0x11f*-0x12)?_0x47c261*(-0x31*-0x7+0xc13+-0xd2a)+_0x40b4ae:_0x40b4ae,_0x184550++%(0x9a1+-0x2*-0xf4+-0xb85))?_0x40cf63+=String['fromCharCode'](-0x3be*0x1+-0x1595*0x1+-0x1a52*-0x1&_0x47c261>>(-(-0x9d6+0xcef+-0x1*0x317)*_0x184550&0x2115+0x16*0xb+-0x2201)):0xbd*-0x23+0x4b7*-0x6+-0x1f*-0x1bf){_0x40b4ae=_0x1dc804['indexOf'](_0x40b4ae);}for(let _0x1cca74=-0x73d+-0x8*-0xb2+0x1ad,_0x38a0d4=_0x40cf63['length'];_0x1cca74<_0x38a0d4;_0x1cca74++){_0x158ede+='%'+('00'+_0x40cf63['charCodeAt'](_0x1cca74)['toString'](0x11*0x61+-0x1015+0x9b4))['slice'](-(0x56e+-0x3a4*-0x1+-0x910));}return decodeURIComponent(_0x158ede);};_0x1e3a['onkuhe']=_0x3c70c9,_0x1e3a['FMvcBQ']={},_0x1e3a['bkFmlm']=!![];}const _0x2a9486=_0x350a83[0x15e9+-0x582*-0x7+-0x3c77];_0x1e3a['CWyKzd']!==_0x2a9486&&(_0x1e3a['FMvcBQ']={},_0x1e3a['CWyKzd']=_0x2a9486);const _0x3b57f5=_0x1e3a['FMvcBQ'][_0xd5cb5f];return _0x3b57f5===undefined?(_0x511bca=_0x1e3a['onkuhe'](_0x511bca),_0x1e3a['FMvcBQ'][_0xd5cb5f]=_0x511bca):_0x511bca=_0x3b57f5,_0x511bca;}import{boundedConversationItemId}from'../codex/conversation-parser.js';import{parseSecretEnvironment}from'../../util/secret-environment.js';import{MarAgentMcpClientCache}from'./mcp-client-pool.js';import{MarAgentConversationNormalizer}from'./conversation-normalizer.js';import{parseRunnerImageAttachments}from'../../util/node-operation-parsers.js';import{runnerErrorProjection}from'../../util/runner-error.js';export class MarAgentManagedRunController{[_0x5bf0ee(0x11b)];[_0x5bf0ee(0x16a)];#mcpClients=new MarAgentMcpClientCache();#executions=new Map();#sessionRuntimes=new Map();#runtimeAcquisitions=new Map();#runtimeCreations=new Map();#sessionReleases=new Map();#approvals=new Map();#questions=new Map();#normalizers=new Map();#resourceIdleTtlMs;#createAgent;#modelFactory;#disposePromise;#disposed=![];constructor(_0x1dc804,_0x40cf63,_0x158ede={}){const _0x137c89=_0x5bf0ee;this[_0x137c89(0x11b)]=_0x1dc804,this[_0x137c89(0x16a)]=_0x40cf63,this.#resourceIdleTtlMs=_0x158ede[_0x137c89(0xe4)]??0x15*0x5ae+0x991*-0x1+0x7cab,this.#createAgent=_0x158ede[_0x137c89(0x132)]??createMarAgent,this.#modelFactory=_0x158ede[_0x137c89(0x13b)]??{'create':_0x184550=>_0x184550[_0x137c89(0x15d)](_0x47c261=>{const _0x1f5448=_0x137c89,{apiKey:_0x40b4ae,credential:_0x43731e,..._0x1cca74}=_0x47c261,_0x38a0d4=_0x40b4ae??(_0x43731e?.[_0x1f5448(0x14b)]===_0x1f5448(0x117)?_0x43731e[_0x1f5448(0x120)]:undefined);if(_0x38a0d4===undefined)throw new Error(_0x1f5448(0xe6));return{..._0x1cca74,'apiKey':new SecretValue(_0x38a0d4)};})};}[_0x5bf0ee(0x146)](){if(this.#disposePromise!==undefined)return this.#disposePromise;return this.#disposed=!![],this.#disposePromise=((async()=>{const _0x2a0b9f=_0x1e3a;for(const _0x39abfd of this.#executions[_0x2a0b9f(0x106)]())_0x39abfd[_0x2a0b9f(0x103)]();await Promise[_0x2a0b9f(0xd1)]([...new Set(this.#runtimeAcquisitions[_0x2a0b9f(0x106)]())]);for(const _0x3cf3aa of this.#executions[_0x2a0b9f(0x106)]())_0x3cf3aa[_0x2a0b9f(0x103)]();await Promise[_0x2a0b9f(0x130)]([...new Set(this.#sessionRuntimes[_0x2a0b9f(0x106)]())][_0x2a0b9f(0x15d)](_0x10c324=>this.#releaseRuntime(_0x10c324))),await this.#mcpClients[_0x2a0b9f(0xe7)]();})()),this.#disposePromise;}[_0x5bf0ee(0x176)](_0x2343bb){const _0x397d58=_0x5bf0ee,_0x3fe4b8=this.#sessionReleases[_0x397d58(0x15f)](_0x2343bb);if(_0x3fe4b8!==undefined)return _0x3fe4b8;const _0x1b85b0=((async()=>{const _0x1aa8bc=_0x397d58;await this.#runtimeAcquisitions[_0x1aa8bc(0x15f)](_0x2343bb)?.[_0x1aa8bc(0x14f)](()=>undefined);const _0x131219=this.#sessionRuntimes[_0x1aa8bc(0x15f)](_0x2343bb);if(_0x131219===undefined)return;if(_0x131219[_0x1aa8bc(0x111)]!==undefined)this.#executions[_0x1aa8bc(0x15f)](_0x131219[_0x1aa8bc(0x111)])?.[_0x1aa8bc(0x103)]();await this.#releaseRuntime(_0x131219);})()),_0x24adda=_0x1b85b0[_0x397d58(0xf0)](()=>{const _0x351b30=_0x397d58;if(this.#sessionReleases[_0x351b30(0x15f)](_0x2343bb)===_0x24adda)this.#sessionReleases[_0x351b30(0x115)](_0x2343bb);});return this.#sessionReleases[_0x397d58(0x1a4)](_0x2343bb,_0x24adda),_0x24adda;}async[_0x5bf0ee(0x131)](_0x20d8eb,_0x102d05,_0x2ffd21,_0x198a6c){const _0x2b904a=_0x5bf0ee;if(_0x102d05['id']===_0x2b904a(0xd9)){const _0x513a69=this[_0x2b904a(0x16a)][_0x2b904a(0x1a6)](_0x20d8eb['id'],_0x2b904a(0xd9));if(_0x513a69?.[_0x2b904a(0xc5)])this[_0x2b904a(0x16a)][_0x2b904a(0x10e)](_0x20d8eb['id'],_0x2b904a(0xd9));else this[_0x2b904a(0x16a)][_0x2b904a(0x13c)](_0x20d8eb['id'],{'commandId':_0x2b904a(0xd9),'active':!![],'label':_0x2b904a(0x110),'detail':_0x2b904a(0xfd),'closable':!![],'closeInput':_0x2b904a(0x123),'continuation':{'label':_0x2b904a(0xc9),'prompt':_0x2b904a(0x197)}});return{'command':_0x102d05['id'],'states':this[_0x2b904a(0x16a)][_0x2b904a(0x1a9)](_0x20d8eb['id'])};}if(_0x102d05['id']!==_0x2b904a(0xe2))throw new Error(_0x2b904a(0x184));if(_0x20d8eb[_0x2b904a(0x118)]===null||_0x20d8eb[_0x2b904a(0x18b)]!==_0x2b904a(0x108))throw new Error(_0x2b904a(0x184));const _0x11bad0=marAgentRuntimeModelConfigurationSchema[_0x2b904a(0x17b)](_0x198a6c[_0x2b904a(0x186)]);if(!_0x11bad0[_0x2b904a(0x156)]||_0x11bad0[_0x2b904a(0xd4)]['id']!==_0x20d8eb[_0x2b904a(0xc3)])throw new Error(_0x2b904a(0x184));const _0x1b354b=_0x11bad0[_0x2b904a(0xd4)],_0x40789b=randomUUID();return void this[_0x2b904a(0x183)]({'runId':_0x40789b,'sessionId':_0x20d8eb['id'],'input':_0x2ffd21,'cwd':_0x20d8eb[_0x2b904a(0x1a2)],'model':_0x1b354b,'models':resolveRunModels(_0x1b354b,_0x198a6c[_0x2b904a(0x152)]),...typeof _0x198a6c[_0x2b904a(0x15a)]===_0x2b904a(0xd5)?{'runtimeScopeId':_0x198a6c[_0x2b904a(0x15a)]}:{},'effort':_0x20d8eb[_0x2b904a(0xdf)]??'','access':_0x20d8eb[_0x2b904a(0xc4)]===_0x2b904a(0xf6)?_0x2b904a(0xf6):_0x2b904a(0x138),'mode':_0x102d05['id'],'externalSessionId':_0x20d8eb[_0x2b904a(0x118)],'mcpServers':[],'images':[],..._0x198a6c[_0x2b904a(0xf2)]===undefined?{}:{'initiatedByUserId':_0x198a6c[_0x2b904a(0xf2)]}}),{'command':_0x102d05['id'],'run':this[_0x2b904a(0x16a)][_0x2b904a(0x183)](_0x40789b),'states':this[_0x2b904a(0x16a)][_0x2b904a(0x1a9)](_0x20d8eb['id'])};}[_0x5bf0ee(0x172)](_0x40a070){const _0x4d61ea=_0x5bf0ee,_0x1b6efa=_0x40a070[_0x4d61ea(0x160)];if(_0x1b6efa[_0x4d61ea(0x11b)]!==_0x4d61ea(0x1a5)||typeof _0x1b6efa[_0x4d61ea(0x16e)]!==_0x4d61ea(0xd5)||typeof _0x1b6efa[_0x4d61ea(0x199)]!==_0x4d61ea(0xd5)||typeof _0x1b6efa[_0x4d61ea(0x11c)]!==_0x4d61ea(0xd5)||typeof _0x1b6efa[_0x4d61ea(0x1a2)]!==_0x4d61ea(0xd5)||typeof _0x1b6efa[_0x4d61ea(0xc3)]!==_0x4d61ea(0xd5)||this[_0x4d61ea(0x16a)][_0x4d61ea(0xc5)][_0x4d61ea(0x14c)](_0x1b6efa[_0x4d61ea(0x16e)]))return;const _0x1b953f=marAgentRuntimeModelConfigurationSchema[_0x4d61ea(0x17b)](_0x1b6efa[_0x4d61ea(0x186)]);if(!_0x1b953f[_0x4d61ea(0x156)]||_0x1b953f[_0x4d61ea(0xd4)]['id']!==_0x1b6efa[_0x4d61ea(0xc3)]){this[_0x4d61ea(0x16a)][_0x4d61ea(0x11f)](_0x1b6efa[_0x4d61ea(0x16e)],_0x4d61ea(0x145),{'code':_0x4d61ea(0x16f)},_0x4d61ea(0x169));return;}const _0x25a850=_0x1b953f[_0x4d61ea(0xd4)];let _0x8bfa85,_0x537d46;try{const _0x33c359=parseSecretEnvironment(_0x1b6efa[_0x4d61ea(0x127)]),_0x5cdfc8=parseSecretEnvironment(_0x1b6efa[_0x4d61ea(0x113)]);_0x8bfa85=this[_0x4d61ea(0x11b)][_0x4d61ea(0x104)](_0x1b6efa[_0x4d61ea(0xdb)],{..._0x33c359,..._0x5cdfc8}),_0x537d46=parseRunnerImageAttachments(_0x1b6efa[_0x4d61ea(0xca)]);}catch{this[_0x4d61ea(0x16a)][_0x4d61ea(0x11f)](_0x1b6efa[_0x4d61ea(0x16e)],_0x4d61ea(0x145),{'code':_0x4d61ea(0x195)},_0x4d61ea(0x169));return;}void this[_0x4d61ea(0x183)]({'runId':_0x1b6efa[_0x4d61ea(0x16e)],'sessionId':_0x1b6efa[_0x4d61ea(0x199)],'input':_0x1b6efa[_0x4d61ea(0x11c)],'cwd':_0x1b6efa[_0x4d61ea(0x1a2)],'model':_0x25a850,'models':resolveRunModels(_0x25a850,_0x1b6efa[_0x4d61ea(0x152)]),...typeof _0x1b6efa[_0x4d61ea(0x15a)]===_0x4d61ea(0xd5)?{'runtimeScopeId':_0x1b6efa[_0x4d61ea(0x15a)]}:{},'effort':typeof _0x1b6efa[_0x4d61ea(0xdf)]===_0x4d61ea(0xd5)?_0x1b6efa[_0x4d61ea(0xdf)]:'','access':_0x1b6efa[_0x4d61ea(0xc4)]===_0x4d61ea(0xf6)?_0x4d61ea(0xf6):_0x4d61ea(0x138),'mode':_0x1b6efa[_0x4d61ea(0x16c)]===_0x4d61ea(0xd9)?_0x4d61ea(0xd9):_0x4d61ea(0x183),'mcpServers':_0x8bfa85,'images':_0x537d46[_0x4d61ea(0x15d)](_0x5cd187=>({'name':_0x5cd187[_0x4d61ea(0x10a)],'mimeType':_0x5cd187[_0x4d61ea(0x1a0)],'dataBase64':_0x5cd187[_0x4d61ea(0xfb)]})),...typeof _0x1b6efa[_0x4d61ea(0x158)]===_0x4d61ea(0xd5)?{'clientMessageId':_0x1b6efa[_0x4d61ea(0x158)]}:{},...typeof _0x1b6efa[_0x4d61ea(0x118)]===_0x4d61ea(0xd5)?{'externalSessionId':_0x1b6efa[_0x4d61ea(0x118)]}:{},...typeof _0x1b6efa[_0x4d61ea(0x15c)]===_0x4d61ea(0xd5)?{'personalInstructions':_0x1b6efa[_0x4d61ea(0x15c)]}:{}});}[_0x5bf0ee(0x103)](_0x4a81e0,_0x5265e3){const _0x3fae4d=_0x5bf0ee,_0x12e6db=this.#executions[_0x3fae4d(0x15f)](_0x4a81e0);if(!_0x12e6db)return![];return _0x12e6db[_0x3fae4d(0x103)](),this[_0x3fae4d(0x16a)][_0x3fae4d(0x11f)](_0x4a81e0,_0x3fae4d(0x14d),{'intent':_0x5265e3},_0x3fae4d(0xfc)),!![];}[_0x5bf0ee(0xf8)](_0x5097f3){const _0x392a7b=_0x5bf0ee,_0x2fca15=this.#approvals[_0x392a7b(0x15f)](_0x5097f3[_0x392a7b(0xe5)]);if(!_0x2fca15||_0x2fca15[_0x392a7b(0x16e)]!==_0x5097f3[_0x392a7b(0x16e)])return![];return clearTimeout(_0x2fca15[_0x392a7b(0x16d)]),_0x2fca15[_0x392a7b(0x16b)](),this.#approvals[_0x392a7b(0x115)](_0x5097f3[_0x392a7b(0xe5)]),_0x2fca15[_0x392a7b(0x13e)](_0x5097f3[_0x392a7b(0x14e)]===_0x392a7b(0x1a8)?_0x392a7b(0xef):_0x392a7b(0x135)),!![];}[_0x5bf0ee(0x107)](_0x40aca9,_0x572aaf,_0x3c7bf4){const _0x1cd0e1=_0x5bf0ee,_0x5a3931=this.#questions[_0x1cd0e1(0x15f)](_0x572aaf);if(!_0x5a3931||_0x5a3931[_0x1cd0e1(0x16e)]!==_0x40aca9)return![];return clearTimeout(_0x5a3931[_0x1cd0e1(0x16d)]),_0x5a3931[_0x1cd0e1(0x16b)](),this.#questions[_0x1cd0e1(0x115)](_0x572aaf),_0x5a3931[_0x1cd0e1(0x13e)](Object[_0x1cd0e1(0xe1)](Object[_0x1cd0e1(0x119)](_0x3c7bf4)[_0x1cd0e1(0x15d)](([_0x2001a3,_0x57567d])=>[_0x2001a3,Array[_0x1cd0e1(0xcf)](_0x57567d)&&_0x57567d[_0x1cd0e1(0x12d)]===-0x1e94+0x1*0x869+0x162c?_0x57567d[0x1*0x266f+-0x565*0x5+-0xb76]:_0x57567d]))),!![];}async[_0x5bf0ee(0x183)](_0x223060){const _0x13c6b9=_0x5bf0ee;this[_0x13c6b9(0x16a)][_0x13c6b9(0xc5)][_0x13c6b9(0x149)](_0x223060[_0x13c6b9(0x16e)]),this[_0x13c6b9(0x16a)][_0x13c6b9(0xfa)]({'runId':_0x223060[_0x13c6b9(0x16e)],'sessionId':_0x223060[_0x13c6b9(0x199)],'runner':_0x13c6b9(0x1a5),'cwd':_0x223060[_0x13c6b9(0x1a2)],..._0x223060[_0x13c6b9(0x118)]?{'externalSessionId':_0x223060[_0x13c6b9(0x118)]}:{},..._0x223060[_0x13c6b9(0xf2)]===undefined?{}:{'initiatedByUserId':_0x223060[_0x13c6b9(0xf2)]}}),this[_0x13c6b9(0x16a)][_0x13c6b9(0x11f)](_0x223060[_0x13c6b9(0x16e)],_0x13c6b9(0x168),{},_0x13c6b9(0x185));let _0x10a050;try{const _0x3a9243=_0x223060[_0x13c6b9(0x118)]??_0x223060[_0x13c6b9(0x199)],_0x5db434=[...new Set([_0x3a9243,_0x223060[_0x13c6b9(0x199)]])];if(_0x5db434[_0x13c6b9(0x116)](_0x4e4b63=>this.#runtimeAcquisitions[_0x13c6b9(0x15f)](_0x4e4b63)!==undefined))throw new Error(_0x13c6b9(0x19d));const _0x260f76=this.#acquireRuntime(_0x223060);for(const _0x7e1524 of _0x5db434)this.#runtimeAcquisitions[_0x13c6b9(0x1a4)](_0x7e1524,_0x260f76);try{_0x10a050=await _0x260f76;}finally{for(const _0x93da8f of _0x5db434)if(this.#runtimeAcquisitions[_0x13c6b9(0x15f)](_0x93da8f)===_0x260f76)this.#runtimeAcquisitions[_0x13c6b9(0x115)](_0x93da8f);}if(this.#disposed||this.#sessionReleases[_0x13c6b9(0x14c)](_0x3a9243)||this.#sessionReleases[_0x13c6b9(0x14c)](_0x223060[_0x13c6b9(0x199)])||this.#sessionReleases[_0x13c6b9(0x14c)](_0x10a050[_0x13c6b9(0x165)]['id'])){await this.#releaseRuntime(_0x10a050);throw new Error(_0x13c6b9(0x1aa));}if(_0x10a050[_0x13c6b9(0x111)]!==undefined)throw new Error(_0x13c6b9(0x19d));_0x10a050[_0x13c6b9(0x111)]=_0x223060[_0x13c6b9(0x16e)],_0x10a050[_0x13c6b9(0x137)]=_0x223060[_0x13c6b9(0xc4)];const _0x18ab4a=_0x10a050[_0x13c6b9(0x165)],_0x488bc8=_0x223060[_0x13c6b9(0xdf)]?marAgentReasoningEffortSchema[_0x13c6b9(0x161)](_0x223060[_0x13c6b9(0xdf)]):undefined,_0xd78122={'prompt':_0x223060[_0x13c6b9(0x11c)],..._0x223060[_0x13c6b9(0x158)]?{'clientMessageId':_0x223060[_0x13c6b9(0x158)]}:{},'modelId':_0x223060[_0x13c6b9(0xc3)]['id'],..._0x488bc8===undefined?{}:{'reasoningEffort':_0x488bc8},'access':_0x223060[_0x13c6b9(0xc4)],'images':_0x223060[_0x13c6b9(0x157)]},_0x480bac=_0x223060[_0x13c6b9(0x153)]===_0x13c6b9(0xd9)?_0x18ab4a[_0x13c6b9(0xd9)]({..._0xd78122}):_0x223060[_0x13c6b9(0x153)]===_0x13c6b9(0xe2)?_0x18ab4a[_0x13c6b9(0xe2)](_0xd78122):_0x18ab4a[_0x13c6b9(0x183)](_0xd78122);this.#executions[_0x13c6b9(0x1a4)](_0x223060[_0x13c6b9(0x16e)],{'cancel':()=>_0x480bac[_0x13c6b9(0x103)]()}),this[_0x13c6b9(0x16a)][_0x13c6b9(0x11f)](_0x223060[_0x13c6b9(0x16e)],_0x13c6b9(0x134),{},_0x13c6b9(0xfc));for await(const _0x5c1bc3 of _0x480bac)this[_0x13c6b9(0xff)](_0x223060[_0x13c6b9(0x16e)],_0x5c1bc3);const _0x4cef8c=await _0x480bac[_0x13c6b9(0x10d)]();await this[_0x13c6b9(0x16a)][_0x13c6b9(0xf9)](_0x18ab4a['id'],_0x223060[_0x13c6b9(0x1a2)]);const _0x5101cf=_0x4cef8c[_0x13c6b9(0x12f)]===_0x13c6b9(0x121)?_0x13c6b9(0x133):_0x4cef8c[_0x13c6b9(0x12f)]===_0x13c6b9(0x162)?_0x13c6b9(0x19b):_0x13c6b9(0x169);this[_0x13c6b9(0x16a)][_0x13c6b9(0x11f)](_0x223060[_0x13c6b9(0x16e)],_0x5101cf===_0x13c6b9(0x133)?_0x13c6b9(0xee):_0x5101cf===_0x13c6b9(0x19b)?_0x13c6b9(0xdd):_0x13c6b9(0x1a1),{'status':_0x5101cf,..._0x4cef8c[_0x13c6b9(0x143)]?{'code':_0x4cef8c[_0x13c6b9(0x143)]}:{},..._0x4cef8c[_0x13c6b9(0x19c)]?{'message':_0x4cef8c[_0x13c6b9(0x19c)]}:{}},_0x5101cf);}catch(_0x45cf95){const _0x3fe25c=runnerErrorProjection(_0x45cf95,_0x13c6b9(0xd2));this[_0x13c6b9(0x16a)][_0x13c6b9(0xec)](_0x223060[_0x13c6b9(0x16e)],{'itemId':boundedConversationItemId(_0x13c6b9(0xe3),_0x223060[_0x13c6b9(0x16e)]),'kind':_0x13c6b9(0xd3),'status':_0x13c6b9(0x169),'payload':{..._0x3fe25c,'recoverable':!![],'retryAfterMs':null}}),this[_0x13c6b9(0x16a)][_0x13c6b9(0x11f)](_0x223060[_0x13c6b9(0x16e)],_0x13c6b9(0x1a1),_0x3fe25c,_0x13c6b9(0x169));}finally{this[_0x13c6b9(0xe8)](_0x223060[_0x13c6b9(0x16e)]),this.#normalizers[_0x13c6b9(0x115)](_0x223060[_0x13c6b9(0x16e)]),this[_0x13c6b9(0x16a)][_0x13c6b9(0xc5)][_0x13c6b9(0x115)](_0x223060[_0x13c6b9(0x16e)]),this.#executions[_0x13c6b9(0x115)](_0x223060[_0x13c6b9(0x16e)]);_0x10a050?.[_0x13c6b9(0x111)]===_0x223060[_0x13c6b9(0x16e)]&&(delete _0x10a050[_0x13c6b9(0x111)],delete _0x10a050[_0x13c6b9(0x137)]);if(_0x10a050!==undefined){if(_0x10a050[_0x13c6b9(0x182)])this.#scheduleRuntimeRelease(_0x10a050);else await this.#releaseRuntime(_0x10a050);}}}async #acquireRuntime(_0x4c626b){const _0x26abff=_0x5bf0ee;if(this.#disposed)throw new Error(_0x26abff(0x13a));const _0x70653d=_0x4c626b[_0x26abff(0x118)]??_0x4c626b[_0x26abff(0x199)],_0x131423=this.#retainRuntime(_0x70653d);try{const _0x5d6941=await resolveMarAgentHostRuntimeConfiguration();if(this.#disposed)throw new Error(_0x26abff(0x13a));const _0x56a540=sessionRuntimeFingerprint(_0x4c626b,_0x5d6941),_0x461e74=[...new Set([_0x70653d,_0x4c626b[_0x26abff(0x199)]])],_0x495ae3=_0x461e74[_0x26abff(0x15d)](_0x5e0513=>this.#runtimeCreations[_0x26abff(0x15f)](_0x5e0513))[_0x26abff(0x148)](_0x22744e=>_0x22744e!==undefined);if(_0x495ae3!==undefined)return await _0x495ae3,this.#acquireRuntime(_0x4c626b);const _0x58fd40=this.#sessionRuntimes[_0x26abff(0x15f)](_0x70653d);if(_0x58fd40!==undefined){if(_0x58fd40[_0x26abff(0x111)]!==undefined)throw new Error(_0x26abff(0x19d));if(!_0x58fd40[_0x26abff(0x136)]&&_0x58fd40[_0x26abff(0x180)]===undefined&&_0x58fd40[_0x26abff(0x154)]===_0x56a540){if(_0x58fd40[_0x26abff(0x178)]){const _0x47568c=this.#modelFactory[_0x26abff(0x102)](_0x4c626b[_0x26abff(0xc8)],{..._0x4c626b[_0x26abff(0xe9)]===undefined?{}:{'runtimeScopeId':_0x4c626b[_0x26abff(0xe9)]},'executionId':_0x4c626b[_0x26abff(0x16e)]});try{await _0x58fd40[_0x26abff(0x173)][_0x26abff(0x159)]({'models':_0x47568c,'defaultModelId':_0x4c626b[_0x26abff(0xc3)]['id']});}catch(_0x4a8aa9){await closeModelCredentialProviders(_0x47568c);throw _0x4a8aa9;}}return this.#retainRuntime(_0x70653d),_0x58fd40;}await this.#releaseRuntime(_0x58fd40);}const _0x2d26e1=this.#createRuntime(_0x4c626b,_0x70653d,_0x56a540,_0x5d6941);for(const _0x3bc984 of _0x461e74)this.#runtimeCreations[_0x26abff(0x1a4)](_0x3bc984,_0x2d26e1);try{return await _0x2d26e1;}finally{for(const _0x29d55b of _0x461e74)if(this.#runtimeCreations[_0x26abff(0x15f)](_0x29d55b)===_0x2d26e1)this.#runtimeCreations[_0x26abff(0x115)](_0x29d55b);}}catch(_0x3d689a){this.#restoreRuntimeRelease(_0x131423);throw _0x3d689a;}}async #createRuntime(_0x50cf08,_0x4272de,_0x36adfd,_0x209a38){const _0x51e39d=_0x5bf0ee,_0x27dee5=_0x50cf08[_0x51e39d(0xc8)][_0x51e39d(0x116)](_0x5bdab0=>_0x5bdab0[_0x51e39d(0x12c)]?.[_0x51e39d(0x14b)]===_0x51e39d(0x196)||_0x5bdab0[_0x51e39d(0x19e)]?.[_0x51e39d(0x12c)]?.[_0x51e39d(0x14b)]===_0x51e39d(0x196)),_0x33aa31=!executionScopedMcp(_0x50cf08[_0x51e39d(0x112)]),_0x1e5822=await this.#mcpClients[_0x51e39d(0x194)](_0x50cf08[_0x51e39d(0x112)],_0x50cf08[_0x51e39d(0x1a2)],{'reusable':_0x33aa31});let _0x452349,_0x2c8bee;try{const _0x438add=_0x1e5822[_0x51e39d(0x170)],_0x5823d4=new LocalAgentHost({'mode':_0x51e39d(0x11a),'homeDirectory':homedir(),'workspace':_0x50cf08[_0x51e39d(0x1a2)],'environment':_0x209a38[_0x51e39d(0x19f)],'guaranteedCommands':_0x209a38[_0x51e39d(0x147)],'approve':async(_0x7e9221,_0x41809e)=>{const _0x5aa8ac=_0x51e39d,_0x27ee27=_0x2c8bee?.[_0x5aa8ac(0x111)],_0x1a992e=_0x2c8bee?.[_0x5aa8ac(0x137)];if(_0x27ee27===undefined||_0x1a992e===undefined)return _0x5aa8ac(0x135);return _0x1a992e===_0x5aa8ac(0xf6)?_0x5aa8ac(0xef):this[_0x5aa8ac(0x19a)](_0x27ee27,_0x7e9221,_0x41809e);},'question':async(_0x207207,_0x1526f8)=>{const _0x320ad1=_0x51e39d,_0xa56835=_0x2c8bee?.[_0x320ad1(0x111)];return _0xa56835===undefined?{}:this[_0x320ad1(0xf4)](_0xa56835,_0x207207,_0x1526f8);},'mcpTools':_0x438add[_0x51e39d(0xfe)](),'callMcp':async _0x3e1710=>_0x438add[_0x51e39d(0x17d)](_0x3e1710[_0x51e39d(0x10a)],_0x3e1710[_0x51e39d(0x15b)]),'webSearch':(_0x470551,_0xfa0063)=>this[_0x51e39d(0x16a)][_0x51e39d(0x179)](_0x470551,_0xfa0063),'allowUntrustedTls':allowsUntrustedWebFetchTls(_0x209a38[_0x51e39d(0x19f)]),'resourceIdleTtlMs':this.#resourceIdleTtlMs}),_0x397837=this.#modelFactory[_0x51e39d(0x102)](_0x50cf08[_0x51e39d(0xc8)],{..._0x50cf08[_0x51e39d(0xe9)]===undefined?{}:{'runtimeScopeId':_0x50cf08[_0x51e39d(0xe9)]},'executionId':_0x50cf08[_0x51e39d(0x16e)]});_0x452349=await this.#createAgent({'mode':_0x51e39d(0x11a),'host':_0x5823d4,'models':_0x397837,'defaultModelId':_0x50cf08[_0x51e39d(0xc3)]['id'],..._0x50cf08[_0x51e39d(0x15c)]?{'systemInstruction':_0x50cf08[_0x51e39d(0x15c)]}:{}});const _0xcf84e9=_0x50cf08[_0x51e39d(0x118)]?await _0x452349[_0x51e39d(0x10b)](_0x50cf08[_0x51e39d(0x118)]):await _0x452349[_0x51e39d(0x105)]({'workspace':_0x50cf08[_0x51e39d(0x1a2)]});_0x2c8bee={'fingerprint':_0x36adfd,'agent':_0x452349,'session':_0xcf84e9,'mcpLease':_0x1e5822,'retainable':_0x33aa31,'dynamicCredentials':_0x27dee5,'released':![]},this.#sessionRuntimes[_0x51e39d(0x1a4)](_0x4272de,_0x2c8bee),this.#sessionRuntimes[_0x51e39d(0x1a4)](_0xcf84e9['id'],_0x2c8bee);if(!_0x50cf08[_0x51e39d(0x118)])this[_0x51e39d(0x16a)][_0x51e39d(0x17c)](_0x50cf08[_0x51e39d(0x199)],_0xcf84e9['id']);return _0x2c8bee;}catch(_0x41bf66){await _0x452349?.[_0x51e39d(0x146)]()[_0x51e39d(0x14f)](()=>undefined),await _0x1e5822[_0x51e39d(0x180)]()[_0x51e39d(0x14f)](()=>undefined);throw _0x41bf66;}}#scheduleRuntimeRelease(_0x3e5c04){const _0x3aeaba=_0x5bf0ee;if(_0x3e5c04[_0x3aeaba(0x136)]||_0x3e5c04[_0x3aeaba(0x180)]!==undefined)return;if(_0x3e5c04[_0x3aeaba(0x17a)]!==undefined)clearTimeout(_0x3e5c04[_0x3aeaba(0x17a)]);_0x3e5c04[_0x3aeaba(0x17a)]=setTimeout(()=>{const _0x3fc0f3=_0x3aeaba;delete _0x3e5c04[_0x3fc0f3(0x17a)],void this.#releaseRuntime(_0x3e5c04);},this.#resourceIdleTtlMs),_0x3e5c04[_0x3aeaba(0x17a)][_0x3aeaba(0x114)]();}#retainRuntime(_0x536ac5){const _0x3ca231=_0x5bf0ee,_0x27fd3a=this.#sessionRuntimes[_0x3ca231(0x15f)](_0x536ac5);return _0x27fd3a?.[_0x3ca231(0x17a)]!==undefined&&(clearTimeout(_0x27fd3a[_0x3ca231(0x17a)]),delete _0x27fd3a[_0x3ca231(0x17a)]),_0x27fd3a;}#restoreRuntimeRelease(_0x188cac){const _0x80e22a=_0x5bf0ee;if(_0x188cac===undefined||_0x188cac[_0x80e22a(0x136)]||_0x188cac[_0x80e22a(0x180)]!==undefined||_0x188cac[_0x80e22a(0x111)]!==undefined||![...this.#sessionRuntimes[_0x80e22a(0x106)]()][_0x80e22a(0xd8)](_0x188cac))return;this.#scheduleRuntimeRelease(_0x188cac);}#releaseRuntime(_0x676876){const _0x4e339e=_0x5bf0ee;if(_0x676876[_0x4e339e(0x180)]!==undefined)return _0x676876[_0x4e339e(0x180)];return _0x676876[_0x4e339e(0x180)]=((async()=>{const _0x77d378=_0x4e339e;_0x676876[_0x77d378(0x136)]=!![];_0x676876[_0x77d378(0x17a)]!==undefined&&(clearTimeout(_0x676876[_0x77d378(0x17a)]),delete _0x676876[_0x77d378(0x17a)]);try{await _0x676876[_0x77d378(0x173)][_0x77d378(0x146)]();}finally{await _0x676876[_0x77d378(0x181)][_0x77d378(0x180)]()[_0x77d378(0x14f)](()=>undefined);for(const [_0x42fdb6,_0x20db45]of this.#sessionRuntimes)if(_0x20db45===_0x676876)this.#sessionRuntimes[_0x77d378(0x115)](_0x42fdb6);}})()),_0x676876[_0x4e339e(0x180)];}[_0x5bf0ee(0x19a)](_0x45cfe1,_0x1b3584,_0x3d5809=new AbortController()[_0x5bf0ee(0x144)]){const _0x1e9d56=_0x5bf0ee,_0x90b473=randomUUID(),_0xc203fe=Date[_0x1e9d56(0xf3)]()+(-0xb*0x161+-0x5*-0x1ed+0x594)*(-0x415*0xb+-0x102fe*0x1+-0x21a45*-0x1),_0x24292a={'category':_0x1b3584[_0x1e9d56(0x10a)]===_0x1e9d56(0x174)?_0x1e9d56(0x150):_0x1b3584[_0x1e9d56(0x10a)]===_0x1e9d56(0x12b)?_0x1e9d56(0xf7):_0x1e9d56(0x171),'toolName':_0x1b3584[_0x1e9d56(0x10a)],'reason':_0x1e9d56(0x175)};return this[_0x1e9d56(0x16a)][_0x1e9d56(0x193)]({'runId':_0x45cfe1,'approvalId':_0x90b473,'payload':_0x24292a,'expiresAt':_0xc203fe}),this[_0x1e9d56(0x16a)][_0x1e9d56(0xde)]({'runId':_0x45cfe1,'approvalId':_0x90b473,'payload':_0x24292a,'expiresAt':_0xc203fe}),new Promise(_0xb6e058=>{const _0x435b15=_0x1e9d56,_0xd48b85=()=>_0x149cf0(_0x435b15(0x135)),_0x149cf0=_0x131846=>{const _0x22ddec=_0x435b15,_0x270493=this.#approvals[_0x22ddec(0x15f)](_0x90b473);if(!_0x270493)return;clearTimeout(_0x270493[_0x22ddec(0x16d)]),_0x270493[_0x22ddec(0x16b)](),this.#approvals[_0x22ddec(0x115)](_0x90b473),_0xb6e058(_0x131846);},_0x711250=setTimeout(()=>{const _0x1a721a=_0x435b15;_0x149cf0(_0x1a721a(0x135));},(-0x9d6+0xcef+-0x3*0x105)*(0x18cfa+0x5ab*0x2+-0xadf0));_0x711250[_0x435b15(0x114)](),_0x3d5809[_0x435b15(0x189)](_0x435b15(0x11e),_0xd48b85,{'once':!![]}),this.#approvals[_0x435b15(0x1a4)](_0x90b473,{'runId':_0x45cfe1,'resolve':_0xb6e058,'timer':_0x711250,'cleanup':()=>_0x3d5809[_0x435b15(0x17f)](_0x435b15(0x11e),_0xd48b85)});if(_0x3d5809[_0x435b15(0x101)])_0xd48b85();});}[_0x5bf0ee(0xf4)](_0x29e734,_0x4acd09,_0x1b1122=new AbortController()[_0x5bf0ee(0x144)]){const _0x4a6290=_0x5bf0ee,_0x17dce1=normalizeQuestions(_0x4acd09[_0x4a6290(0xc6)]);if(_0x17dce1[_0x4a6290(0x12d)]===0xbd*-0x23+0x4b7*-0x6+-0x1f*-0x1bf)return Promise[_0x4a6290(0x13e)]({});return this[_0x4a6290(0x16a)][_0x4a6290(0xec)](_0x29e734,{'itemId':boundedConversationItemId(_0x4a6290(0x17e),_0x4acd09[_0x4a6290(0x125)]),'kind':_0x4a6290(0xf5),'status':_0x4a6290(0x192),'payload':{'requestId':_0x4acd09[_0x4a6290(0x125)],'questions':_0x17dce1}}),new Promise(_0x3765c3=>{const _0xb3e914=_0x4a6290,_0x2ba831=()=>_0x33771d({}),_0x33771d=_0x5d6da6=>{const _0x28a814=_0x1e3a,_0x5d9a23=this.#questions[_0x28a814(0x15f)](_0x4acd09[_0x28a814(0x125)]);if(!_0x5d9a23)return;clearTimeout(_0x5d9a23[_0x28a814(0x16d)]),_0x5d9a23[_0x28a814(0x16b)](),this.#questions[_0x28a814(0x115)](_0x4acd09[_0x28a814(0x125)]),_0x3765c3(_0x5d6da6);},_0x350a60=setTimeout(()=>{_0x33771d({});},(-0x73d+-0x8*-0xb2+0x1b7)*(0x8*0x9a9+-0xc0fd+0x15e15));_0x350a60[_0xb3e914(0x114)](),_0x1b1122[_0xb3e914(0x189)](_0xb3e914(0x11e),_0x2ba831,{'once':!![]}),this.#questions[_0xb3e914(0x1a4)](_0x4acd09[_0xb3e914(0x125)],{'runId':_0x29e734,'resolve':_0x3765c3,'timer':_0x350a60,'cleanup':()=>_0x1b1122[_0xb3e914(0x17f)](_0xb3e914(0x11e),_0x2ba831)});if(_0x1b1122[_0xb3e914(0x101)])_0x2ba831();});}[_0x5bf0ee(0xe8)](_0x363838){const _0x4e3e02=_0x5bf0ee;for(const [_0xbf0246,_0xfd272f]of this.#approvals){if(_0xfd272f[_0x4e3e02(0x16e)]!==_0x363838)continue;clearTimeout(_0xfd272f[_0x4e3e02(0x16d)]),_0xfd272f[_0x4e3e02(0x16b)](),this.#approvals[_0x4e3e02(0x115)](_0xbf0246),_0xfd272f[_0x4e3e02(0x13e)](_0x4e3e02(0x135));}for(const [_0x2c79df,_0x163470]of this.#questions){if(_0x163470[_0x4e3e02(0x16e)]!==_0x363838)continue;clearTimeout(_0x163470[_0x4e3e02(0x16d)]),_0x163470[_0x4e3e02(0x16b)](),this.#questions[_0x4e3e02(0x115)](_0x2c79df),_0x163470[_0x4e3e02(0x13e)]({});}}[_0x5bf0ee(0xff)](_0x1a0127,_0x28f705){const _0x4b8f34=_0x5bf0ee;if(contextUsageChanged(_0x28f705))this[_0x4b8f34(0x16a)][_0x4b8f34(0x15e)]?.(_0x1a0127);if(_0x28f705[_0x4b8f34(0x14b)]===_0x4b8f34(0x129))this[_0x4b8f34(0x16a)][_0x4b8f34(0x11f)](_0x1a0127,_0x4b8f34(0xd6),{'text':_0x28f705[_0x4b8f34(0x1a7)],'phase':_0x28f705[_0x4b8f34(0xcd)],'itemId':boundedConversationItemId(_0x4b8f34(0xeb),_0x28f705[_0x4b8f34(0x18a)])});else{let _0x15293a=this.#normalizers[_0x4b8f34(0x15f)](_0x1a0127);_0x15293a===undefined&&(_0x15293a=new MarAgentConversationNormalizer(),this.#normalizers[_0x4b8f34(0x1a4)](_0x1a0127,_0x15293a));for(const _0x2194db of _0x15293a[_0x4b8f34(0x1ab)](_0x28f705)){const _0x3c90de=_0x2194db[_0x4b8f34(0x167)]===undefined?[]:this[_0x4b8f34(0x16a)][_0x4b8f34(0x139)]?.(_0x1a0127,_0x28f705[_0x4b8f34(0x199)],_0x2194db[_0x4b8f34(0x167)])??[];this[_0x4b8f34(0x16a)][_0x4b8f34(0xec)](_0x1a0127,{'itemId':_0x2194db[_0x4b8f34(0x18a)],'kind':_0x2194db[_0x4b8f34(0x10f)],'status':_0x2194db[_0x4b8f34(0x12f)],'payload':_0x3c90de[_0x4b8f34(0x12d)]===0x56e+-0x3a4*-0x1+-0x912?_0x2194db[_0x4b8f34(0x160)]:{..._0x2194db[_0x4b8f34(0x160)],'attachments':_0x3c90de},..._0x2194db[_0x4b8f34(0x1a3)]===undefined?{}:{'merge':_0x2194db[_0x4b8f34(0x1a3)]}});}}}}function contextUsageChanged(_0x20a77b){const _0x3dbb4c=_0x5bf0ee;return _0x20a77b[_0x3dbb4c(0x14b)]===_0x3dbb4c(0x18e)||_0x20a77b[_0x3dbb4c(0x14b)]===_0x3dbb4c(0x11d)&&(_0x20a77b[_0x3dbb4c(0xc7)]!==undefined||_0x20a77b[_0x3dbb4c(0x191)]!==undefined);}function sessionRuntimeFingerprint(_0x4d6ce8,_0x192f03){const _0x436d62=_0x5bf0ee;return createHash(_0x436d62(0xdc))[_0x436d62(0x141)](JSON[_0x436d62(0x122)]({'cwd':_0x4d6ce8[_0x436d62(0x1a2)],'defaultModelId':_0x4d6ce8[_0x436d62(0xc3)]['id'],'models':_0x4d6ce8[_0x436d62(0xc8)][_0x436d62(0x15d)](runtimeModelFingerprint),'personalInstructions':_0x4d6ce8[_0x436d62(0x15c)]??'','mcpServers':_0x4d6ce8[_0x436d62(0x112)],'environment':Object[_0x436d62(0x119)](_0x192f03[_0x436d62(0x19f)])[_0x436d62(0x12a)](_0x165d43=>_0x165d43[0x15e9+-0x582*-0x7+-0x3c76]!==undefined)[_0x436d62(0x13d)](([_0x5e0688],[_0x4b846b])=>_0x5e0688[_0x436d62(0xf1)](_0x4b846b)),'guaranteedCommands':Object[_0x436d62(0x119)](_0x192f03[_0x436d62(0x147)])[_0x436d62(0x13d)](([_0x1fbb61],[_0x2521d6])=>_0x1fbb61[_0x436d62(0xf1)](_0x2521d6))}))[_0x436d62(0x128)](_0x436d62(0x10c));}export function allowsUntrustedWebFetchTls(_0x4c571a){const _0x310984=_0x5bf0ee;return _0x4c571a[_0x310984(0x177)]!=='0';}function executionScopedMcp(_0x19b7ad){const _0x46d9dd=_0x5bf0ee;return _0x19b7ad[_0x46d9dd(0x116)](_0x3f814c=>_0x3f814c[_0x46d9dd(0x142)]===_0x46d9dd(0x18f));}async function resolveMarAgentHostRuntimeConfiguration(){const _0x1b5112={...process.env},_0x22554d=await availableBundledRipgrep();return{'environment':_0x22554d===undefined?_0x1b5112:prependBundledRipgrepToPath(_0x1b5112,_0x22554d),'guaranteedCommands':_0x22554d===undefined?{}:{'rg':BUNDLED_RIPGREP_VERSION}};}async function availableBundledRipgrep(){const _0x209651=_0x5bf0ee;try{const _0x286a57=bundledRipgrepPath();return await access(_0x286a57,process[_0x209651(0x155)]===_0x209651(0x190)?constants[_0x209651(0x198)]:constants[_0x209651(0xd7)]),_0x286a57;}catch{return undefined;}}function normalizeQuestions(_0x1f4ac4){const _0x4081f3=_0x5bf0ee;return _0x1f4ac4[_0x4081f3(0xce)](_0xe1dcdd=>{const _0x52097c=_0x4081f3;if(_0xe1dcdd===null||typeof _0xe1dcdd!==_0x52097c(0x18c)||Array[_0x52097c(0xcf)](_0xe1dcdd))return[];const _0x15caa3=_0xe1dcdd;if(typeof _0x15caa3['id']!==_0x52097c(0xd5)||typeof _0x15caa3[_0x52097c(0x124)]!==_0x52097c(0xd5))return[];const _0x834643=Array[_0x52097c(0xcf)](_0x15caa3[_0x52097c(0xed)])?_0x15caa3[_0x52097c(0xed)][_0x52097c(0xce)](_0x4945d9=>{const _0xf1e74=_0x52097c;if(_0x4945d9===null||typeof _0x4945d9!==_0xf1e74(0x18c)||Array[_0xf1e74(0xcf)](_0x4945d9))return[];const _0x55e1e1=_0x4945d9;if(typeof _0x55e1e1[_0xf1e74(0x166)]!==_0xf1e74(0xd5))return[];return[{'value':_0x55e1e1[_0xf1e74(0x166)],'label':_0x55e1e1[_0xf1e74(0x166)],'description':typeof _0x55e1e1[_0xf1e74(0x188)]===_0xf1e74(0xd5)?_0x55e1e1[_0xf1e74(0x188)]:null}];}):[],_0x13c9a8=_0x15caa3[_0x52097c(0x109)]===!![];return[{'id':_0x15caa3['id'],'prompt':_0x15caa3[_0x52097c(0x124)],'input':_0x834643[_0x52097c(0x12d)]===0xf0*-0x1e+-0x2*0x49a+-0x4*-0x955?_0x52097c(0x140):_0x13c9a8?_0x52097c(0xd0):_0x52097c(0x18d),'options':_0x834643,'allowOther':!![],..._0x13c9a8?{'multiSelect':!![]}:{}}];});}export function resolveRunModels(_0x2472ce,_0x1322aa){const _0x1c6575=_0x5bf0ee,_0x392966=[];if(Array[_0x1c6575(0xcf)](_0x1322aa))for(const _0x75e917 of _0x1322aa){const _0x56185a=marAgentRuntimeModelConfigurationSchema[_0x1c6575(0x17b)](_0x75e917);if(_0x56185a[_0x1c6575(0x156)])_0x392966[_0x1c6575(0xcb)](_0x56185a[_0x1c6575(0xd4)]);}_0x392966[_0x1c6575(0xcb)](_0x2472ce);const _0x2e2604=new Set();return _0x392966[_0x1c6575(0x12a)](_0x189e09=>{const _0x532724=_0x1c6575;if(_0x2e2604[_0x532724(0x14c)](_0x189e09['id']))return![];return _0x2e2604[_0x532724(0x149)](_0x189e09['id']),!![];});}function runtimeModelFingerprint(_0xe316c){const _0x1c3a40=_0x5bf0ee,{apiKey:_0x108236,credential:_0x9ca705,imageGeneration:_0x301778,..._0x1f9b06}=_0xe316c;return{..._0x1f9b06,..._0x301778===undefined?{}:{'imageGeneration':{..._0x301778,'credential':runtimeCredentialFingerprint(_0x301778[_0x1c3a40(0x12c)])}},..._0x108236===undefined?{}:{'apiKeyHash':createHash(_0x1c3a40(0xdc))[_0x1c3a40(0x141)](_0x108236)[_0x1c3a40(0x128)](_0x1c3a40(0x10c))},'credential':runtimeCredentialFingerprint(_0x9ca705)};}function runtimeCredentialFingerprint(_0x2ba58a){const _0x1db656=_0x5bf0ee;return _0x2ba58a?.[_0x1db656(0x14b)]===_0x1db656(0x117)?{'type':_0x2ba58a[_0x1db656(0x14b)],'valueHash':createHash(_0x1db656(0xdc))[_0x1db656(0x141)](_0x2ba58a[_0x1db656(0x120)])[_0x1db656(0x128)](_0x1db656(0x10c))}:_0x2ba58a===undefined?undefined:{'type':_0x2ba58a[_0x1db656(0x14b)],'credentialId':_0x2ba58a[_0x1db656(0x151)]};}async function closeModelCredentialProviders(_0x55d626){const _0xe30eee=_0x5bf0ee;await Promise[_0xe30eee(0xd1)]([...new Set(_0x55d626[_0xe30eee(0xce)](_0x56114e=>[..._0x56114e[_0xe30eee(0xda)]===undefined?[]:[_0x56114e[_0xe30eee(0xda)]],..._0x56114e[_0xe30eee(0x19e)]?.[_0xe30eee(0xda)]===undefined?[]:[_0x56114e[_0xe30eee(0x19e)][_0xe30eee(0xda)]]]))][_0xe30eee(0x15d)](_0x3e2435=>_0x3e2435[_0xe30eee(0xe7)]()));}
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { access, constants } from 'node:fs/promises';
|
|
4
|
+
import { BUNDLED_RIPGREP_VERSION, bundledRipgrepPath, prependBundledRipgrepToPath } from '../../ripgrep-binary.js';
|
|
5
|
+
import { LocalAgentHost, SecretValue, createMarAgent } from '@myagentroam/agent';
|
|
6
|
+
import { marAgentReasoningEffortSchema, marAgentRuntimeModelConfigurationSchema } from '@myagentroam/protocol';
|
|
7
|
+
import { boundedConversationItemId } from '../codex/conversation-parser.js';
|
|
8
|
+
import { parseSecretEnvironment } from '../../util/secret-environment.js';
|
|
9
|
+
import { MarAgentMcpClientCache } from './mcp-client-pool.js';
|
|
10
|
+
import { MarAgentConversationNormalizer } from './conversation-normalizer.js';
|
|
11
|
+
import { parseRunnerImageAttachments } from '../../util/node-operation-parsers.js';
|
|
12
|
+
import { runnerErrorProjection } from '../../util/runner-error.js';
|
|
13
|
+
export class MarAgentManagedRunController {
|
|
14
|
+
runner;
|
|
15
|
+
host;
|
|
16
|
+
#mcpClients = new MarAgentMcpClientCache();
|
|
17
|
+
#executions = new Map();
|
|
18
|
+
#sessionRuntimes = new Map();
|
|
19
|
+
#runtimeAcquisitions = new Map();
|
|
20
|
+
#runtimeCreations = new Map();
|
|
21
|
+
#sessionReleases = new Map();
|
|
22
|
+
#approvals = new Map();
|
|
23
|
+
#questions = new Map();
|
|
24
|
+
#normalizers = new Map();
|
|
25
|
+
#resourceIdleTtlMs;
|
|
26
|
+
#createAgent;
|
|
27
|
+
#modelFactory;
|
|
28
|
+
#disposePromise;
|
|
29
|
+
#disposed = false;
|
|
30
|
+
constructor(runner, host, options = {}) {
|
|
31
|
+
this.runner = runner;
|
|
32
|
+
this.host = host;
|
|
33
|
+
this.#resourceIdleTtlMs = options.resourceIdleTtlMs ?? 60_000;
|
|
34
|
+
this.#createAgent = options.createAgent ?? createMarAgent;
|
|
35
|
+
this.#modelFactory = options.modelFactory ?? {
|
|
36
|
+
create: (configurations) => configurations.map((configuration) => {
|
|
37
|
+
const { apiKey, credential, ...model } = configuration;
|
|
38
|
+
const value = apiKey ?? (credential?.type === 'INLINE_API_KEY' ? credential.value : undefined);
|
|
39
|
+
if (value === undefined)
|
|
40
|
+
throw new Error('MAR_AGENT_RUNTIME_CREDENTIALS_UNSUPPORTED');
|
|
41
|
+
return {
|
|
42
|
+
...model,
|
|
43
|
+
apiKey: new SecretValue(value)
|
|
44
|
+
};
|
|
45
|
+
})
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
dispose() {
|
|
49
|
+
if (this.#disposePromise !== undefined)
|
|
50
|
+
return this.#disposePromise;
|
|
51
|
+
this.#disposed = true;
|
|
52
|
+
this.#disposePromise = (async () => {
|
|
53
|
+
for (const execution of this.#executions.values())
|
|
54
|
+
execution.cancel();
|
|
55
|
+
await Promise.allSettled([...new Set(this.#runtimeAcquisitions.values())]);
|
|
56
|
+
for (const execution of this.#executions.values())
|
|
57
|
+
execution.cancel();
|
|
58
|
+
await Promise.all([...new Set(this.#sessionRuntimes.values())].map((runtime) => this.#releaseRuntime(runtime)));
|
|
59
|
+
await this.#mcpClients.close();
|
|
60
|
+
})();
|
|
61
|
+
return this.#disposePromise;
|
|
62
|
+
}
|
|
63
|
+
releaseSession(sessionId) {
|
|
64
|
+
const existing = this.#sessionReleases.get(sessionId);
|
|
65
|
+
if (existing !== undefined)
|
|
66
|
+
return existing;
|
|
67
|
+
const release = (async () => {
|
|
68
|
+
await this.#runtimeAcquisitions.get(sessionId)?.catch(() => undefined);
|
|
69
|
+
const runtime = this.#sessionRuntimes.get(sessionId);
|
|
70
|
+
if (runtime === undefined)
|
|
71
|
+
return;
|
|
72
|
+
if (runtime.activeRunId !== undefined)
|
|
73
|
+
this.#executions.get(runtime.activeRunId)?.cancel();
|
|
74
|
+
await this.#releaseRuntime(runtime);
|
|
75
|
+
})();
|
|
76
|
+
const tracked = release.finally(() => {
|
|
77
|
+
if (this.#sessionReleases.get(sessionId) === tracked)
|
|
78
|
+
this.#sessionReleases.delete(sessionId);
|
|
79
|
+
});
|
|
80
|
+
this.#sessionReleases.set(sessionId, tracked);
|
|
81
|
+
return tracked;
|
|
82
|
+
}
|
|
83
|
+
async executeCommand(session, command, input, context) {
|
|
84
|
+
if (command.id === 'plan') {
|
|
85
|
+
const current = this.host.commandState(session.id, 'plan');
|
|
86
|
+
if (current?.active)
|
|
87
|
+
this.host.clearCommandState(session.id, 'plan');
|
|
88
|
+
else
|
|
89
|
+
this.host.setCommandState(session.id, {
|
|
90
|
+
commandId: 'plan',
|
|
91
|
+
active: true,
|
|
92
|
+
label: 'Plan Mode',
|
|
93
|
+
detail: 'Subsequent messages run in read-only Plan Mode.',
|
|
94
|
+
closable: true,
|
|
95
|
+
closeInput: '/plan',
|
|
96
|
+
continuation: { label: 'Implement', prompt: 'Implement the plan above.' }
|
|
97
|
+
});
|
|
98
|
+
return { command: command.id, states: this.host.commandStates(session.id) };
|
|
99
|
+
}
|
|
100
|
+
if (command.id !== 'compact')
|
|
101
|
+
throw new Error('RUNNER_COMMAND_UNAVAILABLE');
|
|
102
|
+
if (session.externalSessionId === null || session.nativeControl !== 'MAR_MANAGED')
|
|
103
|
+
throw new Error('RUNNER_COMMAND_UNAVAILABLE');
|
|
104
|
+
const parsed = marAgentRuntimeModelConfigurationSchema.safeParse(context.marAgentModel);
|
|
105
|
+
if (!parsed.success || parsed.data.id !== session.model)
|
|
106
|
+
throw new Error('RUNNER_COMMAND_UNAVAILABLE');
|
|
107
|
+
const current = parsed.data;
|
|
108
|
+
const runId = randomUUID();
|
|
109
|
+
void this.run({
|
|
110
|
+
runId,
|
|
111
|
+
sessionId: session.id,
|
|
112
|
+
input,
|
|
113
|
+
cwd: session.cwd,
|
|
114
|
+
model: current,
|
|
115
|
+
models: resolveRunModels(current, context.marAgentModels),
|
|
116
|
+
...(typeof context.marAgentRuntimeScopeId === 'string'
|
|
117
|
+
? { runtimeScopeId: context.marAgentRuntimeScopeId }
|
|
118
|
+
: {}),
|
|
119
|
+
effort: session.effort ?? '',
|
|
120
|
+
access: session.access === 'full-access' ? 'full-access' : 'on-request',
|
|
121
|
+
mode: command.id,
|
|
122
|
+
secretEnvironment: context.secretEnvironment,
|
|
123
|
+
externalSessionId: session.externalSessionId,
|
|
124
|
+
mcpServers: [],
|
|
125
|
+
images: [],
|
|
126
|
+
...(context.initiatedByUserId === undefined
|
|
127
|
+
? {}
|
|
128
|
+
: { initiatedByUserId: context.initiatedByUserId })
|
|
129
|
+
});
|
|
130
|
+
return {
|
|
131
|
+
command: command.id,
|
|
132
|
+
run: this.host.run(runId),
|
|
133
|
+
states: this.host.commandStates(session.id)
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
start(envelope) {
|
|
137
|
+
const payload = envelope.payload;
|
|
138
|
+
if (payload.runner !== 'mar-agent' ||
|
|
139
|
+
typeof payload.runId !== 'string' ||
|
|
140
|
+
typeof payload.sessionId !== 'string' ||
|
|
141
|
+
typeof payload.input !== 'string' ||
|
|
142
|
+
typeof payload.cwd !== 'string' ||
|
|
143
|
+
typeof payload.model !== 'string' ||
|
|
144
|
+
this.host.active.has(payload.runId))
|
|
145
|
+
return;
|
|
146
|
+
const parsed = marAgentRuntimeModelConfigurationSchema.safeParse(payload.marAgentModel);
|
|
147
|
+
if (!parsed.success || parsed.data.id !== payload.model) {
|
|
148
|
+
this.host.emit(payload.runId, 'run.rejected', { code: 'MAR_AGENT_MODEL_CONFIG_INVALID' }, 'FAILED');
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const model = parsed.data;
|
|
152
|
+
let mcpServers;
|
|
153
|
+
let images;
|
|
154
|
+
let secretEnvironment;
|
|
155
|
+
try {
|
|
156
|
+
secretEnvironment = parseSecretEnvironment(payload.secretEnvironment);
|
|
157
|
+
const mcpSecretEnvironment = parseSecretEnvironment(payload.mcpSecretEnvironment);
|
|
158
|
+
mcpServers = this.runner.mcpConfiguration(payload.mcpInstallations, {
|
|
159
|
+
...secretEnvironment,
|
|
160
|
+
...mcpSecretEnvironment
|
|
161
|
+
});
|
|
162
|
+
images = parseRunnerImageAttachments(payload.attachments);
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
this.host.emit(payload.runId, 'run.rejected', { code: 'MAR_AGENT_MCP_CONFIG_INVALID' }, 'FAILED');
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
void this.run({
|
|
169
|
+
runId: payload.runId,
|
|
170
|
+
sessionId: payload.sessionId,
|
|
171
|
+
input: payload.input,
|
|
172
|
+
secretEnvironment,
|
|
173
|
+
cwd: payload.cwd,
|
|
174
|
+
model,
|
|
175
|
+
models: resolveRunModels(model, payload.marAgentModels),
|
|
176
|
+
...(typeof payload.marAgentRuntimeScopeId === 'string'
|
|
177
|
+
? { runtimeScopeId: payload.marAgentRuntimeScopeId }
|
|
178
|
+
: {}),
|
|
179
|
+
effort: typeof payload.effort === 'string' ? payload.effort : '',
|
|
180
|
+
access: payload.access === 'full-access' ? 'full-access' : 'on-request',
|
|
181
|
+
mode: payload.collaborationMode === 'plan' ? 'plan' : 'run',
|
|
182
|
+
mcpServers,
|
|
183
|
+
images: images.map((image) => ({
|
|
184
|
+
name: image.name,
|
|
185
|
+
mimeType: image.mime,
|
|
186
|
+
dataBase64: image.dataBase64
|
|
187
|
+
})),
|
|
188
|
+
...(typeof payload.clientMessageId === 'string'
|
|
189
|
+
? { clientMessageId: payload.clientMessageId }
|
|
190
|
+
: {}),
|
|
191
|
+
...(typeof payload.externalSessionId === 'string'
|
|
192
|
+
? { externalSessionId: payload.externalSessionId }
|
|
193
|
+
: {}),
|
|
194
|
+
...(typeof payload.personalInstructions === 'string'
|
|
195
|
+
? { personalInstructions: payload.personalInstructions }
|
|
196
|
+
: {})
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
cancel(runId, intent) {
|
|
200
|
+
const execution = this.#executions.get(runId);
|
|
201
|
+
if (!execution)
|
|
202
|
+
return false;
|
|
203
|
+
execution.cancel();
|
|
204
|
+
this.host.emit(runId, 'run.cancelling', { intent }, 'RUNNING');
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
decideApproval(input) {
|
|
208
|
+
const pending = this.#approvals.get(input.approvalId);
|
|
209
|
+
if (!pending || pending.runId !== input.runId)
|
|
210
|
+
return false;
|
|
211
|
+
clearTimeout(pending.timer);
|
|
212
|
+
pending.cleanup();
|
|
213
|
+
this.#approvals.delete(input.approvalId);
|
|
214
|
+
pending.resolve(input.decision === 'APPROVED' ? 'approved' : 'denied');
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
respondUserInput(runId, requestId, answers) {
|
|
218
|
+
const pending = this.#questions.get(requestId);
|
|
219
|
+
if (!pending || pending.runId !== runId)
|
|
220
|
+
return false;
|
|
221
|
+
clearTimeout(pending.timer);
|
|
222
|
+
pending.cleanup();
|
|
223
|
+
this.#questions.delete(requestId);
|
|
224
|
+
pending.resolve(Object.fromEntries(Object.entries(answers).map(([id, answer]) => [
|
|
225
|
+
id,
|
|
226
|
+
Array.isArray(answer) && answer.length === 1 ? answer[0] : answer
|
|
227
|
+
])));
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
async run(input) {
|
|
231
|
+
this.host.active.add(input.runId);
|
|
232
|
+
this.host.adopt({
|
|
233
|
+
runId: input.runId,
|
|
234
|
+
sessionId: input.sessionId,
|
|
235
|
+
runner: 'mar-agent',
|
|
236
|
+
cwd: input.cwd,
|
|
237
|
+
...(input.externalSessionId ? { externalSessionId: input.externalSessionId } : {}),
|
|
238
|
+
...(input.initiatedByUserId === undefined
|
|
239
|
+
? {}
|
|
240
|
+
: { initiatedByUserId: input.initiatedByUserId })
|
|
241
|
+
});
|
|
242
|
+
this.host.emit(input.runId, 'run.started', {}, 'STARTING');
|
|
243
|
+
let runtime;
|
|
244
|
+
try {
|
|
245
|
+
const sessionKey = input.externalSessionId ?? input.sessionId;
|
|
246
|
+
const acquisitionKeys = [...new Set([sessionKey, input.sessionId])];
|
|
247
|
+
if (acquisitionKeys.some((key) => this.#runtimeAcquisitions.get(key) !== undefined))
|
|
248
|
+
throw new Error('MAR_AGENT_SESSION_RUNTIME_ACTIVE');
|
|
249
|
+
const acquisition = this.#acquireRuntime(input);
|
|
250
|
+
for (const key of acquisitionKeys)
|
|
251
|
+
this.#runtimeAcquisitions.set(key, acquisition);
|
|
252
|
+
try {
|
|
253
|
+
runtime = await acquisition;
|
|
254
|
+
}
|
|
255
|
+
finally {
|
|
256
|
+
for (const key of acquisitionKeys)
|
|
257
|
+
if (this.#runtimeAcquisitions.get(key) === acquisition)
|
|
258
|
+
this.#runtimeAcquisitions.delete(key);
|
|
259
|
+
}
|
|
260
|
+
if (this.#disposed ||
|
|
261
|
+
this.#sessionReleases.has(sessionKey) ||
|
|
262
|
+
this.#sessionReleases.has(input.sessionId) ||
|
|
263
|
+
this.#sessionReleases.has(runtime.session.id)) {
|
|
264
|
+
await this.#releaseRuntime(runtime);
|
|
265
|
+
throw new Error('MAR_AGENT_SESSION_RUNTIME_RELEASED');
|
|
266
|
+
}
|
|
267
|
+
if (runtime.activeRunId !== undefined)
|
|
268
|
+
throw new Error('MAR_AGENT_SESSION_RUNTIME_ACTIVE');
|
|
269
|
+
runtime.activeRunId = input.runId;
|
|
270
|
+
runtime.activeAccess = input.access;
|
|
271
|
+
const session = runtime.session;
|
|
272
|
+
const reasoningEffort = input.effort
|
|
273
|
+
? marAgentReasoningEffortSchema.parse(input.effort)
|
|
274
|
+
: undefined;
|
|
275
|
+
const runInput = {
|
|
276
|
+
prompt: input.input,
|
|
277
|
+
...(input.clientMessageId ? { clientMessageId: input.clientMessageId } : {}),
|
|
278
|
+
modelId: input.model.id,
|
|
279
|
+
...(reasoningEffort === undefined ? {} : { reasoningEffort }),
|
|
280
|
+
access: input.access,
|
|
281
|
+
images: input.images
|
|
282
|
+
};
|
|
283
|
+
const handle = input.mode === 'plan'
|
|
284
|
+
? session.plan({
|
|
285
|
+
...runInput
|
|
286
|
+
})
|
|
287
|
+
: input.mode === 'compact'
|
|
288
|
+
? session.compact(runInput)
|
|
289
|
+
: session.run(runInput);
|
|
290
|
+
this.#executions.set(input.runId, {
|
|
291
|
+
cancel: () => handle.cancel()
|
|
292
|
+
});
|
|
293
|
+
this.host.emit(input.runId, 'run.running', {}, 'RUNNING');
|
|
294
|
+
for await (const event of handle)
|
|
295
|
+
this.project(input.runId, event);
|
|
296
|
+
const result = await handle.result();
|
|
297
|
+
await this.host.syncTitle(session.id, input.cwd);
|
|
298
|
+
const status = result.status === 'completed'
|
|
299
|
+
? 'SUCCEEDED'
|
|
300
|
+
: result.status === 'cancelled'
|
|
301
|
+
? 'CANCELLED'
|
|
302
|
+
: 'FAILED';
|
|
303
|
+
this.host.emit(input.runId, status === 'SUCCEEDED'
|
|
304
|
+
? 'run.completed'
|
|
305
|
+
: status === 'CANCELLED'
|
|
306
|
+
? 'run.cancelled'
|
|
307
|
+
: 'run.failed', {
|
|
308
|
+
status,
|
|
309
|
+
...(result.errorCode ? { code: result.errorCode } : {}),
|
|
310
|
+
...(result.errorMessage ? { message: result.errorMessage } : {})
|
|
311
|
+
}, status);
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
const projected = runnerErrorProjection(error, 'MAR_AGENT_RUN_FAILED');
|
|
315
|
+
this.host.emitItem(input.runId, {
|
|
316
|
+
itemId: boundedConversationItemId('mar-agent-error', input.runId),
|
|
317
|
+
kind: 'error',
|
|
318
|
+
status: 'FAILED',
|
|
319
|
+
payload: {
|
|
320
|
+
...projected,
|
|
321
|
+
recoverable: true,
|
|
322
|
+
retryAfterMs: null
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
this.host.emit(input.runId, 'run.failed', projected, 'FAILED');
|
|
326
|
+
}
|
|
327
|
+
finally {
|
|
328
|
+
this.clearInteractions(input.runId);
|
|
329
|
+
this.#normalizers.delete(input.runId);
|
|
330
|
+
this.host.active.delete(input.runId);
|
|
331
|
+
this.#executions.delete(input.runId);
|
|
332
|
+
if (runtime?.activeRunId === input.runId) {
|
|
333
|
+
delete runtime.activeRunId;
|
|
334
|
+
delete runtime.activeAccess;
|
|
335
|
+
}
|
|
336
|
+
if (runtime !== undefined) {
|
|
337
|
+
if (runtime.retainable)
|
|
338
|
+
this.#scheduleRuntimeRelease(runtime);
|
|
339
|
+
else
|
|
340
|
+
await this.#releaseRuntime(runtime);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
async #acquireRuntime(input) {
|
|
345
|
+
if (this.#disposed)
|
|
346
|
+
throw new Error('MAR_AGENT_RUN_CONTROLLER_DISPOSED');
|
|
347
|
+
const sessionKey = input.externalSessionId ?? input.sessionId;
|
|
348
|
+
const retained = this.#retainRuntime(sessionKey);
|
|
349
|
+
try {
|
|
350
|
+
const hostConfiguration = await resolveMarAgentHostRuntimeConfiguration(input.secretEnvironment);
|
|
351
|
+
if (this.#disposed)
|
|
352
|
+
throw new Error('MAR_AGENT_RUN_CONTROLLER_DISPOSED');
|
|
353
|
+
const fingerprint = sessionRuntimeFingerprint(input, hostConfiguration);
|
|
354
|
+
const creationKeys = [...new Set([sessionKey, input.sessionId])];
|
|
355
|
+
const pending = creationKeys
|
|
356
|
+
.map((key) => this.#runtimeCreations.get(key))
|
|
357
|
+
.find((creation) => creation !== undefined);
|
|
358
|
+
if (pending !== undefined) {
|
|
359
|
+
await pending;
|
|
360
|
+
return this.#acquireRuntime(input);
|
|
361
|
+
}
|
|
362
|
+
const existing = this.#sessionRuntimes.get(sessionKey);
|
|
363
|
+
if (existing !== undefined) {
|
|
364
|
+
if (existing.activeRunId !== undefined)
|
|
365
|
+
throw new Error('MAR_AGENT_SESSION_RUNTIME_ACTIVE');
|
|
366
|
+
if (!existing.released &&
|
|
367
|
+
existing.release === undefined &&
|
|
368
|
+
existing.fingerprint === fingerprint) {
|
|
369
|
+
if (existing.dynamicCredentials) {
|
|
370
|
+
const models = this.#modelFactory.create(input.models, {
|
|
371
|
+
...(input.runtimeScopeId === undefined
|
|
372
|
+
? {}
|
|
373
|
+
: { runtimeScopeId: input.runtimeScopeId }),
|
|
374
|
+
executionId: input.runId
|
|
375
|
+
});
|
|
376
|
+
try {
|
|
377
|
+
await existing.agent.reconfigureModels({
|
|
378
|
+
models,
|
|
379
|
+
defaultModelId: input.model.id
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
catch (error) {
|
|
383
|
+
await closeModelCredentialProviders(models);
|
|
384
|
+
throw error;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
this.#retainRuntime(sessionKey);
|
|
388
|
+
return existing;
|
|
389
|
+
}
|
|
390
|
+
await this.#releaseRuntime(existing);
|
|
391
|
+
}
|
|
392
|
+
const creation = this.#createRuntime(input, sessionKey, fingerprint, hostConfiguration);
|
|
393
|
+
for (const key of creationKeys)
|
|
394
|
+
this.#runtimeCreations.set(key, creation);
|
|
395
|
+
try {
|
|
396
|
+
return await creation;
|
|
397
|
+
}
|
|
398
|
+
finally {
|
|
399
|
+
for (const key of creationKeys)
|
|
400
|
+
if (this.#runtimeCreations.get(key) === creation)
|
|
401
|
+
this.#runtimeCreations.delete(key);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
this.#restoreRuntimeRelease(retained);
|
|
406
|
+
throw error;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
async #createRuntime(input, sessionKey, fingerprint, hostConfiguration) {
|
|
410
|
+
const dynamicCredentials = input.models.some((model) => model.credential?.type === 'RUNTIME_TICKET' ||
|
|
411
|
+
model.imageGeneration?.credential?.type === 'RUNTIME_TICKET');
|
|
412
|
+
const retainable = !executionScopedMcp(input.mcpServers);
|
|
413
|
+
const mcpLease = await this.#mcpClients.acquire(input.mcpServers, input.cwd, {
|
|
414
|
+
reusable: retainable
|
|
415
|
+
});
|
|
416
|
+
let agent;
|
|
417
|
+
let runtime;
|
|
418
|
+
try {
|
|
419
|
+
const mcp = mcpLease.pool;
|
|
420
|
+
const localHost = new LocalAgentHost({
|
|
421
|
+
mode: 'node',
|
|
422
|
+
homeDirectory: homedir(),
|
|
423
|
+
workspace: input.cwd,
|
|
424
|
+
environment: hostConfiguration.environment,
|
|
425
|
+
guaranteedCommands: hostConfiguration.guaranteedCommands,
|
|
426
|
+
approve: async (call, signal) => {
|
|
427
|
+
const runId = runtime?.activeRunId;
|
|
428
|
+
const access = runtime?.activeAccess;
|
|
429
|
+
if (runId === undefined || access === undefined)
|
|
430
|
+
return 'denied';
|
|
431
|
+
return access === 'full-access' ? 'approved' : this.requestApproval(runId, call, signal);
|
|
432
|
+
},
|
|
433
|
+
question: async (request, signal) => {
|
|
434
|
+
const runId = runtime?.activeRunId;
|
|
435
|
+
return runId === undefined ? {} : this.requestQuestion(runId, request, signal);
|
|
436
|
+
},
|
|
437
|
+
mcpTools: mcp.definitions(),
|
|
438
|
+
callMcp: async (call) => mcp.call(call.name, call.arguments),
|
|
439
|
+
webSearch: (request, signal) => this.host.webSearch(request, signal),
|
|
440
|
+
allowUntrustedTls: allowsUntrustedWebFetchTls(hostConfiguration.environment),
|
|
441
|
+
resourceIdleTtlMs: this.#resourceIdleTtlMs
|
|
442
|
+
});
|
|
443
|
+
const models = this.#modelFactory.create(input.models, {
|
|
444
|
+
...(input.runtimeScopeId === undefined ? {} : { runtimeScopeId: input.runtimeScopeId }),
|
|
445
|
+
executionId: input.runId
|
|
446
|
+
});
|
|
447
|
+
agent = await this.#createAgent({
|
|
448
|
+
mode: 'node',
|
|
449
|
+
host: localHost,
|
|
450
|
+
models,
|
|
451
|
+
defaultModelId: input.model.id,
|
|
452
|
+
...(input.personalInstructions ? { systemInstruction: input.personalInstructions } : {})
|
|
453
|
+
});
|
|
454
|
+
const session = input.externalSessionId
|
|
455
|
+
? await agent.openSession(input.externalSessionId)
|
|
456
|
+
: await agent.createSession({ workspace: input.cwd });
|
|
457
|
+
runtime = {
|
|
458
|
+
fingerprint,
|
|
459
|
+
agent,
|
|
460
|
+
session,
|
|
461
|
+
mcpLease,
|
|
462
|
+
retainable,
|
|
463
|
+
dynamicCredentials,
|
|
464
|
+
released: false
|
|
465
|
+
};
|
|
466
|
+
this.#sessionRuntimes.set(sessionKey, runtime);
|
|
467
|
+
this.#sessionRuntimes.set(session.id, runtime);
|
|
468
|
+
if (!input.externalSessionId)
|
|
469
|
+
this.host.promote(input.sessionId, session.id);
|
|
470
|
+
return runtime;
|
|
471
|
+
}
|
|
472
|
+
catch (error) {
|
|
473
|
+
await agent?.dispose().catch(() => undefined);
|
|
474
|
+
await mcpLease.release().catch(() => undefined);
|
|
475
|
+
throw error;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
#scheduleRuntimeRelease(runtime) {
|
|
479
|
+
if (runtime.released || runtime.release !== undefined)
|
|
480
|
+
return;
|
|
481
|
+
if (runtime.idleTimer !== undefined)
|
|
482
|
+
clearTimeout(runtime.idleTimer);
|
|
483
|
+
runtime.idleTimer = setTimeout(() => {
|
|
484
|
+
delete runtime.idleTimer;
|
|
485
|
+
void this.#releaseRuntime(runtime);
|
|
486
|
+
}, this.#resourceIdleTtlMs);
|
|
487
|
+
runtime.idleTimer.unref();
|
|
488
|
+
}
|
|
489
|
+
#retainRuntime(sessionKey) {
|
|
490
|
+
const runtime = this.#sessionRuntimes.get(sessionKey);
|
|
491
|
+
if (runtime?.idleTimer !== undefined) {
|
|
492
|
+
clearTimeout(runtime.idleTimer);
|
|
493
|
+
delete runtime.idleTimer;
|
|
494
|
+
}
|
|
495
|
+
return runtime;
|
|
496
|
+
}
|
|
497
|
+
#restoreRuntimeRelease(runtime) {
|
|
498
|
+
if (runtime === undefined ||
|
|
499
|
+
runtime.released ||
|
|
500
|
+
runtime.release !== undefined ||
|
|
501
|
+
runtime.activeRunId !== undefined ||
|
|
502
|
+
![...this.#sessionRuntimes.values()].includes(runtime))
|
|
503
|
+
return;
|
|
504
|
+
this.#scheduleRuntimeRelease(runtime);
|
|
505
|
+
}
|
|
506
|
+
#releaseRuntime(runtime) {
|
|
507
|
+
if (runtime.release !== undefined)
|
|
508
|
+
return runtime.release;
|
|
509
|
+
runtime.release = (async () => {
|
|
510
|
+
runtime.released = true;
|
|
511
|
+
if (runtime.idleTimer !== undefined) {
|
|
512
|
+
clearTimeout(runtime.idleTimer);
|
|
513
|
+
delete runtime.idleTimer;
|
|
514
|
+
}
|
|
515
|
+
try {
|
|
516
|
+
await runtime.agent.dispose();
|
|
517
|
+
}
|
|
518
|
+
finally {
|
|
519
|
+
await runtime.mcpLease.release().catch(() => undefined);
|
|
520
|
+
for (const [sessionId, candidate] of this.#sessionRuntimes)
|
|
521
|
+
if (candidate === runtime)
|
|
522
|
+
this.#sessionRuntimes.delete(sessionId);
|
|
523
|
+
}
|
|
524
|
+
})();
|
|
525
|
+
return runtime.release;
|
|
526
|
+
}
|
|
527
|
+
requestApproval(runId, call, signal = new AbortController().signal) {
|
|
528
|
+
const approvalId = randomUUID();
|
|
529
|
+
const expiresAt = Date.now() + 10 * 60_000;
|
|
530
|
+
const payload = {
|
|
531
|
+
category: call.name === 'apply_patch' ? 'FILE_CHANGE' : call.name === 'exec' ? 'COMMAND' : 'TOOL',
|
|
532
|
+
toolName: call.name,
|
|
533
|
+
reason: 'MAR Agent requested permission for this tool call.'
|
|
534
|
+
};
|
|
535
|
+
this.host.createApproval({ runId, approvalId, payload, expiresAt });
|
|
536
|
+
this.host.publishApproval({ runId, approvalId, payload, expiresAt });
|
|
537
|
+
return new Promise((resolve) => {
|
|
538
|
+
const cancel = () => settle('denied');
|
|
539
|
+
const settle = (decision) => {
|
|
540
|
+
const pending = this.#approvals.get(approvalId);
|
|
541
|
+
if (!pending)
|
|
542
|
+
return;
|
|
543
|
+
clearTimeout(pending.timer);
|
|
544
|
+
pending.cleanup();
|
|
545
|
+
this.#approvals.delete(approvalId);
|
|
546
|
+
resolve(decision);
|
|
547
|
+
};
|
|
548
|
+
const timer = setTimeout(() => {
|
|
549
|
+
settle('denied');
|
|
550
|
+
}, 10 * 60_000);
|
|
551
|
+
timer.unref();
|
|
552
|
+
signal.addEventListener('abort', cancel, { once: true });
|
|
553
|
+
this.#approvals.set(approvalId, {
|
|
554
|
+
runId,
|
|
555
|
+
resolve,
|
|
556
|
+
timer,
|
|
557
|
+
cleanup: () => signal.removeEventListener('abort', cancel)
|
|
558
|
+
});
|
|
559
|
+
if (signal.aborted)
|
|
560
|
+
cancel();
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
requestQuestion(runId, request, signal = new AbortController().signal) {
|
|
564
|
+
const questions = normalizeQuestions(request.questions);
|
|
565
|
+
if (questions.length === 0)
|
|
566
|
+
return Promise.resolve({});
|
|
567
|
+
this.host.emitItem(runId, {
|
|
568
|
+
itemId: boundedConversationItemId('mar-agent-question', request.requestId),
|
|
569
|
+
kind: 'user_input_request',
|
|
570
|
+
status: 'PENDING',
|
|
571
|
+
payload: { requestId: request.requestId, questions }
|
|
572
|
+
});
|
|
573
|
+
return new Promise((resolve) => {
|
|
574
|
+
const cancel = () => settle({});
|
|
575
|
+
const settle = (answers) => {
|
|
576
|
+
const pending = this.#questions.get(request.requestId);
|
|
577
|
+
if (!pending)
|
|
578
|
+
return;
|
|
579
|
+
clearTimeout(pending.timer);
|
|
580
|
+
pending.cleanup();
|
|
581
|
+
this.#questions.delete(request.requestId);
|
|
582
|
+
resolve(answers);
|
|
583
|
+
};
|
|
584
|
+
const timer = setTimeout(() => {
|
|
585
|
+
settle({});
|
|
586
|
+
}, 10 * 60_000);
|
|
587
|
+
timer.unref();
|
|
588
|
+
signal.addEventListener('abort', cancel, { once: true });
|
|
589
|
+
this.#questions.set(request.requestId, {
|
|
590
|
+
runId,
|
|
591
|
+
resolve,
|
|
592
|
+
timer,
|
|
593
|
+
cleanup: () => signal.removeEventListener('abort', cancel)
|
|
594
|
+
});
|
|
595
|
+
if (signal.aborted)
|
|
596
|
+
cancel();
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
clearInteractions(runId) {
|
|
600
|
+
for (const [approvalId, pending] of this.#approvals) {
|
|
601
|
+
if (pending.runId !== runId)
|
|
602
|
+
continue;
|
|
603
|
+
clearTimeout(pending.timer);
|
|
604
|
+
pending.cleanup();
|
|
605
|
+
this.#approvals.delete(approvalId);
|
|
606
|
+
pending.resolve('denied');
|
|
607
|
+
}
|
|
608
|
+
for (const [requestId, pending] of this.#questions) {
|
|
609
|
+
if (pending.runId !== runId)
|
|
610
|
+
continue;
|
|
611
|
+
clearTimeout(pending.timer);
|
|
612
|
+
pending.cleanup();
|
|
613
|
+
this.#questions.delete(requestId);
|
|
614
|
+
pending.resolve({});
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
project(runId, event) {
|
|
618
|
+
if (contextUsageChanged(event))
|
|
619
|
+
this.host.refreshContext?.(runId);
|
|
620
|
+
if (event.type === 'message.delta')
|
|
621
|
+
this.host.emit(runId, 'text.delta', {
|
|
622
|
+
text: event.delta,
|
|
623
|
+
phase: event.phase,
|
|
624
|
+
itemId: boundedConversationItemId('mar-agent-message', event.itemId)
|
|
625
|
+
});
|
|
626
|
+
else {
|
|
627
|
+
let normalizer = this.#normalizers.get(runId);
|
|
628
|
+
if (normalizer === undefined) {
|
|
629
|
+
normalizer = new MarAgentConversationNormalizer();
|
|
630
|
+
this.#normalizers.set(runId, normalizer);
|
|
631
|
+
}
|
|
632
|
+
for (const item of normalizer.normalize(event)) {
|
|
633
|
+
const attachments = item.generatedImages === undefined
|
|
634
|
+
? []
|
|
635
|
+
: (this.host.registerGeneratedImages?.(runId, event.sessionId, item.generatedImages) ??
|
|
636
|
+
[]);
|
|
637
|
+
this.host.emitItem(runId, {
|
|
638
|
+
itemId: item.itemId,
|
|
639
|
+
kind: item.kind,
|
|
640
|
+
status: item.status,
|
|
641
|
+
payload: attachments.length === 0 ? item.payload : { ...item.payload, attachments },
|
|
642
|
+
...(item.merge === undefined ? {} : { merge: item.merge })
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
function contextUsageChanged(event) {
|
|
649
|
+
return (event.type === 'context.compacted' ||
|
|
650
|
+
(event.type === 'usage.updated' &&
|
|
651
|
+
(event.contextInputTokens !== undefined || event.inputTokens !== undefined)));
|
|
652
|
+
}
|
|
653
|
+
function sessionRuntimeFingerprint(input, hostConfiguration) {
|
|
654
|
+
return createHash('sha256')
|
|
655
|
+
.update(JSON.stringify({
|
|
656
|
+
cwd: input.cwd,
|
|
657
|
+
defaultModelId: input.model.id,
|
|
658
|
+
models: input.models.map(runtimeModelFingerprint),
|
|
659
|
+
personalInstructions: input.personalInstructions ?? '',
|
|
660
|
+
mcpServers: input.mcpServers,
|
|
661
|
+
environment: Object.entries(hostConfiguration.environment)
|
|
662
|
+
.filter((entry) => entry[1] !== undefined)
|
|
663
|
+
.sort(([left], [right]) => left.localeCompare(right)),
|
|
664
|
+
guaranteedCommands: Object.entries(hostConfiguration.guaranteedCommands).sort(([left], [right]) => left.localeCompare(right))
|
|
665
|
+
}))
|
|
666
|
+
.digest('hex');
|
|
667
|
+
}
|
|
668
|
+
export function allowsUntrustedWebFetchTls(environment) {
|
|
669
|
+
return environment['MAR_AGENT_WEB_FETCH_ALLOW_UNTRUSTED_TLS'] !== '0';
|
|
670
|
+
}
|
|
671
|
+
function executionScopedMcp(servers) {
|
|
672
|
+
return servers.some((server) => server.lifecycle === 'EXECUTION');
|
|
673
|
+
}
|
|
674
|
+
async function resolveMarAgentHostRuntimeConfiguration(secretEnvironment = {}) {
|
|
675
|
+
const environment = { ...process.env, ...secretEnvironment };
|
|
676
|
+
const ripgrep = await availableBundledRipgrep();
|
|
677
|
+
return {
|
|
678
|
+
environment: ripgrep === undefined ? environment : prependBundledRipgrepToPath(environment, ripgrep),
|
|
679
|
+
guaranteedCommands: ripgrep === undefined ? {} : { rg: BUNDLED_RIPGREP_VERSION }
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
async function availableBundledRipgrep() {
|
|
683
|
+
try {
|
|
684
|
+
const executable = bundledRipgrepPath();
|
|
685
|
+
await access(executable, process.platform === 'win32' ? constants.F_OK : constants.X_OK);
|
|
686
|
+
return executable;
|
|
687
|
+
}
|
|
688
|
+
catch {
|
|
689
|
+
return undefined;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
function normalizeQuestions(raw) {
|
|
693
|
+
return raw.flatMap((value) => {
|
|
694
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
695
|
+
return [];
|
|
696
|
+
const question = value;
|
|
697
|
+
if (typeof question.id !== 'string' || typeof question.question !== 'string')
|
|
698
|
+
return [];
|
|
699
|
+
const options = Array.isArray(question.options)
|
|
700
|
+
? question.options.flatMap((option) => {
|
|
701
|
+
if (option === null || typeof option !== 'object' || Array.isArray(option))
|
|
702
|
+
return [];
|
|
703
|
+
const record = option;
|
|
704
|
+
if (typeof record.label !== 'string')
|
|
705
|
+
return [];
|
|
706
|
+
return [
|
|
707
|
+
{
|
|
708
|
+
value: record.label,
|
|
709
|
+
label: record.label,
|
|
710
|
+
description: typeof record.description === 'string' ? record.description : null
|
|
711
|
+
}
|
|
712
|
+
];
|
|
713
|
+
})
|
|
714
|
+
: [];
|
|
715
|
+
const multiSelect = question.multiSelect === true;
|
|
716
|
+
return [
|
|
717
|
+
{
|
|
718
|
+
id: question.id,
|
|
719
|
+
prompt: question.question,
|
|
720
|
+
input: options.length === 0 ? 'SHORT_TEXT' : multiSelect ? 'MULTI_SELECT' : 'SINGLE_SELECT',
|
|
721
|
+
options,
|
|
722
|
+
allowOther: true,
|
|
723
|
+
...(multiSelect ? { multiSelect: true } : {})
|
|
724
|
+
}
|
|
725
|
+
];
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
export function resolveRunModels(marAgentModel, marAgentModels) {
|
|
729
|
+
const configurations = [];
|
|
730
|
+
if (Array.isArray(marAgentModels))
|
|
731
|
+
for (const candidate of marAgentModels) {
|
|
732
|
+
const parsed = marAgentRuntimeModelConfigurationSchema.safeParse(candidate);
|
|
733
|
+
if (parsed.success)
|
|
734
|
+
configurations.push(parsed.data);
|
|
735
|
+
}
|
|
736
|
+
configurations.push(marAgentModel);
|
|
737
|
+
const seen = new Set();
|
|
738
|
+
return configurations.filter((configuration) => {
|
|
739
|
+
if (seen.has(configuration.id))
|
|
740
|
+
return false;
|
|
741
|
+
seen.add(configuration.id);
|
|
742
|
+
return true;
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
function runtimeModelFingerprint(model) {
|
|
746
|
+
const { apiKey, credential, imageGeneration, ...configuration } = model;
|
|
747
|
+
return {
|
|
748
|
+
...configuration,
|
|
749
|
+
...(imageGeneration === undefined
|
|
750
|
+
? {}
|
|
751
|
+
: {
|
|
752
|
+
imageGeneration: {
|
|
753
|
+
...imageGeneration,
|
|
754
|
+
credential: runtimeCredentialFingerprint(imageGeneration.credential)
|
|
755
|
+
}
|
|
756
|
+
}),
|
|
757
|
+
...(apiKey === undefined
|
|
758
|
+
? {}
|
|
759
|
+
: { apiKeyHash: createHash('sha256').update(apiKey).digest('hex') }),
|
|
760
|
+
credential: runtimeCredentialFingerprint(credential)
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
function runtimeCredentialFingerprint(credential) {
|
|
764
|
+
return credential?.type === 'INLINE_API_KEY'
|
|
765
|
+
? {
|
|
766
|
+
type: credential.type,
|
|
767
|
+
valueHash: createHash('sha256').update(credential.value).digest('hex')
|
|
768
|
+
}
|
|
769
|
+
: credential === undefined
|
|
770
|
+
? undefined
|
|
771
|
+
: {
|
|
772
|
+
type: credential.type,
|
|
773
|
+
credentialId: credential.credentialId
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
async function closeModelCredentialProviders(models) {
|
|
777
|
+
await Promise.allSettled([
|
|
778
|
+
...new Set(models.flatMap((model) => [
|
|
779
|
+
...(model.credentialProvider === undefined ? [] : [model.credentialProvider]),
|
|
780
|
+
...(model.imageGeneration?.credentialProvider === undefined
|
|
781
|
+
? []
|
|
782
|
+
: [model.imageGeneration.credentialProvider])
|
|
783
|
+
]))
|
|
784
|
+
].map((provider) => provider.close()));
|
|
785
|
+
}
|