@myagentroam/node 0.9.9 → 0.9.11

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 (214) hide show
  1. package/dist/capabilities.js +2 -92
  2. package/dist/claude-agent-sdk.js +2 -330
  3. package/dist/claude-channel.js +2 -44
  4. package/dist/codex-app-server.js +2 -503
  5. package/dist/config.js +2 -56
  6. package/dist/connector/node-connector-options.js +2 -1
  7. package/dist/connector/node-operation-router.js +2 -22
  8. package/dist/connector.js +2 -845
  9. package/dist/control-outbound-scheduler.js +2 -154
  10. package/dist/database.js +2 -1418
  11. package/dist/event-buffer.js +2 -19
  12. package/dist/fake-runner.js +2 -129
  13. package/dist/health.js +2 -3
  14. package/dist/main.js +2 -54
  15. package/dist/migrations/v001.js +3 -144
  16. package/dist/migrations/v002.js +2 -143
  17. package/dist/migrations/v003.js +2 -44
  18. package/dist/migrations/v004.js +34 -30
  19. package/dist/native-jsonl-reader.js +2 -186
  20. package/dist/native-session-history.js +2 -1119
  21. package/dist/opencode-runtime.js +2 -80
  22. package/dist/opencode-server.js +2 -263
  23. package/dist/operational.js +2 -122
  24. package/dist/process-tree.js +2 -18
  25. package/dist/rotating-log.js +2 -67
  26. package/dist/runner/abstract-runner.js +2 -232
  27. package/dist/runner/claude/managed-run-controller.js +2 -345
  28. package/dist/runner/claude-code-runner.js +2 -303
  29. package/dist/runner/codex/composer-image-markers.js +2 -0
  30. package/dist/runner/codex/conversation-parser.js +2 -861
  31. package/dist/runner/codex/managed-run-controller.js +2 -460
  32. package/dist/runner/codex-runner.js +2 -628
  33. package/dist/runner/fake-test-runner.js +2 -47
  34. package/dist/runner/opencode/conversation-parser.js +2 -221
  35. package/dist/runner/opencode/managed-run-controller.js +2 -537
  36. package/dist/runner/opencode-runner.js +2 -448
  37. package/dist/runner/runner-registry.js +2 -90
  38. package/dist/runner-command-engine.js +2 -70
  39. package/dist/runner-profiles.js +2 -215
  40. package/dist/runner-usage.js +2 -190
  41. package/dist/runtime-command-detector.js +2 -73
  42. package/dist/runtime-state.js +2 -982
  43. package/dist/service/attachment-domain-state.js +2 -7
  44. package/dist/service/conversation-history-service.js +2 -457
  45. package/dist/service/conversation-segment-service.js +2 -162
  46. package/dist/service/external-session-resume-service.js +2 -118
  47. package/dist/service/fake-managed-run-service.js +2 -60
  48. package/dist/service/managed-runner-session-service.js +2 -35
  49. package/dist/service/mcp-installation-verifier.js +2 -87
  50. package/dist/service/mcp-node-operation-service.js +2 -90
  51. package/dist/service/mcp-package-installer.js +2 -136
  52. package/dist/service/native-session-projection-service.js +2 -280
  53. package/dist/service/native-session-watch-service.js +2 -383
  54. package/dist/service/node-connection-lifecycle-service.js +2 -84
  55. package/dist/service/node-control-channel.js +2 -85
  56. package/dist/service/node-control-message-service.js +2 -107
  57. package/dist/service/node-request-service.js +2 -52
  58. package/dist/service/node-run-event-bridge.js +2 -83
  59. package/dist/service/node-terminal-channel.js +2 -182
  60. package/dist/service/node-upgrade-coordinator.js +2 -137
  61. package/dist/service/node-workspace-coordinator.js +2 -70
  62. package/dist/service/recent-run-projection-service.js +2 -78
  63. package/dist/service/run-attachment-service.js +2 -194
  64. package/dist/service/run-domain-state.js +2 -4
  65. package/dist/service/run-event-service.js +2 -193
  66. package/dist/service/run-workbench-service.js +2 -104
  67. package/dist/service/runner-channel-message-service.js +2 -20
  68. package/dist/service/runner-interaction-service.js +2 -243
  69. package/dist/service/runner-service.js +2 -71
  70. package/dist/service/session-catalog-service.js +2 -224
  71. package/dist/service/session-command-service.js +2 -76
  72. package/dist/service/session-context-service.js +2 -101
  73. package/dist/service/session-domain-state.js +2 -9
  74. package/dist/service/session-identity-service.js +2 -86
  75. package/dist/service/session-lifecycle-service.js +2 -240
  76. package/dist/service/session-message-service.js +2 -173
  77. package/dist/service/session-presentation-service.js +2 -43
  78. package/dist/service/session-query-service.js +2 -82
  79. package/dist/service/skill-directory-service.js +2 -238
  80. package/dist/service/skill-install-service.js +2 -434
  81. package/dist/service/skill-node-operation-service.js +2 -206
  82. package/dist/service/terminal-relay-state.js +2 -3
  83. package/dist/service/terminal-service.js +2 -52
  84. package/dist/service/workbench-event-service.js +2 -19
  85. package/dist/service/workbench-manifest-service.js +2 -69
  86. package/dist/service/workspace-change-service.js +2 -86
  87. package/dist/service/workspace-content-search-service.js +2 -477
  88. package/dist/service/workspace-domain-state.js +2 -41
  89. package/dist/service/workspace-file-service.js +2 -122
  90. package/dist/service/workspace-git-exclude-service.js +2 -119
  91. package/dist/service/workspace-queue-workbench-service.js +2 -304
  92. package/dist/service/workspace-service.js +2 -69
  93. package/dist/service/workspace-session-service.js +2 -139
  94. package/dist/service/workspace-upload-service.js +2 -262
  95. package/dist/service/workspace-watch-service.js +2 -146
  96. package/dist/service/workspace-workbench-service.js +2 -405
  97. package/dist/service.js +2 -38
  98. package/dist/storage.js +2 -32
  99. package/dist/supervisor.js +2 -136
  100. package/dist/terminal.js +2 -416
  101. package/dist/util/node-operation-parsers.js +2 -382
  102. package/dist/util/personal-instructions.js +2 -31
  103. package/dist/util/runner-error.js +2 -52
  104. package/dist/util/runner-native-session-parsers.js +2 -490
  105. package/dist/util/safe-error.js +2 -5
  106. package/dist/util/secret-environment.js +2 -25
  107. package/dist/workspace.js +2 -1519
  108. package/package.json +3 -3
  109. package/dist/capabilities.d.ts +0 -12
  110. package/dist/claude-agent-sdk.d.ts +0 -92
  111. package/dist/claude-channel.d.ts +0 -28
  112. package/dist/codex-app-server.d.ts +0 -133
  113. package/dist/config.d.ts +0 -18
  114. package/dist/connector/node-connector-options.d.ts +0 -27
  115. package/dist/connector/node-operation-router.d.ts +0 -9
  116. package/dist/connector.d.ts +0 -94
  117. package/dist/control-outbound-scheduler.d.ts +0 -29
  118. package/dist/database.d.ts +0 -305
  119. package/dist/event-buffer.d.ts +0 -9
  120. package/dist/fake-runner.d.ts +0 -42
  121. package/dist/health.d.ts +0 -4
  122. package/dist/main.d.ts +0 -2
  123. package/dist/migrations/v001.d.ts +0 -3
  124. package/dist/migrations/v002.d.ts +0 -4
  125. package/dist/migrations/v003.d.ts +0 -4
  126. package/dist/migrations/v004.d.ts +0 -4
  127. package/dist/native-jsonl-reader.d.ts +0 -35
  128. package/dist/native-session-history.d.ts +0 -126
  129. package/dist/opencode-runtime.d.ts +0 -33
  130. package/dist/opencode-server.d.ts +0 -49
  131. package/dist/operational.d.ts +0 -39
  132. package/dist/process-tree.d.ts +0 -9
  133. package/dist/rotating-log.d.ts +0 -17
  134. package/dist/runner/abstract-runner.d.ts +0 -172
  135. package/dist/runner/claude/managed-run-controller.d.ts +0 -51
  136. package/dist/runner/claude-code-runner.d.ts +0 -72
  137. package/dist/runner/codex/conversation-parser.d.ts +0 -59
  138. package/dist/runner/codex/managed-run-controller.d.ts +0 -90
  139. package/dist/runner/codex-runner.d.ts +0 -103
  140. package/dist/runner/fake-test-runner.d.ts +0 -26
  141. package/dist/runner/opencode/conversation-parser.d.ts +0 -31
  142. package/dist/runner/opencode/managed-run-controller.d.ts +0 -82
  143. package/dist/runner/opencode-runner.d.ts +0 -71
  144. package/dist/runner/runner-registry.d.ts +0 -19
  145. package/dist/runner-command-engine.d.ts +0 -28
  146. package/dist/runner-profiles.d.ts +0 -15
  147. package/dist/runner-usage.d.ts +0 -33
  148. package/dist/runtime-command-detector.d.ts +0 -3
  149. package/dist/runtime-state.d.ts +0 -171
  150. package/dist/service/attachment-domain-state.d.ts +0 -7
  151. package/dist/service/conversation-history-service.d.ts +0 -43
  152. package/dist/service/conversation-segment-service.d.ts +0 -20
  153. package/dist/service/external-session-resume-service.d.ts +0 -34
  154. package/dist/service/fake-managed-run-service.d.ts +0 -28
  155. package/dist/service/managed-runner-session-service.d.ts +0 -12
  156. package/dist/service/mcp-installation-verifier.d.ts +0 -9
  157. package/dist/service/mcp-node-operation-service.d.ts +0 -11
  158. package/dist/service/mcp-package-installer.d.ts +0 -8
  159. package/dist/service/native-session-projection-service.d.ts +0 -52
  160. package/dist/service/native-session-watch-service.d.ts +0 -62
  161. package/dist/service/node-connection-lifecycle-service.d.ts +0 -36
  162. package/dist/service/node-control-channel.d.ts +0 -32
  163. package/dist/service/node-control-message-service.d.ts +0 -27
  164. package/dist/service/node-request-service.d.ts +0 -14
  165. package/dist/service/node-run-event-bridge.d.ts +0 -40
  166. package/dist/service/node-terminal-channel.d.ts +0 -29
  167. package/dist/service/node-upgrade-coordinator.d.ts +0 -29
  168. package/dist/service/node-workspace-coordinator.d.ts +0 -29
  169. package/dist/service/recent-run-projection-service.d.ts +0 -14
  170. package/dist/service/run-attachment-service.d.ts +0 -38
  171. package/dist/service/run-domain-state.d.ts +0 -4
  172. package/dist/service/run-event-service.d.ts +0 -33
  173. package/dist/service/run-workbench-service.d.ts +0 -25
  174. package/dist/service/runner-channel-message-service.d.ts +0 -13
  175. package/dist/service/runner-interaction-service.d.ts +0 -39
  176. package/dist/service/runner-service.d.ts +0 -46
  177. package/dist/service/session-catalog-service.d.ts +0 -45
  178. package/dist/service/session-command-service.d.ts +0 -24
  179. package/dist/service/session-context-service.d.ts +0 -35
  180. package/dist/service/session-domain-state.d.ts +0 -9
  181. package/dist/service/session-identity-service.d.ts +0 -24
  182. package/dist/service/session-lifecycle-service.d.ts +0 -31
  183. package/dist/service/session-message-service.d.ts +0 -33
  184. package/dist/service/session-presentation-service.d.ts +0 -34
  185. package/dist/service/session-query-service.d.ts +0 -35
  186. package/dist/service/skill-directory-service.d.ts +0 -20
  187. package/dist/service/skill-install-service.d.ts +0 -21
  188. package/dist/service/skill-node-operation-service.d.ts +0 -44
  189. package/dist/service/terminal-relay-state.d.ts +0 -6
  190. package/dist/service/terminal-service.d.ts +0 -12
  191. package/dist/service/workbench-event-service.d.ts +0 -9
  192. package/dist/service/workbench-manifest-service.d.ts +0 -90
  193. package/dist/service/workspace-change-service.d.ts +0 -9
  194. package/dist/service/workspace-content-search-service.d.ts +0 -14
  195. package/dist/service/workspace-domain-state.d.ts +0 -79
  196. package/dist/service/workspace-file-service.d.ts +0 -18
  197. package/dist/service/workspace-git-exclude-service.d.ts +0 -4
  198. package/dist/service/workspace-queue-workbench-service.d.ts +0 -86
  199. package/dist/service/workspace-service.d.ts +0 -15
  200. package/dist/service/workspace-session-service.d.ts +0 -23
  201. package/dist/service/workspace-upload-service.d.ts +0 -39
  202. package/dist/service/workspace-watch-service.d.ts +0 -23
  203. package/dist/service/workspace-workbench-service.d.ts +0 -58
  204. package/dist/service.d.ts +0 -4
  205. package/dist/storage.d.ts +0 -2
  206. package/dist/supervisor.d.ts +0 -1
  207. package/dist/terminal.d.ts +0 -133
  208. package/dist/util/node-operation-parsers.d.ts +0 -92
  209. package/dist/util/personal-instructions.d.ts +0 -2
  210. package/dist/util/runner-error.d.ts +0 -6
  211. package/dist/util/runner-native-session-parsers.d.ts +0 -74
  212. package/dist/util/safe-error.d.ts +0 -2
  213. package/dist/util/secret-environment.d.ts +0 -1
  214. package/dist/workspace.d.ts +0 -217
