@langchain/svelte 1.0.16 → 1.0.17
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/selectors.svelte.cjs +27 -0
- package/dist/selectors.svelte.cjs.map +1 -1
- package/dist/selectors.svelte.d.cts.map +1 -1
- package/dist/selectors.svelte.d.ts.map +1 -1
- package/dist/selectors.svelte.js +27 -0
- package/dist/selectors.svelte.js.map +1 -1
- package/dist/use-stream.svelte.cjs +2 -1
- package/dist/use-stream.svelte.cjs.map +1 -1
- package/dist/use-stream.svelte.d.cts.map +1 -1
- package/dist/use-stream.svelte.d.ts.map +1 -1
- package/dist/use-stream.svelte.js +2 -1
- package/dist/use-stream.svelte.js.map +1 -1
- package/package.json +5 -5
|
@@ -18,6 +18,31 @@ function isGetter(input) {
|
|
|
18
18
|
return typeof input === "function";
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
+
* If `target` is a subagent snapshot still on its default
|
|
22
|
+
* `tools:<toolCallId>` namespace, return that tool-call id. See the
|
|
23
|
+
* React selectors for the rationale (deep-agent subagents execute under
|
|
24
|
+
* a distinct `tools:<uuid>` namespace resolved lazily from history).
|
|
25
|
+
*/
|
|
26
|
+
function subagentNeedingNamespace(target) {
|
|
27
|
+
if (target == null || Array.isArray(target)) return null;
|
|
28
|
+
const obj = target;
|
|
29
|
+
if (typeof obj.id !== "string" || !Array.isArray(obj.namespace)) return null;
|
|
30
|
+
if (obj.namespace.length === 1 && obj.namespace[0] === `tools:${obj.id}`) return obj.id;
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Lazily resolve a subagent's execution namespace on first scoped use.
|
|
35
|
+
* Re-evaluates when a reactive `target` changes; the controller
|
|
36
|
+
* de-dupes and skips already-promoted ids.
|
|
37
|
+
*/
|
|
38
|
+
function useResolveSubagentNamespace(stream, target) {
|
|
39
|
+
const controller = stream[require_use_stream_svelte.STREAM_CONTROLLER];
|
|
40
|
+
$effect(() => {
|
|
41
|
+
const id = subagentNeedingNamespace(isGetter(target) ? target() : target);
|
|
42
|
+
if (id != null) controller.resolveSubagentNamespace(id);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
21
46
|
* Internal helper that wires a reactive-or-static target into
|
|
22
47
|
* {@link useProjection}. Encapsulates the bookkeeping every selector
|
|
23
48
|
* otherwise repeats.
|
|
@@ -63,6 +88,7 @@ const EMPTY_FILES = [];
|
|
|
63
88
|
* `@langchain/core/messages`.
|
|
64
89
|
*/
|
|
65
90
|
function useMessages(stream, target) {
|
|
91
|
+
useResolveSubagentNamespace(stream, target);
|
|
66
92
|
if (!isGetter(target)) {
|
|
67
93
|
if (isRoot(resolveNamespace(target))) return { get current() {
|
|
68
94
|
return stream.messages;
|
|
@@ -71,6 +97,7 @@ function useMessages(stream, target) {
|
|
|
71
97
|
return selectFromTarget(stream, target, EMPTY_MESSAGES, (ns) => (0, _langchain_langgraph_sdk_stream.messagesProjection)(ns), "messages");
|
|
72
98
|
}
|
|
73
99
|
function useToolCalls(stream, target) {
|
|
100
|
+
useResolveSubagentNamespace(stream, target);
|
|
74
101
|
if (!isGetter(target)) {
|
|
75
102
|
if (isRoot(resolveNamespace(target))) return { get current() {
|
|
76
103
|
return stream.toolCalls;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.svelte.cjs","names":["NAMESPACE_SEPARATOR","useProjection","getRegistry","STREAM_CONTROLLER"],"sources":["../src/selectors.svelte.ts"],"sourcesContent":["import type { BaseMessage } from \"@langchain/core/messages\";\nimport {\n NAMESPACE_SEPARATOR,\n audioProjection,\n channelProjection,\n extensionProjection,\n filesProjection,\n imagesProjection,\n messagesProjection,\n toolCallsProjection,\n valuesProjection,\n videoProjection,\n type AssembledToolCall,\n type AudioMedia,\n type Channel,\n type ChannelProjectionOptions,\n type Event,\n type FileMedia,\n type ImageMedia,\n type InferToolCalls,\n type InferStateType,\n type MessageMetadata,\n type MessageMetadataMap,\n type SubagentDiscoverySnapshot,\n type SubgraphDiscoverySnapshot,\n type SubmissionQueueEntry,\n type SubmissionQueueSnapshot,\n type VideoMedia,\n} from \"@langchain/langgraph-sdk/stream\";\nimport {\n getRegistry,\n STREAM_CONTROLLER,\n type AnyStream,\n type UseStreamReturn,\n} from \"./use-stream.svelte.js\";\nimport {\n useProjection,\n type ReactiveValue,\n type ValueOrGetter,\n} from \"./use-projection.svelte.js\";\n\n/**\n * Parameterise selectors on `StateType` alone so callers with a full\n * `useStream<S, I, C>()` handle don't have to redeclare\n * `InterruptType` / `ConfigurableType` at every call site.\n */\ntype StreamHandle<StateType extends object> = UseStreamReturn<\n StateType,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any\n>;\n\n/**\n * What a selector composable targets. Callers can pass:\n * - `undefined` / `null` — root namespace (served by the always-on\n * root store; no extra subscription opens);\n * - a {@link SubagentDiscoverySnapshot} (`stream.subagents.get(...)`);\n * - a {@link SubgraphDiscoverySnapshot}\n * (`stream.subgraphs.get(...)`);\n * - an explicit `{ namespace: string[] }`;\n * - a raw `string[]` escape hatch.\n */\nexport type SelectorTarget =\n | undefined\n | null\n | readonly string[]\n | { namespace: readonly string[] }\n | SubagentDiscoverySnapshot\n | SubgraphDiscoverySnapshot;\n\nconst EMPTY_NAMESPACE: readonly string[] = [];\n\nfunction resolveNamespace(target: SelectorTarget): readonly string[] {\n if (target == null) return EMPTY_NAMESPACE;\n if (Array.isArray(target)) return target as readonly string[];\n const obj = target as { namespace?: readonly string[] };\n return obj.namespace ?? EMPTY_NAMESPACE;\n}\n\nfunction isRoot(namespace: readonly string[]): boolean {\n return namespace.length === 0;\n}\n\nfunction namespaceKey(namespace: readonly string[]): string {\n return namespace.join(NAMESPACE_SEPARATOR);\n}\n\nfunction isGetter<T>(input: ValueOrGetter<T> | undefined): input is () => T {\n return typeof input === \"function\";\n}\n\n/**\n * Internal helper that wires a reactive-or-static target into\n * {@link useProjection}. Encapsulates the bookkeeping every selector\n * otherwise repeats.\n */\nfunction selectFromTarget<T>(\n stream: AnyStream,\n target: ValueOrGetter<SelectorTarget> | undefined,\n initialValue: T,\n makeSpec: (\n namespace: readonly string[]\n ) => import(\"@langchain/langgraph-sdk/stream\").ProjectionSpec<T>,\n keyPrefix: string\n): ReactiveValue<T> {\n if (isGetter(target)) {\n const getTarget = target;\n return useProjection<T>(\n () => {\n const ns = resolveNamespace(getTarget());\n return isRoot(ns) ? null : getRegistry(stream);\n },\n () => makeSpec(resolveNamespace(getTarget())),\n () => `${keyPrefix}|${namespaceKey(resolveNamespace(getTarget()))}`,\n initialValue\n );\n }\n const ns = resolveNamespace(target);\n // Static root: we deliberately don't short-circuit here because\n // each selector owns the root fallback shape (`stream.messages`\n // vs `stream.values` vs `stream.toolCalls`). Callers use the\n // dedicated wrappers below.\n const key = `${keyPrefix}|${namespaceKey(ns)}`;\n return useProjection<T>(\n isRoot(ns) ? null : getRegistry(stream),\n () => makeSpec(ns),\n key,\n initialValue\n );\n}\n\nconst EMPTY_MESSAGES: BaseMessage[] = [];\nconst EMPTY_TOOLCALLS: AssembledToolCall[] = [];\nconst EMPTY_EVENTS: Event[] = [];\nconst EMPTY_AUDIO: AudioMedia[] = [];\nconst EMPTY_IMAGES: ImageMedia[] = [];\nconst EMPTY_VIDEO: VideoMedia[] = [];\nconst EMPTY_FILES: FileMedia[] = [];\n\n/**\n * Subscribe to a scoped `messages` stream.\n *\n * Contract:\n * - At the root (no `target`, or a static target that resolves to\n * the root namespace) returns a handle whose `.current` delegates\n * to `stream.messages` — the always-on root projection. No extra\n * subscription is opened.\n * - For any non-root namespace, mount triggers a ref-counted\n * `messages` subscription scoped to that namespace. The\n * subscription is released automatically when the owning\n * component teardown fires (and the registry closes the\n * underlying server subscription when the last consumer leaves).\n * - A reactive `target` (getter form) re-binds the subscription on\n * change. A getter that flips between root and scoped is\n * supported: the root case short-circuits to the initial value\n * because dynamic root delegation isn't meaningful — pass a\n * static undefined/null target for root handles.\n *\n * Messages are always `BaseMessage` class instances from\n * `@langchain/core/messages`.\n */\nexport function useMessages(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<BaseMessage[]> {\n if (!isGetter(target)) {\n const ns = resolveNamespace(target);\n if (isRoot(ns)) {\n return {\n get current() {\n return stream.messages;\n },\n };\n }\n }\n return selectFromTarget<BaseMessage[]>(\n stream,\n target,\n EMPTY_MESSAGES,\n (ns) => messagesProjection(ns),\n \"messages\"\n );\n}\n\n/**\n * Subscribe to a scoped `tools` (tool-call) stream. Same target and\n * lifecycle rules as {@link useMessages}; at the root this returns a\n * handle delegating to `stream.toolCalls`.\n */\nexport function useToolCalls(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<AssembledToolCall[]>;\nexport function useToolCalls<T>(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<InferToolCalls<T>[]>;\nexport function useToolCalls(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<AssembledToolCall[]> {\n if (!isGetter(target)) {\n const ns = resolveNamespace(target);\n if (isRoot(ns)) {\n return {\n get current() {\n return stream.toolCalls;\n },\n };\n }\n }\n return selectFromTarget<AssembledToolCall[]>(\n stream,\n target,\n EMPTY_TOOLCALLS,\n (ns) => toolCallsProjection(ns),\n \"toolCalls\"\n );\n}\n\n/**\n * Subscribe to a scoped `values` stream — the most recent state\n * payload for a namespace. At the root returns a handle delegating\n * to `stream.values`.\n *\n * Typing:\n * - **Root** (`useValues(stream)`): returns the `StateType` declared\n * on `useStream<State>()` — non-nullable (the root snapshot\n * always has values, falling back to `initialValues ?? {}`).\n * - **Scoped** (`useValues(stream, target)`): scoped payloads can\n * differ from the root state; callers should annotate the\n * expected shape explicitly (`useValues<SubagentState>(stream,\n * sub)`). Defaults to `unknown` when not annotated.\n */\nexport function useValues<StateType extends object>(\n stream: StreamHandle<StateType>\n): ReactiveValue<StateType>;\nexport function useValues<T>(\n stream: AnyStream\n): ReactiveValue<InferStateType<T>>;\nexport function useValues<T = unknown>(\n stream: AnyStream,\n target: ValueOrGetter<SelectorTarget>,\n options?: { messagesKey?: string }\n): ReactiveValue<T | undefined>;\nexport function useValues(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>,\n options?: { messagesKey?: string }\n): ReactiveValue<unknown> {\n if (!isGetter(target)) {\n const ns = resolveNamespace(target);\n if (isRoot(ns)) {\n return {\n get current() {\n return stream.values;\n },\n };\n }\n }\n const messagesKey = options?.messagesKey ?? \"messages\";\n return selectFromTarget<unknown>(\n stream,\n target,\n undefined,\n (ns) => valuesProjection<unknown>(ns, messagesKey),\n `values|${messagesKey}`\n );\n}\n\n/**\n * Subscribe to a `custom:<name>` stream extension — most-recent\n * payload emitted by the transformer, scoped to the target namespace.\n *\n * `name` accepts either a plain string or a getter so component\n * state can drive the extension name at runtime.\n */\nexport function useExtension<T = unknown>(\n stream: AnyStream,\n name: ValueOrGetter<string>,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<T | undefined> {\n const getName = () => (isGetter(name) ? (name as () => string)() : name);\n if (isGetter(target)) {\n const getTarget = target;\n return useProjection<T | undefined>(\n () => getRegistry(stream),\n () => extensionProjection<T>(getName(), resolveNamespace(getTarget())),\n () =>\n `extension|${getName()}|${namespaceKey(resolveNamespace(getTarget()))}`,\n undefined\n );\n }\n const ns = resolveNamespace(target);\n return useProjection<T | undefined>(\n getRegistry(stream),\n () => extensionProjection<T>(getName(), ns),\n () => `extension|${getName()}|${namespaceKey(ns)}`,\n undefined\n );\n}\n\n/**\n * Raw-events escape hatch. Subscribes to one or more channels at a\n * namespace and returns a bounded buffer of raw protocol events.\n * Prefer {@link useMessages} / {@link useToolCalls} / {@link useValues}\n * for the common cases.\n */\nexport type UseChannelOptions = ChannelProjectionOptions;\n\nexport function useChannel(\n stream: AnyStream,\n channels: ValueOrGetter<readonly Channel[]>,\n target?: ValueOrGetter<SelectorTarget>,\n options?: UseChannelOptions\n): ReactiveValue<Event[]> {\n const getChannels = () =>\n isGetter(channels) ? (channels as () => readonly Channel[])() : channels;\n const getTarget = () => (isGetter(target) ? target() : target);\n const bufferSize = options?.bufferSize ?? \"default\";\n const replayMode = (options?.replay ?? true) ? \"replay\" : \"live\";\n return useProjection<Event[]>(\n () => getRegistry(stream),\n () =>\n channelProjection(\n getChannels(),\n resolveNamespace(getTarget()),\n options\n ) as unknown as import(\"@langchain/langgraph-sdk/stream\").ProjectionSpec<\n Event[]\n >,\n () => {\n const sortedChannels = [...getChannels()].sort().join(\",\");\n return `channel|${bufferSize}|${replayMode}|${sortedChannels}|${namespaceKey(resolveNamespace(getTarget()))}`;\n },\n EMPTY_EVENTS\n );\n}\n\n/**\n * Subscribe to a scoped audio-media stream. Each handle is yielded\n * on its first matching `content-block-start`, exposes\n * `.partialBytes` for live access, settles `.blob` / `.objectURL` /\n * `.transcript` on `message-finish`, and surfaces errors via\n * `.error`.\n */\nexport function useAudio(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<AudioMedia[]> {\n return selectFromTarget<AudioMedia[]>(\n stream,\n target,\n EMPTY_AUDIO,\n (ns) => audioProjection(ns),\n \"audio\"\n );\n}\n\n/**\n * Subscribe to a scoped image-media stream. Pair with `useMediaURL`\n * for `<img src>`.\n */\nexport function useImages(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<ImageMedia[]> {\n return selectFromTarget<ImageMedia[]>(\n stream,\n target,\n EMPTY_IMAGES,\n (ns) => imagesProjection(ns),\n \"images\"\n );\n}\n\n/**\n * Subscribe to a scoped video-media stream. Pair with `useMediaURL`\n * for `<video src>`.\n */\nexport function useVideo(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<VideoMedia[]> {\n return selectFromTarget<VideoMedia[]>(\n stream,\n target,\n EMPTY_VIDEO,\n (ns) => videoProjection(ns),\n \"video\"\n );\n}\n\n/**\n * Subscribe to a scoped file-media stream. Pair with `useMediaURL`\n * for an `<a download href>` target.\n */\nexport function useFiles(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<FileMedia[]> {\n return selectFromTarget<FileMedia[]>(\n stream,\n target,\n EMPTY_FILES,\n (ns) => filesProjection(ns),\n \"files\"\n );\n}\n\n/**\n * Read metadata recorded for a specific message id — today exposes\n * `parentCheckpointId`, the checkpoint the message was first seen\n * on. Designed for fork / edit flows:\n *\n * ```svelte\n * <script lang=\"ts\">\n * const meta = useMessageMetadata(stream, () => selected?.id);\n * </script>\n * Parent: {meta.current?.parentCheckpointId ?? \"root\"}\n * ```\n *\n * `messageId` accepts a plain string or a getter — the binding\n * re-evaluates whenever the id changes.\n */\nexport function useMessageMetadata(\n stream: AnyStream,\n messageId: ValueOrGetter<string | undefined>\n): ReactiveValue<MessageMetadata | undefined> {\n const store = stream[STREAM_CONTROLLER].messageMetadataStore;\n let map = $state<MessageMetadataMap>(store.getSnapshot());\n\n $effect(() => {\n const unsubscribe = store.subscribe(() => {\n map = store.getSnapshot();\n });\n return unsubscribe;\n });\n\n const getId = () =>\n isGetter(messageId) ? (messageId as () => string | undefined)() : messageId;\n\n return {\n get current(): MessageMetadata | undefined {\n const key = getId();\n if (key == null) return undefined;\n return map.get(key);\n },\n };\n}\n\n/**\n * Reactive handle on the server-side submission queue.\n *\n * Populated when `submit()` is invoked with\n * `multitaskStrategy: \"enqueue\"` while another run is in flight. The\n * returned getters are stable — safe to pass into `{#each}`.\n */\nexport interface UseSubmissionQueueReturn<\n StateType extends object = Record<string, unknown>,\n> {\n readonly entries: SubmissionQueueSnapshot<StateType>;\n readonly size: number;\n cancel(id: string): Promise<boolean>;\n clear(): Promise<void>;\n}\n\nexport function useSubmissionQueue<StateType extends object>(\n stream: StreamHandle<StateType>\n): UseSubmissionQueueReturn<StateType>;\nexport function useSubmissionQueue(stream: AnyStream): UseSubmissionQueueReturn;\nexport function useSubmissionQueue(\n stream: AnyStream\n): UseSubmissionQueueReturn {\n const controller = stream[STREAM_CONTROLLER];\n const store = controller.queueStore;\n let entries = $state<SubmissionQueueSnapshot>(store.getSnapshot());\n\n $effect(() => {\n const unsubscribe = store.subscribe(() => {\n entries = store.getSnapshot();\n });\n return unsubscribe;\n });\n\n return {\n get entries() {\n return entries;\n },\n get size() {\n return entries.length;\n },\n cancel: (id) => controller.cancelQueued(id),\n clear: () => controller.clearQueue(),\n };\n}\n\nexport type { SubmissionQueueEntry, SubmissionQueueSnapshot };\n"],"mappings":";;;;AAwEA,MAAM,kBAAqC,EAAE;AAE7C,SAAS,iBAAiB,QAA2C;AACnE,KAAI,UAAU,KAAM,QAAO;AAC3B,KAAI,MAAM,QAAQ,OAAO,CAAE,QAAO;AAElC,QADY,OACD,aAAa;;AAG1B,SAAS,OAAO,WAAuC;AACrD,QAAO,UAAU,WAAW;;AAG9B,SAAS,aAAa,WAAsC;AAC1D,QAAO,UAAU,KAAKA,gCAAAA,oBAAoB;;AAG5C,SAAS,SAAY,OAAuD;AAC1E,QAAO,OAAO,UAAU;;;;;;;AAQ1B,SAAS,iBACP,QACA,QACA,cACA,UAGA,WACkB;AAClB,KAAI,SAAS,OAAO,EAAE;EACpB,MAAM,YAAY;AAClB,SAAOC,8BAAAA,oBACC;AAEJ,UAAO,OADI,iBAAiB,WAAW,CAAC,CACvB,GAAG,OAAOC,0BAAAA,YAAY,OAAO;WAE1C,SAAS,iBAAiB,WAAW,CAAC,CAAC,QACvC,GAAG,UAAU,GAAG,aAAa,iBAAiB,WAAW,CAAC,CAAC,IACjE,aACD;;CAEH,MAAM,KAAK,iBAAiB,OAAO;CAKnC,MAAM,MAAM,GAAG,UAAU,GAAG,aAAa,GAAG;AAC5C,QAAOD,8BAAAA,cACL,OAAO,GAAG,GAAG,OAAOC,0BAAAA,YAAY,OAAO,QACjC,SAAS,GAAG,EAClB,KACA,aACD;;AAGH,MAAM,iBAAgC,EAAE;AACxC,MAAM,kB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OC,0BAAAA,mBAAmB;CACxC,IAAI,MAAM,OAA2B,MAAM,aAAa,CAAC;AAEzD,eAAc;AAIZ,SAHoB,MAAM,gBAAgB;AACxC,SAAM,MAAM,aAAa;IACzB;GAEF;CAEF,MAAM,cACJ,SAAS,UAAU,GAAI,WAAwC,GAAG;AAEpE,QAAO,EACL,IAAI,UAAuC;EACzC,MAAM,MAAM,OAAO;AACnB,MAAI,OAAO,KAAM,QAAO,KAAA;AACxB,SAAO,IAAI,IAAI,IAAI;IAEtB;;AAuBH,SAAgB,mBACd,QAC0B;CAC1B,MAAM,aAAa,OAAOA,0BAAAA;CAC1B,MAAM,QAAQ,WAAW;CACzB,IAAI,UAAU,OAAgC,MAAM,aAAa,CAAC;AAElE,eAAc;AAIZ,SAHoB,MAAM,gBAAgB;AACxC,aAAU,MAAM,aAAa;IAC7B;GAEF;AAEF,QAAO;EACL,IAAI,UAAU;AACZ,UAAO;;EAET,IAAI,OAAO;AACT,UAAO,QAAQ;;EAEjB,SAAS,OAAO,WAAW,aAAa,GAAG;EAC3C,aAAa,WAAW,YAAY;EACrC"}
|
|
1
|
+
{"version":3,"file":"selectors.svelte.cjs","names":["NAMESPACE_SEPARATOR","STREAM_CONTROLLER","useProjection","getRegistry"],"sources":["../src/selectors.svelte.ts"],"sourcesContent":["import type { BaseMessage } from \"@langchain/core/messages\";\nimport {\n NAMESPACE_SEPARATOR,\n audioProjection,\n channelProjection,\n extensionProjection,\n filesProjection,\n imagesProjection,\n messagesProjection,\n toolCallsProjection,\n valuesProjection,\n videoProjection,\n type AssembledToolCall,\n type AudioMedia,\n type Channel,\n type ChannelProjectionOptions,\n type Event,\n type FileMedia,\n type ImageMedia,\n type InferToolCalls,\n type InferStateType,\n type MessageMetadata,\n type MessageMetadataMap,\n type SubagentDiscoverySnapshot,\n type SubgraphDiscoverySnapshot,\n type SubmissionQueueEntry,\n type SubmissionQueueSnapshot,\n type VideoMedia,\n} from \"@langchain/langgraph-sdk/stream\";\nimport {\n getRegistry,\n STREAM_CONTROLLER,\n type AnyStream,\n type UseStreamReturn,\n} from \"./use-stream.svelte.js\";\nimport {\n useProjection,\n type ReactiveValue,\n type ValueOrGetter,\n} from \"./use-projection.svelte.js\";\n\n/**\n * Parameterise selectors on `StateType` alone so callers with a full\n * `useStream<S, I, C>()` handle don't have to redeclare\n * `InterruptType` / `ConfigurableType` at every call site.\n */\ntype StreamHandle<StateType extends object> = UseStreamReturn<\n StateType,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any\n>;\n\n/**\n * What a selector composable targets. Callers can pass:\n * - `undefined` / `null` — root namespace (served by the always-on\n * root store; no extra subscription opens);\n * - a {@link SubagentDiscoverySnapshot} (`stream.subagents.get(...)`);\n * - a {@link SubgraphDiscoverySnapshot}\n * (`stream.subgraphs.get(...)`);\n * - an explicit `{ namespace: string[] }`;\n * - a raw `string[]` escape hatch.\n */\nexport type SelectorTarget =\n | undefined\n | null\n | readonly string[]\n | { namespace: readonly string[] }\n | SubagentDiscoverySnapshot\n | SubgraphDiscoverySnapshot;\n\nconst EMPTY_NAMESPACE: readonly string[] = [];\n\nfunction resolveNamespace(target: SelectorTarget): readonly string[] {\n if (target == null) return EMPTY_NAMESPACE;\n if (Array.isArray(target)) return target as readonly string[];\n const obj = target as { namespace?: readonly string[] };\n return obj.namespace ?? EMPTY_NAMESPACE;\n}\n\nfunction isRoot(namespace: readonly string[]): boolean {\n return namespace.length === 0;\n}\n\nfunction namespaceKey(namespace: readonly string[]): string {\n return namespace.join(NAMESPACE_SEPARATOR);\n}\n\nfunction isGetter<T>(input: ValueOrGetter<T> | undefined): input is () => T {\n return typeof input === \"function\";\n}\n\n/**\n * If `target` is a subagent snapshot still on its default\n * `tools:<toolCallId>` namespace, return that tool-call id. See the\n * React selectors for the rationale (deep-agent subagents execute under\n * a distinct `tools:<uuid>` namespace resolved lazily from history).\n */\nfunction subagentNeedingNamespace(target: SelectorTarget): string | null {\n if (target == null || Array.isArray(target)) return null;\n const obj = target as { id?: unknown; namespace?: readonly string[] };\n if (typeof obj.id !== \"string\" || !Array.isArray(obj.namespace)) return null;\n if (obj.namespace.length === 1 && obj.namespace[0] === `tools:${obj.id}`) {\n return obj.id;\n }\n return null;\n}\n\n/**\n * Lazily resolve a subagent's execution namespace on first scoped use.\n * Re-evaluates when a reactive `target` changes; the controller\n * de-dupes and skips already-promoted ids.\n */\nfunction useResolveSubagentNamespace(\n stream: AnyStream,\n target: ValueOrGetter<SelectorTarget> | undefined\n): void {\n const controller = stream[STREAM_CONTROLLER];\n $effect(() => {\n const resolved = isGetter(target) ? target() : target;\n const id = subagentNeedingNamespace(resolved);\n if (id != null) void controller.resolveSubagentNamespace(id);\n });\n}\n\n/**\n * Internal helper that wires a reactive-or-static target into\n * {@link useProjection}. Encapsulates the bookkeeping every selector\n * otherwise repeats.\n */\nfunction selectFromTarget<T>(\n stream: AnyStream,\n target: ValueOrGetter<SelectorTarget> | undefined,\n initialValue: T,\n makeSpec: (\n namespace: readonly string[]\n ) => import(\"@langchain/langgraph-sdk/stream\").ProjectionSpec<T>,\n keyPrefix: string\n): ReactiveValue<T> {\n if (isGetter(target)) {\n const getTarget = target;\n return useProjection<T>(\n () => {\n const ns = resolveNamespace(getTarget());\n return isRoot(ns) ? null : getRegistry(stream);\n },\n () => makeSpec(resolveNamespace(getTarget())),\n () => `${keyPrefix}|${namespaceKey(resolveNamespace(getTarget()))}`,\n initialValue\n );\n }\n const ns = resolveNamespace(target);\n // Static root: we deliberately don't short-circuit here because\n // each selector owns the root fallback shape (`stream.messages`\n // vs `stream.values` vs `stream.toolCalls`). Callers use the\n // dedicated wrappers below.\n const key = `${keyPrefix}|${namespaceKey(ns)}`;\n return useProjection<T>(\n isRoot(ns) ? null : getRegistry(stream),\n () => makeSpec(ns),\n key,\n initialValue\n );\n}\n\nconst EMPTY_MESSAGES: BaseMessage[] = [];\nconst EMPTY_TOOLCALLS: AssembledToolCall[] = [];\nconst EMPTY_EVENTS: Event[] = [];\nconst EMPTY_AUDIO: AudioMedia[] = [];\nconst EMPTY_IMAGES: ImageMedia[] = [];\nconst EMPTY_VIDEO: VideoMedia[] = [];\nconst EMPTY_FILES: FileMedia[] = [];\n\n/**\n * Subscribe to a scoped `messages` stream.\n *\n * Contract:\n * - At the root (no `target`, or a static target that resolves to\n * the root namespace) returns a handle whose `.current` delegates\n * to `stream.messages` — the always-on root projection. No extra\n * subscription is opened.\n * - For any non-root namespace, mount triggers a ref-counted\n * `messages` subscription scoped to that namespace. The\n * subscription is released automatically when the owning\n * component teardown fires (and the registry closes the\n * underlying server subscription when the last consumer leaves).\n * - A reactive `target` (getter form) re-binds the subscription on\n * change. A getter that flips between root and scoped is\n * supported: the root case short-circuits to the initial value\n * because dynamic root delegation isn't meaningful — pass a\n * static undefined/null target for root handles.\n *\n * Messages are always `BaseMessage` class instances from\n * `@langchain/core/messages`.\n */\nexport function useMessages(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<BaseMessage[]> {\n useResolveSubagentNamespace(stream, target);\n if (!isGetter(target)) {\n const ns = resolveNamespace(target);\n if (isRoot(ns)) {\n return {\n get current() {\n return stream.messages;\n },\n };\n }\n }\n return selectFromTarget<BaseMessage[]>(\n stream,\n target,\n EMPTY_MESSAGES,\n (ns) => messagesProjection(ns),\n \"messages\"\n );\n}\n\n/**\n * Subscribe to a scoped `tools` (tool-call) stream. Same target and\n * lifecycle rules as {@link useMessages}; at the root this returns a\n * handle delegating to `stream.toolCalls`.\n */\nexport function useToolCalls(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<AssembledToolCall[]>;\nexport function useToolCalls<T>(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<InferToolCalls<T>[]>;\nexport function useToolCalls(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<AssembledToolCall[]> {\n useResolveSubagentNamespace(stream, target);\n if (!isGetter(target)) {\n const ns = resolveNamespace(target);\n if (isRoot(ns)) {\n return {\n get current() {\n return stream.toolCalls;\n },\n };\n }\n }\n return selectFromTarget<AssembledToolCall[]>(\n stream,\n target,\n EMPTY_TOOLCALLS,\n (ns) => toolCallsProjection(ns),\n \"toolCalls\"\n );\n}\n\n/**\n * Subscribe to a scoped `values` stream — the most recent state\n * payload for a namespace. At the root returns a handle delegating\n * to `stream.values`.\n *\n * Typing:\n * - **Root** (`useValues(stream)`): returns the `StateType` declared\n * on `useStream<State>()` — non-nullable (the root snapshot\n * always has values, falling back to `initialValues ?? {}`).\n * - **Scoped** (`useValues(stream, target)`): scoped payloads can\n * differ from the root state; callers should annotate the\n * expected shape explicitly (`useValues<SubagentState>(stream,\n * sub)`). Defaults to `unknown` when not annotated.\n */\nexport function useValues<StateType extends object>(\n stream: StreamHandle<StateType>\n): ReactiveValue<StateType>;\nexport function useValues<T>(\n stream: AnyStream\n): ReactiveValue<InferStateType<T>>;\nexport function useValues<T = unknown>(\n stream: AnyStream,\n target: ValueOrGetter<SelectorTarget>,\n options?: { messagesKey?: string }\n): ReactiveValue<T | undefined>;\nexport function useValues(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>,\n options?: { messagesKey?: string }\n): ReactiveValue<unknown> {\n if (!isGetter(target)) {\n const ns = resolveNamespace(target);\n if (isRoot(ns)) {\n return {\n get current() {\n return stream.values;\n },\n };\n }\n }\n const messagesKey = options?.messagesKey ?? \"messages\";\n return selectFromTarget<unknown>(\n stream,\n target,\n undefined,\n (ns) => valuesProjection<unknown>(ns, messagesKey),\n `values|${messagesKey}`\n );\n}\n\n/**\n * Subscribe to a `custom:<name>` stream extension — most-recent\n * payload emitted by the transformer, scoped to the target namespace.\n *\n * `name` accepts either a plain string or a getter so component\n * state can drive the extension name at runtime.\n */\nexport function useExtension<T = unknown>(\n stream: AnyStream,\n name: ValueOrGetter<string>,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<T | undefined> {\n const getName = () => (isGetter(name) ? (name as () => string)() : name);\n if (isGetter(target)) {\n const getTarget = target;\n return useProjection<T | undefined>(\n () => getRegistry(stream),\n () => extensionProjection<T>(getName(), resolveNamespace(getTarget())),\n () =>\n `extension|${getName()}|${namespaceKey(resolveNamespace(getTarget()))}`,\n undefined\n );\n }\n const ns = resolveNamespace(target);\n return useProjection<T | undefined>(\n getRegistry(stream),\n () => extensionProjection<T>(getName(), ns),\n () => `extension|${getName()}|${namespaceKey(ns)}`,\n undefined\n );\n}\n\n/**\n * Raw-events escape hatch. Subscribes to one or more channels at a\n * namespace and returns a bounded buffer of raw protocol events.\n * Prefer {@link useMessages} / {@link useToolCalls} / {@link useValues}\n * for the common cases.\n */\nexport type UseChannelOptions = ChannelProjectionOptions;\n\nexport function useChannel(\n stream: AnyStream,\n channels: ValueOrGetter<readonly Channel[]>,\n target?: ValueOrGetter<SelectorTarget>,\n options?: UseChannelOptions\n): ReactiveValue<Event[]> {\n const getChannels = () =>\n isGetter(channels) ? (channels as () => readonly Channel[])() : channels;\n const getTarget = () => (isGetter(target) ? target() : target);\n const bufferSize = options?.bufferSize ?? \"default\";\n const replayMode = (options?.replay ?? true) ? \"replay\" : \"live\";\n return useProjection<Event[]>(\n () => getRegistry(stream),\n () =>\n channelProjection(\n getChannels(),\n resolveNamespace(getTarget()),\n options\n ) as unknown as import(\"@langchain/langgraph-sdk/stream\").ProjectionSpec<\n Event[]\n >,\n () => {\n const sortedChannels = [...getChannels()].sort().join(\",\");\n return `channel|${bufferSize}|${replayMode}|${sortedChannels}|${namespaceKey(resolveNamespace(getTarget()))}`;\n },\n EMPTY_EVENTS\n );\n}\n\n/**\n * Subscribe to a scoped audio-media stream. Each handle is yielded\n * on its first matching `content-block-start`, exposes\n * `.partialBytes` for live access, settles `.blob` / `.objectURL` /\n * `.transcript` on `message-finish`, and surfaces errors via\n * `.error`.\n */\nexport function useAudio(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<AudioMedia[]> {\n return selectFromTarget<AudioMedia[]>(\n stream,\n target,\n EMPTY_AUDIO,\n (ns) => audioProjection(ns),\n \"audio\"\n );\n}\n\n/**\n * Subscribe to a scoped image-media stream. Pair with `useMediaURL`\n * for `<img src>`.\n */\nexport function useImages(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<ImageMedia[]> {\n return selectFromTarget<ImageMedia[]>(\n stream,\n target,\n EMPTY_IMAGES,\n (ns) => imagesProjection(ns),\n \"images\"\n );\n}\n\n/**\n * Subscribe to a scoped video-media stream. Pair with `useMediaURL`\n * for `<video src>`.\n */\nexport function useVideo(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<VideoMedia[]> {\n return selectFromTarget<VideoMedia[]>(\n stream,\n target,\n EMPTY_VIDEO,\n (ns) => videoProjection(ns),\n \"video\"\n );\n}\n\n/**\n * Subscribe to a scoped file-media stream. Pair with `useMediaURL`\n * for an `<a download href>` target.\n */\nexport function useFiles(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<FileMedia[]> {\n return selectFromTarget<FileMedia[]>(\n stream,\n target,\n EMPTY_FILES,\n (ns) => filesProjection(ns),\n \"files\"\n );\n}\n\n/**\n * Read metadata recorded for a specific message id — today exposes\n * `parentCheckpointId`, the checkpoint the message was first seen\n * on. Designed for fork / edit flows:\n *\n * ```svelte\n * <script lang=\"ts\">\n * const meta = useMessageMetadata(stream, () => selected?.id);\n * </script>\n * Parent: {meta.current?.parentCheckpointId ?? \"root\"}\n * ```\n *\n * `messageId` accepts a plain string or a getter — the binding\n * re-evaluates whenever the id changes.\n */\nexport function useMessageMetadata(\n stream: AnyStream,\n messageId: ValueOrGetter<string | undefined>\n): ReactiveValue<MessageMetadata | undefined> {\n const store = stream[STREAM_CONTROLLER].messageMetadataStore;\n let map = $state<MessageMetadataMap>(store.getSnapshot());\n\n $effect(() => {\n const unsubscribe = store.subscribe(() => {\n map = store.getSnapshot();\n });\n return unsubscribe;\n });\n\n const getId = () =>\n isGetter(messageId) ? (messageId as () => string | undefined)() : messageId;\n\n return {\n get current(): MessageMetadata | undefined {\n const key = getId();\n if (key == null) return undefined;\n return map.get(key);\n },\n };\n}\n\n/**\n * Reactive handle on the server-side submission queue.\n *\n * Populated when `submit()` is invoked with\n * `multitaskStrategy: \"enqueue\"` while another run is in flight. The\n * returned getters are stable — safe to pass into `{#each}`.\n */\nexport interface UseSubmissionQueueReturn<\n StateType extends object = Record<string, unknown>,\n> {\n readonly entries: SubmissionQueueSnapshot<StateType>;\n readonly size: number;\n cancel(id: string): Promise<boolean>;\n clear(): Promise<void>;\n}\n\nexport function useSubmissionQueue<StateType extends object>(\n stream: StreamHandle<StateType>\n): UseSubmissionQueueReturn<StateType>;\nexport function useSubmissionQueue(stream: AnyStream): UseSubmissionQueueReturn;\nexport function useSubmissionQueue(\n stream: AnyStream\n): UseSubmissionQueueReturn {\n const controller = stream[STREAM_CONTROLLER];\n const store = controller.queueStore;\n let entries = $state<SubmissionQueueSnapshot>(store.getSnapshot());\n\n $effect(() => {\n const unsubscribe = store.subscribe(() => {\n entries = store.getSnapshot();\n });\n return unsubscribe;\n });\n\n return {\n get entries() {\n return entries;\n },\n get size() {\n return entries.length;\n },\n cancel: (id) => controller.cancelQueued(id),\n clear: () => controller.clearQueue(),\n };\n}\n\nexport type { SubmissionQueueEntry, SubmissionQueueSnapshot };\n"],"mappings":";;;;AAwEA,MAAM,kBAAqC,EAAE;AAE7C,SAAS,iBAAiB,QAA2C;AACnE,KAAI,UAAU,KAAM,QAAO;AAC3B,KAAI,MAAM,QAAQ,OAAO,CAAE,QAAO;AAElC,QADY,OACD,aAAa;;AAG1B,SAAS,OAAO,WAAuC;AACrD,QAAO,UAAU,WAAW;;AAG9B,SAAS,aAAa,WAAsC;AAC1D,QAAO,UAAU,KAAKA,gCAAAA,oBAAoB;;AAG5C,SAAS,SAAY,OAAuD;AAC1E,QAAO,OAAO,UAAU;;;;;;;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,cACJ,SAAS,UAAU,GAAI,WAAwC,GAAG;AAEpE,QAAO,EACL,IAAI,UAAuC;EACzC,MAAM,MAAM,OAAO;AACnB,MAAI,OAAO,KAAM,QAAO,KAAA;AACxB,SAAO,IAAI,IAAI,IAAI;IAEtB;;AAuBH,SAAgB,mBACd,QAC0B;CAC1B,MAAM,aAAa,OAAOA,0BAAAA;CAC1B,MAAM,QAAQ,WAAW;CACzB,IAAI,UAAU,OAAgC,MAAM,aAAa,CAAC;AAElE,eAAc;AAIZ,SAHoB,MAAM,gBAAgB;AACxC,aAAU,MAAM,aAAa;IAC7B;GAEF;AAEF,QAAO;EACL,IAAI,UAAU;AACZ,UAAO;;EAET,IAAI,OAAO;AACT,UAAO,QAAQ;;EAEjB,SAAS,OAAO,WAAW,aAAa,GAAG;EAC3C,aAAa,WAAW,YAAY;EACrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.svelte.d.cts","names":[],"sources":["../src/selectors.svelte.ts"],"mappings":";;;;;;;;AAuCoC;;;KAO/B,YAAA,6BAAyC,eAAA,CAC5C,SAAA;;;;;;AAiBF;;;;;KAAY,cAAA;EAIN,SAAA;AAAA,IACF,yBAAA,GACA,yBAAA;;
|
|
1
|
+
{"version":3,"file":"selectors.svelte.d.cts","names":[],"sources":["../src/selectors.svelte.ts"],"mappings":";;;;;;;;AAuCoC;;;KAO/B,YAAA,6BAAyC,eAAA,CAC5C,SAAA;;;;;;AAiBF;;;;;KAAY,cAAA;EAIN,SAAA;AAAA,IACF,yBAAA,GACA,yBAAA;;AA8HJ;;;;;;;;;;;;;;;;;;;AA6BA;;iBA7BgB,WAAA,CACd,MAAA,EAAQ,SAAA,EACR,MAAA,GAAS,aAAA,CAAc,cAAA,IACtB,aAAA,CAAc,WAAA;;;;;;iBA0BD,YAAA,CACd,MAAA,EAAQ,SAAA,EACR,MAAA,GAAS,aAAA,CAAc,cAAA,IACtB,aAAA,CAAc,iBAAA;AAAA,iBACD,YAAA,GA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AA,CACd,MAAA,EAAQ,SAAA,EACR,SAAA,EAAW,aAAA,uBACV,aAAA,CAAc,eAAA;;;;;;;;UA8BA,wBAAA,4BACY,MAAA;EAAA,SAElB,OAAA,EAAS,uBAAA,CAAwB,SAAA;EAAA,SACjC,IAAA;EACT,MAAA,CAAO,EAAA,WAAa,OAAA;EACpB,KAAA,IAAS,OAAA;AAAA;AAAA,iBAGK,kBAAA,0BAAA,CACd,MAAA,EAAQ,YAAA,CAAa,SAAA,IACpB,wBAAA,CAAyB,SAAA;AAAA,iBACZ,kBAAA,CAAmB,MAAA,EAAQ,SAAA,GAAY,wBAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.svelte.d.ts","names":[],"sources":["../src/selectors.svelte.ts"],"mappings":";;;;;;;;AAuCoC;;;KAO/B,YAAA,6BAAyC,eAAA,CAC5C,SAAA;;;;;;AAiBF;;;;;KAAY,cAAA;EAIN,SAAA;AAAA,IACF,yBAAA,GACA,yBAAA;;
|
|
1
|
+
{"version":3,"file":"selectors.svelte.d.ts","names":[],"sources":["../src/selectors.svelte.ts"],"mappings":";;;;;;;;AAuCoC;;;KAO/B,YAAA,6BAAyC,eAAA,CAC5C,SAAA;;;;;;AAiBF;;;;;KAAY,cAAA;EAIN,SAAA;AAAA,IACF,yBAAA,GACA,yBAAA;;AA8HJ;;;;;;;;;;;;;;;;;;;AA6BA;;iBA7BgB,WAAA,CACd,MAAA,EAAQ,SAAA,EACR,MAAA,GAAS,aAAA,CAAc,cAAA,IACtB,aAAA,CAAc,WAAA;;;;;;iBA0BD,YAAA,CACd,MAAA,EAAQ,SAAA,EACR,MAAA,GAAS,aAAA,CAAc,cAAA,IACtB,aAAA,CAAc,iBAAA;AAAA,iBACD,YAAA,GAAA,CACd,MAAA,EAAQ,SAAA,EACR,MAAA,GAAS,aAAA,CAAc,cAAA,IACtB,aAAA,CAAc,cAAA,CAAe,CAAA;;;;;;;;;;AAHhC;;;;;iBA0CgB,SAAA,0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A,CAAwB,SAAA;EAAA,SACjC,IAAA;EACT,MAAA,CAAO,EAAA,WAAa,OAAA;EACpB,KAAA,IAAS,OAAA;AAAA;AAAA,iBAGK,kBAAA,0BAAA,CACd,MAAA,EAAQ,YAAA,CAAa,SAAA,IACpB,wBAAA,CAAyB,SAAA;AAAA,iBACZ,kBAAA,CAAmB,MAAA,EAAQ,SAAA,GAAY,wBAAA"}
|
package/dist/selectors.svelte.js
CHANGED
|
@@ -18,6 +18,31 @@ function isGetter(input) {
|
|
|
18
18
|
return typeof input === "function";
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
|
+
* If `target` is a subagent snapshot still on its default
|
|
22
|
+
* `tools:<toolCallId>` namespace, return that tool-call id. See the
|
|
23
|
+
* React selectors for the rationale (deep-agent subagents execute under
|
|
24
|
+
* a distinct `tools:<uuid>` namespace resolved lazily from history).
|
|
25
|
+
*/
|
|
26
|
+
function subagentNeedingNamespace(target) {
|
|
27
|
+
if (target == null || Array.isArray(target)) return null;
|
|
28
|
+
const obj = target;
|
|
29
|
+
if (typeof obj.id !== "string" || !Array.isArray(obj.namespace)) return null;
|
|
30
|
+
if (obj.namespace.length === 1 && obj.namespace[0] === `tools:${obj.id}`) return obj.id;
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Lazily resolve a subagent's execution namespace on first scoped use.
|
|
35
|
+
* Re-evaluates when a reactive `target` changes; the controller
|
|
36
|
+
* de-dupes and skips already-promoted ids.
|
|
37
|
+
*/
|
|
38
|
+
function useResolveSubagentNamespace(stream, target) {
|
|
39
|
+
const controller = stream[STREAM_CONTROLLER];
|
|
40
|
+
$effect(() => {
|
|
41
|
+
const id = subagentNeedingNamespace(isGetter(target) ? target() : target);
|
|
42
|
+
if (id != null) controller.resolveSubagentNamespace(id);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
21
46
|
* Internal helper that wires a reactive-or-static target into
|
|
22
47
|
* {@link useProjection}. Encapsulates the bookkeeping every selector
|
|
23
48
|
* otherwise repeats.
|
|
@@ -63,6 +88,7 @@ const EMPTY_FILES = [];
|
|
|
63
88
|
* `@langchain/core/messages`.
|
|
64
89
|
*/
|
|
65
90
|
function useMessages(stream, target) {
|
|
91
|
+
useResolveSubagentNamespace(stream, target);
|
|
66
92
|
if (!isGetter(target)) {
|
|
67
93
|
if (isRoot(resolveNamespace(target))) return { get current() {
|
|
68
94
|
return stream.messages;
|
|
@@ -71,6 +97,7 @@ function useMessages(stream, target) {
|
|
|
71
97
|
return selectFromTarget(stream, target, EMPTY_MESSAGES, (ns) => messagesProjection(ns), "messages");
|
|
72
98
|
}
|
|
73
99
|
function useToolCalls(stream, target) {
|
|
100
|
+
useResolveSubagentNamespace(stream, target);
|
|
74
101
|
if (!isGetter(target)) {
|
|
75
102
|
if (isRoot(resolveNamespace(target))) return { get current() {
|
|
76
103
|
return stream.toolCalls;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"selectors.svelte.js","names":[],"sources":["../src/selectors.svelte.ts"],"sourcesContent":["import type { BaseMessage } from \"@langchain/core/messages\";\nimport {\n NAMESPACE_SEPARATOR,\n audioProjection,\n channelProjection,\n extensionProjection,\n filesProjection,\n imagesProjection,\n messagesProjection,\n toolCallsProjection,\n valuesProjection,\n videoProjection,\n type AssembledToolCall,\n type AudioMedia,\n type Channel,\n type ChannelProjectionOptions,\n type Event,\n type FileMedia,\n type ImageMedia,\n type InferToolCalls,\n type InferStateType,\n type MessageMetadata,\n type MessageMetadataMap,\n type SubagentDiscoverySnapshot,\n type SubgraphDiscoverySnapshot,\n type SubmissionQueueEntry,\n type SubmissionQueueSnapshot,\n type VideoMedia,\n} from \"@langchain/langgraph-sdk/stream\";\nimport {\n getRegistry,\n STREAM_CONTROLLER,\n type AnyStream,\n type UseStreamReturn,\n} from \"./use-stream.svelte.js\";\nimport {\n useProjection,\n type ReactiveValue,\n type ValueOrGetter,\n} from \"./use-projection.svelte.js\";\n\n/**\n * Parameterise selectors on `StateType` alone so callers with a full\n * `useStream<S, I, C>()` handle don't have to redeclare\n * `InterruptType` / `ConfigurableType` at every call site.\n */\ntype StreamHandle<StateType extends object> = UseStreamReturn<\n StateType,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any\n>;\n\n/**\n * What a selector composable targets. Callers can pass:\n * - `undefined` / `null` — root namespace (served by the always-on\n * root store; no extra subscription opens);\n * - a {@link SubagentDiscoverySnapshot} (`stream.subagents.get(...)`);\n * - a {@link SubgraphDiscoverySnapshot}\n * (`stream.subgraphs.get(...)`);\n * - an explicit `{ namespace: string[] }`;\n * - a raw `string[]` escape hatch.\n */\nexport type SelectorTarget =\n | undefined\n | null\n | readonly string[]\n | { namespace: readonly string[] }\n | SubagentDiscoverySnapshot\n | SubgraphDiscoverySnapshot;\n\nconst EMPTY_NAMESPACE: readonly string[] = [];\n\nfunction resolveNamespace(target: SelectorTarget): readonly string[] {\n if (target == null) return EMPTY_NAMESPACE;\n if (Array.isArray(target)) return target as readonly string[];\n const obj = target as { namespace?: readonly string[] };\n return obj.namespace ?? EMPTY_NAMESPACE;\n}\n\nfunction isRoot(namespace: readonly string[]): boolean {\n return namespace.length === 0;\n}\n\nfunction namespaceKey(namespace: readonly string[]): string {\n return namespace.join(NAMESPACE_SEPARATOR);\n}\n\nfunction isGetter<T>(input: ValueOrGetter<T> | undefined): input is () => T {\n return typeof input === \"function\";\n}\n\n/**\n * Internal helper that wires a reactive-or-static target into\n * {@link useProjection}. Encapsulates the bookkeeping every selector\n * otherwise repeats.\n */\nfunction selectFromTarget<T>(\n stream: AnyStream,\n target: ValueOrGetter<SelectorTarget> | undefined,\n initialValue: T,\n makeSpec: (\n namespace: readonly string[]\n ) => import(\"@langchain/langgraph-sdk/stream\").ProjectionSpec<T>,\n keyPrefix: string\n): ReactiveValue<T> {\n if (isGetter(target)) {\n const getTarget = target;\n return useProjection<T>(\n () => {\n const ns = resolveNamespace(getTarget());\n return isRoot(ns) ? null : getRegistry(stream);\n },\n () => makeSpec(resolveNamespace(getTarget())),\n () => `${keyPrefix}|${namespaceKey(resolveNamespace(getTarget()))}`,\n initialValue\n );\n }\n const ns = resolveNamespace(target);\n // Static root: we deliberately don't short-circuit here because\n // each selector owns the root fallback shape (`stream.messages`\n // vs `stream.values` vs `stream.toolCalls`). Callers use the\n // dedicated wrappers below.\n const key = `${keyPrefix}|${namespaceKey(ns)}`;\n return useProjection<T>(\n isRoot(ns) ? null : getRegistry(stream),\n () => makeSpec(ns),\n key,\n initialValue\n );\n}\n\nconst EMPTY_MESSAGES: BaseMessage[] = [];\nconst EMPTY_TOOLCALLS: AssembledToolCall[] = [];\nconst EMPTY_EVENTS: Event[] = [];\nconst EMPTY_AUDIO: AudioMedia[] = [];\nconst EMPTY_IMAGES: ImageMedia[] = [];\nconst EMPTY_VIDEO: VideoMedia[] = [];\nconst EMPTY_FILES: FileMedia[] = [];\n\n/**\n * Subscribe to a scoped `messages` stream.\n *\n * Contract:\n * - At the root (no `target`, or a static target that resolves to\n * the root namespace) returns a handle whose `.current` delegates\n * to `stream.messages` — the always-on root projection. No extra\n * subscription is opened.\n * - For any non-root namespace, mount triggers a ref-counted\n * `messages` subscription scoped to that namespace. The\n * subscription is released automatically when the owning\n * component teardown fires (and the registry closes the\n * underlying server subscription when the last consumer leaves).\n * - A reactive `target` (getter form) re-binds the subscription on\n * change. A getter that flips between root and scoped is\n * supported: the root case short-circuits to the initial value\n * because dynamic root delegation isn't meaningful — pass a\n * static undefined/null target for root handles.\n *\n * Messages are always `BaseMessage` class instances from\n * `@langchain/core/messages`.\n */\nexport function useMessages(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<BaseMessage[]> {\n if (!isGetter(target)) {\n const ns = resolveNamespace(target);\n if (isRoot(ns)) {\n return {\n get current() {\n return stream.messages;\n },\n };\n }\n }\n return selectFromTarget<BaseMessage[]>(\n stream,\n target,\n EMPTY_MESSAGES,\n (ns) => messagesProjection(ns),\n \"messages\"\n );\n}\n\n/**\n * Subscribe to a scoped `tools` (tool-call) stream. Same target and\n * lifecycle rules as {@link useMessages}; at the root this returns a\n * handle delegating to `stream.toolCalls`.\n */\nexport function useToolCalls(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<AssembledToolCall[]>;\nexport function useToolCalls<T>(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<InferToolCalls<T>[]>;\nexport function useToolCalls(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<AssembledToolCall[]> {\n if (!isGetter(target)) {\n const ns = resolveNamespace(target);\n if (isRoot(ns)) {\n return {\n get current() {\n return stream.toolCalls;\n },\n };\n }\n }\n return selectFromTarget<AssembledToolCall[]>(\n stream,\n target,\n EMPTY_TOOLCALLS,\n (ns) => toolCallsProjection(ns),\n \"toolCalls\"\n );\n}\n\n/**\n * Subscribe to a scoped `values` stream — the most recent state\n * payload for a namespace. At the root returns a handle delegating\n * to `stream.values`.\n *\n * Typing:\n * - **Root** (`useValues(stream)`): returns the `StateType` declared\n * on `useStream<State>()` — non-nullable (the root snapshot\n * always has values, falling back to `initialValues ?? {}`).\n * - **Scoped** (`useValues(stream, target)`): scoped payloads can\n * differ from the root state; callers should annotate the\n * expected shape explicitly (`useValues<SubagentState>(stream,\n * sub)`). Defaults to `unknown` when not annotated.\n */\nexport function useValues<StateType extends object>(\n stream: StreamHandle<StateType>\n): ReactiveValue<StateType>;\nexport function useValues<T>(\n stream: AnyStream\n): ReactiveValue<InferStateType<T>>;\nexport function useValues<T = unknown>(\n stream: AnyStream,\n target: ValueOrGetter<SelectorTarget>,\n options?: { messagesKey?: string }\n): ReactiveValue<T | undefined>;\nexport function useValues(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>,\n options?: { messagesKey?: string }\n): ReactiveValue<unknown> {\n if (!isGetter(target)) {\n const ns = resolveNamespace(target);\n if (isRoot(ns)) {\n return {\n get current() {\n return stream.values;\n },\n };\n }\n }\n const messagesKey = options?.messagesKey ?? \"messages\";\n return selectFromTarget<unknown>(\n stream,\n target,\n undefined,\n (ns) => valuesProjection<unknown>(ns, messagesKey),\n `values|${messagesKey}`\n );\n}\n\n/**\n * Subscribe to a `custom:<name>` stream extension — most-recent\n * payload emitted by the transformer, scoped to the target namespace.\n *\n * `name` accepts either a plain string or a getter so component\n * state can drive the extension name at runtime.\n */\nexport function useExtension<T = unknown>(\n stream: AnyStream,\n name: ValueOrGetter<string>,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<T | undefined> {\n const getName = () => (isGetter(name) ? (name as () => string)() : name);\n if (isGetter(target)) {\n const getTarget = target;\n return useProjection<T | undefined>(\n () => getRegistry(stream),\n () => extensionProjection<T>(getName(), resolveNamespace(getTarget())),\n () =>\n `extension|${getName()}|${namespaceKey(resolveNamespace(getTarget()))}`,\n undefined\n );\n }\n const ns = resolveNamespace(target);\n return useProjection<T | undefined>(\n getRegistry(stream),\n () => extensionProjection<T>(getName(), ns),\n () => `extension|${getName()}|${namespaceKey(ns)}`,\n undefined\n );\n}\n\n/**\n * Raw-events escape hatch. Subscribes to one or more channels at a\n * namespace and returns a bounded buffer of raw protocol events.\n * Prefer {@link useMessages} / {@link useToolCalls} / {@link useValues}\n * for the common cases.\n */\nexport type UseChannelOptions = ChannelProjectionOptions;\n\nexport function useChannel(\n stream: AnyStream,\n channels: ValueOrGetter<readonly Channel[]>,\n target?: ValueOrGetter<SelectorTarget>,\n options?: UseChannelOptions\n): ReactiveValue<Event[]> {\n const getChannels = () =>\n isGetter(channels) ? (channels as () => readonly Channel[])() : channels;\n const getTarget = () => (isGetter(target) ? target() : target);\n const bufferSize = options?.bufferSize ?? \"default\";\n const replayMode = (options?.replay ?? true) ? \"replay\" : \"live\";\n return useProjection<Event[]>(\n () => getRegistry(stream),\n () =>\n channelProjection(\n getChannels(),\n resolveNamespace(getTarget()),\n options\n ) as unknown as import(\"@langchain/langgraph-sdk/stream\").ProjectionSpec<\n Event[]\n >,\n () => {\n const sortedChannels = [...getChannels()].sort().join(\",\");\n return `channel|${bufferSize}|${replayMode}|${sortedChannels}|${namespaceKey(resolveNamespace(getTarget()))}`;\n },\n EMPTY_EVENTS\n );\n}\n\n/**\n * Subscribe to a scoped audio-media stream. Each handle is yielded\n * on its first matching `content-block-start`, exposes\n * `.partialBytes` for live access, settles `.blob` / `.objectURL` /\n * `.transcript` on `message-finish`, and surfaces errors via\n * `.error`.\n */\nexport function useAudio(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<AudioMedia[]> {\n return selectFromTarget<AudioMedia[]>(\n stream,\n target,\n EMPTY_AUDIO,\n (ns) => audioProjection(ns),\n \"audio\"\n );\n}\n\n/**\n * Subscribe to a scoped image-media stream. Pair with `useMediaURL`\n * for `<img src>`.\n */\nexport function useImages(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<ImageMedia[]> {\n return selectFromTarget<ImageMedia[]>(\n stream,\n target,\n EMPTY_IMAGES,\n (ns) => imagesProjection(ns),\n \"images\"\n );\n}\n\n/**\n * Subscribe to a scoped video-media stream. Pair with `useMediaURL`\n * for `<video src>`.\n */\nexport function useVideo(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<VideoMedia[]> {\n return selectFromTarget<VideoMedia[]>(\n stream,\n target,\n EMPTY_VIDEO,\n (ns) => videoProjection(ns),\n \"video\"\n );\n}\n\n/**\n * Subscribe to a scoped file-media stream. Pair with `useMediaURL`\n * for an `<a download href>` target.\n */\nexport function useFiles(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<FileMedia[]> {\n return selectFromTarget<FileMedia[]>(\n stream,\n target,\n EMPTY_FILES,\n (ns) => filesProjection(ns),\n \"files\"\n );\n}\n\n/**\n * Read metadata recorded for a specific message id — today exposes\n * `parentCheckpointId`, the checkpoint the message was first seen\n * on. Designed for fork / edit flows:\n *\n * ```svelte\n * <script lang=\"ts\">\n * const meta = useMessageMetadata(stream, () => selected?.id);\n * </script>\n * Parent: {meta.current?.parentCheckpointId ?? \"root\"}\n * ```\n *\n * `messageId` accepts a plain string or a getter — the binding\n * re-evaluates whenever the id changes.\n */\nexport function useMessageMetadata(\n stream: AnyStream,\n messageId: ValueOrGetter<string | undefined>\n): ReactiveValue<MessageMetadata | undefined> {\n const store = stream[STREAM_CONTROLLER].messageMetadataStore;\n let map = $state<MessageMetadataMap>(store.getSnapshot());\n\n $effect(() => {\n const unsubscribe = store.subscribe(() => {\n map = store.getSnapshot();\n });\n return unsubscribe;\n });\n\n const getId = () =>\n isGetter(messageId) ? (messageId as () => string | undefined)() : messageId;\n\n return {\n get current(): MessageMetadata | undefined {\n const key = getId();\n if (key == null) return undefined;\n return map.get(key);\n },\n };\n}\n\n/**\n * Reactive handle on the server-side submission queue.\n *\n * Populated when `submit()` is invoked with\n * `multitaskStrategy: \"enqueue\"` while another run is in flight. The\n * returned getters are stable — safe to pass into `{#each}`.\n */\nexport interface UseSubmissionQueueReturn<\n StateType extends object = Record<string, unknown>,\n> {\n readonly entries: SubmissionQueueSnapshot<StateType>;\n readonly size: number;\n cancel(id: string): Promise<boolean>;\n clear(): Promise<void>;\n}\n\nexport function useSubmissionQueue<StateType extends object>(\n stream: StreamHandle<StateType>\n): UseSubmissionQueueReturn<StateType>;\nexport function useSubmissionQueue(stream: AnyStream): UseSubmissionQueueReturn;\nexport function useSubmissionQueue(\n stream: AnyStream\n): UseSubmissionQueueReturn {\n const controller = stream[STREAM_CONTROLLER];\n const store = controller.queueStore;\n let entries = $state<SubmissionQueueSnapshot>(store.getSnapshot());\n\n $effect(() => {\n const unsubscribe = store.subscribe(() => {\n entries = store.getSnapshot();\n });\n return unsubscribe;\n });\n\n return {\n get entries() {\n return entries;\n },\n get size() {\n return entries.length;\n },\n cancel: (id) => controller.cancelQueued(id),\n clear: () => controller.clearQue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EACL,IAAI,UAAU;AACZ,UAAO;;EAET,IAAI,OAAO;AACT,UAAO,QAAQ;;EAEjB,SAAS,OAAO,WAAW,aAAa,GAAG;EAC3C,aAAa,WAAW,YAAY;EACrC"}
|
|
1
|
+
{"version":3,"file":"selectors.svelte.js","names":[],"sources":["../src/selectors.svelte.ts"],"sourcesContent":["import type { BaseMessage } from \"@langchain/core/messages\";\nimport {\n NAMESPACE_SEPARATOR,\n audioProjection,\n channelProjection,\n extensionProjection,\n filesProjection,\n imagesProjection,\n messagesProjection,\n toolCallsProjection,\n valuesProjection,\n videoProjection,\n type AssembledToolCall,\n type AudioMedia,\n type Channel,\n type ChannelProjectionOptions,\n type Event,\n type FileMedia,\n type ImageMedia,\n type InferToolCalls,\n type InferStateType,\n type MessageMetadata,\n type MessageMetadataMap,\n type SubagentDiscoverySnapshot,\n type SubgraphDiscoverySnapshot,\n type SubmissionQueueEntry,\n type SubmissionQueueSnapshot,\n type VideoMedia,\n} from \"@langchain/langgraph-sdk/stream\";\nimport {\n getRegistry,\n STREAM_CONTROLLER,\n type AnyStream,\n type UseStreamReturn,\n} from \"./use-stream.svelte.js\";\nimport {\n useProjection,\n type ReactiveValue,\n type ValueOrGetter,\n} from \"./use-projection.svelte.js\";\n\n/**\n * Parameterise selectors on `StateType` alone so callers with a full\n * `useStream<S, I, C>()` handle don't have to redeclare\n * `InterruptType` / `ConfigurableType` at every call site.\n */\ntype StreamHandle<StateType extends object> = UseStreamReturn<\n StateType,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any\n>;\n\n/**\n * What a selector composable targets. Callers can pass:\n * - `undefined` / `null` — root namespace (served by the always-on\n * root store; no extra subscription opens);\n * - a {@link SubagentDiscoverySnapshot} (`stream.subagents.get(...)`);\n * - a {@link SubgraphDiscoverySnapshot}\n * (`stream.subgraphs.get(...)`);\n * - an explicit `{ namespace: string[] }`;\n * - a raw `string[]` escape hatch.\n */\nexport type SelectorTarget =\n | undefined\n | null\n | readonly string[]\n | { namespace: readonly string[] }\n | SubagentDiscoverySnapshot\n | SubgraphDiscoverySnapshot;\n\nconst EMPTY_NAMESPACE: readonly string[] = [];\n\nfunction resolveNamespace(target: SelectorTarget): readonly string[] {\n if (target == null) return EMPTY_NAMESPACE;\n if (Array.isArray(target)) return target as readonly string[];\n const obj = target as { namespace?: readonly string[] };\n return obj.namespace ?? EMPTY_NAMESPACE;\n}\n\nfunction isRoot(namespace: readonly string[]): boolean {\n return namespace.length === 0;\n}\n\nfunction namespaceKey(namespace: readonly string[]): string {\n return namespace.join(NAMESPACE_SEPARATOR);\n}\n\nfunction isGetter<T>(input: ValueOrGetter<T> | undefined): input is () => T {\n return typeof input === \"function\";\n}\n\n/**\n * If `target` is a subagent snapshot still on its default\n * `tools:<toolCallId>` namespace, return that tool-call id. See the\n * React selectors for the rationale (deep-agent subagents execute under\n * a distinct `tools:<uuid>` namespace resolved lazily from history).\n */\nfunction subagentNeedingNamespace(target: SelectorTarget): string | null {\n if (target == null || Array.isArray(target)) return null;\n const obj = target as { id?: unknown; namespace?: readonly string[] };\n if (typeof obj.id !== \"string\" || !Array.isArray(obj.namespace)) return null;\n if (obj.namespace.length === 1 && obj.namespace[0] === `tools:${obj.id}`) {\n return obj.id;\n }\n return null;\n}\n\n/**\n * Lazily resolve a subagent's execution namespace on first scoped use.\n * Re-evaluates when a reactive `target` changes; the controller\n * de-dupes and skips already-promoted ids.\n */\nfunction useResolveSubagentNamespace(\n stream: AnyStream,\n target: ValueOrGetter<SelectorTarget> | undefined\n): void {\n const controller = stream[STREAM_CONTROLLER];\n $effect(() => {\n const resolved = isGetter(target) ? target() : target;\n const id = subagentNeedingNamespace(resolved);\n if (id != null) void controller.resolveSubagentNamespace(id);\n });\n}\n\n/**\n * Internal helper that wires a reactive-or-static target into\n * {@link useProjection}. Encapsulates the bookkeeping every selector\n * otherwise repeats.\n */\nfunction selectFromTarget<T>(\n stream: AnyStream,\n target: ValueOrGetter<SelectorTarget> | undefined,\n initialValue: T,\n makeSpec: (\n namespace: readonly string[]\n ) => import(\"@langchain/langgraph-sdk/stream\").ProjectionSpec<T>,\n keyPrefix: string\n): ReactiveValue<T> {\n if (isGetter(target)) {\n const getTarget = target;\n return useProjection<T>(\n () => {\n const ns = resolveNamespace(getTarget());\n return isRoot(ns) ? null : getRegistry(stream);\n },\n () => makeSpec(resolveNamespace(getTarget())),\n () => `${keyPrefix}|${namespaceKey(resolveNamespace(getTarget()))}`,\n initialValue\n );\n }\n const ns = resolveNamespace(target);\n // Static root: we deliberately don't short-circuit here because\n // each selector owns the root fallback shape (`stream.messages`\n // vs `stream.values` vs `stream.toolCalls`). Callers use the\n // dedicated wrappers below.\n const key = `${keyPrefix}|${namespaceKey(ns)}`;\n return useProjection<T>(\n isRoot(ns) ? null : getRegistry(stream),\n () => makeSpec(ns),\n key,\n initialValue\n );\n}\n\nconst EMPTY_MESSAGES: BaseMessage[] = [];\nconst EMPTY_TOOLCALLS: AssembledToolCall[] = [];\nconst EMPTY_EVENTS: Event[] = [];\nconst EMPTY_AUDIO: AudioMedia[] = [];\nconst EMPTY_IMAGES: ImageMedia[] = [];\nconst EMPTY_VIDEO: VideoMedia[] = [];\nconst EMPTY_FILES: FileMedia[] = [];\n\n/**\n * Subscribe to a scoped `messages` stream.\n *\n * Contract:\n * - At the root (no `target`, or a static target that resolves to\n * the root namespace) returns a handle whose `.current` delegates\n * to `stream.messages` — the always-on root projection. No extra\n * subscription is opened.\n * - For any non-root namespace, mount triggers a ref-counted\n * `messages` subscription scoped to that namespace. The\n * subscription is released automatically when the owning\n * component teardown fires (and the registry closes the\n * underlying server subscription when the last consumer leaves).\n * - A reactive `target` (getter form) re-binds the subscription on\n * change. A getter that flips between root and scoped is\n * supported: the root case short-circuits to the initial value\n * because dynamic root delegation isn't meaningful — pass a\n * static undefined/null target for root handles.\n *\n * Messages are always `BaseMessage` class instances from\n * `@langchain/core/messages`.\n */\nexport function useMessages(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<BaseMessage[]> {\n useResolveSubagentNamespace(stream, target);\n if (!isGetter(target)) {\n const ns = resolveNamespace(target);\n if (isRoot(ns)) {\n return {\n get current() {\n return stream.messages;\n },\n };\n }\n }\n return selectFromTarget<BaseMessage[]>(\n stream,\n target,\n EMPTY_MESSAGES,\n (ns) => messagesProjection(ns),\n \"messages\"\n );\n}\n\n/**\n * Subscribe to a scoped `tools` (tool-call) stream. Same target and\n * lifecycle rules as {@link useMessages}; at the root this returns a\n * handle delegating to `stream.toolCalls`.\n */\nexport function useToolCalls(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<AssembledToolCall[]>;\nexport function useToolCalls<T>(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<InferToolCalls<T>[]>;\nexport function useToolCalls(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<AssembledToolCall[]> {\n useResolveSubagentNamespace(stream, target);\n if (!isGetter(target)) {\n const ns = resolveNamespace(target);\n if (isRoot(ns)) {\n return {\n get current() {\n return stream.toolCalls;\n },\n };\n }\n }\n return selectFromTarget<AssembledToolCall[]>(\n stream,\n target,\n EMPTY_TOOLCALLS,\n (ns) => toolCallsProjection(ns),\n \"toolCalls\"\n );\n}\n\n/**\n * Subscribe to a scoped `values` stream — the most recent state\n * payload for a namespace. At the root returns a handle delegating\n * to `stream.values`.\n *\n * Typing:\n * - **Root** (`useValues(stream)`): returns the `StateType` declared\n * on `useStream<State>()` — non-nullable (the root snapshot\n * always has values, falling back to `initialValues ?? {}`).\n * - **Scoped** (`useValues(stream, target)`): scoped payloads can\n * differ from the root state; callers should annotate the\n * expected shape explicitly (`useValues<SubagentState>(stream,\n * sub)`). Defaults to `unknown` when not annotated.\n */\nexport function useValues<StateType extends object>(\n stream: StreamHandle<StateType>\n): ReactiveValue<StateType>;\nexport function useValues<T>(\n stream: AnyStream\n): ReactiveValue<InferStateType<T>>;\nexport function useValues<T = unknown>(\n stream: AnyStream,\n target: ValueOrGetter<SelectorTarget>,\n options?: { messagesKey?: string }\n): ReactiveValue<T | undefined>;\nexport function useValues(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>,\n options?: { messagesKey?: string }\n): ReactiveValue<unknown> {\n if (!isGetter(target)) {\n const ns = resolveNamespace(target);\n if (isRoot(ns)) {\n return {\n get current() {\n return stream.values;\n },\n };\n }\n }\n const messagesKey = options?.messagesKey ?? \"messages\";\n return selectFromTarget<unknown>(\n stream,\n target,\n undefined,\n (ns) => valuesProjection<unknown>(ns, messagesKey),\n `values|${messagesKey}`\n );\n}\n\n/**\n * Subscribe to a `custom:<name>` stream extension — most-recent\n * payload emitted by the transformer, scoped to the target namespace.\n *\n * `name` accepts either a plain string or a getter so component\n * state can drive the extension name at runtime.\n */\nexport function useExtension<T = unknown>(\n stream: AnyStream,\n name: ValueOrGetter<string>,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<T | undefined> {\n const getName = () => (isGetter(name) ? (name as () => string)() : name);\n if (isGetter(target)) {\n const getTarget = target;\n return useProjection<T | undefined>(\n () => getRegistry(stream),\n () => extensionProjection<T>(getName(), resolveNamespace(getTarget())),\n () =>\n `extension|${getName()}|${namespaceKey(resolveNamespace(getTarget()))}`,\n undefined\n );\n }\n const ns = resolveNamespace(target);\n return useProjection<T | undefined>(\n getRegistry(stream),\n () => extensionProjection<T>(getName(), ns),\n () => `extension|${getName()}|${namespaceKey(ns)}`,\n undefined\n );\n}\n\n/**\n * Raw-events escape hatch. Subscribes to one or more channels at a\n * namespace and returns a bounded buffer of raw protocol events.\n * Prefer {@link useMessages} / {@link useToolCalls} / {@link useValues}\n * for the common cases.\n */\nexport type UseChannelOptions = ChannelProjectionOptions;\n\nexport function useChannel(\n stream: AnyStream,\n channels: ValueOrGetter<readonly Channel[]>,\n target?: ValueOrGetter<SelectorTarget>,\n options?: UseChannelOptions\n): ReactiveValue<Event[]> {\n const getChannels = () =>\n isGetter(channels) ? (channels as () => readonly Channel[])() : channels;\n const getTarget = () => (isGetter(target) ? target() : target);\n const bufferSize = options?.bufferSize ?? \"default\";\n const replayMode = (options?.replay ?? true) ? \"replay\" : \"live\";\n return useProjection<Event[]>(\n () => getRegistry(stream),\n () =>\n channelProjection(\n getChannels(),\n resolveNamespace(getTarget()),\n options\n ) as unknown as import(\"@langchain/langgraph-sdk/stream\").ProjectionSpec<\n Event[]\n >,\n () => {\n const sortedChannels = [...getChannels()].sort().join(\",\");\n return `channel|${bufferSize}|${replayMode}|${sortedChannels}|${namespaceKey(resolveNamespace(getTarget()))}`;\n },\n EMPTY_EVENTS\n );\n}\n\n/**\n * Subscribe to a scoped audio-media stream. Each handle is yielded\n * on its first matching `content-block-start`, exposes\n * `.partialBytes` for live access, settles `.blob` / `.objectURL` /\n * `.transcript` on `message-finish`, and surfaces errors via\n * `.error`.\n */\nexport function useAudio(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<AudioMedia[]> {\n return selectFromTarget<AudioMedia[]>(\n stream,\n target,\n EMPTY_AUDIO,\n (ns) => audioProjection(ns),\n \"audio\"\n );\n}\n\n/**\n * Subscribe to a scoped image-media stream. Pair with `useMediaURL`\n * for `<img src>`.\n */\nexport function useImages(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<ImageMedia[]> {\n return selectFromTarget<ImageMedia[]>(\n stream,\n target,\n EMPTY_IMAGES,\n (ns) => imagesProjection(ns),\n \"images\"\n );\n}\n\n/**\n * Subscribe to a scoped video-media stream. Pair with `useMediaURL`\n * for `<video src>`.\n */\nexport function useVideo(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<VideoMedia[]> {\n return selectFromTarget<VideoMedia[]>(\n stream,\n target,\n EMPTY_VIDEO,\n (ns) => videoProjection(ns),\n \"video\"\n );\n}\n\n/**\n * Subscribe to a scoped file-media stream. Pair with `useMediaURL`\n * for an `<a download href>` target.\n */\nexport function useFiles(\n stream: AnyStream,\n target?: ValueOrGetter<SelectorTarget>\n): ReactiveValue<FileMedia[]> {\n return selectFromTarget<FileMedia[]>(\n stream,\n target,\n EMPTY_FILES,\n (ns) => filesProjection(ns),\n \"files\"\n );\n}\n\n/**\n * Read metadata recorded for a specific message id — today exposes\n * `parentCheckpointId`, the checkpoint the message was first seen\n * on. Designed for fork / edit flows:\n *\n * ```svelte\n * <script lang=\"ts\">\n * const meta = useMessageMetadata(stream, () => selected?.id);\n * </script>\n * Parent: {meta.current?.parentCheckpointId ?? \"root\"}\n * ```\n *\n * `messageId` accepts a plain string or a getter — the binding\n * re-evaluates whenever the id changes.\n */\nexport function useMessageMetadata(\n stream: AnyStream,\n messageId: ValueOrGetter<string | undefined>\n): ReactiveValue<MessageMetadata | undefined> {\n const store = stream[STREAM_CONTROLLER].messageMetadataStore;\n let map = $state<MessageMetadataMap>(store.getSnapshot());\n\n $effect(() => {\n const unsubscribe = store.subscribe(() => {\n map = store.getSnapshot();\n });\n return unsubscribe;\n });\n\n const getId = () =>\n isGetter(messageId) ? (messageId as () => string | undefined)() : messageId;\n\n return {\n get current(): MessageMetadata | undefined {\n const key = getId();\n if (key == null) return undefined;\n return map.get(key);\n },\n };\n}\n\n/**\n * Reactive handle on the server-side submission queue.\n *\n * Populated when `submit()` is invoked with\n * `multitaskStrategy: \"enqueue\"` while another run is in flight. The\n * returned getters are stable — safe to pass into `{#each}`.\n */\nexport interface UseSubmissionQueueReturn<\n StateType extends object = Record<string, unknown>,\n> {\n readonly entries: SubmissionQueueSnapshot<StateType>;\n readonly size: number;\n cancel(id: string): Promise<boolean>;\n clear(): Promise<void>;\n}\n\nexport function useSubmissionQueue<StateType extends object>(\n stream: StreamHandle<StateType>\n): UseSubmissionQueueReturn<StateType>;\nexport function useSubmissionQueue(stream: AnyStream): UseSubmissionQueueReturn;\nexport function useSubmissionQueue(\n stream: AnyStream\n): UseSubmissionQueueReturn {\n const controller = stream[STREAM_CONTROLLER];\n const store = controller.queueStore;\n let entries = $state<SubmissionQueueSnapshot>(store.getSnapshot());\n\n $effect(() => {\n const unsubscribe = store.subscribe(() => {\n entries = store.getSnapshot();\n });\n return unsubscribe;\n });\n\n return {\n get entries() {\n return entries;\n },\n get size() {\n return entries.length;\n },\n cancel: (id) => controller.cancelQueued(id),\n clear: () => controller.clearQueue(),\n };\n}\n\nexport type { SubmissionQueueEntry, SubmissionQueueSnapshot };\n"],"mappings":";;;;AAwEA,MAAM,kBAAqC,EAAE;AAE7C,SAAS,iBAAiB,QAA2C;AACnE,KAAI,UAAU,KAAM,QAAO;AAC3B,KAAI,MAAM,QAAQ,OAAO,CAAE,QAAO;AAElC,QADY,OACD,aAAa;;AAG1B,SAAS,OAAO,WAAuC;AACrD,QAAO,UAAU,WAAW;;AAG9B,SAAS,aAAa,WAAsC;AAC1D,QAAO,UAAU,KAAK,oBAAoB;;AAG5C,SAAS,SAAY,OAAuD;AAC1E,QAAO,OAAO,UAAU;;;;;;;;AAS1B,SAAS,yBAAyB,QAAuC;AACvE,KAAI,UAAU,QAAQ,MAAM,QAAQ,OAAO,CAAE,QAAO;CACpD,MAAM,MAAM;AACZ,KAAI,OAAO,IAAI,OAAO,YAAY,CAAC,MAAM,QAAQ,IAAI,UAAU,CAAE,QAAO;AACxE,KAAI,IAAI,UAAU,WAAW,KAAK,IAAI,UAAU,OAAO,SAAS,IAAI,KAClE,QAAO,IAAI;AAEb,QAAO;;;;;;;AAQT,SAAS,4BACP,QACA,QACM;CACN,MAAM,aAAa,OAAO;AAC1B,eAAc;EAEZ,MAAM,KAAK,yBADM,SAAS,OAAO,GAAG,QAAQ,GAAG,OACF;AAC7C,MAAI,MAAM,KAAW,YAAW,yBAAyB,GAAG;GAC5D;;;;;;;AAQJ,SAAS,iBACP,QACA,QACA,cACA,UAGA,WACkB;AAClB,KAAI,SAAS,OAAO,EAAE;EACpB,MAAM,YAAY;AAClB,SAAO,oBACC;AAEJ,UAAO,OADI,i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B,QAAO,iBACL,QACA,QACA,cACC,OAAO,gBAAgB,GAAG,EAC3B,QACD;;;;;;AAOH,SAAgB,SACd,QACA,QAC4B;AAC5B,QAAO,iBACL,QACA,QACA,cACC,OAAO,gBAAgB,GAAG,EAC3B,QACD;;;;;;;;;;;;;;;;;AAkBH,SAAgB,mBACd,QACA,WAC4C;CAC5C,MAAM,QAAQ,OAAO,mBAAmB;CACxC,IAAI,MAAM,OAA2B,MAAM,aAAa,CAAC;AAEzD,eAAc;AAIZ,SAHoB,MAAM,gBAAgB;AACxC,SAAM,MAAM,aAAa;IACzB;GAEF;CAEF,MAAM,cACJ,SAAS,UAAU,GAAI,WAAwC,GAAG;AAEpE,QAAO,EACL,IAAI,UAAuC;EACzC,MAAM,MAAM,OAAO;AACnB,MAAI,OAAO,KAAM,QAAO,KAAA;AACxB,SAAO,IAAI,IAAI,IAAI;IAEtB;;AAuBH,SAAgB,mBACd,QAC0B;CAC1B,MAAM,aAAa,OAAO;CAC1B,MAAM,QAAQ,WAAW;CACzB,IAAI,UAAU,OAAgC,MAAM,aAAa,CAAC;AAElE,eAAc;AAIZ,SAHoB,MAAM,gBAAgB;AACxC,aAAU,MAAM,aAAa;IAC7B;GAEF;AAEF,QAAO;EACL,IAAI,UAAU;AACZ,UAAO;;EAET,IAAI,OAAO;AACT,UAAO,QAAQ;;EAEjB,SAAS,OAAO,WAAW,aAAa,GAAG;EAC3C,aAAa,WAAW,YAAY;EACrC"}
|
|
@@ -72,7 +72,8 @@ function useStream(options) {
|
|
|
72
72
|
onCreated: options.onCreated,
|
|
73
73
|
onCompleted: options.onCompleted,
|
|
74
74
|
initialValues: options.initialValues,
|
|
75
|
-
messagesKey: options.messagesKey
|
|
75
|
+
messagesKey: options.messagesKey,
|
|
76
|
+
optimistic: asBag.optimistic
|
|
76
77
|
});
|
|
77
78
|
(0, svelte.onDestroy)(controller.activate());
|
|
78
79
|
let rootSnapshot = $state(controller.rootStore.getSnapshot());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-stream.svelte.cjs","names":["ClientCtor","StreamController"],"sources":["../src/use-stream.svelte.ts"],"sourcesContent":["import { onDestroy } from \"svelte\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type { Client, Interrupt } from \"@langchain/langgraph-sdk\";\nimport {\n applyHeadlessToolResumeCommand,\n flushPendingHeadlessToolInterrupts,\n scheduleCoalescedHeadlessToolFlush,\n type AnyHeadlessToolImplementation,\n type OnToolCallback,\n} from \"@langchain/langgraph-sdk\";\nimport {\n Client as ClientCtor,\n type ClientConfig,\n type ThreadStream,\n} from \"@langchain/langgraph-sdk/client\";\nimport {\n StreamController,\n type AgentServerAdapter,\n type AgentServerOptions as StreamAgentServerOptions,\n type ChannelRegistry,\n type CustomAdapterOptions as StreamCustomAdapterOptions,\n type InferStateType,\n type InferToolCalls,\n type InferSubagentStates,\n type RootSnapshot,\n type RunCompletedInfo,\n type RunExecutionInfo,\n type StreamRespondAllOptions,\n type StreamRespondOptions,\n type StreamStopOptions,\n type StreamSubmitOptions,\n type SubagentDiscoverySnapshot,\n type SubagentMap,\n type SubgraphByNodeMap,\n type SubgraphDiscoverySnapshot,\n type SubgraphMap,\n type UseStreamOptions as StreamUseStreamOptions,\n type WidenUpdateMessages,\n} from \"@langchain/langgraph-sdk/stream\";\n\n/**\n * A value that may be either a plain `T` or a getter `() => T`. Used\n * for reactive-capable option inputs (currently `threadId` only). When\n * a getter is passed the composable tracks it via `$effect` and\n * re-hydrates when the returned value changes.\n */\nexport type ValueOrGetter<T> = T | (() => T);\n\nfunction readValueOrGetter<T>(\n input: ValueOrGetter<T> | undefined\n): T | undefined {\n if (typeof input === \"function\") return (input as () => T)();\n return input;\n}\n\ntype SvelteThreadId = ValueOrGetter<string | null | undefined>;\n\nexport type AgentServerOptions<StateType extends object> =\n StreamAgentServerOptions<StateType, SvelteThreadId>;\n\nexport type CustomAdapterOptions<StateType extends object> =\n StreamCustomAdapterOptions<StateType, SvelteThreadId, string>;\n\nexport type UseStreamOptions<\n StateType extends object = Record<string, unknown>,\n> = StreamUseStreamOptions<\n StateType,\n SvelteThreadId,\n string | undefined,\n string | undefined,\n string\n>;\n\n/**\n * Private field on the handle that carries the {@link StreamController}\n * reference. Selector composables read this to reach the shared\n * {@link ChannelRegistry}. Use the selector composables\n * (`useMessages`, `useToolCalls`, `useValues`, …) instead of reading\n * this directly.\n */\nexport const STREAM_CONTROLLER: unique symbol = Symbol.for(\n \"@langchain/svelte/controller\"\n);\n\n/**\n * Svelte binding return type for {@link useStream}. Reactive\n * projections are exposed as getters on a stable object so templates\n * can read `stream.messages` directly without a `.value` / `.current`\n * hop and `$derived` wrappers auto-track the getter read.\n *\n * Destructuring (`const { messages } = stream`) breaks reactivity —\n * this is a Svelte 5 constraint and applies to every getter-object\n * pattern. Access fields through the live `stream` handle instead.\n */\nexport interface UseStreamReturn<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n StateType extends object = InferStateType<T>,\n SubagentStates = InferSubagentStates<T>,\n> {\n // ----- always-on root projections -----\n /**\n * The most recent `values`-channel snapshot emitted at the root\n * namespace — i.e. the thread-level state as the server sees it\n * after each superstep. Updated on every root `values` event, not\n * on token-level deltas: if you render `stream.values.messages`\n * directly you'll see full turns appear at once instead of\n * streaming token-by-token. Use {@link messages} (or\n * `useMessages`) for the token-streamed view.\n *\n * Equivalent to calling `useValues(stream)`.\n */\n readonly values: StateType;\n /**\n * The root message projection. Assembled from two sources and\n * merged in real time:\n *\n * 1. `messages`-channel deltas — token-level streaming events\n * (`message-start`, `content-block-delta`, `message-finish`)\n * emitted by the runtime. These drive live, token-by-token\n * updates.\n * 2. `values.messages` snapshots — the authoritative ordering\n * and any messages the agent produces without token streaming\n * (human turns, tool results, echoes from subagents).\n *\n * If the backend only emits `values` events (no `messages`\n * channel), every message will appear fully-formed on each\n * values update rather than streaming. This is a backend/runtime\n * concern — the Svelte layer faithfully renders whatever the\n * server sends.\n *\n * Equivalent to calling `useMessages(stream)` with no target.\n */\n readonly messages: BaseMessage[];\n /**\n * Root-namespace tool calls assembled from the `tools` channel.\n * Each entry is a fully parsed {@link AssembledToolCall} with\n * name, args, and id — suitable for rendering approval UIs or\n * forwarding to headless tool handlers.\n *\n * When the stream is typed with an agent brand or tool list,\n * entries are narrowed via {@link InferToolCalls}. Equivalent to\n * calling `useToolCalls(stream)` with no target.\n */\n readonly toolCalls: InferToolCalls<T>[];\n /**\n * All unresolved protocol interrupts observed on the root\n * namespace during the active thread. Populated from lifecycle /\n * input events and seeded on hydration from `thread.getState()`.\n * Cleared optimistically when a new run starts or an interrupt is\n * resolved via {@link respond}.\n */\n readonly interrupts: Interrupt<InterruptType>[];\n /**\n * Convenience alias for {@link interrupts}[0] — the primary\n * interrupt most UIs should act on when only one is pending.\n * `undefined` when no interrupt is active.\n */\n readonly interrupt: Interrupt<InterruptType> | undefined;\n /**\n * `true` while a run is active or being started on the current\n * thread. Driven by root-namespace lifecycle events (`running` →\n * `true`, terminal phases → `false`). Use this to disable submit\n * buttons and show in-flight spinners.\n */\n readonly isLoading: boolean;\n /**\n * `true` while the initial `thread.getState()` hydration for the\n * active thread is in flight. Distinct from {@link isLoading} —\n * thread loading covers the one-time fetch that seeds\n * {@link values} / {@link messages} before any user submit.\n */\n readonly isThreadLoading: boolean;\n /**\n * The last error observed on the active run or hydration attempt.\n * `undefined` when no error has occurred. Cleared optimistically\n * when a new {@link submit} starts.\n */\n readonly error: unknown;\n /**\n * Id of the thread the controller is bound to. `null` until the\n * first {@link submit} creates or selects a thread (or until an\n * explicit `threadId` option is provided and hydrated).\n */\n readonly threadId: string | null;\n /**\n * Promise that settles when the current thread's initial hydration\n * completes. Useful in SvelteKit `load()` handlers (or any\n * async-init site) to block until the controller has reconciled\n * with server-held state. A fresh promise is installed on every\n * `threadId` change.\n */\n readonly hydrationPromise: Promise<void>;\n\n // ----- always-on discovery -----\n /**\n * Subagents discovered on the root run. For DeepAgent-typed\n * streams the key set is narrowed to the subagent names declared\n * on the agent brand (`keyof InferSubagentStates<T>`).\n */\n readonly subagents: ReadonlyMap<\n keyof SubagentStates & string extends never\n ? string\n : keyof SubagentStates & string,\n SubagentDiscoverySnapshot\n >;\n /**\n * Subgraphs discovered on the root run.\n *\n * A namespace is classified as a subgraph iff at least one\n * strictly-deeper namespace has been observed with it as a prefix.\n * This is inferred from the lifecycle event stream — plain function\n * nodes (`orchestrator`, `writer` in the nested-stategraph example)\n * never appear here even though the server emits namespaced\n * lifecycle events for them. Promotion is monotonic and retroactive;\n * an entry appears as soon as the first descendant event lands.\n */\n readonly subgraphs: ReadonlyMap<string, SubgraphDiscoverySnapshot>;\n /**\n * Subgraphs indexed by the graph node that produced them\n * (`addNode(\"visualizer_0\", …)`). Each value is an array because\n * parallel fan-outs and loops can spawn multiple invocations of\n * the same node; arrays preserve insertion order. Updates in\n * lock-step with {@link subgraphs}.\n */\n readonly subgraphsByNode: ReadonlyMap<\n string,\n readonly SubgraphDiscoverySnapshot[]\n >;\n\n // ----- imperatives -----\n /**\n * Dispatch a new run on the bound thread.\n *\n * `input` is typed as `Partial<StateType>` so IDE autocompletion\n * surfaces the state keys declared on the root composable.\n */\n submit(\n input: WidenUpdateMessages<Partial<StateType>> | null | undefined,\n options?: StreamSubmitOptions<StateType, ConfigurableType>\n ): Promise<void>;\n /**\n * Stop the active run on the current thread. By default cancels the\n * run server-side and disconnects the client; pass `{ cancel: false }`\n * or use {@link disconnect} for join/rejoin. Sets {@link isLoading} to\n * `false` immediately; {@link values} and {@link messages} are preserved.\n */\n stop(options?: StreamStopOptions): Promise<void>;\n /**\n * Disconnect the client without cancelling the run server-side.\n * Alias for `stop({ cancel: false })`.\n */\n disconnect(): Promise<void>;\n /**\n * Resume a pending protocol interrupt by sending a response payload\n * back to the interrupted namespace.\n *\n * When `options.interruptId` is omitted, walks `getThread()?.interrupts`\n * from newest to oldest and resumes the first not yet resolved by a prior\n * `respond()` call. That may be a root or subgraph interrupt and is\n * **not** necessarily {@link interrupt} (`interrupts[0]`, root-only).\n * Safe when exactly one interrupt is pending; otherwise pass an explicit\n * `options.interruptId` (and `options.namespace` for subgraph\n * interrupts).\n *\n * The server validates `namespace` against the pending interrupt. Root\n * interrupts use `namespace: []` (default when omitted). For subgraph\n * interrupts, copy `namespace` from `getThread()?.interrupts`.\n *\n * @example\n * ```ts\n * // Single pending interrupt\n * await stream.respond({ approved: true });\n * ```\n *\n * @example\n * ```svelte\n * // Multiple root interrupts\n * {#each stream.interrupts as intr (intr.id)}\n * <button onclick={() => stream.respond(decide(intr.value), { interruptId: intr.id! })}>\n * Resolve\n * </button>\n * {/each}\n * ```\n *\n * @example\n * ```ts\n * // Subgraph interrupt — namespace from `getThread()`\n * const thread = stream.getThread();\n * for (const entry of thread?.interrupts ?? []) {\n * await stream.respond(buildResponse(entry.payload), {\n * interruptId: entry.interruptId,\n * namespace: entry.namespace,\n * });\n * }\n * ```\n *\n * To resume several interrupts pending at the same checkpoint in one\n * command, use {@link respondAll}.\n */\n respond(\n response: unknown,\n options?: StreamRespondOptions<ConfigurableType>\n ): Promise<void>;\n\n /**\n * Resume several pending interrupts at the same checkpoint in a single\n * command — required when a run pauses on multiple interrupts at once\n * (e.g. parallel tool-authorization prompts), which sequential\n * {@link respond} calls cannot handle. `responsesById` maps each pending\n * `interruptId` to its response, so different interrupts can receive\n * different payloads. Pass `options.config` / `options.metadata` to fold\n * run-level config and metadata into the resumed run, mirroring\n * `submit()`.\n *\n * @example\n * ```ts\n * await stream.respondAll({\n * [interruptA.id]: { approved: true },\n * [interruptB.id]: { approved: false },\n * });\n * ```\n */\n respondAll(\n responsesById: Record<string, unknown>,\n options?: StreamRespondAllOptions<ConfigurableType>\n ): Promise<void>;\n\n // ----- identity -----\n /** LangGraph SDK client used to construct thread streams. */\n readonly client: Client;\n /** Assistant id the thread is bound to for its lifetime. */\n readonly assistantId: string;\n\n /**\n * Returns the bound {@link ThreadStream}, if one exists (`undefined`\n * until the thread is hydrated or the first submit completes). Prefer\n * the projections and selector composables for UI work; use this for\n * low-level protocol access (raw subscriptions, state commands, etc.).\n */\n getThread(): ThreadStream | undefined;\n\n /** @internal Used by selector composables. */\n readonly [STREAM_CONTROLLER]: StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >;\n}\n\n/**\n * Erased handle useful as a parameter type for helpers and wrapper\n * components that pass a `stream` through to selector composables\n * without reading `values` directly. Mirrors the React\n * `AnyStream` alias.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyStream = UseStreamReturn<any, any, any>;\n\n/**\n * Svelte 5 binding for the v2-native stream runtime.\n *\n * Returns a handle whose reactive fields are plain getters on a\n * stable object — templates can read `stream.messages` directly and\n * `$derived(stream.isLoading)` auto-tracks the getter.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { useStream } from \"@langchain/svelte\";\n *\n * const stream = useStream({\n * assistantId: \"agent\",\n * apiUrl: \"http://localhost:2024\",\n * });\n * </script>\n *\n * {#each stream.messages as msg (msg.id)}\n * <div>{msg.content}</div>\n * {/each}\n * <button onclick={() =>\n * stream.submit({ messages: [{ type: \"human\", content: \"Hi\" }] })\n * }>\n * Send\n * </button>\n * ```\n *\n * `assistantId`, `client`, and `transport` are captured at composable\n * init. To bind a new assistant/transport, remount the component.\n * Only `threadId` is treated as reactive — pass it as a getter\n * (`threadId: () => active`) to drive an in-place thread swap.\n */\nexport function useStream<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n>(\n options: UseStreamOptions<InferStateType<T>>\n): UseStreamReturn<T, InterruptType, ConfigurableType> {\n type StateType = InferStateType<T>;\n\n interface OptionsBag {\n assistantId?: string;\n threadId?: ValueOrGetter<string | null | undefined>;\n client?: Client;\n apiUrl?: string;\n apiKey?: string;\n callerOptions?: ClientConfig[\"callerOptions\"];\n defaultHeaders?: ClientConfig[\"defaultHeaders\"];\n transport?: \"sse\" | \"websocket\" | AgentServerAdapter;\n fetch?: typeof fetch;\n webSocketFactory?: (url: string) => WebSocket;\n onThreadId?: (threadId: string) => void;\n onCreated?: (info: RunExecutionInfo) => void;\n onCompleted?: (info: RunCompletedInfo) => void;\n initialValues?: StateType;\n messagesKey?: string;\n tools?: AnyHeadlessToolImplementation[];\n onTool?: OnToolCallback;\n }\n const asBag = options as OptionsBag;\n\n const hasCustomAdapter =\n asBag.transport != null && typeof asBag.transport !== \"string\";\n const transport = asBag.transport;\n\n // Client construction — captured once at init. Consumers that need\n // to swap `apiUrl`/`apiKey` at runtime remount the owning component.\n const client: Client =\n asBag.client ??\n (new ClientCtor({\n apiUrl: asBag.apiUrl,\n apiKey: asBag.apiKey,\n callerOptions: asBag.callerOptions,\n defaultHeaders: asBag.defaultHeaders,\n }) as unknown as Client);\n\n // Custom adapters may omit `assistantId`; the controller still\n // requires one so it has something to forward to `threads.stream`.\n const sentinel = \"_\";\n const assistantId =\n \"assistantId\" in options ? (options.assistantId ?? sentinel) : sentinel;\n\n const initialThreadId = readValueOrGetter(asBag.threadId) ?? null;\n\n // Plain `let` binding, not `$state`: the controller holds maps of\n // listeners, Promises, and the live `ThreadStream`, none of which\n // survive Svelte's deep `$state` proxy wrapping.\n const controller = new StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >({\n assistantId,\n // `Client` is state-shape agnostic at runtime; the controller\n // advertises `Client<StateType>` on its public type for ergonomics.\n client: client as unknown as Client<StateType>,\n threadId: initialThreadId,\n transport,\n fetch: hasCustomAdapter ? undefined : asBag.fetch,\n webSocketFactory: hasCustomAdapter ? undefined : asBag.webSocketFactory,\n onThreadId: options.onThreadId,\n onCreated: options.onCreated,\n onCompleted: options.onCompleted,\n initialValues: options.initialValues,\n messagesKey: options.messagesKey,\n });\n\n // Deferred dispose: mirrors React's activate/dispose pattern so HMR\n // and other scope-reuse scenarios stay clean. `activate()` cancels\n // a pending dispose if the owning scope survives.\n const deactivate = controller.activate();\n onDestroy(deactivate);\n\n // ─── Reactive state bridges ─────────────────────────────────────────\n //\n // Each always-on `StreamStore` is wrapped in a runes `$state` slot\n // seeded from `getSnapshot()` and kept in sync via `store.subscribe`.\n // Subscriptions are torn down on component destroy.\n let rootSnapshot = $state<RootSnapshot<StateType, InterruptType>>(\n controller.rootStore.getSnapshot()\n );\n const unsubscribeRoot = controller.rootStore.subscribe(() => {\n rootSnapshot = controller.rootStore.getSnapshot();\n });\n onDestroy(unsubscribeRoot);\n\n let subagentSnapshot = $state<SubagentMap>(\n controller.subagentStore.getSnapshot()\n );\n const unsubscribeSubagents = controller.subagentStore.subscribe(() => {\n subagentSnapshot = controller.subagentStore.getSnapshot();\n });\n onDestroy(unsubscribeSubagents);\n\n let subgraphSnapshot = $state<SubgraphMap>(\n controller.subgraphStore.getSnapshot()\n );\n const unsubscribeSubgraphs = controller.subgraphStore.subscribe(() => {\n subgraphSnapshot = controller.subgraphStore.getSnapshot();\n });\n onDestroy(unsubscribeSubgraphs);\n\n let subgraphByNodeSnapshot = $state<SubgraphByNodeMap>(\n controller.subgraphByNodeStore.getSnapshot()\n );\n const unsubscribeSubgraphByNode = controller.subgraphByNodeStore.subscribe(\n () => {\n subgraphByNodeSnapshot = controller.subgraphByNodeStore.getSnapshot();\n }\n );\n onDestroy(unsubscribeSubgraphByNode);\n\n // ─── threadId reactivity ────────────────────────────────────────────\n //\n // Only matters when the caller passed a getter. The initial hydrate\n // already fired in the controller constructor, so skip the first\n // tick to avoid a redundant `thread.state.get()`.\n if (typeof asBag.threadId === \"function\") {\n const getThreadId = asBag.threadId;\n let previousThreadId = initialThreadId;\n $effect(() => {\n const next = (getThreadId() ?? null) as string | null;\n if (next === previousThreadId) return;\n previousThreadId = next;\n void controller.hydrate(next);\n });\n }\n\n // ─── Headless-tool handling ─────────────────────────────────────────\n //\n // Watch the root `values.__interrupt__` key plus the protocol-\n // surfaced interrupts for items targeting a registered tool, invoke\n // the handler, and resume the run with the handler's return value.\n // Dedup via an id set so rerenders don't replay a tool call twice.\n const tools = options.tools;\n const onTool = options.onTool;\n if (tools?.length) {\n const handledTools = new Set<string>();\n let handledForThreadId: string | null = initialThreadId;\n $effect(() => {\n // Reset dedup set when the active thread id changes — a fresh\n // thread may legitimately re-emit a tool-call id we've seen.\n const currentThreadId = rootSnapshot.threadId;\n if (currentThreadId !== handledForThreadId) {\n handledTools.clear();\n handledForThreadId = currentThreadId;\n }\n\n scheduleCoalescedHeadlessToolFlush(handledTools, () => {\n const valuesBag = rootSnapshot.values as unknown as Record<\n string,\n unknown\n >;\n const protocolInterrupts =\n rootSnapshot.interrupts as unknown as Interrupt[];\n const valuesInterrupts = Array.isArray(valuesBag?.__interrupt__)\n ? (valuesBag.__interrupt__ as Interrupt[])\n : [];\n const headlessInterrupts =\n protocolInterrupts.length > 0 ? protocolInterrupts : valuesInterrupts;\n if (headlessInterrupts.length === 0) return;\n flushPendingHeadlessToolInterrupts(\n { ...valuesBag, __interrupt__: headlessInterrupts },\n tools,\n handledTools,\n {\n onTool,\n defer: (run) => {\n void Promise.resolve().then(run);\n },\n resumeSubmit: (command) =>\n applyHeadlessToolResumeCommand(controller, command),\n }\n );\n });\n });\n }\n\n // ─── Public handle ──────────────────────────────────────────────────\n //\n // Single stable object with getters. Getters read the runes\n // `$state` slots, which drives template reactivity automatically.\n const handle: UseStreamReturn<T, InterruptType, ConfigurableType> = {\n get values() {\n return rootSnapshot.values;\n },\n get messages() {\n return rootSnapshot.messages;\n },\n get toolCalls() {\n return rootSnapshot.toolCalls as InferToolCalls<T>[];\n },\n get interrupts() {\n return rootSnapshot.interrupts;\n },\n get interrupt() {\n return rootSnapshot.interrupt;\n },\n get isLoading() {\n return rootSnapshot.isLoading;\n },\n get isThreadLoading() {\n return rootSnapshot.isThreadLoading;\n },\n get error() {\n return rootSnapshot.error;\n },\n get threadId() {\n return rootSnapshot.threadId;\n },\n get hydrationPromise() {\n return controller.hydrationPromise;\n },\n get subagents() {\n return subagentSnapshot as UseStreamReturn<\n T,\n InterruptType,\n ConfigurableType\n >[\"subagents\"];\n },\n get subgraphs() {\n return subgraphSnapshot;\n },\n get subgraphsByNode() {\n return subgraphByNodeSnapshot;\n },\n submit: (input, submitOptions) => controller.submit(input, submitOptions),\n stop: (options) => controller.stop(options),\n disconnect: () => controller.disconnect(),\n respond: (response, options) => controller.respond(response, options),\n respondAll: (responsesById, options) =>\n controller.respondAll(responsesById, options),\n getThread: () => controller.getThread(),\n client,\n assistantId,\n [STREAM_CONTROLLER]: controller,\n };\n\n return handle;\n}\n\n/** Convenience alias for the fully-resolved stream handle type. */\nexport type UseStreamResult<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> = UseStreamReturn<T, InterruptType, ConfigurableType>;\n\n/**\n * Helper used by the selector composables to reach the underlying\n * {@link ChannelRegistry} from a stream handle. Kept internal —\n * application code should call `useMessages`, `useToolCalls`, etc.\n *\n * @internal\n */\nexport function getRegistry(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n stream: UseStreamReturn<any, any, any>\n): ChannelRegistry {\n return stream[STREAM_CONTROLLER].registry;\n}\n\nexport type { ThreadStream };\n"],"mappings":";;;;;AAgDA,SAAS,kBACP,OACe;AACf,KAAI,OAAO,UAAU,WAAY,QAAQ,OAAmB;AAC5D,QAAO;;;;;;;;;AA4BT,MAAa,oBAAmC,OAAO,IACrD,+BACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuTD,SAAgB,UAKd,SACqD;CAsBrD,MAAM,QAAQ;CAEd,MAAM,mBACJ,MAAM,aAAa,QAAQ,OAAO,MAAM,cAAc;CACxD,MAAM,YAAY,MAAM;CAIxB,MAAM,SACJ,MAAM,UACL,IAAIA,gCAAAA,OAAW;EACd,QAAQ,MAAM;EACd,QAAQ,MAAM;EACd,eAAe,MAAM;EACrB,gBAAgB,MAAM;EACvB,CAAC;CAIJ,MAAM,WAAW;CACjB,MAAM,cACJ,iBAAiB,UAAW,QAAQ,eAAe,WAAY;CAEjE,MAAM,kBAAkB,kBAAkB,MAAM,SAAS,IAAI;CAK7D,M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C1B,WAAW,WAAW,eAAe,QAAQ;EAC/C,iBAAiB,WAAW,WAAW;EACvC;EACA;GACC,oBAAoB;EACtB;;;;;;;;;AAmBH,SAAgB,YAEd,QACiB;AACjB,QAAO,OAAO,mBAAmB"}
|
|
1
|
+
{"version":3,"file":"use-stream.svelte.cjs","names":["ClientCtor","StreamController"],"sources":["../src/use-stream.svelte.ts"],"sourcesContent":["import { onDestroy } from \"svelte\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type { Client, Interrupt } from \"@langchain/langgraph-sdk\";\nimport {\n applyHeadlessToolResumeCommand,\n flushPendingHeadlessToolInterrupts,\n scheduleCoalescedHeadlessToolFlush,\n type AnyHeadlessToolImplementation,\n type OnToolCallback,\n} from \"@langchain/langgraph-sdk\";\nimport {\n Client as ClientCtor,\n type ClientConfig,\n type ThreadStream,\n} from \"@langchain/langgraph-sdk/client\";\nimport {\n StreamController,\n type AgentServerAdapter,\n type AgentServerOptions as StreamAgentServerOptions,\n type ChannelRegistry,\n type CustomAdapterOptions as StreamCustomAdapterOptions,\n type InferStateType,\n type InferToolCalls,\n type InferSubagentStates,\n type RootSnapshot,\n type RunCompletedInfo,\n type RunExecutionInfo,\n type StreamRespondAllOptions,\n type StreamRespondOptions,\n type StreamStopOptions,\n type StreamSubmitOptions,\n type SubagentDiscoverySnapshot,\n type SubagentMap,\n type SubgraphByNodeMap,\n type SubgraphDiscoverySnapshot,\n type SubgraphMap,\n type UseStreamOptions as StreamUseStreamOptions,\n type WidenUpdateMessages,\n} from \"@langchain/langgraph-sdk/stream\";\n\n/**\n * A value that may be either a plain `T` or a getter `() => T`. Used\n * for reactive-capable option inputs (currently `threadId` only). When\n * a getter is passed the composable tracks it via `$effect` and\n * re-hydrates when the returned value changes.\n */\nexport type ValueOrGetter<T> = T | (() => T);\n\nfunction readValueOrGetter<T>(\n input: ValueOrGetter<T> | undefined\n): T | undefined {\n if (typeof input === \"function\") return (input as () => T)();\n return input;\n}\n\ntype SvelteThreadId = ValueOrGetter<string | null | undefined>;\n\nexport type AgentServerOptions<StateType extends object> =\n StreamAgentServerOptions<StateType, SvelteThreadId>;\n\nexport type CustomAdapterOptions<StateType extends object> =\n StreamCustomAdapterOptions<StateType, SvelteThreadId, string>;\n\nexport type UseStreamOptions<\n StateType extends object = Record<string, unknown>,\n> = StreamUseStreamOptions<\n StateType,\n SvelteThreadId,\n string | undefined,\n string | undefined,\n string\n>;\n\n/**\n * Private field on the handle that carries the {@link StreamController}\n * reference. Selector composables read this to reach the shared\n * {@link ChannelRegistry}. Use the selector composables\n * (`useMessages`, `useToolCalls`, `useValues`, …) instead of reading\n * this directly.\n */\nexport const STREAM_CONTROLLER: unique symbol = Symbol.for(\n \"@langchain/svelte/controller\"\n);\n\n/**\n * Svelte binding return type for {@link useStream}. Reactive\n * projections are exposed as getters on a stable object so templates\n * can read `stream.messages` directly without a `.value` / `.current`\n * hop and `$derived` wrappers auto-track the getter read.\n *\n * Destructuring (`const { messages } = stream`) breaks reactivity —\n * this is a Svelte 5 constraint and applies to every getter-object\n * pattern. Access fields through the live `stream` handle instead.\n */\nexport interface UseStreamReturn<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n StateType extends object = InferStateType<T>,\n SubagentStates = InferSubagentStates<T>,\n> {\n // ----- always-on root projections -----\n /**\n * The most recent `values`-channel snapshot emitted at the root\n * namespace — i.e. the thread-level state as the server sees it\n * after each superstep. Updated on every root `values` event, not\n * on token-level deltas: if you render `stream.values.messages`\n * directly you'll see full turns appear at once instead of\n * streaming token-by-token. Use {@link messages} (or\n * `useMessages`) for the token-streamed view.\n *\n * Equivalent to calling `useValues(stream)`.\n */\n readonly values: StateType;\n /**\n * The root message projection. Assembled from two sources and\n * merged in real time:\n *\n * 1. `messages`-channel deltas — token-level streaming events\n * (`message-start`, `content-block-delta`, `message-finish`)\n * emitted by the runtime. These drive live, token-by-token\n * updates.\n * 2. `values.messages` snapshots — the authoritative ordering\n * and any messages the agent produces without token streaming\n * (human turns, tool results, echoes from subagents).\n *\n * If the backend only emits `values` events (no `messages`\n * channel), every message will appear fully-formed on each\n * values update rather than streaming. This is a backend/runtime\n * concern — the Svelte layer faithfully renders whatever the\n * server sends.\n *\n * Equivalent to calling `useMessages(stream)` with no target.\n */\n readonly messages: BaseMessage[];\n /**\n * Root-namespace tool calls assembled from the `tools` channel.\n * Each entry is a fully parsed {@link AssembledToolCall} with\n * name, args, and id — suitable for rendering approval UIs or\n * forwarding to headless tool handlers.\n *\n * When the stream is typed with an agent brand or tool list,\n * entries are narrowed via {@link InferToolCalls}. Equivalent to\n * calling `useToolCalls(stream)` with no target.\n */\n readonly toolCalls: InferToolCalls<T>[];\n /**\n * All unresolved protocol interrupts observed on the root\n * namespace during the active thread. Populated from lifecycle /\n * input events and seeded on hydration from `thread.getState()`.\n * Cleared optimistically when a new run starts or an interrupt is\n * resolved via {@link respond}.\n */\n readonly interrupts: Interrupt<InterruptType>[];\n /**\n * Convenience alias for {@link interrupts}[0] — the primary\n * interrupt most UIs should act on when only one is pending.\n * `undefined` when no interrupt is active.\n */\n readonly interrupt: Interrupt<InterruptType> | undefined;\n /**\n * `true` while a run is active or being started on the current\n * thread. Driven by root-namespace lifecycle events (`running` →\n * `true`, terminal phases → `false`). Use this to disable submit\n * buttons and show in-flight spinners.\n */\n readonly isLoading: boolean;\n /**\n * `true` while the initial `thread.getState()` hydration for the\n * active thread is in flight. Distinct from {@link isLoading} —\n * thread loading covers the one-time fetch that seeds\n * {@link values} / {@link messages} before any user submit.\n */\n readonly isThreadLoading: boolean;\n /**\n * The last error observed on the active run or hydration attempt.\n * `undefined` when no error has occurred. Cleared optimistically\n * when a new {@link submit} starts.\n */\n readonly error: unknown;\n /**\n * Id of the thread the controller is bound to. `null` until the\n * first {@link submit} creates or selects a thread (or until an\n * explicit `threadId` option is provided and hydrated).\n */\n readonly threadId: string | null;\n /**\n * Promise that settles when the current thread's initial hydration\n * completes. Useful in SvelteKit `load()` handlers (or any\n * async-init site) to block until the controller has reconciled\n * with server-held state. A fresh promise is installed on every\n * `threadId` change.\n */\n readonly hydrationPromise: Promise<void>;\n\n // ----- always-on discovery -----\n /**\n * Subagents discovered on the root run. For DeepAgent-typed\n * streams the key set is narrowed to the subagent names declared\n * on the agent brand (`keyof InferSubagentStates<T>`).\n */\n readonly subagents: ReadonlyMap<\n keyof SubagentStates & string extends never\n ? string\n : keyof SubagentStates & string,\n SubagentDiscoverySnapshot\n >;\n /**\n * Subgraphs discovered on the root run.\n *\n * A namespace is classified as a subgraph iff at least one\n * strictly-deeper namespace has been observed with it as a prefix.\n * This is inferred from the lifecycle event stream — plain function\n * nodes (`orchestrator`, `writer` in the nested-stategraph example)\n * never appear here even though the server emits namespaced\n * lifecycle events for them. Promotion is monotonic and retroactive;\n * an entry appears as soon as the first descendant event lands.\n */\n readonly subgraphs: ReadonlyMap<string, SubgraphDiscoverySnapshot>;\n /**\n * Subgraphs indexed by the graph node that produced them\n * (`addNode(\"visualizer_0\", …)`). Each value is an array because\n * parallel fan-outs and loops can spawn multiple invocations of\n * the same node; arrays preserve insertion order. Updates in\n * lock-step with {@link subgraphs}.\n */\n readonly subgraphsByNode: ReadonlyMap<\n string,\n readonly SubgraphDiscoverySnapshot[]\n >;\n\n // ----- imperatives -----\n /**\n * Dispatch a new run on the bound thread.\n *\n * `input` is typed as `Partial<StateType>` so IDE autocompletion\n * surfaces the state keys declared on the root composable.\n */\n submit(\n input: WidenUpdateMessages<Partial<StateType>> | null | undefined,\n options?: StreamSubmitOptions<StateType, ConfigurableType>\n ): Promise<void>;\n /**\n * Stop the active run on the current thread. By default cancels the\n * run server-side and disconnects the client; pass `{ cancel: false }`\n * or use {@link disconnect} for join/rejoin. Sets {@link isLoading} to\n * `false` immediately; {@link values} and {@link messages} are preserved.\n */\n stop(options?: StreamStopOptions): Promise<void>;\n /**\n * Disconnect the client without cancelling the run server-side.\n * Alias for `stop({ cancel: false })`.\n */\n disconnect(): Promise<void>;\n /**\n * Resume a pending protocol interrupt by sending a response payload\n * back to the interrupted namespace.\n *\n * When `options.interruptId` is omitted, walks `getThread()?.interrupts`\n * from newest to oldest and resumes the first not yet resolved by a prior\n * `respond()` call. That may be a root or subgraph interrupt and is\n * **not** necessarily {@link interrupt} (`interrupts[0]`, root-only).\n * Safe when exactly one interrupt is pending; otherwise pass an explicit\n * `options.interruptId` (and `options.namespace` for subgraph\n * interrupts).\n *\n * The server validates `namespace` against the pending interrupt. Root\n * interrupts use `namespace: []` (default when omitted). For subgraph\n * interrupts, copy `namespace` from `getThread()?.interrupts`.\n *\n * @example\n * ```ts\n * // Single pending interrupt\n * await stream.respond({ approved: true });\n * ```\n *\n * @example\n * ```svelte\n * // Multiple root interrupts\n * {#each stream.interrupts as intr (intr.id)}\n * <button onclick={() => stream.respond(decide(intr.value), { interruptId: intr.id! })}>\n * Resolve\n * </button>\n * {/each}\n * ```\n *\n * @example\n * ```ts\n * // Subgraph interrupt — namespace from `getThread()`\n * const thread = stream.getThread();\n * for (const entry of thread?.interrupts ?? []) {\n * await stream.respond(buildResponse(entry.payload), {\n * interruptId: entry.interruptId,\n * namespace: entry.namespace,\n * });\n * }\n * ```\n *\n * To resume several interrupts pending at the same checkpoint in one\n * command, use {@link respondAll}.\n */\n respond(\n response: unknown,\n options?: StreamRespondOptions<ConfigurableType>\n ): Promise<void>;\n\n /**\n * Resume several pending interrupts at the same checkpoint in a single\n * command — required when a run pauses on multiple interrupts at once\n * (e.g. parallel tool-authorization prompts), which sequential\n * {@link respond} calls cannot handle. `responsesById` maps each pending\n * `interruptId` to its response, so different interrupts can receive\n * different payloads. Pass `options.config` / `options.metadata` to fold\n * run-level config and metadata into the resumed run, mirroring\n * `submit()`.\n *\n * @example\n * ```ts\n * await stream.respondAll({\n * [interruptA.id]: { approved: true },\n * [interruptB.id]: { approved: false },\n * });\n * ```\n */\n respondAll(\n responsesById: Record<string, unknown>,\n options?: StreamRespondAllOptions<ConfigurableType>\n ): Promise<void>;\n\n // ----- identity -----\n /** LangGraph SDK client used to construct thread streams. */\n readonly client: Client;\n /** Assistant id the thread is bound to for its lifetime. */\n readonly assistantId: string;\n\n /**\n * Returns the bound {@link ThreadStream}, if one exists (`undefined`\n * until the thread is hydrated or the first submit completes). Prefer\n * the projections and selector composables for UI work; use this for\n * low-level protocol access (raw subscriptions, state commands, etc.).\n */\n getThread(): ThreadStream | undefined;\n\n /** @internal Used by selector composables. */\n readonly [STREAM_CONTROLLER]: StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >;\n}\n\n/**\n * Erased handle useful as a parameter type for helpers and wrapper\n * components that pass a `stream` through to selector composables\n * without reading `values` directly. Mirrors the React\n * `AnyStream` alias.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyStream = UseStreamReturn<any, any, any>;\n\n/**\n * Svelte 5 binding for the v2-native stream runtime.\n *\n * Returns a handle whose reactive fields are plain getters on a\n * stable object — templates can read `stream.messages` directly and\n * `$derived(stream.isLoading)` auto-tracks the getter.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { useStream } from \"@langchain/svelte\";\n *\n * const stream = useStream({\n * assistantId: \"agent\",\n * apiUrl: \"http://localhost:2024\",\n * });\n * </script>\n *\n * {#each stream.messages as msg (msg.id)}\n * <div>{msg.content}</div>\n * {/each}\n * <button onclick={() =>\n * stream.submit({ messages: [{ type: \"human\", content: \"Hi\" }] })\n * }>\n * Send\n * </button>\n * ```\n *\n * `assistantId`, `client`, and `transport` are captured at composable\n * init. To bind a new assistant/transport, remount the component.\n * Only `threadId` is treated as reactive — pass it as a getter\n * (`threadId: () => active`) to drive an in-place thread swap.\n */\nexport function useStream<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n>(\n options: UseStreamOptions<InferStateType<T>>\n): UseStreamReturn<T, InterruptType, ConfigurableType> {\n type StateType = InferStateType<T>;\n\n interface OptionsBag {\n assistantId?: string;\n threadId?: ValueOrGetter<string | null | undefined>;\n client?: Client;\n apiUrl?: string;\n apiKey?: string;\n callerOptions?: ClientConfig[\"callerOptions\"];\n defaultHeaders?: ClientConfig[\"defaultHeaders\"];\n transport?: \"sse\" | \"websocket\" | AgentServerAdapter;\n fetch?: typeof fetch;\n webSocketFactory?: (url: string) => WebSocket;\n onThreadId?: (threadId: string) => void;\n onCreated?: (info: RunExecutionInfo) => void;\n onCompleted?: (info: RunCompletedInfo) => void;\n initialValues?: StateType;\n messagesKey?: string;\n tools?: AnyHeadlessToolImplementation[];\n onTool?: OnToolCallback;\n optimistic?: boolean;\n }\n const asBag = options as OptionsBag;\n\n const hasCustomAdapter =\n asBag.transport != null && typeof asBag.transport !== \"string\";\n const transport = asBag.transport;\n\n // Client construction — captured once at init. Consumers that need\n // to swap `apiUrl`/`apiKey` at runtime remount the owning component.\n const client: Client =\n asBag.client ??\n (new ClientCtor({\n apiUrl: asBag.apiUrl,\n apiKey: asBag.apiKey,\n callerOptions: asBag.callerOptions,\n defaultHeaders: asBag.defaultHeaders,\n }) as unknown as Client);\n\n // Custom adapters may omit `assistantId`; the controller still\n // requires one so it has something to forward to `threads.stream`.\n const sentinel = \"_\";\n const assistantId =\n \"assistantId\" in options ? (options.assistantId ?? sentinel) : sentinel;\n\n const initialThreadId = readValueOrGetter(asBag.threadId) ?? null;\n\n // Plain `let` binding, not `$state`: the controller holds maps of\n // listeners, Promises, and the live `ThreadStream`, none of which\n // survive Svelte's deep `$state` proxy wrapping.\n const controller = new StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >({\n assistantId,\n // `Client` is state-shape agnostic at runtime; the controller\n // advertises `Client<StateType>` on its public type for ergonomics.\n client: client as unknown as Client<StateType>,\n threadId: initialThreadId,\n transport,\n fetch: hasCustomAdapter ? undefined : asBag.fetch,\n webSocketFactory: hasCustomAdapter ? undefined : asBag.webSocketFactory,\n onThreadId: options.onThreadId,\n onCreated: options.onCreated,\n onCompleted: options.onCompleted,\n initialValues: options.initialValues,\n messagesKey: options.messagesKey,\n optimistic: asBag.optimistic,\n });\n\n // Deferred dispose: mirrors React's activate/dispose pattern so HMR\n // and other scope-reuse scenarios stay clean. `activate()` cancels\n // a pending dispose if the owning scope survives.\n const deactivate = controller.activate();\n onDestroy(deactivate);\n\n // ─── Reactive state bridges ─────────────────────────────────────────\n //\n // Each always-on `StreamStore` is wrapped in a runes `$state` slot\n // seeded from `getSnapshot()` and kept in sync via `store.subscribe`.\n // Subscriptions are torn down on component destroy.\n let rootSnapshot = $state<RootSnapshot<StateType, InterruptType>>(\n controller.rootStore.getSnapshot()\n );\n const unsubscribeRoot = controller.rootStore.subscribe(() => {\n rootSnapshot = controller.rootStore.getSnapshot();\n });\n onDestroy(unsubscribeRoot);\n\n let subagentSnapshot = $state<SubagentMap>(\n controller.subagentStore.getSnapshot()\n );\n const unsubscribeSubagents = controller.subagentStore.subscribe(() => {\n subagentSnapshot = controller.subagentStore.getSnapshot();\n });\n onDestroy(unsubscribeSubagents);\n\n let subgraphSnapshot = $state<SubgraphMap>(\n controller.subgraphStore.getSnapshot()\n );\n const unsubscribeSubgraphs = controller.subgraphStore.subscribe(() => {\n subgraphSnapshot = controller.subgraphStore.getSnapshot();\n });\n onDestroy(unsubscribeSubgraphs);\n\n let subgraphByNodeSnapshot = $state<SubgraphByNodeMap>(\n controller.subgraphByNodeStore.getSnapshot()\n );\n const unsubscribeSubgraphByNode = controller.subgraphByNodeStore.subscribe(\n () => {\n subgraphByNodeSnapshot = controller.subgraphByNodeStore.getSnapshot();\n }\n );\n onDestroy(unsubscribeSubgraphByNode);\n\n // ─── threadId reactivity ────────────────────────────────────────────\n //\n // Only matters when the caller passed a getter. The initial hydrate\n // already fired in the controller constructor, so skip the first\n // tick to avoid a redundant `thread.state.get()`.\n if (typeof asBag.threadId === \"function\") {\n const getThreadId = asBag.threadId;\n let previousThreadId = initialThreadId;\n $effect(() => {\n const next = (getThreadId() ?? null) as string | null;\n if (next === previousThreadId) return;\n previousThreadId = next;\n void controller.hydrate(next);\n });\n }\n\n // ─── Headless-tool handling ─────────────────────────────────────────\n //\n // Watch the root `values.__interrupt__` key plus the protocol-\n // surfaced interrupts for items targeting a registered tool, invoke\n // the handler, and resume the run with the handler's return value.\n // Dedup via an id set so rerenders don't replay a tool call twice.\n const tools = options.tools;\n const onTool = options.onTool;\n if (tools?.length) {\n const handledTools = new Set<string>();\n let handledForThreadId: string | null = initialThreadId;\n $effect(() => {\n // Reset dedup set when the active thread id changes — a fresh\n // thread may legitimately re-emit a tool-call id we've seen.\n const currentThreadId = rootSnapshot.threadId;\n if (currentThreadId !== handledForThreadId) {\n handledTools.clear();\n handledForThreadId = currentThreadId;\n }\n\n scheduleCoalescedHeadlessToolFlush(handledTools, () => {\n const valuesBag = rootSnapshot.values as unknown as Record<\n string,\n unknown\n >;\n const protocolInterrupts =\n rootSnapshot.interrupts as unknown as Interrupt[];\n const valuesInterrupts = Array.isArray(valuesBag?.__interrupt__)\n ? (valuesBag.__interrupt__ as Interrupt[])\n : [];\n const headlessInterrupts =\n protocolInterrupts.length > 0 ? protocolInterrupts : valuesInterrupts;\n if (headlessInterrupts.length === 0) return;\n flushPendingHeadlessToolInterrupts(\n { ...valuesBag, __interrupt__: headlessInterrupts },\n tools,\n handledTools,\n {\n onTool,\n defer: (run) => {\n void Promise.resolve().then(run);\n },\n resumeSubmit: (command) =>\n applyHeadlessToolResumeCommand(controller, command),\n }\n );\n });\n });\n }\n\n // ─── Public handle ──────────────────────────────────────────────────\n //\n // Single stable object with getters. Getters read the runes\n // `$state` slots, which drives template reactivity automatically.\n const handle: UseStreamReturn<T, InterruptType, ConfigurableType> = {\n get values() {\n return rootSnapshot.values;\n },\n get messages() {\n return rootSnapshot.messages;\n },\n get toolCalls() {\n return rootSnapshot.toolCalls as InferToolCalls<T>[];\n },\n get interrupts() {\n return rootSnapshot.interrupts;\n },\n get interrupt() {\n return rootSnapshot.interrupt;\n },\n get isLoading() {\n return rootSnapshot.isLoading;\n },\n get isThreadLoading() {\n return rootSnapshot.isThreadLoading;\n },\n get error() {\n return rootSnapshot.error;\n },\n get threadId() {\n return rootSnapshot.threadId;\n },\n get hydrationPromise() {\n return controller.hydrationPromise;\n },\n get subagents() {\n return subagentSnapshot as UseStreamReturn<\n T,\n InterruptType,\n ConfigurableType\n >[\"subagents\"];\n },\n get subgraphs() {\n return subgraphSnapshot;\n },\n get subgraphsByNode() {\n return subgraphByNodeSnapshot;\n },\n submit: (input, submitOptions) => controller.submit(input, submitOptions),\n stop: (options) => controller.stop(options),\n disconnect: () => controller.disconnect(),\n respond: (response, options) => controller.respond(response, options),\n respondAll: (responsesById, options) =>\n controller.respondAll(responsesById, options),\n getThread: () => controller.getThread(),\n client,\n assistantId,\n [STREAM_CONTROLLER]: controller,\n };\n\n return handle;\n}\n\n/** Convenience alias for the fully-resolved stream handle type. */\nexport type UseStreamResult<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> = UseStreamReturn<T, InterruptType, ConfigurableType>;\n\n/**\n * Helper used by the selector composables to reach the underlying\n * {@link ChannelRegistry} from a stream handle. Kept internal —\n * application code should call `useMessages`, `useToolCalls`, etc.\n *\n * @internal\n */\nexport function getRegistry(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n stream: UseStreamReturn<any, any, any>\n): ChannelRegistry {\n return stream[STREAM_CONTROLLER].registry;\n}\n\nexport type { ThreadStream };\n"],"mappings":";;;;;AAgDA,SAAS,kBACP,OACe;AACf,KAAI,OAAO,UAAU,WAAY,QAAQ,OAAmB;AAC5D,QAAO;;;;;;;;;AA4BT,MAAa,oBAAmC,OAAO,IACrD,+BACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuTD,SAAgB,UAKd,SACqD;CAuBrD,MAAM,QAAQ;CAEd,MAAM,mBACJ,MAAM,aAAa,QAAQ,OAAO,MAAM,cAAc;CACxD,MAAM,YAAY,MAAM;CAIxB,MAAM,SACJ,MAAM,UACL,IAAIA,gCAAAA,OAAW;EACd,QAAQ,MAAM;EACd,QA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,OAAA;EATjC;;;;EAcF,UAAA,IAAc,OAAA;EAZX;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqHL;;;;;AAmCA;;;;;;;;;;EA5FE,OAAA,CACE,QAAA,WACA,OAAA,GAAU,oBAAA,CAAqB,gBAAA,IAC9B,OAAA;EA+FF;;;;;;;;;;;;;;;;;;EA3ED,UAAA,CACE,aAAA,EAAe,MAAA,mBACf,OAAA,GAAU,uBAAA,CAAwB,gBAAA,IACjC,OAAA;EA+TsB;EAAA,SA3ThB,MAAA,EAAQ,MAAA;EA4Tb;EAAA,SA1TK,WAAA;EA6TS;;;;;;EArTlB,SAAA,IAAa,YAAA;EAkTT;EAAA,UA/SM,iBAAA,GAAoB,gBAAA,CAC5B,SAAA,EACA,aAAA,EACA,gBAAA;AAAA;;;;;;;KAWQ,SAAA,GAAY,eAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAmCR,SAAA,KACV,MAAA,8EAE8B,MAAA,kBAAA,CAElC,OAAA,EAAS,kBAAA,CAAiB,cAAA,CAAe,CAAA,KACxC,eAAA,CAAgB,CAAA,EAAG,aAAA,EAAe,gBAAA;;KAuPzB,eAAA,KACN,MAAA,8EAE8B,MAAA,qBAChC,eAAA,CAAgB,CAAA,EAAG,aAAA,EAAe,gBAAA"}
|
|
@@ -72,7 +72,8 @@ function useStream(options) {
|
|
|
72
72
|
onCreated: options.onCreated,
|
|
73
73
|
onCompleted: options.onCompleted,
|
|
74
74
|
initialValues: options.initialValues,
|
|
75
|
-
messagesKey: options.messagesKey
|
|
75
|
+
messagesKey: options.messagesKey,
|
|
76
|
+
optimistic: asBag.optimistic
|
|
76
77
|
});
|
|
77
78
|
onDestroy(controller.activate());
|
|
78
79
|
let rootSnapshot = $state(controller.rootStore.getSnapshot());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-stream.svelte.js","names":["ClientCtor"],"sources":["../src/use-stream.svelte.ts"],"sourcesContent":["import { onDestroy } from \"svelte\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type { Client, Interrupt } from \"@langchain/langgraph-sdk\";\nimport {\n applyHeadlessToolResumeCommand,\n flushPendingHeadlessToolInterrupts,\n scheduleCoalescedHeadlessToolFlush,\n type AnyHeadlessToolImplementation,\n type OnToolCallback,\n} from \"@langchain/langgraph-sdk\";\nimport {\n Client as ClientCtor,\n type ClientConfig,\n type ThreadStream,\n} from \"@langchain/langgraph-sdk/client\";\nimport {\n StreamController,\n type AgentServerAdapter,\n type AgentServerOptions as StreamAgentServerOptions,\n type ChannelRegistry,\n type CustomAdapterOptions as StreamCustomAdapterOptions,\n type InferStateType,\n type InferToolCalls,\n type InferSubagentStates,\n type RootSnapshot,\n type RunCompletedInfo,\n type RunExecutionInfo,\n type StreamRespondAllOptions,\n type StreamRespondOptions,\n type StreamStopOptions,\n type StreamSubmitOptions,\n type SubagentDiscoverySnapshot,\n type SubagentMap,\n type SubgraphByNodeMap,\n type SubgraphDiscoverySnapshot,\n type SubgraphMap,\n type UseStreamOptions as StreamUseStreamOptions,\n type WidenUpdateMessages,\n} from \"@langchain/langgraph-sdk/stream\";\n\n/**\n * A value that may be either a plain `T` or a getter `() => T`. Used\n * for reactive-capable option inputs (currently `threadId` only). When\n * a getter is passed the composable tracks it via `$effect` and\n * re-hydrates when the returned value changes.\n */\nexport type ValueOrGetter<T> = T | (() => T);\n\nfunction readValueOrGetter<T>(\n input: ValueOrGetter<T> | undefined\n): T | undefined {\n if (typeof input === \"function\") return (input as () => T)();\n return input;\n}\n\ntype SvelteThreadId = ValueOrGetter<string | null | undefined>;\n\nexport type AgentServerOptions<StateType extends object> =\n StreamAgentServerOptions<StateType, SvelteThreadId>;\n\nexport type CustomAdapterOptions<StateType extends object> =\n StreamCustomAdapterOptions<StateType, SvelteThreadId, string>;\n\nexport type UseStreamOptions<\n StateType extends object = Record<string, unknown>,\n> = StreamUseStreamOptions<\n StateType,\n SvelteThreadId,\n string | undefined,\n string | undefined,\n string\n>;\n\n/**\n * Private field on the handle that carries the {@link StreamController}\n * reference. Selector composables read this to reach the shared\n * {@link ChannelRegistry}. Use the selector composables\n * (`useMessages`, `useToolCalls`, `useValues`, …) instead of reading\n * this directly.\n */\nexport const STREAM_CONTROLLER: unique symbol = Symbol.for(\n \"@langchain/svelte/controller\"\n);\n\n/**\n * Svelte binding return type for {@link useStream}. Reactive\n * projections are exposed as getters on a stable object so templates\n * can read `stream.messages` directly without a `.value` / `.current`\n * hop and `$derived` wrappers auto-track the getter read.\n *\n * Destructuring (`const { messages } = stream`) breaks reactivity —\n * this is a Svelte 5 constraint and applies to every getter-object\n * pattern. Access fields through the live `stream` handle instead.\n */\nexport interface UseStreamReturn<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n StateType extends object = InferStateType<T>,\n SubagentStates = InferSubagentStates<T>,\n> {\n // ----- always-on root projections -----\n /**\n * The most recent `values`-channel snapshot emitted at the root\n * namespace — i.e. the thread-level state as the server sees it\n * after each superstep. Updated on every root `values` event, not\n * on token-level deltas: if you render `stream.values.messages`\n * directly you'll see full turns appear at once instead of\n * streaming token-by-token. Use {@link messages} (or\n * `useMessages`) for the token-streamed view.\n *\n * Equivalent to calling `useValues(stream)`.\n */\n readonly values: StateType;\n /**\n * The root message projection. Assembled from two sources and\n * merged in real time:\n *\n * 1. `messages`-channel deltas — token-level streaming events\n * (`message-start`, `content-block-delta`, `message-finish`)\n * emitted by the runtime. These drive live, token-by-token\n * updates.\n * 2. `values.messages` snapshots — the authoritative ordering\n * and any messages the agent produces without token streaming\n * (human turns, tool results, echoes from subagents).\n *\n * If the backend only emits `values` events (no `messages`\n * channel), every message will appear fully-formed on each\n * values update rather than streaming. This is a backend/runtime\n * concern — the Svelte layer faithfully renders whatever the\n * server sends.\n *\n * Equivalent to calling `useMessages(stream)` with no target.\n */\n readonly messages: BaseMessage[];\n /**\n * Root-namespace tool calls assembled from the `tools` channel.\n * Each entry is a fully parsed {@link AssembledToolCall} with\n * name, args, and id — suitable for rendering approval UIs or\n * forwarding to headless tool handlers.\n *\n * When the stream is typed with an agent brand or tool list,\n * entries are narrowed via {@link InferToolCalls}. Equivalent to\n * calling `useToolCalls(stream)` with no target.\n */\n readonly toolCalls: InferToolCalls<T>[];\n /**\n * All unresolved protocol interrupts observed on the root\n * namespace during the active thread. Populated from lifecycle /\n * input events and seeded on hydration from `thread.getState()`.\n * Cleared optimistically when a new run starts or an interrupt is\n * resolved via {@link respond}.\n */\n readonly interrupts: Interrupt<InterruptType>[];\n /**\n * Convenience alias for {@link interrupts}[0] — the primary\n * interrupt most UIs should act on when only one is pending.\n * `undefined` when no interrupt is active.\n */\n readonly interrupt: Interrupt<InterruptType> | undefined;\n /**\n * `true` while a run is active or being started on the current\n * thread. Driven by root-namespace lifecycle events (`running` →\n * `true`, terminal phases → `false`). Use this to disable submit\n * buttons and show in-flight spinners.\n */\n readonly isLoading: boolean;\n /**\n * `true` while the initial `thread.getState()` hydration for the\n * active thread is in flight. Distinct from {@link isLoading} —\n * thread loading covers the one-time fetch that seeds\n * {@link values} / {@link messages} before any user submit.\n */\n readonly isThreadLoading: boolean;\n /**\n * The last error observed on the active run or hydration attempt.\n * `undefined` when no error has occurred. Cleared optimistically\n * when a new {@link submit} starts.\n */\n readonly error: unknown;\n /**\n * Id of the thread the controller is bound to. `null` until the\n * first {@link submit} creates or selects a thread (or until an\n * explicit `threadId` option is provided and hydrated).\n */\n readonly threadId: string | null;\n /**\n * Promise that settles when the current thread's initial hydration\n * completes. Useful in SvelteKit `load()` handlers (or any\n * async-init site) to block until the controller has reconciled\n * with server-held state. A fresh promise is installed on every\n * `threadId` change.\n */\n readonly hydrationPromise: Promise<void>;\n\n // ----- always-on discovery -----\n /**\n * Subagents discovered on the root run. For DeepAgent-typed\n * streams the key set is narrowed to the subagent names declared\n * on the agent brand (`keyof InferSubagentStates<T>`).\n */\n readonly subagents: ReadonlyMap<\n keyof SubagentStates & string extends never\n ? string\n : keyof SubagentStates & string,\n SubagentDiscoverySnapshot\n >;\n /**\n * Subgraphs discovered on the root run.\n *\n * A namespace is classified as a subgraph iff at least one\n * strictly-deeper namespace has been observed with it as a prefix.\n * This is inferred from the lifecycle event stream — plain function\n * nodes (`orchestrator`, `writer` in the nested-stategraph example)\n * never appear here even though the server emits namespaced\n * lifecycle events for them. Promotion is monotonic and retroactive;\n * an entry appears as soon as the first descendant event lands.\n */\n readonly subgraphs: ReadonlyMap<string, SubgraphDiscoverySnapshot>;\n /**\n * Subgraphs indexed by the graph node that produced them\n * (`addNode(\"visualizer_0\", …)`). Each value is an array because\n * parallel fan-outs and loops can spawn multiple invocations of\n * the same node; arrays preserve insertion order. Updates in\n * lock-step with {@link subgraphs}.\n */\n readonly subgraphsByNode: ReadonlyMap<\n string,\n readonly SubgraphDiscoverySnapshot[]\n >;\n\n // ----- imperatives -----\n /**\n * Dispatch a new run on the bound thread.\n *\n * `input` is typed as `Partial<StateType>` so IDE autocompletion\n * surfaces the state keys declared on the root composable.\n */\n submit(\n input: WidenUpdateMessages<Partial<StateType>> | null | undefined,\n options?: StreamSubmitOptions<StateType, ConfigurableType>\n ): Promise<void>;\n /**\n * Stop the active run on the current thread. By default cancels the\n * run server-side and disconnects the client; pass `{ cancel: false }`\n * or use {@link disconnect} for join/rejoin. Sets {@link isLoading} to\n * `false` immediately; {@link values} and {@link messages} are preserved.\n */\n stop(options?: StreamStopOptions): Promise<void>;\n /**\n * Disconnect the client without cancelling the run server-side.\n * Alias for `stop({ cancel: false })`.\n */\n disconnect(): Promise<void>;\n /**\n * Resume a pending protocol interrupt by sending a response payload\n * back to the interrupted namespace.\n *\n * When `options.interruptId` is omitted, walks `getThread()?.interrupts`\n * from newest to oldest and resumes the first not yet resolved by a prior\n * `respond()` call. That may be a root or subgraph interrupt and is\n * **not** necessarily {@link interrupt} (`interrupts[0]`, root-only).\n * Safe when exactly one interrupt is pending; otherwise pass an explicit\n * `options.interruptId` (and `options.namespace` for subgraph\n * interrupts).\n *\n * The server validates `namespace` against the pending interrupt. Root\n * interrupts use `namespace: []` (default when omitted). For subgraph\n * interrupts, copy `namespace` from `getThread()?.interrupts`.\n *\n * @example\n * ```ts\n * // Single pending interrupt\n * await stream.respond({ approved: true });\n * ```\n *\n * @example\n * ```svelte\n * // Multiple root interrupts\n * {#each stream.interrupts as intr (intr.id)}\n * <button onclick={() => stream.respond(decide(intr.value), { interruptId: intr.id! })}>\n * Resolve\n * </button>\n * {/each}\n * ```\n *\n * @example\n * ```ts\n * // Subgraph interrupt — namespace from `getThread()`\n * const thread = stream.getThread();\n * for (const entry of thread?.interrupts ?? []) {\n * await stream.respond(buildResponse(entry.payload), {\n * interruptId: entry.interruptId,\n * namespace: entry.namespace,\n * });\n * }\n * ```\n *\n * To resume several interrupts pending at the same checkpoint in one\n * command, use {@link respondAll}.\n */\n respond(\n response: unknown,\n options?: StreamRespondOptions<ConfigurableType>\n ): Promise<void>;\n\n /**\n * Resume several pending interrupts at the same checkpoint in a single\n * command — required when a run pauses on multiple interrupts at once\n * (e.g. parallel tool-authorization prompts), which sequential\n * {@link respond} calls cannot handle. `responsesById` maps each pending\n * `interruptId` to its response, so different interrupts can receive\n * different payloads. Pass `options.config` / `options.metadata` to fold\n * run-level config and metadata into the resumed run, mirroring\n * `submit()`.\n *\n * @example\n * ```ts\n * await stream.respondAll({\n * [interruptA.id]: { approved: true },\n * [interruptB.id]: { approved: false },\n * });\n * ```\n */\n respondAll(\n responsesById: Record<string, unknown>,\n options?: StreamRespondAllOptions<ConfigurableType>\n ): Promise<void>;\n\n // ----- identity -----\n /** LangGraph SDK client used to construct thread streams. */\n readonly client: Client;\n /** Assistant id the thread is bound to for its lifetime. */\n readonly assistantId: string;\n\n /**\n * Returns the bound {@link ThreadStream}, if one exists (`undefined`\n * until the thread is hydrated or the first submit completes). Prefer\n * the projections and selector composables for UI work; use this for\n * low-level protocol access (raw subscriptions, state commands, etc.).\n */\n getThread(): ThreadStream | undefined;\n\n /** @internal Used by selector composables. */\n readonly [STREAM_CONTROLLER]: StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >;\n}\n\n/**\n * Erased handle useful as a parameter type for helpers and wrapper\n * components that pass a `stream` through to selector composables\n * without reading `values` directly. Mirrors the React\n * `AnyStream` alias.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyStream = UseStreamReturn<any, any, any>;\n\n/**\n * Svelte 5 binding for the v2-native stream runtime.\n *\n * Returns a handle whose reactive fields are plain getters on a\n * stable object — templates can read `stream.messages` directly and\n * `$derived(stream.isLoading)` auto-tracks the getter.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { useStream } from \"@langchain/svelte\";\n *\n * const stream = useStream({\n * assistantId: \"agent\",\n * apiUrl: \"http://localhost:2024\",\n * });\n * </script>\n *\n * {#each stream.messages as msg (msg.id)}\n * <div>{msg.content}</div>\n * {/each}\n * <button onclick={() =>\n * stream.submit({ messages: [{ type: \"human\", content: \"Hi\" }] })\n * }>\n * Send\n * </button>\n * ```\n *\n * `assistantId`, `client`, and `transport` are captured at composable\n * init. To bind a new assistant/transport, remount the component.\n * Only `threadId` is treated as reactive — pass it as a getter\n * (`threadId: () => active`) to drive an in-place thread swap.\n */\nexport function useStream<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n>(\n options: UseStreamOptions<InferStateType<T>>\n): UseStreamReturn<T, InterruptType, ConfigurableType> {\n type StateType = InferStateType<T>;\n\n interface OptionsBag {\n assistantId?: string;\n threadId?: ValueOrGetter<string | null | undefined>;\n client?: Client;\n apiUrl?: string;\n apiKey?: string;\n callerOptions?: ClientConfig[\"callerOptions\"];\n defaultHeaders?: ClientConfig[\"defaultHeaders\"];\n transport?: \"sse\" | \"websocket\" | AgentServerAdapter;\n fetch?: typeof fetch;\n webSocketFactory?: (url: string) => WebSocket;\n onThreadId?: (threadId: string) => void;\n onCreated?: (info: RunExecutionInfo) => void;\n onCompleted?: (info: RunCompletedInfo) => void;\n initialValues?: StateType;\n messagesKey?: string;\n tools?: AnyHeadlessToolImplementation[];\n onTool?: OnToolCallback;\n }\n const asBag = options as OptionsBag;\n\n const hasCustomAdapter =\n asBag.transport != null && typeof asBag.transport !== \"string\";\n const transport = asBag.transport;\n\n // Client construction — captured once at init. Consumers that need\n // to swap `apiUrl`/`apiKey` at runtime remount the owning component.\n const client: Client =\n asBag.client ??\n (new ClientCtor({\n apiUrl: asBag.apiUrl,\n apiKey: asBag.apiKey,\n callerOptions: asBag.callerOptions,\n defaultHeaders: asBag.defaultHeaders,\n }) as unknown as Client);\n\n // Custom adapters may omit `assistantId`; the controller still\n // requires one so it has something to forward to `threads.stream`.\n const sentinel = \"_\";\n const assistantId =\n \"assistantId\" in options ? (options.assistantId ?? sentinel) : sentinel;\n\n const initialThreadId = readValueOrGetter(asBag.threadId) ?? null;\n\n // Plain `let` binding, not `$state`: the controller holds maps of\n // listeners, Promises, and the live `ThreadStream`, none of which\n // survive Svelte's deep `$state` proxy wrapping.\n const controller = new StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >({\n assistantId,\n // `Client` is state-shape agnostic at runtime; the controller\n // advertises `Client<StateType>` on its public type for ergonomics.\n client: client as unknown as Client<StateType>,\n threadId: initialThreadId,\n transport,\n fetch: hasCustomAdapter ? undefined : asBag.fetch,\n webSocketFactory: hasCustomAdapter ? undefined : asBag.webSocketFactory,\n onThreadId: options.onThreadId,\n onCreated: options.onCreated,\n onCompleted: options.onCompleted,\n initialValues: options.initialValues,\n messagesKey: options.messagesKey,\n });\n\n // Deferred dispose: mirrors React's activate/dispose pattern so HMR\n // and other scope-reuse scenarios stay clean. `activate()` cancels\n // a pending dispose if the owning scope survives.\n const deactivate = controller.activate();\n onDestroy(deactivate);\n\n // ─── Reactive state bridges ─────────────────────────────────────────\n //\n // Each always-on `StreamStore` is wrapped in a runes `$state` slot\n // seeded from `getSnapshot()` and kept in sync via `store.subscribe`.\n // Subscriptions are torn down on component destroy.\n let rootSnapshot = $state<RootSnapshot<StateType, InterruptType>>(\n controller.rootStore.getSnapshot()\n );\n const unsubscribeRoot = controller.rootStore.subscribe(() => {\n rootSnapshot = controller.rootStore.getSnapshot();\n });\n onDestroy(unsubscribeRoot);\n\n let subagentSnapshot = $state<SubagentMap>(\n controller.subagentStore.getSnapshot()\n );\n const unsubscribeSubagents = controller.subagentStore.subscribe(() => {\n subagentSnapshot = controller.subagentStore.getSnapshot();\n });\n onDestroy(unsubscribeSubagents);\n\n let subgraphSnapshot = $state<SubgraphMap>(\n controller.subgraphStore.getSnapshot()\n );\n const unsubscribeSubgraphs = controller.subgraphStore.subscribe(() => {\n subgraphSnapshot = controller.subgraphStore.getSnapshot();\n });\n onDestroy(unsubscribeSubgraphs);\n\n let subgraphByNodeSnapshot = $state<SubgraphByNodeMap>(\n controller.subgraphByNodeStore.getSnapshot()\n );\n const unsubscribeSubgraphByNode = controller.subgraphByNodeStore.subscribe(\n () => {\n subgraphByNodeSnapshot = controller.subgraphByNodeStore.getSnapshot();\n }\n );\n onDestroy(unsubscribeSubgraphByNode);\n\n // ─── threadId reactivity ────────────────────────────────────────────\n //\n // Only matters when the caller passed a getter. The initial hydrate\n // already fired in the controller constructor, so skip the first\n // tick to avoid a redundant `thread.state.get()`.\n if (typeof asBag.threadId === \"function\") {\n const getThreadId = asBag.threadId;\n let previousThreadId = initialThreadId;\n $effect(() => {\n const next = (getThreadId() ?? null) as string | null;\n if (next === previousThreadId) return;\n previousThreadId = next;\n void controller.hydrate(next);\n });\n }\n\n // ─── Headless-tool handling ─────────────────────────────────────────\n //\n // Watch the root `values.__interrupt__` key plus the protocol-\n // surfaced interrupts for items targeting a registered tool, invoke\n // the handler, and resume the run with the handler's return value.\n // Dedup via an id set so rerenders don't replay a tool call twice.\n const tools = options.tools;\n const onTool = options.onTool;\n if (tools?.length) {\n const handledTools = new Set<string>();\n let handledForThreadId: string | null = initialThreadId;\n $effect(() => {\n // Reset dedup set when the active thread id changes — a fresh\n // thread may legitimately re-emit a tool-call id we've seen.\n const currentThreadId = rootSnapshot.threadId;\n if (currentThreadId !== handledForThreadId) {\n handledTools.clear();\n handledForThreadId = currentThreadId;\n }\n\n scheduleCoalescedHeadlessToolFlush(handledTools, () => {\n const valuesBag = rootSnapshot.values as unknown as Record<\n string,\n unknown\n >;\n const protocolInterrupts =\n rootSnapshot.interrupts as unknown as Interrupt[];\n const valuesInterrupts = Array.isArray(valuesBag?.__interrupt__)\n ? (valuesBag.__interrupt__ as Interrupt[])\n : [];\n const headlessInterrupts =\n protocolInterrupts.length > 0 ? protocolInterrupts : valuesInterrupts;\n if (headlessInterrupts.length === 0) return;\n flushPendingHeadlessToolInterrupts(\n { ...valuesBag, __interrupt__: headlessInterrupts },\n tools,\n handledTools,\n {\n onTool,\n defer: (run) => {\n void Promise.resolve().then(run);\n },\n resumeSubmit: (command) =>\n applyHeadlessToolResumeCommand(controller, command),\n }\n );\n });\n });\n }\n\n // ─── Public handle ──────────────────────────────────────────────────\n //\n // Single stable object with getters. Getters read the runes\n // `$state` slots, which drives template reactivity automatically.\n const handle: UseStreamReturn<T, InterruptType, ConfigurableType> = {\n get values() {\n return rootSnapshot.values;\n },\n get messages() {\n return rootSnapshot.messages;\n },\n get toolCalls() {\n return rootSnapshot.toolCalls as InferToolCalls<T>[];\n },\n get interrupts() {\n return rootSnapshot.interrupts;\n },\n get interrupt() {\n return rootSnapshot.interrupt;\n },\n get isLoading() {\n return rootSnapshot.isLoading;\n },\n get isThreadLoading() {\n return rootSnapshot.isThreadLoading;\n },\n get error() {\n return rootSnapshot.error;\n },\n get threadId() {\n return rootSnapshot.threadId;\n },\n get hydrationPromise() {\n return controller.hydrationPromise;\n },\n get subagents() {\n return subagentSnapshot as UseStreamReturn<\n T,\n InterruptType,\n ConfigurableType\n >[\"subagents\"];\n },\n get subgraphs() {\n return subgraphSnapshot;\n },\n get subgraphsByNode() {\n return subgraphByNodeSnapshot;\n },\n submit: (input, submitOptions) => controller.submit(input, submitOptions),\n stop: (options) => controller.stop(options),\n disconnect: () => controller.disconnect(),\n respond: (response, options) => controller.respond(response, options),\n respondAll: (responsesById, options) =>\n controller.respondAll(responsesById, options),\n getThread: () => controller.getThread(),\n client,\n assistantId,\n [STREAM_CONTROLLER]: controller,\n };\n\n return handle;\n}\n\n/** Convenience alias for the fully-resolved stream handle type. */\nexport type UseStreamResult<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> = UseStreamReturn<T, InterruptType, ConfigurableType>;\n\n/**\n * Helper used by the selector composables to reach the underlying\n * {@link ChannelRegistry} from a stream handle. Kept internal —\n * application code should call `useMessages`, `useToolCalls`, etc.\n *\n * @internal\n */\nexport function getRegistry(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n stream: UseStreamReturn<any, any, any>\n): ChannelRegistry {\n return stream[STREAM_CONTROLLER].registry;\n}\n\nexport type { ThreadStream };\n"],"mappings":";;;;;AAgDA,SAAS,kBACP,OACe;AACf,KAAI,OAAO,UAAU,WAAY,QAAQ,OAAmB;AAC5D,QAAO;;;;;;;;;AA4BT,MAAa,oBAAmC,OAAO,IACrD,+BACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuTD,SAAgB,UAKd,SACqD;CAsBrD,MAAM,QAAQ;CAEd,MAAM,mBACJ,MAAM,aAAa,QAAQ,OAAO,MAAM,cAAc;CACxD,MAAM,YAAY,MAAM;CAIxB,MAAM,SACJ,MAAM,UACL,IAAIA,SAAW;EACd,QAAQ,MAAM;EACd,QAAQ,MAAM;EACd,eAAe,MAAM;EACrB,gBAAgB,MAAM;EACvB,CAAC;CAIJ,MAAM,WAAW;CACjB,MAAM,cACJ,iBAAiB,UAAW,QAAQ,eAAe,WAAY;CAEjE,MAAM,kBAAkB,kBAAkB,MAAM,SAAS,IAAI;CAK7D,MAAM,aAAa,IAAI,iBAIrB;EACA;EAGQ;EACR,UAAU;EACV;EACA,OAAO,mBAAmB,KAAA,IAAY,MAAM;EAC5C,kBAAkB,mBAAmB,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AAc,GAC3D,UAAU,gBACX,EAAE;IACN,MAAM,qBACJ,mBAAmB,SAAS,IAAI,qBAAqB;AACvD,QAAI,mBAAmB,WAAW,EAAG;AACrC,uCACE;KAAE,GAAG;KAAW,eAAe;KAAoB,EACnD,OACA,cACA;KACE;KACA,QAAQ,QAAQ;AACT,cAAQ,SAAS,CAAC,KAAK,IAAI;;KAElC,eAAe,YACb,+BAA+B,YAAY,QAAQ;KACtD,CACF;KACD;IACF;;AA+DJ,QAxDoE;EAClE,IAAI,SAAS;AACX,UAAO,aAAa;;EAEtB,IAAI,WAAW;AACb,UAAO,aAAa;;EAEtB,IAAI,YAAY;AACd,UAAO,aAAa;;EAEtB,IAAI,aAAa;AACf,UAAO,aAAa;;EAEtB,IAAI,YAAY;AACd,UAAO,aAAa;;EAEtB,IAAI,YAAY;AACd,UAAO,aAAa;;EAEtB,IAAI,kBAAkB;AACpB,UAAO,aAAa;;EAEtB,IAAI,QAAQ;AACV,UAAO,aAAa;;EAEtB,IAAI,WAAW;AACb,UAAO,aAAa;;EAEtB,IAAI,mBAAmB;AACrB,UAAO,WAAW;;EAEpB,IAAI,YAAY;AACd,UAAO;;EAMT,IAAI,YAAY;AACd,UAAO;;EAET,IAAI,kBAAkB;AACpB,UAAO;;EAET,SAAS,OAAO,kBAAkB,WAAW,OAAO,OAAO,cAAc;EACzE,OAAO,YAAY,WAAW,KAAK,QAAQ;EAC3C,kBAAkB,WAAW,YAAY;EACzC,UAAU,UAAU,YAAY,WAAW,QAAQ,UAAU,QAAQ;EACrE,aAAa,eAAe,YAC1B,WAAW,WAAW,eAAe,QAAQ;EAC/C,iBAAiB,WAAW,WAAW;EACvC;EACA;GACC,oBAAoB;EACtB;;;;;;;;;AAmBH,SAAgB,YAEd,QACiB;AACjB,QAAO,OAAO,mBAAmB"}
|
|
1
|
+
{"version":3,"file":"use-stream.svelte.js","names":["ClientCtor"],"sources":["../src/use-stream.svelte.ts"],"sourcesContent":["import { onDestroy } from \"svelte\";\nimport type { BaseMessage } from \"@langchain/core/messages\";\nimport type { Client, Interrupt } from \"@langchain/langgraph-sdk\";\nimport {\n applyHeadlessToolResumeCommand,\n flushPendingHeadlessToolInterrupts,\n scheduleCoalescedHeadlessToolFlush,\n type AnyHeadlessToolImplementation,\n type OnToolCallback,\n} from \"@langchain/langgraph-sdk\";\nimport {\n Client as ClientCtor,\n type ClientConfig,\n type ThreadStream,\n} from \"@langchain/langgraph-sdk/client\";\nimport {\n StreamController,\n type AgentServerAdapter,\n type AgentServerOptions as StreamAgentServerOptions,\n type ChannelRegistry,\n type CustomAdapterOptions as StreamCustomAdapterOptions,\n type InferStateType,\n type InferToolCalls,\n type InferSubagentStates,\n type RootSnapshot,\n type RunCompletedInfo,\n type RunExecutionInfo,\n type StreamRespondAllOptions,\n type StreamRespondOptions,\n type StreamStopOptions,\n type StreamSubmitOptions,\n type SubagentDiscoverySnapshot,\n type SubagentMap,\n type SubgraphByNodeMap,\n type SubgraphDiscoverySnapshot,\n type SubgraphMap,\n type UseStreamOptions as StreamUseStreamOptions,\n type WidenUpdateMessages,\n} from \"@langchain/langgraph-sdk/stream\";\n\n/**\n * A value that may be either a plain `T` or a getter `() => T`. Used\n * for reactive-capable option inputs (currently `threadId` only). When\n * a getter is passed the composable tracks it via `$effect` and\n * re-hydrates when the returned value changes.\n */\nexport type ValueOrGetter<T> = T | (() => T);\n\nfunction readValueOrGetter<T>(\n input: ValueOrGetter<T> | undefined\n): T | undefined {\n if (typeof input === \"function\") return (input as () => T)();\n return input;\n}\n\ntype SvelteThreadId = ValueOrGetter<string | null | undefined>;\n\nexport type AgentServerOptions<StateType extends object> =\n StreamAgentServerOptions<StateType, SvelteThreadId>;\n\nexport type CustomAdapterOptions<StateType extends object> =\n StreamCustomAdapterOptions<StateType, SvelteThreadId, string>;\n\nexport type UseStreamOptions<\n StateType extends object = Record<string, unknown>,\n> = StreamUseStreamOptions<\n StateType,\n SvelteThreadId,\n string | undefined,\n string | undefined,\n string\n>;\n\n/**\n * Private field on the handle that carries the {@link StreamController}\n * reference. Selector composables read this to reach the shared\n * {@link ChannelRegistry}. Use the selector composables\n * (`useMessages`, `useToolCalls`, `useValues`, …) instead of reading\n * this directly.\n */\nexport const STREAM_CONTROLLER: unique symbol = Symbol.for(\n \"@langchain/svelte/controller\"\n);\n\n/**\n * Svelte binding return type for {@link useStream}. Reactive\n * projections are exposed as getters on a stable object so templates\n * can read `stream.messages` directly without a `.value` / `.current`\n * hop and `$derived` wrappers auto-track the getter read.\n *\n * Destructuring (`const { messages } = stream`) breaks reactivity —\n * this is a Svelte 5 constraint and applies to every getter-object\n * pattern. Access fields through the live `stream` handle instead.\n */\nexport interface UseStreamReturn<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n StateType extends object = InferStateType<T>,\n SubagentStates = InferSubagentStates<T>,\n> {\n // ----- always-on root projections -----\n /**\n * The most recent `values`-channel snapshot emitted at the root\n * namespace — i.e. the thread-level state as the server sees it\n * after each superstep. Updated on every root `values` event, not\n * on token-level deltas: if you render `stream.values.messages`\n * directly you'll see full turns appear at once instead of\n * streaming token-by-token. Use {@link messages} (or\n * `useMessages`) for the token-streamed view.\n *\n * Equivalent to calling `useValues(stream)`.\n */\n readonly values: StateType;\n /**\n * The root message projection. Assembled from two sources and\n * merged in real time:\n *\n * 1. `messages`-channel deltas — token-level streaming events\n * (`message-start`, `content-block-delta`, `message-finish`)\n * emitted by the runtime. These drive live, token-by-token\n * updates.\n * 2. `values.messages` snapshots — the authoritative ordering\n * and any messages the agent produces without token streaming\n * (human turns, tool results, echoes from subagents).\n *\n * If the backend only emits `values` events (no `messages`\n * channel), every message will appear fully-formed on each\n * values update rather than streaming. This is a backend/runtime\n * concern — the Svelte layer faithfully renders whatever the\n * server sends.\n *\n * Equivalent to calling `useMessages(stream)` with no target.\n */\n readonly messages: BaseMessage[];\n /**\n * Root-namespace tool calls assembled from the `tools` channel.\n * Each entry is a fully parsed {@link AssembledToolCall} with\n * name, args, and id — suitable for rendering approval UIs or\n * forwarding to headless tool handlers.\n *\n * When the stream is typed with an agent brand or tool list,\n * entries are narrowed via {@link InferToolCalls}. Equivalent to\n * calling `useToolCalls(stream)` with no target.\n */\n readonly toolCalls: InferToolCalls<T>[];\n /**\n * All unresolved protocol interrupts observed on the root\n * namespace during the active thread. Populated from lifecycle /\n * input events and seeded on hydration from `thread.getState()`.\n * Cleared optimistically when a new run starts or an interrupt is\n * resolved via {@link respond}.\n */\n readonly interrupts: Interrupt<InterruptType>[];\n /**\n * Convenience alias for {@link interrupts}[0] — the primary\n * interrupt most UIs should act on when only one is pending.\n * `undefined` when no interrupt is active.\n */\n readonly interrupt: Interrupt<InterruptType> | undefined;\n /**\n * `true` while a run is active or being started on the current\n * thread. Driven by root-namespace lifecycle events (`running` →\n * `true`, terminal phases → `false`). Use this to disable submit\n * buttons and show in-flight spinners.\n */\n readonly isLoading: boolean;\n /**\n * `true` while the initial `thread.getState()` hydration for the\n * active thread is in flight. Distinct from {@link isLoading} —\n * thread loading covers the one-time fetch that seeds\n * {@link values} / {@link messages} before any user submit.\n */\n readonly isThreadLoading: boolean;\n /**\n * The last error observed on the active run or hydration attempt.\n * `undefined` when no error has occurred. Cleared optimistically\n * when a new {@link submit} starts.\n */\n readonly error: unknown;\n /**\n * Id of the thread the controller is bound to. `null` until the\n * first {@link submit} creates or selects a thread (or until an\n * explicit `threadId` option is provided and hydrated).\n */\n readonly threadId: string | null;\n /**\n * Promise that settles when the current thread's initial hydration\n * completes. Useful in SvelteKit `load()` handlers (or any\n * async-init site) to block until the controller has reconciled\n * with server-held state. A fresh promise is installed on every\n * `threadId` change.\n */\n readonly hydrationPromise: Promise<void>;\n\n // ----- always-on discovery -----\n /**\n * Subagents discovered on the root run. For DeepAgent-typed\n * streams the key set is narrowed to the subagent names declared\n * on the agent brand (`keyof InferSubagentStates<T>`).\n */\n readonly subagents: ReadonlyMap<\n keyof SubagentStates & string extends never\n ? string\n : keyof SubagentStates & string,\n SubagentDiscoverySnapshot\n >;\n /**\n * Subgraphs discovered on the root run.\n *\n * A namespace is classified as a subgraph iff at least one\n * strictly-deeper namespace has been observed with it as a prefix.\n * This is inferred from the lifecycle event stream — plain function\n * nodes (`orchestrator`, `writer` in the nested-stategraph example)\n * never appear here even though the server emits namespaced\n * lifecycle events for them. Promotion is monotonic and retroactive;\n * an entry appears as soon as the first descendant event lands.\n */\n readonly subgraphs: ReadonlyMap<string, SubgraphDiscoverySnapshot>;\n /**\n * Subgraphs indexed by the graph node that produced them\n * (`addNode(\"visualizer_0\", …)`). Each value is an array because\n * parallel fan-outs and loops can spawn multiple invocations of\n * the same node; arrays preserve insertion order. Updates in\n * lock-step with {@link subgraphs}.\n */\n readonly subgraphsByNode: ReadonlyMap<\n string,\n readonly SubgraphDiscoverySnapshot[]\n >;\n\n // ----- imperatives -----\n /**\n * Dispatch a new run on the bound thread.\n *\n * `input` is typed as `Partial<StateType>` so IDE autocompletion\n * surfaces the state keys declared on the root composable.\n */\n submit(\n input: WidenUpdateMessages<Partial<StateType>> | null | undefined,\n options?: StreamSubmitOptions<StateType, ConfigurableType>\n ): Promise<void>;\n /**\n * Stop the active run on the current thread. By default cancels the\n * run server-side and disconnects the client; pass `{ cancel: false }`\n * or use {@link disconnect} for join/rejoin. Sets {@link isLoading} to\n * `false` immediately; {@link values} and {@link messages} are preserved.\n */\n stop(options?: StreamStopOptions): Promise<void>;\n /**\n * Disconnect the client without cancelling the run server-side.\n * Alias for `stop({ cancel: false })`.\n */\n disconnect(): Promise<void>;\n /**\n * Resume a pending protocol interrupt by sending a response payload\n * back to the interrupted namespace.\n *\n * When `options.interruptId` is omitted, walks `getThread()?.interrupts`\n * from newest to oldest and resumes the first not yet resolved by a prior\n * `respond()` call. That may be a root or subgraph interrupt and is\n * **not** necessarily {@link interrupt} (`interrupts[0]`, root-only).\n * Safe when exactly one interrupt is pending; otherwise pass an explicit\n * `options.interruptId` (and `options.namespace` for subgraph\n * interrupts).\n *\n * The server validates `namespace` against the pending interrupt. Root\n * interrupts use `namespace: []` (default when omitted). For subgraph\n * interrupts, copy `namespace` from `getThread()?.interrupts`.\n *\n * @example\n * ```ts\n * // Single pending interrupt\n * await stream.respond({ approved: true });\n * ```\n *\n * @example\n * ```svelte\n * // Multiple root interrupts\n * {#each stream.interrupts as intr (intr.id)}\n * <button onclick={() => stream.respond(decide(intr.value), { interruptId: intr.id! })}>\n * Resolve\n * </button>\n * {/each}\n * ```\n *\n * @example\n * ```ts\n * // Subgraph interrupt — namespace from `getThread()`\n * const thread = stream.getThread();\n * for (const entry of thread?.interrupts ?? []) {\n * await stream.respond(buildResponse(entry.payload), {\n * interruptId: entry.interruptId,\n * namespace: entry.namespace,\n * });\n * }\n * ```\n *\n * To resume several interrupts pending at the same checkpoint in one\n * command, use {@link respondAll}.\n */\n respond(\n response: unknown,\n options?: StreamRespondOptions<ConfigurableType>\n ): Promise<void>;\n\n /**\n * Resume several pending interrupts at the same checkpoint in a single\n * command — required when a run pauses on multiple interrupts at once\n * (e.g. parallel tool-authorization prompts), which sequential\n * {@link respond} calls cannot handle. `responsesById` maps each pending\n * `interruptId` to its response, so different interrupts can receive\n * different payloads. Pass `options.config` / `options.metadata` to fold\n * run-level config and metadata into the resumed run, mirroring\n * `submit()`.\n *\n * @example\n * ```ts\n * await stream.respondAll({\n * [interruptA.id]: { approved: true },\n * [interruptB.id]: { approved: false },\n * });\n * ```\n */\n respondAll(\n responsesById: Record<string, unknown>,\n options?: StreamRespondAllOptions<ConfigurableType>\n ): Promise<void>;\n\n // ----- identity -----\n /** LangGraph SDK client used to construct thread streams. */\n readonly client: Client;\n /** Assistant id the thread is bound to for its lifetime. */\n readonly assistantId: string;\n\n /**\n * Returns the bound {@link ThreadStream}, if one exists (`undefined`\n * until the thread is hydrated or the first submit completes). Prefer\n * the projections and selector composables for UI work; use this for\n * low-level protocol access (raw subscriptions, state commands, etc.).\n */\n getThread(): ThreadStream | undefined;\n\n /** @internal Used by selector composables. */\n readonly [STREAM_CONTROLLER]: StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >;\n}\n\n/**\n * Erased handle useful as a parameter type for helpers and wrapper\n * components that pass a `stream` through to selector composables\n * without reading `values` directly. Mirrors the React\n * `AnyStream` alias.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnyStream = UseStreamReturn<any, any, any>;\n\n/**\n * Svelte 5 binding for the v2-native stream runtime.\n *\n * Returns a handle whose reactive fields are plain getters on a\n * stable object — templates can read `stream.messages` directly and\n * `$derived(stream.isLoading)` auto-tracks the getter.\n *\n * @example\n * ```svelte\n * <script lang=\"ts\">\n * import { useStream } from \"@langchain/svelte\";\n *\n * const stream = useStream({\n * assistantId: \"agent\",\n * apiUrl: \"http://localhost:2024\",\n * });\n * </script>\n *\n * {#each stream.messages as msg (msg.id)}\n * <div>{msg.content}</div>\n * {/each}\n * <button onclick={() =>\n * stream.submit({ messages: [{ type: \"human\", content: \"Hi\" }] })\n * }>\n * Send\n * </button>\n * ```\n *\n * `assistantId`, `client`, and `transport` are captured at composable\n * init. To bind a new assistant/transport, remount the component.\n * Only `threadId` is treated as reactive — pass it as a getter\n * (`threadId: () => active`) to drive an in-place thread swap.\n */\nexport function useStream<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n>(\n options: UseStreamOptions<InferStateType<T>>\n): UseStreamReturn<T, InterruptType, ConfigurableType> {\n type StateType = InferStateType<T>;\n\n interface OptionsBag {\n assistantId?: string;\n threadId?: ValueOrGetter<string | null | undefined>;\n client?: Client;\n apiUrl?: string;\n apiKey?: string;\n callerOptions?: ClientConfig[\"callerOptions\"];\n defaultHeaders?: ClientConfig[\"defaultHeaders\"];\n transport?: \"sse\" | \"websocket\" | AgentServerAdapter;\n fetch?: typeof fetch;\n webSocketFactory?: (url: string) => WebSocket;\n onThreadId?: (threadId: string) => void;\n onCreated?: (info: RunExecutionInfo) => void;\n onCompleted?: (info: RunCompletedInfo) => void;\n initialValues?: StateType;\n messagesKey?: string;\n tools?: AnyHeadlessToolImplementation[];\n onTool?: OnToolCallback;\n optimistic?: boolean;\n }\n const asBag = options as OptionsBag;\n\n const hasCustomAdapter =\n asBag.transport != null && typeof asBag.transport !== \"string\";\n const transport = asBag.transport;\n\n // Client construction — captured once at init. Consumers that need\n // to swap `apiUrl`/`apiKey` at runtime remount the owning component.\n const client: Client =\n asBag.client ??\n (new ClientCtor({\n apiUrl: asBag.apiUrl,\n apiKey: asBag.apiKey,\n callerOptions: asBag.callerOptions,\n defaultHeaders: asBag.defaultHeaders,\n }) as unknown as Client);\n\n // Custom adapters may omit `assistantId`; the controller still\n // requires one so it has something to forward to `threads.stream`.\n const sentinel = \"_\";\n const assistantId =\n \"assistantId\" in options ? (options.assistantId ?? sentinel) : sentinel;\n\n const initialThreadId = readValueOrGetter(asBag.threadId) ?? null;\n\n // Plain `let` binding, not `$state`: the controller holds maps of\n // listeners, Promises, and the live `ThreadStream`, none of which\n // survive Svelte's deep `$state` proxy wrapping.\n const controller = new StreamController<\n StateType,\n InterruptType,\n ConfigurableType\n >({\n assistantId,\n // `Client` is state-shape agnostic at runtime; the controller\n // advertises `Client<StateType>` on its public type for ergonomics.\n client: client as unknown as Client<StateType>,\n threadId: initialThreadId,\n transport,\n fetch: hasCustomAdapter ? undefined : asBag.fetch,\n webSocketFactory: hasCustomAdapter ? undefined : asBag.webSocketFactory,\n onThreadId: options.onThreadId,\n onCreated: options.onCreated,\n onCompleted: options.onCompleted,\n initialValues: options.initialValues,\n messagesKey: options.messagesKey,\n optimistic: asBag.optimistic,\n });\n\n // Deferred dispose: mirrors React's activate/dispose pattern so HMR\n // and other scope-reuse scenarios stay clean. `activate()` cancels\n // a pending dispose if the owning scope survives.\n const deactivate = controller.activate();\n onDestroy(deactivate);\n\n // ─── Reactive state bridges ─────────────────────────────────────────\n //\n // Each always-on `StreamStore` is wrapped in a runes `$state` slot\n // seeded from `getSnapshot()` and kept in sync via `store.subscribe`.\n // Subscriptions are torn down on component destroy.\n let rootSnapshot = $state<RootSnapshot<StateType, InterruptType>>(\n controller.rootStore.getSnapshot()\n );\n const unsubscribeRoot = controller.rootStore.subscribe(() => {\n rootSnapshot = controller.rootStore.getSnapshot();\n });\n onDestroy(unsubscribeRoot);\n\n let subagentSnapshot = $state<SubagentMap>(\n controller.subagentStore.getSnapshot()\n );\n const unsubscribeSubagents = controller.subagentStore.subscribe(() => {\n subagentSnapshot = controller.subagentStore.getSnapshot();\n });\n onDestroy(unsubscribeSubagents);\n\n let subgraphSnapshot = $state<SubgraphMap>(\n controller.subgraphStore.getSnapshot()\n );\n const unsubscribeSubgraphs = controller.subgraphStore.subscribe(() => {\n subgraphSnapshot = controller.subgraphStore.getSnapshot();\n });\n onDestroy(unsubscribeSubgraphs);\n\n let subgraphByNodeSnapshot = $state<SubgraphByNodeMap>(\n controller.subgraphByNodeStore.getSnapshot()\n );\n const unsubscribeSubgraphByNode = controller.subgraphByNodeStore.subscribe(\n () => {\n subgraphByNodeSnapshot = controller.subgraphByNodeStore.getSnapshot();\n }\n );\n onDestroy(unsubscribeSubgraphByNode);\n\n // ─── threadId reactivity ────────────────────────────────────────────\n //\n // Only matters when the caller passed a getter. The initial hydrate\n // already fired in the controller constructor, so skip the first\n // tick to avoid a redundant `thread.state.get()`.\n if (typeof asBag.threadId === \"function\") {\n const getThreadId = asBag.threadId;\n let previousThreadId = initialThreadId;\n $effect(() => {\n const next = (getThreadId() ?? null) as string | null;\n if (next === previousThreadId) return;\n previousThreadId = next;\n void controller.hydrate(next);\n });\n }\n\n // ─── Headless-tool handling ─────────────────────────────────────────\n //\n // Watch the root `values.__interrupt__` key plus the protocol-\n // surfaced interrupts for items targeting a registered tool, invoke\n // the handler, and resume the run with the handler's return value.\n // Dedup via an id set so rerenders don't replay a tool call twice.\n const tools = options.tools;\n const onTool = options.onTool;\n if (tools?.length) {\n const handledTools = new Set<string>();\n let handledForThreadId: string | null = initialThreadId;\n $effect(() => {\n // Reset dedup set when the active thread id changes — a fresh\n // thread may legitimately re-emit a tool-call id we've seen.\n const currentThreadId = rootSnapshot.threadId;\n if (currentThreadId !== handledForThreadId) {\n handledTools.clear();\n handledForThreadId = currentThreadId;\n }\n\n scheduleCoalescedHeadlessToolFlush(handledTools, () => {\n const valuesBag = rootSnapshot.values as unknown as Record<\n string,\n unknown\n >;\n const protocolInterrupts =\n rootSnapshot.interrupts as unknown as Interrupt[];\n const valuesInterrupts = Array.isArray(valuesBag?.__interrupt__)\n ? (valuesBag.__interrupt__ as Interrupt[])\n : [];\n const headlessInterrupts =\n protocolInterrupts.length > 0 ? protocolInterrupts : valuesInterrupts;\n if (headlessInterrupts.length === 0) return;\n flushPendingHeadlessToolInterrupts(\n { ...valuesBag, __interrupt__: headlessInterrupts },\n tools,\n handledTools,\n {\n onTool,\n defer: (run) => {\n void Promise.resolve().then(run);\n },\n resumeSubmit: (command) =>\n applyHeadlessToolResumeCommand(controller, command),\n }\n );\n });\n });\n }\n\n // ─── Public handle ──────────────────────────────────────────────────\n //\n // Single stable object with getters. Getters read the runes\n // `$state` slots, which drives template reactivity automatically.\n const handle: UseStreamReturn<T, InterruptType, ConfigurableType> = {\n get values() {\n return rootSnapshot.values;\n },\n get messages() {\n return rootSnapshot.messages;\n },\n get toolCalls() {\n return rootSnapshot.toolCalls as InferToolCalls<T>[];\n },\n get interrupts() {\n return rootSnapshot.interrupts;\n },\n get interrupt() {\n return rootSnapshot.interrupt;\n },\n get isLoading() {\n return rootSnapshot.isLoading;\n },\n get isThreadLoading() {\n return rootSnapshot.isThreadLoading;\n },\n get error() {\n return rootSnapshot.error;\n },\n get threadId() {\n return rootSnapshot.threadId;\n },\n get hydrationPromise() {\n return controller.hydrationPromise;\n },\n get subagents() {\n return subagentSnapshot as UseStreamReturn<\n T,\n InterruptType,\n ConfigurableType\n >[\"subagents\"];\n },\n get subgraphs() {\n return subgraphSnapshot;\n },\n get subgraphsByNode() {\n return subgraphByNodeSnapshot;\n },\n submit: (input, submitOptions) => controller.submit(input, submitOptions),\n stop: (options) => controller.stop(options),\n disconnect: () => controller.disconnect(),\n respond: (response, options) => controller.respond(response, options),\n respondAll: (responsesById, options) =>\n controller.respondAll(responsesById, options),\n getThread: () => controller.getThread(),\n client,\n assistantId,\n [STREAM_CONTROLLER]: controller,\n };\n\n return handle;\n}\n\n/** Convenience alias for the fully-resolved stream handle type. */\nexport type UseStreamResult<\n T = Record<string, unknown>,\n InterruptType = unknown,\n ConfigurableType extends object = Record<string, unknown>,\n> = UseStreamReturn<T, InterruptType, ConfigurableType>;\n\n/**\n * Helper used by the selector composables to reach the underlying\n * {@link ChannelRegistry} from a stream handle. Kept internal —\n * application code should call `useMessages`, `useToolCalls`, etc.\n *\n * @internal\n */\nexport function getRegistry(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n stream: UseStreamReturn<any, any, any>\n): ChannelRegistry {\n return stream[STREAM_CONTROLLER].registry;\n}\n\nexport type { ThreadStream };\n"],"mappings":";;;;;AAgDA,SAAS,kBACP,OACe;AACf,KAAI,OAAO,UAAU,WAAY,QAAQ,OAAmB;AAC5D,QAAO;;;;;;;;;AA4BT,MAAa,oBAAmC,OAAO,IACrD,+BACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuTD,SAAgB,UAKd,SACqD;CAuBrD,MAAM,QAAQ;CAEd,MAAM,mBACJ,MAAM,aAAa,QAAQ,OAAO,MAAM,cAAc;CACxD,MAAM,YAAY,MAAM;CAIxB,MAAM,SACJ,MAAM,UACL,IAAIA,SAAW;EACd,QAAQ,MAAM;EACd,QAAQ,MAAM;EACd,eAAe,MAAM;EACrB,gBAAgB,MAAM;EACvB,CAAC;CAIJ,MAAM,WAAW;CACjB,MAAM,cACJ,iBAAiB,UAAW,QAAQ,eAAe,WAAY;CAEjE,MAAM,kBAAkB,kBAAkB,MAAM,SAAS,IAAI;CAK7D,MAAM,aAAa,IAAI,iBAIrB;EACA;EAGQ;EACR,UAAU;EACV;EACA,OAAO,mBAAmB,KAAA,IAAY,MAAM;EAC5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ain/svelte",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "Svelte integration for LangGraph & LangChain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"directory": "libs/sdk-svelte"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@langchain/langgraph-sdk": "1.9.
|
|
13
|
+
"@langchain/langgraph-sdk": "1.9.17"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@hono/node-server": "^1.19.13",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"@vitest/browser": "^4.1.8",
|
|
22
22
|
"@vitest/browser-webdriverio": "^4.1.8",
|
|
23
23
|
"deepagents": "^1.8.3",
|
|
24
|
-
"hono": "^4.12.
|
|
24
|
+
"hono": "^4.12.21",
|
|
25
25
|
"langchain": "^1.4.4",
|
|
26
26
|
"svelte": "^5.56.1",
|
|
27
27
|
"typescript": "^5.9.3",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"vitest-browser-svelte": "^2.1.1",
|
|
30
30
|
"webdriverio": "^9.25.0",
|
|
31
31
|
"zod": "^4.3.6",
|
|
32
|
-
"@langchain/langgraph": "^1.3.
|
|
33
|
-
"@langchain/langgraph-api": "^1.2.
|
|
32
|
+
"@langchain/langgraph": "^1.3.6",
|
|
33
|
+
"@langchain/langgraph-api": "^1.2.5",
|
|
34
34
|
"@langchain/langgraph-checkpoint": "^1.0.4"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|