@openwarelabs/ui 0.4.0 → 0.5.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/README.md +3 -2
- package/dist/components/ChainOfThought/ChainOfThought.d.cts +44 -0
- package/dist/components/ChainOfThought/ChainOfThought.d.ts +44 -0
- package/dist/components/Chat/ChatConversation.d.cts +48 -0
- package/dist/components/Chat/ChatConversation.d.ts +48 -0
- package/dist/components/Chat/ChatLoader.d.cts +21 -0
- package/dist/components/Chat/ChatLoader.d.ts +21 -0
- package/dist/components/Chat/ChatMessage.d.cts +93 -0
- package/dist/components/Chat/ChatMessage.d.ts +93 -0
- package/dist/components/ChatSource/ChatSource.d.cts +58 -0
- package/dist/components/ChatSource/ChatSource.d.ts +58 -0
- package/dist/components/ChatTool/ChatTool.d.cts +89 -0
- package/dist/components/ChatTool/ChatTool.d.ts +89 -0
- package/dist/components/PromptInput/PromptInput.d.cts +95 -0
- package/dist/components/PromptInput/PromptInput.d.ts +95 -0
- package/dist/components/PromptInput/PromptSuggestion.d.cts +36 -0
- package/dist/components/PromptInput/PromptSuggestion.d.ts +36 -0
- package/dist/components/Prose/Prose.d.cts +22 -0
- package/dist/components/Prose/Prose.d.ts +22 -0
- package/dist/components/TextShimmer/TextShimmer.d.cts +20 -0
- package/dist/components/TextShimmer/TextShimmer.d.ts +20 -0
- package/dist/components.css +2524 -0
- package/dist/index.cjs +1548 -73
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +1573 -72
- package/dist/index.js.map +4 -4
- package/dist/openware-ui.iife.js +7 -6
- package/dist/styles.css +2524 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3824,7 +3824,7 @@ function FileDropZone({
|
|
|
3824
3824
|
}
|
|
3825
3825
|
keep(kept.current);
|
|
3826
3826
|
}
|
|
3827
|
-
const
|
|
3827
|
+
const hasFiles2 = (event) => event.dataTransfer.types.includes("Files");
|
|
3828
3828
|
return /* @__PURE__ */ jsxs20(
|
|
3829
3829
|
"label",
|
|
3830
3830
|
{
|
|
@@ -3836,13 +3836,13 @@ function FileDropZone({
|
|
|
3836
3836
|
className
|
|
3837
3837
|
),
|
|
3838
3838
|
onDragEnter: (event) => {
|
|
3839
|
-
if (!
|
|
3839
|
+
if (!hasFiles2(event) || disabled) return;
|
|
3840
3840
|
event.preventDefault();
|
|
3841
3841
|
depth.current += 1;
|
|
3842
3842
|
setIsDragging(true);
|
|
3843
3843
|
},
|
|
3844
3844
|
onDragOver: (event) => {
|
|
3845
|
-
if (!
|
|
3845
|
+
if (!hasFiles2(event) || disabled) return;
|
|
3846
3846
|
event.preventDefault();
|
|
3847
3847
|
event.dataTransfer.dropEffect = "copy";
|
|
3848
3848
|
},
|
|
@@ -3851,7 +3851,7 @@ function FileDropZone({
|
|
|
3851
3851
|
if (depth.current === 0) setIsDragging(false);
|
|
3852
3852
|
},
|
|
3853
3853
|
onDrop: (event) => {
|
|
3854
|
-
if (!
|
|
3854
|
+
if (!hasFiles2(event)) return;
|
|
3855
3855
|
event.preventDefault();
|
|
3856
3856
|
depth.current = 0;
|
|
3857
3857
|
setIsDragging(false);
|
|
@@ -6400,10 +6400,1497 @@ function DotGrid({ fade = false, interactive = false, className, children, onPoi
|
|
|
6400
6400
|
);
|
|
6401
6401
|
}
|
|
6402
6402
|
|
|
6403
|
+
// src/components/Prose/Prose.tsx
|
|
6404
|
+
import { forwardRef as forwardRef23 } from "react";
|
|
6405
|
+
import { jsx as jsx62 } from "react/jsx-runtime";
|
|
6406
|
+
var Prose = forwardRef23(function Prose2({ size: size2 = "md", fullWidth = false, as = "div", className, children, ...props }, ref) {
|
|
6407
|
+
const Element2 = as;
|
|
6408
|
+
return /* @__PURE__ */ jsx62(
|
|
6409
|
+
Element2,
|
|
6410
|
+
{
|
|
6411
|
+
ref,
|
|
6412
|
+
className: cx("ow-prose", `ow-prose--${size2}`, size2 === "md" ? "ow-type-prose" : "ow-type-copy", fullWidth && "ow-prose--full", className),
|
|
6413
|
+
...props,
|
|
6414
|
+
children
|
|
6415
|
+
}
|
|
6416
|
+
);
|
|
6417
|
+
});
|
|
6418
|
+
|
|
6419
|
+
// src/components/TextShimmer/TextShimmer.tsx
|
|
6420
|
+
import { jsx as jsx63 } from "react/jsx-runtime";
|
|
6421
|
+
function TextShimmer({ children, as = "span", duration = 2, active = true, className }) {
|
|
6422
|
+
const Element2 = as;
|
|
6423
|
+
return /* @__PURE__ */ jsx63(
|
|
6424
|
+
Element2,
|
|
6425
|
+
{
|
|
6426
|
+
className: cx("ow-shimmer", active && "ow-shimmer--active", className),
|
|
6427
|
+
style: active ? { "--ow-shimmer-duration": `${duration}s` } : void 0,
|
|
6428
|
+
children
|
|
6429
|
+
}
|
|
6430
|
+
);
|
|
6431
|
+
}
|
|
6432
|
+
|
|
6433
|
+
// src/components/PromptInput/PromptInput.tsx
|
|
6434
|
+
import {
|
|
6435
|
+
forwardRef as forwardRef24,
|
|
6436
|
+
useEffect as useEffect26,
|
|
6437
|
+
useId as useId22,
|
|
6438
|
+
useLayoutEffect as useLayoutEffect7,
|
|
6439
|
+
useRef as useRef34,
|
|
6440
|
+
useState as useState29
|
|
6441
|
+
} from "react";
|
|
6442
|
+
import { jsx as jsx64, jsxs as jsxs48 } from "react/jsx-runtime";
|
|
6443
|
+
var noAttachments = [];
|
|
6444
|
+
var counterFrom = 0.8;
|
|
6445
|
+
var announceDelay = 1e3;
|
|
6446
|
+
function Glyph({ children }) {
|
|
6447
|
+
return /* @__PURE__ */ jsx64(
|
|
6448
|
+
"svg",
|
|
6449
|
+
{
|
|
6450
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
6451
|
+
width: 16,
|
|
6452
|
+
height: 16,
|
|
6453
|
+
viewBox: "0 0 24 24",
|
|
6454
|
+
fill: "none",
|
|
6455
|
+
stroke: "currentColor",
|
|
6456
|
+
strokeWidth: 2,
|
|
6457
|
+
strokeLinecap: "round",
|
|
6458
|
+
strokeLinejoin: "round",
|
|
6459
|
+
"aria-hidden": "true",
|
|
6460
|
+
focusable: "false",
|
|
6461
|
+
children
|
|
6462
|
+
}
|
|
6463
|
+
);
|
|
6464
|
+
}
|
|
6465
|
+
var sheet = "M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z";
|
|
6466
|
+
var fold = "M14 2v5a1 1 0 0 0 1 1h5";
|
|
6467
|
+
var PaperclipIcon = () => /* @__PURE__ */ jsx64(Glyph, { children: /* @__PURE__ */ jsx64("path", { d: "m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551" }) });
|
|
6468
|
+
var StopIcon = () => /* @__PURE__ */ jsx64(Glyph, { children: /* @__PURE__ */ jsx64("rect", { x: "6", y: "6", width: "12", height: "12", rx: "2", fill: "currentColor", stroke: "none" }) });
|
|
6469
|
+
var fileIcons = {
|
|
6470
|
+
image: /* @__PURE__ */ jsxs48(Glyph, { children: [
|
|
6471
|
+
/* @__PURE__ */ jsx64("path", { d: sheet }),
|
|
6472
|
+
/* @__PURE__ */ jsx64("path", { d: fold }),
|
|
6473
|
+
/* @__PURE__ */ jsx64("circle", { cx: "10", cy: "12", r: "2" }),
|
|
6474
|
+
/* @__PURE__ */ jsx64("path", { d: "m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22" })
|
|
6475
|
+
] }),
|
|
6476
|
+
code: /* @__PURE__ */ jsxs48(Glyph, { children: [
|
|
6477
|
+
/* @__PURE__ */ jsx64("path", { d: sheet }),
|
|
6478
|
+
/* @__PURE__ */ jsx64("path", { d: fold }),
|
|
6479
|
+
/* @__PURE__ */ jsx64("path", { d: "M10 12.5 8 15l2 2.5" }),
|
|
6480
|
+
/* @__PURE__ */ jsx64("path", { d: "m14 12.5 2 2.5-2 2.5" })
|
|
6481
|
+
] }),
|
|
6482
|
+
text: /* @__PURE__ */ jsxs48(Glyph, { children: [
|
|
6483
|
+
/* @__PURE__ */ jsx64("path", { d: sheet }),
|
|
6484
|
+
/* @__PURE__ */ jsx64("path", { d: fold }),
|
|
6485
|
+
/* @__PURE__ */ jsx64("path", { d: "M10 9H8" }),
|
|
6486
|
+
/* @__PURE__ */ jsx64("path", { d: "M16 13H8" }),
|
|
6487
|
+
/* @__PURE__ */ jsx64("path", { d: "M16 17H8" })
|
|
6488
|
+
] }),
|
|
6489
|
+
file: /* @__PURE__ */ jsx64(FileIcon, { size: 16 })
|
|
6490
|
+
};
|
|
6491
|
+
function kindOf({ name, type = "" }) {
|
|
6492
|
+
const lower = name.toLowerCase();
|
|
6493
|
+
if (type.startsWith("image/") || /\.(png|jpe?g|gif|webp|avif|heic|svg)$/.test(lower)) return "image";
|
|
6494
|
+
if (/\.(tsx?|jsx?|mjs|cjs|py|go|rs|rb|java|kt|swift|c|cc|cpp|h|cs|php|css|scss|html|json|ya?ml|toml|sql|sh)$/.test(lower)) return "code";
|
|
6495
|
+
if (type.startsWith("text/") || type === "application/pdf" || /\.(txt|md|log|csv|pdf|docx?|rtf)$/.test(lower)) return "text";
|
|
6496
|
+
return "file";
|
|
6497
|
+
}
|
|
6498
|
+
function splitName(name) {
|
|
6499
|
+
const dot = name.lastIndexOf(".");
|
|
6500
|
+
if (dot <= 0 || name.length - dot > 8) return [name, ""];
|
|
6501
|
+
return [name.slice(0, dot), name.slice(dot)];
|
|
6502
|
+
}
|
|
6503
|
+
function formatBytes(bytes, locale) {
|
|
6504
|
+
const units = ["byte", "kilobyte", "megabyte", "gigabyte"];
|
|
6505
|
+
let value = bytes;
|
|
6506
|
+
let unit = 0;
|
|
6507
|
+
while (value >= 1e3 && unit < units.length - 1) {
|
|
6508
|
+
value /= 1e3;
|
|
6509
|
+
unit += 1;
|
|
6510
|
+
}
|
|
6511
|
+
return new Intl.NumberFormat(locale, {
|
|
6512
|
+
style: "unit",
|
|
6513
|
+
unit: units[unit],
|
|
6514
|
+
unitDisplay: unit === 0 ? "long" : "short",
|
|
6515
|
+
maximumFractionDigits: unit > 0 && value < 10 ? 1 : 0
|
|
6516
|
+
}).format(value);
|
|
6517
|
+
}
|
|
6518
|
+
function accepts(file, accept) {
|
|
6519
|
+
if (!accept) return true;
|
|
6520
|
+
return accept.split(",").some((rule) => {
|
|
6521
|
+
const pattern = rule.trim().toLowerCase();
|
|
6522
|
+
if (!pattern) return false;
|
|
6523
|
+
if (pattern.startsWith(".")) return file.name.toLowerCase().endsWith(pattern);
|
|
6524
|
+
if (pattern.endsWith("/*")) return file.type.toLowerCase().startsWith(pattern.slice(0, -1));
|
|
6525
|
+
return file.type.toLowerCase() === pattern;
|
|
6526
|
+
});
|
|
6527
|
+
}
|
|
6528
|
+
var hasFiles = (event) => Array.from(event.dataTransfer.types).includes("Files");
|
|
6529
|
+
var PromptInput = forwardRef24(function PromptInput2({
|
|
6530
|
+
value,
|
|
6531
|
+
defaultValue = "",
|
|
6532
|
+
onChange,
|
|
6533
|
+
onSubmit,
|
|
6534
|
+
isStreaming = false,
|
|
6535
|
+
onStop,
|
|
6536
|
+
attachments = noAttachments,
|
|
6537
|
+
onAttach,
|
|
6538
|
+
onRemoveAttachment,
|
|
6539
|
+
accept,
|
|
6540
|
+
multiple = true,
|
|
6541
|
+
startActions,
|
|
6542
|
+
endActions,
|
|
6543
|
+
hint,
|
|
6544
|
+
placeholder = "Message the agent\u2026",
|
|
6545
|
+
"aria-label": ariaLabel,
|
|
6546
|
+
"aria-labelledby": ariaLabelledBy,
|
|
6547
|
+
"aria-describedby": ariaDescribedBy,
|
|
6548
|
+
id,
|
|
6549
|
+
isInvalid = false,
|
|
6550
|
+
disabled = false,
|
|
6551
|
+
autoFocus = false,
|
|
6552
|
+
maxLength,
|
|
6553
|
+
minRows = 1,
|
|
6554
|
+
maxRows = 8,
|
|
6555
|
+
size: size2 = "md",
|
|
6556
|
+
locale,
|
|
6557
|
+
onKeyDown,
|
|
6558
|
+
className
|
|
6559
|
+
}, ref) {
|
|
6560
|
+
const [text, setText] = useControllableState(value, defaultValue, onChange);
|
|
6561
|
+
const textAreaRef = useRef34(null);
|
|
6562
|
+
const actionRef = useRef34(null);
|
|
6563
|
+
const pickerRef = useRef34(null);
|
|
6564
|
+
const listRef = useRef34(null);
|
|
6565
|
+
const composing = useRef34(false);
|
|
6566
|
+
const dragDepth = useRef34(0);
|
|
6567
|
+
const pendingFocus = useRef34(null);
|
|
6568
|
+
const [isDragging, setIsDragging] = useState29(false);
|
|
6569
|
+
const [notice, setNotice] = useState29();
|
|
6570
|
+
const [announcement, setAnnouncement] = useState29("");
|
|
6571
|
+
const hintId = useId22();
|
|
6572
|
+
const rows = Math.max(1, Math.round(minRows));
|
|
6573
|
+
const maxRowCount = Math.max(rows, Math.round(maxRows));
|
|
6574
|
+
const canAttach = Boolean(onAttach) && !disabled;
|
|
6575
|
+
const hasContent = text.trim().length > 0 || attachments.length > 0;
|
|
6576
|
+
const canSend = hasContent && !disabled && !isStreaming;
|
|
6577
|
+
const toolbarStart = Boolean(onAttach || startActions);
|
|
6578
|
+
const inline = !toolbarStart && !endActions;
|
|
6579
|
+
const showCounter = maxLength !== void 0 && maxLength > 0 && text.length >= maxLength * counterFrom;
|
|
6580
|
+
const remaining = maxLength === void 0 ? 0 : Math.max(0, maxLength - text.length);
|
|
6581
|
+
const number = (count) => new Intl.NumberFormat(locale).format(count);
|
|
6582
|
+
const shownHint = notice ?? hint;
|
|
6583
|
+
const describedBy = [ariaDescribedBy, hint && !notice ? hintId : void 0].filter(Boolean).join(" ") || void 0;
|
|
6584
|
+
const name = ariaLabel ?? (ariaLabelledBy || id ? void 0 : "Message");
|
|
6585
|
+
function setTextAreaRef(element) {
|
|
6586
|
+
textAreaRef.current = element;
|
|
6587
|
+
if (typeof ref === "function") ref(element);
|
|
6588
|
+
else if (ref) ref.current = element;
|
|
6589
|
+
}
|
|
6590
|
+
useEffect26(() => {
|
|
6591
|
+
const textArea = textAreaRef.current;
|
|
6592
|
+
if (!textArea || typeof ResizeObserver === "undefined") return;
|
|
6593
|
+
let width = textArea.clientWidth;
|
|
6594
|
+
const observer = new ResizeObserver(() => {
|
|
6595
|
+
if (textArea.clientWidth === width) return;
|
|
6596
|
+
width = textArea.clientWidth;
|
|
6597
|
+
resizeTextArea(textArea);
|
|
6598
|
+
});
|
|
6599
|
+
observer.observe(textArea);
|
|
6600
|
+
return () => observer.disconnect();
|
|
6601
|
+
}, []);
|
|
6602
|
+
useLayoutEffect7(() => {
|
|
6603
|
+
if (textAreaRef.current) resizeTextArea(textAreaRef.current);
|
|
6604
|
+
}, [size2, rows]);
|
|
6605
|
+
const wasStreaming = useRef34(isStreaming);
|
|
6606
|
+
const actionHadFocus = useRef34(false);
|
|
6607
|
+
if (wasStreaming.current !== isStreaming) {
|
|
6608
|
+
actionHadFocus.current = typeof document !== "undefined" && document.activeElement === actionRef.current;
|
|
6609
|
+
}
|
|
6610
|
+
useLayoutEffect7(() => {
|
|
6611
|
+
if (wasStreaming.current && !isStreaming && actionHadFocus.current && !hasContent) textAreaRef.current?.focus();
|
|
6612
|
+
wasStreaming.current = isStreaming;
|
|
6613
|
+
actionHadFocus.current = false;
|
|
6614
|
+
}, [isStreaming, hasContent]);
|
|
6615
|
+
useLayoutEffect7(() => {
|
|
6616
|
+
const pending = pendingFocus.current;
|
|
6617
|
+
if (!pending) return;
|
|
6618
|
+
pendingFocus.current = null;
|
|
6619
|
+
if (attachments.some((attachment) => attachment.id === pending.id)) return;
|
|
6620
|
+
const buttons = listRef.current?.querySelectorAll(".ow-prompt-input__remove");
|
|
6621
|
+
const next = buttons?.length ? buttons[Math.min(pending.index, buttons.length - 1)] : void 0;
|
|
6622
|
+
(next ?? textAreaRef.current)?.focus();
|
|
6623
|
+
}, [attachments]);
|
|
6624
|
+
useEffect26(() => {
|
|
6625
|
+
if (!showCounter || document.activeElement !== textAreaRef.current) return;
|
|
6626
|
+
const timer = window.setTimeout(() => {
|
|
6627
|
+
setAnnouncement(`${number(remaining)} ${remaining === 1 ? "character" : "characters"} left`);
|
|
6628
|
+
}, announceDelay);
|
|
6629
|
+
return () => window.clearTimeout(timer);
|
|
6630
|
+
}, [showCounter, remaining, locale]);
|
|
6631
|
+
function submit() {
|
|
6632
|
+
if (!canSend) return;
|
|
6633
|
+
onSubmit?.(text.trim(), attachments);
|
|
6634
|
+
setNotice(void 0);
|
|
6635
|
+
if (value === void 0) setText("");
|
|
6636
|
+
}
|
|
6637
|
+
function stop() {
|
|
6638
|
+
if (isStreaming && !disabled) onStop?.();
|
|
6639
|
+
}
|
|
6640
|
+
function take(list) {
|
|
6641
|
+
if (!canAttach || !list.length) return;
|
|
6642
|
+
const files = multiple ? list : list.slice(0, 1);
|
|
6643
|
+
const refused = files.find((file) => !accepts(file, accept));
|
|
6644
|
+
const taken = files.filter((file) => accepts(file, accept));
|
|
6645
|
+
let message;
|
|
6646
|
+
if (refused) message = `\u201C${refused.name}\u201D isn't a file this accepts.`;
|
|
6647
|
+
else if (!multiple && list.length > 1) message = "Attach one file at a time.";
|
|
6648
|
+
setNotice(message);
|
|
6649
|
+
if (message) setAnnouncement(message);
|
|
6650
|
+
if (taken.length) onAttach?.(taken);
|
|
6651
|
+
}
|
|
6652
|
+
function remove(attachment, index) {
|
|
6653
|
+
if (listRef.current?.contains(document.activeElement)) pendingFocus.current = { id: attachment.id, index };
|
|
6654
|
+
onRemoveAttachment?.(attachment.id);
|
|
6655
|
+
}
|
|
6656
|
+
function handleKeyDown(event) {
|
|
6657
|
+
onKeyDown?.(event);
|
|
6658
|
+
if (event.defaultPrevented) return;
|
|
6659
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
6660
|
+
if (composing.current || event.nativeEvent.isComposing || event.keyCode === 229) return;
|
|
6661
|
+
event.preventDefault();
|
|
6662
|
+
submit();
|
|
6663
|
+
} else if (event.key === "Escape" && isStreaming && onStop) {
|
|
6664
|
+
event.preventDefault();
|
|
6665
|
+
event.stopPropagation();
|
|
6666
|
+
stop();
|
|
6667
|
+
}
|
|
6668
|
+
}
|
|
6669
|
+
function handlePaste(event) {
|
|
6670
|
+
if (!canAttach) return;
|
|
6671
|
+
const files = Array.from(event.clipboardData.files);
|
|
6672
|
+
if (!files.length || event.clipboardData.getData("text/plain")) return;
|
|
6673
|
+
event.preventDefault();
|
|
6674
|
+
take(files);
|
|
6675
|
+
}
|
|
6676
|
+
function handleMouseDown(event) {
|
|
6677
|
+
const target = event.target;
|
|
6678
|
+
if (disabled || target !== event.currentTarget && !target.hasAttribute("data-prompt-blank")) return;
|
|
6679
|
+
event.preventDefault();
|
|
6680
|
+
textAreaRef.current?.focus();
|
|
6681
|
+
}
|
|
6682
|
+
const attachButton = onAttach ? /* @__PURE__ */ jsx64(Tooltip, { label: "Attach files", children: /* @__PURE__ */ jsx64(
|
|
6683
|
+
Button,
|
|
6684
|
+
{
|
|
6685
|
+
className: "ow-prompt-input__attach",
|
|
6686
|
+
variant: "ghost",
|
|
6687
|
+
size: "sm",
|
|
6688
|
+
iconOnly: true,
|
|
6689
|
+
"aria-label": multiple ? "Attach files" : "Attach a file",
|
|
6690
|
+
disabled,
|
|
6691
|
+
onClick: () => pickerRef.current?.click(),
|
|
6692
|
+
children: /* @__PURE__ */ jsx64(PaperclipIcon, {})
|
|
6693
|
+
}
|
|
6694
|
+
) }) : null;
|
|
6695
|
+
const actionLabel = isStreaming ? "Stop" : "Send";
|
|
6696
|
+
const actionButton = /* @__PURE__ */ jsx64(Tooltip, { label: actionLabel, children: /* @__PURE__ */ jsx64(
|
|
6697
|
+
Button,
|
|
6698
|
+
{
|
|
6699
|
+
ref: actionRef,
|
|
6700
|
+
className: "ow-prompt-input__action",
|
|
6701
|
+
variant: "primary",
|
|
6702
|
+
size: "sm",
|
|
6703
|
+
iconOnly: true,
|
|
6704
|
+
"aria-label": actionLabel,
|
|
6705
|
+
disabled: disabled || (isStreaming ? !onStop : !hasContent),
|
|
6706
|
+
onClick: () => {
|
|
6707
|
+
if (isStreaming) stop();
|
|
6708
|
+
else submit();
|
|
6709
|
+
textAreaRef.current?.focus();
|
|
6710
|
+
},
|
|
6711
|
+
children: isStreaming ? /* @__PURE__ */ jsx64(StopIcon, {}) : /* @__PURE__ */ jsx64(ArrowUpIcon, { size: 16 })
|
|
6712
|
+
}
|
|
6713
|
+
) });
|
|
6714
|
+
return /* @__PURE__ */ jsxs48(
|
|
6715
|
+
"div",
|
|
6716
|
+
{
|
|
6717
|
+
className: cx(
|
|
6718
|
+
"ow-prompt-input",
|
|
6719
|
+
`ow-prompt-input--${size2}`,
|
|
6720
|
+
inline && "ow-prompt-input--inline",
|
|
6721
|
+
isInvalid && "ow-prompt-input--invalid",
|
|
6722
|
+
disabled && "ow-prompt-input--disabled",
|
|
6723
|
+
isDragging && "ow-prompt-input--dragging",
|
|
6724
|
+
className
|
|
6725
|
+
),
|
|
6726
|
+
style: { "--ow-prompt-min-rows": rows, "--ow-prompt-max-rows": maxRowCount },
|
|
6727
|
+
children: [
|
|
6728
|
+
/* @__PURE__ */ jsxs48(
|
|
6729
|
+
"fieldset",
|
|
6730
|
+
{
|
|
6731
|
+
role: "presentation",
|
|
6732
|
+
className: "ow-prompt-input__box",
|
|
6733
|
+
disabled,
|
|
6734
|
+
onMouseDown: handleMouseDown,
|
|
6735
|
+
onDragEnter: (event) => {
|
|
6736
|
+
if (!canAttach || !hasFiles(event)) return;
|
|
6737
|
+
event.preventDefault();
|
|
6738
|
+
dragDepth.current += 1;
|
|
6739
|
+
setIsDragging(true);
|
|
6740
|
+
},
|
|
6741
|
+
onDragOver: (event) => {
|
|
6742
|
+
if (!canAttach || !hasFiles(event)) return;
|
|
6743
|
+
event.preventDefault();
|
|
6744
|
+
event.dataTransfer.dropEffect = "copy";
|
|
6745
|
+
},
|
|
6746
|
+
onDragLeave: () => {
|
|
6747
|
+
dragDepth.current = Math.max(0, dragDepth.current - 1);
|
|
6748
|
+
if (dragDepth.current === 0) setIsDragging(false);
|
|
6749
|
+
},
|
|
6750
|
+
onDrop: (event) => {
|
|
6751
|
+
if (!canAttach || !hasFiles(event)) return;
|
|
6752
|
+
event.preventDefault();
|
|
6753
|
+
dragDepth.current = 0;
|
|
6754
|
+
setIsDragging(false);
|
|
6755
|
+
take(Array.from(event.dataTransfer.files));
|
|
6756
|
+
},
|
|
6757
|
+
children: [
|
|
6758
|
+
attachments.length ? /* @__PURE__ */ jsx64("ul", { ref: listRef, className: "ow-prompt-input__attachments", "aria-label": "Attachments", children: attachments.map((attachment, index) => {
|
|
6759
|
+
const [base, extension] = splitName(attachment.name);
|
|
6760
|
+
return /* @__PURE__ */ jsxs48("li", { className: "ow-prompt-input__attachment", children: [
|
|
6761
|
+
/* @__PURE__ */ jsxs48("span", { className: "ow-prompt-input__thumb", "aria-hidden": "true", children: [
|
|
6762
|
+
fileIcons[kindOf(attachment)],
|
|
6763
|
+
attachment.previewUrl ? /* @__PURE__ */ jsx64(
|
|
6764
|
+
"img",
|
|
6765
|
+
{
|
|
6766
|
+
src: attachment.previewUrl,
|
|
6767
|
+
alt: "",
|
|
6768
|
+
onError: (event) => {
|
|
6769
|
+
event.currentTarget.hidden = true;
|
|
6770
|
+
}
|
|
6771
|
+
}
|
|
6772
|
+
) : null
|
|
6773
|
+
] }),
|
|
6774
|
+
/* @__PURE__ */ jsxs48("span", { className: "ow-prompt-input__file", children: [
|
|
6775
|
+
/* @__PURE__ */ jsxs48("span", { className: "ow-prompt-input__file-name", title: attachment.name, children: [
|
|
6776
|
+
/* @__PURE__ */ jsx64("span", { className: "ow-prompt-input__file-base", children: base }),
|
|
6777
|
+
extension
|
|
6778
|
+
] }),
|
|
6779
|
+
attachment.size !== void 0 ? /* @__PURE__ */ jsx64("span", { className: "ow-prompt-input__file-size", children: formatBytes(attachment.size, locale) }) : null
|
|
6780
|
+
] }),
|
|
6781
|
+
onRemoveAttachment ? /* @__PURE__ */ jsx64(
|
|
6782
|
+
"button",
|
|
6783
|
+
{
|
|
6784
|
+
type: "button",
|
|
6785
|
+
className: "ow-prompt-input__remove",
|
|
6786
|
+
"aria-label": `Remove ${attachment.name}`,
|
|
6787
|
+
onClick: () => remove(attachment, index),
|
|
6788
|
+
children: /* @__PURE__ */ jsx64(XIcon, { size: 14 })
|
|
6789
|
+
}
|
|
6790
|
+
) : null
|
|
6791
|
+
] }, attachment.id);
|
|
6792
|
+
}) }) : null,
|
|
6793
|
+
/* @__PURE__ */ jsx64(
|
|
6794
|
+
Textarea,
|
|
6795
|
+
{
|
|
6796
|
+
ref: setTextAreaRef,
|
|
6797
|
+
className: "ow-prompt-input__textarea",
|
|
6798
|
+
bare: true,
|
|
6799
|
+
autoGrow: true,
|
|
6800
|
+
autoGrowMaxHeight: `calc(var(--ow-prompt-line) * ${maxRowCount} + 2 * var(--ow-prompt-pad))`,
|
|
6801
|
+
rows,
|
|
6802
|
+
id,
|
|
6803
|
+
value: text,
|
|
6804
|
+
placeholder,
|
|
6805
|
+
"aria-label": name,
|
|
6806
|
+
"aria-labelledby": ariaLabelledBy,
|
|
6807
|
+
"aria-describedby": describedBy,
|
|
6808
|
+
isInvalid,
|
|
6809
|
+
disabled,
|
|
6810
|
+
autoFocus,
|
|
6811
|
+
maxLength,
|
|
6812
|
+
enterKeyHint: "send",
|
|
6813
|
+
onChange: (event) => setText(event.target.value),
|
|
6814
|
+
onKeyDown: handleKeyDown,
|
|
6815
|
+
onPaste: handlePaste,
|
|
6816
|
+
onCompositionStart: () => {
|
|
6817
|
+
composing.current = true;
|
|
6818
|
+
},
|
|
6819
|
+
onCompositionEnd: () => {
|
|
6820
|
+
composing.current = false;
|
|
6821
|
+
}
|
|
6822
|
+
}
|
|
6823
|
+
),
|
|
6824
|
+
/* @__PURE__ */ jsxs48("div", { className: "ow-prompt-input__toolbar", "data-prompt-blank": "", children: [
|
|
6825
|
+
toolbarStart ? /* @__PURE__ */ jsxs48("div", { className: "ow-prompt-input__start", "data-prompt-blank": "", children: [
|
|
6826
|
+
attachButton,
|
|
6827
|
+
startActions
|
|
6828
|
+
] }) : null,
|
|
6829
|
+
/* @__PURE__ */ jsxs48("div", { className: "ow-prompt-input__end", "data-prompt-blank": "", children: [
|
|
6830
|
+
showCounter ? /* @__PURE__ */ jsxs48("span", { className: cx("ow-prompt-input__counter", remaining === 0 && "ow-prompt-input__counter--full"), "aria-hidden": "true", children: [
|
|
6831
|
+
number(text.length),
|
|
6832
|
+
" / ",
|
|
6833
|
+
number(maxLength)
|
|
6834
|
+
] }) : null,
|
|
6835
|
+
endActions,
|
|
6836
|
+
actionButton
|
|
6837
|
+
] })
|
|
6838
|
+
] }),
|
|
6839
|
+
onAttach ? /* @__PURE__ */ jsx64(
|
|
6840
|
+
"input",
|
|
6841
|
+
{
|
|
6842
|
+
ref: pickerRef,
|
|
6843
|
+
type: "file",
|
|
6844
|
+
hidden: true,
|
|
6845
|
+
tabIndex: -1,
|
|
6846
|
+
accept,
|
|
6847
|
+
multiple,
|
|
6848
|
+
onChange: (event) => {
|
|
6849
|
+
take(Array.from(event.target.files ?? []));
|
|
6850
|
+
event.target.value = "";
|
|
6851
|
+
textAreaRef.current?.focus();
|
|
6852
|
+
}
|
|
6853
|
+
}
|
|
6854
|
+
) : null,
|
|
6855
|
+
isDragging ? /* @__PURE__ */ jsxs48("div", { className: "ow-prompt-input__drop", "aria-hidden": "true", children: [
|
|
6856
|
+
/* @__PURE__ */ jsx64(UploadIcon, { size: 16 }),
|
|
6857
|
+
"Drop to attach"
|
|
6858
|
+
] }) : null
|
|
6859
|
+
]
|
|
6860
|
+
}
|
|
6861
|
+
),
|
|
6862
|
+
shownHint ? /* @__PURE__ */ jsx64(
|
|
6863
|
+
"div",
|
|
6864
|
+
{
|
|
6865
|
+
className: cx("ow-prompt-input__hint", notice && "ow-prompt-input__hint--notice"),
|
|
6866
|
+
id: notice ? void 0 : hintId,
|
|
6867
|
+
"aria-hidden": notice ? true : void 0,
|
|
6868
|
+
children: shownHint
|
|
6869
|
+
}
|
|
6870
|
+
) : null,
|
|
6871
|
+
/* @__PURE__ */ jsx64("span", { className: "ow-visually-hidden", role: "status", children: announcement })
|
|
6872
|
+
]
|
|
6873
|
+
}
|
|
6874
|
+
);
|
|
6875
|
+
});
|
|
6876
|
+
|
|
6877
|
+
// src/components/PromptInput/PromptSuggestion.tsx
|
|
6878
|
+
import { forwardRef as forwardRef25 } from "react";
|
|
6879
|
+
import { jsx as jsx65, jsxs as jsxs49 } from "react/jsx-runtime";
|
|
6880
|
+
var PromptSuggestion = forwardRef25(function PromptSuggestion2({ children, icon: icon2, description, variant = description ? "card" : "pill", type = "button", className, ...buttonProps }, ref) {
|
|
6881
|
+
if (variant === "card") {
|
|
6882
|
+
return /* @__PURE__ */ jsxs49("button", { ref, type, className: cx("ow-prompt-suggestion", "ow-prompt-suggestion--card", className), ...buttonProps, children: [
|
|
6883
|
+
icon2 ? /* @__PURE__ */ jsx65("span", { className: "ow-prompt-suggestion__icon", children: icon2 }) : null,
|
|
6884
|
+
/* @__PURE__ */ jsxs49("span", { className: "ow-prompt-suggestion__text", children: [
|
|
6885
|
+
/* @__PURE__ */ jsx65("span", { className: "ow-prompt-suggestion__title", children }),
|
|
6886
|
+
description ? /* @__PURE__ */ jsx65("span", { className: "ow-prompt-suggestion__description", children: description }) : null
|
|
6887
|
+
] })
|
|
6888
|
+
] });
|
|
6889
|
+
}
|
|
6890
|
+
return /* @__PURE__ */ jsxs49(
|
|
6891
|
+
"button",
|
|
6892
|
+
{
|
|
6893
|
+
ref,
|
|
6894
|
+
type,
|
|
6895
|
+
className: cx(
|
|
6896
|
+
buttonClassName({ variant: "secondary", size: "sm", shape: "pill" }),
|
|
6897
|
+
"ow-prompt-suggestion",
|
|
6898
|
+
"ow-prompt-suggestion--pill",
|
|
6899
|
+
className
|
|
6900
|
+
),
|
|
6901
|
+
...buttonProps,
|
|
6902
|
+
children: [
|
|
6903
|
+
icon2 ? /* @__PURE__ */ jsx65("span", { className: "ow-prompt-suggestion__icon", children: icon2 }) : null,
|
|
6904
|
+
/* @__PURE__ */ jsx65("span", { className: "ow-prompt-suggestion__label", children })
|
|
6905
|
+
]
|
|
6906
|
+
}
|
|
6907
|
+
);
|
|
6908
|
+
});
|
|
6909
|
+
function PromptSuggestions({
|
|
6910
|
+
children,
|
|
6911
|
+
layout = "wrap",
|
|
6912
|
+
columns = 2,
|
|
6913
|
+
align = "start",
|
|
6914
|
+
"aria-label": ariaLabel = "Suggested prompts",
|
|
6915
|
+
className,
|
|
6916
|
+
style,
|
|
6917
|
+
...props
|
|
6918
|
+
}) {
|
|
6919
|
+
return /* @__PURE__ */ jsx65(
|
|
6920
|
+
"div",
|
|
6921
|
+
{
|
|
6922
|
+
role: "group",
|
|
6923
|
+
"aria-label": ariaLabel,
|
|
6924
|
+
className: cx("ow-prompt-suggestions", `ow-prompt-suggestions--${layout}`, align === "center" && "ow-prompt-suggestions--center", className),
|
|
6925
|
+
style: layout === "grid" ? { "--ow-suggestion-columns": Math.max(1, Math.round(columns)), ...style } : style,
|
|
6926
|
+
...props,
|
|
6927
|
+
children
|
|
6928
|
+
}
|
|
6929
|
+
);
|
|
6930
|
+
}
|
|
6931
|
+
|
|
6932
|
+
// src/components/Chat/ChatConversation.tsx
|
|
6933
|
+
import {
|
|
6934
|
+
Children as Children2,
|
|
6935
|
+
createContext as createContext8,
|
|
6936
|
+
forwardRef as forwardRef26,
|
|
6937
|
+
useCallback as useCallback10,
|
|
6938
|
+
useEffect as useEffect27,
|
|
6939
|
+
useImperativeHandle as useImperativeHandle3,
|
|
6940
|
+
useLayoutEffect as useLayoutEffect8,
|
|
6941
|
+
useMemo as useMemo12,
|
|
6942
|
+
useRef as useRef35,
|
|
6943
|
+
useState as useState30
|
|
6944
|
+
} from "react";
|
|
6945
|
+
import { jsx as jsx66, jsxs as jsxs50 } from "react/jsx-runtime";
|
|
6946
|
+
var ChatConversationContext = createContext8(null);
|
|
6947
|
+
var stickyDistance = 32;
|
|
6948
|
+
var defaultCount = (count) => `${count} new`;
|
|
6949
|
+
var prefersReducedMotion = () => typeof window !== "undefined" && Boolean(window.matchMedia?.("(prefers-reduced-motion: reduce)").matches);
|
|
6950
|
+
var ChatConversation = forwardRef26(function ChatConversation2({
|
|
6951
|
+
children,
|
|
6952
|
+
empty,
|
|
6953
|
+
footer,
|
|
6954
|
+
"aria-label": ariaLabel = "Conversation",
|
|
6955
|
+
"aria-labelledby": ariaLabelledBy,
|
|
6956
|
+
width = "comfortable",
|
|
6957
|
+
jumpLabel = "Jump to latest",
|
|
6958
|
+
formatNewCount = defaultCount,
|
|
6959
|
+
className,
|
|
6960
|
+
...props
|
|
6961
|
+
}, ref) {
|
|
6962
|
+
const scrollerRef = useRef35(null);
|
|
6963
|
+
const contentRef = useRef35(null);
|
|
6964
|
+
const jumpRef = useRef35(null);
|
|
6965
|
+
const following = useRef35(true);
|
|
6966
|
+
const lastTop = useRef35(0);
|
|
6967
|
+
const ready = useRef35(false);
|
|
6968
|
+
const unseen = useRef35(/* @__PURE__ */ new Set());
|
|
6969
|
+
const [isFollowing, setIsFollowing] = useState30(true);
|
|
6970
|
+
const [newCount, setNewCount] = useState30(0);
|
|
6971
|
+
const isEmpty = Children2.toArray(children).length === 0;
|
|
6972
|
+
const follow = useCallback10((next) => {
|
|
6973
|
+
following.current = next;
|
|
6974
|
+
setIsFollowing(next);
|
|
6975
|
+
if (next && unseen.current.size > 0) {
|
|
6976
|
+
unseen.current.clear();
|
|
6977
|
+
setNewCount(0);
|
|
6978
|
+
}
|
|
6979
|
+
}, []);
|
|
6980
|
+
const stick = useCallback10(() => {
|
|
6981
|
+
const scroller = scrollerRef.current;
|
|
6982
|
+
if (!scroller) return;
|
|
6983
|
+
scroller.scrollTop = scroller.scrollHeight;
|
|
6984
|
+
lastTop.current = scroller.scrollTop;
|
|
6985
|
+
}, []);
|
|
6986
|
+
const scrollToBottom = useCallback10(
|
|
6987
|
+
(options) => {
|
|
6988
|
+
const scroller = scrollerRef.current;
|
|
6989
|
+
if (!scroller) return;
|
|
6990
|
+
follow(true);
|
|
6991
|
+
scroller.scrollTo({ top: scroller.scrollHeight, behavior: options?.behavior ?? (prefersReducedMotion() ? "auto" : "smooth") });
|
|
6992
|
+
},
|
|
6993
|
+
[follow]
|
|
6994
|
+
);
|
|
6995
|
+
useImperativeHandle3(ref, () => ({ scrollToBottom }), [scrollToBottom]);
|
|
6996
|
+
useLayoutEffect8(stick, [stick]);
|
|
6997
|
+
useEffect27(() => {
|
|
6998
|
+
ready.current = true;
|
|
6999
|
+
}, []);
|
|
7000
|
+
useEffect27(() => {
|
|
7001
|
+
const scroller = scrollerRef.current;
|
|
7002
|
+
const content = contentRef.current;
|
|
7003
|
+
if (!scroller || !content || typeof ResizeObserver === "undefined") return void 0;
|
|
7004
|
+
const observer = new ResizeObserver(() => {
|
|
7005
|
+
if (following.current) stick();
|
|
7006
|
+
});
|
|
7007
|
+
observer.observe(content);
|
|
7008
|
+
observer.observe(scroller);
|
|
7009
|
+
return () => observer.disconnect();
|
|
7010
|
+
}, [stick]);
|
|
7011
|
+
function onScroll() {
|
|
7012
|
+
const scroller = scrollerRef.current;
|
|
7013
|
+
if (!scroller) return;
|
|
7014
|
+
const top = scroller.scrollTop;
|
|
7015
|
+
const distance = scroller.scrollHeight - top - scroller.clientHeight;
|
|
7016
|
+
if (top < lastTop.current && distance > 1) {
|
|
7017
|
+
if (following.current) follow(false);
|
|
7018
|
+
} else if (distance <= stickyDistance && !following.current) {
|
|
7019
|
+
follow(true);
|
|
7020
|
+
}
|
|
7021
|
+
lastTop.current = top;
|
|
7022
|
+
}
|
|
7023
|
+
const context = useMemo12(
|
|
7024
|
+
() => ({
|
|
7025
|
+
ready,
|
|
7026
|
+
register(id) {
|
|
7027
|
+
if (ready.current && !following.current) {
|
|
7028
|
+
unseen.current.add(id);
|
|
7029
|
+
setNewCount(unseen.current.size);
|
|
7030
|
+
}
|
|
7031
|
+
return () => {
|
|
7032
|
+
if (unseen.current.delete(id)) setNewCount(unseen.current.size);
|
|
7033
|
+
};
|
|
7034
|
+
}
|
|
7035
|
+
}),
|
|
7036
|
+
[]
|
|
7037
|
+
);
|
|
7038
|
+
const showJump = !isFollowing && !isEmpty;
|
|
7039
|
+
const jump = usePresence(showJump);
|
|
7040
|
+
return /* @__PURE__ */ jsxs50("div", { className: cx("ow-chat-conversation", width === "full" && "ow-chat-conversation--full", className), ...props, children: [
|
|
7041
|
+
/* @__PURE__ */ jsxs50("div", { className: "ow-chat-conversation__viewport", children: [
|
|
7042
|
+
/* @__PURE__ */ jsx66(
|
|
7043
|
+
"div",
|
|
7044
|
+
{
|
|
7045
|
+
ref: scrollerRef,
|
|
7046
|
+
className: "ow-chat-conversation__scroll",
|
|
7047
|
+
role: "log",
|
|
7048
|
+
"aria-live": "polite",
|
|
7049
|
+
"aria-relevant": "additions",
|
|
7050
|
+
"aria-label": ariaLabelledBy ? void 0 : ariaLabel,
|
|
7051
|
+
"aria-labelledby": ariaLabelledBy,
|
|
7052
|
+
tabIndex: isEmpty ? void 0 : 0,
|
|
7053
|
+
onScroll,
|
|
7054
|
+
children: /* @__PURE__ */ jsx66("div", { ref: contentRef, className: "ow-chat-conversation__content", children: /* @__PURE__ */ jsx66(ChatConversationContext.Provider, { value: context, children }) })
|
|
7055
|
+
}
|
|
7056
|
+
),
|
|
7057
|
+
isEmpty && empty ? /* @__PURE__ */ jsx66("div", { className: "ow-chat-conversation__empty", children: /* @__PURE__ */ jsx66("div", { className: "ow-chat-conversation__empty-inner", children: empty }) }) : null,
|
|
7058
|
+
jump.mounted ? /* @__PURE__ */ jsx66("div", { className: "ow-chat-conversation__jump", "data-state": jump.state, children: /* @__PURE__ */ jsxs50(
|
|
7059
|
+
Button,
|
|
7060
|
+
{
|
|
7061
|
+
ref: jumpRef,
|
|
7062
|
+
size: "sm",
|
|
7063
|
+
shape: "pill",
|
|
7064
|
+
startIcon: /* @__PURE__ */ jsx66(ArrowDownIcon, { size: 16 }),
|
|
7065
|
+
"aria-label": newCount > 0 ? `${jumpLabel}, ${formatNewCount(newCount)}` : jumpLabel,
|
|
7066
|
+
tabIndex: showJump ? void 0 : -1,
|
|
7067
|
+
onClick: () => {
|
|
7068
|
+
if (document.activeElement === jumpRef.current) scrollerRef.current?.focus({ preventScroll: true });
|
|
7069
|
+
scrollToBottom();
|
|
7070
|
+
},
|
|
7071
|
+
children: [
|
|
7072
|
+
jumpLabel,
|
|
7073
|
+
newCount > 0 ? /* @__PURE__ */ jsx66("span", { className: "ow-chat-conversation__count", children: formatNewCount(newCount) }) : null
|
|
7074
|
+
]
|
|
7075
|
+
}
|
|
7076
|
+
) }) : null
|
|
7077
|
+
] }),
|
|
7078
|
+
footer != null && footer !== false ? /* @__PURE__ */ jsx66("div", { className: "ow-chat-conversation__footer", children: /* @__PURE__ */ jsx66("div", { className: "ow-chat-conversation__footer-inner", children: footer }) }) : null
|
|
7079
|
+
] });
|
|
7080
|
+
});
|
|
7081
|
+
|
|
7082
|
+
// src/components/Chat/ChatMessage.tsx
|
|
7083
|
+
import {
|
|
7084
|
+
forwardRef as forwardRef27,
|
|
7085
|
+
useContext as useContext10,
|
|
7086
|
+
useEffect as useEffect28,
|
|
7087
|
+
useId as useId23,
|
|
7088
|
+
useLayoutEffect as useLayoutEffect9,
|
|
7089
|
+
useRef as useRef36,
|
|
7090
|
+
useState as useState31
|
|
7091
|
+
} from "react";
|
|
7092
|
+
import { Fragment as Fragment10, jsx as jsx67, jsxs as jsxs51 } from "react/jsx-runtime";
|
|
7093
|
+
function lucide(paths) {
|
|
7094
|
+
return function Icon({ size: size2 = 16, strokeWidth = 2, ...props }) {
|
|
7095
|
+
return /* @__PURE__ */ jsx67(
|
|
7096
|
+
"svg",
|
|
7097
|
+
{
|
|
7098
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
7099
|
+
width: size2,
|
|
7100
|
+
height: size2,
|
|
7101
|
+
viewBox: "0 0 24 24",
|
|
7102
|
+
fill: "none",
|
|
7103
|
+
stroke: "currentColor",
|
|
7104
|
+
strokeWidth,
|
|
7105
|
+
strokeLinecap: "round",
|
|
7106
|
+
strokeLinejoin: "round",
|
|
7107
|
+
"aria-hidden": "true",
|
|
7108
|
+
focusable: "false",
|
|
7109
|
+
...props,
|
|
7110
|
+
children: paths
|
|
7111
|
+
}
|
|
7112
|
+
);
|
|
7113
|
+
};
|
|
7114
|
+
}
|
|
7115
|
+
var BotIcon = lucide(
|
|
7116
|
+
/* @__PURE__ */ jsxs51(Fragment10, { children: [
|
|
7117
|
+
/* @__PURE__ */ jsx67("path", { d: "M12 8V4H8" }),
|
|
7118
|
+
/* @__PURE__ */ jsx67("rect", { width: "16", height: "12", x: "4", y: "8", rx: "2" }),
|
|
7119
|
+
/* @__PURE__ */ jsx67("path", { d: "M2 14h2" }),
|
|
7120
|
+
/* @__PURE__ */ jsx67("path", { d: "M20 14h2" }),
|
|
7121
|
+
/* @__PURE__ */ jsx67("path", { d: "M15 13v2" }),
|
|
7122
|
+
/* @__PURE__ */ jsx67("path", { d: "M9 13v2" })
|
|
7123
|
+
] })
|
|
7124
|
+
);
|
|
7125
|
+
var RotateCcwIcon = lucide(
|
|
7126
|
+
/* @__PURE__ */ jsxs51(Fragment10, { children: [
|
|
7127
|
+
/* @__PURE__ */ jsx67("path", { d: "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" }),
|
|
7128
|
+
/* @__PURE__ */ jsx67("path", { d: "M3 3v5h5" })
|
|
7129
|
+
] })
|
|
7130
|
+
);
|
|
7131
|
+
var ThumbsUpIcon = lucide(
|
|
7132
|
+
/* @__PURE__ */ jsxs51(Fragment10, { children: [
|
|
7133
|
+
/* @__PURE__ */ jsx67("path", { d: "M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2a3.13 3.13 0 0 1 3 3.88Z" }),
|
|
7134
|
+
/* @__PURE__ */ jsx67("path", { d: "M7 10v12" })
|
|
7135
|
+
] })
|
|
7136
|
+
);
|
|
7137
|
+
var ThumbsDownIcon = lucide(
|
|
7138
|
+
/* @__PURE__ */ jsxs51(Fragment10, { children: [
|
|
7139
|
+
/* @__PURE__ */ jsx67("path", { d: "M9 18.12 10 14H4.17a2 2 0 0 1-1.92-2.56l2.33-8A2 2 0 0 1 6.5 2H20a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2h-2.76a2 2 0 0 0-1.79 1.11L12 22a3.13 3.13 0 0 1-3-3.88Z" }),
|
|
7140
|
+
/* @__PURE__ */ jsx67("path", { d: "M17 14V2" })
|
|
7141
|
+
] })
|
|
7142
|
+
);
|
|
7143
|
+
var PencilIcon = lucide(
|
|
7144
|
+
/* @__PURE__ */ jsxs51(Fragment10, { children: [
|
|
7145
|
+
/* @__PURE__ */ jsx67("path", { d: "M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z" }),
|
|
7146
|
+
/* @__PURE__ */ jsx67("path", { d: "m15 5 4 4" })
|
|
7147
|
+
] })
|
|
7148
|
+
);
|
|
7149
|
+
var botSizes = { sm: 14, md: 16, lg: 18 };
|
|
7150
|
+
function ChatAgentAvatar({ size: size2 = "md", label, className }) {
|
|
7151
|
+
return /* @__PURE__ */ jsx67(
|
|
7152
|
+
"span",
|
|
7153
|
+
{
|
|
7154
|
+
className: cx("ow-chat-avatar", size2 !== "md" && `ow-chat-avatar--${size2}`, className),
|
|
7155
|
+
role: label ? "img" : void 0,
|
|
7156
|
+
"aria-label": label,
|
|
7157
|
+
"aria-hidden": label ? void 0 : true,
|
|
7158
|
+
children: /* @__PURE__ */ jsx67(BotIcon, { size: botSizes[size2] })
|
|
7159
|
+
}
|
|
7160
|
+
);
|
|
7161
|
+
}
|
|
7162
|
+
function useChatEntrance() {
|
|
7163
|
+
const conversation = useContext10(ChatConversationContext);
|
|
7164
|
+
const [entering] = useState31(() => conversation?.ready.current ?? false);
|
|
7165
|
+
return entering;
|
|
7166
|
+
}
|
|
7167
|
+
var formatters = /* @__PURE__ */ new Map();
|
|
7168
|
+
function formattersFor(locale) {
|
|
7169
|
+
const key = locale ?? "";
|
|
7170
|
+
let entry = formatters.get(key);
|
|
7171
|
+
if (!entry) {
|
|
7172
|
+
entry = {
|
|
7173
|
+
short: new Intl.DateTimeFormat(locale, { timeStyle: "short" }),
|
|
7174
|
+
full: new Intl.DateTimeFormat(locale, { dateStyle: "full", timeStyle: "short" })
|
|
7175
|
+
};
|
|
7176
|
+
formatters.set(key, entry);
|
|
7177
|
+
}
|
|
7178
|
+
return entry;
|
|
7179
|
+
}
|
|
7180
|
+
function MessageTime({ time, locale }) {
|
|
7181
|
+
const date = typeof time === "string" ? new Date(time) : time;
|
|
7182
|
+
if (Number.isNaN(date.getTime())) {
|
|
7183
|
+
return /* @__PURE__ */ jsx67("time", { className: "ow-chat-message__time", children: String(time) });
|
|
7184
|
+
}
|
|
7185
|
+
const { short, full } = formattersFor(locale);
|
|
7186
|
+
return /* @__PURE__ */ jsx67("time", { className: "ow-chat-message__time", dateTime: date.toISOString(), title: full.format(date), children: short.format(date) });
|
|
7187
|
+
}
|
|
7188
|
+
var skipCaret = '[aria-hidden="true"], .ow-visually-hidden';
|
|
7189
|
+
function useStreamingCaret(bodyRef, contentRef, caretRef, active) {
|
|
7190
|
+
useLayoutEffect9(() => {
|
|
7191
|
+
const body = bodyRef.current;
|
|
7192
|
+
const content = contentRef.current;
|
|
7193
|
+
const caret = caretRef.current;
|
|
7194
|
+
if (!active || !body || !content || !caret) return void 0;
|
|
7195
|
+
const place = () => {
|
|
7196
|
+
const walker = document.createTreeWalker(content, NodeFilter.SHOW_TEXT, {
|
|
7197
|
+
acceptNode: (node) => node.nodeValue?.trim() && !node.parentElement?.closest(skipCaret) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT
|
|
7198
|
+
});
|
|
7199
|
+
const last = walker.lastChild();
|
|
7200
|
+
const box = body.getBoundingClientRect();
|
|
7201
|
+
if (!last) {
|
|
7202
|
+
caret.style.transform = "";
|
|
7203
|
+
caret.style.removeProperty("height");
|
|
7204
|
+
caret.style.removeProperty("color");
|
|
7205
|
+
caret.hidden = false;
|
|
7206
|
+
return;
|
|
7207
|
+
}
|
|
7208
|
+
const end = last.data.trimEnd().length;
|
|
7209
|
+
const range = document.createRange();
|
|
7210
|
+
range.setStart(last, end - 1);
|
|
7211
|
+
range.setEnd(last, end);
|
|
7212
|
+
const rects = range.getClientRects();
|
|
7213
|
+
const rect = rects[rects.length - 1];
|
|
7214
|
+
if (!rect) {
|
|
7215
|
+
caret.hidden = true;
|
|
7216
|
+
return;
|
|
7217
|
+
}
|
|
7218
|
+
const x = Math.min(rect.right - box.left + 2, box.width - 2);
|
|
7219
|
+
caret.hidden = false;
|
|
7220
|
+
caret.style.transform = `translate(${Math.round(x)}px, ${Math.round(rect.top - box.top)}px)`;
|
|
7221
|
+
caret.style.height = `${Math.round(rect.height)}px`;
|
|
7222
|
+
caret.style.color = getComputedStyle(last.parentElement ?? content).color;
|
|
7223
|
+
};
|
|
7224
|
+
place();
|
|
7225
|
+
const mutations = new MutationObserver(place);
|
|
7226
|
+
mutations.observe(content, { subtree: true, childList: true, characterData: true });
|
|
7227
|
+
const resizes = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(place);
|
|
7228
|
+
resizes?.observe(body);
|
|
7229
|
+
return () => {
|
|
7230
|
+
mutations.disconnect();
|
|
7231
|
+
resizes?.disconnect();
|
|
7232
|
+
};
|
|
7233
|
+
}, [active, bodyRef, contentRef, caretRef]);
|
|
7234
|
+
}
|
|
7235
|
+
var ChatMessage = forwardRef27(function ChatMessage2({ from, children, name, avatar, time, locale, status = "done", error, onRetry, retryLabel = "Retry", actions, showActions = "hover", className, ...props }, ref) {
|
|
7236
|
+
const conversation = useContext10(ChatConversationContext);
|
|
7237
|
+
const entering = useChatEntrance();
|
|
7238
|
+
const id = useId23();
|
|
7239
|
+
const bodyRef = useRef36(null);
|
|
7240
|
+
const contentRef = useRef36(null);
|
|
7241
|
+
const caretRef = useRef36(null);
|
|
7242
|
+
const streaming = status === "streaming";
|
|
7243
|
+
useEffect28(() => conversation?.register(id), [conversation, id]);
|
|
7244
|
+
useStreamingCaret(bodyRef, contentRef, caretRef, streaming && from !== "system");
|
|
7245
|
+
if (from === "system") {
|
|
7246
|
+
return /* @__PURE__ */ jsx67(
|
|
7247
|
+
"div",
|
|
7248
|
+
{
|
|
7249
|
+
ref,
|
|
7250
|
+
className: cx("ow-chat-message", "ow-chat-message--system", entering && "ow-chat-message--enter", className),
|
|
7251
|
+
...props,
|
|
7252
|
+
children: /* @__PURE__ */ jsxs51("span", { className: "ow-chat-message__system-text", children: [
|
|
7253
|
+
children,
|
|
7254
|
+
time !== void 0 ? /* @__PURE__ */ jsxs51(Fragment10, { children: [
|
|
7255
|
+
/* @__PURE__ */ jsx67("span", { "aria-hidden": "true", children: " \xB7 " }),
|
|
7256
|
+
/* @__PURE__ */ jsx67(MessageTime, { time, locale })
|
|
7257
|
+
] }) : null
|
|
7258
|
+
] })
|
|
7259
|
+
}
|
|
7260
|
+
);
|
|
7261
|
+
}
|
|
7262
|
+
const isUser = from === "user";
|
|
7263
|
+
const avatarNode = avatar !== void 0 ? avatar : isUser ? null : /* @__PURE__ */ jsx67(ChatAgentAvatar, {});
|
|
7264
|
+
const hasHeader = name != null || time !== void 0;
|
|
7265
|
+
const errorText = error ?? (isUser ? "Couldn't send this message." : "The answer didn't finish.");
|
|
7266
|
+
return /* @__PURE__ */ jsxs51(
|
|
7267
|
+
"article",
|
|
7268
|
+
{
|
|
7269
|
+
ref,
|
|
7270
|
+
className: cx(
|
|
7271
|
+
"ow-chat-message",
|
|
7272
|
+
`ow-chat-message--${from}`,
|
|
7273
|
+
entering && "ow-chat-message--enter",
|
|
7274
|
+
streaming && "ow-chat-message--streaming",
|
|
7275
|
+
status === "error" && "ow-chat-message--error",
|
|
7276
|
+
showActions === "always" && "ow-chat-message--actions-always",
|
|
7277
|
+
className
|
|
7278
|
+
),
|
|
7279
|
+
"aria-busy": streaming || void 0,
|
|
7280
|
+
...props,
|
|
7281
|
+
children: [
|
|
7282
|
+
avatarNode != null && avatarNode !== false ? /* @__PURE__ */ jsx67("div", { className: "ow-chat-message__avatar", children: avatarNode }) : null,
|
|
7283
|
+
/* @__PURE__ */ jsxs51("div", { className: "ow-chat-message__main", children: [
|
|
7284
|
+
hasHeader ? /* @__PURE__ */ jsxs51("div", { className: "ow-chat-message__header", children: [
|
|
7285
|
+
name != null ? /* @__PURE__ */ jsx67("span", { className: "ow-chat-message__name", children: name }) : /* @__PURE__ */ jsx67("span", { className: "ow-visually-hidden", children: isUser ? "You" : "Agent" }),
|
|
7286
|
+
time !== void 0 ? /* @__PURE__ */ jsx67(MessageTime, { time, locale }) : null
|
|
7287
|
+
] }) : /* @__PURE__ */ jsx67("span", { className: "ow-visually-hidden", children: isUser ? "You" : "Agent" }),
|
|
7288
|
+
/* @__PURE__ */ jsxs51("div", { ref: bodyRef, className: "ow-chat-message__body", children: [
|
|
7289
|
+
/* @__PURE__ */ jsx67("div", { ref: contentRef, className: "ow-chat-message__content", children }),
|
|
7290
|
+
streaming ? /* @__PURE__ */ jsx67("span", { ref: caretRef, className: "ow-chat-message__caret", "aria-hidden": "true" }) : null
|
|
7291
|
+
] }),
|
|
7292
|
+
status === "error" ? /* @__PURE__ */ jsxs51("div", { className: cx("ow-chat-message__error", onRetry && "ow-chat-message__error--retry"), children: [
|
|
7293
|
+
/* @__PURE__ */ jsx67(CircleAlertIcon, { size: 16, className: "ow-chat-message__error-icon" }),
|
|
7294
|
+
/* @__PURE__ */ jsx67("span", { className: "ow-chat-message__error-text", children: errorText }),
|
|
7295
|
+
onRetry ? /* @__PURE__ */ jsx67(Button, { size: "sm", startIcon: /* @__PURE__ */ jsx67(RotateCcwIcon, { size: 16 }), onClick: onRetry, children: retryLabel }) : null
|
|
7296
|
+
] }) : null,
|
|
7297
|
+
actions && !streaming ? /* @__PURE__ */ jsx67("div", { className: "ow-chat-message__actions", children: actions }) : null
|
|
7298
|
+
] })
|
|
7299
|
+
]
|
|
7300
|
+
}
|
|
7301
|
+
);
|
|
7302
|
+
});
|
|
7303
|
+
var defaultLabels = { copy: "Copy", copied: "Copied", edit: "Edit", retry: "Retry", good: "Good response", bad: "Bad response" };
|
|
7304
|
+
function CopyAction({ text, label, copiedLabel }) {
|
|
7305
|
+
const [copied, setCopied] = useState31(false);
|
|
7306
|
+
const timer = useRef36(0);
|
|
7307
|
+
useEffect28(() => () => window.clearTimeout(timer.current), []);
|
|
7308
|
+
const current = copied ? copiedLabel : label;
|
|
7309
|
+
return /* @__PURE__ */ jsxs51(Fragment10, { children: [
|
|
7310
|
+
/* @__PURE__ */ jsx67(Tooltip, { label: current, children: /* @__PURE__ */ jsx67(
|
|
7311
|
+
Button,
|
|
7312
|
+
{
|
|
7313
|
+
variant: "ghost",
|
|
7314
|
+
size: "sm",
|
|
7315
|
+
iconOnly: true,
|
|
7316
|
+
"aria-label": current,
|
|
7317
|
+
className: cx("ow-chat-actions__copy", copied && "ow-chat-actions__copy--copied"),
|
|
7318
|
+
onClick: async () => {
|
|
7319
|
+
if (await copyText(text)) {
|
|
7320
|
+
setCopied(true);
|
|
7321
|
+
window.clearTimeout(timer.current);
|
|
7322
|
+
timer.current = window.setTimeout(() => setCopied(false), 2e3);
|
|
7323
|
+
}
|
|
7324
|
+
},
|
|
7325
|
+
children: /* @__PURE__ */ jsxs51("span", { className: "ow-chat-actions__copy-icon", children: [
|
|
7326
|
+
/* @__PURE__ */ jsx67(CopyIcon, { size: 16 }),
|
|
7327
|
+
/* @__PURE__ */ jsx67(CheckIcon, { size: 16 })
|
|
7328
|
+
] })
|
|
7329
|
+
}
|
|
7330
|
+
) }),
|
|
7331
|
+
/* @__PURE__ */ jsx67("span", { className: "ow-visually-hidden", "aria-live": "polite", children: copied ? copiedLabel : "" })
|
|
7332
|
+
] });
|
|
7333
|
+
}
|
|
7334
|
+
function ChatMessageActions({
|
|
7335
|
+
copyText: text,
|
|
7336
|
+
onEdit,
|
|
7337
|
+
onRetry,
|
|
7338
|
+
onRate,
|
|
7339
|
+
rating,
|
|
7340
|
+
defaultRating = null,
|
|
7341
|
+
children,
|
|
7342
|
+
labels,
|
|
7343
|
+
"aria-label": ariaLabel = "Message actions",
|
|
7344
|
+
className
|
|
7345
|
+
}) {
|
|
7346
|
+
const words = { ...defaultLabels, ...labels };
|
|
7347
|
+
const [current, setCurrent] = useControllableState(rating, defaultRating, onRate);
|
|
7348
|
+
const rate = (value, label, Icon) => {
|
|
7349
|
+
const pressed = current === value;
|
|
7350
|
+
return /* @__PURE__ */ jsx67(Tooltip, { label, children: /* @__PURE__ */ jsx67(
|
|
7351
|
+
ToggleButton,
|
|
7352
|
+
{
|
|
7353
|
+
variant: "ghost",
|
|
7354
|
+
size: "sm",
|
|
7355
|
+
iconOnly: true,
|
|
7356
|
+
"aria-label": label,
|
|
7357
|
+
pressed,
|
|
7358
|
+
className: "ow-chat-actions__rate",
|
|
7359
|
+
onPressedChange: () => setCurrent(pressed ? null : value),
|
|
7360
|
+
children: /* @__PURE__ */ jsx67(Icon, { size: 16 })
|
|
7361
|
+
}
|
|
7362
|
+
) });
|
|
7363
|
+
};
|
|
7364
|
+
return /* @__PURE__ */ jsxs51(Toolbar, { variant: "plain", size: "sm", "aria-label": ariaLabel, className: cx("ow-chat-actions", className), children: [
|
|
7365
|
+
text !== void 0 ? /* @__PURE__ */ jsx67(CopyAction, { text, label: words.copy, copiedLabel: words.copied }) : null,
|
|
7366
|
+
onEdit ? /* @__PURE__ */ jsx67(Tooltip, { label: words.edit, children: /* @__PURE__ */ jsx67(Button, { variant: "ghost", size: "sm", iconOnly: true, "aria-label": words.edit, onClick: onEdit, children: /* @__PURE__ */ jsx67(PencilIcon, { size: 16 }) }) }) : null,
|
|
7367
|
+
onRetry ? /* @__PURE__ */ jsx67(Tooltip, { label: words.retry, children: /* @__PURE__ */ jsx67(Button, { variant: "ghost", size: "sm", iconOnly: true, "aria-label": words.retry, onClick: onRetry, children: /* @__PURE__ */ jsx67(RotateCcwIcon, { size: 16 }) }) }) : null,
|
|
7368
|
+
onRate ? /* @__PURE__ */ jsxs51(Fragment10, { children: [
|
|
7369
|
+
rate("up", words.good, ThumbsUpIcon),
|
|
7370
|
+
rate("down", words.bad, ThumbsDownIcon)
|
|
7371
|
+
] }) : null,
|
|
7372
|
+
children
|
|
7373
|
+
] });
|
|
7374
|
+
}
|
|
7375
|
+
|
|
7376
|
+
// src/components/Chat/ChatLoader.tsx
|
|
7377
|
+
import { jsx as jsx68, jsxs as jsxs52 } from "react/jsx-runtime";
|
|
7378
|
+
function ChatLoader({ label, inline = false, name, avatar, srLabel = "Working\u2026", className }) {
|
|
7379
|
+
const entering = useChatEntrance();
|
|
7380
|
+
const indicator = label != null ? /* @__PURE__ */ jsx68(TextShimmer, { className: "ow-chat-loader__label", children: label }) : /* @__PURE__ */ jsxs52("span", { className: "ow-chat-loader__dots", children: [
|
|
7381
|
+
/* @__PURE__ */ jsx68("span", { className: "ow-chat-loader__dot", "aria-hidden": "true" }),
|
|
7382
|
+
/* @__PURE__ */ jsx68("span", { className: "ow-chat-loader__dot", "aria-hidden": "true" }),
|
|
7383
|
+
/* @__PURE__ */ jsx68("span", { className: "ow-chat-loader__dot", "aria-hidden": "true" }),
|
|
7384
|
+
/* @__PURE__ */ jsx68("span", { className: "ow-visually-hidden", children: srLabel })
|
|
7385
|
+
] });
|
|
7386
|
+
if (inline) {
|
|
7387
|
+
return /* @__PURE__ */ jsx68("span", { role: "status", className: cx("ow-chat-loader", "ow-chat-loader--inline", className), children: indicator });
|
|
7388
|
+
}
|
|
7389
|
+
const avatarNode = avatar === void 0 ? /* @__PURE__ */ jsx68(ChatAgentAvatar, {}) : avatar;
|
|
7390
|
+
return /* @__PURE__ */ jsxs52("div", { role: "status", className: cx("ow-chat-message", "ow-chat-message--assistant", "ow-chat-loader", entering && "ow-chat-loader--enter", className), children: [
|
|
7391
|
+
avatarNode != null && avatarNode !== false ? /* @__PURE__ */ jsx68("div", { className: "ow-chat-message__avatar", children: avatarNode }) : null,
|
|
7392
|
+
/* @__PURE__ */ jsxs52("div", { className: "ow-chat-message__main", children: [
|
|
7393
|
+
name != null ? /* @__PURE__ */ jsx68("div", { className: "ow-chat-message__header", children: /* @__PURE__ */ jsx68("span", { className: "ow-chat-message__name", children: name }) }) : null,
|
|
7394
|
+
/* @__PURE__ */ jsx68("div", { className: "ow-chat-loader__line", children: indicator })
|
|
7395
|
+
] })
|
|
7396
|
+
] });
|
|
7397
|
+
}
|
|
7398
|
+
|
|
7399
|
+
// src/components/ChatTool/ChatTool.tsx
|
|
7400
|
+
import { forwardRef as forwardRef28, useEffect as useEffect29, useId as useId24, useRef as useRef37, useState as useState32 } from "react";
|
|
7401
|
+
import { Fragment as Fragment11, jsx as jsx69, jsxs as jsxs53 } from "react/jsx-runtime";
|
|
7402
|
+
var statusWords = {
|
|
7403
|
+
pending: "Not started",
|
|
7404
|
+
running: "Running",
|
|
7405
|
+
success: "Done",
|
|
7406
|
+
error: "Failed",
|
|
7407
|
+
approval: "Needs approval",
|
|
7408
|
+
cancelled: "Cancelled"
|
|
7409
|
+
};
|
|
7410
|
+
function SlashIcon() {
|
|
7411
|
+
return /* @__PURE__ */ jsx69(
|
|
7412
|
+
"svg",
|
|
7413
|
+
{
|
|
7414
|
+
width: 12,
|
|
7415
|
+
height: 12,
|
|
7416
|
+
viewBox: "0 0 24 24",
|
|
7417
|
+
fill: "none",
|
|
7418
|
+
stroke: "currentColor",
|
|
7419
|
+
strokeWidth: 3,
|
|
7420
|
+
strokeLinecap: "round",
|
|
7421
|
+
"aria-hidden": "true",
|
|
7422
|
+
focusable: "false",
|
|
7423
|
+
children: /* @__PURE__ */ jsx69("path", { d: "M7 17 17 7" })
|
|
7424
|
+
}
|
|
7425
|
+
);
|
|
7426
|
+
}
|
|
7427
|
+
function ExclamationIcon() {
|
|
7428
|
+
return /* @__PURE__ */ jsxs53(
|
|
7429
|
+
"svg",
|
|
7430
|
+
{
|
|
7431
|
+
width: 12,
|
|
7432
|
+
height: 12,
|
|
7433
|
+
viewBox: "0 0 24 24",
|
|
7434
|
+
fill: "none",
|
|
7435
|
+
stroke: "currentColor",
|
|
7436
|
+
strokeWidth: 3,
|
|
7437
|
+
strokeLinecap: "round",
|
|
7438
|
+
"aria-hidden": "true",
|
|
7439
|
+
focusable: "false",
|
|
7440
|
+
children: [
|
|
7441
|
+
/* @__PURE__ */ jsx69("path", { d: "M12 5v9" }),
|
|
7442
|
+
/* @__PURE__ */ jsx69("path", { d: "M12 19h.01" })
|
|
7443
|
+
]
|
|
7444
|
+
}
|
|
7445
|
+
);
|
|
7446
|
+
}
|
|
7447
|
+
function ChatStatusMarker({ status, icon: icon2 }) {
|
|
7448
|
+
const showsIcon = Boolean(icon2) && (status === "success" || status === "pending");
|
|
7449
|
+
const glyph = status === "running" ? /* @__PURE__ */ jsx69(Spinner, { size: "sm", label: "" }) : status === "error" ? /* @__PURE__ */ jsx69(XIcon, { size: 12, strokeWidth: 3 }) : status === "approval" ? /* @__PURE__ */ jsx69(ExclamationIcon, {}) : status === "cancelled" ? /* @__PURE__ */ jsx69(SlashIcon, {}) : showsIcon ? icon2 : status === "success" ? /* @__PURE__ */ jsx69(CheckIcon, { size: 12, strokeWidth: 3 }) : null;
|
|
7450
|
+
return /* @__PURE__ */ jsxs53("span", { className: cx("ow-chat-status", `ow-chat-status--${status}`, showsIcon && "ow-chat-status--icon"), children: [
|
|
7451
|
+
/* @__PURE__ */ jsx69("span", { className: "ow-chat-status__glyph", "aria-hidden": "true", children: glyph }),
|
|
7452
|
+
/* @__PURE__ */ jsxs53("span", { className: "ow-visually-hidden", children: [
|
|
7453
|
+
statusWords[status],
|
|
7454
|
+
": "
|
|
7455
|
+
] })
|
|
7456
|
+
] });
|
|
7457
|
+
}
|
|
7458
|
+
function formatDuration(ms, locale) {
|
|
7459
|
+
const number = (value, digits = 0) => new Intl.NumberFormat(locale, { maximumFractionDigits: digits }).format(value);
|
|
7460
|
+
const safe = Math.max(0, ms);
|
|
7461
|
+
if (safe < 1e3) return `${number(Math.round(safe))} ms`;
|
|
7462
|
+
const seconds = safe / 1e3;
|
|
7463
|
+
if (seconds < 10) return `${number(Math.floor(seconds * 10) / 10, 1)} s`;
|
|
7464
|
+
if (seconds < 60) return `${number(Math.floor(seconds))} s`;
|
|
7465
|
+
const minutes = Math.floor(seconds / 60);
|
|
7466
|
+
if (minutes < 60) {
|
|
7467
|
+
const rest2 = Math.floor(seconds % 60);
|
|
7468
|
+
return rest2 ? `${number(minutes)} min ${number(rest2)} s` : `${number(minutes)} min`;
|
|
7469
|
+
}
|
|
7470
|
+
const hours = Math.floor(minutes / 60);
|
|
7471
|
+
const rest = minutes % 60;
|
|
7472
|
+
return rest ? `${number(hours)} h ${number(rest)} min` : `${number(hours)} h`;
|
|
7473
|
+
}
|
|
7474
|
+
function ChatDuration({ ms, locale, className }) {
|
|
7475
|
+
return /* @__PURE__ */ jsx69("time", { dateTime: `PT${Math.max(0, Math.round(ms)) / 1e3}S`, className, children: formatDuration(ms, locale) });
|
|
7476
|
+
}
|
|
7477
|
+
function useStatusExpansion({
|
|
7478
|
+
expanded,
|
|
7479
|
+
defaultExpanded,
|
|
7480
|
+
onExpandedChange,
|
|
7481
|
+
wantsOpen,
|
|
7482
|
+
closeWhenSettled = true,
|
|
7483
|
+
initial = wantsOpen
|
|
7484
|
+
}) {
|
|
7485
|
+
const [isOpen, setOpen] = useControllableState(expanded, defaultExpanded ?? initial, onExpandedChange);
|
|
7486
|
+
const touched = useRef37(false);
|
|
7487
|
+
const previous = useRef37(wantsOpen);
|
|
7488
|
+
useEffect29(() => {
|
|
7489
|
+
if (previous.current === wantsOpen) return;
|
|
7490
|
+
previous.current = wantsOpen;
|
|
7491
|
+
if (expanded !== void 0) return;
|
|
7492
|
+
if (wantsOpen) {
|
|
7493
|
+
touched.current = false;
|
|
7494
|
+
setOpen(true);
|
|
7495
|
+
} else if (closeWhenSettled && !touched.current) {
|
|
7496
|
+
setOpen(false);
|
|
7497
|
+
}
|
|
7498
|
+
}, [wantsOpen]);
|
|
7499
|
+
return [
|
|
7500
|
+
isOpen,
|
|
7501
|
+
() => {
|
|
7502
|
+
touched.current = true;
|
|
7503
|
+
setOpen(!isOpen);
|
|
7504
|
+
}
|
|
7505
|
+
];
|
|
7506
|
+
}
|
|
7507
|
+
function ChatCollapse({
|
|
7508
|
+
id,
|
|
7509
|
+
open,
|
|
7510
|
+
bleed = false,
|
|
7511
|
+
className,
|
|
7512
|
+
children
|
|
7513
|
+
}) {
|
|
7514
|
+
const ref = useRef37(null);
|
|
7515
|
+
useEffect29(() => {
|
|
7516
|
+
if (ref.current) ref.current.inert = !open;
|
|
7517
|
+
}, [open]);
|
|
7518
|
+
return /* @__PURE__ */ jsx69("div", { ref, id, className: cx("ow-chat-collapse", bleed && "ow-chat-collapse--bleed"), "data-open": open, children: /* @__PURE__ */ jsx69("div", { className: "ow-chat-collapse__clip", children: /* @__PURE__ */ jsx69("div", { className, children }) }) });
|
|
7519
|
+
}
|
|
7520
|
+
var codeMaxHeight = 280;
|
|
7521
|
+
function formatInput(input) {
|
|
7522
|
+
if (typeof input === "string") return input;
|
|
7523
|
+
try {
|
|
7524
|
+
return JSON.stringify(input, null, 2);
|
|
7525
|
+
} catch {
|
|
7526
|
+
return String(input);
|
|
7527
|
+
}
|
|
7528
|
+
}
|
|
7529
|
+
var ChatTool = forwardRef28(function ChatTool2({
|
|
7530
|
+
title,
|
|
7531
|
+
name,
|
|
7532
|
+
icon: icon2,
|
|
7533
|
+
status,
|
|
7534
|
+
summary,
|
|
7535
|
+
duration,
|
|
7536
|
+
input,
|
|
7537
|
+
output,
|
|
7538
|
+
error,
|
|
7539
|
+
expanded,
|
|
7540
|
+
defaultExpanded,
|
|
7541
|
+
onExpandedChange,
|
|
7542
|
+
approvalMessage,
|
|
7543
|
+
approveLabel = "Approve",
|
|
7544
|
+
denyLabel = "Deny",
|
|
7545
|
+
onApprove,
|
|
7546
|
+
onDeny,
|
|
7547
|
+
locale,
|
|
7548
|
+
className,
|
|
7549
|
+
...props
|
|
7550
|
+
}, ref) {
|
|
7551
|
+
const id = useId24();
|
|
7552
|
+
const rootRef = useRef37(null);
|
|
7553
|
+
const triggerRef = useRef37(null);
|
|
7554
|
+
const messageRef = useRef37(null);
|
|
7555
|
+
const decided = useRef37(false);
|
|
7556
|
+
const [announcement, setAnnouncement] = useState32("");
|
|
7557
|
+
const needsApproval = status === "approval";
|
|
7558
|
+
const [isOpen, toggle] = useStatusExpansion({
|
|
7559
|
+
expanded,
|
|
7560
|
+
defaultExpanded,
|
|
7561
|
+
onExpandedChange,
|
|
7562
|
+
wantsOpen: status === "error" || needsApproval
|
|
7563
|
+
});
|
|
7564
|
+
const hasInput = input !== void 0 && input !== null && input !== "";
|
|
7565
|
+
const hasOutput = output !== void 0 && output !== null && output !== false && output !== "";
|
|
7566
|
+
const hasError = error !== void 0 && error !== null && error !== false && error !== "";
|
|
7567
|
+
const hasDetails = hasInput || hasOutput || hasError;
|
|
7568
|
+
const hasMeta = Boolean(summary) || duration !== void 0;
|
|
7569
|
+
useEffect29(() => {
|
|
7570
|
+
if (!needsApproval) {
|
|
7571
|
+
setAnnouncement("");
|
|
7572
|
+
return;
|
|
7573
|
+
}
|
|
7574
|
+
const timer = window.setTimeout(() => {
|
|
7575
|
+
const request = messageRef.current?.textContent?.trim();
|
|
7576
|
+
setAnnouncement(`Needs approval. ${request ?? ""}`.trim());
|
|
7577
|
+
}, 150);
|
|
7578
|
+
return () => window.clearTimeout(timer);
|
|
7579
|
+
}, [needsApproval]);
|
|
7580
|
+
useEffect29(() => {
|
|
7581
|
+
if (needsApproval || !decided.current) return;
|
|
7582
|
+
decided.current = false;
|
|
7583
|
+
const active = document.activeElement;
|
|
7584
|
+
if (!active || active === document.body) (triggerRef.current ?? rootRef.current)?.focus();
|
|
7585
|
+
}, [needsApproval]);
|
|
7586
|
+
const running = status === "running";
|
|
7587
|
+
const header = /* @__PURE__ */ jsxs53(Fragment11, { children: [
|
|
7588
|
+
/* @__PURE__ */ jsx69(ChatStatusMarker, { status }),
|
|
7589
|
+
icon2 ? /* @__PURE__ */ jsx69("span", { className: "ow-chat-tool__icon", "aria-hidden": "true", children: icon2 }) : null,
|
|
7590
|
+
/* @__PURE__ */ jsxs53("span", { className: "ow-chat-tool__main", children: [
|
|
7591
|
+
/* @__PURE__ */ jsxs53("span", { className: "ow-chat-tool__heading", children: [
|
|
7592
|
+
/* @__PURE__ */ jsx69("span", { className: "ow-chat-tool__title", children: running ? /* @__PURE__ */ jsx69(TextShimmer, { children: title }) : title }),
|
|
7593
|
+
name ? /* @__PURE__ */ jsx69(Code, { className: "ow-chat-tool__name", children: name }) : null
|
|
7594
|
+
] }),
|
|
7595
|
+
hasMeta ? /* @__PURE__ */ jsxs53("span", { className: "ow-chat-tool__meta", children: [
|
|
7596
|
+
summary ? /* @__PURE__ */ jsx69("span", { className: "ow-chat-tool__summary", children: summary }) : null,
|
|
7597
|
+
summary && duration !== void 0 ? /* @__PURE__ */ jsx69("span", { className: "ow-chat-tool__dot", "aria-hidden": "true", children: "\xB7" }) : null,
|
|
7598
|
+
duration !== void 0 ? /* @__PURE__ */ jsx69(ChatDuration, { ms: duration, locale, className: "ow-chat-tool__duration" }) : null
|
|
7599
|
+
] }) : null
|
|
7600
|
+
] }),
|
|
7601
|
+
hasDetails ? /* @__PURE__ */ jsx69("span", { className: "ow-chat-tool__chevron", "aria-hidden": "true", children: /* @__PURE__ */ jsx69(ChevronRightIcon, { size: 14 }) }) : null
|
|
7602
|
+
] });
|
|
7603
|
+
return /* @__PURE__ */ jsxs53(
|
|
7604
|
+
"div",
|
|
7605
|
+
{
|
|
7606
|
+
ref: (element) => {
|
|
7607
|
+
rootRef.current = element;
|
|
7608
|
+
if (typeof ref === "function") ref(element);
|
|
7609
|
+
else if (ref) ref.current = element;
|
|
7610
|
+
},
|
|
7611
|
+
className: cx("ow-chat-tool", className),
|
|
7612
|
+
"data-status": status,
|
|
7613
|
+
"data-open": hasDetails ? isOpen : void 0,
|
|
7614
|
+
"aria-busy": running || void 0,
|
|
7615
|
+
tabIndex: hasDetails ? void 0 : -1,
|
|
7616
|
+
...props,
|
|
7617
|
+
children: [
|
|
7618
|
+
hasDetails ? /* @__PURE__ */ jsx69(
|
|
7619
|
+
"button",
|
|
7620
|
+
{
|
|
7621
|
+
ref: triggerRef,
|
|
7622
|
+
type: "button",
|
|
7623
|
+
id: `${id}-trigger`,
|
|
7624
|
+
className: "ow-chat-tool__header ow-chat-tool__header--button",
|
|
7625
|
+
"aria-expanded": isOpen,
|
|
7626
|
+
"aria-controls": `${id}-details`,
|
|
7627
|
+
onClick: toggle,
|
|
7628
|
+
children: header
|
|
7629
|
+
}
|
|
7630
|
+
) : /* @__PURE__ */ jsx69("div", { className: "ow-chat-tool__header", children: header }),
|
|
7631
|
+
hasDetails ? /* @__PURE__ */ jsxs53(ChatCollapse, { id: `${id}-details`, open: isOpen, className: "ow-chat-tool__details", children: [
|
|
7632
|
+
hasInput ? /* @__PURE__ */ jsxs53("div", { className: "ow-chat-tool__section", children: [
|
|
7633
|
+
/* @__PURE__ */ jsx69("span", { className: "ow-chat-tool__label", children: "Input" }),
|
|
7634
|
+
typeof input === "string" && !input.includes("\n") ? /* @__PURE__ */ jsx69(Snippet, { value: input, prompt: null }) : /* @__PURE__ */ jsx69(CodeBlock, { code: formatInput(input), language: typeof input === "string" ? void 0 : "json", maxHeight: codeMaxHeight })
|
|
7635
|
+
] }) : null,
|
|
7636
|
+
hasOutput ? /* @__PURE__ */ jsxs53("div", { className: "ow-chat-tool__section", children: [
|
|
7637
|
+
/* @__PURE__ */ jsx69("span", { className: "ow-chat-tool__label", children: "Output" }),
|
|
7638
|
+
typeof output === "string" ? /* @__PURE__ */ jsx69(CodeBlock, { code: output, maxHeight: codeMaxHeight }) : /* @__PURE__ */ jsx69("div", { className: "ow-chat-tool__output", children: output })
|
|
7639
|
+
] }) : null,
|
|
7640
|
+
hasError ? /* @__PURE__ */ jsxs53("div", { className: "ow-chat-tool__section", children: [
|
|
7641
|
+
/* @__PURE__ */ jsx69("span", { className: "ow-chat-tool__label", children: "Error" }),
|
|
7642
|
+
/* @__PURE__ */ jsx69("div", { className: "ow-chat-tool__error", children: error })
|
|
7643
|
+
] }) : null
|
|
7644
|
+
] }) : null,
|
|
7645
|
+
needsApproval ? /* @__PURE__ */ jsxs53("div", { className: "ow-chat-tool__approval", role: "group", "aria-labelledby": `${id}-request`, children: [
|
|
7646
|
+
/* @__PURE__ */ jsx69("p", { ref: messageRef, id: `${id}-request`, className: "ow-chat-tool__request", children: approvalMessage ?? (name ? /* @__PURE__ */ jsxs53(Fragment11, { children: [
|
|
7647
|
+
"Wants to run ",
|
|
7648
|
+
/* @__PURE__ */ jsx69(Code, { children: name })
|
|
7649
|
+
] }) : "Wants to go ahead") }),
|
|
7650
|
+
/* @__PURE__ */ jsxs53("div", { className: "ow-chat-tool__actions", children: [
|
|
7651
|
+
/* @__PURE__ */ jsx69(
|
|
7652
|
+
Button,
|
|
7653
|
+
{
|
|
7654
|
+
variant: "primary",
|
|
7655
|
+
size: "sm",
|
|
7656
|
+
onClick: () => {
|
|
7657
|
+
decided.current = true;
|
|
7658
|
+
onApprove?.();
|
|
7659
|
+
},
|
|
7660
|
+
children: approveLabel
|
|
7661
|
+
}
|
|
7662
|
+
),
|
|
7663
|
+
/* @__PURE__ */ jsx69(
|
|
7664
|
+
Button,
|
|
7665
|
+
{
|
|
7666
|
+
size: "sm",
|
|
7667
|
+
onClick: () => {
|
|
7668
|
+
decided.current = true;
|
|
7669
|
+
onDeny?.();
|
|
7670
|
+
},
|
|
7671
|
+
children: denyLabel
|
|
7672
|
+
}
|
|
7673
|
+
)
|
|
7674
|
+
] })
|
|
7675
|
+
] }) : null,
|
|
7676
|
+
/* @__PURE__ */ jsx69("span", { className: "ow-visually-hidden", "aria-live": "polite", children: announcement })
|
|
7677
|
+
]
|
|
7678
|
+
}
|
|
7679
|
+
);
|
|
7680
|
+
});
|
|
7681
|
+
|
|
7682
|
+
// src/components/ChainOfThought/ChainOfThought.tsx
|
|
7683
|
+
import { forwardRef as forwardRef29, useId as useId25 } from "react";
|
|
7684
|
+
import { jsx as jsx70, jsxs as jsxs54 } from "react/jsx-runtime";
|
|
7685
|
+
var plural = (count, word) => `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
7686
|
+
var ChainOfThought = forwardRef29(function ChainOfThought2({
|
|
7687
|
+
steps = [],
|
|
7688
|
+
status = "success",
|
|
7689
|
+
duration,
|
|
7690
|
+
label,
|
|
7691
|
+
children,
|
|
7692
|
+
expanded,
|
|
7693
|
+
defaultExpanded,
|
|
7694
|
+
onExpandedChange,
|
|
7695
|
+
collapseWhenDone = true,
|
|
7696
|
+
locale,
|
|
7697
|
+
className,
|
|
7698
|
+
...props
|
|
7699
|
+
}, ref) {
|
|
7700
|
+
const id = useId25();
|
|
7701
|
+
const running = status === "running";
|
|
7702
|
+
const [isOpen, toggle] = useStatusExpansion({
|
|
7703
|
+
expanded,
|
|
7704
|
+
defaultExpanded,
|
|
7705
|
+
onExpandedChange,
|
|
7706
|
+
wantsOpen: running,
|
|
7707
|
+
closeWhenSettled: collapseWhenDone,
|
|
7708
|
+
initial: running || !collapseWhenDone
|
|
7709
|
+
});
|
|
7710
|
+
const hasReasoning = children !== void 0 && children !== null && children !== false && children !== "";
|
|
7711
|
+
const hasBody = hasReasoning || steps.length > 0;
|
|
7712
|
+
const finished = steps.filter((step) => step.status === "success" || step.status === "error").length;
|
|
7713
|
+
const failed = steps.filter((step) => step.status === "error").length;
|
|
7714
|
+
const heading = label ?? (running ? "Thinking\u2026" : duration !== void 0 ? `Thought for ${formatDuration(duration, locale)}` : "Reasoning");
|
|
7715
|
+
const count = steps.length > 0 ? running ? `${finished} of ${plural(steps.length, "step")}` : plural(steps.length, "step") : null;
|
|
7716
|
+
const headerText = /* @__PURE__ */ jsxs54("span", { className: "ow-chat-toggle__text", children: [
|
|
7717
|
+
/* @__PURE__ */ jsx70("span", { className: "ow-chain-of-thought__label", children: running ? /* @__PURE__ */ jsx70(TextShimmer, { children: heading }) : heading }),
|
|
7718
|
+
count ? /* @__PURE__ */ jsxs54("span", { className: "ow-chat-toggle__meta", children: [
|
|
7719
|
+
/* @__PURE__ */ jsx70("span", { "aria-hidden": "true", children: "\xB7 " }),
|
|
7720
|
+
count,
|
|
7721
|
+
failed > 0 ? /* @__PURE__ */ jsxs54("span", { className: "ow-chain-of-thought__failed", children: [
|
|
7722
|
+
", ",
|
|
7723
|
+
failed,
|
|
7724
|
+
" failed"
|
|
7725
|
+
] }) : null
|
|
7726
|
+
] }) : null
|
|
7727
|
+
] });
|
|
7728
|
+
return /* @__PURE__ */ jsxs54("div", { ref, className: cx("ow-chain-of-thought", className), "data-status": status, "aria-busy": running || void 0, ...props, children: [
|
|
7729
|
+
hasBody ? /* @__PURE__ */ jsxs54("button", { type: "button", className: "ow-chat-toggle", "aria-expanded": isOpen, "aria-controls": `${id}-body`, onClick: toggle, children: [
|
|
7730
|
+
/* @__PURE__ */ jsx70("span", { className: "ow-chat-toggle__chevron", "aria-hidden": "true", children: /* @__PURE__ */ jsx70(ChevronRightIcon, { size: 14 }) }),
|
|
7731
|
+
headerText
|
|
7732
|
+
] }) : /* @__PURE__ */ jsx70("div", { className: "ow-chat-toggle ow-chain-of-thought__static", children: headerText }),
|
|
7733
|
+
hasBody ? /* @__PURE__ */ jsxs54(ChatCollapse, { id: `${id}-body`, open: isOpen, bleed: true, className: "ow-chain-of-thought__body", children: [
|
|
7734
|
+
hasReasoning ? /* @__PURE__ */ jsx70("div", { className: "ow-chain-of-thought__reasoning", children }) : null,
|
|
7735
|
+
steps.length > 0 ? /* @__PURE__ */ jsx70("ol", { className: "ow-chain-of-thought__steps", children: steps.map((step) => /* @__PURE__ */ jsxs54("li", { className: "ow-chain-of-thought__step", "data-status": step.status, children: [
|
|
7736
|
+
/* @__PURE__ */ jsx70(ChatStatusMarker, { status: step.status, icon: step.icon }),
|
|
7737
|
+
/* @__PURE__ */ jsxs54("div", { className: "ow-chain-of-thought__step-body", children: [
|
|
7738
|
+
/* @__PURE__ */ jsx70("span", { className: "ow-chain-of-thought__step-title", children: step.status === "running" ? /* @__PURE__ */ jsx70(TextShimmer, { children: step.title }) : step.title }),
|
|
7739
|
+
step.detail !== void 0 && step.detail !== null ? /* @__PURE__ */ jsx70("div", { className: "ow-chain-of-thought__detail", children: step.detail }) : null
|
|
7740
|
+
] })
|
|
7741
|
+
] }, step.id)) }) : null
|
|
7742
|
+
] }) : null
|
|
7743
|
+
] });
|
|
7744
|
+
});
|
|
7745
|
+
|
|
7746
|
+
// src/components/ChatSource/ChatSource.tsx
|
|
7747
|
+
import { forwardRef as forwardRef30, useCallback as useCallback11, useEffect as useEffect30, useId as useId26, useRef as useRef38, useState as useState33 } from "react";
|
|
7748
|
+
import { Fragment as Fragment12, jsx as jsx71, jsxs as jsxs55 } from "react/jsx-runtime";
|
|
7749
|
+
var openDelay = 250;
|
|
7750
|
+
var closeDelay = 150;
|
|
7751
|
+
var ChatSource = forwardRef30(function ChatSource2({
|
|
7752
|
+
title,
|
|
7753
|
+
source,
|
|
7754
|
+
snippet,
|
|
7755
|
+
href,
|
|
7756
|
+
external = false,
|
|
7757
|
+
icon: icon2,
|
|
7758
|
+
index,
|
|
7759
|
+
label,
|
|
7760
|
+
snippetFormat = "text",
|
|
7761
|
+
openLabel = "Open",
|
|
7762
|
+
onClick,
|
|
7763
|
+
"aria-label": ariaLabel,
|
|
7764
|
+
className
|
|
7765
|
+
}, ref) {
|
|
7766
|
+
const id = useId26();
|
|
7767
|
+
const wrapperRef = useRef38(null);
|
|
7768
|
+
const chipRef = useRef38(null);
|
|
7769
|
+
const cardRef = useRef38(null);
|
|
7770
|
+
const timer = useRef38(0);
|
|
7771
|
+
const pointer = useRef38("mouse");
|
|
7772
|
+
const [open, setOpen] = useState33(false);
|
|
7773
|
+
const { mounted, state } = usePresence(open);
|
|
7774
|
+
const style = useFloating({ open: mounted, anchorRef: chipRef, floatingRef: cardRef, placement: "bottom-start", offset: 6, maxHeight: 360 });
|
|
7775
|
+
const schedule = (next, delay) => {
|
|
7776
|
+
window.clearTimeout(timer.current);
|
|
7777
|
+
if (delay === 0) setOpen(next);
|
|
7778
|
+
else timer.current = window.setTimeout(() => setOpen(next), delay);
|
|
7779
|
+
};
|
|
7780
|
+
const close = useCallback11(() => {
|
|
7781
|
+
window.clearTimeout(timer.current);
|
|
7782
|
+
setOpen(false);
|
|
7783
|
+
}, []);
|
|
7784
|
+
useDismiss(open, [wrapperRef], close);
|
|
7785
|
+
useEffect30(() => () => window.clearTimeout(timer.current), []);
|
|
7786
|
+
const name = ariaLabel ?? (index !== void 0 ? `Source ${index}` : label ?? "Source");
|
|
7787
|
+
const describedBy = [`${id}-title`, source ? `${id}-source` : null, snippet ? `${id}-snippet` : null].filter(Boolean).join(" ");
|
|
7788
|
+
const externalProps = external ? { target: "_blank", rel: "noopener noreferrer" } : {};
|
|
7789
|
+
const chipProps = {
|
|
7790
|
+
ref: (element) => {
|
|
7791
|
+
chipRef.current = element;
|
|
7792
|
+
if (typeof ref === "function") ref(element);
|
|
7793
|
+
else if (ref) ref.current = element;
|
|
7794
|
+
},
|
|
7795
|
+
className: cx("ow-chat-source__chip", index === void 0 && "ow-chat-source__chip--label", open && "ow-chat-source__chip--open"),
|
|
7796
|
+
"aria-label": name,
|
|
7797
|
+
"aria-describedby": describedBy,
|
|
7798
|
+
onFocus: (event) => {
|
|
7799
|
+
if (event.currentTarget.matches(":focus-visible")) schedule(true, 0);
|
|
7800
|
+
},
|
|
7801
|
+
onBlur: () => schedule(false, 0),
|
|
7802
|
+
onPointerDown: (event) => {
|
|
7803
|
+
pointer.current = event.pointerType;
|
|
7804
|
+
},
|
|
7805
|
+
onClick: (event) => {
|
|
7806
|
+
const tapped = event.detail > 0 && pointer.current !== "mouse";
|
|
7807
|
+
pointer.current = "mouse";
|
|
7808
|
+
if (tapped && !open) {
|
|
7809
|
+
event.preventDefault();
|
|
7810
|
+
schedule(true, 0);
|
|
7811
|
+
return;
|
|
7812
|
+
}
|
|
7813
|
+
if (!href) schedule(true, 0);
|
|
7814
|
+
onClick?.(event);
|
|
7815
|
+
}
|
|
7816
|
+
};
|
|
7817
|
+
const chipText = /* @__PURE__ */ jsx71("span", { className: "ow-chat-source__chip-text", children: index ?? label });
|
|
7818
|
+
return /* @__PURE__ */ jsxs55(
|
|
7819
|
+
"span",
|
|
7820
|
+
{
|
|
7821
|
+
ref: wrapperRef,
|
|
7822
|
+
className: cx("ow-chat-source", className),
|
|
7823
|
+
onPointerEnter: (event) => {
|
|
7824
|
+
if (event.pointerType === "mouse") schedule(true, open ? 0 : openDelay);
|
|
7825
|
+
},
|
|
7826
|
+
onPointerLeave: (event) => {
|
|
7827
|
+
if (event.pointerType === "mouse") schedule(false, closeDelay);
|
|
7828
|
+
},
|
|
7829
|
+
children: [
|
|
7830
|
+
href ? /* @__PURE__ */ jsx71("a", { href, ...externalProps, ...chipProps, children: chipText }) : /* @__PURE__ */ jsx71("button", { type: "button", ...chipProps, children: chipText }),
|
|
7831
|
+
/* @__PURE__ */ jsxs55("span", { ref: cardRef, ...manualPopover, hidden: !mounted, "data-state": state, className: "ow-chat-source-card ow-floating", style, children: [
|
|
7832
|
+
/* @__PURE__ */ jsxs55("span", { className: "ow-chat-source-card__header", children: [
|
|
7833
|
+
icon2 ? /* @__PURE__ */ jsx71("span", { className: "ow-chat-source-card__icon", "aria-hidden": "true", children: icon2 }) : null,
|
|
7834
|
+
/* @__PURE__ */ jsx71("span", { id: `${id}-title`, className: "ow-chat-source-card__title", children: title })
|
|
7835
|
+
] }),
|
|
7836
|
+
source ? /* @__PURE__ */ jsx71("span", { id: `${id}-source`, className: "ow-chat-source-card__source", children: source }) : null,
|
|
7837
|
+
snippet ? /* @__PURE__ */ jsx71("span", { id: `${id}-snippet`, className: cx("ow-chat-source-card__snippet", `ow-chat-source-card__snippet--${snippetFormat}`), children: snippet }) : null,
|
|
7838
|
+
href ? (
|
|
7839
|
+
// The chip is the same link, so this one stays out of the tab order.
|
|
7840
|
+
/* @__PURE__ */ jsxs55("a", { href, ...externalProps, tabIndex: -1, className: cx(linkClassName({ variant: "standalone" }), "ow-chat-source-card__open"), children: [
|
|
7841
|
+
openLabel,
|
|
7842
|
+
/* @__PURE__ */ jsx71(ArrowUpRightIcon, { size: 13 })
|
|
7843
|
+
] })
|
|
7844
|
+
) : null
|
|
7845
|
+
] })
|
|
7846
|
+
]
|
|
7847
|
+
}
|
|
7848
|
+
);
|
|
7849
|
+
});
|
|
7850
|
+
var ChatSources = forwardRef30(function ChatSources2({ sources, label, expanded, defaultExpanded = false, onExpandedChange, className, ...props }, ref) {
|
|
7851
|
+
const id = useId26();
|
|
7852
|
+
const [isOpen, setOpen] = useControllableState(expanded, defaultExpanded, onExpandedChange);
|
|
7853
|
+
if (sources.length === 0) return null;
|
|
7854
|
+
return /* @__PURE__ */ jsxs55("div", { ref, className: cx("ow-chat-sources", className), ...props, children: [
|
|
7855
|
+
/* @__PURE__ */ jsxs55("button", { type: "button", className: "ow-chat-toggle", "aria-expanded": isOpen, "aria-controls": `${id}-list`, onClick: () => setOpen(!isOpen), children: [
|
|
7856
|
+
/* @__PURE__ */ jsx71("span", { className: "ow-chat-toggle__chevron", "aria-hidden": "true", children: /* @__PURE__ */ jsx71(ChevronRightIcon, { size: 14 }) }),
|
|
7857
|
+
/* @__PURE__ */ jsx71("span", { className: "ow-chat-toggle__text", children: label ?? `${sources.length} ${sources.length === 1 ? "source" : "sources"}` })
|
|
7858
|
+
] }),
|
|
7859
|
+
/* @__PURE__ */ jsx71(ChatCollapse, { id: `${id}-list`, open: isOpen, bleed: true, className: "ow-chat-sources__body", children: /* @__PURE__ */ jsx71("ul", { className: "ow-chat-sources__list", children: sources.map((item, position) => {
|
|
7860
|
+
const content = /* @__PURE__ */ jsxs55(Fragment12, { children: [
|
|
7861
|
+
/* @__PURE__ */ jsxs55("span", { className: "ow-chat-sources__lead", children: [
|
|
7862
|
+
item.index !== void 0 ? /* @__PURE__ */ jsxs55("span", { className: "ow-chat-sources__index", children: [
|
|
7863
|
+
/* @__PURE__ */ jsx71("span", { className: "ow-visually-hidden", children: "Source " }),
|
|
7864
|
+
item.index
|
|
7865
|
+
] }) : null,
|
|
7866
|
+
item.icon || item.index === void 0 ? /* @__PURE__ */ jsx71("span", { className: "ow-chat-sources__icon", "aria-hidden": "true", children: item.icon ?? /* @__PURE__ */ jsx71(FileIcon, { size: 15 }) }) : null
|
|
7867
|
+
] }),
|
|
7868
|
+
/* @__PURE__ */ jsxs55("span", { className: "ow-chat-sources__text", children: [
|
|
7869
|
+
/* @__PURE__ */ jsx71("span", { className: "ow-chat-sources__title", children: item.title }),
|
|
7870
|
+
item.source ? /* @__PURE__ */ jsx71("span", { className: "ow-chat-sources__source", children: item.source }) : null
|
|
7871
|
+
] }),
|
|
7872
|
+
item.href && item.external ? /* @__PURE__ */ jsxs55(Fragment12, { children: [
|
|
7873
|
+
/* @__PURE__ */ jsx71("span", { className: "ow-chat-sources__external", "aria-hidden": "true", children: /* @__PURE__ */ jsx71(ArrowUpRightIcon, { size: 14 }) }),
|
|
7874
|
+
/* @__PURE__ */ jsx71("span", { className: "ow-visually-hidden", children: " (opens in a new tab)" })
|
|
7875
|
+
] }) : null
|
|
7876
|
+
] });
|
|
7877
|
+
return /* @__PURE__ */ jsx71("li", { children: item.href ? /* @__PURE__ */ jsx71(
|
|
7878
|
+
"a",
|
|
7879
|
+
{
|
|
7880
|
+
href: item.href,
|
|
7881
|
+
className: "ow-chat-sources__card ow-chat-sources__card--link",
|
|
7882
|
+
...item.external ? { target: "_blank", rel: "noopener noreferrer" } : {},
|
|
7883
|
+
children: content
|
|
7884
|
+
}
|
|
7885
|
+
) : /* @__PURE__ */ jsx71("div", { className: "ow-chat-sources__card", children: content }) }, item.id ?? item.index ?? position);
|
|
7886
|
+
}) }) })
|
|
7887
|
+
] });
|
|
7888
|
+
});
|
|
7889
|
+
|
|
6403
7890
|
// src/components/ColorPicker/ColorPicker.tsx
|
|
6404
|
-
import { forwardRef as
|
|
7891
|
+
import { forwardRef as forwardRef31, useCallback as useCallback12, useEffect as useEffect31, useId as useId27, useRef as useRef39, useState as useState34 } from "react";
|
|
6405
7892
|
import { HexAlphaColorPicker, HexColorInput, HexColorPicker } from "react-colorful";
|
|
6406
|
-
import { Fragment as
|
|
7893
|
+
import { Fragment as Fragment13, jsx as jsx72, jsxs as jsxs56 } from "react/jsx-runtime";
|
|
6407
7894
|
var swatchColor = (swatch) => typeof swatch === "string" ? swatch : swatch.color;
|
|
6408
7895
|
var swatchName = (swatch) => typeof swatch === "string" ? swatch : swatch.name;
|
|
6409
7896
|
var same = (a, b) => a.toLowerCase().replace(/^#/, "") === b.toLowerCase().replace(/^#/, "");
|
|
@@ -6419,10 +7906,10 @@ function ColorPicker({
|
|
|
6419
7906
|
className
|
|
6420
7907
|
}) {
|
|
6421
7908
|
const [color, setColor] = useControllableState(value, defaultValue, onChange);
|
|
6422
|
-
const [canPick, setCanPick] =
|
|
6423
|
-
const rootRef =
|
|
6424
|
-
|
|
6425
|
-
|
|
7909
|
+
const [canPick, setCanPick] = useState34(false);
|
|
7910
|
+
const rootRef = useRef39(null);
|
|
7911
|
+
useEffect31(() => setCanPick(typeof window !== "undefined" && "EyeDropper" in window), []);
|
|
7912
|
+
useEffect31(() => {
|
|
6426
7913
|
const names = { saturation: "Colour", hue: "Hue", alpha: "Opacity" };
|
|
6427
7914
|
for (const [part, label] of Object.entries(names)) {
|
|
6428
7915
|
rootRef.current?.querySelector(`.react-colorful__${part} .react-colorful__interactive`)?.setAttribute("aria-label", label);
|
|
@@ -6438,13 +7925,13 @@ function ColorPicker({
|
|
|
6438
7925
|
} catch {
|
|
6439
7926
|
}
|
|
6440
7927
|
}
|
|
6441
|
-
return /* @__PURE__ */
|
|
6442
|
-
/* @__PURE__ */
|
|
6443
|
-
showInput || eyeDropper && canPick ? /* @__PURE__ */
|
|
6444
|
-
eyeDropper && canPick ? /* @__PURE__ */
|
|
6445
|
-
showInput ? /* @__PURE__ */
|
|
6446
|
-
/* @__PURE__ */
|
|
6447
|
-
/* @__PURE__ */
|
|
7928
|
+
return /* @__PURE__ */ jsxs56("div", { ref: rootRef, role: "group", "aria-label": ariaLabel, className: cx("ow-color-picker", className), children: [
|
|
7929
|
+
/* @__PURE__ */ jsx72(Picker, { color, onChange: change }),
|
|
7930
|
+
showInput || eyeDropper && canPick ? /* @__PURE__ */ jsxs56("div", { className: "ow-color-picker__row", children: [
|
|
7931
|
+
eyeDropper && canPick ? /* @__PURE__ */ jsx72("button", { type: "button", className: "ow-color-picker__dropper", "aria-label": "Pick a colour from the screen", onClick: pickFromScreen, children: /* @__PURE__ */ jsx72(PipetteIcon, { size: 15 }) }) : null,
|
|
7932
|
+
showInput ? /* @__PURE__ */ jsxs56("span", { className: "ow-input-group ow-input-group--sm ow-color-picker__input", children: [
|
|
7933
|
+
/* @__PURE__ */ jsx72("span", { className: "ow-input-group__addon", "aria-hidden": "true", children: "#" }),
|
|
7934
|
+
/* @__PURE__ */ jsx72(
|
|
6448
7935
|
HexColorInput,
|
|
6449
7936
|
{
|
|
6450
7937
|
className: "ow-input-group__input",
|
|
@@ -6456,11 +7943,11 @@ function ColorPicker({
|
|
|
6456
7943
|
}
|
|
6457
7944
|
)
|
|
6458
7945
|
] }) : null,
|
|
6459
|
-
/* @__PURE__ */
|
|
7946
|
+
/* @__PURE__ */ jsx72("span", { className: "ow-color-picker__preview", style: { "--ow-color-picker-value": color }, "aria-hidden": "true" })
|
|
6460
7947
|
] }) : null,
|
|
6461
|
-
swatches?.length ? /* @__PURE__ */
|
|
7948
|
+
swatches?.length ? /* @__PURE__ */ jsx72("div", { className: "ow-color-picker__swatches", role: "group", "aria-label": "Swatches", children: swatches.map((swatch) => {
|
|
6462
7949
|
const swatchValue = swatchColor(swatch);
|
|
6463
|
-
return /* @__PURE__ */
|
|
7950
|
+
return /* @__PURE__ */ jsx72(
|
|
6464
7951
|
"button",
|
|
6465
7952
|
{
|
|
6466
7953
|
type: "button",
|
|
@@ -6480,7 +7967,7 @@ function assignRef7(ref, value) {
|
|
|
6480
7967
|
if (typeof ref === "function") ref(value);
|
|
6481
7968
|
else if (ref) ref.current = value;
|
|
6482
7969
|
}
|
|
6483
|
-
var ColorField =
|
|
7970
|
+
var ColorField = forwardRef31(function ColorField2({
|
|
6484
7971
|
value,
|
|
6485
7972
|
defaultValue = "#312c7e",
|
|
6486
7973
|
onChange,
|
|
@@ -6496,24 +7983,24 @@ var ColorField = forwardRef23(function ColorField2({
|
|
|
6496
7983
|
...pickerProps
|
|
6497
7984
|
}, ref) {
|
|
6498
7985
|
const [color, setColor] = useControllableState(value, defaultValue, onChange);
|
|
6499
|
-
const [isOpen, setOpen] =
|
|
6500
|
-
const triggerRef =
|
|
6501
|
-
const panelRef =
|
|
6502
|
-
const panelId =
|
|
7986
|
+
const [isOpen, setOpen] = useState34(false);
|
|
7987
|
+
const triggerRef = useRef39(null);
|
|
7988
|
+
const panelRef = useRef39(null);
|
|
7989
|
+
const panelId = useId27();
|
|
6503
7990
|
const { mounted, state } = usePresence(isOpen);
|
|
6504
7991
|
const style = useFloating({ open: mounted, anchorRef: triggerRef, floatingRef: panelRef, placement, offset: 6, maxHeight: 640 });
|
|
6505
|
-
const close =
|
|
7992
|
+
const close = useCallback12((reason) => {
|
|
6506
7993
|
setOpen(false);
|
|
6507
7994
|
if (reason !== "outside") triggerRef.current?.focus();
|
|
6508
7995
|
}, []);
|
|
6509
7996
|
useDismiss(isOpen, [panelRef, triggerRef], close);
|
|
6510
|
-
|
|
7997
|
+
useEffect31(() => {
|
|
6511
7998
|
if (!isOpen) return void 0;
|
|
6512
7999
|
const frame = requestAnimationFrame(() => panelRef.current?.querySelector(".react-colorful__interactive")?.focus());
|
|
6513
8000
|
return () => cancelAnimationFrame(frame);
|
|
6514
8001
|
}, [isOpen]);
|
|
6515
|
-
return /* @__PURE__ */
|
|
6516
|
-
/* @__PURE__ */
|
|
8002
|
+
return /* @__PURE__ */ jsxs56(Fragment13, { children: [
|
|
8003
|
+
/* @__PURE__ */ jsxs56(
|
|
6517
8004
|
"button",
|
|
6518
8005
|
{
|
|
6519
8006
|
ref: (element) => {
|
|
@@ -6545,13 +8032,13 @@ var ColorField = forwardRef23(function ColorField2({
|
|
|
6545
8032
|
}
|
|
6546
8033
|
},
|
|
6547
8034
|
children: [
|
|
6548
|
-
/* @__PURE__ */
|
|
6549
|
-
/* @__PURE__ */
|
|
6550
|
-
/* @__PURE__ */
|
|
8035
|
+
/* @__PURE__ */ jsx72("span", { className: "ow-color-field__swatch", style: { "--ow-color-picker-value": color }, "aria-hidden": "true" }),
|
|
8036
|
+
/* @__PURE__ */ jsx72("span", { id: `${panelId}-value`, className: "ow-select__value ow-color-field__value", children: color.toUpperCase() }),
|
|
8037
|
+
/* @__PURE__ */ jsx72(ChevronDownIcon, { size: size2 === "sm" ? 14 : 16, className: "ow-select__chevron" })
|
|
6551
8038
|
]
|
|
6552
8039
|
}
|
|
6553
8040
|
),
|
|
6554
|
-
mounted ? /* @__PURE__ */
|
|
8041
|
+
mounted ? /* @__PURE__ */ jsx72(
|
|
6555
8042
|
"div",
|
|
6556
8043
|
{
|
|
6557
8044
|
ref: panelRef,
|
|
@@ -6565,17 +8052,17 @@ var ColorField = forwardRef23(function ColorField2({
|
|
|
6565
8052
|
onKeyDown: (event) => {
|
|
6566
8053
|
if (event.key === "Enter" && event.target.closest(".react-colorful")) close();
|
|
6567
8054
|
},
|
|
6568
|
-
children: /* @__PURE__ */
|
|
8055
|
+
children: /* @__PURE__ */ jsx72(ColorPicker, { ...pickerProps, value: color, onChange: setColor })
|
|
6569
8056
|
}
|
|
6570
8057
|
) : null
|
|
6571
8058
|
] });
|
|
6572
8059
|
});
|
|
6573
8060
|
|
|
6574
8061
|
// src/components/ColorPicker/ColorArea.tsx
|
|
6575
|
-
import { forwardRef as
|
|
8062
|
+
import { forwardRef as forwardRef32, useRef as useRef41, useState as useState36 } from "react";
|
|
6576
8063
|
|
|
6577
8064
|
// src/components/ColorPicker/color.ts
|
|
6578
|
-
import { useCallback as
|
|
8065
|
+
import { useCallback as useCallback13, useReducer, useRef as useRef40, useState as useState35 } from "react";
|
|
6579
8066
|
var clamp2 = (n, min, max) => Math.min(max, Math.max(min, n));
|
|
6580
8067
|
function parseHex(color) {
|
|
6581
8068
|
let hex = color.trim().replace(/^#/, "");
|
|
@@ -6652,7 +8139,7 @@ var hslModel = {
|
|
|
6652
8139
|
var fallback = { r: 0, g: 0, b: 0, a: 1 };
|
|
6653
8140
|
function useColorModel(value, defaultValue, onChange, model, { hue, alpha = false } = {}) {
|
|
6654
8141
|
const [color, setColor] = useControllableState(value, defaultValue, onChange);
|
|
6655
|
-
const memory =
|
|
8142
|
+
const memory = useRef40(null);
|
|
6656
8143
|
const [, rerender] = useReducer((n) => n + 1, 0);
|
|
6657
8144
|
const incoming = normalizeHex(color);
|
|
6658
8145
|
if (!memory.current || memory.current.hex !== incoming || memory.current.model !== model) {
|
|
@@ -6664,7 +8151,7 @@ function useColorModel(value, defaultValue, onChange, model, { hue, alpha = fals
|
|
|
6664
8151
|
const isGrey = rgba.r === rgba.g && rgba.g === rgba.b;
|
|
6665
8152
|
const current = isGrey && hue !== void 0 ? { ...memory.current.value, h: hue } : memory.current.value;
|
|
6666
8153
|
const withAlpha = alpha || hasAlpha(color);
|
|
6667
|
-
const set =
|
|
8154
|
+
const set = useCallback13(
|
|
6668
8155
|
(next) => {
|
|
6669
8156
|
const hex = toHex(model.write(next), withAlpha);
|
|
6670
8157
|
memory.current = { hex, model, value: next };
|
|
@@ -6674,7 +8161,7 @@ function useColorModel(value, defaultValue, onChange, model, { hue, alpha = fals
|
|
|
6674
8161
|
},
|
|
6675
8162
|
[model, withAlpha, setColor]
|
|
6676
8163
|
);
|
|
6677
|
-
const latest =
|
|
8164
|
+
const latest = useCallback13(() => memory.current?.hex ?? incoming, [incoming]);
|
|
6678
8165
|
return { value: current, rgba: model.write(current), hex: memory.current.hex, set, latest };
|
|
6679
8166
|
}
|
|
6680
8167
|
function useDrag({
|
|
@@ -6683,8 +8170,8 @@ function useDrag({
|
|
|
6683
8170
|
onStart,
|
|
6684
8171
|
disabled = false
|
|
6685
8172
|
}) {
|
|
6686
|
-
const [dragging, setDragging] =
|
|
6687
|
-
const [pointerFocus, setPointerFocus] =
|
|
8173
|
+
const [dragging, setDragging] = useState35(false);
|
|
8174
|
+
const [pointerFocus, setPointerFocus] = useState35(false);
|
|
6688
8175
|
const move = (event) => {
|
|
6689
8176
|
const rect = event.currentTarget.getBoundingClientRect();
|
|
6690
8177
|
onMove(clamp2((event.clientX - rect.left) / (rect.width || 1), 0, 1), clamp2((event.clientY - rect.top) / (rect.height || 1), 0, 1));
|
|
@@ -6756,13 +8243,13 @@ var hueHex = (h) => toHex(hsvToRgb({ h, s: 100, v: 100, a: 1 }));
|
|
|
6756
8243
|
var hueStops = "#ff0000 0%, #ffff00 16.67%, #00ff00 33.33%, #00ffff 50%, #0000ff 66.67%, #ff00ff 83.33%, #ff0000 100%";
|
|
6757
8244
|
|
|
6758
8245
|
// src/components/ColorPicker/ColorArea.tsx
|
|
6759
|
-
import { jsx as
|
|
8246
|
+
import { jsx as jsx73, jsxs as jsxs57 } from "react/jsx-runtime";
|
|
6760
8247
|
var size = (length) => typeof length === "number" ? `${length}px` : length;
|
|
6761
8248
|
function assignRef8(ref, value) {
|
|
6762
8249
|
if (typeof ref === "function") ref(value);
|
|
6763
8250
|
else if (ref) ref.current = value;
|
|
6764
8251
|
}
|
|
6765
|
-
var ColorArea =
|
|
8252
|
+
var ColorArea = forwardRef32(function ColorArea2({
|
|
6766
8253
|
value,
|
|
6767
8254
|
defaultValue = "#312c7e",
|
|
6768
8255
|
onChange,
|
|
@@ -6780,9 +8267,9 @@ var ColorArea = forwardRef24(function ColorArea2({
|
|
|
6780
8267
|
className
|
|
6781
8268
|
}, ref) {
|
|
6782
8269
|
const { value: hsv, rgba, hex, set, latest } = useColorModel(value, defaultValue, onChange, hsvModel, { hue });
|
|
6783
|
-
const rootRef =
|
|
6784
|
-
const inputs =
|
|
6785
|
-
const [axis, setAxis] =
|
|
8270
|
+
const rootRef = useRef41(null);
|
|
8271
|
+
const inputs = useRef41({ x: null, y: null });
|
|
8272
|
+
const [axis, setAxis] = useState36("x");
|
|
6786
8273
|
const isRtl = () => rootRef.current ? getComputedStyle(rootRef.current).direction === "rtl" : false;
|
|
6787
8274
|
const end = () => onChangeEnd?.(latest());
|
|
6788
8275
|
const drag = useDrag({
|
|
@@ -6837,7 +8324,7 @@ var ColorArea = forwardRef24(function ColorArea2({
|
|
|
6837
8324
|
const saturation = `Saturation ${percent.format(hsv.s / 100)}`;
|
|
6838
8325
|
const brightness = `brightness ${percent.format(hsv.v / 100)}`;
|
|
6839
8326
|
const colorName = describeColor(rgba);
|
|
6840
|
-
const input = (which) => /* @__PURE__ */
|
|
8327
|
+
const input = (which) => /* @__PURE__ */ jsx73(
|
|
6841
8328
|
"input",
|
|
6842
8329
|
{
|
|
6843
8330
|
ref: (element) => {
|
|
@@ -6864,7 +8351,7 @@ var ColorArea = forwardRef24(function ColorArea2({
|
|
|
6864
8351
|
onKeyUp
|
|
6865
8352
|
}
|
|
6866
8353
|
);
|
|
6867
|
-
return /* @__PURE__ */
|
|
8354
|
+
return /* @__PURE__ */ jsxs57(
|
|
6868
8355
|
"div",
|
|
6869
8356
|
{
|
|
6870
8357
|
ref: rootRef,
|
|
@@ -6885,7 +8372,7 @@ var ColorArea = forwardRef24(function ColorArea2({
|
|
|
6885
8372
|
},
|
|
6886
8373
|
...drag.handlers,
|
|
6887
8374
|
children: [
|
|
6888
|
-
/* @__PURE__ */
|
|
8375
|
+
/* @__PURE__ */ jsxs57(
|
|
6889
8376
|
"div",
|
|
6890
8377
|
{
|
|
6891
8378
|
className: "ow-color-area__thumb",
|
|
@@ -6896,15 +8383,15 @@ var ColorArea = forwardRef24(function ColorArea2({
|
|
|
6896
8383
|
]
|
|
6897
8384
|
}
|
|
6898
8385
|
),
|
|
6899
|
-
name ? /* @__PURE__ */
|
|
8386
|
+
name ? /* @__PURE__ */ jsx73("input", { type: "hidden", name, value: hex }) : null
|
|
6900
8387
|
]
|
|
6901
8388
|
}
|
|
6902
8389
|
);
|
|
6903
8390
|
});
|
|
6904
8391
|
|
|
6905
8392
|
// src/components/ColorPicker/ColorSlider.tsx
|
|
6906
|
-
import { forwardRef as
|
|
6907
|
-
import { jsx as
|
|
8393
|
+
import { forwardRef as forwardRef33, useId as useId28, useRef as useRef42 } from "react";
|
|
8394
|
+
import { jsx as jsx74, jsxs as jsxs58 } from "react/jsx-runtime";
|
|
6908
8395
|
var channels = {
|
|
6909
8396
|
hue: { name: "Hue", max: 360, unit: "degree" },
|
|
6910
8397
|
saturation: { name: "Saturation", max: 100, unit: "percent" },
|
|
@@ -6951,7 +8438,7 @@ function assignRef9(ref, value) {
|
|
|
6951
8438
|
if (typeof ref === "function") ref(value);
|
|
6952
8439
|
else if (ref) ref.current = value;
|
|
6953
8440
|
}
|
|
6954
|
-
var ColorSlider =
|
|
8441
|
+
var ColorSlider = forwardRef33(function ColorSlider2({
|
|
6955
8442
|
channel,
|
|
6956
8443
|
value,
|
|
6957
8444
|
defaultValue = "#312c7e",
|
|
@@ -6979,9 +8466,9 @@ var ColorSlider = forwardRef25(function ColorSlider2({
|
|
|
6979
8466
|
});
|
|
6980
8467
|
const { rgba, latest } = color;
|
|
6981
8468
|
const current = read(channel, color.value, rgba);
|
|
6982
|
-
const labelId =
|
|
6983
|
-
const trackRef =
|
|
6984
|
-
const inputRef =
|
|
8469
|
+
const labelId = useId28();
|
|
8470
|
+
const trackRef = useRef42(null);
|
|
8471
|
+
const inputRef = useRef42(null);
|
|
6985
8472
|
const vertical = orientation === "vertical";
|
|
6986
8473
|
const isRtl = () => !vertical && trackRef.current !== null && getComputedStyle(trackRef.current).direction === "rtl";
|
|
6987
8474
|
const end = () => onChangeEnd?.(latest());
|
|
@@ -7019,7 +8506,7 @@ var ColorSlider = forwardRef25(function ColorSlider2({
|
|
|
7019
8506
|
const shown = format.format(spec.unit === "percent" ? current / 100 : current);
|
|
7020
8507
|
const named = channel === "hue" ? describeColor(parseHex(hueHex(color.value.h))) : describeColor({ ...rgba, a: 1 });
|
|
7021
8508
|
const fill = channel === "hue" ? hueHex(color.value.h) : toHex(rgba, channel === "alpha");
|
|
7022
|
-
return /* @__PURE__ */
|
|
8509
|
+
return /* @__PURE__ */ jsxs58(
|
|
7023
8510
|
"div",
|
|
7024
8511
|
{
|
|
7025
8512
|
className: cx(
|
|
@@ -7034,11 +8521,11 @@ var ColorSlider = forwardRef25(function ColorSlider2({
|
|
|
7034
8521
|
className
|
|
7035
8522
|
),
|
|
7036
8523
|
children: [
|
|
7037
|
-
label || showValue ? /* @__PURE__ */
|
|
7038
|
-
label ? /* @__PURE__ */
|
|
7039
|
-
showValue ? /* @__PURE__ */
|
|
8524
|
+
label || showValue ? /* @__PURE__ */ jsxs58("div", { className: "ow-color-slider__header", children: [
|
|
8525
|
+
label ? /* @__PURE__ */ jsx74("span", { id: labelId, className: "ow-color-slider__label", children: label }) : /* @__PURE__ */ jsx74("span", {}),
|
|
8526
|
+
showValue ? /* @__PURE__ */ jsx74("output", { className: "ow-color-slider__value", "aria-hidden": "true", children: shown }) : null
|
|
7040
8527
|
] }) : null,
|
|
7041
|
-
/* @__PURE__ */
|
|
8528
|
+
/* @__PURE__ */ jsx74(
|
|
7042
8529
|
"div",
|
|
7043
8530
|
{
|
|
7044
8531
|
ref: trackRef,
|
|
@@ -7047,12 +8534,12 @@ var ColorSlider = forwardRef25(function ColorSlider2({
|
|
|
7047
8534
|
"--ow-color-slider-gradient": `linear-gradient(var(--ow-color-slider-direction), ${gradient(channel, color.value, rgba)})`
|
|
7048
8535
|
},
|
|
7049
8536
|
...drag.handlers,
|
|
7050
|
-
children: /* @__PURE__ */
|
|
8537
|
+
children: /* @__PURE__ */ jsx74(
|
|
7051
8538
|
"div",
|
|
7052
8539
|
{
|
|
7053
8540
|
className: "ow-color-slider__thumb",
|
|
7054
8541
|
style: { "--ow-color-slider-position": `${current / spec.max * 100}%`, "--ow-color-slider-thumb": fill },
|
|
7055
|
-
children: /* @__PURE__ */
|
|
8542
|
+
children: /* @__PURE__ */ jsx74(
|
|
7056
8543
|
"input",
|
|
7057
8544
|
{
|
|
7058
8545
|
ref: (element) => {
|
|
@@ -7084,18 +8571,18 @@ var ColorSlider = forwardRef25(function ColorSlider2({
|
|
|
7084
8571
|
)
|
|
7085
8572
|
}
|
|
7086
8573
|
),
|
|
7087
|
-
name ? /* @__PURE__ */
|
|
8574
|
+
name ? /* @__PURE__ */ jsx74("input", { type: "hidden", name, value: color.hex }) : null
|
|
7088
8575
|
]
|
|
7089
8576
|
}
|
|
7090
8577
|
);
|
|
7091
8578
|
});
|
|
7092
8579
|
|
|
7093
8580
|
// src/components/ColorPicker/ColorSwatchPicker.tsx
|
|
7094
|
-
import { forwardRef as
|
|
7095
|
-
import { jsx as
|
|
7096
|
-
var ColorSwatchPicker =
|
|
8581
|
+
import { forwardRef as forwardRef34, useRef as useRef43 } from "react";
|
|
8582
|
+
import { jsx as jsx75, jsxs as jsxs59 } from "react/jsx-runtime";
|
|
8583
|
+
var ColorSwatchPicker = forwardRef34(function ColorSwatchPicker2({ options, value, defaultValue, onChange, size: size2 = "md", shape = "square", disabled = false, name, className, ...aria }, ref) {
|
|
7097
8584
|
const [current, setCurrent] = useControllableState(value, defaultValue ?? "", onChange);
|
|
7098
|
-
const refs =
|
|
8585
|
+
const refs = useRef43([]);
|
|
7099
8586
|
const items2 = options.map((option) => {
|
|
7100
8587
|
const item = typeof option === "string" ? { value: option } : option;
|
|
7101
8588
|
const rgba = parseHex(item.value);
|
|
@@ -7129,7 +8616,7 @@ var ColorSwatchPicker = forwardRef26(function ColorSwatchPicker2({ options, valu
|
|
|
7129
8616
|
refs.current[target]?.focus();
|
|
7130
8617
|
choose(target);
|
|
7131
8618
|
}
|
|
7132
|
-
return /* @__PURE__ */
|
|
8619
|
+
return /* @__PURE__ */ jsxs59(
|
|
7133
8620
|
"div",
|
|
7134
8621
|
{
|
|
7135
8622
|
ref,
|
|
@@ -7146,7 +8633,7 @@ var ColorSwatchPicker = forwardRef26(function ColorSwatchPicker2({ options, valu
|
|
|
7146
8633
|
items2.map((item, index) => {
|
|
7147
8634
|
const isSelected = index === selectedIndex;
|
|
7148
8635
|
const isDisabled = disabled || Boolean(item.disabled);
|
|
7149
|
-
return /* @__PURE__ */
|
|
8636
|
+
return /* @__PURE__ */ jsx75(
|
|
7150
8637
|
"div",
|
|
7151
8638
|
{
|
|
7152
8639
|
ref: (element) => {
|
|
@@ -7163,12 +8650,12 @@ var ColorSwatchPicker = forwardRef26(function ColorSwatchPicker2({ options, valu
|
|
|
7163
8650
|
style: { "--ow-color-swatch-picker-value": item.value },
|
|
7164
8651
|
onClick: () => choose(index),
|
|
7165
8652
|
onKeyDown: (event) => onKeyDown(event, index),
|
|
7166
|
-
children: /* @__PURE__ */
|
|
8653
|
+
children: /* @__PURE__ */ jsx75(CheckIcon, { size: size2 === "sm" ? 14 : 16, strokeWidth: 2.5, className: "ow-color-swatch-picker__check", "aria-hidden": "true" })
|
|
7167
8654
|
},
|
|
7168
8655
|
`${item.value}-${index}`
|
|
7169
8656
|
);
|
|
7170
8657
|
}),
|
|
7171
|
-
name ? /* @__PURE__ */
|
|
8658
|
+
name ? /* @__PURE__ */ jsx75("input", { type: "hidden", name, value: selectedIndex >= 0 ? items2[selectedIndex].value : "" }) : null
|
|
7172
8659
|
]
|
|
7173
8660
|
}
|
|
7174
8661
|
);
|
|
@@ -7378,6 +8865,15 @@ export {
|
|
|
7378
8865
|
ButtonGroup,
|
|
7379
8866
|
Calendar,
|
|
7380
8867
|
Card,
|
|
8868
|
+
ChainOfThought,
|
|
8869
|
+
ChatAgentAvatar,
|
|
8870
|
+
ChatConversation,
|
|
8871
|
+
ChatLoader,
|
|
8872
|
+
ChatMessage,
|
|
8873
|
+
ChatMessageActions,
|
|
8874
|
+
ChatSource,
|
|
8875
|
+
ChatSources,
|
|
8876
|
+
ChatTool,
|
|
7381
8877
|
Checkbox,
|
|
7382
8878
|
CheckboxGroup,
|
|
7383
8879
|
Chip,
|
|
@@ -7426,6 +8922,10 @@ export {
|
|
|
7426
8922
|
Popover,
|
|
7427
8923
|
ProgressBar,
|
|
7428
8924
|
ProgressCircle,
|
|
8925
|
+
PromptInput,
|
|
8926
|
+
PromptSuggestion,
|
|
8927
|
+
PromptSuggestions,
|
|
8928
|
+
Prose,
|
|
7429
8929
|
Radio,
|
|
7430
8930
|
RadioGroup,
|
|
7431
8931
|
RangeCalendar,
|
|
@@ -7454,6 +8954,7 @@ export {
|
|
|
7454
8954
|
Tag,
|
|
7455
8955
|
TagGroup,
|
|
7456
8956
|
Text,
|
|
8957
|
+
TextShimmer,
|
|
7457
8958
|
Textarea,
|
|
7458
8959
|
TimeField,
|
|
7459
8960
|
Toaster,
|