@nexface/chat 0.1.13-alpha.2 → 0.1.13
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-components.js +15 -7
- package/dist/assistant-components.js.map +1 -1
- package/dist/assistant-runtime.d.ts +5 -1
- package/dist/assistant-runtime.js +8 -4
- package/dist/assistant-runtime.js.map +1 -1
- package/dist/default-chat.d.ts +1 -1
- package/dist/default-chat.js +614 -346
- package/dist/default-chat.js.map +4 -4
- package/dist/shared/runtime-controller.d.ts +0 -1
- package/dist/shared/runtime-controller.js.map +1 -1
- package/dist/styles.css +70 -2
- package/dist/types.d.ts +2 -0
- package/dist/types.js.map +1 -1
- package/dist/ui/composer-voice.d.ts +3 -0
- package/dist/ui/composer-voice.js +18 -0
- package/dist/ui/composer-voice.js.map +1 -0
- package/dist/ui/home-demo/composer.js +1 -1
- package/dist/ui/home-demo/composer.js.map +1 -1
- package/dist/ui/thread-list.aui.js +2 -2
- package/dist/ui/thread-list.aui.js.map +1 -1
- package/dist/voice/types.d.ts +31 -0
- package/dist/voice/types.js +2 -0
- package/dist/voice/types.js.map +1 -0
- package/dist/voice/use-voice.d.ts +23 -0
- package/dist/voice/use-voice.js +157 -0
- package/dist/voice/use-voice.js.map +1 -0
- package/package.json +3 -3
|
@@ -12,7 +12,6 @@ interface OperationSnapshot {
|
|
|
12
12
|
readonly taskProgress?: TaskProgress;
|
|
13
13
|
}
|
|
14
14
|
export interface RuntimeController {
|
|
15
|
-
getRegisteredTools(): ReturnType<ToolRuntime["getTools"]>;
|
|
16
15
|
beginInternalOperation(options?: {
|
|
17
16
|
signal?: AbortSignal;
|
|
18
17
|
onCancel?: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-controller.js","sourceRoot":"","sources":["../../src/shared/runtime-controller.ts"],"names":[],"mappings":"AAAA,qEAAqE;AAGrE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"runtime-controller.js","sourceRoot":"","sources":["../../src/shared/runtime-controller.ts"],"names":[],"mappings":"AAAA,qEAAqE;AAGrE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAuB7C,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;AAEvF,MAAM,UAAU,oBAAoB,CAAC,OAAoB;IACvD,MAAM,UAAU,GAAI,OAA2E,CAAC,uBAAuB,CAAC,CAAC;IACzH,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,cAAc,CAAC,sBAAsB,EAAE,iGAAiG,CAAC,CAAC;IACtJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["// Generated from shared/runtime-controller.ts. Do not edit manually.\n\nimport type { ToolOperation, ToolRuntime } from \"@nexface/tools\";\nimport { AgentToolError } from \"./errors.js\";\n\nexport type TaskProgress = { readonly phase: \"processing\" } | { readonly phase: \"tool\"; readonly toolCallId: string; readonly progressLabel?: string };\n\ninterface OperationSnapshot {\n readonly id: string;\n readonly status: \"running\" | \"waiting\" | \"cancelling\" | \"ending\";\n readonly taskProgress?: TaskProgress;\n}\n\nexport interface RuntimeController {\n beginInternalOperation(options?: {\n signal?: AbortSignal;\n onCancel?: () => void;\n replaceWaiting?: ToolOperation;\n taskProgress?: TaskProgress;\n }): ToolOperation;\n setOperationWaiting(handle: ToolOperation, waiting: boolean): void;\n setTaskProgress(handle: ToolOperation, progress: TaskProgress): void;\n getOperationSnapshot(): OperationSnapshot | null;\n subscribeOperation(listener: () => void): () => void;\n}\n\nexport const runtimeControllerSymbol = Symbol.for(\"@nexface/tools/runtime-controller\");\n\nexport function getRuntimeController(runtime: ToolRuntime): RuntimeController {\n const controller = (runtime as ToolRuntime & { [runtimeControllerSymbol]?: RuntimeController })[runtimeControllerSymbol];\n if (!controller) {\n throw new AgentToolError(\"INVALID_TOOL_RUNTIME\", \"ToolRuntime does not support internal task coordination. Use matching Nexface package versions.\");\n }\n return controller;\n}\n"]}
|
package/dist/styles.css
CHANGED
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
--nxf-radius-xs: .125rem;
|
|
25
25
|
--nxf-radius-xl: .75rem;
|
|
26
26
|
--nxf-animate-spin: nxf-spin 1s linear infinite;
|
|
27
|
+
--nxf-animate-pulse: nxf-pulse 2s cubic-bezier(.4, 0, .6, 1) infinite;
|
|
27
28
|
--nxf-blur-sm: 8px;
|
|
28
29
|
--nxf-default-transition-duration: .15s;
|
|
29
30
|
--nxf-default-transition-timing-function: cubic-bezier(.4, 0, .2, 1);
|
|
@@ -535,6 +536,9 @@
|
|
|
535
536
|
.nexface-ui .nxf-me-1\.5 {
|
|
536
537
|
margin-inline-end: calc(var(--nxf-spacing) * 1.5);
|
|
537
538
|
}
|
|
539
|
+
.nexface-ui .nxf--mt-1 {
|
|
540
|
+
margin-top: calc(var(--nxf-spacing) * -1);
|
|
541
|
+
}
|
|
538
542
|
.nexface-ui .nxf-mt-1 {
|
|
539
543
|
margin-top: var(--nxf-spacing);
|
|
540
544
|
}
|
|
@@ -556,6 +560,9 @@
|
|
|
556
560
|
.nexface-ui .nxf-mt-auto {
|
|
557
561
|
margin-top: auto;
|
|
558
562
|
}
|
|
563
|
+
.nexface-ui .nxf--mr-1 {
|
|
564
|
+
margin-right: calc(var(--nxf-spacing) * -1);
|
|
565
|
+
}
|
|
559
566
|
.nexface-ui .nxf-mb-1 {
|
|
560
567
|
margin-bottom: var(--nxf-spacing);
|
|
561
568
|
}
|
|
@@ -706,6 +713,9 @@
|
|
|
706
713
|
.nexface-ui .nxf-min-h-12 {
|
|
707
714
|
min-height: calc(var(--nxf-spacing) * 12);
|
|
708
715
|
}
|
|
716
|
+
.nexface-ui .nxf-w-0\.5 {
|
|
717
|
+
width: calc(var(--nxf-spacing) * .5);
|
|
718
|
+
}
|
|
709
719
|
.nexface-ui .nxf-w-1\.5 {
|
|
710
720
|
width: calc(var(--nxf-spacing) * 1.5);
|
|
711
721
|
}
|
|
@@ -789,6 +799,9 @@
|
|
|
789
799
|
.nexface-ui .nxf-animate-in {
|
|
790
800
|
animation: nxf-enter var(--nxf-tw-animation-duration, var(--nxf-tw-duration, .15s))var(--nxf-tw-ease, ease)var(--nxf-tw-animation-delay, 0s)var(--nxf-tw-animation-iteration-count, 1)var(--nxf-tw-animation-direction, normal)var(--nxf-tw-animation-fill-mode, none);
|
|
791
801
|
}
|
|
802
|
+
.nexface-ui .nxf-animate-pulse {
|
|
803
|
+
animation: var(--nxf-animate-pulse);
|
|
804
|
+
}
|
|
792
805
|
.nexface-ui .nxf-animate-spin {
|
|
793
806
|
animation: var(--nxf-animate-spin);
|
|
794
807
|
}
|
|
@@ -843,6 +856,9 @@
|
|
|
843
856
|
.nexface-ui .nxf-items-end {
|
|
844
857
|
align-items: flex-end;
|
|
845
858
|
}
|
|
859
|
+
.nexface-ui .nxf-items-start {
|
|
860
|
+
align-items: flex-start;
|
|
861
|
+
}
|
|
846
862
|
.nexface-ui .nxf-justify-between {
|
|
847
863
|
justify-content: space-between;
|
|
848
864
|
}
|
|
@@ -1059,7 +1075,23 @@
|
|
|
1059
1075
|
.nexface-ui .nxf-bg-destructive {
|
|
1060
1076
|
background-color: oklch(57.7% .245 27.325);
|
|
1061
1077
|
}
|
|
1062
|
-
.nexface-ui .nxf-bg-foreground,.nexface-ui .nxf-bg-foreground
|
|
1078
|
+
.nexface-ui .nxf-bg-foreground,.nexface-ui .nxf-bg-foreground\/25 {
|
|
1079
|
+
background-color: var(--nxf-foreground);
|
|
1080
|
+
}
|
|
1081
|
+
@supports (color: color-mix(in lab, red, red)) {
|
|
1082
|
+
.nexface-ui .nxf-bg-foreground\/25 {
|
|
1083
|
+
background-color: color-mix(in oklab, var(--nxf-foreground) 25%, transparent);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
.nexface-ui .nxf-bg-foreground\/50 {
|
|
1087
|
+
background-color: var(--nxf-foreground);
|
|
1088
|
+
}
|
|
1089
|
+
@supports (color: color-mix(in lab, red, red)) {
|
|
1090
|
+
.nexface-ui .nxf-bg-foreground\/50 {
|
|
1091
|
+
background-color: color-mix(in oklab, var(--nxf-foreground) 50%, transparent);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
.nexface-ui .nxf-bg-foreground\/\[0\.025\] {
|
|
1063
1095
|
background-color: var(--nxf-foreground);
|
|
1064
1096
|
}
|
|
1065
1097
|
@supports (color: color-mix(in lab, red, red)) {
|
|
@@ -1345,6 +1377,9 @@
|
|
|
1345
1377
|
.nexface-ui .nxf-text-pretty {
|
|
1346
1378
|
text-wrap: pretty;
|
|
1347
1379
|
}
|
|
1380
|
+
.nexface-ui .nxf-break-words {
|
|
1381
|
+
overflow-wrap: break-word;
|
|
1382
|
+
}
|
|
1348
1383
|
.nexface-ui .nxf-wrap-anywhere {
|
|
1349
1384
|
overflow-wrap: anywhere;
|
|
1350
1385
|
}
|
|
@@ -1450,6 +1485,11 @@
|
|
|
1450
1485
|
transition-timing-function: var(--nxf-tw-ease, var(--nxf-default-transition-timing-function));
|
|
1451
1486
|
transition-duration: var(--nxf-tw-duration, var(--nxf-default-transition-duration));
|
|
1452
1487
|
}
|
|
1488
|
+
.nexface-ui .nxf-transition-\[height\,background-color\] {
|
|
1489
|
+
transition-property: height, background-color;
|
|
1490
|
+
transition-timing-function: var(--nxf-tw-ease, var(--nxf-default-transition-timing-function));
|
|
1491
|
+
transition-duration: var(--nxf-tw-duration, var(--nxf-default-transition-duration));
|
|
1492
|
+
}
|
|
1453
1493
|
.nexface-ui .nxf-transition-\[transform\,opacity\] {
|
|
1454
1494
|
transition-property: transform, opacity;
|
|
1455
1495
|
transition-timing-function: var(--nxf-tw-ease, var(--nxf-default-transition-timing-function));
|
|
@@ -1829,7 +1869,15 @@
|
|
|
1829
1869
|
}
|
|
1830
1870
|
}
|
|
1831
1871
|
|
|
1832
|
-
.nexface-ui .nxf-hover\:text-accent-foreground:hover
|
|
1872
|
+
.nexface-ui .nxf-hover\:text-accent-foreground:hover {
|
|
1873
|
+
color: var(--nxf-foreground);
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
.nexface-ui .nxf-hover\:text-destructive:hover {
|
|
1877
|
+
color: oklch(57.7% .245 27.325);
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1880
|
+
.nexface-ui .nxf-hover\:text-foreground:hover {
|
|
1833
1881
|
color: var(--nxf-foreground);
|
|
1834
1882
|
}
|
|
1835
1883
|
|
|
@@ -1910,6 +1958,10 @@
|
|
|
1910
1958
|
--nxf-tw-ring-shadow: var(--nxf-tw-ring-inset, ) 0 0 0 calc(1px + var(--nxf-tw-ring-offset-width)) var(--nxf-tw-ring-color, currentcolor);
|
|
1911
1959
|
box-shadow: var(--nxf-tw-inset-shadow), var(--nxf-tw-inset-ring-shadow), var(--nxf-tw-ring-offset-shadow), var(--nxf-tw-ring-shadow), var(--nxf-tw-shadow);
|
|
1912
1960
|
}
|
|
1961
|
+
.nexface-ui .nxf-focus-visible\:ring-2:focus-visible {
|
|
1962
|
+
--nxf-tw-ring-shadow: var(--nxf-tw-ring-inset, ) 0 0 0 calc(2px + var(--nxf-tw-ring-offset-width)) var(--nxf-tw-ring-color, currentcolor);
|
|
1963
|
+
box-shadow: var(--nxf-tw-inset-shadow), var(--nxf-tw-inset-ring-shadow), var(--nxf-tw-ring-offset-shadow), var(--nxf-tw-ring-shadow), var(--nxf-tw-shadow);
|
|
1964
|
+
}
|
|
1913
1965
|
.nexface-ui .nxf-focus-visible\:ring-\[3px\]:focus-visible {
|
|
1914
1966
|
--nxf-tw-ring-shadow: var(--nxf-tw-ring-inset, ) 0 0 0 calc(3px + var(--nxf-tw-ring-offset-width)) var(--nxf-tw-ring-color, currentcolor);
|
|
1915
1967
|
box-shadow: var(--nxf-tw-inset-shadow), var(--nxf-tw-inset-ring-shadow), var(--nxf-tw-ring-offset-shadow), var(--nxf-tw-ring-shadow), var(--nxf-tw-shadow);
|
|
@@ -1917,6 +1969,9 @@
|
|
|
1917
1969
|
.nexface-ui .nxf-focus-visible\:ring-destructive\/20:focus-visible {
|
|
1918
1970
|
--nxf-tw-ring-color: oklab(57.7% .217662 .112464 / .2);
|
|
1919
1971
|
}
|
|
1972
|
+
.nexface-ui .nxf-focus-visible\:ring-destructive\/30:focus-visible {
|
|
1973
|
+
--nxf-tw-ring-color: oklab(57.7% .217662 .112464 / .3);
|
|
1974
|
+
}
|
|
1920
1975
|
.nexface-ui .nxf-focus-visible\:ring-ring\/50:focus-visible {
|
|
1921
1976
|
--nxf-tw-ring-color: oklab(70.8% -.00165382 .00576757 / .5);
|
|
1922
1977
|
}
|
|
@@ -1935,6 +1990,10 @@
|
|
|
1935
1990
|
outline-color: color-mix(in oklab, var(--nxf-foreground) 20%, transparent);
|
|
1936
1991
|
}
|
|
1937
1992
|
}
|
|
1993
|
+
.nexface-ui .nxf-focus-visible\:outline-none:focus-visible {
|
|
1994
|
+
--nxf-tw-outline-style: none;
|
|
1995
|
+
outline-style: none;
|
|
1996
|
+
}
|
|
1938
1997
|
.nexface-ui .nxf-active\:scale-90:active {
|
|
1939
1998
|
--nxf-tw-scale-x: 90%;
|
|
1940
1999
|
--nxf-tw-scale-y: 90%;
|
|
@@ -2119,6 +2178,10 @@
|
|
|
2119
2178
|
font-size: var(--nxf-text-sm);
|
|
2120
2179
|
line-height: var(--nxf-tw-leading, var(--nxf-text-sm--line-height));
|
|
2121
2180
|
}
|
|
2181
|
+
|
|
2182
|
+
.nexface-ui .nxf-md\:text-\[13px\] {
|
|
2183
|
+
font-size: 13px;
|
|
2184
|
+
}
|
|
2122
2185
|
}
|
|
2123
2186
|
@media (min-width: 64rem) {
|
|
2124
2187
|
.nexface-ui .nxf-lg\:text-\[1\.75rem\] {
|
|
@@ -2877,6 +2940,11 @@
|
|
|
2877
2940
|
to {
|
|
2878
2941
|
transform: rotate(360deg);
|
|
2879
2942
|
}
|
|
2943
|
+
}
|
|
2944
|
+
@keyframes nxf-pulse {
|
|
2945
|
+
50% {
|
|
2946
|
+
opacity: .5;
|
|
2947
|
+
}
|
|
2880
2948
|
}
|
|
2881
2949
|
@keyframes nxf-enter {
|
|
2882
2950
|
from {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AgentRunResult } from "@nexface/agent";
|
|
2
2
|
import type { CSSProperties } from "react";
|
|
3
|
+
import type { ChatDictation } from "./voice/types.js";
|
|
3
4
|
export type ChatRunResult = Extract<AgentRunResult, {
|
|
4
5
|
outcome: {
|
|
5
6
|
type: "success";
|
|
@@ -10,6 +11,7 @@ export interface ChatSuggestion {
|
|
|
10
11
|
readonly prompt: string;
|
|
11
12
|
}
|
|
12
13
|
export interface ChatProps {
|
|
14
|
+
dictation?: false | ChatDictation | undefined;
|
|
13
15
|
open?: boolean;
|
|
14
16
|
onOpenChange?: (open: boolean) => void;
|
|
15
17
|
sessionSidebar?: boolean | {
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AgentRunResult } from \"@nexface/agent\";\nimport type { CSSProperties } from \"react\";\nexport type ChatRunResult = Extract<AgentRunResult, { outcome: { type: \"success\" } }>;\n\nexport interface ChatSuggestion {\n readonly label: string;\n readonly prompt: string;\n}\n\nexport interface ChatProps {\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n sessionSidebar?: boolean | { layout?: \"overlay\" | \"outside\" };\n showToolDetails?: boolean;\n onFullscreenChange?: (fullscreen: boolean) => void;\n avatar?: string;\n welcomeDescription?: string;\n side?: \"left\" | \"right\";\n className?: string;\n style?: CSSProperties;\n attachments?: false | ChatAttachmentOptions;\n title?: string;\n welcomeMessage?: string;\n placeholder?: string;\n layout?: \"floating\" | \"docked\" | \"inline\";\n suggestions?: readonly ChatSuggestion[];\n suggestNextMessage?: (input: {\n sessionId: string;\n messages: readonly { role: \"user\" | \"assistant\"; parts: readonly { type: \"text\"; text: string }[] }[];\n signal: AbortSignal;\n }) => string | undefined | Promise<string | undefined>;\n onRunResult?: (result: ChatRunResult) => void;\n}\n\nexport interface ChatAttachmentOptions {\n accept?: string;\n maxCount?: number;\n maxSizeBytes?: number;\n adapter?: {\n add(input: { id: string; file: File; signal: AbortSignal }): Promise<{ data?: unknown; preview?: string }>;\n send(input: { id: string; file: File; data?: unknown; signal: AbortSignal }): Promise<{\n content: readonly ({ type: \"text\"; text: string } | { type: \"image\"; source: { type: \"data\"; value: string; mimeType: string } })[];\n }>;\n remove?(input: { id: string; file: File; data?: unknown }): void | Promise<void>;\n };\n}\n\nexport type { AgentModelConfig, AgentModelInfo } from \"@nexface/agent\";\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { AgentRunResult } from \"@nexface/agent\";\nimport type { CSSProperties } from \"react\";\nimport type { ChatDictation } from \"./voice/types.js\";\nexport type ChatRunResult = Extract<AgentRunResult, { outcome: { type: \"success\" } }>;\n\nexport interface ChatSuggestion {\n readonly label: string;\n readonly prompt: string;\n}\n\nexport interface ChatProps {\n dictation?: false | ChatDictation | undefined;\n open?: boolean;\n onOpenChange?: (open: boolean) => void;\n sessionSidebar?: boolean | { layout?: \"overlay\" | \"outside\" };\n showToolDetails?: boolean;\n onFullscreenChange?: (fullscreen: boolean) => void;\n avatar?: string;\n welcomeDescription?: string;\n side?: \"left\" | \"right\";\n className?: string;\n style?: CSSProperties;\n attachments?: false | ChatAttachmentOptions;\n title?: string;\n welcomeMessage?: string;\n placeholder?: string;\n layout?: \"floating\" | \"docked\" | \"inline\";\n suggestions?: readonly ChatSuggestion[];\n suggestNextMessage?: (input: {\n sessionId: string;\n messages: readonly { role: \"user\" | \"assistant\"; parts: readonly { type: \"text\"; text: string }[] }[];\n signal: AbortSignal;\n }) => string | undefined | Promise<string | undefined>;\n onRunResult?: (result: ChatRunResult) => void;\n}\n\nexport interface ChatAttachmentOptions {\n accept?: string;\n maxCount?: number;\n maxSizeBytes?: number;\n adapter?: {\n add(input: { id: string; file: File; signal: AbortSignal }): Promise<{ data?: unknown; preview?: string }>;\n send(input: { id: string; file: File; data?: unknown; signal: AbortSignal }): Promise<{\n content: readonly ({ type: \"text\"; text: string } | { type: \"image\"; source: { type: \"data\"; value: string; mimeType: string } })[];\n }>;\n remove?(input: { id: string; file: File; data?: unknown }): void | Promise<void>;\n };\n}\n\nexport type { AgentModelConfig, AgentModelInfo } from \"@nexface/agent\";\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Adapted from assistant-ui Elements ComposerVoice (18f03fec45d406b0285ccc4165f6db143ba87c7d).
|
|
3
|
+
// https://github.com/assistant-ui/assistant-ui/blob/18f03fec45d406b0285ccc4165f6db143ba87c7d/packages/ui/src/components/react/assistant-ui/elements/composer.tsx
|
|
4
|
+
// Keep the upstream illustrative waveform without exposing microphone-level APIs.
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
import { cn } from "./utils.js";
|
|
7
|
+
const barCount = 64;
|
|
8
|
+
export function ComposerVoice({ recording }) {
|
|
9
|
+
const [tick, setTick] = useState(0);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!recording)
|
|
12
|
+
return;
|
|
13
|
+
const timer = setInterval(() => setTick((value) => value + 1), 100);
|
|
14
|
+
return () => clearInterval(timer);
|
|
15
|
+
}, [recording]);
|
|
16
|
+
return _jsx("div", { "data-slot": "composer-voice", "data-recording": recording || undefined, className: cn("flex h-7 min-w-0 flex-1 items-center overflow-hidden px-2"), children: _jsx("div", { className: cn("flex h-6 w-full items-center justify-between overflow-hidden"), "aria-hidden": true, children: Array.from({ length: barCount }, (_, index) => _jsx("span", { className: cn("w-0.5 shrink-0 rounded-full transition-[height,background-color] duration-150 motion-reduce:transition-none", recording ? "bg-foreground/50" : "bg-foreground/25"), style: { height: recording ? 5 + Math.abs(Math.sin(index * 1.35 + tick * 0.55)) * 13 : 3 } }, index)) }) });
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=composer-voice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composer-voice.js","sourceRoot":"","sources":["../../src/ui/composer-voice.tsx"],"names":[],"mappings":";AAAA,+FAA+F;AAC/F,iKAAiK;AACjK,kFAAkF;AAClF,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAEhC,MAAM,QAAQ,GAAG,EAAE,CAAC;AAEpB,MAAM,UAAU,aAAa,CAAC,EAAE,SAAS,EAA0B;IACjE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IACpC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,SAAS;YAAE,OAAO;QACvB,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;QACpE,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAChB,OAAO,2BAAe,gBAAgB,oBAAiB,SAAS,IAAI,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,2DAA2D,CAAC,YACvJ,cAAK,SAAS,EAAE,EAAE,CAAC,8DAA8D,CAAC,iCAC/E,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,eAC9C,SAAS,EAAE,EAAE,CAAC,6GAA6G,EAAE,SAAS,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,kBAAkB,CAAC,EACjL,KAAK,EAAE,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAFjC,KAAK,CAEgC,CAAC,GAC7F,GACF,CAAC;AACT,CAAC","sourcesContent":["// Adapted from assistant-ui Elements ComposerVoice (18f03fec45d406b0285ccc4165f6db143ba87c7d).\n// https://github.com/assistant-ui/assistant-ui/blob/18f03fec45d406b0285ccc4165f6db143ba87c7d/packages/ui/src/components/react/assistant-ui/elements/composer.tsx\n// Keep the upstream illustrative waveform without exposing microphone-level APIs.\nimport { useEffect, useState } from \"react\";\nimport { cn } from \"./utils.js\";\n\nconst barCount = 64;\n\nexport function ComposerVoice({ recording }: { recording: boolean }) {\n const [tick, setTick] = useState(0);\n useEffect(() => {\n if (!recording) return;\n const timer = setInterval(() => setTick((value) => value + 1), 100);\n return () => clearInterval(timer);\n }, [recording]);\n return <div data-slot=\"composer-voice\" data-recording={recording || undefined} className={cn(\"flex h-7 min-w-0 flex-1 items-center overflow-hidden px-2\")}>\n <div className={cn(\"flex h-6 w-full items-center justify-between overflow-hidden\")} aria-hidden>\n {Array.from({ length: barCount }, (_, index) => <span key={index}\n className={cn(\"w-0.5 shrink-0 rounded-full transition-[height,background-color] duration-150 motion-reduce:transition-none\", recording ? \"bg-foreground/50\" : \"bg-foreground/25\")}\n style={{ height: recording ? 5 + Math.abs(Math.sin(index * 1.35 + tick * 0.55)) * 13 : 3 }} />)}\n </div>\n </div>;\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import { cn } from "../utils.js";
|
|
|
4
4
|
export function Composer({ children, inputProps, actions, ...props }) {
|
|
5
5
|
return (_jsx(ComposerPrimitive.Root, { className: cn("relative w-full"), ...props, children: _jsx(ComposerPrimitive.AttachmentDropzone, { asChild: true, disabled: inputProps.disabled, onDropCapture: (event) => { if (inputProps.disabled)
|
|
6
6
|
event.preventDefault(); }, onDragOverCapture: (event) => { if (inputProps.disabled)
|
|
7
|
-
event.preventDefault(); }, children: _jsxs("div", { "data-slot": "aui_composer-shell", className: cn("border-foreground/10 bg-muted/30 focus-within:border-foreground/25 data-[dragging=true]:border-foreground/40 rounded-thread flex flex-col border transition-colors data-[dragging=true]:border-dashed"), children: [_jsx("div", { className: cn("has-[.aui-attachment-root]:px-3 has-[.aui-attachment-root]:pt-3"), children: children }), _jsx(ComposerPrimitive.Input, { asChild: true, ...inputProps, children: _jsx("textarea", { "data-composer-input": true, rows: 1, className: cn("placeholder:text-muted-foreground field-sizing-content max-h-48 w-full resize-none bg-transparent px-4 pt-3 pb-2 text-base leading-6 focus:outline-none") }) }), _jsx("div", { className: cn("flex items-center justify-between gap-2 px-2 pb-2"), children: actions })] }) }) }));
|
|
7
|
+
event.preventDefault(); }, children: _jsxs("div", { "data-slot": "aui_composer-shell", className: cn("border-foreground/10 bg-muted/30 focus-within:border-foreground/25 data-[dragging=true]:border-foreground/40 rounded-thread flex flex-col border transition-colors data-[dragging=true]:border-dashed"), children: [_jsx("div", { className: cn("has-[.aui-attachment-root]:px-3 has-[.aui-attachment-root]:pt-3"), children: children }), _jsx(ComposerPrimitive.Input, { asChild: true, ...inputProps, children: _jsx("textarea", { "data-composer-input": true, rows: 1, className: cn("placeholder:text-muted-foreground field-sizing-content block max-h-48 w-full resize-none bg-transparent px-4 pt-3 pb-2 text-base leading-6 focus:outline-none") }) }), _jsx("div", { className: cn("flex items-center justify-between gap-2 px-2 pb-2"), children: actions })] }) }) }));
|
|
8
8
|
}
|
|
9
9
|
export function EditComposer({ children, inputProps, cancelProps, sendProps, ...props }) {
|
|
10
10
|
return (_jsx(MessagePrimitive.Root, { "data-role": "user", "data-slot": "aui_edit-composer-wrapper", className: cn("mx-auto flex w-full max-w-(--nxf-thread-max-width) flex-col items-end"), children: _jsxs(ComposerPrimitive.Root, { className: cn("border-foreground/10 bg-muted/30 focus-within:border-foreground/25 rounded-thread flex w-full max-w-[85%] flex-col border transition-colors"), ...props, children: [_jsx(ComposerPrimitive.Input, { asChild: true, ...inputProps, children: _jsx("textarea", { autoFocus: true, rows: 1, className: cn("field-sizing-content max-h-48 min-h-12 w-full resize-none bg-transparent px-4 pt-3.5 pb-1 text-[15px] leading-6 focus:outline-none") }) }), children, _jsxs("div", { className: cn("flex items-center justify-end gap-1.5 px-2.5 pb-2.5"), children: [_jsx(ComposerPrimitive.Cancel, { asChild: true, children: _jsx("button", { type: "button", ...cancelProps, className: cn("text-muted-foreground hover:text-foreground rounded-control h-8 px-3 text-[13px] transition-colors"), children: "\u53D6\u6D88" }) }), _jsx(ComposerPrimitive.Send, { asChild: true, children: _jsx("button", { type: "button", ...sendProps, className: cn("bg-primary text-primary-foreground rounded-control h-8 px-3 text-[13px] font-medium transition-opacity disabled:opacity-40"), children: "\u4FDD\u5B58\u5E76\u91CD\u65B0\u53D1\u9001" }) })] })] }) }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"composer.js","sourceRoot":"","sources":["../../../src/ui/home-demo/composer.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC1E,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,MAAM,UAAU,QAAQ,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,KAAK,EAEjE;IACC,OAAO,CACL,KAAC,iBAAiB,CAAC,IAAI,IAAC,SAAS,EAAE,EAAE,CAAC,iBAAiB,CAAC,KAAO,KAAK,YAClE,KAAC,iBAAiB,CAAC,kBAAkB,IAAC,OAAO,QAAC,QAAQ,EAAE,UAAU,CAAC,QAAQ,EACzE,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE,GAAG,IAAI,UAAU,CAAC,QAAQ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ui/home-demo/ADAPTATIONS.md.\nimport type { ComponentProps, ReactNode } from \"react\";\nimport { ComposerPrimitive, MessagePrimitive } from \"@assistant-ui/react\";\nimport { cn } from \"../utils.js\";\nexport function Composer({ children, inputProps, actions, ...props }: ComponentProps<typeof ComposerPrimitive.Root> & {\n inputProps: ComponentProps<typeof ComposerPrimitive.Input>; actions: ReactNode;\n}) {\n return (\n <ComposerPrimitive.Root className={cn(\"relative w-full\")} {...props}>\n <ComposerPrimitive.AttachmentDropzone asChild disabled={inputProps.disabled}\n onDropCapture={(event) => { if (inputProps.disabled) event.preventDefault(); }}\n onDragOverCapture={(event) => { if (inputProps.disabled) event.preventDefault(); }}>\n <div data-slot=\"aui_composer-shell\" className={cn(\"border-foreground/10 bg-muted/30 focus-within:border-foreground/25 data-[dragging=true]:border-foreground/40 rounded-thread flex flex-col border transition-colors data-[dragging=true]:border-dashed\")} >\n <div className={cn(\"has-[.aui-attachment-root]:px-3 has-[.aui-attachment-root]:pt-3\")} >{children}</div>\n <ComposerPrimitive.Input asChild {...inputProps}>\n <textarea data-composer-input rows={1} className={cn(\"placeholder:text-muted-foreground field-sizing-content block max-h-48 w-full resize-none bg-transparent px-4 pt-3 pb-2 text-base leading-6 focus:outline-none\")} />\n </ComposerPrimitive.Input>\n <div className={cn(\"flex items-center justify-between gap-2 px-2 pb-2\")} >{actions}</div>\n </div>\n </ComposerPrimitive.AttachmentDropzone>\n </ComposerPrimitive.Root>\n );\n}\n\nexport function EditComposer({ children, inputProps, cancelProps, sendProps, ...props }: ComponentProps<typeof ComposerPrimitive.Root> & {\n inputProps: ComponentProps<typeof ComposerPrimitive.Input>;\n cancelProps: ComponentProps<\"button\">; sendProps: ComponentProps<\"button\">;\n}) {\n return (\n <MessagePrimitive.Root\n data-role=\"user\" data-slot=\"aui_edit-composer-wrapper\"\n className={cn(\"mx-auto flex w-full max-w-(--nxf-thread-max-width) flex-col items-end\")}\n >\n <ComposerPrimitive.Root className={cn(\"border-foreground/10 bg-muted/30 focus-within:border-foreground/25 rounded-thread flex w-full max-w-[85%] flex-col border transition-colors\")} {...props}>\n <ComposerPrimitive.Input asChild {...inputProps}>\n <textarea\n autoFocus\n\n rows={1}\n className={cn(\"field-sizing-content max-h-48 min-h-12 w-full resize-none bg-transparent px-4 pt-3.5 pb-1 text-[15px] leading-6 focus:outline-none\")}\n />\n </ComposerPrimitive.Input>\n {children}\n <div className={cn(\"flex items-center justify-end gap-1.5 px-2.5 pb-2.5\")} >\n <ComposerPrimitive.Cancel asChild>\n <button\n type=\"button\"\n {...cancelProps}\n className={cn(\"text-muted-foreground hover:text-foreground rounded-control h-8 px-3 text-[13px] transition-colors\")}\n >\n 取消\n </button>\n </ComposerPrimitive.Cancel>\n <ComposerPrimitive.Send asChild>\n <button\n type=\"button\"\n {...sendProps}\n className={cn(\"bg-primary text-primary-foreground rounded-control h-8 px-3 text-[13px] font-medium transition-opacity disabled:opacity-40\")}\n >\n 保存并重新发送\n </button>\n </ComposerPrimitive.Send>\n </div>\n </ComposerPrimitive.Root>\n </MessagePrimitive.Root>\n );\n}\n"]}
|
|
@@ -14,7 +14,7 @@ export function ThreadListNew(props) {
|
|
|
14
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
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]") })] });
|
|
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
19
|
export function ThreadListItem({ disabled, menu }) {
|
|
20
20
|
const isRunning = useAuiState((s) => s.threadListItem.isRunning);
|
|
@@ -52,7 +52,7 @@ function ThreadListItemRename({ onDone }) {
|
|
|
52
52
|
inputRef.current?.focus();
|
|
53
53
|
});
|
|
54
54
|
};
|
|
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]"), onChange: (event) => setValue(event.target.value), onBlur: () => commit(false), onKeyDown: (event) => {
|
|
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) => {
|
|
56
56
|
if (event.nativeEvent.isComposing || event.keyCode === 229)
|
|
57
57
|
return;
|
|
58
58
|
if (event.key === "Enter") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-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K,CAAC,WAAW,CAAC,WAAW,IAAI,KAAK,CAAC,OAAO,KAAK,GAAG;gBAAE,OAAO;YACnE,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,EAAE,CAAC;gBAAC,KAAK,CAAC,cAAc,EAAE,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]\")} />\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]\")}\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
|
+
{"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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AAc,EAAE,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"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare type ChatDictation = Pick<DictationAdapter, "listen">;
|
|
2
|
+
|
|
3
|
+
declare namespace DictationAdapter {
|
|
4
|
+
type Status = {
|
|
5
|
+
type: "starting" | "running";
|
|
6
|
+
} | {
|
|
7
|
+
type: "ended";
|
|
8
|
+
reason: "stopped" | "cancelled" | "error";
|
|
9
|
+
};
|
|
10
|
+
type Result = {
|
|
11
|
+
transcript: string;
|
|
12
|
+
isFinal?: boolean;
|
|
13
|
+
};
|
|
14
|
+
type Session = {
|
|
15
|
+
status: Status;
|
|
16
|
+
stop: () => Promise<void>;
|
|
17
|
+
cancel: () => void;
|
|
18
|
+
onSpeechStart: (callback: () => void) => Unsubscribe;
|
|
19
|
+
onSpeechEnd: (callback: (result: Result) => void) => Unsubscribe;
|
|
20
|
+
onSpeech: (callback: (result: Result) => void) => Unsubscribe;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare type DictationAdapter = {
|
|
25
|
+
listen: () => DictationAdapter.Session;
|
|
26
|
+
disableInputDuringDictation?: boolean;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
declare type Unsubscribe = () => void;
|
|
30
|
+
|
|
31
|
+
export { }
|
|
@@ -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"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ComposerRuntime, DictationAdapter } from "@assistant-ui/react";
|
|
2
|
+
import type { ChatDictation } from "./types.js";
|
|
3
|
+
export interface VoiceComposerState {
|
|
4
|
+
supported: boolean;
|
|
5
|
+
status: "idle" | "starting" | "recording" | "transcribing";
|
|
6
|
+
cancel(): void;
|
|
7
|
+
}
|
|
8
|
+
export declare function useVoiceInput(options: {
|
|
9
|
+
dictation: false | ChatDictation | undefined;
|
|
10
|
+
active: boolean;
|
|
11
|
+
open: boolean;
|
|
12
|
+
blocked: boolean;
|
|
13
|
+
sessionId: string;
|
|
14
|
+
composer(): ComposerRuntime;
|
|
15
|
+
notice(message: string): void;
|
|
16
|
+
}): {
|
|
17
|
+
dictation: DictationAdapter | undefined;
|
|
18
|
+
state: {
|
|
19
|
+
status: "idle" | "starting" | "recording" | "transcribing";
|
|
20
|
+
supported: boolean;
|
|
21
|
+
cancel: () => void;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
export function useVoiceInput(options) {
|
|
3
|
+
const latest = useRef(options);
|
|
4
|
+
latest.current = options;
|
|
5
|
+
const source = options.dictation || undefined;
|
|
6
|
+
const enabled = Boolean(source);
|
|
7
|
+
const [status, setStatus] = useState("idle");
|
|
8
|
+
const owner = useRef(undefined);
|
|
9
|
+
const generation = useRef(0);
|
|
10
|
+
const cancel = () => { owner.current?.(); generation.current++; };
|
|
11
|
+
const dictation = useMemo(() => ({
|
|
12
|
+
disableInputDuringDictation: true,
|
|
13
|
+
listen() {
|
|
14
|
+
const config = latest.current;
|
|
15
|
+
if (!config.active || !config.open || config.blocked || !config.dictation || !source)
|
|
16
|
+
throw new Error("当前无法开始语音输入。");
|
|
17
|
+
cancel();
|
|
18
|
+
const token = ++generation.current;
|
|
19
|
+
const composer = config.composer();
|
|
20
|
+
const original = composer.getState().text;
|
|
21
|
+
const starts = new Set();
|
|
22
|
+
const speeches = new Set();
|
|
23
|
+
const ends = new Set();
|
|
24
|
+
let input;
|
|
25
|
+
const subscriptions = [];
|
|
26
|
+
let confirmed = original;
|
|
27
|
+
let hasConfirmed = false;
|
|
28
|
+
let ended = false;
|
|
29
|
+
let status = { type: "starting" };
|
|
30
|
+
const emit = (listeners, value) => {
|
|
31
|
+
for (const callback of [...listeners])
|
|
32
|
+
callback(value);
|
|
33
|
+
};
|
|
34
|
+
const valid = () => !ended && generation.current === token;
|
|
35
|
+
const restore = () => { try {
|
|
36
|
+
composer.setText(original);
|
|
37
|
+
}
|
|
38
|
+
catch { /* A disposed Session no longer owns a composer. */ } };
|
|
39
|
+
const finish = (reason) => {
|
|
40
|
+
if (!valid())
|
|
41
|
+
return;
|
|
42
|
+
ended = true;
|
|
43
|
+
status = { type: "ended", reason };
|
|
44
|
+
owner.current = undefined;
|
|
45
|
+
for (const unsubscribe of subscriptions.splice(0))
|
|
46
|
+
unsubscribe();
|
|
47
|
+
if (reason !== "stopped" || !hasConfirmed)
|
|
48
|
+
restore();
|
|
49
|
+
else
|
|
50
|
+
composer.setText(confirmed);
|
|
51
|
+
emit(ends, { transcript: "", isFinal: true });
|
|
52
|
+
if (reason === "stopped" && !hasConfirmed)
|
|
53
|
+
latest.current.notice("未识别到语音,请重试。");
|
|
54
|
+
setStatus("idle");
|
|
55
|
+
};
|
|
56
|
+
const terminate = () => {
|
|
57
|
+
if (ended)
|
|
58
|
+
return;
|
|
59
|
+
if (valid()) {
|
|
60
|
+
finish("cancelled");
|
|
61
|
+
generation.current++;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
input?.cancel();
|
|
65
|
+
}
|
|
66
|
+
catch { /* Cancellation still restores the draft. */ }
|
|
67
|
+
};
|
|
68
|
+
const session = {
|
|
69
|
+
get status() {
|
|
70
|
+
// Reuse assistant-ui's status polling, including sources that emit no end event.
|
|
71
|
+
if (!ended && input?.status.type === "ended")
|
|
72
|
+
queueMicrotask(complete);
|
|
73
|
+
return ended ? status : input?.status ?? status;
|
|
74
|
+
},
|
|
75
|
+
stop: async () => {
|
|
76
|
+
if (!valid())
|
|
77
|
+
return;
|
|
78
|
+
setStatus("transcribing");
|
|
79
|
+
try {
|
|
80
|
+
await input?.stop();
|
|
81
|
+
if (valid())
|
|
82
|
+
complete();
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
failure(error);
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
cancel: terminate,
|
|
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); },
|
|
92
|
+
};
|
|
93
|
+
owner.current = terminate;
|
|
94
|
+
config.notice("");
|
|
95
|
+
setStatus("starting");
|
|
96
|
+
const failure = (error) => {
|
|
97
|
+
if (!valid())
|
|
98
|
+
return;
|
|
99
|
+
const cancelled = error instanceof DOMException && error.name === "AbortError";
|
|
100
|
+
finish(cancelled ? "cancelled" : "error");
|
|
101
|
+
try {
|
|
102
|
+
input?.cancel();
|
|
103
|
+
}
|
|
104
|
+
catch { /* The source already failed. */ }
|
|
105
|
+
if (!cancelled)
|
|
106
|
+
latest.current.notice(error instanceof Error ? error.message : "语音输入失败,请重试。");
|
|
107
|
+
};
|
|
108
|
+
const complete = () => {
|
|
109
|
+
if (!valid())
|
|
110
|
+
return;
|
|
111
|
+
const reason = input?.status.type === "ended" ? input.status.reason : "stopped";
|
|
112
|
+
if (reason === "error")
|
|
113
|
+
failure(new Error("语音输入失败,请检查授权、麦克风权限和网络。"));
|
|
114
|
+
else
|
|
115
|
+
finish(reason);
|
|
116
|
+
};
|
|
117
|
+
try {
|
|
118
|
+
input = source.listen();
|
|
119
|
+
const started = () => {
|
|
120
|
+
if (!valid())
|
|
121
|
+
return;
|
|
122
|
+
status = { type: "running" };
|
|
123
|
+
setStatus("recording");
|
|
124
|
+
for (const callback of [...starts])
|
|
125
|
+
callback();
|
|
126
|
+
};
|
|
127
|
+
subscriptions.push(input.onSpeechStart(started));
|
|
128
|
+
subscriptions.push(input.onSpeech((result) => {
|
|
129
|
+
if (!valid())
|
|
130
|
+
return;
|
|
131
|
+
emit(speeches, result);
|
|
132
|
+
if (result.isFinal !== false) {
|
|
133
|
+
confirmed = composer.getState().text;
|
|
134
|
+
hasConfirmed ||= Boolean(result.transcript.trim());
|
|
135
|
+
}
|
|
136
|
+
}));
|
|
137
|
+
subscriptions.push(input.onSpeechEnd(complete));
|
|
138
|
+
// Sources may already be running or synchronously ended after listen().
|
|
139
|
+
if (input.status.type === "running")
|
|
140
|
+
queueMicrotask(started);
|
|
141
|
+
if (input.status.type === "ended")
|
|
142
|
+
queueMicrotask(complete);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
queueMicrotask(() => failure(error));
|
|
146
|
+
}
|
|
147
|
+
return session;
|
|
148
|
+
},
|
|
149
|
+
}), [source]);
|
|
150
|
+
useLayoutEffect(() => {
|
|
151
|
+
if (!options.active || !options.open || options.blocked || !enabled)
|
|
152
|
+
cancel();
|
|
153
|
+
}, [options.active, options.open, options.blocked, enabled]);
|
|
154
|
+
useLayoutEffect(() => () => cancel(), [source, options.sessionId]);
|
|
155
|
+
return { dictation: enabled ? dictation : undefined, state: { status, supported: enabled, cancel } };
|
|
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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CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,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"]}
|