@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
63 lines • 3.52 kB
TypeScript
import { type CallSettings, type Experimental_DownloadFunction, type LanguageModel, streamText } from 'ai';
import type { ModelProvider } from '../index.js';
import { type ModelCatalog } from '../spi/model-catalog.js';
/**
* Pass-through settings forwarded to the AI SDK `streamText` call (headers, temperature,
* `maxOutputTokens`, `providerOptions`, …). `model`, `instructions`, `messages`, `tools`, and
* `abortSignal` are owned by the adapter and always win over anything set here.
*/
export type AiSdkModelOptions = CallSettings & {
/**
* Override the AI SDK's file/attachment downloader (`experimental_download` on `streamText`).
* The SDK's DEFAULT downloader refuses localhost/private hostnames (SSRF guard), which breaks
* attachment parts whose staging presigns against a local object store (e.g. MinIO in dev) —
* the model call dies with `AI_DownloadError: URL with hostname localhost is not allowed`.
* Attachment URLs come from the host's own staging SPI — never from user input — so relaxing
* the guard with a plain fetch is the host's legitimate call. Pair with the ready-made
* {@link import('./attachment-fetch-downloader.js').attachmentFetchDownloader}.
*/
experimental_download?: Experimental_DownloadFunction;
/**
* Provider-specific request options (`streamText`'s `providerOptions`). For an OpenRouter model the
* adapter adds `openrouter.usage = { include: true }` (usage accounting, which is what makes
* OpenRouter report each call's cost) unless you set `openrouter.usage` yourself.
*/
providerOptions?: StreamProviderOptions;
};
/** `streamText`'s `providerOptions`, taken off its own signature (the `ai` root does not export it). */
type StreamProviderOptions = NonNullable<Parameters<typeof streamText>[0]['providerOptions']>;
export declare function aiSdkModel(model: LanguageModel, opts?: AiSdkModelOptions): ModelProvider;
/** One model `aiSdkModels` offers, with how a picker shows it. */
export interface AiSdkModelEntry {
model: LanguageModel;
label?: string;
description?: string;
badges?: string[];
contextWindow?: number;
/** The catalog group. Default: the id's `provider/` prefix, else the model's provider. */
provider?: string;
}
export interface AiSdkModelsOptions extends AiSdkModelOptions {
/** The model a turn runs on when nobody picked one. Default: the first offered. */
default?: string;
/** Display names for the catalog groups, e.g. `{ openai: 'OpenAI' }`. */
providerLabels?: Record<string, string>;
}
/** A provider that serves several models, carrying the catalog a picker lists. */
export interface AiSdkModelsProvider extends ModelProvider {
catalog: ModelCatalog;
}
/**
* Several AI SDK models behind one provider — what a model picker needs, and all it needs: the
* provider carries its catalog (`.catalog`), which `GET <path>/models` serves when `config/agent.ts`
* sets no `models`, and a turn runs on the picked id (else `default`).
*
* ```ts
* model: () => aiSdkModels({ 'openai/gpt-4o-mini': 'openai/gpt-4o-mini', 'openai/gpt-4o': { model: openai('gpt-4o'), badges: ['smart'] } }),
* ```
*/
export declare function aiSdkModels(models: Record<string, LanguageModel | AiSdkModelEntry>, options?: AiSdkModelsOptions): AiSdkModelsProvider;
/** Test seam: forget which models already warned. */
export declare function resetOpenRouterCostWarnings(): void;
export {};
//# sourceMappingURL=ai-sdk-model.d.ts.map