@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.
Files changed (161) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +4 -0
  3. package/dist/capabilities.js +110 -2
  4. package/dist/claude-agent-sdk.js +330 -2
  5. package/dist/claude-channel.js +44 -2
  6. package/dist/codex-app-server.js +510 -2
  7. package/dist/config.js +106 -2
  8. package/dist/connector/node-connector-options.js +1 -2
  9. package/dist/connector/node-operation-router.js +22 -2
  10. package/dist/connector.js +1736 -2
  11. package/dist/control-outbound-scheduler.js +153 -2
  12. package/dist/database.js +639 -2
  13. package/dist/fake-runner.js +129 -2
  14. package/dist/git-askpass.js +12 -0
  15. package/dist/git-execution-helper.js +266 -0
  16. package/dist/health.js +3 -2
  17. package/dist/main.js +57 -2
  18. package/dist/mcp-installation-model.js +1 -2
  19. package/dist/migrations/v004.js +55 -3
  20. package/dist/migrations/v005.js +13 -3
  21. package/dist/migrations/v006.js +90 -3
  22. package/dist/migrations/v007.js +22 -3
  23. package/dist/migrations/v008.js +18 -3
  24. package/dist/migrations/v009.js +70 -4
  25. package/dist/migrations/v010.js +43 -3
  26. package/dist/migrations/v011.js +20 -3
  27. package/dist/migrations/v012.js +8 -0
  28. package/dist/native-jsonl-reader.js +186 -2
  29. package/dist/native-session-history.js +1143 -2
  30. package/dist/opencode-runtime.js +80 -2
  31. package/dist/opencode-server.js +259 -2
  32. package/dist/operational.js +122 -2
  33. package/dist/process-tree.js +18 -2
  34. package/dist/ripgrep-binary.js +31 -2
  35. package/dist/rotating-log.js +67 -2
  36. package/dist/runner/abstract-runner.js +260 -2
  37. package/dist/runner/claude/managed-run-controller.js +355 -2
  38. package/dist/runner/claude/tool-normalizer.js +120 -2
  39. package/dist/runner/claude-code-runner.js +303 -2
  40. package/dist/runner/codex/composer-image-markers.js +8 -2
  41. package/dist/runner/codex/conversation-parser.js +913 -2
  42. package/dist/runner/codex/managed-run-controller.js +494 -2
  43. package/dist/runner/codex/tool-normalizer.js +214 -2
  44. package/dist/runner/codex-runner.js +585 -2
  45. package/dist/runner/fake-test-runner.js +47 -2
  46. package/dist/runner/mar-agent/conversation-normalizer.js +644 -2
  47. package/dist/runner/mar-agent/executor-stdio-client-transport.js +139 -2
  48. package/dist/runner/mar-agent/generated-images.js +41 -2
  49. package/dist/runner/mar-agent/history-projection.js +106 -2
  50. package/dist/runner/mar-agent/hosted-conversation-runtime.js +446 -2
  51. package/dist/runner/mar-agent/managed-run-controller.js +785 -2
  52. package/dist/runner/mar-agent/mcp-client-pool.js +233 -2
  53. package/dist/runner/mar-agent/runtime-model-factory.js +326 -2
  54. package/dist/runner/mar-agent-runner.js +458 -2
  55. package/dist/runner/opencode/conversation-parser.js +221 -2
  56. package/dist/runner/opencode/managed-run-controller.js +588 -2
  57. package/dist/runner/opencode/tool-normalizer.js +80 -2
  58. package/dist/runner/opencode-runner.js +426 -2
  59. package/dist/runner/runner-registry.js +87 -2
  60. package/dist/runner-command-engine.js +71 -2
  61. package/dist/runner-profiles.js +323 -2
  62. package/dist/runner-usage.js +190 -2
  63. package/dist/runtime-command-detector.js +73 -2
  64. package/dist/runtime-model.js +1 -2
  65. package/dist/runtime-state.js +1509 -2
  66. package/dist/service/attachment-domain-state.js +7 -2
  67. package/dist/service/bubblewrap-sandbox-executor.js +543 -2
  68. package/dist/service/continuous-run-coordinator.js +425 -2
  69. package/dist/service/conversation-history-service.js +552 -2
  70. package/dist/service/conversation-hosting-capability-service.js +61 -2
  71. package/dist/service/conversation-hosting-enablement-service.js +91 -2
  72. package/dist/service/conversation-hosting-maintenance-service.js +174 -2
  73. package/dist/service/conversation-segment-service.js +162 -2
  74. package/dist/service/conversation-template-node-service.js +992 -2
  75. package/dist/service/external-session-resume-service.js +152 -2
  76. package/dist/service/fake-managed-run-service.js +60 -2
  77. package/dist/service/git-execution-service.js +418 -0
  78. package/dist/service/git-operation-service.js +57 -0
  79. package/dist/service/hosted-conversation-node-service.js +1982 -2
  80. package/dist/service/hosted-conversation-store.js +1405 -2
  81. package/dist/service/managed-runner-session-service.js +35 -2
  82. package/dist/service/mar-agent-model-transport-test-service.js +88 -2
  83. package/dist/service/mcp-installation-verifier.js +87 -2
  84. package/dist/service/mcp-node-operation-service.js +90 -2
  85. package/dist/service/mission-mcp-server.js +124 -2
  86. package/dist/service/mission-mcp-stdio.js +40 -2
  87. package/dist/service/mission-runtime.js +142 -2
  88. package/dist/service/native-session-projection-service.js +274 -2
  89. package/dist/service/native-session-watch-service.js +683 -2
  90. package/dist/service/node-connection-lifecycle-service.js +88 -2
  91. package/dist/service/node-control-channel.js +85 -2
  92. package/dist/service/node-control-message-service.js +109 -2
  93. package/dist/service/node-request-service.js +62 -2
  94. package/dist/service/node-run-event-bridge.js +88 -2
  95. package/dist/service/node-terminal-channel.js +202 -2
  96. package/dist/service/node-upgrade-coordinator.js +137 -2
  97. package/dist/service/node-workspace-coordinator.js +97 -2
  98. package/dist/service/recent-run-projection-service.js +99 -2
  99. package/dist/service/run-attachment-service.js +321 -2
  100. package/dist/service/run-domain-state.js +4 -2
  101. package/dist/service/run-event-service.js +246 -2
  102. package/dist/service/run-ownership-policy.js +22 -2
  103. package/dist/service/run-workbench-service.js +120 -2
  104. package/dist/service/runner-channel-message-service.js +20 -2
  105. package/dist/service/runner-interaction-service.js +243 -2
  106. package/dist/service/runner-service.js +69 -2
  107. package/dist/service/runtime-credential-control-service.js +95 -2
  108. package/dist/service/session-catalog-service.js +404 -2
  109. package/dist/service/session-command-service.js +125 -2
  110. package/dist/service/session-context-service.js +128 -2
  111. package/dist/service/session-domain-state.js +9 -2
  112. package/dist/service/session-identity-service.js +86 -2
  113. package/dist/service/session-lifecycle-service.js +248 -2
  114. package/dist/service/session-message-service.js +270 -2
  115. package/dist/service/session-presentation-service.js +43 -2
  116. package/dist/service/session-query-service.js +82 -2
  117. package/dist/service/session-watch-slot-coordinator.js +21 -2
  118. package/dist/service/skill-directory-service.js +238 -2
  119. package/dist/service/skill-install-service.js +434 -2
  120. package/dist/service/skill-node-operation-service.js +206 -2
  121. package/dist/service/terminal-relay-state.js +3 -2
  122. package/dist/service/terminal-service.js +90 -2
  123. package/dist/service/web-search-error.js +40 -2
  124. package/dist/service/workbench-event-service.js +21 -2
  125. package/dist/service/workbench-manifest-service.js +69 -2
  126. package/dist/service/workspace-change-service.js +290 -2
  127. package/dist/service/workspace-content-search-service.js +457 -2
  128. package/dist/service/workspace-domain-state.js +41 -2
  129. package/dist/service/workspace-file-service.js +150 -2
  130. package/dist/service/workspace-git-exclude-service.js +119 -2
  131. package/dist/service/workspace-queue-workbench-service.js +176 -2
  132. package/dist/service/workspace-service.js +92 -2
  133. package/dist/service/workspace-session-service.js +154 -2
  134. package/dist/service/workspace-upload-service.js +262 -2
  135. package/dist/service/workspace-watch-controller.js +68 -2
  136. package/dist/service/workspace-watch-service.js +170 -2
  137. package/dist/service/workspace-watch-snapshot-service.js +218 -2
  138. package/dist/service/workspace-workbench-service.js +239 -2
  139. package/dist/service.js +91 -2
  140. package/dist/storage.js +32 -2
  141. package/dist/supervisor.js +136 -2
  142. package/dist/terminal.js +496 -2
  143. package/dist/util/git-credential-client.js +32 -0
  144. package/dist/util/node-operation-data.js +9 -2
  145. package/dist/util/node-operation-parsers.js +382 -2
  146. package/dist/util/personal-instructions.js +34 -2
  147. package/dist/util/runner-error.js +70 -2
  148. package/dist/util/runner-native-session-parsers.js +510 -2
  149. package/dist/util/safe-error.js +8 -2
  150. package/dist/util/secret-environment.js +25 -2
  151. package/dist/workspace.js +1793 -2
  152. package/package.json +11 -8
  153. package/vendor/ripgrep/darwin-arm64/rg +0 -0
  154. package/vendor/ripgrep/darwin-x64/rg +0 -0
  155. package/vendor/ripgrep/manifest.json +12 -0
  156. package/README.md +0 -42
  157. package/dist/event-buffer.js +0 -2
  158. package/dist/migrations/v001.js +0 -107
  159. package/dist/migrations/v002.js +0 -2
  160. package/dist/migrations/v003.js +0 -2
  161. package/dist/service/mcp-package-installer.js +0 -2
