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;
  name?: string;
  messages: TamboThreadMessage[];
  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";
StatusDescription
idleNo generation in progress
waitingWaiting for server response
streamingActively receiving streamed response

Error information is tracked separately in StreamingState.error, not as a run status.

StreamingState

Detailed streaming state returned by useTambo().

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

Authentication Types

TamboAuthState

Discriminated union tracking the SDK's authentication lifecycle. Returned by useTambo() as authState.

type TamboAuthState =
  | { status: "identified"; source: "userKey" | "tokenExchange" }
  | { status: "exchanging" }
  | { status: "error"; error: Error }
  | { status: "invalid" }
  | { status: "unauthenticated" };
StatusAdditional PropertiesDescription
identifiedsource: "userKey" | "tokenExchange"Ready to make API calls. source indicates how auth was established.
exchangingA userToken was provided and token exchange is in progress
errorerror: ErrorToken exchange failed
invalidBoth userKey and userToken were provided (must use one, not both)
unauthenticatedNeither userKey nor userToken was provided

Example: Auth-Aware UI

import { useTambo } from "@tambo-ai/react";

function AuthAwareChat() {
  const { authState, isIdentified } = useTambo();

  if (authState.status === "exchanging") {
    return <div>Authenticating...</div>;
  }

  if (authState.status === "error") {
    return <div>Auth failed: {authState.error.message}</div>;
  }

  if (!isIdentified) {
    return <div>Please sign in to continue.</div>;
  }

  return <ChatInterface />;
}

Configuration Types

TamboConfig

Configuration interface for the Tambo provider. Passed to TamboProvider or accessed via useTamboConfig().

interface TamboConfig {
  userKey?: string;
  autoGenerateThreadName?: boolean;
  autoGenerateNameThreshold?: number;
  initialMessages?: InitialInputMessage[];
}
PropertyTypeDefaultDescription
userKeystringUser key for thread ownership and scoping
autoGenerateThreadNamebooleantrueAutomatically generate thread names after a threshold of messages
autoGenerateNameThresholdnumber3Message count at which thread name auto-generation triggers
initialMessagesInitialInputMessage[]Initial messages to seed new threads with (displayed immediately, sent on first user message)

InitialInputMessage

Message type for seeding new threads with initial messages. Re-exported from @tambo-ai/typescript-sdk.

interface InitialInputMessage {
  content: Array<TextContent | ResourceContent>;
  role: "user" | "system" | "assistant";
  metadata?: unknown;
}
PropertyTypeRequiredDescription
contentArray<TextContent | ResourceContent>YesContent blocks (text or resource)
role"user" | "system" | "assistant"YesMessage role
metadataunknownNoAdditional metadata to attach to the message

Example: Seeding a Thread

import { TamboProvider } from "@tambo-ai/react";

function App() {
  return (
    <TamboProvider
      apiKey="your-api-key"
      initialMessages={[
        {
          role: "system",
          content: [
            { type: "text", text: "You are a helpful cooking assistant." },
          ],
        },
        {
          role: "assistant",
          content: [
            { type: "text", text: "What would you like to cook today?" },
          ],
        },
      ]}
    >
      <Chat />
    </TamboProvider>
  );
}

Message Types

TamboThreadMessage

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

interface TamboThreadMessage {
  id: string;
  role: MessageRole;
  content: Content[];
  createdAt?: string;
  metadata?: Record<string, unknown>;
  parentMessageId?: string;
  reasoning?: string[];
  reasoningDurationMS?: number;
}
PropertyTypeDescription
parentMessageIdstringID of the parent message, if created during generation of another message (e.g., MCP sampling).
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
  | TamboComponentContent
  | TamboToolUseContent
  | ToolResultContent
  | ResourceContent;

TextContent

Plain text content.

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

TamboComponentContent

A rendered component with streaming state. Extends the base ComponentContent from the SDK with computed properties.

