@kite-copilot/chat-panel 0.2.27 → 0.2.29

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.cjs CHANGED
@@ -1376,6 +1376,11 @@ function ChatPanel({
1376
1376
  const escalationWsRef = React4.useRef(null);
1377
1377
  const resetSession = React4.useCallback(() => {
1378
1378
  setSessionId(crypto.randomUUID());
1379
+ setIsEscalated(false);
1380
+ if (escalationWsRef.current) {
1381
+ escalationWsRef.current.close();
1382
+ escalationWsRef.current = null;
1383
+ }
1379
1384
  }, []);
1380
1385
  const streamIntervals = React4.useRef({});
1381
1386
  const isEmpty = messages.length === 0;
@@ -1609,12 +1614,23 @@ function ChatPanel({
1609
1614
  try {
1610
1615
  const data = JSON.parse(event.data);
1611
1616
  if (data.type === "agent_message") {
1612
- setMessages((prev) => [...prev, {
1613
- id: Date.now(),
1614
- role: "agent",
1615
- kind: "text",
1616
- content: data.content
1617
- }]);
1617
+ setMessages((prev) => {
1618
+ const content = data.content;
1619
+ const messageId = data.message_id;
1620
+ const isDuplicate = messageId ? prev.some((m) => m.serverMessageId === messageId) : prev.slice(-5).some((m) => m.content === content);
1621
+ if (isDuplicate) {
1622
+ console.debug("[KiteChat] Skipping duplicate agent message:", messageId || content.slice(0, 30));
1623
+ return prev;
1624
+ }
1625
+ return [...prev, {
1626
+ id: Date.now(),
1627
+ role: "agent",
1628
+ kind: "text",
1629
+ content,
1630
+ serverMessageId: messageId
1631
+ // Store server ID for deduplication
1632
+ }];
1633
+ });
1618
1634
  } else if (data.type === "error") {
1619
1635
  console.error("[KiteChat] Escalation error:", data.message);
1620
1636
  }
@@ -1659,7 +1675,7 @@ function ChatPanel({
1659
1675
  }
1660
1676
  }, [isEscalated, sessionId, connectToEscalationWs]);
1661
1677
  function streamAssistantMessage(messageId, fullText, followups) {
1662
- let textToStream = fullText;
1678
+ let textToStream = fullText || "";
1663
1679
  let extractedFollowups = followups;
1664
1680
  if (fullText && fullText.startsWith("{") && fullText.includes('"response"')) {
1665
1681
  try {
@@ -1959,6 +1975,12 @@ function ChatPanel({
1959
1975
  if (data.status === "thinking") {
1960
1976
  setPhase("thinking");
1961
1977
  setProgressSteps([{ message: data.message, completed: false }]);
1978
+ } else if (data.status === "searching") {
1979
+ setPhase("thinking");
1980
+ setProgressSteps([{ message: data.message || "Searching knowledge base...", completed: false }]);
1981
+ } else if (data.status === "evaluating") {
1982
+ setPhase("thinking");
1983
+ setProgressSteps([{ message: data.message || "Evaluating sources...", completed: false }]);
1962
1984
  } else if (data.status === "executing") {
1963
1985
  setPhase("executing");
1964
1986
  setProgressSteps((prev) => {
@@ -2060,7 +2082,7 @@ function ChatPanel({
2060
2082
  setMessages((prev) => [...prev, assistantMessage]);
2061
2083
  streamAssistantMessage(
2062
2084
  assistantMessageId,
2063
- agentResponse.response,
2085
+ agentResponse.response || "Action completed successfully.",
2064
2086
  agentResponse.followups
2065
2087
  );
2066
2088
  streamCompleted = true;
@@ -2082,7 +2104,7 @@ function ChatPanel({
2082
2104
  setMessages((prev) => [...prev, assistantMessage]);
2083
2105
  streamAssistantMessage(
2084
2106
  assistantMessageId,
2085
- agentResponse.response,
2107
+ agentResponse.response || agentResponse.message || "",
2086
2108
  agentResponse.followups
2087
2109
  );
2088
2110
  streamCompleted = true;
@@ -2118,6 +2140,10 @@ function ChatPanel({
2118
2140
  content: data.message || "You've been connected to our support queue. An agent will be with you shortly."
2119
2141
  };
2120
2142
  setMessages((prev) => [...prev, escalationMessage]);
2143
+ } else if (eventType === "token") {
2144
+ if (process.env.NODE_ENV === "development") {
2145
+ console.debug("[SSE] Token delta:", data.delta?.length || 0, "chars");
2146
+ }
2121
2147
  }
2122
2148
  } catch (parseError) {
2123
2149
  console.error("Failed to parse SSE event:", parseError);
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ import {
31
31
  cn,
32
32
  createKiteChat,
33
33
  useGuideCursor
34
- } from "./chunk-4KYS4INW.js";
34
+ } from "./chunk-DGU3KTFD.js";
35
35
  export {
36
36
  ApiKeyList,
37
37
  AssistantActivity,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kite-copilot/chat-panel",
3
- "version": "0.2.27",
3
+ "version": "0.2.29",
4
4
  "description": "AI-powered chat panel SDK with programmatic lifecycle control",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",