@superlinked/sie-sdk 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 getErrorCode(response) {
336
+ async function getErrorDetail(response) {
315
337
  try {
316
338
  const contentType = response.headers.get("content-type") ?? "";
317
339
  let data;
@@ -322,24 +344,42 @@ async function getErrorCode(response) {
322
344
  data = await response.json();
323
345
  }
324
346
  if (data.error && typeof data.error === "object") {
325
- const error = data.error;
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
- const detail = data.detail;
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.code;
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
385
  let errorBody = {};
@@ -476,7 +516,7 @@ function parseCapacityInfo(data, gpuFilter) {
476
516
  }
477
517
 
478
518
  // src/version.ts
479
- var SDK_VERSION = "0.3.0";
519
+ var SDK_VERSION = "0.3.1";
480
520
 
481
521
  // src/client.ts
482
522
  function sleep(ms) {
@@ -1180,6 +1220,7 @@ var SIEClient = class {
1180
1220
  await sleep(actualDelay);
1181
1221
  continue;
1182
1222
  }
1223
+ await throwIfModelLoadFailed(response, model);
1183
1224
  if (response.status === 503) {
1184
1225
  const clonedResponse = response.clone();
1185
1226
  const errorCode = await getErrorCode(clonedResponse);
@@ -1502,6 +1543,7 @@ function detectImageFormat(bytes) {
1502
1543
  }
1503
1544
 
1504
1545
  exports.LoraLoadingError = LoraLoadingError;
1546
+ exports.ModelLoadFailedError = ModelLoadFailedError;
1505
1547
  exports.ModelLoadingError = ModelLoadingError;
1506
1548
  exports.PoolError = PoolError;
1507
1549
  exports.ProvisioningError = ProvisioningError;