@speeq/core 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-CELQUH6A.js +166 -0
- package/dist/chunk-CELQUH6A.js.map +1 -0
- package/dist/{chunk-JA2L35IQ.js → chunk-FRW2OUQL.js} +8 -2
- package/dist/chunk-FRW2OUQL.js.map +1 -0
- package/dist/chunk-PU7PGHHO.js +421 -0
- package/dist/chunk-PU7PGHHO.js.map +1 -0
- package/dist/errors.cjs +6 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +1 -1
- package/dist/index-DPp4Fwdy.d.cts +236 -0
- package/dist/index-I0oTxGMf.d.ts +236 -0
- package/dist/index.cjs +365 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +176 -3
- package/dist/index.d.ts +176 -3
- package/dist/index.js +87 -4
- package/dist/index.js.map +1 -1
- package/dist/manifest.cjs +230 -0
- package/dist/manifest.cjs.map +1 -0
- package/dist/manifest.d.cts +2523 -0
- package/dist/manifest.d.ts +2523 -0
- package/dist/manifest.js +218 -0
- package/dist/manifest.js.map +1 -0
- package/dist/speech-http.cjs +346 -0
- package/dist/speech-http.cjs.map +1 -0
- package/dist/speech-http.d.cts +41 -0
- package/dist/speech-http.d.ts +41 -0
- package/dist/speech-http.js +264 -0
- package/dist/speech-http.js.map +1 -0
- package/dist/speech-provider-D0YChUSt.d.cts +103 -0
- package/dist/speech-provider-D0YChUSt.d.ts +103 -0
- package/dist/utils.cjs +237 -0
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +2 -156
- package/dist/utils.d.ts +2 -156
- package/dist/utils.js +3 -2
- package/package.json +24 -2
- package/dist/chunk-JA2L35IQ.js.map +0 -1
- package/dist/chunk-JOTEKM5R.js +0 -318
- package/dist/chunk-JOTEKM5R.js.map +0 -1
package/dist/utils.d.cts
CHANGED
|
@@ -1,156 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Returns an `AbortSignal` that aborts when any input signal aborts, or after `timeoutMs`.
|
|
5
|
-
* It uses `AbortSignal.any` / `AbortSignal.timeout` when available, with a manual fallback.
|
|
6
|
-
*/
|
|
7
|
-
declare function combineSignals(signals: ReadonlyArray<AbortSignal | undefined>, timeoutMs?: number): AbortSignal;
|
|
8
|
-
/** Resolves after `ms` milliseconds, or rejects early when `signal` aborts. */
|
|
9
|
-
declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
|
|
10
|
-
|
|
11
|
-
/** A listener for event `K` of an event map `E`. */
|
|
12
|
-
type Listener<E, K extends keyof E> = (payload: E[K]) => void;
|
|
13
|
-
/**
|
|
14
|
-
* A tiny, typed event emitter. A listener that throws never breaks other listeners or the
|
|
15
|
-
* emitter (the error is reported with `console.error`).
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* const em = new TypedEmitter<{ state: "idle" | "busy" }>();
|
|
19
|
-
* const off = em.on("state", (s) => console.log(s));
|
|
20
|
-
* em.emit("state", "busy");
|
|
21
|
-
* off();
|
|
22
|
-
*/
|
|
23
|
-
declare class TypedEmitter<E extends Record<string, unknown>> {
|
|
24
|
-
private readonly listeners;
|
|
25
|
-
/** Subscribes to `event`. Returns an unsubscribe function. */
|
|
26
|
-
on<K extends keyof E>(event: K, listener: Listener<E, K>): () => void;
|
|
27
|
-
/** Subscribes to the next `event` only. */
|
|
28
|
-
once<K extends keyof E>(event: K, listener: Listener<E, K>): () => void;
|
|
29
|
-
/** Removes a listener. */
|
|
30
|
-
off<K extends keyof E>(event: K, listener: Listener<E, K>): void;
|
|
31
|
-
/** Calls every listener for `event` with `payload`. */
|
|
32
|
-
emit<K extends keyof E>(event: K, payload: E[K]): void;
|
|
33
|
-
/** Removes every listener. */
|
|
34
|
-
clear(): void;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Returns a random, URL-safe id such as `ses_3f9a…`. It uses `crypto.randomUUID()`, which is
|
|
39
|
-
* available in browsers, Node 20+ and edge runtimes. Ids never encode user data.
|
|
40
|
-
*
|
|
41
|
-
* @param prefix - A short readable prefix such as `ses`, `evt` or `turn`.
|
|
42
|
-
*/
|
|
43
|
-
declare function createId(prefix: string): string;
|
|
44
|
-
|
|
45
|
-
/** Result of {@link safeJsonParse}. */
|
|
46
|
-
type SafeJsonResult<T = unknown> = {
|
|
47
|
-
ok: true;
|
|
48
|
-
value: T;
|
|
49
|
-
} | {
|
|
50
|
-
ok: false;
|
|
51
|
-
error: string;
|
|
52
|
-
};
|
|
53
|
-
/** Parses JSON without throwing. */
|
|
54
|
-
declare function safeJsonParse<T = unknown>(text: string): SafeJsonResult<T>;
|
|
55
|
-
/**
|
|
56
|
-
* Stringifies any value without throwing: handles cycles (`"[Circular]"`), `bigint`, `Error`,
|
|
57
|
-
* `undefined` at the top level and functions. Use it for tool output before sending it to a model.
|
|
58
|
-
*/
|
|
59
|
-
declare function safeJsonStringify(value: unknown, space?: number): string;
|
|
60
|
-
/** Result of {@link truncate}. */
|
|
61
|
-
interface TruncateResult {
|
|
62
|
-
text: string;
|
|
63
|
-
truncated: boolean;
|
|
64
|
-
}
|
|
65
|
-
/** Cuts `text` to at most `maxChars` characters and marks whether it was cut. */
|
|
66
|
-
declare function truncate(text: string, maxChars: number): TruncateResult;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Reads the `data:` payloads of an SSE response body. For LLM adapters: stops at `[DONE]`
|
|
70
|
-
* and honors `signal`.
|
|
71
|
-
*/
|
|
72
|
-
declare function readSseData(body: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<string>;
|
|
73
|
-
/** Parses a `Retry-After` header (seconds or HTTP date) into milliseconds. */
|
|
74
|
-
declare function parseRetryAfter(value: string | null | undefined): number | undefined;
|
|
75
|
-
/**
|
|
76
|
-
* Maps an HTTP error from an LLM provider to a {@link SpeeqError}:
|
|
77
|
-
* 429 and quota or rate-limit bodies → `RATE_LIMITED` (with a retry hint), 401/403 →
|
|
78
|
-
* `NOT_CONFIGURED` (bad API key), anything else → `PROVIDER_ERROR`. The provider's raw message
|
|
79
|
-
* is kept in `details` for server logs, never in the public message.
|
|
80
|
-
*/
|
|
81
|
-
declare function mapProviderHttpError(provider: string, status: number, bodyText: string, retryAfter?: string | null): SpeeqError;
|
|
82
|
-
/** Wraps `fetch` so network failures become `PROVIDER_ERROR` and aborts are rethrown as-is. */
|
|
83
|
-
declare function providerFetch(provider: string, fetchImpl: typeof fetch, url: string, init: RequestInit): Promise<Response>;
|
|
84
|
-
|
|
85
|
-
/** The placeholder written in place of redacted values. */
|
|
86
|
-
declare const REDACTED = "[REDACTED]";
|
|
87
|
-
/** Keys that are redacted by default by {@link redactKeys}. Matching ignores case. */
|
|
88
|
-
declare const DEFAULT_SECRET_KEYS: readonly string[];
|
|
89
|
-
/**
|
|
90
|
-
* Returns a deep copy of `value` with the values of matching keys replaced by `[REDACTED]`.
|
|
91
|
-
* Matching ignores case and also strips `-` / `_`, so `api-key` matches `apikey`.
|
|
92
|
-
*/
|
|
93
|
-
declare function redactKeys<T>(value: T, keys?: readonly string[]): T;
|
|
94
|
-
/** Replaces email addresses and long digit sequences (phones, cards) in free text. */
|
|
95
|
-
declare function redactText(text: string): string;
|
|
96
|
-
|
|
97
|
-
/** Options for {@link SentenceChunker}. */
|
|
98
|
-
interface SentenceChunkerOptions {
|
|
99
|
-
/** Force a split (at the last comma or space) once a sentence grows past this length. */
|
|
100
|
-
maxLength?: number;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Splits streamed text deltas into whole sentences, so text-to-speech can start speaking the
|
|
104
|
-
* first sentence while the rest is still generating.
|
|
105
|
-
*
|
|
106
|
-
* A sentence ends at end-punctuation followed by whitespace, or at a newline. Punctuation at the
|
|
107
|
-
* very end of the buffer waits for more input, so `3.` + `5` stays `3.5`. Overlong text is split
|
|
108
|
-
* at the last comma or space before `maxLength`.
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* const c = new SentenceChunker();
|
|
112
|
-
* c.push("Hello the"); // []
|
|
113
|
-
* c.push("re. How are"); // ["Hello there."]
|
|
114
|
-
* c.flush(); // "How are"
|
|
115
|
-
*/
|
|
116
|
-
declare class SentenceChunker {
|
|
117
|
-
private buffer;
|
|
118
|
-
private readonly maxLength;
|
|
119
|
-
constructor(options?: SentenceChunkerOptions);
|
|
120
|
-
/** Adds a delta and returns every sentence it completed (never empty strings). */
|
|
121
|
-
push(delta: string): string[];
|
|
122
|
-
/** Returns the buffered remainder (trimmed, may be empty) and resets the chunker. */
|
|
123
|
-
flush(): string;
|
|
124
|
-
private take;
|
|
125
|
-
private cut;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** One parsed Server-Sent Event. */
|
|
129
|
-
interface SseMessage {
|
|
130
|
-
/** The `event:` field, or `"message"` when absent. */
|
|
131
|
-
event: string;
|
|
132
|
-
/** The joined `data:` lines. */
|
|
133
|
-
data: string;
|
|
134
|
-
id?: string;
|
|
135
|
-
}
|
|
136
|
-
/** Encodes one SSE message (`event:` + `data:` lines + blank line). */
|
|
137
|
-
declare function encodeSse(event: string, data: string): string;
|
|
138
|
-
/**
|
|
139
|
-
* Incremental SSE parser that follows the WHATWG event-stream rules. Feed it decoded text chunks
|
|
140
|
-
* in any split (mid-line, mid-field, CRLF across chunks) and it returns complete messages.
|
|
141
|
-
*/
|
|
142
|
-
declare class SseParser {
|
|
143
|
-
private buffer;
|
|
144
|
-
private event;
|
|
145
|
-
private data;
|
|
146
|
-
private id;
|
|
147
|
-
/** Adds a chunk and returns every message completed by it. */
|
|
148
|
-
push(chunk: string): SseMessage[];
|
|
149
|
-
/** Flushes a final message that was not followed by a blank line (end of stream). */
|
|
150
|
-
end(): SseMessage[];
|
|
151
|
-
private processLine;
|
|
152
|
-
private dispatch;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export { DEFAULT_SECRET_KEYS, REDACTED, SentenceChunker, SseParser, TypedEmitter, combineSignals, createId, encodeSse, mapProviderHttpError, parseRetryAfter, providerFetch, readSseData, redactKeys, redactText, safeJsonParse, safeJsonStringify, sleep, truncate };
|
|
156
|
-
export type { Listener, SafeJsonResult, SentenceChunkerOptions, SseMessage, TruncateResult };
|
|
1
|
+
export { b as CorrectionResult, D as DEFAULT_SECRET_KEYS, L as Listener, R as REDACTED, S as SafeJsonResult, d as SentenceChunker, e as SentenceChunkerOptions, f as SseMessage, g as SseParser, T as TruncateResult, h as TypedEmitter, V as Vocabulary, k as baseLanguage, l as combineSignals, m as correctWithVocabulary, n as createId, p as encodeSse, q as guessLanguageFromScript, r as mapProviderHttpError, s as parseRetryAfter, t as providerFetch, u as readSseData, v as redactKeys, w as redactText, x as safeJsonParse, y as safeJsonStringify, z as sleep, E as truncate } from './index-DPp4Fwdy.cjs';
|
|
2
|
+
import './errors.cjs';
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,156 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Returns an `AbortSignal` that aborts when any input signal aborts, or after `timeoutMs`.
|
|
5
|
-
* It uses `AbortSignal.any` / `AbortSignal.timeout` when available, with a manual fallback.
|
|
6
|
-
*/
|
|
7
|
-
declare function combineSignals(signals: ReadonlyArray<AbortSignal | undefined>, timeoutMs?: number): AbortSignal;
|
|
8
|
-
/** Resolves after `ms` milliseconds, or rejects early when `signal` aborts. */
|
|
9
|
-
declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
|
|
10
|
-
|
|
11
|
-
/** A listener for event `K` of an event map `E`. */
|
|
12
|
-
type Listener<E, K extends keyof E> = (payload: E[K]) => void;
|
|
13
|
-
/**
|
|
14
|
-
* A tiny, typed event emitter. A listener that throws never breaks other listeners or the
|
|
15
|
-
* emitter (the error is reported with `console.error`).
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* const em = new TypedEmitter<{ state: "idle" | "busy" }>();
|
|
19
|
-
* const off = em.on("state", (s) => console.log(s));
|
|
20
|
-
* em.emit("state", "busy");
|
|
21
|
-
* off();
|
|
22
|
-
*/
|
|
23
|
-
declare class TypedEmitter<E extends Record<string, unknown>> {
|
|
24
|
-
private readonly listeners;
|
|
25
|
-
/** Subscribes to `event`. Returns an unsubscribe function. */
|
|
26
|
-
on<K extends keyof E>(event: K, listener: Listener<E, K>): () => void;
|
|
27
|
-
/** Subscribes to the next `event` only. */
|
|
28
|
-
once<K extends keyof E>(event: K, listener: Listener<E, K>): () => void;
|
|
29
|
-
/** Removes a listener. */
|
|
30
|
-
off<K extends keyof E>(event: K, listener: Listener<E, K>): void;
|
|
31
|
-
/** Calls every listener for `event` with `payload`. */
|
|
32
|
-
emit<K extends keyof E>(event: K, payload: E[K]): void;
|
|
33
|
-
/** Removes every listener. */
|
|
34
|
-
clear(): void;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Returns a random, URL-safe id such as `ses_3f9a…`. It uses `crypto.randomUUID()`, which is
|
|
39
|
-
* available in browsers, Node 20+ and edge runtimes. Ids never encode user data.
|
|
40
|
-
*
|
|
41
|
-
* @param prefix - A short readable prefix such as `ses`, `evt` or `turn`.
|
|
42
|
-
*/
|
|
43
|
-
declare function createId(prefix: string): string;
|
|
44
|
-
|
|
45
|
-
/** Result of {@link safeJsonParse}. */
|
|
46
|
-
type SafeJsonResult<T = unknown> = {
|
|
47
|
-
ok: true;
|
|
48
|
-
value: T;
|
|
49
|
-
} | {
|
|
50
|
-
ok: false;
|
|
51
|
-
error: string;
|
|
52
|
-
};
|
|
53
|
-
/** Parses JSON without throwing. */
|
|
54
|
-
declare function safeJsonParse<T = unknown>(text: string): SafeJsonResult<T>;
|
|
55
|
-
/**
|
|
56
|
-
* Stringifies any value without throwing: handles cycles (`"[Circular]"`), `bigint`, `Error`,
|
|
57
|
-
* `undefined` at the top level and functions. Use it for tool output before sending it to a model.
|
|
58
|
-
*/
|
|
59
|
-
declare function safeJsonStringify(value: unknown, space?: number): string;
|
|
60
|
-
/** Result of {@link truncate}. */
|
|
61
|
-
interface TruncateResult {
|
|
62
|
-
text: string;
|
|
63
|
-
truncated: boolean;
|
|
64
|
-
}
|
|
65
|
-
/** Cuts `text` to at most `maxChars` characters and marks whether it was cut. */
|
|
66
|
-
declare function truncate(text: string, maxChars: number): TruncateResult;
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Reads the `data:` payloads of an SSE response body. For LLM adapters: stops at `[DONE]`
|
|
70
|
-
* and honors `signal`.
|
|
71
|
-
*/
|
|
72
|
-
declare function readSseData(body: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<string>;
|
|
73
|
-
/** Parses a `Retry-After` header (seconds or HTTP date) into milliseconds. */
|
|
74
|
-
declare function parseRetryAfter(value: string | null | undefined): number | undefined;
|
|
75
|
-
/**
|
|
76
|
-
* Maps an HTTP error from an LLM provider to a {@link SpeeqError}:
|
|
77
|
-
* 429 and quota or rate-limit bodies → `RATE_LIMITED` (with a retry hint), 401/403 →
|
|
78
|
-
* `NOT_CONFIGURED` (bad API key), anything else → `PROVIDER_ERROR`. The provider's raw message
|
|
79
|
-
* is kept in `details` for server logs, never in the public message.
|
|
80
|
-
*/
|
|
81
|
-
declare function mapProviderHttpError(provider: string, status: number, bodyText: string, retryAfter?: string | null): SpeeqError;
|
|
82
|
-
/** Wraps `fetch` so network failures become `PROVIDER_ERROR` and aborts are rethrown as-is. */
|
|
83
|
-
declare function providerFetch(provider: string, fetchImpl: typeof fetch, url: string, init: RequestInit): Promise<Response>;
|
|
84
|
-
|
|
85
|
-
/** The placeholder written in place of redacted values. */
|
|
86
|
-
declare const REDACTED = "[REDACTED]";
|
|
87
|
-
/** Keys that are redacted by default by {@link redactKeys}. Matching ignores case. */
|
|
88
|
-
declare const DEFAULT_SECRET_KEYS: readonly string[];
|
|
89
|
-
/**
|
|
90
|
-
* Returns a deep copy of `value` with the values of matching keys replaced by `[REDACTED]`.
|
|
91
|
-
* Matching ignores case and also strips `-` / `_`, so `api-key` matches `apikey`.
|
|
92
|
-
*/
|
|
93
|
-
declare function redactKeys<T>(value: T, keys?: readonly string[]): T;
|
|
94
|
-
/** Replaces email addresses and long digit sequences (phones, cards) in free text. */
|
|
95
|
-
declare function redactText(text: string): string;
|
|
96
|
-
|
|
97
|
-
/** Options for {@link SentenceChunker}. */
|
|
98
|
-
interface SentenceChunkerOptions {
|
|
99
|
-
/** Force a split (at the last comma or space) once a sentence grows past this length. */
|
|
100
|
-
maxLength?: number;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Splits streamed text deltas into whole sentences, so text-to-speech can start speaking the
|
|
104
|
-
* first sentence while the rest is still generating.
|
|
105
|
-
*
|
|
106
|
-
* A sentence ends at end-punctuation followed by whitespace, or at a newline. Punctuation at the
|
|
107
|
-
* very end of the buffer waits for more input, so `3.` + `5` stays `3.5`. Overlong text is split
|
|
108
|
-
* at the last comma or space before `maxLength`.
|
|
109
|
-
*
|
|
110
|
-
* @example
|
|
111
|
-
* const c = new SentenceChunker();
|
|
112
|
-
* c.push("Hello the"); // []
|
|
113
|
-
* c.push("re. How are"); // ["Hello there."]
|
|
114
|
-
* c.flush(); // "How are"
|
|
115
|
-
*/
|
|
116
|
-
declare class SentenceChunker {
|
|
117
|
-
private buffer;
|
|
118
|
-
private readonly maxLength;
|
|
119
|
-
constructor(options?: SentenceChunkerOptions);
|
|
120
|
-
/** Adds a delta and returns every sentence it completed (never empty strings). */
|
|
121
|
-
push(delta: string): string[];
|
|
122
|
-
/** Returns the buffered remainder (trimmed, may be empty) and resets the chunker. */
|
|
123
|
-
flush(): string;
|
|
124
|
-
private take;
|
|
125
|
-
private cut;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/** One parsed Server-Sent Event. */
|
|
129
|
-
interface SseMessage {
|
|
130
|
-
/** The `event:` field, or `"message"` when absent. */
|
|
131
|
-
event: string;
|
|
132
|
-
/** The joined `data:` lines. */
|
|
133
|
-
data: string;
|
|
134
|
-
id?: string;
|
|
135
|
-
}
|
|
136
|
-
/** Encodes one SSE message (`event:` + `data:` lines + blank line). */
|
|
137
|
-
declare function encodeSse(event: string, data: string): string;
|
|
138
|
-
/**
|
|
139
|
-
* Incremental SSE parser that follows the WHATWG event-stream rules. Feed it decoded text chunks
|
|
140
|
-
* in any split (mid-line, mid-field, CRLF across chunks) and it returns complete messages.
|
|
141
|
-
*/
|
|
142
|
-
declare class SseParser {
|
|
143
|
-
private buffer;
|
|
144
|
-
private event;
|
|
145
|
-
private data;
|
|
146
|
-
private id;
|
|
147
|
-
/** Adds a chunk and returns every message completed by it. */
|
|
148
|
-
push(chunk: string): SseMessage[];
|
|
149
|
-
/** Flushes a final message that was not followed by a blank line (end of stream). */
|
|
150
|
-
end(): SseMessage[];
|
|
151
|
-
private processLine;
|
|
152
|
-
private dispatch;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export { DEFAULT_SECRET_KEYS, REDACTED, SentenceChunker, SseParser, TypedEmitter, combineSignals, createId, encodeSse, mapProviderHttpError, parseRetryAfter, providerFetch, readSseData, redactKeys, redactText, safeJsonParse, safeJsonStringify, sleep, truncate };
|
|
156
|
-
export type { Listener, SafeJsonResult, SentenceChunkerOptions, SseMessage, TruncateResult };
|
|
1
|
+
export { b as CorrectionResult, D as DEFAULT_SECRET_KEYS, L as Listener, R as REDACTED, S as SafeJsonResult, d as SentenceChunker, e as SentenceChunkerOptions, f as SseMessage, g as SseParser, T as TruncateResult, h as TypedEmitter, V as Vocabulary, k as baseLanguage, l as combineSignals, m as correctWithVocabulary, n as createId, p as encodeSse, q as guessLanguageFromScript, r as mapProviderHttpError, s as parseRetryAfter, t as providerFetch, u as readSseData, v as redactKeys, w as redactText, x as safeJsonParse, y as safeJsonStringify, z as sleep, E as truncate } from './index-I0oTxGMf.js';
|
|
2
|
+
import './errors.js';
|
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { DEFAULT_SECRET_KEYS, REDACTED, SentenceChunker,
|
|
2
|
-
|
|
1
|
+
export { DEFAULT_SECRET_KEYS, REDACTED, SentenceChunker, TypedEmitter, combineSignals, correctWithVocabulary, createId, redactKeys, redactText, safeJsonParse, safeJsonStringify, sleep, truncate } from './chunk-PU7PGHHO.js';
|
|
2
|
+
export { SseParser, baseLanguage, encodeSse, guessLanguageFromScript, mapProviderHttpError, parseRetryAfter, providerFetch, readSseData } from './chunk-CELQUH6A.js';
|
|
3
|
+
import './chunk-FRW2OUQL.js';
|
|
3
4
|
//# sourceMappingURL=utils.js.map
|
|
4
5
|
//# sourceMappingURL=utils.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@speeq/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Types, Zod schemas, protocol, errors and utilities shared by every speeq package.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -62,7 +62,29 @@
|
|
|
62
62
|
"default": "./dist/utils.cjs"
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
|
-
"./package.json": "./package.json"
|
|
65
|
+
"./package.json": "./package.json",
|
|
66
|
+
"./speech-http": {
|
|
67
|
+
"@speeq/source": "./src/speech-http/index.ts",
|
|
68
|
+
"import": {
|
|
69
|
+
"types": "./dist/speech-http.d.ts",
|
|
70
|
+
"default": "./dist/speech-http.js"
|
|
71
|
+
},
|
|
72
|
+
"require": {
|
|
73
|
+
"types": "./dist/speech-http.d.cts",
|
|
74
|
+
"default": "./dist/speech-http.cjs"
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"./manifest": {
|
|
78
|
+
"@speeq/source": "./src/manifest.ts",
|
|
79
|
+
"import": {
|
|
80
|
+
"types": "./dist/manifest.d.ts",
|
|
81
|
+
"default": "./dist/manifest.js"
|
|
82
|
+
},
|
|
83
|
+
"require": {
|
|
84
|
+
"types": "./dist/manifest.d.cts",
|
|
85
|
+
"default": "./dist/manifest.cjs"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
66
88
|
},
|
|
67
89
|
"publishConfig": {
|
|
68
90
|
"access": "public"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts"],"names":[],"mappings":"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","file":"chunk-JA2L35IQ.js","sourcesContent":["/**\n * Errors shared by every speeq package. This module has no dependencies (no zod), so browser\n * code can import it from `@speeq/core/errors` without pulling in schemas.\n */\n\n/** Every stable error code. Codes are part of the public protocol. Never rename one. */\nexport const ERROR_CODES = [\n \"UNAUTHENTICATED\",\n \"FORBIDDEN\",\n \"INVALID_INPUT\",\n \"NOT_FOUND\",\n \"CONFLICT\",\n \"RATE_LIMITED\",\n \"PROVIDER_ERROR\",\n \"TOOL_ERROR\",\n \"TOOL_TIMEOUT\",\n \"CONFIRMATION_REQUIRED\",\n \"SESSION_EXPIRED\",\n \"NOT_CONFIGURED\",\n \"INTERNAL\",\n] as const;\n\n/** A stable, machine-readable error code. */\nexport type ErrorCode = (typeof ERROR_CODES)[number];\n\n/** HTTP status used when an error with this code is returned as a plain JSON response. */\nexport const ERROR_HTTP_STATUS: Readonly<Record<ErrorCode, number>> = {\n UNAUTHENTICATED: 401,\n FORBIDDEN: 403,\n INVALID_INPUT: 400,\n NOT_FOUND: 404,\n CONFLICT: 409,\n RATE_LIMITED: 429,\n PROVIDER_ERROR: 502,\n TOOL_ERROR: 500,\n TOOL_TIMEOUT: 504,\n CONFIRMATION_REQUIRED: 409,\n SESSION_EXPIRED: 401,\n NOT_CONFIGURED: 500,\n INTERNAL: 500,\n};\n\n/** Friendly default messages that are always safe to show to end users. */\nexport const DEFAULT_ERROR_MESSAGES: Readonly<Record<ErrorCode, string>> = {\n UNAUTHENTICATED: \"Please sign in to continue.\",\n FORBIDDEN: \"You are not allowed to do that.\",\n INVALID_INPUT: \"The request was not valid.\",\n NOT_FOUND: \"That could not be found.\",\n CONFLICT: \"That was already handled.\",\n RATE_LIMITED: \"The assistant is busy right now. Please try again in a moment.\",\n PROVIDER_ERROR: \"The AI provider had a problem. Please try again.\",\n TOOL_ERROR: \"An action failed to run.\",\n TOOL_TIMEOUT: \"An action took too long and was stopped.\",\n CONFIRMATION_REQUIRED: \"This action needs your confirmation.\",\n SESSION_EXPIRED: \"Your session expired. Starting a new one.\",\n NOT_CONFIGURED: \"The assistant is not configured correctly.\",\n INTERNAL: \"Something went wrong.\",\n};\n\nconst RETRYABLE: ReadonlySet<ErrorCode> = new Set([\n \"RATE_LIMITED\",\n \"PROVIDER_ERROR\",\n \"TOOL_TIMEOUT\",\n \"SESSION_EXPIRED\",\n]);\n\n/** Options for constructing a {@link SpeeqError}. */\nexport interface SpeeqErrorOptions {\n /** Public, user-safe message. Defaults to {@link DEFAULT_ERROR_MESSAGES}. */\n message?: string;\n /** Whether retrying the same request may succeed. Defaults by code. */\n retryable?: boolean;\n /** Suggested wait before retrying, in milliseconds. */\n retryAfterMs?: number;\n /** The underlying error. Kept for server logs, never serialized to clients. */\n cause?: unknown;\n /** Extra structured detail for logs (never sent to clients). */\n details?: Record<string, unknown>;\n}\n\n/** The single error type used across speeq. Always carries a stable {@link ErrorCode}. */\nexport class SpeeqError extends Error {\n /** Brand used by {@link isSpeeqError} so checks work across bundled copies. */\n readonly isSpeeqError = true as const;\n readonly code: ErrorCode;\n readonly retryable: boolean;\n readonly retryAfterMs: number | undefined;\n readonly details: Record<string, unknown> | undefined;\n\n constructor(code: ErrorCode, options: SpeeqErrorOptions = {}) {\n super(options.message ?? DEFAULT_ERROR_MESSAGES[code], { cause: options.cause });\n this.name = \"SpeeqError\";\n this.code = code;\n this.retryable = options.retryable ?? RETRYABLE.has(code);\n this.retryAfterMs = options.retryAfterMs;\n this.details = options.details;\n }\n\n /** HTTP status for this error. */\n get status(): number {\n return ERROR_HTTP_STATUS[this.code];\n }\n}\n\n/** True if `value` is a {@link SpeeqError} (works across duplicated package copies). */\nexport function isSpeeqError(value: unknown): value is SpeeqError {\n return (\n typeof value === \"object\" &&\n value !== null &&\n (value as { isSpeeqError?: unknown }).isSpeeqError === true &&\n typeof (value as { code?: unknown }).code === \"string\"\n );\n}\n\n/** True if `value` is one of the known {@link ERROR_CODES}. */\nexport function isErrorCode(value: unknown): value is ErrorCode {\n return typeof value === \"string\" && (ERROR_CODES as readonly string[]).includes(value);\n}\n\n/** The client-safe shape of an error, as sent over the wire. */\nexport interface PublicError {\n code: ErrorCode;\n message: string;\n retryable: boolean;\n retryAfterMs?: number;\n}\n\n/**\n * Converts anything thrown into a {@link SpeeqError}. Unknown errors become `INTERNAL` with the\n * generic message, so raw messages and stack traces never reach clients.\n */\nexport function toSpeeqError(error: unknown, fallback: ErrorCode = \"INTERNAL\"): SpeeqError {\n if (isSpeeqError(error)) return error;\n if (isAbortError(error))\n return new SpeeqError(\"INTERNAL\", { message: \"Cancelled.\", cause: error });\n return new SpeeqError(fallback, { cause: error });\n}\n\n/** Serializes an error to its {@link PublicError} form (safe to send to the browser). */\nexport function toPublicError(error: unknown): PublicError {\n const e = toSpeeqError(error);\n const out: PublicError = { code: e.code, message: e.message, retryable: e.retryable };\n if (e.retryAfterMs !== undefined) out.retryAfterMs = e.retryAfterMs;\n return out;\n}\n\n/** True for `AbortError`s raised by `AbortSignal` / `fetch`. */\nexport function isAbortError(error: unknown): boolean {\n return (\n typeof error === \"object\" &&\n error !== null &&\n ((error as { name?: unknown }).name === \"AbortError\" ||\n (error as { name?: unknown }).name === \"TimeoutError\")\n );\n}\n"]}
|