@crvouga/mockingbird-service-aws-speech 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/README.md +132 -0
- package/dist/chunk-3DE3INNY.js +3410 -0
- package/dist/chunk-3DE3INNY.js.map +7 -0
- package/dist/chunk-A46XUZ6Z.js +306 -0
- package/dist/chunk-A46XUZ6Z.js.map +7 -0
- package/dist/cli.js +371 -0
- package/dist/cli.js.map +7 -0
- package/dist/index.d.ts +1066 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +7 -0
- package/dist/server.d.ts +1314 -0
- package/dist/server.js +14 -0
- package/dist/server.js.map +7 -0
- package/package.json +96 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1066 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Anything that can answer a Fetch `Request` with a `Response`.
|
|
5
|
+
*
|
|
6
|
+
* Every Mockingbird service implements this, and every runtime adapter consumes it.
|
|
7
|
+
* It is the only contract shared across the whole graph.
|
|
8
|
+
*/
|
|
9
|
+
interface FetchAPI$1 {
|
|
10
|
+
fetch(request: Request): Promise<Response>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The single source of time for a service.
|
|
15
|
+
*
|
|
16
|
+
* Every timestamp a mock writes reads from here, so a suite moves time instead of
|
|
17
|
+
* sleeping: appointment windows, result delays and expiries become reachable in
|
|
18
|
+
* milliseconds. A frozen clock also makes timestamps reproducible from a seed.
|
|
19
|
+
*/
|
|
20
|
+
type ClockState = {
|
|
21
|
+
/** Current epoch milliseconds. */
|
|
22
|
+
now: number;
|
|
23
|
+
/** True while time does not advance on its own. */
|
|
24
|
+
frozen: boolean;
|
|
25
|
+
/** Milliseconds this clock adds to its underlying source. */
|
|
26
|
+
offsetMs: number;
|
|
27
|
+
};
|
|
28
|
+
type Clock = {
|
|
29
|
+
now(): number;
|
|
30
|
+
/** Pin the clock to an exact instant, keeping it frozen if it already was. */
|
|
31
|
+
set(epochMs: number): void;
|
|
32
|
+
/** Move the clock forward, or back with a negative delta. */
|
|
33
|
+
advance(deltaMs: number): void;
|
|
34
|
+
/** Stop time at the current instant. */
|
|
35
|
+
freeze(): void;
|
|
36
|
+
/** Resume from the current instant. */
|
|
37
|
+
unfreeze(): void;
|
|
38
|
+
/** Drop back to the underlying source, live. */
|
|
39
|
+
reset(): void;
|
|
40
|
+
state(): ClockState;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
|
|
44
|
+
type SqliteValue$1 = null | number | bigint | string | Uint8Array | boolean;
|
|
45
|
+
/** Mutation counters returned by {@link SqliteStatement.run}. */
|
|
46
|
+
type SqliteRunResult$1 = {
|
|
47
|
+
changes: number;
|
|
48
|
+
lastInsertRowid: number | bigint;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Prepared statement bound to a {@link SqliteClient}.
|
|
52
|
+
*
|
|
53
|
+
* Pass bind values as rest arguments on each call (no sticky `bind()`).
|
|
54
|
+
*/
|
|
55
|
+
interface SqliteStatement$1 {
|
|
56
|
+
run(...params: SqliteValue$1[]): SqliteRunResult$1;
|
|
57
|
+
all<T = Record<string, unknown>>(...params: SqliteValue$1[]): T[];
|
|
58
|
+
get<T = Record<string, unknown>>(...params: SqliteValue$1[]): T | undefined;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Sync SQLite client port owned by Mockingbird.
|
|
62
|
+
*
|
|
63
|
+
* Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
|
|
64
|
+
* `bun:sqlite` instances all work when they expose this surface.
|
|
65
|
+
*/
|
|
66
|
+
interface SqliteClient$1 {
|
|
67
|
+
exec(sql: string): void;
|
|
68
|
+
prepare(sql: string): SqliteStatement$1;
|
|
69
|
+
transaction<T>(fn: () => T): T;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Every stored record carries a monotonically increasing sequence for stable ordering. */
|
|
73
|
+
type Stored<T> = {
|
|
74
|
+
seq: number;
|
|
75
|
+
value: T;
|
|
76
|
+
};
|
|
77
|
+
type ListRecordsOptions<T> = {
|
|
78
|
+
/** Keep only records passing the predicate. */
|
|
79
|
+
where?: (value: T, seq: number) => boolean;
|
|
80
|
+
/** Sort order; default newest first. */
|
|
81
|
+
order?: "newest" | "oldest";
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* A SQLite-backed table of JSON records addressed by id. Ordering is by insertion
|
|
85
|
+
* sequence, never by id lexicographic order, so list semantics stay stable.
|
|
86
|
+
*/
|
|
87
|
+
declare class Collection<T> {
|
|
88
|
+
private readonly sqlite;
|
|
89
|
+
private readonly namespace;
|
|
90
|
+
private readonly name;
|
|
91
|
+
constructor(sqlite: SqliteClient$1, namespace: string, name: string);
|
|
92
|
+
private bumpCollectionSeq;
|
|
93
|
+
nextSequence(): number;
|
|
94
|
+
get(id: string): T | undefined;
|
|
95
|
+
has(id: string): boolean;
|
|
96
|
+
/** Insert a new record, assigning it the next sequence number. */
|
|
97
|
+
insert(id: string, value: T): Stored<T>;
|
|
98
|
+
/** Replace an existing record's value, keeping its position. */
|
|
99
|
+
update(id: string, value: T): Stored<T> | undefined;
|
|
100
|
+
delete(id: string): boolean;
|
|
101
|
+
/** How many records the collection holds, without reading them. */
|
|
102
|
+
count(): number;
|
|
103
|
+
list(options?: ListRecordsOptions<T>): Array<Stored<T> & {
|
|
104
|
+
id: string;
|
|
105
|
+
}>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Seeded pseudo-random numbers, so anything a mock invents — ids, jitter, which
|
|
110
|
+
* request a percentage fault hits — is reproducible from a seed.
|
|
111
|
+
*
|
|
112
|
+
* mulberry32: small, fast, and stable across runtimes, which matters more here
|
|
113
|
+
* than statistical quality.
|
|
114
|
+
*/
|
|
115
|
+
type Rng = {
|
|
116
|
+
/** Next value in `[0, 1)`. */
|
|
117
|
+
next(): number;
|
|
118
|
+
/** Next integer in `[min, max]`. */
|
|
119
|
+
int(min: number, max: number): number;
|
|
120
|
+
/** Restart the stream from its seed. */
|
|
121
|
+
reset(): void;
|
|
122
|
+
/** Serializable engine state used by deterministic checkpoints. */
|
|
123
|
+
state(): number;
|
|
124
|
+
/** Restore a state previously returned by {@link state}. */
|
|
125
|
+
setState(state: number): void;
|
|
126
|
+
seed: number;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* A deliberate failure injected in front of an operation.
|
|
131
|
+
*
|
|
132
|
+
* This is how a suite reaches the vendor's failure modes without the vendor: the
|
|
133
|
+
* quota error that only appears when a shared sandbox is full, the 429 that only
|
|
134
|
+
* appears under load, the 5xx that proves a retry path works.
|
|
135
|
+
*/
|
|
136
|
+
type FaultRule = {
|
|
137
|
+
/** Stable id, so a suite can retire exactly the rule it added. */
|
|
138
|
+
id: string;
|
|
139
|
+
/** Fault only this operation. Omit to match every operation. */
|
|
140
|
+
operationId?: string;
|
|
141
|
+
/** Fault only this HTTP method, case-insensitive. Omit to match every method. */
|
|
142
|
+
method?: string;
|
|
143
|
+
/** Fault only paths starting with this prefix. Omit to match every path. */
|
|
144
|
+
pathPrefix?: string;
|
|
145
|
+
/**
|
|
146
|
+
* Fault only this namespace. Omit (or `"*"`) to fault every namespace — which is what
|
|
147
|
+
* an in-process caller usually wants, and what a parallel worker usually does not:
|
|
148
|
+
* rules added through `POST /__admin/faults` default to the calling namespace.
|
|
149
|
+
*/
|
|
150
|
+
namespace?: string;
|
|
151
|
+
/**
|
|
152
|
+
* Status of the injected response. Omit for a rule that only delays (`delayMs` /
|
|
153
|
+
* `latencyMs`), only drops the connection (`drop`), or only switches on an `effect`:
|
|
154
|
+
* the request then still reaches the service.
|
|
155
|
+
*/
|
|
156
|
+
status?: number;
|
|
157
|
+
/** Response body, serialized as JSON. A string is sent as-is. */
|
|
158
|
+
body?: unknown;
|
|
159
|
+
headers?: Record<string, string>;
|
|
160
|
+
/** Retire the rule after this many faults. Omit to keep it until removed. */
|
|
161
|
+
count?: number;
|
|
162
|
+
/** Fault this fraction of matching requests, `0`–`1`. Default `1`. */
|
|
163
|
+
rate?: number;
|
|
164
|
+
/** Hold the response back this long, to exercise timeouts. */
|
|
165
|
+
delayMs?: number;
|
|
166
|
+
/** Alias of `delayMs`. */
|
|
167
|
+
latencyMs?: number;
|
|
168
|
+
/**
|
|
169
|
+
* Drop the connection instead of answering: an in-process `fetch` rejects with a
|
|
170
|
+
* `TypeError`, and a served mock destroys the socket. Models "unknown outcome" failures.
|
|
171
|
+
*/
|
|
172
|
+
drop?: boolean;
|
|
173
|
+
/**
|
|
174
|
+
* A named service behaviour to switch on for the matching request instead of (or
|
|
175
|
+
* before) a canned response, e.g. `created_but_500` or `numeric_tracking_id`. Services
|
|
176
|
+
* read it with `faultEffects(request)`.
|
|
177
|
+
*/
|
|
178
|
+
effect?: string;
|
|
179
|
+
/** Parameters for `effect`. */
|
|
180
|
+
params?: Record<string, unknown>;
|
|
181
|
+
/** From the preset this rule was expanded from, if any. */
|
|
182
|
+
preset?: string;
|
|
183
|
+
};
|
|
184
|
+
/** A fault that fired for one request. */
|
|
185
|
+
type FaultHit = {
|
|
186
|
+
id: string;
|
|
187
|
+
/** The injected response; absent when the rule only delays, drops, or sets an effect. */
|
|
188
|
+
response?: Response;
|
|
189
|
+
drop?: boolean;
|
|
190
|
+
effect?: {
|
|
191
|
+
name: string;
|
|
192
|
+
params: Record<string, unknown>;
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* A named, documented fault a suite switches on by name
|
|
197
|
+
* (`POST /__admin/faults {"preset": "rate_limited"}`): one or more rules, and optionally a
|
|
198
|
+
* webhook delivery fault.
|
|
199
|
+
*/
|
|
200
|
+
type FaultPreset = {
|
|
201
|
+
description: string;
|
|
202
|
+
rules?: Omit<FaultRule, "id">[];
|
|
203
|
+
webhook?: {
|
|
204
|
+
mode: "duplicate" | "reorder" | "drop";
|
|
205
|
+
count?: number;
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
/** What a request looks like to the fault matcher. */
|
|
209
|
+
type FaultCandidate = {
|
|
210
|
+
operationId: string | undefined;
|
|
211
|
+
method: string;
|
|
212
|
+
path: string;
|
|
213
|
+
namespace: string;
|
|
214
|
+
};
|
|
215
|
+
type FaultRegistry = {
|
|
216
|
+
add(rule: FaultRule): FaultRule;
|
|
217
|
+
list(): (FaultRule & {
|
|
218
|
+
remaining: number | null;
|
|
219
|
+
hits: number;
|
|
220
|
+
})[];
|
|
221
|
+
remove(id: string): boolean;
|
|
222
|
+
clear(): void;
|
|
223
|
+
/**
|
|
224
|
+
* Every fault this request should get, in rule order, stopping at the first that answers
|
|
225
|
+
* or drops (effect-only and delay-only rules let later rules match too). Consumes one of
|
|
226
|
+
* each matching rule's remaining uses.
|
|
227
|
+
*/
|
|
228
|
+
take(candidate: FaultCandidate): Promise<FaultHit[]>;
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
/** One handled request, as the structured log sees it. */
|
|
232
|
+
type RequestLog = {
|
|
233
|
+
service: string;
|
|
234
|
+
namespace: string;
|
|
235
|
+
operationId: string | undefined;
|
|
236
|
+
method: string;
|
|
237
|
+
path: string;
|
|
238
|
+
status: number;
|
|
239
|
+
durationMs: number;
|
|
240
|
+
/** True when the path matched no operation in the contract. */
|
|
241
|
+
unmatched: boolean;
|
|
242
|
+
/** Set when a fault rule produced the response. */
|
|
243
|
+
faultId?: string;
|
|
244
|
+
/** Resource ids the handler touched (`userId`, `orderId`, …), when the service reports them. */
|
|
245
|
+
ids?: Record<string, string>;
|
|
246
|
+
/** Set when the service created a resource the request referred to but that did not exist. */
|
|
247
|
+
adopted?: boolean;
|
|
248
|
+
};
|
|
249
|
+
type MetricsReport = {
|
|
250
|
+
requests: number;
|
|
251
|
+
/** Counts keyed `<operationId> <status>`. */
|
|
252
|
+
byOperation: Record<string, number>;
|
|
253
|
+
/**
|
|
254
|
+
* Paths that matched no operation, most frequent first.
|
|
255
|
+
*
|
|
256
|
+
* This is the early-warning signal: a consumer calling something the mock does
|
|
257
|
+
* not implement shows up here as a count, before it fails a suite as a 404.
|
|
258
|
+
*/
|
|
259
|
+
unmatched: {
|
|
260
|
+
method: string;
|
|
261
|
+
path: string;
|
|
262
|
+
count: number;
|
|
263
|
+
}[];
|
|
264
|
+
faults: number;
|
|
265
|
+
totalDurationMs: number;
|
|
266
|
+
};
|
|
267
|
+
type Metrics = {
|
|
268
|
+
record(entry: RequestLog): void;
|
|
269
|
+
report(): MetricsReport;
|
|
270
|
+
reset(): void;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
/** One journal entry: a request log stamped with when (on the mock clock) it was handled. */
|
|
274
|
+
type JournalEntry = RequestLog & {
|
|
275
|
+
at: string;
|
|
276
|
+
};
|
|
277
|
+
type JournalQuery = {
|
|
278
|
+
/** Only this namespace. Omit for every namespace, oldest first across all of them. */
|
|
279
|
+
namespace?: string;
|
|
280
|
+
operationId?: string;
|
|
281
|
+
status?: number;
|
|
282
|
+
/** Only entries at or after this instant (epoch ms). */
|
|
283
|
+
since?: number;
|
|
284
|
+
/** At most this many, the most recent kept. */
|
|
285
|
+
limit?: number;
|
|
286
|
+
};
|
|
287
|
+
type Journal = {
|
|
288
|
+
readonly size: number;
|
|
289
|
+
record(entry: JournalEntry): void;
|
|
290
|
+
list(query?: JournalQuery): JournalEntry[];
|
|
291
|
+
/** Forget one namespace's entries, or every namespace's. */
|
|
292
|
+
clear(namespace?: string): void;
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
/** Credential → namespace mapping behind `PUT /__admin/credentials`. */
|
|
296
|
+
type CredentialRegistry = {
|
|
297
|
+
set(credential: string, namespace: string): void;
|
|
298
|
+
get(credential: string): string | undefined;
|
|
299
|
+
remove(credential: string): boolean;
|
|
300
|
+
clear(): void;
|
|
301
|
+
entries(): {
|
|
302
|
+
credential: string;
|
|
303
|
+
namespace: string;
|
|
304
|
+
}[];
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
/** A stable identifier for a point in a {@link Timeline}. */
|
|
308
|
+
type CheckpointId = string;
|
|
309
|
+
/** An immutable node in a timeline's checkpoint DAG. */
|
|
310
|
+
type Checkpoint<T> = Readonly<{
|
|
311
|
+
id: CheckpointId;
|
|
312
|
+
branch: string;
|
|
313
|
+
parent: CheckpointId | null;
|
|
314
|
+
/** Logical time supplied by the timeline's injected clock. */
|
|
315
|
+
at: number;
|
|
316
|
+
value: T;
|
|
317
|
+
}>;
|
|
318
|
+
type TimelineOptions = {
|
|
319
|
+
/** Logical clock used to stamp checkpoints. Defaults to a deterministic counter. */
|
|
320
|
+
now?: () => number;
|
|
321
|
+
/** Maximum retained checkpoints. Branch heads are never collected. Default 1,000. */
|
|
322
|
+
maxCheckpoints?: number;
|
|
323
|
+
/** Customize deterministic checkpoint IDs. */
|
|
324
|
+
id?: (sequence: number) => CheckpointId;
|
|
325
|
+
};
|
|
326
|
+
type CommitOptions = {
|
|
327
|
+
branch?: string;
|
|
328
|
+
/** Parent checkpoint. Defaults to the selected branch's current head. */
|
|
329
|
+
parent?: CheckpointId | null;
|
|
330
|
+
};
|
|
331
|
+
type ForkOptions = {
|
|
332
|
+
/** Checkpoint to fork from. Defaults to the main branch's head. */
|
|
333
|
+
from?: CheckpointId;
|
|
334
|
+
};
|
|
335
|
+
/**
|
|
336
|
+
* Small, storage-agnostic checkpoint DAG shared by service runtimes. Its values may be immutable
|
|
337
|
+
* records, namespace images, or copy-on-write SQL engine snapshots.
|
|
338
|
+
*
|
|
339
|
+
* Values are retained by reference. Engines can therefore use persistent/COW snapshots while
|
|
340
|
+
* simpler services can use immutable values. IDs and GC order are deterministic, and all IO
|
|
341
|
+
* (the logical clock) is injected.
|
|
342
|
+
*/
|
|
343
|
+
declare class Timeline<T> {
|
|
344
|
+
readonly maxCheckpoints: number;
|
|
345
|
+
private readonly now;
|
|
346
|
+
private readonly makeId;
|
|
347
|
+
private readonly nodes;
|
|
348
|
+
private readonly heads;
|
|
349
|
+
/** Unreferenced nodes in the exact order they became collectible. */
|
|
350
|
+
private readonly evictable;
|
|
351
|
+
/** Branch heads plus explicit retainers. Absent means zero. */
|
|
352
|
+
private readonly references;
|
|
353
|
+
private readonly explicitPins;
|
|
354
|
+
private sequence;
|
|
355
|
+
constructor(options?: TimelineOptions);
|
|
356
|
+
/** Capture a new immutable value and move `branch` to it. */
|
|
357
|
+
commit(value: T, options?: CommitOptions): Checkpoint<T>;
|
|
358
|
+
/** Create a branch pointer without copying its checkpoint value. */
|
|
359
|
+
fork(branch: string, options?: ForkOptions): Checkpoint<T> | undefined;
|
|
360
|
+
/** Move a branch pointer to an existing checkpoint. */
|
|
361
|
+
checkout(branch: string, id: CheckpointId): Checkpoint<T>;
|
|
362
|
+
get(id: CheckpointId): Checkpoint<T>;
|
|
363
|
+
head(branch?: string): Checkpoint<T> | undefined;
|
|
364
|
+
hasBranch(branch: string): boolean;
|
|
365
|
+
branches(): Readonly<Record<string, CheckpointId>>;
|
|
366
|
+
checkpoints(): readonly Checkpoint<T>[];
|
|
367
|
+
/** Number of retained checkpoints without allocating an array. */
|
|
368
|
+
get size(): number;
|
|
369
|
+
/** Pin a checkpoint independently of branch heads (used by compatibility snapshot handles). */
|
|
370
|
+
retain(id: CheckpointId): Checkpoint<T>;
|
|
371
|
+
/** Release one explicit pin. Branch heads remain pinned until moved or deleted. */
|
|
372
|
+
release(id: CheckpointId): boolean;
|
|
373
|
+
deleteBranch(branch: string): boolean;
|
|
374
|
+
/**
|
|
375
|
+
* Deterministically discard oldest unpinned checkpoints. Collection is O(number removed):
|
|
376
|
+
* commits never scan pinned nodes or the retained history. Parents are metadata rather than a
|
|
377
|
+
* storage dependency, so a retained node remains usable after pruning.
|
|
378
|
+
*/
|
|
379
|
+
gc(max?: number): CheckpointId[];
|
|
380
|
+
private collect;
|
|
381
|
+
private moveHead;
|
|
382
|
+
private addReference;
|
|
383
|
+
private removeReference;
|
|
384
|
+
private assertBranch;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Anything that can answer a Fetch `Request` with a `Response`.
|
|
389
|
+
*
|
|
390
|
+
* Every Mockingbird service implements this, and every runtime adapter consumes it.
|
|
391
|
+
* It is the only contract shared across the whole graph.
|
|
392
|
+
*/
|
|
393
|
+
interface FetchAPI {
|
|
394
|
+
fetch(request: Request): Promise<Response>;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* A point-in-time copy of everything a service namespace holds.
|
|
399
|
+
*
|
|
400
|
+
* All service state lives in the two core tables keyed by namespace, so a snapshot
|
|
401
|
+
* is generic: any service gets per-test rollback without knowing its own schema.
|
|
402
|
+
* Restoring is much cheaper than rebuilding a namespace from a corpus.
|
|
403
|
+
*/
|
|
404
|
+
type NamespaceSnapshot = {
|
|
405
|
+
namespace: string;
|
|
406
|
+
records: {
|
|
407
|
+
collection: string;
|
|
408
|
+
id: string;
|
|
409
|
+
seq: number;
|
|
410
|
+
value: string;
|
|
411
|
+
}[];
|
|
412
|
+
sequences: {
|
|
413
|
+
name: string;
|
|
414
|
+
kind: string;
|
|
415
|
+
value: number;
|
|
416
|
+
}[];
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
type WebhookEndpoint = {
|
|
420
|
+
/** Stable id; generated when omitted. */
|
|
421
|
+
id?: string;
|
|
422
|
+
url: string;
|
|
423
|
+
secret?: string;
|
|
424
|
+
/** Event types to deliver; omit or include `"*"` for every type. */
|
|
425
|
+
events?: string[];
|
|
426
|
+
/** Deliver only messages whose tags include all of these (e.g. `{ account: "mso" }`). */
|
|
427
|
+
tags?: Record<string, string>;
|
|
428
|
+
/** The public URL the receiver verifies signatures against (Twilio), when it differs. */
|
|
429
|
+
signUrl?: string;
|
|
430
|
+
headers?: Record<string, string>;
|
|
431
|
+
};
|
|
432
|
+
type WebhookMessage = {
|
|
433
|
+
id: string;
|
|
434
|
+
namespace: string;
|
|
435
|
+
type: string;
|
|
436
|
+
body: string;
|
|
437
|
+
contentType: string;
|
|
438
|
+
tags: Record<string, string>;
|
|
439
|
+
headers?: Record<string, string>;
|
|
440
|
+
/** Wall-clock ISO-8601 time of publication. */
|
|
441
|
+
publishedAt: string;
|
|
442
|
+
};
|
|
443
|
+
type WebhookAttempt = {
|
|
444
|
+
attempt: number;
|
|
445
|
+
at: string;
|
|
446
|
+
status: number | null;
|
|
447
|
+
error: string | null;
|
|
448
|
+
durationMs: number;
|
|
449
|
+
/** Exact receiver response body, when one was returned. */
|
|
450
|
+
responseBody?: string | null;
|
|
451
|
+
};
|
|
452
|
+
type WebhookDelivery = {
|
|
453
|
+
id: string;
|
|
454
|
+
messageId: string;
|
|
455
|
+
namespace: string;
|
|
456
|
+
type: string;
|
|
457
|
+
endpointId: string;
|
|
458
|
+
url: string;
|
|
459
|
+
state: "pending" | "delivered" | "failed" | "dropped";
|
|
460
|
+
attempts: WebhookAttempt[];
|
|
461
|
+
};
|
|
462
|
+
/** A delivery-level fault: what happens to the next `count` messages in a namespace. */
|
|
463
|
+
type WebhookFault = {
|
|
464
|
+
mode: "duplicate" | "reorder" | "drop";
|
|
465
|
+
/** Messages affected; default 1. */
|
|
466
|
+
count?: number;
|
|
467
|
+
};
|
|
468
|
+
type PublishInput = {
|
|
469
|
+
namespace: string;
|
|
470
|
+
type: string;
|
|
471
|
+
/** Exact body; objects are JSON-encoded. */
|
|
472
|
+
body: string | Record<string, unknown> | unknown[];
|
|
473
|
+
/** Default `application/json`, or form-encoded when `form` is given. */
|
|
474
|
+
contentType?: string;
|
|
475
|
+
/** Form parameters, when the vendor posts `application/x-www-form-urlencoded`. */
|
|
476
|
+
form?: Record<string, string>;
|
|
477
|
+
tags?: Record<string, string>;
|
|
478
|
+
/** Message-specific delivery headers, captured as part of durable message state. */
|
|
479
|
+
headers?: Record<string, string>;
|
|
480
|
+
/** Message id; generated when omitted. */
|
|
481
|
+
id?: string;
|
|
482
|
+
};
|
|
483
|
+
type WebhookHub = {
|
|
484
|
+
publish(input: PublishInput): WebhookMessage;
|
|
485
|
+
/** Replace a namespace's own endpoints (`PUT /__admin/webhook-endpoints`). */
|
|
486
|
+
setEndpoints(namespace: string, endpoints: WebhookEndpoint[]): WebhookEndpoint[];
|
|
487
|
+
/** The endpoints a namespace delivers to: its own, plus the global ones. */
|
|
488
|
+
endpoints(namespace: string): WebhookEndpoint[];
|
|
489
|
+
messages(namespace?: string): WebhookMessage[];
|
|
490
|
+
deliveries(namespace?: string): WebhookDelivery[];
|
|
491
|
+
replay(deliveryId: string): Promise<WebhookDelivery | undefined>;
|
|
492
|
+
/** Run every pending retry (and release held reordered messages) now. */
|
|
493
|
+
flush(): Promise<void>;
|
|
494
|
+
/** Resolve once nothing is in flight. */
|
|
495
|
+
idle(): Promise<void>;
|
|
496
|
+
fault(namespace: string, fault: WebhookFault): void;
|
|
497
|
+
clear(namespace?: string): void;
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
/** What the runtime needs from a service: a Fetch handler it can reset. */
|
|
501
|
+
type ServiceInstance = FetchAPI & {
|
|
502
|
+
reset(): Promise<void>;
|
|
503
|
+
};
|
|
504
|
+
type ServiceTimelineState = Readonly<{
|
|
505
|
+
snapshot: NamespaceSnapshot;
|
|
506
|
+
clock: Readonly<ReturnType<Clock["state"]>>;
|
|
507
|
+
rngState: number;
|
|
508
|
+
}>;
|
|
509
|
+
type ServiceCheckpoint = Checkpoint<ServiceTimelineState>;
|
|
510
|
+
type ServiceRuntime<T extends ServiceInstance> = FetchAPI & {
|
|
511
|
+
readonly name: string;
|
|
512
|
+
readonly sqlite: SqliteClient$1;
|
|
513
|
+
readonly clock: Clock;
|
|
514
|
+
readonly faults: FaultRegistry;
|
|
515
|
+
readonly metrics: Metrics;
|
|
516
|
+
readonly journal: Journal;
|
|
517
|
+
readonly rng: Rng;
|
|
518
|
+
readonly credentials: CredentialRegistry;
|
|
519
|
+
/** The webhook hub, when the service has outbound webhooks. */
|
|
520
|
+
readonly webhooks: WebhookHub | undefined;
|
|
521
|
+
/** Expand a named preset into fault rules (and webhook faults) for `namespace`. */
|
|
522
|
+
applyPreset(name: string, namespace?: string, overrides?: Partial<FaultRule>): FaultRule[];
|
|
523
|
+
/** The instance behind `namespace` (the default one when omitted), created on first use. */
|
|
524
|
+
instance(namespace?: string): T;
|
|
525
|
+
/** Public names of every namespace created so far. */
|
|
526
|
+
namespaces(): string[];
|
|
527
|
+
/** Reset one namespace, or every namespace with `"*"`. */
|
|
528
|
+
reset(namespace?: string): Promise<void>;
|
|
529
|
+
snapshot(namespace?: string): NamespaceSnapshot;
|
|
530
|
+
restore(snapshot: NamespaceSnapshot, namespace?: string): void;
|
|
531
|
+
/** Capture the current branch. Mutating HTTP calls do this automatically. */
|
|
532
|
+
checkpoint(namespace?: string, branch?: string): ServiceCheckpoint;
|
|
533
|
+
/** Create an isolated branch, optionally from a historical checkpoint. */
|
|
534
|
+
branch(name: string, options?: {
|
|
535
|
+
namespace?: string;
|
|
536
|
+
at?: string;
|
|
537
|
+
}): ServiceCheckpoint;
|
|
538
|
+
/** Restore a branch, clock, and PRNG to a checkpoint. */
|
|
539
|
+
checkout(checkpoint: string, options?: {
|
|
540
|
+
namespace?: string;
|
|
541
|
+
branch?: string;
|
|
542
|
+
}): void;
|
|
543
|
+
/** Inspect the retained history for a namespace. */
|
|
544
|
+
timeline(namespace?: string): Timeline<ServiceTimelineState>;
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* A minimal S3 `PutObject` for mocks whose vendor hands the app an `s3://` object (GxG
|
|
549
|
+
* results, Daily transcripts): the mock writes the object into the stack's local S3
|
|
550
|
+
* (s3rver, MinIO) so the app's own `GetObject` / `CopyObject` finds it. Path-style
|
|
551
|
+
* addressing, SigV4-signed, no SDK.
|
|
552
|
+
*/
|
|
553
|
+
type S3Target = {
|
|
554
|
+
/** e.g. `http://127.0.0.1:4569`. */
|
|
555
|
+
endpoint: string;
|
|
556
|
+
bucket: string;
|
|
557
|
+
region?: string;
|
|
558
|
+
accessKeyId?: string;
|
|
559
|
+
secretAccessKey?: string;
|
|
560
|
+
fetch?: (request: Request) => Promise<Response>;
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
/** Options every provider constructor accepts. */
|
|
564
|
+
type APIOptions = {
|
|
565
|
+
/** Sync SQLite client. Defaults to `@crvouga/mockingbird-service-sqlite`. */
|
|
566
|
+
sqlite?: SqliteClient$1;
|
|
567
|
+
/** Clock used for `created`-style fields. Default `Date.now`. */
|
|
568
|
+
now?: () => number;
|
|
569
|
+
/**
|
|
570
|
+
* Storage namespace for this instance's records. Instances sharing one SQLite
|
|
571
|
+
* client stay isolated when their namespaces differ. Defaults to the service name.
|
|
572
|
+
*/
|
|
573
|
+
namespace?: string;
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
/** Bind values accepted by Mockingbird's SQLite port (matches sqlite-mem / better-sqlite3). */
|
|
577
|
+
type SqliteValue = null | number | bigint | string | Uint8Array | boolean;
|
|
578
|
+
/** Mutation counters returned by {@link SqliteStatement.run}. */
|
|
579
|
+
type SqliteRunResult = {
|
|
580
|
+
changes: number;
|
|
581
|
+
lastInsertRowid: number | bigint;
|
|
582
|
+
};
|
|
583
|
+
/**
|
|
584
|
+
* Prepared statement bound to a {@link SqliteClient}.
|
|
585
|
+
*
|
|
586
|
+
* Pass bind values as rest arguments on each call (no sticky `bind()`).
|
|
587
|
+
*/
|
|
588
|
+
interface SqliteStatement {
|
|
589
|
+
run(...params: SqliteValue[]): SqliteRunResult;
|
|
590
|
+
all<T = Record<string, unknown>>(...params: SqliteValue[]): T[];
|
|
591
|
+
get<T = Record<string, unknown>>(...params: SqliteValue[]): T | undefined;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Sync SQLite client port owned by Mockingbird.
|
|
595
|
+
*
|
|
596
|
+
* Duck-typed so `@crvouga/mockingbird-service-sqlite` `Database`, better-sqlite3, and wrapped
|
|
597
|
+
* `bun:sqlite` instances all work when they expose this surface.
|
|
598
|
+
*/
|
|
599
|
+
interface SqliteClient {
|
|
600
|
+
exec(sql: string): void;
|
|
601
|
+
prepare(sql: string): SqliteStatement;
|
|
602
|
+
transaction<T>(fn: () => T): T;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* A scripted transcript (`PUT /__admin/transcripts`): what Transcribe "hears". Audio bytes
|
|
607
|
+
* sent in are ignored; the words come from here.
|
|
608
|
+
*/
|
|
609
|
+
type TranscriptScript = {
|
|
610
|
+
id: string;
|
|
611
|
+
/**
|
|
612
|
+
* Which streaming session (0-based, per namespace) or batch job this answers; `any: true`
|
|
613
|
+
* (or no match) answers any session that has no more specific script.
|
|
614
|
+
*/
|
|
615
|
+
match?: {
|
|
616
|
+
sessionIndex?: number;
|
|
617
|
+
jobName?: string;
|
|
618
|
+
any?: boolean;
|
|
619
|
+
};
|
|
620
|
+
/** Partial results, sent one per audio chunk received, in order. */
|
|
621
|
+
partials?: string[];
|
|
622
|
+
/** The final (IsPartial: false) result, sent when the audio ends. */
|
|
623
|
+
final: string;
|
|
624
|
+
/** Answer at most this many sessions / jobs. */
|
|
625
|
+
times?: number;
|
|
626
|
+
};
|
|
627
|
+
/** A Transcribe batch job, with only the fields the service echoes back. */
|
|
628
|
+
type JobRecord = {
|
|
629
|
+
TranscriptionJobName: string;
|
|
630
|
+
TranscriptionJobStatus: "QUEUED" | "IN_PROGRESS" | "FAILED" | "COMPLETED";
|
|
631
|
+
LanguageCode: string;
|
|
632
|
+
MediaFormat?: string;
|
|
633
|
+
MediaSampleRateHertz?: number;
|
|
634
|
+
Media: {
|
|
635
|
+
MediaFileUri?: string;
|
|
636
|
+
};
|
|
637
|
+
Settings?: Record<string, unknown>;
|
|
638
|
+
OutputBucketName?: string;
|
|
639
|
+
OutputKey?: string;
|
|
640
|
+
region: string;
|
|
641
|
+
/** Mock-clock epoch ms. */
|
|
642
|
+
createdAtMs: number;
|
|
643
|
+
completedAtMs?: number;
|
|
644
|
+
failureReason?: string;
|
|
645
|
+
/** The transcript text, fixed when the job completes. */
|
|
646
|
+
transcript?: string;
|
|
647
|
+
};
|
|
648
|
+
/** Per-namespace knobs, set through `PUT /__admin/settings`; cleared on reset. */
|
|
649
|
+
type Settings = {
|
|
650
|
+
/** What an unscripted streaming session or batch job hears. */
|
|
651
|
+
defaultTranscript: string;
|
|
652
|
+
/** Mock-clock ms from `StartTranscriptionJob` to COMPLETED (0: complete on the first Get). */
|
|
653
|
+
jobDurationMs: number;
|
|
654
|
+
};
|
|
655
|
+
declare const DEFAULT_SETTINGS: Settings;
|
|
656
|
+
/** Metadata about one synthesis or transcription (never the text). */
|
|
657
|
+
type SpeechLogEntry = {
|
|
658
|
+
operation: string;
|
|
659
|
+
voiceId?: string;
|
|
660
|
+
engine?: string;
|
|
661
|
+
outputFormat?: string;
|
|
662
|
+
sampleRate?: string;
|
|
663
|
+
characters?: number;
|
|
664
|
+
audioBytes: number;
|
|
665
|
+
/** Audio events received (transcription). */
|
|
666
|
+
chunks?: number;
|
|
667
|
+
script?: string;
|
|
668
|
+
};
|
|
669
|
+
type SpeechStats = {
|
|
670
|
+
sessions: number;
|
|
671
|
+
scripted: number;
|
|
672
|
+
unscripted: number;
|
|
673
|
+
};
|
|
674
|
+
declare class SpeechState {
|
|
675
|
+
private readonly seed;
|
|
676
|
+
readonly transcripts: Collection<TranscriptScript>;
|
|
677
|
+
readonly uses: Collection<number>;
|
|
678
|
+
readonly jobs: Collection<JobRecord>;
|
|
679
|
+
readonly settings: Collection<Settings>;
|
|
680
|
+
readonly stats: Collection<SpeechStats>;
|
|
681
|
+
readonly log: Collection<SpeechLogEntry>;
|
|
682
|
+
constructor(sqlite: SqliteClient, namespace: string, seed: {
|
|
683
|
+
settings: Partial<Settings>;
|
|
684
|
+
transcripts: readonly TranscriptScript[];
|
|
685
|
+
});
|
|
686
|
+
ensureSeeded(): void;
|
|
687
|
+
current(): Settings;
|
|
688
|
+
update(patch: Partial<Settings>): Settings;
|
|
689
|
+
scripts(): TranscriptScript[];
|
|
690
|
+
put(scripts: readonly TranscriptScript[], replace: boolean): TranscriptScript[];
|
|
691
|
+
remove(id?: string): number;
|
|
692
|
+
/**
|
|
693
|
+
* The transcript for a session or job: the first script naming it exactly, else the first
|
|
694
|
+
* `any` (or unmatched) script with uses left. Counts the use and the stats.
|
|
695
|
+
*/
|
|
696
|
+
pick(target: {
|
|
697
|
+
sessionIndex?: number;
|
|
698
|
+
jobName?: string;
|
|
699
|
+
}): TranscriptScript | undefined;
|
|
700
|
+
/** The 0-based index of the next streaming session in this namespace. */
|
|
701
|
+
nextSessionIndex(): number;
|
|
702
|
+
currentStats(): SpeechStats;
|
|
703
|
+
record(entry: SpeechLogEntry): void;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* Deterministic synthetic audio. Polly's answer stands in for speech: its length grows with
|
|
708
|
+
* the text (60 ms per character) and the bytes are identical on every run.
|
|
709
|
+
*
|
|
710
|
+
* - PCM is a 440 Hz tone, signed 16-bit little-endian mono: always an even byte count.
|
|
711
|
+
* - MP3 is a run of valid MPEG-2 (or 2.5) Layer III frames, mono, 32 kbit/s, at the requested
|
|
712
|
+
* sample rate: 576 samples each, decoding (mpg123, ffmpeg) to silence. A tone would need a
|
|
713
|
+
* real encoder; the frames are what a decoder checks.
|
|
714
|
+
*/
|
|
715
|
+
/** Milliseconds of audio per character of text. */
|
|
716
|
+
declare const MS_PER_CHARACTER = 60;
|
|
717
|
+
/** Duration of the speech standing in for `text`. */
|
|
718
|
+
declare const durationFor: (text: string) => number;
|
|
719
|
+
/** PCM s16le mono tone of `durationMs` at `sampleRate`. */
|
|
720
|
+
declare const pcmTone: (durationMs: number, sampleRate: number) => Uint8Array;
|
|
721
|
+
/** Sample rates {@link mp3Frames} can encode. */
|
|
722
|
+
declare const MP3_SAMPLE_RATES: number[];
|
|
723
|
+
/** Samples per MPEG-2/2.5 Layer III frame. */
|
|
724
|
+
declare const MP3_SAMPLES_PER_FRAME = 576;
|
|
725
|
+
/** One silent Layer III frame: header, zeroed side info (9 bytes, mono), zeroed main data. */
|
|
726
|
+
declare const mp3Frame: (sampleRate: number) => Uint8Array;
|
|
727
|
+
/** MP3 frames covering `durationMs`. */
|
|
728
|
+
declare const mp3Audio: (durationMs: number, sampleRate: number) => Uint8Array;
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* AWS event-stream framing (`application/vnd.amazon.eventstream`), both directions.
|
|
732
|
+
*
|
|
733
|
+
* Every frame is: a 12-byte prelude (total length, headers length, CRC32 of those 8 bytes),
|
|
734
|
+
* the headers, the payload, and a CRC32 of everything before it. `@smithy/eventstream-codec`
|
|
735
|
+
* (the AWS SDKs and the AI SDK) rejects a frame whose lengths or checksums are off by one
|
|
736
|
+
* byte, so this module is exact: it is the only place a frame is built or parsed.
|
|
737
|
+
*
|
|
738
|
+
* The same codec reads what an SDK sends on a bidirectional stream. Those frames arrive
|
|
739
|
+
* wrapped in a SigV4 envelope (`:date` + `:chunk-signature` headers around the encoded
|
|
740
|
+
* inner frame); {@link unwrapSigned} opens it. The signature itself is never verified.
|
|
741
|
+
*/
|
|
742
|
+
/** A typed header value; plain strings encode as type 7 (string). */
|
|
743
|
+
type HeaderValue = {
|
|
744
|
+
type: "boolean";
|
|
745
|
+
value: boolean;
|
|
746
|
+
} | {
|
|
747
|
+
type: "byte";
|
|
748
|
+
value: number;
|
|
749
|
+
} | {
|
|
750
|
+
type: "short";
|
|
751
|
+
value: number;
|
|
752
|
+
} | {
|
|
753
|
+
type: "integer";
|
|
754
|
+
value: number;
|
|
755
|
+
} | {
|
|
756
|
+
type: "long";
|
|
757
|
+
value: bigint;
|
|
758
|
+
} | {
|
|
759
|
+
type: "binary";
|
|
760
|
+
value: Uint8Array;
|
|
761
|
+
} | {
|
|
762
|
+
type: "string";
|
|
763
|
+
value: string;
|
|
764
|
+
} | {
|
|
765
|
+
type: "timestamp";
|
|
766
|
+
value: Date;
|
|
767
|
+
} | {
|
|
768
|
+
type: "uuid";
|
|
769
|
+
value: string;
|
|
770
|
+
};
|
|
771
|
+
type EventStreamMessage = {
|
|
772
|
+
headers: Record<string, HeaderValue>;
|
|
773
|
+
body: Uint8Array;
|
|
774
|
+
};
|
|
775
|
+
/** What {@link encodeMessage} accepts: header values may be bare strings. */
|
|
776
|
+
type MessageInput = {
|
|
777
|
+
headers: Record<string, HeaderValue | string>;
|
|
778
|
+
body?: Uint8Array | string;
|
|
779
|
+
};
|
|
780
|
+
declare class EventStreamError extends Error {
|
|
781
|
+
constructor(message: string);
|
|
782
|
+
}
|
|
783
|
+
/** CRC-32 (IEEE 802.3, the one event-stream uses) of `bytes`. */
|
|
784
|
+
declare const crc32: (bytes: Uint8Array) => number;
|
|
785
|
+
/** One complete frame: prelude, prelude CRC, headers, payload, message CRC. */
|
|
786
|
+
declare const encodeMessage: (message: MessageInput) => Uint8Array;
|
|
787
|
+
/** Parse exactly one frame, checking both lengths and both checksums. */
|
|
788
|
+
declare const decodeMessage: (frame: Uint8Array) => EventStreamMessage;
|
|
789
|
+
/** Splits a byte stream into frames as they complete. */
|
|
790
|
+
declare class FrameReader {
|
|
791
|
+
private buffer;
|
|
792
|
+
/** Add bytes; returns every frame they complete. */
|
|
793
|
+
push(chunk: Uint8Array): EventStreamMessage[];
|
|
794
|
+
/** Bytes of an incomplete frame still waiting for the rest. */
|
|
795
|
+
get pending(): number;
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* The frame inside a SigV4 event envelope (`:chunk-signature`), `null` for the empty
|
|
799
|
+
* end-of-stream envelope, or the frame itself when it is not signed.
|
|
800
|
+
*/
|
|
801
|
+
declare const unwrapSigned: (message: EventStreamMessage) => EventStreamMessage | null;
|
|
802
|
+
/** An `event` frame whose payload is JSON (or raw bytes, for blob event payloads). */
|
|
803
|
+
declare const eventFrame: (eventType: string, payload: unknown, contentType?: string) => Uint8Array;
|
|
804
|
+
/** An `exception` frame, as a service raises one mid-stream. */
|
|
805
|
+
declare const exceptionFrame: (exceptionType: string, body: Record<string, unknown>) => Uint8Array;
|
|
806
|
+
/** An async iterator over the frames of a byte stream (a request or response body). */
|
|
807
|
+
declare function readFrames(body: ReadableStream<Uint8Array> | null): AsyncGenerator<EventStreamMessage>;
|
|
808
|
+
|
|
809
|
+
/**
|
|
810
|
+
* The slice of OpenAPI 3.1 (and JSON Schema 2020-12) Mockingbird understands.
|
|
811
|
+
* Unknown keys (including `x-*` extensions) are preserved on every object.
|
|
812
|
+
*/
|
|
813
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
814
|
+
type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
815
|
+
[key: string]: JsonValue;
|
|
816
|
+
};
|
|
817
|
+
type ReferenceObject = {
|
|
818
|
+
$ref: string;
|
|
819
|
+
description?: string;
|
|
820
|
+
summary?: string;
|
|
821
|
+
};
|
|
822
|
+
type SchemaType = "string" | "number" | "integer" | "boolean" | "object" | "array" | "null";
|
|
823
|
+
type SchemaObject = {
|
|
824
|
+
$ref?: string;
|
|
825
|
+
type?: SchemaType | SchemaType[];
|
|
826
|
+
title?: string;
|
|
827
|
+
description?: string;
|
|
828
|
+
format?: string;
|
|
829
|
+
enum?: JsonValue[];
|
|
830
|
+
const?: JsonValue;
|
|
831
|
+
default?: JsonValue;
|
|
832
|
+
example?: JsonValue;
|
|
833
|
+
examples?: JsonValue[];
|
|
834
|
+
nullable?: boolean;
|
|
835
|
+
deprecated?: boolean;
|
|
836
|
+
readOnly?: boolean;
|
|
837
|
+
writeOnly?: boolean;
|
|
838
|
+
minimum?: number;
|
|
839
|
+
maximum?: number;
|
|
840
|
+
exclusiveMinimum?: number;
|
|
841
|
+
exclusiveMaximum?: number;
|
|
842
|
+
multipleOf?: number;
|
|
843
|
+
minLength?: number;
|
|
844
|
+
maxLength?: number;
|
|
845
|
+
pattern?: string;
|
|
846
|
+
minItems?: number;
|
|
847
|
+
maxItems?: number;
|
|
848
|
+
uniqueItems?: boolean;
|
|
849
|
+
items?: SchemaObject;
|
|
850
|
+
prefixItems?: SchemaObject[];
|
|
851
|
+
minProperties?: number;
|
|
852
|
+
maxProperties?: number;
|
|
853
|
+
required?: string[];
|
|
854
|
+
properties?: Record<string, SchemaObject>;
|
|
855
|
+
additionalProperties?: boolean | SchemaObject;
|
|
856
|
+
propertyNames?: SchemaObject;
|
|
857
|
+
oneOf?: SchemaObject[];
|
|
858
|
+
anyOf?: SchemaObject[];
|
|
859
|
+
allOf?: SchemaObject[];
|
|
860
|
+
not?: SchemaObject;
|
|
861
|
+
discriminator?: {
|
|
862
|
+
propertyName: string;
|
|
863
|
+
mapping?: Record<string, string>;
|
|
864
|
+
};
|
|
865
|
+
[extension: `x-${string}`]: unknown;
|
|
866
|
+
};
|
|
867
|
+
type ParameterLocation = "path" | "query" | "header" | "cookie";
|
|
868
|
+
type ParameterObject = {
|
|
869
|
+
name: string;
|
|
870
|
+
in: ParameterLocation;
|
|
871
|
+
description?: string;
|
|
872
|
+
required?: boolean;
|
|
873
|
+
deprecated?: boolean;
|
|
874
|
+
style?: string;
|
|
875
|
+
explode?: boolean;
|
|
876
|
+
schema?: SchemaObject;
|
|
877
|
+
content?: Record<string, MediaTypeObject>;
|
|
878
|
+
example?: JsonValue;
|
|
879
|
+
[extension: `x-${string}`]: unknown;
|
|
880
|
+
};
|
|
881
|
+
type MediaTypeObject = {
|
|
882
|
+
schema?: SchemaObject;
|
|
883
|
+
example?: JsonValue;
|
|
884
|
+
examples?: Record<string, unknown>;
|
|
885
|
+
encoding?: Record<string, unknown>;
|
|
886
|
+
[extension: `x-${string}`]: unknown;
|
|
887
|
+
};
|
|
888
|
+
type RequestBodyObject = {
|
|
889
|
+
description?: string;
|
|
890
|
+
required?: boolean;
|
|
891
|
+
content: Record<string, MediaTypeObject>;
|
|
892
|
+
[extension: `x-${string}`]: unknown;
|
|
893
|
+
};
|
|
894
|
+
type HeaderObject = {
|
|
895
|
+
description?: string;
|
|
896
|
+
required?: boolean;
|
|
897
|
+
schema?: SchemaObject;
|
|
898
|
+
[extension: `x-${string}`]: unknown;
|
|
899
|
+
};
|
|
900
|
+
type ResponseObject = {
|
|
901
|
+
description: string;
|
|
902
|
+
headers?: Record<string, HeaderObject | ReferenceObject>;
|
|
903
|
+
content?: Record<string, MediaTypeObject>;
|
|
904
|
+
[extension: `x-${string}`]: unknown;
|
|
905
|
+
};
|
|
906
|
+
type ResponsesObject = Record<string, ResponseObject | ReferenceObject>;
|
|
907
|
+
type SecurityRequirementObject = Record<string, string[]>;
|
|
908
|
+
type OperationObject = {
|
|
909
|
+
operationId?: string;
|
|
910
|
+
summary?: string;
|
|
911
|
+
description?: string;
|
|
912
|
+
tags?: string[];
|
|
913
|
+
deprecated?: boolean;
|
|
914
|
+
parameters?: Array<ParameterObject | ReferenceObject>;
|
|
915
|
+
requestBody?: RequestBodyObject | ReferenceObject;
|
|
916
|
+
responses: ResponsesObject;
|
|
917
|
+
security?: SecurityRequirementObject[];
|
|
918
|
+
[extension: `x-${string}`]: unknown;
|
|
919
|
+
};
|
|
920
|
+
declare const HTTP_METHODS: readonly ["get", "put", "post", "delete", "options", "head", "patch", "trace"];
|
|
921
|
+
type HttpMethod = (typeof HTTP_METHODS)[number];
|
|
922
|
+
type PathItemObject = {
|
|
923
|
+
summary?: string;
|
|
924
|
+
description?: string;
|
|
925
|
+
parameters?: Array<ParameterObject | ReferenceObject>;
|
|
926
|
+
[extension: `x-${string}`]: unknown;
|
|
927
|
+
} & Partial<Record<HttpMethod, OperationObject>>;
|
|
928
|
+
type SecuritySchemeObject = {
|
|
929
|
+
type: "apiKey" | "http" | "oauth2" | "openIdConnect" | "mutualTLS";
|
|
930
|
+
description?: string;
|
|
931
|
+
name?: string;
|
|
932
|
+
in?: ParameterLocation;
|
|
933
|
+
scheme?: string;
|
|
934
|
+
bearerFormat?: string;
|
|
935
|
+
flows?: Record<string, unknown>;
|
|
936
|
+
openIdConnectUrl?: string;
|
|
937
|
+
[extension: `x-${string}`]: unknown;
|
|
938
|
+
};
|
|
939
|
+
type ComponentsObject = {
|
|
940
|
+
schemas?: Record<string, SchemaObject>;
|
|
941
|
+
responses?: Record<string, ResponseObject>;
|
|
942
|
+
parameters?: Record<string, ParameterObject>;
|
|
943
|
+
requestBodies?: Record<string, RequestBodyObject>;
|
|
944
|
+
headers?: Record<string, HeaderObject>;
|
|
945
|
+
securitySchemes?: Record<string, SecuritySchemeObject>;
|
|
946
|
+
[extension: `x-${string}`]: unknown;
|
|
947
|
+
};
|
|
948
|
+
type ServerObject = {
|
|
949
|
+
url: string;
|
|
950
|
+
description?: string;
|
|
951
|
+
variables?: Record<string, unknown>;
|
|
952
|
+
[extension: `x-${string}`]: unknown;
|
|
953
|
+
};
|
|
954
|
+
type InfoObject = {
|
|
955
|
+
title: string;
|
|
956
|
+
version: string;
|
|
957
|
+
description?: string;
|
|
958
|
+
[extension: `x-${string}`]: unknown;
|
|
959
|
+
};
|
|
960
|
+
type OpenAPIDocument = {
|
|
961
|
+
openapi: string;
|
|
962
|
+
info: InfoObject;
|
|
963
|
+
servers?: ServerObject[];
|
|
964
|
+
paths: Record<string, PathItemObject>;
|
|
965
|
+
components?: ComponentsObject;
|
|
966
|
+
security?: SecurityRequirementObject[];
|
|
967
|
+
tags?: Array<{
|
|
968
|
+
name: string;
|
|
969
|
+
description?: string;
|
|
970
|
+
}>;
|
|
971
|
+
[extension: `x-${string}`]: unknown;
|
|
972
|
+
};
|
|
973
|
+
|
|
974
|
+
declare const document: OpenAPIDocument;
|
|
975
|
+
type OperationId = "SynthesizeSpeech" | "StartSpeechSynthesisStream" | "StartStreamTranscription" | "TranscribeJsonRpc";
|
|
976
|
+
type SupportedOperationId = "SynthesizeSpeech" | "StartSpeechSynthesisStream" | "StartStreamTranscription" | "TranscribeJsonRpc";
|
|
977
|
+
declare const operationIds: readonly ["SynthesizeSpeech", "StartSpeechSynthesisStream", "StartStreamTranscription", "TranscribeJsonRpc"];
|
|
978
|
+
declare const supportedOperationIds: readonly ["SynthesizeSpeech", "StartSpeechSynthesisStream", "StartStreamTranscription", "TranscribeJsonRpc"];
|
|
979
|
+
|
|
980
|
+
/**
|
|
981
|
+
* Every named Polly / Transcribe misbehaviour our consumer branches on, switched on with
|
|
982
|
+
* `POST /__admin/faults {"preset": "<name>", "count"?: n}`.
|
|
983
|
+
*/
|
|
984
|
+
declare const SPEECH_PRESETS: Record<string, FaultPreset>;
|
|
985
|
+
type SpeechRuntimeOptions = {
|
|
986
|
+
sqlite?: SqliteClient;
|
|
987
|
+
clock?: Clock;
|
|
988
|
+
seed?: number | string;
|
|
989
|
+
adminKey?: string;
|
|
990
|
+
onLog?: (entry: RequestLog) => void;
|
|
991
|
+
settings?: Partial<Settings>;
|
|
992
|
+
/** Transcripts every namespace starts with (and returns to on reset). */
|
|
993
|
+
transcripts?: readonly TranscriptScript[];
|
|
994
|
+
/** Write completed batch transcripts into this S3 (the stack's s3rver); bucket = OutputBucketName. */
|
|
995
|
+
transcriptStore?: Omit<S3Target, "bucket">;
|
|
996
|
+
};
|
|
997
|
+
type SpeechRuntime = ServiceRuntime<SpeechAPI>;
|
|
998
|
+
/**
|
|
999
|
+
* The Polly + Transcribe mock with Mockingbird's full service contract: `/health`,
|
|
1000
|
+
* `/__admin/*`, namespaces by header, by `/ns/<name>` prefix, or by SigV4 access key id
|
|
1001
|
+
* (`PUT /__admin/credentials {"credentials": {"<AWS_ACCESS_KEY_ID>": "<namespace>"}}`), the
|
|
1002
|
+
* mock clock (batch jobs complete on it), fault presets and a metadata-only journal.
|
|
1003
|
+
*/
|
|
1004
|
+
declare const createRuntime: (options?: SpeechRuntimeOptions) => SpeechRuntime;
|
|
1005
|
+
|
|
1006
|
+
declare const SPEECH_NAMESPACE = "aws-speech";
|
|
1007
|
+
/** Every Polly voice id (`@aws-sdk/client-polly` VoiceId). */
|
|
1008
|
+
declare const POLLY_VOICES: readonly ["Aditi", "Adriano", "Ambre", "Amy", "Andres", "Aria", "Arlet", "Arthur", "Astrid", "Ayanda", "Beatrice", "Bianca", "Brian", "Burcu", "Camila", "Carla", "Carmen", "Celine", "Chantal", "Conchita", "Cristiano", "Daniel", "Danielle", "Dora", "Elin", "Emma", "Enrique", "Ewa", "Filiz", "Florian", "Gabrielle", "Geraint", "Giorgio", "Gregory", "Gwyneth", "Hala", "Hannah", "Hans", "Hiujin", "Ida", "Ines", "Isabelle", "Ivy", "Jacek", "Jan", "Jasmine", "Jihye", "Jitka", "Joanna", "Joey", "Justin", "Kajal", "Karl", "Kazuha", "Kendra", "Kevin", "Kimberly", "Laura", "Lea", "Lennart", "Liam", "Lisa", "Liv", "Lorenzo", "Lotte", "Lucia", "Lupe", "Mads", "Maja", "Marlene", "Mathieu", "Matthew", "Maxim", "Mia", "Miguel", "Mizuki", "Naja", "Niamh", "Nicole", "Ola", "Olivia", "Pedro", "Penelope", "Raveena", "Remi", "Ricardo", "Ruben", "Russell", "Ruth", "Sabrina", "Salli", "Seoyeon", "Sergio", "Sofie", "Stephen", "Suvi", "Takumi", "Tatyana", "Thiago", "Tiffany", "Tomoko", "Vicki", "Vitoria", "Zayd", "Zeina", "Zhiyu"];
|
|
1009
|
+
/** A restJson1 error (Polly, Transcribe Streaming): `x-amzn-ErrorType` + `{message}`. */
|
|
1010
|
+
declare const speechError: (status: number, type: string, message: string, requestId?: string) => Response;
|
|
1011
|
+
/** The namespace credential: the SigV4 access key id. */
|
|
1012
|
+
declare const accessKeyCredential: (request: Request) => string | undefined;
|
|
1013
|
+
type SpeechAPIOptions = APIOptions & {
|
|
1014
|
+
settings?: Partial<Settings>;
|
|
1015
|
+
transcripts?: readonly TranscriptScript[];
|
|
1016
|
+
/**
|
|
1017
|
+
* Where completed batch transcripts are written (the stack's local S3), so the app's
|
|
1018
|
+
* own `GetObject` of `TranscriptFileUri` finds them. The bucket is the job's
|
|
1019
|
+
* `OutputBucketName`.
|
|
1020
|
+
*/
|
|
1021
|
+
transcriptStore?: Omit<S3Target, "bucket">;
|
|
1022
|
+
};
|
|
1023
|
+
/**
|
|
1024
|
+
* Stateful mock of Amazon Polly and Amazon Transcribe (streaming and batch).
|
|
1025
|
+
*
|
|
1026
|
+
* Polly answers with deterministic synthetic audio whose length follows the text. Transcribe
|
|
1027
|
+
* never listens: what it "hears" comes from scripted transcripts (`PUT /__admin/transcripts`),
|
|
1028
|
+
* sent as partial results while the audio streams in and a final result when it ends.
|
|
1029
|
+
*/
|
|
1030
|
+
declare class SpeechAPI implements FetchAPI$1 {
|
|
1031
|
+
readonly app: Hono;
|
|
1032
|
+
readonly sqlite: SqliteClient;
|
|
1033
|
+
readonly state: SpeechState;
|
|
1034
|
+
private readonly service;
|
|
1035
|
+
private readonly now;
|
|
1036
|
+
private readonly transcriptStore;
|
|
1037
|
+
private requests;
|
|
1038
|
+
constructor(options?: SpeechAPIOptions);
|
|
1039
|
+
fetch(request: Request): Promise<Response>;
|
|
1040
|
+
reset(): Promise<void>;
|
|
1041
|
+
/** Metadata of every synthesis and transcription so far (never text). */
|
|
1042
|
+
speechLog(): SpeechLogEntry[];
|
|
1043
|
+
jobs(): JobRecord[];
|
|
1044
|
+
stats(): SpeechStats;
|
|
1045
|
+
private requestId;
|
|
1046
|
+
/** Shared checks for both Polly operations; a string is the error. */
|
|
1047
|
+
private checkVoice;
|
|
1048
|
+
private audio;
|
|
1049
|
+
private synthesize;
|
|
1050
|
+
private synthesisStream;
|
|
1051
|
+
private streamTranscription;
|
|
1052
|
+
/** Move a job along the mock clock: IN_PROGRESS → COMPLETED after `jobDurationMs`. */
|
|
1053
|
+
private advance;
|
|
1054
|
+
/** Complete a job (admin or clock), fixing its transcript; writes it to S3 when configured. */
|
|
1055
|
+
complete(name: string, transcript: string | undefined): JobRecord | undefined;
|
|
1056
|
+
/** Fail a job with a reason (admin, or the `transcribe_job_failed` preset). */
|
|
1057
|
+
fail(name: string, reason: string): JobRecord | undefined;
|
|
1058
|
+
private outputKey;
|
|
1059
|
+
/** The transcript JSON Transcribe writes to S3 (the shape our formatter reads). */
|
|
1060
|
+
transcriptDocument(job: JobRecord): Record<string, unknown>;
|
|
1061
|
+
private jobBody;
|
|
1062
|
+
private jsonRpc;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
export { DEFAULT_SETTINGS, EventStreamError, FrameReader, MP3_SAMPLES_PER_FRAME, MP3_SAMPLE_RATES, MS_PER_CHARACTER, POLLY_VOICES, SPEECH_NAMESPACE, SPEECH_PRESETS, SpeechAPI, accessKeyCredential, crc32, createRuntime, decodeMessage, document, durationFor, encodeMessage, eventFrame, exceptionFrame, mp3Audio, mp3Frame, operationIds, pcmTone, readFrames, speechError, supportedOperationIds, unwrapSigned };
|
|
1066
|
+
export type { EventStreamMessage, FetchAPI$1 as FetchAPI, HeaderValue, JobRecord, MessageInput, OperationId, Settings, SpeechAPIOptions, SpeechLogEntry, SpeechRuntime, SpeechRuntimeOptions, SpeechStats, SqliteClient, SupportedOperationId, TranscriptScript };
|