@mcp-b/react-components 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/{CodeBlock-C2Xjxu9M.js → CodeBlock-D-a84xBL.js} +1 -1
  2. package/dist/{FileTree-D0c9Yj9U.js → FileTree-D8rtTLgK.js} +1 -1
  3. package/dist/attachment-preview-ChtC3HiU.js +25 -0
  4. package/dist/components/Activity.js +1 -1
  5. package/dist/components/AgentChat.d.ts +31 -1
  6. package/dist/components/AgentChat.js +166 -38
  7. package/dist/components/AgentConnection.js +3 -3
  8. package/dist/components/Artifact.js +1 -1
  9. package/dist/components/BrowserLiveView.js +2 -2
  10. package/dist/components/BrowserReplay.js +1 -1
  11. package/dist/components/ChainOfThought.d.ts +1 -1
  12. package/dist/components/ChainOfThought.js +1 -1
  13. package/dist/components/CodeBlock.js +1 -1
  14. package/dist/components/Commit.js +2 -2
  15. package/dist/components/Context.d.ts +28 -27
  16. package/dist/components/Context.js +48 -47
  17. package/dist/components/ContextMenu.js +1 -1
  18. package/dist/components/Conversation.js +1 -1
  19. package/dist/components/Dialog.js +1 -1
  20. package/dist/components/EnvironmentVariables.js +1 -1
  21. package/dist/components/FileTree.js +1 -1
  22. package/dist/components/Menubar.js +1 -1
  23. package/dist/components/Message.d.ts +16 -2
  24. package/dist/components/Message.js +39 -5
  25. package/dist/components/ModelSelector.js +1 -1
  26. package/dist/components/NavigationMenu.js +1 -1
  27. package/dist/components/PricingPage.js +2 -2
  28. package/dist/components/PromptInput.d.ts +532 -2
  29. package/dist/components/PromptInput.js +158 -20
  30. package/dist/components/Queue.js +1 -1
  31. package/dist/components/Reasoning.js +9 -17
  32. package/dist/components/Select.js +1 -1
  33. package/dist/components/Sources.js +1 -1
  34. package/dist/components/Stepper.js +1 -1
  35. package/dist/components/Task.js +1 -1
  36. package/dist/components/Terminal.js +2 -2
  37. package/dist/components/TestResults.js +1 -1
  38. package/dist/components/ThinkChat.d.ts +24 -5
  39. package/dist/components/ThinkChat.js +87 -19
  40. package/dist/components/WebPreview.js +1 -1
  41. package/dist/components/WorkspaceExplorer.js +3 -3
  42. package/dist/components/icons.d.ts +2 -2
  43. package/dist/components/icons.js +2 -2
  44. package/dist/{copy-button-Dd6DEhOm.js → copy-button-BmJEAKuP.js} +1 -1
  45. package/dist/{icons-DQC4Zw5R.js → icons-CZRH4FVH.js} +1 -15
  46. package/dist/{icons-ctdVxng0.d.ts → icons-CmO7-pNY.d.ts} +1 -2
  47. package/dist/styles/agent-chat.css +39 -6
  48. package/dist/styles/attachment-preview.css +21 -0
  49. package/dist/styles/context.css +9 -17
  50. package/dist/styles/conversation.css +3 -3
  51. package/dist/styles/index.css +1 -1
  52. package/dist/styles/message.css +50 -2
  53. package/dist/styles/prompt-input.css +189 -6
  54. package/dist/styles/reasoning.css +0 -1
  55. package/package.json +2 -2
  56. package/dist/PromptInput-Dzn-fOPc.d.ts +0 -444
  57. package/dist/components/Tool.d.ts +0 -123
  58. package/dist/components/Tool.js +0 -209
  59. package/dist/styles/tool.css +0 -203
@@ -1,5 +1,4 @@
1
1
  import { t as cx } from "../class-names-9UtZwb0J.js";
2
- import { Button } from "./Button.js";
3
2
  import { Popover } from "./Popover.js";
4
3
  import { Separator } from "./Separator.js";
5
4
  import * as React from "react";
@@ -13,8 +12,8 @@ function useContextContext() {
13
12
  }