@@ -1,2 +1,683 @@
1
- /* mar-release-protected */
2
- function _0x273a(){const _0x476351=['zxzLBNrszxzPC2LVBG','AhLKCMf0zvj1BM5PBMDiAxn0B3j5','CMvHzfj1BNrPBwvqywDL','Bg9N','u0vtu0LptL9jtLzbteLe','ywnJzxb0zwq','u0vtu0LptL9ot1rFrK9vtKq','uLvotKLorW','C2XPy2u','C2vZC2LVBG','zw1PDfjLywX0Aw1L','u1rbuLrjtKC','CMvTB3zLtgvHC2u','mZG5nJGZnKnmEhPrvG','C3rHDhvZ','y29Kzq','Dw5Yzwy','CMvHzfbHz2u','Aw5PDgLHBf9YzwzYzxnO','y29TCg9Zzvj1BNrPBwvqywDL','u0vtu0LptL9xqvrdsf9ttKfqu0Hpvf9gquLmruq','mtKWody4nMzZsNvruq','u0vtu0LptL9xqvrdsf9sruzsrvnix0zbsuXfra','ywn0AxzPDhK','zxHLy3v0zvvUD2f0y2G','BgvHC2vuAw1LCG','y29UDMvYz2vqywDL','DhjHBNnPDgLVBKDLBMvYyxrPB24','Bg9JywWTDgvZDc1UB2rL','DgLTzxi','ChvIBgLZAfj1BNrPBwvtBMfWC2HVDa','zw1PDeXLyxnLrxzLBNq','zMfPBhvYzxm','B2jQzwn0','zw1PDf9WywDL','zgvSzxrL','D2f0y2G','zw1PDfnLC3nPB24','CMvZB2X2zq','CMvHzeHPC3rVCNLqywDL','D2f0y2GUzMfPBgvK','ChjVAMvJDf9ZBMfWC2HVDa','u0vtu0LptL9xqvrdsf9ot1rFrK9vtKq','CMvSzwfZzq','n1fVs25nuW','zxH0zxjUywXtzxnZAw9Uswq','Bgf0zxn0tgvHC2vfEhbPCNK','B2jZzxj2zwrqywDL','u0vtu0LptL9xqvrdsf9isvnut1jzx0zbsuXfra','zw1PDfbHz2u','C2LNBMf0DxjL','CMvMCMvZAa','Bg9JywWTDgvZDc1Nzw5LCMf0Aw9U','C2vZC2LVBKHHC2G','AxnxyxrJAgLUzW','BwfUywDLzefJDgL2zq','zw50CNK','zw1PDfnUyxbZAg90','BgvHC2vZ','y29UDMvYz2vFCgfNzq','CgvYzM9YBvjLzNjLC2G','ChvZAa','B3DUzxjlzxK','CgfNzq','Dw5PDa','vfvstG','D29YA3nWywnLswq','CNvUDgLTzvbHz2u','BNvTyMvY','Bw9Kzq','y29UDMvYz2viAxn0B3j5','oda3nZGZmLnjww1yDq','BM9KzuDLBMvYyxrPB24','Dw5RBM93BG','CNvUDgLTzvjLDMLZAw9U','ChjLC2vUDa','D29YA2jLBMnOq29UBMvJDgLVBKLK','BgvUz3rO','C2vZC2LVBLDHDgnOu2XVDhm','Aw5PDgLHBgL6zuXLyxnL','q0foq0vmteLorW','AgfZ','BM9KzuLK','DgvZDa','CMvSzwfZzvbLBMrPBMDfDMvUDhm','D2f0y2GUC2vZC2LVBI5ZBMfWC2HVDa','zw1PDfDHDgnOrxzLBNq','B3DUCW','y2XLyxi','yxv0Ag9YAxr5','zxHLy3v0zvDHDgnO','CMvMCMvZAf9Hy3rPDML0Eq','surmrq','zMLSDgvY','C3rYAw5N','CNvU','Bg9JywWTDgvZDa','C2vZC2LVBI53yxrJAc5YDw50Aw1LlxnUyxbZAg90lMzHAwXLza','B3bLCMf0Aw9UCW','u2vZC2LVBIb3yxrJAcbZBMfWC2HVDcbMywLSzwqU','C2v0','zw1PDe9IC2vYDMvKugfNzq','C2XVDfrVA2vU','x193B3jRC3bHy2vxyxrJAfnLC3nPB25iyxnO','u0vtu0LptL9xqvrdsf9svu5usu1fx1noqvbtse9ux0zbsuXfra','B3b0Aw9UCW','Bwf4','otCYnti4AvPAswzp','A2v5CW','C25HChnOB3rtzxf1zw5Jzq','ChjLC2vUDf9ZzxnZAw9U','zMfPBfnLC3nPB24','CgvUzgLUz0v2zw50CW','Aw5PDgLHBa','C2vXDwvUy2u','CMvWBgfJzq','mtuXmZe0nKnrz0D5zq','D2f0y2GUC2vZC2LVBI5LDMvUDa','AgLZDg9YEvjLywq','DMfSDwvZ','D2f0y2HLCW','CMvSzwfZzvnLC3nPB25mzwfZzxm','C2vZC2LVBLnPz25HDhvYzq','Cgf5Bg9Hza','C2vZC2LVBI53yxrJAc5YzwzYzxnOlMzHAwXLza','z2v0','CMvHzf9WywDL','q09ovKvsr0LorW','mtC2mti5mtbYzefSBhK','CNvUDgLTzvjLywq','u0vhtuvova','C291CMnL','C25HChnOB3rtzw50','C2vZC2LVBI53yxrJAc5PBML0AwfSlMzHAwXLza','y2f0zwDVCNK','CMvHzhK','BM93','C3vZCgvUzgvK','CNvUBMvY','C3rYAw5NAwz5','C2vZC2LVBI53yxrJAc5YDw5UAw5NlwHPC3rVCNKUzMfPBgvK','zw1PDfnUyxbZAg90vg9mzwfZzxm','DhvYBNm','CMvMCMvZAfrPBwvY','murWEwPkDa','Aw52ywXPzgf0zq','mJi1mdyXnvrAtvfADG','CMvUzxC','u0vtu0LptL9xt1jlu1bbq0vFtuLttufuq0G','tKfusvzfx1rsqu5tq1jjufrFvu5bvKfjtefcteu','C3rVCa','zxHWAxjLC0f0','D2f0y2Hjza','CMvSzwfZzvnUyxbZAg90ugvUzgLUz0v2zw50CW','ChjVAMvJDeLUAxrPywXqywDL','seLtve9swq','AxntywzLsw50zwDLCG','tufoquDfrf9bq1rjvKu','C2vZC2LVBKLK','CMvMCMvZAefJDgL2Axr5','C2L6zq'];_0x273a=function(){return _0x476351;};return _0x273a();}function _0x451c(_0x1a4388,_0x5d3b64){_0x1a4388=_0x1a4388-(0x1f8c+-0x945*0x2+-0xc15);const _0x32ec02=_0x273a();let _0x23dae0=_0x32ec02[_0x1a4388];if(_0x451c['NvtIcV']===undefined){var _0x47f100=function(_0x4ded47){const _0x449be5='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x5baa91='',_0x5a17f8='';for(let _0x2cabb7=0x18da+0xef*0xb+-0x1*0x231f,_0x4ba39d,_0x4a2200,_0x208c7b=-0x6f6*0x3+0x2*0x112f+0x1*-0xd7c;_0x4a2200=_0x4ded47['charAt'](_0x208c7b++);~_0x4a2200&&(_0x4ba39d=_0x2cabb7%(-0x165b*0x1+-0x6f1+0x43*0x70)?_0x4ba39d*(0x18a0*0x1+0x175d*-0x1+-0x103)+_0x4a2200:_0x4a2200,_0x2cabb7++%(-0x3be+0x73e*0x2+-0x55d*0x2))?_0x5baa91+=String['fromCharCode'](0x377*-0x1+-0xc2f*-0x1+-0x7b9&_0x4ba39d>>(-(-0x1b3a+0x73b+0x1401)*_0x2cabb7&0x995+0x54*0x1f+-0x13bb)):-0x65*0x17+-0x1b1*-0x15+0x1a72*-0x1){_0x4a2200=_0x449be5['indexOf'](_0x4a2200);}for(let _0xd8bd73=-0x131c*0x2+-0x11b0*-0x2+-0x2*-0x16c,_0x16d971=_0x5baa91['length'];_0xd8bd73<_0x16d971;_0xd8bd73++){_0x5a17f8+='%'+('00'+_0x5baa91['charCodeAt'](_0xd8bd73)['toString'](0x711+0x1f1a+0x1*-0x261b))['slice'](-(0x19f+-0x33d+-0x68*-0x4));}return decodeURIComponent(_0x5a17f8);};_0x451c['eNzbAk']=_0x47f100,_0x451c['TntXFw']={},_0x451c['NvtIcV']=!![];}const _0x1f9bd1=_0x32ec02[-0x2e3*0x1+-0x1c98+0x1f7b];_0x451c['LRpdCo']!==_0x1f9bd1&&(_0x451c['TntXFw']={},_0x451c['LRpdCo']=_0x1f9bd1);const _0x334615=_0x451c['TntXFw'][_0x1a4388];return _0x334615===undefined?(_0x23dae0=_0x451c['eNzbAk'](_0x23dae0),_0x451c['TntXFw'][_0x1a4388]=_0x23dae0):_0x23dae0=_0x334615,_0x23dae0;}const _0x55e41a=_0x451c;(function(_0x15bfce,_0x3e9db6){const _0x3f2677=_0x451c,_0x176413=_0x15bfce();while(!![]){try{const _0xfe904b=-parseInt(_0x3f2677(0x16f))/(0x7b9+0xa23+0x1*-0x11db)*(parseInt(_0x3f2677(0xf4))/(0x49*-0x7+0x26fc*0x1+-0x24fb))+-parseInt(_0x3f2677(0x14a))/(0x1a83+-0x9*0x11a+-0x1*0x1096)+-parseInt(_0x3f2677(0x18d))/(0x24e6*0x1+0x941*-0x2+-0x31*0x60)+-parseInt(_0x3f2677(0x171))/(-0xbba+0x2192+-0x15d3)+parseInt(_0x3f2677(0x153))/(-0x9a9*0x4+0x2*-0xa5e+0x3b66)*(parseInt(_0x3f2677(0x10b))/(-0x49b*0x6+-0x2*-0xef+0x19cb))+parseInt(_0x3f2677(0x126))/(0xa3e+-0xa4+-0x992)+parseInt(_0x3f2677(0x15f))/(0x84*0x36+0x1cfb+-0x38ca);if(_0xfe904b===_0x3e9db6)break;else _0x176413['push'](_0x176413['shift']());}catch(_0x233317){_0x176413['push'](_0x176413['shift']());}}}(_0x273a,-0x1*0x80616+0xf82d2+-0x3f7*-0x19));import{isPlainRecord}from'../runner/codex/conversation-parser.js';import{safeErrorCode}from'../util/safe-error.js';import{SessionWatchSlotCoordinator}from'./session-watch-slot-coordinator.js';const INTERVAL_MS=0x1b01+0x1fb6+0x32e7*-0x1,TTL_MS=0x1*-0x13d05+-0x443b*-0x4+0xdbe1,MAX_FAILURES=0xbb4+0x6*-0x5a7+-0x1639*-0x1,INITIAL_TURN_LIMIT=0xb4d*0x1+0x2496+-0x2fc5,EMITTED_TURN_LIMIT=0x73e*0x2+-0xe27*0x1+-0x4b;export class NativeSessionWatchService{[_0x55e41a(0x148)];[_0x55e41a(0x157)]=new Map();[_0x55e41a(0x119)]=new Map();[_0x55e41a(0x12d)];[_0x55e41a(0x14c)]=0xc2f*0x1+0xe2c+-0x1a5b;constructor(_0x6c860a){const _0x369665=_0x55e41a;this[_0x369665(0x148)]=_0x6c860a,this[_0x369665(0x12d)]=_0x6c860a[_0x369665(0x12d)]??new SessionWatchSlotCoordinator();}[_0x55e41a(0x141)](){const _0x5b83aa=_0x55e41a;return{'session.watch':_0x1630fd=>this[_0x5b83aa(0x139)](isPlainRecord(_0x1630fd)?_0x1630fd:{}),'session.unwatch':_0x50453f=>this[_0x5b83aa(0xf7)](isPlainRecord(_0x50453f)?_0x50453f:{})};}async[_0x55e41a(0x139)](_0x190cef){const _0x40720c=_0x55e41a,_0xebf88d=this[_0x40720c(0x148)][_0x40720c(0x179)];if(_0x190cef[_0x40720c(0x11f)]===_0x40720c(0x161)&&_0xebf88d===undefined)throw new Error(_0x40720c(0x184));if(typeof _0x190cef[_0x40720c(0x17d)]!==_0x40720c(0x13d)||_0x190cef[_0x40720c(0x121)]!==undefined&&typeof _0x190cef[_0x40720c(0x121)]!==_0x40720c(0x13d)||typeof _0x190cef[_0x40720c(0x177)]!==_0x40720c(0x13d)||typeof _0x190cef[_0x40720c(0x12b)]!==_0x40720c(0x13d)||_0x190cef[_0x40720c(0x124)]!==_0x40720c(0x150)&&_0x190cef[_0x40720c(0x124)]!==_0x40720c(0x172)||_0x190cef[_0x40720c(0x11f)]!==undefined&&_0x190cef[_0x40720c(0x11f)]!==_0x40720c(0x161))throw new Error(_0x40720c(0x184));const _0x1d4160=this[_0x40720c(0x11d)](_0x190cef);if(_0x190cef[_0x40720c(0x124)]===_0x40720c(0x172)){const _0x20abc5=this[_0x40720c(0x119)][_0x40720c(0x15c)](_0x1d4160);if(_0x20abc5===undefined||!this[_0x40720c(0x12d)][_0x40720c(0x136)](_0x1d4160,_0x20abc5[_0x40720c(0x145)])||_0x20abc5[_0x40720c(0x177)]!==_0x190cef[_0x40720c(0x177)]||_0x20abc5[_0x40720c(0x17d)]!==_0x190cef[_0x40720c(0x17d)]||_0x190cef[_0x40720c(0x121)]!==undefined&&_0x20abc5[_0x40720c(0x121)]!==_0x190cef[_0x40720c(0x121)])throw new Error(_0x40720c(0x109));if(_0x20abc5[_0x40720c(0x176)]<=Date[_0x40720c(0x167)]()){this[_0x40720c(0x18c)](_0x1d4160);throw new Error(_0x40720c(0x109));}_0x20abc5[_0x40720c(0x176)]=Date[_0x40720c(0x167)]()+TTL_MS;const _0x380b14=this[_0x40720c(0x157)][_0x40720c(0x15c)](_0x20abc5[_0x40720c(0x17d)]);if(_0x380b14!==undefined)_0x380b14[_0x40720c(0x176)]=this[_0x40720c(0x10d)](_0x20abc5[_0x40720c(0x17d)]);return clearTimeout(_0x20abc5[_0x40720c(0xfc)]),_0x20abc5[_0x40720c(0xfc)]=this[_0x40720c(0xf8)](_0x1d4160),this[_0x40720c(0x185)](_0x20abc5);}const _0x19aa1a=this[_0x40720c(0x119)][_0x40720c(0x15c)](_0x1d4160),_0x2062a4=_0x190cef[_0x40720c(0x11f)]===_0x40720c(0x161)?_0x40720c(0x161):_0x40720c(0x120);if(_0x19aa1a?.[_0x40720c(0x177)]===_0x190cef[_0x40720c(0x177)]&&this[_0x40720c(0x12d)][_0x40720c(0x136)](_0x1d4160,_0x19aa1a[_0x40720c(0x145)])&&_0x19aa1a[_0x40720c(0x17d)]===_0x190cef[_0x40720c(0x17d)]&&(_0x190cef[_0x40720c(0x121)]===undefined||_0x19aa1a[_0x40720c(0x121)]===_0x190cef[_0x40720c(0x121)])&&_0x19aa1a[_0x40720c(0x11f)]===_0x2062a4&&_0x19aa1a[_0x40720c(0x176)]>Date[_0x40720c(0x167)]())return _0x19aa1a[_0x40720c(0x176)]=Date[_0x40720c(0x167)]()+TTL_MS,clearTimeout(_0x19aa1a[_0x40720c(0xfc)]),_0x19aa1a[_0x40720c(0xfc)]=this[_0x40720c(0xf8)](_0x1d4160),this[_0x40720c(0x185)](_0x19aa1a);this[_0x40720c(0x18c)](_0x1d4160);const _0x18a0d9=this[_0x40720c(0x12d)][_0x40720c(0x152)](_0x1d4160,_0x40720c(0x189),()=>this[_0x40720c(0x18c)](_0x1d4160)),_0x2611ea={'ownerKey':_0x1d4160,'sessionHash':this[_0x40720c(0x114)](_0x190cef),'workbenchConnectionId':_0x190cef[_0x40720c(0x12b)],'watchId':_0x190cef[_0x40720c(0x177)],'sessionId':_0x190cef[_0x40720c(0x17d)],'unit':_0x2062a4,'nodeGeneration':this[_0x40720c(0x148)][_0x40720c(0x127)]?.()??_0x40720c(0x113),...typeof _0x190cef[_0x40720c(0x121)]===_0x40720c(0x13d)?{'workspaceId':_0x190cef[_0x40720c(0x121)]}:{},'expiresAt':Date[_0x40720c(0x167)]()+TTL_MS,'ready':![],'snapshotSent':![],'pendingEvents':[],'slotToken':_0x18a0d9,'timer':undefined};_0x2611ea[_0x40720c(0xfc)]=this[_0x40720c(0xf8)](_0x1d4160),this[_0x40720c(0x119)][_0x40720c(0x143)](_0x1d4160,_0x2611ea);const _0xb1e0bb=this[_0x40720c(0x157)][_0x40720c(0x15c)](_0x2611ea[_0x40720c(0x17d)]);if(_0xb1e0bb!==undefined)_0xb1e0bb[_0x40720c(0x176)]=this[_0x40720c(0x10d)](_0x2611ea[_0x40720c(0x17d)]);return void this[_0x40720c(0x12e)](_0x2611ea,_0xebf88d),this[_0x40720c(0x185)](_0x2611ea);}[_0x55e41a(0xf7)](_0x25f4b1){const _0x53ed26=_0x55e41a;if(typeof _0x25f4b1[_0x53ed26(0x17d)]!==_0x53ed26(0x13d)||typeof _0x25f4b1[_0x53ed26(0x177)]!==_0x53ed26(0x13d)||typeof _0x25f4b1[_0x53ed26(0x12b)]!==_0x53ed26(0x13d))throw new Error(_0x53ed26(0x184));const _0x1e470f=this[_0x53ed26(0x11d)](_0x25f4b1),_0xa29e1a=this[_0x53ed26(0x119)][_0x53ed26(0x15c)](_0x1e470f);if(_0xa29e1a?.[_0x53ed26(0x177)]===_0x25f4b1[_0x53ed26(0x177)]&&_0xa29e1a[_0x53ed26(0x17d)]===_0x25f4b1[_0x53ed26(0x17d)])this[_0x53ed26(0x18c)](_0x1e470f);return{'stopped':!![]};}[_0x55e41a(0x103)](_0x55fe8c){const _0x849f85=_0x55e41a,_0x1c23b2=this[_0x849f85(0x157)][_0x849f85(0x15c)](_0x55fe8c['id']);if(_0x1c23b2!==undefined)return _0x1c23b2[_0x849f85(0x176)]=Date[_0x849f85(0x167)]()+TTL_MS,{'expiresAt':_0x1c23b2[_0x849f85(0x176)]};const _0x49d21a={'session':_0x55fe8c,'mode':this[_0x849f85(0x148)][_0x849f85(0x116)](_0x55fe8c)?_0x849f85(0x187):_0x849f85(0x17a),'expiresAt':Date[_0x849f85(0x167)]()+TTL_MS,'refresh':undefined,'sessionSignature':undefined,'signature':undefined,'page':undefined,'runtimePage':undefined,'runtimeRevision':undefined,'runtimeRead':undefined,'historyRead':undefined,'observedPage':undefined,'authority':undefined,'eventRevision':0x0,'failures':0x0,'transitionGeneration':0x0,'timer':undefined};return _0x49d21a[_0x849f85(0xfc)]=this[_0x849f85(0x16e)](_0x55fe8c['id']),this[_0x849f85(0x157)][_0x849f85(0x143)](_0x55fe8c['id'],_0x49d21a),{'expiresAt':_0x49d21a[_0x849f85(0x176)]};}[_0x55e41a(0x18a)](_0x2af12d,_0x1e3bff){const _0x49faef=_0x55e41a,_0x36356f=this[_0x49faef(0x157)][_0x49faef(0x15c)](_0x2af12d);if(_0x36356f!==undefined)_0x36356f[_0x49faef(0x180)]=_0x1e3bff[_0x49faef(0x151)];const _0x38101b=[...this[_0x49faef(0x119)][_0x49faef(0x156)]()][_0x49faef(0x13c)](_0x1ede77=>_0x1ede77[_0x49faef(0x17d)]===_0x2af12d),_0x5c1798=sessionActivity(_0x1e3bff);if(_0x36356f!==undefined&&_0x5c1798===_0x49faef(0x187)&&_0x36356f[_0x49faef(0x124)]!==_0x49faef(0x187)){_0x36356f[_0x49faef(0x124)]=_0x49faef(0x187),_0x36356f[_0x49faef(0xfa)]+=-0x1b3a+0x73b+0x1400;for(const _0x30de3d of _0x38101b)_0x30de3d[_0x49faef(0x166)]=![];void this[_0x49faef(0xfd)](_0x36356f,_0x36356f[_0x49faef(0xfa)]);}else{if(_0x36356f!==undefined&&_0x5c1798===_0x49faef(0x13b)&&_0x36356f[_0x49faef(0x124)]===_0x49faef(0x187)){_0x36356f[_0x49faef(0x124)]=_0x49faef(0x15e);const _0x42ce58=++_0x36356f[_0x49faef(0xfa)];for(const _0x8c5c23 of _0x38101b)_0x8c5c23[_0x49faef(0x166)]=![];setTimeout(()=>void this[_0x49faef(0x125)](_0x36356f,_0x42ce58),0x995+0x54*0x1f+-0x13c1);}}for(const _0x1b5be5 of _0x38101b){if(!_0x1b5be5[_0x49faef(0x166)])_0x1b5be5[_0x49faef(0x14f)][_0x49faef(0x11c)](_0x1e3bff);else this[_0x49faef(0xfe)](_0x1b5be5,_0x1e3bff);}return _0x38101b[_0x49faef(0x12c)]>-0x65*0x17+-0x1b1*-0x15+0x1a72*-0x1;}[_0x55e41a(0x172)](_0x5ee048){const _0x3e3ff2=_0x55e41a,_0x4fc210=this[_0x3e3ff2(0x157)][_0x3e3ff2(0x15c)](_0x5ee048['id']);if(_0x4fc210===undefined||_0x4fc210[_0x3e3ff2(0x176)]<=Date[_0x3e3ff2(0x167)]())return this[_0x3e3ff2(0x175)](_0x5ee048['id']),undefined;return _0x4fc210[_0x3e3ff2(0x176)]=Date[_0x3e3ff2(0x167)]()+TTL_MS,{'expiresAt':_0x4fc210[_0x3e3ff2(0x176)]};}[_0x55e41a(0x175)](_0x3e4f99){const _0x340358=_0x55e41a,_0xffa4f8=this[_0x340358(0x157)][_0x340358(0x15c)](_0x3e4f99);if(_0xffa4f8===undefined)return;clearTimeout(_0xffa4f8[_0x340358(0xfc)]),this[_0x340358(0x157)][_0x340358(0x102)](_0x3e4f99);}[_0x55e41a(0x170)](_0x50d51c){const _0x56169b=_0x55e41a;for(const [_0x12c247,_0x309343]of this[_0x56169b(0x119)])if(_0x309343[_0x56169b(0x17d)]===_0x50d51c)this[_0x56169b(0x18c)](_0x12c247);this[_0x56169b(0x175)](_0x50d51c);}[_0x55e41a(0x137)](){const _0x31196a=_0x55e41a;for(const _0x5d4f1d of this[_0x31196a(0x157)][_0x31196a(0x156)]())clearTimeout(_0x5d4f1d[_0x31196a(0xfc)]);this[_0x31196a(0x157)][_0x31196a(0x137)]();for(const _0x382e68 of[...this[_0x31196a(0x119)][_0x31196a(0x14b)]()])this[_0x31196a(0x18c)](_0x382e68);}[_0x55e41a(0x130)](_0x3132ba){const _0x1466a5=_0x55e41a;return this[_0x1466a5(0x157)][_0x1466a5(0x130)](_0x3132ba);}[_0x55e41a(0x115)](_0x54919d){const _0x5a4889=_0x55e41a;return this[_0x5a4889(0x130)](_0x54919d);}[_0x55e41a(0x117)](_0x353a3d){const _0x3d6147=_0x55e41a;return this[_0x3d6147(0x157)][_0x3d6147(0x15c)](_0x353a3d);}get[_0x55e41a(0x17f)](){const _0x4a9d19=_0x55e41a;return this[_0x4a9d19(0x157)][_0x4a9d19(0x17f)];}async[_0x55e41a(0x112)](_0xa616fd,_0x202083=-0x131c*0x2+-0x11b0*-0x2+-0x2*-0x171,_0x5e7903=!![]){const _0x5d086b=_0x55e41a,_0x7c4f02=this[_0x5d086b(0x157)][_0x5d086b(0x15c)](_0xa616fd);if(_0x7c4f02===undefined)return undefined;if(_0x7c4f02[_0x5d086b(0x112)]!==undefined)return _0x7c4f02[_0x5d086b(0x112)];if(_0x7c4f02[_0x5d086b(0x176)]<=Date[_0x5d086b(0x167)]())return this[_0x5d086b(0x175)](_0xa616fd),undefined;const _0x503f7a=this[_0x5d086b(0x11b)](_0xa616fd,_0x7c4f02,_0x202083,_0x5e7903);_0x7c4f02[_0x5d086b(0x112)]=_0x503f7a;try{return await _0x503f7a;}finally{this[_0x5d086b(0x157)][_0x5d086b(0x15c)](_0xa616fd)===_0x7c4f02&&(_0x7c4f02[_0x5d086b(0x112)]=undefined,clearTimeout(_0x7c4f02[_0x5d086b(0xfc)]),_0x7c4f02[_0x5d086b(0xfc)]=this[_0x5d086b(0x16e)](_0xa616fd));}}async[_0x55e41a(0x11b)](_0x29cc7d,_0x51ed06,_0x11d51e,_0x35c208){const _0x43f52b=_0x55e41a;let _0x308fc2=_0x43f52b(0x105),_0x333b4b;const _0xa91683=_0x51ed06[_0x43f52b(0x124)]===_0x43f52b(0x17a)&&this[_0x43f52b(0x148)][_0x43f52b(0x106)]!==undefined;try{if(this[_0x43f52b(0x148)][_0x43f52b(0x168)]?.(_0x29cc7d)===!![])return _0x51ed06[_0x43f52b(0x11e)];_0x333b4b=await this[_0x43f52b(0x148)][_0x43f52b(0x105)](_0x29cc7d);if(_0x333b4b===undefined||_0x333b4b[_0x43f52b(0x10c)]===null)return this[_0x43f52b(0x158)](_0x29cc7d),undefined;_0x51ed06[_0x43f52b(0x189)]=_0x333b4b;if(_0x35c208&&this[_0x43f52b(0x148)][_0x43f52b(0x116)](_0x333b4b))return _0x51ed06[_0x43f52b(0x11e)];_0x308fc2=_0x43f52b(0x13a),await this[_0x43f52b(0x148)][_0x43f52b(0x17e)](_0x333b4b);if(this[_0x43f52b(0x148)][_0x43f52b(0x168)]?.(_0x29cc7d)===!![])return _0x51ed06[_0x43f52b(0x11e)];_0x308fc2=_0x43f52b(0x15d);const _0x31dcbc=_0x51ed06[_0x43f52b(0x180)],_0x3b91d3=await(_0xa91683?this[_0x43f52b(0x148)][_0x43f52b(0x106)](_0x333b4b,_0x11d51e):this[_0x43f52b(0x148)][_0x43f52b(0xf0)](_0x333b4b,_0x11d51e));if(_0x35c208&&_0x31dcbc!==_0x51ed06[_0x43f52b(0x180)])return _0x51ed06[_0x43f52b(0x11e)];_0x308fc2=_0x43f52b(0x14d);const _0x98d033=this[_0x43f52b(0x148)][_0x43f52b(0x12a)](_0x333b4b),_0x2cc93a=JSON[_0x43f52b(0x16a)](_0x98d033);if(_0x2cc93a!==_0x51ed06[_0x43f52b(0x159)]){_0x51ed06[_0x43f52b(0x159)]=_0x2cc93a;if(_0x35c208)this[_0x43f52b(0x148)][_0x43f52b(0x104)](_0x98d033);}_0x51ed06[_0x43f52b(0xff)]=0x711+0x1f1a+0x1*-0x262b;const _0x424a13=_0x3b91d3[_0x43f52b(0x16d)][_0x43f52b(0x12c)]<=EMITTED_TURN_LIMIT?_0x3b91d3[_0x43f52b(0x16d)]:_0x3b91d3[_0x43f52b(0x16d)][_0x43f52b(0x188)](-EMITTED_TURN_LIMIT),_0x34e86f={..._0x3b91d3,'turns':_0x424a13};_0x308fc2=_0x43f52b(0x11a);const _0x4127b1=this[_0x43f52b(0x148)][_0x43f52b(0xf9)](_0x51ed06[_0x43f52b(0x11e)],_0x51ed06[_0x43f52b(0x10e)],_0x34e86f,_0x51ed06[_0x43f52b(0x138)]),_0x4c05c7=_0x4127b1[_0x43f52b(0x11e)],_0x2eb855=_0x4c05c7[_0x43f52b(0x16d)][_0x43f52b(0x12c)]<=EMITTED_TURN_LIMIT+(0x19f+-0x33d+-0x19f*-0x1)?_0x4c05c7:{..._0x4c05c7,'turns':_0x4c05c7[_0x43f52b(0x16d)][_0x43f52b(0x188)](-(EMITTED_TURN_LIMIT+(-0x2e3*0x1+-0x1c98+0x1f7c)))};_0x51ed06[_0x43f52b(0x10e)]=_0x34e86f,_0x51ed06[_0x43f52b(0x138)]=_0x4127b1[_0x43f52b(0x138)];const _0x775a8b=_0x51ed06[_0x43f52b(0x124)]===_0x43f52b(0x15e)&&!this[_0x43f52b(0x148)][_0x43f52b(0x116)](_0x333b4b);_0x775a8b&&(_0x51ed06[_0x43f52b(0x124)]=_0x43f52b(0x17a),_0x51ed06[_0x43f52b(0x122)]=undefined,_0x51ed06[_0x43f52b(0x129)]=undefined);const _0x20526f=JSON[_0x43f52b(0x16a)]({'source':_0x2eb855[_0x43f52b(0x162)],'turns':_0x2eb855[_0x43f52b(0x16d)]}),_0xc4207e=_0x20526f!==_0x51ed06[_0x43f52b(0x111)];_0xc4207e&&(_0x51ed06[_0x43f52b(0x111)]=_0x20526f,_0x51ed06[_0x43f52b(0x11e)]=_0x2eb855);_0x308fc2=_0x43f52b(0x101);if(_0x35c208&&_0x775a8b)this[_0x43f52b(0x16c)](_0x333b4b,_0x2eb855,!![]);else{if(_0x35c208&&_0xc4207e)this[_0x43f52b(0x144)](_0x333b4b,_0x2eb855);}return _0x35c208?_0x2eb855:_0x3b91d3;}catch(_0xfac5fb){_0x51ed06[_0x43f52b(0xff)]+=-0x6*0x2ed+-0x29*-0xe9+0x232*-0x9,this[_0x43f52b(0x148)][_0x43f52b(0x183)]?.(_0x43f52b(0x15b),{'nodeId':this[_0x43f52b(0x148)][_0x43f52b(0x131)]?.()??_0x43f52b(0xfb),'sessionId':_0x29cc7d,..._0x333b4b===undefined?{}:{'runner':_0x333b4b[_0x43f52b(0x169)]},'stage':_0x308fc2,'errorCode':diagnosticErrorCode(_0xfac5fb,_0x43f52b(0xf5)),'failureCount':_0x51ed06[_0x43f52b(0xff)],'terminal':_0x51ed06[_0x43f52b(0xff)]>=MAX_FAILURES});if(_0x51ed06[_0x43f52b(0xff)]>=MAX_FAILURES)this[_0x43f52b(0x14e)](_0x29cc7d);return undefined;}}[_0x55e41a(0x114)](_0x4a7376){const _0x441761=_0x55e41a;return typeof _0x4a7376[_0x441761(0x146)]===_0x441761(0x13d)?_0x4a7376[_0x441761(0x146)]:_0x441761(0x13f);}[_0x55e41a(0x11d)](_0x8cadba){const _0x12d69b=_0x55e41a;return this[_0x12d69b(0x114)](_0x8cadba)+':'+_0x8cadba[_0x12d69b(0x12b)];}[_0x55e41a(0x185)](_0x1088f9){const _0x433aaa=_0x55e41a;return{'accepted':!![],'watchId':_0x1088f9[_0x433aaa(0x177)],'nodeGeneration':_0x1088f9[_0x433aaa(0x127)],'expiresAt':_0x1088f9[_0x433aaa(0x176)]};}async[_0x55e41a(0x12e)](_0x4cbe38,_0x191907){const _0x2c9abc=_0x55e41a;let _0x38bc44=_0x2c9abc(0x105);try{const _0x499ec0=await this[_0x2c9abc(0x148)][_0x2c9abc(0x105)](_0x4cbe38[_0x2c9abc(0x17d)]);if(_0x499ec0===undefined||_0x499ec0[_0x2c9abc(0x10c)]===null)throw new Error(_0x2c9abc(0x186));if(_0x4cbe38[_0x2c9abc(0x121)]!==undefined&&_0x499ec0[_0x2c9abc(0x121)]!==_0x4cbe38[_0x2c9abc(0x121)])throw new Error(_0x2c9abc(0x173));if(this[_0x2c9abc(0x119)][_0x2c9abc(0x15c)](_0x4cbe38[_0x2c9abc(0x11d)])!==_0x4cbe38)return;_0x4cbe38[_0x2c9abc(0x121)]=_0x499ec0[_0x2c9abc(0x121)],_0x38bc44=_0x2c9abc(0xf1),this[_0x2c9abc(0x103)](_0x499ec0);const _0x10fab6=this[_0x2c9abc(0x157)][_0x2c9abc(0x15c)](_0x499ec0['id']);if(_0x10fab6!==undefined)_0x10fab6[_0x2c9abc(0x189)]=_0x499ec0;const _0x590d4d=this[_0x2c9abc(0x148)][_0x2c9abc(0x116)](_0x499ec0);if(_0x10fab6!==undefined)_0x10fab6[_0x2c9abc(0x124)]=_0x590d4d?_0x2c9abc(0x187):_0x10fab6[_0x2c9abc(0x124)];const _0x534e9a=!_0x590d4d&&_0x10fab6?.[_0x2c9abc(0x11e)]!==undefined?_0x10fab6[_0x2c9abc(0x11e)]:undefined;let _0x55cd54=_0x590d4d?_0x10fab6===undefined?undefined:this[_0x2c9abc(0xf2)](_0x10fab6[_0x2c9abc(0x11e)],await this[_0x2c9abc(0x182)](_0x10fab6,_0x499ec0)):_0x534e9a??(_0x10fab6===undefined?undefined:await this[_0x2c9abc(0x112)](_0x499ec0['id'],INITIAL_TURN_LIMIT,![]));if(_0x55cd54===undefined)throw new Error(_0x2c9abc(0x174));if(_0x4cbe38[_0x2c9abc(0x163)])return;const _0x3cd181=this[_0x2c9abc(0x148)][_0x2c9abc(0x116)](_0x499ec0);_0x3cd181&&!_0x590d4d&&_0x10fab6!==undefined&&(_0x10fab6[_0x2c9abc(0x124)]=_0x2c9abc(0x187),_0x55cd54=this[_0x2c9abc(0xf2)](_0x55cd54,await this[_0x2c9abc(0x182)](_0x10fab6,_0x499ec0)));_0x38bc44=_0x2c9abc(0x108);const _0x55a804=_0x4cbe38[_0x2c9abc(0x11f)]===_0x2c9abc(0x161)?_0x191907(_0x499ec0,_0x55cd54,_0x2c9abc(0x161),-0x1*-0x1124+0x481*0x8+-0x3522):_0x55cd54;if(this[_0x2c9abc(0x119)][_0x2c9abc(0x15c)](_0x4cbe38[_0x2c9abc(0x11d)])!==_0x4cbe38)return;this[_0x2c9abc(0x118)](_0x4cbe38,_0x499ec0,_0x55a804),this[_0x2c9abc(0x178)](_0x4cbe38,_0x55cd54);if(_0x3cd181&&_0x10fab6!==undefined&&_0x10fab6[_0x2c9abc(0x11e)]===undefined)void this[_0x2c9abc(0x181)](_0x10fab6,_0x499ec0);}catch(_0x14302a){if(this[_0x2c9abc(0x119)][_0x2c9abc(0x15c)](_0x4cbe38[_0x2c9abc(0x11d)])!==_0x4cbe38)return;const _0x214e41=diagnosticErrorCode(_0x14302a,_0x2c9abc(0xf3));this[_0x2c9abc(0x148)][_0x2c9abc(0x183)]?.(_0x2c9abc(0x164),{'nodeId':this[_0x2c9abc(0x148)][_0x2c9abc(0x131)]?.()??_0x2c9abc(0xfb),'sessionId':_0x4cbe38[_0x2c9abc(0x17d)],'workspaceId':_0x4cbe38[_0x2c9abc(0x121)]??_0x2c9abc(0x128),'workbenchConnectionId':_0x4cbe38[_0x2c9abc(0x12b)],'watchId':_0x4cbe38[_0x2c9abc(0x177)],'stage':_0x38bc44,'errorCode':_0x214e41}),this[_0x2c9abc(0x148)][_0x2c9abc(0x135)]?.({'type':_0x2c9abc(0x107),'workbenchConnectionId':_0x4cbe38[_0x2c9abc(0x12b)],'watchType':_0x2c9abc(0x189),'watchId':_0x4cbe38[_0x2c9abc(0x177)],'nodeGeneration':_0x4cbe38[_0x2c9abc(0x127)],'nodeId':this[_0x2c9abc(0x148)][_0x2c9abc(0x131)]?.()??_0x2c9abc(0xfb),'workspaceId':_0x4cbe38[_0x2c9abc(0x121)]??_0x2c9abc(0x128),'sessionId':_0x4cbe38[_0x2c9abc(0x17d)],'code':_0x214e41,'message':_0x2c9abc(0x142)}),this[_0x2c9abc(0x18c)](_0x4cbe38[_0x2c9abc(0x11d)]);}}[_0x55e41a(0x18c)](_0x56063f){const _0x1eaadb=_0x55e41a,_0x27e3a6=this[_0x1eaadb(0x119)][_0x1eaadb(0x15c)](_0x56063f);if(_0x27e3a6===undefined)return;clearTimeout(_0x27e3a6[_0x1eaadb(0xfc)]),this[_0x1eaadb(0x119)][_0x1eaadb(0x102)](_0x56063f),this[_0x1eaadb(0x12d)][_0x1eaadb(0x10a)](_0x56063f,_0x27e3a6[_0x1eaadb(0x145)]);const _0x2ee6ca=this[_0x1eaadb(0x157)][_0x1eaadb(0x15c)](_0x27e3a6[_0x1eaadb(0x17d)]),_0x47849c=this[_0x1eaadb(0x10d)](_0x27e3a6[_0x1eaadb(0x17d)]);if(_0x47849c===-0xe7*0x1f+0xa2d*-0x2+0x3053)this[_0x1eaadb(0x175)](_0x27e3a6[_0x1eaadb(0x17d)]);else{if(_0x2ee6ca!==undefined)_0x2ee6ca[_0x1eaadb(0x176)]=_0x47849c;}}[_0x55e41a(0xf2)](_0x18ad7f,_0x53e18a){const _0x25493f=_0x55e41a;return this[_0x25493f(0x148)][_0x25493f(0xf2)]?.(_0x18ad7f,_0x53e18a)??_0x53e18a;}async[_0x55e41a(0x182)](_0x11a7ef,_0x296b38){const _0x58bb77=_0x55e41a;if(_0x11a7ef[_0x58bb77(0x122)]!==undefined&&_0x11a7ef[_0x58bb77(0x129)]===_0x11a7ef[_0x58bb77(0x180)])return _0x11a7ef[_0x58bb77(0x122)];if(_0x11a7ef[_0x58bb77(0x160)]!==undefined)return _0x11a7ef[_0x58bb77(0x160)];const _0x56a295=_0x11a7ef[_0x58bb77(0x180)],_0x4b0ccb=this[_0x58bb77(0x148)][_0x58bb77(0xf0)](_0x296b38,INITIAL_TURN_LIMIT);_0x11a7ef[_0x58bb77(0x160)]=_0x4b0ccb;try{const _0x4710a2=await _0x4b0ccb;return this[_0x58bb77(0x157)][_0x58bb77(0x15c)](_0x296b38['id'])===_0x11a7ef&&(_0x11a7ef[_0x58bb77(0x122)]=_0x4710a2,_0x11a7ef[_0x58bb77(0x129)]=_0x56a295),_0x4710a2;}finally{if(this[_0x58bb77(0x157)][_0x58bb77(0x15c)](_0x296b38['id'])===_0x11a7ef&&_0x11a7ef[_0x58bb77(0x160)]===_0x4b0ccb)_0x11a7ef[_0x58bb77(0x160)]=undefined;}}async[_0x55e41a(0xfd)](_0x4133ac,_0x5bc43f){const _0xa1ebfa=_0x55e41a,_0x4c5fc0=_0x4133ac[_0xa1ebfa(0x189)];if(_0x4c5fc0===undefined)return;try{const _0x3619bc=await this[_0xa1ebfa(0x182)](_0x4133ac,_0x4c5fc0);if(this[_0xa1ebfa(0x157)][_0xa1ebfa(0x15c)](_0x4c5fc0['id'])!==_0x4133ac||_0x4133ac[_0xa1ebfa(0x124)]!==_0xa1ebfa(0x187)||_0x4133ac[_0xa1ebfa(0xfa)]!==_0x5bc43f)return;_0x4133ac[_0xa1ebfa(0x122)]=_0x3619bc,this[_0xa1ebfa(0x16c)](_0x4c5fc0,this[_0xa1ebfa(0xf2)](_0x4133ac[_0xa1ebfa(0x11e)],_0x3619bc),!![]);}catch(_0xe2c449){this[_0xa1ebfa(0x148)][_0xa1ebfa(0x183)]?.(_0xa1ebfa(0x140),{'nodeId':this[_0xa1ebfa(0x148)][_0xa1ebfa(0x131)]?.()??_0xa1ebfa(0xfb),'sessionId':_0x4c5fc0['id'],'runner':_0x4c5fc0[_0xa1ebfa(0x169)],'errorCode':diagnosticErrorCode(_0xe2c449,_0xa1ebfa(0x147))}),this[_0xa1ebfa(0x133)](_0x4c5fc0['id']);}}async[_0x55e41a(0x181)](_0x105480,_0x1b75e3){const _0x37302e=_0x55e41a;if(this[_0x37302e(0x148)][_0x37302e(0x106)]===undefined||_0x105480[_0x37302e(0x155)]!==undefined)return;const _0x9f5094=this[_0x37302e(0x148)][_0x37302e(0x106)](_0x1b75e3,INITIAL_TURN_LIMIT);_0x105480[_0x37302e(0x155)]=_0x9f5094;try{const _0x83af96=await _0x9f5094;if(this[_0x37302e(0x157)][_0x37302e(0x15c)](_0x1b75e3['id'])!==_0x105480||_0x105480[_0x37302e(0x124)]!==_0x37302e(0x187))return;_0x105480[_0x37302e(0x11e)]=_0x83af96,_0x105480[_0x37302e(0x138)]=_0x83af96[_0x37302e(0x162)];const _0x22b073=_0x105480[_0x37302e(0xfa)];for(const _0x72192c of this[_0x37302e(0x119)][_0x37302e(0x156)]())if(_0x72192c[_0x37302e(0x17d)]===_0x1b75e3['id'])_0x72192c[_0x37302e(0x166)]=![];await this[_0x37302e(0xfd)](_0x105480,_0x22b073);}catch(_0x4a1432){this[_0x37302e(0x148)][_0x37302e(0x183)]?.(_0x37302e(0x16b),{'nodeId':this[_0x37302e(0x148)][_0x37302e(0x131)]?.()??_0x37302e(0xfb),'sessionId':_0x1b75e3['id'],'runner':_0x1b75e3[_0x37302e(0x169)],'errorCode':diagnosticErrorCode(_0x4a1432,_0x37302e(0x10f))});}finally{if(this[_0x37302e(0x157)][_0x37302e(0x15c)](_0x1b75e3['id'])===_0x105480&&_0x105480[_0x37302e(0x155)]===_0x9f5094)_0x105480[_0x37302e(0x155)]=undefined;}}async[_0x55e41a(0x125)](_0x52eab9,_0x402a07){const _0x256c45=_0x55e41a;if(_0x52eab9[_0x256c45(0x155)]!==undefined)try{await _0x52eab9[_0x256c45(0x155)];}catch{}const _0xd11df1=_0x52eab9[_0x256c45(0x189)];if(_0xd11df1===undefined||this[_0x256c45(0x157)][_0x256c45(0x15c)](_0xd11df1['id'])!==_0x52eab9||_0x52eab9[_0x256c45(0x124)]!==_0x256c45(0x15e)||_0x52eab9[_0x256c45(0xfa)]!==_0x402a07)return;await this[_0x256c45(0x112)](_0xd11df1['id'],INITIAL_TURN_LIMIT,!![]);}[_0x55e41a(0xfe)](_0x288262,_0x252c6d){const _0x540b9b=_0x55e41a;this[_0x540b9b(0x148)][_0x540b9b(0x135)]?.({'type':_0x540b9b(0x154),'workbenchConnectionId':_0x288262[_0x540b9b(0x12b)],'watchId':_0x288262[_0x540b9b(0x177)],'nodeGeneration':_0x288262[_0x540b9b(0x127)],'nodeId':this[_0x540b9b(0x148)][_0x540b9b(0x131)]?.()??_0x540b9b(0xfb),'workspaceId':_0x288262[_0x540b9b(0x121)]??_0x540b9b(0x128),'sessionId':_0x288262[_0x540b9b(0x17d)],'expiresAt':_0x288262[_0x540b9b(0x176)],'event':_0x252c6d});}[_0x55e41a(0x144)](_0x4d9950,_0x18e71e){const _0x3e1746=_0x55e41a,_0x55bd17=[...this[_0x3e1746(0x119)][_0x3e1746(0x156)]()][_0x3e1746(0x13c)](_0x16c8a9=>_0x16c8a9[_0x3e1746(0x17d)]===_0x4d9950['id']);if(_0x55bd17[_0x3e1746(0x12c)]===0x3b*0x89+0x1fdb+-0x3f6e){this[_0x3e1746(0x148)][_0x3e1746(0x110)](_0x4d9950,_0x18e71e);return;}for(const _0x113ac3 of _0x55bd17){if(!_0x113ac3[_0x3e1746(0x166)])continue;const _0x59ac71=_0x113ac3[_0x3e1746(0x11f)]===_0x3e1746(0x161)?this[_0x3e1746(0x148)][_0x3e1746(0x179)]?.(_0x4d9950,_0x18e71e,_0x3e1746(0x161),-0xacb*0x1+0x2*0x5dd+0x1*-0xe5):_0x18e71e;if(_0x59ac71===undefined)continue;this[_0x3e1746(0x148)][_0x3e1746(0x135)]?.({'type':_0x3e1746(0x134),'workbenchConnectionId':_0x113ac3[_0x3e1746(0x12b)],'watchId':_0x113ac3[_0x3e1746(0x177)],'nodeGeneration':_0x113ac3[_0x3e1746(0x127)],'nodeId':this[_0x3e1746(0x148)][_0x3e1746(0x131)]?.()??_0x3e1746(0xfb),'workspaceId':_0x4d9950[_0x3e1746(0x121)],'sessionId':_0x4d9950['id'],'revision':0x1,'snapshotSequence':++this[_0x3e1746(0x14c)],'expiresAt':_0x113ac3[_0x3e1746(0x176)],'payload':_0x59ac71});}}[_0x55e41a(0x16c)](_0x342ff7,_0x482410,_0x21a6c8){const _0x298607=_0x55e41a;for(const _0x56fcfe of[...this[_0x298607(0x119)][_0x298607(0x156)]()]){if(_0x56fcfe[_0x298607(0x17d)]!==_0x342ff7['id'])continue;if(!_0x56fcfe[_0x298607(0x163)])continue;const _0xbb489d=_0x56fcfe[_0x298607(0x11f)]===_0x298607(0x161)?this[_0x298607(0x148)][_0x298607(0x179)]?.(_0x342ff7,_0x482410,_0x298607(0x161),0xbb9*-0x1+0x29*-0x9+0xd34):_0x482410;if(_0xbb489d===undefined)continue;this[_0x298607(0x118)](_0x56fcfe,_0x342ff7,_0xbb489d);if(!_0x21a6c8)continue;this[_0x298607(0x178)](_0x56fcfe,_0x482410);}}[_0x55e41a(0x118)](_0x41e3f3,_0x3d2d13,_0x112736){const _0x1488af=_0x55e41a;_0x41e3f3[_0x1488af(0x163)]=!![],this[_0x1488af(0x148)][_0x1488af(0x135)]?.({'type':_0x1488af(0x134),'workbenchConnectionId':_0x41e3f3[_0x1488af(0x12b)],'watchId':_0x41e3f3[_0x1488af(0x177)],'nodeGeneration':_0x41e3f3[_0x1488af(0x127)],'nodeId':this[_0x1488af(0x148)][_0x1488af(0x131)]?.()??_0x1488af(0xfb),'workspaceId':_0x3d2d13[_0x1488af(0x121)],'sessionId':_0x3d2d13['id'],'revision':0x1,'snapshotSequence':++this[_0x1488af(0x14c)],'expiresAt':_0x41e3f3[_0x1488af(0x176)],'payload':_0x112736});}[_0x55e41a(0x133)](_0x4c0dbe){const _0x488944=_0x55e41a;for(const _0x141750 of this[_0x488944(0x119)][_0x488944(0x156)]()){if(_0x141750[_0x488944(0x17d)]!==_0x4c0dbe)continue;if(!_0x141750[_0x488944(0x163)])continue;_0x141750[_0x488944(0x166)]=!![];for(const _0x5e1590 of _0x141750[_0x488944(0x14f)])this[_0x488944(0xfe)](_0x141750,_0x5e1590);_0x141750[_0x488944(0x14f)][_0x488944(0x12c)]=0x85c+0x13d6+0x3*-0x966;}}[_0x55e41a(0x178)](_0x471f5e,_0x310cf0){const _0x2939cf=_0x55e41a,_0x4fcd6e=isPlainRecord(_0x310cf0)?_0x310cf0:undefined,_0x2f6c36=_0x4fcd6e?.[_0x2939cf(0x14c)],_0x7d386=typeof _0x2f6c36===_0x2939cf(0x123)&&Number[_0x2939cf(0x17b)](_0x2f6c36)&&_0x2f6c36>=-0x70+0x3dd*0x3+-0xb27?_0x2f6c36:undefined;_0x471f5e[_0x2939cf(0x166)]=!![];for(const _0xc1eed2 of _0x471f5e[_0x2939cf(0x14f)])if(_0x7d386===undefined||_0xc1eed2[_0x2939cf(0x151)]>_0x7d386)this[_0x2939cf(0xfe)](_0x471f5e,_0xc1eed2);_0x471f5e[_0x2939cf(0x14f)][_0x2939cf(0x12c)]=-0x17d9+0x15e8+0x1*0x1f1;}[_0x55e41a(0x14e)](_0x1f7712){const _0x710ab8=_0x55e41a;for(const _0x3ab9af of[...this[_0x710ab8(0x119)][_0x710ab8(0x156)]()]){if(_0x3ab9af[_0x710ab8(0x17d)]!==_0x1f7712)continue;this[_0x710ab8(0x148)][_0x710ab8(0x135)]?.({'type':_0x710ab8(0x107),'workbenchConnectionId':_0x3ab9af[_0x710ab8(0x12b)],'watchType':_0x710ab8(0x189),'watchId':_0x3ab9af[_0x710ab8(0x177)],'nodeGeneration':_0x3ab9af[_0x710ab8(0x127)],'nodeId':this[_0x710ab8(0x148)][_0x710ab8(0x131)]?.()??_0x710ab8(0xfb),'workspaceId':_0x3ab9af[_0x710ab8(0x121)]??_0x710ab8(0x128),'sessionId':_0x1f7712,'code':_0x710ab8(0x174),'message':_0x710ab8(0x142)}),this[_0x710ab8(0x18c)](_0x3ab9af[_0x710ab8(0x11d)]);}this[_0x710ab8(0x175)](_0x1f7712);}[_0x55e41a(0x158)](_0x110328){const _0x425ca6=_0x55e41a;for(const _0x231420 of[...this[_0x425ca6(0x119)][_0x425ca6(0x156)]()])if(_0x231420[_0x425ca6(0x17d)]===_0x110328)this[_0x425ca6(0x18c)](_0x231420[_0x425ca6(0x11d)]);this[_0x425ca6(0x175)](_0x110328);}[_0x55e41a(0xf8)](_0x532bed){const _0x3eaac3=_0x55e41a,_0x804164=setTimeout(()=>this[_0x3eaac3(0x18c)](_0x532bed),TTL_MS);return _0x804164[_0x3eaac3(0xef)](),_0x804164;}[_0x55e41a(0x10d)](_0x4b2dfe){const _0x2359dc=_0x55e41a;let _0xb44f10=-0xf1f*0x2+0x1*0x1946+0x4f8;for(const _0x446984 of this[_0x2359dc(0x119)][_0x2359dc(0x156)]())if(_0x446984[_0x2359dc(0x17d)]===_0x4b2dfe)_0xb44f10=Math[_0x2359dc(0x149)](_0xb44f10,_0x446984[_0x2359dc(0x176)]);return _0xb44f10;}[_0x55e41a(0x16e)](_0x4f452e){const _0x2e43af=_0x55e41a,_0x426df7=setTimeout(()=>void this[_0x2e43af(0x112)](_0x4f452e),INTERVAL_MS);return _0x426df7[_0x2e43af(0xef)](),_0x426df7;}}function diagnosticErrorCode(_0x619c4,_0x28f726){const _0x55bd5b=_0x55e41a,_0x3b142b=safeErrorCode(_0x619c4,'');if(_0x3b142b[_0x55bd5b(0x12c)]>0x2253+0xf2*0x14+-0x353b)return _0x3b142b;if(_0x619c4!==null&&typeof _0x619c4===_0x55bd5b(0x100)&&_0x55bd5b(0xee)in _0x619c4&&typeof _0x619c4[_0x55bd5b(0xee)]===_0x55bd5b(0x13d)&&/^[A-Z][A-Z0-9_]{0,127}$/[_0x55bd5b(0x132)](_0x619c4[_0x55bd5b(0xee)]))return _0x619c4[_0x55bd5b(0xee)];return _0x28f726;}function sessionActivity(_0x4426a4){const _0x3c7862=_0x55e41a;if(!isPlainRecord(_0x4426a4[_0x3c7862(0x15a)]))return undefined;if(_0x4426a4[_0x3c7862(0x165)]===_0x3c7862(0x13e)&&isPlainRecord(_0x4426a4[_0x3c7862(0x15a)][_0x3c7862(0x13e)])){const _0x1d766b=_0x4426a4[_0x3c7862(0x15a)][_0x3c7862(0x13e)][_0x3c7862(0xed)];if(_0x1d766b===_0x3c7862(0x18b)||_0x1d766b===_0x3c7862(0x187)||_0x1d766b===_0x3c7862(0x12f))return _0x3c7862(0x187);return undefined;}if(_0x4426a4[_0x3c7862(0x165)]!==_0x3c7862(0x189))return undefined;const _0x41e62f=_0x4426a4[_0x3c7862(0x15a)][_0x3c7862(0x189)];if(!isPlainRecord(_0x41e62f)||typeof _0x41e62f[_0x3c7862(0xf6)]!==_0x3c7862(0x13d))return undefined;return _0x41e62f[_0x3c7862(0xf6)]===_0x3c7862(0x17c)?_0x3c7862(0x187):_0x3c7862(0x13b);}
1
+ import { isPlainRecord } from '../runner/codex/conversation-parser.js';
2
+ import { safeErrorCode } from '../util/safe-error.js';
3
+ import { SessionWatchSlotCoordinator } from './session-watch-slot-coordinator.js';
4
+ const INTERVAL_MS = 2_000;
5
+ const TTL_MS = 45_000;
6
+ const MAX_FAILURES = 3;
7
+ const INITIAL_TURN_LIMIT = 30;
8
+ const EMITTED_TURN_LIMIT = 10;
9
+ export class NativeSessionWatchService {
10
+ options;
11
+ watches = new Map();
12
+ leases = new Map();
13
+ sessionWatchSlots;
14
+ snapshotSequence = 0;
15
+ constructor(options) {
16
+ this.options = options;
17
+ this.sessionWatchSlots = options.sessionWatchSlots ?? new SessionWatchSlotCoordinator();
18
+ }
19
+ operations() {
20
+ return {
21
+ 'session.watch': (data) => this.executeWatch(isPlainRecord(data) ? data : {}),
22
+ 'session.unwatch': (data) => this.executeUnwatch(isPlainRecord(data) ? data : {})
23
+ };
24
+ }
25
+ async executeWatch(input) {
26
+ const projectInitialPage = this.options.projectInitialPage;
27
+ if (input.unit === 'SEGMENT' && projectInitialPage === undefined)
28
+ throw new Error('SESSION_INVALID');
29
+ if (typeof input.sessionId !== 'string' ||
30
+ (input.workspaceId !== undefined && typeof input.workspaceId !== 'string') ||
31
+ typeof input.watchId !== 'string' ||
32
+ typeof input.workbenchConnectionId !== 'string' ||
33
+ (input.mode !== 'initial' && input.mode !== 'renew') ||
34
+ (input.unit !== undefined && input.unit !== 'SEGMENT'))
35
+ throw new Error('SESSION_INVALID');
36
+ const ownerKey = this.ownerKey(input);
37
+ if (input.mode === 'renew') {
38
+ const lease = this.leases.get(ownerKey);
39
+ if (lease === undefined ||
40
+ !this.sessionWatchSlots.owns(ownerKey, lease.slotToken) ||
41
+ lease.watchId !== input.watchId ||
42
+ lease.sessionId !== input.sessionId ||
43
+ (input.workspaceId !== undefined && lease.workspaceId !== input.workspaceId))
44
+ throw new Error('SESSION_WATCH_NOT_FOUND');
45
+ if (lease.expiresAt <= Date.now()) {
46
+ this.removeLease(ownerKey);
47
+ throw new Error('SESSION_WATCH_NOT_FOUND');
48
+ }
49
+ lease.expiresAt = Date.now() + TTL_MS;
50
+ const observer = this.watches.get(lease.sessionId);
51
+ if (observer !== undefined)
52
+ observer.expiresAt = this.latestLeaseExpiry(lease.sessionId);
53
+ clearTimeout(lease.timer);
54
+ lease.timer = this.leaseTimer(ownerKey);
55
+ return this.accepted(lease);
56
+ }
57
+ const existing = this.leases.get(ownerKey);
58
+ const unit = input.unit === 'SEGMENT' ? 'SEGMENT' : 'TURN';
59
+ if (existing?.watchId === input.watchId &&
60
+ this.sessionWatchSlots.owns(ownerKey, existing.slotToken) &&
61
+ existing.sessionId === input.sessionId &&
62
+ (input.workspaceId === undefined || existing.workspaceId === input.workspaceId) &&
63
+ existing.unit === unit &&
64
+ existing.expiresAt > Date.now()) {
65
+ existing.expiresAt = Date.now() + TTL_MS;
66
+ clearTimeout(existing.timer);
67
+ existing.timer = this.leaseTimer(ownerKey);
68
+ return this.accepted(existing);
69
+ }
70
+ this.removeLease(ownerKey);
71
+ const slotToken = this.sessionWatchSlots.replace(ownerKey, 'session', () => this.removeLease(ownerKey));
72
+ const lease = {
73
+ ownerKey,
74
+ sessionHash: this.sessionHash(input),
75
+ workbenchConnectionId: input.workbenchConnectionId,
76
+ watchId: input.watchId,
77
+ sessionId: input.sessionId,
78
+ unit,
79
+ nodeGeneration: this.options.nodeGeneration?.() ?? 'local-test-generation',
80
+ ...(typeof input.workspaceId === 'string' ? { workspaceId: input.workspaceId } : {}),
81
+ expiresAt: Date.now() + TTL_MS,
82
+ ready: false,
83
+ snapshotSent: false,
84
+ pendingEvents: [],
85
+ slotToken,
86
+ timer: undefined
87
+ };
88
+ lease.timer = this.leaseTimer(ownerKey);
89
+ this.leases.set(ownerKey, lease);
90
+ const observer = this.watches.get(lease.sessionId);
91
+ if (observer !== undefined)
92
+ observer.expiresAt = this.latestLeaseExpiry(lease.sessionId);
93
+ void this.initializeLease(lease, projectInitialPage);
94
+ return this.accepted(lease);
95
+ }
96
+ executeUnwatch(input) {
97
+ if (typeof input.sessionId !== 'string' ||
98
+ typeof input.watchId !== 'string' ||
99
+ typeof input.workbenchConnectionId !== 'string')
100
+ throw new Error('SESSION_INVALID');
101
+ const ownerKey = this.ownerKey(input);
102
+ const lease = this.leases.get(ownerKey);
103
+ if (lease?.watchId === input.watchId && lease.sessionId === input.sessionId)
104
+ this.removeLease(ownerKey);
105
+ return { stopped: true };
106
+ }
107
+ watch(session) {
108
+ const existing = this.watches.get(session.id);
109
+ if (existing !== undefined) {
110
+ existing.expiresAt = Date.now() + TTL_MS;
111
+ return { expiresAt: existing.expiresAt };
112
+ }
113
+ const watch = {
114
+ session,
115
+ mode: this.options.managedActive(session) ? 'RUNNING' : 'HISTORY',
116
+ expiresAt: Date.now() + TTL_MS,
117
+ refresh: undefined,
118
+ sessionSignature: undefined,
119
+ signature: undefined,
120
+ page: undefined,
121
+ runtimePage: undefined,
122
+ runtimeRevision: undefined,
123
+ runtimeRead: undefined,
124
+ historyRead: undefined,
125
+ observedPage: undefined,
126
+ authority: undefined,
127
+ eventRevision: 0,
128
+ failures: 0,
129
+ transitionGeneration: 0,
130
+ timer: undefined
131
+ };
132
+ watch.timer = this.refreshTimer(session.id);
133
+ this.watches.set(session.id, watch);
134
+ return { expiresAt: watch.expiresAt };
135
+ }
136
+ emitRealtime(sessionId, event) {
137
+ const watch = this.watches.get(sessionId);
138
+ if (watch !== undefined)
139
+ watch.eventRevision = event.sequence;
140
+ const leases = [...this.leases.values()].filter((lease) => lease.sessionId === sessionId);
141
+ const activity = sessionActivity(event);
142
+ if (watch !== undefined && activity === 'RUNNING' && watch.mode !== 'RUNNING') {
143
+ watch.mode = 'RUNNING';
144
+ watch.transitionGeneration += 1;
145
+ for (const lease of leases)
146
+ lease.ready = false;
147
+ void this.publishRuntimeSnapshot(watch, watch.transitionGeneration);
148
+ }
149
+ else if (watch !== undefined && activity === 'IDLE' && watch.mode === 'RUNNING') {
150
+ watch.mode = 'CONVERGING';
151
+ const generation = ++watch.transitionGeneration;
152
+ for (const lease of leases)
153
+ lease.ready = false;
154
+ setTimeout(() => void this.convergeHistory(watch, generation), 0);
155
+ }
156
+ for (const lease of leases) {
157
+ if (!lease.ready)
158
+ lease.pendingEvents.push(event);
159
+ else
160
+ this.emitLeaseEvent(lease, event);
161
+ }
162
+ return leases.length > 0;
163
+ }
164
+ renew(session) {
165
+ const watch = this.watches.get(session.id);
166
+ if (watch === undefined || watch.expiresAt <= Date.now()) {
167
+ this.stop(session.id);
168
+ return undefined;
169
+ }
170
+ watch.expiresAt = Date.now() + TTL_MS;
171
+ return { expiresAt: watch.expiresAt };
172
+ }
173
+ stop(sessionId) {
174
+ const watch = this.watches.get(sessionId);
175
+ if (watch === undefined)
176
+ return;
177
+ clearTimeout(watch.timer);
178
+ this.watches.delete(sessionId);
179
+ }
180
+ invalidate(sessionId) {
181
+ for (const [ownerKey, lease] of this.leases)
182
+ if (lease.sessionId === sessionId)
183
+ this.removeLease(ownerKey);
184
+ this.stop(sessionId);
185
+ }
186
+ clear() {
187
+ for (const watch of this.watches.values())
188
+ clearTimeout(watch.timer);
189
+ this.watches.clear();
190
+ for (const ownerKey of [...this.leases.keys()])
191
+ this.removeLease(ownerKey);
192
+ }
193
+ has(sessionId) {
194
+ return this.watches.has(sessionId);
195
+ }
196
+ isWatching(sessionId) {
197
+ return this.has(sessionId);
198
+ }
199
+ entry(sessionId) {
200
+ return this.watches.get(sessionId);
201
+ }
202
+ get size() {
203
+ return this.watches.size;
204
+ }
205
+ async refresh(sessionId, limit = 10, emit = true) {
206
+ const watch = this.watches.get(sessionId);
207
+ if (watch === undefined)
208
+ return undefined;
209
+ if (watch.refresh !== undefined)
210
+ return watch.refresh;
211
+ if (watch.expiresAt <= Date.now()) {
212
+ this.stop(sessionId);
213
+ return undefined;
214
+ }
215
+ const refresh = this.performRefresh(sessionId, watch, limit, emit);
216
+ watch.refresh = refresh;
217
+ try {
218
+ return await refresh;
219
+ }
220
+ finally {
221
+ if (this.watches.get(sessionId) === watch) {
222
+ watch.refresh = undefined;
223
+ clearTimeout(watch.timer);
224
+ watch.timer = this.refreshTimer(sessionId);
225
+ }
226
+ }
227
+ }
228
+ async performRefresh(sessionId, watch, limit, emit) {
229
+ let stage = 'resolve';
230
+ let session;
231
+ const readHistoricalPage = watch.mode === 'HISTORY' && this.options.readHistoryPage !== undefined;
232
+ try {
233
+ if (this.options.suspended?.(sessionId) === true)
234
+ return watch.page;
235
+ session = await this.options.resolve(sessionId);
236
+ if (session === undefined || session.externalSessionId === null) {
237
+ this.releaseSessionLeases(sessionId);
238
+ return undefined;
239
+ }
240
+ watch.session = session;
241
+ if (emit && this.options.managedActive(session))
242
+ return watch.page;
243
+ stage = 'refresh_activity';
244
+ await this.options.refreshActivity(session);
245
+ if (this.options.suspended?.(sessionId) === true)
246
+ return watch.page;
247
+ stage = 'read_page';
248
+ const revisionBeforeRead = watch.eventRevision;
249
+ const page = await (readHistoricalPage
250
+ ? this.options.readHistoryPage(session, limit)
251
+ : this.options.readPage(session, limit));
252
+ if (emit && revisionBeforeRead !== watch.eventRevision)
253
+ return watch.page;
254
+ stage = 'present_session';
255
+ const presented = this.options.present(session);
256
+ const sessionSignature = JSON.stringify(presented);
257
+ if (sessionSignature !== watch.sessionSignature) {
258
+ watch.sessionSignature = sessionSignature;
259
+ if (emit)
260
+ this.options.emitSession(presented);
261
+ }
262
+ watch.failures = 0;
263
+ const turns = page.turns.length <= EMITTED_TURN_LIMIT
264
+ ? page.turns
265
+ : page.turns.slice(-EMITTED_TURN_LIMIT);
266
+ const observed = { ...page, turns };
267
+ stage = 'converge_page';
268
+ const convergence = this.options.convergePage(watch.page, watch.observedPage, observed, watch.authority);
269
+ const converged = convergence.page;
270
+ const accepted = converged.turns.length <= EMITTED_TURN_LIMIT + 1
271
+ ? converged
272
+ : {
273
+ ...converged,
274
+ turns: converged.turns.slice(-(EMITTED_TURN_LIMIT + 1))
275
+ };
276
+ watch.observedPage = observed;
277
+ watch.authority = convergence.authority;
278
+ const completingConvergence = watch.mode === 'CONVERGING' && !this.options.managedActive(session);
279
+ if (completingConvergence) {
280
+ watch.mode = 'HISTORY';
281
+ watch.runtimePage = undefined;
282
+ watch.runtimeRevision = undefined;
283
+ }
284
+ const signature = JSON.stringify({ source: accepted.source, turns: accepted.turns });
285
+ const changed = signature !== watch.signature;
286
+ if (changed) {
287
+ watch.signature = signature;
288
+ watch.page = accepted;
289
+ }
290
+ stage = 'emit_page';
291
+ if (emit && completingConvergence)
292
+ this.emitSnapshotToLeases(session, accepted, true);
293
+ else if (emit && changed)
294
+ this.emitObservedPage(session, accepted);
295
+ return emit ? accepted : page;
296
+ }
297
+ catch (error) {
298
+ watch.failures += 1;
299
+ this.options.log?.('session.watch.refresh.failed', {
300
+ nodeId: this.options.nodeId?.() ?? 'local-test-node',
301
+ sessionId,
302
+ ...(session === undefined ? {} : { runner: session.runner }),
303
+ stage,
304
+ errorCode: diagnosticErrorCode(error, 'SESSION_WATCH_REFRESH_FAILED'),
305
+ failureCount: watch.failures,
306
+ terminal: watch.failures >= MAX_FAILURES
307
+ });
308
+ if (watch.failures >= MAX_FAILURES)
309
+ this.failSession(sessionId);
310
+ return undefined;
311
+ }
312
+ }
313
+ sessionHash(input) {
314
+ return typeof input.__workspaceWatchSessionHash === 'string'
315
+ ? input.__workspaceWatchSessionHash
316
+ : 'local-test';
317
+ }
318
+ ownerKey(input) {
319
+ return `${this.sessionHash(input)}:${input.workbenchConnectionId}`;
320
+ }
321
+ accepted(lease) {
322
+ return {
323
+ accepted: true,
324
+ watchId: lease.watchId,
325
+ nodeGeneration: lease.nodeGeneration,
326
+ expiresAt: lease.expiresAt
327
+ };
328
+ }
329
+ async initializeLease(lease, projectInitialPage) {
330
+ let stage = 'resolve';
331
+ try {
332
+ const session = await this.options.resolve(lease.sessionId);
333
+ if (session === undefined || session.externalSessionId === null)
334
+ throw new Error('SESSION_NOT_FOUND');
335
+ if (lease.workspaceId !== undefined && session.workspaceId !== lease.workspaceId)
336
+ throw new Error('SESSION_WORKSPACE_MISMATCH');
337
+ if (this.leases.get(lease.ownerKey) !== lease)
338
+ return;
339
+ lease.workspaceId = session.workspaceId;
340
+ stage = 'initial_refresh';
341
+ this.watch(session);
342
+ const watch = this.watches.get(session.id);
343
+ if (watch !== undefined)
344
+ watch.session = session;
345
+ const activeAtStart = this.options.managedActive(session);
346
+ if (watch !== undefined)
347
+ watch.mode = activeAtStart ? 'RUNNING' : watch.mode;
348
+ const cached = !activeAtStart && watch?.page !== undefined ? watch.page : undefined;
349
+ let page = activeAtStart
350
+ ? watch === undefined
351
+ ? undefined
352
+ : this.composeRuntimePage(watch.page, await this.readRuntimePage(watch, session))
353
+ : (cached ??
354
+ (watch === undefined
355
+ ? undefined
356
+ : await this.refresh(session.id, INITIAL_TURN_LIMIT, false)));
357
+ if (page === undefined)
358
+ throw new Error('NATIVE_TRANSCRIPT_UNAVAILABLE');
359
+ if (lease.snapshotSent)
360
+ return;
361
+ const active = this.options.managedActive(session);
362
+ if (active && !activeAtStart && watch !== undefined) {
363
+ watch.mode = 'RUNNING';
364
+ page = this.composeRuntimePage(page, await this.readRuntimePage(watch, session));
365
+ }
366
+ stage = 'project_snapshot';
367
+ const payload = lease.unit === 'SEGMENT' ? projectInitialPage(session, page, 'SEGMENT', 10) : page;
368
+ if (this.leases.get(lease.ownerKey) !== lease)
369
+ return;
370
+ this.emitSnapshot(lease, session, payload);
371
+ this.releaseSnapshotPendingEvents(lease, page);
372
+ if (active && watch !== undefined && watch.page === undefined)
373
+ void this.hydrateRunningHistory(watch, session);
374
+ }
375
+ catch (error) {
376
+ if (this.leases.get(lease.ownerKey) !== lease)
377
+ return;
378
+ const errorCode = diagnosticErrorCode(error, 'SESSION_WATCH_SNAPSHOT_FAILED');
379
+ this.options.log?.('session.watch.initial.failed', {
380
+ nodeId: this.options.nodeId?.() ?? 'local-test-node',
381
+ sessionId: lease.sessionId,
382
+ workspaceId: lease.workspaceId ?? 'unknown',
383
+ workbenchConnectionId: lease.workbenchConnectionId,
384
+ watchId: lease.watchId,
385
+ stage,
386
+ errorCode
387
+ });
388
+ this.options.emitWatchEvent?.({
389
+ type: 'watch.failed',
390
+ workbenchConnectionId: lease.workbenchConnectionId,
391
+ watchType: 'session',
392
+ watchId: lease.watchId,
393
+ nodeGeneration: lease.nodeGeneration,
394
+ nodeId: this.options.nodeId?.() ?? 'local-test-node',
395
+ workspaceId: lease.workspaceId ?? 'unknown',
396
+ sessionId: lease.sessionId,
397
+ code: errorCode,
398
+ message: 'Session watch snapshot failed.'
399
+ });
400
+ this.removeLease(lease.ownerKey);
401
+ }
402
+ }
403
+ removeLease(ownerKey) {
404
+ const lease = this.leases.get(ownerKey);
405
+ if (lease === undefined)
406
+ return;
407
+ clearTimeout(lease.timer);
408
+ this.leases.delete(ownerKey);
409
+ this.sessionWatchSlots.release(ownerKey, lease.slotToken);
410
+ const observer = this.watches.get(lease.sessionId);
411
+ const nextExpiry = this.latestLeaseExpiry(lease.sessionId);
412
+ if (nextExpiry === 0)
413
+ this.stop(lease.sessionId);
414
+ else if (observer !== undefined)
415
+ observer.expiresAt = nextExpiry;
416
+ }
417
+ composeRuntimePage(history, runtime) {
418
+ return this.options.composeRuntimePage?.(history, runtime) ?? runtime;
419
+ }
420
+ async readRuntimePage(watch, session) {
421
+ if (watch.runtimePage !== undefined && watch.runtimeRevision === watch.eventRevision)
422
+ return watch.runtimePage;
423
+ if (watch.runtimeRead !== undefined)
424
+ return watch.runtimeRead;
425
+ const revision = watch.eventRevision;
426
+ const read = this.options.readPage(session, INITIAL_TURN_LIMIT);
427
+ watch.runtimeRead = read;
428
+ try {
429
+ const page = await read;
430
+ if (this.watches.get(session.id) === watch) {
431
+ watch.runtimePage = page;
432
+ watch.runtimeRevision = revision;
433
+ }
434
+ return page;
435
+ }
436
+ finally {
437
+ if (this.watches.get(session.id) === watch && watch.runtimeRead === read)
438
+ watch.runtimeRead = undefined;
439
+ }
440
+ }
441
+ async publishRuntimeSnapshot(watch, generation) {
442
+ const session = watch.session;
443
+ if (session === undefined)
444
+ return;
445
+ try {
446
+ const runtime = await this.readRuntimePage(watch, session);
447
+ if (this.watches.get(session.id) !== watch ||
448
+ watch.mode !== 'RUNNING' ||
449
+ watch.transitionGeneration !== generation)
450
+ return;
451
+ watch.runtimePage = runtime;
452
+ this.emitSnapshotToLeases(session, this.composeRuntimePage(watch.page, runtime), true);
453
+ }
454
+ catch (error) {
455
+ this.options.log?.('session.watch.runtime-snapshot.failed', {
456
+ nodeId: this.options.nodeId?.() ?? 'local-test-node',
457
+ sessionId: session.id,
458
+ runner: session.runner,
459
+ errorCode: diagnosticErrorCode(error, 'SESSION_WATCH_RUNTIME_SNAPSHOT_FAILED')
460
+ });
461
+ this.releasePendingEvents(session.id);
462
+ }
463
+ }
464
+ async hydrateRunningHistory(watch, session) {
465
+ if (this.options.readHistoryPage === undefined || watch.historyRead !== undefined)
466
+ return;
467
+ const read = this.options.readHistoryPage(session, INITIAL_TURN_LIMIT);
468
+ watch.historyRead = read;
469
+ try {
470
+ const history = await read;
471
+ if (this.watches.get(session.id) !== watch || watch.mode !== 'RUNNING')
472
+ return;
473
+ watch.page = history;
474
+ watch.authority = history.source;
475
+ const generation = watch.transitionGeneration;
476
+ for (const lease of this.leases.values())
477
+ if (lease.sessionId === session.id)
478
+ lease.ready = false;
479
+ await this.publishRuntimeSnapshot(watch, generation);
480
+ }
481
+ catch (error) {
482
+ this.options.log?.('session.watch.running-history.failed', {
483
+ nodeId: this.options.nodeId?.() ?? 'local-test-node',
484
+ sessionId: session.id,
485
+ runner: session.runner,
486
+ errorCode: diagnosticErrorCode(error, 'SESSION_WATCH_HISTORY_FAILED')
487
+ });
488
+ }
489
+ finally {
490
+ if (this.watches.get(session.id) === watch && watch.historyRead === read)
491
+ watch.historyRead = undefined;
492
+ }
493
+ }
494
+ async convergeHistory(watch, generation) {
495
+ if (watch.historyRead !== undefined) {
496
+ try {
497
+ await watch.historyRead;
498
+ }
499
+ catch {
500
+ // The running snapshot remains usable; the authoritative convergence below retries.
501
+ }
502
+ }
503
+ const session = watch.session;
504
+ if (session === undefined ||
505
+ this.watches.get(session.id) !== watch ||
506
+ watch.mode !== 'CONVERGING' ||
507
+ watch.transitionGeneration !== generation)
508
+ return;
509
+ await this.refresh(session.id, INITIAL_TURN_LIMIT, true);
510
+ }
511
+ emitLeaseEvent(lease, event) {
512
+ this.options.emitWatchEvent?.({
513
+ type: 'watch.session.event',
514
+ workbenchConnectionId: lease.workbenchConnectionId,
515
+ watchId: lease.watchId,
516
+ nodeGeneration: lease.nodeGeneration,
517
+ nodeId: this.options.nodeId?.() ?? 'local-test-node',
518
+ workspaceId: lease.workspaceId ?? 'unknown',
519
+ sessionId: lease.sessionId,
520
+ expiresAt: lease.expiresAt,
521
+ event
522
+ });
523
+ }
524
+ emitObservedPage(session, page) {
525
+ const leases = [...this.leases.values()].filter((lease) => lease.sessionId === session.id);
526
+ if (leases.length === 0) {
527
+ this.options.emitPage(session, page);
528
+ return;
529
+ }
530
+ for (const lease of leases) {
531
+ if (!lease.ready)
532
+ continue;
533
+ const payload = lease.unit === 'SEGMENT'
534
+ ? this.options.projectInitialPage?.(session, page, 'SEGMENT', 10)
535
+ : page;
536
+ if (payload === undefined)
537
+ continue;
538
+ this.options.emitWatchEvent?.({
539
+ type: 'watch.session.snapshot',
540
+ workbenchConnectionId: lease.workbenchConnectionId,
541
+ watchId: lease.watchId,
542
+ nodeGeneration: lease.nodeGeneration,
543
+ nodeId: this.options.nodeId?.() ?? 'local-test-node',
544
+ workspaceId: session.workspaceId,
545
+ sessionId: session.id,
546
+ revision: 1,
547
+ snapshotSequence: ++this.snapshotSequence,
548
+ expiresAt: lease.expiresAt,
549
+ payload
550
+ });
551
+ }
552
+ }
553
+ emitSnapshotToLeases(session, page, releasePending) {
554
+ for (const lease of [...this.leases.values()]) {
555
+ if (lease.sessionId !== session.id)
556
+ continue;
557
+ if (!lease.snapshotSent)
558
+ continue;
559
+ const payload = lease.unit === 'SEGMENT'
560
+ ? this.options.projectInitialPage?.(session, page, 'SEGMENT', 10)
561
+ : page;
562
+ if (payload === undefined)
563
+ continue;
564
+ this.emitSnapshot(lease, session, payload);
565
+ if (!releasePending)
566
+ continue;
567
+ this.releaseSnapshotPendingEvents(lease, page);
568
+ }
569
+ }
570
+ emitSnapshot(lease, session, payload) {
571
+ lease.snapshotSent = true;
572
+ this.options.emitWatchEvent?.({
573
+ type: 'watch.session.snapshot',
574
+ workbenchConnectionId: lease.workbenchConnectionId,
575
+ watchId: lease.watchId,
576
+ nodeGeneration: lease.nodeGeneration,
577
+ nodeId: this.options.nodeId?.() ?? 'local-test-node',
578
+ workspaceId: session.workspaceId,
579
+ sessionId: session.id,
580
+ revision: 1,
581
+ snapshotSequence: ++this.snapshotSequence,
582
+ expiresAt: lease.expiresAt,
583
+ payload
584
+ });
585
+ }
586
+ releasePendingEvents(sessionId) {
587
+ for (const lease of this.leases.values()) {
588
+ if (lease.sessionId !== sessionId)
589
+ continue;
590
+ if (!lease.snapshotSent)
591
+ continue;
592
+ lease.ready = true;
593
+ for (const event of lease.pendingEvents)
594
+ this.emitLeaseEvent(lease, event);
595
+ lease.pendingEvents.length = 0;
596
+ }
597
+ }
598
+ releaseSnapshotPendingEvents(lease, page) {
599
+ const pageRecord = isPlainRecord(page) ? page : undefined;
600
+ const candidateSequence = pageRecord?.snapshotSequence;
601
+ const snapshotSequence = typeof candidateSequence === 'number' &&
602
+ Number.isSafeInteger(candidateSequence) &&
603
+ candidateSequence >= 0
604
+ ? candidateSequence
605
+ : undefined;
606
+ lease.ready = true;
607
+ for (const event of lease.pendingEvents)
608
+ if (snapshotSequence === undefined || event.sequence > snapshotSequence)
609
+ this.emitLeaseEvent(lease, event);
610
+ lease.pendingEvents.length = 0;
611
+ }
612
+ failSession(sessionId) {
613
+ for (const lease of [...this.leases.values()]) {
614
+ if (lease.sessionId !== sessionId)
615
+ continue;
616
+ this.options.emitWatchEvent?.({
617
+ type: 'watch.failed',
618
+ workbenchConnectionId: lease.workbenchConnectionId,
619
+ watchType: 'session',
620
+ watchId: lease.watchId,
621
+ nodeGeneration: lease.nodeGeneration,
622
+ nodeId: this.options.nodeId?.() ?? 'local-test-node',
623
+ workspaceId: lease.workspaceId ?? 'unknown',
624
+ sessionId,
625
+ code: 'NATIVE_TRANSCRIPT_UNAVAILABLE',
626
+ message: 'Session watch snapshot failed.'
627
+ });
628
+ this.removeLease(lease.ownerKey);
629
+ }
630
+ this.stop(sessionId);
631
+ }
632
+ releaseSessionLeases(sessionId) {
633
+ for (const lease of [...this.leases.values()])
634
+ if (lease.sessionId === sessionId)
635
+ this.removeLease(lease.ownerKey);
636
+ this.stop(sessionId);
637
+ }
638
+ leaseTimer(ownerKey) {
639
+ const timer = setTimeout(() => this.removeLease(ownerKey), TTL_MS);
640
+ timer.unref();
641
+ return timer;
642
+ }
643
+ latestLeaseExpiry(sessionId) {
644
+ let latest = 0;
645
+ for (const lease of this.leases.values())
646
+ if (lease.sessionId === sessionId)
647
+ latest = Math.max(latest, lease.expiresAt);
648
+ return latest;
649
+ }
650
+ refreshTimer(sessionId) {
651
+ const timer = setTimeout(() => void this.refresh(sessionId), INTERVAL_MS);
652
+ timer.unref();
653
+ return timer;
654
+ }
655
+ }
656
+ function diagnosticErrorCode(error, fallback) {
657
+ const direct = safeErrorCode(error, '');
658
+ if (direct.length > 0)
659
+ return direct;
660
+ if (error !== null &&
661
+ typeof error === 'object' &&
662
+ 'code' in error &&
663
+ typeof error.code === 'string' &&
664
+ /^[A-Z][A-Z0-9_]{0,127}$/.test(error.code))
665
+ return error.code;
666
+ return fallback;
667
+ }
668
+ function sessionActivity(event) {
669
+ if (!isPlainRecord(event.payload))
670
+ return undefined;
671
+ if (event.category === 'run' && isPlainRecord(event.payload.run)) {
672
+ const status = event.payload.run.status;
673
+ if (status === 'STARTING' || status === 'RUNNING' || status === 'CANCELLING')
674
+ return 'RUNNING';
675
+ return undefined;
676
+ }
677
+ if (event.category !== 'session')
678
+ return undefined;
679
+ const session = event.payload.session;
680
+ if (!isPlainRecord(session) || typeof session.activity !== 'string')
681
+ return undefined;
682
+ return session.activity === 'MANAGED_ACTIVE' ? 'RUNNING' : 'IDLE';
683
+ }