@tetrascience-npm/tetrascience-react-ui 0.5.0-beta.40.1 → 0.5.0-beta.42.1

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 (99) hide show
  1. package/dist/components/ai/attachments.cjs +2 -0
  2. package/dist/components/ai/attachments.cjs.map +1 -0
  3. package/dist/components/ai/attachments.js +224 -0
  4. package/dist/components/ai/attachments.js.map +1 -0
  5. package/dist/components/ai/chain-of-thought.cjs +2 -0
  6. package/dist/components/ai/chain-of-thought.cjs.map +1 -0
  7. package/dist/components/ai/chain-of-thought.js +145 -0
  8. package/dist/components/ai/chain-of-thought.js.map +1 -0
  9. package/dist/components/ai/confirmation.cjs +2 -0
  10. package/dist/components/ai/confirmation.cjs.map +1 -0
  11. package/dist/components/ai/confirmation.js +109 -0
  12. package/dist/components/ai/confirmation.js.map +1 -0
  13. package/dist/components/ai/context.cjs +2 -0
  14. package/dist/components/ai/context.cjs.map +1 -0
  15. package/dist/components/ai/context.js +266 -0
  16. package/dist/components/ai/context.js.map +1 -0
  17. package/dist/components/ai/conversation.cjs +4 -0
  18. package/dist/components/ai/conversation.cjs.map +1 -0
  19. package/dist/components/ai/conversation.js +108 -0
  20. package/dist/components/ai/conversation.js.map +1 -0
  21. package/dist/components/ai/inline-citation.cjs +2 -0
  22. package/dist/components/ai/inline-citation.cjs.map +1 -0
  23. package/dist/components/ai/inline-citation.js +182 -0
  24. package/dist/components/ai/inline-citation.js.map +1 -0
  25. package/dist/components/ai/message.cjs +2 -0
  26. package/dist/components/ai/message.cjs.map +1 -0
  27. package/dist/components/ai/message.js +237 -0
  28. package/dist/components/ai/message.js.map +1 -0
  29. package/dist/components/ai/model-selector.cjs +2 -0
  30. package/dist/components/ai/model-selector.cjs.map +1 -0
  31. package/dist/components/ai/model-selector.js +77 -0
  32. package/dist/components/ai/model-selector.js.map +1 -0
  33. package/dist/components/ai/prompt-input.cjs +2 -0
  34. package/dist/components/ai/prompt-input.cjs.map +1 -0
  35. package/dist/components/ai/prompt-input.js +774 -0
  36. package/dist/components/ai/prompt-input.js.map +1 -0
  37. package/dist/components/ai/queue.cjs +2 -0
  38. package/dist/components/ai/queue.cjs.map +1 -0
  39. package/dist/components/ai/queue.js +209 -0
  40. package/dist/components/ai/queue.js.map +1 -0
  41. package/dist/components/ai/reasoning.cjs +2 -0
  42. package/dist/components/ai/reasoning.cjs.map +1 -0
  43. package/dist/components/ai/reasoning.js +129 -0
  44. package/dist/components/ai/reasoning.js.map +1 -0
  45. package/dist/components/ai/shimmer.cjs +2 -0
  46. package/dist/components/ai/shimmer.cjs.map +1 -0
  47. package/dist/components/ai/shimmer.js +49 -0
  48. package/dist/components/ai/shimmer.js.map +1 -0
  49. package/dist/components/ai/sources.cjs +2 -0
  50. package/dist/components/ai/sources.cjs.map +1 -0
  51. package/dist/components/ai/sources.js +54 -0
  52. package/dist/components/ai/sources.js.map +1 -0
  53. package/dist/components/ai/speech-input.cjs +2 -0
  54. package/dist/components/ai/speech-input.cjs.map +1 -0
  55. package/dist/components/ai/speech-input.js +123 -0
  56. package/dist/components/ai/speech-input.js.map +1 -0
  57. package/dist/components/ai/stream-status.cjs +2 -0
  58. package/dist/components/ai/stream-status.cjs.map +1 -0
  59. package/dist/components/ai/stream-status.js +106 -0
  60. package/dist/components/ai/stream-status.js.map +1 -0
  61. package/dist/components/ai/suggestion.cjs +2 -0
  62. package/dist/components/ai/suggestion.cjs.map +1 -0
  63. package/dist/components/ai/suggestion.js +38 -0
  64. package/dist/components/ai/suggestion.js.map +1 -0
  65. package/dist/components/ai/task.cjs +2 -0
  66. package/dist/components/ai/task.cjs.map +1 -0
  67. package/dist/components/ai/task.js +94 -0
  68. package/dist/components/ai/task.js.map +1 -0
  69. package/dist/components/ai/tool.cjs +2 -0
  70. package/dist/components/ai/tool.cjs.map +1 -0
  71. package/dist/components/ai/tool.js +143 -0
  72. package/dist/components/ai/tool.js.map +1 -0
  73. package/dist/components/composed/Chat/Chat.cjs +2 -0
  74. package/dist/components/composed/Chat/Chat.cjs.map +1 -0
  75. package/dist/components/composed/Chat/Chat.js +167 -0
  76. package/dist/components/composed/Chat/Chat.js.map +1 -0
  77. package/dist/components/ui/code-block.cjs +4 -0
  78. package/dist/components/ui/code-block.cjs.map +1 -0
  79. package/dist/components/ui/code-block.js +306 -0
  80. package/dist/components/ui/code-block.js.map +1 -0
  81. package/dist/components/ui/data-table/data-table-filter.cjs +2 -0
  82. package/dist/components/ui/data-table/data-table-filter.cjs.map +1 -0
  83. package/dist/components/ui/data-table/data-table-filter.js +178 -0
  84. package/dist/components/ui/data-table/data-table-filter.js.map +1 -0
  85. package/dist/components/ui/data-table/data-table.cjs +1 -1
  86. package/dist/components/ui/data-table/data-table.cjs.map +1 -1
  87. package/dist/components/ui/data-table/data-table.js +244 -195
  88. package/dist/components/ui/data-table/data-table.js.map +1 -1
  89. package/dist/components/ui/progress.cjs +2 -0
  90. package/dist/components/ui/progress.cjs.map +1 -0
  91. package/dist/components/ui/progress.js +32 -0
  92. package/dist/components/ui/progress.js.map +1 -0
  93. package/dist/index.cjs +1 -1
  94. package/dist/index.css +1 -1
  95. package/dist/index.d.ts +1182 -1
  96. package/dist/index.js +572 -368
  97. package/dist/index.js.map +1 -1
  98. package/dist/index.tailwind.css +1 -1
  99. package/package.json +12 -1
