This document provides technical details about the BB Tool Library architecture, APIs, and integration points.
- Architecture
- Tool Package Structure
- Library APIs
- Security Model
- Integration Points
- Versioning
- Technical Requirements
The BB Tool Library is built on three main components:
-
Registry Service
- Tool metadata storage
- Version management
- Search and discovery
- Access control
-
Distribution System
- Package delivery
- Version resolution
- Dependency management
- Update notifications
-
Integration Layer
- BB core integration
- Tool loading
- Runtime management
- Resource monitoring
graph TD
A[BB Core] --> B[Integration Layer]
B --> C[Registry Service]
B --> D[Distribution System]
C --> E[Tool Metadata]
D --> F[Tool Packages]
BB uses a straightforward process to discover and load tools:
graph TD
A[Start Tool Loading] --> B[Scan userPluginDirectories]
B --> C{For Each Directory}
C --> D[Check for .tool Extension]
D --> E{Required Files?}
E -- No --> C
E -- Yes --> F[Validate info.json]
F --> G{Valid?}
G -- No --> C
G -- Yes --> H[Load Tool]
H --> I[Apply toolConfigs]
I --> C
C --> J[End Tool Loading]
subgraph Required Files Check
K[tool.ts Exists]
L[info.json Exists]
end
Tools that fail validation are silently skipped. The userPluginDirectories setting in BB's config specifies where to look for tools:
api:
userPluginDirectories:
- ./plugins # Relative to config file
- /abs/path/to/plugins # Absolute path
toolConfigs: # Tool-specific configurations
run_command:
allowedCommands:
- git branch
- ls
- pwd
multi_model_query:
anthropicApiKey: sk-ant-xxxx
models:
- claude-3-haiku
- gpt-4π§ Planned Feature: Tool Sets
- Tools can belong to sets (defined in info.json)
- Users can load specific tool sets
- Helps organize and manage tool collections
tool-package.tool/
β tool.ts # Main implementation
β formatter.browser.tsx # Browser formatting
β formatter.console.ts # Console formatting
βββ tests/
β βββ tool.test.ts # Test suite
βββ docs/
β βββ README.md # Documentation
βββ info.json # Metadata
βββ package.json # Package config
interface ToolMetadata {
name: string; // Tool name
version: string; // Semantic version
description: string; // Brief description
author: string; // Author name/organization
license: string; // License identifier
category: ToolCategory; // Primary category
tags: string[]; // Search tags
bb: {
minVersion: string; // Minimum BB version
permissions: string[]; // Required permissions
resourceIntensive: boolean; // Resource usage flag
};
repository: string; // Source repository URL
documentation: string; // Documentation URL
support: string; // Support URL
dependencies?: { // Optional dependencies
[name: string]: string;
};
}
type ToolCategory =
| 'File Operations'
| 'Code Analysis'
| 'Documentation'
| 'Project Management'
| 'Integration'
| 'Utility';Base URL: https://registry.bb.dev/api/v1
POST /tools
Content-Type: application/json
{
metadata: ToolMetadata;
signature: string; // Package signature
checksum: string; // Package checksum
}GET /tools/search
Query Parameters:
- q: string // Search query
- category: string // Filter by category
- tags: string[] // Filter by tags
- author: string // Filter by authorPOST /tools/:name/versions
Content-Type: application/json
{
version: string; // New version
metadata: ToolMetadata;
changes: string[]; // Changelog
}Base URL: https://dist.bb.dev/api/v1
GET /packages/:name/:version
Response:
Content-Type: application/x-bb-tool
X-BB-Signature: string
X-BB-Checksum: stringGET /updates/:name
Query Parameters:
- current: string // Current version
Response:
{
available: boolean;
latest: string; // Latest version
required: boolean; // Required update
}π§ Planned Feature: The following security features are planned for future implementation.
π§ Planned Feature: All tool packages must be signed:
- Developer generates key pair
- Public key registered with BB
- Packages signed before submission
- Signatures verified on installation
Tools declare required permissions:
{
"bb": {
"permissions": [
"files.read",
"files.write",
"network.fetch",
"system.exec"
]
}
}π§ Planned Feature: The following verification steps will be implemented:
-
Static Analysis
- Code security scan
- Dependency audit
- Permission verification
-
Dynamic Analysis
- Sandbox testing
- Resource monitoring
- Behavior analysis
-
Manual Review
- Code review
- Documentation review
- Security assessment
Tools integrate through the @beyondbetter/tools package:
import LLMTool from '@beyondbetter/tools';
import type {
IConversationInteraction,
IProjectEditor,
LLMToolRunResult
} from '@beyondbetter/tools';
export class CustomTool extends LLMTool {
// Implementation
}BB dynamically loads tools:
- Tool discovery
- Dependency resolution
- Permission verification
- Resource allocation
Tools operate within constraints:
- Memory limits
- CPU usage caps
- Network quotas
- Storage restrictions
Tools use semantic versioning:
- Major: Breaking changes
- Minor: New features
- Patch: Bug fixes
Version compatibility includes:
- BB core version
- Dependency versions
- API versions
- Feature flags
-
Patch Updates
- Bug fixes
- Security patches
- Performance improvements
-
Minor Updates
- New features
- Enhanced functionality
- Expanded capabilities
-
Major Updates
- Breaking changes
- Architecture changes
- Permission changes
π§ Planned Feature: Tools will be required to meet these performance criteria:
- Response time < 5s
- Memory usage < 100MB
- CPU usage < 50%
- Network efficiency
Required test coverage:
- Unit tests: >80%
- Integration tests
- Performance tests
- Security tests
Technical documentation must include:
- API reference
- Type definitions
- Example code
- Error handling
- Performance notes
Standardized error handling:
interface ToolError {
code: string; // Error code
message: string; // User message
details?: unknown; // Technical details
retry?: boolean; // Can retry
}Structured logging format:
interface ToolLog {
level: 'debug' | 'info' | 'warn' | 'error';
message: string;
metadata: Record<string, unknown>;
timestamp: string;
}import LLMTool from '@beyondbetter/tools';
export class LLMToolExampleTool extends LLMTool {
constructor() {
super('example_tool', 'Example tool description');
}
get inputSchema() {
return {
type: 'object',
properties: {
param: { type: 'string' }
}
};
}
async runTool(
interaction: IConversationInteraction,
toolUse: LLMAnswerToolUse,
projectEditor: IProjectEditor
): Promise<LLMToolRunResult> {
// Implementation
}
}Tools are integrated by adding their directory to BB's configuration:
api:
userPluginDirectories:
- ./tools # Relative to config file
- /abs/path/to/tools # Absolute path
toolConfigs: # Tool-specific configurations
run_command:
allowedCommands:
- git branch
- ls
- pwd
multi_model_query:
anthropicApiKey: sk-ant-xxxx
models:
- claude-3-haiku
- gpt-4BB will discover and load any .tool directories in these paths that contain the required tool.ts and info.json files. Each tool can have its own configuration in the toolConfigs section.
Path Resolution:
- Absolute paths are used as-is
- Relative paths are resolved from the directory containing the config file