@bysages/react 0.4.3 → 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/dist/ai-B3vbpXlK.mjs +309 -0
- package/dist/ai-prompt-input-k34KssHJ.mjs +401 -0
- package/dist/{ai-response-CjjjprMY.mjs → ai-response-DTxdL5rX.mjs} +9 -11
- package/dist/{chevron-BA7kV9m7.mjs → chevron-DnImlNip.mjs} +2 -3
- package/dist/components/accordion/index.d.mts +1 -2
- package/dist/components/accordion/index.mjs +3 -4
- package/dist/components/affix/index.d.mts +1 -2
- package/dist/components/affix/index.mjs +2 -3
- package/dist/components/ai/index.d.mts +107 -2
- package/dist/components/ai/index.mjs +7 -82
- package/dist/components/ai-action/index.d.mts +0 -2
- package/dist/components/ai-action/index.mjs +2 -3
- package/dist/components/ai-attachments/index.d.mts +0 -2
- package/dist/components/ai-attachments/index.mjs +4 -5
- package/dist/components/ai-message/index.d.mts +2 -14
- package/dist/components/ai-message/index.mjs +5 -4
- package/dist/components/ai-prompt-input/index.d.mts +14 -18
- package/dist/components/ai-prompt-input/index.mjs +1 -126
- package/dist/components/ai-reasoning/index.d.mts +0 -2
- package/dist/components/ai-reasoning/index.mjs +3 -4
- package/dist/components/ai-response/index.d.mts +1 -3
- package/dist/components/ai-response/index.mjs +1 -2
- package/dist/components/ai-source/index.d.mts +0 -2
- package/dist/components/ai-source/index.mjs +2 -3
- package/dist/components/ai-suggestion/index.d.mts +0 -2
- package/dist/components/ai-suggestion/index.mjs +2 -3
- package/dist/components/ai-tool/index.d.mts +2 -24
- package/dist/components/ai-tool/index.mjs +46 -14
- package/dist/components/alert/index.d.mts +1 -2
- package/dist/components/alert/index.mjs +2 -3
- package/dist/components/angle-slider/index.d.mts +1 -2
- package/dist/components/angle-slider/index.mjs +2 -3
- package/dist/components/aspect-ratio/index.d.mts +1 -2
- package/dist/components/aspect-ratio/index.mjs +2 -3
- package/dist/components/autocomplete/index.d.mts +1 -2
- package/dist/components/autocomplete/index.mjs +3 -4
- package/dist/components/avatar/index.d.mts +13 -4
- package/dist/components/avatar/index.mjs +20 -6
- package/dist/components/avatar-group/index.d.mts +1 -2
- package/dist/components/avatar-group/index.mjs +2 -3
- package/dist/components/back-top/index.d.mts +1 -2
- package/dist/components/back-top/index.mjs +3 -4
- package/dist/components/badge/index.d.mts +1 -2
- package/dist/components/badge/index.mjs +2 -3
- package/dist/components/banner/index.d.mts +17 -4
- package/dist/components/banner/index.mjs +21 -6
- package/dist/components/bento/index.d.mts +1 -3
- package/dist/components/bento/index.mjs +1 -2
- package/dist/components/block-ui/index.d.mts +1 -2
- package/dist/components/block-ui/index.mjs +2 -3
- package/dist/components/breadcrumb/index.d.mts +16 -3
- package/dist/components/breadcrumb/index.mjs +22 -5
- package/dist/components/browser/index.d.mts +1 -3
- package/dist/components/browser/index.mjs +1 -2
- package/dist/components/button/index.d.mts +1 -2
- package/dist/components/button/index.mjs +2 -3
- package/dist/components/button-group/index.d.mts +1 -2
- package/dist/components/button-group/index.mjs +1 -2
- package/dist/components/calendar/index.d.mts +1 -2
- package/dist/components/calendar/index.mjs +3 -4
- package/dist/components/card/index.d.mts +1 -3
- package/dist/components/card/index.mjs +1 -2
- package/dist/components/carousel/index.d.mts +1 -2
- package/dist/components/carousel/index.mjs +3 -4
- package/dist/components/cascade-select/index.d.mts +1 -2
- package/dist/components/cascade-select/index.mjs +6 -7
- package/dist/components/checkbox/index.d.mts +1 -2
- package/dist/components/checkbox/index.mjs +3 -4
- package/dist/components/checkbox-group/index.d.mts +1 -2
- package/dist/components/checkbox-group/index.mjs +3 -4
- package/dist/components/chip/index.d.mts +1 -2
- package/dist/components/chip/index.mjs +2 -3
- package/dist/components/client-only/index.d.mts +0 -2
- package/dist/components/client-only/index.mjs +2 -3
- package/dist/components/clipboard/index.d.mts +1 -2
- package/dist/components/clipboard/index.mjs +3 -4
- package/dist/components/collapsible/index.d.mts +1 -2
- package/dist/components/collapsible/index.mjs +3 -4
- package/dist/components/collection/index.mjs +1 -2
- package/dist/components/color-picker/index.d.mts +3 -2
- package/dist/components/color-picker/index.mjs +38 -25
- package/dist/components/combobox/index.d.mts +1 -2
- package/dist/components/combobox/index.mjs +3 -4
- package/dist/components/command/index.d.mts +1 -2
- package/dist/components/command/index.mjs +3 -4
- package/dist/components/comment/index.d.mts +1 -2
- package/dist/components/comment/index.mjs +2 -3
- package/dist/components/config-provider/index.d.mts +1 -2
- package/dist/components/config-provider/index.mjs +2 -3
- package/dist/components/container/index.d.mts +1 -2
- package/dist/components/container/index.mjs +2 -3
- package/dist/components/data-view/index.d.mts +1 -2
- package/dist/components/data-view/index.mjs +3 -4
- package/dist/components/date-input/index.d.mts +0 -2
- package/dist/components/date-input/index.mjs +2 -3
- package/dist/components/date-picker/index.d.mts +0 -2
- package/dist/components/date-picker/index.mjs +3 -4
- package/dist/components/deferred-content/index.d.mts +1 -2
- package/dist/components/deferred-content/index.mjs +2 -3
- package/dist/components/descriptions/index.d.mts +1 -2
- package/dist/components/descriptions/index.mjs +2 -3
- package/dist/components/dialog/index.d.mts +31 -4
- package/dist/components/dialog/index.mjs +41 -10
- package/dist/components/dock/index.d.mts +1 -3
- package/dist/components/dock/index.mjs +1 -2
- package/dist/components/download-trigger/index.d.mts +0 -2
- package/dist/components/download-trigger/index.mjs +2 -3
- package/dist/components/drawer/index.d.mts +1 -2
- package/dist/components/drawer/index.mjs +3 -4
- package/dist/components/dynamic-input/index.d.mts +1 -2
- package/dist/components/dynamic-input/index.mjs +5 -6
- package/dist/components/editable/index.d.mts +1 -2
- package/dist/components/editable/index.mjs +3 -4
- package/dist/components/ellipsis/index.d.mts +1 -2
- package/dist/components/ellipsis/index.mjs +2 -3
- package/dist/components/empty/index.d.mts +1 -3
- package/dist/components/empty/index.mjs +1 -2
- package/dist/components/field/index.d.mts +1 -2
- package/dist/components/field/index.mjs +2 -3
- package/dist/components/fieldset/index.d.mts +1 -2
- package/dist/components/fieldset/index.mjs +2 -3
- package/dist/components/file-upload/index.d.mts +1 -2
- package/dist/components/file-upload/index.mjs +4 -9
- package/dist/components/float-button/index.d.mts +23 -3
- package/dist/components/float-button/index.mjs +30 -5
- package/dist/components/floating-panel/index.d.mts +1 -2
- package/dist/components/floating-panel/index.mjs +8 -4
- package/dist/components/focus-trap/index.d.mts +0 -2
- package/dist/components/focus-trap/index.mjs +2 -3
- package/dist/components/form/index.d.mts +0 -2
- package/dist/components/form/index.mjs +2 -3
- package/dist/components/format/index.d.mts +1 -3
- package/dist/components/format/index.mjs +1 -2
- package/dist/components/frame/index.d.mts +1 -3
- package/dist/components/frame/index.mjs +3 -4
- package/dist/components/grid/index.d.mts +1 -2
- package/dist/components/grid/index.mjs +2 -3
- package/dist/components/highlight/index.d.mts +1 -3
- package/dist/components/highlight/index.mjs +2 -3
- package/dist/components/hover-card/index.d.mts +1 -2
- package/dist/components/hover-card/index.mjs +2 -3
- package/dist/components/icon/index.d.mts +1 -2
- package/dist/components/icon/index.mjs +2 -3
- package/dist/components/image/index.d.mts +1 -2
- package/dist/components/image/index.mjs +3 -4
- package/dist/components/image-cropper/index.d.mts +1 -2
- package/dist/components/image-cropper/index.mjs +2 -3
- package/dist/components/image-viewer/index.d.mts +1 -1
- package/dist/components/image-viewer/index.mjs +1 -2
- package/dist/components/input/index.d.mts +1 -3
- package/dist/components/input/index.mjs +1 -2
- package/dist/components/input-group/index.d.mts +1 -3
- package/dist/components/input-group/index.mjs +1 -2
- package/dist/components/json-tree-view/index.d.mts +1 -2
- package/dist/components/json-tree-view/index.mjs +3 -4
- package/dist/components/kbd/index.d.mts +1 -2
- package/dist/components/kbd/index.mjs +2 -3
- package/dist/components/layout/index.d.mts +1 -2
- package/dist/components/layout/index.mjs +19 -15
- package/dist/components/link/index.d.mts +1 -2
- package/dist/components/link/index.mjs +2 -3
- package/dist/components/list/index.d.mts +1 -2
- package/dist/components/list/index.mjs +1 -2
- package/dist/components/listbox/index.d.mts +0 -2
- package/dist/components/listbox/index.mjs +3 -4
- package/dist/components/marquee/index.d.mts +1 -2
- package/dist/components/marquee/index.mjs +2 -3
- package/dist/components/masonry/index.d.mts +1 -2
- package/dist/components/masonry/index.mjs +2 -3
- package/dist/components/media-player/index.d.mts +1 -1
- package/dist/components/media-player/index.mjs +1 -2
- package/dist/components/mentions/index.d.mts +2 -2
- package/dist/components/mentions/index.mjs +1 -2
- package/dist/components/menu/index.d.mts +1 -2
- package/dist/components/menu/index.mjs +3 -4
- package/dist/components/menubar/index.d.mts +1 -2
- package/dist/components/menubar/index.mjs +2 -3
- package/dist/components/meter/index.d.mts +1 -3
- package/dist/components/meter/index.mjs +1 -2
- package/dist/components/navigation-menu/index.d.mts +1 -2
- package/dist/components/navigation-menu/index.mjs +2 -3
- package/dist/components/number-input/index.d.mts +1 -2
- package/dist/components/number-input/index.mjs +3 -4
- package/dist/components/order-list/index.d.mts +1 -2
- package/dist/components/order-list/index.mjs +4 -5
- package/dist/components/page-header/index.d.mts +1 -3
- package/dist/components/page-header/index.mjs +1 -2
- package/dist/components/pagination/index.d.mts +3 -4
- package/dist/components/pagination/index.mjs +3 -4
- package/dist/components/password-input/index.d.mts +1 -2
- package/dist/components/password-input/index.mjs +3 -4
- package/dist/components/pin-input/index.d.mts +1 -2
- package/dist/components/pin-input/index.mjs +2 -3
- package/dist/components/popconfirm/index.d.mts +2 -3
- package/dist/components/popconfirm/index.mjs +2 -3
- package/dist/components/popover/index.d.mts +1 -1
- package/dist/components/popover/index.mjs +3 -4
- package/dist/components/presence/index.d.mts +0 -2
- package/dist/components/presence/index.mjs +2 -3
- package/dist/components/progress/index.d.mts +1 -2
- package/dist/components/progress/index.mjs +2 -3
- package/dist/components/progress-group/index.d.mts +1 -2
- package/dist/components/progress-group/index.mjs +2 -3
- package/dist/components/qr-code/index.d.mts +1 -2
- package/dist/components/qr-code/index.mjs +2 -3
- package/dist/components/radio-group/index.d.mts +1 -2
- package/dist/components/radio-group/index.mjs +2 -3
- package/dist/components/rating-group/index.d.mts +1 -2
- package/dist/components/rating-group/index.mjs +3 -4
- package/dist/components/result/index.d.mts +1 -2
- package/dist/components/result/index.mjs +2 -3
- package/dist/components/scroll-area/index.d.mts +8 -3
- package/dist/components/scroll-area/index.mjs +7 -6
- package/dist/components/segment-group/index.d.mts +1 -2
- package/dist/components/segment-group/index.mjs +2 -3
- package/dist/components/select/index.d.mts +1 -1
- package/dist/components/select/index.mjs +1 -2
- package/dist/components/separator/index.d.mts +1 -2
- package/dist/components/separator/index.mjs +2 -3
- package/dist/components/signature-pad/index.d.mts +1 -2
- package/dist/components/signature-pad/index.mjs +3 -4
- package/dist/components/skeleton/index.d.mts +1 -2
- package/dist/components/skeleton/index.mjs +2 -3
- package/dist/components/slider/index.d.mts +1 -2
- package/dist/components/slider/index.mjs +2 -3
- package/dist/components/spinner/index.d.mts +1 -2
- package/dist/components/spinner/index.mjs +3 -4
- package/dist/components/split-button/index.d.mts +1 -2
- package/dist/components/split-button/index.mjs +4 -5
- package/dist/components/splitter/index.d.mts +1 -2
- package/dist/components/splitter/index.mjs +2 -3
- package/dist/components/spotlight/index.d.mts +1 -2
- package/dist/components/spotlight/index.mjs +2 -3
- package/dist/components/stack/index.d.mts +1 -2
- package/dist/components/stack/index.mjs +2 -3
- package/dist/components/stat/index.d.mts +1 -3
- package/dist/components/stat/index.mjs +1 -2
- package/dist/components/steps/index.d.mts +0 -2
- package/dist/components/steps/index.mjs +2 -3
- package/dist/components/swap/index.d.mts +1 -2
- package/dist/components/swap/index.mjs +3 -4
- package/dist/components/switch/index.d.mts +1 -2
- package/dist/components/switch/index.mjs +2 -3
- package/dist/components/table/index.d.mts +0 -2
- package/dist/components/table/index.mjs +5 -6
- package/dist/components/tabs/index.d.mts +9 -3
- package/dist/components/tabs/index.mjs +36 -8
- package/dist/components/tag/index.d.mts +1 -2
- package/dist/components/tag/index.mjs +3 -4
- package/dist/components/tags-input/index.d.mts +1 -2
- package/dist/components/tags-input/index.mjs +3 -4
- package/dist/components/terminal/index.d.mts +4 -3
- package/dist/components/terminal/index.mjs +8 -7
- package/dist/components/textarea/index.d.mts +1 -2
- package/dist/components/textarea/index.mjs +2 -3
- package/dist/components/timeline/index.d.mts +1 -2
- package/dist/components/timeline/index.mjs +1 -2
- package/dist/components/timer/index.d.mts +1 -2
- package/dist/components/timer/index.mjs +2 -3
- package/dist/components/toast/index.d.mts +0 -2
- package/dist/components/toast/index.mjs +18 -6
- package/dist/components/toc/index.d.mts +1 -2
- package/dist/components/toc/index.mjs +2 -3
- package/dist/components/toggle/index.d.mts +1 -2
- package/dist/components/toggle/index.mjs +2 -3
- package/dist/components/toggle-group/index.d.mts +1 -2
- package/dist/components/toggle-group/index.mjs +3 -4
- package/dist/components/toolbar/index.d.mts +1 -2
- package/dist/components/toolbar/index.mjs +2 -3
- package/dist/components/tooltip/index.d.mts +1 -2
- package/dist/components/tooltip/index.mjs +2 -3
- package/dist/components/tour/index.d.mts +0 -2
- package/dist/components/tour/index.mjs +2 -3
- package/dist/components/transfer/index.d.mts +1 -2
- package/dist/components/transfer/index.mjs +5 -6
- package/dist/components/tree-select/index.d.mts +2 -3
- package/dist/components/tree-select/index.mjs +5 -6
- package/dist/components/tree-view/index.d.mts +15 -5
- package/dist/components/tree-view/index.mjs +30 -12
- package/dist/components/typography/index.d.mts +1 -3
- package/dist/components/typography/index.mjs +1 -2
- package/dist/components/user/index.d.mts +1 -2
- package/dist/components/user/index.mjs +2 -3
- package/dist/components/virtual-list/index.d.mts +1 -2
- package/dist/components/virtual-list/index.mjs +2 -3
- package/dist/components/watermark/index.d.mts +1 -2
- package/dist/components/watermark/index.mjs +2 -3
- package/dist/{family-DE_GQeeM.mjs → family-Co1YsN4N.mjs} +1 -2
- package/dist/generative/index.d.mts +0 -2
- package/dist/generative/index.mjs +146 -106
- package/dist/{icon-Cri0-7-x.mjs → icon-C9udWCyz.mjs} +1 -2
- package/dist/{id-C37UYLwJ.mjs → id-Ctic_3o8.mjs} +1 -2
- package/dist/{image-viewer-D4FuYrk6.mjs → image-viewer-BYiXpi1X.mjs} +21 -26
- package/dist/{index-Eu-Bttta.d.mts → index-BVdkcSSY.d.mts} +0 -2
- package/dist/index-CjO4Ggf0.d.mts +115 -0
- package/dist/{index-Dj8S4eyJ.d.mts → index-D4C52fI7.d.mts} +0 -4
- package/dist/{index-BcRdWGY-.d.mts → index-DIZEFqJM.d.mts} +0 -8
- package/dist/{index-Bbg4heDO.d.mts → index-DcpvCyt6.d.mts} +63 -18
- package/dist/{index-D_iKc2Uw.d.mts → index-DczfbPCg.d.mts} +0 -4
- package/dist/index-lCsvE2Vl.d.mts +37 -0
- package/dist/index.d.mts +14 -14
- package/dist/index.mjs +10 -10
- package/dist/{input-BDpQ0e6G.mjs → input-YRjehBhU.mjs} +3 -5
- package/dist/{media-player-C0WcjVI-.mjs → media-player-CO2Cczl-.mjs} +7 -12
- package/dist/mentions-De7ChJbl.mjs +335 -0
- package/dist/{messages-1jJWtaYU.mjs → messages-B6n0lVyt.mjs} +1 -2
- package/dist/{select-D_soVdWK.mjs → select-DQ5669_K.mjs} +4 -6
- package/package.json +17 -17
- package/dist/index-B4twHAQC.d.mts +0 -10456
- package/dist/mentions-BwnyvdXz.mjs +0 -213
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { r as iconNode } from "./icon-C9udWCyz.mjs";
|
|
2
|
+
import { t as withSelfRoot } from "./family-Co1YsN4N.mjs";
|
|
3
|
+
import { n as useComponentMessages } from "./messages-B6n0lVyt.mjs";
|
|
4
|
+
import { Action } from "./components/ai-action/index.mjs";
|
|
5
|
+
import { AiMessage as Message } from "./components/ai-message/index.mjs";
|
|
6
|
+
import { t as PromptInput } from "./ai-prompt-input-k34KssHJ.mjs";
|
|
7
|
+
import { AiReasoning as Reasoning } from "./components/ai-reasoning/index.mjs";
|
|
8
|
+
import { t as Response } from "./ai-response-DTxdL5rX.mjs";
|
|
9
|
+
import { AiSource as Source, AiSources as Sources } from "./components/ai-source/index.mjs";
|
|
10
|
+
import { AiSuggestion as Suggestion } from "./components/ai-suggestion/index.mjs";
|
|
11
|
+
import { AiTool as Tool } from "./components/ai-tool/index.mjs";
|
|
12
|
+
import { createConversationFollower } from "@bysages/core";
|
|
13
|
+
import { injectComponentStyle } from "@bysages/core/styling";
|
|
14
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
import { Fragment as Fragment$1, useCallback, useEffect, useRef, useState } from "react";
|
|
16
|
+
// src/components/ai/parts.tsx
|
|
17
|
+
const mediaKind = (mediaType) => {
|
|
18
|
+
const family = mediaType.split("/")[0];
|
|
19
|
+
if (family === "image") return "image";
|
|
20
|
+
if (family === "audio") return "audio";
|
|
21
|
+
if (family === "video") return "video";
|
|
22
|
+
return "file";
|
|
23
|
+
};
|
|
24
|
+
function toolPartDisplay(part) {
|
|
25
|
+
const name = part.type === "dynamic-tool" ? part.toolName : part.type.slice(5);
|
|
26
|
+
const approval = (() => {
|
|
27
|
+
if (part.state === "approval-requested") return "required";
|
|
28
|
+
if (part.state === "approval-responded") return part.approval.approved ? "approved" : "denied";
|
|
29
|
+
if (part.state === "output-denied") return "denied";
|
|
30
|
+
})();
|
|
31
|
+
return {
|
|
32
|
+
name,
|
|
33
|
+
status: (() => {
|
|
34
|
+
if (part.state === "input-streaming") return "pending";
|
|
35
|
+
if (part.state === "input-available") return "running";
|
|
36
|
+
if (part.state === "approval-requested") return "running";
|
|
37
|
+
if (part.state === "approval-responded") return "running";
|
|
38
|
+
if (part.state === "output-available") return "completed";
|
|
39
|
+
if (part.state === "output-error") return "error";
|
|
40
|
+
return "denied";
|
|
41
|
+
})(),
|
|
42
|
+
approval,
|
|
43
|
+
input: part.input,
|
|
44
|
+
output: part.state === "output-error" ? part.errorText : part.output
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const fileLabel = (part) => "filename" in part && part.filename ? part.filename : part.mediaType;
|
|
48
|
+
const fileLink = (part) => /* @__PURE__ */ jsxs("a", {
|
|
49
|
+
"data-scope": "ai",
|
|
50
|
+
"data-part": "file-link",
|
|
51
|
+
href: part.url,
|
|
52
|
+
target: "_blank",
|
|
53
|
+
rel: "noreferrer",
|
|
54
|
+
children: [iconNode("file"), /* @__PURE__ */ jsx("span", { children: fileLabel(part) })]
|
|
55
|
+
});
|
|
56
|
+
const slotContent = (content) => content ?? null;
|
|
57
|
+
const isTextPart = (part) => part.type === "text";
|
|
58
|
+
const isCustomPart = (part) => part.type === "custom";
|
|
59
|
+
const isReasoningPart = (part) => part.type === "reasoning";
|
|
60
|
+
const isReasoningFilePart = (part) => part.type === "reasoning-file";
|
|
61
|
+
const isFilePart = (part) => part.type === "file";
|
|
62
|
+
const isSourceUrlPart = (part) => part.type === "source-url";
|
|
63
|
+
const isSourceDocumentPart = (part) => part.type === "source-document";
|
|
64
|
+
const isToolPart = (part) => part.type === "dynamic-tool" || part.type.startsWith("tool-");
|
|
65
|
+
const isDataPart = (part) => part.type.startsWith("data-");
|
|
66
|
+
const isStepStartPart = (part) => part.type === "step-start";
|
|
67
|
+
const AiMedia = withSelfRoot(function AiMedia(props) {
|
|
68
|
+
injectComponentStyle("ai");
|
|
69
|
+
const shown = props.part ?? (props.mediaType && props.url ? {
|
|
70
|
+
type: "file",
|
|
71
|
+
mediaType: props.mediaType,
|
|
72
|
+
url: props.url,
|
|
73
|
+
...props.filename ? { filename: props.filename } : {}
|
|
74
|
+
} : null);
|
|
75
|
+
if (!shown) return null;
|
|
76
|
+
const kind = mediaKind(shown.mediaType);
|
|
77
|
+
const label = fileLabel(shown);
|
|
78
|
+
return /* @__PURE__ */ jsx("figure", {
|
|
79
|
+
"data-scope": "ai",
|
|
80
|
+
"data-part": "media",
|
|
81
|
+
"data-kind": kind,
|
|
82
|
+
children: kind === "image" ? /* @__PURE__ */ jsx("img", {
|
|
83
|
+
src: shown.url,
|
|
84
|
+
alt: props.alt ?? (label === shown.mediaType ? "" : label)
|
|
85
|
+
}) : kind === "audio" ? /* @__PURE__ */ jsx("audio", {
|
|
86
|
+
src: shown.url,
|
|
87
|
+
controls: true
|
|
88
|
+
}) : kind === "video" ? /* @__PURE__ */ jsx("video", {
|
|
89
|
+
src: shown.url,
|
|
90
|
+
controls: true
|
|
91
|
+
}) : fileLink(shown)
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
const source = (part) => "url" in part ? /* @__PURE__ */ jsx(Sources, { children: /* @__PURE__ */ jsx(Source, {
|
|
95
|
+
href: part.url,
|
|
96
|
+
children: part.title ?? part.url
|
|
97
|
+
}) }) : /* @__PURE__ */ jsx(Sources, { children: /* @__PURE__ */ jsxs("li", {
|
|
98
|
+
"data-scope": "ai",
|
|
99
|
+
"data-part": "document-source",
|
|
100
|
+
children: [/* @__PURE__ */ jsx("span", { children: part.title }), /* @__PURE__ */ jsx("span", { children: part.mediaType })]
|
|
101
|
+
}) });
|
|
102
|
+
function AiPartsRenderer(props) {
|
|
103
|
+
injectComponentStyle("ai");
|
|
104
|
+
const renderPart = (part, index) => {
|
|
105
|
+
if (isTextPart(part)) {
|
|
106
|
+
const custom = slotContent(props.slots?.text?.({
|
|
107
|
+
part,
|
|
108
|
+
index
|
|
109
|
+
}));
|
|
110
|
+
if (custom) return custom;
|
|
111
|
+
return part.text ? /* @__PURE__ */ jsx(Response, {
|
|
112
|
+
content: part.text,
|
|
113
|
+
highlighter: props.highlighter
|
|
114
|
+
}) : null;
|
|
115
|
+
}
|
|
116
|
+
if (isReasoningPart(part)) {
|
|
117
|
+
const custom = slotContent(props.slots?.reasoning?.({
|
|
118
|
+
part,
|
|
119
|
+
index
|
|
120
|
+
}));
|
|
121
|
+
if (custom) return custom;
|
|
122
|
+
return /* @__PURE__ */ jsx(Reasoning, {
|
|
123
|
+
defaultOpen: part.state === "streaming",
|
|
124
|
+
children: part.text
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
if (isReasoningFilePart(part)) return slotContent(props.slots?.reasoningFile?.({
|
|
128
|
+
part,
|
|
129
|
+
index
|
|
130
|
+
})) ?? /* @__PURE__ */ jsx(AiMedia, { part });
|
|
131
|
+
if (isFilePart(part)) return slotContent(props.slots?.file?.({
|
|
132
|
+
part,
|
|
133
|
+
index
|
|
134
|
+
})) ?? /* @__PURE__ */ jsx(AiMedia, { part });
|
|
135
|
+
if (isSourceUrlPart(part)) return slotContent(props.slots?.sourceUrl?.({
|
|
136
|
+
part,
|
|
137
|
+
index
|
|
138
|
+
})) ?? source(part);
|
|
139
|
+
if (isSourceDocumentPart(part)) return slotContent(props.slots?.sourceDocument?.({
|
|
140
|
+
part,
|
|
141
|
+
index
|
|
142
|
+
})) ?? source(part);
|
|
143
|
+
if (isToolPart(part)) {
|
|
144
|
+
const custom = slotContent(props.slots?.tool?.({
|
|
145
|
+
part,
|
|
146
|
+
index
|
|
147
|
+
}));
|
|
148
|
+
if (custom) return custom;
|
|
149
|
+
const display = toolPartDisplay(part);
|
|
150
|
+
return /* @__PURE__ */ jsx(Tool, {
|
|
151
|
+
name: display.name,
|
|
152
|
+
status: display.status,
|
|
153
|
+
approval: display.approval,
|
|
154
|
+
inputValue: display.input,
|
|
155
|
+
outputValue: display.output,
|
|
156
|
+
defaultOpen: display.status === "error" || display.approval === "required",
|
|
157
|
+
onApprove: () => props.onApprove?.({
|
|
158
|
+
part,
|
|
159
|
+
index
|
|
160
|
+
}),
|
|
161
|
+
onDeny: () => props.onDeny?.({
|
|
162
|
+
part,
|
|
163
|
+
index
|
|
164
|
+
})
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (isStepStartPart(part)) return slotContent(props.slots?.stepStart?.({
|
|
168
|
+
part,
|
|
169
|
+
index
|
|
170
|
+
})) ?? /* @__PURE__ */ jsx("hr", {
|
|
171
|
+
"data-scope": "ai",
|
|
172
|
+
"data-part": "step-start"
|
|
173
|
+
});
|
|
174
|
+
if (isDataPart(part)) return slotContent(props.slots?.data?.({
|
|
175
|
+
part,
|
|
176
|
+
index
|
|
177
|
+
}));
|
|
178
|
+
if (isCustomPart(part)) return slotContent(props.slots?.custom?.({
|
|
179
|
+
part,
|
|
180
|
+
index
|
|
181
|
+
}));
|
|
182
|
+
return slotContent(props.slots?.fallback?.({
|
|
183
|
+
part,
|
|
184
|
+
index
|
|
185
|
+
}));
|
|
186
|
+
};
|
|
187
|
+
const overriddenMessage = slotContent(props.slots?.default?.({ message: props.message }));
|
|
188
|
+
if (overriddenMessage) return overriddenMessage;
|
|
189
|
+
return /* @__PURE__ */ jsx(Fragment, { children: props.message.parts.map((part, index) => /* @__PURE__ */ jsx(Fragment$1, { children: renderPart(part, index) }, index)) });
|
|
190
|
+
}
|
|
191
|
+
const AiParts = withSelfRoot(AiPartsRenderer);
|
|
192
|
+
// src/components/ai/index.tsx
|
|
193
|
+
/** A conversation column: Root is the log, Message carries a role, and
|
|
194
|
+
* the speaking parts — Response, Reasoning, Tool, Sources — part the
|
|
195
|
+
* stream. The interactive folds are the shared Collapsible wearing a
|
|
196
|
+
* `data-ai` marker, so the machine work is never ours. Parts stay
|
|
197
|
+
* agnostic of any client; consumers map their message format (e.g. the
|
|
198
|
+
* `UIMessage` parts re-exported here) onto these primitives. */
|
|
199
|
+
function part(name, tag, extra = {}) {
|
|
200
|
+
const Tag = tag;
|
|
201
|
+
const Component = ({ children, ...rest }) => /* @__PURE__ */ jsx(Tag, {
|
|
202
|
+
...extra,
|
|
203
|
+
...rest,
|
|
204
|
+
"data-scope": "ai",
|
|
205
|
+
"data-part": name.toLowerCase(),
|
|
206
|
+
children
|
|
207
|
+
});
|
|
208
|
+
Component.displayName = "Ai" + name;
|
|
209
|
+
return Component;
|
|
210
|
+
}
|
|
211
|
+
/** The log itself: the column every stroke lands in, a landmark to
|
|
212
|
+
* screen readers. While the reply streams, the log follows its growth —
|
|
213
|
+
* but only while the reader rests at the bottom edge. */
|
|
214
|
+
function AiConversation({ autoScroll = true, children, ...rest }) {
|
|
215
|
+
const messages = useComponentMessages();
|
|
216
|
+
const ref = useRef(null);
|
|
217
|
+
useEffect(() => {
|
|
218
|
+
const node = ref.current;
|
|
219
|
+
if (!node || !autoScroll) return;
|
|
220
|
+
return createConversationFollower(node);
|
|
221
|
+
}, [autoScroll]);
|
|
222
|
+
return /* @__PURE__ */ jsx("div", {
|
|
223
|
+
ref,
|
|
224
|
+
...rest,
|
|
225
|
+
role: "log",
|
|
226
|
+
"aria-label": rest["aria-label"] ?? messages.ai.conversation,
|
|
227
|
+
"data-scope": "ai",
|
|
228
|
+
"data-part": "conversation",
|
|
229
|
+
children
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
/** The optional jump-to-latest door: an explicit part the caller drops
|
|
233
|
+
* inside the conversation when the log scrolls. It watches the log's
|
|
234
|
+
* distance from the bottom edge and surfaces only while the reader is
|
|
235
|
+
* away — clicking returns to the stream. Nothing renders by default. */
|
|
236
|
+
function AiJumpToLatest({ threshold = 96, onJump, children, ...rest }) {
|
|
237
|
+
const messages = useComponentMessages();
|
|
238
|
+
const ref = useRef(null);
|
|
239
|
+
const [visible, setVisible] = useState(false);
|
|
240
|
+
const measure = useCallback(() => {
|
|
241
|
+
const log = ref.current?.closest("[data-scope=\"ai\"][data-part=\"conversation\"]");
|
|
242
|
+
if (!log) return;
|
|
243
|
+
setVisible(log.scrollHeight - log.scrollTop - log.clientHeight > threshold);
|
|
244
|
+
}, [threshold]);
|
|
245
|
+
useEffect(() => {
|
|
246
|
+
const log = ref.current?.closest("[data-scope=\"ai\"][data-part=\"conversation\"]");
|
|
247
|
+
if (!log) return;
|
|
248
|
+
log.addEventListener("scroll", measure, { passive: true });
|
|
249
|
+
measure();
|
|
250
|
+
return () => log.removeEventListener("scroll", measure);
|
|
251
|
+
}, [measure]);
|
|
252
|
+
const jump = useCallback(() => {
|
|
253
|
+
const log = ref.current?.closest("[data-scope=\"ai\"][data-part=\"conversation\"]");
|
|
254
|
+
if (log) log.scrollTop = log.scrollHeight;
|
|
255
|
+
onJump?.();
|
|
256
|
+
}, [onJump]);
|
|
257
|
+
return /* @__PURE__ */ jsx("button", {
|
|
258
|
+
ref,
|
|
259
|
+
...rest,
|
|
260
|
+
type: "button",
|
|
261
|
+
"data-scope": "ai",
|
|
262
|
+
"data-part": "jump-to-latest",
|
|
263
|
+
"data-visible": visible ? "" : void 0,
|
|
264
|
+
tabIndex: visible ? 0 : -1,
|
|
265
|
+
"aria-label": rest["aria-label"] ?? messages.ai.jumpToLatest,
|
|
266
|
+
onClick: jump,
|
|
267
|
+
children: children ?? messages.ai.jumpToLatest
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
/** The bubble's inner measure — content that belongs to neither side
|
|
271
|
+
* specifically. */
|
|
272
|
+
const AiContent = withSelfRoot(part("Content", "div"));
|
|
273
|
+
/** The quiet row under a message — copy, retry, feedback. */
|
|
274
|
+
const AiActions = withSelfRoot(part("Actions", "div"));
|
|
275
|
+
/** The while-it-works whisper for the in-flight turns. */
|
|
276
|
+
function AiLoader({ children, ...rest }) {
|
|
277
|
+
const messages = useComponentMessages();
|
|
278
|
+
return /* @__PURE__ */ jsx("span", {
|
|
279
|
+
...rest,
|
|
280
|
+
role: "status",
|
|
281
|
+
"aria-label": rest["aria-label"] ?? messages.ai.loading,
|
|
282
|
+
"data-scope": "ai",
|
|
283
|
+
"data-part": "loader",
|
|
284
|
+
children
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
/** The whole family under one handle — `Ai.Conversation`,
|
|
288
|
+
* `Ai.Message`, and the rest, exactly as before the split. */
|
|
289
|
+
const Ai = Object.assign(AiConversation, {
|
|
290
|
+
Root: AiConversation,
|
|
291
|
+
Conversation: AiConversation,
|
|
292
|
+
MessageContent: AiContent,
|
|
293
|
+
Actions: AiActions,
|
|
294
|
+
Loader: AiLoader,
|
|
295
|
+
Media: AiMedia,
|
|
296
|
+
Parts: AiParts,
|
|
297
|
+
JumpToLatest: AiJumpToLatest,
|
|
298
|
+
Message,
|
|
299
|
+
Response,
|
|
300
|
+
Reasoning,
|
|
301
|
+
Tool,
|
|
302
|
+
Sources,
|
|
303
|
+
Source,
|
|
304
|
+
Action,
|
|
305
|
+
Suggestion,
|
|
306
|
+
PromptInput
|
|
307
|
+
});
|
|
308
|
+
injectComponentStyle("ai");
|
|
309
|
+
export { AiJumpToLatest as a, toolPartDisplay as c, AiConversation as i, AiActions as n, AiMedia as o, AiContent as r, AiParts as s, Ai as t };
|