import { type OperatorSdk } from '@pellux/goodvibes-operator-sdk';
import { type PeerSdk } from '@pellux/goodvibes-peer-sdk';
import type { AuthTokenResolver, HeaderResolver, HttpRetryPolicy, StreamReconnectPolicy, TransportMiddleware } from '@pellux/goodvibes-transport-http';
import { type RemoteRuntimeEvents } from '@pellux/goodvibes-transport-realtime';
import type { AnyRuntimeEvent } from './events/index.js';
import { type AutoRefreshOptions, type GoodVibesAuthClient, type GoodVibesTokenStore } from './auth.js';
import type { SDKObserver } from './observer/index.js';
/**
 * Discriminated union of all runtime events emitted by the GoodVibes daemon.
 *
 * TypeScript narrows the full event shape (including all payload fields) when
 * matching on the `type` discriminant — no `as` casts required.
 *
 * Each domain's events are accessible via the per-domain feed:
 * ```ts
 * const events = sdk.realtime.viaSse();
 * events.agents.on('AGENT_SPAWNING', (payload) => {
 *   console.log(payload.agentId, payload.task); // fully typed
 * });
 * ```
 *
 * @see AnyRuntimeEvent for the full discriminated union type.
 *
 * @public
 */
export type { RuntimeEventRecord } from './events/index.js';
/**
 * Options for constructing a GoodVibes SDK instance.
 *
 * ### Auth token precedence (highest → lowest)
 * 1. **`tokenStore`** — when present, `getToken()` is called on every request.
 *    Mutations (`login`, `setToken`, `clearToken`) persist back to the store.
 * 2. **`getAuthToken`** — a read-only async resolver. No persistence; mutations
 *    throw `ConfigurationError`.
 * 3. **`authToken`** — a static string (or `null`). Wrapped in a
 *    `createMemoryTokenStore` internally so mutations work in-process.
 *
 * Only provide one of the three. If none are supplied the SDK operates without
 * credentials (useful for public endpoints).
 */