14
13
  /**
15
14
  * Displays token / context usage with a hover card breakdown. The trigger is
16
- * a button showing a compact percentage indicator; hovering or clicking opens
17
- * a popover with category rows and total cost.
15
+ * a bare progress ring; clicking it opens a popover (upward by default) with
16
+ * category rows and total cost.
18
17
  *
19
18
  * @example
20
19
  * ```tsx
@@ -22,7 +21,7 @@ function useContextContext() {
22
21
  * usedTokens={42_300}
23
22
  * maxTokens={200_000}
24
23
  * modelId="claude-opus-4-6"
25
- * usage={{ input: 30000, output: 12300 }}
24
+ * usage={{ inputTokens: 30000, outputTokens: 12300 }}
26
25
  * totalCostUsd={0.42}
27
26
  * >
28
27
  * <ContextTrigger />
@@ -68,33 +67,26 @@ function ContextTrigger({ className, children, ...props }) {
68
67
  const percent = maxTokens > 0 ? usedTokens / maxTokens * 100 : 0;
69
68
  if (React.isValidElement(children)) return /* @__PURE__ */ jsx(Popover.Trigger, { render: children });
70
69
  if (children) return /* @__PURE__ */ jsx(Popover.Trigger, { children });
71
- return /* @__PURE__ */ jsx(Popover.Trigger, { render: /* @__PURE__ */ jsxs(Button, {
72
- variant: "ghost",
73
- color: "neutral",
74
- size: "sm",
70
+ return /* @__PURE__ */ jsx(Popover.Trigger, {
75
71
  className: cx("context__trigger", className),
76
72
  "aria-label": `Context usage: ${percent.toFixed(0)}%`,
77
73
  ...props,
78
- children: [/* @__PURE__ */ jsx("span", {
79
- className: "context__trigger-ring",
80
- "aria-hidden": "true",
81
- children: /* @__PURE__ */ jsx(ProgressRing, {
82
- percent,
83
- size: 16,
84
- stroke: 2.5
85
- })
86
- }), /* @__PURE__ */ jsxs("span", {
87
- className: "context__trigger-label",
88
- children: [percent.toFixed(0), "%"]
89
- })]
90
- }) });
74
+ children: /* @__PURE__ */ jsx(ProgressRing, {
75
+ percent,
76
+ size: 16,
77
+ stroke: 2.5
78
+ })
79
+ });
91
80
  }
92
- function ContextContent({ className, children, ...props }) {
93
- return /* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsx(Popover.Positioner, { children: /* @__PURE__ */ jsx(Popover.Popup, {
94
- className: cx("context__content", className),
95
- ...props,
96
- children
97
- }) }) });
81
+ function ContextContent({ className, side = "top", children, ...props }) {
82
+ return /* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsx(Popover.Positioner, {
83
+ side,
84
+ children: /* @__PURE__ */ jsx(Popover.Popup, {
85
+ className: cx("context__content", className),
86
+ ...props,
87
+ children
88
+ })
89
+ }) });
98
90
  }
99
91
  function ContextContentHeader({ className, children, ref, ...props }) {
100
92
  const { usedTokens, maxTokens, modelId } = useContextContext();
@@ -173,7 +165,6 @@ function ContextContentBody({ className, children, ref, ...props }) {
173
165
  label: "Cache",
174
166
  tokens: cacheTokens
175
167
  });
176
- if (usage?.categories) rows.push(...usage.categories);
177
168
  return /* @__PURE__ */ jsxs("div", {
178
169
  ref,
179
170
  className: cx("context__body", className),
@@ -182,20 +173,13 @@ function ContextContentBody({ className, children, ref, ...props }) {
182
173
  className: "context__rows",
183
174
  children: rows.map((row) => /* @__PURE__ */ jsxs("li", {
184
175
  className: "context__row",
185
- children: [
186
- /* @__PURE__ */ jsx("span", {
187
- className: "context__row-label",
188
- children: row.label
189
- }),
190
- /* @__PURE__ */ jsx("span", {
191
- className: "context__row-value",
192
- children: row.tokens.toLocaleString()
193
- }),
194
- row.costUsd !== void 0 ? /* @__PURE__ */ jsxs("span", {
195
- className: "context__row-cost",
196
- children: ["$", row.costUsd.toFixed(4)]
197
- }) : null
198
- ]
176
+ children: [/* @__PURE__ */ jsx("span", {
177
+ className: "context__row-label",
178
+ children: row.label
179
+ }), /* @__PURE__ */ jsx("span", {
180
+ className: "context__row-value",
181
+ children: row.tokens.toLocaleString()
182
+ })]
199
183
  }, row.label))
200
184
  })]
