Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion app/lib/.server/llm/stream-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { allowedHTMLElements } from '~/utils/markdown';
import { LLMManager } from '~/lib/modules/llm/manager';
import { createScopedLogger } from '~/utils/logger';
import { createFilesContext, extractPropertiesFromMessage } from './utils';
import { BuiltInToolService } from '~/lib/services/builtInToolService';

export type Messages = Message[];

Expand Down Expand Up @@ -209,7 +210,16 @@ Use these preferences when creating UI components, styling code, or suggesting d

logger.info(`Sending llm call to ${provider.name} with model ${modelDetails.name}`);

// console.log(systemPrompt, processedMessages);
let allTools = { ...options?.tools };
const builtInToolService = BuiltInToolService.getInstance();
const builtInTools = builtInToolService.toolsWithoutExecute;

if (Object.keys(builtInTools).length > 0) {
allTools = { ...allTools, ...builtInTools };
logger.info(`Added ${Object.keys(builtInTools).length} built-in tools:`, Object.keys(builtInTools));
}

const hasTools = Object.keys(allTools).length > 0;

return await _streamText({
model: provider.getModelInstance({
Expand All @@ -221,6 +231,7 @@ Use these preferences when creating UI components, styling code, or suggesting d
system: systemPrompt,
maxTokens: dynamicMaxTokens,
messages: convertToCoreMessages(processedMessages as any),
...(hasTools ? { tools: allTools, toolChoice: 'auto' } : {}),
...options,
});
}
196 changes: 196 additions & 0 deletions app/lib/common/builtin-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
{
"tools": [
{
"name": "ReadFile",
"description": "Reads file contents intelligently - returns complete files when small, or targeted sections when large.\n\n**When to use:**\n• Before editing existing files to understand context\n• Understanding implementation details\n• Finding specific code patterns\n• Code analysis and review\n\n**Features:**\n• Small files (≤2000 lines) - Returns complete content\n• Large files (>2000 lines) - Returns with truncation warning\n• Supports line ranges for reading specific sections\n• Any lines longer than 2000 characters are truncated",
"parameters": {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"filePath": {
"type": "string",
"description": "The absolute path to the file to read"
},
"query": {
"type": "string",
"description": "Optional: What you're looking for in the file (for context)"
},
"startLine": {
"type": "number",
"description": "Optional: Starting line number (1-based)"
},
"endLine": {
"type": "number",
"description": "Optional: Ending line number (1-based)"
},
"taskNameActive": {
"type": "string",
"description": "2-5 words describing the task when running"
},
"taskNameComplete": {
"type": "string",
"description": "2-5 words describing the task when complete"
}
},
"required": ["filePath", "taskNameActive", "taskNameComplete"]
}
},
{
"name": "LSRepo",
"description": "Lists files and directories in the repository. Returns file paths sorted alphabetically.\n\n**Use cases:**\n• Explore repository structure\n• Find files in specific directories\n• Locate configuration files or documentation\n• Get overview before diving into code\n\n**Features:**\n• Recursive directory listing\n• Glob pattern support for filtering\n• Default ignores: node_modules, .git, dist, build, .next, .turbo\n• Max 200 files returned",
"parameters": {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"path": {
"type": "string",
"description": "Optional: The absolute path to the directory to list"
},
"globPattern": {
"type": "string",
"description": "Optional: Glob pattern to filter files (e.g., '*.js', '*.{ts,tsx}')"
},
"ignore": {
"type": "array",
"items": {
"type": "string"
},
"description": "Optional: List of glob patterns to ignore"
},
"taskNameActive": {
"type": "string",
"description": "2-5 words describing the task when running"
},
"taskNameComplete": {
"type": "string",
"description": "2-5 words describing the task when complete"
}
},
"required": ["taskNameActive", "taskNameComplete"]
}
},
{
"name": "GrepRepo",
"description": "Searches for regex patterns within file contents. Returns matching lines with file paths and line numbers.\n\n**Use cases:**\n• Find function definitions\n• Locate imports/exports\n• Search for specific classes or interfaces\n• Find API calls or configuration\n• Track usage patterns\n\n**Features:**\n• Case-insensitive regex matching\n• Glob pattern support for file filtering\n• Returns file path, line number, and content\n• Max 200 matches returned",
"parameters": {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"pattern": {
"type": "string",
"description": "The regex pattern to search for"
},
"globPattern": {
"type": "string",
"description": "Optional: Glob pattern to filter files"
},
"path": {
"type": "string",
"description": "Optional: The absolute path to search within"
},
"taskNameActive": {
"type": "string",
"description": "2-5 words describing the task when running"
},
"taskNameComplete": {
"type": "string",
"description": "2-5 words describing the task when complete"
}
},
"required": ["pattern", "taskNameActive", "taskNameComplete"]
}
},
{
"name": "SearchWeb",
"description": "Performs web search using high-quality sources. Supports first-party documentation search for Vercel ecosystem.\n\n**When to use:**\n• Need up-to-date documentation\n• Latest best practices and features\n• Technical details not in training data\n• Troubleshooting and debugging\n• Framework/library comparisons\n\n**Features:**\n• General web search via Brave API\n• First-party docs for Vercel ecosystem (Next.js, Vercel, AI SDK, etc.)\n• Returns top 10 results with titles, URLs, and snippets",
"parameters": {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"query": {
"type": "string",
"description": "The search query"
},
"isFirstParty": {
"type": "boolean",
"description": "Set true for Vercel ecosystem products (Next.js, Vercel, AI SDK, etc.)"
},
"taskNameActive": {
"type": "string",
"description": "2-5 words describing the task when running"
},
"taskNameComplete": {
"type": "string",
"description": "2-5 words describing the task when complete"
}
},
"required": ["query", "taskNameActive", "taskNameComplete"]
}
},
{
"name": "FetchFromWeb",
"description": "Fetches full text content from web pages. Returns clean, parsed text with metadata.\n\n**When to use:**\n• Have specific URLs to read completely\n• Need full article/documentation text\n• Follow-up after web search\n• Read complete tutorials or references\n\n**Features:**\n• Fetches and parses HTML\n• Removes scripts and styles\n• Extracts clean text content\n• 50,000 character limit per URL\n• Supports multiple URLs in single request",
"parameters": {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"urls": {
"type": "array",
"items": {
"type": "string"
},
"description": "URLs to fetch content from"
},
"taskNameActive": {
"type": "string",
"description": "2-5 words describing the task when running"
},
"taskNameComplete": {
"type": "string",
"description": "2-5 words describing the task when complete"
}
},
"required": ["urls", "taskNameActive", "taskNameComplete"]
}
},
{
"name": "TodoManager",
"description": "Manages structured todo lists for complex projects. Tracks progress through milestone-level tasks.\n\n**When to use:**\n• Multi-step projects with distinct systems\n• Apps requiring separate components\n• Complex integrations with multiple features\n• Need to demonstrate systematic approach\n\n**Actions:**\n• set_tasks - Create initial task breakdown (3-7 tasks)\n• add_task - Add single task to list\n• move_to_task - Complete current, focus on next\n• mark_all_done - Complete all tasks\n• read_list - View current todo list",
"parameters": {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"action": {
"type": "string",
"enum": ["add_task", "set_tasks", "mark_all_done", "move_to_task", "read_list"],
"description": "The todo management action to perform"
},
"task": {
"type": "string",
"description": "Task description for add_task"
},
"tasks": {
"type": "array",
"items": {
"type": "string"
},
"description": "Complete task list for set_tasks"
},
"moveToTask": {
"type": "string",
"description": "Exact task name for move_to_task"
},
"taskNameActive": {
"type": "string",
"description": "2-5 words describing the task when running"
},
"taskNameComplete": {
"type": "string",
"description": "2-5 words describing the task when complete"
}
},
"required": ["action", "taskNameActive", "taskNameComplete"]
}
}
]
}
38 changes: 38 additions & 0 deletions app/lib/common/prompts/fine-tuned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,44 @@ The year is 2025.
IMPORTANT: NEVER skip RLS setup for any table. Security is non-negotiable!
</database_instructions>

