@anthropic-ai/claude-agent-sdk 0.1.51 → 0.1.52

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.
Files changed (5) hide show
  1. package/cli.js +1157 -1141
  2. package/package.json +3 -1
  3. package/sdk-tools.d.ts +0 -15
  4. package/sdk.d.ts +33 -0
  5. package/sdk.mjs +330 -57
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anthropic-ai/claude-agent-sdk",
3
- "version": "0.1.51",
3
+ "version": "0.1.52",
4
4
  "main": "sdk.mjs",
5
5
  "types": "sdk.d.ts",
6
6
  "engines": {
@@ -33,6 +33,8 @@
33
33
  "@img/sharp-linux-arm": "^0.33.5",
34
34
  "@img/sharp-linux-arm64": "^0.33.5",
35
35
  "@img/sharp-linux-x64": "^0.33.5",
36
+ "@img/sharp-linuxmusl-arm64": "^0.33.5",
37
+ "@img/sharp-linuxmusl-x64": "^0.33.5",
36
38
  "@img/sharp-win32-x64": "^0.33.5"
37
39
  }
38
40
  }
package/sdk-tools.d.ts CHANGED
@@ -23,7 +23,6 @@ export type ToolInputSchemas =
23
23
  | McpInput
24
24
  | NotebookEditInput
25
25
  | ReadMcpResourceInput
26
- | TimeMachineInput
27
26
  | TodoWriteInput
28
27
  | WebFetchInput
29
28
  | WebSearchInput
@@ -253,20 +252,6 @@ export interface ReadMcpResourceInput {
253
252
  */
254
253
  uri: string;
255
254
  }
256
- export interface TimeMachineInput {
257
- /**
258
- * The prefix of the user message to rewind to (searches backwards for first match)
259
- */
260
- message_prefix: string;
261
- /**
262
- * The new instructions to inject after rewinding, explaining what to do differently
263
- */
264
- course_correction: string;
265
- /**
266
- * Whether to restore code changes using file history (default: true)
267
- */
268
- restore_code?: boolean;
269
- }
270
255
  export interface TodoWriteInput {
271
256
  /**
272
257
  * The updated todo list
package/sdk.d.ts CHANGED
@@ -486,6 +486,39 @@ export interface Query extends AsyncGenerator<SDKMessage, void> {
486
486
  supportedModels(): Promise<ModelInfo[]>;
487
487
  mcpServerStatus(): Promise<McpServerStatus[]>;
488
488
  accountInfo(): Promise<AccountInfo>;
489
+ /**
490
+ * Stream input messages to the query
491
+ * Used internally for multi-turn conversations
492
+ */
493
+ streamInput(stream: AsyncIterable<SDKUserMessage>): Promise<void>;
494
+ }
495
+ /**
496
+ * V2 API - UNSTABLE
497
+ * Options for creating a session
498
+ */
499
+ export type SDKSessionOptions = {
500
+ /** Model to use */
501
+ model: string;
502
+ /** Path to Claude Code executable */
503
+ pathToClaudeCodeExecutable?: string;
504
+ /** Executable to use (node, bun, deno) */
505
+ executable?: 'node' | 'bun' | 'deno';
506
+ /** Arguments to pass to executable */
507
+ executableArgs?: string[];
508
+ };
509
+ /**
510
+ * V2 API - UNSTABLE
511
+ * Session interface for multi-turn conversations
512
+ */
513
+ export interface SDKSession {
514
+ /** Send a message to the agent */
515
+ send(message: string | SDKUserMessage): Promise<void>;
516
+ /** Receive messages from the agent */
517
+ receive(): AsyncGenerator<SDKMessage, void>;
518
+ /** Close the session */
519
+ close(): void;
520
+ /** Async disposal support (calls close if not already closed) */
521
+ [Symbol.asyncDispose](): Promise<void>;
489
522
  }
490
523
  type SdkMcpToolDefinition<Schema extends ZodRawShape = ZodRawShape> = {
491
524
  name: 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.51
4
+ // Version: 0.1.52
5
5
 
6
6
  // Want to see the unminified source? We're hiring!
7
7
  // https://job-boards.greenhouse.io/anthropic/jobs/4816199008
@@ -31,6 +31,43 @@ var __export = (target, all) => {
31
31
  set: (newValue) => all[name] = () => newValue
32
32
  });
