React SDK
Loading...

React SDK Types

TypeScript interfaces and types exported by @tambo-ai/react

The @tambo-ai/react package exports TypeScript types and interfaces for building type-safe AI applications.

Thread Types

TamboThread

Represents a conversation thread with messages and metadata.

interface TamboThread {
  id: string;
  title?: string;
  messages: TamboMessage[];
  status: RunStatus;
  metadata?: Record<string, unknown>;
  createdAt: string;
  updatedAt: string;
  lastRunCancelled: boolean;
}

RunStatus

The status of the current run in a thread.

type RunStatus = "idle" | "waiting" | "streaming" | "complete" | "error";
StatusDescription
idleNo generation in progress
waitingWaiting for server response
streamingActively receiving streamed response
completeGeneration finished successfully
errorAn error occurred

StreamingState

Detailed streaming state returned by useTambo().

interface StreamingState {
  status: RunStatus;
  runId?: string;
  messageId?: string;
  startTime?: number;
  error?: {
    message: string;
    code?: string;
  };
}

Message Types

TamboMessage

A message in a thread, containing an array of content blocks.

interface TamboMessage {
  id: string;
  role: MessageRole;
  content: Content[];
  createdAt?: string;
  metadata?: Record<string, unknown>;
  reasoning?: string[];
  reasoningDurationMS?: number;
}
PropertyTypeDescription
reasoningstring[]Reasoning chunks from the model. Transient — only present during streaming, not persisted to the API.
reasoningDurationMSnumberDuration of the reasoning phase in milliseconds, for display purposes.

MessageRole

The role of a message sender.

type MessageRole = "user" | "assistant" | "system";

Content Types

Messages contain an array of typed content blocks:

type Content =
  | TextContent
  | ComponentContent
  | ToolUseContent
  | ToolResultContent
  | ResourceContent;

TextContent

Plain text content.

interface TextContent {
  type: "text";
  text: string;
}

ComponentContent

A rendered component with streaming state.

interface ComponentContent {
  type: "component";
  id: string;
  name: string;
  props: Record<string, unknown>;
  streamingState?: "started" | "streaming" | "done";
  renderedComponent?: ReactElement | null;
}

The renderedComponent property contains the pre-rendered React element for the component, looked up from the registry.

ToolUseContent

A tool invocation with display metadata.

interface ToolUseContent {
  type: "tool_use";
  id: string;
  name: string;
  input: Record<string, unknown>;
  hasCompleted?: boolean;
  statusMessage?: string;
  tamboDisplayProps?: TamboToolDisplayProps;
}

The input object has internal _tambo_* properties automatically stripped. Display messages are available via tamboDisplayProps.

TamboToolDisplayProps

Display properties extracted from tool inputs.

interface TamboToolDisplayProps {
  _tambo_displayMessage?: string;
  _tambo_statusMessage?: string;
  _tambo_completionStatusMessage?: string;
}

ToolResultContent

The result of a tool execution.

interface ToolResultContent {
  type: "tool_result";
  tool_use_id: string;
  content: string | ContentPart[];
}

ResourceContent

An MCP resource reference.

interface ResourceContent {
  type: "resource";
  uri: string;
  name?: string;
  mimeType?: string;
  text?: string;
}

Component Types

TamboComponent

Configuration for registering a component with Tambo.

interface TamboComponent {
  name: string;
  description: string;
  component: ComponentType<any>;
  propsSchema: Record<string, unknown>;
  stateSchema?: Record<string, unknown>;
  initialState?: () => Record<string, unknown>;
}

Properties

PropertyTypeRequiredDescription
namestringYesUnique identifier for the component
descriptionstringYesDescription for AI understanding
componentComponentTypeYesThe React component to render
propsSchemaobjectYesJSON Schema for component props
stateSchemaobjectNoJSON Schema for component state
initialState() => objectNoFactory function for initial state

Example Registration

import { z } from "zod";
import { zodToJsonSchema } from "zod-to-json-schema";

const WeatherCardSchema = z.object({
  city: z.string().describe("The city name"),
  temperature: z.number().describe("Temperature in Fahrenheit"),
  condition: z.string().describe("Weather condition"),
});

const components: TamboComponent[] = [
  {
    name: "WeatherCard",
    description: "Displays current weather for a city",
    component: WeatherCard,
    propsSchema: zodToJsonSchema(WeatherCardSchema),
  },
];

TamboComponentProps

Props interface for components receiving Tambo data.

interface TamboComponentProps<TProps, TState> {
  props: TProps;
  state?: TState;
  componentId: string;
  isStreaming?: boolean;
}

Tool Types

TamboTool

The same TamboTool interface from the base SDK is used.

