π§ theia Knowledge Base Integration Guide
This guide walks you through integrating the Knowledge Base extension into your theia-based IDE.
Table of Contentsβ
- Prerequisites
- Quick Integration (3 Steps)
- Detailed Setup
- Configuration
- Usage
- Troubleshooting
- Development
- Architecture
Prerequisitesβ
- theia Application: Existing theia IDE (v1.45+)
- Node.js: v18 or higher
- Python: 3.8+ (for KB backend)
- Knowledge Base API: Running on port 5175
Quick Integration (3 Steps)β
1οΈβ£ Add Extension to Dependenciesβ
In your theia application's package.json:
{
"dependencies": {
"@theia/core": "latest",
"@theia/navigator": "latest",
"@theia/monaco": "latest",
"@theia/messages": "latest",
"@coditect/theia-kb-extension": "file:../theia-kb-extension"
}
}
2οΈβ£ Install and Buildβ
# From your theia app directory
npm install
npm run build
3οΈβ£ Start Servicesβ
# terminal 1: Start KB API
cd knowledge-base-ui
npm run server
# terminal 2: Start theia
cd ../your-theia-app
npm start
β Access via: View β Knowledge Base
Detailed Setupβ
Step 1: Verify Extension is Builtβ
cd theia-kb-extension
ls lib/browser/ # Should see compiled .js files
# If not built:
npm install
npm run build
Step 2: Link Extension (Development)β
For development, you can use npm link:
# In theia-kb-extension directory
npm link
# In your theia app directory
npm link @coditect/theia-kb-extension
Step 3: Configure theia Applicationβ
Update package.json:β
{
"name": "your-theia-app",
"dependencies": {
"@coditect/theia-kb-extension": "file:../theia-kb-extension"
},
"theiaExtensions": [
"@coditect/theia-kb-extension"
]
}
Ensure Required theia Extensions:β
{
"dependencies": {
"@theia/core": "latest",
"@theia/navigator": "latest",
"@theia/workspace": "latest",
"@theia/monaco": "latest",
"@theia/messages": "latest",
"@theia/scm": "latest",
"@theia/editor": "latest"
}
}
Step 4: Build theia Applicationβ
# Clean build
npm run clean
npm install
npm run build
# Or if using yarn
yarn clean
yarn install
yarn build
Step 5: Configure API Endpoint (Optional)β
If KB API runs on a different host/port, create .theia/settings.json:
{
"coditect.knowledgeBase.apiUrl": "http://localhost:5175/api",
"coditect.knowledgeBase.timeout": 30000
}
Configurationβ
Environment Variablesβ
# .env file in theia app root
KB_API_URL=http://localhost:5175/api
KB_API_TIMEOUT=30000
theia Preferencesβ
Access via: File β Preferences β Settings β Extensions β Knowledge Base
| Setting | Description | Default |
|---|---|---|
apiUrl | Knowledge Base API endpoint | http://localhost:5175/api |
timeout | API request timeout (ms) | 30000 |
defaultLimit | Default search result limit | 20 |
minRelevance | Minimum relevance threshold | 0.7 |
workspace Settingsβ
Create .theia/settings.json in your workspace:
{
"coditect.knowledgeBase": {
"apiUrl": "http://localhost:5175/api",
"defaultCategories": ["debugging", "frontend"],
"autoSearch": true,
"searchOnSelection": true
}
}
Usageβ
1. Opening Knowledge Base Viewβ
Via Menu:
- View β Knowledge Base
Via Command Palette:
Ctrl/Cmd + Shift + P- Type: "Knowledge Base: Show"
Via Keyboard Shortcut (if configured):
Ctrl/Cmd + K, K
2. Searchingβ
Quick Search (Side Panel)β
- Click on Knowledge Base in sidebar
- Enter search query
- Press Enter or click Search
Advanced Searchβ
- View β Knowledge Base Search
- Use filters:
- Categories
- Status
- Time window
- Solution-only
- Relevance threshold
Context Search from editorβ
- Select text in editor
- Right-click β "Search in Knowledge Base"
- Or use: Edit β Search Knowledge Base
3. Applying Solutionsβ
When a search result contains a solution:
- Click "Apply" button on result
- Solution is inserted at current cursor position
- Or replaces selected text
4. Category Browsingβ
In the Knowledge Base panel:
- Click any category to instant-search
- View document counts per category
- Categories update in real-time
Troubleshootingβ
Extension Not Appearingβ
Check Installation:
# In theia app
npm list @coditect/theia-kb-extension
Verify Module Loading:
# Check console output on theia start
# Should see: "Knowledge Base extension activated"
Rebuild Completely:
npm run clean
rm -rf node_modules
npm install
npm run build
API Connection Failedβ
Check API Server:
# Is API running?
curl http://localhost:5175/api/stats
# Check logs
cd knowledge-base-ui
npm run server
Verify Network:
- No firewall blocking port 5175
- Correct API URL in settings
- CORS enabled on API server
Search Not Workingβ
Check Knowledge Base:
cd knowledge-base
python3 query_kb.py -i
> stats # Should show document count
Rebuild KB if Empty:
python3 setup_chromadb.py
Widget Errorsβ
Console Errors:
- Open Developer Tools: Help β Toggle Developer Tools
- Check Console tab for errors
- Look for injection errors
Common Fixes:
- Missing dependency injection
- API timeout - increase timeout setting
- Large results - reduce default limit
Developmentβ
Extension Structureβ
theia-kb-extension/
βββ src/browser/
β βββ kb-widget.tsx # Main panel widget
β βββ kb-search-widget.tsx # Search widget
β βββ kb-service.ts # API service
β βββ kb-contribution.ts # Commands/menus
β βββ kb-extension-frontend-module.ts # DI module
βββ package.json
βββ tsconfig.json
Adding Featuresβ
New Command:β
// kb-contribution.ts
commands.registerCommand({
id: 'kb.myNewCommand',
label: 'My New KB Command'
}, {
execute: () => this.kbService.doSomething()
});
New Menu Item:β
// kb-contribution.ts
menus.registerMenuAction(CommonMenus.VIEW, {
commandId: 'kb.myNewCommand',
label: 'My New Action'
});
Debuggingβ
-
Enable Source Maps:
// tsconfig.json
"sourceMap": true -
Launch Configuration:
// .vscode/launch.json
{
"type": "chrome",
"request": "launch",
"name": "Launch theia",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
} -
Debug Logs:
// Add to kb-service.ts
console.log('[KB]', 'Debug message', data);
Testingβ
# Unit tests
cd theia-kb-extension
npm test
# Integration test
npm run test:integration
Architectureβ
Component Flowβ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β theia editor ββββββΆβ KB Extension ββββββΆβ KB API β
β β β β β (Port 5175) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
β β βΌ
βΌ βΌ βββββββββββββββββββ
βββββββββββββββββββ βββββββββββββββββββ β ChromaDB β
β User Selection β β KB Widgets β β Vector Store β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
Dependency Injectionβ
// Module registration
export default new ContainerModule(bind => {
// Service
bind(KnowledgeBaseService).toSelf().inSingletonScope();
// Widgets
bind(KnowledgeBaseWidget).toSelf();
bind(WidgetFactory).toDynamicValue(ctx => ({
id: KnowledgeBaseWidget.ID,
createWidget: () => ctx.container.get(KnowledgeBaseWidget)
}));
// Contributions
bind(CommandContribution).to(KnowledgeBaseContribution);
bind(MenuContribution).to(KnowledgeBaseContribution);
});
API Integrationβ
// kb-service.ts
async search(params: SearchParams): Promise<SearchResult> {
const response = await fetch(`${this.apiUrl}/search`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(params)
});
return response.json();
}
Best Practicesβ
1. Performanceβ
- Debounce searches: Wait 300ms after typing
- Limit results: Default to 20, max 50
- Cache results: Store recent searches
- Lazy load: Load categories on demand
2. User Experienceβ
- Show loading states: Spinner during search
- Handle errors gracefully: User-friendly messages
- Preserve context: Remember filters/query
- Keyboard shortcuts: For power users
3. Integrationβ
- Follow theia patterns: Use DI, commands, contributions
- Respect themes: Use theia CSS classes
- Handle workspace changes: Clear cache on switch
- Support offline: Graceful degradation
Advanced Configurationβ
Custom Stylingβ
Create style/custom-kb.css:
/* Override KB widget styles */
.kb-widget {
--kb-primary: var(--theia-brand-color0);
--kb-background: var(--theia-editor-background);
}
.kb-search-result-item {
border-color: var(--theia-border-color);
}
API Interceptorsβ
// Add to kb-service.ts
protected async request(url: string, options: RequestInit): Promise<Response> {
// Add auth headers
options.headers = {
...options.headers,
'Authorization': `Bearer ${this.getAuthToken()}`
};
// Add telemetry
const start = Date.now();
const response = await fetch(url, options);
console.log(`[KB] ${url} took ${Date.now() - start}ms`);
return response;
}
Event Handlingβ
// Listen for workspace events
@inject(workspaceService)
protected readonly workspaceService: workspaceService;
@postConstruct()
protected init(): void {
this.workspaceService.onworkspaceChanged(() => {
this.clearCache();
this.loadworkspaceSpecificData();
});
}
Migration from Standaloneβ
If migrating from the standalone React app:
- Reuse Components: Extract React components
- Share Styles: Import CSS with adjustments
- Sync State: Use theia's state management
- Port Features: Commands instead of buttons
Resourcesβ
- Extension Source:
/theia-kb-extension - API Documentation:
/knowledge-base-ui/README.md - theia Docs: https://theia-ide.org/docs/
- Support: File issues in project repository
Quick Commands Referenceβ
| Command | Description | Shortcut |
|---|---|---|
kb.show | Show Knowledge Base view | - |
kb.search | Open search widget | Ctrl+K K |
kb.searchSelection | Search selected text | Ctrl+K S |
kb.refresh | Refresh stats/categories | F5 (in KB view) |
kb.clearCache | Clear search cache | - |
Last Updated: 2025-10-09 Version: 1.0.0