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