@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,1509 @@
1
- /* mar-release-protected */
2
- const _0xbdbd9d=_0x5093;(function(_0x53ffda,_0x149a0f){const _0x614f7a=_0x5093,_0x175c71=_0x53ffda();while(!![]){try{const _0x40a903=parseInt(_0x614f7a(0xdf))/(-0x117d+-0x1e2b*-0x1+-0xcad)*(parseInt(_0x614f7a(0x19d))/(0x1*0x227a+-0x1f49+-0x32f))+-parseInt(_0x614f7a(0xd3))/(0x1411+-0x1110+-0x2fe)*(-parseInt(_0x614f7a(0x10a))/(0x2650+-0x8d0+-0x1d7c))+-parseInt(_0x614f7a(0x1e9))/(-0x176b+0x20c0+-0x950)*(parseInt(_0x614f7a(0x1cc))/(0x11e9+-0x191a+0x737))+-parseInt(_0x614f7a(0x166))/(0x1*-0x25c1+-0x1837+0x3dff)+parseInt(_0x614f7a(0x11c))/(-0x18b9*-0x1+-0x1781+-0x10*0x13)*(-parseInt(_0x614f7a(0xe2))/(0x1c38+0xdb*-0x17+-0x882))+parseInt(_0x614f7a(0xce))/(0xaa5+0x1*0x14fe+0x1*-0x1f99)*(parseInt(_0x614f7a(0x1cd))/(0x5c1+-0x1*-0x137+-0x6ed))+parseInt(_0x614f7a(0x183))/(0x1*-0x2665+0x14e7+0x1c1*0xa);if(_0x40a903===_0x149a0f)break;else _0x175c71['push'](_0x175c71['shift']());}catch(_0x1255d0){_0x175c71['push'](_0x175c71['shift']());}}}(_0x5c2a,0x36895+0x199ad+-0x34954));import{randomUUID}from'node:crypto';export class NodeRuntimeState{[_0xbdbd9d(0x12f)];[_0xbdbd9d(0x14f)];[_0xbdbd9d(0x130)];[_0xbdbd9d(0x1dd)];static [_0xbdbd9d(0x1a4)]=0x5*-0x68c+-0xc65+0x2d2b;[_0xbdbd9d(0x1ec)]=new Map();[_0xbdbd9d(0x1ed)]=new Map();[_0xbdbd9d(0x1a0)]=new Map();[_0xbdbd9d(0x1d9)]=new Map();[_0xbdbd9d(0x119)]=new Map();[_0xbdbd9d(0x18c)]=new Map();[_0xbdbd9d(0xf6)]=new Map();[_0xbdbd9d(0xf3)]=new Map();[_0xbdbd9d(0xf1)]=new Map();[_0xbdbd9d(0xf2)]=new Map();[_0xbdbd9d(0x11d)]=new Map();[_0xbdbd9d(0x1bb)]=new Map();[_0xbdbd9d(0xe8)]=new Set();[_0xbdbd9d(0x1d7)]=new Map();[_0xbdbd9d(0x105)]=new Map();[_0xbdbd9d(0xed)]=new Set();[_0xbdbd9d(0x117)]=new Set();constructor(_0x53e378,_0xb77d05,_0xa48c1f=Date[_0xbdbd9d(0x130)],_0x18e548){const _0x26ab9c=_0xbdbd9d;this[_0x26ab9c(0x12f)]=_0x53e378,this[_0x26ab9c(0x14f)]=_0xb77d05,this[_0x26ab9c(0x130)]=_0xa48c1f,this[_0x26ab9c(0x1dd)]=_0x18e548;}[_0xbdbd9d(0x1af)](){const _0x33d12b=_0xbdbd9d;return this[_0x33d12b(0x1bb)][_0x33d12b(0x104)];}[_0xbdbd9d(0x1a7)](_0x4c198f){const _0xa44f9=_0xbdbd9d,_0x58680e=this[_0xa44f9(0x1bb)][_0xa44f9(0x156)](_0x4c198f);return _0x58680e===undefined?undefined:this[_0xa44f9(0x1ed)][_0xa44f9(0x156)](_0x58680e);}[_0xbdbd9d(0x1ee)](_0x5eb196){const _0x2e9c95=_0xbdbd9d;return this[_0x2e9c95(0x1bb)][_0x2e9c95(0x132)](_0x5eb196);}[_0xbdbd9d(0x177)](_0x352d8a){const _0x1b3bfb=_0xbdbd9d;if(this[_0x1b3bfb(0x14f)](_0x352d8a[_0x1b3bfb(0x155)])===undefined)throw new Error(_0x1b3bfb(0x133));const _0x4ae5f5=this[_0x1b3bfb(0x130)](),_0x43450c=_0x352d8a[_0x1b3bfb(0xcd)]??randomUUID();if(this[_0x1b3bfb(0x1ec)][_0x1b3bfb(0x132)](_0x43450c))throw new Error(_0x1b3bfb(0x167));const _0x460667=_0x352d8a[_0x1b3bfb(0x1be)]?.[_0x1b3bfb(0x182)]()[_0x1b3bfb(0x1b3)](0x240*-0x8+-0xc95*-0x2+-0x7*0x106,0x1*-0x220c+-0x26c+0x946*0x4)||null,_0x1da5ba={'id':_0x43450c,'nodeId':this[_0x1b3bfb(0x12f)](),'workspaceId':_0x352d8a[_0x1b3bfb(0x155)],'runner':_0x352d8a[_0x1b3bfb(0xd6)],'externalSessionId':_0x352d8a[_0x1b3bfb(0xcd)]??null,'nativeControl':_0x352d8a[_0x1b3bfb(0xcd)]===undefined?_0x1b3bfb(0x1b4):_0x352d8a[_0x1b3bfb(0x190)]??_0x1b3bfb(0x1ab),'channelToken':null,'cwd':_0x352d8a[_0x1b3bfb(0x12b)],'model':_0x352d8a[_0x1b3bfb(0x1ac)]??null,'effort':_0x352d8a[_0x1b3bfb(0x101)]??null,'access':_0x352d8a[_0x1b3bfb(0xd2)]??null,'customTitle':_0x460667,'runnerTitle':_0x352d8a[_0x1b3bfb(0x19e)]?.[_0x1b3bfb(0x182)]()[_0x1b3bfb(0x1b3)](0x1de3*0x1+-0x1a69+-0x37a,0x1e9*-0x1+-0x125e+-0x14e7*-0x1)||null,'pinnedAt':null,'titleSource':_0x460667===null?_0x1b3bfb(0x16b):_0x1b3bfb(0x10d),'lastActivityAt':_0x4ae5f5,'createdAt':_0x4ae5f5};return this[_0x1b3bfb(0x1ec)][_0x1b3bfb(0xd9)](_0x1da5ba['id'],_0x1da5ba),_0x1da5ba;}[_0xbdbd9d(0xfc)](_0x4e0dfb){const _0x3aca18=_0xbdbd9d;this[_0x3aca18(0x199)](_0x4e0dfb[_0x3aca18(0xe0)]);if(this[_0x3aca18(0x117)][_0x3aca18(0x132)](_0x4e0dfb[_0x3aca18(0x129)]))throw new Error(_0x3aca18(0x150));let _0x1b2839=this[_0x3aca18(0x1ec)][_0x3aca18(0x156)](_0x4e0dfb[_0x3aca18(0xe0)]);if(_0x1b2839===undefined){const _0x266b6e=this[_0x3aca18(0x130)]();_0x1b2839={'id':_0x4e0dfb[_0x3aca18(0xe0)],'nodeId':this[_0x3aca18(0x12f)](),'workspaceId':_0x4e0dfb[_0x3aca18(0x155)]??_0x3aca18(0x1a1)+_0x4e0dfb[_0x3aca18(0x12b)],'runner':_0x4e0dfb[_0x3aca18(0xd6)],'externalSessionId':_0x4e0dfb[_0x3aca18(0xcd)]??null,'nativeControl':_0x4e0dfb[_0x3aca18(0xcd)]===undefined?_0x3aca18(0x1b4):_0x3aca18(0x1ab),'channelToken':null,'cwd':_0x4e0dfb[_0x3aca18(0x12b)],'model':null,'effort':null,'access':null,'customTitle':null,'runnerTitle':null,'pinnedAt':null,'titleSource':_0x3aca18(0x16b),'lastActivityAt':_0x266b6e,'createdAt':_0x266b6e},this[_0x3aca18(0x1ec)][_0x3aca18(0xd9)](_0x1b2839['id'],_0x1b2839);}const _0x2f7f07=this[_0x3aca18(0x15b)](_0x4e0dfb[_0x3aca18(0x129)]);if(_0x2f7f07!==undefined)return _0x2f7f07;const _0x4bc856=this[_0x3aca18(0x130)](),_0x10b444={'id':_0x4e0dfb[_0x3aca18(0x129)],'sessionId':_0x1b2839['id'],'nodeId':this[_0x3aca18(0x12f)](),'workspaceId':_0x1b2839[_0x3aca18(0x155)],'runner':_0x1b2839[_0x3aca18(0xd6)],'status':_0x3aca18(0x10e),'recoveryState':_0x3aca18(0x17a),'version':0x0,'clientMessageId':_0x4e0dfb[_0x3aca18(0xfd)]??_0x4e0dfb[_0x3aca18(0x129)],..._0x4e0dfb[_0x3aca18(0x138)]===undefined?{}:{'initiatedByUserId':_0x4e0dfb[_0x3aca18(0x138)]},'createdAt':_0x4bc856,'startedAt':_0x4bc856,'completedAt':null,'updatedAt':_0x4bc856};return this[_0x3aca18(0x1ed)][_0x3aca18(0xd9)](_0x10b444['id'],_0x10b444),this[_0x3aca18(0x1bb)][_0x3aca18(0xd9)](_0x10b444[_0x3aca18(0xe0)],_0x10b444['id']),this[_0x3aca18(0x197)](_0x10b444,_0x1b2839),_0x10b444;}[_0xbdbd9d(0x126)](_0x3f6a2b){const _0x20eb0e=_0xbdbd9d;return this[_0x20eb0e(0x1ec)][_0x20eb0e(0x156)](_0x3f6a2b)??[...this[_0x20eb0e(0x1ec)][_0x20eb0e(0xea)]()][_0x20eb0e(0x1df)](_0x18b2ad=>_0x18b2ad[_0x20eb0e(0xcd)]===_0x3f6a2b);}[_0xbdbd9d(0x19c)](){const _0x4d935f=_0xbdbd9d;return[...this[_0x4d935f(0x1ec)][_0x4d935f(0xea)]()][_0x4d935f(0x102)]((_0x3efd3b,_0xefc4f9)=>_0xefc4f9[_0x4d935f(0x1b9)]-_0x3efd3b[_0x4d935f(0x1b9)]);}[_0xbdbd9d(0x1b6)](_0x132350,_0x1614c2){const _0x4c09f7=_0xbdbd9d;return[...this[_0x4c09f7(0x1ec)][_0x4c09f7(0xea)]()][_0x4c09f7(0x1df)](_0x38d49f=>_0x38d49f[_0x4c09f7(0xd6)]===_0x132350&&_0x38d49f[_0x4c09f7(0xcd)]===_0x1614c2);}[_0xbdbd9d(0x187)](_0x48bbdc){const _0x4ab9a0=_0xbdbd9d;return this[_0x4ab9a0(0x1ef)](_0x48bbdc[_0x4ab9a0(0xe0)],{'model':_0x48bbdc[_0x4ab9a0(0x1ac)],'effort':_0x48bbdc[_0x4ab9a0(0x101)],'access':_0x48bbdc[_0x4ab9a0(0xd2)]});}[_0xbdbd9d(0x1b2)](_0x8713b2,_0x5a0eb1){const _0x2a0b24=_0xbdbd9d;return this[_0x2a0b24(0x1ef)](_0x8713b2,{'access':_0x5a0eb1});}[_0xbdbd9d(0x1ce)](_0x2cc139,_0x2cae33){const _0x37bb02=_0xbdbd9d;this[_0x37bb02(0x1ef)](_0x2cc139,{'nativeControl':_0x2cae33});}[_0xbdbd9d(0xec)](_0x55706f,_0x211696){const _0x206d82=_0xbdbd9d;if(_0x211696[_0x206d82(0x171)]===-0x3a7+0x26f9+-0x19b*0x16)throw new Error(_0x206d82(0x18f));this[_0x206d82(0x154)](_0x55706f,_0x211696);}[_0xbdbd9d(0x154)](_0x1a3f9c,_0x33ca0b){const _0x448c2a=_0xbdbd9d;if(_0x33ca0b[_0x448c2a(0x171)]===-0x1af8+0x16ed+0x40b)throw new Error(_0x448c2a(0x18f));const _0x7f6252=this[_0x448c2a(0x169)](_0x1a3f9c);if(_0x1a3f9c===_0x33ca0b)return this[_0x448c2a(0x1ef)](_0x1a3f9c,{'externalSessionId':_0x33ca0b,'nativeControl':_0x448c2a(0x1b4)});const _0x1f17ae=this[_0x448c2a(0x1ec)][_0x448c2a(0x156)](_0x33ca0b);if(_0x1f17ae!==undefined&&_0x1f17ae['id']!==_0x7f6252['id'])throw new Error(_0x448c2a(0x167));const _0x3b906e={..._0x7f6252,'id':_0x33ca0b,'externalSessionId':_0x33ca0b,'nativeControl':_0x448c2a(0x1b4)},_0x3dc487=this[_0x448c2a(0x15f)](_0x1a3f9c),_0xf0fe2f=this[_0x448c2a(0xf2)][_0x448c2a(0x156)](_0x1a3f9c)??[],_0xf37ab5=this[_0x448c2a(0x1d7)][_0x448c2a(0x156)](_0x1a3f9c),_0x462124=this[_0x448c2a(0x105)][_0x448c2a(0x156)](_0x1a3f9c),_0x52014d=this[_0x448c2a(0x1bb)][_0x448c2a(0x156)](_0x1a3f9c),_0x4e76dd=this[_0x448c2a(0xed)][_0x448c2a(0x132)](_0x1a3f9c);this[_0x448c2a(0x1ec)][_0x448c2a(0x111)](_0x1a3f9c),this[_0x448c2a(0x1ec)][_0x448c2a(0xd9)](_0x33ca0b,_0x3b906e);for(const _0x241b0f of _0x3dc487)this[_0x448c2a(0x1ed)][_0x448c2a(0xd9)](_0x241b0f['id'],{..._0x241b0f,'sessionId':_0x33ca0b});this[_0x448c2a(0xf2)][_0x448c2a(0x111)](_0x1a3f9c),this[_0x448c2a(0xf2)][_0x448c2a(0xd9)](_0x33ca0b,_0xf0fe2f[_0x448c2a(0xe7)](_0x45fa08=>({..._0x45fa08,'sessionId':_0x33ca0b,'items':_0x45fa08[_0x448c2a(0x135)][_0x448c2a(0xe7)](_0x1a0209=>({..._0x1a0209,'sessionId':_0x33ca0b}))})));if(_0xf37ab5!==undefined){this[_0x448c2a(0x1d7)][_0x448c2a(0x111)](_0x1a3f9c),this[_0x448c2a(0x1d7)][_0x448c2a(0xd9)](_0x33ca0b,_0xf37ab5);for(const _0x5d205e of _0xf37ab5){const _0x23b96b=this[_0x448c2a(0x18c)][_0x448c2a(0x156)](_0x5d205e);if(_0x23b96b!==undefined)this[_0x448c2a(0x18c)][_0x448c2a(0xd9)](_0x5d205e,{..._0x23b96b,'sessionId':_0x33ca0b});}}_0x462124!==undefined&&(this[_0x448c2a(0x105)][_0x448c2a(0x111)](_0x1a3f9c),this[_0x448c2a(0x105)][_0x448c2a(0xd9)](_0x33ca0b,_0x462124));_0x52014d!==undefined&&(this[_0x448c2a(0x1bb)][_0x448c2a(0x111)](_0x1a3f9c),this[_0x448c2a(0x1bb)][_0x448c2a(0xd9)](_0x33ca0b,_0x52014d));_0x4e76dd&&(this[_0x448c2a(0xed)][_0x448c2a(0x111)](_0x1a3f9c),this[_0x448c2a(0xed)][_0x448c2a(0xd1)](_0x33ca0b));for(const [_0x5316f4,_0xe0427]of[...this[_0x448c2a(0x1d9)]]){if(!_0x5316f4[_0x448c2a(0xf7)](_0x1a3f9c+'\x00'))continue;this[_0x448c2a(0x1d9)][_0x448c2a(0x111)](_0x5316f4),this[_0x448c2a(0x1d9)][_0x448c2a(0xd9)](''+_0x33ca0b+_0x5316f4[_0x448c2a(0x1b3)](_0x1a3f9c[_0x448c2a(0x171)]),_0xe0427);}for(const [_0x1fa2c6,_0x20cb18]of this[_0x448c2a(0xf3)])if(_0x20cb18[_0x448c2a(0xe0)]===_0x1a3f9c)this[_0x448c2a(0xf3)][_0x448c2a(0xd9)](_0x1fa2c6,{..._0x20cb18,'sessionId':_0x33ca0b});for(const _0x23e2c2 of _0x3dc487){const _0x1e5a9a=this[_0x448c2a(0xfe)](_0x23e2c2['id']);this[_0x448c2a(0x197)](_0x1e5a9a,_0x3b906e);}return _0x3b906e;}[_0xbdbd9d(0xde)](_0x534ac7,_0x2d0bd4){const _0x3ec751=_0xbdbd9d;if(_0x2d0bd4[_0x3ec751(0x171)]<-0x2618+-0x69a+-0x11*-0x2a2)throw new Error(_0x3ec751(0x1ad));this[_0x3ec751(0x1ef)](_0x534ac7,{'channelToken':_0x2d0bd4});}[_0xbdbd9d(0xcb)](_0x3ae222){const _0x2b379b=_0xbdbd9d,_0x265102=this[_0x2b379b(0x169)](_0x3ae222[_0x2b379b(0xe0)]),_0x28df2d=_0x3ae222[_0x2b379b(0x1be)]===undefined?_0x265102[_0x2b379b(0x1be)]:_0x3ae222[_0x2b379b(0x1be)]?.[_0x2b379b(0x182)]()||null;if(_0x28df2d!==null&&_0x28df2d[_0x2b379b(0x171)]>-0x15*-0x18e+0x16f8+-0x36fe)throw new Error(_0x2b379b(0xf0));return this[_0x2b379b(0x1ef)](_0x265102['id'],{'customTitle':_0x28df2d,'pinnedAt':_0x3ae222[_0x2b379b(0x1e6)]===undefined?_0x265102[_0x2b379b(0x198)]:_0x3ae222[_0x2b379b(0x1e6)]?this[_0x2b379b(0x130)]():null,'titleSource':_0x28df2d===null?_0x2b379b(0x16b):_0x2b379b(0x10d)});}[_0xbdbd9d(0xd8)](_0x3f6309,_0xdaf7f3){const _0x2a0379=_0xbdbd9d,_0x1dfc69=this[_0x2a0379(0x169)](_0x3f6309),_0xa77ae0=_0xdaf7f3[_0x2a0379(0x182)]()[_0x2a0379(0xe5)](/\s+/g,'\x20')[_0x2a0379(0x1b3)](-0x215b*-0x1+-0x422+-0x1d39,0xf0b*0x2+0x15ff*-0x1+0x7*-0x111);if(_0xa77ae0[_0x2a0379(0x171)]===0x239b+-0x16df+-0xcbc||_0x1dfc69[_0x2a0379(0x1be)]!==null||_0x1dfc69[_0x2a0379(0x1d8)]!==null)return _0x1dfc69;return this[_0x2a0379(0x1ef)](_0x3f6309,{'runnerTitle':_0xa77ae0,'titleSource':_0x2a0379(0x16b)});}[_0xbdbd9d(0x1e7)](_0x34d83c,_0x1e7ed9){const _0x417fa0=_0xbdbd9d,_0x23034b=this[_0x417fa0(0x169)](_0x34d83c),_0x4298f9=_0x1e7ed9[_0x417fa0(0x182)]()[_0x417fa0(0xe5)](/\s+/g,'\x20')[_0x417fa0(0x1b3)](0x5*-0x26e+0x49c+0x78a,0x25a6+0xbcf+0x1047*-0x3);if(_0x4298f9[_0x417fa0(0x171)]===-0x2065*0x1+0xa77+-0x191*-0xe||_0x23034b[_0x417fa0(0x1be)]!==null||_0x23034b[_0x417fa0(0x1d8)]===_0x4298f9||_0x23034b[_0x417fa0(0x178)]===_0x417fa0(0x16b)&&isDefaultRunnerTitle(_0x4298f9))return _0x23034b;return this[_0x417fa0(0x1ef)](_0x34d83c,{'runnerTitle':_0x4298f9,'titleSource':_0x417fa0(0xe1)});}[_0xbdbd9d(0x17d)](_0x342a43){const _0x1cd300=_0xbdbd9d;this[_0x1cd300(0x199)](_0x342a43[_0x1cd300(0xe0)]);const _0x2dc549=_0x342a43[_0x1cd300(0xe0)]+'\x00'+_0x342a43[_0x1cd300(0xfd)],_0x3057ef=this[_0x1cd300(0x1d9)][_0x1cd300(0x156)](_0x2dc549);if(_0x3057ef!==undefined){if(_0x3057ef[_0x1cd300(0x1a5)]!==_0x1cd300(0xcc))throw new Error(_0x1cd300(0x193));return{'run':this[_0x1cd300(0xfe)](_0x3057ef['id']),'created':![]};}const _0x2df819=this[_0x1cd300(0x169)](_0x342a43[_0x1cd300(0xe0)]);if(this[_0x1cd300(0x1a7)](_0x2df819['id'])!==undefined)throw new Error(_0x1cd300(0x186));const _0x51c559=this[_0x1cd300(0x130)](),_0x241c23={'id':_0x342a43[_0x1cd300(0x129)]??randomUUID(),'sessionId':_0x2df819['id'],'nodeId':this[_0x1cd300(0x12f)](),'workspaceId':_0x2df819[_0x1cd300(0x155)],'runner':_0x2df819[_0x1cd300(0xd6)],'status':_0x1cd300(0x10e),'recoveryState':_0x1cd300(0x17a),'version':0x0,'clientMessageId':_0x342a43[_0x1cd300(0xfd)],..._0x342a43[_0x1cd300(0x138)]===undefined?{}:{'initiatedByUserId':_0x342a43[_0x1cd300(0x138)]},'createdAt':_0x51c559,'startedAt':_0x51c559,'completedAt':null,'updatedAt':_0x51c559},_0x2859d0=this[_0x1cd300(0x16f)](_0x241c23['id'],_0x342a43[_0x1cd300(0xff)]??[]),_0x887580={'id':randomUUID(),'sessionId':_0x2df819['id'],'turnId':'','runId':_0x241c23['id'],'parentItemId':null,'sourceSequence':null,'revision':0x0,'kind':_0x1cd300(0x14b),'status':_0x1cd300(0x1d5),'payload':{'clientMessageId':_0x342a43[_0x1cd300(0xfd)],'text':_0x342a43[_0x1cd300(0x13a)],'contexts':[],'attachments':_0x2859d0,'delivery':_0x1cd300(0x1a9)},'startedAt':_0x51c559,'completedAt':_0x51c559},_0x5b4464={'id':randomUUID(),'sessionId':_0x2df819['id'],'runId':_0x241c23['id'],'userItemId':_0x887580['id'],'status':_0x1cd300(0x17c),'model':_0x2df819[_0x1cd300(0x1ac)],'effort':_0x2df819[_0x1cd300(0x101)],'access':_0x2df819[_0x1cd300(0xd2)],'items':[_0x887580],'startedAt':_0x51c559,'completedAt':null},_0x469600={..._0x5b4464,'items':[{..._0x887580,'turnId':_0x5b4464['id']}]};return this[_0x1cd300(0x1ed)][_0x1cd300(0xd9)](_0x241c23['id'],_0x241c23),this[_0x1cd300(0x1a0)][_0x1cd300(0xd9)](_0x241c23['id'],_0x342a43[_0x1cd300(0xd4)]??_0x342a43[_0x1cd300(0x13a)]),this[_0x1cd300(0x1d9)][_0x1cd300(0xd9)](_0x2dc549,{'kind':_0x1cd300(0xcc),'id':_0x241c23['id']}),this[_0x1cd300(0x1bb)][_0x1cd300(0xd9)](_0x2df819['id'],_0x241c23['id']),this[_0x1cd300(0xf2)][_0x1cd300(0xd9)](_0x2df819['id'],[...this[_0x1cd300(0xf2)][_0x1cd300(0x156)](_0x2df819['id'])??[],_0x469600]),this[_0x1cd300(0x1ef)](_0x2df819['id'],{'lastActivityAt':_0x51c559}),this[_0x1cd300(0x197)](_0x241c23,this[_0x1cd300(0x169)](_0x2df819['id'])),{'run':_0x241c23,'created':!![]};}[_0xbdbd9d(0x1d0)](_0x2a30ed){const _0x205cc0=_0xbdbd9d;this[_0x205cc0(0x199)](_0x2a30ed[_0x205cc0(0xe0)]);const _0x409590=_0x2a30ed[_0x205cc0(0xe0)]+'\x00'+_0x2a30ed[_0x205cc0(0xfd)],_0x31a251=this[_0x205cc0(0x1d9)][_0x205cc0(0x156)](_0x409590);if(_0x31a251!==undefined){if(_0x31a251[_0x205cc0(0x1a5)]!==_0x205cc0(0x1c5))throw new Error(_0x205cc0(0x1c2));return{'item':this[_0x205cc0(0x16a)](_0x31a251['id']),'created':![]};}const _0x2c6a85=this[_0x205cc0(0x169)](_0x2a30ed[_0x205cc0(0xe0)]),_0x467991=this[_0x205cc0(0x1a7)](_0x2c6a85['id']),_0x4b852c=(this[_0x205cc0(0x1d7)][_0x205cc0(0x156)](_0x2c6a85['id'])??[])[_0x205cc0(0xe7)](_0x336b18=>this[_0x205cc0(0x18c)][_0x205cc0(0x156)](_0x336b18)?.[_0x205cc0(0x138)])[_0x205cc0(0x1df)](_0x4ca262=>_0x4ca262!==undefined),_0x16cf34=_0x467991?.[_0x205cc0(0x138)]??_0x4b852c;if(_0x16cf34!==undefined&&_0x2a30ed[_0x205cc0(0x138)]!==_0x16cf34)throw new Error(_0x205cc0(0x12d));const _0x4d01cc=this[_0x205cc0(0x130)](),_0x48ecc2={'id':_0x2a30ed[_0x205cc0(0x1db)]??randomUUID(),'sessionId':_0x2c6a85['id'],'workspaceId':_0x2c6a85[_0x205cc0(0x155)],'runner':_0x2c6a85[_0x205cc0(0xd6)],'clientMessageId':_0x2a30ed[_0x205cc0(0xfd)],'content':_0x2a30ed[_0x205cc0(0x13a)],'attachments':_0x2a30ed[_0x205cc0(0xff)]??[],..._0x2a30ed[_0x205cc0(0x138)]===undefined?{}:{'initiatedByUserId':_0x2a30ed[_0x205cc0(0x138)]},'createdAt':_0x4d01cc};return this[_0x205cc0(0x18c)][_0x205cc0(0xd9)](_0x48ecc2['id'],_0x48ecc2),this[_0x205cc0(0x1d9)][_0x205cc0(0xd9)](_0x409590,{'kind':_0x205cc0(0x1c5),'id':_0x48ecc2['id']}),this[_0x205cc0(0x1d7)][_0x205cc0(0xd9)](_0x2c6a85['id'],[...this[_0x205cc0(0x1d7)][_0x205cc0(0x156)](_0x2c6a85['id'])??[],_0x48ecc2['id']]),this[_0x205cc0(0x149)](_0x2c6a85['id']),{'item':_0x48ecc2,'created':!![]};}[_0xbdbd9d(0x1dc)](_0x111574){const _0x4d4a64=_0xbdbd9d;return{'version':this[_0x4d4a64(0x105)][_0x4d4a64(0x156)](_0x111574)??0x1*-0x1b92+-0x503+0x2095,'paused':this[_0x4d4a64(0xed)][_0x4d4a64(0x132)](_0x111574),'itemIds':this[_0x4d4a64(0x1d7)][_0x4d4a64(0x156)](_0x111574)??[]};}[_0xbdbd9d(0x191)](_0x48efb1){const _0x29a7f2=_0xbdbd9d;return this[_0x29a7f2(0x18c)][_0x29a7f2(0x156)](_0x48efb1);}[_0xbdbd9d(0x17b)](_0x49714b,_0x5d769c){const _0x2c05c1=_0xbdbd9d;if(this[_0x2c05c1(0xed)][_0x2c05c1(0x132)](_0x49714b))return undefined;const _0x161005=this[_0x2c05c1(0x1a7)](_0x49714b);if(_0x161005===undefined)return undefined;const _0xea7c49=this[_0x2c05c1(0x1d7)][_0x2c05c1(0x156)](_0x49714b)??[],_0x129cbf=_0xea7c49[-0x1afb*0x1+0x1*0x17e1+0x31a];if(_0x129cbf===undefined)return undefined;const _0x2944e5=this[_0x2c05c1(0x16a)](_0x129cbf),_0x9ad661=_0x161005[_0x2c05c1(0x138)]===undefined&&_0x2944e5[_0x2c05c1(0x138)]!==undefined?{..._0x161005,'initiatedByUserId':_0x2944e5[_0x2c05c1(0x138)]}:_0x161005;if(_0x9ad661!==_0x161005)this[_0x2c05c1(0x1ed)][_0x2c05c1(0xd9)](_0x9ad661['id'],_0x9ad661);this[_0x2c05c1(0x1d7)][_0x2c05c1(0xd9)](_0x49714b,_0xea7c49[_0x2c05c1(0x1b3)](-0x1fd*-0x13+-0xb6*-0x4+-0x289e)),this[_0x2c05c1(0x149)](_0x49714b),this[_0x2c05c1(0x18c)][_0x2c05c1(0x111)](_0x129cbf),this[_0x2c05c1(0x1d9)][_0x2c05c1(0xd9)](_0x2944e5[_0x2c05c1(0xe0)]+'\x00'+_0x2944e5[_0x2c05c1(0xfd)],{'kind':_0x2c05c1(0xcc),'id':_0x9ad661['id']});const _0x538268=this[_0x2c05c1(0x173)](_0x9ad661,_0x2944e5[_0x2c05c1(0xfd)],_0x5d769c??_0x2944e5[_0x2c05c1(0x13a)],_0x2944e5[_0x2c05c1(0xff)]);return this[_0x2c05c1(0x1a0)][_0x2c05c1(0xd9)](_0x9ad661['id'],_0x2944e5[_0x2c05c1(0x13a)]),this[_0x2c05c1(0x197)](_0x9ad661,this[_0x2c05c1(0x169)](_0x49714b)),{'item':_0x2944e5,'turn':_0x538268};}[_0xbdbd9d(0x15a)](_0xcf37d0,_0x5d58dc){const _0x29496f=_0xbdbd9d,_0x9b64d9=this[_0x29496f(0x16a)](_0xcf37d0);if(this[_0x29496f(0x1a7)](_0x9b64d9[_0x29496f(0xe0)])!==undefined)throw new Error(_0x29496f(0x186));const _0xfe4baf=this[_0x29496f(0x1d7)][_0x29496f(0x156)](_0x9b64d9[_0x29496f(0xe0)])??[];if(_0xfe4baf[-0x2003+0x3ed*-0x9+0x4358]!==_0xcf37d0)throw new Error(_0x29496f(0x181));this[_0x29496f(0x1d7)][_0x29496f(0xd9)](_0x9b64d9[_0x29496f(0xe0)],_0xfe4baf[_0x29496f(0x1b3)](0x1ee9+-0x3ab*0x2+-0xe*0x1af)),this[_0x29496f(0x18c)][_0x29496f(0x111)](_0xcf37d0),this[_0x29496f(0x1d9)][_0x29496f(0x111)](_0x9b64d9[_0x29496f(0xe0)]+'\x00'+_0x9b64d9[_0x29496f(0xfd)]),this[_0x29496f(0x149)](_0x9b64d9[_0x29496f(0xe0)]);const _0x6cbc28=this[_0x29496f(0x17d)]({'sessionId':_0x9b64d9[_0x29496f(0xe0)],'clientMessageId':_0x9b64d9[_0x29496f(0xfd)],'content':_0x5d58dc??_0x9b64d9[_0x29496f(0x13a)],'recentUserMessage':_0x9b64d9[_0x29496f(0x13a)],..._0x9b64d9[_0x29496f(0xff)][_0x29496f(0x171)]===-0x150f+-0x51*-0x1f+-0xf0*-0xc?{}:{'attachments':_0x9b64d9[_0x29496f(0xff)]},..._0x9b64d9[_0x29496f(0x138)]===undefined?{}:{'initiatedByUserId':_0x9b64d9[_0x29496f(0x138)]}}),_0x45cb4a=this[_0x29496f(0x12e)](_0x6cbc28[_0x29496f(0xcc)]['id']);if(_0x45cb4a===undefined)throw new Error(_0x29496f(0x127));return{'run':_0x6cbc28[_0x29496f(0xcc)],'turn':_0x45cb4a};}[_0xbdbd9d(0xef)](_0x1d7e85){const _0x52a073=_0xbdbd9d;this[_0x52a073(0xed)][_0x52a073(0xd1)](_0x1d7e85),this[_0x52a073(0x149)](_0x1d7e85);}[_0xbdbd9d(0x1c9)](_0x300f44){const _0x50c02f=_0xbdbd9d;if(!this[_0x50c02f(0xed)][_0x50c02f(0x111)](_0x300f44))return;this[_0x50c02f(0x149)](_0x300f44);}[_0xbdbd9d(0x170)](_0x4fe6d1,_0x12d41b,_0x259500){const _0x313ec1=_0xbdbd9d,_0x2a4e32=this[_0x313ec1(0x1d7)][_0x313ec1(0x156)](_0x4fe6d1)??[];if(this[_0x313ec1(0x1dc)](_0x4fe6d1)[_0x313ec1(0x185)]!==_0x12d41b||_0x2a4e32[_0x313ec1(0x171)]!==_0x259500[_0x313ec1(0x171)]||new Set(_0x2a4e32)[_0x313ec1(0x104)]!==_0x2a4e32[_0x313ec1(0x171)]||_0x2a4e32[_0x313ec1(0x1da)](_0x4547cc=>!_0x259500[_0x313ec1(0x19a)](_0x4547cc)))throw new Error(_0x313ec1(0x1b1));if(_0x259500[_0x313ec1(0x1da)](_0x5760cb=>this[_0x313ec1(0x18c)][_0x313ec1(0x156)](_0x5760cb)?.[_0x313ec1(0xe0)]!==_0x4fe6d1))throw new Error(_0x313ec1(0x181));this[_0x313ec1(0x1d7)][_0x313ec1(0xd9)](_0x4fe6d1,[..._0x259500]),this[_0x313ec1(0x149)](_0x4fe6d1);}[_0xbdbd9d(0xf9)](_0x565a2f){const _0x240f8a=_0xbdbd9d,_0x2aa14f=this[_0x240f8a(0x16a)](_0x565a2f),_0x4587c3=this[_0x240f8a(0x1d7)][_0x240f8a(0x156)](_0x2aa14f[_0x240f8a(0xe0)])??[];if(!_0x4587c3[_0x240f8a(0x19a)](_0x565a2f))throw new Error(_0x240f8a(0x181));return this[_0x240f8a(0x1d7)][_0x240f8a(0xd9)](_0x2aa14f[_0x240f8a(0xe0)],[_0x565a2f,..._0x4587c3[_0x240f8a(0x1e1)](_0x88e0a8=>_0x88e0a8!==_0x565a2f)]),this[_0x240f8a(0x149)](_0x2aa14f[_0x240f8a(0xe0)]),_0x2aa14f;}[_0xbdbd9d(0x176)](_0x486c00,_0x4c553f){const _0x40fefd=_0xbdbd9d,_0x451520=this[_0x40fefd(0x16a)](_0x486c00);if(!(this[_0x40fefd(0x1d7)][_0x40fefd(0x156)](_0x451520[_0x40fefd(0xe0)])??[])[_0x40fefd(0x19a)](_0x486c00))throw new Error(_0x40fefd(0x181));const _0x596864={..._0x451520,'content':_0x4c553f};return this[_0x40fefd(0x18c)][_0x40fefd(0xd9)](_0x486c00,_0x596864),this[_0x40fefd(0x149)](_0x451520[_0x40fefd(0xe0)]),_0x596864;}[_0xbdbd9d(0x15e)](_0xf2f7f1,_0x522b62){const _0x55e44f=_0xbdbd9d,_0x590c56=this[_0x55e44f(0x16a)](_0xf2f7f1),_0x31b340={..._0x590c56,'attachments':_0x522b62};return this[_0x55e44f(0x18c)][_0x55e44f(0xd9)](_0xf2f7f1,_0x31b340),_0x31b340;}[_0xbdbd9d(0x145)](_0x4d096){const _0x2eaf35=_0xbdbd9d,_0x3b99bc=this[_0x2eaf35(0x16a)](_0x4d096),_0x39f3cf=this[_0x2eaf35(0x1d7)][_0x2eaf35(0x156)](_0x3b99bc[_0x2eaf35(0xe0)])??[];if(!_0x39f3cf[_0x2eaf35(0x19a)](_0x4d096))throw new Error(_0x2eaf35(0x181));this[_0x2eaf35(0x1d7)][_0x2eaf35(0xd9)](_0x3b99bc[_0x2eaf35(0xe0)],_0x39f3cf[_0x2eaf35(0x1e1)](_0x66fd8a=>_0x66fd8a!==_0x4d096)),this[_0x2eaf35(0x149)](_0x3b99bc[_0x2eaf35(0xe0)]),this[_0x2eaf35(0x18c)][_0x2eaf35(0x111)](_0x4d096);for(const [_0x37e0fc,_0x500482]of this[_0x2eaf35(0x1d9)])if(_0x500482[_0x2eaf35(0x1a5)]===_0x2eaf35(0x1c5)&&_0x500482['id']===_0x4d096)this[_0x2eaf35(0x1d9)][_0x2eaf35(0x111)](_0x37e0fc);}[_0xbdbd9d(0x1b5)](_0x367d47){const _0x3aba59=_0xbdbd9d,_0x4c5e7a=this[_0x3aba59(0xfe)](_0x367d47),_0x1d8e8f=(this[_0x3aba59(0xf2)][_0x3aba59(0x156)](_0x4c5e7a[_0x3aba59(0xe0)])??[])[_0x3aba59(0x118)](_0x39d11b=>_0x39d11b[_0x3aba59(0x129)]===_0x367d47),_0x25a326=_0x1d8e8f?.[_0x3aba59(0x135)][_0x3aba59(0x1df)](_0x55b74a=>_0x55b74a['id']===_0x1d8e8f[_0x3aba59(0x1e0)]);return isRecord(_0x25a326?.[_0x3aba59(0x11f)])&&typeof _0x25a326[_0x3aba59(0x11f)][_0x3aba59(0x131)]===_0x3aba59(0x147)?_0x25a326[_0x3aba59(0x11f)][_0x3aba59(0x131)]:'';}[_0xbdbd9d(0x1a8)](_0x320a79,_0xb331db,_0x1c4404){const _0x145126=_0xbdbd9d,_0x32c386=this[_0x145126(0x16f)](_0x320a79,_0x1c4404);this[_0x145126(0x1e3)](_0x320a79,_0x5dd15c=>({..._0x5dd15c,'items':_0x5dd15c[_0x145126(0x135)][_0x145126(0xe7)](_0x193773=>_0x193773['id']===_0x5dd15c[_0x145126(0x1e0)]&&isRecord(_0x193773[_0x145126(0x11f)])?{..._0x193773,'payload':{..._0x193773[_0x145126(0x11f)],'text':_0xb331db,'attachments':_0x32c386}}:_0x193773)}));}[_0xbdbd9d(0x15b)](_0xd5f7ec){const _0x3e862d=_0xbdbd9d,_0x222818=this[_0x3e862d(0xf6)][_0x3e862d(0x156)](_0xd5f7ec)?.[_0x3e862d(0x129)]??_0xd5f7ec;return this[_0x3e862d(0x1ed)][_0x3e862d(0x156)](_0x222818);}[_0xbdbd9d(0x122)](_0x4b6394,_0x282ef2){const _0x2ff84e=_0xbdbd9d,_0x235308=this[_0x2ff84e(0x1d9)][_0x2ff84e(0x156)](_0x4b6394+'\x00'+_0x282ef2);return _0x235308?.[_0x2ff84e(0x1a5)]===_0x2ff84e(0xcc)?this[_0x2ff84e(0x1ed)][_0x2ff84e(0x156)](_0x235308['id']):undefined;}[_0xbdbd9d(0x108)](_0x1bb2d6,_0x2b580d){const _0x2d954b=_0xbdbd9d,_0x390613=this[_0x2d954b(0x1d9)][_0x2d954b(0x156)](_0x1bb2d6+'\x00'+_0x2b580d);if(_0x390613===undefined)return undefined;if(_0x390613[_0x2d954b(0x1a5)]===_0x2d954b(0xcc))return{'kind':_0x2d954b(0xcc),'run':this[_0x2d954b(0xfe)](_0x390613['id'])};const _0x48221f=this[_0x2d954b(0x16a)](_0x390613['id']),_0x3d7c0d=this[_0x2d954b(0x1a7)](_0x1bb2d6);if(_0x3d7c0d===undefined)throw new Error(_0x2d954b(0x18e));return{'kind':_0x2d954b(0x1c5),'item':_0x48221f,'run':_0x3d7c0d};}[_0xbdbd9d(0x1f0)](_0x3196c5,_0x4a5eb7){const _0x1c25a1=_0xbdbd9d;return this[_0x1c25a1(0x119)][_0x1c25a1(0x156)](_0x3196c5+'\x00'+_0x4a5eb7);}[_0xbdbd9d(0x195)](_0x3fb779,_0x45299b){const _0x3f1186=_0xbdbd9d,_0x5baac8=[...this[_0x3f1186(0x1d9)]][_0x3f1186(0x1df)](([,_0x2ad4e8])=>_0x2ad4e8['id']===_0x3fb779);if(_0x5baac8===undefined)return;this[_0x3f1186(0x119)][_0x3f1186(0xd9)](_0x5baac8[0xb46*-0x2+-0xd03*0x3+0x41b*0xf],_0x45299b);if(this[_0x3f1186(0x119)][_0x3f1186(0x104)]>-0x118c+-0x15bf*0x1+0x2b4b)this[_0x3f1186(0x119)][_0x3f1186(0x111)](this[_0x3f1186(0x119)][_0x3f1186(0x113)]()[_0x3f1186(0x1d3)]()[_0x3f1186(0x124)]);}[_0xbdbd9d(0x15f)](_0x59c28b){const _0xf83d19=_0xbdbd9d;return[...this[_0xf83d19(0x1ed)][_0xf83d19(0xea)]()][_0xf83d19(0x1e1)](_0x42e424=>_0x42e424[_0xf83d19(0xe0)]===_0x59c28b)[_0xf83d19(0x102)]((_0x5c3ad7,_0x5e04d2)=>_0x5e04d2[_0xf83d19(0xca)]-_0x5c3ad7[_0xf83d19(0xca)]);}[_0xbdbd9d(0x13f)](_0x47231a,_0x21cde1){const _0x1c29b0=_0xbdbd9d,_0x2ce52b=this[_0x1c29b0(0xf6)][_0x1c29b0(0x156)](_0x47231a)?.[_0x1c29b0(0x129)]??_0x47231a,_0xb91f7f=this[_0x1c29b0(0xfe)](_0x2ce52b);if(!transitionAllowed(_0xb91f7f[_0x1c29b0(0x134)],_0x21cde1))throw new Error(_0x1c29b0(0x121));const _0x1d6046=this[_0x1c29b0(0x130)](),_0x256110={..._0xb91f7f,'status':_0x21cde1,'version':_0xb91f7f[_0x1c29b0(0x185)]+(0x8*-0x28d+0x3fb*0x7+0xd4*-0x9),'completedAt':terminal(_0x21cde1)?_0x1d6046:_0xb91f7f[_0x1c29b0(0x1c4)],'updatedAt':_0x1d6046};this[_0x1c29b0(0x1ed)][_0x1c29b0(0xd9)](_0x2ce52b,_0x256110),this[_0x1c29b0(0x197)](_0x256110,this[_0x1c29b0(0x169)](_0x256110[_0x1c29b0(0xe0)]));if(terminal(_0x21cde1)&&this[_0x1c29b0(0x1bb)][_0x1c29b0(0x156)](_0x256110[_0x1c29b0(0xe0)])===_0x256110['id'])this[_0x1c29b0(0x1bb)][_0x1c29b0(0x111)](_0x256110[_0x1c29b0(0xe0)]);return this[_0x1c29b0(0x1e3)](_0x256110['id'],_0x3d9876=>({..._0x3d9876,'status':_0x21cde1,'completedAt':terminal(_0x21cde1)?this[_0x1c29b0(0x130)]():_0x3d9876[_0x1c29b0(0x1c4)],'items':terminal(_0x21cde1)?_0x3d9876[_0x1c29b0(0x135)][_0x1c29b0(0xe7)](_0x9b9156=>activeConversationItem(_0x9b9156[_0x1c29b0(0x134)])?{..._0x9b9156,'status':completedStatusForRun(_0x21cde1),'completedAt':this[_0x1c29b0(0x130)]()}:_0x9b9156):_0x3d9876[_0x1c29b0(0x135)]})),_0x256110;}[_0xbdbd9d(0x1d4)](_0x34e959){const _0x9fb702=_0xbdbd9d,_0xe8665=this[_0x9fb702(0xf6)][_0x9fb702(0x156)](_0x34e959[_0x9fb702(0x129)]),_0x5bc03f=_0xe8665?.[_0x9fb702(0x129)]??_0x34e959[_0x9fb702(0x129)];this[_0x9fb702(0xfe)](_0x5bc03f);const _0x563b88=this[_0x9fb702(0xf1)][_0x9fb702(0x156)](_0x5bc03f)??0x28*-0xd6+0x2677+0x1ad*-0x3;if(_0x34e959[_0x9fb702(0xeb)]<=_0x563b88)return undefined;if(_0x34e959[_0x9fb702(0xeb)]>_0x563b88+(-0xe87*0x1+-0x7b2+0x163a))throw new Error(_0x9fb702(0x17f));const _0xb4a3a={'runId':_0x5bc03f,'sequence':_0x34e959[_0x9fb702(0xeb)],'eventType':_0x34e959[_0x9fb702(0x1d2)],'payload':_0x34e959[_0x9fb702(0x11f)],..._0x34e959[_0x9fb702(0x134)]===undefined?{}:{'status':_0x34e959[_0x9fb702(0x134)]},'createdAt':this[_0x9fb702(0x130)]()};this[_0x9fb702(0xf1)][_0x9fb702(0xd9)](_0x5bc03f,_0x34e959[_0x9fb702(0xeb)]);if(_0xe8665!==undefined&&_0x34e959[_0x9fb702(0x134)]!==undefined){const _0x5f338c=executionStatusForRun(_0x34e959[_0x9fb702(0x134)]);this[_0x9fb702(0xf6)][_0x9fb702(0xd9)](_0x34e959[_0x9fb702(0x129)],{..._0xe8665,'status':_0x5f338c,'completedAt':terminal(_0x34e959[_0x9fb702(0x134)])?_0xb4a3a[_0x9fb702(0xca)]:_0xe8665[_0x9fb702(0x1c4)]});}if(_0x34e959[_0x9fb702(0x134)]!==undefined&&!terminal(_0x34e959[_0x9fb702(0x134)]))this[_0x9fb702(0x13f)](_0x5bc03f,_0x34e959[_0x9fb702(0x134)]);this[_0x9fb702(0x1cf)](_0xb4a3a,_0xe8665?.[_0x9fb702(0x1d6)]);if(_0x34e959[_0x9fb702(0x134)]!==undefined&&terminal(_0x34e959[_0x9fb702(0x134)])&&_0xe8665!==undefined)this[_0x9fb702(0x1d1)](_0xe8665[_0x9fb702(0x1d6)],_0x34e959[_0x9fb702(0x134)],_0xb4a3a[_0x9fb702(0xca)]);return _0xb4a3a;}[_0xbdbd9d(0x1bd)](_0x5f500b){const _0xa1d8e3=_0xbdbd9d,_0xf6fe6c=this[_0xa1d8e3(0x12e)](_0x5f500b);if(_0xf6fe6c===undefined)return undefined;for(const [_0x4e1cd9,_0x463d32]of this[_0xa1d8e3(0xf6)])if(_0x463d32[_0xa1d8e3(0x129)]===_0x5f500b&&_0x463d32[_0xa1d8e3(0x1d6)]===_0xf6fe6c['id']&&!terminalExecution(_0x463d32[_0xa1d8e3(0x134)]))return _0x4e1cd9;return undefined;}[_0xbdbd9d(0x110)](_0x278bd4){const _0x3eafb4=_0xbdbd9d,_0x3f0eb0=this[_0x3eafb4(0xdc)](_0x278bd4),_0x4a796c=this[_0x3eafb4(0x12e)](_0x3f0eb0);if(_0x4a796c===undefined||_0x4a796c[_0x3eafb4(0x134)]!==_0x3eafb4(0x17c))throw new Error(_0x3eafb4(0x1a3));const _0x200b12=[...this[_0x3eafb4(0xf6)][_0x3eafb4(0xea)]()][_0x3eafb4(0x1df)](_0x36f3fb=>_0x36f3fb[_0x3eafb4(0x129)]===_0x3f0eb0&&_0x36f3fb[_0x3eafb4(0x1d6)]===_0x4a796c['id']);if(_0x200b12!==undefined)return _0x200b12;const _0x20de49=this[_0x3eafb4(0x130)](),_0x2be9eb={'id':randomUUID(),'runId':_0x3f0eb0,'turnId':_0x4a796c['id'],'status':_0x3eafb4(0x10e),'startedAt':_0x20de49,'completedAt':null};return this[_0x3eafb4(0xf6)][_0x3eafb4(0xd9)](_0x2be9eb['id'],_0x2be9eb),this[_0x3eafb4(0x1e3)](_0x3f0eb0,_0x33bb3e=>({..._0x33bb3e,'items':_0x33bb3e[_0x3eafb4(0x135)][_0x3eafb4(0xe7)](_0x5026ca=>_0x5026ca['id']===_0x33bb3e[_0x3eafb4(0x1e0)]&&isRecord(_0x5026ca[_0x3eafb4(0x11f)])&&Array[_0x3eafb4(0x1ca)](_0x5026ca[_0x3eafb4(0x11f)][_0x3eafb4(0xff)])?{..._0x5026ca,'payload':{..._0x5026ca[_0x3eafb4(0x11f)],'attachments':_0x5026ca[_0x3eafb4(0x11f)][_0x3eafb4(0xff)][_0x3eafb4(0xe7)](_0x526455=>isRecord(_0x526455)&&typeof _0x526455[_0x3eafb4(0x146)]===_0x3eafb4(0x1a6)?{..._0x526455,'runId':_0x2be9eb['id']}:_0x526455)}}:_0x5026ca)})),_0x2be9eb;}[_0xbdbd9d(0xdc)](_0x31a043){const _0x4847da=_0xbdbd9d;return this[_0x4847da(0xf6)][_0x4847da(0x156)](_0x31a043)?.[_0x4847da(0x129)]??_0x31a043;}[_0xbdbd9d(0x13c)](_0x408f0d,_0x5f1487){const _0x2c2909=_0xbdbd9d;return this[_0x2c2909(0x13f)](this[_0x2c2909(0xdc)](_0x408f0d),_0x5f1487);}[_0xbdbd9d(0x11b)](_0x161268){const _0x5ee9f9=_0xbdbd9d;this[_0x5ee9f9(0x169)](_0x161268[_0x5ee9f9(0xe0)]);const _0x59a7ac=[...this[_0x5ee9f9(0xf2)][_0x5ee9f9(0x156)](_0x161268[_0x5ee9f9(0xe0)])??[]][_0x5ee9f9(0xe7)]((_0x4c5c5e,_0x33b4f1)=>({'turn':_0x4c5c5e,'index':_0x33b4f1}))[_0x5ee9f9(0x102)]((_0x921d2f,_0x43329b)=>{const _0x13bf1b=_0x5ee9f9,_0x9cbb7f=_0x1db033=>_0x1db033[_0x13bf1b(0x135)][_0x13bf1b(0x1df)](_0x32eff3=>_0x32eff3['id']===_0x1db033[_0x13bf1b(0x1e0)])?.[_0x13bf1b(0x120)]??_0x1db033[_0x13bf1b(0x120)]??_0x1db033[_0x13bf1b(0x1c4)]??-0x759*-0x4+0x1*-0xb5d+-0x1207;return _0x9cbb7f(_0x921d2f[_0x13bf1b(0x14d)])-_0x9cbb7f(_0x43329b[_0x13bf1b(0x14d)])||_0x921d2f[_0x13bf1b(0xd5)]-_0x43329b[_0x13bf1b(0xd5)];})[_0x5ee9f9(0xe7)](({turn:_0x52be3a})=>_0x52be3a),_0x28c1bf=_0x161268[_0x5ee9f9(0xf4)]===undefined?_0x59a7ac[_0x5ee9f9(0x171)]:decodeCursor(_0x161268[_0x5ee9f9(0xf4)],_0x161268[_0x5ee9f9(0xe0)]),_0x377510=Math[_0x5ee9f9(0x1c3)](Math[_0x5ee9f9(0x115)](_0x161268[_0x5ee9f9(0x148)]??0x1416+0x318*-0x9+0x7e0,0x7d8*-0x1+0x7d*-0x9+-0xc3e*-0x1),0x64*-0x1+0x3b*-0xc+0x147*0x4),_0x8c2f25=Math[_0x5ee9f9(0x115)](0xd3*-0xa+-0x2003+0x2d*0xe5,_0x28c1bf-_0x377510),_0x5c45bd=_0x59a7ac[_0x5ee9f9(0x1b3)](_0x8c2f25,_0x28c1bf);return{'turns':_0x5c45bd,'nextCursor':_0x8c2f25>0x359*0x4+-0x1fd5+0x1271?encodeCursor(_0x161268[_0x5ee9f9(0xe0)],_0x8c2f25):null};}[_0xbdbd9d(0x1bf)](_0x579bf6){const _0x2bd83=_0xbdbd9d;for(const _0x529f6a of this[_0x2bd83(0xf2)][_0x2bd83(0xea)]()){const _0x1c770f=_0x529f6a[_0x2bd83(0x118)](_0x13dd63=>_0x13dd63[_0x2bd83(0x129)]===this[_0x2bd83(0xdc)](_0x579bf6));if(_0x1c770f!==undefined)return _0x1c770f;}return undefined;}[_0xbdbd9d(0x180)](_0x56f76b){const _0x2f4710=_0xbdbd9d,_0x41c463=this[_0x2f4710(0xf6)][_0x2f4710(0x156)](_0x56f76b),_0x4de5dd=_0x41c463===undefined?this[_0x2f4710(0xf3)][_0x2f4710(0x156)](_0x56f76b):{'sessionId':this[_0x2f4710(0xfe)](_0x41c463[_0x2f4710(0x129)])[_0x2f4710(0xe0)],'turnId':_0x41c463[_0x2f4710(0x1d6)]};if(_0x4de5dd===undefined)return undefined;return(this[_0x2f4710(0xf2)][_0x2f4710(0x156)](_0x4de5dd[_0x2f4710(0xe0)])??[])[_0x2f4710(0x1df)](_0x5568ea=>_0x5568ea['id']===_0x4de5dd[_0x2f4710(0x1d6)]);}[_0xbdbd9d(0x1c0)](_0x1b1226){const _0x368f78=_0xbdbd9d,_0x139da2=this[_0x368f78(0x11b)](_0x1b1226)[_0x368f78(0xf2)];return{'items':_0x139da2[_0x368f78(0x157)](_0x3fc114=>_0x3fc114[_0x368f78(0x135)]),'nextCursor':null};}[_0xbdbd9d(0xdb)](_0x4c1c03){const _0x21342f=_0xbdbd9d,_0x226696=this[_0x21342f(0x169)](_0x4c1c03[_0x21342f(0xe0)]),_0x573769=this[_0x21342f(0x130)](),_0x25f000={'id':randomUUID(),'sessionId':_0x4c1c03[_0x21342f(0xe0)],'turnId':'','runId':null,'parentItemId':null,'sourceSequence':null,'revision':0x1,'kind':_0x21342f(0xd7),'status':_0x4c1c03[_0x21342f(0x1e4)]?_0x21342f(0x1e5):_0x21342f(0x1d5),'payload':{'command':_0x4c1c03[_0x21342f(0x194)],'cwd':_0x4c1c03[_0x21342f(0x12b)],'outputPreview':_0x4c1c03[_0x21342f(0x103)][_0x21342f(0x1b3)](-0x2238+0x849*-0x1+-0x9*-0x4b9,0x379e+-0x425b+0x31cd),'outputRef':null,'exitCode':_0x4c1c03[_0x21342f(0x1e4)]?0x584+-0x1242+0xcbf:-0x1*0x11ea+-0x1e6b+0x3055,'durationMs':0x0,'truncated':![]},'startedAt':_0x573769,'completedAt':_0x573769},_0xf5b4cd={'id':randomUUID(),'sessionId':_0x4c1c03[_0x21342f(0xe0)],'runId':null,'userItemId':null,'status':_0x4c1c03[_0x21342f(0x1e4)]?_0x21342f(0x1e5):_0x21342f(0x1e2),'model':_0x226696[_0x21342f(0x1ac)],'effort':_0x226696[_0x21342f(0x101)],'access':_0x226696[_0x21342f(0xd2)],'items':[],'startedAt':_0x573769,'completedAt':_0x573769},_0x2b6a92={..._0x25f000,'turnId':_0xf5b4cd['id']},_0xd80c4e={..._0xf5b4cd,'items':[_0x2b6a92]};return this[_0x21342f(0xf2)][_0x21342f(0xd9)](_0x4c1c03[_0x21342f(0xe0)],[...this[_0x21342f(0xf2)][_0x21342f(0x156)](_0x4c1c03[_0x21342f(0xe0)])??[],_0xd80c4e]),this[_0x21342f(0x1ef)](_0x226696['id'],{'lastActivityAt':_0x573769}),_0xd80c4e;}[_0xbdbd9d(0x1e8)](_0x376e46){const _0x307ced=_0xbdbd9d,_0x79f103=this[_0x307ced(0x15b)](_0x376e46[_0x307ced(0x129)]);if(_0x79f103===undefined)throw new Error(_0x307ced(0x18e));if(_0x376e46[_0x307ced(0x129)]!==_0x79f103['id']&&this[_0x307ced(0x1bd)](_0x79f103['id'])!==_0x376e46[_0x307ced(0x129)])throw new Error(_0x307ced(0x162));if(this[_0x307ced(0x11d)][_0x307ced(0x132)](_0x376e46[_0x307ced(0x140)]))throw new Error(_0x307ced(0x13d));if(_0x376e46[_0x307ced(0x168)]<=this[_0x307ced(0x130)]())throw new Error(_0x307ced(0x16c));const _0x25c89d={'id':_0x376e46[_0x307ced(0x140)],'runId':_0x376e46[_0x307ced(0x129)],'status':_0x307ced(0x107),'payload':_0x376e46[_0x307ced(0x11f)],'expiresAt':_0x376e46[_0x307ced(0x168)],'createdAt':this[_0x307ced(0x130)](),'decidedAt':null};return this[_0x307ced(0x11d)][_0x307ced(0xd9)](_0x25c89d['id'],_0x25c89d),_0x25c89d;}[_0xbdbd9d(0x165)](_0x14a6c2){const _0x3f9617=_0xbdbd9d,_0x4794be=this[_0x3f9617(0x11d)][_0x3f9617(0x156)](_0x14a6c2);if(_0x4794be?.[_0x3f9617(0x134)]===_0x3f9617(0x107)&&_0x4794be[_0x3f9617(0x168)]<=this[_0x3f9617(0x130)]())return this[_0x3f9617(0x100)](_0x14a6c2);return _0x4794be;}[_0xbdbd9d(0x16d)](_0x49735b){const _0x4c61c1=_0xbdbd9d,_0x2e6dde=this[_0x4c61c1(0xdc)](_0x49735b);return[...this[_0x4c61c1(0x11d)][_0x4c61c1(0xea)]()][_0x4c61c1(0x1e1)](_0x11bfa5=>this[_0x4c61c1(0xdc)](_0x11bfa5[_0x4c61c1(0x129)])===_0x2e6dde)[_0x4c61c1(0xe7)](_0x1fc28f=>this[_0x4c61c1(0x165)](_0x1fc28f['id']));}[_0xbdbd9d(0x100)](_0x4adbc8){const _0x34190d=_0xbdbd9d,_0x3ea8ba=this[_0x34190d(0x1a2)](_0x4adbc8);if(_0x3ea8ba[_0x34190d(0x134)]!==_0x34190d(0x107))return _0x3ea8ba;if(_0x3ea8ba[_0x34190d(0x168)]>this[_0x34190d(0x130)]())throw new Error(_0x34190d(0x153));const _0x3b3b2b={..._0x3ea8ba,'status':_0x34190d(0x142),'decidedAt':this[_0x34190d(0x130)]()};return this[_0x34190d(0x11d)][_0x34190d(0xd9)](_0x4adbc8,_0x3b3b2b),_0x3b3b2b;}[_0xbdbd9d(0x125)](_0x495b90,_0x171dfb){const _0x27d75b=_0xbdbd9d,_0x283d87=this[_0x27d75b(0x165)](_0x495b90);if(_0x283d87===undefined)throw new Error(_0x27d75b(0x16e));if(_0x283d87[_0x27d75b(0x134)]===_0x27d75b(0x142))throw new Error(_0x27d75b(0x16c));if(_0x283d87[_0x27d75b(0x134)]!==_0x27d75b(0x107))throw new Error(_0x27d75b(0x159));const _0x5c9470={..._0x283d87,'status':_0x171dfb,'decidedAt':this[_0x27d75b(0x130)]()};return this[_0x27d75b(0x11d)][_0x27d75b(0xd9)](_0x495b90,_0x5c9470),_0x5c9470;}[_0xbdbd9d(0x179)](){const _0x43cdf8=_0xbdbd9d;return[...this[_0x43cdf8(0x11d)][_0x43cdf8(0xea)]()][_0x43cdf8(0x1e1)](_0x11c491=>_0x11c491[_0x43cdf8(0x134)]===_0x43cdf8(0x107)&&_0x11c491[_0x43cdf8(0x168)]<=this[_0x43cdf8(0x130)]())[_0x43cdf8(0xe7)](_0x13a47e=>this[_0x43cdf8(0x100)](_0x13a47e['id']));}[_0xbdbd9d(0x112)](){const _0x472426=_0xbdbd9d;return[...this[_0x472426(0x1ed)][_0x472426(0xea)]()][_0x472426(0x1e1)](_0x283593=>!terminal(_0x283593[_0x472426(0x134)]));}[_0xbdbd9d(0xda)](_0x52aac9){const _0x53ee8b=_0xbdbd9d;return this[_0x53ee8b(0xf1)][_0x53ee8b(0x156)](_0x52aac9)??0x113e+0xadb+-0x1c19;}[_0xbdbd9d(0x139)](_0x435752){const _0x3bf653=_0xbdbd9d,_0x50da9f=this[_0x3bf653(0xfe)](_0x435752);if(!terminal(_0x50da9f[_0x3bf653(0x134)]))throw new Error(_0x3bf653(0x1cb));this[_0x3bf653(0x117)][_0x3bf653(0xd1)](_0x435752);if(this[_0x3bf653(0x117)][_0x3bf653(0x104)]>-0x1c80+0x1*-0x1050+0x30d0)this[_0x3bf653(0x117)][_0x3bf653(0x111)](this[_0x3bf653(0x117)][_0x3bf653(0xea)]()[_0x3bf653(0x1d3)]()[_0x3bf653(0x124)]);const _0x2149bc=new Set([...this[_0x3bf653(0xf6)][_0x3bf653(0xea)]()][_0x3bf653(0x1e1)](_0x134748=>_0x134748[_0x3bf653(0x129)]===_0x435752)[_0x3bf653(0xe7)](_0x4e0f3f=>_0x4e0f3f['id'])),_0x51c4db=(this[_0x3bf653(0xf2)][_0x3bf653(0x156)](_0x50da9f[_0x3bf653(0xe0)])??[])[_0x3bf653(0x1e1)](_0x4ed8c6=>{const _0x409f13=_0x3bf653,_0x516405=_0x4ed8c6[_0x409f13(0x135)][_0x409f13(0x1da)](_0x4a7ec=>_0x4a7ec[_0x409f13(0x1a5)]===_0x409f13(0x10f));if(_0x4ed8c6[_0x409f13(0x129)]===_0x435752)return _0x50da9f[_0x409f13(0x134)]===_0x409f13(0x1e2)||_0x50da9f[_0x409f13(0x134)]===_0x409f13(0x160)||_0x516405;const _0x3bc8b8=_0x516405&&_0x4ed8c6[_0x409f13(0x134)]!==_0x409f13(0x1e2)&&_0x4ed8c6[_0x409f13(0x134)]!==_0x409f13(0x160);return _0x50da9f[_0x409f13(0x134)]!==_0x409f13(0x1e2)||!_0x3bc8b8;}),_0x57842b=_0x51c4db[_0x3bf653(0x1e1)](_0x352d33=>terminalTurn(_0x352d33[_0x3bf653(0x134)])),_0x19f942=new Set(_0x57842b[_0x3bf653(0x1b3)](-NodeRuntimeState[_0x3bf653(0x1a4)])[_0x3bf653(0xe7)](_0x2e2c8b=>_0x2e2c8b['id'])),_0xe29691=_0x51c4db[_0x3bf653(0x1e1)](_0x23eb77=>!terminalTurn(_0x23eb77[_0x3bf653(0x134)])||_0x19f942[_0x3bf653(0x132)](_0x23eb77['id'])),_0x8460c4=new Set(_0xe29691[_0x3bf653(0xe7)](_0x4bf35c=>_0x4bf35c['id']));this[_0x3bf653(0xf2)][_0x3bf653(0xd9)](_0x50da9f[_0x3bf653(0xe0)],_0xe29691);for(const [_0x3ca56e,_0x51b110]of this[_0x3bf653(0xf6)]){if(_0x51b110[_0x3bf653(0x129)]!==_0x435752)continue;this[_0x3bf653(0xf6)][_0x3bf653(0x111)](_0x3ca56e);if(_0x8460c4[_0x3bf653(0x132)](_0x51b110[_0x3bf653(0x1d6)]))this[_0x3bf653(0xf3)][_0x3bf653(0xd9)](_0x3ca56e,{'sessionId':_0x50da9f[_0x3bf653(0xe0)],'turnId':_0x51b110[_0x3bf653(0x1d6)]});}this[_0x3bf653(0x1bc)](_0x50da9f[_0x3bf653(0xe0)],_0x8460c4),this[_0x3bf653(0x1ed)][_0x3bf653(0x111)](_0x435752),this[_0x3bf653(0x1a0)][_0x3bf653(0x111)](_0x435752),this[_0x3bf653(0xf1)][_0x3bf653(0x111)](_0x435752);for(const [_0x3bbcd5,_0x4ce09c]of this[_0x3bf653(0x1d9)])if(_0x4ce09c[_0x3bf653(0x1a5)]===_0x3bf653(0xcc)&&_0x4ce09c['id']===_0x435752)this[_0x3bf653(0x1d9)][_0x3bf653(0x111)](_0x3bbcd5);for(const [_0xf18caf,_0x31a1d1]of this[_0x3bf653(0x11d)])if(_0x31a1d1[_0x3bf653(0x129)]===_0x435752||_0x2149bc[_0x3bf653(0x132)](_0x31a1d1[_0x3bf653(0x129)]))this[_0x3bf653(0x11d)][_0x3bf653(0x111)](_0xf18caf);}[_0xbdbd9d(0x12a)](_0x262a92){const _0x1bd349=_0xbdbd9d;return[...this[_0x1bd349(0x1bb)][_0x1bd349(0xea)]()][_0x1bd349(0xe7)](_0x47001e=>this[_0x1bd349(0x1ed)][_0x1bd349(0x156)](_0x47001e))[_0x1bd349(0x1da)](_0x38d504=>_0x38d504?.[_0x1bd349(0x155)]===_0x262a92);}[_0xbdbd9d(0xcf)](_0x3a7cd0){const _0x22c573=_0xbdbd9d;this[_0x22c573(0x169)](_0x3a7cd0);const _0xd73785=this[_0x22c573(0x15f)](_0x3a7cd0);if(_0xd73785[_0x22c573(0x1da)](_0x308161=>!terminal(_0x308161[_0x22c573(0x134)])))throw new Error(_0x22c573(0x11e));const _0x1317ed=new Set(_0xd73785[_0x22c573(0xe7)](_0x3eb6ee=>_0x3eb6ee['id'])),_0x27aa81=new Set([...this[_0x22c573(0xf6)][_0x22c573(0xea)]()][_0x22c573(0x1e1)](_0x4ae956=>_0x1317ed[_0x22c573(0x132)](_0x4ae956[_0x22c573(0x129)]))[_0x22c573(0xe7)](_0x109d4a=>_0x109d4a['id']));this[_0x22c573(0x1ec)][_0x22c573(0x111)](_0x3a7cd0),this[_0x22c573(0xf2)][_0x22c573(0x111)](_0x3a7cd0),this[_0x22c573(0x1bc)](_0x3a7cd0,new Set());const _0x46a00d=this[_0x22c573(0x1d7)][_0x22c573(0x156)](_0x3a7cd0)??[];this[_0x22c573(0x1d7)][_0x22c573(0x111)](_0x3a7cd0);for(const _0x160c5d of _0x46a00d)this[_0x22c573(0x18c)][_0x22c573(0x111)](_0x160c5d);this[_0x22c573(0x105)][_0x22c573(0x111)](_0x3a7cd0),this[_0x22c573(0xed)][_0x22c573(0x111)](_0x3a7cd0),this[_0x22c573(0x1bb)][_0x22c573(0x111)](_0x3a7cd0);for(const _0x3943be of _0x1317ed){this[_0x22c573(0x1ed)][_0x22c573(0x111)](_0x3943be),this[_0x22c573(0x1a0)][_0x22c573(0x111)](_0x3943be),this[_0x22c573(0xf1)][_0x22c573(0x111)](_0x3943be);}for(const _0x55d699 of _0x27aa81)this[_0x22c573(0xf6)][_0x22c573(0x111)](_0x55d699);for(const [_0x11d260,_0x1d9ee1]of this[_0x22c573(0x1d9)])if(_0x1d9ee1[_0x22c573(0x1a5)]===_0x22c573(0xcc)&&_0x1317ed[_0x22c573(0x132)](_0x1d9ee1['id'])||_0x1d9ee1[_0x22c573(0x1a5)]===_0x22c573(0x1c5)&&_0x46a00d[_0x22c573(0x19a)](_0x1d9ee1['id']))this[_0x22c573(0x1d9)][_0x22c573(0x111)](_0x11d260);for(const _0x1c016c of this[_0x22c573(0x119)][_0x22c573(0x113)]())if(_0x1c016c[_0x22c573(0xf7)](_0x3a7cd0+'\x00'))this[_0x22c573(0x119)][_0x22c573(0x111)](_0x1c016c);for(const [_0x2ca637,_0x184443]of this[_0x22c573(0x11d)])if(_0x1317ed[_0x22c573(0x132)](_0x184443[_0x22c573(0x129)])||_0x27aa81[_0x22c573(0x132)](_0x184443[_0x22c573(0x129)]))this[_0x22c573(0x11d)][_0x22c573(0x111)](_0x2ca637);}[_0xbdbd9d(0x151)](_0x17f175){const _0x3f9b3f=_0xbdbd9d;if(this[_0x3f9b3f(0xe8)][_0x3f9b3f(0x132)](_0x17f175))throw new Error(_0x3f9b3f(0x11e));if(this[_0x3f9b3f(0x1a7)](_0x17f175)!==undefined)throw new Error(_0x3f9b3f(0x11e));if(this[_0x3f9b3f(0x1dc)](_0x17f175)[_0x3f9b3f(0x114)][_0x3f9b3f(0x171)]>0x183c+0xb71*-0x2+-0x2*0xad)throw new Error(_0x3f9b3f(0x184));this[_0x3f9b3f(0xe8)][_0x3f9b3f(0xd1)](_0x17f175);let _0xa0c1ff=![];return()=>{const _0x54122e=_0x3f9b3f;if(_0xa0c1ff)return;_0xa0c1ff=!![],this[_0x54122e(0xe8)][_0x54122e(0x111)](_0x17f175);};}[_0xbdbd9d(0x1c1)](_0x3e6d45,_0x34462d){const _0x58a22c=_0xbdbd9d;if(this[_0x58a22c(0x1a7)](_0x3e6d45)!==undefined)throw new Error(_0x58a22c(0x11e));if(this[_0x58a22c(0x1dc)](_0x3e6d45)[_0x58a22c(0x114)][_0x58a22c(0x171)]>-0x245d+0x2*0x1388+0x1*-0x2b3)throw new Error(_0x58a22c(0x184));this[_0x58a22c(0xf2)][_0x58a22c(0x111)](_0x3e6d45),this[_0x58a22c(0x1bc)](_0x3e6d45,new Set());for(const _0x3b1871 of this[_0x58a22c(0x119)][_0x58a22c(0x113)]())if(_0x3b1871[_0x58a22c(0xf7)](_0x3e6d45+'\x00'))this[_0x58a22c(0x119)][_0x58a22c(0x111)](_0x3b1871);return this[_0x58a22c(0x1ef)](_0x3e6d45,{'lastActivityAt':_0x34462d});}[_0xbdbd9d(0x152)](_0x27a982){const _0x4e48fc=_0xbdbd9d;if(this[_0x4e48fc(0x12a)](_0x27a982))throw new Error(_0x4e48fc(0xf5));const _0x1f6d3e=new Set([...this[_0x4e48fc(0x1ec)][_0x4e48fc(0xea)]()][_0x4e48fc(0x1e1)](_0x545ecd=>_0x545ecd[_0x4e48fc(0x155)]===_0x27a982)[_0x4e48fc(0xe7)](_0x3b71a5=>_0x3b71a5['id'])),_0x1e4eb1=new Set([...this[_0x4e48fc(0x1ed)][_0x4e48fc(0xea)]()][_0x4e48fc(0x1e1)](_0x4c7dcd=>_0x4c7dcd[_0x4e48fc(0x155)]===_0x27a982)[_0x4e48fc(0xe7)](_0x4fa0b4=>_0x4fa0b4['id'])),_0x5bad75=new Set([...this[_0x4e48fc(0xf6)][_0x4e48fc(0xea)]()][_0x4e48fc(0x1e1)](_0x40b235=>_0x1e4eb1[_0x4e48fc(0x132)](_0x40b235[_0x4e48fc(0x129)]))[_0x4e48fc(0xe7)](_0x74e3d0=>_0x74e3d0['id'])),_0x270b0d=new Set([..._0x1f6d3e][_0x4e48fc(0x157)](_0x505d6b=>this[_0x4e48fc(0x1d7)][_0x4e48fc(0x156)](_0x505d6b)??[]));for(const _0x49f76b of _0x1f6d3e){this[_0x4e48fc(0x1ec)][_0x4e48fc(0x111)](_0x49f76b),this[_0x4e48fc(0xf2)][_0x4e48fc(0x111)](_0x49f76b),this[_0x4e48fc(0x1bc)](_0x49f76b,new Set());}for(const _0x286e5a of _0x1e4eb1){this[_0x4e48fc(0x1ed)][_0x4e48fc(0x111)](_0x286e5a),this[_0x4e48fc(0x1a0)][_0x4e48fc(0x111)](_0x286e5a),this[_0x4e48fc(0xf1)][_0x4e48fc(0x111)](_0x286e5a);}for(const _0x5684fe of _0x5bad75)this[_0x4e48fc(0xf6)][_0x4e48fc(0x111)](_0x5684fe);for(const [_0x379291,_0x1cf23b]of this[_0x4e48fc(0x1d9)])if(_0x1cf23b[_0x4e48fc(0x1a5)]===_0x4e48fc(0xcc)&&_0x1e4eb1[_0x4e48fc(0x132)](_0x1cf23b['id'])||_0x1cf23b[_0x4e48fc(0x1a5)]===_0x4e48fc(0x1c5)&&_0x270b0d[_0x4e48fc(0x132)](_0x1cf23b['id']))this[_0x4e48fc(0x1d9)][_0x4e48fc(0x111)](_0x379291);for(const _0x544572 of this[_0x4e48fc(0x119)][_0x4e48fc(0x113)]()){const _0x2a2484=_0x544572[_0x4e48fc(0xe3)]('\u0000');if(_0x2a2484>=-0x42c+-0x1f48+-0x4*-0x8dd&&_0x1f6d3e[_0x4e48fc(0x132)](_0x544572[_0x4e48fc(0x1b3)](-0x1adc+-0x1884+0x336*0x10,_0x2a2484)))this[_0x4e48fc(0x119)][_0x4e48fc(0x111)](_0x544572);}for(const [_0x43963e,_0x3013c1]of this[_0x4e48fc(0x11d)])if(_0x1e4eb1[_0x4e48fc(0x132)](_0x3013c1[_0x4e48fc(0x129)])||_0x5bad75[_0x4e48fc(0x132)](_0x3013c1[_0x4e48fc(0x129)]))this[_0x4e48fc(0x11d)][_0x4e48fc(0x111)](_0x43963e);for(const _0x317679 of _0x1f6d3e){const _0x59e425=this[_0x4e48fc(0x1d7)][_0x4e48fc(0x156)](_0x317679)??[];this[_0x4e48fc(0x1d7)][_0x4e48fc(0x111)](_0x317679);for(const _0x360c56 of _0x59e425)this[_0x4e48fc(0x18c)][_0x4e48fc(0x111)](_0x360c56);this[_0x4e48fc(0x105)][_0x4e48fc(0x111)](_0x317679),this[_0x4e48fc(0xed)][_0x4e48fc(0x111)](_0x317679),this[_0x4e48fc(0x1bb)][_0x4e48fc(0x111)](_0x317679);}}[_0xbdbd9d(0x199)](_0x593b82){const _0x34aa98=_0xbdbd9d;if(this[_0x34aa98(0xe8)][_0x34aa98(0x132)](_0x593b82))throw new Error(_0x34aa98(0x11e));}[_0xbdbd9d(0xd0)](_0x2d3b9a,_0x3cd14f){void _0x2d3b9a,void _0x3cd14f;}[_0xbdbd9d(0x1ef)](_0x5bef6f,_0x4f0efd){const _0x30ee82=_0xbdbd9d,_0xddccb0=this[_0x30ee82(0x169)](_0x5bef6f),_0x4ce59e={..._0xddccb0,..._0x4f0efd};this[_0x30ee82(0x1ec)][_0x30ee82(0xd9)](_0x5bef6f,_0x4ce59e);if(_0xddccb0[_0x30ee82(0x1be)]!==_0x4ce59e[_0x30ee82(0x1be)]||_0xddccb0[_0x30ee82(0x1d8)]!==_0x4ce59e[_0x30ee82(0x1d8)]){for(const _0x5864e6 of this[_0x30ee82(0x15f)](_0x5bef6f))this[_0x30ee82(0x197)](_0x5864e6,_0x4ce59e);}return _0x4ce59e;}[_0xbdbd9d(0x197)](_0x1da9cb,_0x1fb2bf){const _0x250bd5=_0xbdbd9d,_0xfef7a4=this[_0x250bd5(0x12e)](_0x1da9cb['id']),_0xb940c0=_0xfef7a4?.[_0x250bd5(0x135)][_0x250bd5(0x1df)](_0x5249a2=>_0x5249a2[_0x250bd5(0x1a5)]===_0x250bd5(0x14b))?.[_0x250bd5(0x11f)],_0x137be7=isRecord(_0xb940c0)&&typeof _0xb940c0[_0x250bd5(0xfd)]===_0x250bd5(0x147)?_0xb940c0[_0x250bd5(0xfd)]:undefined,_0x423530=_0x137be7?.[_0x250bd5(0xf7)](_0x250bd5(0x174))?'':this[_0x250bd5(0x1a0)][_0x250bd5(0x156)](_0x1da9cb['id'])??this[_0x250bd5(0x1b5)](_0x1da9cb['id']);this[_0x250bd5(0x1dd)]?.(_0x1da9cb,_0x1fb2bf,_0x423530[_0x250bd5(0x171)]===0x9*0x35f+-0x1c9b+-0x1bc?undefined:_0x423530);}[_0xbdbd9d(0x149)](_0x5b5881){const _0x47a7b6=_0xbdbd9d;this[_0x47a7b6(0x105)][_0x47a7b6(0xd9)](_0x5b5881,(this[_0x47a7b6(0x105)][_0x47a7b6(0x156)](_0x5b5881)??-0x1*-0x2267+0x2576+0x1*-0x47dd)+(0x7*-0x1a6+-0x1*0x114f+0x1cda));}[_0xbdbd9d(0x1bc)](_0x3c79a1,_0x42af9c){const _0x2bf327=_0xbdbd9d;for(const [_0x291ae8,_0x4566eb]of this[_0x2bf327(0xf3)])if(_0x4566eb[_0x2bf327(0xe0)]===_0x3c79a1&&!_0x42af9c[_0x2bf327(0x132)](_0x4566eb[_0x2bf327(0x1d6)]))this[_0x2bf327(0xf3)][_0x2bf327(0x111)](_0x291ae8);}[_0xbdbd9d(0x169)](_0x48f3e1){const _0x11fb4f=_0xbdbd9d,_0xa3f428=this[_0x11fb4f(0x1ec)][_0x11fb4f(0x156)](_0x48f3e1);if(_0xa3f428===undefined)throw new Error(_0x11fb4f(0x141));return _0xa3f428;}[_0xbdbd9d(0xfe)](_0x46dd84){const _0x1870c9=_0xbdbd9d,_0x4c0fdf=this[_0x1870c9(0x1ed)][_0x1870c9(0x156)](_0x46dd84);if(_0x4c0fdf===undefined)throw new Error(_0x1870c9(0x18e));return _0x4c0fdf;}[_0xbdbd9d(0x16a)](_0x47747a){const _0x355ce1=_0xbdbd9d,_0x231d78=this[_0x355ce1(0x18c)][_0x355ce1(0x156)](_0x47747a);if(_0x231d78===undefined)throw new Error(_0x355ce1(0x181));return _0x231d78;}[_0xbdbd9d(0x1a2)](_0xf4803d){const _0x19bacc=_0xbdbd9d,_0x32a6c0=this[_0x19bacc(0x11d)][_0x19bacc(0x156)](_0xf4803d);if(_0x32a6c0===undefined)throw new Error(_0x19bacc(0x16e));return _0x32a6c0;}[_0xbdbd9d(0x189)](_0x45dd92,_0x7f77cd){const _0x1a898b=_0xbdbd9d,_0x58b6bd=this[_0x1a898b(0xfe)](_0x45dd92),_0xe44002=this[_0x1a898b(0xf2)][_0x1a898b(0x156)](_0x58b6bd[_0x1a898b(0xe0)])??[];this[_0x1a898b(0xf2)][_0x1a898b(0xd9)](_0x58b6bd[_0x1a898b(0xe0)],_0xe44002[_0x1a898b(0xe7)](_0x2f2d66=>_0x2f2d66[_0x1a898b(0x129)]===_0x45dd92?_0x7f77cd(_0x2f2d66):_0x2f2d66));}[_0xbdbd9d(0x1e3)](_0x1eca8f,_0x15bf30){const _0x45d33c=_0xbdbd9d,_0x35a915=this[_0x45d33c(0xfe)](_0x1eca8f),_0x6f9a4b=this[_0x45d33c(0xf2)][_0x45d33c(0x156)](_0x35a915[_0x45d33c(0xe0)])??[],_0x5a27e1=_0x6f9a4b[_0x45d33c(0x15d)](_0x288d4a=>_0x288d4a[_0x45d33c(0x129)]===_0x1eca8f);if(_0x5a27e1<-0x44d+-0x135b*-0x2+-0x17f*0x17)return;this[_0x45d33c(0xf2)][_0x45d33c(0xd9)](_0x35a915[_0x45d33c(0xe0)],_0x6f9a4b[_0x45d33c(0xe7)]((_0x1f3a8b,_0x11aeeb)=>_0x11aeeb===_0x5a27e1?_0x15bf30(_0x1f3a8b):_0x1f3a8b));}[_0xbdbd9d(0x12e)](_0x5c0b6a){const _0x1e4d9a=_0xbdbd9d,_0x3dbd35=this[_0x1e4d9a(0xfe)](_0x5c0b6a);return(this[_0x1e4d9a(0xf2)][_0x1e4d9a(0x156)](_0x3dbd35[_0x1e4d9a(0xe0)])??[])[_0x1e4d9a(0x118)](_0x3dc0b5=>_0x3dc0b5[_0x1e4d9a(0x129)]===_0x5c0b6a);}[_0xbdbd9d(0x19b)](_0x4bea88,_0x4bd28c){const _0x1c7a77=_0xbdbd9d,_0xea6842=this[_0x1c7a77(0x169)](_0x4bea88[_0x1c7a77(0xe0)]),_0x2b44ad={'id':randomUUID(),'sessionId':_0xea6842['id'],'runId':_0x4bea88['id'],'userItemId':null,'status':terminal(_0x4bea88[_0x1c7a77(0x134)])?_0x4bea88[_0x1c7a77(0x134)]:_0x1c7a77(0xfa),'model':_0xea6842[_0x1c7a77(0x1ac)],'effort':_0xea6842[_0x1c7a77(0x101)],'access':_0xea6842[_0x1c7a77(0xd2)],'items':[],'startedAt':_0x4bd28c,'completedAt':terminal(_0x4bea88[_0x1c7a77(0x134)])?_0x4bd28c:null};return this[_0x1c7a77(0xf2)][_0x1c7a77(0xd9)](_0xea6842['id'],[...this[_0x1c7a77(0xf2)][_0x1c7a77(0x156)](_0xea6842['id'])??[],_0x2b44ad]),this[_0x1c7a77(0x1ef)](_0xea6842['id'],{'lastActivityAt':_0x4bd28c}),_0x2b44ad;}[_0xbdbd9d(0x173)](_0x23e6f4,_0x2659e0,_0x34f309,_0xc32d33){const _0x5c09ed=_0xbdbd9d,_0x1df3b7=this[_0x5c09ed(0x169)](_0x23e6f4[_0x5c09ed(0xe0)]),_0x249340=this[_0x5c09ed(0x130)](),_0x2e15bf=randomUUID(),_0x3d1ae6=randomUUID(),_0x30c3ed={'id':_0x3d1ae6,'sessionId':_0x1df3b7['id'],'turnId':_0x2e15bf,'runId':_0x23e6f4['id'],'parentItemId':null,'sourceSequence':null,'revision':0x0,'kind':_0x5c09ed(0x14b),'status':_0x5c09ed(0x1d5),'payload':{'clientMessageId':_0x2659e0,'text':_0x34f309,'contexts':[],'attachments':this[_0x5c09ed(0x16f)](_0x23e6f4['id'],_0xc32d33),'delivery':_0x5c09ed(0x1a9)},'startedAt':_0x249340,'completedAt':_0x249340},_0x4e65b8={'id':_0x2e15bf,'sessionId':_0x1df3b7['id'],'runId':_0x23e6f4['id'],'userItemId':_0x3d1ae6,'status':_0x5c09ed(0x17c),'model':_0x1df3b7[_0x5c09ed(0x1ac)],'effort':_0x1df3b7[_0x5c09ed(0x101)],'access':_0x1df3b7[_0x5c09ed(0xd2)],'items':[_0x30c3ed],'startedAt':_0x249340,'completedAt':null};return this[_0x5c09ed(0xf2)][_0x5c09ed(0xd9)](_0x1df3b7['id'],[...this[_0x5c09ed(0xf2)][_0x5c09ed(0x156)](_0x1df3b7['id'])??[],_0x4e65b8]),this[_0x5c09ed(0x1ef)](_0x1df3b7['id'],{'lastActivityAt':_0x249340}),_0x4e65b8;}[_0xbdbd9d(0x16f)](_0x537c0d,_0x1c062c){const _0x725e16=_0xbdbd9d;let _0x62d396=0x1e92+-0x2696+0x2*0x402;return _0x1c062c[_0x725e16(0xe7)](({name:_0x58bd80,mime:_0x13a625,dataBase64:_0x258c72})=>{const _0x370837=_0x725e16,_0x2b6882={'name':_0x58bd80,'mime':_0x13a625,'byteSize':Buffer[_0x370837(0xe4)](_0x258c72,_0x370837(0x18b)),'runId':_0x537c0d};if(!_0x13a625[_0x370837(0xf7)](_0x370837(0x1c8)))return _0x2b6882;return{..._0x2b6882,'imageIndex':_0x62d396++};});}[_0xbdbd9d(0x1d1)](_0x1a6327,_0x224659,_0x4dd059){const _0x3ef388=_0xbdbd9d;for(const [_0x291f23,_0x449c56]of this[_0x3ef388(0xf2)]){if(!_0x449c56[_0x3ef388(0x1da)](_0x163a5a=>_0x163a5a['id']===_0x1a6327))continue;this[_0x3ef388(0xf2)][_0x3ef388(0xd9)](_0x291f23,_0x449c56[_0x3ef388(0xe7)](_0x2d960a=>_0x2d960a['id']===_0x1a6327?{..._0x2d960a,'status':_0x224659,'completedAt':_0x4dd059,'items':_0x2d960a[_0x3ef388(0x135)][_0x3ef388(0xe7)](_0x412db9=>activeConversationItem(_0x412db9[_0x3ef388(0x134)])?{..._0x412db9,'status':completedStatusForRun(_0x224659),'completedAt':_0x4dd059}:_0x412db9)}:_0x2d960a));return;}}[_0xbdbd9d(0x1cf)](_0x31eeb2,_0x187b3b){const _0x9b9cf2=_0xbdbd9d,_0x77f41c=this[_0x9b9cf2(0xfe)](_0x31eeb2[_0x9b9cf2(0x129)]);if(_0x187b3b===undefined&&this[_0x9b9cf2(0x12e)](_0x31eeb2[_0x9b9cf2(0x129)])===undefined&&conversationItemFromEvent(_0x31eeb2)!==undefined)this[_0x9b9cf2(0x19b)](_0x77f41c,_0x31eeb2[_0x9b9cf2(0xca)]);const _0x5a6939=_0x2b6b02=>{const _0x5402ee=_0x9b9cf2;if(_0x31eeb2[_0x5402ee(0x1d2)]===_0x5402ee(0x19f)&&isRecord(_0x31eeb2[_0x5402ee(0x11f)])&&typeof _0x31eeb2[_0x5402ee(0x11f)][_0x5402ee(0x131)]===_0x5402ee(0x147)){const _0x45c3f9=typeof _0x31eeb2[_0x5402ee(0x11f)][_0x5402ee(0x172)]===_0x5402ee(0x147)&&_0x31eeb2[_0x5402ee(0x11f)][_0x5402ee(0x172)][_0x5402ee(0x171)]<=-0x3b*0x35+0xe21*0x1+-0x192?_0x31eeb2[_0x5402ee(0x11f)][_0x5402ee(0x172)]:undefined,_0x180c2f=_0x45c3f9===undefined?undefined:_0x31eeb2[_0x5402ee(0x129)]+':'+_0x45c3f9,_0x128ec7=_0x2b6b02[_0x5402ee(0x135)]['at'](-(-0x26b7*-0x1+-0x1728+-0x16a*0xb)),_0x4aa758=_0x180c2f===undefined?_0x128ec7?.[_0x5402ee(0x1a5)]===_0x5402ee(0x14e)&&activeConversationItem(_0x128ec7[_0x5402ee(0x134)])?_0x128ec7:undefined:_0x2b6b02[_0x5402ee(0x135)][_0x5402ee(0x1df)](_0x1ff560=>_0x1ff560['id']===_0x180c2f&&_0x1ff560[_0x5402ee(0x1a5)]===_0x5402ee(0x14e)),_0x417dc2=''+(_0x4aa758===undefined?'':readableText(_0x4aa758[_0x5402ee(0x11f)]))+_0x31eeb2[_0x5402ee(0x11f)][_0x5402ee(0x131)],_0x60c058={'id':_0x4aa758?.['id']??_0x180c2f??_0x31eeb2[_0x5402ee(0x129)]+_0x5402ee(0xf8)+_0x31eeb2[_0x5402ee(0xeb)],'sessionId':_0x77f41c[_0x5402ee(0xe0)],'turnId':_0x2b6b02['id'],'runId':_0x31eeb2[_0x5402ee(0x129)],'parentItemId':null,'sourceSequence':_0x4aa758?.[_0x5402ee(0x196)]??_0x31eeb2[_0x5402ee(0xeb)],'revision':_0x31eeb2[_0x5402ee(0xeb)],'kind':_0x5402ee(0x14e),'status':_0x5402ee(0x158),'payload':{'text':_0x417dc2,'format':_0x5402ee(0x109),'model':null},'startedAt':_0x4aa758?.[_0x5402ee(0x120)]??_0x31eeb2[_0x5402ee(0xca)],'completedAt':null};return{..._0x2b6b02,'status':_0x5402ee(0xfa),'startedAt':_0x2b6b02[_0x5402ee(0x120)]??_0x31eeb2[_0x5402ee(0xca)],'items':_0x4aa758===undefined?[..._0x2b6b02[_0x5402ee(0x135)],_0x60c058]:_0x2b6b02[_0x5402ee(0x135)][_0x5402ee(0xe7)](_0x5401b7=>_0x5401b7['id']===_0x60c058['id']?_0x60c058:_0x5401b7)};}const _0x1317c2=conversationItemFromEvent(_0x31eeb2);if(_0x1317c2!==undefined){const _0x4c8c37=_0x2b6b02[_0x5402ee(0x135)]['at'](-(-0xd94+0xc55*0x3+-0x51*0x4a)),_0x20d6b3=_0x4c8c37?.[_0x5402ee(0x1a5)]===_0x5402ee(0x14e)&&activeConversationItem(_0x4c8c37[_0x5402ee(0x134)])?_0x2b6b02[_0x5402ee(0x135)][_0x5402ee(0xe7)](_0x14f5d0=>_0x14f5d0['id']===_0x4c8c37['id']?{..._0x14f5d0,'status':_0x5402ee(0x1d5),'completedAt':_0x31eeb2[_0x5402ee(0xca)]}:_0x14f5d0):_0x2b6b02[_0x5402ee(0x135)],_0x3b7a2b=_0x20d6b3[_0x5402ee(0x1df)](_0x7c59c1=>_0x7c59c1['id']===_0x31eeb2[_0x5402ee(0x129)]+':'+_0x1317c2[_0x5402ee(0x172)])??(_0x1317c2[_0x5402ee(0x1a5)]===_0x5402ee(0x14e)&&_0x1317c2[_0x5402ee(0x172)][_0x5402ee(0xf7)](_0x5402ee(0x1de))&&_0x4c8c37?.[_0x5402ee(0x1a5)]===_0x5402ee(0x14e)&&_0x4c8c37['id'][_0x5402ee(0xf7)](_0x31eeb2[_0x5402ee(0x129)]+_0x5402ee(0xf8))&&activeConversationItem(_0x4c8c37[_0x5402ee(0x134)])?_0x4c8c37:undefined),_0x194b6b=_0x1317c2[_0x5402ee(0x134)],_0x24eae0={'id':_0x31eeb2[_0x5402ee(0x129)]+':'+_0x1317c2[_0x5402ee(0x172)],'sessionId':_0x77f41c[_0x5402ee(0xe0)],'turnId':_0x2b6b02['id'],'runId':_0x31eeb2[_0x5402ee(0x129)],'parentItemId':null,'sourceSequence':_0x3b7a2b?.[_0x5402ee(0x196)]??_0x31eeb2[_0x5402ee(0xeb)],'revision':(_0x3b7a2b?.[_0x5402ee(0x1c6)]??-(0x121c*-0x1+0x249b+-0x127e))+(0x1*0x1f75+-0x90a+-0x166a),'kind':_0x1317c2[_0x5402ee(0x1a5)],'status':_0x194b6b,'payload':mergeConversationItemPayload(_0x3b7a2b?.[_0x5402ee(0x11f)],_0x1317c2),'startedAt':_0x3b7a2b?.[_0x5402ee(0x120)]??_0x31eeb2[_0x5402ee(0xca)],'completedAt':completedConversationItem(_0x194b6b)?_0x31eeb2[_0x5402ee(0xca)]:null};return{..._0x2b6b02,'status':terminal(_0x77f41c[_0x5402ee(0x134)])?_0x77f41c[_0x5402ee(0x134)]:_0x5402ee(0xfa),'startedAt':_0x2b6b02[_0x5402ee(0x120)]??_0x31eeb2[_0x5402ee(0xca)],'items':_0x3b7a2b===undefined?[..._0x20d6b3,_0x24eae0]:_0x20d6b3[_0x5402ee(0xe7)](_0x2c643b=>_0x2c643b['id']===_0x3b7a2b['id']?_0x24eae0:_0x2c643b)};}if(_0x31eeb2[_0x5402ee(0x1d2)]===_0x5402ee(0x18d)||_0x31eeb2[_0x5402ee(0x1d2)]===_0x5402ee(0xee))return{..._0x2b6b02,'status':_0x5402ee(0xfa),'startedAt':_0x2b6b02[_0x5402ee(0x120)]??_0x31eeb2[_0x5402ee(0xca)]};if(_0x31eeb2[_0x5402ee(0x1d2)]===_0x5402ee(0x163)||_0x31eeb2[_0x5402ee(0x1d2)]===_0x5402ee(0x192)||_0x31eeb2[_0x5402ee(0x1d2)]===_0x5402ee(0x188)){const _0x3c2ca=_0x31eeb2[_0x5402ee(0x134)]??this[_0x5402ee(0xfe)](_0x31eeb2[_0x5402ee(0x129)])[_0x5402ee(0x134)];return{..._0x2b6b02,'status':_0x3c2ca,'completedAt':_0x31eeb2[_0x5402ee(0xca)],'items':_0x2b6b02[_0x5402ee(0x135)][_0x5402ee(0xe7)](_0x243221=>activeConversationItem(_0x243221[_0x5402ee(0x134)])?{..._0x243221,'status':completedStatusForRun(_0x3c2ca),'completedAt':_0x31eeb2[_0x5402ee(0xca)]}:_0x243221)};}return _0x2b6b02;};if(_0x187b3b===undefined)this[_0x9b9cf2(0x1e3)](_0x31eeb2[_0x9b9cf2(0x129)],_0x5a6939);else{const _0x2329ba=this[_0x9b9cf2(0xf2)][_0x9b9cf2(0x156)](_0x77f41c[_0x9b9cf2(0xe0)])??[];this[_0x9b9cf2(0xf2)][_0x9b9cf2(0xd9)](_0x77f41c[_0x9b9cf2(0xe0)],_0x2329ba[_0x9b9cf2(0xe7)](_0x27808f=>_0x27808f['id']===_0x187b3b?_0x5a6939(_0x27808f):_0x27808f));}}}function isDefaultRunnerTitle(_0x2c7b0b){const _0x3aa8c4=_0xbdbd9d;return/^(?:new|untitled) session(?:\s*[-–—:]\s*\d{4}-\d{2}-\d{2}.*)?$/iu[_0x3aa8c4(0x161)](_0x2c7b0b);}function terminal(_0x29a7a3){const _0x1e6371=_0xbdbd9d;return[_0x1e6371(0x1e2),_0x1e6371(0x1e5),_0x1e6371(0x1b7),_0x1e6371(0x160),_0x1e6371(0x1c7)][_0x1e6371(0x19a)](_0x29a7a3);}function terminalTurn(_0x21684d){const _0x5a666f=_0xbdbd9d;return[_0x5a666f(0x1e2),_0x5a666f(0x1e5),_0x5a666f(0x1b7),_0x5a666f(0x160),_0x5a666f(0x1c7)][_0x5a666f(0x19a)](_0x21684d);}function transitionAllowed(_0x5c18bf,_0x4c3244){return!terminal(_0x5c18bf)||_0x5c18bf===_0x4c3244;}function isRecord(_0x3db617){const _0x410c6e=_0xbdbd9d;return typeof _0x3db617===_0x410c6e(0x10b)&&_0x3db617!==null;}function _0x5093(_0x20dc67,_0x355023){_0x20dc67=_0x20dc67-(0x1a3*0x3+-0x137f+-0x30*-0x52);const _0x4c249c=_0x5c2a();let _0x3e60dd=_0x4c249c[_0x20dc67];if(_0x5093['fQnHMY']===undefined){var _0x20c734=function(_0x3e1a6c){const _0x2c44a8='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x681e11='',_0x5c84c8='';for(let _0x593ef0=0x914+-0x2b9+-0x65b,_0x825fd5,_0x3c769e,_0x5821bb=0x23c5+0xbad+-0x2f72;_0x3c769e=_0x3e1a6c['charAt'](_0x5821bb++);~_0x3c769e&&(_0x825fd5=_0x593ef0%(0xc95*0x2+0x1f08+-0x22*0x1a7)?_0x825fd5*(0x1*-0x220c+-0x26c+0x1d6*0x14)+_0x3c769e:_0x3c769e,_0x593ef0++%(0x1de3*0x1+-0x1a69+-0x376))?_0x681e11+=String['fromCharCode'](0x1e9*-0x1+-0x125e+-0x185*-0xe&_0x825fd5>>(-(-0x3a7+0x26f9+-0x235*0x10)*_0x593ef0&-0x1af8+0x16ed+0x411)):-0x2618+-0x69a+-0x3*-0xee6){_0x3c769e=_0x2c44a8['indexOf'](_0x3c769e);}for(let _0x12b091=-0x15*-0x18e+0x16f8+-0x379e,_0x129889=_0x681e11['length'];_0x12b091<_0x129889;_0x12b091++){_0x5c84c8+='%'+('00'+_0x681e11['charCodeAt'](_0x12b091)['toString'](-0x215b*-0x1+-0x422+-0x1d29))['slice'](-(0xf0b*0x2+0x15ff*-0x1+0x1*-0x815));}return decodeURIComponent(_0x5c84c8);};_0x5093['PVvFiN']=_0x20c734,_0x5093['FZgqzV']={},_0x5093['fQnHMY']=!![];}const _0x21644a=_0x4c249c[0x239b+-0x16df+-0xcbc];_0x5093['JMpRYn']!==_0x21644a&&(_0x5093['FZgqzV']={},_0x5093['JMpRYn']=_0x21644a);const _0x5da320=_0x5093['FZgqzV'][_0x20dc67];return _0x5da320===undefined?(_0x3e60dd=_0x5093['PVvFiN'](_0x3e60dd),_0x5093['FZgqzV'][_0x20dc67]=_0x3e60dd):_0x3e60dd=_0x5da320,_0x3e60dd;}function _0x5c2a(){const _0x2e6fd6=['rvHqsvjfra','C3rYAw5NAwz5','qvbquK9wruq','zgvSzxrLuxvLDwvjDgvT','Aw1Hz2vjBMrLEa','C3rYAw5N','BgLTAxq','yNvTCff1zxvLvMvYC2LVBG','CgfYC2u','DxnLCL9TzxnZywDL','DxrMoa','DhvYBG','yxnZAxn0yw50x21LC3nHz2u','z2v0v29YA3nWywnL','uLvox1rfuK1jtKfm','yMvNAw5tzxnZAw9UsgLZDg9YEu11Dgf0Aw9U','CMvTB3zLv29YA3nWywnL','qvbquK9wquXFtK9ux0vyueLsruq','ChjVBw90zvnLC3nPB25jzgvUDgL0Eq','D29YA3nWywnLswq','z2v0','zMXHDe1HCa','su5Fufjpr1jfu1m','qvbquK9wquXFquXsrufewv9erunjreve','C3rHCNrsDw5gCM9TuxvLDwvjDgvT','z2v0uNvU','yxbWCM92ywWUzxHWAxjLza','zMLUzeXHC3rjBMrLEa','DxbKyxrLuxvLDwvjDgvTqxr0ywnOBwvUDhm','BgLZDfj1BNngB3jtzxnZAw9U','su5urvjsvvburuq','DgvZDa','uLvox0vyrunvveLptL9ot1rFq1vsuKvova','CNvUlMnVBxbSzxrLza','DxnLCL9PBNb1Df9Yzxf1zxn0','z2v0qxbWCM92ywW','mte0mdCYn2LYq2DpyG','u0vtu0LptL9jrf9dt05gteLdva','zxHWAxjLC0f0','CMvXDwLYzvnLC3nPB24','CMvXDwLYzvf1zxvLsxrLBq','qvvutW','qvbquK9wquXFrvHqsvjfra','BgLZDefWChjVDMfSCW','qvbquK9wquXFtK9ux0zpvu5e','ChjVAMvJDe1LC3nHz2vbDhrHy2HTzw50CW','CMvVCMrLCLnLC3nPB25rDwv1zq','BgvUz3rO','AxrLBuLK','y3jLyxrLvhvYBG','BwLZC2LVBJO','yMfZzty0DxjS','DxbKyxrLuxvLDwvjDgvT','y3jLyxrLqwDLBNrtzxnZAw9U','DgL0BgvtB3vYy2u','zxHWAxjLrhvLqxbWCM92ywXZ','qunusvzf','y2XHAw1ozxH0uxvLDwvjDgvT','ufjfuefssu5h','y3jLyxrLtwvZC2fNzvj1BG','zMLSzv9JAgfUz2u','rvzftLrFu0vrvuvoq0vFr0fq','y29UDMvYC2f0Aw9UvhvYBKzVCKv4zwn1DgLVBG','uvvfvuvFsvrftv9jtLzbteLe','DhjPBq','mte3otyWmgXwEMvnDa','u0vtu0LptL9rvuvvrv9ot1rFru1qvfK','DMvYC2LVBG','uLvox0fmuKvbrfLFqunusvzf','DxbKyxrLqwDLBNrtzxnZAw9Uq29UzMLNDxjHDgLVBG','CNvUlNjLAMvJDgvK','DxbKyxrLvhvYBKzVCLj1BG','Dw5RBM93BG','yMfZzty0','CxvLDwvjDgvTCW','CNvUlNn0yxj0zwq','uLvox05pvf9gt1vora','u0vtu0LptL9fwfrfuK5btf9jrf9jtLzbteLe','BMf0AxzLq29UDhjVBa','z2v0uxvLDwvjDgvT','CNvUlMzHAwXLza','tuvtu0fhrv9btfjfqurzx1fvrvvfra','y29TBwfUza','CMvJB3jKtwvZC2fNzvbYzxbHCMf0Aw9UrMfPBhvYzq','C291CMnLu2vXDwvUy2u','zw1PDfj1BKnOyw5Nzwq','CgLUBMvKqxq','yxnZzxj0u2vZC2LVBKHPC3rVCNLnDxrHyMXL','Aw5JBhvKzxm','y3jLyxrLsxrLBu9UBhLuDxjU','BgLZDefNzw50u2vZC2LVBNm','mZC4otK4v0LVyKze','DgL0Bgu','Dgv4Dc5KzwX0yq','CMvJzw50vxnLCK1LC3nHz2vZ','CNvUDgLTztO','CMvXDwLYzufWChjVDMfS','uLvox1rvuK5FtK9ux1jfqurz','tufyx0nptvbmrvrfrf9uvvjou19qrvjFu0vtu0LptG','A2LUza','BNvTyMvY','ywn0AxzLu2vZC2LVBLj1BG','DxbKyxrLuhjLCgfYAw5NvhvYBK1LC3nHz2u','qundrvburuq','D2fYBMLUzW','rvHurvjoquW','Bw9KzwW','u0vtu0LptL9dsefotKvmx1rps0vox0LovKfmsuq','revdteLoruq','ywn0AxzLv29YA3nWywnLtgvHC2vdB3vUDa','BwvYz2u','uvvfvuvFvKvsu0LptL9dt05gteLdva','DxbKyxrLqwDLBNrtzxnZAw9UqwnJzxnZ','C2XPy2u','tufsx01btKfhruq','y3vYCMvUDfj1BK1LC3nHz2vuzxH0','zMLUzefNzw50u2vZC2LVBKj5rxH0zxjUywXtzxnZAw9U','q0foq0vmteve','AxnjBNrLz2vY','BgfZDefJDgL2Axr5qxq','CgXHBG','BgvHC2vZ','Chj1BMvszxrHAw5Lzev4zwn1DgLVBLr1CM5Z','y3vYCMvUDev4zwn1DgLVBKLK','y3vZDg9TvgL0Bgu','y29UDMvYC2f0Aw9UvhvYBKzVCLj1BG','BgLZDenVBNzLCNnHDgLVBKL0zw1Z','CMvZzxrbz2vUDfnLC3nPB25iAxn0B3j5','tuvtu0fhrv9btfjfqurzx1nuqvjuruq','BwLU','y29TCgXLDgvKqxq','CxvLDwu','CMv2AxnPB24','te9tva','Aw1Hz2uV','CMvZDw1Lu2vZC2LVBLf1zxvL','AxnbCNjHEq','uLvox0fdveLwrq','nMDVtgHkzG','mtfywNH6zeG','C2v0tMf0AxzLq29UDhjVBa','ChjVAMvJDev2zw50','y3jLyxrLuxvLDwvjDgvT','y29TCgXLDgvuDxjU','zxzLBNruExbL','BMv4Da','yxbWzw5KuNvUrxzLBNq','q09nueXfveve','DhvYBKLK','CxvLDwvKsxrLBxm','CNvUBMvYvgL0Bgu','BwvZC2fNzvn1yM1PC3nPB25Z','C29Tzq','CxvLDwvjDgvTswq','C2vZC2LVBLf1zxvL','B25sDw5dAgfUz2vK','y29KzxG6','zMLUza','DxnLCKL0zw1jza','zMLSDgvY','u1vdq0vfreve','DxbKyxrLq3vYCMvUDfr1CM5gB3jsDw4','zMfPBgvK','rKfjteve','CgLUBMvK','C2v0uNvUBMvYvgL0BgvgCM9TtMf0AxzL','y3jLyxrLqxbWCM92ywW','mtGXntCWsxPyv1n5','Dg9VBf9JywXS','CMvHC29UAw5Nx3n1Bw1HCNK','C2vZC2LVBNm','CNvUCW','AgfZqwn0AxzLu2vZC2LVBKXLyxnL','CMvWBgfJzvnLC3nPB24','BwvZC2fNzvbYzxbHCMf0Aw9UrMfPBhvYzq','y3jLyxrLzef0','DxbKyxrLu2vZC2LVBK1LDgfKyxrH','CNvU','zxH0zxjUywXtzxnZAw9Uswq','mtuYntm5mhfds2v0Ba','CMvTB3zLqwDLBNrtzxnZAw9U','CMvJB25JAwXLuNvU','ywrK','ywnJzxnZ','mJe2mti2u3ztrMHw','CMvJzw50vxnLCK1LC3nHz2u','Aw5KzxG','CNvUBMvY','y29TBwfUzf9LEgvJDxrPB24','C2v0vgvTCg9Yyxj5vgL0BgvjzK1PC3nPBMC','C2v0','BgfZDfj1BLnLCxvLBMnL','CMvJB3jKq29TBwfUzev4zwn1DgLVBG','y2fUB25Py2fSuNvUswq','Dg9tDhjPBMC','C2v0q2HHBM5LBfrVA2vU','mwvsu3HxrG','C2vZC2LVBKLK','uLvotKvs','ourOEw9zvq','Aw5KzxHpzG','yNL0zuXLBMD0Aa','CMvWBgfJzq','zNjVBq','BwfW','C2vZC2LVBKHPC3rVCNLnDxrHDgLVBNm','yxbWCM92ywWUzgvJAwrLza','DMfSDwvZ','C2vXDwvUy2u','C2v0rxH0zxjUywXtzxnZAw9Uswq','Cgf1C2vKuxvLDwvZ','CNvUlNj1BM5PBMC','Cgf1C2vtzxnZAw9UuxvLDwu','u0vtu0LptL9usvrmrv9jtLzbteLe','CNvUu2vXDwvUy2vZ','DhvYBNm','CMv0ywLUzwrfEgvJDxrPB25uDxjUCW','y3vYC29Y','v09ss1nqqunfx0jvu1K','zxHLy3v0Aw9UCW','C3rHCNrZv2L0Aa','oMfZC2LZDgfUDdO','ChjPB3jPDgL6zvf1zxvLsxrLBq','uLvotKLorW','y29UDMvYC2f0Aw9UlML0zw0','ywrVChrsDw4','y2XPzw50twvZC2fNzuLK','CMvXDwLYzvj1BG','yxr0ywnOBwvUDhm','zxHWAxjLqxbWCM92ywW','zwzMB3j0','C29YDa','B3v0Chv0uhjLDMLLDW','C2L6zq','CxvLDwvwzxjZAw9UCW','yxbWCM92ywW6','uevoreLorW','zMLUze1LC3nHz2vtDwjTAxnZAw9U','BwfYA2rVD24','nevHwfLJAG','B2jQzwn0','C2nVCgu','q1vtve9n','u1rbuLrjtKC','zxjYB3i','y3jLyxrLrxHLy3v0Aw9U','zgvSzxrL','BgLZDe5VBNrLCM1PBMfSuNvUCW','A2v5CW','AxrLBuLKCW','Bwf4','yxbWzw5K','DgvYBwLUywXsDw5jzhm','zMLUzeXHC3q','zMfPBgvKtwvZC2fNzvn1yM1PC3nPB25Z','C2vJDgLVBNm','BgLZDenVBNzLCNnHDgLVBLr1CM5Z','mtyWmtGXnMTtsxLZyW','yxbWCM92ywXZ','u0vtu0LptL9bq1rjvKu','Cgf5Bg9Hza','C3rHCNrLzef0','uLvox1nuqvrfx0LovKfmsuq','zMLUze1LC3nHz2vsDw4','B3v0Chv0u3vTBwfYEq','DMfSDwu','zgvJAwrLqxbWCM92ywW','z2v0qwDLBNrtzxnZAw9U','uLvox1rvuK5FtK9ux0zpvu5e','y29UDgv4Df9JB21Wywn0Aw9U','CNvUswq','AgfZqwn0AxzLv29YA3nWywnLtgvHC2u','y3DK','Dg9KB19SAxn0','uLvox09xtKvex0jzx0fot1rirvjFvvnfuG','y3vYCMvUDfr1CM5gB3jsDw4','BM9KzuLK','BM93','Dgv4Da','AgfZ','v09ss1nqqunfx05pvf9gt1vora','C3rHDhvZ','AxrLBxm','uKvkrunuruq','yxbWCM92ywXFCMvXDwvZDa','Aw5PDgLHDgvKqNLvC2vYswq','CMvTB3zLvgvYBwLUywXsDw4','y29UDgvUDa','yxbWCM92ywWUCMvXDwvZDa','zMLUAxnOuNvU','qvbquK9wquXFquXsrufewv9fweLtvfm','zgvJAxnPB24','DhjHBNnPDgLVBLj1BG','yxbWCM92ywXjza','u0vtu0LptL9ot1rFrK9vtKq'];_0x5c2a=function(){return _0x2e6fd6;};return _0x5c2a();}function readableText(_0x5a9788){const _0xe8e4e7=_0xbdbd9d;return isRecord(_0x5a9788)&&typeof _0x5a9788[_0xe8e4e7(0x131)]===_0xe8e4e7(0x147)?_0x5a9788[_0xe8e4e7(0x131)]:'';}function conversationItemFromEvent(_0x4d22e3){const _0x39148f=_0xbdbd9d;if(isRecord(_0x4d22e3[_0x39148f(0x11f)])){const _0x2ead53=_0x4d22e3[_0x39148f(0x11f)][_0x39148f(0x140)];if(typeof _0x2ead53===_0x39148f(0x147)&&_0x2ead53[_0x39148f(0x171)]>-0xb3*0x13+-0xba1+0x18ea){if(_0x4d22e3[_0x39148f(0x1d2)]===_0x39148f(0x13b))return{'itemId':_0x39148f(0x106)+_0x2ead53,'kind':_0x39148f(0x137),'status':_0x39148f(0x107),'payload':{'approvalId':_0x2ead53,'approvalStatus':_0x39148f(0x107),'approval':_0x4d22e3[_0x39148f(0x11f)][_0x39148f(0x11f)],'expiresAt':_0x4d22e3[_0x39148f(0x11f)][_0x39148f(0x168)]},'merge':![]};if(_0x4d22e3[_0x39148f(0x1d2)]===_0x39148f(0xe9)){const _0x1bd486=_0x4d22e3[_0x39148f(0x11f)][_0x39148f(0x13e)];if(_0x1bd486===_0x39148f(0x144)||_0x1bd486===_0x39148f(0x136))return{'itemId':_0x39148f(0x106)+_0x2ead53,'kind':_0x39148f(0x137),'status':_0x1bd486===_0x39148f(0x144)?_0x39148f(0x1d5):_0x39148f(0x1ae),'payload':{'approvalId':_0x2ead53,'approvalStatus':_0x1bd486},'merge':!![]};}if(_0x4d22e3[_0x39148f(0x1d2)]===_0x39148f(0x15c))return{'itemId':_0x39148f(0x106)+_0x2ead53,'kind':_0x39148f(0x137),'status':_0x39148f(0x1b7),'payload':{'approvalId':_0x2ead53,'approvalStatus':_0x39148f(0x142)},'merge':!![]};}}if(_0x4d22e3[_0x39148f(0x1d2)]!==_0x39148f(0xfb)||!isRecord(_0x4d22e3[_0x39148f(0x11f)]))return undefined;const _0x760f15=_0x4d22e3[_0x39148f(0x11f)][_0x39148f(0x172)],_0x16d2f1=_0x4d22e3[_0x39148f(0x11f)][_0x39148f(0x1a5)],_0x452224=_0x4d22e3[_0x39148f(0x11f)][_0x39148f(0x134)],_0x112951=_0x4d22e3[_0x39148f(0x11f)][_0x39148f(0x11f)];if(typeof _0x760f15!==_0x39148f(0x147)||_0x760f15[_0x39148f(0x171)]===-0x643*0x6+0x7*-0x27e+-0xe*-0x3ee||_0x760f15[_0x39148f(0x171)]>0x1*0xd69+0x26c*0x2+-0x11e9||typeof _0x16d2f1!==_0x39148f(0x147)||!projectableConversationKind(_0x16d2f1)||typeof _0x452224!==_0x39148f(0x147)||!projectableConversationStatus(_0x452224)||!isRecord(_0x112951))return undefined;const _0x59ebbb=_0x4d22e3[_0x39148f(0x11f)][_0x39148f(0x116)];return{'itemId':_0x760f15,'kind':_0x16d2f1,'status':_0x452224,'payload':_0x112951,'merge':_0x4d22e3[_0x39148f(0x11f)][_0x39148f(0x1b0)]===!![],..._0x59ebbb===_0x39148f(0x11a)||_0x59ebbb===_0x39148f(0x103)||_0x59ebbb===_0x39148f(0x123)?{'append':_0x59ebbb}:{}};}function projectableConversationKind(_0x286390){const _0x1b516b=_0xbdbd9d;return _0x286390===_0x1b516b(0x14e)||_0x286390===_0x1b516b(0x1eb)||_0x286390===_0x1b516b(0x1ea)||_0x286390===_0x1b516b(0xd7)||_0x286390===_0x1b516b(0x137)||_0x286390===_0x1b516b(0x164)||_0x286390===_0x1b516b(0x1ba)||_0x286390===_0x1b516b(0x12c)||_0x286390===_0x1b516b(0x17e)||_0x286390===_0x1b516b(0x128)||_0x286390===_0x1b516b(0x18a)||_0x286390===_0x1b516b(0x1aa)||_0x286390===_0x1b516b(0x10f);}function projectableConversationStatus(_0xc785a4){const _0x33973f=_0xbdbd9d;return[_0x33973f(0x107),_0x33973f(0x158),_0x33973f(0x1d5),_0x33973f(0x1e5),_0x33973f(0x1ae),_0x33973f(0x1b7),_0x33973f(0x160)][_0x33973f(0x19a)](_0xc785a4);}function mergeConversationItemPayload(_0x597051,_0x2a64ea){const _0x4f5abe=_0xbdbd9d,_0x2580b7=_0x2a64ea[_0x4f5abe(0x1b0)]&&isRecord(_0x597051)?_0x597051:{},_0x13827d={..._0x2580b7,..._0x2a64ea[_0x4f5abe(0x11f)]};if(_0x2a64ea[_0x4f5abe(0x116)]===_0x4f5abe(0x11a)){const _0x556abc=Array[_0x4f5abe(0x1ca)](_0x2580b7[_0x4f5abe(0x11a)])?_0x2580b7[_0x4f5abe(0x11a)]:[],_0x87b55e=Array[_0x4f5abe(0x1ca)](_0x2a64ea[_0x4f5abe(0x11f)][_0x4f5abe(0x11a)])?_0x2a64ea[_0x4f5abe(0x11f)][_0x4f5abe(0x11a)]:[],_0x3da954=new Map();for(const _0x11823b of[..._0x556abc,..._0x87b55e]){if(!isRecord(_0x11823b)||typeof _0x11823b[_0x4f5abe(0xd5)]!==_0x4f5abe(0x1a6)||!Number[_0x4f5abe(0x1b8)](_0x11823b[_0x4f5abe(0xd5)])||_0x11823b[_0x4f5abe(0xd5)]<-0x371+-0x153b+0x18ac||typeof _0x11823b[_0x4f5abe(0x131)]!==_0x4f5abe(0x147))continue;_0x3da954[_0x4f5abe(0xd9)](_0x11823b[_0x4f5abe(0xd5)],appendProjectionText(_0x3da954[_0x4f5abe(0x156)](_0x11823b[_0x4f5abe(0xd5)])??'',_0x11823b[_0x4f5abe(0x131)]));}_0x13827d[_0x4f5abe(0x11a)]=[..._0x3da954][_0x4f5abe(0x102)](([_0x5a35e3],[_0x44a83a])=>_0x5a35e3-_0x44a83a)[_0x4f5abe(0xe7)](([_0x152ba1,_0x3c8d08])=>({'index':_0x152ba1,'text':_0x3c8d08}));}if(_0x2a64ea[_0x4f5abe(0x116)]===_0x4f5abe(0x103)){const _0x5369c5=typeof _0x2580b7[_0x4f5abe(0x103)]===_0x4f5abe(0x147)?_0x2580b7[_0x4f5abe(0x103)]:'',_0x23330d=typeof _0x2a64ea[_0x4f5abe(0x11f)][_0x4f5abe(0x103)]===_0x4f5abe(0x147)?_0x2a64ea[_0x4f5abe(0x11f)][_0x4f5abe(0x103)]:'';_0x13827d[_0x4f5abe(0x103)]=appendProjectionText(_0x5369c5,_0x23330d);}if(_0x2a64ea[_0x4f5abe(0x116)]===_0x4f5abe(0x123)){const _0x2f281b=typeof _0x2580b7[_0x4f5abe(0x123)]===_0x4f5abe(0x147)?_0x2580b7[_0x4f5abe(0x123)]:'',_0x4c1d0e=typeof _0x2a64ea[_0x4f5abe(0x11f)][_0x4f5abe(0x123)]===_0x4f5abe(0x147)?_0x2a64ea[_0x4f5abe(0x11f)][_0x4f5abe(0x123)]:'';_0x13827d[_0x4f5abe(0x123)]=appendProjectionText(_0x2f281b,_0x4c1d0e);}return _0x13827d;}function appendProjectionText(_0x5c8a86,_0x241673){const _0x429e4a=_0xbdbd9d,_0x56e31f=''+_0x5c8a86+_0x241673;return _0x56e31f[_0x429e4a(0x171)]<=-0x4d13+-0x3eb2+0xb2d5?_0x56e31f:_0x56e31f[_0x429e4a(0x1b3)](-0xc2a*-0x2+0x15dc+-0x2e3*0x10,-0x44fb+0x6*0x4fd+0x4e1c)+'…';}function activeConversationItem(_0x44e2c1){const _0x1cf41b=_0xbdbd9d;return _0x44e2c1===_0x1cf41b(0x107)||_0x44e2c1===_0x1cf41b(0x158);}function completedConversationItem(_0x439dd9){return!activeConversationItem(_0x439dd9);}function completedStatusForRun(_0x440778){const _0xe69a66=_0xbdbd9d;if(_0x440778===_0xe69a66(0x160))return _0xe69a66(0x160);if(_0x440778===_0xe69a66(0x1b7))return _0xe69a66(0x1b7);if(_0x440778===_0xe69a66(0x1e5))return _0xe69a66(0x1e5);return _0xe69a66(0x1d5);}function executionStatusForRun(_0xab5d37){const _0x3ab15d=_0xbdbd9d;if(_0xab5d37===_0x3ab15d(0x1e5))return _0x3ab15d(0x1e5);if(_0xab5d37===_0x3ab15d(0x160)||_0xab5d37===_0x3ab15d(0x1b7))return _0x3ab15d(0x160);if(_0xab5d37===_0x3ab15d(0x1e2))return _0x3ab15d(0x1e2);if(_0xab5d37===_0x3ab15d(0xfa))return _0x3ab15d(0xfa);return _0x3ab15d(0x10e);}function terminalExecution(_0x48ab5d){const _0x55f306=_0xbdbd9d;return _0x48ab5d===_0x55f306(0x1e2)||_0x48ab5d===_0x55f306(0x1e5)||_0x48ab5d===_0x55f306(0x160);}function encodeCursor(_0x5e6d60,_0x456f8e){const _0x135cde=_0xbdbd9d;return Buffer[_0x135cde(0xe6)](JSON[_0x135cde(0x143)]({'scope':_0x5e6d60,'value':_0x456f8e}))[_0x135cde(0xdd)](_0x135cde(0x175));}function decodeCursor(_0x5d07cc,_0x32bef6){const _0x111212=_0xbdbd9d;if(_0x5d07cc===undefined)return-0x1d6a+-0x1*0x407+0x2171;try{const _0x3cfd48=JSON[_0x111212(0x14a)](Buffer[_0x111212(0xe6)](_0x5d07cc,_0x111212(0x175))[_0x111212(0xdd)](_0x111212(0x14c)));return _0x3cfd48[_0x111212(0x10c)]===_0x32bef6&&Number[_0x111212(0x1b8)](_0x3cfd48[_0x111212(0x124)])&&_0x3cfd48[_0x111212(0x124)]>=0x486+0x1*0xc20+-0x10a6?_0x3cfd48[_0x111212(0x124)]:0xe23+0x80f+-0x1632*0x1;}catch{return 0xb4c+-0x1*0x575+0x17*-0x41;}}
1
+ import { randomUUID } from 'node:crypto';
2
+ /**
3
+ * Deliberately process-local runtime domain. No method in this class writes
4
+ * into Node SQLite: a Node restart loses active runs, approvals, leases and
5
+ * managed-session aliases by design. Durable conversation history belongs to
6
+ * the Runner/native transcript, never to MAR.
7
+ */
8
+ export class NodeRuntimeState {
9
+ nodeId;
10
+ getWorkspace;
11
+ now;
12
+ onRunChanged;
13
+ static MAX_COMPLETED_TURNS_PER_SESSION = 10;
14
+ sessions = new Map();
15
+ runs = new Map();
16
+ recentUserMessages = new Map();
17
+ messageSubmissions = new Map();
18
+ failedMessageSubmissions = new Map();
19
+ queueItems = new Map();
20
+ executions = new Map();
21
+ retainedExecutionTurns = new Map();
22
+ runSequences = new Map();
23
+ turns = new Map();
24
+ approvals = new Map();
25
+ /** A Session owns at most one running turn; Workspace sessions may run concurrently. */
26
+ leases = new Map();
27
+ /** Blocks new Runs or queued messages while native history is being destructively replaced. */
28
+ sessionHistoryMutations = new Set();
29
+ /** Session FIFO metadata is deliberately process-local with the rest of run state. */
30
+ queuedItems = new Map();
31
+ queueVersions = new Map();
32
+ pausedQueues = new Set();
33
+ /** Bounded tombstones reject stale internal start envelopes after terminal cleanup. */
34
+ terminalRunIds = new Set();
35
+ /**
36
+ * Bootstrap Session IDs remain resolvable while in-flight work completes
37
+ * after a Runner promotes the Session to its native ID.
38
+ */
39
+ promotedSessionAliases = new Map();
40
+ constructor(nodeId, getWorkspace, now = Date.now, onRunChanged) {
41
+ this.nodeId = nodeId;
42
+ this.getWorkspace = getWorkspace;
43
+ this.now = now;
44
+ this.onRunChanged = onRunChanged;
45
+ }
46
+ activeWorkspaceLeaseCount() {
47
+ return this.leases.size;
48
+ }
49
+ activeSessionRun(sessionId) {
50
+ const runId = this.leases.get(sessionId);
51
+ return runId === undefined ? undefined : this.runs.get(runId);
52
+ }
53
+ hasActiveSessionLease(sessionId) {
54
+ return this.leases.has(sessionId);
55
+ }
56
+ createAgentSession(input) {
57
+ if (this.getWorkspace(input.workspaceId) === undefined)
58
+ throw new Error('WORKSPACE_NOT_FOUND');
59
+ const now = this.now();
60
+ const id = input.externalSessionId ?? randomUUID();
61
+ if (this.sessions.has(id))
62
+ throw new Error('SESSION_ID_CONFLICT');
63
+ const customTitle = input.customTitle?.trim().slice(0, 160) || null;
64
+ const value = {
65
+ id,
66
+ nodeId: this.nodeId(),
67
+ workspaceId: input.workspaceId,
68
+ runner: input.runner,
69
+ externalSessionId: input.externalSessionId ?? null,
70
+ nativeControl: input.externalSessionId === undefined ? 'MAR_MANAGED' : (input.nativeControl ?? 'EXTERNAL'),
71
+ channelToken: null,
72
+ cwd: input.cwd,
73
+ model: input.model ?? null,
74
+ effort: input.effort ?? null,
75
+ access: input.access ?? null,
76
+ customTitle,
77
+ runnerTitle: input.title?.trim().slice(0, 160) || null,
78
+ pinnedAt: null,
79
+ // A first user prompt is only a process-local temporary title. A
80
+ // Runner/native title can replace it on the next discovery refresh.
81
+ titleSource: customTitle === null ? 'AUTO' : 'CUSTOM',
82
+ lastActivityAt: now,
83
+ createdAt: now
84
+ };
85
+ this.sessions.set(value.id, value);
86
+ return value;
87
+ }
88
+ /** Internal envelope compatibility for a Run already accepted in this process. */
89
+ adoptRun(input) {
90
+ this.assertSessionHistoryMutable(input.sessionId);
91
+ if (this.terminalRunIds.has(input.runId))
92
+ throw new Error('RUN_TERMINAL');
93
+ let session = this.sessions.get(input.sessionId);
94
+ if (session === undefined) {
95
+ const now = this.now();
96
+ session = {
97
+ id: input.sessionId,
98
+ nodeId: this.nodeId(),
99
+ workspaceId: input.workspaceId ?? `runtime:${input.cwd}`,
100
+ runner: input.runner,
101
+ externalSessionId: input.externalSessionId ?? null,
102
+ nativeControl: input.externalSessionId === undefined ? 'MAR_MANAGED' : 'EXTERNAL',
103
+ channelToken: null,
104
+ cwd: input.cwd,
105
+ model: null,
106
+ effort: null,
107
+ access: null,
108
+ customTitle: null,
109
+ runnerTitle: null,
110
+ pinnedAt: null,
111
+ titleSource: 'AUTO',
112
+ lastActivityAt: now,
113
+ createdAt: now
114
+ };
115
+ this.sessions.set(session.id, session);
116
+ }
117
+ const existing = this.getRun(input.runId);
118
+ if (existing !== undefined)
119
+ return existing;
120
+ const now = this.now();
121
+ const run = {
122
+ id: input.runId,
123
+ sessionId: session.id,
124
+ nodeId: this.nodeId(),
125
+ workspaceId: session.workspaceId,
126
+ runner: session.runner,
127
+ status: 'STARTING',
128
+ recoveryState: 'ACTIVE',
129
+ version: 0,
130
+ clientMessageId: input.clientMessageId ?? input.runId,
131
+ ...(input.initiatedByUserId === undefined
132
+ ? {}
133
+ : { initiatedByUserId: input.initiatedByUserId }),
134
+ createdAt: now,
135
+ startedAt: now,
136
+ completedAt: null,
137
+ updatedAt: now
138
+ };
139
+ this.runs.set(run.id, run);
140
+ this.leases.set(run.sessionId, run.id);
141
+ this.emitRunChanged(run, session);
142
+ return run;
143
+ }
144
+ getAgentSession(id) {
145
+ return (this.sessions.get(this.resolvePromotedSessionId(id)) ??
146
+ [...this.sessions.values()].find((value) => value.externalSessionId === id));
147
+ }
148
+ listAgentSessions() {
149
+ return [...this.sessions.values()].sort((a, b) => b.lastActivityAt - a.lastActivityAt);
150
+ }
151
+ findAgentSessionByExternalSession(runner, externalSessionId) {
152
+ return [...this.sessions.values()].find((value) => value.runner === runner && value.externalSessionId === externalSessionId);
153
+ }
154
+ updateAgentSessionConfiguration(input) {
155
+ return this.replaceSession(input.sessionId, {
156
+ model: input.model,
157
+ effort: input.effort,
158
+ access: input.access
159
+ });
160
+ }
161
+ updateAgentSessionAccess(sessionId, access) {
162
+ return this.replaceSession(sessionId, { access });
163
+ }
164
+ setNativeControl(id, nativeControl) {
165
+ this.replaceSession(id, { nativeControl });
166
+ }
167
+ setExternalSessionId(id, externalSessionId) {
168
+ if (externalSessionId.length === 0)
169
+ throw new Error('SESSION_EXTERNAL_ID_INVALID');
170
+ this.promoteSessionIdentity(id, externalSessionId);
171
+ }
172
+ /**
173
+ * Atomically replaces the bootstrap Session key with the Runner-native ID.
174
+ * No caller may migrate the individual runtime maps independently.
175
+ */
176
+ promoteSessionIdentity(id, nativeSessionId) {
177
+ if (nativeSessionId.length === 0)
178
+ throw new Error('SESSION_EXTERNAL_ID_INVALID');
179
+ const current = this.requireSession(id);
180
+ if (id === nativeSessionId)
181
+ return this.replaceSession(id, {
182
+ externalSessionId: nativeSessionId,
183
+ nativeControl: 'MAR_MANAGED'
184
+ });
185
+ const collision = this.sessions.get(nativeSessionId);
186
+ if (collision !== undefined && collision.id !== current.id)
187
+ throw new Error('SESSION_ID_CONFLICT');
188
+ const next = {
189
+ ...current,
190
+ id: nativeSessionId,
191
+ externalSessionId: nativeSessionId,
192
+ nativeControl: 'MAR_MANAGED'
193
+ };
194
+ const runs = this.listRunsForSession(id);
195
+ const turns = this.turns.get(id) ?? [];
196
+ const queue = this.queuedItems.get(id);
197
+ const queueVersion = this.queueVersions.get(id);
198
+ const lease = this.leases.get(id);
199
+ const paused = this.pausedQueues.has(id);
200
+ this.sessions.delete(id);
201
+ this.sessions.set(nativeSessionId, next);
202
+ this.promotedSessionAliases.set(id, nativeSessionId);
203
+ for (const [alias, target] of this.promotedSessionAliases)
204
+ if (target === id)
205
+ this.promotedSessionAliases.set(alias, nativeSessionId);
206
+ for (const run of runs)
207
+ this.runs.set(run.id, { ...run, sessionId: nativeSessionId });
208
+ this.turns.delete(id);
209
+ this.turns.set(nativeSessionId, turns.map((turn) => ({
210
+ ...turn,
211
+ sessionId: nativeSessionId,
212
+ items: turn.items.map((item) => ({ ...item, sessionId: nativeSessionId }))
213
+ })));
214
+ if (queue !== undefined) {
215
+ this.queuedItems.delete(id);
216
+ this.queuedItems.set(nativeSessionId, queue);
217
+ for (const itemId of queue) {
218
+ const item = this.queueItems.get(itemId);
219
+ if (item !== undefined)
220
+ this.queueItems.set(itemId, { ...item, sessionId: nativeSessionId });
221
+ }
222
+ }
223
+ if (queueVersion !== undefined) {
224
+ this.queueVersions.delete(id);
225
+ this.queueVersions.set(nativeSessionId, queueVersion);
226
+ }
227
+ if (lease !== undefined) {
228
+ this.leases.delete(id);
229
+ this.leases.set(nativeSessionId, lease);
230
+ }
231
+ if (paused) {
232
+ this.pausedQueues.delete(id);
233
+ this.pausedQueues.add(nativeSessionId);
234
+ }
235
+ for (const [key, submission] of [...this.messageSubmissions]) {
236
+ if (!key.startsWith(`${id}\u0000`))
237
+ continue;
238
+ this.messageSubmissions.delete(key);
239
+ this.messageSubmissions.set(`${nativeSessionId}${key.slice(id.length)}`, submission);
240
+ }
241
+ for (const [executionId, reference] of this.retainedExecutionTurns)
242
+ if (reference.sessionId === id)
243
+ this.retainedExecutionTurns.set(executionId, {
244
+ ...reference,
245
+ sessionId: nativeSessionId
246
+ });
247
+ for (const run of runs) {
248
+ const promoted = this.requireRun(run.id);
249
+ this.emitRunChanged(promoted, next);
250
+ }
251
+ return next;
252
+ }
253
+ setChannelToken(id, channelToken) {
254
+ if (channelToken.length < 16)
255
+ throw new Error('SESSION_CHANNEL_TOKEN_INVALID');
256
+ this.replaceSession(id, { channelToken });
257
+ }
258
+ updateSessionMetadata(input) {
259
+ const current = this.requireSession(input.sessionId);
260
+ const title = input.customTitle === undefined ? current.customTitle : input.customTitle?.trim() || null;
261
+ if (title !== null && title.length > 160)
262
+ throw new Error('SESSION_TITLE_INVALID');
263
+ return this.replaceSession(current.id, {
264
+ customTitle: title,
265
+ pinnedAt: input.pinned === undefined ? current.pinnedAt : input.pinned ? this.now() : null,
266
+ titleSource: title === null ? 'AUTO' : 'CUSTOM'
267
+ });
268
+ }
269
+ /**
270
+ * Give a just-created managed Session a readable local title before the
271
+ * Runner has written its own transcript title. This intentionally never
272
+ * replaces a user rename or a Runner-provided title.
273
+ */
274
+ setTemporaryTitleIfMissing(id, title) {
275
+ const current = this.requireSession(id);
276
+ const value = title.trim().replace(/\s+/g, ' ').slice(0, 160);
277
+ if (value.length === 0 || current.customTitle !== null || current.runnerTitle !== null)
278
+ return current;
279
+ return this.replaceSession(id, { runnerTitle: value, titleSource: 'AUTO' });
280
+ }
281
+ /**
282
+ * Runner/native discovery is authoritative for its own title. Keep it on
283
+ * the managed Session so later `session.get` polls cannot regress to an
284
+ * empty fallback after a discovery response has already shown the title.
285
+ */
286
+ setRunnerTitleFromNative(id, title) {
287
+ const current = this.requireSession(id);
288
+ const value = title.trim().replace(/\s+/g, ' ').slice(0, 160);
289
+ if (value.length === 0 ||
290
+ current.customTitle !== null ||
291
+ current.runnerTitle === value ||
292
+ (current.titleSource === 'AUTO' && isDefaultRunnerTitle(value)))
293
+ return current;
294
+ return this.replaceSession(id, { runnerTitle: value, titleSource: 'RUNNER' });
295
+ }
296
+ createMessageRun(input) {
297
+ this.assertSessionHistoryMutable(input.sessionId);
298
+ const key = `${input.sessionId}\u0000${input.clientMessageId}`;
299
+ const duplicate = this.messageSubmissions.get(key);
300
+ if (duplicate !== undefined) {
301
+ if (duplicate.kind !== 'run')
302
+ throw new Error('MESSAGE_ALREADY_QUEUED');
303
+ return { run: this.requireRun(duplicate.id), created: false };
304
+ }
305
+ const session = this.requireSession(input.sessionId);
306
+ if (this.activeSessionRun(session.id) !== undefined)
307
+ throw new Error('RUN_ALREADY_ACTIVE');
308
+ const now = this.now();
309
+ const run = {
310
+ id: input.runId ?? randomUUID(),
311
+ sessionId: session.id,
312
+ nodeId: this.nodeId(),
313
+ workspaceId: session.workspaceId,
314
+ runner: session.runner,
315
+ status: 'STARTING',
316
+ recoveryState: 'ACTIVE',
317
+ version: 0,
318
+ clientMessageId: input.clientMessageId,
319
+ ...(input.initiatedByUserId === undefined
320
+ ? {}
321
+ : { initiatedByUserId: input.initiatedByUserId }),
322
+ createdAt: now,
323
+ startedAt: now,
324
+ completedAt: null,
325
+ updatedAt: now
326
+ };
327
+ const attachments = this.projectMessageAttachments(run.id, input.attachments ?? []);
328
+ const user = {
329
+ id: randomUUID(),
330
+ sessionId: session.id,
331
+ turnId: '',
332
+ runId: run.id,
333
+ parentItemId: null,
334
+ sourceSequence: null,
335
+ revision: 0,
336
+ kind: 'user_message',
337
+ status: 'COMPLETED',
338
+ payload: {
339
+ clientMessageId: input.clientMessageId,
340
+ text: input.content,
341
+ contexts: [],
342
+ attachments,
343
+ delivery: 'ACCEPTED'
344
+ },
345
+ startedAt: now,
346
+ completedAt: now
347
+ };
348
+ const turn = {
349
+ id: randomUUID(),
350
+ sessionId: session.id,
351
+ runId: run.id,
352
+ userItemId: user.id,
353
+ status: 'PREPARING',
354
+ model: session.model,
355
+ effort: session.effort,
356
+ access: session.access,
357
+ items: [user],
358
+ startedAt: now,
359
+ completedAt: null
360
+ };
361
+ const fixedTurn = { ...turn, items: [{ ...user, turnId: turn.id }] };
362
+ this.runs.set(run.id, run);
363
+ this.recentUserMessages.set(run.id, input.recentUserMessage ?? input.content);
364
+ this.messageSubmissions.set(key, { kind: 'run', id: run.id });
365
+ this.leases.set(session.id, run.id);
366
+ this.turns.set(session.id, [...(this.turns.get(session.id) ?? []), fixedTurn]);
367
+ this.replaceSession(session.id, { lastActivityAt: now });
368
+ this.emitRunChanged(run, this.requireSession(session.id));
369
+ return { run, created: true };
370
+ }
371
+ createQueueItem(input) {
372
+ this.assertSessionHistoryMutable(input.sessionId);
373
+ const key = `${input.sessionId}\u0000${input.clientMessageId}`;
374
+ const duplicate = this.messageSubmissions.get(key);
375
+ if (duplicate !== undefined) {
376
+ if (duplicate.kind !== 'queue')
377
+ throw new Error('MESSAGE_ALREADY_STARTED');
378
+ return { item: this.requireQueueItem(duplicate.id), created: false };
379
+ }
380
+ const session = this.requireSession(input.sessionId);
381
+ const active = this.activeSessionRun(session.id);
382
+ const queuedOwner = (this.queuedItems.get(session.id) ?? [])
383
+ .map((itemId) => this.queueItems.get(itemId)?.initiatedByUserId)
384
+ .find((userId) => userId !== undefined);
385
+ const expectedOwner = active?.initiatedByUserId ?? queuedOwner;
386
+ if (expectedOwner !== undefined && input.initiatedByUserId !== expectedOwner)
387
+ throw new Error('RUN_OWNED_BY_ANOTHER_USER');
388
+ const now = this.now();
389
+ const item = {
390
+ id: input.queueItemId ?? randomUUID(),
391
+ sessionId: session.id,
392
+ workspaceId: session.workspaceId,
393
+ runner: session.runner,
394
+ clientMessageId: input.clientMessageId,
395
+ content: input.content,
396
+ attachments: input.attachments ?? [],
397
+ ...(input.initiatedByUserId === undefined
398
+ ? {}
399
+ : { initiatedByUserId: input.initiatedByUserId }),
400
+ createdAt: now
401
+ };
402
+ this.queueItems.set(item.id, item);
403
+ this.messageSubmissions.set(key, { kind: 'queue', id: item.id });
404
+ this.queuedItems.set(session.id, [...(this.queuedItems.get(session.id) ?? []), item.id]);
405
+ this.bumpQueueVersion(session.id);
406
+ return { item, created: true };
407
+ }
408
+ sessionQueue(sessionId) {
409
+ return {
410
+ version: this.queueVersions.get(sessionId) ?? 0,
411
+ paused: this.pausedQueues.has(sessionId),
412
+ itemIds: this.queuedItems.get(sessionId) ?? []
413
+ };
414
+ }
415
+ getQueueItem(id) {
416
+ return this.queueItems.get(id);
417
+ }
418
+ claimNextQueueItem(sessionId, content) {
419
+ if (this.pausedQueues.has(sessionId))
420
+ return undefined;
421
+ const active = this.activeSessionRun(sessionId);
422
+ if (active === undefined)
423
+ return undefined;
424
+ const queue = this.queuedItems.get(sessionId) ?? [];
425
+ const itemId = queue[0];
426
+ if (itemId === undefined)
427
+ return undefined;
428
+ const item = this.requireQueueItem(itemId);
429
+ const run = active.initiatedByUserId === undefined && item.initiatedByUserId !== undefined
430
+ ? { ...active, initiatedByUserId: item.initiatedByUserId }
431
+ : active;
432
+ if (run !== active)
433
+ this.runs.set(run.id, run);
434
+ this.queuedItems.set(sessionId, queue.slice(1));
435
+ this.bumpQueueVersion(sessionId);
436
+ this.queueItems.delete(itemId);
437
+ this.messageSubmissions.set(`${item.sessionId}\u0000${item.clientMessageId}`, {
438
+ kind: 'run',
439
+ id: run.id
440
+ });
441
+ const turn = this.createTurn(run, item.clientMessageId, content ?? item.content, item.attachments);
442
+ this.recentUserMessages.set(run.id, item.content);
443
+ this.emitRunChanged(run, this.requireSession(sessionId));
444
+ return { item, turn };
445
+ }
446
+ startRunFromQueueItem(itemId, content) {
447
+ const item = this.requireQueueItem(itemId);
448
+ if (this.activeSessionRun(item.sessionId) !== undefined)
449
+ throw new Error('RUN_ALREADY_ACTIVE');
450
+ const queue = this.queuedItems.get(item.sessionId) ?? [];
451
+ if (queue[0] !== itemId)
452
+ throw new Error('QUEUE_ITEM_INVALID');
453
+ this.queuedItems.set(item.sessionId, queue.slice(1));
454
+ this.queueItems.delete(itemId);
455
+ this.messageSubmissions.delete(`${item.sessionId}\u0000${item.clientMessageId}`);
456
+ this.bumpQueueVersion(item.sessionId);
457
+ const created = this.createMessageRun({
458
+ sessionId: item.sessionId,
459
+ clientMessageId: item.clientMessageId,
460
+ content: content ?? item.content,
461
+ recentUserMessage: item.content,
462
+ ...(item.attachments.length === 0 ? {} : { attachments: item.attachments }),
463
+ ...(item.initiatedByUserId === undefined ? {} : { initiatedByUserId: item.initiatedByUserId })
464
+ });
465
+ const turn = this.currentTurnForRun(created.run.id);
466
+ if (turn === undefined)
467
+ throw new Error('RUN_TURN_NOT_FOUND');
468
+ return { run: created.run, turn };
469
+ }
470
+ pauseSessionQueue(sessionId) {
471
+ this.pausedQueues.add(sessionId);
472
+ this.bumpQueueVersion(sessionId);
473
+ }
474
+ resumeSessionQueue(sessionId) {
475
+ if (!this.pausedQueues.delete(sessionId))
476
+ return;
477
+ this.bumpQueueVersion(sessionId);
478
+ }
479
+ reorderSessionQueue(sessionId, expectedVersion, itemIds) {
480
+ const current = this.queuedItems.get(sessionId) ?? [];
481
+ if (this.sessionQueue(sessionId).version !== expectedVersion ||
482
+ current.length !== itemIds.length ||
483
+ new Set(current).size !== current.length ||
484
+ current.some((itemId) => !itemIds.includes(itemId)))
485
+ throw new Error('QUEUE_VERSION_CONFLICT');
486
+ if (itemIds.some((itemId) => this.queueItems.get(itemId)?.sessionId !== sessionId))
487
+ throw new Error('QUEUE_ITEM_INVALID');
488
+ this.queuedItems.set(sessionId, [...itemIds]);
489
+ this.bumpQueueVersion(sessionId);
490
+ }
491
+ prioritizeQueueItem(itemId) {
492
+ const item = this.requireQueueItem(itemId);
493
+ const queue = this.queuedItems.get(item.sessionId) ?? [];
494
+ if (!queue.includes(itemId))
495
+ throw new Error('QUEUE_ITEM_INVALID');
496
+ this.queuedItems.set(item.sessionId, [
497
+ itemId,
498
+ ...queue.filter((candidate) => candidate !== itemId)
499
+ ]);
500
+ this.bumpQueueVersion(item.sessionId);
501
+ return item;
502
+ }
503
+ updateQueueItem(itemId, content) {
504
+ const item = this.requireQueueItem(itemId);
505
+ if (!(this.queuedItems.get(item.sessionId) ?? []).includes(itemId))
506
+ throw new Error('QUEUE_ITEM_INVALID');
507
+ const next = { ...item, content };
508
+ this.queueItems.set(itemId, next);
509
+ this.bumpQueueVersion(item.sessionId);
510
+ return next;
511
+ }
512
+ updateQueueItemAttachments(itemId, attachments) {
513
+ const item = this.requireQueueItem(itemId);
514
+ const next = { ...item, attachments };
515
+ this.queueItems.set(itemId, next);
516
+ return next;
517
+ }
518
+ deleteQueueItem(itemId) {
519
+ const item = this.requireQueueItem(itemId);
520
+ const queue = this.queuedItems.get(item.sessionId) ?? [];
521
+ if (!queue.includes(itemId))
522
+ throw new Error('QUEUE_ITEM_INVALID');
523
+ this.queuedItems.set(item.sessionId, queue.filter((candidate) => candidate !== itemId));
524
+ this.bumpQueueVersion(item.sessionId);
525
+ this.queueItems.delete(itemId);
526
+ for (const [key, candidate] of this.messageSubmissions)
527
+ if (candidate.kind === 'queue' && candidate.id === itemId)
528
+ this.messageSubmissions.delete(key);
529
+ }
530
+ currentRunMessageText(runId) {
531
+ const run = this.requireRun(runId);
532
+ const turn = (this.turns.get(run.sessionId) ?? []).findLast((candidate) => candidate.runId === runId);
533
+ const item = turn?.items.find((candidate) => candidate.id === turn.userItemId);
534
+ return isRecord(item?.payload) && typeof item.payload.text === 'string'
535
+ ? item.payload.text
536
+ : '';
537
+ }
538
+ updatePreparingTurnMessage(runId, content, attachments) {
539
+ const projected = this.projectMessageAttachments(runId, attachments);
540
+ this.updateCurrentTurnForRun(runId, (turn) => ({
541
+ ...turn,
542
+ items: turn.items.map((item) => item.id === turn.userItemId && isRecord(item.payload)
543
+ ? { ...item, payload: { ...item.payload, text: content, attachments: projected } }
544
+ : item)
545
+ }));
546
+ }
547
+ getRun(id) {
548
+ const canonical = this.executions.get(id)?.runId ?? id;
549
+ return this.runs.get(canonical);
550
+ }
551
+ findMessageRun(sessionId, clientMessageId) {
552
+ const submission = this.messageSubmissions.get(`${sessionId}\u0000${clientMessageId}`);
553
+ return submission?.kind === 'run' ? this.runs.get(submission.id) : undefined;
554
+ }
555
+ findMessageSubmission(sessionId, clientMessageId) {
556
+ const submission = this.messageSubmissions.get(`${sessionId}\u0000${clientMessageId}`);
557
+ if (submission === undefined)
558
+ return undefined;
559
+ if (submission.kind === 'run')
560
+ return { kind: 'run', run: this.requireRun(submission.id) };
561
+ const item = this.requireQueueItem(submission.id);
562
+ const run = this.activeSessionRun(sessionId);
563
+ if (run === undefined)
564
+ throw new Error('RUN_NOT_FOUND');
565
+ return { kind: 'queue', item, run };
566
+ }
567
+ messagePreparationFailure(sessionId, clientMessageId) {
568
+ return this.failedMessageSubmissions.get(`${sessionId}\u0000${clientMessageId}`);
569
+ }
570
+ recordMessagePreparationFailure(submissionId, code) {
571
+ const entry = [...this.messageSubmissions].find(([, submission]) => submission.id === submissionId);
572
+ if (entry === undefined)
573
+ return;
574
+ this.failedMessageSubmissions.set(entry[0], code);
575
+ if (this.failedMessageSubmissions.size > 1_024)
576
+ this.failedMessageSubmissions.delete(this.failedMessageSubmissions.keys().next().value);
577
+ }
578
+ listRunsForSession(sessionId) {
579
+ return [...this.runs.values()]
580
+ .filter((run) => run.sessionId === sessionId)
581
+ .sort((a, b) => b.createdAt - a.createdAt);
582
+ }
583
+ transitionRun(id, next) {
584
+ const runId = this.executions.get(id)?.runId ?? id;
585
+ const current = this.requireRun(runId);
586
+ if (!transitionAllowed(current.status, next))
587
+ throw new Error('RUN_STATE_INVALID');
588
+ const now = this.now();
589
+ const value = {
590
+ ...current,
591
+ status: next,
592
+ version: current.version + 1,
593
+ completedAt: terminal(next) ? now : current.completedAt,
594
+ updatedAt: now
595
+ };
596
+ this.runs.set(runId, value);
597
+ this.emitRunChanged(value, this.requireSession(value.sessionId));
598
+ if (terminal(next) && this.leases.get(value.sessionId) === value.id)
599
+ this.leases.delete(value.sessionId);
600
+ this.updateCurrentTurnForRun(value.id, (turn) => ({
601
+ ...turn,
602
+ status: next,
603
+ completedAt: terminal(next) ? this.now() : turn.completedAt,
604
+ items: terminal(next)
605
+ ? turn.items.map((item) => activeConversationItem(item.status)
606
+ ? { ...item, status: completedStatusForRun(next), completedAt: this.now() }
607
+ : item)
608
+ : turn.items
609
+ }));
610
+ return value;
611
+ }
612
+ appendRunEvent(input) {
613
+ const execution = this.executions.get(input.runId);
614
+ const runId = execution?.runId ?? input.runId;
615
+ this.requireRun(runId);
616
+ const priorSequence = this.runSequences.get(runId) ?? 0;
617
+ if (input.sequence <= priorSequence)
618
+ return undefined;
619
+ if (input.sequence > priorSequence + 1)
620
+ throw new Error('EVENT_SEQUENCE_GAP');
621
+ const value = {
622
+ runId,
623
+ sequence: input.sequence,
624
+ eventType: input.eventType,
625
+ payload: input.payload,
626
+ ...(input.status === undefined ? {} : { status: input.status }),
627
+ createdAt: this.now()
628
+ };
629
+ this.runSequences.set(runId, input.sequence);
630
+ if (execution !== undefined && input.status !== undefined) {
631
+ const executionStatus = executionStatusForRun(input.status);
632
+ this.executions.set(input.runId, {
633
+ ...execution,
634
+ status: executionStatus,
635
+ completedAt: terminal(input.status) ? value.createdAt : execution.completedAt
636
+ });
637
+ }
638
+ if (input.status !== undefined && !terminal(input.status))
639
+ this.transitionRun(runId, input.status);
640
+ this.projectEvent(value, execution?.turnId);
641
+ if (input.status !== undefined && terminal(input.status) && execution !== undefined)
642
+ this.completeTurn(execution.turnId, input.status, value.createdAt);
643
+ return value;
644
+ }
645
+ currentExecutionId(runId) {
646
+ const turn = this.currentTurnForRun(runId);
647
+ if (turn === undefined)
648
+ return undefined;
649
+ for (const [executionId, execution] of this.executions)
650
+ if (execution.runId === runId &&
651
+ execution.turnId === turn.id &&
652
+ !terminalExecution(execution.status))
653
+ return executionId;
654
+ return undefined;
655
+ }
656
+ createExecution(runId) {
657
+ const canonicalRunId = this.canonicalRunId(runId);
658
+ const turn = this.currentTurnForRun(canonicalRunId);
659
+ if (turn === undefined || turn.status !== 'PREPARING')
660
+ throw new Error('RUN_TURN_NOT_READY');
661
+ const existing = [...this.executions.values()].find((execution) => execution.runId === canonicalRunId && execution.turnId === turn.id);
662
+ if (existing !== undefined)
663
+ return existing;
664
+ const now = this.now();
665
+ const execution = {
666
+ id: randomUUID(),
667
+ runId: canonicalRunId,
668
+ turnId: turn.id,
669
+ status: 'STARTING',
670
+ startedAt: now,
671
+ completedAt: null
672
+ };
673
+ this.executions.set(execution.id, execution);
674
+ this.updateCurrentTurnForRun(canonicalRunId, (current) => ({
675
+ ...current,
676
+ items: current.items.map((item) => item.id === current.userItemId &&
677
+ isRecord(item.payload) &&
678
+ Array.isArray(item.payload.attachments)
679
+ ? {
680
+ ...item,
681
+ payload: {
682
+ ...item.payload,
683
+ attachments: item.payload.attachments.map((attachment) => isRecord(attachment) && typeof attachment.imageIndex === 'number'
684
+ ? { ...attachment, runId: execution.id }
685
+ : attachment)
686
+ }
687
+ }
688
+ : item)
689
+ }));
690
+ return execution;
691
+ }
692
+ canonicalRunId(id) {
693
+ return this.executions.get(id)?.runId ?? id;
694
+ }
695
+ finishRun(runId, status) {
696
+ return this.transitionRun(this.canonicalRunId(runId), status);
697
+ }
698
+ listConversationTurns(input) {
699
+ this.requireSession(input.sessionId);
700
+ // A managed Turn keeps the user's acceptance time as its stable timeline
701
+ // position. Runner start/completion timestamps must not move it behind a
702
+ // message that was accepted later. Native Turns without a user timestamp
703
+ // fall back to their own lifecycle time.
704
+ const all = [...(this.turns.get(input.sessionId) ?? [])]
705
+ .map((turn, index) => ({ turn, index }))
706
+ .sort((a, b) => {
707
+ const timestamp = (value) => value.items.find((item) => item.id === value.userItemId)?.startedAt ??
708
+ value.startedAt ??
709
+ value.completedAt ??
710
+ 0;
711
+ return timestamp(a.turn) - timestamp(b.turn) || a.index - b.index;
712
+ })
713
+ .map(({ turn }) => turn);
714
+ const end = input.cursor === undefined ? all.length : decodeCursor(input.cursor, input.sessionId);
715
+ const limit = Math.min(Math.max(input.limit ?? 30, 1), 500);
716
+ const start = Math.max(0, end - limit);
717
+ const slice = all.slice(start, end);
718
+ return {
719
+ turns: slice,
720
+ nextCursor: start > 0 ? encodeCursor(input.sessionId, start) : null
721
+ };
722
+ }
723
+ conversationTurnForRun(runId) {
724
+ for (const turns of this.turns.values()) {
725
+ const turn = turns.findLast((candidate) => candidate.runId === this.canonicalRunId(runId));
726
+ if (turn !== undefined)
727
+ return turn;
728
+ }
729
+ return undefined;
730
+ }
731
+ conversationTurnForExecution(executionId) {
732
+ const execution = this.executions.get(executionId);
733
+ const reference = execution === undefined
734
+ ? this.retainedExecutionTurns.get(executionId)
735
+ : {
736
+ sessionId: this.requireRun(execution.runId).sessionId,
737
+ turnId: execution.turnId
738
+ };
739
+ if (reference === undefined)
740
+ return undefined;
741
+ return (this.turns.get(reference.sessionId) ?? []).find((turn) => turn.id === reference.turnId);
742
+ }
743
+ listConversationItems(input) {
744
+ const turns = this.listConversationTurns(input).turns;
745
+ return { items: turns.flatMap((turn) => turn.items), nextCursor: null };
746
+ }
747
+ recordCommandExecution(input) {
748
+ const session = this.requireSession(input.sessionId);
749
+ const now = this.now();
750
+ const item = {
751
+ id: randomUUID(),
752
+ sessionId: input.sessionId,
753
+ turnId: '',
754
+ runId: null,
755
+ parentItemId: null,
756
+ sourceSequence: null,
757
+ revision: 1,
758
+ kind: 'command_execution',
759
+ status: input.failed ? 'FAILED' : 'COMPLETED',
760
+ payload: {
761
+ command: input.command,
762
+ cwd: input.cwd,
763
+ outputPreview: input.outputPreview.slice(0, 10_000),
764
+ outputRef: null,
765
+ exitCode: input.failed ? 1 : 0,
766
+ durationMs: 0,
767
+ truncated: false
768
+ },
769
+ startedAt: now,
770
+ completedAt: now
771
+ };
772
+ const turn = {
773
+ id: randomUUID(),
774
+ sessionId: input.sessionId,
775
+ runId: null,
776
+ userItemId: null,
777
+ status: input.failed ? 'FAILED' : 'SUCCEEDED',
778
+ model: session.model,
779
+ effort: session.effort,
780
+ access: session.access,
781
+ items: [],
782
+ startedAt: now,
783
+ completedAt: now
784
+ };
785
+ const completedItem = { ...item, turnId: turn.id };
786
+ const completedTurn = { ...turn, items: [completedItem] };
787
+ this.turns.set(input.sessionId, [...(this.turns.get(input.sessionId) ?? []), completedTurn]);
788
+ this.replaceSession(session.id, { lastActivityAt: now });
789
+ return completedTurn;
790
+ }
791
+ createApproval(input) {
792
+ const run = this.getRun(input.runId);
793
+ if (run === undefined)
794
+ throw new Error('RUN_NOT_FOUND');
795
+ if (input.runId !== run.id && this.currentExecutionId(run.id) !== input.runId)
796
+ throw new Error('RUN_EXECUTION_NOT_CURRENT');
797
+ if (this.approvals.has(input.approvalId))
798
+ throw new Error('APPROVAL_ALREADY_EXISTS');
799
+ if (input.expiresAt <= this.now())
800
+ throw new Error('APPROVAL_EXPIRED');
801
+ const value = {
802
+ id: input.approvalId,
803
+ runId: input.runId,
804
+ status: 'PENDING',
805
+ payload: input.payload,
806
+ expiresAt: input.expiresAt,
807
+ createdAt: this.now(),
808
+ decidedAt: null
809
+ };
810
+ this.approvals.set(value.id, value);
811
+ return value;
812
+ }
813
+ getApproval(id) {
814
+ const value = this.approvals.get(id);
815
+ if (value?.status === 'PENDING' && value.expiresAt <= this.now())
816
+ return this.expireApproval(id);
817
+ return value;
818
+ }
819
+ listApprovals(runId) {
820
+ const canonicalRunId = this.canonicalRunId(runId);
821
+ return [...this.approvals.values()]
822
+ .filter((value) => this.canonicalRunId(value.runId) === canonicalRunId)
823
+ .map((value) => this.getApproval(value.id));
824
+ }
825
+ expireApproval(id) {
826
+ const value = this.requireApproval(id);
827
+ if (value.status !== 'PENDING')
828
+ return value;
829
+ if (value.expiresAt > this.now())
830
+ throw new Error('APPROVAL_NOT_EXPIRED');
831
+ const next = { ...value, status: 'EXPIRED', decidedAt: this.now() };
832
+ this.approvals.set(id, next);
833
+ return next;
834
+ }
835
+ decideApproval(id, decision) {
836
+ const value = this.getApproval(id);
837
+ if (value === undefined)
838
+ throw new Error('APPROVAL_NOT_FOUND');
839
+ if (value.status === 'EXPIRED')
840
+ throw new Error('APPROVAL_EXPIRED');
841
+ if (value.status !== 'PENDING')
842
+ throw new Error('APPROVAL_ALREADY_DECIDED');
843
+ const next = { ...value, status: decision, decidedAt: this.now() };
844
+ this.approvals.set(id, next);
845
+ return next;
846
+ }
847
+ expireDueApprovals() {
848
+ return [...this.approvals.values()]
849
+ .filter((value) => value.status === 'PENDING' && value.expiresAt <= this.now())
850
+ .map((value) => this.expireApproval(value.id));
851
+ }
852
+ listNonterminalRuns() {
853
+ return [...this.runs.values()].filter((run) => !terminal(run.status));
854
+ }
855
+ lastRunSequence(id) {
856
+ return this.runSequences.get(id) ?? 0;
857
+ }
858
+ removeTerminalRun(runId) {
859
+ const run = this.requireRun(runId);
860
+ if (!terminal(run.status))
861
+ throw new Error('RUN_ACTIVE');
862
+ this.terminalRunIds.add(runId);
863
+ if (this.terminalRunIds.size > 1_024)
864
+ this.terminalRunIds.delete(this.terminalRunIds.values().next().value);
865
+ const executionIds = new Set([...this.executions.values()]
866
+ .filter((execution) => execution.runId === runId)
867
+ .map((execution) => execution.id));
868
+ const turns = (this.turns.get(run.sessionId) ?? []).filter((turn) => {
869
+ const hasVisibleError = turn.items.some((item) => item.kind === 'error');
870
+ if (turn.runId === runId)
871
+ return run.status === 'SUCCEEDED' || run.status === 'INTERRUPTED' || hasVisibleError;
872
+ const isTransientErrorTurn = hasVisibleError && turn.status !== 'SUCCEEDED' && turn.status !== 'INTERRUPTED';
873
+ return run.status !== 'SUCCEEDED' || !isTransientErrorTurn;
874
+ });
875
+ const completed = turns.filter((turn) => terminalTurn(turn.status));
876
+ const retainedCompleted = new Set(completed.slice(-NodeRuntimeState.MAX_COMPLETED_TURNS_PER_SESSION).map((turn) => turn.id));
877
+ const retainedTurns = turns.filter((turn) => !terminalTurn(turn.status) || retainedCompleted.has(turn.id));
878
+ const retainedTurnIds = new Set(retainedTurns.map((turn) => turn.id));
879
+ this.turns.set(run.sessionId, retainedTurns);
880
+ for (const [executionId, execution] of this.executions) {
881
+ if (execution.runId !== runId)
882
+ continue;
883
+ this.executions.delete(executionId);
884
+ if (retainedTurnIds.has(execution.turnId))
885
+ this.retainedExecutionTurns.set(executionId, {
886
+ sessionId: run.sessionId,
887
+ turnId: execution.turnId
888
+ });
889
+ }
890
+ this.pruneRetainedExecutionTurns(run.sessionId, retainedTurnIds);
891
+ this.runs.delete(runId);
892
+ this.recentUserMessages.delete(runId);
893
+ this.runSequences.delete(runId);
894
+ for (const [key, candidate] of this.messageSubmissions)
895
+ if (candidate.kind === 'run' && candidate.id === runId)
896
+ this.messageSubmissions.delete(key);
897
+ for (const [approvalId, approval] of this.approvals)
898
+ if (approval.runId === runId || executionIds.has(approval.runId))
899
+ this.approvals.delete(approvalId);
900
+ }
901
+ hasActiveWorkspaceLease(workspaceId) {
902
+ return [...this.leases.values()]
903
+ .map((runId) => this.runs.get(runId))
904
+ .some((run) => run?.workspaceId === workspaceId);
905
+ }
906
+ /** Removes a terminal Session's process-local projection after its native history is deleted. */
907
+ removeAgentSession(sessionId) {
908
+ this.requireSession(sessionId);
909
+ const runs = this.listRunsForSession(sessionId);
910
+ if (runs.some((run) => !terminal(run.status)))
911
+ throw new Error('SESSION_ACTIVE');
912
+ const runIds = new Set(runs.map((run) => run.id));
913
+ const executionIds = new Set([...this.executions.values()]
914
+ .filter((execution) => runIds.has(execution.runId))
915
+ .map((execution) => execution.id));
916
+ this.sessions.delete(sessionId);
917
+ this.removePromotedSessionAliases(sessionId);
918
+ this.turns.delete(sessionId);
919
+ this.pruneRetainedExecutionTurns(sessionId, new Set());
920
+ const queued = this.queuedItems.get(sessionId) ?? [];
921
+ this.queuedItems.delete(sessionId);
922
+ for (const itemId of queued)
923
+ this.queueItems.delete(itemId);
924
+ this.queueVersions.delete(sessionId);
925
+ this.pausedQueues.delete(sessionId);
926
+ this.leases.delete(sessionId);
927
+ for (const runId of runIds) {
928
+ this.runs.delete(runId);
929
+ this.recentUserMessages.delete(runId);
930
+ this.runSequences.delete(runId);
931
+ }
932
+ for (const executionId of executionIds)
933
+ this.executions.delete(executionId);
934
+ for (const [key, submission] of this.messageSubmissions)
935
+ if ((submission.kind === 'run' && runIds.has(submission.id)) ||
936
+ (submission.kind === 'queue' && queued.includes(submission.id)))
937
+ this.messageSubmissions.delete(key);
938
+ for (const key of this.failedMessageSubmissions.keys())
939
+ if (key.startsWith(`${sessionId}\u0000`))
940
+ this.failedMessageSubmissions.delete(key);
941
+ for (const [approvalId, approval] of this.approvals)
942
+ if (runIds.has(approval.runId) || executionIds.has(approval.runId))
943
+ this.approvals.delete(approvalId);
944
+ }
945
+ beginSessionHistoryMutation(sessionId) {
946
+ if (this.sessionHistoryMutations.has(sessionId))
947
+ throw new Error('SESSION_ACTIVE');
948
+ if (this.activeSessionRun(sessionId) !== undefined)
949
+ throw new Error('SESSION_ACTIVE');
950
+ if (this.sessionQueue(sessionId).itemIds.length > 0)
951
+ throw new Error('SESSION_QUEUE_NOT_EMPTY');
952
+ this.sessionHistoryMutations.add(sessionId);
953
+ let released = false;
954
+ return () => {
955
+ if (released)
956
+ return;
957
+ released = true;
958
+ this.sessionHistoryMutations.delete(sessionId);
959
+ };
960
+ }
961
+ resetAgentSessionHistory(sessionId, lastActivityAt) {
962
+ if (this.activeSessionRun(sessionId) !== undefined)
963
+ throw new Error('SESSION_ACTIVE');
964
+ if (this.sessionQueue(sessionId).itemIds.length > 0)
965
+ throw new Error('SESSION_QUEUE_NOT_EMPTY');
966
+ this.turns.delete(sessionId);
967
+ this.pruneRetainedExecutionTurns(sessionId, new Set());
968
+ for (const key of this.failedMessageSubmissions.keys())
969
+ if (key.startsWith(`${sessionId}\u0000`))
970
+ this.failedMessageSubmissions.delete(key);
971
+ return this.replaceSession(sessionId, { lastActivityAt });
972
+ }
973
+ removeWorkspace(workspaceId) {
974
+ if (this.hasActiveWorkspaceLease(workspaceId))
975
+ throw new Error('WORKSPACE_BUSY');
976
+ const sessionIds = new Set([...this.sessions.values()]
977
+ .filter((session) => session.workspaceId === workspaceId)
978
+ .map((session) => session.id));
979
+ const runIds = new Set([...this.runs.values()].filter((run) => run.workspaceId === workspaceId).map((run) => run.id));
980
+ const executionIds = new Set([...this.executions.values()]
981
+ .filter((execution) => runIds.has(execution.runId))
982
+ .map((execution) => execution.id));
983
+ const queueItemIds = new Set([...sessionIds].flatMap((sessionId) => this.queuedItems.get(sessionId) ?? []));
984
+ for (const sessionId of sessionIds) {
985
+ this.sessions.delete(sessionId);
986
+ this.removePromotedSessionAliases(sessionId);
987
+ this.turns.delete(sessionId);
988
+ this.pruneRetainedExecutionTurns(sessionId, new Set());
989
+ }
990
+ for (const runId of runIds) {
991
+ this.runs.delete(runId);
992
+ this.recentUserMessages.delete(runId);
993
+ this.runSequences.delete(runId);
994
+ }
995
+ for (const executionId of executionIds)
996
+ this.executions.delete(executionId);
997
+ for (const [key, submission] of this.messageSubmissions)
998
+ if ((submission.kind === 'run' && runIds.has(submission.id)) ||
999
+ (submission.kind === 'queue' && queueItemIds.has(submission.id)))
1000
+ this.messageSubmissions.delete(key);
1001
+ for (const key of this.failedMessageSubmissions.keys()) {
1002
+ const separator = key.indexOf('\u0000');
1003
+ if (separator >= 0 && sessionIds.has(key.slice(0, separator)))
1004
+ this.failedMessageSubmissions.delete(key);
1005
+ }
1006
+ for (const [approvalId, approval] of this.approvals)
1007
+ if (runIds.has(approval.runId) || executionIds.has(approval.runId))
1008
+ this.approvals.delete(approvalId);
1009
+ for (const sessionId of sessionIds) {
1010
+ const queued = this.queuedItems.get(sessionId) ?? [];
1011
+ this.queuedItems.delete(sessionId);
1012
+ for (const itemId of queued)
1013
+ this.queueItems.delete(itemId);
1014
+ this.queueVersions.delete(sessionId);
1015
+ this.pausedQueues.delete(sessionId);
1016
+ this.leases.delete(sessionId);
1017
+ }
1018
+ }
1019
+ assertSessionHistoryMutable(sessionId) {
1020
+ if (this.sessionHistoryMutations.has(sessionId))
1021
+ throw new Error('SESSION_ACTIVE');
1022
+ }
1023
+ reconcileRun(id, active) {
1024
+ // There is no cross-restart run recovery: this process-local state is
1025
+ // discarded on restart and cannot be reconciled from SQLite.
1026
+ void id;
1027
+ void active;
1028
+ }
1029
+ replaceSession(id, patch) {
1030
+ const value = this.requireSession(id);
1031
+ const next = { ...value, ...patch };
1032
+ this.sessions.set(id, next);
1033
+ if (value.customTitle !== next.customTitle || value.runnerTitle !== next.runnerTitle)
1034
+ for (const run of this.listRunsForSession(id))
1035
+ this.emitRunChanged(run, next);
1036
+ return next;
1037
+ }
1038
+ emitRunChanged(run, session) {
1039
+ const turn = this.currentTurnForRun(run.id);
1040
+ const payload = turn?.items.find((item) => item.kind === 'user_message')?.payload;
1041
+ const clientMessageId = isRecord(payload) && typeof payload.clientMessageId === 'string'
1042
+ ? payload.clientMessageId
1043
+ : undefined;
1044
+ const userMessage = clientMessageId?.startsWith('mission:')
1045
+ ? ''
1046
+ : (this.recentUserMessages.get(run.id) ?? this.currentRunMessageText(run.id));
1047
+ this.onRunChanged?.(run, session, userMessage.length === 0 ? undefined : userMessage);
1048
+ }
1049
+ bumpQueueVersion(sessionId) {
1050
+ this.queueVersions.set(sessionId, (this.queueVersions.get(sessionId) ?? 0) + 1);
1051
+ }
1052
+ pruneRetainedExecutionTurns(sessionId, retainedTurnIds) {
1053
+ for (const [executionId, reference] of this.retainedExecutionTurns)
1054
+ if (reference.sessionId === sessionId && !retainedTurnIds.has(reference.turnId))
1055
+ this.retainedExecutionTurns.delete(executionId);
1056
+ }
1057
+ requireSession(id) {
1058
+ const value = this.sessions.get(id);
1059
+ if (value === undefined)
1060
+ throw new Error('SESSION_NOT_FOUND');
1061
+ return value;
1062
+ }
1063
+ resolvePromotedSessionId(id) {
1064
+ let resolved = id;
1065
+ const visited = new Set();
1066
+ while (!visited.has(resolved)) {
1067
+ visited.add(resolved);
1068
+ const next = this.promotedSessionAliases.get(resolved);
1069
+ if (next === undefined)
1070
+ break;
1071
+ resolved = next;
1072
+ }
1073
+ return resolved;
1074
+ }
1075
+ removePromotedSessionAliases(sessionId) {
1076
+ for (const [alias, target] of this.promotedSessionAliases)
1077
+ if (alias === sessionId || target === sessionId)
1078
+ this.promotedSessionAliases.delete(alias);
1079
+ }
1080
+ requireRun(id) {
1081
+ const value = this.runs.get(id);
1082
+ if (value === undefined)
1083
+ throw new Error('RUN_NOT_FOUND');
1084
+ return value;
1085
+ }
1086
+ requireQueueItem(id) {
1087
+ const value = this.queueItems.get(id);
1088
+ if (value === undefined)
1089
+ throw new Error('QUEUE_ITEM_INVALID');
1090
+ return value;
1091
+ }
1092
+ requireApproval(id) {
1093
+ const value = this.approvals.get(id);
1094
+ if (value === undefined)
1095
+ throw new Error('APPROVAL_NOT_FOUND');
1096
+ return value;
1097
+ }
1098
+ updateTurnForRun(runId, update) {
1099
+ const run = this.requireRun(runId);
1100
+ const current = this.turns.get(run.sessionId) ?? [];
1101
+ this.turns.set(run.sessionId, current.map((turn) => (turn.runId === runId ? update(turn) : turn)));
1102
+ }
1103
+ updateCurrentTurnForRun(runId, update) {
1104
+ const run = this.requireRun(runId);
1105
+ const current = this.turns.get(run.sessionId) ?? [];
1106
+ const index = current.findLastIndex((turn) => turn.runId === runId);
1107
+ if (index < 0)
1108
+ return;
1109
+ this.turns.set(run.sessionId, current.map((turn, turnIndex) => (turnIndex === index ? update(turn) : turn)));
1110
+ }
1111
+ currentTurnForRun(runId) {
1112
+ const run = this.requireRun(runId);
1113
+ return (this.turns.get(run.sessionId) ?? []).findLast((turn) => turn.runId === runId);
1114
+ }
1115
+ createItemOnlyTurn(run, startedAt) {
1116
+ const session = this.requireSession(run.sessionId);
1117
+ const turn = {
1118
+ id: randomUUID(),
1119
+ sessionId: session.id,
1120
+ runId: run.id,
1121
+ userItemId: null,
1122
+ status: terminal(run.status) ? run.status : 'RUNNING',
1123
+ model: session.model,
1124
+ effort: session.effort,
1125
+ access: session.access,
1126
+ items: [],
1127
+ startedAt,
1128
+ completedAt: terminal(run.status) ? startedAt : null
1129
+ };
1130
+ this.turns.set(session.id, [...(this.turns.get(session.id) ?? []), turn]);
1131
+ this.replaceSession(session.id, { lastActivityAt: startedAt });
1132
+ return turn;
1133
+ }
1134
+ createTurn(run, clientMessageId, content, attachments) {
1135
+ const session = this.requireSession(run.sessionId);
1136
+ const now = this.now();
1137
+ const turnId = randomUUID();
1138
+ const userId = randomUUID();
1139
+ const user = {
1140
+ id: userId,
1141
+ sessionId: session.id,
1142
+ turnId,
1143
+ runId: run.id,
1144
+ parentItemId: null,
1145
+ sourceSequence: null,
1146
+ revision: 0,
1147
+ kind: 'user_message',
1148
+ status: 'COMPLETED',
1149
+ payload: {
1150
+ clientMessageId,
1151
+ text: content,
1152
+ contexts: [],
1153
+ attachments: this.projectMessageAttachments(run.id, attachments),
1154
+ delivery: 'ACCEPTED'
1155
+ },
1156
+ startedAt: now,
1157
+ completedAt: now
1158
+ };
1159
+ const turn = {
1160
+ id: turnId,
1161
+ sessionId: session.id,
1162
+ runId: run.id,
1163
+ userItemId: userId,
1164
+ status: 'PREPARING',
1165
+ model: session.model,
1166
+ effort: session.effort,
1167
+ access: session.access,
1168
+ items: [user],
1169
+ startedAt: now,
1170
+ completedAt: null
1171
+ };
1172
+ this.turns.set(session.id, [...(this.turns.get(session.id) ?? []), turn]);
1173
+ this.replaceSession(session.id, { lastActivityAt: now });
1174
+ return turn;
1175
+ }
1176
+ projectMessageAttachments(runId, attachments) {
1177
+ let imageIndex = 0;
1178
+ return attachments.map(({ name, mime, dataBase64 }) => {
1179
+ const attachment = {
1180
+ name,
1181
+ mime,
1182
+ byteSize: Buffer.byteLength(dataBase64, 'base64'),
1183
+ runId
1184
+ };
1185
+ if (!mime.startsWith('image/'))
1186
+ return attachment;
1187
+ return { ...attachment, imageIndex: imageIndex++ };
1188
+ });
1189
+ }
1190
+ completeTurn(turnId, status, completedAt) {
1191
+ for (const [sessionId, turns] of this.turns) {
1192
+ if (!turns.some((turn) => turn.id === turnId))
1193
+ continue;
1194
+ this.turns.set(sessionId, turns.map((turn) => turn.id === turnId
1195
+ ? {
1196
+ ...turn,
1197
+ status,
1198
+ completedAt,
1199
+ items: turn.items.map((item) => activeConversationItem(item.status)
1200
+ ? { ...item, status: completedStatusForRun(status), completedAt }
1201
+ : item)
1202
+ }
1203
+ : turn));
1204
+ return;
1205
+ }
1206
+ }
1207
+ projectEvent(event, turnId) {
1208
+ const run = this.requireRun(event.runId);
1209
+ if (turnId === undefined &&
1210
+ this.currentTurnForRun(event.runId) === undefined &&
1211
+ conversationItemFromEvent(event) !== undefined)
1212
+ this.createItemOnlyTurn(run, event.createdAt);
1213
+ const update = (turn) => {
1214
+ if (event.eventType === 'text.delta' &&
1215
+ isRecord(event.payload) &&
1216
+ typeof event.payload.text === 'string') {
1217
+ const nativeItemId = typeof event.payload.itemId === 'string' && event.payload.itemId.length <= 88
1218
+ ? event.payload.itemId
1219
+ : undefined;
1220
+ const stableItemId = nativeItemId === undefined ? undefined : `${event.runId}:${nativeItemId}`;
1221
+ const lastItem = turn.items.at(-1);
1222
+ const existing = stableItemId === undefined
1223
+ ? lastItem?.kind === 'assistant_message' && activeConversationItem(lastItem.status)
1224
+ ? lastItem
1225
+ : undefined
1226
+ : turn.items.find((item) => item.id === stableItemId && item.kind === 'assistant_message');
1227
+ const text = `${existing === undefined ? '' : readableText(existing.payload)}${event.payload.text}`;
1228
+ const item = {
1229
+ id: existing?.id ?? stableItemId ?? `${event.runId}:assistant:${event.sequence}`,
1230
+ sessionId: run.sessionId,
1231
+ turnId: turn.id,
1232
+ runId: event.runId,
1233
+ parentItemId: null,
1234
+ sourceSequence: existing?.sourceSequence ?? event.sequence,
1235
+ revision: event.sequence,
1236
+ kind: 'assistant_message',
1237
+ status: 'IN_PROGRESS',
1238
+ payload: { text, format: 'markdown', model: null },
1239
+ startedAt: existing?.startedAt ?? event.createdAt,
1240
+ completedAt: null
1241
+ };
1242
+ return {
1243
+ ...turn,
1244
+ status: 'RUNNING',
1245
+ startedAt: turn.startedAt ?? event.createdAt,
1246
+ items: existing === undefined
1247
+ ? [...turn.items, item]
1248
+ : turn.items.map((value) => (value.id === item.id ? item : value))
1249
+ };
1250
+ }
1251
+ const projected = conversationItemFromEvent(event);
1252
+ if (projected !== undefined) {
1253
+ const trailingItem = turn.items.at(-1);
1254
+ const orderedItems = trailingItem?.kind === 'assistant_message' && activeConversationItem(trailingItem.status)
1255
+ ? turn.items.map((item) => item.id === trailingItem.id
1256
+ ? { ...item, status: 'COMPLETED', completedAt: event.createdAt }
1257
+ : item)
1258
+ : turn.items;
1259
+ const existing = orderedItems.find((item) => item.id === `${event.runId}:${projected.itemId}`) ??
1260
+ (projected.kind === 'assistant_message' &&
1261
+ projected.itemId.startsWith('codex:') &&
1262
+ trailingItem?.kind === 'assistant_message' &&
1263
+ trailingItem.id.startsWith(`${event.runId}:assistant:`) &&
1264
+ activeConversationItem(trailingItem.status)
1265
+ ? trailingItem
1266
+ : undefined);
1267
+ const status = projected.status;
1268
+ const item = {
1269
+ id: `${event.runId}:${projected.itemId}`,
1270
+ sessionId: run.sessionId,
1271
+ turnId: turn.id,
1272
+ runId: event.runId,
1273
+ parentItemId: null,
1274
+ sourceSequence: existing?.sourceSequence ?? event.sequence,
1275
+ revision: (existing?.revision ?? -1) + 1,
1276
+ kind: projected.kind,
1277
+ status,
1278
+ payload: mergeConversationItemPayload(existing?.payload, projected),
1279
+ startedAt: existing?.startedAt ?? event.createdAt,
1280
+ completedAt: completedConversationItem(status) ? event.createdAt : null
1281
+ };
1282
+ return {
1283
+ ...turn,
1284
+ status: terminal(run.status) ? run.status : 'RUNNING',
1285
+ startedAt: turn.startedAt ?? event.createdAt,
1286
+ items: existing === undefined
1287
+ ? [...orderedItems, item]
1288
+ : orderedItems.map((value) => (value.id === existing.id ? item : value))
1289
+ };
1290
+ }
1291
+ if (event.eventType === 'run.started' || event.eventType === 'run.running')
1292
+ return { ...turn, status: 'RUNNING', startedAt: turn.startedAt ?? event.createdAt };
1293
+ if (event.eventType === 'run.completed' ||
1294
+ event.eventType === 'run.failed' ||
1295
+ event.eventType === 'run.rejected') {
1296
+ const status = event.status ?? this.requireRun(event.runId).status;
1297
+ return {
1298
+ ...turn,
1299
+ status,
1300
+ completedAt: event.createdAt,
1301
+ items: turn.items.map((item) => activeConversationItem(item.status)
1302
+ ? {
1303
+ ...item,
1304
+ status: completedStatusForRun(status),
1305
+ completedAt: event.createdAt
1306
+ }
1307
+ : item)
1308
+ };
1309
+ }
1310
+ return turn;
1311
+ };
1312
+ if (turnId === undefined)
1313
+ this.updateCurrentTurnForRun(event.runId, update);
1314
+ else {
1315
+ const current = this.turns.get(run.sessionId) ?? [];
1316
+ this.turns.set(run.sessionId, current.map((turn) => (turn.id === turnId ? update(turn) : turn)));
1317
+ }
1318
+ }
1319
+ }
1320
+ function isDefaultRunnerTitle(title) {
1321
+ return /^(?:new|untitled) session(?:\s*[-–—:]\s*\d{4}-\d{2}-\d{2}.*)?$/iu.test(title);
1322
+ }
1323
+ function terminal(status) {
1324
+ return ['SUCCEEDED', 'FAILED', 'CANCELLED', 'INTERRUPTED', 'LOST'].includes(status);
1325
+ }
1326
+ function terminalTurn(status) {
1327
+ return ['SUCCEEDED', 'FAILED', 'CANCELLED', 'INTERRUPTED', 'LOST'].includes(status);
1328
+ }
1329
+ function transitionAllowed(from, to) {
1330
+ return !terminal(from) || from === to;
1331
+ }
1332
+ function isRecord(value) {
1333
+ return typeof value === 'object' && value !== null;
1334
+ }
1335
+ function readableText(value) {
1336
+ return isRecord(value) && typeof value.text === 'string' ? value.text : '';
1337
+ }
1338
+ function conversationItemFromEvent(event) {
1339
+ if (isRecord(event.payload)) {
1340
+ const approvalId = event.payload.approvalId;
1341
+ if (typeof approvalId === 'string' && approvalId.length > 0) {
1342
+ if (event.eventType === 'approval.request')
1343
+ return {
1344
+ itemId: `approval:${approvalId}`,
1345
+ kind: 'approval_request',
1346
+ status: 'PENDING',
1347
+ payload: {
1348
+ approvalId,
1349
+ approvalStatus: 'PENDING',
1350
+ approval: event.payload.payload,
1351
+ expiresAt: event.payload.expiresAt
1352
+ },
1353
+ merge: false
1354
+ };
1355
+ if (event.eventType === 'approval.decided') {
1356
+ const decision = event.payload.decision;
1357
+ if (decision === 'APPROVED' || decision === 'REJECTED')
1358
+ return {
1359
+ itemId: `approval:${approvalId}`,
1360
+ kind: 'approval_request',
1361
+ status: decision === 'APPROVED' ? 'COMPLETED' : 'DECLINED',
1362
+ payload: { approvalId, approvalStatus: decision },
1363
+ merge: true
1364
+ };
1365
+ }
1366
+ if (event.eventType === 'approval.expired')
1367
+ return {
1368
+ itemId: `approval:${approvalId}`,
1369
+ kind: 'approval_request',
1370
+ status: 'CANCELLED',
1371
+ payload: { approvalId, approvalStatus: 'EXPIRED' },
1372
+ merge: true
1373
+ };
1374
+ }
1375
+ }
1376
+ if (event.eventType !== 'conversation.item' || !isRecord(event.payload))
1377
+ return undefined;
1378
+ const itemId = event.payload.itemId;
1379
+ const kind = event.payload.kind;
1380
+ const status = event.payload.status;
1381
+ const payload = event.payload.payload;
1382
+ if (typeof itemId !== 'string' ||
1383
+ itemId.length === 0 ||
1384
+ itemId.length > 88 ||
1385
+ typeof kind !== 'string' ||
1386
+ !projectableConversationKind(kind) ||
1387
+ typeof status !== 'string' ||
1388
+ !projectableConversationStatus(status) ||
1389
+ !isRecord(payload))
1390
+ return undefined;
1391
+ const append = event.payload.append;
1392
+ return {
1393
+ itemId,
1394
+ kind,
1395
+ status,
1396
+ payload,
1397
+ merge: event.payload.merge === true,
1398
+ ...(append === 'sections' || append === 'outputPreview' || append === 'outputSummary'
1399
+ ? { append }
1400
+ : {})
1401
+ };
1402
+ }
1403
+ function projectableConversationKind(value) {
1404
+ return (value === 'assistant_message' ||
1405
+ value === 'reasoning_summary' ||
1406
+ value === 'tool_call' ||
1407
+ value === 'command_execution' ||
1408
+ value === 'approval_request' ||
1409
+ value === 'user_input_request' ||
1410
+ value === 'plan' ||
1411
+ value === 'todo_list' ||
1412
+ value === 'file_change' ||
1413
+ value === 'context_compaction' ||
1414
+ value === 'unknown' ||
1415
+ value === 'warning' ||
1416
+ value === 'error');
1417
+ }
1418
+ function projectableConversationStatus(value) {
1419
+ return [
1420
+ 'PENDING',
1421
+ 'IN_PROGRESS',
1422
+ 'COMPLETED',
1423
+ 'FAILED',
1424
+ 'DECLINED',
1425
+ 'CANCELLED',
1426
+ 'INTERRUPTED'
1427
+ ].includes(value);
1428
+ }
1429
+ function mergeConversationItemPayload(existing, next) {
1430
+ const base = next.merge && isRecord(existing) ? existing : {};
1431
+ const value = { ...base, ...next.payload };
1432
+ if (next.append === 'sections') {
1433
+ const prior = Array.isArray(base.sections) ? base.sections : [];
1434
+ const incoming = Array.isArray(next.payload.sections) ? next.payload.sections : [];
1435
+ const sections = new Map();
1436
+ for (const section of [...prior, ...incoming]) {
1437
+ if (!isRecord(section) ||
1438
+ typeof section.index !== 'number' ||
1439
+ !Number.isInteger(section.index) ||
1440
+ section.index < 0 ||
1441
+ typeof section.text !== 'string')
1442
+ continue;
1443
+ sections.set(section.index, appendProjectionText(sections.get(section.index) ?? '', section.text));
1444
+ }
1445
+ value.sections = [...sections]
1446
+ .sort(([left], [right]) => left - right)
1447
+ .map(([index, text]) => ({ index, text }));
1448
+ }
1449
+ if (next.append === 'outputPreview') {
1450
+ const prior = typeof base.outputPreview === 'string' ? base.outputPreview : '';
1451
+ const incoming = typeof next.payload.outputPreview === 'string' ? next.payload.outputPreview : '';
1452
+ value.outputPreview = appendProjectionText(prior, incoming);
1453
+ }
1454
+ if (next.append === 'outputSummary') {
1455
+ const prior = typeof base.outputSummary === 'string' ? base.outputSummary : '';
1456
+ const incoming = typeof next.payload.outputSummary === 'string' ? next.payload.outputSummary : '';
1457
+ value.outputSummary = appendProjectionText(prior, incoming);
1458
+ }
1459
+ return value;
1460
+ }
1461
+ function appendProjectionText(previous, next) {
1462
+ const text = `${previous}${next}`;
1463
+ return text.length <= 10_000 ? text : `${text.slice(0, 9_999)}…`;
1464
+ }
1465
+ function activeConversationItem(status) {
1466
+ return status === 'PENDING' || status === 'IN_PROGRESS';
1467
+ }
1468
+ function completedConversationItem(status) {
1469
+ return !activeConversationItem(status);
1470
+ }
1471
+ function completedStatusForRun(status) {
1472
+ if (status === 'INTERRUPTED')
1473
+ return 'INTERRUPTED';
1474
+ if (status === 'CANCELLED')
1475
+ return 'CANCELLED';
1476
+ if (status === 'FAILED')
1477
+ return 'FAILED';
1478
+ return 'COMPLETED';
1479
+ }
1480
+ function executionStatusForRun(status) {
1481
+ if (status === 'FAILED')
1482
+ return 'FAILED';
1483
+ if (status === 'INTERRUPTED' || status === 'CANCELLED')
1484
+ return 'INTERRUPTED';
1485
+ if (status === 'SUCCEEDED')
1486
+ return 'SUCCEEDED';
1487
+ if (status === 'RUNNING')
1488
+ return 'RUNNING';
1489
+ return 'STARTING';
1490
+ }
1491
+ function terminalExecution(status) {
1492
+ return status === 'SUCCEEDED' || status === 'FAILED' || status === 'INTERRUPTED';
1493
+ }
1494
+ function encodeCursor(scope, value) {
1495
+ return Buffer.from(JSON.stringify({ scope, value })).toString('base64url');
1496
+ }
1497
+ function decodeCursor(cursor, scope) {
1498
+ if (cursor === undefined)
1499
+ return 0;
1500
+ try {
1501
+ const value = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8'));
1502
+ return value.scope === scope && Number.isInteger(value.value) && value.value >= 0
1503
+ ? value.value
1504
+ : 0;
1505
+ }
1506
+ catch {
1507
+ return 0;
1508
+ }
1509
+ }