@nexface/chat 0.1.13-alpha.1 → 0.1.13-alpha.3
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 +0 -1
- package/dist/assistant-components.js +15 -8
- package/dist/assistant-runtime.d.ts +5 -1
- package/dist/assistant-runtime.js +8 -5
- package/dist/attachments.js +0 -1
- package/dist/client.js +0 -1
- package/dist/config.js +0 -1
- package/dist/default-chat.d.ts +1 -1
- package/dist/default-chat.js +614 -347
- package/dist/errors.js +0 -1
- package/dist/index.js +0 -1
- package/dist/messages.js +0 -1
- package/dist/page-confirmation.js +0 -1
- package/dist/protocol-messages.js +0 -1
- package/dist/protocol-response.js +0 -1
- package/dist/react.js +0 -1
- package/dist/shared/errors.js +0 -1
- package/dist/shared/runtime-controller.d.ts +1 -0
- package/dist/shared/runtime-controller.js +0 -1
- package/dist/shared/runtime-execution.js +0 -1
- package/dist/shared/schema.js +0 -1
- package/dist/storage.js +0 -1
- package/dist/styles.css +70 -2
- package/dist/tool-result.js +0 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.js +0 -1
- package/dist/ui/attachment.aui.js +0 -1
- package/dist/ui/avatar.js +0 -1
- package/dist/ui/button.js +0 -1
- package/dist/ui/code-block.js +0 -1
- package/dist/ui/collapsible.js +0 -1
- package/dist/ui/composer-voice.d.ts +3 -0
- package/dist/ui/composer-voice.js +17 -0
- package/dist/ui/dialog.js +0 -1
- package/dist/ui/dropdown-menu.js +0 -1
- package/dist/ui/home-demo/action-bar.js +0 -1
- package/dist/ui/home-demo/composer.js +1 -2
- package/dist/ui/home-demo/greeting.js +0 -1
- package/dist/ui/home-demo/messages.js +0 -1
- package/dist/ui/home-demo/styles.js +0 -1
- package/dist/ui/home-demo/suggestions.js +0 -1
- package/dist/ui/home-demo/surfaces.js +0 -1
- package/dist/ui/home-demo/thread.js +0 -1
- package/dist/ui/home-demo/trace-line.js +0 -1
- package/dist/ui/home-demo/trace.js +0 -1
- package/dist/ui/home-demo/type.js +0 -1
- package/dist/ui/input.js +0 -1
- package/dist/ui/markdown-text.js +0 -1
- package/dist/ui/reasoning.aui.js +0 -1
- package/dist/ui/reasoning.js +0 -1
- package/dist/ui/surface.js +0 -1
- package/dist/ui/thread-list.aui.js +2 -3
- package/dist/ui/tool-group.aui.js +0 -1
- package/dist/ui/tooltip-icon-button.js +0 -1
- package/dist/ui/tooltip.js +0 -1
- package/dist/ui/use-attachment-src.js +0 -1
- package/dist/ui/use-copy-to-clipboard.js +0 -1
- package/dist/ui/utils.js +0 -1
- package/dist/use-next-message.js +0 -1
- package/dist/voice/types.d.ts +31 -0
- package/dist/voice/types.js +1 -0
- package/dist/voice/use-voice.d.ts +23 -0
- package/dist/voice/use-voice.js +156 -0
- package/package.json +8 -4
- package/dist/assistant-attachments.js.map +0 -1
- package/dist/assistant-components.js.map +0 -1
- package/dist/assistant-runtime.js.map +0 -1
- package/dist/attachments.js.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/config.js.map +0 -1
- package/dist/default-chat.js.map +0 -7
- package/dist/errors.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/messages.js.map +0 -1
- package/dist/page-confirmation.js.map +0 -1
- package/dist/protocol-messages.js.map +0 -1
- package/dist/protocol-response.js.map +0 -1
- package/dist/react.js.map +0 -1
- package/dist/shared/errors.js.map +0 -1
- package/dist/shared/runtime-controller.js.map +0 -1
- package/dist/shared/runtime-execution.js.map +0 -1
- package/dist/shared/schema.js.map +0 -1
- package/dist/storage.js.map +0 -1
- package/dist/tool-result.js.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/ui/attachment.aui.js.map +0 -1
- package/dist/ui/avatar.js.map +0 -1
- package/dist/ui/button.js.map +0 -1
- package/dist/ui/code-block.js.map +0 -1
- package/dist/ui/collapsible.js.map +0 -1
- package/dist/ui/dialog.js.map +0 -1
- package/dist/ui/dropdown-menu.js.map +0 -1
- package/dist/ui/home-demo/action-bar.js.map +0 -1
- package/dist/ui/home-demo/composer.js.map +0 -1
- package/dist/ui/home-demo/greeting.js.map +0 -1
- package/dist/ui/home-demo/messages.js.map +0 -1
- package/dist/ui/home-demo/styles.js.map +0 -1
- package/dist/ui/home-demo/suggestions.js.map +0 -1
- package/dist/ui/home-demo/surfaces.js.map +0 -1
- package/dist/ui/home-demo/thread.js.map +0 -1
- package/dist/ui/home-demo/trace-line.js.map +0 -1
- package/dist/ui/home-demo/trace.js.map +0 -1
- package/dist/ui/home-demo/type.js.map +0 -1
- package/dist/ui/input.js.map +0 -1
- package/dist/ui/markdown-text.js.map +0 -1
- package/dist/ui/reasoning.aui.js.map +0 -1
- package/dist/ui/reasoning.js.map +0 -1
- package/dist/ui/surface.js.map +0 -1
- package/dist/ui/thread-list.aui.js.map +0 -1
- package/dist/ui/tool-group.aui.js.map +0 -1
- package/dist/ui/tooltip-icon-button.js.map +0 -1
- package/dist/ui/tooltip.js.map +0 -1
- package/dist/ui/use-attachment-src.js.map +0 -1
- package/dist/ui/use-copy-to-clipboard.js.map +0 -1
- package/dist/ui/utils.js.map +0 -1
- package/dist/use-next-message.js.map +0 -1
|
@@ -3,9 +3,13 @@ import { AttachmentUI } from "./ui/attachment.aui.js";
|
|
|
3
3
|
import { useEffect, useRef, useState } from "react";
|
|
4
4
|
import { MarkdownText } from "./ui/markdown-text.js";
|
|
5
5
|
import { Composer } from "./ui/home-demo/composer.js";
|
|
6
|
+
import { ComposerVoice } from "./ui/composer-voice.js";
|
|
6
7
|
import { cn } from "./ui/utils.js";
|
|
7
|
-
import { AttachmentPrimitive, ComposerPrimitive, useAuiState, MessagePrimitive, groupPartByType } from "@assistant-ui/react";
|
|
8
|
-
import { ArrowUpIcon, PlusIcon, SquareIcon } from "lucide-react";
|
|
8
|
+
import { AuiIf, AttachmentPrimitive, ComposerPrimitive, useAuiState, MessagePrimitive, groupPartByType } from "@assistant-ui/react";
|
|
9
|
+
import { ArrowUpIcon, PlusIcon, SquareIcon, MicIcon, XIcon } from "lucide-react";
|
|
10
|
+
import { TooltipIconButton } from "./ui/tooltip-icon-button.js";
|
|
11
|
+
import { Button } from "./ui/button.js";
|
|
12
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./ui/tooltip.js";
|
|
9
13
|
import { ToolGroupRoot, ToolGroupContent } from "./ui/tool-group.aui.js";
|
|
10
14
|
import { DisclosureTrigger, ToolCall, disclosureContentClass } from "./ui/home-demo/trace.js";
|
|
11
15
|
import { Reasoning, ReasoningRoot, ReasoningContent, ReasoningText } from "./ui/reasoning.aui.js";
|
|
@@ -19,14 +23,18 @@ export function AttachmentTile({ binding, savedPreview }) {
|
|
|
19
23
|
export function AssistantComposer({ binding, options, placeholder, suggestion, busy, cancelling, cancel }) {
|
|
20
24
|
const input = useRef(null);
|
|
21
25
|
const sending = binding.sending;
|
|
26
|
+
const voiceBusy = binding.voice.status !== "idle";
|
|
27
|
+
const inputDisabled = sending || voiceBusy;
|
|
28
|
+
const voiceDisabledReason = busy ? "任务执行中,暂不能录音" : sending ? "正在处理附件,暂不能录音" : undefined;
|
|
22
29
|
const empty = useAuiState((state) => state.composer.text.length === 0);
|
|
23
|
-
const nextMessage = !busy && !
|
|
30
|
+
const nextMessage = !busy && !inputDisabled && empty ? suggestion : undefined;
|
|
24
31
|
const showCancel = useAuiState((state) => busy && (state.thread.isRunning || state.composer.isEmpty));
|
|
25
32
|
const addFiles = (files) => {
|
|
26
33
|
for (const file of files)
|
|
27
34
|
void binding.runtime.thread.composer.addAttachment(file).catch((error) => binding.setNotice(error instanceof Error ? error.message : String(error)));
|
|
28
35
|
};
|
|
29
|
-
return _jsxs(Composer, { onSubmit: (event) => { event.preventDefault(); void binding.send(); }, inputProps: { "aria-label": "输入 Agent 任务", placeholder: nextMessage ?? placeholder, disabled:
|
|
36
|
+
return _jsxs(Composer, { onSubmit: (event) => { event.preventDefault(); void binding.send(); }, inputProps: { "aria-label": "输入 Agent 任务", placeholder: nextMessage ?? placeholder, disabled: inputDisabled, cancelOnEscape: false,
|
|
37
|
+
addAttachmentOnPaste: !inputDisabled,
|
|
30
38
|
onKeyDown: (event) => {
|
|
31
39
|
if (event.keyCode === 229)
|
|
32
40
|
event.preventDefault();
|
|
@@ -38,8 +46,8 @@ export function AssistantComposer({ binding, options, placeholder, suggestion, b
|
|
|
38
46
|
event.preventDefault();
|
|
39
47
|
void binding.send();
|
|
40
48
|
}
|
|
41
|
-
} }, actions: _jsxs(_Fragment, { children: [options !== false ? _jsxs(_Fragment, { children: [_jsx("input", { ref: input, type: "file", multiple: true, disabled:
|
|
42
|
-
|
|
49
|
+
} }, actions: _jsxs(_Fragment, { children: [voiceBusy ? _jsx("span", { role: "status", className: cn("sr-only"), children: binding.voice.status === "starting" ? "正在准备语音输入,请确认麦克风已授权…" : binding.voice.status === "transcribing" ? "正在识别,请稍候…" : "正在录音" }) : null, voiceBusy ? _jsx(TooltipIconButton, { tooltip: "\u53D6\u6D88\u5F55\u97F3", "aria-label": "\u53D6\u6D88\u8BED\u97F3\u8F93\u5165", className: cn("size-7 shrink-0"), onClick: binding.voice.cancel, children: _jsx(XIcon, { className: cn("size-4") }) }) : options !== false ? _jsxs(_Fragment, { children: [_jsx("input", { ref: input, type: "file", multiple: true, disabled: inputDisabled, accept: options?.accept ?? attachmentAccept, hidden: true, onChange: (event) => { addFiles(Array.from(event.target.files ?? [])); event.target.value = ""; } }), _jsx("button", { type: "button", className: cn("text-muted-foreground hover:text-foreground rounded-control grid size-7 shrink-0 place-items-center transition-colors"), "aria-label": "\u6DFB\u52A0\u9644\u4EF6", disabled: inputDisabled, onClick: () => input.current?.click(), children: _jsx(PlusIcon, { className: cn("size-4") }) })] }) : _jsx("span", {}), voiceBusy ? _jsx(ComposerVoice, { recording: binding.voice.status === "recording" }) : null, _jsxs("div", { className: cn("flex shrink-0 items-center gap-1"), children: [_jsxs(AuiIf, { condition: (state) => state.thread.capabilities.dictation, children: [_jsx(AuiIf, { condition: (state) => state.composer.dictation == null, children: _jsx(TooltipProvider, { delayDuration: 0, children: _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx("span", { className: cn("inline-flex"), tabIndex: voiceDisabledReason ? 0 : undefined, "aria-label": voiceDisabledReason, children: _jsx(ComposerPrimitive.Dictate, { asChild: true, disabled: busy || sending, children: _jsx(Button, { variant: "ghost", size: "icon", "aria-label": "\u5F00\u59CB\u8BED\u97F3\u8F93\u5165", "aria-description": voiceDisabledReason, className: cn("size-7 p-1"), children: _jsx(MicIcon, { className: cn("size-4") }) }) }) }) }), _jsx(TooltipContent, { children: voiceDisabledReason ?? "语音输入" })] }) }) }), _jsx(AuiIf, { condition: (state) => state.composer.dictation != null, children: _jsx(ComposerPrimitive.StopDictation, { asChild: true, disabled: binding.voice.status !== "recording", children: _jsx("button", { type: "button", "aria-label": "\u7ED3\u675F\u8BED\u97F3\u8F93\u5165", title: "\u7ED3\u675F\u5F55\u97F3", className: cn("text-destructive rounded-control grid size-7 place-items-center transition-colors disabled:opacity-50"), children: _jsx(SquareIcon, { className: cn("size-3 animate-pulse fill-current") }) }) }) })] }), showCancel ? _jsx("button", { type: "button", "aria-label": "\u53D6\u6D88\u4EFB\u52A1", className: cn("bg-primary text-primary-foreground rounded-control grid size-7 place-items-center"), disabled: cancelling, onClick: cancel, children: _jsx(SquareIcon, { className: cn("size-3 fill-current") }) }) :
|
|
50
|
+
_jsx(ComposerPrimitive.Send, { asChild: true, disabled: inputDisabled, children: _jsx("button", { type: "button", onClick: (event) => { event.preventDefault(); void binding.send(); }, "aria-label": "\u53D1\u9001\u4EFB\u52A1", className: cn("bg-primary text-primary-foreground rounded-control grid size-7 place-items-center transition-opacity disabled:opacity-40"), children: _jsx(ArrowUpIcon, { className: cn("size-4") }) }) })] })] }), children: [_jsx("div", { ref: (element) => { element?.toggleAttribute("inert", inputDisabled); }, className: cn("aui-composer-attachments flex w-full flex-row items-center gap-2 overflow-x-auto empty:hidden"), children: _jsx(ComposerPrimitive.Attachments, { children: () => _jsx(AttachmentTile, { binding: binding }) }) }), sending ? _jsx("small", { role: "status", children: "\u6B63\u5728\u5904\u7406\u9644\u4EF6\u2026" }) : null] });
|
|
43
51
|
}
|
|
44
52
|
function ToolGroup({ tools, running, count, children }) {
|
|
45
53
|
const errors = tools.flatMap((tool) => tool.type === "tool" && tool.error ? [tool.error] : []);
|
|
@@ -60,7 +68,7 @@ export function AssistantParts({ showDetails, tools = [] }) {
|
|
|
60
68
|
switch (part.type) {
|
|
61
69
|
case "group-chainOfThought": return _jsx("div", { className: cn("mb-3"), children: children });
|
|
62
70
|
case "group-tool": return part.indices.length === 1 ? _jsx(_Fragment, { children: children }) : _jsx(ToolGroup, { tools: tools.filter((_, index) => part.indices.includes(index)), running: part.status.type === "running", count: part.indices.length, children: children });
|
|
63
|
-
case "group-reasoning": return _jsxs(ReasoningRoot, { variant: "ghost", streaming: part.status.type === "running", className: cn("my-1
|
|
71
|
+
case "group-reasoning": return _jsxs(ReasoningRoot, { variant: "ghost", streaming: part.status.type === "running", className: cn("my-1"), children: [_jsx(DisclosureTrigger, { live: part.status.type === "running", label: part.status.type === "running" ? "thinking" : "reasoning" }), _jsx(ReasoningContent, { "aria-busy": part.status.type === "running", className: cn(disclosureContentClass), children: _jsx(ReasoningText, { className: cn("ps-0"), children: children }) })] });
|
|
64
72
|
case "reasoning": return _jsx(Reasoning, { ...part });
|
|
65
73
|
case "group-source":
|
|
66
74
|
case "source": return null;
|
|
@@ -72,4 +80,3 @@ export function AssistantParts({ showDetails, tools = [] }) {
|
|
|
72
80
|
}
|
|
73
81
|
} }) });
|
|
74
82
|
}
|
|
75
|
-
//# sourceMappingURL=assistant-components.js.map
|
|
@@ -3,6 +3,7 @@ import { type AssistantRuntime, type ThreadMessageLike } from "@assistant-ui/rea
|
|
|
3
3
|
import { AssistantAttachments } from "./assistant-attachments.js";
|
|
4
4
|
import { type useChat, type UIMessage } from "./react.js";
|
|
5
5
|
import type { ChatProps } from "./types.js";
|
|
6
|
+
import { type VoiceComposerState } from "./voice/use-voice.js";
|
|
6
7
|
type ChatState = ReturnType<typeof useChat>;
|
|
7
8
|
export type AssistantBinding = {
|
|
8
9
|
runtime: AssistantRuntime;
|
|
@@ -10,16 +11,19 @@ export type AssistantBinding = {
|
|
|
10
11
|
notice: string;
|
|
11
12
|
setNotice(message: string): void;
|
|
12
13
|
sending: boolean;
|
|
14
|
+
voice: VoiceComposerState;
|
|
13
15
|
send(): Promise<void>;
|
|
14
16
|
};
|
|
15
17
|
export declare function convertMessage(message: UIMessage): ThreadMessageLike;
|
|
16
18
|
export declare function projectMessages(messages: readonly UIMessage[]): UIMessage[];
|
|
17
|
-
export declare function SessionRuntime({ id, chat, options, blocked, active, onEdit, children }: {
|
|
19
|
+
export declare function SessionRuntime({ id, chat, options, dictation, open, blocked, active, onEdit, children }: {
|
|
18
20
|
id: string;
|
|
19
21
|
chat: ChatState;
|
|
20
22
|
options: ChatProps["attachments"];
|
|
21
23
|
blocked: boolean;
|
|
22
24
|
active: boolean;
|
|
25
|
+
dictation?: ChatProps["dictation"];
|
|
26
|
+
open?: boolean;
|
|
23
27
|
onEdit?(sourceId: string, text: string): Promise<void>;
|
|
24
28
|
children(binding: AssistantBinding): ReactNode;
|
|
25
29
|
}): import("react").JSX.Element;
|
|
@@ -3,6 +3,7 @@ import { useEffect, useLayoutEffect, useReducer, useRef, useState } from "react"
|
|
|
3
3
|
import { AssistantRuntimeProvider, MessageNotSentError, useExternalStoreRuntime } from "@assistant-ui/react";
|
|
4
4
|
import { AssistantAttachments, toAssistantAttachment } from "./assistant-attachments.js";
|
|
5
5
|
import { assertChatSendable } from "./react.js";
|
|
6
|
+
import { useVoiceInput } from "./voice/use-voice.js";
|
|
6
7
|
function parseToolArgs(text) {
|
|
7
8
|
try {
|
|
8
9
|
const value = JSON.parse(text);
|
|
@@ -40,7 +41,7 @@ export function projectMessages(messages) {
|
|
|
40
41
|
}
|
|
41
42
|
// Keep one composer per visited Session: switching the external-store thread id
|
|
42
43
|
// would invalidate pending attachment work and discard that Session's draft.
|
|
43
|
-
export function SessionRuntime({ id, chat, options, blocked, active, onEdit, children }) {
|
|
44
|
+
export function SessionRuntime({ id, chat, options, dictation, open = true, blocked, active, onEdit, children }) {
|
|
44
45
|
const latest = useRef(chat);
|
|
45
46
|
useLayoutEffect(() => { latest.current = chat; });
|
|
46
47
|
const messages = useRef([]);
|
|
@@ -53,6 +54,8 @@ export function SessionRuntime({ id, chat, options, blocked, active, onEdit, chi
|
|
|
53
54
|
const [attachments] = useState(() => new AssistantAttachments(refresh, setNotice));
|
|
54
55
|
attachments.options = options ?? {};
|
|
55
56
|
const alive = useRef(false);
|
|
57
|
+
const voice = useVoiceInput({ dictation, active, open, blocked: blocked || sending || attachments.blocked,
|
|
58
|
+
sessionId: id, composer: () => runtime.thread.composer, notice: setNotice });
|
|
56
59
|
useEffect(() => {
|
|
57
60
|
alive.current = true;
|
|
58
61
|
return () => {
|
|
@@ -65,7 +68,7 @@ export function SessionRuntime({ id, chat, options, blocked, active, onEdit, chi
|
|
|
65
68
|
messages: projectMessages(messages.current),
|
|
66
69
|
convertMessage,
|
|
67
70
|
isRunning: active && chat.status !== "idle" && chat.status !== "error" && chat.status !== "waiting",
|
|
68
|
-
isSendDisabled: !active || blocked || attachments.blocked,
|
|
71
|
+
isSendDisabled: !active || blocked || attachments.blocked || voice.state.status !== "idle",
|
|
69
72
|
onNew: async (message) => {
|
|
70
73
|
if (!alive.current || latest.current.activeSessionId !== id)
|
|
71
74
|
throw new MessageNotSentError("会话已切换,请返回原会话重新发送。");
|
|
@@ -96,6 +99,7 @@ export function SessionRuntime({ id, chat, options, blocked, active, onEdit, chi
|
|
|
96
99
|
} : undefined,
|
|
97
100
|
onCancel: async () => { latest.current.cancel(); },
|
|
98
101
|
adapters: {
|
|
102
|
+
dictation: voice.dictation,
|
|
99
103
|
attachments: options === false ? undefined : attachments,
|
|
100
104
|
threadList: {
|
|
101
105
|
threadId: id,
|
|
@@ -109,7 +113,7 @@ export function SessionRuntime({ id, chat, options, blocked, active, onEdit, chi
|
|
|
109
113
|
});
|
|
110
114
|
const send = async () => {
|
|
111
115
|
const draft = runtime.thread.composer.getState();
|
|
112
|
-
if (!active || blocked || attachments.blocked || sendLock.current || draft.isEmpty)
|
|
116
|
+
if (!active || blocked || attachments.blocked || sendLock.current || voice.state.status !== "idle" || draft.isEmpty)
|
|
113
117
|
return;
|
|
114
118
|
sendLock.current = true;
|
|
115
119
|
setSending(true);
|
|
@@ -142,6 +146,5 @@ export function SessionRuntime({ id, chat, options, blocked, active, onEdit, chi
|
|
|
142
146
|
setSending(false);
|
|
143
147
|
}
|
|
144
148
|
};
|
|
145
|
-
return _jsx(AssistantRuntimeProvider, { runtime: runtime, children: active ? children({ runtime, attachments, notice, setNotice, sending, send }) : null });
|
|
149
|
+
return _jsx(AssistantRuntimeProvider, { runtime: runtime, children: active ? children({ runtime, attachments, notice, setNotice, sending, voice: voice.state, send }) : null });
|
|
146
150
|
}
|
|
147
|
-
//# sourceMappingURL=assistant-runtime.js.map
|
package/dist/attachments.js
CHANGED
package/dist/client.js
CHANGED
package/dist/config.js
CHANGED
package/dist/default-chat.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type ReactElement } from "react";
|
|
2
2
|
import type { ChatProps } from "./types.js";
|
|
3
|
-
export declare function Chat({ title, avatar, welcomeMessage, welcomeDescription, open, onOpenChange, placeholder, layout, side, className, style, suggestions, suggestNextMessage, attachments, sessionSidebar, showToolDetails, onFullscreenChange, onRunResult }: ChatProps): ReactElement | null;
|
|
3
|
+
export declare function Chat({ title, avatar, welcomeMessage, welcomeDescription, open, onOpenChange, placeholder, layout, side, className, style, suggestions, suggestNextMessage, attachments, dictation, sessionSidebar, showToolDetails, onFullscreenChange, onRunResult }: ChatProps): ReactElement | null;
|