@anthropic-ai/claude-agent-sdk 0.1.71 → 0.1.73

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.
@@ -311,14 +311,14 @@ export type HookJSONOutput = AsyncHookJSONOutput | SyncHookJSONOutput;
311
311
  */
312
312
  export type PermissionMode = 'default' | 'acceptEdits' | 'bypassPermissions' | 'plan' | 'delegate' | 'dontAsk';
313
313
  /**
314
- * Information about an available slash command.
314
+ * Information about an available skill (invoked via /command syntax).
315
315
  */
316
316
  export type SlashCommand = {
317
- /** Command name (without the leading slash) */
317
+ /** Skill name (without the leading slash) */
318
318
  name: string;
319
- /** Description of what the command does */
319
+ /** Description of what the skill does */
320
320
  description: string;
321
- /** Hint for command arguments (e.g., "<file>") */
321
+ /** Hint for skill arguments (e.g., "<file>") */
322
322
  argumentHint: string;
323
323
  };
324
324
  /**
@@ -561,9 +561,9 @@ export interface Query extends AsyncGenerator<SDKMessage, void> {
561
561
  */
562
562
  setMaxThinkingTokens(maxThinkingTokens: number | null): Promise<void>;
563
563
  /**
564
- * Get the list of available slash commands for the current session.
564
+ * Get the list of available skills for the current session.
565
565
  *
566
- * @returns Array of available slash commands with their names and descriptions
566
+ * @returns Array of available skills with their names and descriptions
567
567
  */
568
568
  supportedCommands(): Promise<SlashCommand[]>;
569
569
  /**
@@ -645,8 +645,8 @@ export interface SDKSession {
645
645
  readonly sessionId: string;
646
646
  /** Send a message to the agent */
647
647
  send(message: string | SDKUserMessage): Promise<void>;
648
- /** Receive messages from the agent */
649
- receive(): AsyncGenerator<SDKMessage, void>;
648
+ /** Stream messages from the agent */
649
+ stream(): AsyncGenerator<SDKMessage, void>;
650
650
  /** Close the session */
651
651
  close(): void;
652
652
  /** Async disposal support (calls close if not already closed) */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anthropic-ai/claude-agent-sdk",
3
- "version": "0.1.71",
3
+ "version": "0.1.73",
4
4
  "main": "sdk.mjs",
5
5
  "types": "sdk.d.ts",
6
6
  "engines": {
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://code.claude.com/docs/en/legal-and-compliance.
3
3
 
4
- // Version: 0.1.71
4
+ // Version: 0.1.73
5
5
 
6
6
  // Want to see the unminified source? We're hiring!
7
7
  // https://job-boards.greenhouse.io/anthropic/jobs/4816199008
@@ -12602,7 +12602,8 @@ function getInitialState() {
12602
12602
  initJsonSchema: null,
12603
12603
  registeredHooks: null,
12604
12604
  planSlugCache: new Map,
12605
- teleportedSessionInfo: null
12605
+ teleportedSessionInfo: null,
12606
+ invokedSkills: new Map
12606
12607
  };
12607
12608
  }
12608
12609
  var STATE = getInitialState();
@@ -13497,6 +13498,7 @@ import { randomUUID as randomUUID3 } from "crypto";
13497
13498
 
