@agentskit/adapters 0.7.1 → 0.10.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/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,339 @@ 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 Cohere's OpenAI-compatibility endpoint.
169
+ *
170
+ * - Streams tokens via SSE (OpenAI-compatible chunks).
171
+ * - Supports tool calls in the OpenAI `tools` shape.
172
+ * - Reports `usage` on the final stream chunk when the upstream model
173
+ * returns it (Cohere's compatibility layer mirrors OpenAI's
174
+ * `stream_options: { include_usage: true }` semantics).
175
+ * - Inherits auto-retry from the shared OpenAI core (`retry`).
176
+ *
177
+ * Default model: `command-r-plus`. Override via `model`.
178
+ */
179
+ declare function cohere(config: Partial<CohereConfig> & {
180
+ apiKey: string;
181
+ }): AdapterFactory;
182
+ /** Alias for naming consistency with other native adapters. */
183
+ declare const cohereAdapter: typeof cohere;
184
+
185
+ interface TogetherConfig extends OpenAICompatibleConfig {
186
+ }
187
+ /**
188
+ * Together AI. OpenAI-compatible endpoint, broad open-model catalog
189
+ * (Llama, Qwen, DeepSeek, Mixtral, etc.).
190
+ */
191
+ declare const together: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
192
+
193
+ interface GroqConfig extends OpenAICompatibleConfig {
194
+ }
195
+ /**
196
+ * Groq — OpenAI-compatible endpoint serving Llama / Mixtral on LPUs.
197
+ * Known for very low first-token latency.
198
+ *
199
+ * Default model: `llama-3.3-70b-versatile`.
200
+ */
201
+ declare function groq(config: Partial<GroqConfig> & {
202
+ apiKey: string;
203
+ }): AdapterFactory;
204
+ /** Alias for naming consistency with other native adapters. */
205
+ declare const groqAdapter: typeof groq;
206
+
207
+ interface FireworksConfig extends OpenAICompatibleConfig {
208
+ }
209
+ /**
210
+ * Fireworks AI. OpenAI-compatible endpoint with tuned open-source
211
+ * models and fine-tunes (Llama, DeepSeek, Qwen, etc.).
212
+ */
213
+ declare const fireworks: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
214
+
215
+ interface OpenRouterConfig extends OpenAICompatibleConfig {
216
+ }
217
+ /**
218
+ * OpenRouter — routes to 300+ provider models behind a single
219
+ * OpenAI-compatible endpoint. Pass the fully-qualified id as
220
+ * `model`, e.g. `anthropic/claude-sonnet-4-6`.
221
+ */
222
+ declare const openrouter: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
223
+
224
+ interface HuggingFaceConfig extends OpenAICompatibleConfig {
225
+ }
226
+ /**
227
+ * Hugging Face Inference Providers router. OpenAI-compatible
228
+ * endpoint that fans out to HF-hosted model inference providers.
229
+ * Pass any supported repo id as `model`, e.g.
230
+ * `meta-llama/Meta-Llama-3.1-8B-Instruct`.
231
+ */
232
+ declare const huggingface: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
233
+
234
+ interface LMStudioConfig extends OpenAICompatibleConfig {
235
+ }
236
+ /**
237
+ * LM Studio local server. Start the built-in OpenAI-compatible
238
+ * server in LM Studio, then point this adapter at
239
+ * `http://localhost:1234/v1` (the default).
240
+ */
241
+ declare const lmstudio: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
242
+
243
+ interface VLLMConfig extends OpenAICompatibleConfig {
244
+ }
245
+ /**
246
+ * vLLM's OpenAI-compatible serving endpoint. Defaults to
247
+ * `http://localhost:8000/v1` — the standard `vllm serve ...` port.
248
+ */
249
+ declare const vllm: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
250
+
251
+ interface LlamaCppConfig extends OpenAICompatibleConfig {
252
+ }
253
+ /**
254
+ * llama.cpp's OpenAI-compatible HTTP server (`llama-server`). Defaults
255
+ * to `http://localhost:8080/v1`, matching the binary's default port.
256
+ */
257
+ declare const llamacpp: (config: OpenAICompatibleConfig) => _agentskit_core.AdapterFactory;
258
+
259
+ interface CerebrasConfig extends OpenAICompatibleConfig {
260
+ }
261
+ /**
262
+ * Cerebras — ultra-fast inference on wafer-scale chips. OpenAI-compatible
263
+ * endpoint serving Llama / Qwen models with very low first-token latency.
264
+ *
265
+ * Default model: `llama-3.3-70b`.
266
+ */
267
+ declare function cerebras(config: Partial<CerebrasConfig> & {
268
+ apiKey: string;
269
+ }): AdapterFactory;
270
+ declare const cerebrasAdapter: typeof cerebras;
271
+
272
+ interface AzureOpenAIConfig {
273
+ apiKey: string;
274
+ /** Resource endpoint, e.g. `https://my-resource.openai.azure.com`. */
275
+ endpoint: string;
276
+ /** Deployment name (NOT the underlying model name — Azure routes by deployment). */
277
+ deployment: string;
278
+ /** Azure REST `api-version`. Defaults to `2024-10-21`. */
279
+ apiVersion?: string;
280
+ retry?: RetryOptions;
281
+ /** Surface usage by setting `stream_options.include_usage`. Defaults to true. */
282
+ includeUsage?: boolean;
283
+ }
284
+ declare function azureOpenAI(config: AzureOpenAIConfig): AdapterFactory;
285
+ declare const azureOpenAIAdapter: typeof azureOpenAI;
286
+
287
+ interface ReplicateConfig {
288
+ apiKey: string;
289
+ /** Replicate model id, e.g. `meta/meta-llama-3-70b-instruct`. */
290
+ model: string;
291
+ /** Optional pinned version hash (for non-official models). */
292
+ version?: string;
293
+ /** Override the prediction endpoint base. */
294
+ baseUrl?: string;
295
+ /** Map AdapterRequest → Replicate `input` object. Defaults to `{ prompt }`. */
296
+ toInput?: (request: AdapterRequest) => Record<string, unknown>;
297
+ }
298
+ declare function replicate(config: ReplicateConfig): AdapterFactory;
299
+ declare const replicateAdapter: typeof replicate;
300
+
301
+ interface BailConfig extends OpenAICompatibleConfig {
302
+ }
303
+ /**
304
+ * Alibaba Bailian (Qwen) via the DashScope OpenAI-compatibility endpoint.
305
+ *
306
+ * Supports the Qwen-2.5 / 3 chat series and Qwen-VL multimodal models. APAC
307
+ * users typically prefer this over OpenAI for latency + data residency.
308
+ *
309
+ * Default model: `qwen-max`.
310
+ */
311
+ declare function bail(config: Partial<BailConfig> & {
312
+ apiKey: string;
313
+ }): AdapterFactory;
314
+ declare const bailAdapter: typeof bail;
315
+ /** Alias matching Alibaba's product naming. */
316
+ declare const qwen: typeof bail;
317
+
318
+ interface VertexConfig {
319
+ /** GCP project id. */
320
+ project: string;
321
+ /** Region, e.g. `us-central1`. */
322
+ region: string;
323
+ /** Vertex model id, e.g. `gemini-2.5-pro`. */
324
+ model: string;
325
+ /**
326
+ * OAuth2 access token, or a function returning one (called per request).
327
+ *
328
+ * Use the `google-auth-library` (or `gcloud auth print-access-token`) to
329
+ * mint these — the adapter intentionally doesn't take that as a hard dep.
330
+ */
331
+ accessToken: string | (() => string | Promise<string>);
332
+ /** Override the publisher (defaults to `google`; set for partner publishers). */
333
+ publisher?: string;
334
+ retry?: RetryOptions;
335
+ }
336
+ declare function vertex(config: VertexConfig): AdapterFactory;
337
+ declare const vertexAdapter: typeof vertex;
338
+
339
+ interface BedrockConfig {
340
+ /** Bedrock model id, e.g. `anthropic.claude-3-5-sonnet-20241022-v2:0`. */
341
+ model: string;
342
+ /** AWS region (e.g. `us-east-1`). Falls back to the SDK's default credential chain. */
343
+ region?: string;
344
+ /** Override `max_tokens` (Anthropic on Bedrock requires it). Defaults to 4096. */
345
+ maxTokens?: number;
346
+ /**
347
+ * Override the SDK client. Mostly for tests; production code should let the
348
+ * adapter create the client from `region` + the SDK's default credential
349
+ * chain.
350
+ */
351
+ client?: BedrockRuntimeClientLike;
352
+ }
353
+ /**
354
+ * Minimal structural type for `BedrockRuntimeClient` so we don't take a hard
355
+ * dep on `@aws-sdk/client-bedrock-runtime`.
356
+ */
357
+ interface BedrockRuntimeClientLike {
358
+ send(command: {
359
+ input: BedrockInvokeInput;
360
+ }): Promise<{
361
+ body?: AsyncIterable<{
362
+ chunk?: {
363
+ bytes?: Uint8Array;
364
+ };
365
+ }>;
366
+ }>;
367
+ }
368
+ interface BedrockInvokeInput {
369
+ modelId: string;
370
+ contentType: string;
371
+ accept: string;
372
+ body: string;
373
+ }
374
+ declare function bedrock(config: BedrockConfig): AdapterFactory;
375
+ declare const bedrockAdapter: typeof bedrock;
376
+
377
+ interface RouterCandidate {
378
+ id: string;
379
+ adapter: AdapterFactory;
380
+ /**
381
+ * Relative cost hint (lower wins for policy='cheapest'). Only
382
+ * relative values matter — use $/1M tokens or any consistent unit.
383
+ */
384
+ cost?: number;
385
+ /** Typical latency in ms. Lower wins for policy='fastest'. */
386
+ latencyMs?: number;
387
+ /**
388
+ * Capability override. Defaults to `adapter.capabilities`.
389
+ * Used to reject candidates missing required features
390
+ * (e.g. tools, multiModal).
391
+ */
392
+ capabilities?: AdapterCapabilities;
393
+ /** Free-form tags used by classifier routing (e.g. 'fast', 'coding'). */
394
+ tags?: string[];
395
+ }
396
+ type RouterPolicy = 'cheapest' | 'fastest' | 'capability-match' | ((input: {
397
+ request: AdapterRequest;
398
+ candidates: RouterCandidate[];
399
+ }) => string | Promise<string>);
400
+ interface RouterOptions {
401
+ candidates: RouterCandidate[];
402
+ /** Policy when `classify` doesn't pick a candidate. Default 'cheapest'. */
403
+ policy?: RouterPolicy;
404
+ /**
405
+ * Fast path: inspect the request, return a candidate id or tag(s).
406
+ * Return `undefined` to fall back to `policy`.
407
+ */
408
+ classify?: (request: AdapterRequest) => string | string[] | undefined;
409
+ /** Observability hook — fires once per decision. */
410
+ onRoute?: (decision: {
411
+ id: string;
412
+ reason: string;
413
+ request: AdapterRequest;
414
+ }) => void;
415
+ }
416
+ /**
417
+ * Build an AdapterFactory that picks one of N candidates per request.
418
+ *
419
+ * Resolution order:
420
+ * 1. `classify(request)` returns a candidate id → use it
421
+ * 2. `classify(request)` returns tag(s) → filter by tags, then `policy`
422
+ * 3. Fall back to `policy` over all capability-matched candidates
423
+ */
424
+ declare function createRouter(options: RouterOptions): AdapterFactory;
425
+
426
+ interface EnsembleCandidate {
427
+ id: string;
428
+ adapter: AdapterFactory;
429
+ /** Weight used by 'weighted-vote' aggregator. Default 1. */
430
+ weight?: number;
431
+ }
432
+ interface EnsembleBranchResult {
433
+ id: string;
434
+ text: string;
435
+ chunks: StreamChunk[];
436
+ error?: Error;
437
+ }
438
+ type EnsembleAggregator = 'majority-vote' | 'concat' | 'longest' | ((branches: EnsembleBranchResult[]) => string | Promise<string>);
439
+ interface EnsembleOptions {
440
+ candidates: EnsembleCandidate[];
441
+ /** How to combine branches into the single output text. Default 'majority-vote'. */
442
+ aggregate?: EnsembleAggregator;
443
+ /** Per-candidate timeout in ms. Branches that time out are marked with an error. */
444
+ timeoutMs?: number;
445
+ /** Observability hook — fires once with every branch's result. */
446
+ onBranches?: (branches: EnsembleBranchResult[]) => void;
447
+ }
448
+ /**
449
+ * Build an AdapterFactory that runs the same request against N
450
+ * candidates in parallel, then aggregates the results into a single
451
+ * text output. Unlike `speculate` (which picks a winner), `ensemble`
452
+ * combines — majority vote, concatenation, longest, or a custom fn.
453
+ *
454
+ * The returned source emits a single `{ type: 'text' }` chunk with
455
+ * the aggregated output followed by `{ type: 'done' }`, so it plugs
456
+ * into any runtime that expects a regular streaming adapter.
457
+ */
458
+ declare function createEnsembleAdapter(options: EnsembleOptions): AdapterFactory;
459
+
460
+ interface FallbackOptions {
461
+ /**
462
+ * Predicate deciding whether an error from a given adapter should
463
+ * trigger fall-through to the next. Default: always retry the next.
464
+ */
465
+ shouldRetry?: (error: Error, index: number) => boolean;
466
+ /** Observability hook — fires when one adapter fails and the chain advances. */
467
+ onFallback?: (from: {
468
+ id: string;
469
+ index: number;
470
+ error: Error;
471
+ }) => void;
472
+ }
473
+ interface FallbackCandidate {
474
+ id: string;
475
+ adapter: AdapterFactory;
476
+ }
477
+ /**
478
+ * Try adapters in order. If the first fails (throws while opening, or
479
+ * errors mid-stream before emitting any non-done chunk), fall through
480
+ * to the next. As soon as a candidate produces its first real chunk,
481
+ * that's the committed one — we don't retroactively retry mid-stream.
482
+ *
483
+ * Errors that happen *after* committing are propagated; the caller
484
+ * sees a normal streaming failure, not a mysterious cross-candidate
485
+ * retry that could duplicate tool calls.
486
+ */
487
+ declare function createFallbackAdapter(candidates: FallbackCandidate[], options?: FallbackOptions): AdapterFactory;
488
+
156
489
  type MockResponse = StreamChunk[] | ((request: AdapterRequest) => StreamChunk[]);
