Class ThreadsClient<TStateType, TUpdateType>

Type Parameters

Hierarchy

  • BaseClient
    • ThreadsClient

Constructors

Properties

apiUrl: string
asyncCaller: AsyncCaller
defaultHeaders: Record<string, HeaderValue>
onRequest?: RequestHook
timeoutMs: undefined | number

Methods

  • Copy an existing thread

    Parameters

    • threadId: string

      ID of the thread to be copied

    Returns Promise<Thread<TStateType>>

    Newly copied thread

  • Create a new thread.

    Parameters

    • Optional payload: {
          graphId?: string;
          ifExists?: OnConflictBehavior;
          metadata?: Metadata;
          supersteps?: {
              updates: {
                  asNode: string;
                  command?: Command;
                  values: unknown;
              }[];
          }[];
          threadId?: string;
      }

      Payload for creating a thread.

      • Optional graphId?: string

        Graph ID to associate with the thread.

      • Optional ifExists?: OnConflictBehavior

        How to handle duplicate creation.

        Default

        "raise"
        
      • Optional metadata?: Metadata

        Metadata for the thread.

      • Optional supersteps?: {
            updates: {
                asNode: string;
                command?: Command;
                values: unknown;
            }[];
        }[]

        Apply a list of supersteps when creating a thread, each containing a sequence of updates.

        Used for copying a thread between deployments.

      • Optional threadId?: string

        ID of the thread to create.

        If not provided, a random UUID will be generated.

    Returns Promise<Thread<TStateType>>

    The created thread.

  • Delete a thread.

    Parameters

    • threadId: string

      ID of the thread.

    Returns Promise<void>

  • Type Parameters

    • T

    Parameters

    • path: string
    • options: RequestInit & {
          json?: unknown;
          params?: Record<string, unknown>;
          signal?: AbortSignal;
          timeoutMs?: null | number;
          withResponse: true;
      }

    Returns Promise<[T, Response]>

  • Type Parameters

    • T

    Parameters

    • path: string
    • Optional options: RequestInit & {
          json?: unknown;
          params?: Record<string, unknown>;
          signal?: AbortSignal;
          timeoutMs?: null | number;
          withResponse?: false;
      }

    Returns Promise<T>

  • Get all past states for a thread.

    Type Parameters

    Parameters

    • threadId: string

      ID of the thread.

    • Optional options: {
          before?: Config;
          checkpoint?: Partial<Omit<Checkpoint, "thread_id">>;
          limit?: number;
          metadata?: Metadata;
      }

      Additional options.

      • Optional before?: Config
      • Optional checkpoint?: Partial<Omit<Checkpoint, "thread_id">>
      • Optional limit?: number
      • Optional metadata?: Metadata

    Returns Promise<ThreadState<ValuesType>[]>

    List of thread states.

  • Get state for a thread.

    Type Parameters

    Parameters

    • threadId: string

      ID of the thread.

    • Optional checkpoint: string | Checkpoint
    • Optional options: {
          subgraphs?: boolean;
      }
      • Optional subgraphs?: boolean

    Returns Promise<ThreadState<ValuesType>>

    Thread state.

  • Patch the metadata of a thread.

    Parameters

    • threadIdOrConfig: string | Config

      Thread ID or config to patch the state of.

    • metadata: Metadata

      Metadata to patch the state with.

    Returns Promise<void>

  • Parameters

    • path: string
    • Optional options: RequestInit & {
          json?: unknown;
          params?: Record<string, unknown>;
          timeoutMs?: null | number;
          withResponse?: boolean;
      }

    Returns [url: URL, init: RequestInit]

  • List threads

    Type Parameters

    Parameters

    • Optional query: {
          limit?: number;
          metadata?: Metadata;
          offset?: number;
          sortBy?: ThreadSortBy;
          sortOrder?: SortOrder;
          status?: ThreadStatus;
      }

      Query options

      • Optional limit?: number

        Maximum number of threads to return. Defaults to 10

      • Optional metadata?: Metadata

        Metadata to filter threads by.

      • Optional offset?: number

        Offset to start from.

      • Optional sortBy?: ThreadSortBy

        Sort by.

      • Optional sortOrder?: SortOrder

        Sort order. Must be one of 'asc' or 'desc'.

      • Optional status?: ThreadStatus

        Thread status to filter on.

    Returns Promise<Thread<ValuesType>[]>

    List of threads

  • Update a thread.

    Parameters

    • threadId: string

      ID of the thread.

    • Optional payload: {
          metadata?: Metadata;
      }

      Payload for updating the thread.

      • Optional metadata?: Metadata

        Metadata for the thread.

    Returns Promise<Thread<DefaultValues>>

    The updated thread.

  • Add state to a thread.

    Type Parameters

    Parameters

    • threadId: string

      The ID of the thread.

    • options: {
          asNode?: string;
          checkpoint?: Checkpoint;
          checkpointId?: string;
          values: ValuesType;
      }
      • Optional asNode?: string
      • Optional checkpoint?: Checkpoint
      • Optional checkpointId?: string
      • values: ValuesType

    Returns Promise<Pick<Config, "configurable">>