@tomny-dev/uzi 0.20.0 → 0.20.1

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 (48) hide show
  1. package/dist/components/ai-chat/AIChat.d.ts +2 -25
  2. package/dist/components/ai-chat/AIChat.d.ts.map +1 -1
  3. package/dist/components/ai-chat/AIChatParts.d.ts +32 -0
  4. package/dist/components/ai-chat/AIChatParts.d.ts.map +1 -0
  5. package/dist/components/ai-chat/activityLabel.d.ts +20 -0
  6. package/dist/components/ai-chat/activityLabel.d.ts.map +1 -0
  7. package/dist/components/ai-chat/activityLabel.test.d.ts +2 -0
  8. package/dist/components/ai-chat/activityLabel.test.d.ts.map +1 -0
  9. package/dist/index.cjs +6 -5
  10. package/dist/index.js +4 -3
  11. package/dist/index59.js +8 -2
  12. package/dist/index59.js.map +1 -1
  13. package/dist/index60.cjs +10 -1
  14. package/dist/index60.cjs.map +1 -1
  15. package/dist/index60.js +1 -1
  16. package/dist/index60.js.map +1 -1
  17. package/dist/index61.cjs +1 -1
  18. package/dist/index61.cjs.map +1 -1
  19. package/dist/index84.js +3 -556
  20. package/dist/index84.js.map +1 -1
  21. package/dist/index85.cjs +6 -556
  22. package/dist/index85.cjs.map +1 -1
  23. package/dist/index85.js +11 -34
  24. package/dist/index85.js.map +1 -1
  25. package/dist/index86.cjs +11 -49
  26. package/dist/index86.cjs.map +1 -1
  27. package/dist/index86.js +539 -227
  28. package/dist/index86.js.map +1 -1
  29. package/dist/index87.cjs +541 -226
  30. package/dist/index87.cjs.map +1 -1
  31. package/dist/index87.js +33 -15
  32. package/dist/index87.js.map +1 -1
  33. package/dist/index88.cjs +48 -21
  34. package/dist/index88.cjs.map +1 -1
  35. package/dist/index88.js +250 -29
  36. package/dist/index88.js.map +1 -1
  37. package/dist/index89.cjs +250 -30
  38. package/dist/index89.cjs.map +1 -1
  39. package/dist/index89.js +19 -0
  40. package/dist/index89.js.map +1 -0
  41. package/dist/index90.cjs +25 -0
  42. package/dist/index90.cjs.map +1 -0
  43. package/dist/index90.js +36 -0
  44. package/dist/index90.js.map +1 -0
  45. package/dist/index91.cjs +37 -0
  46. package/dist/index91.cjs.map +1 -0
  47. package/dist/style.css +19 -2
  48. package/package.json +1 -1
package/dist/index87.cjs CHANGED
@@ -1,257 +1,572 @@
1
1
  "use client";
2
- const require_ai_chat_dock_module = require("./index86.cjs");
2
+ const require_ai_chat_module = require("./index84.cjs");
3
+ const require_AIChatParts = require("./index85.cjs");
4
+ const require_activityLabel = require("./index86.cjs");
3
5
  let react = require("react");
4
6
  let react_jsx_runtime = require("react/jsx-runtime");
