@jxburros/ai-nugget 0.4.1 → 0.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.
Files changed (187) hide show
  1. package/README.md +158 -382
  2. package/UPGRADING.md +182 -0
  3. package/dist/adapters/engines/anthropic.d.ts +7 -1
  4. package/dist/adapters/engines/anthropic.js +82 -37
  5. package/dist/adapters/engines/base.d.ts +29 -2
  6. package/dist/adapters/engines/base.js +52 -8
  7. package/dist/adapters/engines/google.d.ts +7 -1
  8. package/dist/adapters/engines/google.js +80 -29
  9. package/dist/adapters/engines/ollama.d.ts +2 -1
  10. package/dist/adapters/engines/ollama.js +57 -15
  11. package/dist/adapters/engines/openaiChat.d.ts +8 -1
  12. package/dist/adapters/engines/openaiChat.js +109 -29
  13. package/dist/adapters/profiles.d.ts +21 -1
  14. package/dist/adapters/profiles.js +12 -2
  15. package/dist/agent/loop.d.ts +45 -1
  16. package/dist/agent/loop.js +117 -12
  17. package/dist/cjs/adapters/engines/anthropic.js +326 -0
  18. package/dist/cjs/adapters/engines/base.js +147 -0
  19. package/dist/cjs/adapters/engines/google.js +291 -0
  20. package/dist/cjs/adapters/engines/ollama.js +205 -0
  21. package/dist/cjs/adapters/engines/openaiChat.js +312 -0
  22. package/dist/cjs/adapters/index.js +22 -0
  23. package/dist/cjs/adapters/profiles.js +125 -0
  24. package/dist/cjs/agent/index.js +18 -0
  25. package/dist/cjs/agent/loop.js +373 -0
  26. package/dist/cjs/agent/tools.js +51 -0
  27. package/dist/cjs/connect.js +27 -0
  28. package/dist/cjs/errors.js +110 -0
  29. package/dist/cjs/handler.js +586 -0
  30. package/dist/cjs/index.js +28 -0
  31. package/dist/cjs/json.js +121 -0
  32. package/dist/cjs/keys.js +81 -0
  33. package/dist/cjs/package.json +3 -0
  34. package/dist/cjs/policy.js +42 -0
  35. package/dist/cjs/reasoning.js +159 -0
  36. package/dist/cjs/redact.js +78 -0
  37. package/dist/cjs/tokens.js +22 -0
  38. package/dist/cjs/transport.js +172 -0
  39. package/dist/cjs/types.js +6 -0
  40. package/dist/cjs/util.js +126 -0
  41. package/dist/errors.js +25 -1
  42. package/dist/handler.d.ts +67 -1
  43. package/dist/handler.js +266 -61
  44. package/dist/index.d.ts +1 -0
  45. package/dist/index.js +1 -0
  46. package/dist/reasoning.d.ts +45 -0
  47. package/dist/reasoning.js +154 -0
  48. package/dist/redact.d.ts +18 -0
  49. package/dist/redact.js +29 -1
  50. package/dist/transport.d.ts +3 -1
  51. package/dist/transport.js +21 -1
  52. package/dist/types.d.ts +112 -2
  53. package/dist/util.d.ts +22 -0
  54. package/dist/util.js +59 -0
  55. package/nugget/VERSION.txt +2 -2
  56. package/nugget/dist/adapters/engines/anthropic.d.ts +14 -0
  57. package/nugget/dist/adapters/engines/anthropic.d.ts.map +1 -0
  58. package/nugget/dist/adapters/engines/anthropic.js +323 -0
  59. package/nugget/dist/adapters/engines/anthropic.js.map +1 -0
  60. package/nugget/dist/adapters/engines/base.d.ts +50 -0
  61. package/nugget/dist/adapters/engines/base.d.ts.map +1 -0
  62. package/nugget/dist/adapters/engines/base.js +137 -0
  63. package/nugget/dist/adapters/engines/base.js.map +1 -0
  64. package/nugget/dist/adapters/engines/google.d.ts +24 -0
  65. package/nugget/dist/adapters/engines/google.d.ts.map +1 -0
  66. package/nugget/dist/adapters/engines/google.js +288 -0
  67. package/nugget/dist/adapters/engines/google.js.map +1 -0
  68. package/nugget/dist/adapters/engines/ollama.d.ts +11 -0
  69. package/nugget/dist/adapters/engines/ollama.d.ts.map +1 -0
  70. package/nugget/dist/adapters/engines/ollama.js +202 -0
  71. package/nugget/dist/adapters/engines/ollama.js.map +1 -0
  72. package/nugget/dist/adapters/engines/openaiChat.d.ts +22 -0
  73. package/nugget/dist/adapters/engines/openaiChat.d.ts.map +1 -0
  74. package/nugget/dist/adapters/engines/openaiChat.js +308 -0
  75. package/nugget/dist/adapters/engines/openaiChat.js.map +1 -0
  76. package/nugget/dist/adapters/index.d.ts +5 -0
  77. package/nugget/dist/adapters/index.d.ts.map +1 -0
  78. package/nugget/dist/adapters/index.js +17 -0
  79. package/nugget/dist/adapters/index.js.map +1 -0
  80. package/nugget/dist/adapters/profiles.d.ts +62 -0
  81. package/nugget/dist/adapters/profiles.d.ts.map +1 -0
  82. package/nugget/dist/adapters/profiles.js +121 -0
  83. package/nugget/dist/adapters/profiles.js.map +1 -0
  84. package/nugget/dist/agent/index.d.ts +3 -0
  85. package/nugget/dist/agent/index.d.ts.map +1 -0
  86. package/nugget/dist/agent/index.js +3 -0
  87. package/nugget/dist/agent/index.js.map +1 -0
  88. package/nugget/dist/agent/loop.d.ts +114 -0
  89. package/nugget/dist/agent/loop.d.ts.map +1 -0
  90. package/nugget/dist/agent/loop.js +371 -0
  91. package/nugget/dist/agent/loop.js.map +1 -0
  92. package/nugget/dist/agent/tools.d.ts +29 -0
  93. package/nugget/dist/agent/tools.d.ts.map +1 -0
  94. package/nugget/dist/agent/tools.js +48 -0
  95. package/nugget/dist/agent/tools.js.map +1 -0
  96. package/nugget/dist/cjs/adapters/engines/anthropic.js +326 -0
  97. package/nugget/dist/cjs/adapters/engines/base.js +147 -0
  98. package/nugget/dist/cjs/adapters/engines/google.js +291 -0
  99. package/nugget/dist/cjs/adapters/engines/ollama.js +205 -0
  100. package/nugget/dist/cjs/adapters/engines/openaiChat.js +312 -0
  101. package/nugget/dist/cjs/adapters/index.js +22 -0
  102. package/nugget/dist/cjs/adapters/profiles.js +125 -0
  103. package/nugget/dist/cjs/agent/index.js +18 -0
  104. package/nugget/dist/cjs/agent/loop.js +373 -0
  105. package/nugget/dist/cjs/agent/tools.js +51 -0
  106. package/nugget/dist/cjs/connect.js +27 -0
  107. package/nugget/dist/cjs/errors.js +110 -0
  108. package/nugget/dist/cjs/handler.js +586 -0
  109. package/nugget/dist/cjs/index.js +28 -0
  110. package/nugget/dist/cjs/json.js +121 -0
  111. package/nugget/dist/cjs/keys.js +81 -0
  112. package/nugget/dist/cjs/package.json +3 -0
  113. package/nugget/dist/cjs/policy.js +42 -0
  114. package/nugget/dist/cjs/reasoning.js +159 -0
  115. package/nugget/dist/cjs/redact.js +78 -0
  116. package/nugget/dist/cjs/tokens.js +22 -0
  117. package/nugget/dist/cjs/transport.js +172 -0
  118. package/nugget/dist/cjs/types.js +6 -0
  119. package/nugget/dist/cjs/util.js +126 -0
  120. package/nugget/dist/connect.d.ts +31 -0
  121. package/nugget/dist/connect.d.ts.map +1 -0
  122. package/nugget/dist/connect.js +25 -0
  123. package/nugget/dist/connect.js.map +1 -0
  124. package/nugget/dist/errors.d.ts +22 -0
  125. package/nugget/dist/errors.d.ts.map +1 -0
  126. package/nugget/dist/errors.js +104 -0
  127. package/nugget/dist/errors.js.map +1 -0
  128. package/nugget/dist/handler.d.ts +114 -0
  129. package/nugget/dist/handler.d.ts.map +1 -0
  130. package/nugget/dist/handler.js +582 -0
  131. package/nugget/dist/handler.js.map +1 -0
  132. package/nugget/dist/index.d.ts +13 -0
  133. package/nugget/dist/index.d.ts.map +1 -0
  134. package/nugget/dist/index.js +13 -0
  135. package/nugget/dist/index.js.map +1 -0
  136. package/nugget/dist/json.d.ts +7 -0
  137. package/nugget/dist/json.d.ts.map +1 -0
  138. package/nugget/dist/json.js +114 -0
  139. package/nugget/dist/json.js.map +1 -0
  140. package/nugget/dist/keys.d.ts +7 -0
  141. package/nugget/dist/keys.d.ts.map +1 -0
  142. package/nugget/dist/keys.js +75 -0
  143. package/nugget/dist/keys.js.map +1 -0
  144. package/nugget/dist/policy.d.ts +6 -0
  145. package/nugget/dist/policy.d.ts.map +1 -0
  146. package/nugget/dist/policy.js +37 -0
  147. package/nugget/dist/policy.js.map +1 -0
  148. package/nugget/dist/reasoning.d.ts +45 -0
  149. package/nugget/dist/reasoning.d.ts.map +1 -0
  150. package/nugget/dist/reasoning.js +154 -0
  151. package/nugget/dist/reasoning.js.map +1 -0
  152. package/nugget/dist/redact.d.ts +26 -0
  153. package/nugget/dist/redact.d.ts.map +1 -0
  154. package/nugget/dist/redact.js +74 -0
  155. package/nugget/dist/redact.js.map +1 -0
  156. package/nugget/dist/tokens.d.ts +5 -0
  157. package/nugget/dist/tokens.d.ts.map +1 -0
  158. package/nugget/dist/tokens.js +18 -0
  159. package/nugget/dist/tokens.js.map +1 -0
  160. package/nugget/dist/transport.d.ts +30 -0
  161. package/nugget/dist/transport.d.ts.map +1 -0
  162. package/nugget/dist/transport.js +165 -0
  163. package/nugget/dist/transport.js.map +1 -0
  164. package/nugget/dist/types.d.ts +301 -0
  165. package/nugget/dist/types.d.ts.map +1 -0
  166. package/nugget/dist/types.js +4 -0
  167. package/nugget/dist/types.js.map +1 -0
  168. package/nugget/dist/util.d.ts +31 -0
  169. package/nugget/dist/util.d.ts.map +1 -0
  170. package/nugget/dist/util.js +114 -0
  171. package/nugget/dist/util.js.map +1 -0
  172. package/nugget/src/adapters/engines/anthropic.ts +78 -37
  173. package/nugget/src/adapters/engines/base.ts +50 -7
  174. package/nugget/src/adapters/engines/google.ts +79 -29
  175. package/nugget/src/adapters/engines/ollama.ts +56 -17
  176. package/nugget/src/adapters/engines/openaiChat.ts +104 -30
  177. package/nugget/src/adapters/profiles.ts +53 -3
  178. package/nugget/src/agent/loop.ts +156 -13
  179. package/nugget/src/errors.ts +25 -1
  180. package/nugget/src/handler.ts +308 -59
  181. package/nugget/src/index.ts +1 -0
  182. package/nugget/src/reasoning.ts +174 -0
  183. package/nugget/src/redact.ts +32 -1
  184. package/nugget/src/transport.ts +20 -1
  185. package/nugget/src/types.ts +113 -1
  186. package/nugget/src/util.ts +64 -0
  187. package/package.json +18 -5
