shawon_majid

types.tsx

Nov 12th, 2025
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TypeScript 2.98 KB | Source Code | 0 0
  1. /* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */
  2.  
  3. import {
  4.   Client,
  5.   ClientConfig,
  6.   Command,
  7.   Config,
  8.   CustomStreamEvent,
  9.   DebugStreamEvent,
  10.   EventsStreamEvent,
  11.   MetadataStreamEvent,
  12.   ThreadState,
  13.   UpdatesStreamEvent,
  14. } from '@langchain/langgraph-sdk';
  15.  
  16. export type MessageMetadata<StateType extends Record<string, unknown>> = {
  17.   /**
  18.    * The ID of the message used.
  19.    */
  20.   messageId: string;
  21.  
  22.   /**
  23.    * The first thread state the message was seen in.
  24.    */
  25.   firstSeenState: ThreadState<StateType> | undefined;
  26.  
  27.   /**
  28.    * The branch of the message.
  29.    */
  30.   branch: string | undefined;
  31.  
  32.   /**
  33.    * The list of branches this message is part of.
  34.    * This is useful for displaying branching controls.
  35.    */
  36.   branchOptions: string[] | undefined;
  37.  
  38.   /**
  39.    * Metadata sent alongside the message during run streaming.
  40.    * @remarks This metadata only exists temporarily in browser memory during streaming and is not persisted after completion.
  41.    */
  42.   streamMetadata: Record<string, unknown> | undefined;
  43. };
  44.  
  45. export type BagTemplate = {
  46.   ConfigurableType?: Record<string, unknown>;
  47.   InterruptType?: unknown;
  48.   CustomEventType?: unknown;
  49.   UpdateType?: unknown;
  50. };
  51.  
  52. export type GetUpdateType<
  53.   Bag extends BagTemplate,
  54.   StateType extends Record<string, unknown>,
  55. > = Bag extends { UpdateType: unknown }
  56.   ? Bag['UpdateType']
  57.   : Partial<StateType>;
  58.  
  59. export type GetConfigurableType<Bag extends BagTemplate> = Bag extends {
  60.   ConfigurableType: Record<string, unknown>;
  61. }
  62.   ? Bag['ConfigurableType']
  63.   : Record<string, unknown>;
  64.  
  65. export type GetInterruptType<Bag extends BagTemplate> = Bag extends {
  66.   InterruptType: unknown;
  67. }
  68.   ? Bag['InterruptType']
  69.   : unknown;
  70.  
  71. export type GetCustomEventType<Bag extends BagTemplate> = Bag extends {
  72.   CustomEventType: unknown;
  73. }
  74.   ? Bag['CustomEventType']
  75.   : unknown;
  76.  
  77. export interface RunCallbackMeta {
  78.   run_id: string;
  79.   thread_id: string;
  80. }
  81.  
  82. export interface UseStreamThread<StateType extends Record<string, unknown>> {
  83.   data: ThreadState<StateType>[] | null | undefined;
  84.   error: unknown;
  85.   isLoading: boolean;
  86.   mutate: (
  87.     mutateId?: string,
  88.   ) => Promise<ThreadState<StateType>[] | null | undefined>;
  89. }
  90.  
  91. type ConfigWithConfigurable<ConfigurableType extends Record<string, unknown>> =
  92.   Config & { configurable?: ConfigurableType };
  93. /**
  94.  * Transport used to stream the thread.
  95.  * Only applicable for custom endpoints using `toLangGraphEventStream` or `toLangGraphEventStreamResponse`.
  96.  */
  97. export interface UseStreamTransport<
  98.   StateType extends Record<string, unknown> = Record<string, unknown>,
  99.   Bag extends BagTemplate = BagTemplate,
  100. > {
  101.   stream: (payload: {
  102.     input: GetUpdateType<Bag, StateType> | null | undefined;
  103.     context: GetConfigurableType<Bag> | undefined;
  104.     command: Command | undefined;
  105.     config: ConfigWithConfigurable<GetConfigurableType<Bag>> | undefined;
  106.     signal: AbortSignal;
  107.   }) => Promise<AsyncGenerator<{ id?: string; event: string; data: unknown }>>;
  108. }
  109.  
Advertisement
Add Comment
Please, Sign In to add comment