import { I as IChatBackend, B as BackendAdapterOptions, g as ChatSession, S as SendMessageOptions, c as ChatMessage, a as ChatEvent, d as IResumableBackend } from './types-ajANVzf7.js';
import { F as FullAgentConfig, I as IAgentService, c as IAgent, d as Message, M as ModelInfo } from './agent-CW9XbmG_.js';
import { C as CopilotBackendOptions, a as ClaudeBackendOptions, V as VercelAIBackendOptions } from './backends-BSrsBYFn.js';
import { I as IChatTransport } from './transport-Ciap4PWK.js';

/**
 * @witqq/agent-sdk/chat/backends/base
 *
 * Abstract base class for backend adapters. Provides shared lifecycle
 * management, event bridge via adaptAgentEvents(), and tool forwarding.
 */

/**
 * Abstract base for backend adapters implementing IChatBackend (core only).
 * Subclasses implement createService() for backend-specific service creation.
 * Resume support is NOT required — subclasses can implement IResumableBackend separately.
 */
declare abstract class BaseBackendAdapter implements IChatBackend {
    readonly name: string;
    private _agentService;
    private _agentServiceFactory;
    private _disposed;
    protected readonly _agentConfig: FullAgentConfig;
    private _ownsService;
    private _currentAgent;
    constructor(name: string, options: BackendAdapterOptions);
    /** Subclasses create their specific IAgentService */
    protected abstract createService(): IAgentService;
    get agentService(): IAgentService;
    get currentModel(): string | undefined;
    /**
     * @deprecated No-op. Tools are passed per-call via SendMessageOptions.tools.
     * Kept for backward compatibility with code that calls setTools() directly.
     */
    setTools(): void;
    sendMessage(session: ChatSession, message: string, options?: SendMessageOptions): Promise<ChatMessage>;
    streamMessage(session: ChatSession, message: string, options?: SendMessageOptions): AsyncIterable<ChatEvent>;
    /**
     * Shared streaming helper: bridges agent events to chat events.
     * Used by both streamMessage() and resume() to avoid duplication.
     */
    protected streamAgentEvents(agent: IAgent, messages: Message[], options?: SendMessageOptions): AsyncIterable<ChatEvent>;
    listModels(): Promise<ModelInfo[]>;
    validate(): Promise<{
        valid: boolean;
        errors: string[];
    }>;
    dispose(): Promise<void>;
    /** Get or create an agent. Model is passed per-call via RunOptions.
     *  Tools are passed per-call via SendMessageOptions — not baked into config.
     *  For persistent sessions, reuses agent when model matches. */
    protected getOrCreateAgent(options?: SendMessageOptions): IAgent;
    /** Subclasses capture backend session ID from agent after streaming */
    protected abstract captureSessionId(agent: IAgent): void;
    protected assertNotDisposed(): void;
}

/**
 * @witqq/agent-sdk/chat/backends/copilot
 *
 * CopilotChatAdapter wraps CopilotAgentService for chat use.
 * Supports persistent session mode for canResume/resume.
 */

/** Options for creating a CopilotChatAdapter */
interface CopilotChatAdapterOptions extends BackendAdapterOptions {
    /** Copilot backend options (cliPath, token, etc.) */
    copilotOptions?: CopilotBackendOptions;
}
/**
 * Backend adapter for GitHub Copilot CLI.
 * Uses persistent session mode for session resume via CLI session ID.
 */
declare class CopilotChatAdapter extends BaseBackendAdapter implements IResumableBackend {
    private _backendSessionId;
    private readonly _copilotOptions?;
    constructor(options: CopilotChatAdapterOptions);
    protected createService(): IAgentService;
    get backendSessionId(): string | null;
    canResume(): boolean;
    resume(session: ChatSession, backendSessionId: string, options?: SendMessageOptions): AsyncIterable<ChatEvent>;
    protected captureSessionId(agent: IAgent): void;
}

/**
 * @witqq/agent-sdk/chat/backends/claude
 *
 * ClaudeChatAdapter wraps ClaudeAgentService for chat use.
 * Supports persistent session mode with Claude's session_id for resume.
 */

/** Options for creating a ClaudeChatAdapter */
interface ClaudeChatAdapterOptions extends BackendAdapterOptions {
    /** Claude backend options (cliPath, model, etc.) */
    claudeOptions?: ClaudeBackendOptions;
}
/**
 * Backend adapter for Claude CLI.
 * Uses persistent session mode for session resume via Claude's session_id.
 */