201
185
  });
@@ -269,10 +253,27 @@ function ContextUsageRow({ className, children, label, usageKey, defaultLabel, r
269
253
  }
270
254
  function getUsageTokens(usage, key) {
271
255
  if (!usage) return void 0;
272
- if (key === "input") return usage.input ?? usage.inputTokens;
273
- if (key === "output") return usage.output ?? usage.outputTokens;
274
- if (key === "reasoning") return usage.reasoning ?? usage.reasoningTokens;
275
- return usage.cache ?? usage.cachedInputTokens;
256
+ if (key === "input") return usage.inputTokens;
257
+ if (key === "output") return usage.outputTokens;
258
+ if (key === "reasoning") return usage.outputTokenDetails?.reasoningTokens ?? usage.reasoningTokens;
259
+ return usage.inputTokenDetails?.cacheReadTokens ?? usage.cachedInputTokens;
260
+ }
261
+ /**
262
+ * Latest `metadata.usage` in a transcript — the AI SDK convention for token
263
+ * accounting (`toUIMessageStreamResponse({ messageMetadata })`), which Think
264
+ * merges into `message.metadata` as turns finish. Structural: any message
265
+ * whose metadata carries a `usage` object qualifies.
266
+ */
267
+ function getContextUsage(messages) {
268
+ for (let i = messages.length - 1; i >= 0; i--) {
269
+ const usage = messages[i].metadata?.usage;
270
+ if (usage && typeof usage === "object") return usage;
271
+ }
272
+ }
273
+ /** Tokens occupying the context window: `totalTokens`, or input + output. */
274
+ function getContextUsedTokens(usage) {
275
+ if (!usage) return 0;
276
+ return usage.totalTokens ?? (usage.inputTokens ?? 0) + (usage.outputTokens ?? 0);
276
277
  }
277
278
  function ProgressRing({ percent, size, stroke }) {
278
279
  const radius = (size - stroke) / 2;
@@ -306,4 +307,4 @@ function ProgressRing({ percent, size, stroke }) {
306
307
  });
307
308
  }
308
309
  //#endregion
309
- export { Context, ContextCacheUsage, ContextContent, ContextContentBody, ContextContentFooter, ContextContentHeader, ContextInputUsage, ContextOutputUsage, ContextReasoningUsage, ContextTrigger };
310
+ export { Context, ContextCacheUsage, ContextContent, ContextContentBody, ContextContentFooter, ContextContentHeader, ContextInputUsage, ContextOutputUsage, ContextReasoningUsage, ContextTrigger, getContextUsage, getContextUsedTokens };
@@ -1,4 +1,4 @@
1
- import { d as DotIcon, l as ChevronRightIcon, o as CheckIcon } from "../icons-DQC4Zw5R.js";
1
+ import { a as CheckIcon, c as ChevronRightIcon, u as DotIcon } from "../icons-CZRH4FVH.js";
2
2
  import "react";
3
3
  import { jsx, jsxs } from "react/jsx-runtime";
4
4
  import { ContextMenu as ContextMenu$1 } from "@base-ui/react/context-menu";
@@ -1,5 +1,5 @@
1
1
  import { t as cx } from "../class-names-9UtZwb0J.js";
2
- import { f as DownloadIcon, t as ArrowDownIcon } from "../icons-DQC4Zw5R.js";
2
+ import { d as DownloadIcon, t as ArrowDownIcon } from "../icons-CZRH4FVH.js";
3
3
  import { Button } from "./Button.js";
4
4
  import { useStickToBottom } from "./useStickToBottom.js";
5
5
  import * as React from "react";
