@jxburros/ai-nugget 0.4.1 → 0.6.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 +132 -385
- package/UPGRADING.md +158 -0
- package/dist/adapters/engines/anthropic.d.ts +7 -1
- package/dist/adapters/engines/anthropic.js +64 -37
- package/dist/adapters/engines/base.d.ts +29 -2
- package/dist/adapters/engines/base.js +52 -8
- package/dist/adapters/engines/google.d.ts +7 -1
- package/dist/adapters/engines/google.js +73 -29
- package/dist/adapters/engines/ollama.d.ts +2 -1
- package/dist/adapters/engines/ollama.js +51 -15
- package/dist/adapters/engines/openaiChat.d.ts +2 -1
- package/dist/adapters/engines/openaiChat.js +60 -30
- package/dist/adapters/profiles.d.ts +21 -1
- package/dist/adapters/profiles.js +12 -2
- package/dist/agent/loop.d.ts +43 -1
- package/dist/agent/loop.js +116 -12
- package/dist/cjs/adapters/engines/anthropic.js +308 -0
- package/dist/cjs/adapters/engines/base.js +147 -0
- package/dist/cjs/adapters/engines/google.js +284 -0
- package/dist/cjs/adapters/engines/ollama.js +199 -0
- package/dist/cjs/adapters/engines/openaiChat.js +261 -0
- package/dist/cjs/adapters/index.js +22 -0
- package/dist/cjs/adapters/profiles.js +125 -0
- package/dist/cjs/agent/index.js +18 -0
- package/dist/cjs/agent/loop.js +372 -0
- package/dist/cjs/agent/tools.js +51 -0
- package/dist/cjs/connect.js +27 -0
- package/dist/cjs/errors.js +110 -0
- package/dist/cjs/handler.js +561 -0
- package/dist/cjs/index.js +27 -0
- package/dist/cjs/json.js +121 -0
- package/dist/cjs/keys.js +81 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/policy.js +42 -0
- package/dist/cjs/redact.js +78 -0
- package/dist/cjs/tokens.js +22 -0
- package/dist/cjs/transport.js +172 -0
- package/dist/cjs/types.js +6 -0
- package/dist/cjs/util.js +112 -0
- package/dist/errors.js +25 -1
- package/dist/handler.d.ts +61 -1
- package/dist/handler.js +239 -59
- package/dist/redact.d.ts +18 -0
- package/dist/redact.js +29 -1
- package/dist/transport.d.ts +3 -1
- package/dist/transport.js +21 -1
- package/dist/types.d.ts +96 -2
- package/dist/util.d.ts +15 -0
- package/dist/util.js +46 -0
- package/nugget/VERSION.txt +2 -2
- package/nugget/dist/adapters/engines/anthropic.d.ts +14 -0
- package/nugget/dist/adapters/engines/anthropic.d.ts.map +1 -0
- package/nugget/dist/adapters/engines/anthropic.js +305 -0
- package/nugget/dist/adapters/engines/anthropic.js.map +1 -0
- package/nugget/dist/adapters/engines/base.d.ts +50 -0
- package/nugget/dist/adapters/engines/base.d.ts.map +1 -0
- package/nugget/dist/adapters/engines/base.js +137 -0
- package/nugget/dist/adapters/engines/base.js.map +1 -0
- package/nugget/dist/adapters/engines/google.d.ts +24 -0
- package/nugget/dist/adapters/engines/google.d.ts.map +1 -0
- package/nugget/dist/adapters/engines/google.js +281 -0
- package/nugget/dist/adapters/engines/google.js.map +1 -0
- package/nugget/dist/adapters/engines/ollama.d.ts +11 -0
- package/nugget/dist/adapters/engines/ollama.d.ts.map +1 -0
- package/nugget/dist/adapters/engines/ollama.js +196 -0
- package/nugget/dist/adapters/engines/ollama.js.map +1 -0
- package/nugget/dist/adapters/engines/openaiChat.d.ts +16 -0
- package/nugget/dist/adapters/engines/openaiChat.d.ts.map +1 -0
- package/nugget/dist/adapters/engines/openaiChat.js +258 -0
- package/nugget/dist/adapters/engines/openaiChat.js.map +1 -0
- package/nugget/dist/adapters/index.d.ts +5 -0
- package/nugget/dist/adapters/index.d.ts.map +1 -0
- package/nugget/dist/adapters/index.js +17 -0
- package/nugget/dist/adapters/index.js.map +1 -0
- package/nugget/dist/adapters/profiles.d.ts +62 -0
- package/nugget/dist/adapters/profiles.d.ts.map +1 -0
- package/nugget/dist/adapters/profiles.js +121 -0
- package/nugget/dist/adapters/profiles.js.map +1 -0
- package/nugget/dist/agent/index.d.ts +3 -0
- package/nugget/dist/agent/index.d.ts.map +1 -0
- package/nugget/dist/agent/index.js +3 -0
- package/nugget/dist/agent/index.js.map +1 -0
- package/nugget/dist/agent/loop.d.ts +112 -0
- package/nugget/dist/agent/loop.d.ts.map +1 -0
- package/nugget/dist/agent/loop.js +370 -0
- package/nugget/dist/agent/loop.js.map +1 -0
- package/nugget/dist/agent/tools.d.ts +29 -0
- package/nugget/dist/agent/tools.d.ts.map +1 -0
- package/nugget/dist/agent/tools.js +48 -0
- package/nugget/dist/agent/tools.js.map +1 -0
- package/nugget/dist/cjs/adapters/engines/anthropic.js +308 -0
- package/nugget/dist/cjs/adapters/engines/base.js +147 -0
- package/nugget/dist/cjs/adapters/engines/google.js +284 -0
- package/nugget/dist/cjs/adapters/engines/ollama.js +199 -0
- package/nugget/dist/cjs/adapters/engines/openaiChat.js +261 -0
- package/nugget/dist/cjs/adapters/index.js +22 -0
- package/nugget/dist/cjs/adapters/profiles.js +125 -0
- package/nugget/dist/cjs/agent/index.js +18 -0
- package/nugget/dist/cjs/agent/loop.js +372 -0
- package/nugget/dist/cjs/agent/tools.js +51 -0
- package/nugget/dist/cjs/connect.js +27 -0
- package/nugget/dist/cjs/errors.js +110 -0
- package/nugget/dist/cjs/handler.js +561 -0
- package/nugget/dist/cjs/index.js +27 -0
- package/nugget/dist/cjs/json.js +121 -0
- package/nugget/dist/cjs/keys.js +81 -0
- package/nugget/dist/cjs/package.json +3 -0
- package/nugget/dist/cjs/policy.js +42 -0
- package/nugget/dist/cjs/redact.js +78 -0
- package/nugget/dist/cjs/tokens.js +22 -0
- package/nugget/dist/cjs/transport.js +172 -0
- package/nugget/dist/cjs/types.js +6 -0
- package/nugget/dist/cjs/util.js +112 -0
- package/nugget/dist/connect.d.ts +31 -0
- package/nugget/dist/connect.d.ts.map +1 -0
- package/nugget/dist/connect.js +25 -0
- package/nugget/dist/connect.js.map +1 -0
- package/nugget/dist/errors.d.ts +22 -0
- package/nugget/dist/errors.d.ts.map +1 -0
- package/nugget/dist/errors.js +104 -0
- package/nugget/dist/errors.js.map +1 -0
- package/nugget/dist/handler.d.ts +108 -0
- package/nugget/dist/handler.d.ts.map +1 -0
- package/nugget/dist/handler.js +557 -0
- package/nugget/dist/handler.js.map +1 -0
- package/nugget/dist/index.d.ts +12 -0
- package/nugget/dist/index.d.ts.map +1 -0
- package/nugget/dist/index.js +12 -0
- package/nugget/dist/index.js.map +1 -0
- package/nugget/dist/json.d.ts +7 -0
- package/nugget/dist/json.d.ts.map +1 -0
- package/nugget/dist/json.js +114 -0
- package/nugget/dist/json.js.map +1 -0
- package/nugget/dist/keys.d.ts +7 -0
- package/nugget/dist/keys.d.ts.map +1 -0
- package/nugget/dist/keys.js +75 -0
- package/nugget/dist/keys.js.map +1 -0
- package/nugget/dist/policy.d.ts +6 -0
- package/nugget/dist/policy.d.ts.map +1 -0
- package/nugget/dist/policy.js +37 -0
- package/nugget/dist/policy.js.map +1 -0
- package/nugget/dist/redact.d.ts +26 -0
- package/nugget/dist/redact.d.ts.map +1 -0
- package/nugget/dist/redact.js +74 -0
- package/nugget/dist/redact.js.map +1 -0
- package/nugget/dist/tokens.d.ts +5 -0
- package/nugget/dist/tokens.d.ts.map +1 -0
- package/nugget/dist/tokens.js +18 -0
- package/nugget/dist/tokens.js.map +1 -0
- package/nugget/dist/transport.d.ts +30 -0
- package/nugget/dist/transport.d.ts.map +1 -0
- package/nugget/dist/transport.js +165 -0
- package/nugget/dist/transport.js.map +1 -0
- package/nugget/dist/types.d.ts +285 -0
- package/nugget/dist/types.d.ts.map +1 -0
- package/nugget/dist/types.js +4 -0
- package/nugget/dist/types.js.map +1 -0
- package/nugget/dist/util.d.ts +24 -0
- package/nugget/dist/util.d.ts.map +1 -0
- package/nugget/dist/util.js +101 -0
- package/nugget/dist/util.js.map +1 -0
- package/nugget/src/adapters/engines/anthropic.ts +62 -37
- package/nugget/src/adapters/engines/base.ts +50 -7
- package/nugget/src/adapters/engines/google.ts +72 -29
- package/nugget/src/adapters/engines/ollama.ts +51 -17
- package/nugget/src/adapters/engines/openaiChat.ts +61 -32
- package/nugget/src/adapters/profiles.ts +53 -3
- package/nugget/src/agent/loop.ts +153 -13
- package/nugget/src/errors.ts +25 -1
- package/nugget/src/handler.ts +279 -57
- package/nugget/src/redact.ts +32 -1
- package/nugget/src/transport.ts +20 -1
- package/nugget/src/types.ts +96 -1
- package/nugget/src/util.ts +50 -0
- package/package.json +18 -5
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { KnownProvider } from './adapters/profiles.js';
|
|
2
|
+
export type { KnownProvider };
|
|
1
3
|
export type Role = 'system' | 'user' | 'assistant' | 'tool';
|
|
2
4
|
export interface ContentPart {
|
|
3
5
|
type: 'text' | 'image';
|
|
@@ -42,14 +44,39 @@ export interface ChatRequest {
|
|
|
42
44
|
stopSequences?: string[];
|
|
43
45
|
signal?: AbortSignal;
|
|
44
46
|
metadata?: Record<string, unknown>;
|
|
47
|
+
/**
|
|
48
|
+
* Provider-native request fields the nugget does not model as first-class
|
|
49
|
+
* options — an escape hatch so a caller can reach a capability without waiting
|
|
50
|
+
* for a library release. Merged into the outgoing provider request body:
|
|
51
|
+
* shallow at the top level, and one level deep into the provider's own nested
|
|
52
|
+
* option container (Ollama `options`, Google `generationConfig`). Examples:
|
|
53
|
+
* `{ options: { num_ctx: 8192 }, keep_alive: '30m' }` (Ollama),
|
|
54
|
+
* `{ reasoning_effort: 'high' }` (OpenAI), `{ thinking: { type: 'enabled' } }`
|
|
55
|
+
* (Anthropic), `{ safetySettings: [...] }` (Google). Values here win over the
|
|
56
|
+
* nugget's own fields on a key collision, so use with care.
|
|
57
|
+
*/
|
|
58
|
+
providerOptions?: Record<string, unknown>;
|
|
45
59
|
}
|
|
46
60
|
export interface Connection {
|
|
47
61
|
id: string;
|
|
48
|
-
|
|
62
|
+
/**
|
|
63
|
+
* A provider with a profile in the table, or any other string — an unknown
|
|
64
|
+
* key with a `baseUrl` resolves through the `openai-compat` escape hatch.
|
|
65
|
+
* The union is there for autocomplete and typo-catching; the `string & {}`
|
|
66
|
+
* arm keeps the escape hatch open.
|
|
67
|
+
*/
|
|
68
|
+
provider: KnownProvider | (string & {});
|
|
49
69
|
baseUrl?: string;
|
|
50
70
|
keyRef?: KeyRef;
|
|
51
71
|
timeoutMs?: number;
|
|
52
72
|
headers?: Record<string, string>;
|
|
73
|
+
/**
|
|
74
|
+
* Idle timeout for streaming calls: aborts the stream only if no bytes arrive
|
|
75
|
+
* for this many milliseconds, resetting on every chunk. Distinct from
|
|
76
|
+
* `timeoutMs`, which bounds the total call lifetime. Set this (and a generous
|
|
77
|
+
* `timeoutMs`) for long local generations that stream slowly but healthily.
|
|
78
|
+
*/
|
|
79
|
+
idleTimeoutMs?: number;
|
|
53
80
|
}
|
|
54
81
|
export type KeyRef = {
|
|
55
82
|
kind: 'none';
|
|
@@ -103,8 +130,27 @@ export interface ModelSource {
|
|
|
103
130
|
connectionId: string;
|
|
104
131
|
baseUrl?: string;
|
|
105
132
|
}
|
|
133
|
+
export interface EmbedRequest {
|
|
134
|
+
model: string;
|
|
135
|
+
/** One string, or a batch of strings embedded in a single call. */
|
|
136
|
+
input: string | string[];
|
|
137
|
+
signal?: AbortSignal;
|
|
138
|
+
metadata?: Record<string, unknown>;
|
|
139
|
+
/** Provider-native passthrough, same contract as {@link ChatRequest.providerOptions}. */
|
|
140
|
+
providerOptions?: Record<string, unknown>;
|
|
141
|
+
}
|
|
142
|
+
export interface EmbedResult {
|
|
143
|
+
/** One vector per input, in input order. */
|
|
144
|
+
embeddings: number[][];
|
|
145
|
+
model: string;
|
|
146
|
+
usage: Usage;
|
|
147
|
+
source: ModelSource;
|
|
148
|
+
raw?: unknown;
|
|
149
|
+
}
|
|
106
150
|
export declare function modelRef(source: ModelSource, model: string): string;
|
|
107
|
-
export type AIErrorKind = 'auth' | 'rate_limit' | 'timeout' | 'network' | 'server' | 'invalid_request' | 'invalid_response'
|
|
151
|
+
export type AIErrorKind = 'auth' | 'rate_limit' | 'timeout' | 'network' | 'server' | 'invalid_request' | 'invalid_response'
|
|
152
|
+
/** 404/410 — endpoint, deployment, or model not found (wrong baseUrl/model, or a misrouted edge). */
|
|
153
|
+
| 'not_found' | 'context_length' | 'canceled' | 'policy_blocked' | 'key_unavailable' | 'tool_error' | 'budget_exceeded';
|
|
108
154
|
export type StreamEvent = {
|
|
109
155
|
type: 'start';
|
|
110
156
|
callId: string;
|
|
@@ -113,6 +159,9 @@ export type StreamEvent = {
|
|
|
113
159
|
} | {
|
|
114
160
|
type: 'delta';
|
|
115
161
|
text: string;
|
|
162
|
+
} | {
|
|
163
|
+
type: 'reasoning';
|
|
164
|
+
text: string;
|
|
116
165
|
} | {
|
|
117
166
|
type: 'tool_call';
|
|
118
167
|
call: ToolCall;
|
|
@@ -141,6 +190,7 @@ export interface ProviderAdapter {
|
|
|
141
190
|
ok: boolean;
|
|
142
191
|
detail?: string;
|
|
143
192
|
}>;
|
|
193
|
+
embed?(conn: ResolvedConnection, req: EmbedRequest): Promise<EmbedResult>;
|
|
144
194
|
}
|
|
145
195
|
export interface ModelInfo {
|
|
146
196
|
id: string;
|
|
@@ -168,6 +218,15 @@ export interface CallInfo {
|
|
|
168
218
|
provider: string;
|
|
169
219
|
model: string;
|
|
170
220
|
metadata?: Record<string, unknown>;
|
|
221
|
+
/**
|
|
222
|
+
* The fully resolved connection for this call — base URL defaulted from the
|
|
223
|
+
* provider profile and auth headers applied. Present whenever `beforeCall`
|
|
224
|
+
* runs after resolution (chat/stream and probes), letting a hook validate the
|
|
225
|
+
* *effective* endpoint (e.g. a request-time SSRF/DNS-rebinding re-check on the
|
|
226
|
+
* resolved `baseUrl`) without duplicating profile logic. The resolved
|
|
227
|
+
* `apiKey` is intentionally not exposed here.
|
|
228
|
+
*/
|
|
229
|
+
resolved?: Omit<ResolvedConnection, 'apiKey'>;
|
|
171
230
|
}
|
|
172
231
|
export interface CallRecord {
|
|
173
232
|
callId: string;
|
|
@@ -187,5 +246,40 @@ export interface CallRecord {
|
|
|
187
246
|
metadata?: Record<string, unknown>;
|
|
188
247
|
promptChars: number;
|
|
189
248
|
responseChars: number;
|
|
249
|
+
/**
|
|
250
|
+
* Estimated cost of this call in USD, computed by the optional `pricing` hook
|
|
251
|
+
* passed to the handler. Undefined when no pricing hook is configured or the
|
|
252
|
+
* hook returns nothing for this provider/model.
|
|
253
|
+
*/
|
|
254
|
+
costUsd?: number;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Minimal [Standard Schema](https://standardschema.dev) validator surface. Any
|
|
258
|
+
* Zod / Valibot / ArkType schema (v1+) satisfies this via its `~standard`
|
|
259
|
+
* property, so `chatParsed` can validate model output against a schema the app
|
|
260
|
+
* already owns — with zero dependency added to this library.
|
|
261
|
+
*/
|
|
262
|
+
export interface StandardSchemaV1<Output = unknown> {
|
|
263
|
+
readonly '~standard': {
|
|
264
|
+
readonly version: 1;
|
|
265
|
+
readonly vendor: string;
|
|
266
|
+
readonly validate: (value: unknown) => StandardSchemaResult<Output> | Promise<StandardSchemaResult<Output>>;
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
export type StandardSchemaResult<Output> = {
|
|
270
|
+
readonly value: Output;
|
|
271
|
+
readonly issues?: undefined;
|
|
272
|
+
} | {
|
|
273
|
+
readonly issues: ReadonlyArray<{
|
|
274
|
+
readonly message: string;
|
|
275
|
+
readonly path?: ReadonlyArray<PropertyKey | {
|
|
276
|
+
readonly key: PropertyKey;
|
|
277
|
+
}>;
|
|
278
|
+
}>;
|
|
279
|
+
};
|
|
280
|
+
/** Output of {@link AIHandler.chatParsed}: the validated value plus the raw chat result. */
|
|
281
|
+
export interface ParsedResult<T> {
|
|
282
|
+
data: T;
|
|
283
|
+
result: ChatResult;
|
|
190
284
|
}
|
|
191
285
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/util.d.ts
CHANGED
|
@@ -5,5 +5,20 @@ export declare function asNumber(value: unknown): number | undefined;
|
|
|
5
5
|
export declare function promptChars(messages: ChatMessage[]): number;
|
|
6
6
|
export declare function textFromMessages(messages: ChatMessage[]): string;
|
|
7
7
|
export declare function globalEnv(): Record<string, string | undefined>;
|
|
8
|
+
/**
|
|
9
|
+
* Merges app-supplied {@link ChatRequest.providerOptions} into a provider
|
|
10
|
+
* request body: shallow at the top level, and one level deep for each key in
|
|
11
|
+
* `nestedKeys` where both sides are plain objects (Ollama `options`, Google
|
|
12
|
+
* `generationConfig`). Values in `providerOptions` win on collision.
|
|
13
|
+
*/
|
|
14
|
+
export declare function applyProviderOptions(body: Record<string, unknown>, providerOptions: Record<string, unknown> | undefined, nestedKeys?: readonly string[]): Record<string, unknown>;
|
|
15
|
+
/** Joins a base URL and path without producing a double slash, even if `base` ends with `/`. */
|
|
16
|
+
export declare function joinUrl(base: string, path: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Runs `fn` over `items` with at most `limit` in flight at once, preserving
|
|
19
|
+
* input order in the returned array. Used to probe many local models
|
|
20
|
+
* concurrently without opening an unbounded number of sockets.
|
|
21
|
+
*/
|
|
22
|
+
export declare function mapWithConcurrency<T, R>(items: readonly T[], limit: number, fn: (item: T, index: number) => Promise<R>): Promise<R[]>;
|
|
8
23
|
export declare function sleep(ms: number, signal?: AbortSignal): Promise<void>;
|
|
9
24
|
//# sourceMappingURL=util.d.ts.map
|
package/dist/util.js
CHANGED
|
@@ -25,6 +25,52 @@ export function globalEnv() {
|
|
|
25
25
|
const maybeProcess = globalThis;
|
|
26
26
|
return maybeProcess.process?.env ?? {};
|
|
27
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Merges app-supplied {@link ChatRequest.providerOptions} into a provider
|
|
30
|
+
* request body: shallow at the top level, and one level deep for each key in
|
|
31
|
+
* `nestedKeys` where both sides are plain objects (Ollama `options`, Google
|
|
32
|
+
* `generationConfig`). Values in `providerOptions` win on collision.
|
|
33
|
+
*/
|
|
34
|
+
export function applyProviderOptions(body, providerOptions, nestedKeys = []) {
|
|
35
|
+
if (!providerOptions)
|
|
36
|
+
return body;
|
|
37
|
+
const merged = { ...body };
|
|
38
|
+
for (const [key, value] of Object.entries(providerOptions)) {
|
|
39
|
+
const base = asRecord(merged[key]);
|
|
40
|
+
if (nestedKeys.includes(key) && base && asRecord(value)) {
|
|
41
|
+
merged[key] = { ...base, ...value };
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
merged[key] = value;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return merged;
|
|
48
|
+
}
|
|
49
|
+
/** Joins a base URL and path without producing a double slash, even if `base` ends with `/`. */
|
|
50
|
+
export function joinUrl(base, path) {
|
|
51
|
+
return `${base.replace(/\/+$/, '')}/${path.replace(/^\/+/, '')}`;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Runs `fn` over `items` with at most `limit` in flight at once, preserving
|
|
55
|
+
* input order in the returned array. Used to probe many local models
|
|
56
|
+
* concurrently without opening an unbounded number of sockets.
|
|
57
|
+
*/
|
|
58
|
+
export async function mapWithConcurrency(items, limit, fn) {
|
|
59
|
+
const results = new Array(items.length);
|
|
60
|
+
let next = 0;
|
|
61
|
+
const workerCount = Math.max(1, Math.min(limit, items.length));
|
|
62
|
+
const worker = async () => {
|
|
63
|
+
for (;;) {
|
|
64
|
+
const index = next;
|
|
65
|
+
next += 1;
|
|
66
|
+
if (index >= items.length)
|
|
67
|
+
return;
|
|
68
|
+
results[index] = await fn(items[index], index);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
await Promise.all(Array.from({ length: workerCount }, worker));
|
|
72
|
+
return results;
|
|
73
|
+
}
|
|
28
74
|
export function sleep(ms, signal) {
|
|
29
75
|
if (ms <= 0)
|
|
30
76
|
return Promise.resolve();
|
package/nugget/VERSION.txt
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
0.
|
|
2
|
-
|
|
1
|
+
0.6.0
|
|
2
|
+
762595605eef73dde3751687e21190d8281be3ade9d699d02620920f6c021de2
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ChatRequest, ChatResult, ModelInfo, ProviderAdapter, ResolvedConnection, StreamEvent } from '../../types.js';
|
|
2
|
+
export declare class AnthropicAdapter implements ProviderAdapter {
|
|
3
|
+
readonly provider: string;
|
|
4
|
+
constructor(provider: string);
|
|
5
|
+
chat(conn: ResolvedConnection, req: ChatRequest): Promise<ChatResult>;
|
|
6
|
+
stream(conn: ResolvedConnection, req: ChatRequest): AsyncIterable<StreamEvent>;
|
|
7
|
+
/**
|
|
8
|
+
* Lists models from Anthropic's `/v1/models` endpoint (auth + version headers
|
|
9
|
+
* already applied to `conn.headers`). The endpoint does not report a context
|
|
10
|
+
* window, so `contextWindow` is left undefined rather than guessed.
|
|
11
|
+
*/
|
|
12
|
+
listModels(conn: ResolvedConnection): Promise<ModelInfo[]>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/adapters/engines/anthropic.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAe,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,eAAe,EAAE,kBAAkB,EAAE,WAAW,EAAY,MAAM,gBAAgB,CAAC;AAMlJ,qBAAa,gBAAiB,YAAW,eAAe;IACtD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBACd,QAAQ,EAAE,MAAM;IAItB,IAAI,CAAC,IAAI,EAAE,kBAAkB,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IAUpE,MAAM,CAAC,IAAI,EAAE,kBAAkB,EAAE,GAAG,EAAE,WAAW,GAAG,aAAa,CAAC,WAAW,CAAC;IA2HrF;;;;OAIG;IACG,UAAU,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;CAajE"}
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { AIError } from '../../errors.js';
|
|
2
|
+
import { estimatedUsage } from '../../tokens.js';
|
|
3
|
+
import { fetchJson, postResponse, sseLines } from '../../transport.js';
|
|
4
|
+
import { applyProviderOptions, asNumber, asRecord, asString, joinUrl, textFromMessages } from '../../util.js';
|
|
5
|
+
import { DEFAULT_TIMEOUT_MS, parseArgs, randomId, safeParse, streamAnomaly, streamError, streamTimeout } from './base.js';
|
|
6
|
+
const JSON_MODE_TOOL = 'json_output';
|
|
7
|
+
export class AnthropicAdapter {
|
|
8
|
+
provider;
|
|
9
|
+
constructor(provider) {
|
|
10
|
+
this.provider = provider;
|
|
11
|
+
}
|
|
12
|
+
async chat(conn, req) {
|
|
13
|
+
let result;
|
|
14
|
+
for await (const event of this.stream(conn, req)) {
|
|
15
|
+
if (event.type === 'done')
|
|
16
|
+
result = event.result;
|
|
17
|
+
if (event.type === 'error')
|
|
18
|
+
throw event.error;
|
|
19
|
+
}
|
|
20
|
+
if (!result)
|
|
21
|
+
throw new AIError('Anthropic stream ended without a result', { kind: 'invalid_response', provider: conn.provider });
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
async *stream(conn, req) {
|
|
25
|
+
const started = Date.now();
|
|
26
|
+
const jsonMode = req.responseFormat?.type === 'json' && !req.tools?.length;
|
|
27
|
+
let firstTokenMs = null;
|
|
28
|
+
let text = '';
|
|
29
|
+
let inputTokens;
|
|
30
|
+
let outputTokens;
|
|
31
|
+
let stopReason;
|
|
32
|
+
let sawTerminal = false;
|
|
33
|
+
const emittedTools = [];
|
|
34
|
+
// Partial tool_use blocks keyed by content-block index (input_json_delta accumulation).
|
|
35
|
+
const blocks = new Map();
|
|
36
|
+
const timeout = streamTimeout(conn, req.signal);
|
|
37
|
+
yield { type: 'start', callId: '', provider: conn.provider, model: req.model };
|
|
38
|
+
// Anthropic JSON mode is implemented as a forced `json_output` tool, which
|
|
39
|
+
// cannot coexist with the caller's own tools — same silent-downgrade shape
|
|
40
|
+
// as Gemini, so it gets the same signal rather than quietly dropping.
|
|
41
|
+
if (req.responseFormat?.type === 'json' && req.tools?.length) {
|
|
42
|
+
yield {
|
|
43
|
+
type: 'context',
|
|
44
|
+
kind: 'json_mode_downgraded',
|
|
45
|
+
data: { reason: 'Anthropic JSON mode uses a forced tool and cannot be combined with caller tools; the request was sent without JSON mode', provider: conn.provider },
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const res = await postResponse(`${conn.baseUrl}/v1/messages`, body(req, jsonMode), conn.headers, timeout.signal, conn.provider);
|
|
50
|
+
const contentType = res.headers.get('content-type') ?? '';
|
|
51
|
+
if (!contentType.includes('text/event-stream')) {
|
|
52
|
+
const data = await res.json();
|
|
53
|
+
const parsed = parseResponse(data);
|
|
54
|
+
inputTokens = parsed.inputTokens;
|
|
55
|
+
outputTokens = parsed.outputTokens;
|
|
56
|
+
stopReason = parsed.stopReason;
|
|
57
|
+
sawTerminal = true;
|
|
58
|
+
if (jsonMode) {
|
|
59
|
+
text = jsonTextFrom(parsed.toolCalls, parsed.text);
|
|
60
|
+
if (text)
|
|
61
|
+
yield { type: 'delta', text };
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
text = parsed.text;
|
|
65
|
+
if (text)
|
|
66
|
+
yield { type: 'delta', text };
|
|
67
|
+
for (const call of parsed.toolCalls) {
|
|
68
|
+
emittedTools.push(call);
|
|
69
|
+
yield { type: 'tool_call', call };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
for await (const line of sseLines(res)) {
|
|
75
|
+
timeout.bump();
|
|
76
|
+
const record = asRecord(safeParse(line));
|
|
77
|
+
if (!record)
|
|
78
|
+
continue;
|
|
79
|
+
const type = asString(record.type);
|
|
80
|
+
if (type === 'message_start') {
|
|
81
|
+
const usage = asRecord(asRecord(record.message)?.usage);
|
|
82
|
+
inputTokens = asNumber(usage?.input_tokens) ?? inputTokens;
|
|
83
|
+
outputTokens = asNumber(usage?.output_tokens) ?? outputTokens;
|
|
84
|
+
}
|
|
85
|
+
else if (type === 'content_block_start') {
|
|
86
|
+
const index = asNumber(record.index) ?? 0;
|
|
87
|
+
const block = asRecord(record.content_block);
|
|
88
|
+
if (block?.type === 'tool_use') {
|
|
89
|
+
blocks.set(index, { id: asString(block.id) ?? randomId(), name: asString(block.name) ?? 'unknown', raw: '' });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else if (type === 'content_block_delta') {
|
|
93
|
+
const index = asNumber(record.index) ?? 0;
|
|
94
|
+
const delta = asRecord(record.delta);
|
|
95
|
+
if (delta?.type === 'text_delta') {
|
|
96
|
+
const piece = asString(delta.text) ?? '';
|
|
97
|
+
if (piece) {
|
|
98
|
+
if (firstTokenMs === null)
|
|
99
|
+
firstTokenMs = Date.now() - started;
|
|
100
|
+
text += piece;
|
|
101
|
+
yield { type: 'delta', text: piece };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else if (delta?.type === 'thinking_delta') {
|
|
105
|
+
// Extended-thinking tokens ride the reasoning channel, kept out of `text`.
|
|
106
|
+
const piece = asString(delta.thinking) ?? '';
|
|
107
|
+
if (piece)
|
|
108
|
+
yield { type: 'reasoning', text: piece };
|
|
109
|
+
}
|
|
110
|
+
else if (delta?.type === 'input_json_delta') {
|
|
111
|
+
const partial = blocks.get(index);
|
|
112
|
+
if (partial)
|
|
113
|
+
partial.raw += asString(delta.partial_json) ?? '';
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else if (type === 'content_block_stop') {
|
|
117
|
+
const index = asNumber(record.index) ?? 0;
|
|
118
|
+
const partial = blocks.get(index);
|
|
119
|
+
if (partial) {
|
|
120
|
+
const call = { id: partial.id, name: partial.name, raw: partial.raw, arguments: parseArgs(partial.raw) };
|
|
121
|
+
blocks.delete(index);
|
|
122
|
+
if (jsonMode && call.name === JSON_MODE_TOOL) {
|
|
123
|
+
text = jsonTextFrom([call], text);
|
|
124
|
+
if (firstTokenMs === null)
|
|
125
|
+
firstTokenMs = Date.now() - started;
|
|
126
|
+
yield { type: 'delta', text };
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
emittedTools.push(call);
|
|
130
|
+
yield { type: 'tool_call', call };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else if (type === 'message_stop') {
|
|
135
|
+
sawTerminal = true;
|
|
136
|
+
}
|
|
137
|
+
else if (type === 'message_delta') {
|
|
138
|
+
const delta = asRecord(record.delta);
|
|
139
|
+
if (asString(delta?.stop_reason))
|
|
140
|
+
sawTerminal = true;
|
|
141
|
+
stopReason = asString(delta?.stop_reason) ?? stopReason;
|
|
142
|
+
const usage = asRecord(record.usage);
|
|
143
|
+
outputTokens = asNumber(usage?.output_tokens) ?? outputTokens;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (!sawTerminal)
|
|
148
|
+
yield streamAnomaly('stream ended without a stop_reason or message_stop');
|
|
149
|
+
const hasTools = emittedTools.length > 0;
|
|
150
|
+
yield { type: 'done', result: {
|
|
151
|
+
text,
|
|
152
|
+
toolCalls: hasTools ? emittedTools : undefined,
|
|
153
|
+
finishReason: mapStop(stopReason, hasTools),
|
|
154
|
+
usage: inputTokens !== undefined || outputTokens !== undefined ? { inputTokens, outputTokens, estimated: false } : estimatedUsage(textFromMessages(req.messages), text),
|
|
155
|
+
timing: { firstTokenMs, totalMs: Date.now() - started },
|
|
156
|
+
model: req.model,
|
|
157
|
+
source: { provider: conn.provider, connectionId: conn.id, baseUrl: conn.baseUrl },
|
|
158
|
+
} };
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
throw streamError(error, timeout, conn.provider);
|
|
162
|
+
}
|
|
163
|
+
finally {
|
|
164
|
+
timeout.done();
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Lists models from Anthropic's `/v1/models` endpoint (auth + version headers
|
|
169
|
+
* already applied to `conn.headers`). The endpoint does not report a context
|
|
170
|
+
* window, so `contextWindow` is left undefined rather than guessed.
|
|
171
|
+
*/
|
|
172
|
+
async listModels(conn) {
|
|
173
|
+
const { data } = await fetchJson(joinUrl(conn.baseUrl, '/v1/models'), {
|
|
174
|
+
method: 'GET',
|
|
175
|
+
headers: conn.headers,
|
|
176
|
+
timeoutMs: Math.min(conn.timeoutMs ?? DEFAULT_TIMEOUT_MS, 15_000),
|
|
177
|
+
provider: conn.provider,
|
|
178
|
+
});
|
|
179
|
+
const rows = Array.isArray(asRecord(data)?.data) ? asRecord(data).data : [];
|
|
180
|
+
return rows
|
|
181
|
+
.map((row) => asString(asRecord(row)?.id))
|
|
182
|
+
.filter((id) => Boolean(id))
|
|
183
|
+
.map((id) => ({ id, source: { provider: conn.provider, connectionId: conn.id, baseUrl: conn.baseUrl } }));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function body(req, jsonMode) {
|
|
187
|
+
const system = req.messages.filter((m) => m.role === 'system').map((m) => textContent(m.content)).join('\n\n') || undefined;
|
|
188
|
+
const base = {
|
|
189
|
+
model: req.model,
|
|
190
|
+
max_tokens: req.maxTokens ?? 4096,
|
|
191
|
+
temperature: req.temperature,
|
|
192
|
+
top_p: req.topP,
|
|
193
|
+
stop_sequences: req.stopSequences,
|
|
194
|
+
system,
|
|
195
|
+
messages: toAnthropicMessages(req.messages.filter((m) => m.role !== 'system')),
|
|
196
|
+
stream: true,
|
|
197
|
+
};
|
|
198
|
+
if (jsonMode) {
|
|
199
|
+
// Forced-tool JSON mode: Anthropic has no response_format, so we make the
|
|
200
|
+
// model answer through a single required tool whose input is the JSON we want.
|
|
201
|
+
base.tools = [{ name: JSON_MODE_TOOL, description: 'Return the answer as a JSON object.', input_schema: schemaFor(req) }];
|
|
202
|
+
base.tool_choice = { type: 'tool', name: JSON_MODE_TOOL };
|
|
203
|
+
}
|
|
204
|
+
else if (req.tools?.length) {
|
|
205
|
+
base.tools = req.tools.map((tool) => ({ name: tool.name, description: tool.description, input_schema: tool.parameters }));
|
|
206
|
+
if (typeof req.toolChoice === 'object')
|
|
207
|
+
base.tool_choice = { type: 'tool', name: req.toolChoice.name };
|
|
208
|
+
else if (req.toolChoice === 'auto')
|
|
209
|
+
base.tool_choice = { type: 'auto' };
|
|
210
|
+
else if (req.toolChoice === 'none')
|
|
211
|
+
base.tool_choice = { type: 'none' };
|
|
212
|
+
}
|
|
213
|
+
// providerOptions carries Anthropic-native fields (`thinking`, `metadata`,
|
|
214
|
+
// top-level `cache_control` extras, `service_tier`, …) without a release.
|
|
215
|
+
return applyProviderOptions(base, req.providerOptions);
|
|
216
|
+
}
|
|
217
|
+
function toAnthropicMessages(messages) {
|
|
218
|
+
const out = [];
|
|
219
|
+
for (let index = 0; index < messages.length; index += 1) {
|
|
220
|
+
const message = messages[index];
|
|
221
|
+
if (message.role !== 'tool') {
|
|
222
|
+
out.push(toAnthropicMessage(message));
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
const content = [];
|
|
226
|
+
while (index < messages.length && messages[index]?.role === 'tool') {
|
|
227
|
+
const toolMessage = messages[index];
|
|
228
|
+
content.push({ type: 'tool_result', tool_use_id: toolMessage.toolCallId ?? '', content: textContent(toolMessage.content) });
|
|
229
|
+
index += 1;
|
|
230
|
+
}
|
|
231
|
+
index -= 1;
|
|
232
|
+
out.push({ role: 'user', content });
|
|
233
|
+
}
|
|
234
|
+
return out;
|
|
235
|
+
}
|
|
236
|
+
function toAnthropicMessage(m) {
|
|
237
|
+
// Tool-role messages are handled by toAnthropicMessages' batching loop and
|
|
238
|
+
// never reach here, so no tool branch is needed.
|
|
239
|
+
// assistant turns that carried tool calls replay them as tool_use blocks,
|
|
240
|
+
// preserving any text/image content parts that accompanied the calls.
|
|
241
|
+
if (m.role === 'assistant' && m.toolCalls?.length) {
|
|
242
|
+
const content = [...contentBlocks(m.content)];
|
|
243
|
+
for (const call of m.toolCalls)
|
|
244
|
+
content.push({ type: 'tool_use', id: call.id, name: call.name, input: call.arguments ?? {} });
|
|
245
|
+
return { role: 'assistant', content };
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
role: m.role === 'assistant' ? 'assistant' : 'user',
|
|
249
|
+
content: typeof m.content === 'string' ? m.content : contentBlocks(m.content),
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/** Maps text/image content — a string or a ContentPart[] — onto Anthropic content blocks. */
|
|
253
|
+
function contentBlocks(content) {
|
|
254
|
+
if (typeof content === 'string')
|
|
255
|
+
return content ? [{ type: 'text', text: content }] : [];
|
|
256
|
+
return content.map((part) => part.type === 'image'
|
|
257
|
+
? { type: 'image', source: { type: 'base64', media_type: part.mimeType ?? 'image/png', data: part.imageBase64 ?? '' } }
|
|
258
|
+
: { type: 'text', text: part.text ?? '' });
|
|
259
|
+
}
|
|
260
|
+
function textContent(content) {
|
|
261
|
+
if (typeof content === 'string')
|
|
262
|
+
return content;
|
|
263
|
+
if (!content)
|
|
264
|
+
return '';
|
|
265
|
+
return content.filter((part) => part.type === 'text').map((part) => part.text ?? '').join('\n');
|
|
266
|
+
}
|
|
267
|
+
function parseResponse(data) {
|
|
268
|
+
const record = asRecord(data);
|
|
269
|
+
const content = Array.isArray(record?.content) ? record.content : [];
|
|
270
|
+
let text = '';
|
|
271
|
+
const toolCalls = [];
|
|
272
|
+
for (const blockValue of content) {
|
|
273
|
+
const block = asRecord(blockValue);
|
|
274
|
+
if (block?.type === 'text')
|
|
275
|
+
text += asString(block.text) ?? '';
|
|
276
|
+
if (block?.type === 'tool_use') {
|
|
277
|
+
toolCalls.push({
|
|
278
|
+
id: asString(block.id) ?? randomId(),
|
|
279
|
+
name: asString(block.name) ?? 'unknown',
|
|
280
|
+
arguments: block.input ?? {},
|
|
281
|
+
raw: JSON.stringify(block.input ?? {}),
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const usage = asRecord(record?.usage);
|
|
286
|
+
return { text, inputTokens: asNumber(usage?.input_tokens), outputTokens: asNumber(usage?.output_tokens), stopReason: asString(record?.stop_reason), toolCalls };
|
|
287
|
+
}
|
|
288
|
+
function schemaFor(req) {
|
|
289
|
+
const schema = req.responseFormat?.type === 'json' ? req.responseFormat.schema : undefined;
|
|
290
|
+
return schema ?? { type: 'object' };
|
|
291
|
+
}
|
|
292
|
+
function jsonTextFrom(toolCalls, fallback) {
|
|
293
|
+
const json = toolCalls.find((call) => call.name === JSON_MODE_TOOL) ?? toolCalls[0];
|
|
294
|
+
if (json)
|
|
295
|
+
return json.raw && json.raw.trim() ? json.raw : JSON.stringify(json.arguments ?? {});
|
|
296
|
+
return fallback;
|
|
297
|
+
}
|
|
298
|
+
function mapStop(stop, hasTools) {
|
|
299
|
+
if (stop === 'tool_use' && hasTools)
|
|
300
|
+
return 'tool';
|
|
301
|
+
if (stop === 'max_tokens')
|
|
302
|
+
return 'length';
|
|
303
|
+
return 'stop';
|
|
304
|
+
}
|
|
305
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/adapters/engines/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEvE,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC9G,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1H,MAAM,cAAc,GAAG,aAAa,CAAC;AAErC,MAAM,OAAO,gBAAgB;IAClB,QAAQ,CAAS;IAC1B,YAAY,QAAgB;QAC1B,IAAI,CAAC,QAAQ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,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,cAAc,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;IACpF,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;IAC/F,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,OAAO,CAAC,IAAwB,EAAE,QAAiB;IAC1D,IAAI,IAAI,KAAK,UAAU,IAAI,QAAQ;QAAE,OAAO,MAAM,CAAC;IACnD,IAAI,IAAI,KAAK,YAAY;QAAE,OAAO,QAAQ,CAAC;IAC3C,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AIError } from '../../errors.js';
|
|
2
|
+
import { withTimeout } from '../../transport.js';
|
|
3
|
+
import type { ModelInfo, ResolvedConnection } from '../../types.js';
|
|
4
|
+
import type { ProviderProfile } from '../profiles.js';
|
|
5
|
+
export declare const DEFAULT_TIMEOUT_MS = 120000;
|
|
6
|
+
/**
|
|
7
|
+
* Maps a raw streaming failure onto a typed {@link AIError}. A fired timeout is
|
|
8
|
+
* reported as `timeout` regardless of how the underlying `fetch` surfaced the
|
|
9
|
+
* abort; anything else is normalized through {@link fromUnknown} (which passes
|
|
10
|
+
* an existing {@link AIError} through untouched, preserving retryability).
|
|
11
|
+
*/
|
|
12
|
+
export declare function streamError(error: unknown, timeout: {
|
|
13
|
+
timedOut(): boolean;
|
|
14
|
+
}, provider: string): AIError;
|
|
15
|
+
/**
|
|
16
|
+
* Create a timeout/abort scope covering the full stream lifetime, plus an
|
|
17
|
+
* optional idle timeout (`conn.idleTimeoutMs`) that the engine rearms via
|
|
18
|
+
* `bump()` on each received chunk.
|
|
19
|
+
*/
|
|
20
|
+
export declare function streamTimeout(conn: ResolvedConnection, signal?: AbortSignal): ReturnType<typeof withTimeout>;
|
|
21
|
+
export declare function listOpenModels(conn: ResolvedConnection, profile: ProviderProfile): Promise<ModelInfo[]>;
|
|
22
|
+
export declare function health(conn: ResolvedConnection, profile: ProviderProfile): Promise<{
|
|
23
|
+
ok: boolean;
|
|
24
|
+
detail?: string;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Coerce a provider's tool-call `arguments` into an object. Providers disagree
|
|
28
|
+
* on the shape: OpenAI/Anthropic stream a JSON *string*, Google and Ollama send
|
|
29
|
+
* a native object — but Ollama-compatible backends (llama.cpp and friends)
|
|
30
|
+
* sometimes send a string too. Malformed JSON degrades to `{}` so a single bad
|
|
31
|
+
* tool call surfaces as an argument-validation error rather than a stream crash.
|
|
32
|
+
*/
|
|
33
|
+
export declare function parseArgs(raw: unknown): unknown;
|
|
34
|
+
/** JSON.parse that returns undefined instead of throwing — for per-line stream frames. */
|
|
35
|
+
export declare function safeParse(line: string): unknown;
|
|
36
|
+
/** Stable-enough id for a tool call a provider didn't give one for. */
|
|
37
|
+
export declare function randomId(): string;
|
|
38
|
+
/**
|
|
39
|
+
* A stream that ended without the provider's terminal marker (an OpenAI
|
|
40
|
+
* `finish_reason`, an Anthropic `message_delta.stop_reason`, a Google
|
|
41
|
+
* `finishReason`, an Ollama `done`) was almost certainly truncated. Every
|
|
42
|
+
* engine yields this so a dropped connection is diagnosable identically
|
|
43
|
+
* regardless of provider.
|
|
44
|
+
*/
|
|
45
|
+
export declare function streamAnomaly(reason?: string): {
|
|
46
|
+
type: 'context';
|
|
47
|
+
kind: string;
|
|
48
|
+
data: unknown;
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/adapters/engines/base.ts"],"names":[],"mappings":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