@janole/ai-sdk-provider-codex-asp 0.3.5 → 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.5"};
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.handleReasoningDelta(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,
@@ -1143,12 +1116,51 @@ ${output}`;
1143
1116
  parts.push(...this.startDynamicToolCall(item));
1144
1117
  break;
1145
1118
  }
1119
+ case "fileChange": {
1120
+ this.ensureStreamStarted(parts);
1121
+ const toolName = "codex_file_change";
1122
+ this.openToolCalls.set(item.id, { toolName });
1123
+ parts.push(this.withMeta({
1124
+ type: "tool-call",
1125
+ toolCallId: item.id,
1126
+ toolName,
1127
+ input: JSON.stringify({ changes: item.changes, status: item.status }),
1128
+ providerExecuted: true,
1129
+ dynamic: true
1130
+ }));
1131
+ break;
1132
+ }
1133
+ case "webSearch": {
1134
+ this.ensureStreamStarted(parts);
1135
+ const toolName = "codex_web_search";
1136
+ this.openToolCalls.set(item.id, { toolName });
1137
+ parts.push(this.withMeta({
1138
+ type: "tool-call",
1139
+ toolCallId: item.id,
1140
+ toolName,
1141
+ input: JSON.stringify({ query: item.query, action: item.action ?? void 0 }),
1142
+ providerExecuted: true,
1143
+ dynamic: true
1144
+ }));
1145
+ break;
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
+ }
1146
1161
  case "reasoning":
1147
1162
  case "plan":
1148
- case "fileChange":
1149
- case "mcpToolCall":
1150
1163
  case "collabAgentToolCall":
1151
- case "webSearch":
1152
1164
  case "imageView":
1153
1165
  case "contextCompaction":
1154
1166
  case "enteredReviewMode":
@@ -1196,55 +1208,22 @@ ${output}`;
1196
1208
  parts.push(this.withMeta({ type: "text-end", id: item.id }));
1197
1209
  this.openTextParts.delete(item.id);
1198
1210
  }
1199
- } 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)) {
1200
1212
  const tracked = this.openToolCalls.get(item.id);
1201
- const outputSource = item.aggregatedOutput ?? tracked.output;
1202
- const limitedOutput = this.applyOutputLimit(outputSource);
1203
- const output = this.formatToolOutput(
1204
- limitedOutput.output,
1205
- item.aggregatedOutput !== void 0 && item.aggregatedOutput !== null ? limitedOutput.droppedChars : tracked.droppedChars
1206
- );
1207
- const exitCode = item.exitCode;
1208
- const status = item.status;
1209
1213
  parts.push(this.withMeta({
1210
1214
  type: "tool-result",
1211
1215
  toolCallId: item.id,
1212
1216
  toolName: tracked.toolName,
1213
- result: { output, exitCode, status }
1214
- }));
1215
- this.openToolCalls.delete(item.id);
1216
- } else if (item.type === "dynamicToolCall") {
1217
- const dynamic = item;
1218
- const tracked = this.openToolCalls.get(item.id);
1219
- const toolName = tracked?.toolName ?? dynamic.tool ?? "dynamic_tool_call";
1220
- const rawOutput = this.stringifyDynamicToolResult(dynamic);
1221
- const limitedOutput = this.applyOutputLimit(rawOutput);
1222
- parts.push(this.withMeta({
1223
- type: "tool-result",
1224
- toolCallId: item.id,
1225
- toolName,
1226
- result: {
1227
- output: this.formatToolOutput(limitedOutput.output, limitedOutput.droppedChars),
1228
- success: dynamic.success ?? void 0
1229
- }
1217
+ result: { item }
1230
1218
  }));
1231
1219
  this.openToolCalls.delete(item.id);
1232
- } else if (item.type === "webSearch") {
1233
- const webSearchSummary = this.formatWebSearchItemSummary(item);
1234
- if (webSearchSummary) {
1235
- this.emitReasoningDelta(parts, item.id, webSearchSummary);
1236
- }
1237
- if (this.openReasoningParts.has(item.id)) {
1238
- parts.push(this.withMeta({ type: "reasoning-end", id: item.id }));
1239
- this.openReasoningParts.delete(item.id);
1240
- }
1241
1220
  } else if (this.openReasoningParts.has(item.id)) {
1242
1221
  parts.push(this.withMeta({ type: "reasoning-end", id: item.id }));
1243
1222
  this.openReasoningParts.delete(item.id);
1244
1223
  }