5
- //#region src/components/ai-chat/AIChatDock.tsx
6
- /**
7
- * Shared chat navigation chrome. Children remain mounted while closed to retain
8
- * the consumer's active AI SDK conversation, pending approvals and attachments.
9
- * The dock never creates a second chat runtime or reads application messages.
10
- * Desktop is deliberately non-modal: Tab can move back into the page.
11
- * On mobile the full-screen modal sheet traps sequential keyboard focus.
12
- */
13
- function AIChatDock({ title, description, launcherLabel, showLauncher = true, panelId: controlledPanelId, externalLauncherId, children, onNewChat, newChatDisabled = false, open, defaultOpen = false, onOpenChange, expanded, defaultExpanded = false, onExpandedChange, className }) {
14
- const autoId = (0, react.useId)();
15
- const panelId = controlledPanelId ?? `uzi-ai-dock-${autoId}`;
16
- const [internalOpen, setInternalOpen] = (0, react.useState)(defaultOpen);
17
- const [internalExpanded, setInternalExpanded] = (0, react.useState)(defaultExpanded);
18
- const isOpen = open ?? internalOpen;
19
- const isExpanded = expanded ?? internalExpanded;
20
- const [mobile, setMobile] = (0, react.useState)(false);
21
- const launcherRef = (0, react.useRef)(null);
22
- const panelRef = (0, react.useRef)(null);
23
- const openerRef = (0, react.useRef)(null);
24
- const wasOpen = (0, react.useRef)(false);
25
- const changeOpen = (next) => {
26
- if (open === void 0) setInternalOpen(next);
27
- onOpenChange?.(next);
28
- };
29
- const changeExpanded = (next) => {
30
- if (expanded === void 0) setInternalExpanded(next);
31
- onExpandedChange?.(next);
32
- if (next && !isOpen) changeOpen(true);
33
- };
34
- (0, react.useEffect)(() => {
35
- if (typeof window.matchMedia !== "function") return;
36
- const media = window.matchMedia("(max-width: 640px)");
37
- const update = () => setMobile(media.matches);
38
- update();
39
- media.addEventListener("change", update);
40
- return () => media.removeEventListener("change", update);
41
- }, []);
7
+ let _assistant_ui_react = require("@assistant-ui/react");
8
+ let _assistant_ui_ai_sdk = require("@assistant-ui/ai-sdk");
9
+ //#region src/components/ai-chat/AIChat.tsx
10
+ var DEFAULT_MESSAGE_LIMIT = 8;
11
+ function AIChat({ api, scope, scopeLabel, fetch: requestFetch, headers, credentials, prepareSendMessagesRequest, sessionKey, messageLimit = DEFAULT_MESSAGE_LIMIT, inputPlaceholder = "Ask a question...", inputAriaLabel = "Message", inputMaxLength = 2e3, components, toolbarActions, showNewChatInToolbar = true, newChatRequestKey, attachments, activityLabel, toolActivityLabels, history, sendAutomaticallyWhen, onClose, className, style }) {
12
+ const [session, setSession] = (0, react.useState)(0);
13
+ const transport = (0, react.useMemo)(() => new _assistant_ui_ai_sdk.AssistantChatTransport({
14
+ api,
15
+ ...scope ? { body: { scope } } : {},
16
+ ...requestFetch ? { fetch: requestFetch } : {},
17
+ ...headers ? { headers } : {},
18
+ ...credentials ? { credentials } : {},
19
+ ...prepareSendMessagesRequest ? { prepareSendMessagesRequest } : {}
20
+ }), [
21
+ api,
22
+ scope,
23
+ requestFetch,
24
+ headers,
25
+ credentials,
26
+ prepareSendMessagesRequest
27
+ ]);
28
+ const config = (0, react.useMemo)(() => (0, _assistant_ui_react.AuiConfig)({ threads: (0, _assistant_ui_ai_sdk.AISDKChat)({
29
+ transport,
30
+ ...sendAutomaticallyWhen ? { sendAutomaticallyWhen } : {}
31
+ }) }), [
32
+ transport,
33
+ session,
34
+ sendAutomaticallyWhen
35
+ ]);
36
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
37
+ className: [require_ai_chat_module.default.container, className].filter(Boolean).join(" "),
38
+ style,
39
+ children: [
40
+ scopeLabel && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
41
+ className: require_ai_chat_module.default.scope,
42
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
43
+ className: require_ai_chat_module.default.scopeLabel,
44
+ children: "Current scope"
45
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: scopeLabel })]
46
+ }),
47
+ onClose && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
48
+ className: require_ai_chat_module.default.closeBtn,
49
+ type: "button",
50
+ onClick: onClose,
51
+ "aria-label": "Close chat",
52
+ children: "✕"
53
+ }),
54
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_assistant_ui_react.AuiProvider, {
55
+ config,
56
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_assistant_ui_react.ThreadPrimitive.Root, {
57
+ className: require_ai_chat_module.default.thread,
58
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChatViewport, {
59
+ messageLimit: Number.isFinite(messageLimit) ? Math.max(1, Math.floor(messageLimit)) : DEFAULT_MESSAGE_LIMIT,
60
+ inputPlaceholder,
61
+ inputAriaLabel,
62
+ inputMaxLength,
63
+ components,
64
+ toolbarActions,
65
+ showNewChatInToolbar,
66
+ newChatRequestKey,
67
+ attachmentOptions: attachments,
68
+ activityLabel,
69
+ toolActivityLabels,
70
+ history,
71
+ onNewChat: () => setSession((previous) => previous + 1)
72
+ })
73
+ })
74
+ }, JSON.stringify([
75
+ api,
76
+ scope,
77
+ sessionKey,
78
+ session
79
+ ]))
80
+ ]
81
+ });
82
+ }
83
+ function ChatViewport({ messageLimit, inputPlaceholder, inputAriaLabel, inputMaxLength, components, toolbarActions, showNewChatInToolbar, newChatRequestKey, attachmentOptions, activityLabel, toolActivityLabels, history, onNewChat }) {
84
+ const chat = (0, _assistant_ui_ai_sdk.useAISDKChat)();
85
+ const [draft, setDraft] = (0, react.useState)("");
86
+ const [selectedFiles, setSelectedFiles] = (0, react.useState)([]);
87
+ const [attachmentError, setAttachmentError] = (0, react.useState)(null);
88
+ const [attachmentPreviews, setAttachmentPreviews] = (0, react.useState)([]);
89
+ const [hydrated, setHydrated] = (0, react.useState)(!history);
90
+ const expectedRestoredId = (0, react.useRef)(null);
91
+ const saveQueue = (0, react.useRef)(Promise.resolve());
92
+ const [approvalBusy, setApprovalBusy] = (0, react.useState)(false);
42
93
  (0, react.useEffect)(() => {
43
- if (isOpen && !wasOpen.current) {
44
- openerRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
45
- panelRef.current?.focus();
46
- } else if (!isOpen && wasOpen.current) {
47
- const previous = openerRef.current;
48
- if (previous?.isConnected && previous !== panelRef.current) previous.focus();
49
- else if (externalLauncherId) document.getElementById(externalLauncherId)?.focus();
50
- else launcherRef.current?.focus();
51
- }
52
- wasOpen.current = isOpen;
53
- }, [isOpen, externalLauncherId]);
94
+ const urls = selectedFiles.map((file) => file.type.startsWith("image/") && typeof URL.createObjectURL === "function" ? URL.createObjectURL(file) : "");
95
+ setAttachmentPreviews(urls);
96
+ return () => urls.forEach((url) => {
97
+ if (url && typeof URL.revokeObjectURL === "function") URL.revokeObjectURL(url);
98
+ });
99
+ }, [selectedFiles]);
100
+ const messages = chat?.messages ?? [];
101
+ const status = chat?.status ?? "ready";
102
+ const isBusy = status === "submitted" || status === "streaming";
103
+ const historyFull = messages.filter((message) => message.role === "user").length >= messageLimit;
104
+ const reportHistoryError = (operation, error) => {
105
+ if (history?.onError) history.onError(operation, error);
106
+ else console.warn(`[Uzi AIChat] History ${operation} failed`);
107
+ };
54
108
  (0, react.useEffect)(() => {
55
- if (!isOpen || !mobile) return;
56
- const previous = document.body.style.overflow;
57
- document.body.style.overflow = "hidden";
109
+ if (!history) return;
110
+ let active = true;
111
+ Promise.resolve().then(() => history.load()).then((restored) => {
112
+ if (!active) return;
113
+ if (Array.isArray(restored)) {
114
+ const valid = restored.filter((message) => typeof message?.id === "string" && (message.role === "user" || message.role === "assistant") && Array.isArray(message.parts));
115
+ expectedRestoredId.current = valid.length ? valid[0].id : null;
116
+ if (valid.length) chat?.setMessages(valid);
117
+ }
118
+ setHydrated(true);
119
+ }).catch((error) => {
120
+ if (active) {
121
+ reportHistoryError("load", error);
122
+ setHydrated(true);
123
+ }
124
+ });
58
125
  return () => {
59
- document.body.style.overflow = previous;
126
+ active = false;
60
127
  };
61
- }, [isOpen, mobile]);
128
+ }, [chat?.setMessages, history]);
62
129
  (0, react.useEffect)(() => {
63
- if (!isOpen) return;
64
- const keydown = (event) => {
65
- if (event.key === "Escape") {
66
- event.preventDefault();
67
- changeOpen(false);
68
- return;
69
- }
70
- if (event.key !== "Tab" || !mobile) return;
71
- const focusable = Array.from(panelRef.current?.querySelectorAll("a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex=\"-1\"])") ?? []).filter((item) => item.tabIndex >= 0 && item.getClientRects().length > 0);
72
- if (!focusable.length) {
73
- event.preventDefault();
74
- panelRef.current?.focus();
130
+ if (!history || !hydrated || isBusy) return;
131
+ const snapshot = messages.filter((message) => message.role === "user" || message.role === "assistant").map((message) => ({
132
+ id: message.id,
133
+ role: message.role,
134
+ parts: message.parts,
135
+ ...require_AIChatParts.isRecord(message.metadata) ? { metadata: message.metadata } : {}
136
+ }));
137
+ if (expectedRestoredId.current) {
138
+ if (!snapshot.some((message) => message.id === expectedRestoredId.current)) return;
139
+ expectedRestoredId.current = null;
140
+ }
141
+ saveQueue.current = saveQueue.current.then(() => history.save(snapshot), () => history.save(snapshot)).then(() => {}, (error) => {
142
+ reportHistoryError("save", error);
143
+ });
144
+ }, [
145
+ history,
146
+ hydrated,
147
+ isBusy,
148
+ messages
149
+ ]);
150
+ const handleSelectedFiles = (files) => {
151
+ if (!attachmentOptions) return;
152
+ const selected = Array.from(files);
153
+ if (selected.length + selectedFiles.length > (attachmentOptions.maxFiles ?? 3)) {
154
+ setAttachmentError("Too many attachments.");
155
+ return;
156
+ }
157
+ if (selected.some((file) => file.size > (attachmentOptions.maxBytesPerFile ?? 5 * 1024 * 1024))) {
158
+ setAttachmentError("An attachment exceeds the size limit.");
159
+ return;
160
+ }
161
+ const allowedTypes = attachmentOptions.accept.split(",").map((item) => item.trim());
162
+ if (selected.some((file) => !allowedTypes.some((allow) => allow === file.type || allow.endsWith("/*") && file.type.startsWith(allow.slice(0, -1))))) {
163
+ setAttachmentError("Unsupported attachment type.");
164
+ return;
165
+ }
166
+ setAttachmentError(null);
167
+ setSelectedFiles((existing) => [...existing, ...selected]);
168
+ };
169
+ const handleSubmit = () => {
170
+ const text = draft.trim();
171
+ if (!chat || !text && selectedFiles.length === 0 || isBusy || historyFull || chat.error || !hydrated || approvalBusy) return;
172
+ const files = selectedFiles.length ? new DataTransfer() : null;
173
+ selectedFiles.forEach((file) => files?.items.add(file));
174
+ const previousDraft = draft;
175
+ const previousFiles = selectedFiles;
176
+ setDraft("");
177
+ setSelectedFiles([]);
178
+ setAttachmentError(null);
179
+ Promise.resolve(chat.sendMessage({
180
+ text,
181
+ ...files ? { files: files.files } : {}
182
+ })).catch(() => {
183
+ setDraft((current) => current || previousDraft);
184
+ setSelectedFiles((current) => current.length ? current : previousFiles);
185
+ });
186
+ };
187
+ const handleNewChat = () => {
188
+ (async () => {
189
+ await chat?.stop();
190
+ if (history) try {
191
+ await saveQueue.current;
192
+ await history.clear();
193
+ } catch (error) {
194
+ reportHistoryError("clear", error);
75
195
  return;
76
196
  }
77
- const first = focusable[0], last = focusable[focusable.length - 1];
78
- if (event.shiftKey && (document.activeElement === first || !panelRef.current?.contains(document.activeElement))) {
79
- event.preventDefault();
80
- last?.focus();
81
- } else if (!event.shiftKey && (document.activeElement === last || !panelRef.current?.contains(document.activeElement))) {
82
- event.preventDefault();
83
- first?.focus();
197
+ onNewChat();
198
+ })();
199
+ };
200
+ const lastNewChatRequestKey = (0, react.useRef)(newChatRequestKey);
201
+ (0, react.useEffect)(() => {
202
+ if (lastNewChatRequestKey.current === newChatRequestKey) return;
203
+ lastNewChatRequestKey.current = newChatRequestKey;
204
+ handleNewChat();
205
+ }, [newChatRequestKey]);
206
+ const handleRetry = () => {
207
+ if (!chat || isBusy) return;
208
+ chat.clearError();
209
+ chat.regenerate();
210
+ };
211
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(AIChatView, {
212
+ messages: messages.filter((message) => message.role === "user" || message.role === "assistant").map((message) => ({
213
+ id: message.id,
214
+ role: message.role,
215
+ parts: message.parts,
216
+ ...require_AIChatParts.isRecord(message.metadata) ? { metadata: message.metadata } : {}
217
+ })),
218
+ status,
219
+ activityLabel,
220
+ toolActivityLabels,
221
+ error: chat?.error,
222
+ draft,
223
+ onDraftChange: setDraft,
224
+ onSend: handleSubmit,
225
+ onStop: () => {
226
+ chat?.stop();
227
+ },
228
+ onRetry: handleRetry,
229
+ onNewChat: handleNewChat,
230
+ showNewChatInToolbar,
231
+ toolbarActions,
232
+ messageLimit,
233
+ attachments: selectedFiles.map((file, index) => ({
234
+ name: file.name,
235
+ size: file.size,
236
+ ...attachmentPreviews[index] ? { previewUrl: attachmentPreviews[index] } : {}
237
+ })),
238
+ onSelectAttachments: attachmentOptions ? handleSelectedFiles : void 0,
239
+ onRemoveAttachment: attachmentOptions ? (index) => setSelectedFiles((files) => files.filter((_, i) => i !== index)) : void 0,
240
+ attachmentAccept: attachmentOptions?.accept,
241
+ attachmentError,
242
+ onToolApproval: chat ? async (id, approved) => {
243
+ if (approvalBusy) return;
244
+ setApprovalBusy(true);
245
+ try {
246
+ await chat.addToolApprovalResponse({
247
+ id,
248
+ approved,
249
+ ...!approved ? { reason: "User denied approval" } : {}
250
+ });
251
+ } finally {
252
+ setApprovalBusy(false);
84
253
  }
85
- };
86
- document.addEventListener("keydown", keydown);
87
- return () => document.removeEventListener("keydown", keydown);
88
- }, [
89
- isOpen,
90
- mobile,
91
- onOpenChange,
92
- open
93
- ]);
254
+ } : void 0,
255
+ inputPlaceholder,
256
+ inputAriaLabel,
257
+ inputMaxLength,
258
+ components
259
+ });
260
+ }
261
+ /**
262
+ * Controlled chat presentation for apps with their own AI SDK/assistant-ui
263
+ * runtime. It does not create providers, transports or chat state. Callbacks
264
+ * are the only way messages/actions leave the view.
265
+ */
266
+ function AIChatView({ messages, status = "ready", activityLabel = "Working on your response…", toolActivityLabels, error, draft = "", onDraftChange, onSend, onStop, onRetry, onNewChat, showNewChatInToolbar = true, messageLimit, inputPlaceholder = "Ask a question...", inputAriaLabel = "Message", inputMaxLength = 2e3, components, attachments, onSelectAttachments, onRemoveAttachment, attachmentAccept, attachmentError, onToolApproval, toolbarActions, header, composerLeading, composerTrailing, composer, emptyState, className, style }) {
267
+ const viewportRef = (0, react.useRef)(null);
268
+ const pinnedToBottom = (0, react.useRef)(true);
269
+ const fileInputRef = (0, react.useRef)(null);
270
+ const approvalRef = (0, react.useRef)(null);
271
+ const [pendingApprovalId, setPendingApprovalId] = (0, react.useState)(null);
272
+ const [approvalError, setApprovalError] = (0, react.useState)(null);
273
+ const respondToApproval = async (id, approved) => {
274
+ if (!onToolApproval || approvalRef.current) return;
275
+ approvalRef.current = id;
276
+ setPendingApprovalId(id);
277
+ setApprovalError(null);
278
+ try {
279
+ await onToolApproval(id, approved);
280
+ } catch {
281
+ setApprovalError("Could not submit approval. Please try again.");
282
+ } finally {
283
+ approvalRef.current = null;
284
+ setPendingApprovalId(null);
285
+ }
286
+ };
287
+ const isBusy = status === "submitted" || status === "streaming";
288
+ const lastMessage = messages[messages.length - 1];
289
+ const assistantParts = lastMessage?.role === "assistant" ? lastMessage.parts.filter(require_AIChatParts.isRecord) : [];
290
+ const lastPart = [...assistantParts].reverse().find((part) => part.type !== "step-start");
291
+ const lastPartType = require_AIChatParts.asString(lastPart?.type) ?? "";
292
+ const activeTool = (lastPartType.startsWith("tool-") || lastPartType === "dynamic-tool") && lastPart?.state !== "output-available" && lastPart?.state !== "output-error" ? lastPart : void 0;
293
+ const hasAnswer = assistantParts.some((part) => part.type === "text" && Boolean(require_AIChatParts.asString(part.text)?.trim()));
294
+ const showActivity = isBusy && (!hasAnswer || Boolean(activeTool));
295
+ const toolName = require_AIChatParts.asString(activeTool?.toolName) ?? lastPartType.replace(/^tool-/, "");
296
+ const approval = activeTool?.approval;
297
+ const approved = require_AIChatParts.isRecord(approval) && approval.approved === true;
298
+ const currentActivityLabel = require_activityLabel.resolveChatActivityLabel({
299
+ toolName: activeTool ? toolName : void 0,
300
+ toolState: require_AIChatParts.asString(activeTool?.state),
301
+ approved,
302
+ toolActivityLabels,
303
+ activityLabel
304
+ });
305
+ const limit = messageLimit != null && Number.isFinite(messageLimit) ? Math.max(1, Math.floor(messageLimit)) : null;
306
+ const historyFull = limit !== null && messages.filter((message) => message.role === "user").length >= limit;
307
+ const MessageRenderer = components?.MessageRenderer ?? require_AIChatParts.DefaultMessageRenderer;
308
+ const ErrorRenderer = components?.ErrorRenderer ?? require_AIChatParts.DefaultErrorRenderer;
309
+ (0, react.useEffect)(() => {
310
+ const viewport = viewportRef.current;
311
+ if (viewport && pinnedToBottom.current) viewport.scrollTop = viewport.scrollHeight;
312
+ });
313
+ const handleKeyDown = (event) => {
314
+ if (event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing) {
315
+ event.preventDefault();
316
+ if (!isBusy && !historyFull && !error && (draft.trim() || (attachments?.length ?? 0) > 0)) onSend?.();
317
+ }
318
+ };
319
+ const handleFormSubmit = (event) => {
320
+ event.preventDefault();
321
+ if (!isBusy && !historyFull && !error && (draft.trim() || (attachments?.length ?? 0) > 0)) onSend?.();
322
+ };
94
323
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
95
- className: [require_ai_chat_dock_module.default.dock, className].filter(Boolean).join(" "),
324
+ className: [require_ai_chat_module.default.thread, className].filter(Boolean).join(" "),
325
+ style,
96
326
  children: [
97
- showLauncher && !isOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
98
- ref: launcherRef,
99
- type: "button",
100
- className: require_ai_chat_dock_module.default.launcher,
101
- "aria-controls": panelId,
102
- "aria-expanded": false,
103
- "aria-label": launcherLabel ?? `Open ${title}`,
104
- onClick: () => changeOpen(true),
105
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
106
- "aria-hidden": "true",
107
- width: "23",
108
- height: "23",
109
- viewBox: "0 0 24 24",
110
- fill: "none",
111
- stroke: "currentColor",
112
- strokeWidth: "1.8",
113
- strokeLinecap: "round",
114
- strokeLinejoin: "round",
115
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M21 11.5a8.5 8.5 0 0 1-8.5 8.5 9.1 9.1 0 0 1-4-.9L3 21l1.9-5.5a9.1 9.1 0 0 1-.9-4 8.5 8.5 0 0 1 8.5-8.5h.5A8.5 8.5 0 0 1 21 11.5Z" })
116
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
117
- className: require_ai_chat_dock_module.default.launcherText,
118
- children: title
327
+ header,
328
+ (toolbarActions || showNewChatInToolbar && onNewChat && messages.length > 0) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
329
+ className: require_ai_chat_module.default.chatToolbar,
330
+ role: "toolbar",
331
+ "aria-label": "Conversation actions",
332
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
333
+ className: require_ai_chat_module.default.chatToolbarExtras,
334
+ children: toolbarActions
335
+ }), showNewChatInToolbar && onNewChat && messages.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
336
+ type: "button",
337
+ className: require_ai_chat_module.default.newChatButton,
338
+ onClick: onNewChat,
339
+ "aria-label": "New chat",
340
+ title: "New chat",
341
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
342
+ "aria-hidden": "true",
343
+ width: "18",
344
+ height: "18",
345
+ viewBox: "0 0 24 24",
346
+ fill: "none",
347
+ stroke: "currentColor",
348
+ strokeWidth: "1.8",
349
+ strokeLinecap: "round",
350
+ strokeLinejoin: "round",
351
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M12 5H6a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h11a2 2 0 0 0 2-2v-6" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
352
+ d: "m15 5 4 4M13 11l7-7a2.12 2.12 0 0 1 3 3l-7 7-4 1 1-4Z",
353
+ transform: "translate(-2 -2)"
354
+ })]
355
+ })
119
356
  })]
