From f42ca5897a4299303a725b5a34f407d24040d2a1 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 8 Dec 2025 13:44:01 -0600 Subject: [PATCH] Expose model and provider to system prompt --- src/components/ModelInput.test.tsx | 2 +- src/lib/SessionManager.ts | 14 +++++ src/lib/system.test.ts | 70 ++++++++++++++++++++++++ src/lib/system.ts | 20 ++++++- src/lib/tools/ViewAvailableModelsTool.ts | 2 +- 5 files changed, 104 insertions(+), 4 deletions(-) diff --git a/src/components/ModelInput.test.tsx b/src/components/ModelInput.test.tsx index 1ec141af..03ad645a 100644 --- a/src/components/ModelInput.test.tsx +++ b/src/components/ModelInput.test.tsx @@ -68,7 +68,7 @@ describe('ModelInput', () => { it('accepts modelFilter prop', () => { const onChange = vi.fn(); - const modelFilter = (model: { modalities?: string[] }) => model.modalities?.includes('image'); + const modelFilter = (model: { modalities?: string[] }) => model.modalities?.includes('image') ?? false; render( { cwd: '/projects/test-project', config: testConfig, defaultConfig: testConfig, + model: { + id: 'gpt-4', + fullId: 'openai/gpt-4', + }, + provider: { + id: 'openai', + name: 'OpenAI', + baseURL: 'https://api.openai.com/v1', + }, }; // Mock getAllSkills to return empty array by default @@ -607,4 +616,65 @@ Skills: {{ skills.length }}`; expect(result).not.toContain('**(CURRENT TEMPLATE)**'); }); }); + + describe('model and provider information', () => { + it('should include model and provider information in the system prompt', async () => { + const result = await makeSystemPrompt(baseOpts); + + expect(result).toContain('**AI Model**: openai/gpt-4 (OpenAI)'); + }); + + it('should include model information with different provider', async () => { + const model = { + id: 'claude-3-opus', + fullId: 'anthropic/claude-3-opus', + }; + + const provider = { + id: 'anthropic', + name: 'Anthropic', + baseURL: 'https://api.anthropic.com/v1', + }; + + const result = await makeSystemPrompt({ + ...baseOpts, + model, + provider, + }); + + expect(result).toContain('**AI Model**: anthropic/claude-3-opus (Anthropic)'); + }); + + it('should make model and provider objects accessible in custom templates', async () => { + const model = { + id: 'claude-3-opus', + fullId: 'anthropic/claude-3-opus', + }; + + const provider = { + id: 'anthropic', + name: 'Anthropic', + baseURL: 'https://api.anthropic.com/v1', + }; + + const customTemplate = `Model ID: {{ model.id }} +Model Full ID: {{ model.fullId }} +Provider Name: {{ provider.name }} +Provider ID: {{ provider.id }} +Provider Base URL: {{ provider.baseURL }}`; + + const result = await makeSystemPrompt({ + ...baseOpts, + model, + provider, + template: customTemplate, + }); + + expect(result).toContain('Model ID: claude-3-opus'); + expect(result).toContain('Model Full ID: anthropic/claude-3-opus'); + expect(result).toContain('Provider Name: Anthropic'); + expect(result).toContain('Provider ID: anthropic'); + expect(result).toContain('Provider Base URL: https://api.anthropic.com/v1'); + }); + }); }); diff --git a/src/lib/system.ts b/src/lib/system.ts index 162b8eaf..cefc0415 100644 --- a/src/lib/system.ts +++ b/src/lib/system.ts @@ -8,6 +8,17 @@ import { JSRuntimeFS } from "./JSRuntime"; import { getAllSkills } from "./plugins"; import type { AppConfig } from "@/contexts/AppContext"; +export interface ModelInfo { + id: string; + fullId: string; +} + +export interface ProviderInfo { + id: string; + name: string; + baseURL: string; +} + export interface MakeSystemPromptOpts { tools: OpenAI.Chat.Completions.ChatCompletionTool[]; mode: "init" | "agent"; @@ -20,6 +31,8 @@ export interface MakeSystemPromptOpts { repositoryUrl?: string; template?: string; projectTemplate?: { name: string; description: string; url: string }; + model: ModelInfo; + provider: ProviderInfo; } /** @@ -32,6 +45,7 @@ export const defaultSystemPrompt = `{% if mode === "init" %}You are Shakespeare, You are operating within **Shakespeare**, an AI-powered website builder that allows users to create custom applications through natural language conversation. +- **AI Model**: {{ model.fullId }} - **Current Date**: {{ date }} - **Current Page**: {{ location.href }} - **Current Working Directory**: {{ cwd }} @@ -170,7 +184,7 @@ When a project is first created, you (the AI) choose an appropriate template fro Shakespeare supports AI-powered image generation. Users can configure an image model in **Settings > AI** under the "Advanced" section. **Important Notes:** -- Models that support image generation can use either the chat completions endpoint (for models with "image" output modality) or the dedicated images generation endpoint +- Not all models support image generation - If users experience issues with image generation, they should try selecting a different image model in Settings > AI - Recommended models include gpt-image-1 and gemini-3-pro-image - The generate_image tool will only be available once a compatible image model is configured @@ -236,7 +250,7 @@ Note: the badge should be displayed at its natural size. It is recommended to om {{ AGENTS }}{% endif %}`; export async function makeSystemPrompt(opts: MakeSystemPromptOpts): Promise { - const { tools, mode, fs, cwd, config, defaultConfig, user, metadata, repositoryUrl, template, projectTemplate } = opts; + const { tools, mode, fs, cwd, config, defaultConfig, user, metadata, repositoryUrl, template, projectTemplate, model, provider } = opts; // Add current date const date = new Date().toLocaleDateString("en-US", { @@ -318,6 +332,8 @@ export async function makeSystemPrompt(opts: MakeSystemPromptOpts): Promise> { - readonly description = 'View all available AI models across all configured providers, including their capabilities. This tool MUST be called before attempting to configure an image model, as it shows which models support image generation and displays the currently configured model (if any) to understand user preferences.'; + readonly description = 'View all available AI models across all configured providers, including their capabilities. This tool MUST be called before attempting to configure an image model, as it shows which models support image generation.'; readonly inputSchema = z.object({});