interface TamboComponentContent {
  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.

TamboToolUseContent

A tool invocation with display metadata. Extends the base ToolUseContent from the SDK with computed properties populated by useTambo().

interface TamboToolUseContent {
  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_statusMessage?: string;
  _tambo_completionStatusMessage?: string;
}

ToolResultContent

The result of a tool execution.

interface ToolResultContent {
  type: "tool_result";
  toolUseId: string;
  content: Array<TextContent | ResourceContent>;
  isError?: boolean;
}

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?: SupportedSchema;
  loadingComponent?: ComponentType<any>;
  associatedTools?: TamboTool[];
  annotations?: ToolAnnotations;
}

Properties

PropertyTypeRequiredDescription
namestringYesUnique identifier for the component
descriptionstringYesDescription for AI understanding
componentComponentTypeYesThe React component to render
propsSchemaSupportedSchemaNoSchema for component props (Zod, Valibot, ArkType, or JSON Schema)
loadingComponentComponentTypeNoComponent to render while the component is loading
associatedToolsTamboTool[]NoTools associated with this component
annotationsToolAnnotationsNoBehavior annotations (see ToolAnnotations)

Example Registration

import { z } from "zod";

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: WeatherCardSchema,
  },
];

ComponentRendererProps

Props for the ComponentRenderer component.

interface ComponentRendererProps {
  content: TamboComponentContent;
  threadId: string;
  messageId: string;
  fallback?: React.ReactNode;
}

TamboCurrentComponent

Component metadata returned by useTamboCurrentComponent. Works for both AI-generated and interactable components.

interface TamboCurrentComponent {
  componentName?: string;
  props?: Record<string, unknown>;
  interactableId?: string;
  description?: string;
  threadId?: string;
}
PropertyTypeDescription
componentNamestring | undefinedComponent name from the message or interactable metadata
propsRecord<string, unknown>Component props from the message content block
interactableIdstring | undefinedInteractable ID (only for withTamboInteractable components)
descriptionstring | undefinedDescription (only for withTamboInteractable components)
threadIdstring | undefinedThread ID (not available on messages directly, always undefined)

ComponentContentContext

Context provided by ComponentContentProvider and accessed via useComponentContent.

interface ComponentContentContext {
  componentId: string;
  threadId: string;
  messageId: string;
  componentName: string;
}
PropertyTypeDescription
componentIdstringUnique instance ID for the component
threadIdstringThread the component belongs to
messageIdstringMessage the component belongs to
componentNamestringRegistered component name

Tool Types

TamboTool

The same TamboTool interface from the base SDK is used.