@@ -0,0 +1,109 @@
1
+ import { jsx as n, Fragment as u } from "react/jsx-runtime";
2
+ import { AnimatePresence as b, motion as v } from "motion/react";
3
+ import { createContext as x, useMemo as h, useState as g, useEffect as A, useContext as E } from "react";
4
+ import { Button as N } from "../ui/button.js";
5
+ import { CodeBlock as j } from "../ui/code-block.js";
6
+ import { Kbd as w } from "../ui/kbd.js";
7
+ import { cn as r } from "../../lib/utils.js";
8
+ const l = x(null), a = () => {
9
+ const e = E(l);
10
+ if (!e)
11
+ throw new Error("Confirmation components must be used within Confirmation");
12
+ return e;
13
+ }, y = 1500, R = ({
14
+ className: e,
15
+ approval: o,
16
+ state: t,
17
+ children: m,
18
+ ...s
19
+ }) => {
20
+ const d = h(() => ({ approval: o, state: t }), [o, t]), [p, f] = g(!0), c = o?.approved === !0 && (t === "approval-responded" || t === "output-available" || t === "output-denied");
21
+ if (A(() => {
22
+ if (c) {
23
+ const i = setTimeout(() => f(!1), y);
24
+ return () => clearTimeout(i);
25
+ }
26
+ }, [c]), !o || t === "input-streaming" || t === "input-available")
27
+ return null;
28
+ const C = Object.fromEntries(
29
+ Object.entries(s).filter(([i]) => i.startsWith("data-") || i.startsWith("aria-"))
30
+ );
31
+ return /* @__PURE__ */ n(l.Provider, { value: d, children: /* @__PURE__ */ n(b, { children: p && /* @__PURE__ */ n(
32
+ v.div,
33
+ {
34
+ ...C,
35
+ className: r(
36
+ "flex flex-col gap-4 rounded-xl border bg-card p-5 shadow-sm",
37
+ e
38
+ ),
39
+ exit: { opacity: 0, scale: 0.96 },
40
+ id: s.id,
41
+ style: s.style,
42
+ transition: { duration: 0.5, ease: "easeOut" },
43
+ children: m
44
+ }
45
+ ) }) });
46
+ }, V = ({
47
+ className: e,
48
+ children: o,
49
+ ...t
50
+ }) => /* @__PURE__ */ n(
51
+ "h3",
52
+ {
53
+ className: r("font-semibold text-base text-foreground", e),
54
+ ...t,
55
+ children: o
56
+ }
57
+ ), W = ({
58
+ className: e,
59
+ children: o,
60
+ ...t
61
+ }) => /* @__PURE__ */ n(j, { className: r(e), ...t, language: "bash", code: o?.toString() ?? "" }), _ = ({ children: e }) => {
62
+ const { state: o } = a();
63
+ return o !== "approval-requested" ? null : /* @__PURE__ */ n(u, { children: e });
64
+ }, F = ({ children: e }) => {
65
+ const { approval: o, state: t } = a();
66
+ return !o?.approved || t !== "approval-responded" && t !== "output-denied" && t !== "output-available" ? null : /* @__PURE__ */ n(u, { children: e });
67
+ }, H = ({ children: e }) => {
68
+ const { approval: o, state: t } = a();
69
+ return o?.approved !== !1 || t !== "approval-responded" && t !== "output-denied" && t !== "output-available" ? null : /* @__PURE__ */ n(u, { children: e });
70
+ }, I = ({
71
+ className: e,
72
+ ...o
73
+ }) => {
74
+ const { state: t } = a();
75
+ return t !== "approval-requested" ? null : /* @__PURE__ */ n(
76
+ "div",
77
+ {
78
+ className: r("flex items-center justify-between gap-2", e),
79
+ ...o
80
+ }
81
+ );
82
+ }, K = ({
83
+ className: e,
84
+ size: o = "sm",
85
+ ...t
86
+ }) => /* @__PURE__ */ n(
87
+ N,
88
+ {
89
+ className: r("gap-1.5", e),
90
+ size: o,
91
+ type: "button",
92
+ ...t
93
+ }
94
+ ), L = ({
95
+ className: e,
96
+ ...o
97
+ }) => /* @__PURE__ */ n(w, { className: r("ml-0.5", e), ...o });
98
+ export {
99
+ R as Confirmation,
100
+ F as ConfirmationAccepted,
101
+ K as ConfirmationAction,
102
+ I as ConfirmationActions,
103
+ W as ConfirmationCode,
104
+ H as ConfirmationRejected,
105
+ _ as ConfirmationRequest,
106
+ L as ConfirmationShortcut,
107
+ V as ConfirmationTitle
108
+ };
109
+ //# sourceMappingURL=confirmation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"confirmation.js","sources":["../../../src/components/ai/confirmation.tsx"],"sourcesContent":["import { AnimatePresence, motion } from \"motion/react\";\nimport { createContext, useContext, useEffect, useMemo, useState } from \"react\";\n\n\nimport type { ToolUIPart } from \"ai\";\nimport type { ComponentProps, PropsWithChildren, ReactNode } from \"react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport { CodeBlock } from \"@/components/ui/code-block\";\nimport { Kbd } from \"@/components/ui/kbd\";\nimport { cn } from \"@/lib/utils\";\n\n\ntype ToolUIPartApproval =\n | { id: string; approved?: never; reason?: never }\n | { id: string; approved: boolean; reason?: string }\n | { id: string; approved: true; reason?: string }\n | { id: string; approved: false; reason?: string }\n | undefined;\n\ninterface ConfirmationContextValue {\n approval: ToolUIPartApproval;\n state: ToolUIPart[\"state\"];\n}\n\nconst ConfirmationContext = createContext<ConfirmationContextValue | null>(null);\n\nconst useConfirmation = () => {\n const context = useContext(ConfirmationContext);\n if (!context) {\n throw new Error(\"Confirmation components must be used within Confirmation\");\n }\n return context;\n};\n\n// ---------------------------------------------------------------------------\n// Confirmation (root)\n// ---------------------------------------------------------------------------\n\nexport type ConfirmationProps = ComponentProps<\"div\"> & {\n approval?: ToolUIPartApproval;\n state: ToolUIPart[\"state\"];\n};\n\nconst ACCEPTED_HIDE_DELAY = 1500;\n\nexport const Confirmation = ({\n className,\n approval,\n state,\n children,\n ...props\n}: ConfirmationProps) => {\n const contextValue = useMemo(() => ({ approval, state }), [approval, state]);\n const [visible, setVisible] = useState(true);\n\n const isAccepted =\n approval?.approved === true &&\n (state === \"approval-responded\" ||\n state === \"output-available\" ||\n state === \"output-denied\");\n\n useEffect(() => {\n if (isAccepted) {\n const timer = setTimeout(() => setVisible(false), ACCEPTED_HIDE_DELAY);\n return () => clearTimeout(timer);\n }\n }, [isAccepted]);\n\n if (!approval || state === \"input-streaming\" || state === \"input-available\") {\n return null;\n }\n\n // Pass through data-* and aria-* only; drop event handlers to avoid\n // onDrag type conflict between React and framer-motion.\n const passthroughProps = Object.fromEntries(\n Object.entries(props).filter(([k]) => k.startsWith(\"data-\") || k.startsWith(\"aria-\"))\n );\n\n return (\n <ConfirmationContext.Provider value={contextValue}>\n <AnimatePresence>\n {visible && (\n <motion.div\n {...passthroughProps}\n className={cn(\n \"flex flex-col gap-4 rounded-xl border bg-card p-5 shadow-sm\",\n className\n )}\n exit={{ opacity: 0, scale: 0.96 }}\n id={props.id}\n style={props.style}\n transition={{ duration: 0.5, ease: \"easeOut\" }}\n >\n {children}\n </motion.div>\n )}\n </AnimatePresence>\n </ConfirmationContext.Provider>\n );\n};\n\n// ---------------------------------------------------------------------------\n// ConfirmationTitle\n// ---------------------------------------------------------------------------\n\nexport type ConfirmationTitleProps = PropsWithChildren<ComponentProps<\"h3\">>;\n\nexport const ConfirmationTitle = ({\n className,\n children,\n ...props\n}: ConfirmationTitleProps) => (\n <h3\n className={cn(\"font-semibold text-base text-foreground\", className)}\n {...props}\n >\n {children}\n </h3>\n);\n\n// ---------------------------------------------------------------------------\n// ConfirmationCode — monospace command/code block\n// ---------------------------------------------------------------------------\n\nexport type ConfirmationCodeProps = ComponentProps<typeof CodeBlock>;\n\nexport const ConfirmationCode = ({\n className,\n children,\n ...props\n}: ConfirmationCodeProps) => (\n <CodeBlock className={cn(className)} {...props} language=\"bash\" code={children?.toString() ?? ''} />\n);\n\n// ---------------------------------------------------------------------------\n// ConfirmationRequest / Accepted / Rejected — conditional renderers\n// ---------------------------------------------------------------------------\n\nexport const ConfirmationRequest = ({ children }: { children?: ReactNode }) => {\n const { state } = useConfirmation();\n if (state !== \"approval-requested\") return null;\n return <>{children}</>;\n};\n\nexport const ConfirmationAccepted = ({ children }: { children?: ReactNode }) => {\n const { approval, state } = useConfirmation();\n if (\n !approval?.approved ||\n (state !== \"approval-responded\" &&\n state !== \"output-denied\" &&\n state !== \"output-available\")\n ) {\n return null;\n }\n return <>{children}</>;\n};\n\nexport const ConfirmationRejected = ({ children }: { children?: ReactNode }) => {\n const { approval, state } = useConfirmation();\n if (\n approval?.approved !== false ||\n (state !== \"approval-responded\" &&\n state !== \"output-denied\" &&\n state !== \"output-available\")\n ) {\n return null;\n }\n return <>{children}</>;\n};\n\n// ---------------------------------------------------------------------------\n// ConfirmationActions — deny left, allow buttons right\n// ---------------------------------------------------------------------------\n\nexport type ConfirmationActionsProps = ComponentProps<\"div\">;\n\nexport const ConfirmationActions = ({\n className,\n ...props\n}: ConfirmationActionsProps) => {\n const { state } = useConfirmation();\n if (state !== \"approval-requested\") return null;\n return (\n <div\n className={cn(\"flex items-center justify-between gap-2\", className)}\n {...props}\n />\n );\n};\n\n// ---------------------------------------------------------------------------\n// ConfirmationAction — individual button\n// ---------------------------------------------------------------------------\n\nexport type ConfirmationActionProps = ComponentProps<typeof Button>;\n\nexport const ConfirmationAction = ({\n className,\n size = \"sm\",\n ...props\n}: ConfirmationActionProps) => (\n <Button\n className={cn(\"gap-1.5\", className)}\n size={size}\n type=\"button\"\n {...props}\n />\n);\n\n// ---------------------------------------------------------------------------\n// ConfirmationShortcut — keyboard shortcut label inside a button\n// ---------------------------------------------------------------------------\n\nexport type ConfirmationShortcutProps = ComponentProps<typeof Kbd>;\n\nexport const ConfirmationShortcut = ({\n className,\n ...props\n}: ConfirmationShortcutProps) => (\n <Kbd className={cn(\"ml-0.5\", className)} {...props} />\n);\n"],"names":["ConfirmationContext","createContext","useConfirmation","context","useContext","ACCEPTED_HIDE_DELAY","Confirmation","className","approval","state","children","props","contextValue","useMemo","visible","setVisible","useState","isAccepted","useEffect","timer","passthroughProps","k","jsx","AnimatePresence","motion","cn","ConfirmationTitle","ConfirmationCode","CodeBlock","ConfirmationRequest","ConfirmationAccepted","ConfirmationRejected","ConfirmationActions","ConfirmationAction","size","Button","ConfirmationShortcut","Kbd"],"mappings":";;;;;;;AAyBA,MAAMA,IAAsBC,EAA+C,IAAI,GAEzEC,IAAkB,MAAM;AAC5B,QAAMC,IAAUC,EAAWJ,CAAmB;AAC9C,MAAI,CAACG;AACH,UAAM,IAAI,MAAM,0DAA0D;AAE5E,SAAOA;AACT,GAWME,IAAsB,MAEfC,IAAe,CAAC;AAAA,EAC3B,WAAAC;AAAA,EACA,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,GAAGC;AACL,MAAyB;AACvB,QAAMC,IAAeC,EAAQ,OAAO,EAAE,UAAAL,GAAU,OAAAC,MAAU,CAACD,GAAUC,CAAK,CAAC,GACrE,CAACK,GAASC,CAAU,IAAIC,EAAS,EAAI,GAErCC,IACJT,GAAU,aAAa,OACtBC,MAAU,wBACTA,MAAU,sBACVA,MAAU;AASd,MAPAS,EAAU,MAAM;AACd,QAAID,GAAY;AACd,YAAME,IAAQ,WAAW,MAAMJ,EAAW,EAAK,GAAGV,CAAmB;AACrE,aAAO,MAAM,aAAac,CAAK;AAAA,IACjC;AAAA,EACF,GAAG,CAACF,CAAU,CAAC,GAEX,CAACT,KAAYC,MAAU,qBAAqBA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,GAAU,OAAAC,EAAA,IAAUP,EAAA;AAC5B,SACE,CAACM,GAAU,YACVC,MAAU,wBACTA,MAAU,mBACVA,MAAU,qBAEL,8BAEC,UAAAC,GAAS;AACrB,GAEaqB,IAAuB,CAAC,EAAE,UAAArB,QAAyC;AAC9E,QAAM,EAAE,UAAAF,GAAU,OAAAC,EAAA,IAAUP,EAAA;AAC5B,SACEM,GAAU,aAAa,MACtBC,MAAU,wBACTA,MAAU,mBACVA,MAAU,qBAEL,8BAEC,UAAAC,GAAS;AACrB,GAQasB,IAAsB,CAAC;AAAA,EAClC,WAAAzB;AAAA,EACA,GAAGI;AACL,MAAgC;AAC9B,QAAM,EAAE,OAAAF,EAAA,IAAUP,EAAA;AAClB,SAAIO,MAAU,uBAA6B,OAEzC,gBAAAa;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAWG,EAAG,2CAA2ClB,CAAS;AAAA,MACjE,GAAGI;AAAA,IAAA;AAAA,EAAA;AAGV,GAQasB,IAAqB,CAAC;AAAA,EACjC,WAAA1B;AAAA,EACA,MAAA2B,IAAO;AAAA,EACP,GAAGvB;AACL,MACE,gBAAAW;AAAA,EAACa;AAAA,EAAA;AAAA,IACC,WAAWV,EAAG,WAAWlB,CAAS;AAAA,IAClC,MAAA2B;AAAA,IACA,MAAK;AAAA,IACJ,GAAGvB;AAAA,EAAA;AACN,GASWyB,IAAuB,CAAC;AAAA,EACnC,WAAA7B;AAAA,EACA,GAAGI;AACL,MACE,gBAAAW,EAACe,KAAI,WAAWZ,EAAG,UAAUlB,CAAS,GAAI,GAAGI,EAAA,CAAO;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),f=require("react"),b=require("../ui/button.cjs"),p=require("../ui/hover-card.cjs"),k=require("../ui/progress.cjs"),i=require("../../lib/utils.cjs"),S=100,g=10,h=24,l=12,j=2,U=.75,I=.9,T=e=>e>=I?"danger":e>=U?"warning":"normal",C={normal:"text-muted-foreground",warning:"text-amber-500",danger:"text-destructive"},O={normal:"",warning:"[&_[data-slot=progress-indicator]]:bg-amber-500",danger:"[&_[data-slot=progress-indicator]]:bg-destructive"},N=new Intl.NumberFormat("en-US",{currency:"USD",style:"currency"}),x=e=>e===void 0?void 0:N.format(e),y=f.createContext(null),u=()=>{const e=f.useContext(y);if(!e)throw new Error("Context components must be used within Context");return e},R=({usedTokens:e,maxTokens:n,usage:s,cost:o,...c})=>{const r=f.useMemo(()=>({cost:o,maxTokens:n,usage:s,usedTokens:e}),[o,n,s,e]);return t.jsx(y.Provider,{value:r,children:t.jsx(p.HoverCard,{closeDelay:0,openDelay:0,...c})})},D=()=>{const{usedTokens:e,maxTokens:n}=u(),s=2*Math.PI*g,o=e/n,c=s*(1-o);return t.jsxs("svg",{"aria-label":"Model context usage",height:"20",role:"img",style:{color:"currentcolor"},viewBox:`0 0 ${h} ${h}`,width:"20",children:[t.jsx("circle",{cx:l,cy:l,fill:"none",opacity:"0.25",r:g,stroke:"currentColor",strokeWidth:j}),t.jsx("circle",{cx:l,cy:l,fill:"none",opacity:"0.7",r:g,stroke:"currentColor",strokeDasharray:`${s} ${s}`,strokeDashoffset:c,strokeLinecap:"round",strokeWidth:j,style:{transform:"rotate(-90deg)",transformOrigin:"center"}})]})},F=({children:e,showPercentage:n=!1,...s})=>{const{usedTokens:o,maxTokens:c}=u(),r=o/c,a=T(r),m=new Intl.NumberFormat("en-US",{maximumFractionDigits:1,style:"percent"}).format(r);return t.jsx(p.HoverCardTrigger,{asChild:!0,children:e??t.jsxs(b.Button,{type:"button",variant:"ghost",...s,children:[n?t.jsx("span",{className:i.cn("font-medium",C[a]),children:m}):null,t.jsx("span",{className:C[a],children:t.jsx(D,{})})]})})},_=({className:e,...n})=>t.jsx(p.HoverCardContent,{className:i.cn("min-w-60 divide-y overflow-hidden p-0",e),...n}),E=({children:e,className:n,...s})=>{const{usedTokens:o,maxTokens:c}=u(),r=o/c,a=T(r),m=new Intl.NumberFormat("en-US",{maximumFractionDigits:1,style:"percent"}).format(r),v=new Intl.NumberFormat("en-US",{notation:"compact"}).format(o),w=new Intl.NumberFormat("en-US",{notation:"compact"}).format(c);return t.jsx("div",{className:i.cn("w-full space-y-2 p-3",n),...s,children:e??t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs",children:[t.jsx("p",{className:i.cn(C[a]),children:m}),t.jsxs("p",{className:"font-mono text-muted-foreground",children:[v," / ",w]})]}),t.jsx("div",{className:"space-y-2",children:t.jsx(k.Progress,{className:i.cn("bg-muted",O[a]),value:r*S})})]})})},P=({children:e,className:n,...s})=>t.jsx("div",{className:i.cn("w-full p-3",n),...s,children:e}),H=({children:e,className:n,...s})=>{const{cost:o}=u(),c=o?.total===void 0?"—":N.format(o.total);return t.jsx("div",{className:i.cn("flex w-full items-center justify-between gap-3 bg-muted/50 p-3 text-xs",n),...s,children:e??t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-muted-foreground",children:"Total cost"}),t.jsx("span",{children:c})]})})},d=({tokens:e,costText:n})=>t.jsxs("span",{children:[e===void 0?"—":new Intl.NumberFormat("en-US",{notation:"compact"}).format(e),n?t.jsxs("span",{className:"ml-2 text-muted-foreground",children:["• ",n]}):null]}),A=({className:e,children:n,...s})=>{const{usage:o,cost:c}=u(),r=o?.inputTokens??0;if(n)return n;if(!r)return null;const a=x(c?.input);return t.jsxs("div",{className:i.cn("flex items-center justify-between text-xs",e),...s,children:[t.jsx("span",{className:"text-muted-foreground",children:"Input"}),t.jsx(d,{costText:a,tokens:r})]})},q=({className:e,children:n,...s})=>{const{usage:o,cost:c}=u(),r=o?.outputTokens??0;if(n)return n;if(!r)return null;const a=x(c?.output);return t.jsxs("div",{className:i.cn("flex items-center justify-between text-xs",e),...s,children:[t.jsx("span",{className:"text-muted-foreground",children:"Output"}),t.jsx(d,{costText:a,tokens:r})]})},M=({className:e,children:n,...s})=>{const{usage:o,cost:c}=u(),r=o?.reasoningTokens??0;if(n)return n;if(!r)return null;const a=x(c?.reasoning);return t.jsxs("div",{className:i.cn("flex items-center justify-between text-xs",e),...s,children:[t.jsx("span",{className:"text-muted-foreground",children:"Reasoning"}),t.jsx(d,{costText:a,tokens:r})]})},W=({className:e,children:n,...s})=>{const{usage:o,cost:c}=u(),r=o?.cachedInputTokens??0;if(n)return n;if(!r)return null;const a=x(c?.cache);return t.jsxs("div",{className:i.cn("flex items-center justify-between text-xs",e),...s,children:[t.jsx("span",{className:"text-muted-foreground",children:"Cache"}),t.jsx(d,{costText:a,tokens:r})]})};exports.Context=R;exports.ContextCacheUsage=W;exports.ContextContent=_;exports.ContextContentBody=P;exports.ContextContentFooter=H;exports.ContextContentHeader=E;exports.ContextInputUsage=A;exports.ContextOutputUsage=q;exports.ContextReasoningUsage=M;exports.ContextTrigger=F;
2
+ //# sourceMappingURL=context.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.cjs","sources":["../../../src/components/ai/context.tsx"],"sourcesContent":["import { createContext, useContext, useMemo } from \"react\";\n\nimport type { LanguageModelUsage } from \"ai\";\nimport type { ComponentProps } from \"react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport {\n HoverCard,\n HoverCardContent,\n HoverCardTrigger,\n} from \"@/components/ui/hover-card\";\nimport { Progress } from \"@/components/ui/progress\";\nimport { cn } from \"@/lib/utils\";\n\n\nconst PERCENT_MAX = 100;\nconst ICON_RADIUS = 10;\nconst ICON_VIEWBOX = 24;\nconst ICON_CENTER = 12;\nconst ICON_STROKE_WIDTH = 2;\nconst WARN_THRESHOLD = 0.75;\nconst DANGER_THRESHOLD = 0.9;\n\ntype UsageStatus = \"normal\" | \"warning\" | \"danger\";\n\nconst getUsageStatus = (pct: number): UsageStatus => {\n if (pct >= DANGER_THRESHOLD) return \"danger\";\n if (pct >= WARN_THRESHOLD) return \"warning\";\n return \"normal\";\n};\n\nconst STATUS_TEXT: Record<UsageStatus, string> = {\n normal: \"text-muted-foreground\",\n warning: \"text-amber-500\",\n danger: \"text-destructive\",\n};\n\nconst STATUS_PROGRESS: Record<UsageStatus, string> = {\n normal: \"\",\n warning: \"[&_[data-slot=progress-indicator]]:bg-amber-500\",\n danger: \"[&_[data-slot=progress-indicator]]:bg-destructive\",\n};\n\nconst USD_FORMAT = new Intl.NumberFormat(\"en-US\", {\n currency: \"USD\",\n style: \"currency\",\n});\n\nconst formatUSD = (value: number | undefined): string | undefined =>\n value === undefined ? undefined : USD_FORMAT.format(value);\n\nexport interface CostBreakdown {\n total?: number;\n input?: number;\n output?: number;\n reasoning?: number;\n cache?: number;\n}\n\ninterface ContextSchema {\n usedTokens: number;\n maxTokens: number;\n usage?: LanguageModelUsage;\n cost?: CostBreakdown;\n}\n\nconst ContextContext = createContext<ContextSchema | null>(null);\n\nconst useContextValue = () => {\n const context = useContext(ContextContext);\n\n if (!context) {\n throw new Error(\"Context components must be used within Context\");\n }\n\n return context;\n};\n\nexport type ContextProps = ComponentProps<typeof HoverCard> & ContextSchema;\n\nexport const Context = ({\n usedTokens,\n maxTokens,\n usage,\n cost,\n ...props\n}: ContextProps) => {\n const contextValue = useMemo(\n () => ({ cost, maxTokens, usage, usedTokens }),\n [cost, maxTokens, usage, usedTokens]\n );\n\n return (\n <ContextContext.Provider value={contextValue}>\n <HoverCard closeDelay={0} openDelay={0} {...props} />\n </ContextContext.Provider>\n );\n};\n\nconst ContextIcon = () => {\n const { usedTokens, maxTokens } = useContextValue();\n const circumference = 2 * Math.PI * ICON_RADIUS;\n const usedPercent = usedTokens / maxTokens;\n const dashOffset = circumference * (1 - usedPercent);\n\n return (\n <svg\n aria-label=\"Model context usage\"\n height=\"20\"\n role=\"img\"\n style={{ color: \"currentcolor\" }}\n viewBox={`0 0 ${ICON_VIEWBOX} ${ICON_VIEWBOX}`}\n width=\"20\"\n >\n <circle\n cx={ICON_CENTER}\n cy={ICON_CENTER}\n fill=\"none\"\n opacity=\"0.25\"\n r={ICON_RADIUS}\n stroke=\"currentColor\"\n strokeWidth={ICON_STROKE_WIDTH}\n />\n <circle\n cx={ICON_CENTER}\n cy={ICON_CENTER}\n fill=\"none\"\n opacity=\"0.7\"\n r={ICON_RADIUS}\n stroke=\"currentColor\"\n strokeDasharray={`${circumference} ${circumference}`}\n strokeDashoffset={dashOffset}\n strokeLinecap=\"round\"\n strokeWidth={ICON_STROKE_WIDTH}\n style={{ transform: \"rotate(-90deg)\", transformOrigin: \"center\" }}\n />\n </svg>\n );\n};\n\nexport type ContextTriggerProps = ComponentProps<typeof Button> & {\n showPercentage?: boolean;\n};\n\nexport const ContextTrigger = ({\n children,\n showPercentage = false,\n ...props\n}: ContextTriggerProps) => {\n const { usedTokens, maxTokens } = useContextValue();\n const usedPercent = usedTokens / maxTokens;\n const status = getUsageStatus(usedPercent);\n const renderedPercent = new Intl.NumberFormat(\"en-US\", {\n maximumFractionDigits: 1,\n style: \"percent\",\n }).format(usedPercent);\n\n return (\n <HoverCardTrigger asChild>\n {children ?? (\n <Button type=\"button\" variant=\"ghost\" {...props}>\n {showPercentage ? (\n <span className={cn(\"font-medium\", STATUS_TEXT[status])}>\n {renderedPercent}\n </span>\n ) : null}\n <span className={STATUS_TEXT[status]}>\n <ContextIcon />\n </span>\n </Button>\n )}\n </HoverCardTrigger>\n );\n};\n\nexport type ContextContentProps = ComponentProps<typeof HoverCardContent>;\n\nexport const ContextContent = ({\n className,\n ...props\n}: ContextContentProps) => (\n <HoverCardContent\n className={cn(\"min-w-60 divide-y overflow-hidden p-0\", className)}\n {...props}\n />\n);\n\nexport type ContextContentHeaderProps = ComponentProps<\"div\">;\n\nexport const ContextContentHeader = ({\n children,\n className,\n ...props\n}: ContextContentHeaderProps) => {\n const { usedTokens, maxTokens } = useContextValue();\n const usedPercent = usedTokens / maxTokens;\n const status = getUsageStatus(usedPercent);\n const displayPct = new Intl.NumberFormat(\"en-US\", {\n maximumFractionDigits: 1,\n style: \"percent\",\n }).format(usedPercent);\n const used = new Intl.NumberFormat(\"en-US\", {\n notation: \"compact\",\n }).format(usedTokens);\n const total = new Intl.NumberFormat(\"en-US\", {\n notation: \"compact\",\n }).format(maxTokens);\n\n return (\n <div className={cn(\"w-full space-y-2 p-3\", className)} {...props}>\n {children ?? (\n <>\n <div className=\"flex items-center justify-between gap-3 text-xs\">\n <p className={cn(STATUS_TEXT[status])}>{displayPct}</p>\n <p className=\"font-mono text-muted-foreground\">\n {used} / {total}\n </p>\n </div>\n <div className=\"space-y-2\">\n <Progress\n className={cn(\"bg-muted\", STATUS_PROGRESS[status])}\n value={usedPercent * PERCENT_MAX}\n />\n </div>\n </>\n )}\n </div>\n );\n};\n\nexport type ContextContentBodyProps = ComponentProps<\"div\">;\n\nexport const ContextContentBody = ({\n children,\n className,\n ...props\n}: ContextContentBodyProps) => (\n <div className={cn(\"w-full p-3\", className)} {...props}>\n {children}\n </div>\n);\n\nexport type ContextContentFooterProps = ComponentProps<\"div\">;\n\nexport const ContextContentFooter = ({\n children,\n className,\n ...props\n}: ContextContentFooterProps) => {\n const { cost } = useContextValue();\n const totalCost = cost?.total === undefined ? \"—\" : USD_FORMAT.format(cost.total);\n\n return (\n <div\n className={cn(\n \"flex w-full items-center justify-between gap-3 bg-muted/50 p-3 text-xs\",\n className\n )}\n {...props}\n >\n {children ?? (\n <>\n <span className=\"text-muted-foreground\">Total cost</span>\n <span>{totalCost}</span>\n </>\n )}\n </div>\n );\n};\n\nconst TokensWithCost = ({\n tokens,\n costText,\n}: {\n tokens?: number;\n costText?: string;\n}) => (\n <span>\n {tokens === undefined\n ? \"—\"\n : new Intl.NumberFormat(\"en-US\", {\n notation: \"compact\",\n }).format(tokens)}\n {costText ? (\n <span className=\"ml-2 text-muted-foreground\">• {costText}</span>\n ) : null}\n </span>\n);\n\nexport type ContextInputUsageProps = ComponentProps<\"div\">;\n\nexport const ContextInputUsage = ({\n className,\n children,\n ...props\n}: ContextInputUsageProps) => {\n const { usage, cost } = useContextValue();\n const inputTokens = usage?.inputTokens ?? 0;\n\n if (children) {\n return children;\n }\n\n if (!inputTokens) {\n return null;\n }\n\n const inputCostText = formatUSD(cost?.input);\n\n return (\n <div\n className={cn(\"flex items-center justify-between text-xs\", className)}\n {...props}\n >\n <span className=\"text-muted-foreground\">Input</span>\n <TokensWithCost costText={inputCostText} tokens={inputTokens} />\n </div>\n );\n};\n\nexport type ContextOutputUsageProps = ComponentProps<\"div\">;\n\nexport const ContextOutputUsage = ({\n className,\n children,\n ...props\n}: ContextOutputUsageProps) => {\n const { usage, cost } = useContextValue();\n const outputTokens = usage?.outputTokens ?? 0;\n\n if (children) {\n return children;\n }\n\n if (!outputTokens) {\n return null;\n }\n\n const outputCostText = formatUSD(cost?.output);\n\n return (\n <div\n className={cn(\"flex items-center justify-between text-xs\", className)}\n {...props}\n >\n <span className=\"text-muted-foreground\">Output</span>\n <TokensWithCost costText={outputCostText} tokens={outputTokens} />\n </div>\n );\n};\n\nexport type ContextReasoningUsageProps = ComponentProps<\"div\">;\n\nexport const ContextReasoningUsage = ({\n className,\n children,\n ...props\n}: ContextReasoningUsageProps) => {\n const { usage, cost } = useContextValue();\n const reasoningTokens = usage?.reasoningTokens ?? 0;\n\n if (children) {\n return children;\n }\n\n if (!reasoningTokens) {\n return null;\n }\n\n const reasoningCostText = formatUSD(cost?.reasoning);\n\n return (\n <div\n className={cn(\"flex items-center justify-between text-xs\", className)}\n {...props}\n >\n <span className=\"text-muted-foreground\">Reasoning</span>\n <TokensWithCost costText={reasoningCostText} tokens={reasoningTokens} />\n </div>\n );\n};\n\nexport type ContextCacheUsageProps = ComponentProps<\"div\">;\n\nexport const ContextCacheUsage = ({\n className,\n children,\n ...props\n}: ContextCacheUsageProps) => {\n const { usage, cost } = useContextValue();\n const cacheTokens = usage?.cachedInputTokens ?? 0;\n\n if (children) {\n return children;\n }\n\n if (!cacheTokens) {\n return null;\n }\n\n const cacheCostText = formatUSD(cost?.cache);\n\n return (\n <div\n className={cn(\"flex items-center justify-between text-xs\", className)}\n {...props}\n >\n <span className=\"text-muted-foreground\">Cache</span>\n <TokensWithCost costText={cacheCostText} tokens={cacheTokens} />\n </div>\n );\n};\n"],"names":["PERCENT_MAX","ICON_RADIUS","ICON_VIEWBOX","ICON_CENTER","ICON_STROKE_WIDTH","WARN_THRESHOLD","DANGER_THRESHOLD","getUsageStatus","pct","STATUS_TEXT","STATUS_PROGRESS","USD_FORMAT","formatUSD","value","ContextContext","createContext","useContextValue","context","useContext","Context","usedTokens","maxTokens","usage","cost","props","contextValue","useMemo","jsx","HoverCard","ContextIcon","circumference","usedPercent","dashOffset","jsxs","ContextTrigger","children","showPercentage","status","renderedPercent","HoverCardTrigger","Button","cn","ContextContent","className","HoverCardContent","ContextContentHeader","displayPct","used","total","Fragment","Progress","ContextContentBody","ContextContentFooter","totalCost","TokensWithCost","tokens","costText","ContextInputUsage","inputTokens","inputCostText","ContextOutputUsage","outputTokens","outputCostText","ContextReasoningUsage","reasoningTokens","reasoningCostText","ContextCacheUsage","cacheTokens","cacheCostText"],"mappings":"yQAeMA,EAAc,IACdC,EAAc,GACdC,EAAe,GACfC,EAAc,GACdC,EAAoB,EACpBC,EAAiB,IACjBC,EAAmB,GAInBC,EAAkBC,GAClBA,GAAOF,EAAyB,SAChCE,GAAOH,EAAuB,UAC3B,SAGHI,EAA2C,CAC/C,OAAQ,wBACR,QAAS,iBACT,OAAQ,kBACV,EAEMC,EAA+C,CACnD,OAAQ,GACR,QAAS,kDACT,OAAQ,mDACV,EAEMC,EAAa,IAAI,KAAK,aAAa,QAAS,CAChD,SAAU,MACV,MAAO,UACT,CAAC,EAEKC,EAAaC,GACjBA,IAAU,OAAY,OAAYF,EAAW,OAAOE,CAAK,EAiBrDC,EAAiBC,EAAAA,cAAoC,IAAI,EAEzDC,EAAkB,IAAM,CAC5B,MAAMC,EAAUC,EAAAA,WAAWJ,CAAc,EAEzC,GAAI,CAACG,EACH,MAAM,IAAI,MAAM,gDAAgD,EAGlE,OAAOA,CACT,EAIaE,EAAU,CAAC,CACtB,WAAAC,EACA,UAAAC,EACA,MAAAC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C,CAChC,KAAM,CAAE,MAAAF,EAAO,KAAAC,CAAA,EAASP,EAAA,EAClBgD,EAAkB1C,GAAO,iBAAmB,EAElD,GAAIa,EACF,OAAOA,EAGT,GAAI,CAAC6B,EACH,OAAO,KAGT,MAAMC,EAAoBrD,EAAUW,GAAM,SAAS,EAEnD,OACEU,EAAAA,KAAC,MAAA,CACC,UAAWQ,EAAAA,GAAG,4CAA6CE,CAAS,EACnE,GAAGnB,EAEJ,SAAA,CAAAG,EAAAA,IAAC,OAAA,CAAK,UAAU,wBAAwB,SAAA,YAAS,EACjDA,EAAAA,IAAC2B,EAAA,CAAe,SAAUW,EAAmB,OAAQD,CAAA,CAAiB,CAAA,CAAA,CAAA,CAG5E,EAIaE,EAAoB,CAAC,CAChC,UAAAvB,EACA,SAAAR,EACA,GAAGX,CACL,IAA8B,CAC5B,KAAM,CAAE,MAAAF,EAAO,KAAAC,CAAA,EAASP,EAAA,EAClBmD,EAAc7C,GAAO,mBAAqB,EAEhD,GAAIa,EACF,OAAOA,EAGT,GAAI,CAACgC,EACH,OAAO,KAGT,MAAMC,EAAgBxD,EAAUW,GAAM,KAAK,EAE3C,OACEU,EAAAA,KAAC,MAAA,CACC,UAAWQ,EAAAA,GAAG,4CAA6CE,CAAS,EACnE,GAAGnB,EAEJ,SAAA,CAAAG,EAAAA,IAAC,OAAA,CAAK,UAAU,wBAAwB,SAAA,QAAK,EAC7CA,EAAAA,IAAC2B,EAAA,CAAe,SAAUc,EAAe,OAAQD,CAAA,CAAa,CAAA,CAAA,CAAA,CAGpE"}
@@ -0,0 +1,266 @@
1
+ import { jsx as n, jsxs as i, Fragment as T } from "react/jsx-runtime";
2
+ import { createContext as b, useMemo as S, useContext as I } from "react";
3
+ import { Button as U } from "../ui/button.js";
4
+ import { HoverCard as D, HoverCardContent as O, HoverCardTrigger as R } from "../ui/hover-card.js";
5
+ import { Progress as _ } from "../ui/progress.js";
6
+ import { cn as u } from "../../lib/utils.js";
7
+ const E = 100, p = 10, h = 24, m = 12, C = 2, F = 0.75, P = 0.9, N = (t) => t >= P ? "danger" : t >= F ? "warning" : "normal", g = {
8
+ normal: "text-muted-foreground",
9
+ warning: "text-amber-500",
10
+ danger: "text-destructive"
11
+ }, H = {
12
+ normal: "",
13
+ warning: "[&_[data-slot=progress-indicator]]:bg-amber-500",
14
+ danger: "[&_[data-slot=progress-indicator]]:bg-destructive"
15
+ }, y = new Intl.NumberFormat("en-US", {
16
+ currency: "USD",
17
+ style: "currency"
18
+ }), d = (t) => t === void 0 ? void 0 : y.format(t), v = b(null), l = () => {
19
+ const t = I(v);
20
+ if (!t)
21
+ throw new Error("Context components must be used within Context");
22
+ return t;
23
+ }, V = ({
24
+ usedTokens: t,
25
+ maxTokens: e,
26
+ usage: o,
27
+ cost: s,
28
+ ...c
29
+ }) => {
30
+ const r = S(
31
+ () => ({ cost: s, maxTokens: e, usage: o, usedTokens: t }),
32
+ [s, e, o, t]
33
+ );
34
+ return /* @__PURE__ */ n(v.Provider, { value: r, children: /* @__PURE__ */ n(D, { closeDelay: 0, openDelay: 0, ...c }) });
35
+ }, j = () => {
36
+ const { usedTokens: t, maxTokens: e } = l(), o = 2 * Math.PI * p, s = t / e, c = o * (1 - s);
37
+ return /* @__PURE__ */ i(
38
+ "svg",
39
+ {
40
+ "aria-label": "Model context usage",
41
+ height: "20",
42
+ role: "img",
43
+ style: { color: "currentcolor" },
44
+ viewBox: `0 0 ${h} ${h}`,
45
+ width: "20",
46
+ children: [
47
+ /* @__PURE__ */ n(
48
+ "circle",
49
+ {
50
+ cx: m,
51
+ cy: m,
52
+ fill: "none",
53
+ opacity: "0.25",
54
+ r: p,
55
+ stroke: "currentColor",
56
+ strokeWidth: C
57
+ }
58
+ ),
59
+ /* @__PURE__ */ n(
60
+ "circle",
61
+ {
62
+ cx: m,
63
+ cy: m,
64
+ fill: "none",
65
+ opacity: "0.7",
66
+ r: p,
67
+ stroke: "currentColor",
68
+ strokeDasharray: `${o} ${o}`,
69
+ strokeDashoffset: c,
70
+ strokeLinecap: "round",
71
+ strokeWidth: C,
72
+ style: { transform: "rotate(-90deg)", transformOrigin: "center" }
73
+ }
74
+ )
75
+ ]
76
+ }
77
+ );
78
+ }, X = ({
79
+ children: t,
80
+ showPercentage: e = !1,
81
+ ...o
82
+ }) => {
83
+ const { usedTokens: s, maxTokens: c } = l(), r = s / c, a = N(r), f = new Intl.NumberFormat("en-US", {
84
+ maximumFractionDigits: 1,
85
+ style: "percent"
86
+ }).format(r);
87
+ return /* @__PURE__ */ n(R, { asChild: !0, children: t ?? /* @__PURE__ */ i(U, { type: "button", variant: "ghost", ...o, children: [
88
+ e ? /* @__PURE__ */ n("span", { className: u("font-medium", g[a]), children: f }) : null,
89
+ /* @__PURE__ */ n("span", { className: g[a], children: /* @__PURE__ */ n(j, {}) })
90
+ ] }) });
91
+ }, G = ({
92
+ className: t,
93
+ ...e
94
+ }) => /* @__PURE__ */ n(
95
+ O,
96
+ {
97
+ className: u("min-w-60 divide-y overflow-hidden p-0", t),
98
+ ...e
99
+ }
100
+ ), K = ({
101
+ children: t,
102
+ className: e,
103
+ ...o
104
+ }) => {
105
+ const { usedTokens: s, maxTokens: c } = l(), r = s / c, a = N(r), f = new Intl.NumberFormat("en-US", {
106
+ maximumFractionDigits: 1,
107
+ style: "percent"
108
+ }).format(r), w = new Intl.NumberFormat("en-US", {
109
+ notation: "compact"
110
+ }).format(s), k = new Intl.NumberFormat("en-US", {
111
+ notation: "compact"
112
+ }).format(c);
113
+ return /* @__PURE__ */ n("div", { className: u("w-full space-y-2 p-3", e), ...o, children: t ?? /* @__PURE__ */ i(T, { children: [
114
+ /* @__PURE__ */ i("div", { className: "flex items-center justify-between gap-3 text-xs", children: [
115
+ /* @__PURE__ */ n("p", { className: u(g[a]), children: f }),
116
+ /* @__PURE__ */ i("p", { className: "font-mono text-muted-foreground", children: [
117
+ w,
118
+ " / ",
119
+ k
120
+ ] })
121
+ ] }),
122
+ /* @__PURE__ */ n("div", { className: "space-y-2", children: /* @__PURE__ */ n(
123
+ _,
124
+ {
125
+ className: u("bg-muted", H[a]),
126
+ value: r * E
127
+ }
128
+ ) })
129
+ ] }) });
130
+ }, q = ({
131
+ children: t,
132
+ className: e,
133
+ ...o
134
+ }) => /* @__PURE__ */ n("div", { className: u("w-full p-3", e), ...o, children: t }), z = ({
135
+ children: t,
136
+ className: e,
137
+ ...o
138
+ }) => {
139
+ const { cost: s } = l(), c = s?.total === void 0 ? "—" : y.format(s.total);
140
+ return /* @__PURE__ */ n(
141
+ "div",
142
+ {
143
+ className: u(
144
+ "flex w-full items-center justify-between gap-3 bg-muted/50 p-3 text-xs",
145
+ e
146
+ ),
147
+ ...o,
148
+ children: t ?? /* @__PURE__ */ i(T, { children: [
149
+ /* @__PURE__ */ n("span", { className: "text-muted-foreground", children: "Total cost" }),
150
+ /* @__PURE__ */ n("span", { children: c })
151
+ ] })
152
+ }
153
+ );
154
+ }, x = ({
155
+ tokens: t,
156
+ costText: e
157
+ }) => /* @__PURE__ */ i("span", { children: [
158
+ t === void 0 ? "—" : new Intl.NumberFormat("en-US", {
159
+ notation: "compact"
160
+ }).format(t),
161
+ e ? /* @__PURE__ */ i("span", { className: "ml-2 text-muted-foreground", children: [
162
+ "• ",
163
+ e
164
+ ] }) : null
165
+ ] }), J = ({
166
+ className: t,
167
+ children: e,
168
+ ...o
169
+ }) => {
170
+ const { usage: s, cost: c } = l(), r = s?.inputTokens ?? 0;
171
+ if (e)
172
+ return e;
173
+ if (!r)
174
+ return null;
175
+ const a = d(c?.input);
176
+ return /* @__PURE__ */ i(
177
+ "div",
178
+ {
179
+ className: u("flex items-center justify-between text-xs", t),
180
+ ...o,
181
+ children: [
182
+ /* @__PURE__ */ n("span", { className: "text-muted-foreground", children: "Input" }),
183
+ /* @__PURE__ */ n(x, { costText: a, tokens: r })
184
+ ]
185
+ }
186
+ );
187
+ }, Q = ({
188
+ className: t,
189
+ children: e,
190
+ ...o
191
+ }) => {
192
+ const { usage: s, cost: c } = l(), r = s?.outputTokens ?? 0;
193
+ if (e)
194
+ return e;
195
+ if (!r)
196
+ return null;
197
+ const a = d(c?.output);
198
+ return /* @__PURE__ */ i(
199
+ "div",
200
+ {
201
+ className: u("flex items-center justify-between text-xs", t),
202
+ ...o,
203
+ children: [
204
+ /* @__PURE__ */ n("span", { className: "text-muted-foreground", children: "Output" }),
205
+ /* @__PURE__ */ n(x, { costText: a, tokens: r })
206
+ ]
207
+ }
208
+ );
209
+ }, Y = ({
210
+ className: t,
211
+ children: e,
212
+ ...o
213
+ }) => {
214
+ const { usage: s, cost: c } = l(), r = s?.reasoningTokens ?? 0;
215
+ if (e)
216
+ return e;
217
+ if (!r)
218
+ return null;
219
+ const a = d(c?.reasoning);
220
+ return /* @__PURE__ */ i(
221
+ "div",
222
+ {
223
+ className: u("flex items-center justify-between text-xs", t),
224
+ ...o,
225
+ children: [
226
+ /* @__PURE__ */ n("span", { className: "text-muted-foreground", children: "Reasoning" }),
227
+ /* @__PURE__ */ n(x, { costText: a, tokens: r })
228
+ ]
229
+ }
230
+ );
231
+ }, Z = ({
232
+ className: t,
233
+ children: e,
234
+ ...o
235
+ }) => {
236
+ const { usage: s, cost: c } = l(), r = s?.cachedInputTokens ?? 0;
237
+ if (e)
238
+ return e;
239
+ if (!r)
240
+ return null;
241
+ const a = d(c?.cache);
242
+ return /* @__PURE__ */ i(
243
+ "div",
244
+ {
245
+ className: u("flex items-center justify-between text-xs", t),
246
+ ...o,
247
+ children: [
248
+ /* @__PURE__ */ n("span", { className: "text-muted-foreground", children: "Cache" }),
249
+ /* @__PURE__ */ n(x, { costText: a, tokens: r })
250
+ ]
251
+ }
252
+ );
253
+ };
254
+ export {
255
+ V as Context,
256
+ Z as ContextCacheUsage,
257
+ G as ContextContent,
258
+ q as ContextContentBody,
259
+ z as ContextContentFooter,
260
+ K as ContextContentHeader,
261
+ J as ContextInputUsage,
262
+ Q as ContextOutputUsage,
263
+ Y as ContextReasoningUsage,
264
+ X as ContextTrigger
265
+ };
266
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sources":["../../../src/components/ai/context.tsx"],"sourcesContent":["import { createContext, useContext, useMemo } from \"react\";\n\nimport type { LanguageModelUsage } from \"ai\";\nimport type { ComponentProps } from \"react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport {\n HoverCard,\n HoverCardContent,\n HoverCardTrigger,\n} from \"@/components/ui/hover-card\";\nimport { Progress } from \"@/components/ui/progress\";\nimport { cn } from \"@/lib/utils\";\n\n\nconst PERCENT_MAX = 100;\nconst ICON_RADIUS = 10;\nconst ICON_VIEWBOX = 24;\nconst ICON_CENTER = 12;\nconst ICON_STROKE_WIDTH = 2;\nconst WARN_THRESHOLD = 0.75;\nconst DANGER_THRESHOLD = 0.9;\n\ntype UsageStatus = \"normal\" | \"warning\" | \"danger\";\n\nconst getUsageStatus = (pct: number): UsageStatus => {\n if (pct >= DANGER_THRESHOLD) return \"danger\";\n if (pct >= WARN_THRESHOLD) return \"warning\";\n return \"normal\";\n};\n\nconst STATUS_TEXT: Record<UsageStatus, string> = {\n normal: \"text-muted-foreground\",\n warning: \"text-amber-500\",\n danger: \"text-destructive\",\n};\n\nconst STATUS_PROGRESS: Record<UsageStatus, string> = {\n normal: \"\",\n warning: \"[&_[data-slot=progress-indicator]]:bg-amber-500\",\n danger: \"[&_[data-slot=progress-indicator]]:bg-destructive\",\n};\n\nconst USD_FORMAT = new Intl.NumberFormat(\"en-US\", {\n currency: \"USD\",\n style: \"currency\",\n});\n\nconst formatUSD = (value: number | undefined): string | undefined =>\n value === undefined ? undefined : USD_FORMAT.format(value);\n\nexport interface CostBreakdown {\n total?: number;\n input?: number;\n output?: number;\n reasoning?: number;\n cache?: number;\n}\n\ninterface ContextSchema {\n usedTokens: number;\n maxTokens: number;\n usage?: LanguageModelUsage;\n cost?: CostBreakdown;\n}\n\nconst ContextContext = createContext<ContextSchema | null>(null);\n\nconst useContextValue = () => {\n const context = useContext(ContextContext);\n\n if (!context) {\n throw new Error(\"Context components must be used within Context\");\n }\n\n return context;\n};\n\nexport type ContextProps = ComponentProps<typeof HoverCard> & ContextSchema;\n\nexport const Context = ({\n usedTokens,\n maxTokens,\n usage,\n cost,\n ...props\n}: ContextProps) => {\n const contextValue = useMemo(\n () => ({ cost, maxTokens, usage, usedTokens }),\n [cost, maxTokens, usage, usedTokens]\n );\n\n return (\n <ContextContext.Provider value={contextValue}>\n <HoverCard closeDelay={0} openDelay={0} {...props} />\n </ContextContext.Provider>\n );\n};\n\nconst ContextIcon = () => {\n const { usedTokens, maxTokens } = useContextValue();\n const circumference = 2 * Math.PI * ICON_RADIUS;\n const usedPercent = usedTokens / maxTokens;\n const dashOffset = circumference * (1 - usedPercent);\n\n return (\n <svg\n aria-label=\"Model context usage\"\n height=\"20\"\n role=\"img\"\n style={{ color: \"currentcolor\" }}\n viewBox={`0 0 ${ICON_VIEWBOX} ${ICON_VIEWBOX}`}\n width=\"20\"\n >\n <circle\n cx={ICON_CENTER}\n cy={ICON_CENTER}\n fill=\"none\"\n opacity=\"0.25\"\n r={ICON_RADIUS}\n stroke=\"currentColor\"\n strokeWidth={ICON_STROKE_WIDTH}\n />\n <circle\n cx={ICON_CENTER}\n cy={ICON_CENTER}\n fill=\"none\"\n opacity=\"0.7\"\n r={ICON_RADIUS}\n stroke=\"currentColor\"\n strokeDasharray={`${circumference} ${circumference}`}\n strokeDashoffset={dashOffset}\n strokeLinecap=\"round\"\n strokeWidth={ICON_STROKE_WIDTH}\n style={{ transform: \"rotate(-90deg)\", transformOrigin: \"center\" }}\n />\n </svg>\n );\n};\n\nexport type ContextTriggerProps = ComponentProps<typeof Button> & {\n showPercentage?: boolean;\n};\n\nexport const ContextTrigger = ({\n children,\n showPercentage = false,\n ...props\n}: ContextTriggerProps) => {\n const { usedTokens, maxTokens } = useContextValue();\n const usedPercent = usedTokens / maxTokens;\n const status = getUsageStatus(usedPercent);\n const renderedPercent = new Intl.NumberFormat(\"en-US\", {\n maximumFractionDigits: 1,\n style: \"percent\",\n }).format(usedPercent);\n\n return (\n <HoverCardTrigger asChild>\n {children ?? (\n <Button type=\"button\" variant=\"ghost\" {...props}>\n {showPercentage ? (\n <span className={cn(\"font-medium\", STATUS_TEXT[status])}>\n {renderedPercent}\n </span>\n ) : null}\n <span className={STATUS_TEXT[status]}>\n <ContextIcon />\n </span>\n </Button>\n )}\n </HoverCardTrigger>\n );\n};\n\nexport type ContextContentProps = ComponentProps<typeof HoverCardContent>;\n\nexport const ContextContent = ({\n className,\n ...props\n}: ContextContentProps) => (\n <HoverCardContent\n className={cn(\"min-w-60 divide-y overflow-hidden p-0\", className)}\n {...props}\n />\n);\n\nexport type ContextContentHeaderProps = ComponentProps<\"div\">;\n\nexport const ContextContentHeader = ({\n children,\n className,\n ...props\n}: ContextContentHeaderProps) => {\n const { usedTokens, maxTokens } = useContextValue();\n const usedPercent = usedTokens / maxTokens;\n const status = getUsageStatus(usedPercent);\n const displayPct = new Intl.NumberFormat(\"en-US\", {\n maximumFractionDigits: 1,\n style: \"percent\",\n }).format(usedPercent);\n const used = new Intl.NumberFormat(\"en-US\", {\n notation: \"compact\",\n }).format(usedTokens);\n const total = new Intl.NumberFormat(\"en-US\", {\n notation: \"compact\",\n }).format(maxTokens);\n\n return (\n <div className={cn(\"w-full space-y-2 p-3\", className)} {...props}>\n {children ?? (\n <>\n <div className=\"flex items-center justify-between gap-3 text-xs\">\n <p className={cn(STATUS_TEXT[status])}>{displayPct}</p>\n <p className=\"font-mono text-muted-foreground\">\n {used} / {total}\n </p>\n </div>\n <div className=\"space-y-2\">\n <Progress\n className={cn(\"bg-muted\", STATUS_PROGRESS[status])}\n value={usedPercent * PERCENT_MAX}\n />\n </div>\n </>\n )}\n </div>\n );\n};\n\nexport type ContextContentBodyProps = ComponentProps<\"div\">;\n\nexport const ContextContentBody = ({\n children,\n className,\n ...props\n}: ContextContentBodyProps) => (\n <div className={cn(\"w-full p-3\", className)} {...props}>\n {children}\n </div>\n);\n\nexport type ContextContentFooterProps = ComponentProps<\"div\">;\n\nexport const ContextContentFooter = ({\n children,\n className,\n ...props\n}: ContextContentFooterProps) => {\n const { cost } = useContextValue();\n const totalCost = cost?.total === undefined ? \"—\" : USD_FORMAT.format(cost.total);\n\n return (\n <div\n className={cn(\n \"flex w-full items-center justify-between gap-3 bg-muted/50 p-3 text-xs\",\n className\n )}\n {...props}\n >\n {children ?? (\n <>\n <span className=\"text-muted-foreground\">Total cost</span>\n <span>{totalCost}</span>\n </>\n )}\n </div>\n );\n};\n\nconst TokensWithCost = ({\n tokens,\n costText,\n}: {\n tokens?: number;\n costText?: string;\n}) => (\n <span>\n {tokens === undefined\n ? \"—\"\n : new Intl.NumberFormat(\"en-US\", {\n notation: \"compact\",\n }).format(tokens)}\n {costText ? (\n <span className=\"ml-2 text-muted-foreground\">• {costText}</span>\n ) : null}\n </span>\n);\n\nexport type ContextInputUsageProps = ComponentProps<\"div\">;\n\nexport const ContextInputUsage = ({\n className,\n children,\n ...props\n}: ContextInputUsageProps) => {\n const { usage, cost } = useContextValue();\n const inputTokens = usage?.inputTokens ?? 0;\n\n if (children) {\n return children;\n }\n\n if (!inputTokens) {\n return null;\n }\n\n const inputCostText = formatUSD(cost?.input);\n\n return (\n <div\n className={cn(\"flex items-center justify-between text-xs\", className)}\n {...props}\n >\n <span className=\"text-muted-foreground\">Input</span>\n <TokensWithCost costText={inputCostText} tokens={inputTokens} />\n </div>\n );\n};\n\nexport type ContextOutputUsageProps = ComponentProps<\"div\">;\n\nexport const ContextOutputUsage = ({\n className,\n children,\n ...props\n}: ContextOutputUsageProps) => {\n const { usage, cost } = useContextValue();\n const outputTokens = usage?.outputTokens ?? 0;\n\n if (children) {\n return children;\n }\n\n if (!outputTokens) {\n return null;\n }\n\n const outputCostText = formatUSD(cost?.output);\n\n return (\n <div\n className={cn(\"flex items-center justify-between text-xs\", className)}\n {...props}\n >\n <span className=\"text-muted-foreground\">Output</span>\n <TokensWithCost costText={outputCostText} tokens={outputTokens} />\n </div>\n );\n};\n\nexport type ContextReasoningUsageProps = ComponentProps<\"div\">;\n\nexport const ContextReasoningUsage = ({\n className,\n children,\n ...props\n}: ContextReasoningUsageProps) => {\n const { usage, cost } = useContextValue();\n const reasoningTokens = usage?.reasoningTokens ?? 0;\n\n if (children) {\n return children;\n }\n\n if (!reasoningTokens) {\n return null;\n }\n\n const reasoningCostText = formatUSD(cost?.reasoning);\n\n return (\n <div\n className={cn(\"flex items-center justify-between text-xs\", className)}\n {...props}\n >\n <span className=\"text-muted-foreground\">Reasoning</span>\n <TokensWithCost costText={reasoningCostText} tokens={reasoningTokens} />\n </div>\n );\n};\n\nexport type ContextCacheUsageProps = ComponentProps<\"div\">;\n\nexport const ContextCacheUsage = ({\n className,\n children,\n ...props\n}: ContextCacheUsageProps) => {\n const { usage, cost } = useContextValue();\n const cacheTokens = usage?.cachedInputTokens ?? 0;\n\n if (children) {\n return children;\n }\n\n if (!cacheTokens) {\n return null;\n }\n\n const cacheCostText = formatUSD(cost?.cache);\n\n return (\n <div\n className={cn(\"flex items-center justify-between text-xs\", className)}\n {...props}\n >\n <span className=\"text-muted-foreground\">Cache</span>\n <TokensWithCost costText={cacheCostText} tokens={cacheTokens} />\n </div>\n );\n};\n"],"names":["PERCENT_MAX","ICON_RADIUS","ICON_VIEWBOX","ICON_CENTER","ICON_STROKE_WIDTH","WARN_THRESHOLD","DANGER_THRESHOLD","getUsageStatus","pct","STATUS_TEXT","STATUS_PROGRESS","USD_FORMAT","formatUSD","value","ContextContext","createContext","useContextValue","context","useContext","Context","usedTokens","maxTokens","usage","cost","props","contextValue","useMemo","jsx","HoverCard","ContextIcon","circumference","usedPercent","dashOffset","jsxs","ContextTrigger","children","showPercentage","status","renderedPercent","HoverCardTrigger","Button","cn","ContextContent","className","HoverCardContent","ContextContentHeader","displayPct","used","total","Fragment","Progress","ContextContentBody","ContextContentFooter","totalCost","TokensWithCost","tokens","costText","ContextInputUsage","inputTokens","inputCostText","ContextOutputUsage","outputTokens","outputCostText","ContextReasoningUs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B,UAAA,SAAK;AAAA,QAC7C,gBAAAA,EAAC2B,GAAA,EAAe,UAAUc,GAAe,QAAQD,EAAA,CAAa;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGpE;"}
@@ -0,0 +1,4 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),u=require("lucide-react"),m=require("react"),i=require("use-stick-to-bottom"),x=require("../ui/button.cjs"),c=require("../../lib/utils.cjs"),j=({className:e,...t})=>o.jsx(i.StickToBottom,{className:c.cn("relative flex-1 overflow-y-hidden",e),initial:"smooth",resize:"smooth",role:"log",...t}),C=({className:e,...t})=>o.jsx(i.StickToBottom.Content,{className:c.cn("flex flex-col gap-8 p-4",e),...t}),g=({className:e,title:t="No messages yet",description:n="Start a conversation to see messages here",icon:s,children:r,...l})=>o.jsx("div",{className:c.cn("flex size-full flex-col items-center justify-center gap-3 p-8 text-center",e),...l,children:r??o.jsxs(o.Fragment,{children:[s&&o.jsx("div",{className:"text-muted-foreground",children:s}),o.jsxs("div",{className:"space-y-1",children:[o.jsx("h3",{className:"font-medium text-sm",children:t}),n&&o.jsx("p",{className:"text-muted-foreground text-sm",children:n})]})]})}),f=({className:e,...t})=>{const{isAtBottom:n,scrollToBottom:s}=i.useStickToBottomContext(),r=m.useCallback(()=>{s()},[s]);return!n&&o.jsx(x.Button,{className:c.cn("absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full dark:bg-background dark:hover:bg-muted",e),onClick:r,size:"icon",type:"button",variant:"outline",...t,children:o.jsx(u.ArrowDownIcon,{className:"size-4"})})},w=e=>e.parts.filter(t=>t.type==="text").map(t=>t.text).join(""),b=e=>`**${e.role.charAt(0).toUpperCase()+e.role.slice(1)}:** ${w(e)}`,v=(e,t=b)=>e.map((n,s)=>t(n,s)).join(`
2
+
3
+ `),y=({messages:e,filename:t="conversation.md",formatMessage:n=b,className:s,children:r,...l})=>{const k=m.useCallback(()=>{const h=v(e,n),p=new Blob([h],{type:"text/markdown"}),d=URL.createObjectURL(p),a=document.createElement("a");a.href=d,a.download=t,document.body.append(a),a.click(),a.remove(),URL.revokeObjectURL(d)},[e,t,n]);return o.jsx(x.Button,{className:c.cn("absolute top-4 right-4 rounded-full dark:bg-background dark:hover:bg-muted",s),onClick:k,size:"icon",type:"button",variant:"outline",...l,children:r??o.jsx(u.DownloadIcon,{className:"size-4"})})};exports.Conversation=j;exports.ConversationContent=C;exports.ConversationDownload=y;exports.ConversationEmptyState=g;exports.ConversationScrollButton=f;exports.messagesToMarkdown=v;
4
+ //# sourceMappingURL=conversation.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conversation.cjs","sources":["../../../src/components/ai/conversation.tsx"],"sourcesContent":["import { ArrowDownIcon, DownloadIcon } from \"lucide-react\";\nimport { useCallback } from \"react\";\nimport { StickToBottom, useStickToBottomContext } from \"use-stick-to-bottom\";\n\nimport type { UIMessage } from \"ai\";\nimport type { ComponentProps } from \"react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport { cn } from \"@/lib/utils\";\n\nexport type ConversationProps = ComponentProps<typeof StickToBottom>;\n\nexport const Conversation = ({ className, ...props }: ConversationProps) => (\n <StickToBottom\n className={cn(\"relative flex-1 overflow-y-hidden\", className)}\n initial=\"smooth\"\n resize=\"smooth\"\n role=\"log\"\n {...props}\n />\n);\n\nexport type ConversationContentProps = ComponentProps<\n typeof StickToBottom.Content\n>;\n\nexport const ConversationContent = ({\n className,\n ...props\n}: ConversationContentProps) => (\n <StickToBottom.Content\n className={cn(\"flex flex-col gap-8 p-4\", className)}\n {...props}\n />\n);\n\nexport type ConversationEmptyStateProps = ComponentProps<\"div\"> & {\n title?: string;\n description?: string;\n icon?: React.ReactNode;\n};\n\nexport const ConversationEmptyState = ({\n className,\n title = \"No messages yet\",\n description = \"Start a conversation to see messages here\",\n icon,\n children,\n ...props\n}: ConversationEmptyStateProps) => (\n <div\n className={cn(\n \"flex size-full flex-col items-center justify-center gap-3 p-8 text-center\",\n className\n )}\n {...props}\n >\n {children ?? (\n <>\n {icon && <div className=\"text-muted-foreground\">{icon}</div>}\n <div className=\"space-y-1\">\n <h3 className=\"font-medium text-sm\">{title}</h3>\n {description && (\n <p className=\"text-muted-foreground text-sm\">{description}</p>\n )}\n </div>\n </>\n )}\n </div>\n);\n\nexport type ConversationScrollButtonProps = ComponentProps<typeof Button>;\n\nexport const ConversationScrollButton = ({\n className,\n ...props\n}: ConversationScrollButtonProps) => {\n const { isAtBottom, scrollToBottom } = useStickToBottomContext();\n\n const handleScrollToBottom = useCallback(() => {\n scrollToBottom();\n }, [scrollToBottom]);\n\n return (\n !isAtBottom && (\n <Button\n className={cn(\n \"absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full dark:bg-background dark:hover:bg-muted\",\n className\n )}\n onClick={handleScrollToBottom}\n size=\"icon\"\n type=\"button\"\n variant=\"outline\"\n {...props}\n >\n <ArrowDownIcon className=\"size-4\" />\n </Button>\n )\n );\n};\n\nconst getMessageText = (message: UIMessage): string =>\n message.parts\n .filter((part) => part.type === \"text\")\n .map((part) => part.text)\n .join(\"\");\n\nexport type ConversationDownloadProps = Omit<\n ComponentProps<typeof Button>,\n \"onClick\"\n> & {\n messages: UIMessage[];\n filename?: string;\n formatMessage?: (message: UIMessage, index: number) => string;\n};\n\nconst defaultFormatMessage = (message: UIMessage): string => {\n const roleLabel =\n message.role.charAt(0).toUpperCase() + message.role.slice(1);\n return `**${roleLabel}:** ${getMessageText(message)}`;\n};\n\nexport const messagesToMarkdown = (\n messages: UIMessage[],\n formatMessage: (\n message: UIMessage,\n index: number\n ) => string = defaultFormatMessage\n): string => messages.map((msg, i) => formatMessage(msg, i)).join(\"\\n\\n\");\n\nexport const ConversationDownload = ({\n messages,\n filename = \"conversation.md\",\n formatMessage = defaultFormatMessage,\n className,\n children,\n ...props\n}: ConversationDownloadProps) => {\n const handleDownload = useCallback(() => {\n const markdown = messagesToMarkdown(messages, formatMessage);\n const blob = new Blob([markdown], { type: \"text/markdown\" });\n const url = URL.createObjectURL(blob);\n const link = document.createElement(\"a\");\n link.href = url;\n link.download = filename;\n document.body.append(link);\n link.click();\n link.remove();\n URL.revokeObjectURL(url);\n }, [messages, filename, formatMessage]);\n\n return (\n <Button\n className={cn(\n \"absolute top-4 right-4 rounded-full dark:bg-background dark:hover:bg-muted\",\n className\n )}\n onClick={handleDownload}\n size=\"icon\"\n type=\"button\"\n variant=\"outline\"\n {...props}\n >\n {children ?? <DownloadIcon className=\"size-4\" />}\n </Button>\n );\n};\n"],"names":["Conversation","className","props","jsx","StickToBottom","cn","ConversationContent","ConversationEmptyState","title","description","icon","children","jsxs","Fragment","ConversationScrollButton","isAtBottom","scrollToBottom","useStickToBottomContext","handleScrollToBottom","useCallback","Button","ArrowDownIcon","getMessageText","message","part","defaultFormatMessage","messagesToMarkdown","messages","formatMessage","msg","i","ConversationDownload","filename","handleDownload","markdown","blob","url","link","DownloadIcon"],"mappings":"kQAYaA,EAAe,CAAC,CAAE,UAAAC,EAAW,GAAGC,KAC3CC,EAAAA,IAACC,EAAAA,cAAA,CACC,UAAWC,EAAAA,GAAG,oCAAqCJ,CAAS,EAC5D,QAAQ,SACR,OAAO,SACP,KAAK,MACJ,GAAGC,CAAA,CACN,EAOWI,EAAsB,CAAC,CAClC,UAAAL,EACA,GAAGC,CACL,IACEC,EAAAA,IAACC,EAAAA,cAAc,QAAd,CACC,UAAWC,EAAAA,GAAG,0BAA2BJ,CAAS,EACjD,GAAGC,CAAA,CACN,EASWK,EAAyB,CAAC,CACrC,UAAAN,EACA,MAAAO,EAAQ,kBACR,YAAAC,EAAc,4CACd,KAAAC,EACA,SAAAC,EACA,GAAGT,CACL,IACEC,EAAAA,IAAC,MAAA,CACC,UAAWE,EAAAA,GACT,4EACAJ,CAAA,EAED,GAAGC,EAEH,YACCU,EAAAA,KAAAC,EAAAA,SAAA,CACG,SAAA,CAAAH,GAAQP,EAAAA,IAAC,MAAA,CAAI,UAAU,wBAAyB,SAAAO,EAAK,EAC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R,EAAmBC,EAAUC,CAAa,EACrDO,EAAO,IAAI,KAAK,CAACD,CAAQ,EAAG,CAAE,KAAM,gBAAiB,EACrDE,EAAM,IAAI,gBAAgBD,CAAI,EAC9BE,EAAO,SAAS,cAAc,GAAG,EACvCA,EAAK,KAAOD,EACZC,EAAK,SAAWL,EAChB,SAAS,KAAK,OAAOK,CAAI,EACzBA,EAAK,MAAA,EACLA,EAAK,OAAA,EACL,IAAI,gBAAgBD,CAAG,CACzB,EAAG,CAACT,EAAUK,EAAUJ,CAAa,CAAC,EAEtC,OACEzB,EAAAA,IAACiB,EAAAA,OAAA,CACC,UAAWf,EAAAA,GACT,6EACAJ,CAAA,EAEF,QAASgC,EACT,KAAK,OACL,KAAK,SACL,QAAQ,UACP,GAAG/B,EAEH,SAAAS,GAAYR,EAAAA,IAACmC,EAAAA,aAAA,CAAa,UAAU,QAAA,CAAS,CAAA,CAAA,CAGpD"}
@@ -0,0 +1,108 @@
1
+ import { jsx as e, jsxs as m, Fragment as v } from "react/jsx-runtime";
2
+ import { DownloadIcon as k, ArrowDownIcon as g } from "lucide-react";
3
+ import { useCallback as d } from "react";
4
+ import { StickToBottom as u, useStickToBottomContext as C } from "use-stick-to-bottom";
5
+ import { Button as p } from "../ui/button.js";
6
+ import { cn as l } from "../../lib/utils.js";
7
+ const T = ({ className: o, ...t }) => /* @__PURE__ */ e(
8
+ u,
9
+ {
10
+ className: l("relative flex-1 overflow-y-hidden", o),
11
+ initial: "smooth",
12
+ resize: "smooth",
13
+ role: "log",
14
+ ...t
15
+ }
16
+ ), U = ({
17
+ className: o,
18
+ ...t
19
+ }) => /* @__PURE__ */ e(
20
+ u.Content,
21
+ {
22
+ className: l("flex flex-col gap-8 p-4", o),
23
+ ...t
24
+ }
25
+ ), D = ({
26
+ className: o,
27
+ title: t = "No messages yet",
28
+ description: n = "Start a conversation to see messages here",
29
+ icon: r,
30
+ children: a,
31
+ ...c
32
+ }) => /* @__PURE__ */ e(
33
+ "div",
34
+ {
35
+ className: l(
36
+ "flex size-full flex-col items-center justify-center gap-3 p-8 text-center",
37
+ o
38
+ ),
39
+ ...c,
40
+ children: a ?? /* @__PURE__ */ m(v, { children: [
41
+ r && /* @__PURE__ */ e("div", { className: "text-muted-foreground", children: r }),
42
+ /* @__PURE__ */ m("div", { className: "space-y-1", children: [
43
+ /* @__PURE__ */ e("h3", { className: "font-medium text-sm", children: t }),
44
+ n && /* @__PURE__ */ e("p", { className: "text-muted-foreground text-sm", children: n })
45
+ ] })
46
+ ] })
47
+ }
48
+ ), R = ({
49
+ className: o,
50
+ ...t
51
+ }) => {
52
+ const { isAtBottom: n, scrollToBottom: r } = C(), a = d(() => {
53
+ r();
54
+ }, [r]);
55
+ return !n && /* @__PURE__ */ e(
56
+ p,
57
+ {
58
+ className: l(
59
+ "absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full dark:bg-background dark:hover:bg-muted",
60
+ o
61
+ ),
62
+ onClick: a,
63
+ size: "icon",
64
+ type: "button",
65
+ variant: "outline",
66
+ ...t,
67
+ children: /* @__PURE__ */ e(g, { className: "size-4" })
68
+ }
69
+ );
70
+ }, N = (o) => o.parts.filter((t) => t.type === "text").map((t) => t.text).join(""), f = (o) => `**${o.role.charAt(0).toUpperCase() + o.role.slice(1)}:** ${N(o)}`, w = (o, t = f) => o.map((n, r) => t(n, r)).join(`
71
+
72
+ `), A = ({
73
+ messages: o,
74
+ filename: t = "conversation.md",
75
+ formatMessage: n = f,
76
+ className: r,
77
+ children: a,
78
+ ...c
79
+ }) => {
80
+ const b = d(() => {
81
+ const h = w(o, n), x = new Blob([h], { type: "text/markdown" }), i = URL.createObjectURL(x), s = document.createElement("a");
82
+ s.href = i, s.download = t, document.body.append(s), s.click(), s.remove(), URL.revokeObjectURL(i);
83
+ }, [o, t, n]);
84
+ return /* @__PURE__ */ e(
85
+ p,
86
+ {
87
+ className: l(
88
+ "absolute top-4 right-4 rounded-full dark:bg-background dark:hover:bg-muted",
89
+ r
90
+ ),
91
+ onClick: b,
92
+ size: "icon",
93
+ type: "button",
94
+ variant: "outline",
95
+ ...c,
96
+ children: a ?? /* @__PURE__ */ e(k, { className: "size-4" })
97
+ }
98
+ );
99
+ };
100
+ export {
101
+ T as Conversation,
102
+ U as ConversationContent,
103
+ A as ConversationDownload,
104
+ D as ConversationEmptyState,
105
+ R as ConversationScrollButton,
106
+ w as messagesToMarkdown
107
+ };
108
+ //# sourceMappingURL=conversation.js.map