ai-sdk-provider-claude-code 3.3.6 → 3.4.1
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 +3 -0
- package/dist/index.cjs +40 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -3
- package/dist/index.d.ts +23 -3
- package/dist/index.js +40 -9
- package/dist/index.js.map +1 -1
- package/docs/ai-sdk-v4/GUIDE.md +1 -1
- package/docs/ai-sdk-v5/GUIDE.md +56 -1
- package/package.json +6 -5
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LanguageModelV3, ProviderV3, APICallError, LoadAPIKeyError } from '@ai-sdk/provider';
|
|
2
|
-
import { PermissionMode, SdkBeta, SdkPluginConfig, SandboxSettings, Options, McpServerConfig, CanUseTool, AgentMcpServerSpec, SpawnOptions, SpawnedProcess, Query, McpSdkServerConfigWithInstance } from '@anthropic-ai/claude-agent-sdk';
|
|
3
|
-
export { AgentMcpServerSpec, CanUseTool, HookCallback, HookCallbackMatcher, HookEvent, HookInput, HookJSONOutput, McpSdkServerConfigWithInstance, McpServerConfig, OutputFormat, PermissionBehavior, PermissionResult, PermissionRuleValue, PermissionUpdate, PostToolUseHookInput, PreToolUseHookInput, Query, SessionEndHookInput, SessionStartHookInput, SpawnOptions, SpawnedProcess, UserPromptSubmitHookInput, createSdkMcpServer, tool } from '@anthropic-ai/claude-agent-sdk';
|
|
2
|
+
import { PermissionMode, SdkBeta, SdkPluginConfig, SandboxSettings, Options, McpServerConfig, CanUseTool, AgentMcpServerSpec, SpawnOptions, SpawnedProcess, Query, SdkMcpToolDefinition, McpSdkServerConfigWithInstance } from '@anthropic-ai/claude-agent-sdk';
|
|
3
|
+
export { AgentMcpServerSpec, CanUseTool, HookCallback, HookCallbackMatcher, HookEvent, HookInput, HookJSONOutput, McpSdkServerConfigWithInstance, McpServerConfig, OutputFormat, PermissionBehavior, PermissionResult, PermissionRuleValue, PermissionUpdate, PostToolUseHookInput, PreToolUseHookInput, Query, SessionEndHookInput, SessionStartHookInput, SpawnOptions, SpawnedProcess, TaskCompletedHookInput, TeammateIdleHookInput, UserPromptSubmitHookInput, createSdkMcpServer, tool } from '@anthropic-ai/claude-agent-sdk';
|
|
4
4
|
import { ZodObject, ZodRawShape } from 'zod';
|
|
5
5
|
|
|
6
6
|
type StreamingInputMode = 'auto' | 'always' | 'off';
|
|
@@ -117,6 +117,11 @@ interface ClaudeCodeSettings {
|
|
|
117
117
|
* Resume a specific session by ID
|
|
118
118
|
*/
|
|
119
119
|
resume?: string;
|
|
120
|
+
/**
|
|
121
|
+
* Use a specific session ID for this query.
|
|
122
|
+
* Allows deterministic session identifiers for tracking and correlation.
|
|
123
|
+
*/
|
|
124
|
+
sessionId?: string;
|
|
120
125
|
/**
|
|
121
126
|
* Tools to explicitly allow during execution
|
|
122
127
|
* Examples: ['Read', 'LS', 'Bash(git log:*)']
|
|
@@ -195,6 +200,14 @@ interface ClaudeCodeSettings {
|
|
|
195
200
|
* Enable verbose logging for debugging
|
|
196
201
|
*/
|
|
197
202
|
verbose?: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* Enable programmatic debug logging from the SDK.
|
|
205
|
+
*/
|
|
206
|
+
debug?: boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Path to a file for SDK debug log output.
|
|
209
|
+
*/
|
|
210
|
+
debugFile?: string;
|
|
198
211
|
/**
|
|
199
212
|
* Custom logger for handling warnings and errors.
|
|
200
213
|
* - Set to `false` to disable all logging
|
|
@@ -592,6 +605,12 @@ type ContentAnnotations = {
|
|
|
592
605
|
/** ISO 8601 timestamp of last modification */
|
|
593
606
|
lastModified?: string;
|
|
594
607
|
};
|
|
608
|
+
/**
|
|
609
|
+
* MCP tool annotations for hinting tool behavior to the model.
|
|
610
|
+
* Derived from the SDK's SdkMcpToolDefinition type to stay in sync
|
|
611
|
+
* with the upstream MCP ToolAnnotations definition.
|
|
612
|
+
*/
|
|
613
|
+
type ToolAnnotations = NonNullable<SdkMcpToolDefinition['annotations']>;
|
|
595
614
|
/**
|
|
596
615
|
* Convenience helper to create an SDK MCP server from a simple tool map.
|
|
597
616
|
* Each tool provides a description, a Zod object schema, and a handler.
|
|
@@ -670,6 +689,7 @@ declare function createCustomMcpServer<Tools extends Record<string, {
|
|
|
670
689
|
description: string;
|
|
671
690
|
inputSchema: ZodObject<ZodRawShape>;
|
|
672
691
|
handler: (args: Record<string, unknown>, extra: unknown) => Promise<MinimalCallToolResult>;
|
|
692
|
+
annotations?: ToolAnnotations;
|
|
673
693
|
}>>(config: {
|
|
674
694
|
name: string;
|
|
675
695
|
version?: string;
|
|
@@ -825,4 +845,4 @@ declare function isTimeoutError(error: unknown): boolean;
|
|
|
825
845
|
*/
|
|
826
846
|
declare function getErrorMetadata(error: unknown): ClaudeCodeErrorMetadata | undefined;
|
|
827
847
|
|
|
828
|
-
export { type ClaudeCodeErrorMetadata, ClaudeCodeLanguageModel, type ClaudeCodeLanguageModelOptions, type ClaudeCodeModelId, type ClaudeCodeProvider, type ClaudeCodeProviderSettings, type ClaudeCodeSettings, type Logger, type MessageInjector, claudeCode, createAPICallError, createAuthenticationError, createClaudeCode, createCustomMcpServer, createTimeoutError, getErrorMetadata, isAuthenticationError, isTimeoutError };
|
|
848
|
+
export { type ClaudeCodeErrorMetadata, ClaudeCodeLanguageModel, type ClaudeCodeLanguageModelOptions, type ClaudeCodeModelId, type ClaudeCodeProvider, type ClaudeCodeProviderSettings, type ClaudeCodeSettings, type Logger, type MessageInjector, type MinimalCallToolResult, type ToolAnnotations, claudeCode, createAPICallError, createAuthenticationError, createClaudeCode, createCustomMcpServer, createTimeoutError, getErrorMetadata, isAuthenticationError, isTimeoutError };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LanguageModelV3, ProviderV3, APICallError, LoadAPIKeyError } from '@ai-sdk/provider';
|
|
2
|
-
import { PermissionMode, SdkBeta, SdkPluginConfig, SandboxSettings, Options, McpServerConfig, CanUseTool, AgentMcpServerSpec, SpawnOptions, SpawnedProcess, Query, McpSdkServerConfigWithInstance } from '@anthropic-ai/claude-agent-sdk';
|
|
3
|
-
export { AgentMcpServerSpec, CanUseTool, HookCallback, HookCallbackMatcher, HookEvent, HookInput, HookJSONOutput, McpSdkServerConfigWithInstance, McpServerConfig, OutputFormat, PermissionBehavior, PermissionResult, PermissionRuleValue, PermissionUpdate, PostToolUseHookInput, PreToolUseHookInput, Query, SessionEndHookInput, SessionStartHookInput, SpawnOptions, SpawnedProcess, UserPromptSubmitHookInput, createSdkMcpServer, tool } from '@anthropic-ai/claude-agent-sdk';
|
|
2
|
+
import { PermissionMode, SdkBeta, SdkPluginConfig, SandboxSettings, Options, McpServerConfig, CanUseTool, AgentMcpServerSpec, SpawnOptions, SpawnedProcess, Query, SdkMcpToolDefinition, McpSdkServerConfigWithInstance } from '@anthropic-ai/claude-agent-sdk';
|
|
3
|
+
export { AgentMcpServerSpec, CanUseTool, HookCallback, HookCallbackMatcher, HookEvent, HookInput, HookJSONOutput, McpSdkServerConfigWithInstance, McpServerConfig, OutputFormat, PermissionBehavior, PermissionResult, PermissionRuleValue, PermissionUpdate, PostToolUseHookInput, PreToolUseHookInput, Query, SessionEndHookInput, SessionStartHookInput, SpawnOptions, SpawnedProcess, TaskCompletedHookInput, TeammateIdleHookInput, UserPromptSubmitHookInput, createSdkMcpServer, tool } from '@anthropic-ai/claude-agent-sdk';
|
|
4
4
|
import { ZodObject, ZodRawShape } from 'zod';
|
|
5
5
|
|
|
6
6
|
type StreamingInputMode = 'auto' | 'always' | 'off';
|
|
@@ -117,6 +117,11 @@ interface ClaudeCodeSettings {
|
|
|
117
117
|
* Resume a specific session by ID
|
|
118
118
|
*/
|
|
119
119
|
resume?: string;
|
|
120
|
+
/**
|
|
121
|
+
* Use a specific session ID for this query.
|
|
122
|
+
* Allows deterministic session identifiers for tracking and correlation.
|
|
123
|
+
*/
|
|
124
|
+
sessionId?: string;
|
|
120
125
|
/**
|
|
121
126
|
* Tools to explicitly allow during execution
|
|
122
127
|
* Examples: ['Read', 'LS', 'Bash(git log:*)']
|
|
@@ -195,6 +200,14 @@ interface ClaudeCodeSettings {
|
|
|
195
200
|
* Enable verbose logging for debugging
|
|
196
201
|
*/
|
|
197
202
|
verbose?: boolean;
|
|
203
|
+
/**
|
|
204
|
+
* Enable programmatic debug logging from the SDK.
|
|
205
|
+
*/
|
|
206
|
+
debug?: boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Path to a file for SDK debug log output.
|
|
209
|
+
*/
|
|
210
|
+
debugFile?: string;
|
|
198
211
|
/**
|
|
199
212
|
* Custom logger for handling warnings and errors.
|
|
200
213
|
* - Set to `false` to disable all logging
|
|
@@ -592,6 +605,12 @@ type ContentAnnotations = {
|
|
|
592
605
|
/** ISO 8601 timestamp of last modification */
|
|
593
606
|
lastModified?: string;
|
|
594
607
|
};
|
|
608
|
+
/**
|
|
609
|
+
* MCP tool annotations for hinting tool behavior to the model.
|
|
610
|
+
* Derived from the SDK's SdkMcpToolDefinition type to stay in sync
|
|
611
|
+
* with the upstream MCP ToolAnnotations definition.
|
|
612
|
+
*/
|
|
613
|
+
type ToolAnnotations = NonNullable<SdkMcpToolDefinition['annotations']>;
|
|
595
614
|
/**
|
|
596
615
|
* Convenience helper to create an SDK MCP server from a simple tool map.
|
|
597
616
|
* Each tool provides a description, a Zod object schema, and a handler.
|
|
@@ -670,6 +689,7 @@ declare function createCustomMcpServer<Tools extends Record<string, {
|
|
|
670
689
|
description: string;
|
|
671
690
|
inputSchema: ZodObject<ZodRawShape>;
|
|
672
691
|
handler: (args: Record<string, unknown>, extra: unknown) => Promise<MinimalCallToolResult>;
|
|
692
|
+
annotations?: ToolAnnotations;
|
|
673
693
|
}>>(config: {
|
|
674
694
|
name: string;
|
|
675
695
|
version?: string;
|
|
@@ -825,4 +845,4 @@ declare function isTimeoutError(error: unknown): boolean;
|
|
|
825
845
|
*/
|
|
826
846
|
declare function getErrorMetadata(error: unknown): ClaudeCodeErrorMetadata | undefined;
|
|
827
847
|
|
|
828
|
-
export { type ClaudeCodeErrorMetadata, ClaudeCodeLanguageModel, type ClaudeCodeLanguageModelOptions, type ClaudeCodeModelId, type ClaudeCodeProvider, type ClaudeCodeProviderSettings, type ClaudeCodeSettings, type Logger, type MessageInjector, claudeCode, createAPICallError, createAuthenticationError, createClaudeCode, createCustomMcpServer, createTimeoutError, getErrorMetadata, isAuthenticationError, isTimeoutError };
|
|
848
|
+
export { type ClaudeCodeErrorMetadata, ClaudeCodeLanguageModel, type ClaudeCodeLanguageModelOptions, type ClaudeCodeModelId, type ClaudeCodeProvider, type ClaudeCodeProviderSettings, type ClaudeCodeSettings, type Logger, type MessageInjector, type MinimalCallToolResult, type ToolAnnotations, claudeCode, createAPICallError, createAuthenticationError, createClaudeCode, createCustomMcpServer, createTimeoutError, getErrorMetadata, isAuthenticationError, isTimeoutError };
|
package/dist/index.js
CHANGED
|
@@ -367,18 +367,33 @@ function getErrorMetadata(error) {
|
|
|
367
367
|
}
|
|
368
368
|
|
|
369
369
|
// src/map-claude-code-finish-reason.ts
|
|
370
|
-
function mapClaudeCodeFinishReason(subtype) {
|
|
370
|
+
function mapClaudeCodeFinishReason(subtype, stopReason) {
|
|
371
|
+
if (stopReason != null) {
|
|
372
|
+
switch (stopReason) {
|
|
373
|
+
case "end_turn":
|
|
374
|
+
return { unified: "stop", raw: "end_turn" };
|
|
375
|
+
case "max_tokens":
|
|
376
|
+
return { unified: "length", raw: "max_tokens" };
|
|
377
|
+
case "stop_sequence":
|
|
378
|
+
return { unified: "stop", raw: "stop_sequence" };
|
|
379
|
+
case "tool_use":
|
|
380
|
+
return { unified: "tool-calls", raw: "tool_use" };
|
|
381
|
+
default:
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
const raw = stopReason ?? subtype;
|
|
371
386
|
switch (subtype) {
|
|
372
387
|
case "success":
|
|
373
|
-
return { unified: "stop", raw
|
|
388
|
+
return { unified: "stop", raw };
|
|
374
389
|
case "error_max_turns":
|
|
375
|
-
return { unified: "length", raw
|
|
390
|
+
return { unified: "length", raw };
|
|
376
391
|
case "error_during_execution":
|
|
377
|
-
return { unified: "error", raw
|
|
392
|
+
return { unified: "error", raw };
|
|
378
393
|
case void 0:
|
|
379
|
-
return { unified: "stop", raw
|
|
394
|
+
return { unified: "stop", raw };
|
|
380
395
|
default:
|
|
381
|
-
return { unified: "other", raw
|
|
396
|
+
return { unified: "other", raw };
|
|
382
397
|
}
|
|
383
398
|
}
|
|
384
399
|
|
|
@@ -428,6 +443,7 @@ var claudeCodeSettingsSchema = z.object({
|
|
|
428
443
|
permissionPromptToolName: z.string().optional(),
|
|
429
444
|
continue: z.boolean().optional(),
|
|
430
445
|
resume: z.string().optional(),
|
|
446
|
+
sessionId: z.string().optional(),
|
|
431
447
|
allowedTools: z.array(z.string()).optional(),
|
|
432
448
|
disallowedTools: z.array(z.string()).optional(),
|
|
433
449
|
betas: z.array(z.string()).optional(),
|
|
@@ -497,6 +513,8 @@ var claudeCodeSettingsSchema = z.object({
|
|
|
497
513
|
])
|
|
498
514
|
).optional(),
|
|
499
515
|
verbose: z.boolean().optional(),
|
|
516
|
+
debug: z.boolean().optional(),
|
|
517
|
+
debugFile: z.string().optional(),
|
|
500
518
|
logger: z.union([z.literal(false), loggerFunctionSchema]).optional(),
|
|
501
519
|
env: z.record(z.string(), z.string().optional()).optional(),
|
|
502
520
|
additionalDirectories: z.array(z.string()).optional(),
|
|
@@ -1223,6 +1241,15 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
|
|
|
1223
1241
|
if (this.settings.hooks) {
|
|
1224
1242
|
opts.hooks = this.settings.hooks;
|
|
1225
1243
|
}
|
|
1244
|
+
if (this.settings.sessionId !== void 0) {
|
|
1245
|
+
opts.sessionId = this.settings.sessionId;
|
|
1246
|
+
}
|
|
1247
|
+
if (this.settings.debug !== void 0) {
|
|
1248
|
+
opts.debug = this.settings.debug;
|
|
1249
|
+
}
|
|
1250
|
+
if (this.settings.debugFile !== void 0) {
|
|
1251
|
+
opts.debugFile = this.settings.debugFile;
|
|
1252
|
+
}
|
|
1226
1253
|
const sdkOverrides = sdkOptions ? sdkOptions : void 0;
|
|
1227
1254
|
const sdkEnv = sdkOverrides && typeof sdkOverrides.env === "object" && sdkOverrides.env !== null ? sdkOverrides.env : void 0;
|
|
1228
1255
|
const sdkStderr = sdkOverrides && typeof sdkOverrides.stderr === "function" ? sdkOverrides.stderr : void 0;
|
|
@@ -1426,7 +1453,8 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
|
|
|
1426
1453
|
`[claude-code] Token usage - Input: ${usage.inputTokens.total}, Output: ${usage.outputTokens.total}`
|
|
1427
1454
|
);
|
|
1428
1455
|
}
|
|
1429
|
-
|
|
1456
|
+
const stopReason = "stop_reason" in message ? message.stop_reason : void 0;
|
|
1457
|
+
finishReason = mapClaudeCodeFinishReason(message.subtype, stopReason);
|
|
1430
1458
|
this.logger.debug(`[claude-code] Finish reason: ${finishReason.unified}`);
|
|
1431
1459
|
} else if (message.type === "system" && message.subtype === "init") {
|
|
1432
1460
|
this.setSessionId(message.session_id);
|
|
@@ -2169,8 +2197,10 @@ var ClaudeCodeLanguageModel = class _ClaudeCodeLanguageModel {
|
|
|
2169
2197
|
`[claude-code] Stream token usage - Input: ${usage.inputTokens.total}, Output: ${usage.outputTokens.total}`
|
|
2170
2198
|
);
|
|
2171
2199
|
}
|
|
2200
|
+
const stopReason = "stop_reason" in message ? message.stop_reason : void 0;
|
|
2172
2201
|
const finishReason = mapClaudeCodeFinishReason(
|
|
2173
|
-
message.subtype
|
|
2202
|
+
message.subtype,
|
|
2203
|
+
stopReason
|
|
2174
2204
|
);
|
|
2175
2205
|
this.logger.debug(`[claude-code] Stream finish reason: ${finishReason.unified}`);
|
|
2176
2206
|
this.setSessionId(message.session_id);
|
|
@@ -2431,7 +2461,8 @@ function createCustomMcpServer(config) {
|
|
|
2431
2461
|
name,
|
|
2432
2462
|
def.description,
|
|
2433
2463
|
def.inputSchema.shape,
|
|
2434
|
-
(args, extra) => def.handler(args, extra)
|
|
2464
|
+
(args, extra) => def.handler(args, extra),
|
|
2465
|
+
def.annotations ? { annotations: def.annotations } : void 0
|
|
2435
2466
|
)
|
|
2436
2467
|
);
|
|
2437
2468
|
return createSdkMcpServer({ name: config.name, version: config.version, tools: defs });
|