@inkeep/agents-ui 0.15.9 → 0.15.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.
@@ -7,7 +7,6 @@ export declare const useColorMode: () => UseColorModeProps;
7
7
  * @param light the light mode value
8
8
  * @param dark the dark mode value
9
9
  *
10
- * @example
11
10
  *
12
11
  * ```js
13
12
  * const Icon = useColorModeValue(MoonIcon, SunIcon)
@@ -1,3 +1,3 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const ee=require("@ai-sdk/react"),te=require("ai"),n=require("react"),se=require("../../providers/config-provider.cjs"),ne=require("../../hooks/use-media-query.cjs"),A=require("../../utils/generate-uid.cjs"),re=require("../../providers/base-events-provider.cjs"),oe=require("../../providers/chat-form-provider.cjs"),ae=require("../../providers/widget-provider.cjs"),ie=require("@radix-ui/react-use-controllable-state"),ce=require("../../hooks/use-streaming-events.cjs"),P=`Hmm..
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const re=require("@ai-sdk/react"),ae=require("ai"),n=require("react"),oe=require("../../providers/config-provider.cjs"),ie=require("../../hooks/use-media-query.cjs"),U=require("../../utils/generate-uid.cjs"),ce=require("../../providers/base-events-provider.cjs"),ue=require("../../providers/chat-form-provider.cjs"),le=require("../../providers/widget-provider.cjs"),pe=require("@radix-ui/react-use-controllable-state"),de=require("../../hooks/use-streaming-events.cjs"),O=`Hmm..
2
2
 
3
- It seems I might be having some issues right now. Please clear the chat and try again.`,ue=()=>{const{baseSettings:C,aiChatSettings:i}=se.useInkeepConfig(),[t="",I]=ie.useControllableState({prop:i.conversationId,defaultProp:i.conversationId??""}),{logEvent:o}=re.useBaseEvents(),{setConversationId:N,emitToParent:u}=ce.useStreamingEvents(),[a,l]=n.useState(""),T=e=>l(e.target.value),{filters:b}=C,{onInputMessageChange:U,filters:y,agentUrl:w,context:d,headers:p,apiKey:g}=i,O=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${C.organizationDisplayName??"Administrator"}`;default:return P}},[H,m]=n.useState([]),[z,M]=n.useState(null),K=()=>({"x-inkeep-client-timezone":Intl.DateTimeFormat().resolvedOptions().timeZone,"x-inkeep-client-timestamp":new Date().toISOString()}),L=n.useMemo(()=>new te.DefaultChatTransport({api:w,headers:{...g?{Authorization:`Bearer ${g}`}:{},...p},body:{requestContext:d}}),[w,g,p,d]),{messages:h,sendMessage:_,addToolApprovalResponse:W,status:q,setMessages:x,stop:$,error:f}=ee.useChat({transport:L,onData(e){u(e.type,e.data)},async onFinish(){u("completion",{conversationId:t}),await o({eventName:"assistant_message_received",properties:{conversationId:t}}),o({eventName:"assistant_answer_displayed",properties:{conversationId:t}})},onError(e){console.log("onError",e.message),o({eventName:"chat_error",properties:{conversationId:t,error:e.message}}),x(c=>{const r=[...c],s=r[r.length-1];if(s){const D=O(e);s.role==="user"?r.push({id:A.generateUid(16),role:"assistant",parts:[{type:"text",text:D}]}):s.parts=[{type:"text",text:D}]}return r})}}),F=q==="submitted",B=q==="streaming",G=h.length===0,v=!a.trim()||F,Q=ne.useMediaQuery("(max-width: 768px)"),[j,S]=n.useState(null);n.useEffect(()=>{f&&S(f)},[f]);const J=()=>S(null),R=n.useRef(null);n.useEffect(()=>{U?.(a)},[a]);const V=e=>{e.key==="Enter"&&!e.shiftKey&&!v&&!e.nativeEvent.isComposing&&(e.preventDefault(),E())},E=async(e=a)=>{if(v&&(!e||e.trim().length===0))return;m([]),l(""),await o({eventName:"user_message_submitted",properties:{conversationId:t}});const c=b||y?JSON.stringify({...b,...y}):void 0,r={...p};c&&(r["inkeep-filters"]=c);let s=t;s||(s=`conv_${A.generateUid(16)}`,I(s)),N(s),_({text:e},{headers:{...K(),...r},body:{conversationId:s,requestContext:d}})},Z=()=>{$().then(()=>{u("aborted",{conversationId:t})})},k=()=>{J(),x([]),I(""),m([]),M(null),o({eventName:"chat_clear_button_clicked",properties:{conversationId:t}})},{openForm:X}=oe.useChatForm(),Y=ae.useWidget();return n.useImperativeHandle(i.chatFunctionsRef,()=>({submitMessage:E,updateInputMessage(e){l(e)},clearChat:k,openForm:e=>{Y?.setView("chat"),X(e,void 0)},focusInput:()=>{R.current?.focus()}})),{messages:h,sendMessage:_,addToolApprovalResponse:W,isLoading:F,isStreaming:B,error:j,setError:S,isSubmitDisabled:v,input:a,handleInputChange:T,handleInputKeyDown:V,handleSubmit:E,stop:Z,clear:k,isEmpty:h.length===0,inputRef:R,isMobile:Q,messageAttachments:H,setMessageAttachments:m,selectedWorkflow:z,setSelectedWorkflow:M,isNewChat:G,conversationId:t}};exports.DEFAULT_ERROR_MESSAGE=P;exports.useInkeepChat=ue;
3
+ It seems I might be having some issues right now. Please clear the chat and try again.`,ge=()=>{const{baseSettings:C,aiChatSettings:l}=oe.useInkeepConfig(),[r="",I]=pe.useControllableState({prop:l.conversationId,defaultProp:l.conversationId??""}),{logEvent:o}=ce.useBaseEvents(),{setConversationId:B,emitToParent:p}=de.useStreamingEvents(),[i,d]=n.useState(""),H=e=>d(e.target.value),{filters:M}=C,{onInputMessageChange:W,filters:w,agentUrl:_,context:g,headers:m,apiKey:f}=l,z=e=>{switch(e.code){case 400:return e.message;case 403:return`There seems to be a configuration error. Please contact ${C.organizationDisplayName??"Administrator"}`;default:return O}},[K,h]=n.useState([]),[L,q]=n.useState(null),$=()=>({"x-inkeep-client-timezone":Intl.DateTimeFormat().resolvedOptions().timeZone,"x-inkeep-client-timestamp":new Date().toISOString()}),j=n.useMemo(()=>new ae.DefaultChatTransport({api:_,headers:{...f?{Authorization:`Bearer ${f}`}:{},...m},body:{requestContext:g}}),[_,f,m,g]),{messages:c,sendMessage:F,addToolApprovalResponse:G,status:x,setMessages:A,stop:Q,error:v}=re.useChat({transport:j,onData(e){p(e.type,e.data)},async onFinish(){p("completion",{conversationId:r}),await o({eventName:"assistant_message_received",properties:{conversationId:r}}),o({eventName:"assistant_answer_displayed",properties:{conversationId:r}})},onError(e){console.log("onError",e.message),o({eventName:"chat_error",properties:{conversationId:r,error:e.message}}),A(u=>{const s=[...u],t=s[s.length-1];if(t){const a=z(e);t.role==="user"?s.push({id:U.generateUid(16),role:"assistant",parts:[{type:"text",text:a}]}):t.parts=[{type:"text",text:a}]}return s})}}),P=x==="submitted",S=x==="streaming",J=n.useMemo(()=>{const e=a=>{if(!a||typeof a!="object")return!1;const N=a;return typeof N.type=="string"&&N.type.startsWith("tool-")},s=[...c??[]].reverse().find(a=>a.role==="assistant");if(!s)return!1;const t=s.parts?.at(-1);return!(!e(t)||t.state!=="output-available"||!t.approval?.id||S)},[c,S]),R=S||J,k=P||R,V=c.length===0,y=!i.trim()||k,Z=ie.useMediaQuery("(max-width: 768px)"),[X,E]=n.useState(null);n.useEffect(()=>{v&&E(v)},[v]);const Y=()=>E(null),D=n.useRef(null);n.useEffect(()=>{W?.(i)},[i]);const ee=e=>{e.key==="Enter"&&!e.shiftKey&&!y&&!e.nativeEvent.isComposing&&(e.preventDefault(),b())},b=async(e=i)=>{if(y&&(!e||e.trim().length===0))return;h([]),d(""),await o({eventName:"user_message_submitted",properties:{conversationId:r}});const u=M||w?JSON.stringify({...M,...w}):void 0,s={...m};u&&(s["inkeep-filters"]=u);let t=r;t||(t=`conv_${U.generateUid(16)}`,I(t)),B(t),F({text:e},{headers:{...$(),...s},body:{conversationId:t,requestContext:g}})},te=()=>{Q().then(()=>{p("aborted",{conversationId:r})})},T=()=>{Y(),A([]),I(""),h([]),q(null),o({eventName:"chat_clear_button_clicked",properties:{conversationId:r}})},{openForm:se}=ue.useChatForm(),ne=le.useWidget();return n.useImperativeHandle(l.chatFunctionsRef,()=>({submitMessage:b,updateInputMessage(e){d(e)},clearChat:T,openForm:e=>{ne?.setView("chat"),se(e,void 0)},focusInput:()=>{D.current?.focus()}})),{messages:c,sendMessage:F,addToolApprovalResponse:G,isLoading:P,isStreaming:R,isBusy:k,error:X,setError:E,isSubmitDisabled:y,input:i,handleInputChange:H,handleInputKeyDown:ee,handleSubmit:b,stop:te,clear:T,isEmpty:c.length===0,inputRef:D,isMobile:Z,messageAttachments:K,setMessageAttachments:h,selectedWorkflow:L,setSelectedWorkflow:q,isNewChat:V,conversationId:r}};exports.DEFAULT_ERROR_MESSAGE=O;exports.useInkeepChat=ge;
@@ -26,6 +26,7 @@ export declare const useInkeepChat: () => {
26
26
  addToolApprovalResponse: ChatAddToolApproveResponseFunction;
27
27
  isLoading: boolean;
28
28
  isStreaming: boolean;
29
+ isBusy: boolean;
29
30
  error: Error | null;
30
31
  setError: Dispatch<SetStateAction<Error | null>>;
31
32
  isSubmitDisabled: boolean;
@@ -1,194 +1,204 @@
1
1
  "use client";
2
- import { useChat as ee } from "@ai-sdk/react";
3
- import { DefaultChatTransport as te } from "ai";
4
- import { useState as c, useMemo as se, useEffect as R, useRef as ne, useImperativeHandle as oe } from "react";
5
- import { useInkeepConfig as re } from "../../providers/config-provider.js";
6
- import { useMediaQuery as ae } from "../../hooks/use-media-query.js";
7
- import { generateUid as T } from "../../utils/generate-uid.js";
8
- import { useBaseEvents as ie } from "../../providers/base-events-provider.js";
9
- import { useChatForm as ce } from "../../providers/chat-form-provider.js";
10
- import { useWidget as me } from "../../providers/widget-provider.js";
11
- import { useControllableState as le } from "@radix-ui/react-use-controllable-state";
12
- import { useStreamingEvents as pe } from "../../hooks/use-streaming-events.js";
13
- const ue = `Hmm..
2
+ import { useChat as re } from "@ai-sdk/react";
3
+ import { DefaultChatTransport as ae } from "ai";
4
+ import { useState as m, useMemo as H, useEffect as O, useRef as ie, useImperativeHandle as le } from "react";
5
+ import { useInkeepConfig as ce } from "../../providers/config-provider.js";
6
+ import { useMediaQuery as me } from "../../hooks/use-media-query.js";
7
+ import { generateUid as W } from "../../utils/generate-uid.js";
8
+ import { useBaseEvents as pe } from "../../providers/base-events-provider.js";
9
+ import { useChatForm as ue } from "../../providers/chat-form-provider.js";
10
+ import { useWidget as fe } from "../../providers/widget-provider.js";
11
+ import { useControllableState as ge } from "@radix-ui/react-use-controllable-state";
12
+ import { useStreamingEvents as de } from "../../hooks/use-streaming-events.js";
13
+ const he = `Hmm..
14
14
 
15
- It seems I might be having some issues right now. Please clear the chat and try again.`, we = () => {
16
- const { baseSettings: y, aiChatSettings: a } = re(), [t = "", E] = le({
17
- prop: a.conversationId,
18
- defaultProp: a.conversationId ?? ""
19
- }), { logEvent: o } = ie(), { setConversationId: H, emitToParent: m } = pe(), [r, l] = c(""), O = (e) => l(e.target.value), {
15
+ It seems I might be having some issues right now. Please clear the chat and try again.`, Fe = () => {
16
+ const { baseSettings: S, aiChatSettings: c } = ce(), [n = "", E] = ge({
17
+ prop: c.conversationId,
18
+ defaultProp: c.conversationId ?? ""
19
+ }), { logEvent: r } = pe(), { setConversationId: q, emitToParent: p } = de(), [a, u] = m(""), z = (e) => u(e.target.value), {
20
20
  /* shouldBypassCaptcha, */
21
- filters: b
22
- } = y, {
23
- onInputMessageChange: P,
24
- filters: S,
25
- agentUrl: w,
26
- context: p,
27
- headers: u,
21
+ filters: w
22
+ } = S, {
23
+ onInputMessageChange: K,
24
+ filters: M,
25
+ agentUrl: x,
26
+ context: f,
27
+ headers: g,
28
28
  apiKey: d
29
- } = a, q = (e) => {
29
+ } = c, U = (e) => {
30
30
  switch (e.code) {
31
31
  case 400:
32
32
  return e.message;
33
33
  case 403:
34
- return `There seems to be a configuration error. Please contact ${y.organizationDisplayName ?? "Administrator"}`;
34
+ return `There seems to be a configuration error. Please contact ${S.organizationDisplayName ?? "Administrator"}`;
35
35
  default:
36
- return ue;
36
+ return he;
37
37
  }
38
- }, [z, g] = c([]), [K, x] = c(null), U = () => ({
38
+ }, [$, h] = m([]), [L, _] = m(null), j = () => ({
39
39
  "x-inkeep-client-timezone": Intl.DateTimeFormat().resolvedOptions().timeZone,
40
40
  "x-inkeep-client-timestamp": (/* @__PURE__ */ new Date()).toISOString()
41
- }), W = se(
42
- () => new te({
43
- api: w,
41
+ }), G = H(
42
+ () => new ae({
43
+ api: x,
44
44
  headers: {
45
45
  ...d ? { Authorization: `Bearer ${d}` } : {},
46
- ...u
46
+ ...g
47
47
  },
48
48
  body: {
49
- requestContext: p
49
+ requestContext: f
50
50
  }
51
51
  }),
52
- [w, d, u, p]
52
+ [x, d, g, f]
53
53
  ), {
54
- messages: h,
55
- sendMessage: M,
56
- addToolApprovalResponse: $,
57
- status: _,
58
- setMessages: k,
59
- stop: B,
60
- error: f
61
- } = ee({
62
- transport: W,
54
+ messages: i,
55
+ sendMessage: F,
56
+ addToolApprovalResponse: J,
57
+ status: k,
58
+ setMessages: A,
59
+ stop: Q,
60
+ error: v
61
+ } = re({
62
+ transport: G,
63
63
  onData(e) {
64
- m(e.type, e.data);
64
+ p(e.type, e.data);
65
65
  },
66
66
  async onFinish() {
67
- m("completion", { conversationId: t }), await o({
67
+ p("completion", { conversationId: n }), await r({
68
68
  eventName: "assistant_message_received",
69
69
  properties: {
70
- conversationId: t
70
+ conversationId: n
71
71
  }
72
- }), o({
72
+ }), r({
73
73
  eventName: "assistant_answer_displayed",
74
74
  properties: {
75
- conversationId: t
75
+ conversationId: n
76
76
  }
77
77
  });
78
78
  },
79
79
  onError(e) {
80
- console.log("onError", e.message), o({
80
+ console.log("onError", e.message), r({
81
81
  eventName: "chat_error",
82
82
  properties: {
83
- conversationId: t,
83
+ conversationId: n,
84
84
  error: e.message
85
85
  }
86
- }), k((i) => {
87
- const n = [...i], s = n[n.length - 1];
88
- if (s) {
89
- const A = q(e);
90
- s.role === "user" ? n.push({
91
- id: T(16),
86
+ }), A((l) => {
87
+ const s = [...l], t = s[s.length - 1];
88
+ if (t) {
89
+ const o = U(e);
90
+ t.role === "user" ? s.push({
91
+ id: W(16),
92
92
  role: "assistant",
93
- parts: [{ type: "text", text: A }]
94
- }) : s.parts = [{ type: "text", text: A }];
93
+ parts: [{ type: "text", text: o }]
94
+ }) : t.parts = [{ type: "text", text: o }];
95
95
  }
96
- return n;
96
+ return s;
97
97
  });
98
98
  }
99
- }), D = _ === "submitted", L = _ === "streaming", G = h.length === 0, v = !r.trim() || D, J = ae("(max-width: 768px)"), [Q, I] = c(null);
100
- R(() => {
101
- f && I(f);
102
- }, [f]);
103
- const V = () => I(null), F = ne(null);
104
- R(() => {
105
- P?.(r);
106
- }, [r]);
107
- const Z = (e) => {
108
- e.key === "Enter" && !e.shiftKey && !v && !e.nativeEvent.isComposing && (e.preventDefault(), C());
109
- }, C = async (e = r) => {
110
- if (v && (!e || e.trim().length === 0)) return;
111
- g([]), l(""), await o({
99
+ }), D = k === "submitted", y = k === "streaming", V = H(() => {
100
+ const e = (o) => {
101
+ if (!o || typeof o != "object") return !1;
102
+ const B = o;
103
+ return typeof B.type == "string" && B.type.startsWith("tool-");
104
+ }, s = [...i ?? []].reverse().find((o) => o.role === "assistant");
105
+ if (!s) return !1;
106
+ const t = s.parts?.at(-1);
107
+ return !(!e(t) || t.state !== "output-available" || !t.approval?.id || y);
108
+ }, [i, y]), N = y || V, T = D || N, Z = i.length === 0, I = !a.trim() || T, X = me("(max-width: 768px)"), [Y, C] = m(null);
109
+ O(() => {
110
+ v && C(v);
111
+ }, [v]);
112
+ const ee = () => C(null), R = ie(null);
113
+ O(() => {
114
+ K?.(a);
115
+ }, [a]);
116
+ const te = (e) => {
117
+ e.key === "Enter" && !e.shiftKey && !I && !e.nativeEvent.isComposing && (e.preventDefault(), b());
118
+ }, b = async (e = a) => {
119
+ if (I && (!e || e.trim().length === 0)) return;
120
+ h([]), u(""), await r({
112
121
  eventName: "user_message_submitted",
113
122
  properties: {
114
- conversationId: t
123
+ conversationId: n
115
124
  }
116
125
  });
117
- const i = b || S ? JSON.stringify({
118
- ...b,
119
- ...S
120
- }) : void 0, n = {
121
- ...u
126
+ const l = w || M ? JSON.stringify({
127
+ ...w,
128
+ ...M
129
+ }) : void 0, s = {
130
+ ...g
122
131
  };
123
- i && (n["inkeep-filters"] = i);
124
- let s = t;
125
- s || (s = `conv_${T(16)}`, E(s)), H(s), M(
132
+ l && (s["inkeep-filters"] = l);
133
+ let t = n;
134
+ t || (t = `conv_${W(16)}`, E(t)), q(t), F(
126
135
  {
127
136
  text: e
128
137
  },
129
138
  {
130
139
  headers: {
131
- ...U(),
132
- ...n
140
+ ...j(),
141
+ ...s
133
142
  },
134
143
  body: {
135
- conversationId: s,
136
- requestContext: p
144
+ conversationId: t,
145
+ requestContext: f
137
146
  }
138
147
  }
139
148
  );
140
- }, j = () => {
141
- B().then(() => {
142
- m("aborted", { conversationId: t });
149
+ }, se = () => {
150
+ Q().then(() => {
151
+ p("aborted", { conversationId: n });
143
152
  });
144
- }, N = () => {
145
- V(), k([]), E(""), g([]), x(null), o({
153
+ }, P = () => {
154
+ ee(), A([]), E(""), h([]), _(null), r({
146
155
  eventName: "chat_clear_button_clicked",
147
156
  properties: {
148
- conversationId: t
157
+ conversationId: n
149
158
  }
150
159
  });
151
- }, { openForm: X } = ce(), Y = me();
152
- return oe(a.chatFunctionsRef, () => ({
153
- submitMessage: C,
160
+ }, { openForm: ne } = ue(), oe = fe();
161
+ return le(c.chatFunctionsRef, () => ({
162
+ submitMessage: b,
154
163
  updateInputMessage(e) {
155
- l(e);
164
+ u(e);
156
165
  },
157
- clearChat: N,
166
+ clearChat: P,
158
167
  openForm: (e) => {
159
- Y?.setView("chat"), X(e, void 0);
168
+ oe?.setView("chat"), ne(e, void 0);
160
169
  },
161
170
  focusInput: () => {
162
- F.current?.focus();
171
+ R.current?.focus();
163
172
  }
164
173
  })), {
165
- messages: h,
166
- sendMessage: M,
167
- addToolApprovalResponse: $,
174
+ messages: i,
175
+ sendMessage: F,
176
+ addToolApprovalResponse: J,
168
177
  isLoading: D,
169
- isStreaming: L,
170
- error: Q,
171
- setError: I,
172
- isSubmitDisabled: v,
173
- input: r,
174
- handleInputChange: O,
175
- handleInputKeyDown: Z,
176
- handleSubmit: C,
177
- stop: j,
178
- clear: N,
179
- isEmpty: h.length === 0,
180
- inputRef: F,
181
- isMobile: J,
178
+ isStreaming: N,
179
+ isBusy: T,
180
+ error: Y,
181
+ setError: C,
182
+ isSubmitDisabled: I,
183
+ input: a,
184
+ handleInputChange: z,
185
+ handleInputKeyDown: te,
186
+ handleSubmit: b,
187
+ stop: se,
188
+ clear: P,
189
+ isEmpty: i.length === 0,
190
+ inputRef: R,
191
+ isMobile: X,
182
192
  // Additional state for attachments and workflow
183
- messageAttachments: z,
184
- setMessageAttachments: g,
185
- selectedWorkflow: K,
186
- setSelectedWorkflow: x,
187
- isNewChat: G,
188
- conversationId: t
193
+ messageAttachments: $,
194
+ setMessageAttachments: h,
195
+ selectedWorkflow: L,
196
+ setSelectedWorkflow: _,
197
+ isNewChat: Z,
198
+ conversationId: n
189
199
  };
190
200
  };
191
201
  export {
192
- ue as DEFAULT_ERROR_MESSAGE,
193
- we as useInkeepChat
202
+ he as DEFAULT_ERROR_MESSAGE,
203
+ Fe as useInkeepChat
194
204
  };
@@ -1 +1 @@
1
- "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),E=require("./use-inkeep-chat.cjs");function L(f,i,d){const[p,D]=n.useState([]),[h,x]=n.useState(new Map),[w,T]=n.useState(Date.now()),[A,y]=n.useState(!1),C=n.useRef(0),S=n.useRef(0),R=n.useRef([]),m=n.useRef(h);m.current=h;const b=n.useCallback(()=>{const t=[];let e="",a=[],c=!1;f.length>C.current&&(T(Date.now()),C.current=f.length),S.current=0;const l=new Map,u=(s=!1)=>{if(a.length>0){const r=`group-${S.current++}`,o=m.current.get(r);o?l.set(r,{...o,isCompleted:s}):l.set(r,{isCompleted:s}),t.push({type:"summary-group",summaries:[...a],groupKey:r}),a=[]}};for(const s of f)if(s.type==="text")u(!0),e+=s.text||"";else if(s.type==="data-summary")e.trim()&&(t.push({type:"text",text:e}),e=""),a.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"agent_initializing":break;case"completion":{const{type:o}=r;a.push({type:o,label:"Completed"}),u(!0);break}case"error":{const o=r.message||"Unknown error";if(console.warn("Data operation error:",o),!t.length)u(!0),d(new Error(o)),c||(t.push({type:"text",text:E.DEFAULT_ERROR_MESSAGE}),c=!0);else{const{type:g,label:v}=r;a.push({type:g,label:v})}break}default:{const{type:o,label:g}=r;a.push({type:o,label:g});break}}}else if(s.type==="data-artifact")if(s.data?.type?.toLowerCase()==="citation"){const r=s.data,o=r.artifactSummary||{title:r.name};e+=` ^${o?.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)):(e.trim()&&(t.push({type:"text",text:e}),e=""),u(!0),t.push(s));return u(!i),e.trim()&&t.push({type:"text",text:e}),{processed:t,newTimings:l}},[f,i,d]);n.useEffect(()=>{if(R.current===f)return;R.current=f;const{processed:t,newTimings:e}=b();D(t),(e.size!==m.current.size||Array.from(e.entries()).some(([c,l])=>{const u=m.current.get(c);return!u||u.isCompleted!==l.isCompleted}))&&x(e)},[b,f]),n.useEffect(()=>{i||x(t=>{const e=new Map(t);let a=!1;for(const[c,l]of e.entries())l.isCompleted||(e.set(c,{...l,isCompleted:!0}),a=!0);return a?e:t})},[i]);const k=n.useCallback(()=>{const t=Date.now()-w,e=Array.from(m.current.values()).some(c=>!c.isCompleted),a=t>1e3&&!e;y(a)},[w]);n.useEffect(()=>{if(!i){y(!1);return}if(!(p.length>0)){y(!1);return}const e=setInterval(k,200);return()=>clearInterval(e)},[i,k,p.length]);const P=n.useMemo(()=>!!(!(p.length>0)&&i),[p.length,i]);return{processedParts:p,summaryTimings:h,shouldShowInitialLoading:P,shouldShowStreamDelayLoading:A}}exports.useStreamProcessor=L;
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),L=require("./use-inkeep-chat.cjs");function M(l,u,C){const[p,k]=r.useState([]),[y,x]=r.useState(new Map),[w,A]=r.useState(Date.now()),[P,d]=r.useState(!1),S=r.useRef(0),D=r.useRef(0),R=r.useRef([]),m=r.useRef(y);m.current=y;const T=r.useCallback(()=>{const t=[];let e="",o=[],i=!1;l.length>S.current&&(A(Date.now()),S.current=l.length),D.current=0;const c=new Map,a=(n=!1)=>{if(o.length>0){const s=`group-${D.current++}`,h=m.current.get(s);h?c.set(s,{...h,isCompleted:n}):c.set(s,{isCompleted:n}),t.push({type:"summary-group",summaries:[...o],groupKey:s}),o=[]}};for(const n of l)if(n.type==="text")a(!0),e+=n.text||"";else if(n.type==="data-summary")e.trim()&&(t.push({type:"text",text:e}),e=""),o.push(n.data);else if(n.type==="data-operation"){e.trim()&&(t.push({type:"text",text:e}),e="");const s=n.data;if(s?.type){if((s.type==="tool_call"||s.type==="tool_result")&&s.details?.data?.inDelegatedAgent===!1)continue;switch(s.type){case"agent_initializing":break;case"completion":{const{type:f}=s;o.push({type:f,label:"Completed"}),a(!0);break}case"error":{const f=s.message||"Unknown error";if(console.warn("Data operation error:",f),!t.length)a(!0),C(new Error(f)),i||(t.push({type:"text",text:L.DEFAULT_ERROR_MESSAGE}),i=!0);else{const{type:g,label:E}=s;o.push({type:g,label:E})}break}default:{const{type:f,label:g}=s;o.push({type:f,label:g});break}}}}else if(n.type==="data-artifact")if(n.data?.type?.toLowerCase()==="citation"){const s=n.data,h=s.artifactSummary||{title:s.name};e+=` ^${h?.title||s.name}^`}else e.trim()&&(t.push({type:"text",text:e}),e=""),t.push(n);else n.type==="data-component"?(e.trim()&&(t.push({type:"text",text:e}),e=""),a(!0),t.push(n)):(e.trim()&&(t.push({type:"text",text:e}),e=""),a(!0),t.push(n));return a(!u),e.trim()&&t.push({type:"text",text:e}),{processed:t,newTimings:c}},[l,u,C]);r.useEffect(()=>{if(R.current===l)return;R.current=l;const{processed:t,newTimings:e}=T();k(t),(e.size!==m.current.size||Array.from(e.entries()).some(([i,c])=>{const a=m.current.get(i);return!a||a.isCompleted!==c.isCompleted}))&&x(e)},[T,l]),r.useEffect(()=>{u||x(t=>{const e=new Map(t);let o=!1;for(const[i,c]of e.entries())c.isCompleted||(e.set(i,{...c,isCompleted:!0}),o=!0);return o?e:t})},[u]);const b=r.useCallback(()=>{const t=Date.now()-w,e=Array.from(m.current.values()).some(i=>!i.isCompleted),o=t>1e3&&!e;d(o)},[w]);r.useEffect(()=>{if(!u){d(!1);return}if(!(p.length>0)){d(!1);return}const e=setInterval(b,200);return()=>clearInterval(e)},[u,b,p.length]);const v=r.useMemo(()=>!!(!(p.length>0)&&u),[p.length,u]);return{processedParts:p,summaryTimings:y,shouldShowInitialLoading:v,shouldShowStreamDelayLoading:P}}exports.useStreamProcessor=M;
@@ -1,101 +1,104 @@
1
1
  "use client";
2
- import { useState as m, useRef as h, useCallback as L, useEffect as x, useMemo as z } from "react";
2
+ import { useState as h, useRef as y, useCallback as R, useEffect as w, useMemo as z } from "react";
3
3
  import { DEFAULT_ERROR_MESSAGE as G } from "./use-inkeep-chat.js";
4
- function F(l, i, w) {
5
- const [p, R] = m([]), [y, C] = m(/* @__PURE__ */ new Map()), [D, v] = m(Date.now()), [M, g] = m(!1), S = h(0), A = h(0), T = h([]), f = h(y);
6
- f.current = y;
7
- const b = L(() => {
8
- const e = [];
9
- let t = "", n = [], u = !1;
10
- l.length > S.current && (v(Date.now()), S.current = l.length), A.current = 0;
11
- const c = /* @__PURE__ */ new Map(), a = (s = !1) => {
12
- if (n.length > 0) {
13
- const r = `group-${A.current++}`, o = f.current.get(r);
14
- o ? c.set(r, {
15
- ...o,
16
- isCompleted: s
17
- }) : c.set(r, {
18
- isCompleted: s
19
- }), e.push({
4
+ function K(c, a, C) {
5
+ const [p, v] = h([]), [d, D] = h(/* @__PURE__ */ new Map()), [T, M] = h(Date.now()), [P, g] = h(!1), A = y(0), S = y(0), b = y([]), f = y(d);
6
+ f.current = d;
7
+ const k = R(() => {
8
+ const t = [];
9
+ let e = "", r = [], i = !1;
10
+ c.length > A.current && (M(Date.now()), A.current = c.length), S.current = 0;
11
+ const u = /* @__PURE__ */ new Map(), o = (n = !1) => {
12
+ if (r.length > 0) {
13
+ const s = `group-${S.current++}`, m = f.current.get(s);
14
+ m ? u.set(s, {
15
+ ...m,
16
+ isCompleted: n
17
+ }) : u.set(s, {
18
+ isCompleted: n
19
+ }), t.push({
20
20
  type: "summary-group",
21
- summaries: [...n],
22
- groupKey: r
23
- }), n = [];
21
+ summaries: [...r],
22
+ groupKey: s
23
+ }), r = [];
24
24
  }
25
25
  };
26
- for (const s of l)
27
- if (s.type === "text")
28
- a(!0), t += s.text || "";
29
- else if (s.type === "data-summary")
30
- t.trim() && (e.push({ type: "text", text: t }), t = ""), n.push(s.data);
31
- else if (s.type === "data-operation") {
32
- t.trim() && (e.push({ type: "text", text: t }), t = "");
33
- const r = s.data;
34
- if (r?.type)
35
- switch (r.type) {
26
+ for (const n of c)
27
+ if (n.type === "text")
28
+ o(!0), e += n.text || "";
29
+ else if (n.type === "data-summary")
30
+ e.trim() && (t.push({ type: "text", text: e }), e = ""), r.push(n.data);
31
+ else if (n.type === "data-operation") {
32
+ e.trim() && (t.push({ type: "text", text: e }), e = "");
33
+ const s = n.data;
34
+ if (s?.type) {
35
+ if ((s.type === "tool_call" || s.type === "tool_result") && s.details?.data?.inDelegatedAgent === !1)
36
+ continue;
37
+ switch (s.type) {
36
38
  case "agent_initializing":
37
39
  break;
38
40
  case "completion": {
39
- const { type: o } = r;
40
- n.push({ type: o, label: "Completed" }), a(!0);
41
+ const { type: l } = s;
42
+ r.push({ type: l, label: "Completed" }), o(!0);
41
43
  break;
42
44
  }
43
45
  case "error": {
44
- const o = r.message || "Unknown error";
45
- if (console.warn("Data operation error:", o), !e.length)
46
- a(!0), w(new Error(o)), u || (e.push({ type: "text", text: G }), u = !0);
46
+ const l = s.message || "Unknown error";
47
+ if (console.warn("Data operation error:", l), !t.length)
48
+ o(!0), C(new Error(l)), i || (t.push({ type: "text", text: G }), i = !0);
47
49
  else {
48
- const { type: d, label: E } = r;
49
- n.push({ type: d, label: E });
50
+ const { type: x, label: _ } = s;
51
+ r.push({ type: x, label: _ });
50
52
  }
51
53
  break;
52
54
  }
53
55
  default: {
54
- const { type: o, label: d } = r;
55
- n.push({ type: o, label: d });
56
+ const { type: l, label: x } = s;
57
+ r.push({ type: l, label: x });
56
58
  break;
57
59
  }
58
60
  }
59
- } else if (s.type === "data-artifact")
60
- if (s.data?.type?.toLowerCase() === "citation") {
61
- const r = s.data, o = r.artifactSummary || {
62
- title: r.name
61
+ }
62
+ } else if (n.type === "data-artifact")
63
+ if (n.data?.type?.toLowerCase() === "citation") {
64
+ const s = n.data, m = s.artifactSummary || {
65
+ title: s.name
63
66
  };
64
- t += ` ^${o?.title || r.name}^`;
67
+ e += ` ^${m?.title || s.name}^`;
65
68
  } else
66
- t.trim() && (e.push({ type: "text", text: t }), t = ""), e.push(s);
67
- else s.type === "data-component" ? (t.trim() && (e.push({ type: "text", text: t }), t = ""), a(!0), e.push(s)) : (t.trim() && (e.push({ type: "text", text: t }), t = ""), a(!0), e.push(s));
68
- return a(!i), t.trim() && e.push({ type: "text", text: t }), { processed: e, newTimings: c };
69
- }, [l, i, w]);
70
- x(() => {
71
- if (T.current === l)
69
+ e.trim() && (t.push({ type: "text", text: e }), e = ""), t.push(n);
70
+ else n.type === "data-component" ? (e.trim() && (t.push({ type: "text", text: e }), e = ""), o(!0), t.push(n)) : (e.trim() && (t.push({ type: "text", text: e }), e = ""), o(!0), t.push(n));
71
+ return o(!a), e.trim() && t.push({ type: "text", text: e }), { processed: t, newTimings: u };
72
+ }, [c, a, C]);
73
+ w(() => {
74
+ if (b.current === c)
72
75
  return;
73
- T.current = l;
74
- const { processed: e, newTimings: t } = b();
75
- R(e), (t.size !== f.current.size || Array.from(t.entries()).some(([u, c]) => {
76
- const a = f.current.get(u);
77
- return !a || a.isCompleted !== c.isCompleted;
78
- })) && C(t);
79
- }, [b, l]), x(() => {
80
- i || C((e) => {
81
- const t = new Map(e);
82
- let n = !1;
83
- for (const [u, c] of t.entries())
84
- c.isCompleted || (t.set(u, {
85
- ...c,
76
+ b.current = c;
77
+ const { processed: t, newTimings: e } = k();
78
+ v(t), (e.size !== f.current.size || Array.from(e.entries()).some(([i, u]) => {
79
+ const o = f.current.get(i);
80
+ return !o || o.isCompleted !== u.isCompleted;
81
+ })) && D(e);
82
+ }, [k, c]), w(() => {
83
+ a || D((t) => {
84
+ const e = new Map(t);
85
+ let r = !1;
86
+ for (const [i, u] of e.entries())
87
+ u.isCompleted || (e.set(i, {
88
+ ...u,
86
89
  isCompleted: !0
87
- }), n = !0);
88
- return n ? t : e;
90
+ }), r = !0);
91
+ return r ? e : t;
89
92
  });
90
- }, [i]);
91
- const k = L(() => {
92
- const e = Date.now() - D, t = Array.from(f.current.values()).some(
93
- (u) => !u.isCompleted
94
- ), n = e > 1e3 && !t;
95
- g(n);
96
- }, [D]);
97
- x(() => {
98
- if (!i) {
93
+ }, [a]);
94
+ const L = R(() => {
95
+ const t = Date.now() - T, e = Array.from(f.current.values()).some(
96
+ (i) => !i.isCompleted
97
+ ), r = t > 1e3 && !e;
98
+ g(r);
99
+ }, [T]);
100
+ w(() => {
101
+ if (!a) {
99
102
  g(!1);
100
103
  return;
101
104
  }
@@ -103,17 +106,17 @@ function F(l, i, w) {
103
106
  g(!1);
104
107
  return;
105
108
  }
106
- const t = setInterval(k, 200);
107
- return () => clearInterval(t);
108
- }, [i, k, p.length]);
109
- const P = z(() => !!(!(p.length > 0) && i), [p.length, i]);
109
+ const e = setInterval(L, 200);
110
+ return () => clearInterval(e);
111
+ }, [a, L, p.length]);
112
+ const E = z(() => !!(!(p.length > 0) && a), [p.length, a]);
110
113
  return {
111
114
  processedParts: p,
112
- summaryTimings: y,
113
- shouldShowInitialLoading: P,
114
- shouldShowStreamDelayLoading: M
115
+ summaryTimings: d,
116
+ shouldShowInitialLoading: E,
117
+ shouldShowStreamDelayLoading: P
115
118
  };
116
119
  }
117
120
  export {
118
- F as useStreamProcessor
121
+ K as useStreamProcessor
119
122
  };