export interface GoodVibesSdkOptions {
    /**
     * Base URL of the GoodVibes daemon, e.g. `'https://my-daemon.example.com'`.
     * Must be a non-empty string. A trailing slash is trimmed automatically.
     */
    readonly baseUrl: string;
    /**
     * Static auth token string. Wrapped in an in-memory token store,
     * so `sdk.auth.setToken()` / `sdk.auth.clearToken()` work.
     *
     * Lowest-precedence auth option — ignored when `tokenStore` or `getAuthToken`
     * is also provided.
     *
     * @see https://github.com/mgd34msu/goodvibes-sdk/blob/main/docs/authentication.md
     */
    readonly authToken?: string | null | undefined;
    /**
     * Async token resolver called before every authenticated request.
     * Use this when your token lives outside the SDK (e.g. retrieved from a
     * framework session or an external secret store).
     *
     * When this option is set, `sdk.auth.writable` is `false` — calling
     * `setToken` / `clearToken` throws a `ConfigurationError`.
     *
     * Takes precedence over `authToken`; ignored when `tokenStore` is provided.
     *
     * @see https://github.com/mgd34msu/goodvibes-sdk/blob/main/docs/authentication.md
     */
    readonly getAuthToken?: AuthTokenResolver | undefined;
    /**
     * A mutable token store implementing `getToken / setToken / clearToken`.
     * The SDK calls `getToken()` before every request and writes back via
     * `setToken()` after a successful `sdk.auth.login()`.
     *
     * Highest-precedence auth option — overrides both `getAuthToken` and
     * `authToken`. Use `createBrowserTokenStore()` (localStorage) or
     * `createMemoryTokenStore()` for common cases.
     *
     * @see https://github.com/mgd34msu/goodvibes-sdk/blob/main/docs/authentication.md
     */
    readonly tokenStore?: GoodVibesTokenStore | undefined;
    /**
     * Custom `fetch` implementation. Falls back to `globalThis.fetch`.
     * Required in environments without a native fetch (e.g. older Node.js).
     */
    readonly fetch?: typeof fetch | undefined;
    /**
     * Static extra headers sent on every request, e.g.
     * `{ 'X-Tenant-Id': 'acme' }`.
     */
    readonly headers?: HeadersInit | undefined;
    /**
     * Async resolver for per-request headers. Called on each request after the
     * auth header is set. Useful for adding request-scoped tracing headers.
     */
    readonly getHeaders?: HeaderResolver | undefined;
    /**
     * HTTP retry policy for transient failures (408, 429, 5xx).
     * Runtime-specific factories (e.g. `createBrowserGoodVibesSdk`,
     * `createReactNativeGoodVibesSdk`) apply sensible defaults; pass this to override.
     */
    readonly retry?: HttpRetryPolicy | undefined;
    /**
     * Custom `WebSocket` constructor. Falls back to `globalThis.WebSocket`.
     * Required in Node.js < 21 or when using a polyfill.
     */
    readonly WebSocketImpl?: typeof WebSocket | undefined;
    /**
     * Options that control realtime transport behaviour (SSE and WebSocket
     * reconnect policies, error callback).
     */
    readonly realtime?: GoodVibesRealtimeOptions | undefined;
    /**
     * Optional observer for SDK-level observability hooks.
     *
     * Pass a `SDKObserver` implementation (or one of the built-in adapters
     * like `createConsoleObserver` / `createOpenTelemetryObserver`) to receive
     * callbacks for auth transitions, transport activity, events, and errors.
     *
     * All observer methods are wrapped in a silent try/catch — observer
     * exceptions never propagate into SDK logic.
     */
    readonly observer?: SDKObserver | undefined;
    /**
     * Initial middleware chain applied to every HTTP request/response cycle on
     * BOTH the operator and peer transports. Middleware added here is pushed into
     * each transport's chain independently — it runs twice per SDK call (once for
     * operator, once for peer) if both are used. To target a single transport,
     * append directly via `sdk.operator.transport.use(mw)` or
     * `sdk.peer.transport.use(mw)` after construction.
     *
     * Middleware functions receive a mutable `TransportContext` and a `next()`
     * callback. They run in the order provided (outer-first, onion model).
     *
     * Additional middleware can be appended at any time via `sdk.use(mw)`.
     *
     * @example
     * const sdk = createGoodVibesSdk({
     *   baseUrl: 'https://daemon.example.com',
     *   middleware: [
     *     async (ctx, next) => {
     *       ctx.headers['X-Request-Id'] = crypto.randomUUID();
     *       await next();
     *     },
     *   ],
     * });
     */
    readonly middleware?: TransportMiddleware[] | undefined;
    /**
     * Options for token auto-refresh.
     *
     * - `autoRefresh` — when `false`, disables automatic refresh entirely and lets
     *   401 responses propagate to the caller immediately. Default: `true`.
     * - `refreshLeewayMs` — milliseconds before token expiry to trigger a
     *   pre-flight refresh. Default: 60_000 (1 minute).
     * - `refresh` — optional callback invoked to obtain a new token on pre-flight
     *   leeway trigger or reactive 401. When absent, pre-flight is a no-op and
     *   401 retry re-reads the token store (useful when an external party updates
     *   it). See `AutoRefreshOptions.refresh` for a full example.
     */
    readonly autoRefresh?: AutoRefreshOptions | undefined;
}
/**
 * Options controlling realtime transport behaviour.
 */
export interface GoodVibesRealtimeOptions {
    readonly sseReconnect?: StreamReconnectPolicy | undefined;
    readonly webSocketReconnect?: StreamReconnectPolicy | undefined;
    readonly onError?: ((error: unknown) => void) | undefined;
}
/**
 * Realtime event subscriptions for the GoodVibes daemon.
 * Choose SSE for read-only event streams or WebSocket for bidirectional use.
 *
 * ### Filtering by session
 *
 * When multiple sessions share one SSE/WebSocket connection, use
 * `forSession(events, sessionId)` to get a pre-filtered view instead of
 * manually guarding every callback with `if (e.sessionId !== mine) return`.
 *
 * @example
 * import { createGoodVibesSdk, forSession } from '@pellux/goodvibes-sdk';
 *
 * const sdk = createGoodVibesSdk({ baseUrl: 'http://127.0.0.1:3421' });
 * const session = await sdk.operator.sessions.create({ title: 'demo' });
 * const sessionId = session.session.id;
 *
 * const events = sdk.realtime.viaSse();
 * const sessionEvents = forSession(events, sessionId);
 *
 * sessionEvents.turn.onEnvelope('STREAM_DELTA', (e) => {
 *   process.stdout.write(e.payload.content); // only fires for this session
 * });
 */