120
357
  }),
121
- isOpen && mobile && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
122
- className: require_ai_chat_dock_module.default.backdrop,
123
- "aria-hidden": "true",
124
- onClick: () => changeOpen(false)
125
- }),
126
- /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
127
- ref: panelRef,
128
- id: panelId,
129
- role: "dialog",
130
- "aria-modal": mobile && isOpen,
131
- "aria-label": title,
132
- tabIndex: -1,
133
- className: require_ai_chat_dock_module.default.panel,
134
- "data-expanded": isExpanded,
135
- hidden: !isOpen,
136
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("header", {
137
- className: require_ai_chat_dock_module.default.header,
138
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
139
- className: require_ai_chat_dock_module.default.identity,
140
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
141
- className: require_ai_chat_dock_module.default.avatar,
142
- "aria-hidden": "true",
143
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
144
- width: "18",
145
- height: "18",
146
- viewBox: "0 0 24 24",
147
- fill: "none",
148
- stroke: "currentColor",
149
- strokeWidth: "1.8",
150
- strokeLinecap: "round",
151
- strokeLinejoin: "round",
152
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
153
- x: "4",
154
- y: "6",
155
- width: "16",
156
- height: "14",
157
- rx: "4"
158
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M12 3v3M9 13h.01M15 13h.01M9 17h6" })]
159
- })
160
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
161
- className: require_ai_chat_dock_module.default.titles,
162
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", {
163
- className: require_ai_chat_dock_module.default.title,
164
- children: title
165
- }), description && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
166
- className: require_ai_chat_dock_module.default.description,
167
- children: description
358
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
359
+ ref: viewportRef,
360
+ className: require_ai_chat_module.default.viewport,
361
+ onScroll: (event) => {
362
+ const viewport = event.currentTarget;
363
+ pinnedToBottom.current = viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight < 80;
364
+ },
365
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
366
+ className: require_ai_chat_module.default.messageList,
367
+ role: "log",
368
+ "aria-label": "Chat history",
369
+ "aria-live": "polite",
370
+ children: [
371
+ messages.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
372
+ className: require_ai_chat_module.default.emptyState,
373
+ children: emptyState ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: "Start a conversation" })
374
+ }),
375
+ messages.map((message) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MessageRenderer, {
376
+ message,
377
+ renderMessagePart: (part, index) => require_AIChatParts.renderPart(part, index, components, onToolApproval ? respondToApproval : void 0, pendingApprovalId),
378
+ onToolApproval: onToolApproval ? respondToApproval : void 0
379
+ }, message.id)),
380
+ showActivity && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
381
+ className: require_ai_chat_module.default.activityBubble,
382
+ role: "status",
383
+ "aria-label": currentActivityLabel,
384
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
385
+ className: require_ai_chat_module.default.activityDots,
386
+ "aria-hidden": "true",
387
+ children: [
388
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {}),
389
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {}),
390
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("i", {})
391
+ ]
392
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: currentActivityLabel })]
393
+ }),
394
+ error && (onRetry && onNewChat ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorRenderer, {
395
+ error,
396
+ onRetry,
397
+ onClear: onNewChat
398
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
399
+ className: require_ai_chat_module.default.error,
400
+ role: "alert",
401
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: error.message }), (onRetry || onNewChat) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
402
+ className: require_ai_chat_module.default.errorActions,
403
+ children: [onRetry && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
404
+ type: "button",
405
+ onClick: onRetry,
406
+ children: "Retry response"
407
+ }), onNewChat && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
408
+ type: "button",
409
+ onClick: onNewChat,
410
+ children: "Start new chat"
411
+ })]
168
412
  })]