declare class ClaudeChatAdapter extends BaseBackendAdapter implements IResumableBackend {
    private _backendSessionId;
    private readonly _claudeOptions?;
    constructor(options: ClaudeChatAdapterOptions);
    protected createService(): IAgentService;
    get backendSessionId(): string | null;
    canResume(): boolean;
    resume(session: ChatSession, backendSessionId: string, options?: SendMessageOptions): AsyncIterable<ChatEvent>;
    protected captureSessionId(agent: IAgent): void;
}

/**
 * @witqq/agent-sdk/chat/backends/vercel-ai
 *
 * VercelAIChatAdapter wraps VercelAIAgentService for chat use.
 * Stateless adapter — implements IChatBackend only (no resume support).
 * Each streamMessage/sendMessage creates a fresh agent (per-call session mode).
 */

/** Options for creating a VercelAIChatAdapter */
interface VercelAIChatAdapterOptions extends BackendAdapterOptions {
    /** Vercel AI backend options (baseURL, apiKey, provider, etc.) */
    vercelOptions?: VercelAIBackendOptions;
}
/**
 * Backend adapter for Vercel AI SDK (API-based).
 * Stateless — each call creates a fresh agent. Does not support resume.
 * Implements IChatBackend only (no IResumableBackend).
 */
declare class VercelAIChatAdapter extends BaseBackendAdapter {
    private readonly _vercelOptions?;
    constructor(options: VercelAIChatAdapterOptions);
    protected createService(): IAgentService;
    protected captureSessionId(_agent: IAgent): void;
}

/**
 * @witqq/agent-sdk - WebSocket Chat Transport
 *
 * IChatTransport implementation over WebSocket connections.
 * Accepts a WebSocket-like abstraction compatible with `ws`, native WebSocket, etc.
 */

/** Ready states matching the WebSocket spec (ws, browser, Deno, Bun) */
declare const WS_READY_STATE: {
    readonly CONNECTING: 0;
    readonly OPEN: 1;
    readonly CLOSING: 2;
    readonly CLOSED: 3;
};
/**
 * Minimal WebSocket interface compatible with `ws`, browser WebSocket, Deno, Bun.
 * Only the methods/properties used by WsChatTransport.
 */
interface WebSocketLike {
    readonly readyState: number;
    send(data: string): void;
    close(code?: number, reason?: string): void;
    addEventListener(type: "close", listener: () => void): void;
    addEventListener(type: "error", listener: (err: unknown) => void): void;
}
/** Configuration options for WsChatTransport */
interface WsTransportOptions {
    /** Heartbeat interval in ms. 0 or undefined disables heartbeat. */
    heartbeatMs?: number;
    /** Custom JSON serializer (defaults to JSON.stringify) */
    serialize?: (event: ChatEvent) => string;
}
/**
 * WebSocket transport for ChatEvent streaming.
 * Sends events as JSON messages over a WebSocket connection.
 */
declare class WsChatTransport implements IChatTransport {
    private readonly ws;
    private readonly serialize;
    private _open;
    private _heartbeatTimer;
    constructor(ws: WebSocketLike, options?: WsTransportOptions);
    get isOpen(): boolean;
    send(event: ChatEvent): void;
    close(): void;
    error(err: Error): void;
    private _cleanup;
    private _clearHeartbeat;
}

/**
 * @witqq/agent-sdk - In-Process Chat Transport
 *
 * IChatTransport implementation for zero-network communication.
 * Events are pushed into an internal buffer and consumed via async iteration.
 * Useful for testing, embedded runtimes, CLI tools, and in-process communication.
 */

/**
 * In-process transport for ChatEvent streaming.
 * Producer pushes events via IChatTransport.send(), consumer reads via async iteration.
 *
 * @example
 * ```ts
 * const transport = new InProcessChatTransport();
 *
 * // Consumer side (async iteration)
 * (async () => {
 *   for await (const event of transport) {
 *     console.log("Received:", event);
 *   }
 * })();
 *
 * // Producer side (via streamToTransport or manual)
 * transport.send({ type: "message:start", messageId, role: "assistant" });
 * transport.send({ type: "message:delta", messageId, text: "Hello" });
 * transport.close();
 * ```
 */
declare class InProcessChatTransport implements IChatTransport {
    private _open;
    private _buffer;
    private _resolve;
    private _error;
    get isOpen(): boolean;
    send(event: ChatEvent): void;
    close(): void;
    error(err: Error): void;
    [Symbol.asyncIterator](): AsyncIterator<ChatEvent>;
}

export { BaseBackendAdapter as B, ClaudeChatAdapter as C, InProcessChatTransport as I, VercelAIChatAdapter as V, WS_READY_STATE as W, type ClaudeChatAdapterOptions as a, CopilotChatAdapter as b, type CopilotChatAdapterOptions as c, type VercelAIChatAdapterOptions as d, type WebSocketLike as e, WsChatTransport as f, type WsTransportOptions as g };
