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