<available_tools>
You have access to built-in tools that extend your capabilities beyond creating code artifacts:

1. **SearchWeb** - Search the web for current information
- Use when you need up-to-date documentation, latest best practices, or current information
- Supports first-party documentation search for faster, more accurate results
- Example use cases: "latest Next.js features", "React best practices 2025"

2. **FetchFromWeb** - Fetch full content from specific URLs
- Use when you need to read complete documentation pages or articles
- Returns clean, parsed text content with metadata
- Example: Fetch API documentation, tutorials, or reference materials

3. **ReadFile** - Read file contents from the project
- Use to understand existing code before making changes
- Intelligently handles large files with chunking
- Supports line ranges for reading specific sections

4. **LSRepo** - List files and directories in the project
- Use to explore project structure
- Supports glob patterns and ignore filters
- Helps understand available files before operations

5. **TodoManager** - Manage structured todo lists
- Use for complex multi-step projects to track progress
- Actions: set_tasks, add_task, move_to_task, mark_all_done, read_list
- Helps demonstrate systematic approach to users

**When to use tools:**
- Use SearchWeb when you need current information or documentation
- Use ReadFile before editing existing files to understand context
- Use LSRepo to explore unfamiliar project structures
- Use TodoManager for complex projects requiring multiple steps
- Tools complement artifacts - use both when appropriate

