@providerkit/core 0.27.1 → 0.28.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/README.md +15 -0
- package/dist/auth/with-token.d.ts +3 -1
- package/dist/auth/with-token.d.ts.map +1 -1
- package/dist/auth/with-token.js +23 -4
- package/dist/auth/with-token.js.map +1 -1
- package/dist/errors.d.ts +2 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +6 -0
- package/dist/errors.js.map +1 -1
- package/dist/fallback.d.ts +6 -4
- package/dist/fallback.d.ts.map +1 -1
- package/dist/fallback.js +13 -7
- package/dist/fallback.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/key-pool.d.ts.map +1 -1
- package/dist/key-pool.js +3 -5
- package/dist/key-pool.js.map +1 -1
- package/dist/presets.d.ts +50 -0
- package/dist/presets.d.ts.map +1 -1
- package/dist/presets.js +82 -0
- package/dist/presets.js.map +1 -1
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +2 -1
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/factory.js +4 -1
- package/dist/providers/factory.js.map +1 -1
- package/dist/providers/gemini-speech.d.ts +25 -0
- package/dist/providers/gemini-speech.d.ts.map +1 -0
- package/dist/providers/gemini-speech.js +172 -0
- package/dist/providers/gemini-speech.js.map +1 -0
- package/dist/providers/gemini.d.ts.map +1 -1
- package/dist/providers/gemini.js +4 -1
- package/dist/providers/gemini.js.map +1 -1
- package/dist/providers/openai-speech.d.ts +23 -0
- package/dist/providers/openai-speech.d.ts.map +1 -0
- package/dist/providers/openai-speech.js +86 -0
- package/dist/providers/openai-speech.js.map +1 -0
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +2 -1
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/responses.d.ts.map +1 -1
- package/dist/providers/responses.js +2 -1
- package/dist/providers/responses.js.map +1 -1
- package/dist/providers/speech-factory.d.ts +35 -0
- package/dist/providers/speech-factory.d.ts.map +1 -0
- package/dist/providers/speech-factory.js +47 -0
- package/dist/providers/speech-factory.js.map +1 -0
- package/dist/speech-core.d.ts +184 -0
- package/dist/speech-core.d.ts.map +1 -0
- package/dist/speech-core.js +349 -0
- package/dist/speech-core.js.map +1 -0
- package/dist/speech.d.ts +6 -0
- package/dist/speech.d.ts.map +1 -0
- package/dist/speech.js +12 -0
- package/dist/speech.js.map +1 -0
- package/dist/transport.d.ts +42 -0
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +154 -11
- package/dist/transport.js.map +1 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +6 -1
- package/src/auth/with-token.ts +24 -7
- package/src/errors.ts +7 -0
- package/src/fallback.ts +40 -18
- package/src/index.ts +14 -1
- package/src/key-pool.ts +38 -37
- package/src/presets.ts +113 -0
- package/src/providers/anthropic.ts +8 -1
- package/src/providers/factory.ts +4 -1
- package/src/providers/gemini-speech.ts +232 -0
- package/src/providers/gemini.ts +10 -1
- package/src/providers/openai-speech.ts +125 -0
- package/src/providers/openai.ts +8 -1
- package/src/providers/responses.ts +8 -1
- package/src/providers/speech-factory.ts +85 -0
- package/src/speech-core.ts +507 -0
- package/src/speech.ts +24 -0
- package/src/transport.ts +185 -11
- package/src/types.ts +10 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { ProviderError, type ErrorKind } from "./errors.ts";
|
|
2
|
+
import type { TokenUsage } from "./types.ts";
|
|
3
|
+
export declare const SPEECH_FORMATS: readonly ["wav", "pcm", "mp3", "opus", "aac", "flac"];
|
|
4
|
+
export type SpeechFormat = (typeof SPEECH_FORMATS)[number];
|
|
5
|
+
/** Which wire speaks. A third shape is one new file and one preset row. */
|
|
6
|
+
export type SpeechShape = "openai" | "gemini";
|
|
7
|
+
export interface SpeechRequest {
|
|
8
|
+
/** What to say. Trimmed first. Empty is refused before any request. */
|
|
9
|
+
text: string;
|
|
10
|
+
/** The voice as the endpoint spells it ("Kore", "alloy"). Absent: the provider's default. */
|
|
11
|
+
voice?: string;
|
|
12
|
+
/** Absent: the provider's default format, else "wav". */
|
|
13
|
+
format?: SpeechFormat;
|
|
14
|
+
/** The caller's Stop. Never retried and never turned into a timeout. */
|
|
15
|
+
signal?: AbortSignal;
|
|
16
|
+
}
|
|
17
|
+
/** Token counts the provider stated. `totalTokens` can exceed input plus output:
|
|
18
|
+
* the gap is what the provider counts and does not break out. */
|
|
19
|
+
export interface SpeechUsage extends TokenUsage {
|
|
20
|
+
totalTokens?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface SpeechResult {
|
|
23
|
+
bytes: Uint8Array;
|
|
24
|
+
/** Read from the bytes, so it can differ from the format asked for. */
|
|
25
|
+
format: SpeechFormat;
|
|
26
|
+
/** The media type of `format`. */
|
|
27
|
+
mimeType: string;
|
|
28
|
+
/** Hz. Only when the bytes (a WAV header) or the request state it. */
|
|
29
|
+
sampleRate?: number;
|
|
30
|
+
/** Only when the bytes or the provider state it. */
|
|
31
|
+
channels?: number;
|
|
32
|
+
/** Exact, from a WAV header that checks out. Absent for every other format:
|
|
33
|
+
* measuring those takes a decoder, and a guess here would be wrong in the ledger. */
|
|
34
|
+
durationMs?: number;
|
|
35
|
+
/** Characters sent after trimming, for endpoints billed per character. */
|
|
36
|
+
characters: number;
|
|
37
|
+
/** Only when the provider reported it. Never estimated. */
|
|
38
|
+
usage?: SpeechUsage;
|
|
39
|
+
/** The model and voice that were asked for. */
|
|
40
|
+
model: string;
|
|
41
|
+
voice: string;
|
|
42
|
+
}
|
|
43
|
+
export interface SpeechProvider {
|
|
44
|
+
readonly id: string;
|
|
45
|
+
readonly model: string;
|
|
46
|
+
/**
|
|
47
|
+
* Exactly one HTTP request. No retry, no fallback, no second key. Throws a
|
|
48
|
+
* `ProviderError`; a reply that arrived but holds no usable audio throws a
|
|
49
|
+
* `SpeechError`, which keeps the usage the provider billed for it.
|
|
50
|
+
*/
|
|
51
|
+
synthesize(request: SpeechRequest): Promise<SpeechResult>;
|
|
52
|
+
}
|
|
53
|
+
export interface SpeechLimits {
|
|
54
|
+
/** Longest `text`, in UTF-16 units (JavaScript's `.length`). Default 4,096.
|
|
55
|
+
* Over it is refused before any request. Never silently cut. */
|
|
56
|
+
maxInputChars?: number;
|
|
57
|
+
/** Largest audio accepted, in bytes. Default 32 MiB. */
|
|
58
|
+
maxAudioBytes?: number;
|
|
59
|
+
/** One deadline for the whole call, headers and body. Default 120,000. */
|
|
60
|
+
timeoutMs?: number;
|
|
61
|
+
}
|
|
62
|
+
export declare const DEFAULT_SPEECH_LIMITS: {
|
|
63
|
+
readonly maxInputChars: 4096;
|
|
64
|
+
readonly maxAudioBytes: number;
|
|
65
|
+
readonly timeoutMs: 120000;
|
|
66
|
+
};
|
|
67
|
+
type ProviderErrorOptions = NonNullable<ConstructorParameters<typeof ProviderError>[3]>;
|
|
68
|
+
/**
|
|
69
|
+
* A reply that arrived but holds no usable audio, or a failure the provider
|
|
70
|
+
* reported inside a 200. Carries the usage the provider stated for it, because it
|
|
71
|
+
* billed that: a caller that drops this loses the only record of the charge.
|
|
72
|
+
* Plain `ProviderError`s carry no usage.
|
|
73
|
+
*/
|
|
74
|
+
export declare class SpeechError extends ProviderError {
|
|
75
|
+
readonly usage?: SpeechUsage;
|
|
76
|
+
constructor(provider: string, kind: ErrorKind, message: string, opts?: ProviderErrorOptions & {
|
|
77
|
+
usage?: SpeechUsage;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/** @internal Positive integers or a RangeError, at build time, never mid-call. */
|
|
81
|
+
export declare function resolveLimits(config: SpeechLimits): Required<SpeechLimits>;
|
|
82
|
+
/**
|
|
83
|
+
* @internal Trim, bound and fill in defaults. Throws BEFORE any request, and never
|
|
84
|
+
* puts the text or the key in the message: they are the caller's, and may be private.
|
|
85
|
+
*/
|
|
86
|
+
export declare function prepareSpeech(provider: string, request: SpeechRequest, defaults: {
|
|
87
|
+
/** Checked, never echoed. A key with a line break, a non-Latin-1 character or a zero-width
|
|
88
|
+
* one pasted in makes the runtime reject the header and quote the value in its error. */
|
|
89
|
+
apiKey: string;
|
|
90
|
+
voice?: string;
|
|
91
|
+
format?: SpeechFormat;
|
|
92
|
+
maxInputChars: number;
|
|
93
|
+
/** What this wire can make. */
|
|
94
|
+
formats: readonly SpeechFormat[];
|
|
95
|
+
}): {
|
|
96
|
+
text: string;
|
|
97
|
+
voice: string;
|
|
98
|
+
format: SpeechFormat;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* @internal The "could the vendor already have billed this?" rule, applied in one
|
|
102
|
+
* place so a new failure path cannot forget it.
|
|
103
|
+
*
|
|
104
|
+
* - The caller's Stop comes back untouched.
|
|
105
|
+
* - A timeout, a dead socket, a 5xx or anything unclassified may have landed after
|
|
106
|
+
* the vendor started work, so it is marked `shouldRetry: false`, and a vendor's
|
|
107
|
+
* `x-should-retry: true` does not undo that: the header says the vendor thinks a
|
|
108
|
+
* resend is fine, not that the first call was not billed.
|
|
109
|
+
* - Every other kind keeps what it came with. A 429 means the vendor refused before
|
|
110
|
+
* doing any work, so sending it again is safe, and `Retry-After` is honoured by
|
|
111
|
+
* the caller's own retry. `x-should-retry` is believed there, in either direction.
|
|
112
|
+
*/
|
|
113
|
+
export declare function noReplay(provider: string, error: unknown, signal?: AbortSignal): unknown;
|
|
114
|
+
/**
|
|
115
|
+
* @internal The one place a call runs: under one deadline, once, and with the
|
|
116
|
+
* no-replay rule applied to whatever it throws. Both wires go through here.
|
|
117
|
+
*/
|
|
118
|
+
export declare function synthesizeOnce<T>(provider: string, timeoutMs: number, request: SpeechRequest, call: (signal: AbortSignal) => Promise<T>): Promise<T>;
|
|
119
|
+
/** @internal A reply that arrived but cannot be used. Never retried: it was billed. */
|
|
120
|
+
export declare function unusable(provider: string, kind: ErrorKind, code: string, message: string, usage?: SpeechUsage): SpeechError;
|
|
121
|
+
/**
|
|
122
|
+
* @internal A failure the provider reported inside a 200 body (a gateway that
|
|
123
|
+
* answers 200 with a JSON error, an Interactions reply that says it failed). It is
|
|
124
|
+
* classified like any other failure, with the same words-over-status rules, and
|
|
125
|
+
* then the provider's words are dropped: they can echo the text that was sent.
|
|
126
|
+
*/
|
|
127
|
+
export declare function inBandFailure(provider: string, envelope: unknown, usage?: SpeechUsage): SpeechError;
|
|
128
|
+
/** @internal */
|
|
129
|
+
export declare function asRecord(value: unknown): Record<string, unknown> | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* @internal Strict base64 to bytes: the length is a multiple of 4, the alphabet is
|
|
132
|
+
* the standard one, padding sits only at the end. `atob` alone is too forgiving:
|
|
133
|
+
* it drops whitespace and accepts missing padding. `undefined` on anything else.
|
|
134
|
+
*/
|
|
135
|
+
export declare function decodeBase64(data: string): Uint8Array | undefined;
|
|
136
|
+
/** A format with a signature in its first bytes. Raw PCM has none. */
|
|
137
|
+
type ContainerFormat = Exclude<SpeechFormat, "pcm">;
|
|
138
|
+
/**
|
|
139
|
+
* @internal Which container the first bytes say this is, or `undefined`. Raw PCM
|
|
140
|
+
* has no signature, so it is never returned here. ADTS AAC and mp3 share a sync
|
|
141
|
+
* pattern and are told apart by their layer field.
|
|
142
|
+
*/
|
|
143
|
+
export declare function sniffFormat(bytes: Uint8Array): ContainerFormat | undefined;
|
|
144
|
+
export interface WavInfo {
|
|
145
|
+
sampleRate: number;
|
|
146
|
+
channels: number;
|
|
147
|
+
bitsPerSample: number;
|
|
148
|
+
/** Samples per channel. */
|
|
149
|
+
frames: number;
|
|
150
|
+
durationMs: number;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Read a WAV file's own numbers, strictly. PCM only (format tag 1). The RIFF size
|
|
154
|
+
* is exact, every chunk sits inside the file, there is one `fmt ` before one
|
|
155
|
+
* non-empty `data` that holds whole frames, and nothing trails. Extra chunks such
|
|
156
|
+
* as `LIST` are skipped, and odd-sized chunks carry their pad byte. `undefined`
|
|
157
|
+
* on anything else. It reports what the bytes say; whether 24 kHz mono is
|
|
158
|
+
* acceptable is the caller's policy.
|
|
159
|
+
*/
|
|
160
|
+
export declare function readWav(bytes: Uint8Array): WavInfo | undefined;
|
|
161
|
+
/** @internal Everything a result needs besides the audio itself. */
|
|
162
|
+
export interface AudioExtras {
|
|
163
|
+
model: string;
|
|
164
|
+
voice: string;
|
|
165
|
+
characters: number;
|
|
166
|
+
usage?: SpeechUsage;
|
|
167
|
+
/** What the request or the provider stated, for raw PCM only. */
|
|
168
|
+
sampleRate?: number;
|
|
169
|
+
channels?: number;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* @internal Bytes in, `SpeechResult` out. An empty body is `empty_audio`. A
|
|
173
|
+
* recognised container is accepted whatever was asked for, and `format` says what
|
|
174
|
+
* it really is. Raw PCM is the one case with no signature to read, so it is
|
|
175
|
+
* accepted only when PCM was asked for and the length is whole samples. Anything
|
|
176
|
+
* else is `bad_audio`.
|
|
177
|
+
*
|
|
178
|
+
* A WAV is labelled by its signature. Its numbers (rate, channels, duration) are
|
|
179
|
+
* filled in only when the header checks out, so a server whose header lies still
|
|
180
|
+
* gets its audio through, without a duration anyone could take as measured.
|
|
181
|
+
*/
|
|
182
|
+
export declare function describeAudio(provider: string, bytes: Uint8Array, wanted: SpeechFormat, extras: AudioExtras): SpeechResult;
|
|
183
|
+
export {};
|
|
184
|
+
//# sourceMappingURL=speech-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"speech-core.d.ts","sourceRoot":"","sources":["../src/speech-core.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,aAAa,EAAe,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAEzE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,cAAc,uDAAwD,CAAC;AACpF,MAAM,MAAM,YAAY,GAAG,CAA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ACnB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,YAAY,EACpB,MAAM,EAAE,WAAW,GAClB,YAAY,CA4Cd"}
|
|
@@ -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,KA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;KACR,CAAC;AACJ,CAAC"}
|
package/dist/speech.d.ts
ADDED
|
@@ -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"}
|
package/dist/transport.d.ts
CHANGED
|
@@ -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
|