@@ -1,4 +1,4 @@
1
- import { F as XIcon } from "../icons-DQC4Zw5R.js";
1
+ import { P as XIcon } from "../icons-CZRH4FVH.js";
2
2
  import "react";
3
3
  import { jsx, jsxs } from "react/jsx-runtime";
4
4
  import { Dialog as Dialog$1 } from "@base-ui/react/dialog";
@@ -1,5 +1,5 @@
1
1
  import { t as cx } from "../class-names-9UtZwb0J.js";
2
- import { m as EyeOffIcon, o as CheckIcon, p as EyeIcon, u as CopyIcon } from "../icons-DQC4Zw5R.js";
2
+ import { a as CheckIcon, f as EyeIcon, l as CopyIcon, p as EyeOffIcon } from "../icons-CZRH4FVH.js";
3
3
  import { Button } from "./Button.js";
4
4
  import { Tooltip, TooltipPopup, TooltipPortal, TooltipPositioner, TooltipTrigger } from "./Tooltip.js";
5
5
  import { Badge } from "./Badge.js";
@@ -1,2 +1,2 @@
1
- import { a as FileTreeIcon, i as FileTreeFolder, n as FileTreeActions, o as FileTreeName, r as FileTreeFile, t as FileTree } from "../FileTree-D0c9Yj9U.js";
1
+ import { a as FileTreeIcon, i as FileTreeFolder, n as FileTreeActions, o as FileTreeName, r as FileTreeFile, t as FileTree } from "../FileTree-D8rtTLgK.js";
2
2
  export { FileTree, FileTreeActions, FileTreeFile, FileTreeFolder, FileTreeIcon, FileTreeName };
@@ -1,4 +1,4 @@
1
- import { d as DotIcon, l as ChevronRightIcon, o as CheckIcon } from "../icons-DQC4Zw5R.js";
1
+ import { a as CheckIcon, c as ChevronRightIcon, u as DotIcon } from "../icons-CZRH4FVH.js";
2
2
  import "react";
3
3
  import { jsx, jsxs } from "react/jsx-runtime";
4
4
  import { Menu } from "@base-ui/react/menu";
@@ -1,6 +1,6 @@
1
1
  import { r as ButtonProps } from "../Button-Ct5I6aTu.js";
2
2
  import * as React from "react";
3
- import { UIMessage } from "ai";
3
+ import { FileUIPart, UIMessage } from "ai";
4
4
  import { StreamdownProps } from "streamdown";
5
5
 
6
6
  //#region src/components/Message.d.ts
@@ -60,6 +60,20 @@ declare const MessageResponse: React.MemoExoticComponent<({
60
60
  className,
61
61
  ...props
62
62
  }: MessageResponseProps) => React.JSX.Element>;
63
+ interface MessageAttachmentProps extends Omit<React.HTMLAttributes<HTMLElement>, "part"> {
64
+ /** The AI SDK `file` part, taken whole. */
65
+ part: FileUIPart;
66
+ }
67
+ /**
68
+ * A `file` part inside a message: images render inline (click to zoom),
69
+ * anything else becomes a download chip. Covers both directions — files the
70
+ * user attached and files the agent emitted.
71
+ */
72
+ declare function MessageAttachment({
73
+ part,
74
+ className,
75
+ ...props
76
+ }: MessageAttachmentProps): React.JSX.Element;
63
77
  interface MessageActionsProps extends React.HTMLAttributes<HTMLDivElement> {}
