@inkeep/agents-ui 0.14.10 → 0.14.12

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.d.cts CHANGED
@@ -1225,8 +1225,20 @@ export declare const dataAttr: (guard: boolean | undefined) => Booleanish;
1225
1225
 
1226
1226
  declare type DataParts = {
1227
1227
  operation: {
1228
- type: 'error' | 'agent_thinking' | 'agent_ready' | 'agent_initializing' | 'completion'
1228
+ type:
1229
+ | 'error'
1230
+ | 'agent_initializing'
1231
+ | 'completion'
1232
+ | 'agent_generate'
1233
+ | 'agent_reasoning'
1234
+ | 'tool_execution'
1235
+ | 'transfer'
1236
+ | 'delegation_sent'
1237
+ | 'delegation_returned'
1238
+ | 'artifact_saved'
1229
1239
  ctx: Record<string, unknown>
1240
+ message?: string
1241
+ label?: string
1230
1242
  }
1231
1243
  summary: {
1232
1244
  type: string
@@ -4908,6 +4920,7 @@ declare const useInkeepChat: () => {
4908
4920
  isLoading: boolean;
4909
4921
  isStreaming: boolean;
4910
4922
  error: Error | null;
4923
+ setError: Dispatch<SetStateAction<Error | null>>;
4911
4924
  isSubmitDisabled: boolean;
4912
4925
  input: string;
4913
4926
  handleInputChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
package/dist/index.d.ts CHANGED
@@ -1225,8 +1225,20 @@ export declare const dataAttr: (guard: boolean | undefined) => Booleanish;
1225
1225
 
1226
1226
  declare type DataParts = {
1227
1227
  operation: {
1228
- type: 'error' | 'agent_thinking' | 'agent_ready' | 'agent_initializing' | 'completion'
1228
+ type:
1229
+ | 'error'
1230
+ | 'agent_initializing'
1231
+ | 'completion'
1232
+ | 'agent_generate'
1233
+ | 'agent_reasoning'
1234
+ | 'tool_execution'
1235
+ | 'transfer'
1236
+ | 'delegation_sent'
1237
+ | 'delegation_returned'
1238
+ | 'artifact_saved'
1229
1239
  ctx: Record<string, unknown>
1240
+ message?: string
1241
+ label?: string
1230
1242
  }
1231
1243
  summary: {
1232
1244
  type: string
@@ -4908,6 +4920,7 @@ declare const useInkeepChat: () => {
4908
4920
  isLoading: boolean;
4909
4921
  isStreaming: boolean;
4910
4922
  error: Error | null;
4923
+ setError: Dispatch<SetStateAction<Error | null>>;
4911
4924
  isSubmitDisabled: boolean;
4912
4925
  input: string;
4913
4926
  handleInputChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
@@ -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 X=require("@ai-sdk/react"),Y=require("ai"),t=require("react"),Z=require("../../providers/config-provider.cjs"),ee=require("../../hooks/use-media-query.cjs"),te=require("../../utils/generate-uid.cjs"),se=require("../../providers/base-events-provider.cjs"),ne=require("../../providers/chat-form-provider.cjs"),re=require("../../providers/widget-provider.cjs"),ae=require("@radix-ui/react-use-controllable-state"),oe=require("../../hooks/use-streaming-events.cjs"),q=`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.`,ie=()=>{const{baseSettings:f,aiChatSettings:o}=Z.useInkeepConfig(),[n="",v]=ae.useControllableState({prop:o.conversationId,defaultProp:o.conversationId??""}),{logEvent:i}=se.useBaseEvents(),{setConversationId:F,emitStreamError:R}=oe.useStreamingEvents(),[a,u]=t.useState(""),k=e=>u(e.target.value),{filters:S}=f,{onInputMessageChange:A,filters:E,agentUrl:P,context:x,headers:D,apiKey:C}=o,N=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${f.organizationDisplayName??"Administrator"}`;default:return q}},[U,T]=t.useState({}),[B,l]=t.useState([]),[O,I]=t.useState(null),{messages:g,sendMessage:K,status:b,setMessages:y,stop:L,error:d}=X.useChat({transport:new Y.DefaultChatTransport({api:P,headers:{...C?{Authorization:`Bearer ${C}`}:{},...D},body:{requestContext:x}}),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),R(e.message,void 0,e.code?.toString()),y(c=>{const r=[...c],s=r[r.length-1];return s&&(s.parts=[{type:"text",text:N(e)}]),r})}}),w=b==="submitted",W=b==="streaming",$=g.length===0,m=!a.trim()||w,z=ee.useMediaQuery("(max-width: 768px)"),[G,p]=t.useState(null);t.useEffect(()=>{d&&p(d)},[d]);const H=()=>p(null),M=t.useRef(null);t.useEffect(()=>{A?.(a)},[a]);const Q=e=>{e.key==="Enter"&&!e.shiftKey&&!m&&!e.nativeEvent.isComposing&&(e.preventDefault(),h())},h=async(e=a)=>{if(m&&(!e||e.trim().length===0))return;l([]),u(""),await i({eventName:"user_message_submitted",properties:{conversationId:n}});const c=S||E?JSON.stringify({...S,...E}):void 0,r={};c&&(r["inkeep-filters"]=c);let s=n;s||(s=`conv_${te.generateUid(16)}`,v(s)),F(s),K({text:e},{headers:r,body:{conversationId:s}})},j=()=>{L()},_=()=>{H(),y([]),v(""),T({}),l([]),I(null),i({eventName:"chat_clear_button_clicked",properties:{conversationId:n}})},{openForm:J}=ne.useChatForm(),V=re.useWidget();return t.useImperativeHandle(o.chatFunctionsRef,()=>({submitMessage:h,updateInputMessage(e){u(e)},clearChat:_,openForm:e=>{V?.setView("chat"),J(e,void 0)},focusInput:()=>{M.current?.focus()}})),{messages:g,isLoading:w,isStreaming:W,error:G,setError:p,isSubmitDisabled:m,input:a,handleInputChange:k,handleInputKeyDown:Q,handleSubmit:h,stop:j,clear:_,messageButtons:U,isEmpty:g.length===0,inputRef:M,isMobile:z,messageAttachments:B,setMessageAttachments:l,selectedWorkflow:O,setSelectedWorkflow:I,isNewChat:$,conversationId:n}};exports.DEFAULT_ERROR_MESSAGE=q;exports.useInkeepChat=ie;
@@ -1,58 +1,59 @@
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 me = `Hmm..
14
+
15
+ It seems I might be having some issues right now. Please clear the chat and try again.`, Se = () => {
16
+ const { baseSettings: f, aiChatSettings: a } = te(), [s = "", v] = ie({
14
17
  prop: a.conversationId,
15
18
  defaultProp: a.conversationId ?? ""
16
- }), { logEvent: i } = se(), [o, m] = r(""), k = (e) => m(e.target.value), {
19
+ }), { logEvent: i } = oe(), { setConversationId: F, emitStreamError: k } = ce(), [o, m] = r(""), N = (e) => m(e.target.value), {
17
20
  /* shouldBypassCaptcha, */
18
- filters: v
19
- } = h, {
20
- onInputMessageChange: F,
21
- filters: I,
22
- graphUrl: N,
23
- context: D,
24
- headers: A,
25
- apiKey: C
26
- } = a, B = (e) => {
21
+ filters: I
22
+ } = f, {
23
+ onInputMessageChange: A,
24
+ filters: C,
25
+ agentUrl: D,
26
+ context: R,
27
+ headers: B,
28
+ apiKey: E
29
+ } = a, K = (e) => {
27
30
  switch (e.code) {
28
31
  case 400:
29
32
  return e.message;
30
33
  case 403:
31
- return `There seems to be a configuration error. Please contact ${h.organizationDisplayName ?? "Administrator"}`;
34
+ return `There seems to be a configuration error. Please contact ${f.organizationDisplayName ?? "Administrator"}`;
32
35
  default:
33
- return `Hmm..
34
-
35
- It seems I might be having some issues right now. Please clear the chat and try again.`;
36
+ return me;
36
37
  }
37
- }, [K, P] = r({}), [R, u] = r([]), [W, b] = r(null), {
38
+ }, [P, T] = r({}), [U, u] = r([]), [W, S] = r(null), {
38
39
  messages: l,
39
40
  sendMessage: $,
40
- status: y,
41
- setMessages: w,
41
+ status: b,
42
+ setMessages: y,
42
43
  stop: z,
43
44
  error: p
44
- } = j({
45
- transport: new G({
46
- api: N,
45
+ } = X({
46
+ transport: new Y({
47
+ api: D,
47
48
  headers: {
48
- ...C ? { Authorization: `Bearer ${C}` } : {},
49
- ...A
49
+ ...E ? { Authorization: `Bearer ${E}` } : {},
50
+ ...B
50
51
  },
51
52
  body: {
52
- requestContext: D
53
+ requestContext: R
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,22 +67,22 @@ 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), k(e.message, void 0, e.code?.toString()), y((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: K(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
+ }), w = b === "submitted", H = b === "streaming", L = l.length === 0, g = !o.trim() || w, O = se("(max-width: 768px)"), [q, d] = r(null);
75
76
  x(() => {
76
- p && M(p);
77
+ p && d(p);
77
78
  }, [p]);
78
- const J = () => M(null), S = X(null);
79
+ const G = () => d(null), M = Z(null);
79
80
  x(() => {
80
- F?.(o);
81
+ A?.(o);
81
82
  }, [o]);
82
- const L = (e) => {
83
- e.key === "Enter" && !e.shiftKey && !g && !e.nativeEvent.isComposing && (e.preventDefault(), d());
84
- }, d = async (e = o) => {
83
+ const J = (e) => {
84
+ e.key === "Enter" && !e.shiftKey && !g && !e.nativeEvent.isComposing && (e.preventDefault(), h());
85
+ }, h = async (e = o) => {
85
86
  if (g && (!e || e.trim().length === 0)) return;
86
87
  u([]), m(""), await i({
87
88
  eventName: "user_message_submitted",
@@ -89,13 +90,13 @@ It seems I might be having some issues right now. Please clear the chat and try
89
90
  conversationId: s
90
91
  }
91
92
  });
92
- const c = v || I ? JSON.stringify({
93
- ...v,
94
- ...I
93
+ const c = I || C ? JSON.stringify({
94
+ ...I,
95
+ ...C
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)}`, v(t)), F(t), $(
99
100
  // { ...userMessage, files },
100
101
  // { ...userMessage, },
101
102
  {
@@ -108,53 +109,55 @@ 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
+ }, Q = () => {
112
113
  z();
113
114
  }, _ = () => {
114
- J(), w([]), f(""), P({}), u([]), b(null), i({
115
+ G(), y([]), v(""), T({}), u([]), S(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, () => ({
122
- submitMessage: d,
121
+ }, { openForm: V } = re(), j = ae();
122
+ return ee(a.chatFunctionsRef, () => ({
123
+ submitMessage: h,
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
+ j?.setView("chat"), V(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
- isLoading: E,
136
+ isLoading: w,
136
137
  isStreaming: H,
137
138
  error: q,
139
+ setError: d,
138
140
  isSubmitDisabled: g,
139
141
  input: o,
140
- handleInputChange: k,
141
- handleInputKeyDown: L,
142
- handleSubmit: d,
143
- stop: O,
142
+ handleInputChange: N,
143
+ handleInputKeyDown: J,
144
+ handleSubmit: h,
145
+ stop: Q,
144
146
  clear: _,
145
- messageButtons: K,
147
+ messageButtons: P,
146
148
  isEmpty: l.length === 0,
147
- inputRef: S,
148
- isMobile: U,
149
+ inputRef: M,
150
+ isMobile: O,
149
151
  // Additional state for attachments and workflow
150
- messageAttachments: R,
152
+ messageAttachments: U,
151
153
  setMessageAttachments: u,
152
154
  selectedWorkflow: W,
153
- setSelectedWorkflow: b,
154
- isNewChat: T,
155
+ setSelectedWorkflow: S,
156
+ isNewChat: L,
155
157
  conversationId: s
156
158
  };
157
159
  };
158
160
  export {
159
- fe as useInkeepChat
161
+ me as DEFAULT_ERROR_MESSAGE,
162
+ Se as useInkeepChat
160
163
  };
@@ -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 r=require("react"),M=require("./use-inkeep-chat.cjs"),_=require("../../hooks/use-streaming-events.cjs"),q=require("../../../types/message.cjs");function z(u,l,g){const[m,D]=r.useState([]),[d,E]=r.useState(new Map),[y,I]=r.useState(Date.now()),[P,h]=r.useState(!1),w=r.useRef(0),S=r.useRef(0),x=r.useRef([]),f=r.useRef(d);f.current=d;const{emitArtifactSaved:k,emitCompletion:C,emitAgentInitializing:T,emitTextDelta:A}=_.useStreamingEvents(),R=r.useCallback(()=>{const n=[];let e="",o=[],c=!1;u.length>w.current&&(I(Date.now()),w.current=u.length),S.current=0;const p=new Map,i=(t=!1)=>{if(o.length>0){const s=`group-${S.current++}`,a=f.current.get(s);a?p.set(s,{...a,isCompleted:t}):p.set(s,{isCompleted:t}),n.push({type:"summary-group",summaries:[...o],groupKey:s}),o=[]}};for(const t of u)if(t.type==="text")i(!0),t.text&&l&&A(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"){e.trim()&&(n.push({type:"text",text:e}),e="");const s=t.data;if(s?.type)switch(s.type){case"completion":C("unknown",1),i(!0);break;case"agent_initializing":T("unknown","unknown");break;case"error":{i(!0);const a=s.message||"Unknown error";console.warn("Data operation error:",a),g(new Error(a)),c||(n.push({type:"text",text:M.DEFAULT_ERROR_MESSAGE}),c=!0);break}default:{const{type:a,label:L}=s;o.push({type:a,label:L});break}}}else if(t.type==="data-artifact")if(t.data?.type?.toLowerCase()===q.CITATION_ARTIFACT_TYPE){const s=t.data,a=s.artifactSummary||{title:s.name};e+=` ^${a?.title||s.name}^`}else e.trim()&&(n.push({type:"text",text:e}),e=""),n.push(t),t.data&&k(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=""),i(!0),n.push(t));return i(!l),e.trim()&&n.push({type:"text",text:e}),{processed:n,newTimings:p}},[u,l,k,C,T,A,g]);r.useEffect(()=>{if(x.current===u)return;x.current=u;const{processed:n,newTimings:e}=R();D(n),(e.size!==f.current.size||Array.from(e.entries()).some(([c,p])=>{const i=f.current.get(c);return!i||i.isCompleted!==p.isCompleted}))&&E(e)},[R,u]);const v=r.useCallback(()=>{const n=Date.now()-y,e=Array.from(f.current.values()).some(c=>!c.isCompleted),o=n>1e3&&!e;h(o)},[y]);r.useEffect(()=>{if(!l){h(!1);return}if(!(m.length>0)){h(!1);return}const e=setInterval(v,200);return()=>clearInterval(e)},[l,v,m.length]);const b=r.useMemo(()=>!(m.length>0),[m.length]);return{processedParts:m,summaryTimings:d,shouldShowInitialLoading:b,shouldShowStreamDelayLoading:P}}exports.useStreamProcessor=z;
@@ -1,82 +1,135 @@
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, {
15
- ...l,
2
+ import { useState as p, useRef as d, useCallback as R, useEffect as E, useMemo as F } from "react";
3
+ import { DEFAULT_ERROR_MESSAGE as G } from "./use-inkeep-chat.js";
4
+ import { useStreamingEvents as O } from "../../hooks/use-streaming-events.js";
5
+ import { CITATION_ARTIFACT_TYPE as U } from "../../../types/message.js";
6
+ function j(i, u, g) {
7
+ const [m, L] = p([]), [h, P] = p(/* @__PURE__ */ new Map()), [w, b] = p(Date.now()), [M, y] = p(!1), x = d(0), k = d(0), S = d([]), f = d(h);
8
+ f.current = h;
9
+ const { emitArtifactSaved: T, emitCompletion: C, emitAgentInitializing: A, emitTextDelta: D } = O(), v = R(() => {
10
+ const n = [];
11
+ let t = "", s = [], c = !1;
12
+ i.length > x.current && (b(Date.now()), x.current = i.length), k.current = 0;
13
+ const l = /* @__PURE__ */ new Map(), o = (e = !1) => {
14
+ if (s.length > 0) {
15
+ const r = `group-${k.current++}`, a = f.current.get(r);
16
+ a ? l.set(r, {
17
+ ...a,
16
18
  isCompleted: e
17
- }) : a.set(n, {
19
+ }) : l.set(r, {
18
20
  isCompleted: e
19
- }), s.push({
21
+ }), n.push({
20
22
  type: "summary-group",
21
- summaries: [...o],
22
- groupKey: n
23
- }), o = [];
23
+ summaries: [...s],
24
+ groupKey: r
25
+ }), s = [];
24
26
  }
25
27
  };
26
- for (const e of r)
28
+ for (const e of i)
27
29
  if (e.type === "text")
28
- u(!0), t += e.text || "";
30
+ o(!0), e.text && u && D(e.text), t += e.text || "";
29
31
  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
32
+ t.trim() && (n.push({ type: "text", text: t }), t = ""), s.push(e.data);
33
+ else if (e.type === "data-operation") {
34
+ t.trim() && (n.push({ type: "text", text: t }), t = "");
35
+ const r = e.data;
36
+ if (r?.type)
37
+ switch (r.type) {
38
+ case "completion":
39
+ C(
40
+ "unknown",
41
+ // No agent ID available in current structure
42
+ 1
43
+ // No iteration available in current structure
44
+ ), o(!0);
45
+ break;
46
+ case "agent_initializing":
47
+ A(
48
+ "unknown",
49
+ // No session ID available in current structure
50
+ "unknown"
51
+ // No graph ID available in current structure
52
+ );
53
+ break;
54
+ case "error": {
55
+ o(!0);
56
+ const a = r.message || "Unknown error";
57
+ console.warn("Data operation error:", a), g(new Error(a)), c || (n.push({ type: "text", text: G }), c = !0);
58
+ break;
59
+ }
60
+ default: {
61
+ const { type: a, label: z } = r;
62
+ s.push({ type: a, label: z });
63
+ break;
64
+ }
65
+ }
66
+ } else if (e.type === "data-artifact")
67
+ if (e.data?.type?.toLowerCase() === U) {
68
+ const r = e.data, a = r.artifactSummary || {
69
+ title: r.name
37
70
  };
38
- t += ` ^${l?.title || n.name}^`;
71
+ t += ` ^${a?.title || r.name}^`;
39
72
  } 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)
73
+ t.trim() && (n.push({ type: "text", text: t }), t = ""), n.push(e), e.data && T(
74
+ e.data.artifactId || "unknown",
75
+ e.data.taskId || "unknown",
76
+ "unknown",
77
+ // toolCallId not available in current structure
78
+ e.data.artifactType || "unknown",
79
+ e.data.artifactSummary || {},
80
+ // Use artifactSummary as summaryData
81
+ {},
82
+ // fullData not available in current structure
83
+ { name: e.data.name, description: e.data.description }
84
+ // Use available fields as metadata
85
+ );
86
+ else e.type === "data-component" && (t.trim() && (n.push({ type: "text", text: t }), t = ""), o(!0), n.push(e));
87
+ return o(!u), t.trim() && n.push({ type: "text", text: t }), { processed: n, newTimings: l };
88
+ }, [
89
+ i,
90
+ u,
91
+ T,
92
+ C,
93
+ A,
94
+ D,
95
+ g
96
+ ]);
97
+ E(() => {
98
+ if (S.current === i)
46
99
  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;
100
+ S.current = i;
101
+ const { processed: n, newTimings: t } = v();
102
+ L(n), (t.size !== f.current.size || Array.from(t.entries()).some(([c, l]) => {
103
+ const o = f.current.get(c);
104
+ return !o || o.isCompleted !== l.isCompleted;
52
105
  })) && 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);
59
- }, [g]);
60
- A(() => {
61
- if (!m) {
106
+ }, [v, i]);
107
+ const I = R(() => {
108
+ const n = Date.now() - w, t = Array.from(f.current.values()).some(
109
+ (c) => !c.isCompleted
110
+ ), s = n > 1e3 && !t;
111
+ y(s);
112
+ }, [w]);
113
+ E(() => {
114
+ if (!u) {
62
115
  y(!1);
63
116
  return;
64
117
  }
65
- if (!(i.length > 0)) {
118
+ if (!(m.length > 0)) {
66
119
  y(!1);
67
120
  return;
68
121
  }
69
- const t = setInterval(w, 200);
122
+ const t = setInterval(I, 200);
70
123
  return () => clearInterval(t);
71
- }, [m, w, i.length]);
72
- const I = R(() => !(i.length > 0), [i.length]);
124
+ }, [u, I, m.length]);
125
+ const _ = F(() => !(m.length > 0), [m.length]);
73
126
  return {
74
- processedParts: i,
127
+ processedParts: m,
75
128
  summaryTimings: h,
76
- shouldShowInitialLoading: I,
77
- shouldShowStreamDelayLoading: L
129
+ shouldShowInitialLoading: _,
130
+ shouldShowStreamDelayLoading: M
78
131
  };
79
132
  }
80
133
  export {
81
- E as useStreamProcessor
134
+ j as useStreamProcessor
82
135
  };
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),T=require("../../atoms/cmdk/index.cjs"),C=require("../../providers/search-events-provider.cjs"),E=require("../../providers/config-provider.cjs"),_=require("./search-provider.cjs"),k=400,P=()=>{const{setResultsList:t,setLoading:n,showSearchResults:i,setShowSearchResults:h}=_.useSearch(),{searchSettings:p}=E.useInkeepConfig(),{debounceTimeMs:b,onQueryChange:w,onSearch:f}=p,{logEvent:u}=C.useSearchEvents(),a=r.useRef({}),S=r.useRef(null),d=r.useRef(null),v=r.useCallback(async e=>{if(!f){console.warn("No search implementation provided. Please provide onSearch callback in searchSettings."),t([]);return}const s=new AbortController;S.current=s;try{n(!0);const o=await f(e,s.signal);a.current[e]=o,t(o)}catch(o){if(o.name==="AbortError")return;console.error("Search implementation failed:",o),t([])}finally{n(!1)}},[f,n,t]),R=r.useCallback(e=>{const s=a.current[e];u({eventName:"search_query_response_received",properties:{searchQuery:e,totalResults:s?.length}})},[u]),m=r.useCallback(()=>{S.current&&(S.current.abort(),n(!1))},[n]),g=r.useCallback(e=>{if(d.current&&window.clearTimeout(d.current),!e){m(),t([]);return}d.current=window.setTimeout(()=>{m(),u({eventName:"search_query_submitted",properties:{searchQuery:e}}),a.current[e]?(t(a.current[e]),R(e)):v(e).then(()=>{R(e)})},b)},[b,v,R,m,u,t]),c=T.useCommandState(e=>e.search),l=r.useRef(null);r.useEffect(()=>{const e=()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null)},s=!!c;return s&&!i?(e(),l.current=window.setTimeout(()=>{h(!0)},k)):!s&&i&&(e(),h(!1)),e},[c,i,h]),r.useEffect(()=>{w?.(c),g(c)},[g,c,w])};exports.useSearchFetch=P;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),T=require("../../atoms/cmdk/index.cjs"),C=require("../../providers/search-events-provider.cjs"),E=require("../../providers/config-provider.cjs"),_=require("./search-provider.cjs"),k=250,P=()=>{const{setResultsList:t,setLoading:n,showSearchResults:i,setShowSearchResults:h}=_.useSearch(),{searchSettings:p}=E.useInkeepConfig(),{debounceTimeMs:b,onQueryChange:w,onSearch:f}=p,{logEvent:u}=C.useSearchEvents(),a=r.useRef({}),S=r.useRef(null),d=r.useRef(null),v=r.useCallback(async e=>{if(!f){console.warn("No search implementation provided. Please provide onSearch callback in searchSettings."),t([]);return}const s=new AbortController;S.current=s;try{n(!0);const o=await f(e,s.signal);a.current[e]=o,t(o)}catch(o){if(o.name==="AbortError")return;console.error("Search implementation failed:",o),t([])}finally{n(!1)}},[f,n,t]),R=r.useCallback(e=>{const s=a.current[e];u({eventName:"search_query_response_received",properties:{searchQuery:e,totalResults:s?.length}})},[u]),m=r.useCallback(()=>{S.current&&(S.current.abort(),n(!1))},[n]),g=r.useCallback(e=>{if(d.current&&window.clearTimeout(d.current),!e){m(),t([]);return}d.current=window.setTimeout(()=>{m(),u({eventName:"search_query_submitted",properties:{searchQuery:e}}),a.current[e]?(t(a.current[e]),R(e)):v(e).then(()=>{R(e)})},b)},[b,v,R,m,u,t]),c=T.useCommandState(e=>e.search),l=r.useRef(null);r.useEffect(()=>{const e=()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null)},s=!!c;return s&&!i?(e(),l.current=window.setTimeout(()=>{h(!0)},k)):!s&&i&&(e(),h(!1)),e},[c,i,h]),r.useEffect(()=>{w?.(c),g(c)},[g,c,w])};exports.useSearchFetch=P;
@@ -4,7 +4,7 @@ import { useCommandState as _ } from "../../atoms/cmdk/index.js";
4
4
  import { useSearchEvents as E } from "../../providers/search-events-provider.js";
5
5
  import { useInkeepConfig as k } from "../../providers/config-provider.js";
6
6
  import { useSearch as L } from "./search-provider.js";
7
- const A = 400, O = () => {
7
+ const A = 250, O = () => {
8
8
  const { setResultsList: t, setLoading: s, showSearchResults: h, setShowSearchResults: m } = L(), { searchSettings: C } = k(), { debounceTimeMs: w, onQueryChange: T, onSearch: f } = C, { logEvent: c } = E(), a = u({}), S = u(null), d = u(null), b = i(
9
9
  async (e) => {
10
10
  if (!f) {
@@ -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;