@kodelyth/codex 2026.5.42 → 2026.6.1

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 (138) hide show
  1. package/package.json +16 -1
  2. package/doctor-contract-api.test.ts +0 -44
  3. package/doctor-contract-api.ts +0 -68
  4. package/harness.ts +0 -72
  5. package/index.test.ts +0 -230
  6. package/index.ts +0 -66
  7. package/media-understanding-provider.test.ts +0 -486
  8. package/media-understanding-provider.ts +0 -521
  9. package/prompt-overlay-runtime-contract.test.ts +0 -48
  10. package/prompt-overlay.ts +0 -21
  11. package/provider-catalog.ts +0 -83
  12. package/provider-discovery.ts +0 -45
  13. package/provider.test.ts +0 -384
  14. package/provider.ts +0 -243
  15. package/src/app-server/app-inventory-cache.test.ts +0 -176
  16. package/src/app-server/app-inventory-cache.ts +0 -324
  17. package/src/app-server/approval-bridge.test.ts +0 -1471
  18. package/src/app-server/approval-bridge.ts +0 -1211
  19. package/src/app-server/auth-bridge.test.ts +0 -1449
  20. package/src/app-server/auth-bridge.ts +0 -614
  21. package/src/app-server/auth-profile-runtime-contract.test.ts +0 -239
  22. package/src/app-server/capabilities.ts +0 -27
  23. package/src/app-server/client-factory.ts +0 -24
  24. package/src/app-server/client.test.ts +0 -563
  25. package/src/app-server/client.ts +0 -715
  26. package/src/app-server/compact.test.ts +0 -710
  27. package/src/app-server/compact.ts +0 -500
  28. package/src/app-server/computer-use.test.ts +0 -788
  29. package/src/app-server/computer-use.ts +0 -683
  30. package/src/app-server/config.test.ts +0 -879
  31. package/src/app-server/config.ts +0 -1038
  32. package/src/app-server/context-engine-projection.test.ts +0 -252
  33. package/src/app-server/context-engine-projection.ts +0 -403
  34. package/src/app-server/delivery-no-reply-runtime-contract.test.ts +0 -80
  35. package/src/app-server/dynamic-tool-diagnostics.ts +0 -73
  36. package/src/app-server/dynamic-tool-profile.ts +0 -69
  37. package/src/app-server/dynamic-tools.test.ts +0 -1302
  38. package/src/app-server/dynamic-tools.ts +0 -623
  39. package/src/app-server/elicitation-bridge.test.ts +0 -1056
  40. package/src/app-server/elicitation-bridge.ts +0 -783
  41. package/src/app-server/event-projector.test.ts +0 -2668
  42. package/src/app-server/event-projector.ts +0 -2057
  43. package/src/app-server/image-payload-sanitizer.test.ts +0 -49
  44. package/src/app-server/image-payload-sanitizer.ts +0 -167
  45. package/src/app-server/klaw-owned-tool-runtime-contract.test.ts +0 -456
  46. package/src/app-server/local-runtime-attribution.ts +0 -39
  47. package/src/app-server/managed-binary.test.ts +0 -139
  48. package/src/app-server/managed-binary.ts +0 -193
  49. package/src/app-server/models.test.ts +0 -246
  50. package/src/app-server/models.ts +0 -172
  51. package/src/app-server/native-hook-relay.test.ts +0 -271
  52. package/src/app-server/native-hook-relay.ts +0 -150
  53. package/src/app-server/native-subagent-task-mirror.test.ts +0 -573
  54. package/src/app-server/native-subagent-task-mirror.ts +0 -497
  55. package/src/app-server/outcome-fallback-runtime-contract.test.ts +0 -404
  56. package/src/app-server/plugin-activation.test.ts +0 -336
  57. package/src/app-server/plugin-activation.ts +0 -283
  58. package/src/app-server/plugin-app-cache-key.ts +0 -74
  59. package/src/app-server/plugin-approval-roundtrip.ts +0 -122
  60. package/src/app-server/plugin-inventory.test.ts +0 -355
  61. package/src/app-server/plugin-inventory.ts +0 -357
  62. package/src/app-server/plugin-thread-config.test.ts +0 -865
  63. package/src/app-server/plugin-thread-config.ts +0 -455
  64. package/src/app-server/protocol-generated/json/DynamicToolCallParams.json +0 -33
  65. package/src/app-server/protocol-generated/json/v2/ErrorNotification.json +0 -199
  66. package/src/app-server/protocol-generated/json/v2/GetAccountResponse.json +0 -102
  67. package/src/app-server/protocol-generated/json/v2/ModelListResponse.json +0 -227
  68. package/src/app-server/protocol-generated/json/v2/ThreadResumeResponse.json +0 -2630
  69. package/src/app-server/protocol-generated/json/v2/ThreadStartResponse.json +0 -2630
  70. package/src/app-server/protocol-generated/json/v2/TurnCompletedNotification.json +0 -1659
  71. package/src/app-server/protocol-generated/json/v2/TurnStartResponse.json +0 -1655
  72. package/src/app-server/protocol-validators.test.ts +0 -75
  73. package/src/app-server/protocol-validators.ts +0 -203
  74. package/src/app-server/protocol.ts +0 -520
  75. package/src/app-server/rate-limit-cache.ts +0 -48
  76. package/src/app-server/rate-limits.test.ts +0 -202
  77. package/src/app-server/rate-limits.ts +0 -583
  78. package/src/app-server/request.ts +0 -73
  79. package/src/app-server/run-attempt.context-engine.test.ts +0 -1004
  80. package/src/app-server/run-attempt.test.ts +0 -9477
  81. package/src/app-server/run-attempt.ts +0 -4683
  82. package/src/app-server/run-attempt.vision-tools.test.ts +0 -35
  83. package/src/app-server/schema-normalization-runtime-contract.test.ts +0 -206
  84. package/src/app-server/session-binding.test.ts +0 -303
  85. package/src/app-server/session-binding.ts +0 -398
  86. package/src/app-server/session-history.ts +0 -44
  87. package/src/app-server/shared-client.test.ts +0 -589
  88. package/src/app-server/shared-client.ts +0 -289
  89. package/src/app-server/side-question.test.ts +0 -1175
  90. package/src/app-server/side-question.ts +0 -1007
  91. package/src/app-server/test-support.ts +0 -48
  92. package/src/app-server/thread-lifecycle.test.ts +0 -447
  93. package/src/app-server/thread-lifecycle.ts +0 -939
  94. package/src/app-server/thread-lifecycle.user-mcp-servers.test.ts +0 -442
  95. package/src/app-server/timeout.ts +0 -9
  96. package/src/app-server/tool-progress-normalization.ts +0 -77
  97. package/src/app-server/trajectory.test.ts +0 -205
  98. package/src/app-server/trajectory.ts +0 -365
  99. package/src/app-server/transcript-mirror.test.ts +0 -524
  100. package/src/app-server/transcript-mirror.ts +0 -208
  101. package/src/app-server/transcript-repair-runtime-contract.test.ts +0 -44
  102. package/src/app-server/transport-stdio.test.ts +0 -171
  103. package/src/app-server/transport-stdio.ts +0 -107
  104. package/src/app-server/transport-websocket.test.ts +0 -69
  105. package/src/app-server/transport-websocket.ts +0 -90
  106. package/src/app-server/transport.ts +0 -117
  107. package/src/app-server/user-input-bridge.test.ts +0 -249
  108. package/src/app-server/user-input-bridge.ts +0 -316
  109. package/src/app-server/version.ts +0 -4
  110. package/src/app-server/vision-tools.ts +0 -12
  111. package/src/command-account.ts +0 -544
  112. package/src/command-formatters.ts +0 -425
  113. package/src/command-handlers.ts +0 -2004
  114. package/src/command-rpc.test.ts +0 -16
  115. package/src/command-rpc.ts +0 -142
  116. package/src/commands.test.ts +0 -3312
  117. package/src/commands.ts +0 -65
  118. package/src/conversation-binding-data.ts +0 -124
  119. package/src/conversation-binding.test.ts +0 -599
  120. package/src/conversation-binding.ts +0 -561
  121. package/src/conversation-control.test.ts +0 -126
  122. package/src/conversation-control.ts +0 -303
  123. package/src/conversation-turn-collector.test.ts +0 -191
  124. package/src/conversation-turn-collector.ts +0 -186
  125. package/src/conversation-turn-input.test.ts +0 -141
  126. package/src/conversation-turn-input.ts +0 -106
  127. package/src/manifest.test.ts +0 -20
  128. package/src/migration/apply.ts +0 -501
  129. package/src/migration/helpers.ts +0 -55
  130. package/src/migration/plan.ts +0 -461
  131. package/src/migration/provider.test.ts +0 -1741
  132. package/src/migration/provider.ts +0 -41
  133. package/src/migration/source.ts +0 -643
  134. package/src/migration/targets.ts +0 -25
  135. package/src/node-cli-sessions.test.ts +0 -180
  136. package/src/node-cli-sessions.ts +0 -711
  137. package/test-api.ts +0 -82
  138. package/tsconfig.json +0 -16
