@absolutejs/voice 0.0.22-beta.16 → 0.0.22-beta.160

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 (180) hide show
  1. package/README.md +1053 -5
  2. package/dist/agent.d.ts +24 -0
  3. package/dist/agentSquadContract.d.ts +64 -0
  4. package/dist/angular/index.d.ts +11 -0
  5. package/dist/angular/index.js +3072 -1106
  6. package/dist/angular/voice-campaign-dialer-proof.service.d.ts +14 -0
  7. package/dist/angular/voice-controller.service.d.ts +1 -0
  8. package/dist/angular/voice-delivery-runtime.component.d.ts +17 -0
  9. package/dist/angular/voice-delivery-runtime.service.d.ts +16 -0
  10. package/dist/angular/voice-ops-action-center.service.d.ts +13 -0
  11. package/dist/angular/voice-ops-status.component.d.ts +15 -0
  12. package/dist/angular/voice-ops-status.service.d.ts +12 -0
  13. package/dist/angular/voice-provider-capabilities.service.d.ts +12 -0
  14. package/dist/angular/voice-routing-status.service.d.ts +11 -0
  15. package/dist/angular/voice-stream.service.d.ts +3 -0
  16. package/dist/angular/voice-trace-timeline.service.d.ts +12 -0
  17. package/dist/angular/voice-turn-latency.service.d.ts +13 -0
  18. package/dist/angular/voice-turn-quality.service.d.ts +12 -0
  19. package/dist/angular/voice-workflow-status.service.d.ts +12 -0
  20. package/dist/assistantHealth.d.ts +81 -0
  21. package/dist/audit.d.ts +128 -0
  22. package/dist/auditDeliveryRoutes.d.ts +85 -0
  23. package/dist/auditExport.d.ts +34 -0
  24. package/dist/auditRoutes.d.ts +66 -0
  25. package/dist/auditSinks.d.ts +151 -0
  26. package/dist/bargeInRoutes.d.ts +56 -0
  27. package/dist/campaign.d.ts +610 -0
  28. package/dist/campaignDialers.d.ts +90 -0
  29. package/dist/client/actions.d.ts +105 -0
  30. package/dist/client/bargeInMonitor.d.ts +7 -0
  31. package/dist/client/campaignDialerProof.d.ts +23 -0
  32. package/dist/client/connection.d.ts +3 -0
  33. package/dist/client/deliveryRuntime.d.ts +34 -0
  34. package/dist/client/deliveryRuntimeWidget.d.ts +37 -0
  35. package/dist/client/duplex.d.ts +1 -1
  36. package/dist/client/htmxBootstrap.js +747 -15
  37. package/dist/client/index.d.ts +50 -0
  38. package/dist/client/index.js +2757 -20
  39. package/dist/client/liveTurnLatency.d.ts +41 -0
  40. package/dist/client/opsActionCenter.d.ts +54 -0
  41. package/dist/client/opsActionCenterWidget.d.ts +29 -0
  42. package/dist/client/opsActionHistory.d.ts +19 -0
  43. package/dist/client/opsActionHistoryWidget.d.ts +11 -0
  44. package/dist/client/opsStatus.d.ts +19 -0
  45. package/dist/client/opsStatusWidget.d.ts +40 -0
  46. package/dist/client/providerCapabilities.d.ts +19 -0
  47. package/dist/client/providerCapabilitiesWidget.d.ts +32 -0
  48. package/dist/client/providerSimulationControls.d.ts +33 -0
  49. package/dist/client/providerSimulationControlsWidget.d.ts +20 -0
  50. package/dist/client/providerStatusWidget.d.ts +32 -0
  51. package/dist/client/routingStatus.d.ts +19 -0
  52. package/dist/client/routingStatusWidget.d.ts +28 -0
  53. package/dist/client/traceTimeline.d.ts +19 -0
  54. package/dist/client/traceTimelineWidget.d.ts +32 -0
  55. package/dist/client/turnLatency.d.ts +22 -0
  56. package/dist/client/turnLatencyWidget.d.ts +33 -0
  57. package/dist/client/turnQuality.d.ts +19 -0
  58. package/dist/client/turnQualityWidget.d.ts +32 -0
  59. package/dist/client/workflowStatus.d.ts +19 -0
  60. package/dist/dataControl.d.ts +47 -0
  61. package/dist/deliveryRuntime.d.ts +158 -0
  62. package/dist/deliverySinkRoutes.d.ts +117 -0
  63. package/dist/demoReadyRoutes.d.ts +98 -0
  64. package/dist/diagnosticsRoutes.d.ts +44 -0
  65. package/dist/evalRoutes.d.ts +213 -0
  66. package/dist/fileStore.d.ts +11 -2
  67. package/dist/handoff.d.ts +54 -0
  68. package/dist/handoffHealth.d.ts +94 -0
  69. package/dist/index.d.ts +112 -11
  70. package/dist/index.js +17792 -4316
  71. package/dist/liveLatency.d.ts +78 -0
  72. package/dist/modelAdapters.d.ts +23 -2
  73. package/dist/openaiRealtime.d.ts +27 -0
  74. package/dist/openaiTTS.d.ts +18 -0
  75. package/dist/opsActionAuditRoutes.d.ts +99 -0
  76. package/dist/opsConsoleRoutes.d.ts +80 -0
  77. package/dist/opsStatus.d.ts +76 -0
  78. package/dist/opsStatusRoutes.d.ts +33 -0
  79. package/dist/opsWebhook.d.ts +126 -0
  80. package/dist/outcomeContract.d.ts +112 -0
  81. package/dist/phoneAgent.d.ts +62 -0
  82. package/dist/phoneAgentProductionSmoke.d.ts +115 -0
  83. package/dist/postgresStore.d.ts +13 -2
  84. package/dist/productionReadiness.d.ts +335 -0
  85. package/dist/providerAdapters.d.ts +48 -0
  86. package/dist/providerCapabilities.d.ts +92 -0
  87. package/dist/providerHealth.d.ts +1 -0
  88. package/dist/providerRoutingContract.d.ts +38 -0
  89. package/dist/qualityRoutes.d.ts +76 -0
  90. package/dist/queue.d.ts +61 -0
  91. package/dist/react/VoiceDeliveryRuntime.d.ts +7 -0
  92. package/dist/react/VoiceOpsActionCenter.d.ts +5 -0
  93. package/dist/react/VoiceOpsStatus.d.ts +6 -0
  94. package/dist/react/VoiceProviderCapabilities.d.ts +6 -0
  95. package/dist/react/VoiceProviderSimulationControls.d.ts +5 -0
  96. package/dist/react/VoiceProviderStatus.d.ts +6 -0
  97. package/dist/react/VoiceRoutingStatus.d.ts +6 -0
  98. package/dist/react/VoiceTraceTimeline.d.ts +6 -0
  99. package/dist/react/VoiceTurnLatency.d.ts +6 -0
  100. package/dist/react/VoiceTurnQuality.d.ts +6 -0
  101. package/dist/react/index.d.ts +21 -0
  102. package/dist/react/index.js +3396 -33
  103. package/dist/react/useVoiceCampaignDialerProof.d.ts +10 -0
  104. package/dist/react/useVoiceController.d.ts +3 -0
  105. package/dist/react/useVoiceDeliveryRuntime.d.ts +13 -0
  106. package/dist/react/useVoiceOpsActionCenter.d.ts +11 -0
  107. package/dist/react/useVoiceOpsStatus.d.ts +8 -0
  108. package/dist/react/useVoiceProviderCapabilities.d.ts +8 -0
  109. package/dist/react/useVoiceProviderSimulationControls.d.ts +10 -0
  110. package/dist/react/useVoiceRoutingStatus.d.ts +8 -0
  111. package/dist/react/useVoiceStream.d.ts +3 -0
  112. package/dist/react/useVoiceTraceTimeline.d.ts +8 -0
  113. package/dist/react/useVoiceTurnLatency.d.ts +9 -0
  114. package/dist/react/useVoiceTurnQuality.d.ts +8 -0
  115. package/dist/react/useVoiceWorkflowStatus.d.ts +8 -0
  116. package/dist/readinessProfiles.d.ts +19 -0
  117. package/dist/reconnectContract.d.ts +87 -0
  118. package/dist/resilienceRoutes.d.ts +142 -0
  119. package/dist/sessionReplay.d.ts +185 -0
  120. package/dist/simulationSuite.d.ts +120 -0
  121. package/dist/sqliteStore.d.ts +13 -2
  122. package/dist/svelte/createVoiceCampaignDialerProof.d.ts +9 -0
  123. package/dist/svelte/createVoiceDeliveryRuntime.d.ts +11 -0
  124. package/dist/svelte/createVoiceOpsActionCenter.d.ts +10 -0
  125. package/dist/svelte/createVoiceOpsStatus.d.ts +9 -0
  126. package/dist/svelte/createVoiceProviderCapabilities.d.ts +10 -0
  127. package/dist/svelte/createVoiceProviderSimulationControls.d.ts +11 -0
  128. package/dist/svelte/createVoiceProviderStatus.d.ts +4 -2
  129. package/dist/svelte/createVoiceRoutingStatus.d.ts +10 -0
  130. package/dist/svelte/createVoiceTraceTimeline.d.ts +10 -0
  131. package/dist/svelte/createVoiceTurnLatency.d.ts +11 -0
  132. package/dist/svelte/createVoiceTurnQuality.d.ts +10 -0
  133. package/dist/svelte/createVoiceWorkflowStatus.d.ts +8 -0
  134. package/dist/svelte/index.d.ts +11 -0
  135. package/dist/svelte/index.js +2903 -439
  136. package/dist/telephony/contract.d.ts +61 -0
  137. package/dist/telephony/matrix.d.ts +97 -0
  138. package/dist/telephony/plivo.d.ts +254 -0
  139. package/dist/telephony/telnyx.d.ts +247 -0
  140. package/dist/telephony/twilio.d.ts +135 -2
  141. package/dist/telephonyOutcome.d.ts +201 -0
  142. package/dist/testing/index.d.ts +2 -0
  143. package/dist/testing/index.js +2973 -156
  144. package/dist/testing/ioProviderSimulator.d.ts +41 -0
  145. package/dist/testing/providerSimulator.d.ts +44 -0
  146. package/dist/toolContract.d.ts +130 -0
  147. package/dist/toolRuntime.d.ts +50 -0
  148. package/dist/trace.d.ts +19 -1
  149. package/dist/traceDeliveryRoutes.d.ts +86 -0
  150. package/dist/traceTimeline.d.ts +93 -0
  151. package/dist/turnLatency.d.ts +95 -0
  152. package/dist/turnQuality.d.ts +94 -0
  153. package/dist/types.d.ts +170 -4
  154. package/dist/vue/VoiceDeliveryRuntime.d.ts +30 -0
  155. package/dist/vue/VoiceOpsActionCenter.d.ts +13 -0
  156. package/dist/vue/VoiceOpsStatus.d.ts +30 -0
  157. package/dist/vue/VoiceProviderCapabilities.d.ts +51 -0
  158. package/dist/vue/VoiceProviderSimulationControls.d.ts +88 -0
  159. package/dist/vue/VoiceProviderStatus.d.ts +51 -0
  160. package/dist/vue/VoiceRoutingStatus.d.ts +51 -0
  161. package/dist/vue/VoiceTurnLatency.d.ts +69 -0
  162. package/dist/vue/VoiceTurnQuality.d.ts +51 -0
  163. package/dist/vue/index.d.ts +20 -0
  164. package/dist/vue/index.js +3327 -53
  165. package/dist/vue/useVoiceCampaignDialerProof.d.ts +11 -0
  166. package/dist/vue/useVoiceController.d.ts +2 -1
  167. package/dist/vue/useVoiceDeliveryRuntime.d.ts +13 -0
  168. package/dist/vue/useVoiceOpsActionCenter.d.ts +11 -0
  169. package/dist/vue/useVoiceOpsStatus.d.ts +9 -0
  170. package/dist/vue/useVoiceProviderCapabilities.d.ts +9 -0
  171. package/dist/vue/useVoiceProviderSimulationControls.d.ts +24 -0
  172. package/dist/vue/useVoiceProviderStatus.d.ts +1 -1
  173. package/dist/vue/useVoiceRoutingStatus.d.ts +8 -0
  174. package/dist/vue/useVoiceStream.d.ts +4 -1
  175. package/dist/vue/useVoiceTraceTimeline.d.ts +9 -0
  176. package/dist/vue/useVoiceTurnLatency.d.ts +10 -0
  177. package/dist/vue/useVoiceTurnQuality.d.ts +9 -0
  178. package/dist/vue/useVoiceWorkflowStatus.d.ts +9 -0
  179. package/dist/workflowContract.d.ts +91 -0
  180. package/package.json +1 -1
