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