413
+ }))
414
+ ]
415
+ })
416
+ }),
417
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
418
+ className: require_ai_chat_module.default.footer,
419
+ children: [
420
+ approvalError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
421
+ role: "alert",
422
+ className: require_ai_chat_module.default.attachmentError,
423
+ children: approvalError
424
+ }),
425
+ attachmentError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
426
+ role: "alert",
427
+ className: require_ai_chat_module.default.attachmentError,
428
+ children: attachmentError
429
+ }),
430
+ historyFull && !error && !isBusy && onNewChat && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
431
+ className: require_ai_chat_module.default.historyLimit,
432
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
433
+ "This chat has reached its ",
434
+ limit,
435
+ "-question limit."
436
+ ] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
437
+ type: "button",
438
+ onClick: onNewChat,
439
+ children: "Start new chat"
169
440
  })]
170
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
171
- className: require_ai_chat_dock_module.default.actions,
441
+ }),
442
+ (!historyFull || isBusy) && !error && (composer !== void 0 ? composer : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
443
+ className: require_ai_chat_module.default.composerForm,
444
+ onSubmit: handleFormSubmit,
172
445
  children: [
173
- onNewChat && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
174
- type: "button",
175
- className: require_ai_chat_dock_module.default.iconButton,
176
- "aria-label": "New chat",
177
- title: "New chat",
178
- disabled: newChatDisabled,
179
- onClick: onNewChat,
180
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
181
- "aria-hidden": "true",
182
- width: "18",
183
- height: "18",
184
- viewBox: "0 0 24 24",
185
- fill: "none",
186
- stroke: "currentColor",
187
- strokeWidth: "1.8",
188
- strokeLinecap: "round",
189
- strokeLinejoin: "round",
190
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M12 5H6a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h11a2 2 0 0 0 2-2v-6" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
191
- d: "m15 5 4 4M13 11l7-7a2.12 2.12 0 0 1 3 3l-7 7-4 1 1-4Z",
192
- transform: "translate(-2 -2)"
193
- })]
194
- })
446
+ composerLeading && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
447
+ className: require_ai_chat_module.default.composerExtras,
448
+ children: composerLeading
449
+ }),
450
+ onSelectAttachments && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
451
+ ref: fileInputRef,
452
+ className: require_ai_chat_module.default.visuallyHidden,
453
+ type: "file",
454
+ "aria-label": "Add attachments",
455
+ accept: attachmentAccept,
456
+ multiple: true,
457
+ disabled: isBusy,
458
+ onChange: (event) => {
459
+ if (event.target.files) onSelectAttachments(event.target.files);
460
+ event.target.value = "";
461
+ }
195
462
  }),
