LLM Provider Integration
Relevant source files
The following files were used as context for generating this wiki page:
The LLM Provider Integration system serves as the core intelligence layer for the bl1nk platform, enabling seamless communication between the application and various Large Language Model (LLM) providers. This system is designed to handle multi-provider support, specifically integrating services like AWS Bedrock and OpenRouter to facilitate AI-driven skill development, real-time code modifications, and interactive developer assistance.
The integration architecture follows a monorepo structure where the frontend (Electron + Next.js) interacts with a backend (tRPC + Express) to manage credentials, route requests, and process AI responses. It supports a variety of operational modes, including "Build" for active coding, "Ask" for technical guidance, and "Agent" for information gathering and research.
Sources: Comprehensive.md:37-41, apps/client/src/prompts/system_prompt.ts:258-278, specs/main/plan.md:14-17
Architecture and Core Components
The LLM integration is structured to ensure end-to-end type safety and modularity within a pnpm monorepo. The system relies on a central service layer to abstract provider-specific logic, allowing the rest of the application to interact with a unified interface for AI operations.
Key Components
| Component | Responsibility | Relevant Files |
|---|---|---|
| Claude Service | Handles core AI integration logic and communication with Claude models. | claude-service.ts |
| Credential Router | Manages provider credentials, encryption of API keys, and authentication testing. | credential.router.ts |
| System Prompts | Defines the operational constraints, roles (e.g., bl1nk AI editor), and behaviors for the LLM. | system_prompt.ts |
| Skill Router | Facilitates AI-driven CRUD operations and versioning for developed skills. | skill.router.ts |
Sources: Comprehensive.md:52-56, Comprehensive.md:214-216, apps/client/src/prompts/system_prompt.ts:50-60
Multi-Provider Orchestration
The platform integrates multiple AI backends to provide flexibility and redundancy. Primary integrations include AWS Bedrock for enterprise-grade Claude access and OpenRouter for broader model availability.
The diagram above illustrates the data flow from the user interface through the tRPC backend to the external LLM providers.
Sources: Comprehensive.md:37-41, Comprehensive.md:52-56, apps/client/src/prompts/system_prompt.ts:258-278
Operational Modes and Prompt Engineering
The integration utilizes specialized system prompts to toggle between different functional "modes." This ensures the LLM behaves appropriately based on whether the user needs code changes, technical explanations, or autonomous research.
Chat Mode Configurations
- Build Mode: The default mode where the LLM acts as "bl1nk," an AI editor capable of writing, renaming, and deleting files using specific XML-like tags (e.g.,
<bl1nk-write>). - Ask Mode: A strictly non-coding mode focused on educational guidance and conceptual explanations. The system prompt enforces an ABSOLUTE PRIMARY DIRECTIVE prohibiting code generation.
- Agent Mode: A specialized research mode used to analyze requirements and gather information from external APIs or documentation before the implementation phase begins.
Sources: apps/client/src/prompts/system_prompt.ts:50-58, apps/client/src/prompts/system_prompt.ts:187-200, apps/client/src/prompts/system_prompt.ts:233-245
Prompt Construction Logic
Prompts are constructed dynamically by merging base role definitions, operational guidelines, and project-specific AI_RULES.md files. This allows the LLM to understand the specific tech stack (e.g., React, TypeScript, Tailwind) of the application being built.
export const constructSystemPrompt = ({
aiRules,
chatMode = "build",
enableTurboEditsV2,
}: {
aiRules: string | undefined;
chatMode?: "build" | "ask" | "agent";
enableTurboEditsV2: boolean;
}) => {
const systemPrompt = getSystemPromptForChatMode({
chatMode,
enableTurboEditsV2,
});
return systemPrompt.replace("[[AI_RULES]]", aiRules ?? DEFAULT_AI_RULES);
};
Sources: apps/client/src/prompts/system_prompt.ts:258-278, apps/client/src/prompts/system_prompt.ts:289-304
Data Persistence and Security
The LLM integration interacts with the database to persist AI-generated artifacts and secure sensitive access tokens.
Security Strategy
- Encryption: API credentials for providers (AWS, OpenRouter) are encrypted before storage.
- Ephemeral Data: Test messages used for LLM validation are treated as ephemeral and stored separately from core skill versions.
- Context Management: System prompts include a "Thinking Process" block (using
<think>tags) to ensure the LLM plans architecture and identifies potential bugs before executing changes, reducing security risks from hallucinated code.
Sources: Comprehensive.md:46-50, Comprehensive.md:128, apps/client/src/prompts/system_prompt.ts:7-15
Data Model for Integration
The ER diagram displays the relationship between skills, their AI-generated versions, and the credentials required to call the LLM providers.
Sources: Comprehensive.md:46-50, specs/main/plan.md:113-120
Implementation Workflow (Spec-Driven Development)
The platform utilizes a structured "Spec-Kit" or "Kiro" workflow to guide the LLM through feature development. This workflow is phase-based and ensures that the LLM does not skip critical planning steps.
| Phase | Description | Goal |
|---|---|---|
| Constitution | Establish governing principles and technical standards. | Set foundational rules. |
| Specify | Define functional requirements without technical implementation details. | Alignment on "What". |
| Design | Create architecture, data models, and component interfaces. | Alignment on "How". |
| Tasks | Generate an actionable, test-driven checklist for implementation. | Actionable plan. |
Sources: plugins/kiro-skill/skills/kiro-skill/SKILL.md:17-25, plugins/kiro-skill/skills/kiro-skill/SKILL.md:44-55
Summary
The LLM Provider Integration in bl1nk is a robust, multi-provider system that powers the application's AI capabilities through AWS Bedrock and OpenRouter. By employing strict prompt engineering across different operational modes (Build, Ask, Agent) and enforcing a disciplined spec-driven development workflow (Requirements -> Design -> Tasks), the integration ensures high-quality, type-safe, and secure AI-assisted software engineering. The architecture maintains a clear separation between client-side interactions and server-side credential management, facilitating a professional development environment for AI skills.