@athenaintel/react 0.23.1 → 0.23.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +45 -2
  2. package/dist/chat/AthenaChat.cjs +132 -39
  3. package/dist/chat/AthenaChat.cjs.map +1 -1
  4. package/dist/chat/AthenaChat.d.ts +37 -4
  5. package/dist/chat/AthenaChat.js +133 -40
  6. package/dist/chat/AthenaChat.js.map +1 -1
  7. package/dist/chat/athena-composer-controls.js +1 -1
  8. package/dist/chat/statewire-client-tools.cjs +20 -0
  9. package/dist/chat/statewire-client-tools.cjs.map +1 -1
  10. package/dist/chat/statewire-client-tools.d.ts +27 -0
  11. package/dist/chat/statewire-client-tools.js +20 -0
  12. package/dist/chat/statewire-client-tools.js.map +1 -1
  13. package/dist/chat/use-athena-run-live.cjs.map +1 -1
  14. package/dist/chat/use-athena-run-live.d.ts +7 -0
  15. package/dist/chat/use-athena-run-live.js.map +1 -1
  16. package/dist/chat-ui/composer/tiptap-composer.cjs +16 -1
  17. package/dist/chat-ui/composer/tiptap-composer.cjs.map +1 -1
  18. package/dist/chat-ui/composer/tiptap-composer.js +16 -1
  19. package/dist/chat-ui/composer/tiptap-composer.js.map +1 -1
  20. package/dist/composer/composer-handoff.cjs +121 -0
  21. package/dist/composer/composer-handoff.cjs.map +1 -0
  22. package/dist/composer/composer-handoff.d.ts +89 -0
  23. package/dist/composer/composer-handoff.js +121 -0
  24. package/dist/composer/composer-handoff.js.map +1 -0
  25. package/dist/composer/index.d.ts +2 -0
  26. package/dist/composer/useAppendToComposer.cjs +19 -7
  27. package/dist/composer/useAppendToComposer.cjs.map +1 -1
  28. package/dist/composer/useAppendToComposer.d.ts +22 -4
  29. package/dist/composer/useAppendToComposer.js +20 -8
  30. package/dist/composer/useAppendToComposer.js.map +1 -1
  31. package/dist/composer/useSendMessage.cjs +26 -8
  32. package/dist/composer/useSendMessage.cjs.map +1 -1
  33. package/dist/composer/useSendMessage.d.ts +8 -0
  34. package/dist/composer/useSendMessage.js +27 -9
  35. package/dist/composer/useSendMessage.js.map +1 -1
  36. package/dist/diagnostics/athena-diagnostics.cjs.map +1 -1
  37. package/dist/diagnostics/athena-diagnostics.d.ts +1 -1
  38. package/dist/diagnostics/athena-diagnostics.js.map +1 -1
  39. package/dist/diagnostics/errors.cjs +2 -0
  40. package/dist/diagnostics/errors.cjs.map +1 -1
  41. package/dist/diagnostics/errors.d.ts +2 -0
  42. package/dist/diagnostics/errors.js +2 -0
  43. package/dist/diagnostics/errors.js.map +1 -1
  44. package/dist/dictation/DictationStrip.cjs +60 -0
  45. package/dist/dictation/DictationStrip.cjs.map +1 -0
  46. package/dist/dictation/DictationStrip.d.ts +25 -0
  47. package/dist/dictation/DictationStrip.js +60 -0
  48. package/dist/dictation/DictationStrip.js.map +1 -0
  49. package/dist/dictation/audio-level-history.cjs +68 -0
  50. package/dist/dictation/audio-level-history.cjs.map +1 -0
  51. package/dist/dictation/audio-level-history.d.ts +27 -0
  52. package/dist/dictation/audio-level-history.js +68 -0
  53. package/dist/dictation/audio-level-history.js.map +1 -0
  54. package/dist/dictation/dictation-controls.cjs +60 -0
  55. package/dist/dictation/dictation-controls.cjs.map +1 -0
  56. package/dist/dictation/dictation-controls.d.ts +15 -0
  57. package/dist/dictation/dictation-controls.js +60 -0
  58. package/dist/dictation/dictation-controls.js.map +1 -0
  59. package/dist/dictation/dictation-engine.cjs +128 -0
  60. package/dist/dictation/dictation-engine.cjs.map +1 -0
  61. package/dist/dictation/dictation-engine.d.ts +87 -0
  62. package/dist/dictation/dictation-engine.js +128 -0
  63. package/dist/dictation/dictation-engine.js.map +1 -0
  64. package/dist/dictation/dictation-state.cjs +68 -0
  65. package/dist/dictation/dictation-state.cjs.map +1 -0
  66. package/dist/dictation/dictation-state.d.ts +58 -0
  67. package/dist/dictation/dictation-state.js +68 -0
  68. package/dist/dictation/dictation-state.js.map +1 -0
  69. package/dist/dictation/use-dictation.cjs +204 -0
  70. package/dist/dictation/use-dictation.cjs.map +1 -0
  71. package/dist/dictation/use-dictation.d.ts +47 -0
  72. package/dist/dictation/use-dictation.js +204 -0
  73. package/dist/dictation/use-dictation.js.map +1 -0
  74. package/dist/index.cjs +13 -0
  75. package/dist/index.cjs.map +1 -1
  76. package/dist/index.d.ts +11 -0
  77. package/dist/index.js +13 -0
  78. package/dist/index.js.map +1 -1
  79. package/dist/packages/react/package.json.cjs +1 -1
  80. package/dist/packages/react/package.json.js +1 -1
  81. package/dist/provider/AthenaProvider.cjs +42 -3
  82. package/dist/provider/AthenaProvider.cjs.map +1 -1
  83. package/dist/provider/AthenaProvider.d.ts +1 -1
  84. package/dist/provider/AthenaProvider.js +43 -4
  85. package/dist/provider/AthenaProvider.js.map +1 -1
  86. package/dist/styles.css +1 -1
  87. package/package.json +1 -1
