@inkeep/agents-ui 0.15.11 → 0.15.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.
Files changed (46) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +171 -169
  3. package/dist/primitives/atoms/combobox.cjs +1 -0
  4. package/dist/primitives/atoms/combobox.js +275 -0
  5. package/dist/primitives/components/embedded-chat/use-stream-processor.cjs +1 -1
  6. package/dist/primitives/components/embedded-chat/use-stream-processor.js +74 -87
  7. package/dist/primitives/components/embedded-chat.cjs +4 -4
  8. package/dist/primitives/components/embedded-chat.d.ts +22 -1
  9. package/dist/primitives/components/embedded-chat.js +1249 -1137
  10. package/dist/primitives/hooks/use-simple-scroll.cjs +1 -1
  11. package/dist/primitives/hooks/use-simple-scroll.d.ts +12 -1
  12. package/dist/primitives/hooks/use-simple-scroll.js +45 -12
  13. package/dist/primitives/providers/base-events-provider.cjs +1 -1
  14. package/dist/primitives/providers/base-events-provider.js +1 -1
  15. package/dist/primitives/utils/component-ids.cjs +1 -1
  16. package/dist/primitives/utils/component-ids.d.ts +24 -0
  17. package/dist/primitives/utils/component-ids.js +12 -0
  18. package/dist/primitives/utils/form.cjs +1 -1
  19. package/dist/primitives/utils/form.d.ts +1 -1
  20. package/dist/primitives/utils/form.js +3 -1
  21. package/dist/react/chat-button-modal.cjs +1 -0
  22. package/dist/react/chat-button-modal.d.ts +22 -0
  23. package/dist/react/chat-button-modal.js +41 -0
  24. package/dist/react/embedded-chat.cjs +1 -1
  25. package/dist/react/embedded-chat.js +210 -191
  26. package/dist/react/index.cjs +1 -1
  27. package/dist/react/index.d.ts +1 -0
  28. package/dist/react/index.js +171 -169
  29. package/dist/styled/components/embedded-chat.cjs +1 -1
  30. package/dist/styled/components/embedded-chat.d.ts +16 -1
  31. package/dist/styled/components/embedded-chat.js +686 -568
  32. package/dist/styled/components/message.cjs +1 -1
  33. package/dist/styled/components/message.js +191 -183
  34. package/dist/styled/components/ui/recipes/combobox.cjs +1 -0
  35. package/dist/styled/components/ui/recipes/combobox.d.ts +4 -0
  36. package/dist/styled/components/ui/recipes/combobox.js +57 -0
  37. package/dist/styled/components/ui/recipes/index.cjs +1 -1
  38. package/dist/styled/components/ui/recipes/index.d.ts +1 -0
  39. package/dist/styled/components/ui/recipes/index.js +29 -27
  40. package/dist/styled/components/ui/recipes/modal.d.ts +1 -1
  41. package/dist/styled/components/ui/recipes/scrollable.d.ts +1 -1
  42. package/dist/styled/components/ui/recipes/select.d.ts +1 -1
  43. package/dist/styled/inkeep.css.cjs +182 -2
  44. package/dist/styled/inkeep.css.js +182 -2
  45. package/dist/types/config/settings/form.d.ts +9 -1
  46. package/package.json +6 -5
