@vincemakes/kiso-provider-openai 0.26.1 → 0.26.3

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.
Files changed (2) hide show
  1. package/dist/index.js +14 -2
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@
16
16
  import { mkdirSync, writeFileSync } from "node:fs";
17
17
  import { join } from "node:path";
18
18
  import OpenAI from "openai";
19
- import { mapApiError } from "@vincemakes/kiso-core";
19
+ import { mapApiError, parseRetryAfter } from "@vincemakes/kiso-core";
20
20
  /**
21
21
  * High-level factory (round 7): builds the adapter FROM CONFIG, owning the SDK
22
22
  * inside this package. Consumers (and the runtime's lazy provider path)
@@ -28,6 +28,10 @@ export function createOpenAICompatProvider(config = {}) {
28
28
  const client = new OpenAI({
29
29
  ...(config.apiKey !== undefined ? { apiKey: config.apiKey } : {}),
30
30
  ...(config.baseUrl !== undefined ? { baseURL: config.baseUrl } : {}),
31
+ // CX-1 F8: ONE retry authority — the kernel. The SDK's implicit two
32
+ // retries used to run beneath the kernel's budget (maxRetries = 0
33
+ // still made three requests) and beneath the request trace.
34
+ maxRetries: 0,
31
35
  });
32
36
  const origin = (() => {
33
37
  if (config.baseUrl === undefined)
@@ -440,6 +444,13 @@ function vendorOf(model) {
440
444
  const id = model.split("/").at(-1) ?? model;
441
445
  return (id.split("-")[0] ?? id).toLowerCase();
442
446
  }
447
+ function retryAfterOf(headers) {
448
+ if (headers === null || typeof headers !== "object")
449
+ return undefined;
450
+ const h = headers;
451
+ const raw = typeof h.get === "function" ? h.get("retry-after") : (h["retry-after"] ?? h["Retry-After"]);
452
+ return parseRetryAfter(typeof raw === "string" ? raw : undefined);
453
+ }
443
454
  function toOpenAIError(err, model) {
444
455
  const label = `[${vendorOf(model)}] request failed: `;
445
456
  // D4: connection-level failures are recognized, not lumped into unknown.
@@ -450,7 +461,8 @@ function toOpenAIError(err, model) {
450
461
  return { code: "network", retryable: true, message: label + err.message };
451
462
  }
452
463
  if (err instanceof OpenAI.APIError) {
453
- return mapApiError(err.status, label + err.message);
464
+ // CX-1 F8: the kernel owns retries — Retry-After travels with the error
465
+ return mapApiError(err.status, label + err.message, retryAfterOf(err.headers));
454
466
  }
455
467
  return err;
456
468
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vincemakes/kiso-provider-openai",
3
- "version": "0.26.1",
3
+ "version": "0.26.3",
4
4
  "description": "kiso OpenAI-compatible adapter — OpenAI + the compat family (GLM, Kimi, DeepSeek, OpenRouter) via base_url swap, reasoning dialects digested.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -21,7 +21,7 @@
21
21
  "test": "vitest run"
22
22
  },
23
23
  "dependencies": {
24
- "@vincemakes/kiso-core": "0.26.1",
24
+ "@vincemakes/kiso-core": "0.26.3",
25
25
  "openai": "^7.3.0"
26
26
  },
27
27
  "devDependencies": {