@janole/ai-sdk-provider-codex-asp 0.2.1 → 0.2.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/dist/index.d.cts CHANGED
@@ -1315,6 +1315,8 @@ interface CodexProviderSettings {
1315
1315
  scope?: "provider" | "global";
1316
1316
  key?: string;
1317
1317
  };
1318
+ /** Emit plan updates as tool-call/tool-result parts. Default: true. */
1319
+ emitPlanUpdates?: boolean;
1318
1320
  }
1319
1321
 
1320
1322
  interface CodexLanguageModelSettings {
@@ -1346,14 +1348,23 @@ interface CodexEventMapperInput {
1346
1348
  method: string;
1347
1349
  params?: unknown;
1348
1350
  }
1351
+ interface CodexEventMapperOptions {
1352
+ /** Emit plan updates as tool-call/tool-result parts. Default: true. */
1353
+ emitPlanUpdates?: boolean;
1354
+ }
1349
1355
  declare class CodexEventMapper {
1356
+ private readonly options;
1350
1357
  private streamStarted;
1351
1358
  private readonly openTextParts;
1359
+ private readonly textDeltaReceived;
1352
1360
  private readonly openReasoningParts;
1353
1361
  private readonly openToolCalls;
1362
+ private readonly planSequenceByTurnId;
1354
1363
  private threadId;
1355
1364
  private latestUsage;
1365
+ constructor(options?: CodexEventMapperOptions);
1356
1366
  setThreadId(threadId: string): void;
1367
+ private nextPlanSequence;
1357
1368
  map(event: CodexEventMapperInput): LanguageModelV3StreamPart[];
1358
1369
  }
1359
1370
 
@@ -1396,4 +1407,4 @@ declare const codexAppServer: CodexProvider;
1396
1407
  */
1397
1408
  declare const createCodexProvider: typeof createCodexAppServer;
1398
1409
 
1399
- export { type AgentMessageDeltaNotification, AppServerClient, type AppServerClientSettings, ApprovalsDispatcher, type ApprovalsDispatcherSettings, type AskForApproval, CODEX_PROVIDER_ID, type CodexCommandApprovalRequest, type CodexDynamicToolDefinition, CodexEventMapper, type CodexEventMapperInput, type CodexFileChangeApprovalRequest, type CodexInitializeParams, type CodexInitializeResult, type CodexInitializedNotification, CodexLanguageModel, type CodexLanguageModelSettings, type CodexModelConfig, CodexNotImplementedError, type CodexNotification, type CodexProvider, CodexProviderError, type CodexProviderSettings, type CodexThreadDefaults, type CodexThreadResumeParams, type CodexThreadResumeResult, type CodexThreadStartParams, type CodexThreadStartResult, type CodexToolCallDeltaNotification, type CodexToolCallFinishedNotification, type CodexToolCallRequestParams, type CodexToolCallResult, type CodexToolCallStartedNotification, type CodexToolResultContentItem, type CodexTransport, type CodexTransportEventMap, type CodexTurnInputImage, type CodexTurnInputItem, type CodexTurnInputLocalImage, type CodexTurnInputMention, type CodexTurnInputSkill, type CodexTurnInputText, type CodexTurnStartParams, type CodexTurnStartResult, CodexWorker, CodexWorkerPool, type CodexWorkerPoolSettings, type CodexWorkerSettings, type CommandApprovalHandler, type CommandExecutionApprovalDecision, type CommandExecutionRequestApprovalParams, type CommandExecutionRequestApprovalResponse, type DynamicToolDefinition, type DynamicToolExecutionContext, type DynamicToolHandler, DynamicToolsDispatcher, type DynamicToolsDispatcherSettings, type FileChangeApprovalDecision, type FileChangeApprovalHandler, type FileChangeRequestApprovalParams, type FileChangeRequestApprovalResponse, type ItemCompletedNotification, type ItemStartedNotification, JsonRpcError, type JsonRpcErrorResponse, type JsonRpcId, type JsonRpcMessage, type JsonRpcMessageBase, type JsonRpcNotification, type JsonRpcRequest, type JsonRpcResponse, type JsonRpcSuccessResponse, PACKAGE_NAME, PACKAGE_VERSION, type PendingToolCall, PersistentTransport, type PersistentTransportSettings, type SandboxMode, StdioTransport, type StdioTransportSettings, type ThreadTokenUsageUpdatedNotification, type TurnCompletedNotification, type TurnStartedNotification, WebSocketTransport, type WebSocketTransportSettings, codexAppServer, codexProviderMetadata, createCodexAppServer, createCodexProvider, mapPromptToTurnInput, mapSystemPrompt, withProviderMetadata };
1410
+ export { type AgentMessageDeltaNotification, AppServerClient, type AppServerClientSettings, ApprovalsDispatcher, type ApprovalsDispatcherSettings, type AskForApproval, CODEX_PROVIDER_ID, type CodexCommandApprovalRequest, type CodexDynamicToolDefinition, CodexEventMapper, type CodexEventMapperInput, type CodexEventMapperOptions, type CodexFileChangeApprovalRequest, type CodexInitializeParams, type CodexInitializeResult, type CodexInitializedNotification, CodexLanguageModel, type CodexLanguageModelSettings, type CodexModelConfig, CodexNotImplementedError, type CodexNotification, type CodexProvider, CodexProviderError, type CodexProviderSettings, type CodexThreadDefaults, type CodexThreadResumeParams, type CodexThreadResumeResult, type CodexThreadStartParams, type CodexThreadStartResult, type CodexToolCallDeltaNotification, type CodexToolCallFinishedNotification, type CodexToolCallRequestParams, type CodexToolCallResult, type CodexToolCallStartedNotification, type CodexToolResultContentItem, type CodexTransport, type CodexTransportEventMap, type CodexTurnInputImage, type CodexTurnInputItem, type CodexTurnInputLocalImage, type CodexTurnInputMention, type CodexTurnInputSkill, type CodexTurnInputText, type CodexTurnStartParams, type CodexTurnStartResult, CodexWorker, CodexWorkerPool, type CodexWorkerPoolSettings, type CodexWorkerSettings, type CommandApprovalHandler, type CommandExecutionApprovalDecision, type CommandExecutionRequestApprovalParams, type CommandExecutionRequestApprovalResponse, type DynamicToolDefinition, type DynamicToolExecutionContext, type DynamicToolHandler, DynamicToolsDispatcher, type DynamicToolsDispatcherSettings, type FileChangeApprovalDecision, type FileChangeApprovalHandler, type FileChangeRequestApprovalParams, type FileChangeRequestApprovalResponse, type ItemCompletedNotification, type ItemStartedNotification, JsonRpcError, type JsonRpcErrorResponse, type JsonRpcId, type JsonRpcMessage, type JsonRpcMessageBase, type JsonRpcNotification, type JsonRpcRequest, type JsonRpcResponse, type JsonRpcSuccessResponse, PACKAGE_NAME, PACKAGE_VERSION, type PendingToolCall, PersistentTransport, type PersistentTransportSettings, type SandboxMode, StdioTransport, type StdioTransportSettings, type ThreadTokenUsageUpdatedNotification, type TurnCompletedNotification, type TurnStartedNotification, WebSocketTransport, type WebSocketTransportSettings, codexAppServer, codexProviderMetadata, createCodexAppServer, createCodexProvider, mapPromptToTurnInput, mapSystemPrompt, withProviderMetadata };
package/dist/index.d.ts CHANGED
@@ -1315,6 +1315,8 @@ interface CodexProviderSettings {
1315
1315
  scope?: "provider" | "global";
1316
1316
  key?: string;
1317
1317
  };
1318
+ /** Emit plan updates as tool-call/tool-result parts. Default: true. */
1319
+ emitPlanUpdates?: boolean;
1318
1320
  }
