@page-speed/agent-everywhere 1.0.0 → 1.1.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/dist/index.js CHANGED
@@ -2,11 +2,11 @@
2
2
  import { clsx } from 'clsx';
3
3
  import { twMerge } from 'tailwind-merge';
4
4
  import * as React4 from 'react';
5
- import { createContext, forwardRef, useRef, useImperativeHandle, useCallback, useLayoutEffect, useState, useEffect, useReducer, useMemo, useContext, useId, Fragment as Fragment$1 } from 'react';
5
+ import { createContext, forwardRef, useRef, useImperativeHandle, useCallback, useLayoutEffect, useState, useEffect, useReducer, useMemo, useContext, useId, Fragment as Fragment$1, isValidElement, cloneElement } from 'react';
6
6
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
7
7
  import { AnimatePresence, motion } from 'motion/react';
8
8
  import { Markdown } from '@page-speed/markdown-to-jsx';
9
- import { SendIcon, PaperclipIcon, FileTextIcon, MicIcon, ImageIcon, XIcon, SearchIcon, UploadIcon, FileIcon, UserCircleIcon, CheckIcon, SparklesIcon, BookmarkIcon, InfoIcon, CheckCircle2Icon, AlertTriangleIcon, LightbulbIcon, BrainIcon, ChevronDownIcon, ZapIcon, CopyIcon, ThumbsUpIcon, ThumbsDownIcon, BotIcon, UserIcon, DownloadIcon, MinusIcon, TrendingDownIcon, TrendingUpIcon, ChevronUpIcon, ArrowUpDownIcon, LinkIcon, PlayIcon, ExternalLinkIcon, WandIcon, LayoutGridIcon, Grid3X3Icon, ArrowUpRightIcon, ShuffleIcon, SkipForwardIcon, ChevronLeftIcon, ChevronRightIcon, XCircleIcon, HelpCircleIcon, Minimize2Icon, Maximize2Icon, RotateCcwIcon, MessageSquareIcon, GripVerticalIcon, PanelLeftOpenIcon, PanelLeftCloseIcon, CheckCircleIcon, AlertCircleIcon, MoreHorizontalIcon, ClipboardListIcon, ArrowLeftIcon, MoreVerticalIcon, Loader2, ArrowUp, PanelLeft, PanelRight, RotateCcw, ChevronDown, Sparkles, MessageSquare, Paperclip, Loader2Icon, ArrowRightIcon, AlignLeftIcon, ListIcon, HashIcon, TypeIcon, ClockIcon, CoinsIcon, ActivityIcon, ArrowUpIcon, ArrowDownIcon } from 'lucide-react';
9
+ import { SendIcon, PaperclipIcon, FileTextIcon, MicIcon, ImageIcon, XIcon, SearchIcon, UploadIcon, FileIcon, UserCircleIcon, CheckIcon, SparklesIcon, BookmarkIcon, InfoIcon, CheckCircle2Icon, AlertTriangleIcon, LightbulbIcon, BrainIcon, ChevronDownIcon, ZapIcon, CopyIcon, ThumbsUpIcon, ThumbsDownIcon, BotIcon, UserIcon, DownloadIcon, MinusIcon, TrendingDownIcon, TrendingUpIcon, ChevronUpIcon, ArrowUpDownIcon, LinkIcon, PlayIcon, ExternalLinkIcon, WandIcon, LayoutGridIcon, Grid3X3Icon, ArrowUpRightIcon, ShuffleIcon, SkipForwardIcon, ChevronLeftIcon, ChevronRightIcon, XCircleIcon, HelpCircleIcon, Minimize2Icon, Maximize2Icon, RotateCcwIcon, MessageSquareIcon, GripVerticalIcon, PanelLeftOpenIcon, PanelLeftCloseIcon, CheckCircleIcon, AlertCircleIcon, MoreHorizontalIcon, Globe, X, Loader2, CornerDownLeft, Pencil, Trash2, CircleCheck, ClipboardListIcon, ArrowLeftIcon, MoreVerticalIcon, ArrowUp, PanelLeft, PanelRight, RotateCcw, ChevronDown, Sparkles, MessageSquare, Paperclip, Loader2Icon, ArrowRightIcon, AlignLeftIcon, ListIcon, HashIcon, TypeIcon, ClockIcon, CoinsIcon, ActivityIcon, ShoppingCart, MessageCircle, Camera, Music, MapPin, Calendar, User, Settings, Check, Heart, Star, Video, Image, Link, Phone, Mail, Github, Youtube, Linkedin, Twitter, Instagram, Facebook, Play, ArrowUpIcon, ArrowDownIcon } from 'lucide-react';
10
10
  import { Slot } from '@radix-ui/react-slot';
11
11
  import { cva } from 'class-variance-authority';
12
12
  import * as AvatarPrimitive from '@radix-ui/react-avatar';
@@ -9923,6 +9923,813 @@ function AudioPlayer({
9923
9923
  }) })
9924
9924
  ] });
9925
9925
  }
