@janole/ai-sdk-provider-codex-asp 0.3.6 → 0.4.0

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 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.3.6"};
938
+ version: "0.4.0"};
939
939
 
940
940
  // src/package-info.ts
941
941
  var PACKAGE_NAME = package_default.name;
@@ -955,6 +955,7 @@ function withProviderMetadata(part, threadId, turnId) {
955
955
  }
956
956
 
957
957
  // src/protocol/event-mapper.ts
958
+ var NATIVE_TOOL_RESULT_TYPES = /* @__PURE__ */ new Set(["commandExecution", "dynamicToolCall", "fileChange", "mcpToolCall", "webSearch"]);
958
959
  var EMPTY_USAGE = {
959
960
  inputTokens: {
960
961
  total: void 0,
@@ -981,7 +982,6 @@ function toFinishReason(status) {
981
982
  }
982
983
  }
983
984
  var NOOP = () => [];
984
- var DEFAULT_MAX_TOOL_RESULT_OUTPUT_CHARS = 32768;
985
985
  var CodexEventMapper = class {
986
986
  options;
987
987
  streamStarted = false;
@@ -996,8 +996,7 @@ var CodexEventMapper = class {
996
996
  handlers;
997
997
  constructor(options) {
998
998
  this.options = {
999
- emitPlanUpdates: options?.emitPlanUpdates ?? true,
1000
- maxToolResultOutputChars: options?.maxToolResultOutputChars ?? DEFAULT_MAX_TOOL_RESULT_OUTPUT_CHARS
999
+ emitPlanUpdates: options?.emitPlanUpdates ?? true
1001
1000
  };
1002
1001
  this.handlers = {
1003
1002
  "turn/started": (p) => this.handleTurnStarted(p),
@@ -1007,12 +1006,8 @@ var CodexEventMapper = class {
1007
1006
  "item/reasoning/textDelta": (p) => this.handleReasoningDelta(p),
1008
1007
  "item/reasoning/summaryTextDelta": (p) => this.handleReasoningDelta(p),
1009
1008
  "item/plan/delta": (p) => this.handleReasoningDelta(p),
1010
- "item/fileChange/outputDelta": (p) => this.handleFileChangeOutputDelta(p),
1011
1009
  "item/reasoning/summaryPartAdded": (p) => this.handleSummaryPartAdded(p),
1012
1010
  "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
1011
  "item/mcpToolCall/progress": (p) => this.handleMcpToolCallProgress(p),
1017
1012
  "item/tool/callStarted": (p) => this.handleToolCallStarted(p),
1018
1013
  "item/tool/callDelta": (p) => this.handleToolCallDelta(p),
@@ -1024,10 +1019,15 @@ var CodexEventMapper = class {
1024
1019
  "codex/event/agent_reasoning": NOOP,
1025
1020
  "codex/event/agent_reasoning_section_break": NOOP,
1026
1021
  "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.
1022
+ // Intentionally ignored: web search and MCP wrappers mirror item events.
1029
1023
  "codex/event/web_search_begin": NOOP,
1030
1024
  "codex/event/web_search_end": NOOP,
1025
+ "codex/event/mcp_tool_call_begin": NOOP,
1026
+ "codex/event/mcp_tool_call_end": NOOP,
1027
+ // Intentionally ignored: streaming output deltas — the full output arrives
1028
+ // in item/completed (aggregatedOutput), making these redundant.
1029
+ "item/commandExecution/outputDelta": NOOP,
1030
+ "item/fileChange/outputDelta": NOOP,
1031
1031
  // Intentionally ignored: full diffs (often 50-100 KB) crash/freeze frontend renderers.
1032
1032
  // If these need to surface, they should use a dedicated part type with lazy rendering.
1033
1033
  "turn/diff/updated": NOOP,
@@ -1072,33 +1072,6 @@ var CodexEventMapper = class {
1072
1072
  this.planSequenceByTurnId.set(turnId, next);
1073
1073
  return next;
1074
1074
  }
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
1075
  // ── Handlers ─────────────────────────────────────────────────────────────
1103
1076
  // turn/started
1104
1077
  handleTurnStarted(params) {
@@ -1128,7 +1101,7 @@ ${output}`;
1128
1101
  case "commandExecution": {
1129
1102
  this.ensureStreamStarted(parts);
1130
1103
  const toolName = "codex_command_execution";
1131
- this.openToolCalls.set(item.id, { toolName, output: "", droppedChars: 0 });
1104
+ this.openToolCalls.set(item.id, { toolName });
1132
1105
  parts.push(this.withMeta({
1133
1106
  type: "tool-call",
1134
1107
  toolCallId: item.id,
@@ -1146,7 +1119,7 @@ ${output}`;
1146
1119
  case "fileChange": {
1147
1120
  this.ensureStreamStarted(parts);
1148
1121
  const toolName = "codex_file_change";
1149
- this.openToolCalls.set(item.id, { toolName, output: "", droppedChars: 0 });
1122
+ this.openToolCalls.set(item.id, { toolName });
1150
1123
  parts.push(this.withMeta({
1151
1124
  type: "tool-call",
1152
1125
  toolCallId: item.id,
@@ -1160,7 +1133,7 @@ ${output}`;
1160
1133
  case "webSearch": {
1161
1134
  this.ensureStreamStarted(parts);
1162
1135
  const toolName = "codex_web_search";
1163
- this.openToolCalls.set(item.id, { toolName, output: "", droppedChars: 0 });
1136
+ this.openToolCalls.set(item.id, { toolName });
1164
1137
  parts.push(this.withMeta({
1165
1138
  type: "tool-call",
1166
1139
  toolCallId: item.id,
@@ -1171,9 +1144,22 @@ ${output}`;
1171
1144
  }));
1172
1145
  break;
1173
1146
  }
1147
+ case "mcpToolCall": {
1148
+ this.ensureStreamStarted(parts);
1149
+ const toolName = `mcp:${item.server}/${item.tool}`;
1150
+ this.openToolCalls.set(item.id, { toolName });
1151
+ parts.push(this.withMeta({
1152
+ type: "tool-call",
1153
+ toolCallId: item.id,
1154
+ toolName,
1155
+ input: JSON.stringify(item.arguments ?? {}),
1156
+ providerExecuted: true,
1157
+ dynamic: true
1158
+ }));
1159
+ break;
1160
+ }
1174
1161
  case "reasoning":
1175
1162
  case "plan":
1176
- case "mcpToolCall":
1177
1163
  case "collabAgentToolCall":
1178
1164
  case "imageView":
1179
1165
  case "contextCompaction":
@@ -1222,64 +1208,13 @@ ${output}`;
1222
1208
  parts.push(this.withMeta({ type: "text-end", id: item.id }));
1223
1209
  this.openTextParts.delete(item.id);
1224
1210
  }
1225
- } else if (item.type === "commandExecution" && this.openToolCalls.has(item.id)) {
1211
+ } else if (NATIVE_TOOL_RESULT_TYPES.has(item.type) && this.openToolCalls.has(item.id)) {
1226
1212
  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
1213
  parts.push(this.withMeta({
1236
1214
  type: "tool-result",
1237
1215
  toolCallId: item.id,
1238
1216
  toolName: tracked.toolName,
1239
- result: { output, exitCode, status }
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
- }
1217
+ result: { item }
1283
1218
  }));
1284
1219
  this.openToolCalls.delete(item.id);
1285
1220
  } else if (this.openReasoningParts.has(item.id)) {
@@ -1298,22 +1233,6 @@ ${output}`;
1298
1233
  this.emitReasoningDelta(parts, delta.itemId, delta.delta);
1299
1234
  return parts;
1300
1235
  }
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
1236
  // item/reasoning/summaryPartAdded
1318
1237
  handleSummaryPartAdded(params) {
1319
1238
  const p = params ?? {};
@@ -1356,74 +1275,24 @@ ${output}`;
1356
1275
  }));
1357
1276
  return parts;
1358
1277
  }
1359
- // item/commandExecution/outputDelta
1360
- handleCommandOutputDelta(params) {
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) {
1278
+ // item/mcpToolCall/progress
1279
+ handleMcpToolCallProgress(params) {
1377
1280
  const p = params ?? {};
1378
- const callId = p.msg?.call_id;
1379
- const inv = p.msg?.invocation;
1380
- if (!callId || !inv) {
1281
+ if (!p.itemId || !p.message) {
1381
1282
  return [];
1382
1283
  }
1383
- const parts = [];
1384
- this.ensureStreamStarted(parts);
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)) {
1284
+ const tracked = this.openToolCalls.get(p.itemId);
1285
+ if (!tracked) {
1402
1286
  return [];
1403
1287
  }
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
1288
  return [this.withMeta({
1411
1289
  type: "tool-result",
1412
- toolCallId: callId,
1290
+ toolCallId: p.itemId,
1413
1291
  toolName: tracked.toolName,
1414
- result: { output: this.formatToolOutput(limitedOutput.output, limitedOutput.droppedChars) }
1292
+ result: { output: p.message },
1293
+ preliminary: true
1415
1294
  })];
1416
1295
  }
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
1296
  // item/tool/callStarted
1428
1297
  handleToolCallStarted(params) {
1429
1298
  const p = params ?? {};
@@ -1472,7 +1341,7 @@ ${output}`;
1472
1341
  }
1473
1342
  const parts = [];
1474
1343
  this.ensureStreamStarted(parts);
1475
- this.openToolCalls.set(item.id, { toolName: item.tool, output: "", droppedChars: 0 });
1344
+ this.openToolCalls.set(item.id, { toolName: item.tool });
1476
1345
  parts.push(this.withMeta({
1477
1346
  type: "tool-call",
1478
1347
  toolCallId: item.id,
@@ -1483,50 +1352,6 @@ ${output}`;
1483
1352
  }));
1484
1353
  return parts;
1485
1354
  }
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
1355
  // thread/tokenUsage/updated
1531
1356
  handleTokenUsageUpdated(params) {
1532
1357
  const p = params ?? {};
@@ -1565,7 +1390,8 @@ ${output}`;
1565
1390
  type: "tool-result",
1566
1391
  toolCallId: itemId,
1567
1392
  toolName: tracked.toolName,
1568
- result: { output: this.formatToolOutput(tracked.output, tracked.droppedChars) }
1393
+ result: { error: "Tool call did not complete before turn ended" },
1394
+ isError: true
1569
1395
  }));
1570
1396
  }
1571
1397
  this.openToolCalls.clear();
@@ -2089,8 +1915,7 @@ var CodexLanguageModel = class {
2089
1915
  onPacket: packetLogger
2090
1916
  }));
2091
1917
  const mapper = new CodexEventMapper(stripUndefined({
2092
- emitPlanUpdates: this.config.providerSettings.emitPlanUpdates,
2093
- maxToolResultOutputChars: this.config.providerSettings.maxToolResultOutputChars
1918
+ emitPlanUpdates: this.config.providerSettings.emitPlanUpdates
2094
1919
  }));
2095
1920
  let activeThreadId;
2096
1921
  let activeTurnId;
@@ -2543,7 +2368,6 @@ function createCodexAppServer(settings = {}) {
2543
2368
  approvals: settings.approvals ? { ...settings.approvals } : void 0,
2544
2369
  debug: settings.debug ? { ...settings.debug } : void 0,
2545
2370
  emitPlanUpdates: settings.emitPlanUpdates,
2546
- maxToolResultOutputChars: settings.maxToolResultOutputChars,
2547
2371
  onSessionCreated: settings.onSessionCreated
2548
2372
  }));
2549
2373
  const createLanguageModel = (modelId, modelSettings = {}) => new CodexLanguageModel(modelId, modelSettings, {