import { SharedProviderMetadata } from "../provider/index.js"; import { LanguageModelResponseItem } from "./item.js"; import { LanguageModelRequest } from "./request.js"; import { LanguageModelStreamEvent } from "./stream.js"; /** * Defines the standard interface for language model providers in kernl. */ export interface LanguageModel { /** * The language model must specify which language model interface version it implements. */ readonly spec: "1.0"; /** * Provider ID. */ readonly provider: string; /** * Provider-specific model ID. */ readonly modelId: string; /** * Get a response from the model. * * @param request - The request to get a response for. */ generate(request: LanguageModelRequest): Promise; /** * Get a streamed response from the model. * * @param request - The request to get a response for. */ stream(request: LanguageModelRequest): AsyncIterable; } /** * The base response interface for a language model. */ export interface LanguageModelResponse { /** * The ordered list of content items generated by the model. */ content: LanguageModelResponseItem[]; /** * Finish reason. */ finishReason: LanguageModelFinishReason; /** * The usage information for response. */ usage: LanguageModelUsage; /** * Warnings for the call, e.g. unsupported settings. */ warnings: SharedWarning[]; /** * Raw response data from the underlying model provider. */ providerMetadata?: SharedProviderMetadata; } /** * Reason why a language model finished generating a response. */ export interface LanguageModelFinishReason { /** * Unified finish reason across providers. * * - `stop`: model generated stop sequence * - `length`: model generated maximum number of tokens * - `content-filter`: content filter violation stopped the model * - `tool-calls`: model triggered tool calls * - `error`: model stopped because of an error * - `other`: model stopped for other reasons */ unified: "stop" | "length" | "content-filter" | "tool-calls" | "error" | "other"; /** * Raw finish reason from the provider. */ raw: string | undefined; } /** * Usage information for a language model call. * * If your API return additional usage information, you can add it to the * provider metadata under your provider's key. */ export interface LanguageModelUsage { /** * Input token usage breakdown. */ inputTokens: { /** * Total input tokens used. */ total: number | undefined; /** * Input tokens that were not cached. */ noCache: number | undefined; /** * Input tokens read from cache. */ cacheRead: number | undefined; /** * Input tokens written to cache. */ cacheWrite: number | undefined; }; /** * Output token usage breakdown. */ outputTokens: { /** * Total output tokens used. */ total: number | undefined; /** * Text generation tokens. */ text: number | undefined; /** * Reasoning/thinking tokens. */ reasoning: number | undefined; }; } /** * Warning from the model provider for this call. The call will proceed, but e.g. * some settings might not be supported, which can lead to suboptimal results. */ export type SharedWarning = { /** * A feature is not supported by the model. */ type: "unsupported"; /** * The feature that is not supported. */ feature: string; /** * Additional details about the warning. */ details?: string; } | { /** * A compatibility feature is used that might lead to suboptimal results. */ type: "compatibility"; /** * The feature that is used in compatibility mode. */ feature: string; /** * Additional details about the warning. */ details?: string; } | { /** * Other warning. */ type: "other"; /** * The message of the warning. */ message: string; }; //# sourceMappingURL=model.d.ts.map