33
33
  };
34
+ var __dispose = Symbol.dispose || /* @__PURE__ */ Symbol.for("Symbol.dispose");
35
+ var __asyncDispose = Symbol.asyncDispose || /* @__PURE__ */ Symbol.for("Symbol.asyncDispose");
36
+ var __using = (stack, value, async) => {
37
+ if (value != null) {
38
+ if (typeof value !== "object" && typeof value !== "function")
39
+ throw TypeError('Object expected to be assigned to "using" declaration');
40
+ var dispose;
41
+ if (async)
42
+ dispose = value[__asyncDispose];
43
+ if (dispose === undefined)
44
+ dispose = value[__dispose];
45
+ if (typeof dispose !== "function")
46
+ throw TypeError("Object not disposable");
47
+ stack.push([async, dispose, value]);
48
+ } else if (async) {
49
+ stack.push([async]);
50
+ }
51
+ return value;
52
+ };
53
+ var __callDispose = (stack, error, hasError) => {
54
+ var E = typeof SuppressedError === "function" ? SuppressedError : function(e, s, m, _) {
55
+ return _ = Error(m), _.name = "SuppressedError", _.error = e, _.suppressed = s, _;
56
+ }, fail = (e) => error = hasError ? new E(e, error, "An error was suppressed during disposal") : (hasError = true, e), next = (it) => {
57
+ while (it = stack.pop()) {
58
+ try {
59
+ var result = it[1] && it[1].call(it[2]);
60
+ if (it[0])
61
+ return Promise.resolve(result).then(next, (e) => (fail(e), next()));
62
+ } catch (e) {
63
+ fail(e);
64
+ }
65
+ }
66
+ if (hasError)
67
+ throw error;
68
+ };
69
+ return next();
70
+ };
34
71
 
35
72
  // ../node_modules/uri-js/dist/es5/uri.all.js
36
73
  var require_uri_all = __commonJS((exports, module) => {
@@ -6200,8 +6237,8 @@ var require_ajv = __commonJS((exports, module) => {
6200
6237
  });
6201
6238
 
6202
6239
  // ../src/entrypoints/agentSdk.ts
6203
- import { join as join3 } from "path";
6204
- import { fileURLToPath } from "url";
6240
+ import { join as join5 } from "path";
6241
+ import { fileURLToPath as fileURLToPath2 } from "url";
6205
6242
 
6206
6243
  // ../src/utils/abortController.ts
6207
6244
  import { setMaxListeners } from "events";
@@ -6369,6 +6406,57 @@ function isRunningWithBun() {
6369
6406
  return process.versions.bun !== undefined;
6370
6407
  }
6371
6408
 
6409
+ // ../src/utils/sdkDebug.ts
6410
+ import { randomUUID } from "crypto";
6411
+ import { appendFileSync as appendFileSync2, existsSync as existsSync2, mkdirSync as mkdirSync2 } from "fs";
6412
+ import { join as join2 } from "path";
6413
+
6414
+ // ../src/utils/envUtils.ts
6415
+ import { join } from "path";
6416
+ import { homedir } from "os";
6417
+ function getClaudeConfigHomeDir() {
6418
+ return process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), ".claude");
6419
+ }
6420
+ function isEnvTruthy(envVar) {
6421
+ if (!envVar)
6422
+ return false;
6423
+ if (typeof envVar === "boolean")
6424
+ return envVar;
6425
+ const normalizedValue = envVar.toLowerCase().trim();
6426
+ return ["1", "true", "yes", "on"].includes(normalizedValue);
6427
+ }
6428
+
6429
+ // ../src/utils/sdkDebug.ts
6430
+ var debugFilePath = null;
6431
+ var initialized = false;
6432
+ function getOrCreateDebugFile() {
6433
+ if (initialized) {
6434
+ return debugFilePath;
6435
+ }
6436
+ initialized = true;
6437
+ if (!process.env.DEBUG_CLAUDE_AGENT_SDK) {
6438
+ return null;
6439
+ }
6440
+ const debugDir = join2(getClaudeConfigHomeDir(), "debug");
6441
+ debugFilePath = join2(debugDir, `sdk-${randomUUID()}.txt`);
6442
+ if (!existsSync2(debugDir)) {
6443
+ mkdirSync2(debugDir, { recursive: true });
6444
+ }
6445
+ process.stderr.write(`SDK debug logs: ${debugFilePath}
6446
+ `);
6447
+ return debugFilePath;
6448
+ }
6449
+ function logForSdkDebugging(message) {
6450
+ const path = getOrCreateDebugFile();
6451
+ if (!path) {
6452
+ return;
6453
+ }
6454
+ const timestamp = new Date().toISOString();
6455
+ const output = `${timestamp} ${message}
6456
+ `;
6457
+ appendFileSync2(path, output);
6458
+ }
6459
+
6372
6460
  // ../src/transport/ProcessTransport.ts