1319
1321
 
1320
1322
  interface CodexLanguageModelSettings {
@@ -1346,14 +1348,23 @@ interface CodexEventMapperInput {
1346
1348
  method: string;
1347
1349
  params?: unknown;
1348
1350
  }
1351
+ interface CodexEventMapperOptions {
1352
+ /** Emit plan updates as tool-call/tool-result parts. Default: true. */
1353
+ emitPlanUpdates?: boolean;
1354
+ }
1349
1355
  declare class CodexEventMapper {
1356
+ private readonly options;
1350
1357
  private streamStarted;
1351
1358
  private readonly openTextParts;
1359
+ private readonly textDeltaReceived;
1352
1360
  private readonly openReasoningParts;
1353
1361
  private readonly openToolCalls;
1362
+ private readonly planSequenceByTurnId;
1354
1363
  private threadId;
1355
1364
  private latestUsage;
1365
+ constructor(options?: CodexEventMapperOptions);
1356
1366
  setThreadId(threadId: string): void;
1367
+ private nextPlanSequence;
1357
1368
  map(event: CodexEventMapperInput): LanguageModelV3StreamPart[];
1358
1369
  }
1359
1370
 
@@ -1396,4 +1407,4 @@ declare const codexAppServer: CodexProvider;
1396
1407
  */
1397
1408
  declare const createCodexProvider: typeof createCodexAppServer;
1398
1409
 
1399
- export { type AgentMessageDeltaNotification, AppServerClient, type AppServerClientSettings, ApprovalsDispatcher, type ApprovalsDispatcherSettings, type AskForApproval, CODEX_PROVIDER_ID, type CodexCommandApprovalRequest, type CodexDynamicToolDefinition, CodexEventMapper, type CodexEventMapperInput, type CodexFileChangeApprovalRequest, type CodexInitializeParams, type CodexInitializeResult, type CodexInitializedNotification, CodexLanguageModel, type CodexLanguageModelSettings, type CodexModelConfig, CodexNotImplementedError, type CodexNotification, type CodexProvider, CodexProviderError, type CodexProviderSettings, type CodexThreadDefaults, type CodexThreadResumeParams, type CodexThreadResumeResult, type CodexThreadStartParams, type CodexThreadStartResult, type CodexToolCallDeltaNotification, type CodexToolCallFinishedNotification, type CodexToolCallRequestParams, type CodexToolCallResult, type CodexToolCallStartedNotification, type CodexToolResultContentItem, type CodexTransport, type CodexTransportEventMap, type CodexTurnInputImage, type CodexTurnInputItem, type CodexTurnInputLocalImage, type CodexTurnInputMention, type CodexTurnInputSkill, type CodexTurnInputText, type CodexTurnStartParams, type CodexTurnStartResult, CodexWorker, CodexWorkerPool, type CodexWorkerPoolSettings, type CodexWorkerSettings, type CommandApprovalHandler, type CommandExecutionApprovalDecision, type CommandExecutionRequestApprovalParams, type CommandExecutionRequestApprovalResponse, type DynamicToolDefinition, type DynamicToolExecutionContext, type DynamicToolHandler, DynamicToolsDispatcher, type DynamicToolsDispatcherSettings, type FileChangeApprovalDecision, type FileChangeApprovalHandler, type FileChangeRequestApprovalParams, type FileChangeRequestApprovalResponse, type ItemCompletedNotification, type ItemStartedNotification, JsonRpcError, type JsonRpcErrorResponse, type JsonRpcId, type JsonRpcMessage, type JsonRpcMessageBase, type JsonRpcNotification, type JsonRpcRequest, type JsonRpcResponse, type JsonRpcSuccessResponse, PACKAGE_NAME, PACKAGE_VERSION, type PendingToolCall, PersistentTransport, type PersistentTransportSettings, type SandboxMode, StdioTransport, type StdioTransportSettings, type ThreadTokenUsageUpdatedNotification, type TurnCompletedNotification, type TurnStartedNotification, WebSocketTransport, type WebSocketTransportSettings, codexAppServer, codexProviderMetadata, createCodexAppServer, createCodexProvider, mapPromptToTurnInput, mapSystemPrompt, withProviderMetadata };
1410
+ export { type AgentMessageDeltaNotification, AppServerClient, type AppServerClientSettings, ApprovalsDispatcher, type ApprovalsDispatcherSettings, type AskForApproval, CODEX_PROVIDER_ID, type CodexCommandApprovalRequest, type CodexDynamicToolDefinition, CodexEventMapper, type CodexEventMapperInput, type CodexEventMapperOptions, type CodexFileChangeApprovalRequest, type CodexInitializeParams, type CodexInitializeResult, type CodexInitializedNotification, CodexLanguageModel, type CodexLanguageModelSettings, type CodexModelConfig, CodexNotImplementedError, type CodexNotification, type CodexProvider, CodexProviderError, type CodexProviderSettings, type CodexThreadDefaults, type CodexThreadResumeParams, type CodexThreadResumeResult, type CodexThreadStartParams, type CodexThreadStartResult, type CodexToolCallDeltaNotification, type CodexToolCallFinishedNotification, type CodexToolCallRequestParams, type CodexToolCallResult, type CodexToolCallStartedNotification, type CodexToolResultContentItem, type CodexTransport, type CodexTransportEventMap, type CodexTurnInputImage, type CodexTurnInputItem, type CodexTurnInputLocalImage, type CodexTurnInputMention, type CodexTurnInputSkill, type CodexTurnInputText, type CodexTurnStartParams, type CodexTurnStartResult, CodexWorker, CodexWorkerPool, type CodexWorkerPoolSettings, type CodexWorkerSettings, type CommandApprovalHandler, type CommandExecutionApprovalDecision, type CommandExecutionRequestApprovalParams, type CommandExecutionRequestApprovalResponse, type DynamicToolDefinition, type DynamicToolExecutionContext, type DynamicToolHandler, DynamicToolsDispatcher, type DynamicToolsDispatcherSettings, type FileChangeApprovalDecision, type FileChangeApprovalHandler, type FileChangeRequestApprovalParams, type FileChangeRequestApprovalResponse, type ItemCompletedNotification, type ItemStartedNotification, JsonRpcError, type JsonRpcErrorResponse, type JsonRpcId, type JsonRpcMessage, type JsonRpcMessageBase, type JsonRpcNotification, type JsonRpcRequest, type JsonRpcResponse, type JsonRpcSuccessResponse, PACKAGE_NAME, PACKAGE_VERSION, type PendingToolCall, PersistentTransport, type PersistentTransportSettings, type SandboxMode, StdioTransport, type StdioTransportSettings, type ThreadTokenUsageUpdatedNotification, type TurnCompletedNotification, type TurnStartedNotification, WebSocketTransport, type WebSocketTransportSettings, codexAppServer, codexProviderMetadata, createCodexAppServer, createCodexProvider, mapPromptToTurnInput, mapSystemPrompt, withProviderMetadata };
package/dist/index.js CHANGED
@@ -884,7 +884,7 @@ var DynamicToolsDispatcher = class {
884
884
  // package.json
885
885
  var package_default = {
886
886
  name: "@janole/ai-sdk-provider-codex-asp",
887
- version: "0.2.1"};
887
+ version: "0.2.2"};
888
888
 
889
889
  // src/package-info.ts
890
890
  var PACKAGE_NAME = package_default.name;
@@ -930,15 +930,28 @@ function toFinishReason(status) {
930
930
  }
931
931
  }
