@janole/ai-sdk-provider-codex-asp 0.1.1 → 0.1.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/README.md CHANGED
@@ -125,39 +125,6 @@ codex.shutdown() // clean up persistent workers
125
125
 
126
126
  See [`src/provider.ts`](src/provider.ts) for full type definitions.
127
127
 
128
- ## Event Mapping
129
-
130
- The provider translates Codex App Server Protocol events into AI SDK V3 stream parts. This is where the magic happens — Codex's tool execution lifecycle maps directly onto the AI SDK's provider-executed tool protocol.
131
-
132
- ### Command executions → provider-executed tools
133
-
134
- Codex command executions (shell commands run by the agent) are surfaced as proper tool calls with `providerExecuted: true`, so AI SDK consumers can observe them through the standard tool protocol:
135
-
136
- | Codex event | AI SDK stream part |
137
- |---|---|
138
- | `item/started` (commandExecution) | `tool-call` — includes `command` and `cwd` as input |
139
- | `item/commandExecution/outputDelta` | `tool-result` with `preliminary: true` — accumulated output so far |
140
- | `item/completed` (commandExecution) | `tool-result` — final result with `exitCode` and `status` |
141
-
142
- Preliminary results use "replace" semantics per the AI SDK spec: each one contains the full output accumulated so far, so consumers always have the complete picture.
143
-
144
- ### Client-side tools (AI SDK `tool()`)
145
-
146
- Standard AI SDK tools are injected into Codex as dynamic tools and use the input-streaming protocol:
147
-
148
- | Codex event | AI SDK stream part |
149
- |---|---|
150
- | `item/tool/callStarted` | `tool-input-start` |
151
- | `item/tool/callDelta` | `tool-input-delta` |
152
- | `item/tool/callFinished` | `tool-input-end` |
153
-
154
- ### Text and reasoning
155
-
156
- | Codex event | AI SDK stream part |
157
- |---|---|
158
- | `item/agentMessage/delta` | `text-delta` |
159
- | `item/reasoning/textDelta`, `item/plan/delta`, `item/fileChange/outputDelta`, `item/mcpToolCall/progress` | `reasoning-delta` |
160
-
161
128
  ## Examples
162
129
 
163
130
  See the [`examples/`](examples/) directory:
package/dist/index.cjs CHANGED
@@ -823,7 +823,7 @@ var DynamicToolsDispatcher = class {
823
823
  // package.json
824
824
  var package_default = {
825
825
  name: "@janole/ai-sdk-provider-codex-asp",
826
- version: "0.1.1"};
826
+ version: "0.1.2"};
827
827
 
828
828
  // src/package-info.ts
829
829
  var PACKAGE_NAME = package_default.name;
@@ -1124,13 +1124,32 @@ function extractTurnId(result) {
1124
1124
  }
1125
1125
  return turnId;
1126
1126
  }
1127
+ function extractThreadIdFromProviderOptions(providerOptions) {
1128
+ const meta = providerOptions?.[CODEX_PROVIDER_ID];
1129
+ if (meta && typeof meta === "object" && "threadId" in meta && typeof meta["threadId"] === "string") {
1130
+ return meta["threadId"];
1131
+ }
1132
+ return void 0;
1133
+ }
1127
1134
  function extractResumeThreadId(prompt) {
1128
1135
  for (let i = prompt.length - 1; i >= 0; i--) {
1129
1136
  const message = prompt[i];
1130
1137
  if (message?.role === "assistant") {
1131
- const meta = message.providerOptions?.["codex-app-server"];
1132
- if (meta && typeof meta["threadId"] === "string") {
1133
- return meta["threadId"];
1138
+ const messageThreadId = extractThreadIdFromProviderOptions(
1139
+ message.providerOptions
1140
+ );
1141
+ if (messageThreadId) {
1142
+ return messageThreadId;
1143
+ }
1144
+ if (Array.isArray(message.content)) {
1145
+ for (const part of message.content) {
1146
+ const partThreadId = extractThreadIdFromProviderOptions(
1147
+ part.providerOptions
1148
+ );
1149
+ if (partThreadId) {
1150
+ return partThreadId;
1151
+ }
1152
+ }
1134
1153
  }
1135
1154
  }
1136
1155
  }
@@ -1308,6 +1327,9 @@ var CodexLanguageModel = class {
1308
1327
  console.debug("[codex packet]", packet.message);
1309
1328
  }
1310
1329
  }) : void 0;
1330
+ const debugLog = packetLogger ? (direction, label, data) => {
1331
+ packetLogger({ direction, message: { debug: label, data } });
1332
+ } : void 0;
1311
1333
  const client = new AppServerClient(transport, stripUndefined({
1312
1334
  onPacket: packetLogger
1313
1335
  }));
@@ -1425,7 +1447,9 @@ var CodexLanguageModel = class {
1425
1447
  });
1426
1448
  await client.request("initialize", initializeParams);
1427
1449
  await client.notification("initialized");
1450
+ debugLog?.("inbound", "prompt", options.prompt);
1428
1451
  const resumeThreadId = extractResumeThreadId(options.prompt);
1452
+ debugLog?.("inbound", "extractResumeThreadId", { resumeThreadId });
1429
1453
  const developerInstructions = mapSystemPrompt(options.prompt);
1430
1454
  let threadId;
1431
1455
  if (resumeThreadId) {
@@ -1434,6 +1458,7 @@ var CodexLanguageModel = class {
1434
1458
  persistExtendedHistory: false,
1435
1459
  developerInstructions
1436
1460
  });
1461
+ debugLog?.("outbound", "thread/resume", resumeParams);
1437
1462
  const resumeResult = await client.request(
1438
1463
  "thread/resume",
1439
1464
  resumeParams
@@ -1448,6 +1473,7 @@ var CodexLanguageModel = class {
1448
1473
  approvalPolicy: this.config.providerSettings.defaultThreadSettings?.approvalPolicy,
1449
1474
  sandbox: this.config.providerSettings.defaultThreadSettings?.sandbox
1450
1475
  });
1476
+ debugLog?.("outbound", "thread/start", threadStartParams);
1451
1477
  const threadStartResult = await client.request(
1452
1478
  "thread/start",
1453
1479
  threadStartParams
@@ -1464,9 +1490,11 @@ var CodexLanguageModel = class {
1464
1490
  closeSuccessfully
1465
1491
  );
1466
1492
  }
1493
+ const turnInput = mapPromptToTurnInput(options.prompt, !!resumeThreadId);
1494
+ debugLog?.("outbound", "turn/start", { threadId, input: turnInput });
1467
1495
  const turnStartResult = await client.request("turn/start", {
1468
1496
  threadId,
1469
- input: mapPromptToTurnInput(options.prompt, !!resumeThreadId)
1497
+ input: turnInput
1470
1498
  });
1471
1499
  extractTurnId(turnStartResult);
1472
1500
  } catch (error) {