@@ -0,0 +1,582 @@
1
+ import { adapterFor } from './adapters/index.js';
2
+ import { applyAuth, profileFor } from './adapters/profiles.js';
3
+ import { AIError, fromUnknown } from './errors.js';
4
+ import { extractJson } from './json.js';
5
+ import { containsReasoningBlock, createReasoningStripper, stripReasoningBlocks } from './reasoning.js';
6
+ import { allowAllPolicy } from './policy.js';
7
+ import { SessionRedactor } from './redact.js';
8
+ import { promptChars, sleep } from './util.js';
9
+ /**
10
+ * A *startup* notice, so it fires once per process rather than once per handler
11
+ * — an app that builds a handler per request would otherwise flood its logs
12
+ * with a message that says the same thing every time.
13
+ */
14
+ let warnedNoPolicy = false;
15
+ /** Test seam: reset the once-per-process startup notice. */
16
+ export function resetPolicyWarningForTests() {
17
+ warnedNoPolicy = false;
18
+ }
19
+ export class AIHandler {
20
+ opts;
21
+ active = 0;
22
+ queue = [];
23
+ lastStarted = 0;
24
+ sessionRedactor = new SessionRedactor();
25
+ policy;
26
+ constructor(opts) {
27
+ this.opts = opts;
28
+ this.policy = opts.policy ?? allowAllPolicy();
29
+ // `allowAllPolicy()` stays the default — a library must not decide an app's
30
+ // governance — but "no policy configured" should be visible at runtime, not
31
+ // only in a README paragraph. Passing an explicit policy (including
32
+ // `allowAllPolicy()`) is the opt-out.
33
+ if (!opts.policy && !opts.silencePolicyWarning && !warnedNoPolicy) {
34
+ warnedNoPolicy = true;
35
+ globalThis.console?.warn?.('[ai-nugget] No GovernancePolicy configured — every provider/model is allowed. ' +
36
+ 'Pass `policy` (e.g. allowlistPolicy(...)), or `policy: allowAllPolicy()` / `silencePolicyWarning: true` to accept this deliberately.');
37
+ }
38
+ }
39
+ async chat(conn, req) {
40
+ let result;
41
+ for await (const event of this.stream(conn, req)) {
42
+ if (event.type === 'done')
43
+ result = event.result;
44
+ if (event.type === 'error')
45
+ throw event.error;
46
+ }
47
+ if (!result)
48
+ throw new AIError('Call ended without a result', { kind: 'invalid_response', provider: conn.provider });
49
+ return result;
50
+ }
51
+ async *stream(conn, req) {
52
+ const callId = createCallId();
53
+ const startedAt = Date.now();
54
+ const adapter = adapterFor(conn.provider, conn.baseUrl);
55
+ const preflight = await this.preflight(callId, conn, req.model, req.metadata);
56
+ if (!preflight.ok)
57
+ return yield* this.failStream(callId, conn, req, startedAt, 1, preflight.error);
58
+ // One idempotency key per logical call, reused across every retry attempt,
59
+ // so a provider that supports it collapses a re-sent generation instead of
60
+ // billing it twice (see `supportsIdempotencyKey` in the profile table).
61
+ const resolved = withIdempotencyKey(preflight.resolved, callId);
62
+ let acquired = false;
63
+ let recorded = false;
64
+ let attempt = 0;
65
+ try {
66
+ await this.acquire(req.signal);
67
+ acquired = true;
68
+ const maxAttempts = this.opts.retry?.maxAttempts ?? 3;
69
+ let emittedStart = false;
70
+ let emittedOutput = false;
71
+ const stripInline = this.opts.stripInlineReasoning !== false;
72
+ for (;;) {
73
+ attempt += 1;
74
+ // One stripper per attempt: a retried stream starts its tag state over.
75
+ const stripper = stripInline ? createReasoningStripper() : null;
76
+ try {
77
+ for await (const event of adapter.stream(resolved, req)) {
78
+ if (event.type === 'start') {
79
+ if (!emittedStart) {
80
+ emittedStart = true;
81
+ yield { ...event, callId };
82
+ }
83
+ continue;
84
+ }
85
+ if (event.type === 'delta' || event.type === 'tool_call')
86
+ emittedOutput = true;
87
+ if (event.type === 'delta' && stripper) {
88
+ // Inline reasoning never reaches `delta`; it rides the reasoning channel like a
89
+ // provider-native thinking field would.
90
+ const piece = stripper.push(event.text);
91
+ if (piece.reasoning)
92
+ yield { type: 'reasoning', text: piece.reasoning };
93
+ if (piece.visible)
94
+ yield { type: 'delta', text: piece.visible };
95
+ continue;
96
+ }
97
+ if (event.type === 'done') {
98
+ let result = event.result;
99
+ if (stripper) {
100
+ const tail = stripper.end();
101
+ if (tail.reasoning)
102
+ yield { type: 'reasoning', text: tail.reasoning };
103
+ if (tail.visible)
104
+ yield { type: 'delta', text: tail.visible };
105
+ if (containsReasoningBlock(result.text)) {
106
+ result = { ...result, text: stripReasoningBlocks(result.text) };
107
+ }
108
+ }
109
+ await this.recordSuccess(callId, conn, req, startedAt, attempt, result);
110
+ recorded = true;
111
+ yield { ...event, result };
112
+ return;
113
+ }
114
+ yield event;
115
+ }
116
+ throw new AIError('Provider did not emit a done event', { kind: 'invalid_response', provider: conn.provider });
117
+ }
118
+ catch (errorValue) {
119
+ const error = fromUnknown(errorValue, conn.provider);
120
+ // `emittedOutput` stops retries once any byte has reached the caller:
121
+ // never silently re-run a partially delivered answer.
122
+ if (!error.retryable || attempt >= maxAttempts || req.signal?.aborted || emittedOutput) {
123
+ recorded = true;
124
+ return yield* this.failStream(callId, conn, req, startedAt, attempt, error);
125
+ }
126
+ const delayMs = this.retryDelay(error, attempt);
127
+ yield { type: 'retry', attempt, reason: error.kind, delayMs };
128
+ try {
129
+ await sleep(delayMs, req.signal);
130
+ }
131
+ catch (sleepError) {
132
+ recorded = true;
133
+ return yield* this.failStream(callId, conn, req, startedAt, attempt, fromUnknown(sleepError, conn.provider));
134
+ }
135
+ }
136
+ }
137
+ }
138
+ catch (errorValue) {
139
+ recorded = true;
140
+ return yield* this.failStream(callId, conn, req, startedAt, Math.max(1, attempt), fromUnknown(errorValue, conn.provider));
141
+ }
142
+ finally {
143
+ if (acquired)
144
+ this.release();
145
+ if (acquired && !recorded) {
146
+ await this.recordFailure(callId, conn, req, startedAt, Math.max(1, attempt), new AIError('Call canceled before completion', { kind: 'canceled', retryable: false, provider: conn.provider }));
147
+ }
148
+ }
149
+ }
150
+ /**
151
+ * The shared pre-call preamble: policy check → key resolution → `beforeCall`
152
+ * hook. Every entry point (`stream`, `embed`, `listModels`/`testConnection`)
153
+ * runs exactly this sequence, so it lives once. Failures are *returned*, not
154
+ * recorded — each caller owns its own telemetry shape (`recordFailure` for
155
+ * chat/probe, `recordEmbed` for embeddings) and records the returned error.
156
+ */
157
+ async preflight(callId, conn, model, metadata) {
158
+ const policyResult = this.policy.checkModel(conn.provider, model);
159
+ if (!policyResult.allowed) {
160
+ return { ok: false, error: new AIError(policyResult.reason, { kind: 'policy_blocked', retryable: false, provider: conn.provider }) };
161
+ }
162
+ let resolved;
163
+ try {
164
+ resolved = await this.resolveConnection(conn);
165
+ }
166
+ catch (errorValue) {
167
+ // Key resolution failures (missing/locked/denied) are a recorded outcome,
168
+ // not an uncaught throw — the traceability contract covers them too.
169
+ return { ok: false, error: fromUnknown(errorValue, conn.provider) };
170
+ }
171
+ try {
172
+ const info = {
173
+ callId,
174
+ connection: safeConnection(conn),
175
+ provider: conn.provider,
176
+ model,
177
+ metadata,
178
+ resolved: safeResolved(resolved),
179
+ };
180
+ if (await this.opts.hooks?.beforeCall?.(info) === 'deny') {
181
+ return { ok: false, error: new AIError('Call denied by beforeCall hook', { kind: 'policy_blocked', retryable: false, provider: conn.provider }) };
182
+ }
183
+ }
184
+ catch (errorValue) {
185
+ // A throwing beforeCall hook is a recorded, redacted outcome too — not
186
+ // an uncaught throw that skips telemetry and the redaction guarantee.
187
+ return { ok: false, error: fromUnknown(errorValue, conn.provider) };
188
+ }
189
+ return { ok: true, resolved };
190
+ }
191
+ /** Record a failed call and emit the single redacted `error` event for it. */
192
+ async *failStream(callId, conn, req, startedAt, attempts, error) {
193
+ await this.recordFailure(callId, conn, req, startedAt, attempts, error);
194
+ yield { type: 'error', error: this.redactedError(error) };
195
+ }
196
+ async listModels(conn) {
197
+ return this.runProbe(conn, '__listModels__', async (resolved) => {
198
+ const adapter = adapterFor(conn.provider, conn.baseUrl);
199
+ return adapter.listModels?.(resolved) ?? [];
200
+ });
201
+ }
202
+ async testConnection(conn) {
203
+ try {
204
+ return await this.runProbe(conn, '__testConnection__', async (resolved) => {
205
+ const adapter = adapterFor(conn.provider, conn.baseUrl);
206
+ const health = await adapter.health?.(resolved);
207
+ if (health) {
208
+ if (!health.ok)
209
+ throw new AIError(health.detail ?? 'Connection failed', { kind: 'network', retryable: false, provider: conn.provider });
210
+ return { ok: true, message: health.detail ?? 'Connection healthy' };
211
+ }
212
+ await adapter.listModels?.(resolved);
213
+ return { ok: true, message: 'Connection healthy' };
214
+ });
215
+ }
216
+ catch (error) {
217
+ return { ok: false, message: error instanceof Error ? this.redact(error.message) : 'Connection failed' };
218
+ }
219
+ }
220
+ /**
221
+ * Warm a connection so the first real call doesn't pay cold DNS/TLS and
222
+ * (for a local daemon) process spin-up on the hot path. Runs a lightweight
223
+ * health probe and never throws — call it once at boot. Combined with a CJS
224
+ * `require` path it removes the cold-start "offline" false negative.
225
+ */
226
+ async prewarm(conn) {
227
+ try {
228
+ await this.testConnection(conn);
229
+ }
230
+ catch {
231
+ // Warm-up only: a failure here just means the first real call pays the cost.
232
+ }
233
+ }
234
+ /**
235
+ * Chat that returns typed, validated output. Requests JSON mode, extracts the
236
+ * JSON from the reply, and validates it against any Standard Schema validator
237
+ * (Zod / Valibot / ArkType). On a validation miss it performs exactly one
238
+ * corrective retry that shows the model its error, then throws
239
+ * `invalid_response` if still invalid. No schema library is bundled — the
240
+ * caller supplies the schema.
241
+ */
242
+ async chatParsed(conn, req, schema) {
243
+ const base = { ...req, responseFormat: req.responseFormat ?? { type: 'json' } };
244
+ let result = await this.chat(conn, base);
245
+ let validated = await validateWithSchema(schema, result.text);
246
+ if (validated.ok)
247
+ return { data: validated.value, result };
248
+ const retry = {
249
+ ...base,
250
+ messages: [
251
+ ...base.messages,
252
+ { role: 'assistant', content: result.text },
253
+ { role: 'user', content: `That response did not match the required schema (${validated.message}). Reply again with ONLY a valid JSON value that matches it.` },
254
+ ],
255
+ };
256
+ result = await this.chat(conn, retry);
257
+ validated = await validateWithSchema(schema, result.text);
258
+ if (validated.ok)
259
+ return { data: validated.value, result };
260
+ throw new AIError(`Model output failed schema validation: ${validated.message}`, { kind: 'invalid_response', provider: conn.provider });
261
+ }
262
+ /**
263
+ * Produce embeddings through the same governed pipeline as chat: policy check,
264
+ * key resolution, `beforeCall` hook, concurrency, and exactly one redacted
265
+ * telemetry record. Throws a typed `invalid_request` error for providers whose
266
+ * adapter has no `embed` (Anthropic, Google) rather than failing silently.
267
+ */
268
+ async embed(conn, req) {
269
+ const callId = createCallId();
270
+ const startedAt = Date.now();
271
+ const inputChars = (Array.isArray(req.input) ? req.input : [req.input]).reduce((sum, text) => sum + text.length, 0);
272
+ const fail = async (error) => {
273
+ await this.recordEmbed(callId, conn, req, startedAt, { estimated: true }, inputChars, error);
274
+ throw this.redactedError(error);
275
+ };
276
+ const preflight = await this.preflight(callId, conn, req.model, req.metadata);
277
+ if (!preflight.ok)
278
+ return fail(preflight.error);
279
+ const resolved = preflight.resolved;
280
+ const adapter = adapterFor(conn.provider, conn.baseUrl);
281
+ if (!adapter.embed) {
282
+ return fail(new AIError(`Provider ${conn.provider} does not support embeddings`, { kind: 'invalid_request', retryable: false, provider: conn.provider }));
283
+ }
284
+ await this.acquire(req.signal);
285
+ try {
286
+ const result = await adapter.embed(resolved, req);
287
+ await this.recordEmbed(callId, conn, req, startedAt, result.usage, inputChars);
288
+ return result;
289
+ }
290
+ catch (errorValue) {
291
+ return fail(fromUnknown(errorValue, conn.provider));
292
+ }
293
+ finally {
294
+ this.release();
295
+ }
296
+ }
297
+ async recordEmbed(callId, conn, req, startedAt, usage, inputChars, error) {
298
+ const costUsd = error ? undefined : this.opts.pricing?.({ provider: conn.provider, model: req.model, usage });
299
+ await this.record({
300
+ callId,
301
+ connectionId: conn.id,
302
+ provider: conn.provider,
303
+ model: req.model,
304
+ startedAt,
305
+ timing: { firstTokenMs: null, totalMs: Date.now() - startedAt },
306
+ usage,
307
+ finishReason: error ? (error.kind === 'canceled' ? 'canceled' : 'error') : 'stop',
308
+ ...(error ? { error: { kind: error.kind, status: error.status, message: error.message } } : {}),
309
+ attempts: 1,
310
+ metadata: { ...req.metadata, operation: '__embed__' },
311
+ promptChars: inputChars,
312
+ responseChars: 0,
313
+ ...(costUsd !== undefined ? { costUsd } : {}),
314
+ });
315
+ }
316
+ async runProbe(conn, operation, action) {
317
+ const callId = createCallId();
318
+ const startedAt = Date.now();
319
+ const req = { model: operation, messages: [], metadata: { operation } };
320
+ try {
321
+ const preflight = await this.preflight(callId, conn, operation, req.metadata);
322
+ if (!preflight.ok)
323
+ throw preflight.error;
324
+ const resolved = preflight.resolved;
325
+ await this.acquire(undefined);
326
+ try {
327
+ const value = await action(resolved);
328
+ await this.recordSuccess(callId, conn, req, startedAt, 1, {
329
+ text: '',
330
+ finishReason: 'stop',
331
+ usage: { estimated: true },
332
+ timing: { firstTokenMs: null, totalMs: Date.now() - startedAt },
333
+ model: operation,
334
+ source: { provider: conn.provider, connectionId: conn.id, baseUrl: resolved.baseUrl },
335
+ });
336
+ return value;
337
+ }
338
+ finally {
339
+ this.release();
340
+ }
341
+ }
342
+ catch (errorValue) {
343
+ const error = fromUnknown(errorValue, conn.provider);
344
+ await this.recordFailure(callId, conn, req, startedAt, 1, error);
345
+ throw this.redactedError(error);
346
+ }
347
+ }
348
+ async resolveConnection(conn) {
349
+ const profile = profileFor(conn.provider, conn.baseUrl);
350
+ const baseUrl = conn.baseUrl ?? profile.defaultBaseUrl;
351
+ if (!baseUrl)
352
+ throw new AIError(`Provider ${conn.provider} requires baseUrl`, { kind: 'invalid_request', retryable: false, provider: conn.provider });
353
+ const keyRef = conn.keyRef ?? { kind: 'none' };
354
+ const key = await this.opts.keySource.resolve(keyRef);
355
+ if (!key.ok) {
356
+ throw new AIError(`API key unavailable: ${key.reason}`, { kind: 'key_unavailable', retryable: false, provider: conn.provider });
357
+ }
358
+ this.sessionRedactor.addSecret(key.apiKey);
359
+ return {
360
+ ...conn,
361
+ baseUrl: trimSlash(baseUrl),
362
+ apiKey: key.apiKey,
363
+ headers: applyAuth(profile, key.apiKey, conn.headers ?? {}),
364
+ };
365
+ }
366
+ async acquire(signal) {
367
+ const max = this.opts.limits?.maxConcurrent ?? Number.POSITIVE_INFINITY;
368
+ while (this.active >= max) {
369
+ await new Promise((resolve, reject) => {
370
+ let waiter;
371
+ const onAbort = () => {
372
+ const index = this.queue.indexOf(waiter);
373
+ if (index >= 0)
374
+ this.queue.splice(index, 1);
375
+ reject(new AIError('Call canceled while waiting for concurrency slot', { kind: 'canceled', retryable: false }));
376
+ };
377
+ if (signal?.aborted) {
378
+ reject(new AIError('Call canceled while waiting for concurrency slot', { kind: 'canceled', retryable: false }));
379
+ return;
380
+ }
381
+ signal?.addEventListener('abort', onAbort, { once: true });
382
+ waiter = { resolve, reject, signal, onAbort };
383
+ this.queue.push(waiter);
384
+ });
385
+ }
386
+ this.active += 1;
387
+ const minInterval = this.opts.limits?.minIntervalMs ?? 0;
388
+ const previousLastStarted = this.lastStarted;
389
+ const wait = Math.max(0, previousLastStarted + minInterval - Date.now());
390
+ const reserved = Date.now() + wait;
391
+ this.lastStarted = reserved;
392
+ try {
393
+ if (wait)
394
+ await sleep(wait, signal);
395
+ }
396
+ catch (error) {
397
+ this.release();
398
+ // Only undo our own reservation — a later caller may have already
399
+ // paced itself off `reserved` and must keep that spacing.
400
+ if (this.lastStarted === reserved)
401
+ this.lastStarted = previousLastStarted;
402
+ throw error;
403
+ }
404
+ }
405
+ release() {
406
+ this.active = Math.max(0, this.active - 1);
407
+ while (this.queue.length) {
408
+ const waiter = this.queue.shift();
409
+ waiter.signal?.removeEventListener('abort', waiter.onAbort);
410
+ if (waiter.signal?.aborted)
411
+ continue;
412
+ waiter.resolve();
413
+ break;
414
+ }
415
+ }
416
+ retryDelay(error, attempt) {
417
+ const base = this.opts.retry?.baseDelayMs ?? 250;
418
+ const max = this.opts.retry?.maxDelayMs ?? 30_000;
419
+ if (error.retryAfterMs !== undefined)
420
+ return Math.min(error.retryAfterMs, max);
421
+ const exponential = Math.min(max, base * 2 ** Math.max(0, attempt - 1));
422
+ return Math.round(exponential * (0.75 + Math.random() * 0.5));
423
+ }
424
+ async recordSuccess(callId, conn, req, startedAt, attempts, result) {
425
+ const costUsd = this.opts.pricing?.({ provider: conn.provider, model: req.model, usage: result.usage });
426
+ await this.record({
427
+ callId,
428
+ connectionId: conn.id,
429
+ provider: conn.provider,
430
+ model: req.model,
431
+ startedAt,
432
+ timing: result.timing,
433
+ usage: result.usage,
434
+ finishReason: result.finishReason,
435
+ attempts,
436
+ metadata: req.metadata,
437
+ promptChars: promptChars(req.messages),
438
+ responseChars: result.text.length,
439
+ ...(costUsd !== undefined ? { costUsd } : {}),
440
+ });
441
+ }
442
+ async recordFailure(callId, conn, req, startedAt, attempts, error) {
443
+ await this.record({
444
+ callId,
445
+ connectionId: conn.id,
446
+ provider: conn.provider,
447
+ model: req.model,
448
+ startedAt,
449
+ timing: { firstTokenMs: null, totalMs: Date.now() - startedAt },
450
+ usage: { estimated: true },
451
+ finishReason: error.kind === 'canceled' ? 'canceled' : 'error',
452
+ error: { kind: error.kind, status: error.status, message: error.message },
453
+ attempts,
454
+ metadata: req.metadata,
455
+ promptChars: promptChars(req.messages),
456
+ responseChars: 0,
457
+ });
458
+ }
459
+ async record(record) {
460
+ const redacted = redactRecord(record, (text) => this.redact(text));
461
+ try {
462
+ await this.opts.telemetry?.record(redacted);
463
+ await this.opts.hooks?.afterCall?.(redacted);
464
+ }
465
+ catch {
466
+ // Telemetry and afterCall hooks must not re-drive provider calls or turn
467
+ // an already-completed model response into a retry.
468
+ }
469
+ }
470
+ redact(text) {
471
+ return (this.opts.redactor ?? this.sessionRedactor).redact(this.sessionRedactor.redact(text));
472
+ }
473
+ redactedError(error) {
474
+ return new AIError(this.redact(error.message), {
475
+ kind: error.kind,
476
+ status: error.status,
477
+ retryable: error.retryable,
478
+ provider: error.provider,
479
+ raw: error.raw === undefined ? undefined : this.redact(error.raw),
480
+ retryAfterMs: error.retryAfterMs,
481
+ cause: this.redactedCause(error.cause),
482
+ });
483
+ }
484
+ redactedCause(cause) {
485
+ if (cause instanceof Error) {
486
+ const redacted = new Error(this.redact(cause.message));
487
+ redacted.name = cause.name;
488
+ redacted.stack = undefined;
489
+ return redacted;
490
+ }
491
+ return cause;
492
+ }
493
+ }
494
+ function redactRecord(record, redact) {
495
+ return {
496
+ ...record,
497
+ error: record.error ? { ...record.error, message: redact(record.error.message) } : undefined,
498
+ metadata: redactMetadata(record.metadata, redact),
499
+ };
500
+ }
501
+ /**
502
+ * Redacts metadata by round-tripping through JSON. Metadata is an app-supplied
503
+ * passthrough and may contain values JSON cannot represent (BigInt, circular
504
+ * references, functions); redaction must never throw, so a non-serializable
505
+ * payload is replaced with a sentinel rather than crashing the telemetry path.
506
+ */
507
+ function redactMetadata(metadata, redact) {
508
+ if (!metadata)
509
+ return undefined;
510
+ try {
511
+ return JSON.parse(redact(JSON.stringify(metadata)));
512
+ }
513
+ catch {
514
+ return { redacted: true, note: 'metadata was not JSON-serializable' };
515
+ }
516
+ }
517
+ function trimSlash(value) {
518
+ return value.replace(/\/+$/, '');
519
+ }
520
+ /**
521
+ * Drops the resolved API key *and* neutralizes the auth headers built from it,
522
+ * so a `beforeCall` hook can inspect the endpoint but never the secret.
523
+ * `keyRef` is scrubbed too — a `{ kind: 'literal' }` ref carries the plaintext
524
+ * key, and hooks routinely log the whole object.
525
+ */
526
+ function safeResolved(resolved) {
527
+ const { apiKey: _apiKey, headers, ...rest } = resolved;
528
+ return { ...rest, ...safeKeyRef(resolved), headers: maskAuthHeaders(headers) };
529
+ }
530
+ /**
531
+ * The caller's own `Connection`, with any plaintext `keyRef` masked. Hooks get
532
+ * the connection so they can key off `id`/`provider`/`baseUrl`; they must never
533
+ * be handed the secret, since logging `info.connection` for audit is the
534
+ * obvious thing to do and would otherwise ship the key in clear text.
535
+ */
536
+ function safeConnection(conn) {
537
+ return { ...conn, ...safeKeyRef(conn) };
538
+ }
539
+ function safeKeyRef(conn) {
540
+ if (conn.keyRef?.kind !== 'literal')
541
+ return conn.keyRef === undefined ? {} : { keyRef: conn.keyRef };
542
+ return { keyRef: { kind: 'literal', value: REDACTED } };
543
+ }
544
+ const REDACTED = '[REDACTED]';
545
+ /** Header names whose value is derived from the API key by {@link applyAuth}. */
546
+ const AUTH_HEADERS = new Set(['authorization', 'x-api-key', 'x-goog-api-key', 'api-key']);
547
+ function maskAuthHeaders(headers) {
548
+ const masked = {};
549
+ for (const [name, value] of Object.entries(headers)) {
550
+ masked[name] = AUTH_HEADERS.has(name.toLowerCase()) ? REDACTED : value;
551
+ }
552
+ return masked;
553
+ }
554
+ /**
555
+ * Attach a per-call `Idempotency-Key` for providers that honor one, so a retry
556
+ * after a dropped connection can't be billed as a second generation. Only set
557
+ * where the profile declares support, and never overrides a caller-supplied
558
+ * header.
559
+ */
560
+ function withIdempotencyKey(resolved, callId) {
561
+ const profile = profileFor(resolved.provider, resolved.baseUrl);
562
+ if (!profile.quirks?.supportsIdempotencyKey)
563
+ return resolved;
564
+ if (Object.keys(resolved.headers).some((name) => name.toLowerCase() === 'idempotency-key'))
565
+ return resolved;
566
+ return { ...resolved, headers: { ...resolved.headers, 'idempotency-key': callId } };
567
+ }
568
+ async function validateWithSchema(schema, text) {
569
+ const value = extractJson(text);
570
+ if (value === null)
571
+ return { ok: false, message: 'no JSON found in model output' };
572
+ const result = await schema['~standard'].validate(value);
573
+ if (result.issues) {
574
+ const message = result.issues.map((issue) => issue.message).join('; ');
575
+ return { ok: false, message: message || 'validation failed' };
576
+ }
577
+ return { ok: true, value: result.value };
578
+ }
579
+ function createCallId() {
580
+ return globalThis.crypto?.randomUUID?.() ?? `call_${Date.now()}_${Math.random().toString(36).slice(2)}`;
581
+ }
582
+ //# sourceMappingURL=handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACvG,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAoB9C,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAgD/C;;;;GAIG;AACH,IAAI,cAAc,GAAG,KAAK,CAAC;AAE3B,4DAA4D;AAC5D,MAAM,UAAU,0BAA0B;IACxC,cAAc,GAAG,KA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,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,CAAC;IAChE,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;AAC3C,CAAC;AAED,SAAS,YAAY;IACnB,OAAO,UAAU,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,IAAI,QAAQ,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;AAC1G,CAAC"}
@@ -0,0 +1,13 @@
1
+ export * from './types.js';
2
+ export * from './errors.js';
3
+ export * from './transport.js';
4
+ export * from './json.js';
5
+ export * from './reasoning.js';
6
+ export * from './tokens.js';
7
+ export * from './keys.js';
8
+ export * from './connect.js';
9
+ export * from './redact.js';
10
+ export * from './policy.js';
11
+ export * from './handler.js';
12
+ export * from './adapters/index.js';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,13 @@
1
+ export * from './types.js';
2
+ export * from './errors.js';
3
+ export * from './transport.js';
4
+ export * from './json.js';
5
+ export * from './reasoning.js';
6
+ export * from './tokens.js';
7
+ export * from './keys.js';
8
+ export * from './connect.js';
9
+ export * from './redact.js';
10
+ export * from './policy.js';
11
+ export * from './handler.js';
12
+ export * from './adapters/index.js';
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC"}