import { Event } from "../../../base/common/event.js"; /** * Serializable bridge contract between the node agent host (where the * {@link IByokLmProxyService} OpenAI-compatible proxy runs) and the renderer * (which owns the extension-provided BYOK language models via the LM API). * * These shapes are deliberately wire-friendly (plain JSON, no `VSBuffer`, * `URI`, or `workbench/contrib/chat` types) so they survive both the local * utility-process IPC channel and the remote JSON-RPC transport without a * translation step. The node side converts OpenAI Responses wire payloads * to/from these; the renderer side converts these to/from the VS Code * LM API (`ILanguageModelsService`). */ export interface IByokLmTextPart { readonly type: "text"; readonly text: string; } export type ByokLmImageMimeType = "image/png" | "image/jpeg" | "image/gif" | "image/webp" | "image/bmp"; export interface IByokLmImagePart { readonly type: "image"; readonly mimeType: ByokLmImageMimeType; readonly data: string; } export type IByokLmContentPart = IByokLmTextPart | IByokLmImagePart; export interface IByokLmMessageItem { readonly type: "message"; readonly role: "system" | "developer" | "user" | "assistant"; readonly content: IByokLmContentPart[]; } export interface IByokLmReasoningItem { readonly type: "reasoning"; readonly id?: string; readonly summary: string[]; readonly encryptedContent?: string; readonly metadata?: Record; } export interface IByokLmFunctionCallItem { readonly type: "function_call"; readonly callId: string; readonly name: string; readonly argumentsJson: string; } export interface IByokLmFunctionCallOutputItem { readonly type: "function_call_output"; readonly callId: string; /** Text of the tool result. */ readonly output: string; /** * The tool result's ordered text and image parts, set only when it carries * images (e.g. the `view` tool reading an image file). Supersedes * {@link output}; `output` stays populated so a renderer that predates this * field still receives the text result. */ readonly content?: IByokLmContentPart[]; } export interface IByokLmCustomToolCallItem { readonly type: "custom_tool_call"; readonly callId: string; readonly name: string; readonly input: string; } export interface IByokLmCustomToolCallOutputItem { readonly type: "custom_tool_call_output"; readonly callId: string; /** Text of the tool result. */ readonly output: string; /** Ordered text and image parts; see {@link IByokLmFunctionCallOutputItem.content}. */ readonly content?: IByokLmContentPart[]; } export type IByokLmInputItem = IByokLmMessageItem | IByokLmReasoningItem | IByokLmFunctionCallItem | IByokLmFunctionCallOutputItem | IByokLmCustomToolCallItem | IByokLmCustomToolCallOutputItem; export interface IByokLmFunctionTool { readonly type: "function"; readonly name: string; readonly description?: string; readonly parametersSchema?: object; } export interface IByokLmCustomTool { readonly type: "custom"; readonly name: string; readonly description?: string; } export type IByokLmTool = IByokLmFunctionTool | IByokLmCustomTool; export interface IByokLmChatRequest { readonly vendor: string; readonly modelId: string; readonly instructions?: string; readonly input: IByokLmInputItem[]; readonly tools?: IByokLmTool[]; readonly previousResponseId?: string; readonly reasoningEffort?: string; readonly modelOptions?: Record; } export interface IByokLmOutputMessageItem { readonly type: "message"; readonly content: IByokLmTextPart[]; } export type IByokLmOutputItem = IByokLmOutputMessageItem | IByokLmReasoningItem | IByokLmFunctionCallItem | IByokLmCustomToolCallItem; export interface IByokLmChatResult { readonly output: IByokLmOutputItem[]; /** Opaque provider state identifier. Present only when a subsequent request can resume it. */ readonly responseId?: string; readonly usage?: { readonly inputTokens?: number; readonly outputTokens?: number; readonly reasoningTokens?: number; }; readonly error?: string; } /** * Metadata for a renderer BYOK model, enumerated over the bridge so the node * agent host can advertise it to the SDK runtime without any host-side config. */ export interface IByokLmModelInfo { /** Provider/vendor name (the LM API vendor that registered the model). */ readonly vendor: string; /** Provider-local model id. */ readonly id: string; /** Display name, when the provider supplies one. */ readonly name?: string; /** * The identifier the model is registered under in the renderer's LM service — * i.e. `toModelIdentifier(vendor, group, id)` in `extHostLanguageModels` * (`//` when the user configured a provider group in * `chatLanguageModels.json`, else `/`). */ readonly modelIdentifier?: string; /** Maximum context window tokens (prompt + output), when known. */ readonly maxContextWindowTokens?: number; /** Independent maximum input tokens, when known. */ readonly maxPromptTokens?: number; /** Independent maximum output tokens, when known. */ readonly maxOutputTokens?: number; /** Whether the model accepts image inputs, when known. */ readonly supportsVision?: boolean; /** Reasoning effort values advertised by the renderer model, when known. */ readonly supportedReasoningEfforts?: readonly string[]; /** Default reasoning effort advertised by the renderer model, when known. */ readonly defaultReasoningEffort?: string; } /** * Returns the provider-local selection id used by the agent host. Configured * provider groups remain part of the id so models with the same vendor and * provider-local id do not collide. */ export declare function getByokLmSelectionModelId(model: IByokLmModelInfo): string; /** Returns the provider-qualified model id advertised by the agent host. */ export declare function getByokLmAgentModelId(model: IByokLmModelInfo): string; /** * Whether an agent model id has the BYOK shape produced by * {@link getByokLmAgentModelId} (`vendor/[group/]id`). Copilot API model ids * are single segments, so this identifies a retained BYOK selection even after * the model has left the live catalog (for example, the renderer disconnected). * * This relies on the Copilot SDK listing BYOK models under the provider-qualified * selection id `provider/id` and CAPI models under bare ids. That contract is * pinned against the bundled runtime by `copilotByokSelectionIds.integrationTest.ts`. */ export declare function isByokLmAgentModelId(modelId: string): boolean; /** Resolves BYOK enablement and trace context from synchronized root configuration. */ export declare function resolveByokLmEnablement(rootConfigValue: boolean | undefined): { readonly enabled: boolean; readonly trace: string; }; /** * Node-side connection to a single renderer's {@link IAgentHostByokLmHandler}. * Mirrors `IRemoteFilesystemConnection` for the reverse FS bridge. The renderer * pushes its models over {@link onDidChangeModels}; `chat` stays a round-trip. */ export interface IByokLmBridgeConnection { chat(request: IByokLmChatRequest): Promise; /** Emits the renderer's current BYOK model snapshot on subscribe and on every change. */ readonly onDidChangeModels: Event; }