@@ -1,982 +1,2 @@
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_RUN_EVENTS_PER_RUN = 100;
14
- static MAX_COMPLETED_TURNS_PER_SESSION = 10;
15
- sessions = new Map();
16
- runs = new Map();
17
- messageRuns = new Map();
18
- events = new Map();
19
- turns = new Map();
20
- approvals = new Map();
21
- /** A Session owns at most one running turn; Workspace sessions may run concurrently. */
22
- leases = new Map();
23
- /** Session FIFO metadata is deliberately process-local with the rest of run state. */
24
- queuedRuns = new Map();
25
- queueVersions = new Map();
26
- pausedQueues = new Set();
27
- /** Bounded tombstones reject stale internal start envelopes after terminal cleanup. */
28
- terminalRunIds = new Set();
29
- nextEventId = 1;
30
- constructor(nodeId, getWorkspace, now = Date.now, onRunChanged) {
31
- this.nodeId = nodeId;
32
- this.getWorkspace = getWorkspace;
33
- this.now = now;
34
- this.onRunChanged = onRunChanged;
35
- }
36
- activeWorkspaceLeaseCount() {
37
- return this.leases.size;
38
- }
39
- activeSessionRun(sessionId) {
40
- const runId = this.leases.get(sessionId);
41
- return runId === undefined ? undefined : this.runs.get(runId);
42
- }
43
- hasActiveSessionLease(sessionId) {
44
- return this.leases.has(sessionId);
45
- }
46
- createAgentSession(input) {
47
- if (this.getWorkspace(input.workspaceId) === undefined)
48
- throw new Error('WORKSPACE_NOT_FOUND');
49
- const now = this.now();
50
- const id = input.externalSessionId ?? randomUUID();
51
- if (this.sessions.has(id))
52
- throw new Error('SESSION_ID_CONFLICT');
53
- const value = {
54
- id,
55
- nodeId: this.nodeId(),
56
- workspaceId: input.workspaceId,
57
- runner: input.runner,
58
- externalSessionId: input.externalSessionId ?? null,
59
- nativeControl: input.externalSessionId === undefined ? 'MAR_MANAGED' : (input.nativeControl ?? 'EXTERNAL'),
60
- channelToken: null,
61
- cwd: input.cwd,
62
- model: input.model ?? null,
63
- effort: input.effort ?? null,
64
- access: input.access ?? null,
65
- customTitle: null,
66
- runnerTitle: input.title?.trim().slice(0, 160) || null,
67
- pinnedAt: null,
68
- // A first user prompt is only a process-local temporary title. A
69
- // Runner/native title can replace it on the next discovery refresh.
70
- titleSource: 'AUTO',
71
- lastActivityAt: now,
72
- createdAt: now
73
- };
74
- this.sessions.set(value.id, value);
75
- return value;
76
- }
77
- /** Internal envelope compatibility for a Run already accepted in this process. */
78
- adoptRun(input) {
79
- if (this.terminalRunIds.has(input.runId))
80
- throw new Error('RUN_TERMINAL');
81
- let session = this.sessions.get(input.sessionId);
82
- if (session === undefined) {
83
- const now = this.now();
84
- session = {
85
- id: input.sessionId,
86
- nodeId: this.nodeId(),
87
- workspaceId: input.workspaceId ?? `runtime:${input.cwd}`,
88
- runner: input.runner,
89
- externalSessionId: input.externalSessionId ?? null,
90
- nativeControl: input.externalSessionId === undefined ? 'MAR_MANAGED' : 'EXTERNAL',
91
- channelToken: null,
92
- cwd: input.cwd,
93
- model: null,
94
- effort: null,
95
- access: null,
96
- customTitle: null,
97
- runnerTitle: null,
98
- pinnedAt: null,
99
- titleSource: 'AUTO',
100
- lastActivityAt: now,
101
- createdAt: now
102
- };
103
- this.sessions.set(session.id, session);
104
- }
105
- const existing = this.runs.get(input.runId);
106
- if (existing !== undefined)
107
- return existing;
108
- const now = this.now();
109
- const run = {
110
- id: input.runId,
111
- sessionId: session.id,
112
- nodeId: this.nodeId(),
113
- workspaceId: session.workspaceId,
114
- runner: session.runner,
115
- status: 'QUEUED',
116
- recoveryState: 'ACTIVE',
117
- version: 0,
118
- clientMessageId: input.clientMessageId ?? input.runId,
119
- createdAt: now,
120
- updatedAt: now
121
- };
122
- this.runs.set(run.id, run);
123
- this.leases.set(run.sessionId, run.id);
124
- this.onRunChanged?.(run, session);
125
- return run;
126
- }
127
- getAgentSession(id) {
128
- return (this.sessions.get(id) ??
129
- [...this.sessions.values()].find((value) => value.externalSessionId === id));
130
- }
131
- listAgentSessions() {
132
- return [...this.sessions.values()].sort((a, b) => b.lastActivityAt - a.lastActivityAt);
133
- }
134
- findAgentSessionByExternalSession(runner, externalSessionId) {
135
- return [...this.sessions.values()].find((value) => value.runner === runner && value.externalSessionId === externalSessionId);
136
- }
137
- updateAgentSessionConfiguration(input) {
138
- return this.replaceSession(input.sessionId, {
139
- model: input.model,
140
- effort: input.effort,
141
- access: input.access
142
- });
143
- }
144
- setNativeControl(id, nativeControl) {
145
- this.replaceSession(id, { nativeControl });
146
- }
147
- setExternalSessionId(id, externalSessionId) {
148
- if (externalSessionId.length === 0)
149
- throw new Error('SESSION_EXTERNAL_ID_INVALID');
150
- this.promoteSessionIdentity(id, externalSessionId);
151
- }
152
- /**
153
- * Atomically replaces the bootstrap Session key with the Runner-native ID.
154
- * No caller may migrate the individual runtime maps independently.
155
- */
156
- promoteSessionIdentity(id, nativeSessionId) {
157
- if (nativeSessionId.length === 0)
158
- throw new Error('SESSION_EXTERNAL_ID_INVALID');
159
- const current = this.requireSession(id);
160
- if (id === nativeSessionId)
161
- return this.replaceSession(id, {
162
- externalSessionId: nativeSessionId,
163
- nativeControl: 'MAR_MANAGED'
164
- });
165
- const collision = this.sessions.get(nativeSessionId);
166
- if (collision !== undefined && collision.id !== current.id)
167
- throw new Error('SESSION_ID_CONFLICT');
168
- const next = {
169
- ...current,
170
- id: nativeSessionId,
171
- externalSessionId: nativeSessionId,
172
- nativeControl: 'MAR_MANAGED'
173
- };
174
- const runs = this.listRunsForSession(id);
175
- const turns = this.turns.get(id) ?? [];
176
- const queue = this.queuedRuns.get(id);
177
- const queueVersion = this.queueVersions.get(id);
178
- const lease = this.leases.get(id);
179
- const paused = this.pausedQueues.has(id);
180
- this.sessions.delete(id);
181
- this.sessions.set(nativeSessionId, next);
182
- for (const run of runs)
183
- this.runs.set(run.id, { ...run, sessionId: nativeSessionId });
184
- this.turns.delete(id);
185
- this.turns.set(nativeSessionId, turns.map((turn) => ({
186
- ...turn,
187
- sessionId: nativeSessionId,
188
- items: turn.items.map((item) => ({ ...item, sessionId: nativeSessionId }))
189
- })));
190
- if (queue !== undefined) {
191
- this.queuedRuns.delete(id);
192
- this.queuedRuns.set(nativeSessionId, queue);
193
- }
194
- if (queueVersion !== undefined) {
195
- this.queueVersions.delete(id);
196
- this.queueVersions.set(nativeSessionId, queueVersion);
197
- }
198
- if (lease !== undefined) {
199
- this.leases.delete(id);
200
- this.leases.set(nativeSessionId, lease);
201
- }
202
- if (paused) {
203
- this.pausedQueues.delete(id);
204
- this.pausedQueues.add(nativeSessionId);
205
- }
206
- for (const [key, runId] of [...this.messageRuns]) {
207
- if (!key.startsWith(`${id}\u0000`))
208
- continue;
209
- this.messageRuns.delete(key);
210
- this.messageRuns.set(`${nativeSessionId}${key.slice(id.length)}`, runId);
211
- }
212
- return next;
213
- }
214
- setChannelToken(id, channelToken) {
215
- if (channelToken.length < 16)
216
- throw new Error('SESSION_CHANNEL_TOKEN_INVALID');
217
- this.replaceSession(id, { channelToken });
218
- }
219
- updateSessionMetadata(input) {
220
- const current = this.requireSession(input.sessionId);
221
- const title = input.customTitle === undefined ? current.customTitle : input.customTitle?.trim() || null;
222
- if (title !== null && title.length > 160)
223
- throw new Error('SESSION_TITLE_INVALID');
224
- return this.replaceSession(current.id, {
225
- customTitle: title,
226
- pinnedAt: input.pinned === undefined ? current.pinnedAt : input.pinned ? this.now() : null,
227
- titleSource: title === null ? 'AUTO' : 'CUSTOM'
228
- });
229
- }
230
- /**
231
- * Give a just-created managed Session a readable local title before the
232
- * Runner has written its own transcript title. This intentionally never
233
- * replaces a user rename or a Runner-provided title.
234
- */
235
- setTemporaryTitleIfMissing(id, title) {
236
- const current = this.requireSession(id);
237
- const value = title.trim().replace(/\s+/g, ' ').slice(0, 160);
238
- if (value.length === 0 || current.customTitle !== null || current.runnerTitle !== null)
239
- return current;
240
- return this.replaceSession(id, { runnerTitle: value, titleSource: 'AUTO' });
241
- }
242
- /**
243
- * Runner/native discovery is authoritative for its own title. Keep it on
244
- * the managed Session so later `session.get` polls cannot regress to an
245
- * empty fallback after a discovery response has already shown the title.
246
- */
247
- setRunnerTitleFromNative(id, title) {
248
- const current = this.requireSession(id);
249
- const value = title.trim().replace(/\s+/g, ' ').slice(0, 160);
250
- if (value.length === 0 || current.customTitle !== null || current.runnerTitle === value)
251
- return current;
252
- return this.replaceSession(id, { runnerTitle: value, titleSource: 'RUNNER' });
253
- }
254
- createMessageRun(input) {
255
- const key = `${input.sessionId}\u0000${input.clientMessageId}`;
256
- const duplicate = this.messageRuns.get(key);
257
- if (duplicate !== undefined)
258
- return { run: this.requireRun(duplicate), created: false };
259
- const session = this.requireSession(input.sessionId);
260
- const now = this.now();
261
- const run = {
262
- id: input.runId ?? randomUUID(),
263
- sessionId: session.id,
264
- nodeId: this.nodeId(),
265
- workspaceId: session.workspaceId,
266
- runner: session.runner,
267
- status: 'QUEUED',
268
- recoveryState: 'ACTIVE',
269
- version: 0,
270
- clientMessageId: input.clientMessageId,
271
- ...(input.initiatedByUserId === undefined
272
- ? {}
273
- : { initiatedByUserId: input.initiatedByUserId }),
274
- createdAt: now,
275
- updatedAt: now
276
- };
277
- let imageIndex = 0;
278
- const attachments = (input.attachments ?? []).map(({ name, mime, dataBase64 }) => {
279
- const attachment = {
280
- name,
281
- mime,
282
- byteSize: Buffer.byteLength(dataBase64, 'base64'),
283
- runId: run.id
284
- };
285
- if (!mime.startsWith('image/'))
286
- return attachment;
287
- return { ...attachment, imageIndex: imageIndex++ };
288
- });
289
- const user = {
290
- id: randomUUID(),
291
- sessionId: session.id,
292
- turnId: '',
293
- runId: run.id,
294
- parentItemId: null,
295
- sourceSequence: null,
296
- revision: 0,
297
- kind: 'user_message',
298
- status: 'COMPLETED',
299
- payload: {
300
- clientMessageId: input.clientMessageId,
301
- text: input.content,
302
- contexts: [],
303
- attachments,
304
- delivery: 'ACCEPTED'
305
- },
306
- startedAt: now,
307
- completedAt: now
308
- };
309
- const turn = {
310
- id: randomUUID(),
311
- sessionId: session.id,
312
- runId: run.id,
313
- userItemId: user.id,
314
- status: 'QUEUED',
315
- model: session.model,
316
- effort: session.effort,
317
- access: session.access,
318
- items: [user],
319
- startedAt: null,
320
- completedAt: null
321
- };
322
- const fixedTurn = { ...turn, items: [{ ...user, turnId: turn.id }] };
323
- this.runs.set(run.id, run);
324
- this.messageRuns.set(key, run.id);
325
- this.queuedRuns.set(session.id, [...(this.queuedRuns.get(session.id) ?? []), run.id]);
326
- this.bumpQueueVersion(session.id);
327
- this.turns.set(session.id, [...(this.turns.get(session.id) ?? []), fixedTurn]);
328
- this.replaceSession(session.id, { lastActivityAt: now });
329
- this.onRunChanged?.(run, this.requireSession(session.id));
330
- return { run, created: true };
331
- }
332
- sessionQueue(sessionId) {
333
- return {
334
- version: this.queueVersions.get(sessionId) ?? 0,
335
- paused: this.pausedQueues.has(sessionId),
336
- runIds: this.queuedRuns.get(sessionId) ?? []
337
- };
338
- }
339
- isQueuedRun(runId) {
340
- const run = this.requireRun(runId);
341
- return (this.queuedRuns.get(run.sessionId) ?? []).includes(runId);
342
- }
343
- claimNextQueuedRun(sessionId) {
344
- if (this.leases.has(sessionId) || this.pausedQueues.has(sessionId))
345
- return undefined;
346
- const queue = this.queuedRuns.get(sessionId) ?? [];
347
- const runId = queue[0];
348
- if (runId === undefined)
349
- return undefined;
350
- this.queuedRuns.set(sessionId, queue.slice(1));
351
- this.bumpQueueVersion(sessionId);
352
- const run = this.requireRun(runId);
353
- this.leases.set(sessionId, run.id);
354
- return run;
355
- }
356
- pauseSessionQueue(sessionId) {
357
- this.pausedQueues.add(sessionId);
358
- this.bumpQueueVersion(sessionId);
359
- }
360
- resumeSessionQueue(sessionId) {
361
- if (!this.pausedQueues.delete(sessionId))
362
- return;
363
- this.bumpQueueVersion(sessionId);
364
- }
365
- reorderSessionQueue(sessionId, expectedVersion, runIds) {
366
- const current = this.queuedRuns.get(sessionId) ?? [];
367
- if (this.sessionQueue(sessionId).version !== expectedVersion ||
368
- current.length !== runIds.length ||
369
- new Set(current).size !== current.length ||
370
- current.some((runId) => !runIds.includes(runId)))
371
- throw new Error('QUEUE_VERSION_CONFLICT');
372
- if (runIds.some((runId) => this.requireRun(runId).status !== 'QUEUED'))
373
- throw new Error('QUEUE_ITEM_INVALID');
374
- this.queuedRuns.set(sessionId, [...runIds]);
375
- this.bumpQueueVersion(sessionId);
376
- }
377
- prioritizeQueuedRun(runId) {
378
- const run = this.requireRun(runId);
379
- const queue = this.queuedRuns.get(run.sessionId) ?? [];
380
- if (!queue.includes(runId) || run.status !== 'QUEUED')
381
- throw new Error('QUEUE_ITEM_INVALID');
382
- this.queuedRuns.set(run.sessionId, [
383
- runId,
384
- ...queue.filter((candidate) => candidate !== runId)
385
- ]);
386
- this.bumpQueueVersion(run.sessionId);
387
- return run;
388
- }
389
- updateQueuedMessage(runId, content) {
390
- const run = this.requireRun(runId);
391
- if (!(this.queuedRuns.get(run.sessionId) ?? []).includes(runId) || run.status !== 'QUEUED')
392
- throw new Error('QUEUE_ITEM_INVALID');
393
- this.updateTurnForRun(runId, (turn) => ({
394
- ...turn,
395
- items: turn.items.map((item) => item.id === turn.userItemId && isRecord(item.payload)
396
- ? { ...item, payload: { ...item.payload, text: content } }
397
- : item)
398
- }));
399
- this.bumpQueueVersion(run.sessionId);
400
- return run;
401
- }
402
- deleteQueuedRun(runId) {
403
- const run = this.requireRun(runId);
404
- const queue = this.queuedRuns.get(run.sessionId) ?? [];
405
- if (!queue.includes(runId) || run.status !== 'QUEUED')
406
- throw new Error('QUEUE_ITEM_INVALID');
407
- this.queuedRuns.set(run.sessionId, queue.filter((candidate) => candidate !== runId));
408
- this.bumpQueueVersion(run.sessionId);
409
- this.runs.delete(runId);
410
- this.events.delete(runId);
411
- this.turns.set(run.sessionId, (this.turns.get(run.sessionId) ?? []).filter((turn) => turn.runId !== runId));
412
- for (const [key, candidate] of this.messageRuns)
413
- if (candidate === runId)
414
- this.messageRuns.delete(key);
415
- }
416
- queuedMessageText(runId) {
417
- const run = this.requireRun(runId);
418
- const turn = (this.turns.get(run.sessionId) ?? []).find((candidate) => candidate.runId === runId);
419
- const item = turn?.items.find((candidate) => candidate.id === turn.userItemId);
420
- return isRecord(item?.payload) && typeof item.payload.text === 'string'
421
- ? item.payload.text
422
- : '';
423
- }
424
- getRun(id) {
425
- return this.runs.get(id);
426
- }
427
- findMessageRun(sessionId, clientMessageId) {
428
- const runId = this.messageRuns.get(`${sessionId}\u0000${clientMessageId}`);
429
- return runId === undefined ? undefined : this.runs.get(runId);
430
- }
431
- listRunsForSession(sessionId) {
432
- return [...this.runs.values()]
433
- .filter((run) => run.sessionId === sessionId)
434
- .sort((a, b) => b.createdAt - a.createdAt);
435
- }
436
- transitionRun(id, next) {
437
- const current = this.requireRun(id);
438
- if (!transitionAllowed(current.status, next))
439
- throw new Error('RUN_STATE_INVALID');
440
- const value = { ...current, status: next, version: current.version + 1, updatedAt: this.now() };
441
- this.runs.set(id, value);
442
- this.onRunChanged?.(value, this.requireSession(value.sessionId));
443
- if (terminal(next) && this.leases.get(value.sessionId) === value.id)
444
- this.leases.delete(value.sessionId);
445
- this.updateTurnForRun(id, (turn) => ({
446
- ...turn,
447
- status: next,
448
- completedAt: terminal(next) ? this.now() : turn.completedAt,
449
- items: terminal(next)
450
- ? turn.items.map((item) => activeConversationItem(item.status)
451
- ? { ...item, status: completedStatusForRun(next), completedAt: this.now() }
452
- : item)
453
- : turn.items
454
- }));
455
- return value;
456
- }
457
- appendRunEvent(input) {
458
- this.requireRun(input.runId);
459
- const prior = this.events.get(input.runId) ?? [];
460
- if (prior.some((event) => event.sequence === input.sequence))
461
- return undefined;
462
- if (input.sequence > (prior.at(-1)?.sequence ?? 0) + 1)
463
- throw new Error('EVENT_SEQUENCE_GAP');
464
- const value = {
465
- id: this.nextEventId++,
466
- runId: input.runId,
467
- sequence: input.sequence,
468
- eventType: input.eventType,
469
- payload: input.payload,
470
- ...(input.status === undefined ? {} : { status: input.status }),
471
- createdAt: this.now()
472
- };
473
- this.events.set(input.runId, [...prior, value].slice(-NodeRuntimeState.MAX_RUN_EVENTS_PER_RUN));
474
- if (input.status !== undefined)
475
- this.transitionRun(input.runId, input.status);
476
- this.projectEvent(value);
477
- return value;
478
- }
479
- listRunEvents(id, after = 0) {
480
- return (this.events.get(id) ?? []).filter((event) => event.sequence > after);
481
- }
482
- listConversationTurns(input) {
483
- this.requireSession(input.sessionId);
484
- // A managed Turn keeps the user's acceptance time as its stable timeline
485
- // position. Runner start/completion timestamps must not move it behind a
486
- // message that was accepted later. Native Turns without a user timestamp
487
- // fall back to their own lifecycle time.
488
- const all = [...(this.turns.get(input.sessionId) ?? [])]
489
- .map((turn, index) => ({ turn, index }))
490
- .sort((a, b) => {
491
- const timestamp = (value) => value.items.find((item) => item.id === value.userItemId)?.startedAt ??
492
- value.startedAt ??
493
- value.completedAt ??
494
- 0;
495
- return timestamp(a.turn) - timestamp(b.turn) || a.index - b.index;
496
- })
497
- .map(({ turn }) => turn);
498
- const end = input.cursor === undefined ? all.length : decodeCursor(input.cursor, input.sessionId);
499
- const limit = Math.min(Math.max(input.limit ?? 30, 1), 500);
500
- const start = Math.max(0, end - limit);
501
- const slice = all.slice(start, end);
502
- return {
503
- turns: slice,
504
- nextCursor: start > 0 ? encodeCursor(input.sessionId, start) : null
505
- };
506
- }
507
- conversationTurnForRun(runId) {
508
- for (const turns of this.turns.values()) {
509
- const turn = turns.find((candidate) => candidate.runId === runId);
510
- if (turn !== undefined)
511
- return turn;
512
- }
513
- return undefined;
514
- }
515
- listConversationItems(input) {
516
- const turns = this.listConversationTurns(input).turns;
517
- return { items: turns.flatMap((turn) => turn.items), nextCursor: null };
518
- }
519
- recordCommandExecution(input) {
520
- const session = this.requireSession(input.sessionId);
521
- const now = this.now();
522
- const item = {
523
- id: randomUUID(),
524
- sessionId: input.sessionId,
525
- turnId: '',
526
- runId: null,
527
- parentItemId: null,
528
- sourceSequence: null,
529
- revision: 1,
530
- kind: 'command_execution',
531
- status: input.failed ? 'FAILED' : 'COMPLETED',
532
- payload: {
533
- command: input.command,
534
- cwd: input.cwd,
535
- outputPreview: input.outputPreview.slice(0, 10_000),
536
- outputRef: null,
537
- exitCode: input.failed ? 1 : 0,
538
- durationMs: 0,
539
- truncated: false
540
- },
541
- startedAt: now,
542
- completedAt: now
543
- };
544
- const turn = {
545
- id: randomUUID(),
546
- sessionId: input.sessionId,
547
- runId: null,
548
- userItemId: null,
549
- status: input.failed ? 'FAILED' : 'SUCCEEDED',
550
- model: session.model,
551
- effort: session.effort,
552
- access: session.access,
553
- items: [],
554
- startedAt: now,
555
- completedAt: now
556
- };
557
- const completedItem = { ...item, turnId: turn.id };
558
- const completedTurn = { ...turn, items: [completedItem] };
559
- this.turns.set(input.sessionId, [...(this.turns.get(input.sessionId) ?? []), completedTurn]);
560
- this.replaceSession(session.id, { lastActivityAt: now });
561
- return completedTurn;
562
- }
563
- createApproval(input) {
564
- this.requireRun(input.runId);
565
- if (this.approvals.has(input.approvalId))
566
- throw new Error('APPROVAL_ALREADY_EXISTS');
567
- if (input.expiresAt <= this.now())
568
- throw new Error('APPROVAL_EXPIRED');
569
- const value = {
570
- id: input.approvalId,
571
- runId: input.runId,
572
- status: 'PENDING',
573
- payload: input.payload,
574
- expiresAt: input.expiresAt,
575
- createdAt: this.now(),
576
- decidedAt: null
577
- };
578
- this.approvals.set(value.id, value);
579
- return value;
580
- }
581
- getApproval(id) {
582
- const value = this.approvals.get(id);
583
- if (value?.status === 'PENDING' && value.expiresAt <= this.now())
584
- return this.expireApproval(id);
585
- return value;
586
- }
587
- listApprovals(runId) {
588
- return [...this.approvals.values()]
589
- .filter((value) => value.runId === runId)
590
- .map((value) => this.getApproval(value.id));
591
- }
592
- expireApproval(id) {
593
- const value = this.requireApproval(id);
594
- if (value.status !== 'PENDING')
595
- return value;
596
- if (value.expiresAt > this.now())
597
- throw new Error('APPROVAL_NOT_EXPIRED');
598
- const next = { ...value, status: 'EXPIRED', decidedAt: this.now() };
599
- this.approvals.set(id, next);
600
- return next;
601
- }
602
- decideApproval(id, decision) {
603
- const value = this.getApproval(id);
604
- if (value === undefined)
605
- throw new Error('APPROVAL_NOT_FOUND');
606
- if (value.status === 'EXPIRED')
607
- throw new Error('APPROVAL_EXPIRED');
608
- if (value.status !== 'PENDING')
609
- throw new Error('APPROVAL_ALREADY_DECIDED');
610
- const next = { ...value, status: decision, decidedAt: this.now() };
611
- this.approvals.set(id, next);
612
- return next;
613
- }
614
- expireDueApprovals() {
615
- return [...this.approvals.values()]
616
- .filter((value) => value.status === 'PENDING' && value.expiresAt <= this.now())
617
- .map((value) => this.expireApproval(value.id));
618
- }
619
- listNonterminalRuns() {
620
- return [...this.runs.values()].filter((run) => !terminal(run.status));
621
- }
622
- lastRunSequence(id) {
623
- return this.events.get(id)?.at(-1)?.sequence ?? 0;
624
- }
625
- removeTerminalRun(runId) {
626
- const run = this.requireRun(runId);
627
- if (!terminal(run.status))
628
- throw new Error('RUN_ACTIVE');
629
- this.terminalRunIds.add(runId);
630
- if (this.terminalRunIds.size > 1_024)
631
- this.terminalRunIds.delete(this.terminalRunIds.values().next().value);
632
- const queue = this.queuedRuns.get(run.sessionId) ?? [];
633
- if (queue.includes(runId)) {
634
- this.queuedRuns.set(run.sessionId, queue.filter((candidate) => candidate !== runId));
635
- this.bumpQueueVersion(run.sessionId);
636
- }
637
- this.runs.delete(runId);
638
- this.events.delete(runId);
639
- const turns = (this.turns.get(run.sessionId) ?? []).filter((turn) => {
640
- const hasVisibleError = turn.items.some((item) => item.kind === 'error');
641
- if (turn.runId === runId)
642
- return run.status === 'SUCCEEDED' || run.status === 'INTERRUPTED' || hasVisibleError;
643
- const isTransientErrorTurn = hasVisibleError && turn.status !== 'SUCCEEDED' && turn.status !== 'INTERRUPTED';
644
- return run.status !== 'SUCCEEDED' || !isTransientErrorTurn;
645
- });
646
- const completed = turns.filter((turn) => terminalTurn(turn.status));
647
- const retainedCompleted = new Set(completed.slice(-NodeRuntimeState.MAX_COMPLETED_TURNS_PER_SESSION).map((turn) => turn.id));
648
- this.turns.set(run.sessionId, turns.filter((turn) => !terminalTurn(turn.status) || retainedCompleted.has(turn.id)));
649
- for (const [key, candidate] of this.messageRuns)
650
- if (candidate === runId)
651
- this.messageRuns.delete(key);
652
- for (const [approvalId, approval] of this.approvals)
653
- if (approval.runId === runId)
654
- this.approvals.delete(approvalId);
655
- }
656
- hasActiveWorkspaceLease(workspaceId) {
657
- return [...this.leases.values()]
658
- .map((runId) => this.runs.get(runId))
659
- .some((run) => run?.workspaceId === workspaceId);
660
- }
661
- /** Removes a terminal Session's process-local projection after its native history is deleted. */
662
- removeAgentSession(sessionId) {
663
- this.requireSession(sessionId);
664
- const runs = this.listRunsForSession(sessionId);
665
- if (runs.some((run) => !terminal(run.status)))
666
- throw new Error('SESSION_ACTIVE');
667
- const runIds = new Set(runs.map((run) => run.id));
668
- this.sessions.delete(sessionId);
669
- this.turns.delete(sessionId);
670
- this.queuedRuns.delete(sessionId);
671
- this.queueVersions.delete(sessionId);
672
- this.pausedQueues.delete(sessionId);
673
- this.leases.delete(sessionId);
674
- for (const runId of runIds) {
675
- this.runs.delete(runId);
676
- this.events.delete(runId);
677
- }
678
- for (const [key, runId] of this.messageRuns)
679
- if (runIds.has(runId))
680
- this.messageRuns.delete(key);
681
- for (const [approvalId, approval] of this.approvals)
682
- if (runIds.has(approval.runId))
683
- this.approvals.delete(approvalId);
684
- }
685
- removeWorkspace(workspaceId) {
686
- if (this.hasActiveWorkspaceLease(workspaceId))
687
- throw new Error('WORKSPACE_BUSY');
688
- const sessionIds = new Set([...this.sessions.values()]
689
- .filter((session) => session.workspaceId === workspaceId)
690
- .map((session) => session.id));
691
- const runIds = new Set([...this.runs.values()].filter((run) => run.workspaceId === workspaceId).map((run) => run.id));
692
- for (const sessionId of sessionIds) {
693
- this.sessions.delete(sessionId);
694
- this.turns.delete(sessionId);
695
- }
696
- for (const runId of runIds) {
697
- this.runs.delete(runId);
698
- this.events.delete(runId);
699
- }
700
- for (const [key, runId] of this.messageRuns)
701
- if (runIds.has(runId))
702
- this.messageRuns.delete(key);
703
- for (const [approvalId, approval] of this.approvals)
704
- if (runIds.has(approval.runId))
705
- this.approvals.delete(approvalId);
706
- for (const sessionId of sessionIds) {
707
- this.queuedRuns.delete(sessionId);
708
- this.queueVersions.delete(sessionId);
709
- this.pausedQueues.delete(sessionId);
710
- this.leases.delete(sessionId);
711
- }
712
- }
713
- reconcileRun(id, active) {
714
- // There is no cross-restart run recovery: this process-local state is
715
- // discarded on restart and cannot be reconciled from SQLite.
716
- void id;
717
- void active;
718
- }
719
- replaceSession(id, patch) {
720
- const value = this.requireSession(id);
721
- const next = { ...value, ...patch };
722
- this.sessions.set(id, next);
723
- if (value.customTitle !== next.customTitle || value.runnerTitle !== next.runnerTitle)
724
- for (const run of this.listRunsForSession(id))
725
- this.onRunChanged?.(run, next);
726
- return next;
727
- }
728
- bumpQueueVersion(sessionId) {
729
- this.queueVersions.set(sessionId, (this.queueVersions.get(sessionId) ?? 0) + 1);
730
- }
731
- requireSession(id) {
732
- const value = this.sessions.get(id);
733
- if (value === undefined)
734
- throw new Error('SESSION_NOT_FOUND');
735
- return value;
736
- }
737
- requireRun(id) {
738
- const value = this.runs.get(id);
739
- if (value === undefined)
740
- throw new Error('RUN_NOT_FOUND');
741
- return value;
742
- }
743
- requireApproval(id) {
744
- const value = this.approvals.get(id);
745
- if (value === undefined)
746
- throw new Error('APPROVAL_NOT_FOUND');
747
- return value;
748
- }
749
- updateTurnForRun(runId, update) {
750
- const run = this.requireRun(runId);
751
- const current = this.turns.get(run.sessionId) ?? [];
752
- this.turns.set(run.sessionId, current.map((turn) => (turn.runId === runId ? update(turn) : turn)));
753
- }
754
- projectEvent(event) {
755
- const run = this.requireRun(event.runId);
756
- this.updateTurnForRun(event.runId, (turn) => {
757
- if (event.eventType === 'text.delta' &&
758
- isRecord(event.payload) &&
759
- typeof event.payload.text === 'string') {
760
- const nativeItemId = typeof event.payload.itemId === 'string' && event.payload.itemId.length <= 88
761
- ? event.payload.itemId
762
- : undefined;
763
- const stableItemId = nativeItemId === undefined ? undefined : `${event.runId}:${nativeItemId}`;
764
- const lastItem = turn.items.at(-1);
765
- const existing = stableItemId === undefined
766
- ? lastItem?.kind === 'assistant_message' && activeConversationItem(lastItem.status)
767
- ? lastItem
768
- : undefined
769
- : turn.items.find((item) => item.id === stableItemId && item.kind === 'assistant_message');
770
- const text = `${existing === undefined ? '' : readableText(existing.payload)}${event.payload.text}`;
771
- const item = {
772
- id: existing?.id ?? stableItemId ?? `${event.runId}:assistant:${event.sequence}`,
773
- sessionId: run.sessionId,
774
- turnId: turn.id,
775
- runId: event.runId,
776
- parentItemId: null,
777
- sourceSequence: existing?.sourceSequence ?? event.sequence,
778
- revision: event.sequence,
779
- kind: 'assistant_message',
780
- status: 'IN_PROGRESS',
781
- payload: { text, format: 'markdown', model: null },
782
- startedAt: existing?.startedAt ?? event.createdAt,
783
- completedAt: null
784
- };
785
- return {
786
- ...turn,
787
- status: 'RUNNING',
788
- startedAt: turn.startedAt ?? event.createdAt,
789
- items: existing === undefined
790
- ? [...turn.items, item]
791
- : turn.items.map((value) => (value.id === item.id ? item : value))
792
- };
793
- }
794
- const projected = conversationItemFromEvent(event);
795
- if (projected !== undefined) {
796
- const trailingItem = turn.items.at(-1);
797
- const orderedItems = trailingItem?.kind === 'assistant_message' && activeConversationItem(trailingItem.status)
798
- ? turn.items.map((item) => item.id === trailingItem.id
799
- ? { ...item, status: 'COMPLETED', completedAt: event.createdAt }
800
- : item)
801
- : turn.items;
802
- const existing = orderedItems.find((item) => item.id === `${event.runId}:${projected.itemId}`);
803
- const status = projected.status;
804
- const item = {
805
- id: `${event.runId}:${projected.itemId}`,
806
- sessionId: run.sessionId,
807
- turnId: turn.id,
808
- runId: event.runId,
809
- parentItemId: null,
810
- sourceSequence: existing?.sourceSequence ?? event.sequence,
811
- revision: (existing?.revision ?? -1) + 1,
812
- kind: projected.kind,
813
- status,
814
- payload: mergeConversationItemPayload(existing?.payload, projected),
815
- startedAt: existing?.startedAt ?? event.createdAt,
816
- completedAt: completedConversationItem(status) ? event.createdAt : null
817
- };
818
- return {
819
- ...turn,
820
- status: terminal(run.status) ? run.status : 'RUNNING',
821
- startedAt: turn.startedAt ?? event.createdAt,
822
- items: existing === undefined
823
- ? [...orderedItems, item]
824
- : orderedItems.map((value) => (value.id === item.id ? item : value))
825
- };
826
- }
827
- if (event.eventType === 'run.started' || event.eventType === 'run.running')
828
- return { ...turn, status: 'RUNNING', startedAt: turn.startedAt ?? event.createdAt };
829
- if (event.eventType === 'run.completed' ||
830
- event.eventType === 'run.failed' ||
831
- event.eventType === 'run.rejected') {
832
- return {
833
- ...turn,
834
- status: this.requireRun(event.runId).status,
835
- completedAt: event.createdAt,
836
- items: turn.items.map((item) => activeConversationItem(item.status)
837
- ? {
838
- ...item,
839
- status: completedStatusForRun(this.requireRun(event.runId).status),
840
- completedAt: event.createdAt
841
- }
842
- : item)
843
- };
844
- }
845
- return turn;
846
- });
847
- }
848
- }
849
- function terminal(status) {
850
- return ['SUCCEEDED', 'FAILED', 'CANCELLED', 'INTERRUPTED', 'LOST'].includes(status);
851
- }
852
- function terminalTurn(status) {
853
- return ['SUCCEEDED', 'FAILED', 'CANCELLED', 'INTERRUPTED', 'LOST'].includes(status);
854
- }
855
- function transitionAllowed(from, to) {
856
- return !terminal(from) || from === to;
857
- }
858
- function isRecord(value) {
859
- return typeof value === 'object' && value !== null;
860
- }
861
- function readableText(value) {
862
- return isRecord(value) && typeof value.text === 'string' ? value.text : '';
863
- }
864
- function conversationItemFromEvent(event) {
865
- if (event.eventType !== 'conversation.item' || !isRecord(event.payload))
866
- return undefined;
867
- const itemId = event.payload.itemId;
868
- const kind = event.payload.kind;
869
- const status = event.payload.status;
870
- const payload = event.payload.payload;
871
- if (typeof itemId !== 'string' ||
872
- itemId.length === 0 ||
873
- itemId.length > 88 ||
874
- typeof kind !== 'string' ||
875
- !projectableConversationKind(kind) ||
876
- typeof status !== 'string' ||
877
- !projectableConversationStatus(status) ||
878
- !isRecord(payload))
879
- return undefined;
880
- const append = event.payload.append;
881
- return {
882
- itemId,
883
- kind,
884
- status,
885
- payload,
886
- merge: event.payload.merge === true,
887
- ...(append === 'sections' || append === 'outputPreview' || append === 'outputSummary'
888
- ? { append }
889
- : {})
890
- };
891
- }
892
- function projectableConversationKind(value) {
893
- return (value === 'assistant_message' ||
894
- value === 'reasoning_summary' ||
895
- value === 'tool_call' ||
896
- value === 'command_execution' ||
897
- value === 'user_input_request' ||
898
- value === 'plan' ||
899
- value === 'file_change' ||
900
- value === 'context_compaction' ||
901
- value === 'unknown' ||
902
- value === 'warning' ||
903
- value === 'error');
904
- }
905
- function projectableConversationStatus(value) {
906
- return [
907
- 'PENDING',
908
- 'IN_PROGRESS',
909
- 'COMPLETED',
910
- 'FAILED',
911
- 'DECLINED',
912
- 'CANCELLED',
913
- 'INTERRUPTED'
914
- ].includes(value);
915
- }
916
- function mergeConversationItemPayload(existing, next) {
917
- const base = next.merge && isRecord(existing) ? existing : {};
918
- const value = { ...base, ...next.payload };
919
- if (next.append === 'sections') {
920
- const prior = Array.isArray(base.sections) ? base.sections : [];
921
- const incoming = Array.isArray(next.payload.sections) ? next.payload.sections : [];
922
- const sections = new Map();
923
- for (const section of [...prior, ...incoming]) {
924
- if (!isRecord(section) ||
925
- typeof section.index !== 'number' ||
926
- !Number.isInteger(section.index) ||
927
- section.index < 0 ||
928
- typeof section.text !== 'string')
929
- continue;
930
- sections.set(section.index, appendProjectionText(sections.get(section.index) ?? '', section.text));
931
- }
932
- value.sections = [...sections]
933
- .sort(([left], [right]) => left - right)
934
- .map(([index, text]) => ({ index, text }));
935
- }
936
- if (next.append === 'outputPreview') {
937
- const prior = typeof base.outputPreview === 'string' ? base.outputPreview : '';
938
- const incoming = typeof next.payload.outputPreview === 'string' ? next.payload.outputPreview : '';
939
- value.outputPreview = appendProjectionText(prior, incoming);
940
- }
941
- if (next.append === 'outputSummary') {
942
- const prior = typeof base.outputSummary === 'string' ? base.outputSummary : '';
943
- const incoming = typeof next.payload.outputSummary === 'string' ? next.payload.outputSummary : '';
944
- value.outputSummary = appendProjectionText(prior, incoming);
945
- }
946
- return value;
947
- }
948
- function appendProjectionText(previous, next) {
949
- const text = `${previous}${next}`;
950
- return text.length <= 10_000 ? text : `${text.slice(0, 9_999)}…`;
951
- }
952
- function activeConversationItem(status) {
953
- return status === 'PENDING' || status === 'IN_PROGRESS';
954
- }
955
- function completedConversationItem(status) {
956
- return !activeConversationItem(status);
957
- }
958
- function completedStatusForRun(status) {
959
- if (status === 'INTERRUPTED')
960
- return 'INTERRUPTED';
961
- if (status === 'CANCELLED')
962
- return 'CANCELLED';
963
- if (status === 'FAILED')
964
- return 'FAILED';
965
- return 'COMPLETED';
966
- }
967
- function encodeCursor(scope, value) {
968
- return Buffer.from(JSON.stringify({ scope, value })).toString('base64url');
969
- }
970
- function decodeCursor(cursor, scope) {
971
- if (cursor === undefined)
972
- return 0;
973
- try {
974
- const value = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8'));
975
- return value.scope === scope && Number.isInteger(value.value) && value.value >= 0
976
- ? value.value
977
- : 0;
978
- }
979
- catch {
980
- return 0;
981
- }
982
- }
1
+ /* mar-release-protected */
2
+ function _0x4eb3(_0x28b545,_0x4991cf){_0x28b545=_0x28b545-(0x1de0+-0x1*0x5cb+-0x2*0xb48);const _0x15be66=_0xaa7e();let _0x5d2b68=_0x15be66[_0x28b545];if(_0x4eb3['gWWVOY']===undefined){var _0x4bb489=function(_0x209dca){const _0x7f37c0='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x31dcbd='',_0x4c8b2b='';for(let _0x49727e=0xa8+0x45e+0x1*-0x506,_0x167853,_0x315851,_0x1133b8=-0x1635+0x2342*0x1+0xd*-0x101;_0x315851=_0x209dca['charAt'](_0x1133b8++);~_0x315851&&(_0x167853=_0x49727e%(0xbb*0x2b+-0x139*0x1+-0x1e2c)?_0x167853*(-0x109f+-0xea5+0xfc2*0x2)+_0x315851:_0x315851,_0x49727e++%(0x3*0x4f0+0x17*-0x126+0x1*0xb9e))?_0x31dcbd+=String['fromCharCode'](0xc7a+-0x1*-0x2457+0x17e9*-0x2&_0x167853>>(-(-0x62b*0x6+-0x1c7f+-0x1*-0x4183)*_0x49727e&0x4f4*0x7+0xd7c+-0x7a*0x65)):-0x337*0x7+0x1*-0x1322+0xb*0x3c9){_0x315851=_0x7f37c0['indexOf'](_0x315851);}for(let _0x5eae92=-0xb2c+0x1df4+-0x12c8,_0x3717fc=_0x31dcbd['length'];_0x5eae92<_0x3717fc;_0x5eae92++){_0x4c8b2b+='%'+('00'+_0x31dcbd['charCodeAt'](_0x5eae92)['toString'](-0x139*0x1+-0xb+0x11*0x14))['slice'](-(-0x1080+0x223b+0x1*-0x11b9));}return decodeURIComponent(_0x4c8b2b);};_0x4eb3['bwNISF']=_0x4bb489,_0x4eb3['ToWvjn']={},_0x4eb3['gWWVOY']=!![];}const _0x399105=_0x15be66[-0x2*0x1381+0x1*0x254b+0x1*0x1b7];_0x4eb3['HSJGTE']!==_0x399105&&(_0x4eb3['ToWvjn']={},_0x4eb3['HSJGTE']=_0x399105);const _0x212cfd=_0x4eb3['ToWvjn'][_0x28b545];return _0x212cfd===undefined?(_0x5d2b68=_0x4eb3['bwNISF'](_0x5d2b68),_0x4eb3['ToWvjn'][_0x28b545]=_0x5d2b68):_0x5d2b68=_0x212cfd,_0x5d2b68;}const _0x4daaad=_0x4eb3;(function(_0x8d76e1,_0x511d94){const _0x4f6550=_0x4eb3,_0xea5a6a=_0x8d76e1();while(!![]){try{const _0x1b9e1c=-parseInt(_0x4f6550(0x244))/(0x486+-0x1507+0x1082)+parseInt(_0x4f6550(0x223))/(-0x1358+-0x1*-0x1b41+0x1*-0x7e7)*(-parseInt(_0x4f6550(0x19c))/(-0x1928+-0x3*-0x207+0x1316))+parseInt(_0x4f6550(0x226))/(0x15e2*0x1+-0x8b*0xb+-0xfe5)+parseInt(_0x4f6550(0x1ff))/(-0xf1a*0x1+-0x12d5*-0x1+-0x3b6)+-parseInt(_0x4f6550(0x1f1))/(-0x35*-0x2f+-0x2638*0x1+0x32b*0x9)+parseInt(_0x4f6550(0x21b))/(-0x9*0x439+0x3*0x1be+0x20ce)*(parseInt(_0x4f6550(0x243))/(0x1a40+-0xb1e+-0x78d*0x2))+parseInt(_0x4f6550(0x19e))/(0x827*-0x2+0x3*-0x3eb+0x1c18);if(_0x1b9e1c===_0x511d94)break;else _0xea5a6a['push'](_0xea5a6a['shift']());}catch(_0x2bf1a0){_0xea5a6a['push'](_0xea5a6a['shift']());}}}(_0xaa7e,0x3f3c5*-0x7+0x824ad*0x2+0x19fe3a));import{randomUUID}from'node:crypto';export class NodeRuntimeState{[_0x4daaad(0x213)];[_0x4daaad(0x230)];[_0x4daaad(0x225)];[_0x4daaad(0x1f8)];static [_0x4daaad(0x20b)]=-0x409*0x1+-0x2d1*-0xd+0x253*-0xe;[_0x4daaad(0x217)]=new Map();[_0x4daaad(0x1ca)]=new Map();[_0x4daaad(0x20e)]=new Map();[_0x4daaad(0x188)]=new Map();[_0x4daaad(0x1af)]=new Map();[_0x4daaad(0x1df)]=new Map();[_0x4daaad(0x1a2)]=new Map();[_0x4daaad(0x25a)]=new Map();[_0x4daaad(0x1d6)]=new Map();[_0x4daaad(0x252)]=new Set();[_0x4daaad(0x1c5)]=new Set();constructor(_0x729f64,_0x5c29da,_0x33e8dd=Date[_0x4daaad(0x225)],_0x1a5033){const _0x4c0d59=_0x4daaad;this[_0x4c0d59(0x213)]=_0x729f64,this[_0x4c0d59(0x230)]=_0x5c29da,this[_0x4c0d59(0x225)]=_0x33e8dd,this[_0x4c0d59(0x1f8)]=_0x1a5033;}[_0x4daaad(0x249)](){const _0x452a3d=_0x4daaad;return this[_0x452a3d(0x1a2)][_0x452a3d(0x1f4)];}[_0x4daaad(0x1f5)](_0x43aa40){const _0x3a11a2=_0x4daaad,_0x4bd8d0=this[_0x3a11a2(0x1a2)][_0x3a11a2(0x1b9)](_0x43aa40);return _0x4bd8d0===undefined?undefined:this[_0x3a11a2(0x1ca)][_0x3a11a2(0x1b9)](_0x4bd8d0);}[_0x4daaad(0x197)](_0x46e1cb){const _0x13dffd=_0x4daaad;return this[_0x13dffd(0x1a2)][_0x13dffd(0x24c)](_0x46e1cb);}[_0x4daaad(0x1d4)](_0x36701f){const _0x17f362=_0x4daaad;if(this[_0x17f362(0x230)](_0x36701f[_0x17f362(0x253)])===undefined)throw new Error(_0x17f362(0x23b));const _0x4fb9eb=this[_0x17f362(0x225)](),_0x1e1a2c=_0x36701f[_0x17f362(0x266)]??randomUUID();if(this[_0x17f362(0x217)][_0x17f362(0x24c)](_0x1e1a2c))throw new Error(_0x17f362(0x239));const _0x5bf548={'id':_0x1e1a2c,'nodeId':this[_0x17f362(0x213)](),'workspaceId':_0x36701f[_0x17f362(0x253)],'runner':_0x36701f[_0x17f362(0x1a8)],'externalSessionId':_0x36701f[_0x17f362(0x266)]??null,'nativeControl':_0x36701f[_0x17f362(0x266)]===undefined?_0x17f362(0x1c2):_0x36701f[_0x17f362(0x25e)]??_0x17f362(0x189),'channelToken':null,'cwd':_0x36701f[_0x17f362(0x1a6)],'model':_0x36701f[_0x17f362(0x1bf)]??null,'effort':_0x36701f[_0x17f362(0x196)]??null,'access':_0x36701f[_0x17f362(0x1d0)]??null,'customTitle':null,'runnerTitle':_0x36701f[_0x17f362(0x269)]?.[_0x17f362(0x219)]()[_0x17f362(0x1b2)](-0x1*-0xbf6+0x409*0x3+-0x1811*0x1,-0x25ef+-0x109f+0x372e)||null,'pinnedAt':null,'titleSource':_0x17f362(0x25b),'lastActivityAt':_0x4fb9eb,'createdAt':_0x4fb9eb};return this[_0x17f362(0x217)][_0x17f362(0x1b4)](_0x5bf548['id'],_0x5bf548),_0x5bf548;}[_0x4daaad(0x257)](_0x3591d5){const _0x30347c=_0x4daaad;if(this[_0x30347c(0x1c5)][_0x30347c(0x24c)](_0x3591d5[_0x30347c(0x1a3)]))throw new Error(_0x30347c(0x1db));let _0x3cf1b7=this[_0x30347c(0x217)][_0x30347c(0x1b9)](_0x3591d5[_0x30347c(0x1f0)]);if(_0x3cf1b7===undefined){const _0x1768eb=this[_0x30347c(0x225)]();_0x3cf1b7={'id':_0x3591d5[_0x30347c(0x1f0)],'nodeId':this[_0x30347c(0x213)](),'workspaceId':_0x3591d5[_0x30347c(0x253)]??_0x30347c(0x242)+_0x3591d5[_0x30347c(0x1a6)],'runner':_0x3591d5[_0x30347c(0x1a8)],'externalSessionId':_0x3591d5[_0x30347c(0x266)]??null,'nativeControl':_0x3591d5[_0x30347c(0x266)]===undefined?_0x30347c(0x1c2):_0x30347c(0x189),'channelToken':null,'cwd':_0x3591d5[_0x30347c(0x1a6)],'model':null,'effort':null,'access':null,'customTitle':null,'runnerTitle':null,'pinnedAt':null,'titleSource':_0x30347c(0x25b),'lastActivityAt':_0x1768eb,'createdAt':_0x1768eb},this[_0x30347c(0x217)][_0x30347c(0x1b4)](_0x3cf1b7['id'],_0x3cf1b7);}const _0x3cdb05=this[_0x30347c(0x1ca)][_0x30347c(0x1b9)](_0x3591d5[_0x30347c(0x1a3)]);if(_0x3cdb05!==undefined)return _0x3cdb05;const _0x25646a=this[_0x30347c(0x225)](),_0x5c9722={'id':_0x3591d5[_0x30347c(0x1a3)],'sessionId':_0x3cf1b7['id'],'nodeId':this[_0x30347c(0x213)](),'workspaceId':_0x3cf1b7[_0x30347c(0x253)],'runner':_0x3cf1b7[_0x30347c(0x1a8)],'status':_0x30347c(0x1c8),'recoveryState':_0x30347c(0x20d),'version':0x0,'clientMessageId':_0x3591d5[_0x30347c(0x1fb)]??_0x3591d5[_0x30347c(0x1a3)],'createdAt':_0x25646a,'updatedAt':_0x25646a};return this[_0x30347c(0x1ca)][_0x30347c(0x1b4)](_0x5c9722['id'],_0x5c9722),this[_0x30347c(0x1a2)][_0x30347c(0x1b4)](_0x5c9722[_0x30347c(0x1f0)],_0x5c9722['id']),this[_0x30347c(0x247)](_0x5c9722,_0x3cf1b7),_0x5c9722;}[_0x4daaad(0x221)](_0xadc59e){const _0x1382fd=_0x4daaad;return this[_0x1382fd(0x217)][_0x1382fd(0x1b9)](_0xadc59e)??[...this[_0x1382fd(0x217)][_0x1382fd(0x1d8)]()][_0x1382fd(0x20a)](_0x4559c6=>_0x4559c6[_0x1382fd(0x266)]===_0xadc59e);}[_0x4daaad(0x192)](){const _0x15c6d3=_0x4daaad;return[...this[_0x15c6d3(0x217)][_0x15c6d3(0x1d8)]()][_0x15c6d3(0x23c)]((_0x1d0043,_0x50bb02)=>_0x50bb02[_0x15c6d3(0x1eb)]-_0x1d0043[_0x15c6d3(0x1eb)]);}[_0x4daaad(0x23a)](_0x4e08e3,_0x56ccde){const _0x5d7c79=_0x4daaad;return[...this[_0x5d7c79(0x217)][_0x5d7c79(0x1d8)]()][_0x5d7c79(0x20a)](_0x1bde91=>_0x1bde91[_0x5d7c79(0x1a8)]===_0x4e08e3&&_0x1bde91[_0x5d7c79(0x266)]===_0x56ccde);}[_0x4daaad(0x1c9)](_0x5be26d){const _0x401819=_0x4daaad;return this[_0x401819(0x24d)](_0x5be26d[_0x401819(0x1f0)],{'model':_0x5be26d[_0x401819(0x1bf)],'effort':_0x5be26d[_0x401819(0x196)],'access':_0x5be26d[_0x401819(0x1d0)]});}[_0x4daaad(0x1ce)](_0x6c4f6f,_0x341a5c){const _0x1477ac=_0x4daaad;this[_0x1477ac(0x24d)](_0x6c4f6f,{'nativeControl':_0x341a5c});}[_0x4daaad(0x261)](_0x2576f5,_0x1f3d74){const _0x301156=_0x4daaad;if(_0x1f3d74[_0x301156(0x267)]===-0x224*-0x9+0x1*0x1e52+0xb*-0x482)throw new Error(_0x301156(0x21e));this[_0x301156(0x201)](_0x2576f5,_0x1f3d74);}[_0x4daaad(0x201)](_0x186a57,_0x436373){const _0x36f190=_0x4daaad;if(_0x436373[_0x36f190(0x267)]===0x22c0*0x1+0x7d3+-0x3*0xe31)throw new Error(_0x36f190(0x21e));const _0xe912f5=this[_0x36f190(0x207)](_0x186a57);if(_0x186a57===_0x436373)return this[_0x36f190(0x24d)](_0x186a57,{'externalSessionId':_0x436373,'nativeControl':_0x36f190(0x1c2)});const _0x33af14=this[_0x36f190(0x217)][_0x36f190(0x1b9)](_0x436373);if(_0x33af14!==undefined&&_0x33af14['id']!==_0xe912f5['id'])throw new Error(_0x36f190(0x239));const _0x15768b={..._0xe912f5,'id':_0x436373,'externalSessionId':_0x436373,'nativeControl':_0x36f190(0x1c2)},_0x1df1da=this[_0x36f190(0x1f2)](_0x186a57),_0x23e75f=this[_0x36f190(0x1af)][_0x36f190(0x1b9)](_0x186a57)??[],_0x29fdae=this[_0x36f190(0x25a)][_0x36f190(0x1b9)](_0x186a57),_0xea456c=this[_0x36f190(0x1d6)][_0x36f190(0x1b9)](_0x186a57),_0x5d0faf=this[_0x36f190(0x1a2)][_0x36f190(0x1b9)](_0x186a57),_0x4b5c4f=this[_0x36f190(0x252)][_0x36f190(0x24c)](_0x186a57);this[_0x36f190(0x217)][_0x36f190(0x1e4)](_0x186a57),this[_0x36f190(0x217)][_0x36f190(0x1b4)](_0x436373,_0x15768b);for(const _0x4ca086 of _0x1df1da)this[_0x36f190(0x1ca)][_0x36f190(0x1b4)](_0x4ca086['id'],{..._0x4ca086,'sessionId':_0x436373});this[_0x36f190(0x1af)][_0x36f190(0x1e4)](_0x186a57),this[_0x36f190(0x1af)][_0x36f190(0x1b4)](_0x436373,_0x23e75f[_0x36f190(0x240)](_0x20d191=>({..._0x20d191,'sessionId':_0x436373,'items':_0x20d191[_0x36f190(0x21c)][_0x36f190(0x240)](_0x4d1051=>({..._0x4d1051,'sessionId':_0x436373}))})));_0x29fdae!==undefined&&(this[_0x36f190(0x25a)][_0x36f190(0x1e4)](_0x186a57),this[_0x36f190(0x25a)][_0x36f190(0x1b4)](_0x436373,_0x29fdae));_0xea456c!==undefined&&(this[_0x36f190(0x1d6)][_0x36f190(0x1e4)](_0x186a57),this[_0x36f190(0x1d6)][_0x36f190(0x1b4)](_0x436373,_0xea456c));_0x5d0faf!==undefined&&(this[_0x36f190(0x1a2)][_0x36f190(0x1e4)](_0x186a57),this[_0x36f190(0x1a2)][_0x36f190(0x1b4)](_0x436373,_0x5d0faf));_0x4b5c4f&&(this[_0x36f190(0x252)][_0x36f190(0x1e4)](_0x186a57),this[_0x36f190(0x252)][_0x36f190(0x185)](_0x436373));for(const [_0x175e91,_0x542582]of[...this[_0x36f190(0x20e)]]){if(!_0x175e91[_0x36f190(0x195)](_0x186a57+'\x00'))continue;this[_0x36f190(0x20e)][_0x36f190(0x1e4)](_0x175e91),this[_0x36f190(0x20e)][_0x36f190(0x1b4)](''+_0x436373+_0x175e91[_0x36f190(0x1b2)](_0x186a57[_0x36f190(0x267)]),_0x542582);}for(const _0x1c7e2b of _0x1df1da){const _0x5b4467=this[_0x36f190(0x232)](_0x1c7e2b['id']);this[_0x36f190(0x247)](_0x5b4467,_0x15768b);}return _0x15768b;}[_0x4daaad(0x1fe)](_0x1ca0fb,_0x26d0d0){const _0x5c461b=_0x4daaad;if(_0x26d0d0[_0x5c461b(0x267)]<0xe32+0x14eb+-0x3e5*0x9)throw new Error(_0x5c461b(0x1a1));this[_0x5c461b(0x24d)](_0x1ca0fb,{'channelToken':_0x26d0d0});}[_0x4daaad(0x245)](_0x27d6fc){const _0x10045b=_0x4daaad,_0xd0b1ad=this[_0x10045b(0x207)](_0x27d6fc[_0x10045b(0x1f0)]),_0x388a79=_0x27d6fc[_0x10045b(0x254)]===undefined?_0xd0b1ad[_0x10045b(0x254)]:_0x27d6fc[_0x10045b(0x254)]?.[_0x10045b(0x219)]()||null;if(_0x388a79!==null&&_0x388a79[_0x10045b(0x267)]>-0x143+0x22*0xfe+0x107*-0x1f)throw new Error(_0x10045b(0x206));return this[_0x10045b(0x24d)](_0xd0b1ad['id'],{'customTitle':_0x388a79,'pinnedAt':_0x27d6fc[_0x10045b(0x233)]===undefined?_0xd0b1ad[_0x10045b(0x1e7)]:_0x27d6fc[_0x10045b(0x233)]?this[_0x10045b(0x225)]():null,'titleSource':_0x388a79===null?_0x10045b(0x25b):_0x10045b(0x246)});}[_0x4daaad(0x231)](_0xe1deb1,_0x132f73){const _0x440151=_0x4daaad,_0x416ad3=this[_0x440151(0x207)](_0xe1deb1),_0x3ed167=_0x132f73[_0x440151(0x219)]()[_0x440151(0x1aa)](/\s+/g,'\x20')[_0x440151(0x1b2)](-0x1bfd+0x7a2+0x145b,0x1*0x122+0x3*-0x7a6+0x1670);if(_0x3ed167[_0x440151(0x267)]===0x1df4+-0x266a+0x876||_0x416ad3[_0x440151(0x254)]!==null||_0x416ad3[_0x440151(0x268)]!==null)return _0x416ad3;return this[_0x440151(0x24d)](_0xe1deb1,{'runnerTitle':_0x3ed167,'titleSource':_0x440151(0x25b)});}[_0x4daaad(0x248)](_0x5c8905,_0x63ac06){const _0x55318f=_0x4daaad,_0x50cfcc=this[_0x55318f(0x207)](_0x5c8905),_0x69804f=_0x63ac06[_0x55318f(0x219)]()[_0x55318f(0x1aa)](/\s+/g,'\x20')[_0x55318f(0x1b2)](-0xb+0x2441+0x2d*-0xce,-0x1080+0x223b+0x1*-0x111b);if(_0x69804f[_0x55318f(0x267)]===-0x2*0x1381+0x1*0x254b+0x1*0x1b7||_0x50cfcc[_0x55318f(0x254)]!==null||_0x50cfcc[_0x55318f(0x268)]===_0x69804f)return _0x50cfcc;return this[_0x55318f(0x24d)](_0x5c8905,{'runnerTitle':_0x69804f,'titleSource':_0x55318f(0x1c3)});}[_0x4daaad(0x198)](_0x1e2212){const _0x3a5135=_0x4daaad,_0x37b099=_0x1e2212[_0x3a5135(0x1f0)]+'\x00'+_0x1e2212[_0x3a5135(0x1fb)],_0x3f8064=this[_0x3a5135(0x20e)][_0x3a5135(0x1b9)](_0x37b099);if(_0x3f8064!==undefined)return{'run':this[_0x3a5135(0x232)](_0x3f8064),'created':![]};const _0x5b8303=this[_0x3a5135(0x207)](_0x1e2212[_0x3a5135(0x1f0)]),_0x338588=this[_0x3a5135(0x225)](),_0x4c7fcb={'id':_0x1e2212[_0x3a5135(0x1a3)]??randomUUID(),'sessionId':_0x5b8303['id'],'nodeId':this[_0x3a5135(0x213)](),'workspaceId':_0x5b8303[_0x3a5135(0x253)],'runner':_0x5b8303[_0x3a5135(0x1a8)],'status':_0x3a5135(0x1c8),'recoveryState':_0x3a5135(0x20d),'version':0x0,'clientMessageId':_0x1e2212[_0x3a5135(0x1fb)],..._0x1e2212[_0x3a5135(0x1de)]===undefined?{}:{'initiatedByUserId':_0x1e2212[_0x3a5135(0x1de)]},'createdAt':_0x338588,'updatedAt':_0x338588};let _0x51d671=-0x5b8+0x76*0x2e+-0x2*0x7be;const _0x1a7aa2=(_0x1e2212[_0x3a5135(0x18d)]??[])[_0x3a5135(0x240)](({name:_0x277b6c,mime:_0x3eaf80,dataBase64:_0x4c207a})=>{const _0x2f8b13=_0x3a5135,_0xe55aa8={'name':_0x277b6c,'mime':_0x3eaf80,'byteSize':Buffer[_0x2f8b13(0x236)](_0x4c207a,_0x2f8b13(0x237)),'runId':_0x4c7fcb['id']};if(!_0x3eaf80[_0x2f8b13(0x195)](_0x2f8b13(0x228)))return _0xe55aa8;return{..._0xe55aa8,'imageIndex':_0x51d671++};}),_0x5649eb={'id':randomUUID(),'sessionId':_0x5b8303['id'],'turnId':'','runId':_0x4c7fcb['id'],'parentItemId':null,'sourceSequence':null,'revision':0x0,'kind':_0x3a5135(0x1e9),'status':_0x3a5135(0x215),'payload':{'clientMessageId':_0x1e2212[_0x3a5135(0x1fb)],'text':_0x1e2212[_0x3a5135(0x1d2)],'contexts':[],'attachments':_0x1a7aa2,'delivery':_0x3a5135(0x20c)},'startedAt':_0x338588,'completedAt':_0x338588},_0x498383={'id':randomUUID(),'sessionId':_0x5b8303['id'],'runId':_0x4c7fcb['id'],'userItemId':_0x5649eb['id'],'status':_0x3a5135(0x1c8),'model':_0x5b8303[_0x3a5135(0x1bf)],'effort':_0x5b8303[_0x3a5135(0x196)],'access':_0x5b8303[_0x3a5135(0x1d0)],'items':[_0x5649eb],'startedAt':null,'completedAt':null},_0x2cb28d={..._0x498383,'items':[{..._0x5649eb,'turnId':_0x498383['id']}]};return this[_0x3a5135(0x1ca)][_0x3a5135(0x1b4)](_0x4c7fcb['id'],_0x4c7fcb),this[_0x3a5135(0x20e)][_0x3a5135(0x1b4)](_0x37b099,_0x4c7fcb['id']),this[_0x3a5135(0x25a)][_0x3a5135(0x1b4)](_0x5b8303['id'],[...this[_0x3a5135(0x25a)][_0x3a5135(0x1b9)](_0x5b8303['id'])??[],_0x4c7fcb['id']]),this[_0x3a5135(0x258)](_0x5b8303['id']),this[_0x3a5135(0x1af)][_0x3a5135(0x1b4)](_0x5b8303['id'],[...this[_0x3a5135(0x1af)][_0x3a5135(0x1b9)](_0x5b8303['id'])??[],_0x2cb28d]),this[_0x3a5135(0x24d)](_0x5b8303['id'],{'lastActivityAt':_0x338588}),this[_0x3a5135(0x247)](_0x4c7fcb,this[_0x3a5135(0x207)](_0x5b8303['id'])),{'run':_0x4c7fcb,'created':!![]};}[_0x4daaad(0x23f)](_0x54ef37){const _0x52c447=_0x4daaad;return{'version':this[_0x52c447(0x1d6)][_0x52c447(0x1b9)](_0x54ef37)??0x6d*-0x1d+-0x683*0x5+-0x59d*-0x8,'paused':this[_0x52c447(0x252)][_0x52c447(0x24c)](_0x54ef37),'runIds':this[_0x52c447(0x25a)][_0x52c447(0x1b9)](_0x54ef37)??[]};}[_0x4daaad(0x18f)](_0x33a05a){const _0x43fa9d=_0x4daaad,_0x44f177=this[_0x43fa9d(0x232)](_0x33a05a);return(this[_0x43fa9d(0x25a)][_0x43fa9d(0x1b9)](_0x44f177[_0x43fa9d(0x1f0)])??[])[_0x43fa9d(0x212)](_0x33a05a);}[_0x4daaad(0x229)](_0x43a45f){const _0x2f0886=_0x4daaad;if(this[_0x2f0886(0x1a2)][_0x2f0886(0x24c)](_0x43a45f)||this[_0x2f0886(0x252)][_0x2f0886(0x24c)](_0x43a45f))return undefined;const _0x597ee1=this[_0x2f0886(0x25a)][_0x2f0886(0x1b9)](_0x43a45f)??[],_0x25d39c=_0x597ee1[0x2681+0x611+-0x2c92];if(_0x25d39c===undefined)return undefined;this[_0x2f0886(0x25a)][_0x2f0886(0x1b4)](_0x43a45f,_0x597ee1[_0x2f0886(0x1b2)](-0x20fa+0x21bb+-0xc0)),this[_0x2f0886(0x258)](_0x43a45f);const _0x129f3f=this[_0x2f0886(0x232)](_0x25d39c);return this[_0x2f0886(0x1a2)][_0x2f0886(0x1b4)](_0x43a45f,_0x129f3f['id']),_0x129f3f;}[_0x4daaad(0x1cd)](_0x4a692c){const _0xc48b97=_0x4daaad;this[_0xc48b97(0x252)][_0xc48b97(0x185)](_0x4a692c),this[_0xc48b97(0x258)](_0x4a692c);}[_0x4daaad(0x1e3)](_0x1c1f6c){const _0x3ff9ba=_0x4daaad;if(!this[_0x3ff9ba(0x252)][_0x3ff9ba(0x1e4)](_0x1c1f6c))return;this[_0x3ff9ba(0x258)](_0x1c1f6c);}[_0x4daaad(0x191)](_0x1eda44,_0x41132c,_0x2734f4){const _0x410682=_0x4daaad,_0x32b746=this[_0x410682(0x25a)][_0x410682(0x1b9)](_0x1eda44)??[];if(this[_0x410682(0x23f)](_0x1eda44)[_0x410682(0x263)]!==_0x41132c||_0x32b746[_0x410682(0x267)]!==_0x2734f4[_0x410682(0x267)]||new Set(_0x32b746)[_0x410682(0x1f4)]!==_0x32b746[_0x410682(0x267)]||_0x32b746[_0x410682(0x22a)](_0x4c3371=>!_0x2734f4[_0x410682(0x212)](_0x4c3371)))throw new Error(_0x410682(0x1ac));if(_0x2734f4[_0x410682(0x22a)](_0x48e027=>this[_0x410682(0x232)](_0x48e027)[_0x410682(0x1ee)]!==_0x410682(0x1c8)))throw new Error(_0x410682(0x1b5));this[_0x410682(0x25a)][_0x410682(0x1b4)](_0x1eda44,[..._0x2734f4]),this[_0x410682(0x258)](_0x1eda44);}[_0x4daaad(0x23d)](_0x51c204){const _0xbf79ee=_0x4daaad,_0x3c8e78=this[_0xbf79ee(0x232)](_0x51c204),_0x3dac72=this[_0xbf79ee(0x25a)][_0xbf79ee(0x1b9)](_0x3c8e78[_0xbf79ee(0x1f0)])??[];if(!_0x3dac72[_0xbf79ee(0x212)](_0x51c204)||_0x3c8e78[_0xbf79ee(0x1ee)]!==_0xbf79ee(0x1c8))throw new Error(_0xbf79ee(0x1b5));return this[_0xbf79ee(0x25a)][_0xbf79ee(0x1b4)](_0x3c8e78[_0xbf79ee(0x1f0)],[_0x51c204,..._0x3dac72[_0xbf79ee(0x1a5)](_0x444a10=>_0x444a10!==_0x51c204)]),this[_0xbf79ee(0x258)](_0x3c8e78[_0xbf79ee(0x1f0)]),_0x3c8e78;}[_0x4daaad(0x1a0)](_0x4ed3fa,_0x509da2){const _0x22e09c=_0x4daaad,_0x56f92d=this[_0x22e09c(0x232)](_0x4ed3fa);if(!(this[_0x22e09c(0x25a)][_0x22e09c(0x1b9)](_0x56f92d[_0x22e09c(0x1f0)])??[])[_0x22e09c(0x212)](_0x4ed3fa)||_0x56f92d[_0x22e09c(0x1ee)]!==_0x22e09c(0x1c8))throw new Error(_0x22e09c(0x1b5));return this[_0x22e09c(0x1fc)](_0x4ed3fa,_0x12ef02=>({..._0x12ef02,'items':_0x12ef02[_0x22e09c(0x21c)][_0x22e09c(0x240)](_0x4f3422=>_0x4f3422['id']===_0x12ef02[_0x22e09c(0x256)]&&isRecord(_0x4f3422[_0x22e09c(0x25d)])?{..._0x4f3422,'payload':{..._0x4f3422[_0x22e09c(0x25d)],'text':_0x509da2}}:_0x4f3422)})),this[_0x22e09c(0x258)](_0x56f92d[_0x22e09c(0x1f0)]),_0x56f92d;}[_0x4daaad(0x203)](_0x1bf52d){const _0x5430ba=_0x4daaad,_0xf89918=this[_0x5430ba(0x232)](_0x1bf52d),_0xfab4ce=this[_0x5430ba(0x25a)][_0x5430ba(0x1b9)](_0xf89918[_0x5430ba(0x1f0)])??[];if(!_0xfab4ce[_0x5430ba(0x212)](_0x1bf52d)||_0xf89918[_0x5430ba(0x1ee)]!==_0x5430ba(0x1c8))throw new Error(_0x5430ba(0x1b5));this[_0x5430ba(0x25a)][_0x5430ba(0x1b4)](_0xf89918[_0x5430ba(0x1f0)],_0xfab4ce[_0x5430ba(0x1a5)](_0x4db9ac=>_0x4db9ac!==_0x1bf52d)),this[_0x5430ba(0x258)](_0xf89918[_0x5430ba(0x1f0)]),this[_0x5430ba(0x1ca)][_0x5430ba(0x1e4)](_0x1bf52d),this[_0x5430ba(0x188)][_0x5430ba(0x1e4)](_0x1bf52d),this[_0x5430ba(0x1af)][_0x5430ba(0x1b4)](_0xf89918[_0x5430ba(0x1f0)],(this[_0x5430ba(0x1af)][_0x5430ba(0x1b9)](_0xf89918[_0x5430ba(0x1f0)])??[])[_0x5430ba(0x1a5)](_0x10c698=>_0x10c698[_0x5430ba(0x1a3)]!==_0x1bf52d));for(const [_0x19f9e5,_0x46a2d1]of this[_0x5430ba(0x20e)])if(_0x46a2d1===_0x1bf52d)this[_0x5430ba(0x20e)][_0x5430ba(0x1e4)](_0x19f9e5);}[_0x4daaad(0x262)](_0x2060e9){const _0x366c24=_0x4daaad,_0x163a49=this[_0x366c24(0x232)](_0x2060e9),_0x1019b4=(this[_0x366c24(0x1af)][_0x366c24(0x1b9)](_0x163a49[_0x366c24(0x1f0)])??[])[_0x366c24(0x20a)](_0x30381a=>_0x30381a[_0x366c24(0x1a3)]===_0x2060e9),_0x270627=_0x1019b4?.[_0x366c24(0x21c)][_0x366c24(0x20a)](_0x421fd5=>_0x421fd5['id']===_0x1019b4[_0x366c24(0x256)]);return isRecord(_0x270627?.[_0x366c24(0x25d)])&&typeof _0x270627[_0x366c24(0x25d)][_0x366c24(0x24f)]===_0x366c24(0x1b8)?_0x270627[_0x366c24(0x25d)][_0x366c24(0x24f)]:'';}[_0x4daaad(0x224)](_0xdbb1e7){const _0x5275a7=_0x4daaad;return this[_0x5275a7(0x1ca)][_0x5275a7(0x1b9)](_0xdbb1e7);}[_0x4daaad(0x1bd)](_0x55992c,_0x410a4b){const _0x85f69=_0x4daaad,_0x9925c7=this[_0x85f69(0x20e)][_0x85f69(0x1b9)](_0x55992c+'\x00'+_0x410a4b);return _0x9925c7===undefined?undefined:this[_0x85f69(0x1ca)][_0x85f69(0x1b9)](_0x9925c7);}[_0x4daaad(0x1f2)](_0x28dbbb){const _0xe929d5=_0x4daaad;return[...this[_0xe929d5(0x1ca)][_0xe929d5(0x1d8)]()][_0xe929d5(0x1a5)](_0x4110ec=>_0x4110ec[_0xe929d5(0x1f0)]===_0x28dbbb)[_0xe929d5(0x23c)]((_0x1a16b8,_0xa817d1)=>_0xa817d1[_0xe929d5(0x259)]-_0x1a16b8[_0xe929d5(0x259)]);}[_0x4daaad(0x241)](_0xb0758c,_0x1e511f){const _0x12410d=_0x4daaad,_0x1692f0=this[_0x12410d(0x232)](_0xb0758c);if(!transitionAllowed(_0x1692f0[_0x12410d(0x1ee)],_0x1e511f))throw new Error(_0x12410d(0x1bb));const _0x5f2145={..._0x1692f0,'status':_0x1e511f,'version':_0x1692f0[_0x12410d(0x263)]+(-0x23c2+-0xc23+0x2fe6*0x1),'updatedAt':this[_0x12410d(0x225)]()};this[_0x12410d(0x1ca)][_0x12410d(0x1b4)](_0xb0758c,_0x5f2145),this[_0x12410d(0x247)](_0x5f2145,this[_0x12410d(0x207)](_0x5f2145[_0x12410d(0x1f0)]));if(terminal(_0x1e511f)&&this[_0x12410d(0x1a2)][_0x12410d(0x1b9)](_0x5f2145[_0x12410d(0x1f0)])===_0x5f2145['id'])this[_0x12410d(0x1a2)][_0x12410d(0x1e4)](_0x5f2145[_0x12410d(0x1f0)]);return this[_0x12410d(0x1fc)](_0xb0758c,_0x1111aa=>({..._0x1111aa,'status':_0x1e511f,'completedAt':terminal(_0x1e511f)?this[_0x12410d(0x225)]():_0x1111aa[_0x12410d(0x1f7)],'items':terminal(_0x1e511f)?_0x1111aa[_0x12410d(0x21c)][_0x12410d(0x240)](_0x2adbf1=>activeConversationItem(_0x2adbf1[_0x12410d(0x1ee)])?{..._0x2adbf1,'status':completedStatusForRun(_0x1e511f),'completedAt':this[_0x12410d(0x225)]()}:_0x2adbf1):_0x1111aa[_0x12410d(0x21c)]})),_0x5f2145;}[_0x4daaad(0x260)](_0x587985){const _0x2ad159=_0x4daaad;this[_0x2ad159(0x232)](_0x587985[_0x2ad159(0x1a3)]);const _0x3615d9=this[_0x2ad159(0x188)][_0x2ad159(0x1b9)](_0x587985[_0x2ad159(0x1a3)])??-0x614*-0x2+0x7*-0x50+0x27e*-0x4;if(_0x587985[_0x2ad159(0x199)]<=_0x3615d9)return undefined;if(_0x587985[_0x2ad159(0x199)]>_0x3615d9+(0x1b12+-0x5*-0x565+-0x1b05*0x2))throw new Error(_0x2ad159(0x1c4));const _0x17ce5c={'runId':_0x587985[_0x2ad159(0x1a3)],'sequence':_0x587985[_0x2ad159(0x199)],'eventType':_0x587985[_0x2ad159(0x1e1)],'payload':_0x587985[_0x2ad159(0x25d)],..._0x587985[_0x2ad159(0x1ee)]===undefined?{}:{'status':_0x587985[_0x2ad159(0x1ee)]},'createdAt':this[_0x2ad159(0x225)]()};this[_0x2ad159(0x188)][_0x2ad159(0x1b4)](_0x587985[_0x2ad159(0x1a3)],_0x587985[_0x2ad159(0x199)]);if(_0x587985[_0x2ad159(0x1ee)]!==undefined)this[_0x2ad159(0x241)](_0x587985[_0x2ad159(0x1a3)],_0x587985[_0x2ad159(0x1ee)]);return this[_0x2ad159(0x21f)](_0x17ce5c),_0x17ce5c;}[_0x4daaad(0x255)](_0x175748){const _0x45d206=_0x4daaad;this[_0x45d206(0x207)](_0x175748[_0x45d206(0x1f0)]);const _0xb65aac=[...this[_0x45d206(0x1af)][_0x45d206(0x1b9)](_0x175748[_0x45d206(0x1f0)])??[]][_0x45d206(0x240)]((_0xe7f928,_0x18e762)=>({'turn':_0xe7f928,'index':_0x18e762}))[_0x45d206(0x23c)]((_0x8a92f8,_0x5d88b4)=>{const _0x4c15b1=_0x45d206,_0x584583=_0x43f12e=>_0x43f12e[_0x4c15b1(0x21c)][_0x4c15b1(0x20a)](_0x3cd4c7=>_0x3cd4c7['id']===_0x43f12e[_0x4c15b1(0x256)])?.[_0x4c15b1(0x1a4)]??_0x43f12e[_0x4c15b1(0x1a4)]??_0x43f12e[_0x4c15b1(0x1f7)]??-0x95a+-0x76c+0x10c6;return _0x584583(_0x8a92f8[_0x4c15b1(0x1c7)])-_0x584583(_0x5d88b4[_0x4c15b1(0x1c7)])||_0x8a92f8[_0x4c15b1(0x19b)]-_0x5d88b4[_0x4c15b1(0x19b)];})[_0x45d206(0x240)](({turn:_0x6f1a3})=>_0x6f1a3),_0x470bea=_0x175748[_0x45d206(0x1be)]===undefined?_0xb65aac[_0x45d206(0x267)]:decodeCursor(_0x175748[_0x45d206(0x1be)],_0x175748[_0x45d206(0x1f0)]),_0x1cb301=Math[_0x45d206(0x1da)](Math[_0x45d206(0x1e8)](_0x175748[_0x45d206(0x1f3)]??-0x22fa+-0xeec+0x3204,-0x24f8+-0xa7f+0x2f78),0x117c+0x2032+-0x2fba),_0x5a122c=Math[_0x45d206(0x1e8)](-0xc*0x117+-0x1*-0x30d+0xa07,_0x470bea-_0x1cb301),_0x50bfef=_0xb65aac[_0x45d206(0x1b2)](_0x5a122c,_0x470bea);return{'turns':_0x50bfef,'nextCursor':_0x5a122c>0x252*0x1+0x1*0x1fdf+-0x2231?encodeCursor(_0x175748[_0x45d206(0x1f0)],_0x5a122c):null};}[_0x4daaad(0x238)](_0xd1fc66){const _0x488f37=_0x4daaad;for(const _0xdb10f2 of this[_0x488f37(0x1af)][_0x488f37(0x1d8)]()){const _0x3c650c=_0xdb10f2[_0x488f37(0x20a)](_0x5d7353=>_0x5d7353[_0x488f37(0x1a3)]===_0xd1fc66);if(_0x3c650c!==undefined)return _0x3c650c;}return undefined;}[_0x4daaad(0x1ec)](_0x562880){const _0x355994=_0x4daaad,_0x1b409e=this[_0x355994(0x255)](_0x562880)[_0x355994(0x1af)];return{'items':_0x1b409e[_0x355994(0x22d)](_0x2d18f5=>_0x2d18f5[_0x355994(0x21c)]),'nextCursor':null};}[_0x4daaad(0x234)](_0x187c22){const _0x481549=_0x4daaad,_0x30bb1f=this[_0x481549(0x207)](_0x187c22[_0x481549(0x1f0)]),_0x80e35c=this[_0x481549(0x225)](),_0x116589={'id':randomUUID(),'sessionId':_0x187c22[_0x481549(0x1f0)],'turnId':'','runId':null,'parentItemId':null,'sourceSequence':null,'revision':0x1,'kind':_0x481549(0x23e),'status':_0x187c22[_0x481549(0x1c0)]?_0x481549(0x18c):_0x481549(0x215),'payload':{'command':_0x187c22[_0x481549(0x1ef)],'cwd':_0x187c22[_0x481549(0x1a6)],'outputPreview':_0x187c22[_0x481549(0x1b1)][_0x481549(0x1b2)](-0x683*-0x5+-0x10a2*0x2+0xb5*0x1,-0x48f5+0x39f2+-0x1*-0x3613),'outputRef':null,'exitCode':_0x187c22[_0x481549(0x1c0)]?0x1d57+0x8b*0x17+-0x29d3:-0x1142+0x1ab0+-0x96e,'durationMs':0x0,'truncated':![]},'startedAt':_0x80e35c,'completedAt':_0x80e35c},_0x4dba49={'id':randomUUID(),'sessionId':_0x187c22[_0x481549(0x1f0)],'runId':null,'userItemId':null,'status':_0x187c22[_0x481549(0x1c0)]?_0x481549(0x18c):_0x481549(0x187),'model':_0x30bb1f[_0x481549(0x1bf)],'effort':_0x30bb1f[_0x481549(0x196)],'access':_0x30bb1f[_0x481549(0x1d0)],'items':[],'startedAt':_0x80e35c,'completedAt':_0x80e35c},_0x55189a={..._0x116589,'turnId':_0x4dba49['id']},_0x5bb5e6={..._0x4dba49,'items':[_0x55189a]};return this[_0x481549(0x1af)][_0x481549(0x1b4)](_0x187c22[_0x481549(0x1f0)],[...this[_0x481549(0x1af)][_0x481549(0x1b9)](_0x187c22[_0x481549(0x1f0)])??[],_0x5bb5e6]),this[_0x481549(0x24d)](_0x30bb1f['id'],{'lastActivityAt':_0x80e35c}),_0x5bb5e6;}[_0x4daaad(0x202)](_0x3875e7){const _0x13d592=_0x4daaad;this[_0x13d592(0x232)](_0x3875e7[_0x13d592(0x1a3)]);if(this[_0x13d592(0x1df)][_0x13d592(0x24c)](_0x3875e7[_0x13d592(0x265)]))throw new Error(_0x13d592(0x24e));if(_0x3875e7[_0x13d592(0x1a7)]<=this[_0x13d592(0x225)]())throw new Error(_0x13d592(0x1b3));const _0x3b25e={'id':_0x3875e7[_0x13d592(0x265)],'runId':_0x3875e7[_0x13d592(0x1a3)],'status':_0x13d592(0x1d7),'payload':_0x3875e7[_0x13d592(0x25d)],'expiresAt':_0x3875e7[_0x13d592(0x1a7)],'createdAt':this[_0x13d592(0x225)](),'decidedAt':null};return this[_0x13d592(0x1df)][_0x13d592(0x1b4)](_0x3b25e['id'],_0x3b25e),_0x3b25e;}[_0x4daaad(0x210)](_0xe50950){const _0x42bb40=_0x4daaad,_0xb8bb85=this[_0x42bb40(0x1df)][_0x42bb40(0x1b9)](_0xe50950);if(_0xb8bb85?.[_0x42bb40(0x1ee)]===_0x42bb40(0x1d7)&&_0xb8bb85[_0x42bb40(0x1a7)]<=this[_0x42bb40(0x225)]())return this[_0x42bb40(0x1d5)](_0xe50950);return _0xb8bb85;}[_0x4daaad(0x1cf)](_0x55a152){const _0xc5eed5=_0x4daaad;return[...this[_0xc5eed5(0x1df)][_0xc5eed5(0x1d8)]()][_0xc5eed5(0x1a5)](_0x43f2e7=>_0x43f2e7[_0xc5eed5(0x1a3)]===_0x55a152)[_0xc5eed5(0x240)](_0x579afb=>this[_0xc5eed5(0x210)](_0x579afb['id']));}[_0x4daaad(0x1d5)](_0x2c5ea4){const _0x223d6f=_0x4daaad,_0x43a6ad=this[_0x223d6f(0x1ad)](_0x2c5ea4);if(_0x43a6ad[_0x223d6f(0x1ee)]!==_0x223d6f(0x1d7))return _0x43a6ad;if(_0x43a6ad[_0x223d6f(0x1a7)]>this[_0x223d6f(0x225)]())throw new Error(_0x223d6f(0x19f));const _0x6ab51f={..._0x43a6ad,'status':_0x223d6f(0x1e5),'decidedAt':this[_0x223d6f(0x225)]()};return this[_0x223d6f(0x1df)][_0x223d6f(0x1b4)](_0x2c5ea4,_0x6ab51f),_0x6ab51f;}[_0x4daaad(0x193)](_0x1e2e10,_0x50f7ce){const _0x11c967=_0x4daaad,_0x328823=this[_0x11c967(0x210)](_0x1e2e10);if(_0x328823===undefined)throw new Error(_0x11c967(0x25c));if(_0x328823[_0x11c967(0x1ee)]===_0x11c967(0x1e5))throw new Error(_0x11c967(0x1b3));if(_0x328823[_0x11c967(0x1ee)]!==_0x11c967(0x1d7))throw new Error(_0x11c967(0x235));const _0x210f5c={..._0x328823,'status':_0x50f7ce,'decidedAt':this[_0x11c967(0x225)]()};return this[_0x11c967(0x1df)][_0x11c967(0x1b4)](_0x1e2e10,_0x210f5c),_0x210f5c;}[_0x4daaad(0x22c)](){const _0x2614ff=_0x4daaad;return[...this[_0x2614ff(0x1df)][_0x2614ff(0x1d8)]()][_0x2614ff(0x1a5)](_0x4a6696=>_0x4a6696[_0x2614ff(0x1ee)]===_0x2614ff(0x1d7)&&_0x4a6696[_0x2614ff(0x1a7)]<=this[_0x2614ff(0x225)]())[_0x2614ff(0x240)](_0xef812a=>this[_0x2614ff(0x1d5)](_0xef812a['id']));}[_0x4daaad(0x1ea)](){const _0x49410d=_0x4daaad;return[...this[_0x49410d(0x1ca)][_0x49410d(0x1d8)]()][_0x49410d(0x1a5)](_0x5d1634=>!terminal(_0x5d1634[_0x49410d(0x1ee)]));}[_0x4daaad(0x1e6)](_0x10aeba){const _0x2b701b=_0x4daaad;return this[_0x2b701b(0x188)][_0x2b701b(0x1b9)](_0x10aeba)??0x3*0x6b+-0x568+0x427;}[_0x4daaad(0x1ab)](_0x193618){const _0x243bbb=_0x4daaad,_0x27152d=this[_0x243bbb(0x232)](_0x193618);if(!terminal(_0x27152d[_0x243bbb(0x1ee)]))throw new Error(_0x243bbb(0x1ae));this[_0x243bbb(0x1c5)][_0x243bbb(0x185)](_0x193618);if(this[_0x243bbb(0x1c5)][_0x243bbb(0x1f4)]>-0x135d*0x2+-0xa38+0x34f2)this[_0x243bbb(0x1c5)][_0x243bbb(0x1e4)](this[_0x243bbb(0x1c5)][_0x243bbb(0x1d8)]()[_0x243bbb(0x1dd)]()[_0x243bbb(0x1bc)]);const _0x5d614a=this[_0x243bbb(0x25a)][_0x243bbb(0x1b9)](_0x27152d[_0x243bbb(0x1f0)])??[];_0x5d614a[_0x243bbb(0x212)](_0x193618)&&(this[_0x243bbb(0x25a)][_0x243bbb(0x1b4)](_0x27152d[_0x243bbb(0x1f0)],_0x5d614a[_0x243bbb(0x1a5)](_0x4a5b69=>_0x4a5b69!==_0x193618)),this[_0x243bbb(0x258)](_0x27152d[_0x243bbb(0x1f0)]));this[_0x243bbb(0x1ca)][_0x243bbb(0x1e4)](_0x193618),this[_0x243bbb(0x188)][_0x243bbb(0x1e4)](_0x193618);const _0x3ea7b7=(this[_0x243bbb(0x1af)][_0x243bbb(0x1b9)](_0x27152d[_0x243bbb(0x1f0)])??[])[_0x243bbb(0x1a5)](_0x3d3cd2=>{const _0x5e5d08=_0x243bbb,_0x57b27f=_0x3d3cd2[_0x5e5d08(0x21c)][_0x5e5d08(0x22a)](_0x537524=>_0x537524[_0x5e5d08(0x220)]===_0x5e5d08(0x208));if(_0x3d3cd2[_0x5e5d08(0x1a3)]===_0x193618)return _0x27152d[_0x5e5d08(0x1ee)]===_0x5e5d08(0x187)||_0x27152d[_0x5e5d08(0x1ee)]===_0x5e5d08(0x18b)||_0x57b27f;const _0x1d47d5=_0x57b27f&&_0x3d3cd2[_0x5e5d08(0x1ee)]!==_0x5e5d08(0x187)&&_0x3d3cd2[_0x5e5d08(0x1ee)]!==_0x5e5d08(0x18b);return _0x27152d[_0x5e5d08(0x1ee)]!==_0x5e5d08(0x187)||!_0x1d47d5;}),_0x49cd73=_0x3ea7b7[_0x243bbb(0x1a5)](_0x5cb131=>terminalTurn(_0x5cb131[_0x243bbb(0x1ee)])),_0x10f891=new Set(_0x49cd73[_0x243bbb(0x1b2)](-NodeRuntimeState[_0x243bbb(0x20b)])[_0x243bbb(0x240)](_0x57ba05=>_0x57ba05['id']));this[_0x243bbb(0x1af)][_0x243bbb(0x1b4)](_0x27152d[_0x243bbb(0x1f0)],_0x3ea7b7[_0x243bbb(0x1a5)](_0x479561=>!terminalTurn(_0x479561[_0x243bbb(0x1ee)])||_0x10f891[_0x243bbb(0x24c)](_0x479561['id'])));for(const [_0x4b9eb8,_0x24fd29]of this[_0x243bbb(0x20e)])if(_0x24fd29===_0x193618)this[_0x243bbb(0x20e)][_0x243bbb(0x1e4)](_0x4b9eb8);for(const [_0x2810f1,_0x4f5bb0]of this[_0x243bbb(0x1df)])if(_0x4f5bb0[_0x243bbb(0x1a3)]===_0x193618)this[_0x243bbb(0x1df)][_0x243bbb(0x1e4)](_0x2810f1);}[_0x4daaad(0x1f6)](_0x583fbc){const _0x279a49=_0x4daaad;return[...this[_0x279a49(0x1a2)][_0x279a49(0x1d8)]()][_0x279a49(0x240)](_0x39e122=>this[_0x279a49(0x1ca)][_0x279a49(0x1b9)](_0x39e122))[_0x279a49(0x22a)](_0x1e172a=>_0x1e172a?.[_0x279a49(0x253)]===_0x583fbc);}[_0x4daaad(0x25f)](_0x224bcc){const _0x2552ac=_0x4daaad;this[_0x2552ac(0x207)](_0x224bcc);const _0x3f5ca5=this[_0x2552ac(0x1f2)](_0x224bcc);if(_0x3f5ca5[_0x2552ac(0x22a)](_0x4e76a5=>!terminal(_0x4e76a5[_0x2552ac(0x1ee)])))throw new Error(_0x2552ac(0x24a));const _0x44685c=new Set(_0x3f5ca5[_0x2552ac(0x240)](_0x485476=>_0x485476['id']));this[_0x2552ac(0x217)][_0x2552ac(0x1e4)](_0x224bcc),this[_0x2552ac(0x1af)][_0x2552ac(0x1e4)](_0x224bcc),this[_0x2552ac(0x25a)][_0x2552ac(0x1e4)](_0x224bcc),this[_0x2552ac(0x1d6)][_0x2552ac(0x1e4)](_0x224bcc),this[_0x2552ac(0x252)][_0x2552ac(0x1e4)](_0x224bcc),this[_0x2552ac(0x1a2)][_0x2552ac(0x1e4)](_0x224bcc);for(const _0x1a5677 of _0x44685c){this[_0x2552ac(0x1ca)][_0x2552ac(0x1e4)](_0x1a5677),this[_0x2552ac(0x188)][_0x2552ac(0x1e4)](_0x1a5677);}for(const [_0x48260d,_0x55be05]of this[_0x2552ac(0x20e)])if(_0x44685c[_0x2552ac(0x24c)](_0x55be05))this[_0x2552ac(0x20e)][_0x2552ac(0x1e4)](_0x48260d);for(const [_0x2b7754,_0x12ec49]of this[_0x2552ac(0x1df)])if(_0x44685c[_0x2552ac(0x24c)](_0x12ec49[_0x2552ac(0x1a3)]))this[_0x2552ac(0x1df)][_0x2552ac(0x1e4)](_0x2b7754);}[_0x4daaad(0x218)](_0x14ed20){const _0x1e0dea=_0x4daaad;if(this[_0x1e0dea(0x1f6)](_0x14ed20))throw new Error(_0x1e0dea(0x19a));const _0x50fd44=new Set([...this[_0x1e0dea(0x217)][_0x1e0dea(0x1d8)]()][_0x1e0dea(0x1a5)](_0x323042=>_0x323042[_0x1e0dea(0x253)]===_0x14ed20)[_0x1e0dea(0x240)](_0x51b952=>_0x51b952['id'])),_0x2f6856=new Set([...this[_0x1e0dea(0x1ca)][_0x1e0dea(0x1d8)]()][_0x1e0dea(0x1a5)](_0x58949c=>_0x58949c[_0x1e0dea(0x253)]===_0x14ed20)[_0x1e0dea(0x240)](_0x31b1a3=>_0x31b1a3['id']));for(const _0x38430c of _0x50fd44){this[_0x1e0dea(0x217)][_0x1e0dea(0x1e4)](_0x38430c),this[_0x1e0dea(0x1af)][_0x1e0dea(0x1e4)](_0x38430c);}for(const _0x302168 of _0x2f6856){this[_0x1e0dea(0x1ca)][_0x1e0dea(0x1e4)](_0x302168),this[_0x1e0dea(0x188)][_0x1e0dea(0x1e4)](_0x302168);}for(const [_0x36ff96,_0x382c44]of this[_0x1e0dea(0x20e)])if(_0x2f6856[_0x1e0dea(0x24c)](_0x382c44))this[_0x1e0dea(0x20e)][_0x1e0dea(0x1e4)](_0x36ff96);for(const [_0xa4a2ce,_0x3998aa]of this[_0x1e0dea(0x1df)])if(_0x2f6856[_0x1e0dea(0x24c)](_0x3998aa[_0x1e0dea(0x1a3)]))this[_0x1e0dea(0x1df)][_0x1e0dea(0x1e4)](_0xa4a2ce);for(const _0x4042b3 of _0x50fd44){this[_0x1e0dea(0x25a)][_0x1e0dea(0x1e4)](_0x4042b3),this[_0x1e0dea(0x1d6)][_0x1e0dea(0x1e4)](_0x4042b3),this[_0x1e0dea(0x252)][_0x1e0dea(0x1e4)](_0x4042b3),this[_0x1e0dea(0x1a2)][_0x1e0dea(0x1e4)](_0x4042b3);}}[_0x4daaad(0x24b)](_0xddc34a,_0x5b5bc0){void _0xddc34a,void _0x5b5bc0;}[_0x4daaad(0x24d)](_0x5e5e27,_0x5457dc){const _0x1d530a=_0x4daaad,_0x222bec=this[_0x1d530a(0x207)](_0x5e5e27),_0x3b6855={..._0x222bec,..._0x5457dc};this[_0x1d530a(0x217)][_0x1d530a(0x1b4)](_0x5e5e27,_0x3b6855);if(_0x222bec[_0x1d530a(0x254)]!==_0x3b6855[_0x1d530a(0x254)]||_0x222bec[_0x1d530a(0x268)]!==_0x3b6855[_0x1d530a(0x268)]){for(const _0x4da719 of this[_0x1d530a(0x1f2)](_0x5e5e27))this[_0x1d530a(0x247)](_0x4da719,_0x3b6855);}return _0x3b6855;}[_0x4daaad(0x247)](_0x4b64b9,_0x5e8366){const _0x130aa7=_0x4daaad,_0x59b3bc=this[_0x130aa7(0x262)](_0x4b64b9['id']);this[_0x130aa7(0x1f8)]?.(_0x4b64b9,_0x5e8366,_0x59b3bc[_0x130aa7(0x267)]===-0x19ad+0x1*-0x3af+0x757*0x4?undefined:_0x59b3bc);}[_0x4daaad(0x258)](_0x3b2f41){const _0x1b279d=_0x4daaad;this[_0x1b279d(0x1d6)][_0x1b279d(0x1b4)](_0x3b2f41,(this[_0x1b279d(0x1d6)][_0x1b279d(0x1b9)](_0x3b2f41)??0x6a4+0x252d*0x1+-0x2bd1)+(0x5*0x407+0x156d*-0x1+-0x14b*-0x1));}[_0x4daaad(0x207)](_0x5bd02b){const _0x31faaa=_0x4daaad,_0x2ff230=this[_0x31faaa(0x217)][_0x31faaa(0x1b9)](_0x5bd02b);if(_0x2ff230===undefined)throw new Error(_0x31faaa(0x186));return _0x2ff230;}[_0x4daaad(0x232)](_0x62c8c1){const _0x520b9a=_0x4daaad,_0x12403a=this[_0x520b9a(0x1ca)][_0x520b9a(0x1b9)](_0x62c8c1);if(_0x12403a===undefined)throw new Error(_0x520b9a(0x1d9));return _0x12403a;}[_0x4daaad(0x1ad)](_0x1af1d8){const _0xedc5bd=_0x4daaad,_0x366696=this[_0xedc5bd(0x1df)][_0xedc5bd(0x1b9)](_0x1af1d8);if(_0x366696===undefined)throw new Error(_0xedc5bd(0x25c));return _0x366696;}[_0x4daaad(0x1fc)](_0x551786,_0x2cc025){const _0x5ecb80=_0x4daaad,_0x2412a9=this[_0x5ecb80(0x232)](_0x551786),_0x39417b=this[_0x5ecb80(0x1af)][_0x5ecb80(0x1b9)](_0x2412a9[_0x5ecb80(0x1f0)])??[];this[_0x5ecb80(0x1af)][_0x5ecb80(0x1b4)](_0x2412a9[_0x5ecb80(0x1f0)],_0x39417b[_0x5ecb80(0x240)](_0x41fe29=>_0x41fe29[_0x5ecb80(0x1a3)]===_0x551786?_0x2cc025(_0x41fe29):_0x41fe29));}[_0x4daaad(0x21f)](_0x3d6616){const _0x996692=_0x4daaad,_0x577a89=this[_0x996692(0x232)](_0x3d6616[_0x996692(0x1a3)]);this[_0x996692(0x1fc)](_0x3d6616[_0x996692(0x1a3)],_0x33ddc6=>{const _0x51442c=_0x996692;if(_0x3d6616[_0x51442c(0x1e1)]===_0x51442c(0x1d3)&&isRecord(_0x3d6616[_0x51442c(0x25d)])&&typeof _0x3d6616[_0x51442c(0x25d)][_0x51442c(0x24f)]===_0x51442c(0x1b8)){const _0x4aee7a=typeof _0x3d6616[_0x51442c(0x25d)][_0x51442c(0x1b7)]===_0x51442c(0x1b8)&&_0x3d6616[_0x51442c(0x25d)][_0x51442c(0x1b7)][_0x51442c(0x267)]<=0x139f+-0x17dd+0x496?_0x3d6616[_0x51442c(0x25d)][_0x51442c(0x1b7)]:undefined,_0x5a0292=_0x4aee7a===undefined?undefined:_0x3d6616[_0x51442c(0x1a3)]+':'+_0x4aee7a,_0x2d482b=_0x33ddc6[_0x51442c(0x21c)]['at'](-(-0xe57*0x1+0x1eb0+-0x1058)),_0x396bcc=_0x5a0292===undefined?_0x2d482b?.[_0x51442c(0x220)]===_0x51442c(0x18a)&&activeConversationItem(_0x2d482b[_0x51442c(0x1ee)])?_0x2d482b:undefined:_0x33ddc6[_0x51442c(0x21c)][_0x51442c(0x20a)](_0x48c760=>_0x48c760['id']===_0x5a0292&&_0x48c760[_0x51442c(0x220)]===_0x51442c(0x18a)),_0x515802=''+(_0x396bcc===undefined?'':readableText(_0x396bcc[_0x51442c(0x25d)]))+_0x3d6616[_0x51442c(0x25d)][_0x51442c(0x24f)],_0x5556c1={'id':_0x396bcc?.['id']??_0x5a0292??_0x3d6616[_0x51442c(0x1a3)]+_0x51442c(0x22b)+_0x3d6616[_0x51442c(0x199)],'sessionId':_0x577a89[_0x51442c(0x1f0)],'turnId':_0x33ddc6['id'],'runId':_0x3d6616[_0x51442c(0x1a3)],'parentItemId':null,'sourceSequence':_0x396bcc?.[_0x51442c(0x1ba)]??_0x3d6616[_0x51442c(0x199)],'revision':_0x3d6616[_0x51442c(0x199)],'kind':_0x51442c(0x18a),'status':_0x51442c(0x250),'payload':{'text':_0x515802,'format':_0x51442c(0x22f),'model':null},'startedAt':_0x396bcc?.[_0x51442c(0x1a4)]??_0x3d6616[_0x51442c(0x259)],'completedAt':null};return{..._0x33ddc6,'status':_0x51442c(0x1ed),'startedAt':_0x33ddc6[_0x51442c(0x1a4)]??_0x3d6616[_0x51442c(0x259)],'items':_0x396bcc===undefined?[..._0x33ddc6[_0x51442c(0x21c)],_0x5556c1]:_0x33ddc6[_0x51442c(0x21c)][_0x51442c(0x240)](_0x37fc98=>_0x37fc98['id']===_0x5556c1['id']?_0x5556c1:_0x37fc98)};}const _0x229e30=conversationItemFromEvent(_0x3d6616);if(_0x229e30!==undefined){const _0x1adb14=_0x33ddc6[_0x51442c(0x21c)]['at'](-(-0x1*-0x1cb2+-0x6fb*-0x1+-0x23ac)),_0x46a589=_0x1adb14?.[_0x51442c(0x220)]===_0x51442c(0x18a)&&activeConversationItem(_0x1adb14[_0x51442c(0x1ee)])?_0x33ddc6[_0x51442c(0x21c)][_0x51442c(0x240)](_0x286258=>_0x286258['id']===_0x1adb14['id']?{..._0x286258,'status':_0x51442c(0x215),'completedAt':_0x3d6616[_0x51442c(0x259)]}:_0x286258):_0x33ddc6[_0x51442c(0x21c)],_0x410879=_0x46a589[_0x51442c(0x20a)](_0x588612=>_0x588612['id']===_0x3d6616[_0x51442c(0x1a3)]+':'+_0x229e30[_0x51442c(0x1b7)]),_0x4c9390=_0x229e30[_0x51442c(0x1ee)],_0x581adb={'id':_0x3d6616[_0x51442c(0x1a3)]+':'+_0x229e30[_0x51442c(0x1b7)],'sessionId':_0x577a89[_0x51442c(0x1f0)],'turnId':_0x33ddc6['id'],'runId':_0x3d6616[_0x51442c(0x1a3)],'parentItemId':null,'sourceSequence':_0x410879?.[_0x51442c(0x1ba)]??_0x3d6616[_0x51442c(0x199)],'revision':(_0x410879?.[_0x51442c(0x22e)]??-(-0x1*-0x206+0x213e+-0x2343))+(-0x1*0x95+0x1d82+0xc*-0x269),'kind':_0x229e30[_0x51442c(0x220)],'status':_0x4c9390,'payload':mergeConversationItemPayload(_0x410879?.[_0x51442c(0x25d)],_0x229e30),'startedAt':_0x410879?.[_0x51442c(0x1a4)]??_0x3d6616[_0x51442c(0x259)],'completedAt':completedConversationItem(_0x4c9390)?_0x3d6616[_0x51442c(0x259)]:null};return{..._0x33ddc6,'status':terminal(_0x577a89[_0x51442c(0x1ee)])?_0x577a89[_0x51442c(0x1ee)]:_0x51442c(0x1ed),'startedAt':_0x33ddc6[_0x51442c(0x1a4)]??_0x3d6616[_0x51442c(0x259)],'items':_0x410879===undefined?[..._0x46a589,_0x581adb]:_0x46a589[_0x51442c(0x240)](_0xb3b9d1=>_0xb3b9d1['id']===_0x581adb['id']?_0x581adb:_0xb3b9d1)};}if(_0x3d6616[_0x51442c(0x1e1)]===_0x51442c(0x18e)||_0x3d6616[_0x51442c(0x1e1)]===_0x51442c(0x190))return{..._0x33ddc6,'status':_0x51442c(0x1ed),'startedAt':_0x33ddc6[_0x51442c(0x1a4)]??_0x3d6616[_0x51442c(0x259)]};if(_0x3d6616[_0x51442c(0x1e1)]===_0x51442c(0x19d)||_0x3d6616[_0x51442c(0x1e1)]===_0x51442c(0x216)||_0x3d6616[_0x51442c(0x1e1)]===_0x51442c(0x1c1))return{..._0x33ddc6,'status':this[_0x51442c(0x232)](_0x3d6616[_0x51442c(0x1a3)])[_0x51442c(0x1ee)],'completedAt':_0x3d6616[_0x51442c(0x259)],'items':_0x33ddc6[_0x51442c(0x21c)][_0x51442c(0x240)](_0x3bbc0b=>activeConversationItem(_0x3bbc0b[_0x51442c(0x1ee)])?{..._0x3bbc0b,'status':completedStatusForRun(this[_0x51442c(0x232)](_0x3d6616[_0x51442c(0x1a3)])[_0x51442c(0x1ee)]),'completedAt':_0x3d6616[_0x51442c(0x259)]}:_0x3bbc0b)};return _0x33ddc6;});}}function terminal(_0x115e94){const _0xf21b88=_0x4daaad;return[_0xf21b88(0x187),_0xf21b88(0x18c),_0xf21b88(0x204),_0xf21b88(0x18b),_0xf21b88(0x1e0)][_0xf21b88(0x212)](_0x115e94);}function terminalTurn(_0x57a323){const _0x27a173=_0x4daaad;return[_0x27a173(0x187),_0x27a173(0x18c),_0x27a173(0x204),_0x27a173(0x18b),_0x27a173(0x1e0)][_0x27a173(0x212)](_0x57a323);}function transitionAllowed(_0x328f42,_0x2f9c19){return!terminal(_0x328f42)||_0x328f42===_0x2f9c19;}function isRecord(_0x25cef0){const _0x203189=_0x4daaad;return typeof _0x25cef0===_0x203189(0x1dc)&&_0x25cef0!==null;}function readableText(_0x9ca06c){const _0x4d4515=_0x4daaad;return isRecord(_0x9ca06c)&&typeof _0x9ca06c[_0x4d4515(0x24f)]===_0x4d4515(0x1b8)?_0x9ca06c[_0x4d4515(0x24f)]:'';}function conversationItemFromEvent(_0x2dd646){const _0x2c415d=_0x4daaad;if(_0x2dd646[_0x2c415d(0x1e1)]!==_0x2c415d(0x1f9)||!isRecord(_0x2dd646[_0x2c415d(0x25d)]))return undefined;const _0x2b59ed=_0x2dd646[_0x2c415d(0x25d)][_0x2c415d(0x1b7)],_0x3f0b5c=_0x2dd646[_0x2c415d(0x25d)][_0x2c415d(0x220)],_0x2e4703=_0x2dd646[_0x2c415d(0x25d)][_0x2c415d(0x1ee)],_0x2785ba=_0x2dd646[_0x2c415d(0x25d)][_0x2c415d(0x25d)];if(typeof _0x2b59ed!==_0x2c415d(0x1b8)||_0x2b59ed[_0x2c415d(0x267)]===-0x10b9+0x1235+0x2*-0xbe||_0x2b59ed[_0x2c415d(0x267)]>0x221f+0x30b*-0x2+0x11*-0x1a1||typeof _0x3f0b5c!==_0x2c415d(0x1b8)||!projectableConversationKind(_0x3f0b5c)||typeof _0x2e4703!==_0x2c415d(0x1b8)||!projectableConversationStatus(_0x2e4703)||!isRecord(_0x2785ba))return undefined;const _0x711e2b=_0x2dd646[_0x2c415d(0x25d)][_0x2c415d(0x21d)];return{'itemId':_0x2b59ed,'kind':_0x3f0b5c,'status':_0x2e4703,'payload':_0x2785ba,'merge':_0x2dd646[_0x2c415d(0x25d)][_0x2c415d(0x214)]===!![],..._0x711e2b===_0x2c415d(0x1a9)||_0x711e2b===_0x2c415d(0x1b1)||_0x711e2b===_0x2c415d(0x1e2)?{'append':_0x711e2b}:{}};}function projectableConversationKind(_0x240549){const _0x80ff5a=_0x4daaad;return _0x240549===_0x80ff5a(0x18a)||_0x240549===_0x80ff5a(0x205)||_0x240549===_0x80ff5a(0x1fd)||_0x240549===_0x80ff5a(0x23e)||_0x240549===_0x80ff5a(0x211)||_0x240549===_0x80ff5a(0x1fa)||_0x240549===_0x80ff5a(0x222)||_0x240549===_0x80ff5a(0x209)||_0x240549===_0x80ff5a(0x1b0)||_0x240549===_0x80ff5a(0x20f)||_0x240549===_0x80ff5a(0x208);}function projectableConversationStatus(_0x3d461d){const _0x16fa89=_0x4daaad;return[_0x16fa89(0x1d7),_0x16fa89(0x250),_0x16fa89(0x215),_0x16fa89(0x18c),_0x16fa89(0x251),_0x16fa89(0x204),_0x16fa89(0x18b)][_0x16fa89(0x212)](_0x3d461d);}function mergeConversationItemPayload(_0x587f04,_0x1235dc){const _0x2a17cd=_0x4daaad,_0x4fc1c3=_0x1235dc[_0x2a17cd(0x214)]&&isRecord(_0x587f04)?_0x587f04:{},_0x38eea0={..._0x4fc1c3,..._0x1235dc[_0x2a17cd(0x25d)]};if(_0x1235dc[_0x2a17cd(0x21d)]===_0x2a17cd(0x1a9)){const _0x400a97=Array[_0x2a17cd(0x1cc)](_0x4fc1c3[_0x2a17cd(0x1a9)])?_0x4fc1c3[_0x2a17cd(0x1a9)]:[],_0x5c7d54=Array[_0x2a17cd(0x1cc)](_0x1235dc[_0x2a17cd(0x25d)][_0x2a17cd(0x1a9)])?_0x1235dc[_0x2a17cd(0x25d)][_0x2a17cd(0x1a9)]:[],_0x1872ec=new Map();for(const _0x5151b7 of[..._0x400a97,..._0x5c7d54]){if(!isRecord(_0x5151b7)||typeof _0x5151b7[_0x2a17cd(0x19b)]!==_0x2a17cd(0x200)||!Number[_0x2a17cd(0x264)](_0x5151b7[_0x2a17cd(0x19b)])||_0x5151b7[_0x2a17cd(0x19b)]<-0x2*0x5cb+-0xa6*-0x36+-0xbb7*0x2||typeof _0x5151b7[_0x2a17cd(0x24f)]!==_0x2a17cd(0x1b8))continue;_0x1872ec[_0x2a17cd(0x1b4)](_0x5151b7[_0x2a17cd(0x19b)],appendProjectionText(_0x1872ec[_0x2a17cd(0x1b9)](_0x5151b7[_0x2a17cd(0x19b)])??'',_0x5151b7[_0x2a17cd(0x24f)]));}_0x38eea0[_0x2a17cd(0x1a9)]=[..._0x1872ec][_0x2a17cd(0x23c)](([_0x82c7c6],[_0x2c623d])=>_0x82c7c6-_0x2c623d)[_0x2a17cd(0x240)](([_0x85d89f,_0x57e7d4])=>({'index':_0x85d89f,'text':_0x57e7d4}));}if(_0x1235dc[_0x2a17cd(0x21d)]===_0x2a17cd(0x1b1)){const _0x32e6de=typeof _0x4fc1c3[_0x2a17cd(0x1b1)]===_0x2a17cd(0x1b8)?_0x4fc1c3[_0x2a17cd(0x1b1)]:'',_0x73b1db=typeof _0x1235dc[_0x2a17cd(0x25d)][_0x2a17cd(0x1b1)]===_0x2a17cd(0x1b8)?_0x1235dc[_0x2a17cd(0x25d)][_0x2a17cd(0x1b1)]:'';_0x38eea0[_0x2a17cd(0x1b1)]=appendProjectionText(_0x32e6de,_0x73b1db);}if(_0x1235dc[_0x2a17cd(0x21d)]===_0x2a17cd(0x1e2)){const _0xdb7744=typeof _0x4fc1c3[_0x2a17cd(0x1e2)]===_0x2a17cd(0x1b8)?_0x4fc1c3[_0x2a17cd(0x1e2)]:'',_0x1fab01=typeof _0x1235dc[_0x2a17cd(0x25d)][_0x2a17cd(0x1e2)]===_0x2a17cd(0x1b8)?_0x1235dc[_0x2a17cd(0x25d)][_0x2a17cd(0x1e2)]:'';_0x38eea0[_0x2a17cd(0x1e2)]=appendProjectionText(_0xdb7744,_0x1fab01);}return _0x38eea0;}function appendProjectionText(_0x2df14a,_0x15cc04){const _0x328031=_0x4daaad,_0x26deea=''+_0x2df14a+_0x15cc04;return _0x26deea[_0x328031(0x267)]<=0x1e2b*0x2+0xd57+-0x229d?_0x26deea:_0x26deea[_0x328031(0x1b2)](0xc4e+0x26*0x36+-0x99*0x22,0x403b+0x4a53+-0x1*0x637f)+'…';}function activeConversationItem(_0x5b1296){const _0x8c2630=_0x4daaad;return _0x5b1296===_0x8c2630(0x1d7)||_0x5b1296===_0x8c2630(0x250);}function _0xaa7e(){const _0x44fe49=['Cgf1C2vKuxvLDwvZ','D29YA3nWywnLswq','y3vZDg9TvgL0Bgu','BgLZDenVBNzLCNnHDgLVBLr1CM5Z','DxnLCKL0zw1jza','ywrVChrsDw4','yNvTCff1zxvLvMvYC2LVBG','y3jLyxrLzef0','CxvLDwvKuNvUCW','qvvutW','qvbquK9wquXFtK9ux0zpvu5e','Cgf5Bg9Hza','BMf0AxzLq29UDhjVBa','CMvTB3zLqwDLBNrtzxnZAw9U','yxbWzw5KuNvUrxzLBNq','C2v0rxH0zxjUywXtzxnZAw9Uswq','CxvLDwvKtwvZC2fNzvrLEhq','DMvYC2LVBG','AxnjBNrLz2vY','yxbWCM92ywXjza','zxH0zxjUywXtzxnZAw9Uswq','BgvUz3rO','CNvUBMvYvgL0Bgu','DgL0Bgu','ywrK','u0vtu0LptL9ot1rFrK9vtKq','u1vdq0vfreve','CNvUu2vXDwvUy2vZ','rvHurvjoquW','yxnZAxn0yw50x21LC3nHz2u','su5urvjsvvburuq','rKfjteve','yxr0ywnOBwvUDhm','CNvUlNn0yxj0zwq','AxnrDwv1zwrsDw4','CNvUlNj1BM5PBMC','CMvVCMrLCLnLC3nPB25rDwv1zq','BgLZDefNzw50u2vZC2LVBNm','zgvJAwrLqxbWCM92ywW','yMfZzty0DxjS','C3rHCNrZv2L0Aa','zwzMB3j0','AgfZqwn0AxzLu2vZC2LVBKXLyxnL','y3jLyxrLtwvZC2fNzvj1BG','C2vXDwvUy2u','v09ss1nqqunfx0jvu1K','Aw5KzxG','nty3nJq2ofDvB1jWuq','CNvUlMnVBxbSzxrLza','mta0mdqWotbwwfzQBu4','qvbquK9wquXFtK9ux0vyueLsruq','DxbKyxrLuxvLDwvKtwvZC2fNzq','u0vtu0LptL9dsefotKvmx1rps0vox0LovKfmsuq','BgvHC2vZ','CNvUswq','C3rHCNrLzef0','zMLSDgvY','y3DK','zxHWAxjLC0f0','CNvUBMvY','C2vJDgLVBNm','CMvWBgfJzq','CMvTB3zLvgvYBwLUywXsDw4','uvvfvuvFvKvsu0LptL9dt05gteLdva','CMvXDwLYzufWChjVDMfS','uLvox0fdveLwrq','DhvYBNm','Dw5RBM93BG','B3v0Chv0uhjLDMLLDW','C2XPy2u','qvbquK9wquXFrvHqsvjfra','C2v0','uvvfvuvFsvrftv9jtLzbteLe','zNjVBq','AxrLBuLK','C3rYAw5N','z2v0','C291CMnLu2vXDwvUy2u','uLvox1nuqvrfx0LovKfmsuq','DMfSDwu','zMLUze1LC3nHz2vsDw4','y3vYC29Y','Bw9KzwW','zMfPBgvK','CNvUlNjLAMvJDgvK','tufsx01btKfhruq','uLvotKvs','rvzftLrFu0vrvuvoq0vFr0fq','DgvYBwLUywXsDw5jzhm','CgfYC2u','DhvYBG','uvvfvuve','DxbKyxrLqwDLBNrtzxnZAw9Uq29UzMLNDxjHDgLVBG','CNvUCW','DxrMoa','AxnbCNjHEq','Cgf1C2vtzxnZAw9UuxvLDwu','C2v0tMf0AxzLq29UDhjVBa','BgLZDefWChjVDMfSCW','ywnJzxnZ','C3rYAw5NAwz5','y29UDgvUDa','Dgv4Dc5KzwX0yq','y3jLyxrLqwDLBNrtzxnZAw9U','zxHWAxjLqxbWCM92ywW','CxvLDwvwzxjZAw9UCW','uevoreLorW','DMfSDwvZ','uLvox05pvf9gt1vora','BwLU','uLvox1rfuK1jtKfm','B2jQzwn0','BMv4Da','Aw5PDgLHDgvKqNLvC2vYswq','yxbWCM92ywXZ','te9tva','zxzLBNruExbL','B3v0Chv0u3vTBwfYEq','CMvZDw1Lu2vZC2LVBLf1zxvL','zgvSzxrL','rvHqsvjfra','BgfZDfj1BLnLCxvLBMnL','CgLUBMvKqxq','Bwf4','DxnLCL9TzxnZywDL','BgLZDe5VBNrLCM1PBMfSuNvUCW','BgfZDefJDgL2Axr5qxq','BgLZDenVBNzLCNnHDgLVBKL0zw1Z','uLvotKLorW','C3rHDhvZ','y29TBwfUza','C2vZC2LVBKLK','nZmXmZKXmeXOAeDSyW','BgLZDfj1BNngB3jtzxnZAw9U','BgLTAxq','C2L6zq','ywn0AxzLu2vZC2LVBLj1BG','AgfZqwn0AxzLv29YA3nWywnLtgvHC2u','y29TCgXLDgvKqxq','B25sDw5dAgfUz2vK','y29UDMvYC2f0Aw9UlML0zw0','CgXHBG','y2XPzw50twvZC2fNzuLK','DxbKyxrLvhvYBKzVCLj1BG','Dg9VBf9JywXS','C2v0q2HHBM5LBfrVA2vU','ndyWoti1wMHdBgfw','BNvTyMvY','ChjVBw90zvnLC3nPB25jzgvUDgL0Eq','y3jLyxrLqxbWCM92ywW','zgvSzxrLuxvLDwvKuNvU','q0foq0vmteve','CMvHC29UAw5Nx3n1Bw1HCNK','u0vtu0LptL9usvrmrv9jtLzbteLe','CMvXDwLYzvnLC3nPB24','zxjYB3i','y29UDgv4Df9JB21Wywn0Aw9U','zMLUza','tufyx0nptvbmrvrfrf9uvvjou19qrvjFu0vtu0LptG','qundrvburuq','qunusvzf','BwvZC2fNzvj1BNm','D2fYBMLUzW','z2v0qxbWCM92ywW','DxnLCL9PBNb1Df9Yzxf1zxn0','Aw5JBhvKzxm','BM9KzuLK','BwvYz2u','q09nueXfveve','CNvUlMzHAwXLza','C2vZC2LVBNm','CMvTB3zLv29YA3nWywnL','DhjPBq','C2nVCgu','mteYs3DOswHk','AxrLBxm','yxbWzw5K','u0vtu0LptL9fwfrfuK5btf9jrf9jtLzbteLe','ChjVAMvJDev2zw50','A2LUza','z2v0qwDLBNrtzxnZAw9U','zMLSzv9JAgfUz2u','mKHxzezrsa','z2v0uNvU','BM93','nJa3nJGWohntyLnQyG','Dg9tDhjPBMC','Aw1Hz2uV','y2XHAw1ozxH0uxvLDwvKuNvU','C29Tzq','oMfZC2LZDgfUDdO','zxHWAxjLrhvLqxbWCM92ywXZ','zMXHDe1HCa','CMv2AxnPB24','BwfYA2rVD24','z2v0v29YA3nWywnL','C2v0vgvTCg9Yyxj5vgL0BgvjzK1PC3nPBMC','CMvXDwLYzvj1BG','CgLUBMvK','CMvJB3jKq29TBwfUzev4zwn1DgLVBG','qvbquK9wquXFquXsrufewv9erunjreve','yNL0zuXLBMD0Aa','yMfZzty0','y29UDMvYC2f0Aw9UvhvYBKzVCLj1BG','u0vtu0LptL9jrf9dt05gteLdva','zMLUzefNzw50u2vZC2LVBKj5rxH0zxjUywXtzxnZAw9U','v09ss1nqqunfx05pvf9gt1vora','C29YDa','ChjPB3jPDgL6zvf1zxvLzfj1BG','y29TBwfUzf9LEgvJDxrPB24','C2vZC2LVBLf1zxvL','BwfW','DhjHBNnPDgLVBLj1BG','CNvUDgLTztO','otaXmJG4BNPpvLPd','ntaXmdG3sfn0CeDU','DxbKyxrLu2vZC2LVBK1LDgfKyxrH','q1vtve9n','zw1PDfj1BKnOyw5Nzwq','C2v0uNvUBMvYvgL0BgvgCM9TtMf0AxzL','ywn0AxzLv29YA3nWywnLtgvHC2vdB3vUDa','u0vtu0LptL9bq1rjvKu','CMvJB25JAwXLuNvU','AgfZ','CMvWBgfJzvnLC3nPB24','qvbquK9wquXFquXsrufewv9fweLtvfm','Dgv4Da','su5Fufjpr1jfu1m','revdteLoruq'];_0xaa7e=function(){return _0x44fe49;};return _0xaa7e();}function completedConversationItem(_0x9524e){return!activeConversationItem(_0x9524e);}function completedStatusForRun(_0x85a2e7){const _0x1a188d=_0x4daaad;if(_0x85a2e7===_0x1a188d(0x18b))return _0x1a188d(0x18b);if(_0x85a2e7===_0x1a188d(0x204))return _0x1a188d(0x204);if(_0x85a2e7===_0x1a188d(0x18c))return _0x1a188d(0x18c);return _0x1a188d(0x215);}function encodeCursor(_0x34d24b,_0x40690d){const _0x1d99e5=_0x4daaad;return Buffer[_0x1d99e5(0x1b6)](JSON[_0x1d99e5(0x1d1)]({'scope':_0x34d24b,'value':_0x40690d}))[_0x1d99e5(0x227)](_0x1d99e5(0x194));}function decodeCursor(_0x5b980e,_0x241a68){const _0x33cc1b=_0x4daaad;if(_0x5b980e===undefined)return-0x21ee+0x24ba*0x1+0x166*-0x2;try{const _0x1fa433=JSON[_0x33cc1b(0x1c6)](Buffer[_0x33cc1b(0x1b6)](_0x5b980e,_0x33cc1b(0x194))[_0x33cc1b(0x227)](_0x33cc1b(0x1cb)));return _0x1fa433[_0x33cc1b(0x21a)]===_0x241a68&&Number[_0x33cc1b(0x264)](_0x1fa433[_0x33cc1b(0x1bc)])&&_0x1fa433[_0x33cc1b(0x1bc)]>=0x1960+-0x2*0xe45+-0x195*-0x2?_0x1fa433[_0x33cc1b(0x1bc)]:0x1aa3+-0x809+-0x129a;}catch{return 0x1581+-0x24*-0xb7+0x57*-0x8b;}}