@nexface/chat 0.1.1 → 0.1.4-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assistant-attachments.js +6 -2
- package/dist/assistant-attachments.js.map +1 -1
- package/dist/assistant-components.d.ts +7 -3
- package/dist/assistant-components.js +30 -16
- package/dist/assistant-components.js.map +1 -1
- package/dist/assistant-runtime.d.ts +3 -1
- package/dist/assistant-runtime.js +45 -4
- package/dist/assistant-runtime.js.map +1 -1
- package/dist/default-chat.js +47 -63
- package/dist/default-chat.js.map +1 -1
- package/dist/fonts/JetBrainsMono-OFL.txt +93 -0
- package/dist/fonts/PublicSans-OFL.txt +93 -0
- package/dist/fonts/jetbrains-mono.ttf +0 -0
- package/dist/fonts/public-sans.ttf +0 -0
- package/dist/messages.d.ts +3 -0
- package/dist/messages.js.map +1 -1
- package/dist/protocol-messages.js +40 -9
- package/dist/protocol-messages.js.map +1 -1
- package/dist/protocol-response.js +2 -2
- package/dist/protocol-response.js.map +1 -1
- package/dist/storage.js +4 -3
- package/dist/storage.js.map +1 -1
- package/dist/styles.css +1167 -325
- package/dist/ui/button.js +1 -1
- package/dist/ui/button.js.map +1 -1
- package/dist/ui/code-block.d.ts +22 -0
- package/dist/ui/code-block.js +49 -0
- package/dist/ui/code-block.js.map +1 -0
- package/dist/ui/collapsible.d.ts +5 -0
- package/dist/ui/collapsible.js +15 -0
- package/dist/ui/collapsible.js.map +1 -0
- package/dist/ui/dropdown-menu.js +4 -3
- package/dist/ui/dropdown-menu.js.map +1 -1
- package/dist/ui/home-demo/action-bar.d.ts +2 -0
- package/dist/ui/home-demo/action-bar.js +10 -0
- package/dist/ui/home-demo/action-bar.js.map +1 -0
- package/dist/ui/home-demo/composer.d.ts +11 -0
- package/dist/ui/home-demo/composer.js +12 -0
- package/dist/ui/home-demo/composer.js.map +1 -0
- package/dist/ui/home-demo/greeting.d.ts +5 -0
- package/dist/ui/home-demo/greeting.js +8 -0
- package/dist/ui/home-demo/greeting.js.map +1 -0
- package/dist/ui/home-demo/messages.d.ts +9 -0
- package/dist/ui/home-demo/messages.js +15 -0
- package/dist/ui/home-demo/messages.js.map +1 -0
- package/dist/ui/home-demo/styles.d.ts +3 -0
- package/dist/ui/home-demo/styles.js +4 -0
- package/dist/ui/home-demo/styles.js.map +1 -0
- package/dist/ui/home-demo/suggestions.d.ts +13 -0
- package/dist/ui/home-demo/suggestions.js +21 -0
- package/dist/ui/home-demo/suggestions.js.map +1 -0
- package/dist/ui/home-demo/surfaces.d.ts +4 -0
- package/dist/ui/home-demo/surfaces.js +4 -0
- package/dist/ui/home-demo/surfaces.js.map +1 -0
- package/dist/ui/home-demo/thread.d.ts +13 -0
- package/dist/ui/home-demo/thread.js +12 -0
- package/dist/ui/home-demo/thread.js.map +1 -0
- package/dist/ui/home-demo/trace-line.d.ts +19 -0
- package/dist/ui/home-demo/trace-line.js +38 -0
- package/dist/ui/home-demo/trace-line.js.map +1 -0
- package/dist/ui/home-demo/trace.d.ts +11 -0
- package/dist/ui/home-demo/trace.js +20 -0
- package/dist/ui/home-demo/trace.js.map +1 -0
- package/dist/ui/home-demo/type.d.ts +5 -0
- package/dist/ui/home-demo/type.js +6 -0
- package/dist/ui/home-demo/type.js.map +1 -0
- package/dist/ui/input.js +2 -2
- package/dist/ui/input.js.map +1 -1
- package/dist/ui/markdown-text.js +32 -12
- package/dist/ui/markdown-text.js.map +1 -1
- package/dist/ui/reasoning.aui.d.ts +21 -0
- package/dist/ui/reasoning.aui.js +56 -0
- package/dist/ui/reasoning.aui.js.map +1 -0
- package/dist/ui/reasoning.d.ts +34 -0
- package/dist/ui/reasoning.js +112 -0
- package/dist/ui/reasoning.js.map +1 -0
- package/dist/ui/thread-list.aui.d.ts +7 -4
- package/dist/ui/thread-list.aui.js +53 -5
- package/dist/ui/thread-list.aui.js.map +1 -1
- package/dist/ui/tool-group.aui.d.ts +34 -0
- package/dist/ui/tool-group.aui.js +60 -0
- package/dist/ui/tool-group.aui.js.map +1 -0
- package/package.json +4 -4
- package/dist/ui/thread.aui.d.ts +0 -29
- package/dist/ui/thread.aui.js +0 -26
- package/dist/ui/thread.aui.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-line.js","sourceRoot":"","sources":["../../../src/ui/home-demo/trace-line.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEjC;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,EAC1B,IAAI,EACJ,SAAS,GAIV;IACC,OAAO,CACL,oCAEE,SAAS,EAAE,EAAE,CACX,4CAA4C,EAC5C,IAAI,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,0BAA0B,EACnD,SAAS,CACV,YAEA,GAAG,GACC,CACR,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,SAAkB;IAChD,MAAM,YAAY,GAAG,MAAM,CAAgB,IAAI,CAAC,CAAC;IACjD,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAC;IAE9D,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,SAAS,IAAI,YAAY,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YAC/C,YAAY,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAClC,WAAW,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;aAAM,IAAI,CAAC,SAAS,IAAI,YAAY,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YACvD,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;YAC/C,YAAY,CAAC,OAAO,GAAG,IAAI,CAAC;QAC9B,CAAC;IACH,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,EAAU;IACvC,IAAI,EAAE,GAAG,IAAI;QAAE,OAAO,GAAG,EAAE,IAAI,CAAC;IAChC,OAAO,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,EACxB,IAAI,EACJ,KAAK,EACL,MAAM,EACN,IAAI,GAML;IACC,OAAO,CACL,eAAK,SAAS,EAAE,EAAE,CAAC,oFAAoF,CAAC,aACtG,KAAC,WAAW,IAAC,IAAI,EAAE,IAAI,GAAI,EAC3B,eAAM,SAAS,EAAE,EAAE,CAAC,+CAA+C,CAAC,YACjE,IAAI,CAAC,CAAC,CAAC,CACN,MAAC,YAAY,eACV,KAAK,EACL,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,IAChB,CAChB,CAAC,CAAC,CAAC,CACF,8BACG,KAAK,EACL,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,IAC5B,CACJ,GACI,EACN,IAAI,CAAC,CAAC,CAAC,CACN,eAAM,SAAS,EAAE,EAAE,CAAC,mCAAmC,CAAC,YAAG,IAAI,GAAQ,CACxE,CAAC,CAAC,CAAC,IAAI,IACJ,CACP,CAAC;AACJ,CAAC","sourcesContent":["\"use client\";\n\nimport { useEffect, useRef, useState, type ReactNode } from \"react\";\nimport { ShimmerLabel } from \"./surfaces.js\";\nimport { cn } from \"../utils.js\";\n\n/**\n * The mark every trace line carries. A disclosure rotates it and a plain line\n * does not, so the two read as the same grammar rather than two symbols; it\n * stays a glyph rather than an icon because an icon on a line that cannot open\n * reads as an affordance.\n */\nexport function TraceMarker({\n live,\n className,\n}: {\n live: boolean;\n className?: string;\n}): ReactNode {\n return (\n <span\n aria-hidden\n className={cn(\n \"inline-block shrink-0 transition-transform\",\n live ? \"text-blue-500\" : \"text-muted-foreground/50\",\n className,\n )}\n >\n {\">\"}\n </span>\n );\n}\n\nexport function useToolDuration(isRunning: boolean): number | null {\n const startTimeRef = useRef<number | null>(null);\n const [duration, setDuration] = useState<number | null>(null);\n\n useEffect(() => {\n if (isRunning && startTimeRef.current === null) {\n startTimeRef.current = Date.now();\n setDuration(null);\n } else if (!isRunning && startTimeRef.current !== null) {\n setDuration(Date.now() - startTimeRef.current);\n startTimeRef.current = null;\n }\n }, [isRunning]);\n\n return duration;\n}\n\nexport function formatDuration(ms: number): string {\n if (ms < 1000) return `${ms}ms`;\n return `${(ms / 1000).toFixed(1)}s`;\n}\n\nexport function TraceLine({\n live,\n label,\n detail,\n meta,\n}: {\n live: boolean;\n label: string;\n detail?: string;\n meta?: string;\n}): ReactNode {\n return (\n <div className={cn(\"my-1 flex items-baseline gap-2 font-mono text-[12px] [font-variant-ligatures:none]\")}>\n <TraceMarker live={live} />\n <span className={cn(\"text-muted-foreground min-w-0 flex-1 truncate\")}>\n {live ? (\n <ShimmerLabel>\n {label}\n {detail ? ` ${detail}` : null}\n </ShimmerLabel>\n ) : (\n <>\n {label}\n {detail ? ` ${detail}` : null}\n </>\n )}\n </span>\n {meta ? (\n <span className={cn(\"text-muted-foreground/50 shrink-0\")}>{meta}</span>\n ) : null}\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ToolCallMessagePartProps } from "@assistant-ui/react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
export declare const disclosureContentClass = "border-foreground/10 ms-[5px] border-s ps-4";
|
|
4
|
+
export declare function DisclosureTrigger({ live, label, detail, }: {
|
|
5
|
+
live: boolean;
|
|
6
|
+
label: string;
|
|
7
|
+
detail?: string;
|
|
8
|
+
}): ReactNode;
|
|
9
|
+
export declare function ToolCall({ toolName, args, argsText, result, status, isError, showDetails }: ToolCallMessagePartProps & {
|
|
10
|
+
showDetails: boolean;
|
|
11
|
+
}): ReactNode;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { cn } from "../utils.js";
|
|
3
|
+
import { Collapsible, CollapsibleContent } from "../collapsible.js";
|
|
4
|
+
"use client";
|
|
5
|
+
import { ShimmerLabel } from "./surfaces.js";
|
|
6
|
+
import { CollapsibleTrigger } from "../collapsible.js";
|
|
7
|
+
import { TraceLine, TraceMarker, useToolDuration, formatDuration, } from "./trace-line.js";
|
|
8
|
+
export const disclosureContentClass = "border-foreground/10 ms-[5px] border-s ps-4";
|
|
9
|
+
export function DisclosureTrigger({ live, label, detail, }) {
|
|
10
|
+
return (_jsxs(CollapsibleTrigger, { "data-slot": "tool-group-trigger", className: cn("group/trigger my-1 flex max-w-full items-baseline gap-2 text-left font-mono text-[12px] outline-none [font-variant-ligatures:none] focus-visible:underline"), children: [_jsx(TraceMarker, { live: live, className: cn("group-data-open/trigger:rotate-90 group-data-panel-open/trigger:rotate-90") }), _jsx("span", { className: cn("text-muted-foreground group-hover/trigger:text-foreground min-w-0 truncate transition-colors"), children: live ? (_jsxs(ShimmerLabel, { children: [label, detail ? ` ${detail}` : null] })) : (_jsxs(_Fragment, { children: [label, detail ? ` ${detail}` : null] })) })] }));
|
|
11
|
+
}
|
|
12
|
+
export function ToolCall({ toolName, args, argsText, result, status, isError, showDetails }) {
|
|
13
|
+
const live = status?.type === "running";
|
|
14
|
+
const duration = useToolDuration(live);
|
|
15
|
+
const line = _jsx(TraceLine, { live: live, label: isError ? "failed" : live ? "running" : "ran", detail: toolName, ...(duration === null ? {} : { meta: formatDuration(duration) }) });
|
|
16
|
+
if (!showDetails)
|
|
17
|
+
return line;
|
|
18
|
+
return _jsxs(_Fragment, { children: [line, _jsxs(Collapsible, { children: [_jsx(DisclosureTrigger, { live: false, label: "\u64CD\u4F5C\u660E\u7EC6" }), _jsxs(CollapsibleContent, { className: cn(disclosureContentClass), children: [_jsx("pre", { className: cn("overflow-x-auto text-xs"), "aria-label": "\u64CD\u4F5C\u8F93\u5165", children: argsText || JSON.stringify(args, null, 2) }), result !== undefined ? _jsx("pre", { className: cn("overflow-x-auto text-xs"), "aria-label": "\u64CD\u4F5C\u8F93\u51FA", children: typeof result === "string" ? result : JSON.stringify(result, null, 2) }) : null] })] })] });
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../../../src/ui/home-demo/trace.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACpE,YAAY,CAAC;AAIb,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EACL,SAAS,EACT,WAAW,EACX,eAAe,EACf,cAAc,GACf,MAAM,iBAAiB,CAAC;AAEzB,MAAM,CAAC,MAAM,sBAAsB,GACjC,6CAA6C,CAAC;AAEhD,MAAM,UAAU,iBAAiB,CAAC,EAChC,IAAI,EACJ,KAAK,EACL,MAAM,GAKP;IACC,OAAO,CACL,MAAC,kBAAkB,iBAAW,oBAAoB,EAAC,SAAS,EAAE,EAAE,CAAC,4JAA4J,CAAC,aAC5N,KAAC,WAAW,IACV,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,EAAE,CAAC,2EAA2E,CAAC,GAC1F,EACF,eAAM,SAAS,EAAE,EAAE,CAAC,8FAA8F,CAAC,YAChH,IAAI,CAAC,CAAC,CAAC,CACN,MAAC,YAAY,eACV,KAAK,EACL,MAAM,CAAC,CAAC,CAAC,IAAI,MA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AAE,CAAC,yBAAyB,CAAC,gBAAa,0BAAM,YAAE,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,GAAO,CAAC,CAAC,CAAC,IAAI,IAC1J,IAAc,IAAG,CAAC;AACzC,CAAC","sourcesContent":["import { cn } from \"../utils.js\";\nimport { Collapsible, CollapsibleContent } from \"../collapsible.js\";\n\"use client\";\n\nimport type { ToolCallMessagePartProps } from \"@assistant-ui/react\";\nimport type { ReactNode } from \"react\";\nimport { ShimmerLabel } from \"./surfaces.js\";\nimport { CollapsibleTrigger } from \"../collapsible.js\";\nimport {\n TraceLine,\n TraceMarker,\n useToolDuration,\n formatDuration,\n} from \"./trace-line.js\";\n\nexport const disclosureContentClass =\n \"border-foreground/10 ms-[5px] border-s ps-4\";\n\nexport function DisclosureTrigger({\n live,\n label,\n detail,\n}: {\n live: boolean;\n label: string;\n detail?: string;\n}): ReactNode {\n return (\n <CollapsibleTrigger data-slot=\"tool-group-trigger\" className={cn(\"group/trigger my-1 flex max-w-full items-baseline gap-2 text-left font-mono text-[12px] outline-none [font-variant-ligatures:none] focus-visible:underline\")}>\n <TraceMarker\n live={live}\n className={cn(\"group-data-open/trigger:rotate-90 group-data-panel-open/trigger:rotate-90\")}\n />\n <span className={cn(\"text-muted-foreground group-hover/trigger:text-foreground min-w-0 truncate transition-colors\")}>\n {live ? (\n <ShimmerLabel>\n {label}\n {detail ? ` ${detail}` : null}\n </ShimmerLabel>\n ) : (\n <>\n {label}\n {detail ? ` ${detail}` : null}\n </>\n )}\n </span>\n </CollapsibleTrigger>\n );\n}\n\nexport function ToolCall({ toolName, args, argsText, result, status, isError, showDetails }: ToolCallMessagePartProps & { showDetails: boolean }): ReactNode {\n const live = status?.type === \"running\";\n const duration = useToolDuration(live);\n const line = <TraceLine live={live} label={isError ? \"failed\" : live ? \"running\" : \"ran\"} detail={toolName} {...(duration === null ? {} : { meta: formatDuration(duration) })} />;\n if (!showDetails) return line;\n return <>{line}<Collapsible><DisclosureTrigger live={false} label=\"操作明细\" /><CollapsibleContent className={cn(disclosureContentClass)}>\n <pre className={cn(\"overflow-x-auto text-xs\")} aria-label=\"操作输入\">{argsText || JSON.stringify(args, null, 2)}</pre>\n {result !== undefined ? <pre className={cn(\"overflow-x-auto text-xs\")} aria-label=\"操作输出\">{typeof result === \"string\" ? result : JSON.stringify(result, null, 2)}</pre> : null}\n </CollapsibleContent></Collapsible></>;\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const typeHero = "font-display text-[2.75rem] leading-[1.04] font-medium tracking-[-0.015em] text-balance lg:text-[4.5rem]";
|
|
2
|
+
export declare const typeSection = "font-display text-[1.5rem] leading-snug font-[550] tracking-[-0.01em] text-balance lg:text-[1.75rem]";
|
|
3
|
+
export declare const typePage = "font-display text-3xl font-[550] tracking-[-0.01em] text-balance md:text-4xl";
|
|
4
|
+
export declare const typeDeck = "text-muted-foreground max-w-[40ch] text-[15px] leading-relaxed text-pretty";
|
|
5
|
+
export declare const typePackage = "font-mono text-[1.5rem] leading-snug font-medium tracking-[-0.01em] text-balance lg:text-[1.75rem] [font-variant-ligatures:none]";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const typeHero = "font-display text-[2.75rem] leading-[1.04] font-medium tracking-[-0.015em] text-balance lg:text-[4.5rem]";
|
|
2
|
+
export const typeSection = "font-display text-[1.5rem] leading-snug font-[550] tracking-[-0.01em] text-balance lg:text-[1.75rem]";
|
|
3
|
+
export const typePage = "font-display text-3xl font-[550] tracking-[-0.01em] text-balance md:text-4xl";
|
|
4
|
+
export const typeDeck = "text-muted-foreground max-w-[40ch] text-[15px] leading-relaxed text-pretty";
|
|
5
|
+
export const typePackage = "font-mono text-[1.5rem] leading-snug font-medium tracking-[-0.01em] text-balance lg:text-[1.75rem] [font-variant-ligatures:none]";
|
|
6
|
+
//# sourceMappingURL=type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/ui/home-demo/type.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GACnB,0GAA0G,CAAC;AAE7G,MAAM,CAAC,MAAM,WAAW,GACtB,sGAAsG,CAAC;AAEzG,MAAM,CAAC,MAAM,QAAQ,GACnB,8EAA8E,CAAC;AAEjF,MAAM,CAAC,MAAM,QAAQ,GACnB,4EAA4E,CAAC;AAE/E,MAAM,CAAC,MAAM,WAAW,GACtB,kIAAkI,CAAC","sourcesContent":["export const typeHero =\n \"font-display text-[2.75rem] leading-[1.04] font-medium tracking-[-0.015em] text-balance lg:text-[4.5rem]\";\n\nexport const typeSection =\n \"font-display text-[1.5rem] leading-snug font-[550] tracking-[-0.01em] text-balance lg:text-[1.75rem]\";\n\nexport const typePage =\n \"font-display text-3xl font-[550] tracking-[-0.01em] text-balance md:text-4xl\";\n\nexport const typeDeck =\n \"text-muted-foreground max-w-[40ch] text-[15px] leading-relaxed text-pretty\";\n\nexport const typePackage =\n \"font-mono text-[1.5rem] leading-snug font-medium tracking-[-0.01em] text-balance lg:text-[1.75rem] [font-variant-ligatures:none]\";\n"]}
|
package/dist/ui/input.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use client";
|
|
2
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
2
|
import * as React from "react";
|
|
3
|
+
import { Input as InputPrimitive } from "@base-ui/react/input";
|
|
4
4
|
import { cn } from "./utils.js";
|
|
5
5
|
const Input = React.forwardRef(function Input({ className, type, ...props }, ref) {
|
|
6
|
-
return (_jsx(
|
|
6
|
+
return (_jsx(InputPrimitive, { ref: ref, type: type, "data-slot": "input", className: cn("file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 disabled:bg-input/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 bg-muted/60 focus-visible:bg-background h-9 w-full min-w-0 rounded-lg border border-transparent px-3 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:ring-1 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-1 md:text-sm", className), ...props }));
|
|
7
7
|
});
|
|
8
8
|
export { Input };
|
|
9
9
|
//# sourceMappingURL=input.js.map
|
package/dist/ui/input.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../src/ui/input.tsx"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"input.js","sourceRoot":"","sources":["../../src/ui/input.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,KAAK,IAAI,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAEhC,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAA4D,SAAS,KAAK,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG;IACzI,OAAO,CACL,KAAC,cAAc,IACb,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,eACA,OAAO,EACjB,SAAS,EAAE,EAAE,CACX,ypBAAypB,EACzpB,SAAS,CACV,KACG,KAAK,GACT,CACH,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,OAAO,EAAE,KAAK,EAAE,CAAC","sourcesContent":["import * as React from \"react\";\nimport { Input as InputPrimitive } from \"@base-ui/react/input\";\n\nimport { cn } from \"./utils.js\";\n\nconst Input = React.forwardRef<HTMLInputElement, React.ComponentPropsWithoutRef<\"input\">>(function Input({ className, type, ...props }, ref) {\n return (\n <InputPrimitive\n ref={ref}\n type={type}\n data-slot=\"input\"\n className={cn(\n \"file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 disabled:bg-input/50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 bg-muted/60 focus-visible:bg-background h-9 w-full min-w-0 rounded-lg border border-transparent px-3 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium focus-visible:ring-1 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:ring-1 md:text-sm\",\n className,\n )}\n {...props}\n />\n );\n});\n\nexport { Input };\n"]}
|
package/dist/ui/markdown-text.js
CHANGED
|
@@ -4,7 +4,7 @@ import { MarkdownTextPrimitive, unstable_memoizeMarkdownComponents as memoizeMar
|
|
|
4
4
|
import remarkGfm from "remark-gfm";
|
|
5
5
|
import { memo, useMemo, useRef } from "react";
|
|
6
6
|
import { CheckIcon, CopyIcon } from "lucide-react";
|
|
7
|
-
import {
|
|
7
|
+
import { CodeBlock } from "./code-block.js";
|
|
8
8
|
import { useCopyToClipboard } from "./use-copy-to-clipboard.js";
|
|
9
9
|
import { cn } from "./utils.js";
|
|
10
10
|
const useShallowStable = (value) => {
|
|
@@ -33,15 +33,34 @@ const MarkdownTextImpl = ({ components }) => {
|
|
|
33
33
|
return (_jsx(MarkdownTextPrimitive, { remarkPlugins: [remarkGfm], skipHtml: true, className: cn("aui-md"), components: markdownComponents, defer: true }));
|
|
34
34
|
};
|
|
35
35
|
export const MarkdownText = memo(MarkdownTextImpl);
|
|
36
|
-
|
|
36
|
+
function MarkdownTable({ className, children, ...props }) {
|
|
37
|
+
const ref = useRef(null);
|
|
37
38
|
const { isCopied, copyToClipboard } = useCopyToClipboard();
|
|
38
|
-
const
|
|
39
|
-
|
|
39
|
+
const copy = () => {
|
|
40
|
+
const table = ref.current;
|
|
41
|
+
if (!table)
|
|
40
42
|
return;
|
|
41
|
-
|
|
43
|
+
const rows = [...table.querySelectorAll("tr")].map((row) => [...row.querySelectorAll("th, td")].map((cell) => (cell.textContent ?? "")
|
|
44
|
+
.replace(/\s+/g, " ")
|
|
45
|
+
.trim()
|
|
46
|
+
// The backslash goes first: escaping the pipe alone would turn a cell's
|
|
47
|
+
// own backslash into the escape for it.
|
|
48
|
+
.replace(/[\\|]/g, "\\$&")));
|
|
49
|
+
if (rows.length === 0)
|
|
50
|
+
return;
|
|
51
|
+
const width = Math.max(...rows.map((row) => row.length));
|
|
52
|
+
const pad = (row) => `| ${Array.from({ length: width }, (_, i) => row[i] ?? "").join(" | ")} |`;
|
|
53
|
+
const [header, ...body] = rows;
|
|
54
|
+
copyToClipboard([
|
|
55
|
+
pad(header),
|
|
56
|
+
`| ${Array.from({ length: width }, () => "---").join(" | ")} |`,
|
|
57
|
+
...body.map(pad),
|
|
58
|
+
].join("\n"));
|
|
42
59
|
};
|
|
43
|
-
return (_jsxs("
|
|
44
|
-
}
|
|
60
|
+
return (_jsxs("figure", { className: cn("border-foreground/10 rounded-document my-3 border"), children: [_jsxs("div", { className: cn("border-foreground/10 bg-foreground/[0.025] dark:bg-foreground/[0.04] rounded-t-document flex h-9 items-center justify-between border-b px-3"), children: [_jsx("span", { className: cn("text-muted-foreground font-mono text-[11px] [font-variant-ligatures:none]"), children: "\u8868\u683C" }), _jsx("button", { type: "button", onClick: copy, "aria-label": "\u590D\u5236\u8868\u683C Markdown", className: cn("text-muted-foreground hover:text-foreground rounded-control grid size-6 place-items-center transition-colors"), children: isCopied ? (_jsx(CheckIcon, { className: cn("size-3.5") })) : (_jsx(CopyIcon, { className: cn("size-3.5") })) })] }), _jsx("div", { className: cn("overflow-x-auto"), children: _jsx("table", { ref: ref, className: cn("aui-md-table w-full border-separate border-spacing-0 text-[13px]", className), ...props, children: children }) })] }));
|
|
61
|
+
}
|
|
62
|
+
const SyntaxHighlighter = ({ language, code }) => _jsx(CodeBlock, { title: language || undefined, copyText: code, className: cn("my-3"), children: _jsx("pre", { children: _jsx("code", { children: code }) }) });
|
|
63
|
+
const NoCodeHeader = () => null;
|
|
45
64
|
const defaultComponents = memoizeMarkdownComponents({
|
|
46
65
|
h1: ({ className, ...props }) => (_jsx("h1", { className: cn("aui-md-h1 mt-5 mb-2 scroll-m-20 text-xl font-semibold first:mt-0 last:mb-0", className), ...props })),
|
|
47
66
|
h2: ({ className, ...props }) => (_jsx("h2", { className: cn("aui-md-h2 mt-5 mb-2 scroll-m-20 text-lg font-semibold first:mt-0 last:mb-0", className), ...props })),
|
|
@@ -55,10 +74,10 @@ const defaultComponents = memoizeMarkdownComponents({
|
|
|
55
74
|
ul: ({ className, ...props }) => (_jsx("ul", { className: cn("aui-md-ul marker:text-muted-foreground my-3 ms-5 list-disc [&>li]:mt-1", className), ...props })),
|
|
56
75
|
ol: ({ className, ...props }) => (_jsx("ol", { className: cn("aui-md-ol marker:text-muted-foreground my-3 ms-5 list-decimal [&>li]:mt-1", className), ...props })),
|
|
57
76
|
hr: ({ className, ...props }) => (_jsx("hr", { className: cn("aui-md-hr border-muted-foreground/20 my-3", className), ...props })),
|
|
58
|
-
table: ({ className, ...props }) =>
|
|
59
|
-
th: ({ className, ...props }) => (_jsx("th", { className: cn("aui-md-th
|
|
60
|
-
td: ({ className, ...props }) => (_jsx("td", { className: cn("aui-md-td border-
|
|
61
|
-
tr: ({ className, ...props }) => (_jsx("tr", { className: cn("aui-md-tr m-0
|
|
77
|
+
table: ({ className, ...props }) => _jsx(MarkdownTable, { className: className, ...props }),
|
|
78
|
+
th: ({ className, ...props }) => (_jsx("th", { className: cn("aui-md-th border-foreground/10 border-b px-3 py-1.5 text-start font-medium [[align=center]]:text-center [[align=right]]:text-right", className), ...props })),
|
|
79
|
+
td: ({ className, ...props }) => (_jsx("td", { className: cn("aui-md-td border-foreground/10 border-b px-3 py-1.5 text-start [[align=center]]:text-center [[align=right]]:text-right", className), ...props })),
|
|
80
|
+
tr: ({ className, ...props }) => (_jsx("tr", { className: cn("aui-md-tr m-0 p-0", className), ...props })),
|
|
62
81
|
li: ({ className, ...props }) => (_jsx("li", { className: cn("aui-md-li leading-relaxed", className), ...props })),
|
|
63
82
|
strong: ({ className, ...props }) => (_jsx("strong", { className: cn("aui-md-strong font-semibold", className), ...props })),
|
|
64
83
|
sup: ({ className, ...props }) => (_jsx("sup", { className: cn("aui-md-sup [&>a]:text-xs [&>a]:no-underline", className), ...props })),
|
|
@@ -68,6 +87,7 @@ const defaultComponents = memoizeMarkdownComponents({
|
|
|
68
87
|
return (_jsx("code", { className: cn(!isCodeBlock &&
|
|
69
88
|
"aui-md-inline-code bg-muted rounded-md px-1.5 py-0.5 font-mono text-[0.85em]", className), ...props }));
|
|
70
89
|
},
|
|
71
|
-
CodeHeader,
|
|
90
|
+
CodeHeader: NoCodeHeader,
|
|
91
|
+
SyntaxHighlighter,
|
|
72
92
|
});
|
|
73
93
|
//# sourceMappingURL=markdown-text.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown-text.js","sourceRoot":"","sources":["../../src/ui/markdown-text.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAwB,qBAAqB,EAAE,kCAAkC,IAAI,yBAAyB,EAAE,sBAAsB,GAAG,MAAM,8BAA8B,CAAC;AACrL,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAW,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEvD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAIhC,MAAM,gBAAgB,GAAG,CAAgD,KAAQ,EAAK,EAAE;IACtF,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,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,SAAS,EAAE,EAAE,CAAC,6BAA6B,EAAE,SAAS,CAAC,KAAM,KAAK,GAAG,CAAC;IACpH,GAAG,EAAE,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,cAAK,SAAS,EAAE,EAAE,CAAC,6CAA6C,EAAE,SAAS,CAAC,KAAM,KAAK,GAAG,CAAC;IAC9H,GAAG,EAAE,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,cAAK,SAAS,EAAE,EAAE,CAAC,yIAAyI,EAAE,SAAS,CAAC,KAAM,KAAK,GAAG,CAAC;IAC1N,IAAI,EAAE,SAAS,IAAI,CAAC,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE;QACzC,MAAM,WAAW,GAAG,sBAAsB,EAAE,CAAC;QAC7C,OAAO,CAAC,eAAM,SAAS,EAAE,EAAE,CAAC,CAAC,WAAW;gBACpC,8EAA8E,EAAE,SAAS,CAAC,KAAM,KAAK,GAAG,CAAC,CAAC;IAChH,CAAC;IACD,UAAU;CACX,CAAC,CAAC","sourcesContent":["\"use client\";\nimport { type CodeHeaderProps, MarkdownTextPrimitive, unstable_memoizeMarkdownComponents as memoizeMarkdownComponents, useIsMarkdownCodeBlock, } from \"@assistant-ui/react-markdown\";\nimport remarkGfm from \"remark-gfm\";\nimport { type FC, memo, useMemo, useRef } from \"react\";\nimport type { TextMessagePartProps } from \"@assistant-ui/react\";\nimport { CheckIcon, CopyIcon } from \"lucide-react\";\nimport { TooltipIconButton } from \"./tooltip-icon-button.js\";\nimport { useCopyToClipboard } from \"./use-copy-to-clipboard.js\";\nimport { cn } from \"./utils.js\";\ntype MarkdownTextProps = Partial<TextMessagePartProps> & {\n components?: Parameters<typeof memoizeMarkdownComponents>[0];\n};\nconst useShallowStable = <T extends Record<string, unknown> | undefined>(value: T): T => {\n const ref = useRef(value);\n if (value !== ref.current) {\n const prev = ref.current;\n const stable = value !== undefined &&\n prev !== undefined &&\n Object.keys(prev).length === Object.keys(value).length &&\n Object.keys(value).every((key) => prev[key] === value[key]);\n if (!stable)\n ref.current = value;\n }\n return ref.current;\n};\nconst MarkdownTextImpl: FC<MarkdownTextProps> = ({ components }) => {\n const stableComponents = useShallowStable(components);\n const markdownComponents = useMemo(() => {\n if (!stableComponents)\n return defaultComponents;\n return {\n ...defaultComponents,\n ...memoizeMarkdownComponents(stableComponents),\n };\n }, [stableComponents]);\n return (<MarkdownTextPrimitive remarkPlugins={[remarkGfm]} skipHtml className={cn(\"aui-md\")} components={markdownComponents} defer/>);\n};\nexport const MarkdownText = memo(MarkdownTextImpl);\nconst CodeHeader: FC<CodeHeaderProps> = ({ language, code }) => {\n const { isCopied, copyToClipboard } = useCopyToClipboard();\n const onCopy = () => {\n if (!code || isCopied)\n return;\n copyToClipboard(code);\n };\n return (<div className={cn(\"aui-code-header-root border-border/50 bg-muted/50 mt-3 flex items-center justify-between rounded-t-xl border border-b-0 px-3.5 py-1.5 text-xs\")}>\n <span className={cn(\"aui-code-header-language text-muted-foreground font-medium lowercase\")}>\n {language}\n </span>\n <TooltipIconButton tooltip=\"Copy\" onClick={onCopy}>\n {!isCopied && (<CopyIcon className={cn(\"animate-in zoom-in-75 fade-in duration-150\")}/>)}\n {isCopied && (<CheckIcon className={cn(\"animate-in zoom-in-50 fade-in duration-200 ease-out\")}/>)}\n </TooltipIconButton>\n </div>);\n};\nconst defaultComponents = memoizeMarkdownComponents({\n h1: ({ className, ...props }) => (<h1 className={cn(\"aui-md-h1 mt-5 mb-2 scroll-m-20 text-xl font-semibold first:mt-0 last:mb-0\", className)} {...props}/>),\n h2: ({ className, ...props }) => (<h2 className={cn(\"aui-md-h2 mt-5 mb-2 scroll-m-20 text-lg font-semibold first:mt-0 last:mb-0\", className)} {...props}/>),\n h3: ({ className, ...props }) => (<h3 className={cn(\"aui-md-h3 mt-4 mb-1.5 scroll-m-20 text-base font-semibold first:mt-0 last:mb-0\", className)} {...props}/>),\n h4: ({ className, ...props }) => (<h4 className={cn(\"aui-md-h4 mt-3.5 mb-1 scroll-m-20 text-base font-medium first:mt-0 last:mb-0\", className)} {...props}/>),\n h5: ({ className, ...props }) => (<h5 className={cn(\"aui-md-h5 mt-3 mb-1 text-sm font-semibold first:mt-0 last:mb-0\", className)} {...props}/>),\n h6: ({ className, ...props }) => (<h6 className={cn(\"aui-md-h6 mt-3 mb-1 text-sm font-medium first:mt-0 last:mb-0\", className)} {...props}/>),\n p: ({ className, ...props }) => (<p className={cn(\"aui-md-p my-3 leading-relaxed first:mt-0 last:mb-0\", className)} {...props}/>),\n a: ({ className, ...props }) => (<a className={cn(\"aui-md-a text-primary hover:text-primary/80 underline underline-offset-2\", className)} {...props}/>),\n blockquote: ({ className, ...props }) => (<blockquote className={cn(\"aui-md-blockquote border-muted-foreground/30 text-muted-foreground my-3 border-s-2 ps-4\", className)} {...props}/>),\n ul: ({ className, ...props }) => (<ul className={cn(\"aui-md-ul marker:text-muted-foreground my-3 ms-5 list-disc [&>li]:mt-1\", className)} {...props}/>),\n ol: ({ className, ...props }) => (<ol className={cn(\"aui-md-ol marker:text-muted-foreground my-3 ms-5 list-decimal [&>li]:mt-1\", className)} {...props}/>),\n hr: ({ className, ...props }) => (<hr className={cn(\"aui-md-hr border-muted-foreground/20 my-3\", className)} {...props}/>),\n table: ({ className, ...props }) => (<div className={cn(\"aui-md-table-wrapper my-3 overflow-x-auto\")}>\n <table className={cn(\"aui-md-table w-full border-separate border-spacing-0\", className)} {...props}/>\n </div>),\n th: ({ className, ...props }) => (<th className={cn(\"aui-md-th bg-muted px-3 py-1.5 text-start font-medium first:rounded-ss-lg last:rounded-se-lg [[align=center]]:text-center [[align=right]]:text-right\", className)} {...props}/>),\n td: ({ className, ...props }) => (<td className={cn(\"aui-md-td border-muted-foreground/20 border-s border-b px-3 py-1.5 text-start last:border-e [[align=center]]:text-center [[align=right]]:text-right\", className)} {...props}/>),\n tr: ({ className, ...props }) => (<tr className={cn(\"aui-md-tr m-0 border-b p-0 first:border-t [&:last-child>td:first-child]:rounded-es-lg [&:last-child>td:last-child]:rounded-ee-lg\", className)} {...props}/>),\n li: ({ className, ...props }) => (<li className={cn(\"aui-md-li leading-relaxed\", className)} {...props}/>),\n strong: ({ className, ...props }) => (<strong className={cn(\"aui-md-strong font-semibold\", className)} {...props}/>),\n sup: ({ className, ...props }) => (<sup className={cn(\"aui-md-sup [&>a]:text-xs [&>a]:no-underline\", className)} {...props}/>),\n pre: ({ className, ...props }) => (<pre className={cn(\"aui-md-pre border-border/50 bg-muted/30 overflow-x-auto rounded-t-none rounded-b-xl border border-t-0 p-3.5 text-[13px] leading-relaxed\", className)} {...props}/>),\n code: function Code({ className, ...props }) {\n const isCodeBlock = useIsMarkdownCodeBlock();\n return (<code className={cn(!isCodeBlock &&\n \"aui-md-inline-code bg-muted rounded-md px-1.5 py-0.5 font-mono text-[0.85em]\", className)} {...props}/>);\n },\n CodeHeader,\n});\n"]}
|
|
1
|
+
{"version":3,"file":"markdown-text.js","sourceRoot":"","sources":["../../src/ui/markdown-text.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAA+B,qBAAqB,EAAE,kCAAkC,IAAI,yBAAyB,EAAE,sBAAsB,GAAG,MAAM,8BAA8B,CAAC;AAC5L,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAgC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE5E,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAIhC,MAAM,gBAAgB,GAAG,CAAgD,KAAQ,EAAK,EAAE;IACtF,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC1B,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port { type SyntaxHighlighterProps, MarkdownTextPrimitive, unstable_memoizeMarkdownComponents as memoizeMarkdownComponents, useIsMarkdownCodeBlock, } from \"@assistant-ui/react-markdown\";\nimport remarkGfm from \"remark-gfm\";\nimport { type FC, type ComponentProps, memo, useMemo, useRef } from \"react\";\nimport type { TextMessagePartProps } from \"@assistant-ui/react\";\nimport { CheckIcon, CopyIcon } from \"lucide-react\";\nimport { CodeBlock } from \"./code-block.js\";\nimport { useCopyToClipboard } from \"./use-copy-to-clipboard.js\";\nimport { cn } from \"./utils.js\";\ntype MarkdownTextProps = Partial<TextMessagePartProps> & {\n components?: Parameters<typeof memoizeMarkdownComponents>[0];\n};\nconst useShallowStable = <T extends Record<string, unknown> | undefined>(value: T): T => {\n const ref = useRef(value);\n if (value !== ref.current) {\n const prev = ref.current;\n const stable = value !== undefined &&\n prev !== undefined &&\n Object.keys(prev).length === Object.keys(value).length &&\n Object.keys(value).every((key) => prev[key] === value[key]);\n if (!stable)\n ref.current = value;\n }\n return ref.current;\n};\nconst MarkdownTextImpl: FC<MarkdownTextProps> = ({ components }) => {\n const stableComponents = useShallowStable(components);\n const markdownComponents = useMemo(() => {\n if (!stableComponents)\n return defaultComponents;\n return {\n ...defaultComponents,\n ...memoizeMarkdownComponents(stableComponents),\n };\n }, [stableComponents]);\n return (<MarkdownTextPrimitive remarkPlugins={[remarkGfm]} skipHtml className={cn(\"aui-md\")} components={markdownComponents} defer/>);\n};\nexport const MarkdownText = memo(MarkdownTextImpl);\nfunction MarkdownTable({\n className,\n children,\n ...props\n}: ComponentProps<\"table\">) {\n const ref = useRef<HTMLTableElement>(null);\n const { isCopied, copyToClipboard } = useCopyToClipboard();\n\n const copy = () => {\n const table = ref.current;\n if (!table) return;\n\n const rows = [...table.querySelectorAll(\"tr\")].map((row) =>\n [...row.querySelectorAll(\"th, td\")].map((cell) =>\n (cell.textContent ?? \"\")\n .replace(/\\s+/g, \" \")\n .trim()\n // The backslash goes first: escaping the pipe alone would turn a cell's\n // own backslash into the escape for it.\n .replace(/[\\\\|]/g, \"\\\\$&\"),\n ),\n );\n if (rows.length === 0) return;\n\n const width = Math.max(...rows.map((row) => row.length));\n const pad = (row: string[]) =>\n `| ${Array.from({ length: width }, (_, i) => row[i] ?? \"\").join(\" | \")} |`;\n const [header, ...body] = rows;\n copyToClipboard(\n [\n pad(header!),\n `| ${Array.from({ length: width }, () => \"---\").join(\" | \")} |`,\n ...body.map(pad),\n ].join(\"\\n\"),\n );\n };\n\n return (\n <figure className={cn(\"border-foreground/10 rounded-document my-3 border\")}>\n <div className={cn(\"border-foreground/10 bg-foreground/[0.025] dark:bg-foreground/[0.04] rounded-t-document flex h-9 items-center justify-between border-b px-3\")}>\n <span className={cn(\"text-muted-foreground font-mono text-[11px] [font-variant-ligatures:none]\")}>\n 表格\n </span>\n <button\n type=\"button\"\n onClick={copy}\n aria-label=\"复制表格 Markdown\"\n className={cn(\"text-muted-foreground hover:text-foreground rounded-control grid size-6 place-items-center transition-colors\")}\n >\n {isCopied ? (\n <CheckIcon className={cn(\"size-3.5\")} />\n ) : (\n <CopyIcon className={cn(\"size-3.5\")} />\n )}\n </button>\n </div>\n <div className={cn(\"overflow-x-auto\")}>\n <table\n ref={ref}\n className={cn(\n \"aui-md-table w-full border-separate border-spacing-0 text-[13px]\",\n className,\n )}\n {...props}\n >\n {children}\n </table>\n </div>\n </figure>\n );\n}\n\nconst SyntaxHighlighter = ({ language, code }: SyntaxHighlighterProps) => <CodeBlock title={language || undefined} copyText={code} className={cn(\"my-3\")}><pre><code>{code}</code></pre></CodeBlock>;\nconst NoCodeHeader = () => null;\nconst defaultComponents = memoizeMarkdownComponents({\n h1: ({ className, ...props }) => (<h1 className={cn(\"aui-md-h1 mt-5 mb-2 scroll-m-20 text-xl font-semibold first:mt-0 last:mb-0\", className)} {...props}/>),\n h2: ({ className, ...props }) => (<h2 className={cn(\"aui-md-h2 mt-5 mb-2 scroll-m-20 text-lg font-semibold first:mt-0 last:mb-0\", className)} {...props}/>),\n h3: ({ className, ...props }) => (<h3 className={cn(\"aui-md-h3 mt-4 mb-1.5 scroll-m-20 text-base font-semibold first:mt-0 last:mb-0\", className)} {...props}/>),\n h4: ({ className, ...props }) => (<h4 className={cn(\"aui-md-h4 mt-3.5 mb-1 scroll-m-20 text-base font-medium first:mt-0 last:mb-0\", className)} {...props}/>),\n h5: ({ className, ...props }) => (<h5 className={cn(\"aui-md-h5 mt-3 mb-1 text-sm font-semibold first:mt-0 last:mb-0\", className)} {...props}/>),\n h6: ({ className, ...props }) => (<h6 className={cn(\"aui-md-h6 mt-3 mb-1 text-sm font-medium first:mt-0 last:mb-0\", className)} {...props}/>),\n p: ({ className, ...props }) => (<p className={cn(\"aui-md-p my-3 leading-relaxed first:mt-0 last:mb-0\", className)} {...props}/>),\n a: ({ className, ...props }) => (<a className={cn(\"aui-md-a text-primary hover:text-primary/80 underline underline-offset-2\", className)} {...props}/>),\n blockquote: ({ className, ...props }) => (<blockquote className={cn(\"aui-md-blockquote border-muted-foreground/30 text-muted-foreground my-3 border-s-2 ps-4\", className)} {...props}/>),\n ul: ({ className, ...props }) => (<ul className={cn(\"aui-md-ul marker:text-muted-foreground my-3 ms-5 list-disc [&>li]:mt-1\", className)} {...props}/>),\n ol: ({ className, ...props }) => (<ol className={cn(\"aui-md-ol marker:text-muted-foreground my-3 ms-5 list-decimal [&>li]:mt-1\", className)} {...props}/>),\n hr: ({ className, ...props }) => (<hr className={cn(\"aui-md-hr border-muted-foreground/20 my-3\", className)} {...props}/>),\n table: ({ className, ...props }) => <MarkdownTable className={className} {...props} />,\n th: ({ className, ...props }) => (<th className={cn(\"aui-md-th border-foreground/10 border-b px-3 py-1.5 text-start font-medium [[align=center]]:text-center [[align=right]]:text-right\", className)} {...props}/>),\n td: ({ className, ...props }) => (<td className={cn(\"aui-md-td border-foreground/10 border-b px-3 py-1.5 text-start [[align=center]]:text-center [[align=right]]:text-right\", className)} {...props}/>),\n tr: ({ className, ...props }) => (<tr className={cn(\"aui-md-tr m-0 p-0\", className)} {...props}/>),\n li: ({ className, ...props }) => (<li className={cn(\"aui-md-li leading-relaxed\", className)} {...props}/>),\n strong: ({ className, ...props }) => (<strong className={cn(\"aui-md-strong font-semibold\", className)} {...props}/>),\n sup: ({ className, ...props }) => (<sup className={cn(\"aui-md-sup [&>a]:text-xs [&>a]:no-underline\", className)} {...props}/>),\n pre: ({ className, ...props }) => (<pre className={cn(\"aui-md-pre border-border/50 bg-muted/30 overflow-x-auto rounded-t-none rounded-b-xl border border-t-0 p-3.5 text-[13px] leading-relaxed\", className)} {...props}/>),\n code: function Code({ className, ...props }) {\n const isCodeBlock = useIsMarkdownCodeBlock();\n return (<code className={cn(!isCodeBlock &&\n \"aui-md-inline-code bg-muted rounded-md px-1.5 py-0.5 font-mono text-[0.85em]\", className)} {...props}/>);\n },\n CodeHeader: NoCodeHeader,\n SyntaxHighlighter,\n});\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ReasoningMessagePartComponent } from "@assistant-ui/react";
|
|
2
|
+
import { ReasoningTrigger, ReasoningContent, ReasoningText, ReasoningFade, reasoningVariants, type ReasoningRootProps } from "./reasoning.js";
|
|
3
|
+
export type { ReasoningRootProps } from "./reasoning.js";
|
|
4
|
+
/** `ReasoningRoot` with the thread viewport scroll locked during disclosure animations. */
|
|
5
|
+
declare function ReasoningRoot({ ref, onAnimationStart, ...props }: ReasoningRootProps): import("react").JSX.Element;
|
|
6
|
+
declare const Reasoning: ReasoningMessagePartComponent & {
|
|
7
|
+
Root: typeof ReasoningRoot;
|
|
8
|
+
Trigger: typeof ReasoningTrigger;
|
|
9
|
+
Content: typeof ReasoningContent;
|
|
10
|
+
Text: typeof ReasoningText;
|
|
11
|
+
Fade: typeof ReasoningFade;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated This wrapper targets the legacy `components.ReasoningGroup`
|
|
15
|
+
* prop on `<MessagePrimitive.Parts>`. Use `<MessagePrimitive.GroupedParts>`
|
|
16
|
+
* with a `groupBy` returning `"group-reasoning"` and compose `ReasoningRoot`
|
|
17
|
+
* / `ReasoningTrigger` / `ReasoningContent` / `ReasoningText` directly.
|
|
18
|
+
* See `thread.aui.tsx` for an example.
|
|
19
|
+
*/
|
|
20
|
+
declare const ReasoningGroup: import("react").NamedExoticComponent<import("@assistant-ui/react").ReasoningGroupProps>;
|
|
21
|
+
export { Reasoning, ReasoningGroup, ReasoningRoot, ReasoningTrigger, ReasoningContent, ReasoningText, ReasoningFade, reasoningVariants, };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { memo, useCallback, useRef } from "react";
|
|
4
|
+
import { useScrollLock, useAuiState, } from "@assistant-ui/react";
|
|
5
|
+
import { MarkdownText } from "./markdown-text.js";
|
|
6
|
+
import { ANIMATION_DURATION, ReasoningRoot as ReasoningRootBase, ReasoningTrigger, ReasoningContent, ReasoningText, ReasoningFade, reasoningVariants, } from "./reasoning.js";
|
|
7
|
+
/** `ReasoningRoot` with the thread viewport scroll locked during disclosure animations. */
|
|
8
|
+
function ReasoningRoot({ ref, onAnimationStart, ...props }) {
|
|
9
|
+
const collapsibleRef = useRef(null);
|
|
10
|
+
const lockScroll = useScrollLock(collapsibleRef, ANIMATION_DURATION);
|
|
11
|
+
const handleAnimationStart = useCallback(() => {
|
|
12
|
+
lockScroll();
|
|
13
|
+
onAnimationStart?.();
|
|
14
|
+
}, [lockScroll, onAnimationStart]);
|
|
15
|
+
const composedRef = useCallback((node) => {
|
|
16
|
+
collapsibleRef.current = node;
|
|
17
|
+
if (typeof ref === "function") {
|
|
18
|
+
ref(node);
|
|
19
|
+
}
|
|
20
|
+
else if (ref) {
|
|
21
|
+
ref.current = node;
|
|
22
|
+
}
|
|
23
|
+
}, [ref]);
|
|
24
|
+
return (_jsx(ReasoningRootBase, { ref: composedRef, onAnimationStart: handleAnimationStart, ...props }));
|
|
25
|
+
}
|
|
26
|
+
const ReasoningImpl = () => _jsx(MarkdownText, {});
|
|
27
|
+
const ReasoningGroupImpl = ({ children, startIndex, endIndex, }) => {
|
|
28
|
+
const isReasoningStreaming = useAuiState((s) => {
|
|
29
|
+
if (s.message.status?.type !== "running")
|
|
30
|
+
return false;
|
|
31
|
+
for (let index = startIndex; index <= endIndex; index++) {
|
|
32
|
+
if (s.message.parts[index]?.status.type === "running")
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
});
|
|
37
|
+
return (_jsxs(ReasoningRoot, { streaming: isReasoningStreaming, children: [_jsx(ReasoningTrigger, { active: isReasoningStreaming }), _jsx(ReasoningContent, { "aria-busy": isReasoningStreaming, children: _jsx(ReasoningText, { children: children }) })] }));
|
|
38
|
+
};
|
|
39
|
+
const Reasoning = memo(ReasoningImpl);
|
|
40
|
+
Reasoning.displayName = "Reasoning";
|
|
41
|
+
Reasoning.Root = ReasoningRoot;
|
|
42
|
+
Reasoning.Trigger = ReasoningTrigger;
|
|
43
|
+
Reasoning.Content = ReasoningContent;
|
|
44
|
+
Reasoning.Text = ReasoningText;
|
|
45
|
+
Reasoning.Fade = ReasoningFade;
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated This wrapper targets the legacy `components.ReasoningGroup`
|
|
48
|
+
* prop on `<MessagePrimitive.Parts>`. Use `<MessagePrimitive.GroupedParts>`
|
|
49
|
+
* with a `groupBy` returning `"group-reasoning"` and compose `ReasoningRoot`
|
|
50
|
+
* / `ReasoningTrigger` / `ReasoningContent` / `ReasoningText` directly.
|
|
51
|
+
* See `thread.aui.tsx` for an example.
|
|
52
|
+
*/
|
|
53
|
+
const ReasoningGroup = memo(ReasoningGroupImpl);
|
|
54
|
+
ReasoningGroup.displayName = "ReasoningGroup";
|
|
55
|
+
export { Reasoning, ReasoningGroup, ReasoningRoot, ReasoningTrigger, ReasoningContent, ReasoningText, ReasoningFade, reasoningVariants, };
|
|
56
|
+
//# sourceMapp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AAM,cAAc,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC;AAChD,cAAc,CAAC,WAAW,GAAG,gBAAgB,CAAC;AAE9C,OAAO,EACL,SAAS,EACT,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,iBAAiB,GAClB,CAAC","sourcesContent":["\"use client\";\n\nimport { memo, useCallback, useRef } from \"react\";\nimport {\n useScrollLock,\n useAuiState,\n type ReasoningMessagePartComponent,\n type ReasoningGroupComponent,\n} from \"@assistant-ui/react\";\nimport { MarkdownText } from \"./markdown-text.js\";\nimport {\n ANIMATION_DURATION,\n ReasoningRoot as ReasoningRootBase,\n ReasoningTrigger,\n ReasoningContent,\n ReasoningText,\n ReasoningFade,\n reasoningVariants,\n type ReasoningRootProps,\n} from \"./reasoning.js\";\n\nexport type { ReasoningRootProps } from \"./reasoning.js\";\n\n/** `ReasoningRoot` with the thread viewport scroll locked during disclosure animations. */\nfunction ReasoningRoot({\n ref,\n onAnimationStart,\n ...props\n}: ReasoningRootProps) {\n const collapsibleRef = useRef<HTMLDivElement | null>(null);\n const lockScroll = useScrollLock(collapsibleRef, ANIMATION_DURATION);\n\n const handleAnimationStart = useCallback(() => {\n lockScroll();\n onAnimationStart?.();\n }, [lockScroll, onAnimationStart]);\n\n const composedRef = useCallback(\n (node: HTMLDivElement | null) => {\n collapsibleRef.current = node;\n if (typeof ref === \"function\") {\n ref(node);\n } else if (ref) {\n ref.current = node;\n }\n },\n [ref],\n );\n\n return (\n <ReasoningRootBase\n ref={composedRef}\n onAnimationStart={handleAnimationStart}\n {...props}\n />\n );\n}\n\nconst ReasoningImpl: ReasoningMessagePartComponent = () => <MarkdownText />;\n\nconst ReasoningGroupImpl: ReasoningGroupComponent = ({\n children,\n startIndex,\n endIndex,\n}) => {\n const isReasoningStreaming = useAuiState((s) => {\n if (s.message.status?.type !== \"running\") return false;\n for (let index = startIndex; index <= endIndex; index++) {\n if (s.message.parts[index]?.status.type === \"running\") return true;\n }\n return false;\n });\n\n return (\n <ReasoningRoot streaming={isReasoningStreaming}>\n <ReasoningTrigger active={isReasoningStreaming} />\n <ReasoningContent aria-busy={isReasoningStreaming}>\n <ReasoningText>{children}</ReasoningText>\n </ReasoningContent>\n </ReasoningRoot>\n );\n};\n\nconst Reasoning = memo(\n ReasoningImpl,\n) as unknown as ReasoningMessagePartComponent & {\n Root: typeof ReasoningRoot;\n Trigger: typeof ReasoningTrigger;\n Content: typeof ReasoningContent;\n Text: typeof ReasoningText;\n Fade: typeof ReasoningFade;\n};\n\nReasoning.displayName = \"Reasoning\";\nReasoning.Root = ReasoningRoot;\nReasoning.Trigger = ReasoningTrigger;\nReasoning.Content = ReasoningContent;\nReasoning.Text = ReasoningText;\nReasoning.Fade = ReasoningFade;\n\n/**\n * @deprecated This wrapper targets the legacy `components.ReasoningGroup`\n * prop on `<MessagePrimitive.Parts>`. Use `<MessagePrimitive.GroupedParts>`\n * with a `groupBy` returning `\"group-reasoning\"` and compose `ReasoningRoot`\n * / `ReasoningTrigger` / `ReasoningContent` / `ReasoningText` directly.\n * See `thread.aui.tsx` for an example.\n */\nconst ReasoningGroup = memo(ReasoningGroupImpl);\nReasoningGroup.displayName = \"ReasoningGroup\";\n\nexport {\n Reasoning,\n ReasoningGroup,\n ReasoningRoot,\n ReasoningTrigger,\n ReasoningContent,\n ReasoningText,\n ReasoningFade,\n reasoningVariants,\n};\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type VariantProps } from "class-variance-authority";
|
|
2
|
+
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "./collapsible.js";
|
|
3
|
+
export declare const ANIMATION_DURATION = 200;
|
|
4
|
+
declare const reasoningVariants: (props?: ({
|
|
5
|
+
variant?: "muted" | "outline" | "ghost" | null | undefined;
|
|
6
|
+
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
7
|
+
export type ReasoningRootProps = Omit<React.ComponentProps<typeof Collapsible>, "open" | "onOpenChange"> & VariantProps<typeof reasoningVariants> & {
|
|
8
|
+
open?: boolean;
|
|
9
|
+
onOpenChange?: (open: boolean) => void;
|
|
10
|
+
defaultOpen?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Whether the reasoning is currently streaming. While `true` the
|
|
13
|
+
* disclosure is held open with a bottom-pinned live preview; when
|
|
14
|
+
* streaming ends it returns to `defaultOpen`, and the first manual
|
|
15
|
+
* toggle takes over the open/close state permanently. The live preview
|
|
16
|
+
* keeps following the newest tokens while the disclosure is open during
|
|
17
|
+
* streaming, even after a manual toggle, and pauses while the reader is
|
|
18
|
+
* scrolled up.
|
|
19
|
+
*/
|
|
20
|
+
streaming?: boolean;
|
|
21
|
+
/** Called right before the disclosure animates, on toggle and on streaming transitions. */
|
|
22
|
+
onAnimationStart?: () => void;
|
|
23
|
+
};
|
|
24
|
+
declare const ReasoningRoot: import("react").ForwardRefExoticComponent<Omit<ReasoningRootProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
|
|
25
|
+
declare function ReasoningFade({ side, className, ...props }: React.ComponentProps<"div"> & {
|
|
26
|
+
side?: "top" | "bottom";
|
|
27
|
+
}): import("react").JSX.Element;
|
|
28
|
+
declare function ReasoningTrigger({ active, duration, className, ...props }: React.ComponentProps<typeof CollapsibleTrigger> & {
|
|
29
|
+
active?: boolean;
|
|
30
|
+
duration?: number;
|
|
31
|
+
}): import("react").JSX.Element;
|
|
32
|
+
declare function ReasoningContent({ className, children, ...props }: React.ComponentProps<typeof CollapsibleContent>): import("react").JSX.Element;
|
|
33
|
+
declare function ReasoningText({ className, children, ...props }: React.ComponentProps<"div">): import("react").JSX.Element;
|
|
34
|
+
export { ReasoningRoot, ReasoningTrigger, ReasoningContent, ReasoningText, ReasoningFade, reasoningVariants, };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef, createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState, } from "react";
|
|
4
|
+
import { cva } from "class-variance-authority";
|
|
5
|
+
import { BrainIcon, ChevronDownIcon } from "lucide-react";
|
|
6
|
+
import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "./collapsible.js";
|
|
7
|
+
import { cn } from "./utils.js";
|
|
8
|
+
export const ANIMATION_DURATION = 200;
|
|
9
|
+
const ReasoningPreviewContext = createContext(false);
|
|
10
|
+
const reasoningVariants = cva("aui-reasoning-root mb-4 w-full", {
|
|
11
|
+
variants: {
|
|
12
|
+
variant: {
|
|
13
|
+
outline: "rounded-lg border px-3 py-2",
|
|
14
|
+
ghost: "",
|
|
15
|
+
muted: "bg-muted/50 rounded-lg px-3 py-2",
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
defaultVariants: {
|
|
19
|
+
variant: "outline",
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
const ReasoningRoot = forwardRef(function ReasoningRoot({ className, variant, open: controlledOpen, onOpenChange: controlledOnOpenChange, defaultOpen = false, streaming, onAnimationStart, children, ...props }, ref) {
|
|
23
|
+
const [initialOpen] = useState(defaultOpen);
|
|
24
|
+
const [userOpen, setUserOpen] = useState(null);
|
|
25
|
+
const isControlled = controlledOpen !== undefined;
|
|
26
|
+
const isOpen = isControlled
|
|
27
|
+
? controlledOpen
|
|
28
|
+
: (userOpen ?? (streaming || initialOpen));
|
|
29
|
+
const isPreview = streaming === true && isOpen;
|
|
30
|
+
const prevStreamingRef = useRef(streaming);
|
|
31
|
+
useLayoutEffect(() => {
|
|
32
|
+
if (prevStreamingRef.current === streaming)
|
|
33
|
+
return;
|
|
34
|
+
prevStreamingRef.current = streaming;
|
|
35
|
+
// A streaming transition only animates the panel when the resting state
|
|
36
|
+
// is collapsed; with `defaultOpen` the disclosure stays open across it.
|
|
37
|
+
if (!isControlled && userOpen === null && !initialOpen) {
|
|
38
|
+
onAnimationStart?.();
|
|
39
|
+
}
|
|
40
|
+
}, [streaming, isControlled, userOpen, initialOpen, onAnimationStart]);
|
|
41
|
+
const handleOpenChange = useCallback((open) => {
|
|
42
|
+
onAnimationStart?.();
|
|
43
|
+
if (!isControlled) {
|
|
44
|
+
setUserOpen(open);
|
|
45
|
+
}
|
|
46
|
+
controlledOnOpenChange?.(open);
|
|
47
|
+
}, [onAnimationStart, isControlled, controlledOnOpenChange]);
|
|
48
|
+
return (_jsx(Collapsible, { "data-slot": "reasoning-root", "data-variant": variant, open: isOpen, onOpenChange: handleOpenChange, className: cn("group/reasoning-root", reasoningVariants({ variant, className })), style: {
|
|
49
|
+
"--nxf-animation-duration": `${ANIMATION_DURATION}ms`,
|
|
50
|
+
}, ref: ref, ...props, children: _jsx(ReasoningPreviewContext.Provider, { value: isPreview, children: children }) }));
|
|
51
|
+
});
|
|
52
|
+
function ReasoningFade({ side = "bottom", className, ...props }) {
|
|
53
|
+
if (side === "top") {
|
|
54
|
+
return (_jsx("div", { "data-slot": "reasoning-fade", className: cn("aui-reasoning-fade pointer-events-none absolute inset-x-0 top-0 z-10 h-8", "bg-[linear-gradient(to_bottom,var(--color-background),transparent)]", "group-data-[variant=muted]/reasoning-root:bg-[linear-gradient(to_bottom,color-mix(in_oklab,var(--color-muted)_50%,var(--color-background)),transparent)]", "fade-in-0 animate-in", "animation-duration-(--animation-duration)", className), ...props }));
|
|
55
|
+
}
|
|
56
|
+
return (_jsx("div", { "data-slot": "reasoning-fade", className: cn("aui-reasoning-fade pointer-events-none absolute inset-x-0 bottom-0 z-10 h-8", "bg-[linear-gradient(to_top,var(--color-background),transparent)]", "group-data-[variant=muted]/reasoning-root:bg-[linear-gradient(to_top,color-mix(in_oklab,var(--color-muted)_50%,var(--color-background)),transparent)]", "fade-in-0 animate-in", "animation-duration-(--animation-duration)", className), ...props }));
|
|
57
|
+
}
|
|
58
|
+
function ReasoningTrigger({ active, duration, className, ...props }) {
|
|
59
|
+
const durationText = duration ? ` (${duration}s)` : "";
|
|
60
|
+
return (_jsxs(CollapsibleTrigger, { "data-slot": "reasoning-trigger", className: cn("aui-reasoning-trigger group/trigger text-muted-foreground hover:text-foreground flex max-w-[75%] origin-left items-center gap-2 py-1.5 text-sm transition-[color,scale] active:scale-[0.98]", className), ...props, children: [_jsx(BrainIcon, { "data-slot": "reasoning-trigger-icon", className: cn("aui-reasoning-trigger-icon size-4 shrink-0") }), _jsxs("span", { "data-slot": "reasoning-trigger-label", className: cn("aui-reasoning-trigger-label-wrapper inline-block leading-none tabular-nums", active && "shimmer motion-reduce:animate-none"), children: ["Reasoning", durationText] }), _jsx(ChevronDownIcon, { "data-slot": "reasoning-trigger-chevron", className: cn("aui-reasoning-trigger-chevron mt-0.5 size-4 shrink-0", "transition-transform duration-(--animation-duration) ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:transition-none", "-rotate-90", "group-data-open/trigger:rotate-0", "group-data-panel-open/trigger:rotate-0") })] }));
|
|
61
|
+
}
|
|
62
|
+
function ReasoningContent({ className, children, ...props }) {
|
|
63
|
+
const isPreview = useContext(ReasoningPreviewContext);
|
|
64
|
+
return (_jsxs(CollapsibleContent, { "data-slot": "reasoning-content", className: cn("aui-reasoning-content text-muted-foreground relative overflow-hidden text-sm outline-none", "group/collapsible-content ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:animate-none", "data-closed:animate-collapsible-up", "data-open:animate-collapsible-down", "data-closed:fill-mode-forwards", "data-closed:pointer-events-none", "[--tw-duration:var(--animation-duration)]", className), ...props, children: [_jsx(ReasoningFade, { side: "top" }), children, isPreview ? _jsx(ReasoningFade, {}) : null] }));
|
|
65
|
+
}
|
|
66
|
+
function ReasoningText({ className, children, ...props }) {
|
|
67
|
+
const isPreview = useContext(ReasoningPreviewContext);
|
|
68
|
+
const scrollRef = useRef(null);
|
|
69
|
+
const contentRef = useRef(null);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (!isPreview)
|
|
72
|
+
return;
|
|
73
|
+
const scrollEl = scrollRef.current;
|
|
74
|
+
const contentEl = contentRef.current;
|
|
75
|
+
if (!scrollEl || !contentEl)
|
|
76
|
+
return;
|
|
77
|
+
let pinned = true;
|
|
78
|
+
let lastScrollTop = scrollEl.scrollTop;
|
|
79
|
+
let lastScrollHeight = scrollEl.scrollHeight;
|
|
80
|
+
const isAtBottom = () => Math.abs(scrollEl.scrollHeight - scrollEl.scrollTop - scrollEl.clientHeight) <= 1 || scrollEl.scrollHeight <= scrollEl.clientHeight;
|
|
81
|
+
const pin = () => {
|
|
82
|
+
if (!pinned)
|
|
83
|
+
return;
|
|
84
|
+
scrollEl.scrollTop = scrollEl.scrollHeight;
|
|
85
|
+
};
|
|
86
|
+
// A pin's own scroll event can arrive after new content grew the scroll
|
|
87
|
+
// height and read as "not at bottom"; only an upward move at unchanged
|
|
88
|
+
// scroll height is user intent.
|
|
89
|
+
const onScroll = () => {
|
|
90
|
+
if (isAtBottom()) {
|
|
91
|
+
pinned = true;
|
|
92
|
+
}
|
|
93
|
+
else if (scrollEl.scrollTop < lastScrollTop &&
|
|
94
|
+
scrollEl.scrollHeight === lastScrollHeight) {
|
|
95
|
+
pinned = false;
|
|
96
|
+
}
|
|
97
|
+
lastScrollTop = scrollEl.scrollTop;
|
|
98
|
+
lastScrollHeight = scrollEl.scrollHeight;
|
|
99
|
+
};
|
|
100
|
+
pin();
|
|
101
|
+
scrollEl.addEventListener("scroll", onScroll);
|
|
102
|
+
const observer = new ResizeObserver(pin);
|
|
103
|
+
observer.observe(contentEl);
|
|
104
|
+
return () => {
|
|
105
|
+
scrollEl.removeEventListener("scroll", onScroll);
|
|
106
|
+
observer.disconnect();
|
|
107
|
+
};
|
|
108
|
+
}, [isPreview]);
|
|
109
|
+
return (_jsx("div", { ref: scrollRef, "data-slot": "reasoning-text", className: cn("aui-reasoning-text relative z-0 max-h-64 overflow-y-auto ps-6 pt-2 pb-2 leading-relaxed text-pretty", "transform-gpu transition-[transform,opacity] ease-[cubic-bezier(0.32,0.72,0,1)]", "motion-reduce:animate-none", "group-data-open/collapsible-content:animate-in", "group-data-closed/collapsible-content:animate-out", "group-data-open/collapsible-content:fade-in-0", "group-data-closed/collapsible-content:fade-out-0", "group-data-open/collapsible-content:slide-in-from-top-4", "group-data-closed/collapsible-content:slide-out-to-top-4", "group-data-open/collapsible-content:blur-in-[2px]", "group-data-closed/collapsible-content:blur-out-[2px]", "group-data-open/collapsible-content:animation-duration-(--animation-duration)", "group-data-closed/collapsible-content:animation-duration-(--animation-duration)", className), ...props, children: _jsx("div", { ref: contentRef, className: cn("aui-reasoning-text-content space-y-4"), children: children }) }));
|
|
110
|
+
}
|
|
111
|
+
export { ReasoningRoot, ReasoningTrigger, ReasoningContent, ReasoningText, ReasoningFade, reasoningVariants, };
|
|
112
|
+
//# sourceMappingURL=reasoning.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reasoning.js","sourceRoot":"","sources":["../../src/ui/reasoning.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EACL,UAAU,EACV,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,eAAe,EACf,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,GAAG,EAAqB,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAEhC,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAEtC,MAAM,uBAAuB,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;AAErD,MAAM,iBAAiB,GAAG,GAAG,CAAC,gCAAgC,EAAE;IAC9D,QAAQ,EAAE;QACR,OAAO,EAAE;YACP,OAAO,EAAE,6BAA6B;YACtC,KAAK,EAAE,EAAE;YACT,KAAK,EAAE,kCAAkC;SAC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Q,EAAE,QAAQ,CAAC,CAAC;QAC9C,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,GAAG,CAAC,CAAC;QACzC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC5B,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YACjD,QAAQ,CAAC,UAAU,EAAE,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,CACL,cACE,GAAG,EAAE,SAAS,eACJ,gBAAgB,EAC1B,SAAS,EAAE,EAAE,CACX,qGAAqG,EACrG,iFAAiF,EACjF,4BAA4B,EAC5B,gDAAgD,EAChD,mDAAmD,EACnD,+CAA+C,EAC/C,kDAAkD,EAClD,yDAAyD,EACzD,0DAA0D,EAC1D,mDAAmD,EACnD,sDAAsD,EACtD,+EAA+E,EAC/E,iFAAiF,EACjF,SAAS,CACV,KACG,KAAK,YAET,cAAK,GAAG,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,CAAC,sCAAsC,CAAC,YACxE,QAAQ,GACL,GACF,CACP,CAAC;AACJ,CAAC;AAED,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,iBAAiB,GAClB,CAAC","sourcesContent":["\"use client\";\n\nimport {\n forwardRef,\n createContext,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useRef,\n useState,\n} from \"react\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport { BrainIcon, ChevronDownIcon } from \"lucide-react\";\nimport {\n Collapsible,\n CollapsibleContent,\n CollapsibleTrigger,\n} from \"./collapsible.js\";\nimport { cn } from \"./utils.js\";\n\nexport const ANIMATION_DURATION = 200;\n\nconst ReasoningPreviewContext = createContext(false);\n\nconst reasoningVariants = cva(\"aui-reasoning-root mb-4 w-full\", {\n variants: {\n variant: {\n outline: \"rounded-lg border px-3 py-2\",\n ghost: \"\",\n muted: \"bg-muted/50 rounded-lg px-3 py-2\",\n },\n },\n defaultVariants: {\n variant: \"outline\",\n },\n});\n\nexport type ReasoningRootProps = Omit<\n React.ComponentProps<typeof Collapsible>,\n \"open\" | \"onOpenChange\"\n> &\n VariantProps<typeof reasoningVariants> & {\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n defaultOpen?: boolean;\n /**\n * Whether the reasoning is currently streaming. While `true` the\n * disclosure is held open with a bottom-pinned live preview; when\n * streaming ends it returns to `defaultOpen`, and the first manual\n * toggle takes over the open/close state permanently. The live preview\n * keeps following the newest tokens while the disclosure is open during\n * streaming, even after a manual toggle, and pauses while the reader is\n * scrolled up.\n */\n streaming?: boolean;\n /** Called right before the disclosure animates, on toggle and on streaming transitions. */\n onAnimationStart?: () => void;\n };\n\nconst ReasoningRoot = forwardRef<HTMLDivElement, ReasoningRootProps>(function ReasoningRoot({\n className,\n variant,\n open: controlledOpen,\n onOpenChange: controlledOnOpenChange,\n defaultOpen = false,\n streaming,\n onAnimationStart,\n children,\n ...props\n}: ReasoningRootProps, ref) {\n const [initialOpen] = useState(defaultOpen);\n const [userOpen, setUserOpen] = useState<boolean | null>(null);\n\n const isControlled = controlledOpen !== undefined;\n const isOpen = isControlled\n ? controlledOpen\n : (userOpen ?? (streaming || initialOpen));\n const isPreview = streaming === true && isOpen;\n\n const prevStreamingRef = useRef(streaming);\n useLayoutEffect(() => {\n if (prevStreamingRef.current === streaming) return;\n prevStreamingRef.current = streaming;\n // A streaming transition only animates the panel when the resting state\n // is collapsed; with `defaultOpen` the disclosure stays open across it.\n if (!isControlled && userOpen === null && !initialOpen) {\n onAnimationStart?.();\n }\n }, [streaming, isControlled, userOpen, initialOpen, onAnimationStart]);\n\n const handleOpenChange = useCallback(\n (open: boolean) => {\n onAnimationStart?.();\n if (!isControlled) {\n setUserOpen(open);\n }\n controlledOnOpenChange?.(open);\n },\n [onAnimationStart, isControlled, controlledOnOpenChange],\n );\n\n return (\n <Collapsible\n data-slot=\"reasoning-root\"\n data-variant={variant}\n open={isOpen}\n onOpenChange={handleOpenChange}\n className={cn(\n \"group/reasoning-root\",\n reasoningVariants({ variant, className }),\n )}\n style={\n {\n \"--nxf-animation-duration\": `${ANIMATION_DURATION}ms`,\n } as React.CSSProperties\n }\n ref={ref}\n {...props}\n >\n <ReasoningPreviewContext.Provider value={isPreview}>\n {children}\n </ReasoningPreviewContext.Provider>\n </Collapsible>\n );\n});\n\nfunction ReasoningFade({\n side = \"bottom\",\n className,\n ...props\n}: React.ComponentProps<\"div\"> & { side?: \"top\" | \"bottom\" }) {\n if (side === \"top\") {\n return (\n <div\n data-slot=\"reasoning-fade\"\n className={cn(\n \"aui-reasoning-fade pointer-events-none absolute inset-x-0 top-0 z-10 h-8\",\n \"bg-[linear-gradient(to_bottom,var(--color-background),transparent)]\",\n \"group-data-[variant=muted]/reasoning-root:bg-[linear-gradient(to_bottom,color-mix(in_oklab,var(--color-muted)_50%,var(--color-background)),transparent)]\",\n \"fade-in-0 animate-in\",\n \"animation-duration-(--animation-duration)\",\n className,\n )}\n {...props}\n />\n );\n }\n\n return (\n <div\n data-slot=\"reasoning-fade\"\n className={cn(\n \"aui-reasoning-fade pointer-events-none absolute inset-x-0 bottom-0 z-10 h-8\",\n \"bg-[linear-gradient(to_top,var(--color-background),transparent)]\",\n \"group-data-[variant=muted]/reasoning-root:bg-[linear-gradient(to_top,color-mix(in_oklab,var(--color-muted)_50%,var(--color-background)),transparent)]\",\n \"fade-in-0 animate-in\",\n \"animation-duration-(--animation-duration)\",\n className,\n )}\n {...props}\n />\n );\n}\n\nfunction ReasoningTrigger({\n active,\n duration,\n className,\n ...props\n}: React.ComponentProps<typeof CollapsibleTrigger> & {\n active?: boolean;\n duration?: number;\n}) {\n const durationText = duration ? ` (${duration}s)` : \"\";\n\n return (\n <CollapsibleTrigger\n data-slot=\"reasoning-trigger\"\n className={cn(\n \"aui-reasoning-trigger group/trigger text-muted-foreground hover:text-foreground flex max-w-[75%] origin-left items-center gap-2 py-1.5 text-sm transition-[color,scale] active:scale-[0.98]\",\n className,\n )}\n {...props}\n >\n <BrainIcon\n data-slot=\"reasoning-trigger-icon\"\n className={cn(\"aui-reasoning-trigger-icon size-4 shrink-0\")}\n />\n <span\n data-slot=\"reasoning-trigger-label\"\n className={cn(\n \"aui-reasoning-trigger-label-wrapper inline-block leading-none tabular-nums\",\n active && \"shimmer motion-reduce:animate-none\",\n )}\n >\n Reasoning{durationText}\n </span>\n <ChevronDownIcon\n data-slot=\"reasoning-trigger-chevron\"\n className={cn(\n \"aui-reasoning-trigger-chevron mt-0.5 size-4 shrink-0\",\n \"transition-transform duration-(--animation-duration) ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:transition-none\",\n \"-rotate-90\",\n \"group-data-open/trigger:rotate-0\",\n \"group-data-panel-open/trigger:rotate-0\",\n )}\n />\n </CollapsibleTrigger>\n );\n}\n\nfunction ReasoningContent({\n className,\n children,\n ...props\n}: React.ComponentProps<typeof CollapsibleContent>) {\n const isPreview = useContext(ReasoningPreviewContext);\n\n return (\n <CollapsibleContent\n data-slot=\"reasoning-content\"\n className={cn(\n \"aui-reasoning-content text-muted-foreground relative overflow-hidden text-sm outline-none\",\n \"group/collapsible-content ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:animate-none\",\n \"data-closed:animate-collapsible-up\",\n \"data-open:animate-collapsible-down\",\n \"data-closed:fill-mode-forwards\",\n \"data-closed:pointer-events-none\",\n \"[--tw-duration:var(--animation-duration)]\",\n className,\n )}\n {...props}\n >\n <ReasoningFade side=\"top\" />\n {children}\n {isPreview ? <ReasoningFade /> : null}\n </CollapsibleContent>\n );\n}\n\nfunction ReasoningText({\n className,\n children,\n ...props\n}: React.ComponentProps<\"div\">) {\n const isPreview = useContext(ReasoningPreviewContext);\n const scrollRef = useRef<HTMLDivElement>(null);\n const contentRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n if (!isPreview) return;\n const scrollEl = scrollRef.current;\n const contentEl = contentRef.current;\n if (!scrollEl || !contentEl) return;\n\n let pinned = true;\n let lastScrollTop = scrollEl.scrollTop;\n let lastScrollHeight = scrollEl.scrollHeight;\n const isAtBottom = () =>\n Math.abs(\n scrollEl.scrollHeight - scrollEl.scrollTop - scrollEl.clientHeight,\n ) <= 1 || scrollEl.scrollHeight <= scrollEl.clientHeight;\n\n const pin = () => {\n if (!pinned) return;\n scrollEl.scrollTop = scrollEl.scrollHeight;\n };\n // A pin's own scroll event can arrive after new content grew the scroll\n // height and read as \"not at bottom\"; only an upward move at unchanged\n // scroll height is user intent.\n const onScroll = () => {\n if (isAtBottom()) {\n pinned = true;\n } else if (\n scrollEl.scrollTop < lastScrollTop &&\n scrollEl.scrollHeight === lastScrollHeight\n ) {\n pinned = false;\n }\n lastScrollTop = scrollEl.scrollTop;\n lastScrollHeight = scrollEl.scrollHeight;\n };\n\n pin();\n scrollEl.addEventListener(\"scroll\", onScroll);\n const observer = new ResizeObserver(pin);\n observer.observe(contentEl);\n return () => {\n scrollEl.removeEventListener(\"scroll\", onScroll);\n observer.disconnect();\n };\n }, [isPreview]);\n\n return (\n <div\n ref={scrollRef}\n data-slot=\"reasoning-text\"\n className={cn(\n \"aui-reasoning-text relative z-0 max-h-64 overflow-y-auto ps-6 pt-2 pb-2 leading-relaxed text-pretty\",\n \"transform-gpu transition-[transform,opacity] ease-[cubic-bezier(0.32,0.72,0,1)]\",\n \"motion-reduce:animate-none\",\n \"group-data-open/collapsible-content:animate-in\",\n \"group-data-closed/collapsible-content:animate-out\",\n \"group-data-open/collapsible-content:fade-in-0\",\n \"group-data-closed/collapsible-content:fade-out-0\",\n \"group-data-open/collapsible-content:slide-in-from-top-4\",\n \"group-data-closed/collapsible-content:slide-out-to-top-4\",\n \"group-data-open/collapsible-content:blur-in-[2px]\",\n \"group-data-closed/collapsible-content:blur-out-[2px]\",\n \"group-data-open/collapsible-content:animation-duration-(--animation-duration)\",\n \"group-data-closed/collapsible-content:animation-duration-(--animation-duration)\",\n className,\n )}\n {...props}\n >\n <div ref={contentRef} className={cn(\"aui-reasoning-text-content space-y-4\")}>\n {children}\n </div>\n </div>\n );\n}\n\nexport {\n ReasoningRoot,\n ReasoningTrigger,\n ReasoningContent,\n ReasoningText,\n ReasoningFade,\n reasoningVariants,\n};\n"]}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ComponentProps, type ReactNode } from "react";
|
|
2
2
|
import { ThreadListPrimitive } from "@assistant-ui/react";
|
|
3
|
-
import { Button } from "./button.js";
|
|
4
3
|
export declare function ThreadListRoot({ className, ...props }: ComponentProps<typeof ThreadListPrimitive.Root>): import("react").JSX.Element;
|
|
5
|
-
export declare function ThreadListNew(props: ComponentProps<
|
|
4
|
+
export declare function ThreadListNew(props: ComponentProps<"button">): import("react").JSX.Element;
|
|
5
|
+
export declare function ThreadListSearch({ value, onValueChange }: {
|
|
6
|
+
value: string;
|
|
7
|
+
onValueChange(value: string): void;
|
|
8
|
+
}): import("react").JSX.Element;
|
|
6
9
|
export declare function ThreadListItem({ disabled, menu }: {
|
|
7
10
|
disabled: boolean;
|
|
8
|
-
menu: ReactNode;
|
|
11
|
+
menu: (beginRename: () => void) => ReactNode;
|
|
9
12
|
}): import("react").JSX.Element;
|