A new reusable package called prompt-library has been created to manage custom prompts with localStorage persistence. This package is now integrated into the ByteChat browser extension's Agent Chat feature.
Location: /Users/sauravverma/programs/bytebellpackages/prompt-library/
prompt-library/
├── src/
│ ├── index.ts # Main exports
│ ├── types.ts # TypeScript interfaces
│ ├── PromptLibrary.ts # Core storage & CRUD operations
│ ├── components/
│ │ ├── PromptSelector.tsx # Dropdown UI component
│ │ └── PromptManager.tsx # Create/Edit modal component
│ └── hooks/
│ └── usePromptLibrary.ts # React hook for state management
├── package.json
├── tsconfig.json
└── README.md
Static class that handles all CRUD operations with localStorage:
loadAll()- Load all saved promptscreate(input)- Create a new promptgetById(id)- Get a specific promptupdate(id, input)- Update an existing promptdelete(id)- Delete a promptsearch(query)- Search prompts by name or contentcount()- Get total number of promptsclearAll()- Delete all prompts
interface CustomPrompt {
id: string; // Unique identifier
name: string; // Display name
prompt: string; // The actual prompt text
createdAt: number; // Timestamp
updatedAt: number; // Timestamp
}
interface PromptInput {
name: string; // Prompt name
prompt: string; // Prompt text
}A dropdown component that shows:
- "None (Default behavior)" option
- List of all saved prompts
- "+ Create New Prompt" option
- Edit button (appears when a prompt is selected)
A modal dialog for creating/editing prompts with:
- Two simple fields: Name and Prompt Text
- Preview section showing how the prompt will look
- Save, Cancel, and Delete buttons
- Input validation
usePromptLibrary() - Provides state management:
const {
prompts, // Array of all prompts
loading, // Loading state
error, // Error message
createPrompt, // Function to create
updatePrompt, // Function to update
deletePrompt, // Function to delete
getPrompt, // Function to get by ID
searchPrompts, // Function to search
refresh // Function to reload
} = usePromptLibrary();File: bytechat-browser-agent/src/conversational/ConversationalAgent.ts
Changes made:
- Added
customPrompt?: stringtoAgentConfiginterface - Modified
sendMessage()to prepend custom prompt before processing - Added
setCustomPrompt(prompt)method to update prompt dynamically - Added
getCustomPrompt()method to retrieve current prompt
How it works:
// When a custom prompt is set:
const processedInput = this.config.customPrompt
? `${this.config.customPrompt}\n\nUser: ${userInput}`
: userInput;
// This processed input is sent to the LLMFile: ByteChat/src/components/AgentChat.tsx
Changes made:
- Added prompt library imports
- Added state for prompt management:
selectedPromptId- Currently selected promptisPromptModalOpen- Modal visibilityeditingPrompt- Prompt being edited
- Added
usePromptLibrary()hook - Added effect to update agent when prompt selection changes
- Added handler functions for prompt CRUD operations
- Added UI components:
<PromptSelector />above the message input<PromptManager />modal for creating/editing
- Click the "Custom Prompt" dropdown in Agent Chat
- Select "+ Create New Prompt"
- Enter a name (e.g., "Code Review Assistant")
- Enter the detailed prompt text
- Preview shows how it will be formatted
- Click "Create Prompt"
- Select a prompt from the "Custom Prompt" dropdown
- The prompt is automatically applied to the agent
- All subsequent messages will be prepended with this prompt
- Format:
{custom_prompt}\n\nUser: {user_message}
- Select a prompt from the dropdown
- Click the edit (pencil) icon that appears
- Modify the name or prompt text
- Click "Update Prompt"
- Edit a prompt (as above)
- Click "Delete Prompt" button
- Confirm the deletion
Location: Browser's localStorage
Key: prompt-library-v1
Format: JSON array of CustomPrompt objects
Example:
[
{
"id": "prompt_1729692000000_abc123",
"name": "Code Review Assistant",
"prompt": "You are an expert code reviewer. Focus on security, performance, and best practices.",
"createdAt": 1729692000000,
"updatedAt": 1729692000000
}
]- ByteChat package.json:
"prompt-library": "file:../prompt-library"
- Build prompt-library:
npm run build(in prompt-library directory) - Build bytechat-browser-agent:
npm run build(in bytechat-browser-agent directory) - Install in ByteChat:
npm install(in ByteChat directory) - Build ByteChat:
npm run build
The prompt-library package exports:
PromptLibrary- Core classCustomPrompt,PromptInput,PromptOperationResult- TypesPromptSelector- React componentPromptManager- React componentusePromptLibrary- React hookSTORAGE_KEY- Constant
- Reusability: The prompt-library package can be used in any React application
- Type Safety: Full TypeScript support with interfaces
- Persistence: Prompts are saved in localStorage and survive browser restarts
- User-Friendly: Simple two-field interface (name + prompt)
- Validation: Input validation prevents empty or duplicate names
- Preview: Users can see how their prompt will be formatted
- Flexibility: Prompts can be created, edited, deleted, and toggled on/off
Name: Code Review Assistant
Prompt: You are an expert code reviewer. Please focus on:
- Security vulnerabilities
- Performance issues
- Code quality and best practices
- Potential bugs
Provide constructive feedback with specific suggestions.
Name: Technical Documentation
Prompt: You are a technical writer. When explaining concepts:
- Use clear, concise language
- Include practical examples
- Break down complex topics
- Focus on clarity over brevity
Name: Friendly Helper
Prompt: You are a friendly and encouraging assistant. Be:
- Patient and understanding
- Enthusiastic about helping
- Clear in your explanations
- Supportive when users struggle
- Import/Export: Allow users to export/import prompt collections
- Categories/Tags: Organize prompts by category
- Sharing: Share prompts between team members
- Variables: Support template variables in prompts (e.g.,
{{username}}) - History: Track prompt usage statistics
- Cloud Sync: Sync prompts across devices
- Marketplace: Community-shared prompt library
To test the implementation:
- Navigate to the Agent Chat tab in ByteChat
- Look for the "Custom Prompt" dropdown above the message input
- Click "+ Create New Prompt"
- Create a test prompt (e.g., "Be concise and direct")
- Select the prompt from the dropdown
- Send a message - it will be prepended with your custom prompt
- Check the console logs to verify the prompt is being applied
prompt-library/src/index.tsprompt-library/src/types.tsprompt-library/src/PromptLibrary.tsprompt-library/src/components/PromptSelector.tsxprompt-library/src/components/PromptManager.tsxprompt-library/src/hooks/usePromptLibrary.tsprompt-library/package.jsonprompt-library/tsconfig.jsonprompt-library/README.md
bytechat-browser-agent/src/conversational/ConversationalAgent.tsByteChat/src/components/AgentChat.tsxByteChat/package.json
The prompt library package is now fully functional and integrated into the ByteChat extension. Users can create, edit, and manage custom prompts that will be automatically prepended to their messages when sending to the OpenRouter LLM. The implementation is clean, reusable, and follows React best practices with TypeScript for type safety.