@assistant-ui/react 0.11.53 → 0.11.55
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/README.md +6 -3
- package/dist/client/NoOpComposerClient.d.ts +1 -1
- package/dist/client/NoOpComposerClient.d.ts.map +1 -1
- package/dist/client/NoOpComposerClient.js +7 -0
- package/dist/client/NoOpComposerClient.js.map +1 -1
- package/dist/client/types/Composer.d.ts +18 -3
- package/dist/client/types/Composer.d.ts.map +1 -1
- package/dist/client/types/Message.d.ts +17 -3
- package/dist/client/types/Message.d.ts.map +1 -1
- package/dist/legacy-runtime/client/ComposerRuntimeClient.d.ts.map +1 -1
- package/dist/legacy-runtime/client/ComposerRuntimeClient.js +3 -0
- package/dist/legacy-runtime/client/ComposerRuntimeClient.js.map +1 -1
- package/dist/legacy-runtime/hooks/AssistantContext.d.ts +2 -2
- package/dist/legacy-runtime/hooks/AssistantContext.js +1 -1
- package/dist/legacy-runtime/hooks/AttachmentContext.d.ts +2 -2
- package/dist/legacy-runtime/hooks/AttachmentContext.js +1 -1
- package/dist/legacy-runtime/hooks/ComposerContext.d.ts +2 -2
- package/dist/legacy-runtime/hooks/ComposerContext.js +1 -1
- package/dist/legacy-runtime/hooks/MessageContext.d.ts +3 -3
- package/dist/legacy-runtime/hooks/MessageContext.js +2 -2
- package/dist/legacy-runtime/hooks/MessagePartContext.d.ts +2 -2
- package/dist/legacy-runtime/hooks/MessagePartContext.js +1 -1
- package/dist/legacy-runtime/hooks/ThreadContext.d.ts +4 -4
- package/dist/legacy-runtime/hooks/ThreadContext.js +2 -2
- package/dist/legacy-runtime/hooks/ThreadListItemContext.d.ts +2 -2
- package/dist/legacy-runtime/hooks/ThreadListItemContext.js +1 -1
- package/dist/legacy-runtime/runtime/ComposerRuntime.d.ts +22 -6
- package/dist/legacy-runtime/runtime/ComposerRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime/ComposerRuntime.js +18 -2
- package/dist/legacy-runtime/runtime/ComposerRuntime.js.map +1 -1
- package/dist/legacy-runtime/runtime/ThreadRuntime.d.ts +3 -0
- package/dist/legacy-runtime/runtime/ThreadRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/adapters/speech/SpeechAdapterTypes.d.ts +25 -3
- package/dist/legacy-runtime/runtime-cores/adapters/speech/SpeechAdapterTypes.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/adapters/speech/WebSpeechDictationAdapter.d.ts +61 -0
- package/dist/legacy-runtime/runtime-cores/adapters/speech/WebSpeechDictationAdapter.d.ts.map +1 -0
- package/dist/legacy-runtime/runtime-cores/adapters/speech/WebSpeechDictationAdapter.js +152 -0
- package/dist/legacy-runtime/runtime-cores/adapters/speech/WebSpeechDictationAdapter.js.map +1 -0
- package/dist/legacy-runtime/runtime-cores/adapters/speech/index.d.ts +2 -1
- package/dist/legacy-runtime/runtime-cores/adapters/speech/index.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/adapters/speech/index.js +1 -0
- package/dist/legacy-runtime/runtime-cores/adapters/speech/index.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/types.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js +4 -1
- package/dist/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/composer/BaseComposerRuntimeCore.d.ts +20 -5
- package/dist/legacy-runtime/runtime-cores/composer/BaseComposerRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/composer/BaseComposerRuntimeCore.js +140 -0
- package/dist/legacy-runtime/runtime-cores/composer/BaseComposerRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/composer/DefaultEditComposerRuntimeCore.d.ts +6 -3
- package/dist/legacy-runtime/runtime-cores/composer/DefaultEditComposerRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/composer/DefaultEditComposerRuntimeCore.js +3 -0
- package/dist/legacy-runtime/runtime-cores/composer/DefaultEditComposerRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/composer/DefaultThreadComposerRuntimeCore.d.ts +7 -4
- package/dist/legacy-runtime/runtime-cores/composer/DefaultThreadComposerRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/composer/DefaultThreadComposerRuntimeCore.js +3 -0
- package/dist/legacy-runtime/runtime-cores/composer/DefaultThreadComposerRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/core/ComposerRuntimeCore.d.ts +35 -1
- package/dist/legacy-runtime/runtime-cores/core/ComposerRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.d.ts +1 -0
- package/dist/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/core/index.d.ts +1 -0
- package/dist/legacy-runtime/runtime-cores/core/index.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreAdapter.d.ts +8 -7
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreAdapter.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.d.ts +7 -6
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.js +4 -2
- package/dist/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.d.ts +10 -8
- package/dist/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.d.ts +5 -3
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.js +6 -0
- package/dist/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.d.ts +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.js +8 -0
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.js.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.d.ts.map +1 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.js +8 -1
- package/dist/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.js.map +1 -1
- package/dist/primitives/actionBarMore/ActionBarMoreContent.d.ts +12 -0
- package/dist/primitives/actionBarMore/ActionBarMoreContent.d.ts.map +1 -0
- package/dist/primitives/actionBarMore/ActionBarMoreContent.js +11 -0
- package/dist/primitives/actionBarMore/ActionBarMoreContent.js.map +1 -0
- package/dist/primitives/actionBarMore/ActionBarMoreItem.d.ts +8 -0
- package/dist/primitives/actionBarMore/ActionBarMoreItem.d.ts.map +1 -0
- package/dist/primitives/actionBarMore/ActionBarMoreItem.js +11 -0
- package/dist/primitives/actionBarMore/ActionBarMoreItem.js.map +1 -0
- package/dist/primitives/actionBarMore/ActionBarMoreRoot.d.ts +7 -0
- package/dist/primitives/actionBarMore/ActionBarMoreRoot.d.ts.map +1 -0
- package/dist/primitives/actionBarMore/ActionBarMoreRoot.js +10 -0
- package/dist/primitives/actionBarMore/ActionBarMoreRoot.js.map +1 -0
- package/dist/primitives/actionBarMore/ActionBarMoreSeparator.d.ts +8 -0
- package/dist/primitives/actionBarMore/ActionBarMoreSeparator.d.ts.map +1 -0
- package/dist/primitives/actionBarMore/ActionBarMoreSeparator.js +12 -0
- package/dist/primitives/actionBarMore/ActionBarMoreSeparator.js.map +1 -0
- package/dist/primitives/actionBarMore/ActionBarMoreTrigger.d.ts +8 -0
- package/dist/primitives/actionBarMore/ActionBarMoreTrigger.d.ts.map +1 -0
- package/dist/primitives/actionBarMore/ActionBarMoreTrigger.js +11 -0
- package/dist/primitives/actionBarMore/ActionBarMoreTrigger.js.map +1 -0
- package/dist/primitives/actionBarMore/index.d.ts +6 -0
- package/dist/primitives/actionBarMore/index.d.ts.map +1 -0
- package/dist/primitives/actionBarMore/index.js +6 -0
- package/dist/primitives/actionBarMore/index.js.map +1 -0
- package/dist/primitives/actionBarMore/scope.d.ts +7 -0
- package/dist/primitives/actionBarMore/scope.d.ts.map +1 -0
- package/dist/primitives/actionBarMore/scope.js +3 -0
- package/dist/primitives/actionBarMore/scope.js.map +1 -0
- package/dist/primitives/composer/ComposerDictate.d.ts +23 -0
- package/dist/primitives/composer/ComposerDictate.d.ts.map +1 -0
- package/dist/primitives/composer/ComposerDictate.js +30 -0
- package/dist/primitives/composer/ComposerDictate.js.map +1 -0
- package/dist/primitives/composer/ComposerDictationTranscript.d.ts +25 -0
- package/dist/primitives/composer/ComposerDictationTranscript.d.ts.map +1 -0
- package/dist/primitives/composer/ComposerDictationTranscript.js +29 -0
- package/dist/primitives/composer/ComposerDictationTranscript.js.map +1 -0
- package/dist/primitives/composer/ComposerIf.d.ts +3 -0
- package/dist/primitives/composer/ComposerIf.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerIf.js +5 -0
- package/dist/primitives/composer/ComposerIf.js.map +1 -1
- package/dist/primitives/composer/ComposerInput.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerInput.js +1 -1
- package/dist/primitives/composer/ComposerInput.js.map +1 -1
- package/dist/primitives/composer/ComposerStopDictation.d.ts +23 -0
- package/dist/primitives/composer/ComposerStopDictation.d.ts.map +1 -0
- package/dist/primitives/composer/ComposerStopDictation.js +28 -0
- package/dist/primitives/composer/ComposerStopDictation.js.map +1 -0
- package/dist/primitives/composer/index.d.ts +3 -0
- package/dist/primitives/composer/index.d.ts.map +1 -1
- package/dist/primitives/composer/index.js +3 -0
- package/dist/primitives/composer/index.js.map +1 -1
- package/dist/primitives/index.d.ts +2 -0
- package/dist/primitives/index.d.ts.map +1 -1
- package/dist/primitives/index.js +2 -0
- package/dist/primitives/index.js.map +1 -1
- package/dist/primitives/threadListItemMore/ThreadListItemMoreContent.d.ts +12 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreContent.d.ts.map +1 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreContent.js +12 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreContent.js.map +1 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreItem.d.ts +8 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreItem.d.ts.map +1 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreItem.js +12 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreItem.js.map +1 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreRoot.d.ts +7 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreRoot.d.ts.map +1 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreRoot.js +11 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreRoot.js.map +1 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreSeparator.d.ts +8 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreSeparator.d.ts.map +1 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreSeparator.js +12 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreSeparator.js.map +1 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreTrigger.d.ts +8 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreTrigger.d.ts.map +1 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreTrigger.js +12 -0
- package/dist/primitives/threadListItemMore/ThreadListItemMoreTrigger.js.map +1 -0
- package/dist/primitives/threadListItemMore/index.d.ts +6 -0
- package/dist/primitives/threadListItemMore/index.d.ts.map +1 -0
- package/dist/primitives/threadListItemMore/index.js +6 -0
- package/dist/primitives/threadListItemMore/index.js.map +1 -0
- package/dist/primitives/threadListItemMore/scope.d.ts +7 -0
- package/dist/primitives/threadListItemMore/scope.d.ts.map +1 -0
- package/dist/primitives/threadListItemMore/scope.js +3 -0
- package/dist/primitives/threadListItemMore/scope.js.map +1 -0
- package/package.json +6 -5
- package/src/client/NoOpComposerClient.tsx +8 -1
- package/src/client/types/Composer.ts +21 -4
- package/src/client/types/Message.ts +17 -3
- package/src/legacy-runtime/client/ComposerRuntimeClient.ts +4 -0
- package/src/legacy-runtime/hooks/AssistantContext.ts +2 -2
- package/src/legacy-runtime/hooks/AttachmentContext.ts +2 -2
- package/src/legacy-runtime/hooks/ComposerContext.ts +2 -2
- package/src/legacy-runtime/hooks/MessageContext.ts +3 -3
- package/src/legacy-runtime/hooks/MessagePartContext.ts +2 -2
- package/src/legacy-runtime/hooks/ThreadContext.ts +4 -4
- package/src/legacy-runtime/hooks/ThreadListItemContext.ts +2 -2
- package/src/legacy-runtime/runtime/ComposerRuntime.ts +51 -14
- package/src/legacy-runtime/runtime-cores/adapters/speech/SpeechAdapterTypes.ts +26 -3
- package/src/legacy-runtime/runtime-cores/adapters/speech/WebSpeechDictationAdapter.ts +255 -0
- package/src/legacy-runtime/runtime-cores/adapters/speech/index.ts +5 -1
- package/src/legacy-runtime/runtime-cores/assistant-transport/types.ts +1 -1
- package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx +5 -1
- package/src/legacy-runtime/runtime-cores/composer/BaseComposerRuntimeCore.tsx +171 -5
- package/src/legacy-runtime/runtime-cores/composer/DefaultEditComposerRuntimeCore.tsx +14 -4
- package/src/legacy-runtime/runtime-cores/composer/DefaultThreadComposerRuntimeCore.tsx +15 -5
- package/src/legacy-runtime/runtime-cores/core/ComposerRuntimeCore.tsx +39 -1
- package/src/legacy-runtime/runtime-cores/core/ThreadRuntimeCore.tsx +1 -0
- package/src/legacy-runtime/runtime-cores/core/index.ts +2 -0
- package/src/legacy-runtime/runtime-cores/external-store/ExternalStoreAdapter.tsx +11 -7
- package/src/legacy-runtime/runtime-cores/external-store/ExternalStoreThreadRuntimeCore.tsx +12 -7
- package/src/legacy-runtime/runtime-cores/local/LocalRuntimeOptions.tsx +12 -8
- package/src/legacy-runtime/runtime-cores/local/LocalThreadRuntimeCore.tsx +11 -4
- package/src/legacy-runtime/runtime-cores/remote-thread-list/EMPTY_THREAD_CORE.tsx +12 -1
- package/src/legacy-runtime/runtime-cores/remote-thread-list/adapter/cloud.tsx +11 -1
- package/src/primitives/actionBarMore/ActionBarMoreContent.tsx +46 -0
- package/src/primitives/actionBarMore/ActionBarMoreItem.tsx +31 -0
- package/src/primitives/actionBarMore/ActionBarMoreRoot.tsx +22 -0
- package/src/primitives/actionBarMore/ActionBarMoreSeparator.tsx +32 -0
- package/src/primitives/actionBarMore/ActionBarMoreTrigger.tsx +31 -0
- package/src/primitives/actionBarMore/index.ts +5 -0
- package/src/primitives/actionBarMore/scope.tsx +8 -0
- package/src/primitives/composer/ComposerDictate.tsx +48 -0
- package/src/primitives/composer/ComposerDictationTranscript.tsx +45 -0
- package/src/primitives/composer/ComposerIf.tsx +7 -0
- package/src/primitives/composer/ComposerInput.tsx +4 -1
- package/src/primitives/composer/ComposerStopDictation.tsx +45 -0
- package/src/primitives/composer/index.ts +3 -0
- package/src/primitives/index.ts +2 -0
- package/src/primitives/threadListItemMore/ThreadListItemMoreContent.tsx +47 -0
- package/src/primitives/threadListItemMore/ThreadListItemMoreItem.tsx +32 -0
- package/src/primitives/threadListItemMore/ThreadListItemMoreRoot.tsx +23 -0
- package/src/primitives/threadListItemMore/ThreadListItemMoreSeparator.tsx +32 -0
- package/src/primitives/threadListItemMore/ThreadListItemMoreTrigger.tsx +32 -0
- package/src/primitives/threadListItemMore/index.ts +5 -0
- package/src/primitives/threadListItemMore/scope.tsx +8 -0
|
@@ -5,7 +5,7 @@ import { createStateHookForRuntime } from "../../context/react/utils/createState
|
|
|
5
5
|
import { useAssistantApi, useAssistantState } from "../../context/react";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @deprecated Use `useAssistantApi()` with `api.attachment()` instead. See migration guide: https://
|
|
8
|
+
* @deprecated Use `useAssistantApi()` with `api.attachment()` instead. See migration guide: https://assistant-ui.com/docs/migrations/v0-12
|
|
9
9
|
*/
|
|
10
10
|
export function useAttachmentRuntime(options?: {
|
|
11
11
|
optional?: false | undefined;
|
|
@@ -84,7 +84,7 @@ export function useMessageAttachmentRuntime(options?: {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/**
|
|
87
|
-
* @deprecated Use `useAssistantState(({ attachment }) => attachment)` instead. See migration guide: https://
|
|
87
|
+
* @deprecated Use `useAssistantState(({ attachment }) => attachment)` instead. See migration guide: https://assistant-ui.com/docs/migrations/v0-12
|
|
88
88
|
*/
|
|
89
89
|
export const useAttachment = createStateHookForRuntime(useAttachmentRuntime);
|
|
90
90
|
|
|
@@ -5,7 +5,7 @@ import { ComposerRuntime } from "../runtime/ComposerRuntime";
|
|
|
5
5
|
import { createStateHookForRuntime } from "../../context/react/utils/createStateHookForRuntime";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @deprecated Use `useAssistantApi()` with `api.composer()` instead. See migration guide: https://
|
|
8
|
+
* @deprecated Use `useAssistantApi()` with `api.composer()` instead. See migration guide: https://assistant-ui.com/docs/migrations/v0-12
|
|
9
9
|
*
|
|
10
10
|
* Hook to access the ComposerRuntime from the current context.
|
|
11
11
|
*
|
|
@@ -87,7 +87,7 @@ export function useComposerRuntime(options?: {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
|
-
* @deprecated Use `useAssistantState(({ composer }) => composer)` instead. See migration guide: https://
|
|
90
|
+
* @deprecated Use `useAssistantState(({ composer }) => composer)` instead. See migration guide: https://assistant-ui.com/docs/migrations/v0-12
|
|
91
91
|
*
|
|
92
92
|
* Hook to access the current composer state.
|
|
93
93
|
*
|
|
@@ -6,7 +6,7 @@ import { createStateHookForRuntime } from "../../context/react/utils/createState
|
|
|
6
6
|
import { EditComposerRuntime } from "../runtime";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* @deprecated Use `useAssistantApi()` with `api.message()` instead. See migration guide: https://
|
|
9
|
+
* @deprecated Use `useAssistantApi()` with `api.message()` instead. See migration guide: https://assistant-ui.com/docs/migrations/v0-12
|
|
10
10
|
*
|
|
11
11
|
* Hook to access the MessageRuntime from the current context.
|
|
12
12
|
*
|
|
@@ -76,7 +76,7 @@ export function useMessageRuntime(options?: {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
|
-
* @deprecated Use `useAssistantState(({ message }) => message)` instead. See migration guide: https://
|
|
79
|
+
* @deprecated Use `useAssistantState(({ message }) => message)` instead. See migration guide: https://assistant-ui.com/docs/migrations/v0-12
|
|
80
80
|
*
|
|
81
81
|
* Hook to access the current message state.
|
|
82
82
|
*
|
|
@@ -120,7 +120,7 @@ const useEditComposerRuntime = (opt: {
|
|
|
120
120
|
}): EditComposerRuntime | null => useMessageRuntime(opt)?.composer ?? null;
|
|
121
121
|
|
|
122
122
|
/**
|
|
123
|
-
* @deprecated Use `useAssistantState(({ message }) => message.composer)` instead. See migration guide: https://
|
|
123
|
+
* @deprecated Use `useAssistantState(({ message }) => message.composer)` instead. See migration guide: https://assistant-ui.com/docs/migrations/v0-12
|
|
124
124
|
*/
|
|
125
125
|
export const useEditComposer = createStateHookForRuntime(
|
|
126
126
|
useEditComposerRuntime,
|
|
@@ -5,7 +5,7 @@ import { createStateHookForRuntime } from "../../context/react/utils/createState
|
|
|
5
5
|
import { useAssistantApi, useAssistantState } from "../../context/react";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @deprecated Use `useAssistantApi()` with `api.part()` instead. See migration guide: https://
|
|
8
|
+
* @deprecated Use `useAssistantApi()` with `api.part()` instead. See migration guide: https://assistant-ui.com/docs/migrations/v0-12
|
|
9
9
|
*/
|
|
10
10
|
export function useMessagePartRuntime(options?: {
|
|
11
11
|
optional?: false | undefined;
|
|
@@ -27,6 +27,6 @@ export function useMessagePartRuntime(options?: {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
|
-
* @deprecated Use `useAssistantState(({ part }) => part)` instead. See migration guide: https://
|
|
30
|
+
* @deprecated Use `useAssistantState(({ part }) => part)` instead. See migration guide: https://assistant-ui.com/docs/migrations/v0-12
|
|
31
31
|
*/
|
|
32
32
|
export const useMessagePart = createStateHookForRuntime(useMessagePartRuntime);
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "../../context/react";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* @deprecated Use `useAssistantApi()` with `api.thread()` instead. See migration guide: https://
|
|
15
|
+
* @deprecated Use `useAssistantApi()` with `api.thread()` instead. See migration guide: https://assistant-ui.com/docs/migrations/v0-12
|
|
16
16
|
*
|
|
17
17
|
* Hook to access the ThreadRuntime from the current context.
|
|
18
18
|
*
|
|
@@ -62,7 +62,7 @@ export function useThreadRuntime(options?: { optional?: boolean | undefined }) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
* @deprecated Use `useAssistantState(({ thread }) => thread)` instead. See migration guide: https://
|
|
65
|
+
* @deprecated Use `useAssistantState(({ thread }) => thread)` instead. See migration guide: https://assistant-ui.com/docs/migrations/v0-12
|
|
66
66
|
*
|
|
67
67
|
* Hook to access the current thread state.
|
|
68
68
|
*
|
|
@@ -96,14 +96,14 @@ const useThreadComposerRuntime = (opt: {
|
|
|
96
96
|
}): ThreadComposerRuntime | null => useThreadRuntime(opt)?.composer ?? null;
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
|
-
* @deprecated Use `useAssistantState(({ thread }) => thread.composer)` instead. See migration guide: https://
|
|
99
|
+
* @deprecated Use `useAssistantState(({ thread }) => thread.composer)` instead. See migration guide: https://assistant-ui.com/docs/migrations/v0-12
|
|
100
100
|
*/
|
|
101
101
|
export const useThreadComposer = createStateHookForRuntime(
|
|
102
102
|
useThreadComposerRuntime,
|
|
103
103
|
);
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
|
-
* @deprecated Use `useAssistantState(({ thread }) => thread.modelContext)` instead. See migration guide: https://
|
|
106
|
+
* @deprecated Use `useAssistantState(({ thread }) => thread.modelContext)` instead. See migration guide: https://assistant-ui.com/docs/migrations/v0-12
|
|
107
107
|
*/
|
|
108
108
|
export function useThreadModelContext(options?: {
|
|
109
109
|
optional?: false | undefined;
|
|
@@ -5,7 +5,7 @@ import { createStateHookForRuntime } from "../../context/react/utils/createState
|
|
|
5
5
|
import { useAssistantApi, useAssistantState } from "../../context/react";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* @deprecated Use `useAssistantApi()` with `api.threadListItem()` instead. See migration guide: https://
|
|
8
|
+
* @deprecated Use `useAssistantApi()` with `api.threadListItem()` instead. See migration guide: https://assistant-ui.com/docs/migrations/v0-12
|
|
9
9
|
*/
|
|
10
10
|
export function useThreadListItemRuntime(options?: {
|
|
11
11
|
optional?: false | undefined;
|
|
@@ -29,7 +29,7 @@ export function useThreadListItemRuntime(options?: {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
* @deprecated Use `useAssistantState(({ threadListItem }) => threadListItem)` instead. See migration guide: https://
|
|
32
|
+
* @deprecated Use `useAssistantState(({ threadListItem }) => threadListItem)` instead. See migration guide: https://assistant-ui.com/docs/migrations/v0-12
|
|
33
33
|
*/
|
|
34
34
|
export const useThreadListItem = createStateHookForRuntime(
|
|
35
35
|
useThreadListItemRuntime,
|
|
@@ -1,28 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type {
|
|
2
|
+
Attachment,
|
|
3
|
+
PendingAttachment,
|
|
4
|
+
} from "../../types/AttachmentTypes";
|
|
5
|
+
import type {
|
|
3
6
|
ComposerRuntimeCore,
|
|
4
7
|
ComposerRuntimeEventType,
|
|
8
|
+
DictationState,
|
|
5
9
|
ThreadComposerRuntimeCore,
|
|
6
10
|
} from "../runtime-cores/core/ComposerRuntimeCore";
|
|
7
|
-
import { Unsubscribe } from "../../types";
|
|
11
|
+
import type { Unsubscribe } from "../../types";
|
|
12
|
+
import type { MessageRole, RunConfig } from "../../types/AssistantTypes";
|
|
13
|
+
import type {
|
|
14
|
+
ThreadComposerRuntimeCoreBinding,
|
|
15
|
+
EditComposerRuntimeCoreBinding,
|
|
16
|
+
ComposerRuntimeCoreBinding,
|
|
17
|
+
} from "./RuntimeBindings";
|
|
18
|
+
import type { ComposerRuntimePath } from "./RuntimePathTypes";
|
|
8
19
|
|
|
9
20
|
import { LazyMemoizeSubject } from "./subscribable/LazyMemoizeSubject";
|
|
10
21
|
import {
|
|
11
|
-
AttachmentRuntime,
|
|
12
|
-
AttachmentState,
|
|
22
|
+
type AttachmentRuntime,
|
|
23
|
+
type AttachmentState,
|
|
13
24
|
EditComposerAttachmentRuntimeImpl,
|
|
14
25
|
ThreadComposerAttachmentRuntimeImpl,
|
|
15
26
|
} from "./AttachmentRuntime";
|
|
16
27
|
import { ShallowMemoizeSubject } from "./subscribable/ShallowMemoizeSubject";
|
|
17
28
|
import { SKIP_UPDATE } from "./subscribable/SKIP_UPDATE";
|
|
18
|
-
import { ComposerRuntimePath } from "./RuntimePathTypes";
|
|
19
|
-
import { MessageRole, RunConfig } from "../../types/AssistantTypes";
|
|
20
29
|
import { EventSubscriptionSubject } from "./subscribable/EventSubscriptionSubject";
|
|
21
|
-
import type {
|
|
22
|
-
ThreadComposerRuntimeCoreBinding,
|
|
23
|
-
EditComposerRuntimeCoreBinding,
|
|
24
|
-
ComposerRuntimeCoreBinding,
|
|
25
|
-
} from "./RuntimeBindings";
|
|
26
30
|
|
|
27
31
|
export type {
|
|
28
32
|
ThreadComposerRuntimeCoreBinding,
|
|
@@ -41,6 +45,12 @@ type BaseComposerState = {
|
|
|
41
45
|
readonly runConfig: RunConfig;
|
|
42
46
|
|
|
43
47
|
readonly attachmentAccept: string;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The current state of dictation.
|
|
51
|
+
* Undefined when dictation is not active.
|
|
52
|
+
*/
|
|
53
|
+
readonly dictation: DictationState | undefined;
|
|
44
54
|
};
|
|
45
55
|
|
|
46
56
|
export type ThreadComposerState = BaseComposerState & {
|
|
@@ -72,6 +82,7 @@ const getThreadComposerState = (
|
|
|
72
82
|
role: runtime?.role ?? "user",
|
|
73
83
|
runConfig: runtime?.runConfig ?? EMPTY_OBJECT,
|
|
74
84
|
attachmentAccept: runtime?.attachmentAccept ?? "",
|
|
85
|
+
dictation: runtime?.dictation,
|
|
75
86
|
|
|
76
87
|
value: runtime?.text ?? "",
|
|
77
88
|
});
|
|
@@ -92,6 +103,7 @@ const getEditComposerState = (
|
|
|
92
103
|
attachments: runtime?.attachments ?? EMPTY_ARRAY,
|
|
93
104
|
runConfig: runtime?.runConfig ?? EMPTY_OBJECT,
|
|
94
105
|
attachmentAccept: runtime?.attachmentAccept ?? "",
|
|
106
|
+
dictation: runtime?.dictation,
|
|
95
107
|
|
|
96
108
|
value: runtime?.text ?? "",
|
|
97
109
|
});
|
|
@@ -169,6 +181,17 @@ export type ComposerRuntime = {
|
|
|
169
181
|
*/
|
|
170
182
|
getAttachmentByIndex(idx: number): AttachmentRuntime;
|
|
171
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Start dictation to convert voice to text input.
|
|
186
|
+
* Requires a DictationAdapter to be configured.
|
|
187
|
+
*/
|
|
188
|
+
startDictation(): void;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Stop the current dictation session.
|
|
192
|
+
*/
|
|
193
|
+
stopDictation(): void;
|
|
194
|
+
|
|
172
195
|
/**
|
|
173
196
|
* @deprecated This API is still under active development and might change without notice.
|
|
174
197
|
*/
|
|
@@ -199,6 +222,8 @@ export abstract class ComposerRuntimeImpl implements ComposerRuntime {
|
|
|
199
222
|
this.cancel = this.cancel.bind(this);
|
|
200
223
|
this.setRole = this.setRole.bind(this);
|
|
201
224
|
this.getAttachmentByIndex = this.getAttachmentByIndex.bind(this);
|
|
225
|
+
this.startDictation = this.startDictation.bind(this);
|
|
226
|
+
this.stopDictation = this.stopDictation.bind(this);
|
|
202
227
|
this.unstable_on = this.unstable_on.bind(this);
|
|
203
228
|
}
|
|
204
229
|
|
|
@@ -252,6 +277,18 @@ export abstract class ComposerRuntimeImpl implements ComposerRuntime {
|
|
|
252
277
|
core.setRole(role);
|
|
253
278
|
}
|
|
254
279
|
|
|
280
|
+
public startDictation() {
|
|
281
|
+
const core = this._core.getState();
|
|
282
|
+
if (!core) throw new Error("Composer is not available");
|
|
283
|
+
core.startDictation();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
public stopDictation() {
|
|
287
|
+
const core = this._core.getState();
|
|
288
|
+
if (!core) throw new Error("Composer is not available");
|
|
289
|
+
core.stopDictation();
|
|
290
|
+
}
|
|
291
|
+
|
|
255
292
|
public subscribe(callback: () => void) {
|
|
256
293
|
return this._core.subscribe(callback);
|
|
257
294
|
}
|
|
@@ -335,7 +372,7 @@ export class ThreadComposerRuntimeImpl
|
|
|
335
372
|
...this.path,
|
|
336
373
|
attachmentSource: "thread-composer",
|
|
337
374
|
attachmentSelector: { type: "index", index: idx },
|
|
338
|
-
ref: `${this.path.ref}
|
|
375
|
+
ref: `${this.path.ref}.attachments[${idx}]`,
|
|
339
376
|
},
|
|
340
377
|
getState: () => {
|
|
341
378
|
const attachments = this.getState().attachments;
|
|
@@ -423,7 +460,7 @@ export class EditComposerRuntimeImpl
|
|
|
423
460
|
...this.path,
|
|
424
461
|
attachmentSource: "edit-composer",
|
|
425
462
|
attachmentSelector: { type: "index", index: idx },
|
|
426
|
-
ref: `${this.path.ref}
|
|
463
|
+
ref: `${this.path.ref}.attachments[${idx}]`,
|
|
427
464
|
},
|
|
428
465
|
getState: () => {
|
|
429
466
|
const attachments = this.getState().attachments;
|
|
@@ -69,7 +69,7 @@ export type SpeechSynthesisAdapter = {
|
|
|
69
69
|
speak: (text: string) => SpeechSynthesisAdapter.Utterance;
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
-
export namespace
|
|
72
|
+
export namespace DictationAdapter {
|
|
73
73
|
export type Status =
|
|
74
74
|
| {
|
|
75
75
|
type: "starting" | "running";
|
|
@@ -80,7 +80,22 @@ export namespace SpeechRecognitionAdapter {
|
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
export type Result = {
|
|
83
|
+
/** The transcribed text */
|
|
83
84
|
transcript: string;
|
|
85
|
+
/**
|
|
86
|
+
* Whether this is a final (committed) result or an interim (partial) result.
|
|
87
|
+
*
|
|
88
|
+
* - `true` (final): The text should be appended to the composer input.
|
|
89
|
+
* This text is finalized and won't change.
|
|
90
|
+
*
|
|
91
|
+
* - `false` (interim/partial): The text is a preview that may change.
|
|
92
|
+
* It should be displayed as a preview but not appended to the input yet.
|
|
93
|
+
* Subsequent interim results replace the previous interim result.
|
|
94
|
+
*
|
|
95
|
+
* Defaults to `true` for backwards compatibility with adapters that
|
|
96
|
+
* don't set this flag.
|
|
97
|
+
*/
|
|
98
|
+
isFinal?: boolean;
|
|
84
99
|
};
|
|
85
100
|
|
|
86
101
|
export type Session = {
|
|
@@ -93,6 +108,14 @@ export namespace SpeechRecognitionAdapter {
|
|
|
93
108
|
};
|
|
94
109
|
}
|
|
95
110
|
|
|
96
|
-
export type
|
|
97
|
-
listen: () =>
|
|
111
|
+
export type DictationAdapter = {
|
|
112
|
+
listen: () => DictationAdapter.Session;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Whether to disable text input while dictation is active.
|
|
116
|
+
* Some adapters (like ElevenLabs Scribe) return cumulative transcripts
|
|
117
|
+
* that conflict with simultaneous typing.
|
|
118
|
+
* @default false
|
|
119
|
+
*/
|
|
120
|
+
disableInputDuringDictation?: boolean;
|
|
98
121
|
};
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import type { Unsubscribe } from "../../../../types";
|
|
2
|
+
import type { DictationAdapter } from "./SpeechAdapterTypes";
|
|
3
|
+
|
|
4
|
+
// Type definitions for Web Speech API
|
|
5
|
+
// Users can install @types/dom-speech-recognition for full type support
|
|
6
|
+
interface SpeechRecognitionResultItem {
|
|
7
|
+
transcript: string;
|
|
8
|
+
confidence: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface SpeechRecognitionResult {
|
|
12
|
+
readonly length: number;
|
|
13
|
+
item(index: number): SpeechRecognitionResultItem;
|
|
14
|
+
readonly isFinal: boolean;
|
|
15
|
+
[index: number]: SpeechRecognitionResultItem;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface SpeechRecognitionResultList {
|
|
19
|
+
readonly length: number;
|
|
20
|
+
item(index: number): SpeechRecognitionResult;
|
|
21
|
+
[index: number]: SpeechRecognitionResult;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface SpeechRecognitionEvent extends Event {
|
|
25
|
+
readonly resultIndex: number;
|
|
26
|
+
readonly results: SpeechRecognitionResultList;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface SpeechRecognitionErrorEvent extends Event {
|
|
30
|
+
readonly error: string;
|
|
31
|
+
readonly message: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface SpeechRecognitionInstance extends EventTarget {
|
|
35
|
+
lang: string;
|
|
36
|
+
continuous: boolean;
|
|
37
|
+
interimResults: boolean;
|
|
38
|
+
start(): void;
|
|
39
|
+
stop(): void;
|
|
40
|
+
abort(): void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface SpeechRecognitionConstructor {
|
|
44
|
+
new (): SpeechRecognitionInstance;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare global {
|
|
48
|
+
interface Window {
|
|
49
|
+
SpeechRecognition?: SpeechRecognitionConstructor;
|
|
50
|
+
webkitSpeechRecognition?: SpeechRecognitionConstructor;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const getSpeechRecognitionAPI = ():
|
|
55
|
+
| SpeechRecognitionConstructor
|
|
56
|
+
| undefined => {
|
|
57
|
+
if (typeof window === "undefined") return undefined;
|
|
58
|
+
return window.SpeechRecognition ?? window.webkitSpeechRecognition;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* WebSpeechDictationAdapter provides speech-to-text (dictation) functionality using
|
|
63
|
+
* the browser's Web Speech API (SpeechRecognition).
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```tsx
|
|
67
|
+
* const runtime = useChatRuntime({
|
|
68
|
+
* api: "/api/chat",
|
|
69
|
+
* adapters: {
|
|
70
|
+
* dictation: new WebSpeechDictationAdapter(),
|
|
71
|
+
* },
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export class WebSpeechDictationAdapter implements DictationAdapter {
|
|
76
|
+
private _language: string;
|
|
77
|
+
private _continuous: boolean;
|
|
78
|
+
private _interimResults: boolean;
|
|
79
|
+
|
|
80
|
+
constructor(
|
|
81
|
+
options: {
|
|
82
|
+
/**
|
|
83
|
+
* The language for dictation (e.g., "en-US", "zh-CN").
|
|
84
|
+
* Defaults to the browser's language.
|
|
85
|
+
*/
|
|
86
|
+
language?: string;
|
|
87
|
+
/**
|
|
88
|
+
* Whether to keep recording after the user stops speaking.
|
|
89
|
+
* Defaults to true.
|
|
90
|
+
*/
|
|
91
|
+
continuous?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Whether to return interim (partial) results.
|
|
94
|
+
* Defaults to true for real-time feedback.
|
|
95
|
+
*/
|
|
96
|
+
interimResults?: boolean;
|
|
97
|
+
} = {},
|
|
98
|
+
) {
|
|
99
|
+
const defaultLanguage =
|
|
100
|
+
typeof navigator !== "undefined" && navigator.language
|
|
101
|
+
? navigator.language
|
|
102
|
+
: "en-US";
|
|
103
|
+
this._language = options.language ?? defaultLanguage;
|
|
104
|
+
this._continuous = options.continuous ?? true;
|
|
105
|
+
this._interimResults = options.interimResults ?? true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Check if the browser supports the Web Speech Recognition API.
|
|
110
|
+
*/
|
|
111
|
+
static isSupported(): boolean {
|
|
112
|
+
return getSpeechRecognitionAPI() !== undefined;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
listen(): DictationAdapter.Session {
|
|
116
|
+
const SpeechRecognitionAPI = getSpeechRecognitionAPI();
|
|
117
|
+
if (!SpeechRecognitionAPI) {
|
|
118
|
+
throw new Error(
|
|
119
|
+
"SpeechRecognition is not supported in this browser. " +
|
|
120
|
+
"Try using Chrome, Edge, or Safari.",
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const recognition = new SpeechRecognitionAPI();
|
|
125
|
+
recognition.lang = this._language;
|
|
126
|
+
recognition.continuous = this._continuous;
|
|
127
|
+
recognition.interimResults = this._interimResults;
|
|
128
|
+
|
|
129
|
+
const speechStartCallbacks = new Set<() => void>();
|
|
130
|
+
const speechEndCallbacks = new Set<
|
|
131
|
+
(result: DictationAdapter.Result) => void
|
|
132
|
+
>();
|
|
133
|
+
const speechCallbacks = new Set<
|
|
134
|
+
(result: DictationAdapter.Result) => void
|
|
135
|
+
>();
|
|
136
|
+
|
|
137
|
+
let finalTranscript = "";
|
|
138
|
+
|
|
139
|
+
const session: DictationAdapter.Session = {
|
|
140
|
+
status: { type: "starting" },
|
|
141
|
+
|
|
142
|
+
stop: async () => {
|
|
143
|
+
recognition.stop();
|
|
144
|
+
return new Promise<void>((resolve) => {
|
|
145
|
+
const checkEnded = () => {
|
|
146
|
+
if (session.status.type === "ended") {
|
|
147
|
+
resolve();
|
|
148
|
+
} else {
|
|
149
|
+
setTimeout(checkEnded, 50);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
checkEnded();
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
cancel: () => {
|
|
157
|
+
recognition.abort();
|
|
158
|
+
},
|
|
159
|
+
|
|
160
|
+
onSpeechStart: (callback: () => void): Unsubscribe => {
|
|
161
|
+
speechStartCallbacks.add(callback);
|
|
162
|
+
return () => {
|
|
163
|
+
speechStartCallbacks.delete(callback);
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
onSpeechEnd: (
|
|
168
|
+
callback: (result: DictationAdapter.Result) => void,
|
|
169
|
+
): Unsubscribe => {
|
|
170
|
+
speechEndCallbacks.add(callback);
|
|
171
|
+
return () => {
|
|
172
|
+
speechEndCallbacks.delete(callback);
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
onSpeech: (
|
|
177
|
+
callback: (result: DictationAdapter.Result) => void,
|
|
178
|
+
): Unsubscribe => {
|
|
179
|
+
speechCallbacks.add(callback);
|
|
180
|
+
return () => {
|
|
181
|
+
speechCallbacks.delete(callback);
|
|
182
|
+
};
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const updateStatus = (newStatus: DictationAdapter.Status) => {
|
|
187
|
+
session.status = newStatus;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
recognition.addEventListener("speechstart", () => {
|
|
191
|
+
for (const cb of speechStartCallbacks) cb();
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
recognition.addEventListener("start", () => {
|
|
195
|
+
updateStatus({ type: "running" });
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
recognition.addEventListener("result", (event) => {
|
|
199
|
+
const speechEvent = event as unknown as SpeechRecognitionEvent;
|
|
200
|
+
|
|
201
|
+
for (
|
|
202
|
+
let i = speechEvent.resultIndex;
|
|
203
|
+
i < speechEvent.results.length;
|
|
204
|
+
i++
|
|
205
|
+
) {
|
|
206
|
+
const result = speechEvent.results[i];
|
|
207
|
+
if (!result) continue;
|
|
208
|
+
|
|
209
|
+
const transcript = result[0]?.transcript ?? "";
|
|
210
|
+
|
|
211
|
+
if (result.isFinal) {
|
|
212
|
+
finalTranscript += transcript;
|
|
213
|
+
for (const cb of speechCallbacks) cb({ transcript, isFinal: true });
|
|
214
|
+
} else {
|
|
215
|
+
for (const cb of speechCallbacks) cb({ transcript, isFinal: false });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
recognition.addEventListener("speechend", () => {
|
|
221
|
+
// speechend fires when user stops speaking, but 'end' handles final cleanup
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
recognition.addEventListener("end", () => {
|
|
225
|
+
const currentStatus = session.status;
|
|
226
|
+
if (currentStatus.type !== "ended") {
|
|
227
|
+
updateStatus({ type: "ended", reason: "stopped" });
|
|
228
|
+
}
|
|
229
|
+
if (finalTranscript) {
|
|
230
|
+
for (const cb of speechEndCallbacks)
|
|
231
|
+
cb({ transcript: finalTranscript });
|
|
232
|
+
finalTranscript = "";
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
recognition.addEventListener("error", (event) => {
|
|
237
|
+
const errorEvent = event as unknown as SpeechRecognitionErrorEvent;
|
|
238
|
+
if (errorEvent.error === "aborted") {
|
|
239
|
+
updateStatus({ type: "ended", reason: "cancelled" });
|
|
240
|
+
} else {
|
|
241
|
+
updateStatus({ type: "ended", reason: "error" });
|
|
242
|
+
console.error("Dictation error:", errorEvent.error, errorEvent.message);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
try {
|
|
247
|
+
recognition.start();
|
|
248
|
+
} catch (error) {
|
|
249
|
+
updateStatus({ type: "ended", reason: "error" });
|
|
250
|
+
throw error;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return session;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type {
|
|
2
|
+
SpeechSynthesisAdapter,
|
|
3
|
+
DictationAdapter,
|
|
4
|
+
} from "./SpeechAdapterTypes";
|
|
2
5
|
export { WebSpeechSynthesisAdapter } from "./WebSpeechSynthesisAdapter";
|
|
6
|
+
export { WebSpeechDictationAdapter } from "./WebSpeechDictationAdapter";
|
|
@@ -88,7 +88,7 @@ export type AssistantTransportOptions<T> = {
|
|
|
88
88
|
protocol?: AssistantTransportProtocol;
|
|
89
89
|
converter: AssistantTransportStateConverter<T>;
|
|
90
90
|
headers: HeadersValue | (() => Promise<HeadersValue>);
|
|
91
|
-
body?: object;
|
|
91
|
+
body?: object | (() => Promise<object | undefined>);
|
|
92
92
|
onResponse?: (response: Response) => void;
|
|
93
93
|
onFinish?: () => void;
|
|
94
94
|
onError?: (
|
package/src/legacy-runtime/runtime-cores/assistant-transport/useAssistantTransportRuntime.tsx
CHANGED
|
@@ -97,6 +97,10 @@ const useAssistantTransportThreadRuntime = <T,>(
|
|
|
97
97
|
throw new Error("No commands to send");
|
|
98
98
|
|
|
99
99
|
const headers = await createRequestHeaders(options.headers);
|
|
100
|
+
const bodyValue =
|
|
101
|
+
typeof options.body === "function"
|
|
102
|
+
? await options.body()
|
|
103
|
+
: options.body;
|
|
100
104
|
const context = runtime.thread.getModelContext();
|
|
101
105
|
|
|
102
106
|
const response = await fetch(
|
|
@@ -113,7 +117,7 @@ const useAssistantTransportThreadRuntime = <T,>(
|
|
|
113
117
|
: undefined,
|
|
114
118
|
...context.callSettings,
|
|
115
119
|
...context.config,
|
|
116
|
-
...
|
|
120
|
+
...(bodyValue ?? {}),
|
|
117
121
|
}),
|
|
118
122
|
signal,
|
|
119
123
|
},
|