1245
1224
  return parts;
1246
1225
  }
1247
- // item/reasoning/textDelta, item/reasoning/summaryTextDelta, item/plan/delta, item/fileChange/outputDelta
1226
+ // item/reasoning/textDelta, item/reasoning/summaryTextDelta, item/plan/delta
1248
1227
  handleReasoningDelta(params) {
1249
1228
  const delta = params ?? {};
1250
1229
  if (!delta.itemId || !delta.delta) {
@@ -1296,74 +1275,24 @@ ${output}`;
1296
1275
  }));
1297
1276
  return parts;
1298
1277
  }
1299
- // item/commandExecution/outputDelta
1300
- handleCommandOutputDelta(params) {
1301
- const delta = params ?? {};
1302
- if (!delta.itemId || !delta.delta || !this.openToolCalls.has(delta.itemId)) {
1303
- return [];
1304
- }
1305
- const tracked = this.openToolCalls.get(delta.itemId);
1306
- this.appendTrackedOutput(tracked, delta.delta);
1307
- return [this.withMeta({
1308
- type: "tool-result",
1309
- toolCallId: delta.itemId,
1310
- toolName: tracked.toolName,
1311
- result: { output: this.formatToolOutput(tracked.output, tracked.droppedChars) },
1312
- preliminary: true
1313
- })];
1314
- }
1315
- // codex/event/mcp_tool_call_begin
1316
- handleMcpToolCallBegin(params) {
1278
+ // item/mcpToolCall/progress
1279
+ handleMcpToolCallProgress(params) {
1317
1280
  const p = params ?? {};
1318
- const callId = p.msg?.call_id;
1319
- const inv = p.msg?.invocation;
1320
- if (!callId || !inv) {
1281
+ if (!p.itemId || !p.message) {
1321
1282
  return [];
1322
1283
  }
1323
- const parts = [];
1324
- this.ensureStreamStarted(parts);
1325
- const toolName = `mcp:${inv.server}/${inv.tool}`;
1326
- this.openToolCalls.set(callId, { toolName, output: "", droppedChars: 0 });
1327
- parts.push(this.withMeta({
1328
- type: "tool-call",
1329
- toolCallId: callId,
1330
- toolName,
1331
- input: JSON.stringify(inv.arguments ?? {}),
1332
- providerExecuted: true,
1333
- dynamic: true
1334
- }));
1335
- return parts;
1336
- }
1337
- // codex/event/mcp_tool_call_end
1338
- handleMcpToolCallEnd(params) {
1339
- const p = params ?? {};
1340
- const callId = p.msg?.call_id;
1341
- if (!callId || !this.openToolCalls.has(callId)) {
1284
+ const tracked = this.openToolCalls.get(p.itemId);
1285
+ if (!tracked) {
1342
1286
  return [];
1343
1287
  }
1344
- const tracked = this.openToolCalls.get(callId);
1345
- const result = p.msg?.result;
1346
- const textParts = result?.Ok?.content?.filter((c) => c.type === "text").map((c) => c.text) ?? [];
1347
- const rawOutput = textParts.join("\n") || (result?.Err ? JSON.stringify(result.Err) : "");
1348
- const limitedOutput = this.applyOutputLimit(rawOutput);
1349
- this.openToolCalls.delete(callId);
1350
1288
  return [this.withMeta({
1351
1289
  type: "tool-result",
1352
- toolCallId: callId,
1290
+ toolCallId: p.itemId,
1353
1291
  toolName: tracked.toolName,
1354
- result: { output: this.formatToolOutput(limitedOutput.output, limitedOutput.droppedChars) }
1292
+ result: { output: p.message },
1293
+ preliminary: true
1355
1294
  })];
1356
1295
  }
1357
- // item/mcpToolCall/progress
1358
- handleMcpToolCallProgress(params) {
1359
- const p = params ?? {};
1360
- if (!p.itemId || !p.message) {
1361
- return [];
1362
- }
1363
- const parts = [];
1364
- this.emitReasoningDelta(parts, p.itemId, p.message);
1365
- return parts;
1366
- }
1367
1296
  // item/tool/callStarted
1368
1297
  handleToolCallStarted(params) {
1369
1298
  const p = params ?? {};
@@ -1412,7 +1341,7 @@ ${output}`;
1412
1341
  }
1413
1342
  const parts = [];
1414
1343
  this.ensureStreamStarted(parts);
1415
- this.openToolCalls.set(item.id, { toolName: item.tool, output: "", droppedChars: 0 });
1344
+ this.openToolCalls.set(item.id, { toolName: item.tool });
1416
1345
  parts.push(this.withMeta({
1417
1346
  type: "tool-call",
1418
1347
  toolCallId: item.id,
@@ -1423,50 +1352,6 @@ ${output}`;
1423
1352
  }));
1424
1353
  return parts;
1425
1354
  }
1426
- stringifyDynamicToolResult(item) {
1427
- const contentItems = item.contentItems ?? [];
1428
- if (!contentItems.length) {
1429
- return "";
1430
- }
1431
- const chunks = [];
1432
- for (const contentItem of contentItems) {
1433
- if (contentItem.type === "inputText" && contentItem.text) {
1434
- chunks.push(contentItem.text);
1435
- continue;
1436
- }
1437
- if (contentItem.type === "inputImage" && contentItem.imageUrl) {
1438
- chunks.push(`[image] ${contentItem.imageUrl}`);
1439
- }
1440
- }
1441
- return chunks.join("\n");
1442
- }
1443
- formatWebSearchItemSummary(item) {
1444
- const query = item.query?.trim();
1445
- const actionType = item.action?.type;
1446
- if (actionType === "search") {
1447
- if (query) {
1448
- return `Web search: ${query}`;
1449
- }
1450
- const actionQuery = item.action?.query?.trim();
1451
- return actionQuery ? `Web search: ${actionQuery}` : "Web search";
1452
- }
1453
- if (actionType === "openPage" || actionType === "open_page") {
1454
- const url = item.action?.url?.trim();
1455
- return url ? `Open page: ${url}` : "Open page";
1456
- }
1457
- if (actionType === "findInPage" || actionType === "find_in_page") {
1458
- const pattern = item.action?.pattern?.trim();
1459
- const url = item.action?.url?.trim();
1460
- if (pattern && url) {
1461
- return `Find in page: "${pattern}" (${url})`;
1462
- }
1463
- if (pattern) {
1464
- return `Find in page: "${pattern}"`;
1465
- }
1466
- return url ? `Find in page: ${url}` : "Find in page";
1467
- }
1468
- return query ? `Web search: ${query}` : "";
1469
- }
1470
1355
  // thread/tokenUsage/updated
1471
1356
  handleTokenUsageUpdated(params) {
1472
1357
  const p = params ?? {};
@@ -1505,7 +1390,8 @@ ${output}`;
1505
1390
  type: "tool-result",
1506
1391
  toolCallId: itemId,
1507
1392
  toolName: tracked.toolName,
1508
- result: { output: this.formatToolOutput(tracked.output, tracked.droppedChars) }
1393
+ result: { error: "Tool call did not complete before turn ended" },
1394
+ isError: true
1509
1395
  }));
1510
1396
  }
