From 1ce7d2a2d060e16be0fd6ede1b2919f84144b7d5 Mon Sep 17 00:00:00 2001 From: Literalkrishu Date: Thu, 19 Nov 2026 03:30:27 +0530 Subject: [PATCH] feat(model-setup): Simplify model ID entry and enhance provider request handling --- README.md | 2 +- src/model-setup.js | 22 ++-------------------- src/prompt.js | 2 +- test/managed-vsix.test.js | 6 ++++-- 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 4726251..f9e7d7c 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ AgentExtension is a VS Code coding agent for local TrueForge. It can edit a sele 4. Choose one connection. - **OpenAI.** Paste an OpenAI API key with access to GPT-4.1 mini. This is the default model. [Model requirements](https://developers.openai.com/api/docs/models/gpt-4.1-mini) - - **OpenAI-compatible API.** Enter the API URL. Add a key if the provider requires one. Select a model that supports tool calls, or enter its model ID. For LM Studio or Ollama, start the local model server first. + - **OpenAI-compatible API.** Enter the API URL and the ID of a model that supports tool calls. Add a key if the provider requires one. For LM Studio or Ollama, start the local model server first. TrueForge sends the provider requests. - **Existing TrueForge server.** Enter its local URL and select one of its configured models. You can continue to use **AgentExtension: Server URL**, **Model**, and **Fallback Model** in VS Code Settings for that connection. 5. Describe a task and select **Run agent**. Review the proposed changes in VS Code. diff --git a/src/model-setup.js b/src/model-setup.js index 2f1c81b..a9d489a 100644 --- a/src/model-setup.js +++ b/src/model-setup.js @@ -12,25 +12,7 @@ function validate(fn) { }; } -async function chooseProviderModel(baseUrl, apiKey) { - // Some compatible APIs omit GET /models. In that case the user can enter the model ID. - let models = []; - try { - const response = await fetch(`${baseUrl}/models`, { - redirect: 'error', signal: AbortSignal.timeout(4_000), - headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : {}, - }); - if (response.ok) { - const { data } = await response.json(); - if (Array.isArray(data)) models = [...new Set(data.map(row => row?.id) - .filter(id => typeof id === 'string' && id.trim() && id.length <= 200))].sort(); - } - } catch { /* Offer manual entry if discovery fails. */ } - if (models.length) { - const pick = await vscode.window.showQuickPick([...models.map(label => ({ label, model: label })), { label: 'Enter model ID manually' }], - { title: 'Choose a model that supports tool calls', ignoreFocusOut: true }); - if (!pick || pick.model) return pick?.model; - } +async function enterProviderModel() { return (await vscode.window.showInputBox({ title: 'Model ID', prompt: 'Enter the model ID from your provider. Choose a chat model that supports tool calls.', ignoreFocusOut: true, validateInput: value => !value.trim() || value.trim().length > 200 ? 'Enter a model ID of up to 200 characters.' : undefined, @@ -86,7 +68,7 @@ async function configureModel(context, managed, settings, status) { (!value.trim() && choice.id === 'openai') || /[\r\n]/.test(value) ? 'Enter a valid API key.' : undefined, }); if (apiKey === undefined) return; - const modelId = choice.id === 'openai' ? OPENAI_MODEL : await chooseProviderModel(baseUrl, apiKey.trim()); + const modelId = choice.id === 'openai' ? OPENAI_MODEL : await enterProviderModel(); if (!modelId) return; const profile = { id: randomBytes(16).toString('hex'), baseUrl, apiKey: apiKey.trim(), modelId }; status('Starting bundled TrueForge…'); diff --git a/src/prompt.js b/src/prompt.js index b5ef22f..b788644 100644 --- a/src/prompt.js +++ b/src/prompt.js @@ -43,7 +43,7 @@ function composePrompt({ request, requestSource = 'Your request', selection, pla const scope = report ? `SCHEDULED READ-ONLY REPORT MODE. This run was started by a schedule, not by a person at the keyboard. Read the workspace and the listed connector targets only. Write tools are unavailable and no approval can be given during this run.\nRUN SCOPE (host data)\n${JSON.stringify(report.scope)}` : selection ? 'INLINE MODE. Only replace text within the original selection.' : planFirst ? 'PLAN FIRST MODE. Use read-only tools. Call propose_plan and wait for approval before edits or commands.' - : 'AGENT MODE. Discover the files needed to complete this task.'; + : 'AGENT MODE. Carry out the user request with the available tools. For an edit request, find the relevant files, stage the requested changes, and submit them for review.'; manifest.add('instructions', 'Run mode', scope, { trust: 'host instructions' }); manifest.add('request', requestSource, request, { trust: 'user instruction', limit: 8_000 }); const parts = [scope, `USER REQUEST\n${request}`]; diff --git a/test/managed-vsix.test.js b/test/managed-vsix.test.js index 3e7ec39..2c6f3e8 100644 --- a/test/managed-vsix.test.js +++ b/test/managed-vsix.test.js @@ -14,10 +14,11 @@ test('installed VSIX connects a model and runs from saved credentials', { skip: t.after(() => fs.rm(root, { recursive: true, force: true })); await fs.writeFile(path.join(root, 'README.md'), 'Test workspace.\n'); let calls = 0; + let providerRequests = 0; let authorization; let messages; const provider = http.createServer(async (req, res) => { - if (req.url === '/v1/models') return res.end(JSON.stringify({ data: [{ id: 'test-model' }] })); + providerRequests += 1; if (req.url !== '/v1/chat/completions') return res.writeHead(404).end(); authorization = req.headers.authorization; let body = ''; @@ -42,11 +43,12 @@ test('installed VSIX connects a model and runs from saved credentials', { skip: { kind: 'pick', value: items => items.find(item => item.id === 'custom') }, { kind: 'input', value: baseUrl }, { kind: 'input', value: 'fixture-secret' }, - { kind: 'pick', value: items => items.find(item => item.model === 'test-model') }, + { kind: 'input', value: 'test-model' }, ); await host.send({ type: 'model-settings' }); await host.waitFor(state => state.configuringModel === false, 35_000, 'model setup to finish'); assert.equal(host.state().model, 'test-model', host.state().status); + assert.equal(providerRequests, 0, 'Setup registers the model through TrueForge without querying the provider.'); assert.equal(JSON.stringify(host.states).includes('fixture-secret'), false); const stored = host.secrets.get(MODEL_SECRET); assert.equal(readProfile(stored).apiKey, 'fixture-secret');