@langchain/langgraph-sdk 1.3.1 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/CHANGELOG.md +0 -281
- package/dist/_virtual/rolldown_runtime.cjs +0 -25
- package/dist/auth/error.cjs +0 -79
- package/dist/auth/error.cjs.map +0 -1
- package/dist/auth/error.d.cts +0 -13
- package/dist/auth/error.d.cts.map +0 -1
- package/dist/auth/error.d.ts +0 -13
- package/dist/auth/error.d.ts.map +0 -1
- package/dist/auth/error.js +0 -78
- package/dist/auth/error.js.map +0 -1
- package/dist/auth/index.cjs +0 -39
- package/dist/auth/index.cjs.map +0 -1
- package/dist/auth/index.d.cts +0 -31
- package/dist/auth/index.d.cts.map +0 -1
- package/dist/auth/index.d.ts +0 -31
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/index.js +0 -37
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/types.d.cts +0 -294
- package/dist/auth/types.d.cts.map +0 -1
- package/dist/auth/types.d.ts +0 -294
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/client.cjs +0 -1219
- package/dist/client.cjs.map +0 -1
- package/dist/client.d.cts +0 -803
- package/dist/client.d.cts.map +0 -1
- package/dist/client.d.ts +0 -803
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -1212
- package/dist/client.js.map +0 -1
- package/dist/index.cjs +0 -6
- package/dist/index.d.cts +0 -7
- package/dist/index.d.ts +0 -7
- package/dist/index.js +0 -4
- package/dist/logging/index.cjs +0 -35
- package/dist/logging/index.cjs.map +0 -1
- package/dist/logging/index.d.cts +0 -47
- package/dist/logging/index.d.cts.map +0 -1
- package/dist/logging/index.d.ts +0 -47
- package/dist/logging/index.d.ts.map +0 -1
- package/dist/logging/index.js +0 -34
- package/dist/logging/index.js.map +0 -1
- package/dist/react/index.cjs +0 -5
- package/dist/react/index.d.cts +0 -4
- package/dist/react/index.d.ts +0 -4
- package/dist/react/index.js +0 -4
- package/dist/react/stream.cjs +0 -18
- package/dist/react/stream.cjs.map +0 -1
- package/dist/react/stream.custom.cjs +0 -129
- package/dist/react/stream.custom.cjs.map +0 -1
- package/dist/react/stream.custom.d.cts +0 -39
- package/dist/react/stream.custom.d.cts.map +0 -1
- package/dist/react/stream.custom.d.ts +0 -39
- package/dist/react/stream.custom.d.ts.map +0 -1
- package/dist/react/stream.custom.js +0 -127
- package/dist/react/stream.custom.js.map +0 -1
- package/dist/react/stream.d.cts +0 -73
- package/dist/react/stream.d.cts.map +0 -1
- package/dist/react/stream.d.ts +0 -73
- package/dist/react/stream.d.ts.map +0 -1
- package/dist/react/stream.js +0 -17
- package/dist/react/stream.js.map +0 -1
- package/dist/react/stream.lgp.cjs +0 -446
- package/dist/react/stream.lgp.cjs.map +0 -1
- package/dist/react/stream.lgp.js +0 -445
- package/dist/react/stream.lgp.js.map +0 -1
- package/dist/react/thread.cjs +0 -22
- package/dist/react/thread.cjs.map +0 -1
- package/dist/react/thread.js +0 -21
- package/dist/react/thread.js.map +0 -1
- package/dist/react/types.d.cts +0 -363
- package/dist/react/types.d.cts.map +0 -1
- package/dist/react/types.d.ts +0 -363
- package/dist/react/types.d.ts.map +0 -1
- package/dist/react-ui/client.cjs +0 -137
- package/dist/react-ui/client.cjs.map +0 -1
- package/dist/react-ui/client.d.cts +0 -90
- package/dist/react-ui/client.d.cts.map +0 -1
- package/dist/react-ui/client.d.ts +0 -90
- package/dist/react-ui/client.d.ts.map +0 -1
- package/dist/react-ui/client.js +0 -134
- package/dist/react-ui/client.js.map +0 -1
- package/dist/react-ui/index.cjs +0 -14
- package/dist/react-ui/index.cjs.map +0 -1
- package/dist/react-ui/index.d.cts +0 -3
- package/dist/react-ui/index.d.ts +0 -3
- package/dist/react-ui/index.js +0 -9
- package/dist/react-ui/index.js.map +0 -1
- package/dist/react-ui/server/index.cjs +0 -5
- package/dist/react-ui/server/index.d.cts +0 -3
- package/dist/react-ui/server/index.d.ts +0 -3
- package/dist/react-ui/server/index.js +0 -4
- package/dist/react-ui/server/server.cjs +0 -57
- package/dist/react-ui/server/server.cjs.map +0 -1
- package/dist/react-ui/server/server.d.cts +0 -55
- package/dist/react-ui/server/server.d.cts.map +0 -1
- package/dist/react-ui/server/server.d.ts +0 -55
- package/dist/react-ui/server/server.d.ts.map +0 -1
- package/dist/react-ui/server/server.js +0 -56
- package/dist/react-ui/server/server.js.map +0 -1
- package/dist/react-ui/types.cjs +0 -38
- package/dist/react-ui/types.cjs.map +0 -1
- package/dist/react-ui/types.d.cts +0 -25
- package/dist/react-ui/types.d.cts.map +0 -1
- package/dist/react-ui/types.d.ts +0 -25
- package/dist/react-ui/types.d.ts.map +0 -1
- package/dist/react-ui/types.js +0 -35
- package/dist/react-ui/types.js.map +0 -1
- package/dist/schema.d.cts +0 -284
- package/dist/schema.d.cts.map +0 -1
- package/dist/schema.d.ts +0 -284
- package/dist/schema.d.ts.map +0 -1
- package/dist/singletons/fetch.cjs +0 -24
- package/dist/singletons/fetch.cjs.map +0 -1
- package/dist/singletons/fetch.d.cts +0 -14
- package/dist/singletons/fetch.d.cts.map +0 -1
- package/dist/singletons/fetch.d.ts +0 -14
- package/dist/singletons/fetch.d.ts.map +0 -1
- package/dist/singletons/fetch.js +0 -22
- package/dist/singletons/fetch.js.map +0 -1
- package/dist/types.d.cts +0 -187
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.ts +0 -187
- package/dist/types.d.ts.map +0 -1
- package/dist/types.messages.d.cts +0 -91
- package/dist/types.messages.d.cts.map +0 -1
- package/dist/types.messages.d.ts +0 -91
- package/dist/types.messages.d.ts.map +0 -1
- package/dist/types.stream.d.cts +0 -235
- package/dist/types.stream.d.cts.map +0 -1
- package/dist/types.stream.d.ts +0 -235
- package/dist/types.stream.d.ts.map +0 -1
- package/dist/ui/branching.cjs +0 -153
- package/dist/ui/branching.cjs.map +0 -1
- package/dist/ui/branching.d.cts +0 -22
- package/dist/ui/branching.d.cts.map +0 -1
- package/dist/ui/branching.d.ts +0 -22
- package/dist/ui/branching.d.ts.map +0 -1
- package/dist/ui/branching.js +0 -152
- package/dist/ui/branching.js.map +0 -1
- package/dist/ui/errors.cjs +0 -15
- package/dist/ui/errors.cjs.map +0 -1
- package/dist/ui/errors.js +0 -14
- package/dist/ui/errors.js.map +0 -1
- package/dist/ui/manager.cjs +0 -182
- package/dist/ui/manager.cjs.map +0 -1
- package/dist/ui/manager.js +0 -182
- package/dist/ui/manager.js.map +0 -1
- package/dist/ui/messages.cjs +0 -70
- package/dist/ui/messages.cjs.map +0 -1
- package/dist/ui/messages.js +0 -68
- package/dist/ui/messages.js.map +0 -1
- package/dist/ui/utils.cjs +0 -14
- package/dist/ui/utils.cjs.map +0 -1
- package/dist/ui/utils.js +0 -12
- package/dist/ui/utils.js.map +0 -1
- package/dist/utils/async_caller.cjs +0 -111
- package/dist/utils/async_caller.cjs.map +0 -1
- package/dist/utils/async_caller.d.cts +0 -53
- package/dist/utils/async_caller.d.cts.map +0 -1
- package/dist/utils/async_caller.d.ts +0 -53
- package/dist/utils/async_caller.d.ts.map +0 -1
- package/dist/utils/async_caller.js +0 -110
- package/dist/utils/async_caller.js.map +0 -1
- package/dist/utils/env.cjs +0 -13
- package/dist/utils/env.cjs.map +0 -1
- package/dist/utils/env.js +0 -12
- package/dist/utils/env.js.map +0 -1
- package/dist/utils/error.cjs +0 -17
- package/dist/utils/error.cjs.map +0 -1
- package/dist/utils/error.js +0 -16
- package/dist/utils/error.js.map +0 -1
- package/dist/utils/signals.cjs +0 -20
- package/dist/utils/signals.cjs.map +0 -1
- package/dist/utils/signals.js +0 -19
- package/dist/utils/signals.js.map +0 -1
- package/dist/utils/sse.cjs +0 -124
- package/dist/utils/sse.cjs.map +0 -1
- package/dist/utils/sse.js +0 -122
- package/dist/utils/sse.js.map +0 -1
- package/dist/utils/stream.cjs +0 -176
- package/dist/utils/stream.cjs.map +0 -1
- package/dist/utils/stream.js +0 -175
- package/dist/utils/stream.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.custom.cjs","names":["options: FetchStreamTransportOptions","requestInit: RequestInit","BytesLineDecoder","SSEDecoder","IterableReadableStream","MessageTupleManager","StreamManager","useControllableThreadId","callbackMeta: RunCallbackMeta | undefined"],"sources":["../../src/react/stream.custom.tsx"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\nimport { useEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport { EventStreamEvent, StreamManager } from \"../ui/manager.js\";\nimport type {\n BagTemplate,\n GetUpdateType,\n GetCustomEventType,\n GetInterruptType,\n RunCallbackMeta,\n GetConfigurableType,\n UseStreamCustomOptions,\n UseStreamCustom,\n UseStreamTransport,\n CustomSubmitOptions,\n} from \"./types.js\";\nimport type { Message } from \"../types.messages.js\";\nimport { MessageTupleManager } from \"../ui/messages.js\";\nimport { Interrupt } from \"../schema.js\";\nimport { BytesLineDecoder, SSEDecoder } from \"../utils/sse.js\";\nimport { IterableReadableStream } from \"../utils/stream.js\";\nimport { useControllableThreadId } from \"./thread.js\";\nimport { Command } from \"../types.js\";\n\ninterface FetchStreamTransportOptions {\n /**\n * The URL of the API to use.\n */\n apiUrl: string;\n\n /**\n * Default headers to send with requests.\n */\n defaultHeaders?: HeadersInit;\n\n /**\n * Specify a custom fetch implementation.\n */\n fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any\n\n /**\n * Callback that is called before the request is made.\n */\n onRequest?: (\n url: string,\n init: RequestInit\n ) => Promise<RequestInit> | RequestInit;\n}\n\nexport class FetchStreamTransport<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate\n> implements UseStreamTransport<StateType, Bag>\n{\n constructor(private readonly options: FetchStreamTransportOptions) {}\n\n async stream(payload: {\n input: GetUpdateType<Bag, StateType> | null | undefined;\n context: GetConfigurableType<Bag> | undefined;\n command: Command | undefined;\n signal: AbortSignal;\n }): Promise<AsyncGenerator<{ id?: string; event: string; data: unknown }>> {\n const { signal, ...body } = payload;\n\n let requestInit: RequestInit = {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...this.options.defaultHeaders,\n },\n body: JSON.stringify(body),\n signal,\n };\n\n if (this.options.onRequest) {\n requestInit = await this.options.onRequest(\n this.options.apiUrl,\n requestInit\n );\n }\n const fetchFn = this.options.fetch ?? fetch;\n\n const response = await fetchFn(this.options.apiUrl, requestInit);\n if (!response.ok) {\n throw new Error(`Failed to stream: ${response.statusText}`);\n }\n\n const stream = (\n response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })\n )\n .pipeThrough(BytesLineDecoder())\n .pipeThrough(SSEDecoder());\n\n return IterableReadableStream.fromReadableStream(stream);\n }\n}\n\nexport function useStreamCustom<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n } = BagTemplate\n>(\n options: UseStreamCustomOptions<StateType, Bag>\n): UseStreamCustom<StateType, Bag> {\n type UpdateType = GetUpdateType<Bag, StateType>;\n type CustomType = GetCustomEventType<Bag>;\n type InterruptType = GetInterruptType<Bag>;\n type ConfigurableType = GetConfigurableType<Bag>;\n\n const [messageManager] = useState(() => new MessageTupleManager());\n const [stream] = useState(\n () =>\n new StreamManager<StateType, Bag>(messageManager, {\n throttle: options.throttle ?? false,\n })\n );\n\n useSyncExternalStore(\n stream.subscribe,\n stream.getSnapshot,\n stream.getSnapshot\n );\n\n const [threadId, onThreadId] = useControllableThreadId(options);\n const threadIdRef = useRef<string | null>(threadId);\n\n // Cancel the stream if thread ID has changed\n useEffect(() => {\n if (threadIdRef.current !== threadId) {\n threadIdRef.current = threadId;\n stream.clear();\n }\n }, [threadId, stream]);\n\n const getMessages = (value: StateType): Message[] => {\n const messagesKey = options.messagesKey ?? \"messages\";\n return Array.isArray(value[messagesKey]) ? value[messagesKey] : [];\n };\n\n const setMessages = (current: StateType, messages: Message[]): StateType => {\n const messagesKey = options.messagesKey ?? \"messages\";\n return { ...current, [messagesKey]: messages };\n };\n\n const historyValues = options.initialValues ?? ({} as StateType);\n\n const stop = () => stream.stop(historyValues, { onStop: options.onStop });\n\n const submit = async (\n values: UpdateType | null | undefined,\n submitOptions?: CustomSubmitOptions<StateType, ConfigurableType>\n ) => {\n let callbackMeta: RunCallbackMeta | undefined;\n let usableThreadId = threadId;\n\n stream.setStreamValues(() => {\n if (submitOptions?.optimisticValues != null) {\n return {\n ...historyValues,\n ...(typeof submitOptions.optimisticValues === \"function\"\n ? submitOptions.optimisticValues(historyValues)\n : submitOptions.optimisticValues),\n };\n }\n\n return { ...historyValues };\n });\n\n await stream.start(\n async (signal: AbortSignal) => {\n if (!usableThreadId) {\n // generate random thread id\n usableThreadId = crypto.randomUUID();\n threadIdRef.current = usableThreadId;\n onThreadId(usableThreadId);\n }\n\n if (!usableThreadId) {\n throw new Error(\"Failed to obtain valid thread ID.\");\n }\n\n return options.transport.stream({\n input: values,\n context: submitOptions?.context,\n command: submitOptions?.command,\n signal,\n config: {\n ...submitOptions?.config,\n configurable: {\n thread_id: usableThreadId,\n ...submitOptions?.config?.configurable,\n } as unknown as GetConfigurableType<Bag>,\n },\n }) as Promise<\n AsyncGenerator<EventStreamEvent<StateType, UpdateType, CustomType>>\n >;\n },\n {\n getMessages,\n setMessages,\n\n initialValues: {} as StateType,\n callbacks: options,\n\n onSuccess: () => undefined,\n onError(error) {\n options.onError?.(error, callbackMeta);\n },\n }\n );\n };\n\n return {\n get values() {\n return stream.values ?? ({} as StateType);\n },\n\n error: stream.error,\n isLoading: stream.isLoading,\n\n stop,\n submit,\n\n get interrupt(): Interrupt<InterruptType> | undefined {\n if (\n stream.values != null &&\n \"__interrupt__\" in stream.values &&\n Array.isArray(stream.values.__interrupt__)\n ) {\n const valueInterrupts = stream.values.__interrupt__;\n if (valueInterrupts.length === 0) return { when: \"breakpoint\" };\n if (valueInterrupts.length === 1) return valueInterrupts[0];\n\n // TODO: fix the typing of interrupts if multiple interrupts are returned\n return valueInterrupts as Interrupt<InterruptType>;\n }\n\n return undefined;\n },\n\n get messages() {\n if (!stream.values) return [];\n return getMessages(stream.values);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;AAmDA,IAAa,uBAAb,MAIA;CACE,YAAY,AAAiBA,SAAsC;EAAtC;;CAE7B,MAAM,OAAO,SAK8D;EACzE,MAAM,EAAE,OAAQ,GAAG,SAAS;EAE5B,IAAIC,cAA2B;GAC7B,QAAQ;GACR,SAAS;IACP,gBAAgB;IAChB,GAAG,KAAK,QAAQ;;GAElB,MAAM,KAAK,UAAU;GACrB;;AAGF,MAAI,KAAK,QAAQ,UACf,eAAc,MAAM,KAAK,QAAQ,UAC/B,KAAK,QAAQ,QACb;EAGJ,MAAM,UAAU,KAAK,QAAQ,SAAS;EAEtC,MAAM,WAAW,MAAM,QAAQ,KAAK,QAAQ,QAAQ;AACpD,MAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MAAM,qBAAqB,SAAS;EAGhD,MAAM,UACJ,SAAS,QAAQ,IAAI,eAAe,EAAE,QAAQ,SAAS,KAAK,YAE3D,YAAYC,gCACZ,YAAYC;AAEf,SAAOC,sCAAuB,mBAAmB;;;AAIrD,SAAgB,gBASd,SACiC;CAMjC,MAAM,CAAC,4CAAiC,IAAIC;CAC5C,MAAM,CAAC,oCAEH,IAAIC,8BAA8B,gBAAgB,EAChD,UAAU,QAAQ,YAAY;AAIpC,iCACE,OAAO,WACP,OAAO,aACP,OAAO;CAGT,MAAM,CAAC,UAAU,cAAcC,uCAAwB;CACvD,MAAM,gCAAoC;AAG1C,4BAAgB;AACd,MAAI,YAAY,YAAY,UAAU;AACpC,eAAY,UAAU;AACtB,UAAO;;IAER,CAAC,UAAU;CAEd,MAAM,eAAe,UAAgC;EACnD,MAAM,cAAc,QAAQ,eAAe;AAC3C,SAAO,MAAM,QAAQ,MAAM,gBAAgB,MAAM,eAAe;;CAGlE,MAAM,eAAe,SAAoB,aAAmC;EAC1E,MAAM,cAAc,QAAQ,eAAe;AAC3C,SAAO;GAAE,GAAG;IAAU,cAAc;;;CAGtC,MAAM,gBAAgB,QAAQ,iBAAkB;CAEhD,MAAM,aAAa,OAAO,KAAK,eAAe,EAAE,QAAQ,QAAQ;CAEhE,MAAM,SAAS,OACb,QACA,kBACG;EACH,IAAIC;EACJ,IAAI,iBAAiB;AAErB,SAAO,sBAAsB;AAC3B,OAAI,eAAe,oBAAoB,KACrC,QAAO;IACL,GAAG;IACH,GAAI,OAAO,cAAc,qBAAqB,aAC1C,cAAc,iBAAiB,iBAC/B,cAAc;;AAItB,UAAO,EAAE,GAAG;;AAGd,QAAM,OAAO,MACX,OAAO,WAAwB;AAC7B,OAAI,CAAC,gBAAgB;AAEnB,qBAAiB,OAAO;AACxB,gBAAY,UAAU;AACtB,eAAW;;AAGb,OAAI,CAAC,eACH,OAAM,IAAI,MAAM;AAGlB,UAAO,QAAQ,UAAU,OAAO;IAC9B,OAAO;IACP,SAAS,eAAe;IACxB,SAAS,eAAe;IACxB;IACA,QAAQ;KACN,GAAG,eAAe;KAClB,cAAc;MACZ,WAAW;MACX,GAAG,eAAe,QAAQ;;;;KAOlC;GACE;GACA;GAEA,eAAe;GACf,WAAW;GAEX,iBAAiB;GACjB,QAAQ,OAAO;AACb,YAAQ,UAAU,OAAO;;;;AAMjC,QAAO;EACL,IAAI,SAAS;AACX,UAAO,OAAO,UAAW;;EAG3B,OAAO,OAAO;EACd,WAAW,OAAO;EAElB;EACA;EAEA,IAAI,YAAkD;AACpD,OACE,OAAO,UAAU,QACjB,mBAAmB,OAAO,UAC1B,MAAM,QAAQ,OAAO,OAAO,gBAC5B;IACA,MAAM,kBAAkB,OAAO,OAAO;AACtC,QAAI,gBAAgB,WAAW,EAAG,QAAO,EAAE,MAAM;AACjD,QAAI,gBAAgB,WAAW,EAAG,QAAO,gBAAgB;AAGzD,WAAO;;AAGT,UAAO;;EAGT,IAAI,WAAW;AACb,OAAI,CAAC,OAAO,OAAQ,QAAO;AAC3B,UAAO,YAAY,OAAO"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Command } from "../types.cjs";
|
|
2
|
-
import { BagTemplate, GetConfigurableType, GetUpdateType, UseStreamTransport } from "./types.cjs";
|
|
3
|
-
|
|
4
|
-
//#region src/react/stream.custom.d.ts
|
|
5
|
-
interface FetchStreamTransportOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The URL of the API to use.
|
|
8
|
-
*/
|
|
9
|
-
apiUrl: string;
|
|
10
|
-
/**
|
|
11
|
-
* Default headers to send with requests.
|
|
12
|
-
*/
|
|
13
|
-
defaultHeaders?: HeadersInit;
|
|
14
|
-
/**
|
|
15
|
-
* Specify a custom fetch implementation.
|
|
16
|
-
*/
|
|
17
|
-
fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
18
|
-
/**
|
|
19
|
-
* Callback that is called before the request is made.
|
|
20
|
-
*/
|
|
21
|
-
onRequest?: (url: string, init: RequestInit) => Promise<RequestInit> | RequestInit;
|
|
22
|
-
}
|
|
23
|
-
declare class FetchStreamTransport<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> implements UseStreamTransport<StateType, Bag> {
|
|
24
|
-
private readonly options;
|
|
25
|
-
constructor(options: FetchStreamTransportOptions);
|
|
26
|
-
stream(payload: {
|
|
27
|
-
input: GetUpdateType<Bag, StateType> | null | undefined;
|
|
28
|
-
context: GetConfigurableType<Bag> | undefined;
|
|
29
|
-
command: Command | undefined;
|
|
30
|
-
signal: AbortSignal;
|
|
31
|
-
}): Promise<AsyncGenerator<{
|
|
32
|
-
id?: string;
|
|
33
|
-
event: string;
|
|
34
|
-
data: unknown;
|
|
35
|
-
}>>;
|
|
36
|
-
}
|
|
37
|
-
//#endregion
|
|
38
|
-
export { FetchStreamTransport };
|
|
39
|
-
//# sourceMappingURL=stream.custom.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.custom.d.cts","names":["BagTemplate","GetUpdateType","GetConfigurableType","UseStreamCustomOptions","UseStreamCustom","UseStreamTransport","Command","FetchStreamTransportOptions","HeadersInit","fetch","RequestInit","Promise","FetchStreamTransport","Record","StateType","Bag","AbortSignal","AsyncGenerator","useStreamCustom"],"sources":["../../src/react/stream.custom.d.ts"],"sourcesContent":["import type { BagTemplate, GetUpdateType, GetConfigurableType, UseStreamCustomOptions, UseStreamCustom, UseStreamTransport } from \"./types.js\";\nimport { Command } from \"../types.js\";\ninterface FetchStreamTransportOptions {\n /**\n * The URL of the API to use.\n */\n apiUrl: string;\n /**\n * Default headers to send with requests.\n */\n defaultHeaders?: HeadersInit;\n /**\n * Specify a custom fetch implementation.\n */\n fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any\n /**\n * Callback that is called before the request is made.\n */\n onRequest?: (url: string, init: RequestInit) => Promise<RequestInit> | RequestInit;\n}\nexport declare class FetchStreamTransport<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> implements UseStreamTransport<StateType, Bag> {\n private readonly options;\n constructor(options: FetchStreamTransportOptions);\n stream(payload: {\n input: GetUpdateType<Bag, StateType> | null | undefined;\n context: GetConfigurableType<Bag> | undefined;\n command: Command | undefined;\n signal: AbortSignal;\n }): Promise<AsyncGenerator<{\n id?: string;\n event: string;\n data: unknown;\n }>>;\n}\nexport declare function useStreamCustom<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n} = BagTemplate>(options: UseStreamCustomOptions<StateType, Bag>): UseStreamCustom<StateType, Bag>;\nexport {};\n"],"mappings":";;;;UAEUO,2BAAAA;;AAD4B;;QASjBC,EAAAA,MAAAA;;;;gBAQ+BG,CAAAA,EAR/BH,WAQ+BG;;;AAEpD;EAAyC,KAAA,CAAA,EAAA,OANtBF,KAMsB,GAAA,CAAA,CAAA,GAAA,IAAA,EAAA,GAAA,EAAA,EAAA,GAAA,GAAA,CAAA,CAAA,CAAA;;;;WAAgGT,CAAAA,EAAAA,CAAAA,GAAAA,EAAAA,MAAAA,EAAAA,IAAAA,EAFrGU,WAEqGV,EAAAA,GAFrFW,OAEqFX,CAF7EU,WAE6EV,CAAAA,GAF9DU,WAE8DV;;AAAsDe,cAA1KH,oBAA0KG,CAAAA,kBAAnIF,MAAmIE,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,GAAzGF,MAAyGE,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,EAAAA,YAApEf,WAAoEe,GAAtDf,WAAsDe,CAAAA,YAA9BV,kBAA8BU,CAAXD,SAAWC,EAAAA,GAAAA,CAAAA,CAAAA;mBAEtKR,OAAAA;aAEIQ,CAAAA,OAAAA,EAFJR,2BAEIQ;QAAKD,CAAAA,OAAAA,EAAAA;IAAnBb,KAAAA,EAAAA,aAAAA,CAAcc,GAAdd,EAAmBa,SAAnBb,CAAAA,GAAAA,IAAAA,GAAAA,SAAAA;IACsBc,OAAAA,EAApBb,mBAAoBa,CAAAA,GAAAA,CAAAA,GAAAA,SAAAA;IAApBb,OAAAA,EACAI,OADAJ,GAAAA,SAAAA;IACAI,MAAAA,EACDU,WADCV;MAETK,OADQK,CACAC,cADAD,CAAAA;IACAC,EAAAA,CAAAA,EAAAA,MAAAA;IAARN,KAAAA,EAAAA,MAAAA;IARyJN,IAAAA,EAAAA,OAAAA"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Command } from "../types.js";
|
|
2
|
-
import { BagTemplate, GetConfigurableType, GetUpdateType, UseStreamTransport } from "./types.js";
|
|
3
|
-
|
|
4
|
-
//#region src/react/stream.custom.d.ts
|
|
5
|
-
interface FetchStreamTransportOptions {
|
|
6
|
-
/**
|
|
7
|
-
* The URL of the API to use.
|
|
8
|
-
*/
|
|
9
|
-
apiUrl: string;
|
|
10
|
-
/**
|
|
11
|
-
* Default headers to send with requests.
|
|
12
|
-
*/
|
|
13
|
-
defaultHeaders?: HeadersInit;
|
|
14
|
-
/**
|
|
15
|
-
* Specify a custom fetch implementation.
|
|
16
|
-
*/
|
|
17
|
-
fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
18
|
-
/**
|
|
19
|
-
* Callback that is called before the request is made.
|
|
20
|
-
*/
|
|
21
|
-
onRequest?: (url: string, init: RequestInit) => Promise<RequestInit> | RequestInit;
|
|
22
|
-
}
|
|
23
|
-
declare class FetchStreamTransport<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> implements UseStreamTransport<StateType, Bag> {
|
|
24
|
-
private readonly options;
|
|
25
|
-
constructor(options: FetchStreamTransportOptions);
|
|
26
|
-
stream(payload: {
|
|
27
|
-
input: GetUpdateType<Bag, StateType> | null | undefined;
|
|
28
|
-
context: GetConfigurableType<Bag> | undefined;
|
|
29
|
-
command: Command | undefined;
|
|
30
|
-
signal: AbortSignal;
|
|
31
|
-
}): Promise<AsyncGenerator<{
|
|
32
|
-
id?: string;
|
|
33
|
-
event: string;
|
|
34
|
-
data: unknown;
|
|
35
|
-
}>>;
|
|
36
|
-
}
|
|
37
|
-
//#endregion
|
|
38
|
-
export { FetchStreamTransport };
|
|
39
|
-
//# sourceMappingURL=stream.custom.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.custom.d.ts","names":["BagTemplate","GetUpdateType","GetConfigurableType","UseStreamCustomOptions","UseStreamCustom","UseStreamTransport","Command","FetchStreamTransportOptions","HeadersInit","fetch","RequestInit","Promise","FetchStreamTransport","Record","StateType","Bag","AbortSignal","AsyncGenerator","useStreamCustom"],"sources":["../../src/react/stream.custom.d.ts"],"sourcesContent":["import type { BagTemplate, GetUpdateType, GetConfigurableType, UseStreamCustomOptions, UseStreamCustom, UseStreamTransport } from \"./types.js\";\nimport { Command } from \"../types.js\";\ninterface FetchStreamTransportOptions {\n /**\n * The URL of the API to use.\n */\n apiUrl: string;\n /**\n * Default headers to send with requests.\n */\n defaultHeaders?: HeadersInit;\n /**\n * Specify a custom fetch implementation.\n */\n fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any\n /**\n * Callback that is called before the request is made.\n */\n onRequest?: (url: string, init: RequestInit) => Promise<RequestInit> | RequestInit;\n}\nexport declare class FetchStreamTransport<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends BagTemplate = BagTemplate> implements UseStreamTransport<StateType, Bag> {\n private readonly options;\n constructor(options: FetchStreamTransportOptions);\n stream(payload: {\n input: GetUpdateType<Bag, StateType> | null | undefined;\n context: GetConfigurableType<Bag> | undefined;\n command: Command | undefined;\n signal: AbortSignal;\n }): Promise<AsyncGenerator<{\n id?: string;\n event: string;\n data: unknown;\n }>>;\n}\nexport declare function useStreamCustom<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n} = BagTemplate>(options: UseStreamCustomOptions<StateType, Bag>): UseStreamCustom<StateType, Bag>;\nexport {};\n"],"mappings":";;;;UAEUO,2BAAAA;;AAD4B;;QASjBC,EAAAA,MAAAA;;;;gBAQ+BG,CAAAA,EAR/BH,WAQ+BG;;;AAEpD;EAAyC,KAAA,CAAA,EAAA,OANtBF,KAMsB,GAAA,CAAA,CAAA,GAAA,IAAA,EAAA,GAAA,EAAA,EAAA,GAAA,GAAA,CAAA,CAAA,CAAA;;;;WAAgGT,CAAAA,EAAAA,CAAAA,GAAAA,EAAAA,MAAAA,EAAAA,IAAAA,EAFrGU,WAEqGV,EAAAA,GAFrFW,OAEqFX,CAF7EU,WAE6EV,CAAAA,GAF9DU,WAE8DV;;AAAsDe,cAA1KH,oBAA0KG,CAAAA,kBAAnIF,MAAmIE,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,GAAzGF,MAAyGE,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,EAAAA,YAApEf,WAAoEe,GAAtDf,WAAsDe,CAAAA,YAA9BV,kBAA8BU,CAAXD,SAAWC,EAAAA,GAAAA,CAAAA,CAAAA;mBAEtKR,OAAAA;aAEIQ,CAAAA,OAAAA,EAFJR,2BAEIQ;QAAKD,CAAAA,OAAAA,EAAAA;IAAnBb,KAAAA,EAAAA,aAAAA,CAAcc,GAAdd,EAAmBa,SAAnBb,CAAAA,GAAAA,IAAAA,GAAAA,SAAAA;IACsBc,OAAAA,EAApBb,mBAAoBa,CAAAA,GAAAA,CAAAA,GAAAA,SAAAA;IAApBb,OAAAA,EACAI,OADAJ,GAAAA,SAAAA;IACAI,MAAAA,EACDU,WADCV;MAETK,OADQK,CACAC,cADAD,CAAAA;IACAC,EAAAA,CAAAA,EAAAA,MAAAA;IAARN,KAAAA,EAAAA,MAAAA;IARyJN,IAAAA,EAAAA,OAAAA"}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { BytesLineDecoder, SSEDecoder } from "../utils/sse.js";
|
|
5
|
-
import { IterableReadableStream } from "../utils/stream.js";
|
|
6
|
-
import { MessageTupleManager } from "../ui/messages.js";
|
|
7
|
-
import { StreamManager } from "../ui/manager.js";
|
|
8
|
-
import { useControllableThreadId } from "./thread.js";
|
|
9
|
-
import { useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
10
|
-
|
|
11
|
-
//#region src/react/stream.custom.tsx
|
|
12
|
-
var FetchStreamTransport = class {
|
|
13
|
-
constructor(options) {
|
|
14
|
-
this.options = options;
|
|
15
|
-
}
|
|
16
|
-
async stream(payload) {
|
|
17
|
-
const { signal,...body } = payload;
|
|
18
|
-
let requestInit = {
|
|
19
|
-
method: "POST",
|
|
20
|
-
headers: {
|
|
21
|
-
"Content-Type": "application/json",
|
|
22
|
-
...this.options.defaultHeaders
|
|
23
|
-
},
|
|
24
|
-
body: JSON.stringify(body),
|
|
25
|
-
signal
|
|
26
|
-
};
|
|
27
|
-
if (this.options.onRequest) requestInit = await this.options.onRequest(this.options.apiUrl, requestInit);
|
|
28
|
-
const fetchFn = this.options.fetch ?? fetch;
|
|
29
|
-
const response = await fetchFn(this.options.apiUrl, requestInit);
|
|
30
|
-
if (!response.ok) throw new Error(`Failed to stream: ${response.statusText}`);
|
|
31
|
-
const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(BytesLineDecoder()).pipeThrough(SSEDecoder());
|
|
32
|
-
return IterableReadableStream.fromReadableStream(stream);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
function useStreamCustom(options) {
|
|
36
|
-
const [messageManager] = useState(() => new MessageTupleManager());
|
|
37
|
-
const [stream] = useState(() => new StreamManager(messageManager, { throttle: options.throttle ?? false }));
|
|
38
|
-
useSyncExternalStore(stream.subscribe, stream.getSnapshot, stream.getSnapshot);
|
|
39
|
-
const [threadId, onThreadId] = useControllableThreadId(options);
|
|
40
|
-
const threadIdRef = useRef(threadId);
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
if (threadIdRef.current !== threadId) {
|
|
43
|
-
threadIdRef.current = threadId;
|
|
44
|
-
stream.clear();
|
|
45
|
-
}
|
|
46
|
-
}, [threadId, stream]);
|
|
47
|
-
const getMessages = (value) => {
|
|
48
|
-
const messagesKey = options.messagesKey ?? "messages";
|
|
49
|
-
return Array.isArray(value[messagesKey]) ? value[messagesKey] : [];
|
|
50
|
-
};
|
|
51
|
-
const setMessages = (current, messages) => {
|
|
52
|
-
const messagesKey = options.messagesKey ?? "messages";
|
|
53
|
-
return {
|
|
54
|
-
...current,
|
|
55
|
-
[messagesKey]: messages
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
const historyValues = options.initialValues ?? {};
|
|
59
|
-
const stop = () => stream.stop(historyValues, { onStop: options.onStop });
|
|
60
|
-
const submit = async (values, submitOptions) => {
|
|
61
|
-
let callbackMeta;
|
|
62
|
-
let usableThreadId = threadId;
|
|
63
|
-
stream.setStreamValues(() => {
|
|
64
|
-
if (submitOptions?.optimisticValues != null) return {
|
|
65
|
-
...historyValues,
|
|
66
|
-
...typeof submitOptions.optimisticValues === "function" ? submitOptions.optimisticValues(historyValues) : submitOptions.optimisticValues
|
|
67
|
-
};
|
|
68
|
-
return { ...historyValues };
|
|
69
|
-
});
|
|
70
|
-
await stream.start(async (signal) => {
|
|
71
|
-
if (!usableThreadId) {
|
|
72
|
-
usableThreadId = crypto.randomUUID();
|
|
73
|
-
threadIdRef.current = usableThreadId;
|
|
74
|
-
onThreadId(usableThreadId);
|
|
75
|
-
}
|
|
76
|
-
if (!usableThreadId) throw new Error("Failed to obtain valid thread ID.");
|
|
77
|
-
return options.transport.stream({
|
|
78
|
-
input: values,
|
|
79
|
-
context: submitOptions?.context,
|
|
80
|
-
command: submitOptions?.command,
|
|
81
|
-
signal,
|
|
82
|
-
config: {
|
|
83
|
-
...submitOptions?.config,
|
|
84
|
-
configurable: {
|
|
85
|
-
thread_id: usableThreadId,
|
|
86
|
-
...submitOptions?.config?.configurable
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}, {
|
|
91
|
-
getMessages,
|
|
92
|
-
setMessages,
|
|
93
|
-
initialValues: {},
|
|
94
|
-
callbacks: options,
|
|
95
|
-
onSuccess: () => void 0,
|
|
96
|
-
onError(error) {
|
|
97
|
-
options.onError?.(error, callbackMeta);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
return {
|
|
102
|
-
get values() {
|
|
103
|
-
return stream.values ?? {};
|
|
104
|
-
},
|
|
105
|
-
error: stream.error,
|
|
106
|
-
isLoading: stream.isLoading,
|
|
107
|
-
stop,
|
|
108
|
-
submit,
|
|
109
|
-
get interrupt() {
|
|
110
|
-
if (stream.values != null && "__interrupt__" in stream.values && Array.isArray(stream.values.__interrupt__)) {
|
|
111
|
-
const valueInterrupts = stream.values.__interrupt__;
|
|
112
|
-
if (valueInterrupts.length === 0) return { when: "breakpoint" };
|
|
113
|
-
if (valueInterrupts.length === 1) return valueInterrupts[0];
|
|
114
|
-
return valueInterrupts;
|
|
115
|
-
}
|
|
116
|
-
return void 0;
|
|
117
|
-
},
|
|
118
|
-
get messages() {
|
|
119
|
-
if (!stream.values) return [];
|
|
120
|
-
return getMessages(stream.values);
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
//#endregion
|
|
126
|
-
export { FetchStreamTransport, useStreamCustom };
|
|
127
|
-
//# sourceMappingURL=stream.custom.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.custom.js","names":["options: FetchStreamTransportOptions","requestInit: RequestInit","callbackMeta: RunCallbackMeta | undefined"],"sources":["../../src/react/stream.custom.tsx"],"sourcesContent":["/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */\n\n\"use client\";\n\nimport { useEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport { EventStreamEvent, StreamManager } from \"../ui/manager.js\";\nimport type {\n BagTemplate,\n GetUpdateType,\n GetCustomEventType,\n GetInterruptType,\n RunCallbackMeta,\n GetConfigurableType,\n UseStreamCustomOptions,\n UseStreamCustom,\n UseStreamTransport,\n CustomSubmitOptions,\n} from \"./types.js\";\nimport type { Message } from \"../types.messages.js\";\nimport { MessageTupleManager } from \"../ui/messages.js\";\nimport { Interrupt } from \"../schema.js\";\nimport { BytesLineDecoder, SSEDecoder } from \"../utils/sse.js\";\nimport { IterableReadableStream } from \"../utils/stream.js\";\nimport { useControllableThreadId } from \"./thread.js\";\nimport { Command } from \"../types.js\";\n\ninterface FetchStreamTransportOptions {\n /**\n * The URL of the API to use.\n */\n apiUrl: string;\n\n /**\n * Default headers to send with requests.\n */\n defaultHeaders?: HeadersInit;\n\n /**\n * Specify a custom fetch implementation.\n */\n fetch?: typeof fetch | ((...args: any[]) => any); // eslint-disable-line @typescript-eslint/no-explicit-any\n\n /**\n * Callback that is called before the request is made.\n */\n onRequest?: (\n url: string,\n init: RequestInit\n ) => Promise<RequestInit> | RequestInit;\n}\n\nexport class FetchStreamTransport<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate\n> implements UseStreamTransport<StateType, Bag>\n{\n constructor(private readonly options: FetchStreamTransportOptions) {}\n\n async stream(payload: {\n input: GetUpdateType<Bag, StateType> | null | undefined;\n context: GetConfigurableType<Bag> | undefined;\n command: Command | undefined;\n signal: AbortSignal;\n }): Promise<AsyncGenerator<{ id?: string; event: string; data: unknown }>> {\n const { signal, ...body } = payload;\n\n let requestInit: RequestInit = {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n ...this.options.defaultHeaders,\n },\n body: JSON.stringify(body),\n signal,\n };\n\n if (this.options.onRequest) {\n requestInit = await this.options.onRequest(\n this.options.apiUrl,\n requestInit\n );\n }\n const fetchFn = this.options.fetch ?? fetch;\n\n const response = await fetchFn(this.options.apiUrl, requestInit);\n if (!response.ok) {\n throw new Error(`Failed to stream: ${response.statusText}`);\n }\n\n const stream = (\n response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })\n )\n .pipeThrough(BytesLineDecoder())\n .pipeThrough(SSEDecoder());\n\n return IterableReadableStream.fromReadableStream(stream);\n }\n}\n\nexport function useStreamCustom<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n } = BagTemplate\n>(\n options: UseStreamCustomOptions<StateType, Bag>\n): UseStreamCustom<StateType, Bag> {\n type UpdateType = GetUpdateType<Bag, StateType>;\n type CustomType = GetCustomEventType<Bag>;\n type InterruptType = GetInterruptType<Bag>;\n type ConfigurableType = GetConfigurableType<Bag>;\n\n const [messageManager] = useState(() => new MessageTupleManager());\n const [stream] = useState(\n () =>\n new StreamManager<StateType, Bag>(messageManager, {\n throttle: options.throttle ?? false,\n })\n );\n\n useSyncExternalStore(\n stream.subscribe,\n stream.getSnapshot,\n stream.getSnapshot\n );\n\n const [threadId, onThreadId] = useControllableThreadId(options);\n const threadIdRef = useRef<string | null>(threadId);\n\n // Cancel the stream if thread ID has changed\n useEffect(() => {\n if (threadIdRef.current !== threadId) {\n threadIdRef.current = threadId;\n stream.clear();\n }\n }, [threadId, stream]);\n\n const getMessages = (value: StateType): Message[] => {\n const messagesKey = options.messagesKey ?? \"messages\";\n return Array.isArray(value[messagesKey]) ? value[messagesKey] : [];\n };\n\n const setMessages = (current: StateType, messages: Message[]): StateType => {\n const messagesKey = options.messagesKey ?? \"messages\";\n return { ...current, [messagesKey]: messages };\n };\n\n const historyValues = options.initialValues ?? ({} as StateType);\n\n const stop = () => stream.stop(historyValues, { onStop: options.onStop });\n\n const submit = async (\n values: UpdateType | null | undefined,\n submitOptions?: CustomSubmitOptions<StateType, ConfigurableType>\n ) => {\n let callbackMeta: RunCallbackMeta | undefined;\n let usableThreadId = threadId;\n\n stream.setStreamValues(() => {\n if (submitOptions?.optimisticValues != null) {\n return {\n ...historyValues,\n ...(typeof submitOptions.optimisticValues === \"function\"\n ? submitOptions.optimisticValues(historyValues)\n : submitOptions.optimisticValues),\n };\n }\n\n return { ...historyValues };\n });\n\n await stream.start(\n async (signal: AbortSignal) => {\n if (!usableThreadId) {\n // generate random thread id\n usableThreadId = crypto.randomUUID();\n threadIdRef.current = usableThreadId;\n onThreadId(usableThreadId);\n }\n\n if (!usableThreadId) {\n throw new Error(\"Failed to obtain valid thread ID.\");\n }\n\n return options.transport.stream({\n input: values,\n context: submitOptions?.context,\n command: submitOptions?.command,\n signal,\n config: {\n ...submitOptions?.config,\n configurable: {\n thread_id: usableThreadId,\n ...submitOptions?.config?.configurable,\n } as unknown as GetConfigurableType<Bag>,\n },\n }) as Promise<\n AsyncGenerator<EventStreamEvent<StateType, UpdateType, CustomType>>\n >;\n },\n {\n getMessages,\n setMessages,\n\n initialValues: {} as StateType,\n callbacks: options,\n\n onSuccess: () => undefined,\n onError(error) {\n options.onError?.(error, callbackMeta);\n },\n }\n );\n };\n\n return {\n get values() {\n return stream.values ?? ({} as StateType);\n },\n\n error: stream.error,\n isLoading: stream.isLoading,\n\n stop,\n submit,\n\n get interrupt(): Interrupt<InterruptType> | undefined {\n if (\n stream.values != null &&\n \"__interrupt__\" in stream.values &&\n Array.isArray(stream.values.__interrupt__)\n ) {\n const valueInterrupts = stream.values.__interrupt__;\n if (valueInterrupts.length === 0) return { when: \"breakpoint\" };\n if (valueInterrupts.length === 1) return valueInterrupts[0];\n\n // TODO: fix the typing of interrupts if multiple interrupts are returned\n return valueInterrupts as Interrupt<InterruptType>;\n }\n\n return undefined;\n },\n\n get messages() {\n if (!stream.values) return [];\n return getMessages(stream.values);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;AAmDA,IAAa,uBAAb,MAIA;CACE,YAAY,AAAiBA,SAAsC;EAAtC;;CAE7B,MAAM,OAAO,SAK8D;EACzE,MAAM,EAAE,OAAQ,GAAG,SAAS;EAE5B,IAAIC,cAA2B;GAC7B,QAAQ;GACR,SAAS;IACP,gBAAgB;IAChB,GAAG,KAAK,QAAQ;;GAElB,MAAM,KAAK,UAAU;GACrB;;AAGF,MAAI,KAAK,QAAQ,UACf,eAAc,MAAM,KAAK,QAAQ,UAC/B,KAAK,QAAQ,QACb;EAGJ,MAAM,UAAU,KAAK,QAAQ,SAAS;EAEtC,MAAM,WAAW,MAAM,QAAQ,KAAK,QAAQ,QAAQ;AACpD,MAAI,CAAC,SAAS,GACZ,OAAM,IAAI,MAAM,qBAAqB,SAAS;EAGhD,MAAM,UACJ,SAAS,QAAQ,IAAI,eAAe,EAAE,QAAQ,SAAS,KAAK,YAE3D,YAAY,oBACZ,YAAY;AAEf,SAAO,uBAAuB,mBAAmB;;;AAIrD,SAAgB,gBASd,SACiC;CAMjC,MAAM,CAAC,kBAAkB,eAAe,IAAI;CAC5C,MAAM,CAAC,UAAU,eAEb,IAAI,cAA8B,gBAAgB,EAChD,UAAU,QAAQ,YAAY;AAIpC,sBACE,OAAO,WACP,OAAO,aACP,OAAO;CAGT,MAAM,CAAC,UAAU,cAAc,wBAAwB;CACvD,MAAM,cAAc,OAAsB;AAG1C,iBAAgB;AACd,MAAI,YAAY,YAAY,UAAU;AACpC,eAAY,UAAU;AACtB,UAAO;;IAER,CAAC,UAAU;CAEd,MAAM,eAAe,UAAgC;EACnD,MAAM,cAAc,QAAQ,eAAe;AAC3C,SAAO,MAAM,QAAQ,MAAM,gBAAgB,MAAM,eAAe;;CAGlE,MAAM,eAAe,SAAoB,aAAmC;EAC1E,MAAM,cAAc,QAAQ,eAAe;AAC3C,SAAO;GAAE,GAAG;IAAU,cAAc;;;CAGtC,MAAM,gBAAgB,QAAQ,iBAAkB;CAEhD,MAAM,aAAa,OAAO,KAAK,eAAe,EAAE,QAAQ,QAAQ;CAEhE,MAAM,SAAS,OACb,QACA,kBACG;EACH,IAAIC;EACJ,IAAI,iBAAiB;AAErB,SAAO,sBAAsB;AAC3B,OAAI,eAAe,oBAAoB,KACrC,QAAO;IACL,GAAG;IACH,GAAI,OAAO,cAAc,qBAAqB,aAC1C,cAAc,iBAAiB,iBAC/B,cAAc;;AAItB,UAAO,EAAE,GAAG;;AAGd,QAAM,OAAO,MACX,OAAO,WAAwB;AAC7B,OAAI,CAAC,gBAAgB;AAEnB,qBAAiB,OAAO;AACxB,gBAAY,UAAU;AACtB,eAAW;;AAGb,OAAI,CAAC,eACH,OAAM,IAAI,MAAM;AAGlB,UAAO,QAAQ,UAAU,OAAO;IAC9B,OAAO;IACP,SAAS,eAAe;IACxB,SAAS,eAAe;IACxB;IACA,QAAQ;KACN,GAAG,eAAe;KAClB,cAAc;MACZ,WAAW;MACX,GAAG,eAAe,QAAQ;;;;KAOlC;GACE;GACA;GAEA,eAAe;GACf,WAAW;GAEX,iBAAiB;GACjB,QAAQ,OAAO;AACb,YAAQ,UAAU,OAAO;;;;AAMjC,QAAO;EACL,IAAI,SAAS;AACX,UAAO,OAAO,UAAW;;EAG3B,OAAO,OAAO;EACd,WAAW,OAAO;EAElB;EACA;EAEA,IAAI,YAAkD;AACpD,OACE,OAAO,UAAU,QACjB,mBAAmB,OAAO,UAC1B,MAAM,QAAQ,OAAO,OAAO,gBAC5B;IACA,MAAM,kBAAkB,OAAO,OAAO;AACtC,QAAI,gBAAgB,WAAW,EAAG,QAAO,EAAE,MAAM;AACjD,QAAI,gBAAgB,WAAW,EAAG,QAAO,gBAAgB;AAGzD,WAAO;;AAGT,UAAO;;EAGT,IAAI,WAAW;AACb,OAAI,CAAC,OAAO,OAAQ,QAAO;AAC3B,UAAO,YAAY,OAAO"}
|
package/dist/react/stream.d.cts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { BagTemplate, UseStream, UseStreamCustom, UseStreamCustomOptions, UseStreamOptions } from "./types.cjs";
|
|
2
|
-
|
|
3
|
-
//#region src/react/stream.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A React hook that provides seamless integration with LangGraph streaming capabilities.
|
|
7
|
-
*
|
|
8
|
-
* The `useStream` hook handles all the complexities of streaming, state management, and branching logic,
|
|
9
|
-
* letting you focus on building great chat experiences. It provides automatic state management for
|
|
10
|
-
* messages, interrupts, loading states, and errors.
|
|
11
|
-
*
|
|
12
|
-
* @template StateType The type of the thread state (default: `Record<string, unknown>`)
|
|
13
|
-
* @template Bag Type configuration bag containing:
|
|
14
|
-
* - `ConfigurableType`: Type for the `config.configurable` property
|
|
15
|
-
* - `InterruptType`: Type for interrupt values
|
|
16
|
-
* - `CustomEventType`: Type for custom events
|
|
17
|
-
* - `UpdateType`: Type for the submit function updates
|
|
18
|
-
*
|
|
19
|
-
* @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
|
|
20
|
-
*/
|
|
21
|
-
declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
|
|
22
|
-
ConfigurableType?: Record<string, unknown>;
|
|
23
|
-
InterruptType?: unknown;
|
|
24
|
-
CustomEventType?: unknown;
|
|
25
|
-
UpdateType?: unknown;
|
|
26
|
-
} = BagTemplate>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;
|
|
27
|
-
/**
|
|
28
|
-
* A React hook that provides seamless integration with LangGraph streaming capabilities.
|
|
29
|
-
*
|
|
30
|
-
* The `useStream` hook handles all the complexities of streaming, state management, and branching logic,
|
|
31
|
-
* letting you focus on building great chat experiences. It provides automatic state management for
|
|
32
|
-
* messages, interrupts, loading states, and errors.
|
|
33
|
-
*
|
|
34
|
-
* @template StateType The type of the thread state (default: `Record<string, unknown>`)
|
|
35
|
-
* @template Bag Type configuration bag containing:
|
|
36
|
-
* - `ConfigurableType`: Type for the `config.configurable` property
|
|
37
|
-
* - `InterruptType`: Type for interrupt values
|
|
38
|
-
* - `CustomEventType`: Type for custom events
|
|
39
|
-
* - `UpdateType`: Type for the submit function updates
|
|
40
|
-
*
|
|
41
|
-
* @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
|
|
42
|
-
*/
|
|
43
|
-
declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
|
|
44
|
-
ConfigurableType?: Record<string, unknown>;
|
|
45
|
-
InterruptType?: unknown;
|
|
46
|
-
CustomEventType?: unknown;
|
|
47
|
-
UpdateType?: unknown;
|
|
48
|
-
} = BagTemplate>(options: UseStreamCustomOptions<StateType, Bag>): UseStreamCustom<StateType, Bag>;
|
|
49
|
-
/**
|
|
50
|
-
* A React hook that provides seamless integration with LangGraph streaming capabilities.
|
|
51
|
-
*
|
|
52
|
-
* The `useStream` hook handles all the complexities of streaming, state management, and branching logic,
|
|
53
|
-
* letting you focus on building great chat experiences. It provides automatic state management for
|
|
54
|
-
* messages, interrupts, loading states, and errors.
|
|
55
|
-
*
|
|
56
|
-
* @template StateType The type of the thread state (default: `Record<string, unknown>`)
|
|
57
|
-
* @template Bag Type configuration bag containing:
|
|
58
|
-
* - `ConfigurableType`: Type for the `config.configurable` property
|
|
59
|
-
* - `InterruptType`: Type for interrupt values
|
|
60
|
-
* - `CustomEventType`: Type for custom events
|
|
61
|
-
* - `UpdateType`: Type for the submit function updates
|
|
62
|
-
*
|
|
63
|
-
* @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
|
|
64
|
-
*/
|
|
65
|
-
declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
|
|
66
|
-
ConfigurableType?: Record<string, unknown>;
|
|
67
|
-
InterruptType?: unknown;
|
|
68
|
-
CustomEventType?: unknown;
|
|
69
|
-
UpdateType?: unknown;
|
|
70
|
-
} = BagTemplate>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;
|
|
71
|
-
//#endregion
|
|
72
|
-
export { useStream };
|
|
73
|
-
//# sourceMappingURL=stream.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.cts","names":["BagTemplate","UseStream","UseStreamCustom","UseStreamCustomOptions","UseStreamOptions","useStream","Record","StateType","Bag"],"sources":["../../src/react/stream.d.ts"],"sourcesContent":["import { BagTemplate, UseStream, UseStreamCustom, UseStreamCustomOptions, UseStreamOptions } from \"./types.js\";\n/**\n * A React hook that provides seamless integration with LangGraph streaming capabilities.\n *\n * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,\n * letting you focus on building great chat experiences. It provides automatic state management for\n * messages, interrupts, loading states, and errors.\n *\n * @template StateType The type of the thread state (default: `Record<string, unknown>`)\n * @template Bag Type configuration bag containing:\n * - `ConfigurableType`: Type for the `config.configurable` property\n * - `InterruptType`: Type for interrupt values\n * - `CustomEventType`: Type for custom events\n * - `UpdateType`: Type for the submit function updates\n *\n * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}\n */\nexport declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n} = BagTemplate>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;\n/**\n * A React hook that provides seamless integration with LangGraph streaming capabilities.\n *\n * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,\n * letting you focus on building great chat experiences. It provides automatic state management for\n * messages, interrupts, loading states, and errors.\n *\n * @template StateType The type of the thread state (default: `Record<string, unknown>`)\n * @template Bag Type configuration bag containing:\n * - `ConfigurableType`: Type for the `config.configurable` property\n * - `InterruptType`: Type for interrupt values\n * - `CustomEventType`: Type for custom events\n * - `UpdateType`: Type for the submit function updates\n *\n * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}\n */\nexport declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n} = BagTemplate>(options: UseStreamCustomOptions<StateType, Bag>): UseStreamCustom<StateType, Bag>;\n/**\n * A React hook that provides seamless integration with LangGraph streaming capabilities.\n *\n * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,\n * letting you focus on building great chat experiences. It provides automatic state management for\n * messages, interrupts, loading states, and errors.\n *\n * @template StateType The type of the thread state (default: `Record<string, unknown>`)\n * @template Bag Type configuration bag containing:\n * - `ConfigurableType`: Type for the `config.configurable` property\n * - `InterruptType`: Type for interrupt values\n * - `CustomEventType`: Type for custom events\n * - `UpdateType`: Type for the submit function updates\n *\n * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}\n */\nexport declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n} = BagTemplate>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;\n"],"mappings":";;;;;;AAiBA;;;;;;;;;;;;;AAsBA;AAAiC,iBAtBTK,SAsBS,CAAA,kBAtBmBC,MAsBnB,CAAA,MAAA,EAAA,OAAA,CAAA,GAtB6CA,MAsB7C,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,YAAA;kBAAmBA,CAAAA,EArB7BA,MAqB6BA,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;eAA0BA,CAAAA,EAAAA,OAAAA;iBACvDA,CAAAA,EAAAA,OAAAA;YAInBN,CAAAA,EAAAA,OAAAA;IAtBAA,WAsB6CO,CAAAA,CAAAA,OAAAA,EAtBvBH,gBAsBuBG,CAtBNA,SAsBMA,EAtBKC,GAsBLD,CAAAA,CAAAA,EAtBYN,SAsBZM,CAtBsBA,SAsBtBA,EAtBiCC,GAsBjCD,CAAAA;;;;;;;AAiBjD;;;;;;;;;;AAKkFC,iBA3B1DH,SA2B0DG,CAAAA,kBA3B9BF,MA2B8BE,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,GA3BJF,MA2BIE,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,EAAAA,YAAAA;kBAArBP,CAAAA,EA1BtCK,MA0BsCL,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;;;;IAtBzDD,sBAAsBG,uBAAuBI,WAAWC,OAAON,gBAAgBK,WAAWC;;;;;;;;;;;;;;;;;iBAiBtEH,4BAA4BC,0BAA0BA;qBACvDA;;;;IAInBN,sBAAsBI,iBAAiBG,WAAWC,OAAOP,UAAUM,WAAWC"}
|
package/dist/react/stream.d.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { BagTemplate, UseStream, UseStreamCustom, UseStreamCustomOptions, UseStreamOptions } from "./types.js";
|
|
2
|
-
|
|
3
|
-
//#region src/react/stream.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A React hook that provides seamless integration with LangGraph streaming capabilities.
|
|
7
|
-
*
|
|
8
|
-
* The `useStream` hook handles all the complexities of streaming, state management, and branching logic,
|
|
9
|
-
* letting you focus on building great chat experiences. It provides automatic state management for
|
|
10
|
-
* messages, interrupts, loading states, and errors.
|
|
11
|
-
*
|
|
12
|
-
* @template StateType The type of the thread state (default: `Record<string, unknown>`)
|
|
13
|
-
* @template Bag Type configuration bag containing:
|
|
14
|
-
* - `ConfigurableType`: Type for the `config.configurable` property
|
|
15
|
-
* - `InterruptType`: Type for interrupt values
|
|
16
|
-
* - `CustomEventType`: Type for custom events
|
|
17
|
-
* - `UpdateType`: Type for the submit function updates
|
|
18
|
-
*
|
|
19
|
-
* @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
|
|
20
|
-
*/
|
|
21
|
-
declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
|
|
22
|
-
ConfigurableType?: Record<string, unknown>;
|
|
23
|
-
InterruptType?: unknown;
|
|
24
|
-
CustomEventType?: unknown;
|
|
25
|
-
UpdateType?: unknown;
|
|
26
|
-
} = BagTemplate>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;
|
|
27
|
-
/**
|
|
28
|
-
* A React hook that provides seamless integration with LangGraph streaming capabilities.
|
|
29
|
-
*
|
|
30
|
-
* The `useStream` hook handles all the complexities of streaming, state management, and branching logic,
|
|
31
|
-
* letting you focus on building great chat experiences. It provides automatic state management for
|
|
32
|
-
* messages, interrupts, loading states, and errors.
|
|
33
|
-
*
|
|
34
|
-
* @template StateType The type of the thread state (default: `Record<string, unknown>`)
|
|
35
|
-
* @template Bag Type configuration bag containing:
|
|
36
|
-
* - `ConfigurableType`: Type for the `config.configurable` property
|
|
37
|
-
* - `InterruptType`: Type for interrupt values
|
|
38
|
-
* - `CustomEventType`: Type for custom events
|
|
39
|
-
* - `UpdateType`: Type for the submit function updates
|
|
40
|
-
*
|
|
41
|
-
* @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
|
|
42
|
-
*/
|
|
43
|
-
declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
|
|
44
|
-
ConfigurableType?: Record<string, unknown>;
|
|
45
|
-
InterruptType?: unknown;
|
|
46
|
-
CustomEventType?: unknown;
|
|
47
|
-
UpdateType?: unknown;
|
|
48
|
-
} = BagTemplate>(options: UseStreamCustomOptions<StateType, Bag>): UseStreamCustom<StateType, Bag>;
|
|
49
|
-
/**
|
|
50
|
-
* A React hook that provides seamless integration with LangGraph streaming capabilities.
|
|
51
|
-
*
|
|
52
|
-
* The `useStream` hook handles all the complexities of streaming, state management, and branching logic,
|
|
53
|
-
* letting you focus on building great chat experiences. It provides automatic state management for
|
|
54
|
-
* messages, interrupts, loading states, and errors.
|
|
55
|
-
*
|
|
56
|
-
* @template StateType The type of the thread state (default: `Record<string, unknown>`)
|
|
57
|
-
* @template Bag Type configuration bag containing:
|
|
58
|
-
* - `ConfigurableType`: Type for the `config.configurable` property
|
|
59
|
-
* - `InterruptType`: Type for interrupt values
|
|
60
|
-
* - `CustomEventType`: Type for custom events
|
|
61
|
-
* - `UpdateType`: Type for the submit function updates
|
|
62
|
-
*
|
|
63
|
-
* @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}
|
|
64
|
-
*/
|
|
65
|
-
declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {
|
|
66
|
-
ConfigurableType?: Record<string, unknown>;
|
|
67
|
-
InterruptType?: unknown;
|
|
68
|
-
CustomEventType?: unknown;
|
|
69
|
-
UpdateType?: unknown;
|
|
70
|
-
} = BagTemplate>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;
|
|
71
|
-
//#endregion
|
|
72
|
-
export { useStream };
|
|
73
|
-
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","names":["BagTemplate","UseStream","UseStreamCustom","UseStreamCustomOptions","UseStreamOptions","useStream","Record","StateType","Bag"],"sources":["../../src/react/stream.d.ts"],"sourcesContent":["import { BagTemplate, UseStream, UseStreamCustom, UseStreamCustomOptions, UseStreamOptions } from \"./types.js\";\n/**\n * A React hook that provides seamless integration with LangGraph streaming capabilities.\n *\n * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,\n * letting you focus on building great chat experiences. It provides automatic state management for\n * messages, interrupts, loading states, and errors.\n *\n * @template StateType The type of the thread state (default: `Record<string, unknown>`)\n * @template Bag Type configuration bag containing:\n * - `ConfigurableType`: Type for the `config.configurable` property\n * - `InterruptType`: Type for interrupt values\n * - `CustomEventType`: Type for custom events\n * - `UpdateType`: Type for the submit function updates\n *\n * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}\n */\nexport declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n} = BagTemplate>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;\n/**\n * A React hook that provides seamless integration with LangGraph streaming capabilities.\n *\n * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,\n * letting you focus on building great chat experiences. It provides automatic state management for\n * messages, interrupts, loading states, and errors.\n *\n * @template StateType The type of the thread state (default: `Record<string, unknown>`)\n * @template Bag Type configuration bag containing:\n * - `ConfigurableType`: Type for the `config.configurable` property\n * - `InterruptType`: Type for interrupt values\n * - `CustomEventType`: Type for custom events\n * - `UpdateType`: Type for the submit function updates\n *\n * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}\n */\nexport declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n} = BagTemplate>(options: UseStreamCustomOptions<StateType, Bag>): UseStreamCustom<StateType, Bag>;\n/**\n * A React hook that provides seamless integration with LangGraph streaming capabilities.\n *\n * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,\n * letting you focus on building great chat experiences. It provides automatic state management for\n * messages, interrupts, loading states, and errors.\n *\n * @template StateType The type of the thread state (default: `Record<string, unknown>`)\n * @template Bag Type configuration bag containing:\n * - `ConfigurableType`: Type for the `config.configurable` property\n * - `InterruptType`: Type for interrupt values\n * - `CustomEventType`: Type for custom events\n * - `UpdateType`: Type for the submit function updates\n *\n * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}\n */\nexport declare function useStream<StateType extends Record<string, unknown> = Record<string, unknown>, Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n} = BagTemplate>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;\n"],"mappings":";;;;;;AAiBA;;;;;;;;;;;;;AAsBA;AAAiC,iBAtBTK,SAsBS,CAAA,kBAtBmBC,MAsBnB,CAAA,MAAA,EAAA,OAAA,CAAA,GAtB6CA,MAsB7C,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,YAAA;kBAAmBA,CAAAA,EArB7BA,MAqB6BA,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;eAA0BA,CAAAA,EAAAA,OAAAA;iBACvDA,CAAAA,EAAAA,OAAAA;YAInBN,CAAAA,EAAAA,OAAAA;IAtBAA,WAsB6CO,CAAAA,CAAAA,OAAAA,EAtBvBH,gBAsBuBG,CAtBNA,SAsBMA,EAtBKC,GAsBLD,CAAAA,CAAAA,EAtBYN,SAsBZM,CAtBsBA,SAsBtBA,EAtBiCC,GAsBjCD,CAAAA;;;;;;;AAiBjD;;;;;;;;;;AAKkFC,iBA3B1DH,SA2B0DG,CAAAA,kBA3B9BF,MA2B8BE,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,GA3BJF,MA2BIE,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA,EAAAA,YAAAA;kBAArBP,CAAAA,EA1BtCK,MA0BsCL,CAAAA,MAAAA,EAAAA,OAAAA,CAAAA;;;;IAtBzDD,sBAAsBG,uBAAuBI,WAAWC,OAAON,gBAAgBK,WAAWC;;;;;;;;;;;;;;;;;iBAiBtEH,4BAA4BC,0BAA0BA;qBACvDA;;;;IAInBN,sBAAsBI,iBAAiBG,WAAWC,OAAOP,UAAUM,WAAWC"}
|
package/dist/react/stream.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { useStreamLGP } from "./stream.lgp.js";
|
|
2
|
-
import { useStreamCustom } from "./stream.custom.js";
|
|
3
|
-
import { useState } from "react";
|
|
4
|
-
|
|
5
|
-
//#region src/react/stream.tsx
|
|
6
|
-
function isCustomOptions(options) {
|
|
7
|
-
return "transport" in options;
|
|
8
|
-
}
|
|
9
|
-
function useStream(options) {
|
|
10
|
-
const [isCustom] = useState(isCustomOptions(options));
|
|
11
|
-
if (isCustom) return useStreamCustom(options);
|
|
12
|
-
return useStreamLGP(options);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
export { useStream };
|
|
17
|
-
//# sourceMappingURL=stream.js.map
|
package/dist/react/stream.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","names":[],"sources":["../../src/react/stream.tsx"],"sourcesContent":["import { useState } from \"react\";\nimport { useStreamLGP } from \"./stream.lgp.js\";\nimport { useStreamCustom } from \"./stream.custom.js\";\nimport {\n BagTemplate,\n UseStream,\n UseStreamCustom,\n UseStreamCustomOptions,\n UseStreamOptions,\n} from \"./types.js\";\n\nfunction isCustomOptions<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n } = BagTemplate\n>(\n options:\n | UseStreamOptions<StateType, Bag>\n | UseStreamCustomOptions<StateType, Bag>\n): options is UseStreamCustomOptions<StateType, Bag> {\n return \"transport\" in options;\n}\n\n/**\n * A React hook that provides seamless integration with LangGraph streaming capabilities.\n *\n * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,\n * letting you focus on building great chat experiences. It provides automatic state management for\n * messages, interrupts, loading states, and errors.\n *\n * @template StateType The type of the thread state (default: `Record<string, unknown>`)\n * @template Bag Type configuration bag containing:\n * - `ConfigurableType`: Type for the `config.configurable` property\n * - `InterruptType`: Type for interrupt values\n * - `CustomEventType`: Type for custom events\n * - `UpdateType`: Type for the submit function updates\n *\n * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}\n */\nexport function useStream<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n } = BagTemplate\n>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;\n\n/**\n * A React hook that provides seamless integration with LangGraph streaming capabilities.\n *\n * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,\n * letting you focus on building great chat experiences. It provides automatic state management for\n * messages, interrupts, loading states, and errors.\n *\n * @template StateType The type of the thread state (default: `Record<string, unknown>`)\n * @template Bag Type configuration bag containing:\n * - `ConfigurableType`: Type for the `config.configurable` property\n * - `InterruptType`: Type for interrupt values\n * - `CustomEventType`: Type for custom events\n * - `UpdateType`: Type for the submit function updates\n *\n * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}\n */\nexport function useStream<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n } = BagTemplate\n>(\n options: UseStreamCustomOptions<StateType, Bag>\n): UseStreamCustom<StateType, Bag>;\n\n/**\n * A React hook that provides seamless integration with LangGraph streaming capabilities.\n *\n * The `useStream` hook handles all the complexities of streaming, state management, and branching logic,\n * letting you focus on building great chat experiences. It provides automatic state management for\n * messages, interrupts, loading states, and errors.\n *\n * @template StateType The type of the thread state (default: `Record<string, unknown>`)\n * @template Bag Type configuration bag containing:\n * - `ConfigurableType`: Type for the `config.configurable` property\n * - `InterruptType`: Type for interrupt values\n * - `CustomEventType`: Type for custom events\n * - `UpdateType`: Type for the submit function updates\n *\n * @see {@link https://docs.langchain.com/langgraph-platform/use-stream-react | LangGraph React Integration Guide}\n */\nexport function useStream<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n } = BagTemplate\n>(options: UseStreamOptions<StateType, Bag>): UseStream<StateType, Bag>;\n\nexport function useStream<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends {\n ConfigurableType?: Record<string, unknown>;\n InterruptType?: unknown;\n CustomEventType?: unknown;\n UpdateType?: unknown;\n } = BagTemplate\n>(\n options:\n | UseStreamOptions<StateType, Bag>\n | UseStreamCustomOptions<StateType, Bag>\n): UseStream<StateType, Bag> | UseStreamCustom<StateType, Bag> {\n // Store this in useState to make sure we're not changing the implementation in re-renders\n const [isCustom] = useState(isCustomOptions(options));\n\n if (isCustom) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStreamCustom(options as UseStreamCustomOptions<StateType, Bag>);\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStreamLGP(options as UseStreamOptions<StateType, Bag>);\n}\n"],"mappings":";;;;;AAWA,SAAS,gBASP,SAGmD;AACnD,QAAO,eAAe;;AAmFxB,SAAgB,UASd,SAG6D;CAE7D,MAAM,CAAC,YAAY,SAAS,gBAAgB;AAE5C,KAAI,SAEF,QAAO,gBAAgB;AAIzB,QAAO,aAAa"}
|