@providerkit/core 0.27.2 → 0.28.1

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 (42) hide show
  1. package/README.md +15 -0
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +3 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/presets.d.ts +50 -0
  7. package/dist/presets.d.ts.map +1 -1
  8. package/dist/presets.js +82 -0
  9. package/dist/presets.js.map +1 -1
  10. package/dist/providers/gemini-speech.d.ts +26 -0
  11. package/dist/providers/gemini-speech.d.ts.map +1 -0
  12. package/dist/providers/gemini-speech.js +171 -0
  13. package/dist/providers/gemini-speech.js.map +1 -0
  14. package/dist/providers/openai-speech.d.ts +23 -0
  15. package/dist/providers/openai-speech.d.ts.map +1 -0
  16. package/dist/providers/openai-speech.js +86 -0
  17. package/dist/providers/openai-speech.js.map +1 -0
  18. package/dist/providers/speech-factory.d.ts +35 -0
  19. package/dist/providers/speech-factory.d.ts.map +1 -0
  20. package/dist/providers/speech-factory.js +47 -0
  21. package/dist/providers/speech-factory.js.map +1 -0
  22. package/dist/speech-core.d.ts +184 -0
  23. package/dist/speech-core.d.ts.map +1 -0
  24. package/dist/speech-core.js +349 -0
  25. package/dist/speech-core.js.map +1 -0
  26. package/dist/speech.d.ts +6 -0
  27. package/dist/speech.d.ts.map +1 -0
  28. package/dist/speech.js +12 -0
  29. package/dist/speech.js.map +1 -0
  30. package/dist/transport.d.ts +42 -0
  31. package/dist/transport.d.ts.map +1 -1
  32. package/dist/transport.js +154 -11
  33. package/dist/transport.js.map +1 -1
  34. package/package.json +6 -1
  35. package/src/index.ts +14 -1
  36. package/src/presets.ts +113 -0
  37. package/src/providers/gemini-speech.ts +234 -0
  38. package/src/providers/openai-speech.ts +125 -0
  39. package/src/providers/speech-factory.ts +85 -0
  40. package/src/speech-core.ts +507 -0
  41. package/src/speech.ts +24 -0
  42. package/src/transport.ts +185 -11
