@langchain/vue 0.1.3 → 0.3.0
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/README.md +122 -19
- package/dist/context.cjs +112 -0
- package/dist/context.cjs.map +1 -0
- package/dist/context.d.cts +112 -0
- package/dist/context.d.cts.map +1 -0
- package/dist/context.d.ts +112 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +109 -0
- package/dist/context.js.map +1 -0
- package/dist/index.cjs +129 -421
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -16
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +7 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +128 -424
- package/dist/index.js.map +1 -1
- package/dist/stream.custom.cjs +46 -133
- package/dist/stream.custom.cjs.map +1 -1
- package/dist/stream.custom.js +48 -135
- package/dist/stream.custom.js.map +1 -1
- package/dist/types.d.cts +28 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +28 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +6 -8
package/dist/index.cjs
CHANGED
|
@@ -1,471 +1,175 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_stream_custom = require("./stream.custom.cjs");
|
|
3
|
+
const require_context = require("./context.cjs");
|
|
3
4
|
let vue = require("vue");
|
|
4
5
|
let _langchain_langgraph_sdk_ui = require("@langchain/langgraph-sdk/ui");
|
|
5
|
-
let _langchain_langgraph_sdk_utils = require("@langchain/langgraph-sdk/utils");
|
|
6
6
|
let _langchain_langgraph_sdk = require("@langchain/langgraph-sdk");
|
|
7
7
|
//#region src/index.ts
|
|
8
|
-
function fetchHistory(client, threadId, options) {
|
|
9
|
-
if (options?.limit === false) return client.threads.getState(threadId).then((state) => {
|
|
10
|
-
if (state.checkpoint == null) return [];
|
|
11
|
-
return [state];
|
|
12
|
-
});
|
|
13
|
-
const limit = typeof options?.limit === "number" ? options.limit : 10;
|
|
14
|
-
return client.threads.getHistory(threadId, { limit });
|
|
15
|
-
}
|
|
16
8
|
function useStreamLGP(options) {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
const setMessages = (current, messages) => {
|
|
29
|
-
const messagesKey = options.messagesKey ?? "messages";
|
|
30
|
-
return {
|
|
31
|
-
...current,
|
|
32
|
-
[messagesKey]: messages
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
const historyLimit = typeof options.fetchStateHistory === "object" && options.fetchStateHistory != null ? options.fetchStateHistory.limit ?? false : options.fetchStateHistory ?? false;
|
|
36
|
-
const threadId = (0, vue.ref)(void 0);
|
|
37
|
-
let threadIdPromise = null;
|
|
38
|
-
const client = options.client ?? new _langchain_langgraph_sdk.Client({ apiUrl: options.apiUrl });
|
|
39
|
-
const history = (0, vue.shallowRef)({
|
|
40
|
-
data: void 0,
|
|
41
|
-
error: void 0,
|
|
42
|
-
isLoading: false,
|
|
43
|
-
mutate: async () => void 0
|
|
44
|
-
});
|
|
45
|
-
async function mutate(mutateId) {
|
|
46
|
-
const tid = mutateId ?? threadId.value;
|
|
47
|
-
if (!tid) return void 0;
|
|
48
|
-
try {
|
|
49
|
-
const data = await fetchHistory(client, tid, { limit: historyLimit });
|
|
50
|
-
history.value = {
|
|
51
|
-
data,
|
|
52
|
-
error: void 0,
|
|
53
|
-
isLoading: false,
|
|
54
|
-
mutate
|
|
55
|
-
};
|
|
56
|
-
return data;
|
|
57
|
-
} catch (err) {
|
|
58
|
-
history.value = {
|
|
59
|
-
...history.value,
|
|
60
|
-
error: err,
|
|
61
|
-
isLoading: false
|
|
62
|
-
};
|
|
63
|
-
options.onError?.(err, void 0);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
history.value = {
|
|
68
|
-
...history.value,
|
|
69
|
-
mutate
|
|
70
|
-
};
|
|
71
|
-
const branch = (0, vue.ref)("");
|
|
72
|
-
const branchContext = (0, vue.computed)(() => (0, _langchain_langgraph_sdk_ui.getBranchContext)(branch.value, history.value.data ?? void 0));
|
|
73
|
-
const messageManager = new _langchain_langgraph_sdk_ui.MessageTupleManager();
|
|
74
|
-
const stream = new _langchain_langgraph_sdk_ui.StreamManager(messageManager, {
|
|
75
|
-
throttle: options.throttle ?? false,
|
|
76
|
-
subagentToolNames: options.subagentToolNames,
|
|
77
|
-
filterSubagentMessages: options.filterSubagentMessages,
|
|
78
|
-
toMessage: _langchain_langgraph_sdk_ui.toMessageClass
|
|
79
|
-
});
|
|
80
|
-
const pendingRuns = new _langchain_langgraph_sdk_ui.PendingRunsTracker();
|
|
81
|
-
const queueEntries = (0, vue.shallowRef)(pendingRuns.entries);
|
|
82
|
-
const queueSize = (0, vue.ref)(pendingRuns.size);
|
|
83
|
-
const trackedStreamModes = [];
|
|
84
|
-
function trackStreamMode(...modes) {
|
|
85
|
-
for (const mode of modes) if (!trackedStreamModes.includes(mode)) trackedStreamModes.push(mode);
|
|
86
|
-
}
|
|
87
|
-
const callbackStreamModes = [];
|
|
88
|
-
if (options.onUpdateEvent) callbackStreamModes.push("updates");
|
|
89
|
-
if (options.onCustomEvent) callbackStreamModes.push("custom");
|
|
90
|
-
if (options.onCheckpointEvent) callbackStreamModes.push("checkpoints");
|
|
91
|
-
if (options.onTaskEvent) callbackStreamModes.push("tasks");
|
|
92
|
-
if ("onDebugEvent" in options && options.onDebugEvent) callbackStreamModes.push("debug");
|
|
93
|
-
if ("onLangChainEvent" in options && options.onLangChainEvent) callbackStreamModes.push("events");
|
|
94
|
-
const historyValues = (0, vue.computed)(() => branchContext.value.threadHead?.values ?? options.initialValues ?? {});
|
|
95
|
-
const historyError = (0, vue.computed)(() => {
|
|
96
|
-
const error = branchContext.value.threadHead?.tasks?.at(-1)?.error;
|
|
97
|
-
if (error == null) return void 0;
|
|
98
|
-
try {
|
|
99
|
-
const parsed = JSON.parse(error);
|
|
100
|
-
if (_langchain_langgraph_sdk_ui.StreamError.isStructuredError(parsed)) return new _langchain_langgraph_sdk_ui.StreamError(parsed);
|
|
101
|
-
return parsed;
|
|
102
|
-
} catch {}
|
|
103
|
-
return error;
|
|
9
|
+
const pluginOptions = (0, vue.inject)(require_context.LANGCHAIN_OPTIONS, {});
|
|
10
|
+
const client = (0, vue.computed)(() => {
|
|
11
|
+
const c = (0, vue.toValue)(options.client) ?? pluginOptions.client;
|
|
12
|
+
if (c) return c;
|
|
13
|
+
return new _langchain_langgraph_sdk.Client({
|
|
14
|
+
apiUrl: (0, vue.toValue)(options.apiUrl) ?? pluginOptions.apiUrl,
|
|
15
|
+
apiKey: (0, vue.toValue)(options.apiKey) ?? pluginOptions.apiKey,
|
|
16
|
+
callerOptions: (0, vue.toValue)(options.callerOptions),
|
|
17
|
+
defaultHeaders: (0, vue.toValue)(options.defaultHeaders)
|
|
18
|
+
});
|
|
104
19
|
});
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const error = (0, vue.computed)(() => streamError.value ?? historyError.value ?? history.value.error);
|
|
110
|
-
const messageMetadata = (0, vue.computed)(() => (0, _langchain_langgraph_sdk_ui.getMessagesMetadataMap)({
|
|
111
|
-
initialValues: options.initialValues,
|
|
112
|
-
history: history.value.data,
|
|
113
|
-
getMessages,
|
|
114
|
-
branchContext: branchContext.value
|
|
115
|
-
}));
|
|
116
|
-
const subagentVersion = (0, vue.shallowRef)(0);
|
|
117
|
-
const unsubscribe = stream.subscribe(() => {
|
|
118
|
-
streamValues.value = stream.values;
|
|
119
|
-
streamError.value = stream.error;
|
|
120
|
-
isLoading.value = stream.isLoading;
|
|
121
|
-
subagentVersion.value += 1;
|
|
20
|
+
const orchestrator = new _langchain_langgraph_sdk_ui.StreamOrchestrator(options, {
|
|
21
|
+
getClient: () => client.value,
|
|
22
|
+
getAssistantId: () => (0, vue.toValue)(options.assistantId),
|
|
23
|
+
getMessagesKey: () => (0, vue.toValue)(options.messagesKey) ?? "messages"
|
|
122
24
|
});
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
25
|
+
const initialThreadId = (0, vue.toValue)(options.threadId) ?? void 0;
|
|
26
|
+
orchestrator.initThreadId(initialThreadId);
|
|
27
|
+
(0, vue.watch)(() => (0, vue.toValue)(options.threadId), (newId) => {
|
|
28
|
+
const resolved = newId ?? void 0;
|
|
29
|
+
orchestrator.setThreadId(resolved);
|
|
30
|
+
}, { flush: "sync" });
|
|
31
|
+
const version = (0, vue.shallowRef)(0);
|
|
32
|
+
const subagentsRef = (0, vue.shallowRef)(orchestrator.subagents);
|
|
33
|
+
const activeSubagentsRef = (0, vue.shallowRef)(orchestrator.activeSubagents);
|
|
34
|
+
const unsubscribe = orchestrator.subscribe(() => {
|
|
35
|
+
version.value += 1;
|
|
36
|
+
subagentsRef.value = orchestrator.subagents;
|
|
37
|
+
activeSubagentsRef.value = orchestrator.activeSubagents;
|
|
126
38
|
});
|
|
127
39
|
(0, vue.onScopeDispose)(() => {
|
|
128
40
|
unsubscribe();
|
|
129
|
-
|
|
130
|
-
stop();
|
|
41
|
+
orchestrator.dispose();
|
|
131
42
|
});
|
|
132
43
|
(0, vue.watch)(() => {
|
|
133
|
-
|
|
44
|
+
version.value;
|
|
45
|
+
const hvMessages = orchestrator.messages;
|
|
134
46
|
return {
|
|
135
|
-
should: options.filterSubagentMessages && !isLoading
|
|
47
|
+
should: options.filterSubagentMessages && !orchestrator.isLoading && !orchestrator.historyData.isLoading && hvMessages.length > 0,
|
|
136
48
|
len: hvMessages.length
|
|
137
49
|
};
|
|
138
|
-
}, ({ should }) => {
|
|
50
|
+
}, ({ should }, _prev, onCleanup) => {
|
|
139
51
|
if (should) {
|
|
140
|
-
const
|
|
141
|
-
|
|
52
|
+
const controller = orchestrator.reconstructSubagentsIfNeeded();
|
|
53
|
+
if (controller) onCleanup(() => controller.abort());
|
|
142
54
|
}
|
|
143
55
|
}, { immediate: true });
|
|
144
|
-
function stop() {
|
|
145
|
-
return stream.stop(historyValues.value, { onStop: (args) => {
|
|
146
|
-
if (runMetadataStorage && threadId.value) {
|
|
147
|
-
const runId = runMetadataStorage.getItem(`lg:stream:${threadId.value}`);
|
|
148
|
-
if (runId) client.runs.cancel(threadId.value, runId);
|
|
149
|
-
runMetadataStorage.removeItem(`lg:stream:${threadId.value}`);
|
|
150
|
-
}
|
|
151
|
-
options.onStop?.(args);
|
|
152
|
-
} });
|
|
153
|
-
}
|
|
154
|
-
function setBranch(value) {
|
|
155
|
-
branch.value = value;
|
|
156
|
-
}
|
|
157
|
-
async function joinStream(runId, lastEventId, joinOptions) {
|
|
158
|
-
lastEventId ??= "-1";
|
|
159
|
-
if (!threadId.value) return;
|
|
160
|
-
const callbackMeta = {
|
|
161
|
-
thread_id: threadId.value,
|
|
162
|
-
run_id: runId
|
|
163
|
-
};
|
|
164
|
-
await stream.start(async (signal) => {
|
|
165
|
-
const rawStream = client.runs.joinStream(threadId.value, runId, {
|
|
166
|
-
signal,
|
|
167
|
-
lastEventId,
|
|
168
|
-
streamMode: joinOptions?.streamMode
|
|
169
|
-
});
|
|
170
|
-
return joinOptions?.filter != null ? (0, _langchain_langgraph_sdk_ui.filterStream)(rawStream, joinOptions.filter) : rawStream;
|
|
171
|
-
}, {
|
|
172
|
-
getMessages,
|
|
173
|
-
setMessages,
|
|
174
|
-
initialValues: historyValues.value,
|
|
175
|
-
callbacks: options,
|
|
176
|
-
async onSuccess() {
|
|
177
|
-
runMetadataStorage?.removeItem(`lg:stream:${threadId.value}`);
|
|
178
|
-
const lastHead = (await mutate(threadId.value))?.at(0);
|
|
179
|
-
if (lastHead) options.onFinish?.(lastHead, callbackMeta);
|
|
180
|
-
},
|
|
181
|
-
onError(error) {
|
|
182
|
-
options.onError?.(error, callbackMeta);
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
function submitDirect(values, submitOptions) {
|
|
187
|
-
const currentBranchContext = branchContext.value;
|
|
188
|
-
const checkpointId = submitOptions?.checkpoint?.checkpoint_id;
|
|
189
|
-
branch.value = checkpointId != null ? currentBranchContext.branchByCheckpoint[checkpointId]?.branch ?? "" : "";
|
|
190
|
-
const includeImplicitBranch = historyLimit === true || typeof historyLimit === "number";
|
|
191
|
-
const shouldRefetch = options.onFinish != null || includeImplicitBranch;
|
|
192
|
-
let checkpoint = submitOptions?.checkpoint ?? (includeImplicitBranch ? currentBranchContext.threadHead?.checkpoint : void 0) ?? void 0;
|
|
193
|
-
if (submitOptions?.checkpoint === null) checkpoint = void 0;
|
|
194
|
-
if (checkpoint != null) delete checkpoint.thread_id;
|
|
195
|
-
let callbackMeta;
|
|
196
|
-
let rejoinKey;
|
|
197
|
-
let usableThreadId;
|
|
198
|
-
return stream.start(async (signal) => {
|
|
199
|
-
usableThreadId = threadId.value;
|
|
200
|
-
if (!usableThreadId) {
|
|
201
|
-
const threadPromise = client.threads.create({
|
|
202
|
-
threadId: submitOptions?.threadId,
|
|
203
|
-
metadata: submitOptions?.metadata
|
|
204
|
-
});
|
|
205
|
-
threadIdPromise = threadPromise.then((t) => t.thread_id);
|
|
206
|
-
usableThreadId = (await threadPromise).thread_id;
|
|
207
|
-
threadId.value = usableThreadId;
|
|
208
|
-
options.onThreadId?.(usableThreadId);
|
|
209
|
-
}
|
|
210
|
-
const streamMode = (0, _langchain_langgraph_sdk_ui.unique)([
|
|
211
|
-
"values",
|
|
212
|
-
"updates",
|
|
213
|
-
...submitOptions?.streamMode ?? [],
|
|
214
|
-
...trackedStreamModes,
|
|
215
|
-
...callbackStreamModes
|
|
216
|
-
]);
|
|
217
|
-
stream.setStreamValues(() => {
|
|
218
|
-
const prev = {
|
|
219
|
-
...historyValues.value,
|
|
220
|
-
...stream.values
|
|
221
|
-
};
|
|
222
|
-
if (submitOptions?.optimisticValues != null) return {
|
|
223
|
-
...prev,
|
|
224
|
-
...typeof submitOptions.optimisticValues === "function" ? submitOptions.optimisticValues(prev) : submitOptions.optimisticValues
|
|
225
|
-
};
|
|
226
|
-
return { ...prev };
|
|
227
|
-
});
|
|
228
|
-
const streamResumable = submitOptions?.streamResumable ?? !!runMetadataStorage;
|
|
229
|
-
return client.runs.stream(usableThreadId, options.assistantId, {
|
|
230
|
-
input: values,
|
|
231
|
-
config: submitOptions?.config,
|
|
232
|
-
context: submitOptions?.context,
|
|
233
|
-
command: submitOptions?.command,
|
|
234
|
-
interruptBefore: submitOptions?.interruptBefore,
|
|
235
|
-
interruptAfter: submitOptions?.interruptAfter,
|
|
236
|
-
metadata: submitOptions?.metadata,
|
|
237
|
-
multitaskStrategy: submitOptions?.multitaskStrategy,
|
|
238
|
-
onCompletion: submitOptions?.onCompletion,
|
|
239
|
-
onDisconnect: submitOptions?.onDisconnect ?? (streamResumable ? "continue" : "cancel"),
|
|
240
|
-
signal,
|
|
241
|
-
checkpoint,
|
|
242
|
-
streamMode,
|
|
243
|
-
streamSubgraphs: submitOptions?.streamSubgraphs,
|
|
244
|
-
streamResumable,
|
|
245
|
-
durability: submitOptions?.durability,
|
|
246
|
-
onRunCreated(params) {
|
|
247
|
-
callbackMeta = {
|
|
248
|
-
run_id: params.run_id,
|
|
249
|
-
thread_id: params.thread_id ?? usableThreadId
|
|
250
|
-
};
|
|
251
|
-
if (runMetadataStorage) {
|
|
252
|
-
rejoinKey = `lg:stream:${usableThreadId}`;
|
|
253
|
-
runMetadataStorage.setItem(rejoinKey, callbackMeta.run_id);
|
|
254
|
-
}
|
|
255
|
-
options.onCreated?.(callbackMeta);
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
}, {
|
|
259
|
-
getMessages,
|
|
260
|
-
setMessages,
|
|
261
|
-
initialValues: historyValues.value,
|
|
262
|
-
callbacks: options,
|
|
263
|
-
async onSuccess() {
|
|
264
|
-
if (rejoinKey) runMetadataStorage?.removeItem(rejoinKey);
|
|
265
|
-
if (shouldRefetch && usableThreadId) {
|
|
266
|
-
const lastHead = (await mutate(usableThreadId))?.at(0);
|
|
267
|
-
if (lastHead) {
|
|
268
|
-
options.onFinish?.(lastHead, callbackMeta);
|
|
269
|
-
return null;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
},
|
|
273
|
-
onError: (error) => {
|
|
274
|
-
options.onError?.(error, callbackMeta);
|
|
275
|
-
submitOptions?.onError?.(error, callbackMeta);
|
|
276
|
-
},
|
|
277
|
-
onFinish: () => {}
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
const submitting = (0, vue.ref)(false);
|
|
281
|
-
function drainQueue() {
|
|
282
|
-
if (!isLoading.value && !submitting.value && pendingRuns.size > 0) {
|
|
283
|
-
const next = pendingRuns.shift();
|
|
284
|
-
if (next) {
|
|
285
|
-
submitting.value = true;
|
|
286
|
-
joinStream(next.id).finally(() => {
|
|
287
|
-
submitting.value = false;
|
|
288
|
-
drainQueue();
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
56
|
(0, vue.watch)(() => ({
|
|
294
|
-
loading: isLoading
|
|
295
|
-
|
|
296
|
-
|
|
57
|
+
loading: orchestrator.isLoading,
|
|
58
|
+
size: orchestrator.queueSize,
|
|
59
|
+
v: version.value
|
|
297
60
|
}), () => {
|
|
298
|
-
drainQueue();
|
|
61
|
+
orchestrator.drainQueue();
|
|
299
62
|
});
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
let usableThreadId = threadId.value;
|
|
312
|
-
if (!usableThreadId && threadIdPromise) usableThreadId = await threadIdPromise;
|
|
313
|
-
if (usableThreadId) {
|
|
314
|
-
try {
|
|
315
|
-
const run = await client.runs.create(usableThreadId, options.assistantId, {
|
|
316
|
-
input: values,
|
|
317
|
-
config: submitOptions?.config,
|
|
318
|
-
context: submitOptions?.context,
|
|
319
|
-
command: submitOptions?.command,
|
|
320
|
-
interruptBefore: submitOptions?.interruptBefore,
|
|
321
|
-
interruptAfter: submitOptions?.interruptAfter,
|
|
322
|
-
metadata: submitOptions?.metadata,
|
|
323
|
-
multitaskStrategy: "enqueue",
|
|
324
|
-
streamResumable: true,
|
|
325
|
-
streamSubgraphs: submitOptions?.streamSubgraphs,
|
|
326
|
-
durability: submitOptions?.durability
|
|
327
|
-
});
|
|
328
|
-
pendingRuns.add({
|
|
329
|
-
id: run.run_id,
|
|
330
|
-
values,
|
|
331
|
-
options: submitOptions,
|
|
332
|
-
createdAt: new Date(run.created_at)
|
|
333
|
-
});
|
|
334
|
-
} catch (error) {
|
|
335
|
-
options.onError?.(error, void 0);
|
|
336
|
-
submitOptions?.onError?.(error, void 0);
|
|
337
|
-
}
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
submitting.value = true;
|
|
342
|
-
const result = submitDirect(values, submitOptions);
|
|
343
|
-
Promise.resolve(result).finally(() => {
|
|
344
|
-
submitting.value = false;
|
|
345
|
-
drainQueue();
|
|
346
|
-
});
|
|
347
|
-
return result;
|
|
348
|
-
}
|
|
349
|
-
let shouldReconnect = !!runMetadataStorage;
|
|
350
|
-
function tryReconnect() {
|
|
351
|
-
if (shouldReconnect && runMetadataStorage && threadId.value) {
|
|
352
|
-
const runId = runMetadataStorage.getItem(`lg:stream:${threadId.value}`);
|
|
353
|
-
if (runId) {
|
|
354
|
-
shouldReconnect = false;
|
|
355
|
-
joinStream(runId);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
tryReconnect();
|
|
360
|
-
(0, vue.watch)(() => threadId.value, () => {
|
|
361
|
-
shouldReconnect = !!runMetadataStorage;
|
|
362
|
-
tryReconnect();
|
|
363
|
-
});
|
|
364
|
-
const toolCalls = (0, vue.computed)(() => {
|
|
365
|
-
trackStreamMode("messages-tuple");
|
|
366
|
-
return (0, _langchain_langgraph_sdk_utils.getToolCallsWithResults)(getMessages(values.value));
|
|
63
|
+
let { shouldReconnect } = orchestrator;
|
|
64
|
+
if (shouldReconnect) orchestrator.tryReconnect();
|
|
65
|
+
(0, vue.watch)(() => {
|
|
66
|
+
version.value;
|
|
67
|
+
return orchestrator.threadId;
|
|
68
|
+
}, () => {
|
|
69
|
+
({shouldReconnect} = orchestrator);
|
|
70
|
+
if (shouldReconnect) orchestrator.tryReconnect();
|
|
367
71
|
});
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
return
|
|
371
|
-
}
|
|
372
|
-
const interrupts = (0, vue.computed)(() => {
|
|
373
|
-
const v = values.value;
|
|
374
|
-
if (v != null && "__interrupt__" in v && Array.isArray(v.__interrupt__)) {
|
|
375
|
-
const valueInterrupts = v.__interrupt__;
|
|
376
|
-
if (valueInterrupts.length === 0) return [{ when: "breakpoint" }];
|
|
377
|
-
return valueInterrupts;
|
|
378
|
-
}
|
|
379
|
-
if (isLoading.value) return [];
|
|
380
|
-
const allInterrupts = (branchContext.value.threadHead?.tasks ?? []).flatMap((t) => t.interrupts ?? []);
|
|
381
|
-
if (allInterrupts.length > 0) return allInterrupts;
|
|
382
|
-
if (!(branchContext.value.threadHead?.next ?? []).length || error.value != null) return [];
|
|
383
|
-
return [{ when: "breakpoint" }];
|
|
72
|
+
const values = (0, vue.computed)(() => {
|
|
73
|
+
version.value;
|
|
74
|
+
return orchestrator.values;
|
|
384
75
|
});
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
return
|
|
76
|
+
const error = (0, vue.computed)(() => {
|
|
77
|
+
version.value;
|
|
78
|
+
return orchestrator.error;
|
|
388
79
|
});
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
return branchContext.value.branchTree;
|
|
80
|
+
const isLoading = (0, vue.computed)(() => {
|
|
81
|
+
version.value;
|
|
82
|
+
return orchestrator.isLoading;
|
|
393
83
|
});
|
|
84
|
+
const branch = (0, vue.ref)("");
|
|
85
|
+
(0, vue.watch)(() => {
|
|
86
|
+
version.value;
|
|
87
|
+
return orchestrator.branch;
|
|
88
|
+
}, (newBranch) => {
|
|
89
|
+
if (branch.value !== newBranch) branch.value = newBranch;
|
|
90
|
+
}, { immediate: true });
|
|
394
91
|
return {
|
|
395
|
-
assistantId
|
|
396
|
-
|
|
92
|
+
get assistantId() {
|
|
93
|
+
return (0, vue.toValue)(options.assistantId);
|
|
94
|
+
},
|
|
95
|
+
get client() {
|
|
96
|
+
return client.value;
|
|
97
|
+
},
|
|
397
98
|
values,
|
|
398
99
|
error,
|
|
399
100
|
isLoading,
|
|
400
101
|
branch,
|
|
401
|
-
setBranch
|
|
102
|
+
setBranch(value) {
|
|
103
|
+
orchestrator.setBranch(value);
|
|
104
|
+
},
|
|
402
105
|
messages: (0, vue.computed)(() => {
|
|
403
|
-
|
|
404
|
-
|
|
106
|
+
version.value;
|
|
107
|
+
orchestrator.trackStreamMode("messages-tuple");
|
|
108
|
+
return (0, _langchain_langgraph_sdk_ui.ensureMessageInstances)(orchestrator.messages);
|
|
405
109
|
}),
|
|
406
|
-
toolCalls,
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
interrupts,
|
|
414
|
-
history: flatHistory,
|
|
415
|
-
isThreadLoading,
|
|
416
|
-
experimental_branchTree: experimentalBranchTree,
|
|
417
|
-
getMessagesMetadata: (message, index) => {
|
|
418
|
-
const streamMetadata = messageManager.get(message.id)?.metadata;
|
|
419
|
-
const historyMetadata = messageMetadata.value?.find((m) => m.messageId === (message.id ?? index));
|
|
420
|
-
if (streamMetadata != null || historyMetadata != null) return {
|
|
421
|
-
...historyMetadata,
|
|
422
|
-
streamMetadata
|
|
423
|
-
};
|
|
110
|
+
toolCalls: (0, vue.computed)(() => {
|
|
111
|
+
version.value;
|
|
112
|
+
return orchestrator.toolCalls;
|
|
113
|
+
}),
|
|
114
|
+
getToolCalls(message) {
|
|
115
|
+
orchestrator.trackStreamMode("messages-tuple");
|
|
116
|
+
return orchestrator.getToolCalls(message);
|
|
424
117
|
},
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
118
|
+
interrupt: (0, vue.computed)(() => {
|
|
119
|
+
version.value;
|
|
120
|
+
return orchestrator.interrupt;
|
|
121
|
+
}),
|
|
122
|
+
interrupts: (0, vue.computed)(() => {
|
|
123
|
+
version.value;
|
|
124
|
+
return orchestrator.interrupts;
|
|
125
|
+
}),
|
|
126
|
+
history: (0, vue.computed)(() => {
|
|
127
|
+
version.value;
|
|
128
|
+
return orchestrator.flatHistory;
|
|
129
|
+
}),
|
|
130
|
+
isThreadLoading: (0, vue.computed)(() => {
|
|
131
|
+
version.value;
|
|
132
|
+
return orchestrator.isThreadLoading;
|
|
133
|
+
}),
|
|
134
|
+
experimental_branchTree: (0, vue.computed)(() => {
|
|
135
|
+
version.value;
|
|
136
|
+
return orchestrator.experimental_branchTree;
|
|
137
|
+
}),
|
|
138
|
+
getMessagesMetadata: (message, index) => {
|
|
139
|
+
return orchestrator.getMessagesMetadata(message, index);
|
|
442
140
|
},
|
|
141
|
+
submit: (...args) => orchestrator.submit(...args),
|
|
142
|
+
stop: () => orchestrator.stop(),
|
|
143
|
+
joinStream: (...args) => orchestrator.joinStream(...args),
|
|
144
|
+
queue: (0, vue.reactive)({
|
|
145
|
+
entries: (0, vue.computed)(() => {
|
|
146
|
+
version.value;
|
|
147
|
+
return orchestrator.queueEntries;
|
|
148
|
+
}),
|
|
149
|
+
size: (0, vue.computed)(() => {
|
|
150
|
+
version.value;
|
|
151
|
+
return orchestrator.queueSize;
|
|
152
|
+
}),
|
|
153
|
+
cancel: (id) => orchestrator.cancelQueueItem(id),
|
|
154
|
+
clear: () => orchestrator.clearQueue()
|
|
155
|
+
}),
|
|
443
156
|
switchThread(newThreadId) {
|
|
444
|
-
|
|
445
|
-
const prevThreadId = threadId.value;
|
|
446
|
-
threadId.value = newThreadId ?? void 0;
|
|
447
|
-
stream.clear();
|
|
448
|
-
const removed = pendingRuns.removeAll();
|
|
449
|
-
if (prevThreadId && removed.length > 0) Promise.all(removed.map((e) => client.runs.cancel(prevThreadId, e.id)));
|
|
450
|
-
if (newThreadId != null) options.onThreadId?.(newThreadId);
|
|
451
|
-
}
|
|
157
|
+
orchestrator.switchThread(newThreadId);
|
|
452
158
|
},
|
|
453
159
|
get subagents() {
|
|
454
|
-
|
|
455
|
-
return stream.getSubagents();
|
|
160
|
+
return subagentsRef.value;
|
|
456
161
|
},
|
|
457
162
|
get activeSubagents() {
|
|
458
|
-
|
|
459
|
-
return stream.getActiveSubagents();
|
|
163
|
+
return activeSubagentsRef.value;
|
|
460
164
|
},
|
|
461
165
|
getSubagent(toolCallId) {
|
|
462
|
-
return
|
|
166
|
+
return orchestrator.getSubagent(toolCallId);
|
|
463
167
|
},
|
|
464
168
|
getSubagentsByType(type) {
|
|
465
|
-
return
|
|
169
|
+
return orchestrator.getSubagentsByType(type);
|
|
466
170
|
},
|
|
467
171
|
getSubagentsByMessage(messageId) {
|
|
468
|
-
return
|
|
172
|
+
return orchestrator.getSubagentsByMessage(messageId);
|
|
469
173
|
}
|
|
470
174
|
};
|
|
471
175
|
}
|
|
@@ -475,6 +179,8 @@ function useStream(options) {
|
|
|
475
179
|
}
|
|
476
180
|
//#endregion
|
|
477
181
|
exports.FetchStreamTransport = _langchain_langgraph_sdk_ui.FetchStreamTransport;
|
|
182
|
+
exports.LANGCHAIN_OPTIONS = require_context.LANGCHAIN_OPTIONS;
|
|
183
|
+
exports.LangChainPlugin = require_context.LangChainPlugin;
|
|
478
184
|
Object.defineProperty(exports, "SubagentManager", {
|
|
479
185
|
enumerable: true,
|
|
480
186
|
get: function() {
|
|
@@ -505,6 +211,8 @@ Object.defineProperty(exports, "isSubagentNamespace", {
|
|
|
505
211
|
return _langchain_langgraph_sdk_ui.isSubagentNamespace;
|
|
506
212
|
}
|
|
507
213
|
});
|
|
214
|
+
exports.provideStream = require_context.provideStream;
|
|
508
215
|
exports.useStream = useStream;
|
|
216
|
+
exports.useStreamContext = require_context.useStreamContext;
|
|
509
217
|
|
|
510
218
|
//# sourceMappingURL=index.cjs.map
|