196
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
197
- type: "button",
198
- className: `${require_ai_chat_dock_module.default.iconButton} ${require_ai_chat_dock_module.default.expandButton}`,
199
- "aria-label": isExpanded ? `Collapse ${title}` : `Expand ${title}`,
200
- title: isExpanded ? "Collapse" : "Expand",
201
- onClick: () => changeExpanded(!isExpanded),
202
- children: isExpanded ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
203
- width: "17",
204
- height: "17",
205
- viewBox: "0 0 24 24",
206
- fill: "none",
207
- stroke: "currentColor",
208
- strokeWidth: "2",
209
- strokeLinecap: "round",
210
- strokeLinejoin: "round",
211
- "aria-hidden": "true",
212
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M9 3v6H3M15 21v-6h6M3 9l6-6M21 15l-6 6" })
213
- }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
214
- width: "17",
215
- height: "17",
216
- viewBox: "0 0 24 24",
217
- fill: "none",
218
- stroke: "currentColor",
219
- strokeWidth: "2",
220
- strokeLinecap: "round",
221
- strokeLinejoin: "round",
222
- "aria-hidden": "true",
223
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M8 3H3v5M16 21h5v-5M3 3l7 7M21 21l-7-7" })
463
+ attachments && attachments.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
464
+ className: require_ai_chat_module.default.composerExtras,
465
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
466
+ className: require_ai_chat_module.default.attachmentList,
467
+ "aria-label": "Attached files",
468
+ children: attachments.map((attachment, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AIChatParts.AIChatAttachmentPreview, {
469
+ name: attachment.name,
470
+ size: attachment.size,
471
+ staged: true,
472
+ imageUrl: attachment.previewUrl,
473
+ onRemove: onRemoveAttachment ? () => onRemoveAttachment(index) : void 0
474
+ }) }, index))
224
475
  })
