@agno-hq/chat-react 0.1.0 → 0.1.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.
package/dist/index.js CHANGED
@@ -303,6 +303,35 @@ function toolsFromEvent(e) {
303
303
  if (Array.isArray(e.tools)) out.push(...e.tools);
304
304
  return out;
305
305
  }
306
+ function applyContentEvent(message, e) {
307
+ const next = { ...message };
308
+ if (typeof e.content === "string" && e.content) {
309
+ next.content = message.content + e.content;
310
+ } else if (e.content && typeof e.content === "object") {
311
+ next.content = message.content + "\n```json\n" + JSON.stringify(e.content, null, 2) + "\n```\n";
312
+ }
313
+ if (e.reasoning_steps?.length) next.reasoning_steps = e.reasoning_steps;
314
+ if (e.extra_data?.reasoning_steps?.length) next.reasoning_steps = e.extra_data.reasoning_steps;
315
+ if (e.references?.length) next.references = e.references;
316
+ if (e.extra_data?.references?.length) next.references = e.extra_data.references;
317
+ if (e.citations) next.citations = e.citations;
318
+ const tools = toolsFromEvent(e);
319
+ if (tools.length) {
320
+ let toolCalls = message.tool_calls ?? [];
321
+ for (const tool of tools) toolCalls = mergeTool(toolCalls, tool);
322
+ next.tool_calls = toolCalls;
323
+ }
324
+ if (e.images?.length) next.images = e.images;
325
+ if (e.videos?.length) next.videos = e.videos;
326
+ if (e.audio?.length) next.audio = e.audio;
327
+ if (e.response_audio?.transcript) {
328
+ next.response_audio = {
329
+ ...message.response_audio,
330
+ transcript: (message.response_audio?.transcript ?? "") + e.response_audio.transcript
331
+ };
332
+ }
333
+ return next;
334
+ }
306
335
  function activityLabel(e) {
307
336
  const ev = name(e);
308
337
  switch (ev) {
@@ -491,7 +520,6 @@ function useAgnoChat(options) {
491
520
  const [sessionsLoading, setSessionsLoading] = useState(false);
492
521
  const abortRef = useRef(null);
493
522
  const activeMsgIdRef = useRef(null);
494
- const lastContentRef = useRef("");
495
523
  const runIdRef = useRef(void 0);
496
524
  const entityRef = useRef(entity);
497
525
  const sessionIdRef = useRef(options.sessionId);
@@ -544,37 +572,7 @@ function useAgnoChat(options) {
544
572
  return;
545
573
  }
546
574
  if (isContentEvent(e)) {
547
- patchActive((m) => {
548
- const next = { ...m };
549
- if (typeof e.content === "string" && e.content) {
550
- const unique = e.content.startsWith(lastContentRef.current) ? e.content.slice(lastContentRef.current.length) : e.content;
551
- next.content = (m.content ?? "") + unique;
552
- lastContentRef.current = e.content.length >= lastContentRef.current.length ? e.content : lastContentRef.current;
553
- } else if (e.content && typeof e.content === "object") {
554
- next.content = (m.content ?? "") + "\n```json\n" + JSON.stringify(e.content, null, 2) + "\n```\n";
555
- }
556
- if (e.reasoning_steps?.length) next.reasoning_steps = e.reasoning_steps;
557
- if (e.extra_data?.reasoning_steps?.length) next.reasoning_steps = e.extra_data.reasoning_steps;
558
- if (e.references?.length) next.references = e.references;
559
- if (e.extra_data?.references?.length) next.references = e.extra_data.references;
560
- if (e.citations) next.citations = e.citations;
561
- const tools = toolsFromEvent(e);
562
- if (tools.length) {
563
- let tc = m.tool_calls ?? [];
564
- for (const t of tools) tc = mergeTool(tc, t);
565
- next.tool_calls = tc;
566
- }
567
- if (e.images?.length) next.images = e.images;
568
- if (e.videos?.length) next.videos = e.videos;
569
- if (e.audio?.length) next.audio = e.audio;
570
- if (e.response_audio?.transcript) {
571
- next.response_audio = {
572
- ...m.response_audio,
573
- transcript: (m.response_audio?.transcript ?? "") + e.response_audio.transcript
574
- };
575
- }
576
- return next;
577
- });
575
+ patchActive((m) => applyContentEvent(m, e));
578
576
  return;
579
577
  }
580
578
  if (isReasoningStepEvent(e)) {
@@ -645,7 +643,6 @@ function useAgnoChat(options) {
645
643
  abortRef.current = controller;
646
644
  setError(null);
647
645
  setStatus("streaming");
648
- lastContentRef.current = "";
649
646
  await starter({
650
647
  signal: controller.signal,
651
648
  onEvent: applyEvent,
@@ -806,7 +803,6 @@ function useAgnoChat(options) {
806
803
  abortRef.current?.abort();
807
804
  activeMsgIdRef.current = null;
808
805
  runIdRef.current = void 0;
809
- lastContentRef.current = "";
810
806
  setEvents([]);
811
807
  setCurrentEvent(null);
812
808
  setStatus("idle");
@@ -844,7 +840,6 @@ function useAgnoChat(options) {
844
840
  abortRef.current = null;
845
841
  activeMsgIdRef.current = null;
846
842
  runIdRef.current = void 0;
847
- lastContentRef.current = "";
848
843
  sessionIdRef.current = void 0;
849
844
  setMessages([]);
850
845
  setEvents([]);