@tomny-dev/uzi 0.20.0 → 0.20.1-pr.138.475.1.15516bf
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/components/ai-chat/AIChat.d.ts +2 -25
- package/dist/components/ai-chat/AIChat.d.ts.map +1 -1
- package/dist/components/ai-chat/AIChatParts.d.ts +32 -0
- package/dist/components/ai-chat/AIChatParts.d.ts.map +1 -0
- package/dist/components/ai-chat/activityLabel.d.ts +20 -0
- package/dist/components/ai-chat/activityLabel.d.ts.map +1 -0
- package/dist/components/ai-chat/activityLabel.test.d.ts +2 -0
- package/dist/components/ai-chat/activityLabel.test.d.ts.map +1 -0
- package/dist/index.cjs +6 -5
- package/dist/index.js +4 -3
- package/dist/index59.js +8 -2
- package/dist/index59.js.map +1 -1
- package/dist/index60.cjs +10 -1
- package/dist/index60.cjs.map +1 -1
- package/dist/index60.js +1 -1
- package/dist/index60.js.map +1 -1
- package/dist/index61.cjs +1 -1
- package/dist/index61.cjs.map +1 -1
- package/dist/index84.js +3 -556
- package/dist/index84.js.map +1 -1
- package/dist/index85.cjs +6 -556
- package/dist/index85.cjs.map +1 -1
- package/dist/index85.js +11 -34
- package/dist/index85.js.map +1 -1
- package/dist/index86.cjs +11 -49
- package/dist/index86.cjs.map +1 -1
- package/dist/index86.js +539 -227
- package/dist/index86.js.map +1 -1
- package/dist/index87.cjs +541 -226
- package/dist/index87.cjs.map +1 -1
- package/dist/index87.js +33 -15
- package/dist/index87.js.map +1 -1
- package/dist/index88.cjs +48 -21
- package/dist/index88.cjs.map +1 -1
- package/dist/index88.js +250 -29
- package/dist/index88.js.map +1 -1
- package/dist/index89.cjs +250 -30
- package/dist/index89.cjs.map +1 -1
- package/dist/index89.js +19 -0
- package/dist/index89.js.map +1 -0
- package/dist/index90.cjs +25 -0
- package/dist/index90.cjs.map +1 -0
- package/dist/index90.js +36 -0
- package/dist/index90.js.map +1 -0
- package/dist/index91.cjs +37 -0
- package/dist/index91.cjs.map +1 -0
- package/dist/style.css +19 -2
- package/package.json +9 -3
package/dist/index87.cjs
CHANGED
|
@@ -1,257 +1,572 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
const
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
(0,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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 (!
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
126
|
+
active = false;
|
|
60
127
|
};
|
|
61
|
-
}, [
|
|
128
|
+
}, [chat?.setMessages, history]);
|
|
62
129
|
(0, react.useEffect)(() => {
|
|
63
|
-
if (!
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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: [
|
|
324
|
+
className: [require_ai_chat_module.default.thread, className].filter(Boolean).join(" "),
|
|
325
|
+
style,
|
|
96
326
|
children: [
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
"aria-
|
|
102
|
-
"
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
}),
|
|
171
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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)("
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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)("
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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
|
-
|
|
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.
|
|
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
|