voice-runtime 0.0.2 → 1.0.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 CHANGED
@@ -8,18 +8,113 @@
8
8
  [TVIC](https://github.com/Kkartik14/TVIC), a provider-neutral runtime for realtime
9
9
  voice agents with bring-your-own telephony, speech, model, and synthesis providers.
10
10
 
11
- ## Status: early preview
11
+ ## Status
12
12
 
13
- This `0.0.x` release reserves the stable package name while the high-level
14
- `createVoiceAgent` API is completed. **It does not yet export the executable
15
- runtime, and it should not be used in production.**
13
+ The package is the public Node.js entry point for the TVIC runtime. The first
14
+ release targets Node 20 through 26 and ships both ESM and CommonJS entry points.
15
+ It is server-side only: browser audio connects to a Node server through the
16
+ browser-audio transport adapter, while browser imports from this package remain
17
+ out of scope for the first release.
16
18
 
17
- Publishing an explicit placeholder is intentional. Shipping an unfinished runtime
18
- API under a stable name would be worse than shipping nothing.
19
+ The stable managed API assembles the STT → LLM → TTS pipeline from a prompt and
20
+ provider configuration. The host application still owns its HTTP server,
21
+ webhook authentication, browser-session authentication, and domain tools.
19
22
 
20
- The runtime itself is executable today and developed in the open. To run it now,
21
- work from the [repository](https://github.com/Kkartik14/TVIC) rather than from this
22
- package.
23
+ This README describes the intended public contract; release status is tracked in
24
+ the repository's `local/release/1.0.0/checklist.md`.
25
+
26
+ ## Install
27
+
28
+ ```sh
29
+ npm install voice-runtime
30
+ ```
31
+
32
+ The package has no provider SDK lock-in. You may use the built-in adapters, pass
33
+ your own provider implementations, or mix both approaches.
34
+
35
+ ## Prompt-first agent
36
+
37
+ ```ts
38
+ import { createVoiceAgent } from "voice-runtime";
39
+
40
+ const agent = createVoiceAgent({
41
+ prompt: "You schedule appointments for Dr. Kartik. Be concise and confirm the time.",
42
+ providers: {
43
+ telephony: { provider: "web-client-audio" },
44
+ stt: { provider: "deepgram", apiKey: process.env.DEEPGRAM_API_KEY },
45
+ llm: {
46
+ provider: "openai",
47
+ apiKey: process.env.OPENAI_API_KEY,
48
+ model: "gpt-4.1-mini",
49
+ },
50
+ tts: {
51
+ provider: "cartesia",
52
+ apiKey: process.env.CARTESIA_API_KEY,
53
+ voiceId: process.env.CARTESIA_VOICE_ID,
54
+ },
55
+ },
56
+ });
57
+
58
+ // `callHandle` comes from a verified transport connection or your own adapter.
59
+ const session = await agent.start({
60
+ callHandle,
61
+ channel: "web_audio",
62
+ });
63
+
64
+ for await (const event of session.run) {
65
+ if (event.kind === "transcript_delta") console.log("caller:", event.text);
66
+ if (event.kind === "error") console.error(event.error);
67
+ }
68
+
69
+ const result = await session.run;
70
+ console.log(result.turnsHandled);
71
+ await agent.stop();
72
+ ```
73
+
74
+ `agent.start()` returns `{ sessionId, run }`. The `run` value is both an async
75
+ event stream and an awaitable final result. The separate envelope is required by
76
+ JavaScript Promise assimilation rules; returning the Promise-like run directly
77
+ from an async `start()` method would make `await agent.start()` lose the session
78
+ handle. Use `agent.run(options)` when you only need the final result.
79
+
80
+ TVIC does not receive media from a prompt alone. A verified transport adapter
81
+ must produce the `callHandle` passed to `start()`.
82
+
83
+ For a built-in Web Client Audio or Twilio adapter, use the factory form so the
84
+ adapter receives the session ID created by TVIC:
85
+
86
+ ```ts
87
+ import { createTwilioMediaStreamsProvider, createVoiceAgent } from "voice-runtime";
88
+
89
+ const telephony = createTwilioMediaStreamsProvider();
90
+
91
+ const session = await agent.start({
92
+ call: verifiedInboundCall,
93
+ channel: "phone",
94
+ callHandle: ({ sessionId, call }) => telephony.acceptWebSocket(socket, call.id, sessionId),
95
+ });
96
+ ```
97
+
98
+ The factory runs after the runtime session exists and receives
99
+ `{ sessionId, call, channel }`. The supplied call is required in this form, and
100
+ its ID must match the returned handle's `callId`. Replace the provider and
101
+ `channel` with `createWebClientAudioProvider()` and `"web_audio"` for browser
102
+ audio. A preconstructed custom `CallHandle` is also supported when the adapter
103
+ already knows how to correlate its events to the managed session.
104
+
105
+ `agent.stop()` is idempotent. If a session is still running, it cancels and
106
+ drains that session before closing the runtime and its stores.
107
+
108
+ Errors on `VoiceEvent` and `MediaEvent` payloads are JSON-safe
109
+ `NormalizedError` values. Check them with `isNormalizedError`; the
110
+ `isTvicError` marker is reserved for thrown `TvicThrowableError` wrappers and
111
+ is not present on plain event payloads.
112
+
113
+ TVIC-created error codes use lowercase, namespaced identifiers such as
114
+ `auth.invalid_key` and `provider.open_failed`. Custom calls to
115
+ `normalizedError()` and `normalizeUnknownError()` must use one or more
116
+ lowercase dot-separated segments; older persisted error records retain their
117
+ legacy codes during migration.
23
118
 
24
119
  ## What TVIC does
25
120
 
@@ -31,6 +126,123 @@ Recordings, traces, incident analysis, and dashboards are deliberately out of sc
31
126
  Those belong to Earshot, a separate voice observability product that integrates
32
127
  outside the realtime critical path.
33
128
 
129
+ ## Providers, models, and credentials
130
+
131
+ Each stage is configured independently. Built-in options currently include:
132
+
133
+ - STT: Deepgram, Sarvam, ElevenLabs Scribe, AssemblyAI, and Soniox.
134
+ - LLM: OpenAI Responses.
135
+ - TTS: Cartesia and ElevenLabs.
136
+ - Transport: browser audio and inbound Twilio Media Streams.
137
+
138
+ Maturity is intentionally explicit: Web Client Audio and inbound Twilio Media
139
+ Streams are the stable transport candidates for `1.0.0`. The paid STT, LLM,
140
+ and TTS adapters are currently `experimental`—their deterministic protocol
141
+ coverage passes, but each still needs a credential-gated live-service check
142
+ before release notes can call it stable. The root export `PROVIDER_STABILITY`
143
+ contains the machine-readable labels.
144
+
145
+ Pass an explicit `apiKey` or use the documented environment variable. Explicit
146
+ credentials take precedence; missing credentials fail before a live session is
147
+ created.
148
+
149
+ | Provider | Environment variable |
150
+ | ---------- | -------------------- |
151
+ | Deepgram | `DEEPGRAM_API_KEY` |
152
+ | Sarvam | `SARVAM_API_KEY` |
153
+ | ElevenLabs | `ELEVENLABS_API_KEY` |
154
+ | AssemblyAI | `ASSEMBLYAI_API_KEY` |
155
+ | Soniox | `SONIOX_API_KEY` |
156
+ | OpenAI | `OPENAI_API_KEY` |
157
+ | Cartesia | `CARTESIA_API_KEY` |
158
+
159
+ STT, LLM, and TTS models are independent settings. TTS voice selection is also
160
+ independent. Built-in TTS can read `CARTESIA_VOICE_ID` or
161
+ `ELEVENLABS_VOICE_ID` for its voice. For complete provider-specific control,
162
+ pass a constructed provider instance instead of a built-in configuration object.
163
+ Built-in STT and OpenAI-compatible LLM configurations reject models outside the
164
+ dated TVIC catalog unless `allowUnknownModel: true` is explicitly set.
165
+
166
+ Tools are application-owned functions. Define their schema and executor once,
167
+ then include them in the agent:
168
+
169
+ ```ts
170
+ import { createVoiceAgent, defineTool } from "voice-runtime";
171
+
172
+ const bookAppointment = defineTool<{ date: string }, { booked: boolean }>({
173
+ id: "book_appointment",
174
+ name: "book_appointment",
175
+ description: "Books an appointment for a requested date.",
176
+ inputSchema: { type: "object", required: ["date"] },
177
+ outputSchema: { type: "object", required: ["booked"] },
178
+ async execute(input) {
179
+ // Call your application service here; TVIC does not own domain state.
180
+ return { booked: input.date.length > 0 };
181
+ },
182
+ });
183
+
184
+ const providers = {
185
+ telephony: { provider: "web-client-audio" as const },
186
+ stt: { provider: "deepgram" as const, apiKey: process.env.DEEPGRAM_API_KEY },
187
+ llm: { provider: "openai" as const, apiKey: process.env.OPENAI_API_KEY },
188
+ tts: {
189
+ provider: "cartesia" as const,
190
+ apiKey: process.env.CARTESIA_API_KEY,
191
+ voiceId: process.env.CARTESIA_VOICE_ID,
192
+ },
193
+ };
194
+
195
+ const agentWithTools = createVoiceAgent({
196
+ prompt: "Schedule appointments and use the booking tool when needed.",
197
+ tools: [bookAppointment],
198
+ providers,
199
+ });
200
+ ```
201
+
202
+ Tool execution receives a session/turn-scoped `AbortSignal`; authorization,
203
+ confirmation for irreversible actions, and domain-state writes remain the host
204
+ application's responsibility.
205
+
206
+ ## Composable API
207
+
208
+ Advanced runtime, media, provider, normalized-error, and durable-adapter APIs
209
+ are exported from the package root. There are no advanced subpath imports in the
210
+ first release. This lets a developer start with `createVoiceAgent` and later own
211
+ the runtime/session/pipeline boundaries without changing package names.
212
+
213
+ The host remains responsible for creating authenticated transport connections,
214
+ owning HTTP/webhook lifecycle, and implementing application-domain tools. TVIC
215
+ does not automatically create public unauthenticated endpoints or choose a
216
+ provider fallback policy.
217
+
218
+ ## Persistence adapters
219
+
220
+ The root also exposes the PostgreSQL and Redis durability building blocks. The
221
+ database drivers are intentionally injected, so install and configure `pg` and
222
+ `redis` in your application:
223
+
224
+ ```ts
225
+ import {
226
+ createPostgresMemory,
227
+ createPostgresRedisDurableRuntimeStore,
228
+ runPostgresMemoryMigrations,
229
+ runPostgresMigrations,
230
+ } from "voice-runtime";
231
+
232
+ await runPostgresMigrations(pgPool);
233
+ await runPostgresMemoryMigrations(memoryPool);
234
+ const memory = createPostgresMemory({ pool: memoryPool });
235
+ const durable = createPostgresRedisDurableRuntimeStore({
236
+ pool: pgPool,
237
+ redis: redisClient,
238
+ });
239
+ ```
240
+
241
+ The migration SQL is bundled into the published package and can also be
242
+ inspected in the package's migration sources. Run each migration function once
243
+ at deploy time; repeated calls are idempotent. PostgreSQL is authoritative for
244
+ the composite store, while Redis is used for its cache/projection layer.
245
+
34
246
  ## License
35
247
 
36
248
  [Apache-2.0](./LICENSE)