@jxburros/ai-nugget 0.3.1

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 (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +316 -0
  3. package/dist/adapters/engines/anthropic.d.ts +8 -0
  4. package/dist/adapters/engines/anthropic.js +278 -0
  5. package/dist/adapters/engines/base.d.ts +23 -0
  6. package/dist/adapters/engines/base.js +93 -0
  7. package/dist/adapters/engines/google.d.ts +8 -0
  8. package/dist/adapters/engines/google.js +217 -0
  9. package/dist/adapters/engines/ollama.d.ts +10 -0
  10. package/dist/adapters/engines/ollama.js +160 -0
  11. package/dist/adapters/engines/openaiChat.d.ts +15 -0
  12. package/dist/adapters/engines/openaiChat.js +228 -0
  13. package/dist/adapters/index.d.ts +5 -0
  14. package/dist/adapters/index.js +17 -0
  15. package/dist/adapters/profiles.d.ts +42 -0
  16. package/dist/adapters/profiles.js +111 -0
  17. package/dist/agent/index.d.ts +3 -0
  18. package/dist/agent/index.js +3 -0
  19. package/dist/agent/loop.d.ts +70 -0
  20. package/dist/agent/loop.js +263 -0
  21. package/dist/agent/tools.d.ts +29 -0
  22. package/dist/agent/tools.js +48 -0
  23. package/dist/errors.d.ts +22 -0
  24. package/dist/errors.js +80 -0
  25. package/dist/handler.d.ts +48 -0
  26. package/dist/handler.js +371 -0
  27. package/dist/index.d.ts +11 -0
  28. package/dist/index.js +11 -0
  29. package/dist/json.d.ts +7 -0
  30. package/dist/json.js +114 -0
  31. package/dist/keys.d.ts +7 -0
  32. package/dist/keys.js +78 -0
  33. package/dist/policy.d.ts +6 -0
  34. package/dist/policy.js +37 -0
  35. package/dist/redact.d.ts +8 -0
  36. package/dist/redact.js +46 -0
  37. package/dist/tokens.d.ts +5 -0
  38. package/dist/tokens.js +18 -0
  39. package/dist/transport.d.ts +28 -0
  40. package/dist/transport.js +145 -0
  41. package/dist/types.d.ts +191 -0
  42. package/dist/types.js +4 -0
  43. package/dist/util.d.ts +8 -0
  44. package/dist/util.js +51 -0
  45. package/nugget/VERSION.txt +2 -0
  46. package/nugget/src/adapters/engines/anthropic.ts +260 -0
  47. package/nugget/src/adapters/engines/base.ts +90 -0
  48. package/nugget/src/adapters/engines/google.ts +209 -0
  49. package/nugget/src/adapters/engines/ollama.ts +153 -0
  50. package/nugget/src/adapters/engines/openaiChat.ts +223 -0
  51. package/nugget/src/adapters/index.ts +17 -0
  52. package/nugget/src/adapters/profiles.ts +149 -0
  53. package/nugget/src/agent/index.ts +2 -0
  54. package/nugget/src/agent/loop.ts +314 -0
  55. package/nugget/src/agent/tools.ts +55 -0
  56. package/nugget/src/errors.ts +80 -0
  57. package/nugget/src/handler.ts +408 -0
  58. package/nugget/src/index.ts +10 -0
  59. package/nugget/src/json.ts +108 -0
  60. package/nugget/src/keys.ts +70 -0
  61. package/nugget/src/policy.ts +39 -0
  62. package/nugget/src/redact.ts +48 -0
  63. package/nugget/src/tokens.ts +21 -0
  64. package/nugget/src/transport.ts +148 -0
  65. package/nugget/src/types.ts +175 -0
  66. package/nugget/src/util.ts +51 -0
  67. package/package.json +69 -0
@@ -0,0 +1,263 @@
1
+ import { profileFor } from '../adapters/profiles.js';
2
+ import { AIError } from '../errors.js';
3
+ import { extractJson } from '../json.js';
4
+ import { mergeUsage } from '../tokens.js';
5
+ import { sleep } from '../util.js';
6
+ import { validateToolArgs } from './tools.js';
7
+ export function runAgent(opts) {
8
+ let resolveResult;
9
+ const result = new Promise((resolve) => {
10
+ resolveResult = resolve;
11
+ });
12
+ const iterable = run(opts, resolveResult);
13
+ return Object.assign(iterable, { result });
14
+ }
15
+ async function* run(opts, resolveResult) {
16
+ const messages = [...opts.messages];
17
+ const toolMode = resolveToolMode(opts);
18
+ const maxSteps = opts.budget?.maxSteps ?? 8;
19
+ const agentSignal = createAgentSignal(opts.signal, opts.budget?.deadlineMs);
20
+ let usage;
21
+ let finalText = '';
22
+ let step = 0;
23
+ let settled = false;
24
+ try {
25
+ while (step < maxSteps) {
26
+ step += 1;
27
+ if (agentSignal.signal?.aborted)
28
+ return yield* yieldDone(agentSignal.timedOut() ? 'deadline' : 'canceled');
29
+ yield emit(opts, { type: 'step_start', step });
30
+ const calls = [];
31
+ let stepText = '';
32
+ let streamFailure;
33
+ const requestMessages = toolMode === 'promptJson' ? withPromptJsonInstruction(messages, opts.tools) : messages;
34
+ for await (const event of opts.handler.stream(opts.connection, {
35
+ model: opts.model,
36
+ messages: requestMessages,
37
+ tools: toolMode === 'promptJson' ? undefined : opts.tools,
38
+ signal: agentSignal.signal,
39
+ metadata: { ...opts.metadata, agentStep: step },
40
+ })) {
41
+ if (event.type === 'delta')
42
+ stepText += event.text;
43
+ if (event.type === 'tool_call')
44
+ calls.push(event.call);
45
+ if (event.type === 'error')
46
+ streamFailure = event.error;
47
+ if (event.type === 'done') {
48
+ usage = usage ? mergeUsage(usage, event.result.usage) : event.result.usage;
49
+ if (toolMode === 'promptJson' && calls.length === 0)
50
+ calls.push(...callsFromPromptJson(stepText));
51
+ }
52
+ yield emit(opts, event);
53
+ }
54
+ // A handler-level failure (auth, policy, cancel, exhausted retries) must
55
+ // stop the loop honestly rather than looking like an empty completion.
56
+ if (streamFailure)
57
+ return yield* yieldDone(agentSignal.timedOut() ? 'deadline' : streamFailure.kind === 'canceled' ? 'canceled' : 'error');
58
+ finalText = stepText;
59
+ messages.push(toolMode === 'promptJson'
60
+ ? { role: 'assistant', content: stepText }
61
+ : { role: 'assistant', content: stepText, toolCalls: calls.length ? calls : undefined });
62
+ if (calls.length === 0)
63
+ return yield* yieldDone('finished');
64
+ for (const call of calls) {
65
+ if (agentSignal.signal?.aborted)
66
+ return yield* yieldDone(agentSignal.timedOut() ? 'deadline' : 'canceled');
67
+ const tool = opts.tools.find((candidate) => candidate.name === call.name);
68
+ if (!tool) {
69
+ yield* appendToolError(opts, messages, step, call, `Unknown tool: ${call.name}`);
70
+ continue;
71
+ }
72
+ const validation = validateToolArgs(tool, call);
73
+ if (!validation.ok) {
74
+ yield* appendToolError(opts, messages, step, call, validation.message);
75
+ continue;
76
+ }
77
+ let args = validation.args;
78
+ if (tool.sideEffects) {
79
+ if (!opts.approval) {
80
+ yield* appendToolDenied(opts, messages, step, call, 'No approval gate configured');
81
+ continue;
82
+ }
83
+ const approval = await opts.approval({ call, tool, step });
84
+ if (agentSignal.signal?.aborted)
85
+ return yield* yieldDone(agentSignal.timedOut() ? 'deadline' : 'canceled');
86
+ if (approval === 'deny') {
87
+ yield* appendToolDenied(opts, messages, step, call, 'Denied by approval gate');
88
+ continue;
89
+ }
90
+ if (approval !== 'allow') {
91
+ const modified = validateToolArgs(tool, { ...call, arguments: approval.modifiedArguments });
92
+ if (!modified.ok) {
93
+ yield* appendToolError(opts, messages, step, call, modified.message);
94
+ continue;
95
+ }
96
+ args = modified.args;
97
+ }
98
+ }
99
+ yield emit(opts, { type: 'tool_start', step, call });
100
+ let executed;
101
+ try {
102
+ const result = await tool.execute(args, {
103
+ signal: agentSignal.signal ?? new AbortController().signal,
104
+ callId: call.id,
105
+ step,
106
+ metadata: opts.metadata,
107
+ });
108
+ executed = { ok: true, result };
109
+ }
110
+ catch (error) {
111
+ executed = { ok: false, message: error instanceof Error ? error.message : 'Tool failed' };
112
+ }
113
+ if (!executed.ok) {
114
+ yield* appendToolError(opts, messages, step, call, executed.message);
115
+ continue;
116
+ }
117
+ try {
118
+ messages.push({ role: 'tool', toolCallId: call.id, name: call.name, content: JSON.stringify(executed.result) });
119
+ yield emit(opts, { type: 'tool_result', step, call, result: executed.result, isError: false });
120
+ }
121
+ catch (error) {
122
+ const message = error instanceof Error ? error.message : 'Tool result was not serializable';
123
+ yield* appendToolError(opts, messages, step, call, message);
124
+ }
125
+ }
126
+ const totalTokens = (usage?.inputTokens ?? 0) + (usage?.outputTokens ?? 0);
127
+ if (opts.budget?.maxTokens && totalTokens > opts.budget.maxTokens)
128
+ return yield* yieldDone('budget');
129
+ await sleep(0, agentSignal.signal);
130
+ }
131
+ return yield* yieldDone('max_steps');
132
+ }
133
+ catch (error) {
134
+ const result = makeResult(finalText, messages, usage ?? { estimated: true }, step, agentSignal.timedOut() ? 'deadline' : (agentSignal.signal?.aborted || (error instanceof AIError && error.kind === 'canceled')) ? 'canceled' : 'error');
135
+ settled = true;
136
+ resolveResult(result);
137
+ yield emit(opts, { type: 'agent_done', result });
138
+ }
139
+ finally {
140
+ agentSignal.dispose();
141
+ if (!settled) {
142
+ const result = makeResult(finalText, messages, usage ?? { estimated: true }, step, 'canceled');
143
+ resolveResult(result);
144
+ }
145
+ }
146
+ function* yieldDone(stopReason) {
147
+ const result = makeResult(finalText, messages, usage ?? { estimated: true }, step, stopReason);
148
+ settled = true;
149
+ resolveResult(result);
150
+ yield emit(opts, { type: 'agent_done', result });
151
+ }
152
+ }
153
+ function emit(opts, event) {
154
+ opts.onEvent?.(event);
155
+ return event;
156
+ }
157
+ function makeResult(finalText, messages, usage, steps, stopReason) {
158
+ return { finalText, messages, usage, steps, stopReason };
159
+ }
160
+ function* appendToolError(opts, messages, step, call, message) {
161
+ const result = { error: message };
162
+ messages.push({ role: 'tool', toolCallId: call.id, name: call.name, content: JSON.stringify(result) });
163
+ yield emit(opts, { type: 'tool_result', step, call, result, isError: true });
164
+ }
165
+ function* appendToolDenied(opts, messages, step, call, reason) {
166
+ messages.push({ role: 'tool', toolCallId: call.id, name: call.name, content: JSON.stringify({ denied: true, reason }) });
167
+ yield emit(opts, { type: 'tool_denied', step, call, reason });
168
+ }
169
+ function resolveToolMode(opts) {
170
+ const mode = opts.toolMode ?? 'auto';
171
+ if (mode !== 'auto')
172
+ return mode;
173
+ return profileFor(opts.connection.provider, opts.connection.baseUrl).capabilities.nativeTools ? 'native' : 'promptJson';
174
+ }
175
+ function withPromptJsonInstruction(messages, tools) {
176
+ return [
177
+ {
178
+ role: 'system',
179
+ content: `When you need tools, respond only with JSON. For one tool: {"tool":"name","input":{...}}. For several in one turn: {"tools":[{"tool":"name","input":{...}}]}. Available tools: ${tools.map((tool) => `${tool.name}: ${tool.description}`).join('; ')}`,
180
+ },
181
+ ...messages.map(toPromptJsonMessage),
182
+ ];
183
+ }
184
+ function toPromptJsonMessage(message) {
185
+ if (message.role === 'tool') {
186
+ return {
187
+ role: 'user',
188
+ content: `Tool ${message.name ?? message.toolCallId ?? 'unknown'} returned: ${textContent(message.content)}`,
189
+ };
190
+ }
191
+ return {
192
+ role: message.role,
193
+ content: textContent(message.content),
194
+ };
195
+ }
196
+ /**
197
+ * Parses a promptJson tool directive into zero or more calls. Accepts the single
198
+ * form ({"tool","input"}), the batched form ({"tools":[...]}), and a bare array
199
+ * of directives, so a promptJson-mode model can request several tools per turn
200
+ * just like native tool-calling can. Malformed entries are skipped, not thrown.
201
+ */
202
+ function callsFromPromptJson(text) {
203
+ const value = extractJson(text);
204
+ if (!value || typeof value !== 'object')
205
+ return [];
206
+ const entries = Array.isArray(value)
207
+ ? value
208
+ : Array.isArray(value.tools)
209
+ ? value.tools
210
+ : [value];
211
+ const calls = [];
212
+ for (const entry of entries) {
213
+ if (!entry || typeof entry !== 'object' || Array.isArray(entry))
214
+ continue;
215
+ const record = entry;
216
+ if (typeof record.tool !== 'string')
217
+ continue;
218
+ calls.push({
219
+ id: crypto.randomUUID(),
220
+ name: record.tool,
221
+ arguments: record.input && typeof record.input === 'object' ? record.input : {},
222
+ raw: JSON.stringify(record.input ?? {}),
223
+ });
224
+ }
225
+ return calls;
226
+ }
227
+ function textContent(content) {
228
+ if (typeof content === 'string')
229
+ return content;
230
+ if (!content)
231
+ return '';
232
+ return content.filter((part) => part.type === 'text').map((part) => part.text ?? '').join('\n');
233
+ }
234
+ function createAgentSignal(signal, deadlineMs) {
235
+ if (!signal && deadlineMs === undefined)
236
+ return { signal: undefined, timedOut: () => false, dispose: () => undefined };
237
+ const controller = new AbortController();
238
+ let didTimeOut = false;
239
+ let timer;
240
+ const onAbort = () => controller.abort(signal?.reason);
241
+ if (signal) {
242
+ if (signal.aborted)
243
+ onAbort();
244
+ else
245
+ signal.addEventListener('abort', onAbort, { once: true });
246
+ }
247
+ if (deadlineMs !== undefined) {
248
+ timer = setTimeout(() => {
249
+ didTimeOut = true;
250
+ controller.abort(new AIError(`Agent deadline exceeded after ${deadlineMs}ms`, { kind: 'budget_exceeded', retryable: false }));
251
+ }, deadlineMs);
252
+ }
253
+ return {
254
+ signal: controller.signal,
255
+ timedOut: () => didTimeOut,
256
+ dispose() {
257
+ if (timer)
258
+ clearTimeout(timer);
259
+ signal?.removeEventListener('abort', onAbort);
260
+ },
261
+ };
262
+ }
263
+ //# sourceMappingURL=loop.js.map
@@ -0,0 +1,29 @@
1
+ import type { ToolCall, ToolSchema } from '../types.js';
2
+ export interface ToolSpec<A = unknown, R = unknown> extends ToolSchema {
3
+ sideEffects?: boolean;
4
+ execute(args: A, ctx: ToolContext): Promise<R> | R;
5
+ }
6
+ export interface ToolContext {
7
+ signal: AbortSignal;
8
+ callId: string;
9
+ step: number;
10
+ metadata?: Record<string, unknown>;
11
+ }
12
+ export declare function defineTool<A, R>(spec: ToolSpec<A, R>): ToolSpec<A, R>;
13
+ /**
14
+ * Light validation only: object-ness, `required` presence, and top-level
15
+ * `properties[key].type` against JS typeof/Array.isArray/Number.isInteger.
16
+ * It does not implement full JSON Schema — no `enum`, nested `properties`,
17
+ * `oneOf`/`anyOf`, numeric bounds, string `pattern`, array `items` schemas, or
18
+ * `additionalProperties`. That's intentional for a zero-dependency nugget; a
19
+ * caller that needs stricter guarantees should validate `args` again inside
20
+ * `tool.execute` with its own schema library.
21
+ */
22
+ export declare function validateToolArgs(tool: ToolSpec, call: ToolCall): {
23
+ ok: true;
24
+ args: unknown;
25
+ } | {
26
+ ok: false;
27
+ message: string;
28
+ };
29
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1,48 @@
1
+ export function defineTool(spec) {
2
+ return spec;
3
+ }
4
+ /**
5
+ * Light validation only: object-ness, `required` presence, and top-level
6
+ * `properties[key].type` against JS typeof/Array.isArray/Number.isInteger.
7
+ * It does not implement full JSON Schema — no `enum`, nested `properties`,
8
+ * `oneOf`/`anyOf`, numeric bounds, string `pattern`, array `items` schemas, or
9
+ * `additionalProperties`. That's intentional for a zero-dependency nugget; a
10
+ * caller that needs stricter guarantees should validate `args` again inside
11
+ * `tool.execute` with its own schema library.
12
+ */
13
+ export function validateToolArgs(tool, call) {
14
+ const schema = tool.parameters;
15
+ if (schema.type && schema.type !== 'object')
16
+ return { ok: false, message: `Tool ${tool.name} parameters must be an object schema` };
17
+ if (typeof call.arguments !== 'object' || call.arguments === null || Array.isArray(call.arguments)) {
18
+ return { ok: false, message: `Tool ${tool.name} expected object arguments` };
19
+ }
20
+ const args = call.arguments;
21
+ const required = Array.isArray(schema.required) ? schema.required.filter((key) => typeof key === 'string') : [];
22
+ for (const key of required) {
23
+ if (!(key in args))
24
+ return { ok: false, message: `Tool ${tool.name} missing required argument: ${key}` };
25
+ }
26
+ const properties = schema.properties && typeof schema.properties === 'object' ? schema.properties : {};
27
+ for (const [key, spec] of Object.entries(properties)) {
28
+ if (!(key in args) || spec.type === undefined)
29
+ continue;
30
+ const value = args[key];
31
+ const ok = matchesType(value, spec.type);
32
+ if (!ok)
33
+ return { ok: false, message: `Tool ${tool.name} argument ${key} must be ${spec.type}` };
34
+ }
35
+ return { ok: true, args };
36
+ }
37
+ function matchesType(value, type) {
38
+ if (type === 'array')
39
+ return Array.isArray(value);
40
+ if (type === 'integer')
41
+ return typeof value === 'number' && Number.isInteger(value);
42
+ if (type === 'null')
43
+ return value === null;
44
+ if (type === 'object')
45
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
46
+ return typeof value === type;
47
+ }
48
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1,22 @@
1
+ import type { AIErrorKind } from './types.js';
2
+ export declare class AIError extends Error {
3
+ kind: AIErrorKind;
4
+ status?: number;
5
+ retryable: boolean;
6
+ provider?: string;
7
+ raw?: string;
8
+ retryAfterMs?: number;
9
+ constructor(message: string, opts: {
10
+ kind: AIErrorKind;
11
+ status?: number;
12
+ retryable?: boolean;
13
+ provider?: string;
14
+ raw?: string;
15
+ retryAfterMs?: number;
16
+ cause?: unknown;
17
+ });
18
+ }
19
+ export declare function defaultRetryable(kind: AIErrorKind): boolean;
20
+ export declare function classify(status: number, body?: string, provider?: string, headers?: Headers): AIError;
21
+ export declare function fromUnknown(error: unknown, provider?: string): AIError;
22
+ //# sourceMappingURL=errors.d.ts.map
package/dist/errors.js ADDED
@@ -0,0 +1,80 @@
1
+ export class AIError extends Error {
2
+ kind;
3
+ status;
4
+ retryable;
5
+ provider;
6
+ raw;
7
+ retryAfterMs;
8
+ constructor(message, opts) {
9
+ super(message);
10
+ this.name = 'AIError';
11
+ this.kind = opts.kind;
12
+ this.retryable = opts.retryable ?? defaultRetryable(opts.kind);
13
+ if (opts.status !== undefined)
14
+ this.status = opts.status;
15
+ if (opts.provider !== undefined)
16
+ this.provider = opts.provider;
17
+ if (opts.raw !== undefined)
18
+ this.raw = opts.raw;
19
+ if (opts.retryAfterMs !== undefined)
20
+ this.retryAfterMs = opts.retryAfterMs;
21
+ if (opts.cause !== undefined)
22
+ this.cause = opts.cause;
23
+ }
24
+ }
25
+ export function defaultRetryable(kind) {
26
+ return kind === 'rate_limit' || kind === 'timeout' || kind === 'network' || kind === 'server' || kind === 'invalid_response';
27
+ }
28
+ export function classify(status, body = '', provider, headers) {
29
+ const excerpt = body.slice(0, 200);
30
+ const lower = body.toLowerCase();
31
+ let kind = 'server';
32
+ if (status === 401 || status === 403)
33
+ kind = 'auth';
34
+ else if (status === 408)
35
+ kind = 'timeout';
36
+ else if (status === 429)
37
+ kind = 'rate_limit';
38
+ else if (status === 400 || status === 422) {
39
+ kind = lower.includes('context') || lower.includes('maximum context') || lower.includes('token limit')
40
+ ? 'context_length'
41
+ : 'invalid_request';
42
+ }
43
+ else if (status >= 500)
44
+ kind = 'server';
45
+ else
46
+ kind = 'invalid_request';
47
+ return new AIError(`HTTP ${status}: ${excerpt}`, {
48
+ kind,
49
+ status,
50
+ provider,
51
+ raw: excerpt,
52
+ retryAfterMs: parseRetryAfter(headers?.get('retry-after') ?? null),
53
+ });
54
+ }
55
+ export function fromUnknown(error, provider) {
56
+ if (error instanceof AIError)
57
+ return error;
58
+ if (error instanceof DOMException && error.name === 'AbortError') {
59
+ return new AIError('Request was canceled', { kind: 'canceled', retryable: false, provider, cause: error });
60
+ }
61
+ if (error instanceof Error && /timeout|timed out/i.test(error.message)) {
62
+ return new AIError(error.message, { kind: 'timeout', provider, cause: error });
63
+ }
64
+ if (error instanceof Error) {
65
+ return new AIError(error.message, { kind: 'network', provider, cause: error });
66
+ }
67
+ return new AIError('Unknown AI provider error', { kind: 'network', provider, cause: error });
68
+ }
69
+ function parseRetryAfter(value) {
70
+ if (!value)
71
+ return undefined;
72
+ const seconds = Number(value);
73
+ if (Number.isFinite(seconds))
74
+ return Math.max(0, seconds * 1000);
75
+ const time = Date.parse(value);
76
+ if (!Number.isNaN(time))
77
+ return Math.max(0, time - Date.now());
78
+ return undefined;
79
+ }
80
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,48 @@
1
+ import type { CallInfo, CallRecord, ChatRequest, ChatResult, Connection, GovernancePolicy, KeySource, ModelInfo, Redactor, StreamEvent, TelemetrySink } from './types.js';
2
+ export interface HandlerOptions {
3
+ keySource: KeySource;
4
+ policy?: GovernancePolicy;
5
+ redactor?: Redactor;
6
+ telemetry?: TelemetrySink;
7
+ hooks?: {
8
+ beforeCall?(info: CallInfo): Promise<void | 'deny'>;
9
+ afterCall?(record: CallRecord): Promise<void>;
10
+ };
11
+ retry?: {
12
+ maxAttempts?: number;
13
+ baseDelayMs?: number;
14
+ maxDelayMs?: number;
15
+ };
16
+ limits?: {
17
+ maxConcurrent?: number;
18
+ minIntervalMs?: number;
19
+ };
20
+ }
21
+ export declare class AIHandler {
22
+ private opts;
23
+ private active;
24
+ private queue;
25
+ private lastStarted;
26
+ private sessionRedactor;
27
+ private policy;
28
+ constructor(opts: HandlerOptions);
29
+ chat(conn: Connection, req: ChatRequest): Promise<ChatResult>;
30
+ stream(conn: Connection, req: ChatRequest): AsyncIterable<StreamEvent>;
31
+ listModels(conn: Connection): Promise<ModelInfo[]>;
32
+ testConnection(conn: Connection): Promise<{
33
+ ok: boolean;
34
+ message: string;
35
+ }>;
36
+ private runProbe;
37
+ private resolveConnection;
38
+ private acquire;
39
+ private release;
40
+ private retryDelay;
41
+ private recordSuccess;
42
+ private recordFailure;
43
+ private record;
44
+ private redact;
45
+ private redactedError;
46
+ private redactedCause;
47
+ }
48
+ //# sourceMappingURL=handler.d.ts.map