@@ -0,0 +1,47 @@
1
+ import { type DictationEngine, type DictationEngineError } from './dictation-engine';
2
+ import { type DictationStatus, type DictationTranscript } from './dictation-state';
3
+ export interface UseDictationOptions {
4
+ /** Speech engine. Defaults to the browser's Web Speech API. */
5
+ engine?: DictationEngine;
6
+ /** BCP-47 language tag. Defaults to the document language, else `en-US`. */
7
+ lang?: string;
8
+ /**
9
+ * Open the microphone through `getUserMedia` so callers get a `stream` for
10
+ * a waveform. Web Speech opens its own capture; this second capture is
11
+ * what the level meter reads. Defaults to true.
12
+ */
13
+ captureStream?: boolean;
14
+ /**
15
+ * The engine ended on its own (silence window, recognizer timeout) while
16
+ * listening, without `stop()` or `cancel()`. Receives the spoken text so
17
+ * the words are not lost; the composer puts them into the draft.
18
+ */
19
+ onAutoEnd?: (spoken: string) => void;
20
+ }
21
+ export interface DictationController {
22
+ status: DictationStatus;
23
+ /** True while starting, listening or stopping. */
24
+ isActive: boolean;
25
+ transcript: DictationTranscript;
26
+ /** `final` plus the interim tail, ready to hand to the composer. */
27
+ text: string;
28
+ error: DictationEngineError | null;
29
+ /** The microphone stream while active (for a waveform), else null. */
30
+ stream: MediaStream | null;
31
+ /** Whether the engine can run here. Hide the control when false. */
32
+ isSupported: boolean;
33
+ start: () => void;
34
+ /**
35
+ * Finish recording. Resolves with the spoken text once the engine has
36
+ * flushed (bounded wait), so trailing words are not lost.
37
+ */
38
+ stop: () => Promise<string>;
39
+ /** Discard the session and its transcript. */
40
+ cancel: () => void;
41
+ }
42
+ /**
43
+ * Drive a dictation session: microphone, speech engine, and the transcript
44
+ * state machine. The composer renders the waveform from `stream` and the
45
+ * live caption from `transcript`; on `stop()` it appends `text` to the draft.
46
+ */
47
+ export declare function useDictation(options?: UseDictationOptions): DictationController;
@@ -0,0 +1,204 @@
1
+ import { useMemo, useReducer, useState, useRef, useEffect, useCallback } from "react";
2
+ import { athenaDiagnostics } from "../diagnostics/athena-diagnostics.js";
3
+ import { createWebSpeechDictationEngine, DICTATION_ENGINE_ERROR_KINDS } from "./dictation-engine.js";
4
+ import { dictationReducer, INITIAL_DICTATION_STATE, DICTATION_STATUSES, spokenText, joinSpeech } from "./dictation-state.js";
5
+ const STOP_FLUSH_TIMEOUT_MS = 1500;
6
+ const EMPTY_TRANSCRIPT = { final: "", interim: "" };
7
+ function documentLanguage() {
8
+ if (typeof document !== "undefined" && document.documentElement.lang) {
9
+ return document.documentElement.lang;
10
+ }
11
+ if (typeof navigator !== "undefined" && navigator.language) return navigator.language;
12
+ return "en-US";
13
+ }
14
+ async function openMicrophone() {
15
+ var _a;
16
+ if (typeof navigator === "undefined" || !((_a = navigator.mediaDevices) == null ? void 0 : _a.getUserMedia)) return null;
17
+ return navigator.mediaDevices.getUserMedia({ audio: true });
18
+ }
19
+ function releaseStream(stream) {
20
+ if (!stream) return;
21
+ for (const track of stream.getTracks()) track.stop();
22
+ }
23
+ function useDictation(options = {}) {
24
+ const engine = useMemo(() => options.engine ?? createWebSpeechDictationEngine(), [options.engine]);
25
+ const { lang, captureStream = true, onAutoEnd } = options;
26
+ const [state, dispatch] = useReducer(dictationReducer, INITIAL_DICTATION_STATE);
27
+ const [stream, setStream] = useState(null);
28
+ const [isSupported, setIsSupported] = useState(false);
29
+ const sessionRef = useRef(null);
30
+ const streamRef = useRef(null);
31
+ const stateRef = useRef(state);
32
+ stateRef.current = state;
33
+ const transcriptRef = useRef(EMPTY_TRANSCRIPT);
34
+ const onAutoEndRef = useRef(onAutoEnd);
35
+ onAutoEndRef.current = onAutoEnd;
36
+ const stopWaitersRef = useRef([]);
37
+ const generationRef = useRef(0);
38
+ useEffect(() => {
39
+ setIsSupported(engine.isSupported());
40
+ }, [engine]);
41
+ const settleWaiters = useCallback((spoken) => {
42
+ const waiters = stopWaitersRef.current;
43
+ stopWaitersRef.current = [];
44
+ for (const resolve of waiters) resolve(spoken);
45
+ }, []);
46
+ const releaseSession = useCallback(() => {
47
+ sessionRef.current = null;
48
+ releaseStream(streamRef.current);
49
+ streamRef.current = null;
50
+ setStream(null);
51
+ }, []);
52
+ const teardown = useCallback(() => {
53
+ var _a;
54
+ generationRef.current += 1;
55
+ (_a = sessionRef.current) == null ? void 0 : _a.abort();
56
+ releaseSession();
57
+ transcriptRef.current = EMPTY_TRANSCRIPT;
58
+ settleWaiters("");
59
+ }, [releaseSession, settleWaiters]);
60
+ const reportEngineError = useCallback(
61
+ (engineError) => {
62
+ athenaDiagnostics.emit("composer.dictation", {
63
+ level: "warn",
64
+ data: { phase: "error", engine: engine.id, kind: engineError.kind }
65
+ });
66
+ dispatch({ type: "error", error: engineError });
67
+ },
68
+ [engine.id]
69
+ );
70
+ const start = useCallback(() => {
71
+ if (sessionRef.current) return;
72
+ const generation = generationRef.current + 1;
73
+ generationRef.current = generation;
74
+ transcriptRef.current = EMPTY_TRANSCRIPT;
75
+ dispatch({ type: "start" });
76
+ athenaDiagnostics.emit("composer.dictation", {
77
+ level: "debug",
78
+ data: { phase: "start", engine: engine.id }
79
+ });
80
+ const run = async () => {
81
+ let microphone = null;
82
+ if (captureStream) {
83
+ try {
84
+ microphone = await openMicrophone();
85
+ } catch (error) {
86
+ if (generationRef.current !== generation) {
87
+ releaseStream(microphone);
88
+ return;
89
+ }
90
+ dispatch({
91
+ type: "error",
92
+ error: {
93
+ kind: DICTATION_ENGINE_ERROR_KINDS.permission,
94
+ message: error instanceof DOMException && error.name === "NotFoundError" ? "No microphone was found." : "Microphone access was denied. Allow the microphone for this site and try again."
95
+ }
96
+ });
97
+ return;
98
+ }
99
+ }
100
+ if (generationRef.current !== generation) {
101
+ releaseStream(microphone);
102
+ return;
103
+ }
104
+ streamRef.current = microphone;
105
+ setStream(microphone);
106
+ let terminated = false;
107
+ const endSession = () => {
108
+ var _a;
109
+ terminated = true;
110
+ const current = stateRef.current;
111
+ const spoken = spokenText(transcriptRef.current);
112
+ const endedOnItsOwn = stopWaitersRef.current.length === 0 && current.status === DICTATION_STATUSES.listening;
113
+ dispatch({ type: "ended" });
114
+ releaseSession();
115
+ settleWaiters(spoken);
116
+ if (endedOnItsOwn) (_a = onAutoEndRef.current) == null ? void 0 : _a.call(onAutoEndRef, spoken);
117
+ };
118
+ let session;
119
+ try {
120
+ session = engine.start({
121
+ stream: microphone,
122
+ lang: lang ?? documentLanguage(),
123
+ callbacks: {
124
+ onTranscript: (update) => {
125
+ if (generationRef.current !== generation) return;
126
+ transcriptRef.current = {
127
+ final: joinSpeech(transcriptRef.current.final, update.final),
128
+ interim: update.interim
129
+ };
130
+ dispatch({ type: "transcript", update });
131
+ },
132
+ onError: (engineError) => {
133
+ if (generationRef.current !== generation) return;
134
+ if (engineError.kind === DICTATION_ENGINE_ERROR_KINDS.noSpeech) return;
135
+ reportEngineError(engineError);
136
+ },
137
+ onEnd: () => {
138
+ if (generationRef.current !== generation) return;
139
+ endSession();
140
+ }
141
+ }
142
+ });
143
+ } catch (error) {
144
+ releaseSession();
145
+ reportEngineError({
146
+ kind: DICTATION_ENGINE_ERROR_KINDS.connection,
147
+ message: error instanceof Error ? error.message : "Dictation could not start."
148
+ });
149
+ return;
150
+ }
151
+ if (terminated) return;
152
+ sessionRef.current = session;
153
+ dispatch({ type: "listening" });
154
+ };
155
+ void run();
156
+ }, [captureStream, engine, lang, releaseSession, reportEngineError, settleWaiters]);
157
+ const stop = useCallback(() => {
158
+ const session = sessionRef.current;
159
+ if (!session) {
160
+ if (stateRef.current.status === DICTATION_STATUSES.starting) {
161
+ teardown();
162
+ dispatch({ type: "cancel" });
163
+ return Promise.resolve("");
164
+ }
165
+ return Promise.resolve(spokenText(transcriptRef.current));
166
+ }
167
+ dispatch({ type: "stop" });
168
+ const flushed = new Promise((resolve) => {
169
+ stopWaitersRef.current.push(resolve);
170
+ window.setTimeout(() => {
171
+ if (sessionRef.current === session) {
172
+ session.abort();
173
+ dispatch({ type: "ended" });
174
+ releaseSession();
175
+ settleWaiters(spokenText(transcriptRef.current));
176
+ }
177
+ }, STOP_FLUSH_TIMEOUT_MS);
178
+ });
179
+ session.stop();
180
+ return flushed;
181
+ }, [releaseSession, settleWaiters, teardown]);
182
+ const cancel = useCallback(() => {
183
+ teardown();
184
+ dispatch({ type: "cancel" });
185
+ }, [teardown]);
186
+ useEffect(() => () => teardown(), [teardown]);
187
+ const isActive = state.status === DICTATION_STATUSES.starting || state.status === DICTATION_STATUSES.listening || state.status === DICTATION_STATUSES.stopping;
188
+ return {
189
+ status: state.status,
190
+ isActive,
191
+ transcript: state.transcript,
192
+ text: spokenText(state.transcript),
193
+ error: state.error,
194
+ stream,
195
+ isSupported,
196
+ start,
197
+ stop,
198
+ cancel
199
+ };
200
+ }
201
+ export {
202
+ useDictation
203
+ };
204
+ //# sourceMappingURL=use-dictation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-dictation.js","sources":["../../src/dictation/use-dictation.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react';\nimport { athenaDiagnostics } from '../diagnostics/athena-diagnostics';\nimport {\n createWebSpeechDictationEngine,\n DICTATION_ENGINE_ERROR_KINDS,\n type DictationEngine,\n type DictationEngineError,\n type DictationEngineSession,\n} from './dictation-engine';\nimport {\n DICTATION_STATUSES,\n dictationReducer,\n INITIAL_DICTATION_STATE,\n joinSpeech,\n spokenText,\n type DictationStatus,\n type DictationTranscript,\n} from './dictation-state';\n\nexport interface UseDictationOptions {\n /** Speech engine. Defaults to the browser's Web Speech API. */\n engine?: DictationEngine;\n /** BCP-47 language tag. Defaults to the document language, else `en-US`. */\n lang?: string;\n /**\n * Open the microphone through `getUserMedia` so callers get a `stream` for\n * a waveform. Web Speech opens its own capture; this second capture is\n * what the level meter reads. Defaults to true.\n */\n captureStream?: boolean;\n /**\n * The engine ended on its own (silence window, recognizer timeout) while\n * listening, without `stop()` or `cancel()`. Receives the spoken text so\n * the words are not lost; the composer puts them into the draft.\n */\n onAutoEnd?: (spoken: string) => void;\n}\n\nexport interface DictationController {\n status: DictationStatus;\n /** True while starting, listening or stopping. */\n isActive: boolean;\n transcript: DictationTranscript;\n /** `final` plus the interim tail, ready to hand to the composer. */\n text: string;\n error: DictationEngineError | null;\n /** The microphone stream while active (for a waveform), else null. */\n stream: MediaStream | null;\n /** Whether the engine can run here. Hide the control when false. */\n isSupported: boolean;\n start: () => void;\n /**\n * Finish recording. Resolves with the spoken text once the engine has\n * flushed (bounded wait), so trailing words are not lost.\n */\n stop: () => Promise<string>;\n /** Discard the session and its transcript. */\n cancel: () => void;\n}\n\n/** How long `stop()` waits for the engine's final flush before giving up. */\nconst STOP_FLUSH_TIMEOUT_MS = 1500;\n\ntype StopResolver = (spoken: string) => void;\n\nconst EMPTY_TRANSCRIPT: DictationTranscript = { final: '', interim: '' };\n\nfunction documentLanguage(): string {\n if (typeof document !== 'undefined' && document.documentElement.lang) {\n return document.documentElement.lang;\n }\n if (typeof navigator !== 'undefined' && navigator.language) return navigator.language;\n return 'en-US';\n}\n\nasync function openMicrophone(): Promise<MediaStream | null> {\n if (typeof navigator === 'undefined' || !navigator.mediaDevices?.getUserMedia) return null;\n return navigator.mediaDevices.getUserMedia({ audio: true });\n}\n\nfunction releaseStream(stream: MediaStream | null): void {\n if (!stream) return;\n for (const track of stream.getTracks()) track.stop();\n}\n\n/**\n * Drive a dictation session: microphone, speech engine, and the transcript\n * state machine. The composer renders the waveform from `stream` and the\n * live caption from `transcript`; on `stop()` it appends `text` to the draft.\n */\nexport function useDictation(options: UseDictationOptions = {}): DictationController {\n const engine = useMemo(() => options.engine ?? createWebSpeechDictationEngine(), [options.engine]);\n const { lang, captureStream = true, onAutoEnd } = options;\n const [state, dispatch] = useReducer(dictationReducer, INITIAL_DICTATION_STATE);\n const [stream, setStream] = useState<MediaStream | null>(null);\n const [isSupported, setIsSupported] = useState(false);\n\n const sessionRef = useRef<DictationEngineSession | null>(null);\n const streamRef = useRef<MediaStream | null>(null);\n const stateRef = useRef(state);\n stateRef.current = state;\n // The authoritative transcript, updated synchronously as the engine reports\n // it. The reducer's copy renders the caption; this one is what `stop()` and\n // `onAutoEnd` hand over, so an engine that flushes its last words and ends\n // in the same tick — before React has rendered — loses nothing.\n const transcriptRef = useRef<DictationTranscript>(EMPTY_TRANSCRIPT);\n const onAutoEndRef = useRef(onAutoEnd);\n onAutoEndRef.current = onAutoEnd;\n // stop() callers waiting for the engine's final flush.\n const stopWaitersRef = useRef<StopResolver[]>([]);\n // Distinguishes a fresh session from the callbacks of a torn-down one.\n const generationRef = useRef(0);\n\n useEffect(() => {\n setIsSupported(engine.isSupported());\n }, [engine]);\n\n const settleWaiters = useCallback((spoken: string) => {\n const waiters = stopWaitersRef.current;\n stopWaitersRef.current = [];\n for (const resolve of waiters) resolve(spoken);\n }, []);\n\n const releaseSession = useCallback(() => {\n sessionRef.current = null;\n releaseStream(streamRef.current);\n streamRef.current = null;\n setStream(null);\n }, []);\n\n const teardown = useCallback(() => {\n generationRef.current += 1;\n sessionRef.current?.abort();\n releaseSession();\n transcriptRef.current = EMPTY_TRANSCRIPT;\n settleWaiters('');\n }, [releaseSession, settleWaiters]);\n\n const reportEngineError = useCallback(\n (engineError: DictationEngineError) => {\n athenaDiagnostics.emit('composer.dictation', {\n level: 'warn',\n data: { phase: 'error', engine: engine.id, kind: engineError.kind },\n });\n dispatch({ type: 'error', error: engineError });\n },\n [engine.id],\n );\n\n const start = useCallback(() => {\n if (sessionRef.current) return;\n const generation = generationRef.current + 1;\n generationRef.current = generation;\n transcriptRef.current = EMPTY_TRANSCRIPT;\n dispatch({ type: 'start' });\n athenaDiagnostics.emit('composer.dictation', {\n level: 'debug',\n data: { phase: 'start', engine: engine.id },\n });\n\n const run = async () => {\n let microphone: MediaStream | null = null;\n if (captureStream) {\n try {\n microphone = await openMicrophone();\n } catch (error) {\n if (generationRef.current !== generation) {\n releaseStream(microphone);\n return;\n }\n dispatch({\n type: 'error',\n error: {\n kind: DICTATION_ENGINE_ERROR_KINDS.permission,\n message:\n error instanceof DOMException && error.name === 'NotFoundError'\n ? 'No microphone was found.'\n : 'Microphone access was denied. Allow the microphone for this site and try again.',\n },\n });\n return;\n }\n }\n if (generationRef.current !== generation) {\n releaseStream(microphone);\n return;\n }\n streamRef.current = microphone;\n setStream(microphone);\n\n // An engine may fail synchronously inside start() (Web Speech throws\n // when recognition.start() is refused) and run onError/onEnd before we\n // hold the session. Those callbacks flip this flag so a dead session is\n // never stored, which would make every later mic click return early.\n let terminated = false;\n const endSession = () => {\n terminated = true;\n const current = stateRef.current;\n const spoken = spokenText(transcriptRef.current);\n // No stop() is waiting: the engine gave up on its own. Hand the\n // words over so they land in the draft instead of vanishing.\n const endedOnItsOwn =\n stopWaitersRef.current.length === 0 && current.status === DICTATION_STATUSES.listening;\n // The reducer keeps an error status through 'ended', so an error\n // reported just before the engine closed stays on screen.\n dispatch({ type: 'ended' });\n releaseSession();\n settleWaiters(spoken);\n if (endedOnItsOwn) onAutoEndRef.current?.(spoken);\n };\n let session: DictationEngineSession;\n try {\n session = engine.start({\n stream: microphone,\n lang: lang ?? documentLanguage(),\n callbacks: {\n onTranscript: (update) => {\n if (generationRef.current !== generation) return;\n transcriptRef.current = {\n final: joinSpeech(transcriptRef.current.final, update.final),\n interim: update.interim,\n };\n dispatch({ type: 'transcript', update });\n },\n onError: (engineError) => {\n if (generationRef.current !== generation) return;\n // A silence timeout is the engine giving up politely; keep the\n // words we have instead of showing an error.\n if (engineError.kind === DICTATION_ENGINE_ERROR_KINDS.noSpeech) return;\n reportEngineError(engineError);\n },\n onEnd: () => {\n if (generationRef.current !== generation) return;\n endSession();\n },\n },\n });\n } catch (error) {\n // A relay engine that cannot build its session must not strand the\n // microphone or leave the composer in `starting`.\n releaseSession();\n reportEngineError({\n kind: DICTATION_ENGINE_ERROR_KINDS.connection,\n message: error instanceof Error ? error.message : 'Dictation could not start.',\n });\n return;\n }\n if (terminated) return;\n sessionRef.current = session;\n dispatch({ type: 'listening' });\n };\n void run();\n }, [captureStream, engine, lang, releaseSession, reportEngineError, settleWaiters]);\n\n const stop = useCallback((): Promise<string> => {\n const session = sessionRef.current;\n if (!session) {\n // Stopped while the microphone prompt was still open: nothing was heard\n // yet, and the pending start must not bring the engine up afterwards.\n if (stateRef.current.status === DICTATION_STATUSES.starting) {\n teardown();\n dispatch({ type: 'cancel' });\n return Promise.resolve('');\n }\n return Promise.resolve(spokenText(transcriptRef.current));\n }\n dispatch({ type: 'stop' });\n const flushed = new Promise<string>((resolve) => {\n stopWaitersRef.current.push(resolve);\n window.setTimeout(() => {\n // Bounded wait: a recognizer that never fires onend must not hold the\n // composer hostage. Force the session closed and hand over what was\n // heard so far.\n if (sessionRef.current === session) {\n session.abort();\n dispatch({ type: 'ended' });\n releaseSession();\n settleWaiters(spokenText(transcriptRef.current));\n }\n }, STOP_FLUSH_TIMEOUT_MS);\n });\n session.stop();\n return flushed;\n }, [releaseSession, settleWaiters, teardown]);\n\n const cancel = useCallback(() => {\n teardown();\n dispatch({ type: 'cancel' });\n }, [teardown]);\n\n // Release the microphone with the component.\n useEffect(() => () => teardown(), [teardown]);\n\n const isActive =\n state.status === DICTATION_STATUSES.starting ||\n state.status === DICTATION_STATUSES.listening ||\n state.status === DICTATION_STATUSES.stopping;\n\n return {\n status: state.status,\n isActive,\n transcript: state.transcript,\n text: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AQ,MAAM;AAAA,IACd;AAAA,IACA,YAAY,MAAM;AAAA,IAClB,MAAM,WAAW,MAAM,UAAU;AAAA,IACjC,OAAO,MAAM;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}
package/dist/index.cjs CHANGED
@@ -88,7 +88,12 @@ const threadPrefetcher = require("./threads/thread-prefetcher.cjs");
88
88
  const useRestConversationHistory = require("./threads/use-rest-conversation-history.cjs");
