network-ai 5.12.7 → 5.13.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.
Files changed (77) hide show
  1. package/INTEGRATION_GUIDE.md +2 -2
  2. package/README.md +59 -3
  3. package/SKILL.md +3 -1
  4. package/dist/adapters/anthropic-messages-adapter.d.ts +141 -0
  5. package/dist/adapters/anthropic-messages-adapter.d.ts.map +1 -0
  6. package/dist/adapters/anthropic-messages-adapter.js +218 -0
  7. package/dist/adapters/anthropic-messages-adapter.js.map +1 -0
  8. package/dist/adapters/index.d.ts +2 -0
  9. package/dist/adapters/index.d.ts.map +1 -1
  10. package/dist/adapters/index.js +6 -1
  11. package/dist/adapters/index.js.map +1 -1
  12. package/dist/esm/adapters/anthropic-messages-adapter.js +218 -0
  13. package/dist/esm/adapters/anthropic-messages-adapter.js.map +1 -0
  14. package/dist/esm/adapters/index.js +6 -1
  15. package/dist/esm/adapters/index.js.map +1 -1
  16. package/dist/esm/index.js +30 -1
  17. package/dist/esm/index.js.map +1 -1
  18. package/dist/esm/lib/effort-policy.js +107 -0
  19. package/dist/esm/lib/effort-policy.js.map +1 -0
  20. package/dist/esm/lib/fan-out.js +47 -14
  21. package/dist/esm/lib/fan-out.js.map +1 -1
  22. package/dist/esm/lib/goal-decomposer.js +79 -10
  23. package/dist/esm/lib/goal-decomposer.js.map +1 -1
  24. package/dist/esm/lib/model-budget.js +167 -0
  25. package/dist/esm/lib/model-budget.js.map +1 -0
  26. package/dist/esm/lib/model-gateway.js +243 -0
  27. package/dist/esm/lib/model-gateway.js.map +1 -0
  28. package/dist/esm/lib/owasp-compliance.js +167 -0
  29. package/dist/esm/lib/owasp-compliance.js.map +1 -0
  30. package/dist/esm/lib/retry-budget.js +75 -0
  31. package/dist/esm/lib/retry-budget.js.map +1 -0
  32. package/dist/esm/lib/telemetry-provider.js +109 -1
  33. package/dist/esm/lib/telemetry-provider.js.map +1 -1
  34. package/dist/esm/lib/thinking-blocks.js +106 -0
  35. package/dist/esm/lib/thinking-blocks.js.map +1 -0
  36. package/dist/index.d.ts +16 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +30 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/lib/effort-policy.d.ts +88 -0
  41. package/dist/lib/effort-policy.d.ts.map +1 -0
  42. package/dist/lib/effort-policy.js +107 -0
  43. package/dist/lib/effort-policy.js.map +1 -0
  44. package/dist/lib/fan-out.d.ts +17 -0
  45. package/dist/lib/fan-out.d.ts.map +1 -1
  46. package/dist/lib/fan-out.js +47 -14
  47. package/dist/lib/fan-out.js.map +1 -1
  48. package/dist/lib/goal-decomposer.d.ts +18 -0
  49. package/dist/lib/goal-decomposer.d.ts.map +1 -1
  50. package/dist/lib/goal-decomposer.js +79 -10
  51. package/dist/lib/goal-decomposer.js.map +1 -1
  52. package/dist/lib/model-budget.d.ts +144 -0
  53. package/dist/lib/model-budget.d.ts.map +1 -0
  54. package/dist/lib/model-budget.js +167 -0
  55. package/dist/lib/model-budget.js.map +1 -0
  56. package/dist/lib/model-gateway.d.ts +252 -0
  57. package/dist/lib/model-gateway.d.ts.map +1 -0
  58. package/dist/lib/model-gateway.js +243 -0
  59. package/dist/lib/model-gateway.js.map +1 -0
  60. package/dist/lib/owasp-compliance.d.ts +57 -0
  61. package/dist/lib/owasp-compliance.d.ts.map +1 -0
  62. package/dist/lib/owasp-compliance.js +167 -0
  63. package/dist/lib/owasp-compliance.js.map +1 -0
  64. package/dist/lib/retry-budget.d.ts +51 -0
  65. package/dist/lib/retry-budget.d.ts.map +1 -0
  66. package/dist/lib/retry-budget.js +75 -0
  67. package/dist/lib/retry-budget.js.map +1 -0
  68. package/dist/lib/telemetry-provider.d.ts +72 -0
  69. package/dist/lib/telemetry-provider.d.ts.map +1 -1
  70. package/dist/lib/telemetry-provider.js +109 -1
  71. package/dist/lib/telemetry-provider.js.map +1 -1
  72. package/dist/lib/thinking-blocks.d.ts +77 -0
  73. package/dist/lib/thinking-blocks.d.ts.map +1 -0
  74. package/dist/lib/thinking-blocks.js +106 -0
  75. package/dist/lib/thinking-blocks.js.map +1 -0
  76. package/package.json +1 -1
  77. package/socket.json +8 -0
