@navai/voice-frontend 0.1.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/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # @navai/voice-frontend
2
+
3
+ Frontend helpers to integrate OpenAI Realtime voice without creating custom base plumbing in every app.
4
+
5
+ ## What this package provides
6
+
7
+ - Route resolution helpers.
8
+ - Optional dynamic frontend function loader.
9
+ - `buildNavaiAgent(...)` with built-in tools:
10
+ - `navigate_to`
11
+ - `execute_app_function`
12
+ - Optional backend function bridge:
13
+ - frontend + backend functions can coexist under `execute_app_function`.
14
+ - `createNavaiBackendClient(...)` to centralize calls to backend routes:
15
+ - `POST /navai/realtime/client-secret`
16
+ - `GET /navai/functions`
17
+ - `POST /navai/functions/execute`
18
+ - `resolveNavaiFrontendRuntimeConfig(...)` to read routes/functions from env.
19
+
20
+ ## Install
21
+
22
+ ```bash
23
+ npm install @navai/voice-frontend @openai/agents zod
24
+ ```
25
+
26
+ ## Expected app inputs
27
+
28
+ 1. Route data in `src/ai/routes.ts` (or any array compatible with `NavaiRoute[]`).
29
+ 2. Optional function module loaders when you want local/frontend tools.
30
+
31
+ ## Minimal usage (no bundler-specific APIs)
32
+
33
+ ```ts
34
+ import { buildNavaiAgent, createNavaiBackendClient } from "@navai/voice-frontend";
35
+ import { NAVAI_ROUTE_ITEMS } from "./ai/routes";
36
+
37
+ const backendClient = createNavaiBackendClient({
38
+ apiBaseUrl: "http://localhost:3000"
39
+ });
40
+ const backendFunctions = await backendClient.listFunctions();
41
+
42
+ const { agent } = await buildNavaiAgent({
43
+ navigate: (path) => routerNavigate(path),
44
+ routes: NAVAI_ROUTE_ITEMS,
45
+ backendFunctions: backendFunctions.functions,
46
+ executeBackendFunction: backendClient.executeFunction
47
+ });
48
+ ```
49
+
50
+ Then use `agent` with `RealtimeSession` from `@openai/agents/realtime`.
51
+
52
+ ## Optional dynamic frontend functions (bundler adapter)
53
+
54
+ If your bundler can provide module loaders, you can add local frontend functions too.
55
+
56
+ ```ts
57
+ import { resolveNavaiFrontendRuntimeConfig } from "@navai/voice-frontend";
58
+
59
+ // Vite adapter example:
60
+ const runtime = await resolveNavaiFrontendRuntimeConfig({
61
+ moduleLoaders: import.meta.glob(["/src/**/*.{ts,js}", "!/src/ai/routes.ts"]),
62
+ defaultRoutes: NAVAI_ROUTE_ITEMS
63
+ });
64
+ ```
65
+
66
+ Execution rule inside `execute_app_function`:
67
+
68
+ - local/frontend function is attempted first.
69
+ - if not found locally, backend function is attempted.
70
+ - if names conflict, frontend function wins and backend one is ignored with warning.
71
+
72
+ ## Runtime env keys
73
+
74
+ `resolveNavaiFrontendRuntimeConfig` reads:
75
+
76
+ - `NAVAI_ROUTES_FILE`
77
+ - `NAVAI_FUNCTIONS_FOLDERS`
78
+ - `NAVAI_REALTIME_MODEL`
79
+
80
+ `createNavaiBackendClient` reads:
81
+
82
+ - `NAVAI_API_URL` when you pass `env`
83
+ - or `apiBaseUrl` directly (fallback `http://localhost:3000`)
84
+
85
+ When `modelOverride` exists, pass it to:
86
+
87
+ - backend request body: `POST /navai/realtime/client-secret`
88
+ - realtime connection: `session.connect({ model })`
89
+
90
+ ## `NAVAI_FUNCTIONS_FOLDERS` formats
91
+
92
+ - single path: `src/ai/functions-modules`
93
+ - recursive marker: `src/ai/functions-modules/...`
94
+ - wildcard: `src/features/*/voice-functions`
95
+ - CSV list: `src/ai/functions,src/features/account/functions`