@anthropic-ai/claude-agent-sdk 0.1.27 → 0.1.29
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/cli.js +890 -891
- package/package.json +1 -1
- package/sdk-tools.d.ts +8 -0
- package/sdk.d.ts +7 -0
- package/sdk.mjs +21 -17
package/package.json
CHANGED
package/sdk-tools.d.ts
CHANGED
|
@@ -40,6 +40,14 @@ export interface AgentInput {
|
|
|
40
40
|
* The type of specialized agent to use for this task
|
|
41
41
|
*/
|
|
42
42
|
subagent_type: string;
|
|
43
|
+
/**
|
|
44
|
+
* Optional model to use for this agent. If not specified, inherits from parent. Prefer haiku for quick, straightforward tasks to minimize cost and latency.
|
|
45
|
+
*/
|
|
46
|
+
model?: "sonnet" | "opus" | "haiku";
|
|
47
|
+
/**
|
|
48
|
+
* Optional agent ID to resume from. If provided, the agent will continue from the previous execution transcript.
|
|
49
|
+
*/
|
|
50
|
+
resume?: string;
|
|
43
51
|
}
|
|
44
52
|
export interface BashInput {
|
|
45
53
|
/**
|
package/sdk.d.ts
CHANGED
|
@@ -129,6 +129,11 @@ export type CanUseTool = (toolName: string, input: Record<string, unknown>, opti
|
|
|
129
129
|
* `updatedPermissions` in the PermissionResult.
|
|
130
130
|
*/
|
|
131
131
|
suggestions?: PermissionUpdate[];
|
|
132
|
+
/**
|
|
133
|
+
* Unique identifier for this specific tool call within the assistant message.
|
|
134
|
+
* Multiple tool calls in the same assistant message will have different toolUseIDs.
|
|
135
|
+
*/
|
|
136
|
+
toolUseID: string;
|
|
132
137
|
}) => Promise<PermissionResult>;
|
|
133
138
|
export declare const HOOK_EVENTS: readonly ["PreToolUse", "PostToolUse", "Notification", "UserPromptSubmit", "SessionStart", "SessionEnd", "Stop", "SubagentStop", "PreCompact"];
|
|
134
139
|
export type HookEvent = (typeof HOOK_EVENTS)[number];
|
|
@@ -391,6 +396,8 @@ type CreateSdkMcpServerOptions = {
|
|
|
391
396
|
/**
|
|
392
397
|
* Creates an MCP server instance that can be used with the SDK transport.
|
|
393
398
|
* This allows SDK users to define custom tools that run in the same process.
|
|
399
|
+
*
|
|
400
|
+
* If your SDK MCP calls will run longer than 60s, override CLAUDE_CODE_STREAM_CLOSE_TIMEOUT
|
|
394
401
|
*/
|
|
395
402
|
export declare function createSdkMcpServer(_options: CreateSdkMcpServerOptions): McpSdkServerConfigWithInstance;
|
|
396
403
|
export declare class AbortError extends Error {
|
package/sdk.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// (c) Anthropic PBC. All rights reserved. Use is subject to the Legal Agreements outlined here: https://docs.claude.com/en/docs/claude-code/legal-and-compliance.
|
|
3
3
|
|
|
4
|
-
// Version: 0.1.
|
|
4
|
+
// Version: 0.1.29
|
|
5
5
|
|
|
6
6
|
// Want to see the unminified source? We're hiring!
|
|
7
7
|
// https://job-boards.greenhouse.io/anthropic/jobs/4816199008
|
|
@@ -7301,6 +7301,7 @@ import { dirname, join as join2 } from "path";
|
|
|
7301
7301
|
|
|
7302
7302
|
// ../src/bootstrap/state.ts
|
|
7303
7303
|
import { cwd } from "process";
|
|
7304
|
+
import { realpathSync as realpathSync2 } from "fs";
|
|
7304
7305
|
import { randomUUID } from "crypto";
|
|
7305
7306
|
|
|
7306
7307
|
// ../src/bootstrap/envValidators.ts
|
|
@@ -7362,8 +7363,9 @@ var maxOutputTokensValidator = {
|
|
|
7362
7363
|
|
|
7363
7364
|
// ../src/bootstrap/state.ts
|
|
7364
7365
|
function getInitialState() {
|
|
7366
|
+
const resolvedCwd = realpathSync2(cwd());
|
|
7365
7367
|
return {
|
|
7366
|
-
originalCwd:
|
|
7368
|
+
originalCwd: resolvedCwd,
|
|
7367
7369
|
totalCostUSD: 0,
|
|
7368
7370
|
totalAPIDuration: 0,
|
|
7369
7371
|
totalAPIDurationWithoutRetries: 0,
|
|
@@ -7373,7 +7375,7 @@ function getInitialState() {
|
|
|
7373
7375
|
totalLinesAdded: 0,
|
|
7374
7376
|
totalLinesRemoved: 0,
|
|
7375
7377
|
hasUnknownModelCost: false,
|
|
7376
|
-
cwd:
|
|
7378
|
+
cwd: resolvedCwd,
|
|
7377
7379
|
modelUsage: {},
|
|
7378
7380
|
mainLoopModelOverride: undefined,
|
|
7379
7381
|
maxRateLimitFallbackActive: false,
|
|
@@ -7505,12 +7507,14 @@ class Query {
|
|
|
7505
7507
|
pendingMcpResponses = new Map;
|
|
7506
7508
|
firstResultReceivedPromise;
|
|
7507
7509
|
firstResultReceivedResolve;
|
|
7510
|
+
streamCloseTimeout;
|
|
7508
7511
|
constructor(transport, isSingleUserTurn, canUseTool, hooks, abortController, sdkMcpServers = new Map) {
|
|
7509
7512
|
this.transport = transport;
|
|
7510
7513
|
this.isSingleUserTurn = isSingleUserTurn;
|
|
7511
7514
|
this.canUseTool = canUseTool;
|
|
7512
7515
|
this.hooks = hooks;
|
|
7513
7516
|
this.abortController = abortController;
|
|
7517
|
+
this.streamCloseTimeout = parseInt(process.env.CLAUDE_CODE_STREAM_CLOSE_TIMEOUT || "") || 60000;
|
|
7514
7518
|
for (const [name, server] of sdkMcpServers) {
|
|
7515
7519
|
const sdkTransport = new SdkControlServerTransport((message) => this.sendMcpServerMessageToCli(name, message));
|
|
7516
7520
|
this.sdkMcpTransports.set(name, sdkTransport);
|
|
@@ -7636,7 +7640,8 @@ class Query {
|
|
|
7636
7640
|
}
|
|
7637
7641
|
return this.canUseTool(request.request.tool_name, request.request.input, {
|
|
7638
7642
|
signal,
|
|
7639
|
-
suggestions: request.request.permission_suggestions
|
|
7643
|
+
suggestions: request.request.permission_suggestions,
|
|
7644
|
+
toolUseID: request.request.tool_use_id
|
|
7640
7645
|
});
|
|
7641
7646
|
} else if (request.request.subtype === "hook_callback") {
|
|
7642
7647
|
const result = await this.handleHookCallbacks(request.request.callback_id, request.request.input, request.request.tool_use_id, signal);
|
|
@@ -7717,6 +7722,13 @@ class Query {
|
|
|
7717
7722
|
max_thinking_tokens: maxThinkingTokens
|
|
7718
7723
|
});
|
|
7719
7724
|
}
|
|
7725
|
+
async processPendingPermissionRequests(pendingPermissionRequests) {
|
|
7726
|
+
for (const request of pendingPermissionRequests) {
|
|
7727
|
+
if (request.request.subtype === "can_use_tool") {
|
|
7728
|
+
this.handleControlRequest(request).catch(() => {});
|
|
7729
|
+
}
|
|
7730
|
+
}
|
|
7731
|
+
}
|
|
7720
7732
|
request(request) {
|
|
7721
7733
|
const requestId = Math.random().toString(36).substring(2, 15);
|
|
7722
7734
|
const sdkRequest = {
|
|
@@ -7730,6 +7742,9 @@ class Query {
|
|
|
7730
7742
|
resolve(response);
|
|
7731
7743
|
} else {
|
|
7732
7744
|
reject(new Error(response.error));
|
|
7745
|
+
if (response.pending_permission_requests) {
|
|
7746
|
+
this.processPendingPermissionRequests(response.pending_permission_requests);
|
|
7747
|
+
}
|
|
7733
7748
|
}
|
|
7734
7749
|
});
|
|
7735
7750
|
Promise.resolve(this.transport.write(JSON.stringify(sdkRequest) + `
|
|
@@ -7769,7 +7784,6 @@ class Query {
|
|
|
7769
7784
|
logForDebugging(`[Query.streamInput] About to check MCP servers. this.sdkMcpTransports.size = ${this.sdkMcpTransports.size}`);
|
|
7770
7785
|
if (this.sdkMcpTransports.size > 0 && this.firstResultReceivedPromise) {
|
|
7771
7786
|
logForDebugging(`[Query.streamInput] Entering Promise.race to wait for result`);
|
|
7772
|
-
const STREAM_CLOSE_TIMEOUT = 1e4;
|
|
7773
7787
|
let timeoutId;
|
|
7774
7788
|
await Promise.race([
|
|
7775
7789
|
this.firstResultReceivedPromise.then(() => {
|
|
@@ -7782,7 +7796,7 @@ class Query {
|
|
|
7782
7796
|
timeoutId = setTimeout(() => {
|
|
7783
7797
|
logForDebugging(`[Query.streamInput] Timed out waiting for first result, closing input stream`);
|
|
7784
7798
|
resolve();
|
|
7785
|
-
},
|
|
7799
|
+
}, this.streamCloseTimeout);
|
|
7786
7800
|
})
|
|
7787
7801
|
]);
|
|
7788
7802
|
if (timeoutId) {
|
|
@@ -7822,11 +7836,7 @@ class Query {
|
|
|
7822
7836
|
const messageId = "id" in mcpRequest.message ? mcpRequest.message.id : null;
|
|
7823
7837
|
const key = `${serverName}:${messageId}`;
|
|
7824
7838
|
return new Promise((resolve, reject) => {
|
|
7825
|
-
let timeoutId = null;
|
|
7826
7839
|
const cleanup = () => {
|
|
7827
|
-
if (timeoutId) {
|
|
7828
|
-
clearTimeout(timeoutId);
|
|
7829
|
-
}
|
|
7830
7840
|
this.pendingMcpResponses.delete(key);
|
|
7831
7841
|
};
|
|
7832
7842
|
const resolveAndCleanup = (response) => {
|
|
@@ -7848,12 +7858,6 @@ class Query {
|
|
|
7848
7858
|
reject(new Error("No message handler registered"));
|
|
7849
7859
|
return;
|
|
7850
7860
|
}
|
|
7851
|
-
timeoutId = setTimeout(() => {
|
|
7852
|
-
if (this.pendingMcpResponses.has(key)) {
|
|
7853
|
-
cleanup();
|
|
7854
|
-
reject(new Error("Request timeout"));
|
|
7855
|
-
}
|
|
7856
|
-
}, 30000);
|
|
7857
7861
|
});
|
|
7858
7862
|
}
|
|
7859
7863
|
}
|
|
@@ -14759,7 +14763,7 @@ function query({
|
|
|
14759
14763
|
const dirname2 = join3(filename, "..");
|
|
14760
14764
|
pathToClaudeCodeExecutable = join3(dirname2, "cli.js");
|
|
14761
14765
|
}
|
|
14762
|
-
process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.
|
|
14766
|
+
process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.29";
|
|
14763
14767
|
const {
|
|
14764
14768
|
abortController = createAbortController(),
|
|
14765
14769
|
additionalDirectories = [],
|