@galaxycore/ai-chat 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +3 -3
- package/dist/appearance.js +1 -1
- package/dist/context.js +1 -1
- package/dist/headless.d.ts +2 -2
- package/dist/headless.js +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +354 -240
- package/dist/index.js.map +1 -1
- package/dist/{labels-DJsjblzj.js → labels-BM5o9a9K.js} +5 -1
- package/dist/{labels-DJsjblzj.js.map → labels-BM5o9a9K.js.map} +1 -1
- package/dist/{labels-BBjaNAlS.d.ts → labels-D8smv23O.d.ts} +36 -2
- package/dist/markdown.d.ts +1 -1
- package/dist/markdown.js +1 -1
- package/dist/markdown.js.map +1 -1
- package/dist/styles.css +207 -112
- package/dist/targeting.css +205 -0
- package/dist/targeting.d.ts +101 -0
- package/dist/targeting.js +585 -0
- package/dist/targeting.js.map +1 -0
- package/dist/{ui-primitives-DlZ1hJkr.js → ui-primitives-BCbe9Ds8.js} +4 -4
- package/dist/{ui-primitives-DlZ1hJkr.js.map → ui-primitives-BCbe9Ds8.js.map} +1 -1
- package/docs/api-reference.md +2 -2
- package/docs/design.md +2 -2
- package/docs/integration.md +3 -4
- package/docs/patent-prototype.md +72 -0
- package/docs/patent-visual-baseline.json +121 -0
- package/docs/publishing.md +10 -10
- package/docs/validation.md +12 -0
- package/package.json +8 -10
package/dist/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
"use client";
|
|
3
|
-
import { i as useAiChat, n as resolveLabels, r as zhCN, t as enUS } from "./labels-
|
|
4
|
-
import { n as ChatAppearanceProvider, r as Icon, t as ChatIconButton } from "./ui-primitives-
|
|
3
|
+
import { i as useAiChat, n as resolveLabels, r as zhCN, t as enUS } from "./labels-BM5o9a9K.js";
|
|
4
|
+
import { n as ChatAppearanceProvider, r as Icon, t as ChatIconButton } from "./ui-primitives-BCbe9Ds8.js";
|
|
5
5
|
import { i as safeUrl, n as asError, r as getMessageText, t as acceptsFile } from "./utils-DqBGBYA1.js";
|
|
6
6
|
import { SpeechInputError, createBrowserSpeechAdapter, defaultSpeechInputLabels, useSpeechInput } from "./voice.js";
|
|
7
|
+
import { MarkdownResponse } from "./markdown.js";
|
|
7
8
|
import { ContextTray, createTextSelectionAdapter, useChatContext } from "./context.js";
|
|
8
9
|
import "./appearance.js";
|
|
10
|
+
import { ChatTargetingOverlay, enUSTargetingLabels, toChatContextItem, useChatTargeting, zhCNTargetingLabels } from "./targeting.js";
|
|
9
11
|
import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
|
10
12
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
13
|
import { isToolUIPart } from "ai";
|
|
@@ -59,12 +61,21 @@ function Composer({ chat, labels: overrides, attachments, speech, toolbar, conte
|
|
|
59
61
|
};
|
|
60
62
|
}, []);
|
|
61
63
|
useEffect(() => {
|
|
62
|
-
|
|
63
|
-
if (element) {
|
|
64
|
-
element.style.height = "auto";
|
|
65
|
-
element.style.height = `${Math.min(element.scrollHeight, 180)}px`;
|
|
66
|
-
}
|
|
64
|
+
if (textarea.current) fitTextarea(textarea.current);
|
|
67
65
|
}, [text]);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
const element = textarea.current;
|
|
68
|
+
if (!element || typeof ResizeObserver === "undefined") return;
|
|
69
|
+
let width = element.getBoundingClientRect().width;
|
|
70
|
+
const observer = new ResizeObserver(() => {
|
|
71
|
+
const nextWidth = element.getBoundingClientRect().width;
|
|
72
|
+
if (nextWidth === width) return;
|
|
73
|
+
width = nextWidth;
|
|
74
|
+
fitTextarea(element);
|
|
75
|
+
});
|
|
76
|
+
observer.observe(element);
|
|
77
|
+
return () => observer.disconnect();
|
|
78
|
+
}, []);
|
|
68
79
|
function report(value) {
|
|
69
80
|
const actionError = asError(value);
|
|
70
81
|
setError(actionError.message);
|
|
@@ -136,215 +147,233 @@ function Composer({ chat, labels: overrides, attachments, speech, toolbar, conte
|
|
|
136
147
|
sending.current = false;
|
|
137
148
|
}
|
|
138
149
|
}
|
|
139
|
-
return /* @__PURE__ */ jsxs("
|
|
140
|
-
className:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
},
|
|
148
|
-
onDrop: (event) => {
|
|
149
|
-
if (attachments && !disabled) {
|
|
150
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
151
|
+
className: "gc-chat__composer-wrap",
|
|
152
|
+
children: [context != null ? /* @__PURE__ */ jsx("div", {
|
|
153
|
+
className: "gc-chat__context",
|
|
154
|
+
children: context
|
|
155
|
+
}) : null, /* @__PURE__ */ jsxs("form", {
|
|
156
|
+
className: `gc-chat__composer ${className}`,
|
|
157
|
+
onSubmit: (event) => {
|
|
150
158
|
event.preventDefault();
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
159
|
+
send();
|
|
160
|
+
},
|
|
161
|
+
onDragOver: (event) => {
|
|
162
|
+
if (attachments && !disabled) event.preventDefault();
|
|
163
|
+
},
|
|
164
|
+
onDrop: (event) => {
|
|
165
|
+
if (attachments && !disabled) {
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
addFiles(Array.from(event.dataTransfer.files));
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
children: [
|
|
171
|
+
files.length ? /* @__PURE__ */ jsx("ul", {
|
|
172
|
+
className: "gc-chat__attachments",
|
|
173
|
+
"aria-label": labels.attach,
|
|
174
|
+
children: files.map((file) => /* @__PURE__ */ jsxs("li", {
|
|
175
|
+
className: "gc-chat__attachment",
|
|
176
|
+
children: [
|
|
177
|
+
/* @__PURE__ */ jsx(Icon, { name: "file" }),
|
|
178
|
+
/* @__PURE__ */ jsx("span", { children: file.name }),
|
|
179
|
+
!file.part ? /* @__PURE__ */ jsx("span", {
|
|
180
|
+
role: "status",
|
|
181
|
+
children: labels.uploading
|
|
182
|
+
}) : null,
|
|
183
|
+
/* @__PURE__ */ jsx(ChatIconButton, {
|
|
184
|
+
label: `${labels.removeAttachment}: ${file.name}`,
|
|
185
|
+
icon: "close",
|
|
186
|
+
onClick: () => removeFile(file.id)
|
|
187
|
+
})
|
|
188
|
+
]
|
|
189
|
+
}, file.id))
|
|
190
|
+
}) : null,
|
|
191
|
+
speech && voice.state === "consent" && /* @__PURE__ */ jsxs("div", {
|
|
192
|
+
className: "gc-chat__voice-consent",
|
|
193
|
+
role: "group",
|
|
194
|
+
"aria-label": voiceLabels.consentTitle,
|
|
195
|
+
children: [
|
|
196
|
+
/* @__PURE__ */ jsx("strong", { children: voiceLabels.consentTitle }),
|
|
197
|
+
/* @__PURE__ */ jsx("p", {
|
|
198
|
+
className: "gc-chat__voice-disclosure",
|
|
199
|
+
children: voice.disclosure
|
|
200
|
+
}),
|
|
201
|
+
/* @__PURE__ */ jsxs("label", {
|
|
202
|
+
className: "gc-chat__voice-remember",
|
|
203
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
204
|
+
type: "checkbox",
|
|
205
|
+
checked: rememberSpeech,
|
|
206
|
+
onChange: (event) => setRememberSpeech(event.target.checked)
|
|
207
|
+
}), voiceLabels.remember]
|
|
208
|
+
}),
|
|
209
|
+
/* @__PURE__ */ jsxs("div", {
|
|
210
|
+
className: "gc-chat__voice-actions",
|
|
211
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
212
|
+
type: "button",
|
|
213
|
+
className: "gc-chat__button",
|
|
214
|
+
disabled: disabled || chat.isBusy,
|
|
215
|
+
onClick: () => voice.confirm(rememberSpeech),
|
|
216
|
+
children: voiceLabels.confirm
|
|
217
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
218
|
+
type: "button",
|
|
219
|
+
className: "gc-chat__button",
|
|
220
|
+
onClick: voice.cancel,
|
|
221
|
+
children: voiceLabels.cancel
|
|
222
|
+
})]
|
|
223
|
+
})
|
|
224
|
+
]
|
|
225
|
+
}),
|
|
226
|
+
speech && voice.isActive && /* @__PURE__ */ jsxs("div", {
|
|
227
|
+
className: "gc-chat__voice",
|
|
228
|
+
"data-state": voice.state,
|
|
164
229
|
children: [
|
|
165
|
-
/* @__PURE__ */
|
|
166
|
-
|
|
167
|
-
|
|
230
|
+
/* @__PURE__ */ jsxs("span", {
|
|
231
|
+
className: "gc-chat__voice-wave",
|
|
232
|
+
"aria-hidden": "true",
|
|
233
|
+
children: [
|
|
234
|
+
/* @__PURE__ */ jsx("i", {}),
|
|
235
|
+
/* @__PURE__ */ jsx("i", {}),
|
|
236
|
+
/* @__PURE__ */ jsx("i", {}),
|
|
237
|
+
/* @__PURE__ */ jsx("i", {}),
|
|
238
|
+
/* @__PURE__ */ jsx("i", {})
|
|
239
|
+
]
|
|
240
|
+
}),
|
|
241
|
+
/* @__PURE__ */ jsx("span", {
|
|
242
|
+
className: "gc-chat__voice-status",
|
|
168
243
|
role: "status",
|
|
169
|
-
children:
|
|
170
|
-
})
|
|
171
|
-
/* @__PURE__ */
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
244
|
+
children: voice.state === "starting" ? voiceLabels.starting : voice.state === "stopping" ? voiceLabels.stopping : voiceLabels.listening
|
|
245
|
+
}),
|
|
246
|
+
/* @__PURE__ */ jsxs("div", {
|
|
247
|
+
className: "gc-chat__voice-actions",
|
|
248
|
+
children: [/* @__PURE__ */ jsx(ChatIconButton, {
|
|
249
|
+
disabled: voice.state === "stopping",
|
|
250
|
+
label: voiceLabels.finish,
|
|
251
|
+
icon: "check",
|
|
252
|
+
onClick: voice.stop
|
|
253
|
+
}), /* @__PURE__ */ jsx(ChatIconButton, {
|
|
254
|
+
label: voiceLabels.cancel,
|
|
255
|
+
icon: "close",
|
|
256
|
+
onClick: voice.cancel
|
|
257
|
+
})]
|
|
258
|
+
}),
|
|
259
|
+
/* @__PURE__ */ jsxs("p", {
|
|
260
|
+
className: "gc-chat__voice-transcript",
|
|
261
|
+
children: [
|
|
262
|
+
voice.result.finalText,
|
|
263
|
+
/* @__PURE__ */ jsx("span", { children: voice.result.interimText }),
|
|
264
|
+
!voice.result.finalText && !voice.result.interimText ? voiceLabels.empty : null
|
|
265
|
+
]
|
|
175
266
|
})
|
|
176
267
|
]
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
/* @__PURE__ */ jsxs("span", {
|
|
219
|
-
className: "gc-chat__voice-wave",
|
|
220
|
-
"aria-hidden": "true",
|
|
268
|
+
}),
|
|
269
|
+
speech && !voice.support.supported && /* @__PURE__ */ jsx("p", {
|
|
270
|
+
id: `${inputId}-voice-support`,
|
|
271
|
+
className: "gc-chat__voice-unsupported",
|
|
272
|
+
children: voice.support.reason
|
|
273
|
+
}),
|
|
274
|
+
speech && voice.error && /* @__PURE__ */ jsx("p", {
|
|
275
|
+
className: "gc-chat__voice-error",
|
|
276
|
+
role: "alert",
|
|
277
|
+
children: voice.error.message
|
|
278
|
+
}),
|
|
279
|
+
/* @__PURE__ */ jsx("textarea", {
|
|
280
|
+
ref: textarea,
|
|
281
|
+
className: "gc-chat__input",
|
|
282
|
+
"aria-label": labels.placeholder,
|
|
283
|
+
placeholder: labels.placeholder,
|
|
284
|
+
value: text,
|
|
285
|
+
rows: 2,
|
|
286
|
+
disabled,
|
|
287
|
+
onChange: (event) => setText(event.target.value),
|
|
288
|
+
onPaste: (event) => {
|
|
289
|
+
if (attachments && event.clipboardData.files.length) {
|
|
290
|
+
event.preventDefault();
|
|
291
|
+
addFiles(Array.from(event.clipboardData.files));
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
onKeyDown: (event) => {
|
|
295
|
+
if (event.key === "Escape" && !event.nativeEvent.isComposing && event.keyCode !== 229) {
|
|
296
|
+
event.currentTarget.blur();
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
if (event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing && event.keyCode !== 229) {
|
|
300
|
+
event.preventDefault();
|
|
301
|
+
send();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}),
|
|
305
|
+
/* @__PURE__ */ jsxs("div", {
|
|
306
|
+
className: "gc-chat__composer-bottom",
|
|
307
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
308
|
+
className: "gc-chat__toolbar",
|
|
221
309
|
children: [
|
|
222
|
-
/* @__PURE__ */ jsx("
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
310
|
+
attachments ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("input", {
|
|
311
|
+
ref: fileInput,
|
|
312
|
+
id: inputId,
|
|
313
|
+
type: "file",
|
|
314
|
+
hidden: true,
|
|
315
|
+
multiple: true,
|
|
316
|
+
accept: attachments.accept,
|
|
317
|
+
disabled,
|
|
318
|
+
onChange: (event) => {
|
|
319
|
+
addFiles(Array.from(event.target.files ?? []));
|
|
320
|
+
event.target.value = "";
|
|
321
|
+
}
|
|
322
|
+
}), /* @__PURE__ */ jsx(ChatIconButton, {
|
|
323
|
+
disabled,
|
|
324
|
+
label: labels.attach,
|
|
325
|
+
icon: "plus",
|
|
326
|
+
onClick: () => fileInput.current?.click()
|
|
327
|
+
})] }) : null,
|
|
328
|
+
toolbar,
|
|
329
|
+
!attachments && !speech && toolbar == null && /* @__PURE__ */ jsx("span", {
|
|
330
|
+
className: "gc-chat__input-hint",
|
|
331
|
+
children: labels.composerHint
|
|
332
|
+
})
|
|
227
333
|
]
|
|
228
|
-
}),
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
334
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
335
|
+
className: "gc-chat__composer-actions",
|
|
336
|
+
children: [speech && /* @__PURE__ */ jsx(ChatIconButton, {
|
|
337
|
+
label: voiceLabels.start,
|
|
338
|
+
icon: "mic",
|
|
339
|
+
tooltip: voice.support.reason ?? voiceLabels.start,
|
|
340
|
+
"aria-describedby": !voice.support.supported ? `${inputId}-voice-support` : void 0,
|
|
341
|
+
disabled: disabled || chat.isBusy || voice.isActive || voice.state === "consent" || !voice.support.supported,
|
|
342
|
+
onClick: voice.start
|
|
343
|
+
}), chat.isBusy ? /* @__PURE__ */ jsx(ChatIconButton, {
|
|
344
|
+
className: "gc-chat__send",
|
|
345
|
+
label: labels.stop,
|
|
346
|
+
icon: "stop",
|
|
347
|
+
onClick: (event) => {
|
|
348
|
+
event.preventDefault();
|
|
349
|
+
chat.stop().catch(report);
|
|
350
|
+
}
|
|
351
|
+
}) : /* @__PURE__ */ jsx(ChatIconButton, {
|
|
352
|
+
className: "gc-chat__send",
|
|
353
|
+
type: "submit",
|
|
354
|
+
disabled: !canSend,
|
|
355
|
+
label: labels.send,
|
|
356
|
+
icon: "send"
|
|
245
357
|
})]
|
|
246
|
-
}),
|
|
247
|
-
/* @__PURE__ */ jsxs("p", {
|
|
248
|
-
className: "gc-chat__voice-transcript",
|
|
249
|
-
children: [
|
|
250
|
-
voice.result.finalText,
|
|
251
|
-
/* @__PURE__ */ jsx("span", { children: voice.result.interimText }),
|
|
252
|
-
!voice.result.finalText && !voice.result.interimText ? voiceLabels.empty : null
|
|
253
|
-
]
|
|
254
|
-
})
|
|
255
|
-
]
|
|
256
|
-
}),
|
|
257
|
-
speech && !voice.support.supported && /* @__PURE__ */ jsx("p", {
|
|
258
|
-
id: `${inputId}-voice-support`,
|
|
259
|
-
className: "gc-chat__voice-unsupported",
|
|
260
|
-
children: voice.support.reason
|
|
261
|
-
}),
|
|
262
|
-
speech && voice.error && /* @__PURE__ */ jsx("p", {
|
|
263
|
-
className: "gc-chat__voice-error",
|
|
264
|
-
role: "alert",
|
|
265
|
-
children: voice.error.message
|
|
266
|
-
}),
|
|
267
|
-
/* @__PURE__ */ jsx("textarea", {
|
|
268
|
-
ref: textarea,
|
|
269
|
-
className: "gc-chat__input",
|
|
270
|
-
"aria-label": labels.placeholder,
|
|
271
|
-
placeholder: labels.placeholder,
|
|
272
|
-
value: text,
|
|
273
|
-
rows: 1,
|
|
274
|
-
disabled,
|
|
275
|
-
onChange: (event) => setText(event.target.value),
|
|
276
|
-
onPaste: (event) => {
|
|
277
|
-
if (attachments && event.clipboardData.files.length) {
|
|
278
|
-
event.preventDefault();
|
|
279
|
-
addFiles(Array.from(event.clipboardData.files));
|
|
280
|
-
}
|
|
281
|
-
},
|
|
282
|
-
onKeyDown: (event) => {
|
|
283
|
-
if (event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing && event.keyCode !== 229) {
|
|
284
|
-
event.preventDefault();
|
|
285
|
-
send();
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}),
|
|
289
|
-
/* @__PURE__ */ jsxs("div", {
|
|
290
|
-
className: "gc-chat__composer-bottom",
|
|
291
|
-
children: [/* @__PURE__ */ jsxs("div", {
|
|
292
|
-
className: "gc-chat__toolbar",
|
|
293
|
-
children: [attachments ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("input", {
|
|
294
|
-
ref: fileInput,
|
|
295
|
-
id: inputId,
|
|
296
|
-
type: "file",
|
|
297
|
-
hidden: true,
|
|
298
|
-
multiple: true,
|
|
299
|
-
accept: attachments.accept,
|
|
300
|
-
disabled,
|
|
301
|
-
onChange: (event) => {
|
|
302
|
-
addFiles(Array.from(event.target.files ?? []));
|
|
303
|
-
event.target.value = "";
|
|
304
|
-
}
|
|
305
|
-
}), /* @__PURE__ */ jsx(ChatIconButton, {
|
|
306
|
-
disabled,
|
|
307
|
-
label: labels.attach,
|
|
308
|
-
icon: "plus",
|
|
309
|
-
onClick: () => fileInput.current?.click()
|
|
310
|
-
})] }) : null, toolbar]
|
|
311
|
-
}), /* @__PURE__ */ jsxs("div", {
|
|
312
|
-
className: "gc-chat__composer-actions",
|
|
313
|
-
children: [speech && /* @__PURE__ */ jsx(ChatIconButton, {
|
|
314
|
-
label: voiceLabels.start,
|
|
315
|
-
icon: "mic",
|
|
316
|
-
tooltip: voice.support.reason ?? voiceLabels.start,
|
|
317
|
-
"aria-describedby": !voice.support.supported ? `${inputId}-voice-support` : void 0,
|
|
318
|
-
disabled: disabled || chat.isBusy || voice.isActive || voice.state === "consent" || !voice.support.supported,
|
|
319
|
-
onClick: voice.start
|
|
320
|
-
}), chat.isBusy ? /* @__PURE__ */ jsx(ChatIconButton, {
|
|
321
|
-
className: "gc-chat__send",
|
|
322
|
-
label: labels.stop,
|
|
323
|
-
icon: "stop",
|
|
324
|
-
onClick: () => {
|
|
325
|
-
chat.stop().catch(report);
|
|
326
|
-
}
|
|
327
|
-
}) : /* @__PURE__ */ jsx(ChatIconButton, {
|
|
328
|
-
className: "gc-chat__send",
|
|
329
|
-
type: "submit",
|
|
330
|
-
disabled: !canSend,
|
|
331
|
-
label: labels.send,
|
|
332
|
-
icon: "send"
|
|
333
358
|
})]
|
|
334
|
-
})
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
})
|
|
344
|
-
|
|
345
|
-
]
|
|
359
|
+
}),
|
|
360
|
+
error ? /* @__PURE__ */ jsxs("div", {
|
|
361
|
+
className: "gc-chat__error",
|
|
362
|
+
role: "alert",
|
|
363
|
+
children: [error, /* @__PURE__ */ jsx(ChatIconButton, {
|
|
364
|
+
label: labels.dismiss,
|
|
365
|
+
icon: "close",
|
|
366
|
+
onClick: () => setError(void 0)
|
|
367
|
+
})]
|
|
368
|
+
}) : null
|
|
369
|
+
]
|
|
370
|
+
})]
|
|
346
371
|
});
|
|
347
372
|
}
|
|
373
|
+
function fitTextarea(element) {
|
|
374
|
+
element.style.height = "auto";
|
|
375
|
+
element.style.height = `${Math.min(Math.max(element.getBoundingClientRect().height, element.scrollHeight), 180)}px`;
|
|
376
|
+
}
|
|
348
377
|
//#endregion
|
|
349
378
|
//#region src/tool-activity.tsx
|
|
350
379
|
function readableValue(value) {
|
|
@@ -768,7 +797,7 @@ function StreamingText({ text, isStreaming, enabled = true, renderText }) {
|
|
|
768
797
|
function ChatMessages(props) {
|
|
769
798
|
return /* @__PURE__ */ jsx(Messages, { ...props }, props.chat.id);
|
|
770
799
|
}
|
|
771
|
-
function Messages({ chat, labels: labelOverrides, renderText, smoothStreaming = true, renderers, tools, toolPresentation, empty, className, requestOptions, onActionError, capabilities }) {
|
|
800
|
+
function Messages({ chat, labels: labelOverrides, renderText, smoothStreaming = true, renderers, tools, toolPresentation, suggestedActions, suggestionsTitle, suggestionsDescription, renderMessageActions, renderMessageHeader, empty, className, requestOptions, onActionError, capabilities }) {
|
|
772
801
|
const labels = resolveLabels(labelOverrides);
|
|
773
802
|
const { scroller, content, awayFromBottom, scrollToLatest, scrollEvents } = useMessageScroll(chat.messages);
|
|
774
803
|
const copyTimeout = useRef(void 0);
|
|
@@ -776,6 +805,7 @@ function Messages({ chat, labels: labelOverrides, renderText, smoothStreaming =
|
|
|
776
805
|
const [copiedId, setCopiedId] = useState();
|
|
777
806
|
const [actionError, setActionError] = useState();
|
|
778
807
|
const [actionPending, setActionPending] = useState(false);
|
|
808
|
+
const [pendingSuggestion, setPendingSuggestion] = useState();
|
|
779
809
|
useEffect(() => () => clearTimeout(copyTimeout.current), []);
|
|
780
810
|
function reportError(cause) {
|
|
781
811
|
const error = asError(cause);
|
|
@@ -810,6 +840,29 @@ function Messages({ chat, labels: labelOverrides, renderText, smoothStreaming =
|
|
|
810
840
|
setActionPending(false);
|
|
811
841
|
}
|
|
812
842
|
}
|
|
843
|
+
function focusComposer() {
|
|
844
|
+
content.current?.closest(".gc-chat")?.querySelector(".gc-chat__input")?.focus();
|
|
845
|
+
}
|
|
846
|
+
async function selectSuggestion(action, message) {
|
|
847
|
+
if (chat.isBusy || actionInFlight.current || action.disabled || message !== chat.messages.at(-1)) return;
|
|
848
|
+
actionInFlight.current = true;
|
|
849
|
+
setActionPending(true);
|
|
850
|
+
setPendingSuggestion(action.id);
|
|
851
|
+
setActionError(void 0);
|
|
852
|
+
try {
|
|
853
|
+
await action.onSelect({
|
|
854
|
+
message,
|
|
855
|
+
chat,
|
|
856
|
+
focusComposer
|
|
857
|
+
});
|
|
858
|
+
} catch (cause) {
|
|
859
|
+
reportError(cause);
|
|
860
|
+
} finally {
|
|
861
|
+
actionInFlight.current = false;
|
|
862
|
+
setActionPending(false);
|
|
863
|
+
setPendingSuggestion(void 0);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
813
866
|
function renderPart(part, message, isStreaming) {
|
|
814
867
|
const renderer = renderers?.[part.type];
|
|
815
868
|
if (renderer) return renderer({
|
|
@@ -850,7 +903,7 @@ function Messages({ chat, labels: labelOverrides, renderText, smoothStreaming =
|
|
|
850
903
|
text: part.text,
|
|
851
904
|
isStreaming: message.role === "assistant" && isStreaming && part.state !== "done",
|
|
852
905
|
enabled: smoothStreaming,
|
|
853
|
-
renderText
|
|
906
|
+
renderText: renderText ?? (message.role === "assistant" ? MarkdownResponse : void 0)
|
|
854
907
|
})
|
|
855
908
|
}) : null;
|
|
856
909
|
case "reasoning": return /* @__PURE__ */ jsxs("details", {
|
|
@@ -910,6 +963,8 @@ function Messages({ chat, labels: labelOverrides, renderText, smoothStreaming =
|
|
|
910
963
|
const lastPart = last?.parts.filter((part) => part.type !== "step-start").at(-1);
|
|
911
964
|
const toolFinished = lastPart && isToolUIPart(lastPart) && (lastPart.state === "output-available" && !lastPart.preliminary || lastPart.state === "output-error" || lastPart.state === "output-denied");
|
|
912
965
|
const visibleMessages = chat.messages.filter((message) => message.role !== "system");
|
|
966
|
+
const actions = suggestedActions?.slice(0, 3) ?? [];
|
|
967
|
+
const recommendedIndex = actions.findIndex((action) => action.emphasis === "recommended");
|
|
913
968
|
const showThinking = chat.isBusy && (last?.role !== "assistant" || !lastPart || lastPart.type === "text" && !lastPart.text || toolFinished);
|
|
914
969
|
const thinking = /* @__PURE__ */ jsxs("div", {
|
|
915
970
|
className: "gc-chat__thinking",
|
|
@@ -962,35 +1017,83 @@ function Messages({ chat, labels: labelOverrides, renderText, smoothStreaming =
|
|
|
962
1017
|
visibleMessages.map((message) => /* @__PURE__ */ jsxs("article", {
|
|
963
1018
|
className: `gc-chat__message gc-chat__message--${message.role}`,
|
|
964
1019
|
"aria-label": message.role === "user" ? labels.user : labels.assistant,
|
|
965
|
-
children: [
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
1020
|
+
children: [
|
|
1021
|
+
message.role === "assistant" && (renderMessageHeader ? renderMessageHeader({
|
|
1022
|
+
message,
|
|
1023
|
+
isStreaming: chat.status === "streaming" && message === last,
|
|
1024
|
+
chat
|
|
1025
|
+
}) : /* @__PURE__ */ jsxs("div", {
|
|
1026
|
+
className: "gc-chat__message-heading",
|
|
1027
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1028
|
+
className: "gc-chat__assistant-mark",
|
|
1029
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "sparkle" })
|
|
1030
|
+
}), /* @__PURE__ */ jsx("strong", {
|
|
1031
|
+
className: "gc-chat__assistant-name",
|
|
1032
|
+
children: labels.assistant
|
|
1033
|
+
})]
|
|
1034
|
+
})),
|
|
1035
|
+
/* @__PURE__ */ jsx("div", {
|
|
1036
|
+
className: "gc-chat__message-body",
|
|
1037
|
+
children: message.parts.map((part, partIndex) => /* @__PURE__ */ jsx("div", {
|
|
1038
|
+
className: "gc-chat__part",
|
|
1039
|
+
"data-part": isToolUIPart(part) ? "tool" : part.type,
|
|
1040
|
+
children: renderPart(part, message, chat.status === "streaming" && message === last)
|
|
1041
|
+
}, isToolUIPart(part) ? `tool-${part.toolCallId}` : `${part.type}-${partIndex}`))
|
|
1042
|
+
}),
|
|
1043
|
+
message === last && message.role === "assistant" && !chat.isBusy && /* @__PURE__ */ jsxs(Fragment, { children: [actions.length > 0 && /* @__PURE__ */ jsxs("section", {
|
|
1044
|
+
className: "gc-chat__suggestions",
|
|
1045
|
+
"aria-label": labels.suggestions ?? "Suggested next steps",
|
|
1046
|
+
"aria-busy": pendingSuggestion !== void 0,
|
|
1047
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
1048
|
+
className: "gc-chat__suggestions-heading",
|
|
1049
|
+
children: [/* @__PURE__ */ jsx("h3", { children: suggestionsTitle ?? labels.suggestions ?? "Suggested next steps" }), suggestionsDescription != null && /* @__PURE__ */ jsx("span", {
|
|
1050
|
+
className: "gc-chat__suggestions-reason",
|
|
1051
|
+
children: suggestionsDescription
|
|
1052
|
+
})]
|
|
1053
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
1054
|
+
className: "gc-chat__suggestions-actions",
|
|
1055
|
+
children: actions.map((action, index) => /* @__PURE__ */ jsxs("button", {
|
|
1056
|
+
type: "button",
|
|
1057
|
+
className: "gc-chat__suggestion",
|
|
1058
|
+
"data-emphasis": action.emphasis === "recommended" && index !== recommendedIndex ? "secondary" : action.emphasis ?? "secondary",
|
|
1059
|
+
"data-pending": pendingSuggestion === action.id || void 0,
|
|
1060
|
+
disabled: actionPending || action.disabled,
|
|
1061
|
+
onClick: () => void selectSuggestion(action, message),
|
|
1062
|
+
children: [
|
|
1063
|
+
action.icon,
|
|
1064
|
+
pendingSuggestion === action.id ? action.pendingLabel ?? action.label : action.label,
|
|
1065
|
+
action.trailingIcon
|
|
1066
|
+
]
|
|
1067
|
+
}, action.id))
|
|
991
1068
|
})]
|
|
1069
|
+
}), renderMessageActions?.({
|
|
1070
|
+
message,
|
|
1071
|
+
chat,
|
|
1072
|
+
focusComposer
|
|
1073
|
+
})] }),
|
|
1074
|
+
message.role === "assistant" && /* @__PURE__ */ jsx("div", {
|
|
1075
|
+
className: "gc-chat__message-footer",
|
|
1076
|
+
children: showThinking && message === last ? thinking : /* @__PURE__ */ jsxs("div", {
|
|
1077
|
+
className: "gc-chat__message-actions",
|
|
1078
|
+
role: "group",
|
|
1079
|
+
"aria-label": labels.assistant,
|
|
1080
|
+
children: [getMessageText(message) && /* @__PURE__ */ jsx(ChatIconButton, {
|
|
1081
|
+
size: "sm",
|
|
1082
|
+
label: copiedId === message.id ? labels.copied : labels.copy,
|
|
1083
|
+
icon: copiedId === message.id ? "check" : "copy",
|
|
1084
|
+
"data-copied": copiedId === message.id || void 0,
|
|
1085
|
+
disabled: chat.isBusy && message === last,
|
|
1086
|
+
onClick: () => void copy(message)
|
|
1087
|
+
}), message === last && capabilities?.regenerate !== false && /* @__PURE__ */ jsx(ChatIconButton, {
|
|
1088
|
+
size: "sm",
|
|
1089
|
+
label: labels.regenerate,
|
|
1090
|
+
icon: "refresh",
|
|
1091
|
+
disabled: chat.isBusy || actionPending,
|
|
1092
|
+
onClick: () => void regenerate(message)
|
|
1093
|
+
})]
|
|
1094
|
+
})
|
|
992
1095
|
})
|
|
993
|
-
|
|
1096
|
+
]
|
|
994
1097
|
}, message.id)),
|
|
995
1098
|
showThinking && last?.role !== "assistant" && /* @__PURE__ */ jsx("article", {
|
|
996
1099
|
className: "gc-chat__message gc-chat__message--assistant",
|
|
@@ -1032,7 +1135,7 @@ function Messages({ chat, labels: labelOverrides, renderText, smoothStreaming =
|
|
|
1032
1135
|
function ChatPanel(props) {
|
|
1033
1136
|
return /* @__PURE__ */ jsx(Panel, { ...props }, props.chat.id);
|
|
1034
1137
|
}
|
|
1035
|
-
function Panel({ chat, labels: labelOverrides, title, header, headerActions, footer, composer, composerProps, theme = "auto", variant = "panel", density = "comfortable", capabilities, className, renderText, smoothStreaming, renderers, tools, toolPresentation, empty, requestOptions, onActionError, ...elementProps }) {
|
|
1138
|
+
function Panel({ chat, labels: labelOverrides, title, subtitle, headerIcon, header, headerActions, footer, composer, composerProps, theme = "auto", variant = "panel", density = "comfortable", capabilities, className, renderText, smoothStreaming, renderers, tools, toolPresentation, suggestedActions, suggestionsTitle, suggestionsDescription, renderMessageActions, renderMessageHeader, empty, requestOptions, onActionError, ...elementProps }) {
|
|
1036
1139
|
const labels = resolveLabels(labelOverrides);
|
|
1037
1140
|
const [retrying, setRetrying] = useState(false);
|
|
1038
1141
|
const [retryError, setRetryError] = useState();
|
|
@@ -1073,10 +1176,16 @@ function Panel({ chat, labels: labelOverrides, title, header, headerActions, foo
|
|
|
1073
1176
|
className: "gc-chat__heading",
|
|
1074
1177
|
children: [/* @__PURE__ */ jsx("span", {
|
|
1075
1178
|
className: "gc-chat__brand",
|
|
1076
|
-
children: /* @__PURE__ */ jsx(Icon, { name: "sparkle" })
|
|
1077
|
-
}), /* @__PURE__ */
|
|
1078
|
-
className: "gc-
|
|
1079
|
-
children:
|
|
1179
|
+
children: headerIcon ?? /* @__PURE__ */ jsx(Icon, { name: "sparkle" })
|
|
1180
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
1181
|
+
className: "gc-chat__header-copy",
|
|
1182
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
1183
|
+
className: "gc-chat__title",
|
|
1184
|
+
children: title ?? labels.title
|
|
1185
|
+
}), subtitle != null && /* @__PURE__ */ jsx("p", {
|
|
1186
|
+
className: "gc-chat__subtitle",
|
|
1187
|
+
children: subtitle
|
|
1188
|
+
})]
|
|
1080
1189
|
})]
|
|
1081
1190
|
}), headerActions && /* @__PURE__ */ jsx("div", {
|
|
1082
1191
|
className: "gc-chat__header-actions",
|
|
@@ -1092,6 +1201,11 @@ function Panel({ chat, labels: labelOverrides, title, header, headerActions, foo
|
|
|
1092
1201
|
renderers,
|
|
1093
1202
|
tools,
|
|
1094
1203
|
toolPresentation,
|
|
1204
|
+
suggestedActions,
|
|
1205
|
+
suggestionsTitle,
|
|
1206
|
+
suggestionsDescription,
|
|
1207
|
+
renderMessageActions,
|
|
1208
|
+
renderMessageHeader,
|
|
1095
1209
|
empty,
|
|
1096
1210
|
requestOptions,
|
|
1097
1211
|
onActionError
|
|
@@ -1319,6 +1433,6 @@ function ChatHistoryMenu({ conversations, currentId, onSelect, onNewChat, disabl
|
|
|
1319
1433
|
});
|
|
1320
1434
|
}
|
|
1321
1435
|
//#endregion
|
|
1322
|
-
export { AiChat, ChatAppearanceProvider, ChatComposer, ChatHistoryMenu, Icon as ChatIcon, ChatIconButton, ChatMessages, ChatPanel, ContextTray, SpeechInputError, createBrowserSpeechAdapter, createTextSelectionAdapter, defaultSpeechInputLabels, enUS, getMessageText, useAiChat, useChatContext, useSpeechInput, zhCN };
|
|
1436
|
+
export { AiChat, ChatAppearanceProvider, ChatComposer, ChatHistoryMenu, Icon as ChatIcon, ChatIconButton, ChatMessages, ChatPanel, ChatTargetingOverlay, ContextTray, SpeechInputError, createBrowserSpeechAdapter, createTextSelectionAdapter, defaultSpeechInputLabels, enUS, enUSTargetingLabels, getMessageText, toChatContextItem, useAiChat, useChatContext, useChatTargeting, useSpeechInput, zhCN, zhCNTargetingLabels };
|
|
1323
1437
|
|
|
1324
1438
|
//# sourceMappingURL=index.js.map
|