932
932
  var CodexEventMapper = class {
933
+ options;
933
934
  streamStarted = false;
934
935
  openTextParts = /* @__PURE__ */ new Set();
936
+ textDeltaReceived = /* @__PURE__ */ new Set();
935
937
  openReasoningParts = /* @__PURE__ */ new Set();
936
938
  openToolCalls = /* @__PURE__ */ new Map();
939
+ planSequenceByTurnId = /* @__PURE__ */ new Map();
937
940
  threadId;
938
941
  latestUsage;
942
+ constructor(options) {
943
+ this.options = {
944
+ emitPlanUpdates: options?.emitPlanUpdates ?? true
945
+ };
946
+ }
939
947
  setThreadId(threadId) {
940
948
  this.threadId = threadId;
941
949
  }
950
+ nextPlanSequence(turnId) {
951
+ const next = (this.planSequenceByTurnId.get(turnId) ?? 0) + 1;
952
+ this.planSequenceByTurnId.set(turnId, next);
953
+ return next;
954
+ }
942
955
  map(event) {
943
956
  const parts = [];
944
957
  const withMeta = (part) => withProviderMetadata(part, this.threadId);
@@ -1018,6 +1031,7 @@ var CodexEventMapper = class {
1018
1031
  parts.push(withMeta({ type: "text-start", id: delta.itemId }));
1019
1032
  }
1020
1033
  parts.push(withMeta({ type: "text-delta", id: delta.itemId, delta: delta.delta }));
1034
+ this.textDeltaReceived.add(delta.itemId);
1021
1035
  break;
1022
1036
  }
1023
1037
  case "item/completed": {
@@ -1026,9 +1040,19 @@ var CodexEventMapper = class {
1026
1040
  if (!item?.id) {
1027
1041
  break;
1028
1042
  }
1029
- if (item.type === "agentMessage" && this.openTextParts.has(item.id)) {
1030
- parts.push(withMeta({ type: "text-end", id: item.id }));
1031
- this.openTextParts.delete(item.id);
1043
+ if (item.type === "agentMessage") {
1044
+ if (!this.textDeltaReceived.has(item.id) && item.text) {
1045
+ pushStreamStart();
1046
+ if (!this.openTextParts.has(item.id)) {
1047
+ this.openTextParts.add(item.id);
1048
+ parts.push(withMeta({ type: "text-start", id: item.id }));
1049
+ }
1050
+ parts.push(withMeta({ type: "text-delta", id: item.id, delta: item.text }));
1051
+ }
1052
+ if (this.openTextParts.has(item.id)) {
1053
+ parts.push(withMeta({ type: "text-end", id: item.id }));
1054
+ this.openTextParts.delete(item.id);
1055
+ }
1032
1056
  } else if (item.type === "commandExecution" && this.openToolCalls.has(item.id)) {
1033
1057
  const tracked = this.openToolCalls.get(item.id);
1034
1058
  const output = item.aggregatedOutput ?? tracked.output;
@@ -1057,6 +1081,64 @@ var CodexEventMapper = class {
1057
1081
  }
1058
1082
  break;
1059
1083
  }
1084
+ case "item/reasoning/summaryPartAdded": {
1085
+ const params = event.params ?? {};
1086
+ if (params.itemId) {
1087
+ pushReasoningDelta(params.itemId, "\n\n");
1088
+ }
1089
+ break;
1090
+ }
1091
+ // codex/event/agent_reasoning mirrors canonical reasoning summary
1092
+ // stream events in current logs. Ignore wrapper to avoid duplicate
1093
+ // reasoning text in consumers.
1094
+ case "codex/event/agent_reasoning":
1095
+ break;
1096
+ // codex/event/agent_reasoning_section_break is the wrapper form of
1097
+ // item/reasoning/summaryPartAdded (identical 1:1). Handled by the
1098
+ // canonical event above — skip the wrapper to avoid double "\n\n".
1099
+ case "codex/event/agent_reasoning_section_break":
1100
+ break;
1101
+ case "turn/plan/updated": {
1102
+ if (!this.options.emitPlanUpdates) {
1103
+ break;
1104
+ }
1105
+ const params = event.params ?? {};
1106
+ const turnId = params.turnId;
1107
+ const plan = params.plan;
1108
+ if (turnId && plan) {
1109
+ pushStreamStart();
1110
+ const planSequence = this.nextPlanSequence(turnId);
1111
+ const toolCallId = `plan:${turnId}:${planSequence}`;
1112
+ const toolName = "codex_plan_update";
1113
+ parts.push(withMeta({
1114
+ type: "tool-call",
1115
+ toolCallId,
1116
+ toolName,
1117
+ input: JSON.stringify({}),
1118
+ providerExecuted: true,
1119
+ dynamic: true
1120
+ }));
1121
+ parts.push(withMeta({
1122
+ type: "tool-result",
1123
+ toolCallId,
1124
+ toolName,
1125
+ result: { plan, explanation: params.explanation ?? void 0 }
1126
+ }));
1127
+ }
1128
+ break;
1129
+ }
1130
+ // codex/event/plan_update is the wrapper form of turn/plan/updated (1:1).
1131
+ case "codex/event/plan_update":
1132
+ break;
1133
+ // NOTE: turn/diff/updated and codex/event/turn_diff are intentionally
1134
+ // NOT mapped. They carry full unified diffs (often 50-100 KB) which,
1135
+ // when emitted as reasoning deltas, crash or freeze the frontend
1136
+ // markdown renderer. If these need to surface in the UI, they should
1137
+ // use a dedicated part type with lazy/collapsed rendering — not
1138
+ // reasoning text.
1139
+ case "turn/diff/updated":
1140
+ case "codex/event/turn_diff":
1141
+ break;
1060
1142
  case "item/commandExecution/outputDelta": {
1061
1143
  const delta = event.params ?? {};
1062
1144
  if (delta.itemId && delta.delta && this.openToolCalls.has(delta.itemId)) {
@@ -1072,6 +1154,43 @@ var CodexEventMapper = class {
1072
1154
  }
1073
1155
  break;
1074
1156
  }
1157
+ case "codex/event/mcp_tool_call_begin": {
1158
+ const params = event.params ?? {};
1159
+ const callId = params.msg?.call_id;
1160
+ const inv = params.msg?.invocation;
1161
+ if (callId && inv) {
1162
+ pushStreamStart();
1163
+ const toolName = `mcp:${inv.server}/${inv.tool}`;
1164
+ this.openToolCalls.set(callId, { toolName, output: "" });
1165
+ parts.push(withMeta({
1166
+ type: "tool-call",
1167
+ toolCallId: callId,
1168
+ toolName,
1169
+ input: JSON.stringify(inv.arguments ?? {}),
1170
+ providerExecuted: true,
1171
+ dynamic: true
1172
+ }));
1173
+ }
1174
+ break;
1175
+ }
1176
+ case "codex/event/mcp_tool_call_end": {
1177
+ const params = event.params ?? {};
1178
+ const callId = params.msg?.call_id;
1179
+ if (callId && this.openToolCalls.has(callId)) {
1180
+ const tracked = this.openToolCalls.get(callId);
1181
+ const result = params.msg?.result;
1182
+ const textParts = result?.Ok?.content?.filter((c) => c.type === "text").map((c) => c.text) ?? [];
1183
+ const output = textParts.join("\n") || (result?.Err ? JSON.stringify(result.Err) : "");
1184
+ parts.push(withMeta({
1185
+ type: "tool-result",
1186
+ toolCallId: callId,
1187
+ toolName: tracked.toolName,
1188
+ result: { output }
1189
+ }));
1190
+ this.openToolCalls.delete(callId);
1191
+ }
1192
+ break;
1193
+ }
1075
1194
  case "item/mcpToolCall/progress": {
1076
1195
  const params = event.params ?? {};
1077
1196
  if (params.itemId && params.message) {
@@ -1141,6 +1260,9 @@ var CodexEventMapper = class {
1141
1260
  }
1142
1261
  this.openToolCalls.clear();
1143
1262
  const completed = event.params ?? {};
1263
+ if (completed.turn?.id) {
1264
+ this.planSequenceByTurnId.delete(completed.turn.id);
1265
+ }
1144
1266
  const usage = this.latestUsage ?? EMPTY_USAGE;
1145
1267
  parts.push(withMeta({ type: "finish", finishReason: toFinishReason(completed.turn?.status), usage }));
1146
1268
  break;
@@ -1446,7 +1568,9 @@ var CodexLanguageModel = class {
1446
1568
  const client = new AppServerClient(transport, stripUndefined({
1447
1569
  onPacket: packetLogger
1448
1570
  }));
1449
- const mapper = new CodexEventMapper();
1571
+ const mapper = new CodexEventMapper(stripUndefined({
1572
+ emitPlanUpdates: this.config.providerSettings.emitPlanUpdates
1573
+ }));
1450
1574
  let activeThreadId;
1451
1575
  let activeTurnId;
1452
1576
  const interruptTimeoutMs = this.config.providerSettings.interruptTimeoutMs ?? 1e4;