@jrkropp/codex-js 0.1.2 → 0.1.4

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 (134) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +2 -2
  3. package/dist/ClientNotification-B6-FhXQf.d.ts +5 -0
  4. package/dist/DynamicToolCallResponse-82DFjES2.d.ts +8 -0
  5. package/dist/DynamicToolSpec-CfnhqAYK.d.ts +29 -0
  6. package/dist/PermissionsRequestApprovalResponse-DxzPPDRb.d.ts +55 -0
  7. package/dist/ProviderStatusBanner-BlP6lzwE.d.ts +441 -0
  8. package/dist/ServerRequest-B5cKVJjr.d.ts +2181 -0
  9. package/dist/{session-DPhHN7RZ.d.ts → ThreadResumeResponse-DvmE1juU.d.ts} +3 -306
  10. package/dist/ToolRequestUserInputQuestion-CeZa5X1J.d.ts +23 -0
  11. package/dist/ToolRequestUserInputResponse-zcPLwbiK.d.ts +17 -0
  12. package/dist/TurnSteerResponse-0kBCfplh.d.ts +209 -0
  13. package/dist/WebSearchToolConfig-D3ep0625.d.ts +18 -0
  14. package/dist/chat-runtime-9RkXHC_w.d.ts +382 -0
  15. package/dist/chunk-2DZRMCI2.js +1258 -0
  16. package/dist/chunk-2DZRMCI2.js.map +1 -0
  17. package/dist/chunk-4DPLJPB5.js +396 -0
  18. package/dist/chunk-4DPLJPB5.js.map +1 -0
  19. package/dist/chunk-5JMJ6OI5.js +3 -0
  20. package/dist/chunk-5JMJ6OI5.js.map +1 -0
  21. package/dist/chunk-6ZMJ34KE.js +1153 -0
  22. package/dist/chunk-6ZMJ34KE.js.map +1 -0
  23. package/dist/chunk-CGBS37IU.js +128 -0
  24. package/dist/chunk-CGBS37IU.js.map +1 -0
  25. package/dist/chunk-DCMKA2A6.js +18 -0
  26. package/dist/chunk-DCMKA2A6.js.map +1 -0
  27. package/dist/chunk-DYLHN3HG.js +937 -0
  28. package/dist/chunk-DYLHN3HG.js.map +1 -0
  29. package/dist/{chunk-SVK6PLGO.js → chunk-LWQNX4LI.js} +12009 -18768
  30. package/dist/chunk-LWQNX4LI.js.map +1 -0
  31. package/dist/{chunk-JLDH4U5L.js → chunk-NCI4MAWZ.js} +317 -1967
  32. package/dist/chunk-NCI4MAWZ.js.map +1 -0
  33. package/dist/chunk-O44XP7LH.js +214 -0
  34. package/dist/chunk-O44XP7LH.js.map +1 -0
  35. package/dist/chunk-PST3ZWX2.js +555 -0
  36. package/dist/chunk-PST3ZWX2.js.map +1 -0
  37. package/dist/chunk-SYPHCDRD.js +1133 -0
  38. package/dist/chunk-SYPHCDRD.js.map +1 -0
  39. package/dist/chunk-V4BMZWBM.js +2401 -0
  40. package/dist/chunk-V4BMZWBM.js.map +1 -0
  41. package/dist/chunk-W7S6HFCQ.js +1983 -0
  42. package/dist/chunk-W7S6HFCQ.js.map +1 -0
  43. package/dist/chunk-YHVCFD2D.js +117 -0
  44. package/dist/chunk-YHVCFD2D.js.map +1 -0
  45. package/dist/chunk-Z63UPBS3.js +152 -0
  46. package/dist/chunk-Z63UPBS3.js.map +1 -0
  47. package/dist/client/index.d.ts +16 -4
  48. package/dist/client/index.js +13 -1
  49. package/dist/codex-rs/app-server/index.d.ts +161 -0
  50. package/dist/codex-rs/app-server/index.js +13 -0
  51. package/dist/codex-rs/app-server/index.js.map +1 -0
  52. package/dist/codex-rs/app-server-protocol/index.d.ts +1722 -0
  53. package/dist/codex-rs/app-server-protocol/index.js +6 -0
  54. package/dist/codex-rs/app-server-protocol/index.js.map +1 -0
  55. package/dist/codex-rs/app-server-protocol/protocol.d.ts +19 -0
  56. package/dist/codex-rs/app-server-protocol/protocol.js +4 -0
  57. package/dist/codex-rs/app-server-protocol/protocol.js.map +1 -0
  58. package/dist/codex-rs/codex-api/index.d.ts +104 -0
  59. package/dist/codex-rs/codex-api/index.js +11 -0
  60. package/dist/codex-rs/codex-api/index.js.map +1 -0
  61. package/dist/codex-rs/config/index.d.ts +88 -0
  62. package/dist/codex-rs/config/index.js +4 -0
  63. package/dist/codex-rs/config/index.js.map +1 -0
  64. package/dist/codex-rs/core/config/index.d.ts +61 -0
  65. package/dist/codex-rs/core/config/index.js +5 -0
  66. package/dist/codex-rs/core/config/index.js.map +1 -0
  67. package/dist/codex-rs/core/index.d.ts +1393 -0
  68. package/dist/codex-rs/core/index.js +11 -0
  69. package/dist/codex-rs/core/index.js.map +1 -0
  70. package/dist/codex-rs/model-provider/index.d.ts +2 -0
  71. package/dist/codex-rs/model-provider/index.js +4 -0
  72. package/dist/codex-rs/model-provider/index.js.map +1 -0
  73. package/dist/codex-rs/models-manager/index.d.ts +2 -0
  74. package/dist/codex-rs/models-manager/index.js +4 -0
  75. package/dist/codex-rs/models-manager/index.js.map +1 -0
  76. package/dist/codex-rs/parity.d.ts +26 -0
  77. package/dist/codex-rs/parity.js +3 -0
  78. package/dist/codex-rs/parity.js.map +1 -0
  79. package/dist/codex-rs/thread-store/index.d.ts +5 -0
  80. package/dist/codex-rs/thread-store/index.js +4 -0
  81. package/dist/codex-rs/thread-store/index.js.map +1 -0
  82. package/dist/codex-rs/unsupported.d.ts +15 -0
  83. package/dist/codex-rs/unsupported.js +22 -0
  84. package/dist/codex-rs/unsupported.js.map +1 -0
  85. package/dist/codex-rs/utils/output-truncation.d.ts +21 -0
  86. package/dist/codex-rs/utils/output-truncation.js +4 -0
  87. package/dist/codex-rs/utils/output-truncation.js.map +1 -0
  88. package/dist/codex-rs/utils/string.d.ts +7 -0
  89. package/dist/codex-rs/utils/string.js +3 -0
  90. package/dist/codex-rs/utils/string.js.map +1 -0
  91. package/dist/common-CTyph5x8.d.ts +40 -0
  92. package/dist/event-mapping-CbISdQ1D.d.ts +43 -0
  93. package/dist/history-CfM-4V7b.d.ts +1654 -0
  94. package/dist/index-77U_Oc-a.d.ts +63 -0
  95. package/dist/index-CoDZosq0.d.ts +261 -0
  96. package/dist/index.d.ts +18 -7
  97. package/dist/index.js +16 -2
  98. package/dist/lib-nXlaKiS-.d.ts +48 -0
  99. package/dist/live-thread-BMvlflzM.d.ts +30 -0
  100. package/dist/merge-B_AWVmnI.d.ts +24 -0
  101. package/dist/mod-DYVLSWO4.d.ts +91 -0
  102. package/dist/plan-mode-Cv6KWb_S.d.ts +14 -0
  103. package/dist/proposed-plan-DpN1ma0Y.d.ts +53 -0
  104. package/dist/protocol-mpBcYHrm.d.ts +1655 -0
  105. package/dist/react/index.d.ts +56 -48
  106. package/dist/react/index.js +16 -2
  107. package/dist/{remote-_6TDvg-g.d.ts → remote-ClZbq9KN.d.ts} +3 -1
  108. package/dist/rendered-thread-AOxw3V5b.d.ts +29 -0
  109. package/dist/responses_websocket-BhxSgCzK.d.ts +183 -0
  110. package/dist/runtime-Cm6ml53h.d.ts +528 -0
  111. package/dist/server/index.d.ts +29 -2416
  112. package/dist/server/index.js +13 -1
  113. package/dist/session-BRYzi8OT.d.ts +46 -0
  114. package/dist/shadcn/index.d.ts +1 -1
  115. package/dist/{sidebar-DT2XoitN.d.ts → sidebar-DMMij22z.d.ts} +1 -1
  116. package/dist/spec_plan_types-CmsJ-Tfn.d.ts +260 -0
  117. package/dist/{store-GYldc9EJ.d.ts → store-AGRxhgQ3.d.ts} +2 -1
  118. package/dist/t3code/apps/web/components/chat.d.ts +508 -0
  119. package/dist/t3code/apps/web/components/chat.js +12 -0
  120. package/dist/t3code/apps/web/components/chat.js.map +1 -0
  121. package/dist/t3code/apps/web/index.d.ts +12 -0
  122. package/dist/t3code/apps/web/index.js +13 -0
  123. package/dist/t3code/apps/web/index.js.map +1 -0
  124. package/dist/testing/index.d.ts +9 -91
  125. package/dist/testing/index.js +13 -1
  126. package/dist/thread-history-builder-zW0zeqcS.d.ts +58 -0
  127. package/dist/thread_event_store-C0zYzukG.d.ts +77 -0
  128. package/dist/types-BTeabLYr.d.ts +126 -0
  129. package/package.json +152 -88
  130. package/dist/chat-runtime-D7wu_KbX.d.ts +0 -747
  131. package/dist/chunk-JLDH4U5L.js.map +0 -1
  132. package/dist/chunk-SVK6PLGO.js.map +0 -1
  133. package/dist/index-CB9la6xE.d.ts +0 -112
  134. package/dist/thread_event_store-B9CoQUIA.d.ts +0 -3868
