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