@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.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Message, MessageChunk } from '@axiom-lattice/protocols';
|
|
1
|
+
import { Message, MessageChunk, InterruptMessage } from '@axiom-lattice/protocols';
|
|
2
2
|
export * from '@axiom-lattice/protocols';
|
|
3
3
|
import * as React$1 from 'react';
|
|
4
4
|
import React__default, { ReactNode } from 'react';
|
|
@@ -92,6 +92,10 @@ interface ChatState {
|
|
|
92
92
|
* Current streaming message (if any)
|
|
93
93
|
*/
|
|
94
94
|
streamingMessage: MessageChunk | null;
|
|
95
|
+
/**
|
|
96
|
+
* Interrupt data when agent requires user intervention
|
|
97
|
+
*/
|
|
98
|
+
interrupts: InterruptMessage[] | undefined;
|
|
95
99
|
}
|
|
96
100
|
/**
|
|
97
101
|
* Extended chat state with agent state
|
|
@@ -386,6 +390,7 @@ interface ChatingProps {
|
|
|
386
390
|
onOpenSidePanel: (data: any) => void;
|
|
387
391
|
onReminderClick: () => void;
|
|
388
392
|
onClearError?: () => void;
|
|
393
|
+
interrupts: InterruptMessage[] | undefined;
|
|
389
394
|
styles: any;
|
|
390
395
|
reminderCount: number;
|
|
391
396
|
handleMDResponseEvent: (action: string, data?: any, message?: string, agent?: string) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Message, MessageChunk } from '@axiom-lattice/protocols';
|
|
1
|
+
import { Message, MessageChunk, InterruptMessage } from '@axiom-lattice/protocols';
|
|
2
2
|
export * from '@axiom-lattice/protocols';
|
|
3
3
|
import * as React$1 from 'react';
|
|
4
4
|
import React__default, { ReactNode } from 'react';
|
|
@@ -92,6 +92,10 @@ interface ChatState {
|
|
|
92
92
|
* Current streaming message (if any)
|
|
93
93
|
*/
|
|
94
94
|
streamingMessage: MessageChunk | null;
|
|
95
|
+
/**
|
|
96
|
+
* Interrupt data when agent requires user intervention
|
|
97
|
+
*/
|
|
98
|
+
interrupts: InterruptMessage[] | undefined;
|
|
95
99
|
}
|
|
96
100
|
/**
|
|
97
101
|
* Extended chat state with agent state
|
|
@@ -386,6 +390,7 @@ interface ChatingProps {
|
|
|
386
390
|
onOpenSidePanel: (data: any) => void;
|
|
387
391
|
onReminderClick: () => void;
|
|
388
392
|
onClearError?: () => void;
|
|
393
|
+
interrupts: InterruptMessage[] | undefined;
|
|
389
394
|
styles: any;
|
|
390
395
|
reminderCount: number;
|
|
391
396
|
handleMDResponseEvent: (action: string, data?: any, message?: string, agent?: string) => void;
|
package/dist/index.js
CHANGED
|
@@ -96,6 +96,7 @@ function useChat(threadId, options = {}) {
|
|
|
96
96
|
isLoading: false,
|
|
97
97
|
error: null,
|
|
98
98
|
streamingMessage: null,
|
|
99
|
+
interrupts: void 0,
|
|
99
100
|
...options.enableReturnStateWhenStreamCompleted ? { agentState: null } : {}
|
|
100
101
|
});
|
|
101
102
|
const stopStreamingRef = (0, import_react2.useRef)(null);
|
|
@@ -108,7 +109,15 @@ function useChat(threadId, options = {}) {
|
|
|
108
109
|
setState(
|
|
109
110
|
(prev) => ({
|
|
110
111
|
...prev,
|
|
111
|
-
agentState
|
|
112
|
+
agentState,
|
|
113
|
+
interrupts: agentState?.tasks?.flatMap((task) => {
|
|
114
|
+
return task.interrupts.map((interrupt) => {
|
|
115
|
+
return {
|
|
116
|
+
id: interrupt.id,
|
|
117
|
+
value: interrupt.value
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
})
|
|
112
121
|
})
|
|
113
122
|
);
|
|
114
123
|
} catch (error) {
|
|
@@ -122,29 +131,38 @@ function useChat(threadId, options = {}) {
|
|
|
122
131
|
chunkMessageMerger.current.initialMessages(options.initialMessages);
|
|
123
132
|
}
|
|
124
133
|
}, [options.initialMessages]);
|
|
125
|
-
const handleStreamEvent = (0, import_react2.useCallback)(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
+
const handleStreamEvent = (0, import_react2.useCallback)(
|
|
135
|
+
(chunk) => {
|
|
136
|
+
let interrupt;
|
|
137
|
+
if (chunk.type === "interrupt") {
|
|
138
|
+
interrupt = chunk;
|
|
139
|
+
} else {
|
|
140
|
+
chunkMessageMerger.current.push(chunk);
|
|
141
|
+
}
|
|
142
|
+
let todos;
|
|
143
|
+
if (chunk.type === "tool" && chunk.data && typeof chunk.data.content === "string" && chunk.data.content.startsWith("```todo_list")) {
|
|
144
|
+
try {
|
|
145
|
+
const content = chunk.data.content;
|
|
146
|
+
const match = content.match(/```todo_list\s*([\s\S]*?)\s*```/);
|
|
147
|
+
if (match && match[1]) {
|
|
148
|
+
todos = JSON.parse(match[1]);
|
|
149
|
+
}
|
|
150
|
+
} catch (e) {
|
|
151
|
+
console.error("Failed to parse todo list from chunk", e);
|
|
134
152
|
}
|
|
135
|
-
} catch (e) {
|
|
136
|
-
console.error("Failed to parse todo list from chunk", e);
|
|
137
153
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
154
|
+
const updatedMessages = chunkMessageMerger.current.getMessages();
|
|
155
|
+
setState((prev) => ({
|
|
156
|
+
...prev,
|
|
157
|
+
interrupts: interrupt ? [interrupt] : void 0,
|
|
158
|
+
todos: todos || prev.todos,
|
|
159
|
+
messages: updatedMessages,
|
|
160
|
+
isLoading: true,
|
|
161
|
+
streamingMessage: null
|
|
162
|
+
}));
|
|
163
|
+
},
|
|
164
|
+
[]
|
|
165
|
+
);
|
|
148
166
|
const sendMessage = (0, import_react2.useCallback)(
|
|
149
167
|
async (data) => {
|
|
150
168
|
if (!threadId) {
|
|
@@ -271,12 +289,21 @@ function useChat(threadId, options = {}) {
|
|
|
271
289
|
setState((prev) => ({ ...prev, isLoading: true, error: null }));
|
|
272
290
|
try {
|
|
273
291
|
const agentState = await client.getAgentState(threadId);
|
|
292
|
+
const interrupts = agentState?.tasks?.flatMap((task) => {
|
|
293
|
+
return task.interrupts.map((interrupt) => {
|
|
294
|
+
return {
|
|
295
|
+
id: interrupt.id,
|
|
296
|
+
value: interrupt.value
|
|
297
|
+
};
|
|
298
|
+
});
|
|
299
|
+
});
|
|
274
300
|
const fetchedMessages = await client.getMessages({ threadId });
|
|
275
301
|
chunkMessageMerger.current.reset();
|
|
276
302
|
chunkMessageMerger.current.initialMessages(fetchedMessages);
|
|
277
303
|
setState((prev) => ({
|
|
278
304
|
...prev,
|
|
279
305
|
agentState,
|
|
306
|
+
interrupts,
|
|
280
307
|
todos: agentState?.values?.todos,
|
|
281
308
|
messages: chunkMessageMerger.current.getMessages(),
|
|
282
309
|
isLoading: false
|
|
@@ -331,6 +358,7 @@ function useChat(threadId, options = {}) {
|
|
|
331
358
|
setState((prev) => ({
|
|
332
359
|
...prev,
|
|
333
360
|
messages: [],
|
|
361
|
+
interrupts: void 0,
|
|
334
362
|
streamingMessage: null
|
|
335
363
|
}));
|
|
336
364
|
}, []);
|
|
@@ -1202,7 +1230,7 @@ var Todo = ({
|
|
|
1202
1230
|
case "completed":
|
|
1203
1231
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_icons4.CheckCircleOutlined, { style: { color: "#52c41a" } });
|
|
1204
1232
|
case "in_progress":
|
|
1205
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_icons4.
|
|
1233
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_icons4.ArrowRightOutlined, { style: { fontWeight: "500" } });
|
|
1206
1234
|
case "pending":
|
|
1207
1235
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_icons4.ClockCircleOutlined, { style: { color: "gray" } });
|
|
1208
1236
|
default:
|
|
@@ -1327,7 +1355,7 @@ var WriteTodos = ({
|
|
|
1327
1355
|
{
|
|
1328
1356
|
size: "small",
|
|
1329
1357
|
bordered: false,
|
|
1330
|
-
defaultActiveKey: [],
|
|
1358
|
+
defaultActiveKey: [toolCallData.id],
|
|
1331
1359
|
expandIcon,
|
|
1332
1360
|
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1333
1361
|
import_CollapsePanel2.default,
|
|
@@ -2680,6 +2708,7 @@ MemoizedBubbleList.displayName = "MemoizedBubbleList";
|
|
|
2680
2708
|
var Chating = ({
|
|
2681
2709
|
avatar,
|
|
2682
2710
|
name,
|
|
2711
|
+
interrupts,
|
|
2683
2712
|
description,
|
|
2684
2713
|
default_submit_message,
|
|
2685
2714
|
tenant_id,
|
|
@@ -3091,9 +3120,18 @@ ${JSON.stringify(tool_call)}
|
|
|
3091
3120
|
message: `${error.message}`
|
|
3092
3121
|
}
|
|
3093
3122
|
) }),
|
|
3123
|
+
interrupts && interrupts.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(import_antd13.Space, { direction: "vertical", style: { width: "100%" }, children: interrupts.map((interrupt) => /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
3124
|
+
MDResponse,
|
|
3125
|
+
{
|
|
3126
|
+
content: interrupt.value,
|
|
3127
|
+
eventHandler: handleMDResponseEvent
|
|
3128
|
+
},
|
|
3129
|
+
interrupt.id
|
|
3130
|
+
)) }),
|
|
3094
3131
|
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
3095
3132
|
import_x2.Sender,
|
|
3096
3133
|
{
|
|
3134
|
+
disabled: interrupts && interrupts.length > 0,
|
|
3097
3135
|
allowSpeech: true,
|
|
3098
3136
|
ref: senderRef,
|
|
3099
3137
|
value: content,
|