@@ -0,0 +1,275 @@
1
+ "use client";
2
+ import { jsx as c, Fragment as O, jsxs as M } from "react/jsx-runtime";
3
+ import * as f from "@zag-js/combobox";
4
+ import { useMachine as j, normalizeProps as B } from "@zag-js/react";
5
+ import * as r from "react";
6
+ import { useId as q } from "react";
7
+ import { BuiltInIconRenderer as I } from "./icons/built-in-icon-renderer.js";
8
+ import { useShadow as z } from "./shadow/context.js";
9
+ const A = r.forwardRef((o, a) => {
10
+ const {
11
+ children: t,
12
+ defaultValue: e = [],
13
+ items: n,
14
+ multiple: s = !1,
15
+ placeholder: l,
16
+ name: b,
17
+ disabled: P,
18
+ required: v,
19
+ id: w,
20
+ onValueChange: R
21
+ } = o, y = q(), N = w ?? y, T = z(), [p, h] = r.useState(n), L = r.useMemo(
22
+ () => f.collection({
23
+ items: p,
24
+ itemToValue: (i) => i.value,
25
+ itemToString: (i) => i.label
26
+ }),
27
+ [p]
28
+ ), V = j(f.machine, {
29
+ id: N,
30
+ collection: L,
31
+ defaultValue: e,
32
+ multiple: s,
33
+ placeholder: l,
34
+ name: b,
35
+ disabled: P,
36
+ required: v,
37
+ openOnClick: !0,
38
+ getRootNode: () => T?.shadowHost?.shadowRoot ?? document,
39
+ selectionBehavior: s ? "clear" : "replace",
40
+ onOpenChange(i) {
41
+ i.open || h(n);
42
+ },
43
+ onInputValueChange(i) {
44
+ const g = i.inputValue.trim() === "" ? n : n.filter(
45
+ (E) => E.label.toLowerCase().includes(i.inputValue.toLowerCase())
46
+ );
47
+ h(g.length > 0 ? g : []);
48
+ },
49
+ onValueChange(i) {
50
+ R?.(i);
51
+ }
52
+ }), u = f.connect(
53
+ V,
54
+ B
55
+ ), S = r.useMemo(() => ({ api: u, options: p }), [u, p]), k = u.getRootProps();
56
+ return /* @__PURE__ */ c("div", { "data-scope": "combobox", "data-part": "root", ...k, children: /* @__PURE__ */ c(C.Provider, { value: S, children: t }) });
57
+ });
58
+ A.displayName = "ComboboxRoot";
59
+ const D = r.forwardRef((o, a) => {
60
+ const { children: t, ...e } = o, n = d(), s = n.getControlProps();
61
+ return /* @__PURE__ */ c(
62
+ "div",
63
+ {
64
+ "data-scope": "combobox",
65
+ "data-part": "control",
66
+ "data-state": n.open ? "open" : "closed",
67
+ "data-disabled": n.disabled ? "" : void 0,
68
+ "data-focus": n.focused ? "" : void 0,
69
+ ...s,
70
+ ref: m(a, s.ref),
71
+ ...e,
72
+ children: t
73
+ }
74
+ );
75
+ });
76
+ D.displayName = "ComboboxControl";
77
+ function m(...o) {
78
+ return (a) => {
79
+ o.forEach((t) => {
80
+ typeof t == "function" ? t(a) : t && (t.current = a);
81
+ });
82
+ };
83
+ }
84
+ const F = r.forwardRef((o, a) => {
85
+ const t = d(), e = t.getInputProps();
86
+ return /* @__PURE__ */ c(
87
+ "input",
88
+ {
89
+ "data-scope": "combobox",
90
+ "data-part": "input",
91
+ "data-state": t.open ? "open" : "closed",
92
+ ...e,
93
+ ...o,
94
+ ref: m(a, e.ref)
95
+ }
96
+ );
97
+ });
98
+ F.displayName = "ComboboxInput";
99
+ const H = r.forwardRef((o, a) => {
100
+ const t = d(), e = t.getTriggerProps();
101
+ return /* @__PURE__ */ c(
102
+ "button",
103
+ {
104
+ type: "button",
105
+ "data-scope": "combobox",
106
+ "data-part": "trigger",
107
+ "data-state": t.open ? "open" : "closed",
108
+ "data-disabled": t.disabled ? "" : void 0,
109
+ ...e,
110
+ ref: m(a, e.ref),
111
+ ...o,
112
+ children: o.children ?? "▼"
113
+ }
114
+ );
115
+ });
116
+ H.displayName = "ComboboxTrigger";
117
+ const ao = r.forwardRef(
118
+ function(a, t) {
119
+ const e = d();
120
+ return /* @__PURE__ */ c("div", { ref: t, ...e.getPositionerProps(), ...a });
121
+ }
122
+ ), _ = r.forwardRef((o, a) => {
123
+ const t = d(), e = t.getContentProps();
124
+ return /* @__PURE__ */ c(
125
+ "div",
126
+ {
127
+ "data-scope": "combobox",
128
+ "data-part": "content",
129
+ "data-state": t.open ? "open" : "closed",
130
+ ...e,
131
+ ref: m(a, e.ref),
132
+ ...o,
133
+ children: o.children
134
+ }
135
+ );
136
+ });
137
+ _.displayName = "ComboboxContent";
138
+ const $ = r.forwardRef((o, a) => {
139
+ const e = d().getListProps();
140
+ return /* @__PURE__ */ c(
141
+ "div",
142
+ {
143
+ ref: m(a, e.ref),
144
+ "data-scope": "combobox",
145
+ "data-part": "list",
146
+ ...e,
147
+ ...o,
148
+ children: o.children
149
+ }
150
+ );
151
+ });
152
+ $.displayName = "ComboboxList";
153
+ const G = ({ children: o }) => {
154
+ const a = W();
155
+ return /* @__PURE__ */ c(O, { children: o(a) });
156
+ };
157
+ G.displayName = "ComboboxListItems";
158
+ const J = r.forwardRef((o, a) => {
159
+ const { children: t = "No results found", ...e } = o;
160
+ return /* @__PURE__ */ c("div", { ref: a, "data-scope": "combobox", "data-part": "list-empty", ...e, children: t });
161
+ });
162
+ J.displayName = "ComboboxListEmpty";
163
+ const x = r.createContext(null), K = r.forwardRef((o, a) => {
164
+ const { item: t, ...e } = o, n = d(), s = n.getItemState({ item: t }), l = n.getItemProps({ item: t });
165
+ return /* @__PURE__ */ c(x.Provider, { value: t, children: /* @__PURE__ */ c(
166
+ "div",
167
+ {
168
+ ref: m(a, l.ref),
169
+ "data-scope": "combobox",
170
+ "data-part": "item",
171
+ "data-value": t.value,
172
+ "data-highlighted": s.highlighted ? "" : void 0,
173
+ "data-state": s.selected ? "checked" : "unchecked",
174
+ "data-disabled": s.disabled ? "" : void 0,
175
+ ...l,
176
+ ...e,
177
+ children: o.children
178
+ }
179
+ ) });
180
+ });
181
+ K.displayName = "ComboboxItem";
182
+ const Q = r.forwardRef((o, a) => {
183
+ const t = r.useContext(x), e = d(), n = t ? e.getItemTextProps({ item: t }) : {};
184
+ return /* @__PURE__ */ c(
185
+ "span",
186
+ {
187
+ ref: m(a, n.ref),
188
+ "data-scope": "combobox",
189
+ "data-part": "item-text",
190
+ ...n,
191
+ ...o
192
+ }
193
+ );
194
+ });
195
+ Q.displayName = "ComboboxItemText";
196
+ const U = r.forwardRef(
197
+ (o, a) => {
198
+ const { children: t, ...e } = o, n = r.useContext(x), s = d(), l = n ? s.getItemState({ item: n }) : { selected: !1 }, b = n ? s.getItemIndicatorProps({ item: n }) : {};
199
+ return l.selected ? /* @__PURE__ */ c(
200
+ "span",
201
+ {
202
+ ref: m(a, b.ref),
203
+ "data-scope": "combobox",
204
+ "data-part": "item-indicator",
205
+ "data-state": "checked",
206
+ "aria-hidden": !0,
207
+ ...b,
208
+ ...e,
209
+ children: t ?? /* @__PURE__ */ c(I, { iconSettings: { builtIn: "LuCheck" } })
210
+ }
211
+ ) : null;
212
+ }
213
+ );
214
+ U.displayName = "ComboboxItemIndicator";
215
+ const C = r.createContext(
216
+ null
217
+ );
218
+ function d() {
219
+ const o = r.useContext(C);
220
+ if (!o) throw new Error("Combobox components must be used within ComboboxRoot");
221
+ return o.api;
222
+ }
223
+ function W() {
224
+ const o = r.useContext(C);
225
+ if (!o) throw new Error("Combobox components must be used within ComboboxRoot");
226
+ return o.options;
227
+ }
228
+ const X = r.forwardRef(
229
+ (o, a) => {
230
+ const t = d(), e = t.selectedItems ?? [], n = t.clearValue;
231
+ return e.length === 0 ? null : /* @__PURE__ */ c(
232
+ "div",
233
+ {
234
+ ref: a,
235
+ "data-scope": "combobox",
236
+ "data-part": "selected-tags",
237
+ className: o.className,
238
+ style: o.style,
239
+ children: e.map((s) => /* @__PURE__ */ M("span", { "data-scope": "combobox", "data-part": "tag", children: [
240
+ o.renderTag ? o.renderTag(s) : s.label,
241
+ /* @__PURE__ */ c(
242
+ "button",
243
+ {
244
+ type: "button",
245
+ "data-part": "tag-clear",
246
+ "aria-label": `Remove ${s.label}`,
247
+ onClick: (l) => {
248
+ l.preventDefault(), l.stopPropagation(), n?.(s.value);
249
+ },
250
+ children: /* @__PURE__ */ c(I, { iconSettings: { builtIn: "IoCloseOutline" } })
251
+ }
252
+ )
253
+ ] }, s.value))
254
+ }
255
+ );
256
+ }
257
+ );
258
+ X.displayName = "ComboboxSelectedTags";
259
+ export {
260
+ _ as ComboboxContent,
261
+ D as ComboboxControl,
262
+ F as ComboboxInput,
263
+ K as ComboboxItem,
264
+ U as ComboboxItemIndicator,
265
+ Q as ComboboxItemText,
266
+ $ as ComboboxList,
267
+ J as ComboboxListEmpty,
268
+ G as ComboboxListItems,
269
+ ao as ComboboxPositioner,
270
+ A as ComboboxRoot,
271
+ X as ComboboxSelectedTags,
272
+ H as ComboboxTrigger,
273
+ d as useComboboxApi,
274
+ W as useComboboxOptions
275
+ };
@@ -1 +1 @@
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
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),A=require("./use-inkeep-chat.cjs");function E(m,u,S){const[T,d]=n.useState(!1),x=n.useRef(0),C=n.useRef(0),w=n.useRef(Date.now()),c=n.useRef(new Map),h=n.useRef(null),{processedParts:p,summaryTimings:b}=n.useMemo(()=>{const s=[];let e="",o=[],y=!1;m.length>x.current&&(w.current=Date.now(),x.current=m.length),C.current=0;const i=new Map,l=(r=!1)=>{if(o.length>0){const t=`group-${C.current++}`,a=c.current.get(t);a?i.set(t,{...a,isCompleted:r}):i.set(t,{isCompleted:r}),s.push({type:"summary-group",summaries:[...o],groupKey:t}),o=[]}};for(const r of m)if(r.type==="text")l(!0),e+=r.text||"";else if(r.type==="data-summary")e.trim()&&(s.push({type:"text",text:e}),e=""),o.push(r.data);else if(r.type==="data-operation"){e.trim()&&(s.push({type:"text",text:e}),e="");const t=r.data;if(t?.type){if((t.type==="tool_call"||t.type==="tool_result")&&t.details?.data?.inDelegatedAgent===!1)continue;switch(t.type){case"agent_initializing":break;case"completion":{const{type:f}=t;o.push({type:f,label:"Completed"}),l(!0);break}case"error":{const f=t.message||"Unknown error";if(console.warn("Data operation error:",f),!s.length)l(!0),h.current=f,y||(s.push({type:"text",text:A.DEFAULT_ERROR_MESSAGE}),y=!0);else{const{type:g,label:v}=t;o.push({type:g,label:v})}break}default:{const{type:f,label:g}=t;o.push({type:f,label:g});break}}}}else if(r.type==="data-artifact")if(r.data?.type?.toLowerCase()==="citation"){const t=r.data,a=t.artifactSummary||{title:t.name};e+=` ^${a?.title||t.name}^`}else e.trim()&&(s.push({type:"text",text:e}),e=""),s.push(r);else r.type==="data-component"?(e.trim()&&(s.push({type:"text",text:e}),e=""),l(!0),s.push(r)):(e.trim()&&(s.push({type:"text",text:e}),e=""),l(!0),s.push(r));if(l(!u),e.trim()&&s.push({type:"text",text:e}),!u)for(const[r,t]of i.entries())t.isCompleted||i.set(r,{...t,isCompleted:!0});const D=i.size!==c.current.size||Array.from(i.entries()).some(([r,t])=>{const a=c.current.get(r);return!a||a.isCompleted!==t.isCompleted})?i:c.current;return c.current=D,{processedParts:s,summaryTimings:D}},[m,u]);n.useEffect(()=>{h.current&&(S(new Error(h.current)),h.current=null)});const R=n.useCallback(()=>{const s=Date.now()-w.current,e=Array.from(c.current.values()).some(y=>!y.isCompleted),o=s>1e3&&!e;d(o)},[]);n.useEffect(()=>{if(!u){d(!1);return}if(!(p.length>0)){d(!1);return}const e=setInterval(R,200);return()=>clearInterval(e)},[u,R,p.length]);const k=n.useMemo(()=>!!(!(p.length>0)&&u),[p.length,u]);return{processedParts:p,summaryTimings:b,shouldShowInitialLoading:k,shouldShowStreamDelayLoading:T}}exports.useStreamProcessor=E;
@@ -1,122 +1,109 @@
1
1
  "use client";