157
490
  interface MockAdapterOptions {
158
491
  /**
@@ -272,4 +605,4 @@ interface KimiEmbedderConfig extends OpenAICompatibleEmbedderConfig {
272
605
  }
273
606
  declare const kimiEmbedder: (config: OpenAICompatibleEmbedderConfig) => _agentskit_core.EmbedFn;
274
607
 
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 };
608
+ export { type AnthropicConfig, type AzureOpenAIConfig, type BailConfig, type BedrockConfig, type BedrockRuntimeClientLike, type CerebrasConfig, 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 ReplicateConfig, type RetryOptions, type RouterCandidate, type RouterOptions, type RouterPolicy, type TogetherConfig, type VLLMConfig, type VercelAIConfig, type VertexConfig, anthropic, azureOpenAI, azureOpenAIAdapter, bail, bailAdapter, bedrock, bedrockAdapter, cerebras, cerebrasAdapter, chunkText, cohere, cohereAdapter, createAdapter, createEnsembleAdapter, createFallbackAdapter, createOpenAICompatibleEmbedder, createRouter, deepseek, deepseekEmbedder, fetchWithRetry, fireworks, gemini, geminiEmbedder, generic, grok, grokEmbedder, groq, groqAdapter, huggingface, inMemorySink, kimi, kimiEmbedder, langchain, langgraph, llamacpp, lmstudio, mistral, mockAdapter, ollama, ollamaEmbedder, openai, openaiEmbedder, openrouter, qwen, recordingAdapter, replayAdapter, replicate, replicateAdapter, simulateStream, together, vercelAI, vertex, vertexAdapter, vllm };