@plurnk/plurnk-providers 1.6.1 → 1.7.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 CHANGED
@@ -21,16 +21,18 @@ reasoning activation, and estimated prices resolve independently
21
21
  ({§model-fact-resolution}). PLURNK does not fetch live per-token prices, and the
22
22
  local estimate is not an authoritative relay-settled charge.
23
23
 
24
- ## Runtime-neutral accounting
24
+ ## Runtime-neutral contracts
25
25
 
26
- Browser and edge Workers import the accounting contract through its dedicated
27
- runtime-neutral subpath ({§provider-runtime-neutral-accounting}):
26
+ Browser and edge Workers import accounting and normalized failures through
27
+ their dedicated runtime-neutral subpaths
28
+ ({§provider-runtime-neutral-accounting}, {§provider-runtime-neutral-errors}):
28
29
 
29
30
  ```js
30
31
  import {
31
32
  aggregateProviderAccounting,
32
33
  estimateProviderCost,
33
34
  } from "@plurnk/plurnk-providers/accounting";
35
+ import { ProviderError } from "@plurnk/plurnk-providers/errors";
34
36
  ```
35
37
 
36
38
  The package root composes the complete Node provider runtime, including plugin
package/SPEC.md CHANGED
@@ -22,13 +22,17 @@ model prefix, context window, price, or vendor request shape into a PLURNK
22
22
  table. A missing or wrong catalog fact is fixed upstream, overridden through a
23
23
  provider declaration, or left explicitly unknown.
24
24
 
25
- §provider-runtime-neutral-accounting The public
26
- `@plurnk/plurnk-providers/accounting` subpath exposes provider-request
27
- aggregation and Models.dev cost estimation, plus their wire types, without
28
- evaluating Node-only provider discovery, filesystem defaults, or runtime
29
- construction. It re-exports the package's sole accounting implementation. The
30
- package root remains the Node provider-runtime composition surface and is not a
31
- Worker entrypoint.
25
+ The package exposes two runtime-neutral public surfaces:
26
+
27
+ | Surface | Contract |
28
+ | --- | --- |
29
+ | §provider-runtime-neutral-accounting `@plurnk/plurnk-providers/accounting` | Provider-request aggregation, Models.dev cost estimation, and their wire types. |
30
+ | §provider-runtime-neutral-errors `@plurnk/plurnk-providers/errors` | Normalized `ProviderError`, `ProviderErrorKind`, and the types of its attempt, accounting, and capacity evidence. |
31
+
32
+ Both surfaces re-export the package's sole implementations without evaluating
33
+ Node-only provider discovery, filesystem defaults, or runtime construction.
34
+ The package root remains the Node provider-runtime composition surface and is
35
+ not a Worker entrypoint.
32
36
 
33
37
  ## §2 Provider interface
34
38
 