225
476
  }),
226
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
227
- type: "button",
228
- className: require_ai_chat_dock_module.default.iconButton,
229
- "aria-label": `Close ${title}`,
230
- title: "Close",
231
- onClick: () => changeOpen(false),
232
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
233
- width: "18",
234
- height: "18",
235
- viewBox: "0 0 24 24",
236
- fill: "none",
237
- stroke: "currentColor",
238
- strokeWidth: "2",
239
- strokeLinecap: "round",
240
- "aria-hidden": "true",
241
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M18 6 6 18M6 6l12 12" })
477
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
478
+ className: require_ai_chat_module.default.composerSurface,
479
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
480
+ className: require_ai_chat_module.default.composerRow,
481
+ children: [
482
+ onSelectAttachments && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
483
+ type: "button",
484
+ className: require_ai_chat_module.default.composerIconButton,
485
+ "aria-label": "Attach file",
486
+ title: "Attach file",
487
+ disabled: isBusy,
488
+ onClick: () => fileInputRef.current?.click(),
489
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
490
+ width: "20",
491
+ height: "20",
492
+ viewBox: "0 0 24 24",
493
+ fill: "none",
494
+ stroke: "currentColor",
495
+ strokeWidth: "1.8",
496
+ strokeLinecap: "round",
497
+ strokeLinejoin: "round",
498
+ "aria-hidden": "true",
499
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "m21 11-8.5 8.5a6 6 0 0 1-8.5-8.5l9-9a4 4 0 0 1 5.7 5.7l-9 9a2 2 0 0 1-2.8-2.8l8.5-8.5" })
500
+ })
501
+ }),
502
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
503
+ className: require_ai_chat_module.default.input,
504
+ "aria-label": inputAriaLabel,
505
+ rows: 1,
506
+ value: draft,
507
+ onChange: (event) => onDraftChange?.(event.target.value),
508
+ onKeyDown: handleKeyDown,
509
+ placeholder: inputPlaceholder,
510
+ maxLength: inputMaxLength,
511
+ disabled: isBusy || !onSend || !onDraftChange,
512
+ readOnly: !onDraftChange
513
+ }),
514
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
515
+ className: require_ai_chat_module.default.composerActions,
516
+ children: [composerTrailing, isBusy ? onStop && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
517
+ type: "button",
518
+ className: require_ai_chat_module.default.composerIconButton,
519
+ onClick: onStop,
520
+ "aria-label": "Stop response",
521
+ title: "Stop response",
522
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
523
+ width: "18",
524
+ height: "18",
525
+ viewBox: "0 0 24 24",
526
+ fill: "currentColor",
527
+ "aria-hidden": "true",
528
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("rect", {
529
+ x: "5",
530
+ y: "5",
531
+ width: "14",
532
+ height: "14",
533
+ rx: "2"
534
+ })
535
+ })
536
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
537
+ type: "submit",
538
+ className: require_ai_chat_module.default.sendButton,
539
+ "aria-label": "Send message",
540
+ title: "Send message",
541
+ disabled: !onSend || !draft.trim() && !attachments?.length,
542
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
543
+ width: "20",
544
+ height: "20",
545
+ viewBox: "0 0 24 24",
546
+ fill: "none",
547
+ stroke: "currentColor",
548
+ strokeWidth: "2",
549
+ strokeLinecap: "round",
550
+ strokeLinejoin: "round",
551
+ "aria-hidden": "true",
552
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", { d: "M12 19V5m-7 7 7-7 7 7" })
553
+ })
554
+ })]
555
+ })
556
+ ]
242
557
  })
243
558
  })
244
559
  ]
245
- })]
246
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
247
- className: require_ai_chat_dock_module.default.content,
248
- children
249
- })]
560
+ }))
561
+ ]
250
562
  })
251
563
  ]
252
564
  });
253
565
  }
254
566
  //#endregion
255
- exports.AIChatDock = AIChatDock;
567
+ exports.AIChat = AIChat;
568
+ exports.AIChatAttachmentPreview = require_AIChatParts.AIChatAttachmentPreview;
569
+ exports.AIChatMessageBubble = require_AIChatParts.AIChatMessageBubble;
570
+ exports.AIChatView = AIChatView;
256
571
 
257
572
  //# sourceMappingURL=index87.cjs.map