@axiom-lattice/react-sdk 2.1.8 → 2.1.10
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 +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +72 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -58,6 +58,7 @@ interface ChatResponse {
|
|
|
58
58
|
* Agent state interface
|
|
59
59
|
*/
|
|
60
60
|
interface AgentState {
|
|
61
|
+
createdAt?: string;
|
|
61
62
|
values: {
|
|
62
63
|
messages: Message[];
|
|
63
64
|
[key: string]: any;
|
|
@@ -446,6 +447,7 @@ interface ChatingProps {
|
|
|
446
447
|
showHeader?: boolean;
|
|
447
448
|
showSender?: boolean;
|
|
448
449
|
showHITL?: boolean;
|
|
450
|
+
showRefreshButton?: boolean;
|
|
449
451
|
}
|
|
450
452
|
declare const Chating: React__default.FC<ChatingProps>;
|
|
451
453
|
|
package/dist/index.d.ts
CHANGED
|
@@ -58,6 +58,7 @@ interface ChatResponse {
|
|
|
58
58
|
* Agent state interface
|
|
59
59
|
*/
|
|
60
60
|
interface AgentState {
|
|
61
|
+
createdAt?: string;
|
|
61
62
|
values: {
|
|
62
63
|
messages: Message[];
|
|
63
64
|
[key: string]: any;
|
|
@@ -446,6 +447,7 @@ interface ChatingProps {
|
|
|
446
447
|
showHeader?: boolean;
|
|
447
448
|
showSender?: boolean;
|
|
448
449
|
showHITL?: boolean;
|
|
450
|
+
showRefreshButton?: boolean;
|
|
449
451
|
}
|
|
450
452
|
declare const Chating: React__default.FC<ChatingProps>;
|
|
451
453
|
|
package/dist/index.js
CHANGED
|
@@ -441,15 +441,21 @@ function AgentThreadProvider({
|
|
|
441
441
|
});
|
|
442
442
|
const stopStreamingRef = (0, import_react3.useRef)(null);
|
|
443
443
|
const chunkMessageMerger = (0, import_react3.useRef)((0, import_client_sdk3.createSimpleMessageMerger)());
|
|
444
|
+
const lastAgentStateCreatedAtRef = (0, import_react3.useRef)(null);
|
|
444
445
|
const fetchAndUpdateAgentState = (0, import_react3.useCallback)(
|
|
445
446
|
async (threadId2) => {
|
|
446
447
|
if (!options.enableReturnStateWhenStreamCompleted) return;
|
|
447
448
|
try {
|
|
448
449
|
const agentState = await client.getAgentState(threadId2);
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
450
|
+
const currentCreatedAt = agentState?.createdAt;
|
|
451
|
+
const needsUpdate = !lastAgentStateCreatedAtRef.current || currentCreatedAt !== lastAgentStateCreatedAtRef.current;
|
|
452
|
+
if (currentCreatedAt) {
|
|
453
|
+
lastAgentStateCreatedAtRef.current = currentCreatedAt;
|
|
454
|
+
}
|
|
455
|
+
let needUpdateFields = {};
|
|
456
|
+
if (needsUpdate) {
|
|
457
|
+
needUpdateFields.agentState = agentState;
|
|
458
|
+
needUpdateFields.interrupts = agentState?.tasks?.flatMap((task) => {
|
|
453
459
|
return task.interrupts.map((interrupt) => {
|
|
454
460
|
return {
|
|
455
461
|
id: interrupt.id,
|
|
@@ -458,7 +464,12 @@ function AgentThreadProvider({
|
|
|
458
464
|
type: "interrupt"
|
|
459
465
|
};
|
|
460
466
|
});
|
|
461
|
-
})
|
|
467
|
+
});
|
|
468
|
+
needUpdateFields.todos = agentState?.values?.todos;
|
|
469
|
+
}
|
|
470
|
+
setState((prev) => ({
|
|
471
|
+
...prev,
|
|
472
|
+
...needUpdateFields
|
|
462
473
|
}));
|
|
463
474
|
} catch (error) {
|
|
464
475
|
console.warn("Failed to fetch agent state:", error);
|
|
@@ -628,27 +639,39 @@ function AgentThreadProvider({
|
|
|
628
639
|
setState((prev) => ({ ...prev, isLoading: true, error: null }));
|
|
629
640
|
try {
|
|
630
641
|
const agentState = await client.getAgentState(threadId);
|
|
631
|
-
const
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
642
|
+
const currentCreatedAt = agentState?.createdAt;
|
|
643
|
+
const needsUpdate = !lastAgentStateCreatedAtRef.current || currentCreatedAt !== lastAgentStateCreatedAtRef.current;
|
|
644
|
+
if (currentCreatedAt) {
|
|
645
|
+
lastAgentStateCreatedAtRef.current = currentCreatedAt;
|
|
646
|
+
}
|
|
647
|
+
let needUpdateFields = {};
|
|
648
|
+
let fetchedMessages = [];
|
|
649
|
+
if (needsUpdate) {
|
|
650
|
+
needUpdateFields.agentState = agentState;
|
|
651
|
+
needUpdateFields.todos = agentState?.values?.todos;
|
|
652
|
+
const interrupts = agentState?.tasks?.flatMap(
|
|
653
|
+
(task) => {
|
|
654
|
+
return task.interrupts.map((interrupt) => {
|
|
655
|
+
return {
|
|
656
|
+
id: interrupt.id,
|
|
657
|
+
value: interrupt.value,
|
|
658
|
+
role: "ai",
|
|
659
|
+
type: "interrupt"
|
|
660
|
+
};
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
);
|
|
664
|
+
needUpdateFields.interrupts = interrupts;
|
|
665
|
+
fetchedMessages = await client.getMessages({ threadId });
|
|
666
|
+
needUpdateFields.messages = fetchedMessages;
|
|
667
|
+
chunkMessageMerger.current.reset();
|
|
668
|
+
chunkMessageMerger.current.initialMessages(fetchedMessages);
|
|
669
|
+
} else {
|
|
670
|
+
fetchedMessages = chunkMessageMerger.current.getMessages();
|
|
671
|
+
}
|
|
646
672
|
setState((prev) => ({
|
|
647
673
|
...prev,
|
|
648
|
-
|
|
649
|
-
interrupts,
|
|
650
|
-
todos: agentState?.values?.todos,
|
|
651
|
-
messages: chunkMessageMerger.current.getMessages(),
|
|
674
|
+
...needUpdateFields,
|
|
652
675
|
isLoading: false
|
|
653
676
|
}));
|
|
654
677
|
if (options.enableResumeStream && fetchedMessages.length > 0) {
|
|
@@ -702,6 +725,7 @@ function AgentThreadProvider({
|
|
|
702
725
|
);
|
|
703
726
|
const clearMessages = (0, import_react3.useCallback)(() => {
|
|
704
727
|
chunkMessageMerger.current.reset();
|
|
728
|
+
lastAgentStateCreatedAtRef.current = null;
|
|
705
729
|
setState((prev) => ({
|
|
706
730
|
...prev,
|
|
707
731
|
messages: [],
|
|
@@ -716,7 +740,8 @@ function AgentThreadProvider({
|
|
|
716
740
|
}));
|
|
717
741
|
}, []);
|
|
718
742
|
(0, import_react3.useEffect)(() => {
|
|
719
|
-
if (threadId) {
|
|
743
|
+
if (threadId && clientAssistantId === assistantId) {
|
|
744
|
+
lastAgentStateCreatedAtRef.current = null;
|
|
720
745
|
loadMessages();
|
|
721
746
|
} else {
|
|
722
747
|
clearMessages();
|
|
@@ -727,7 +752,7 @@ function AgentThreadProvider({
|
|
|
727
752
|
stopStreamingRef.current = null;
|
|
728
753
|
}
|
|
729
754
|
};
|
|
730
|
-
}, [threadId, loadMessages, clearMessages]);
|
|
755
|
+
}, [threadId, loadMessages, clearMessages, clientAssistantId, assistantId]);
|
|
731
756
|
const value = {
|
|
732
757
|
state,
|
|
733
758
|
sendMessage,
|
|
@@ -3262,17 +3287,17 @@ var useStyle5 = (0, import_antd_style7.createStyles)(({ token, css }) => ({
|
|
|
3262
3287
|
&:hover {
|
|
3263
3288
|
border-color: ${token.colorPrimary};
|
|
3264
3289
|
box-shadow: 0 8px 24px rgba(24, 144, 255, 0.12);
|
|
3265
|
-
transform:
|
|
3290
|
+
transform: translateX(4px);
|
|
3266
3291
|
}
|
|
3267
3292
|
&::before {
|
|
3268
3293
|
content: "";
|
|
3269
3294
|
position: absolute;
|
|
3270
3295
|
top: 0;
|
|
3271
3296
|
left: 0;
|
|
3272
|
-
|
|
3273
|
-
|
|
3297
|
+
bottom: 0;
|
|
3298
|
+
width: 4px;
|
|
3274
3299
|
background: linear-gradient(
|
|
3275
|
-
|
|
3300
|
+
180deg,
|
|
3276
3301
|
${token.colorPrimary} 0%,
|
|
3277
3302
|
${token.colorPrimaryHover} 100%
|
|
3278
3303
|
);
|
|
@@ -3390,7 +3415,7 @@ var TaskCard = ({
|
|
|
3390
3415
|
const { description, subagent_type, assignee } = toolCallData?.args || {};
|
|
3391
3416
|
const status = toolCallData.status || "pending";
|
|
3392
3417
|
const { threadId } = useAgentChat();
|
|
3393
|
-
const subagent_thread_id = (threadId || "") + "
|
|
3418
|
+
const subagent_thread_id = (threadId || "") + "____" + subagent_type + "_" + toolCallData.id;
|
|
3394
3419
|
const getStatusConfig = (status2) => {
|
|
3395
3420
|
switch (status2) {
|
|
3396
3421
|
case "success":
|
|
@@ -3869,7 +3894,8 @@ var Chating = ({
|
|
|
3869
3894
|
uploadAction = "/api/file_storage/upload?path=temp",
|
|
3870
3895
|
showHeader = true,
|
|
3871
3896
|
showSender = true,
|
|
3872
|
-
showHITL = true
|
|
3897
|
+
showHITL = true,
|
|
3898
|
+
showRefreshButton = false
|
|
3873
3899
|
}) => {
|
|
3874
3900
|
const [content, setContent] = (0, import_react18.useState)("");
|
|
3875
3901
|
const [attachedFiles, setAttachedFiles] = (0, import_react18.useState)([]);
|
|
@@ -3881,6 +3907,7 @@ var Chating = ({
|
|
|
3881
3907
|
messages,
|
|
3882
3908
|
sendMessage,
|
|
3883
3909
|
stopStreaming,
|
|
3910
|
+
loadMessages,
|
|
3884
3911
|
isLoading,
|
|
3885
3912
|
error,
|
|
3886
3913
|
interrupts,
|
|
@@ -4022,6 +4049,17 @@ var Chating = ({
|
|
|
4022
4049
|
)
|
|
4023
4050
|
}
|
|
4024
4051
|
);
|
|
4052
|
+
const refreshButton = /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
4053
|
+
import_antd19.Button,
|
|
4054
|
+
{
|
|
4055
|
+
type: "text",
|
|
4056
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_icons11.ReloadOutlined, {}),
|
|
4057
|
+
onClick: () => {
|
|
4058
|
+
loadMessages();
|
|
4059
|
+
}
|
|
4060
|
+
}
|
|
4061
|
+
);
|
|
4062
|
+
const headerExtra = showRefreshButton ? [refreshButton] : [];
|
|
4025
4063
|
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(import_jsx_runtime28.Fragment, { children: [
|
|
4026
4064
|
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { children: showHeader && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
4027
4065
|
AgentHeader,
|
|
@@ -4029,7 +4067,7 @@ var Chating = ({
|
|
|
4029
4067
|
description,
|
|
4030
4068
|
avatar,
|
|
4031
4069
|
name,
|
|
4032
|
-
extra,
|
|
4070
|
+
extra: extra ? [...extra, ...headerExtra] : headerExtra,
|
|
4033
4071
|
extraMeta
|
|
4034
4072
|
}
|
|
4035
4073
|
) }),
|
|
@@ -4089,7 +4127,7 @@ var TaskDetail = ({ data, component_key, interactive = true }) => {
|
|
|
4089
4127
|
children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { style: { overflow: "hidden" }, children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
|
|
4090
4128
|
Chating,
|
|
4091
4129
|
{
|
|
4092
|
-
|
|
4130
|
+
showRefreshButton: true,
|
|
4093
4131
|
name: subagent_type,
|
|
4094
4132
|
showHeader: true,
|
|
4095
4133
|
showSender: false,
|