/**
* Standard Schema v1 — a tiny cross-library validation interface implemented
* by Zod, Valibot, ArkType, and others. Anything matching this shape plugs
* into `clientTool({ schema })`.
*
* @see https://standardschema.dev/
*
* We re-declare the spec here (instead of depending on `@standard-schema/spec`)
* so the SDK stays dependency-free and server-safe.
*/
/** The schema itself — what a `z.object(...)` etc. resolves to. */
interface StandardSchemaV1 {
readonly '~standard': {
readonly version: 1;
readonly vendor: string;
readonly validate: (value: unknown) => StandardSchemaResult | Promise>;
readonly types?: {
readonly input: Input;
readonly output: Output;
};
};
}
/** Result of calling `schema['~standard'].validate(value)`. */
type StandardSchemaResult = {
readonly value: Output;
readonly issues?: undefined;
} | {
readonly issues: ReadonlyArray;
};
/** A single validation failure — part of the error path. */
interface StandardSchemaIssue {
readonly message: string;
readonly path?: ReadonlyArray;
}
type InferSchemaInput = Schema extends StandardSchemaV1 ? Input : never;
type InferSchemaOutput = Schema extends StandardSchemaV1 ? Output : never;
interface ConsumeSessionResponse {
url: string;
token: string;
roomName: string;
}
interface ConsumeSessionOptions {
sessionId: string;
sessionKey: string;
baseUrl?: string;
}
interface ClientEvent> {
type: 'client_event';
tool: T;
args: A;
}
/**
* A standalone client tool definition. Composable — combine into arrays
* and derive event types with `ClientEventsFrom`.
*
* At runtime this is just `{ type, name, description }` (exactly what the
* Runway session create payload expects). The `Args` generic is phantom —
* it only exists at the TypeScript level for type narrowing.
*
* When the tool is defined with a `schema` ([Standard Schema](https://standardschema.dev/)),
* the schema is attached internally (not serialized) for runtime validation
* and to infer `Args` from the schema output type.
*/
interface ClientToolDef {
readonly type: 'client_event';
readonly name: Name;
readonly description: string;
/** @internal phantom field — always `undefined` at runtime */
readonly _args?: Args;
}
type ClientToolArgs = Tool extends ClientToolDef ? Args : never;
type ClientEventFromTool = Tool extends ClientToolDef ? ClientEvent : never;
/**
* Derive a discriminated union of ClientEvent types from an array of tools.
*
* @example
* ```typescript
* const tools = [showQuestion, playSound];
* type MyEvent = ClientEventsFrom;
* ```
*/
type ClientEventsFrom> = T[number] extends infer U ? U extends ClientToolDef ? ClientEvent : never : never;
/**
* Return the Standard Schema associated with a tool, if any.
* Useful when composing validation outside of the SDK hooks.
*/
declare function getClientToolSchema(tool: ClientToolDef): StandardSchemaV1 | undefined;
/**
* Validate parsed client event args against a tool's schema.
*
* Returns the typed args on success, or `null` when the schema fails or
* when the schema would need to resolve asynchronously (Standard Schema
* allows async `validate`, but for fire-and-forget client events we only
* accept sync results here).
*
* Tools defined without a schema always validate successfully — the
* incoming args are returned as-is.
*/
declare function validateClientToolArgs(tool: Tool, args: unknown): ClientToolArgs | null;
/**
* Define a single client tool.
*
* Returns a standalone object that can be composed into arrays and passed
* to `realtimeSessions.create({ tools })`.
*
* Two forms are supported:
*
* 1. **Schema-driven** (recommended) — pass a
* [Standard Schema](https://standardschema.dev/) (Zod, Valibot, ArkType, …)
* to infer `args` types and enable runtime validation of incoming events:
*
* ```typescript
* import { z } from 'zod';
* const showCaption = clientTool('show_caption', {
* description: 'Display a caption',
* schema: z.object({ text: z.string() }),
* });
* ```
*
* 2. **Type-only** — pass an `args` type via a cast when you don't need
* runtime validation:
*
* ```typescript
* const showCaption = clientTool('show_caption', {
* description: 'Display a caption',
* args: {} as { text: string },
* });
* ```
*
* Combine tools and derive event types with `ClientEventsFrom`:
*
* ```typescript
* const tools = [showCaption, playSound];
* type MyEvent = ClientEventsFrom;
* ```
*/
declare function clientTool(name: Name, config: {
description: string;
schema: Schema;
}): ClientToolDef>;
declare function clientTool(name: Name, config: {
description: string;
args: Args;
}): ClientToolDef;
declare function consumeSession(options: ConsumeSessionOptions): Promise;
interface CreateElevenLabsSessionOptions {
/** Runway API secret (Bearer token). */
runwayApiSecret: string;
/** ID of a custom avatar to render. Must be visible to `runwayApiSecret`. */
avatarId: string;
/** ElevenLabs API key (used server-side to obtain a signed URL). */
elevenLabsApiKey: string;
/** ID of the ElevenLabs Conversational AI agent (e.g. `agent_…`). */
elevenLabsAgentId: string;
/** Runway API base URL. Defaults to production. */
baseUrl?: string;
/** Maximum time to wait for the session to become ready, in ms. */
timeoutMs?: number;
}
interface CreateElevenLabsSessionResponse {
sessionId: string;
sessionKey: string;
/** Echoed back so it can be passed straight to ``. */
avatarId: string;
/** Resolved base URL (defaults applied) for the consume call on the client. */
baseUrl: string;
}
/**
* Create a Runway avatar session powered by a customer-owned ElevenLabs
* Conversational AI agent. Handles the full server-side flow:
*
* 1. Fetches a signed WebSocket URL from the ElevenLabs API
* 2. Creates a Runway realtime session with the ElevenLabs integration
* 3. Polls until the session is READY and returns credentials
*
* The returned `sessionId`, `sessionKey`, `avatarId`, and `baseUrl` can be
* passed straight to `` (or to `consumeSession` for lower-level
* control).
*
* Run this server-side only — it requires both your Runway API secret and your
* ElevenLabs API key.
*
* The ElevenLabs agent's **User input audio format** must be **PCM 16000Hz**
* (ElevenLabs → agent → Advanced), otherwise the avatar receives no audio.
*
* @throws {AvatarError} with code `ELEVENLABS_SIGNED_URL_FAILED`,
* `SESSION_CREATE_FAILED`, or `CONNECTION_FAILED` (poll timeout).
*/
declare function createElevenLabsSession(options: CreateElevenLabsSessionOptions): Promise;
declare const toolDefs: readonly [ClientToolDef<"click", {
target: string;
}>, ClientToolDef<"scroll_to", {
target: string;
}>, ClientToolDef<"highlight", {
target: string;
duration?: number;
}>];
type PageActionEvent = ClientEventsFrom;
/**
* Pre-built tool definitions with `parameters` arrays, ready to spread
* into `realtimeSessions.create({ tools })`.
*
* @example
* ```ts
* import { pageActionTools } from '@runwayml/avatars-react/api';
*
* await client.realtimeSessions.create({
* model: 'gwm1_avatars',
* avatar: { type: 'runway-preset', presetId: 'music-superstar' },
* tools: [...pageActionTools, ...myCustomTools],
* });
* ```
*/
declare const pageActionTools: ({
parameters: {
name: string;
type: string;
description: string;
}[];
type: "client_event";
name: "click";
description: string;
_args?: {
target: string;
} | undefined;
} | {
parameters: {
name: string;
type: string;
description: string;
}[];
type: "client_event";
name: "scroll_to";
description: string;
_args?: {
target: string;
} | undefined;
} | {
parameters: {
name: string;
type: string;
description: string;
}[];
type: "client_event";
name: "highlight";
description: string;
_args?: {
target: string;
duration?: number;
} | undefined;
})[];
interface PollUntilReadyOptions {
sessionId: string;
apiKey: string;
baseUrl?: string;
timeoutMs?: number;
intervalMs?: number;
}
/**
* Poll a realtime session until it reaches READY status.
*
* Returns `{ sessionId, sessionKey }` — ready to pass to `streamTo` or `connect`.
*
* This is a server-side utility (requires your API key). Use it in
* Next.js API routes, Express handlers, etc.
*
* @example
* ```ts
* import Runway from '@runwayml/sdk';
* import { pollUntilReady } from '@runwayml/avatars/api';
*
* const runway = new Runway();
* const { id: sessionId } = await runway.realtimeSessions.create({ ... });
* const { sessionKey } = await pollUntilReady({ sessionId, apiKey: process.env.RUNWAYML_API_SECRET });
*
* return Response.json({ sessionId, sessionKey });
* ```
*/
declare function pollUntilReady(options: PollUntilReadyOptions): Promise<{
sessionId: string;
sessionKey: string;
}>;
export { type ClientEvent, type ClientEventFromTool, type ClientEventsFrom, type ClientToolArgs, type ClientToolDef, type ConsumeSessionOptions, type ConsumeSessionResponse, type CreateElevenLabsSessionOptions, type CreateElevenLabsSessionResponse, type InferSchemaInput, type InferSchemaOutput, type PageActionEvent, type PollUntilReadyOptions, type StandardSchemaIssue, type StandardSchemaResult, type StandardSchemaV1, clientTool, consumeSession, createElevenLabsSession, getClientToolSchema, pageActionTools, pollUntilReady, validateClientToolArgs };