@garrix82/reactgenie-lib 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +22 -0
- package/.github/workflows/publish.yml +20 -0
- package/LICENSE.txt +201 -0
- package/README.md +621 -0
- package/babel.config.js +29 -0
- package/dist/adapters/__tests__/expo-router-adapter.test.d.ts +1 -0
- package/dist/adapters/expo-router-adapter.d.ts +16 -0
- package/dist/adapters/expo-router-adapter.js +521 -0
- package/dist/adapters/navigation-adapter.d.ts +20 -0
- package/dist/adapters/navigation-adapter.js +137 -0
- package/dist/audio-visualizer.d.ts +14 -0
- package/dist/audio-visualizer.js +123 -0
- package/dist/current-selection.d.ts +27 -0
- package/dist/current-selection.js +94 -0
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +37 -0
- package/dist/genie/DateTime.d.ts +66 -0
- package/dist/genie/DateTime.js +399 -0
- package/dist/genie/TimeDelta.d.ts +35 -0
- package/dist/genie/TimeDelta.js +169 -0
- package/dist/genie-view-wrapper.d.ts +1 -0
- package/dist/genie-view-wrapper.js +377 -0
- package/dist/hooks/__tests__/useSpeechRecognition.test.d.ts +1 -0
- package/dist/hooks/useSpeechRecognition.d.ts +28 -0
- package/dist/hooks/useSpeechRecognition.js +118 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +469 -0
- package/dist/logger.d.ts +23 -0
- package/dist/logger.js +597 -0
- package/dist/logger.remote.test.d.ts +0 -0
- package/dist/modality-provider-v2.d.ts +28 -0
- package/dist/modality-provider-v2.js +1321 -0
- package/dist/modality-provider.d.ts +22 -0
- package/dist/modality-provider.js +373 -0
- package/dist/native-visibility.d.ts +28 -0
- package/dist/native-visibility.js +50 -0
- package/dist/platform/VoiceRecognitionBar.d.ts +17 -0
- package/dist/platform/VoiceRecognitionBar.js +332 -0
- package/dist/platform/components.d.ts +32 -0
- package/dist/platform/components.js +351 -0
- package/dist/platform/events.d.ts +31 -0
- package/dist/platform/events.js +274 -0
- package/dist/platform/index.d.ts +3 -0
- package/dist/platform/index.js +39 -0
- package/dist/platform/types.d.ts +79 -0
- package/dist/platform/types.js +97 -0
- package/dist/react-decorators.d.ts +87 -0
- package/dist/react-decorators.js +368 -0
- package/dist/shared-store.d.ts +74 -0
- package/dist/shared-store.js +589 -0
- package/dist/speech-recognition/__tests__/speech-recognition-groq-transport.test.d.ts +1 -0
- package/dist/speech-recognition/__tests__/speech-recognition-native.test.d.ts +1 -0
- package/dist/speech-recognition/__tests__/speech-recognition-openai-native.test.d.ts +1 -0
- package/dist/speech-recognition/__tests__/speech-recognition-openai.test.d.ts +1 -0
- package/dist/speech-recognition/__tests__/speech-recognition-unified-import.test.d.ts +0 -0
- package/dist/speech-recognition/__tests__/speech-recognition-unified.test.d.ts +1 -0
- package/dist/speech-recognition/speech-recognition-groq.d.ts +21 -0
- package/dist/speech-recognition/speech-recognition-groq.js +409 -0
- package/dist/speech-recognition/speech-recognition-mlx.d.ts +15 -0
- package/dist/speech-recognition/speech-recognition-mlx.js +393 -0
- package/dist/speech-recognition/speech-recognition-native.d.ts +24 -0
- package/dist/speech-recognition/speech-recognition-native.js +632 -0
- package/dist/speech-recognition/speech-recognition-openai-native.d.ts +40 -0
- package/dist/speech-recognition/speech-recognition-openai-native.js +653 -0
- package/dist/speech-recognition/speech-recognition-openai.d.ts +39 -0
- package/dist/speech-recognition/speech-recognition-openai.js +718 -0
- package/dist/speech-recognition/speech-recognition-unified.d.ts +93 -0
- package/dist/speech-recognition/speech-recognition-unified.js +589 -0
- package/dist/speech-recognition/utils/groq-transcription.d.ts +41 -0
- package/dist/speech-recognition/utils/groq-transcription.js +382 -0
- package/dist/speech-recognition.d.ts +7 -0
- package/dist/speech-recognition.js +61 -0
- package/dist/voice-pipeline-telemetry.d.ts +26 -0
- package/dist/voice-pipeline-telemetry.js +15 -0
- package/garrix82-reactgenie-lib-1.3.0.tgz +0 -0
- package/metro/index.js +3 -0
- package/metro/with-genie-registry.js +47 -0
- package/package.json +111 -0
- package/scripts/dry-run.js +23 -0
- package/scripts/generate-genie-registry.js +278 -0
- package/scripts/log-file-test.js +51 -0
- package/scripts/parse.js +26 -0
- package/scripts/prompt.js +19 -0
- package/scripts/set-script.js +200 -0
- package/tsconfig.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
# ReactGenie
|
|
2
|
+
|
|
3
|
+
> React, React Native, and Expo integration for multimodal apps built on `@omkarfork/reactgenie-dsl`
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@omkarfork/reactgenie-lib)
|
|
6
|
+
[](https://standardjs.com)
|
|
7
|
+
|
|
8
|
+
> Fork notice: this package snapshot is maintained as a thesis-project fork by [Omkar Mirgal](https://github.com/OmkarMirgal). For the original ReactGenie project, see [StanfordHCI/ReactGenie](https://github.com/StanfordHCI/ReactGenie).
|
|
9
|
+
|
|
10
|
+
## Introduction
|
|
11
|
+
|
|
12
|
+
`@omkarfork/reactgenie-lib` is the React integration layer for `@omkarfork/reactgenie-dsl`.
|
|
13
|
+
|
|
14
|
+
It gives you the pieces needed to turn Genie DSL classes into a working UI runtime:
|
|
15
|
+
|
|
16
|
+
- decorator and base-class re-exports for Genie models
|
|
17
|
+
- a Redux-backed runtime bootstrap with `initReactGenie()`
|
|
18
|
+
- visible-view registration with `GenieClassInterface(...)`
|
|
19
|
+
- multimodal execution through `ModalityProvider`
|
|
20
|
+
- speech recognition support for web and native runtimes
|
|
21
|
+
- Expo Router integration helpers
|
|
22
|
+
- platform-aware voice UI, overlays, logging, and telemetry hooks
|
|
23
|
+
|
|
24
|
+
This README covers the current package surface, installation, quick start, and feature map. For deeper architecture, advanced routing details, and lower-level implementation notes, see [DEVELOPER_GUIDE.md](./DEVELOPER_GUIDE.md).
|
|
25
|
+
|
|
26
|
+
## Feature Overview
|
|
27
|
+
|
|
28
|
+
ReactGenie currently includes:
|
|
29
|
+
|
|
30
|
+
- React-oriented re-exports of the DSL decorators and base classes: `GenieClass`, `GenieFunction`, `GenieProperty`, `GenieKey`, `DataClass`, `HelperClass`, `int`, `float`
|
|
31
|
+
- runtime bootstrap with `initReactGenie()`
|
|
32
|
+
- shared store access with `useGenieSelector()` and `useGenieCodeSelector()`
|
|
33
|
+
- UI-to-object registration with `GenieClassInterface(...)`
|
|
34
|
+
- multimodal orchestration with `ModalityProvider`
|
|
35
|
+
- contextual object resolution through injected `Current()` and `AllCurrent()`
|
|
36
|
+
- speech recognition adapters for:
|
|
37
|
+
- Groq on web
|
|
38
|
+
- Groq on native via optional Expo audio/filesystem support
|
|
39
|
+
- OpenAI realtime transcription on web
|
|
40
|
+
- OpenAI realtime transcription on native via optional WebRTC support
|
|
41
|
+
- browser Web Speech fallback for Groq flows
|
|
42
|
+
- local MLX Whisper on web
|
|
43
|
+
- voice UI primitives including `VoiceRecognitionBar`, `AudioVisualizer`, and `AudioLevelIndicator`
|
|
44
|
+
- the `useSpeechRecognition()` hook for custom voice UI
|
|
45
|
+
- Expo Router helpers: `useExpoRouterAdapter()`, `withExpoRouterAdapter()`, `useRegisterGenieRoute()`, `registerGenieRoute()`
|
|
46
|
+
- platform abstraction exports for overlay, button, transcript, event, and safe-container helpers
|
|
47
|
+
- runtime diagnostics with `configureLogger()`, `setLogLevel()`, `setLoggerTelemetryBridge()`, and voice-pipeline telemetry bridges
|
|
48
|
+
- built-in helper classes `DateTime` and `TimeDelta`
|
|
49
|
+
- typed user-facing errors with `GenieUserFacingError`
|
|
50
|
+
- CLI binaries for prompt and parser experiments: `get-prompt`, `dry-run`, `set-script`, `parse`
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
Install the library and the required peer dependencies for any ReactGenie app:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install @omkarfork/reactgenie-lib @omkarfork/reactgenie-dsl react-redux redux reflect-metadata
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
If your app uses React Navigation directly, install the expected navigation peers:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npm install @react-navigation/native @react-navigation/native-stack @react-navigation/stack
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Optional peers depend on which runtime paths you want to enable:
|
|
67
|
+
|
|
68
|
+
- `expo-router` for file-based route integration
|
|
69
|
+
- `expo-audio` and `expo-file-system` for native Groq speech capture
|
|
70
|
+
- `react-native-webrtc` for native OpenAI realtime transcription
|
|
71
|
+
- `expo-speech` if your native app speaks responses aloud
|
|
72
|
+
|
|
73
|
+
### TypeScript and Babel setup
|
|
74
|
+
|
|
75
|
+
ReactGenie depends on decorator metadata. Enable the same pipeline used by ReactGenieDSL.
|
|
76
|
+
|
|
77
|
+
TypeScript:
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"compilerOptions": {
|
|
82
|
+
"experimentalDecorators": true,
|
|
83
|
+
"emitDecoratorMetadata": true,
|
|
84
|
+
"useDefineForClassFields": false
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Babel:
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
plugins: [
|
|
93
|
+
["@babel/plugin-proposal-decorators", { legacy: true }],
|
|
94
|
+
["@babel/plugin-transform-class-properties", { loose: true }],
|
|
95
|
+
"babel-plugin-parameter-decorator",
|
|
96
|
+
"babel-plugin-reactgenie"
|
|
97
|
+
]
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Import `reflect-metadata` before any decorated Genie classes are evaluated.
|
|
101
|
+
|
|
102
|
+
## Quick Start
|
|
103
|
+
|
|
104
|
+
The example below matches the current package API.
|
|
105
|
+
|
|
106
|
+
### 1. Define your Genie model
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import "reflect-metadata";
|
|
110
|
+
import {
|
|
111
|
+
DataClass,
|
|
112
|
+
GenieClass,
|
|
113
|
+
GenieFunction,
|
|
114
|
+
GenieKey,
|
|
115
|
+
GenieProperty,
|
|
116
|
+
int,
|
|
117
|
+
} from "@omkarfork/reactgenie-lib";
|
|
118
|
+
|
|
119
|
+
@GenieClass("A counter")
|
|
120
|
+
export class Counter extends DataClass {
|
|
121
|
+
@GenieKey
|
|
122
|
+
@GenieProperty("Stable counter name")
|
|
123
|
+
name: string;
|
|
124
|
+
|
|
125
|
+
@GenieProperty("Current count")
|
|
126
|
+
count: int;
|
|
127
|
+
|
|
128
|
+
static Examples = [
|
|
129
|
+
{
|
|
130
|
+
user_utterance: "increment this counter",
|
|
131
|
+
example_parsed: "Counter.Current().increment()",
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
user_utterance: "what is the count",
|
|
135
|
+
example_parsed: "Counter.Current().count",
|
|
136
|
+
},
|
|
137
|
+
];
|
|
138
|
+
|
|
139
|
+
constructor({ name, count = 0 }: { name: string; count?: int }) {
|
|
140
|
+
super({ name });
|
|
141
|
+
this.name = name;
|
|
142
|
+
this.count = count;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
static setup() {
|
|
146
|
+
Counter.CreateObject({ name: "apples", count: 2 });
|
|
147
|
+
Counter.CreateObject({ name: "oranges", count: 5 });
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@GenieFunction("Increment the counter")
|
|
151
|
+
increment(): this {
|
|
152
|
+
this.count += 1;
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 2. Register a renderable view
|
|
159
|
+
|
|
160
|
+
```tsx
|
|
161
|
+
import { Pressable, Text, View } from "react-native";
|
|
162
|
+
import {
|
|
163
|
+
GenieClassInterface,
|
|
164
|
+
genieDispatch,
|
|
165
|
+
useGenieSelector,
|
|
166
|
+
} from "@omkarfork/reactgenie-lib";
|
|
167
|
+
import { Counter } from "./counter";
|
|
168
|
+
|
|
169
|
+
type CounterViewProps = {
|
|
170
|
+
name: string;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
function CounterView({ name }: CounterViewProps) {
|
|
174
|
+
const counter = useGenieSelector(() => Counter.GetObject({ name }));
|
|
175
|
+
const count = useGenieSelector(() => counter.count);
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<View>
|
|
179
|
+
<Text>{name}</Text>
|
|
180
|
+
<Text>{count}</Text>
|
|
181
|
+
<Pressable onPress={() => genieDispatch(() => counter.increment())}>
|
|
182
|
+
<Text>Increment</Text>
|
|
183
|
+
</Pressable>
|
|
184
|
+
</View>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export const CounterCard = GenieClassInterface(
|
|
189
|
+
"Counter",
|
|
190
|
+
({ name }: CounterViewProps) => `${name} counter`,
|
|
191
|
+
1
|
|
192
|
+
)(CounterView);
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
`GenieClassInterface(...)` currently takes:
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
GenieClassInterface(
|
|
199
|
+
type: string,
|
|
200
|
+
displayTitle?: string | ((props: any) => string),
|
|
201
|
+
displayPriority?: number | ((props: any) => number)
|
|
202
|
+
)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Important: the registered view class name comes from the wrapped component function name (`CounterView` above), not from the `displayTitle` argument.
|
|
206
|
+
|
|
207
|
+
### 3. Initialize the shared runtime
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
import { initReactGenie } from "@omkarfork/reactgenie-lib";
|
|
211
|
+
import { Counter } from "./counter";
|
|
212
|
+
|
|
213
|
+
export const reactGenieStore = initReactGenie();
|
|
214
|
+
|
|
215
|
+
Counter.setup();
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Call `setup()` yourself after `initReactGenie()`. The README examples in older docs implied that setup was automatic; the current implementation expects explicit initialization order.
|
|
219
|
+
|
|
220
|
+
### 4. Mount the provider
|
|
221
|
+
|
|
222
|
+
```tsx
|
|
223
|
+
import { Provider } from "react-redux";
|
|
224
|
+
import {
|
|
225
|
+
ModalityProvider,
|
|
226
|
+
type SpeechRecognitionConfig,
|
|
227
|
+
} from "@omkarfork/reactgenie-lib";
|
|
228
|
+
import type { NlInterpreterParserConfig } from "@omkarfork/reactgenie-dsl";
|
|
229
|
+
import { reactGenieStore } from "./store";
|
|
230
|
+
import { CounterCard } from "./CounterCard";
|
|
231
|
+
|
|
232
|
+
const parserConfig: NlInterpreterParserConfig = {
|
|
233
|
+
provider: "groq",
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const speechConfig: SpeechRecognitionConfig = {
|
|
237
|
+
provider: "groq",
|
|
238
|
+
groq: {
|
|
239
|
+
apiBaseUrl: "http://localhost:4000",
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
export function App() {
|
|
244
|
+
return (
|
|
245
|
+
<Provider store={reactGenieStore}>
|
|
246
|
+
<ModalityProvider
|
|
247
|
+
clientSecret="proxy-or-provider-token"
|
|
248
|
+
apiBaseUrl="http://localhost:4000"
|
|
249
|
+
parserConfig={parserConfig}
|
|
250
|
+
speechConfig={speechConfig}
|
|
251
|
+
displayTranscript={true}
|
|
252
|
+
>
|
|
253
|
+
<CounterCard name="apples" />
|
|
254
|
+
</ModalityProvider>
|
|
255
|
+
</Provider>
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Core Concepts
|
|
261
|
+
|
|
262
|
+
### `@GenieClass`
|
|
263
|
+
|
|
264
|
+
Marks a class as part of the Genie model surface and contributes prompt metadata.
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
@GenieClass("A counter")
|
|
268
|
+
export class Counter extends DataClass {}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### `DataClass`
|
|
272
|
+
|
|
273
|
+
Use `DataClass` for persisted Genie objects with stable keys. These objects can be created with `CreateObject(...)`, retrieved with `GetObject(...)`, enumerated with `All()`, and targeted through UI-aware helpers such as `Current()` and `AllCurrent()` after ReactGenie initialization.
|
|
274
|
+
|
|
275
|
+
### `HelperClass`
|
|
276
|
+
|
|
277
|
+
Use `HelperClass` for structured helper values nested inside data objects. Helper classes are serialized through parent data objects and are not standalone persisted records.
|
|
278
|
+
|
|
279
|
+
### `@GenieKey`
|
|
280
|
+
|
|
281
|
+
Marks the key field for a `DataClass`. Each `DataClass` needs a Genie key.
|
|
282
|
+
|
|
283
|
+
```ts
|
|
284
|
+
@GenieKey
|
|
285
|
+
@GenieProperty()
|
|
286
|
+
name: string;
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### `@GenieProperty`
|
|
290
|
+
|
|
291
|
+
Marks a field as part of the serializable Genie state and prompt-visible model.
|
|
292
|
+
|
|
293
|
+
```ts
|
|
294
|
+
@GenieProperty("Current count")
|
|
295
|
+
count: int;
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### `@GenieFunction`
|
|
299
|
+
|
|
300
|
+
Marks a static or instance method as callable from Genie-generated DSL / multimodal flows.
|
|
301
|
+
|
|
302
|
+
```ts
|
|
303
|
+
@GenieFunction("Increment the counter")
|
|
304
|
+
increment(): this {
|
|
305
|
+
this.count += 1;
|
|
306
|
+
return this;
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### `CreateObject(...)`
|
|
311
|
+
|
|
312
|
+
Create Genie objects through `CreateObject(...)`, not `new`.
|
|
313
|
+
|
|
314
|
+
```ts
|
|
315
|
+
Counter.CreateObject({ name: "apples", count: 2 });
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### `GetObject(...)`
|
|
319
|
+
|
|
320
|
+
Fetch a `DataClass` instance by its key.
|
|
321
|
+
|
|
322
|
+
```ts
|
|
323
|
+
const apples = Counter.GetObject({ name: "apples" });
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### `Current()` and `AllCurrent()`
|
|
327
|
+
|
|
328
|
+
After `initReactGenie()`, ReactGenie injects:
|
|
329
|
+
|
|
330
|
+
- `Current()`: the single visible object the user is most likely referring to
|
|
331
|
+
- `AllCurrent()`: all visible objects of that class, or the nearest matches to multiple taps
|
|
332
|
+
|
|
333
|
+
These helpers are driven by visible registered interfaces, so they only work when the corresponding UI is wrapped with `GenieClassInterface(...)`.
|
|
334
|
+
|
|
335
|
+
### `GenieClassInterface(...)`
|
|
336
|
+
|
|
337
|
+
Wrap any component that should be:
|
|
338
|
+
|
|
339
|
+
- targetable by voice results
|
|
340
|
+
- visible to `Current()` / `AllCurrent()`
|
|
341
|
+
- eligible for result-driven navigation
|
|
342
|
+
|
|
343
|
+
## `ModalityProvider`
|
|
344
|
+
|
|
345
|
+
`ModalityProvider` is the main runtime entry point. It creates the shared interpreter, merges examples, listens for speech, parses commands, executes DSL, emits user-facing responses, and routes displayable results into registered views.
|
|
346
|
+
|
|
347
|
+
Key props in the current implementation:
|
|
348
|
+
|
|
349
|
+
- `examples`: extra prompt examples to merge with class-level `static Examples`
|
|
350
|
+
- `clientSecret`: required credential or client token used by parser / speech providers
|
|
351
|
+
- `apiBaseUrl`: optional shared proxy base URL
|
|
352
|
+
- `parserConfig`: ReactGenieDSL parser configuration
|
|
353
|
+
- `speechConfig`: speech runtime configuration
|
|
354
|
+
- `speechLanguage`: recognition language tag
|
|
355
|
+
- `displayTranscript`: show transcript text in the default voice UI
|
|
356
|
+
- `extraPrompt`: append extra instructions to the parser prompt
|
|
357
|
+
- `VoiceUIComponent`: replace the default `VoiceRecognitionBar`
|
|
358
|
+
- `showFloatingMicButton`: show or hide the default floating mic button
|
|
359
|
+
- `voicePlaceholder`: custom placeholder text for the default voice UI
|
|
360
|
+
- `loggerConfig`: override runtime logging configuration
|
|
361
|
+
- `langsmithConfig`: optional monitor configuration object with `apiKey`, `project`, and `endpoint`
|
|
362
|
+
|
|
363
|
+
If you are migrating from older examples, note that the current prop name is `clientSecret`, not `codexApiKey`.
|
|
364
|
+
|
|
365
|
+
## Speech Recognition
|
|
366
|
+
|
|
367
|
+
ReactGenie ships a unified speech layer and individual adapters.
|
|
368
|
+
|
|
369
|
+
### Supported speech paths
|
|
370
|
+
|
|
371
|
+
| Path | Runtime | Export | Notes |
|
|
372
|
+
| --- | --- | --- | --- |
|
|
373
|
+
| Groq web transcription | Web | `GroqSpeechRecognizer` | Default provider path on web when configured. |
|
|
374
|
+
| Groq native transcription | iOS / Android | selected through `UnifiedSpeechRecognizer` | Requires optional `expo-audio` and `expo-file-system`. |
|
|
375
|
+
| OpenAI realtime transcription | Web | `OpenAISpeechRecognizer` | WebRTC-based realtime transcription. |
|
|
376
|
+
| OpenAI realtime transcription | iOS / Android | selected through `UnifiedSpeechRecognizer` | Requires optional `react-native-webrtc`. |
|
|
377
|
+
| Browser Web Speech fallback | Web | `SpeechRecognizer` | Used as a Groq fallback when enabled. |
|
|
378
|
+
| Local MLX Whisper | Web | `MLXSpeechRecognizer` | Useful for local speech pipelines. |
|
|
379
|
+
|
|
380
|
+
### Unified speech helpers
|
|
381
|
+
|
|
382
|
+
The main speech exports are:
|
|
383
|
+
|
|
384
|
+
- `UnifiedSpeechRecognizer`
|
|
385
|
+
- `getSpeechRecognitionConfig()`
|
|
386
|
+
- `selectSpeechRecognitionMethod()`
|
|
387
|
+
- `getSpeechRecognitionStatus()`
|
|
388
|
+
- `useSpeechRecognition()`
|
|
389
|
+
- `VoiceRecognitionBar`
|
|
390
|
+
|
|
391
|
+
### `SpeechRecognitionConfig`
|
|
392
|
+
|
|
393
|
+
The current config shape is:
|
|
394
|
+
|
|
395
|
+
```ts
|
|
396
|
+
type SpeechRecognitionConfig = {
|
|
397
|
+
provider?: "groq" | "openai";
|
|
398
|
+
fallbackToWebSpeech?: boolean;
|
|
399
|
+
groq?: {
|
|
400
|
+
enabled?: boolean;
|
|
401
|
+
apiKey?: string;
|
|
402
|
+
apiBaseUrl?: string;
|
|
403
|
+
transcriptionEndpoint?: string;
|
|
404
|
+
stream?: boolean;
|
|
405
|
+
};
|
|
406
|
+
openai?: {
|
|
407
|
+
proxyBaseUrl?: string;
|
|
408
|
+
transcriptionSessionEndpoint?: string;
|
|
409
|
+
translationEndpoint?: string;
|
|
410
|
+
realtimeWebRtcUrl?: string;
|
|
411
|
+
realtimeModel?: "gpt-4o-transcribe" | "gpt-4o-mini-transcribe";
|
|
412
|
+
translationModel?: string;
|
|
413
|
+
vadEnabled?: boolean;
|
|
414
|
+
autoStopOnVadSilence?: boolean;
|
|
415
|
+
vadThreshold?: number;
|
|
416
|
+
vadPrefixPaddingMs?: number;
|
|
417
|
+
vadSilenceDurationMs?: number;
|
|
418
|
+
vadIdleTimeoutMs?: number;
|
|
419
|
+
prewarmOnMount?: boolean;
|
|
420
|
+
};
|
|
421
|
+
localModel?: {
|
|
422
|
+
enabledOnWeb?: boolean;
|
|
423
|
+
baseUrl?: string;
|
|
424
|
+
mode?: "oneshot" | "sse" | "realtime";
|
|
425
|
+
model?: string;
|
|
426
|
+
};
|
|
427
|
+
};
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
Defaults in the current implementation include:
|
|
431
|
+
|
|
432
|
+
- speech provider defaults to `groq`
|
|
433
|
+
- Groq defaults to streaming mode
|
|
434
|
+
- Groq defaults to `fallbackToWebSpeech: true`
|
|
435
|
+
- OpenAI defaults to `realtimeModel: "gpt-4o-transcribe"`
|
|
436
|
+
- OpenAI defaults to `prewarmOnMount: true`
|
|
437
|
+
- local MLX defaults to disabled on web unless explicitly enabled
|
|
438
|
+
|
|
439
|
+
## Routing and Result Display
|
|
440
|
+
|
|
441
|
+
ReactGenie can turn displayable execution results into navigation events when the target object type has a registered interface.
|
|
442
|
+
|
|
443
|
+
Expo Router support is available through:
|
|
444
|
+
|
|
445
|
+
- `useExpoRouterAdapter()`
|
|
446
|
+
- `withExpoRouterAdapter()`
|
|
447
|
+
- `useRegisterGenieRoute()`
|
|
448
|
+
- `registerGenieRoute()`
|
|
449
|
+
- `isExpoRouterAvailable()`
|
|
450
|
+
- `getRegisteredRoutes()`
|
|
451
|
+
- `getRouteMap()`
|
|
452
|
+
|
|
453
|
+
Example:
|
|
454
|
+
|
|
455
|
+
```tsx
|
|
456
|
+
import { useRegisterGenieRoute } from "@omkarfork/reactgenie-lib";
|
|
457
|
+
|
|
458
|
+
export default function CounterRoute() {
|
|
459
|
+
useRegisterGenieRoute("CounterView");
|
|
460
|
+
return <CounterCard name="apples" />;
|
|
461
|
+
}
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
Notes:
|
|
465
|
+
|
|
466
|
+
- the route key must match the wrapped component function name, not necessarily the exported variable name
|
|
467
|
+
- duplicate route registration for the same view class and different paths throws
|
|
468
|
+
- dynamic route params are filtered so Genie metadata does not become arbitrary query params
|
|
469
|
+
- result-window and query-intent metadata are stored in shared state for downstream reconstruction
|
|
470
|
+
|
|
471
|
+
## Public API At a Glance
|
|
472
|
+
|
|
473
|
+
### Runtime and store
|
|
474
|
+
|
|
475
|
+
- `ModalityProvider`
|
|
476
|
+
- `GenieInterpreter`
|
|
477
|
+
- `initReactGenie`
|
|
478
|
+
- `useGenieSelector`
|
|
479
|
+
- `useGenieCodeSelector`
|
|
480
|
+
- `resetGenieNavigation`
|
|
481
|
+
- `genieDispatch`
|
|
482
|
+
- `sharedStore`
|
|
483
|
+
- `sharedState`
|
|
484
|
+
|
|
485
|
+
### Genie model and decorators
|
|
486
|
+
|
|
487
|
+
- `GenieClass`
|
|
488
|
+
- `GenieClassInterface`
|
|
489
|
+
- `GenieFunction`
|
|
490
|
+
- `GenieProperty`
|
|
491
|
+
- `GenieKey`
|
|
492
|
+
- `DataClass`
|
|
493
|
+
- `HelperClass`
|
|
494
|
+
- `AllGenieObjects`
|
|
495
|
+
- `ClassDescriptor`
|
|
496
|
+
- `FieldDescriptor`
|
|
497
|
+
- `FuncDescriptor`
|
|
498
|
+
- `ParamDescriptor`
|
|
499
|
+
- `int`
|
|
500
|
+
- `float`
|
|
501
|
+
- `DateTime`
|
|
502
|
+
- `TimeDelta`
|
|
503
|
+
|
|
504
|
+
### Voice and speech
|
|
505
|
+
|
|
506
|
+
- `useSpeechRecognition`
|
|
507
|
+
- `SpeechState`
|
|
508
|
+
- `VoiceRecognitionBar`
|
|
509
|
+
- `SpeechRecognizer`
|
|
510
|
+
- `GroqSpeechRecognizer`
|
|
511
|
+
- `OpenAISpeechRecognizer`
|
|
512
|
+
- `MLXSpeechRecognizer`
|
|
513
|
+
- `UnifiedSpeechRecognizer`
|
|
514
|
+
- `isGroqSpeechAvailable`
|
|
515
|
+
- `getGroqSpeechCapabilities`
|
|
516
|
+
- `isOpenAISpeechAvailable`
|
|
517
|
+
- `getOpenAISpeechCapabilities`
|
|
518
|
+
- `getSpeechRecognitionConfig`
|
|
519
|
+
- `selectSpeechRecognitionMethod`
|
|
520
|
+
- `getSpeechRecognitionStatus`
|
|
521
|
+
- `streamGroqTranscription`
|
|
522
|
+
- `mergeTranscriptParts`
|
|
523
|
+
- `AudioVisualizer`
|
|
524
|
+
- `AudioLevelIndicator`
|
|
525
|
+
|
|
526
|
+
### Routing and platform support
|
|
527
|
+
|
|
528
|
+
- `useExpoRouterAdapter`
|
|
529
|
+
- `withExpoRouterAdapter`
|
|
530
|
+
- `useRegisterGenieRoute`
|
|
531
|
+
- `registerGenieRoute`
|
|
532
|
+
- `isExpoRouterAvailable`
|
|
533
|
+
- `getRegisteredRoutes`
|
|
534
|
+
- `getRouteMap`
|
|
535
|
+
- platform-aware exports from `./platform`, including overlay, button, transcript, loading, safe-container, event, and type helpers
|
|
536
|
+
|
|
537
|
+
### Diagnostics and errors
|
|
538
|
+
|
|
539
|
+
- `configureLogger`
|
|
540
|
+
- `setLogLevel`
|
|
541
|
+
- `logger`
|
|
542
|
+
- `setLoggerTelemetryBridge`
|
|
543
|
+
- `setVoicePipelineTelemetryBridge`
|
|
544
|
+
- `getVoicePipelineTelemetryBridge`
|
|
545
|
+
- `GenieUserFacingError`
|
|
546
|
+
- `isGenieUserFacingError`
|
|
547
|
+
|
|
548
|
+
### Types and compatibility exports
|
|
549
|
+
|
|
550
|
+
- `ReactGenieState`
|
|
551
|
+
- `NavigatorState`
|
|
552
|
+
- `QueryIntent`
|
|
553
|
+
- `QueryIntentOperation`
|
|
554
|
+
- `ResultWindowEntry`
|
|
555
|
+
- `SpeechRecognitionState`
|
|
556
|
+
- `SpeechRecognitionControls`
|
|
557
|
+
- `UseSpeechRecognitionReturn`
|
|
558
|
+
- `VoiceRecognitionBarProps`
|
|
559
|
+
- `SpeechRecognitionConfig`
|
|
560
|
+
- `UnifiedSpeechRecognizerProps`
|
|
561
|
+
- `GroqConfigProps`
|
|
562
|
+
- `OpenAIConfigProps`
|
|
563
|
+
- `LocalModelConfigProps`
|
|
564
|
+
- `LoggerRuntimeConfig`
|
|
565
|
+
- `LogLevel`
|
|
566
|
+
- `LoggerTelemetryBridge`
|
|
567
|
+
- `VoicePipelineContext`
|
|
568
|
+
- `VoicePipelineHandle`
|
|
569
|
+
- `VoicePipelineOutcome`
|
|
570
|
+
- `VoicePipelineStage`
|
|
571
|
+
- `VoicePipelineStageHandle`
|
|
572
|
+
- `VoicePipelineStageStatus`
|
|
573
|
+
- `VoicePipelineTelemetryBridge`
|
|
574
|
+
- `RouteRegistrationInfo`
|
|
575
|
+
- `NativeSpeechRecognizerProps` and `OpenAINativeSpeechRecognizerProps` as type-only exports
|
|
576
|
+
- `ReactFromModule`
|
|
577
|
+
- `ReactReduxFromModule`
|
|
578
|
+
|
|
579
|
+
## Custom Voice UI
|
|
580
|
+
|
|
581
|
+
If you do not want the default floating mic and voice bar, you can:
|
|
582
|
+
|
|
583
|
+
- pass `showFloatingMicButton={false}`
|
|
584
|
+
- supply your own `VoiceUIComponent`
|
|
585
|
+
- build a fully custom interface with `useSpeechRecognition()`
|
|
586
|
+
|
|
587
|
+
The default UI components already understand transcript display, listening state, processing state, and waveform preview.
|
|
588
|
+
|
|
589
|
+
## Logging and Telemetry
|
|
590
|
+
|
|
591
|
+
ReactGenie includes runtime logging and voice-pipeline instrumentation hooks:
|
|
592
|
+
|
|
593
|
+
- `configureLogger(...)` to enable or tune runtime sinks
|
|
594
|
+
- `setLogLevel(...)` for environment-specific noise control
|
|
595
|
+
- `setLoggerTelemetryBridge(...)` to forward logger events
|
|
596
|
+
- `setVoicePipelineTelemetryBridge(...)` to observe mic / parse / execute pipeline stages
|
|
597
|
+
|
|
598
|
+
These hooks are useful when you want app-level observability without forking the runtime.
|
|
599
|
+
|
|
600
|
+
## CLI Utilities
|
|
601
|
+
|
|
602
|
+
The published package exposes four binaries:
|
|
603
|
+
|
|
604
|
+
- `get-prompt`
|
|
605
|
+
- `dry-run`
|
|
606
|
+
- `set-script`
|
|
607
|
+
- `parse`
|
|
608
|
+
|
|
609
|
+
These are oriented toward local prompt-generation and parser experiments around Genie test harnesses.
|
|
610
|
+
|
|
611
|
+
## Common Notes
|
|
612
|
+
|
|
613
|
+
- Create Genie objects with `CreateObject(...)`, not `new`.
|
|
614
|
+
- Import all Genie classes and registered interfaces before calling `initReactGenie()`.
|
|
615
|
+
- Wrap visible targetable components with `GenieClassInterface(...)`; otherwise `Current()` / `AllCurrent()` cannot resolve them.
|
|
616
|
+
- Register routes when using Expo Router if you expect displayable results to navigate.
|
|
617
|
+
- If native speech does not work, check whether the corresponding optional peer dependencies are installed for your selected provider path.
|
|
618
|
+
|
|
619
|
+
## License
|
|
620
|
+
|
|
621
|
+
Apache-2.0 © [Jackie Yang](https://github.com/valkjsaaa)
|
package/babel.config.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview
|
|
3
|
+
* Babel configuration for Expo and React Genie projects.
|
|
4
|
+
*
|
|
5
|
+
* This file sets up Babel with various presets and plugins to enable ES6+ features,
|
|
6
|
+
* React JSX, Flow, and TypeScript syntax. It specifically includes plugins for decorators,
|
|
7
|
+
* class properties, object rest/spread, dynamic imports, and parameter decorators.
|
|
8
|
+
* These configurations are crucial for ensuring that advanced React component transformations,
|
|
9
|
+
* as well as custom syntax supported by React Genie, are properly transpiled.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
module.exports = function (api) {
|
|
13
|
+
api.cache(true);
|
|
14
|
+
return {
|
|
15
|
+
presets: [
|
|
16
|
+
["@babel/preset-env", { targets: { node: "current" } }],
|
|
17
|
+
"@babel/preset-react",
|
|
18
|
+
"@babel/preset-typescript",
|
|
19
|
+
],
|
|
20
|
+
plugins: [
|
|
21
|
+
["@babel/plugin-proposal-decorators", { legacy: true }],
|
|
22
|
+
["@babel/plugin-transform-class-properties", { loose: true }],
|
|
23
|
+
"@babel/plugin-proposal-object-rest-spread",
|
|
24
|
+
"@babel/plugin-syntax-dynamic-import",
|
|
25
|
+
"babel-plugin-parameter-decorator",
|
|
26
|
+
"babel-plugin-reactgenie",
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { NavigatorState } from '../shared-store';
|
|
3
|
+
export type RouteRegistrationInfo = {
|
|
4
|
+
readonly viewClassName: string;
|
|
5
|
+
readonly routePath: string;
|
|
6
|
+
readonly registeredAt: string;
|
|
7
|
+
readonly source: "auto" | "runtime";
|
|
8
|
+
};
|
|
9
|
+
export declare function buildQueryParamsFromNavState(navState: NavigatorState): Record<string, string>;
|
|
10
|
+
export declare function useRegisterGenieRoute(baseViewClassName: string, routePath?: string): void;
|
|
11
|
+
export declare function registerGenieRoute(viewClassName: string, routePath: string): void;
|
|
12
|
+
export declare function useExpoRouterAdapter(): void;
|
|
13
|
+
export declare function withExpoRouterAdapter<P extends object>(Component: React.ComponentType<P>): React.ComponentType<P>;
|
|
14
|
+
export declare function isExpoRouterAvailable(): boolean;
|
|
15
|
+
export declare function getRegisteredRoutes(): Map<string, RouteRegistrationInfo>;
|
|
16
|
+
export declare function getRouteMap(): Map<string, string>;
|