@superlinked/sie-sdk 0.3.0 → 0.3.2
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/index.cjs +80 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -2
- package/dist/index.d.ts +35 -2
- package/dist/index.js +80 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -87,6 +87,28 @@ var ModelLoadingError = class extends SIEError {
|
|
|
87
87
|
this.model = model;
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
|
+
var ModelLoadFailedError = class extends ServerError {
|
|
91
|
+
/** The model that was requested */
|
|
92
|
+
model;
|
|
93
|
+
/**
|
|
94
|
+
* Server-side classification: one of `GATED`, `OOM`, `DEPENDENCY`,
|
|
95
|
+
* `NOT_FOUND`, `NETWORK`, `UNKNOWN`. Use this to route to specific
|
|
96
|
+
* remediation paths (e.g. surface a "set HF_TOKEN" hint for `GATED`).
|
|
97
|
+
*/
|
|
98
|
+
errorClass;
|
|
99
|
+
/** Whether the failure is non-retryable per server policy. */
|
|
100
|
+
permanent;
|
|
101
|
+
/** How many load attempts the server has logged. */
|
|
102
|
+
attempts;
|
|
103
|
+
constructor(message, options) {
|
|
104
|
+
super(message, "MODEL_LOAD_FAILED", 502);
|
|
105
|
+
this.name = "ModelLoadFailedError";
|
|
106
|
+
this.model = options?.model;
|
|
107
|
+
this.errorClass = options?.errorClass;
|
|
108
|
+
this.permanent = options?.permanent ?? true;
|
|
109
|
+
this.attempts = options?.attempts ?? 1;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
90
112
|
|
|
91
113
|
// src/internal/constants.ts
|
|
92
114
|
var MSGPACK_CONTENT_TYPE = "application/msgpack";
|
|
@@ -311,7 +333,7 @@ function getRetryAfter2(response) {
|
|
|
311
333
|
const header = response.headers.get("Retry-After");
|
|
312
334
|
return getRetryAfter(header);
|
|
313
335
|
}
|
|
314
|
-
async function
|
|
336
|
+
async function getErrorDetail(response) {
|
|
315
337
|
try {
|
|
316
338
|
const contentType = response.headers.get("content-type") ?? "";
|
|
317
339
|
let data;
|
|
@@ -322,40 +344,73 @@ async function getErrorCode(response) {
|
|
|
322
344
|
data = await response.json();
|
|
323
345
|
}
|
|
324
346
|
if (data.error && typeof data.error === "object") {
|
|
325
|
-
|
|
326
|
-
if (typeof error.code === "string") {
|
|
327
|
-
return error.code;
|
|
328
|
-
}
|
|
347
|
+
return data.error;
|
|
329
348
|
}
|
|
330
349
|
if (data.detail && typeof data.detail === "object") {
|
|
331
|
-
|
|
332
|
-
if (typeof detail.code === "string") {
|
|
333
|
-
return detail.code;
|
|
334
|
-
}
|
|
350
|
+
return data.detail;
|
|
335
351
|
}
|
|
336
352
|
if (typeof data.code === "string") {
|
|
337
|
-
return data
|
|
353
|
+
return data;
|
|
338
354
|
}
|
|
339
355
|
} catch {
|
|
340
356
|
}
|
|
341
357
|
return void 0;
|
|
342
358
|
}
|
|
359
|
+
async function getErrorCode(response) {
|
|
360
|
+
const detail = await getErrorDetail(response);
|
|
361
|
+
if (!detail) return void 0;
|
|
362
|
+
const code = detail.code;
|
|
363
|
+
return typeof code === "string" ? code : void 0;
|
|
364
|
+
}
|
|
365
|
+
async function throwIfModelLoadFailed(response, model) {
|
|
366
|
+
if (response.status !== 502) return;
|
|
367
|
+
const detail = await getErrorDetail(response.clone());
|
|
368
|
+
if (!detail) return;
|
|
369
|
+
if (detail.code !== "MODEL_LOAD_FAILED") return;
|
|
370
|
+
const errorClass = typeof detail.error_class === "string" ? detail.error_class : void 0;
|
|
371
|
+
const permanent = typeof detail.permanent === "boolean" ? detail.permanent : true;
|
|
372
|
+
const attemptsRaw = detail.attempts;
|
|
373
|
+
const parsedAttempts = typeof attemptsRaw === "number" ? attemptsRaw : typeof attemptsRaw === "string" ? Number.parseInt(attemptsRaw, 10) : Number.NaN;
|
|
374
|
+
const attempts = Number.isFinite(parsedAttempts) ? parsedAttempts : 1;
|
|
375
|
+
const message = typeof detail.message === "string" ? detail.message : `Model '${model ?? "?"}' failed to load`;
|
|
376
|
+
throw new ModelLoadFailedError(message, {
|
|
377
|
+
model,
|
|
378
|
+
errorClass,
|
|
379
|
+
permanent,
|
|
380
|
+
attempts
|
|
381
|
+
});
|
|
382
|
+
}
|
|
343
383
|
async function handleError(response, gpu) {
|
|
344
384
|
const { status } = response;
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
385
|
+
const detail = await getErrorDetail(response.clone());
|
|
386
|
+
let code;
|
|
387
|
+
let message;
|
|
388
|
+
if (detail) {
|
|
389
|
+
const c = detail.code;
|
|
390
|
+
code = typeof c === "string" ? c : void 0;
|
|
391
|
+
const m = detail.message;
|
|
392
|
+
message = typeof m === "string" ? m : JSON.stringify(detail);
|
|
393
|
+
} else {
|
|
394
|
+
try {
|
|
395
|
+
const data = await response.json();
|
|
396
|
+
if (typeof data.detail === "string") {
|
|
397
|
+
code = typeof data.code === "string" ? data.code : void 0;
|
|
398
|
+
message = data.detail;
|
|
399
|
+
} else if (typeof data.message === "string") {
|
|
400
|
+
code = typeof data.code === "string" ? data.code : void 0;
|
|
401
|
+
message = data.message;
|
|
402
|
+
} else {
|
|
403
|
+
code = typeof data.code === "string" ? data.code : void 0;
|
|
404
|
+
message = response.statusText;
|
|
405
|
+
}
|
|
406
|
+
} catch {
|
|
407
|
+
code = void 0;
|
|
408
|
+
message = response.statusText;
|
|
409
|
+
}
|
|
349
410
|
}
|
|
350
|
-
const code = errorBody.code ?? "UNKNOWN";
|
|
351
|
-
const message = errorBody.detail ?? response.statusText;
|
|
352
411
|
if (status === HTTP_ACCEPTED) {
|
|
353
|
-
const retryAfter = response
|
|
354
|
-
throw new ProvisioningError(
|
|
355
|
-
message,
|
|
356
|
-
gpu,
|
|
357
|
-
retryAfter ? Number.parseInt(retryAfter, 10) * 1e3 : void 0
|
|
358
|
-
);
|
|
412
|
+
const retryAfter = getRetryAfter2(response);
|
|
413
|
+
throw new ProvisioningError(message, gpu, retryAfter);
|
|
359
414
|
}
|
|
360
415
|
if (status >= HTTP_CLIENT_ERROR_MIN && status <= HTTP_CLIENT_ERROR_MAX) {
|
|
361
416
|
throw new RequestError(message, code, status);
|
|
@@ -476,7 +531,7 @@ function parseCapacityInfo(data, gpuFilter) {
|
|
|
476
531
|
}
|
|
477
532
|
|
|
478
533
|
// src/version.ts
|
|
479
|
-
var SDK_VERSION = "0.3.
|
|
534
|
+
var SDK_VERSION = "0.3.2";
|
|
480
535
|
|
|
481
536
|
// src/client.ts
|
|
482
537
|
function sleep(ms) {
|
|
@@ -1180,6 +1235,7 @@ var SIEClient = class {
|
|
|
1180
1235
|
await sleep(actualDelay);
|
|
1181
1236
|
continue;
|
|
1182
1237
|
}
|
|
1238
|
+
await throwIfModelLoadFailed(response, model);
|
|
1183
1239
|
if (response.status === 503) {
|
|
1184
1240
|
const clonedResponse = response.clone();
|
|
1185
1241
|
const errorCode = await getErrorCode(clonedResponse);
|
|
@@ -1502,6 +1558,7 @@ function detectImageFormat(bytes) {
|
|
|
1502
1558
|
}
|
|
1503
1559
|
|
|
1504
1560
|
exports.LoraLoadingError = LoraLoadingError;
|
|
1561
|
+
exports.ModelLoadFailedError = ModelLoadFailedError;
|
|
1505
1562
|
exports.ModelLoadingError = ModelLoadingError;
|
|
1506
1563
|
exports.PoolError = PoolError;
|
|
1507
1564
|
exports.ProvisioningError = ProvisioningError;
|