@venturekit-pro/ai 0.0.48 → 0.0.50
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 +192 -0
- package/dist/agent-loop/index.d.ts +9 -0
- package/dist/agent-loop/index.d.ts.map +1 -0
- package/dist/agent-loop/index.js +7 -0
- package/dist/agent-loop/index.js.map +1 -0
- package/dist/agent-loop/registry.d.ts +85 -0
- package/dist/agent-loop/registry.d.ts.map +1 -0
- package/dist/agent-loop/registry.js +100 -0
- package/dist/agent-loop/registry.js.map +1 -0
- package/dist/agent-loop/run-agent.d.ts +37 -0
- package/dist/agent-loop/run-agent.d.ts.map +1 -0
- package/dist/agent-loop/run-agent.js +405 -0
- package/dist/agent-loop/run-agent.js.map +1 -0
- package/dist/agent-loop/tools.d.ts +10 -0
- package/dist/agent-loop/tools.d.ts.map +1 -0
- package/dist/agent-loop/tools.js +28 -0
- package/dist/agent-loop/tools.js.map +1 -0
- package/dist/agent-loop/types.d.ts +175 -0
- package/dist/agent-loop/types.d.ts.map +1 -0
- package/dist/agent-loop/types.js +8 -0
- package/dist/agent-loop/types.js.map +1 -0
- package/dist/chat/types.d.ts +4 -2
- package/dist/chat/types.d.ts.map +1 -1
- package/dist/cost/types.d.ts +15 -0
- package/dist/cost/types.d.ts.map +1 -1
- package/dist/cost-ledger/migrations/vk_ai_cost_0004_llm_gateway.sql +69 -0
- package/dist/cost-ledger/migrations/vk_ai_cost_0005_harness.sql +99 -0
- package/dist/cost-ledger/migrations/vk_ai_cost_0006_cache_write_prices.sql +17 -0
- package/dist/cost-ledger/migrations/vk_ai_cost_0007_harness_fan_out.sql +47 -0
- package/dist/gateway/errors.d.ts +24 -0
- package/dist/gateway/errors.d.ts.map +1 -0
- package/dist/gateway/errors.js +29 -0
- package/dist/gateway/errors.js.map +1 -0
- package/dist/gateway/gateway.d.ts +27 -0
- package/dist/gateway/gateway.d.ts.map +1 -0
- package/dist/gateway/gateway.js +503 -0
- package/dist/gateway/gateway.js.map +1 -0
- package/dist/gateway/index.d.ts +13 -0
- package/dist/gateway/index.d.ts.map +1 -0
- package/dist/gateway/index.js +10 -0
- package/dist/gateway/index.js.map +1 -0
- package/dist/gateway/policies.d.ts +32 -0
- package/dist/gateway/policies.d.ts.map +1 -0
- package/dist/gateway/policies.js +45 -0
- package/dist/gateway/policies.js.map +1 -0
- package/dist/gateway/postgres.d.ts +55 -0
- package/dist/gateway/postgres.d.ts.map +1 -0
- package/dist/gateway/postgres.js +127 -0
- package/dist/gateway/postgres.js.map +1 -0
- package/dist/gateway/pricing.d.ts +11 -0
- package/dist/gateway/pricing.d.ts.map +1 -0
- package/dist/gateway/pricing.js +47 -0
- package/dist/gateway/pricing.js.map +1 -0
- package/dist/gateway/routing.d.ts +25 -0
- package/dist/gateway/routing.d.ts.map +1 -0
- package/dist/gateway/routing.js +23 -0
- package/dist/gateway/routing.js.map +1 -0
- package/dist/gateway/types.d.ts +225 -0
- package/dist/gateway/types.d.ts.map +1 -0
- package/dist/gateway/types.js +7 -0
- package/dist/gateway/types.js.map +1 -0
- package/dist/generate/anthropic.d.ts +38 -0
- package/dist/generate/anthropic.d.ts.map +1 -0
- package/dist/generate/anthropic.js +446 -0
- package/dist/generate/anthropic.js.map +1 -0
- package/dist/generate/client.d.ts +9 -0
- package/dist/generate/client.d.ts.map +1 -0
- package/dist/generate/client.js +44 -0
- package/dist/generate/client.js.map +1 -0
- package/dist/generate/google.d.ts +39 -0
- package/dist/generate/google.d.ts.map +1 -0
- package/dist/generate/google.js +372 -0
- package/dist/generate/google.js.map +1 -0
- package/dist/generate/http.d.ts +48 -0
- package/dist/generate/http.d.ts.map +1 -0
- package/dist/generate/http.js +180 -0
- package/dist/generate/http.js.map +1 -0
- package/dist/generate/index.d.ts +13 -0
- package/dist/generate/index.d.ts.map +1 -0
- package/dist/generate/index.js +12 -0
- package/dist/generate/index.js.map +1 -0
- package/dist/generate/openai.d.ts +29 -0
- package/dist/generate/openai.d.ts.map +1 -0
- package/dist/generate/openai.js +314 -0
- package/dist/generate/openai.js.map +1 -0
- package/dist/generate/perplexity.d.ts +27 -0
- package/dist/generate/perplexity.d.ts.map +1 -0
- package/dist/generate/perplexity.js +208 -0
- package/dist/generate/perplexity.js.map +1 -0
- package/dist/generate/types.d.ts +253 -0
- package/dist/generate/types.d.ts.map +1 -0
- package/dist/generate/types.js +19 -0
- package/dist/generate/types.js.map +1 -0
- package/dist/harness/define.d.ts +15 -0
- package/dist/harness/define.d.ts.map +1 -0
- package/dist/harness/define.js +38 -0
- package/dist/harness/define.js.map +1 -0
- package/dist/harness/harness.d.ts +29 -0
- package/dist/harness/harness.d.ts.map +1 -0
- package/dist/harness/harness.js +1287 -0
- package/dist/harness/harness.js.map +1 -0
- package/dist/harness/index.d.ts +14 -0
- package/dist/harness/index.d.ts.map +1 -0
- package/dist/harness/index.js +10 -0
- package/dist/harness/index.js.map +1 -0
- package/dist/harness/memory-store.d.ts +8 -0
- package/dist/harness/memory-store.d.ts.map +1 -0
- package/dist/harness/memory-store.js +270 -0
- package/dist/harness/memory-store.js.map +1 -0
- package/dist/harness/postgres-store.d.ts +12 -0
- package/dist/harness/postgres-store.d.ts.map +1 -0
- package/dist/harness/postgres-store.js +368 -0
- package/dist/harness/postgres-store.js.map +1 -0
- package/dist/harness/scheduler.d.ts +12 -0
- package/dist/harness/scheduler.d.ts.map +1 -0
- package/dist/harness/scheduler.js +23 -0
- package/dist/harness/scheduler.js.map +1 -0
- package/dist/harness/store.d.ts +172 -0
- package/dist/harness/store.d.ts.map +1 -0
- package/dist/harness/store.js +21 -0
- package/dist/harness/store.js.map +1 -0
- package/dist/harness/types.d.ts +312 -0
- package/dist/harness/types.d.ts.map +1 -0
- package/dist/harness/types.js +11 -0
- package/dist/harness/types.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/model-catalog/crud.d.ts.map +1 -1
- package/dist/model-catalog/crud.js +33 -2
- package/dist/model-catalog/crud.js.map +1 -1
- package/dist/model-catalog/types.d.ts +20 -0
- package/dist/model-catalog/types.d.ts.map +1 -1
- package/dist/tracing/index.d.ts +68 -0
- package/dist/tracing/index.d.ts.map +1 -0
- package/dist/tracing/index.js +72 -0
- package/dist/tracing/index.js.map +1 -0
- package/dist/tracing/recording.d.ts +23 -0
- package/dist/tracing/recording.d.ts.map +1 -0
- package/dist/tracing/recording.js +49 -0
- package/dist/tracing/recording.js.map +1 -0
- package/package.json +7 -4
- package/src/cost-ledger/migrations/vk_ai_cost_0004_llm_gateway.sql +69 -0
- package/src/cost-ledger/migrations/vk_ai_cost_0005_harness.sql +99 -0
- package/src/cost-ledger/migrations/vk_ai_cost_0006_cache_write_prices.sql +17 -0
- package/src/cost-ledger/migrations/vk_ai_cost_0007_harness_fan_out.sql +47 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `generate` — the provider-neutral model call behind the LLM gateway and
|
|
3
|
+
* the agent loop.
|
|
4
|
+
*
|
|
5
|
+
* Wider than `chat/` (which stays the single-shot text API): function
|
|
6
|
+
* tools + tool choice, model-native web search with citations, native
|
|
7
|
+
* structured output, file / image inputs, prompt-cache hints and
|
|
8
|
+
* cached / cache-write usage, search counts for pricing, provider-state
|
|
9
|
+
* replay between turns, streaming, and cancellation through an
|
|
10
|
+
* `AbortSignal`.
|
|
11
|
+
*
|
|
12
|
+
* Adapters are `fetch()`-based like the chat adapters, and throw
|
|
13
|
+
* `Error("[ai/generate/<provider>] <status> <statusText>: <body>")` on an
|
|
14
|
+
* HTTP failure so `fallback/isRetryableError` (and callers that classify
|
|
15
|
+
* vendor errors) read the status the same way.
|
|
16
|
+
*/
|
|
17
|
+
import type { ChatFinishReason, ChatProvider } from '../chat/types.js';
|
|
18
|
+
/** A JSON Schema object (tool inputs, structured output). */
|
|
19
|
+
export type JsonSchema = Record<string, unknown>;
|
|
20
|
+
export interface TextPart {
|
|
21
|
+
type: 'text';
|
|
22
|
+
text: string;
|
|
23
|
+
}
|
|
24
|
+
/** A document the model reads natively (PDF, plain text). `data` is base64. */
|
|
25
|
+
export interface FilePart {
|
|
26
|
+
type: 'file';
|
|
27
|
+
mediaType: string;
|
|
28
|
+
data: string;
|
|
29
|
+
filename?: string;
|
|
30
|
+
}
|
|
31
|
+
/** An image input. `data` is base64. */
|
|
32
|
+
export interface ImagePart {
|
|
33
|
+
type: 'image';
|
|
34
|
+
mediaType: string;
|
|
35
|
+
data: string;
|
|
36
|
+
}
|
|
37
|
+
export type ContentPart = TextPart | FilePart | ImagePart;
|
|
38
|
+
/** A function-tool call the model asked for. */
|
|
39
|
+
export interface ToolCall {
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
arguments: Record<string, unknown>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Opaque, provider-specific assistant content replayed verbatim on the
|
|
46
|
+
* next turn (Anthropic server-tool blocks, Gemini thought signatures).
|
|
47
|
+
* Ignored by other providers.
|
|
48
|
+
*/
|
|
49
|
+
export interface ProviderState {
|
|
50
|
+
provider: ChatProvider;
|
|
51
|
+
data: unknown;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Prompt-cache breakpoint: `cache: true` asks the provider to cache the
|
|
55
|
+
* prompt up to and including this message (tools and system first). Put
|
|
56
|
+
* it on the end of the stable prefix — kernel, brand profile, playbook.
|
|
57
|
+
* Anthropic gets a `cache_control` block (at most 4 per call: the system
|
|
58
|
+
* one plus the latest three); OpenAI and Gemini cache prefixes on their
|
|
59
|
+
* own, so the marker is a no-op there.
|
|
60
|
+
*/
|
|
61
|
+
interface Cacheable {
|
|
62
|
+
cache?: boolean;
|
|
63
|
+
}
|
|
64
|
+
export interface SystemMessage extends Cacheable {
|
|
65
|
+
role: 'system';
|
|
66
|
+
content: string;
|
|
67
|
+
}
|
|
68
|
+
export interface UserMessage extends Cacheable {
|
|
69
|
+
role: 'user';
|
|
70
|
+
content: string | ContentPart[];
|
|
71
|
+
}
|
|
72
|
+
export interface AssistantMessage extends Cacheable {
|
|
73
|
+
role: 'assistant';
|
|
74
|
+
content: string;
|
|
75
|
+
toolCalls?: ToolCall[];
|
|
76
|
+
providerState?: ProviderState;
|
|
77
|
+
}
|
|
78
|
+
/** The result of one function-tool call, answered back to the model. */
|
|
79
|
+
export interface ToolMessage extends Cacheable {
|
|
80
|
+
role: 'tool';
|
|
81
|
+
toolCallId: string;
|
|
82
|
+
name: string;
|
|
83
|
+
content: string;
|
|
84
|
+
isError?: boolean;
|
|
85
|
+
}
|
|
86
|
+
export type GenerateMessage = SystemMessage | UserMessage | AssistantMessage | ToolMessage;
|
|
87
|
+
export interface ToolDefinition {
|
|
88
|
+
name: string;
|
|
89
|
+
description: string;
|
|
90
|
+
inputSchema: JsonSchema;
|
|
91
|
+
}
|
|
92
|
+
/** `required` = the model must call some tool; `{ name }` = that tool. */
|
|
93
|
+
export type ToolChoice = 'auto' | 'none' | 'required' | {
|
|
94
|
+
name: string;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Model-native web search (Anthropic web search tool, OpenAI `web_search`,
|
|
98
|
+
* Gemini Google Search grounding). Results and citations come back on the
|
|
99
|
+
* result; every search is counted for pricing.
|
|
100
|
+
*/
|
|
101
|
+
export interface WebSearchOptions {
|
|
102
|
+
/** Searches allowed in one call (Anthropic `max_uses`, OpenAI `max_tool_calls`). */
|
|
103
|
+
maxUses?: number;
|
|
104
|
+
allowedDomains?: string[];
|
|
105
|
+
blockedDomains?: string[];
|
|
106
|
+
/** Localizes results. `country` is ISO 3166-1 alpha-2. */
|
|
107
|
+
userLocation?: {
|
|
108
|
+
country?: string;
|
|
109
|
+
city?: string;
|
|
110
|
+
region?: string;
|
|
111
|
+
timezone?: string;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
export type ResponseFormat = {
|
|
115
|
+
type: 'json_schema';
|
|
116
|
+
name: string;
|
|
117
|
+
schema: JsonSchema;
|
|
118
|
+
strict?: boolean;
|
|
119
|
+
} | {
|
|
120
|
+
type: 'json';
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Prompt-cache options for the call. Setting it with no message marked
|
|
124
|
+
* `cache: true` lets Anthropic place the breakpoint itself (automatic
|
|
125
|
+
* caching).
|
|
126
|
+
*/
|
|
127
|
+
export interface CacheOptions {
|
|
128
|
+
/**
|
|
129
|
+
* Groups calls that share a prefix: OpenAI `prompt_cache_key` (routing
|
|
130
|
+
* and per-group cache accounting). Use a stable, PII-free value such as
|
|
131
|
+
* `<tenant>:<graph>:<node>`.
|
|
132
|
+
*/
|
|
133
|
+
key?: string;
|
|
134
|
+
/** Anthropic entry lifetime. `1h` writes cost 2× input instead of 1.25×. Default `5m`. */
|
|
135
|
+
ttl?: '5m' | '1h';
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* How much the model may think before it answers, provider-neutral:
|
|
139
|
+
* OpenAI reasoning models get `reasoning.effort` (`max` → `high`), Claude
|
|
140
|
+
* extended thinking with a token budget (1k / 4k / 12k / 24k; not when the
|
|
141
|
+
* call forces a tool, which Anthropic refuses with thinking on), Gemini a
|
|
142
|
+
* thinking budget (2.5) or level (3+). More effort spends more output
|
|
143
|
+
* tokens. Left out, each vendor's default applies.
|
|
144
|
+
*/
|
|
145
|
+
export type ReasoningEffort = 'low' | 'medium' | 'high' | 'max';
|
|
146
|
+
/** Thinking-token budget per effort, for vendors that take a budget (Claude, Gemini 2.5). */
|
|
147
|
+
export declare const THINKING_BUDGET: Record<ReasoningEffort, number>;
|
|
148
|
+
export interface GenerateRequest {
|
|
149
|
+
/** Wire model id at the adapter level (the gateway takes a catalog key). */
|
|
150
|
+
model: string;
|
|
151
|
+
messages: GenerateMessage[];
|
|
152
|
+
/** Hard cap on output tokens. Default 4096. With a thinking budget, raised to fit it. */
|
|
153
|
+
maxTokens?: number;
|
|
154
|
+
/** See {@link ReasoningEffort}. */
|
|
155
|
+
effort?: ReasoningEffort;
|
|
156
|
+
temperature?: number;
|
|
157
|
+
topP?: number;
|
|
158
|
+
stop?: string[];
|
|
159
|
+
tools?: ToolDefinition[];
|
|
160
|
+
toolChoice?: ToolChoice;
|
|
161
|
+
webSearch?: WebSearchOptions;
|
|
162
|
+
/** Native structured output; the parsed value comes back as `result.json`. */
|
|
163
|
+
responseFormat?: ResponseFormat;
|
|
164
|
+
/** Prompt caching for the call (see also `cache: true` on messages). */
|
|
165
|
+
cache?: CacheOptions;
|
|
166
|
+
/** Request timeout, covering the body read (the whole stream when streaming). Default 120 s. */
|
|
167
|
+
timeoutMs?: number;
|
|
168
|
+
/** Forwarded as `Idempotency-Key` to vendors that support it. */
|
|
169
|
+
idempotencyKey?: string;
|
|
170
|
+
/** Cooperative cancellation: aborts the HTTP call. */
|
|
171
|
+
signal?: AbortSignal;
|
|
172
|
+
}
|
|
173
|
+
/** A source the answer cites. */
|
|
174
|
+
export interface Citation {
|
|
175
|
+
url: string;
|
|
176
|
+
title?: string;
|
|
177
|
+
citedText?: string;
|
|
178
|
+
}
|
|
179
|
+
/** A page a web search returned. */
|
|
180
|
+
export interface SearchResult {
|
|
181
|
+
url: string;
|
|
182
|
+
title?: string;
|
|
183
|
+
pageAge?: string;
|
|
184
|
+
}
|
|
185
|
+
export interface GenerateUsage {
|
|
186
|
+
/** Every input token: uncached, read from the cache and written to it. */
|
|
187
|
+
tokensIn: number | null;
|
|
188
|
+
/** Input tokens served from the provider's prompt cache. */
|
|
189
|
+
cachedTokensIn: number | null;
|
|
190
|
+
/** Input tokens written to the provider's prompt cache (priced above the input rate). */
|
|
191
|
+
cacheWriteTokensIn?: number | null;
|
|
192
|
+
/** The part of `cacheWriteTokensIn` written with a 1-hour lifetime (Anthropic). */
|
|
193
|
+
cacheWrite1hTokensIn?: number | null;
|
|
194
|
+
/** Output tokens, reasoning included. */
|
|
195
|
+
tokensOut: number | null;
|
|
196
|
+
/** Web searches the vendor ran (priced per search). */
|
|
197
|
+
webSearches: number;
|
|
198
|
+
}
|
|
199
|
+
export interface GenerateResult {
|
|
200
|
+
provider: ChatProvider;
|
|
201
|
+
/** Wire model that served the call. */
|
|
202
|
+
model: string;
|
|
203
|
+
/** Final assistant text (may be empty when the model only called tools). */
|
|
204
|
+
text: string;
|
|
205
|
+
/** Parsed structured output when `responseFormat` was set and the reply parsed. */
|
|
206
|
+
json?: unknown;
|
|
207
|
+
toolCalls: ToolCall[];
|
|
208
|
+
citations: Citation[];
|
|
209
|
+
searchResults: SearchResult[];
|
|
210
|
+
searchQueries: string[];
|
|
211
|
+
finishReason: ChatFinishReason | null;
|
|
212
|
+
usage: GenerateUsage;
|
|
213
|
+
latencyMs: number;
|
|
214
|
+
/** Replay this on the assistant message of the next turn. */
|
|
215
|
+
providerState?: ProviderState;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* What a stream yields: text as it is written, each function-tool call
|
|
219
|
+
* once its arguments are complete, each native web search as it starts,
|
|
220
|
+
* then exactly one `done` with the same result `generate()` returns.
|
|
221
|
+
*/
|
|
222
|
+
export type GenerateStreamEvent = {
|
|
223
|
+
type: 'text';
|
|
224
|
+
delta: string;
|
|
225
|
+
} | {
|
|
226
|
+
type: 'tool_call';
|
|
227
|
+
call: ToolCall;
|
|
228
|
+
} | {
|
|
229
|
+
type: 'search';
|
|
230
|
+
query: string;
|
|
231
|
+
} | {
|
|
232
|
+
type: 'done';
|
|
233
|
+
result: GenerateResult;
|
|
234
|
+
};
|
|
235
|
+
export interface GenerateClient {
|
|
236
|
+
readonly provider: ChatProvider;
|
|
237
|
+
generate(request: GenerateRequest): Promise<GenerateResult>;
|
|
238
|
+
/** Streams the call (server-sent events). Clients without it are called through `generate`. */
|
|
239
|
+
stream?(request: GenerateRequest): AsyncIterable<GenerateStreamEvent>;
|
|
240
|
+
}
|
|
241
|
+
export interface GenerateAdapterConfig {
|
|
242
|
+
apiKey: string;
|
|
243
|
+
baseUrl?: string;
|
|
244
|
+
/** Default request timeout. Default 120 s. */
|
|
245
|
+
timeoutMs?: number;
|
|
246
|
+
/** Test seam. Defaults to the global `fetch`. */
|
|
247
|
+
fetch?: typeof fetch;
|
|
248
|
+
}
|
|
249
|
+
export type GenerateClientConfig = {
|
|
250
|
+
provider: ChatProvider;
|
|
251
|
+
} & GenerateAdapterConfig;
|
|
252
|
+
export {};
|
|
253
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/generate/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEvE,6DAA6D;AAC7D,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEjD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,+EAA+E;AAC/E,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wCAAwC;AACxC,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE1D,gDAAgD;AAChD,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,YAAY,CAAC;IACvB,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CAAC;IACxB,YAAY,EAAE,gBAAgB,GAAG,IAAI,CAAC;IACtC,KAAK,EAAE,aAAa,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAC3B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,cAAc,CAAA;CAAE,CAAC;AAE7C,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAC5D,+FAA+F;IAC/F,MAAM,CAAC,CAAC,OAAO,EAAE,eAAe,GAAG,aAAa,CAAC,mBAAmB,CAAC,CAAC;CACvE;AAED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB;AAED,MAAM,MAAM,oBAAoB,GAAG;IAAE,QAAQ,EAAE,YAAY,CAAA;CAAE,GAAG,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `generate` — the provider-neutral model call behind the LLM gateway and
|
|
3
|
+
* the agent loop.
|
|
4
|
+
*
|
|
5
|
+
* Wider than `chat/` (which stays the single-shot text API): function
|
|
6
|
+
* tools + tool choice, model-native web search with citations, native
|
|
7
|
+
* structured output, file / image inputs, prompt-cache hints and
|
|
8
|
+
* cached / cache-write usage, search counts for pricing, provider-state
|
|
9
|
+
* replay between turns, streaming, and cancellation through an
|
|
10
|
+
* `AbortSignal`.
|
|
11
|
+
*
|
|
12
|
+
* Adapters are `fetch()`-based like the chat adapters, and throw
|
|
13
|
+
* `Error("[ai/generate/<provider>] <status> <statusText>: <body>")` on an
|
|
14
|
+
* HTTP failure so `fallback/isRetryableError` (and callers that classify
|
|
15
|
+
* vendor errors) read the status the same way.
|
|
16
|
+
*/
|
|
17
|
+
/** Thinking-token budget per effort, for vendors that take a budget (Claude, Gemini 2.5). */
|
|
18
|
+
export const THINKING_BUDGET = { low: 1024, medium: 4096, high: 12_288, max: 24_576 };
|
|
19
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/generate/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA0IH,6FAA6F;AAC7F,MAAM,CAAC,MAAM,eAAe,GAAoC,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { GraphDefinition, NodeDefinition } from './types.js';
|
|
2
|
+
/** A node failure that must not be retried (bad input, a claim already taken, no budget). */
|
|
3
|
+
export declare class NodeFatalError extends Error {
|
|
4
|
+
readonly code: string;
|
|
5
|
+
constructor(message: string, code?: string);
|
|
6
|
+
}
|
|
7
|
+
/** Declare a node. Identity at runtime; keeps the node's literal types. */
|
|
8
|
+
export declare function defineNode<N extends NodeDefinition>(node: N): N;
|
|
9
|
+
/**
|
|
10
|
+
* Declare a graph: code, versioned (`key@version`), pinned per run.
|
|
11
|
+
* Register a new version alongside the old one so in-flight runs finish
|
|
12
|
+
* on the version they started with.
|
|
13
|
+
*/
|
|
14
|
+
export declare function defineGraph(graph: GraphDefinition): GraphDefinition;
|
|
15
|
+
//# sourceMappingURL=define.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.d.ts","sourceRoot":"","sources":["../../src/harness/define.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAElE,6FAA6F;AAC7F,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,OAAO,EAAE,MAAM,EAAE,IAAI,SAAe;CAKjD;AAED,2EAA2E;AAC3E,wBAAgB,UAAU,CAAC,CAAC,SAAS,cAAc,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,CAE/D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,eAAe,GAAG,eAAe,CAwBnE"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** A node failure that must not be retried (bad input, a claim already taken, no budget). */
|
|
2
|
+
export class NodeFatalError extends Error {
|
|
3
|
+
code;
|
|
4
|
+
constructor(message, code = 'node_fatal') {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = 'NodeFatalError';
|
|
7
|
+
this.code = code;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/** Declare a node. Identity at runtime; keeps the node's literal types. */
|
|
11
|
+
export function defineNode(node) {
|
|
12
|
+
return node;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Declare a graph: code, versioned (`key@version`), pinned per run.
|
|
16
|
+
* Register a new version alongside the old one so in-flight runs finish
|
|
17
|
+
* on the version they started with.
|
|
18
|
+
*/
|
|
19
|
+
export function defineGraph(graph) {
|
|
20
|
+
const ids = new Set();
|
|
21
|
+
for (const node of graph.nodes) {
|
|
22
|
+
if (ids.has(node.id))
|
|
23
|
+
throw new Error(`[ai/harness] ${graph.key}@${graph.version}: duplicate node '${node.id}'`);
|
|
24
|
+
ids.add(node.id);
|
|
25
|
+
}
|
|
26
|
+
if (!ids.has(graph.start))
|
|
27
|
+
throw new Error(`[ai/harness] ${graph.key}@${graph.version}: start node '${graph.start}' does not exist`);
|
|
28
|
+
for (const node of graph.nodes) {
|
|
29
|
+
if (typeof node.next === 'string' && !ids.has(node.next)) {
|
|
30
|
+
throw new Error(`[ai/harness] ${graph.key}@${graph.version}: node '${node.id}' goes to unknown node '${node.next}'`);
|
|
31
|
+
}
|
|
32
|
+
if (node.kind === 'gate' && node.decisions.length === 0) {
|
|
33
|
+
throw new Error(`[ai/harness] ${graph.key}@${graph.version}: gate '${node.id}' accepts no decision`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return graph;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","sourceRoot":"","sources":["../../src/harness/define.ts"],"names":[],"mappings":"AAEA,6FAA6F;AAC7F,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,IAAI,CAAS;IAEtB,YAAY,OAAe,EAAE,IAAI,GAAG,YAAY;QAC9C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAED,2EAA2E;AAC3E,MAAM,UAAU,UAAU,CAA2B,IAAO;IAC1D,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,KAAsB;IAChD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAC/B,IAAI,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,gBAAgB,KAAK,CAAC,GAAG,IAAI,KAAK,CAAC,OAAO,qBAAqB,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;QAC7F,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnB,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,gBAAgB,KAAK,CAAC,GAAG,IAAI,KAAK,CAAC,OAAO,iBAAiB,KAAK,CAAC,KAAK,kBAAkB,CACzF,CAAC;IACJ,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAC/B,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YACzD,MAAM,IAAI,KAAK,CACb,gBAAgB,KAAK,CAAC,GAAG,IAAI,KAAK,CAAC,OAAO,WAAW,IAAI,CAAC,EAAE,2BAA2B,IAAI,CAAC,IAAI,GAAG,CACpG,CAAC;QACJ,CAAC;QACD,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxD,MAAM,IAAI,KAAK,CACb,gBAAgB,KAAK,CAAC,GAAG,IAAI,KAAK,CAAC,OAAO,WAAW,IAAI,CAAC,EAAE,uBAAuB,CACpF,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createHarness` — the durable runtime for graphs.
|
|
3
|
+
*
|
|
4
|
+
* One task per node attempt (`{ runId, step, attempt }`):
|
|
5
|
+
*
|
|
6
|
+
* lease (CAS queued → running, `node.started`)
|
|
7
|
+
* → run the node (heartbeat renews the lease; a cancel poll and the
|
|
8
|
+
* node timeout abort `ctx.signal`)
|
|
9
|
+
* → ONE compare-and-set commit: output, next node, events, node-run row
|
|
10
|
+
* → schedule the next task
|
|
11
|
+
*
|
|
12
|
+
* A gate is reached in the same commit (status `waiting`, nothing in
|
|
13
|
+
* flight) and left by `resume()`. A failed attempt is retried with
|
|
14
|
+
* backoff unless it is fatal (`NodeFatalError`, a gateway policy denial,
|
|
15
|
+
* a 4xx caller error) or the node's attempts are used up. Duplicate or
|
|
16
|
+
* late deliveries are no-ops (`stale` / `busy`). `sweep()` re-sends tasks
|
|
17
|
+
* that were lost or held back, and fails the attempt of a worker whose
|
|
18
|
+
* lease expired.
|
|
19
|
+
*/
|
|
20
|
+
import type { Harness, HarnessOptions, RetryCategory } from './types.js';
|
|
21
|
+
/** Misuse of the harness API (unknown run, wrong status, bad decision, lost race). */
|
|
22
|
+
export declare class HarnessError extends Error {
|
|
23
|
+
readonly code: string;
|
|
24
|
+
constructor(code: string, message: string);
|
|
25
|
+
}
|
|
26
|
+
/** What kind of failure `err` is, for `retry.on` (an `AgentRunError` is judged by its cause). */
|
|
27
|
+
export declare function retryCategory(err: unknown): RetryCategory;
|
|
28
|
+
export declare function createHarness(options: HarnessOptions): Harness;
|
|
29
|
+
//# sourceMappingURL=harness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"harness.d.ts","sourceRoot":"","sources":["../../src/harness/harness.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAkBH,OAAO,KAAK,EAIV,OAAO,EACP,cAAc,EAKd,aAAa,EAId,MAAM,YAAY,CAAC;AAUpB,sFAAsF;AACtF,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK1C;AA2CD,iGAAiG;AACjG,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,aAAa,CA0BzD;AAiBD,wBAAgB,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAk0C9D"}
|