export interface GoodVibesRealtime {
    viaSse(): RemoteRuntimeEvents<AnyRuntimeEvent>;
    viaWebSocket(webSocketImpl?: typeof WebSocket): RemoteRuntimeEvents<AnyRuntimeEvent>;
}
/**
 * The GoodVibes SDK instance returned by `createGoodVibesSdk` (and its
 * runtime-specific wrappers).
 *
 * Three primary namespaces:
 * - **`operator`** — full control-plane API (daemon admin, agent management,
 *   session lifecycle, config). Requires an operator-level auth token.
 * - **`peer`** — peer-to-peer and collaboration APIs (pairing, channels,
 *   shared sessions). May be used with peer-scoped tokens.
 * - **`realtime`** — subscribe to live daemon events via SSE or WebSocket.
 * - **`auth`** — login, logout, and token management helpers.
 */
export interface GoodVibesSdk {
    /**
     * Full control-plane API: daemon admin, agent management, session lifecycle,
     * config. Requires an operator-level auth token.
     *
     * @see https://github.com/mgd34msu/goodvibes-sdk/blob/main/docs/reference-operator.md
     */
    readonly operator: OperatorSdk;
    /**
     * Peer-to-peer and collaboration APIs: pairing, channels, shared sessions.
     * May be used with peer-scoped tokens.
     *
     * @see https://github.com/mgd34msu/goodvibes-sdk/blob/main/docs/reference-peer.md
     */
    readonly peer: PeerSdk;
    /**
     * Login, logout, and token management helpers.
     *
     * @see https://github.com/mgd34msu/goodvibes-sdk/blob/main/docs/authentication.md
     */
    readonly auth: GoodVibesAuthClient;
    /**
     * Subscribe to live daemon events via SSE or WebSocket.
     *
     * @see https://github.com/mgd34msu/goodvibes-sdk/blob/main/docs/realtime-and-telemetry.md
     */
    readonly realtime: GoodVibesRealtime;
    /**
     * Append a middleware to the SDK's HTTP transport chain.
     *
     * Multiple `use()` calls compose in order (outer-first). The method is
     * idempotent in the sense that each call simply appends — call it once per
     * middleware to avoid double-registration.
     *
     * @example
     * sdk.use(async (ctx, next) => {
     *   ctx.headers['X-Tenant-Id'] = 'acme';
     *   await next();
     * });
     */
    use(middleware: TransportMiddleware): void;
}
/**
 * Create a GoodVibes SDK instance.
 *
 * This is the runtime-agnostic constructor. For environments with sensible
 * defaults already configured, prefer the platform-specific wrappers:
 * `createBrowserGoodVibesSdk`, `createReactNativeGoodVibesSdk`.
 *
 * @see https://github.com/mgd34msu/goodvibes-sdk/blob/main/docs/getting-started.md
 *
 * @example
 * // Example only: replace baseUrl and authToken with your own values.
 * import { createGoodVibesSdk } from '@pellux/goodvibes-sdk';
 *
 * const sdk = createGoodVibesSdk({
 *   baseUrl: 'https://daemon.example.com',
 *   authToken: process.env.GV_TOKEN,
 * });
 *
 * const agents = await sdk.operator.agents.list();
 * console.log(agents);
 */
export declare function createGoodVibesSdk(options: GoodVibesSdkOptions): GoodVibesSdk;
//# sourceMappingURL=client.d.ts.map