@langchain/vue 0.2.0 → 0.3.1
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/index.cjs +106 -456
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -21
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +6 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +108 -458
- package/dist/index.js.map +1 -1
- package/dist/stream.custom.cjs +63 -161
- package/dist/stream.custom.cjs.map +1 -1
- package/dist/stream.custom.js +65 -163
- package/dist/stream.custom.js.map +1 -1
- package/package.json +3 -3
package/dist/stream.custom.js
CHANGED
|
@@ -1,209 +1,111 @@
|
|
|
1
|
-
import { onScopeDispose, ref, shallowRef, toValue, watch } from "vue";
|
|
2
|
-
import {
|
|
3
|
-
import { getToolCallsWithResults } from "@langchain/langgraph-sdk/utils";
|
|
1
|
+
import { computed, onScopeDispose, reactive, ref, shallowRef, toValue, watch } from "vue";
|
|
2
|
+
import { CustomStreamOrchestrator, ensureMessageInstances } from "@langchain/langgraph-sdk/ui";
|
|
4
3
|
//#region src/stream.custom.ts
|
|
5
|
-
function createCustomTransportThreadState(values, threadId) {
|
|
6
|
-
return {
|
|
7
|
-
values,
|
|
8
|
-
next: [],
|
|
9
|
-
tasks: [],
|
|
10
|
-
metadata: void 0,
|
|
11
|
-
created_at: null,
|
|
12
|
-
checkpoint: {
|
|
13
|
-
thread_id: threadId,
|
|
14
|
-
checkpoint_id: null,
|
|
15
|
-
checkpoint_ns: "",
|
|
16
|
-
checkpoint_map: null
|
|
17
|
-
},
|
|
18
|
-
parent_checkpoint: null
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
4
|
function useStreamCustom(options) {
|
|
22
|
-
const
|
|
23
|
-
const stream = new StreamManager(messageManager, {
|
|
24
|
-
throttle: options.throttle ?? false,
|
|
25
|
-
subagentToolNames: options.subagentToolNames,
|
|
26
|
-
filterSubagentMessages: options.filterSubagentMessages,
|
|
27
|
-
toMessage: toMessageClass
|
|
28
|
-
});
|
|
29
|
-
const streamValues = shallowRef(stream.values);
|
|
30
|
-
const streamError = shallowRef(stream.error);
|
|
31
|
-
const isLoading = shallowRef(stream.isLoading);
|
|
32
|
-
const subagentVersion = shallowRef(0);
|
|
33
|
-
const unsubscribe = stream.subscribe(() => {
|
|
34
|
-
streamValues.value = stream.values;
|
|
35
|
-
streamError.value = stream.error;
|
|
36
|
-
isLoading.value = stream.isLoading;
|
|
37
|
-
subagentVersion.value += 1;
|
|
38
|
-
});
|
|
5
|
+
const orchestrator = new CustomStreamOrchestrator(options);
|
|
39
6
|
const branch = ref("");
|
|
40
7
|
let threadId = toValue(options.threadId) ?? null;
|
|
41
8
|
watch(() => toValue(options.threadId), (newId) => {
|
|
42
9
|
const resolved = newId ?? null;
|
|
43
10
|
if (resolved !== threadId) {
|
|
44
11
|
threadId = resolved;
|
|
45
|
-
|
|
12
|
+
orchestrator.syncThreadId(resolved);
|
|
46
13
|
}
|
|
47
14
|
}, { flush: "sync" });
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
15
|
+
const streamValues = shallowRef(null);
|
|
16
|
+
const streamError = shallowRef(void 0);
|
|
17
|
+
const isLoading = shallowRef(false);
|
|
18
|
+
const subagentsRef = shallowRef(orchestrator.subagents);
|
|
19
|
+
const activeSubagentsRef = shallowRef(orchestrator.activeSubagents);
|
|
20
|
+
const unsubscribe = orchestrator.subscribe(() => {
|
|
21
|
+
streamValues.value = orchestrator.streamValues;
|
|
22
|
+
streamError.value = orchestrator.error;
|
|
23
|
+
isLoading.value = orchestrator.isLoading;
|
|
24
|
+
subagentsRef.value = orchestrator.subagents;
|
|
25
|
+
activeSubagentsRef.value = orchestrator.activeSubagents;
|
|
26
|
+
});
|
|
60
27
|
onScopeDispose(() => {
|
|
61
28
|
unsubscribe();
|
|
62
|
-
|
|
29
|
+
orchestrator.dispose();
|
|
63
30
|
});
|
|
64
|
-
const historyMessages = getMessages(historyValues);
|
|
65
|
-
options.filterSubagentMessages && !stream.isLoading && historyMessages.length;
|
|
66
31
|
watch(() => ({
|
|
67
|
-
should: options.filterSubagentMessages && !isLoading.value &&
|
|
68
|
-
len:
|
|
32
|
+
should: options.filterSubagentMessages && !isLoading.value && streamValues.value != null && orchestrator.messages.length > 0,
|
|
33
|
+
len: orchestrator.messages.length
|
|
69
34
|
}), ({ should }) => {
|
|
70
|
-
if (should)
|
|
35
|
+
if (should) orchestrator.reconstructSubagentsIfNeeded();
|
|
71
36
|
}, { immediate: true });
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
stream.setStreamValues(() => {
|
|
89
|
-
if (submitOptions?.optimisticValues != null) return {
|
|
90
|
-
...historyValues,
|
|
91
|
-
...typeof submitOptions.optimisticValues === "function" ? submitOptions.optimisticValues(historyValues) : submitOptions.optimisticValues
|
|
92
|
-
};
|
|
93
|
-
return { ...historyValues };
|
|
94
|
-
});
|
|
95
|
-
await stream.start(async (signal) => {
|
|
96
|
-
if (!usableThreadId) {
|
|
97
|
-
usableThreadId = crypto.randomUUID();
|
|
98
|
-
threadId = usableThreadId;
|
|
99
|
-
options.onThreadId?.(usableThreadId);
|
|
100
|
-
}
|
|
101
|
-
if (!usableThreadId) throw new Error("Failed to obtain valid thread ID.");
|
|
102
|
-
return options.transport.stream({
|
|
103
|
-
input: values,
|
|
104
|
-
context: submitOptions?.context,
|
|
105
|
-
command: submitOptions?.command,
|
|
106
|
-
streamSubgraphs: submitOptions?.streamSubgraphs,
|
|
107
|
-
signal,
|
|
108
|
-
config: {
|
|
109
|
-
...submitOptions?.config,
|
|
110
|
-
configurable: {
|
|
111
|
-
thread_id: usableThreadId,
|
|
112
|
-
...submitOptions?.config?.configurable
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}, {
|
|
117
|
-
getMessages,
|
|
118
|
-
setMessages,
|
|
119
|
-
initialValues: {},
|
|
120
|
-
callbacks: options,
|
|
121
|
-
onSuccess: () => {
|
|
122
|
-
if (!usableThreadId) return void 0;
|
|
123
|
-
const finalValues = stream.values ?? historyValues;
|
|
124
|
-
options.onFinish?.(createCustomTransportThreadState(finalValues, usableThreadId), void 0);
|
|
125
|
-
},
|
|
126
|
-
onError(error) {
|
|
127
|
-
options.onError?.(error, void 0);
|
|
128
|
-
submitOptions?.onError?.(error, void 0);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
async function submit(values, submitOptions) {
|
|
133
|
-
await submitDirect(values, submitOptions);
|
|
134
|
-
}
|
|
135
|
-
function setBranch(value) {
|
|
136
|
-
branch.value = value;
|
|
137
|
-
}
|
|
138
|
-
function getMessagesMetadata(message, index) {
|
|
139
|
-
const streamMetadata = messageManager.get(message.id)?.metadata;
|
|
140
|
-
if (streamMetadata != null) return {
|
|
141
|
-
messageId: message.id ?? String(index),
|
|
142
|
-
firstSeenState: void 0,
|
|
143
|
-
branch: void 0,
|
|
144
|
-
branchOptions: void 0,
|
|
145
|
-
streamMetadata
|
|
146
|
-
};
|
|
147
|
-
}
|
|
37
|
+
const interruptsComputed = computed(() => {
|
|
38
|
+
isLoading.value;
|
|
39
|
+
return orchestrator.interrupts;
|
|
40
|
+
});
|
|
41
|
+
const interruptComputed = computed(() => {
|
|
42
|
+
isLoading.value;
|
|
43
|
+
return orchestrator.interrupt;
|
|
44
|
+
});
|
|
45
|
+
const messagesComputed = computed(() => {
|
|
46
|
+
if (!streamValues.value) return [];
|
|
47
|
+
return ensureMessageInstances(orchestrator.messages);
|
|
48
|
+
});
|
|
49
|
+
const toolCallsComputed = computed(() => {
|
|
50
|
+
if (!streamValues.value) return [];
|
|
51
|
+
return orchestrator.toolCalls;
|
|
52
|
+
});
|
|
148
53
|
return {
|
|
149
54
|
get values() {
|
|
150
55
|
return streamValues.value ?? {};
|
|
151
56
|
},
|
|
152
57
|
error: streamError,
|
|
153
58
|
isLoading,
|
|
154
|
-
stop,
|
|
155
|
-
submit,
|
|
156
|
-
|
|
59
|
+
stop: () => orchestrator.stop(),
|
|
60
|
+
submit: async (values, submitOptions) => {
|
|
61
|
+
await orchestrator.submit(values, submitOptions);
|
|
62
|
+
},
|
|
63
|
+
switchThread(newThreadId) {
|
|
64
|
+
orchestrator.switchThread(newThreadId);
|
|
65
|
+
},
|
|
157
66
|
branch,
|
|
158
|
-
setBranch
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return false;
|
|
165
|
-
},
|
|
166
|
-
async clear() {}
|
|
67
|
+
setBranch(value) {
|
|
68
|
+
branch.value = value;
|
|
69
|
+
orchestrator.setBranch(value);
|
|
70
|
+
},
|
|
71
|
+
getMessagesMetadata(message, index) {
|
|
72
|
+
return orchestrator.getMessagesMetadata(message, index);
|
|
167
73
|
},
|
|
74
|
+
queue: reactive({
|
|
75
|
+
entries: shallowRef([]),
|
|
76
|
+
size: shallowRef(0),
|
|
77
|
+
cancel: async () => false,
|
|
78
|
+
clear: async () => {}
|
|
79
|
+
}),
|
|
168
80
|
get interrupts() {
|
|
169
|
-
|
|
170
|
-
const valueInterrupts = streamValues.value.__interrupt__;
|
|
171
|
-
if (valueInterrupts.length === 0) return [{ when: "breakpoint" }];
|
|
172
|
-
return valueInterrupts;
|
|
173
|
-
}
|
|
174
|
-
return [];
|
|
81
|
+
return interruptsComputed.value;
|
|
175
82
|
},
|
|
176
83
|
get interrupt() {
|
|
177
|
-
return
|
|
84
|
+
return interruptComputed.value;
|
|
178
85
|
},
|
|
179
86
|
get messages() {
|
|
180
|
-
|
|
181
|
-
return ensureMessageInstances(getMessages(streamValues.value));
|
|
87
|
+
return messagesComputed.value;
|
|
182
88
|
},
|
|
183
89
|
get toolCalls() {
|
|
184
|
-
|
|
185
|
-
return getToolCallsWithResults(getMessages(streamValues.value));
|
|
90
|
+
return toolCallsComputed.value;
|
|
186
91
|
},
|
|
187
92
|
getToolCalls(message) {
|
|
188
|
-
|
|
189
|
-
return getToolCallsWithResults(getMessages(streamValues.value)).filter((tc) => tc.aiMessage.id === message.id);
|
|
93
|
+
return orchestrator.getToolCalls(message);
|
|
190
94
|
},
|
|
191
95
|
get subagents() {
|
|
192
|
-
|
|
193
|
-
return stream.getSubagents();
|
|
96
|
+
return subagentsRef.value;
|
|
194
97
|
},
|
|
195
98
|
get activeSubagents() {
|
|
196
|
-
|
|
197
|
-
return stream.getActiveSubagents();
|
|
99
|
+
return activeSubagentsRef.value;
|
|
198
100
|
},
|
|
199
101
|
getSubagent(toolCallId) {
|
|
200
|
-
return
|
|
102
|
+
return orchestrator.getSubagent(toolCallId);
|
|
201
103
|
},
|
|
202
104
|
getSubagentsByType(type) {
|
|
203
|
-
return
|
|
105
|
+
return orchestrator.getSubagentsByType(type);
|
|
204
106
|
},
|
|
205
107
|
getSubagentsByMessage(messageId) {
|
|
206
|
-
return
|
|
108
|
+
return orchestrator.getSubagentsByMessage(messageId);
|
|
207
109
|
}
|
|
208
110
|
};
|
|
209
111
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.custom.js","names":[],"sources":["../src/stream.custom.ts"],"sourcesContent":["import { onScopeDispose, ref, shallowRef, toValue, watch } from \"vue\";\nimport {\n StreamManager,\n MessageTupleManager,\n extractInterrupts,\n toMessageClass,\n ensureMessageInstances,\n type EventStreamEvent,\n type GetUpdateType,\n type GetCustomEventType,\n type GetInterruptType,\n type GetConfigurableType,\n type AnyStreamCustomOptions,\n type CustomSubmitOptions,\n type MessageMetadata,\n} from \"@langchain/langgraph-sdk/ui\";\nimport { getToolCallsWithResults } from \"@langchain/langgraph-sdk/utils\";\nimport type {\n BagTemplate,\n Message,\n Interrupt,\n ThreadState,\n} from \"@langchain/langgraph-sdk\";\nimport type { VueReactiveOptions } from \"./types.js\";\n\nfunction createCustomTransportThreadState<\n StateType extends Record<string, unknown>,\n>(values: StateType, threadId: string): ThreadState<StateType> {\n return {\n values,\n next: [],\n tasks: [],\n metadata: undefined,\n created_at: null,\n checkpoint: {\n thread_id: threadId,\n checkpoint_id: null,\n checkpoint_ns: \"\",\n checkpoint_map: null,\n },\n parent_checkpoint: null,\n };\n}\n\nexport function useStreamCustom<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate,\n>(options: VueReactiveOptions<AnyStreamCustomOptions<StateType, Bag>>) {\n type UpdateType = GetUpdateType<Bag, StateType>;\n type CustomType = GetCustomEventType<Bag>;\n type InterruptType = GetInterruptType<Bag>;\n type ConfigurableType = GetConfigurableType<Bag>;\n\n const messageManager = new MessageTupleManager();\n const stream = new StreamManager<StateType, Bag>(messageManager, {\n throttle: options.throttle ?? false,\n subagentToolNames: options.subagentToolNames,\n filterSubagentMessages: options.filterSubagentMessages,\n toMessage: toMessageClass,\n });\n\n const streamValues = shallowRef<StateType | null>(stream.values);\n const streamError = shallowRef<unknown>(stream.error);\n const isLoading = shallowRef(stream.isLoading);\n\n const subagentVersion = shallowRef(0);\n\n const unsubscribe = stream.subscribe(() => {\n streamValues.value = stream.values;\n streamError.value = stream.error;\n isLoading.value = stream.isLoading;\n subagentVersion.value += 1;\n });\n\n const branch = ref<string>(\"\");\n\n let threadId: string | null = toValue(options.threadId) ?? null;\n\n watch(\n () => toValue(options.threadId),\n (newId) => {\n const resolved = newId ?? null;\n if (resolved !== threadId) {\n threadId = resolved;\n stream.clear();\n }\n },\n { flush: \"sync\" },\n );\n\n const getMessages = (value: StateType): Message[] => {\n const messagesKey = toValue(options.messagesKey) ?? \"messages\";\n return Array.isArray(value[messagesKey])\n ? (value[messagesKey] as Message[])\n : [];\n };\n\n const setMessages = (current: StateType, messages: Message[]): StateType => {\n const messagesKey = toValue(options.messagesKey) ?? \"messages\";\n return { ...current, [messagesKey]: messages };\n };\n\n const historyValues = options.initialValues ?? ({} as StateType);\n\n onScopeDispose(() => {\n unsubscribe();\n void stream.stop(historyValues, { onStop: options.onStop });\n });\n\n const historyMessages = getMessages(historyValues);\n // @ts-expect-error used in watch callback below\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const shouldReconstructSubagents =\n options.filterSubagentMessages &&\n !stream.isLoading &&\n historyMessages.length > 0;\n\n watch(\n () => ({\n should:\n options.filterSubagentMessages &&\n !isLoading.value &&\n getMessages(historyValues).length > 0,\n len: getMessages(historyValues).length,\n }),\n ({ should }) => {\n if (should) {\n stream.reconstructSubagents(getMessages(historyValues), {\n skipIfPopulated: true,\n });\n }\n },\n { immediate: true },\n );\n\n function switchThread(newThreadId: string | null) {\n if (newThreadId !== threadId) {\n threadId = newThreadId;\n stream.clear();\n }\n }\n\n function stop() {\n return stream.stop(historyValues, { onStop: options.onStop });\n }\n\n async function submitDirect(\n values: UpdateType | null | undefined,\n submitOptions?: CustomSubmitOptions<StateType, ConfigurableType>,\n ) {\n const currentThreadId = toValue(options.threadId) ?? null;\n if (currentThreadId !== threadId) {\n threadId = currentThreadId;\n stream.clear();\n }\n\n let usableThreadId = threadId ?? submitOptions?.threadId;\n\n stream.setStreamValues(() => {\n if (submitOptions?.optimisticValues != null) {\n return {\n ...historyValues,\n ...(typeof submitOptions.optimisticValues === \"function\"\n ? submitOptions.optimisticValues(historyValues)\n : submitOptions.optimisticValues),\n };\n }\n\n return { ...historyValues };\n });\n\n await stream.start(\n async (signal: AbortSignal) => {\n if (!usableThreadId) {\n usableThreadId = crypto.randomUUID();\n threadId = usableThreadId;\n options.onThreadId?.(usableThreadId);\n }\n\n if (!usableThreadId) {\n throw new Error(\"Failed to obtain valid thread ID.\");\n }\n\n return options.transport.stream({\n input: values,\n context: submitOptions?.context,\n command: submitOptions?.command,\n streamSubgraphs: submitOptions?.streamSubgraphs,\n signal,\n config: {\n ...submitOptions?.config,\n configurable: {\n thread_id: usableThreadId,\n ...submitOptions?.config?.configurable,\n } as unknown as GetConfigurableType<Bag>,\n },\n }) as Promise<\n AsyncGenerator<EventStreamEvent<StateType, UpdateType, CustomType>>\n >;\n },\n {\n getMessages,\n setMessages,\n\n initialValues: {} as StateType,\n callbacks: options,\n\n onSuccess: () => {\n if (!usableThreadId) return undefined;\n\n const finalValues = stream.values ?? historyValues;\n options.onFinish?.(\n createCustomTransportThreadState(finalValues, usableThreadId),\n undefined,\n );\n\n return undefined;\n },\n onError(error) {\n options.onError?.(error, undefined);\n submitOptions?.onError?.(error, undefined);\n },\n },\n );\n }\n\n async function submit(\n values: UpdateType | null | undefined,\n submitOptions?: CustomSubmitOptions<StateType, ConfigurableType>,\n ) {\n await submitDirect(values, submitOptions);\n }\n\n function setBranch(value: string) {\n branch.value = value;\n }\n\n function getMessagesMetadata(\n message: Message,\n index?: number,\n ): MessageMetadata<StateType> | undefined {\n const streamMetadata = messageManager.get(message.id)?.metadata;\n if (streamMetadata != null) {\n return {\n messageId: message.id ?? String(index),\n firstSeenState: undefined,\n branch: undefined,\n branchOptions: undefined,\n streamMetadata,\n } as MessageMetadata<StateType>;\n }\n return undefined;\n }\n\n return {\n get values() {\n return streamValues.value ?? ({} as StateType);\n },\n\n error: streamError,\n isLoading,\n\n stop,\n submit,\n switchThread,\n\n branch,\n setBranch,\n getMessagesMetadata,\n\n queue: {\n entries: [],\n size: 0,\n async cancel() {\n return false;\n },\n async clear() {},\n },\n\n get interrupts(): Interrupt<InterruptType>[] {\n if (\n streamValues.value != null &&\n \"__interrupt__\" in streamValues.value &&\n Array.isArray(streamValues.value.__interrupt__)\n ) {\n const valueInterrupts = streamValues.value.__interrupt__;\n if (valueInterrupts.length === 0) return [{ when: \"breakpoint\" }];\n return valueInterrupts;\n }\n\n return [];\n },\n\n get interrupt(): Interrupt<InterruptType> | undefined {\n return extractInterrupts<InterruptType>(streamValues.value);\n },\n\n get messages() {\n if (!streamValues.value) return [];\n return ensureMessageInstances(getMessages(streamValues.value));\n },\n\n get toolCalls() {\n if (!streamValues.value) return [];\n return getToolCallsWithResults(getMessages(streamValues.value));\n },\n\n getToolCalls(message: Message) {\n if (!streamValues.value) return [];\n const allToolCalls = getToolCallsWithResults(\n getMessages(streamValues.value),\n );\n return allToolCalls.filter((tc) => tc.aiMessage.id === message.id);\n },\n\n get subagents() {\n void subagentVersion.value;\n return stream.getSubagents();\n },\n\n get activeSubagents() {\n void subagentVersion.value;\n return stream.getActiveSubagents();\n },\n\n getSubagent(toolCallId: string) {\n return stream.getSubagent(toolCallId);\n },\n\n getSubagentsByType(type: string) {\n return stream.getSubagentsByType(type);\n },\n\n getSubagentsByMessage(messageId: string) {\n return stream.getSubagentsByMessage(messageId);\n },\n };\n}\n"],"mappings":";;;;AAyBA,SAAS,iCAEP,QAAmB,UAA0C;AAC7D,QAAO;EACL;EACA,MAAM,EAAE;EACR,OAAO,EAAE;EACT,UAAU,KAAA;EACV,YAAY;EACZ,YAAY;GACV,WAAW;GACX,eAAe;GACf,eAAe;GACf,gBAAgB;GACjB;EACD,mBAAmB;EACpB;;AAGH,SAAgB,gBAGd,SAAqE;CAMrE,MAAM,iBAAiB,IAAI,qBAAqB;CAChD,MAAM,SAAS,IAAI,cAA8B,gBAAgB;EAC/D,UAAU,QAAQ,YAAY;EAC9B,mBAAmB,QAAQ;EAC3B,wBAAwB,QAAQ;EAChC,WAAW;EACZ,CAAC;CAEF,MAAM,eAAe,WAA6B,OAAO,OAAO;CAChE,MAAM,cAAc,WAAoB,OAAO,MAAM;CACrD,MAAM,YAAY,WAAW,OAAO,UAAU;CAE9C,MAAM,kBAAkB,WAAW,EAAE;CAErC,MAAM,cAAc,OAAO,gBAAgB;AACzC,eAAa,QAAQ,OAAO;AAC5B,cAAY,QAAQ,OAAO;AAC3B,YAAU,QAAQ,OAAO;AACzB,kBAA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import {\n computed,\n onScopeDispose,\n reactive,\n ref,\n shallowRef,\n toValue,\n watch,\n} from \"vue\";\nimport {\n CustomStreamOrchestrator,\n ensureMessageInstances,\n type AnyStreamCustomOptions,\n type CustomSubmitOptions,\n type GetUpdateType,\n type GetInterruptType,\n type GetConfigurableType,\n type MessageMetadata,\n} from \"@langchain/langgraph-sdk/ui\";\nimport type { BagTemplate, Message, Interrupt } from \"@langchain/langgraph-sdk\";\nimport type { VueReactiveOptions } from \"./types.js\";\n\nexport function useStreamCustom<\n StateType extends Record<string, unknown> = Record<string, unknown>,\n Bag extends BagTemplate = BagTemplate,\n>(options: VueReactiveOptions<AnyStreamCustomOptions<StateType, Bag>>) {\n type UpdateType = GetUpdateType<Bag, StateType>;\n type InterruptType = GetInterruptType<Bag>;\n type ConfigurableType = GetConfigurableType<Bag>;\n\n const orchestrator = new CustomStreamOrchestrator<StateType, Bag>(\n options as unknown as AnyStreamCustomOptions<StateType, Bag>,\n );\n\n const branch = ref<string>(\"\");\n\n let threadId: string | null = toValue(options.threadId) ?? null;\n\n watch(\n () => toValue(options.threadId),\n (newId) => {\n const resolved = newId ?? null;\n if (resolved !== threadId) {\n threadId = resolved;\n orchestrator.syncThreadId(resolved);\n }\n },\n { flush: \"sync\" },\n );\n\n const streamValues = shallowRef<StateType | null>(null);\n const streamError = shallowRef<unknown>(undefined);\n const isLoading = shallowRef(false);\n const subagentsRef = shallowRef(orchestrator.subagents);\n const activeSubagentsRef = shallowRef(orchestrator.activeSubagents);\n\n const unsubscribe = orchestrator.subscribe(() => {\n streamValues.value = orchestrator.streamValues;\n streamError.value = orchestrator.error;\n isLoading.value = orchestrator.isLoading;\n subagentsRef.value = orchestrator.subagents;\n activeSubagentsRef.value = orchestrator.activeSubagents;\n });\n\n onScopeDispose(() => {\n unsubscribe();\n orchestrator.dispose();\n });\n\n watch(\n () => ({\n should:\n options.filterSubagentMessages &&\n !isLoading.value &&\n streamValues.value != null &&\n orchestrator.messages.length > 0,\n len: orchestrator.messages.length,\n }),\n ({ should }) => {\n if (should) {\n orchestrator.reconstructSubagentsIfNeeded();\n }\n },\n { immediate: true },\n );\n\n // Cached computed properties — unlike plain getters, `computed()` only\n // recomputes when a tracked dependency changes, and caches the result\n // between reads. Getters below unwrap `.value` so callers see plain\n // values (matching the original API surface).\n //\n // `void isLoading.value` / reading `streamValues.value` accesses the\n // ref solely to register it as a dependency of the computed, so Vue\n // knows to invalidate the cached value when the orchestrator pushes an\n // update. The `void` operator discards the unused value and signals\n // intent to future readers.\n const interruptsComputed = computed(() => {\n void isLoading.value;\n return orchestrator.interrupts as Interrupt<InterruptType>[];\n });\n\n const interruptComputed = computed(() => {\n void isLoading.value;\n return orchestrator.interrupt as Interrupt<InterruptType> | undefined;\n });\n\n const messagesComputed = computed(() => {\n if (!streamValues.value) return [];\n return ensureMessageInstances(orchestrator.messages);\n });\n\n const toolCallsComputed = computed(() => {\n if (!streamValues.value) return [];\n return orchestrator.toolCalls;\n });\n\n const queueEntries = shallowRef<unknown[]>([]);\n const queueSize = shallowRef(0);\n\n return {\n get values() {\n return streamValues.value ?? ({} as StateType);\n },\n\n error: streamError,\n isLoading,\n\n stop: () => orchestrator.stop(),\n\n submit: async (\n values: UpdateType | null | undefined,\n submitOptions?: CustomSubmitOptions<StateType, ConfigurableType>,\n ) => {\n await orchestrator.submit(values, submitOptions);\n },\n\n switchThread(newThreadId: string | null) {\n orchestrator.switchThread(newThreadId);\n },\n\n branch,\n setBranch(value: string) {\n branch.value = value;\n orchestrator.setBranch(value);\n },\n\n getMessagesMetadata(\n message: Message,\n index?: number,\n ): MessageMetadata<StateType> | undefined {\n return orchestrator.getMessagesMetadata(message, index);\n },\n\n queue: reactive({\n entries: queueEntries,\n size: queueSize,\n cancel: async () => false,\n clear: async () => {},\n }),\n\n get interrupts(): Interrupt<InterruptType>[] {\n return interruptsComputed.value;\n },\n get interrupt(): Interrupt<InterruptType> | undefined {\n return interruptComputed.value;\n },\n get messages() {\n return messagesComputed.value;\n },\n get toolCalls() {\n return toolCallsComputed.value;\n },\n\n getToolCalls(message: Message) {\n return orchestrator.getToolCalls(message);\n },\n\n get subagents() {\n return subagentsRef.value;\n },\n\n get activeSubagents() {\n return activeSubagentsRef.value;\n },\n\n getSubagent(toolCallId: string) {\n return orchestrator.getSubagent(toolCallId);\n },\n getSubagentsByType(type: string) {\n return orchestrator.getSubagentsByType(type);\n },\n getSubagentsByMessage(messageId: string) {\n return orchestrator.getSubagentsByMessage(messageId);\n },\n };\n}\n"],"mappings":";;;AAsBA,SAAgB,gBAGd,SAAqE;CAKrE,MAAM,eAAe,IAAI,yBACvB,QACD;CAED,MAAM,SAAS,IAAY,GAAG;CAE9B,IAAI,WAA0B,QAAQ,QAAQ,SAAS,IAAI;AAE3D,aACQ,QAAQ,QAAQ,SAAS,GAC9B,UAAU;EACT,MAAM,WAAW,SAAS;AAC1B,MAAI,aAAa,UAAU;AACzB,cAAW;AACX,gBAAa,aAAa,SAAS;;IAGvC,EAAE,OAAO,QAAQ,CAClB;CAED,MAAM,eAAe,WAA6B,KAAK;CACvD,MAAM,cAAc,WAAoB,KAAA,EAAU;CAClD,MAAM,YAAY,WAAW,MAAM;CACnC,MAAM,eAAe,WAAW,aAAa,UAAU;CACvD,MAAM,qBAAqB,WAAW,aAAa,gBAAgB;CAEnE,MAAM,cAAc,aAAa,gBAAgB;AAC/C,eAAa,QAAQ,aAAa;AAClC,cAAY,QAAQ,aAAa;AACjC,YAAU,QAAQ,aAAa;AAC/B,eAAa,QAAQ,aAAa;AAClC,qBAAmB,QAAQ,aAAa;GACxC;AAEF,sBAAqB;AACnB,eAAa;AACb,eAAa,SAAS;GACtB;AAEF,cACS;EACL,QACE,QAAQ,0BACR,CAAC,UAAU,SACX,aAAa,SAAS,QACtB,aAAa,SAAS,SAAS;EACjC,KAAK,aAAa,SAAS;EAC5B,IACA,EAAE,aAAa;AACd,MAAI,OACF,cAAa,8BAA8B;IAG/C,EAAE,WAAW,MAAM,CACpB;CAYD,MAAM,qBAA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,sBAAsB,UAAU;;EAEvD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Vue integration for LangGraph & LangChain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"directory": "libs/sdk-vue"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@langchain/langgraph-sdk": "^1.
|
|
13
|
+
"@langchain/langgraph-sdk": "^1.8.1"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
16
|
"@hono/node-server": "^1.19.11",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"vue": "^3.5.30",
|
|
39
39
|
"webdriverio": "^9.25.0",
|
|
40
40
|
"zod": "^4.3.6",
|
|
41
|
-
"@langchain/langgraph": "1.2.
|
|
41
|
+
"@langchain/langgraph": "1.2.6",
|
|
42
42
|
"@langchain/langgraph-api": "1.1.16",
|
|
43
43
|
"@langchain/langgraph-checkpoint": "1.0.1"
|
|
44
44
|
},
|