64
78
  /**
65
79
  * Horizontal list of action buttons (copy, retry, thumbs-up, etc.) shown
@@ -214,4 +228,4 @@ declare function MessageBranchPage({
214
228
  ref?: React.Ref<HTMLSpanElement>;
215
229
  }): React.JSX.Element;
216
230
  //#endregion
217
- export { Message, MessageAction, MessageActionProps, MessageActions, MessageActionsProps, MessageBranch, MessageBranchContent, MessageBranchContentProps, MessageBranchNext, MessageBranchNextProps, MessageBranchPage, MessageBranchPageProps, MessageBranchPrevious, MessageBranchPreviousProps, MessageBranchProps, MessageBranchSelector, MessageBranchSelectorProps, MessageContent, MessageContentProps, MessageProps, MessageResponse, MessageResponseProps, MessageRole, MessageToolbar, MessageToolbarProps };
231
+ export { Message, MessageAction, MessageActionProps, MessageActions, MessageActionsProps, MessageAttachment, MessageAttachmentProps, MessageBranch, MessageBranchContent, MessageBranchContentProps, MessageBranchNext, MessageBranchNextProps, MessageBranchPage, MessageBranchPageProps, MessageBranchPrevious, MessageBranchPreviousProps, MessageBranchProps, MessageBranchSelector, MessageBranchSelectorProps, MessageContent, MessageContentProps, MessageProps, MessageResponse, MessageResponseProps, MessageRole, MessageToolbar, MessageToolbarProps };
@@ -1,7 +1,8 @@
1
1
  import { t as cx } from "../class-names-9UtZwb0J.js";
2
- import { n as ArrowLeftIcon, r as ArrowRightIcon } from "../icons-DQC4Zw5R.js";
2
+ import { m as FileIcon, n as ArrowLeftIcon, r as ArrowRightIcon } from "../icons-CZRH4FVH.js";
3
3
  import { Button } from "./Button.js";
4
4
  import { Tooltip, TooltipPopup, TooltipPortal, TooltipPositioner, TooltipTrigger } from "./Tooltip.js";
5
+ import { t as AttachmentPreview } from "../attachment-preview-ChtC3HiU.js";
5
6
  import * as React from "react";
6
7
  import { jsx, jsxs } from "react/jsx-runtime";
7
8
  import { cjk } from "@streamdown/cjk";
@@ -66,6 +67,39 @@ const MessageResponse = React.memo(function MessageResponse({ className, ...prop
66
67
  });
67
68
  });
68
69
  /**
70
+ * A `file` part inside a message: images render inline (click to zoom),
71
+ * anything else becomes a download chip. Covers both directions — files the
72
+ * user attached and files the agent emitted.
73
+ */
74
+ function MessageAttachment({ part, className, ...props }) {
75
+ const name = part.filename ?? (part.mediaType || "attachment");
76
+ if (part.mediaType.startsWith("image/")) return /* @__PURE__ */ jsx(AttachmentPreview, {
77
+ url: part.url,
78
+ filename: part.filename,
79
+ children: /* @__PURE__ */ jsx("button", {
80
+ type: "button",
81
+ className: cx("message__attachment-zoom", className),
82
+ "aria-label": `Preview ${name}`,
83
+ ...props,
84
+ children: /* @__PURE__ */ jsx("img", {
85
+ className: "message__attachment-image",
86
+ src: part.url,
87
+ alt: part.filename ?? "Attached image"
88
+ })
89
+ })
90
+ });
91
+ return /* @__PURE__ */ jsxs("a", {
92
+ className: cx("message__attachment", className),
93
+ href: part.url,
94
+ download: part.filename,
95
+ ...props,
96
+ children: [/* @__PURE__ */ jsx(FileIcon, { className: "message__attachment-icon" }), /* @__PURE__ */ jsx("span", {
97
+ className: "message__attachment-name",
98
+ children: name
99
+ })]
100
+ });
101
+ }
102
+ /**
69
103
  * Horizontal list of action buttons (copy, retry, thumbs-up, etc.) shown
70
104
  * alongside or beneath a message.
71
105
  */