@@ -0,0 +1,349 @@
1
+ // Speech: text in, one audio clip out. A second kind of client next to `Provider`,
2
+ // reached through `@providerkit/core/speech` so a chat-only app never loads it.
3
+ //
4
+ // This file holds what both wires share: the types, the error, and the byte-level
5
+ // checks. Two rules run through all of it.
6
+ //
7
+ // 1. A paid synthesis is never replayed. A speech reply arrives whole, so there is
8
+ // no "nothing was emitted yet" the way a chat stream has: a timeout or a dropped
9
+ // socket may land after the vendor started billing. One request per call.
10
+ // 2. Audio is named by its own bytes, not by what was asked for. Many servers ignore
11
+ // the format they were sent, and "WebM with an MP4 name" is not MP4.
12
+ import { ProviderError, streamError } from "./errors.js";
13
+ import { withDeadline } from "./transport.js";
14
+ export const SPEECH_FORMATS = ["wav", "pcm", "mp3", "opus", "aac", "flac"];
15
+ export const DEFAULT_SPEECH_LIMITS = {
16
+ maxInputChars: 4_096,
17
+ maxAudioBytes: 32 * 1024 * 1024,
18
+ timeoutMs: 120_000,
19
+ };
20
+ /**
21
+ * A reply that arrived but holds no usable audio, or a failure the provider
22
+ * reported inside a 200. Carries the usage the provider stated for it, because it
23
+ * billed that: a caller that drops this loses the only record of the charge.
24
+ * Plain `ProviderError`s carry no usage.
25
+ */
26
+ export class SpeechError extends ProviderError {
27
+ usage;
28
+ constructor(provider, kind, message, opts = {}) {
29
+ const { usage, ...rest } = opts;
30
+ super(provider, kind, message, rest);
31
+ this.name = "SpeechError";
32
+ this.usage = usage;
33
+ }
34
+ }
35
+ /** @internal Positive integers or a RangeError, at build time, never mid-call. */
36
+ export function resolveLimits(config) {
37
+ const limits = {
38
+ maxInputChars: config.maxInputChars ?? DEFAULT_SPEECH_LIMITS.maxInputChars,
39
+ maxAudioBytes: config.maxAudioBytes ?? DEFAULT_SPEECH_LIMITS.maxAudioBytes,
40
+ timeoutMs: config.timeoutMs ?? DEFAULT_SPEECH_LIMITS.timeoutMs,
41
+ };
42
+ for (const [name, value] of Object.entries(limits)) {
43
+ if (!Number.isSafeInteger(value) || value < 1) {
44
+ throw new RangeError(`[providerkit] ${name} must be a positive integer`);
45
+ }
46
+ }
47
+ return limits;
48
+ }
49
+ const refuse = (provider, code, message, kind = "invalid") => new ProviderError(provider, kind, `${provider}: ${message}`, { code, shouldRetry: false });
50
+ /** Space to tilde. Anything else in a header value is refused or altered by a runtime. */
51
+ const HEADER_SAFE = /^[\x20-\x7e]*$/;
52
+ /**
53
+ * @internal Trim, bound and fill in defaults. Throws BEFORE any request, and never
54
+ * puts the text or the key in the message: they are the caller's, and may be private.
55
+ */
56
+ export function prepareSpeech(provider, request, defaults) {
57
+ if (!HEADER_SAFE.test(defaults.apiKey)) {
58
+ throw refuse(provider, "key_invalid", "the API key holds a character that cannot be sent in a header (a line break or a character outside plain ASCII). Paste the key again", "auth");
59
+ }
60
+ const text = typeof request.text === "string" ? request.text.trim() : "";
61
+ if (!text)
62
+ throw refuse(provider, "text_empty", "there is no text to speak");
63
+ if (text.length > defaults.maxInputChars) {
64
+ throw refuse(provider, "text_too_long", `the text is ${text.length} characters and the limit is ${defaults.maxInputChars}`);
65
+ }
66
+ const voice = (request.voice ?? defaults.voice)?.trim();
67
+ if (!voice)
68
+ throw refuse(provider, "voice_required", "this provider needs a voice name");
69
+ const format = request.format ?? defaults.format ?? "wav";
70
+ if (!defaults.formats.includes(format)) {
71
+ throw refuse(provider, "format_unsupported", `this provider cannot make ${String(format)}. It makes ${defaults.formats.join(", ")}`);
72
+ }
73
+ return { text, voice, format };
74
+ }
75
+ const REPLAY_UNSAFE = new Set([
76
+ "network",
77
+ "timeout",
78
+ "overload",
79
+ "unknown",
80
+ ]);
81
+ function neverRetry(err) {
82
+ const opts = {
83
+ status: err.status,
84
+ code: err.code,
85
+ retryAfterMs: err.retryAfterMs,
86
+ resetAtMs: err.resetAtMs,
87
+ window: err.window,
88
+ shouldRetry: false,
89
+ body: err.body,
90
+ cause: err.cause,
91
+ };
92
+ return err instanceof SpeechError
93
+ ? new SpeechError(err.provider, err.kind, err.message, { ...opts, usage: err.usage })
94
+ : new ProviderError(err.provider, err.kind, err.message, opts);
95
+ }
96
+ /**
97
+ * @internal The "could the vendor already have billed this?" rule, applied in one
98
+ * place so a new failure path cannot forget it.
99
+ *
100
+ * - The caller's Stop comes back untouched.
101
+ * - A timeout, a dead socket, a 5xx or anything unclassified may have landed after
102
+ * the vendor started work, so it is marked `shouldRetry: false`, and a vendor's
103
+ * `x-should-retry: true` does not undo that: the header says the vendor thinks a
104
+ * resend is fine, not that the first call was not billed.
105
+ * - Every other kind keeps what it came with. A 429 means the vendor refused before
106
+ * doing any work, so sending it again is safe, and `Retry-After` is honoured by
107
+ * the caller's own retry. `x-should-retry` is believed there, in either direction.
108
+ */
109
+ export function noReplay(provider, error, signal) {
110
+ if (signal?.aborted)
111
+ return error;
112
+ const err = ProviderError.from(provider, error);
113
+ return REPLAY_UNSAFE.has(err.kind) && err.shouldRetry !== false ? neverRetry(err) : err;
114
+ }
115
+ /**
116
+ * @internal The one place a call runs: under one deadline, once, and with the
117
+ * no-replay rule applied to whatever it throws. Both wires go through here.
118
+ */
119
+ export async function synthesizeOnce(provider, timeoutMs, request, call) {
120
+ try {
121
+ return await withDeadline(provider, timeoutMs, request.signal, call);
122
+ }
123
+ catch (error) {
124
+ throw noReplay(provider, error, request.signal);
125
+ }
126
+ }
127
+ // ── failures ──────────────────────────────────────────────────────────────
128
+ /** @internal A reply that arrived but cannot be used. Never retried: it was billed. */
129
+ export function unusable(provider, kind, code, message, usage) {
130
+ return new SpeechError(provider, kind, `${provider}: ${message}`, {
131
+ code,
132
+ shouldRetry: false,
133
+ ...(usage ? { usage } : {}),
134
+ });
135
+ }
136
+ /**
137
+ * @internal A failure the provider reported inside a 200 body (a gateway that
138
+ * answers 200 with a JSON error, an Interactions reply that says it failed). It is
139
+ * classified like any other failure, with the same words-over-status rules, and
140
+ * then the provider's words are dropped: they can echo the text that was sent.
141
+ */
142
+ export function inBandFailure(provider, envelope, usage) {
143
+ const found = streamError(provider, envelope);
144
+ return new SpeechError(provider, found.kind, `${provider}: the provider reported ${found.kind}`, {
145
+ status: found.status,
146
+ retryAfterMs: found.retryAfterMs,
147
+ resetAtMs: found.resetAtMs,
148
+ window: found.window,
149
+ ...(usage ? { usage } : {}),
150
+ });
151
+ }
152
+ /** @internal */
153
+ export function asRecord(value) {
154
+ return typeof value === "object" && value !== null && !Array.isArray(value)
155
+ ? value
156
+ : undefined;
157
+ }
158
+ // ── bytes ─────────────────────────────────────────────────────────────────
159
+ /**
160
+ * @internal Strict base64 to bytes: the length is a multiple of 4, the alphabet is
161
+ * the standard one, padding sits only at the end. `atob` alone is too forgiving:
162
+ * it drops whitespace and accepts missing padding. `undefined` on anything else.
163
+ */
164
+ export function decodeBase64(data) {
165
+ if (data.length === 0 || data.length % 4 !== 0 || !/^[A-Za-z0-9+/]+={0,2}$/.test(data)) {
166
+ return undefined;
167
+ }
168
+ let binary;
169
+ try {
170
+ binary = atob(data);
171
+ }
172
+ catch {
173
+ return undefined;
174
+ }
175
+ const bytes = new Uint8Array(binary.length);
176
+ for (let i = 0; i < binary.length; i++)
177
+ bytes[i] = binary.charCodeAt(i);
178
+ return bytes;
179
+ }
180
+ function ascii(bytes, at, length) {
181
+ if (at < 0 || at + length > bytes.byteLength)
182
+ return "";
183
+ let out = "";
184
+ for (let i = 0; i < length; i++)
185
+ out += String.fromCharCode(bytes[at + i]);
186
+ return out;
187
+ }
188
+ /** The first three bytes of an MPEG audio frame: Layer III is mp3, and a zero layer
189
+ * field behind twelve sync bits is AAC in ADTS. Layer I and II are neither. */
190
+ function mpegAudio(b0, b1, b2) {
191
+ if (b0 !== 0xff || b1 === undefined || b2 === undefined || (b1 & 0xe0) !== 0xe0) {
192
+ return undefined;
193
+ }
194
+ const layer = (b1 >> 1) & 3;
195
+ if (layer === 0)
196
+ return (b1 & 0xf0) === 0xf0 && ((b2 >> 2) & 15) < 13 ? "aac" : undefined;
197
+ const reservedVersion = ((b1 >> 3) & 3) === 1;
198
+ const reservedBitrate = b2 >> 4 === 15;
199
+ const reservedRate = ((b2 >> 2) & 3) === 3;
200
+ return layer === 1 && !reservedVersion && !reservedBitrate && !reservedRate ? "mp3" : undefined;
201
+ }
202
+ /**
203
+ * @internal Which container the first bytes say this is, or `undefined`. Raw PCM
204
+ * has no signature, so it is never returned here. ADTS AAC and mp3 share a sync
205
+ * pattern and are told apart by their layer field.
206
+ */
207
+ export function sniffFormat(bytes) {
208
+ if (ascii(bytes, 0, 4) === "RIFF" && ascii(bytes, 8, 4) === "WAVE")
209
+ return "wav";
210
+ if (ascii(bytes, 0, 4) === "fLaC")
211
+ return "flac";
212
+ if (ascii(bytes, 0, 4) === "OggS") {
213
+ // The first packet starts after the page's 27-byte header and its segment table.
214
+ return ascii(bytes, 27 + (bytes[26] ?? 0), 8) === "OpusHead" ? "opus" : undefined;
215
+ }
216
+ let at = 0;
217
+ if (ascii(bytes, 0, 3) === "ID3" && bytes.byteLength >= 10) {
218
+ // An ID3v2 tag in front of the audio: a 10-byte header whose size is four
219
+ // 7-bit bytes, plus a 10-byte footer when flag bit 4 says there is one.
220
+ const size = ((bytes[6] & 0x7f) << 21) |
221
+ ((bytes[7] & 0x7f) << 14) |
222
+ ((bytes[8] & 0x7f) << 7) |
223
+ (bytes[9] & 0x7f);
224
+ at = 10 + size + (bytes[5] & 0x10 ? 10 : 0);
225
+ }
226
+ return mpegAudio(bytes[at], bytes[at + 1], bytes[at + 2]);
227
+ }
228
+ /**
229
+ * Read a WAV file's own numbers, strictly. PCM only (format tag 1). The RIFF size
230
+ * is exact, every chunk sits inside the file, there is one `fmt ` before one
231
+ * non-empty `data` that holds whole frames, and nothing trails. Extra chunks such
232
+ * as `LIST` are skipped, and odd-sized chunks carry their pad byte. `undefined`
233
+ * on anything else. It reports what the bytes say; whether 24 kHz mono is
234
+ * acceptable is the caller's policy.
235
+ */
236
+ export function readWav(bytes) {
237
+ if (ascii(bytes, 0, 4) !== "RIFF" || ascii(bytes, 8, 4) !== "WAVE")
238
+ return undefined;
239
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
240
+ if (view.getUint32(4, true) !== bytes.byteLength - 8)
241
+ return undefined;
242
+ let fmt;
243
+ let dataBytes;
244
+ let offset = 12;
245
+ let chunks = 0;
246
+ while (offset < bytes.byteLength) {
247
+ if (++chunks > 1024 || bytes.byteLength - offset < 8)
248
+ return undefined;
249
+ const name = ascii(bytes, offset, 4);
250
+ const size = view.getUint32(offset + 4, true);
251
+ const start = offset + 8;
252
+ const paddedEnd = start + size + (size % 2);
253
+ if (start + size > bytes.byteLength || paddedEnd > bytes.byteLength)
254
+ return undefined;
255
+ if (name === "fmt ") {
256
+ if (fmt || (size !== 16 && size !== 18))
257
+ return undefined;
258
+ const channels = view.getUint16(start + 2, true);
259
+ const sampleRate = view.getUint32(start + 4, true);
260
+ const blockAlign = view.getUint16(start + 12, true);
261
+ const bitsPerSample = view.getUint16(start + 14, true);
262
+ if (view.getUint16(start, true) !== 1 ||
263
+ channels < 1 ||
264
+ sampleRate < 1 ||
265
+ bitsPerSample === 0 ||
266
+ bitsPerSample % 8 !== 0 ||
267
+ blockAlign !== (channels * bitsPerSample) / 8 ||
268
+ view.getUint32(start + 8, true) !== sampleRate * blockAlign ||
269
+ (size === 18 && view.getUint16(start + 16, true) !== 0)) {
270
+ return undefined;
271
+ }
272
+ fmt = { sampleRate, channels, bitsPerSample, blockAlign };
273
+ }
274
+ else if (name === "data") {
275
+ if (!fmt || dataBytes !== undefined || size === 0 || size % fmt.blockAlign !== 0) {
276
+ return undefined;
277
+ }
278
+ dataBytes = size;
279
+ }
280
+ else if (name === "RIFF" || name === "RIFX" || name === "RF64") {
281
+ return undefined;
282
+ }
283
+ offset = paddedEnd;
284
+ }
285
+ if (!fmt || dataBytes === undefined)
286
+ return undefined;
287
+ const frames = dataBytes / fmt.blockAlign;
288
+ const { blockAlign: _blockAlign, ...info } = fmt;
289
+ return { ...info, frames, durationMs: (frames / fmt.sampleRate) * 1000 };
290
+ }
291
+ const MIME = {
292
+ wav: "audio/wav",
293
+ mp3: "audio/mpeg",
294
+ opus: "audio/ogg; codecs=opus",
295
+ aac: "audio/aac",
296
+ flac: "audio/flac",
297
+ };
298
+ /**
299
+ * @internal Bytes in, `SpeechResult` out. An empty body is `empty_audio`. A
300
+ * recognised container is accepted whatever was asked for, and `format` says what
301
+ * it really is. Raw PCM is the one case with no signature to read, so it is
302
+ * accepted only when PCM was asked for and the length is whole samples. Anything
303
+ * else is `bad_audio`.
304
+ *
305
+ * A WAV is labelled by its signature. Its numbers (rate, channels, duration) are
306
+ * filled in only when the header checks out, so a server whose header lies still
307
+ * gets its audio through, without a duration anyone could take as measured.
308
+ */
309
+ export function describeAudio(provider, bytes, wanted, extras) {
310
+ if (bytes.byteLength === 0) {
311
+ throw unusable(provider, "overload", "empty_audio", "the reply holds no audio", extras.usage);
312
+ }
313
+ const base = {
314
+ bytes,
315
+ characters: extras.characters,
316
+ model: extras.model,
317
+ voice: extras.voice,
318
+ ...(extras.usage ? { usage: extras.usage } : {}),
319
+ };
320
+ const sniffed = sniffFormat(bytes);
321
+ if (sniffed === "wav") {
322
+ const wav = readWav(bytes);
323
+ return {
324
+ ...base,
325
+ format: "wav",
326
+ mimeType: MIME.wav,
327
+ ...(wav
328
+ ? { sampleRate: wav.sampleRate, channels: wav.channels, durationMs: wav.durationMs }
329
+ : {}),
330
+ };
331
+ }
332
+ if (sniffed)
333
+ return { ...base, format: sniffed, mimeType: MIME[sniffed] };
334
+ if (wanted !== "pcm" || bytes.byteLength % 2 !== 0) {
335
+ throw unusable(provider, "unknown", "bad_audio", "the reply is not audio this package recognises", extras.usage);
336
+ }
337
+ const { sampleRate, channels } = extras;
338
+ return {
339
+ ...base,
340
+ format: "pcm",
341
+ mimeType: sampleRate ? `audio/L16;rate=${sampleRate}` : "audio/L16",
342
+ ...(sampleRate ? { sampleRate } : {}),
343
+ ...(channels ? { channels } : {}),
344
+ ...(sampleRate && channels
345
+ ? { durationMs: (bytes.byteLength / 2 / channels / sampleRate) * 1000 }
346
+ : {}),
347
+ };
348
+ }
349
+ //# sourceMappingURL=speech-core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speech-core.js","sourceRoot":"","sources":["../src/speech-core.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,gFAAgF;AAChF,EAAE;AACF,kFAAkF;AAClF,2CAA2C;AAC3C,EAAE;AACF,mFAAmF;AACnF,oFAAoF;AACpF,6EAA6E;AAC7E,qFAAqF;AACrF,wEAAwE;AACxE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAkB,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAU,CAAC;AAkEpF,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,aAAa,EAAE,KAAK;IACpB,aAAa,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;IAC/B,SAAS,EAAE,OAAO;CACuB,CAAC;AAI5C;;;;;GAKG;AACH,MAAM,OAAO,WAAY,SAAQ,aAAa;IACnC,KAAK,CAAe;IAE7B,YACE,QAAgB,EAChB,IAAe,EACf,OAAe,EACf,OAAuD,EAAE;QAEzD,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;QAChC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED,kFAAkF;AAClF,MAAM,UAAU,aAAa,CAAC,MAAoB;IAChD,MAAM,MAAM,GAAG;QACb,aAAa,EAAE,MAAM,CAAC,aAAa,IAAI,qBAAqB,CAAC,aAAa;QAC1E,aAAa,EAAE,MAAM,CAAC,aAAa,IAAI,qBAAq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,OAAO,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;IAC1E,IAAI,MAAM,KAAK,KAAK,IAAI,KAAK,CAAC,UAAU,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;QACnD,MAAM,QAAQ,CACZ,QAAQ,EACR,SAAS,EACT,WAAW,EACX,gDAAgD,EAChD,MAAM,CAAC,KAAK,CACb,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IACxC,OAAO;QACL,GAAG,IAAI;QACP,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,kBAAkB,UAAU,EAAE,CAAC,CAAC,CAAC,WAAW;QACnE,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACrC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACjC,GAAG,CAAC,UAAU,IAAI,QAAQ;YACxB,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,GAAG,QAAQ,GAAG,UAAU,CAAC,GAAG,IAAI,EAAE;YACvE,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { DEFAULT_SPEECH_LIMITS, readWav, SPEECH_FORMATS, SpeechError, type SpeechFormat, type SpeechLimits, type SpeechProvider, type SpeechRequest, type SpeechResult, type SpeechShape, type SpeechUsage, type WavInfo, } from "./speech-core.ts";
2
+ export * from "./providers/openai-speech.ts";
3
+ export * from "./providers/gemini-speech.ts";
4
+ export * from "./providers/speech-factory.ts";
5
+ export { SPEECH_PRESET_IDS, type PresetSpeech } from "./presets.ts";
6
+ //# sourceMappingURL=speech.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speech.d.ts","sourceRoot":"","sources":["../src/speech.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,qBAAqB,EACrB,OAAO,EACP,cAAc,EACd,WAAW,EACX,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,OAAO,GACb,MAAM,kBAAkB,CAAC;AAC1B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC"}
package/dist/speech.js ADDED
@@ -0,0 +1,12 @@
1
+ // `@providerkit/core/speech`: text to speech, a second kind of client next to the chat
2
+ // `Provider`. It is its own entry point, and `index.ts` does not export it, so an app
3
+ // that only chats loads none of the speech code. Same reason `decisions.ts` stands apart.
4
+ //
5
+ // Named, not `export *`: speech-core.ts also holds helpers the two wires share, and a
6
+ // helper exported here is one this package can never change without a major version.
7
+ export { DEFAULT_SPEECH_LIMITS, readWav, SPEECH_FORMATS, SpeechError, } from "./speech-core.js";
8
+ export * from "./providers/openai-speech.js";
9
+ export * from "./providers/gemini-speech.js";
10
+ export * from "./providers/speech-factory.js";
11
+ export { SPEECH_PRESET_IDS } from "./presets.js";
12
+ //# sourceMappingURL=speech.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speech.js","sourceRoot":"","sources":["../src/speech.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,sFAAsF;AACtF,0FAA0F;AAC1F,EAAE;AACF,sFAAsF;AACtF,qFAAqF;AACrF,OAAO,EACL,qBAAqB,EACrB,OAAO,EACP,cAAc,EACd,WAAW,GASZ,MAAM,kBAAkB,CAAC;AAC1B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAqB,MAAM,cAAc,CAAC"}
@@ -18,6 +18,13 @@ export interface RequestInit_ {
18
18
  onRateLimit?: (reading: RateLimitReading) => void;
19
19
  /** Whether the turn already stated its finish. See `SseHooks.finished`. */
20
20
  finished?: () => boolean;
21
+ /**
22
+ * Set `"error"` on any call that carries a credential to a host the user typed.
23
+ * A cross-origin redirect keeps custom headers such as `x-goog-api-key`, so a
24
+ * wrong or hostile address would be handed the key. The redirect then fails
25
+ * the call instead of following. Absent: the runtime's default (follow).
26
+ */
27
+ redirect?: RequestRedirect;
21
28
  }
