@kuralle-syrinx/core 4.4.0 → 4.5.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.
Files changed (217) hide show
  1. package/dist/audio/alaw.d.ts +3 -0
  2. package/dist/audio/alaw.d.ts.map +1 -0
  3. package/dist/audio/alaw.js +53 -0
  4. package/dist/audio/alaw.js.map +1 -0
  5. package/dist/audio/g722.d.ts +39 -0
  6. package/dist/audio/g722.d.ts.map +1 -0
  7. package/dist/audio/g722.js +286 -0
  8. package/dist/audio/g722.js.map +1 -0
  9. package/dist/audio/index.d.ts +7 -0
  10. package/dist/audio/index.d.ts.map +1 -0
  11. package/dist/audio/index.js +8 -0
  12. package/dist/audio/index.js.map +1 -0
  13. package/dist/audio/loudness.d.ts +13 -0
  14. package/dist/audio/loudness.d.ts.map +1 -0
  15. package/dist/audio/loudness.js +65 -0
  16. package/dist/audio/loudness.js.map +1 -0
  17. package/dist/audio/mulaw.d.ts +3 -0
  18. package/dist/audio/mulaw.d.ts.map +1 -0
  19. package/dist/audio/mulaw.js +39 -0
  20. package/dist/audio/mulaw.js.map +1 -0
  21. package/dist/audio/pcm.d.ts +5 -0
  22. package/dist/audio/pcm.d.ts.map +1 -0
  23. package/dist/audio/pcm.js +40 -0
  24. package/dist/audio/pcm.js.map +1 -0
  25. package/dist/audio/resample.d.ts +12 -0
  26. package/dist/audio/resample.d.ts.map +1 -0
  27. package/dist/audio/resample.js +157 -0
  28. package/dist/audio/resample.js.map +1 -0
  29. package/dist/audio-envelope.d.ts +23 -0
  30. package/dist/audio-envelope.d.ts.map +1 -0
  31. package/dist/audio-envelope.js +114 -0
  32. package/dist/audio-envelope.js.map +1 -0
  33. package/dist/confidence-to-wait.d.ts +12 -0
  34. package/dist/confidence-to-wait.d.ts.map +1 -0
  35. package/dist/confidence-to-wait.js +18 -0
  36. package/dist/confidence-to-wait.js.map +1 -0
  37. package/dist/conversation-event.d.ts +19 -0
  38. package/dist/conversation-event.d.ts.map +1 -0
  39. package/dist/conversation-event.js +44 -0
  40. package/dist/conversation-event.js.map +1 -0
  41. package/dist/error-handler.d.ts +35 -0
  42. package/dist/error-handler.d.ts.map +1 -0
  43. package/dist/error-handler.js +136 -0
  44. package/dist/error-handler.js.map +1 -0
  45. package/dist/idle-timeout.d.ts +69 -0
  46. package/dist/idle-timeout.d.ts.map +1 -0
  47. package/dist/idle-timeout.js +149 -0
  48. package/dist/idle-timeout.js.map +1 -0
  49. package/dist/incremental-unit.d.ts +17 -0
  50. package/dist/incremental-unit.d.ts.map +1 -0
  51. package/dist/incremental-unit.js +5 -0
  52. package/dist/incremental-unit.js.map +1 -0
  53. package/dist/index.d.ts +47 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +61 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/init-chain.d.ts +35 -0
  58. package/dist/init-chain.d.ts.map +1 -0
  59. package/dist/init-chain.js +102 -0
  60. package/dist/init-chain.js.map +1 -0
  61. package/dist/init-stage-order.d.ts +5 -0
  62. package/dist/init-stage-order.d.ts.map +1 -0
  63. package/dist/init-stage-order.js +74 -0
  64. package/dist/init-stage-order.js.map +1 -0
  65. package/dist/interaction-coordinator.d.ts +45 -0
  66. package/dist/interaction-coordinator.d.ts.map +1 -0
  67. package/dist/interaction-coordinator.js +197 -0
  68. package/dist/interaction-coordinator.js.map +1 -0
  69. package/dist/interaction-policy.d.ts +103 -0
  70. package/dist/interaction-policy.d.ts.map +1 -0
  71. package/dist/interaction-policy.js +6 -0
  72. package/dist/interaction-policy.js.map +1 -0
  73. package/dist/iu-ledger.d.ts +39 -0
  74. package/dist/iu-ledger.d.ts.map +1 -0
  75. package/dist/iu-ledger.js +90 -0
  76. package/dist/iu-ledger.js.map +1 -0
  77. package/dist/latency-filler-fixtures.d.ts +7 -0
  78. package/dist/latency-filler-fixtures.d.ts.map +1 -0
  79. package/dist/latency-filler-fixtures.js +10 -0
  80. package/dist/latency-filler-fixtures.js.map +1 -0
  81. package/dist/latency-filler.d.ts +29 -0
  82. package/dist/latency-filler.d.ts.map +1 -0
  83. package/dist/latency-filler.js +102 -0
  84. package/dist/latency-filler.js.map +1 -0
  85. package/dist/mode-switcher.d.ts +24 -0
  86. package/dist/mode-switcher.d.ts.map +1 -0
  87. package/dist/mode-switcher.js +83 -0
  88. package/dist/mode-switcher.js.map +1 -0
  89. package/dist/observability-observer.d.ts +36 -0
  90. package/dist/observability-observer.d.ts.map +1 -0
  91. package/dist/observability-observer.js +141 -0
  92. package/dist/observability-observer.js.map +1 -0
  93. package/dist/observability.d.ts +68 -0
  94. package/dist/observability.d.ts.map +1 -0
  95. package/dist/observability.js +70 -0
  96. package/dist/observability.js.map +1 -0
  97. package/dist/packet-factories.d.ts +58 -0
  98. package/dist/packet-factories.d.ts.map +1 -0
  99. package/dist/packet-factories.js +181 -0
  100. package/dist/packet-factories.js.map +1 -0
  101. package/dist/packets.d.ts +532 -0
  102. package/dist/packets.d.ts.map +1 -0
  103. package/dist/packets.js +51 -0
  104. package/dist/packets.js.map +1 -0
  105. package/dist/pipeline-bus.d.ts +92 -0
  106. package/dist/pipeline-bus.d.ts.map +1 -0
  107. package/dist/pipeline-bus.js +294 -0
  108. package/dist/pipeline-bus.js.map +1 -0
  109. package/dist/plugin-contract.d.ts +73 -0
  110. package/dist/plugin-contract.d.ts.map +1 -0
  111. package/dist/plugin-contract.js +30 -0
  112. package/dist/plugin-contract.js.map +1 -0
  113. package/dist/policies/defer.d.ts +11 -0
  114. package/dist/policies/defer.d.ts.map +1 -0
  115. package/dist/policies/defer.js +13 -0
  116. package/dist/policies/defer.js.map +1 -0
  117. package/dist/policies/rule-based.d.ts +35 -0
  118. package/dist/policies/rule-based.d.ts.map +1 -0
  119. package/dist/policies/rule-based.js +130 -0
  120. package/dist/policies/rule-based.js.map +1 -0
  121. package/dist/pricing.d.ts +34 -0
  122. package/dist/pricing.d.ts.map +1 -0
  123. package/dist/pricing.js +108 -0
  124. package/dist/pricing.js.map +1 -0
  125. package/dist/primary-speaker-fixtures.d.ts +12 -0
  126. package/dist/primary-speaker-fixtures.d.ts.map +1 -0
  127. package/dist/primary-speaker-fixtures.js +37 -0
  128. package/dist/primary-speaker-fixtures.js.map +1 -0
  129. package/dist/primary-speaker-gate.d.ts +42 -0
  130. package/dist/primary-speaker-gate.d.ts.map +1 -0
  131. package/dist/primary-speaker-gate.js +178 -0
  132. package/dist/primary-speaker-gate.js.map +1 -0
  133. package/dist/provider-fallback.d.ts +28 -0
  134. package/dist/provider-fallback.d.ts.map +1 -0
  135. package/dist/provider-fallback.js +72 -0
  136. package/dist/provider-fallback.js.map +1 -0
  137. package/dist/reasoner-hedge.d.ts +21 -0
  138. package/dist/reasoner-hedge.d.ts.map +1 -0
  139. package/dist/reasoner-hedge.js +170 -0
  140. package/dist/reasoner-hedge.js.map +1 -0
  141. package/dist/reasoner-route.d.ts +24 -0
  142. package/dist/reasoner-route.d.ts.map +1 -0
  143. package/dist/reasoner-route.js +87 -0
  144. package/dist/reasoner-route.js.map +1 -0
  145. package/dist/reasoner-session-store.d.ts +18 -0
  146. package/dist/reasoner-session-store.d.ts.map +1 -0
  147. package/dist/reasoner-session-store.js +21 -0
  148. package/dist/reasoner-session-store.js.map +1 -0
  149. package/dist/reasoner.d.ts +97 -0
  150. package/dist/reasoner.d.ts.map +1 -0
  151. package/dist/reasoner.js +9 -0
  152. package/dist/reasoner.js.map +1 -0
  153. package/dist/retry.d.ts +31 -0
  154. package/dist/retry.d.ts.map +1 -0
  155. package/dist/retry.js +83 -0
  156. package/dist/retry.js.map +1 -0
  157. package/dist/scheduler.d.ts +11 -0
  158. package/dist/scheduler.d.ts.map +1 -0
  159. package/dist/scheduler.js +20 -0
  160. package/dist/scheduler.js.map +1 -0
  161. package/dist/spend-cap.d.ts +27 -0
  162. package/dist/spend-cap.d.ts.map +1 -0
  163. package/dist/spend-cap.js +38 -0
  164. package/dist/spend-cap.js.map +1 -0
  165. package/dist/tts-playout-clock.d.ts +43 -0
  166. package/dist/tts-playout-clock.d.ts.map +1 -0
  167. package/dist/tts-playout-clock.js +125 -0
  168. package/dist/tts-playout-clock.js.map +1 -0
  169. package/dist/turn-arbiter.d.ts +41 -0
  170. package/dist/turn-arbiter.d.ts.map +1 -0
  171. package/dist/turn-arbiter.js +259 -0
  172. package/dist/turn-arbiter.js.map +1 -0
  173. package/dist/voice-agent-session-util.d.ts +60 -0
  174. package/dist/voice-agent-session-util.d.ts.map +1 -0
  175. package/dist/voice-agent-session-util.js +204 -0
  176. package/dist/voice-agent-session-util.js.map +1 -0
  177. package/dist/voice-agent-session.d.ts +435 -0
  178. package/dist/voice-agent-session.d.ts.map +1 -0
  179. package/dist/voice-agent-session.js +1597 -0
  180. package/dist/voice-agent-session.js.map +1 -0
  181. package/dist/voice-text.d.ts +46 -0
  182. package/dist/voice-text.d.ts.map +1 -0
  183. package/dist/voice-text.js +209 -0
  184. package/dist/voice-text.js.map +1 -0
  185. package/package.json +19 -6
  186. package/src/audio/alaw.test.ts +87 -0
  187. package/src/audio/audio.test.ts +285 -0
  188. package/src/audio/g722.test.ts +149 -0
  189. package/src/audio/loudness.test.ts +58 -0
  190. package/src/audio-envelope.test.ts +167 -0
  191. package/src/confidence-to-wait.test.ts +21 -0
  192. package/src/error-handler.test.ts +56 -0
  193. package/src/hedge-throwing-backend.test.ts +46 -0
  194. package/src/interaction-coordinator.test.ts +529 -0
  195. package/src/iu-ledger.test.ts +276 -0
  196. package/src/latency-filler.test.ts +62 -0
  197. package/src/observability-observer.test.ts +248 -0
  198. package/src/observability.test.ts +94 -0
  199. package/src/packet-factories.test.ts +126 -0
  200. package/src/pipeline-bus.g10.test.ts +145 -0
  201. package/src/pipeline-bus.test.ts +211 -0
  202. package/src/policies/defer.test.ts +86 -0
  203. package/src/policies/rule-based.test.ts +334 -0
  204. package/src/pricing.test.ts +226 -0
  205. package/src/primary-speaker-gate.test.ts +150 -0
  206. package/src/provider-fallback.test.ts +87 -0
  207. package/src/reasoner-hedge.test.ts +361 -0
  208. package/src/reasoner-route.test.ts +248 -0
  209. package/src/reasoner.test.ts +69 -0
  210. package/src/retry.test.ts +83 -0
  211. package/src/route-throwing-spec.test.ts +44 -0
  212. package/src/spend-cap.test.ts +114 -0
  213. package/src/tts-playout-clock.test.ts +125 -0
  214. package/src/turn-arbiter.characterization.test.ts +477 -0
  215. package/src/turn-arbiter.test.ts +762 -0
  216. package/src/voice-agent-session.test.ts +4165 -0
  217. package/src/voice-text.test.ts +156 -0
