@inkeep/agents-ui 0.14.11 → 0.14.13

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 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..
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.`}},[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;
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,emitToParent:R}=oe.useStreamingEvents(),[a,u]=t.useState(""),P=e=>u(e.target.value),{filters:E}=f,{onInputMessageChange:k,filters:S,agentUrl:A,context:D,headers:x,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}},[T,U]=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:A,headers:{...C?{Authorization:`Bearer ${C}`}:{},...x},body:{requestContext:D}}),onData(e){R(e.type,e.data)},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),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(()=>{k?.(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=E||S?JSON.stringify({...E,...S}):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(""),U({}),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:P,handleInputKeyDown:Q,handleSubmit:h,stop:j,clear:_,messageButtons:T,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;
@@ -10,49 +10,52 @@ import { useChatForm as re } from "../../providers/chat-form-provider.js";
10
10
  import { useWidget as ae } from "../../providers/widget-provider.js";
11
11
  import { useControllableState as ie } from "@radix-ui/react-use-controllable-state";
12
12
  import { useStreamingEvents as ce } from "../../hooks/use-streaming-events.js";
13
- const be = () => {
14
- const { baseSettings: h, aiChatSettings: a } = te(), [s = "", f] = ie({
13
+ const me = `Hmm..
14
+
15
+ It seems I might be having some issues right now. Please clear the chat and try again.`, ye = () => {
16
+ const { baseSettings: f, aiChatSettings: a } = te(), [s = "", v] = ie({
15
17
  prop: a.conversationId,
16
18
  defaultProp: a.conversationId ?? ""
17
- }), { logEvent: i } = oe(), { setConversationId: k, emitStreamError: F } = ce(), [o, m] = r(""), N = (e) => m(e.target.value), {
19
+ }), { logEvent: i } = oe(), { setConversationId: F, emitToParent: k } = ce(), [o, m] = r(""), D = (e) => m(e.target.value), {
18
20
  /* shouldBypassCaptcha, */
19
- filters: v
20
- } = h, {
21
- onInputMessageChange: D,
22
- filters: I,
23
- graphUrl: A,
24
- context: B,
25
- headers: K,
26
- apiKey: C
21
+ filters: I
22
+ } = f, {
23
+ onInputMessageChange: N,
24
+ filters: C,
25
+ agentUrl: A,
26
+ context: R,
27
+ headers: B,
28
+ apiKey: E
27
29
  } = a, P = (e) => {
28
30
  switch (e.code) {
29
31
  case 400:
30
32
  return e.message;
31
33
  case 403:
32
- 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"}`;
33
35
  default:
34
- return `Hmm..
35
-
36
- It seems I might be having some issues right now. Please clear the chat and try again.`;
36
+ return me;
37
37
  }
38
- }, [R, W] = r({}), [$, u] = r([]), [z, b] = r(null), {
38
+ }, [T, K] = r({}), [U, u] = r([]), [W, y] = r(null), {
39
39
  messages: l,
40
- sendMessage: H,
41
- status: y,
40
+ sendMessage: $,
41
+ status: b,
42
42
  setMessages: w,
43
- stop: T,
43
+ stop: z,
44
44
  error: p
45
45
  } = X({
46
46
  transport: new Y({
47
47
  api: A,
48
48
  headers: {
49
- ...C ? { Authorization: `Bearer ${C}` } : {},
50
- ...K
49
+ ...E ? { Authorization: `Bearer ${E}` } : {},
50
+ ...B
51
51
  },
52
52
  body: {
53
- requestContext: B
53
+ requestContext: R
54
54
  }
55
55
  }),
56
+ onData(e) {
57
+ k(e.type, e.data);
58
+ },
56
59
  async onFinish() {
57
60
  await i({
58
61
  eventName: "assistant_message_received",
@@ -67,22 +70,22 @@ It seems I might be having some issues right now. Please clear the chat and try
67
70
  });
68
71
  },
69
72
  onError(e) {
70
- console.log("onError", e.message), F(e.message, void 0, e.code?.toString()), w((c) => {
73
+ console.log("onError", e.message), w((c) => {
71
74
  const n = [...c], t = n[n.length - 1];
72
75
  return t && (t.parts = [{ type: "text", text: P(e) }]), n;
73
76
  });
74
77
  }
75
- }), E = y === "submitted", U = y === "streaming", q = l.length === 0, g = !o.trim() || E, J = se("(max-width: 768px)"), [L, S] = r(null);
78
+ }), S = b === "submitted", H = b === "streaming", L = l.length === 0, g = !o.trim() || S, O = se("(max-width: 768px)"), [q, d] = r(null);
76
79
  x(() => {
77
- p && S(p);
80
+ p && d(p);
78
81
  }, [p]);
