@agentskit/adapters 0.7.0 → 0.9.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.
- package/README.md +23 -5
- package/dist/index.cjs +281 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +199 -2
- package/dist/index.d.ts +199 -2
- package/dist/index.js +269 -1
- package/dist/index.js.map +1 -1
- package/package.json +14 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _agentskit_core from '@agentskit/core';
|
|
2
|
-
import { AdapterRequest, StreamChunk, AdapterFactory, StreamSource, EmbedFn } from '@agentskit/core';
|
|
2
|
+
import { AdapterRequest, StreamChunk, AdapterFactory, StreamSource, AdapterCapabilities, EmbedFn } from '@agentskit/core';
|
|
3
3
|
|
|
4
4
|
interface CreateAdapterConfig {
|
|
5
5
|
send: (request: AdapterRequest) => Promise<ReadableStream | Response>;
|
|
@@ -153,6 +153,203 @@ interface VercelAIConfig {
|
|
|
153
153
|
}
|
|
154
154
|
declare function vercelAI(config: VercelAIConfig): AdapterFactory;
|
|
155
155
|
|
|
156
|
+
interface MistralConfig extends OpenAICompatibleConfig {
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Mistral AI. Uses the OpenAI-compatible chat completions endpoint.
|
|
160
|
+
* Default models: `mistral-large-latest`, `mistral-small-latest`,
|
|
161
|
+
* `open-mistral-nemo`.
|
|
162
|
+
*/
|
|
163
|
+
declare const mistral: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
164
|
+
|
|
165
|
+
interface CohereConfig extends OpenAICompatibleConfig {
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Cohere Command models via the OpenAI-compatibility endpoint.
|
|
169
|
+
* Default models: `command-r-plus`, `command-r`, `command-light`.
|
|
170
|
+
*/
|
|
171
|
+
declare const cohere: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
172
|
+
|
|
173
|
+
interface TogetherConfig extends OpenAICompatibleConfig {
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Together AI. OpenAI-compatible endpoint, broad open-model catalog
|
|
177
|
+
* (Llama, Qwen, DeepSeek, Mixtral, etc.).
|
|
178
|
+
*/
|
|
179
|
+
declare const together: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
180
|
+
|
|
181
|
+
interface GroqConfig extends OpenAICompatibleConfig {
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Groq. OpenAI-compatible endpoint serving Llama / Mixtral on LPU.
|
|
185
|
+
* Known for very low first-token latency.
|
|
186
|
+
*/
|
|
187
|
+
declare const groq: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
188
|
+
|
|
189
|
+
interface FireworksConfig extends OpenAICompatibleConfig {
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Fireworks AI. OpenAI-compatible endpoint with tuned open-source
|
|
193
|
+
* models and fine-tunes (Llama, DeepSeek, Qwen, etc.).
|
|
194
|
+
*/
|
|
195
|
+
declare const fireworks: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
196
|
+
|
|
197
|
+
interface OpenRouterConfig extends OpenAICompatibleConfig {
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* OpenRouter — routes to 300+ provider models behind a single
|
|
201
|
+
* OpenAI-compatible endpoint. Pass the fully-qualified id as
|
|
202
|
+
* `model`, e.g. `anthropic/claude-sonnet-4-6`.
|
|
203
|
+
*/
|
|
204
|
+
declare const openrouter: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
205
|
+
|
|
206
|
+
interface HuggingFaceConfig extends OpenAICompatibleConfig {
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Hugging Face Inference Providers router. OpenAI-compatible
|
|
210
|
+
* endpoint that fans out to HF-hosted model inference providers.
|
|
211
|
+
* Pass any supported repo id as `model`, e.g.
|
|
212
|
+
* `meta-llama/Meta-Llama-3.1-8B-Instruct`.
|
|
213
|
+
*/
|
|
214
|
+
declare const huggingface: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
215
|
+
|
|
216
|
+
interface LMStudioConfig extends OpenAICompatibleConfig {
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* LM Studio local server. Start the built-in OpenAI-compatible
|
|
220
|
+
* server in LM Studio, then point this adapter at
|
|
221
|
+
* `http://localhost:1234/v1` (the default).
|
|
222
|
+
*/
|
|
223
|
+
declare const lmstudio: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
224
|
+
|
|
225
|
+
interface VLLMConfig extends OpenAICompatibleConfig {
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* vLLM's OpenAI-compatible serving endpoint. Defaults to
|
|
229
|
+
* `http://localhost:8000/v1` — the standard `vllm serve ...` port.
|
|
230
|
+
*/
|
|
231
|
+
declare const vllm: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
232
|
+
|
|
233
|
+
interface LlamaCppConfig extends OpenAICompatibleConfig {
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* llama.cpp's OpenAI-compatible HTTP server (`llama-server`). Defaults
|
|
237
|
+
* to `http://localhost:8080/v1`, matching the binary's default port.
|
|
238
|
+
*/
|
|
239
|
+
declare const llamacpp: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
240
|
+
|
|
241
|
+
interface RouterCandidate {
|
|
242
|
+
id: string;
|
|
243
|
+
adapter: AdapterFactory;
|
|
244
|
+
/**
|
|
245
|
+
* Relative cost hint (lower wins for policy='cheapest'). Only
|
|
246
|
+
* relative values matter — use $/1M tokens or any consistent unit.
|
|
247
|
+
*/
|
|
248
|
+
cost?: number;
|
|
249
|
+
/** Typical latency in ms. Lower wins for policy='fastest'. */
|
|
250
|
+
latencyMs?: number;
|
|
251
|
+
/**
|
|
252
|
+
* Capability override. Defaults to `adapter.capabilities`.
|
|
253
|
+
* Used to reject candidates missing required features
|
|
254
|
+
* (e.g. tools, multiModal).
|
|
255
|
+
*/
|
|
256
|
+
capabilities?: AdapterCapabilities;
|
|
257
|
+
/** Free-form tags used by classifier routing (e.g. 'fast', 'coding'). */
|
|
258
|
+
tags?: string[];
|
|
259
|
+
}
|
|
260
|
+
type RouterPolicy = 'cheapest' | 'fastest' | 'capability-match' | ((input: {
|
|
261
|
+
request: AdapterRequest;
|
|
262
|
+
candidates: RouterCandidate[];
|
|
263
|
+
}) => string | Promise<string>);
|
|
264
|
+
interface RouterOptions {
|
|
265
|
+
candidates: RouterCandidate[];
|
|
266
|
+
/** Policy when `classify` doesn't pick a candidate. Default 'cheapest'. */
|
|
267
|
+
policy?: RouterPolicy;
|
|
268
|
+
/**
|
|
269
|
+
* Fast path: inspect the request, return a candidate id or tag(s).
|
|
270
|
+
* Return `undefined` to fall back to `policy`.
|
|
271
|
+
*/
|
|
272
|
+
classify?: (request: AdapterRequest) => string | string[] | undefined;
|
|
273
|
+
/** Observability hook — fires once per decision. */
|
|
274
|
+
onRoute?: (decision: {
|
|
275
|
+
id: string;
|
|
276
|
+
reason: string;
|
|
277
|
+
request: AdapterRequest;
|
|
278
|
+
}) => void;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Build an AdapterFactory that picks one of N candidates per request.
|
|
282
|
+
*
|
|
283
|
+
* Resolution order:
|
|
284
|
+
* 1. `classify(request)` returns a candidate id → use it
|
|
285
|
+
* 2. `classify(request)` returns tag(s) → filter by tags, then `policy`
|
|
286
|
+
* 3. Fall back to `policy` over all capability-matched candidates
|
|
287
|
+
*/
|
|
288
|
+
declare function createRouter(options: RouterOptions): AdapterFactory;
|
|
289
|
+
|
|
290
|
+
interface EnsembleCandidate {
|
|
291
|
+
id: string;
|
|
292
|
+
adapter: AdapterFactory;
|
|
293
|
+
/** Weight used by 'weighted-vote' aggregator. Default 1. */
|
|
294
|
+
weight?: number;
|
|
295
|
+
}
|
|
296
|
+
interface EnsembleBranchResult {
|
|
297
|
+
id: string;
|
|
298
|
+
text: string;
|
|
299
|
+
chunks: StreamChunk[];
|
|
300
|
+
error?: Error;
|
|
301
|
+
}
|
|
302
|
+
type EnsembleAggregator = 'majority-vote' | 'concat' | 'longest' | ((branches: EnsembleBranchResult[]) => string | Promise<string>);
|
|
303
|
+
interface EnsembleOptions {
|
|
304
|
+
candidates: EnsembleCandidate[];
|
|
305
|
+
/** How to combine branches into the single output text. Default 'majority-vote'. */
|
|
306
|
+
aggregate?: EnsembleAggregator;
|
|
307
|
+
/** Per-candidate timeout in ms. Branches that time out are marked with an error. */
|
|
308
|
+
timeoutMs?: number;
|
|
309
|
+
/** Observability hook — fires once with every branch's result. */
|
|
310
|
+
onBranches?: (branches: EnsembleBranchResult[]) => void;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Build an AdapterFactory that runs the same request against N
|
|
314
|
+
* candidates in parallel, then aggregates the results into a single
|
|
315
|
+
* text output. Unlike `speculate` (which picks a winner), `ensemble`
|
|
316
|
+
* combines — majority vote, concatenation, longest, or a custom fn.
|
|
317
|
+
*
|
|
318
|
+
* The returned source emits a single `{ type: 'text' }` chunk with
|
|
319
|
+
* the aggregated output followed by `{ type: 'done' }`, so it plugs
|
|
320
|
+
* into any runtime that expects a regular streaming adapter.
|
|
321
|
+
*/
|
|
322
|
+
declare function createEnsembleAdapter(options: EnsembleOptions): AdapterFactory;
|
|
323
|
+
|
|
324
|
+
interface FallbackOptions {
|
|
325
|
+
/**
|
|
326
|
+
* Predicate deciding whether an error from a given adapter should
|
|
327
|
+
* trigger fall-through to the next. Default: always retry the next.
|
|
328
|
+
*/
|
|
329
|
+
shouldRetry?: (error: Error, index: number) => boolean;
|
|
330
|
+
/** Observability hook — fires when one adapter fails and the chain advances. */
|
|
331
|
+
onFallback?: (from: {
|
|
332
|
+
id: string;
|
|
333
|
+
index: number;
|
|
334
|
+
error: Error;
|
|
335
|
+
}) => void;
|
|
336
|
+
}
|
|
337
|
+
interface FallbackCandidate {
|
|
338
|
+
id: string;
|
|
339
|
+
adapter: AdapterFactory;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Try adapters in order. If the first fails (throws while opening, or
|
|
343
|
+
* errors mid-stream before emitting any non-done chunk), fall through
|
|
344
|
+
* to the next. As soon as a candidate produces its first real chunk,
|
|
345
|
+
* that's the committed one — we don't retroactively retry mid-stream.
|
|
346
|
+
*
|
|
347
|
+
* Errors that happen *after* committing are propagated; the caller
|
|
348
|
+
* sees a normal streaming failure, not a mysterious cross-candidate
|
|
349
|
+
* retry that could duplicate tool calls.
|
|
350
|
+
*/
|
|
351
|
+
declare function createFallbackAdapter(candidates: FallbackCandidate[], options?: FallbackOptions): AdapterFactory;
|
|
352
|
+
|
|
156
353
|
type MockResponse = StreamChunk[] | ((request: AdapterRequest) => StreamChunk[]);
|
|
157
354
|
interface MockAdapterOptions {
|
|
158
355
|
/**
|
|
@@ -272,4 +469,4 @@ interface KimiEmbedderConfig extends OpenAICompatibleEmbedderConfig {
|
|
|
272
469
|
}
|
|
273
470
|
declare const kimiEmbedder: (config: OpenAICompatibleEmbedderConfig) => _agentskit_core.EmbedFn;
|
|
274
471
|
|
|
275
|
-
export { type AnthropicConfig, type CreateAdapterConfig, type DeepSeekConfig, type DeepSeekEmbedderConfig, type GeminiConfig, type GeminiEmbedderConfig, type GenericAdapterConfig, type GrokConfig, type GrokEmbedderConfig, type KimiConfig, type KimiEmbedderConfig, type LangChainConfig, type LangGraphConfig, type MockAdapterOptions, type MockResponse, type OllamaConfig, type OllamaEmbedderConfig, type OpenAICompatibleEmbedderConfig, type OpenAIConfig, type OpenAIEmbedderConfig, type RecordedTurn, type RecordingFixture, type RecordingSink, type RetryOptions, type VercelAIConfig, anthropic, chunkText, createAdapter, createOpenAICompatibleEmbedder, deepseek, deepseekEmbedder, fetchWithRetry, gemini, geminiEmbedder, generic, grok, grokEmbedder, inMemorySink, kimi, kimiEmbedder, langchain, langgraph, mockAdapter, ollama, ollamaEmbedder, openai, openaiEmbedder, recordingAdapter, replayAdapter, simulateStream, vercelAI };
|
|
472
|
+
export { type AnthropicConfig, type CohereConfig, type CreateAdapterConfig, type DeepSeekConfig, type DeepSeekEmbedderConfig, type EnsembleAggregator, type EnsembleBranchResult, type EnsembleCandidate, type EnsembleOptions, type FallbackCandidate, type FallbackOptions, type FireworksConfig, type GeminiConfig, type GeminiEmbedderConfig, type GenericAdapterConfig, type GrokConfig, type GrokEmbedderConfig, type GroqConfig, type HuggingFaceConfig, type KimiConfig, type KimiEmbedderConfig, type LMStudioConfig, type LangChainConfig, type LangGraphConfig, type LlamaCppConfig, type MistralConfig, type MockAdapterOptions, type MockResponse, type OllamaConfig, type OllamaEmbedderConfig, type OpenAICompatibleEmbedderConfig, type OpenAIConfig, type OpenAIEmbedderConfig, type OpenRouterConfig, type RecordedTurn, type RecordingFixture, type RecordingSink, type RetryOptions, type RouterCandidate, type RouterOptions, type RouterPolicy, type TogetherConfig, type VLLMConfig, type VercelAIConfig, anthropic, chunkText, cohere, createAdapter, createEnsembleAdapter, createFallbackAdapter, createOpenAICompatibleEmbedder, createRouter, deepseek, deepseekEmbedder, fetchWithRetry, fireworks, gemini, geminiEmbedder, generic, grok, grokEmbedder, groq, huggingface, inMemorySink, kimi, kimiEmbedder, langchain, langgraph, llamacpp, lmstudio, mistral, mockAdapter, ollama, ollamaEmbedder, openai, openaiEmbedder, openrouter, recordingAdapter, replayAdapter, simulateStream, together, vercelAI, vllm };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _agentskit_core from '@agentskit/core';
|
|
2
|
-
import { AdapterRequest, StreamChunk, AdapterFactory, StreamSource, EmbedFn } from '@agentskit/core';
|
|
2
|
+
import { AdapterRequest, StreamChunk, AdapterFactory, StreamSource, AdapterCapabilities, EmbedFn } from '@agentskit/core';
|
|
3
3
|
|
|
4
4
|
interface CreateAdapterConfig {
|
|
5
5
|
send: (request: AdapterRequest) => Promise<ReadableStream | Response>;
|
|
@@ -153,6 +153,203 @@ interface VercelAIConfig {
|
|
|
153
153
|
}
|
|
154
154
|
declare function vercelAI(config: VercelAIConfig): AdapterFactory;
|
|
155
155
|
|
|
156
|
+
interface MistralConfig extends OpenAICompatibleConfig {
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Mistral AI. Uses the OpenAI-compatible chat completions endpoint.
|
|
160
|
+
* Default models: `mistral-large-latest`, `mistral-small-latest`,
|
|
161
|
+
* `open-mistral-nemo`.
|
|
162
|
+
*/
|
|
163
|
+
declare const mistral: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
164
|
+
|
|
165
|
+
interface CohereConfig extends OpenAICompatibleConfig {
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Cohere Command models via the OpenAI-compatibility endpoint.
|
|
169
|
+
* Default models: `command-r-plus`, `command-r`, `command-light`.
|
|
170
|
+
*/
|
|
171
|
+
declare const cohere: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
172
|
+
|
|
173
|
+
interface TogetherConfig extends OpenAICompatibleConfig {
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Together AI. OpenAI-compatible endpoint, broad open-model catalog
|
|
177
|
+
* (Llama, Qwen, DeepSeek, Mixtral, etc.).
|
|
178
|
+
*/
|
|
179
|
+
declare const together: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
180
|
+
|
|
181
|
+
interface GroqConfig extends OpenAICompatibleConfig {
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Groq. OpenAI-compatible endpoint serving Llama / Mixtral on LPU.
|
|
185
|
+
* Known for very low first-token latency.
|
|
186
|
+
*/
|
|
187
|
+
declare const groq: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
188
|
+
|
|
189
|
+
interface FireworksConfig extends OpenAICompatibleConfig {
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Fireworks AI. OpenAI-compatible endpoint with tuned open-source
|
|
193
|
+
* models and fine-tunes (Llama, DeepSeek, Qwen, etc.).
|
|
194
|
+
*/
|
|
195
|
+
declare const fireworks: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
196
|
+
|
|
197
|
+
interface OpenRouterConfig extends OpenAICompatibleConfig {
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* OpenRouter — routes to 300+ provider models behind a single
|
|
201
|
+
* OpenAI-compatible endpoint. Pass the fully-qualified id as
|
|
202
|
+
* `model`, e.g. `anthropic/claude-sonnet-4-6`.
|
|
203
|
+
*/
|
|
204
|
+
declare const openrouter: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
205
|
+
|
|
206
|
+
interface HuggingFaceConfig extends OpenAICompatibleConfig {
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Hugging Face Inference Providers router. OpenAI-compatible
|
|
210
|
+
* endpoint that fans out to HF-hosted model inference providers.
|
|
211
|
+
* Pass any supported repo id as `model`, e.g.
|
|
212
|
+
* `meta-llama/Meta-Llama-3.1-8B-Instruct`.
|
|
213
|
+
*/
|
|
214
|
+
declare const huggingface: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
215
|
+
|
|
216
|
+
interface LMStudioConfig extends OpenAICompatibleConfig {
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* LM Studio local server. Start the built-in OpenAI-compatible
|
|
220
|
+
* server in LM Studio, then point this adapter at
|
|
221
|
+
* `http://localhost:1234/v1` (the default).
|
|
222
|
+
*/
|
|
223
|
+
declare const lmstudio: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
224
|
+
|
|
225
|
+
interface VLLMConfig extends OpenAICompatibleConfig {
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* vLLM's OpenAI-compatible serving endpoint. Defaults to
|
|
229
|
+
* `http://localhost:8000/v1` — the standard `vllm serve ...` port.
|
|
230
|
+
*/
|
|
231
|
+
declare const vllm: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
232
|
+
|
|
233
|
+
interface LlamaCppConfig extends OpenAICompatibleConfig {
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* llama.cpp's OpenAI-compatible HTTP server (`llama-server`). Defaults
|
|
237
|
+
* to `http://localhost:8080/v1`, matching the binary's default port.
|
|
238
|
+
*/
|
|
239
|
+
declare const llamacpp: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
|
|
240
|
+
|
|
241
|
+
interface RouterCandidate {
|
|
242
|
+
id: string;
|
|
243
|
+
adapter: AdapterFactory;
|
|
244
|
+
/**
|
|
245
|
+
* Relative cost hint (lower wins for policy='cheapest'). Only
|
|
246
|
+
* relative values matter — use $/1M tokens or any consistent unit.
|
|
247
|
+
*/
|
|
248
|
+
cost?: number;
|
|
249
|
+
/** Typical latency in ms. Lower wins for policy='fastest'. */
|
|
250
|
+
latencyMs?: number;
|
|
251
|
+
/**
|
|
252
|
+
* Capability override. Defaults to `adapter.capabilities`.
|
|
253
|
+
* Used to reject candidates missing required features
|
|
254
|
+
* (e.g. tools, multiModal).
|
|
255
|
+
*/
|
|
256
|
+
capabilities?: AdapterCapabilities;
|
|
257
|
+
/** Free-form tags used by classifier routing (e.g. 'fast', 'coding'). */
|
|
258
|
+
tags?: string[];
|
|
259
|
+
}
|
|
260
|
+
type RouterPolicy = 'cheapest' | 'fastest' | 'capability-match' | ((input: {
|
|
261
|
+
request: AdapterRequest;
|
|
262
|
+
candidates: RouterCandidate[];
|
|
263
|
+
}) => string | Promise<string>);
|
|
264
|
+
interface RouterOptions {
|
|
265
|
+
candidates: RouterCandidate[];
|
|
266
|
+
/** Policy when `classify` doesn't pick a candidate. Default 'cheapest'. */
|
|
267
|
+
policy?: RouterPolicy;
|
|
268
|
+
/**
|
|
269
|
+
* Fast path: inspect the request, return a candidate id or tag(s).
|
|
270
|
+
* Return `undefined` to fall back to `policy`.
|
|
271
|
+
*/
|
|
272
|
+
classify?: (request: AdapterRequest) => string | string[] | undefined;
|
|
273
|
+
/** Observability hook — fires once per decision. */
|
|
274
|
+
onRoute?: (decision: {
|
|
275
|
+
id: string;
|
|
276
|
+
reason: string;
|
|
277
|
+
request: AdapterRequest;
|
|
278
|
+
}) => void;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Build an AdapterFactory that picks one of N candidates per request.
|
|
282
|
+
*
|
|
283
|
+
* Resolution order:
|
|
284
|
+
* 1. `classify(request)` returns a candidate id → use it
|
|
285
|
+
* 2. `classify(request)` returns tag(s) → filter by tags, then `policy`
|
|
286
|
+
* 3. Fall back to `policy` over all capability-matched candidates
|
|
287
|
+
*/
|
|
288
|
+
declare function createRouter(options: RouterOptions): AdapterFactory;
|
|
289
|
+
|
|
290
|
+
interface EnsembleCandidate {
|
|
291
|
+
id: string;
|
|
292
|
+
adapter: AdapterFactory;
|
|
293
|
+
/** Weight used by 'weighted-vote' aggregator. Default 1. */
|
|
294
|
+
weight?: number;
|
|
295
|
+
}
|
|
296
|
+
interface EnsembleBranchResult {
|
|
297
|
+
id: string;
|
|
298
|
+
text: string;
|
|
299
|
+
chunks: StreamChunk[];
|
|
300
|
+
error?: Error;
|
|
301
|
+
}
|
|
302
|
+
type EnsembleAggregator = 'majority-vote' | 'concat' | 'longest' | ((branches: EnsembleBranchResult[]) => string | Promise<string>);
|
|
303
|
+
interface EnsembleOptions {
|
|
304
|
+
candidates: EnsembleCandidate[];
|
|
305
|
+
/** How to combine branches into the single output text. Default 'majority-vote'. */
|
|
306
|
+
aggregate?: EnsembleAggregator;
|
|
307
|
+
/** Per-candidate timeout in ms. Branches that time out are marked with an error. */
|
|
308
|
+
timeoutMs?: number;
|
|
309
|
+
/** Observability hook — fires once with every branch's result. */
|
|
310
|
+
onBranches?: (branches: EnsembleBranchResult[]) => void;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Build an AdapterFactory that runs the same request against N
|
|
314
|
+
* candidates in parallel, then aggregates the results into a single
|
|
315
|
+
* text output. Unlike `speculate` (which picks a winner), `ensemble`
|
|
316
|
+
* combines — majority vote, concatenation, longest, or a custom fn.
|
|
317
|
+
*
|
|
318
|
+
* The returned source emits a single `{ type: 'text' }` chunk with
|
|
319
|
+
* the aggregated output followed by `{ type: 'done' }`, so it plugs
|
|
320
|
+
* into any runtime that expects a regular streaming adapter.
|
|
321
|
+
*/
|
|
322
|
+
declare function createEnsembleAdapter(options: EnsembleOptions): AdapterFactory;
|
|
323
|
+
|
|
324
|
+
interface FallbackOptions {
|
|
325
|
+
/**
|
|
326
|
+
* Predicate deciding whether an error from a given adapter should
|
|
327
|
+
* trigger fall-through to the next. Default: always retry the next.
|
|
328
|
+
*/
|
|
329
|
+
shouldRetry?: (error: Error, index: number) => boolean;
|
|
330
|
+
/** Observability hook — fires when one adapter fails and the chain advances. */
|
|
331
|
+
onFallback?: (from: {
|
|
332
|
+
id: string;
|
|
333
|
+
index: number;
|
|
334
|
+
error: Error;
|
|
335
|
+
}) => void;
|
|
336
|
+
}
|
|
337
|
+
interface FallbackCandidate {
|
|
338
|
+
id: string;
|
|
339
|
+
adapter: AdapterFactory;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Try adapters in order. If the first fails (throws while opening, or
|
|
343
|
+
* errors mid-stream before emitting any non-done chunk), fall through
|
|
344
|
+
* to the next. As soon as a candidate produces its first real chunk,
|
|
345
|
+
* that's the committed one — we don't retroactively retry mid-stream.
|
|
346
|
+
*
|
|
347
|
+
* Errors that happen *after* committing are propagated; the caller
|
|
348
|
+
* sees a normal streaming failure, not a mysterious cross-candidate
|
|
349
|
+
* retry that could duplicate tool calls.
|
|
350
|
+
*/
|
|
351
|
+
declare function createFallbackAdapter(candidates: FallbackCandidate[], options?: FallbackOptions): AdapterFactory;
|
|
352
|
+
|
|
156
353
|
type MockResponse = StreamChunk[] | ((request: AdapterRequest) => StreamChunk[]);
|
|
157
354
|
interface MockAdapterOptions {
|
|
158
355
|
/**
|
|
@@ -272,4 +469,4 @@ interface KimiEmbedderConfig extends OpenAICompatibleEmbedderConfig {
|
|
|
272
469
|
}
|
|
273
470
|
declare const kimiEmbedder: (config: OpenAICompatibleEmbedderConfig) => _agentskit_core.EmbedFn;
|
|
274
471
|
|
|
275
|
-
export { type AnthropicConfig, type CreateAdapterConfig, type DeepSeekConfig, type DeepSeekEmbedderConfig, type GeminiConfig, type GeminiEmbedderConfig, type GenericAdapterConfig, type GrokConfig, type GrokEmbedderConfig, type KimiConfig, type KimiEmbedderConfig, type LangChainConfig, type LangGraphConfig, type MockAdapterOptions, type MockResponse, type OllamaConfig, type OllamaEmbedderConfig, type OpenAICompatibleEmbedderConfig, type OpenAIConfig, type OpenAIEmbedderConfig, type RecordedTurn, type RecordingFixture, type RecordingSink, type RetryOptions, type VercelAIConfig, anthropic, chunkText, createAdapter, createOpenAICompatibleEmbedder, deepseek, deepseekEmbedder, fetchWithRetry, gemini, geminiEmbedder, generic, grok, grokEmbedder, inMemorySink, kimi, kimiEmbedder, langchain, langgraph, mockAdapter, ollama, ollamaEmbedder, openai, openaiEmbedder, recordingAdapter, replayAdapter, simulateStream, vercelAI };
|
|
472
|
+
export { type AnthropicConfig, type CohereConfig, type CreateAdapterConfig, type DeepSeekConfig, type DeepSeekEmbedderConfig, type EnsembleAggregator, type EnsembleBranchResult, type EnsembleCandidate, type EnsembleOptions, type FallbackCandidate, type FallbackOptions, type FireworksConfig, type GeminiConfig, type GeminiEmbedderConfig, type GenericAdapterConfig, type GrokConfig, type GrokEmbedderConfig, type GroqConfig, type HuggingFaceConfig, type KimiConfig, type KimiEmbedderConfig, type LMStudioConfig, type LangChainConfig, type LangGraphConfig, type LlamaCppConfig, type MistralConfig, type MockAdapterOptions, type MockResponse, type OllamaConfig, type OllamaEmbedderConfig, type OpenAICompatibleEmbedderConfig, type OpenAIConfig, type OpenAIEmbedderConfig, type OpenRouterConfig, type RecordedTurn, type RecordingFixture, type RecordingSink, type RetryOptions, type RouterCandidate, type RouterOptions, type RouterPolicy, type TogetherConfig, type VLLMConfig, type VercelAIConfig, anthropic, chunkText, cohere, createAdapter, createEnsembleAdapter, createFallbackAdapter, createOpenAICompatibleEmbedder, createRouter, deepseek, deepseekEmbedder, fetchWithRetry, fireworks, gemini, geminiEmbedder, generic, grok, grokEmbedder, groq, huggingface, inMemorySink, kimi, kimiEmbedder, langchain, langgraph, llamacpp, lmstudio, mistral, mockAdapter, ollama, ollamaEmbedder, openai, openaiEmbedder, openrouter, recordingAdapter, replayAdapter, simulateStream, together, vercelAI, vllm };
|