89
89
  const useStatewireConversationHistory = require("./threads/use-statewire-conversation-history.cjs");
90
90
  const useAthenaThreadManager = require("./threads/useAthenaThreadManager.cjs");
91
+ const useDictation = require("./dictation/use-dictation.cjs");
92
+ const DictationStrip = require("./dictation/DictationStrip.cjs");
93
+ const dictationEngine = require("./dictation/dictation-engine.cjs");
94
+ const dictationState = require("./dictation/dictation-state.cjs");
91
95
  const useAppendToComposer = require("./composer/useAppendToComposer.cjs");
96
+ const composerHandoff = require("./composer/composer-handoff.cjs");
92
97
  const useSendMessage = require("./composer/useSendMessage.cjs");
93
98
  const useComposerAttachment = require("./composer/useComposerAttachment.cjs");
94
99
  const useFileUpload = require("./composer/useFileUpload.cjs");
@@ -300,7 +305,15 @@ exports.useRestConversationHistory = useRestConversationHistory.useRestConversat
300
305
  exports.conversationSummaryFromIndexEntry = useStatewireConversationHistory.conversationSummaryFromIndexEntry;
301
306
  exports.useStatewireConversationHistory = useStatewireConversationHistory.useStatewireConversationHistory;
302
307
  exports.useAthenaThreadManager = useAthenaThreadManager.useAthenaThreadManager;
