@inkeep/agents-ui 0.0.0-dev-20260508201702 → 0.0.0-dev-20260508211520

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 (21) hide show
  1. package/dist/node_modules/.pnpm/@hookform_resolvers@5.2.2_react-hook-form@7.70.0_react@19.3.0-canary-87ae75b3-20260128_/node_modules/@hookform/resolvers/zod/dist/zod.cjs +1 -0
  2. package/dist/node_modules/.pnpm/@hookform_resolvers@5.2.2_react-hook-form@7.70.0_react@19.3.0-canary-87ae75b3-20260128_/node_modules/@hookform/resolvers/zod/dist/zod.js +93 -0
  3. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.cjs +1 -0
  4. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.js +49 -0
  5. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.cjs +1 -0
  6. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.js +19 -0
  7. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/parse.cjs +1 -0
  8. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/parse.js +28 -0
  9. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.cjs +1 -0
  10. package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.js +23 -0
  11. package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -2
  12. package/dist/primitives/components/embedded-chat/use-inkeep-chat.d.ts +13 -0
  13. package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +181 -183
  14. package/dist/styled/components/ask-user-form.cjs +1 -0
  15. package/dist/styled/components/ask-user-form.d.ts +96 -0
  16. package/dist/styled/components/ask-user-form.js +672 -0
  17. package/dist/styled/components/message.cjs +1 -1
  18. package/dist/styled/components/message.js +272 -210
  19. package/dist/styled/inkeep.css.cjs +78 -0
  20. package/dist/styled/inkeep.css.js +78 -0
  21. package/package.json +2 -1
@@ -1,34 +1,34 @@
1
1
  "use client";
2
- import { useChat as it } from "@ai-sdk/react";
3
- import { normalizeFileType as Oe } from "./file-upload-input.js";
4
- import { DefaultChatTransport as lt } from "ai";
5
- import { useRef as c, useEffect as x, useState as F, useMemo as _e, useCallback as $, useImperativeHandle as ct } from "react";
6
- import { useModal as ut } from "../modal/modal-provider.js";
7
- import { useOptionalChatBubble as pt } from "../../providers/chat-bubble-provider.js";
8
- import { useOptionalSidebarChat as dt } from "../../providers/sidebar-chat-provider.js";
9
- import { useInkeepConfig as ft } from "../../providers/config-provider.js";
10
- import { useCaptcha as mt } from "./use-captcha.js";
11
- import { useMediaQuery as gt } from "../../hooks/use-media-query.js";
12
- import { useAnonymousSession as ht } from "../../hooks/use-anonymous-session.js";
13
- import { useAuthToken as vt } from "../../hooks/use-auth-token.js";
14
- import { useConversationLoader as yt } from "../../hooks/use-conversation-loader.js";
15
- import { useInitialConversation as Ct } from "../../hooks/use-initial-conversation.js";
2
+ import { useChat as at } from "@ai-sdk/react";
3
+ import { normalizeFileType as xe } from "./file-upload-input.js";
4
+ import { DefaultChatTransport as it } from "ai";
5
+ import { useRef as c, useEffect as x, useState as F, useMemo as Fe, useCallback as $, useImperativeHandle as lt } from "react";
6
+ import { useModal as ct } from "../modal/modal-provider.js";
7
+ import { useOptionalChatBubble as ut } from "../../providers/chat-bubble-provider.js";
8
+ import { useOptionalSidebarChat as pt } from "../../providers/sidebar-chat-provider.js";
9
+ import { useInkeepConfig as dt } from "../../providers/config-provider.js";
10
+ import { useCaptcha as ft } from "./use-captcha.js";
11
+ import { useMediaQuery as mt } from "../../hooks/use-media-query.js";
12
+ import { useAnonymousSession as gt } from "../../hooks/use-anonymous-session.js";
13
+ import { useAuthToken as ht } from "../../hooks/use-auth-token.js";
14
+ import { useConversationLoader as vt } from "../../hooks/use-conversation-loader.js";
15
+ import { useInitialConversation as yt } from "../../hooks/use-initial-conversation.js";
16
16
  import { generateUid as U } from "../../utils/generate-uid.js";
17
- import { useBaseEvents as At } from "../../providers/base-events-provider.js";
18
- import { useChatForm as St } from "../../providers/chat-form-provider.js";
19
- import { useWidget as bt } from "../../providers/widget-provider.js";
20
- import { useControllableState as Rt } from "@radix-ui/react-use-controllable-state";
17
+ import { useBaseEvents as Ct } from "../../providers/base-events-provider.js";
18
+ import { useChatForm as At } from "../../providers/chat-form-provider.js";
19
+ import { useWidget as St } from "../../providers/widget-provider.js";
20
+ import { useControllableState as bt } from "@radix-ui/react-use-controllable-state";
21
21
  import { useStreamingEvents as It } from "../../hooks/use-streaming-events.js";