interface TamboTool {
  name: string;
  description: string;
  title?: 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
titlestringNoOptional human-readable name for display purposes
toolfunctionYesThe tool implementation function
inputSchemaSupportedSchemaYesSchema for tool input parameters
outputSchemaSupportedSchemaYesSchema for tool output (informational, not validated at runtime)
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. Each event uses an envelope pattern with a name string and a value object containing the payload.

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

ComponentStartEvent

Emitted when component rendering begins.

type ComponentStartEvent = {
  name: "tambo.component.start";
  value: {
    messageId: string;
    componentId: string;
    componentName: string;
  };
};

ComponentPropsDeltaEvent

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

type ComponentPropsDeltaEvent = {
  name: "tambo.component.props_delta";
  value: {
    componentId: string;
    operations: Operation[];
  };
};

ComponentStateDeltaEvent

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

type ComponentStateDeltaEvent = {
  name: "tambo.component.state_delta";
  value: {
    componentId: string;
    operations: Operation[];
  };
};

ComponentEndEvent

Emitted when component rendering completes.

type ComponentEndEvent = {
  name: "tambo.component.end";
  value: {
    componentId: string;
  };
};

RunAwaitingInputEvent

Emitted when the run is waiting for client-side tool execution.

type RunAwaitingInputEvent = {
  name: "tambo.run.awaiting_input";
  value: {
    pendingToolCalls: PendingToolCall[];
  };
};

PendingToolCall

Information about a tool call awaiting execution.

interface PendingToolCall {
  toolCallId: string;
  toolName: string;
  arguments: string;
}

MessageParentEvent

Emitted when a message was created during the generation of another message (e.g., MCP sampling or elicitation).

type MessageParentEvent = {
  name: "tambo.message.parent";
  value: {
    messageId: string;
    parentMessageId: string;
  };
};

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.

Interactable Types

InteractableComponent

Represents a registered interactable component instance. Extends TamboComponent with instance-specific state. The internal type name is TamboInteractableComponent.

interface TamboInteractableComponent<
  Props = Record<string, unknown>,
  State = Record<string, unknown>,
> extends TamboComponent {
  id: string;
  props: Props;
  isSelected?: boolean;
  state?: State;
  stateSchema?: SupportedSchema<State>;
}
PropertyTypeRequiredDescription
idstringYesUnique identifier for this component instance
propsPropsYesCurrent props for the component
isSelectedbooleanNoWhether the component is selected for AI interaction on next message
stateStateNoCurrent state for the component
stateSchemaSupportedSchema<State>NoSchema for validating state updates

InteractableConfig

Configuration passed to withTamboInteractable() to make a component interactable.

interface InteractableConfig<
  Props = Record<string, unknown>,
  State = Record<string, unknown>,
> {
  componentName: string;
  description: string;
  propsSchema?: SupportedSchema<Props>;
  stateSchema?: SupportedSchema<State>;
  annotations?: ToolAnnotations;
}
PropertyTypeRequiredDescription
componentNamestringYesName used for identification in Tambo
descriptionstringYesDescription of the component for the AI
propsSchemaSupportedSchema<Props>NoSchema for validating prop updates
stateSchemaSupportedSchema<State>NoSchema for validating state updates
annotationsToolAnnotationsNoAnnotations for the auto-registered update tools

WithTamboInteractableProps

Props injected by withTamboInteractable() that can be passed to the wrapped component.

interface WithTamboInteractableProps {
  interactableId?: string;
  onInteractableReady?: (id: string) => void;
  onPropsUpdate?: (newProps: Record<string, unknown>) => void;
}
PropertyTypeDescription
interactableIdstringOptional custom ID (auto-generated if not provided)
onInteractableReady(id: string) => voidCalled when the component is registered
onPropsUpdate(newProps: Record<string, unknown>) => voidCalled when Tambo updates the component's props

Image Types

StagedImage

Represents an image staged for upload in message input.

interface StagedImage {
  id: string;
  name: string;
  dataUrl: string;
  file: File;
  size: number;
  type: string;
}
PropertyTypeDescription
idstringUnique identifier
namestringFile name
dataUrlstringBase64 data URL for preview
fileFileOriginal File object
sizenumberFile size in bytes
typestringMIME type (e.g., "image/png")

Resource Types

ResourceSource

Configuration for dynamic resource sources. Implement this interface to provide custom resources that can be listed and fetched by the SDK.

interface ResourceSource {
  listResources: (search?: string) => Promise<ListResourceItem[]>;
  getResource: (
    uri: string,
    args?: Record<string, unknown>,
  ) => Promise<ReadResourceResult>;
}
PropertyTypeDescription
listResourcesfunctionLists available resources, optionally filtered by a search string
getResourcefunctionFetches the content of a specific resource by URI

getResource may be called with URIs not previously returned by listResources. Implementations should handle unknown URIs gracefully.

Re-exported Types

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

Hook & Provider Types

  • UseTamboReturn - Return type of useTambo()
  • TamboConfig - Provider configuration interface
  • TamboThreadInputContextProps - Context interface for useTamboThreadInput()

Component & Tool Types

  • TamboComponent - Base component registration interface
  • TamboTool - Tool definition interface
  • ComponentRegistry - Map of registered components
  • ParameterSpec - Parameter specification
  • InteractableComponent - Alias for TamboInteractableComponent
  • TamboInteractableContext - Full interactable registry context (see useTamboInteractable())

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

SDK Types

  • Suggestion - AI-generated suggestion
  • SuggestionGenerateParams - Suggestion generation parameters
  • SuggestionGenerateResponse - Suggestion generation response
  • SuggestionListResponse - Suggestion list response
  • InitialInputMessage - Initial message for seeding threads

Error Types

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