package/README.md CHANGED
@@ -1,11 +1,48 @@
1
1
  # `@absolutejs/voice`
2
2
 
3
- `@absolutejs/voice` is the voice session layer for AbsoluteJS. It owns the duplex WebSocket lifecycle, transcript buffering, turn commits, reconnect behavior, and client primitives, while keeping speech vendors and session storage pluggable.
3
+ `@absolutejs/voice` is the self-hosted voice operations layer for AbsoluteJS.
4
+
5
+ It gives your app the primitives hosted voice platforms usually keep behind their dashboards: browser voice sessions, phone-call routes, provider routing, assistant tools, handoffs, traces, evals, production-readiness checks, latency proof, storage adapters, and framework-native UI helpers.
6
+
7
+ Use it when you want Vapi/Retell/Bland-style voice-agent capability, but you want the orchestration, data, traces, storage, and UI to live inside the AbsoluteJS server you already operate.
8
+
9
+ ## Why AbsoluteJS Voice
10
+
11
+ - Self-hosted by default: your app owns sessions, traces, reviews, tasks, handoffs, retention, and provider keys.
12
+ - Provider-neutral: use Deepgram, AssemblyAI, OpenAI, Anthropic, Gemini, ElevenLabs-style TTS, or your own adapters without rewriting app workflow code.
13
+ - Browser and phone surfaces: mount browser WebSocket voice routes plus Twilio, Telnyx, and Plivo telephony routes from the same package.
14
+ - Production proof: ops status, production readiness, turn quality, turn latency, live browser p50/p95 latency, trace timelines, evals, fixtures, and contracts are package primitives.
15
+ - Framework parity: React, Vue, Svelte, Angular, HTML, HTMX, and plain client entrypoints share the same core behavior.
16
+ - No hosted platform tax: AbsoluteJS Voice does not add a mandatory per-minute orchestration fee between your app and your providers.
17
+
18
+ ## Start Here
19
+
20
+ Pick the path that matches what you are building:
21
+
22
+ - Browser voice agent: mount `voice(...)`, choose an STT adapter, and use the React/Vue/Svelte/Angular/HTML/HTMX client helpers for mic, transcript, reconnect, and status UI.
23
+ - Phone voice agent: mount Twilio, Telnyx, or Plivo routes, normalize carrier outcomes, inspect carrier readiness, and persist call lifecycle traces.
24
+ - Production readiness: mount the status and proof primitives you need, such as `createVoiceOpsStatusRoutes(...)`, `createVoiceProductionReadinessRoutes(...)`, quality routes, trace routes, eval routes, and smoke contracts.
25
+ - Provider routing and fallback: use LLM/STT/TTS provider routers, provider health, provider simulation controls, and cost/latency-aware routing policies.
26
+ - Evals and simulation: mount `createVoiceSimulationSuiteRoutes(...)` to run scenario fixtures, workflow contracts, tool contracts, outcome contracts, baseline comparisons, and saved benchmark artifacts before live traffic.
27
+
28
+ ## How This Differs From Hosted Voice Platforms
29
+
30
+ Hosted voice-agent platforms are strongest when you want a managed dashboard, phone-number provisioning, hosted orchestration, and campaign tooling out of the box.
31
+
32
+ AbsoluteJS Voice is strongest when voice is part of your own product and you need code-owned primitives:
33
+
34
+ - Your app stores the call data instead of a vendor dashboard being the source of truth.
35
+ - Your app controls provider routing, fallback, retries, handoffs, and retention.
36
+ - Your team can inspect and extend every primitive.
37
+ - Your framework UI can render first-class voice state without iframe/dashboard handoffs.
38
+ - Your production checks and evals can run in CI, smoke tests, or your own admin UI.
39
+
40
+ The goal is not to clone a hosted platform. The goal is to make AbsoluteJS the best place to build and operate self-hosted voice products.
4
41
 
5
42
  ## Install
6
43
 
7
44
  ```bash
8
- bun add @absolutejs/voice
45
+ bun add @absolutejs/voice @absolutejs/voice-deepgram
9
46
  ```
10
47
 
11
48
  Peer dependencies:
@@ -21,7 +58,12 @@ Optional framework entrypoints:
21
58
  - `@absolutejs/voice/angular`
22
59
  - `@absolutejs/voice/client`
23
60
 
24
- ## Route Setup
61
+ Common optional adapters:
62
+
63
+ - `@absolutejs/voice-deepgram`
64
+ - `@absolutejs/voice-assemblyai`
65
+
66
+ ## Browser Voice Agent
25
67
 
