@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.
- 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
- 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
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.cjs +1 -0
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/core.js +49 -0
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.cjs +1 -0
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/errors.js +19 -0
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/parse.cjs +1 -0
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/parse.js +28 -0
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.cjs +1 -0
- package/dist/node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/util.js +23 -0
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.cjs +2 -2
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.d.ts +13 -0
- package/dist/primitives/components/embedded-chat/use-inkeep-chat.js +181 -183
- package/dist/styled/components/ask-user-form.cjs +1 -0
- package/dist/styled/components/ask-user-form.d.ts +96 -0
- package/dist/styled/components/ask-user-form.js +672 -0
- package/dist/styled/components/message.cjs +1 -1
- package/dist/styled/components/message.js +272 -210
- package/dist/styled/inkeep.css.cjs +78 -0
- package/dist/styled/inkeep.css.js +78 -0
- package/package.json +2 -1
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useChat as
|
|
3
|
-
import { normalizeFileType as
|
|
4
|
-
import { DefaultChatTransport as
|
|
5
|
-
import { useRef as c, useEffect as x, useState as F, useMemo as
|
|
6
|
-
import { useModal as
|
|
7
|
-
import { useOptionalChatBubble as
|
|
8
|
-
import { useOptionalSidebarChat as
|
|
9
|
-
import { useInkeepConfig as
|
|
10
|
-
import { useCaptcha as
|
|
11
|
-
import { useMediaQuery as
|
|
12
|
-
import { useAnonymousSession as
|
|
13
|
-
import { useAuthToken as
|
|
14
|
-
import { useConversationLoader as
|
|
15
|
-
import { useInitialConversation as
|
|
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
|
|
18
|
-
import { useChatForm as
|
|
19
|
-
import { useWidget as
|
|
20
|
-
import { useControllableState as
|
|
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
|
|
23
|
-
import { resolveStreamingAuthError as Tt, DEFAULT_ERROR_MESSAGE as
|
|
24
|
-
const
|
|
25
|
-
const { baseSettings: q, aiChatSettings: y } =
|
|
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
|
-
}),
|
|
28
|
+
}), _e = ct(), Ne = ut(), Pe = pt(), { logEvent: m } = Ct(), { setConversationId: Le, emitToParent: O } = It(), le = c(i);
|
|
29
29
|
x(() => {
|
|
30
|
-
const e =
|
|
31
|
-
|
|
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(""),
|
|
40
|
-
shouldBypassCaptcha:
|
|
41
|
-
filters:
|
|
42
|
-
privacyPreferences:
|
|
43
|
-
userProperties: z
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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:
|
|
50
|
-
context:
|
|
51
|
-
headers:
|
|
48
|
+
agentUrl: qe,
|
|
49
|
+
context: me,
|
|
50
|
+
headers: ge,
|
|
52
51
|
appId: S,
|
|
53
52
|
apiKey: h,
|
|
54
53
|
files: b
|
|
55
|
-
} = y,
|
|
54
|
+
} = y, ze = _e?.isOpen ?? Ne?.isOpen ?? Pe?.isOpen ?? !0, { getCaptchaHeader: I, invalidate: u } = ft({
|
|
56
55
|
baseUrl: N,
|
|
57
|
-
shouldBypassCaptcha:
|
|
58
|
-
shouldMakeInitialRequest:
|
|
59
|
-
}),
|
|
60
|
-
|
|
61
|
-
const
|
|
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:
|
|
63
|
+
getCaptchaHeader: I,
|
|
65
64
|
invalidateCaptcha: u,
|
|
66
|
-
optOutAllAnalytics:
|
|
67
|
-
enabled: !d &&
|
|
68
|
-
}),
|
|
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:
|
|
72
|
-
getCaptchaHeader:
|
|
70
|
+
authToken: ye,
|
|
71
|
+
getCaptchaHeader: I,
|
|
73
72
|
invalidateCaptcha: u,
|
|
74
|
-
refreshSession: h || d ? void 0 :
|
|
75
|
-
}), [
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
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
|
-
|
|
89
|
-
}, [
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
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 (
|
|
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 ??
|
|
96
|
+
return t.detail ?? t.error?.message ?? Oe;
|
|
100
97
|
} catch {
|
|
101
|
-
return e.message?.trim() ||
|
|
98
|
+
return e.message?.trim() || Oe;
|
|
102
99
|
}
|
|
103
100
|
case 401:
|
|
104
|
-
return
|
|
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
|
|
105
|
+
return Mt;
|
|
109
106
|
default:
|
|
110
|
-
return
|
|
107
|
+
return ie;
|
|
111
108
|
}
|
|
112
|
-
}, [P,
|
|
113
|
-
() => new
|
|
114
|
-
api:
|
|
109
|
+
}, [P, Z] = F([]), Je = Fe(
|
|
110
|
+
() => new it({
|
|
111
|
+
api: ve,
|
|
115
112
|
headers: () => {
|
|
116
|
-
const e = h ??
|
|
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
|
-
...
|
|
120
|
+
...Q.current ? { "inkeep-filters": Q.current } : {},
|
|
124
121
|
...V.current ? { "x-inkeep-user-properties": V.current } : {},
|
|
125
|
-
...
|
|
126
|
-
...Re.current
|
|
122
|
+
...Se.current
|
|
127
123
|
};
|
|
128
124
|
},
|
|
129
125
|
prepareSendMessagesRequest: async (e) => {
|
|
130
|
-
const a = await
|
|
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:
|
|
144
|
+
requestContext: me
|
|
149
145
|
}
|
|
150
146
|
}),
|
|
151
|
-
[
|
|
147
|
+
[ve, me, S, h]
|
|
152
148
|
), {
|
|
153
149
|
messages: L,
|
|
154
|
-
sendMessage:
|
|
155
|
-
addToolApprovalResponse:
|
|
156
|
-
|
|
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
|
-
} =
|
|
161
|
-
transport:
|
|
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 =
|
|
177
|
+
const a = ce || h ? null : Tt(e);
|
|
181
178
|
if (a !== null && v.current < 1) {
|
|
182
179
|
v.current++;
|
|
183
|
-
const n =
|
|
180
|
+
const n = W.current, s = j.current;
|
|
184
181
|
(async () => {
|
|
185
|
-
if (a === "session" &&
|
|
186
|
-
const l = await
|
|
182
|
+
if (a === "session" && de) {
|
|
183
|
+
const l = await pe();
|
|
187
184
|
if (!l) throw new Error("Auth token refresh failed");
|
|
188
|
-
|
|
185
|
+
J.current = l;
|
|
189
186
|
} else if (a === "session") {
|
|
190
|
-
const l = await
|
|
191
|
-
l && (
|
|
187
|
+
const l = await K();
|
|
188
|
+
l && (G.current = l);
|
|
192
189
|
} else
|
|
193
190
|
u();
|
|
194
191
|
if (n) {
|
|
195
|
-
|
|
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
|
-
}),
|
|
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],
|
|
208
|
-
if (!
|
|
209
|
-
const
|
|
210
|
-
return
|
|
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:
|
|
214
|
-
}) :
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
236
|
-
n && A(n),
|
|
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
|
-
}),
|
|
245
|
+
}), Ie = c(d);
|
|
249
246
|
x(() => {
|
|
250
|
-
const e =
|
|
251
|
-
|
|
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
|
|
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 ||
|
|
262
|
-
}, [L,
|
|
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 (
|
|
266
|
-
|
|
262
|
+
if (re.current === B) {
|
|
263
|
+
re.current = null;
|
|
267
264
|
return;
|
|
268
265
|
}
|
|
269
|
-
|
|
266
|
+
T(B);
|
|
270
267
|
}
|
|
271
268
|
}, [B]);
|
|
272
|
-
const
|
|
269
|
+
const Ye = () => T(null), { inputNotification: et, showInputNotification: ne, clearInputNotification: tt } = Rt(), Ee = c(null);
|
|
273
270
|
x(() => {
|
|
274
|
-
|
|
271
|
+
Ue?.(C);
|
|
275
272
|
}, [C]);
|
|
276
|
-
const
|
|
277
|
-
e.key === "Enter" && !e.shiftKey && !
|
|
278
|
-
},
|
|
279
|
-
if (
|
|
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
|
-
|
|
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)),
|
|
289
|
-
const p =
|
|
290
|
-
|
|
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 =
|
|
298
|
-
return new Promise((
|
|
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
|
-
|
|
299
|
+
k(new Error(`Failed to read file "${r.name}"`));
|
|
303
300
|
return;
|
|
304
301
|
}
|
|
305
|
-
|
|
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 = () =>
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
327
|
+
j.current = {
|
|
331
328
|
content: e,
|
|
332
329
|
body: { conversationId: t },
|
|
333
330
|
files: s
|
|
334
|
-
},
|
|
331
|
+
}, X(n, {
|
|
335
332
|
body: { conversationId: t }
|
|
336
333
|
});
|
|
337
|
-
},
|
|
334
|
+
}, rt = $(
|
|
338
335
|
(e) => {
|
|
339
|
-
v.current = 0,
|
|
336
|
+
v.current = 0, W.current = e, te(!1), Y(e);
|
|
340
337
|
},
|
|
341
|
-
[
|
|
342
|
-
),
|
|
343
|
-
|
|
338
|
+
[Y]
|
|
339
|
+
), ae = $(() => {
|
|
340
|
+
te(!0), D().then(() => {
|
|
344
341
|
O("aborted", { conversationId: i });
|
|
345
342
|
});
|
|
346
|
-
}, [D, i, O]),
|
|
347
|
-
|
|
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
|
-
},
|
|
350
|
+
}, w = $(
|
|
354
351
|
(e, a) => {
|
|
355
|
-
|
|
352
|
+
T(null), f(a), g(e), u(), R.current = void 0;
|
|
356
353
|
},
|
|
357
354
|
[f, g, u]
|
|
358
|
-
),
|
|
355
|
+
), Me = $(
|
|
359
356
|
async (e, a) => {
|
|
360
|
-
|
|
357
|
+
ae(), w(e, []), Ae(!0);
|
|
361
358
|
try {
|
|
362
|
-
const t = await
|
|
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
|
|
374
|
+
return w(e, n), !0;
|
|
378
375
|
} finally {
|
|
379
|
-
a?.aborted ||
|
|
376
|
+
a?.aborted || Ae(!1);
|
|
380
377
|
}
|
|
381
378
|
},
|
|
382
|
-
[
|
|
379
|
+
[w, Ce, ae]
|
|
383
380
|
);
|
|
384
|
-
|
|
381
|
+
yt({
|
|
385
382
|
conversationId: y.conversationId,
|
|
386
|
-
effectiveAuthToken:
|
|
387
|
-
loadAndRestoreSession:
|
|
388
|
-
onLoadFailed: () =>
|
|
383
|
+
effectiveAuthToken: ye,
|
|
384
|
+
loadAndRestoreSession: Me,
|
|
385
|
+
onLoadFailed: () => w("", [])
|
|
389
386
|
});
|
|
390
|
-
const { openForm:
|
|
391
|
-
return
|
|
392
|
-
submitMessage:
|
|
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:
|
|
393
|
+
clearChat: ke,
|
|
397
394
|
openForm: (e) => {
|
|
398
|
-
|
|
395
|
+
ot?.setView("chat"), nt(e, void 0);
|
|
399
396
|
},
|
|
400
397
|
focusInput: () => {
|
|
401
|
-
|
|
398
|
+
Ee.current?.focus();
|
|
402
399
|
}
|
|
403
400
|
})), {
|
|
404
401
|
messages: L,
|
|
405
|
-
sendMessage:
|
|
406
|
-
addToolApprovalResponse:
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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:
|
|
415
|
-
handleInputKeyDown:
|
|
416
|
-
handleSubmit:
|
|
417
|
-
stop:
|
|
418
|
-
clear:
|
|
419
|
-
inputRef:
|
|
420
|
-
isMobile:
|
|
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:
|
|
423
|
-
isNewChat:
|
|
420
|
+
setFiles: Z,
|
|
421
|
+
isNewChat: Qe,
|
|
424
422
|
conversationId: i,
|
|
425
|
-
restoreSession:
|
|
426
|
-
loadAndRestoreSession:
|
|
427
|
-
isSessionLoading:
|
|
428
|
-
authToken: d ? _ :
|
|
429
|
-
refreshSession: d ?
|
|
430
|
-
getCaptchaHeader:
|
|
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:
|
|
433
|
-
showInputNotification:
|
|
434
|
-
clearInputNotification:
|
|
430
|
+
inputNotification: et,
|
|
431
|
+
showInputNotification: ne,
|
|
432
|
+
clearInputNotification: tt
|
|
435
433
|
};
|
|
436
434
|
};
|
|
437
435
|
export {
|
|
438
|
-
|
|
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;
|