package/dist/errors.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { type ProblemDetails } from "@plurnk/plurnk-contracts";
2
- import type { ProviderAttempt, ProviderRequestAccounting, ProviderRequestCapacity } from "./types.ts";
3
- export type ProviderErrorKind = "rate_limit" | "network_failure" | "deadline_exceeded" | "model_refused" | "invalid_response" | "unauthorized" | "quota_exceeded" | "grammar_invalid" | "capacity_exceeded" | "resource_interrupted";
1
+ import { ProviderError } from "./providerError.ts";
2
+ import type { ProviderErrorKind } from "./providerError.ts";
3
+ import type { ProviderRequestCapacity } from "./types.ts";
4
+ export { ProviderError } from "./providerError.ts";
5
+ export type { ProviderErrorKind } from "./providerError.ts";
4
6
  export interface ClassifiedProviderError {
5
7
  kind: ProviderErrorKind;
6
8
  message: string;
@@ -16,26 +18,6 @@ export declare class ProviderTimeoutError extends Error {
16
18
  constructor(phase: ProviderTimeoutPhase, timeoutMs: number, cause?: unknown);
17
19
  }
18
20
  export declare const providerTimeoutOf: (error: unknown) => ProviderTimeoutError | null;
19
- export declare class ProviderError extends Error {
20
- #private;
21
- readonly source: string;
22
- readonly kind: ProviderErrorKind;
23
- readonly problem: ProblemDetails;
24
- readonly attempt?: ProviderAttempt;
25
- readonly capacity?: ProviderRequestCapacity;
26
- constructor(source: string, kind: ProviderErrorKind, message: string, options?: {
27
- status?: number | null;
28
- cause?: unknown;
29
- retryable?: boolean;
30
- extensions?: Readonly<Record<string, unknown>>;
31
- attempt?: ProviderAttempt;
32
- accounting?: readonly ProviderRequestAccounting[];
33
- capacity?: ProviderRequestCapacity;
34
- });
35
- get status(): number;
36
- get accounting(): readonly ProviderRequestAccounting[];
37
- prependAccounting(accounting: readonly ProviderRequestAccounting[]): void;
38
- }
39
21
  export declare const classifyProviderError: (err: unknown, detailLimit?: number) => ClassifiedProviderError;
40
22
  export declare const toProviderError: (err: unknown, source: string, detailLimit?: number, capacity?: ProviderRequestCapacity) => ProviderError;
41
23
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAGzE,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAEtG,MAAM,MAAM,iBAAiB,GACvB,YAAY,GACZ,iBAAiB,GACjB,mBAAmB,GACnB,eAAe,GACf,kBAAkB,GAClB,cAAc,GACd,gBAAgB,GAChB,iBAAiB,GACjB,mBAAmB,GACnB,sBAAsB,CAAC;AAE7B,MAAM,WAAW,uBAAuB;IACpC,IAAI,EAAE,iBAAiB,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAClD;AAED,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,eAAe,GAAG,aAAa,GAAG,WAAW,CAAC;AAE7F,qBAAa,oBAAqB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CAAC;IACrC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,YAAY,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,EAW1E;CACJ;AAED,eAAO,MAAM,iBAAiB,UAAW,OAAO,KAAG,oBAAoB,GAAG,IASzE,C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O,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D,MAAM,WAAW,uBAAuB;IACpC,IAAI,EAAE,iBAAiB,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAClD;AAED,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,eAAe,GAAG,aAAa,GAAG,WAAW,CAAC;AAE7F,qBAAa,oBAAqB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CAAC;IACrC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,YAAY,KAAK,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,EAW1E;CACJ;AAED,eAAO,MAAM,iBAAiB,UAAW,OAAO,KAAG,oBAAoB,GAAG,IASzE,CAAC;AA0BF,eAAO,MAAM,qBAAqB,QACzB,OAAO,gBACE,MAAM,KACrB,uBAuEF,CAAC;AAEF,eAAO,MAAM,eAAe,QACnB,OAAO,UACJ,MAAM,gBACA,MAAM,aACT,uBAAuB,KACnC,aAsBF,CAAC"}
package/dist/errors.js CHANGED
@@ -1,6 +1,6 @@
1
- import { Problems } from "@plurnk/plurnk-contracts";
2
1
  import { APICallError, RetryError } from "ai";
3
- import { providerSource } from "./notices.js";
2
+ import { ProviderError } from "./providerError.js";
3
+ export { ProviderError } from "./providerError.js";
4
4
  export class ProviderTimeoutError extends Error {
5
5
  phase;
6
6
  timeoutMs;
@@ -28,94 +28,6 @@ export const providerTimeoutOf = (error) => {
28
28
  }
29
29
  return null;
30
30
  };
31
- const defaultStatus = (kind) => {
32
- switch (kind) {
33
- case "unauthorized": return 401;
34
- case "quota_exceeded": return 402;
35
- case "capacity_exceeded": return 413;
36
- case "rate_limit": return 429;
37
- case "model_refused":
38
- case "grammar_invalid": return 422;
39
- case "invalid_response": return 502;
40
- case "deadline_exceeded": return 504;
41
- case "network_failure":
42
- case "resource_interrupted": return 503;
43
- }
44
- };
45
- const retryable = (kind) => {
46
- switch (kind) {
47
- case "rate_limit":
48
- case "network_failure":
49
- return true;
50
- case "deadline_exceeded":
51
- case "invalid_response":
52
- case "grammar_invalid":
53
- case "capacity_exceeded":
54
- case "resource_interrupted":
55
- case "model_refused":
56
- case "unauthorized":
57
- case "quota_exceeded":
58
- return false;
59
- }
60
- };
61
- const buildProblem = (source, kind, message, status, extensions, retryableOverride) => {
62
- const code = {
63
- rate_limit: "rate-limit",
64
- network_failure: "network-failure",
65
- deadline_exceeded: "deadline-exceeded",
66
- model_refused: "model-refused",
67
- invalid_response: "invalid-response",
68
- unauthorized: "unauthorized",
69
- quota_exceeded: "quota-exceeded",
70
- grammar_invalid: "grammar-invalid",
71
- capacity_exceeded: "capacity-exceeded",
72
- resource_interrupted: "resource-interrupted",
73
- };
74
- return Problems.create(source, code[kind], status, message, {
75
- providerKind: kind,
76
- stage: "provider-request",
77
- retryable: retryableOverride ?? retryable(kind),
78
- ...extensions,
79
- });
80
- };
81
- // A provider operation failed before a completed exchange existed. An
82
- // interrupted response may still carry attempt evidence for its consumer.
83
- // The standardized Problem is the public failure contract; kind remains the
84
- // provider pool's routing discriminator and is repeated as a Problem extension.
85
- export class ProviderError extends Error {
86
- source;
87
- kind;
88
- problem;
89
- attempt;
90
- capacity;
91
- #accounting;
92
- constructor(source, kind, message, options = {}) {
93
- super(message, options.cause !== undefined ? { cause: options.cause } : undefined);
94
- this.name = "ProviderError";
95
- this.source = providerSource(source);
96
- this.kind = kind;
97
- this.attempt = options.attempt;
98
- this.capacity = options.capacity ?? options.attempt?.capacity;
99
- this.#accounting = [...(options.accounting ?? options.attempt?.accounting ?? [])];
100
- const status = options.status !== null && options.status !== undefined
101
- && Number.isInteger(options.status) && options.status >= 400 && options.status <= 599
102
- ? options.status
103
- : defaultStatus(kind);
104
- this.problem = buildProblem(this.source, kind, message, status, options.extensions ?? {}, options.retryable);
105
- }
106
- get status() {
107
- return this.problem.status;
108
- }
109
- get accounting() {
110
- return this.#accounting;
111
- }
112
- // A capacity pool adds the already-settled requests from prior backends as
113
- // the same failure crosses that orchestration boundary.
114
- prependAccounting(accounting) {
115
- if (accounting.length > 0)
116
- this.#accounting = [...accounting, ...this.#accounting];
117
- }
118
- }
119
31
  const wireError = (body) => {
120
32
  try {
121
33
  const { error } = JSON.parse(body);
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAuB,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AA0B9C,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAClC,KAAK,CAAuB;IAC5B,SAAS,CAAS;IAE3B,YAAY,KAA2B,EAAE,SAAiB,EAAE,KAAe;QACvE,MAAM,MAAM,GAAyC;YACjD,OAAO,EAAE,kBAAkB;YAC3B,aAAa,EAAE,wBAAwB;YACvC,WAAW,EAAE,sBAAsB;YACnC,SAAS,EAAE,oBAAoB;SAClC,CAAC;QACF,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,iBAAiB,SAAS,eAAe,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAC9G,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,KA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AAI,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE;QAC5C,MAAM;QACN,KAAK,EAAE,GAAG;QACV,SAAS,EAAE,UAAU,CAAC,SAAS;QAC/B,UAAU,EAAE;YACR,GAAG,CAAC,UAAU,CAAC,UAAU,IAAI,EAAE,CAAC;YAChC,GAAG,CAAC,IAAI,KAAK,mBAAmB,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACtE,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC;YAC/C,GAAG,CAAC,UAAU,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC;YAC/E,GAAG,CAAC,UAAU,CAAC,cAAc,KAAK,SAAS;gBACvC,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,EAAE,cAAc,EAAE,UAAU,CAAC,cAAc,EAAE,CAAC;SACvD;QACD,QAAQ;KACX,CAAC,CAAC;AACP,CAAC,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { type ProblemDetails } from "@plurnk/plurnk-contracts";
2
+ import type { ProviderAttempt, ProviderRequestAccounting, ProviderRequestCapacity } from "./types.ts";
3
+ export type ProviderErrorKind = "rate_limit" | "network_failure" | "deadline_exceeded" | "model_refused" | "invalid_response" | "unauthorized" | "quota_exceeded" | "grammar_invalid" | "capacity_exceeded" | "resource_interrupted";
4
+ export declare class ProviderError extends Error {
5
+ #private;
6
+ readonly source: string;
7
+ readonly kind: ProviderErrorKind;
8
+ readonly problem: ProblemDetails;
9
+ readonly attempt?: ProviderAttempt;
10
+ readonly capacity?: ProviderRequestCapacity;
11
+ constructor(source: string, kind: ProviderErrorKind, message: string, options?: {
12
+ status?: number | null;
13
+ cause?: unknown;
14
+ retryable?: boolean;
15
+ extensions?: Readonly<Record<string, unknown>>;
16
+ attempt?: ProviderAttempt;
17
+ accounting?: readonly ProviderRequestAccounting[];
18
+ capacity?: ProviderRequestCapacity;
19
+ });
20
+ get status(): number;
21
+ get accounting(): readonly ProviderRequestAccounting[];
22
+ prependAccounting(accounting: readonly ProviderRequestAccounting[]): void;
23
+ }
24
+ export type { ProviderAttempt, ProviderRequestAccounting, ProviderRequestCapacity } from "./types.ts";
25
+ //# sourceMappingURL=providerError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providerError.d.ts","sourceRoot":"","sources":["../src/providerError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAEzE,OAAO,KAAK,EAAE,eAAe,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAEtG,MAAM,MAAM,iBAAiB,GACvB,YAAY,GACZ,iBAAiB,GACjB,mBAAmB,GACnB,eAAe,GACf,kBAAkB,GAClB,cAAc,GACd,gBAAgB,GAChB,iBAAiB,GACjB,mBAAmB,GACnB,sBAAsB,CAAC;AAkE7B,qBAAa,aAAc,SAAQ,KAAK;;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,CAAC;IACnC,QAAQ,CAAC,QAAQ,CAAC,EAAE,uBAAuB,CAAC;IAG5C,YACI,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,iBAAiB,EACvB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QACL,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QACvB,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QAC/C,OAAO,CAAC,EAAE,eAAe,CAAC;QAC1B,UAAU,CAAC,EAAE,SAAS,yBAAyB,EAAE,CAAC;QAClD,QAAQ,CAAC,EAAE,uBAAuB,CAAC;KACjC,EAqBT;IAED,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,UAAU,IAAI,SAAS,yBAAyB,EAAE,CAErD;IAID,iBAAiB,CAAC,UAAU,EAAE,SAAS,yBAAyB,EAAE,GAAG,IAAI,CAExE;CACJ;AAED,YAAY,EAAE,eAAe,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,91 @@
1
+ import { Problems } from "@plurnk/plurnk-contracts";
2
+ import { providerSource } from "./notices.js";
3
+ const defaultStatus = (kind) => {
4
+ switch (kind) {
5
+ case "unauthorized": return 401;
6
+ case "quota_exceeded": return 402;
7
+ case "capacity_exceeded": return 413;
8
+ case "rate_limit": return 429;
9
+ case "model_refused":
10
+ case "grammar_invalid": return 422;
11
+ case "invalid_response": return 502;
12
+ case "deadline_exceeded": return 504;
13
+ case "network_failure":
14
+ case "resource_interrupted": return 503;
15
+ }
16
+ };
17
+ const retryable = (kind) => {
18
+ switch (kind) {
19
+ case "rate_limit":
20
+ case "network_failure":
21
+ return true;
22
+ case "deadline_exceeded":
23
+ case "invalid_response":
24
+ case "grammar_invalid":
25
+ case "capacity_exceeded":
26
+ case "resource_interrupted":
27
+ case "model_refused":
28
+ case "unauthorized":
29
+ case "quota_exceeded":
30
+ return false;
31
+ }
32
+ };
33
+ const buildProblem = (source, kind, message, status, extensions, retryableOverride) => {
34
+ const code = {
35
+ rate_limit: "rate-limit",
36
+ network_failure: "network-failure",
37
+ deadline_exceeded: "deadline-exceeded",
38
+ model_refused: "model-refused",
39
+ invalid_response: "invalid-response",
40
+ unauthorized: "unauthorized",
41
+ quota_exceeded: "quota-exceeded",
42
+ grammar_invalid: "grammar-invalid",
43
+ capacity_exceeded: "capacity-exceeded",
44
+ resource_interrupted: "resource-interrupted",
45
+ };
46
+ return Problems.create(source, code[kind], status, message, {
47
+ providerKind: kind,
48
+ stage: "provider-request",
49
+ retryable: retryableOverride ?? retryable(kind),
50
+ ...extensions,
51
+ });
52
+ };
53
+ // A provider operation failed before a completed exchange existed. An
54
+ // interrupted response may still carry attempt evidence for its consumer.
55
+ // The standardized Problem is the public failure contract; kind remains the
56
+ // provider pool's routing discriminator and is repeated as a Problem extension.
57
+ export class ProviderError extends Error {
58
+ source;
59
+ kind;
60
+ problem;
61
+ attempt;
62
+ capacity;
63
+ #accounting;
64
+ constructor(source, kind, message, options = {}) {
65
+ super(message, options.cause !== undefined ? { cause: options.cause } : undefined);
66
+ this.name = "ProviderError";
67
+ this.source = providerSource(source);
68
+ this.kind = kind;
69
+ this.attempt = options.attempt;
70
+ this.capacity = options.capacity ?? options.attempt?.capacity;
71
+ this.#accounting = [...(options.accounting ?? options.attempt?.accounting ?? [])];
72
+ const status = options.status !== null && options.status !== undefined
73
+ && Number.isInteger(options.status) && options.status >= 400 && options.status <= 599
74
+ ? options.status
75
+ : defaultStatus(kind);
76
+ this.problem = buildProblem(this.source, kind, message, status, options.extensions ?? {}, options.retryable);
77
+ }
78
+ get status() {
79
+ return this.problem.status;
80
+ }
81
+ get accounting() {
82
+ return this.#accounting;
83
+ }
84
+ // A capacity pool adds the already-settled requests from prior backends as
85
+ // the same failure crosses that orchestration boundary.
86
+ prependAccounting(accounting) {
87
+ if (accounting.length > 0)
88
+ this.#accounting = [...accounting, ...this.#accounting];
89
+ }
90
+ }
91
+ //# sourceMappingURL=providerError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providerError.js","sourceRoot":"","sources":["../src/providerError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAuB,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAe9C,MAAM,aAAa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,GAAG,OAAO,CAAC,MAAM,KAAK,IAAI,IAAI,OAAO,CAAC,MAAM,KAAK,SAAS;eAC/D,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,MAAM,IAAI,GAAG,IAAI,OAAO,CAAC,MAAM,IAAI,GAAG;YACrF,CAAC,CAAC,OAAO,CAAC,MAAM;YAChB,CAAC,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,YAAY,CACvB,IAAI,CAAC,MAAM,EACX,IAAI,EACJ,OAAO,EACP,MAAM,EACN,OAAO,CAAC,UAAU,IAAI,EAAE,EACxB,OAAO,CAAC,SAAS,CACpB,CAAC;IACN,CAAC;IAED,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED,IAAI,UAAU;QACV,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED,2EAA2E;IAC3E,wDAAwD;IACxD,iBAAiB,CAAC,UAAgD;QAC9D,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC;YAAE,IAAI,CAAC,WAAW,GAAG,CAAC,GAAG,UAAU,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,CAAC;IACvF,CAAC;CACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plurnk/plurnk-providers",
3
- "version": "1.6.1",
3
+ "version": "1.7.0",
4
4
  "description": "PLURNK's stable model-provider contract and AI SDK adapter.",
5
5
  "keywords": [
6
6
  "plurnk",
@@ -42,6 +42,11 @@
42
42
  "types": "./dist/accountingPublic.d.ts",
43
43
  "default": "./dist/accountingPublic.js"
44
44
  },
45
+ "./errors": {
46
+ "plurnk-dev": "./src/providerError.ts",
47
+ "types": "./dist/providerError.d.ts",
48
+ "default": "./dist/providerError.js"
49
+ },
45
50
  "./package.json": "./package.json"
46
51
  },
47
52
  "files": [
@@ -58,7 +63,7 @@
58
63
  "test:providersPing": "bash ../scripts/operator-environment.sh node --conditions=plurnk-dev --import=../plurnk-core/test/floor.ts --env-file-if-exists=../plurnk-core/.env.defaults --env-file-if-exists=$HOME/.plurnk/.env --env-file-if-exists=../plurnk-core/.env --env-file-if-exists=../plurnk-core/.env.test scripts/providers-ping.mjs",
59
64
  "probe:tokens": "bash ../scripts/operator-environment.sh node --conditions=plurnk-dev --import=../plurnk-core/test/floor.ts --env-file-if-exists=../plurnk-core/.env.defaults --env-file-if-exists=$HOME/.plurnk/.env --env-file-if-exists=../plurnk-core/.env --env-file-if-exists=../plurnk-core/.env.test scripts/token-envelope-probe.mjs",
60
65
  "test": "npm run test:lint && npm run test:unit",
61
- "release:check": "node scripts/accounting-worker-smoke.mjs",
66
+ "release:check": "node scripts/runtime-neutral-worker-smoke.mjs",
62
67
  "prepublishOnly": "npm audit --audit-level=moderate && npm test && npm run build && npm run release:check",
63
68
  "build:clean": "rm -rf dist",
64
69
  "build:dist": "tsc -p tsconfig.build.json",
@@ -78,11 +83,11 @@
78
83
  "@ai-sdk/togetherai": "^3.0.0",
79
84
  "@ai-sdk/xai": "^4.0.0",
80
85
  "@openrouter/ai-sdk-provider": "^3.0.0",
81
- "@plurnk/gbnf": "1.6.1",
82
- "@plurnk/plurnk-aliases": "1.6.1",
83
- "@plurnk/plurnk-contracts": "1.6.1",
84
- "@plurnk/plurnk-meta": "1.6.1",
85
- "@plurnk/plurnk-models": "1.6.1",
86
+ "@plurnk/gbnf": "1.7.0",
87
+ "@plurnk/plurnk-aliases": "1.7.0",
88
+ "@plurnk/plurnk-contracts": "1.7.0",
89
+ "@plurnk/plurnk-meta": "1.7.0",
90
+ "@plurnk/plurnk-models": "1.7.0",
86
91
  "ai": "^7.0.37",
87
92
  "zod": "^3.25.76"
88
93
  },
@@ -26,8 +26,24 @@ test("provider source does not import the PLURNK parser", () => {
26
26
  }
27
27
  });
28
28
 
29
+ const assertRuntimeNeutralGraph = (entrypoint: string, allowed: ReadonlySet<string>): void => {
30
+ const pending = [entrypoint];
31
+ const visited = new Set<string>();
32
+ while (pending.length > 0) {
33
+ const file = pending.pop()!;
34
+ if (visited.has(file)) continue;
35
+ visited.add(file);
36
+ assert.ok(allowed.has(file), `${entrypoint} reaches ${file}`);
37
+ const source = readFileSync(join(root, file), "utf8");
38
+ assert.doesNotMatch(source, /from\s+["']node:/, `${file} imports a Node built-in`);
39
+ for (const match of source.matchAll(/from\s+["']\.\/([^"']+)\.ts["']/g)) {
40
+ pending.push(`${match[1]}.ts`);
41
+ }
42
+ }
43
+ };
44
+
29
45
  test("the OpenAI-compatible entrypoint excludes Node-owned provider machinery", () => {
30
- const allowed = new Set([
46
+ assertRuntimeNeutralGraph("openai.ts", new Set([
31
47
  "accounting.ts",
32
48
  "AiSdkProvider.ts",
33
49
  "aiSdkTransport.ts",
@@ -38,21 +54,17 @@ test("the OpenAI-compatible entrypoint excludes Node-owned provider machinery",
38
54
  "notices.ts",
39
55
  "openai.ts",
40
56
  "promptTokens.ts",
57
+ "providerError.ts",
41
58
  "types.ts",
42
59
  "usage.ts",
43
60
  "warnings.ts",
44
- ]);
45
- const pending = ["openai.ts"];
46
- const visited = new Set<string>();
47
- while (pending.length > 0) {
48
- const file = pending.pop()!;
49
- if (visited.has(file)) continue;
50
- visited.add(file);
51
- assert.ok(allowed.has(file), `runtime-neutral entrypoint reaches ${file}`);
52
- const source = readFileSync(join(root, file), "utf8");
53
- assert.doesNotMatch(source, /from\s+["']node:/, `${file} imports a Node built-in`);
54
- for (const match of source.matchAll(/from\s+["']\.\/([^"']+)\.ts["']/g)) {
55
- pending.push(`${match[1]}.ts`);
56
- }
57
- }
61
+ ]));
62
+ });
63
+
64
+ test("the normalized-error entrypoint excludes transport and Node machinery", () => {
65
+ assertRuntimeNeutralGraph("providerError.ts", new Set([
66
+ "notices.ts",
67
+ "providerError.ts",
68
+ "types.ts",
69
+ ]));
58
70
  });
package/src/errors.ts CHANGED
@@ -1,19 +1,10 @@
1
- import { Problems, type ProblemDetails } from "@plurnk/plurnk-contracts";
2
1
  import { APICallError, RetryError } from "ai";
3
- import { providerSource } from "./notices.ts";
4
- import type { ProviderAttempt, ProviderRequestAccounting, ProviderRequestCapacity } from "./types.ts";
2
+ import { ProviderError } from "./providerError.ts";
3
+ import type { ProviderErrorKind } from "./providerError.ts";
4
+ import type { ProviderRequestCapacity } from "./types.ts";
5
5
 
6
- export type ProviderErrorKind =
7
- | "rate_limit"
8
- | "network_failure"
9
- | "deadline_exceeded"
10
- | "model_refused"
11
- | "invalid_response"
12
- | "unauthorized"
13
- | "quota_exceeded"
14
- | "grammar_invalid"
15
- | "capacity_exceeded"
16
- | "resource_interrupted";
6
+ export { ProviderError } from "./providerError.ts";
7
+ export type { ProviderErrorKind } from "./providerError.ts";
17
8
 
18
9
  export interface ClassifiedProviderError {
19
10
  kind: ProviderErrorKind;
@@ -55,128 +46,6 @@ export const providerTimeoutOf = (error: unknown): ProviderTimeoutError | null =
55
46
  return null;
56
47
  };
57
48
 
58
- const defaultStatus = (kind: ProviderErrorKind): number => {
59
- switch (kind) {
60
- case "unauthorized": return 401;
61
- case "quota_exceeded": return 402;
62
- case "capacity_exceeded": return 413;
63
- case "rate_limit": return 429;
64
- case "model_refused":
65
- case "grammar_invalid": return 422;
66
- case "invalid_response": return 502;
67
- case "deadline_exceeded": return 504;
68
- case "network_failure":
69
- case "resource_interrupted": return 503;
70
- }
71
- };
72
-
73
- const retryable = (kind: ProviderErrorKind): boolean => {
74
- switch (kind) {
75
- case "rate_limit":
76
- case "network_failure":
77
- return true;
78
- case "deadline_exceeded":
79
- case "invalid_response":
80
- case "grammar_invalid":
81
- case "capacity_exceeded":
82
- case "resource_interrupted":
83
- case "model_refused":
84
- case "unauthorized":
85
- case "quota_exceeded":
86
- return false;
87
- }
88
- };
89
-
90
- const buildProblem = (
91
- source: string,
92
- kind: ProviderErrorKind,
93
- message: string,
94
- status: number,
95
- extensions: Readonly<Record<string, unknown>>,
96
- retryableOverride: boolean | undefined,
97
- ): ProblemDetails => {
98
- const code: Record<ProviderErrorKind, string> = {
99
- rate_limit: "rate-limit",
100
- network_failure: "network-failure",
101
- deadline_exceeded: "deadline-exceeded",
102
- model_refused: "model-refused",
103
- invalid_response: "invalid-response",
104
- unauthorized: "unauthorized",
105
- quota_exceeded: "quota-exceeded",
106
- grammar_invalid: "grammar-invalid",
107
- capacity_exceeded: "capacity-exceeded",
108
- resource_interrupted: "resource-interrupted",
109
- };
110
- return Problems.create(source, code[kind], status, message, {
111
- providerKind: kind,
112
- stage: "provider-request",
113
- retryable: retryableOverride ?? retryable(kind),
114
- ...extensions,
115
- });
116
- };
117
-
118
- // A provider operation failed before a completed exchange existed. An
119
- // interrupted response may still carry attempt evidence for its consumer.
120
- // The standardized Problem is the public failure contract; kind remains the
121
- // provider pool's routing discriminator and is repeated as a Problem extension.
122
- export class ProviderError extends Error {
123
- readonly source: string;
124
- readonly kind: ProviderErrorKind;
125
- readonly problem: ProblemDetails;
126
- readonly attempt?: ProviderAttempt;
127
- readonly capacity?: ProviderRequestCapacity;
128
- #accounting: ProviderRequestAccounting[];
129
-
130
- constructor(
131
- source: string,
132
- kind: ProviderErrorKind,
133
- message: string,
134
- options: {
135
- status?: number | null;
136
- cause?: unknown;
137
- retryable?: boolean;
138
- extensions?: Readonly<Record<string, unknown>>;
139
- attempt?: ProviderAttempt;
140
- accounting?: readonly ProviderRequestAccounting[];
141
- capacity?: ProviderRequestCapacity;
142
- } = {},
143
- ) {
144
- super(message, options.cause !== undefined ? { cause: options.cause } : undefined);
145
- this.name = "ProviderError";
146
- this.source = providerSource(source);
147
- this.kind = kind;
148
- this.attempt = options.attempt;
149
- this.capacity = options.capacity ?? options.attempt?.capacity;
150
- this.#accounting = [...(options.accounting ?? options.attempt?.accounting ?? [])];
151
- const status = options.status !== null && options.status !== undefined
152
- && Number.isInteger(options.status) && options.status >= 400 && options.status <= 599
153
- ? options.status
154
- : defaultStatus(kind);
155
- this.problem = buildProblem(
156
- this.source,
157
- kind,
158
- message,
159
- status,
160
- options.extensions ?? {},
161
- options.retryable,
162
- );
163
- }
164
-
165
- get status(): number {
166
- return this.problem.status;
167
- }
168
-
169
- get accounting(): readonly ProviderRequestAccounting[] {
170
- return this.#accounting;
171
- }
172
-
173
- // A capacity pool adds the already-settled requests from prior backends as
174
- // the same failure crosses that orchestration boundary.
175
- prependAccounting(accounting: readonly ProviderRequestAccounting[]): void {
176
- if (accounting.length > 0) this.#accounting = [...accounting, ...this.#accounting];
177
- }
178
- }
179
-
180
49
  const wireError = (body: string): { type: string | null; code: string | null; message: string | null } => {
181
50
  try {
182
51
  const { error } = JSON.parse(body) as { error?: { type?: unknown } };
@@ -0,0 +1,139 @@
1
+ import { Problems, type ProblemDetails } from "@plurnk/plurnk-contracts";
2
+ import { providerSource } from "./notices.ts";
3
+ import type { ProviderAttempt, ProviderRequestAccounting, ProviderRequestCapacity } from "./types.ts";
4
+
5
+ export type ProviderErrorKind =
6
+ | "rate_limit"
7
+ | "network_failure"
8
+ | "deadline_exceeded"
9
+ | "model_refused"
10
+ | "invalid_response"
11
+ | "unauthorized"
12
+ | "quota_exceeded"
13
+ | "grammar_invalid"
14
+ | "capacity_exceeded"
15
+ | "resource_interrupted";
16
+
17
+ const defaultStatus = (kind: ProviderErrorKind): number => {
18
+ switch (kind) {
19
+ case "unauthorized": return 401;
20
+ case "quota_exceeded": return 402;
21
+ case "capacity_exceeded": return 413;
22
+ case "rate_limit": return 429;
23
+ case "model_refused":
24
+ case "grammar_invalid": return 422;
25
+ case "invalid_response": return 502;
26
+ case "deadline_exceeded": return 504;
27
+ case "network_failure":
28
+ case "resource_interrupted": return 503;
29
+ }
30
+ };
31
+
32
+ const retryable = (kind: ProviderErrorKind): boolean => {
33
+ switch (kind) {
34
+ case "rate_limit":
35
+ case "network_failure":
36
+ return true;
37
+ case "deadline_exceeded":
38
+ case "invalid_response":
39
+ case "grammar_invalid":
40
+ case "capacity_exceeded":
41
+ case "resource_interrupted":
42
+ case "model_refused":
43
+ case "unauthorized":
44
+ case "quota_exceeded":
45
+ return false;
46
+ }
47
+ };
48
+
49
+ const buildProblem = (
50
+ source: string,
51
+ kind: ProviderErrorKind,
52
+ message: string,
53
+ status: number,
54
+ extensions: Readonly<Record<string, unknown>>,
55
+ retryableOverride: boolean | undefined,
56
+ ): ProblemDetails => {
57
+ const code: Record<ProviderErrorKind, string> = {
58
+ rate_limit: "rate-limit",
59
+ network_failure: "network-failure",
60
+ deadline_exceeded: "deadline-exceeded",
61
+ model_refused: "model-refused",
62
+ invalid_response: "invalid-response",
63
+ unauthorized: "unauthorized",
64
+ quota_exceeded: "quota-exceeded",
65
+ grammar_invalid: "grammar-invalid",
66
+ capacity_exceeded: "capacity-exceeded",
67
+ resource_interrupted: "resource-interrupted",
68
+ };
69
+ return Problems.create(source, code[kind], status, message, {
70
+ providerKind: kind,
71
+ stage: "provider-request",
72
+ retryable: retryableOverride ?? retryable(kind),
73
+ ...extensions,
74
+ });
75
+ };
76
+
77
+ // A provider operation failed before a completed exchange existed. An
78
+ // interrupted response may still carry attempt evidence for its consumer.
79
+ // The standardized Problem is the public failure contract; kind remains the
80
+ // provider pool's routing discriminator and is repeated as a Problem extension.
81
+ export class ProviderError extends Error {
82
+ readonly source: string;
83
+ readonly kind: ProviderErrorKind;
84
+ readonly problem: ProblemDetails;
85
+ readonly attempt?: ProviderAttempt;
86
+ readonly capacity?: ProviderRequestCapacity;
87
+ #accounting: ProviderRequestAccounting[];
88
+
89
+ constructor(
90
+ source: string,
91
+ kind: ProviderErrorKind,
92
+ message: string,
93
+ options: {
94
+ status?: number | null;
95
+ cause?: unknown;
96
+ retryable?: boolean;
97
+ extensions?: Readonly<Record<string, unknown>>;
98
+ attempt?: ProviderAttempt;
99
+ accounting?: readonly ProviderRequestAccounting[];
100
+ capacity?: ProviderRequestCapacity;
101
+ } = {},
102
+ ) {
103
+ super(message, options.cause !== undefined ? { cause: options.cause } : undefined);
104
+ this.name = "ProviderError";
105
+ this.source = providerSource(source);
106
+ this.kind = kind;
107
+ this.attempt = options.attempt;
108
+ this.capacity = options.capacity ?? options.attempt?.capacity;
109
+ this.#accounting = [...(options.accounting ?? options.attempt?.accounting ?? [])];
110
+ const status = options.status !== null && options.status !== undefined
111
+ && Number.isInteger(options.status) && options.status >= 400 && options.status <= 599
112
+ ? options.status
113
+ : defaultStatus(kind);
114
+ this.problem = buildProblem(
115
+ this.source,
116
+ kind,
117
+ message,
118
+ status,
119
+ options.extensions ?? {},
120
+ options.retryable,
121
+ );
122
+ }
123
+
124
+ get status(): number {
125
+ return this.problem.status;
126
+ }
127
+
128
+ get accounting(): readonly ProviderRequestAccounting[] {
129
+ return this.#accounting;
130
+ }
131
+
132
+ // A capacity pool adds the already-settled requests from prior backends as
133
+ // the same failure crosses that orchestration boundary.
134
+ prependAccounting(accounting: readonly ProviderRequestAccounting[]): void {
135
+ if (accounting.length > 0) this.#accounting = [...accounting, ...this.#accounting];
136
+ }
137
+ }
138
+
139
+ export type { ProviderAttempt, ProviderRequestAccounting, ProviderRequestCapacity } from "./types.ts";