@inkeep/agents-ui 0.14.10 → 0.14.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.
@@ -1,3 +1,3 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("@ai-sdk/react"),V=require("ai"),t=require("react"),G=require("../../providers/config-provider.cjs"),X=require("../../hooks/use-media-query.cjs"),Y=require("../../utils/generate-uid.cjs"),Z=require("../../providers/base-events-provider.cjs"),ee=require("../../providers/chat-form-provider.cjs"),te=require("../../providers/widget-provider.cjs"),se=require("@radix-ui/react-use-controllable-state"),ne=()=>{const{baseSettings:m,aiChatSettings:o}=G.useInkeepConfig(),[n="",f]=se.useControllableState({prop:o.conversationId,defaultProp:o.conversationId??""}),{logEvent:i}=Z.useBaseEvents(),[a,u]=t.useState(""),_=e=>u(e.target.value),{filters:v}=m,{onInputMessageChange:k,filters:b,graphUrl:F,context:P,headers:x,apiKey:y}=o,N=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${m.organizationDisplayName??"Administrator"}`;default:return`Hmm..
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const G=require("@ai-sdk/react"),X=require("ai"),t=require("react"),Y=require("../../providers/config-provider.cjs"),Z=require("../../hooks/use-media-query.cjs"),ee=require("../../utils/generate-uid.cjs"),te=require("../../providers/base-events-provider.cjs"),se=require("../../providers/chat-form-provider.cjs"),ne=require("../../providers/widget-provider.cjs"),re=require("@radix-ui/react-use-controllable-state"),ae=require("../../hooks/use-streaming-events.cjs"),oe=()=>{const{baseSettings:h,aiChatSettings:o}=Y.useInkeepConfig(),[n="",f]=re.useControllableState({prop:o.conversationId,defaultProp:o.conversationId??""}),{logEvent:i}=te.useBaseEvents(),{setConversationId:_,emitStreamError:k}=ae.useStreamingEvents(),[a,u]=t.useState(""),F=e=>u(e.target.value),{filters:v}=h,{onInputMessageChange:P,filters:S,graphUrl:x,context:N,headers:D,apiKey:C}=o,A=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${h.organizationDisplayName??"Administrator"}`;default:return`Hmm..
2
2
 
3
- It seems I might be having some issues right now. Please clear the chat and try again.`}},[D,A]=t.useState({}),[B,l]=t.useState([]),[R,C]=t.useState(null),{messages:g,sendMessage:U,status:I,setMessages:S,stop:K,error:d}=L.useChat({transport:new V.DefaultChatTransport({api:F,headers:{...y?{Authorization:`Bearer ${y}`}:{},...x},body:{requestContext:P}}),async onFinish(e){await i({eventName:"assistant_message_received",properties:{conversationId:n}}),i({eventName:"assistant_answer_displayed",properties:{conversationId:n}})},onError(e){console.log("onError",e.message),S(c=>{const r=[...c],s=r[r.length-1];return s&&(s.parts=[{type:"text",text:N(e)}]),r})}}),w=I==="submitted",T=I==="streaming",W=g.length===0,p=!a.trim()||w,$=X.useMediaQuery("(max-width: 768px)"),[z,E]=t.useState(null);t.useEffect(()=>{d&&E(d)},[d]);const H=()=>E(null),M=t.useRef(null);t.useEffect(()=>{k?.(a)},[a]);const O=e=>{e.key==="Enter"&&!e.shiftKey&&!p&&!e.nativeEvent.isComposing&&(e.preventDefault(),h())},h=async(e=a)=>{if(p&&(!e||e.trim().length===0))return;l([]),u(""),await i({eventName:"user_message_submitted",properties:{conversationId:n}});const c=v||b?JSON.stringify({...v,...b}):void 0,r={};c&&(r["inkeep-filters"]=c);let s=n;s||(s=`conv_${Y.generateUid(16)}`,f(s)),U({text:e},{headers:r,body:{conversationId:s}})},Q=()=>{K()},q=()=>{H(),S([]),f(""),A({}),l([]),C(null),i({eventName:"chat_clear_button_clicked",properties:{conversationId:n}})},{openForm:j}=ee.useChatForm(),J=te.useWidget();return t.useImperativeHandle(o.chatFunctionsRef,()=>({submitMessage:h,updateInputMessage(e){u(e)},clearChat:q,openForm:e=>{J?.setView("chat"),j(e,void 0)},focusInput:()=>{M.current?.focus()}})),{messages:g,isLoading:w,isStreaming:T,error:z,isSubmitDisabled:p,input:a,handleInputChange:_,handleInputKeyDown:O,handleSubmit:h,stop:Q,clear:q,messageButtons:D,isEmpty:g.length===0,inputRef:M,isMobile:$,messageAttachments:B,setMessageAttachments:l,selectedWorkflow:R,setSelectedWorkflow:C,isNewChat:W,conversationId:n}};exports.useInkeepChat=ne;
3
+ It seems I might be having some issues right now. Please clear the chat and try again.`}},[B,R]=t.useState({}),[U,l]=t.useState([]),[K,I]=t.useState(null),{messages:g,sendMessage:T,status:b,setMessages:y,stop:W,error:d}=G.useChat({transport:new X.DefaultChatTransport({api:x,headers:{...C?{Authorization:`Bearer ${C}`}:{},...D},body:{requestContext:N}}),async onFinish(){await i({eventName:"assistant_message_received",properties:{conversationId:n}}),i({eventName:"assistant_answer_displayed",properties:{conversationId:n}})},onError(e){console.log("onError",e.message),k(e.message,void 0,e.code?.toString()),y(c=>{const r=[...c],s=r[r.length-1];return s&&(s.parts=[{type:"text",text:A(e)}]),r})}}),E=b==="submitted",$=b==="streaming",z=g.length===0,m=!a.trim()||E,H=Z.useMediaQuery("(max-width: 768px)"),[O,w]=t.useState(null);t.useEffect(()=>{d&&w(d)},[d]);const Q=()=>w(null),M=t.useRef(null);t.useEffect(()=>{P?.(a)},[a]);const j=e=>{e.key==="Enter"&&!e.shiftKey&&!m&&!e.nativeEvent.isComposing&&(e.preventDefault(),p())},p=async(e=a)=>{if(m&&(!e||e.trim().length===0))return;l([]),u(""),await i({eventName:"user_message_submitted",properties:{conversationId:n}});const c=v||S?JSON.stringify({...v,...S}):void 0,r={};c&&(r["inkeep-filters"]=c);let s=n;s||(s=`conv_${ee.generateUid(16)}`,f(s)),_(s),T({text:e},{headers:r,body:{conversationId:s}})},J=()=>{W()},q=()=>{Q(),y([]),f(""),R({}),l([]),I(null),i({eventName:"chat_clear_button_clicked",properties:{conversationId:n}})},{openForm:L}=se.useChatForm(),V=ne.useWidget();return t.useImperativeHandle(o.chatFunctionsRef,()=>({submitMessage:p,updateInputMessage(e){u(e)},clearChat:q,openForm:e=>{V?.setView("chat"),L(e,void 0)},focusInput:()=>{M.current?.focus()}})),{messages:g,isLoading:E,isStreaming:$,error:O,isSubmitDisabled:m,input:a,handleInputChange:F,handleInputKeyDown:j,handleSubmit:p,stop:J,clear:q,messageButtons:B,isEmpty:g.length===0,inputRef:M,isMobile:H,messageAttachments:U,setMessageAttachments:l,selectedWorkflow:K,setSelectedWorkflow:I,isNewChat:z,conversationId:n}};exports.useInkeepChat=oe;
@@ -1,29 +1,30 @@
1
1
  "use client";