79
- const O = () => S(null), M = Z(null);
82
+ const G = () => d(null), M = Z(null);
80
83
  x(() => {
81
- D?.(o);
84
+ N?.(o);
82
85
  }, [o]);
83
- const Q = (e) => {
84
- e.key === "Enter" && !e.shiftKey && !g && !e.nativeEvent.isComposing && (e.preventDefault(), d());
85
- }, d = async (e = o) => {
86
+ const J = (e) => {
87
+ e.key === "Enter" && !e.shiftKey && !g && !e.nativeEvent.isComposing && (e.preventDefault(), h());
88
+ }, h = async (e = o) => {
86
89
  if (g && (!e || e.trim().length === 0)) return;
87
90
  u([]), m(""), await i({
88
91
  eventName: "user_message_submitted",
@@ -90,13 +93,13 @@ It seems I might be having some issues right now. Please clear the chat and try
90
93
  conversationId: s
91
94
  }
92
95
  });
93
- const c = v || I ? JSON.stringify({
94
- ...v,
95
- ...I
96
+ const c = I || C ? JSON.stringify({
97
+ ...I,
98
+ ...C
96
99
  }) : void 0, n = {};
97
100
  c && (n["inkeep-filters"] = c);
98
101
  let t = s;
99
- t || (t = `conv_${ne(16)}`, f(t)), k(t), H(
102
+ t || (t = `conv_${ne(16)}`, v(t)), F(t), $(
100
103
  // { ...userMessage, files },
101
104
  // { ...userMessage, },
102
105
  {
@@ -109,53 +112,55 @@ It seems I might be having some issues right now. Please clear the chat and try
109
112
  }
110
113
  }
111
114
  );
112
- }, V = () => {
113
- T();
115
+ }, Q = () => {
116
+ z();
114
117
  }, _ = () => {
115
- O(), w([]), f(""), W({}), u([]), b(null), i({
118
+ G(), w([]), v(""), K({}), u([]), y(null), i({
116
119
  eventName: "chat_clear_button_clicked",
117
120
  properties: {
118
121
  conversationId: s
119
122
  }
120
123
  });
121
- }, { openForm: j } = re(), G = ae();
124
+ }, { openForm: V } = re(), j = ae();
122
125
  return ee(a.chatFunctionsRef, () => ({
123
- submitMessage: d,
126
+ submitMessage: h,
124
127
  updateInputMessage(e) {
125
128
  m(e);
126
129
  },
127
130
  clearChat: _,
128
131
  openForm: (e) => {
129
- G?.setView("chat"), j(e, void 0);
132
+ j?.setView("chat"), V(e, void 0);
130
133
  },
131
134
  focusInput: () => {
132
135
  M.current?.focus();
133
136
  }
134
137
  })), {
135
138
  messages: l,
136
- isLoading: E,
137
- isStreaming: U,
138
- error: L,
139
+ isLoading: S,
140
+ isStreaming: H,
141
+ error: q,
142
+ setError: d,
139
143
  isSubmitDisabled: g,
140
144
  input: o,
141
- handleInputChange: N,
142
- handleInputKeyDown: Q,
143
- handleSubmit: d,
144
- stop: V,
145
+ handleInputChange: D,
146
+ handleInputKeyDown: J,
147
+ handleSubmit: h,
148
+ stop: Q,
145
149
  clear: _,
146
- messageButtons: R,
150
+ messageButtons: T,
147
151
  isEmpty: l.length === 0,
148
152
  inputRef: M,
149
- isMobile: J,
153
+ isMobile: O,
150
154
  // Additional state for attachments and workflow
151
- messageAttachments: $,
155
+ messageAttachments: U,
152
156
  setMessageAttachments: u,
153
- selectedWorkflow: z,
154
- setSelectedWorkflow: b,
155
- isNewChat: q,
157
+ selectedWorkflow: W,
158
+ setSelectedWorkflow: y,
159
+ isNewChat: L,
156
160
  conversationId: s
157
161
  };
158
162
  };
159
163
  export {
160
- be as useInkeepChat
164
+ me as DEFAULT_ERROR_MESSAGE,
165
+ ye as useInkeepChat
161
166
  };
@@ -1 +1 @@
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
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),b=require("./use-inkeep-chat.cjs"),E=require("../../../types/message.cjs");function L(i,p,g){const[l,R]=n.useState([]),[h,A]=n.useState(new Map),[d,D]=n.useState(Date.now()),[P,y]=n.useState(!1),S=n.useRef(0),x=n.useRef(0),w=n.useRef([]),f=n.useRef(h);f.current=h;const C=n.useCallback(()=>{const t=[];let e="",o=[],c=!1;i.length>S.current&&(D(Date.now()),S.current=i.length),x.current=0;const m=new Map,u=(s=!1)=>{if(o.length>0){const r=`group-${x.current++}`,a=f.current.get(r);a?m.set(r,{...a,isCompleted:s}):m.set(r,{isCompleted:s}),t.push({type:"summary-group",summaries:[...o],groupKey:r}),o=[]}};for(const s of i)if(s.type==="text")u(!0),e+=s.text||"";else if(s.type==="data-summary")e.trim()&&(t.push({type:"text",text:e}),e=""),o.push(s.data);else if(s.type==="data-operation"){e.trim()&&(t.push({type:"text",text:e}),e="");const r=s.data;if(r?.type)switch(r.type){case"completion":u(!0);break;case"error":{u(!0);const a=r.message||"Unknown error";console.warn("Data operation error:",a),g(new Error(a)),c||(t.push({type:"text",text:b.DEFAULT_ERROR_MESSAGE}),c=!0);break}default:{const{type:a,label:v}=r;o.push({type:a,label:v});break}}}else if(s.type==="data-artifact")if(s.data?.type?.toLowerCase()===E.CITATION_ARTIFACT_TYPE){const r=s.data,a=r.artifactSummary||{title:r.name};e+=` ^${a?.title||r.name}^`}else e.trim()&&(t.push({type:"text",text:e}),e=""),t.push(s);else s.type==="data-component"&&(e.trim()&&(t.push({type:"text",text:e}),e=""),u(!0),t.push(s));return u(!p),e.trim()&&t.push({type:"text",text:e}),{processed:t,newTimings:m}},[i,p,g]);n.useEffect(()=>{if(w.current===i)return;w.current=i;const{processed:t,newTimings:e}=C();R(t),(e.size!==f.current.size||Array.from(e.entries()).some(([c,m])=>{const u=f.current.get(c);return!u||u.isCompleted!==m.isCompleted}))&&A(e)},[C,i]);const T=n.useCallback(()=>{const t=Date.now()-d,e=Array.from(f.current.values()).some(c=>!c.isCompleted),o=t>1e3&&!e;y(o)},[d]);n.useEffect(()=>{if(!p){y(!1);return}if(!(l.length>0)){y(!1);return}const e=setInterval(T,200);return()=>clearInterval(e)},[p,T,l.length]);const k=n.useMemo(()=>!(l.length>0),[l.length]);return{processedParts:l,summaryTimings:h,shouldShowInitialLoading:k,shouldShowStreamDelayLoading:P}}exports.useStreamProcessor=L;
@@ -1,121 +1,101 @@
1
1
  "use client";
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, {
16
- ...l,
17
- isCompleted: t
18
- }) : o.set(a, {
19
- isCompleted: t
20
- }), n.push({
2
+ import { useState as p, useRef as h, useCallback as D, useEffect as R, useMemo as M } from "react";
3
+ import { DEFAULT_ERROR_MESSAGE as b } from "./use-inkeep-chat.js";
4
+ import { CITATION_ARTIFACT_TYPE as _ } from "../../../types/message.js";
5
+ function z(i, f, d) {
6
+ const [u, v] = p([]), [y, L] = p(/* @__PURE__ */ new Map()), [x, P] = p(Date.now()), [k, g] = p(!1), w = h(0), C = h(0), S = h([]), m = h(y);
7
+ m.current = y;
8
+ const T = D(() => {
9
+ const e = [];
10
+ let t = "", o = [], c = !1;
11
+ i.length > w.current && (P(Date.now()), w.current = i.length), C.current = 0;
12
+ const l = /* @__PURE__ */ new Map(), a = (r = !1) => {
13
+ if (o.length > 0) {
14
+ const s = `group-${C.current++}`, n = m.current.get(s);
15
+ n ? l.set(s, {
16
+ ...n,
17
+ isCompleted: r
18
+ }) : l.set(s, {
19
+ isCompleted: r
20
+ }), e.push({
21
21
  type: "summary-group",
22
- summaries: [...s],
23
- groupKey: a
24
- }), s = [];
22
+ summaries: [...o],
23
+ groupKey: s
24
+ }), o = [];
25
25
  }
26
26
  };
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) {
27
+ for (const r of i)
28
+ if (r.type === "text")
29
+ a(!0), t += r.text || "";
30
+ else if (r.type === "data-summary")
31
+ t.trim() && (e.push({ type: "text", text: t }), t = ""), o.push(r.data);
32
+ else if (r.type === "data-operation") {
33
+ t.trim() && (e.push({ type: "text", text: t }), t = "");
34
+ const s = r.data;
35
+ if (s?.type)
36
+ switch (s.type) {
36
37
  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);
38
+ a(!0);
43
39
  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
- );
40
+ case "error": {
41
+ a(!0);
42
+ const n = s.message || "Unknown error";
43
+ console.warn("Data operation error:", n), d(new Error(n)), c || (e.push({ type: "text", text: b }), c = !0);
51
44
  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);
45
+ }
46
+ default: {
47
+ const { type: n, label: I } = s;
48
+ o.push({ type: n, label: I });
58
49
  break;
50
+ }
59
51
  }
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
52
+ } else if (r.type === "data-artifact")
53
+ if (r.data?.type?.toLowerCase() === _) {
54
+ const s = r.data, n = s.artifactSummary || {
55
+ title: s.name
64
56
  };
65
- e += ` ^${l?.title || a.name}^`;
57
+ t += ` ^${n?.title || s.name}^`;
66
58
  } else
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)
59
+ t.trim() && (e.push({ type: "text", text: t }), t = ""), e.push(r);
60
+ else r.type === "data-component" && (t.trim() && (e.push({ type: "text", text: t }), t = ""), a(!0), e.push(r));
61
+ return a(!f), t.trim() && e.push({ type: "text", text: t }), { processed: e, newTimings: l };
62
+ }, [i, f, d]);
63
+ R(() => {
64
+ if (S.current === i)
85
65
  return;
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);
98
- }, [g]);
99
- I(() => {
100
- if (!i) {
101
- h(!1);
66
+ S.current = i;
67
+ const { processed: e, newTimings: t } = T();
68
+ v(e), (t.size !== m.current.size || Array.from(t.entries()).some(([c, l]) => {
69
+ const a = m.current.get(c);
70
+ return !a || a.isCompleted !== l.isCompleted;
71
+ })) && L(t);
72
+ }, [T, i]);
73
+ const A = D(() => {
74
+ const e = Date.now() - x, t = Array.from(m.current.values()).some(
75
+ (c) => !c.isCompleted
76
+ ), o = e > 1e3 && !t;
77
+ g(o);
78
+ }, [x]);
79
+ R(() => {
80
+ if (!f) {
81
+ g(!1);
102
82
  return;
103
83
  }
104
- if (!(c.length > 0)) {
105
- h(!1);
84
+ if (!(u.length > 0)) {
85
+ g(!1);
106
86
  return;
107
87
  }
108
- const e = setInterval(v, 200);
109
- return () => clearInterval(e);
110
- }, [i, v, c.length]);
111
- const _ = z(() => !(c.length > 0), [c.length]);
88
+ const t = setInterval(A, 200);
89
+ return () => clearInterval(t);
90
+ }, [f, A, u.length]);
91
+ const E = M(() => !(u.length > 0), [u.length]);
112
92
  return {
113
- processedParts: c,
114
- summaryTimings: d,
115
- shouldShowInitialLoading: _,
116
- shouldShowStreamDelayLoading: b
93
+ processedParts: u,
94
+ summaryTimings: y,
95
+ shouldShowInitialLoading: E,
96
+ shouldShowStreamDelayLoading: k
117
97
  };
118
98
  }
119
99
  export {
120
- $ as useStreamProcessor
100
+ z as useStreamProcessor
121
101
  };
@@ -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) {
@@ -1 +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;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),u=require("../atoms/shadow/context.cjs");function i(){const e=u.useShadow()?.shadowHost,s=n.useRef(""),o=n.useCallback(t=>{s.current=t},[]),r=n.useCallback((t,a)=>{if(!e){console.warn("useStreamingEvents: No host element available for parent event emission");return}const c=new CustomEvent(`ikp-${t}`,{detail:{...a,conversationId:s.current,timestamp:Date.now()},bubbles:!0,composed:!0});e.dispatchEvent(c)},[e]);return{setConversationId:o,emitToParent:r}}exports.useStreamingEvents=i;