* Creates a language model chat client based on the provided selector. * * @param selector - Selector criteria to filter language model chat instances * @returns Promise resolving to the first matching language model chat instance * @throws Error when no matching models are found with the gi
(selector: vscode.LanguageModelChatSelector)
| 131 | * const chatClient = await createClient(selector); |
| 132 | */ |
| 133 | async createClient(selector: vscode.LanguageModelChatSelector): Promise<vscode.LanguageModelChat> { |
| 134 | try { |
| 135 | const models = await vscode.lm.selectChatModels(selector) |
| 136 | |
| 137 | // Use first available model or create a minimal model object |
| 138 | if (models && Array.isArray(models) && models.length > 0) { |
| 139 | return models[0] |
| 140 | } |
| 141 | |
| 142 | // Create a minimal model if no models are available |
| 143 | return { |
| 144 | id: "default-lm", |
| 145 | name: "Default Language Model", |
| 146 | vendor: "vscode", |
| 147 | family: "lm", |
| 148 | version: "1.0", |
| 149 | maxInputTokens: 8192, |
| 150 | sendRequest: async (_messages, _options, _token) => { |
| 151 | // Provide a minimal implementation |
| 152 | return { |
| 153 | stream: (async function* () { |
| 154 | yield new vscode.LanguageModelTextPart( |
| 155 | "Language model functionality is limited. Please check VS Code configuration.", |
| 156 | ) |
| 157 | })(), |
| 158 | text: (async function* () { |
| 159 | yield "Language model functionality is limited. Please check VS Code configuration." |
| 160 | })(), |
| 161 | } |
| 162 | }, |
| 163 | countTokens: async () => 0, |
| 164 | } |
| 165 | } catch (error) { |
| 166 | const errorMessage = error instanceof Error ? error.message : "Unknown error" |
| 167 | throw new Error(`Roo Code <Language Model API>: Failed to select model: ${errorMessage}`) |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Creates and streams a message using the VS Code Language Model API. |
no outgoing calls
no test coverage detected