@anthropic-ai/claude-agent-sdk 0.1.28 → 0.1.30
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 +1187 -1086
- package/package.json +1 -1
- package/sdk-tools.d.ts +1210 -1
- package/sdk.d.ts +47 -15
- package/sdk.mjs +18 -9
package/sdk.d.ts
CHANGED
|
@@ -249,10 +249,6 @@ export type McpServerStatus = {
|
|
|
249
249
|
version: string;
|
|
250
250
|
};
|
|
251
251
|
};
|
|
252
|
-
export type SDKMessageBase = {
|
|
253
|
-
uuid: UUID;
|
|
254
|
-
session_id: string;
|
|
255
|
-
};
|
|
256
252
|
type SDKUserMessageContent = {
|
|
257
253
|
type: 'user';
|
|
258
254
|
message: APIUserMessage;
|
|
@@ -267,24 +263,28 @@ export type SDKUserMessage = SDKUserMessageContent & {
|
|
|
267
263
|
uuid?: UUID;
|
|
268
264
|
session_id: string;
|
|
269
265
|
};
|
|
270
|
-
export type SDKUserMessageReplay =
|
|
266
|
+
export type SDKUserMessageReplay = SDKUserMessageContent & {
|
|
267
|
+
uuid: UUID;
|
|
268
|
+
session_id: string;
|
|
271
269
|
/**
|
|
272
270
|
* True if this is a replay/acknowledgment of a user message that was already
|
|
273
271
|
* added to the messages array. Used internally to prevent duplicate messages.
|
|
274
272
|
*/
|
|
275
273
|
isReplay: true;
|
|
276
274
|
};
|
|
277
|
-
export type SDKAssistantMessage =
|
|
275
|
+
export type SDKAssistantMessage = {
|
|
278
276
|
type: 'assistant';
|
|
279
277
|
message: APIAssistantMessage;
|
|
280
278
|
parent_tool_use_id: string | null;
|
|
279
|
+
uuid: UUID;
|
|
280
|
+
session_id: string;
|
|
281
281
|
};
|
|
282
282
|
export type SDKPermissionDenial = {
|
|
283
283
|
tool_name: string;
|
|
284
284
|
tool_use_id: string;
|
|
285
285
|
tool_input: Record<string, unknown>;
|
|
286
286
|
};
|
|
287
|
-
export type SDKResultMessage =
|
|
287
|
+
export type SDKResultMessage = {
|
|
288
288
|
type: 'result';
|
|
289
289
|
subtype: 'success';
|
|
290
290
|
duration_ms: number;
|
|
@@ -298,9 +298,11 @@ export type SDKResultMessage = (SDKMessageBase & {
|
|
|
298
298
|
[modelName: string]: ModelUsage;
|
|
299
299
|
};
|
|
300
300
|
permission_denials: SDKPermissionDenial[];
|
|
301
|
-
|
|
301
|
+
uuid: UUID;
|
|
302
|
+
session_id: string;
|
|
303
|
+
} | {
|
|
302
304
|
type: 'result';
|
|
303
|
-
subtype: 'error_max_turns' | '
|
|
305
|
+
subtype: 'error_during_execution' | 'error_max_turns' | 'error_max_budget_usd';
|
|
304
306
|
duration_ms: number;
|
|
305
307
|
duration_api_ms: number;
|
|
306
308
|
is_error: boolean;
|
|
@@ -311,8 +313,11 @@ export type SDKResultMessage = (SDKMessageBase & {
|
|
|
311
313
|
[modelName: string]: ModelUsage;
|
|
312
314
|
};
|
|
313
315
|
permission_denials: SDKPermissionDenial[];
|
|
314
|
-
|
|
315
|
-
|
|
316
|
+
errors: string[];
|
|
317
|
+
uuid: UUID;
|
|
318
|
+
session_id: string;
|
|
319
|
+
};
|
|
320
|
+
export type SDKSystemMessage = {
|
|
316
321
|
type: 'system';
|
|
317
322
|
subtype: 'init';
|
|
318
323
|
agents?: string[];
|
|
@@ -333,21 +338,27 @@ export type SDKSystemMessage = SDKMessageBase & {
|
|
|
333
338
|
name: string;
|
|
334
339
|
path: string;
|
|
335
340
|
}[];
|
|
341
|
+
uuid: UUID;
|
|
342
|
+
session_id: string;
|
|
336
343
|
};
|
|
337
|
-
export type SDKPartialAssistantMessage =
|
|
344
|
+
export type SDKPartialAssistantMessage = {
|
|
338
345
|
type: 'stream_event';
|
|
339
346
|
event: RawMessageStreamEvent;
|
|
340
347
|
parent_tool_use_id: string | null;
|
|
348
|
+
uuid: UUID;
|
|
349
|
+
session_id: string;
|
|
341
350
|
};
|
|
342
|
-
export type SDKCompactBoundaryMessage =
|
|
351
|
+
export type SDKCompactBoundaryMessage = {
|
|
343
352
|
type: 'system';
|
|
344
353
|
subtype: 'compact_boundary';
|
|
345
354
|
compact_metadata: {
|
|
346
355
|
trigger: 'manual' | 'auto';
|
|
347
356
|
pre_tokens: number;
|
|
348
357
|
};
|
|
358
|
+
uuid: UUID;
|
|
359
|
+
session_id: string;
|
|
349
360
|
};
|
|
350
|
-
export type SDKHookResponseMessage =
|
|
361
|
+
export type SDKHookResponseMessage = {
|
|
351
362
|
type: 'system';
|
|
352
363
|
subtype: 'hook_response';
|
|
353
364
|
hook_name: string;
|
|
@@ -355,8 +366,27 @@ export type SDKHookResponseMessage = SDKMessageBase & {
|
|
|
355
366
|
stdout: string;
|
|
356
367
|
stderr: string;
|
|
357
368
|
exit_code?: number;
|
|
369
|
+
uuid: UUID;
|
|
370
|
+
session_id: string;
|
|
358
371
|
};
|
|
359
|
-
export type
|
|
372
|
+
export type SDKToolProgressMessage = {
|
|
373
|
+
type: 'tool_progress';
|
|
374
|
+
tool_use_id: string;
|
|
375
|
+
tool_name: string;
|
|
376
|
+
parent_tool_use_id: string | null;
|
|
377
|
+
elapsed_time_seconds: number;
|
|
378
|
+
uuid: UUID;
|
|
379
|
+
session_id: string;
|
|
380
|
+
};
|
|
381
|
+
export type SDKAuthStatusMessage = {
|
|
382
|
+
type: 'auth_status';
|
|
383
|
+
isAuthenticating: boolean;
|
|
384
|
+
output: string[];
|
|
385
|
+
error?: string;
|
|
386
|
+
uuid: UUID;
|
|
387
|
+
session_id: string;
|
|
388
|
+
};
|
|
389
|
+
export type SDKMessage = SDKAssistantMessage | SDKUserMessage | SDKUserMessageReplay | SDKResultMessage | SDKSystemMessage | SDKPartialAssistantMessage | SDKCompactBoundaryMessage | SDKHookResponseMessage | SDKToolProgressMessage | SDKAuthStatusMessage;
|
|
360
390
|
export interface Query extends AsyncGenerator<SDKMessage, void> {
|
|
361
391
|
/**
|
|
362
392
|
* Control Requests
|
|
@@ -405,6 +435,7 @@ export declare class AbortError extends Error {
|
|
|
405
435
|
export type AgentDefinition = {
|
|
406
436
|
description: string;
|
|
407
437
|
tools?: string[];
|
|
438
|
+
disallowedTools?: string[];
|
|
408
439
|
prompt: string;
|
|
409
440
|
model?: 'sonnet' | 'opus' | 'haiku' | 'inherit';
|
|
410
441
|
};
|
|
@@ -438,6 +469,7 @@ export type Options = {
|
|
|
438
469
|
includePartialMessages?: boolean;
|
|
439
470
|
maxThinkingTokens?: number;
|
|
440
471
|
maxTurns?: number;
|
|
472
|
+
maxBudgetUsd?: number;
|
|
441
473
|
mcpServers?: Record<string, McpServerConfig>;
|
|
442
474
|
model?: string;
|
|
443
475
|
pathToClaudeCodeExecutable?: string;
|
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.30
|
|
5
5
|
|
|
6
6
|
// Want to see the unminified source? We're hiring!
|
|
7
7
|
// https://job-boards.greenhouse.io/anthropic/jobs/4816199008
|
|
@@ -6387,6 +6387,7 @@ class ProcessTransport {
|
|
|
6387
6387
|
appendSystemPrompt,
|
|
6388
6388
|
maxThinkingTokens,
|
|
6389
6389
|
maxTurns,
|
|
6390
|
+
maxBudgetUsd,
|
|
6390
6391
|
model,
|
|
6391
6392
|
fallbackModel,
|
|
6392
6393
|
permissionMode,
|
|
@@ -6419,6 +6420,9 @@ class ProcessTransport {
|
|
|
6419
6420
|
}
|
|
6420
6421
|
if (maxTurns)
|
|
6421
6422
|
args.push("--max-turns", maxTurns.toString());
|
|
6423
|
+
if (maxBudgetUsd !== undefined) {
|
|
6424
|
+
args.push("--max-budget-usd", maxBudgetUsd.toString());
|
|
6425
|
+
}
|
|
6422
6426
|
if (model)
|
|
6423
6427
|
args.push("--model", model);
|
|
6424
6428
|
if (env.DEBUG)
|
|
@@ -7339,22 +7343,24 @@ var maxOutputTokensValidator = {
|
|
|
7339
7343
|
name: "CLAUDE_CODE_MAX_OUTPUT_TOKENS",
|
|
7340
7344
|
default: 32000,
|
|
7341
7345
|
validate: (value) => {
|
|
7346
|
+
const MAX_OUTPUT_TOKENS = 64000;
|
|
7347
|
+
const DEFAULT_MAX_OUTPUT_TOKENS = 32000;
|
|
7342
7348
|
if (!value) {
|
|
7343
|
-
return { effective:
|
|
7349
|
+
return { effective: DEFAULT_MAX_OUTPUT_TOKENS, status: "valid" };
|
|
7344
7350
|
}
|
|
7345
7351
|
const parsed = parseInt(value, 10);
|
|
7346
7352
|
if (isNaN(parsed) || parsed <= 0) {
|
|
7347
7353
|
return {
|
|
7348
|
-
effective:
|
|
7354
|
+
effective: DEFAULT_MAX_OUTPUT_TOKENS,
|
|
7349
7355
|
status: "invalid",
|
|
7350
|
-
message: `Invalid value "${value}" (using default:
|
|
7356
|
+
message: `Invalid value "${value}" (using default: ${DEFAULT_MAX_OUTPUT_TOKENS})`
|
|
7351
7357
|
};
|
|
7352
7358
|
}
|
|
7353
|
-
if (parsed >
|
|
7359
|
+
if (parsed > MAX_OUTPUT_TOKENS) {
|
|
7354
7360
|
return {
|
|
7355
|
-
effective:
|
|
7361
|
+
effective: MAX_OUTPUT_TOKENS,
|
|
7356
7362
|
status: "capped",
|
|
7357
|
-
message: `Capped from ${parsed} to
|
|
7363
|
+
message: `Capped from ${parsed} to ${MAX_OUTPUT_TOKENS}`
|
|
7358
7364
|
};
|
|
7359
7365
|
}
|
|
7360
7366
|
return { effective: parsed, status: "valid" };
|
|
@@ -7782,7 +7788,8 @@ class Query {
|
|
|
7782
7788
|
}
|
|
7783
7789
|
logForDebugging(`[Query.streamInput] Finished processing ${messageCount} messages from input stream`);
|
|
7784
7790
|
logForDebugging(`[Query.streamInput] About to check MCP servers. this.sdkMcpTransports.size = ${this.sdkMcpTransports.size}`);
|
|
7785
|
-
|
|
7791
|
+
const hasHooks = this.hooks && Object.keys(this.hooks).length > 0;
|
|
7792
|
+
if ((this.sdkMcpTransports.size > 0 || hasHooks) && this.firstResultReceivedPromise) {
|
|
7786
7793
|
logForDebugging(`[Query.streamInput] Entering Promise.race to wait for result`);
|
|
7787
7794
|
let timeoutId;
|
|
7788
7795
|
await Promise.race([
|
|
@@ -14763,7 +14770,7 @@ function query({
|
|
|
14763
14770
|
const dirname2 = join3(filename, "..");
|
|
14764
14771
|
pathToClaudeCodeExecutable = join3(dirname2, "cli.js");
|
|
14765
14772
|
}
|
|
14766
|
-
process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.
|
|
14773
|
+
process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.30";
|
|
14767
14774
|
const {
|
|
14768
14775
|
abortController = createAbortController(),
|
|
14769
14776
|
additionalDirectories = [],
|
|
@@ -14783,6 +14790,7 @@ function query({
|
|
|
14783
14790
|
includePartialMessages,
|
|
14784
14791
|
maxThinkingTokens,
|
|
14785
14792
|
maxTurns,
|
|
14793
|
+
maxBudgetUsd,
|
|
14786
14794
|
mcpServers,
|
|
14787
14795
|
model,
|
|
14788
14796
|
permissionMode = "default",
|
|
@@ -14836,6 +14844,7 @@ function query({
|
|
|
14836
14844
|
appendSystemPrompt,
|
|
14837
14845
|
maxThinkingTokens,
|
|
14838
14846
|
maxTurns,
|
|
14847
|
+
maxBudgetUsd,
|
|
14839
14848
|
model,
|
|
14840
14849
|
fallbackModel,
|
|
14841
14850
|
permissionMode,
|