apps/vscode/src/sdk/vscode-lm/README.md
vscode-lm)Routes Cline inference through the VS Code Language Model API
(vscode.lm), letting Cline use models contributed by any extension that
registers a language model chat provider (a vendor) with VS Code. GitHub
Copilot is the most common such vendor, but the implementation is
vendor-agnostic — it selects models via vscode.lm.selectChatModels and has no
Copilot-specific logic. VS Code only — the vscode.lm API does not exist on
other hosts (e.g. JetBrains), so the provider is gated on the API being present.
vscode-lm-handler.ts — VsCodeLmHandler, a Cline SDK ApiHandler
(@cline/llms) backed by vscode.lm. Selects a chat model, streams the
response, forwards tool definitions, and surfaces tool calls and usage.vscode-lm-format.ts — converts SDK Messages to
vscode.LanguageModelChatMessages and back-converts tool results.register-vscode-lm.ts — registers the handler with the SDK handler
registry and exposes the vscode.lm availability check used for gating.The SDK's @cline/llms handler registry (registerHandler) exists for providers
that need host-only dependencies — here, vscode.lm — which cannot live in the
host-agnostic SDK package. registerVsCodeLmHandler() (called during extension
activation) registers the factory for the vscode-lm provider id when the API is
available. The SDK then resolves vscode-lm to this handler for both the main
task loop and standalone utility calls.
ProviderConfig has no field for a VS Code LM selector, so the selected model
travels as a vendor/family[/version/id] string in ProviderConfig.modelId —
the model-id channel the rest of the SDK adapter uses. The webview stores the
structured LanguageModelChatSelector in
plan/actModeVsCodeLmModelSelector; the session factory stringifies it into
modelId, and parseVsCodeLmSelector reads it back into a selector here.
Tool definitions are passed to sendRequest via LanguageModelChatRequestOptions.tools
(with toolMode: Auto). Tool invocations arrive as LanguageModelToolCallPart
and are forwarded as tool-call chunks the SDK runtime executes.
Tool results round-trip as LanguageModelToolResultPart. Two details the VS Code
LM API requires:
ToolOperationResult { query, result, success }),
not typed text blocks; extractToolOutputText pulls their text out so the model
receives the actual output.