|
1 | 1 | # Codebolt Agent Library |
2 | 2 |
|
3 | | -This library provides a set of tools and utilities for creating Codebolt agents, enabling seamless integration with the Codebolt platform. |
| 3 | +This library provides a set of tools and utilities for creating Codebolt agents, enabling seamless integration with the Codebolt platform with full TypeScript support. |
4 | 4 |
|
5 | 5 | ## Features |
6 | 6 | - Create and manage Codebolt agents |
7 | 7 | - Interact with the Codebolt platform |
8 | 8 | - Utilize Codebolt's powerful API |
| 9 | +- **Full TypeScript support with comprehensive type definitions** |
| 10 | +- Type-safe API interactions |
| 11 | +- IntelliSense support in TypeScript/JavaScript IDEs |
9 | 12 |
|
10 | 13 | ## Installation |
11 | 14 |
|
12 | 15 | ```bash |
13 | 16 | npm install @codebolt/codeboltjs |
14 | 17 | ``` |
15 | 18 |
|
16 | | -## Usage |
| 19 | +## Quick Start |
17 | 20 |
|
| 21 | +### JavaScript |
18 | 22 | ```javascript |
19 | 23 | const codebolt = require('@codebolt/codeboltjs'); |
20 | 24 |
|
21 | | -// Your code here |
| 25 | +// Set up message handling |
| 26 | +codebolt.onMessage(async (userMessage) => { |
| 27 | + console.log('User said:', userMessage.userMessage); |
| 28 | + |
| 29 | + // Read a file |
| 30 | + const content = await codebolt.fs.readFile({ path: './example.txt' }); |
| 31 | + console.log('File content:', content); |
| 32 | + |
| 33 | + return { status: 'completed' }; |
| 34 | +}); |
| 35 | +``` |
| 36 | + |
| 37 | +### TypeScript |
| 38 | +```typescript |
| 39 | +import codebolt from 'codeboltjs'; |
| 40 | +import type { |
| 41 | + ChatMessageFromUser, |
| 42 | + ReadFileOptions, |
| 43 | + BrowserScreenshotOptions |
| 44 | +} from 'codeboltjs'; |
| 45 | + |
| 46 | +// Type-safe message handling |
| 47 | +codebolt.onMessage(async (userMessage: ChatMessageFromUser) => { |
| 48 | + console.log('User said:', userMessage.userMessage); |
| 49 | + console.log('Mentioned files:', userMessage.mentionedFiles); |
| 50 | + |
| 51 | + // Type-safe file operations |
| 52 | + const readOptions: ReadFileOptions = { |
| 53 | + path: './config.json', |
| 54 | + encoding: 'utf8', |
| 55 | + askForPermission: true |
| 56 | + }; |
| 57 | + |
| 58 | + const content = await codebolt.fs.readFile(readOptions); |
| 59 | + |
| 60 | + // Type-safe browser operations |
| 61 | + const screenshotOptions: BrowserScreenshotOptions = { |
| 62 | + fullPage: true, |
| 63 | + quality: 90, |
| 64 | + format: 'png' |
| 65 | + }; |
| 66 | + |
| 67 | + const screenshot = await codebolt.browser.takeScreenshot(screenshotOptions); |
| 68 | + |
| 69 | + return { status: 'completed', data: content }; |
| 70 | +}); |
| 71 | +``` |
| 72 | + |
| 73 | +## TypeScript Support |
| 74 | + |
| 75 | +This library provides comprehensive TypeScript support with over 200+ type definitions covering: |
| 76 | + |
| 77 | +### Core Types |
| 78 | +- **Message & Tool Types**: `Message`, `ToolCall`, `Tool`, `LLMInferenceParams` |
| 79 | +- **API Response Types**: `APIResponse`, `SuccessResponse`, `FailureResponse` |
| 80 | +- **Configuration Types**: `CodeboltConfig`, `AgentConfiguration` |
| 81 | + |
| 82 | +### Module-Specific Types |
| 83 | +- **File System**: `ReadFileOptions`, `WriteFileOptions`, `SearchFilesOptions` |
| 84 | +- **Browser**: `BrowserNavigationOptions`, `BrowserScreenshotOptions` |
| 85 | +- **Terminal**: `TerminalExecuteOptions` |
| 86 | +- **Git**: `GitCommitOptions`, `GitLogOptions` |
| 87 | +- **LLM**: `LLMChatOptions`, `OpenAIMessage` |
| 88 | +- **Vector DB**: `VectorAddOptions`, `VectorQueryOptions` |
| 89 | + |
| 90 | +### Import Strategies |
| 91 | + |
| 92 | +#### From Main Package |
| 93 | +```typescript |
| 94 | +import codebolt, { type Message, type ToolCall } from 'codeboltjs'; |
| 95 | +``` |
| 96 | + |
| 97 | +#### From Types Barrel (Recommended) |
| 98 | +```typescript |
| 99 | +import codebolt from 'codeboltjs'; |
| 100 | +import type { Message, ToolCall, LLMChatOptions } from 'codeboltjs/types'; |
| 101 | +``` |
| 102 | + |
| 103 | +#### Namespace Import |
| 104 | +```typescript |
| 105 | +import codebolt from 'codeboltjs'; |
| 106 | +import type * as CodeboltTypes from 'codeboltjs/types'; |
| 107 | +``` |
| 108 | + |
| 109 | +For detailed type usage examples, see [TYPES.md](./TYPES.md). |
| 110 | + |
| 111 | +## API Overview |
| 112 | + |
| 113 | +### Core Modules |
| 114 | + |
| 115 | +- `codebolt.fs` - File system operations |
| 116 | +- `codebolt.git` - Git operations |
| 117 | +- `codebolt.browser` - Browser automation |
| 118 | +- `codebolt.terminal` - Terminal/shell operations |
| 119 | +- `codebolt.llm` - LLM interactions |
| 120 | +- `codebolt.chat` - Chat management |
| 121 | +- `codebolt.agent` - Agent operations |
| 122 | +- `codebolt.vectordb` - Vector database operations |
| 123 | +- `codebolt.mcp` - MCP (Model Context Protocol) tools |
| 124 | + |
| 125 | +### Example Usage |
| 126 | + |
| 127 | +```typescript |
| 128 | +// Wait for connection |
| 129 | +await codebolt.waitForReady(); |
| 130 | + |
| 131 | +// File operations |
| 132 | +const files = await codebolt.fs.listFiles({ path: './src', recursive: true }); |
| 133 | +const content = await codebolt.fs.readFile({ path: './package.json' }); |
| 134 | + |
| 135 | +// Browser operations |
| 136 | +await codebolt.browser.navigateTo({ url: 'https://example.com' }); |
| 137 | +const screenshot = await codebolt.browser.takeScreenshot({ fullPage: true }); |
| 138 | + |
| 139 | +// Terminal operations |
| 140 | +const result = await codebolt.terminal.execute({ |
| 141 | + command: 'npm install', |
| 142 | + cwd: './my-project' |
| 143 | +}); |
| 144 | + |
| 145 | +// LLM operations |
| 146 | +const response = await codebolt.llm.chat({ |
| 147 | + messages: [{ role: 'user', content: 'Explain TypeScript' }], |
| 148 | + temperature: 0.7 |
| 149 | +}); |
22 | 150 | ``` |
23 | 151 |
|
24 | 152 | ## Development |
@@ -64,11 +192,17 @@ The project supports two build methods: |
64 | 192 | ### Project Structure |
65 | 193 |
|
66 | 194 | - `src/` - TypeScript source code |
| 195 | + - `core/` - Core library classes (Codebolt class, WebSocket management) |
| 196 | + - `modules/` - Feature modules (fs, git, browser, etc.) |
| 197 | + - `types/` - TypeScript type definitions |
| 198 | + - `utils/` - Utility functions |
67 | 199 | - `dist/` - Compiled JavaScript and type definitions (generated by TypeScript) |
68 | 200 | - `build/` - Webpack bundle (generated by webpack) |
69 | 201 | - `docs/` - Generated documentation |
70 | 202 |
|
71 | 203 | ## Documentation |
72 | 204 |
|
73 | | -For More Documentation visit [Codebolt's Documentation](https://docs.codebolt.ai) |
| 205 | +- **[Type Definitions Guide](./TYPES.md)** - Comprehensive TypeScript usage guide |
| 206 | +- **[Codebolt Documentation](https://docs.codebolt.ai)** - Platform documentation |
| 207 | +- **API Reference** - Generated from source code (coming soon) |
74 | 208 |
|
0 commit comments