@langchain/langgraph-sdk 0.1.10 → 1.0.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/CHANGELOG.md +6 -0
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/auth/error.cjs +76 -86
- package/dist/auth/error.cjs.map +1 -0
- package/dist/auth/error.d.cts +13 -0
- package/dist/auth/error.d.cts.map +1 -0
- package/dist/auth/error.d.ts +12 -8
- package/dist/auth/error.d.ts.map +1 -0
- package/dist/auth/error.js +76 -83
- package/dist/auth/error.js.map +1 -0
- package/dist/auth/index.cjs +36 -44
- package/dist/auth/index.cjs.map +1 -0
- package/dist/auth/index.d.cts +31 -0
- package/dist/auth/index.d.cts.map +1 -0
- package/dist/auth/index.d.ts +20 -15
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +35 -39
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/types.d.cts +294 -0
- package/dist/auth/types.d.cts.map +1 -0
- package/dist/auth/types.d.ts +162 -165
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/client.cjs +1108 -1294
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +688 -0
- package/dist/client.d.cts.map +1 -0
- package/dist/client.d.ts +647 -639
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +1099 -1281
- package/dist/client.js.map +1 -0
- package/dist/index.cjs +6 -8
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -7
- package/dist/index.js +4 -2
- package/dist/logging/index.cjs +30 -31
- package/dist/logging/index.cjs.map +1 -0
- package/dist/logging/index.d.cts +47 -0
- package/dist/logging/index.d.cts.map +1 -0
- package/dist/logging/index.d.ts +20 -16
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +31 -29
- package/dist/logging/index.js.map +1 -0
- package/dist/react/index.cjs +5 -7
- package/dist/react/index.d.cts +4 -0
- package/dist/react/index.d.ts +4 -3
- package/dist/react/index.js +4 -2
- package/dist/react/stream.cjs +14 -15
- package/dist/react/stream.cjs.map +1 -0
- package/dist/react/stream.custom.cjs +126 -145
- package/dist/react/stream.custom.cjs.map +1 -0
- package/dist/react/stream.custom.d.cts +39 -0
- package/dist/react/stream.custom.d.cts.map +1 -0
- package/dist/react/stream.custom.d.ts +35 -37
- package/dist/react/stream.custom.d.ts.map +1 -0
- package/dist/react/stream.custom.js +122 -137
- package/dist/react/stream.custom.js.map +1 -0
- package/dist/react/stream.d.cts +73 -0
- package/dist/react/stream.d.cts.map +1 -0
- package/dist/react/stream.d.ts +21 -15
- package/dist/react/stream.d.ts.map +1 -0
- package/dist/react/stream.js +12 -11
- package/dist/react/stream.js.map +1 -0
- package/dist/react/stream.lgp.cjs +438 -498
- package/dist/react/stream.lgp.cjs.map +1 -0
- package/dist/react/stream.lgp.js +433 -490
- package/dist/react/stream.lgp.js.map +1 -0
- package/dist/react/thread.cjs +18 -15
- package/dist/react/thread.cjs.map +1 -0
- package/dist/react/thread.js +19 -13
- package/dist/react/thread.js.map +1 -0
- package/dist/react/types.d.cts +355 -0
- package/dist/react/types.d.cts.map +1 -0
- package/dist/react/types.d.ts +333 -329
- package/dist/react/types.d.ts.map +1 -0
- package/dist/react-ui/client.cjs +123 -184
- package/dist/react-ui/client.cjs.map +1 -0
- package/dist/react-ui/client.d.cts +90 -0
- package/dist/react-ui/client.d.cts.map +1 -0
- package/dist/react-ui/client.d.ts +67 -51
- package/dist/react-ui/client.d.ts.map +1 -0
- package/dist/react-ui/client.js +118 -143
- package/dist/react-ui/client.js.map +1 -0
- package/dist/react-ui/index.cjs +14 -13
- package/dist/react-ui/index.cjs.map +1 -0
- package/dist/react-ui/index.d.cts +3 -0
- package/dist/react-ui/index.d.ts +3 -2
- package/dist/react-ui/index.js +8 -3
- package/dist/react-ui/index.js.map +1 -0
- package/dist/react-ui/server/index.cjs +5 -7
- package/dist/react-ui/server/index.d.cts +3 -0
- package/dist/react-ui/server/index.d.ts +3 -2
- package/dist/react-ui/server/index.js +4 -2
- package/dist/react-ui/server/server.cjs +53 -44
- package/dist/react-ui/server/server.cjs.map +1 -0
- package/dist/react-ui/server/server.d.cts +55 -0
- package/dist/react-ui/server/server.d.cts.map +1 -0
- package/dist/react-ui/server/server.d.ts +43 -39
- package/dist/react-ui/server/server.d.ts.map +1 -0
- package/dist/react-ui/server/server.js +54 -42
- package/dist/react-ui/server/server.js.map +1 -0
- package/dist/react-ui/types.cjs +32 -36
- package/dist/react-ui/types.cjs.map +1 -0
- package/dist/react-ui/types.d.cts +25 -0
- package/dist/react-ui/types.d.cts.map +1 -0
- package/dist/react-ui/types.d.ts +23 -19
- package/dist/react-ui/types.d.ts.map +1 -0
- package/dist/react-ui/types.js +32 -34
- package/dist/react-ui/types.js.map +1 -0
- package/dist/schema.d.cts +277 -0
- package/dist/schema.d.cts.map +1 -0
- package/dist/schema.d.ts +249 -242
- package/dist/schema.d.ts.map +1 -0
- package/dist/singletons/fetch.cjs +16 -20
- package/dist/singletons/fetch.cjs.map +1 -0
- package/dist/singletons/fetch.d.cts +14 -0
- package/dist/singletons/fetch.d.cts.map +1 -0
- package/dist/singletons/fetch.d.ts +5 -2
- package/dist/singletons/fetch.d.ts.map +1 -0
- package/dist/singletons/fetch.js +16 -17
- package/dist/singletons/fetch.js.map +1 -0
- package/dist/types.d.cts +187 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +178 -173
- package/dist/types.d.ts.map +1 -0
- package/dist/types.messages.d.cts +91 -0
- package/dist/types.messages.d.cts.map +1 -0
- package/dist/types.messages.d.ts +71 -66
- package/dist/types.messages.d.ts.map +1 -0
- package/dist/types.stream.d.cts +235 -0
- package/dist/types.stream.d.cts.map +1 -0
- package/dist/types.stream.d.ts +149 -142
- package/dist/types.stream.d.ts.map +1 -0
- package/dist/ui/branching.cjs +145 -141
- package/dist/ui/branching.cjs.map +1 -0
- package/dist/ui/branching.d.cts +22 -0
- package/dist/ui/branching.d.cts.map +1 -0
- package/dist/ui/branching.d.ts +17 -30
- package/dist/ui/branching.d.ts.map +1 -0
- package/dist/ui/branching.js +147 -139
- package/dist/ui/branching.js.map +1 -0
- package/dist/ui/errors.cjs +14 -12
- package/dist/ui/errors.cjs.map +1 -0
- package/dist/ui/errors.js +14 -9
- package/dist/ui/errors.js.map +1 -0
- package/dist/ui/manager.cjs +156 -232
- package/dist/ui/manager.cjs.map +1 -0
- package/dist/ui/manager.js +156 -228
- package/dist/ui/manager.js.map +1 -0
- package/dist/ui/messages.cjs +55 -69
- package/dist/ui/messages.cjs.map +1 -0
- package/dist/ui/messages.js +55 -66
- package/dist/ui/messages.js.map +1 -0
- package/dist/ui/utils.cjs +10 -10
- package/dist/ui/utils.cjs.map +1 -0
- package/dist/ui/utils.js +10 -8
- package/dist/ui/utils.js.map +1 -0
- package/dist/utils/async_caller.cjs +103 -185
- package/dist/utils/async_caller.cjs.map +1 -0
- package/dist/utils/async_caller.d.cts +53 -0
- package/dist/utils/async_caller.d.cts.map +1 -0
- package/dist/utils/async_caller.d.ts +36 -31
- package/dist/utils/async_caller.d.ts.map +1 -0
- package/dist/utils/async_caller.js +101 -177
- package/dist/utils/async_caller.js.map +1 -0
- package/dist/utils/env.cjs +11 -13
- package/dist/utils/env.cjs.map +1 -0
- package/dist/utils/env.js +11 -11
- package/dist/utils/env.js.map +1 -0
- package/dist/utils/signals.cjs +18 -19
- package/dist/utils/signals.cjs.map +1 -0
- package/dist/utils/signals.js +18 -17
- package/dist/utils/signals.js.map +1 -0
- package/dist/utils/sse.cjs +110 -140
- package/dist/utils/sse.cjs.map +1 -0
- package/dist/utils/sse.js +110 -138
- package/dist/utils/sse.js.map +1 -0
- package/dist/utils/stream.cjs +90 -114
- package/dist/utils/stream.cjs.map +1 -0
- package/dist/utils/stream.js +90 -111
- package/dist/utils/stream.js.map +1 -0
- package/package.json +72 -80
- package/auth.cjs +0 -1
- package/auth.d.cts +0 -1
- package/auth.d.ts +0 -1
- package/auth.js +0 -1
- package/client.cjs +0 -1
- package/client.d.cts +0 -1
- package/client.d.ts +0 -1
- package/client.js +0 -1
- package/dist/auth/types.cjs +0 -2
- package/dist/auth/types.js +0 -1
- package/dist/react/stream.lgp.d.ts +0 -7
- package/dist/react/thread.d.ts +0 -4
- package/dist/react/types.cjs +0 -2
- package/dist/react/types.js +0 -1
- package/dist/schema.cjs +0 -2
- package/dist/schema.js +0 -1
- package/dist/types.cjs +0 -2
- package/dist/types.js +0 -1
- package/dist/types.messages.cjs +0 -2
- package/dist/types.messages.js +0 -1
- package/dist/types.stream.cjs +0 -2
- package/dist/types.stream.js +0 -1
- package/dist/ui/branching.test.cjs +0 -370
- package/dist/ui/branching.test.d.ts +0 -1
- package/dist/ui/branching.test.js +0 -368
- package/dist/ui/errors.d.ts +0 -12
- package/dist/ui/manager.d.ts +0 -87
- package/dist/ui/messages.d.ts +0 -18
- package/dist/ui/utils.d.ts +0 -2
- package/dist/utils/env.d.ts +0 -1
- package/dist/utils/signals.d.ts +0 -1
- package/dist/utils/sse.d.ts +0 -8
- package/dist/utils/stream.d.ts +0 -13
- package/index.cjs +0 -1
- package/index.d.cts +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/logging.cjs +0 -1
- package/logging.d.cts +0 -1
- package/logging.d.ts +0 -1
- package/logging.js +0 -1
- package/react-ui/server.cjs +0 -1
- package/react-ui/server.d.cts +0 -1
- package/react-ui/server.d.ts +0 -1
- package/react-ui/server.js +0 -1
- package/react-ui.cjs +0 -1
- package/react-ui.d.cts +0 -1
- package/react-ui.d.ts +0 -1
- package/react-ui.js +0 -1
- package/react.cjs +0 -1
- package/react.d.cts +0 -1
- package/react.d.ts +0 -1
- package/react.js +0 -1
package/dist/react/stream.lgp.js
CHANGED
|
@@ -1,503 +1,446 @@
|
|
|
1
|
-
/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */
|
|
2
1
|
"use client";
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { Client, getClientConfigHash } from "../client.js";
|
|
4
5
|
import { findLast, unique } from "../ui/utils.js";
|
|
5
6
|
import { StreamError } from "../ui/errors.js";
|
|
6
7
|
import { getBranchContext } from "../ui/branching.js";
|
|
7
|
-
import { StreamManager } from "../ui/manager.js";
|
|
8
|
-
import { Client, getClientConfigHash } from "../client.js";
|
|
9
8
|
import { MessageTupleManager } from "../ui/messages.js";
|
|
9
|
+
import { StreamManager } from "../ui/manager.js";
|
|
10
10
|
import { useControllableThreadId } from "./thread.js";
|
|
11
|
+
import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
12
|
+
|
|
13
|
+
//#region src/react/stream.lgp.tsx
|
|
11
14
|
function getFetchHistoryKey(client, threadId, limit) {
|
|
12
|
-
|
|
15
|
+
return [
|
|
16
|
+
getClientConfigHash(client),
|
|
17
|
+
threadId,
|
|
18
|
+
limit
|
|
19
|
+
].join(":");
|
|
13
20
|
}
|
|
14
21
|
function fetchHistory(client, threadId, options) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
const limit = typeof options?.limit === "number" ? options.limit : 10;
|
|
23
|
-
return client.threads.getHistory(threadId, { limit });
|
|
22
|
+
if (options?.limit === false) return client.threads.getState(threadId).then((state) => {
|
|
23
|
+
if (state.checkpoint == null) return [];
|
|
24
|
+
return [state];
|
|
25
|
+
});
|
|
26
|
+
const limit = typeof options?.limit === "number" ? options.limit : 10;
|
|
27
|
+
return client.threads.getHistory(threadId, { limit });
|
|
24
28
|
}
|
|
25
29
|
function useThreadHistory(client, threadId, limit, options) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
30
|
+
const key = getFetchHistoryKey(client, threadId, limit);
|
|
31
|
+
const [state, setState] = useState(() => ({
|
|
32
|
+
key: void 0,
|
|
33
|
+
data: void 0,
|
|
34
|
+
error: void 0,
|
|
35
|
+
isLoading: threadId != null
|
|
36
|
+
}));
|
|
37
|
+
const clientRef = useRef(client);
|
|
38
|
+
clientRef.current = client;
|
|
39
|
+
const onErrorRef = useRef(options?.onError);
|
|
40
|
+
onErrorRef.current = options?.onError;
|
|
41
|
+
const fetcher = useCallback((threadId$1, limit$1) => {
|
|
42
|
+
if (options.passthrough) return Promise.resolve([]);
|
|
43
|
+
const client$1 = clientRef.current;
|
|
44
|
+
const key$1 = getFetchHistoryKey(client$1, threadId$1, limit$1);
|
|
45
|
+
if (threadId$1 != null) {
|
|
46
|
+
setState((state$1) => {
|
|
47
|
+
if (state$1.key === key$1) return {
|
|
48
|
+
...state$1,
|
|
49
|
+
isLoading: true
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
key: key$1,
|
|
53
|
+
data: void 0,
|
|
54
|
+
error: void 0,
|
|
55
|
+
isLoading: true
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
return fetchHistory(client$1, threadId$1, { limit: limit$1 }).then((data) => {
|
|
59
|
+
setState((state$1) => {
|
|
60
|
+
if (state$1.key !== key$1) return state$1;
|
|
61
|
+
return {
|
|
62
|
+
key: key$1,
|
|
63
|
+
data,
|
|
64
|
+
error: void 0,
|
|
65
|
+
isLoading: false
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
return data;
|
|
69
|
+
}, (error) => {
|
|
70
|
+
setState((state$1) => {
|
|
71
|
+
if (state$1.key !== key$1) return state$1;
|
|
72
|
+
return {
|
|
73
|
+
key: key$1,
|
|
74
|
+
data: state$1.data,
|
|
75
|
+
error,
|
|
76
|
+
isLoading: false
|
|
77
|
+
};
|
|
78
|
+
});
|
|
79
|
+
onErrorRef.current?.(error);
|
|
80
|
+
return Promise.reject(error);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
setState({
|
|
84
|
+
key: key$1,
|
|
85
|
+
data: void 0,
|
|
86
|
+
error: void 0,
|
|
87
|
+
isLoading: false
|
|
88
|
+
});
|
|
89
|
+
return Promise.resolve([]);
|
|
90
|
+
}, [options.passthrough]);
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (options.submittingRef.current != null && options.submittingRef.current === threadId) return;
|
|
93
|
+
fetcher(threadId, limit);
|
|
94
|
+
}, [fetcher, key]);
|
|
95
|
+
return {
|
|
96
|
+
data: state.data,
|
|
97
|
+
error: state.error,
|
|
98
|
+
isLoading: state.isLoading,
|
|
99
|
+
mutate: (mutateId) => fetcher(mutateId ?? threadId, limit)
|
|
100
|
+
};
|
|
86
101
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
reconnectRef.current.shouldReconnect = false;
|
|
428
|
-
void joinStreamRef.current?.(reconnectKey.runId);
|
|
429
|
-
}
|
|
430
|
-
}, [reconnectKey]);
|
|
431
|
-
const error = stream.error ?? historyError ?? history.error;
|
|
432
|
-
const values = stream.values ?? historyValues;
|
|
433
|
-
return {
|
|
434
|
-
get values() {
|
|
435
|
-
trackStreamMode("values");
|
|
436
|
-
return values;
|
|
437
|
-
},
|
|
438
|
-
client,
|
|
439
|
-
assistantId: options.assistantId,
|
|
440
|
-
error,
|
|
441
|
-
isLoading: stream.isLoading,
|
|
442
|
-
stop,
|
|
443
|
-
submit,
|
|
444
|
-
joinStream,
|
|
445
|
-
branch,
|
|
446
|
-
setBranch,
|
|
447
|
-
get history() {
|
|
448
|
-
if (historyLimit === false) {
|
|
449
|
-
throw new Error("`fetchStateHistory` must be set to `true` to use `history`");
|
|
450
|
-
}
|
|
451
|
-
return branchContext.flatHistory;
|
|
452
|
-
},
|
|
453
|
-
isThreadLoading: history.isLoading && history.data == null,
|
|
454
|
-
get experimental_branchTree() {
|
|
455
|
-
if (historyLimit === false) {
|
|
456
|
-
throw new Error("`fetchStateHistory` must be set to `true` to use `experimental_branchTree`");
|
|
457
|
-
}
|
|
458
|
-
return branchContext.branchTree;
|
|
459
|
-
},
|
|
460
|
-
get interrupt() {
|
|
461
|
-
if (values != null &&
|
|
462
|
-
"__interrupt__" in values &&
|
|
463
|
-
Array.isArray(values.__interrupt__)) {
|
|
464
|
-
const valueInterrupts = values.__interrupt__;
|
|
465
|
-
if (valueInterrupts.length === 0)
|
|
466
|
-
return { when: "breakpoint" };
|
|
467
|
-
if (valueInterrupts.length === 1)
|
|
468
|
-
return valueInterrupts[0];
|
|
469
|
-
// TODO: fix the typing of interrupts if multiple interrupts are returned
|
|
470
|
-
return valueInterrupts;
|
|
471
|
-
}
|
|
472
|
-
// If we're deferring to old interrupt detection logic, don't show the interrupt if the stream is loading
|
|
473
|
-
if (stream.isLoading)
|
|
474
|
-
return undefined;
|
|
475
|
-
const interrupts = branchContext.threadHead?.tasks?.at(-1)?.interrupts;
|
|
476
|
-
if (interrupts == null || interrupts.length === 0) {
|
|
477
|
-
// check if there's a next task present
|
|
478
|
-
const next = branchContext.threadHead?.next ?? [];
|
|
479
|
-
if (!next.length || error != null)
|
|
480
|
-
return undefined;
|
|
481
|
-
return { when: "breakpoint" };
|
|
482
|
-
}
|
|
483
|
-
// Return only the current interrupt
|
|
484
|
-
return interrupts.at(-1);
|
|
485
|
-
},
|
|
486
|
-
get messages() {
|
|
487
|
-
trackStreamMode("messages-tuple", "values");
|
|
488
|
-
return getMessages(values);
|
|
489
|
-
},
|
|
490
|
-
getMessagesMetadata(message, index) {
|
|
491
|
-
trackStreamMode("values");
|
|
492
|
-
const streamMetadata = messageManager.get(message.id)?.metadata;
|
|
493
|
-
const historyMetadata = messageMetadata?.find((m) => m.messageId === (message.id ?? index));
|
|
494
|
-
if (streamMetadata != null || historyMetadata != null) {
|
|
495
|
-
return {
|
|
496
|
-
...historyMetadata,
|
|
497
|
-
streamMetadata,
|
|
498
|
-
};
|
|
499
|
-
}
|
|
500
|
-
return undefined;
|
|
501
|
-
},
|
|
502
|
-
};
|
|
102
|
+
function useStreamLGP(options) {
|
|
103
|
+
const reconnectOnMountRef = useRef(options.reconnectOnMount);
|
|
104
|
+
const runMetadataStorage = useMemo(() => {
|
|
105
|
+
if (typeof window === "undefined") return null;
|
|
106
|
+
const storage = reconnectOnMountRef.current;
|
|
107
|
+
if (storage === true) return window.sessionStorage;
|
|
108
|
+
if (typeof storage === "function") return storage();
|
|
109
|
+
return null;
|
|
110
|
+
}, []);
|
|
111
|
+
const client = useMemo(() => options.client ?? new Client({
|
|
112
|
+
apiUrl: options.apiUrl,
|
|
113
|
+
apiKey: options.apiKey,
|
|
114
|
+
callerOptions: options.callerOptions,
|
|
115
|
+
defaultHeaders: options.defaultHeaders
|
|
116
|
+
}), [
|
|
117
|
+
options.client,
|
|
118
|
+
options.apiKey,
|
|
119
|
+
options.apiUrl,
|
|
120
|
+
options.callerOptions,
|
|
121
|
+
options.defaultHeaders
|
|
122
|
+
]);
|
|
123
|
+
const [messageManager] = useState(() => new MessageTupleManager());
|
|
124
|
+
const [stream] = useState(() => new StreamManager(messageManager));
|
|
125
|
+
useSyncExternalStore(stream.subscribe, stream.getSnapshot, stream.getSnapshot);
|
|
126
|
+
const [threadId, onThreadId] = useControllableThreadId(options);
|
|
127
|
+
const trackStreamModeRef = useRef([]);
|
|
128
|
+
const trackStreamMode = useCallback((...mode) => {
|
|
129
|
+
const ref = trackStreamModeRef.current;
|
|
130
|
+
for (const m of mode) if (!ref.includes(m)) ref.push(m);
|
|
131
|
+
}, []);
|
|
132
|
+
const hasUpdateListener = options.onUpdateEvent != null;
|
|
133
|
+
const hasCustomListener = options.onCustomEvent != null;
|
|
134
|
+
const hasLangChainListener = options.onLangChainEvent != null;
|
|
135
|
+
const hasDebugListener = options.onDebugEvent != null;
|
|
136
|
+
const hasCheckpointListener = options.onCheckpointEvent != null;
|
|
137
|
+
const hasTaskListener = options.onTaskEvent != null;
|
|
138
|
+
const callbackStreamMode = useMemo(() => {
|
|
139
|
+
const modes = [];
|
|
140
|
+
if (hasUpdateListener) modes.push("updates");
|
|
141
|
+
if (hasCustomListener) modes.push("custom");
|
|
142
|
+
if (hasLangChainListener) modes.push("events");
|
|
143
|
+
if (hasDebugListener) modes.push("debug");
|
|
144
|
+
if (hasCheckpointListener) modes.push("checkpoints");
|
|
145
|
+
if (hasTaskListener) modes.push("tasks");
|
|
146
|
+
return modes;
|
|
147
|
+
}, [
|
|
148
|
+
hasUpdateListener,
|
|
149
|
+
hasCustomListener,
|
|
150
|
+
hasLangChainListener,
|
|
151
|
+
hasDebugListener,
|
|
152
|
+
hasCheckpointListener,
|
|
153
|
+
hasTaskListener
|
|
154
|
+
]);
|
|
155
|
+
const clearCallbackRef = useRef(null);
|
|
156
|
+
clearCallbackRef.current = stream.clear;
|
|
157
|
+
const threadIdRef = useRef(threadId);
|
|
158
|
+
const threadIdStreamingRef = useRef(null);
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
if (threadIdRef.current !== threadId) {
|
|
161
|
+
threadIdRef.current = threadId;
|
|
162
|
+
stream.clear();
|
|
163
|
+
}
|
|
164
|
+
}, [threadId, stream]);
|
|
165
|
+
const historyLimit = typeof options.fetchStateHistory === "object" && options.fetchStateHistory != null ? options.fetchStateHistory.limit ?? false : options.fetchStateHistory ?? false;
|
|
166
|
+
const builtInHistory = useThreadHistory(client, threadId, historyLimit, {
|
|
167
|
+
passthrough: options.experimental_thread != null,
|
|
168
|
+
submittingRef: threadIdStreamingRef,
|
|
169
|
+
onError: options.onError
|
|
170
|
+
});
|
|
171
|
+
const history = options.experimental_thread ?? builtInHistory;
|
|
172
|
+
const getMessages = (value) => {
|
|
173
|
+
const messagesKey = options.messagesKey ?? "messages";
|
|
174
|
+
return Array.isArray(value[messagesKey]) ? value[messagesKey] : [];
|
|
175
|
+
};
|
|
176
|
+
const setMessages = (current, messages) => {
|
|
177
|
+
const messagesKey = options.messagesKey ?? "messages";
|
|
178
|
+
return {
|
|
179
|
+
...current,
|
|
180
|
+
[messagesKey]: messages
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
const [branch, setBranch] = useState("");
|
|
184
|
+
const branchContext = getBranchContext(branch, history.data ?? void 0);
|
|
185
|
+
const historyValues = branchContext.threadHead?.values ?? options.initialValues ?? {};
|
|
186
|
+
const historyError = (() => {
|
|
187
|
+
const error$1 = branchContext.threadHead?.tasks?.at(-1)?.error;
|
|
188
|
+
if (error$1 == null) return void 0;
|
|
189
|
+
try {
|
|
190
|
+
const parsed = JSON.parse(error$1);
|
|
191
|
+
if (StreamError.isStructuredError(parsed)) return new StreamError(parsed);
|
|
192
|
+
return parsed;
|
|
193
|
+
} catch {}
|
|
194
|
+
return error$1;
|
|
195
|
+
})();
|
|
196
|
+
const messageMetadata = (() => {
|
|
197
|
+
const alreadyShown = /* @__PURE__ */ new Set();
|
|
198
|
+
return getMessages(historyValues).map((message, idx) => {
|
|
199
|
+
const messageId = message.id ?? idx;
|
|
200
|
+
const firstSeenState = findLast(history.data ?? [], (state) => getMessages(state.values).map((m, idx$1) => m.id ?? idx$1).includes(messageId));
|
|
201
|
+
const checkpointId = firstSeenState?.checkpoint?.checkpoint_id;
|
|
202
|
+
let branch$1 = checkpointId != null ? branchContext.branchByCheckpoint[checkpointId] : void 0;
|
|
203
|
+
if (!branch$1?.branch?.length) branch$1 = void 0;
|
|
204
|
+
const optionsShown = branch$1?.branchOptions?.flat(2).join(",");
|
|
205
|
+
if (optionsShown) {
|
|
206
|
+
if (alreadyShown.has(optionsShown)) branch$1 = void 0;
|
|
207
|
+
alreadyShown.add(optionsShown);
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
messageId: messageId.toString(),
|
|
211
|
+
firstSeenState,
|
|
212
|
+
branch: branch$1?.branch,
|
|
213
|
+
branchOptions: branch$1?.branchOptions
|
|
214
|
+
};
|
|
215
|
+
});
|
|
216
|
+
})();
|
|
217
|
+
const stop = () => stream.stop(historyValues, { onStop: (args) => {
|
|
218
|
+
if (runMetadataStorage && threadId) {
|
|
219
|
+
const runId = runMetadataStorage.getItem(`lg:stream:${threadId}`);
|
|
220
|
+
if (runId) client.runs.cancel(threadId, runId);
|
|
221
|
+
runMetadataStorage.removeItem(`lg:stream:${threadId}`);
|
|
222
|
+
}
|
|
223
|
+
options.onStop?.(args);
|
|
224
|
+
} });
|
|
225
|
+
const submit = async (values$1, submitOptions) => {
|
|
226
|
+
const checkpointId = submitOptions?.checkpoint?.checkpoint_id;
|
|
227
|
+
setBranch(checkpointId != null ? branchContext.branchByCheckpoint[checkpointId]?.branch ?? "" : "");
|
|
228
|
+
const includeImplicitBranch = historyLimit === true || typeof historyLimit === "number";
|
|
229
|
+
const shouldRefetch = options.onFinish != null || includeImplicitBranch;
|
|
230
|
+
stream.setStreamValues(() => {
|
|
231
|
+
const prev = shouldRefetch ? historyValues : {
|
|
232
|
+
...historyValues,
|
|
233
|
+
...stream.values
|
|
234
|
+
};
|
|
235
|
+
if (submitOptions?.optimisticValues != null) return {
|
|
236
|
+
...prev,
|
|
237
|
+
...typeof submitOptions.optimisticValues === "function" ? submitOptions.optimisticValues(prev) : submitOptions.optimisticValues
|
|
238
|
+
};
|
|
239
|
+
return { ...prev };
|
|
240
|
+
});
|
|
241
|
+
let callbackMeta;
|
|
242
|
+
let rejoinKey;
|
|
243
|
+
let usableThreadId = threadId;
|
|
244
|
+
await stream.start(async (signal) => {
|
|
245
|
+
if (!usableThreadId) {
|
|
246
|
+
const thread = await client.threads.create({
|
|
247
|
+
threadId: submitOptions?.threadId,
|
|
248
|
+
metadata: submitOptions?.metadata
|
|
249
|
+
});
|
|
250
|
+
usableThreadId = thread.thread_id;
|
|
251
|
+
threadIdRef.current = usableThreadId;
|
|
252
|
+
threadIdStreamingRef.current = usableThreadId;
|
|
253
|
+
onThreadId(usableThreadId);
|
|
254
|
+
}
|
|
255
|
+
if (!usableThreadId) throw new Error("Failed to obtain valid thread ID.");
|
|
256
|
+
threadIdStreamingRef.current = usableThreadId;
|
|
257
|
+
const streamMode = unique([
|
|
258
|
+
...submitOptions?.streamMode ?? [],
|
|
259
|
+
...trackStreamModeRef.current,
|
|
260
|
+
...callbackStreamMode
|
|
261
|
+
]);
|
|
262
|
+
let checkpoint = submitOptions?.checkpoint ?? (includeImplicitBranch ? branchContext.threadHead?.checkpoint : void 0) ?? void 0;
|
|
263
|
+
if (submitOptions?.checkpoint === null) checkpoint = void 0;
|
|
264
|
+
if (checkpoint != null) delete checkpoint.thread_id;
|
|
265
|
+
const streamResumable = submitOptions?.streamResumable ?? !!runMetadataStorage;
|
|
266
|
+
return client.runs.stream(usableThreadId, options.assistantId, {
|
|
267
|
+
input: values$1,
|
|
268
|
+
config: submitOptions?.config,
|
|
269
|
+
context: submitOptions?.context,
|
|
270
|
+
command: submitOptions?.command,
|
|
271
|
+
interruptBefore: submitOptions?.interruptBefore,
|
|
272
|
+
interruptAfter: submitOptions?.interruptAfter,
|
|
273
|
+
metadata: submitOptions?.metadata,
|
|
274
|
+
multitaskStrategy: submitOptions?.multitaskStrategy,
|
|
275
|
+
onCompletion: submitOptions?.onCompletion,
|
|
276
|
+
onDisconnect: submitOptions?.onDisconnect ?? (streamResumable ? "continue" : "cancel"),
|
|
277
|
+
signal,
|
|
278
|
+
checkpoint,
|
|
279
|
+
streamMode,
|
|
280
|
+
streamSubgraphs: submitOptions?.streamSubgraphs,
|
|
281
|
+
streamResumable,
|
|
282
|
+
durability: submitOptions?.durability,
|
|
283
|
+
onRunCreated(params) {
|
|
284
|
+
callbackMeta = {
|
|
285
|
+
run_id: params.run_id,
|
|
286
|
+
thread_id: params.thread_id ?? usableThreadId
|
|
287
|
+
};
|
|
288
|
+
if (runMetadataStorage) {
|
|
289
|
+
rejoinKey = `lg:stream:${usableThreadId}`;
|
|
290
|
+
runMetadataStorage.setItem(rejoinKey, callbackMeta.run_id);
|
|
291
|
+
}
|
|
292
|
+
options.onCreated?.(callbackMeta);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}, {
|
|
296
|
+
getMessages,
|
|
297
|
+
setMessages,
|
|
298
|
+
initialValues: historyValues,
|
|
299
|
+
callbacks: options,
|
|
300
|
+
async onSuccess() {
|
|
301
|
+
if (rejoinKey) runMetadataStorage?.removeItem(rejoinKey);
|
|
302
|
+
if (shouldRefetch) {
|
|
303
|
+
const newHistory = await history.mutate(usableThreadId);
|
|
304
|
+
const lastHead = newHistory?.at(0);
|
|
305
|
+
if (lastHead) {
|
|
306
|
+
options.onFinish?.(lastHead, callbackMeta);
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return void 0;
|
|
311
|
+
},
|
|
312
|
+
onError(error$1) {
|
|
313
|
+
options.onError?.(error$1, callbackMeta);
|
|
314
|
+
},
|
|
315
|
+
onFinish() {
|
|
316
|
+
threadIdStreamingRef.current = null;
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
};
|
|
320
|
+
const joinStream = async (runId, lastEventId, joinOptions) => {
|
|
321
|
+
lastEventId ??= "-1";
|
|
322
|
+
if (!threadId) return;
|
|
323
|
+
const callbackMeta = {
|
|
324
|
+
thread_id: threadId,
|
|
325
|
+
run_id: runId
|
|
326
|
+
};
|
|
327
|
+
await stream.start(async (signal) => {
|
|
328
|
+
threadIdStreamingRef.current = threadId;
|
|
329
|
+
return client.runs.joinStream(threadId, runId, {
|
|
330
|
+
signal,
|
|
331
|
+
lastEventId,
|
|
332
|
+
streamMode: joinOptions?.streamMode
|
|
333
|
+
});
|
|
334
|
+
}, {
|
|
335
|
+
getMessages,
|
|
336
|
+
setMessages,
|
|
337
|
+
initialValues: historyValues,
|
|
338
|
+
callbacks: options,
|
|
339
|
+
async onSuccess() {
|
|
340
|
+
runMetadataStorage?.removeItem(`lg:stream:${threadId}`);
|
|
341
|
+
const newHistory = await history.mutate(threadId);
|
|
342
|
+
const lastHead = newHistory?.at(0);
|
|
343
|
+
if (lastHead) options.onFinish?.(lastHead, callbackMeta);
|
|
344
|
+
},
|
|
345
|
+
onError(error$1) {
|
|
346
|
+
options.onError?.(error$1, callbackMeta);
|
|
347
|
+
},
|
|
348
|
+
onFinish() {
|
|
349
|
+
threadIdStreamingRef.current = null;
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
};
|
|
353
|
+
const reconnectKey = useMemo(() => {
|
|
354
|
+
if (!runMetadataStorage || stream.isLoading) return void 0;
|
|
355
|
+
if (typeof window === "undefined") return void 0;
|
|
356
|
+
const runId = runMetadataStorage?.getItem(`lg:stream:${threadId}`);
|
|
357
|
+
if (!runId) return void 0;
|
|
358
|
+
return {
|
|
359
|
+
runId,
|
|
360
|
+
threadId
|
|
361
|
+
};
|
|
362
|
+
}, [
|
|
363
|
+
runMetadataStorage,
|
|
364
|
+
stream.isLoading,
|
|
365
|
+
threadId
|
|
366
|
+
]);
|
|
367
|
+
const shouldReconnect = !!runMetadataStorage;
|
|
368
|
+
const reconnectRef = useRef({
|
|
369
|
+
threadId,
|
|
370
|
+
shouldReconnect
|
|
371
|
+
});
|
|
372
|
+
const joinStreamRef = useRef(joinStream);
|
|
373
|
+
joinStreamRef.current = joinStream;
|
|
374
|
+
useEffect(() => {
|
|
375
|
+
if (reconnectRef.current.threadId !== threadId) reconnectRef.current = {
|
|
376
|
+
threadId,
|
|
377
|
+
shouldReconnect
|
|
378
|
+
};
|
|
379
|
+
}, [threadId, shouldReconnect]);
|
|
380
|
+
useEffect(() => {
|
|
381
|
+
if (reconnectKey && reconnectRef.current.shouldReconnect) {
|
|
382
|
+
reconnectRef.current.shouldReconnect = false;
|
|
383
|
+
joinStreamRef.current?.(reconnectKey.runId);
|
|
384
|
+
}
|
|
385
|
+
}, [reconnectKey]);
|
|
386
|
+
const error = stream.error ?? historyError ?? history.error;
|
|
387
|
+
const values = stream.values ?? historyValues;
|
|
388
|
+
return {
|
|
389
|
+
get values() {
|
|
390
|
+
trackStreamMode("values");
|
|
391
|
+
return values;
|
|
392
|
+
},
|
|
393
|
+
client,
|
|
394
|
+
assistantId: options.assistantId,
|
|
395
|
+
error,
|
|
396
|
+
isLoading: stream.isLoading,
|
|
397
|
+
stop,
|
|
398
|
+
submit,
|
|
399
|
+
joinStream,
|
|
400
|
+
branch,
|
|
401
|
+
setBranch,
|
|
402
|
+
get history() {
|
|
403
|
+
if (historyLimit === false) throw new Error("`fetchStateHistory` must be set to `true` to use `history`");
|
|
404
|
+
return branchContext.flatHistory;
|
|
405
|
+
},
|
|
406
|
+
isThreadLoading: history.isLoading && history.data == null,
|
|
407
|
+
get experimental_branchTree() {
|
|
408
|
+
if (historyLimit === false) throw new Error("`fetchStateHistory` must be set to `true` to use `experimental_branchTree`");
|
|
409
|
+
return branchContext.branchTree;
|
|
410
|
+
},
|
|
411
|
+
get interrupt() {
|
|
412
|
+
if (values != null && "__interrupt__" in values && Array.isArray(values.__interrupt__)) {
|
|
413
|
+
const valueInterrupts = values.__interrupt__;
|
|
414
|
+
if (valueInterrupts.length === 0) return { when: "breakpoint" };
|
|
415
|
+
if (valueInterrupts.length === 1) return valueInterrupts[0];
|
|
416
|
+
return valueInterrupts;
|
|
417
|
+
}
|
|
418
|
+
if (stream.isLoading) return void 0;
|
|
419
|
+
const interrupts = branchContext.threadHead?.tasks?.at(-1)?.interrupts;
|
|
420
|
+
if (interrupts == null || interrupts.length === 0) {
|
|
421
|
+
const next = branchContext.threadHead?.next ?? [];
|
|
422
|
+
if (!next.length || error != null) return void 0;
|
|
423
|
+
return { when: "breakpoint" };
|
|
424
|
+
}
|
|
425
|
+
return interrupts.at(-1);
|
|
426
|
+
},
|
|
427
|
+
get messages() {
|
|
428
|
+
trackStreamMode("messages-tuple", "values");
|
|
429
|
+
return getMessages(values);
|
|
430
|
+
},
|
|
431
|
+
getMessagesMetadata(message, index) {
|
|
432
|
+
trackStreamMode("values");
|
|
433
|
+
const streamMetadata = messageManager.get(message.id)?.metadata;
|
|
434
|
+
const historyMetadata = messageMetadata?.find((m) => m.messageId === (message.id ?? index));
|
|
435
|
+
if (streamMetadata != null || historyMetadata != null) return {
|
|
436
|
+
...historyMetadata,
|
|
437
|
+
streamMetadata
|
|
438
|
+
};
|
|
439
|
+
return void 0;
|
|
440
|
+
}
|
|
441
|
+
};
|
|
503
442
|
}
|
|
443
|
+
|
|
444
|
+
//#endregion
|
|
445
|
+
export { useStreamLGP };
|
|
446
|
+
//# sourceMappingURL=stream.lgp.js.map
|