import { Agent } from './agent.js'; import { Options, type SessionContext } from './job.js'; import type { RecordingConfig } from './config.js'; /** * A factory that builds a fresh {@link Agent}. * * Pass one to {@link serve} to get a new Agent + Pipeline per call, which is * required for correct per-call state and pipeline hooks under concurrent calls. * Declare a parameter (`(context) => ...`) to receive the call's * {@link SessionContext} and read `context.metadata` while building the agent. */ export type AgentFactory = (() => Agent) | ((context: SessionContext) => Agent); /** * An {@link Agent} subclass constructor. * * Pass the class itself to {@link serve} (e.g. `serve(MyAgent)`) to get a fresh * Agent + Pipeline per call. Declare a constructor parameter * (`constructor(context) { ... }`) to receive the call's {@link SessionContext} and * read `context.metadata` before `super(...)`. * * A union of the zero-arg and context-taking forms so a class with a *required* * `constructor(context)` (the common case) is accepted - an optional-parameter * signature would reject it. */ export type AgentClass = (new () => Agent) | (new (context: SessionContext) => Agent); /** * True when `fn` declares at least one parameter. `Function.length` counts the * parameters before the first one with a default or a rest parameter, so a * `(context) => ...` callable reports `1` and a zero-arg one reports `0`. */ export declare function acceptsContext(fn: unknown): boolean; /** * Normalize the {@link serve} agent argument into a per-call builder. Returns a * `(context) => Agent` that forwards `context` only when the class/factory declares a * parameter, or `null` for a shared {@link Agent} instance (no factory). */ export declare function resolveAgentBuilder(agent: Agent | AgentFactory | AgentClass): ((context: SessionContext) => Agent) | null; /** Options for {@link serve}. */ export type ServeOptions = { /** Registration id the agent is reachable by. Defaults to the agent's own id. */ agentId?: string; /** ZRT auth token. Falls back to `ZRT_AUTH_TOKEN` / `ZRT_API_KEY` + `ZRT_SECRET_KEY`. */ authToken?: string; /** Callback invoked once the agent is registered and ready to accept sessions. */ onReady?: () => void; /** Maximum concurrent sessions. Defaults to `10` (or `ZRT_MAX_CONCURRENT_SESSIONS`). */ capacity?: number; /** Load fraction (0-1) above which the worker reports itself busy. Defaults to `0.75`. */ loadThreshold?: number; /** Seconds to wait for the agent/models to initialize before the worker is considered failed. Raise it when model load is slow. Defaults to `10.0`. */ initializeTimeout?: number; /** Base URL of the signaling/registry service. Defaults to the standard endpoint. */ rtcBaseUrl?: string; /** Log level (`DEBUG`/`INFO`/`WARNING`/`ERROR`/`CRITICAL`). Defaults to `'INFO'`. */ logLevel?: string; /** Start the local debug HTTP server. Defaults to `true`. */ debug?: boolean; /** Port for the debug server when `debug` is enabled. Defaults to `8081`. */ debugPort?: number; /** Network interface the worker binds. Defaults to `'0.0.0.0'`. */ host?: string; /** Record sessions: `true` for defaults, or a {@link RecordingConfig} for custom output. Defaults to `false`. */ recording?: boolean | RecordingConfig; /** Enable camera-frame capture for every session. Defaults to `false`. */ vision?: boolean; /** Enable background-audio playback. Defaults to `false`. */ backgroundAudio?: boolean; /** Deliver raw input audio to listeners. Defaults to `false`. */ audioListenerEnabled?: boolean; /** Avatar configuration to attach to each session. Defaults to `null`. */ avatar?: unknown; /** Allow playground sessions. Defaults to `true`. */ playground?: boolean; /** End the session automatically when the caller leaves. Defaults to `true`. */ autoEndSession?: boolean; /** Hard cap on session duration, in seconds. */ sessionTimeoutSeconds?: number | null; /** End the session if no participant joins within this many seconds. */ noParticipantTimeoutSeconds?: number | null; /** Fixed participant id to publish the agent under. */ agentParticipantId?: string | null; /** Base worker {@link Options} to extend; serve overrides registration-related fields. */ options?: Options; }; /** * Register an agent with the Zero Runtime and serve sessions dispatched to it. * * Registers under `options.agentId` (or the agent's own id) and runs until the * process receives a shutdown signal, starting a new {@link AgentSession} for * each dispatched session. Pair with {@link invoke} to start sessions against the * registered agent. * * @param agent - One of: a configured {@link Agent} instance; a zero-arg * {@link Agent} subclass (the class itself, e.g. `serve(MyAgent)`); or an * {@link AgentFactory} returning an Agent. A class or factory yields a fresh * Agent + Pipeline per call - required for correct per-call state and pipeline * hooks under concurrent calls. A shared instance is still accepted for simple, * stateless agents. In every case the agent must carry a `pipeline` and an id. * @param options - Registration, capacity, and debug settings. See {@link ServeOptions}. * @throws If the agent has no pipeline or no resolvable id. */ export declare function serve(agent: Agent | AgentFactory | AgentClass, options?: ServeOptions): Promise;