2
- import { useState as h, useRef as y, useCallback as R, useEffect as w, useMemo as z } from "react";
3
- import { DEFAULT_ERROR_MESSAGE as G } from "./use-inkeep-chat.js";
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({
2
+ import { useState as L, useRef as f, useMemo as S, useEffect as k, useCallback as M } from "react";
3
+ import { DEFAULT_ERROR_MESSAGE as _ } from "./use-inkeep-chat.js";
4
+ function I(m, a, A) {
5
+ const [R, d] = L(!1), x = f(0), C = f(0), w = f(Date.now()), u = f(/* @__PURE__ */ new Map()), h = f(null), { processedParts: p, summaryTimings: b } = S(() => {
6
+ const n = [];
7
+ let e = "", s = [], y = !1;
8
+ m.length > x.current && (w.current = Date.now(), x.current = m.length), C.current = 0;
9
+ const i = /* @__PURE__ */ new Map(), l = (r = !1) => {
10
+ if (s.length > 0) {
11
+ const t = `group-${C.current++}`, o = u.current.get(t);
12
+ o ? i.set(t, {
13
+ ...o,
14
+ isCompleted: r
15
+ }) : i.set(t, {
16
+ isCompleted: r
17
+ }), n.push({
20
18
  type: "summary-group",
21
- summaries: [...r],
22
- groupKey: s
23
- }), r = [];
19
+ summaries: [...s],
20
+ groupKey: t
21
+ }), s = [];
24
22
  }
25
23
  };
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)
24
+ for (const r of m)
25
+ if (r.type === "text")
26
+ l(!0), e += r.text || "";
27
+ else if (r.type === "data-summary")
28
+ e.trim() && (n.push({ type: "text", text: e }), e = ""), s.push(r.data);
29
+ else if (r.type === "data-operation") {
30
+ e.trim() && (n.push({ type: "text", text: e }), e = "");
31
+ const t = r.data;
32
+ if (t?.type) {
33
+ if ((t.type === "tool_call" || t.type === "tool_result") && t.details?.data?.inDelegatedAgent === !1)
36
34
  continue;
37
- switch (s.type) {
35
+ switch (t.type) {
38
36
  case "agent_initializing":
39
37
  break;
40
38
  case "completion": {
41
- const { type: l } = s;
42
- r.push({ type: l, label: "Completed" }), o(!0);
39
+ const { type: c } = t;
40
+ s.push({ type: c, label: "Completed" }), l(!0);
43
41
  break;
44
42
  }
45
43
  case "error": {
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);
44
+ const c = t.message || "Unknown error";
45
+ if (console.warn("Data operation error:", c), !n.length)
46
+ l(!0), h.current = c, y || (n.push({ type: "text", text: _ }), y = !0);
49
47
  else {
50
- const { type: x, label: _ } = s;
51
- r.push({ type: x, label: _ });
48
+ const { type: g, label: E } = t;
49
+ s.push({ type: g, label: E });
52
50
  }
53
51
  break;
54
52
  }
55
53
  default: {
56
- const { type: l, label: x } = s;
57
- r.push({ type: l, label: x });
54
+ const { type: c, label: g } = t;
55
+ s.push({ type: c, label: g });
58
56
  break;
59
57
  }
60
58
  }
61
59
  }
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
60
+ } else if (r.type === "data-artifact")
61
+ if (r.data?.type?.toLowerCase() === "citation") {
62
+ const t = r.data, o = t.artifactSummary || {
63
+ title: t.name
66
64
  };
67
- e += ` ^${m?.title || s.name}^`;
65
+ e += ` ^${o?.title || t.name}^`;
68
66
  } else
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)
75
- return;
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,
89
- isCompleted: !0
90
- }), r = !0);
91
- return r ? e : t;
92
- });
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(() => {
67
+ e.trim() && (n.push({ type: "text", text: e }), e = ""), n.push(r);
68
+ else r.type === "data-component" ? (e.trim() && (n.push({ type: "text", text: e }), e = ""), l(!0), n.push(r)) : (e.trim() && (n.push({ type: "text", text: e }), e = ""), l(!0), n.push(r));
69
+ if (l(!a), e.trim() && n.push({ type: "text", text: e }), !a)
70
+ for (const [r, t] of i.entries())
71
+ t.isCompleted || i.set(r, { ...t, isCompleted: !0 });
72
+ const T = i.size !== u.current.size || Array.from(i.entries()).some(([r, t]) => {
73
+ const o = u.current.get(r);
74
+ return !o || o.isCompleted !== t.isCompleted;
75
+ }) ? i : u.current;
76
+ return u.current = T, { processedParts: n, summaryTimings: T };
77
+ }, [m, a]);
78
+ k(() => {
79
+ h.current && (A(new Error(h.current)), h.current = null);
80
+ });
81
+ const D = M(() => {
82
+ const n = Date.now() - w.current, e = Array.from(u.current.values()).some(
83
+ (y) => !y.isCompleted
84
+ ), s = n > 1e3 && !e;
85
+ d(s);
86
+ }, []);
87
+ k(() => {
101
88
  if (!a) {
102
- g(!1);
89
+ d(!1);
103
90
  return;
104
91
  }
105
92
  if (!(p.length > 0)) {
106
- g(!1);
93
+ d(!1);
107
94
  return;
108
95
  }
109
- const e = setInterval(L, 200);
96
+ const e = setInterval(D, 200);
110
97
  return () => clearInterval(e);
111
- }, [a, L, p.length]);
112
- const E = z(() => !!(!(p.length > 0) && a), [p.length, a]);
98
+ }, [a, D, p.length]);
99
+ const v = S(() => !!(!(p.length > 0) && a), [p.length, a]);
113
100
  return {
114
101
  processedParts: p,
115
- summaryTimings: d,
116
- shouldShowInitialLoading: E,
117
- shouldShowStreamDelayLoading: P
102
+ summaryTimings: b,
103
+ shouldShowInitialLoading: v,
104
+ shouldShowStreamDelayLoading: R
118
105
  };
119
106
  }
120
107
  export {
121
- K as useStreamProcessor
108
+ I as useStreamProcessor
122
109
  };