@langchain/langgraph-sdk 1.9.19 → 1.9.20
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/dist/client/index.cjs +1 -0
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +1 -0
- package/dist/client/index.d.cts.map +1 -1
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -0
- package/dist/client/index.js.map +1 -1
- package/dist/client/stream/resolve-client-api-url.cjs +20 -0
- package/dist/client/stream/resolve-client-api-url.cjs.map +1 -0
- package/dist/client/stream/resolve-client-api-url.d.cts +17 -0
- package/dist/client/stream/resolve-client-api-url.d.cts.map +1 -0
- package/dist/client/stream/resolve-client-api-url.d.ts +17 -0
- package/dist/client/stream/resolve-client-api-url.d.ts.map +1 -0
- package/dist/client/stream/resolve-client-api-url.js +20 -0
- package/dist/client/stream/resolve-client-api-url.js.map +1 -0
- package/dist/client/stream/transport/agent-server.cjs +11 -0
- package/dist/client/stream/transport/agent-server.cjs.map +1 -1
- package/dist/client/stream/transport/agent-server.d.cts +6 -0
- package/dist/client/stream/transport/agent-server.d.cts.map +1 -1
- package/dist/client/stream/transport/agent-server.d.ts +6 -0
- package/dist/client/stream/transport/agent-server.d.ts.map +1 -1
- package/dist/client/stream/transport/agent-server.js +11 -0
- package/dist/client/stream/transport/agent-server.js.map +1 -1
- package/dist/client/stream/transport/http.cjs +26 -1
- package/dist/client/stream/transport/http.cjs.map +1 -1
- package/dist/client/stream/transport/http.d.cts +21 -1
- package/dist/client/stream/transport/http.d.cts.map +1 -1
- package/dist/client/stream/transport/http.d.ts +21 -1
- package/dist/client/stream/transport/http.d.ts.map +1 -1
- package/dist/client/stream/transport/http.js +26 -1
- package/dist/client/stream/transport/http.js.map +1 -1
- package/dist/client/stream/transport/types.d.cts +2 -0
- package/dist/client/stream/transport/types.d.cts.map +1 -1
- package/dist/client/stream/transport/types.d.ts +2 -0
- package/dist/client/stream/transport/types.d.ts.map +1 -1
- package/dist/client/stream/transport.d.cts +10 -4
- package/dist/client/stream/transport.d.cts.map +1 -1
- package/dist/client/stream/transport.d.ts +10 -4
- package/dist/client/stream/transport.d.ts.map +1 -1
- package/dist/client.cjs +2 -0
- package/dist/client.d.cts +2 -1
- package/dist/client.d.ts +2 -1
- package/dist/client.js +2 -1
- package/dist/stream/controller.cjs +12 -1
- package/dist/stream/controller.cjs.map +1 -1
- package/dist/stream/controller.d.cts.map +1 -1
- package/dist/stream/controller.d.ts.map +1 -1
- package/dist/stream/controller.js +12 -1
- package/dist/stream/controller.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","names":[],"sources":["../../../../src/client/stream/transport/http.ts"],"sourcesContent":["import { AsyncQueue } from \"./queue.js\";\nimport type {\n Message,\n SubscribeParams,\n Command,\n CommandResponse,\n ErrorResponse,\n} from \"@langchain/protocol\";\n\nimport type {\n HeaderValue,\n ProtocolRequestHook,\n ProtocolSseTransportOptions,\n} from \"./types.js\";\nimport type { TransportAdapter, EventStreamHandle } from \"../transport.js\";\nimport {\n toAbsoluteUrl,\n isRecord,\n mergeHeaders,\n toError,\n isProtocolResponse,\n} from \"./utils.js\";\nimport { BytesLineDecoder, SSEDecoder } from \"../../../utils/sse.js\";\nimport { IterableReadableStream } from \"../../../utils/stream.js\";\n\n/**\n * Transport adapter that speaks the thread-centric protocol over HTTP\n * commands plus SSE event streams. Bound to a specific `threadId`\n * at construction. Each {@link openEventStream} call opens an independent\n * filtered SSE connection via `POST /threads/:thread_id/stream/events`.\n */\nexport class ProtocolSseTransportAdapter implements TransportAdapter {\n readonly threadId: string;\n\n private readonly queue = new AsyncQueue<Message>();\n\n private readonly fetchImpl: typeof fetch;\n\n private readonly apiUrl: string;\n\n private readonly defaultHeaders: Record<string, HeaderValue>;\n\n private readonly onRequest?: ProtocolRequestHook;\n\n private readonly fetchFactory?: () => typeof fetch | Promise<typeof fetch>;\n\n private readonly commandsUrl: string;\n\n private readonly streamUrl: string;\n\n private readonly sessionAbortController = new AbortController();\n\n private readonly eventStreams = new Set<AbortController>();\n\n private closed = false;\n\n constructor(options: ProtocolSseTransportOptions) {\n this.fetchImpl = options.fetch ?? fetch;\n this.apiUrl = options.apiUrl;\n this.defaultHeaders = options.defaultHeaders ?? {};\n this.onRequest = options.onRequest;\n this.fetchFactory = options.fetchFactory;\n this.threadId = options.threadId;\n this.commandsUrl =\n options.paths?.commands ?? `/threads/${this.threadId}/commands`;\n this.streamUrl =\n options.paths?.stream ?? `/threads/${this.threadId}/stream/events`;\n }\n\n private async resolveFetch(): Promise<typeof fetch> {\n if (this.fetchFactory) {\n return await this.fetchFactory();\n }\n return this.fetchImpl;\n }\n\n /**\n * HTTP/SSE transports have no handshake — connections are made\n * per-command and per-subscription.\n */\n async open(): Promise<void> {\n // no-op\n }\n\n async send(\n command: Command\n ): Promise<CommandResponse | ErrorResponse | void> {\n const response = await this.request(this.commandsUrl, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify(command),\n signal: this.sessionAbortController.signal,\n });\n\n if (response.status === 202 || response.status === 204) {\n return undefined;\n }\n\n const payload = (await response.json()) as unknown;\n if (!isProtocolResponse(payload)) {\n throw new Error(\"Protocol command did not return a valid response.\");\n }\n return payload;\n }\n\n /**\n * WebSocket-style single event stream.\n * For the SSE transport this returns a dummy iterable; real event\n * delivery happens via {@link openEventStream}.\n */\n events(): AsyncIterable<Message> {\n const queue = this.queue;\n return {\n [Symbol.asyncIterator]: () => ({\n next: async () => await queue.shift(),\n return: async () => {\n queue.close();\n return { done: true, value: undefined };\n },\n }),\n };\n }\n\n openEventStream(params: SubscribeParams): EventStreamHandle {\n if (this.closed) {\n throw new Error(\"Protocol transport is closed.\");\n }\n\n const ac = new AbortController();\n this.eventStreams.add(ac);\n const streamQueue = new AsyncQueue<Message>();\n const streamUrl = this.streamUrl;\n\n let resolveReady!: () => void;\n let rejectReady!: (err: unknown) => void;\n const ready = new Promise<void>((resolve, reject) => {\n resolveReady = resolve;\n rejectReady = reject;\n });\n\n const since = (params as SubscribeParams & { since?: unknown }).since;\n\n const startStream = async () => {\n try {\n const response = await this.request(streamUrl, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n accept: \"text/event-stream\",\n },\n body: JSON.stringify({\n channels: params.channels,\n ...(params.namespaces ? { namespaces: params.namespaces } : {}),\n ...(params.depth != null ? { depth: params.depth } : {}),\n ...(typeof since === \"number\" ? { since } : {}),\n }),\n signal: ac.signal,\n });\n\n resolveReady();\n\n const readable =\n response.body ??\n new ReadableStream<Uint8Array>({\n start(controller) {\n controller.close();\n },\n });\n\n const stream = readable\n .pipeThrough(BytesLineDecoder())\n .pipeThrough(SSEDecoder());\n const iterable = IterableReadableStream.fromReadableStream(stream);\n\n for await (const event of iterable) {\n if (ac.signal.aborted || this.closed) {\n break;\n }\n if (isRecord(event.data)) {\n const msg = event.data as Message & {\n seq?: number;\n method?: string;\n };\n streamQueue.push(msg);\n }\n }\n streamQueue.close();\n } catch (error) {\n rejectReady(error);\n if (ac.signal.aborted || this.closed) {\n streamQueue.close();\n return;\n }\n streamQueue.close(error);\n }\n };\n\n void startStream();\n\n const cleanup = () => {\n this.eventStreams.delete(ac);\n ac.abort();\n streamQueue.close();\n };\n\n return {\n events: {\n [Symbol.asyncIterator]: () => ({\n next: async () => await streamQueue.shift(),\n return: async () => {\n cleanup();\n return { done: true, value: undefined };\n },\n }),\n },\n ready,\n close: cleanup,\n };\n }\n\n async close(): Promise<void> {\n if (this.closed) {\n return;\n }\n this.closed = true;\n this.sessionAbortController.abort();\n for (const ac of this.eventStreams) ac.abort();\n this.eventStreams.clear();\n this.queue.close();\n }\n\n private async request(path: string, init: RequestInit): Promise<Response> {\n const url = toAbsoluteUrl(this.apiUrl, path);\n let requestInit: RequestInit = {\n ...init,\n headers: mergeHeaders(this.defaultHeaders, init.headers),\n };\n\n if (this.onRequest) {\n requestInit = await this.onRequest(url, requestInit);\n }\n\n try {\n const fetchImpl = await this.resolveFetch();\n const response = await fetchImpl(url.toString(), requestInit);\n if (!response.ok) {\n let detail = \"\";\n try {\n const body = await response.text();\n const parsed = JSON.parse(body);\n if (typeof parsed === \"object\" && parsed != null) {\n detail =\n ((parsed as Record<string, unknown>).message as string) ??\n ((parsed as Record<string, unknown>).error as string) ??\n \"\";\n }\n if (!detail) detail = body;\n } catch {\n // body unreadable or not JSON — fall through\n }\n const message = detail\n ? `Protocol request failed: ${response.status} ${response.statusText} — ${detail}`\n : `Protocol request failed: ${response.status} ${response.statusText}`;\n throw new Error(message);\n }\n return response;\n } catch (error) {\n throw toError(error);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AA+BA,IAAa,8BAAb,MAAqE;CACnE;CAEA,QAAyB,IAAI,YAAqB;CAElD;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA;CAEA,yBAA0C,IAAI,iBAAiB;CAE/D,+BAAgC,IAAI,KAAsB;CAE1D,SAAiB;CAEjB,YAAY,SAAsC;AAChD,OAAK,YAAY,QAAQ,SAAS;AAClC,OAAK,SAAS,QAAQ;AACtB,OAAK,iBAAiB,QAAQ,kBAAkB,EAAE;AAClD,OAAK,YAAY,QAAQ;AACzB,OAAK,eAAe,QAAQ;AAC5B,OAAK,WAAW,QAAQ;AACxB,OAAK,cACH,QAAQ,OAAO,YAAY,YAAY,KAAK,SAAS;AACvD,OAAK,YACH,QAAQ,OAAO,UAAU,YAAY,KAAK,SAAS;;CAGvD,MAAc,eAAsC;AAClD,MAAI,KAAK,aACP,QAAO,MAAM,KAAK,cAAc;AAElC,SAAO,KAAK;;;;;;CAOd,MAAM,OAAsB;CAI5B,MAAM,KACJ,SACiD;EACjD,MAAM,WAAW,MAAM,KAAK,QAAQ,KAAK,aAAa;GACpD,QAAQ;GACR,SAAS,EAAE,gBAAgB,oBAAoB;GAC/C,MAAM,KAAK,UAAU,QAAQ;GAC7B,QAAQ,KAAK,uBAAuB;GAC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;KACF,MAAM,OAAO,MAAM,SAAS,MAAM;KAClC,MAAM,SAAS,KAAK,MAAM,KAAK;AAC/B,SAAI,OAAO,WAAW,YAAY,UAAU,KAC1C,UACI,OAAmC,WACnC,OAAmC,SACrC;AAEJ,SAAI,CAAC,OAAQ,UAAS;YAChB;IAGR,MAAM,UAAU,SACZ,4BAA4B,SAAS,OAAO,GAAG,SAAS,WAAW,KAAK,WACxE,4BAA4B,SAAS,OAAO,GAAG,SAAS;AAC5D,UAAM,IAAI,MAAM,QAAQ;;AAE1B,UAAO;WACA,OAAO;AACd,SAAM,QAAQ,MAAM"}
|
|
1
|
+
{"version":3,"file":"http.js","names":[],"sources":["../../../../src/client/stream/transport/http.ts"],"sourcesContent":["import { AsyncQueue } from \"./queue.js\";\nimport type {\n Message,\n SubscribeParams,\n Command,\n CommandResponse,\n ErrorResponse,\n} from \"@langchain/protocol\";\n\nimport type {\n HeaderValue,\n ProtocolRequestHook,\n ProtocolSseTransportOptions,\n} from \"./types.js\";\nimport type { TransportAdapter, EventStreamHandle } from \"../transport.js\";\nimport {\n toAbsoluteUrl,\n isRecord,\n mergeHeaders,\n toError,\n isProtocolResponse,\n} from \"./utils.js\";\nimport { BytesLineDecoder, SSEDecoder } from \"../../../utils/sse.js\";\nimport { IterableReadableStream } from \"../../../utils/stream.js\";\n\n/**\n * Transport adapter that speaks the thread-centric protocol over HTTP\n * commands plus SSE event streams. Bound to a specific `threadId`\n * at construction. Each {@link openEventStream} call opens an independent\n * filtered SSE connection via `POST /threads/:thread_id/stream/events`.\n */\nexport class ProtocolSseTransportAdapter implements TransportAdapter {\n readonly threadId: string;\n\n readonly apiUrl: string;\n\n private readonly queue = new AsyncQueue<Message>();\n\n private readonly fetchImpl: typeof fetch;\n\n private readonly defaultHeaders: Record<string, HeaderValue>;\n\n private readonly onRequest?: ProtocolRequestHook;\n\n private readonly fetchFactory?: () => typeof fetch | Promise<typeof fetch>;\n\n private readonly commandsUrl: string;\n\n private readonly streamUrl: string;\n\n private readonly stateUrl: string;\n\n private readonly sessionAbortController = new AbortController();\n\n private readonly eventStreams = new Set<AbortController>();\n\n private closed = false;\n\n constructor(options: ProtocolSseTransportOptions) {\n this.fetchImpl = options.fetch ?? fetch;\n this.apiUrl = options.apiUrl;\n this.defaultHeaders = options.defaultHeaders ?? {};\n this.onRequest = options.onRequest;\n this.fetchFactory = options.fetchFactory;\n this.threadId = options.threadId;\n this.commandsUrl =\n options.paths?.commands ?? `/threads/${this.threadId}/commands`;\n this.streamUrl =\n options.paths?.stream ?? `/threads/${this.threadId}/stream/events`;\n this.stateUrl = options.paths?.state ?? `/threads/${this.threadId}/state`;\n }\n\n /**\n * Fetch checkpointed thread state for hydration.\n *\n * Uses `GET`, matching `client.threads.getState()` and both LangGraph\n * Platform and Agent Protocol custom backends (`POST` is reserved for\n * `updateState`).\n */\n async getState<StateType = unknown>(): Promise<{\n values: StateType;\n next?: unknown;\n tasks?: unknown;\n metadata?: unknown;\n checkpoint?: { checkpoint_id?: string } | null;\n parent_checkpoint?: { checkpoint_id?: string } | null;\n } | null> {\n const url = toAbsoluteUrl(this.apiUrl, this.stateUrl);\n let requestInit: RequestInit = {\n method: \"GET\",\n headers: mergeHeaders(this.defaultHeaders, {}),\n };\n\n if (this.onRequest) {\n requestInit = await this.onRequest(url, requestInit);\n }\n\n const fetchImpl = await this.resolveFetch();\n const response = await fetchImpl(url.toString(), requestInit);\n if (response.status === 404) return null;\n if (!response.ok) {\n const error = toError(\n new Error(\n `Thread state request failed: ${response.status} ${response.statusText}`\n )\n ) as Error & { status?: number };\n error.status = response.status;\n throw error;\n }\n\n return (await response.json()) as {\n values: StateType;\n next?: unknown;\n tasks?: unknown;\n metadata?: unknown;\n checkpoint?: { checkpoint_id?: string } | null;\n parent_checkpoint?: { checkpoint_id?: string } | null;\n };\n }\n\n private async resolveFetch(): Promise<typeof fetch> {\n if (this.fetchFactory) {\n return await this.fetchFactory();\n }\n return this.fetchImpl;\n }\n\n /**\n * HTTP/SSE transports have no handshake — connections are made\n * per-command and per-subscription.\n */\n async open(): Promise<void> {\n // no-op\n }\n\n async send(\n command: Command\n ): Promise<CommandResponse | ErrorResponse | void> {\n const response = await this.request(this.commandsUrl, {\n method: \"POST\",\n headers: { \"content-type\": \"application/json\" },\n body: JSON.stringify(command),\n signal: this.sessionAbortController.signal,\n });\n\n if (response.status === 202 || response.status === 204) {\n return undefined;\n }\n\n const payload = (await response.json()) as unknown;\n if (!isProtocolResponse(payload)) {\n throw new Error(\"Protocol command did not return a valid response.\");\n }\n return payload;\n }\n\n /**\n * WebSocket-style single event stream.\n * For the SSE transport this returns a dummy iterable; real event\n * delivery happens via {@link openEventStream}.\n */\n events(): AsyncIterable<Message> {\n const queue = this.queue;\n return {\n [Symbol.asyncIterator]: () => ({\n next: async () => await queue.shift(),\n return: async () => {\n queue.close();\n return { done: true, value: undefined };\n },\n }),\n };\n }\n\n openEventStream(params: SubscribeParams): EventStreamHandle {\n if (this.closed) {\n throw new Error(\"Protocol transport is closed.\");\n }\n\n const ac = new AbortController();\n this.eventStreams.add(ac);\n const streamQueue = new AsyncQueue<Message>();\n const streamUrl = this.streamUrl;\n\n let resolveReady!: () => void;\n let rejectReady!: (err: unknown) => void;\n const ready = new Promise<void>((resolve, reject) => {\n resolveReady = resolve;\n rejectReady = reject;\n });\n\n const since = (params as SubscribeParams & { since?: unknown }).since;\n\n const startStream = async () => {\n try {\n const response = await this.request(streamUrl, {\n method: \"POST\",\n headers: {\n \"content-type\": \"application/json\",\n accept: \"text/event-stream\",\n },\n body: JSON.stringify({\n channels: params.channels,\n ...(params.namespaces ? { namespaces: params.namespaces } : {}),\n ...(params.depth != null ? { depth: params.depth } : {}),\n ...(typeof since === \"number\" ? { since } : {}),\n }),\n signal: ac.signal,\n });\n\n resolveReady();\n\n const readable =\n response.body ??\n new ReadableStream<Uint8Array>({\n start(controller) {\n controller.close();\n },\n });\n\n const stream = readable\n .pipeThrough(BytesLineDecoder())\n .pipeThrough(SSEDecoder());\n const iterable = IterableReadableStream.fromReadableStream(stream);\n\n for await (const event of iterable) {\n if (ac.signal.aborted || this.closed) {\n break;\n }\n if (isRecord(event.data)) {\n const msg = event.data as Message & {\n seq?: number;\n method?: string;\n };\n streamQueue.push(msg);\n }\n }\n streamQueue.close();\n } catch (error) {\n rejectReady(error);\n if (ac.signal.aborted || this.closed) {\n streamQueue.close();\n return;\n }\n streamQueue.close(error);\n }\n };\n\n void startStream();\n\n const cleanup = () => {\n this.eventStreams.delete(ac);\n ac.abort();\n streamQueue.close();\n };\n\n return {\n events: {\n [Symbol.asyncIterator]: () => ({\n next: async () => await streamQueue.shift(),\n return: async () => {\n cleanup();\n return { done: true, value: undefined };\n },\n }),\n },\n ready,\n close: cleanup,\n };\n }\n\n async close(): Promise<void> {\n if (this.closed) {\n return;\n }\n this.closed = true;\n this.sessionAbortController.abort();\n for (const ac of this.eventStreams) ac.abort();\n this.eventStreams.clear();\n this.queue.close();\n }\n\n private async request(path: string, init: RequestInit): Promise<Response> {\n const url = toAbsoluteUrl(this.apiUrl, path);\n let requestInit: RequestInit = {\n ...init,\n headers: mergeHeaders(this.defaultHeaders, init.headers),\n };\n\n if (this.onRequest) {\n requestInit = await this.onRequest(url, requestInit);\n }\n\n try {\n const fetchImpl = await this.resolveFetch();\n const response = await fetchImpl(url.toString(), requestInit);\n if (!response.ok) {\n let detail = \"\";\n try {\n const body = await response.text();\n const parsed = JSON.parse(body);\n if (typeof parsed === \"object\" && parsed != null) {\n detail =\n ((parsed as Record<string, unknown>).message as string) ??\n ((parsed as Record<string, unknown>).error as string) ??\n \"\";\n }\n if (!detail) detail = body;\n } catch {\n // body unreadable or not JSON — fall through\n }\n const message = detail\n ? `Protocol request failed: ${response.status} ${response.statusText} — ${detail}`\n : `Protocol request failed: ${response.status} ${response.statusText}`;\n throw new Error(message);\n }\n return response;\n } catch (error) {\n throw toError(error);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AA+BA,IAAa,8BAAb,MAAqE;CACnE;CAEA;CAEA,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YAAY;AAC7D,OAAI,CAAC,SAAS,IAAI;IAChB,IAAI,SAAS;AACb,QAAI;KACF,MAAM,OAAO,MAAM,SAAS,MAAM;KAClC,MAAM,SAAS,KAAK,MAAM,KAAK;AAC/B,SAAI,OAAO,WAAW,YAAY,UAAU,KAC1C,UACI,OAAmC,WACnC,OAAmC,SACrC;AAEJ,SAAI,CAAC,OAAQ,UAAS;YAChB;IAGR,MAAM,UAAU,SACZ,4BAA4B,SAAS,OAAO,GAAG,SAAS,WAAW,KAAK,WACxE,4BAA4B,SAAS,OAAO,GAAG,SAAS;AAC5D,UAAM,IAAI,MAAM,QAAQ;;AAE1B,UAAO;WACA,OAAO;AACd,SAAM,QAAQ,MAAM"}
|
|
@@ -5,6 +5,8 @@ type ProtocolRequestHook = (url: URL, init: RequestInit) => Promise<RequestInit>
|
|
|
5
5
|
interface ProtocolTransportPaths {
|
|
6
6
|
commands?: string;
|
|
7
7
|
stream?: string;
|
|
8
|
+
/** `GET` path for thread-state hydration. Defaults to `/threads/:threadId/state`. */
|
|
9
|
+
state?: string;
|
|
8
10
|
}
|
|
9
11
|
interface ProtocolSseTransportOptions {
|
|
10
12
|
apiUrl: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","names":[],"sources":["../../../../src/client/stream/transport/types.ts"],"mappings":";;;KAEY,mBAAA,IACV,GAAA,EAAK,GAAA,EACL,IAAA,EAAM,WAAA,KACH,OAAA,CAAQ,WAAA,IAAe,WAAA;AAAA,UAEX,sBAAA;EACf,QAAA;EACA,MAAA;AAAA;AAAA,UAGe,2BAAA;EACf,MAAA;EACA,QAAA;EACA,cAAA,GAAiB,MAAA,SAAe,WAAA;EAChC,SAAA,GAAY,mBAAA;EACZ,KAAA,UAAe,KAAA;EACf,YAAA,gBAA4B,KAAA,GAAQ,OAAA,QAAe,KAAA;EACnD,KAAA,GAAQ,sBAAA;AAAA;AAAA,UAGO,iCAAA;EACf,MAAA;EACA,QAAA;EACA,cAAA,GAAiB,MAAA,SAAe,WAAA;EAChC,SAAA,GAAY,mBAAA;EACZ,gBAAA,IAAoB,GAAA,aAAgB,SAAA;EACpC,KAAA,GAAQ,IAAA,CAAK,sBAAA;AAAA;AAAA,KAGH,WAAA"}
|
|
1
|
+
{"version":3,"file":"types.d.cts","names":[],"sources":["../../../../src/client/stream/transport/types.ts"],"mappings":";;;KAEY,mBAAA,IACV,GAAA,EAAK,GAAA,EACL,IAAA,EAAM,WAAA,KACH,OAAA,CAAQ,WAAA,IAAe,WAAA;AAAA,UAEX,sBAAA;EACf,QAAA;EACA,MAAA;;EAEA,KAAA;AAAA;AAAA,UAGe,2BAAA;EACf,MAAA;EACA,QAAA;EACA,cAAA,GAAiB,MAAA,SAAe,WAAA;EAChC,SAAA,GAAY,mBAAA;EACZ,KAAA,UAAe,KAAA;EACf,YAAA,gBAA4B,KAAA,GAAQ,OAAA,QAAe,KAAA;EACnD,KAAA,GAAQ,sBAAA;AAAA;AAAA,UAGO,iCAAA;EACf,MAAA;EACA,QAAA;EACA,cAAA,GAAiB,MAAA,SAAe,WAAA;EAChC,SAAA,GAAY,mBAAA;EACZ,gBAAA,IAAoB,GAAA,aAAgB,SAAA;EACpC,KAAA,GAAQ,IAAA,CAAK,sBAAA;AAAA;AAAA,KAGH,WAAA"}
|
|
@@ -5,6 +5,8 @@ type ProtocolRequestHook = (url: URL, init: RequestInit) => Promise<RequestInit>
|
|
|
5
5
|
interface ProtocolTransportPaths {
|
|
6
6
|
commands?: string;
|
|
7
7
|
stream?: string;
|
|
8
|
+
/** `GET` path for thread-state hydration. Defaults to `/threads/:threadId/state`. */
|
|
9
|
+
state?: string;
|
|
8
10
|
}
|
|
9
11
|
interface ProtocolSseTransportOptions {
|
|
10
12
|
apiUrl: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../../src/client/stream/transport/types.ts"],"mappings":";;;KAEY,mBAAA,IACV,GAAA,EAAK,GAAA,EACL,IAAA,EAAM,WAAA,KACH,OAAA,CAAQ,WAAA,IAAe,WAAA;AAAA,UAEX,sBAAA;EACf,QAAA;EACA,MAAA;AAAA;AAAA,UAGe,2BAAA;EACf,MAAA;EACA,QAAA;EACA,cAAA,GAAiB,MAAA,SAAe,WAAA;EAChC,SAAA,GAAY,mBAAA;EACZ,KAAA,UAAe,KAAA;EACf,YAAA,gBAA4B,KAAA,GAAQ,OAAA,QAAe,KAAA;EACnD,KAAA,GAAQ,sBAAA;AAAA;AAAA,UAGO,iCAAA;EACf,MAAA;EACA,QAAA;EACA,cAAA,GAAiB,MAAA,SAAe,WAAA;EAChC,SAAA,GAAY,mBAAA;EACZ,gBAAA,IAAoB,GAAA,aAAgB,SAAA;EACpC,KAAA,GAAQ,IAAA,CAAK,sBAAA;AAAA;AAAA,KAGH,WAAA"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../../src/client/stream/transport/types.ts"],"mappings":";;;KAEY,mBAAA,IACV,GAAA,EAAK,GAAA,EACL,IAAA,EAAM,WAAA,KACH,OAAA,CAAQ,WAAA,IAAe,WAAA;AAAA,UAEX,sBAAA;EACf,QAAA;EACA,MAAA;;EAEA,KAAA;AAAA;AAAA,UAGe,2BAAA;EACf,MAAA;EACA,QAAA;EACA,cAAA,GAAiB,MAAA,SAAe,WAAA;EAChC,SAAA,GAAY,mBAAA;EACZ,KAAA,UAAe,KAAA;EACf,YAAA,gBAA4B,KAAA,GAAQ,OAAA,QAAe,KAAA;EACnD,KAAA,GAAQ,sBAAA;AAAA;AAAA,UAGO,iCAAA;EACf,MAAA;EACA,QAAA;EACA,cAAA,GAAiB,MAAA,SAAe,WAAA;EAChC,SAAA,GAAY,mBAAA;EACZ,gBAAA,IAAoB,GAAA,aAAgB,SAAA;EACpC,KAAA,GAAQ,IAAA,CAAK,sBAAA;AAAA;AAAA,KAGH,WAAA"}
|
|
@@ -86,16 +86,22 @@ interface TransportAdapter {
|
|
|
86
86
|
*/
|
|
87
87
|
interface AgentServerAdapter extends TransportAdapter {
|
|
88
88
|
/**
|
|
89
|
-
* Fetch the latest checkpointed state for the bound thread
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
89
|
+
* Fetch the latest checkpointed state for the bound thread via
|
|
90
|
+
* `GET /threads/:threadId/state` (or an adapter-specific override).
|
|
91
|
+
* When omitted, {@link StreamController.hydrate} falls back to
|
|
92
|
+
* `client.threads.getState()`.
|
|
93
93
|
*/
|
|
94
94
|
getState?<StateType = unknown>(): Promise<{
|
|
95
95
|
values: StateType;
|
|
96
|
+
next?: unknown;
|
|
97
|
+
tasks?: unknown;
|
|
98
|
+
metadata?: unknown;
|
|
96
99
|
checkpoint?: {
|
|
97
100
|
checkpoint_id?: string;
|
|
98
101
|
} | null;
|
|
102
|
+
parent_checkpoint?: {
|
|
103
|
+
checkpoint_id?: string;
|
|
104
|
+
} | null;
|
|
99
105
|
} | null>;
|
|
100
106
|
/**
|
|
101
107
|
* Fetch a slice of checkpoint history for the bound thread. Used
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.cts","names":[],"sources":["../../../src/client/stream/transport.ts"],"mappings":";;;;;AAgBA;;;;;;UAAiB,iBAAA;EACf,MAAA,EAAQ,aAAA,CAAc,OAAA;EACtB,KAAA,EAAO,OAAA;EACP,KAAA;AAAA;;;;;;AAUF;;UAAiB,gBAAA;EASP;;;EAAA,SALC,QAAA;EAWe;;;;EANxB,IAAA,IAAQ,OAAA;EAmCC;;;;;EA7BT,IAAA,CAAK,OAAA,EAAS,OAAA,GAAU,OAAA,CAAQ,eAAA,GAAkB,aAAA;EAAlD;;;;EAKA,MAAA,IAAU,aAAA,CAAc,OAAA;EAL0B;;;;;;;;;;;;AAiDpD;;;;;;;EAxBE,eAAA,EAAiB,MAAA,EAAQ,eAAA,GAAkB,iBAAA;EAwBD;;;EApB1C,KAAA,IAAS,OAAA;AAAA;;;;;;;;;;;;;;;;;;UAoBM,kBAAA,SAA2B,gBAAA
|
|
1
|
+
{"version":3,"file":"transport.d.cts","names":[],"sources":["../../../src/client/stream/transport.ts"],"mappings":";;;;;AAgBA;;;;;;UAAiB,iBAAA;EACf,MAAA,EAAQ,aAAA,CAAc,OAAA;EACtB,KAAA,EAAO,OAAA;EACP,KAAA;AAAA;;;;;;AAUF;;UAAiB,gBAAA;EASP;;;EAAA,SALC,QAAA;EAWe;;;;EANxB,IAAA,IAAQ,OAAA;EAmCC;;;;;EA7BT,IAAA,CAAK,OAAA,EAAS,OAAA,GAAU,OAAA,CAAQ,eAAA,GAAkB,aAAA;EAAlD;;;;EAKA,MAAA,IAAU,aAAA,CAAc,OAAA;EAL0B;;;;;;;;;;;;AAiDpD;;;;;;;EAxBE,eAAA,EAAiB,MAAA,EAAQ,eAAA,GAAkB,iBAAA;EAwBD;;;EApB1C,KAAA,IAAS,OAAA;AAAA;;;;;;;;;;;;;;;;;;UAoBM,kBAAA,SAA2B,gBAAA;EAwB9B;;;;;;EAjBZ,QAAA,0BAAkC,OAAA;IAChC,MAAA,EAAQ,SAAA;IACR,IAAA;IACA,KAAA;IACA,QAAA;IACA,UAAA;MAAe,aAAA;IAAA;IACf,iBAAA;MAAsB,aAAA;IAAA;EAAA;;;;;;EAOxB,UAAA,uBAAiC,OAAA;IAC/B,KAAA;EAAA,IACE,OAAA,CACF,KAAA;IACE,MAAA,EAAQ,SAAA;IACR,UAAA;MAAe,aAAA;IAAA;EAAA;AAAA"}
|
|
@@ -86,16 +86,22 @@ interface TransportAdapter {
|
|
|
86
86
|
*/
|
|
87
87
|
interface AgentServerAdapter extends TransportAdapter {
|
|
88
88
|
/**
|
|
89
|
-
* Fetch the latest checkpointed state for the bound thread
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
89
|
+
* Fetch the latest checkpointed state for the bound thread via
|
|
90
|
+
* `GET /threads/:threadId/state` (or an adapter-specific override).
|
|
91
|
+
* When omitted, {@link StreamController.hydrate} falls back to
|
|
92
|
+
* `client.threads.getState()`.
|
|
93
93
|
*/
|
|
94
94
|
getState?<StateType = unknown>(): Promise<{
|
|
95
95
|
values: StateType;
|
|
96
|
+
next?: unknown;
|
|
97
|
+
tasks?: unknown;
|
|
98
|
+
metadata?: unknown;
|
|
96
99
|
checkpoint?: {
|
|
97
100
|
checkpoint_id?: string;
|
|
98
101
|
} | null;
|
|
102
|
+
parent_checkpoint?: {
|
|
103
|
+
checkpoint_id?: string;
|
|
104
|
+
} | null;
|
|
99
105
|
} | null>;
|
|
100
106
|
/**
|
|
101
107
|
* Fetch a slice of checkpoint history for the bound thread. Used
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","names":[],"sources":["../../../src/client/stream/transport.ts"],"mappings":";;;;;AAgBA;;;;;;UAAiB,iBAAA;EACf,MAAA,EAAQ,aAAA,CAAc,OAAA;EACtB,KAAA,EAAO,OAAA;EACP,KAAA;AAAA;;;;;;AAUF;;UAAiB,gBAAA;EASP;;;EAAA,SALC,QAAA;EAWe;;;;EANxB,IAAA,IAAQ,OAAA;EAmCC;;;;;EA7BT,IAAA,CAAK,OAAA,EAAS,OAAA,GAAU,OAAA,CAAQ,eAAA,GAAkB,aAAA;EAAlD;;;;EAKA,MAAA,IAAU,aAAA,CAAc,OAAA;EAL0B;;;;;;;;;;;;AAiDpD;;;;;;;EAxBE,eAAA,EAAiB,MAAA,EAAQ,eAAA,GAAkB,iBAAA;EAwBD;;;EApB1C,KAAA,IAAS,OAAA;AAAA;;;;;;;;;;;;;;;;;;UAoBM,kBAAA,SAA2B,gBAAA
|
|
1
|
+
{"version":3,"file":"transport.d.ts","names":[],"sources":["../../../src/client/stream/transport.ts"],"mappings":";;;;;AAgBA;;;;;;UAAiB,iBAAA;EACf,MAAA,EAAQ,aAAA,CAAc,OAAA;EACtB,KAAA,EAAO,OAAA;EACP,KAAA;AAAA;;;;;;AAUF;;UAAiB,gBAAA;EASP;;;EAAA,SALC,QAAA;EAWe;;;;EANxB,IAAA,IAAQ,OAAA;EAmCC;;;;;EA7BT,IAAA,CAAK,OAAA,EAAS,OAAA,GAAU,OAAA,CAAQ,eAAA,GAAkB,aAAA;EAAlD;;;;EAKA,MAAA,IAAU,aAAA,CAAc,OAAA;EAL0B;;;;;;;;;;;;AAiDpD;;;;;;;EAxBE,eAAA,EAAiB,MAAA,EAAQ,eAAA,GAAkB,iBAAA;EAwBD;;;EApB1C,KAAA,IAAS,OAAA;AAAA;;;;;;;;;;;;;;;;;;UAoBM,kBAAA,SAA2B,gBAAA;EAwB9B;;;;;;EAjBZ,QAAA,0BAAkC,OAAA;IAChC,MAAA,EAAQ,SAAA;IACR,IAAA;IACA,KAAA;IACA,QAAA;IACA,UAAA;MAAe,aAAA;IAAA;IACf,iBAAA;MAAsB,aAAA;IAAA;EAAA;;;;;;EAOxB,UAAA,uBAAiC,OAAA;IAC/B,KAAA;EAAA,IACE,OAAA,CACF,KAAA;IACE,MAAA,EAAQ,SAAA;IACR,UAAA;MAAe,aAAA;IAAA;EAAA;AAAA"}
|
package/dist/client.cjs
CHANGED
|
@@ -13,6 +13,7 @@ const require_index$3 = require("./client/runs/index.cjs");
|
|
|
13
13
|
const require_index$4 = require("./client/crons/index.cjs");
|
|
14
14
|
const require_index$5 = require("./client/store/index.cjs");
|
|
15
15
|
const require_agent_server = require("./client/stream/transport/agent-server.cjs");
|
|
16
|
+
const require_resolve_client_api_url = require("./client/stream/resolve-client-api-url.cjs");
|
|
16
17
|
const require_index$6 = require("./client/index.cjs");
|
|
17
18
|
exports.AssistantsClient = require_index.AssistantsClient;
|
|
18
19
|
exports.BaseClient = require_base.BaseClient;
|
|
@@ -34,3 +35,4 @@ exports.getApiKey = require_base.getApiKey;
|
|
|
34
35
|
exports.getClientConfigHash = require_index$6.getClientConfigHash;
|
|
35
36
|
exports.inferChannel = require_subscription.inferChannel;
|
|
36
37
|
exports.matchesSubscription = require_subscription.matchesSubscription;
|
|
38
|
+
exports.resolveClientApiUrl = require_resolve_client_api_url.resolveClientApiUrl;
|
package/dist/client.d.cts
CHANGED
|
@@ -15,5 +15,6 @@ import { HeaderValue as HeaderValue$1, ProtocolRequestHook, ProtocolSseTransport
|
|
|
15
15
|
import { ProtocolSseTransportAdapter } from "./client/stream/transport/http.cjs";
|
|
16
16
|
import { ProtocolWebSocketTransportAdapter } from "./client/stream/transport/websocket.cjs";
|
|
17
17
|
import { HttpAgentServerAdapter, HttpAgentServerAdapterOptions } from "./client/stream/transport/agent-server.cjs";
|
|
18
|
+
import { resolveClientApiUrl } from "./client/stream/resolve-client-api-url.cjs";
|
|
18
19
|
import { Client, getClientConfigHash } from "./client/index.cjs";
|
|
19
|
-
export { type AgentServerAdapter, type AnyMediaHandle, type AssembledMessage, AssistantsClient, type AudioMedia, BaseClient, Client, type ClientConfig, CronsClient, type EventForChannel, type EventForChannels, type EventMethodByChannel, type EventSubscription, type FileMedia, type HeaderValue, HttpAgentServerAdapter, type HttpAgentServerAdapterOptions, type ImageMedia, type InputModule, MediaAssembler, type MediaAssemblerCallbacks, type MediaAssemblerOptions, MediaAssemblyError, type MediaAssemblyErrorKind, type MediaBase, type MediaBlockType, MessageAssembler, type MessageAssemblyUpdate, type MessageSubscription, ProtocolError, type HeaderValue$1 as ProtocolHeaderValue, type ProtocolRequestHook, ProtocolSseTransportAdapter, type ProtocolSseTransportOptions, type ProtocolTransportPaths, ProtocolWebSocketTransportAdapter, type ProtocolWebSocketTransportOptions, type RequestHook, RunsClient, type SessionOrderingState, type StateModule, StoreClient, type SubscribeOptions, SubscriptionHandle, type ThreadExtension, type ThreadExtensions, type ThreadModules, ThreadStream, type ThreadStreamOptions, type ThreadStreamTransport, type ThreadStreamTransportKind, ThreadsClient, type TransportAdapter, type UnwrapExtension, type VideoMedia, getApiKey, getClientConfigHash, inferChannel, matchesSubscription };
|
|
20
|
+
export { type AgentServerAdapter, type AnyMediaHandle, type AssembledMessage, AssistantsClient, type AudioMedia, BaseClient, Client, type ClientConfig, CronsClient, type EventForChannel, type EventForChannels, type EventMethodByChannel, type EventSubscription, type FileMedia, type HeaderValue, HttpAgentServerAdapter, type HttpAgentServerAdapterOptions, type ImageMedia, type InputModule, MediaAssembler, type MediaAssemblerCallbacks, type MediaAssemblerOptions, MediaAssemblyError, type MediaAssemblyErrorKind, type MediaBase, type MediaBlockType, MessageAssembler, type MessageAssemblyUpdate, type MessageSubscription, ProtocolError, type HeaderValue$1 as ProtocolHeaderValue, type ProtocolRequestHook, ProtocolSseTransportAdapter, type ProtocolSseTransportOptions, type ProtocolTransportPaths, ProtocolWebSocketTransportAdapter, type ProtocolWebSocketTransportOptions, type RequestHook, RunsClient, type SessionOrderingState, type StateModule, StoreClient, type SubscribeOptions, SubscriptionHandle, type ThreadExtension, type ThreadExtensions, type ThreadModules, ThreadStream, type ThreadStreamOptions, type ThreadStreamTransport, type ThreadStreamTransportKind, ThreadsClient, type TransportAdapter, type UnwrapExtension, type VideoMedia, getApiKey, getClientConfigHash, inferChannel, matchesSubscription, resolveClientApiUrl };
|
package/dist/client.d.ts
CHANGED
|
@@ -15,5 +15,6 @@ import { HeaderValue as HeaderValue$1, ProtocolRequestHook, ProtocolSseTransport
|
|
|
15
15
|
import { ProtocolSseTransportAdapter } from "./client/stream/transport/http.js";
|
|
16
16
|
import { ProtocolWebSocketTransportAdapter } from "./client/stream/transport/websocket.js";
|
|
17
17
|
import { HttpAgentServerAdapter, HttpAgentServerAdapterOptions } from "./client/stream/transport/agent-server.js";
|
|
18
|
+
import { resolveClientApiUrl } from "./client/stream/resolve-client-api-url.js";
|
|
18
19
|
import { Client, getClientConfigHash } from "./client/index.js";
|
|
19
|
-
export { type AgentServerAdapter, type AnyMediaHandle, type AssembledMessage, AssistantsClient, type AudioMedia, BaseClient, Client, type ClientConfig, CronsClient, type EventForChannel, type EventForChannels, type EventMethodByChannel, type EventSubscription, type FileMedia, type HeaderValue, HttpAgentServerAdapter, type HttpAgentServerAdapterOptions, type ImageMedia, type InputModule, MediaAssembler, type MediaAssemblerCallbacks, type MediaAssemblerOptions, MediaAssemblyError, type MediaAssemblyErrorKind, type MediaBase, type MediaBlockType, MessageAssembler, type MessageAssemblyUpdate, type MessageSubscription, ProtocolError, type HeaderValue$1 as ProtocolHeaderValue, type ProtocolRequestHook, ProtocolSseTransportAdapter, type ProtocolSseTransportOptions, type ProtocolTransportPaths, ProtocolWebSocketTransportAdapter, type ProtocolWebSocketTransportOptions, type RequestHook, RunsClient, type SessionOrderingState, type StateModule, StoreClient, type SubscribeOptions, SubscriptionHandle, type ThreadExtension, type ThreadExtensions, type ThreadModules, ThreadStream, type ThreadStreamOptions, type ThreadStreamTransport, type ThreadStreamTransportKind, ThreadsClient, type TransportAdapter, type UnwrapExtension, type VideoMedia, getApiKey, getClientConfigHash, inferChannel, matchesSubscription };
|
|
20
|
+
export { type AgentServerAdapter, type AnyMediaHandle, type AssembledMessage, AssistantsClient, type AudioMedia, BaseClient, Client, type ClientConfig, CronsClient, type EventForChannel, type EventForChannels, type EventMethodByChannel, type EventSubscription, type FileMedia, type HeaderValue, HttpAgentServerAdapter, type HttpAgentServerAdapterOptions, type ImageMedia, type InputModule, MediaAssembler, type MediaAssemblerCallbacks, type MediaAssemblerOptions, MediaAssemblyError, type MediaAssemblyErrorKind, type MediaBase, type MediaBlockType, MessageAssembler, type MessageAssemblyUpdate, type MessageSubscription, ProtocolError, type HeaderValue$1 as ProtocolHeaderValue, type ProtocolRequestHook, ProtocolSseTransportAdapter, type ProtocolSseTransportOptions, type ProtocolTransportPaths, ProtocolWebSocketTransportAdapter, type ProtocolWebSocketTransportOptions, type RequestHook, RunsClient, type SessionOrderingState, type StateModule, StoreClient, type SubscribeOptions, SubscriptionHandle, type ThreadExtension, type ThreadExtensions, type ThreadModules, ThreadStream, type ThreadStreamOptions, type ThreadStreamTransport, type ThreadStreamTransportKind, ThreadsClient, type TransportAdapter, type UnwrapExtension, type VideoMedia, getApiKey, getClientConfigHash, inferChannel, matchesSubscription, resolveClientApiUrl };
|
package/dist/client.js
CHANGED
|
@@ -12,5 +12,6 @@ import { RunsClient } from "./client/runs/index.js";
|
|
|
12
12
|
import { CronsClient } from "./client/crons/index.js";
|
|
13
13
|
import { StoreClient } from "./client/store/index.js";
|
|
14
14
|
import { HttpAgentServerAdapter } from "./client/stream/transport/agent-server.js";
|
|
15
|
+
import { resolveClientApiUrl } from "./client/stream/resolve-client-api-url.js";
|
|
15
16
|
import { Client, getClientConfigHash } from "./client/index.js";
|
|
16
|
-
export { AssistantsClient, BaseClient, Client, CronsClient, HttpAgentServerAdapter, MediaAssembler, MediaAssemblyError, MessageAssembler, ProtocolError, ProtocolSseTransportAdapter, ProtocolWebSocketTransportAdapter, RunsClient, StoreClient, SubscriptionHandle, ThreadStream, ThreadsClient, getApiKey, getClientConfigHash, inferChannel, matchesSubscription };
|
|
17
|
+
export { AssistantsClient, BaseClient, Client, CronsClient, HttpAgentServerAdapter, MediaAssembler, MediaAssemblyError, MessageAssembler, ProtocolError, ProtocolSseTransportAdapter, ProtocolWebSocketTransportAdapter, RunsClient, StoreClient, SubscriptionHandle, ThreadStream, ThreadsClient, getApiKey, getClientConfigHash, inferChannel, matchesSubscription, resolveClientApiUrl };
|
|
@@ -345,6 +345,17 @@ var StreamController = class {
|
|
|
345
345
|
this.#hydrationPromise = this.#createHydrationPromise();
|
|
346
346
|
}
|
|
347
347
|
/**
|
|
348
|
+
* Load thread state for hydration, preferring the active custom
|
|
349
|
+
* adapter's `getState()` when present.
|
|
350
|
+
*/
|
|
351
|
+
async #fetchHydrationState() {
|
|
352
|
+
const threadId = this.#currentThreadId;
|
|
353
|
+
if (threadId == null) return null;
|
|
354
|
+
const transport = this.#options.transport;
|
|
355
|
+
if (transport != null && typeof transport === "object" && typeof transport.getState === "function") return await transport.getState();
|
|
356
|
+
return this.#options.client.threads.getState(threadId);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
348
359
|
* Fetch the checkpointed thread state and seed the root snapshot.
|
|
349
360
|
* Re-calling with a different `threadId` swaps the underlying
|
|
350
361
|
* {@link ThreadStream}, rewires the registry to the new thread, and
|
|
@@ -417,7 +428,7 @@ var StreamController = class {
|
|
|
417
428
|
let threadExists = false;
|
|
418
429
|
let threadActive = true;
|
|
419
430
|
try {
|
|
420
|
-
const state = await this.#
|
|
431
|
+
const state = await this.#fetchHydrationState();
|
|
421
432
|
threadExists = state != null;
|
|
422
433
|
threadActive = isThreadStateActive(state);
|
|
423
434
|
if (state?.values != null) {
|