2
- import { useChat as j } from "@ai-sdk/react";
3
- import { DefaultChatTransport as G } from "ai";
4
- import { useState as r, useEffect as x, useRef as X, useImperativeHandle as Y } from "react";
5
- import { useInkeepConfig as Z } from "../../providers/config-provider.js";
6
- import { useMediaQuery as ee } from "../../hooks/use-media-query.js";
7
- import { generateUid as te } from "../../utils/generate-uid.js";
8
- import { useBaseEvents as se } from "../../providers/base-events-provider.js";
9
- import { useChatForm as ne } from "../../providers/chat-form-provider.js";
10
- import { useWidget as oe } from "../../providers/widget-provider.js";
11
- import { useControllableState as re } from "@radix-ui/react-use-controllable-state";
12
- const fe = () => {
13
- const { baseSettings: h, aiChatSettings: a } = Z(), [s = "", f] = re({
2
+ import { useChat as X } from "@ai-sdk/react";
3
+ import { DefaultChatTransport as Y } from "ai";
4
+ import { useState as r, useEffect as x, useRef as Z, useImperativeHandle as ee } from "react";
5
+ import { useInkeepConfig as te } from "../../providers/config-provider.js";
6
+ import { useMediaQuery as se } from "../../hooks/use-media-query.js";
7
+ import { generateUid as ne } from "../../utils/generate-uid.js";
8
+ import { useBaseEvents as oe } from "../../providers/base-events-provider.js";
9
+ import { useChatForm as re } from "../../providers/chat-form-provider.js";
10
+ import { useWidget as ae } from "../../providers/widget-provider.js";
11
+ import { useControllableState as ie } from "@radix-ui/react-use-controllable-state";
12
+ import { useStreamingEvents as ce } from "../../hooks/use-streaming-events.js";
13
+ const be = () => {
14
+ const { baseSettings: h, aiChatSettings: a } = te(), [s = "", f] = ie({
14
15
  prop: a.conversationId,
15
16
  defaultProp: a.conversationId ?? ""
16
- }), { logEvent: i } = se(), [o, m] = r(""), k = (e) => m(e.target.value), {
17
+ }), { logEvent: i } = oe(), { setConversationId: k, emitStreamError: F } = ce(), [o, m] = r(""), N = (e) => m(e.target.value), {
17
18
  /* shouldBypassCaptcha, */
18
19
  filters: v
19
20
  } = h, {
20
- onInputMessageChange: F,
21
+ onInputMessageChange: D,
21
22
  filters: I,
22
- graphUrl: N,
23
- context: D,
24
- headers: A,
23
+ graphUrl: A,
24
+ context: B,
25
+ headers: K,
25
26
  apiKey: C
26
- } = a, B = (e) => {
27
+ } = a, P = (e) => {
27
28
  switch (e.code) {
28
29
  case 400:
29
30
  return e.message;
@@ -34,25 +35,25 @@ const fe = () => {
34
35
 
35
36
  It seems I might be having some issues right now. Please clear the chat and try again.`;
36
37
  }
37
- }, [K, P] = r({}), [R, u] = r([]), [W, b] = r(null), {
38
+ }, [R, W] = r({}), [$, u] = r([]), [z, b] = r(null), {
38
39
  messages: l,
39
- sendMessage: $,
40
+ sendMessage: H,
40
41
  status: y,
41
42
  setMessages: w,
42
- stop: z,
43
+ stop: T,
43
44
  error: p
44
- } = j({
45
- transport: new G({
46
- api: N,
45
+ } = X({
46
+ transport: new Y({
47
+ api: A,
47
48
  headers: {
48
49
  ...C ? { Authorization: `Bearer ${C}` } : {},
49
- ...A
50
+ ...K
50
51
  },
51
52
  body: {
52
- requestContext: D
53
+ requestContext: B
53
54
  }
54
55
  }),
55
- async onFinish(e) {
56
+ async onFinish() {
56
57
  await i({
57
58
  eventName: "assistant_message_received",
58
59
  properties: {
@@ -66,20 +67,20 @@ It seems I might be having some issues right now. Please clear the chat and try
66
67
  });
67
68
  },
68
69
  onError(e) {
69
- console.log("onError", e.message), w((c) => {
70
+ console.log("onError", e.message), F(e.message, void 0, e.code?.toString()), w((c) => {
70
71
  const n = [...c], t = n[n.length - 1];
71
- return t && (t.parts = [{ type: "text", text: B(e) }]), n;
72
+ return t && (t.parts = [{ type: "text", text: P(e) }]), n;
72
73
  });
73
74
  }
74
- }), E = y === "submitted", H = y === "streaming", T = l.length === 0, g = !o.trim() || E, U = ee("(max-width: 768px)"), [q, M] = r(null);
75
+ }), E = y === "submitted", U = y === "streaming", q = l.length === 0, g = !o.trim() || E, J = se("(max-width: 768px)"), [L, S] = r(null);
75
76
  x(() => {
76
- p && M(p);
77
+ p && S(p);
77
78
  }, [p]);
78
- const J = () => M(null), S = X(null);
79
+ const O = () => S(null), M = Z(null);
79
80
  x(() => {
80
- F?.(o);
81
+ D?.(o);
81
82
  }, [o]);
82
- const L = (e) => {
83
+ const Q = (e) => {
83
84
  e.key === "Enter" && !e.shiftKey && !g && !e.nativeEvent.isComposing && (e.preventDefault(), d());
84
85
  }, d = async (e = o) => {
85
86
  if (g && (!e || e.trim().length === 0)) return;
@@ -95,7 +96,7 @@ It seems I might be having some issues right now. Please clear the chat and try
95
96
  }) : void 0, n = {};
96
97
  c && (n["inkeep-filters"] = c);
97
98
  let t = s;
98
- t || (t = `conv_${te(16)}`, f(t)), $(
99
+ t || (t = `conv_${ne(16)}`, f(t)), k(t), H(
99
100
  // { ...userMessage, files },
100
101
  // { ...userMessage, },
101
102
  {
@@ -108,53 +109,53 @@ It seems I might be having some issues right now. Please clear the chat and try
108
109
  }
109
110
  }
110
111
  );
111
- }, O = () => {
112
- z();
112
+ }, V = () => {
113
+ T();
113
114
  }, _ = () => {
114
- J(), w([]), f(""), P({}), u([]), b(null), i({
115
+ O(), w([]), f(""), W({}), u([]), b(null), i({
115
116
  eventName: "chat_clear_button_clicked",
116
117
  properties: {
117
118
  conversationId: s
118
119
  }
119
120
  });
120
- }, { openForm: Q } = ne(), V = oe();
121
- return Y(a.chatFunctionsRef, () => ({
121
+ }, { openForm: j } = re(), G = ae();
122
+ return ee(a.chatFunctionsRef, () => ({
122
123
  submitMessage: d,
123
124
  updateInputMessage(e) {
124
125
  m(e);
125
126
  },
126
127
  clearChat: _,
127
128
  openForm: (e) => {
128
- V?.setView("chat"), Q(e, void 0);
129
+ G?.setView("chat"), j(e, void 0);
129
130
  },
130
131
  focusInput: () => {
131
- S.current?.focus();
132
+ M.current?.focus();
132
133
  }
133
134
  })), {
134
135
  messages: l,
135
136
  isLoading: E,
136
- isStreaming: H,
137
- error: q,
137
+ isStreaming: U,
138
+ error: L,
138
139
  isSubmitDisabled: g,
139
140
  input: o,
140
- handleInputChange: k,
141
- handleInputKeyDown: L,
141
+ handleInputChange: N,
142
+ handleInputKeyDown: Q,
142
143
  handleSubmit: d,
143
- stop: O,
144
+ stop: V,
144
145
  clear: _,
145
- messageButtons: K,
146
+ messageButtons: R,
146
147
  isEmpty: l.length === 0,
147
- inputRef: S,
148
- isMobile: U,
148
+ inputRef: M,
149
+ isMobile: J,
149
150
  // Additional state for attachments and workflow
150
- messageAttachments: R,
151
+ messageAttachments: $,
151
152
  setMessageAttachments: u,
152
- selectedWorkflow: W,
153
+ selectedWorkflow: z,
153
154
  setSelectedWorkflow: b,
154
- isNewChat: T,
155
+ isNewChat: q,
155
156
  conversationId: s
156
157
  };
157
158
  };
158
159
  export {
159
- fe as useInkeepChat
160
+ be as useInkeepChat
160
161
  };
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),A=require("../../../types/message.cjs");function D(a,f){const[i,x]=n.useState([]),[h,w]=n.useState(new Map),[y,P]=n.useState(Date.now()),[R,p]=n.useState(!1),g=n.useRef(0),d=n.useRef(0),S=n.useRef([]),c=n.useRef(h);c.current=h;const C=n.useCallback(()=>{const s=[];let e="",o=[];a.length>g.current&&(P(Date.now()),g.current=a.length),d.current=0;const u=new Map,l=(t=!1)=>{if(o.length>0){const r=`group-${d.current++}`,m=c.current.get(r);m?u.set(r,{...m,isCompleted:t}):u.set(r,{isCompleted:t}),s.push({type:"summary-group",summaries:[...o],groupKey:r}),o=[]}};for(const t of a)if(t.type==="text")l(!0),e+=t.text||"";else if(t.type==="data-summary")e.trim()&&(s.push({type:"text",text:e}),e=""),o.push(t.data);else if(t.type==="data-operation")t.data.type==="completion"&&l(!0);else if(t.type==="data-artifact")if(t.data?.type?.toLowerCase()===A.CITATION_ARTIFACT_TYPE){const r=t.data,m=r.artifactSummary||{title:r.name};e+=` ^${m?.title||r.name}^`}else e.trim()&&(s.push({type:"text",text:e}),e=""),s.push(t);else t.type==="data-component"&&(e.trim()&&(s.push({type:"text",text:e}),e=""),s.push(t));return l(!f),e.trim()&&s.push({type:"text",text:e}),{processed:s,newTimings:u}},[a,f]);n.useEffect(()=>{if(S.current===a)return;S.current=a;const{processed:s,newTimings:e}=C();x(s),(e.size!==c.current.size||Array.from(e.entries()).some(([u,l])=>{const t=c.current.get(u);return!t||t.isCompleted!==l.isCompleted}))&&w(e)},[C,a]);const T=n.useCallback(()=>{const s=Date.now()-y,e=Array.from(c.current.values()).some(u=>!u.isCompleted),o=s>1e3&&!e;p(o)},[y]);n.useEffect(()=>{if(!f){p(!1);return}if(!(i.length>0)){p(!1);return}const e=setInterval(T,200);return()=>clearInterval(e)},[f,T,i.length]);const v=n.useMemo(()=>!(i.length>0),[i.length]);return{processedParts:i,summaryTimings:h,shouldShowInitialLoading:v,shouldShowStreamDelayLoading:R}}exports.useStreamProcessor=D;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),b=require("../../../types/message.cjs"),L=require("../../hooks/use-streaming-events.cjs");function E(r,c){const[u,A]=a.useState([]),[p,D]=a.useState(new Map),[d,P]=a.useState(Date.now()),[R,g]=a.useState(!1),h=a.useRef(0),y=a.useRef(0),w=a.useRef([]),l=a.useRef(p);l.current=p;const{emitArtifactSaved:S,emitCompletion:x,emitAgentInitializing:k,emitTextDelta:C}=L.useStreamingEvents(),T=a.useCallback(()=>{const n=[];let e="",o=[];r.length>h.current&&(P(Date.now()),h.current=r.length),y.current=0;const i=new Map,m=(t=!1)=>{if(o.length>0){const s=`group-${y.current++}`,f=l.current.get(s);f?i.set(s,{...f,isCompleted:t}):i.set(s,{isCompleted:t}),n.push({type:"summary-group",summaries:[...o],groupKey:s}),o=[]}};for(const t of r)if(t.type==="text")m(!0),t.text&&c&&C(t.text),e+=t.text||"";else if(t.type==="data-summary")e.trim()&&(n.push({type:"text",text:e}),e=""),o.push(t.data);else if(t.type==="data-operation"){const s=t.data;if(s?.type)switch(s.type){case"completion":x("unknown",1),m(!0);break;case"agent_initializing":k("unknown","unknown");break;case"error":console.warn("Data operation error:",s.ctx);break;case"agent_thinking":case"agent_ready":console.log("Agent state:",s.type,s.ctx);break}}else if(t.type==="data-artifact")if(t.data?.type?.toLowerCase()===b.CITATION_ARTIFACT_TYPE){const s=t.data,f=s.artifactSummary||{title:s.name};e+=` ^${f?.title||s.name}^`}else e.trim()&&(n.push({type:"text",text:e}),e=""),n.push(t),t.data&&S(t.data.artifactId||"unknown",t.data.taskId||"unknown","unknown",t.data.artifactType||"unknown",t.data.artifactSummary||{},{},{name:t.data.name,description:t.data.description});else t.type==="data-component"&&(e.trim()&&(n.push({type:"text",text:e}),e=""),n.push(t));return m(!c),e.trim()&&n.push({type:"text",text:e}),{processed:n,newTimings:i}},[r,c,S,x,k,C]);a.useEffect(()=>{if(w.current===r)return;w.current=r;const{processed:n,newTimings:e}=T();A(n),(e.size!==l.current.size||Array.from(e.entries()).some(([i,m])=>{const t=l.current.get(i);return!t||t.isCompleted!==m.isCompleted}))&&D(e)},[T,r]);const v=a.useCallback(()=>{const n=Date.now()-d,e=Array.from(l.current.values()).some(i=>!i.isCompleted),o=n>1e3&&!e;g(o)},[d]);a.useEffect(()=>{if(!c){g(!1);return}if(!(u.length>0)){g(!1);return}const e=setInterval(v,200);return()=>clearInterval(e)},[c,v,u.length]);const I=a.useMemo(()=>!(u.length>0),[u.length]);return{processedParts:u,summaryTimings:p,shouldShowInitialLoading:I,shouldShowStreamDelayLoading:R}}exports.useStreamProcessor=E;
@@ -1,82 +1,121 @@
1
1
  "use client";
2
- import { useState as f, useRef as p, useCallback as S, useEffect as A, useMemo as R } from "react";
3
- import { CITATION_ARTIFACT_TYPE as k } from "../../../types/message.js";
4
- function E(r, m) {
5
- const [i, v] = f([]), [h, P] = f(/* @__PURE__ */ new Map()), [g, D] = f(Date.now()), [L, y] = f(!1), d = p(0), x = p(0), C = p([]), c = p(h);
6
- c.current = h;
7
- const T = S(() => {
8
- const s = [];
9
- let t = "", o = [];
10
- r.length > d.current && (D(Date.now()), d.current = r.length), x.current = 0;
11
- const a = /* @__PURE__ */ new Map(), u = (e = !1) => {
12
- if (o.length > 0) {
13
- const n = `group-${x.current++}`, l = c.current.get(n);
14
- l ? a.set(n, {
2
+ import { useState as f, useRef as p, useCallback as D, useEffect as I, useMemo as z } from "react";
3
+ import { CITATION_ARTIFACT_TYPE as E } from "../../../types/message.js";
4
+ import { useStreamingEvents as M } from "../../hooks/use-streaming-events.js";
5
+ function $(r, i) {
6
+ const [c, P] = f([]), [d, L] = f(/* @__PURE__ */ new Map()), [g, R] = f(Date.now()), [b, h] = f(!1), y = p(0), w = p(0), x = p([]), u = p(d);
7
+ u.current = d;
8
+ const { emitArtifactSaved: k, emitCompletion: C, emitAgentInitializing: T, emitTextDelta: S } = M(), A = D(() => {
9
+ const n = [];
10
+ let e = "", s = [];
11
+ r.length > y.current && (R(Date.now()), y.current = r.length), w.current = 0;
12
+ const o = /* @__PURE__ */ new Map(), m = (t = !1) => {
13
+ if (s.length > 0) {
14
+ const a = `group-${w.current++}`, l = u.current.get(a);
15
+ l ? o.set(a, {
15
16
  ...l,
16
- isCompleted: e
17
- }) : a.set(n, {
18
- isCompleted: e
19
- }), s.push({
17
+ isCompleted: t
18
+ }) : o.set(a, {
19
+ isCompleted: t
20
+ }), n.push({
20
21
  type: "summary-group",
21
- summaries: [...o],
22
- groupKey: n
23
- }), o = [];
22
+ summaries: [...s],
23
+ groupKey: a
24
+ }), s = [];
24
25
  }
25
26
  };
26
- for (const e of r)
27
- if (e.type === "text")
28
- u(!0), t += e.text || "";
29
- else if (e.type === "data-summary")
30
- t.trim() && (s.push({ type: "text", text: t }), t = ""), o.push(e.data);
31
- else if (e.type === "data-operation")
32
- e.data.type === "completion" && u(!0);
33
- else if (e.type === "data-artifact")
34
- if (e.data?.type?.toLowerCase() === k) {
35
- const n = e.data, l = n.artifactSummary || {
36
- title: n.name
27
+ for (const t of r)
28
+ if (t.type === "text")
29
+ m(!0), t.text && i && S(t.text), e += t.text || "";
30
+ else if (t.type === "data-summary")
31
+ e.trim() && (n.push({ type: "text", text: e }), e = ""), s.push(t.data);
32
+ else if (t.type === "data-operation") {
33
+ const a = t.data;
34
+ if (a?.type)
35
+ switch (a.type) {
36
+ case "completion":
37
+ C(
38
+ "unknown",
39
+ // No agent ID available in current structure
40
+ 1
41
+ // No iteration available in current structure
42
+ ), m(!0);
43
+ break;
44
+ case "agent_initializing":
45
+ T(
46
+ "unknown",
47
+ // No session ID available in current structure
48
+ "unknown"
49
+ // No graph ID available in current structure
50
+ );
51
+ break;
52
+ case "error":
53
+ console.warn("Data operation error:", a.ctx);
54
+ break;
55
+ case "agent_thinking":
56
+ case "agent_ready":
57
+ console.log("Agent state:", a.type, a.ctx);
58
+ break;
59
+ }
60
+ } else if (t.type === "data-artifact")
61
+ if (t.data?.type?.toLowerCase() === E) {
62
+ const a = t.data, l = a.artifactSummary || {
63
+ title: a.name
37
64
  };
38
- t += ` ^${l?.title || n.name}^`;
65
+ e += ` ^${l?.title || a.name}^`;
39
66
  } else
40
- t.trim() && (s.push({ type: "text", text: t }), t = ""), s.push(e);
41
- else e.type === "data-component" && (t.trim() && (s.push({ type: "text", text: t }), t = ""), s.push(e));
42
- return u(!m), t.trim() && s.push({ type: "text", text: t }), { processed: s, newTimings: a };
43
- }, [r, m]);
44
- A(() => {
45
- if (C.current === r)
67
+ e.trim() && (n.push({ type: "text", text: e }), e = ""), n.push(t), t.data && k(
68
+ t.data.artifactId || "unknown",
69
+ t.data.taskId || "unknown",
70
+ "unknown",
71
+ // toolCallId not available in current structure
72
+ t.data.artifactType || "unknown",
73
+ t.data.artifactSummary || {},
74
+ // Use artifactSummary as summaryData
75
+ {},
76
+ // fullData not available in current structure
77
+ { name: t.data.name, description: t.data.description }
78
+ // Use available fields as metadata
79
+ );
80
+ else t.type === "data-component" && (e.trim() && (n.push({ type: "text", text: e }), e = ""), n.push(t));
81
+ return m(!i), e.trim() && n.push({ type: "text", text: e }), { processed: n, newTimings: o };
82
+ }, [r, i, k, C, T, S]);
83
+ I(() => {
84
+ if (x.current === r)
46
85
  return;
47
- C.current = r;
48
- const { processed: s, newTimings: t } = T();
49
- v(s), (t.size !== c.current.size || Array.from(t.entries()).some(([a, u]) => {
50
- const e = c.current.get(a);
51
- return !e || e.isCompleted !== u.isCompleted;
52
- })) && P(t);
53
- }, [T, r]);
54
- const w = S(() => {
55
- const s = Date.now() - g, t = Array.from(c.current.values()).some(
56
- (a) => !a.isCompleted
57
- ), o = s > 1e3 && !t;
58
- y(o);
86
+ x.current = r;
87
+ const { processed: n, newTimings: e } = A();
88
+ P(n), (e.size !== u.current.size || Array.from(e.entries()).some(([o, m]) => {
89
+ const t = u.current.get(o);
90
+ return !t || t.isCompleted !== m.isCompleted;
91
+ })) && L(e);
92
+ }, [A, r]);
93
+ const v = D(() => {
94
+ const n = Date.now() - g, e = Array.from(u.current.values()).some(
95
+ (o) => !o.isCompleted
96
+ ), s = n > 1e3 && !e;
97
+ h(s);
59
98
  }, [g]);
60
- A(() => {
61
- if (!m) {
62
- y(!1);
99
+ I(() => {
100
+ if (!i) {
101
+ h(!1);
63
102
  return;
64
103
  }
65
- if (!(i.length > 0)) {
66
- y(!1);
104
+ if (!(c.length > 0)) {
105
+ h(!1);
67
106
  return;
68
107
  }
69
- const t = setInterval(w, 200);
70
- return () => clearInterval(t);
71
- }, [m, w, i.length]);
72
- const I = R(() => !(i.length > 0), [i.length]);
108
+ const e = setInterval(v, 200);
109
+ return () => clearInterval(e);
110
+ }, [i, v, c.length]);
111
+ const _ = z(() => !(c.length > 0), [c.length]);
73
112
  return {
74
- processedParts: i,
75
- summaryTimings: h,
76
- shouldShowInitialLoading: I,
77
- shouldShowStreamDelayLoading: L
113
+ processedParts: c,
114
+ summaryTimings: d,
115
+ shouldShowInitialLoading: _,
116
+ shouldShowStreamDelayLoading: b
78
117
  };
79
118
  }
80
119
  export {
81
- E as useStreamProcessor
120
+ $ as useStreamProcessor
82
121
  };
@@ -0,0 +1 @@
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),p=require("../atoms/shadow/context.cjs");function x(){const c=p.useShadow()?.shadowHost,r=s.useRef(""),t=s.useCallback(e=>{if(!c){console.warn("useStreamingEvents: No host element available for event emission");return}const n={...e,conversationId:r.current,timestamp:Date.now()},a=new CustomEvent("streaming-event",{detail:n,bubbles:!0,composed:!0});c.dispatchEvent(a)},[c]),d=s.useCallback(e=>{r.current=e},[]),u=s.useCallback(e=>{t({kind:"text:delta",data:{text:e}})},[t]),m=s.useCallback((e,n,a)=>{t({kind:"stream:error",data:{message:e,agent:n,severity:"error",code:a}})},[t]),k=s.useCallback((e,n)=>{t({kind:"agent:reasoning",data:{agentId:e,parts:n}})},[t]),g=s.useCallback((e,n,a)=>{t({kind:"agent:generate",data:{agentId:e,parts:n,generationType:a}})},[t]),b=s.useCallback((e,n,a,o,i,l)=>{t({kind:"tool:execution",data:{agentId:e,toolName:n,args:a,result:o,toolId:i,duration:l}})},[t]),v=s.useCallback((e,n,a,o)=>{t({kind:"agent:transfer",data:{fromAgent:e,targetAgent:n,reason:a,context:o}})},[t]),C=s.useCallback((e,n,a,o,i)=>{t({kind:"delegation:sent",data:{delegationId:e,fromAgent:n,targetAgent:a,taskDescription:o,context:i}})},[t]),f=s.useCallback((e,n,a,o)=>{t({kind:"delegation:returned",data:{delegationId:e,fromAgent:n,targetAgent:a,result:o}})},[t]),E=s.useCallback((e,n,a,o,i,l,w)=>{t({kind:"artifact:saved",data:{artifactId:e,taskId:n,toolCallId:a,artifactType:o,summaryData:i,fullData:l,metadata:w}})},[t]),S=s.useCallback((e,n)=>{t({kind:"completion",data:{agent:e,iteration:n}})},[t]),h=s.useCallback((e,n)=>{t({kind:"agent:initializing",data:{sessionId:e,graphId:n}})},[t]);return{emitEvent:t,setConversationId:d,emitTextDelta:u,emitStreamError:m,emitAgentReasoning:k,emitAgentGenerate:g,emitToolExecution:b,emitAgentTransfer:v,emitDelegationSent:C,emitDelegationReturned:f,emitArtifactSaved:E,emitCompletion:S,emitAgentInitializing:h}}exports.useStreamingEvents=x;
@@ -0,0 +1,140 @@
1
+ "use client";
2
+ import { useRef as x, useCallback as o } from "react";
3
+ import { useShadow as A } from "../atoms/shadow/context.js";
4
+ function R() {
5
+ const r = A()?.shadowHost, c = x(""), e = o(
6
+ (t) => {
7
+ if (!r) {
8
+ console.warn("useStreamingEvents: No host element available for event emission");
9
+ return;
10
+ }
11
+ const n = {
12
+ ...t,
13
+ conversationId: c.current,
14
+ timestamp: Date.now()
15
+ }, a = new CustomEvent("streaming-event", {
16
+ detail: n,
17
+ bubbles: !0,
18
+ // Allow event to bubble up
19
+ composed: !0
20
+ // Allow event to escape Shadow DOM boundary
21
+ });
22
+ r.dispatchEvent(a);
23
+ },
24
+ [r]
25
+ ), m = o((t) => {
26
+ c.current = t;
27
+ }, []), l = o(
28
+ (t) => {
29
+ e({
30
+ kind: "text:delta",
31
+ data: { text: t }
32
+ });
33
+ },
34
+ [e]
35
+ ), u = o(
36
+ (t, n, a) => {
37
+ e({
38
+ kind: "stream:error",
39
+ data: {
40
+ message: t,
41
+ agent: n,
42
+ severity: "error",
43
+ code: a
44
+ }
45
+ });
46
+ },
47
+ [e]
48
+ ), g = o(
49
+ (t, n) => {
50
+ e({
51
+ kind: "agent:reasoning",
52
+ data: { agentId: t, parts: n }
53
+ });
54
+ },
55
+ [e]
56
+ ), v = o(
57
+ (t, n, a) => {
58
+ e({
59
+ kind: "agent:generate",
60
+ data: { agentId: t, parts: n, generationType: a }
61
+ });
62
+ },
63
+ [e]
64
+ ), f = o(
65
+ (t, n, a, i, s, d) => {
66
+ e({
67
+ kind: "tool:execution",
68
+ data: { agentId: t, toolName: n, args: a, result: i, toolId: s, duration: d }
69
+ });
70
+ },
71
+ [e]
72
+ ), k = o(
73
+ (t, n, a, i) => {
74
+ e({
75
+ kind: "agent:transfer",
76
+ data: { fromAgent: t, targetAgent: n, reason: a, context: i }
77
+ });
78
+ },
79
+ [e]
80
+ ), E = o(
81
+ (t, n, a, i, s) => {
82
+ e({
83
+ kind: "delegation:sent",
84
+ data: { delegationId: t, fromAgent: n, targetAgent: a, taskDescription: i, context: s }
85
+ });
86
+ },
87
+ [e]
88
+ ), p = o(
89
+ (t, n, a, i) => {
90
+ e({
91
+ kind: "delegation:returned",
92
+ data: { delegationId: t, fromAgent: n, targetAgent: a, result: i }
93
+ });
94
+ },
95
+ [e]
96
+ ), h = o(
97
+ (t, n, a, i, s, d, b) => {
98
+ e({
99
+ kind: "artifact:saved",
100
+ data: { artifactId: t, taskId: n, toolCallId: a, artifactType: i, summaryData: s, fullData: d, metadata: b }
101
+ });
102
+ },
103
+ [e]
104
+ ), w = o(
105
+ (t, n) => {
106
+ e({
107
+ kind: "completion",
108
+ data: { agent: t, iteration: n }
109
+ });
110
+ },
111
+ [e]
112
+ ), S = o(
113
+ (t, n) => {
114
+ e({
115
+ kind: "agent:initializing",
116
+ data: { sessionId: t, graphId: n }
117
+ });
118
+ },
119
+ [e]
120
+ );
121
+ return {
122
+ emitEvent: e,
123
+ setConversationId: m,
124
+ // Convenience methods
125
+ emitTextDelta: l,
126
+ emitStreamError: u,
127
+ emitAgentReasoning: g,
128
+ emitAgentGenerate: v,
129
+ emitToolExecution: f,
130
+ emitAgentTransfer: k,
131
+ emitDelegationSent: E,
132
+ emitDelegationReturned: p,
133
+ emitArtifactSaved: h,
134
+ emitCompletion: w,
135
+ emitAgentInitializing: S
136
+ };
137
+ }
138
+ export {
139
+ R as useStreamingEvents
140
+ };
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react/jsx-runtime"),t=require("react"),l=require("./config-provider.cjs"),a=t.createContext(void 0),p=({children:e})=>{const{baseSettings:s,componentType:n}=l.useInkeepConfig(),{tags:o,analyticsProperties:r}=s,i=t.useMemo(()=>({widgetLibraryVersion:"0.14.9",componentType:n,tags:o}),[n,o]),u={logEvent:t.useCallback(async c=>{const v={...i,...c.properties,...r},d={eventName:c.eventName,properties:v};return s.onEvent?.(d)},[s,i,r])};return E.jsx(a.Provider,{value:u,children:e})},g=()=>{const e=t.useContext(a);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=p;exports.useBaseEvents=g;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react/jsx-runtime"),t=require("react"),l=require("./config-provider.cjs"),a=t.createContext(void 0),p=({children:e})=>{const{baseSettings:s,componentType:n}=l.useInkeepConfig(),{tags:o,analyticsProperties:r}=s,i=t.useMemo(()=>({widgetLibraryVersion:"0.14.10",componentType:n,tags:o}),[n,o]),u={logEvent:t.useCallback(async c=>{const v={...i,...c.properties,...r},d={eventName:c.eventName,properties:v};return s.onEvent?.(d)},[s,i,r])};return E.jsx(a.Provider,{value:u,children:e})},g=()=>{const e=t.useContext(a);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=p;exports.useBaseEvents=g;
@@ -5,7 +5,7 @@ import { useInkeepConfig as g } from "./config-provider.js";
5
5
  const a = d(void 0), P = ({ children: e }) => {
6
6
  const { baseSettings: t, componentType: o } = g(), { tags: s, analyticsProperties: n } = t, r = u(
7
7
  () => ({
8
- widgetLibraryVersion: "0.14.9",
8
+ widgetLibraryVersion: "0.14.10",
9
9
  componentType: o,
10
10
  tags: s
11
11
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-ui",
3
- "version": "0.14.10",
3
+ "version": "0.14.11",
4
4
  "description": "",
5
5
  "homepage": "",
6
6
  "repository": {