@@ -1,117 +0,0 @@
1
- export type CodexAppServerTransport = {
2
- stdin: {
3
- write: (data: string, callback?: (error?: Error | null) => void) => unknown;
4
- end?: () => unknown;
5
- destroy?: () => unknown;
6
- unref?: () => unknown;
7
- on?: (event: "error", listener: (error: Error) => void) => unknown;
8
- };
9
- stdout: NodeJS.ReadableStream & {
10
- destroy?: () => unknown;
11
- unref?: () => unknown;
12
- };
13
- stderr: NodeJS.ReadableStream & {
14
- destroy?: () => unknown;
15
- unref?: () => unknown;
16
- };
17
- pid?: number;
18
- exitCode?: number | null;
19
- signalCode?: string | null;
20
- killed?: boolean;
21
- kill?: (signal?: NodeJS.Signals) => unknown;
22
- unref?: () => unknown;
23
- once: (event: string, listener: (...args: unknown[]) => void) => unknown;
24
- off?: (event: string, listener: (...args: unknown[]) => void) => unknown;
25
- };
26
-
27
- export function closeCodexAppServerTransport(
28
- child: CodexAppServerTransport,
29
- options: { forceKillDelayMs?: number } = {},
30
- ): void {
31
- child.stdin.end?.();
32
- child.stdin.destroy?.();
33
- const forceKillDelayMs = options.forceKillDelayMs ?? 1_000;
34
- const forceKill = setTimeout(
35
- () => {
36
- if (hasCodexAppServerTransportExited(child)) {
37
- return;
38
- }
39
- signalCodexAppServerTransport(child, "SIGKILL");
40
- },
41
- Math.max(1, forceKillDelayMs),
42
- );
43
- forceKill.unref?.();
44
- child.once("exit", () => {
45
- clearTimeout(forceKill);
46
- child.stdout.destroy?.();
47
- child.stderr.destroy?.();
48
- });
49
- child.unref?.();
50
- child.stdout.unref?.();
51
- child.stderr.unref?.();
52
- child.stdin.unref?.();
53
- }
54
-
55
- export async function closeCodexAppServerTransportAndWait(
56
- child: CodexAppServerTransport,
57
- options: { exitTimeoutMs?: number; forceKillDelayMs?: number } = {},
58
- ): Promise<boolean> {
59
- if (!hasCodexAppServerTransportExited(child)) {
60
- closeCodexAppServerTransport(child, options);
61
- }
62
- return await waitForCodexAppServerTransportExit(child, options.exitTimeoutMs ?? 2_000);
63
- }
64
-
65
- function hasCodexAppServerTransportExited(child: CodexAppServerTransport): boolean {
66
- return child.exitCode !== null && child.exitCode !== undefined
67
- ? true
68
- : child.signalCode !== null && child.signalCode !== undefined;
69
- }
70
-
71
- async function waitForCodexAppServerTransportExit(
72
- child: CodexAppServerTransport,
73
- timeoutMs: number,
74
- ): Promise<boolean> {
75
- if (hasCodexAppServerTransportExited(child)) {
76
- return true;
77
- }
78
- return await new Promise<boolean>((resolve) => {
79
- let settled = false;
80
- const onExit = () => {
81
- if (settled) {
82
- return;
83
- }
84
- settled = true;
85
- clearTimeout(timeout);
86
- resolve(true);
87
- };
88
- const timeout = setTimeout(
89
- () => {
90
- if (settled) {
91
- return;
92
- }
93
- settled = true;
94
- child.off?.("exit", onExit);
95
- resolve(false);
96
- },
97
- Math.max(1, timeoutMs),
98
- );
99
- child.once("exit", onExit);
100
- });
101
- }
102
-
103
- function signalCodexAppServerTransport(
104
- child: CodexAppServerTransport,
105
- signal: NodeJS.Signals,
106
- ): void {
107
- if (child.pid && process.platform !== "win32") {
108
- try {
109
- process.kill(-child.pid, signal);
110
- return;
111
- } catch {
112
- // Fall back to the child handle. The process may already be gone or not
113
- // be a process-group leader on older call sites.
114
- }
115
- }
116
- child.kill?.(signal);
117
- }
@@ -1,249 +0,0 @@
1
- import type { EmbeddedRunAttemptParams } from "klaw/plugin-sdk/agent-harness-runtime";
2
- import { describe, expect, it, vi } from "vitest";
3
- import { createCodexUserInputBridge } from "./user-input-bridge.js";
4
-
5
- function createParams(): EmbeddedRunAttemptParams {
6
- return {
7
- sessionId: "session-1",
8
- sessionKey: "agent:main:session-1",
9
- onBlockReply: vi.fn(),
10
- } as unknown as EmbeddedRunAttemptParams;
11
- }
12
-
13
- function expectFirstBlockReplyText(params: EmbeddedRunAttemptParams): string {
14
- const onBlockReply = params.onBlockReply;
15
- if (onBlockReply === undefined) {
16
- throw new Error("Expected onBlockReply callback");
17
- }
18
- const payload = vi.mocked(onBlockReply).mock.calls[0]?.[0];
19
- if (typeof payload?.text !== "string") {
20
- throw new Error("Expected first block reply text");
21
- }
22
- return payload.text;
23
- }
24
-
25
- describe("Codex app-server user input bridge", () => {
26
- it("prompts the originating chat and resolves request_user_input from the next queued message", async () => {
27
- const params = createParams();
28
- const bridge = createCodexUserInputBridge({
29
- paramsForRun: params,
30
- threadId: "thread-1",
31
- turnId: "turn-1",
32
- });
33
-
34
- const response = bridge.handleRequest({
35
- id: "input-1",
36
- params: {
37
- threadId: "thread-1",
38
- turnId: "turn-1",
39
- itemId: "tool-1",
40
- questions: [
41
- {
42
- id: "choice",
43
- header: "Mode",
44
- question: "Pick a mode",
45
- isOther: false,
46
- isSecret: false,
47
- options: [
48
- { label: "Fast", description: "Use less reasoning" },
49
- { label: "Deep", description: "Use more reasoning" },
50
- ],
51
- },
52
- ],
53
- },
54
- });
55
-
56
- await vi.waitFor(() => expect(params.onBlockReply).toHaveBeenCalledTimes(1));
57
- expect(expectFirstBlockReplyText(params)).toContain("Pick a mode");
58
- expect(bridge.handleQueuedMessage("2")).toBe(true);
59
-
60
- await expect(response).resolves.toEqual({
61
- answers: { choice: { answers: ["Deep"] } },
62
- });
63
- });
64
-
65
- it("maps keyed multi-question replies to Codex answer ids", async () => {
66
- const params = createParams();
67
- const bridge = createCodexUserInputBridge({
68
- paramsForRun: params,
69
- threadId: "thread-1",
70
- turnId: "turn-1",
71
- });
72
-
73
- const response = bridge.handleRequest({
74
- id: "input-2",
75
- params: {
76
- threadId: "thread-1",
77
- turnId: "turn-1",
78
- itemId: "tool-1",
79
- questions: [
80
- {
81
- id: "repo",
82
- header: "Repository",
83
- question: "Which repo?",
84
- isOther: true,
85
- isSecret: false,
86
- options: null,
87
- },
88
- {
89
- id: "scope",
90
- header: "Scope",
91
- question: "Which scope?",
92
- isOther: false,
93
- isSecret: false,
94
- options: [{ label: "Tests", description: "Only tests" }],
95
- },
96
- ],
97
- },
98
- });
99
-
100
- await vi.waitFor(() => expect(params.onBlockReply).toHaveBeenCalledTimes(1));
101
- expect(bridge.handleQueuedMessage("repo: klaw\nscope: Tests")).toBe(true);
102
-
103
- await expect(response).resolves.toEqual({
104
- answers: {
105
- repo: { answers: ["klaw"] },
106
- scope: { answers: ["Tests"] },
107
- },
108
- });
109
- });
110
-
111
- it("rejects free-form option replies when Other is disabled", async () => {
112
- const params = createParams();
113
- const bridge = createCodexUserInputBridge({
114
- paramsForRun: params,
115
- threadId: "thread-1",
116
- turnId: "turn-1",
117
- });
118
-
119
- const response = bridge.handleRequest({
120
- id: "input-options",
121
- params: {
122
- threadId: "thread-1",
123
- turnId: "turn-1",
124
- itemId: "tool-1",
125
- questions: [
126
- {
127
- id: "mode",
128
- header: "Mode",
129
- question: "Pick a mode",
130
- isOther: false,
131
- isSecret: false,
132
- options: [{ label: "Fast", description: "Use less reasoning" }],
133
- },
134
- ],
135
- },
136
- });
137
-
138
- await vi.waitFor(() => expect(params.onBlockReply).toHaveBeenCalledTimes(1));
139
- expect(bridge.handleQueuedMessage("banana")).toBe(true);
140
-
141
- await expect(response).resolves.toEqual({
142
- answers: { mode: { answers: [] } },
143
- });
144
- });
145
-
146
- it("escapes prompt question and option text before chat display", async () => {
147
- const params = createParams();
148
- const bridge = createCodexUserInputBridge({
149
- paramsForRun: params,
150
- threadId: "thread-1",
151
- turnId: "turn-1",
152
- });
153
-
154
- const response = bridge.handleRequest({
155
- id: "input-escaped",
156
- params: {
157
- threadId: "thread-1",
158
- turnId: "turn-1",
159
- itemId: "tool-1",
160
- questions: [
161
- {
162
- id: "mode",
163
- header: "Mode <@U123>",
164
- question: "Pick [trusted](https://evil) @here",
165
- isOther: false,
166
- isSecret: false,
167
- options: [{ label: "Fast <@U123>", description: "Use [less](https://evil)" }],
168
- },
169
- ],
170
- },
171
- });
172
-
173
- await vi.waitFor(() => expect(params.onBlockReply).toHaveBeenCalledTimes(1));
174
- const text = expectFirstBlockReplyText(params);
175
- expect(text).toContain("Mode &lt;\uff20U123&gt;");
176
- expect(text).toContain("Pick \uff3btrusted\uff3d\uff08https://evil\uff09 \uff20here");
177
- expect(text).toContain(
178
- "Fast &lt;\uff20U123&gt; - Use \uff3bless\uff3d\uff08https://evil\uff09",
179
- );
180
- expect(text).not.toContain("<@U123>");
181
- expect(text).not.toContain("[trusted](https://evil)");
182
- expect(text).not.toContain("@here");
183
-
184
- expect(bridge.handleQueuedMessage("1")).toBe(true);
185
- await expect(response).resolves.toEqual({
186
- answers: { mode: { answers: ["Fast <@U123>"] } },
187
- });
188
- });
189
-
190
- it("clears pending prompts when Codex resolves the server request itself", async () => {
191
- const params = createParams();
192
- const bridge = createCodexUserInputBridge({
193
- paramsForRun: params,
194
- threadId: "thread-1",
195
- turnId: "turn-1",
196
- });
197
-
198
- const response = bridge.handleRequest({
199
- id: "input-3",
200
- params: {
201
- threadId: "thread-1",
202
- turnId: "turn-1",
203
- itemId: "tool-1",
204
- questions: [
205
- {
206
- id: "answer",
207
- header: "Answer",
208
- question: "Continue?",
209
- isOther: true,
210
- isSecret: false,
211
- options: null,
212
- },
213
- ],
214
- },
215
- });
216
-
217
- await vi.waitFor(() => expect(params.onBlockReply).toHaveBeenCalledTimes(1));
218
- bridge.handleNotification({
219
- method: "serverRequest/resolved",
220
- params: { threadId: "thread-1", requestId: "input-3" },
221
- });
222
-
223
- await expect(response).resolves.toEqual({ answers: {} });
224
- expect(bridge.handleQueuedMessage("too late")).toBe(false);
225
- });
226
-
227
- it("resolves malformed empty question prompts without waiting for chat input", async () => {
228
- const params = createParams();
229
- const bridge = createCodexUserInputBridge({
230
- paramsForRun: params,
231
- threadId: "thread-1",
232
- turnId: "turn-1",
233
- });
234
-
235
- await expect(
236
- bridge.handleRequest({
237
- id: "input-empty",
238
- params: {
239
- threadId: "thread-1",
240
- turnId: "turn-1",
241
- itemId: "tool-1",
242
- questions: [],
243
- },
244
- }),
245
- ).resolves.toEqual({ answers: {} });
246
- expect(params.onBlockReply).not.toHaveBeenCalled();
247
- expect(bridge.handleQueuedMessage("late answer")).toBe(false);
248
- });
249
- });
@@ -1,316 +0,0 @@
1
- import {
2
- embeddedAgentLog,
3
- type EmbeddedRunAttemptParams,
4
- } from "klaw/plugin-sdk/agent-harness-runtime";
5
- import { formatCodexDisplayText } from "../command-formatters.js";
6
- import {
7
- isJsonObject,
8
- type CodexServerNotification,
9
- type JsonObject,
10
- type JsonValue,
11
- } from "./protocol.js";
12
-
13
- type PendingUserInput = {
14
- requestId: number | string;
15
- threadId: string;
16
- turnId: string;
17
- itemId: string;
18
- questions: UserInputQuestion[];
19
- resolve: (value: JsonValue) => void;
20
- cleanup: () => void;
21
- };
22
-
23
- type UserInputQuestion = {
24
- id: string;
25
- header: string;
26
- question: string;
27
- isOther: boolean;
28
- isSecret: boolean;
29
- options: UserInputOption[] | null;
30
- };
31
-
32
- type UserInputOption = {
33
- label: string;
34
- description: string;
35
- };
36
-
37
- type CodexUserInputBridge = {
38
- handleRequest: (request: {
39
- id: number | string;
40
- params?: JsonValue;
41
- }) => Promise<JsonValue | undefined>;
42
- handleQueuedMessage: (text: string) => boolean;
43
- handleNotification: (notification: CodexServerNotification) => void;
44
- cancelPending: () => void;
45
- };
46
-
47
- export function createCodexUserInputBridge(params: {
48
- paramsForRun: EmbeddedRunAttemptParams;
49
- threadId: string;
50
- turnId: string;
51
- signal?: AbortSignal;
52
- }): CodexUserInputBridge {
53
- let pending: PendingUserInput | undefined;
54
-
55
- const resolvePending = (value: JsonValue) => {
56
- const current = pending;
57
- if (!current) {
58
- return;
59
- }
60
- pending = undefined;
61
- current.cleanup();
62
- current.resolve(value);
63
- };
64
-
65
- return {
66
- async handleRequest(request) {
67
- const requestParams = readUserInputParams(request.params);
68
- if (!requestParams) {
69
- return undefined;
70
- }
71
- if (requestParams.threadId !== params.threadId || requestParams.turnId !== params.turnId) {
72
- return undefined;
73
- }
74
- if (requestParams.questions.length === 0) {
75
- return emptyUserInputResponse();
76
- }
77
-
78
- resolvePending(emptyUserInputResponse());
79
-
80
- return new Promise<JsonValue>((resolve) => {
81
- const abortListener = () => resolvePending(emptyUserInputResponse());
82
- const cleanup = () => params.signal?.removeEventListener("abort", abortListener);
83
- pending = {
84
- requestId: request.id,
85
- threadId: requestParams.threadId,
86
- turnId: requestParams.turnId,
87
- itemId: requestParams.itemId,
88
- questions: requestParams.questions,
89
- resolve,
90
- cleanup,
91
- };
92
- params.signal?.addEventListener("abort", abortListener, { once: true });
93
- if (params.signal?.aborted) {
94
- resolvePending(emptyUserInputResponse());
95
- return;
96
- }
97
- void deliverUserInputPrompt(params.paramsForRun, requestParams.questions).catch((error) => {
98
- embeddedAgentLog.warn("failed to deliver codex user input prompt", { error });
99
- });
100
- });
101
- },
102
- handleQueuedMessage(text) {
103
- const current = pending;
104
- if (!current) {
105
- return false;
106
- }
107
- resolvePending(buildUserInputResponse(current.questions, text));
108
- return true;
109
- },
110
- handleNotification(notification) {
111
- if (notification.method !== "serverRequest/resolved" || !pending) {
112
- return;
113
- }
114
- const notificationParams = isJsonObject(notification.params)
115
- ? notification.params
116
- : undefined;
117
- const requestId = notificationParams ? readRequestId(notificationParams) : undefined;
118
- if (
119
- notificationParams &&
120
- readString(notificationParams, "threadId") === pending.threadId &&
121
- requestId !== undefined &&
122
- String(requestId) === String(pending.requestId)
123
- ) {
124
- resolvePending(emptyUserInputResponse());
125
- }
126
- },
127
- cancelPending() {
128
- resolvePending(emptyUserInputResponse());
129
- },
130
- };
131
- }
132
-
133
- function readUserInputParams(value: JsonValue | undefined):
134
- | {
135
- threadId: string;
136
- turnId: string;
137
- itemId: string;
138
- questions: UserInputQuestion[];
139
- }
140
- | undefined {
141
- if (!isJsonObject(value)) {
142
- return undefined;
143
- }
144
- const threadId = readString(value, "threadId");
145
- const turnId = readString(value, "turnId");
146
- const itemId = readString(value, "itemId");
147
- const questionsRaw = value.questions;
148
- if (!threadId || !turnId || !itemId || !Array.isArray(questionsRaw)) {
149
- return undefined;
150
- }
151
- const questions = questionsRaw
152
- .map(readQuestion)
153
- .filter((question): question is UserInputQuestion => Boolean(question));
154
- return { threadId, turnId, itemId, questions };
155
- }
156
-
157
- function readQuestion(value: JsonValue): UserInputQuestion | undefined {
158
- if (!isJsonObject(value)) {
159
- return undefined;
160
- }
161
- const id = readString(value, "id");
162
- const header = readString(value, "header");
163
- const question = readString(value, "question");
164
- if (!id || !header || !question) {
165
- return undefined;
166
- }
167
- return {
168
- id,
169
- header,
170
- question,
171
- isOther: value.isOther === true,
172
- isSecret: value.isSecret === true,
173
- options: readOptions(value.options),
174
- };
175
- }
176
-
177
- function readOptions(value: JsonValue | undefined): UserInputOption[] | null {
178
- if (!Array.isArray(value)) {
179
- return null;
180
- }
181
- const options = value
182
- .map(readOption)
183
- .filter((option): option is UserInputOption => Boolean(option));
184
- return options.length > 0 ? options : null;
185
- }
186
-
187
- function readOption(value: JsonValue): UserInputOption | undefined {
188
- if (!isJsonObject(value)) {
189
- return undefined;
190
- }
191
- const label = readString(value, "label");
192
- const description = readString(value, "description") ?? "";
193
- return label ? { label, description } : undefined;
194
- }
195
-
196
- async function deliverUserInputPrompt(
197
- params: EmbeddedRunAttemptParams,
198
- questions: UserInputQuestion[],
199
- ): Promise<void> {
200
- const text = formatUserInputPrompt(questions);
201
- if (params.onBlockReply) {
202
- await params.onBlockReply({ text });
203
- return;
204
- }
205
- await params.onPartialReply?.({ text });
206
- }
207
-
208
- function formatUserInputPrompt(questions: UserInputQuestion[]): string {
209
- const lines = ["Codex needs input:"];
210
- questions.forEach((question, index) => {
211
- if (questions.length > 1) {
212
- lines.push(
213
- "",
214
- `${index + 1}. ${formatCodexDisplayText(question.header)}`,
215
- formatCodexDisplayText(question.question),
216
- );
217
- } else {
218
- lines.push(
219
- "",
220
- formatCodexDisplayText(question.header),
221
- formatCodexDisplayText(question.question),
222
- );
223
- }
224
- if (question.isSecret) {
225
- lines.push("This channel may show your reply to other participants.");
226
- }
227
- question.options?.forEach((option, optionIndex) => {
228
- lines.push(
229
- `${optionIndex + 1}. ${formatCodexDisplayText(option.label)}${
230
- option.description ? ` - ${formatCodexDisplayText(option.description)}` : ""
231
- }`,
232
- );
233
- });
234
- if (question.isOther) {
235
- lines.push("Other: reply with your own answer.");
236
- }
237
- });
238
- return lines.join("\n");
239
- }
240
-
241
- function buildUserInputResponse(questions: UserInputQuestion[], inputText: string): JsonObject {
242
- const answers: JsonObject = {};
243
- if (questions.length === 1) {
244
- const question = questions[0];
245
- if (question) {
246
- const answer = normalizeAnswer(inputText, question);
247
- answers[question.id] = { answers: answer ? [answer] : [] };
248
- }
249
- return { answers };
250
- }
251
-
252
- const keyed = parseKeyedAnswers(inputText);
253
- const fallbackLines = inputText
254
- .split(/\r?\n/)
255
- .map((line) => line.trim())
256
- .filter(Boolean);
257
- questions.forEach((question, index) => {
258
- const key =
259
- keyed.get(question.id.toLowerCase()) ??
260
- keyed.get(question.header.toLowerCase()) ??
261
- keyed.get(question.question.toLowerCase()) ??
262
- keyed.get(String(index + 1));
263
- const answer = key ?? fallbackLines[index] ?? "";
264
- const normalized = answer ? normalizeAnswer(answer, question) : undefined;
265
- answers[question.id] = { answers: normalized ? [normalized] : [] };
266
- });
267
- return { answers };
268
- }
269
-
270
- function normalizeAnswer(answer: string, question: UserInputQuestion): string | undefined {
271
- const trimmed = answer.trim();
272
- const options = question.options ?? [];
273
- const optionIndex = /^\d+$/.test(trimmed) ? Number(trimmed) - 1 : -1;
274
- const indexed = optionIndex >= 0 ? options[optionIndex] : undefined;
275
- if (indexed) {
276
- return indexed.label;
277
- }
278
- const exact = options.find((option) => option.label.toLowerCase() === trimmed.toLowerCase());
279
- if (exact) {
280
- return exact.label;
281
- }
282
- if (options.length > 0 && !question.isOther) {
283
- return undefined;
284
- }
285
- return trimmed || undefined;
286
- }
287
-
288
- function parseKeyedAnswers(inputText: string): Map<string, string> {
289
- const answers = new Map<string, string>();
290
- for (const line of inputText.split(/\r?\n/)) {
291
- const match = line.match(/^\s*([^:=-]+?)\s*[:=-]\s*(.+?)\s*$/);
292
- if (!match) {
293
- continue;
294
- }
295
- const key = match[1]?.trim().toLowerCase();
296
- const value = match[2]?.trim();
297
- if (key && value) {
298
- answers.set(key, value);
299
- }
300
- }
301
- return answers;
302
- }
303
-
304
- function emptyUserInputResponse(): JsonObject {
305
- return { answers: {} };
306
- }
307
-
308
- function readString(record: JsonObject, key: string): string | undefined {
309
- const value = record[key];
310
- return typeof value === "string" ? value : undefined;
311
- }
312
-
313
- function readRequestId(record: JsonObject): string | number | undefined {
314
- const value = record.requestId;
315
- return typeof value === "string" || typeof value === "number" ? value : undefined;
316
- }
@@ -1,4 +0,0 @@
1
- export const MIN_CODEX_APP_SERVER_VERSION = "0.125.0";
2
- export const MANAGED_CODEX_APP_SERVER_PACKAGE = "@openai/codex";
3
- // Keep this in sync with the Codex CLI live-test package pin.
4
- export const MANAGED_CODEX_APP_SERVER_PACKAGE_VERSION = "0.130.0";
@@ -1,12 +0,0 @@
1
- export function filterToolsForVisionInputs<T extends { name?: string }>(
2
- tools: T[],
3
- params: {
4
- modelHasVision: boolean;
5
- hasInboundImages: boolean;
6
- },
7
- ): T[] {
8
- if (!params.modelHasVision || !params.hasInboundImages) {
9
- return tools;
10
- }
11
- return tools.filter((tool) => tool.name !== "image");
12
- }