@@ -0,0 +1,136 @@
1
+ // SPDX-License-Identifier: MIT
2
+ //
3
+ // Syrinx Kernel v2 — Error Handler
4
+ //
5
+ // Categorizes errors from external service providers and determines
6
+ // whether they are recoverable (retry with backoff) or fatal (terminate session).
7
+ //
8
+ // Each component (STT, TTS, LLM) has its own categorization logic.
9
+ // The session manager uses these to decide retry vs. terminate.
10
+ import { ErrorCategory } from "./packets.js";
11
+ // =============================================================================
12
+ // Error Categorization
13
+ // =============================================================================
14
+ /**
15
+ * Categorize an error from the STT provider.
16
+ *
17
+ * Heuristic:
18
+ * - HTTP 429 → RateLimit (recoverable)
19
+ * - Network errors (ECONNRESET, ETIMEDOUT, ENOTFOUND) → NetworkTimeout (recoverable)
20
+ * - HTTP 401/403 → Authentication (fatal)
21
+ * - HTTP 400/422 → InvalidInput (fatal)
22
+ * - HTTP 402 → ResourceExhausted (fatal)
23
+ * - Everything else → InternalFault (fatal)
24
+ */
25
+ export function categorizeSttError(err) {
26
+ const msg = extractMessage(err).toLowerCase();
27
+ const code = extractHttpStatus(err);
28
+ if (code === 429 ||
29
+ msg.includes("rate limit") ||
30
+ msg.includes("rate_limit") ||
31
+ msg.includes("too many requests") ||
32
+ // Provider concurrency limits (e.g. Cartesia) — recoverable, retry with backoff.
33
+ msg.includes("concurrency limit") ||
34
+ msg.includes("concurrency_limit") ||
35
+ msg.includes("concurrent limit") ||
36
+ msg.includes("too many concurrent") ||
37
+ msg.includes("max concurrency") ||
38
+ (msg.includes("concurren") && (msg.includes("exceed") || msg.includes("limit")))) {
39
+ return ErrorCategory.RateLimit;
40
+ }
41
+ if (code === 401 || code === 403 || msg.includes("unauthorized") || msg.includes("forbidden")) {
42
+ return ErrorCategory.Authentication;
43
+ }
44
+ if (code === 400 || code === 422 || msg.includes("invalid") || msg.includes("bad request")) {
45
+ return ErrorCategory.InvalidInput;
46
+ }
47
+ if (msg.includes("data-000")) {
48
+ return ErrorCategory.InvalidInput;
49
+ }
50
+ if (code === 402 || msg.includes("payment required") || msg.includes("insufficient")) {
51
+ return ErrorCategory.ResourceExhausted;
52
+ }
53
+ if (msg.includes("econnreset") ||
54
+ msg.includes("etimedout") ||
55
+ msg.includes("enotfound") ||
56
+ msg.includes("network") ||
57
+ msg.includes("net-000") ||
58
+ msg.includes("timeout") ||
59
+ msg.includes("timed out") ||
60
+ msg.includes("econnrefused") ||
61
+ msg.includes("socket hang up") ||
62
+ msg.includes("code=1011") ||
63
+ msg.includes("internal error has occurred") ||
64
+ (code !== null && code >= 500 && code <= 599)) {
65
+ return ErrorCategory.NetworkTimeout;
66
+ }
67
+ return ErrorCategory.InternalFault;
68
+ }
69
+ /**
70
+ * Categorize an error from the TTS provider.
71
+ * Same heuristic as STT — TTS providers have similar error patterns.
72
+ */
73
+ export function categorizeTtsError(err) {
74
+ return categorizeSttError(err); // Same logic applies
75
+ }
76
+ /**
77
+ * Categorize an error from the LLM provider.
78
+ *
79
+ * Additional LLM-specific heuristics:
80
+ * - "context length exceeded" → InvalidInput (fatal)
81
+ * - "content filter" / "safety" → InvalidInput (fatal)
82
+ */
83
+ export function categorizeLlmError(err) {
84
+ const msg = extractMessage(err).toLowerCase();
85
+ if (msg.includes("context length") || msg.includes("token limit") || msg.includes("too many tokens")) {
86
+ return ErrorCategory.InvalidInput;
87
+ }
88
+ if (msg.includes("content filter") || msg.includes("safety") || msg.includes("blocked")) {
89
+ return ErrorCategory.InvalidInput;
90
+ }
91
+ if (msg.includes("malformed_function_call")) {
92
+ return ErrorCategory.NetworkTimeout;
93
+ }
94
+ return categorizeSttError(err); // Base logic for HTTP errors
95
+ }
96
+ // =============================================================================
97
+ // Recoverability
98
+ // =============================================================================
99
+ /**
100
+ * Returns true if the error category is recoverable (retry with backoff).
101
+ */
102
+ export function isRecoverable(category) {
103
+ return category === ErrorCategory.RateLimit || category === ErrorCategory.NetworkTimeout;
104
+ }
105
+ /**
106
+ * Returns true if the error packet represents a fatal error.
107
+ */
108
+ export function isFatalError(pkt) {
109
+ return !pkt.isRecoverable;
110
+ }
111
+ // =============================================================================
112
+ // Helpers
113
+ // =============================================================================
114
+ function extractMessage(err) {
115
+ if (err instanceof Error)
116
+ return err.message;
117
+ if (typeof err === "string")
118
+ return err;
119
+ if (err && typeof err === "object" && "message" in err) {
120
+ return String(err.message);
121
+ }
122
+ return String(err);
123
+ }
124
+ function extractHttpStatus(err) {
125
+ if (err && typeof err === "object") {
126
+ const e = err;
127
+ if (typeof e.status === "number")
128
+ return e.status;
129
+ if (typeof e.statusCode === "number")
130
+ return e.statusCode;
131
+ if (typeof e.code === "number")
132
+ return e.code;
133
+ }
134
+ return null;
135
+ }
136
+ //# sourceMappingURL=error-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../src/error-handler.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,EAAE;AACF,mCAAmC;AACnC,EAAE;AACF,oEAAoE;AACpE,kFAAkF;AAClF,EAAE;AACF,mEAAmE;AACnE,gEAAgE;AAEhE,OAAO,EAAE,aAAa,EAAyB,MAAM,cAAc,CAAC;AAEpE,gFAAgF;AAChF,uBAAuB;AACvB,gFAAgF;AAEhF;;;;;;;;;;GAUG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAY;IAC7C,MAAM,GAAG,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;IAC9C,MAAM,IAAI,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC;IAEpC,IACE,IAAI,KAAK,GAAG;QACZ,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,MAAM,CAAC;QAClD,IAAI,OAAO,CAAC,CAAC,UAAU,KAAK,QAAQ;YAAE,OAAO,CAAC,CAAC,UAAU,CAAC;QAC1D,IAAI,OAAO,CAAC,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,CAAC,CAAC,IAAI,CAAC;IAChD,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,69 @@
1
+ import type { PipelineBus } from "./pipeline-bus.js";
2
+ import type { StartIdleTimeoutPacket, StopIdleTimeoutPacket } from "./packets.js";
3
+ import { type Scheduler } from "./scheduler.js";
4
+ export interface IdleTimeoutConfig {
5
+ /** Base duration before triggering idle behavior (ms). Default: 15000 */
6
+ durationMs: number;
7
+ /**
8
+ * Number of consecutive timeouts before disconnecting.
9
+ * 0 = never disconnect (just inject messages repeatedly).
10
+ * Default: 3
11
+ */
12
+ maxConsecutive: number;
13
+ /**
14
+ * Messages to inject at each consecutive idle.
15
+ * Index 0 = first timeout, index 1 = second timeout, etc.
16
+ * If more timeouts occur than messages, the last message repeats.
17
+ * Default: ["Are you still there?", "I'll end this call soon."]
18
+ */
19
+ escalationMessages: string[];
20
+ /**
21
+ * Whether to disconnect the session after maxConsecutive is reached.
22
+ * If false, the maxConsecutive counter stops incrementing and the
23
+ * last escalation message repeats indefinitely.
24
+ * Default: true
25
+ */
26
+ disconnectAfterMax: boolean;
27
+ }
28
+ export declare const DEFAULT_IDLE_TIMEOUT_CONFIG: IdleTimeoutConfig;
29
+ export declare class IdleTimeoutManager {
30
+ private timerScheduled;
31
+ private count;
32
+ private readonly config;
33
+ private readonly bus;
34
+ private currentContextId;
35
+ private readonly scheduler;
36
+ constructor(bus: PipelineBus, config?: Partial<IdleTimeoutConfig>, scheduler?: Scheduler);
37
+ /** Set the current turn context ID (used for injected message context). */
38
+ setContextId(id: string): void;
39
+ /** Start (or restart) the idle timeout timer. */
40
+ start(): void;
41
+ /**
42
+ * Stop the idle timeout timer.
43
+ * @param resetCount — If true, resets the consecutive idle counter.
44
+ * Use true when the user actively engages (speaks or types).
45
+ * Use false for system-driven stops (e.g., TTS still playing).
46
+ */
47
+ stop(resetCount: boolean): void;
48
+ /**
49
+ * Extend the current timer by a duration (e.g., TTS audio playback time).
50
+ * Stops the current timer and restarts with the remaining time + extension.
51
+ */
52
+ extend(ms: number): void;
53
+ /** Clean up — stop timer without side effects. */
54
+ dispose(): void;
55
+ private clearTimer;
56
+ /**
57
+ * Resolve a non-empty context id for injected idle turns. If no turn context has been seen yet
58
+ * (e.g. the idle timer fired before the first user turn completed), synthesize a stable one —
59
+ * an empty contextId propagates downstream and is rejected by providers that validate it
60
+ * (e.g. Cartesia TTS: "context_id must be alphanumeric/_/-").
61
+ */
62
+ private ensureContextId;
63
+ private onTimeout;
64
+ /** Handle a StartIdleTimeoutPacket from the bus. */
65
+ handleStart(pkt: StartIdleTimeoutPacket): void;
66
+ /** Handle a StopIdleTimeoutPacket from the bus. */
67
+ handleStop(pkt: StopIdleTimeoutPacket): void;
68
+ }
69
+ //# sourceMappingURL=idle-timeout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idle-timeout.d.ts","sourceRoot":"","sources":["../src/idle-timeout.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EAGtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAMhE,MAAM,WAAW,iBAAiB;IAChC,yEAAyE;IACzE,UAAU,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;;;;OAKG;IACH,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B;;;;;OAKG;IACH,kBAAkB,EAAE,OAAO,CAAC;CAC7B;AAED,eAAO,MAAM,2BAA2B,EAAE,iBAKzC,CAAC;AAMF,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;IAC3C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAc;IAClC,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAY;gBAGpC,GAAG,EAAE,WAAW,EAChB,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,EACnC,SAAS,CAAC,EAAE,SAAS;IAYvB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAI9B,iDAAiD;IACjD,KAAK,IAAI,IAAI;IAWb;;;;;OAKG;IACH,IAAI,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI;IAO/B;;;OAGG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAUxB,kDAAkD;IAClD,OAAO,IAAI,IAAI;IAQf,OAAO,CAAC,UAAU;IAMlB;;;;;OAKG;IACH,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,SAAS;IA4CjB,oDAAoD;IACpD,WAAW,CAAC,GAAG,EAAE,sBAAsB,GAAG,IAAI;IAK9C,mDAAmD;IACnD,UAAU,CAAC,GAAG,EAAE,qBAAqB,GAAG,IAAI;CAG7C"}
@@ -0,0 +1,149 @@
1
+ // SPDX-License-Identifier: MIT
2
+ //
3
+ // Syrinx Kernel v2 — Idle Timeout Manager
4
+ //
5
+ // Tracks user silence and escalates: inject message → inject warning → disconnect.
6
+ // Configurable duration, escalation messages, and consecutive backoff.
7
+ //
8
+ // Design decision (per RFC Q4 resolution): idle messages are injected as
9
+ // synthetic LlmDeltaPacket + LlmDonePacket through the normal TTS path.
10
+ // This keeps voice style, logging, interruption, and abort semantics consistent.
11
+ import { Route } from "./pipeline-bus.js";
12
+ import { TimerScheduler } from "./scheduler.js";
13
+ export const DEFAULT_IDLE_TIMEOUT_CONFIG = {
14
+ durationMs: 15_000,
15
+ maxConsecutive: 3,
16
+ escalationMessages: ["Are you still there?", "I'll end this call soon."],
17
+ disconnectAfterMax: true,
18
+ };
19
+ // =============================================================================
20
+ // Manager
21
+ // =============================================================================
22
+ export class IdleTimeoutManager {
23
+ timerScheduled = false;
24
+ count = 0;
25
+ config;
26
+ bus;
27
+ currentContextId;
28
+ scheduler;
29
+ constructor(bus, config, scheduler) {
30
+ this.bus = bus;
31
+ this.config = { ...DEFAULT_IDLE_TIMEOUT_CONFIG, ...config };
32
+ this.currentContextId = "";
33
+ this.scheduler = scheduler ?? new TimerScheduler();
34
+ }
35
+ // -------------------------------------------------------------------------
36
+ // Public API
37
+ // -------------------------------------------------------------------------
38
+ /** Set the current turn context ID (used for injected message context). */
39
+ setContextId(id) {
40
+ this.currentContextId = id;
41
+ }
42
+ /** Start (or restart) the idle timeout timer. */
43
+ start() {
44
+ this.clearTimer();
45
+ if (this.config.durationMs <= 0)
46
+ return;
47
+ this.timerScheduled = true;
48
+ this.scheduler.schedule("voice.idle_timeout", this.config.durationMs, () => {
49
+ this.timerScheduled = false;
50
+ this.onTimeout();
51
+ });
52
+ }
53
+ /**
54
+ * Stop the idle timeout timer.
55
+ * @param resetCount — If true, resets the consecutive idle counter.
56
+ * Use true when the user actively engages (speaks or types).
57
+ * Use false for system-driven stops (e.g., TTS still playing).
58
+ */
59
+ stop(resetCount) {
60
+ this.clearTimer();
61
+ if (resetCount) {
62
+ this.count = 0;
63
+ }
64
+ }
65
+ /**
66
+ * Extend the current timer by a duration (e.g., TTS audio playback time).
67
+ * Stops the current timer and restarts with the remaining time + extension.
68
+ */
69
+ extend(ms) {
70
+ this.clearTimer();
71
+ if (this.config.durationMs <= 0)
72
+ return;
73
+ this.timerScheduled = true;
74
+ this.scheduler.schedule("voice.idle_timeout", this.config.durationMs + ms, () => {
75
+ this.timerScheduled = false;
76
+ this.onTimeout();
77
+ });
78
+ }
79
+ /** Clean up — stop timer without side effects. */
80
+ dispose() {
81
+ this.clearTimer();
82
+ }
83
+ // -------------------------------------------------------------------------
84
+ // Private
85
+ // -------------------------------------------------------------------------
86
+ clearTimer() {
87
+ if (!this.timerScheduled)
88
+ return;
89
+ this.scheduler.cancel("voice.idle_timeout");
90
+ this.timerScheduled = false;
91
+ }
92
+ /**
93
+ * Resolve a non-empty context id for injected idle turns. If no turn context has been seen yet
94
+ * (e.g. the idle timer fired before the first user turn completed), synthesize a stable one —
95
+ * an empty contextId propagates downstream and is rejected by providers that validate it
96
+ * (e.g. Cartesia TTS: "context_id must be alphanumeric/_/-").
97
+ */
98
+ ensureContextId() {
99
+ if (this.currentContextId === "") {
100
+ this.currentContextId = `idle-${String(Date.now())}`;
101
+ }
102
+ return this.currentContextId;
103
+ }
104
+ onTimeout() {
105
+ this.count++;
106
+ const contextId = this.ensureContextId();
107
+ // Check if we should disconnect
108
+ if (this.config.maxConsecutive > 0 &&
109
+ this.count >= this.config.maxConsecutive &&
110
+ this.config.disconnectAfterMax) {
111
+ const disconnect = {
112
+ kind: "session.disconnect",
113
+ contextId,
114
+ timestampMs: Date.now(),
115
+ reason: `idle_timeout: ${this.count} consecutive`,
116
+ };
117
+ this.bus.push(Route.Critical, disconnect);
118
+ return;
119
+ }
120
+ // Inject escalation message
121
+ const msgIdx = Math.min(this.count - 1, this.config.escalationMessages.length - 1);
122
+ const message = this.config.escalationMessages[msgIdx];
123
+ if (message) {
124
+ const inject = {
125
+ kind: "inject.message",
126
+ contextId,
127
+ timestampMs: Date.now(),
128
+ text: message,
129
+ };
130
+ this.bus.push(Route.Main, inject);
131
+ }
132
+ // Restart timer for next escalation
133
+ this.start();
134
+ }
135
+ // -------------------------------------------------------------------------
136
+ // Bus packet handlers (for integration with VoiceAgentSession)
137
+ // -------------------------------------------------------------------------
138
+ /** Handle a StartIdleTimeoutPacket from the bus. */
139
+ handleStart(pkt) {
140
+ if (pkt.contextId)
141
+ this.setContextId(pkt.contextId);
142
+ this.start();
143
+ }
144
+ /** Handle a StopIdleTimeoutPacket from the bus. */
145
+ handleStop(pkt) {
146
+ this.stop(pkt.resetCount);
147
+ }
148
+ }
149
+ //# sourceMappingURL=idle-timeout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"idle-timeout.js","sourceRoot":"","sources":["../src/idle-timeout.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,EAAE;AACF,0CAA0C;AAC1C,EAAE;AACF,mFAAmF;AACnF,uEAAuE;AACvE,EAAE;AACF,yEAAyE;AACzE,wEAAwE;AACxE,iFAAiF;AAGjF,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAO1C,OAAO,EAAE,cAAc,EAAkB,MAAM,gBAAgB,CAAC;AA+BhE,MAAM,CAAC,MAAM,2BAA2B,GAAsB;IAC5D,UAAU,EAAE,MAAM;IAClB,cAAc,EAAE,CAAC;IACjB,kBAAkB,EAAE,CAAC,sBAAsB,EAAE,0BAA0B,CAAC;IACxE,kBAAkB,EAAE,IAAI;CACzB,CAAC;AAEF,gFAAgF;AAChF,UAAU;AACV,gFAAgF;AAEhF,MAAM,OAAO,kBAAkB;IACrB,cAAc,GAAG,KAAK,CAAC;IACvB,KAAK,GAAG,CAAC,CAAC;IACD,MAAM,CAAoB;IAC1B,GAAG,CAAc;IAC1B,gBAAgB,CAAS;IAChB,SAAS,CAAY;IAEtC,YACE,GAAgB,EAChB,MAAmC,EACnC,SAAqB;QAErB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,2BAA2B,EAAE,GAAG,MAAM,EAAE,CAAC;QAC5D,IAAI,CAAC,gBAAgB,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,IAAI,cAAc,EAAE,CAAC;IACrD,CAAC;IAED,4EAA4E;IAC5E,aAAa;IACb,4EAA4E;IAE5E,2EAA2E;IAC3E,YAAY,CAAC,EAAU;QACrB,IAAI,CAAC,gBAAgB,GAAG,EAAE,C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,EAAE;gBACvB,IAAI,EAAE,OAAO;aACd,CAAC;YACF,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACpC,CAAC;QAED,oCAAoC;QACpC,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAED,4EAA4E;IAC5E,+DAA+D;IAC/D,4EAA4E;IAE5E,oDAAoD;IACpD,WAAW,CAAC,GAA2B;QACrC,IAAI,GAAG,CAAC,SAAS;YAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACpD,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAED,mDAAmD;IACnD,UAAU,CAAC,GAA0B;QACnC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAC5B,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ export type IuState = "hypothesized" | "committed" | "revoked";
2
+ export interface IncrementalUnitId {
3
+ readonly contextId: string;
4
+ readonly iuId: string;
5
+ readonly epoch: number;
6
+ }
7
+ export interface IncrementalUnit {
8
+ readonly id: IncrementalUnitId;
9
+ readonly kind: "user_turn" | "assistant_response" | "tts_segment";
10
+ state: IuState;
11
+ /** For assistant/tts IUs: the committed character/ms prefix (heard). */
12
+ committedPrefix?: {
13
+ chars?: number;
14
+ ms?: number;
15
+ };
16
+ }
17
+ //# sourceMappingURL=incremental-unit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"incremental-unit.d.ts","sourceRoot":"","sources":["../src/incremental-unit.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,OAAO,GAAG,cAAc,GAAG,WAAW,GAAG,SAAS,CAAC;AAE/D,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,EAAE,iBAAiB,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,oBAAoB,GAAG,aAAa,CAAC;IAClE,KAAK,EAAE,OAAO,CAAC;IACf,wEAAwE;IACxE,eAAe,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACnD"}
@@ -0,0 +1,5 @@
1
+ // SPDX-License-Identifier: MIT
2
+ //
3
+ // Syrinx Kernel v2 — Incremental-Unit identity + state (IU substrate, RFC incremental-unit-substrate)
4
+ export {};
5
+ //# sourceMappingURL=incremental-unit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"incremental-unit.js","sourceRoot":"","sources":["../src/incremental-unit.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,EAAE;AACF,sGAAsG"}
@@ -0,0 +1,47 @@
1
+ export { type AudioFormat, type VoicePacket, type AsyncPacket, type VoiceErrorPacket, ErrorCategory, SessionState, InitStage, type InitStepCompletedPacket, type InitializationFailedPacket, type InitializationCompletedPacket, } from "./packets.js";
2
+ export { type UserAudioReceivedPacket, type UserTextReceivedPacket, type DenoiseAudioPacket, type DenoisedAudioPacket, type VadAudioPacket, type VadSpeechStartedPacket, type VadSpeechEndedPacket, type VadSpeechActivityPacket, type SpeechToTextAudioPacket, type SttInterimPacket, type SttPartialPacket, type SttResultPacket, type FinalizeSttPacket, type SttReconfigurePacket, type SttErrorPacket, type EndOfSpeechAudioPacket, type EndOfSpeechPacket, type InterimEndOfSpeechPacket, type EndOfSpeechRetractedPacket, type TurnEndOwner, type TurnEndReason, type UserInputPacket, } from "./packets.js";
3
+ export { type InterruptionDetectedPacket, type InterruptTtsPacket, type InterruptLlmPacket, type InterruptSttPacket, type TurnChangePacket, } from "./packets.js";
4
+ export { type DtmfDigit, type DtmfReceivedPacket, type DtmfSendPacket, type CallTransferMode, type CallTransferPacket, } from "./packets.js";
5
+ export { parseDtmfDigit, dtmfReceived, dtmfSend, callTransfer } from "./packet-factories.js";
6
+ export { type LlmDeltaPacket, type LlmResponseDonePacket, type LlmErrorPacket, type LlmToolCallPacket, type LlmToolResultPacket, } from "./packets.js";
7
+ export { type ReasoningSuspendedPacket, type ReasoningResumePacket, } from "./packets.js";
8
+ export { type DelegateQueryPacket, type DelegateResultPacket, type DelegatePacket, type RealtimeResumptionHandlePacket, } from "./packets.js";
9
+ export { InMemoryReasonerSessionStore, type ReasonerSessionStore, } from "./reasoner-session-store.js";
10
+ export { type IuState, type IncrementalUnitId, type IncrementalUnit, } from "./incremental-unit.js";
11
+ export { type IuLedger, type IuLedgerAnomaly, InMemoryIuLedger, } from "./iu-ledger.js";
12
+ export { type TextToSpeechTextPacket, type TextToSpeechDonePacket, type TextToSpeechAudioPacket, type TextToSpeechEndPacket, type TextToSpeechPlayoutStartedPacket, type TextToSpeechPlayoutProgressPacket, type TextToSpeechWordTimestampsPacket, type TtsWordTimestamp, type TtsErrorPacket, } from "./packets.js";
13
+ export { type RecordAssistantAudioDataPacket, type RecordAssistantAudioPacket, type RecordAssistantAudioTruncatePacket, type RecordUserAudioPacket, type StartIdleTimeoutPacket, type StopIdleTimeoutPacket, type InjectMessagePacket, type DisconnectRequestedPacket, } from "./packets.js";
14
+ export { type ModeSwitchRequestedPacket, type ModeSwitchCompletedPacket, } from "./packets.js";
15
+ export { type MessageCreatePacket, type ConversationMetricPacket, type AcousticSignalPacket, type AcousticSignal, type TurnLocalizationPacket, type UsageStage, type UsageRecordedPacket, type TurnBoundaryKind, type TurnBoundaryEventPacket, type ObservabilityPacket, type PipelineErrorPacket, } from "./packets.js";
16
+ export { type SttPrice, type LlmPrice, type TtsPrice, type PriceCatalog, type CostResult, DEFAULT_PRICE_CATALOG, costOf, } from "./pricing.js";
17
+ export { SpendCapGuard, type SpendCapConfig, type SpendCapCheck, } from "./spend-cap.js";
18
+ export { monotonicNowMs, type MetricTags, type ObservabilityLayer, type TurnLocalizationVerdict, type TurnLocalizationSignals, localizeTurn, type SpanHandle, type MetricsExporter, noopMetricsExporter, InMemoryMetricsExporter, reconstructTurnTimeline, type TurnTimelineStep, } from "./observability.js";
19
+ export { ObservabilityObserver, type ObservabilityObserverDeps, type ObservabilityDims, } from "./observability-observer.js";
20
+ export { PipelineBusImpl, Route, type PipelineBus, type PipelineBusConfig, type PacketHandler } from "./pipeline-bus.js";
21
+ export { runInitChain, runFinalizeChain, type InitStep, InitializationError } from "./init-chain.js";
22
+ export { type VoicePlugin, type PluginConfig, type EndpointingOwner, type EndpointingCapability, type SttReconfigure, type SttReconfigurePartial, requireStringConfig, optionalStringConfig, } from "./plugin-contract.js";
23
+ export { categorizeSttError, categorizeTtsError, categorizeLlmError, isRecoverable, isFatalError } from "./error-handler.js";
24
+ export { DEFAULT_RETRY_CONFIG, VOICE_PROVIDER_RETRY_CONFIG, VOICE_PROVIDER_OUTAGE_RETRY_CONFIG, readRetryConfig, readProviderRetryConfig, retryDelayMs, waitForRetryDelay, type RetryConfig } from "./retry.js";
25
+ export { ProviderFallback, type FallbackProvider, type ProviderFallbackOptions } from "./provider-fallback.js";
26
+ export { TimerScheduler, type Scheduler, type ScheduledCallback } from "./scheduler.js";
27
+ export { IdleTimeoutManager, type IdleTimeoutConfig, DEFAULT_IDLE_TIMEOUT_CONFIG } from "./idle-timeout.js";
28
+ export { ModeSwitcher, type ModeSwitchHandlers } from "./mode-switcher.js";
29
+ export { type ConversationEvent, createConversationEventStream } from "./conversation-event.js";
30
+ export { SYRINX_AUDIO_ENVELOPE_NAME, SYRINX_AUDIO_ENVELOPE_MAGIC, assertAudioFormat, assertAudioPayload, encodeSyrinxAudioEnvelope, decodeSyrinxAudioEnvelope, hasSyrinxAudioEnvelope, type SyrinxAudioEnvelope, type SyrinxAudioEnvelopeHeader, } from "./audio-envelope.js";
31
+ export { StreamingPcm16Resampler, createLoudnessState, normalizeLoudness, type LoudnessConfig, type LoudnessState, } from "./audio/index.js";
32
+ export { type InteractionPolicy, type LifecycleInteractionPolicy, isLifecycleInteractionPolicy, type InteractionObservation, type InteractionDecision, type AcousticSignalObservation, type AcousticSignalSink, type WordTiming, } from "./interaction-policy.js";
33
+ export { confidenceToWaitMs, type ConfidenceToWaitConfig } from "./confidence-to-wait.js";
34
+ export { RuleBasedInteractionPolicy } from "./policies/rule-based.js";
35
+ export { DeferInteractionPolicy } from "./policies/defer.js";
36
+ export { InteractionCoordinator, type InteractionCaps } from "./interaction-coordinator.js";
37
+ export { type InteractionBackchannelPacket, type InteractionDuckPacket, type InteractionResumePacket, } from "./packets.js";
38
+ export { VoiceAgentSession, type VoiceAgentSessionConfig, type VoiceAgentSessionEvents, type SessionStageUsage, } from "./voice-agent-session.js";
39
+ export { PrimarySpeakerGate, extractSpeakerFingerprint, fingerprintSimilarity, type SpeakerFingerprint, type PrimarySpeakerGateDecision, type PrimarySpeakerGateConfig, } from "./primary-speaker-gate.js";
40
+ export { synthesizeTonePcm16, mixPcm16, PRIMARY_SPEAKER_TONE_HZ, BYSTANDER_SPEAKER_TONE_HZ, ASSISTANT_ECHO_TONE_HZ, } from "./primary-speaker-fixtures.js";
41
+ export { LatencyFillerController, selectLatencyFillerConnective, stripRedundantFillerPrefix, LATENCY_FILLER_CONNECTIVES, type LatencyFillerConfig, type LatencyFillerState, type LatencyFillerConnective, } from "./latency-filler.js";
42
+ export { LATENCY_FILLER_FIXTURES, type LatencyFillerFixture, } from "./latency-filler-fixtures.js";
43
+ export { normalizeForSpeech, stripLeakedToolCalls } from "./voice-text.js";
44
+ export { type Reasoner, type ReasonerTurn, type ReasonerMessage, type ReasonerUsage, type ReasoningPart, } from "./reasoner.js";
45
+ export { HedgedReasoner, type HedgedReasonerOptions } from "./reasoner-hedge.js";
46
+ export { RoutingReasoner, type RoutingReasonerOptions, type ReasonerRoute, } from "./reasoner-route.js";
47
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.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B,GAC7B,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,iBAAiB,EACjB,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,iBAAiB,GACvB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,qBAAqB,EACrB,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,GAC9B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,mBAAmB,EACnB,QAAQ,EACR,uBAAuB,EACvB,yBAAyB,EACzB,sBAAsB,GACvB,MAAM,+BAA+B,CAAC;AAGvC,OAAO,EACL,uBAAuB,EACvB,6BAA6B,EAC7B,0BAA0B,EAC1B,0BAA0B,EAC1B,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,GAC7B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,uBAAuB,EACvB,KAAK,oBAAoB,GAC1B,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAG3E,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,aAAa,GACnB,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAGjF,OAAO,EACL,eAAe,EACf,KAAK,sBAAsB,EAC3B,KAAK,aAAa,GACnB,MAAM,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,61 @@
1
+ // SPDX-License-Identifier: MIT
2
+ //
3
+ // Syrinx Kernel v2 — Public API
4
+ //
5
+ // Everything a consumer needs to build voice agents with the new kernel.
6
+ // Core types
7
+ export { ErrorCategory, SessionState, InitStage, } from "./packets.js";
8
+ export { parseDtmfDigit, dtmfReceived, dtmfSend, callTransfer } from "./packet-factories.js";
9
+ // Durable reasoner session state (G4)
10
+ export { InMemoryReasonerSessionStore, } from "./reasoner-session-store.js";
11
+ export { InMemoryIuLedger, } from "./iu-ledger.js";
12
+ // Metering: price catalog + spend-cap guard (standalone; session wires later)
13
+ export { DEFAULT_PRICE_CATALOG, costOf, } from "./pricing.js";
14
+ export { SpendCapGuard, } from "./spend-cap.js";
15
+ // Observability backbone (VE-07)
16
+ export { monotonicNowMs, localizeTurn, noopMetricsExporter, InMemoryMetricsExporter, reconstructTurnTimeline, } from "./observability.js";
17
+ export { ObservabilityObserver, } from "./observability-observer.js";
18
+ // PipelineBus
19
+ export { PipelineBusImpl, Route } from "./pipeline-bus.js";
20
+ // Init chain
21
+ export { runInitChain, runFinalizeChain, InitializationError } from "./init-chain.js";
22
+ // Plugin contract
23
+ export { requireStringConfig, optionalStringConfig, } from "./plugin-contract.js";
24
+ // Error handler
25
+ export { categorizeSttError, categorizeTtsError, categorizeLlmError, isRecoverable, isFatalError } from "./error-handler.js";
26
+ // Retry helpers
27
+ export { DEFAULT_RETRY_CONFIG, VOICE_PROVIDER_RETRY_CONFIG, VOICE_PROVIDER_OUTAGE_RETRY_CONFIG, readRetryConfig, readProviderRetryConfig, retryDelayMs, waitForRetryDelay } from "./retry.js";
28
+ // Provider fallback/degradation
29
+ export { ProviderFallback } from "./provider-fallback.js";
30
+ // Runtime scheduler seam
31
+ export { TimerScheduler } from "./scheduler.js";
32
+ // Idle timeout
33
+ export { IdleTimeoutManager, DEFAULT_IDLE_TIMEOUT_CONFIG } from "./idle-timeout.js";
34
+ // Mode switcher
35
+ export { ModeSwitcher } from "./mode-switcher.js";
36
+ // Conversation events
37
+ export { createConversationEventStream } from "./conversation-event.js";
38
+ // Websocket audio envelope
39
+ export { SYRINX_AUDIO_ENVELOPE_NAME, SYRINX_AUDIO_ENVELOPE_MAGIC, assertAudioFormat, assertAudioPayload, encodeSyrinxAudioEnvelope, decodeSyrinxAudioEnvelope, hasSyrinxAudioEnvelope, } from "./audio-envelope.js";
40
+ export { StreamingPcm16Resampler, createLoudnessState, normalizeLoudness, } from "./audio/index.js";
41
+ // Interaction policy seam (IP-C1)
42
+ export { isLifecycleInteractionPolicy, } from "./interaction-policy.js";
43
+ export { confidenceToWaitMs } from "./confidence-to-wait.js";
44
+ export { RuleBasedInteractionPolicy } from "./policies/rule-based.js";
45
+ export { DeferInteractionPolicy } from "./policies/defer.js";
46
+ export { InteractionCoordinator } from "./interaction-coordinator.js";
47
+ // VoiceAgentSession
48
+ export { VoiceAgentSession, } from "./voice-agent-session.js";
49
+ // Primary-speaker barge-in gate (VE-02)
50
+ export { PrimarySpeakerGate, extractSpeakerFingerprint, fingerprintSimilarity, } from "./primary-speaker-gate.js";
51
+ export { synthesizeTonePcm16, mixPcm16, PRIMARY_SPEAKER_TONE_HZ, BYSTANDER_SPEAKER_TONE_HZ, ASSISTANT_ECHO_TONE_HZ, } from "./primary-speaker-fixtures.js";
52
+ // Latency-hiding filler track (VE-03)
53
+ export { LatencyFillerController, selectLatencyFillerConnective, stripRedundantFillerPrefix, LATENCY_FILLER_CONNECTIVES, } from "./latency-filler.js";
54
+ export { LATENCY_FILLER_FIXTURES, } from "./latency-filler-fixtures.js";
55
+ // Voice text: markdown/formatting normalization + leaked-tool-call guard before TTS
56
+ export { normalizeForSpeech, stripLeakedToolCalls } from "./voice-text.js";
57
+ // Hedged reasoner (Lever C — reasoner-latency RFC)
58
+ export { HedgedReasoner } from "./reasoner-hedge.js";
59
+ // Routing reasoner (Lever B — reasoner-latency RFC)
60
+ export { RoutingReasoner, } from "./reasoner-route.js";
61
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,EAAE;AACF,gCAAgC;AAChC,EAAE;AACF,yEAAyE;AAEzE,aAAa;AACb,OAAO,EAKL,aAAa,EACb,YAAY,EACZ,SAAS,GAIV,MAAM,cAAc,CAAC;A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,EAAE,cAAc,EAA8B,MAAM,qBAAqB,CAAC;AAEjF,oDAAoD;AACpD,OAAO,EACL,eAAe,GAGhB,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { PipelineBus } from "./pipeline-bus.js";
2
+ import type { InitStage } from "./packets.js";
3
+ export interface InitStep {
4
+ /** Human-readable name for logging and error messages. */
5
+ readonly name: string;
6
+ /** Which initialization stage this step represents. */
7
+ readonly stage: InitStage;
8
+ /** Run the initialization. Throws on failure. */
9
+ run(): Promise<void>;
10
+ /** Clean up resources. Called during teardown (on failure) or finalize chain. */
11
+ cleanup?(): Promise<void>;
12
+ }
13
+ export declare class InitializationError extends Error {
14
+ readonly stage: InitStage;
15
+ readonly component: string;
16
+ constructor(stage: InitStage, component: string, cause: Error);
17
+ }
18
+ /**
19
+ * Run a serial init chain. Each step runs in order. On failure:
20
+ * 1. Emits InitializationFailedPacket through the bus.
21
+ * 2. Tears down already-initialized steps in reverse order.
22
+ * 3. Throws InitializationError.
23
+ *
24
+ * On success:
25
+ * 1. Emits InitStepCompletedPacket for each step (with initMs).
26
+ * 2. Emits InitializationCompletedPacket.
27
+ */
28
+ export declare function runInitChain(bus: PipelineBus, steps: readonly InitStep[]): Promise<void>;
29
+ /**
30
+ * Run a reverse finalize chain. Steps are torn down in reverse order.
31
+ * Errors during teardown are logged but do not stop the chain.
32
+ * All steps get their cleanup called regardless of earlier failures.
33
+ */
34
+ export declare function runFinalizeChain(steps: readonly InitStep[]): Promise<void>;
35
+ //# sourceMappingURL=init-chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-chain.d.ts","sourceRoot":"","sources":["../src/init-chain.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,KAAK,EACV,SAAS,EAIV,MAAM,cAAc,CAAC;AAOtB,MAAM,WAAW,QAAQ;IACvB,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,uDAAuD;IACvD,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,iDAAiD;IACjD,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACrB,iFAAiF;IACjF,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAMD,qBAAa,mBAAoB,SAAQ,KAAK;aAE1B,KAAK,EAAE,SAAS;aAChB,SAAS,EAAE,MAAM;gBADjB,KAAK,EAAE,SAAS,EAChB,SAAS,EAAE,MAAM,EACjC,KAAK,EAAE,KAAK;CAKf;AAMD;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,SAAS,QAAQ,EAAE,GACzB,OAAO,CAAC,IAAI,CAAC,CAsDf;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,SAAS,QAAQ,EAAE,GACzB,OAAO,CAAC,IAAI,CAAC,CAQf"}