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