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