@sparkleideas/agent-booster 0.2.5 → 0.2.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.d.ts +8 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +259 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +222 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +13 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +266 -0
- package/dist/server.js.map +1 -0
- package/package.json +5 -1
- package/wasm/README.md +299 -0
- package/wasm/agent_booster_wasm.d.ts +149 -0
- package/wasm/agent_booster_wasm.js +849 -0
- package/wasm/agent_booster_wasm_bg.wasm +0 -0
- package/wasm/agent_booster_wasm_bg.wasm.d.ts +47 -0
package/dist/server.js
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* Agent Booster API Server - Morph LLM Compatible
|
|
5
|
+
*
|
|
6
|
+
* Drop-in replacement for Morph LLM API with 352x faster performance
|
|
7
|
+
*
|
|
8
|
+
* Compatible endpoints:
|
|
9
|
+
* - POST /v1/chat/completions (Morph LLM format)
|
|
10
|
+
* - POST /v1/apply (Morph LLM format)
|
|
11
|
+
*/
|
|
12
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
|
+
};
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
const express_1 = __importDefault(require("express"));
|
|
17
|
+
const index_1 = require("./index");
|
|
18
|
+
const app = (0, express_1.default)();
|
|
19
|
+
app.use(express_1.default.json());
|
|
20
|
+
// Initialize Agent Booster
|
|
21
|
+
const booster = new index_1.AgentBooster({
|
|
22
|
+
confidenceThreshold: parseFloat(process.env.CONFIDENCE_THRESHOLD || '0.5'),
|
|
23
|
+
maxChunks: parseInt(process.env.MAX_CHUNKS || '100'),
|
|
24
|
+
});
|
|
25
|
+
/**
|
|
26
|
+
* Parse Morph LLM message format to extract instruction, code, and update
|
|
27
|
+
*/
|
|
28
|
+
function parseMorphMessage(content) {
|
|
29
|
+
const instructionMatch = content.match(/<instruction>(.*?)<\/instruction>/s);
|
|
30
|
+
const codeMatch = content.match(/<code>(.*?)<\/code>/s);
|
|
31
|
+
const updateMatch = content.match(/<update>(.*?)<\/update>/s);
|
|
32
|
+
if (!instructionMatch || !codeMatch || !updateMatch) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
instruction: instructionMatch[1].trim(),
|
|
37
|
+
code: codeMatch[1].trim(),
|
|
38
|
+
update: updateMatch[1].trim(),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* POST /v1/chat/completions
|
|
43
|
+
*
|
|
44
|
+
* Morph LLM-compatible chat completions endpoint
|
|
45
|
+
* Supports the same request/response format as Morph LLM
|
|
46
|
+
*/
|
|
47
|
+
app.post('/v1/chat/completions', async (req, res) => {
|
|
48
|
+
try {
|
|
49
|
+
const { model, messages, stream } = req.body;
|
|
50
|
+
if (!messages || messages.length === 0) {
|
|
51
|
+
return res.status(400).json({
|
|
52
|
+
error: {
|
|
53
|
+
message: 'messages array is required',
|
|
54
|
+
type: 'invalid_request_error',
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// Extract user message
|
|
59
|
+
const userMessage = messages.find((m) => m.role === 'user');
|
|
60
|
+
if (!userMessage) {
|
|
61
|
+
return res.status(400).json({
|
|
62
|
+
error: {
|
|
63
|
+
message: 'No user message found',
|
|
64
|
+
type: 'invalid_request_error',
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// Parse Morph message format
|
|
69
|
+
const parsed = parseMorphMessage(userMessage.content);
|
|
70
|
+
if (!parsed) {
|
|
71
|
+
return res.status(400).json({
|
|
72
|
+
error: {
|
|
73
|
+
message: 'Invalid message format. Expected <instruction>, <code>, and <update> tags',
|
|
74
|
+
type: 'invalid_request_error',
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
// Detect language from code
|
|
79
|
+
const language = detectLanguage(parsed.code);
|
|
80
|
+
// Apply edit using Agent Booster
|
|
81
|
+
const startTime = Date.now();
|
|
82
|
+
const result = await booster.apply({
|
|
83
|
+
code: parsed.code,
|
|
84
|
+
edit: parsed.update,
|
|
85
|
+
language,
|
|
86
|
+
});
|
|
87
|
+
// Return in Morph LLM format
|
|
88
|
+
res.json({
|
|
89
|
+
id: `chatcmpl-${Date.now()}`,
|
|
90
|
+
object: 'chat.completion',
|
|
91
|
+
created: Math.floor(Date.now() / 1000),
|
|
92
|
+
model: model || 'agent-booster-v1',
|
|
93
|
+
choices: [
|
|
94
|
+
{
|
|
95
|
+
index: 0,
|
|
96
|
+
message: {
|
|
97
|
+
role: 'assistant',
|
|
98
|
+
content: result.output,
|
|
99
|
+
},
|
|
100
|
+
finish_reason: result.success ? 'stop' : 'length',
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
usage: {
|
|
104
|
+
prompt_tokens: result.tokens.input,
|
|
105
|
+
completion_tokens: result.tokens.output,
|
|
106
|
+
total_tokens: result.tokens.input + result.tokens.output,
|
|
107
|
+
},
|
|
108
|
+
// Agent Booster extensions
|
|
109
|
+
confidence: result.confidence,
|
|
110
|
+
strategy: result.strategy,
|
|
111
|
+
latency: result.latency,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
console.error('Error in /v1/chat/completions:', error);
|
|
116
|
+
res.status(500).json({
|
|
117
|
+
error: {
|
|
118
|
+
message: error.message || 'Internal server error',
|
|
119
|
+
type: 'internal_error',
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
/**
|
|
125
|
+
* POST /v1/apply
|
|
126
|
+
*
|
|
127
|
+
* Direct apply endpoint (simpler than chat completions)
|
|
128
|
+
*/
|
|
129
|
+
app.post('/v1/apply', async (req, res) => {
|
|
130
|
+
try {
|
|
131
|
+
const { code, edit, language } = req.body;
|
|
132
|
+
if (!code || !edit) {
|
|
133
|
+
return res.status(400).json({
|
|
134
|
+
error: {
|
|
135
|
+
message: 'code and edit fields are required',
|
|
136
|
+
type: 'invalid_request_error',
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
const result = await booster.apply({
|
|
141
|
+
code,
|
|
142
|
+
edit,
|
|
143
|
+
language: language || detectLanguage(code),
|
|
144
|
+
});
|
|
145
|
+
res.json(result);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
console.error('Error in /v1/apply:', error);
|
|
149
|
+
res.status(500).json({
|
|
150
|
+
error: {
|
|
151
|
+
message: error.message || 'Internal server error',
|
|
152
|
+
type: 'internal_error',
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
/**
|
|
158
|
+
* POST /v1/batch
|
|
159
|
+
*
|
|
160
|
+
* Batch apply endpoint for processing multiple edits
|
|
161
|
+
*/
|
|
162
|
+
app.post('/v1/batch', async (req, res) => {
|
|
163
|
+
try {
|
|
164
|
+
const { requests } = req.body;
|
|
165
|
+
if (!Array.isArray(requests)) {
|
|
166
|
+
return res.status(400).json({
|
|
167
|
+
error: {
|
|
168
|
+
message: 'requests array is required',
|
|
169
|
+
type: 'invalid_request_error',
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
const results = await booster.batchApply(requests);
|
|
174
|
+
res.json({
|
|
175
|
+
results,
|
|
176
|
+
total: results.length,
|
|
177
|
+
successful: results.filter(r => r.success).length,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
console.error('Error in /v1/batch:', error);
|
|
182
|
+
res.status(500).json({
|
|
183
|
+
error: {
|
|
184
|
+
message: error.message || 'Internal server error',
|
|
185
|
+
type: 'internal_error',
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
/**
|
|
191
|
+
* GET /health
|
|
192
|
+
*
|
|
193
|
+
* Health check endpoint
|
|
194
|
+
*/
|
|
195
|
+
app.get('/health', (req, res) => {
|
|
196
|
+
res.json({
|
|
197
|
+
status: 'ok',
|
|
198
|
+
version: require('../package.json').version,
|
|
199
|
+
uptime: process.uptime(),
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
/**
|
|
203
|
+
* GET /
|
|
204
|
+
*
|
|
205
|
+
* API documentation endpoint
|
|
206
|
+
*/
|
|
207
|
+
app.get('/', (req, res) => {
|
|
208
|
+
res.json({
|
|
209
|
+
name: 'Agent Booster API',
|
|
210
|
+
version: require('../package.json').version,
|
|
211
|
+
description: 'Morph LLM-compatible API with 352x faster performance',
|
|
212
|
+
endpoints: {
|
|
213
|
+
'POST /v1/chat/completions': 'Morph LLM-compatible chat completions',
|
|
214
|
+
'POST /v1/apply': 'Direct apply endpoint',
|
|
215
|
+
'POST /v1/batch': 'Batch apply multiple edits',
|
|
216
|
+
'GET /health': 'Health check',
|
|
217
|
+
},
|
|
218
|
+
docs: 'https://github.com/yourusername/agent-booster',
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
/**
|
|
222
|
+
* Simple language detection based on file content
|
|
223
|
+
*/
|
|
224
|
+
function detectLanguage(code) {
|
|
225
|
+
if (code.includes('function') || code.includes('const') || code.includes('let')) {
|
|
226
|
+
if (code.includes(':') && (code.includes('number') || code.includes('string') || code.includes('boolean'))) {
|
|
227
|
+
return 'typescript';
|
|
228
|
+
}
|
|
229
|
+
return 'javascript';
|
|
230
|
+
}
|
|
231
|
+
if (code.includes('def ') || code.includes('import ')) {
|
|
232
|
+
return 'python';
|
|
233
|
+
}
|
|
234
|
+
if (code.includes('fn ') || code.includes('impl ')) {
|
|
235
|
+
return 'rust';
|
|
236
|
+
}
|
|
237
|
+
if (code.includes('func ') || code.includes('package ')) {
|
|
238
|
+
return 'go';
|
|
239
|
+
}
|
|
240
|
+
if (code.includes('public class') || code.includes('private ')) {
|
|
241
|
+
return 'java';
|
|
242
|
+
}
|
|
243
|
+
if (code.includes('#include')) {
|
|
244
|
+
if (code.includes('std::') || code.includes('class ')) {
|
|
245
|
+
return 'cpp';
|
|
246
|
+
}
|
|
247
|
+
return 'c';
|
|
248
|
+
}
|
|
249
|
+
return 'javascript'; // Default
|
|
250
|
+
}
|
|
251
|
+
// Start server
|
|
252
|
+
const PORT = parseInt(process.env.PORT || '3000');
|
|
253
|
+
const HOST = process.env.HOST || '0.0.0.0';
|
|
254
|
+
app.listen(PORT, HOST, () => {
|
|
255
|
+
console.log(`🚀 Agent Booster API Server`);
|
|
256
|
+
console.log(`📡 Listening on http://${HOST}:${PORT}`);
|
|
257
|
+
console.log(`📚 API docs: http://${HOST}:${PORT}`);
|
|
258
|
+
console.log(`🏥 Health check: http://${HOST}:${PORT}/health`);
|
|
259
|
+
console.log(`\n✨ Morph LLM-compatible endpoints:`);
|
|
260
|
+
console.log(` POST /v1/chat/completions`);
|
|
261
|
+
console.log(` POST /v1/apply`);
|
|
262
|
+
console.log(` POST /v1/batch`);
|
|
263
|
+
console.log(`\n⚡ 352x faster than Morph LLM | $0 cost | 100% private\n`);
|
|
264
|
+
});
|
|
265
|
+
exports.default = app;
|
|
266
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;AACA;;;;;;;;GAQG;;;;;AAEH,sDAA8B;AAC9B,mCAA8E;AAE9E,MAAM,GAAG,GAAG,IAAA,iBAAO,GAAE,CAAC;AACtB,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,IAAI,EAAE,C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AED,eAAe;AACf,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC;AAClD,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,SAAS,CAAC;AAE3C,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE;IAC1B,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;IAC3C,OAAO,CAAC,GAAG,CAAC,0BAA0B,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC;IACtD,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC;IACnD,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,IAAI,IAAI,SAAS,CAAC,CAAC;IAC9D,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAC;IACnD,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;IAC5C,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACjC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IACjC,OAAO,CAAC,GAAG,CAAC,2DAA2D,CAAC,CAAC;AAC3E,CAAC,CAAC,CAAC;AAEH,kBAAe,GAAG,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sparkleideas/agent-booster",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.32",
|
|
4
4
|
"description": "Ultra-fast code editing engine - 52x faster than Morph LLM at $0 cost",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"agent-booster-server": "./dist/server.js",
|
|
9
|
+
"@sparkleideas/agent-booster": "./dist/cli.js"
|
|
10
|
+
},
|
|
7
11
|
"files": [
|
|
8
12
|
"dist/",
|
|
9
13
|
"wasm/",
|
package/wasm/README.md
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
# agent-booster-wasm
|
|
2
|
+
|
|
3
|
+
WebAssembly bindings for the Agent Booster library, providing fast code editing capabilities using tree-sitter and similarity matching in Node.js and browser environments.
|
|
4
|
+
|
|
5
|
+
## Status
|
|
6
|
+
|
|
7
|
+
**Phase**: Initial implementation complete, waiting for core library API finalization.
|
|
8
|
+
|
|
9
|
+
The WASM bindings infrastructure is ready with:
|
|
10
|
+
- ✅ Type definitions and conversions
|
|
11
|
+
- ✅ WASM-bindgen setup
|
|
12
|
+
- ✅ JavaScript interop layer
|
|
13
|
+
- ⏳ Core `apply_edit` function (pending core library implementation)
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
Once published, you can install via npm:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install agent-booster-wasm
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Building from Source
|
|
24
|
+
|
|
25
|
+
### Prerequisites
|
|
26
|
+
|
|
27
|
+
1. Install Rust (1.70+):
|
|
28
|
+
```bash
|
|
29
|
+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
2. Add WASM target:
|
|
33
|
+
```bash
|
|
34
|
+
rustup target add wasm32-unknown-unknown
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
3. Install wasm-pack:
|
|
38
|
+
```bash
|
|
39
|
+
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Build Commands
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Build for Node.js
|
|
46
|
+
wasm-pack build --target nodejs
|
|
47
|
+
|
|
48
|
+
# Build for web browsers
|
|
49
|
+
wasm-pack build --target web
|
|
50
|
+
|
|
51
|
+
# Build for bundlers (webpack, rollup, etc.)
|
|
52
|
+
wasm-pack build --target bundler
|
|
53
|
+
|
|
54
|
+
# Release build (optimized)
|
|
55
|
+
wasm-pack build --release --target nodejs
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
### Basic Example
|
|
61
|
+
|
|
62
|
+
```javascript
|
|
63
|
+
const { AgentBoosterWasm, WasmLanguage } = require('agent-booster-wasm');
|
|
64
|
+
|
|
65
|
+
// Create an instance
|
|
66
|
+
const booster = new AgentBoosterWasm();
|
|
67
|
+
|
|
68
|
+
// Parse language
|
|
69
|
+
const language = AgentBoosterWasm.parse_language('javascript');
|
|
70
|
+
|
|
71
|
+
// Apply an edit (once implemented)
|
|
72
|
+
try {
|
|
73
|
+
const result = booster.apply_edit(
|
|
74
|
+
originalCode,
|
|
75
|
+
editSnippet,
|
|
76
|
+
language
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
console.log('Merged code:', result.merged_code);
|
|
80
|
+
console.log('Confidence:', result.confidence);
|
|
81
|
+
console.log('Strategy:', result.strategy);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error('Edit failed:', error);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Configuration
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
const { WasmConfig } = require('agent-booster-wasm');
|
|
91
|
+
|
|
92
|
+
// Create custom configuration
|
|
93
|
+
const config = new WasmConfig();
|
|
94
|
+
config.confidence_threshold = 0.7;
|
|
95
|
+
config.max_chunks = 100;
|
|
96
|
+
|
|
97
|
+
// Use with AgentBooster
|
|
98
|
+
const booster = AgentBoosterWasm.with_config(config);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### JSON API
|
|
102
|
+
|
|
103
|
+
For dynamic use cases, you can use the JSON API:
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
const requestJson = JSON.stringify({
|
|
107
|
+
original_code: "const x = 1;",
|
|
108
|
+
edit_snippet: "const x = 2;",
|
|
109
|
+
language: "JavaScript",
|
|
110
|
+
confidence_threshold: 0.5
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const result = booster.apply_edit_json(requestJson);
|
|
114
|
+
const resultData = JSON.parse(result.to_json());
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## API Reference
|
|
118
|
+
|
|
119
|
+
### AgentBoosterWasm
|
|
120
|
+
|
|
121
|
+
Main interface for applying code edits.
|
|
122
|
+
|
|
123
|
+
#### Methods
|
|
124
|
+
|
|
125
|
+
- `new()` - Create with default configuration
|
|
126
|
+
- `with_config(config: WasmConfig)` - Create with custom configuration
|
|
127
|
+
- `parse_language(lang: string)` - Parse language string to WasmLanguage
|
|
128
|
+
- `apply_edit(original_code: string, edit_snippet: string, language: WasmLanguage)` - Apply an edit
|
|
129
|
+
- `apply_edit_json(request_json: string)` - Apply edit from JSON request
|
|
130
|
+
- `get_config()` - Get current configuration
|
|
131
|
+
- `set_config(config: WasmConfig)` - Update configuration
|
|
132
|
+
- `version()` - Get library version (static method)
|
|
133
|
+
|
|
134
|
+
### WasmLanguage
|
|
135
|
+
|
|
136
|
+
Supported programming languages:
|
|
137
|
+
- `JavaScript`
|
|
138
|
+
- `TypeScript`
|
|
139
|
+
|
|
140
|
+
### WasmMergeStrategy
|
|
141
|
+
|
|
142
|
+
Strategies for applying edits:
|
|
143
|
+
- `ExactReplace` - Replace exact match with high confidence
|
|
144
|
+
- `FuzzyReplace` - Replace with fuzzy text matching
|
|
145
|
+
- `InsertAfter` - Insert after matched location
|
|
146
|
+
- `InsertBefore` - Insert before matched location
|
|
147
|
+
- `Append` - Append to end of file
|
|
148
|
+
|
|
149
|
+
### WasmEditResult
|
|
150
|
+
|
|
151
|
+
Result of an edit operation:
|
|
152
|
+
- `merged_code: string` - The merged code after applying edit
|
|
153
|
+
- `confidence: f32` - Confidence score (0.0 - 1.0)
|
|
154
|
+
- `strategy: WasmMergeStrategy` - Strategy used for merging
|
|
155
|
+
- `chunks_found: usize` - Number of chunks extracted from original code
|
|
156
|
+
- `best_similarity: f32` - Best similarity score found
|
|
157
|
+
- `syntax_valid: bool` - Whether syntax validation passed
|
|
158
|
+
- `processing_time_ms?: u64` - Processing time in milliseconds
|
|
159
|
+
- `to_json()` - Convert to JSON string
|
|
160
|
+
|
|
161
|
+
### WasmConfig
|
|
162
|
+
|
|
163
|
+
Configuration for AgentBooster:
|
|
164
|
+
- `confidence_threshold: f32` - Minimum confidence threshold (default: 0.5)
|
|
165
|
+
- `max_chunks: usize` - Maximum number of chunks to consider (default: 50)
|
|
166
|
+
- `from_json(json: string)` - Create from JSON string (static method)
|
|
167
|
+
- `to_json()` - Convert to JSON string
|
|
168
|
+
|
|
169
|
+
### Helper Functions
|
|
170
|
+
|
|
171
|
+
- `parse_edit_request(json: string)` - Parse EditRequest from JSON
|
|
172
|
+
- `create_edit_request(original_code: string, edit_snippet: string, language: WasmLanguage, confidence_threshold?: f32)` - Create EditRequest JSON
|
|
173
|
+
|
|
174
|
+
## Performance
|
|
175
|
+
|
|
176
|
+
The WASM module is optimized for:
|
|
177
|
+
- **Small binary size**: Release builds use `opt-level = "z"` and LTO
|
|
178
|
+
- **Fast parsing**: Tree-sitter provides zero-copy parsing
|
|
179
|
+
- **Efficient similarity matching**: Rust's performance with minimal JavaScript overhead
|
|
180
|
+
|
|
181
|
+
Expected performance characteristics:
|
|
182
|
+
- Small code files (<1KB): < 1ms
|
|
183
|
+
- Medium files (1-10KB): 1-5ms
|
|
184
|
+
- Large files (10-100KB): 5-50ms
|
|
185
|
+
|
|
186
|
+
## Architecture
|
|
187
|
+
|
|
188
|
+
```
|
|
189
|
+
┌─────────────────────────────────────┐
|
|
190
|
+
│ JavaScript/TypeScript Application │
|
|
191
|
+
└──────────────┬──────────────────────┘
|
|
192
|
+
│
|
|
193
|
+
▼
|
|
194
|
+
┌─────────────────────────────────────┐
|
|
195
|
+
│ wasm-bindgen JS Glue Code │
|
|
196
|
+
└──────────────┬──────────────────────┘
|
|
197
|
+
│
|
|
198
|
+
▼
|
|
199
|
+
┌─────────────────────────────────────┐
|
|
200
|
+
│ agent-booster-wasm (This Crate) │
|
|
201
|
+
│ - Type conversions │
|
|
202
|
+
│ - Error handling │
|
|
203
|
+
│ - JS interop layer │
|
|
204
|
+
└──────────────┬──────────────────────┘
|
|
205
|
+
│
|
|
206
|
+
▼
|
|
207
|
+
┌─────────────────────────────────────┐
|
|
208
|
+
│ agent-booster (Core Library) │
|
|
209
|
+
│ - Tree-sitter parsing │
|
|
210
|
+
│ - Similarity matching │
|
|
211
|
+
│ - Code merging logic │
|
|
212
|
+
└─────────────────────────────────────┘
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Testing
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
# Run WASM tests
|
|
219
|
+
wasm-pack test --node
|
|
220
|
+
|
|
221
|
+
# Run in browser (requires Chrome/Firefox)
|
|
222
|
+
wasm-pack test --headless --firefox
|
|
223
|
+
wasm-pack test --headless --chrome
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Size Optimization
|
|
227
|
+
|
|
228
|
+
The WASM binary is optimized for size:
|
|
229
|
+
|
|
230
|
+
1. **Compiler optimizations**: `opt-level = "z"` for maximum size reduction
|
|
231
|
+
2. **LTO**: Link-time optimization enabled
|
|
232
|
+
3. **Strip**: Debug symbols removed in release builds
|
|
233
|
+
4. **Optional allocator**: Can use `wee_alloc` for smaller binary
|
|
234
|
+
|
|
235
|
+
To enable `wee_alloc`:
|
|
236
|
+
```bash
|
|
237
|
+
wasm-pack build --release --target nodejs -- --features wee_alloc_feature
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Troubleshooting
|
|
241
|
+
|
|
242
|
+
### Build Errors
|
|
243
|
+
|
|
244
|
+
If you encounter build errors:
|
|
245
|
+
|
|
246
|
+
1. Ensure Rust toolchain is up to date:
|
|
247
|
+
```bash
|
|
248
|
+
rustup update
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
2. Clean and rebuild:
|
|
252
|
+
```bash
|
|
253
|
+
cargo clean
|
|
254
|
+
wasm-pack build --target nodejs
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
3. Check that the core library builds:
|
|
258
|
+
```bash
|
|
259
|
+
cd ../agent-booster
|
|
260
|
+
cargo build
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Runtime Errors
|
|
264
|
+
|
|
265
|
+
Common issues:
|
|
266
|
+
|
|
267
|
+
1. **"apply_edit not yet implemented"**: The core library API is still being developed. This is expected during the initial phase.
|
|
268
|
+
|
|
269
|
+
2. **Memory issues**: WASM has a memory limit. For very large files, consider processing in chunks.
|
|
270
|
+
|
|
271
|
+
3. **Browser compatibility**: Ensure your target browsers support WebAssembly (most modern browsers do).
|
|
272
|
+
|
|
273
|
+
## Development Status
|
|
274
|
+
|
|
275
|
+
- [x] Project structure
|
|
276
|
+
- [x] Type definitions and conversions
|
|
277
|
+
- [x] WASM-bindgen integration
|
|
278
|
+
- [x] Configuration API
|
|
279
|
+
- [x] Helper functions
|
|
280
|
+
- [x] Documentation
|
|
281
|
+
- [ ] Core library integration (waiting for apply_edit implementation)
|
|
282
|
+
- [ ] Performance benchmarks
|
|
283
|
+
- [ ] Integration tests
|
|
284
|
+
- [ ] NPM package publication
|
|
285
|
+
|
|
286
|
+
## Contributing
|
|
287
|
+
|
|
288
|
+
This is part of the Agent Booster project. See the main project README for contribution guidelines.
|
|
289
|
+
|
|
290
|
+
## License
|
|
291
|
+
|
|
292
|
+
MIT - See LICENSE file for details.
|
|
293
|
+
|
|
294
|
+
## Links
|
|
295
|
+
|
|
296
|
+
- [Agent Booster Core](../agent-booster/)
|
|
297
|
+
- [Agent Booster Native (N-API)](../agent-booster-native/)
|
|
298
|
+
- [wasm-bindgen Documentation](https://rustwasm.github.io/wasm-bindgen/)
|
|
299
|
+
- [wasm-pack Documentation](https://rustwasm.github.io/wasm-pack/)
|