@kuralle-syrinx/test 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +22 -0
  2. package/package.json +16 -0
  3. package/src/index.ts +275 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kuralle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@kuralle-syrinx/test",
3
+ "version": "2.1.0",
4
+ "private": false,
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "main": "./src/index.ts",
8
+ "types": "./src/index.ts",
9
+ "dependencies": {
10
+ "@kuralle-syrinx/core": "2.1.0"
11
+ },
12
+ "devDependencies": {
13
+ "typescript": "^5.7.0",
14
+ "vitest": "^2.1.0"
15
+ }
16
+ }
package/src/index.ts ADDED
@@ -0,0 +1,275 @@
1
+ // SPDX-License-Identifier: MIT
2
+ //
3
+ // Syrinx Kernel v2 — Test Fakes
4
+ //
5
+ // Fake implementations of VoicePlugin for testing the kernel without
6
+ // real provider connections. Each fake pushes scripted output into the bus.
7
+
8
+ import { Route, type PipelineBus, type VoicePlugin, type PluginConfig } from "@kuralle-syrinx/core";
9
+
10
+ // =============================================================================
11
+ // Fake STT
12
+ // =============================================================================
13
+
14
+ export interface FakeSTTConfig extends PluginConfig {
15
+ /** Scripted events to emit in order. */
16
+ scriptedEvents: Array<
17
+ | { kind: "interim"; text: string }
18
+ | { kind: "final"; text: string; confidence: number; ts: number }
19
+ >;
20
+ }
21
+
22
+ export class FakeSTT implements VoicePlugin {
23
+ private config: FakeSTTConfig | null = null;
24
+ private bus: PipelineBus | null = null;
25
+
26
+ async initialize(bus: PipelineBus, config: PluginConfig): Promise<void> {
27
+ this.bus = bus;
28
+ this.config = config as FakeSTTConfig;
29
+ }
30
+
31
+ /** Emit scripted events into the bus. Call after audio injection. */
32
+ async emitScripted(contextId: string): Promise<void> {
33
+ if (!this.bus || !this.config) return;
34
+ for (const event of this.config.scriptedEvents) {
35
+ if (event.kind === "interim") {
36
+ this.bus.push(Route.Main, {
37
+ kind: "stt.interim",
38
+ contextId,
39
+ timestampMs: Date.now(),
40
+ text: event.text,
41
+ });
42
+ } else {
43
+ this.bus.push(Route.Main, {
44
+ kind: "stt.result",
45
+ contextId,
46
+ timestampMs: event.ts,
47
+ text: event.text,
48
+ confidence: event.confidence,
49
+ });
50
+ this.bus.push(Route.Main, {
51
+ kind: "eos.turn_complete",
52
+ contextId,
53
+ timestampMs: event.ts,
54
+ text: event.text,
55
+ transcripts: [],
56
+ });
57
+ }
58
+ }
59
+ }
60
+
61
+ async close(): Promise<void> {
62
+ this.bus = null;
63
+ this.config = null;
64
+ }
65
+ }
66
+
67
+ // =============================================================================
68
+ // Fake TTS
69
+ // =============================================================================
70
+
71
+ export interface FakeTTSConfig extends PluginConfig {
72
+ /** Scripted audio batches. Each batch is emitted when tts.text arrives. */
73
+ scriptedAudioBatches: Array<{
74
+ frame: { data: Int16Array; sampleRateHz: number; durationMs: number };
75
+ final: boolean;
76
+ }>;
77
+ }
78
+
79
+ export class FakeTTS implements VoicePlugin {
80
+ private config: FakeTTSConfig | null = null;
81
+ private bus: PipelineBus | null = null;
82
+ private batchIndex = 0;
83
+
84
+ async initialize(bus: PipelineBus, config: PluginConfig): Promise<void> {
85
+ this.bus = bus;
86
+ this.config = config as FakeTTSConfig;
87
+
88
+ // Listen for TTS text
89
+ bus.on("tts.text", (pkt: unknown) => {
90
+ this.emitNextBatch((pkt as { contextId?: string }).contextId ?? "");
91
+ });
92
+ }
93
+
94
+ private emitNextBatch(contextId: string): void {
95
+ if (!this.bus || !this.config) return;
96
+ const batches = this.config.scriptedAudioBatches;
97
+ if (this.batchIndex >= batches.length) return;
98
+
99
+ const batch = batches[this.batchIndex]!;
100
+ const buf = new Uint8Array(batch.frame.data.buffer);
101
+ const now = Date.now();
102
+
103
+ this.bus.push(Route.Main, {
104
+ kind: "tts.audio",
105
+ contextId,
106
+ timestampMs: now,
107
+ audio: buf,
108
+ sampleRateHz: 16000,
109
+ });
110
+
111
+ if (batch.final) {
112
+ this.bus.push(Route.Main, {
113
+ kind: "tts.end",
114
+ contextId,
115
+ timestampMs: now,
116
+ });
117
+ }
118
+
119
+ this.batchIndex++;
120
+ }
121
+
122
+ async close(): Promise<void> {
123
+ this.bus = null;
124
+ this.config = null;
125
+ }
126
+ }
127
+
128
+ // =============================================================================
129
+ // Fake VAD
130
+ // =============================================================================
131
+
132
+ export interface FakeVADConfig extends PluginConfig {
133
+ /**
134
+ * Array of speech probabilities, one per 20ms audio frame.
135
+ * Value >= 0.5 → speech, < 0.5 → silence.
136
+ */
137
+ scriptedSpeechProbabilities: number[];
138
+ }
139
+
140
+ export class FakeVAD implements VoicePlugin {
141
+ private config: FakeVADConfig | null = null;
142
+ private bus: PipelineBus | null = null;
143
+ private frameIndex = 0;
144
+ private speaking = false;
145
+
146
+ async initialize(bus: PipelineBus, config: PluginConfig): Promise<void> {
147
+ this.bus = bus;
148
+ this.config = config as FakeVADConfig;
149
+ }
150
+
151
+ /** Process one frame and emit VAD events based on scripted probability. */
152
+ processFrame(contextId: string): void {
153
+ if (!this.bus || !this.config) return;
154
+ const probs = this.config.scriptedSpeechProbabilities;
155
+ if (this.frameIndex >= probs.length) return;
156
+
157
+ const prob = probs[this.frameIndex]!;
158
+ const isSpeech = prob >= 0.5;
159
+ const now = Date.now();
160
+
161
+ if (isSpeech && !this.speaking) {
162
+ this.speaking = true;
163
+ this.bus.push(Route.Main, {
164
+ kind: "vad.speech_started",
165
+ contextId,
166
+ timestampMs: now,
167
+ confidence: prob,
168
+ });
169
+ }
170
+
171
+ if (!isSpeech && this.speaking) {
172
+ this.speaking = false;
173
+ this.bus.push(Route.Main, {
174
+ kind: "vad.speech_ended",
175
+ contextId,
176
+ timestampMs: now,
177
+ });
178
+ }
179
+
180
+ if (isSpeech) {
181
+ this.bus.push(Route.Main, {
182
+ kind: "vad.speech_activity",
183
+ contextId,
184
+ timestampMs: now,
185
+ isAsync: true,
186
+ });
187
+ }
188
+
189
+ this.frameIndex++;
190
+ }
191
+
192
+ async close(): Promise<void> {
193
+ this.bus = null;
194
+ this.config = null;
195
+ }
196
+ }
197
+
198
+ // =============================================================================
199
+ // Fake Bridge (LLM)
200
+ // =============================================================================
201
+
202
+ export interface FakeBridgeConfig extends PluginConfig {
203
+ /** Scripted LLM events in order. */
204
+ scriptedEvents: Array<
205
+ | { kind: "text"; delta: string }
206
+ | { kind: "tool_call"; id: string; name: string; args: Record<string, unknown> }
207
+ | { kind: "tool_result"; id: string; result: string }
208
+ | { kind: "done" }
209
+ >;
210
+ }
211
+
212
+ export class FakeBridge implements VoicePlugin {
213
+ private config: FakeBridgeConfig | null = null;
214
+ private bus: PipelineBus | null = null;
215
+
216
+ async initialize(bus: PipelineBus, config: PluginConfig): Promise<void> {
217
+ this.bus = bus;
218
+ this.config = config as FakeBridgeConfig;
219
+
220
+ // Listen for EOS turn completions
221
+ bus.on("eos.turn_complete", (pkt: unknown) => {
222
+ const eos = pkt as { contextId: string };
223
+ this.emitScripted(eos.contextId);
224
+ });
225
+ }
226
+
227
+ private emitScripted(contextId: string): void {
228
+ if (!this.bus || !this.config) return;
229
+ for (const event of this.config.scriptedEvents) {
230
+ switch (event.kind) {
231
+ case "text":
232
+ this.bus.push(Route.Main, {
233
+ kind: "llm.delta",
234
+ contextId,
235
+ timestampMs: Date.now(),
236
+ text: event.delta,
237
+ });
238
+ break;
239
+ case "tool_call":
240
+ this.bus.push(Route.Main, {
241
+ kind: "llm.tool_call",
242
+ contextId,
243
+ timestampMs: Date.now(),
244
+ toolId: event.id,
245
+ toolName: event.name,
246
+ toolArgs: event.args,
247
+ });
248
+ break;
249
+ case "tool_result":
250
+ this.bus.push(Route.Main, {
251
+ kind: "llm.tool_result",
252
+ contextId,
253
+ timestampMs: Date.now(),
254
+ toolId: event.id,
255
+ toolName: "",
256
+ result: event.result,
257
+ });
258
+ break;
259
+ case "done":
260
+ this.bus.push(Route.Main, {
261
+ kind: "llm.done",
262
+ contextId,
263
+ timestampMs: Date.now(),
264
+ text: "",
265
+ });
266
+ break;
267
+ }
268
+ }
269
+ }
270
+
271
+ async close(): Promise<void> {
272
+ this.bus = null;
273
+ this.config = null;
274
+ }
275
+ }