9926
+ var ICON_MAP = {
9927
+ globe: Globe,
9928
+ facebook: Facebook,
9929
+ instagram: Instagram,
9930
+ twitter: Twitter,
9931
+ x: Twitter,
9932
+ linkedin: Linkedin,
9933
+ youtube: Youtube,
9934
+ github: Github,
9935
+ mail: Mail,
9936
+ email: Mail,
9937
+ phone: Phone,
9938
+ link: Link,
9939
+ url: Link,
9940
+ image: Image,
9941
+ photo: Image,
9942
+ video: Video,
9943
+ star: Star,
9944
+ heart: Heart,
9945
+ check: Check,
9946
+ settings: Settings,
9947
+ user: User,
9948
+ account: User,
9949
+ calendar: Calendar,
9950
+ "map-pin": MapPin,
9951
+ mappin: MapPin,
9952
+ location: MapPin,
9953
+ music: Music,
9954
+ camera: Camera,
9955
+ message: MessageCircle,
9956
+ chat: MessageCircle,
9957
+ cart: ShoppingCart,
9958
+ shop: ShoppingCart
9959
+ };
9960
+ function resolveIconName(name, className = "size-5 shrink-0") {
9961
+ if (!name) return null;
9962
+ const Icon = ICON_MAP[name.trim().toLowerCase()];
9963
+ return Icon ? /* @__PURE__ */ jsx(Icon, { "aria-hidden": "true", className }) : null;
9964
+ }
9965
+ var DEFAULT_OPEN_GRAPH_ENDPOINT = "/api/opengraph";
9966
+ function firstString(...values) {
9967
+ for (const value of values) {
9968
+ if (typeof value === "string" && value.trim()) {
9969
+ return value.trim();
9970
+ }
9971
+ }
9972
+ return null;
9973
+ }
9974
+ function imageUrlFromOpenGraph(image) {
9975
+ if (!image) return null;
9976
+ if (typeof image === "string") return firstString(image);
9977
+ return firstString(image.url);
9978
+ }
9979
+ function domainFromUrl(url) {
9980
+ try {
9981
+ return new URL(url).hostname.replace(/^www\./, "");
9982
+ } catch {
9983
+ return url;
9984
+ }
9985
+ }
9986
+ function normalizeUrlForPreview(input) {
9987
+ const trimmed = input.trim();
9988
+ if (!trimmed) return "";
9989
+ return /^https?:\/\//i.test(trimmed) ? trimmed : `https://${trimmed}`;
9990
+ }
9991
+ function buildEndpointUrl(endpoint, url) {
9992
+ const separator = endpoint.includes("?") ? "&" : "?";
9993
+ return `${endpoint}${separator}url=${encodeURIComponent(url)}`;
9994
+ }
9995
+ function getErrorMessage(body) {
9996
+ if (body && typeof body === "object" && "error" in body && typeof body.error === "string") {
9997
+ return body.error;
9998
+ }
9999
+ return "Could not load a preview for that link.";
10000
+ }
10001
+ function extractLinkPreview(data, fallbackUrl = "") {
10002
+ const hybridGraph = data.hybridGraph;
10003
+ const openGraph = data.openGraph;
10004
+ const htmlInferred = data.htmlInferred;
10005
+ const url = firstString(
10006
+ data.finalUrl,
10007
+ data.url,
10008
+ data.normalizedUrl,
10009
+ data.requestedUrl,
10010
+ openGraph?.url,
10011
+ hybridGraph?.url,
10012
+ htmlInferred?.url
10013
+ ) ?? normalizeUrlForPreview(fallbackUrl);
10014
+ return {
10015
+ url,
10016
+ domain: domainFromUrl(url),
10017
+ title: firstString(hybridGraph?.title, openGraph?.title, htmlInferred?.title),
10018
+ description: firstString(
10019
+ hybridGraph?.description,
10020
+ openGraph?.description,
10021
+ htmlInferred?.description
10022
+ ),
10023
+ image: firstString(
10024
+ hybridGraph?.image,
10025
+ imageUrlFromOpenGraph(openGraph?.image ?? null),
10026
+ htmlInferred?.image,
10027
+ htmlInferred?.images?.[0]
10028
+ ),
10029
+ favicon: firstString(hybridGraph?.favicon, htmlInferred?.favicon),
10030
+ siteName: firstString(
10031
+ htmlInferred?.site_name,
10032
+ openGraph?.site_name,
10033
+ hybridGraph?.site_name
10034
+ )
10035
+ };
10036
+ }
10037
+ async function fetchOpenGraphPreview(url, endpoint = DEFAULT_OPEN_GRAPH_ENDPOINT) {
10038
+ const response = await fetch(buildEndpointUrl(endpoint, url), {
10039
+ headers: { Accept: "application/json" }
10040
+ });
10041
+ let body = null;
10042
+ try {
10043
+ body = await response.json();
10044
+ } catch {
10045
+ body = null;
10046
+ }
10047
+ if (!response.ok) {
10048
+ throw new Error(getErrorMessage(body));
10049
+ }
10050
+ return body;
10051
+ }
10052
+ function LinkInput({
10053
+ label = "Add a link",
10054
+ icon,
10055
+ iconName,
10056
+ placeholder = "Paste or type a URL...",
10057
+ defaultUrl = "",
10058
+ defaultValue = null,
10059
+ value,
10060
+ defaultExpanded = false,
10061
+ expanded: controlledExpanded,
10062
+ disabled = false,
10063
+ endpoint = DEFAULT_OPEN_GRAPH_ENDPOINT,
10064
+ fetcher,
10065
+ onSubmit,
10066
+ onValueChange,
10067
+ onClear,
10068
+ onExpandedChange,
10069
+ className
10070
+ }) {
10071
+ const [uncontrolledExpanded, setUncontrolledExpanded] = useState(defaultExpanded);
10072
+ const [url, setUrl] = useState(defaultUrl || defaultValue?.url || "");
10073
+ const [submittedUrl, setSubmittedUrl] = useState(
10074
+ defaultUrl || defaultValue?.url || ""
10075
+ );
10076
+ const [status, setStatus] = useState("idle");
10077
+ const [error, setError] = useState(null);
10078
+ const [internalPreview, setInternalPreview] = useState(
10079
+ defaultValue
10080
+ );
10081
+ const inputRef = useRef(null);
10082
+ const reactId = useId();
10083
+ const inputId = `link-input-${reactId}`;
10084
+ const errorId = `link-input-error-${reactId}`;
10085
+ const isExpanded = controlledExpanded === void 0 ? uncontrolledExpanded : controlledExpanded;
10086
+ const isPreviewControlled = value !== void 0;
10087
+ const preview = (isPreviewControlled ? value : internalPreview) ?? null;
10088
+ const isLoading = status === "loading";
10089
+ const hasPreview = preview !== null;
10090
+ const resolvedIcon = icon ?? resolveIconName(iconName, "size-5") ?? /* @__PURE__ */ jsx(Globe, { "aria-hidden": true, className: "size-5" });
10091
+ const resolvedFetcher = useCallback(
10092
+ (nextUrl) => fetcher?.(nextUrl) ?? fetchOpenGraphPreview(nextUrl, endpoint),
10093
+ [endpoint, fetcher]
10094
+ );
10095
+ const setExpanded = useCallback(
10096
+ (next) => {
10097
+ if (controlledExpanded === void 0) {
10098
+ setUncontrolledExpanded(next);
10099
+ }
10100
+ onExpandedChange?.(next);
10101
+ },
10102
+ [controlledExpanded, onExpandedChange]
10103
+ );
10104
+ useEffect(() => {
10105
+ if (value !== void 0) {
10106
+ const nextUrl = value?.url ?? "";
10107
+ setSubmittedUrl(nextUrl);
10108
+ if (!isExpanded) setUrl(nextUrl);
10109
+ }
10110
+ }, [isExpanded, value]);
10111
+ useEffect(() => {
10112
+ if (!isExpanded) return;
10113
+ const timeout = window.setTimeout(() => inputRef.current?.focus(), 60);
10114
+ return () => window.clearTimeout(timeout);
10115
+ }, [isExpanded]);
10116
+ async function handleSubmit(event) {
10117
+ event?.preventDefault();
10118
+ const nextUrl = url.trim();
10119
+ if (!nextUrl || isLoading || disabled) return;
10120
+ setStatus("loading");
10121
+ setError(null);
10122
+ try {
10123
+ const data = await resolvedFetcher(nextUrl);
10124
+ const nextPreview = extractLinkPreview(data, nextUrl);
10125
+ if (!isPreviewControlled) {
10126
+ setInternalPreview(nextPreview);
10127
+ }
10128
+ setUrl(nextPreview.url);
10129
+ setSubmittedUrl(nextPreview.url);
10130
+ setStatus("idle");
10131
+ setExpanded(false);
10132
+ onValueChange?.(nextPreview, data);
10133
+ onSubmit?.(data, nextPreview);
10134
+ } catch (submitError) {
10135
+ setStatus("error");
10136
+ setError(
10137
+ submitError instanceof Error ? submitError.message : "Something went wrong."
10138
+ );
10139
+ }
10140
+ }
10141
+ function handleEdit() {
10142
+ if (disabled) return;
10143
+ setUrl(submittedUrl);
10144
+ setStatus("idle");
10145
+ setError(null);
10146
+ setExpanded(true);
10147
+ }
10148
+ function handleClose() {
10149
+ setUrl(submittedUrl);
10150
+ setStatus("idle");
10151
+ setError(null);
10152
+ setExpanded(false);
10153
+ }
10154
+ function handleDelete() {
10155
+ if (disabled) return;
10156
+ if (!isPreviewControlled) {
10157
+ setInternalPreview(null);
10158
+ }
10159
+ setUrl("");
10160
+ setSubmittedUrl("");
10161
+ setStatus("idle");
10162
+ setError(null);
10163
+ setExpanded(false);
10164
+ onValueChange?.(null, null);
10165
+ onClear?.();
10166
+ }
10167
+ return /* @__PURE__ */ jsxs(
10168
+ "div",
10169
+ {
10170
+ "data-state": isExpanded ? "editing" : hasPreview ? "filled" : "idle",
10171
+ className: cn(
10172
+ "group/link-input overflow-hidden rounded-xl border bg-card text-card-foreground transition-colors",
10173
+ isExpanded || hasPreview ? "border-foreground/80 shadow-sm" : "border-border hover:border-foreground/30",
10174
+ disabled && "opacity-60",
10175
+ className
10176
+ ),
10177
+ children: [
10178
+ isExpanded ? /* @__PURE__ */ jsxs("div", { className: "relative flex w-full flex-col gap-3 px-4 py-3.5", children: [
10179
+ /* @__PURE__ */ jsx("span", { className: "flex size-5 items-center justify-center text-muted-foreground [&_svg]:size-5", children: resolvedIcon }),
10180
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 text-sm font-medium leading-5 text-foreground", children: label }),
10181
+ /* @__PURE__ */ jsx(
10182
+ "button",
10183
+ {
10184
+ type: "button",
10185
+ onClick: handleClose,
10186
+ "aria-label": "Close link input",
10187
+ className: "absolute right-2.5 top-2.5 flex size-6 items-center justify-center rounded-full text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/60",
10188
+ children: /* @__PURE__ */ jsx(X, { className: "size-4" })
10189
+ }
10190
+ )
10191
+ ] }) : hasPreview ? /* @__PURE__ */ jsx(
10192
+ LinkInputPreview,
10193
+ {
10194
+ preview,
10195
+ onEdit: handleEdit,
10196
+ onDelete: handleDelete,
10197
+ disabled
10198
+ }
10199
+ ) : /* @__PURE__ */ jsxs(
10200
+ "button",
10201
+ {
10202
+ type: "button",
10203
+ onClick: () => setExpanded(true),
10204
+ "aria-expanded": false,
10205
+ disabled,
10206
+ className: "flex w-full flex-col gap-3 px-4 py-3.5 text-left outline-none focus-visible:ring-2 focus-visible:ring-ring/60 disabled:cursor-not-allowed",
10207
+ children: [
10208
+ /* @__PURE__ */ jsx("span", { className: "flex size-5 items-center justify-center text-muted-foreground [&_svg]:size-5", children: resolvedIcon }),
10209
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 text-sm font-medium leading-5 text-foreground", children: label })
10210
+ ]
10211
+ }
10212
+ ),
10213
+ isExpanded && /* @__PURE__ */ jsx("div", { className: "border-t border-border px-4 pb-4 pt-3", children: /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, className: "space-y-2", children: [
10214
+ /* @__PURE__ */ jsxs("div", { className: "relative", children: [
10215
+ /* @__PURE__ */ jsx(
10216
+ Input,
10217
+ {
10218
+ ref: inputRef,
10219
+ id: inputId,
10220
+ type: "text",
10221
+ inputMode: "url",
10222
+ autoComplete: "off",
10223
+ spellCheck: false,
10224
+ value: url,
10225
+ disabled: disabled || isLoading,
10226
+ "aria-invalid": status === "error",
10227
+ "aria-describedby": status === "error" ? errorId : void 0,
10228
+ onChange: (event) => {
10229
+ setUrl(event.target.value);
10230
+ if (status === "error") {
10231
+ setStatus("idle");
10232
+ setError(null);
10233
+ }
10234
+ },
10235
+ placeholder,
10236
+ className: cn(
10237
+ "h-10 rounded-lg bg-background pr-[5.25rem] text-sm shadow-sm placeholder:text-muted-foreground/70 focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/40",
10238
+ status === "error" && "border-destructive/60"
10239
+ )
10240
+ }
10241
+ ),
10242
+ /* @__PURE__ */ jsx("div", { className: "absolute inset-y-0 right-1.5 flex items-center", children: /* @__PURE__ */ jsxs(
10243
+ Button,
10244
+ {
10245
+ type: "submit",
10246
+ size: "sm",
10247
+ disabled: !url.trim() || isLoading || disabled,
10248
+ className: "h-7 gap-1 px-2",
10249
+ children: [
10250
+ isLoading ? /* @__PURE__ */ jsx(Loader2, { "aria-hidden": true, className: "size-3.5 animate-spin" }) : /* @__PURE__ */ jsx(CornerDownLeft, { "aria-hidden": true, className: "size-3.5" }),
10251
+ /* @__PURE__ */ jsx("span", { className: "text-xs", children: isLoading ? "Loading" : "Enter" })
10252
+ ]
10253
+ }
10254
+ ) })
10255
+ ] }),
10256
+ status === "error" && error ? /* @__PURE__ */ jsx("p", { id: errorId, role: "alert", className: "px-0.5 text-xs text-destructive", children: error }) : /* @__PURE__ */ jsxs("p", { className: "px-0.5 text-xs text-muted-foreground", children: [
10257
+ "Press",
10258
+ " ",
10259
+ /* @__PURE__ */ jsx("kbd", { className: "rounded border border-border bg-muted px-1 font-sans text-[0.65rem] text-muted-foreground", children: "Enter" }),
10260
+ " ",
10261
+ "to fetch a preview."
10262
+ ] })
10263
+ ] }) })
10264
+ ]
10265
+ }
10266
+ );
10267
+ }
10268
+ function LinkInputPreview({
10269
+ preview,
10270
+ onEdit,
10271
+ onDelete,
10272
+ disabled
10273
+ }) {
10274
+ const [imageError, setImageError] = useState(false);
10275
+ const [faviconError, setFaviconError] = useState(false);
10276
+ const showImage = Boolean(preview.image) && !imageError;
10277
+ const showFavicon = Boolean(preview.favicon) && !faviconError;
10278
+ const title = preview.title || preview.siteName || preview.domain || "Untitled link";
10279
+ useEffect(() => {
10280
+ setImageError(false);
10281
+ setFaviconError(false);
10282
+ }, [preview.favicon, preview.image]);
10283
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-stretch gap-3 p-3", children: [
10284
+ /* @__PURE__ */ jsx(
10285
+ "a",
10286
+ {
10287
+ href: preview.url || "#",
10288
+ target: "_blank",
10289
+ rel: "noopener noreferrer",
10290
+ className: "relative flex size-16 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-border bg-muted outline-none focus-visible:ring-2 focus-visible:ring-ring/60",
10291
+ children: showImage ? /* @__PURE__ */ jsx(
10292
+ "img",
10293
+ {
10294
+ src: preview.image,
10295
+ alt: "",
10296
+ crossOrigin: "anonymous",
10297
+ onError: () => setImageError(true),
10298
+ className: "size-full object-cover"
10299
+ }
10300
+ ) : showFavicon ? /* @__PURE__ */ jsx(
10301
+ "img",
10302
+ {
10303
+ src: preview.favicon,
10304
+ alt: "",
10305
+ crossOrigin: "anonymous",
10306
+ onError: () => setFaviconError(true),
10307
+ className: "size-7"
10308
+ }
10309
+ ) : /* @__PURE__ */ jsx(Globe, { "aria-hidden": true, className: "size-7 text-muted-foreground" })
10310
+ }
10311
+ ),
10312
+ /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 flex-col justify-center py-0.5", children: [
10313
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
10314
+ showFavicon && showImage ? /* @__PURE__ */ jsx(
10315
+ "img",
10316
+ {
10317
+ src: preview.favicon,
10318
+ alt: "",
10319
+ crossOrigin: "anonymous",
10320
+ onError: () => setFaviconError(true),
10321
+ className: "size-3.5 shrink-0 rounded-sm"
10322
+ }
10323
+ ) : null,
10324
+ /* @__PURE__ */ jsx("span", { className: "truncate text-xs font-medium text-muted-foreground", children: preview.domain || preview.siteName })
10325
+ ] }),
10326
+ /* @__PURE__ */ jsx(
10327
+ "a",
10328
+ {
10329
+ href: preview.url || "#",
10330
+ target: "_blank",
10331
+ rel: "noopener noreferrer",
10332
+ className: "mt-0.5 line-clamp-1 text-sm font-semibold text-foreground outline-none hover:underline focus-visible:underline",
10333
+ children: title
10334
+ }
10335
+ ),
10336
+ preview.description ? /* @__PURE__ */ jsx("p", { className: "mt-0.5 line-clamp-2 text-xs leading-4 text-muted-foreground", children: preview.description }) : null
10337
+ ] }),
10338
+ /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 flex-col items-center gap-1", children: [
10339
+ /* @__PURE__ */ jsx(
10340
+ Button,
10341
+ {
10342
+ type: "button",
10343
+ size: "icon",
10344
+ variant: "ghost",
10345
+ onClick: onEdit,
10346
+ disabled,
10347
+ "aria-label": "Edit link",
10348
+ className: "size-7 rounded-full",
10349
+ children: /* @__PURE__ */ jsx(Pencil, { className: "size-3.5" })
10350
+ }
10351
+ ),
10352
+ /* @__PURE__ */ jsx(
10353
+ Button,
10354
+ {
10355
+ type: "button",
10356
+ size: "icon",
10357
+ variant: "ghost",
10358
+ onClick: onDelete,
10359
+ disabled,
10360
+ "aria-label": "Delete link",
10361
+ className: "size-7 rounded-full",
10362
+ children: /* @__PURE__ */ jsx(Trash2, { className: "size-3.5" })
10363
+ }
10364
+ )
10365
+ ] })
10366
+ ] });
10367
+ }
10368
+ function LinkInputGroup({
10369
+ options,
10370
+ onSubmit,
10371
+ onValueChange,
10372
+ onClear,
10373
+ className
10374
+ }) {
10375
+ const [openId, setOpenId] = useState(null);
10376
+ return /* @__PURE__ */ jsx("div", { className: cn("flex flex-col gap-3", className), children: options.map(({ id, ...option }) => /* @__PURE__ */ jsx(
10377
+ LinkInput,
10378
+ {
10379
+ ...option,
10380
+ expanded: openId === id,
10381
+ onExpandedChange: (next) => setOpenId((currentId) => {
10382
+ if (next) return id;
10383
+ return currentId === id ? null : currentId;
10384
+ }),
10385
+ onSubmit: (data, preview) => {
10386
+ setOpenId(null);
10387
+ onSubmit?.(id, data, preview);
10388
+ },
10389
+ onValueChange: (preview, data) => {
10390
+ onValueChange?.(id, preview, data);
10391
+ },
10392
+ onClear: () => onClear?.(id)
10393
+ },
10394
+ id
10395
+ )) });
10396
+ }
10397
+ var getDimensionStyle = (width, height) => {
10398
+ const style = {};
10399
+ if (width) style.width = typeof width === "number" ? `${width}px` : width;
10400
+ if (height) style.height = typeof height === "number" ? `${height}px` : height;
10401
+ return style;
10402
+ };
10403
+ var getThumbnailSizing = (thumbnailHeight) => ({
10404
+ heightClass: typeof thumbnailHeight === "number" ? "" : thumbnailHeight,
10405
+ heightStyle: typeof thumbnailHeight === "number" ? { height: `${thumbnailHeight}px` } : void 0
10406
+ });
10407
+ function MediaFallback() {
10408
+ return /* @__PURE__ */ jsx("div", { className: "flex h-full min-h-28 w-full items-center justify-center bg-muted text-muted-foreground", children: /* @__PURE__ */ jsx(ImageIcon, { className: "size-7", "aria-hidden": "true" }) });
10409
+ }
10410
+ function MediaOptionItem({
10411
+ option,
10412
+ isChecked,
10413
+ onToggle,
10414
+ thumbnailHeight
10415
+ }) {
10416
+ const {
10417
+ value,
10418
+ label,
10419
+ subtitle,
10420
+ mediaUrl,
10421
+ mediaType,
10422
+ thumbnailUrl,
10423
+ width,
10424
+ height,
10425
+ disabled
10426
+ } = option;
10427
+ const videoRef = useRef(null);
10428
+ const [playing, setPlaying] = useState(false);
10429
+ const [mediaError, setMediaError] = useState(!mediaUrl);
10430
+ const sizeStyle = getDimensionStyle(width, height);
10431
+ const { heightClass, heightStyle } = getThumbnailSizing(thumbnailHeight);
10432
+ const handleMouseEnter = () => {
10433
+ if (mediaType === "video" && videoRef.current && !disabled) {
10434
+ videoRef.current.play().then(() => setPlaying(true)).catch(() => {
10435
+ });
10436
+ }
10437
+ };
10438
+ const handleMouseLeave = () => {
10439
+ if (mediaType === "video" && videoRef.current) {
10440
+ videoRef.current.pause();
10441
+ setPlaying(false);
10442
+ }
10443
+ };
10444
+ const handleVideoClick = (e) => {
10445
+ e.stopPropagation();
10446
+ if (mediaType !== "video" || !videoRef.current || disabled) return;
10447
+ if (playing) {
10448
+ videoRef.current.pause();
10449
+ setPlaying(false);
10450
+ return;
10451
+ }
10452
+ videoRef.current.play().then(() => setPlaying(true)).catch(() => {
10453
+ });
10454
+ };
10455
+ return /* @__PURE__ */ jsxs(
10456
+ "label",
10457
+ {
10458
+ className: cn(
10459
+ "group block h-full",
10460
+ disabled ? "cursor-not-allowed opacity-60" : "cursor-pointer"
10461
+ ),
10462
+ style: sizeStyle,
10463
+ children: [
10464
+ /* @__PURE__ */ jsx(
10465
+ "input",
10466
+ {
10467
+ type: "checkbox",
10468
+ className: "peer sr-only",
10469
+ checked: isChecked,
10470
+ disabled,
10471
+ onChange: () => onToggle(value)
10472
+ }
10473
+ ),
10474
+ /* @__PURE__ */ jsxs(
10475
+ "span",
10476
+ {
10477
+ className: cn(
10478
+ "relative flex h-full flex-col overflow-hidden rounded-lg border bg-card text-card-foreground shadow-xs transition-all duration-200 ease-in-out",
10479
+ "border-input hover:border-border hover:shadow-sm",
10480
+ "peer-focus-visible:ring-2 peer-focus-visible:ring-ring peer-focus-visible:ring-offset-2 peer-focus-visible:ring-offset-background",
10481
+ isChecked && "border-primary shadow-sm ring-1 ring-primary/30 hover:border-primary",
10482
+ disabled && "pointer-events-none"
10483
+ ),
10484
+ children: [
10485
+ /* @__PURE__ */ jsxs(
10486
+ "span",
10487
+ {
10488
+ className: cn("relative block overflow-hidden bg-muted", heightClass),
10489
+ style: heightStyle,
10490
+ onMouseEnter: handleMouseEnter,
10491
+ onMouseLeave: handleMouseLeave,
10492
+ children: [
10493
+ mediaError ? /* @__PURE__ */ jsx(MediaFallback, {}) : mediaType === "image" ? /* @__PURE__ */ jsx(
10494
+ "img",
10495
+ {
10496
+ src: mediaUrl,
10497
+ alt: label,
10498
+ className: "h-full w-full object-cover transition-transform duration-300 ease-out group-hover:scale-[1.015]",
10499
+ onError: () => setMediaError(true)
10500
+ }
10501
+ ) : /* @__PURE__ */ jsxs(Fragment, { children: [
10502
+ /* @__PURE__ */ jsx(
10503
+ "video",
10504
+ {
10505
+ ref: videoRef,
10506
+ src: mediaUrl,
10507
+ poster: thumbnailUrl,
10508
+ muted: true,
10509
+ loop: true,
10510
+ playsInline: true,
10511
+ preload: "metadata",
10512
+ onClick: handleVideoClick,
10513
+ onError: () => setMediaError(true),
10514
+ className: cn(
10515
+ "h-full w-full object-cover transition duration-300 ease-out group-hover:scale-[1.015]",
10516
+ playing ? "grayscale-0" : "grayscale"
10517
+ )
10518
+ }
10519
+ ),
10520
+ /* @__PURE__ */ jsx(
10521
+ "span",
10522
+ {
10523
+ className: cn(
10524
+ "absolute bottom-2 left-2 flex size-7 items-center justify-center rounded-full bg-background/85 text-foreground shadow-xs backdrop-blur",
10525
+ playing && "opacity-0"
10526
+ ),
10527
+ "aria-hidden": "true",
10528
+ children: /* @__PURE__ */ jsx(Play, { className: "ml-0.5 size-3.5 fill-current" })
10529
+ }
10530
+ )
10531
+ ] }),
10532
+ /* @__PURE__ */ jsx(
10533
+ "span",
10534
+ {
10535
+ className: cn(
10536
+ "absolute right-3 top-3 flex size-6 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-xs transition-all duration-200",
10537
+ isChecked ? "scale-100 opacity-100 ring-2 ring-white ring-offset-2" : "scale-75 opacity-0"
10538
+ ),
10539
+ "aria-hidden": "true",
10540
+ children: /* @__PURE__ */ jsx(Check, { className: "size-3.5 stroke-[2.5]" })
10541
+ }
10542
+ )
10543
+ ]
10544
+ }
10545
+ ),
10546
+ /* @__PURE__ */ jsxs(
10547
+ "span",
10548
+ {
10549
+ className: cn(
10550
+ "flex min-h-[82px] flex-col gap-1 border-t border-border bg-card px-3 py-3 text-card-foreground",
10551
+ isChecked && "bg-primary text-primary-foreground"
10552
+ ),
10553
+ children: [
10554
+ /* @__PURE__ */ jsx("span", { className: "line-clamp-1 text-sm font-semibold leading-5", children: label }),
10555
+ subtitle && /* @__PURE__ */ jsx("span", { className: "line-clamp-2 text-sm leading-5", children: subtitle })
10556
+ ]
10557
+ }
10558
+ )
10559
+ ]
10560
+ }
10561
+ )
10562
+ ]
10563
+ }
10564
+ );
10565
+ }
10566
+ function MediaCheckboxes({
10567
+ options,
10568
+ selectedValues,
10569
+ defaultSelectedValues,
10570
+ onSelect,
10571
+ minSelection = 0,
10572
+ maxSelection,
10573
+ className,
10574
+ thumbnailHeight = "h-48"
10575
+ }) {
10576
+ const isControlled = Array.isArray(selectedValues);
10577
+ const [internal, setInternal] = useState(
10578
+ defaultSelectedValues ?? []
10579
+ );
10580
+ const current = isControlled ? selectedValues : internal;
10581
+ const max = maxSelection ?? options.length;
10582
+ const toggleOption = useCallback(
10583
+ (value) => {
10584
+ const isSelected = current.includes(value);
10585
+ let updated;
10586
+ if (isSelected) {
10587
+ updated = current.filter((v) => v !== value);
10588
+ if (updated.length < minSelection) return;
10589
+ } else if (max === 1) {
10590
+ updated = [value];
10591
+ } else {
10592
+ if (current.length >= max) return;
10593
+ updated = [...current, value];
10594
+ }
10595
+ if (!isControlled) setInternal(updated);
10596
+ onSelect?.(updated);
10597
+ },
10598
+ [current, isControlled, max, minSelection, onSelect]
10599
+ );
10600
+ return /* @__PURE__ */ jsx(
10601
+ "fieldset",
10602
+ {
10603
+ className: cn(
10604
+ "grid w-full grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4",
10605
+ className
10606
+ ),
10607
+ children: options.map((option) => /* @__PURE__ */ jsx(
10608
+ MediaOptionItem,
10609
+ {
10610
+ option,
10611
+ isChecked: current.includes(option.value),
10612
+ onToggle: toggleOption,
10613
+ thumbnailHeight
10614
+ },
10615
+ option.value
10616
+ ))
10617
+ }
10618
+ );
10619
+ }
10620
+ function renderTileIcon(item) {
10621
+ if (item.icon != null) {
10622
+ if (isValidElement(item.icon)) {
10623
+ return cloneElement(item.icon, {
10624
+ className: cn(item.icon.props.className, "size-5 shrink-0")
10625
+ });
10626
+ }
10627
+ return item.icon;
10628
+ }
10629
+ return resolveIconName(item.iconName);
10630
+ }
10631
+ function IconCheckboxes({
10632
+ options,
10633
+ selectedValues,
10634
+ defaultSelectedValues,
10635
+ onSelect,
10636
+ minSelection = 0,
10637
+ maxSelection,
10638
+ className
10639
+ }) {
10640
+ const isControlled = Array.isArray(selectedValues);
10641
+ const [internal, setInternal] = useState(
10642
+ defaultSelectedValues ?? []
10643
+ );
10644
+ const current = isControlled ? selectedValues : internal;
10645
+ const max = maxSelection ?? options.length;
10646
+ const commit = (updated) => {
10647
+ if (!isControlled) setInternal(updated);
10648
+ onSelect?.(updated);
10649
+ };
10650
+ const toggleOption = (value) => {
10651
+ const isSelected = current.includes(value);
10652
+ let updated;
10653
+ if (isSelected) {
10654
+ updated = current.filter((v) => v !== value);
10655
+ if (updated.length < minSelection) return;
10656
+ } else if (max === 1) {
10657
+ updated = [value];
10658
+ } else {
10659
+ if (current.length >= max) return;
10660
+ updated = [...current, value];
10661
+ }
10662
+ commit(updated);
10663
+ };
10664
+ return /* @__PURE__ */ jsx(
10665
+ "fieldset",
10666
+ {
10667
+ className: cn(
10668
+ "grid w-full max-w-sm grid-cols-[repeat(auto-fit,minmax(7rem,1fr))] gap-3",
10669
+ className
10670
+ ),
10671
+ children: options.map((item) => {
10672
+ const { value, label, disabled } = item;
10673
+ const isChecked = current.includes(value);
10674
+ return /* @__PURE__ */ jsxs(
10675
+ "label",
10676
+ {
10677
+ className: cn(
10678
+ "block",
10679
+ disabled ? "cursor-not-allowed opacity-60" : "cursor-pointer"
10680
+ ),
10681
+ children: [
10682
+ /* @__PURE__ */ jsx(
10683
+ "input",
10684
+ {
10685
+ type: "checkbox",
10686
+ className: "peer sr-only",
10687
+ checked: isChecked,
10688
+ disabled,
10689
+ onChange: () => toggleOption(value)
10690
+ }
10691
+ ),
10692
+ /* @__PURE__ */ jsxs(
10693
+ "span",
10694
+ {
10695
+ className: cn(
10696
+ "relative flex min-h-[88px] flex-col items-start justify-center rounded-lg border bg-card px-4 py-3 text-left text-muted-foreground transition-all duration-200 ease-in-out",
10697
+ "border-input hover:border-border hover:bg-accent/40",
10698
+ "peer-focus-visible:ring-2 peer-focus-visible:ring-ring peer-focus-visible:ring-offset-2 peer-focus-visible:ring-offset-background",
10699
+ isChecked && "border-primary bg-primary/5 text-primary shadow-xs ring-1 ring-primary/20 hover:border-primary hover:bg-primary/5",
10700
+ disabled && "pointer-events-none"
10701
+ ),
10702
+ children: [
10703
+ /* @__PURE__ */ jsx(
10704
+ "span",
10705
+ {
10706
+ "aria-hidden": "true",
10707
+ className: "mb-3 flex size-5 items-center justify-center",
10708
+ children: renderTileIcon(item)
10709
+ }
10710
+ ),
10711
+ /* @__PURE__ */ jsx("span", { className: "w-full break-words text-sm font-medium leading-tight transition-colors duration-200 ease-in-out", children: label }),
10712
+ /* @__PURE__ */ jsx(
10713
+ CircleCheck,
10714
+ {
10715
+ "aria-hidden": "true",
10716
+ className: cn(
10717
+ "absolute right-2 top-2 size-5 rounded-full fill-primary text-primary-foreground transition-all duration-200 ease-in-out",
10718
+ isChecked ? "scale-100 opacity-100" : "scale-75 opacity-0"
10719
+ )
10720
+ }
10721
+ )
10722
+ ]
10723
+ }
10724
+ )
10725
+ ]
10726
+ },
10727
+ value
10728
+ );
10729
+ })
10730
+ }
10731
+ );
10732
+ }
9926
10733
  var ARTIFACT_REGISTRY = {
9927
10734
  chart: ({ payload, className }) => payload.chart ? /* @__PURE__ */ jsx(ChartContainer, { data: payload.chart, className }) : null,
9928
10735
  metrics: ({ payload, className }) => payload.metrics ? /* @__PURE__ */ jsx(MetricsGrid, { metrics: payload.metrics, className }) : null,
@@ -9940,7 +10747,10 @@ var ARTIFACT_REGISTRY = {
9940
10747
  "deep-research-progress": ({ payload, className }) => payload.deepResearchProgress ? /* @__PURE__ */ jsx(DeepResearchProgress, { ...payload.deepResearchProgress, className }) : null,
9941
10748
  tracker: ({ payload, className }) => payload.tracker ? /* @__PURE__ */ jsx(Tracker, { ...payload.tracker, className }) : null,
9942
10749
  "built-in-questions": ({ payload, className }) => payload.builtInQuestions ? /* @__PURE__ */ jsx(BuiltInQuestions, { ...payload.builtInQuestions, className }) : null,
9943
- "audio-player": ({ payload, className }) => payload.audioPlayer ? /* @__PURE__ */ jsx(AudioPlayer, { ...payload.audioPlayer, className }) : null
10750
+ "audio-player": ({ payload, className }) => payload.audioPlayer ? /* @__PURE__ */ jsx(AudioPlayer, { ...payload.audioPlayer, className }) : null,
10751
+ "link-input": ({ payload, className }) => payload.linkInput ? /* @__PURE__ */ jsx(LinkInput, { ...payload.linkInput, className }) : null,
10752
+ "media-checkboxes": ({ payload, className }) => payload.mediaCheckboxes ? /* @__PURE__ */ jsx(MediaCheckboxes, { ...payload.mediaCheckboxes, className }) : null,
10753
+ "icon-checkboxes": ({ payload, className }) => payload.iconCheckboxes ? /* @__PURE__ */ jsx(IconCheckboxes, { ...payload.iconCheckboxes, className }) : null
9944
10754
  };
9945
10755
  function DataPayloadView({ payload, className }) {
9946
10756
  const render = ARTIFACT_REGISTRY[payload.type];
@@ -11370,6 +12180,6 @@ function AgentWorkspaceSkeleton({
11370
12180
  );
11371
12181
  }
11372
12182
 
11373
- export { AgentAvatar, AgentComposer, AgentConversation, AgentHandoff, AgentProvider, AgentSurface, AgentWorkspace, AgentWorkspaceComposer, AgentWorkspacePanelToggle, AgentWorkspaceSkeleton, AllocationBreakdown, AnalyticsDashboard, AudioPlayer, Avatar, AvatarFallback, AvatarImage, Badge, BadgesArtifact, BuiltInQuestions, Button, ChartContainer, ChatPanel, Collapsible, CollapsibleContent2 as CollapsibleContent, CollapsibleTrigger2 as CollapsibleTrigger, ConfirmationPanel, ControlGrid, ConversationAnalytics, ConversationArtifact, DataPayloadView, DataTable, DeepResearchProgress, DynamicRenderer, EntityCard, FileDropZone, FloatingWidget, FullBleedSurface, FullscreenDashboard, GuidedLessonFlow, ImageGenerator, InlineSuggestionsInput, Input, KpiCardWithChart, KpiCardWithSparklines, ListingFeed, LocationsRevenueCard, MediaEditorCanvas, MediaGallery, MessageActions, MessageBubble, MessageContainer, MessageContent, MessageList, MessageWithAttachments, MessageWithFeedback, MessageWithReasoning, MessageWithSteps, MetricsGrid, MobileShell, MultimodalInput, NativeAgentProvider, NativeSurface, OnboardingWizard, OptionCards, OrderedListArtifact, OverlayModal, PerformanceMetrics, PersonaSelector, PieChartArtifact, Progress, ProgressTracker, PromptInput, PromptLibrary, QuickReplies, QuizCard, RecommendationCards, ReportView, RowBasedDataList, ScheduleTimeline, ScrollArea, ScrollBar, SemanticBuilderSocketClient, SentimentDisplay, SettingsPanel, SlotRenderer, SplitView, StackedSparklines, StatCardHalfCircle, StatusBadge, SystemMessage, TableListArtifact, TemplateSelector, Textarea, Timestamp, Tooltip4 as Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, Tracker, TypingIndicator, WritingAssistant, badgeVariants, buildSocketUrl, buttonVariants, calculatePercentage, cn, componentManifest, componentMap, componentRegistry, copyToClipboard, createMockBackend, debounce, delay, findComponentsByCapability, findComponentsByCategory, findComponentsBySurface, formatBytes, formatCurrency, formatNumber, formatRelativeTime, formatTime, generateId, getInitials, getManifestEntry, getSentimentBgColor, getSentimentColor, isBrowser, isInIframe, normalizeWebsiteId, parseTextWithBold, registerAllComponents, truncate, useAgent, useAgentBackend, useAgentInput, useAgentLayout, useAgentMessages, useAgentWorkspace, useAgentWorkspaceOptional, useNativeAgent, useNativeAgentOptional, useSemanticBuilder };
12183
+ export { AgentAvatar, AgentComposer, AgentConversation, AgentHandoff, AgentProvider, AgentSurface, AgentWorkspace, AgentWorkspaceComposer, AgentWorkspacePanelToggle, AgentWorkspaceSkeleton, AllocationBreakdown, AnalyticsDashboard, AudioPlayer, Avatar, AvatarFallback, AvatarImage, Badge, BadgesArtifact, BuiltInQuestions, Button, ChartContainer, ChatPanel, Collapsible, CollapsibleContent2 as CollapsibleContent, CollapsibleTrigger2 as CollapsibleTrigger, ConfirmationPanel, ControlGrid, ConversationAnalytics, ConversationArtifact, DEFAULT_OPEN_GRAPH_ENDPOINT, DataPayloadView, DataTable, DeepResearchProgress, DynamicRenderer, EntityCard, FileDropZone, FloatingWidget, FullBleedSurface, FullscreenDashboard, GuidedLessonFlow, IconCheckboxes, ImageGenerator, InlineSuggestionsInput, Input, KpiCardWithChart, KpiCardWithSparklines, LinkInput, LinkInputGroup, ListingFeed, LocationsRevenueCard, MediaCheckboxes, MediaEditorCanvas, MediaGallery, MessageActions, MessageBubble, MessageContainer, MessageContent, MessageList, MessageWithAttachments, MessageWithFeedback, MessageWithReasoning, MessageWithSteps, MetricsGrid, MobileShell, MultimodalInput, NativeAgentProvider, NativeSurface, OnboardingWizard, OptionCards, OrderedListArtifact, OverlayModal, PerformanceMetrics, PersonaSelector, PieChartArtifact, Progress, ProgressTracker, PromptInput, PromptLibrary, QuickReplies, QuizCard, RecommendationCards, ReportView, RowBasedDataList, ScheduleTimeline, ScrollArea, ScrollBar, SemanticBuilderSocketClient, SentimentDisplay, SettingsPanel, SlotRenderer, SplitView, StackedSparklines, StatCardHalfCircle, StatusBadge, SystemMessage, TableListArtifact, TemplateSelector, Textarea, Timestamp, Tooltip4 as Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, Tracker, TypingIndicator, WritingAssistant, badgeVariants, buildSocketUrl, buttonVariants, calculatePercentage, cn, componentManifest, componentMap, componentRegistry, copyToClipboard, createMockBackend, debounce, delay, extractLinkPreview, fetchOpenGraphPreview, findComponentsByCapability, findComponentsByCategory, findComponentsBySurface, formatBytes, formatCurrency, formatNumber, formatRelativeTime, formatTime, generateId, getInitials, getManifestEntry, getSentimentBgColor, getSentimentColor, isBrowser, isInIframe, normalizeWebsiteId, parseTextWithBold, registerAllComponents, truncate, useAgent, useAgentBackend, useAgentInput, useAgentLayout, useAgentMessages, useAgentWorkspace, useAgentWorkspaceOptional, useNativeAgent, useNativeAgentOptional, useSemanticBuilder };
11374
12184
  //# sourceMappingURL=index.js.map
11375
12185
  //# sourceMappingURL=index.js.map