@janole/ai-sdk-provider-codex-asp 0.3.6 → 0.4.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.
- package/dist/index.cjs +60 -227
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +54 -25
- package/dist/index.d.ts +54 -25
- package/dist/index.js +60 -228
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -935,7 +935,7 @@ var DynamicToolsDispatcher = class {
|
|
|
935
935
|
// package.json
|
|
936
936
|
var package_default = {
|
|
937
937
|
name: "@janole/ai-sdk-provider-codex-asp",
|
|
938
|
-
version: "0.
|
|
938
|
+
version: "0.4.1"};
|
|
939
939
|
|
|
940
940
|
// src/package-info.ts
|
|
941
941
|
var PACKAGE_NAME = package_default.name;
|
|
@@ -949,12 +949,16 @@ function codexProviderMetadata(threadId, turnId) {
|
|
|
949
949
|
}
|
|
950
950
|
return { [CODEX_PROVIDER_ID]: stripUndefined({ threadId, turnId }) };
|
|
951
951
|
}
|
|
952
|
+
function codexCallOptions(options) {
|
|
953
|
+
return { [CODEX_PROVIDER_ID]: options };
|
|
954
|
+
}
|
|
952
955
|
function withProviderMetadata(part, threadId, turnId) {
|
|
953
956
|
const meta = codexProviderMetadata(threadId, turnId);
|
|
954
957
|
return meta ? { ...part, providerMetadata: meta } : part;
|
|
955
958
|
}
|
|
956
959
|
|
|
957
960
|
// src/protocol/event-mapper.ts
|
|
961
|
+
var NATIVE_TOOL_RESULT_TYPES = /* @__PURE__ */ new Set(["commandExecution", "dynamicToolCall", "fileChange", "mcpToolCall", "webSearch"]);
|
|
958
962
|
var EMPTY_USAGE = {
|
|
959
963
|
inputTokens: {
|
|
960
964
|
total: void 0,
|
|
@@ -981,7 +985,6 @@ function toFinishReason(status) {
|
|
|
981
985
|
}
|
|
982
986
|
}
|
|
983
987
|
var NOOP = () => [];
|
|
984
|
-
var DEFAULT_MAX_TOOL_RESULT_OUTPUT_CHARS = 32768;
|
|
985
988
|
var CodexEventMapper = class {
|
|
986
989
|
options;
|
|
987
990
|
streamStarted = false;
|
|
@@ -996,8 +999,7 @@ var CodexEventMapper = class {
|
|
|
996
999
|
handlers;
|
|
997
1000
|
constructor(options) {
|
|
998
1001
|
this.options = {
|
|
999
|
-
emitPlanUpdates: options?.emitPlanUpdates ?? true
|
|
1000
|
-
maxToolResultOutputChars: options?.maxToolResultOutputChars ?? DEFAULT_MAX_TOOL_RESULT_OUTPUT_CHARS
|
|
1002
|
+
emitPlanUpdates: options?.emitPlanUpdates ?? true
|
|
1001
1003
|
};
|
|
1002
1004
|
this.handlers = {
|
|
1003
1005
|
"turn/started": (p) => this.handleTurnStarted(p),
|
|
@@ -1007,12 +1009,8 @@ var CodexEventMapper = class {
|
|
|
1007
1009
|
"item/reasoning/textDelta": (p) => this.handleReasoningDelta(p),
|
|
1008
1010
|
"item/reasoning/summaryTextDelta": (p) => this.handleReasoningDelta(p),
|
|
1009
1011
|
"item/plan/delta": (p) => this.handleReasoningDelta(p),
|
|
1010
|
-
"item/fileChange/outputDelta": (p) => this.handleFileChangeOutputDelta(p),
|
|
1011
1012
|
"item/reasoning/summaryPartAdded": (p) => this.handleSummaryPartAdded(p),
|
|
1012
1013
|
"turn/plan/updated": (p) => this.handlePlanUpdated(p),
|
|
1013
|
-
"item/commandExecution/outputDelta": (p) => this.handleCommandOutputDelta(p),
|
|
1014
|
-
"codex/event/mcp_tool_call_begin": (p) => this.handleMcpToolCallBegin(p),
|
|
1015
|
-
"codex/event/mcp_tool_call_end": (p) => this.handleMcpToolCallEnd(p),
|
|
1016
1014
|
"item/mcpToolCall/progress": (p) => this.handleMcpToolCallProgress(p),
|
|
1017
1015
|
"item/tool/callStarted": (p) => this.handleToolCallStarted(p),
|
|
1018
1016
|
"item/tool/callDelta": (p) => this.handleToolCallDelta(p),
|
|
@@ -1024,10 +1022,15 @@ var CodexEventMapper = class {
|
|
|
1024
1022
|
"codex/event/agent_reasoning": NOOP,
|
|
1025
1023
|
"codex/event/agent_reasoning_section_break": NOOP,
|
|
1026
1024
|
"codex/event/plan_update": NOOP,
|
|
1027
|
-
// Intentionally ignored: web search wrappers mirror item events.
|
|
1028
|
-
// We emit web-search reasoning only from item/started + item/completed.
|
|
1025
|
+
// Intentionally ignored: web search and MCP wrappers mirror item events.
|
|
1029
1026
|
"codex/event/web_search_begin": NOOP,
|
|
1030
1027
|
"codex/event/web_search_end": NOOP,
|
|
1028
|
+
"codex/event/mcp_tool_call_begin": NOOP,
|
|
1029
|
+
"codex/event/mcp_tool_call_end": NOOP,
|
|
1030
|
+
// Intentionally ignored: streaming output deltas — the full output arrives
|
|
1031
|
+
// in item/completed (aggregatedOutput), making these redundant.
|
|
1032
|
+
"item/commandExecution/outputDelta": NOOP,
|
|
1033
|
+
"item/fileChange/outputDelta": NOOP,
|
|
1031
1034
|
// Intentionally ignored: full diffs (often 50-100 KB) crash/freeze frontend renderers.
|
|
1032
1035
|
// If these need to surface, they should use a dedicated part type with lazy rendering.
|
|
1033
1036
|
"turn/diff/updated": NOOP,
|
|
@@ -1072,33 +1075,6 @@ var CodexEventMapper = class {
|
|
|
1072
1075
|
this.planSequenceByTurnId.set(turnId, next);
|
|
1073
1076
|
return next;
|
|
1074
1077
|
}
|
|
1075
|
-
applyOutputLimit(output) {
|
|
1076
|
-
const limit = this.options.maxToolResultOutputChars;
|
|
1077
|
-
if (limit <= 0) {
|
|
1078
|
-
return { output, droppedChars: 0 };
|
|
1079
|
-
}
|
|
1080
|
-
if (output.length <= limit) {
|
|
1081
|
-
return { output, droppedChars: 0 };
|
|
1082
|
-
}
|
|
1083
|
-
const droppedChars = output.length - limit;
|
|
1084
|
-
return { output: output.slice(droppedChars), droppedChars };
|
|
1085
|
-
}
|
|
1086
|
-
appendTrackedOutput(tracked, delta) {
|
|
1087
|
-
if (!delta) {
|
|
1088
|
-
return;
|
|
1089
|
-
}
|
|
1090
|
-
const combined = tracked.output + delta;
|
|
1091
|
-
const limited = this.applyOutputLimit(combined);
|
|
1092
|
-
tracked.output = limited.output;
|
|
1093
|
-
tracked.droppedChars += limited.droppedChars;
|
|
1094
|
-
}
|
|
1095
|
-
formatToolOutput(output, droppedChars) {
|
|
1096
|
-
if (droppedChars <= 0) {
|
|
1097
|
-
return output;
|
|
1098
|
-
}
|
|
1099
|
-
return `[output truncated: ${droppedChars} chars omitted]
|
|
1100
|
-
${output}`;
|
|
1101
|
-
}
|
|
1102
1078
|
// ── Handlers ─────────────────────────────────────────────────────────────
|
|
1103
1079
|
// turn/started
|
|
1104
1080
|
handleTurnStarted(params) {
|
|
@@ -1128,7 +1104,7 @@ ${output}`;
|
|
|
1128
1104
|
case "commandExecution": {
|
|
1129
1105
|
this.ensureStreamStarted(parts);
|
|
1130
1106
|
const toolName = "codex_command_execution";
|
|
1131
|
-
this.openToolCalls.set(item.id, { toolName
|
|
1107
|
+
this.openToolCalls.set(item.id, { toolName });
|
|
1132
1108
|
parts.push(this.withMeta({
|
|
1133
1109
|
type: "tool-call",
|
|
1134
1110
|
toolCallId: item.id,
|
|
@@ -1146,7 +1122,7 @@ ${output}`;
|
|
|
1146
1122
|
case "fileChange": {
|
|
1147
1123
|
this.ensureStreamStarted(parts);
|
|
1148
1124
|
const toolName = "codex_file_change";
|
|
1149
|
-
this.openToolCalls.set(item.id, { toolName
|
|
1125
|
+
this.openToolCalls.set(item.id, { toolName });
|
|
1150
1126
|
parts.push(this.withMeta({
|
|
1151
1127
|
type: "tool-call",
|
|
1152
1128
|
toolCallId: item.id,
|
|
@@ -1160,7 +1136,7 @@ ${output}`;
|
|
|
1160
1136
|
case "webSearch": {
|
|
1161
1137
|
this.ensureStreamStarted(parts);
|
|
1162
1138
|
const toolName = "codex_web_search";
|
|
1163
|
-
this.openToolCalls.set(item.id, { toolName
|
|
1139
|
+
this.openToolCalls.set(item.id, { toolName });
|
|
1164
1140
|
parts.push(this.withMeta({
|
|
1165
1141
|
type: "tool-call",
|
|
1166
1142
|
toolCallId: item.id,
|
|
@@ -1171,9 +1147,22 @@ ${output}`;
|
|
|
1171
1147
|
}));
|
|
1172
1148
|
break;
|
|
1173
1149
|
}
|
|
1150
|
+
case "mcpToolCall": {
|
|
1151
|
+
this.ensureStreamStarted(parts);
|
|
1152
|
+
const toolName = `mcp:${item.server}/${item.tool}`;
|
|
1153
|
+
this.openToolCalls.set(item.id, { toolName });
|
|
1154
|
+
parts.push(this.withMeta({
|
|
1155
|
+
type: "tool-call",
|
|
1156
|
+
toolCallId: item.id,
|
|
1157
|
+
toolName,
|
|
1158
|
+
input: JSON.stringify(item.arguments ?? {}),
|
|
1159
|
+
providerExecuted: true,
|
|
1160
|
+
dynamic: true
|
|
1161
|
+
}));
|
|
1162
|
+
break;
|
|
1163
|
+
}
|
|
1174
1164
|
case "reasoning":
|
|
1175
1165
|
case "plan":
|
|
1176
|
-
case "mcpToolCall":
|
|
1177
1166
|
case "collabAgentToolCall":
|
|
1178
1167
|
case "imageView":
|
|
1179
1168
|
case "contextCompaction":
|
|
@@ -1222,64 +1211,13 @@ ${output}`;
|
|
|
1222
1211
|
parts.push(this.withMeta({ type: "text-end", id: item.id }));
|
|
1223
1212
|
this.openTextParts.delete(item.id);
|
|
1224
1213
|
}
|
|
1225
|
-
} else if (item.type
|
|
1214
|
+
} else if (NATIVE_TOOL_RESULT_TYPES.has(item.type) && this.openToolCalls.has(item.id)) {
|
|
1226
1215
|
const tracked = this.openToolCalls.get(item.id);
|
|
1227
|
-
const outputSource = item.aggregatedOutput ?? tracked.output;
|
|
1228
|
-
const limitedOutput = this.applyOutputLimit(outputSource);
|
|
1229
|
-
const output = this.formatToolOutput(
|
|
1230
|
-
limitedOutput.output,
|
|
1231
|
-
item.aggregatedOutput !== void 0 && item.aggregatedOutput !== null ? limitedOutput.droppedChars : tracked.droppedChars
|
|
1232
|
-
);
|
|
1233
|
-
const exitCode = item.exitCode;
|
|
1234
|
-
const status = item.status;
|
|
1235
1216
|
parts.push(this.withMeta({
|
|
1236
1217
|
type: "tool-result",
|
|
1237
1218
|
toolCallId: item.id,
|
|
1238
1219
|
toolName: tracked.toolName,
|
|
1239
|
-
result: {
|
|
1240
|
-
}));
|
|
1241
|
-
this.openToolCalls.delete(item.id);
|
|
1242
|
-
} else if (item.type === "dynamicToolCall") {
|
|
1243
|
-
const dynamic = item;
|
|
1244
|
-
const tracked = this.openToolCalls.get(item.id);
|
|
1245
|
-
const toolName = tracked?.toolName ?? dynamic.tool ?? "dynamic_tool_call";
|
|
1246
|
-
const rawOutput = this.stringifyDynamicToolResult(dynamic);
|
|
1247
|
-
const limitedOutput = this.applyOutputLimit(rawOutput);
|
|
1248
|
-
parts.push(this.withMeta({
|
|
1249
|
-
type: "tool-result",
|
|
1250
|
-
toolCallId: item.id,
|
|
1251
|
-
toolName,
|
|
1252
|
-
result: {
|
|
1253
|
-
output: this.formatToolOutput(limitedOutput.output, limitedOutput.droppedChars),
|
|
1254
|
-
success: dynamic.success ?? void 0
|
|
1255
|
-
}
|
|
1256
|
-
}));
|
|
1257
|
-
this.openToolCalls.delete(item.id);
|
|
1258
|
-
} else if (item.type === "fileChange" && this.openToolCalls.has(item.id)) {
|
|
1259
|
-
const tracked = this.openToolCalls.get(item.id);
|
|
1260
|
-
const toolName = tracked?.toolName ?? "codex_file_change";
|
|
1261
|
-
const output = tracked ? this.formatToolOutput(tracked.output, tracked.droppedChars) : "";
|
|
1262
|
-
parts.push(this.withMeta({
|
|
1263
|
-
type: "tool-result",
|
|
1264
|
-
toolCallId: item.id,
|
|
1265
|
-
toolName,
|
|
1266
|
-
result: { output, status: item.status, changes: item.changes }
|
|
1267
|
-
}));
|
|
1268
|
-
this.openToolCalls.delete(item.id);
|
|
1269
|
-
} else if (item.type === "webSearch" && this.openToolCalls.has(item.id)) {
|
|
1270
|
-
const webSearchSummary = this.formatWebSearchItemSummary(item);
|
|
1271
|
-
const tracked = this.openToolCalls.get(item.id);
|
|
1272
|
-
const toolName = tracked?.toolName ?? "codex_web_search";
|
|
1273
|
-
parts.push(this.withMeta({
|
|
1274
|
-
type: "tool-result",
|
|
1275
|
-
toolCallId: item.id,
|
|
1276
|
-
toolName,
|
|
1277
|
-
result: {
|
|
1278
|
-
output: webSearchSummary || "",
|
|
1279
|
-
query: item.query,
|
|
1280
|
-
action: item.action ?? void 0,
|
|
1281
|
-
summary: webSearchSummary || void 0
|
|
1282
|
-
}
|
|
1220
|
+
result: { item }
|
|
1283
1221
|
}));
|
|
1284
1222
|
this.openToolCalls.delete(item.id);
|
|
1285
1223
|
} else if (this.openReasoningParts.has(item.id)) {
|
|
@@ -1298,22 +1236,6 @@ ${output}`;
|
|
|
1298
1236
|
this.emitReasoningDelta(parts, delta.itemId, delta.delta);
|
|
1299
1237
|
return parts;
|
|
1300
1238
|
}
|
|
1301
|
-
// item/fileChange/outputDelta
|
|
1302
|
-
handleFileChangeOutputDelta(params) {
|
|
1303
|
-
const delta = params ?? {};
|
|
1304
|
-
if (!delta.itemId || !delta.delta || !this.openToolCalls.has(delta.itemId)) {
|
|
1305
|
-
return [];
|
|
1306
|
-
}
|
|
1307
|
-
const tracked = this.openToolCalls.get(delta.itemId);
|
|
1308
|
-
this.appendTrackedOutput(tracked, delta.delta);
|
|
1309
|
-
return [this.withMeta({
|
|
1310
|
-
type: "tool-result",
|
|
1311
|
-
toolCallId: delta.itemId,
|
|
1312
|
-
toolName: tracked.toolName,
|
|
1313
|
-
result: { output: this.formatToolOutput(tracked.output, tracked.droppedChars) },
|
|
1314
|
-
preliminary: true
|
|
1315
|
-
})];
|
|
1316
|
-
}
|
|
1317
1239
|
// item/reasoning/summaryPartAdded
|
|
1318
1240
|
handleSummaryPartAdded(params) {
|
|
1319
1241
|
const p = params ?? {};
|
|
@@ -1356,74 +1278,24 @@ ${output}`;
|
|
|
1356
1278
|
}));
|
|
1357
1279
|
return parts;
|
|
1358
1280
|
}
|
|
1359
|
-
// item/
|
|
1360
|
-
|
|
1361
|
-
const delta = params ?? {};
|
|
1362
|
-
if (!delta.itemId || !delta.delta || !this.openToolCalls.has(delta.itemId)) {
|
|
1363
|
-
return [];
|
|
1364
|
-
}
|
|
1365
|
-
const tracked = this.openToolCalls.get(delta.itemId);
|
|
1366
|
-
this.appendTrackedOutput(tracked, delta.delta);
|
|
1367
|
-
return [this.withMeta({
|
|
1368
|
-
type: "tool-result",
|
|
1369
|
-
toolCallId: delta.itemId,
|
|
1370
|
-
toolName: tracked.toolName,
|
|
1371
|
-
result: { output: this.formatToolOutput(tracked.output, tracked.droppedChars) },
|
|
1372
|
-
preliminary: true
|
|
1373
|
-
})];
|
|
1374
|
-
}
|
|
1375
|
-
// codex/event/mcp_tool_call_begin
|
|
1376
|
-
handleMcpToolCallBegin(params) {
|
|
1281
|
+
// item/mcpToolCall/progress
|
|
1282
|
+
handleMcpToolCallProgress(params) {
|
|
1377
1283
|
const p = params ?? {};
|
|
1378
|
-
|
|
1379
|
-
const inv = p.msg?.invocation;
|
|
1380
|
-
if (!callId || !inv) {
|
|
1284
|
+
if (!p.itemId || !p.message) {
|
|
1381
1285
|
return [];
|
|
1382
1286
|
}
|
|
1383
|
-
const
|
|
1384
|
-
|
|
1385
|
-
const toolName = `mcp:${inv.server}/${inv.tool}`;
|
|
1386
|
-
this.openToolCalls.set(callId, { toolName, output: "", droppedChars: 0 });
|
|
1387
|
-
parts.push(this.withMeta({
|
|
1388
|
-
type: "tool-call",
|
|
1389
|
-
toolCallId: callId,
|
|
1390
|
-
toolName,
|
|
1391
|
-
input: JSON.stringify(inv.arguments ?? {}),
|
|
1392
|
-
providerExecuted: true,
|
|
1393
|
-
dynamic: true
|
|
1394
|
-
}));
|
|
1395
|
-
return parts;
|
|
1396
|
-
}
|
|
1397
|
-
// codex/event/mcp_tool_call_end
|
|
1398
|
-
handleMcpToolCallEnd(params) {
|
|
1399
|
-
const p = params ?? {};
|
|
1400
|
-
const callId = p.msg?.call_id;
|
|
1401
|
-
if (!callId || !this.openToolCalls.has(callId)) {
|
|
1287
|
+
const tracked = this.openToolCalls.get(p.itemId);
|
|
1288
|
+
if (!tracked) {
|
|
1402
1289
|
return [];
|
|
1403
1290
|
}
|
|
1404
|
-
const tracked = this.openToolCalls.get(callId);
|
|
1405
|
-
const result = p.msg?.result;
|
|
1406
|
-
const textParts = result?.Ok?.content?.filter((c) => c.type === "text").map((c) => c.text) ?? [];
|
|
1407
|
-
const rawOutput = textParts.join("\n") || (result?.Err ? JSON.stringify(result.Err) : "");
|
|
1408
|
-
const limitedOutput = this.applyOutputLimit(rawOutput);
|
|
1409
|
-
this.openToolCalls.delete(callId);
|
|
1410
1291
|
return [this.withMeta({
|
|
1411
1292
|
type: "tool-result",
|
|
1412
|
-
toolCallId:
|
|
1293
|
+
toolCallId: p.itemId,
|
|
1413
1294
|
toolName: tracked.toolName,
|
|
1414
|
-
result: { output:
|
|
1295
|
+
result: { output: p.message },
|
|
1296
|
+
preliminary: true
|
|
1415
1297
|
})];
|
|
1416
1298
|
}
|
|
1417
|
-
// item/mcpToolCall/progress
|
|
1418
|
-
handleMcpToolCallProgress(params) {
|
|
1419
|
-
const p = params ?? {};
|
|
1420
|
-
if (!p.itemId || !p.message) {
|
|
1421
|
-
return [];
|
|
1422
|
-
}
|
|
1423
|
-
const parts = [];
|
|
1424
|
-
this.emitReasoningDelta(parts, p.itemId, p.message);
|
|
1425
|
-
return parts;
|
|
1426
|
-
}
|
|
1427
1299
|
// item/tool/callStarted
|
|
1428
1300
|
handleToolCallStarted(params) {
|
|
1429
1301
|
const p = params ?? {};
|
|
@@ -1472,7 +1344,7 @@ ${output}`;
|
|
|
1472
1344
|
}
|
|
1473
1345
|
const parts = [];
|
|
1474
1346
|
this.ensureStreamStarted(parts);
|
|
1475
|
-
this.openToolCalls.set(item.id, { toolName: item.tool
|
|
1347
|
+
this.openToolCalls.set(item.id, { toolName: item.tool });
|
|
1476
1348
|
parts.push(this.withMeta({
|
|
1477
1349
|
type: "tool-call",
|
|
1478
1350
|
toolCallId: item.id,
|
|
@@ -1483,50 +1355,6 @@ ${output}`;
|
|
|
1483
1355
|
}));
|
|
1484
1356
|
return parts;
|
|
1485
1357
|
}
|
|
1486
|
-
stringifyDynamicToolResult(item) {
|
|
1487
|
-
const contentItems = item.contentItems ?? [];
|
|
1488
|
-
if (!contentItems.length) {
|
|
1489
|
-
return "";
|
|
1490
|
-
}
|
|
1491
|
-
const chunks = [];
|
|
1492
|
-
for (const contentItem of contentItems) {
|
|
1493
|
-
if (contentItem.type === "inputText" && contentItem.text) {
|
|
1494
|
-
chunks.push(contentItem.text);
|
|
1495
|
-
continue;
|
|
1496
|
-
}
|
|
1497
|
-
if (contentItem.type === "inputImage" && contentItem.imageUrl) {
|
|
1498
|
-
chunks.push(`[image] ${contentItem.imageUrl}`);
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
return chunks.join("\n");
|
|
1502
|
-
}
|
|
1503
|
-
formatWebSearchItemSummary(item) {
|
|
1504
|
-
const query = item.query?.trim();
|
|
1505
|
-
const actionType = item.action?.type;
|
|
1506
|
-
if (actionType === "search") {
|
|
1507
|
-
if (query) {
|
|
1508
|
-
return `Web search: ${query}`;
|
|
1509
|
-
}
|
|
1510
|
-
const actionQuery = item.action?.query?.trim();
|
|
1511
|
-
return actionQuery ? `Web search: ${actionQuery}` : "Web search";
|
|
1512
|
-
}
|
|
1513
|
-
if (actionType === "openPage" || actionType === "open_page") {
|
|
1514
|
-
const url = item.action?.url?.trim();
|
|
1515
|
-
return url ? `Open page: ${url}` : "Open page";
|
|
1516
|
-
}
|
|
1517
|
-
if (actionType === "findInPage" || actionType === "find_in_page") {
|
|
1518
|
-
const pattern = item.action?.pattern?.trim();
|
|
1519
|
-
const url = item.action?.url?.trim();
|
|
1520
|
-
if (pattern && url) {
|
|
1521
|
-
return `Find in page: "${pattern}" (${url})`;
|
|
1522
|
-
}
|
|
1523
|
-
if (pattern) {
|
|
1524
|
-
return `Find in page: "${pattern}"`;
|
|
1525
|
-
}
|
|
1526
|
-
return url ? `Find in page: ${url}` : "Find in page";
|
|
1527
|
-
}
|
|
1528
|
-
return query ? `Web search: ${query}` : "";
|
|
1529
|
-
}
|
|
1530
1358
|
// thread/tokenUsage/updated
|
|
1531
1359
|
handleTokenUsageUpdated(params) {
|
|
1532
1360
|
const p = params ?? {};
|
|
@@ -1565,7 +1393,8 @@ ${output}`;
|
|
|
1565
1393
|
type: "tool-result",
|
|
1566
1394
|
toolCallId: itemId,
|
|
1567
1395
|
toolName: tracked.toolName,
|
|
1568
|
-
result: {
|
|
1396
|
+
result: { error: "Tool call did not complete before turn ended" },
|
|
1397
|
+
isError: true
|
|
1569
1398
|
}));
|
|
1570
1399
|
}
|
|
1571
1400
|
this.openToolCalls.clear();
|
|
@@ -2073,6 +1902,7 @@ var CodexLanguageModel = class {
|
|
|
2073
1902
|
}
|
|
2074
1903
|
doStream(options) {
|
|
2075
1904
|
const resumeThreadId = extractResumeThreadId(options.prompt);
|
|
1905
|
+
const callOptions = options.providerOptions?.[CODEX_PROVIDER_ID];
|
|
2076
1906
|
const transport = this.config.providerSettings.transportFactory ? this.config.providerSettings.transportFactory(stripUndefined({ signal: options.abortSignal, threadId: resumeThreadId })) : this.config.providerSettings.transport?.type === "websocket" ? new WebSocketTransport(this.config.providerSettings.transport.websocket) : new StdioTransport(this.config.providerSettings.transport?.stdio);
|
|
2077
1907
|
const packetLogger = this.config.providerSettings.debug?.logPackets === true ? this.config.providerSettings.debug.logger ?? ((packet) => {
|
|
2078
1908
|
if (packet.direction === "inbound") {
|
|
@@ -2089,8 +1919,7 @@ var CodexLanguageModel = class {
|
|
|
2089
1919
|
onPacket: packetLogger
|
|
2090
1920
|
}));
|
|
2091
1921
|
const mapper = new CodexEventMapper(stripUndefined({
|
|
2092
|
-
emitPlanUpdates: this.config.providerSettings.emitPlanUpdates
|
|
2093
|
-
maxToolResultOutputChars: this.config.providerSettings.maxToolResultOutputChars
|
|
1922
|
+
emitPlanUpdates: this.config.providerSettings.emitPlanUpdates
|
|
2094
1923
|
}));
|
|
2095
1924
|
let activeThreadId;
|
|
2096
1925
|
let activeTurnId;
|
|
@@ -2284,7 +2113,11 @@ var CodexLanguageModel = class {
|
|
|
2284
2113
|
const resumeParams = stripUndefined({
|
|
2285
2114
|
threadId: resumeThreadId,
|
|
2286
2115
|
persistExtendedHistory: false,
|
|
2287
|
-
developerInstructions
|
|
2116
|
+
developerInstructions,
|
|
2117
|
+
cwd: callOptions?.cwd ?? this.config.providerSettings.defaultThreadSettings?.cwd,
|
|
2118
|
+
approvalPolicy: callOptions?.approvalPolicy ?? this.config.providerSettings.defaultThreadSettings?.approvalPolicy,
|
|
2119
|
+
sandbox: callOptions?.sandbox ?? this.config.providerSettings.defaultThreadSettings?.sandbox,
|
|
2120
|
+
model: callOptions?.model ?? this.config.providerSettings.defaultModel
|
|
2288
2121
|
});
|
|
2289
2122
|
debugLog?.("outbound", "thread/resume", resumeParams);
|
|
2290
2123
|
const resumeResult = await client.request(
|
|
@@ -2344,9 +2177,9 @@ var CodexLanguageModel = class {
|
|
|
2344
2177
|
dynamicTools,
|
|
2345
2178
|
developerInstructions,
|
|
2346
2179
|
config,
|
|
2347
|
-
cwd: this.config.providerSettings.defaultThreadSettings?.cwd,
|
|
2348
|
-
approvalPolicy: this.config.providerSettings.defaultThreadSettings?.approvalPolicy,
|
|
2349
|
-
sandbox: this.config.providerSettings.defaultThreadSettings?.sandbox
|
|
2180
|
+
cwd: callOptions?.cwd ?? this.config.providerSettings.defaultThreadSettings?.cwd,
|
|
2181
|
+
approvalPolicy: callOptions?.approvalPolicy ?? this.config.providerSettings.defaultThreadSettings?.approvalPolicy,
|
|
2182
|
+
sandbox: callOptions?.sandbox ?? this.config.providerSettings.defaultThreadSettings?.sandbox
|
|
2350
2183
|
});
|
|
2351
2184
|
debugLog?.("outbound", "thread/start", threadStartParams);
|
|
2352
2185
|
const threadStartResult = await client.request(
|
|
@@ -2370,12 +2203,12 @@ var CodexLanguageModel = class {
|
|
|
2370
2203
|
const turnStartParams = stripUndefined({
|
|
2371
2204
|
threadId,
|
|
2372
2205
|
input: turnInput,
|
|
2373
|
-
cwd: this.config.providerSettings.defaultTurnSettings?.cwd,
|
|
2374
|
-
approvalPolicy: this.config.providerSettings.defaultTurnSettings?.approvalPolicy,
|
|
2375
|
-
sandboxPolicy: this.config.providerSettings.defaultTurnSettings?.sandboxPolicy,
|
|
2376
|
-
model: this.config.providerSettings.defaultTurnSettings?.model,
|
|
2377
|
-
effort: this.config.providerSettings.defaultTurnSettings?.effort,
|
|
2378
|
-
summary: this.config.providerSettings.defaultTurnSettings?.summary,
|
|
2206
|
+
cwd: callOptions?.cwd ?? this.config.providerSettings.defaultTurnSettings?.cwd,
|
|
2207
|
+
approvalPolicy: callOptions?.approvalPolicy ?? this.config.providerSettings.defaultTurnSettings?.approvalPolicy,
|
|
2208
|
+
sandboxPolicy: callOptions?.sandboxPolicy ?? this.config.providerSettings.defaultTurnSettings?.sandboxPolicy,
|
|
2209
|
+
model: callOptions?.model ?? this.config.providerSettings.defaultTurnSettings?.model,
|
|
2210
|
+
effort: callOptions?.effort ?? this.config.providerSettings.defaultTurnSettings?.effort,
|
|
2211
|
+
summary: callOptions?.summary ?? this.config.providerSettings.defaultTurnSettings?.summary,
|
|
2379
2212
|
outputSchema: options.responseFormat?.type === "json" ? options.responseFormat.schema : void 0
|
|
2380
2213
|
});
|
|
2381
2214
|
debugLog?.("outbound", "turn/start", turnStartParams);
|
|
@@ -2543,7 +2376,6 @@ function createCodexAppServer(settings = {}) {
|
|
|
2543
2376
|
approvals: settings.approvals ? { ...settings.approvals } : void 0,
|
|
2544
2377
|
debug: settings.debug ? { ...settings.debug } : void 0,
|
|
2545
2378
|
emitPlanUpdates: settings.emitPlanUpdates,
|
|
2546
|
-
maxToolResultOutputChars: settings.maxToolResultOutputChars,
|
|
2547
2379
|
onSessionCreated: settings.onSessionCreated
|
|
2548
2380
|
}));
|
|
2549
2381
|
const createLanguageModel = (modelId, modelSettings = {}) => new CodexLanguageModel(modelId, modelSettings, {
|
|
@@ -2628,6 +2460,7 @@ exports.PromptFileResolver = PromptFileResolver;
|
|
|
2628
2460
|
exports.StdioTransport = StdioTransport;
|
|
2629
2461
|
exports.WebSocketTransport = WebSocketTransport;
|
|
2630
2462
|
exports.codexAppServer = codexAppServer;
|
|
2463
|
+
exports.codexCallOptions = codexCallOptions;
|
|
2631
2464
|
exports.codexProviderMetadata = codexProviderMetadata;
|
|
2632
2465
|
exports.createCodexAppServer = createCodexAppServer;
|
|
2633
2466
|
exports.createCodexProvider = createCodexProvider;
|