ACP v2 (Preview) TypeScript SDK — EXPERIMENTAL - v2.12.1
    Preparing search index...

    Class ActiveSessionExperimental

    Experimental draft ACP v2 convenience wrapper for an active session.

    An active session routes session/update notifications for one session ID into an async queue. Use prompt(...) to submit user content and nextUpdate() to observe the session independently of prompt requests. A stop message reports idle foreground work, not per-prompt completion.

    Index
    • get configOptions(): SessionConfigOption[] | undefined
      Experimental

      Current configuration options for this session, if the agent provided any.

      Starts with the configOptions from session/new. It is replaced with the full list from each config_option_update routed to this session (applied when the notification arrives, before it is read with nextUpdate()) and from each setConfigOption(...) response. Updates stop after dispose(). newSessionResponse.configOptions keeps the original session/new value.

      Returns SessionConfigOption[] | undefined

    • get meta(): { [key: string]: unknown } | null | undefined
      Experimental

      Metadata returned when the session was created.

      Returns { [key: string]: unknown } | null | undefined

    • get background(): readonly BackgroundWork[] | undefined
      Experimental

      The background list from the latest state_update routed to this session, or undefined while background work is not reported.

      Each state_update replaces it, applied when the notification arrives, before it is read with nextUpdate(). [] means no background work is running. A snapshot that omits the list, carries null or a malformed list, or reports a state this SDK does not know resets it to undefined: background work is unknown until a list arrives, and nothing should be treated as abandoned. Updates stop after dispose().

      Returns readonly BackgroundWork[] | undefined

    • Experimental

      Whether request is for work in the latest background list of this session. For a request of this session, that is a listed tool call (by the subject's toolCall.toolCallId, or a command subject's toolCallId) or a listed terminal (by a command subject's terminalId). A request of another session is for listed work when that session is a listed subagent: tool call and terminal IDs are scoped to the session that reports them, so its subject is not compared with this session's items.

      session/cancel does not cover listed work, so permission requests for it stay open. For the cancelled foreground work, the Agent stops waiting on its permission requests and cancels them with $/cancel_request, and the Client dismisses each cancelled request and answers it with the cancelled outcome. A Client may also answer a request with cancelled right after sending session/cancel, without waiting for $/cancel_request, but only when it knows the request belongs to the cancelled work. A false result alone does not establish that: it is also returned for requests without a subject, custom subjects, a request of a child session that is not listed, such as a listed child's own child, and any request while background is not reported. On session/close, the Agent cancels every pending permission request in the session with $/cancel_request. When an Agent sends a permission request with cancellationSignal and stopWaitingOnCancel: true, aborting the signal sends $/cancel_request and stops waiting for the answer.

      Parameters

      Returns boolean

    • Experimental

      Whether the tool call currently advertises capabilities.cancel, from the tool_call_update patches routed to this session.

      Parameters

      • toolCallId: string

      Returns boolean

    • Experimental

      Whether the terminal currently advertises capabilities.cancel, from the terminal_update patches routed to this session.

      Parameters

      • terminalId: string

      Returns boolean

    • Experimental

      Cancels one tool call with tool_call/cancel.

      Rejects with a TypeError, without sending the request, unless the tool call currently advertises capabilities.cancel (see canCancelToolCall). The response means the Agent accepted the cancellation, not that the work stopped. The Agent confirms it with a tool_call_update to a final status.

      This only covers tool calls reported in this session. A subagent's tool call is reported in its child session, so send methods.agent.toolCall.cancel through ClientContext.request with the child's sessionId. The tool call's own capabilities.cancel enables that even when the child session doesn't advertise cancel.

      The Agent answers -32602 once the tool call has a final status. This includes a request sent again after the first one was accepted. The tool_call_update with that status reports the outcome.

      Parameters

      Returns Promise<CancelToolCallResponse>

    • Experimental

      Stops a terminal's process with terminal/cancel.

      Rejects with a TypeError, without sending the request, unless the terminal currently advertises capabilities.cancel (see canCancelTerminal). The response means the Agent accepted the cancellation, not that the process stopped. The Agent confirms it with a terminal_update that sets exitStatus. The terminal is not released.

      This only covers terminals reported in this session. A subagent's terminal is reported in its child session, so send methods.agent.terminal.cancel through ClientContext.request with the child's sessionId. The terminal's own capabilities.cancel enables that even when the child session doesn't advertise cancel.

      The Agent answers -32602 once the process has exited. This includes a request sent again after the first one was accepted. The terminal_update that sets exitStatus reports the outcome.

      Parameters

      Returns Promise<CancelTerminalResponse>

    • Experimental

      Sends a prompt to this session.

      Strings are converted to one text content block. A single content block is wrapped in an array. A prompt must contain at least one block. The returned promise resolves with the inserted user message's ID once the agent inserts it into the ACP conversation, not when processing finishes.

      A prompt may be sent while the agent is working. The agent inserts it right away or holds it and inserts it later, in the order received; the promise stays pending until then. session/cancel and session/close drop the prompts the agent has received but not inserted, and the agent answers each with -32800. session/cancel does not affect a prompt sent after it: the agent does not reject that prompt because a cancellation is in progress, and starts its work only after it reported idle with stopReason: "cancelled" for the cancelled work. Aborting options.cancellationSignal sends $/cancel_request for the prompt, which is best effort. An agent that honors it answers -32800 and does not insert the message. Otherwise the prompt is inserted and the promise resolves with its messageId. An inserted prompt cannot be withdrawn. Stop the work it started with session/cancel.

      If the response is lost, for example because the connection ended, the session does not show whether the message was inserted. Pass options.idempotencyKey to identify retries of the same submission: while the agent recognizes the key, a retry resolves with the original messageId and inserts no second message. A retry with a key the agent has forgotten is a new submission. See ActiveSessionPromptOptions.

      Session updates remain independent of this request and have no fixed order relative to its response; an idle state_update does not establish that this message was processed. Rejection is reported only by this promise, not by the session update queue. The agent reports the inserted message with a user_message update that carries the same messageId. The agent owns that message, so its content can differ from the prompt you sent.

      Parameters

      Returns Promise<PromptResponse>

    • Experimental

      Sets a configuration option for this session with session/set_config_option.

      The response carries the agent's complete configOptions list, which replaces configOptions on this session. For example, session.setConfigOption({ configId: "model", type: "id", value: "fast" }).

      Parameters

      • request:
            | {
                type: "id";
                value: string;
                configId: string;
                _meta?: { [key: string]: unknown }
                | null;
            }
            | {
                type: "boolean";
                value: boolean;
                configId: string;
                _meta?: { [key: string]: unknown }
                | null;
            }
            | {
                type: `_${string}`;
                value: unknown;
                configId: string;
                _meta?: { [key: string]: unknown }
                | null;
                [key: string]: unknown;
            }
            | {
                "[unknownVariant]": true;
                type: string;
                value: unknown;
                configId: string;
                _meta?: { [key: string]: unknown }
                | null;
                [key: string]: unknown;
            }
        • {
              type: "id";
              value: string;
              configId: string;
              _meta?: { [key: string]: unknown } | null;
          }
          • type: "id"
          • value: string

            The value ID.

          • configId: string

            The ID of the configuration option to set.

          • Optional_meta?: { [key: string]: unknown } | null

            The _meta property is reserved by ACP to allow Clients and Agents to attach additional metadata to their interactions. Omitted and null are equivalent and mean no metadata. Implementations MUST NOT assign meaning to keys they do not recognize.

            See protocol docs: Extensibility

        • {
              type: "boolean";
              value: boolean;
              configId: string;
              _meta?: { [key: string]: unknown } | null;
          }
          • type: "boolean"
          • value: boolean

            The boolean value.

          • configId: string

            The ID of the configuration option to set.

          • Optional_meta?: { [key: string]: unknown } | null

            The _meta property is reserved by ACP to allow Clients and Agents to attach additional metadata to their interactions. Omitted and null are equivalent and mean no metadata. Implementations MUST NOT assign meaning to keys they do not recognize.

            See protocol docs: Extensibility

        • {
              type: `_${string}`;
              value: unknown;
              configId: string;
              _meta?: { [key: string]: unknown } | null;
              [key: string]: unknown;
          }
          • [key: string]: unknown
          • type: `_${string}`

            Custom or future session configuration option value type.

            Values beginning with _ are reserved for implementation-specific extensions. Unknown values that do not begin with _ are reserved for future ACP variants.

          • value: unknown

            Raw value payload for the custom or future value type.

          • configId: string

            The ID of the configuration option to set.

          • Optional_meta?: { [key: string]: unknown } | null

            The _meta property is reserved by ACP to allow Clients and Agents to attach additional metadata to their interactions. Omitted and null are equivalent and mean no metadata. Implementations MUST NOT assign meaning to keys they do not recognize.

            See protocol docs: Extensibility

        • {
              "[unknownVariant]": true;
              type: string;
              value: unknown;
              configId: string;
              _meta?: { [key: string]: unknown } | null;
              [key: string]: unknown;
          }
          • [key: string]: unknown
          • Readonly[unknownVariant]: true
          • type: string

            Custom or future session configuration option value type.

            Values beginning with _ are reserved for implementation-specific extensions. Unknown values that do not begin with _ are reserved for future ACP variants.

          • value: unknown

            Raw value payload for the custom or future value type.

          • configId: string

            The ID of the configuration option to set.

          • Optional_meta?: { [key: string]: unknown } | null

            The _meta property is reserved by ACP to allow Clients and Agents to attach additional metadata to their interactions. Omitted and null are equivalent and mean no metadata. Implementations MUST NOT assign meaning to keys they do not recognize.

            See protocol docs: Extensibility

      • Optionaloptions: SendRequestOptions

      Returns Promise<SetSessionConfigOptionResponse>

    • Experimental

      Reads the next update or stop message for this session.

      Idle updates are always returned as stop messages, whether or not a prompt is pending. Queued updates are consumed in arrival order. An abort signal cancels this read without cancelling session work or discarding updates.

      Parameters

      • Optionalsignal: AbortSignal

      Returns Promise<ActiveSessionMessage>

    • Experimental

      Collects agent text from the session queue until the next idle update.

      This consumes the same queue as nextUpdate(), including already queued updates. It does not associate output or idle with any submitted prompt, skip updates when a prompt is sent, or wait for a prompt to be inserted. Use one reader at a time to avoid splitting the session's updates. An abort signal cancels the read without cancelling session work.

      Full agent_message updates replace content for their messageId, while agent_message_chunk updates append to it. Non-text content and other update types are ignored; use nextUpdate() when you need them.

      Parameters

      • Optionalsignal: AbortSignal

      Returns Promise<string>

    • Experimental

      Stops routing updates to this active-session helper.

      This does not close the ACP session on the agent. Use ClientContext session lifecycle methods when the protocol session itself should be closed or deleted.

      Returns void

    • Experimental

      Supports explicit resource management with using.

      Returns void