macbetter 0.1.0-beta.1 → 0.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/artifact-card.d.ts +41 -0
- package/dist/components/artifact-card.js +57 -0
- package/dist/components/attachment.d.ts +48 -0
- package/dist/components/attachment.js +65 -0
- package/dist/components/chat.d.ts +29 -0
- package/dist/components/chat.js +29 -0
- package/dist/components/code-block.d.ts +39 -0
- package/dist/components/code-block.js +65 -0
- package/dist/components/confirmation.d.ts +24 -0
- package/dist/components/confirmation.js +50 -0
- package/dist/components/content-unavailable.d.ts +19 -0
- package/dist/components/content-unavailable.js +21 -0
- package/dist/components/description-list.d.ts +18 -0
- package/dist/components/description-list.js +17 -0
- package/dist/components/generated-image.d.ts +39 -0
- package/dist/components/generated-image.js +47 -0
- package/dist/components/inspector.d.ts +29 -0
- package/dist/components/inspector.js +40 -0
- package/dist/components/message.d.ts +65 -0
- package/dist/components/message.js +69 -0
- package/dist/components/model-picker.d.ts +61 -0
- package/dist/components/model-picker.js +59 -0
- package/dist/components/plan.d.ts +25 -0
- package/dist/components/plan.js +43 -0
- package/dist/components/prompt-input.d.ts +93 -0
- package/dist/components/prompt-input.js +172 -0
- package/dist/components/reasoning.d.ts +28 -0
- package/dist/components/reasoning.js +52 -0
- package/dist/components/response.d.ts +14 -0
- package/dist/components/response.js +14 -0
- package/dist/components/shimmer.d.ts +18 -0
- package/dist/components/shimmer.js +17 -0
- package/dist/components/sources.d.ts +51 -0
- package/dist/components/sources.js +46 -0
- package/dist/components/suggestion.d.ts +23 -0
- package/dist/components/suggestion.js +29 -0
- package/dist/components/tool-call.d.ts +48 -0
- package/dist/components/tool-call.js +77 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +19 -0
- package/dist/lib/agent-glyphs.d.ts +10 -0
- package/dist/lib/agent-glyphs.js +19 -0
- package/dist/styles/components/artifact-card.css +238 -0
- package/dist/styles/components/attachment.css +540 -0
- package/dist/styles/components/chat.css +209 -0
- package/dist/styles/components/code-block.css +162 -0
- package/dist/styles/components/confirmation.css +189 -0
- package/dist/styles/components/content-unavailable.css +105 -0
- package/dist/styles/components/description-list.css +92 -0
- package/dist/styles/components/device-frame.css +8 -0
- package/dist/styles/components/generated-image.css +248 -0
- package/dist/styles/components/index.css +19 -0
- package/dist/styles/components/inspector.css +236 -0
- package/dist/styles/components/message.css +236 -0
- package/dist/styles/components/model-picker.css +64 -0
- package/dist/styles/components/navigation-bar.css +2 -1
- package/dist/styles/components/plan.css +212 -0
- package/dist/styles/components/prompt-input.css +503 -0
- package/dist/styles/components/reasoning.css +214 -0
- package/dist/styles/components/response.css +303 -0
- package/dist/styles/components/shimmer.css +60 -0
- package/dist/styles/components/sources.css +349 -0
- package/dist/styles/components/suggestion.css +203 -0
- package/dist/styles/components/tool-call.css +391 -0
- package/package.json +1 -1
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { createFileInputController, FileInput, FileInputDropzone, FileInputItem, FileInputItemRemove, FileInputList, formatFileSize, } from "@ui-sdk/react/file-input";
|
|
4
|
+
import { Textarea } from "@ui-sdk/react/textarea";
|
|
5
|
+
import { TriggerMenu, TriggerMenuContent, TriggerMenuEmpty, TriggerMenuList, TriggerMenuStatus, textFieldAdapter, } from "@ui-sdk/react/trigger-menu";
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { cx, join } from "../lib/cx.js";
|
|
8
|
+
import { Attachment, AttachmentMeta, AttachmentName, AttachmentPreview } from "./attachment.js";
|
|
9
|
+
import { Button } from "./button.js";
|
|
10
|
+
import { Menu, MenuContent, MenuItem, MenuItemIcon, MenuTrigger } from "./menu.js";
|
|
11
|
+
const PromptInputContext = React.createContext(null);
|
|
12
|
+
function usePromptInput(part) {
|
|
13
|
+
const context = React.useContext(PromptInputContext);
|
|
14
|
+
if (!context)
|
|
15
|
+
throw new Error(`${part} must be inside a PromptInput.`);
|
|
16
|
+
return context;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The composer. Return sends, Shift-Return adds a line, and files come in from the
|
|
20
|
+
* add button, a drop or a paste. `PromptInputAccessory` children are placed under it.
|
|
21
|
+
*/
|
|
22
|
+
function PromptInput({ status = "ready", onSubmit, onStop, size = "md", glow, floating, value: valueProp, defaultValue = "", onValueChange, files: filesProp, defaultFiles, onFilesChange, accept, maxFiles, maxSize, disabled = false, className, children, ...props }) {
|
|
23
|
+
const [ownText, setOwnText] = React.useState(defaultValue);
|
|
24
|
+
const text = valueProp ?? ownText;
|
|
25
|
+
const [ownFiles, setOwnFiles] = React.useState(defaultFiles ?? []);
|
|
26
|
+
const files = filesProp ?? ownFiles;
|
|
27
|
+
const [controller] = React.useState(createFileInputController);
|
|
28
|
+
const fieldRef = React.useRef(null);
|
|
29
|
+
const formRef = React.useRef(null);
|
|
30
|
+
// A floating composer tells its Chat how much room it covers, so the last turn and the
|
|
31
|
+
// jump button clear it however many lines the field has grown to.
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
const form = formRef.current;
|
|
34
|
+
const chat = floating ? form?.closest(".mb-chat") : null;
|
|
35
|
+
if (!form || !chat || typeof ResizeObserver === "undefined")
|
|
36
|
+
return;
|
|
37
|
+
const measure = () => {
|
|
38
|
+
const room = chat.getBoundingClientRect().bottom - form.getBoundingClientRect().top;
|
|
39
|
+
chat.style.setProperty("--mb-chat-inset-bottom", `${Math.max(0, Math.round(room))}px`);
|
|
40
|
+
};
|
|
41
|
+
measure();
|
|
42
|
+
const observer = new ResizeObserver(measure);
|
|
43
|
+
observer.observe(form);
|
|
44
|
+
observer.observe(chat);
|
|
45
|
+
return () => {
|
|
46
|
+
observer.disconnect();
|
|
47
|
+
chat.style.removeProperty("--mb-chat-inset-bottom");
|
|
48
|
+
};
|
|
49
|
+
}, [floating]);
|
|
50
|
+
const setText = React.useCallback((next) => {
|
|
51
|
+
if (valueProp === undefined)
|
|
52
|
+
setOwnText(next);
|
|
53
|
+
onValueChange?.(next);
|
|
54
|
+
}, [valueProp, onValueChange]);
|
|
55
|
+
const setFiles = (next) => {
|
|
56
|
+
if (filesProp === undefined)
|
|
57
|
+
setOwnFiles(next);
|
|
58
|
+
onFilesChange?.(next);
|
|
59
|
+
};
|
|
60
|
+
const busy = status === "submitted" || status === "streaming";
|
|
61
|
+
const empty = text.trim() === "" && files.length === 0;
|
|
62
|
+
const glowing = Boolean(glow) && busy;
|
|
63
|
+
const context = {
|
|
64
|
+
status,
|
|
65
|
+
busy,
|
|
66
|
+
empty,
|
|
67
|
+
disabled,
|
|
68
|
+
text,
|
|
69
|
+
setText,
|
|
70
|
+
files,
|
|
71
|
+
fieldRef,
|
|
72
|
+
openFiles: () => controller.open(),
|
|
73
|
+
stop: () => onStop?.(),
|
|
74
|
+
};
|
|
75
|
+
const inside = [];
|
|
76
|
+
const under = [];
|
|
77
|
+
React.Children.forEach(children, (child) => {
|
|
78
|
+
if (React.isValidElement(child) && child.type === PromptInputAccessory)
|
|
79
|
+
under.push(child);
|
|
80
|
+
else
|
|
81
|
+
inside.push(child);
|
|
82
|
+
});
|
|
83
|
+
return (_jsx(PromptInputContext.Provider, { value: context, children: _jsxs("form", { noValidate: true, "data-size": size, "data-status": status, "data-glow": glow ? "" : undefined, "data-glowing": glowing ? "" : undefined, "data-floating": floating ? "" : undefined, "data-disabled": disabled ? "" : undefined, className: join("mb-prompt-input", className), ...props, ref: formRef, onSubmit: (event) => {
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
if (busy || empty || disabled)
|
|
86
|
+
return;
|
|
87
|
+
onSubmit?.({ text, files: [...files] });
|
|
88
|
+
setText("");
|
|
89
|
+
setFiles([]);
|
|
90
|
+
}, children: [_jsx(FileInput, { multiple: true, accept: accept, maxFiles: maxFiles, maxSize: maxSize, disabled: disabled, controller: controller, value: files, onValueChange: (next) => setFiles([...next]), className: "mb-prompt-input-files", children: _jsx(FileInputDropzone, { className: "mb-prompt-input-box", pasteTarget: () => fieldRef.current, children: inside }) }), under] }) }));
|
|
91
|
+
}
|
|
92
|
+
function assignRef(ref, value) {
|
|
93
|
+
if (typeof ref === "function")
|
|
94
|
+
ref(value);
|
|
95
|
+
else if (ref)
|
|
96
|
+
ref.current = value;
|
|
97
|
+
}
|
|
98
|
+
/** The text field. It grows with what's typed. */
|
|
99
|
+
function PromptInputField({ "aria-label": ariaLabel = "Message", triggers, triggerEmpty, maxRows, rows, ref, className, style, disabled, ...props }) {
|
|
100
|
+
const context = usePromptInput("PromptInputField");
|
|
101
|
+
const [editor, setEditor] = React.useState();
|
|
102
|
+
const lines = maxRows ? { "--mb-prompt-input-max-rows": maxRows } : undefined;
|
|
103
|
+
const field = (_jsx(Textarea, { ref: (element) => {
|
|
104
|
+
context.fieldRef.current = element;
|
|
105
|
+
assignRef(ref, element);
|
|
106
|
+
if (triggers && element && editor?.element !== element)
|
|
107
|
+
setEditor(textFieldAdapter(element));
|
|
108
|
+
}, autoResize: true, rows: rows ?? 1, submitShortcut: "enter", "aria-label": ariaLabel, disabled: disabled ?? context.disabled, value: context.text, onValueChange: (next) => context.setText(next), className: cx("mb-prompt-input-field", className), style: lines
|
|
109
|
+
? typeof style === "function"
|
|
110
|
+
? (state) => ({ ...lines, ...style(state) })
|
|
111
|
+
: { ...lines, ...style }
|
|
112
|
+
: style, ...props }));
|
|
113
|
+
if (!triggers)
|
|
114
|
+
return field;
|
|
115
|
+
return (_jsxs(TriggerMenu, { editor: editor, triggers: triggers, children: [field, _jsx(TriggerMenuStatus, { className: "mb-visually-hidden" }), _jsxs(TriggerMenuContent, { side: "top", align: "start", sideOffset: 6, className: "mb-menu-content mb-prompt-input-suggestions", children: [triggerEmpty ? _jsx(TriggerMenuEmpty, { className: "mb-prompt-input-suggestions-empty", children: triggerEmpty }) : null, _jsx(TriggerMenuList, { className: "mb-prompt-input-suggestions-list" })] })] }));
|
|
116
|
+
}
|
|
117
|
+
/** The files attached so far, as chips above the field. Arrow keys move between them; Delete removes one. */
|
|
118
|
+
function PromptInputAttachments({ "aria-label": ariaLabel = "Attachments", className, ...props }) {
|
|
119
|
+
const { files } = usePromptInput("PromptInputAttachments");
|
|
120
|
+
if (files.length === 0)
|
|
121
|
+
return null;
|
|
122
|
+
return (_jsx(FileInputList, { "aria-label": ariaLabel, className: cx("mb-prompt-input-attachments", className), ...props, children: _jsx(FileInputItem, { className: "mb-prompt-input-attachment", children: ({ file }) => _jsx(PromptInputAttachmentChip, { file: file }) }) }));
|
|
123
|
+
}
|
|
124
|
+
function PromptInputAttachmentChip({ file }) {
|
|
125
|
+
const image = file.type.startsWith("image/");
|
|
126
|
+
const [url, setUrl] = React.useState();
|
|
127
|
+
React.useEffect(() => {
|
|
128
|
+
if (!image || typeof URL.createObjectURL !== "function")
|
|
129
|
+
return;
|
|
130
|
+
const next = URL.createObjectURL(file);
|
|
131
|
+
setUrl(next);
|
|
132
|
+
return () => URL.revokeObjectURL(next);
|
|
133
|
+
}, [file, image]);
|
|
134
|
+
const extension = file.name.includes(".") ? file.name.split(".").pop()?.toUpperCase().slice(0, 4) : undefined;
|
|
135
|
+
return (_jsxs(Attachment, { variant: "chip", children: [_jsx(AttachmentPreview, { src: url, extension: image ? undefined : extension }), _jsx(AttachmentName, { children: file.name }), _jsx(AttachmentMeta, { children: formatFileSize(file.size) }), _jsx(FileInputItemRemove, { className: "mb-attachment-remove", children: _jsx("svg", { viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "m4.75 4.75 6.5 6.5m0-6.5-6.5 6.5" }) }) })] }));
|
|
136
|
+
}
|
|
137
|
+
/** The row under the field: leading and trailing `PromptInputTools`. */
|
|
138
|
+
function PromptInputToolbar({ className, ...props }) {
|
|
139
|
+
return _jsx("div", { className: join("mb-prompt-input-toolbar", className), ...props });
|
|
140
|
+
}
|
|
141
|
+
/** A cluster of controls in the toolbar. The first sits at the leading edge, the last at the trailing edge. */
|
|
142
|
+
function PromptInputTools({ className, ...props }) {
|
|
143
|
+
return _jsx("div", { className: join("mb-prompt-input-tools", className), ...props });
|
|
144
|
+
}
|
|
145
|
+
/** A plain round icon button for the toolbar, like dictation or voice. */
|
|
146
|
+
function PromptInputButton({ variant = "plain", tone = "neutral", shape = "circle", type = "button", className, ...props }) {
|
|
147
|
+
return (_jsx(Button, { variant: variant, tone: tone, shape: shape, type: type, className: cx("mb-prompt-input-button", className), ...props }));
|
|
148
|
+
}
|
|
149
|
+
/** The add button. It opens a menu whose first item picks photos and files. */
|
|
150
|
+
function PromptInputAdd({ label = "Add", filesLabel = "Add photos and files", hideFiles, disabled, className, presentation = "auto", onAction, children, ...props }) {
|
|
151
|
+
const context = usePromptInput("PromptInputAdd");
|
|
152
|
+
return (_jsxs(Menu, { presentation: presentation, onAction: (value, details) => {
|
|
153
|
+
if (value === "mb-prompt-input-files")
|
|
154
|
+
context.openFiles();
|
|
155
|
+
return onAction?.(value, details);
|
|
156
|
+
}, ...props, children: [_jsx(MenuTrigger, { variant: "plain", tone: "neutral", shape: "circle", indicator: false, "aria-label": label, disabled: disabled ?? context.disabled, className: join("mb-prompt-input-button mb-prompt-input-add", className), children: _jsx("svg", { viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M8 2.75v10.5M2.75 8h10.5", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" }) }) }), _jsxs(MenuContent, { side: "top", align: "start", className: "mb-prompt-input-add-menu", children: [hideFiles ? null : (_jsxs(MenuItem, { value: "mb-prompt-input-files", children: [_jsx(MenuItemIcon, { children: _jsx("svg", { viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "m13.2 7.6-5.15 5.15a3.25 3.25 0 0 1-4.6-4.6l5.3-5.3a2.17 2.17 0 0 1 3.07 3.07L6.6 11.15a1.08 1.08 0 0 1-1.53-1.53l4.8-4.8", stroke: "currentColor", strokeWidth: "1.35", strokeLinecap: "round", strokeLinejoin: "round" }) }) }), filesLabel] })), children] })] }));
|
|
157
|
+
}
|
|
158
|
+
/** Sends the message. While a reply is on its way it's a Stop button that calls `onStop`. */
|
|
159
|
+
function PromptInputSubmit({ sendLabel = "Send", stopLabel = "Stop", variant = "filled", tone = "accent", shape = "circle", size = "sm", disabled, className, onClick, ...props }) {
|
|
160
|
+
const context = usePromptInput("PromptInputSubmit");
|
|
161
|
+
const stopping = context.busy;
|
|
162
|
+
return (_jsx(Button, { type: stopping ? "button" : "submit", variant: variant, tone: stopping ? "neutral" : tone, shape: shape, size: size, "aria-label": stopping ? stopLabel : sendLabel, disabled: disabled ?? (context.disabled || (!stopping && context.empty)), "data-status": context.status, className: cx("mb-prompt-input-submit", className), onClick: (event, ...rest) => {
|
|
163
|
+
onClick?.(event, ...rest);
|
|
164
|
+
if (stopping && !event.defaultPrevented)
|
|
165
|
+
context.stop();
|
|
166
|
+
}, ...props, children: stopping ? (_jsx("svg", { viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false", children: _jsx("rect", { x: "4", y: "4", width: "8", height: "8", rx: "1.75", fill: "currentColor" }) })) : (_jsx("svg", { viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M8 13.25V2.9M3.6 7.2 8 2.75l4.4 4.45", stroke: "currentColor", strokeWidth: "1.9", strokeLinecap: "round", strokeLinejoin: "round" }) })) }));
|
|
167
|
+
}
|
|
168
|
+
/** The strip attached under the composer: context chips on the leading side, an action on the trailing side. */
|
|
169
|
+
function PromptInputAccessory({ className, ...props }) {
|
|
170
|
+
return _jsx("div", { className: join("mb-prompt-input-accessory", className), ...props });
|
|
171
|
+
}
|
|
172
|
+
export { PromptInput, PromptInputAccessory, PromptInputAdd, PromptInputAttachments, PromptInputButton, PromptInputField, PromptInputSubmit, PromptInputToolbar, PromptInputTools, };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "@ui-sdk/react/collapsible";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
type ReasoningState = "running" | "done";
|
|
4
|
+
/** Seconds as people say them: `12s`, `2m 1s`, `1h 4m`. */
|
|
5
|
+
declare function formatDuration(seconds: number): string;
|
|
6
|
+
type ReasoningProps = React.ComponentProps<typeof Collapsible> & {
|
|
7
|
+
/** `running` shimmers "Thinking…"; `done` says how long it took. */
|
|
8
|
+
state?: ReasoningState;
|
|
9
|
+
/** How long the model worked, in seconds. */
|
|
10
|
+
duration?: number;
|
|
11
|
+
/** Opens while running and closes when `state` turns `done`. Only when uncontrolled. */
|
|
12
|
+
autoCollapse?: boolean;
|
|
13
|
+
/** A soft moving glow behind the line while running. It holds still under Reduce Motion. */
|
|
14
|
+
glow?: boolean;
|
|
15
|
+
};
|
|
16
|
+
declare function Reasoning({ state, duration, autoCollapse, glow, open, defaultOpen, onOpenChange, className, ...props }: ReasoningProps): React.JSX.Element;
|
|
17
|
+
type ReasoningTriggerProps = Omit<React.ComponentProps<typeof CollapsibleTrigger>, "children"> & {
|
|
18
|
+
/** Replaces the label. It still shimmers while running. */
|
|
19
|
+
children?: React.ReactNode;
|
|
20
|
+
};
|
|
21
|
+
/** The line itself: "Thinking…" while running, then "Thought for 12s", with a chevron that turns down when open. */
|
|
22
|
+
declare function ReasoningTrigger({ className, children, ...props }: ReasoningTriggerProps): React.JSX.Element;
|
|
23
|
+
/** The reasoning text or steps, behind a leading hairline. */
|
|
24
|
+
declare function ReasoningContent({ className, children, ...props }: Omit<React.ComponentProps<typeof CollapsiblePanel>, "children"> & {
|
|
25
|
+
children?: React.ReactNode;
|
|
26
|
+
}): React.JSX.Element;
|
|
27
|
+
export { formatDuration, Reasoning, ReasoningContent, ReasoningTrigger };
|
|
28
|
+
export type { ReasoningProps, ReasoningState, ReasoningTriggerProps };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "@ui-sdk/react/collapsible";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { DisclosureChevron } from "../lib/agent-glyphs.js";
|
|
6
|
+
import { cx } from "../lib/cx.js";
|
|
7
|
+
import { Shimmer } from "./shimmer.js";
|
|
8
|
+
const ReasoningContext = React.createContext({ state: "done", duration: undefined });
|
|
9
|
+
/** Seconds as people say them: `12s`, `2m 1s`, `1h 4m`. */
|
|
10
|
+
function formatDuration(seconds) {
|
|
11
|
+
const total = Math.max(0, Math.round(seconds));
|
|
12
|
+
if (total < 60)
|
|
13
|
+
return `${total}s`;
|
|
14
|
+
const hours = Math.floor(total / 3600);
|
|
15
|
+
const minutes = Math.floor((total % 3600) / 60);
|
|
16
|
+
const rest = total % 60;
|
|
17
|
+
if (hours > 0)
|
|
18
|
+
return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;
|
|
19
|
+
return rest > 0 ? `${minutes}m ${rest}s` : `${minutes}m`;
|
|
20
|
+
}
|
|
21
|
+
function Reasoning({ state = "done", duration, autoCollapse, glow, open, defaultOpen, onOpenChange, className, ...props }) {
|
|
22
|
+
const [ownOpen, setOwnOpen] = React.useState(defaultOpen ?? (autoCollapse ? state === "running" : false));
|
|
23
|
+
const previous = React.useRef(state);
|
|
24
|
+
React.useEffect(() => {
|
|
25
|
+
if (!autoCollapse || previous.current === state)
|
|
26
|
+
return;
|
|
27
|
+
previous.current = state;
|
|
28
|
+
setOwnOpen(state === "running");
|
|
29
|
+
}, [autoCollapse, state]);
|
|
30
|
+
const context = React.useMemo(() => ({ state, duration }), [state, duration]);
|
|
31
|
+
return (_jsx(ReasoningContext.Provider, { value: context, children: _jsx(Collapsible, { "data-state": state, "data-glow": glow ? "" : undefined, "aria-busy": state === "running" ? true : undefined, open: open ?? ownOpen, onOpenChange: (next, details) => {
|
|
32
|
+
onOpenChange?.(next, details);
|
|
33
|
+
if (open === undefined && !details.canceled)
|
|
34
|
+
setOwnOpen(next);
|
|
35
|
+
}, className: cx("mb-reasoning", className), ...props }) }));
|
|
36
|
+
}
|
|
37
|
+
/** The line itself: "Thinking…" while running, then "Thought for 12s", with a chevron that turns down when open. */
|
|
38
|
+
function ReasoningTrigger({ className, children, ...props }) {
|
|
39
|
+
const { state, duration } = React.useContext(ReasoningContext);
|
|
40
|
+
const label = children ??
|
|
41
|
+
(state === "running"
|
|
42
|
+
? "Thinking…"
|
|
43
|
+
: duration !== undefined
|
|
44
|
+
? `Thought for ${formatDuration(duration)}`
|
|
45
|
+
: "Thought for a few seconds");
|
|
46
|
+
return (_jsxs(CollapsibleTrigger, { className: cx("mb-reasoning-trigger", className), ...props, children: [_jsx(Shimmer, { active: state === "running", className: "mb-reasoning-label", children: label }), _jsx(DisclosureChevron, { className: "mb-reasoning-chevron" })] }));
|
|
47
|
+
}
|
|
48
|
+
/** The reasoning text or steps, behind a leading hairline. */
|
|
49
|
+
function ReasoningContent({ className, children, ...props }) {
|
|
50
|
+
return (_jsx(CollapsiblePanel, { className: cx("mb-reasoning-panel", className), ...props, children: _jsx("div", { className: "mb-reasoning-content", children: children }) }));
|
|
51
|
+
}
|
|
52
|
+
export { formatDuration, Reasoning, ReasoningContent, ReasoningTrigger };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
type ResponseProps = React.ComponentProps<"div"> & {
|
|
3
|
+
/** Set while the reply is still arriving. Pair it with a `ResponseCaret` at the end. */
|
|
4
|
+
streaming?: boolean;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Typography for the assistant's reply. It styles the elements you give it —
|
|
8
|
+
* paragraphs, headings, lists, tables, code — and leaves nested macbetter components alone.
|
|
9
|
+
*/
|
|
10
|
+
declare function Response({ streaming, className, ...props }: ResponseProps): React.JSX.Element;
|
|
11
|
+
/** The blinking mark at the end of a reply that's still streaming. It holds still under Reduce Motion. */
|
|
12
|
+
declare function ResponseCaret({ className, ...props }: React.ComponentProps<"span">): React.JSX.Element;
|
|
13
|
+
export { Response, ResponseCaret };
|
|
14
|
+
export type { ResponseProps };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { join } from "../lib/cx.js";
|
|
3
|
+
/**
|
|
4
|
+
* Typography for the assistant's reply. It styles the elements you give it —
|
|
5
|
+
* paragraphs, headings, lists, tables, code — and leaves nested macbetter components alone.
|
|
6
|
+
*/
|
|
7
|
+
function Response({ streaming, className, ...props }) {
|
|
8
|
+
return (_jsx("div", { "data-streaming": streaming ? "" : undefined, "aria-busy": streaming || undefined, className: join("mb-response", className), ...props }));
|
|
9
|
+
}
|
|
10
|
+
/** The blinking mark at the end of a reply that's still streaming. It holds still under Reduce Motion. */
|
|
11
|
+
function ResponseCaret({ className, ...props }) {
|
|
12
|
+
return _jsx("span", { "aria-hidden": "true", className: join("mb-response-caret", className), ...props });
|
|
13
|
+
}
|
|
14
|
+
export { Response, ResponseCaret };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type RenderProp } from "@ui-sdk/react/primitive";
|
|
2
|
+
import type * as React from "react";
|
|
3
|
+
type ShimmerProps = React.ComponentProps<"span"> & {
|
|
4
|
+
/** While true, a brighter band sweeps along the text. False leaves plain secondary text. */
|
|
5
|
+
active?: boolean;
|
|
6
|
+
/** Seconds for one sweep, or any CSS time. */
|
|
7
|
+
duration?: number | string;
|
|
8
|
+
/** Renders a different element, such as `<p />`, with the shimmer's props. */
|
|
9
|
+
render?: RenderProp;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Text that shimmers while work is in progress, like "Thinking…". The sweep
|
|
13
|
+
* only ever brightens secondary text, so it reads at every frame, and it
|
|
14
|
+
* holds still under Reduce Motion.
|
|
15
|
+
*/
|
|
16
|
+
declare function Shimmer({ active, duration, className, style, render, ...props }: ShimmerProps): React.ReactElement<unknown, string | React.JSXElementConstructor<any>>;
|
|
17
|
+
export { Shimmer };
|
|
18
|
+
export type { ShimmerProps };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { renderElement } from "@ui-sdk/react/primitive";
|
|
2
|
+
import { join } from "../lib/cx.js";
|
|
3
|
+
/**
|
|
4
|
+
* Text that shimmers while work is in progress, like "Thinking…". The sweep
|
|
5
|
+
* only ever brightens secondary text, so it reads at every frame, and it
|
|
6
|
+
* holds still under Reduce Motion.
|
|
7
|
+
*/
|
|
8
|
+
function Shimmer({ active = true, duration, className, style, render, ...props }) {
|
|
9
|
+
const time = typeof duration === "number" ? `${duration}s` : duration;
|
|
10
|
+
return renderElement("span", {
|
|
11
|
+
...props,
|
|
12
|
+
"data-active": active ? "" : undefined,
|
|
13
|
+
className: join("mb-shimmer", className),
|
|
14
|
+
style: time ? { "--mb-shimmer-duration": time, ...style } : style,
|
|
15
|
+
}, render);
|
|
16
|
+
}
|
|
17
|
+
export { Shimmer };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "@ui-sdk/react/collapsible";
|
|
2
|
+
import { HoverCard as HoverCardPrimitive, HoverCardTrigger as HoverCardTriggerPrimitive } from "@ui-sdk/react/hover-card";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
/** A collapsible "Used 4 sources" line that opens to the list of sources. */
|
|
5
|
+
declare function Sources({ className, ...props }: React.ComponentProps<typeof Collapsible>): React.JSX.Element;
|
|
6
|
+
type SourcesTriggerProps = Omit<React.ComponentProps<typeof CollapsibleTrigger>, "children"> & {
|
|
7
|
+
/** How many sources, for the default label "Used 4 sources". */
|
|
8
|
+
count?: number;
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
};
|
|
11
|
+
declare function SourcesTrigger({ count, className, children, ...props }: SourcesTriggerProps): React.JSX.Element;
|
|
12
|
+
declare function SourcesContent({ className, children, "aria-label": label, ...props }: Omit<React.ComponentProps<typeof CollapsiblePanel>, "children"> & {
|
|
13
|
+
children?: React.ReactNode;
|
|
14
|
+
}): React.JSX.Element;
|
|
15
|
+
type SourceIconProps = React.ComponentProps<"span"> & {
|
|
16
|
+
/** The site's name. Its first letter is drawn in a tinted squircle unless you pass children. */
|
|
17
|
+
site?: string;
|
|
18
|
+
};
|
|
19
|
+
/** A favicon-sized slot. Without children it draws the site's first letter on a tinted tile. */
|
|
20
|
+
declare function SourceIcon({ site, className, style, children, ...props }: SourceIconProps): React.JSX.Element;
|
|
21
|
+
type SourceProps = Omit<React.ComponentProps<"a">, "title"> & {
|
|
22
|
+
href: string;
|
|
23
|
+
/** The site's name, like "example.com". */
|
|
24
|
+
site: string;
|
|
25
|
+
/** Your own favicon in place of the drawn letter. */
|
|
26
|
+
icon?: React.ReactNode;
|
|
27
|
+
};
|
|
28
|
+
/** One source: a link, opening in a new tab, with its favicon, title (children) and site. */
|
|
29
|
+
declare function Source({ href, site, icon, className, children, target, rel, ...props }: SourceProps): React.JSX.Element;
|
|
30
|
+
type CitationProps = Omit<React.ComponentProps<typeof HoverCardTriggerPrimitive>, "title" | "children"> & {
|
|
31
|
+
href: string;
|
|
32
|
+
/** The source's title, shown in the preview and read after the chip's label. */
|
|
33
|
+
title: string;
|
|
34
|
+
/** The site's name, like "example.com". It's the chip's label unless you pass children. */
|
|
35
|
+
site: string;
|
|
36
|
+
/** A line about the source, shown in the preview. */
|
|
37
|
+
description?: React.ReactNode;
|
|
38
|
+
/** Your own favicon in place of the drawn letter. */
|
|
39
|
+
icon?: React.ReactNode;
|
|
40
|
+
/** The chip's label: a number, or a short name. */
|
|
41
|
+
children?: React.ReactNode;
|
|
42
|
+
/** Props for the ui-sdk Hover Card root, like `delay`. */
|
|
43
|
+
hoverCardProps?: Omit<React.ComponentProps<typeof HoverCardPrimitive>, "children">;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* An inline citation: a small capsule in the reply's text that's a link to the source. Pausing
|
|
47
|
+
* on it, or focusing it, previews the source in a hover card.
|
|
48
|
+
*/
|
|
49
|
+
declare function Citation({ href, title, site, description, icon, className, children, hoverCardProps, target, rel, ...props }: CitationProps): React.JSX.Element;
|
|
50
|
+
export { Citation, Source, SourceIcon, Sources, SourcesContent, SourcesTrigger };
|
|
51
|
+
export type { CitationProps, SourceIconProps, SourceProps, SourcesTriggerProps };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "@ui-sdk/react/collapsible";
|
|
4
|
+
import { HoverCard as HoverCardPrimitive, HoverCardTrigger as HoverCardTriggerPrimitive, } from "@ui-sdk/react/hover-card";
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import { DisclosureChevron } from "../lib/agent-glyphs.js";
|
|
7
|
+
import { cx, join } from "../lib/cx.js";
|
|
8
|
+
import { HoverCardContent } from "./hover-card.js";
|
|
9
|
+
const tints = ["blue", "green", "orange", "pink", "purple", "teal", "indigo", "red", "cyan", "brown"];
|
|
10
|
+
function tintFor(text) {
|
|
11
|
+
let hash = 0;
|
|
12
|
+
for (let index = 0; index < text.length; index++)
|
|
13
|
+
hash = (hash * 31 + text.charCodeAt(index)) >>> 0;
|
|
14
|
+
return tints[hash % tints.length];
|
|
15
|
+
}
|
|
16
|
+
const ListContext = React.createContext(false);
|
|
17
|
+
/** A collapsible "Used 4 sources" line that opens to the list of sources. */
|
|
18
|
+
function Sources({ className, ...props }) {
|
|
19
|
+
return _jsx(Collapsible, { className: cx("mb-sources", className), ...props });
|
|
20
|
+
}
|
|
21
|
+
function SourcesTrigger({ count, className, children, ...props }) {
|
|
22
|
+
const label = children ?? (count === undefined ? "Sources" : `Used ${count} ${count === 1 ? "source" : "sources"}`);
|
|
23
|
+
return (_jsxs(CollapsibleTrigger, { className: cx("mb-sources-trigger", className), ...props, children: [_jsx("span", { className: "mb-sources-label", children: label }), _jsx(DisclosureChevron, { className: "mb-sources-chevron" })] }));
|
|
24
|
+
}
|
|
25
|
+
function SourcesContent({ className, children, "aria-label": label = "Sources", ...props }) {
|
|
26
|
+
return (_jsx(CollapsiblePanel, { className: cx("mb-sources-panel", className), ...props, children: _jsx(ListContext.Provider, { value: true, children: _jsx("ul", { role: "list", "aria-label": label, className: "mb-sources-list", children: children }) }) }));
|
|
27
|
+
}
|
|
28
|
+
/** A favicon-sized slot. Without children it draws the site's first letter on a tinted tile. */
|
|
29
|
+
function SourceIcon({ site = "", className, style, children, ...props }) {
|
|
30
|
+
const letter = site.replace(/^(https?:\/\/)?(www\.)?/, "").charAt(0).toUpperCase();
|
|
31
|
+
return (_jsx("span", { "aria-hidden": "true", "data-letter": children ? undefined : "", className: join("mb-source-icon", className), style: children ? style : { "--mb-source-tint": `var(--mb-${tintFor(site)})`, ...style }, ...props, children: children ?? letter }));
|
|
32
|
+
}
|
|
33
|
+
/** One source: a link, opening in a new tab, with its favicon, title (children) and site. */
|
|
34
|
+
function Source({ href, site, icon, className, children, target = "_blank", rel = "noreferrer", ...props }) {
|
|
35
|
+
const inList = React.useContext(ListContext);
|
|
36
|
+
const link = (_jsxs("a", { href: href, target: target, rel: rel, className: join("mb-source", className), ...props, children: [_jsx(SourceIcon, { site: site, children: icon }), _jsx("span", { className: "mb-source-title", children: children }), _jsx("span", { className: "mb-source-site", children: site }), target === "_blank" ? _jsx("span", { className: "mb-visually-hidden", children: " (opens in a new tab)" }) : null] }));
|
|
37
|
+
return inList ? _jsx("li", { className: "mb-sources-item", children: link }) : link;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* An inline citation: a small capsule in the reply's text that's a link to the source. Pausing
|
|
41
|
+
* on it, or focusing it, previews the source in a hover card.
|
|
42
|
+
*/
|
|
43
|
+
function Citation({ href, title, site, description, icon, className, children, hoverCardProps, target = "_blank", rel = "noreferrer", ...props }) {
|
|
44
|
+
return (_jsxs(HoverCardPrimitive, { ...hoverCardProps, children: [_jsxs(HoverCardTriggerPrimitive, { href: href, target: target, rel: rel, className: cx("mb-citation", className), ...props, children: [_jsx("span", { className: "mb-citation-label", children: children ?? site }), _jsxs("span", { className: "mb-visually-hidden", children: [", ", title] })] }), _jsxs(HoverCardContent, { render: _jsx("span", {}), className: "mb-citation-card", children: [_jsxs("span", { className: "mb-citation-card-site", children: [_jsx(SourceIcon, { site: site, children: icon }), _jsx("span", { children: site })] }), _jsx("span", { className: "mb-citation-card-title", children: title }), description != null ? _jsx("span", { className: "mb-citation-card-description", children: description }) : null] })] }));
|
|
45
|
+
}
|
|
46
|
+
export { Citation, Source, SourceIcon, Sources, SourcesContent, SourcesTrigger };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Button as ButtonPrimitive } from "@ui-sdk/react/button";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
type SuggestionsLayout = "list" | "chips";
|
|
4
|
+
type SuggestionsProps = Omit<React.ComponentProps<"div">, "onSelect"> & {
|
|
5
|
+
/** `list` is rows with a hairline between, under a composer; `chips` is a row of capsules. */
|
|
6
|
+
layout?: SuggestionsLayout;
|
|
7
|
+
/** For `chips`: wrap onto more lines, or stay on one line that scrolls sideways. */
|
|
8
|
+
overflow?: "wrap" | "scroll";
|
|
9
|
+
/** Runs with a suggestion's text when it's chosen, unless the suggestion has its own `onClick`. */
|
|
10
|
+
onSelect?: (text: string) => void;
|
|
11
|
+
};
|
|
12
|
+
/** Prompt starters. Name the group with `aria-label`, like "Suggestions". */
|
|
13
|
+
declare function Suggestions({ layout, overflow, onSelect, className, ...props }: SuggestionsProps): React.JSX.Element;
|
|
14
|
+
type SuggestionProps = React.ComponentProps<typeof ButtonPrimitive> & {
|
|
15
|
+
/** A leading glyph. Decorative: the text names the suggestion. */
|
|
16
|
+
icon?: React.ReactNode;
|
|
17
|
+
/** The prompt it sends, when it differs from what it shows. Defaults to its text. */
|
|
18
|
+
value?: string;
|
|
19
|
+
};
|
|
20
|
+
/** One prompt starter. It's a button: choosing it calls the group's `onSelect` with its text. */
|
|
21
|
+
declare function Suggestion({ icon, value, className, children, onClick, ...props }: SuggestionProps): React.JSX.Element;
|
|
22
|
+
export { Suggestion, Suggestions };
|
|
23
|
+
export type { SuggestionProps, SuggestionsLayout, SuggestionsProps };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Button as ButtonPrimitive } from "@ui-sdk/react/button";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { cx, join } from "../lib/cx.js";
|
|
6
|
+
const SuggestionsContext = React.createContext(undefined);
|
|
7
|
+
/** Prompt starters. Name the group with `aria-label`, like "Suggestions". */
|
|
8
|
+
function Suggestions({ layout = "list", overflow = "wrap", onSelect, className, ...props }) {
|
|
9
|
+
return (_jsx(SuggestionsContext.Provider, { value: onSelect, children: _jsx("div", { role: "group", "data-layout": layout, "data-overflow": layout === "chips" ? overflow : undefined, className: join("mb-suggestions", className), ...props }) }));
|
|
10
|
+
}
|
|
11
|
+
function textOf(node) {
|
|
12
|
+
if (typeof node === "string" || typeof node === "number")
|
|
13
|
+
return String(node);
|
|
14
|
+
if (Array.isArray(node))
|
|
15
|
+
return node.map(textOf).join("");
|
|
16
|
+
if (React.isValidElement(node))
|
|
17
|
+
return textOf(node.props.children);
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
/** One prompt starter. It's a button: choosing it calls the group's `onSelect` with its text. */
|
|
21
|
+
function Suggestion({ icon, value, className, children, onClick, ...props }) {
|
|
22
|
+
const onSelect = React.useContext(SuggestionsContext);
|
|
23
|
+
return (_jsx(ButtonPrimitive, { className: cx("mb-suggestion", className), onClick: (event, ...rest) => {
|
|
24
|
+
onClick?.(event, ...rest);
|
|
25
|
+
if (!event.defaultPrevented)
|
|
26
|
+
onSelect?.(value ?? textOf(children));
|
|
27
|
+
}, ...props, children: (state) => (_jsxs(_Fragment, { children: [icon ? (_jsx("span", { "aria-hidden": "true", className: "mb-suggestion-icon", children: icon })) : null, _jsx("span", { className: "mb-suggestion-label", children: typeof children === "function" ? children(state) : children })] })) }));
|
|
28
|
+
}
|
|
29
|
+
export { Suggestion, Suggestions };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "@ui-sdk/react/collapsible";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
type ToolCallStatusValue = "pending" | "running" | "done" | "error" | "approval";
|
|
4
|
+
/** The steps an agent took: a summary line that opens a group of steps. */
|
|
5
|
+
declare function ToolActivity({ className, ...props }: React.ComponentProps<typeof Collapsible>): React.JSX.Element;
|
|
6
|
+
type ToolActivitySummaryProps = Omit<React.ComponentProps<typeof CollapsibleTrigger>, "children"> & {
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
/** A small glyph before the text, like a wrench or a stack of pages. */
|
|
9
|
+
icon?: React.ReactNode;
|
|
10
|
+
/** Shimmers the text while the agent is still working. */
|
|
11
|
+
active?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** "Used Dataroom, read a file · 29s", with a chevron that turns down when the steps show. */
|
|
14
|
+
declare function ToolActivitySummary({ icon, active, className, children, ...props }: ToolActivitySummaryProps): React.JSX.Element;
|
|
15
|
+
/** The group of steps, in a rounded box with a hairline between them. */
|
|
16
|
+
declare function ToolActivityContent({ className, children, "aria-label": label, ...props }: Omit<React.ComponentProps<typeof CollapsiblePanel>, "children"> & {
|
|
17
|
+
children?: React.ReactNode;
|
|
18
|
+
}): React.JSX.Element;
|
|
19
|
+
type ToolCallProps = Omit<React.ComponentProps<typeof Collapsible>, "children"> & {
|
|
20
|
+
/** Where the step stands. Every status but `done` is said in words to assistive tech. */
|
|
21
|
+
status?: ToolCallStatusValue;
|
|
22
|
+
children?: React.ReactNode;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* One step. Put a ToolCallTitle in it, and a ToolCallDetail if the step has a request and
|
|
26
|
+
* response to show: the row then becomes a button that opens it. Without detail it's plain text.
|
|
27
|
+
*/
|
|
28
|
+
declare function ToolCall({ status, className, children, ...props }: ToolCallProps): React.JSX.Element;
|
|
29
|
+
/** A small glyph at the start of a step, for the tool it used. */
|
|
30
|
+
declare function ToolCallIcon({ className, ...props }: React.ComponentProps<"span">): React.JSX.Element;
|
|
31
|
+
type ToolCallTitleProps = React.ComponentProps<"span"> & {
|
|
32
|
+
/** What the agent did, in secondary text before the object: "Read", "Loaded skill". */
|
|
33
|
+
verb?: React.ReactNode;
|
|
34
|
+
};
|
|
35
|
+
/** The verb and its object on one line, like "Read data-workflows.md". Without a verb it's a note. */
|
|
36
|
+
declare function ToolCallTitle({ verb, className, children, ...props }: ToolCallTitleProps): React.JSX.Element;
|
|
37
|
+
/** The status at the end of the row. ToolCall draws it for you. */
|
|
38
|
+
declare function ToolCallStatus(): React.JSX.Element | null;
|
|
39
|
+
/** What opens under a step: one or more ToolCallSections, like Request and Response. */
|
|
40
|
+
declare function ToolCallDetail({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
|
|
41
|
+
type ToolCallSectionProps = Omit<React.ComponentProps<"section">, "title"> & {
|
|
42
|
+
/** The section's heading, like "Request". */
|
|
43
|
+
title: React.ReactNode;
|
|
44
|
+
};
|
|
45
|
+
/** A titled panel on a raised fill. Put a DescriptionList or a CodeBlock in it. */
|
|
46
|
+
declare function ToolCallSection({ title, className, children, ...props }: ToolCallSectionProps): React.JSX.Element;
|
|
47
|
+
export { ToolActivity, ToolActivityContent, ToolActivitySummary, ToolCall, ToolCallDetail, ToolCallIcon, ToolCallSection, ToolCallStatus, ToolCallTitle, };
|
|
48
|
+
export type { ToolActivitySummaryProps, ToolCallProps, ToolCallSectionProps, ToolCallStatusValue, ToolCallTitleProps };
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "@ui-sdk/react/collapsible";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { AlertGlyph, DisclosureChevron } from "../lib/agent-glyphs.js";
|
|
6
|
+
import { cx, join } from "../lib/cx.js";
|
|
7
|
+
import { ActivityIndicator } from "./activity-indicator.js";
|
|
8
|
+
import { Shimmer } from "./shimmer.js";
|
|
9
|
+
const ListContext = React.createContext(false);
|
|
10
|
+
const StatusContext = React.createContext("done");
|
|
11
|
+
/** The steps an agent took: a summary line that opens a group of steps. */
|
|
12
|
+
function ToolActivity({ className, ...props }) {
|
|
13
|
+
return _jsx(Collapsible, { className: cx("mb-tool-activity", className), ...props });
|
|
14
|
+
}
|
|
15
|
+
/** "Used Dataroom, read a file · 29s", with a chevron that turns down when the steps show. */
|
|
16
|
+
function ToolActivitySummary({ icon, active, className, children, ...props }) {
|
|
17
|
+
return (_jsxs(CollapsibleTrigger, { className: cx("mb-tool-activity-summary", className), ...props, children: [icon ? (_jsx("span", { "aria-hidden": "true", className: "mb-tool-activity-icon", children: icon })) : null, _jsx(Shimmer, { active: !!active, className: "mb-tool-activity-label", children: children }), _jsx(DisclosureChevron, { className: "mb-tool-activity-chevron" })] }));
|
|
18
|
+
}
|
|
19
|
+
/** The group of steps, in a rounded box with a hairline between them. */
|
|
20
|
+
function ToolActivityContent({ className, children, "aria-label": label = "Steps", ...props }) {
|
|
21
|
+
return (_jsx(CollapsiblePanel, { className: cx("mb-tool-activity-panel", className), ...props, children: _jsx(ListContext.Provider, { value: true, children: _jsx("ul", { role: "list", "aria-label": label, className: "mb-tool-activity-list", children: children }) }) }));
|
|
22
|
+
}
|
|
23
|
+
const statusWords = {
|
|
24
|
+
pending: "Pending",
|
|
25
|
+
running: "In progress",
|
|
26
|
+
done: null,
|
|
27
|
+
error: "Failed",
|
|
28
|
+
approval: "Needs approval",
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* One step. Put a ToolCallTitle in it, and a ToolCallDetail if the step has a request and
|
|
32
|
+
* response to show: the row then becomes a button that opens it. Without detail it's plain text.
|
|
33
|
+
*/
|
|
34
|
+
function ToolCall({ status = "done", className, children, ...props }) {
|
|
35
|
+
const { open: _open, defaultOpen: _defaultOpen, onOpenChange: _onOpenChange, onOpenChangeComplete: _onOpenChangeComplete, disabled: _disabled, controller: _controller, debug: _debug, render: _render, ...plain } = props;
|
|
36
|
+
const inList = React.useContext(ListContext);
|
|
37
|
+
const all = React.Children.toArray(children);
|
|
38
|
+
const detail = all.filter((child) => React.isValidElement(child) && child.type === ToolCallDetail);
|
|
39
|
+
const row = all.filter((child) => !(React.isValidElement(child) && child.type === ToolCallDetail));
|
|
40
|
+
const content = (_jsxs(_Fragment, { children: [row, _jsx(ToolCallStatus, {})] }));
|
|
41
|
+
const element = detail.length > 0 ? (_jsxs(Collapsible, { "data-status": status, "aria-busy": status === "running" ? true : undefined, className: cx("mb-tool-call", className), ...props, children: [_jsxs(CollapsibleTrigger, { className: "mb-tool-call-row", children: [content, _jsx(DisclosureChevron, { className: "mb-tool-call-chevron" })] }), _jsx(CollapsiblePanel, { className: "mb-tool-call-panel", children: detail })] })) : (_jsx("div", { "data-status": status, "aria-busy": status === "running" ? true : undefined, className: join("mb-tool-call", typeof className === "string" ? className : undefined), ...plain, children: _jsx("div", { className: "mb-tool-call-row", children: content }) }));
|
|
42
|
+
return (_jsx(StatusContext.Provider, { value: status, children: inList ? _jsx("li", { className: "mb-tool-activity-item", children: element }) : element }));
|
|
43
|
+
}
|
|
44
|
+
/** A small glyph at the start of a step, for the tool it used. */
|
|
45
|
+
function ToolCallIcon({ className, ...props }) {
|
|
46
|
+
return _jsx("span", { "aria-hidden": "true", className: join("mb-tool-call-icon", className), ...props });
|
|
47
|
+
}
|
|
48
|
+
/** The verb and its object on one line, like "Read data-workflows.md". Without a verb it's a note. */
|
|
49
|
+
function ToolCallTitle({ verb, className, children, ...props }) {
|
|
50
|
+
const status = React.useContext(StatusContext);
|
|
51
|
+
return (_jsxs(Shimmer, { active: status === "running", "data-note": verb == null ? "" : undefined, className: join("mb-tool-call-title", className), ...props, children: [verb != null ? _jsx("span", { className: "mb-tool-call-verb", children: verb }) : null, verb != null ? " " : null, _jsx("span", { className: "mb-tool-call-object", children: children })] }));
|
|
52
|
+
}
|
|
53
|
+
/** The status at the end of the row. ToolCall draws it for you. */
|
|
54
|
+
function ToolCallStatus() {
|
|
55
|
+
const status = React.useContext(StatusContext);
|
|
56
|
+
const words = statusWords[status];
|
|
57
|
+
if (status === "running") {
|
|
58
|
+
return (_jsxs("span", { className: "mb-tool-call-status", children: [_jsx("span", { "aria-hidden": "true", children: _jsx(ActivityIndicator, { size: "sm", className: "mb-tool-call-spinner" }) }), _jsx("span", { className: "mb-visually-hidden", children: words })] }));
|
|
59
|
+
}
|
|
60
|
+
if (status === "error") {
|
|
61
|
+
return (_jsxs("span", { className: "mb-tool-call-status", "data-status": "error", children: [_jsx(AlertGlyph, { className: "mb-tool-call-alert" }), _jsx("span", { children: words })] }));
|
|
62
|
+
}
|
|
63
|
+
if (status === "approval") {
|
|
64
|
+
return (_jsx("span", { className: "mb-tool-call-status", "data-status": "approval", children: words }));
|
|
65
|
+
}
|
|
66
|
+
return words ? _jsx("span", { className: "mb-visually-hidden", children: words }) : null;
|
|
67
|
+
}
|
|
68
|
+
/** What opens under a step: one or more ToolCallSections, like Request and Response. */
|
|
69
|
+
function ToolCallDetail({ className, ...props }) {
|
|
70
|
+
return _jsx("div", { className: join("mb-tool-call-detail", className), ...props });
|
|
71
|
+
}
|
|
72
|
+
/** A titled panel on a raised fill. Put a DescriptionList or a CodeBlock in it. */
|
|
73
|
+
function ToolCallSection({ title, className, children, ...props }) {
|
|
74
|
+
const id = React.useId();
|
|
75
|
+
return (_jsxs("section", { "aria-labelledby": id, className: join("mb-tool-call-section", className), ...props, children: [_jsx("div", { id: id, className: "mb-tool-call-section-title", children: title }), _jsx("div", { className: "mb-tool-call-section-body", children: children })] }));
|
|
76
|
+
}
|
|
77
|
+
export { ToolActivity, ToolActivityContent, ToolActivitySummary, ToolCall, ToolCallDetail, ToolCallIcon, ToolCallSection, ToolCallStatus, ToolCallTitle, };
|