@cntyclub/agent-react 0.14.0 → 0.14.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"agent-widget.d.ts","sourceRoot":"","sources":["../../src/components/agent-widget.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,UAAU,CAAC;AAK1D,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,WAAW,CAAC;IACpB,wCAAwC;IACxC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;CACtC;AAQD;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,EAC1B,MAAM,EACN,YAAY,EACZ,IAAI,EAAE,cAAc,EACpB,YAAyB,GAC1B,EAAE,gBAAgB,qBAgUlB"}
1
+ {"version":3,"file":"agent-widget.d.ts","sourceRoot":"","sources":["../../src/components/agent-widget.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,WAAW,EAAgB,MAAM,UAAU,CAAC;AAK1D,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,WAAW,CAAC;IACpB,wCAAwC;IACxC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC;;;;;;;;;OASG;IACH,YAAY,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;CACtC;AAQD;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,EAC1B,MAAM,EACN,YAAY,EACZ,IAAI,EAAE,cAAc,EACpB,YAAyB,GAC1B,EAAE,gBAAgB,qBAiVlB"}
package/dist/index.js CHANGED
@@ -1838,6 +1838,7 @@ function useAgentChat(config) {
1838
1838
  const client = React11.useMemo(() => new AgentApiClient(config), [config]);
1839
1839
  const [agentInfo, setAgentInfo] = React11.useState(null);
1840
1840
  const [conversationId, setConversationId] = React11.useState(null);
1841
+ const [conversationEpoch, setConversationEpoch] = React11.useState(0);
1841
1842
  const [conversations, setConversations] = React11.useState([]);
1842
1843
  const [messages, setMessages] = React11.useState([]);
1843
1844
  const [pendingApprovals, setPendingApprovals] = React11.useState([]);
@@ -2017,6 +2018,7 @@ function useAgentChat(config) {
2017
2018
  setMessages([]);
2018
2019
  setPendingApprovals([]);
2019
2020
  setError(null);
2021
+ setConversationEpoch((e) => e + 1);
2020
2022
  }, []);
2021
2023
  const refreshConversations = React11.useCallback(async () => {
2022
2024
  try {
@@ -2036,6 +2038,7 @@ function useAgentChat(config) {
2036
2038
  setConversationId(id);
2037
2039
  setMessages(payload.messages ?? []);
2038
2040
  setPendingApprovals(payload.pending_approvals ?? []);
2041
+ setConversationEpoch((e) => e + 1);
2039
2042
  } catch (err) {
2040
2043
  handleFailure(err);
2041
2044
  }
@@ -2059,6 +2062,7 @@ function useAgentChat(config) {
2059
2062
  agentInfo,
2060
2063
  clearError,
2061
2064
  conversationId,
2065
+ conversationEpoch,
2062
2066
  conversations,
2063
2067
  deleteConversation,
2064
2068
  error,
@@ -2246,10 +2250,16 @@ function AgentWidget({
2246
2250
  }
2247
2251
  }, [messages, onWriteSuccess]);
2248
2252
  const lastNavigatedMessageId = React11.useRef(null);
2253
+ const navEpochRef = React11.useRef(-1);
2249
2254
  React11.useEffect(() => {
2250
2255
  if (!open || fullscreen || !config.navigate || !config.pages?.length) return;
2251
2256
  const toolMessages = messages.filter((message) => message.role === "tool");
2252
2257
  const latest = toolMessages[toolMessages.length - 1];
2258
+ if (navEpochRef.current !== chat.conversationEpoch) {
2259
+ navEpochRef.current = chat.conversationEpoch;
2260
+ lastNavigatedMessageId.current = latest?.id ?? null;
2261
+ return;
2262
+ }
2253
2263
  if (!latest || latest.id === lastNavigatedMessageId.current) return;
2254
2264
  lastNavigatedMessageId.current = latest.id;
2255
2265
  const mapping = config.pages.find((page) => page.tools.includes(latest.tool_name ?? ""));
@@ -2259,7 +2269,7 @@ function AgentWidget({
2259
2269
  if (!path) return;
2260
2270
  const scrollTo = typeof mapping.scrollTo === "function" ? mapping.scrollTo(args) : mapping.scrollTo;
2261
2271
  config.navigate(path, { scrollTo: scrollTo ?? null });
2262
- }, [config, fullscreen, messages, open]);
2272
+ }, [chat.conversationEpoch, config, fullscreen, messages, open]);
2263
2273
  const closePanel = React11.useCallback(() => {
2264
2274
  setOpen(false);
2265
2275
  setAgentMode(false);