@@ -0,0 +1,1153 @@
1
+ import { parseClientTransportPayload, serializeJsonRpcResponse, serializeJsonRpcError } from './chunk-V4BMZWBM.js';
2
+
3
+ // src/upstream/codex-rs/app-server-client/src/session.ts
4
+ var AppServerSession = class {
5
+ constructor(client) {
6
+ this.client = client;
7
+ }
8
+ client;
9
+ nextRequestIdValue = 1;
10
+ nextRequestId() {
11
+ const requestId = this.nextRequestIdValue;
12
+ this.nextRequestIdValue += 1;
13
+ return requestId;
14
+ }
15
+ nextEvent() {
16
+ return this.client.nextEvent?.() ?? Promise.resolve(null);
17
+ }
18
+ events() {
19
+ return this.client.events?.() ?? null;
20
+ }
21
+ requestTyped(request) {
22
+ return this.client.requestTyped(request);
23
+ }
24
+ initialize(params = defaultInitializeParams()) {
25
+ return this.requestTyped({
26
+ id: this.nextRequestId(),
27
+ method: "initialize",
28
+ params
29
+ });
30
+ }
31
+ threadStart(params) {
32
+ return this.requestTyped({
33
+ id: this.nextRequestId(),
34
+ method: "thread/start",
35
+ params
36
+ });
37
+ }
38
+ threadResume(params) {
39
+ return this.requestTyped({
40
+ id: this.nextRequestId(),
41
+ method: "thread/resume",
42
+ params
43
+ });
44
+ }
45
+ threadList(params = {}) {
46
+ return this.requestTyped({
47
+ id: this.nextRequestId(),
48
+ method: "thread/list",
49
+ params
50
+ });
51
+ }
52
+ collaborationModeList(params = {}) {
53
+ return this.requestTyped({
54
+ id: this.nextRequestId(),
55
+ method: "collaborationMode/list",
56
+ params
57
+ });
58
+ }
59
+ configMcpServerReload() {
60
+ return this.requestTyped({
61
+ id: this.nextRequestId(),
62
+ method: "config/mcpServer/reload",
63
+ params: void 0
64
+ });
65
+ }
66
+ mcpServerStatusList(params = {}) {
67
+ return this.requestTyped({
68
+ id: this.nextRequestId(),
69
+ method: "mcpServerStatus/list",
70
+ params
71
+ });
72
+ }
73
+ mcpResourceRead(params) {
74
+ return this.requestTyped({
75
+ id: this.nextRequestId(),
76
+ method: "mcpServer/resource/read",
77
+ params
78
+ });
79
+ }
80
+ mcpServerToolCall(params) {
81
+ return this.requestTyped({
82
+ id: this.nextRequestId(),
83
+ method: "mcpServer/tool/call",
84
+ params
85
+ });
86
+ }
87
+ mcpServerOauthLogin(params) {
88
+ return this.requestTyped({
89
+ id: this.nextRequestId(),
90
+ method: "mcpServer/oauth/login",
91
+ params
92
+ });
93
+ }
94
+ threadRead(params) {
95
+ return this.requestTyped({
96
+ id: this.nextRequestId(),
97
+ method: "thread/read",
98
+ params
99
+ });
100
+ }
101
+ threadNameSet(params) {
102
+ return this.requestTyped({
103
+ id: this.nextRequestId(),
104
+ method: "thread/name/set",
105
+ params
106
+ });
107
+ }
108
+ threadArchive(params) {
109
+ return this.requestTyped({
110
+ id: this.nextRequestId(),
111
+ method: "thread/archive",
112
+ params
113
+ });
114
+ }
115
+ threadUnarchive(params) {
116
+ return this.requestTyped({
117
+ id: this.nextRequestId(),
118
+ method: "thread/unarchive",
119
+ params
120
+ });
121
+ }
122
+ threadMetadataUpdate(params) {
123
+ return this.requestTyped({
124
+ id: this.nextRequestId(),
125
+ method: "thread/metadata/update",
126
+ params
127
+ });
128
+ }
129
+ turnStart(params) {
130
+ return this.requestTyped({
131
+ id: this.nextRequestId(),
132
+ method: "turn/start",
133
+ params
134
+ });
135
+ }
136
+ turnSteer(params) {
137
+ return this.requestTyped({
138
+ id: this.nextRequestId(),
139
+ method: "turn/steer",
140
+ params
141
+ });
142
+ }
143
+ turnInterrupt(params) {
144
+ return this.requestTyped({
145
+ id: this.nextRequestId(),
146
+ method: "turn/interrupt",
147
+ params
148
+ });
149
+ }
150
+ threadCompactStart(params) {
151
+ return this.requestTyped({
152
+ id: this.nextRequestId(),
153
+ method: "thread/compact/start",
154
+ params
155
+ });
156
+ }
157
+ resolveServerRequest(requestId, result) {
158
+ return this.client.resolveServerRequest(requestId, result);
159
+ }
160
+ rejectServerRequest(requestId, error) {
161
+ return this.client.rejectServerRequest(requestId, error);
162
+ }
163
+ };
164
+ function defaultInitializeParams() {
165
+ return {
166
+ capabilities: {
167
+ experimentalApi: false,
168
+ optOutNotificationMethods: []
169
+ },
170
+ clientInfo: {
171
+ name: "codex-js",
172
+ title: null,
173
+ version: "0.0.0"
174
+ }
175
+ };
176
+ }
177
+
178
+ // src/upstream/codex-rs/app-server-client/src/pending_requests.ts
179
+ var PendingAppServerRequests = class {
180
+ dynamicToolCalls = /* @__PURE__ */ new Map();
181
+ execApprovals = /* @__PURE__ */ new Map();
182
+ fileChangeApprovals = /* @__PURE__ */ new Map();
183
+ mcpRequests = /* @__PURE__ */ new Map();
184
+ permissionsApprovals = /* @__PURE__ */ new Map();
185
+ userInputs = /* @__PURE__ */ new Map();
186
+ clear() {
187
+ this.dynamicToolCalls.clear();
188
+ this.execApprovals.clear();
189
+ this.fileChangeApprovals.clear();
190
+ this.mcpRequests.clear();
191
+ this.permissionsApprovals.clear();
192
+ this.userInputs.clear();
193
+ }
194
+ noteServerRequest(request) {
195
+ switch (request.method) {
196
+ case "item/commandExecution/requestApproval": {
197
+ const id = request.params.approvalId ?? request.params.itemId;
198
+ this.execApprovals.set(id, request.id);
199
+ return null;
200
+ }
201
+ case "item/fileChange/requestApproval":
202
+ this.fileChangeApprovals.set(request.params.itemId, request.id);
203
+ return null;
204
+ case "item/permissions/requestApproval":
205
+ this.permissionsApprovals.set(request.params.itemId, request.id);
206
+ return null;
207
+ case "item/tool/requestUserInput": {
208
+ const queue = this.userInputs.get(request.params.turnId) ?? [];
209
+ queue.push({
210
+ itemId: request.params.itemId,
211
+ requestId: request.id
212
+ });
213
+ this.userInputs.set(request.params.turnId, queue);
214
+ return null;
215
+ }
216
+ case "mcpServer/elicitation/request":
217
+ this.mcpRequests.set(
218
+ mcpRequestKey(request.params.serverName, request.id),
219
+ request.id
220
+ );
221
+ return null;
222
+ case "item/tool/call":
223
+ this.dynamicToolCalls.set(request.params.callId, request.id);
224
+ return null;
225
+ default:
226
+ return {
227
+ message: `Unsupported Codex app-server request: ${request.method}`,
228
+ requestId: request.id
229
+ };
230
+ }
231
+ }
232
+ takeCommandExecutionApprovalResolution(id, response) {
233
+ return takeMapResolution(this.execApprovals, id, response);
234
+ }
235
+ takeFileChangeApprovalResolution(id, response) {
236
+ return takeMapResolution(this.fileChangeApprovals, id, response);
237
+ }
238
+ takePermissionsApprovalResolution(id, response) {
239
+ return takeMapResolution(this.permissionsApprovals, id, response);
240
+ }
241
+ takeDynamicToolCallResolution(callId, response) {
242
+ return takeMapResolution(this.dynamicToolCalls, callId, response);
243
+ }
244
+ takeUserInputResolution(turnId, response) {
245
+ const pending = this.popUserInputRequestForTurn(turnId);
246
+ return pending ? { requestId: pending.requestId, result: response } : null;
247
+ }
248
+ takeMcpElicitationResolution(serverName, requestId, response) {
249
+ return takeMapResolution(
250
+ this.mcpRequests,
251
+ mcpRequestKey(serverName, requestId),
252
+ response
253
+ );
254
+ }
255
+ resolveNotification(requestId) {
256
+ const execApproval = removeValue(this.execApprovals, requestId);
257
+ if (execApproval) {
258
+ return { id: execApproval, type: "exec_approval" };
259
+ }
260
+ const fileChangeApproval = removeValue(
261
+ this.fileChangeApprovals,
262
+ requestId
263
+ );
264
+ if (fileChangeApproval) {
265
+ return { id: fileChangeApproval, type: "file_change_approval" };
266
+ }
267
+ const permissionsApproval = removeValue(
268
+ this.permissionsApprovals,
269
+ requestId
270
+ );
271
+ if (permissionsApproval) {
272
+ return { id: permissionsApproval, type: "permissions_approval" };
273
+ }
274
+ const userInput = this.removeUserInputRequest(requestId);
275
+ if (userInput) {
276
+ return { itemId: userInput.itemId, type: "user_input" };
277
+ }
278
+ const dynamicToolCall = removeValue(this.dynamicToolCalls, requestId);
279
+ if (dynamicToolCall) {
280
+ return { callId: dynamicToolCall, type: "dynamic_tool_call" };
281
+ }
282
+ const mcpRequest = removeValue(this.mcpRequests, requestId);
283
+ if (mcpRequest) {
284
+ const [serverName] = mcpRequest.split(":");
285
+ return { requestId, serverName, type: "mcp_elicitation" };
286
+ }
287
+ return null;
288
+ }
289
+ containsServerRequest(request) {
290
+ return this.requestIds().some((requestId) => requestId === request.id);
291
+ }
292
+ requestIds() {
293
+ return [
294
+ ...this.execApprovals.values(),
295
+ ...this.fileChangeApprovals.values(),
296
+ ...this.permissionsApprovals.values(),
297
+ ...this.dynamicToolCalls.values(),
298
+ ...this.mcpRequests.values(),
299
+ ...Array.from(this.userInputs.values()).flatMap(
300
+ (queue) => queue.map((request) => request.requestId)
301
+ )
302
+ ];
303
+ }
304
+ popUserInputRequestForTurn(turnId) {
305
+ const queue = this.userInputs.get(turnId);
306
+ const pending = queue?.shift() ?? null;
307
+ if (queue && queue.length === 0) {
308
+ this.userInputs.delete(turnId);
309
+ }
310
+ return pending;
311
+ }
312
+ removeUserInputRequest(requestId) {
313
+ for (const [turnId, queue] of this.userInputs) {
314
+ const index = queue.findIndex((pending2) => pending2.requestId === requestId);
315
+ if (index === -1) {
316
+ continue;
317
+ }
318
+ const [pending] = queue.splice(index, 1);
319
+ if (queue.length === 0) {
320
+ this.userInputs.delete(turnId);
321
+ }
322
+ return pending ?? null;
323
+ }
324
+ return null;
325
+ }
326
+ };
327
+ function takeMapResolution(map, key, result) {
328
+ const requestId = map.get(key);
329
+ if (requestId === void 0) {
330
+ return null;
331
+ }
332
+ map.delete(key);
333
+ return { requestId, result };
334
+ }
335
+ function removeValue(map, value) {
336
+ for (const [key, current] of map) {
337
+ if (current === value) {
338
+ map.delete(key);
339
+ return key;
340
+ }
341
+ }
342
+ return null;
343
+ }
344
+ function mcpRequestKey(serverName, requestId) {
345
+ return `${serverName}:${requestId}`;
346
+ }
347
+
348
+ // src/upstream/codex-rs/app-server-client/src/thread_event_store.ts
349
+ var ThreadEventStore = class _ThreadEventStore {
350
+ accountRateLimits = null;
351
+ activeTurnIds = /* @__PURE__ */ new Set();
352
+ bufferedEvents = [];
353
+ connectionStatus = "idle";
354
+ errors = [];
355
+ pendingRequests = /* @__PURE__ */ new Map();
356
+ resolvedRequestIds = [];
357
+ thread = null;
358
+ tokenUsage = null;
359
+ turns = [];
360
+ warnings = [];
361
+ static fromThread(thread) {
362
+ const store = new _ThreadEventStore();
363
+ store.setThread(thread);
364
+ return store;
365
+ }
366
+ applyNotification(notification) {
367
+ applyServerNotificationToThreadEventStore(this, notification);
368
+ return this.snapshot();
369
+ }
370
+ applyRequest(request) {
371
+ applyServerRequestToThreadEventStore(this, request);
372
+ return this.snapshot();
373
+ }
374
+ setConnectionStatus(status) {
375
+ this.connectionStatus = status;
376
+ return this.snapshot();
377
+ }
378
+ setThread(thread) {
379
+ this.thread = cloneThread(thread);
380
+ this.turns = thread.turns.map(cloneTurn);
381
+ this.activeTurnIds = new Set(
382
+ this.turns.filter((turn) => turn.status === "inProgress").map((turn) => turn.id)
383
+ );
384
+ return this.snapshot();
385
+ }
386
+ snapshot() {
387
+ return {
388
+ activeTurnIds: [...this.activeTurnIds],
389
+ accountRateLimits: this.accountRateLimits ? { ...this.accountRateLimits } : null,
390
+ bufferedEvents: [...this.bufferedEvents],
391
+ connectionStatus: this.connectionStatus,
392
+ errors: [...this.errors],
393
+ pendingRequests: [...this.pendingRequests.values()],
394
+ resolvedRequestIds: [...this.resolvedRequestIds],
395
+ thread: this.thread ? cloneThread(this.thread) : null,
396
+ tokenUsage: this.tokenUsage ? {
397
+ ...this.tokenUsage,
398
+ tokenUsage: cloneThreadTokenUsage(this.tokenUsage.tokenUsage)
399
+ } : null,
400
+ turns: this.turns.map(cloneTurn),
401
+ warnings: [...this.warnings]
402
+ };
403
+ }
404
+ noteNotification(notification) {
405
+ this.bufferedEvents = [...this.bufferedEvents, { notification, type: "notification" }];
406
+ switch (notification.method) {
407
+ case "thread/started":
408
+ this.setThread(notification.params.thread);
409
+ return;
410
+ case "thread/status/changed":
411
+ if (this.thread) {
412
+ this.thread = { ...this.thread, status: notification.params.status };
413
+ }
414
+ return;
415
+ case "thread/name/updated":
416
+ if (this.thread) {
417
+ this.thread = { ...this.thread, name: notification.params.threadName ?? null };
418
+ }
419
+ return;
420
+ case "thread/archived":
421
+ case "thread/unarchived":
422
+ case "thread/closed":
423
+ case "thread/goal/updated":
424
+ case "thread/goal/cleared":
425
+ return;
426
+ case "thread/tokenUsage/updated":
427
+ this.tokenUsage = {
428
+ threadId: notification.params.threadId,
429
+ tokenUsage: cloneThreadTokenUsage(notification.params.tokenUsage),
430
+ turnId: notification.params.turnId,
431
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
432
+ };
433
+ return;
434
+ case "turn/started":
435
+ this.upsertTurn(notification.params.turn);
436
+ this.activeTurnIds.add(notification.params.turn.id);
437
+ return;
438
+ case "turn/diff/updated":
439
+ case "turn/plan/updated":
440
+ this.ensureTurn(notification.params.turnId);
441
+ return;
442
+ case "turn/completed":
443
+ this.upsertTurn(notification.params.turn);
444
+ this.activeTurnIds.delete(notification.params.turn.id);
445
+ if (notification.params.turn.error?.message) {
446
+ this.errors = appendUnique(this.errors, notification.params.turn.error.message);
447
+ }
448
+ return;
449
+ case "item/started":
450
+ case "item/completed":
451
+ this.upsertItem(notification.params.turnId, notification.params.item);
452
+ return;
453
+ case "item/agentMessage/delta":
454
+ this.applyAgentMessageDelta(
455
+ notification.params.turnId,
456
+ notification.params.itemId,
457
+ notification.params.delta
458
+ );
459
+ return;
460
+ case "item/plan/delta":
461
+ this.applyPlanDelta(
462
+ notification.params.turnId,
463
+ notification.params.itemId,
464
+ notification.params.delta
465
+ );
466
+ return;
467
+ case "item/reasoning/summaryPartAdded":
468
+ this.applyReasoningSummaryPartAdded(
469
+ notification.params.turnId,
470
+ notification.params.itemId,
471
+ notification.params.summaryIndex
472
+ );
473
+ return;
474
+ case "item/reasoning/summaryTextDelta":
475
+ this.applyReasoningSummaryTextDelta(
476
+ notification.params.turnId,
477
+ notification.params.itemId,
478
+ notification.params.summaryIndex,
479
+ notification.params.delta
480
+ );
481
+ return;
482
+ case "item/reasoning/textDelta":
483
+ this.applyReasoningTextDelta(
484
+ notification.params.turnId,
485
+ notification.params.itemId,
486
+ notification.params.contentIndex,
487
+ notification.params.delta
488
+ );
489
+ return;
490
+ case "item/commandExecution/outputDelta":
491
+ this.applyCommandOutputDelta(
492
+ notification.params.turnId,
493
+ notification.params.itemId,
494
+ notification.params.delta
495
+ );
496
+ return;
497
+ case "item/fileChange/outputDelta":
498
+ this.ensureTurn(notification.params.turnId);
499
+ return;
500
+ case "item/fileChange/patchUpdated":
501
+ this.applyFileChangePatchUpdated(
502
+ notification.params.turnId,
503
+ notification.params.itemId,
504
+ notification.params.changes
505
+ );
506
+ return;
507
+ case "item/mcpToolCall/progress":
508
+ case "item/commandExecution/terminalInteraction":
509
+ case "command/exec/outputDelta":
510
+ case "process/outputDelta":
511
+ case "process/exited":
512
+ case "rawResponseItem/completed":
513
+ case "hook/started":
514
+ case "hook/completed":
515
+ case "item/autoApprovalReview/started":
516
+ case "item/autoApprovalReview/completed":
517
+ return;
518
+ case "thread/compacted":
519
+ this.upsertItem(notification.params.turnId, {
520
+ id: `compacted-${notification.params.turnId}`,
521
+ type: "contextCompaction"
522
+ });
523
+ return;
524
+ case "serverRequest/resolved":
525
+ this.pendingRequests.delete(notification.params.requestId);
526
+ this.resolvedRequestIds = appendUnique(
527
+ this.resolvedRequestIds,
528
+ notification.params.requestId
529
+ );
530
+ return;
531
+ case "warning":
532
+ this.warnings = appendUnique(this.warnings, notification.params.message);
533
+ return;
534
+ case "error":
535
+ this.errors = appendUnique(this.errors, notification.params.error.message);
536
+ return;
537
+ case "guardianWarning":
538
+ this.warnings = appendUnique(this.warnings, notification.params.message);
539
+ return;
540
+ case "deprecationNotice":
541
+ this.warnings = appendUnique(this.warnings, notification.params.summary);
542
+ return;
543
+ case "configWarning":
544
+ this.warnings = appendUnique(this.warnings, notification.params.summary);
545
+ return;
546
+ case "account/rateLimits/updated":
547
+ this.accountRateLimits = { ...notification.params.rateLimits };
548
+ return;
549
+ case "thread/realtime/started":
550
+ case "thread/realtime/itemAdded":
551
+ case "thread/realtime/transcript/delta":
552
+ case "thread/realtime/transcript/done":
553
+ case "thread/realtime/outputAudio/delta":
554
+ case "thread/realtime/sdp":
555
+ case "thread/realtime/error":
556
+ case "thread/realtime/closed":
557
+ case "fs/changed":
558
+ case "model/rerouted":
559
+ case "model/verification":
560
+ case "mcpServer/oauthLogin/completed":
561
+ case "mcpServer/startupStatus/updated":
562
+ case "fuzzyFileSearch/sessionUpdated":
563
+ case "fuzzyFileSearch/sessionCompleted":
564
+ case "windows/worldWritableWarning":
565
+ case "windowsSandbox/setupCompleted":
566
+ return;
567
+ default:
568
+ if (notificationThreadId(notification)) {
569
+ this.warnings = appendUnique(
570
+ this.warnings,
571
+ `Unsupported Codex app-server notification: ${notification.method}`
572
+ );
573
+ }
574
+ return;
575
+ }
576
+ }
577
+ noteRequest(request) {
578
+ this.bufferedEvents = [...this.bufferedEvents, { request, type: "request" }];
579
+ this.pendingRequests.set(request.id, request);
580
+ }
581
+ upsertTurn(turn) {
582
+ const index = this.turns.findIndex((candidate) => candidate.id === turn.id);
583
+ if (index === -1) {
584
+ this.turns = [...this.turns, cloneTurn(turn)];
585
+ return;
586
+ }
587
+ const current = this.turns[index];
588
+ this.turns = replaceAt(this.turns, index, {
589
+ ...current,
590
+ ...turn,
591
+ items: turn.items.length > 0 ? turn.items.map(cloneThreadItem) : current.items
592
+ });
593
+ }
594
+ upsertItem(turnId, item) {
595
+ const turn = this.ensureTurn(turnId);
596
+ const itemIndex = turn.items.findIndex((candidate) => candidate.id === item.id);
597
+ const nextItems = itemIndex === -1 ? [...turn.items, cloneThreadItem(item)] : replaceAt(turn.items, itemIndex, cloneThreadItem(item));
598
+ this.replaceTurn({ ...turn, items: nextItems, itemsView: "full" });
599
+ }
600
+ applyAgentMessageDelta(turnId, itemId, delta) {
601
+ const turn = this.ensureTurn(turnId);
602
+ const item = turn.items.find((candidate) => candidate.id === itemId);
603
+ if (item?.type === "agentMessage") {
604
+ this.upsertItem(turnId, { ...item, text: `${item.text}${delta}` });
605
+ return;
606
+ }
607
+ this.upsertItem(turnId, {
608
+ id: itemId,
609
+ memoryCitation: null,
610
+ phase: "commentary",
611
+ text: delta,
612
+ type: "agentMessage"
613
+ });
614
+ }
615
+ applyPlanDelta(turnId, itemId, delta) {
616
+ const turn = this.ensureTurn(turnId);
617
+ const item = turn.items.find((candidate) => candidate.id === itemId);
618
+ if (item?.type === "plan") {
619
+ this.upsertItem(turnId, { ...item, text: `${item.text}${delta}` });
620
+ return;
621
+ }
622
+ this.upsertItem(turnId, {
623
+ id: itemId,
624
+ text: delta,
625
+ type: "plan"
626
+ });
627
+ }
628
+ applyReasoningSummaryPartAdded(turnId, itemId, summaryIndex) {
629
+ const item = this.reasoningItem(turnId, itemId);
630
+ const summary = replaceAtOrAppend(item.summary, summaryIndex, "");
631
+ this.upsertItem(turnId, { ...item, summary });
632
+ }
633
+ applyReasoningSummaryTextDelta(turnId, itemId, summaryIndex, delta) {
634
+ const item = this.reasoningItem(turnId, itemId);
635
+ const current = item.summary[summaryIndex] ?? "";
636
+ const summary = replaceAtOrAppend(item.summary, summaryIndex, `${current}${delta}`);
637
+ this.upsertItem(turnId, { ...item, summary });
638
+ }
639
+ applyReasoningTextDelta(turnId, itemId, contentIndex, delta) {
640
+ const item = this.reasoningItem(turnId, itemId);
641
+ const current = item.content[contentIndex] ?? "";
642
+ const content = replaceAtOrAppend(item.content, contentIndex, `${current}${delta}`);
643
+ this.upsertItem(turnId, { ...item, content });
644
+ }
645
+ applyCommandOutputDelta(turnId, itemId, delta) {
646
+ const turn = this.ensureTurn(turnId);
647
+ const item = turn.items.find((candidate) => candidate.id === itemId);
648
+ if (item?.type !== "commandExecution") {
649
+ return;
650
+ }
651
+ this.upsertItem(turnId, {
652
+ ...item,
653
+ aggregatedOutput: `${item.aggregatedOutput ?? ""}${delta}`
654
+ });
655
+ }
656
+ applyFileChangePatchUpdated(turnId, itemId, changes) {
657
+ const turn = this.ensureTurn(turnId);
658
+ const item = turn.items.find((candidate) => candidate.id === itemId);
659
+ if (item?.type !== "fileChange") {
660
+ return;
661
+ }
662
+ this.upsertItem(turnId, { ...item, changes });
663
+ }
664
+ reasoningItem(turnId, itemId) {
665
+ const turn = this.ensureTurn(turnId);
666
+ const item = turn.items.find((candidate) => candidate.id === itemId);
667
+ if (item?.type === "reasoning") {
668
+ return item;
669
+ }
670
+ return {
671
+ content: [],
672
+ id: itemId,
673
+ summary: [],
674
+ type: "reasoning"
675
+ };
676
+ }
677
+ ensureTurn(turnId) {
678
+ const existing = this.turns.find((turn2) => turn2.id === turnId);
679
+ if (existing) {
680
+ return existing;
681
+ }
682
+ const turn = {
683
+ completedAt: null,
684
+ durationMs: null,
685
+ error: null,
686
+ id: turnId,
687
+ items: [],
688
+ itemsView: "full",
689
+ startedAt: null,
690
+ status: "inProgress"
691
+ };
692
+ this.turns = [...this.turns, turn];
693
+ this.activeTurnIds.add(turnId);
694
+ return turn;
695
+ }
696
+ replaceTurn(turn) {
697
+ const index = this.turns.findIndex((candidate) => candidate.id === turn.id);
698
+ this.turns = index === -1 ? [...this.turns, turn] : replaceAt(this.turns, index, turn);
699
+ }
700
+ };
701
+ function applyServerNotificationToThreadEventStore(store, notification) {
702
+ store.noteNotification(notification);
703
+ return store.snapshot();
704
+ }
705
+ function applyServerRequestToThreadEventStore(store, request) {
706
+ store.noteRequest(request);
707
+ return store.snapshot();
708
+ }
709
+ function serverRequestThreadId(request) {
710
+ if ("params" in request && request.params && typeof request.params === "object") {
711
+ const threadId = request.params.threadId;
712
+ return typeof threadId === "string" ? threadId : null;
713
+ }
714
+ return null;
715
+ }
716
+ function serverNotificationThreadTarget(notification) {
717
+ const threadId = notificationThreadId(notification);
718
+ if (!threadId) {
719
+ return { type: "global" };
720
+ }
721
+ return isUuidLike(threadId) ? { threadId, type: "thread" } : { threadId, type: "invalid_thread_id" };
722
+ }
723
+ function threadEventSnapshotHasStarted(snapshot) {
724
+ if (!snapshot) {
725
+ return false;
726
+ }
727
+ return snapshot.turns.some((turn) => turn.items.length > 0) || snapshot.activeTurnIds.length > 0 || snapshot.pendingRequests.length > 0 || snapshot.warnings.length > 0 || snapshot.errors.length > 0;
728
+ }
729
+ function notificationThreadId(notification) {
730
+ if (notification.method === "thread/started") {
731
+ return notification.params.thread.id;
732
+ }
733
+ if ("params" in notification && notification.params && typeof notification.params === "object") {
734
+ const threadId = notification.params.threadId;
735
+ return typeof threadId === "string" ? threadId : null;
736
+ }
737
+ return null;
738
+ }
739
+ function cloneThread(thread) {
740
+ return {
741
+ ...thread,
742
+ turns: thread.turns.map(cloneTurn)
743
+ };
744
+ }
745
+ function cloneTurn(turn) {
746
+ return {
747
+ ...turn,
748
+ items: turn.items.map(cloneThreadItem)
749
+ };
750
+ }
751
+ function cloneThreadItem(item) {
752
+ return { ...item };
753
+ }
754
+ function cloneThreadTokenUsage(tokenUsage) {
755
+ return {
756
+ last: { ...tokenUsage.last },
757
+ modelContextWindow: tokenUsage.modelContextWindow,
758
+ total: { ...tokenUsage.total }
759
+ };
760
+ }
761
+ function replaceAt(items, index, item) {
762
+ return [...items.slice(0, index), item, ...items.slice(index + 1)];
763
+ }
764
+ function replaceAtOrAppend(items, index, item) {
765
+ if (index < items.length) {
766
+ return replaceAt(items, index, item);
767
+ }
768
+ return [...items, item];
769
+ }
770
+ function appendUnique(items, item) {
771
+ return items.includes(item) ? [...items] : [...items, item];
772
+ }
773
+ function isUuidLike(value) {
774
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu.test(value);
775
+ }
776
+
777
+ // src/upstream/codex-rs/app-server-client/src/lib.ts
778
+ async function requestTyped(request, send) {
779
+ try {
780
+ return await send(request);
781
+ } catch (source) {
782
+ if (isJsonRpcError(source)) {
783
+ throw {
784
+ method: request.method,
785
+ source,
786
+ type: "server"
787
+ };
788
+ }
789
+ throw {
790
+ method: request.method,
791
+ source,
792
+ type: "transport"
793
+ };
794
+ }
795
+ }
796
+ function serverNotificationRequiresDelivery(notification) {
797
+ return notification.method === "turn/completed" || notification.method === "item/completed" || notification.method === "item/agentMessage/delta" || notification.method === "item/plan/delta" || notification.method === "item/reasoning/summaryTextDelta" || notification.method === "item/reasoning/textDelta";
798
+ }
799
+ function requestMethodName(request) {
800
+ return request.method;
801
+ }
802
+ function isJsonRpcError(value) {
803
+ return typeof value === "object" && value !== null && typeof value.code === "number" && typeof value.message === "string";
804
+ }
805
+
806
+ // src/upstream/codex-rs/app-server-client/src/remote.ts
807
+ var CodexAppServerClientTransportError = class extends Error {
808
+ constructor(message, status, body) {
809
+ super(message);
810
+ this.status = status;
811
+ this.body = body;
812
+ this.name = "CodexAppServerClientTransportError";
813
+ }
814
+ status;
815
+ body;
816
+ };
817
+ function createCodexAppServerClient(options) {
818
+ let socket = null;
819
+ let openPromise = null;
820
+ let initializePromise = null;
821
+ let initialized = false;
822
+ const pendingRequests = /* @__PURE__ */ new Map();
823
+ const eventQueue = createEventQueue();
824
+ async function ensureOpenSocket() {
825
+ const openState = 1;
826
+ if (socket?.readyState === openState) {
827
+ return socket;
828
+ }
829
+ openPromise ??= openSocket();
830
+ return openPromise;
831
+ }
832
+ async function ensureInitialized() {
833
+ if (initialized) {
834
+ return;
835
+ }
836
+ initializePromise ??= sendClientRequest({
837
+ id: 0,
838
+ method: "initialize",
839
+ params: await resolveInitializeParams(options.initializeParams)
840
+ });
841
+ await initializePromise;
842
+ initialized = true;
843
+ }
844
+ async function request(request2) {
845
+ if (request2.method !== "initialize") {
846
+ await ensureInitialized();
847
+ return sendClientRequest(request2);
848
+ }
849
+ const result = await sendClientRequest(request2);
850
+ initialized = true;
851
+ return result;
852
+ }
853
+ async function sendClientRequest(request2) {
854
+ const websocket = await ensureOpenSocket();
855
+ return new Promise((resolve, reject) => {
856
+ pendingRequests.set(request2.id, { reject, resolve });
857
+ try {
858
+ websocket.send(JSON.stringify(request2));
859
+ } catch (error) {
860
+ pendingRequests.delete(request2.id);
861
+ reject(error);
862
+ }
863
+ });
864
+ }
865
+ async function sendClientResponse(requestId, result) {
866
+ const websocket = await ensureOpenSocket();
867
+ websocket.send(serializeJsonRpcResponse(requestId, result));
868
+ }
869
+ async function sendClientError(requestId, error) {
870
+ const websocket = await ensureOpenSocket();
871
+ websocket.send(serializeJsonRpcError(requestId, error));
872
+ }
873
+ async function openSocket() {
874
+ options.onConnectionStatus?.("connecting");
875
+ eventQueue.reopen();
876
+ const WebSocketCtor = options.WebSocket ?? WebSocket;
877
+ const websocketUrl = await resolveUrl(options.url);
878
+ return new Promise((resolve, reject) => {
879
+ let settled = false;
880
+ const nextSocket = new WebSocketCtor(websocketUrl);
881
+ socket = nextSocket;
882
+ nextSocket.addEventListener("open", () => {
883
+ settled = true;
884
+ options.onConnectionStatus?.("connected");
885
+ resolve(nextSocket);
886
+ });
887
+ nextSocket.addEventListener("message", (message) => {
888
+ handleSocketMessage(message.data);
889
+ });
890
+ nextSocket.addEventListener("close", () => {
891
+ const error = new CodexAppServerClientTransportError(
892
+ "Codex app-server WebSocket closed."
893
+ );
894
+ closeSocketState(error);
895
+ eventQueue.push({ message: "closed", type: "disconnected" });
896
+ eventQueue.close();
897
+ options.onConnectionStatus?.("closed");
898
+ if (!settled) {
899
+ reject(error);
900
+ }
901
+ });
902
+ nextSocket.addEventListener("error", () => {
903
+ const error = new CodexAppServerClientTransportError(
904
+ "Codex app-server WebSocket failed."
905
+ );
906
+ closeSocketState(error);
907
+ eventQueue.fail(error);
908
+ options.onConnectionStatus?.("error");
909
+ if (!settled) {
910
+ reject(error);
911
+ }
912
+ });
913
+ });
914
+ }
915
+ function handleSocketMessage(value) {
916
+ const parsed = parseClientTransportPayload(value);
917
+ if (parsed.type === "invalid") {
918
+ const event = options.parseEvent?.(value);
919
+ if (event) {
920
+ eventQueue.push(event);
921
+ }
922
+ return;
923
+ }
924
+ const message = parsed.message;
925
+ switch (message.type) {
926
+ case "response": {
927
+ const pending = pendingRequests.get(message.response.id);
928
+ if (!pending) {
929
+ return;
930
+ }
931
+ pendingRequests.delete(message.response.id);
932
+ pending.resolve(message.response.result);
933
+ return;
934
+ }
935
+ case "error": {
936
+ if (message.error.id === null) {
937
+ eventQueue.fail(message.error.error);
938
+ return;
939
+ }
940
+ const pending = pendingRequests.get(message.error.id);
941
+ if (!pending) {
942
+ return;
943
+ }
944
+ pendingRequests.delete(message.error.id);
945
+ pending.reject(message.error.error);
946
+ return;
947
+ }
948
+ case "server_notification":
949
+ eventQueue.push({
950
+ notification: message.notification,
951
+ type: "server_notification"
952
+ });
953
+ return;
954
+ case "server_request":
955
+ eventQueue.push({ request: message.request, type: "server_request" });
956
+ return;
957
+ }
958
+ }
959
+ function closeSocketState(error) {
960
+ socket = null;
961
+ openPromise = null;
962
+ initializePromise = null;
963
+ initialized = false;
964
+ for (const pending of pendingRequests.values()) {
965
+ pending.reject(error);
966
+ }
967
+ pendingRequests.clear();
968
+ }
969
+ function close() {
970
+ const currentSocket = socket;
971
+ closeSocketState(
972
+ new CodexAppServerClientTransportError(
973
+ "Codex app-server WebSocket closed."
974
+ )
975
+ );
976
+ eventQueue.close();
977
+ if (currentSocket && currentSocket.readyState !== 3) {
978
+ currentSocket.close();
979
+ }
980
+ }
981
+ return {
982
+ close,
983
+ events() {
984
+ void ensureInitialized().catch((error) => eventQueue.fail(error));
985
+ return eventQueue.iterable();
986
+ },
987
+ request,
988
+ requestTyped(clientRequest) {
989
+ return requestTyped(clientRequest, request);
990
+ },
991
+ rejectServerRequest(requestId, error) {
992
+ return sendClientError(requestId, error);
993
+ },
994
+ resolveServerRequest(requestId, result) {
995
+ return sendClientResponse(requestId, result);
996
+ }
997
+ };
998
+ }
999
+ function parseCodexAppServerEvent(value) {
1000
+ const parsed = parseClientTransportPayload(value);
1001
+ if (parsed.type === "ok") {
1002
+ switch (parsed.message.type) {
1003
+ case "server_notification":
1004
+ return {
1005
+ notification: parsed.message.notification,
1006
+ type: "server_notification"
1007
+ };
1008
+ case "server_request":
1009
+ return { request: parsed.message.request, type: "server_request" };
1010
+ case "error":
1011
+ case "response":
1012
+ return null;
1013
+ }
1014
+ }
1015
+ if (typeof value !== "string") {
1016
+ return appServerEventFromParsed(value);
1017
+ }
1018
+ try {
1019
+ return appServerEventFromParsed(JSON.parse(value));
1020
+ } catch {
1021
+ return null;
1022
+ }
1023
+ }
1024
+ async function resolveInitializeParams(params) {
1025
+ if (typeof params === "function") {
1026
+ return params();
1027
+ }
1028
+ return params ?? defaultInitializeParams2();
1029
+ }
1030
+ async function resolveUrl(url) {
1031
+ return typeof url === "function" ? await url() : url;
1032
+ }
1033
+ function defaultInitializeParams2() {
1034
+ return {
1035
+ capabilities: {
1036
+ experimentalApi: false,
1037
+ optOutNotificationMethods: []
1038
+ },
1039
+ clientInfo: {
1040
+ name: "codex-js",
1041
+ title: null,
1042
+ version: "0.0.0"
1043
+ }
1044
+ };
1045
+ }
1046
+ function appServerEventFromParsed(value) {
1047
+ if (isObject(value) && typeof value.type === "string") {
1048
+ if (value.type === "server_notification" || value.type === "server_request" || value.type === "lagged" || value.type === "disconnected") {
1049
+ return value;
1050
+ }
1051
+ }
1052
+ if (isObject(value) && typeof value.method === "string" && "params" in value) {
1053
+ if ("id" in value) {
1054
+ return { request: value, type: "server_request" };
1055
+ }
1056
+ return {
1057
+ notification: value,
1058
+ type: "server_notification"
1059
+ };
1060
+ }
1061
+ return null;
1062
+ }
1063
+ function isObject(value) {
1064
+ return typeof value === "object" && value !== null;
1065
+ }
1066
+ function createEventQueue() {
1067
+ const values = [];
1068
+ const waiters = [];
1069
+ let closed = false;
1070
+ let failure = null;
1071
+ return {
1072
+ close() {
1073
+ closed = true;
1074
+ for (const waiter of waiters.splice(0)) {
1075
+ waiter.settled = true;
1076
+ waiter.resolve({ done: true, value: void 0 });
1077
+ }
1078
+ },
1079
+ fail(error) {
1080
+ failure = error;
1081
+ for (const waiter of waiters.splice(0)) {
1082
+ waiter.settled = true;
1083
+ waiter.reject(error);
1084
+ }
1085
+ },
1086
+ push(value) {
1087
+ while (waiters.length > 0) {
1088
+ const waiter = waiters.shift();
1089
+ if (waiter.settled) {
1090
+ continue;
1091
+ }
1092
+ waiter.settled = true;
1093
+ waiter.resolve({ done: false, value });
1094
+ return;
1095
+ }
1096
+ values.push(value);
1097
+ },
1098
+ reopen() {
1099
+ values.splice(0);
1100
+ closed = false;
1101
+ failure = null;
1102
+ },
1103
+ iterable(options = {}) {
1104
+ return {
1105
+ [Symbol.asyncIterator]() {
1106
+ let active = true;
1107
+ let pendingWaiter = null;
1108
+ return {
1109
+ next() {
1110
+ if (!active) {
1111
+ return Promise.resolve({ done: true, value: void 0 });
1112
+ }
1113
+ if (failure) {
1114
+ return Promise.reject(failure);
1115
+ }
1116
+ if (values.length > 0) {
1117
+ return Promise.resolve({
1118
+ done: false,
1119
+ value: values.shift()
1120
+ });
1121
+ }
1122
+ if (closed) {
1123
+ return Promise.resolve({ done: true, value: void 0 });
1124
+ }
1125
+ return new Promise((resolve, reject) => {
1126
+ const waiter = { reject, resolve, settled: false };
1127
+ pendingWaiter = waiter;
1128
+ waiters.push(waiter);
1129
+ });
1130
+ },
1131
+ return() {
1132
+ options.onReturn?.();
1133
+ active = false;
1134
+ if (pendingWaiter && !pendingWaiter.settled) {
1135
+ pendingWaiter.settled = true;
1136
+ const index = waiters.indexOf(pendingWaiter);
1137
+ if (index !== -1) {
1138
+ waiters.splice(index, 1);
1139
+ }
1140
+ pendingWaiter.resolve({ done: true, value: void 0 });
1141
+ }
1142
+ return Promise.resolve({ done: true, value: void 0 });
1143
+ }
1144
+ };
1145
+ }
1146
+ };
1147
+ }
1148
+ };
1149
+ }
1150
+
1151
+ export { AppServerSession, CodexAppServerClientTransportError, PendingAppServerRequests, ThreadEventStore, createCodexAppServerClient, parseCodexAppServerEvent, requestMethodName, requestTyped, serverNotificationRequiresDelivery, serverNotificationThreadTarget, serverRequestThreadId, threadEventSnapshotHasStarted };
1152
+ //# sourceMappingURL=chunk-6ZMJ34KE.js.map
1153
+ //# sourceMappingURL=chunk-6ZMJ34KE.js.map