22
- import { useInputNotification as wt } from "../../hooks/use-input-notification.js";
23
- import { resolveStreamingAuthError as Tt, DEFAULT_ERROR_MESSAGE as ce, isRecoverableError as kt, RECOVERABLE_NOTIFICATION_DURATION_MS as Et, resolveHttpStatusCode as Mt, RATE_LIMIT_MESSAGE as xt, RECOVERABLE_FALLBACK_MESSAGE as Ne } from "./chat-error-helpers.js";
24
- const Yt = () => {
25
- const { baseSettings: q, aiChatSettings: y } = ft(), [i = "", g] = Rt({
22
+ import { useInputNotification as Rt } from "../../hooks/use-input-notification.js";
23
+ import { resolveStreamingAuthError as Tt, DEFAULT_ERROR_MESSAGE as ie, isRecoverableError as wt, RECOVERABLE_NOTIFICATION_DURATION_MS as Et, resolveHttpStatusCode as kt, RATE_LIMIT_MESSAGE as Mt, RECOVERABLE_FALLBACK_MESSAGE as Oe } from "./chat-error-helpers.js";
24
+ const Xt = () => {
25
+ const { baseSettings: q, aiChatSettings: y } = dt(), [i = "", g] = bt({
26
26
  prop: y.conversationIdOverride,
27
27
  defaultProp: y.conversationIdOverride ?? ""
28
- }), Pe = ut(), Le = pt(), De = dt(), { logEvent: m } = At(), { setConversationId: Be, emitToParent: O } = It(), ue = c(i);
28
+ }), _e = ct(), Ne = ut(), Pe = pt(), { logEvent: m } = Ct(), { setConversationId: Le, emitToParent: O } = It(), le = c(i);
29
29
  x(() => {
30
- const e = ue.current;
31
- ue.current = i, e !== i && m({
30
+ const e = le.current;
31
+ le.current = i, e !== i && m({
32
32
  eventName: "chat_conversation_changed",
33
33
  properties: {
34
34
  conversationId: i,
@@ -36,98 +36,94 @@ const Yt = () => {
36
36
  }
37
37
  });
38
38
  }, [i, m]);
39
- const [C, A] = F(""), $e = (e) => A(e.target.value), {
40
- shouldBypassCaptcha: pe,
41
- filters: de,
42
- privacyPreferences: Ue,
43
- userProperties: z,
44
- analyticsProperties: H
45
- } = q, { authToken: _, isLoading: qe, refreshToken: fe } = vt(), me = !!q.getAuthToken, d = !!_, {
46
- onInputMessageChange: ze,
47
- filters: ge,
39
+ const [C, A] = F(""), De = (e) => A(e.target.value), {
40
+ shouldBypassCaptcha: ce,
41
+ filters: ue,
42
+ privacyPreferences: Be,
43
+ userProperties: z
44
+ } = q, { authToken: _, isLoading: $e, refreshToken: pe } = ht(), de = !!q.getAuthToken, d = !!_, {
45
+ onInputMessageChange: Ue,
46
+ filters: fe,
48
47
  baseUrl: N,
49
- agentUrl: He,
50
- context: he,
51
- headers: ve,
48
+ agentUrl: qe,
49
+ context: me,
50
+ headers: ge,
52
51
  appId: S,
53
52
  apiKey: h,
54
53
  files: b
55
- } = y, Ke = Pe?.isOpen ?? Le?.isOpen ?? De?.isOpen ?? !0, { getCaptchaHeader: R, invalidate: u } = mt({
54
+ } = y, ze = _e?.isOpen ?? Ne?.isOpen ?? Pe?.isOpen ?? !0, { getCaptchaHeader: I, invalidate: u } = ft({
56
55
  baseUrl: N,
57
- shouldBypassCaptcha: pe || !!h,
58
- shouldMakeInitialRequest: Ke
59
- }), ye = c(R);
60
- ye.current = R;
61
- const Ce = He || `${N}/run/api/chat`, { sessionToken: K, refreshSession: J } = ht({
56
+ shouldBypassCaptcha: ce || !!h,
57
+ shouldMakeInitialRequest: ze
58
+ }), he = c(I);
59
+ he.current = I;
60
+ const ve = qe || `${N}/run/api/chat`, { sessionToken: H, refreshSession: K } = gt({
62
61
  baseUrl: N,
63
62
  appId: S,
64
- getCaptchaHeader: R,
63
+ getCaptchaHeader: I,
65
64
  invalidateCaptcha: u,
66
- optOutAllAnalytics: Ue?.optOutAllAnalytics,
67
- enabled: !d && !qe
68
- }), Ae = h ?? (d ? _ : K), { loadConversation: Se } = yt({
65
+ optOutAllAnalytics: Be?.optOutAllAnalytics,
66
+ enabled: !d && !$e
67
+ }), ye = h ?? (d ? _ : H), { loadConversation: Ce } = vt({
69
68
  baseUrl: N,
70
69
  appId: S,
71
- authToken: Ae,
72
- getCaptchaHeader: R,
70
+ authToken: ye,
71
+ getCaptchaHeader: I,
73
72
  invalidateCaptcha: u,
74
- refreshSession: h || d ? void 0 : J
75
- }), [Je, be] = F(!1), j = c(null);
76
- j.current = K;
77
- const G = c(null);
78
- G.current = _;
73
+ refreshSession: h || d ? void 0 : K
74
+ }), [He, Ae] = F(!1), G = c(null);
75
+ G.current = H;
76
+ const J = c(null);
77
+ J.current = _;
79
78
  const V = c(void 0);
80
79
  V.current = z && Object.keys(z).length > 0 ? JSON.stringify(z) : void 0;
81
- const W = c(void 0);
82
- W.current = H && Object.keys(H).length > 0 ? JSON.stringify(H) : void 0;
83
- const v = c(0), Q = c(null), Z = c(null), I = c(void 0), je = b?.map(
80
+ const v = c(0), j = c(null), W = c(null), R = c(void 0), Ke = b?.map(
84
81
  (e) => `${e.filename ?? ""}:${e.mediaType}:${e.url.length}:${e.url.slice(0, 64)}:${e.url.slice(-32)}`
85
82
  ).join(`
86
83
  `) ?? "";
87
84
  x(() => {
88
- I.current = b?.length ? b : void 0;
89
- }, [je]);
90
- const Re = c(ve);
91
- Re.current = ve;
92
- const X = c(void 0);
93
- X.current = de || ge ? JSON.stringify({ ...de, ...ge }) : void 0;
85
+ R.current = b?.length ? b : void 0;
86
+ }, [Ke]);
87
+ const Se = c(ge);
88
+ Se.current = ge;
89
+ const Q = c(void 0);
90
+ Q.current = ue || fe ? JSON.stringify({ ...ue, ...fe }) : void 0;
94
91
  const Ge = (e) => {
95
- switch (Mt(e)) {
92
+ switch (kt(e)) {
96
93
  case 400:
97
94
  try {
98
95
  const t = JSON.parse(e.message ?? "");
99
- return t.detail ?? t.error?.message ?? Ne;
96
+ return t.detail ?? t.error?.message ?? Oe;
100
97
  } catch {
101
- return e.message?.trim() || Ne;
98
+ return e.message?.trim() || Oe;
102
99
  }
103
100
  case 401:
104
- return me ? "Authentication failed. Please try again." : ce;
101
+ return de ? "Authentication failed. Please try again." : ie;
105
102
  case 403:
106
103
  return `There seems to be a configuration error. Please contact ${q.organizationDisplayName ?? "Administrator"}`;
107
104
  case 429:
108
- return xt;
105
+ return Mt;
109
106
  default:
110
- return ce;
107
+ return ie;
111
108
  }
112
- }, [P, Y] = F([]), Ve = _e(
113
- () => new lt({
114
- api: Ce,
109
+ }, [P, Z] = F([]), Je = Fe(
110
+ () => new it({
111
+ api: ve,
115
112
  headers: () => {
116
- const e = h ?? G.current ?? j.current;
113
+ const e = h ?? J.current ?? G.current;
117
114
  return {
118
115
  "x-inkeep-client-timezone": Intl.DateTimeFormat().resolvedOptions().timeZone,
119
116
  "x-inkeep-client-timestamp": (/* @__PURE__ */ new Date()).toISOString(),
120
117
  "x-inkeep-invocation-type": "chat_widget",
121
118
  ...S ? { "x-inkeep-app-id": S } : {},
122
119
  ...e ? { Authorization: `Bearer ${e}` } : {},
123
- ...X.current ? { "inkeep-filters": X.current } : {},
120
+ ...Q.current ? { "inkeep-filters": Q.current } : {},
124
121
  ...V.current ? { "x-inkeep-user-properties": V.current } : {},
125
- ...W.current ? { "x-inkeep-properties": W.current } : {},
126
- ...Re.current
122
+ ...Se.current
127
123
  };
128
124
  },
129
125
  prepareSendMessagesRequest: async (e) => {
130
- const a = await ye.current(), t = e.messages[e.messages.length - 1];
126
+ const a = await he.current(), t = e.messages[e.messages.length - 1];
131
127
  return t || console.warn(
132
128
  "[useInkeepChat] prepareSendMessagesRequest called with empty messages array"
133
129
  ), {
@@ -145,20 +141,21 @@ const Yt = () => {
145
141
  };
146
142
  },
147
143
  body: {
148
- requestContext: he
144
+ requestContext: me
149
145
  }
150
146
  }),
151
- [Ce, he, S, h]
147
+ [ve, me, S, h]
152
148
  ), {
153
149
  messages: L,
154
- sendMessage: ee,
155
- addToolApprovalResponse: te,
156
- status: Ie,
150
+ sendMessage: X,
151
+ addToolApprovalResponse: Y,
152
+ addToolOutput: Ve,
153
+ status: be,
157
154
  setMessages: f,
158
155
  stop: D,
159
156
  error: B
160
- } = it({
161
- transport: Ve,
157
+ } = at({
158
+ transport: Je,
162
159
  onData(e) {
163
160
  O(e.type, e.data);
164
161
  },
@@ -177,47 +174,47 @@ const Yt = () => {
177
174
  },
178
175
  onError(e) {
179
176
  console.error("onError", { code: e.code, message: e.message });
180
- const a = pe || h ? null : Tt(e);
177
+ const a = ce || h ? null : Tt(e);
181
178
  if (a !== null && v.current < 1) {
182
179
  v.current++;
183
- const n = Z.current, s = Q.current;
180
+ const n = W.current, s = j.current;
184
181
  (async () => {
185
- if (a === "session" && me) {
186
- const l = await fe();
182
+ if (a === "session" && de) {
183
+ const l = await pe();
187
184
  if (!l) throw new Error("Auth token refresh failed");
188
- G.current = l;
185
+ J.current = l;
189
186
  } else if (a === "session") {
190
- const l = await J();
191
- l && (j.current = l);
187
+ const l = await K();
188
+ l && (G.current = l);
192
189
  } else
193
190
  u();
194
191
  if (n) {
195
- te(n);
192
+ Y(n);
196
193
  return;
197
194
  }
198
195
  s && (f((l) => {
199
196
  let r = [...l];
200
197
  return r.at(-1)?.role === "assistant" && (r = r.slice(0, -1)), r.at(-1)?.role === "user" && (r = r.slice(0, -1)), r;
201
- }), ee(
198
+ }), X(
202
199
  s.files?.length ? { parts: [{ type: "text", text: s.content }, ...s.files] } : { text: s.content },
203
200
  { body: s.body }
204
201
  ));
205
202
  })().catch(() => {
206
203
  v.current = 0, u(), f((l) => {
207
- const r = [...l], k = r[r.length - 1];
208
- if (!k) return r;
209
- const E = ce;
210
- return k.role === "user" ? r.push({
204
+ const r = [...l], E = r[r.length - 1];
205
+ if (!E) return r;
206
+ const k = ie;
207
+ return E.role === "user" ? r.push({
211
208
  id: U(16),
212
209
  role: "assistant",
213
- parts: [{ type: "text", text: E }]
214
- }) : k.parts = [{ type: "text", text: E }], r;
210
+ parts: [{ type: "text", text: k }]
211
+ }) : E.parts = [{ type: "text", text: k }], r;
215
212
  });
216
213
  });
217
214
  return;
218
215
  }
219
216
  v.current = 0, a !== null && u();
220
- const t = kt(e), p = Ge(e);
217
+ const t = wt(e), p = Ge(e);
221
218
  if (m({
222
219
  eventName: "chat_error",
223
220
  properties: {
@@ -225,15 +222,15 @@ const Yt = () => {
225
222
  error: e.message
226
223
  }
227
224
  }), t) {
228
- ae(
225
+ ne(
229
226
  { title: "Request failed", message: p },
230
227
  Et
231
228
  ), f((s) => {
232
229
  let o = [...s];
233
230
  return o.at(-1)?.role === "assistant" && (o = o.slice(0, -1)), o.at(-1)?.role === "user" && (o = o.slice(0, -1)), o;
234
231
  });
235
- const n = Q.current?.content;
236
- n && A(n), oe.current = e;
232
+ const n = j.current?.content;
233
+ n && A(n), re.current = e;
237
234
  return;
238
235
  }
239
236
  f((n) => {
@@ -245,12 +242,12 @@ const Yt = () => {
245
242
  }) : o.parts = [{ type: "text", text: p }]), s;
246
243
  });
247
244
  }
248
- }), we = c(d);
245
+ }), Ie = c(d);
249
246
  x(() => {
250
- const e = we.current;
251
- we.current = d, e !== d && (D(), w(null), f([]), g(""), A(""), Y([]), u());
247
+ const e = Ie.current;
248
+ Ie.current = d, e !== d && (D(), T(null), f([]), g(""), A(""), Z([]), u());
252
249
  }, [d, D, f, g, u]);
253
- const Te = Ie === "submitted", se = Ie === "streaming", We = _e(() => {
250
+ const Re = be === "submitted", ee = be === "streaming", je = Fe(() => {
254
251
  const e = (n) => {
255
252
  if (!n || typeof n != "object") return !1;
256
253
  const s = n;
@@ -258,62 +255,62 @@ const Yt = () => {
258
255
  }, t = [...L ?? []].reverse().find((n) => n.role === "assistant");
259
256
  if (!t) return !1;
260
257
  const p = t.parts?.at(-1);
261
- return !(!e(p) || p.state !== "output-available" || !p.approval?.id || se);
262
- }, [L, se]), [Qe, re] = F(!1), ke = se || We && !Qe, Ee = Te || ke, Ze = L.length === 0, ne = !C.trim() && P.length === 0 || Ee, Xe = gt("(max-width: 768px)"), [Ye, w] = F(null), oe = c(null);
258
+ return !(!e(p) || p.state !== "output-available" || !p.approval?.id || ee);
259
+ }, [L, ee]), [We, te] = F(!1), Te = ee || je && !We, we = Re || Te, Qe = L.length === 0, se = !C.trim() && P.length === 0 || we, Ze = mt("(max-width: 768px)"), [Xe, T] = F(null), re = c(null);
263
260
  x(() => {
264
261
  if (B) {
265
- if (oe.current === B) {
266
- oe.current = null;
262
+ if (re.current === B) {
263
+ re.current = null;
267
264
  return;
268
265
  }
269
- w(B);
266
+ T(B);
270
267
  }
271
268
  }, [B]);
272
- const et = () => w(null), { inputNotification: tt, showInputNotification: ae, clearInputNotification: st } = wt(), Me = c(null);
269
+ const Ye = () => T(null), { inputNotification: et, showInputNotification: ne, clearInputNotification: tt } = Rt(), Ee = c(null);
273
270
  x(() => {
274
- ze?.(C);
271
+ Ue?.(C);
275
272
  }, [C]);
276
- const rt = (e) => {
277
- e.key === "Enter" && !e.shiftKey && !ne && !e.nativeEvent.isComposing && (e.preventDefault(), ie());
278
- }, ie = async (e = C) => {
279
- if (ne && (!e || e.trim().length === 0) && P.length === 0) return;
273
+ const st = (e) => {
274
+ e.key === "Enter" && !e.shiftKey && !se && !e.nativeEvent.isComposing && (e.preventDefault(), oe());
275
+ }, oe = async (e = C) => {
276
+ if (se && (!e || e.trim().length === 0) && P.length === 0) return;
280
277
  const a = P;
281
- Y([]), A(""), v.current = 0, Z.current = null, re(!1), await m({
278
+ Z([]), A(""), v.current = 0, W.current = null, te(!1), await m({
282
279
  eventName: "user_message_submitted",
283
280
  properties: {
284
281
  conversationId: i
285
282
  }
286
283
  });
287
284
  let t = i;
288
- t || (t = `conv_${U(16)}`, g(t)), Be(t);
289
- const p = I.current;
290
- I.current = void 0;
285
+ t || (t = `conv_${U(16)}`, g(t)), Le(t);
286
+ const p = R.current;
287
+ R.current = void 0;
291
288
  let n, s;
292
289
  if (p?.length) {
293
290
  let o;
294
291
  try {
295
292
  o = await Promise.all(
296
293
  a.map((l) => {
297
- const r = Oe(l);
298
- return new Promise((k, E) => {
294
+ const r = xe(l);
295
+ return new Promise((E, k) => {
299
296
  const M = new FileReader();
300
297
  M.onload = () => {
301
298
  if (typeof M.result != "string") {
302
- E(new Error(`Failed to read file "${r.name}"`));
299
+ k(new Error(`Failed to read file "${r.name}"`));
303
300
  return;
304
301
  }
305
- k({
302
+ E({
306
303
  type: "file",
307
304
  url: M.result,
308
305
  mediaType: r.type,
309
306
  filename: r.name
310
307
  });
311
- }, M.onerror = () => E(new Error(`Failed to read file "${r.name}"`)), M.readAsDataURL(r);
308
+ }, M.onerror = () => k(new Error(`Failed to read file "${r.name}"`)), M.readAsDataURL(r);
312
309
  });
313
310
  })
314
311
  );
315
312
  } catch {
316
- ae({
313
+ ne({
317
314
  title: "Failed to attach files",
318
315
  message: "Could not read one or more files. Please try again."
319
316
  });
@@ -322,44 +319,44 @@ const Yt = () => {
322
319
  s = [...o, ...p], n = e.trim() ? { parts: [{ type: "text", text: e }, ...s] } : { parts: s };
323
320
  } else if (a.length > 0) {
324
321
  const o = new DataTransfer();
325
- for (const r of a) o.items.add(Oe(r));
322
+ for (const r of a) o.items.add(xe(r));
326
323
  const l = o.files;
327
324
  n = e.trim() ? { text: e, files: l } : { files: l };
328
325
  } else
329
326
  n = { text: e };
330
- Q.current = {
327
+ j.current = {
331
328
  content: e,
332
329
  body: { conversationId: t },
333
330
  files: s
334
- }, ee(n, {
331
+ }, X(n, {
335
332
  body: { conversationId: t }
336
333
  });
337
- }, nt = $(
334
+ }, rt = $(
338
335
  (e) => {
339
- v.current = 0, Z.current = e, re(!1), te(e);
336
+ v.current = 0, W.current = e, te(!1), Y(e);
340
337
  },
341
- [te]
342
- ), le = $(() => {
343
- re(!0), D().then(() => {
338
+ [Y]
339
+ ), ae = $(() => {
340
+ te(!0), D().then(() => {
344
341
  O("aborted", { conversationId: i });
345
342
  });
346
- }, [D, i, O]), xe = () => {
347
- et(), f([]), g(""), u(), I.current = b?.length ? b : void 0, m({
343
+ }, [D, i, O]), ke = () => {
344
+ Ye(), f([]), g(""), u(), R.current = b?.length ? b : void 0, m({
348
345
  eventName: "chat_clear_button_clicked",
349
346
  properties: {
350
347
  conversationId: i
351
348
  }
352
349
  });
353
- }, T = $(
350
+ }, w = $(
354
351
  (e, a) => {
355
- w(null), f(a), g(e), u(), I.current = void 0;
352
+ T(null), f(a), g(e), u(), R.current = void 0;
356
353
  },
357
354
  [f, g, u]
358
- ), Fe = $(
355
+ ), Me = $(
359
356
  async (e, a) => {
360
- le(), T(e, []), be(!0);
357
+ ae(), w(e, []), Ae(!0);
361
358
  try {
362
- const t = await Se(e, a);
359
+ const t = await Ce(e, a);
363
360
  if (t === null) return !1;
364
361
  const n = t[t.length - 1]?.role === "user" ? [
365
362
  ...t,
@@ -374,66 +371,67 @@ const Yt = () => {
374
371
  ]
375
372
  }
376
373
  ] : t;
377
- return T(e, n), !0;
374
+ return w(e, n), !0;
378
375
  } finally {
379
- a?.aborted || be(!1);
376
+ a?.aborted || Ae(!1);
380
377
  }
381
378
  },
382
- [T, Se, le]
379
+ [w, Ce, ae]
383
380
  );
384
- Ct({
381
+ yt({
385
382
  conversationId: y.conversationId,
386
- effectiveAuthToken: Ae,
387
- loadAndRestoreSession: Fe,
388
- onLoadFailed: () => T("", [])
383
+ effectiveAuthToken: ye,
384
+ loadAndRestoreSession: Me,
385
+ onLoadFailed: () => w("", [])
389
386
  });
390
- const { openForm: ot } = St(), at = bt();
391
- return ct(y.chatFunctionsRef, () => ({
392
- submitMessage: ie,
387
+ const { openForm: nt } = At(), ot = St();
388
+ return lt(y.chatFunctionsRef, () => ({
389
+ submitMessage: oe,
393
390
  updateInputMessage(e) {
394
391
  A(e);
395
392
  },
396
- clearChat: xe,
393
+ clearChat: ke,
397
394
  openForm: (e) => {
398
- at?.setView("chat"), ot(e, void 0);
395
+ ot?.setView("chat"), nt(e, void 0);
399
396
  },
400
397
  focusInput: () => {
401
- Me.current?.focus();
398
+ Ee.current?.focus();
402
399
  }
403
400
  })), {
404
401
  messages: L,
405
- sendMessage: ee,
406
- addToolApprovalResponse: nt,
407
- isLoading: Te,
408
- isStreaming: ke,
409
- isBusy: Ee,
410
- error: Ye,
411
- setError: w,
412
- isSubmitDisabled: ne,
402
+ sendMessage: X,
403
+ addToolApprovalResponse: rt,
404
+ addToolOutput: Ve,
405
+ isLoading: Re,
406
+ isStreaming: Te,
407
+ isBusy: we,
408
+ error: Xe,
409
+ setError: T,
410
+ isSubmitDisabled: se,
413
411
  input: C,
414
- handleInputChange: $e,
415
- handleInputKeyDown: rt,
416
- handleSubmit: ie,
417
- stop: le,
418
- clear: xe,
419
- inputRef: Me,
420
- isMobile: Xe,
412
+ handleInputChange: De,
413
+ handleInputKeyDown: st,
414
+ handleSubmit: oe,
415
+ stop: ae,
416
+ clear: ke,
417
+ inputRef: Ee,
418
+ isMobile: Ze,
421
419
  files: P,
422
- setFiles: Y,
423
- isNewChat: Ze,
420
+ setFiles: Z,
421
+ isNewChat: Qe,
424
422
  conversationId: i,
425
- restoreSession: T,
426
- loadAndRestoreSession: Fe,
427
- isSessionLoading: Je,
428
- authToken: d ? _ : K,
429
- refreshSession: d ? fe : J,
430
- getCaptchaHeader: R,
423
+ restoreSession: w,
424
+ loadAndRestoreSession: Me,
425
+ isSessionLoading: He,
426
+ authToken: d ? _ : H,
427
+ refreshSession: d ? pe : K,
428
+ getCaptchaHeader: I,
431
429
  invalidateCaptcha: u,
432
- inputNotification: tt,
433
- showInputNotification: ae,
434
- clearInputNotification: st
430
+ inputNotification: et,
431
+ showInputNotification: ne,
432
+ clearInputNotification: tt
435
433
  };
436
434
  };
437
435
  export {
438
- Yt as useInkeepChat
436
+ Xt as useInkeepChat
439
437
  };
@@ -0,0 +1 @@
1
+ "use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),Y=require("../../node_modules/.pnpm/@hookform_resolvers@5.2.2_react-hook-form@7.70.0_react@19.3.0-canary-87ae75b3-20260128_/node_modules/@hookform/resolvers/zod/dist/zod.cjs"),b=require("react"),y=require("react-hook-form"),x=require("zod"),f=require("../utils.cjs"),E=require("./ui/recipes/button.cjs"),S="border border-gray-200 dark:border-white-alpha-200 rounded-lg mb-3 p-4 bg-white dark:bg-gray-dark-900",q="text-xs font-medium text-gray-700 dark:text-white-alpha-700 select-none",$="text-xs px-2 py-1.5 rounded-md border bg-white dark:bg-gray-dark-900 text-gray-800 dark:text-white-alpha-800 border-gray-200 dark:border-white-alpha-200 focus:outline-none focus:ring-1 focus:ring-inkeep-expanded-primary-500 disabled:opacity-60 disabled:cursor-not-allowed",F="text-2xs text-gray-500 dark:text-white-alpha-500 mt-0.5",z="text-2xs text-red-600 dark:text-red-400 mt-0.5",M=e=>{switch(e){case"short":return"w-20";case"medium":return"w-48";default:return"w-full"}};function _(e){return!(e.length>200||/[+*?}]\)?[+*?{]/.test(e))}function H(e){const a=e.required!==!1;switch(e.type){case"boolean":return x.z.boolean().default(!1);case"number":{let t=x.z.number();e.validation?.min!==void 0&&(t=t.min(e.validation.min)),e.validation?.max!==void 0&&(t=t.max(e.validation.max));const i=a?t:t.optional();return x.z.preprocess(s=>{if(!(s===""||s===null||s===void 0)){if(typeof s=="string"){const l=Number(s);return Number.isNaN(l)?s:l}return s}},i)}case"email":{let t=x.z.string().email("Enter a valid email");return e.validation?.minLength!==void 0&&(t=t.min(e.validation.minLength)),e.validation?.maxLength!==void 0&&(t=t.max(e.validation.maxLength)),a?t.min(1,"Required"):t.or(x.z.literal(""))}case"date":{const t=x.z.string();return a?t.min(1,"Required"):t.optional()}default:{let t=x.z.string();if(e.validation?.minLength!==void 0&&(t=t.min(e.validation.minLength)),e.validation?.maxLength!==void 0&&(t=t.max(e.validation.maxLength)),e.validation?.pattern&&_(e.validation.pattern))try{t=t.regex(new RegExp(e.validation.pattern),"Invalid format")}catch{}if(e.options&&e.options.length>0){const i=e.options.map(l=>l.value),s=x.z.enum(i);return a?s:s.or(x.z.literal(""))}return a?t.min(1,"Required"):t}}}function J(e){let a;switch(e.itemType){case"number":a=x.z.preprocess(i=>i===""||i===null||i===void 0?void 0:Number(i),x.z.number());break;case"email":a=x.z.string().email();break;case"boolean":a=x.z.boolean();break;default:a=x.z.string().min(1)}let t=x.z.array(a);return e.min!==void 0&&(t=t.min(e.min,`At least ${e.min}`)),e.max!==void 0&&(t=t.max(e.max,`At most ${e.max}`)),t}function K(e){return e.kind==="leaf"?H(e):e.kind==="list"?J(e):e.kind==="groupList"?W(e):B(e.children)}function B(e){const a={};for(const t of e)a[t.id]=K(t);return x.z.object(a)}function W(e){const a=B(e.item.children);let t=x.z.array(a);return e.min!==void 0&&(t=t.min(e.min,`At least ${e.min}`)),e.max!==void 0&&(t=t.max(e.max,`At most ${e.max}`)),t}function Q(e){return B(e)}function X(e){if(e.default!==void 0)return e.default;if(e.options&&e.options.length>0)return e.options[0]?.value??"";switch(e.type){case"boolean":return!1;case"number":return"";default:return""}}function L(e){const a={};for(const t of e)if(t.kind==="leaf")a[t.id]=X(t);else if(t.kind==="list")a[t.id]=[];else if(t.kind==="groupList"){const i=t.min??0,s=[];for(let l=0;l<i;l++)s.push(L(t.item.children));a[t.id]=s}else a[t.id]=L(t.children);return a}function V(e,a=[]){for(const t of e){if(t.kind==="leaf")return[...a,t.id];if(t.kind==="group"){const i=V(t.children,[...a,t.id]);if(i)return i}}}function Z(e,a=[]){for(const t of e)if(t.kind==="leaf"){if(!(t.default!==void 0&&t.default!==""))return[...a,t.id]}else if(t.kind==="group"){const i=Z(t.children,[...a,t.id]);if(i)return i}}function ee(e){return Z(e)??V(e)}const re=({input:e,output:a,status:t,errorText:i,onSubmit:s,onDecline:l})=>t==="pending"?r.jsx("div",{className:S,children:r.jsxs("div",{className:"space-y-3 animate-pulse",children:[r.jsx("div",{className:"h-3 w-32 bg-gray-100 dark:bg-white-alpha-100 rounded"}),r.jsx("div",{className:"h-7 w-full bg-gray-100 dark:bg-white-alpha-100 rounded"}),r.jsx("div",{className:"h-7 w-full bg-gray-100 dark:bg-white-alpha-100 rounded"})]})}):t==="declined"?r.jsx("div",{className:S,children:r.jsx("div",{className:"text-xs font-medium text-gray-700 dark:text-white-alpha-700",children:i||"User declined to provide input."})}):t==="submitted"&&a?r.jsx(te,{output:a}):!e||!Array.isArray(e.form)?r.jsx("div",{className:S,children:r.jsx("div",{className:"text-xs text-gray-500 dark:text-white-alpha-500 italic",children:"Preparing form…"})}):r.jsx(ae,{input:e,onSubmit:s??(()=>{}),onDecline:l??(()=>{})}),te=({output:e})=>r.jsxs("div",{className:S,children:[e.message&&r.jsx("div",{className:"text-sm font-medium text-gray-800 dark:text-white-alpha-800 mb-3",children:e.message}),r.jsx("div",{className:"space-y-3",children:e.form.map(a=>r.jsx(P,{node:a,value:e.answers[a.id]},a.id))})]}),P=({node:e,value:a})=>{if(e.kind==="group"){const t=a&&typeof a=="object"&&!Array.isArray(a)?a:{};return r.jsxs("fieldset",{className:"border-l-2 border-gray-100 dark:border-white-alpha-100 pl-3",children:[e.label&&r.jsx("legend",{className:"text-xs font-semibold text-gray-700 dark:text-white-alpha-700 mb-2",children:e.label}),r.jsx("div",{className:"space-y-3",children:e.children.map(i=>r.jsx(P,{node:i,value:t[i.id]},i.id))})]})}if(e.kind==="list"){const t=Array.isArray(a)?a:[];return r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsx("span",{className:q,children:e.label}),r.jsx("div",{className:"flex flex-wrap gap-1",children:t.length===0?r.jsx("span",{className:"text-2xs text-gray-500 dark:text-white-alpha-500 italic",children:"(none)"}):t.map((i,s)=>{const l=G(i);return r.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-gray-100 dark:bg-white-alpha-100 text-2xs text-gray-700 dark:text-white-alpha-700",children:l},`${l}-${s}`)})})]})}if(e.kind==="groupList"){const t=Array.isArray(a)?a:[];return r.jsxs("fieldset",{className:"border-l-2 border-gray-100 dark:border-white-alpha-100 pl-3",children:[r.jsx("legend",{className:"text-xs font-semibold text-gray-700 dark:text-white-alpha-700 mb-2",children:e.label}),r.jsx("div",{className:"space-y-2",children:t.length===0?r.jsx("span",{className:"text-2xs text-gray-500 dark:text-white-alpha-500 italic",children:"(none)"}):t.map((i,s)=>{const l=i&&typeof i=="object"&&!Array.isArray(i)?i:{};return r.jsxs("div",{className:"pl-2 py-1 rounded-md bg-gray-50/50 dark:bg-white-alpha-50/50",children:[r.jsxs("span",{className:"text-2xs font-medium text-gray-500 dark:text-white-alpha-500 uppercase tracking-wider",children:["#",s+1]}),r.jsx("div",{className:"mt-1 space-y-2",children:e.item.children.map(n=>r.jsx(P,{node:n,value:l[n.id]},n.id))})]},`row-${s}-${e.id}`)})})]})}return r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsx("span",{className:q,children:e.label}),r.jsx("span",{className:f.cn($,M(e.width),"inline-block opacity-70"),"aria-disabled":"true",children:a===void 0||a===""?r.jsx("span",{className:"italic text-gray-500 dark:text-white-alpha-500",children:"(empty)"}):e.type==="boolean"?a?"Yes":"No":String(a)})]})},ae=({input:e,onSubmit:a,onDecline:t})=>{const i=e.form??[],s=b.useMemo(()=>Q(i),[i]),l=b.useMemo(()=>L(i),[i]),n=b.useMemo(()=>ee(i),[i]),h=Y.zodResolver(s),m=y.useForm({resolver:h,defaultValues:l,mode:"onBlur",reValidateMode:"onChange",shouldFocusError:!0}),A=m.handleSubmit(c=>{a(c)});return r.jsx(y.FormProvider,{...m,children:r.jsxs("form",{onSubmit:A,className:S,noValidate:!0,"aria-label":e.message||"User input form",children:[e.message&&r.jsx("div",{className:"text-sm font-medium text-gray-800 dark:text-white-alpha-800 mb-3",children:e.message}),r.jsx("div",{className:"space-y-3",children:i.map(c=>r.jsx(D,{node:c,pathPrefix:"",autoFocusPath:n},c.id))}),r.jsxs("div",{className:"flex items-center justify-end gap-2 mt-4",children:[r.jsx("button",{type:"button",className:E.button({size:"xs",variant:"ghost"}),onClick:t,disabled:m.formState.isSubmitting,children:"Cancel"}),r.jsx("button",{type:"submit",className:E.button({size:"xs",variant:"primaryFilled"}),disabled:m.formState.isSubmitting,children:m.formState.isSubmitting?"Submitting…":"Submit"})]})]})})},D=({node:e,pathPrefix:a,autoFocusPath:t})=>{const i=a?`${a}.${e.id}`:e.id;return e.kind==="group"?r.jsx(ie,{node:e,path:i,autoFocusPath:t}):e.kind==="list"?r.jsx(ne,{node:e,path:i}):e.kind==="groupList"?r.jsx(ce,{node:e,path:i,autoFocusPath:t}):r.jsx(se,{node:e,path:i,autoFocusPath:t})},ie=({node:e,path:a,autoFocusPath:t})=>r.jsxs("fieldset",{className:"border-l-2 border-gray-100 dark:border-white-alpha-100 pl-3","aria-labelledby":e.label?`group-${a}`:void 0,children:[e.label&&r.jsx("legend",{id:`group-${a}`,className:"text-xs font-semibold text-gray-700 dark:text-white-alpha-700 mb-2 px-1",children:e.label}),e.helpText&&r.jsx("div",{className:F,children:e.helpText}),r.jsx("div",{className:"space-y-3",children:e.children.map(i=>r.jsx(D,{node:i,pathPrefix:a,autoFocusPath:t},i.id))})]}),se=({node:e,path:a,autoFocusPath:t})=>{const{register:i,control:s}=y.useFormContext(),l=e.required!==!1,n=`askuser-${a.replace(/\./g,"-")}`,h=`${n}-error`,m=`${n}-help`,{errors:A}=y.useFormState({control:s,name:a}),c=U(A,a),j=b.useMemo(()=>t!==void 0&&t.join(".")===a,[t,a]),k=r.jsxs("label",{htmlFor:n,className:q,children:[e.label,l&&r.jsx("span",{"aria-label":"required",className:"text-red-500 ml-0.5",children:"*"})]}),p=r.jsxs(r.Fragment,{children:[e.helpText&&r.jsx("div",{id:m,className:F,children:e.helpText}),c&&r.jsx("div",{id:h,role:"alert",className:z,children:c})]});if(e.type==="boolean")return r.jsx(y.Controller,{name:a,control:s,render:({field:d})=>r.jsxs("div",{className:"flex items-start gap-3",children:[r.jsx("button",{type:"button",role:"switch",id:n,"aria-checked":!!d.value,"aria-required":l,"aria-invalid":!!c,"aria-describedby":f.cn(e.helpText&&m,c&&h)||void 0,onClick:()=>d.onChange(!d.value),onBlur:d.onBlur,ref:j?R:void 0,className:f.cn("inline-flex h-5 w-9 items-center rounded-full border transition-colors mt-0.5","border-gray-200 dark:border-white-alpha-200","focus:outline-none focus:ring-1 focus:ring-inkeep-expanded-primary-500",d.value?"bg-inkeep-expanded-primary-500":"bg-gray-100 dark:bg-white-alpha-100"),children:r.jsx("span",{className:f.cn("inline-block h-3.5 w-3.5 rounded-full bg-white shadow transform transition-transform",d.value?"translate-x-4":"translate-x-0.5")})}),r.jsxs("div",{className:"flex flex-col flex-1",children:[k,p]})]})});if(e.type==="multiline")return r.jsxs("div",{className:"flex flex-col gap-1",children:[k,r.jsx(y.Controller,{name:a,control:s,render:({field:d})=>r.jsx(le,{id:n,value:d.value??"",onChange:u=>d.onChange(u.target.value),onBlur:d.onBlur,placeholder:e.placeholder,autoComplete:e.autocomplete??"off","aria-required":l,"aria-invalid":!!c,"aria-describedby":f.cn(e.helpText&&m,c&&h)||void 0,focusOnMount:j,className:f.cn($,"w-full resize-none min-h-[60px]")})}),p]});if(e.options&&e.options.length>0){const d=i(a);return r.jsxs("div",{className:"flex flex-col gap-1",children:[k,r.jsxs("select",{id:n,...d,ref:u=>{d.ref(u),j&&R(u)},"aria-required":l,"aria-invalid":!!c,"aria-describedby":f.cn(e.helpText&&m,c&&h)||void 0,className:f.cn($,M(e.width)),children:[!l&&r.jsx("option",{value:"",children:"—"}),e.options.map(u=>r.jsx("option",{value:u.value,children:u.label??u.value},u.value))]}),p]})}const w=e.type==="date"?"date":e.type==="email"?"email":"text",T=e.type==="number"?"numeric":void 0,N=i(a);return r.jsxs("div",{className:"flex flex-col gap-1",children:[k,r.jsx("input",{id:n,type:w,inputMode:T,placeholder:e.placeholder,autoComplete:e.autocomplete??"off","aria-required":l,"aria-invalid":!!c,"aria-describedby":f.cn(e.helpText&&m,c&&h)||void 0,...N,ref:d=>{N.ref(d),j&&R(d)},className:f.cn($,M(e.width))}),p]})};function R(e){e&&requestAnimationFrame(()=>{typeof e.focus=="function"&&e.focus()})}const le=({value:e,className:a,focusOnMount:t,...i})=>{const s=b.useRef(null);return b.useEffect(()=>{const l=s.current;if(!l)return;l.style.height="0";const n=Math.min(l.scrollHeight,200);l.style.height=`${n}px`},[e]),b.useEffect(()=>{t&&requestAnimationFrame(()=>s.current?.focus())},[]),r.jsx("textarea",{ref:s,value:e,className:a,rows:3,...i})},ne=({node:e,path:a})=>{const{control:t,setValue:i,trigger:s}=y.useFormContext(),l=y.useWatch({control:t,name:a}),n=Array.isArray(l)?l:[],h=`askuser-${a.replace(/\./g,"-")}`,m=`${h}-error`,{errors:A}=y.useFormState({control:t,name:a}),c=U(A,a),j=(e.min??0)>0,k=e.max??Number.POSITIVE_INFINITY,p=n.length>=k,[w,T]=b.useState(""),N=b.useCallback(o=>{i(a,o,{shouldValidate:!0,shouldDirty:!0,shouldTouch:!0})},[i,a]),d=b.useCallback(o=>{N([...n,o])},[n,N]),u=b.useCallback(o=>{N(n.filter((v,g)=>g!==o))},[n,N]),C=b.useCallback(()=>{const o=w.trim();if(!o||p)return;let v;if(e.itemType==="number"){const g=Number(o);if(Number.isNaN(g))return;v=g}else e.itemType==="boolean"?v=o==="true":v=o;d(v),T("")},[w,p,e.itemType,d]),O=o=>{o.key==="Enter"||o.key===","?(o.preventDefault(),C()):o.key==="Backspace"&&w===""&&n.length>0&&u(n.length-1)};return e.options&&e.options.length>0?r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsxs("label",{htmlFor:h,className:q,children:[e.label,j&&r.jsx("span",{"aria-label":"required",className:"text-red-500 ml-0.5",children:"*"})]}),r.jsx("fieldset",{className:"flex flex-wrap gap-1.5",id:h,children:e.options.map(o=>{const v=n.findIndex(I=>I===o.value),g=v>=0;return r.jsx("button",{type:"button","aria-pressed":g,onClick:()=>{g?u(v):p||d(o.value),s(a)},className:f.cn("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-2xs border transition-colors",g?"bg-inkeep-expanded-primary-500 text-white border-inkeep-expanded-primary-500":"bg-white dark:bg-gray-dark-900 text-gray-700 dark:text-white-alpha-700 border-gray-200 dark:border-white-alpha-200 hover:bg-gray-50 dark:hover:bg-white-alpha-50"),children:o.label??o.value},o.value)})}),e.helpText&&r.jsx("div",{className:F,children:e.helpText}),c&&r.jsx("div",{id:m,role:"alert",className:z,children:c})]}):r.jsxs("div",{className:"flex flex-col gap-1",children:[r.jsxs("label",{htmlFor:h,className:q,children:[e.label,j&&r.jsx("span",{"aria-label":"required",className:"text-red-500 ml-0.5",children:"*"})]}),r.jsxs("div",{className:f.cn($,"w-full flex flex-wrap gap-1 items-center cursor-text min-h-[32px] py-1"),onClick:()=>document.getElementById(h)?.focus(),children:[n.map((o,v)=>{const g=G(o);return r.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-gray-100 dark:bg-white-alpha-100 text-2xs text-gray-700 dark:text-white-alpha-700",children:[g,r.jsx("button",{type:"button",onClick:I=>{I.stopPropagation(),u(v)},"aria-label":`Remove ${g}`,className:"text-gray-500 hover:text-gray-700 dark:text-white-alpha-500 dark:hover:text-white-alpha-700",children:"×"})]},`${g}-${v}`)}),r.jsx("input",{id:h,type:e.itemType==="number"?"text":e.itemType==="email"?"email":"text",inputMode:e.itemType==="number"?"numeric":void 0,value:w,placeholder:n.length===0?e.placeholder??"Type and press Enter…":"",onChange:o=>T(o.target.value),onKeyDown:O,onBlur:C,"aria-required":j,"aria-invalid":!!c,"aria-describedby":c?m:void 0,disabled:p,className:"flex-1 min-w-[80px] outline-none bg-transparent text-xs"})]}),e.helpText&&r.jsx("div",{className:F,children:e.helpText}),c&&r.jsx("div",{id:m,role:"alert",className:z,children:c})]})};function G(e){if(e==null)return"";if(typeof e=="string"||typeof e=="number"||typeof e=="boolean")return String(e);try{return JSON.stringify(e)}catch{return""}}const ce=({node:e,path:a,autoFocusPath:t})=>{const{control:i}=y.useFormContext(),{errors:s}=y.useFormState({control:i,name:a}),{fields:l,append:n,remove:h}=y.useFieldArray({control:i,name:a}),m=`askuser-${a.replace(/\./g,"-")}`,A=`${m}-error`,c=U(s,a),j=(e.min??0)>0,k=e.max??Number.POSITIVE_INFINITY,p=l.length>=k,w=e.min??0,T=l.length>w,N=b.useCallback(()=>{p||n(L(e.item.children))},[n,p,e.item.children]);return r.jsxs("fieldset",{className:"border-l-2 border-gray-100 dark:border-white-alpha-100 pl-3","aria-labelledby":`grouplist-${m}`,children:[r.jsxs("legend",{id:`grouplist-${m}`,className:"text-xs font-semibold text-gray-700 dark:text-white-alpha-700 mb-2 px-1",children:[e.label,j&&r.jsx("span",{"aria-label":"required",className:"text-red-500 ml-0.5",children:"*"})]}),e.helpText&&r.jsx("div",{className:F,children:e.helpText}),r.jsx("div",{className:"space-y-3",children:l.length===0?r.jsxs("div",{className:"text-2xs text-gray-500 dark:text-white-alpha-500 italic",children:["No rows yet — click “",e.addLabel??"Add row","” below."]}):l.map((d,u)=>r.jsxs("div",{className:"relative pl-2 py-2 rounded-md bg-gray-50/50 dark:bg-white-alpha-50/50",children:[r.jsxs("div",{className:"flex items-start justify-between mb-1",children:[r.jsxs("span",{className:"text-2xs font-medium text-gray-500 dark:text-white-alpha-500 uppercase tracking-wider",children:["#",u+1]}),T&&r.jsx("button",{type:"button",onClick:()=>h(u),"aria-label":`Remove row ${u+1}`,className:"text-2xs text-gray-500 hover:text-red-500 dark:text-white-alpha-500",children:"Remove"})]}),r.jsx("div",{className:"space-y-3",children:e.item.children.map(C=>r.jsx(D,{node:C,pathPrefix:`${a}.${u}`,autoFocusPath:t},C.id))})]},d.id))}),r.jsx("div",{className:"mt-2",children:r.jsxs("button",{type:"button",onClick:N,disabled:p,className:f.cn(E.button({size:"xs",variant:"outline"})),children:["+ ",e.addLabel??"Add row"]})}),c&&r.jsx("div",{id:A,role:"alert",className:z,children:c})]})};function U(e,a){const t=a.split(".");let i=e;for(const s of t)if(i&&typeof i=="object"&&s in i)i=i[s];else return;if(i&&typeof i=="object"&&"message"in i){const s=i.message;return typeof s=="string"?s:void 0}}exports.AskUserForm=re;