308
+ exports.useDictation = useDictation.useDictation;
309
+ exports.DictationStrip = DictationStrip.DictationStrip;
310
+ exports.DictationWaveform = DictationStrip.DictationWaveform;
311
+ exports.DICTATION_ENGINE_ERROR_KINDS = dictationEngine.DICTATION_ENGINE_ERROR_KINDS;
312
+ exports.createWebSpeechDictationEngine = dictationEngine.createWebSpeechDictationEngine;
313
+ exports.DICTATION_STATUSES = dictationState.DICTATION_STATUSES;
314
+ exports.composeDictationDraft = dictationState.composeDictationDraft;
303
315
  exports.useAppendToComposer = useAppendToComposer.useAppendToComposer;
316
+ exports.useComposerReady = composerHandoff.useComposerReady;
304
317
  exports.useSendMessage = useSendMessage.useSendMessage;
305
318
  exports.useComposerAttachment = useComposerAttachment.useComposerAttachment;
306
319
  exports.useFileUpload = useFileUpload.useFileUpload;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -114,7 +114,18 @@ export { conversationDisplayTitle, useRestConversationHistory, type RestConversa
114
114
  export { conversationSummaryFromIndexEntry, useStatewireConversationHistory, type UseStatewireConversationHistoryOptions, } from './threads/use-statewire-conversation-history';
115
115
  export { useAthenaThreadManager } from './threads/useAthenaThreadManager';
116
116
  export type { AthenaThreadManagerState } from './threads/useAthenaThreadManager';
117
+ export { useDictation } from './dictation/use-dictation';
118
+ export type { DictationController, UseDictationOptions } from './dictation/use-dictation';
119
+ export { DictationStrip, DictationWaveform } from './dictation/DictationStrip';
120
+ export type { DictationStripProps } from './dictation/DictationStrip';
121
+ export { createWebSpeechDictationEngine, DICTATION_ENGINE_ERROR_KINDS, } from './dictation/dictation-engine';
122
+ export type { DictationEngine, DictationEngineCallbacks, DictationEngineError, DictationEngineErrorKind, DictationEngineSession, DictationTranscriptUpdate, } from './dictation/dictation-engine';
123
+ export { composeDictationDraft, DICTATION_STATUSES } from './dictation/dictation-state';
124
+ export type { DictationStatus, DictationTranscript } from './dictation/dictation-state';
125
+ export type { AthenaChatComposerSlots, AthenaChatDictationOptions } from './chat/AthenaChat';
117
126
  export { useAppendToComposer } from './composer/useAppendToComposer';
127
+ export type { AppendToComposerOptions } from './composer/useAppendToComposer';
128
+ export { useComposerReady } from './composer/composer-handoff';
118
129
  export { useSendMessage } from './composer/useSendMessage';
119
130
  export type { SendMessageOptions } from './composer/useSendMessage';
120
131
  export { useComposerAttachment } from './composer/useComposerAttachment';
package/dist/index.js CHANGED
@@ -86,7 +86,12 @@ import { THREAD_PREFETCH_HOVER_DELAY_MS, THREAD_PREFETCH_MAX_CONCURRENT } from "
86
86
  import { conversationDisplayTitle, useRestConversationHistory } from "./threads/use-rest-conversation-history.js";
87
87
  import { conversationSummaryFromIndexEntry, useStatewireConversationHistory } from "./threads/use-statewire-conversation-history.js";
88
88
  import { useAthenaThreadManager } from "./threads/useAthenaThreadManager.js";
89
+ import { useDictation } from "./dictation/use-dictation.js";
90
+ import { DictationStrip, DictationWaveform } from "./dictation/DictationStrip.js";
91
+ import { DICTATION_ENGINE_ERROR_KINDS, createWebSpeechDictationEngine } from "./dictation/dictation-engine.js";
92
+ import { DICTATION_STATUSES, composeDictationDraft } from "./dictation/dictation-state.js";
89
93
  import { useAppendToComposer } from "./composer/useAppendToComposer.js";
94
+ import { useComposerReady } from "./composer/composer-handoff.js";
90
95
  import { useSendMessage } from "./composer/useSendMessage.js";
91
96
  import { useComposerAttachment } from "./composer/useComposerAttachment.js";
92
97
  import { useFileUpload } from "./composer/useFileUpload.js";
@@ -142,7 +147,11 @@ export {
142
147
  DEFAULT_STATEWIRE_MODEL,
143
148
  DEFAULT_STATEWIRE_SYNC_URL,
144
149
  DEFAULT_TOOLKIT_THEME,
150
+ DICTATION_ENGINE_ERROR_KINDS,
151
+ DICTATION_STATUSES,
145
152
  DescribeDatabaseToolUI,
153
+ DictationStrip,
154
+ DictationWaveform,
146
155
  EditFileToolUI,
147
156
  EmailSearchToolUI,
148
157
  ExpandableSection,
@@ -223,6 +232,7 @@ export {
223
232
  clearAutoOpenedAssets,
224
233
  cn,
225
234
  collectStatewireClientTools,
235
+ composeDictationDraft,
226
236
  conversationDisplayTitle,
227
237
  conversationSummaryFromIndexEntry,
228
238
  countActivityTools,
@@ -230,6 +240,7 @@ export {
230
240
  createAthenaSpacesUrl,
231
241
  createThread,
232
242
  createToolBasedGroupingFunction,
243
+ createWebSpeechDictationEngine,
233
244
  defaultGetToolGroupKey,
234
245
  deriveAthenaApiUrl,
235
246
  deriveAthenaAppUrl,
@@ -315,6 +326,8 @@ export {
315
326
  useAthenaThreadId,
316
327
  useAthenaThreadManager,
317
328
  useComposerAttachment,
329
+ useComposerReady,
330
+ useDictation,
318
331
  useFileUpload,
319
332
  useLatestTodoPlan,
320
333
  useNestedPtcComponents,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const version = "0.23.1";
3
+ const version = "0.23.3";
4
4
  const packageJson = {
5
5
  version
6
6
  };
@@ -1,4 +1,4 @@
1
- const version = "0.23.1";
1
+ const version = "0.23.3";
2
2
  const packageJson = {
3
3
  version
4
4
  };
@@ -29,9 +29,12 @@ const statewireLifecycle = require("../runtime/statewire-lifecycle.cjs");
29
29
  const statewireRunConfig = require("../runtime/statewire-run-config.cjs");
30
30
  const mintThreadId = require("../threads/mint-thread-id.cjs");
31
31
  const statewireLifecycleContext = require("./statewire-lifecycle-context.cjs");
32
+ const composerHandoff = require("../composer/composer-handoff.cjs");
32
33
  const statewireWindowContext = require("./statewire-window-context.cjs");
33
34
  const StatewireClientToolBridge = require("../chat/StatewireClientToolBridge.cjs");
34
35
  const athenaDiagnostics = require("../diagnostics/athena-diagnostics.cjs");
36
+ const errors = require("../diagnostics/errors.cjs");
37
+ const statewireClientTools = require("../chat/statewire-client-tools.cjs");
35
38
  const tooltip = require("../ui/tooltip.cjs");
36
39
  const autoOpenTools = require("../tools/auto-open-tools.cjs");
37
40
  const AthenaContext = require("./AthenaContext.cjs");
@@ -89,6 +92,17 @@ const useAthenaConfigValue = ({
89
92
  [backendUrl, appUrl, apiKey, enabledToolkits]
90
93
  );
91
94
  };
95
+ function ComposerHandoffDrain() {
96
+ const aui = react$1.useAui();
97
+ const store = composerHandoff.useComposerHandoffStore();
98
+ const threadId = react.useContext(threadIdContext.AthenaStatewireThreadIdContext);
99
+ const ready = composerHandoff.useComposerReady();
100
+ react.useEffect(() => {
101
+ if (!ready || !store) return;
102
+ composerHandoff.drainComposerHandoff({ store, target: aui, threadId });
103
+ }, [aui, ready, store, threadId]);
104
+ return null;
105
+ }
92
106
  function AthenaStatewireRuntimeMount({
93
107
  threadId,
94
108
  isNewChat,
@@ -189,6 +203,21 @@ function AthenaStatewireStandalone({
189
203
  const isNewChat = (threadList == null ? void 0 : threadList.isNewChat) ?? !threadIdProp;
190
204
  const [published, setPublished] = react.useState(null);
191
205
  const clientTools = useAthenaStatewireRuntime.useStatewireClientTools(runtimeProps.frontendTools);
206
+ const clientToolNamesKey = clientTools.map((tool) => tool.definition.name).join(",");
207
+ const clientToolAppId = runtimeProps.appId;
208
+ react.useEffect(() => {
209
+ if (clientTools.length === 0 || statewireClientTools.resolveClientToolSurface(clientToolAppId) !== null) return;
210
+ athenaDiagnostics.athenaDiagnostics.emit("sdk.config.warning", {
211
+ level: "error",
212
+ error: new errors.AthenaSdkError({
213
+ code: "config_invalid",
214
+ message: `frontendTools with an execute() need a recognised appId; ${clientTools.length} tool(s) will not be bound.`,
215
+ hint: "Pass appId={publicAppId} on <AthenaProvider> (a computer-asset app reads it from athena-public-config.json as computer_asset_<uuid>). Without it the deep-agent runtime drops every client tool.",
216
+ context: { appId: clientToolAppId ?? null, tools: clientToolNamesKey.split(",") }
217
+ }),
218
+ data: { appId: clientToolAppId ?? null, tools: clientToolNamesKey.split(",") }
219
+ });
220
+ }, [clientToolAppId, clientToolNamesKey]);
192
221
  const athenaConfig = useAthenaConfigValue({
193
222
  backendUrl,
194
223
  appUrl,
@@ -201,6 +230,7 @@ function AthenaStatewireStandalone({
201
230
  });
202
231
  const scope = published && /* @__PURE__ */ jsxRuntime.jsx(react$1.AuiProvider, { value: published.client, children: /* @__PURE__ */ jsxRuntime.jsx(AthenaContext.AthenaContext.Provider, { value: athenaConfig, children: /* @__PURE__ */ jsxRuntime.jsx(threadIdContext.AthenaStatewireThreadIdContext.Provider, { value: published.threadId, children: /* @__PURE__ */ jsxRuntime.jsx(statewireLifecycleContext.AthenaStatewireLifecycleContext.Provider, { value: published.lifecycle, children: /* @__PURE__ */ jsxRuntime.jsx(threadStatus.DeepAgentConnectionContext.Provider, { value: published.lifecycle.connection, children: /* @__PURE__ */ jsxRuntime.jsx(statewireWindowContext.StatewireToolOutputsContext.Provider, { value: runtimeProps.toolOutputs, children: /* @__PURE__ */ jsxRuntime.jsxs(tooltip.TooltipProvider, { children: [
203
232
  /* @__PURE__ */ jsxRuntime.jsx(StatewireClientToolBridge.StatewireClientToolBridge, { tools: clientTools, threadId: published.threadId }),
233
+ /* @__PURE__ */ jsxRuntime.jsx(ComposerHandoffDrain, {}),
204
234
  children
205
235
  ] }) }) }) }) }) }) });
206
236
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
@@ -347,7 +377,10 @@ function AthenaProvider({
347
377
  react.useEffect(() => {
348
378
  athenaDiagnostics.athenaDiagnostics.configure(athenaDiagnostics.debugPropToDiagnosticsConfig(debug));
349
379
  }, [debugKey]);
350
- const frontendToolNames = react.useMemo(() => Object.keys(frontendTools), [frontendTools]);
380
+ const frontendToolNames = react.useMemo(
381
+ () => statewireClientTools.backendDeclaredFrontendToolIds(frontendTools),
382
+ [frontendTools]
383
+ );
351
384
  const effectiveFrontendTools = react.useMemo(
352
385
  () => disableAutoOpen ? frontendTools : { ...autoOpenTools.DEFAULT_AUTO_OPEN_TOOLS, ...frontendTools },
353
386
  [disableAutoOpen, frontendTools]
@@ -381,12 +414,18 @@ function AthenaProvider({
381
414
  const authContext = react.useContext(AthenaAuthContext.AthenaAuthContext);
382
415
  const authProviderToken = (authContext == null ? void 0 : authContext.accessToken) ?? null;
383
416
  const [snapshotCache] = react.useState(() => threadSnapshotCache.createDeepAgentThreadSnapshotCache());
417
+ const [composerHandoff$1] = react.useState(composerHandoff.createComposerHandoffStore);
384
418
  const [toolOutputs$1] = react.useState(() => toolOutputs.createDeepAgentToolOutputStore());
385
419
  const principal = ((_a = authContext == null ? void 0 : authContext.user) == null ? void 0 : _a.userId) ?? "";
386
420
  react.useEffect(() => {
387
421
  snapshotCache.clear();
388
422
  toolOutputs$1.clear();
389
- }, [snapshotCache, toolOutputs$1, principal, configuredApiKey]);
423
+ composerHandoff.clearComposerHandoff({ store: composerHandoff$1, reason: "the signed-in identity changed" });
424
+ }, [snapshotCache, toolOutputs$1, composerHandoff$1, principal, configuredApiKey]);
425
+ react.useEffect(
426
+ () => () => composerHandoff.clearComposerHandoff({ store: composerHandoff$1, reason: "the chat provider unmounted" }),
427
+ [composerHandoff$1]
428
+ );
390
429
  const effectiveToken = configuredToken !== void 0 ? configuredToken : authProviderToken ?? bridge.token;
391
430
  const effectiveApiUrl = configuredApiUrl ?? environmentUrls.apiUrl;
392
431
  const effectiveBackendUrl = mint.getAthenaApiBaseUrl(
@@ -444,7 +483,7 @@ function AthenaProvider({
444
483
  {
445
484
  className: themeStyleVars ? "athena-sdk athena-themed" : "athena-sdk",
446
485
  style: themeStyleVars,
447
- children: /* @__PURE__ */ jsxRuntime.jsx(PostHogProvider.PostHogProvider, { config: posthogConfig, children: inner })
486
+ children: /* @__PURE__ */ jsxRuntime.jsx(PostHogProvider.PostHogProvider, { config: posthogConfig, children: /* @__PURE__ */ jsxRuntime.jsx(composerHandoff.ComposerHandoffContext.Provider, { value: composerHandoff$1, children: inner }) })
448
487
  }
449
488
  );
450
489
  }