@@ -82,7 +116,7 @@ function MessageActions({ className, children, ref, ...props }) {
82
116
  * A single icon button inside {@link MessageActions}. Always has an accessible
83
117
  * name; shows a tooltip on hover/focus when {@link tooltip} is set.
84
118
  */
85
- function MessageAction({ className, label, tooltip, variant = "ghost", color = "neutral", size = "sm", children, ref, ...props }) {
119
+ function MessageAction({ className, label, tooltip, variant = "ghost", color = "neutral", size = "icon-xs", children, ref, ...props }) {
86
120
  const button = /* @__PURE__ */ jsx(Button, {
87
121
  ref,
88
122
  type: "button",
@@ -190,7 +224,7 @@ function MessageBranchSelector({ className, children, ref, ...props }) {
190
224
  });
191
225
  }
192
226
  /** Button that selects the previous branch. Disabled at the first branch. */
193
- function MessageBranchPrevious({ className, label = "Previous response", variant = "ghost", color = "neutral", size = "sm", children, onClick, ref, ...props }) {
227
+ function MessageBranchPrevious({ className, label = "Previous response", variant = "ghost", color = "neutral", size = "icon-xs", children, onClick, ref, ...props }) {
194
228
  const { branchIndex, branchCount, setBranchIndex } = useMessageBranch("MessageBranchPrevious");
195
229
  return /* @__PURE__ */ jsx(Button, {
196
230
  ref,
@@ -210,7 +244,7 @@ function MessageBranchPrevious({ className, label = "Previous response", variant
210
244
  });
211
245
  }
212
246
  /** Button that selects the next branch. Disabled at the last branch. */
213
- function MessageBranchNext({ className, label = "Next response", variant = "ghost", color = "neutral", size = "sm", children, onClick, ref, ...props }) {
247
+ function MessageBranchNext({ className, label = "Next response", variant = "ghost", color = "neutral", size = "icon-xs", children, onClick, ref, ...props }) {
214
248
  const { branchIndex, branchCount, setBranchIndex } = useMessageBranch("MessageBranchNext");
215
249
  return /* @__PURE__ */ jsx(Button, {
216
250
  ref,
@@ -242,4 +276,4 @@ function MessageBranchPage({ className, format, ref, ...props }) {
242
276
  });
243
277
  }
244
278
  //#endregion
245
- export { Message, MessageAction, MessageActions, MessageBranch, MessageBranchContent, MessageBranchNext, MessageBranchPage, MessageBranchPrevious, MessageBranchSelector, MessageContent, MessageResponse, MessageToolbar };
279
+ export { Message, MessageAction, MessageActions, MessageAttachment, MessageBranch, MessageBranchContent, MessageBranchNext, MessageBranchPage, MessageBranchPrevious, MessageBranchSelector, MessageContent, MessageResponse, MessageToolbar };
@@ -1,5 +1,5 @@
1
1
  import { t as cx } from "../class-names-9UtZwb0J.js";
2
- import { k as SearchIcon, s as ChevronDownIcon } from "../icons-DQC4Zw5R.js";
2
+ import { O as SearchIcon, o as ChevronDownIcon } from "../icons-CZRH4FVH.js";
3
3
  import { Button } from "./Button.js";
4
4
  import { Dialog, DialogBackdrop, DialogPopup, DialogPortal, DialogTitle, DialogTrigger } from "./Dialog.js";
5
5
  import * as React from "react";
@@ -1,4 +1,4 @@
1
- import { s as ChevronDownIcon } from "../icons-DQC4Zw5R.js";
1
+ import { o as ChevronDownIcon } from "../icons-CZRH4FVH.js";
2
2
  import * as React from "react";
3
3
  import { jsx, jsxs } from "react/jsx-runtime";
4
4
  import { NavigationMenu as NavigationMenu$1 } from "@base-ui/react/navigation-menu";
@@ -1,12 +1,12 @@
1
1
  import { Accordion, AccordionItem, AccordionPanel, AccordionTrigger } from "./Accordion.js";
2
+ import { Separator } from "./Separator.js";
2
3
  import { Button } from "./Button.js";
3
4
  import { Tooltip, TooltipPopup, TooltipPortal, TooltipPositioner, TooltipTrigger } from "./Tooltip.js";
4
- import { Badge } from "./Badge.js";
5
5
  import { AlertDialog, AlertDialogBackdrop, AlertDialogClose, AlertDialogDescription, AlertDialogPopup, AlertDialogPortal, AlertDialogTitle } from "./AlertDialog.js";
6
+ import { Badge } from "./Badge.js";
6
7
  import { Slider, SliderControl, SliderIndicator, SliderThumb, SliderTrack } from "./Slider.js";
7
8
  import { Card } from "./Card.js";
8
9
  import { Checkbox } from "./Checkbox.js";
9
- import { Separator } from "./Separator.js";
10
10
  import { Switch, SwitchThumb } from "./Switch.js";
11
11
  import { Label } from "./Label.js";
12
12
  import { ToggleGroup, ToggleGroupItem } from "./ToggleGroup.js";