1511
1397
  this.openToolCalls.clear();
@@ -2029,8 +1915,7 @@ var CodexLanguageModel = class {
2029
1915
  onPacket: packetLogger
2030
1916
  }));
2031
1917
  const mapper = new CodexEventMapper(stripUndefined({
2032
- emitPlanUpdates: this.config.providerSettings.emitPlanUpdates,
2033
- maxToolResultOutputChars: this.config.providerSettings.maxToolResultOutputChars
1918
+ emitPlanUpdates: this.config.providerSettings.emitPlanUpdates
2034
1919
  }));
2035
1920
  let activeThreadId;
2036
1921
  let activeTurnId;
@@ -2483,7 +2368,6 @@ function createCodexAppServer(settings = {}) {
2483
2368
  approvals: settings.approvals ? { ...settings.approvals } : void 0,
2484
2369
  debug: settings.debug ? { ...settings.debug } : void 0,
2485
2370
  emitPlanUpdates: settings.emitPlanUpdates,
2486
- maxToolResultOutputChars: settings.maxToolResultOutputChars,
2487
2371
  onSessionCreated: settings.onSessionCreated
2488
2372
  }));
2489
2373
  const createLanguageModel = (modelId, modelSettings = {}) => new CodexLanguageModel(modelId, modelSettings, {