26
68
  ```ts
27
69
  import { Elysia } from 'elysia';
@@ -73,6 +115,681 @@ const app = new Elysia()
73
115
 
74
116
  `createVoiceMemoryStore()` is dev-only. Real deployments should provide a shared store backed by Redis, Postgres, or equivalent.
75
117
 
118
+ ## Production Readiness Path
119
+
120
+ Once the basic route works, mount the proof routes you need. These give you the self-hosted operational surfaces that hosted platforms usually make mandatory, without forcing a bundled app kit:
121
+
122
+ ```ts
123
+ import {
124
+ createVoiceAuditDeliveryRoutes,
125
+ createVoiceDemoReadyRoutes,
126
+ createVoiceFileRuntimeStorage,
127
+ createVoiceLiveLatencyRoutes,
128
+ createVoiceOpsStatusRoutes,
129
+ createVoiceProductionReadinessRoutes,
130
+ createVoiceTraceDeliveryRoutes,
131
+ createVoiceTraceTimelineRoutes,
132
+ createVoiceTurnLatencyRoutes,
133
+ createVoiceTurnQualityRoutes
134
+ } from '@absolutejs/voice';
135
+
136
+ const runtime = createVoiceFileRuntimeStorage({
137
+ directory: '.voice-runtime/support'
138
+ });
139
+
140
+ app
141
+ .use(
142
+ createVoiceOpsStatusRoutes({
143
+ store: runtime.traces,
144
+ llmProviders: ['openai', 'anthropic', 'gemini'],
145
+ sttProviders: ['deepgram', 'assemblyai']
146
+ })
147
+ )
148
+ .use(
149
+ createVoiceTurnLatencyRoutes({
150
+ htmlPath: '/turn-latency',
151
+ path: '/api/turn-latency',
152
+ store: runtime.session,
153
+ traceStore: runtime.traces
154
+ })
155
+ )
156
+ .use(
157
+ createVoiceLiveLatencyRoutes({
158
+ htmlPath: '/live-latency',
159
+ path: '/api/live-latency',
160
+ store: runtime.traces
161
+ })
162
+ )
163
+ .use(
164
+ createVoiceTurnQualityRoutes({
165
+ htmlPath: '/turn-quality',
166
+ path: '/api/turn-quality',
167
+ store: runtime.session
168
+ })
169
+ )
170
+ .use(
171
+ createVoiceTraceTimelineRoutes({
172
+ htmlPath: '/traces',
173
+ path: '/api/voice-traces',
174
+ store: runtime.traces
175
+ })
176
+ )
177
+ .use(
178
+ createVoiceProductionReadinessRoutes({
179
+ audit: runtime.audit,
180
+ auditDeliveries: runtime.auditDeliveries,
181
+ htmlPath: '/production-readiness',
182
+ path: '/api/production-readiness',
183
+ store: runtime.traces,
184
+ traceDeliveries: runtime.traceDeliveries
185
+ })
186
+ )
187
+ .use(
188
+ createVoiceAuditDeliveryRoutes({
189
+ htmlPath: '/audit/deliveries',
190
+ path: '/api/voice-audit-deliveries',
191
+ store: runtime.auditDeliveries
192
+ })
193
+ )
194
+ .use(
195
+ createVoiceTraceDeliveryRoutes({
196
+ htmlPath: '/traces/deliveries',
197
+ path: '/api/voice-trace-deliveries',
198
+ store: runtime.traceDeliveries
199
+ })
200
+ );
201
+ ```
202
+
203
+ Recommended proof routes:
204
+
205
+ - `/api/voice/ops-status`: compact status for hooks, widgets, and customer-facing demos.
206
+ - `/api/voice/ops-status/html`: HTML status card for quick internal review.
207
+ - `/demo-ready`: customer-facing demo readiness checklist.
208
+ - `/production-readiness`: production gate summary.
209
+ - `/audit/deliveries`: audit sink export queue and failed delivery details.
210
+ - `/voice/phone/smoke-contract`: trace-backed phone-agent production smoke proof.
211
+ - `/traces`: per-session trace timelines.
212
+ - `/traces/deliveries`: trace sink export queue and failed delivery details.
213
+ - `/turn-latency`: server-side turn-stage latency.
214
+ - `/live-latency`: browser-measured speech-to-assistant p50/p95 latency.
215
+ - `/turn-quality`: STT confidence, correction, fallback, and transcript diagnostics.
216
+
217
+ ### Readiness Profiles
218
+
219
+ Use `createVoiceReadinessProfile(...)` when you want production-shaped defaults without adopting an app kit. Profiles are just spreadable route-option bundles for `createVoiceProductionReadinessRoutes(...)`; every option remains explicit and overrideable.
220
+
221
+ ```ts
222
+ import {
223
+ createVoiceProductionReadinessRoutes,
224
+ createVoiceReadinessProfile
225
+ } from '@absolutejs/voice';
226
+
227
+ app.use(
228
+ createVoiceProductionReadinessRoutes({
229
+ ...createVoiceReadinessProfile('meeting-recorder', {
230
+ bargeInReports: async () => [await buildBargeInReport()],
231
+ providerRoutingContracts: async () => [await runProviderRoutingContract()],
232
+ reconnectContracts: async () => [await runReconnectContract()]
233
+ }),
234
+ store: runtime.traces
235
+ })
236
+ );
237
+ ```
238
+
239
+ Built-in profiles:
240
+
241
+ - `meeting-recorder`: live latency, session health, provider fallback, routing contracts, reconnect proof, and barge-in interruption proof.
242
+ - `phone-agent`: carrier readiness, phone-agent smoke proof, handoffs, provider routing contracts, audit/trace delivery health, and delivery runtime proof.
243
+ - `ops-heavy`: audit evidence, operator action history, audit/trace delivery health, delivery runtime proof, and deploy-gate support.
244
+
245
+ Phone-agent fast path:
246
+
247
+ ```ts
248
+ app.use(
249
+ createVoiceProductionReadinessRoutes({
250
+ ...createVoiceReadinessProfile('phone-agent', {
251
+ auditDeliveries: runtime.auditDeliveries,
252
+ carriers: loadCarrierMatrixInputs,
253
+ deliveryRuntime,
254
+ phoneAgentSmokes: async () => [await runPhoneSmoke()],
255
+ providerRoutingContracts: async () => [await runProviderRoutingContract()],
256
+ traceDeliveries: runtime.traceDeliveries
257
+ }),
258
+ store: runtime.traces
259
+ })
260
+ );
261
+ ```
262
+
263
+ Ops-heavy fast path:
264
+
265
+ ```ts
266
+ app.use(
267
+ createVoiceProductionReadinessRoutes({
268
+ ...createVoiceReadinessProfile('ops-heavy', {
269
+ audit: runtime.audit,
270
+ auditDeliveries: runtime.auditDeliveries,
271
+ deliveryRuntime,
272
+ traceDeliveries: runtime.traceDeliveries
273
+ }),
274
+ gate: {
275
+ failOnWarnings: true
276
+ },
277
+ store: runtime.traces
278
+ })
279
+ );
280
+ ```
281
+
282
+ The profile helper intentionally does not mount routes, create storage, start workers, or prescribe a deploy workflow. It only returns readiness options so teams can standardize defaults while keeping control over proof sources and route mounting.
283
+
284
+ ## Delivery Runtime Presets
285
+
286
+ Use `createVoiceDeliveryRuntimePresetConfig(...)` when you want one primitive to create paired audit and trace delivery workers for the same target. The preset returns a normal `VoiceDeliveryRuntimeConfig`, so you can still inspect or override worker options before passing it to `createVoiceDeliveryRuntime(...)`.
287
+
288
+ ### File Delivery
289
+
290
+ Use file delivery for local demos, dev environments, or self-hosted deployments that collect exports from disk.
291
+
292
+ ```ts
293
+ import {
294
+ createVoiceDeliveryRuntime,
295
+ createVoiceDeliveryRuntimePresetConfig,
296
+ createVoiceDeliveryRuntimeRoutes,
297
+ createVoiceFileRuntimeStorage
298
+ } from '@absolutejs/voice';
299
+
300
+ const runtimeStorage = createVoiceFileRuntimeStorage({
301
+ directory: '.voice-runtime/support'
302
+ });
303
+
304
+ const deliveryRuntime = createVoiceDeliveryRuntime(
305
+ createVoiceDeliveryRuntimePresetConfig({
306
+ auditDeliveries: runtimeStorage.auditDeliveries,
307
+ directory: '.voice-runtime/support/delivery-exports',
308
+ leases: createLeaseCoordinator(),
309
+ mode: 'file',
310
+ traceDeliveries: runtimeStorage.traceDeliveries
311
+ })
312
+ );
313
+
314
+ app.use(
315
+ createVoiceDeliveryRuntimeRoutes({
316
+ runtime: deliveryRuntime
317
+ })
318
+ );
319
+ ```
320
+
321
+ ### Webhook Delivery
322
+
323
+ Use webhook delivery when audit and trace exports should go to your own ingestion service, SIEM bridge, warehouse collector, or internal ops backend. The built-in HTTP sinks support retries, optional HMAC signing, custom headers, timeouts, and custom envelope bodies.
324
+
325
+ ```ts
326
+ const deliveryRuntime = createVoiceDeliveryRuntime(
327
+ createVoiceDeliveryRuntimePresetConfig({
328
+ auditDeliveries: runtimeStorage.auditDeliveries,
329
+ auditSinkId: 'support-audit-webhook',
330
+ body: {
331
+ audit: ({ events }) => ({
332
+ eventCount: events.length,
333
+ events,
334
+ source: 'support-app',
335
+ surface: 'audit-deliveries'
336
+ }),
337
+ trace: ({ events }) => ({
338
+ eventCount: events.length,
339
+ events,
340
+ source: 'support-app',
341
+ surface: 'trace-deliveries'
342
+ })
343
+ },
344
+ failures: {
345
+ maxFailures: 3
346
+ },
347
+ leases: {
348
+ audit: createLeaseCoordinator(),
349
+ trace: createLeaseCoordinator()
350
+ },
351
+ mode: 'webhook',
352
+ signingSecret: process.env.VOICE_DELIVERY_WEBHOOK_SECRET,
353
+ traceDeliveries: runtimeStorage.traceDeliveries,
354
+ traceSinkId: 'support-trace-webhook',
355
+ url: process.env.VOICE_DELIVERY_WEBHOOK_URL!
356
+ })
357
+ );
358
+ ```
359
+
360
+ ### S3 Delivery
361
+
362
+ Use S3 delivery when exports should land directly in object storage through Bun's native S3 client. Set `bucket` and `keyPrefix`; the preset writes audit and trace exports under separate prefixes.
363
+
364
+ ```ts
365
+ const deliveryRuntime = createVoiceDeliveryRuntime(
366
+ createVoiceDeliveryRuntimePresetConfig({
367
+ auditDeliveries: runtimeStorage.auditDeliveries,
368
+ auditSinkId: 'support-audit-s3',
369
+ bucket: process.env.VOICE_DELIVERY_S3_BUCKET,
370
+ failures: {
371
+ maxFailures: 3
372
+ },
373
+ keyPrefix: 'support/voice-deliveries',
374
+ leases: {
375
+ audit: createLeaseCoordinator(),
376
+ trace: createLeaseCoordinator()
377
+ },
378
+ mode: 's3',
379
+ traceDeliveries: runtimeStorage.traceDeliveries,
380
+ traceSinkId: 'support-trace-s3'
381
+ })
382
+ );
383
+ ```
384
+
385
+ Mount `createVoiceDeliveryRuntimeRoutes({ runtime: deliveryRuntime })` to expose:
386
+
387
+ - `/api/voice-delivery-runtime`: combined audit and trace worker summary.
388
+ - `/api/voice-delivery-runtime/tick`: manual tick for both workers.
389
+ - `/delivery-runtime`: HTML worker control plane.
390
+
391
+ Pass the same runtime to production readiness so failed, dead-lettered, or pending export queues become deploy-blocking evidence:
392
+
393
+ ```ts
394
+ app.use(
395
+ createVoiceProductionReadinessRoutes({
396
+ auditDeliveries: runtimeStorage.auditDeliveries,
397
+ deliveryRuntime,
398
+ links: {
399
+ deliveryRuntime: '/delivery-runtime'
400
+ },
401
+ store: runtimeStorage.traces,
402
+ traceDeliveries: runtimeStorage.traceDeliveries
403
+ })
404
+ );
405
+ ```
406
+
407
+ ## Simulation Suite Path
408
+
409
+ Use `createVoiceSimulationSuiteRoutes(...)` when you want one pre-production proof surface for the things that usually live in separate dashboards or scripts:
410
+
411
+ ```ts
412
+ import {
413
+ createVoiceSimulationSuiteRoutes,
414
+ createVoiceFileRuntimeStorage
415
+ } from '@absolutejs/voice';
416
+
417
+ const runtime = createVoiceFileRuntimeStorage({
418
+ directory: '.voice-runtime/support'
419
+ });
420
+
421
+ app.use(
422
+ createVoiceSimulationSuiteRoutes({
423
+ htmlPath: '/voice/simulations',
424
+ path: '/api/voice/simulations',
425
+ store: runtime.traces,
426
+ scenarios: workflowScenarios,
427
+ fixtureStore: scenarioFixtureStore,
428
+ tools: toolContracts,
429
+ outcomes: {
430
+ contracts: outcomeContracts,
431
+ events: runtime.events,
432
+ reviews: runtime.reviews,
433
+ sessions: runtime.session,
434
+ tasks: runtime.tasks
435
+ }
436
+ })
437
+ );
438
+ ```
439
+
440
+ The suite rolls up session quality, scenario evals, fixture simulations, tool contracts, and outcome contracts into one pass/fail report. It is the code-owned equivalent of "test this voice flow before production" without requiring a hosted voice-agent dashboard.
441
+
442
+ ## Phone Voice Agent In 20 Minutes
443
+
444
+ Use `createVoicePhoneAgent(...)` when the agent needs to answer or place calls through your own Twilio, Telnyx, or Plivo account. This is the self-hosted alternative to a hosted phone-agent dashboard: your app owns the carrier routes, stream URLs, webhooks, traces, readiness checks, and lifecycle outcomes.
445
+
446
+ ```ts
447
+ import {
448
+ createVoicePhoneAgent,
449
+ createVoiceTelephonyOutcomePolicy,
450
+ runVoicePhoneAgentProductionSmokeContract
451
+ } from '@absolutejs/voice';
452
+ import { deepgram } from '@absolutejs/voice-deepgram';
453
+
454
+ const outcomePolicy = createVoiceTelephonyOutcomePolicy({
455
+ transferTarget: '+15551234567'
456
+ });
457
+
458
+ app
459
+ .use(
460
+ createVoicePhoneAgent({
461
+ setup: {
462
+ path: '/api/voice/phone/setup',
463
+ title: 'Support Phone Agent'
464
+ },
465
+ matrix: {
466
+ path: '/api/carriers',
467
+ title: 'AbsoluteJS Voice Carrier Matrix'
468
+ },
469
+ productionSmoke: {
470
+ maxAgeMs: 24 * 60 * 60 * 1000,
471
+ required: [
472
+ 'carrier-contract',
473
+ 'media-started',
474
+ 'transcript',
475
+ 'assistant-response',
476
+ 'lifecycle-outcome',
477
+ 'no-session-error',
478
+ 'fresh-trace'
479
+ ],
480
+ store: runtime.traces
481
+ },
482
+ carriers: [
483
+ {
484
+ provider: 'twilio',
485
+ options: {
486
+ context: {},
487
+ outcomePolicy,
488
+ session: runtime.session,
489
+ stt: deepgram({ apiKey: process.env.DEEPGRAM_API_KEY! }),
490
+ streamPath: '/api/voice/twilio/stream',
491
+ twiml: {
492
+ path: '/api/voice/twilio',
493
+ streamUrl: process.env.TWILIO_STREAM_URL
494
+ },
495
+ webhook: {
496
+ path: '/api/voice/twilio/webhook',
497
+ signingSecret: process.env.TWILIO_AUTH_TOKEN
498
+ },
499
+ async onTurn({ turn }) {
500
+ return { assistantText: `I heard: ${turn.text}` };
501
+ },
502
+ onComplete: async () => {}
503
+ }
504
+ }
505
+ ]
506
+ }).routes
507
+ );
508
+ ```
509
+
510
+ The wrapper mounts selected carrier routes plus two proof surfaces:
511
+
512
+ - `/api/voice/phone/setup`: one setup report with carrier URLs, smoke links, lifecycle stages, and readiness.
513
+ - `/api/voice/phone/setup?format=html`: copy/paste setup page for carrier dashboards.
514
+ - `/api/carriers`: carrier matrix JSON for Twilio, Telnyx, and Plivo.
515
+ - `/api/carriers?format=html`: side-by-side carrier readiness matrix.
516
+ - `/api/voice/phone/smoke-contract?sessionId=...`: trace-backed production smoke contract.
517
+ - `/voice/phone/smoke-contract?sessionId=...`: HTML production smoke contract.
518
+
519
+ The setup page tells you exactly what to copy into the carrier dashboard:
520
+
521
+ - Twilio: set the phone number voice webhook/TwiML URL to the reported TwiML URL, set the status callback to the reported webhook URL, and allow the reported `wss://` media stream.
522
+ - Telnyx: set the connection TeXML URL to the reported TeXML URL, set the status webhook to the reported webhook URL, and allow the reported `wss://` media stream.
523
+ - Plivo: set the answer URL to the reported answer URL, set the status callback to the reported webhook URL, and allow the reported `wss://` media stream.
524
+
525
+ Each configured carrier can also expose its own setup and smoke pages, for example:
526
+
527
+ - `/api/voice/twilio/setup?format=html`
528
+ - `/api/voice/twilio/smoke?format=html`
529
+ - `/api/voice/telnyx/setup?format=html`
530
+ - `/api/voice/telnyx/smoke?format=html`
531
+ - `/api/voice/plivo/setup?format=html`
532
+ - `/api/voice/plivo/smoke?format=html`
533
+
534
+ The phone-agent report normalizes the lifecycle schema across carriers:
535
+
536
+ - `ringing`
537
+ - `answered`
538
+ - `media-started`
539
+ - `transcript`
540
+ - `assistant-response`
541
+ - `transfer`
542
+ - `voicemail`
543
+ - `no-answer`
544
+ - `completed`
545
+ - `failed`
546
+
547
+ That is the important Vapi/Retell/Bland gap this primitive closes: a team can mount one phone-agent entrypoint, bring its own carrier account, verify readiness before live calls, and keep call traces and lifecycle outcomes inside its own AbsoluteJS app. Telnyx and Plivo use the same wrapper with `{ provider: 'telnyx', options: ... }` or `{ provider: 'plivo', options: ... }`. The lower-level `createTwilioVoiceRoutes(...)`, `createTelnyxVoiceRoutes(...)`, and `createPlivoVoiceRoutes(...)` helpers remain available when you need carrier-specific control.
548
+
549
+ After running a real smoke call, certify the phone-agent path from traces:
550
+
551
+ ```ts
552
+ const smoke = await runVoicePhoneAgentProductionSmokeContract({
553
+ maxAgeMs: 24 * 60 * 60 * 1000,
554
+ required: [
555
+ 'media-started',
556
+ 'transcript',
557
+ 'assistant-response',
558
+ 'lifecycle-outcome',
559
+ 'no-session-error',
560
+ 'fresh-trace'
561
+ ],
562
+ sessionId: 'phone-smoke-session',
563
+ store: runtime.traces
564
+ });
565
+
566
+ if (!smoke.pass) {
567
+ throw new Error(smoke.issues.map((issue) => issue.message).join('\n'));
568
+ }
569
+ ```
570
+
571
+ Pass those reports into production readiness through `phoneAgentSmokes`. This makes deployment fail when the carrier setup exists but the actual phone-agent call path did not produce media start, transcript, assistant response, terminal lifecycle outcome, and clean trace evidence.
572
+
573
+ When `productionSmoke` is enabled on `createVoicePhoneAgent(...)`, the wrapper mounts `/api/voice/phone/smoke-contract?sessionId=...` for JSON and `/voice/phone/smoke-contract?sessionId=...` for HTML. It also derives carrier contract evidence from the existing carrier matrix unless you provide a custom `getContract`.
574
+
575
+ ## Ops Status Hooks And Widgets
576
+
577
+ Use `createVoiceOpsStatusRoutes(...)` when you want a small status endpoint for demos, admin pages, and framework widgets. It is intentionally not a route bundle: mount quality gates, eval routes, provider health, session replay, phone-agent smoke proof, handoff health, and diagnostics explicitly when your app needs them.
578
+
579
+ ```ts
580
+ import {
581
+ createVoiceDemoReadyRoutes,
582
+ createVoiceFileRuntimeStorage,
583
+ createVoiceOpsStatusRoutes,
584
+ summarizeVoiceOpsStatus
585
+ } from '@absolutejs/voice';
586
+
587
+ const runtime = createVoiceFileRuntimeStorage({ directory: '.voice-runtime/support' });
588
+
589
+ app.use(
590
+ createVoiceOpsStatusRoutes({
591
+ store: runtime.traces,
592
+ llmProviders: ['openai', 'anthropic', 'gemini'],
593
+ sttProviders: ['deepgram', 'assemblyai']
594
+ })
595
+ );
596
+ ```
597
+
598
+ The status endpoint is intentionally small enough for customer-facing demos. It can report fixture-backed workflow readiness while leaving deeper live quality/session failures visible on the proof routes you mount separately.
599
+
600
+ For a single demo page that rolls up ops status, production readiness, phone setup, and phone smoke proof, mount `createVoiceDemoReadyRoutes(...)` with the same reports you already expose elsewhere:
601
+
602
+ ```ts
603
+ app.use(
604
+ createVoiceDemoReadyRoutes({
605
+ opsStatus: {
606
+ href: '/api/voice/ops-status',
607
+ load: () => summarizeVoiceOpsStatus(opsStatusOptions)
608
+ },
609
+ phoneSetup: {
610
+ href: '/api/voice/phone/setup?format=html',
611
+ load: () => phoneAgentSetupReport
612
+ },
613
+ phoneSmoke: {
614
+ href: '/voice/phone/smoke-contract',
615
+ load: () => phoneSmokeReport
616
+ },
617
+ productionReadiness: {
618
+ href: '/production-readiness',
619
+ load: () => productionReadinessReport
620
+ }
621
+ })
622
+ );
623
+ ```
624
+
625
+ ```ts
626
+ app.use(
627
+ createVoiceOpsStatusRoutes({
628
+ include: { quality: false, sessions: false },
629
+ preferFixtureWorkflows: true,
630
+ store: runtime.traces
631
+ })
632
+ );
633
+ ```
634
+
635
+ ### React Status Widget
636
+
637
+ ```tsx
638
+ import { VoiceOpsStatus } from '@absolutejs/voice/react';
639
+
640
+ export function OpsBadge() {
641
+ return <VoiceOpsStatus intervalMs={5000} />;
642
+ }
643
+ ```
644
+
645
+ ### Vue Status Widget
646
+
647
+ ```vue
648
+ <script setup lang="ts">
649
+ import { VoiceOpsStatus } from '@absolutejs/voice/vue';
650
+ </script>
651
+
652
+ <template>
653
+ <VoiceOpsStatus :interval-ms="5000" />
654
+ </template>
655
+ ```
656
+
657
+ ### Svelte Status Widget
658
+
659
+ ```svelte
660
+ <script lang="ts">
661
+ import { onDestroy, onMount } from 'svelte';
662
+ import { createVoiceOpsStatus } from '@absolutejs/voice/svelte';
663
+
664
+ const status = createVoiceOpsStatus('/api/voice/ops-status', { intervalMs: 5000 });
665
+ let html = '';
666
+ onMount(() => status.subscribe(() => (html = status.getHTML())));
667
+ onDestroy(() => status.close());
668
+ </script>
669
+
670
+ {@html html}
671
+ ```
672
+
673
+ ### Angular Status Widget
674
+
675
+ ```ts
676
+ import { VoiceOpsStatusService } from '@absolutejs/voice/angular';
677
+
678
+ status = inject(VoiceOpsStatusService).connect('/api/voice/ops-status', {
679
+ intervalMs: 5000
680
+ });
681
+ ```
682
+
683
+ ```html
684
+ <h2>{{ status.report()?.status === 'pass' ? 'Passing' : 'Needs attention' }}</h2>
685
+ <p>{{ status.report()?.passed ?? 0 }} passing checks</p>
686
+ ```
687
+
688
+ ### HTML Or HTMX Status Widget
689
+
690
+ ```html
691
+ <div id="voice-ops-status"></div>
692
+ <script type="module">
693
+ import { mountVoiceOpsStatus } from '@absolutejs/voice/client';
694
+
695
+ mountVoiceOpsStatus(document.querySelector('#voice-ops-status'), '/api/voice/ops-status', {
696
+ intervalMs: 5000
697
+ });
698
+ </script>
699
+ ```
700
+
701
+ For custom elements:
702
+
703
+ ```html
704
+ <absolute-voice-ops-status interval-ms="5000"></absolute-voice-ops-status>
705
+ <script type="module">
706
+ import { defineVoiceOpsStatusElement } from '@absolutejs/voice/client';
707
+ defineVoiceOpsStatusElement();
708
+ </script>
709
+ ```
710
+
711
+ ## Delivery Runtime Widgets
712
+
713
+ After mounting `createVoiceDeliveryRuntimeRoutes(...)`, apps can expose audit and trace worker health through the same framework-native primitives:
714
+
715
+ ```tsx
716
+ import { VoiceDeliveryRuntime } from '@absolutejs/voice/react';
717
+
718
+ export function DeliveryWorkers() {
719
+ return <VoiceDeliveryRuntime intervalMs={5000} />;
720
+ }
721
+ ```
722
+
723
+ The widget includes operator actions by default: `Tick workers` drains pending/failed deliveries, and `Requeue dead letters` moves reviewed dead-lettered audit/trace deliveries back into the live queues. Pass `includeActions={false}` when you only want a read-only status card.
724
+
725
+ ```ts
726
+ import { VoiceDeliveryRuntime } from '@absolutejs/voice/vue';
727
+ import { createVoiceDeliveryRuntime } from '@absolutejs/voice/svelte';
728
+ import { VoiceDeliveryRuntimeService } from '@absolutejs/voice/angular';
729
+ ```
730
+
731
+ For HTML or HTMX pages:
732
+
733
+ ```html
734
+ <absolute-voice-delivery-runtime interval-ms="5000"></absolute-voice-delivery-runtime>
735
+ <script type="module">
736
+ import { defineVoiceDeliveryRuntimeElement } from '@absolutejs/voice/client';
737
+ defineVoiceDeliveryRuntimeElement();
738
+ </script>
739
+ ```
740
+
741
+ ## Voice Ops Action Center
742
+
743
+ Use `VoiceOpsActionCenter` when you want one primitive operator panel for production proofs and recovery actions without building a dashboard. The default action builder can include production readiness refresh, delivery worker ticks, dead-letter requeue, turn-latency proof, and provider failover simulation.
744
+
745
+ ```tsx
746
+ import { VoiceOpsActionCenter } from '@absolutejs/voice/react';
747
+ import { createVoiceOpsActionCenterActions } from '@absolutejs/voice/client';
748
+
749
+ export function OperatorPanel() {
750
+ return (
751
+ <VoiceOpsActionCenter
752
+ actions={createVoiceOpsActionCenterActions({
753
+ providers: ['deepgram', 'assemblyai']
754
+ })}
755
+ />
756
+ );
757
+ }
758
+ ```
759
+
760
+ Mount `createVoiceOpsActionAuditRoutes(...)` to make every action-center click auditable. The client posts successful and failed action results to `/api/voice/ops-actions/audit` by default, and the route records both `operator.action` audit events and `operator.action` trace events.
761
+
762
+ ```ts
763
+ import { createVoiceOpsActionAuditRoutes } from '@absolutejs/voice';
764
+
765
+ app.use(
766
+ createVoiceOpsActionAuditRoutes({
767
+ audit: runtimeStorage.audit,
768
+ trace: runtimeStorage.traces
769
+ })
770
+ );
771
+ ```
772
+
773
+ The same route exposes `GET /api/voice/ops-actions/history` and `/voice/ops-actions` so apps can show recent operator actions beside the action center. For HTML or HTMX pages, use `mountVoiceOpsActionHistory(...)` from `@absolutejs/voice/client`.
774
+
775
+ For HTML or HTMX pages:
776
+
777
+ ```html
778
+ <div id="voice-ops-actions"></div>
779
+ <script type="module">
780
+ import {
781
+ createVoiceOpsActionCenterActions,
782
+ mountVoiceOpsActionCenter
783
+ } from '@absolutejs/voice/client';
784
+
785
+ mountVoiceOpsActionCenter(document.querySelector('#voice-ops-actions'), {
786
+ actions: createVoiceOpsActionCenterActions({
787
+ providers: ['deepgram']
788
+ })
789
+ });
790
+ </script>
791
+ ```
792
+
76
793
  ## Voice Assistants
