ai-sdk-provider-claude-code 3.5.2 → 4.0.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 +223 -120
- package/dist/index.d.ts +236 -51
- package/dist/index.js +951 -223
- package/dist/index.js.map +1 -1
- package/docs/sessions.md +4 -4
- package/package.json +12 -14
- package/dist/index.cjs +0 -4025
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -1329
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,133 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Options, ThinkingConfig, EffortLevel, PermissionMode, SdkBeta, SdkPluginConfig, SandboxSettings, Settings, ToolConfig, McpServerConfig, CanUseTool, OnUserDialog, AgentDefinition, SessionStore, SessionStoreFlush, SpawnOptions, SpawnedProcess, Query, SdkMcpToolDefinition, McpSdkServerConfigWithInstance } from '@anthropic-ai/claude-agent-sdk';
|
|
3
|
-
export { AbortError, AccountInfo, AgentDefinition, AgentInfo, AgentMcpServerSpec, AsyncHookJSONOutput, CanUseTool, ConfigChangeHookInput, CwdChangedHookInput, CwdChangedHookSpecificOutput, EffortLevel, ElicitationHookInput, ElicitationHookSpecificOutput, ElicitationResultHookInput, ElicitationResultHookSpecificOutput, FileChangedHookInput, FileChangedHookSpecificOutput, ForkSessionOptions, ForkSessionResult, GetSessionInfoOptions, GetSessionMessagesOptions, GetSubagentMessagesOptions, HOOK_EVENTS, HookCallback, HookCallbackMatcher, HookEvent, HookInput, HookJSONOutput, HookPermissionDecision, ImportSessionToStoreOptions, InMemorySessionStore, InstructionsLoadedHookInput, ListSessionsOptions, ListSubagentsOptions, McpHttpServerConfig, McpSSEServerConfig, McpSdkServerConfig, McpSdkServerConfigWithInstance, McpServerConfig, McpServerConfigForProcessTransport, McpServerStatus, McpSetServersResult, McpStdioServerConfig, MessageDisplayHookInput, MessageDisplayHookSpecificOutput, ModelInfo, NotificationHookInput, NotificationHookSpecificOutput, OnUserDialog, Options, OutputFormat, PermissionBehavior, PermissionDecisionClassification, PermissionDeniedHookInput, PermissionDeniedHookSpecificOutput, PermissionMode, PermissionRequestHookInput, PermissionRequestHookSpecificOutput, PermissionResult, PermissionRuleValue, PermissionUpdate, PermissionUpdateDestination, PostCompactHookInput, PostToolBatchHookInput, PostToolBatchHookSpecificOutput, PostToolUseFailureHookInput, PostToolUseFailureHookSpecificOutput, PostToolUseHookInput, PostToolUseHookSpecificOutput, PreCompactHookInput, PreToolUseHookInput, PreToolUseHookSpecificOutput, Query, RewindFilesResult, SDKMessage, SDKMessageOrigin, SDKSessionInfo, SDKUserMessage, SYSTEM_PROMPT_DYNAMIC_BOUNDARY, SandboxFilesystemConfig, SandboxIgnoreViolations, SandboxNetworkConfig, SandboxSettings, SdkBeta, SdkPluginConfig, SessionCronSummary, SessionEndHookInput, SessionKey, SessionMessage, SessionMutationOptions, SessionStartHookInput, SessionStartHookSpecificOutput, SessionStore, SessionStoreEntry, SessionStoreFlush, SessionSummaryEntry, Settings, SetupHookInput, SetupHookSpecificOutput, SlashCommand, SpawnOptions, SpawnedProcess, StopFailureHookInput, StopHookInput, StopHookSpecificOutput, SubagentStartHookInput, SubagentStartHookSpecificOutput, SubagentStopHookInput, SubagentStopHookSpecificOutput, SyncHookJSONOutput, TaskCompletedHookInput, TaskCreatedHookInput, TeammateIdleHookInput, TerminalReason, ThinkingAdaptive, ThinkingConfig, ThinkingDisabled, ThinkingEnabled, ToolConfig, UserDialogRequest, UserDialogResult, UserPromptExpansionHookInput, UserPromptExpansionHookSpecificOutput, UserPromptSubmitHookInput, UserPromptSubmitHookSpecificOutput, WarmQuery, WorktreeCreateHookInput, WorktreeCreateHookSpecificOutput, WorktreeRemoveHookInput, createSdkMcpServer, deleteSession, foldSessionSummary, forkSession, getSessionInfo, getSessionMessages, getSubagentMessages, importSessionToStore, listSessions, listSubagents, renameSession, startup, tagSession, tool } from '@anthropic-ai/claude-agent-sdk';
|
|
1
|
+
import { LanguageModelV4, LanguageModelV4CallOptions, LanguageModelV4GenerateResult, LanguageModelV4StreamResult, ProviderV4, APICallError, LoadAPIKeyError } from '@ai-sdk/provider';
|
|
2
|
+
import { Options, ThinkingConfig, EffortLevel, PermissionMode, SdkBeta, SdkPluginConfig, SandboxSettings, Settings, ToolConfig, SDKMessage, SDKTaskStartedMessage, SDKTaskProgressMessage, SDKTaskUpdatedMessage, SDKTaskNotificationMessage, SDKHookStartedMessage, SDKHookProgressMessage, SDKHookResponseMessage, McpServerStatus, McpServerConfig, CanUseTool, OnUserDialog, OnElicitation, AgentDefinition, SessionStore, SessionStoreFlush, SpawnOptions, SpawnedProcess, Query, McpSetServersResult, SDKControlGetContextUsageResponse, RewindFilesResult, SDKUserMessage, SdkMcpToolDefinition, McpSdkServerConfigWithInstance } from '@anthropic-ai/claude-agent-sdk';
|
|
3
|
+
export { AbortError, AccountInfo, AgentDefinition, AgentInfo, AgentMcpServerSpec, AsyncHookJSONOutput, CanUseTool, ConfigChangeHookInput, CwdChangedHookInput, CwdChangedHookSpecificOutput, EffortLevel, ElicitationHookInput, ElicitationHookSpecificOutput, ElicitationResultHookInput, ElicitationResultHookSpecificOutput, FileChangedHookInput, FileChangedHookSpecificOutput, ForkSessionOptions, ForkSessionResult, GetSessionInfoOptions, GetSessionMessagesOptions, GetSubagentMessagesOptions, HOOK_EVENTS, HookCallback, HookCallbackMatcher, HookEvent, HookInput, HookJSONOutput, HookPermissionDecision, ImportSessionToStoreOptions, InMemorySessionStore, InstructionsLoadedHookInput, ListSessionsOptions, ListSubagentsOptions, McpHttpServerConfig, McpSSEServerConfig, McpSdkServerConfig, McpSdkServerConfigWithInstance, McpServerConfig, McpServerConfigForProcessTransport, McpServerStatus, McpSetServersResult, McpStdioServerConfig, MessageDisplayHookInput, MessageDisplayHookSpecificOutput, ModelInfo, NotificationHookInput, NotificationHookSpecificOutput, OnElicitation, OnUserDialog, Options, OutputFormat, PermissionBehavior, PermissionDecisionClassification, PermissionDeniedHookInput, PermissionDeniedHookSpecificOutput, PermissionMode, PermissionRequestHookInput, PermissionRequestHookSpecificOutput, PermissionResult, PermissionRuleValue, PermissionUpdate, PermissionUpdateDestination, PolicySettingsOrigin, PostCompactHookInput, PostToolBatchHookInput, PostToolBatchHookSpecificOutput, PostToolUseFailureHookInput, PostToolUseFailureHookSpecificOutput, PostToolUseHookInput, PostToolUseHookSpecificOutput, PreCompactHookInput, PreToolUseHookInput, PreToolUseHookSpecificOutput, ProvenanceEntry, Query, ResolveSettingsOptions, ResolvedSettingSource, ResolvedSettings, RewindFilesResult, SDKControlGetContextUsageResponse, SDKFilesPersistedEvent, SDKHookProgressMessage, SDKHookResponseMessage, SDKHookStartedMessage, SDKMessage, SDKMessageOrigin, SDKSessionInfo, SDKTaskNotificationMessage, SDKTaskProgressMessage, SDKTaskStartedMessage, SDKTaskUpdatedMessage, SDKUserMessage, SYSTEM_PROMPT_DYNAMIC_BOUNDARY, SandboxCredentialsConfig, SandboxFilesystemConfig, SandboxIgnoreViolations, SandboxNetworkConfig, SandboxSettings, SdkBeta, SdkPluginConfig, SessionCronSummary, SessionEndHookInput, SessionKey, SessionMessage, SessionMutationOptions, SessionStartHookInput, SessionStartHookSpecificOutput, SessionStore, SessionStoreEntry, SessionStoreFlush, SessionSummaryEntry, Settings, SetupHookInput, SetupHookSpecificOutput, SlashCommand, SpawnOptions, SpawnedProcess, StopFailureHookInput, StopHookInput, StopHookSpecificOutput, SubagentStartHookInput, SubagentStartHookSpecificOutput, SubagentStopHookInput, SubagentStopHookSpecificOutput, SyncHookJSONOutput, TaskCompletedHookInput, TaskCreatedHookInput, TeammateIdleHookInput, TerminalReason, ThinkingAdaptive, ThinkingConfig, ThinkingDisabled, ThinkingEnabled, ToolConfig, UserDialogRequest, UserDialogResult, UserPromptExpansionHookInput, UserPromptExpansionHookSpecificOutput, UserPromptSubmitHookInput, UserPromptSubmitHookSpecificOutput, WarmQuery, WorktreeCreateHookInput, WorktreeCreateHookSpecificOutput, WorktreeRemoveHookInput, createSdkMcpServer, deleteSession, filterEscalatingDefaultMode, foldSessionSummary, forkSession, getSessionInfo, getSessionMessages, getSubagentMessages, importSessionToStore, listSessions, listSubagents, renameSession, resolveSettings, startup, tagSession, tool } from '@anthropic-ai/claude-agent-sdk';
|
|
4
4
|
import { ZodObject, ZodRawShape } from 'zod';
|
|
5
5
|
|
|
6
6
|
type StreamingInputMode = 'auto' | 'always' | 'off';
|
|
7
|
+
/**
|
|
8
|
+
* Normalized Task/subagent lifecycle events surfaced by the provider.
|
|
9
|
+
* The original Agent SDK message is preserved on `raw`.
|
|
10
|
+
*/
|
|
11
|
+
type ClaudeCodeTaskEvent = {
|
|
12
|
+
subtype: 'task_started';
|
|
13
|
+
taskId: string;
|
|
14
|
+
toolUseId?: string;
|
|
15
|
+
description: string;
|
|
16
|
+
subagentType?: string;
|
|
17
|
+
taskType?: string;
|
|
18
|
+
workflowName?: string;
|
|
19
|
+
prompt?: string;
|
|
20
|
+
skipTranscript?: boolean;
|
|
21
|
+
uuid: string;
|
|
22
|
+
sessionId: string;
|
|
23
|
+
raw: SDKTaskStartedMessage;
|
|
24
|
+
} | {
|
|
25
|
+
subtype: 'task_progress';
|
|
26
|
+
taskId: string;
|
|
27
|
+
toolUseId?: string;
|
|
28
|
+
description: string;
|
|
29
|
+
subagentType?: string;
|
|
30
|
+
usage: SDKTaskProgressMessage['usage'];
|
|
31
|
+
lastToolName?: string;
|
|
32
|
+
summary?: string;
|
|
33
|
+
uuid: string;
|
|
34
|
+
sessionId: string;
|
|
35
|
+
raw: SDKTaskProgressMessage;
|
|
36
|
+
} | {
|
|
37
|
+
subtype: 'task_updated';
|
|
38
|
+
taskId: string;
|
|
39
|
+
patch: SDKTaskUpdatedMessage['patch'];
|
|
40
|
+
uuid: string;
|
|
41
|
+
sessionId: string;
|
|
42
|
+
raw: SDKTaskUpdatedMessage;
|
|
43
|
+
} | {
|
|
44
|
+
subtype: 'task_notification';
|
|
45
|
+
taskId: string;
|
|
46
|
+
toolUseId?: string;
|
|
47
|
+
status: SDKTaskNotificationMessage['status'];
|
|
48
|
+
outputFile: string;
|
|
49
|
+
summary: string;
|
|
50
|
+
usage?: SDKTaskNotificationMessage['usage'];
|
|
51
|
+
skipTranscript?: boolean;
|
|
52
|
+
uuid: string;
|
|
53
|
+
sessionId: string;
|
|
54
|
+
raw: SDKTaskNotificationMessage;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Normalized hook lifecycle events surfaced by the provider.
|
|
58
|
+
* The original Agent SDK message is preserved on `raw`.
|
|
59
|
+
*/
|
|
60
|
+
type ClaudeCodeHookEvent = {
|
|
61
|
+
subtype: 'hook_started';
|
|
62
|
+
hookId: string;
|
|
63
|
+
hookName: string;
|
|
64
|
+
hookEvent: string;
|
|
65
|
+
uuid: string;
|
|
66
|
+
sessionId: string;
|
|
67
|
+
raw: SDKHookStartedMessage;
|
|
68
|
+
} | {
|
|
69
|
+
subtype: 'hook_progress';
|
|
70
|
+
hookId: string;
|
|
71
|
+
hookName: string;
|
|
72
|
+
hookEvent: string;
|
|
73
|
+
stdout: string;
|
|
74
|
+
stderr: string;
|
|
75
|
+
output: string;
|
|
76
|
+
uuid: string;
|
|
77
|
+
sessionId: string;
|
|
78
|
+
raw: SDKHookProgressMessage;
|
|
79
|
+
} | {
|
|
80
|
+
subtype: 'hook_response';
|
|
81
|
+
hookId: string;
|
|
82
|
+
hookName: string;
|
|
83
|
+
hookEvent: string;
|
|
84
|
+
output: string;
|
|
85
|
+
stdout: string;
|
|
86
|
+
stderr: string;
|
|
87
|
+
exitCode?: number;
|
|
88
|
+
outcome: SDKHookResponseMessage['outcome'];
|
|
89
|
+
uuid: string;
|
|
90
|
+
sessionId: string;
|
|
91
|
+
raw: SDKHookResponseMessage;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Snapshot of MCP server connection state reported by the provider.
|
|
95
|
+
*/
|
|
96
|
+
interface ClaudeCodeMcpStatusEvent {
|
|
97
|
+
subtype: 'init';
|
|
98
|
+
sessionId?: string;
|
|
99
|
+
uuid?: string;
|
|
100
|
+
servers: McpServerStatus[];
|
|
101
|
+
raw?: unknown;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Safe runtime controller for common Agent SDK Query operations.
|
|
105
|
+
* The underlying Query is intentionally exposed as `rawQuery`.
|
|
106
|
+
*/
|
|
107
|
+
interface ClaudeCodeQueryController {
|
|
108
|
+
readonly rawQuery: Query;
|
|
109
|
+
interrupt(): Promise<void>;
|
|
110
|
+
setPermissionMode(mode: PermissionMode): Promise<void>;
|
|
111
|
+
setMcpPermissionModeOverride(serverName: string, mode: 'default' | 'auto' | null): Promise<{
|
|
112
|
+
warning?: string;
|
|
113
|
+
}>;
|
|
114
|
+
setModel(model?: string): Promise<void>;
|
|
115
|
+
setMaxThinkingTokens(maxThinkingTokens: number | null, thinkingDisplay?: 'summarized' | 'omitted' | null): Promise<void>;
|
|
116
|
+
applyFlagSettings(settings: {
|
|
117
|
+
[K in keyof Settings]?: Settings[K] | null;
|
|
118
|
+
}): Promise<void>;
|
|
119
|
+
mcpServerStatus(): Promise<McpServerStatus[]>;
|
|
120
|
+
reconnectMcpServer(serverName: string): Promise<void>;
|
|
121
|
+
toggleMcpServer(serverName: string, enabled: boolean): Promise<void>;
|
|
122
|
+
setMcpServers(servers: Record<string, McpServerConfig>): Promise<McpSetServersResult>;
|
|
123
|
+
getContextUsage(): Promise<SDKControlGetContextUsageResponse>;
|
|
124
|
+
rewindFiles(userMessageId: string, options?: {
|
|
125
|
+
dryRun?: boolean;
|
|
126
|
+
}): Promise<RewindFilesResult>;
|
|
127
|
+
stopTask(taskId: string): Promise<void>;
|
|
128
|
+
backgroundTasks(toolUseId?: string): Promise<boolean>;
|
|
129
|
+
streamInput?(stream: AsyncIterable<SDKUserMessage>): Promise<void>;
|
|
130
|
+
}
|
|
7
131
|
/**
|
|
8
132
|
* Logger interface for custom logging.
|
|
9
133
|
* Allows consumers to provide their own logging implementation
|
|
@@ -117,6 +241,7 @@ interface ClaudeCodeSettings {
|
|
|
117
241
|
/**
|
|
118
242
|
* Enable prompt suggestions. When true, the agent emits a predicted
|
|
119
243
|
* next user prompt after each turn (arrives after the result message).
|
|
244
|
+
* Disabled by default; set this explicitly to true to receive suggestions.
|
|
120
245
|
*/
|
|
121
246
|
promptSuggestions?: boolean;
|
|
122
247
|
/**
|
|
@@ -285,6 +410,31 @@ interface ClaudeCodeSettings {
|
|
|
285
410
|
* @default false
|
|
286
411
|
*/
|
|
287
412
|
includeHookEvents?: boolean;
|
|
413
|
+
/**
|
|
414
|
+
* Callback invoked for every raw Agent SDK message emitted by the query.
|
|
415
|
+
* Use this as a forward-compatible escape hatch when the provider does not
|
|
416
|
+
* yet expose a dedicated callback or metadata field for a new SDK subtype.
|
|
417
|
+
*/
|
|
418
|
+
onSdkMessage?: (message: SDKMessage) => void | PromiseLike<void>;
|
|
419
|
+
/**
|
|
420
|
+
* Callback invoked for Task/subagent lifecycle messages after they are
|
|
421
|
+
* normalized to camelCase provider events. The original SDK message is
|
|
422
|
+
* available on `event.raw`.
|
|
423
|
+
*/
|
|
424
|
+
onTaskEvent?: (event: ClaudeCodeTaskEvent) => void | PromiseLike<void>;
|
|
425
|
+
/**
|
|
426
|
+
* Callback invoked for hook lifecycle messages when hook events are emitted.
|
|
427
|
+
* Set `includeHookEvents: true` to receive all hook event types; the SDK may
|
|
428
|
+
* still emit startup/setup hook events independently.
|
|
429
|
+
*/
|
|
430
|
+
onHookEvent?: (event: ClaudeCodeHookEvent) => void | PromiseLike<void>;
|
|
431
|
+
/**
|
|
432
|
+
* Callback invoked once with the initial MCP server status snapshot observed
|
|
433
|
+
* from the SDK init message. For live status after runtime MCP changes, call
|
|
434
|
+
* `controller.mcpServerStatus()` while the query is live and SDK streaming
|
|
435
|
+
* input/output is active.
|
|
436
|
+
*/
|
|
437
|
+
onMcpStatusChange?: (status: ClaudeCodeMcpStatusEvent) => void | PromiseLike<void>;
|
|
288
438
|
/**
|
|
289
439
|
* MCP server configuration
|
|
290
440
|
*/
|
|
@@ -350,6 +500,12 @@ interface ClaudeCodeSettings {
|
|
|
350
500
|
* make the CLI emit dialogs.
|
|
351
501
|
*/
|
|
352
502
|
onUserDialog?: OnUserDialog;
|
|
503
|
+
/**
|
|
504
|
+
* Callback for MCP elicitation requests that are not handled by hooks.
|
|
505
|
+
* Return an Agent SDK elicitation result to accept, decline, or cancel the
|
|
506
|
+
* request; when omitted, the SDK declines unhandled elicitations.
|
|
507
|
+
*/
|
|
508
|
+
onElicitation?: OnElicitation;
|
|
353
509
|
/**
|
|
354
510
|
* Dialog kinds (`request_user_dialog` `dialog_kind` values, e.g.
|
|
355
511
|
* `'refusal_fallback_prompt'`) that your `onUserDialog` callback can
|
|
@@ -365,10 +521,12 @@ interface ClaudeCodeSettings {
|
|
|
365
521
|
*/
|
|
366
522
|
supportedDialogKinds?: string[];
|
|
367
523
|
/**
|
|
368
|
-
* Controls whether to send streaming input to the SDK
|
|
369
|
-
* - 'auto' (default): stream when canUseTool is provided
|
|
524
|
+
* Controls whether to send streaming input to the SDK.
|
|
525
|
+
* - 'auto' (default): stream when canUseTool is provided or the prompt contains
|
|
526
|
+
* image parts
|
|
370
527
|
* - 'always': always stream
|
|
371
|
-
* - 'off':
|
|
528
|
+
* - 'off': disable streaming input, including streaming image input; emits a
|
|
529
|
+
* warning when the prompt contains image parts
|
|
372
530
|
*/
|
|
373
531
|
streamingInput?: StreamingInputMode;
|
|
374
532
|
/**
|
|
@@ -420,6 +578,12 @@ interface ClaudeCodeSettings {
|
|
|
420
578
|
* Additional directories Claude can access.
|
|
421
579
|
*/
|
|
422
580
|
additionalDirectories?: string[];
|
|
581
|
+
/**
|
|
582
|
+
* Named agent persona for the main conversation. The agent must be defined
|
|
583
|
+
* in `agents` or loaded from settings; its prompt/tools/model augment the
|
|
584
|
+
* main thread similarly to the Claude Code `--agent` flag.
|
|
585
|
+
*/
|
|
586
|
+
agent?: string;
|
|
423
587
|
/**
|
|
424
588
|
* Programmatically defined subagents.
|
|
425
589
|
*
|
|
@@ -538,6 +702,12 @@ interface ClaudeCodeSettings {
|
|
|
538
702
|
* ```
|
|
539
703
|
*/
|
|
540
704
|
onQueryCreated?: (query: Query) => void;
|
|
705
|
+
/**
|
|
706
|
+
* Callback invoked when a safe Claude Code query controller is created.
|
|
707
|
+
* Prefer this over `onQueryCreated` for common runtime controls; the raw
|
|
708
|
+
* SDK Query remains available as `controller.rawQuery`.
|
|
709
|
+
*/
|
|
710
|
+
onQueryControllerCreated?: (controller: ClaudeCodeQueryController) => void | PromiseLike<void>;
|
|
541
711
|
/**
|
|
542
712
|
* Callback invoked when streaming input mode starts.
|
|
543
713
|
* Provides a MessageInjector that can be used to inject messages mid-session.
|
|
@@ -562,14 +732,14 @@ interface ClaudeCodeSettings {
|
|
|
562
732
|
onStreamStart?: (injector: MessageInjector) => void;
|
|
563
733
|
/**
|
|
564
734
|
* Callback invoked when the agent emits a prompt suggestion (a predicted
|
|
565
|
-
* next user prompt). Suggestions are
|
|
566
|
-
* `true`
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
735
|
+
* next user prompt). Suggestions are emitted only when `promptSuggestions`
|
|
736
|
+
* is `true` (set via settings or `sdkOptions`); when it is unset, the CLI
|
|
737
|
+
* emits none and this callback never fires. When the callback is set and
|
|
738
|
+
* `promptSuggestions !== false`, the provider drains post-result messages
|
|
739
|
+
* to deliver the suggestion. Delivery is still subject to CLI heuristics —
|
|
740
|
+
* suppressed on the first turn, after API errors, in plan mode, and by
|
|
741
|
+
* `CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=false` — so it may not fire on every
|
|
742
|
+
* enabled turn.
|
|
573
743
|
*
|
|
574
744
|
* The SDK emits at most one `prompt_suggestion` message per turn, and it
|
|
575
745
|
* arrives AFTER the `result` message — i.e. after the AI SDK response has
|
|
@@ -642,7 +812,7 @@ interface MessageInjector {
|
|
|
642
812
|
interface ClaudeCodeLanguageModelOptions {
|
|
643
813
|
/**
|
|
644
814
|
* The model identifier to use.
|
|
645
|
-
* Can be 'opus', 'sonnet', 'haiku', or a custom model string.
|
|
815
|
+
* Can be 'fable', 'opus', 'sonnet', 'haiku', or a custom model string.
|
|
646
816
|
*/
|
|
647
817
|
id: ClaudeCodeModelId;
|
|
648
818
|
/**
|
|
@@ -657,23 +827,25 @@ interface ClaudeCodeLanguageModelOptions {
|
|
|
657
827
|
}
|
|
658
828
|
/**
|
|
659
829
|
* Supported Claude model identifiers.
|
|
660
|
-
* - '
|
|
830
|
+
* - 'fable': Claude Fable (most capable)
|
|
831
|
+
* - 'opus': Claude Opus (highly capable)
|
|
661
832
|
* - 'sonnet': Claude Sonnet (balanced performance)
|
|
662
833
|
* - 'haiku': Claude Haiku (fastest, most cost-effective)
|
|
663
834
|
* - Custom string: Any full model identifier (e.g., 'claude-opus-4-5', 'claude-sonnet-4-5-20250514')
|
|
664
835
|
*
|
|
665
836
|
* @example
|
|
666
837
|
* ```typescript
|
|
838
|
+
* const fableModel = claudeCode('fable');
|
|
667
839
|
* const opusModel = claudeCode('opus');
|
|
668
840
|
* const sonnetModel = claudeCode('sonnet');
|
|
669
841
|
* const haikuModel = claudeCode('haiku');
|
|
670
|
-
* const customModel = claudeCode('claude-
|
|
842
|
+
* const customModel = claudeCode('claude-fable-5');
|
|
671
843
|
* ```
|
|
672
844
|
*/
|
|
673
|
-
type ClaudeCodeModelId = 'opus' | 'sonnet' | 'haiku' | (string & {});
|
|
845
|
+
type ClaudeCodeModelId = 'fable' | 'opus' | 'sonnet' | 'haiku' | (string & {});
|
|
674
846
|
/**
|
|
675
847
|
* Language model implementation for Claude Code SDK.
|
|
676
|
-
* This class implements the AI SDK's
|
|
848
|
+
* This class implements the AI SDK's LanguageModelV4 interface to provide
|
|
677
849
|
* integration with Claude models through the Claude Agent SDK.
|
|
678
850
|
*
|
|
679
851
|
* Features:
|
|
@@ -694,13 +866,17 @@ type ClaudeCodeModelId = 'opus' | 'sonnet' | 'haiku' | (string & {});
|
|
|
694
866
|
* });
|
|
695
867
|
*
|
|
696
868
|
* const result = await model.doGenerate({
|
|
697
|
-
* prompt: [
|
|
698
|
-
*
|
|
869
|
+
* prompt: [
|
|
870
|
+
* {
|
|
871
|
+
* role: 'user',
|
|
872
|
+
* content: [{ type: 'text', text: 'Hello!' }]
|
|
873
|
+
* }
|
|
874
|
+
* ]
|
|
699
875
|
* });
|
|
700
876
|
* ```
|
|
701
877
|
*/
|
|
702
|
-
declare class ClaudeCodeLanguageModel implements
|
|
703
|
-
readonly specificationVersion: "
|
|
878
|
+
declare class ClaudeCodeLanguageModel implements LanguageModelV4 {
|
|
879
|
+
readonly specificationVersion: "v4";
|
|
704
880
|
readonly defaultObjectGenerationMode: "json";
|
|
705
881
|
readonly supportsImageUrls = false;
|
|
706
882
|
readonly supportedUrls: {};
|
|
@@ -721,6 +897,12 @@ declare class ClaudeCodeLanguageModel implements LanguageModelV3 {
|
|
|
721
897
|
private getModel;
|
|
722
898
|
private getSanitizedSdkOptions;
|
|
723
899
|
private getEffectiveResume;
|
|
900
|
+
private invokeObservabilityCallback;
|
|
901
|
+
private invokeSdkMessageCallback;
|
|
902
|
+
private notifyQueryCreated;
|
|
903
|
+
private trackTaskEvent;
|
|
904
|
+
private trackHookEvent;
|
|
905
|
+
private trackMcpStatusFromInit;
|
|
724
906
|
/**
|
|
725
907
|
* Single source of truth for the CLI's `--session-id` exclusivity rule.
|
|
726
908
|
*
|
|
@@ -787,20 +969,12 @@ declare class ClaudeCodeLanguageModel implements LanguageModelV3 {
|
|
|
787
969
|
private buildToolResultPart;
|
|
788
970
|
private serializeToolError;
|
|
789
971
|
/**
|
|
790
|
-
* Builds a provider
|
|
791
|
-
* `tool_error` block
|
|
792
|
-
*
|
|
972
|
+
* Builds a V4 provider `tool-result` part with `isError: true` from a
|
|
973
|
+
* user-message `tool_error` block. V4 has no provider-level `tool-error`
|
|
974
|
+
* content or stream part; AI SDK core derives user-facing tool-error
|
|
975
|
+
* semantics from this result while preserving providerMetadata.
|
|
793
976
|
*/
|
|
794
|
-
private
|
|
795
|
-
/**
|
|
796
|
-
* Builds a V3 `tool-result` CONTENT part with `isError: true` from a
|
|
797
|
-
* user-message `tool_error` block (doGenerate only). The V3 content union
|
|
798
|
-
* has no `tool-error` member and AI SDK core's asContent() silently drops
|
|
799
|
-
* unknown content part types, so an extension tool-error part would never
|
|
800
|
-
* reach `generateText` users — an isError tool-result, by contrast,
|
|
801
|
-
* round-trips into a proper tool-error part in steps content.
|
|
802
|
-
*/
|
|
803
|
-
private buildToolErrorResultPart;
|
|
977
|
+
private buildErroredToolResultPart;
|
|
804
978
|
/**
|
|
805
979
|
* Policy (P3): late-frame drop guard, shared by all four tool_result/tool_error
|
|
806
980
|
* sites (doGenerate result+error, doStream result+error). When a frame's tool
|
|
@@ -810,6 +984,8 @@ declare class ClaudeCodeLanguageModel implements LanguageModelV3 {
|
|
|
810
984
|
* lockstep so a future tombstone change can't be applied to only some of them.
|
|
811
985
|
*/
|
|
812
986
|
private isRetractedToolFrame;
|
|
987
|
+
private resolvePortableReasoningOptions;
|
|
988
|
+
private applyClaudeReasoningProviderOptions;
|
|
813
989
|
private generateAllWarnings;
|
|
814
990
|
private createQueryOptions;
|
|
815
991
|
private handleClaudeCodeError;
|
|
@@ -847,17 +1023,17 @@ declare class ClaudeCodeLanguageModel implements LanguageModelV3 {
|
|
|
847
1023
|
* suggestion arrives AFTER the result message; the SDK emits at most one
|
|
848
1024
|
* per turn, so stop once it is delivered, and a timeout closes the
|
|
849
1025
|
* iterator (tearing down the subprocess) if the CLI lingers after the
|
|
850
|
-
* result without emitting one.
|
|
851
|
-
*
|
|
1026
|
+
* result without emitting one. Drained messages still pass through the
|
|
1027
|
+
* generic raw SDK callback before prompt-specific handling.
|
|
852
1028
|
*/
|
|
853
1029
|
private drainPromptSuggestion;
|
|
854
|
-
doGenerate(options:
|
|
855
|
-
doStream(options:
|
|
1030
|
+
doGenerate(options: LanguageModelV4CallOptions): Promise<LanguageModelV4GenerateResult>;
|
|
1031
|
+
doStream(options: LanguageModelV4CallOptions): Promise<LanguageModelV4StreamResult>;
|
|
856
1032
|
private serializeWarningsForMetadata;
|
|
857
1033
|
}
|
|
858
1034
|
|
|
859
1035
|
/**
|
|
860
|
-
* Claude Code provider interface that extends the AI SDK's
|
|
1036
|
+
* Claude Code provider interface that extends the AI SDK's ProviderV4.
|
|
861
1037
|
* Provides methods to create language models for interacting with Claude via the CLI.
|
|
862
1038
|
*
|
|
863
1039
|
* @example
|
|
@@ -872,32 +1048,33 @@ declare class ClaudeCodeLanguageModel implements LanguageModelV3 {
|
|
|
872
1048
|
* const languageModel = claudeCode.languageModel('opus', { maxTurns: 10 });
|
|
873
1049
|
* ```
|
|
874
1050
|
*/
|
|
875
|
-
interface ClaudeCodeProvider extends
|
|
1051
|
+
interface ClaudeCodeProvider extends ProviderV4 {
|
|
876
1052
|
/**
|
|
877
1053
|
* Creates a language model instance for the specified model ID.
|
|
878
1054
|
* This is a shorthand for calling `languageModel()`.
|
|
879
1055
|
*
|
|
880
|
-
* @param modelId - The Claude model to use ('opus'
|
|
1056
|
+
* @param modelId - The Claude model to use (e.g. 'fable', 'opus', 'sonnet', 'haiku', or a full model id)
|
|
881
1057
|
* @param settings - Optional settings to configure the model
|
|
882
1058
|
* @returns A language model instance
|
|
883
1059
|
*/
|
|
884
|
-
(modelId: ClaudeCodeModelId, settings?: ClaudeCodeSettings):
|
|
1060
|
+
(modelId: ClaudeCodeModelId, settings?: ClaudeCodeSettings): LanguageModelV4;
|
|
885
1061
|
/**
|
|
886
1062
|
* Creates a language model instance for text generation.
|
|
887
1063
|
*
|
|
888
|
-
* @param modelId - The Claude model to use ('opus'
|
|
1064
|
+
* @param modelId - The Claude model to use (e.g. 'fable', 'opus', 'sonnet', 'haiku', or a full model id)
|
|
889
1065
|
* @param settings - Optional settings to configure the model
|
|
890
1066
|
* @returns A language model instance
|
|
891
1067
|
*/
|
|
892
|
-
languageModel(modelId: ClaudeCodeModelId, settings?: ClaudeCodeSettings):
|
|
1068
|
+
languageModel(modelId: ClaudeCodeModelId, settings?: ClaudeCodeSettings): LanguageModelV4;
|
|
893
1069
|
/**
|
|
894
1070
|
* Alias for `languageModel()` to maintain compatibility with AI SDK patterns.
|
|
895
1071
|
*
|
|
896
|
-
* @param modelId - The Claude model to use ('opus'
|
|
1072
|
+
* @param modelId - The Claude model to use (e.g. 'fable', 'opus', 'sonnet', 'haiku', or a full model id)
|
|
897
1073
|
* @param settings - Optional settings to configure the model
|
|
898
1074
|
* @returns A language model instance
|
|
899
1075
|
*/
|
|
900
|
-
chat(modelId: ClaudeCodeModelId, settings?: ClaudeCodeSettings):
|
|
1076
|
+
chat(modelId: ClaudeCodeModelId, settings?: ClaudeCodeSettings): LanguageModelV4;
|
|
1077
|
+
embeddingModel(modelId: string): never;
|
|
901
1078
|
imageModel(modelId: string): never;
|
|
902
1079
|
}
|
|
903
1080
|
/**
|
|
@@ -958,6 +1135,12 @@ declare function createClaudeCode(options?: ClaudeCodeProviderSettings): ClaudeC
|
|
|
958
1135
|
*/
|
|
959
1136
|
declare const claudeCode: ClaudeCodeProvider;
|
|
960
1137
|
|
|
1138
|
+
/**
|
|
1139
|
+
* Creates a safe controller for common runtime operations on an Agent SDK Query.
|
|
1140
|
+
* The raw Query remains available as `rawQuery` for SDK features not wrapped here.
|
|
1141
|
+
*/
|
|
1142
|
+
declare function createClaudeCodeQueryController(query: Query): ClaudeCodeQueryController;
|
|
1143
|
+
|
|
961
1144
|
/**
|
|
962
1145
|
* Optional annotations for content items, per MCP specification.
|
|
963
1146
|
* Validated against MCP SDK schema version 2025-06-18.
|
|
@@ -1090,10 +1273,12 @@ type AiSdkToolExecuteOptions = {
|
|
|
1090
1273
|
* v4) — the same schema you would pass to the `ai` package's `tool()`
|
|
1091
1274
|
* helper. Schemas created with the AI SDK's `jsonSchema()` helper are not
|
|
1092
1275
|
* supported because the Agent SDK's `tool()` requires a Zod shape.
|
|
1276
|
+
* - Call-context description functions accepted by AI SDK v7 tools cannot be
|
|
1277
|
+
* evaluated here, so only static string descriptions are forwarded.
|
|
1093
1278
|
* - `execute` is required: only tools that execute locally can be bridged.
|
|
1094
1279
|
*/
|
|
1095
1280
|
type AiSdkLikeTool = {
|
|
1096
|
-
description?: string;
|
|
1281
|
+
description?: string | ((options: never) => string);
|
|
1097
1282
|
/** A Zod object schema (`z.object({...})`), Zod v3 or v4. */
|
|
1098
1283
|
inputSchema: unknown;
|
|
1099
1284
|
/**
|
|
@@ -1112,7 +1297,7 @@ type AiSdkLikeTool = {
|
|
|
1112
1297
|
*
|
|
1113
1298
|
* Why this helper exists: the Claude Code CLI executes its own tools, so AI
|
|
1114
1299
|
* SDK tools passed to `generateText`/`streamText` via the `tools` option
|
|
1115
|
-
* cannot be auto-bridged by the provider — at the `
|
|
1300
|
+
* cannot be auto-bridged by the provider — at the `LanguageModelV4` layer the
|
|
1116
1301
|
* provider only receives tool *declarations* (name, description, JSON
|
|
1117
1302
|
* schema); the `execute` functions live in the `ai` package layer and never
|
|
1118
1303
|
* reach providers. This helper is the explicit alternative: pass your tools
|
|
@@ -1326,4 +1511,4 @@ declare function isTimeoutError(error: unknown): boolean;
|
|
|
1326
1511
|
*/
|
|
1327
1512
|
declare function getErrorMetadata(error: unknown): ClaudeCodeErrorMetadata | undefined;
|
|
1328
1513
|
|
|
1329
|
-
export { type AiSdkLikeTool, type AiSdkToolExecuteOptions, type ClaudeCodeErrorMetadata, ClaudeCodeLanguageModel, type ClaudeCodeLanguageModelOptions, type ClaudeCodeModelId, type ClaudeCodeProvider, type ClaudeCodeProviderSettings, type ClaudeCodeSettings, type Logger, type MessageInjector, type MinimalCallToolResult, type ToolAnnotations, claudeCode, createAPICallError, createAiSdkMcpServer, createAuthenticationError, createClaudeCode, createCustomMcpServer, createTimeoutError, getErrorMetadata, isAuthenticationError, isTimeoutError };
|
|
1514
|
+
export { type AiSdkLikeTool, type AiSdkToolExecuteOptions, type ClaudeCodeErrorMetadata, type ClaudeCodeHookEvent, ClaudeCodeLanguageModel, type ClaudeCodeLanguageModelOptions, type ClaudeCodeMcpStatusEvent, type ClaudeCodeModelId, type ClaudeCodeProvider, type ClaudeCodeProviderSettings, type ClaudeCodeQueryController, type ClaudeCodeSettings, type ClaudeCodeTaskEvent, type Logger, type MessageInjector, type MinimalCallToolResult, type ToolAnnotations, claudeCode, createAPICallError, createAiSdkMcpServer, createAuthenticationError, createClaudeCode, createClaudeCodeQueryController, createCustomMcpServer, createTimeoutError, getErrorMetadata, isAuthenticationError, isTimeoutError };
|