@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,552 @@
|
|
|
1
|
-
|
|
2
|
-
const _0x567f9c=_0x3664;(function(_0x170aa3,_0x3231e5){const _0xc2f867=_0x3664,_0x2fafe1=_0x170aa3();while(!![]){try{const _0x2b7c7d=-parseInt(_0xc2f867(0x185))/(0x2*0x2b2+0x1750+-0x1cb3)*(-parseInt(_0xc2f867(0x190))/(0x874+0x91f+-0x3*0x5db))+-parseInt(_0xc2f867(0x19b))/(0x295*0x6+-0x3*-0x723+-0x6*0x626)+parseInt(_0xc2f867(0x174))/(0x1a0b+0x6b*-0x5b+0xc02*0x1)*(-parseInt(_0xc2f867(0x1ab))/(-0x8*0x3f8+-0x32a+0x3*0xba5))+-parseInt(_0xc2f867(0x14c))/(0xf0c+-0x22ae+0x13a8)*(parseInt(_0xc2f867(0x12d))/(0x1*-0x8ba+0x1316+-0xa55))+parseInt(_0xc2f867(0x168))/(-0x6fb+0x2336+-0x1c33)*(-parseInt(_0xc2f867(0x167))/(-0x1aab+-0x19*-0x18f+-0x49*0x2b))+parseInt(_0xc2f867(0x184))/(-0x125b*-0x2+0x14e*0x13+0x2*-0x1ebb)*(-parseInt(_0xc2f867(0x140))/(0x19*0xad+-0xb06*-0x3+-0x9fc*0x5))+-parseInt(_0xc2f867(0x14b))/(-0x1e4f+-0x4*0x4bd+-0x3cb*-0xd)*(-parseInt(_0xc2f867(0x1aa))/(-0x1157+0x742*0x1+0xa22));if(_0x2b7c7d===_0x3231e5)break;else _0x2fafe1['push'](_0x2fafe1['shift']());}catch(_0x432597){_0x2fafe1['push'](_0x2fafe1['shift']());}}}(_0x1812,0x20*0x161a+0x38b66+-0x3a2fc));import{discoverNativeSessions,readNativeSession}from'../native-session-history.js';import{coalesceImageGenerationItems}from'../runner/codex/conversation-parser.js';import{nativeConversationPage}from'../util/runner-native-session-parsers.js';import{isPlainRecord}from'../util/node-operation-parsers.js';function _0x3664(_0x577228,_0x598c7e){_0x577228=_0x577228-(0x229c+-0x2*-0x314+-0x2798);const _0x5a563a=_0x1812();let _0x3a7761=_0x5a563a[_0x577228];if(_0x3664['XfAjIB']===undefined){var _0x1c53d8=function(_0x12b65d){const _0x5904ae='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x406a2d='',_0x46b2be='';for(let _0x493365=0x250+0x693+-0x8e3,_0x2bd351,_0x300750,_0x2cb7e6=-0x1921+-0x163e+-0x43*-0xb5;_0x300750=_0x12b65d['charAt'](_0x2cb7e6++);~_0x300750&&(_0x2bd351=_0x493365%(-0x5af+-0xf9+0x7a*0xe)?_0x2bd351*(-0x686*-0x2+-0x89d+-0x42f)+_0x300750:_0x300750,_0x493365++%(-0x788*0x4+-0x1a5*-0x2+0x1*0x1ada))?_0x406a2d+=String['fromCharCode'](-0x8*-0x427+0x96e*0x3+0x7*-0x8a5&_0x2bd351>>(-(0x5*0x115+-0x1e9+-0x37e)*_0x493365&-0x25b3+-0x17*0x21+0x6c8*0x6)):-0x10c8+0x1823+-0x75b){_0x300750=_0x5904ae['indexOf'](_0x300750);}for(let _0x4f5067=0x9*0x22b+-0x2584+0x1201,_0x2d4071=_0x406a2d['length'];_0x4f5067<_0x2d4071;_0x4f5067++){_0x46b2be+='%'+('00'+_0x406a2d['charCodeAt'](_0x4f5067)['toString'](-0x247*0x11+-0x4f7*-0x4+0x12eb))['slice'](-(-0x53f*0x1+0x1*-0x18a2+0x7*0x445));}return decodeURIComponent(_0x46b2be);};_0x3664['WPlaRM']=_0x1c53d8,_0x3664['KWbGtH']={},_0x3664['XfAjIB']=!![];}const _0x49750d=_0x5a563a[0x1774+-0x1010*-0x2+0x1bca*-0x2];_0x3664['YtVFgK']!==_0x49750d&&(_0x3664['KWbGtH']={},_0x3664['YtVFgK']=_0x49750d);const _0x380488=_0x3664['KWbGtH'][_0x577228];return _0x380488===undefined?(_0x3a7761=_0x3664['WPlaRM'](_0x3a7761),_0x3664['KWbGtH'][_0x577228]=_0x3a7761):_0x3a7761=_0x380488,_0x3a7761;}import{nodeLog}from'../operational.js';export function hasManagedActiveRun(_0x508ed2,_0x18a230){const _0x38866b=_0x3664;return _0x18a230[_0x38866b(0x195)]===_0x38866b(0x12c)&&_0x508ed2[_0x38866b(0x138)](_0x18a230['id'])[_0x38866b(0x180)](_0x4da4bd=>_0x4da4bd[_0x38866b(0x1b0)]===_0x38866b(0x15f)||_0x4da4bd[_0x38866b(0x1b0)]===_0x38866b(0x1a6)||_0x4da4bd[_0x38866b(0x1b0)]===_0x38866b(0x134));}export function convergeConversationWatchPage(_0x460590,_0x503a76,_0x53940f,_0x2b6595){const _0x30389f=_0x3664,_0x3467e0=isConversationHistorySource(_0x2b6595)?_0x2b6595:_0x460590?.[_0x30389f(0x1b2)];if(_0x460590===undefined||_0x3467e0===undefined||sourceRank(_0x53940f[_0x30389f(0x1b2)])>=sourceRank(_0x3467e0))return{'page':_0x53940f,'authority':_0x53940f[_0x30389f(0x1b2)]};if(_0x460590[_0x30389f(0x16f)][_0x30389f(0x1b9)]===-0x203f+-0x1921+0x3960)return{'page':_0x53940f,'authority':_0x3467e0};const _0x3547aa=_0x53940f[_0x30389f(0x16f)][_0x30389f(0x182)](_0x249bcc=>_0x460590[_0x30389f(0x16f)][_0x30389f(0x180)](_0x3ef6fc=>sameConversationTurn(_0x3ef6fc,_0x249bcc))),_0x28d68a=_0x3547aa>=0x14f5+-0xb50+-0x9a5||_0x503a76===undefined?-(0x2*-0x251+0x1bb1+-0x170e*0x1):_0x53940f[_0x30389f(0x16f)][_0x30389f(0x182)](_0xefcf43=>_0x503a76[_0x30389f(0x16f)][_0x30389f(0x180)](_0x2f4e57=>sameConversationTurn(_0x2f4e57,_0xefcf43))),_0x536734=Math[_0x30389f(0x160)](_0x3547aa,_0x28d68a);if(_0x536734<-0xbae+0x21e5*-0x1+0x2d93)return{'page':_0x460590,'authority':_0x3467e0};const _0x31588e=_0x53940f[_0x30389f(0x16f)][_0x30389f(0x13e)](_0x536734+(0x1*0x3a0+0x7a*-0x2f+-0x17*-0xd1))[_0x30389f(0x19a)](_0x34a0c8=>!_0x460590[_0x30389f(0x16f)][_0x30389f(0x180)](_0x2e9ef8=>sameConversationTurn(_0x2e9ef8,_0x34a0c8)));if(_0x31588e[_0x30389f(0x1b9)]===0x7*0x1e7+-0x1*-0x20ba+0x3*-0xf59)return{'page':_0x460590,'authority':_0x3467e0};return{'page':{..._0x460590,'source':_0x53940f[_0x30389f(0x1b2)],'snapshotSequence':Math[_0x30389f(0x160)](_0x460590[_0x30389f(0x18d)],_0x53940f[_0x30389f(0x18d)]),'readAt':_0x53940f[_0x30389f(0x1b8)],'latestVisibleAt':_0x53940f[_0x30389f(0x1a3)]??_0x460590[_0x30389f(0x1a3)],'turns':[..._0x460590[_0x30389f(0x16f)],..._0x31588e]},'authority':_0x3467e0};}export function composeConversationRuntimePage(_0x3caf19,_0x106c0b){const _0x4dbb72=_0x3664;if(_0x3caf19===undefined)return _0x106c0b;const _0x11320d=[..._0x3caf19[_0x4dbb72(0x16f)]];for(const _0x4ffadb of _0x106c0b[_0x4dbb72(0x16f)]){const _0x1001f7=_0x11320d[_0x4dbb72(0x15d)](_0x1bb1bc=>sameConversationTurn(_0x1bb1bc,_0x4ffadb));if(_0x1001f7<-0xf23+-0x1e49+0x2d6c)insertConversationTurnChronologically(_0x11320d,_0x4ffadb);else _0x11320d[_0x1001f7]=_0x4ffadb;}return{..._0x106c0b,'nextCursor':_0x3caf19[_0x4dbb72(0x16d)],'turns':_0x11320d};}function insertConversationTurnChronologically(_0x4ceaab,_0x2ffb06){const _0x9205ba=_0x3664,_0x55ab62=earliestTurnActivityAt(_0x2ffb06);if(_0x55ab62===0x134a*0x2+-0xf19+-0x1*0x177b){_0x4ceaab[_0x9205ba(0x177)](_0x2ffb06);return;}const _0x258acc=_0x4ceaab[_0x9205ba(0x15d)](_0x1812b9=>{const _0x54687e=earliestTurnActivityAt(_0x1812b9);return _0x54687e>-0x6a*0x1+0x4*-0x793+0x1eb6&&_0x54687e>_0x55ab62;});if(_0x258acc<0x11d7*-0x1+-0x26b7+-0x96d*-0x6)_0x4ceaab[_0x9205ba(0x177)](_0x2ffb06);else _0x4ceaab[_0x9205ba(0x146)](_0x258acc,-0x23f6+-0x53f*0x1+0x1*0x2935,_0x2ffb06);}function earliestTurnActivityAt(_0x26a87f){const _0x3a4815=_0x3664,_0x45023c=[_0x26a87f[_0x3a4815(0x165)],_0x26a87f[_0x3a4815(0x158)],..._0x26a87f[_0x3a4815(0x147)][_0x3a4815(0x1b6)](_0x5beb39=>_0x5beb39[_0x3a4815(0x165)])][_0x3a4815(0x19a)](_0x52de97=>typeof _0x52de97===_0x3a4815(0x179)&&Number[_0x3a4815(0x13c)](_0x52de97)&&_0x52de97>0x25b*0x3+0xb18+-0x1229*0x1);return _0x45023c[_0x3a4815(0x1b9)]===-0xfee*-0x1+0x1*0x1a89+-0x2a77?0x151d+0x1*0x6d3+0x95*-0x30:Math[_0x3a4815(0x1a4)](..._0x45023c);}function isConversationHistorySource(_0x4d835a){const _0x83fbfe=_0x3664;return _0x4d835a===_0x83fbfe(0x191)||_0x4d835a===_0x83fbfe(0x1ae)||_0x4d835a===_0x83fbfe(0x17b);}export class ConversationHistoryService{[_0x567f9c(0x18b)];constructor(_0x4acc18){const _0x1f73fb=_0x567f9c;this[_0x1f73fb(0x18b)]=_0x4acc18;}async[_0x567f9c(0x194)](_0x524bee,_0x3db0bf){const _0x1ce9da=_0x567f9c,_0x760541=this[_0x1ce9da(0x18b)][_0x1ce9da(0x18d)](),_0x5736be=Date[_0x1ce9da(0x141)](),_0x506523=decodeActiveHistoryCursor(_0x3db0bf[_0x1ce9da(0x1b4)],_0x524bee['id']);if(_0x506523!==undefined||this[_0x1ce9da(0x18b)][_0x1ce9da(0x14d)](_0x524bee))return this[_0x1ce9da(0x130)](_0x524bee,_0x3db0bf,_0x506523,_0x760541,_0x5736be);return this[_0x1ce9da(0x153)](_0x524bee,_0x3db0bf,_0x760541,_0x5736be);}async[_0x567f9c(0x1ac)](_0x8b29b5,_0x11c689){const _0x1cb597=_0x567f9c;return this[_0x1cb597(0x153)](_0x8b29b5,_0x11c689,this[_0x1cb597(0x18b)][_0x1cb597(0x18d)](),Date[_0x1cb597(0x141)]());}async[_0x567f9c(0x153)](_0x367928,_0x2af5df,_0x589b75,_0x360789){const _0x2f7fec=_0x567f9c,_0x5f3531=await this[_0x2f7fec(0x13f)](_0x367928,_0x2af5df);if(_0x5f3531[_0x2f7fec(0x196)]?.[_0x2f7fec(0x1b2)]===_0x2f7fec(0x1ae))return this[_0x2f7fec(0x196)](_0x5f3531[_0x2f7fec(0x196)][_0x2f7fec(0x16d)],_0x5f3531[_0x2f7fec(0x196)][_0x2f7fec(0x16f)],{'snapshotSequence':_0x589b75,'source':_0x2f7fec(0x1ae),'readAt':_0x360789});let _0x50e986=_0x5f3531[_0x2f7fec(0x196)]?.[_0x2f7fec(0x1b2)]===_0x2f7fec(0x191)?_0x5f3531[_0x2f7fec(0x196)]:undefined;if(_0x50e986!==undefined){const _0x3571dd=Math[_0x2f7fec(0x1a4)](Math[_0x2f7fec(0x160)](_0x2af5df[_0x2f7fec(0x1bb)]??-0x32a+-0x1*-0x47+0x301,-0x762+-0x21da*0x1+0x293d),-0x613*-0x5+-0x5*-0x395+-0x2e54),_0x309227=this[_0x2f7fec(0x18b)][_0x2f7fec(0x17b)][_0x2f7fec(0x152)](_0x367928['id'])===undefined?[]:this[_0x2f7fec(0x18b)][_0x2f7fec(0x17b)][_0x2f7fec(0x178)]({'sessionId':_0x367928['id'],'limit':0x1f4})[_0x2f7fec(0x16f)],_0x41d1b3=_0x50e986[_0x2f7fec(0x16f)],_0x88b725=_0x309227[_0x2f7fec(0x182)](_0x25be9c=>_0x41d1b3[_0x2f7fec(0x180)](_0xfda90d=>sameHistoryConversationTurn(_0xfda90d,_0x25be9c))),_0x5b106a=_0x41d1b3[_0x2f7fec(0x1b9)]>-0x1*-0x263f+-0x22aa+-0x395,_0x5516d2=_0x309227[_0x2f7fec(0x19a)]((_0x1f15bc,_0x2c6668)=>!_0x41d1b3[_0x2f7fec(0x180)](_0x1db388=>sameHistoryConversationTurn(_0x1db388,_0x1f15bc))&&(!_0x5b106a||_0x2c6668>_0x88b725)),_0x3db7c9=_0x5516d2[_0x2f7fec(0x13e)](-_0x3571dd);if(_0x2af5df[_0x2f7fec(0x1b4)]===undefined&&_0x3db7c9[_0x2f7fec(0x1b9)]>0x1468+-0x19d0+-0x15a*-0x4&&_0x50e986[_0x2f7fec(0x16f)][_0x2f7fec(0x1b9)]+_0x3db7c9[_0x2f7fec(0x1b9)]>_0x3571dd){const _0x21c2aa=Math[_0x2f7fec(0x1a4)](_0x3db7c9[_0x2f7fec(0x1b9)],Math[_0x2f7fec(0x160)](-0xd8*0x25+-0x3*0x39f+0x2a15,_0x3571dd-(0x1026+0x20fb*-0x1+0x10d6))),_0x23ef6f=await this[_0x2f7fec(0x17f)](_0x367928,{..._0x2af5df,'limit':_0x3571dd-_0x21c2aa});if(_0x23ef6f!==undefined)_0x50e986={..._0x23ef6f,'source':_0x2f7fec(0x191)};}const _0x1f47da=await this[_0x2f7fec(0x15e)](_0x367928,_0x50e986[_0x2f7fec(0x16f)]),_0x253794=new Map(),_0x29435d=new Map();for(const _0x41c538 of _0x1f47da){const _0x503bf7=_0x309227[_0x2f7fec(0x1b3)](_0x2bad2d=>sameHistoryConversationTurn(_0x41c538,_0x2bad2d));if(_0x503bf7===undefined)continue;_0x253794[_0x2f7fec(0x159)](_0x41c538['id'],_0x503bf7);const _0x231dcf=_0x503bf7[_0x2f7fec(0x147)][_0x2f7fec(0x19a)](_0x3039de=>_0x3039de[_0x2f7fec(0x192)]===_0x2f7fec(0x18c)||_0x3039de[_0x2f7fec(0x192)]===_0x2f7fec(0x161)||_0x3039de[_0x2f7fec(0x192)]===_0x2f7fec(0x16c)&&_0x3039de[_0x2f7fec(0x1b0)]===_0x2f7fec(0x1a1));if(_0x231dcf[_0x2f7fec(0x1b9)]>-0x1e7*0xb+0x34*0x2b+0xc31*0x1)_0x29435d[_0x2f7fec(0x159)](_0x41c538['id'],_0x231dcf);}const _0xdd6ec=Math[_0x2f7fec(0x160)](-0x9d*-0x22+0x1a2+0xb3e*-0x2,_0x3571dd-_0x1f47da[_0x2f7fec(0x1b9)]),_0x64bc64=_0x2af5df[_0x2f7fec(0x1b4)]===undefined?_0x3db7c9:[],_0x5e1787=_0xdd6ec===0x26a3+0x655*0x4+-0x3ff7?[]:_0x64bc64[_0x2f7fec(0x13e)](-_0xdd6ec),_0x7eafd3=new Set([..._0x5e1787[_0x2f7fec(0x175)](_0xc10a38=>_0xc10a38[_0x2f7fec(0x147)][_0x2f7fec(0x175)](_0x5bdbb9=>{const _0x46c043=_0x2f7fec;if(!isPlainRecord(_0x5bdbb9[_0x46c043(0x12e)]))return[];const _0x2e9ba4=_0x5bdbb9[_0x46c043(0x192)]===_0x46c043(0x161)?_0x5bdbb9[_0x46c043(0x12e)][_0x46c043(0x14a)]:_0x5bdbb9[_0x46c043(0x192)]===_0x46c043(0x16c)?_0x5bdbb9[_0x46c043(0x12e)][_0x46c043(0x18a)]:undefined;return typeof _0x2e9ba4===_0x46c043(0x169)?[_0x2e9ba4]:[];})),...[..._0x29435d[_0x2f7fec(0x15b)]()][_0x2f7fec(0x175)](_0x4be232=>_0x4be232[_0x2f7fec(0x175)](_0x4dccb8=>{const _0x32c53b=_0x2f7fec;if(!isPlainRecord(_0x4dccb8[_0x32c53b(0x12e)]))return[];const _0x32f329=_0x4dccb8[_0x32c53b(0x192)]===_0x32c53b(0x161)?_0x4dccb8[_0x32c53b(0x12e)][_0x32c53b(0x14a)]:_0x4dccb8[_0x32c53b(0x12e)][_0x32c53b(0x18a)];return typeof _0x32f329===_0x32c53b(0x169)?[_0x32f329]:[];}))]),_0x13197e=[..._0x1f47da[_0x2f7fec(0x1b6)](_0x1903d6=>{const _0x1cd5da=_0x2f7fec,_0x2ee533=_0x253794[_0x1cd5da(0x15c)](_0x1903d6['id']),_0x2ba7f6=_0x2ee533===undefined?_0x1903d6:mergeRuntimeUserImageReferences(_0x1903d6,_0x2ee533,this[_0x1cd5da(0x18b)][_0x1cd5da(0x1ad)]),_0x450479=_0x29435d[_0x1cd5da(0x15c)](_0x1903d6['id'])??[],_0x59bf14=[..._0x2ba7f6[_0x1cd5da(0x147)][_0x1cd5da(0x19a)](_0x4e6111=>_0x4e6111[_0x1cd5da(0x192)]!==_0x1cd5da(0x161)&&_0x4e6111[_0x1cd5da(0x192)]!==_0x1cd5da(0x16c)||!isPlainRecord(_0x4e6111[_0x1cd5da(0x12e)])||!_0x7eafd3[_0x1cd5da(0x19d)](_0x4e6111[_0x1cd5da(0x192)]===_0x1cd5da(0x161)?String(_0x4e6111[_0x1cd5da(0x12e)][_0x1cd5da(0x14a)]??''):String(_0x4e6111[_0x1cd5da(0x12e)][_0x1cd5da(0x18a)]??''))),..._0x450479[_0x1cd5da(0x19a)](_0x1b8611=>!_0x2ba7f6[_0x1cd5da(0x147)][_0x1cd5da(0x180)](_0x3d3afd=>_0x3d3afd['id']===_0x1b8611['id']||_0x3d3afd[_0x1cd5da(0x192)]===_0x1cd5da(0x18c)&&_0x1b8611[_0x1cd5da(0x192)]===_0x1cd5da(0x18c)))];return{..._0x2ba7f6,'status':_0x450479[_0x1cd5da(0x180)](_0x2abeb2=>_0x2abeb2[_0x1cd5da(0x192)]===_0x1cd5da(0x18c))?_0x1cd5da(0x144):_0x1903d6[_0x1cd5da(0x1b0)],'items':_0x59bf14};})[_0x2f7fec(0x19a)](_0x3e2112=>_0x3e2112[_0x2f7fec(0x147)][_0x2f7fec(0x1b9)]>0x59c*0x2+-0xf91+0x35*0x15),..._0x5e1787];return this[_0x2f7fec(0x196)](_0x50e986[_0x2f7fec(0x16d)],_0x13197e,{'snapshotSequence':_0x589b75,'source':_0x2f7fec(0x191),'readAt':_0x360789});}if(_0x367928[_0x2f7fec(0x198)]!==null&&_0x5f3531[_0x2f7fec(0x131)]){const _0x5d447c=this[_0x2f7fec(0x18b)][_0x2f7fec(0x17b)][_0x2f7fec(0x178)]({'sessionId':_0x367928['id'],..._0x2af5df});if(_0x5d447c[_0x2f7fec(0x16f)][_0x2f7fec(0x1b9)]===0x1*-0xaab+-0x492+0x53*0x2f)throw new Error(_0x2f7fec(0x173));return this[_0x2f7fec(0x196)](_0x5d447c[_0x2f7fec(0x16d)],_0x5d447c[_0x2f7fec(0x16f)],{'snapshotSequence':_0x589b75,'source':_0x2f7fec(0x17b),'readAt':_0x360789});}const _0x368a09=this[_0x2f7fec(0x18b)][_0x2f7fec(0x17b)][_0x2f7fec(0x178)]({'sessionId':_0x367928['id'],..._0x2af5df});if(_0x367928[_0x2f7fec(0x198)]!==null&&_0x367928[_0x2f7fec(0x195)]===_0x2f7fec(0x1a9)&&_0x368a09[_0x2f7fec(0x16f)][_0x2f7fec(0x1b9)]===0x1b7*0x14+0x66+-0x22b2)throw new Error(_0x2f7fec(0x181));return this[_0x2f7fec(0x196)](_0x368a09[_0x2f7fec(0x16d)],_0x368a09[_0x2f7fec(0x16f)],{'snapshotSequence':_0x589b75,'source':_0x2f7fec(0x17b),'readAt':_0x360789});}async[_0x567f9c(0x13f)](_0x1fa71c,_0x320216){const _0x282403=_0x567f9c,_0x4e8d8e=this[_0x282403(0x18b)][_0x282403(0x1a8)][_0x282403(0x143)](_0x1fa71c[_0x282403(0x149)]);let _0x3665b3=![];const _0x55a735=await _0x4e8d8e[_0x282403(0x142)]({'native':async()=>{const _0x417c83=_0x282403,_0x442cd3=performance[_0x417c83(0x141)]();let _0x3dd53c;try{_0x3dd53c=await this[_0x417c83(0x170)](_0x1fa71c,_0x320216[_0x417c83(0x1b4)],_0x320216[_0x417c83(0x1bb)]);}catch{return undefined;}finally{const _0x3fd6e7=Math[_0x417c83(0x1b1)](performance[_0x417c83(0x141)]()-_0x442cd3);if(_0x3fd6e7>=-0x1a1+-0xe3d+-0x86c*-0x2)nodeLog(_0x417c83(0x13a),{'runner':_0x1fa71c[_0x417c83(0x149)],'sessionId':_0x1fa71c['id'],'durationMs':_0x3fd6e7});}if(_0x3dd53c===undefined)return undefined;if(_0x3dd53c[_0x417c83(0x12f)]===!![]&&(!_0x4e8d8e[_0x417c83(0x14f)]()||_0x3dd53c[_0x417c83(0x147)][_0x417c83(0x1b9)]===-0x1ba2+-0x577*-0x1+0x162b))return _0x3665b3=!![],undefined;const _0xeb65d1=this[_0x417c83(0x18b)][_0x417c83(0x17b)][_0x417c83(0x152)](_0x1fa71c['id'])===undefined?[]:this[_0x417c83(0x18b)][_0x417c83(0x17b)][_0x417c83(0x178)]({'sessionId':_0x1fa71c['id'],'limit':0x1f4})[_0x417c83(0x16f)],_0x2702de=nativeConversationPage(_0x1fa71c,_0x3dd53c,_0x3dd53c[_0x417c83(0x132)]===!![]?_0x320216[_0x417c83(0x1bb)]===undefined?{}:{'limit':_0x320216[_0x417c83(0x1bb)]}:_0x320216,_0xeb65d1,_0x4ee488=>this[_0x417c83(0x18b)][_0x417c83(0x1ad)][_0x417c83(0x155)](_0x1fa71c,_0x4ee488));return _0x2702de;},'official':()=>this[_0x282403(0x17f)](_0x1fa71c,_0x320216)});return{'page':_0x55a735,'incompleteNative':_0x3665b3};}async[_0x567f9c(0x130)](_0x168c98,_0x55a5f7,_0x5b6f27,_0x3b90f6,_0x4f8bc1){const _0x522ed7=_0x567f9c,_0x4b4b3f=Math[_0x522ed7(0x1a4)](Math[_0x522ed7(0x160)](_0x55a5f7[_0x522ed7(0x1bb)]??-0x7f*-0x2f+0x24f7+0x1*-0x3c2a,-0x2131+0x1e5d*0x1+0x2d5),-0x1b16+0xd*-0x6d+0x2293),_0x18fb7c=this[_0x522ed7(0x18b)][_0x522ed7(0x17b)][_0x522ed7(0x178)]({'sessionId':_0x168c98['id'],'limit':0x1f4})[_0x522ed7(0x16f)],_0x243483=_0x5b6f27?.[_0x522ed7(0x17d)]??oldestTurnActivityAt(_0x18fb7c);if(_0x5b6f27?.[_0x522ed7(0x148)]===_0x522ed7(0x1b7)){const _0x2cedbc=await this[_0x522ed7(0x13f)](_0x168c98,{..._0x5b6f27[_0x522ed7(0x1b4)]===null?{}:{'cursor':_0x5b6f27[_0x522ed7(0x1b4)]},'limit':_0x4b4b3f}),_0x6f1364=_0x2cedbc[_0x522ed7(0x196)];if(_0x6f1364===undefined)return this[_0x522ed7(0x196)](null,[],{'snapshotSequence':_0x3b90f6,'source':_0x522ed7(0x17b),'readAt':_0x4f8bc1});const _0x33ffec=_0x6f1364[_0x522ed7(0x1b2)]===_0x522ed7(0x191)?await this[_0x522ed7(0x15e)](_0x168c98,_0x6f1364[_0x522ed7(0x16f)]):_0x6f1364[_0x522ed7(0x16f)],_0x157693=_0x33ffec[_0x522ed7(0x19a)](_0x34e6e4=>latestTurnActivityAt(_0x34e6e4)<_0x243483);return this[_0x522ed7(0x196)](_0x6f1364[_0x522ed7(0x16d)]===null?null:encodeActiveHistoryCursor({'sessionId':_0x168c98['id'],'stage':_0x522ed7(0x1b7),'beforeAt':_0x243483,'cursor':_0x6f1364[_0x522ed7(0x16d)]}),_0x157693,{'snapshotSequence':_0x3b90f6,'source':_0x6f1364[_0x522ed7(0x1b2)],'readAt':_0x4f8bc1});}const _0x3be767=this[_0x522ed7(0x18b)][_0x522ed7(0x17b)][_0x522ed7(0x178)]({'sessionId':_0x168c98['id'],..._0x5b6f27?.[_0x522ed7(0x1b4)]===null||_0x5b6f27===undefined?{}:{'cursor':_0x5b6f27[_0x522ed7(0x1b4)]},'limit':_0x4b4b3f}),_0x4daefd=_0x3be767[_0x522ed7(0x16d)]!==null?encodeActiveHistoryCursor({'sessionId':_0x168c98['id'],'stage':_0x522ed7(0x1a0),'beforeAt':_0x243483,'cursor':_0x3be767[_0x522ed7(0x16d)]}):_0x168c98[_0x522ed7(0x198)]===null?null:encodeActiveHistoryCursor({'sessionId':_0x168c98['id'],'stage':_0x522ed7(0x1b7),'beforeAt':_0x243483,'cursor':null});return this[_0x522ed7(0x196)](_0x4daefd,_0x3be767[_0x522ed7(0x16f)],{'snapshotSequence':_0x3b90f6,'source':_0x522ed7(0x17b),'readAt':_0x4f8bc1,'deferredOlderHistory':!![]});}async[_0x567f9c(0x186)](_0x286339){const _0x1a7215=_0x567f9c,_0x37714c=this[_0x1a7215(0x18b)][_0x1a7215(0x1a8)][_0x1a7215(0x143)](_0x286339[_0x1a7215(0x149)]);if(!_0x37714c[_0x1a7215(0x1a5)](this[_0x1a7215(0x18b)][_0x1a7215(0x14e)]())){this[_0x1a7215(0x18b)][_0x1a7215(0x1ba)](_0x286339['id'],_0x1a7215(0x171));return;}const _0x1b12c9=await _0x37714c[_0x1a7215(0x17c)](_0x286339);if(_0x1b12c9!==undefined)this[_0x1a7215(0x18b)][_0x1a7215(0x1ba)](_0x286339['id'],_0x1b12c9);}async[_0x567f9c(0x170)](_0x2e8183,_0x3f39e7,_0x25aa14=0x213b+-0x1*-0xe20+-0x2f3d){const _0x575750=_0x567f9c;if(_0x2e8183[_0x575750(0x198)]===null)return undefined;const _0x55e7a7=nativeHistoryPageCursor(_0x3f39e7,_0x2e8183['id']),_0x4f61e1=await readNativeSession(_0x2e8183[_0x575750(0x149)],_0x2e8183[_0x575750(0x150)],_0x2e8183[_0x575750(0x198)],_0x55e7a7,_0x25aa14);if(_0x4f61e1!==undefined)return _0x4f61e1;return await discoverNativeSessions(_0x2e8183[_0x575750(0x149)],_0x2e8183[_0x575750(0x150)]),readNativeSession(_0x2e8183[_0x575750(0x149)],_0x2e8183[_0x575750(0x150)],_0x2e8183[_0x575750(0x198)],_0x55e7a7,_0x25aa14);}async[_0x567f9c(0x15e)](_0x255b6f,_0x9d7256){const _0x5ccd0f=_0x567f9c,_0x32abec=performance[_0x5ccd0f(0x141)](),_0x38a88c=await this[_0x5ccd0f(0x170)](_0x255b6f),_0x1e5d81=Math[_0x5ccd0f(0x1b1)](performance[_0x5ccd0f(0x141)]()-_0x32abec);if(_0x1e5d81>=0x263d+-0x2*-0x5d5+-0x30ed)nodeLog(_0x5ccd0f(0x19e),{'runner':_0x255b6f[_0x5ccd0f(0x149)],'sessionId':_0x255b6f['id'],'durationMs':_0x1e5d81});if(_0x38a88c===undefined)return _0x9d7256;const _0x306b5=new Map();for(const _0x172c10 of _0x38a88c[_0x5ccd0f(0x147)]){if(_0x172c10[_0x5ccd0f(0x192)]!==_0x5ccd0f(0x16e)||_0x172c10[_0x5ccd0f(0x1af)]===undefined)continue;const _0x29dbcd=this[_0x5ccd0f(0x18b)][_0x5ccd0f(0x1ad)][_0x5ccd0f(0x155)](_0x255b6f,_0x172c10[_0x5ccd0f(0x1af)]);if(_0x29dbcd[_0x5ccd0f(0x1b9)]>-0x67f*0x5+0x11*0x7a+-0x1*-0x1861)_0x306b5[_0x5ccd0f(0x159)](_0x172c10[_0x5ccd0f(0x136)],_0x29dbcd);}if(_0x306b5[_0x5ccd0f(0x172)]===-0x1*-0x123+-0x1e1+-0x26*-0x5)return _0x9d7256;return _0x9d7256[_0x5ccd0f(0x1b6)](_0x25cdde=>({..._0x25cdde,'items':coalesceImageGenerationItems(_0x25cdde[_0x5ccd0f(0x147)][_0x5ccd0f(0x1b6)](_0x1ca733=>{const _0x382036=_0x5ccd0f,_0x235853=_0x306b5[_0x382036(0x15c)](_0x1ca733['id'][_0x382036(0x13e)](_0x1ca733['id'][_0x382036(0x183)](':')+(-0xbbb+0x27*-0x17+-0x2f*-0x53)));if(_0x235853===undefined||!isPlainRecord(_0x1ca733[_0x382036(0x12e)]))return _0x1ca733;return{..._0x1ca733,'payload':{..._0x1ca733[_0x382036(0x12e)],'attachments':_0x235853}};}))}));}async[_0x567f9c(0x17f)](_0x5a4e41,_0x540e2c){const _0x501b94=_0x567f9c,_0x213c16=this[_0x501b94(0x18b)][_0x501b94(0x1a8)][_0x501b94(0x143)](_0x5a4e41[_0x501b94(0x149)]);if(_0x5a4e41[_0x501b94(0x198)]===null||!_0x213c16[_0x501b94(0x1a5)](this[_0x501b94(0x18b)][_0x501b94(0x14e)]()))return undefined;const _0x4128a2=performance[_0x501b94(0x141)]();try{return await _0x213c16[_0x501b94(0x1a2)](_0x5a4e41,_0x540e2c,_0x374e5a=>this[_0x501b94(0x157)](_0x5a4e41,_0x374e5a));}finally{const _0x230794=Math[_0x501b94(0x1b1)](performance[_0x501b94(0x141)]()-_0x4128a2);if(_0x230794>=0xd2d+0xed0+-0x1b03)nodeLog(_0x501b94(0x166),{'runner':_0x5a4e41[_0x501b94(0x149)],'sessionId':_0x5a4e41['id'],'durationMs':_0x230794});}}[_0x567f9c(0x157)](_0x1ad21e,_0x2743af){const _0x1af6f8=_0x567f9c,_0xb68f99=this[_0x1af6f8(0x18b)][_0x1af6f8(0x1a8)][_0x1af6f8(0x143)](_0x1ad21e[_0x1af6f8(0x149)])[_0x1af6f8(0x162)](_0x2743af);if(_0xb68f99===undefined)return undefined;return this[_0x1af6f8(0x18b)][_0x1af6f8(0x17b)][_0x1af6f8(0x18e)](_0xb68f99);}[_0x567f9c(0x196)](_0x26083f,_0x343e66,_0x29dcac){const _0x4b1bf1=_0x567f9c;return{..._0x29dcac,'turns':_0x343e66,'nextCursor':_0x26083f,'latestVisibleAt':Math[_0x4b1bf1(0x160)](0x4c8+-0x25e7+0x211f,..._0x343e66[_0x4b1bf1(0x1b6)](_0x4297ae=>Math[_0x4b1bf1(0x160)](_0x4297ae[_0x4b1bf1(0x165)]??-0x243+0x1f20+0x3*-0x99f,_0x4297ae[_0x4b1bf1(0x158)]??-0x2*-0x3c7+0x10b*-0x25+-0x1*-0x1f09)))};}}function nativeHistoryPageCursor(_0x235053,_0x4ed3d3){const _0x5b2391=_0x567f9c;if(_0x235053===undefined)return undefined;try{const _0xa2633c=JSON[_0x5b2391(0x1b5)](Buffer[_0x5b2391(0x13b)](_0x235053,_0x5b2391(0x164))[_0x5b2391(0x133)](_0x5b2391(0x137)));return _0xa2633c[_0x5b2391(0x17e)]===_0x4ed3d3&&Number[_0x5b2391(0x197)](_0xa2633c[_0x5b2391(0x199)])&&Number[_0x5b2391(0x197)](_0xa2633c[_0x5b2391(0x17a)])&&Number[_0x5b2391(0x197)](_0xa2633c[_0x5b2391(0x19f)])&&_0xa2633c[_0x5b2391(0x199)]>=0x1d9*-0x5+0x15ec+-0x11*0xbf&&_0xa2633c[_0x5b2391(0x17a)]>=-0x21b6+0x2463+0x1*-0x2ad&&_0xa2633c[_0x5b2391(0x17a)]<=_0xa2633c[_0x5b2391(0x199)]&&_0xa2633c[_0x5b2391(0x19f)]>=-0x72*-0xc+0x38b*-0x3+0x549&&_0xa2633c[_0x5b2391(0x19f)]<=_0xa2633c[_0x5b2391(0x199)]&&(_0xa2633c[_0x5b2391(0x18f)]===undefined||Number[_0x5b2391(0x197)](_0xa2633c[_0x5b2391(0x18f)])&&_0xa2633c[_0x5b2391(0x18f)]>=0x648+-0x1f0+-0xb*0x65&&_0xa2633c[_0x5b2391(0x18f)]<=0x879+0x1386+-0x1a0b)&&typeof _0xa2633c[_0x5b2391(0x16b)]===_0x5b2391(0x169)?{'snapshotEnd':_0xa2633c[_0x5b2391(0x199)],'nextEnd':_0xa2633c[_0x5b2391(0x17a)],'fileAnchor':_0xa2633c[_0x5b2391(0x16b)],'anchorBytes':_0xa2633c[_0x5b2391(0x19f)],..._0xa2633c[_0x5b2391(0x18f)]===undefined?{}:{'readLimit':_0xa2633c[_0x5b2391(0x18f)]}}:undefined;}catch{return undefined;}}const ACTIVE_HISTORY_CURSOR_PREFIX=_0x567f9c(0x19c);function encodeActiveHistoryCursor(_0x44e1bb){const _0x5c6c81=_0x567f9c;return''+ACTIVE_HISTORY_CURSOR_PREFIX+Buffer[_0x5c6c81(0x13b)](JSON[_0x5c6c81(0x145)](_0x44e1bb))[_0x5c6c81(0x133)](_0x5c6c81(0x164));}function decodeActiveHistoryCursor(_0xf62705,_0x23683e){const _0x457217=_0x567f9c;if(_0xf62705===undefined||!_0xf62705[_0x457217(0x154)](ACTIVE_HISTORY_CURSOR_PREFIX))return undefined;try{const _0x98539d=JSON[_0x457217(0x1b5)](Buffer[_0x457217(0x13b)](_0xf62705[_0x457217(0x13e)](ACTIVE_HISTORY_CURSOR_PREFIX[_0x457217(0x1b9)]),_0x457217(0x164))[_0x457217(0x133)](_0x457217(0x137)));if(_0x98539d[_0x457217(0x17e)]!==_0x23683e||_0x98539d[_0x457217(0x148)]!==_0x457217(0x1a0)&&_0x98539d[_0x457217(0x148)]!==_0x457217(0x1b7)||typeof _0x98539d[_0x457217(0x17d)]!==_0x457217(0x179)||!Number[_0x457217(0x13c)](_0x98539d[_0x457217(0x17d)])||_0x98539d[_0x457217(0x17d)]<-0x1e3f+-0x2*0xebf+0x3bbd||_0x98539d[_0x457217(0x1b4)]!==null&&typeof _0x98539d[_0x457217(0x1b4)]!==_0x457217(0x169))throw new Error(_0x457217(0x139));return _0x98539d;}catch{throw new Error(_0x457217(0x139));}}function latestTurnActivityAt(_0x65d17b){const _0x1dc52d=_0x567f9c;return Math[_0x1dc52d(0x160)](_0x65d17b[_0x1dc52d(0x165)]??-0x18f5+0x11f9+0x6fc,_0x65d17b[_0x1dc52d(0x158)]??0x1b70+0x859+-0x23c9);}function oldestTurnActivityAt(_0x39a790){const _0x4cc44b=_0x567f9c;return _0x39a790[_0x4cc44b(0x1b9)]===0x66a*-0x3+-0x23b3+0x91*0x61?-0x1301+-0x7df+0x1ae0:Math[_0x4cc44b(0x1a4)](..._0x39a790[_0x4cc44b(0x1b6)](latestTurnActivityAt));}function mergeRuntimeUserImageReferences(_0x3aa4e9,_0x1bc471,_0x262695){const _0xb376d5=_0x567f9c,_0x4b48f3=_0x3aa4e9[_0xb376d5(0x147)][_0xb376d5(0x1b3)](_0x5e152f=>_0x5e152f[_0xb376d5(0x192)]===_0xb376d5(0x187)),_0x25da26=_0x1bc471[_0xb376d5(0x147)][_0xb376d5(0x1b3)](_0x50619a=>_0x50619a[_0xb376d5(0x192)]===_0xb376d5(0x187));if(_0x4b48f3===undefined||_0x25da26===undefined||!isPlainRecord(_0x4b48f3[_0xb376d5(0x12e)])||!isPlainRecord(_0x25da26[_0xb376d5(0x12e)]))return _0x3aa4e9;const _0x2c1526=_0x4b48f3[_0xb376d5(0x12e)],_0x198ea1=_0x25da26[_0xb376d5(0x12e)];if(!Array[_0xb376d5(0x176)](_0x2c1526[_0xb376d5(0x1ad)])||!Array[_0xb376d5(0x176)](_0x198ea1[_0xb376d5(0x1ad)]))return _0x3aa4e9;const _0x32bbef=_0x198ea1[_0xb376d5(0x1ad)][_0xb376d5(0x19a)](_0x2cde1c=>isPlainRecord(_0x2cde1c)&&typeof _0x2cde1c[_0xb376d5(0x156)]===_0xb376d5(0x169)&&_0x2cde1c[_0xb376d5(0x156)][_0xb376d5(0x154)](_0xb376d5(0x135)));let _0x4903b2=0xda*-0x3+-0x1881*0x1+0x1b0f,_0x5e5ef1=![];const _0x53e20e=_0x2c1526[_0xb376d5(0x1ad)][_0xb376d5(0x1b6)](_0x5e80d1=>{const _0x251a3c=_0xb376d5;if(!isPlainRecord(_0x5e80d1)||typeof _0x5e80d1[_0x251a3c(0x156)]!==_0x251a3c(0x169)||!_0x5e80d1[_0x251a3c(0x156)][_0x251a3c(0x154)](_0x251a3c(0x135)))return _0x5e80d1;const _0x3ab971=_0x32bbef[_0x4903b2++];if(_0x3ab971===undefined||_0x3ab971[_0x251a3c(0x163)]!==_0x5e80d1[_0x251a3c(0x163)]||_0x3ab971[_0x251a3c(0x156)]!==_0x5e80d1[_0x251a3c(0x156)]||typeof _0x5e80d1[_0x251a3c(0x1a7)]!==_0x251a3c(0x179)||!Number[_0x251a3c(0x16a)](_0x5e80d1[_0x251a3c(0x1a7)])||_0x5e80d1[_0x251a3c(0x1a7)]<0x1a0+-0x3*0x5fb+-0x1051*-0x1||_0x3ab971[_0x251a3c(0x1a7)]!==_0x5e80d1[_0x251a3c(0x1a7)]||typeof _0x3ab971[_0x251a3c(0x151)]!==_0x251a3c(0x169)||typeof _0x3ab971[_0x251a3c(0x193)]!==_0x251a3c(0x179)||!Number[_0x251a3c(0x16a)](_0x3ab971[_0x251a3c(0x193)])||_0x3ab971[_0x251a3c(0x193)]<-0x1c6*0x8+-0x194*-0xb+-0x32c)return _0x5e80d1;const _0x2fa5d2=_0x262695[_0x251a3c(0x194)](_0x3ab971[_0x251a3c(0x151)],_0x3ab971[_0x251a3c(0x193)]);if(_0x2fa5d2===undefined||_0x2fa5d2[_0x251a3c(0x163)]!==_0x3ab971[_0x251a3c(0x163)]||_0x2fa5d2[_0x251a3c(0x156)]!==_0x3ab971[_0x251a3c(0x156)]||Buffer[_0x251a3c(0x189)](_0x2fa5d2[_0x251a3c(0x188)],_0x251a3c(0x15a))!==_0x5e80d1[_0x251a3c(0x1a7)])return _0x5e80d1;return _0x5e5ef1=!![],{..._0x5e80d1,'runId':_0x3ab971[_0x251a3c(0x151)],'imageIndex':_0x3ab971[_0x251a3c(0x193)]};});if(!_0x5e5ef1)return _0x3aa4e9;return{..._0x3aa4e9,'items':_0x3aa4e9[_0xb376d5(0x147)][_0xb376d5(0x1b6)](_0x5c7c6d=>_0x5c7c6d['id']===_0x4b48f3['id']?{..._0x5c7c6d,'payload':{..._0x2c1526,'attachments':_0x53e20e}}:_0x5c7c6d)};}function sameHistoryConversationTurn(_0x5ac540,_0x585427){const _0x82aa07=_0x567f9c;return sameConversationTurn(_0x5ac540,_0x585427)||_0x5ac540[_0x82aa07(0x151)]!==null&&_0x5ac540[_0x82aa07(0x151)]===_0x585427[_0x82aa07(0x151)];}function sameConversationTurn(_0xa5ddff,_0x26eb7e){if(_0xa5ddff['id']===_0x26eb7e['id'])return!![];const _0x310383=conversationClientMessageId(_0xa5ddff);return _0x310383!==null&&_0x310383===conversationClientMessageId(_0x26eb7e);}function conversationClientMessageId(_0x218ea9){const _0x53b0c4=_0x567f9c;for(const _0x3d7c74 of _0x218ea9[_0x53b0c4(0x147)]){if(_0x3d7c74[_0x53b0c4(0x192)]!==_0x53b0c4(0x187)||!isPlainRecord(_0x3d7c74[_0x53b0c4(0x12e)]))continue;const _0x2c43c8=_0x3d7c74[_0x53b0c4(0x12e)][_0x53b0c4(0x13d)];if(typeof _0x2c43c8===_0x53b0c4(0x169)&&_0x2c43c8[_0x53b0c4(0x1b9)]>0x12*0xc0+0x13*-0x103+-0x125*-0x5)return _0x2c43c8;}return null;}function sourceRank(_0x43eaaa){const _0x556df2=_0x567f9c;if(_0x43eaaa===_0x556df2(0x191))return-0x1451+0x6ef+-0x17d*-0x9;if(_0x43eaaa===_0x556df2(0x1ae))return 0x2*0x11f5+0xddb+0x1*-0x31c3;return 0x850+0x63*-0x37+0xcf6;}function _0x1812(){const _0x547d71=['mMTJs3vUAW','B2zMAwnPywW','A2LUza','Aw1Hz2vjBMrLEa','CMvHza','BMf0AxzLq29UDhjVBa','CgfNzq','AxnjBNrLz2vY','zxH0zxjUywXtzxnZAw9Uswq','C25HChnOB3rfBMq','zMLSDgvY','otaYotm3vunjDuTo','BwfYlwfJDgL2zs1OAxn0B3j5oJe6','AgfZ','BMf0AxzLlNnLC3nPB24UAgLZDg9YEs5HDhrHy2HTzw50lxnVDxjJzs1YzwfKlMnVBxbSzxrLza','yw5JAg9YqNL0zxm','uLvoveLnrq','uevoreLorW','CMvHze9MzMLJAwfSq29UDMvYC2f0Aw9U','Bgf0zxn0vMLZAwjSzuf0','BwLU','yxzHAwXHyMXL','uLvotKLorW','yNL0zvnPEMu','CNvUBMvYCW','rvHurvjoquW','mta0q1LorNnM','odCYmdm1uKzqwKP4','CMvHzeHPC3rVCNLqywDL','yxr0ywnOBwvUDhm','BMf0AxzL','Aw1Hz2vbDhrHy2HTzw50CW','C3rHDhvZ','CM91BMq','C291CMnL','zMLUza','y3vYC29Y','CgfYC2u','BwfW','t0zgsunjquW','CMvHzef0','BgvUz3rO','C2v0rxH0zxjUywXby3rPDML0Eq','BgLTAxq','tufsx01btKfhruq','nZa0mKXJD25jtW','Cgf5Bg9Hza','Dhj1BMnHDgvK','CMvHze1HBMfNzwrby3rPDMu','Aw5JB21WBgv0zu5HDgL2zq','y3vYC29YuMvZzxq','Dg9tDhjPBMC','q0foq0vmteLorW','Aw1Hz2uV','Dg9VBfvZzuLK','DxrMoa','BgLZDfj1BNngB3jtzxnZAw9U','rvzftLrFq1vsu09sx0LovKfmsuq','BMf0AxzLlNnLC3nPB24UAgLZDg9YEs5UyxrPDMuTCMvHzc5JB21WBgv0zwq','zNjVBq','AxngAw5PDgu','y2XPzw50twvZC2fNzuLK','C2XPy2u','CMvHzfj1BM5LCKHPC3rVCNK','mtfPs2nVDK4','BM93','CMvHzenVBNzLCNnHDgLVBKHPC3rVCNK','CMvXDwLYzq','rKfjteve','C3rYAw5NAwz5','C3bSAwnL','AxrLBxm','C3rHz2u','CNvUBMvY','yxbWCM92ywXjza','mtiYmtq2ofbZD1vKyG','ntm0rxfjEKXf','AgfZtwfUywDLzefJDgL2zvj1BG','y2fWywjPBgL0AwvZ','ywnJzxb0C1rYDw5JyxrLze5HDgL2zuHPC3rVCNK','y3DK','CNvUswq','z2v0qwDLBNrtzxnZAw9U','CMvHzeHPC3rVCNK','C3rHCNrZv2L0Aa','CMvNAxn0zxjoyxrPDMu','BwLTzq','BwfUywDLzfj1BM5LCLr1CM4','y29TCgXLDgvKqxq','C2v0','yMfZzty0','DMfSDwvZ','z2v0','zMLUzeLUzgv4','yxr0ywnOtMf0AxzLsw1Hz2vZ','u1rbuLrjtKC','Bwf4','yxbWCM92ywXFCMvXDwvZDa','BwfUywDLzfj1BKzVCK5HDgL2zvr1CM4','BMfTzq','yMfZzty0DxjS','C3rHCNrLzef0','BMf0AxzLlNnLC3nPB24UAgLZDg9YEs5VzMzPy2LHBc1YzwfKlMnVBxbSzxrLza','mti5mZu3ourfDuTHEa','ohrvB21wrG','C3rYAw5N','AxntywzLsw50zwDLCG','zMLSzufUy2HVCG','DxnLCL9PBNb1Df9Yzxf1zxn0','BMv4Den1CNnVCG','Dg9VBf9JywXS','DhvYBNm','CMvHze5HDgL2zq','vu5bvKfjtefcteu','C2L6zq','tKfusvzfx1rsqu5tq1jjufrFsu5dt01qtevurq','nefWvgnIqG','zMXHDe1HCa','AxnbCNjHEq','ChvZAa','BgLZDenVBNzLCNnHDgLVBLr1CM5Z','BNvTyMvY','BMv4DevUza','CNvUDgLTzq','CMvHzev4DgvYBMfSqwn0AxzPDhK','yMvMB3jLqxq','C2vZC2LVBKLK','CMvHze9MzMLJAwfS','C29Tzq','tKfusvzfx1rsqu5tq1jjufrFvu5bvKfjtefcteu','zMLUzeXHC3rjBMrLEa','BgfZDeLUzgv4t2y','mte4nZKYme9NC1L5tG','mtG4mtq5uhD3Du1N','CMvMCMvZAev4DgvYBMfSqwn0AxzPDhK','DxnLCL9TzxnZywDL','zgf0yujHC2u2na','yNL0zuXLBMD0Aa','CMvXDwvZDeLK','B3b0Aw9UCW','zxjYB3i','C25HChnOB3rtzxf1zw5Jzq','y29UDMvYC2f0Aw9UvhvYBKzVCKv4zwn1DgLVBG','CMvHzeXPBwL0'];_0x1812=function(){return _0x547d71;};return _0x1812();}
|
|
1
|
+
import { discoverNativeSessions, readNativeSession } from '../native-session-history.js';
|
|
2
|
+
import { coalesceImageGenerationItems } from '../runner/codex/conversation-parser.js';
|
|
3
|
+
import { nativeConversationPage } from '../util/runner-native-session-parsers.js';
|
|
4
|
+
import { isPlainRecord } from '../util/node-operation-parsers.js';
|
|
5
|
+
import { nodeLog } from '../operational.js';
|
|
6
|
+
export function hasManagedActiveRun(runtime, session) {
|
|
7
|
+
return (session.nativeControl === 'MAR_MANAGED' &&
|
|
8
|
+
runtime
|
|
9
|
+
.listRunsForSession(session.id)
|
|
10
|
+
.some((run) => run.status === 'STARTING' || run.status === 'RUNNING' || run.status === 'CANCELLING'));
|
|
11
|
+
}
|
|
12
|
+
export function convergeConversationWatchPage(previous, previousObserved, next, previousAuthority) {
|
|
13
|
+
const authority = isConversationHistorySource(previousAuthority)
|
|
14
|
+
? previousAuthority
|
|
15
|
+
: previous?.source;
|
|
16
|
+
if (previous === undefined ||
|
|
17
|
+
authority === undefined ||
|
|
18
|
+
sourceRank(next.source) >= sourceRank(authority))
|
|
19
|
+
return { page: next, authority: next.source };
|
|
20
|
+
if (previous.turns.length === 0)
|
|
21
|
+
return { page: next, authority };
|
|
22
|
+
const boundary = next.turns.findLastIndex((turn) => previous.turns.some((candidate) => sameConversationTurn(candidate, turn)));
|
|
23
|
+
const observedBoundary = boundary >= 0 || previousObserved === undefined
|
|
24
|
+
? -1
|
|
25
|
+
: next.turns.findLastIndex((turn) => previousObserved.turns.some((candidate) => sameConversationTurn(candidate, turn)));
|
|
26
|
+
const safeBoundary = Math.max(boundary, observedBoundary);
|
|
27
|
+
if (safeBoundary < 0)
|
|
28
|
+
return { page: previous, authority };
|
|
29
|
+
const additions = next.turns
|
|
30
|
+
.slice(safeBoundary + 1)
|
|
31
|
+
.filter((turn) => !previous.turns.some((candidate) => sameConversationTurn(candidate, turn)));
|
|
32
|
+
if (additions.length === 0)
|
|
33
|
+
return { page: previous, authority };
|
|
34
|
+
return {
|
|
35
|
+
page: {
|
|
36
|
+
...previous,
|
|
37
|
+
source: next.source,
|
|
38
|
+
snapshotSequence: Math.max(previous.snapshotSequence, next.snapshotSequence),
|
|
39
|
+
readAt: next.readAt,
|
|
40
|
+
latestVisibleAt: next.latestVisibleAt ?? previous.latestVisibleAt,
|
|
41
|
+
turns: [...previous.turns, ...additions]
|
|
42
|
+
},
|
|
43
|
+
authority
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export function composeConversationRuntimePage(history, runtime) {
|
|
47
|
+
if (history === undefined)
|
|
48
|
+
return runtime;
|
|
49
|
+
const turns = [...history.turns];
|
|
50
|
+
for (const turn of runtime.turns) {
|
|
51
|
+
const index = turns.findIndex((candidate) => sameConversationTurn(candidate, turn));
|
|
52
|
+
if (index < 0)
|
|
53
|
+
insertConversationTurnChronologically(turns, turn);
|
|
54
|
+
else
|
|
55
|
+
turns[index] = turn;
|
|
56
|
+
}
|
|
57
|
+
return { ...runtime, nextCursor: history.nextCursor, turns };
|
|
58
|
+
}
|
|
59
|
+
function insertConversationTurnChronologically(turns, turn) {
|
|
60
|
+
const time = earliestTurnActivityAt(turn);
|
|
61
|
+
if (time === 0) {
|
|
62
|
+
turns.push(turn);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const next = turns.findIndex((candidate) => {
|
|
66
|
+
const candidateTime = earliestTurnActivityAt(candidate);
|
|
67
|
+
return candidateTime > 0 && candidateTime > time;
|
|
68
|
+
});
|
|
69
|
+
if (next < 0)
|
|
70
|
+
turns.push(turn);
|
|
71
|
+
else
|
|
72
|
+
turns.splice(next, 0, turn);
|
|
73
|
+
}
|
|
74
|
+
function earliestTurnActivityAt(turn) {
|
|
75
|
+
const values = [
|
|
76
|
+
turn.startedAt,
|
|
77
|
+
turn.completedAt,
|
|
78
|
+
...turn.items.map((item) => item.startedAt)
|
|
79
|
+
].filter((value) => typeof value === 'number' && Number.isFinite(value) && value > 0);
|
|
80
|
+
return values.length === 0 ? 0 : Math.min(...values);
|
|
81
|
+
}
|
|
82
|
+
function isConversationHistorySource(value) {
|
|
83
|
+
return value === 'official' || value === 'native' || value === 'runtime';
|
|
84
|
+
}
|
|
85
|
+
export class ConversationHistoryService {
|
|
86
|
+
options;
|
|
87
|
+
constructor(options) {
|
|
88
|
+
this.options = options;
|
|
89
|
+
}
|
|
90
|
+
async read(session, input) {
|
|
91
|
+
const snapshotSequence = this.options.snapshotSequence();
|
|
92
|
+
const readAt = Date.now();
|
|
93
|
+
const activeCursor = decodeActiveHistoryCursor(input.cursor, session.id);
|
|
94
|
+
if (activeCursor !== undefined || this.options.hasManagedActiveRun(session))
|
|
95
|
+
return this.readManagedActive(session, input, activeCursor, snapshotSequence, readAt);
|
|
96
|
+
return this.readHistory(session, input, snapshotSequence, readAt);
|
|
97
|
+
}
|
|
98
|
+
async readHistoryPage(session, input) {
|
|
99
|
+
return this.readHistory(session, input, this.options.snapshotSequence(), Date.now());
|
|
100
|
+
}
|
|
101
|
+
async readHistory(session, input, snapshotSequence, readAt) {
|
|
102
|
+
const selected = await this.readRunnerHistory(session, input);
|
|
103
|
+
if (selected.page?.source === 'native')
|
|
104
|
+
return this.page(selected.page.nextCursor, selected.page.turns, {
|
|
105
|
+
snapshotSequence,
|
|
106
|
+
source: 'native',
|
|
107
|
+
readAt
|
|
108
|
+
});
|
|
109
|
+
let official = selected.page?.source === 'official' ? selected.page : undefined;
|
|
110
|
+
if (official !== undefined) {
|
|
111
|
+
const limit = Math.min(Math.max(input.limit ?? 30, 1), 500);
|
|
112
|
+
const runtimeTurns = this.options.runtime.getAgentSession(session.id) === undefined
|
|
113
|
+
? []
|
|
114
|
+
: this.options.runtime.listConversationTurns({ sessionId: session.id, limit: 500 }).turns;
|
|
115
|
+
const initialOfficialTurns = official.turns;
|
|
116
|
+
const lastRepresentedRuntimeIndex = runtimeTurns.findLastIndex((turn) => initialOfficialTurns.some((officialTurn) => sameHistoryConversationTurn(officialTurn, turn)));
|
|
117
|
+
const officialHasTurns = initialOfficialTurns.length > 0;
|
|
118
|
+
const absentLocalTurns = runtimeTurns.filter((turn, index) => !initialOfficialTurns.some((officialTurn) => sameHistoryConversationTurn(officialTurn, turn)) &&
|
|
119
|
+
(!officialHasTurns || index > lastRepresentedRuntimeIndex));
|
|
120
|
+
const missingLocalTurns = absentLocalTurns.slice(-limit);
|
|
121
|
+
if (input.cursor === undefined &&
|
|
122
|
+
missingLocalTurns.length > 0 &&
|
|
123
|
+
official.turns.length + missingLocalTurns.length > limit) {
|
|
124
|
+
const reserved = Math.min(missingLocalTurns.length, Math.max(0, limit - 1));
|
|
125
|
+
const narrowed = await this.readOfficial(session, { ...input, limit: limit - reserved });
|
|
126
|
+
if (narrowed !== undefined)
|
|
127
|
+
official = { ...narrowed, source: 'official' };
|
|
128
|
+
}
|
|
129
|
+
const officialTurns = await this.attachNativeImages(session, official.turns);
|
|
130
|
+
const runtimeTurnsByOfficialId = new Map();
|
|
131
|
+
const runtimeSupplementalItemsByOfficialId = new Map();
|
|
132
|
+
for (const officialTurn of officialTurns) {
|
|
133
|
+
const runtimeTurn = runtimeTurns.find((candidate) => sameHistoryConversationTurn(officialTurn, candidate));
|
|
134
|
+
if (runtimeTurn === undefined)
|
|
135
|
+
continue;
|
|
136
|
+
runtimeTurnsByOfficialId.set(officialTurn.id, runtimeTurn);
|
|
137
|
+
const runtimeSupplementalItems = runtimeTurn.items.filter((item) => item.kind === 'error' ||
|
|
138
|
+
item.kind === 'approval_request' ||
|
|
139
|
+
(item.kind === 'user_input_request' && item.status === 'PENDING'));
|
|
140
|
+
if (runtimeSupplementalItems.length > 0)
|
|
141
|
+
runtimeSupplementalItemsByOfficialId.set(officialTurn.id, runtimeSupplementalItems);
|
|
142
|
+
}
|
|
143
|
+
const availableLocalSlots = Math.max(0, limit - officialTurns.length);
|
|
144
|
+
const localCandidates = input.cursor === undefined ? missingLocalTurns : [];
|
|
145
|
+
const localTurns = availableLocalSlots === 0 ? [] : localCandidates.slice(-availableLocalSlots);
|
|
146
|
+
const localInteractionIds = new Set([
|
|
147
|
+
...localTurns.flatMap((turn) => turn.items.flatMap((item) => {
|
|
148
|
+
if (!isPlainRecord(item.payload))
|
|
149
|
+
return [];
|
|
150
|
+
const interactionId = item.kind === 'approval_request'
|
|
151
|
+
? item.payload.approvalId
|
|
152
|
+
: item.kind === 'user_input_request'
|
|
153
|
+
? item.payload.requestId
|
|
154
|
+
: undefined;
|
|
155
|
+
return typeof interactionId === 'string' ? [interactionId] : [];
|
|
156
|
+
})),
|
|
157
|
+
...[...runtimeSupplementalItemsByOfficialId.values()].flatMap((items) => items.flatMap((item) => {
|
|
158
|
+
if (!isPlainRecord(item.payload))
|
|
159
|
+
return [];
|
|
160
|
+
const interactionId = item.kind === 'approval_request' ? item.payload.approvalId : item.payload.requestId;
|
|
161
|
+
return typeof interactionId === 'string' ? [interactionId] : [];
|
|
162
|
+
}))
|
|
163
|
+
]);
|
|
164
|
+
const turns = [
|
|
165
|
+
...officialTurns
|
|
166
|
+
.map((turn) => {
|
|
167
|
+
const runtimeTurn = runtimeTurnsByOfficialId.get(turn.id);
|
|
168
|
+
const hydratedTurn = runtimeTurn === undefined
|
|
169
|
+
? turn
|
|
170
|
+
: mergeRuntimeUserImageReferences(turn, runtimeTurn, this.options.attachments);
|
|
171
|
+
const runtimeSupplementalItems = runtimeSupplementalItemsByOfficialId.get(turn.id) ?? [];
|
|
172
|
+
const items = [
|
|
173
|
+
...hydratedTurn.items.filter((item) => (item.kind !== 'approval_request' && item.kind !== 'user_input_request') ||
|
|
174
|
+
!isPlainRecord(item.payload) ||
|
|
175
|
+
!localInteractionIds.has(item.kind === 'approval_request'
|
|
176
|
+
? String(item.payload.approvalId ?? '')
|
|
177
|
+
: String(item.payload.requestId ?? ''))),
|
|
178
|
+
...runtimeSupplementalItems.filter((item) => !hydratedTurn.items.some((officialItem) => officialItem.id === item.id ||
|
|
179
|
+
(officialItem.kind === 'error' && item.kind === 'error')))
|
|
180
|
+
];
|
|
181
|
+
return {
|
|
182
|
+
...hydratedTurn,
|
|
183
|
+
status: runtimeSupplementalItems.some((item) => item.kind === 'error')
|
|
184
|
+
? 'FAILED'
|
|
185
|
+
: turn.status,
|
|
186
|
+
items
|
|
187
|
+
};
|
|
188
|
+
})
|
|
189
|
+
.filter((turn) => turn.items.length > 0),
|
|
190
|
+
...localTurns
|
|
191
|
+
];
|
|
192
|
+
return this.page(official.nextCursor, turns, {
|
|
193
|
+
snapshotSequence,
|
|
194
|
+
source: 'official',
|
|
195
|
+
readAt
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
if (session.externalSessionId !== null && selected.incompleteNative) {
|
|
199
|
+
const runtimePage = this.options.runtime.listConversationTurns({
|
|
200
|
+
sessionId: session.id,
|
|
201
|
+
...input
|
|
202
|
+
});
|
|
203
|
+
if (runtimePage.turns.length === 0)
|
|
204
|
+
throw new Error('NATIVE_TRANSCRIPT_INCOMPLETE');
|
|
205
|
+
return this.page(runtimePage.nextCursor, runtimePage.turns, {
|
|
206
|
+
snapshotSequence,
|
|
207
|
+
source: 'runtime',
|
|
208
|
+
readAt
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
const page = this.options.runtime.listConversationTurns({ sessionId: session.id, ...input });
|
|
212
|
+
if (session.externalSessionId !== null &&
|
|
213
|
+
session.nativeControl === 'EXTERNAL' &&
|
|
214
|
+
page.turns.length === 0)
|
|
215
|
+
throw new Error('NATIVE_TRANSCRIPT_UNAVAILABLE');
|
|
216
|
+
return this.page(page.nextCursor, page.turns, { snapshotSequence, source: 'runtime', readAt });
|
|
217
|
+
}
|
|
218
|
+
async readRunnerHistory(session, input) {
|
|
219
|
+
const runner = this.options.runners.require(session.runner);
|
|
220
|
+
let incompleteNative = false;
|
|
221
|
+
const page = await runner.readConversationHistory({
|
|
222
|
+
native: async () => {
|
|
223
|
+
const startedAt = performance.now();
|
|
224
|
+
let history;
|
|
225
|
+
try {
|
|
226
|
+
history = await this.readNative(session, input.cursor, input.limit);
|
|
227
|
+
}
|
|
228
|
+
catch {
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
231
|
+
finally {
|
|
232
|
+
const durationMs = Math.round(performance.now() - startedAt);
|
|
233
|
+
if (durationMs >= 250)
|
|
234
|
+
nodeLog('native.session.history.native-read.completed', {
|
|
235
|
+
runner: session.runner,
|
|
236
|
+
sessionId: session.id,
|
|
237
|
+
durationMs
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
if (history === undefined)
|
|
241
|
+
return undefined;
|
|
242
|
+
if (history.truncated === true &&
|
|
243
|
+
(!runner.acceptsTruncatedNativeHistory() || history.items.length === 0)) {
|
|
244
|
+
incompleteNative = true;
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
const runtimeTurns = this.options.runtime.getAgentSession(session.id) === undefined
|
|
248
|
+
? []
|
|
249
|
+
: this.options.runtime.listConversationTurns({ sessionId: session.id, limit: 500 })
|
|
250
|
+
.turns;
|
|
251
|
+
const native = nativeConversationPage(session, history, history.cursorReset === true
|
|
252
|
+
? input.limit === undefined
|
|
253
|
+
? {}
|
|
254
|
+
: { limit: input.limit }
|
|
255
|
+
: input, runtimeTurns, (images) => this.options.attachments.registerNative(session, images));
|
|
256
|
+
return native;
|
|
257
|
+
},
|
|
258
|
+
official: () => this.readOfficial(session, input)
|
|
259
|
+
});
|
|
260
|
+
return { page, incompleteNative };
|
|
261
|
+
}
|
|
262
|
+
async readManagedActive(session, input, cursor, snapshotSequence, readAt) {
|
|
263
|
+
const limit = Math.min(Math.max(input.limit ?? 30, 1), 500);
|
|
264
|
+
const runtimeTurns = this.options.runtime.listConversationTurns({
|
|
265
|
+
sessionId: session.id,
|
|
266
|
+
limit: 500
|
|
267
|
+
}).turns;
|
|
268
|
+
const beforeAt = cursor?.beforeAt ?? oldestTurnActivityAt(runtimeTurns);
|
|
269
|
+
if (cursor?.stage === 'OFFICIAL') {
|
|
270
|
+
const selected = await this.readRunnerHistory(session, {
|
|
271
|
+
...(cursor.cursor === null ? {} : { cursor: cursor.cursor }),
|
|
272
|
+
limit
|
|
273
|
+
});
|
|
274
|
+
const history = selected.page;
|
|
275
|
+
if (history === undefined)
|
|
276
|
+
return this.page(null, [], { snapshotSequence, source: 'runtime', readAt });
|
|
277
|
+
const hydratedTurns = history.source === 'official'
|
|
278
|
+
? await this.attachNativeImages(session, history.turns)
|
|
279
|
+
: history.turns;
|
|
280
|
+
const turns = hydratedTurns.filter((turn) => latestTurnActivityAt(turn) < beforeAt);
|
|
281
|
+
return this.page(history.nextCursor === null
|
|
282
|
+
? null
|
|
283
|
+
: encodeActiveHistoryCursor({
|
|
284
|
+
sessionId: session.id,
|
|
285
|
+
stage: 'OFFICIAL',
|
|
286
|
+
beforeAt,
|
|
287
|
+
cursor: history.nextCursor
|
|
288
|
+
}), turns, { snapshotSequence, source: history.source, readAt });
|
|
289
|
+
}
|
|
290
|
+
const runtimePage = this.options.runtime.listConversationTurns({
|
|
291
|
+
sessionId: session.id,
|
|
292
|
+
...(cursor?.cursor === null || cursor === undefined ? {} : { cursor: cursor.cursor }),
|
|
293
|
+
limit
|
|
294
|
+
});
|
|
295
|
+
const nextCursor = runtimePage.nextCursor !== null
|
|
296
|
+
? encodeActiveHistoryCursor({
|
|
297
|
+
sessionId: session.id,
|
|
298
|
+
stage: 'RUNTIME',
|
|
299
|
+
beforeAt,
|
|
300
|
+
cursor: runtimePage.nextCursor
|
|
301
|
+
})
|
|
302
|
+
: session.externalSessionId === null
|
|
303
|
+
? null
|
|
304
|
+
: encodeActiveHistoryCursor({
|
|
305
|
+
sessionId: session.id,
|
|
306
|
+
stage: 'OFFICIAL',
|
|
307
|
+
beforeAt,
|
|
308
|
+
cursor: null
|
|
309
|
+
});
|
|
310
|
+
return this.page(nextCursor, runtimePage.turns, {
|
|
311
|
+
snapshotSequence,
|
|
312
|
+
source: 'runtime',
|
|
313
|
+
readAt,
|
|
314
|
+
deferredOlderHistory: true
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
async refreshExternalActivity(session) {
|
|
318
|
+
const runner = this.options.runners.require(session.runner);
|
|
319
|
+
if (!runner.available(this.options.capabilities())) {
|
|
320
|
+
this.options.setExternalActivity(session.id, 'UNAVAILABLE');
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
const activity = await runner.readExternalActivity(session);
|
|
324
|
+
if (activity !== undefined)
|
|
325
|
+
this.options.setExternalActivity(session.id, activity);
|
|
326
|
+
}
|
|
327
|
+
async readNative(session, cursor, limit = 30) {
|
|
328
|
+
if (session.externalSessionId === null)
|
|
329
|
+
return undefined;
|
|
330
|
+
const page = nativeHistoryPageCursor(cursor, session.id);
|
|
331
|
+
const current = await readNativeSession(session.runner, session.cwd, session.externalSessionId, page, limit);
|
|
332
|
+
if (current !== undefined)
|
|
333
|
+
return current;
|
|
334
|
+
await discoverNativeSessions(session.runner, session.cwd);
|
|
335
|
+
return readNativeSession(session.runner, session.cwd, session.externalSessionId, page, limit);
|
|
336
|
+
}
|
|
337
|
+
async attachNativeImages(session, turns) {
|
|
338
|
+
const startedAt = performance.now();
|
|
339
|
+
const history = await this.readNative(session);
|
|
340
|
+
const readDurationMs = Math.round(performance.now() - startedAt);
|
|
341
|
+
if (readDurationMs >= 250)
|
|
342
|
+
nodeLog('native.session.history.attachment-source-read.completed', {
|
|
343
|
+
runner: session.runner,
|
|
344
|
+
sessionId: session.id,
|
|
345
|
+
durationMs: readDurationMs
|
|
346
|
+
});
|
|
347
|
+
if (history === undefined)
|
|
348
|
+
return turns;
|
|
349
|
+
const attachments = new Map();
|
|
350
|
+
for (const item of history.items) {
|
|
351
|
+
if (item.kind !== 'tool_call' || item.imageAttachments === undefined)
|
|
352
|
+
continue;
|
|
353
|
+
const registered = this.options.attachments.registerNative(session, item.imageAttachments);
|
|
354
|
+
if (registered.length > 0)
|
|
355
|
+
attachments.set(item.toolUseId, registered);
|
|
356
|
+
}
|
|
357
|
+
if (attachments.size === 0)
|
|
358
|
+
return turns;
|
|
359
|
+
return turns.map((turn) => ({
|
|
360
|
+
...turn,
|
|
361
|
+
items: coalesceImageGenerationItems(turn.items.map((item) => {
|
|
362
|
+
const registered = attachments.get(item.id.slice(item.id.lastIndexOf(':') + 1));
|
|
363
|
+
if (registered === undefined || !isPlainRecord(item.payload))
|
|
364
|
+
return item;
|
|
365
|
+
return { ...item, payload: { ...item.payload, attachments: registered } };
|
|
366
|
+
}))
|
|
367
|
+
}));
|
|
368
|
+
}
|
|
369
|
+
async readOfficial(session, input) {
|
|
370
|
+
const runner = this.options.runners.require(session.runner);
|
|
371
|
+
if (session.externalSessionId === null || !runner.available(this.options.capabilities()))
|
|
372
|
+
return undefined;
|
|
373
|
+
const startedAt = performance.now();
|
|
374
|
+
try {
|
|
375
|
+
return await runner.readOfficialConversation(session, input, (nativeTurnId) => this.managedRunnerTurn(session, nativeTurnId));
|
|
376
|
+
}
|
|
377
|
+
finally {
|
|
378
|
+
const durationMs = Math.round(performance.now() - startedAt);
|
|
379
|
+
if (durationMs >= 250)
|
|
380
|
+
nodeLog('native.session.history.official-read.completed', {
|
|
381
|
+
runner: session.runner,
|
|
382
|
+
sessionId: session.id,
|
|
383
|
+
durationMs
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
managedRunnerTurn(session, nativeTurnId) {
|
|
388
|
+
const executionId = this.options.runners
|
|
389
|
+
.require(session.runner)
|
|
390
|
+
.managedRunForNativeTurn(nativeTurnId);
|
|
391
|
+
if (executionId === undefined)
|
|
392
|
+
return undefined;
|
|
393
|
+
return this.options.runtime.conversationTurnForExecution(executionId);
|
|
394
|
+
}
|
|
395
|
+
page(nextCursor, turns, metadata) {
|
|
396
|
+
return {
|
|
397
|
+
...metadata,
|
|
398
|
+
turns,
|
|
399
|
+
nextCursor,
|
|
400
|
+
latestVisibleAt: Math.max(0, ...turns.map((turn) => Math.max(turn.startedAt ?? 0, turn.completedAt ?? 0)))
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
function nativeHistoryPageCursor(cursor, sessionId) {
|
|
405
|
+
if (cursor === undefined)
|
|
406
|
+
return undefined;
|
|
407
|
+
try {
|
|
408
|
+
const value = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8'));
|
|
409
|
+
return value.sessionId === sessionId &&
|
|
410
|
+
Number.isInteger(value.snapshotEnd) &&
|
|
411
|
+
Number.isInteger(value.nextEnd) &&
|
|
412
|
+
Number.isInteger(value.anchorBytes) &&
|
|
413
|
+
value.snapshotEnd >= 0 &&
|
|
414
|
+
value.nextEnd >= 0 &&
|
|
415
|
+
value.nextEnd <= value.snapshotEnd &&
|
|
416
|
+
value.anchorBytes >= 0 &&
|
|
417
|
+
value.anchorBytes <= value.snapshotEnd &&
|
|
418
|
+
(value.readLimit === undefined ||
|
|
419
|
+
(Number.isInteger(value.readLimit) &&
|
|
420
|
+
value.readLimit >= 1 &&
|
|
421
|
+
value.readLimit <= 500)) &&
|
|
422
|
+
typeof value.fileAnchor === 'string'
|
|
423
|
+
? {
|
|
424
|
+
snapshotEnd: value.snapshotEnd,
|
|
425
|
+
nextEnd: value.nextEnd,
|
|
426
|
+
fileAnchor: value.fileAnchor,
|
|
427
|
+
anchorBytes: value.anchorBytes,
|
|
428
|
+
...(value.readLimit === undefined ? {} : { readLimit: value.readLimit })
|
|
429
|
+
}
|
|
430
|
+
: undefined;
|
|
431
|
+
}
|
|
432
|
+
catch {
|
|
433
|
+
return undefined;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
const ACTIVE_HISTORY_CURSOR_PREFIX = 'mar-active-history:1:';
|
|
437
|
+
function encodeActiveHistoryCursor(cursor) {
|
|
438
|
+
return `${ACTIVE_HISTORY_CURSOR_PREFIX}${Buffer.from(JSON.stringify(cursor)).toString('base64url')}`;
|
|
439
|
+
}
|
|
440
|
+
function decodeActiveHistoryCursor(value, sessionId) {
|
|
441
|
+
if (value === undefined || !value.startsWith(ACTIVE_HISTORY_CURSOR_PREFIX))
|
|
442
|
+
return undefined;
|
|
443
|
+
try {
|
|
444
|
+
const decoded = JSON.parse(Buffer.from(value.slice(ACTIVE_HISTORY_CURSOR_PREFIX.length), 'base64url').toString('utf8'));
|
|
445
|
+
if (decoded.sessionId !== sessionId ||
|
|
446
|
+
(decoded.stage !== 'RUNTIME' && decoded.stage !== 'OFFICIAL') ||
|
|
447
|
+
typeof decoded.beforeAt !== 'number' ||
|
|
448
|
+
!Number.isFinite(decoded.beforeAt) ||
|
|
449
|
+
decoded.beforeAt < 0 ||
|
|
450
|
+
(decoded.cursor !== null && typeof decoded.cursor !== 'string'))
|
|
451
|
+
throw new Error('EVENT_CURSOR_INVALID');
|
|
452
|
+
return decoded;
|
|
453
|
+
}
|
|
454
|
+
catch {
|
|
455
|
+
throw new Error('EVENT_CURSOR_INVALID');
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
function latestTurnActivityAt(turn) {
|
|
459
|
+
return Math.max(turn.startedAt ?? 0, turn.completedAt ?? 0);
|
|
460
|
+
}
|
|
461
|
+
function oldestTurnActivityAt(turns) {
|
|
462
|
+
return turns.length === 0 ? 0 : Math.min(...turns.map(latestTurnActivityAt));
|
|
463
|
+
}
|
|
464
|
+
function mergeRuntimeUserImageReferences(officialTurn, runtimeTurn, attachments) {
|
|
465
|
+
const officialUser = officialTurn.items.find((item) => item.kind === 'user_message');
|
|
466
|
+
const runtimeUser = runtimeTurn.items.find((item) => item.kind === 'user_message');
|
|
467
|
+
if (officialUser === undefined ||
|
|
468
|
+
runtimeUser === undefined ||
|
|
469
|
+
!isPlainRecord(officialUser.payload) ||
|
|
470
|
+
!isPlainRecord(runtimeUser.payload))
|
|
471
|
+
return officialTurn;
|
|
472
|
+
const officialPayload = officialUser.payload;
|
|
473
|
+
const runtimePayload = runtimeUser.payload;
|
|
474
|
+
if (!Array.isArray(officialPayload.attachments) || !Array.isArray(runtimePayload.attachments))
|
|
475
|
+
return officialTurn;
|
|
476
|
+
const runtimeImages = runtimePayload.attachments.filter((attachment) => isPlainRecord(attachment) &&
|
|
477
|
+
typeof attachment.mime === 'string' &&
|
|
478
|
+
attachment.mime.startsWith('image/'));
|
|
479
|
+
let runtimeImageIndex = 0;
|
|
480
|
+
let changed = false;
|
|
481
|
+
const mergedAttachments = officialPayload.attachments.map((attachment) => {
|
|
482
|
+
if (!isPlainRecord(attachment) ||
|
|
483
|
+
typeof attachment.mime !== 'string' ||
|
|
484
|
+
!attachment.mime.startsWith('image/'))
|
|
485
|
+
return attachment;
|
|
486
|
+
const runtimeAttachment = runtimeImages[runtimeImageIndex++];
|
|
487
|
+
if (runtimeAttachment === undefined ||
|
|
488
|
+
runtimeAttachment.name !== attachment.name ||
|
|
489
|
+
runtimeAttachment.mime !== attachment.mime ||
|
|
490
|
+
typeof attachment.byteSize !== 'number' ||
|
|
491
|
+
!Number.isSafeInteger(attachment.byteSize) ||
|
|
492
|
+
attachment.byteSize < 0 ||
|
|
493
|
+
runtimeAttachment.byteSize !== attachment.byteSize ||
|
|
494
|
+
typeof runtimeAttachment.runId !== 'string' ||
|
|
495
|
+
typeof runtimeAttachment.imageIndex !== 'number' ||
|
|
496
|
+
!Number.isSafeInteger(runtimeAttachment.imageIndex) ||
|
|
497
|
+
runtimeAttachment.imageIndex < 0)
|
|
498
|
+
return attachment;
|
|
499
|
+
const cached = attachments.read(runtimeAttachment.runId, runtimeAttachment.imageIndex);
|
|
500
|
+
if (cached === undefined ||
|
|
501
|
+
cached.name !== runtimeAttachment.name ||
|
|
502
|
+
cached.mime !== runtimeAttachment.mime ||
|
|
503
|
+
Buffer.byteLength(cached.dataBase64, 'base64') !== attachment.byteSize)
|
|
504
|
+
return attachment;
|
|
505
|
+
changed = true;
|
|
506
|
+
return {
|
|
507
|
+
...attachment,
|
|
508
|
+
runId: runtimeAttachment.runId,
|
|
509
|
+
imageIndex: runtimeAttachment.imageIndex
|
|
510
|
+
};
|
|
511
|
+
});
|
|
512
|
+
if (!changed)
|
|
513
|
+
return officialTurn;
|
|
514
|
+
return {
|
|
515
|
+
...officialTurn,
|
|
516
|
+
items: officialTurn.items.map((item) => item.id === officialUser.id
|
|
517
|
+
? {
|
|
518
|
+
...item,
|
|
519
|
+
payload: {
|
|
520
|
+
...officialPayload,
|
|
521
|
+
attachments: mergedAttachments
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
: item)
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
function sameHistoryConversationTurn(left, right) {
|
|
528
|
+
return sameConversationTurn(left, right) || (left.runId !== null && left.runId === right.runId);
|
|
529
|
+
}
|
|
530
|
+
function sameConversationTurn(left, right) {
|
|
531
|
+
if (left.id === right.id)
|
|
532
|
+
return true;
|
|
533
|
+
const leftMessageId = conversationClientMessageId(left);
|
|
534
|
+
return leftMessageId !== null && leftMessageId === conversationClientMessageId(right);
|
|
535
|
+
}
|
|
536
|
+
function conversationClientMessageId(turn) {
|
|
537
|
+
for (const item of turn.items) {
|
|
538
|
+
if (item.kind !== 'user_message' || !isPlainRecord(item.payload))
|
|
539
|
+
continue;
|
|
540
|
+
const value = item.payload.clientMessageId;
|
|
541
|
+
if (typeof value === 'string' && value.length > 0)
|
|
542
|
+
return value;
|
|
543
|
+
}
|
|
544
|
+
return null;
|
|
545
|
+
}
|
|
546
|
+
function sourceRank(source) {
|
|
547
|
+
if (source === 'official')
|
|
548
|
+
return 3;
|
|
549
|
+
if (source === 'native')
|
|
550
|
+
return 2;
|
|
551
|
+
return 1;
|
|
552
|
+
}
|