77
794
 
78
795
  Use `createVoiceAssistant(...)` when you want one product-level surface for a voice agent instead of wiring tools, guardrails, experiments, traces, and ops recipes separately. It returns a standard `onTurn` handler, plus an `ops` object you can pass to `voice(...)`.
@@ -212,7 +929,21 @@ const billingAgent = createVoiceAgent({
212
929
  const frontDesk = createVoiceAgentSquad({
213
930
  id: 'front-desk',
214
931
  defaultAgentId: 'support',
215
- agents: [supportAgent, billingAgent]
932
+ agents: [supportAgent, billingAgent],
933
+ handoffPolicy: ({ handoff }) => {
934
+ if (handoff.targetAgentId === 'billing') {
935
+ return {
936
+ summary: 'Route verified billing requests to the billing specialist.',
937
+ metadata: { queue: 'billing' }
938
+ };
939
+ }
940
+
941
+ return {
942
+ allow: false,
943
+ reason: `No approved route for ${handoff.targetAgentId}.`,
944
+ escalate: { reason: 'unsupported-specialist' }
945
+ };
946
+ }
216
947
  });
217
948
 
218
949
  voice({
@@ -226,6 +957,56 @@ voice({
226
957
 
227
958
  `createVoiceAgentSquad(...)` gives you squad-style specialization without locking your app into a hosted voice platform. An agent can return `handoff: { targetAgentId: 'billing' }`; the squad records the handoff, runs the target agent on the same turn, and still returns a standard `VoiceRouteResult`.
228
959
 
960
+ For production call centers, pass `handoffPolicy` to keep routing code-owned instead of dashboard-owned. The policy can allow a handoff, reroute it to a different specialist, merge handoff metadata, summarize the reason for the target agent, or block the handoff and return an escalation. Squad traces mark each handoff as `allowed`, `blocked`, `unknown-target`, or `max-exceeded`, so support teams can audit why a caller moved between specialists.
961
+
962
+ Use `runVoiceAgentSquadContract(...)` in tests or readiness checks when you need proof that a specialist graph still routes correctly:
963
+
964
+ ```ts
965
+ import {
966
+ createVoiceMemoryTraceEventStore,
967
+ runVoiceAgentSquadContract
968
+ } from '@absolutejs/voice';
969
+
970
+ const trace = createVoiceMemoryTraceEventStore();
971
+ const frontDesk = createVoiceAgentSquad({
972
+ id: 'front-desk',
973
+ defaultAgentId: 'support',
974
+ agents: [supportAgent, billingAgent],
975
+ trace
976
+ });
977
+
978
+ const report = await runVoiceAgentSquadContract({
979
+ context: {},
980
+ squad: frontDesk,
981
+ trace,
982
+ contract: {
983
+ id: 'billing-route',
984
+ scenarioId: 'billing-route',
985
+ turns: [
986
+ {
987
+ text: 'I have a billing question.',
988
+ expect: {
989
+ finalAgentId: 'billing',
990
+ outcome: 'assistant',
991
+ assistantIncludes: ['billing'],
992
+ handoffs: [
993
+ {
994
+ fromAgentId: 'support',
995
+ targetAgentId: 'billing',
996
+ status: 'allowed'
997
+ }
998
+ ]
999
+ }
1000
+ }
1001
+ ]
1002
+ }
1003
+ });
1004
+
1005
+ if (!report.pass) {
1006
+ throw new Error(report.issues.map((issue) => issue.message).join('\n'));
1007
+ }
1008
+ ```
1009
+
229
1010
  ## Traces And Replay
230
1011
 
231
1012
  Use trace stores when you want every call to be inspectable outside a hosted platform. Trace events are append-only records for model passes, tool calls, handoffs, agent results, call lifecycle, turn timing, errors, and cost telemetry.
@@ -233,13 +1014,22 @@ Use trace stores when you want every call to be inspectable outside a hosted pla
233
1014
  ```ts
234
1015
  import {
235
1016
  buildVoiceTraceReplay,
1017
+ buildVoiceAuditExport,
1018
+ createVoiceAuditHTTPSink,
1019
+ createVoiceAuditLogger,
1020
+ createVoiceAuditSinkDeliveryWorker,
1021
+ createVoiceAuditSinkStore,
1022
+ createVoiceAuditTrailRoutes,
236
1023
  createVoiceAgent,
237
1024
  createVoiceFileRuntimeStorage,
238
1025
  createVoiceRedisTaskLeaseCoordinator,
1026
+ createVoiceTraceDeliveryRoutes,
239
1027
  createVoiceTraceHTTPSink,
240
1028
  createVoiceTraceSinkStore,
241
1029
  createVoiceTraceSinkDeliveryWorker,
1030
+ buildVoiceDataRetentionPlan,
242
1031
  exportVoiceTrace,
1032
+ applyVoiceDataRetentionPolicy,
243
1033
  pruneVoiceTraceEvents,
244
1034
  voice
245
1035
  } from '@absolutejs/voice';
@@ -251,6 +1041,30 @@ const runtimeStorage = createVoiceFileRuntimeStorage({
251
1041
  const redisLeases = createVoiceRedisTaskLeaseCoordinator({
252
1042
  url: process.env.REDIS_URL
253
1043
  });
1044
+ const auditStore = createVoiceAuditSinkStore({
1045
+ store: runtimeStorage.audit,
1046
+ deliveryQueue: runtimeStorage.auditDeliveries,
1047
+ sinks: [
1048
+ createVoiceAuditHTTPSink({
1049
+ id: 'security-warehouse',
1050
+ signingSecret: process.env.VOICE_AUDIT_SINK_SECRET,
1051
+ url: process.env.VOICE_AUDIT_SINK_URL!
1052
+ })
1053
+ ]
1054
+ });
1055
+ const audit = createVoiceAuditLogger(auditStore);
1056
+ const auditSinkWorker = createVoiceAuditSinkDeliveryWorker({
1057
+ deliveries: runtimeStorage.auditDeliveries,
1058
+ leases: redisLeases,
1059
+ sinks: [
1060
+ createVoiceAuditHTTPSink({
1061
+ id: 'security-warehouse',
1062
+ signingSecret: process.env.VOICE_AUDIT_SINK_SECRET,
1063
+ url: process.env.VOICE_AUDIT_SINK_URL!
1064
+ })
1065
+ ],
1066
+ workerId: 'audit-sink-worker'
1067
+ });
254
1068
  const trace = createVoiceTraceSinkStore({
255
1069
  store: runtimeStorage.traces,
256
1070
  deliveryQueue: runtimeStorage.traceDeliveries,
@@ -277,6 +1091,9 @@ const traceSinkWorker = createVoiceTraceSinkDeliveryWorker({
277
1091
 
278
1092
  const supportAgent = createVoiceAgent({
279
1093
  id: 'support',
1094
+ audit,
1095
+ auditProvider: 'openai',
1096
+ auditModel: 'gpt-4.1',
280
1097
  trace,
281
1098
  model: {
282
1099
  async generate() {
@@ -293,6 +1110,17 @@ voice({
293
1110
  onTurn: supportAgent.onTurn,
294
1111
  onComplete: async () => {}
295
1112
  });
1113
+ app.use(
1114
+ createVoiceAuditTrailRoutes({
1115
+ store: runtimeStorage.audit
1116
+ })
1117
+ );
1118
+ app.use(
1119
+ createVoiceTraceDeliveryRoutes({
1120
+ store: runtimeStorage.traceDeliveries,
1121
+ worker: traceSinkWorker
1122
+ })
1123
+ );
296
1124
 
297
1125
  const replay = await exportVoiceTrace({
298
1126
  store: runtimeStorage.traces,
@@ -314,18 +1142,53 @@ await pruneVoiceTraceEvents({
314
1142
  store: runtimeStorage.traces,
315
1143
  before: Date.now() - 30 * 24 * 60 * 60 * 1000
316
1144
  });
1145
+
1146
+ await audit.operatorAction({
1147
+ action: 'review.approve',
1148
+ actor: { id: 'operator-123', kind: 'operator' },
1149
+ resource: { id: 'review-123', type: 'review' }
1150
+ });
317
1151
  ```
318
1152
 
319
1153
  `createVoiceMemoryTraceEventStore(...)`, `createVoiceFileTraceEventStore(...)`, `createVoiceSQLiteTraceEventStore(...)`, and `createVoicePostgresTraceEventStore(...)` all implement the same `VoiceTraceEventStore` contract. File, SQLite, and Postgres runtime storage expose `runtimeStorage.traces` and `runtimeStorage.traceDeliveries` alongside sessions, reviews, tasks, events, and external object mappings. Passing `trace` to `voice(...)` records session lifecycle, transcript, committed-turn, assistant, cost, and error events; passing it to agents records model passes, tools, results, and handoffs.
320
1154
 
321
1155
  For self-hosted QA and support workflows, use `summarizeVoiceTrace(...)`, `evaluateVoiceTrace(...)`, `renderVoiceTraceMarkdown(...)`, `renderVoiceTraceHTML(...)`, or `buildVoiceTraceReplay(...)`. They turn raw trace events into portable artifacts you can attach to tickets, inspect locally, or fail in CI when a call has missing transcripts, missing turns, tool errors, session errors, or excessive handoffs.
322
1156
 
323
- For observability pipelines, wrap any trace store with `createVoiceTraceSinkStore(...)` and pass sinks such as `createVoiceTraceHTTPSink(...)`. The wrapper still writes to your normal file, SQLite, or Postgres store, then fans out appended events to your warehouse, logs, S3 bridge, or analytics endpoint. Use `awaitDelivery: true` only when you want trace delivery to block append completion. For durable delivery, pass `deliveryQueue` and run `createVoiceTraceSinkDeliveryWorker(...)` or `createVoiceTraceSinkDeliveryWorkerLoop(...)`; the worker uses the same Redis lease/idempotency primitives as ops workers and supports retries plus dead-letter stores.
1157
+ For observability pipelines, wrap any trace store with `createVoiceTraceSinkStore(...)` and pass sinks such as `createVoiceTraceHTTPSink(...)`. The wrapper still writes to your normal file, SQLite, or Postgres store, then fans out appended events to your warehouse, logs, S3 bridge, or analytics endpoint. Use `awaitDelivery: true` only when you want trace delivery to block append completion. For durable delivery, pass `deliveryQueue` and run `createVoiceTraceSinkDeliveryWorker(...)` or `createVoiceTraceSinkDeliveryWorkerLoop(...)`; the worker uses the same Redis lease/idempotency primitives as ops workers and supports retries plus dead-letter stores. Mount `createVoiceTraceDeliveryRoutes({ store: runtimeStorage.traceDeliveries, worker })` to expose `/traces/deliveries`, `/api/voice-trace-deliveries`, and an explicit `POST /api/voice-trace-deliveries/drain` retry path.
324
1158
 
325
1159
  When traces may leave your private runtime, pass `redact: true` or a redaction config to `exportVoiceTrace(...)`, `renderVoiceTraceMarkdown(...)`, `renderVoiceTraceHTML(...)`, or `buildVoiceTraceReplay(...)`. The built-in redactor scrubs common email addresses, phone numbers, and sensitive keys like `token`, `secret`, `password`, `apiKey`, `authorization`, `phone`, and `email`; you can pass custom keys or replacement text for stricter policies.
326
1160
 
327
1161
  For retention jobs, `pruneVoiceTraceEvents(...)` works against any trace store. Use `dryRun: true` before deleting, filter by session, trace, scenario, turn, or event type, cap each run with `limit`, or keep only the newest N matching events with `keepNewest`.
328
1162
 
1163
+ For whole-runtime data control, use `buildVoiceDataRetentionPlan(...)` first and then `applyVoiceDataRetentionPolicy(...)` when the deletion set is correct. The policy works across stores exposed by file, SQLite, or Postgres runtime storage, including sessions, traces, trace deliveries, audit deliveries, reviews, ops tasks, integration events, and campaigns. A cutoff or per-scope `keepNewest` selector is required before anything is deleted, so an empty policy reports skipped scopes instead of wiping data.
1164
+
1165
+ ```ts
1166
+ const plan = await buildVoiceDataRetentionPlan({
1167
+ before: Date.now() - 30 * 24 * 60 * 60 * 1000,
1168
+ ...runtimeStorage
1169
+ });
1170
+
1171
+ console.log(plan.scopes);
1172
+
1173
+ await applyVoiceDataRetentionPolicy({
1174
+ audit: runtimeStorage.audit,
1175
+ before: Date.now() - 30 * 24 * 60 * 60 * 1000,
1176
+ ...runtimeStorage
1177
+ });
1178
+ ```
1179
+
1180
+ Use `createVoiceAuditLogger(...)` when you need append-only compliance evidence outside call traces. The logger records provider calls, tool calls, handoffs, retention runs, and operator actions into `runtimeStorage.audit`, so self-hosted teams can prove who changed what, which provider ran, which tool fired, and what data-control policy deleted.
1181
+
1182
+ Pass `audit` directly to `createVoiceAgent(...)` to record model calls as provider-call audit events and tool executions as tool-call audit events. Pass it to `createVoiceAgentSquad(...)` to record squad handoffs automatically. Use `auditProvider` and `auditModel` on agents when you want readiness and compliance reports to show the actual model provider instead of the agent id.
1183
+
1184
+ For compliance pipelines, wrap any audit store with `createVoiceAuditSinkStore(...)` and pass sinks such as `createVoiceAuditHTTPSink(...)`. Audit sinks redact by default, support HMAC signing, retries, event-type filters, optional blocking delivery, durable delivery queues through `runtimeStorage.auditDeliveries`, and background workers through `createVoiceAuditSinkDeliveryWorker(...)` or `createVoiceAuditSinkDeliveryWorkerLoop(...)`. File, SQLite, and Postgres runtime storage all expose `auditDeliveries`, so teams can ship evidence to a SIEM, warehouse, or internal security service without a hosted dashboard. Mount `createVoiceAuditDeliveryRoutes({ store: runtimeStorage.auditDeliveries, worker })` to expose `/audit/deliveries`, `/api/voice-audit-deliveries`, and an explicit `POST /api/voice-audit-deliveries/drain` retry path.
1185
+
1186
+ Pass `audit: runtimeStorage.audit` into production readiness when audit coverage should block deploys. By default readiness requires provider-call, retention-policy, and operator-action audit evidence; retention-policy evidence must be from the last 7 days so a stale one-time audit event does not certify an active retention job. Override required event types or freshness with `audit: { store: runtimeStorage.audit, require: [{ type: 'retention.policy', maxAgeMs: ... }] }` when a deployment has different compliance gates. Pass `auditDeliveries: runtimeStorage.auditDeliveries` and `traceDeliveries: runtimeStorage.traceDeliveries` when sink export health should also block deploys; failed or dead-lettered deliveries fail readiness, pending deliveries warn, and pending deliveries older than the configured fail window fail readiness.
1187
+
1188
+ Mount `createVoiceAuditTrailRoutes(...)` to expose `/api/voice-audit` and `/audit` over the same store. File, SQLite, and Postgres runtime storage all expose `runtimeStorage.audit`. The JSON and HTML surfaces support filters like `type`, `outcome`, `actorId`, `resourceType`, `resourceId`, `sessionId`, `traceId`, and `limit`, so operators can search audit evidence without writing a custom viewer first.
1189
+
1190
+ Use `exportVoiceAuditTrail(...)` or `buildVoiceAuditExport(...)` when audit evidence needs to leave the app. Pass `redact: true` to scrub sensitive keys plus common email and phone patterns from payloads and metadata before generating JSON, Markdown, or HTML. Audit trail routes also expose redacted exports at `/api/voice-audit/export`, `/api/voice-audit/export?format=markdown`, `/api/voice-audit/export?format=html`, and `/audit/export`; export routes redact by default unless `redact=false` is passed.
1191
+
329
1192
  ## Production Voice Ops
330
1193
 
331
1194
  The recommended production pattern is:
@@ -733,6 +1596,59 @@ app.use(
733
1596
 
734
1597
  Client state now exposes `assistantAudio` on the stream/controller helpers, so apps can buffer or play synthesized chunks without inventing a second transport.
735
1598
 
1599
+ ## OpenAI Realtime
1600
+
1601
+ Use `createOpenAIRealtimeAdapter(...)` when you want a direct OpenAI Realtime speech-to-speech output path for live smoke tests, duplex benchmarks, or custom realtime orchestration. It implements the same `RealtimeAdapter` contract used by the benchmark harness, so the provider can stream `response.output_audio.delta` audio chunks into AbsoluteJS voice events while still emitting normalized transcript, error, and close events.
1602
+
1603
+ ```ts
1604
+ import { createOpenAIRealtimeAdapter } from '@absolutejs/voice';
1605
+ import { runTTSAdapterFixture } from '@absolutejs/voice/testing';
1606
+
1607
+ const realtime = createOpenAIRealtimeAdapter({
1608
+ apiKey: process.env.OPENAI_API_KEY!,
1609
+ instructions: 'Answer in one concise sentence.',
1610
+ model: 'gpt-realtime',
1611
+ voice: 'marin'
1612
+ });
1613
+
1614
+ app.use(
1615
+ voice({
1616
+ path: '/voice',
1617
+ realtime,
1618
+ realtimeInputFormat: {
1619
+ channels: 1,
1620
+ container: 'raw',
1621
+ encoding: 'pcm_s16le',
1622
+ sampleRateHz: 24000
1623
+ },
1624
+ session,
1625
+ onTurn: async ({ turn }) => ({
1626
+ assistantText: `You said: ${turn.text}`
1627
+ }),
1628
+ onComplete: async () => {}
1629
+ })
1630
+ );
1631
+
1632
+ const report = await runTTSAdapterFixture(
1633
+ realtime,
1634
+ {
1635
+ id: 'openai-realtime-smoke',
1636
+ text: 'Say exactly: AbsoluteJS realtime is online.',
1637
+ title: 'OpenAI Realtime smoke'
1638
+ },
1639
+ {
1640
+ realtimeFormat: {
1641
+ channels: 1,
1642
+ container: 'raw',
1643
+ encoding: 'pcm_s16le',
1644
+ sampleRateHz: 24000
1645
+ }
1646
+ }
1647
+ );
1648
+ ```
1649
+
1650
+ For server-to-server use, the adapter opens a WebSocket to OpenAI, sends `session.update`, streams text or base64 PCM input, and emits raw 24kHz mono `pcm_s16le` assistant audio. It requires raw 24kHz mono PCM input because that is the OpenAI Realtime PCM format. The main `voice(...)` route can now run in cascaded mode with `stt` plus optional `tts`, or direct realtime mode with `realtime`. Browser demos should make sure the captured PCM format matches `realtimeInputFormat` or resample before sending audio.
1651
+
736
1652
  If you want a minimal browser playback path, use the client audio player:
737
1653
 
738
1654
  ```ts
@@ -1069,6 +1985,136 @@ app.use(
1069
1985
  - `benchmark-results/sessions-cheap-stt-runs-3.json`
1070
1986
  - `benchmark-results/stt-routing-run-manifest.json`
1071
1987
 
1988
+ ## LLM Provider Routing
1989
+
1990
+ Use `createVoiceProviderRouter(...)` when your assistant can run on more than one LLM provider. The router keeps provider choice inside your app: you define the available model adapters, profile each provider, and choose a policy.
1991
+
1992
+ ```ts
1993
+ import {
1994
+ createAnthropicVoiceAssistantModel,
1995
+ createGeminiVoiceAssistantModel,
1996
+ createOpenAIVoiceAssistantModel,
1997
+ createVoiceProviderRouter,
1998
+ resolveVoiceProviderRoutingPolicyPreset
1999
+ } from '@absolutejs/voice';
2000
+
2001
+ const model = createVoiceProviderRouter({
2002
+ providers: {
2003
+ openai: createOpenAIVoiceAssistantModel({ apiKey: process.env.OPENAI_API_KEY! }),
2004
+ anthropic: createAnthropicVoiceAssistantModel({ apiKey: process.env.ANTHROPIC_API_KEY! }),
2005
+ gemini: createGeminiVoiceAssistantModel({ apiKey: process.env.GEMINI_API_KEY! })
2006
+ },
2007
+ providerHealth: {
2008
+ failureThreshold: 1,
2009
+ cooldownMs: 30_000,
2010
+ rateLimitCooldownMs: 120_000
2011
+ },
2012
+ providerProfiles: {
2013
+ openai: { cost: 6, latencyMs: 650, quality: 0.92, timeoutMs: 3500 },
2014
+ anthropic: { cost: 7, latencyMs: 850, quality: 0.95, timeoutMs: 4500 },
2015
+ gemini: { cost: 2, latencyMs: 700, quality: 0.86, timeoutMs: 3500 }
2016
+ },
2017
+ policy: resolveVoiceProviderRoutingPolicyPreset('balanced')
2018
+ });
2019
+ ```
2020
+
2021
+ Built-in policy presets:
2022
+
2023
+ - `quality-first`: rank by `providerProfiles[provider].quality`, then priority, latency, and cost.
2024
+ - `latency-first`: rank by expected latency.
2025
+ - `cost-first`: rank by expected cost.
2026
+ - `cost-cap`: rank by cost and reject providers above `maxCost`.
2027
+ - `balanced`: weighted score using cost, latency, quality, and priority.
2028
+
2029
+ Budget filters are strict. If you pass `maxCost`, `maxLatencyMs`, or `minQuality`, providers outside those limits are removed before ranking, even if they were selected by the request.
2030
+
2031
+ ```ts
2032
+ const policy = resolveVoiceProviderRoutingPolicyPreset('cost-cap', {
2033
+ maxCost: 3,
2034
+ minQuality: 0.82
2035
+ });
2036
+ ```
2037
+
2038
+ Use `runVoiceProviderRoutingContract(...)` when provider fallback needs to be certified before production. The contract reads provider routing trace events and verifies the expected selected provider, fallback provider, status, and kind in order.
2039
+
2040
+ ```ts
2041
+ import { runVoiceProviderRoutingContract } from '@absolutejs/voice';
2042
+
2043
+ const report = await runVoiceProviderRoutingContract({
2044
+ store: runtime.traces,
2045
+ contract: {
2046
+ id: 'openai-to-anthropic-fallback',
2047
+ expect: [
2048
+ {
2049
+ kind: 'llm',
2050
+ provider: 'openai',
2051
+ selectedProvider: 'openai',
2052
+ fallbackProvider: 'anthropic',
2053
+ status: 'error'
2054
+ },
2055
+ {
2056
+ kind: 'llm',
2057
+ provider: 'anthropic',
2058
+ selectedProvider: 'openai',
2059
+ status: 'fallback'
2060
+ }
2061
+ ]
2062
+ }
2063
+ });
2064
+
2065
+ if (!report.pass) {
2066
+ throw new Error(report.issues.map((issue) => issue.message).join('\n'));
2067
+ }
2068
+ ```
2069
+
2070
+ Pass provider routing contract reports into production readiness through `providerRoutingContracts`. Readiness fails when a fallback contract fails, so model-routing regressions become deploy blockers instead of dashboard-only surprises.
2071
+
2072
+ For full control, pass an object policy:
2073
+
2074
+ ```ts
2075
+ const model = createVoiceProviderRouter({
2076
+ providers,
2077
+ providerProfiles,
2078
+ policy: {
2079
+ strategy: 'balanced',
2080
+ maxLatencyMs: 1000,
2081
+ weights: { cost: 1, latencyMs: 0.004, quality: 12 }
2082
+ }
2083
+ });
2084
+ ```
2085
+
2086
+ The same profile and policy shape also works for STT and TTS provider routers, so a self-hosted app can choose the fastest provider for live calls, cap cost for background work, or require a minimum quality score without hard-coding provider branches.
2087
+
2088
+ ```ts
2089
+ const stt = createVoiceSTTProviderRouter({
2090
+ adapters: {
2091
+ deepgram,
2092
+ assemblyai
2093
+ },
2094
+ providerHealth: { cooldownMs: 30_000 },
2095
+ providerProfiles: {
2096
+ deepgram: { cost: 4, latencyMs: 180, quality: 0.93, timeoutMs: 1500 },
2097
+ assemblyai: { cost: 2, latencyMs: 650, quality: 0.88, timeoutMs: 3000 }
2098
+ },
2099
+ policy: resolveVoiceProviderRoutingPolicyPreset('latency-first')
2100
+ });
2101
+
2102
+ const tts = createVoiceTTSProviderRouter({
2103
+ adapters: {
2104
+ elevenlabs,
2105
+ openai
2106
+ },
2107
+ providerProfiles: {
2108
+ elevenlabs: { cost: 5, latencyMs: 220, quality: 0.94 },
2109
+ openai: { cost: 2, latencyMs: 320, quality: 0.87 }
2110
+ },
2111
+ policy: resolveVoiceProviderRoutingPolicyPreset('cost-cap', {
2112
+ maxCost: 3,
2113
+ minQuality: 0.85
2114
+ })
2115
+ });
2116
+ ```
2117
+
1072
2118
  ## Presets
1073
2119
 
1074
2120
  Voice now ships named runtime presets so apps can start from a useful baseline instead of hand-tuning silence and capture settings every time.
@@ -1566,6 +2612,8 @@ Default reconnect strategy is `resume-last-turn`.
1566
2612
 
1567
2613
  If an adapter does not emit native end-of-turn events, core falls back to silence detection with a default `700ms` threshold.
1568
2614
 
2615
+ For browser/client proof, use `runVoiceReconnectContract(...)` or mount `createVoiceReconnectContractRoutes(...)` with captured reconnect snapshots. The contract verifies that a reconnect was observed, the stream resumed before exhaustion, and replayed state did not duplicate committed turn IDs.
2616
+
1569
2617
  ## STT Fallback
1570
2618
 
1571
2619
  You can pair a primary vendor with an optional fallback vendor per route when you need extra reliability for accents, edge environments, or short commands.