@axiom-lattice/react-sdk 2.1.0 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +62 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -28
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -43,6 +43,7 @@ function useChat(threadId, options = {}) {
|
|
|
43
43
|
isLoading: false,
|
|
44
44
|
error: null,
|
|
45
45
|
streamingMessage: null,
|
|
46
|
+
interrupts: void 0,
|
|
46
47
|
...options.enableReturnStateWhenStreamCompleted ? { agentState: null } : {}
|
|
47
48
|
});
|
|
48
49
|
const stopStreamingRef = useRef(null);
|
|
@@ -55,7 +56,15 @@ function useChat(threadId, options = {}) {
|
|
|
55
56
|
setState(
|
|
56
57
|
(prev) => ({
|
|
57
58
|
...prev,
|
|
58
|
-
agentState
|
|
59
|
+
agentState,
|
|
60
|
+
interrupts: agentState?.tasks?.flatMap((task) => {
|
|
61
|
+
return task.interrupts.map((interrupt) => {
|
|
62
|
+
return {
|
|
63
|
+
id: interrupt.id,
|
|
64
|
+
value: interrupt.value
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
})
|
|
59
68
|
})
|
|
60
69
|
);
|
|
61
70
|
} catch (error) {
|
|
@@ -69,29 +78,38 @@ function useChat(threadId, options = {}) {
|
|
|
69
78
|
chunkMessageMerger.current.initialMessages(options.initialMessages);
|
|
70
79
|
}
|
|
71
80
|
}, [options.initialMessages]);
|
|
72
|
-
const handleStreamEvent = useCallback(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
+
const handleStreamEvent = useCallback(
|
|
82
|
+
(chunk) => {
|
|
83
|
+
let interrupt;
|
|
84
|
+
if (chunk.type === "interrupt") {
|
|
85
|
+
interrupt = chunk;
|
|
86
|
+
} else {
|
|
87
|
+
chunkMessageMerger.current.push(chunk);
|
|
88
|
+
}
|
|
89
|
+
let todos;
|
|
90
|
+
if (chunk.type === "tool" && chunk.data && typeof chunk.data.content === "string" && chunk.data.content.startsWith("```todo_list")) {
|
|
91
|
+
try {
|
|
92
|
+
const content = chunk.data.content;
|
|
93
|
+
const match = content.match(/```todo_list\s*([\s\S]*?)\s*```/);
|
|
94
|
+
if (match && match[1]) {
|
|
95
|
+
todos = JSON.parse(match[1]);
|
|
96
|
+
}
|
|
97
|
+
} catch (e) {
|
|
98
|
+
console.error("Failed to parse todo list from chunk", e);
|
|
81
99
|
}
|
|
82
|
-
} catch (e) {
|
|
83
|
-
console.error("Failed to parse todo list from chunk", e);
|
|
84
100
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
101
|
+
const updatedMessages = chunkMessageMerger.current.getMessages();
|
|
102
|
+
setState((prev) => ({
|
|
103
|
+
...prev,
|
|
104
|
+
interrupts: interrupt ? [interrupt] : void 0,
|
|
105
|
+
todos: todos || prev.todos,
|
|
106
|
+
messages: updatedMessages,
|
|
107
|
+
isLoading: true,
|
|
108
|
+
streamingMessage: null
|
|
109
|
+
}));
|
|
110
|
+
},
|
|
111
|
+
[]
|
|
112
|
+
);
|
|
95
113
|
const sendMessage = useCallback(
|
|
96
114
|
async (data) => {
|
|
97
115
|
if (!threadId) {
|
|
@@ -218,12 +236,21 @@ function useChat(threadId, options = {}) {
|
|
|
218
236
|
setState((prev) => ({ ...prev, isLoading: true, error: null }));
|
|
219
237
|
try {
|
|
220
238
|
const agentState = await client.getAgentState(threadId);
|
|
239
|
+
const interrupts = agentState?.tasks?.flatMap((task) => {
|
|
240
|
+
return task.interrupts.map((interrupt) => {
|
|
241
|
+
return {
|
|
242
|
+
id: interrupt.id,
|
|
243
|
+
value: interrupt.value
|
|
244
|
+
};
|
|
245
|
+
});
|
|
246
|
+
});
|
|
221
247
|
const fetchedMessages = await client.getMessages({ threadId });
|
|
222
248
|
chunkMessageMerger.current.reset();
|
|
223
249
|
chunkMessageMerger.current.initialMessages(fetchedMessages);
|
|
224
250
|
setState((prev) => ({
|
|
225
251
|
...prev,
|
|
226
252
|
agentState,
|
|
253
|
+
interrupts,
|
|
227
254
|
todos: agentState?.values?.todos,
|
|
228
255
|
messages: chunkMessageMerger.current.getMessages(),
|
|
229
256
|
isLoading: false
|
|
@@ -278,6 +305,7 @@ function useChat(threadId, options = {}) {
|
|
|
278
305
|
setState((prev) => ({
|
|
279
306
|
...prev,
|
|
280
307
|
messages: [],
|
|
308
|
+
interrupts: void 0,
|
|
281
309
|
streamingMessage: null
|
|
282
310
|
}));
|
|
283
311
|
}, []);
|
|
@@ -1113,9 +1141,9 @@ var ToolCall = ({ data, eventHandler }) => {
|
|
|
1113
1141
|
import { Card as Card4, List, Typography as Typography5, Space as Space5 } from "antd";
|
|
1114
1142
|
import { createStyles as createStyles3 } from "antd-style";
|
|
1115
1143
|
import {
|
|
1144
|
+
ArrowRightOutlined,
|
|
1116
1145
|
CheckCircleOutlined as CheckCircleOutlined2,
|
|
1117
|
-
ClockCircleOutlined
|
|
1118
|
-
LoadingOutlined as LoadingOutlined2
|
|
1146
|
+
ClockCircleOutlined
|
|
1119
1147
|
} from "@ant-design/icons";
|
|
1120
1148
|
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1121
1149
|
var { Text: Text4 } = Typography5;
|
|
@@ -1157,7 +1185,7 @@ var Todo = ({
|
|
|
1157
1185
|
case "completed":
|
|
1158
1186
|
return /* @__PURE__ */ jsx7(CheckCircleOutlined2, { style: { color: "#52c41a" } });
|
|
1159
1187
|
case "in_progress":
|
|
1160
|
-
return /* @__PURE__ */ jsx7(
|
|
1188
|
+
return /* @__PURE__ */ jsx7(ArrowRightOutlined, { style: { fontWeight: "500" } });
|
|
1161
1189
|
case "pending":
|
|
1162
1190
|
return /* @__PURE__ */ jsx7(ClockCircleOutlined, { style: { color: "gray" } });
|
|
1163
1191
|
default:
|
|
@@ -1282,7 +1310,7 @@ var WriteTodos = ({
|
|
|
1282
1310
|
{
|
|
1283
1311
|
size: "small",
|
|
1284
1312
|
bordered: false,
|
|
1285
|
-
defaultActiveKey: [],
|
|
1313
|
+
defaultActiveKey: [toolCallData.id],
|
|
1286
1314
|
expandIcon,
|
|
1287
1315
|
children: /* @__PURE__ */ jsx8(
|
|
1288
1316
|
CollapsePanel2,
|
|
@@ -2685,6 +2713,7 @@ MemoizedBubbleList.displayName = "MemoizedBubbleList";
|
|
|
2685
2713
|
var Chating = ({
|
|
2686
2714
|
avatar,
|
|
2687
2715
|
name,
|
|
2716
|
+
interrupts,
|
|
2688
2717
|
description,
|
|
2689
2718
|
default_submit_message,
|
|
2690
2719
|
tenant_id,
|
|
@@ -3096,9 +3125,18 @@ ${JSON.stringify(tool_call)}
|
|
|
3096
3125
|
message: `${error.message}`
|
|
3097
3126
|
}
|
|
3098
3127
|
) }),
|
|
3128
|
+
interrupts && interrupts.length > 0 && /* @__PURE__ */ jsx19(Space10, { direction: "vertical", style: { width: "100%" }, children: interrupts.map((interrupt) => /* @__PURE__ */ jsx19(
|
|
3129
|
+
MDResponse,
|
|
3130
|
+
{
|
|
3131
|
+
content: interrupt.value,
|
|
3132
|
+
eventHandler: handleMDResponseEvent
|
|
3133
|
+
},
|
|
3134
|
+
interrupt.id
|
|
3135
|
+
)) }),
|
|
3099
3136
|
/* @__PURE__ */ jsx19(
|
|
3100
3137
|
Sender,
|
|
3101
3138
|
{
|
|
3139
|
+
disabled: interrupts && interrupts.length > 0,
|
|
3102
3140
|
allowSpeech: true,
|
|
3103
3141
|
ref: senderRef,
|
|
3104
3142
|
value: content,
|
|
@@ -3135,7 +3173,7 @@ ${JSON.stringify(tool_call)}
|
|
|
3135
3173
|
import {
|
|
3136
3174
|
CheckCircleOutlined as CheckCircleOutlined3,
|
|
3137
3175
|
InfoCircleOutlined as InfoCircleOutlined2,
|
|
3138
|
-
LoadingOutlined as
|
|
3176
|
+
LoadingOutlined as LoadingOutlined3
|
|
3139
3177
|
} from "@ant-design/icons";
|
|
3140
3178
|
import {
|
|
3141
3179
|
ThoughtChain
|
|
@@ -3148,7 +3186,7 @@ function getStatusIcon2(status) {
|
|
|
3148
3186
|
case "error":
|
|
3149
3187
|
return /* @__PURE__ */ jsx20(InfoCircleOutlined2, {});
|
|
3150
3188
|
case "pending":
|
|
3151
|
-
return /* @__PURE__ */ jsx20(
|
|
3189
|
+
return /* @__PURE__ */ jsx20(LoadingOutlined3, {});
|
|
3152
3190
|
default:
|
|
3153
3191
|
return /* @__PURE__ */ jsx20(CheckCircleOutlined3, {});
|
|
3154
3192
|
}
|