interface TamboTool {
  name: string;
  description: string;
  tool: (params: Record<string, unknown>) => unknown;
  inputSchema: SupportedSchema;
  outputSchema: SupportedSchema;
  transformToContent?: (result: any) => Promise<ContentPart[]> | ContentPart[];
  maxCalls?: number;
  annotations?: ToolAnnotations;
}
PropertyTypeRequiredDescription
namestringYesUnique identifier for the tool
descriptionstringYesDescription for AI understanding
toolfunctionYesThe tool implementation function
inputSchemaSupportedSchemaYesSchema for tool input parameters
outputSchemaSupportedSchemaYesSchema for tool output
maxCallsnumberNoMaximum times this tool can be called in a single response. Overrides the project-level tool call limit.
annotationsToolAnnotationsNoBehavior annotations (see ToolAnnotations)
transformToContentfunctionNoTransform tool result into content parts for richer display

Event Types

TamboCustomEvent

Custom events emitted during streaming.

type TamboCustomEvent =
  | ComponentStartEvent
  | ComponentPropsDeltaEvent
  | ComponentStateDeltaEvent
  | ComponentEndEvent
  | RunAwaitingInputEvent;

ComponentStartEvent

Emitted when component rendering begins.

interface ComponentStartEvent {
  name: "tambo.component.start";
  componentId: string;
  componentName: string;
}

ComponentPropsDeltaEvent

Emitted when component props are updated (JSON Patch format).

interface ComponentPropsDeltaEvent {
  name: "tambo.component.props_delta";
  componentId: string;
  delta: JsonPatchOperation[];
}

ComponentStateDeltaEvent

Emitted when component state is updated (JSON Patch format).

interface ComponentStateDeltaEvent {
  name: "tambo.component.state_delta";
  componentId: string;
  delta: JsonPatchOperation[];
}

ComponentEndEvent

Emitted when component rendering completes.

interface ComponentEndEvent {
  name: "tambo.component.end";
  componentId: string;
}

RunAwaitingInputEvent

Emitted when the run is waiting for tool execution.

interface RunAwaitingInputEvent {
  name: "tambo.run.awaiting_input";
  toolCalls: ToolCall[];
}

Type Guards

Helper functions for working with events:

function isTamboCustomEvent(event: {
  name?: string;
}): event is TamboCustomEvent;
function asTamboCustomEvent(event: CustomEvent): TamboCustomEvent | undefined;

Input Types

SubmitOptions

Options passed to useTamboThreadInput().submit().

interface SubmitOptions {
  debug?: boolean;
  toolChoice?: ToolChoice;
}
PropertyTypeDescription
debugbooleanEnable debug logging for this submission
toolChoiceToolChoiceControl how the model selects tools (see below)

ToolChoice

Controls how the model selects tools during generation.

type ToolChoice = "auto" | "required" | "none" | { name: string };
ValueDescription
"auto"Model decides whether to use tools (default)
"required"Model must use at least one tool
"none"Model cannot use tools
{ name: string }Model must use the specified tool

Stream Status Types

StreamStatus

Overall streaming status for a component, returned by useTamboStreamStatus().

interface StreamStatus {
  isPending: boolean;
  isStreaming: boolean;
  isSuccess: boolean;
  isError: boolean;
  streamError?: Error;
}
PropertyTypeDescription
isPendingbooleanNo tokens received yet and generation is not active
isStreamingbooleanAt least one prop is still streaming
isSuccessbooleanAll props finished streaming without error
isErrorbooleanA fatal error occurred in the stream or any prop
streamErrorErrorThe first error encountered during streaming

PropStatus

Per-prop streaming status, returned by useTamboStreamStatus().

interface PropStatus {
  isPending: boolean;
  isStreaming: boolean;
  isSuccess: boolean;
  error?: Error;
}
PropertyTypeDescription
isPendingbooleanNo tokens received for this prop yet
isStreamingbooleanTokens received but streaming is not complete
isSuccessbooleanThis prop has finished streaming successfully
errorErrorError that occurred during streaming for this prop

Tool Annotations

ToolAnnotations

Annotations describing a tool's behavior, extending the MCP specification.

type ToolAnnotations = MCPToolAnnotations & {
  tamboStreamableHint?: boolean;
};
PropertyTypeDescription
tamboStreamableHintbooleanWhen true, the tool can be called with partially-streamed arguments as they arrive. Use for read-only tools without side effects.

ToolAnnotations can be set on both TamboTool and TamboComponent via the annotations property.

Re-exported Types

The following types are re-exported from the base SDK for convenience:

Component & Tool Types

  • TamboComponent - Base component registration interface
  • TamboTool - Tool definition interface
  • ComponentRegistry - Map of registered components
  • ParameterSpec - Parameter specification

Context Types

  • ContextHelpers - Collection of context helpers
  • ContextHelperFn - Context helper function signature
  • AdditionalContext - Additional context interface

MCP Types

  • MCPTransport - Transport type enum
  • McpServerInfo - MCP server configuration
  • NormalizedMcpServerInfo - Processed server info
  • ReadResourceResult - Resource read result
  • ListResourceItem - Resource list item
  • ResourceSource - Resource source interface

SDK Types

  • Suggestion - AI-generated suggestion
  • SuggestionGenerateParams - Suggestion generation parameters
  • SuggestionGenerateResponse - Suggestion generation response

Error Types

  • TamboAIError - Base error class
  • APIError - API error
  • RateLimitError - Rate limit error