@jaypie/llm 1.2.28 → 1.2.29

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.
@@ -3340,10 +3340,29 @@ class OpenRouterAdapter extends BaseProviderAdapter {
3340
3340
  // Export singleton instance
3341
3341
  const openRouterAdapter = new OpenRouterAdapter();
3342
3342
 
3343
+ /**
3344
+ * Error-message substrings that indicate a transient xAI media-ingest flake.
3345
+ * The xAI ingest service enters a bad state after ~12 consecutive file-bearing
3346
+ * calls and rejects subsequent requests with HTTP 400. The condition is
3347
+ * self-clearing, so these errors should be retried with backoff rather than
3348
+ * surfaced as unrecoverable.
3349
+ *
3350
+ * See: github.com/finlaysonstudio/jaypie issue #301
3351
+ */
3352
+ const TRANSIENT_INGEST_MESSAGE_PATTERNS = [
3353
+ "failed to ingest inline file bytes",
3354
+ ];
3355
+ function isTransientIngestError(error) {
3356
+ if (!(error instanceof openai.BadRequestError))
3357
+ return false;
3358
+ const message = (error.message ?? "").toLowerCase();
3359
+ return TRANSIENT_INGEST_MESSAGE_PATTERNS.some((pattern) => message.includes(pattern));
3360
+ }
3343
3361
  /**
3344
3362
  * XaiAdapter extends OpenAiAdapter since xAI (Grok) uses an OpenAI-compatible API.
3345
- * Only the name and default model are overridden; all request building, response parsing,
3346
- * error classification, tool handling, and streaming are inherited.
3363
+ * Name, default model, and transient-ingest-error detection are overridden;
3364
+ * all request building, response parsing, tool handling, and streaming are
3365
+ * inherited.
3347
3366
  */
3348
3367
  class XaiAdapter extends OpenAiAdapter {
3349
3368
  constructor() {
@@ -3353,6 +3372,16 @@ class XaiAdapter extends OpenAiAdapter {
3353
3372
  // @ts-expect-error Narrowing override: xAI default model differs from parent's literal
3354
3373
  this.defaultModel = PROVIDER.XAI.MODEL.DEFAULT;
3355
3374
  }
3375
+ classifyError(error) {
3376
+ if (isTransientIngestError(error)) {
3377
+ return {
3378
+ error,
3379
+ category: ErrorCategory.Retryable,
3380
+ shouldRetry: true,
3381
+ };
3382
+ }
3383
+ return super.classifyError(error);
3384
+ }
3356
3385
  }
3357
3386
  // Export singleton instance
3358
3387
  const xaiAdapter = new XaiAdapter();