ai-sdk-provider-claude-code 3.3.6 → 3.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/README.md CHANGED
@@ -284,6 +284,9 @@ This provider exposes Agent SDK options directly. Key options include:
284
284
  | `persistSession` | When `false`, disables session persistence to disk (v3.2.0+) |
285
285
  | `spawnClaudeCodeProcess` | Custom process spawner for VMs/containers (v3.2.0+) |
286
286
  | `permissionMode` | Permission mode: `'default'`, `'acceptEdits'`, `'bypassPermissions'`, `'plan'`, `'delegate'`, `'dontAsk'` |
287
+ | `sessionId` | Use a specific session ID for deterministic tracking and correlation (v3.4.0+) |
288
+ | `debug` | Enable programmatic debug logging from the SDK (v3.4.0+) |
289
+ | `debugFile` | Path to a file for SDK debug log output (v3.4.0+) |
287
290
 
288
291
  **Agent definitions** (`agents`) now support additional fields (v3.2.0+):
289
292
 
package/dist/index.cjs CHANGED
@@ -404,18 +404,33 @@ function getErrorMetadata(error) {
404
404
  }
405
405
 
406
406
  // src/map-claude-code-finish-reason.ts
407
- function mapClaudeCodeFinishReason(subtype) {
407
+ function mapClaudeCodeFinishReason(subtype, stopReason) {
408
+ if (stopReason != null) {
409
+ switch (stopReason) {
410
+ case "end_turn":
411
+ return { unified: "stop", raw: "end_turn" };
412
+ case "max_tokens":
413
+ return { unified: "length", raw: "max_tokens" };
414
+ case "stop_sequence":
415
+ return { unified: "stop", raw: "stop_sequence" };
416
+ case "tool_use":
417
+ return { unified: "tool-calls", raw: "tool_use" };
418
+ default:
419
+ break;
420
+ }
421
+ }
422
+ const raw = stopReason ?? subtype;
408
423
  switch (subtype) {
409
424
  case "success":
410
- return { unified: "stop", raw: subtype };
425
+ return { unified: "stop", raw };
411
426
  case "error_max_turns":
412
- return { unified: "length", raw: subtype };
427
+ return { unified: "length", raw };
413
428
  case "error_during_execution":
414
- return { unified: "error", raw: subtype };
429
+ return { unified: "error", raw };
415
430
  case void 0:
416
- return { unified: "stop", raw: void 0 };
431
+ return { unified: "stop", raw };
417
432
  default:
418
- return { unified: "other", raw: subtype };
433
+ return { unified: "other", raw };
419
434
  }
420
435
  }
421
436
 
@@ -465,6 +480,7 @@ var claudeCodeSettingsSchema = import_zod.z.object({
465
480
  permissionPromptToolName: import_zod.z.string().optional(),
466
481
  continue: import_zod.z.boolean().optional(),
467
482
  resume: import_zod.z.string().optional(),
483
+ sessionId: import_zod.z.string().optional(),
468
484
  allowedTools: import_zod.z.array(import_zod.z.string()).optional(),
469
485
  disallowedTools: import_zod.z.array(import_zod.z.string()).optional(),
470
486
  betas: import_zod.z.array(import_zod.z.string()).optional(),
@@ -534,6 +550,8 @@ var claudeCodeSettingsSchema = import_zod.z.object({
534
550
  ])
535
551
  ).optional(),
536
552
  verbose: import_zod.z.boolean().optional(),
553
+ debug: import_zod.z.boolean().optional(),
554
+ debugFile: import_zod.z.string().optional(),
537
555
  logger: import_zod.z.union([import_zod.z.literal(false), loggerFunctionSchema]).optional(),
538
556
  env: import_zod.z.record(import_zod.z.string(), import_zod.z.string().optional()).optional(),
539
557
  additionalDirectories: import_zod.z.array(import_zod.z.string()).optional(),
@@ -1260,6 +1278,15 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
1260
1278
  if (this.settings.hooks) {
1261
1279
  opts.hooks = this.settings.hooks;
1262
1280
  }
1281
+ if (this.settings.sessionId !== void 0) {
1282
+ opts.sessionId = this.settings.sessionId;
1283
+ }
1284
+ if (this.settings.debug !== void 0) {
1285
+ opts.debug = this.settings.debug;
1286
+ }
1287
+ if (this.settings.debugFile !== void 0) {
1288
+ opts.debugFile = this.settings.debugFile;
1289
+ }
1263
1290
  const sdkOverrides = sdkOptions ? sdkOptions : void 0;
1264
1291
  const sdkEnv = sdkOverrides && typeof sdkOverrides.env === "object" && sdkOverrides.env !== null ? sdkOverrides.env : void 0;
1265
1292
  const sdkStderr = sdkOverrides && typeof sdkOverrides.stderr === "function" ? sdkOverrides.stderr : void 0;
@@ -1463,7 +1490,8 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
1463
1490
  `[claude-code] Token usage - Input: ${usage.inputTokens.total}, Output: ${usage.outputTokens.total}`
1464
1491
  );
1465
1492
  }
1466
- finishReason = mapClaudeCodeFinishReason(message.subtype);
1493
+ const stopReason = "stop_reason" in message ? message.stop_reason : void 0;
1494
+ finishReason = mapClaudeCodeFinishReason(message.subtype, stopReason);
1467
1495
  this.logger.debug(`[claude-code] Finish reason: ${finishReason.unified}`);
1468
1496
  } else if (message.type === "system" && message.subtype === "init") {
1469
1497
  this.setSessionId(message.session_id);
@@ -2206,8 +2234,10 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
2206
2234
  `[claude-code] Stream token usage - Input: ${usage.inputTokens.total}, Output: ${usage.outputTokens.total}`
2207
2235
  );
2208
2236
  }
2237
+ const stopReason = "stop_reason" in message ? message.stop_reason : void 0;
2209
2238
  const finishReason = mapClaudeCodeFinishReason(
2210
- message.subtype
2239
+ message.subtype,
2240
+ stopReason
2211
2241
  );
2212
2242
  this.logger.debug(`[claude-code] Stream finish reason: ${finishReason.unified}`);
2213
2243
  this.setSessionId(message.session_id);
@@ -2468,7 +2498,8 @@ function createCustomMcpServer(config) {
2468
2498
  name,
2469
2499
  def.description,
2470
2500
  def.inputSchema.shape,
2471
- (args, extra) => def.handler(args, extra)
2501
+ (args, extra) => def.handler(args, extra),
2502
+ def.annotations ? { annotations: def.annotations } : void 0
2472
2503
  )
2473
2504
  );
2474
2505
  return (0, import_claude_agent_sdk2.createSdkMcpServer)({ name: config.name, version: config.version, tools: defs });