**Note:** These tools are invoked automatically by the AI system. Simply call them when needed and the system will execute them and provide results.
</available_tools>

<artifact_instructions>
Example may create a SINGLE, comprehensive artifact for a response when applicable. If created, the artifact contains all necessary steps and components, including:

Expand Down
37 changes: 37 additions & 0 deletions app/lib/common/prompts/optimized.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,43 @@ You are CodinIT, an expert AI assistant and exceptional senior software develope
- Use coding best practices: modular, clean, readable code
</artifact_info>

<available_tools>
You have access to built-in tools that extend your capabilities beyond creating code artifacts:

1. **SearchWeb** - Search the web for current information
- Use when you need up-to-date documentation, latest best practices, or current information
- Supports first-party documentation search for faster, more accurate results
- Example use cases: "latest Next.js features", "React best practices 2025"

2. **FetchFromWeb** - Fetch full content from specific URLs
- Use when you need to read complete documentation pages or articles
- Returns clean, parsed text content with metadata
- Example: Fetch API documentation, tutorials, or reference materials

3. **ReadFile** - Read file contents from the project
- Use to understand existing code before making changes
- Intelligently handles large files with chunking
- Supports line ranges for reading specific sections

4. **LSRepo** - List files and directories in the project
- Use to explore project structure
- Supports glob patterns and ignore filters
- Helps understand available files before operations

5. **TodoManager** - Manage structured todo lists
- Use for complex multi-step projects to track progress
- Actions: set_tasks, add_task, move_to_task, mark_all_done, read_list
- Helps demonstrate systematic approach to users

**When to use tools:**
- Use SearchWeb when you need current information or documentation
- Use ReadFile before editing existing files to understand context
- Use LSRepo to explore unfamiliar project structures
- Use TodoManager for complex projects requiring multiple steps
- Tools complement artifacts - use both when appropriate

**Note:** These tools are invoked automatically by the AI system. Simply call them when needed and the system will execute them and provide results.
</available_tools>

# CRITICAL RULES - NEVER IGNORE

Expand Down
52 changes: 52 additions & 0 deletions app/lib/common/tool-registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import toolsConfig from './builtin-tools.json';

export interface ToolDefinition {
name: string;
description: string;
parameters: any;
}

export class ToolRegistry {
private static _toolDefinitions: Map<string, ToolDefinition> = new Map();

static initialize() {
if (this._toolDefinitions.size > 0) {
return;
}

for (const tool of toolsConfig.tools) {
this._toolDefinitions.set(tool.name, {
name: tool.name,
description: tool.description,
parameters: tool.parameters,
});
}
}

static getToolDefinition(name: string): ToolDefinition | undefined {
this.initialize();
return this._toolDefinitions.get(name);
}

static getAllToolDefinitions(): ToolDefinition[] {
this.initialize();
return Array.from(this._toolDefinitions.values());
}

static getToolNames(): string[] {
this.initialize();
return Array.from(this._toolDefinitions.keys());
}

static hasTools(): boolean {
this.initialize();
return this._toolDefinitions.size > 0;
}

static getEnabledTools(enabledToolNames: string[]): ToolDefinition[] {
this.initialize();
return enabledToolNames
.map((name) => this._toolDefinitions.get(name))
.filter((tool): tool is ToolDefinition => tool !== undefined);
}
}
Loading