22
29
  export interface SseHooks {
23
30
  /** Every read of the body, keep-alives and partial frames included: the
@@ -54,6 +61,12 @@ export interface SseHooks {
54
61
  export declare const MAX_SSE_FRAME_CHARS: number;
55
62
  /** Join a base URL and a path without doubling or dropping the slash. */
56
63
  export declare function apiUrl(baseUrl: string, path: string): string;
64
+ /**
65
+ * `path` under the API version a base URL does not already carry: `/v1` (or
66
+ * `version`) in front, unless the base already ends in a version segment such
67
+ * as `/v1` or `/v4`. The rule the chat adapters each keep inline.
68
+ */
69
+ export declare function versionedPath(baseUrl: string, path: string, version?: string): string;
57
70
  /**
58
71
  * How long the provider says to wait, read from the RESPONSE rather than from
59
72
  * a thrown error. Headers are authoritative: `Retry-After` first, then the
@@ -65,6 +78,35 @@ export declare function retryAfterFromHeaders(headers: Headers, now?: number): n
65
78
  export declare function getJson<T = unknown>(opts: Omit<RequestInit_, "body">): Promise<T>;
66
79
  /** POST and parse one JSON response. For the endpoints that do not stream. */
67
80
  export declare function postJson<T = unknown>(opts: RequestInit_): Promise<T>;
81
+ /**
82
+ * Read a whole body, at most `maxBytes`. A `Content-Length` over the cap cancels
83
+ * before a byte is read, and a body that outgrows the cap cancels mid-read:
84
+ * `invalid` with `response_too_large`, and `shouldRetry: false`, because the cap
85
+ * is the caller's and a replay meets it again. A read that dies is `network`,
86
+ * unless the caller's own `signal` aborted it, which passes through untouched.
87
+ */
88
+ export declare function readBounded(res: Response, maxBytes: number, provider: string, signal?: AbortSignal): Promise<Uint8Array>;
89
+ /**
90
+ * POST and return the raw body, bounded. For the endpoints that answer with
91
+ * bytes (audio) or with JSON too large to trust. Same envelope and error
92
+ * classification as `postJson`. `redactErrors` keeps the provider's words out of
93
+ * a failure, and the request's own words too (the full URL, the runtime's rejection):
94
+ * the kind, status and retry hints survive, the text does not.
95
+ */
96
+ export declare function postBytes(opts: RequestInit_ & {
97
+ maxBytes: number;
98
+ redactErrors?: boolean;
99
+ }): Promise<{
100
+ bytes: Uint8Array;
101
+ contentType: string;
102
+ }>;
103
+ /**
104
+ * Run a call that does not stream under one deadline, headers and body together.
105
+ * The caller's Stop passes through exactly as it arrived; only OUR deadline
106
+ * becomes `timeout` (invariant 2). A signal that is already aborted never starts
107
+ * the call.
108
+ */
109
+ export declare function withDeadline<T>(provider: string, timeoutMs: number, signal: AbortSignal | undefined, run: (signal: AbortSignal) => Promise<T>): Promise<T>;
68
110
  /**
69
111
  * Yield each `data:` payload of an SSE body, trimmed, plus the bare JSON
70
112
  * object a vendor appends outside the framing, which is only ever an error
@@ -1 +1 @@
1
- {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAOA,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,iBAAiB,CAAC;AAEzB,MAAM,WAAW,YAAY;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,EAAE,OAAO,CAAC;IACd,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,+EAA+E;IAC/E,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB;wEACoE;IACpE,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC;IACxB,mEAAmE;IACnE,MAAM,C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