@nexface/chat 0.1.14 → 0.1.15-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 +17 -60
- package/dist/assistant-attachments.js.map +1 -0
- package/dist/assistant-components.d.ts +3 -3
- package/dist/assistant-components.js +29 -77
- package/dist/assistant-components.js.map +1 -0
- package/dist/assistant-runtime.d.ts +1 -1
- package/dist/assistant-runtime.js +43 -100
- package/dist/assistant-runtime.js.map +1 -0
- package/dist/attachments.js +15 -36
- package/dist/attachments.js.map +1 -0
- package/dist/client.js +73 -312
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +1 -1
- package/dist/config.js +5 -4
- package/dist/config.js.map +1 -0
- package/dist/default-chat.d.ts +1 -1
- package/dist/default-chat.js +728 -2102
- package/dist/default-chat.js.map +7 -0
- package/dist/errors.js +18 -55
- package/dist/errors.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/messages.js +1 -0
- package/dist/messages.js.map +1 -0
- package/dist/page-confirmation.js +4 -3
- package/dist/page-confirmation.js.map +1 -0
- package/dist/protocol-messages.js +66 -290
- package/dist/protocol-messages.js.map +1 -0
- package/dist/protocol-response.js +18 -38
- package/dist/protocol-response.js.map +1 -0
- package/dist/react.js +50 -146
- package/dist/react.js.map +1 -0
- package/dist/shared/errors.d.ts +1 -1
- package/dist/shared/errors.js +1 -0
- package/dist/shared/errors.js.map +1 -0
- package/dist/shared/runtime-controller.d.ts +0 -1
- package/dist/shared/runtime-controller.js +1 -0
- package/dist/shared/runtime-controller.js.map +1 -0
- package/dist/shared/runtime-execution.js +1 -0
- package/dist/shared/runtime-execution.js.map +1 -0
- package/dist/shared/schema.js +19 -45
- package/dist/shared/schema.js.map +1 -0
- package/dist/storage.js +53 -130
- package/dist/storage.js.map +1 -0
- package/dist/styles.css +20 -99
- package/dist/tool-result.js +3 -7
- package/dist/tool-result.js.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/attachment.aui.d.ts +1 -1
- package/dist/ui/attachment.aui.js +20 -16
- package/dist/ui/attachment.aui.js.map +1 -0
- package/dist/ui/avatar.js +1 -0
- package/dist/ui/avatar.js.map +1 -0
- package/dist/ui/button.js +1 -0
- package/dist/ui/button.js.map +1 -0
- package/dist/ui/code-block.js +3 -2
- package/dist/ui/code-block.js.map +1 -0
- package/dist/ui/collapsible.js +3 -2
- package/dist/ui/collapsible.js.map +1 -0
- package/dist/ui/composer-voice.js +2 -3
- package/dist/ui/composer-voice.js.map +1 -0
- package/dist/ui/dialog.d.ts +1 -1
- package/dist/ui/dialog.js +4 -9
- package/dist/ui/dialog.js.map +1 -0
- package/dist/ui/dropdown-menu.js +3 -2
- package/dist/ui/dropdown-menu.js.map +1 -0
- package/dist/ui/home-demo/action-bar.js +1 -0
- package/dist/ui/home-demo/action-bar.js.map +1 -0
- package/dist/ui/home-demo/composer.js +4 -7
- package/dist/ui/home-demo/composer.js.map +1 -0
- package/dist/ui/home-demo/greeting.d.ts +1 -1
- package/dist/ui/home-demo/greeting.js +2 -1
- package/dist/ui/home-demo/greeting.js.map +1 -0
- package/dist/ui/home-demo/messages.d.ts +1 -1
- package/dist/ui/home-demo/messages.js +5 -4
- package/dist/ui/home-demo/messages.js.map +1 -0
- package/dist/ui/home-demo/styles.js +1 -0
- package/dist/ui/home-demo/styles.js.map +1 -0
- package/dist/ui/home-demo/suggestions.d.ts +1 -1
- package/dist/ui/home-demo/suggestions.js +3 -5
- package/dist/ui/home-demo/suggestions.js.map +1 -0
- package/dist/ui/home-demo/surfaces.js +2 -3
- package/dist/ui/home-demo/surfaces.js.map +1 -0
- package/dist/ui/home-demo/thread.d.ts +1 -1
- package/dist/ui/home-demo/thread.js +2 -1
- package/dist/ui/home-demo/thread.js.map +1 -0
- package/dist/ui/home-demo/trace-line.d.ts +1 -1
- package/dist/ui/home-demo/trace-line.js +3 -2
- package/dist/ui/home-demo/trace-line.js.map +1 -0
- package/dist/ui/home-demo/trace.d.ts +1 -1
- package/dist/ui/home-demo/trace.js +9 -28
- package/dist/ui/home-demo/trace.js.map +1 -0
- package/dist/ui/home-demo/type.js +1 -0
- package/dist/ui/home-demo/type.js.map +1 -0
- package/dist/ui/input.js +1 -0
- package/dist/ui/input.js.map +1 -0
- package/dist/ui/markdown-text.js +3 -2
- package/dist/ui/markdown-text.js.map +1 -0
- package/dist/ui/reasoning.aui.js +3 -2
- package/dist/ui/reasoning.aui.js.map +1 -0
- package/dist/ui/reasoning.d.ts +1 -1
- package/dist/ui/reasoning.js +9 -6
- package/dist/ui/reasoning.js.map +1 -0
- package/dist/ui/surface.js +8 -27
- package/dist/ui/surface.js.map +1 -0
- package/dist/ui/thread-list.aui.d.ts +2 -2
- package/dist/ui/thread-list.aui.js +12 -18
- package/dist/ui/thread-list.aui.js.map +1 -0
- package/dist/ui/tool-group.aui.js +3 -2
- package/dist/ui/tool-group.aui.js.map +1 -0
- package/dist/ui/tooltip-icon-button.js +2 -1
- package/dist/ui/tooltip-icon-button.js.map +1 -0
- package/dist/ui/tooltip.js +1 -0
- package/dist/ui/tooltip.js.map +1 -0
- package/dist/ui/use-attachment-src.js +2 -1
- package/dist/ui/use-attachment-src.js.map +1 -0
- package/dist/ui/use-copy-to-clipboard.d.ts +1 -1
- package/dist/ui/use-copy-to-clipboard.js +2 -1
- package/dist/ui/use-copy-to-clipboard.js.map +1 -0
- package/dist/ui/utils.js +3 -9
- package/dist/ui/utils.js.map +1 -0
- package/dist/use-next-message.js +4 -7
- package/dist/use-next-message.js.map +1 -0
- package/dist/voice/types.js +1 -0
- package/dist/voice/types.js.map +1 -0
- package/dist/voice/use-voice.js +13 -35
- package/dist/voice/use-voice.js.map +1 -0
- package/package.json +4 -8
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
// Official ThreadList composition; Nexface owns the management actions and confirmations.
|
|
4
4
|
import { useEffect, useRef, useState } from "react";
|
|
5
|
-
import { ThreadListItemPrimitive, ThreadListPrimitive, useAui, useAuiState
|
|
5
|
+
import { ThreadListItemPrimitive, ThreadListPrimitive, useAui, useAuiState } from "@assistant-ui/react";
|
|
6
6
|
import { Loader2Icon, MoreHorizontalIcon, PlusIcon, SearchIcon } from "lucide-react";
|
|
7
7
|
import { Input } from "./input.js";
|
|
8
8
|
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent } from "./dropdown-menu.js";
|
|
9
9
|
import { cn } from "./utils.js";
|
|
10
10
|
export function ThreadListRoot({ className, ...props }) {
|
|
11
|
-
return
|
|
11
|
+
return _jsx(ThreadListPrimitive.Root, { "data-slot": "aui_thread-list-root", className: cn("flex flex-col gap-0.5", className), ...props });
|
|
12
12
|
}
|
|
13
13
|
export function ThreadListNew(props) {
|
|
14
|
-
return
|
|
14
|
+
return _jsx(ThreadListPrimitive.New, { asChild: true, children: _jsxs("button", { type: "button", "data-slot": "aui_thread-list-new", className: cn("border-foreground/10 bg-background hover:border-foreground/25 rounded-control flex h-8 w-full shrink-0 items-center gap-2 border px-2.5 text-[13px] transition-colors"), ...props, children: [_jsx(PlusIcon, { className: cn("size-4 shrink-0") }), "\u65B0\u5EFA\u4F1A\u8BDD"] }) });
|
|
15
15
|
}
|
|
16
|
-
export function ThreadListSearch({ value, onValueChange
|
|
17
|
-
return
|
|
16
|
+
export function ThreadListSearch({ value, onValueChange }) {
|
|
17
|
+
return _jsxs("div", { "data-slot": "aui_thread-list-search", className: cn("relative px-0.5 py-1"), children: [_jsx(SearchIcon, { "data-slot": "aui_thread-list-search-icon", className: cn("text-muted-foreground pointer-events-none absolute start-3 top-1/2 size-4 -translate-y-1/2") }), _jsx(Input, { type: "search", value: value, onChange: (event) => onValueChange(event.target.value), "aria-label": "\u641C\u7D22\u4F1A\u8BDD", placeholder: "\u641C\u7D22\u4F1A\u8BDD", className: cn("border-foreground/10 bg-background h-8 ps-8 text-[13px] md:text-[13px]") })] });
|
|
18
18
|
}
|
|
19
|
-
export function ThreadListItem({ disabled, menu
|
|
19
|
+
export function ThreadListItem({ disabled, menu }) {
|
|
20
20
|
const isRunning = useAuiState((s) => s.threadListItem.isRunning);
|
|
21
21
|
const title = useAuiState((s) => s.threadListItem.title);
|
|
22
22
|
const [isRenaming, setIsRenaming] = useState(false);
|
|
@@ -28,10 +28,7 @@ export function ThreadListItem({ disabled, menu, }) {
|
|
|
28
28
|
triggerRef.current?.focus();
|
|
29
29
|
}
|
|
30
30
|
}, [isRenaming]);
|
|
31
|
-
return
|
|
32
|
-
restoreFocus.current = focus;
|
|
33
|
-
setIsRenaming(false);
|
|
34
|
-
} })) : (_jsxs(ThreadListItemPrimitive.Trigger, { ref: triggerRef, disabled: disabled, "data-slot": "aui_thread-list-item-trigger", className: cn("text-muted-foreground group-data-active:text-foreground hover:text-foreground flex h-full min-w-0 flex-1 items-center px-2 text-left text-[13px] transition-colors outline-none group-hover:pe-8 group-has-focus-visible:pe-8 group-has-data-[state=open]:pe-8 group-data-active:pe-8"), children: [isRunning && (_jsx(Loader2Icon, { "aria-hidden": true, className: cn("text-muted-foreground me-1.5 size-3.5 shrink-0 animate-spin") })), _jsx("span", { className: cn("min-w-0 flex-1 truncate"), children: _jsx(ThreadListItemPrimitive.Title, { fallback: "\u65B0\u4F1A\u8BDD" }) })] })), _jsxs(DropdownMenu, { modal: false, children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx("button", { type: "button", "aria-label": `管理 ${title}`, className: cn("text-muted-foreground hover:text-foreground absolute end-1 top-1/2 grid size-6 -translate-y-1/2 place-items-center rounded-sm opacity-0 transition-colors group-hover:opacity-100 group-has-focus-visible:opacity-100 group-data-active:opacity-100 focus-visible:opacity-100 data-[state=open]:opacity-100"), children: _jsx(MoreHorizontalIcon, { className: cn("size-3.5") }) }) }), _jsx(DropdownMenuContent, { side: "right", align: "start", sideOffset: 6, children: menu(() => setIsRenaming(true)) })] })] }));
|
|
31
|
+
return _jsxs(ThreadListItemPrimitive.Root, { "data-slot": "aui_thread-list-item", className: cn("group data-active:bg-foreground/[0.06] hover:bg-foreground/[0.04] has-data-[state=open]:bg-foreground/[0.04] rounded-control relative flex h-8 shrink-0 items-center transition-colors"), children: [isRenaming ? _jsx(ThreadListItemRename, { onDone: (focus) => { restoreFocus.current = focus; setIsRenaming(false); } }) : _jsxs(ThreadListItemPrimitive.Trigger, { ref: triggerRef, disabled: disabled, "data-slot": "aui_thread-list-item-trigger", className: cn("text-muted-foreground group-data-active:text-foreground hover:text-foreground flex h-full min-w-0 flex-1 items-center px-2 text-left text-[13px] transition-colors outline-none group-hover:pe-8 group-has-focus-visible:pe-8 group-has-data-[state=open]:pe-8 group-data-active:pe-8"), children: [isRunning && _jsx(Loader2Icon, { "aria-hidden": true, className: cn("text-muted-foreground me-1.5 size-3.5 shrink-0 animate-spin") }), _jsx("span", { className: cn("min-w-0 flex-1 truncate"), children: _jsx(ThreadListItemPrimitive.Title, { fallback: "\u65B0\u4F1A\u8BDD" }) })] }), _jsxs(DropdownMenu, { modal: false, children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx("button", { type: "button", "aria-label": `管理 ${title}`, className: cn("text-muted-foreground hover:text-foreground absolute end-1 top-1/2 grid size-6 -translate-y-1/2 place-items-center rounded-sm opacity-0 transition-colors group-hover:opacity-100 group-has-focus-visible:opacity-100 group-data-active:opacity-100 focus-visible:opacity-100 data-[state=open]:opacity-100"), children: _jsx(MoreHorizontalIcon, { className: cn("size-3.5") }) }) }), _jsx(DropdownMenuContent, { side: "right", align: "start", sideOffset: 6, children: menu(() => setIsRenaming(true)) })] })] });
|
|
35
32
|
}
|
|
36
33
|
function ThreadListItemRename({ onDone }) {
|
|
37
34
|
const aui = useAui();
|
|
@@ -39,9 +36,7 @@ function ThreadListItemRename({ onDone }) {
|
|
|
39
36
|
const [value, setValue] = useState(title);
|
|
40
37
|
const inputRef = useRef(null);
|
|
41
38
|
const settled = useRef(false);
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
inputRef.current?.select();
|
|
44
|
-
}, []);
|
|
39
|
+
useEffect(() => { inputRef.current?.select(); }, []);
|
|
45
40
|
const commit = (focus) => {
|
|
46
41
|
if (settled.current)
|
|
47
42
|
return;
|
|
@@ -51,15 +46,13 @@ function ThreadListItemRename({ onDone }) {
|
|
|
51
46
|
onDone(focus);
|
|
52
47
|
return;
|
|
53
48
|
}
|
|
54
|
-
void Promise.resolve()
|
|
55
|
-
.then(() => aui.threadListItem.rename(next))
|
|
56
|
-
.then(() => onDone(focus), () => {
|
|
49
|
+
void Promise.resolve().then(() => aui.threadListItem.rename(next)).then(() => onDone(focus), () => {
|
|
57
50
|
settled.current = false;
|
|
58
51
|
if (focus)
|
|
59
52
|
inputRef.current?.focus();
|
|
60
53
|
});
|
|
61
54
|
};
|
|
62
|
-
return
|
|
55
|
+
return _jsx(Input, { ref: inputRef, autoFocus: true, "data-slot": "aui_thread-list-item-rename", "aria-label": "\u4F1A\u8BDD\u540D\u79F0", maxLength: 80, value: value, className: cn("h-7 min-w-0 flex-1 ps-2 pe-8 text-[13px] md:text-[13px]"), onChange: (event) => setValue(event.target.value), onBlur: () => commit(false), onKeyDown: (event) => {
|
|
63
56
|
if (event.nativeEvent.isComposing || event.keyCode === 229)
|
|
64
57
|
return;
|
|
65
58
|
if (event.key === "Enter") {
|
|
@@ -71,5 +64,6 @@ function ThreadListItemRename({ onDone }) {
|
|
|
71
64
|
settled.current = true;
|
|
72
65
|
onDone(true);
|
|
73
66
|
}
|
|
74
|
-
} })
|
|
67
|
+
} });
|
|
75
68
|
}
|
|
69
|
+
//# sourceMappingURL=thread-list.aui.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thread-list.aui.js","sourceRoot":"","sources":["../../src/ui/thread-list.aui.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,0FAA0F;AAC1F,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAuC,MAAM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AAE,CAAC;gBAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAAC,CAAC;iBAC/D,IAAI,KAAK,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;gBAAC,KAAK,CAAC,cAAc,EAAE,CAAC;gBAAC,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;gBAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAAC,CAAC;QACpG,CAAC,GAAI,CAAC;AACV,CAAC","sourcesContent":["\"use client\";\n// Official ThreadList composition; Nexface owns the management actions and confirmations.\nimport { useEffect, useRef, useState, type ComponentProps, type ReactNode } from \"react\";\nimport { ThreadListItemPrimitive, ThreadListPrimitive, useAui, useAuiState } from \"@assistant-ui/react\";\nimport { Loader2Icon, MoreHorizontalIcon, PlusIcon, SearchIcon } from \"lucide-react\";\nimport { Input } from \"./input.js\";\nimport { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent } from \"./dropdown-menu.js\";\nimport { cn } from \"./utils.js\";\nexport function ThreadListRoot({ className, ...props }: ComponentProps<typeof ThreadListPrimitive.Root>) {\n return <ThreadListPrimitive.Root data-slot=\"aui_thread-list-root\" className={cn(\"flex flex-col gap-0.5\", className)} {...props}/>;\n}\nexport function ThreadListNew(props: ComponentProps<\"button\">) {\n return <ThreadListPrimitive.New asChild><button type=\"button\" data-slot=\"aui_thread-list-new\" className={cn(\"border-foreground/10 bg-background hover:border-foreground/25 rounded-control flex h-8 w-full shrink-0 items-center gap-2 border px-2.5 text-[13px] transition-colors\")} {...props}><PlusIcon className={cn(\"size-4 shrink-0\")}/>新建会话</button></ThreadListPrimitive.New>;\n}\nexport function ThreadListSearch({ value, onValueChange }: { value: string; onValueChange(value: string): void }) {\n return <div data-slot=\"aui_thread-list-search\" className={cn(\"relative px-0.5 py-1\")}>\n <SearchIcon data-slot=\"aui_thread-list-search-icon\" className={cn(\"text-muted-foreground pointer-events-none absolute start-3 top-1/2 size-4 -translate-y-1/2\")} />\n <Input type=\"search\" value={value} onChange={(event) => onValueChange(event.target.value)} aria-label=\"搜索会话\" placeholder=\"搜索会话\" className={cn(\"border-foreground/10 bg-background h-8 ps-8 text-[13px] md:text-[13px]\")} />\n </div>;\n}\nexport function ThreadListItem({ disabled, menu }: {\n disabled: boolean;\n menu: (beginRename: () => void) => ReactNode;\n}) {\n const isRunning = useAuiState((s) => s.threadListItem.isRunning);\n const title = useAuiState((s) => s.threadListItem.title);\n const [isRenaming, setIsRenaming] = useState(false);\n const triggerRef = useRef<HTMLButtonElement>(null);\n const restoreFocus = useRef(false);\n useEffect(() => {\n if (!isRenaming && restoreFocus.current) {\n restoreFocus.current = false;\n triggerRef.current?.focus();\n }\n }, [isRenaming]);\n return <ThreadListItemPrimitive.Root data-slot=\"aui_thread-list-item\" className={cn(\"group data-active:bg-foreground/[0.06] hover:bg-foreground/[0.04] has-data-[state=open]:bg-foreground/[0.04] rounded-control relative flex h-8 shrink-0 items-center transition-colors\")}>\n {isRenaming ? <ThreadListItemRename onDone={(focus) => { restoreFocus.current = focus; setIsRenaming(false); }} /> : <ThreadListItemPrimitive.Trigger ref={triggerRef} disabled={disabled} data-slot=\"aui_thread-list-item-trigger\" className={cn(\"text-muted-foreground group-data-active:text-foreground hover:text-foreground flex h-full min-w-0 flex-1 items-center px-2 text-left text-[13px] transition-colors outline-none group-hover:pe-8 group-has-focus-visible:pe-8 group-has-data-[state=open]:pe-8 group-data-active:pe-8\")}>\n {isRunning && <Loader2Icon aria-hidden className={cn(\"text-muted-foreground me-1.5 size-3.5 shrink-0 animate-spin\")}/>}\n <span className={cn(\"min-w-0 flex-1 truncate\")}><ThreadListItemPrimitive.Title fallback=\"新会话\"/></span>\n </ThreadListItemPrimitive.Trigger>}\n <DropdownMenu modal={false}><DropdownMenuTrigger asChild><button type=\"button\" aria-label={`管理 ${title}`} className={cn(\"text-muted-foreground hover:text-foreground absolute end-1 top-1/2 grid size-6 -translate-y-1/2 place-items-center rounded-sm opacity-0 transition-colors group-hover:opacity-100 group-has-focus-visible:opacity-100 group-data-active:opacity-100 focus-visible:opacity-100 data-[state=open]:opacity-100\")}><MoreHorizontalIcon className={cn(\"size-3.5\")}/></button></DropdownMenuTrigger>\n <DropdownMenuContent side=\"right\" align=\"start\" sideOffset={6}>{menu(() => setIsRenaming(true))}</DropdownMenuContent>\n </DropdownMenu>\n </ThreadListItemPrimitive.Root>;\n}\n\nfunction ThreadListItemRename({ onDone }: { onDone(restoreFocus: boolean): void }) {\n const aui = useAui();\n const title = useAuiState((s) => s.threadListItem.title) ?? \"\";\n const [value, setValue] = useState(title);\n const inputRef = useRef<HTMLInputElement>(null);\n const settled = useRef(false);\n useEffect(() => { inputRef.current?.select(); }, []);\n const commit = (focus: boolean) => {\n if (settled.current) return;\n settled.current = true;\n const next = value.trim();\n if (!next || next === title) { onDone(focus); return; }\n void Promise.resolve().then(() => aui.threadListItem.rename(next)).then(() => onDone(focus), () => {\n settled.current = false;\n if (focus) inputRef.current?.focus();\n });\n };\n return <Input ref={inputRef} autoFocus data-slot=\"aui_thread-list-item-rename\" aria-label=\"会话名称\" maxLength={80} value={value} className={cn(\"h-7 min-w-0 flex-1 ps-2 pe-8 text-[13px] md:text-[13px]\")}\n onChange={(event) => setValue(event.target.value)} onBlur={() => commit(false)} onKeyDown={(event) => {\n if (event.nativeEvent.isComposing || event.keyCode === 229) return;\n if (event.key === \"Enter\") { event.preventDefault(); commit(true); }\n else if (event.key === \"Escape\") { event.preventDefault(); settled.current = true; onDone(true); }\n }} />;\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { useCallback, useRef, useState } from "react";
|
|
3
|
+
import { useCallback, useRef, useState, } from "react";
|
|
4
4
|
import { cva } from "class-variance-authority";
|
|
5
5
|
import { useScrollLock } from "@assistant-ui/react";
|
|
6
|
-
import { Collapsible, CollapsibleContent } from "./collapsible.js";
|
|
6
|
+
import { Collapsible, CollapsibleContent, } from "./collapsible.js";
|
|
7
7
|
import { cn } from "./utils.js";
|
|
8
8
|
const ANIMATION_DURATION = 200;
|
|
9
9
|
const toolGroupVariants = cva("aui-tool-group-root group/tool-group w-full", {
|
|
@@ -37,3 +37,4 @@ function ToolGroupContent({ className, children, ...props }) {
|
|
|
37
37
|
return (_jsx(CollapsibleContent, { "data-slot": "tool-group-content", className: cn("aui-tool-group-content 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", "[--nxf-tw-duration:var(--animation-duration)]", className), ...props, children: _jsx("div", { className: cn("mt-2 flex flex-col gap-2", "group-data-[variant=ghost]/tool-group-root:mt-1 group-data-[variant=ghost]/tool-group-root:gap-1", "group-data-[variant=outline]/tool-group-root:mt-3 group-data-[variant=outline]/tool-group-root:border-t group-data-[variant=outline]/tool-group-root:px-4 group-data-[variant=outline]/tool-group-root:pt-3", "group-data-[variant=muted]/tool-group-root:mt-3 group-data-[variant=muted]/tool-group-root:border-t group-data-[variant=muted]/tool-group-root:px-4 group-data-[variant=muted]/tool-group-root:pt-3", "[&>*]:animate-in [&>*]:fade-in-0 [&>*]:blur-in-[2px] [&>*]:slide-in-from-top-1 [&>*]:animation-duration-(--animation-duration) [&>*]:ease-[cubic-bezier(0.32,0.72,0,1)]", "[&>*]:motion-reduce:animate-none", "[&>*:nth-child(2)]:[animation-delay:40ms]", "[&>*:nth-child(3)]:[animation-delay:80ms]", "[&>*:nth-child(4)]:[animation-delay:120ms]", "[&>*:nth-child(n+5)]:[animation-delay:160ms]"), children: children }) }));
|
|
38
38
|
}
|
|
39
39
|
export { ToolGroupRoot, ToolGroupContent };
|
|
40
|
+
//# sourceMappingURL=tool-group.aui.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-group.aui.js","sourceRoot":"","sources":["../../src/ui/tool-group.aui.t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mB,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;QACD,sBAAsB,EAAE,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC,EACD,CAAC,UAAU,EAAE,YAAY,EAAE,sBAAsB,CAAC,CACnD,CAAC;IAEF,OAAO,CACL,KAAC,WAAW,IACV,GAAG,EAAE,cAAc,eACT,iBAAiB,kBACb,OAAO,IAAI,SAAS,EAClC,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,gBAAgB,EAC9B,SAAS,EAAE,EAAE,CACX,iBAAiB,CAAC,EAAE,OAAO,EAAE,CAAC,EAC9B,uBAAuB,EACvB,SAAS,CACV,EACD,KAAK,EACH;YACE,0BAA0B,EAAE,GAAG,kBAAkB,IAAI;SAC/B,KAEtB,KAAK,YAER,QAAQ,GACG,CACf,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,EACxB,SAAS,EACT,QAAQ,EACR,GAAG,KAAK,EACwC;IAChD,OAAO,CACL,KAAC,kBAAkB,iBACP,oBAAoB,EAC9B,SAAS,EAAE,EAAE,CACX,sEAAsE,EACtE,yFAAyF,EACzF,oCAAoC,EACpC,oCAAoC,EACpC,gCAAgC,EAChC,iCAAiC,EACjC,+CAA+C,EAC/C,SAAS,CACV,KACG,KAAK,YAET,cACE,SAAS,EAAE,EAAE,CACX,0BAA0B,EAC1B,kGAAkG,EAClG,6MAA6M,EAC7M,qMAAqM,EACrM,yKAAyK,EACzK,kCAAkC,EAClC,2CAA2C,EAC3C,2CAA2C,EAC3C,4CAA4C,EAC5C,8CAA8C,CAC/C,YAEA,QAAQ,GACL,GACa,CACtB,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,CAAC","sourcesContent":["\"use client\";\n\nimport {\n useCallback,\n useRef,\n useState,\n} from \"react\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport { useScrollLock } from \"@assistant-ui/react\";\nimport {\n Collapsible,\n CollapsibleContent,\n} from \"./collapsible.js\";\nimport { cn } from \"./utils.js\";\n\nconst ANIMATION_DURATION = 200;\n\nconst toolGroupVariants = cva(\"aui-tool-group-root group/tool-group w-full\", {\n variants: {\n variant: {\n outline: \"rounded-lg border py-3\",\n ghost: \"\",\n muted: \"border-muted-foreground/30 bg-muted/30 rounded-lg border py-3\",\n },\n },\n defaultVariants: { variant: \"outline\" },\n});\n\nexport type ToolGroupRootProps = Omit<\n React.ComponentProps<typeof Collapsible>,\n \"open\" | \"onOpenChange\"\n> &\n VariantProps<typeof toolGroupVariants> & {\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n defaultOpen?: boolean;\n };\n\nfunction ToolGroupRoot({\n className,\n variant,\n open: controlledOpen,\n onOpenChange: controlledOnOpenChange,\n defaultOpen = false,\n children,\n ...props\n}: ToolGroupRootProps) {\n const collapsibleRef = useRef<HTMLDivElement>(null);\n const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);\n const lockScroll = useScrollLock(collapsibleRef, ANIMATION_DURATION);\n\n const isControlled = controlledOpen !== undefined;\n const isOpen = isControlled ? controlledOpen : uncontrolledOpen;\n\n const handleOpenChange = useCallback(\n (open: boolean) => {\n lockScroll();\n if (!isControlled) {\n setUncontrolledOpen(open);\n }\n controlledOnOpenChange?.(open);\n },\n [lockScroll, isControlled, controlledOnOpenChange],\n );\n\n return (\n <Collapsible\n ref={collapsibleRef}\n data-slot=\"tool-group-root\"\n data-variant={variant ?? \"outline\"}\n open={isOpen}\n onOpenChange={handleOpenChange}\n className={cn(\n toolGroupVariants({ variant }),\n \"group/tool-group-root\",\n className,\n )}\n style={\n {\n \"--nxf-animation-duration\": `${ANIMATION_DURATION}ms`,\n } as React.CSSProperties\n }\n {...props}\n >\n {children}\n </Collapsible>\n );\n}\n\nfunction ToolGroupContent({\n className,\n children,\n ...props\n}: React.ComponentProps<typeof CollapsibleContent>) {\n return (\n <CollapsibleContent\n data-slot=\"tool-group-content\"\n className={cn(\n \"aui-tool-group-content 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 \"[--nxf-tw-duration:var(--animation-duration)]\",\n className,\n )}\n {...props}\n >\n <div\n className={cn(\n \"mt-2 flex flex-col gap-2\",\n \"group-data-[variant=ghost]/tool-group-root:mt-1 group-data-[variant=ghost]/tool-group-root:gap-1\",\n \"group-data-[variant=outline]/tool-group-root:mt-3 group-data-[variant=outline]/tool-group-root:border-t group-data-[variant=outline]/tool-group-root:px-4 group-data-[variant=outline]/tool-group-root:pt-3\",\n \"group-data-[variant=muted]/tool-group-root:mt-3 group-data-[variant=muted]/tool-group-root:border-t group-data-[variant=muted]/tool-group-root:px-4 group-data-[variant=muted]/tool-group-root:pt-3\",\n \"[&>*]:animate-in [&>*]:fade-in-0 [&>*]:blur-in-[2px] [&>*]:slide-in-from-top-1 [&>*]:animation-duration-(--animation-duration) [&>*]:ease-[cubic-bezier(0.32,0.72,0,1)]\",\n \"[&>*]:motion-reduce:animate-none\",\n \"[&>*:nth-child(2)]:[animation-delay:40ms]\",\n \"[&>*:nth-child(3)]:[animation-delay:80ms]\",\n \"[&>*:nth-child(4)]:[animation-delay:120ms]\",\n \"[&>*:nth-child(n+5)]:[animation-delay:160ms]\",\n )}\n >\n {children}\n </div>\n </CollapsibleContent>\n );\n}\n\nexport { ToolGroupRoot, ToolGroupContent };\n"]}
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { forwardRef } from "react";
|
|
4
4
|
import { Slot } from "radix-ui";
|
|
5
|
-
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./tooltip.js";
|
|
5
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "./tooltip.js";
|
|
6
6
|
import { Button } from "./button.js";
|
|
7
7
|
import { cn } from "./utils.js";
|
|
8
8
|
export const TooltipIconButton = forwardRef(({ children, tooltip, side = "bottom", className, ...rest }, ref) => {
|
|
9
9
|
return (_jsx(TooltipProvider, { delayDuration: 0, children: _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsxs(Button, { variant: "ghost", size: "icon", ...rest, className: cn("aui-button-icon size-6 p-1 active:scale-90", className), ref: ref, children: [_jsx(Slot.Slottable, { children: children }), _jsx("span", { className: cn("aui-sr-only sr-only"), children: tooltip })] }) }), _jsx(TooltipContent, { side: side, children: tooltip })] }) }));
|
|
10
10
|
});
|
|
11
11
|
TooltipIconButton.displayName = "TooltipIconButton";
|
|
12
|
+
//# sourceMappingURL=tooltip-icon-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip-icon-button.js","sourceRoot":"","sources":["../../src/ui/tooltip-icon-button.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAA8B,UAAU,EAAE,MAAM,OAAO,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,GAAG,MAAM,cAAc,CAAC;AACzF,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAKhC,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAA4C,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,GAAG,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE;IACzJ,OAAO,CAAC,KAAC,eAAe,IAAC,aAAa,EAAE,CAAC,YACxC,MAAC,OAAO,eACP,KAAC,cAAc,IAAC,OAAO,kBACtB,MAAC,MAAM,IAAC,OAAO,EAAC,OAAO,EAAC,IAAI,EAAC,MAAM,KAAK,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC,4CAA4C,EAAE,SAAS,CAAC,EAAE,GAAG,EAAE,GAAG,aAC7H,KAAC,IAAI,CAAC,SAAS,cAAE,QAAQ,GAAkB,EAC3C,eAAM,SAAS,EAAE,EAAE,CAAC,qBAAqB,CAAC,YAAG,OAAO,GAAQ,IACpD,GACO,EACjB,KAAC,cAAc,IAAC,IAAI,EAAE,IAAI,YAAG,OAAO,GAAkB,IAC7C,GACO,CAAC,CAAC;AACtB,CAAC,CAAC,CAAC;AACH,iBAAiB,CAAC,WAAW,GAAG,mBAAmB,CAAC","sourcesContent":["\"use client\";\nimport { type ComponentPropsWithRef, forwardRef } from \"react\";\nimport { Slot } from \"radix-ui\";\nimport { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from \"./tooltip.js\";\nimport { Button } from \"./button.js\";\nimport { cn } from \"./utils.js\";\nexport type TooltipIconButtonProps = ComponentPropsWithRef<typeof Button> & {\n tooltip: string;\n side?: \"top\" | \"bottom\" | \"left\" | \"right\";\n};\nexport const TooltipIconButton = forwardRef<HTMLButtonElement, TooltipIconButtonProps>(({ children, tooltip, side = \"bottom\", className, ...rest }, ref) => {\n return (<TooltipProvider delayDuration={0}>\n <Tooltip>\n <TooltipTrigger asChild>\n <Button variant=\"ghost\" size=\"icon\" {...rest} className={cn(\"aui-button-icon size-6 p-1 active:scale-90\", className)} ref={ref}>\n <Slot.Slottable>{children}</Slot.Slottable>\n <span className={cn(\"aui-sr-only sr-only\")}>{tooltip}</span>\n </Button>\n </TooltipTrigger>\n <TooltipContent side={side}>{tooltip}</TooltipContent>\n </Tooltip>\n </TooltipProvider>);\n});\nTooltipIconButton.displayName = \"TooltipIconButton\";\n"]}
|
package/dist/ui/tooltip.js
CHANGED
|
@@ -20,3 +20,4 @@ function TooltipContent({ className, sideOffset = 0, children, ...props }) {
|
|
|
20
20
|
return (_jsx(TooltipPrimitive.Portal, { container: container, children: _jsxs(TooltipPrimitive.Content, { "data-slot": "tooltip-content", sideOffset: sideOffset, className: cn("z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95", className), ...props, children: [_jsx(PortalThemeSync, {}), children, _jsx(TooltipPrimitive.Arrow, { className: cn("z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground") })] }) }));
|
|
21
21
|
}
|
|
22
22
|
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
|
|
23
|
+
//# sourceMappingURL=tooltip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip.js","sourceRoot":"","sources":["../../src/ui/tooltip.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAChC,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACvD,SAAS,eAAe,CAAC,EAAE,aAAa,GAAG,CAAC,EAAE,GAAG,KAAK,EAA0D;IAC9G,OAAO,CAAC,KAAC,gBAAgB,CAAC,QAAQ,iBAAW,kBAAkB,EAAC,aAAa,EAAE,aAAa,KAAM,KAAK,GAAG,CAAC,CAAC;AAC9G,CAAC;AACD,SAAS,OAAO,CAAC,EAAE,GAAG,KAAK,EAAsD;IAC/E,OAAO,KAAC,gBAAgB,CAAC,IAAI,iBAAW,SAAS,KAAK,KAAK,GAAG,CAAC;AACjE,CAAC;AACD,MAAM,cAAc,GAAG,KAAK,CAAC,UAAU,CAAqF,SAAS,cAAc,CAAC,EAAE,GAAG,KAAK,EAAE,EAAE,GAAG;IACnK,OAAO,KAAC,gBAAgB,CAAC,OAAO,iBAAW,iBAAiB,EAAC,GAAG,EAAE,GAAG,KAAM,KAAK,GAAG,CAAC;AACtF,CAAC,CAAC,CAAC;AACH,SAAS,cAAc,CAAC,EAAE,SAAS,EAAE,UAAU,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAyD;IAC9H,MAAM,SAAS,GAAG,kBAAkB,EAAE,CAAC;IACvC,IAAI,CAAC,SAAS;QACZ,OAAO,IAAI,CAAC;IACd,OAAO,CAAC,KAAC,gBAAgB,CAAC,MAAM,IAAC,SAAS,EAAE,SAAS,YACpD,MAAC,gBAAgB,CAAC,OAAO,iBAAW,iBAAiB,EAAC,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,CAAC,maAAma,EAAE,SAAS,CAAC,KAAM,KAAK,aACrhB,KAAC,eAAe,KAAG,EAAC,QAAQ,EAC5B,KAAC,gBAAgB,CAAC,KAAK,IAAC,SAAS,EAAE,EAAE,CAAC,oGAAoG,CAAC,GAAG,IACpH,GACF,CAAC,CAAC;AAC9B,CAAC;AACD,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,CAAC","sourcesContent":["\"use client\";\nimport { usePortalContainer, PortalThemeSync } from \"./surface.js\";\nimport * as React from \"react\";\nimport { cn } from \"./utils.js\";\nimport { Tooltip as TooltipPrimitive } from \"radix-ui\";\nfunction TooltipProvider({ delayDuration = 0, ...props }: React.ComponentProps<typeof TooltipPrimitive.Provider>) {\n return (<TooltipPrimitive.Provider data-slot=\"tooltip-provider\" delayDuration={delayDuration} {...props}/>);\n}\nfunction Tooltip({ ...props }: React.ComponentProps<typeof TooltipPrimitive.Root>) {\n return <TooltipPrimitive.Root data-slot=\"tooltip\" {...props}/>;\n}\nconst TooltipTrigger = React.forwardRef<HTMLButtonElement, React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Trigger>>(function TooltipTrigger({ ...props }, ref) {\n return <TooltipPrimitive.Trigger data-slot=\"tooltip-trigger\" ref={ref} {...props}/>;\n});\nfunction TooltipContent({ className, sideOffset = 0, children, ...props }: React.ComponentProps<typeof TooltipPrimitive.Content>) {\n const container = usePortalContainer();\n if (!container)\n return null;\n return (<TooltipPrimitive.Portal container={container}>\n <TooltipPrimitive.Content data-slot=\"tooltip-content\" sideOffset={sideOffset} className={cn(\"z-50 w-fit origin-(--radix-tooltip-content-transform-origin) animate-in rounded-md bg-foreground px-3 py-1.5 text-xs text-balance text-background fade-in-0 zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95\", className)} {...props}>\n <PortalThemeSync />{children}\n <TooltipPrimitive.Arrow className={cn(\"z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground\")}/>\n </TooltipPrimitive.Content>\n </TooltipPrimitive.Portal>);\n}\nexport { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };\n"]}
|
|
@@ -21,7 +21,8 @@ const useFileSrc = (file) => {
|
|
|
21
21
|
return entry !== undefined && entry.file === file ? entry.url : undefined;
|
|
22
22
|
};
|
|
23
23
|
export const useAttachmentSrc = () => {
|
|
24
|
-
const file = useAuiState((s) =>
|
|
24
|
+
const file = useAuiState((s) => s.attachment.type === "image" ? s.attachment.file : undefined);
|
|
25
25
|
const src = useAuiState((s) => s.attachment.content?.find((part) => part.type === "image")?.image);
|
|
26
26
|
return useFileSrc(file) ?? src;
|
|
27
27
|
};
|
|
28
|
+
//# sourceMappingURL=use-attachment-src.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-attachment-src.js","sourceRoot":"","sources":["../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AU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC;IACnG,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC;AACjC,CAAC,CAAC","sourcesContent":["\"use client\";\nimport { useEffect, useState } from \"react\";\nimport { useAuiState } from \"@assistant-ui/react\";\nconst useFileSrc = (file: File | undefined) => {\n const [entry, setEntry] = useState<{\n file: File;\n url: string;\n } | undefined>(undefined);\n useEffect(() => {\n // The object URL is a browser resource whose lifetime has to straddle\n // commit, so allocation, revocation, and clearing the entry that names a\n // revoked URL all belong to the effect.\n if (!file) {\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setEntry(undefined);\n return;\n }\n const objectUrl = URL.createObjectURL(file);\n setEntry({ file, url: objectUrl });\n return () => {\n URL.revokeObjectURL(objectUrl);\n };\n }, [file]);\n return entry !== undefined && entry.file === file ? entry.url : undefined;\n};\nexport const useAttachmentSrc = () => {\n const file = useAuiState((s) => s.attachment.type === \"image\" ? s.attachment.file : undefined);\n const src = useAuiState((s) => s.attachment.content?.find((part) => part.type === \"image\")?.image);\n return useFileSrc(file) ?? src;\n};\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type UseCopyToClipboardOptions = {
|
|
2
2
|
copiedDuration?: number;
|
|
3
3
|
};
|
|
4
|
-
export declare const useCopyToClipboard: ({ copiedDuration }?: UseCopyToClipboardOptions) => {
|
|
4
|
+
export declare const useCopyToClipboard: ({ copiedDuration, }?: UseCopyToClipboardOptions) => {
|
|
5
5
|
isCopied: boolean;
|
|
6
6
|
copyToClipboard: (value: string) => void;
|
|
7
7
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useState } from "react";
|
|
3
|
-
export const useCopyToClipboard = ({ copiedDuration = 3000 } = {}) => {
|
|
3
|
+
export const useCopyToClipboard = ({ copiedDuration = 3000, } = {}) => {
|
|
4
4
|
const [isCopied, setIsCopied] = useState(false);
|
|
5
5
|
const copyToClipboard = (value) => {
|
|
6
6
|
if (!value || typeof navigator === "undefined" || !navigator.clipboard) {
|
|
@@ -13,3 +13,4 @@ export const useCopyToClipboard = ({ copiedDuration = 3000 } = {}) => {
|
|
|
13
13
|
};
|
|
14
14
|
return { isCopied, copyToClipboard };
|
|
15
15
|
};
|
|
16
|
+
//# sourceMappingURL=use-copy-to-clipboard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-copy-to-clipboard.js","sourceRoot":"","sources":["../../src/ui/use-copy-to-clipboard.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAIjC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EAAE,cAAc,GAAG,IAAI,MAAiC,EAAE,EAAE,EAAE;IAC/F,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC,CAAC;IACzD,MAAM,eAAe,GAAG,CAAC,KAAa,EAAE,EAAE;QACxC,IAAI,CAAC,KAAK,IAAI,OAAO,SAAS,KAAK,WAAW,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;YACvE,OAAO;QACT,CAAC;QACD,SAAS,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;YAC7C,WAAW,CAAC,IAAI,CAAC,CAAC;YAClB,UAAU,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC,CAAC;QACvD,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAChB,CAAC,CAAC;IACF,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC;AACvC,CAAC,CAAC","sourcesContent":["\"use client\";\nimport { useState } from \"react\";\nexport type UseCopyToClipboardOptions = {\n copiedDuration?: number;\n};\nexport const useCopyToClipboard = ({ copiedDuration = 3000, }: UseCopyToClipboardOptions = {}) => {\n const [isCopied, setIsCopied] = useState<boolean>(false);\n const copyToClipboard = (value: string) => {\n if (!value || typeof navigator === \"undefined\" || !navigator.clipboard) {\n return;\n }\n navigator.clipboard.writeText(value).then(() => {\n setIsCopied(true);\n setTimeout(() => setIsCopied(false), copiedDuration);\n }, () => { });\n };\n return { isCopied, copyToClipboard };\n};\n"]}
|
package/dist/ui/utils.js
CHANGED
|
@@ -2,13 +2,7 @@ import { clsx } from "clsx";
|
|
|
2
2
|
import { twMerge } from "tailwind-merge";
|
|
3
3
|
// Keep upstream recipes readable; namespace classes at the component boundary.
|
|
4
4
|
export function cn(...inputs) {
|
|
5
|
-
const raw = clsx(inputs)
|
|
6
|
-
|
|
7
|
-
.map((token) => token.replace(/^nxf-/, ""))
|
|
8
|
-
.join(" ");
|
|
9
|
-
return twMerge(raw)
|
|
10
|
-
.split(/\s+/)
|
|
11
|
-
.filter(Boolean)
|
|
12
|
-
.map((token) => (/^(aui-|nexface-)/.test(token) ? token : `nxf-${token}`))
|
|
13
|
-
.join(" ");
|
|
5
|
+
const raw = clsx(inputs).split(/\s+/).map((token) => token.replace(/^nxf-/, "")).join(" ");
|
|
6
|
+
return twMerge(raw).split(/\s+/).filter(Boolean).map((token) => /^(aui-|nexface-)/.test(token) ? token : `nxf-${token}`).join(" ");
|
|
14
7
|
}
|
|
8
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/ui/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,MAAM,MAAM,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,+EAA+E;AAC/E,MAAM,UAAU,EAAE,CAAC,GAAG,MAAoB;IACxC,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3F,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACrI,CAAC","sourcesContent":["import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n// Keep upstream recipes readable; namespace classes at the component boundary.\nexport function cn(...inputs: ClassValue[]) {\n const raw = clsx(inputs).split(/\\s+/).map((token) => token.replace(/^nxf-/, \"\")).join(\" \");\n return twMerge(raw).split(/\\s+/).filter(Boolean).map((token) => /^(aui-|nexface-)/.test(token) ? token : `nxf-${token}`).join(\" \");\n}\n"]}
|
package/dist/use-next-message.js
CHANGED
|
@@ -17,9 +17,7 @@ export function suggestionMessages(messages) {
|
|
|
17
17
|
}
|
|
18
18
|
export function useNextMessage(chat, suggest, open) {
|
|
19
19
|
const latest = useRef({ suggest, messages: chat.messages });
|
|
20
|
-
useLayoutEffect(() => {
|
|
21
|
-
latest.current = { suggest, messages: chat.messages };
|
|
22
|
-
});
|
|
20
|
+
useLayoutEffect(() => { latest.current = { suggest, messages: chat.messages }; });
|
|
23
21
|
const [suggestion, setSuggestion] = useState();
|
|
24
22
|
const enabled = Boolean(suggest);
|
|
25
23
|
const completionKey = chat.completed ? `${chat.activeSessionId}:${chat.completed.id}` : undefined;
|
|
@@ -33,8 +31,7 @@ export function useNextMessage(chat, suggest, open) {
|
|
|
33
31
|
return;
|
|
34
32
|
const controller = new AbortController();
|
|
35
33
|
// Defer invocation so StrictMode cleanup can cancel the first effect.
|
|
36
|
-
void Promise.resolve()
|
|
37
|
-
.then(async () => {
|
|
34
|
+
void Promise.resolve().then(async () => {
|
|
38
35
|
if (controller.signal.aborted)
|
|
39
36
|
return;
|
|
40
37
|
const text = await latest.current.suggest?.({
|
|
@@ -44,8 +41,7 @@ export function useNextMessage(chat, suggest, open) {
|
|
|
44
41
|
});
|
|
45
42
|
if (!controller.signal.aborted)
|
|
46
43
|
setSuggestion({ key, text: text?.trim() || undefined });
|
|
47
|
-
})
|
|
48
|
-
.catch(() => {
|
|
44
|
+
}).catch(() => {
|
|
49
45
|
if (!controller.signal.aborted)
|
|
50
46
|
setSuggestion({ key, text: undefined });
|
|
51
47
|
});
|
|
@@ -53,3 +49,4 @@ export function useNextMessage(chat, suggest, open) {
|
|
|
53
49
|
}, [key, completionKey, open, suggestion?.key]);
|
|
54
50
|
return suggestion?.key === key ? suggestion?.text : undefined;
|
|
55
51
|
}
|
|
52
|
+
//# sourceMappingURL=use-next-message.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-next-message.js","sourceRoot":"","sources":["../src/use-next-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAOrE,MAAM,UAAU,kBAAkB,CAAC,QAA8B;IAC/D,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAA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;IAChD,OAAO,UAAU,EAAE,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AAChE,CAAC","sourcesContent":["import { useEffect, useLayoutEffect, useRef, useState } from \"react\";\nimport type { useChat } from \"./react.js\";\nimport type { UIMessage } from \"./messages.js\";\nimport type { ChatProps } from \"./types.js\";\n\ntype ChatSuggestionMessage = Parameters<NonNullable<ChatProps[\"suggestNextMessage\"]>>[0][\"messages\"][number];\n\nexport function suggestionMessages(messages: readonly UIMessage[]): ChatSuggestionMessage[] {\n const result: ChatSuggestionMessage[] = [];\n for (const message of messages) {\n const parts = message.parts.flatMap((part) => part.type === \"text\" && part.text.trim() ? [{ type: \"text\" as const, text: part.text }] : []);\n if (message.role === \"assistant\" && !parts.length) continue;\n const previous = result.at(-1);\n if (message.role === \"assistant\" && previous?.role === \"assistant\") {\n previous.parts = [...previous.parts, ...parts];\n } else {\n result.push({ role: message.role, parts });\n }\n }\n return result;\n}\n\nexport function useNextMessage(chat: ReturnType<typeof useChat>, suggest: ChatProps[\"suggestNextMessage\"], open: boolean): string | undefined {\n const latest = useRef({ suggest, messages: chat.messages });\n useLayoutEffect(() => { latest.current = { suggest, messages: chat.messages }; });\n const [suggestion, setSuggestion] = useState<{ key: string; text: string | undefined }>();\n const enabled = Boolean(suggest);\n const completionKey = chat.completed ? `${chat.activeSessionId}:${chat.completed.id}` : undefined;\n const key = enabled && chat.status === \"idle\" && chat.messages.length ? completionKey : undefined;\n useEffect(() => {\n if (!key) {\n setSuggestion(undefined);\n return;\n }\n if (!open || suggestion?.key === key) return;\n const controller = new AbortController();\n // Defer invocation so StrictMode cleanup can cancel the first effect.\n void Promise.resolve().then(async () => {\n if (controller.signal.aborted) return;\n const text = await latest.current.suggest?.({\n sessionId: chat.activeSessionId,\n messages: suggestionMessages(latest.current.messages),\n signal: controller.signal,\n });\n if (!controller.signal.aborted) setSuggestion({ key, text: text?.trim() || undefined });\n }).catch(() => {\n if (!controller.signal.aborted) setSuggestion({ key, text: undefined });\n });\n return () => controller.abort();\n }, [key, completionKey, open, suggestion?.key]);\n return suggestion?.key === key ? suggestion?.text : undefined;\n}\n"]}
|
package/dist/voice/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/voice/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DictationAdapter } from \"@assistant-ui/react\";\n\nexport type ChatDictation = Pick<DictationAdapter, \"listen\">;\n"]}
|
package/dist/voice/use-voice.js
CHANGED
|
@@ -7,10 +7,7 @@ export function useVoiceInput(options) {
|
|
|
7
7
|
const [status, setStatus] = useState("idle");
|
|
8
8
|
const owner = useRef(undefined);
|
|
9
9
|
const generation = useRef(0);
|
|
10
|
-
const cancel = () => {
|
|
11
|
-
owner.current?.();
|
|
12
|
-
generation.current++;
|
|
13
|
-
};
|
|
10
|
+
const cancel = () => { owner.current?.(); generation.current++; };
|
|
14
11
|
const dictation = useMemo(() => ({
|
|
15
12
|
disableInputDuringDictation: true,
|
|
16
13
|
listen() {
|
|
@@ -35,14 +32,10 @@ export function useVoiceInput(options) {
|
|
|
35
32
|
callback(value);
|
|
36
33
|
};
|
|
37
34
|
const valid = () => !ended && generation.current === token;
|
|
38
|
-
const restore = () => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
catch {
|
|
43
|
-
/* A disposed Session no longer owns a composer. */
|
|
44
|
-
}
|
|
45
|
-
};
|
|
35
|
+
const restore = () => { try {
|
|
36
|
+
composer.setText(original);
|
|
37
|
+
}
|
|
38
|
+
catch { /* A disposed Session no longer owns a composer. */ } };
|
|
46
39
|
const finish = (reason) => {
|
|
47
40
|
if (!valid())
|
|
48
41
|
return;
|
|
@@ -70,16 +63,14 @@ export function useVoiceInput(options) {
|
|
|
70
63
|
try {
|
|
71
64
|
input?.cancel();
|
|
72
65
|
}
|
|
73
|
-
catch {
|
|
74
|
-
/* Cancellation still restores the draft. */
|
|
75
|
-
}
|
|
66
|
+
catch { /* Cancellation still restores the draft. */ }
|
|
76
67
|
};
|
|
77
68
|
const session = {
|
|
78
69
|
get status() {
|
|
79
70
|
// Reuse assistant-ui's status polling, including sources that emit no end event.
|
|
80
71
|
if (!ended && input?.status.type === "ended")
|
|
81
72
|
queueMicrotask(complete);
|
|
82
|
-
return ended ? status :
|
|
73
|
+
return ended ? status : input?.status ?? status;
|
|
83
74
|
},
|
|
84
75
|
stop: async () => {
|
|
85
76
|
if (!valid())
|
|
@@ -95,18 +86,9 @@ export function useVoiceInput(options) {
|
|
|
95
86
|
}
|
|
96
87
|
},
|
|
97
88
|
cancel: terminate,
|
|
98
|
-
onSpeechStart(callback) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
},
|
|
102
|
-
onSpeech(callback) {
|
|
103
|
-
speeches.add(callback);
|
|
104
|
-
return () => speeches.delete(callback);
|
|
105
|
-
},
|
|
106
|
-
onSpeechEnd(callback) {
|
|
107
|
-
ends.add(callback);
|
|
108
|
-
return () => ends.delete(callback);
|
|
109
|
-
},
|
|
89
|
+
onSpeechStart(callback) { starts.add(callback); return () => starts.delete(callback); },
|
|
90
|
+
onSpeech(callback) { speeches.add(callback); return () => speeches.delete(callback); },
|
|
91
|
+
onSpeechEnd(callback) { ends.add(callback); return () => ends.delete(callback); },
|
|
110
92
|
};
|
|
111
93
|
owner.current = terminate;
|
|
112
94
|
config.notice("");
|
|
@@ -119,9 +101,7 @@ export function useVoiceInput(options) {
|
|
|
119
101
|
try {
|
|
120
102
|
input?.cancel();
|
|
121
103
|
}
|
|
122
|
-
catch {
|
|
123
|
-
/* The source already failed. */
|
|
124
|
-
}
|
|
104
|
+
catch { /* The source already failed. */ }
|
|
125
105
|
if (!cancelled)
|
|
126
106
|
latest.current.notice(error instanceof Error ? error.message : "语音输入失败,请重试。");
|
|
127
107
|
};
|
|
@@ -172,8 +152,6 @@ export function useVoiceInput(options) {
|
|
|
172
152
|
cancel();
|
|
173
153
|
}, [options.active, options.open, options.blocked, enabled]);
|
|
174
154
|
useLayoutEffect(() => () => cancel(), [source, options.sessionId]);
|
|
175
|
-
return {
|
|
176
|
-
dictation: enabled ? dictation : undefined,
|
|
177
|
-
state: { status, supported: enabled, cancel },
|
|
178
|
-
};
|
|
155
|
+
return { dictation: enabled ? dictation : undefined, state: { status, supported: enabled, cancel } };
|
|
179
156
|
}
|
|
157
|
+
//# sourceMappingURL=use-voice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-voice.js","sourceRoot":"","sources":["../../src/voice/use-voice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAUnE,MAAM,UAAU,aAAa,CAAC,OAQ7B;IACC,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAC/B,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,IAAI,SAAS,CAAC;IAC9C,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAChC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAA+B,MAAM,CAAC,CAAC;IAC3E,MAAM,KAAK,GAAG,MAAM,CAA2B,SAAS,CAAC,CAAC;IAC1D,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC7B,MAAM,MAAM,GAAG,GAAG,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;IAElE,MAAM,SAAS,GAAG,OAAO,CAAmB,GAAG,EAAE,CAAC,CAAC;QACjD,2BAA2B,EAAE,IAAI;QACjC,MAAM;YACJ,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;YAC9B,IAAI,CAAC,MAAM,CA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,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IACnE,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAA+B,EAAE,CAAC;AACpI,CAAC","sourcesContent":["import { useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { ComposerRuntime, DictationAdapter } from \"@assistant-ui/react\";\nimport type { ChatDictation } from \"./types.js\";\n\nexport interface VoiceComposerState {\n supported: boolean;\n status: \"idle\" | \"starting\" | \"recording\" | \"transcribing\";\n cancel(): void;\n}\n\nexport function useVoiceInput(options: {\n dictation: false | ChatDictation | undefined;\n active: boolean;\n open: boolean;\n blocked: boolean;\n sessionId: string;\n composer(): ComposerRuntime;\n notice(message: string): void;\n}) {\n const latest = useRef(options);\n latest.current = options;\n const source = options.dictation || undefined;\n const enabled = Boolean(source);\n const [status, setStatus] = useState<VoiceComposerState[\"status\"]>(\"idle\");\n const owner = useRef<(() => void) | undefined>(undefined);\n const generation = useRef(0);\n const cancel = () => { owner.current?.(); generation.current++; };\n\n const dictation = useMemo<DictationAdapter>(() => ({\n disableInputDuringDictation: true,\n listen() {\n const config = latest.current;\n if (!config.active || !config.open || config.blocked || !config.dictation || !source) throw new Error(\"当前无法开始语音输入。\");\n cancel();\n const token = ++generation.current;\n const composer = config.composer();\n const original = composer.getState().text;\n const starts = new Set<() => void>();\n const speeches = new Set<(result: DictationAdapter.Result) => void>();\n const ends = new Set<(result: DictationAdapter.Result) => void>();\n let input: DictationAdapter.Session | undefined;\n const subscriptions: Array<() => void> = [];\n let confirmed = original;\n let hasConfirmed = false;\n let ended = false;\n let status: DictationAdapter.Session[\"status\"] = { type: \"starting\" };\n const emit = <T,>(listeners: Set<(value: T) => void>, value: T) => {\n for (const callback of [...listeners]) callback(value);\n };\n const valid = () => !ended && generation.current === token;\n const restore = () => { try { composer.setText(original); } catch { /* A disposed Session no longer owns a composer. */ } };\n const finish = (reason: \"stopped\" | \"cancelled\" | \"error\") => {\n if (!valid()) return;\n ended = true;\n status = { type: \"ended\", reason };\n owner.current = undefined;\n for (const unsubscribe of subscriptions.splice(0)) unsubscribe();\n if (reason !== \"stopped\" || !hasConfirmed) restore();\n else composer.setText(confirmed);\n emit(ends, { transcript: \"\", isFinal: true });\n if (reason === \"stopped\" && !hasConfirmed) latest.current.notice(\"未识别到语音,请重试。\");\n setStatus(\"idle\");\n };\n const terminate = () => {\n if (ended) return;\n if (valid()) { finish(\"cancelled\"); generation.current++; }\n try { input?.cancel(); } catch { /* Cancellation still restores the draft. */ }\n };\n const session: DictationAdapter.Session = {\n get status() {\n // Reuse assistant-ui's status polling, including sources that emit no end event.\n if (!ended && input?.status.type === \"ended\") queueMicrotask(complete);\n return ended ? status : input?.status ?? status;\n },\n stop: async () => {\n if (!valid()) return;\n setStatus(\"transcribing\");\n try {\n await input?.stop();\n if (valid()) complete();\n } catch (error) { failure(error); }\n },\n cancel: terminate,\n onSpeechStart(callback) { starts.add(callback); return () => starts.delete(callback); },\n onSpeech(callback) { speeches.add(callback); return () => speeches.delete(callback); },\n onSpeechEnd(callback) { ends.add(callback); return () => ends.delete(callback); },\n };\n owner.current = terminate;\n config.notice(\"\");\n setStatus(\"starting\");\n const failure = (error: unknown) => {\n if (!valid()) return;\n const cancelled = error instanceof DOMException && error.name === \"AbortError\";\n finish(cancelled ? \"cancelled\" : \"error\");\n try { input?.cancel(); } catch { /* The source already failed. */ }\n if (!cancelled) latest.current.notice(error instanceof Error ? error.message : \"语音输入失败,请重试。\");\n };\n const complete = () => {\n if (!valid()) return;\n const reason = input?.status.type === \"ended\" ? input.status.reason : \"stopped\";\n if (reason === \"error\") failure(new Error(\"语音输入失败,请检查授权、麦克风权限和网络。\"));\n else finish(reason);\n };\n try {\n input = source.listen();\n const started = () => {\n if (!valid()) return;\n status = { type: \"running\" };\n setStatus(\"recording\");\n for (const callback of [...starts]) callback();\n };\n subscriptions.push(input.onSpeechStart(started));\n subscriptions.push(input.onSpeech((result) => {\n if (!valid()) return;\n emit(speeches, result);\n if (result.isFinal !== false) {\n confirmed = composer.getState().text;\n hasConfirmed ||= Boolean(result.transcript.trim());\n }\n }));\n subscriptions.push(input.onSpeechEnd(complete));\n // Sources may already be running or synchronously ended after listen().\n if (input.status.type === \"running\") queueMicrotask(started);\n if (input.status.type === \"ended\") queueMicrotask(complete);\n } catch (error) { queueMicrotask(() => failure(error)); }\n return session;\n },\n }), [source]);\n\n useLayoutEffect(() => {\n if (!options.active || !options.open || options.blocked || !enabled) cancel();\n }, [options.active, options.open, options.blocked, enabled]);\n useLayoutEffect(() => () => cancel(), [source, options.sessionId]);\n return { dictation: enabled ? dictation : undefined, state: { status, supported: enabled, cancel } satisfies VoiceComposerState };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nexface/chat",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15-alpha.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
6
6
|
"./dist/index.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@ag-ui/core": "0.0.59",
|
|
21
|
-
"@nexface/agent": "0.1.
|
|
21
|
+
"@nexface/agent": "0.1.15-alpha.0",
|
|
22
22
|
"class-variance-authority": "0.7.1",
|
|
23
23
|
"clsx": "2.1.1",
|
|
24
24
|
"fast-json-patch": "3.1.1",
|
|
@@ -27,15 +27,11 @@
|
|
|
27
27
|
"use-sync-external-store": "1.7.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@nexface/tools": "0.1.
|
|
30
|
+
"@nexface/tools": "0.1.15-alpha.0",
|
|
31
31
|
"react": ">=17",
|
|
32
32
|
"react-dom": ">=17"
|
|
33
33
|
},
|
|
34
34
|
"files": [
|
|
35
35
|
"dist"
|
|
36
|
-
]
|
|
37
|
-
"repository": {
|
|
38
|
-
"type": "git",
|
|
39
|
-
"url": "git+https://github.com/fishear/nexface.git"
|
|
40
|
-
}
|
|
36
|
+
]
|
|
41
37
|
}
|