@@ -0,0 +1,144 @@
1
+ /**
2
+ * ModelBudget — cross-model cost accounting with fallback-credit repricing.
3
+ *
4
+ * Where {@link ../lib/federated-budget!FederatedBudget} tracks raw token counts
5
+ * against a shared ceiling, `ModelBudget` tracks **money**. It prices each
6
+ * attempt with a per-model rate card, distinguishes cache-read from cache-write
7
+ * input tokens, and — critically for a refusal → fallback flow — reprices a
8
+ * redeemed fallback credit so the retry is billed as a cache read (≈10% of the
9
+ * base input rate) instead of a cache write (1.25×–2×).
10
+ *
11
+ * It satisfies the `BudgetSink` contract consumed by
12
+ * {@link ../lib/model-gateway!GovernedModelGateway}, and can optionally forward
13
+ * token totals into a `FederatedBudget` for unified swarm-wide ceilings.
14
+ *
15
+ * @module ModelBudget
16
+ * @version 1.0.0
17
+ * @license MIT
18
+ */
19
+ /** Per-model rate card. Multipliers are applied to the input rate. */
20
+ export interface ModelPricing {
21
+ /** USD per million input tokens. */
22
+ inputPerMTok: number;
23
+ /** USD per million output tokens. */
24
+ outputPerMTok: number;
25
+ /** Multiplier on the input rate for cache-read tokens. Default `0.1`. */
26
+ cacheReadMultiplier?: number;
27
+ /** Multiplier on the input rate for cache-creation (write) tokens. Default `1.25`. */
28
+ cacheWriteMultiplier?: number;
29
+ }
30
+ /** Token usage for a single attempt. Matches the gateway's `ModelUsage`. */
31
+ export interface UsageLike {
32
+ inputTokens: number;
33
+ outputTokens: number;
34
+ cacheReadInputTokens?: number;
35
+ cacheCreationInputTokens?: number;
36
+ }
37
+ /** Minimal token-budget contract (a `FederatedBudget` satisfies this). */
38
+ export interface TokenBudgetLike {
39
+ spend(agentId: string, tokens: number): {
40
+ allowed: boolean;
41
+ };
42
+ }
43
+ /** Construction options for {@link ModelBudget}. */
44
+ export interface ModelBudgetOptions {
45
+ /** Total USD ceiling across all models. Must be positive and finite. */
46
+ ceilingUsd: number;
47
+ /** Per-model rate cards keyed by model id. */
48
+ pricing: Record<string, ModelPricing>;
49
+ /** Rate card used for models absent from `pricing`. */
50
+ defaultPricing?: ModelPricing;
51
+ /** Optional token budget to also debit (e.g. a `FederatedBudget`). */
52
+ tokenBudget?: TokenBudgetLike;
53
+ }
54
+ /** One raw per-attempt usage record (mirrors a `usage.iterations[]` entry). */
55
+ export interface UsageIteration {
56
+ /** `'fallback_message'` is the served attempt; `'message'` is a declined hop. */
57
+ type: 'message' | 'fallback_message' | string;
58
+ model: string;
59
+ inputTokens: number;
60
+ outputTokens: number;
61
+ cacheReadInputTokens?: number;
62
+ cacheCreationInputTokens?: number;
63
+ }
64
+ /**
65
+ * Compute the USD cost of one attempt.
66
+ *
67
+ * `inputTokens` is treated as *uncached* input; `cacheReadInputTokens` and
68
+ * `cacheCreationInputTokens` are billed separately via their multipliers. When
69
+ * `creditRedeemed` is set, cache-creation tokens are repriced at the cache-read
70
+ * multiplier — the fallback-credit refund.
71
+ *
72
+ * @param usage Token usage for the attempt.
73
+ * @param pricing The model's rate card.
74
+ * @param opts `creditRedeemed` reprices cache-write as cache-read.
75
+ * @returns Cost in USD.
76
+ */
77
+ export declare function costOfUsage(usage: UsageLike, pricing: ModelPricing, opts?: {
78
+ creditRedeemed?: boolean;
79
+ }): number;
80
+ /**
81
+ * USD budget tracker priced per model, with fallback-credit awareness.
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * const budget = new ModelBudget({
86
+ * ceilingUsd: 5,
87
+ * pricing: {
88
+ * 'claude-fable-5': { inputPerMTok: 10, outputPerMTok: 50 },
89
+ * 'claude-opus-4-8': { inputPerMTok: 5, outputPerMTok: 25 },
90
+ * },
91
+ * });
92
+ *
93
+ * budget.recordAttempt('claude-opus-4-8', { inputTokens: 1000, outputTokens: 500 });
94
+ * budget.remainingUsd();
95
+ * ```
96
+ */
97
+ export declare class ModelBudget {
98
+ private readonly _ceilingUsd;
99
+ private readonly _pricing;
100
+ private readonly _defaultPricing;
101
+ private readonly _tokenBudget;
102
+ private _spentUsd;
103
+ private readonly _perModelUsd;
104
+ constructor(options: ModelBudgetOptions);
105
+ /**
106
+ * Record one attempt's usage and return its cost plus remaining budget.
107
+ *
108
+ * @param model The model that ran the attempt.
109
+ * @param usage Token usage for the attempt.
110
+ * @param opts `creditRedeemed` reprices cache-write as cache-read; `agentId`
111
+ * attributes the spend on the optional token budget.
112
+ * @returns `{ costUsd, remainingUsd, allowed }`. `allowed` is `false`
113
+ * once the ceiling is breached, signalling callers to stop.
114
+ */
115
+ recordAttempt(model: string, usage: UsageLike, opts?: {
116
+ creditRedeemed?: boolean;
117
+ agentId?: string;
118
+ }): {
119
+ costUsd: number;
120
+ remainingUsd: number;
121
+ allowed: boolean;
122
+ };
123
+ /**
124
+ * Account an entire `usage.iterations` array from a server-side fallback
125
+ * response. The `fallback_message` hop is repriced as a cache read, matching
126
+ * the API's automatic billing change.
127
+ *
128
+ * @param iterations The per-attempt usage records.
129
+ * @param agentId Optional attribution for the token budget.
130
+ * @returns Total USD across all iterations.
131
+ */
132
+ accountIterations(iterations: UsageIteration[], agentId?: string): number;
133
+ /** Remaining USD in the pool (never negative). */
134
+ remainingUsd(): number;
135
+ /** Total USD spent across all models. */
136
+ getTotalUsd(): number;
137
+ /** Per-model USD totals as a plain object. */
138
+ getPerModelUsd(): Record<string, number>;
139
+ /** The configured USD ceiling. */
140
+ getCeilingUsd(): number;
141
+ /** Reset all spend counters. */
142
+ reset(): void;
143
+ }
144
+ //# sourceMappingURL=model-budget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-budget.d.ts","sourceRoot":"","sources":["../../lib/model-budget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,sEAAsE;AACtE,MAAM,WAAW,YAAY;IAC3B,oCAAoC;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,qCAAqC;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,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B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA+B;IACxD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA2B;IAC3D,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA8B;IAC3D,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAkC;gBAEnD,OAAO,EAAE,kBAAkB;IAavC;;;;;;;;;OASG;IACH,aAAa,CACX,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,SAAS,EAChB,IAAI,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GACpD;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE;IAqB9D;;;;;;;;OAQG;IACH,iBAAiB,CAAC,UAAU,EAAE,cAAc,EAAE,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM;IAmBzE,kDAAkD;IAClD,YAAY,IAAI,MAAM;IAItB,yCAAyC;IACzC,WAAW,IAAI,MAAM;IAIrB,8CAA8C;IAC9C,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAMxC,kCAAkC;IAClC,aAAa,IAAI,MAAM;IAIvB,gCAAgC;IAChC,KAAK,IAAI,IAAI;CAId"}
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ /**
3
+ * ModelBudget — cross-model cost accounting with fallback-credit repricing.
4
+ *
5
+ * Where {@link ../lib/federated-budget!FederatedBudget} tracks raw token counts
6
+ * against a shared ceiling, `ModelBudget` tracks **money**. It prices each
7
+ * attempt with a per-model rate card, distinguishes cache-read from cache-write
8
+ * input tokens, and — critically for a refusal → fallback flow — reprices a
9
+ * redeemed fallback credit so the retry is billed as a cache read (≈10% of the
10
+ * base input rate) instead of a cache write (1.25×–2×).
11
+ *
12
+ * It satisfies the `BudgetSink` contract consumed by
13
+ * {@link ../lib/model-gateway!GovernedModelGateway}, and can optionally forward
14
+ * token totals into a `FederatedBudget` for unified swarm-wide ceilings.
15
+ *
16
+ * @module ModelBudget
17
+ * @version 1.0.0
18
+ * @license MIT
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.ModelBudget = void 0;
22
+ exports.costOfUsage = costOfUsage;
23
+ // ============================================================================
24
+ // PURE COST FUNCTION
25
+ // ============================================================================
26
+ /**
27
+ * Compute the USD cost of one attempt.
28
+ *
29
+ * `inputTokens` is treated as *uncached* input; `cacheReadInputTokens` and
30
+ * `cacheCreationInputTokens` are billed separately via their multipliers. When
31
+ * `creditRedeemed` is set, cache-creation tokens are repriced at the cache-read
32
+ * multiplier — the fallback-credit refund.
33
+ *
34
+ * @param usage Token usage for the attempt.
35
+ * @param pricing The model's rate card.
36
+ * @param opts `creditRedeemed` reprices cache-write as cache-read.
37
+ * @returns Cost in USD.
38
+ */
39
+ function costOfUsage(usage, pricing, opts) {
40
+ const inRate = pricing.inputPerMTok / 1_000_000;
41
+ const outRate = pricing.outputPerMTok / 1_000_000;
42
+ const readMult = pricing.cacheReadMultiplier ?? 0.1;
43
+ const writeMult = pricing.cacheWriteMultiplier ?? 1.25;
44
+ const cacheRead = usage.cacheReadInputTokens ?? 0;
45
+ const cacheWrite = usage.cacheCreationInputTokens ?? 0;
46
+ const writeEffectiveMult = opts?.creditRedeemed ? readMult : writeMult;
47
+ return (usage.inputTokens * inRate +
48
+ cacheRead * inRate * readMult +
49
+ cacheWrite * inRate * writeEffectiveMult +
50
+ usage.outputTokens * outRate);
51
+ }
52
+ // ============================================================================
53
+ // MODEL BUDGET
54
+ // ============================================================================
55
+ /**
56
+ * USD budget tracker priced per model, with fallback-credit awareness.
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const budget = new ModelBudget({
61
+ * ceilingUsd: 5,
62
+ * pricing: {
63
+ * 'claude-fable-5': { inputPerMTok: 10, outputPerMTok: 50 },
64
+ * 'claude-opus-4-8': { inputPerMTok: 5, outputPerMTok: 25 },
65
+ * },
66
+ * });
67
+ *
68
+ * budget.recordAttempt('claude-opus-4-8', { inputTokens: 1000, outputTokens: 500 });
69
+ * budget.remainingUsd();
70
+ * ```
71
+ */
72
+ class ModelBudget {
73
+ _ceilingUsd;
74
+ _pricing;
75
+ _defaultPricing;
76
+ _tokenBudget;
77
+ _spentUsd = 0;
78
+ _perModelUsd = new Map();
79
+ constructor(options) {
80
+ if (typeof options.ceilingUsd !== 'number' || options.ceilingUsd <= 0 || !Number.isFinite(options.ceilingUsd)) {
81
+ throw new RangeError('ModelBudget: ceilingUsd must be a positive finite number');
82
+ }
83
+ if (!options.pricing || typeof options.pricing !== 'object') {
84
+ throw new TypeError('ModelBudget: pricing must be an object of model → rate card');
85
+ }
86
+ this._ceilingUsd = options.ceilingUsd;
87
+ this._pricing = options.pricing;
88
+ this._defaultPricing = options.defaultPricing;
89
+ this._tokenBudget = options.tokenBudget;
90
+ }
91
+ /**
92
+ * Record one attempt's usage and return its cost plus remaining budget.
93
+ *
94
+ * @param model The model that ran the attempt.
95
+ * @param usage Token usage for the attempt.
96
+ * @param opts `creditRedeemed` reprices cache-write as cache-read; `agentId`
97
+ * attributes the spend on the optional token budget.
98
+ * @returns `{ costUsd, remainingUsd, allowed }`. `allowed` is `false`
99
+ * once the ceiling is breached, signalling callers to stop.
100
+ */
101
+ recordAttempt(model, usage, opts) {
102
+ const pricing = this._pricing[model] ?? this._defaultPricing;
103
+ const costUsd = pricing ? costOfUsage(usage, pricing, opts) : 0;
104
+ this._spentUsd += costUsd;
105
+ this._perModelUsd.set(model, (this._perModelUsd.get(model) ?? 0) + costUsd);
106
+ if (this._tokenBudget) {
107
+ const tokens = Math.max(0, Math.round(usage.inputTokens + usage.outputTokens));
108
+ if (tokens > 0) {
109
+ this._tokenBudget.spend(opts?.agentId ?? model, tokens);
110
+ }
111
+ }
112
+ return {
113
+ costUsd,
114
+ remainingUsd: this.remainingUsd(),
115
+ allowed: this._spentUsd <= this._ceilingUsd,
116
+ };
117
+ }
118
+ /**
119
+ * Account an entire `usage.iterations` array from a server-side fallback
120
+ * response. The `fallback_message` hop is repriced as a cache read, matching
121
+ * the API's automatic billing change.
122
+ *
123
+ * @param iterations The per-attempt usage records.
124
+ * @param agentId Optional attribution for the token budget.
125
+ * @returns Total USD across all iterations.
126
+ */
127
+ accountIterations(iterations, agentId) {
128
+ let total = 0;
129
+ for (const it of iterations) {
130
+ const creditRedeemed = it.type === 'fallback_message';
131
+ const { costUsd } = this.recordAttempt(it.model, {
132
+ inputTokens: it.inputTokens,
133
+ outputTokens: it.outputTokens,
134
+ cacheReadInputTokens: it.cacheReadInputTokens,
135
+ cacheCreationInputTokens: it.cacheCreationInputTokens,
136
+ }, { creditRedeemed, agentId });
137
+ total += costUsd;
138
+ }
139
+ return total;
140
+ }
141
+ /** Remaining USD in the pool (never negative). */
142
+ remainingUsd() {
143
+ return Math.max(0, this._ceilingUsd - this._spentUsd);
144
+ }
145
+ /** Total USD spent across all models. */
146
+ getTotalUsd() {
147
+ return this._spentUsd;
148
+ }
149
+ /** Per-model USD totals as a plain object. */
150
+ getPerModelUsd() {
151
+ const out = {};
152
+ for (const [model, usd] of this._perModelUsd)
153
+ out[model] = usd;
154
+ return out;
155
+ }
156
+ /** The configured USD ceiling. */
157
+ getCeilingUsd() {
158
+ return this._ceilingUsd;
159
+ }
160
+ /** Reset all spend counters. */
161
+ reset() {
162
+ this._spentUsd = 0;
163
+ this._perModelUsd.clear();
164
+ }
165
+ }
166
+ exports.ModelBudget = ModelBudget;
167
+ //# sourceMappingURL=model-budget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-budget.js","sourceRoot":"","sources":["../../lib/model-budget.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAuEH,kCAoBC;AArCD,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E;;;;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AAI,CAAC,SAAS,GAAG,CAAC,CAAC;QACnB,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF;AA/GD,kCA+GC"}
@@ -0,0 +1,252 @@
1
+ /**
2
+ * GovernedModelGateway — model-interaction lifecycle governance.
3
+ *
4
+ * Absorbs a frontier model's refusal → fallback → billing complexity and
5
+ * presents one governed, budgeted, audited interface. When the primary model
6
+ * declines a request with a classifier refusal (`stop_reason: "refusal"`), the
7
+ * gateway:
8
+ *
9
+ * 1. records the refusal (which classifier `category` fired) to the audit sink,
10
+ * 2. emits a refusal signal to telemetry (a refusal is an HTTP 200, *not* an
11
+ * error — it is invisible to error-rate monitoring),
12
+ * 3. retries on the next model in the fallback chain, redeeming the one-time
13
+ * fallback-credit token so the retry is repriced as a cache read,
14
+ * 4. strips model-specific thinking blocks when it switches models (unless a
15
+ * credit is being redeemed, which requires an exact body match),
16
+ * 5. accounts each attempt's cost against the cross-model budget.
17
+ *
18
+ * This layer is **provider-agnostic**. It operates on a normalized
19
+ * {@link ModelCaller}; the concrete provider binding (e.g. the Anthropic
20
+ * Messages adapter) maps the native API to these shapes. Unlike
21
+ * `AdapterRegistry.fallbackChain` — which fails over on adapter *health*
22
+ * (`CircuitOpenError`) — this gateway falls over on a *classifier refusal*.
23
+ *
24
+ * @module GovernedModelGateway
25
+ * @version 1.0.0
26
+ * @license MIT
27
+ */
28
+ /** Effort levels, lowest to highest cost/depth. Mirrors `output_config.effort`. */
29
+ export type EffortLevel = 'low' | 'medium' | 'high' | 'xhigh' | 'max';
30
+ /**
31
+ * Classifier categories a refusal can carry. `null` when the refusal does not
32
+ * map to a named category (a normal, permanent value — not a placeholder).
33
+ */
34
+ export type RefusalCategory = 'cyber' | 'bio' | 'frontier_llm' | 'reasoning_extraction' | null;
35
+ /** A single conversation message in normalized form. */
36
+ export interface ModelMessage {
37
+ role: string;
38
+ content: unknown;
39
+ }
40
+ /** A normalized content block. `thinking`/`signature` appear on thinking blocks. */
41
+ export interface ModelContentBlock {
42
+ type: string;
43
+ text?: string;
44
+ thinking?: string;
45
+ signature?: string;
46
+ [key: string]: unknown;
47
+ }
48
+ /** Per-attempt token usage, normalized across providers. */
49
+ export interface ModelUsage {
50
+ inputTokens: number;
51
+ outputTokens: number;
52
+ cacheReadInputTokens?: number;
53
+ cacheCreationInputTokens?: number;
54
+ }
55
+ /**
56
+ * Refusal metadata extracted from a declined response. Present only when
57
+ * `stopReason === 'refusal'`.
58
+ */
59
+ export interface RefusalDetails {
60
+ /** Policy area that triggered the classifier, or `null` if unnamed. */
61
+ category: RefusalCategory;
62
+ /** Human-readable description. Display it; do not parse it (text is unstable). */
63
+ explanation?: string;
64
+ /** One-time credit token that reprices the fallback retry. ~5-minute TTL. */
65
+ fallbackCreditToken?: string | null;
66
+ /** Whether the retry may continue the refused model's partial output. */
67
+ fallbackHasPrefillClaim?: boolean | null;
68
+ /** Model to retry directly when a configured fallback could not run. */
69
+ recommendedModel?: string | null;
70
+ }
71
+ /** A normalized request to a single model. */
72
+ export interface ModelRequest {
73
+ model: string;
74
+ messages: ModelMessage[];
75
+ system?: string;
76
+ maxTokens?: number;
77
+ tools?: unknown[];
78
+ /** Soft cost/depth signal; the primary lever on per-token spend. */
79
+ effort?: EffortLevel;
80
+ /** When set, the caller should redeem this credit on the retry. */
81
+ fallbackCreditToken?: string;
82
+ metadata?: Record<string, unknown>;
83
+ }
84
+ /** A normalized response from a single model. */
85
+ export interface ModelResponse {
86
+ id?: string;
87
+ /** The model that actually produced this response. */
88
+ model: string;
89
+ content: ModelContentBlock[];
90
+ stopReason: string | null;
91
+ /** Refusal metadata when `stopReason === 'refusal'`, else `null`/absent. */
92
+ refusal?: RefusalDetails | null;
93
+ usage: ModelUsage;
94
+ }
95
+ /**
96
+ * Provider-agnostic model invocation. A concrete adapter (Anthropic, etc.)
97
+ * implements this by mapping the native API to {@link ModelRequest} /
98
+ * {@link ModelResponse}.
99
+ */
100
+ export type ModelCaller = (request: ModelRequest) => Promise<ModelResponse>;
101
+ /** Records one attempt's cost. {@link ../lib/model-budget!ModelBudget} satisfies this. */
102
+ export interface BudgetSink {
103
+ recordAttempt(model: string, usage: ModelUsage, opts?: {
104
+ creditRedeemed?: boolean;
105
+ agentId?: string;
106
+ }): {
107
+ costUsd: number;
108
+ remainingUsd: number;
109
+ allowed: boolean;
110
+ };
111
+ }
112
+ /** Append-only audit destination. */
113
+ export interface AuditSink {
114
+ log(event: Record<string, unknown>): void | Promise<void>;
115
+ }
116
+ /** Thinking-block lifecycle hook. {@link ThinkingBlockManager} satisfies this. */
117
+ export interface ThinkingSink {
118
+ /** Strip thinking blocks from prior turns before a cross-model retry. */
119
+ stripForModelSwitch(messages: ModelMessage[]): ModelMessage[];
120
+ }
121
+ /** Effort governance hook. {@link EffortPolicy} satisfies this. */
122
+ export interface EffortSink {
123
+ resolve(requested: EffortLevel | undefined, ctx: {
124
+ agentId?: string;
125
+ }): EffortLevel | undefined;
126
+ }
127
+ /** Refusal observability hook. {@link RefusalTelemetry} satisfies this. */
128
+ export interface RefusalTelemetrySink {
129
+ recordRefusal(info: {
130
+ model: string;
131
+ category: RefusalCategory;
132
+ agentId?: string;
133
+ }): void;
134
+ recordFallbackServed(info: {
135
+ requestedModel: string;
136
+ servedModel: string;
137
+ agentId?: string;
138
+ }): void;
139
+ }
140
+ /** Construction options for {@link GovernedModelGateway}. */
141
+ export interface GovernedModelGatewayConfig {
142
+ /** Normalized model invocation. Required. */
143
+ caller: ModelCaller;
144
+ /** Model tried first. Required, non-empty. */
145
+ primaryModel: string;
146
+ /** Ordered fallback models, tried after a refusal. */
147
+ fallbackModels?: string[];
148
+ /** Default effort applied when a request omits one. */
149
+ defaultEffort?: EffortLevel;
150
+ /** Maximum number of fallback attempts (default: `fallbackModels.length`). */
151
+ maxFallbacks?: number;
152
+ /** Permitted fallback targets per model (mirrors `allowed_fallback_models`). */
153
+ allowedFallbacks?: Record<string, string[]>;
154
+ /** Cross-model cost accounting. */
155
+ budget?: BudgetSink;
156
+ /** Audit destination for every attempt and refusal. */
157
+ audit?: AuditSink;
158
+ /** Refusal / fallback observability. */
159
+ telemetry?: RefusalTelemetrySink;
160
+ /** Thinking-block lifecycle manager. */
161
+ thinking?: ThinkingSink;
162
+ /** Effort governance policy. */
163
+ effort?: EffortSink;
164
+ }
165
+ /** A single attempt in the fallback chain — the source of truth for billing. */
166
+ export interface GatewayAttempt {
167
+ model: string;
168
+ stopReason: string | null;
169
+ refusalCategory: RefusalCategory;
170
+ usage: ModelUsage;
171
+ costUsd?: number;
172
+ servedByFallback: boolean;
173
+ creditRedeemed: boolean;
174
+ }
175
+ /** A request to the gateway. The gateway, not the caller, picks the model. */
176
+ export interface GovernedSendRequest {
177
+ messages: ModelMessage[];
178
+ system?: string;
179
+ maxTokens?: number;
180
+ tools?: unknown[];
181
+ effort?: EffortLevel;
182
+ /** Used for audit/telemetry/budget attribution. */
183
+ agentId?: string;
184
+ metadata?: Record<string, unknown>;
185
+ }
186
+ /** The governed outcome of a {@link GovernedModelGateway.send} call. */
187
+ export interface GovernedModelResult {
188
+ /** The response that served the turn, or the final refusal if all declined. */
189
+ response: ModelResponse;
190
+ /** Model that ultimately served (or was last attempted). */
191
+ servedModel: string;
192
+ /** `true` when every model in the chain refused. */
193
+ refused: boolean;
194
+ /** `true` when a fallback (not the primary) served the response. */
195
+ servedByFallback: boolean;
196
+ /** Per-attempt record. Use this for billing and serving-model analytics. */
197
+ attempts: GatewayAttempt[];
198
+ /** Distinct refusal categories encountered across attempts. */
199
+ refusalCategories: RefusalCategory[];
200
+ /** Sum of attempt costs when a budget is configured. */
201
+ totalCostUsd?: number;
202
+ }
203
+ /** Whether a response is a classifier refusal. Branch on this, not on content. */
204
+ export declare function isRefusal(response: ModelResponse): boolean;
205
+ /**
206
+ * Governs the full model-interaction lifecycle: refusal detection, cross-model
207
+ * fallback, fallback-credit redemption, thinking-block handoff, and per-attempt
208
+ * cost accounting — behind one {@link GovernedModelGateway.send} call.
209
+ *
210
+ * @example
211
+ * ```typescript
212
+ * const gateway = new GovernedModelGateway({
213
+ * caller, // provider binding (e.g. Anthropic adapter)
214
+ * primaryModel: 'claude-fable-5',
215
+ * fallbackModels: ['claude-opus-4-8'],
216
+ * budget, audit, telemetry, thinking, effort,
217
+ * });
218
+ *
219
+ * const r = await gateway.send({ messages: [{ role: 'user', content: 'hi' }] });
220
+ * console.log(r.servedModel, r.servedByFallback, r.totalCostUsd);
221
+ * ```
222
+ */
223
+ export declare class GovernedModelGateway {
224
+ private readonly caller;
225
+ private readonly primaryModel;
226
+ private readonly fallbackModels;
227
+ private readonly defaultEffort;
228
+ private readonly maxFallbacks;
229
+ private readonly allowedFallbacks;
230
+ private readonly budget;
231
+ private readonly audit;
232
+ private readonly telemetry;
233
+ private readonly thinking;
234
+ private readonly effortPolicy;
235
+ constructor(config: GovernedModelGatewayConfig);
236
+ /**
237
+ * Send a request through the governed lifecycle.
238
+ *
239
+ * Tries the primary model, then walks the fallback chain on each refusal,
240
+ * redeeming fallback credit and stripping cross-model thinking blocks as it
241
+ * goes. Returns once a model serves the turn or the chain is exhausted.
242
+ *
243
+ * @param request The request. The gateway selects the model(s).
244
+ * @returns A {@link GovernedModelResult} describing every attempt.
245
+ */
246
+ send(request: GovernedSendRequest): Promise<GovernedModelResult>;
247
+ /** The ordered model chain: primary followed by permitted fallbacks. */
248
+ private buildChain;
249
+ private resolveEffort;
250
+ private auditAttempt;
251
+ }
252
+ //# sourceMappingURL=model-gateway.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-gateway.d.ts","sourceRoot":"","sources":["../../lib/model-gateway.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAMH,mFAAmF;AACnF,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AAEtE;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,KAAK,GAAG,c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