13498
13499
  class Query {
13499
13500
  transport;
13501
+ isSingleUserTurn;
13500
13502
  canUseTool;
13501
13503
  hooks;
13502
13504
  abortController;
@@ -13512,26 +13514,19 @@ class Query {
13512
13514
  nextCallbackId = 0;
13513
13515
  sdkMcpTransports = new Map;
13514
13516
  pendingMcpResponses = new Map;
13515
- lastActivityTime = Date.now();
13516
- userInputEndedResolve;
13517
- streamCloseTimeout;
13518
- resetLastActivityTime() {
13519
- this.lastActivityTime = Date.now();
13520
- }
13517
+ firstResultReceivedResolve;
13518
+ firstResultReceived = false;
13521
13519
  hasBidirectionalNeeds() {
13522
13520
  return this.sdkMcpTransports.size > 0 || this.hooks !== undefined && Object.keys(this.hooks).length > 0 || this.canUseTool !== undefined;
13523
13521
  }
13524
- constructor(transport, _isSingleUserTurn, canUseTool, hooks, abortController, sdkMcpServers = new Map, jsonSchema, initConfig) {
13522
+ constructor(transport, isSingleUserTurn, canUseTool, hooks, abortController, sdkMcpServers = new Map, jsonSchema, initConfig) {
13525
13523
  this.transport = transport;
13524
+ this.isSingleUserTurn = isSingleUserTurn;
13526
13525
  this.canUseTool = canUseTool;
13527
13526
  this.hooks = hooks;
13528
13527
  this.abortController = abortController;
13529
13528
  this.jsonSchema = jsonSchema;
13530
13529
  this.initConfig = initConfig;
13531
- this.streamCloseTimeout = 5000;
13532
- if (typeof process !== "undefined" && process.env?.CLAUDE_CODE_STREAM_CLOSE_TIMEOUT) {
13533
- this.streamCloseTimeout = parseInt(process.env.CLAUDE_CODE_STREAM_CLOSE_TIMEOUT);
13534
- }
13535
13530
  for (const [name, server] of sdkMcpServers) {
13536
13531
  const sdkTransport = new SdkControlServerTransport((message) => this.sendMcpServerMessageToCli(name, message));
13537
13532
  this.sdkMcpTransports.set(name, sdkTransport);
@@ -13586,7 +13581,6 @@ class Query {
13586
13581
  async readMessages() {
13587
13582
  try {
13588
13583
  for await (const message of this.transport.readMessages()) {
13589
- this.resetLastActivityTime();
13590
13584
  if (message.type === "control_response") {
13591
13585
  const handler = this.pendingControlResponses.get(message.response.request_id);
13592
13586
  if (handler) {
@@ -13602,16 +13596,26 @@ class Query {
13602
13596
  } else if (message.type === "keep_alive") {
13603
13597
  continue;
13604
13598
  }
13599
+ if (message.type === "result") {
13600
+ this.firstResultReceived = true;
13601
+ if (this.firstResultReceivedResolve) {
13602
+ this.firstResultReceivedResolve();
13603
+ }
13604
+ if (this.isSingleUserTurn) {
13605
+ logForDebugging(`[Query.readMessages] First result received for single-turn query, closing stdin`);
13606
+ this.transport.endInput();
13607
+ }
13608
+ }
13605
13609
  this.inputStream.enqueue(message);
13606
13610
  }
13607
- if (this.userInputEndedResolve) {
13608
- this.userInputEndedResolve();
13611
+ if (this.firstResultReceivedResolve) {
13612
+ this.firstResultReceivedResolve();
13609
13613
  }
13610
13614
  this.inputStream.done();
13611
13615
  this.cleanup();
13612
13616
  } catch (error) {
13613
- if (this.userInputEndedResolve) {
13614
- this.userInputEndedResolve();
13617
+ if (this.firstResultReceivedResolve) {
13618
+ this.firstResultReceivedResolve();
13615
13619
  }
13616
13620
  this.inputStream.error(error);
13617
13621
  this.cleanup(error);
@@ -13827,8 +13831,8 @@ class Query {
13827
13831
  }
13828
13832
  logForDebugging(`[Query.streamInput] Finished processing ${messageCount} messages from input stream`);
13829
13833
  if (this.hasBidirectionalNeeds()) {
13830
- logForDebugging(`[Query.streamInput] Has bidirectional needs, waiting for inactivity`);
13831
- await this.waitForInactivity();
13834
+ logForDebugging(`[Query.streamInput] Has bidirectional needs, waiting for first result`);
13835
+ await this.waitForFirstResult();
13832
13836
  }
13833
13837
  logForDebugging(`[Query] Calling transport.endInput() to close stdin to CLI process`);
13834
13838
  this.transport.endInput();
@@ -13838,18 +13842,12 @@ class Query {
13838
13842
  }
13839
13843
  }
13840
13844
  }
13841
- async handleSingleTurnInputComplete() {
13842
- if (this.hasBidirectionalNeeds()) {
13843
- logForDebugging(`[Query.handleSingleTurnInputComplete] Has bidirectional needs, waiting for inactivity`);
13844
- await this.waitForInactivity();
13845
+ waitForFirstResult() {
13846
+ if (this.firstResultReceived) {
13847
+ logForDebugging(`[Query.waitForFirstResult] Result already received, returning immediately`);
13848
+ return Promise.resolve();
13845
13849
  }
13846
- logForDebugging(`[Query.handleSingleTurnInputComplete] Calling transport.endInput()`);
13847
- this.transport.endInput();
13848
- }
13849
- async waitForInactivity() {
13850
- logForDebugging(`[Query.waitForInactivity] Waiting for inactivity (timeout: ${this.streamCloseTimeout}ms)`);
13851
13850
  return new Promise((resolve) => {
13852
- this.userInputEndedResolve = resolve;
13853
13851
  if (this.abortController?.signal.aborted) {
13854
13852
  resolve();
13855
13853
  return;
@@ -13857,22 +13855,7 @@ class Query {
13857
13855
  this.abortController?.signal.addEventListener("abort", () => resolve(), {
13858
13856
  once: true
13859
13857
  });
13860
- const checkInactivity = () => {
13861
- if (this.abortController?.signal.aborted) {
13862
- resolve();
13863
- return;
13864
- }
13865
- const elapsed = Date.now() - this.lastActivityTime;
13866
- if (elapsed >= this.streamCloseTimeout) {
13867
- logForDebugging(`[Query.waitForInactivity] Inactivity timeout reached (${elapsed}ms elapsed). ` + `Closing stdin. If your tools or hooks need more time, set CLAUDE_CODE_STREAM_CLOSE_TIMEOUT ` + `to a higher value (current: ${this.streamCloseTimeout}ms).`);
13868
- resolve();
13869
- } else {
13870
- const remaining = this.streamCloseTimeout - elapsed;
13871
- logForDebugging(`[Query.waitForInactivity] Still active, checking again in ${remaining}ms`);
13872
- setTimeout(checkInactivity, remaining);
13873
- }
13874
- };
13875
- checkInactivity();
13858
+ this.firstResultReceivedResolve = resolve;
13876
13859
  });
13877
13860
  }
13878
13861
  handleHookCallbacks(callbackId, input, toolUseID, abortSignal) {
@@ -14013,7 +13996,7 @@ class SessionImpl {
14013
13996
  } : message;
14014
13997
  this.inputStream.enqueue(userMessage);
14015
13998
  }
14016
- async* receive() {
13999
+ async* stream() {
14017
14000
  if (!this.queryIterator) {
14018
14001
  this.queryIterator = this.query[Symbol.asyncIterator]();
14019
14002
  }
@@ -26703,7 +26686,7 @@ function query({
26703
26686
  const dirname2 = join5(filename, "..");
26704
26687
  pathToClaudeCodeExecutable = join5(dirname2, "cli.js");
26705
26688
  }
26706
- process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.71";
26689
+ process.env.CLAUDE_AGENT_SDK_VERSION = "0.1.73";
26707
26690
  const {
26708
26691
  abortController = createAbortController(),
26709
26692
  additionalDirectories = [],
@@ -26825,7 +26808,6 @@ function query({
26825
26808
  parent_tool_use_id: null
26826
26809
  }) + `
26827
26810
  `);
26828
- queryInstance.handleSingleTurnInputComplete();
26829
26811
  } else {
26830
26812
  queryInstance.streamInput(prompt);
26831
26813
  }
@@ -26842,7 +26824,7 @@ async function unstable_v2_prompt(message, options) {
26842
26824
  try {
26843
26825
  const session = __using(__stack, createSession(options), 1);
26844
26826
  await session.send(message);
26845
- for await (const msg of session.receive()) {
26827
+ for await (const msg of session.stream()) {
26846
26828
  if (msg.type === "result") {
26847
26829
  return msg;
26848
26830
  }