@kodelyth/codex 2026.5.42 → 2026.6.2
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.
- package/package.json +17 -2
- package/doctor-contract-api.test.ts +0 -44
- package/doctor-contract-api.ts +0 -68
- package/harness.ts +0 -72
- package/index.test.ts +0 -230
- package/index.ts +0 -66
- package/media-understanding-provider.test.ts +0 -486
- package/media-understanding-provider.ts +0 -521
- package/prompt-overlay-runtime-contract.test.ts +0 -48
- package/prompt-overlay.ts +0 -21
- package/provider-catalog.ts +0 -83
- package/provider-discovery.ts +0 -45
- package/provider.test.ts +0 -384
- package/provider.ts +0 -243
- package/src/app-server/app-inventory-cache.test.ts +0 -176
- package/src/app-server/app-inventory-cache.ts +0 -324
- package/src/app-server/approval-bridge.test.ts +0 -1471
- package/src/app-server/approval-bridge.ts +0 -1211
- package/src/app-server/auth-bridge.test.ts +0 -1449
- package/src/app-server/auth-bridge.ts +0 -614
- package/src/app-server/auth-profile-runtime-contract.test.ts +0 -239
- package/src/app-server/capabilities.ts +0 -27
- package/src/app-server/client-factory.ts +0 -24
- package/src/app-server/client.test.ts +0 -563
- package/src/app-server/client.ts +0 -715
- package/src/app-server/compact.test.ts +0 -710
- package/src/app-server/compact.ts +0 -500
- package/src/app-server/computer-use.test.ts +0 -788
- package/src/app-server/computer-use.ts +0 -683
- package/src/app-server/config.test.ts +0 -879
- package/src/app-server/config.ts +0 -1038
- package/src/app-server/context-engine-projection.test.ts +0 -252
- package/src/app-server/context-engine-projection.ts +0 -403
- package/src/app-server/delivery-no-reply-runtime-contract.test.ts +0 -80
- package/src/app-server/dynamic-tool-diagnostics.ts +0 -73
- package/src/app-server/dynamic-tool-profile.ts +0 -69
- package/src/app-server/dynamic-tools.test.ts +0 -1302
- package/src/app-server/dynamic-tools.ts +0 -623
- package/src/app-server/elicitation-bridge.test.ts +0 -1056
- package/src/app-server/elicitation-bridge.ts +0 -783
- package/src/app-server/event-projector.test.ts +0 -2668
- package/src/app-server/event-projector.ts +0 -2057
- package/src/app-server/image-payload-sanitizer.test.ts +0 -49
- package/src/app-server/image-payload-sanitizer.ts +0 -167
- package/src/app-server/klaw-owned-tool-runtime-contract.test.ts +0 -456
- package/src/app-server/local-runtime-attribution.ts +0 -39
- package/src/app-server/managed-binary.test.ts +0 -139
- package/src/app-server/managed-binary.ts +0 -193
- package/src/app-server/models.test.ts +0 -246
- package/src/app-server/models.ts +0 -172
- package/src/app-server/native-hook-relay.test.ts +0 -271
- package/src/app-server/native-hook-relay.ts +0 -150
- package/src/app-server/native-subagent-task-mirror.test.ts +0 -573
- package/src/app-server/native-subagent-task-mirror.ts +0 -497
- package/src/app-server/outcome-fallback-runtime-contract.test.ts +0 -404
- package/src/app-server/plugin-activation.test.ts +0 -336
- package/src/app-server/plugin-activation.ts +0 -283
- package/src/app-server/plugin-app-cache-key.ts +0 -74
- package/src/app-server/plugin-approval-roundtrip.ts +0 -122
- package/src/app-server/plugin-inventory.test.ts +0 -355
- package/src/app-server/plugin-inventory.ts +0 -357
- package/src/app-server/plugin-thread-config.test.ts +0 -865
- package/src/app-server/plugin-thread-config.ts +0 -455
- package/src/app-server/protocol-generated/json/DynamicToolCallParams.json +0 -33
- package/src/app-server/protocol-generated/json/v2/ErrorNotification.json +0 -199
- package/src/app-server/protocol-generated/json/v2/GetAccountResponse.json +0 -102
- package/src/app-server/protocol-generated/json/v2/ModelListResponse.json +0 -227
- package/src/app-server/protocol-generated/json/v2/ThreadResumeResponse.json +0 -2630
- package/src/app-server/protocol-generated/json/v2/ThreadStartResponse.json +0 -2630
- package/src/app-server/protocol-generated/json/v2/TurnCompletedNotification.json +0 -1659
- package/src/app-server/protocol-generated/json/v2/TurnStartResponse.json +0 -1655
- package/src/app-server/protocol-validators.test.ts +0 -75
- package/src/app-server/protocol-validators.ts +0 -203
- package/src/app-server/protocol.ts +0 -520
- package/src/app-server/rate-limit-cache.ts +0 -48
- package/src/app-server/rate-limits.test.ts +0 -202
- package/src/app-server/rate-limits.ts +0 -583
- package/src/app-server/request.ts +0 -73
- package/src/app-server/run-attempt.context-engine.test.ts +0 -1004
- package/src/app-server/run-attempt.test.ts +0 -9477
- package/src/app-server/run-attempt.ts +0 -4683
- package/src/app-server/run-attempt.vision-tools.test.ts +0 -35
- package/src/app-server/schema-normalization-runtime-contract.test.ts +0 -206
- package/src/app-server/session-binding.test.ts +0 -303
- package/src/app-server/session-binding.ts +0 -398
- package/src/app-server/session-history.ts +0 -44
- package/src/app-server/shared-client.test.ts +0 -589
- package/src/app-server/shared-client.ts +0 -289
- package/src/app-server/side-question.test.ts +0 -1175
- package/src/app-server/side-question.ts +0 -1007
- package/src/app-server/test-support.ts +0 -48
- package/src/app-server/thread-lifecycle.test.ts +0 -447
- package/src/app-server/thread-lifecycle.ts +0 -939
- package/src/app-server/thread-lifecycle.user-mcp-servers.test.ts +0 -442
- package/src/app-server/timeout.ts +0 -9
- package/src/app-server/tool-progress-normalization.ts +0 -77
- package/src/app-server/trajectory.test.ts +0 -205
- package/src/app-server/trajectory.ts +0 -365
- package/src/app-server/transcript-mirror.test.ts +0 -524
- package/src/app-server/transcript-mirror.ts +0 -208
- package/src/app-server/transcript-repair-runtime-contract.test.ts +0 -44
- package/src/app-server/transport-stdio.test.ts +0 -171
- package/src/app-server/transport-stdio.ts +0 -107
- package/src/app-server/transport-websocket.test.ts +0 -69
- package/src/app-server/transport-websocket.ts +0 -90
- package/src/app-server/transport.ts +0 -117
- package/src/app-server/user-input-bridge.test.ts +0 -249
- package/src/app-server/user-input-bridge.ts +0 -316
- package/src/app-server/version.ts +0 -4
- package/src/app-server/vision-tools.ts +0 -12
- package/src/command-account.ts +0 -544
- package/src/command-formatters.ts +0 -425
- package/src/command-handlers.ts +0 -2004
- package/src/command-rpc.test.ts +0 -16
- package/src/command-rpc.ts +0 -142
- package/src/commands.test.ts +0 -3312
- package/src/commands.ts +0 -65
- package/src/conversation-binding-data.ts +0 -124
- package/src/conversation-binding.test.ts +0 -599
- package/src/conversation-binding.ts +0 -561
- package/src/conversation-control.test.ts +0 -126
- package/src/conversation-control.ts +0 -303
- package/src/conversation-turn-collector.test.ts +0 -191
- package/src/conversation-turn-collector.ts +0 -186
- package/src/conversation-turn-input.test.ts +0 -141
- package/src/conversation-turn-input.ts +0 -106
- package/src/manifest.test.ts +0 -20
- package/src/migration/apply.ts +0 -501
- package/src/migration/helpers.ts +0 -55
- package/src/migration/plan.ts +0 -461
- package/src/migration/provider.test.ts +0 -1741
- package/src/migration/provider.ts +0 -41
- package/src/migration/source.ts +0 -643
- package/src/migration/targets.ts +0 -25
- package/src/node-cli-sessions.test.ts +0 -180
- package/src/node-cli-sessions.ts +0 -711
- package/test-api.ts +0 -82
- package/tsconfig.json +0 -16
|
@@ -1,486 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { buildCodexMediaUnderstandingProvider } from "./media-understanding-provider.js";
|
|
3
|
-
import type { CodexAppServerClient } from "./src/app-server/client.js";
|
|
4
|
-
import type { CodexServerNotification, JsonValue } from "./src/app-server/protocol.js";
|
|
5
|
-
|
|
6
|
-
function codexModel(inputModalities: string[] = ["text", "image"]) {
|
|
7
|
-
return {
|
|
8
|
-
id: "gpt-5.4",
|
|
9
|
-
model: "gpt-5.4",
|
|
10
|
-
upgrade: null,
|
|
11
|
-
upgradeInfo: null,
|
|
12
|
-
availabilityNux: null,
|
|
13
|
-
displayName: "gpt-5.4",
|
|
14
|
-
description: "GPT-5.4",
|
|
15
|
-
hidden: false,
|
|
16
|
-
supportedReasoningEfforts: [{ reasoningEffort: "low", description: "fast" }],
|
|
17
|
-
defaultReasoningEffort: "low",
|
|
18
|
-
inputModalities,
|
|
19
|
-
supportsPersonality: false,
|
|
20
|
-
additionalSpeedTiers: [],
|
|
21
|
-
isDefault: true,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function threadStartResult() {
|
|
26
|
-
return {
|
|
27
|
-
thread: {
|
|
28
|
-
id: "thread-1",
|
|
29
|
-
sessionId: "session-1",
|
|
30
|
-
forkedFromId: null,
|
|
31
|
-
preview: "",
|
|
32
|
-
ephemeral: true,
|
|
33
|
-
modelProvider: "openai",
|
|
34
|
-
createdAt: 1,
|
|
35
|
-
updatedAt: 1,
|
|
36
|
-
status: { type: "idle" },
|
|
37
|
-
path: null,
|
|
38
|
-
cwd: "/tmp/klaw-agent",
|
|
39
|
-
cliVersion: "0.125.0",
|
|
40
|
-
source: "unknown",
|
|
41
|
-
agentNickname: null,
|
|
42
|
-
agentRole: null,
|
|
43
|
-
gitInfo: null,
|
|
44
|
-
name: null,
|
|
45
|
-
turns: [],
|
|
46
|
-
},
|
|
47
|
-
model: "gpt-5.4",
|
|
48
|
-
modelProvider: "openai",
|
|
49
|
-
serviceTier: null,
|
|
50
|
-
cwd: "/tmp/klaw-agent",
|
|
51
|
-
instructionSources: [],
|
|
52
|
-
approvalPolicy: "on-request",
|
|
53
|
-
approvalsReviewer: "user",
|
|
54
|
-
sandbox: { type: "dangerFullAccess" },
|
|
55
|
-
permissionProfile: null,
|
|
56
|
-
reasoningEffort: null,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function turnStartResult(status = "inProgress", items: JsonValue[] = []) {
|
|
61
|
-
return {
|
|
62
|
-
turn: {
|
|
63
|
-
id: "turn-1",
|
|
64
|
-
status,
|
|
65
|
-
items,
|
|
66
|
-
error: null,
|
|
67
|
-
startedAt: null,
|
|
68
|
-
completedAt: null,
|
|
69
|
-
durationMs: null,
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function createFakeClient(options?: {
|
|
75
|
-
inputModalities?: string[];
|
|
76
|
-
completeWithItems?: boolean;
|
|
77
|
-
notifyError?: string;
|
|
78
|
-
approvalRequestMethod?: string;
|
|
79
|
-
responseText?: string;
|
|
80
|
-
}) {
|
|
81
|
-
const notifications = new Set<(notification: CodexServerNotification) => void>();
|
|
82
|
-
const requestHandlers = new Set<(request: { method: string }) => JsonValue | undefined>();
|
|
83
|
-
const requests: Array<{ method: string; params?: JsonValue }> = [];
|
|
84
|
-
const approvalResponses: JsonValue[] = [];
|
|
85
|
-
const request = vi.fn(async (method: string, params?: JsonValue) => {
|
|
86
|
-
requests.push({ method, params });
|
|
87
|
-
if (method === "model/list") {
|
|
88
|
-
return {
|
|
89
|
-
data: [codexModel(options?.inputModalities)],
|
|
90
|
-
nextCursor: null,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
if (method === "thread/start") {
|
|
94
|
-
return threadStartResult();
|
|
95
|
-
}
|
|
96
|
-
if (method === "turn/start") {
|
|
97
|
-
if (options?.approvalRequestMethod) {
|
|
98
|
-
for (const handler of requestHandlers) {
|
|
99
|
-
const response = handler({ method: options.approvalRequestMethod });
|
|
100
|
-
if (response !== undefined) {
|
|
101
|
-
approvalResponses.push(response);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (options?.notifyError) {
|
|
106
|
-
for (const notify of notifications) {
|
|
107
|
-
notify({
|
|
108
|
-
method: "error",
|
|
109
|
-
params: {
|
|
110
|
-
threadId: "thread-1",
|
|
111
|
-
turnId: "turn-1",
|
|
112
|
-
error: {
|
|
113
|
-
message: options.notifyError,
|
|
114
|
-
codexErrorInfo: null,
|
|
115
|
-
additionalDetails: null,
|
|
116
|
-
},
|
|
117
|
-
willRetry: false,
|
|
118
|
-
},
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
} else if (!options?.completeWithItems) {
|
|
122
|
-
for (const notify of notifications) {
|
|
123
|
-
notify({
|
|
124
|
-
method: "item/agentMessage/delta",
|
|
125
|
-
params: {
|
|
126
|
-
threadId: "thread-1",
|
|
127
|
-
turnId: "turn-1",
|
|
128
|
-
itemId: "msg-1",
|
|
129
|
-
delta: options?.responseText ?? "A red square.",
|
|
130
|
-
},
|
|
131
|
-
});
|
|
132
|
-
notify({
|
|
133
|
-
method: "turn/completed",
|
|
134
|
-
params: {
|
|
135
|
-
threadId: "thread-1",
|
|
136
|
-
turnId: "turn-1",
|
|
137
|
-
turn: turnStartResult("completed").turn,
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return turnStartResult(
|
|
143
|
-
options?.completeWithItems ? "completed" : "inProgress",
|
|
144
|
-
options?.completeWithItems
|
|
145
|
-
? [
|
|
146
|
-
{
|
|
147
|
-
id: "msg-1",
|
|
148
|
-
type: "agentMessage",
|
|
149
|
-
text: options?.responseText ?? "A blue circle.",
|
|
150
|
-
phase: null,
|
|
151
|
-
memoryCitation: null,
|
|
152
|
-
},
|
|
153
|
-
]
|
|
154
|
-
: [],
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
return {};
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
const client = {
|
|
161
|
-
request,
|
|
162
|
-
addNotificationHandler(handler: (notification: CodexServerNotification) => void) {
|
|
163
|
-
notifications.add(handler);
|
|
164
|
-
return () => notifications.delete(handler);
|
|
165
|
-
},
|
|
166
|
-
addRequestHandler(handler: (request: { method: string }) => JsonValue | undefined) {
|
|
167
|
-
requestHandlers.add(handler);
|
|
168
|
-
return () => requestHandlers.delete(handler);
|
|
169
|
-
},
|
|
170
|
-
} as unknown as CodexAppServerClient;
|
|
171
|
-
|
|
172
|
-
return { client, requests, approvalResponses };
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
describe("codex media understanding provider", () => {
|
|
176
|
-
it("runs image understanding through a bounded Codex app-server turn", async () => {
|
|
177
|
-
const { client, requests } = createFakeClient();
|
|
178
|
-
const provider = buildCodexMediaUnderstandingProvider({
|
|
179
|
-
clientFactory: async () => client,
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
const result = await provider.describeImage?.({
|
|
183
|
-
buffer: Buffer.from("image-bytes"),
|
|
184
|
-
fileName: "image.png",
|
|
185
|
-
mime: "image/png",
|
|
186
|
-
provider: "codex",
|
|
187
|
-
model: "gpt-5.4",
|
|
188
|
-
prompt: "Describe briefly.",
|
|
189
|
-
timeoutMs: 30_000,
|
|
190
|
-
cfg: {},
|
|
191
|
-
agentDir: "/tmp/klaw-agent",
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
expect(result).toEqual({ text: "A red square.", model: "gpt-5.4" });
|
|
195
|
-
expect(requests.map((entry) => entry.method)).toEqual([
|
|
196
|
-
"model/list",
|
|
197
|
-
"thread/start",
|
|
198
|
-
"turn/start",
|
|
199
|
-
]);
|
|
200
|
-
expect(requests[1]?.params).toEqual({
|
|
201
|
-
model: "gpt-5.4",
|
|
202
|
-
modelProvider: "openai",
|
|
203
|
-
cwd: "/tmp/klaw-agent",
|
|
204
|
-
approvalPolicy: "on-request",
|
|
205
|
-
sandbox: "read-only",
|
|
206
|
-
serviceName: "Klaw",
|
|
207
|
-
developerInstructions:
|
|
208
|
-
"You are Klaw's bounded image-understanding worker. Describe only the provided image content. Do not call tools, edit files, or ask follow-up questions.",
|
|
209
|
-
dynamicTools: [],
|
|
210
|
-
experimentalRawEvents: true,
|
|
211
|
-
ephemeral: true,
|
|
212
|
-
persistExtendedHistory: false,
|
|
213
|
-
});
|
|
214
|
-
expect(requests[2]?.params).toEqual({
|
|
215
|
-
threadId: "thread-1",
|
|
216
|
-
input: [
|
|
217
|
-
{ type: "text", text: "Describe briefly.", text_elements: [] },
|
|
218
|
-
{ type: "image", url: "data:image/png;base64,aW1hZ2UtYnl0ZXM=" },
|
|
219
|
-
],
|
|
220
|
-
cwd: "/tmp/klaw-agent",
|
|
221
|
-
approvalPolicy: "on-request",
|
|
222
|
-
model: "gpt-5.4",
|
|
223
|
-
effort: "low",
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it("declines approval requests during image understanding", async () => {
|
|
228
|
-
const { client, approvalResponses } = createFakeClient({
|
|
229
|
-
approvalRequestMethod: "item/permissions/requestApproval",
|
|
230
|
-
});
|
|
231
|
-
const provider = buildCodexMediaUnderstandingProvider({
|
|
232
|
-
clientFactory: async () => client,
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
await provider.describeImage?.({
|
|
236
|
-
buffer: Buffer.from("image-bytes"),
|
|
237
|
-
fileName: "image.png",
|
|
238
|
-
mime: "image/png",
|
|
239
|
-
provider: "codex",
|
|
240
|
-
model: "gpt-5.4",
|
|
241
|
-
prompt: "Describe briefly.",
|
|
242
|
-
timeoutMs: 30_000,
|
|
243
|
-
cfg: {},
|
|
244
|
-
agentDir: "/tmp/klaw-agent",
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
expect(approvalResponses).toEqual([{ permissions: {}, scope: "turn" }]);
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
it("extracts text from terminal turn items", async () => {
|
|
251
|
-
const { client } = createFakeClient({ completeWithItems: true });
|
|
252
|
-
const provider = buildCodexMediaUnderstandingProvider({
|
|
253
|
-
clientFactory: async () => client,
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
const result = await provider.describeImages?.({
|
|
257
|
-
images: [{ buffer: Buffer.from("image-bytes"), fileName: "image.png", mime: "image/png" }],
|
|
258
|
-
provider: "codex",
|
|
259
|
-
model: "gpt-5.4",
|
|
260
|
-
prompt: "Describe briefly.",
|
|
261
|
-
timeoutMs: 30_000,
|
|
262
|
-
cfg: {},
|
|
263
|
-
agentDir: "/tmp/klaw-agent",
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
expect(result).toEqual({ text: "A blue circle.", model: "gpt-5.4" });
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it("rejects text-only Codex app-server models before starting a turn", async () => {
|
|
270
|
-
const { client, requests } = createFakeClient({ inputModalities: ["text"] });
|
|
271
|
-
const provider = buildCodexMediaUnderstandingProvider({
|
|
272
|
-
clientFactory: async () => client,
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
await expect(
|
|
276
|
-
provider.describeImage?.({
|
|
277
|
-
buffer: Buffer.from("image-bytes"),
|
|
278
|
-
fileName: "image.png",
|
|
279
|
-
mime: "image/png",
|
|
280
|
-
provider: "codex",
|
|
281
|
-
model: "gpt-5.4",
|
|
282
|
-
timeoutMs: 30_000,
|
|
283
|
-
cfg: {},
|
|
284
|
-
agentDir: "/tmp/klaw-agent",
|
|
285
|
-
}),
|
|
286
|
-
).rejects.toThrow("Codex app-server model does not support images: gpt-5.4");
|
|
287
|
-
expect(requests.map((entry) => entry.method)).toEqual(["model/list"]);
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
it("surfaces Codex app-server turn errors", async () => {
|
|
291
|
-
const { client } = createFakeClient({ notifyError: "vision unavailable" });
|
|
292
|
-
const provider = buildCodexMediaUnderstandingProvider({
|
|
293
|
-
clientFactory: async () => client,
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
await expect(
|
|
297
|
-
provider.describeImage?.({
|
|
298
|
-
buffer: Buffer.from("image-bytes"),
|
|
299
|
-
fileName: "image.png",
|
|
300
|
-
mime: "image/png",
|
|
301
|
-
provider: "codex",
|
|
302
|
-
model: "gpt-5.4",
|
|
303
|
-
timeoutMs: 30_000,
|
|
304
|
-
cfg: {},
|
|
305
|
-
agentDir: "/tmp/klaw-agent",
|
|
306
|
-
}),
|
|
307
|
-
).rejects.toThrow("vision unavailable");
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
it("runs structured extraction through the same bounded Codex app-server path", async () => {
|
|
311
|
-
const { client, requests } = createFakeClient({
|
|
312
|
-
responseText: '{"summary":"red square","tags":["shape"]}',
|
|
313
|
-
});
|
|
314
|
-
const provider = buildCodexMediaUnderstandingProvider({
|
|
315
|
-
clientFactory: async () => client,
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
const result = await provider.extractStructured?.({
|
|
319
|
-
input: [
|
|
320
|
-
{ type: "text", text: "Extract searchable evidence." },
|
|
321
|
-
{
|
|
322
|
-
type: "image",
|
|
323
|
-
buffer: Buffer.from("image-bytes"),
|
|
324
|
-
fileName: "image.png",
|
|
325
|
-
mime: "image/png",
|
|
326
|
-
},
|
|
327
|
-
],
|
|
328
|
-
instructions: "Return a compact evidence object.",
|
|
329
|
-
schemaName: "example.media",
|
|
330
|
-
jsonSchema: {
|
|
331
|
-
type: "object",
|
|
332
|
-
properties: {
|
|
333
|
-
summary: { type: "string" },
|
|
334
|
-
tags: { type: "array", items: { type: "string" } },
|
|
335
|
-
},
|
|
336
|
-
required: ["summary"],
|
|
337
|
-
},
|
|
338
|
-
provider: "codex",
|
|
339
|
-
model: "gpt-5.4",
|
|
340
|
-
timeoutMs: 30_000,
|
|
341
|
-
cfg: {},
|
|
342
|
-
agentDir: "/tmp/klaw-agent",
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
expect(result).toEqual({
|
|
346
|
-
text: '{"summary":"red square","tags":["shape"]}',
|
|
347
|
-
parsed: { summary: "red square", tags: ["shape"] },
|
|
348
|
-
model: "gpt-5.4",
|
|
349
|
-
provider: "codex",
|
|
350
|
-
contentType: "json",
|
|
351
|
-
});
|
|
352
|
-
expect(requests.map((entry) => entry.method)).toEqual([
|
|
353
|
-
"model/list",
|
|
354
|
-
"thread/start",
|
|
355
|
-
"turn/start",
|
|
356
|
-
]);
|
|
357
|
-
expect(requests[1]?.params).toEqual({
|
|
358
|
-
model: "gpt-5.4",
|
|
359
|
-
modelProvider: "openai",
|
|
360
|
-
cwd: "/tmp/klaw-agent",
|
|
361
|
-
approvalPolicy: "on-request",
|
|
362
|
-
sandbox: "read-only",
|
|
363
|
-
serviceName: "Klaw",
|
|
364
|
-
developerInstructions:
|
|
365
|
-
"You are Klaw's bounded structured-extraction worker. Return only the requested extraction. Do not call tools, edit files, ask follow-up questions, or include secrets.",
|
|
366
|
-
dynamicTools: [],
|
|
367
|
-
experimentalRawEvents: true,
|
|
368
|
-
ephemeral: true,
|
|
369
|
-
persistExtendedHistory: false,
|
|
370
|
-
});
|
|
371
|
-
const turnParams = requests[2]?.params as
|
|
372
|
-
| {
|
|
373
|
-
threadId?: unknown;
|
|
374
|
-
approvalPolicy?: unknown;
|
|
375
|
-
model?: unknown;
|
|
376
|
-
input?: Array<{ type?: unknown; text?: unknown; text_elements?: unknown; url?: unknown }>;
|
|
377
|
-
cwd?: unknown;
|
|
378
|
-
effort?: unknown;
|
|
379
|
-
}
|
|
380
|
-
| undefined;
|
|
381
|
-
expect(turnParams?.threadId).toBe("thread-1");
|
|
382
|
-
expect(turnParams?.approvalPolicy).toBe("on-request");
|
|
383
|
-
expect(turnParams?.model).toBe("gpt-5.4");
|
|
384
|
-
expect(turnParams?.cwd).toBe("/tmp/klaw-agent");
|
|
385
|
-
expect(turnParams?.effort).toBe("low");
|
|
386
|
-
expect(turnParams?.input).toHaveLength(3);
|
|
387
|
-
expect(turnParams?.input?.[0]?.type).toBe("text");
|
|
388
|
-
expect(turnParams?.input?.[0]?.text).toContain("Return valid JSON only");
|
|
389
|
-
expect(turnParams?.input?.[0]?.text_elements).toStrictEqual([]);
|
|
390
|
-
expect(turnParams?.input?.[1]).toStrictEqual({
|
|
391
|
-
type: "text",
|
|
392
|
-
text: "Extract searchable evidence.",
|
|
393
|
-
text_elements: [],
|
|
394
|
-
});
|
|
395
|
-
expect(turnParams?.input?.[2]).toStrictEqual({
|
|
396
|
-
type: "image",
|
|
397
|
-
url: "data:image/png;base64,aW1hZ2UtYnl0ZXM=",
|
|
398
|
-
});
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
it("rejects text-only structured extraction before starting a turn", async () => {
|
|
402
|
-
const { client, requests } = createFakeClient({
|
|
403
|
-
inputModalities: ["text"],
|
|
404
|
-
responseText: '{"summary":"only text"}',
|
|
405
|
-
});
|
|
406
|
-
const provider = buildCodexMediaUnderstandingProvider({
|
|
407
|
-
clientFactory: async () => client,
|
|
408
|
-
});
|
|
409
|
-
|
|
410
|
-
await expect(
|
|
411
|
-
provider.extractStructured?.({
|
|
412
|
-
input: [{ type: "text", text: "The answer is only text." }],
|
|
413
|
-
instructions: "Return summary JSON.",
|
|
414
|
-
provider: "codex",
|
|
415
|
-
model: "gpt-5.4",
|
|
416
|
-
timeoutMs: 30_000,
|
|
417
|
-
cfg: {},
|
|
418
|
-
agentDir: "/tmp/klaw-agent",
|
|
419
|
-
}),
|
|
420
|
-
).rejects.toThrow("Codex structured extraction requires at least one image input.");
|
|
421
|
-
expect(requests).toEqual([]);
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
it("returns a controlled error when structured JSON parsing fails", async () => {
|
|
425
|
-
const { client } = createFakeClient({ responseText: "not json" });
|
|
426
|
-
const provider = buildCodexMediaUnderstandingProvider({
|
|
427
|
-
clientFactory: async () => client,
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
await expect(
|
|
431
|
-
provider.extractStructured?.({
|
|
432
|
-
input: [
|
|
433
|
-
{ type: "text", text: "Extract JSON." },
|
|
434
|
-
{
|
|
435
|
-
type: "image",
|
|
436
|
-
buffer: Buffer.from("image-bytes"),
|
|
437
|
-
fileName: "image.png",
|
|
438
|
-
mime: "image/png",
|
|
439
|
-
},
|
|
440
|
-
],
|
|
441
|
-
instructions: "Return summary JSON.",
|
|
442
|
-
provider: "codex",
|
|
443
|
-
model: "gpt-5.4",
|
|
444
|
-
timeoutMs: 30_000,
|
|
445
|
-
cfg: {},
|
|
446
|
-
agentDir: "/tmp/klaw-agent",
|
|
447
|
-
}),
|
|
448
|
-
).rejects.toThrow("Codex structured extraction returned invalid JSON.");
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
it("validates structured extraction JSON against the requested schema", async () => {
|
|
452
|
-
const { client } = createFakeClient({
|
|
453
|
-
responseText: '{"summary":123,"tags":["shape"]}',
|
|
454
|
-
});
|
|
455
|
-
const provider = buildCodexMediaUnderstandingProvider({
|
|
456
|
-
clientFactory: async () => client,
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
await expect(
|
|
460
|
-
provider.extractStructured?.({
|
|
461
|
-
input: [
|
|
462
|
-
{ type: "text", text: "Extract JSON." },
|
|
463
|
-
{
|
|
464
|
-
type: "image",
|
|
465
|
-
buffer: Buffer.from("image-bytes"),
|
|
466
|
-
fileName: "image.png",
|
|
467
|
-
mime: "image/png",
|
|
468
|
-
},
|
|
469
|
-
],
|
|
470
|
-
instructions: "Return summary JSON.",
|
|
471
|
-
jsonSchema: {
|
|
472
|
-
type: "object",
|
|
473
|
-
properties: {
|
|
474
|
-
summary: { type: "string" },
|
|
475
|
-
},
|
|
476
|
-
required: ["summary"],
|
|
477
|
-
},
|
|
478
|
-
provider: "codex",
|
|
479
|
-
model: "gpt-5.4",
|
|
480
|
-
timeoutMs: 30_000,
|
|
481
|
-
cfg: {},
|
|
482
|
-
agentDir: "/tmp/klaw-agent",
|
|
483
|
-
}),
|
|
484
|
-
).rejects.toThrow("Codex structured extraction JSON did not match schema");
|
|
485
|
-
});
|
|
486
|
-
});
|