6373
6461
  class ProcessTransport {
6374
6462
  options;
@@ -6444,8 +6532,9 @@ class ProcessTransport {
6444
6532
  if (jsonSchema) {
6445
6533
  args.push("--json-schema", JSON.stringify(jsonSchema));
6446
6534
  }
6447
- if (env.DEBUG)
6535
+ if (env.DEBUG_CLAUDE_AGENT_SDK) {
6448
6536
  args.push("--debug-to-stderr");
6537
+ }
6449
6538
  if (canUseTool) {
6450
6539
  if (permissionPromptToolName) {
6451
6540
  throw new Error("canUseTool callback cannot be used with permissionPromptToolName. Please use one or the other.");
@@ -6519,6 +6608,12 @@ class ProcessTransport {
6519
6608
  if (!env.CLAUDE_CODE_ENTRYPOINT) {
6520
6609
  env.CLAUDE_CODE_ENTRYPOINT = "sdk-ts";
6521
6610
  }
6611
+ delete env.NODE_OPTIONS;
6612
+ if (env.DEBUG_CLAUDE_AGENT_SDK) {
6613
+ env.DEBUG = "1";
6614
+ } else {
6615
+ delete env.DEBUG;
6616
+ }
6522
6617
  const fs2 = getFsImplementation();
6523
6618
  if (!fs2.existsSync(pathToClaudeCodeExecutable)) {
6524
6619
  const errorMessage = isNativeBinary(pathToClaudeCodeExecutable) ? `Claude Code native binary not found at ${pathToClaudeCodeExecutable}. Please ensure Claude Code is installed via native installer or specify a valid path with options.pathToClaudeCodeExecutable.` : `Claude Code executable not found at ${pathToClaudeCodeExecutable}. Is options.pathToClaudeCodeExecutable set?`;
@@ -6527,8 +6622,12 @@ class ProcessTransport {
6527
6622
  const isNative = isNativeBinary(pathToClaudeCodeExecutable);
6528
6623
  const spawnCommand = isNative ? pathToClaudeCodeExecutable : executable;
6529
6624
  const spawnArgs = isNative ? [...executableArgs, ...args] : [...executableArgs, pathToClaudeCodeExecutable, ...args];
6530
- this.logForDebugging(isNative ? `Spawning Claude Code native binary: ${spawnCommand} ${spawnArgs.join(" ")}` : `Spawning Claude Code process: ${spawnCommand} ${spawnArgs.join(" ")}`);
6531
- const stderrMode = env.DEBUG || stderr ? "pipe" : "ignore";
6625
+ const spawnMessage = isNative ? `Spawning Claude Code native binary: ${spawnCommand} ${spawnArgs.join(" ")}` : `Spawning Claude Code process: ${spawnCommand} ${spawnArgs.join(" ")}`;
6626
+ logForSdkDebugging(spawnMessage);
6627
+ if (stderr) {
6628
+ stderr(spawnMessage);
6629
+ }
6630
+ const stderrMode = env.DEBUG_CLAUDE_AGENT_SDK || stderr ? "pipe" : "ignore";
6532
6631
  this.child = spawn(spawnCommand, spawnArgs, {
6533
6632
  cwd,
6534
6633
  stdio: ["pipe", "pipe", stderrMode],
@@ -6537,9 +6636,13 @@ class ProcessTransport {
6537
6636
  });
6538
6637
  this.childStdin = this.child.stdin;
6539
6638
  this.childStdout = this.child.stdout;
6540
- if (env.DEBUG || stderr) {
6639
+ if (env.DEBUG_CLAUDE_AGENT_SDK || stderr) {
6541
6640
  this.child.stderr.on("data", (data) => {
6542
- this.logForDebugging(data.toString());
6641
+ const message = data.toString();
6642
+ logForSdkDebugging(message);
6643
+ if (stderr) {
6644
+ stderr(message);
6645
+ }
6543
6646
  });
6544
6647
  }
6545
6648
  const cleanup = () => {
@@ -6557,7 +6660,7 @@ class ProcessTransport {
6557
6660
  this.exitError = new AbortError("Claude Code process aborted by user");
6558
6661
  } else {
6559
6662
  this.exitError = new Error(`Failed to spawn Claude Code process: ${error.message}`);
6560
- this.logForDebugging(this.exitError.message);
6663
+ logForSdkDebugging(this.exitError.message);
6561
6664
  }
6562
6665
  });
6563
6666
  this.child.on("close", (code, signal) => {
@@ -6568,7 +6671,7 @@ class ProcessTransport {
6568
6671
  const error = this.getProcessExitError(code, signal);
6569
6672
  if (error) {
6570
6673
  this.exitError = error;
6571
- this.logForDebugging(error.message);
6674
+ logForSdkDebugging(error.message);
6572
6675
  }
6573
6676
  }
6574
6677
  });
@@ -6586,15 +6689,6 @@ class ProcessTransport {
6586
6689
  }
6587
6690
  return;
6588
6691
  }
6589
- logForDebugging(message) {
6590
- if (process.env.DEBUG) {
6591
- process.stderr.write(`${message}
6592
- `);
6593
- }
6594
- if (this.options.stderr) {
6595
- this.options.stderr(message);
6596
- }
6597
- }
6598
6692
  write(data) {
6599
6693
  if (this.abortController.signal.aborted) {
6600
6694
  throw new AbortError("Operation aborted");
@@ -6608,14 +6702,11 @@ class ProcessTransport {
6608
6702
  if (this.exitError) {
6609
6703
  throw new Error(`Cannot write to process that exited with error: ${this.exitError.message}`);
6610
6704
  }
6611
- if (process.env.DEBUG_SDK) {
6612
- process.stderr.write(`[ProcessTransport] Writing to stdin: ${data.substring(0, 100)}
6613
- `);
6614
- }
6705
+ logForSdkDebugging(`[ProcessTransport] Writing to stdin: ${data.substring(0, 100)}`);
6615
6706
  try {
6616
6707
  const written = this.childStdin.write(data);
6617
- if (!written && process.env.DEBUG_SDK) {
6618
- console.warn("[ProcessTransport] Write buffer full, data queued");
6708
+ if (!written) {
6709
+ logForSdkDebugging("[ProcessTransport] Write buffer full, data queued");
6619
6710
  }
6620
6711
  } catch (error) {
6621
6712
  this.ready = false;
@@ -7305,28 +7396,13 @@ function shouldShowDebugMessage(message, filter) {
7305
7396
  return shouldShowDebugCategories(categories, filter);
7306
7397
  }
7307
7398
 
7308
- // ../src/utils/envUtils.ts
7309
- import { join } from "path";
7310
- import { homedir } from "os";
7311
- function getClaudeConfigHomeDir() {
7312
- return process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), ".claude");
7313
- }
7314
- function isEnvTruthy(envVar) {
7315
- if (!envVar)
7316
- return false;
7317
- if (typeof envVar === "boolean")
7318
- return envVar;
7319
- const normalizedValue = envVar.toLowerCase().trim();
7320
- return ["1", "true", "yes", "on"].includes(normalizedValue);
7321
- }
7322
-
7323
7399
  // ../src/utils/debug.ts
7324
- import { dirname, join as join2 } from "path";
7400
+ import { dirname, join as join3 } from "path";
7325
7401
 
7326
7402
  // ../src/bootstrap/state.ts
7327
7403
  import { cwd } from "process";
7328
7404
  import { realpathSync as realpathSync2 } from "fs";
7329
- import { randomUUID } from "crypto";
7405
+ import { randomUUID as randomUUID2 } from "crypto";
7330
7406
 
7331
7407
  // ../src/bootstrap/envValidators.ts
7332
7408
  var bashMaxOutputLengthValidator = {
@@ -7431,7 +7507,7 @@ function getInitialState() {
7431
7507
  tokenCounter: null,
7432
7508
  codeEditToolDecisionCounter: null,
7433
7509
  activeTimeCounter: null,
7434
- sessionId: randomUUID(),
7510
+ sessionId: randomUUID2(),
7435
7511
  loggerProvider: null,
7436
7512
  eventLogger: null,
7437
7513
  meterProvider: null,
@@ -7454,6 +7530,59 @@ function getSessionId() {
7454
7530
  return STATE.sessionId;
7455
7531
  }
7456
7532
 
7533
+ // ../src/utils/bufferedWriter.ts
7534
+ function createBufferedWriter({
7535
+ writeFn,
7536
+ flushIntervalMs = 1000,
7537
+ maxBufferSize = 100,
7538
+ immediateMode = false
7539
+ }) {
7540
+ let buffer = [];
7541
+ let flushTimer = null;
7542
+ function clearTimer() {
7543
+ if (flushTimer) {
7544
+ clearTimeout(flushTimer);
7545
+ flushTimer = null;
7546
+ }
7547
+ }
7548
+ function flush() {
7549
+ if (buffer.length === 0)
7550
+ return;
7551
+ writeFn(buffer.join(""));
7552
+ buffer = [];
7553
+ clearTimer();
7554
+ }
7555
+ function scheduleFlush() {
7556
+ if (!flushTimer) {
7557
+ flushTimer = setTimeout(flush, flushIntervalMs);
7558
+ }
7559
+ }
7560
+ return {
7561
+ write(content) {
7562
+ if (immediateMode) {
7563
+ writeFn(content);
7564
+ return;
7565
+ }
7566
+ buffer.push(content);
7567
+ scheduleFlush();
7568
+ if (buffer.length >= maxBufferSize) {
7569
+ flush();
7570
+ }
7571
+ },
7572
+ flush,
7573
+ dispose() {
7574
+ flush();
7575
+ }
7576
+ };
7577
+ }
7578
+
7579
+ // ../src/utils/cleanupRegistry.ts
7580
+ var cleanupFunctions = new Set;
7581
+ function registerCleanup(cleanupFn) {
7582
+ cleanupFunctions.add(cleanupFn);
7583
+ return () => cleanupFunctions.delete(cleanupFn);
7584
+ }
7585
+
7457
7586
  // ../src/utils/debug.ts
7458
7587
  var isDebugMode = memoize_default(() => {
7459
7588
  return isEnvTruthy(process.env.DEBUG) || isEnvTruthy(process.env.DEBUG_SDK) || process.argv.includes("--debug") || process.argv.includes("-d") || isDebugToStdErr() || process.argv.some((arg) => arg.startsWith("--debug="));
@@ -7478,6 +7607,26 @@ function shouldLogDebugMessage(message) {
7478
7607
  return shouldShowDebugMessage(message, filter);
7479
7608
  }
7480
7609
  var hasFormattedOutput = false;
7610
+ var debugWriter = null;
7611
+ function getDebugWriter() {
7612
+ if (!debugWriter) {
7613
+ debugWriter = createBufferedWriter({
7614
+ writeFn: (content) => {
7615
+ const path = getDebugLogPath();
7616
+ if (!getFsImplementation().existsSync(dirname(path))) {
7617
+ getFsImplementation().mkdirSync(dirname(path));
7618
+ }
7619
+ getFsImplementation().appendFileSync(path, content);
7620
+ updateLatestDebugLogSymlink();
7621
+ },
7622
+ flushIntervalMs: 1000,
7623
+ maxBufferSize: 100,
7624
+ immediateMode: isDebugMode()
7625
+ });
7626
+ registerCleanup(async () => debugWriter?.dispose());
7627
+ }
7628
+ return debugWriter;
7629
+ }
7481
7630
  function logForDebugging(message, { level } = {
7482
7631
  level: "debug"
7483
7632
  }) {
@@ -7495,20 +7644,16 @@ function logForDebugging(message, { level } = {
7495
7644
  writeToStderr(output);
7496
7645
  return;
7497
7646
  }
7498
- if (!getFsImplementation().existsSync(dirname(getDebugLogPath()))) {
7499
- getFsImplementation().mkdirSync(dirname(getDebugLogPath()));
7500
- }
7501
- getFsImplementation().appendFileSync(getDebugLogPath(), output);
7502
- updateLatestDebugLogSymlink();
7647
+ getDebugWriter().write(output);
7503
7648
  }
7504
7649
  function getDebugLogPath() {
7505
- return process.env.CLAUDE_CODE_DEBUG_LOGS_DIR ?? join2(getClaudeConfigHomeDir(), "debug", `${getSessionId()}.txt`);
7650
+ return process.env.CLAUDE_CODE_DEBUG_LOGS_DIR ?? join3(getClaudeConfigHomeDir(), "debug", `${getSessionId()}.txt`);
7506
7651
  }
7507
7652
  var updateLatestDebugLogSymlink = memoize_default(() => {
7508
7653
  try {
7509
7654
  const debugLogPath = getDebugLogPath();
7510
7655
  const debugLogsDir = dirname(debugLogPath);
7511
- const latestSymlinkPath = join2(debugLogsDir, "latest");
7656
+ const latestSymlinkPath = join3(debugLogsDir, "latest");
7512
7657
  if (!getFsImplementation().existsSync(debugLogsDir)) {
7513
7658
  getFsImplementation().mkdirSync(debugLogsDir);
7514
7659
  }
@@ -7522,7 +7667,7 @@ var updateLatestDebugLogSymlink = memoize_default(() => {
7522
7667
  });
7523
7668
 
7524
7669
  // ../src/core/Query.ts
7525
- import { randomUUID as randomUUID2 } from "crypto";
7670
+ import { randomUUID as randomUUID3 } from "crypto";
7526
7671
 
7527
7672
  class Query {
7528
7673
  transport;
@@ -7888,7 +8033,7 @@ class Query {
7888
8033
  }
7889
8034
  const controlRequest = {
7890
8035
  type: "control_request",
7891
- request_id: randomUUID2(),
8036
+ request_id: randomUUID3(),
7892
8037
  request: {
7893
8038
  subtype: "mcp_message",
7894
8039
  server_name: serverName,
@@ -7928,6 +8073,108 @@ class Query {
7928
8073
  }
7929
8074
  }
7930
8075
 
8076
+ // ../src/core/Session.ts
8077
+ import { join as join4 } from "path";
8078
+ import { fileURLToPath } from "url";
8079
+ class SessionImpl {
8080
+ closed = false;
8081
+ inputStream;
8082
+ query;
8083
+ queryIterator = null;
8084
+ abortController;
8085
+ constructor(options) {
8086
+ this.inputStream = new Stream;
8087
+ let pathToClaudeCodeExecutable = options.pathToClaudeCodeExecutable;
8088
+ if (!pathToClaudeCodeExecutable) {
8089
+ const filename = fileURLToPath(import.meta.url);
8090
+ const dirname2 = join4(filename, "..");
8091
+ pathToClaudeCodeExecutable = join4(dirname2, "cli.js");
8092
+ }
8093
+ const processEnv = { ...process.env };
8094
+ if (!processEnv.CLAUDE_CODE_ENTRYPOINT) {
8095
+ processEnv.CLAUDE_CODE_ENTRYPOINT = "sdk-ts";
8096
+ }
8097
+ this.abortController = createAbortController();
8098
+ const transport = new ProcessTransport({
8099
+ abortController: this.abortController,
8100
+ pathToClaudeCodeExecutable,
8101
+ env: processEnv,
8102
+ executable: options.executable ?? (isRunningWithBun() ? "bun" : "node"),
8103
+ executableArgs: options.executableArgs ?? [],
8104
+ extraArgs: {},
8105
+ customSystemPrompt: "",
8106
+ maxThinkingTokens: undefined,
8107
+ maxTurns: undefined,
8108
+ maxBudgetUsd: undefined,
8109
+ model: options.model,
8110
+ fallbackModel: undefined,
8111
+ permissionMode: "default",
8112
+ allowDangerouslySkipPermissions: false,
8113
+ continueConversation: false,
8114
+ resume: options.resume,
8115
+ settingSources: [],
8116
+ allowedTools: [],
8117
+ disallowedTools: [],
8118
+ mcpServers: {},
8119
+ strictMcpConfig: false,
8120
+ canUseTool: false,
8121
+ hooks: false,
8122
+ includePartialMessages: false,
8123
+ forkSession: false,
8124
+ resumeSessionAt: undefined
8125
+ });
8126
+ this.query = new Query(transport, false, undefined, undefined, this.abortController, new Map);
8127
+ this.query.streamInput(this.inputStream);
8128
+ }
8129
+ async send(message) {
8130
+ if (this.closed) {
8131
+ throw new Error("Cannot send to closed session");
8132
+ }
8133
+ const userMessage = typeof message === "string" ? {
8134
+ type: "user",
8135
+ session_id: "",
8136
+ message: {
8137
+ role: "user",
8138
+ content: [{ type: "text", text: message }]
8139
+ },
8140
+ parent_tool_use_id: null
8141
+ } : message;
8142
+ this.inputStream.enqueue(userMessage);
8143
+ }
8144
+ async* receive() {
8145
+ if (!this.queryIterator) {
8146
+ this.queryIterator = this.query[Symbol.asyncIterator]();
8147
+ }
8148
+ while (true) {
8149
+ const { value, done } = await this.queryIterator.next();
8150
+ if (done) {
8151
+ return;
8152
+ }
8153
+ yield value;
8154
+ if (value.type === "result") {
8155
+ return;
8156
+ }
8157
+ }
8158
+ }
8159
+ close() {
8160
+ if (this.closed) {
8161
+ return;
8162
+ }
8163
+ this.closed = true;
8164
+ this.inputStream.done();
8165
+ this.abortController.abort();
8166
+ }
8167
+ async[Symbol.asyncDispose]() {
8168
+ this.close();
8169
+ }
8170
+ }
8171
+ function createSession(options) {
8172
+ return new SessionImpl(options);
8173
+ }
8174
+ function resumeSession(sessionId, options) {
8175
+ return new SessionImpl({ ...options, resume: sessionId });
8176
+ }
8177
+
7931
8178
  // ../node_modules/zod/v3/external.js
7932
8179
  var exports_external = {};
7933
8180
  __export(exports_external, {
@@ -14807,7 +15054,6 @@ function createSdkMcpServer(options) {
14807
15054
  instance: server
14808
15055
  };
14809
15056
  }
14810
-
14811
15057
  // ../src/entrypoints/agentSdk.ts
14812
15058
  function query({
14813
15059
  prompt,
@@ -14825,11 +15071,11 @@ function query({
14825
15071
  }
14826
15072
  let pathToClaudeCodeExecutable = rest.pathToClaudeCodeExecutable;
14827
15073
  if (!pathToClaudeCodeExecutable) {
14828
- const filename = fileURLToPath(import.meta.url);
14829
- const dirname2 = join3(filename, "..");
14830
- pathToClaudeCodeExecutable = join3(dirname2, "cli.js");
15074
+ const filename = fileURLToPath2(import.meta.url);
15075
+ const dirname2 = join5(filename, "..");
15076
+ pathToClaudeCodeExecutable = join5(dirname2, "cli.js");
14831
15077
  }
14832
- process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.51";
15078
+ process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.52";
14833
15079
  const {
14834
15080
  abortController = createAbortController(),
14835
15081
  additionalDirectories = [],
@@ -14942,7 +15188,34 @@ function query({
14942
15188
  }
14943
15189
  return queryInstance;
14944
15190
  }
15191
+ function unstable_v2_createSession(options) {
15192
+ return createSession(options);
15193
+ }
15194
+ function unstable_v2_resumeSession(sessionId, options) {
15195
+ return resumeSession(sessionId, options);
15196
+ }
15197
+ async function unstable_v2_prompt(message, options) {
15198
+ let __stack = [];
15199
+ try {
15200
+ const session = __using(__stack, createSession(options), 1);
15201
+ await session.send(message);
15202
+ for await (const msg of session.receive()) {
15203
+ if (msg.type === "result") {
15204
+ return msg;
15205
+ }
15206
+ }
15207
+ throw new Error("Session ended without result message");
15208
+ } catch (_catch) {
15209
+ var _err = _catch, _hasErr = 1;
15210
+ } finally {
15211
+ var _promise = __callDispose(__stack, _err, _hasErr);
15212
+ _promise && await _promise;
15213
+ }
15214
+ }
14945
15215
  export {
15216
+ unstable_v2_resumeSession,
15217
+ unstable_v2_prompt,
15218
+ unstable_v2_createSession,
14946
15219
  tool,
14947
15220
  query,
14948
15221
  createSdkMcpServer,