@axiom-lattice/react-sdk 2.1.9 → 2.1.11

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.mjs CHANGED
@@ -396,24 +396,33 @@ function AgentThreadProvider({
396
396
  });
397
397
  const stopStreamingRef = useRef2(null);
398
398
  const chunkMessageMerger = useRef2(createSimpleMessageMerger2());
399
+ const lastAgentStateCreatedAtRef = useRef2(null);
399
400
  const fetchAndUpdateAgentState = useCallback2(
400
401
  async (threadId2) => {
401
402
  if (!options.enableReturnStateWhenStreamCompleted) return;
402
403
  try {
403
404
  const agentState = await client.getAgentState(threadId2);
405
+ const currentCreatedAt = agentState?.createdAt;
406
+ const needsUpdate = !lastAgentStateCreatedAtRef.current || currentCreatedAt !== lastAgentStateCreatedAtRef.current;
407
+ if (currentCreatedAt) {
408
+ lastAgentStateCreatedAtRef.current = currentCreatedAt;
409
+ }
410
+ let needUpdateFields = {};
411
+ needUpdateFields.agentState = agentState;
412
+ needUpdateFields.interrupts = agentState?.tasks?.flatMap((task) => {
413
+ return task.interrupts.map((interrupt) => {
414
+ return {
415
+ id: interrupt.id,
416
+ value: interrupt.value,
417
+ role: "ai",
418
+ type: "interrupt"
419
+ };
420
+ });
421
+ });
422
+ needUpdateFields.todos = agentState?.values?.todos;
404
423
  setState((prev) => ({
405
424
  ...prev,
406
- agentState,
407
- interrupts: agentState?.tasks?.flatMap((task) => {
408
- return task.interrupts.map((interrupt) => {
409
- return {
410
- id: interrupt.id,
411
- value: interrupt.value,
412
- role: "ai",
413
- type: "interrupt"
414
- };
415
- });
416
- })
425
+ ...needUpdateFields
417
426
  }));
418
427
  } catch (error) {
419
428
  console.warn("Failed to fetch agent state:", error);
@@ -583,6 +592,15 @@ function AgentThreadProvider({
583
592
  setState((prev) => ({ ...prev, isLoading: true, error: null }));
584
593
  try {
585
594
  const agentState = await client.getAgentState(threadId);
595
+ const currentCreatedAt = agentState?.createdAt;
596
+ const needsUpdate = !lastAgentStateCreatedAtRef.current || currentCreatedAt !== lastAgentStateCreatedAtRef.current;
597
+ if (currentCreatedAt) {
598
+ lastAgentStateCreatedAtRef.current = currentCreatedAt;
599
+ }
600
+ let needUpdateFields = {};
601
+ let fetchedMessages = [];
602
+ needUpdateFields.agentState = agentState;
603
+ needUpdateFields.todos = agentState?.values?.todos;
586
604
  const interrupts = agentState?.tasks?.flatMap(
587
605
  (task) => {
588
606
  return task.interrupts.map((interrupt) => {
@@ -595,15 +613,14 @@ function AgentThreadProvider({
595
613
  });
596
614
  }
597
615
  );
598
- const fetchedMessages = await client.getMessages({ threadId });
616
+ needUpdateFields.interrupts = interrupts;
617
+ fetchedMessages = await client.getMessages({ threadId });
618
+ needUpdateFields.messages = fetchedMessages;
599
619
  chunkMessageMerger.current.reset();
600
620
  chunkMessageMerger.current.initialMessages(fetchedMessages);
601
621
  setState((prev) => ({
602
622
  ...prev,
603
- agentState,
604
- interrupts,
605
- todos: agentState?.values?.todos,
606
- messages: chunkMessageMerger.current.getMessages(),
623
+ ...needUpdateFields,
607
624
  isLoading: false
608
625
  }));
609
626
  if (options.enableResumeStream && fetchedMessages.length > 0) {
@@ -657,6 +674,7 @@ function AgentThreadProvider({
657
674
  );
658
675
  const clearMessages = useCallback2(() => {
659
676
  chunkMessageMerger.current.reset();
677
+ lastAgentStateCreatedAtRef.current = null;
660
678
  setState((prev) => ({
661
679
  ...prev,
662
680
  messages: [],
@@ -672,6 +690,7 @@ function AgentThreadProvider({
672
690
  }, []);
673
691
  useEffect3(() => {
674
692
  if (threadId && clientAssistantId === assistantId) {
693
+ lastAgentStateCreatedAtRef.current = null;
675
694
  loadMessages();
676
695
  } else {
677
696
  clearMessages();
@@ -3259,17 +3278,17 @@ var useStyle5 = createStyles7(({ token, css }) => ({
3259
3278
  &:hover {
3260
3279
  border-color: ${token.colorPrimary};
3261
3280
  box-shadow: 0 8px 24px rgba(24, 144, 255, 0.12);
3262
- transform: translateY(-4px);
3281
+ transform: translateX(4px);
3263
3282
  }
3264
3283
  &::before {
3265
3284
  content: "";
3266
3285
  position: absolute;
3267
3286
  top: 0;
3268
3287
  left: 0;
3269
- right: 0;
3270
- height: 4px;
3288
+ bottom: 0;
3289
+ width: 4px;
3271
3290
  background: linear-gradient(
3272
- 90deg,
3291
+ 180deg,
3273
3292
  ${token.colorPrimary} 0%,
3274
3293
  ${token.colorPrimaryHover} 100%
3275
3294
  );
@@ -3387,7 +3406,7 @@ var TaskCard = ({
3387
3406
  const { description, subagent_type, assignee } = toolCallData?.args || {};
3388
3407
  const status = toolCallData.status || "pending";
3389
3408
  const { threadId } = useAgentChat();
3390
- const subagent_thread_id = (threadId || "") + "_" + subagent_type + "_" + toolCallData.id;
3409
+ const subagent_thread_id = (threadId || "") + "____" + subagent_type + "_" + toolCallData.id;
3391
3410
  const getStatusConfig = (status2) => {
3392
3411
  switch (status2) {
3393
3412
  case "success":
@@ -3485,10 +3504,13 @@ var TaskCard = ({
3485
3504
  import { Typography as Typography12 } from "antd";
3486
3505
 
3487
3506
  // src/components/Chat/Chating.tsx
3488
- import { CloudUploadOutlined, PaperClipOutlined } from "@ant-design/icons";
3507
+ import {
3508
+ CloudUploadOutlined,
3509
+ PaperClipOutlined,
3510
+ ReloadOutlined
3511
+ } from "@ant-design/icons";
3489
3512
  import {
3490
3513
  Attachments,
3491
- Bubble as Bubble2,
3492
3514
  Prompts,
3493
3515
  Sender
3494
3516
  } from "@ant-design/x";
@@ -3888,7 +3910,8 @@ var Chating = ({
3888
3910
  uploadAction = "/api/file_storage/upload?path=temp",
3889
3911
  showHeader = true,
3890
3912
  showSender = true,
3891
- showHITL = true
3913
+ showHITL = true,
3914
+ showRefreshButton = false
3892
3915
  }) => {
3893
3916
  const [content, setContent] = useState16("");
3894
3917
  const [attachedFiles, setAttachedFiles] = useState16([]);
@@ -3900,6 +3923,7 @@ var Chating = ({
3900
3923
  messages,
3901
3924
  sendMessage,
3902
3925
  stopStreaming,
3926
+ loadMessages,
3903
3927
  isLoading,
3904
3928
  error,
3905
3929
  interrupts,
@@ -4041,6 +4065,17 @@ var Chating = ({
4041
4065
  )
4042
4066
  }
4043
4067
  );
4068
+ const refreshButton = /* @__PURE__ */ jsx28(
4069
+ Button10,
4070
+ {
4071
+ type: "text",
4072
+ icon: /* @__PURE__ */ jsx28(ReloadOutlined, {}),
4073
+ onClick: () => {
4074
+ loadMessages();
4075
+ }
4076
+ }
4077
+ );
4078
+ const headerExtra = showRefreshButton ? [refreshButton] : [];
4044
4079
  return /* @__PURE__ */ jsxs17(Fragment4, { children: [
4045
4080
  /* @__PURE__ */ jsx28("div", { children: showHeader && /* @__PURE__ */ jsx28(
4046
4081
  AgentHeader,
@@ -4048,12 +4083,12 @@ var Chating = ({
4048
4083
  description,
4049
4084
  avatar,
4050
4085
  name,
4051
- extra,
4086
+ extra: extra ? [...extra, ...headerExtra] : headerExtra,
4052
4087
  extraMeta
4053
4088
  }
4054
4089
  ) }),
4055
4090
  /* @__PURE__ */ jsx28(MessageList, { messages, className: styles.messages }),
4056
- isLoading ? /* @__PURE__ */ jsx28("div", { children: /* @__PURE__ */ jsx28(Bubble2, { loading: isLoading, variant: "borderless", content: "" }) }) : /* @__PURE__ */ jsx28(Prompts, { items: senderPromptsItems, onItemClick: onPromptsItemClick }),
4091
+ isLoading ? /* @__PURE__ */ jsx28("div", {}) : /* @__PURE__ */ jsx28(Prompts, { items: senderPromptsItems, onItemClick: onPromptsItemClick }),
4057
4092
  error && /* @__PURE__ */ jsx28("div", { style: { padding: "0 16px 8px" }, children: /* @__PURE__ */ jsx28(
4058
4093
  Alert2,
4059
4094
  {
@@ -4108,6 +4143,7 @@ var TaskDetail = ({ data, component_key, interactive = true }) => {
4108
4143
  children: /* @__PURE__ */ jsx29("div", { style: { overflow: "hidden" }, children: /* @__PURE__ */ jsx29(
4109
4144
  Chating,
4110
4145
  {
4146
+ showRefreshButton: true,
4111
4147
  name: subagent_type,
4112
4148
  showHeader: true,
4113
4149
  showSender: false,