@kanzo-tech/ai 0.18.0 → 0.19.0

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/assist.d.ts CHANGED
@@ -23,6 +23,8 @@ export interface AssistTranslations {
23
23
  thinking: string;
24
24
  /** When the model had nothing to offer. */
25
25
  empty: string;
26
+ /** When asking failed and what was thrown carries no message of its own. */
27
+ failed: string;
26
28
  /** A candidate's ✕, given the candidate's text. */
27
29
  dismiss: (text: string) => string;
28
30
  }
@@ -36,6 +38,11 @@ export interface AssistProviderProps {
36
38
  context?: string | (() => string | undefined);
37
39
  /** Each proposal's life — shown, accepted, partly accepted, rejected, ignored. */
38
40
  onEvent?: (event: AssistEvent) => void;
41
+ /**
42
+ * Called with what the model's stream threw, whole, when a field's ask fails — including an
43
+ * `AiError` coded `ai/silent` when it sent nothing for 30 s. The field also says so under itself.
44
+ */
45
+ onFailure?: (error: unknown) => void;
39
46
  translations?: Partial<AssistTranslations>;
40
47
  children: React.ReactNode;
41
48
  }
@@ -1 +1 @@
1
- {"version":3,"file":"assist.d.ts","sourceRoot":"","sources":["../src/assist.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGrD,OAAO,EACL,KAAK,WAAW,EAKjB,MAAM,aAAa,CAAC;AAKrB,0GAA0G;AAC1G,MAAM,WAAW,kBAAkB;IACjC,qBAAqB;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,MAAM,EAAE,MAAM,CAAC;IACf,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAC;IACf,kDAAkD;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,4BAA4B;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,OAAO,EAAE,MAAM,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,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE;IACtD;;;OAGG;IACH,KAAK,EAAE,CAAC,CAAC;IACT,aAAa,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAClC,qFAAqF;IACrF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iGAAiG;IACjG,QAAQ,EAAE,KAAK,CAAC,YAAY,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,qBAOxE"}
package/dist/assist.js CHANGED
@@ -1,13 +1,13 @@
1
1
  "use client";
2
- import { jsx as i, jsxs as E, Fragment as ge } from "react/jsx-runtime";
2
+ import { jsx as c, jsxs as E, Fragment as pe } from "react/jsx-runtime";
3
3
  import { ark as R } from "@ark-ui/react/factory";
4
- import { Undo2Icon as pe, XIcon as ve } from "lucide-react";
4
+ import { Undo2Icon as ye, XIcon as ve } from "lucide-react";
5
5
  import * as l from "react";
6
- import { cn as M, Kbd as j, ButtonGroup as ye, Suggestion as be, Button as xe, Spinner as ke, Suggestions as Ee } from "@kanzo-tech/ui";
6
+ import { cn as M, ButtonGroup as be, Suggestion as xe, Button as ke, Spinner as Ee, Suggestions as Se, Kbd as j } from "@kanzo-tech/ui";
7
7
  import { AiMark as U } from "./ai-mark.js";
8
- import { useContinuation as Se, useCandidates as Q, MIN_CONTINUE_LENGTH as Ce } from "./engine.js";
9
- import { continuation as Re, candidates as Y } from "./proposals.js";
10
- const we = {
8
+ import { useCandidates as Y, useContinuation as Ce, MIN_CONTINUE_LENGTH as Re } from "./engine.js";
9
+ import { candidates as Z, continuation as we } from "./proposals.js";
10
+ const Ne = {
11
11
  assist: "AI assist",
12
12
  accept: "Accept suggestion",
13
13
  others: "Suggest different values",
@@ -18,31 +18,33 @@ const we = {
18
18
  announcement: "Suggestion ready. Press Tab to accept, Escape to dismiss.",
19
19
  thinking: "Thinking…",
20
20
  empty: "Nothing to suggest.",
21
+ failed: "Couldn’t suggest anything.",
21
22
  dismiss: (n) => `Dismiss ${n}`
22
- }, Z = l.createContext(null);
23
- function je(n) {
24
- const { model: t, context: s, onEvent: r, translations: c, children: d } = n, a = l.useMemo(
23
+ }, ee = l.createContext(null);
24
+ function Ue(n) {
25
+ const { model: t, context: s, onEvent: r, onFailure: o, translations: d, children: a } = n, f = l.useMemo(
25
26
  () => ({
26
27
  model: t,
27
28
  context: typeof s == "function" ? s : () => s,
28
29
  onEvent: r,
29
- t: { ...we, ...c }
30
+ onFailure: o,
31
+ t: { ...Ne, ...d }
30
32
  }),
31
- [s, t, r, c]
33
+ [s, t, r, o, d]
32
34
  );
33
- return /* @__PURE__ */ i(Z.Provider, { value: a, children: d });
35
+ return /* @__PURE__ */ c(ee.Provider, { value: f, children: a });
34
36
  }
35
- const J = (n) => (n ?? "").split(/\s+/).map((t) => {
37
+ const Q = (n) => (n ?? "").split(/\s+/).map((t) => {
36
38
  var s, r;
37
39
  return t ? (r = (s = document.getElementById(t)) == null ? void 0 : s.textContent) == null ? void 0 : r.trim() : "";
38
40
  }).filter(Boolean).join(" ");
39
- function G(n, t, s) {
40
- return n ? { name: J(n.getAttribute("aria-labelledby")) || [...n.labels ?? []].map((c) => {
41
+ function q(n, t, s) {
42
+ return n ? { name: Q(n.getAttribute("aria-labelledby")) || [...n.labels ?? []].map((o) => {
41
43
  var d;
42
- return (d = c.textContent) == null ? void 0 : d.trim();
43
- }).filter(Boolean).join(" ") || n.getAttribute("aria-label") || n.getAttribute("placeholder") || "", description: J(n.getAttribute("aria-describedby")) || void 0, instructions: t, context: s } : { name: "", instructions: t, context: s };
44
+ return (d = o.textContent) == null ? void 0 : d.trim();
45
+ }).filter(Boolean).join(" ") || n.getAttribute("aria-label") || n.getAttribute("placeholder") || "", description: Q(n.getAttribute("aria-describedby")) || void 0, instructions: t, context: s } : { name: "", instructions: t, context: s };
44
46
  }
45
- const Ne = [
47
+ const Ae = [
46
48
  "fontFamily",
47
49
  "fontSize",
48
50
  "fontWeight",
@@ -59,137 +61,139 @@ const Ne = [
59
61
  "borderBottomWidth",
60
62
  "borderLeftWidth"
61
63
  ], F = (n) => Number.parseFloat(n) || 0;
62
- function q(n, t, s) {
63
- const r = n.getBoundingClientRect(), c = t.getBoundingClientRect();
64
+ function _(n, t, s) {
65
+ const r = n.getBoundingClientRect(), o = t.getBoundingClientRect();
64
66
  return {
65
- insetBlockStart: r.top - c.top,
66
- insetBlockEnd: c.bottom - r.bottom,
67
- insetInlineStart: s ? c.right - r.right : r.left - c.left,
68
- insetInlineEnd: s ? r.left - c.left : c.right - r.right
67
+ insetBlockStart: r.top - o.top,
68
+ insetBlockEnd: o.bottom - r.bottom,
69
+ insetInlineStart: s ? o.right - r.right : r.left - o.left,
70
+ insetInlineEnd: s ? r.left - o.left : o.right - r.right
69
71
  };
70
72
  }
71
- function Ae(n, t) {
72
- const s = getComputedStyle(n), r = s.direction === "rtl", c = n.offsetWidth - n.clientWidth - F(s.borderLeftWidth) - F(s.borderRightWidth), d = q(n, t, r), a = {
73
+ function Be(n, t) {
74
+ const s = getComputedStyle(n), r = s.direction === "rtl", o = n.offsetWidth - n.clientWidth - F(s.borderLeftWidth) - F(s.borderRightWidth), d = _(n, t, r), a = {
73
75
  ...d,
74
- insetInlineEnd: d.insetInlineEnd + (c > 0 ? c : 0),
76
+ insetInlineEnd: d.insetInlineEnd + (o > 0 ? o : 0),
75
77
  borderStyle: "solid",
76
78
  borderColor: "transparent"
77
79
  };
78
- for (const g of Ne) a[g] = s[g];
80
+ for (const f of Ae) a[f] = s[f];
79
81
  return { metrics: a, rtl: r };
80
82
  }
81
- const ee = "2.25rem", Be = (n) => {
83
+ const te = "2.25rem", Ie = (n) => {
82
84
  var t;
83
85
  return ((t = /^\s*\S+/.exec(n)) == null ? void 0 : t[0]) ?? "";
84
86
  }, I = (...n) => (t) => {
85
87
  for (const s of n) s == null || s(t);
86
- }, Ie = (...n) => (t) => {
88
+ }, Te = (...n) => (t) => {
87
89
  for (const s of n)
88
90
  typeof s == "function" ? s(t) : s && (s.current = t);
89
91
  };
90
- function Ue(n) {
91
- const t = l.useContext(Z);
92
+ function Ge(n) {
93
+ const t = l.useContext(ee);
92
94
  if (!t) throw new Error("<Assist> must render inside <AssistProvider>");
93
- return Array.isArray(n.value) ? /* @__PURE__ */ i(Me, { ...n, settings: t }) : /* @__PURE__ */ i(Le, { ...n, settings: t });
95
+ return Array.isArray(n.value) ? /* @__PURE__ */ c(Pe, { ...n, settings: t }) : /* @__PURE__ */ c(Ke, { ...n, settings: t });
94
96
  }
95
- const Te = (n) => (n == null ? void 0 : n.querySelector("textarea, input:not([type=hidden])")) ?? null;
96
- function te(n, t) {
97
+ const Le = (n) => (n == null ? void 0 : n.querySelector("textarea, input:not([type=hidden])")) ?? null;
98
+ function ne(n, t) {
97
99
  return l.useCallback(
98
100
  (s, r) => {
99
- var c;
100
- return (c = n.onEvent) == null ? void 0 : c.call(n, { kind: s, proposal: r, field: G(t(), void 0, void 0).name });
101
+ var o;
102
+ return (o = n.onEvent) == null ? void 0 : o.call(n, { kind: s, proposal: r, field: q(t(), void 0, void 0).name });
101
103
  },
102
104
  [t, n]
103
105
  );
104
106
  }
105
- function Le(n) {
106
- const { value: t, onValueChange: s, instructions: r, children: c, className: d, settings: a } = n, { t: g } = a, h = l.useRef(null), f = l.useRef(null), [m, C] = l.useState(!1), [w, P] = l.useState(
107
+ function Ke(n) {
108
+ const { value: t, onValueChange: s, instructions: r, children: o, className: d, settings: a } = n, { t: f } = a, h = l.useRef(null), m = l.useRef(null), [g, C] = l.useState(!1), [w, P] = l.useState(
107
109
  { metrics: {}, rtl: !1, mark: {} }
108
- ), [v, x] = l.useState(t.length), [H, O] = l.useState(!1), [N, S] = l.useState(null), u = l.useRef(null), y = l.useCallback(() => f.current, []), T = te(a, y), L = () => {
110
+ ), [y, v] = l.useState(t.length), [H, O] = l.useState(!1), [N, S] = l.useState(null), u = l.useRef(null), b = l.useCallback(() => m.current, []), T = ne(a, b), L = () => {
109
111
  var e;
110
- return G(f.current, r, (e = a.context) == null ? void 0 : e.call(a));
111
- }, p = Se({
112
- source: (e) => Re(a.model, L(), e),
112
+ return q(m.current, r, (e = a.context) == null ? void 0 : e.call(a));
113
+ }, p = Ce({
114
+ source: (e) => we(a.model, L(), e),
113
115
  onEvent: T
114
- }), k = Q({
115
- source: ({ signal: e }) => Y(a.model, L(), { value: t, existing: [t], signal: e, count: 6, list: !1 }),
116
+ }), x = Y({
117
+ source: ({ signal: e }) => Z(a.model, L(), { value: t, existing: [t], signal: e, count: 6, list: !1 }),
116
118
  existing: [t],
117
119
  onEvent: T
118
- }), b = m ? p.ghost : "";
120
+ });
121
+ G(a, p), G(a, x);
122
+ const k = g ? p.ghost : "";
119
123
  l.useLayoutEffect(() => {
120
- const e = f.current, o = h.current;
121
- if (!e || !o) return;
122
- C(e instanceof HTMLTextAreaElement), e.style.paddingInlineEnd = ee;
124
+ const e = m.current, i = h.current;
125
+ if (!e || !i) return;
126
+ C(e instanceof HTMLTextAreaElement), e.style.paddingInlineEnd = te;
123
127
  const W = () => {
124
- const X = Ae(e, o), z = q(e, o, X.rtl), he = e instanceof HTMLTextAreaElement ? { insetInlineEnd: z.insetInlineEnd + 4, insetBlockEnd: z.insetBlockEnd + 4 } : { insetInlineEnd: z.insetInlineEnd + 2, insetBlockStart: z.insetBlockStart, height: e.offsetHeight };
125
- P({ ...X, mark: he });
128
+ const J = Be(e, i), z = _(e, i, J.rtl), he = e instanceof HTMLTextAreaElement ? { insetInlineEnd: z.insetInlineEnd + 4, insetBlockEnd: z.insetBlockEnd + 4 } : { insetInlineEnd: z.insetInlineEnd + 2, insetBlockStart: z.insetBlockStart, height: e.offsetHeight };
129
+ P({ ...J, mark: he });
126
130
  };
127
131
  if (W(), typeof ResizeObserver > "u") return;
128
132
  const V = new ResizeObserver(W);
129
- return V.observe(e), V.observe(o), () => V.disconnect();
133
+ return V.observe(e), V.observe(i), () => V.disconnect();
130
134
  }, []), l.useLayoutEffect(() => {
131
- const e = f.current, o = u.current;
132
- !e || o === null || (u.current = null, e.setSelectionRange(o, o), x(o));
135
+ const e = m.current, i = u.current;
136
+ !e || i === null || (u.current = null, e.setSelectionRange(i, i), v(i));
133
137
  }, [t]);
134
138
  const K = l.useCallback(() => {
135
- const e = f.current;
139
+ const e = m.current;
136
140
  if (!e || u.current !== null) return;
137
- const o = e.selectionStart ?? e.value.length;
138
- if ((e.selectionEnd ?? o) !== o) {
141
+ const i = e.selectionStart ?? e.value.length;
142
+ if ((e.selectionEnd ?? i) !== i) {
139
143
  p.dismiss("ignored");
140
144
  return;
141
145
  }
142
- x(o);
146
+ v(i);
143
147
  }, [p]);
144
148
  l.useEffect(() => {
145
149
  const e = () => {
146
- document.activeElement === f.current && K();
150
+ document.activeElement === m.current && K();
147
151
  };
148
152
  return document.addEventListener("selectionchange", e), () => document.removeEventListener("selectionchange", e);
149
153
  }, [K]);
150
- const D = (e, o) => {
151
- u.current = o, s(e);
152
- }, _ = () => {
154
+ const D = (e, i) => {
155
+ u.current = i, s(e);
156
+ }, $ = () => {
153
157
  var e;
154
- b && (S(t), D(t.slice(0, v) + b + t.slice(v), v + b.length), p.settle("accepted", b), (e = f.current) == null || e.focus());
155
- }, re = () => {
156
- const e = Be(b);
158
+ k && (S(t), D(t.slice(0, y) + k + t.slice(y), y + k.length), p.settle("accepted", k), (e = m.current) == null || e.focus());
159
+ }, oe = () => {
160
+ const e = Ie(k);
157
161
  if (!e) return;
158
- const o = t.slice(0, v) + e + t.slice(v);
159
- D(o, v + e.length), p.settle("partial", e), p.setValue(o, v + e.length);
160
- }, oe = (e) => {
161
- S(t), D(e, e.length), k.take(e);
162
- }, ie = () => {
163
- var e;
164
- N !== null && (D(N, N.length), S(null), (e = f.current) == null || e.focus());
162
+ const i = t.slice(0, y) + e + t.slice(y);
163
+ D(i, y + e.length), p.settle("partial", e), p.setValue(i, y + e.length);
164
+ }, ie = (e) => {
165
+ S(t), D(e, e.length), x.take(e);
165
166
  }, ce = () => {
166
- const e = f.current, o = e && e === document.activeElement ? e.selectionStart ?? v : v;
167
- x(o), p.ask(t, o), e == null || e.focus(), e == null || e.setSelectionRange(o, o);
168
- }, le = (e) => {
169
- const o = e.target, W = o.selectionStart ?? o.value.length;
170
- x(W), S(null), s(o.value), m && p.setValue(o.value, W);
167
+ var e;
168
+ N !== null && (D(N, N.length), S(null), (e = m.current) == null || e.focus());
169
+ }, le = () => {
170
+ const e = m.current, i = e && e === document.activeElement ? e.selectionStart ?? y : y;
171
+ v(i), p.ask(t, i), e == null || e.focus(), e == null || e.setSelectionRange(i, i);
171
172
  }, ae = (e) => {
173
+ const i = e.target, W = i.selectionStart ?? i.value.length;
174
+ v(W), S(null), s(i.value), g && p.setValue(i.value, W);
175
+ }, ue = (e) => {
172
176
  if (e.defaultPrevented) return;
173
- if (!m) {
174
- e.key === "Escape" && k.items.length > 0 && k.cancel();
177
+ if (!g) {
178
+ e.key === "Escape" && x.items.length > 0 && x.cancel();
175
179
  return;
176
180
  }
177
- const o = w.rtl ? "ArrowLeft" : "ArrowRight";
181
+ const i = w.rtl ? "ArrowLeft" : "ArrowRight";
178
182
  if (e.altKey && (e.key === "]" || e.key === "[" || e.code === "BracketRight" || e.code === "BracketLeft")) {
179
183
  e.preventDefault(), p.cycle(e.key === "]" || e.code === "BracketRight" ? 1 : -1);
180
184
  return;
181
185
  }
182
- b && (e.key === "Tab" ? (e.preventDefault(), _()) : e.key === o && (e.ctrlKey || e.metaKey) ? (e.preventDefault(), re()) : e.key === "Escape" && p.dismiss("rejected"));
183
- }, $ = c, A = $.props, ue = l.cloneElement($, {
186
+ k && (e.key === "Tab" ? (e.preventDefault(), $()) : e.key === i && (e.ctrlKey || e.metaKey) ? (e.preventDefault(), oe()) : e.key === "Escape" && p.dismiss("rejected"));
187
+ }, X = o, A = X.props, de = l.cloneElement(X, {
184
188
  value: t,
185
- onChange: I(A.onChange, le),
186
- onKeyDown: I(A.onKeyDown, ae),
189
+ onChange: I(A.onChange, ae),
190
+ onKeyDown: I(A.onKeyDown, ue),
187
191
  onClick: I(A.onClick, K),
188
192
  onKeyUp: I(A.onKeyUp, K),
189
193
  onSelect: I(A.onSelect, K),
190
- ref: Ie(A.ref, f),
191
- "aria-keyshortcuts": b ? "Tab Escape Alt+]" : void 0
192
- }), B = m ? b.length > 0 : k.items.length > 0, de = (m ? p.status : k.status) === "loading" && !B, fe = N !== null && !B, me = !m || t.trim().length >= Ce;
194
+ ref: Te(A.ref, m),
195
+ "aria-keyshortcuts": k ? "Tab Escape Alt+]" : void 0
196
+ }), B = g ? k.length > 0 : x.items.length > 0, fe = (g ? p.status : x.status) === "loading" && !B, me = N !== null && !B, ge = !g || t.trim().length >= Re;
193
197
  return /* @__PURE__ */ E(
194
198
  R.div,
195
199
  {
@@ -201,55 +205,55 @@ function Le(n) {
201
205
  onFocus: () => O(!0),
202
206
  ref: h,
203
207
  children: [
204
- ue,
205
- m && /* @__PURE__ */ i(Ke, { caret: v, field: f, ghost: b, metrics: w.metrics, value: t }),
206
- /* @__PURE__ */ i(
208
+ de,
209
+ g && /* @__PURE__ */ c(We, { caret: y, field: m, ghost: k, metrics: w.metrics, value: t }),
210
+ /* @__PURE__ */ c(
207
211
  R.span,
208
212
  {
209
213
  className: M("absolute flex items-center", w.mark.insetInlineEnd === void 0 && "invisible"),
210
214
  "data-slot": "assist-mark",
211
215
  style: w.mark,
212
- children: fe ? /* @__PURE__ */ i(U, { label: g.revert, onClick: ie, children: /* @__PURE__ */ i(pe, {}) }) : /* @__PURE__ */ i(
216
+ children: me ? /* @__PURE__ */ c(U, { label: f.revert, onClick: ce, children: /* @__PURE__ */ c(ye, {}) }) : /* @__PURE__ */ c(
213
217
  U,
214
218
  {
215
- busy: de,
216
- disabled: !B && !me,
217
- label: B ? m ? g.accept : g.others : g.assist,
219
+ busy: fe,
220
+ disabled: !B && !ge,
221
+ label: B ? g ? f.accept : f.others : f.assist,
218
222
  offering: B,
219
- onClick: m ? B ? _ : ce : k.press
223
+ onClick: g ? B ? $ : le : x.press
220
224
  }
221
225
  )
222
226
  }
223
227
  ),
224
- m ? /* @__PURE__ */ E(ge, { children: [
225
- b && /* @__PURE__ */ i(We, { t: g }),
226
- /* @__PURE__ */ i("span", { "aria-live": "polite", className: "sr-only", "data-slot": "assist-status", children: b ? g.announcement : "" }),
227
- /* @__PURE__ */ i(ne, { error: p.error })
228
- ] }) : H && /* @__PURE__ */ i(se, { list: k, onPick: oe, t: g })
228
+ g ? /* @__PURE__ */ E(pe, { children: [
229
+ k && /* @__PURE__ */ c(Me, { t: f }),
230
+ /* @__PURE__ */ c("span", { "aria-live": "polite", className: "sr-only", "data-slot": "assist-status", children: k ? f.announcement : "" }),
231
+ /* @__PURE__ */ c(se, { error: p.error, status: p.status, t: f })
232
+ ] }) : H && /* @__PURE__ */ c(re, { list: x, onPick: ie, t: f })
229
233
  ]
230
234
  }
231
235
  );
232
236
  }
233
- function Ke(n) {
234
- const { field: t, ghost: s, value: r, caret: c, metrics: d } = n, a = l.useRef(null);
237
+ function We(n) {
238
+ const { field: t, ghost: s, value: r, caret: o, metrics: d } = n, a = l.useRef(null);
235
239
  l.useLayoutEffect(() => {
236
- const h = t.current, f = a.current;
237
- if (!h || !f) return;
240
+ const h = t.current, m = a.current;
241
+ if (!h || !m) return;
238
242
  if (!s) {
239
243
  h.style.removeProperty("min-height");
240
244
  return;
241
245
  }
242
- const m = getComputedStyle(h), C = f.scrollHeight + F(m.borderTopWidth) + F(m.borderBottomWidth);
246
+ const g = getComputedStyle(h), C = m.scrollHeight + F(g.borderTopWidth) + F(g.borderBottomWidth);
243
247
  C > h.getBoundingClientRect().height + 1 && h.style.setProperty("min-height", `${C}px`);
244
248
  }, [t, s, r]), l.useLayoutEffect(() => {
245
- const h = t.current, f = a.current;
246
- if (!h || !f) return;
247
- const m = () => {
248
- f.scrollLeft = h.scrollLeft, f.scrollTop = h.scrollTop;
249
+ const h = t.current, m = a.current;
250
+ if (!h || !m) return;
251
+ const g = () => {
252
+ m.scrollLeft = h.scrollLeft, m.scrollTop = h.scrollTop;
249
253
  };
250
- return m(), h.addEventListener("scroll", m), () => h.removeEventListener("scroll", m);
251
- }, [c, t, s, r]);
252
- const g = Math.min(c, r.length);
254
+ return g(), h.addEventListener("scroll", g), () => h.removeEventListener("scroll", g);
255
+ }, [o, t, s, r]);
256
+ const f = Math.min(o, r.length);
253
257
  return /* @__PURE__ */ E(
254
258
  R.div,
255
259
  {
@@ -262,40 +266,47 @@ function Ke(n) {
262
266
  ref: a,
263
267
  style: d,
264
268
  children: [
265
- /* @__PURE__ */ i("span", { className: "invisible", children: r.slice(0, g) }),
266
- /* @__PURE__ */ i("span", { className: "text-faint", children: s }),
267
- /* @__PURE__ */ i("span", { className: "invisible", children: r.slice(g) })
269
+ /* @__PURE__ */ c("span", { className: "invisible", children: r.slice(0, f) }),
270
+ /* @__PURE__ */ c("span", { className: "text-faint", children: s }),
271
+ /* @__PURE__ */ c("span", { className: "invisible", children: r.slice(f) })
268
272
  ]
269
273
  }
270
274
  );
271
275
  }
272
- function We({ t: n }) {
276
+ function Me({ t: n }) {
273
277
  return /* @__PURE__ */ E(R.span, { className: "inline-flex flex-wrap items-center gap-3 text-muted-foreground text-xs", "data-slot": "assist-keys", children: [
274
278
  /* @__PURE__ */ E("span", { className: "inline-flex items-center gap-1 whitespace-nowrap", children: [
275
- /* @__PURE__ */ i(j, { children: "Tab" }),
279
+ /* @__PURE__ */ c(j, { children: "Tab" }),
276
280
  " ",
277
281
  n.acceptKey
278
282
  ] }),
279
283
  /* @__PURE__ */ E("span", { className: "inline-flex items-center gap-1 whitespace-nowrap", children: [
280
- /* @__PURE__ */ i(j, { children: "Alt ]" }),
284
+ /* @__PURE__ */ c(j, { children: "Alt ]" }),
281
285
  " ",
282
286
  n.nextKey
283
287
  ] }),
284
288
  /* @__PURE__ */ E("span", { className: "inline-flex items-center gap-1 whitespace-nowrap", children: [
285
- /* @__PURE__ */ i(j, { children: "Esc" }),
289
+ /* @__PURE__ */ c(j, { children: "Esc" }),
286
290
  " ",
287
291
  n.dismissKey
288
292
  ] })
289
293
  ] });
290
294
  }
291
- function ne({ error: n }) {
292
- return n === null ? null : /* @__PURE__ */ i(R.p, { className: "text-destructive-foreground text-sm", "data-slot": "assist-error", role: "alert", children: n });
295
+ function G(n, t) {
296
+ const { onFailure: s } = n, { status: r, error: o } = t;
297
+ l.useEffect(() => {
298
+ r === "error" && (s == null || s(o));
299
+ }, [r, o, s]);
293
300
  }
294
301
  function se(n) {
295
- const { list: t, onPick: s, t: r } = n, c = t.error !== null ? /* @__PURE__ */ i(ne, { error: t.error }) : t.items.length > 0 ? t.items.map((d) => /* @__PURE__ */ E(ye, { "aria-label": d.text, slot: "assist-candidate", children: [
296
- /* @__PURE__ */ i(be, { onSelect: s, title: d.rationale, value: d.text, children: d.text }),
297
- /* @__PURE__ */ i(
298
- xe,
302
+ const { error: t, status: s, t: r } = n;
303
+ return s !== "error" ? null : /* @__PURE__ */ c(R.p, { className: "text-destructive-foreground text-sm", "data-slot": "assist-error", role: "alert", children: t instanceof Error && t.message ? t.message : r.failed });
304
+ }
305
+ function re(n) {
306
+ const { list: t, onPick: s, t: r } = n, o = t.status === "error" ? /* @__PURE__ */ c(se, { error: t.error, status: t.status, t: r }) : t.items.length > 0 ? t.items.map((d) => /* @__PURE__ */ E(be, { "aria-label": d.text, slot: "assist-candidate", children: [
307
+ /* @__PURE__ */ c(xe, { onSelect: s, title: d.rationale, value: d.text, children: d.text }),
308
+ /* @__PURE__ */ c(
309
+ ke,
299
310
  {
300
311
  "aria-label": r.dismiss(d.text),
301
312
  className: "h-auto min-h-[24px] self-stretch px-2 py-1",
@@ -304,20 +315,20 @@ function se(n) {
304
315
  size: "sm",
305
316
  slot: "assist-dismiss",
306
317
  variant: "outline",
307
- children: /* @__PURE__ */ i(ve, {})
318
+ children: /* @__PURE__ */ c(ve, {})
308
319
  }
309
320
  )
310
321
  ] }, d.text)) : t.status === "loading" ? /* @__PURE__ */ E("span", { className: "inline-flex items-center gap-2 text-muted-foreground text-sm", "data-slot": "assist-pending", children: [
311
- /* @__PURE__ */ i(ke, { "aria-hidden": !0 }),
322
+ /* @__PURE__ */ c(Ee, { "aria-hidden": !0 }),
312
323
  r.thinking
313
- ] }) : t.status === "ready" ? /* @__PURE__ */ i("span", { className: "text-muted-foreground text-sm", "data-slot": "assist-empty", children: r.empty }) : null;
314
- return c === null ? null : /* @__PURE__ */ i(Ee, { className: "min-h-8", slot: "assist-candidates", children: c });
324
+ ] }) : t.status === "ready" ? /* @__PURE__ */ c("span", { className: "text-muted-foreground text-sm", "data-slot": "assist-empty", children: r.empty }) : null;
325
+ return o === null ? null : /* @__PURE__ */ c(Se, { className: "min-h-8", slot: "assist-candidates", children: o });
315
326
  }
316
- function Me(n) {
317
- const { value: t, onValueChange: s, instructions: r, children: c, className: d, settings: a } = n, { t: g } = a, h = l.useRef(null), [f, m] = l.useState(!1), [C, w] = l.useState({}), P = l.useCallback(() => Te(h.current), []), v = te(a, P), x = Q({
327
+ function Pe(n) {
328
+ const { value: t, onValueChange: s, instructions: r, children: o, className: d, settings: a } = n, { t: f } = a, h = l.useRef(null), [m, g] = l.useState(!1), [C, w] = l.useState({}), P = l.useCallback(() => Le(h.current), []), y = ne(a, P), v = Y({
318
329
  source: ({ signal: u }) => {
319
- var y;
320
- return Y(a.model, G(P(), r, (y = a.context) == null ? void 0 : y.call(a)), {
330
+ var b;
331
+ return Z(a.model, q(P(), r, (b = a.context) == null ? void 0 : b.call(a)), {
321
332
  value: "",
322
333
  existing: t,
323
334
  signal: u,
@@ -326,61 +337,61 @@ function Me(n) {
326
337
  });
327
338
  },
328
339
  existing: t,
329
- onEvent: v
340
+ onEvent: y
330
341
  });
331
- l.useLayoutEffect(() => {
332
- const u = h.current, y = (u == null ? void 0 : u.querySelector("[data-part=control]")) ?? (u == null ? void 0 : u.firstElementChild);
333
- if (!u || !y) return;
334
- y.style.paddingInlineEnd = ee;
342
+ G(a, v), l.useLayoutEffect(() => {
343
+ const u = h.current, b = (u == null ? void 0 : u.querySelector("[data-part=control]")) ?? (u == null ? void 0 : u.firstElementChild);
344
+ if (!u || !b) return;
345
+ b.style.paddingInlineEnd = te;
335
346
  const T = () => {
336
- const p = getComputedStyle(y).direction === "rtl", k = q(y, u, p);
337
- w({ insetInlineEnd: k.insetInlineEnd + 2, insetBlockStart: k.insetBlockStart, height: y.offsetHeight });
347
+ const p = getComputedStyle(b).direction === "rtl", x = _(b, u, p);
348
+ w({ insetInlineEnd: x.insetInlineEnd + 2, insetBlockStart: x.insetBlockStart, height: b.offsetHeight });
338
349
  };
339
350
  if (T(), typeof ResizeObserver > "u") return;
340
351
  const L = new ResizeObserver(T);
341
- return L.observe(y), () => L.disconnect();
352
+ return L.observe(b), () => L.disconnect();
342
353
  }, []);
343
- const H = c, O = H.props, N = l.cloneElement(H, {
354
+ const H = o, O = H.props, N = l.cloneElement(H, {
344
355
  value: t,
345
356
  onValueChange: I(O.onValueChange, (u) => s(u.value))
346
- }), S = x.items.length > 0;
357
+ }), S = v.items.length > 0;
347
358
  return /* @__PURE__ */ E(
348
359
  R.div,
349
360
  {
350
361
  className: M("relative flex w-full min-w-0 flex-col gap-2", d),
351
362
  "data-slot": "assist",
352
363
  onBlur: (u) => {
353
- u.currentTarget.contains(u.relatedTarget) || m(!1);
364
+ u.currentTarget.contains(u.relatedTarget) || g(!1);
354
365
  },
355
- onFocus: () => m(!0),
366
+ onFocus: () => g(!0),
356
367
  ref: h,
357
368
  children: [
358
369
  N,
359
- /* @__PURE__ */ i(
370
+ /* @__PURE__ */ c(
360
371
  R.span,
361
372
  {
362
373
  className: M("absolute flex items-center", C.insetInlineEnd === void 0 && "invisible"),
363
374
  "data-slot": "assist-mark",
364
375
  style: C,
365
- children: /* @__PURE__ */ i(
376
+ children: /* @__PURE__ */ c(
366
377
  U,
367
378
  {
368
- busy: x.status === "loading" && !S,
369
- label: S ? g.others : g.assist,
379
+ busy: v.status === "loading" && !S,
380
+ label: S ? f.others : f.assist,
370
381
  offering: S,
371
- onClick: x.press
382
+ onClick: v.press
372
383
  }
373
384
  )
374
385
  }
375
386
  ),
376
- f && /* @__PURE__ */ i(
377
- se,
387
+ m && /* @__PURE__ */ c(
388
+ re,
378
389
  {
379
- list: x,
390
+ list: v,
380
391
  onPick: (u) => {
381
- s([...t, u]), x.take(u);
392
+ s([...t, u]), v.take(u);
382
393
  },
383
- t: g
394
+ t: f
384
395
  }
385
396
  )
386
397
  ]
@@ -388,7 +399,7 @@ function Me(n) {
388
399
  );
389
400
  }
390
401
  export {
391
- Ue as Assist,
392
- je as AssistProvider
402
+ Ge as Assist,
403
+ Ue as AssistProvider
393
404
  };
394
405
  //# sourceMappingURL=assist.js.map