blazen 0.5.3 → 0.6.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 +56 -52
- package/blazen.workers.js +97 -14
- package/index.d.ts +3398 -1023
- package/index.js +182 -114
- package/package.json +8 -9
- package/error-classes.js +0 -855
package/error-classes.js
DELETED
|
@@ -1,855 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
// Typed JS error classes for Blazen.
|
|
4
|
-
//
|
|
5
|
-
// The Rust binding (see `crates/blazen-node/src/error.rs`) prefixes every
|
|
6
|
-
// `napi::Error` message with a `[ClassName]` tag. This file:
|
|
7
|
-
// 1. Defines a class hierarchy that mirrors the Python binding's
|
|
8
|
-
// `pyo3::create_exception!` tree (the source of truth).
|
|
9
|
-
// 2. Exposes `enrichError(err)` which, given a plain `Error` thrown by a
|
|
10
|
-
// napi-rs function, parses the leading `[Tag]` prefix and rethrows a
|
|
11
|
-
// typed instance whose `message` is the original message minus the
|
|
12
|
-
// prefix.
|
|
13
|
-
//
|
|
14
|
-
// Consumers can do `err instanceof BlazenError`, `err instanceof ProviderError`,
|
|
15
|
-
// or check the concrete leaf type (e.g. `LlamaCppModelLoadError`).
|
|
16
|
-
//
|
|
17
|
-
// The `[ProviderError]` tag is also emitted alongside a sentinel JSON line
|
|
18
|
-
// for HTTP/provider errors -- see `error.rs` `PROVIDER_ERROR_SENTINEL`.
|
|
19
|
-
// `enrichError` extracts the sentinel JSON (when present), attaches the
|
|
20
|
-
// structured fields (`provider`, `status`, `endpoint`, `requestId`,
|
|
21
|
-
// `detail`, `retryAfterMs`) onto the resulting `ProviderError` instance,
|
|
22
|
-
// and strips the sentinel line from the user-visible message.
|
|
23
|
-
|
|
24
|
-
const PROVIDER_ERROR_SENTINEL = '__BLAZEN_PROVIDER_ERROR__'
|
|
25
|
-
|
|
26
|
-
// ---------------------------------------------------------------------------
|
|
27
|
-
// Class hierarchy
|
|
28
|
-
// ---------------------------------------------------------------------------
|
|
29
|
-
|
|
30
|
-
class BlazenError extends Error {
|
|
31
|
-
constructor(message) {
|
|
32
|
-
super(message)
|
|
33
|
-
this.name = 'BlazenError'
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
class AuthError extends BlazenError {
|
|
38
|
-
constructor(message) {
|
|
39
|
-
super(message)
|
|
40
|
-
this.name = 'AuthError'
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
class RateLimitError extends BlazenError {
|
|
45
|
-
constructor(message) {
|
|
46
|
-
super(message)
|
|
47
|
-
this.name = 'RateLimitError'
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
class TimeoutError extends BlazenError {
|
|
52
|
-
constructor(message) {
|
|
53
|
-
super(message)
|
|
54
|
-
this.name = 'TimeoutError'
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
class ValidationError extends BlazenError {
|
|
59
|
-
constructor(message) {
|
|
60
|
-
super(message)
|
|
61
|
-
this.name = 'ValidationError'
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
class ContentPolicyError extends BlazenError {
|
|
66
|
-
constructor(message) {
|
|
67
|
-
super(message)
|
|
68
|
-
this.name = 'ContentPolicyError'
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
class UnsupportedError extends BlazenError {
|
|
73
|
-
constructor(message) {
|
|
74
|
-
super(message)
|
|
75
|
-
this.name = 'UnsupportedError'
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
class ComputeError extends BlazenError {
|
|
80
|
-
constructor(message) {
|
|
81
|
-
super(message)
|
|
82
|
-
this.name = 'ComputeError'
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
class MediaError extends BlazenError {
|
|
87
|
-
constructor(message) {
|
|
88
|
-
super(message)
|
|
89
|
-
this.name = 'MediaError'
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
class ProviderError extends BlazenError {
|
|
94
|
-
constructor(message) {
|
|
95
|
-
super(message)
|
|
96
|
-
this.name = 'ProviderError'
|
|
97
|
-
// Structured fields populated from the sentinel JSON when present.
|
|
98
|
-
// Always defined (defaulting to `null`) so consumers can rely on the
|
|
99
|
-
// shape without `in` / `hasOwnProperty` checks.
|
|
100
|
-
this.provider = null
|
|
101
|
-
this.status = null
|
|
102
|
-
this.endpoint = null
|
|
103
|
-
this.requestId = null
|
|
104
|
-
this.detail = null
|
|
105
|
-
this.retryAfterMs = null
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// Per-backend provider subclasses. All extend `ProviderError` so callers
|
|
110
|
-
// that don't care which backend failed can keep one `instanceof
|
|
111
|
-
// ProviderError` arm.
|
|
112
|
-
|
|
113
|
-
class LlamaCppError extends ProviderError {
|
|
114
|
-
constructor(message) {
|
|
115
|
-
super(message)
|
|
116
|
-
this.name = 'LlamaCppError'
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
class LlamaCppInvalidOptionsError extends LlamaCppError {
|
|
120
|
-
constructor(message) {
|
|
121
|
-
super(message)
|
|
122
|
-
this.name = 'LlamaCppInvalidOptionsError'
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
class LlamaCppModelLoadError extends LlamaCppError {
|
|
126
|
-
constructor(message) {
|
|
127
|
-
super(message)
|
|
128
|
-
this.name = 'LlamaCppModelLoadError'
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
class LlamaCppInferenceError extends LlamaCppError {
|
|
132
|
-
constructor(message) {
|
|
133
|
-
super(message)
|
|
134
|
-
this.name = 'LlamaCppInferenceError'
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
class LlamaCppEngineNotAvailableError extends LlamaCppError {
|
|
138
|
-
constructor(message) {
|
|
139
|
-
super(message)
|
|
140
|
-
this.name = 'LlamaCppEngineNotAvailableError'
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
class CandleLlmError extends ProviderError {
|
|
145
|
-
constructor(message) {
|
|
146
|
-
super(message)
|
|
147
|
-
this.name = 'CandleLlmError'
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
class CandleLlmInvalidOptionsError extends CandleLlmError {
|
|
151
|
-
constructor(message) {
|
|
152
|
-
super(message)
|
|
153
|
-
this.name = 'CandleLlmInvalidOptionsError'
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
class CandleLlmModelLoadError extends CandleLlmError {
|
|
157
|
-
constructor(message) {
|
|
158
|
-
super(message)
|
|
159
|
-
this.name = 'CandleLlmModelLoadError'
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
class CandleLlmInferenceError extends CandleLlmError {
|
|
163
|
-
constructor(message) {
|
|
164
|
-
super(message)
|
|
165
|
-
this.name = 'CandleLlmInferenceError'
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
class CandleLlmEngineNotAvailableError extends CandleLlmError {
|
|
169
|
-
constructor(message) {
|
|
170
|
-
super(message)
|
|
171
|
-
this.name = 'CandleLlmEngineNotAvailableError'
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
class CandleEmbedError extends ProviderError {
|
|
176
|
-
constructor(message) {
|
|
177
|
-
super(message)
|
|
178
|
-
this.name = 'CandleEmbedError'
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
class CandleEmbedInvalidOptionsError extends CandleEmbedError {
|
|
182
|
-
constructor(message) {
|
|
183
|
-
super(message)
|
|
184
|
-
this.name = 'CandleEmbedInvalidOptionsError'
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
class CandleEmbedModelLoadError extends CandleEmbedError {
|
|
188
|
-
constructor(message) {
|
|
189
|
-
super(message)
|
|
190
|
-
this.name = 'CandleEmbedModelLoadError'
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
class CandleEmbedEmbeddingError extends CandleEmbedError {
|
|
194
|
-
constructor(message) {
|
|
195
|
-
super(message)
|
|
196
|
-
this.name = 'CandleEmbedEmbeddingError'
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
class CandleEmbedEngineNotAvailableError extends CandleEmbedError {
|
|
200
|
-
constructor(message) {
|
|
201
|
-
super(message)
|
|
202
|
-
this.name = 'CandleEmbedEngineNotAvailableError'
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
class CandleEmbedTaskPanickedError extends CandleEmbedError {
|
|
206
|
-
constructor(message) {
|
|
207
|
-
super(message)
|
|
208
|
-
this.name = 'CandleEmbedTaskPanickedError'
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
class MistralRsError extends ProviderError {
|
|
213
|
-
constructor(message) {
|
|
214
|
-
super(message)
|
|
215
|
-
this.name = 'MistralRsError'
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
class MistralRsInvalidOptionsError extends MistralRsError {
|
|
219
|
-
constructor(message) {
|
|
220
|
-
super(message)
|
|
221
|
-
this.name = 'MistralRsInvalidOptionsError'
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
class MistralRsInitError extends MistralRsError {
|
|
225
|
-
constructor(message) {
|
|
226
|
-
super(message)
|
|
227
|
-
this.name = 'MistralRsInitError'
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
class MistralRsInferenceError extends MistralRsError {
|
|
231
|
-
constructor(message) {
|
|
232
|
-
super(message)
|
|
233
|
-
this.name = 'MistralRsInferenceError'
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
class MistralRsEngineNotAvailableError extends MistralRsError {
|
|
237
|
-
constructor(message) {
|
|
238
|
-
super(message)
|
|
239
|
-
this.name = 'MistralRsEngineNotAvailableError'
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
class WhisperError extends ProviderError {
|
|
244
|
-
constructor(message) {
|
|
245
|
-
super(message)
|
|
246
|
-
this.name = 'WhisperError'
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
class WhisperInvalidOptionsError extends WhisperError {
|
|
250
|
-
constructor(message) {
|
|
251
|
-
super(message)
|
|
252
|
-
this.name = 'WhisperInvalidOptionsError'
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
class WhisperModelLoadError extends WhisperError {
|
|
256
|
-
constructor(message) {
|
|
257
|
-
super(message)
|
|
258
|
-
this.name = 'WhisperModelLoadError'
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
class WhisperTranscriptionError extends WhisperError {
|
|
262
|
-
constructor(message) {
|
|
263
|
-
super(message)
|
|
264
|
-
this.name = 'WhisperTranscriptionError'
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
class WhisperEngineNotAvailableError extends WhisperError {
|
|
268
|
-
constructor(message) {
|
|
269
|
-
super(message)
|
|
270
|
-
this.name = 'WhisperEngineNotAvailableError'
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
class WhisperIoError extends WhisperError {
|
|
274
|
-
constructor(message) {
|
|
275
|
-
super(message)
|
|
276
|
-
this.name = 'WhisperIoError'
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
class PiperError extends ProviderError {
|
|
281
|
-
constructor(message) {
|
|
282
|
-
super(message)
|
|
283
|
-
this.name = 'PiperError'
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
class PiperInvalidOptionsError extends PiperError {
|
|
287
|
-
constructor(message) {
|
|
288
|
-
super(message)
|
|
289
|
-
this.name = 'PiperInvalidOptionsError'
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
class PiperModelLoadError extends PiperError {
|
|
293
|
-
constructor(message) {
|
|
294
|
-
super(message)
|
|
295
|
-
this.name = 'PiperModelLoadError'
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
class PiperSynthesisError extends PiperError {
|
|
299
|
-
constructor(message) {
|
|
300
|
-
super(message)
|
|
301
|
-
this.name = 'PiperSynthesisError'
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
class PiperEngineNotAvailableError extends PiperError {
|
|
305
|
-
constructor(message) {
|
|
306
|
-
super(message)
|
|
307
|
-
this.name = 'PiperEngineNotAvailableError'
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
class DiffusionError extends ProviderError {
|
|
312
|
-
constructor(message) {
|
|
313
|
-
super(message)
|
|
314
|
-
this.name = 'DiffusionError'
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
class DiffusionInvalidOptionsError extends DiffusionError {
|
|
318
|
-
constructor(message) {
|
|
319
|
-
super(message)
|
|
320
|
-
this.name = 'DiffusionInvalidOptionsError'
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
class DiffusionModelLoadError extends DiffusionError {
|
|
324
|
-
constructor(message) {
|
|
325
|
-
super(message)
|
|
326
|
-
this.name = 'DiffusionModelLoadError'
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
class DiffusionGenerationError extends DiffusionError {
|
|
330
|
-
constructor(message) {
|
|
331
|
-
super(message)
|
|
332
|
-
this.name = 'DiffusionGenerationError'
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
// fastembed (non-musl) and tract (musl) both surface as `Embed*` tags
|
|
337
|
-
// from the Rust side. We expose them both as `FastEmbedError` (matching
|
|
338
|
-
// the Python binding's name) AND as the underlying `Embed*` tag classes
|
|
339
|
-
// so consumers who already check the per-tag class keep working.
|
|
340
|
-
class FastEmbedError extends ProviderError {
|
|
341
|
-
constructor(message) {
|
|
342
|
-
super(message)
|
|
343
|
-
this.name = 'FastEmbedError'
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
class EmbedUnknownModelError extends FastEmbedError {
|
|
347
|
-
constructor(message) {
|
|
348
|
-
super(message)
|
|
349
|
-
this.name = 'EmbedUnknownModelError'
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
class EmbedInitError extends FastEmbedError {
|
|
353
|
-
constructor(message) {
|
|
354
|
-
super(message)
|
|
355
|
-
this.name = 'EmbedInitError'
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
class EmbedEmbedError extends FastEmbedError {
|
|
359
|
-
constructor(message) {
|
|
360
|
-
super(message)
|
|
361
|
-
this.name = 'EmbedEmbedError'
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
class EmbedMutexPoisonedError extends FastEmbedError {
|
|
365
|
-
constructor(message) {
|
|
366
|
-
super(message)
|
|
367
|
-
this.name = 'EmbedMutexPoisonedError'
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
class EmbedTaskPanickedError extends FastEmbedError {
|
|
371
|
-
constructor(message) {
|
|
372
|
-
super(message)
|
|
373
|
-
this.name = 'EmbedTaskPanickedError'
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
class TractError extends ProviderError {
|
|
378
|
-
constructor(message) {
|
|
379
|
-
super(message)
|
|
380
|
-
this.name = 'TractError'
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
// Peer subsystem
|
|
385
|
-
class PeerEncodeError extends BlazenError {
|
|
386
|
-
constructor(message) {
|
|
387
|
-
super(message)
|
|
388
|
-
this.name = 'PeerEncodeError'
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
class PeerTransportError extends BlazenError {
|
|
392
|
-
constructor(message) {
|
|
393
|
-
super(message)
|
|
394
|
-
this.name = 'PeerTransportError'
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
class PeerEnvelopeVersionError extends BlazenError {
|
|
398
|
-
constructor(message) {
|
|
399
|
-
super(message)
|
|
400
|
-
this.name = 'PeerEnvelopeVersionError'
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
class PeerWorkflowError extends BlazenError {
|
|
404
|
-
constructor(message) {
|
|
405
|
-
super(message)
|
|
406
|
-
this.name = 'PeerWorkflowError'
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
class PeerTlsError extends BlazenError {
|
|
410
|
-
constructor(message) {
|
|
411
|
-
super(message)
|
|
412
|
-
this.name = 'PeerTlsError'
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
class PeerUnknownStepError extends BlazenError {
|
|
416
|
-
constructor(message) {
|
|
417
|
-
super(message)
|
|
418
|
-
this.name = 'PeerUnknownStepError'
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
// Persist
|
|
423
|
-
class PersistError extends BlazenError {
|
|
424
|
-
constructor(message) {
|
|
425
|
-
super(message)
|
|
426
|
-
this.name = 'PersistError'
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
// Prompts
|
|
431
|
-
class PromptError extends BlazenError {
|
|
432
|
-
constructor(message) {
|
|
433
|
-
super(message)
|
|
434
|
-
this.name = 'PromptError'
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
class PromptMissingVariableError extends PromptError {
|
|
438
|
-
constructor(message) {
|
|
439
|
-
super(message)
|
|
440
|
-
this.name = 'PromptMissingVariableError'
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
class PromptNotFoundError extends PromptError {
|
|
444
|
-
constructor(message) {
|
|
445
|
-
super(message)
|
|
446
|
-
this.name = 'PromptNotFoundError'
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
class PromptVersionNotFoundError extends PromptError {
|
|
450
|
-
constructor(message) {
|
|
451
|
-
super(message)
|
|
452
|
-
this.name = 'PromptVersionNotFoundError'
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
class PromptIoError extends PromptError {
|
|
456
|
-
constructor(message) {
|
|
457
|
-
super(message)
|
|
458
|
-
this.name = 'PromptIoError'
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
class PromptYamlError extends PromptError {
|
|
462
|
-
constructor(message) {
|
|
463
|
-
super(message)
|
|
464
|
-
this.name = 'PromptYamlError'
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
class PromptJsonError extends PromptError {
|
|
468
|
-
constructor(message) {
|
|
469
|
-
super(message)
|
|
470
|
-
this.name = 'PromptJsonError'
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
class PromptValidationError extends PromptError {
|
|
474
|
-
constructor(message) {
|
|
475
|
-
super(message)
|
|
476
|
-
this.name = 'PromptValidationError'
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// Memory
|
|
481
|
-
class MemoryError extends BlazenError {
|
|
482
|
-
constructor(message) {
|
|
483
|
-
super(message)
|
|
484
|
-
this.name = 'MemoryError'
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
class MemoryNoEmbedderError extends MemoryError {
|
|
488
|
-
constructor(message) {
|
|
489
|
-
super(message)
|
|
490
|
-
this.name = 'MemoryNoEmbedderError'
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
class MemoryElidError extends MemoryError {
|
|
494
|
-
constructor(message) {
|
|
495
|
-
super(message)
|
|
496
|
-
this.name = 'MemoryElidError'
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
class MemoryEmbeddingError extends MemoryError {
|
|
500
|
-
constructor(message) {
|
|
501
|
-
super(message)
|
|
502
|
-
this.name = 'MemoryEmbeddingError'
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
class MemoryNotFoundError extends MemoryError {
|
|
506
|
-
constructor(message) {
|
|
507
|
-
super(message)
|
|
508
|
-
this.name = 'MemoryNotFoundError'
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
class MemorySerializationError extends MemoryError {
|
|
512
|
-
constructor(message) {
|
|
513
|
-
super(message)
|
|
514
|
-
this.name = 'MemorySerializationError'
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
class MemoryIoError extends MemoryError {
|
|
518
|
-
constructor(message) {
|
|
519
|
-
super(message)
|
|
520
|
-
this.name = 'MemoryIoError'
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
class MemoryBackendError extends MemoryError {
|
|
524
|
-
constructor(message) {
|
|
525
|
-
super(message)
|
|
526
|
-
this.name = 'MemoryBackendError'
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
// Model cache
|
|
531
|
-
class CacheError extends BlazenError {
|
|
532
|
-
constructor(message) {
|
|
533
|
-
super(message)
|
|
534
|
-
this.name = 'CacheError'
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
class DownloadError extends CacheError {
|
|
538
|
-
constructor(message) {
|
|
539
|
-
super(message)
|
|
540
|
-
this.name = 'DownloadError'
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
class CacheDirError extends CacheError {
|
|
544
|
-
constructor(message) {
|
|
545
|
-
super(message)
|
|
546
|
-
this.name = 'CacheDirError'
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
class IoError extends CacheError {
|
|
550
|
-
constructor(message) {
|
|
551
|
-
super(message)
|
|
552
|
-
this.name = 'IoError'
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
// ---------------------------------------------------------------------------
|
|
557
|
-
// Tag -> class registry
|
|
558
|
-
// ---------------------------------------------------------------------------
|
|
559
|
-
|
|
560
|
-
const TAG_TO_CLASS = {
|
|
561
|
-
// Core
|
|
562
|
-
BlazenError,
|
|
563
|
-
AuthError,
|
|
564
|
-
RateLimitError,
|
|
565
|
-
TimeoutError,
|
|
566
|
-
ValidationError,
|
|
567
|
-
ContentPolicyError,
|
|
568
|
-
UnsupportedError,
|
|
569
|
-
ComputeError,
|
|
570
|
-
MediaError,
|
|
571
|
-
ProviderError,
|
|
572
|
-
|
|
573
|
-
// LlamaCpp
|
|
574
|
-
LlamaCppError,
|
|
575
|
-
LlamaCppInvalidOptionsError,
|
|
576
|
-
LlamaCppModelLoadError,
|
|
577
|
-
LlamaCppInferenceError,
|
|
578
|
-
LlamaCppEngineNotAvailableError,
|
|
579
|
-
|
|
580
|
-
// Candle LLM
|
|
581
|
-
CandleLlmError,
|
|
582
|
-
CandleLlmInvalidOptionsError,
|
|
583
|
-
CandleLlmModelLoadError,
|
|
584
|
-
CandleLlmInferenceError,
|
|
585
|
-
CandleLlmEngineNotAvailableError,
|
|
586
|
-
|
|
587
|
-
// Candle Embed
|
|
588
|
-
CandleEmbedError,
|
|
589
|
-
CandleEmbedInvalidOptionsError,
|
|
590
|
-
CandleEmbedModelLoadError,
|
|
591
|
-
CandleEmbedEmbeddingError,
|
|
592
|
-
CandleEmbedEngineNotAvailableError,
|
|
593
|
-
CandleEmbedTaskPanickedError,
|
|
594
|
-
|
|
595
|
-
// MistralRs
|
|
596
|
-
MistralRsError,
|
|
597
|
-
MistralRsInvalidOptionsError,
|
|
598
|
-
MistralRsInitError,
|
|
599
|
-
MistralRsInferenceError,
|
|
600
|
-
MistralRsEngineNotAvailableError,
|
|
601
|
-
|
|
602
|
-
// Whisper
|
|
603
|
-
WhisperError,
|
|
604
|
-
WhisperInvalidOptionsError,
|
|
605
|
-
WhisperModelLoadError,
|
|
606
|
-
WhisperTranscriptionError,
|
|
607
|
-
WhisperEngineNotAvailableError,
|
|
608
|
-
WhisperIoError,
|
|
609
|
-
|
|
610
|
-
// Piper
|
|
611
|
-
PiperError,
|
|
612
|
-
PiperInvalidOptionsError,
|
|
613
|
-
PiperModelLoadError,
|
|
614
|
-
PiperSynthesisError,
|
|
615
|
-
PiperEngineNotAvailableError,
|
|
616
|
-
|
|
617
|
-
// Diffusion
|
|
618
|
-
DiffusionError,
|
|
619
|
-
DiffusionInvalidOptionsError,
|
|
620
|
-
DiffusionModelLoadError,
|
|
621
|
-
DiffusionGenerationError,
|
|
622
|
-
|
|
623
|
-
// Fastembed / Tract
|
|
624
|
-
FastEmbedError,
|
|
625
|
-
EmbedUnknownModelError,
|
|
626
|
-
EmbedInitError,
|
|
627
|
-
EmbedEmbedError,
|
|
628
|
-
EmbedMutexPoisonedError,
|
|
629
|
-
EmbedTaskPanickedError,
|
|
630
|
-
TractError,
|
|
631
|
-
|
|
632
|
-
// Peer
|
|
633
|
-
PeerEncodeError,
|
|
634
|
-
PeerTransportError,
|
|
635
|
-
PeerEnvelopeVersionError,
|
|
636
|
-
PeerWorkflowError,
|
|
637
|
-
PeerTlsError,
|
|
638
|
-
PeerUnknownStepError,
|
|
639
|
-
|
|
640
|
-
// Persist
|
|
641
|
-
PersistError,
|
|
642
|
-
|
|
643
|
-
// Prompts
|
|
644
|
-
PromptError,
|
|
645
|
-
PromptMissingVariableError,
|
|
646
|
-
PromptNotFoundError,
|
|
647
|
-
PromptVersionNotFoundError,
|
|
648
|
-
PromptIoError,
|
|
649
|
-
PromptYamlError,
|
|
650
|
-
PromptJsonError,
|
|
651
|
-
PromptValidationError,
|
|
652
|
-
|
|
653
|
-
// Memory
|
|
654
|
-
MemoryError,
|
|
655
|
-
MemoryNoEmbedderError,
|
|
656
|
-
MemoryElidError,
|
|
657
|
-
MemoryEmbeddingError,
|
|
658
|
-
MemoryNotFoundError,
|
|
659
|
-
MemorySerializationError,
|
|
660
|
-
MemoryIoError,
|
|
661
|
-
MemoryBackendError,
|
|
662
|
-
|
|
663
|
-
// Model cache
|
|
664
|
-
CacheError,
|
|
665
|
-
DownloadError,
|
|
666
|
-
CacheDirError,
|
|
667
|
-
IoError,
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
// Tag prefix regex. Matches `[Tag] rest-of-message`. The tag is restricted
|
|
671
|
-
// to ASCII letters/digits to avoid eating bracketed user content.
|
|
672
|
-
const TAG_RE = /^\[([A-Za-z][A-Za-z0-9]*)\]\s*([\s\S]*)$/
|
|
673
|
-
|
|
674
|
-
/**
|
|
675
|
-
* Given an `Error` thrown by a napi-rs function, parse the Rust-side
|
|
676
|
-
* `[Tag]` prefix and return a typed instance from the hierarchy above.
|
|
677
|
-
*
|
|
678
|
-
* If `err` is not an `Error`, or its message is not tagged, or the tag
|
|
679
|
-
* is unknown, the original error is returned unchanged.
|
|
680
|
-
*/
|
|
681
|
-
function enrichError(err) {
|
|
682
|
-
if (!(err instanceof Error)) {
|
|
683
|
-
return err
|
|
684
|
-
}
|
|
685
|
-
let message = err.message || ''
|
|
686
|
-
let providerPayload = null
|
|
687
|
-
|
|
688
|
-
// Detect and strip the provider-error sentinel (a JSON line followed by
|
|
689
|
-
// the human-readable `[ProviderError] ...` line).
|
|
690
|
-
if (message.startsWith(PROVIDER_ERROR_SENTINEL)) {
|
|
691
|
-
const newlineIdx = message.indexOf('\n')
|
|
692
|
-
if (newlineIdx !== -1) {
|
|
693
|
-
const jsonPart = message
|
|
694
|
-
.slice(PROVIDER_ERROR_SENTINEL.length, newlineIdx)
|
|
695
|
-
.trim()
|
|
696
|
-
try {
|
|
697
|
-
providerPayload = JSON.parse(jsonPart)
|
|
698
|
-
} catch {
|
|
699
|
-
providerPayload = null
|
|
700
|
-
}
|
|
701
|
-
message = message.slice(newlineIdx + 1)
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
const match = TAG_RE.exec(message)
|
|
706
|
-
if (!match) {
|
|
707
|
-
return err
|
|
708
|
-
}
|
|
709
|
-
const tag = match[1]
|
|
710
|
-
const rest = match[2]
|
|
711
|
-
const Cls = TAG_TO_CLASS[tag]
|
|
712
|
-
if (!Cls) {
|
|
713
|
-
return err
|
|
714
|
-
}
|
|
715
|
-
const enriched = new Cls(rest)
|
|
716
|
-
enriched.stack = err.stack
|
|
717
|
-
// Preserve the original napi `code` (e.g. 'GenericFailure') if present.
|
|
718
|
-
if (err.code !== undefined) {
|
|
719
|
-
enriched.code = err.code
|
|
720
|
-
}
|
|
721
|
-
if (providerPayload && enriched instanceof ProviderError) {
|
|
722
|
-
if (providerPayload.provider !== undefined) {
|
|
723
|
-
enriched.provider = providerPayload.provider
|
|
724
|
-
}
|
|
725
|
-
if (providerPayload.status !== undefined) {
|
|
726
|
-
enriched.status = providerPayload.status
|
|
727
|
-
}
|
|
728
|
-
if (providerPayload.endpoint !== undefined) {
|
|
729
|
-
enriched.endpoint = providerPayload.endpoint
|
|
730
|
-
}
|
|
731
|
-
if (providerPayload.requestId !== undefined) {
|
|
732
|
-
enriched.requestId = providerPayload.requestId
|
|
733
|
-
}
|
|
734
|
-
if (providerPayload.detail !== undefined) {
|
|
735
|
-
enriched.detail = providerPayload.detail
|
|
736
|
-
}
|
|
737
|
-
if (providerPayload.retryAfterMs !== undefined) {
|
|
738
|
-
enriched.retryAfterMs = providerPayload.retryAfterMs
|
|
739
|
-
}
|
|
740
|
-
}
|
|
741
|
-
return enriched
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
module.exports = {
|
|
745
|
-
// Core
|
|
746
|
-
BlazenError,
|
|
747
|
-
AuthError,
|
|
748
|
-
RateLimitError,
|
|
749
|
-
TimeoutError,
|
|
750
|
-
ValidationError,
|
|
751
|
-
ContentPolicyError,
|
|
752
|
-
UnsupportedError,
|
|
753
|
-
ComputeError,
|
|
754
|
-
MediaError,
|
|
755
|
-
ProviderError,
|
|
756
|
-
|
|
757
|
-
// LlamaCpp
|
|
758
|
-
LlamaCppError,
|
|
759
|
-
LlamaCppInvalidOptionsError,
|
|
760
|
-
LlamaCppModelLoadError,
|
|
761
|
-
LlamaCppInferenceError,
|
|
762
|
-
LlamaCppEngineNotAvailableError,
|
|
763
|
-
|
|
764
|
-
// Candle LLM
|
|
765
|
-
CandleLlmError,
|
|
766
|
-
CandleLlmInvalidOptionsError,
|
|
767
|
-
CandleLlmModelLoadError,
|
|
768
|
-
CandleLlmInferenceError,
|
|
769
|
-
CandleLlmEngineNotAvailableError,
|
|
770
|
-
|
|
771
|
-
// Candle Embed
|
|
772
|
-
CandleEmbedError,
|
|
773
|
-
CandleEmbedInvalidOptionsError,
|
|
774
|
-
CandleEmbedModelLoadError,
|
|
775
|
-
CandleEmbedEmbeddingError,
|
|
776
|
-
CandleEmbedEngineNotAvailableError,
|
|
777
|
-
CandleEmbedTaskPanickedError,
|
|
778
|
-
|
|
779
|
-
// MistralRs
|
|
780
|
-
MistralRsError,
|
|
781
|
-
MistralRsInvalidOptionsError,
|
|
782
|
-
MistralRsInitError,
|
|
783
|
-
MistralRsInferenceError,
|
|
784
|
-
MistralRsEngineNotAvailableError,
|
|
785
|
-
|
|
786
|
-
// Whisper
|
|
787
|
-
WhisperError,
|
|
788
|
-
WhisperInvalidOptionsError,
|
|
789
|
-
WhisperModelLoadError,
|
|
790
|
-
WhisperTranscriptionError,
|
|
791
|
-
WhisperEngineNotAvailableError,
|
|
792
|
-
WhisperIoError,
|
|
793
|
-
|
|
794
|
-
// Piper
|
|
795
|
-
PiperError,
|
|
796
|
-
PiperInvalidOptionsError,
|
|
797
|
-
PiperModelLoadError,
|
|
798
|
-
PiperSynthesisError,
|
|
799
|
-
PiperEngineNotAvailableError,
|
|
800
|
-
|
|
801
|
-
// Diffusion
|
|
802
|
-
DiffusionError,
|
|
803
|
-
DiffusionInvalidOptionsError,
|
|
804
|
-
DiffusionModelLoadError,
|
|
805
|
-
DiffusionGenerationError,
|
|
806
|
-
|
|
807
|
-
// Fastembed / Tract
|
|
808
|
-
FastEmbedError,
|
|
809
|
-
EmbedUnknownModelError,
|
|
810
|
-
EmbedInitError,
|
|
811
|
-
EmbedEmbedError,
|
|
812
|
-
EmbedMutexPoisonedError,
|
|
813
|
-
EmbedTaskPanickedError,
|
|
814
|
-
TractError,
|
|
815
|
-
|
|
816
|
-
// Peer
|
|
817
|
-
PeerEncodeError,
|
|
818
|
-
PeerTransportError,
|
|
819
|
-
PeerEnvelopeVersionError,
|
|
820
|
-
PeerWorkflowError,
|
|
821
|
-
PeerTlsError,
|
|
822
|
-
PeerUnknownStepError,
|
|
823
|
-
|
|
824
|
-
// Persist
|
|
825
|
-
PersistError,
|
|
826
|
-
|
|
827
|
-
// Prompts
|
|
828
|
-
PromptError,
|
|
829
|
-
PromptMissingVariableError,
|
|
830
|
-
PromptNotFoundError,
|
|
831
|
-
PromptVersionNotFoundError,
|
|
832
|
-
PromptIoError,
|
|
833
|
-
PromptYamlError,
|
|
834
|
-
PromptJsonError,
|
|
835
|
-
PromptValidationError,
|
|
836
|
-
|
|
837
|
-
// Memory
|
|
838
|
-
MemoryError,
|
|
839
|
-
MemoryNoEmbedderError,
|
|
840
|
-
MemoryElidError,
|
|
841
|
-
MemoryEmbeddingError,
|
|
842
|
-
MemoryNotFoundError,
|
|
843
|
-
MemorySerializationError,
|
|
844
|
-
MemoryIoError,
|
|
845
|
-
MemoryBackendError,
|
|
846
|
-
|
|
847
|
-
// Model cache
|
|
848
|
-
CacheError,
|
|
849
|
-
DownloadError,
|
|
850
|
-
CacheDirError,
|
|
851
|
-
IoError,
|
|
852
|
-
|
|
853
|
-
// Helper
|
|
854
|
-
enrichError,
|
|
855
|
-
}
|