codebuff 1.0.250 → 1.0.251
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/package.json +1 -1
- package/dist/background-process-manager.js +0 -359
- package/dist/background-process-manager.js.map +0 -1
- package/dist/browser-runner.js +0 -680
- package/dist/browser-runner.js.map +0 -1
- package/dist/chat-storage.js +0 -93
- package/dist/chat-storage.js.map +0 -1
- package/dist/checkpoints/checkpoint-manager.js +0 -280
- package/dist/checkpoints/checkpoint-manager.js.map +0 -1
- package/dist/cli-handlers/api-key.js +0 -66
- package/dist/cli-handlers/api-key.js.map +0 -1
- package/dist/cli-handlers/checkpoint.js +0 -195
- package/dist/cli-handlers/checkpoint.js.map +0 -1
- package/dist/cli-handlers/diff.js +0 -31
- package/dist/cli-handlers/diff.js.map +0 -1
- package/dist/cli-handlers/inititalization-flow.js +0 -24
- package/dist/cli-handlers/inititalization-flow.js.map +0 -1
- package/dist/cli.js +0 -478
- package/dist/cli.js.map +0 -1
- package/dist/client.js +0 -836
- package/dist/client.js.map +0 -1
- package/dist/credentials.js +0 -38
- package/dist/credentials.js.map +0 -1
- package/dist/dev-process-manager.js +0 -54
- package/dist/dev-process-manager.js.map +0 -1
- package/dist/index.js +0 -117
- package/dist/index.js.map +0 -1
- package/dist/menu.js +0 -126
- package/dist/menu.js.map +0 -1
- package/dist/project-files.js +0 -513
- package/dist/project-files.js.map +0 -1
- package/dist/startup-process-handler.js +0 -21
- package/dist/startup-process-handler.js.map +0 -1
- package/dist/tool-handlers.js +0 -240
- package/dist/tool-handlers.js.map +0 -1
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
- package/dist/utils/__tests__/tool-renderers.test.js +0 -51
- package/dist/utils/__tests__/tool-renderers.test.js.map +0 -1
- package/dist/utils/__tests__/xml-stream-parser.test.js +0 -229
- package/dist/utils/__tests__/xml-stream-parser.test.js.map +0 -1
- package/dist/utils/analytics.js +0 -59
- package/dist/utils/analytics.js.map +0 -1
- package/dist/utils/logger.js +0 -105
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/terminal.js +0 -474
- package/dist/utils/terminal.js.map +0 -1
- package/dist/utils/tool-renderers.js +0 -145
- package/dist/utils/tool-renderers.js.map +0 -1
- package/dist/utils/xml-stream-parser.js +0 -128
- package/dist/utils/xml-stream-parser.js.map +0 -1
- package/dist/web-scraper.js +0 -57
- package/dist/web-scraper.js.map +0 -1
- package/dist/workers/project-context.js +0 -17
- package/dist/workers/project-context.js.map +0 -1
package/dist/tool-handlers.js
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.handleToolCall = exports.toolHandlers = exports.handleCodeSearch = exports.handleRunTerminalCommand = exports.handleScrapeWebPage = exports.handleWriteFile = void 0;
|
|
27
|
-
const child_process_1 = require("child_process");
|
|
28
|
-
const path = __importStar(require("path"));
|
|
29
|
-
const ripgrep_1 = require("@vscode/ripgrep");
|
|
30
|
-
const actions_1 = require("./common/actions");
|
|
31
|
-
const browser_actions_1 = require("./common/browser-actions");
|
|
32
|
-
const changes_1 = require("./common/util/changes");
|
|
33
|
-
const string_1 = require("./common/util/string");
|
|
34
|
-
const picocolors_1 = require("picocolors");
|
|
35
|
-
const browser_runner_1 = require("./browser-runner");
|
|
36
|
-
const spinner_1 = require("./utils/spinner");
|
|
37
|
-
const terminal_1 = require("./utils/terminal");
|
|
38
|
-
const web_scraper_1 = require("./web-scraper");
|
|
39
|
-
const handleWriteFile = async (parameters, _id, projectPath) => {
|
|
40
|
-
const fileChange = actions_1.FileChangeSchema.parse(parameters);
|
|
41
|
-
const lines = fileChange.content.split('\n');
|
|
42
|
-
const { created, modified, ignored } = (0, changes_1.applyChanges)(projectPath, [fileChange]);
|
|
43
|
-
let result = [];
|
|
44
|
-
for (const file of created) {
|
|
45
|
-
const counts = `(${(0, picocolors_1.green)(`+${lines.length}`)})`;
|
|
46
|
-
result.push(`Wrote to ${file} successfully.`);
|
|
47
|
-
console.log((0, picocolors_1.green)(`- Created ${file} ${counts}`));
|
|
48
|
-
}
|
|
49
|
-
for (const file of modified) {
|
|
50
|
-
// Calculate added/deleted lines from the diff content
|
|
51
|
-
let addedLines = 0;
|
|
52
|
-
let deletedLines = 0;
|
|
53
|
-
lines.forEach((line) => {
|
|
54
|
-
if (line.startsWith('+')) {
|
|
55
|
-
addedLines++;
|
|
56
|
-
}
|
|
57
|
-
else if (line.startsWith('-')) {
|
|
58
|
-
deletedLines++;
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
const counts = `(${(0, picocolors_1.green)(`+${addedLines}`)}, ${(0, picocolors_1.red)(`-${deletedLines}`)})`;
|
|
62
|
-
result.push(`Wrote to ${file} successfully.`);
|
|
63
|
-
console.log((0, picocolors_1.green)(`- Updated ${file} ${counts}`));
|
|
64
|
-
}
|
|
65
|
-
for (const file of ignored) {
|
|
66
|
-
result.push(`Failed to write to ${file}; file is ignored by .gitignore or .codebuffignore`);
|
|
67
|
-
}
|
|
68
|
-
return result.join('\n');
|
|
69
|
-
};
|
|
70
|
-
exports.handleWriteFile = handleWriteFile;
|
|
71
|
-
const handleScrapeWebPage = async (parameters) => {
|
|
72
|
-
const { url } = parameters;
|
|
73
|
-
const content = await (0, web_scraper_1.scrapeWebPage)(url);
|
|
74
|
-
if (!content) {
|
|
75
|
-
return `<web_scraping_error url="${url}">Failed to scrape the web page.</web_scraping_error>`;
|
|
76
|
-
}
|
|
77
|
-
return `<web_scraped_content url="${url}">${content}</web_scraped_content>`;
|
|
78
|
-
};
|
|
79
|
-
exports.handleScrapeWebPage = handleScrapeWebPage;
|
|
80
|
-
const handleRunTerminalCommand = async (parameters, id, projectPath) => {
|
|
81
|
-
const { command, mode = 'assistant', process_type = 'SYNC' } = parameters;
|
|
82
|
-
return (0, terminal_1.runTerminalCommand)(id, command, mode, projectPath, process_type.toUpperCase());
|
|
83
|
-
};
|
|
84
|
-
exports.handleRunTerminalCommand = handleRunTerminalCommand;
|
|
85
|
-
const handleCodeSearch = async (parameters, _id, projectPath) => {
|
|
86
|
-
return new Promise((resolve) => {
|
|
87
|
-
let stdout = '';
|
|
88
|
-
let stderr = '';
|
|
89
|
-
const basename = path.basename(projectPath);
|
|
90
|
-
const pattern = parameters.pattern.replace(/"/g, '');
|
|
91
|
-
const command = `${path.resolve(ripgrep_1.rgPath)} "${pattern}" .`;
|
|
92
|
-
console.log();
|
|
93
|
-
console.log((0, picocolors_1.green)(`Searching ${basename} for "${pattern}":`));
|
|
94
|
-
const childProcess = (0, child_process_1.spawn)(command, {
|
|
95
|
-
cwd: projectPath,
|
|
96
|
-
shell: true,
|
|
97
|
-
});
|
|
98
|
-
childProcess.stdout.on('data', (data) => {
|
|
99
|
-
stdout += data.toString();
|
|
100
|
-
});
|
|
101
|
-
childProcess.stderr.on('data', (data) => {
|
|
102
|
-
stderr += data.toString();
|
|
103
|
-
});
|
|
104
|
-
childProcess.on('close', (code) => {
|
|
105
|
-
const lines = stdout.split('\n').filter((line) => line.trim());
|
|
106
|
-
const maxResults = 3;
|
|
107
|
-
const previewResults = lines.slice(0, maxResults);
|
|
108
|
-
if (previewResults.length > 0) {
|
|
109
|
-
console.log(previewResults.join('\n'));
|
|
110
|
-
if (lines.length > maxResults) {
|
|
111
|
-
console.log('...');
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
console.log((0, picocolors_1.green)(`Found ${lines.length} results`));
|
|
115
|
-
const truncatedStdout = (0, string_1.truncateStringWithMessage)({
|
|
116
|
-
str: stdout,
|
|
117
|
-
maxLength: 10000,
|
|
118
|
-
});
|
|
119
|
-
const truncatedStderr = (0, string_1.truncateStringWithMessage)({
|
|
120
|
-
str: stderr,
|
|
121
|
-
maxLength: 1000,
|
|
122
|
-
});
|
|
123
|
-
resolve(formatResult(truncatedStdout, truncatedStderr, 'Code search completed', code));
|
|
124
|
-
});
|
|
125
|
-
childProcess.on('error', (error) => {
|
|
126
|
-
resolve(`<terminal_command_error>Failed to execute ripgrep: ${error.message}</terminal_command_error>`);
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
};
|
|
130
|
-
exports.handleCodeSearch = handleCodeSearch;
|
|
131
|
-
function formatResult(stdout, stderr, status, exitCode) {
|
|
132
|
-
let result = '<terminal_command_result>\n';
|
|
133
|
-
result += `<stdout>${stdout}</stdout>\n`;
|
|
134
|
-
if (stderr !== undefined) {
|
|
135
|
-
result += `<stderr>${stderr}</stderr>\n`;
|
|
136
|
-
}
|
|
137
|
-
result += `<status>${status}</status>\n`;
|
|
138
|
-
if (exitCode !== null) {
|
|
139
|
-
result += `<exit_code>${exitCode}</exit_code>\n`;
|
|
140
|
-
}
|
|
141
|
-
result += '</terminal_command_result>';
|
|
142
|
-
return result;
|
|
143
|
-
}
|
|
144
|
-
exports.toolHandlers = {
|
|
145
|
-
write_file: exports.handleWriteFile,
|
|
146
|
-
scrape_web_page: exports.handleScrapeWebPage,
|
|
147
|
-
run_terminal_command: ((parameters, id, projectPath) => (0, exports.handleRunTerminalCommand)(parameters, id, projectPath).then((result) => result.result)),
|
|
148
|
-
code_search: exports.handleCodeSearch,
|
|
149
|
-
end_turn: async () => {
|
|
150
|
-
return '';
|
|
151
|
-
},
|
|
152
|
-
browser_logs: async (params, _id) => {
|
|
153
|
-
spinner_1.Spinner.get().start();
|
|
154
|
-
let response;
|
|
155
|
-
try {
|
|
156
|
-
const action = browser_actions_1.BrowserActionSchema.parse(params);
|
|
157
|
-
response = await (0, browser_runner_1.handleBrowserInstruction)(action);
|
|
158
|
-
}
|
|
159
|
-
catch (error) {
|
|
160
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
161
|
-
console.log('Small hiccup, one sec...');
|
|
162
|
-
return JSON.stringify({
|
|
163
|
-
success: false,
|
|
164
|
-
error: `Browser action validation failed: ${errorMessage}`,
|
|
165
|
-
logs: [
|
|
166
|
-
{
|
|
167
|
-
type: 'error',
|
|
168
|
-
message: `Browser action validation failed: ${errorMessage}`,
|
|
169
|
-
timestamp: Date.now(),
|
|
170
|
-
source: 'tool',
|
|
171
|
-
},
|
|
172
|
-
],
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
finally {
|
|
176
|
-
spinner_1.Spinner.get().stop();
|
|
177
|
-
}
|
|
178
|
-
// Log any browser errors
|
|
179
|
-
if (!response.success && response.error) {
|
|
180
|
-
console.error((0, picocolors_1.red)(`Browser action failed: ${response.error}`));
|
|
181
|
-
}
|
|
182
|
-
if (response.logs) {
|
|
183
|
-
response.logs.forEach((log) => {
|
|
184
|
-
if (log.source === 'tool') {
|
|
185
|
-
switch (log.type) {
|
|
186
|
-
case 'error':
|
|
187
|
-
console.error((0, picocolors_1.red)(log.message));
|
|
188
|
-
break;
|
|
189
|
-
case 'warning':
|
|
190
|
-
console.warn((0, picocolors_1.yellow)(log.message));
|
|
191
|
-
break;
|
|
192
|
-
case 'info':
|
|
193
|
-
console.info((0, picocolors_1.cyan)(log.message));
|
|
194
|
-
break;
|
|
195
|
-
default:
|
|
196
|
-
console.log((0, picocolors_1.cyan)(log.message));
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
return JSON.stringify(response);
|
|
202
|
-
},
|
|
203
|
-
};
|
|
204
|
-
const handleToolCall = async (toolCall, projectPath) => {
|
|
205
|
-
const { name, parameters } = toolCall;
|
|
206
|
-
const handler = exports.toolHandlers[name];
|
|
207
|
-
if (!handler) {
|
|
208
|
-
throw new Error(`No handler found for tool: ${name}`);
|
|
209
|
-
}
|
|
210
|
-
const content = await handler(parameters, toolCall.id, projectPath);
|
|
211
|
-
if (typeof content !== 'string') {
|
|
212
|
-
throw new Error(`Tool call ${name} not supported. It returned non-string content.`);
|
|
213
|
-
}
|
|
214
|
-
// TODO: Add support for screenshots.
|
|
215
|
-
// const toolResultMessage: Message = {
|
|
216
|
-
// role: 'user',
|
|
217
|
-
// content: match(content)
|
|
218
|
-
// .with({ screenshots: P.not(P.nullish) }, (response) => [
|
|
219
|
-
// ...(response.screenshots.pre ? [response.screenshots.pre] : []),
|
|
220
|
-
// {
|
|
221
|
-
// type: 'text' as const,
|
|
222
|
-
// text:
|
|
223
|
-
// JSON.stringify({
|
|
224
|
-
// ...response,
|
|
225
|
-
// screenshots: undefined,
|
|
226
|
-
// }),
|
|
227
|
-
// },
|
|
228
|
-
// response.screenshots.post,
|
|
229
|
-
// ])
|
|
230
|
-
// .with(P.string, (str) => str)
|
|
231
|
-
// .otherwise((val) => JSON.stringify(val)),
|
|
232
|
-
// }
|
|
233
|
-
return {
|
|
234
|
-
name,
|
|
235
|
-
result: content,
|
|
236
|
-
id: toolCall.id,
|
|
237
|
-
};
|
|
238
|
-
};
|
|
239
|
-
exports.handleToolCall = handleToolCall;
|
|
240
|
-
//# sourceMappingURL=tool-handlers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool-handlers.js","sourceRoot":"","sources":["../src/tool-handlers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAqC;AACrC,2CAA4B;AAE5B,6CAAwC;AACxC,4CAAiD;AACjD,4DAA6E;AAE7E,iDAAkD;AAClD,+CAA8D;AAC9D,2CAAqD;AAErD,qDAA2D;AAC3D,6CAAyC;AACzC,+CAAqD;AACrD,+CAA6C;AAQtC,MAAM,eAAe,GAIvB,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,EAAE;IAC1C,MAAM,UAAU,GAAG,0BAAgB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;IACrD,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC5C,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAA,sBAAY,EAAC,WAAW,EAAE,CAAC,UAAU,CAAC,CAAC,CAAA;IAC9E,IAAI,MAAM,GAAa,EAAE,CAAA;IAEzB,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,IAAI,IAAA,kBAAK,EAAC,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC,GAAG,CAAA;QAC/C,MAAM,CAAC,IAAI,CAAC,YAAY,IAAI,gBAAgB,CAAC,CAAA;QAC7C,OAAO,CAAC,GAAG,CAAC,IAAA,kBAAK,EAAC,aAAa,IAAI,IAAI,MAAM,EAAE,CAAC,CAAC,CAAA;IACnD,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC5B,sDAAsD;QACtD,IAAI,UAAU,GAAG,CAAC,CAAA;QAClB,IAAI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B,CAAA;AACH,CAAC,CAAA;AA3CY,QAAA,cAAc,kBA2C1B"}
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
const bun_test_1 = require("bun:test");
|
|
8
|
-
const stream_1 = require("stream");
|
|
9
|
-
const tools_1 = require("../../common/constants/tools");
|
|
10
|
-
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
11
|
-
const tool_renderers_1 = require("../tool-renderers");
|
|
12
|
-
const xml_stream_parser_1 = require("../xml-stream-parser");
|
|
13
|
-
(0, bun_test_1.describe)('Tool renderers with XML parser', () => {
|
|
14
|
-
// Helper function to process XML through parser and get output
|
|
15
|
-
async function processXML(xml) {
|
|
16
|
-
let result = '';
|
|
17
|
-
const processor = (0, xml_stream_parser_1.createXMLStreamParser)(tool_renderers_1.toolRenderers);
|
|
18
|
-
const writable = new stream_1.Writable({
|
|
19
|
-
write(chunk, encoding, callback) {
|
|
20
|
-
result += chunk.toString();
|
|
21
|
-
callback();
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
processor.pipe(writable);
|
|
25
|
-
processor.write(xml);
|
|
26
|
-
processor.end();
|
|
27
|
-
// Wait for stream to finish
|
|
28
|
-
await new Promise((resolve) => {
|
|
29
|
-
writable.on('finish', resolve);
|
|
30
|
-
});
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
(0, bun_test_1.test)('formats write_file tool call', async () => {
|
|
34
|
-
const xml = (0, tools_1.getToolCallString)('write_file', {
|
|
35
|
-
path: 'test.ts',
|
|
36
|
-
content: 'console.log("test");',
|
|
37
|
-
});
|
|
38
|
-
const output = await processXML(xml);
|
|
39
|
-
const stripped = (0, strip_ansi_1.default)(output);
|
|
40
|
-
(0, bun_test_1.expect)(stripped).toBe('[Write File]\nEditing file at test.ts...\n');
|
|
41
|
-
});
|
|
42
|
-
(0, bun_test_1.test)('formats read_files tool call', async () => {
|
|
43
|
-
const xml = (0, tools_1.getToolCallString)('read_files', {
|
|
44
|
-
paths: 'file1.ts\nfile2.ts',
|
|
45
|
-
});
|
|
46
|
-
const output = await processXML(xml);
|
|
47
|
-
const stripped = (0, strip_ansi_1.default)(output);
|
|
48
|
-
(0, bun_test_1.expect)(stripped).toBe('[Read Files]\nfile1.ts\nfile2.ts\n');
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
//# sourceMappingURL=tool-renderers.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool-renderers.test.js","sourceRoot":"","sources":["../../../src/utils/__tests__/tool-renderers.test.ts"],"names":[],"mappings":";;;;;AAAA,aAAa;AACb,uCAAiD;AACjD,mCAAiC;AACjC,kDAA0D;AAC1D,4DAAkC;AAClC,sDAAiD;AACjD,4DAA4D;AAE5D,IAAA,mBAAQ,EAAC,gCAAgC,EAAE,GAAG,EAAE;IAC9C,+DAA+D;IAC/D,KAAK,UAAU,UAAU,CAAC,GAAW;QACnC,IAAI,MAAM,GAAG,EAAE,CAAA;QACf,MAAM,SAAS,GAAG,IAAA,yCAAqB,EAAC,8BAAa,CAAC,CAAA;QAEtD,MAAM,QAAQ,GAAG,IAAI,iBAAQ,CAAC;YAC5B,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ;gBAC7B,MAAM,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAA;gBAC1B,QAAQ,EAAE,CAAA;YACZ,CAAC;SACF,CAAC,CAAA;QAEF,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA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|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const stream_1 = require("stream");
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
const bun_test_1 = require("bun:test");
|
|
11
|
-
const tools_1 = require("../../common/constants/tools");
|
|
12
|
-
const strip_ansi_1 = __importDefault(require("strip-ansi"));
|
|
13
|
-
const tool_renderers_1 = require("../tool-renderers");
|
|
14
|
-
const xml_stream_parser_1 = require("../xml-stream-parser");
|
|
15
|
-
const toolRenderers = {
|
|
16
|
-
run_terminal_command: tool_renderers_1.defaultToolCallRenderer,
|
|
17
|
-
write_file: tool_renderers_1.defaultToolCallRenderer,
|
|
18
|
-
read_files: tool_renderers_1.defaultToolCallRenderer,
|
|
19
|
-
};
|
|
20
|
-
(0, bun_test_1.describe)('Saxy Stream Processor', () => {
|
|
21
|
-
(0, bun_test_1.test)('pipes output to writable stream', async () => {
|
|
22
|
-
const xml = (0, tools_1.getToolCallString)('run_terminal_command', {
|
|
23
|
-
command: 'echo hello',
|
|
24
|
-
});
|
|
25
|
-
let result = '';
|
|
26
|
-
const processor = (0, xml_stream_parser_1.createXMLStreamParser)(toolRenderers);
|
|
27
|
-
const writable = new stream_1.Writable({
|
|
28
|
-
write(chunk, encoding, callback) {
|
|
29
|
-
result += chunk.toString();
|
|
30
|
-
callback();
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
processor.pipe(writable);
|
|
34
|
-
processor.write(xml);
|
|
35
|
-
processor.end();
|
|
36
|
-
// Wait for the stream to finish
|
|
37
|
-
await new Promise((resolve) => {
|
|
38
|
-
writable.on('finish', resolve);
|
|
39
|
-
});
|
|
40
|
-
(0, bun_test_1.expect)(result).toContain('Run Terminal Command');
|
|
41
|
-
(0, bun_test_1.expect)(result).toContain('echo hello');
|
|
42
|
-
});
|
|
43
|
-
(0, bun_test_1.test)('handles multiple tool calls in sequence', async () => {
|
|
44
|
-
const xml = (0, tools_1.getToolCallString)('run_terminal_command', { command: 'ls' }) +
|
|
45
|
-
(0, tools_1.getToolCallString)('read_files', { paths: 'file.txt' });
|
|
46
|
-
let result = '';
|
|
47
|
-
const processor = (0, xml_stream_parser_1.createXMLStreamParser)(toolRenderers);
|
|
48
|
-
const writable = new stream_1.Writable({
|
|
49
|
-
write(chunk, encoding, callback) {
|
|
50
|
-
result += chunk.toString();
|
|
51
|
-
callback();
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
processor.pipe(writable);
|
|
55
|
-
processor.write(xml);
|
|
56
|
-
processor.end();
|
|
57
|
-
// Wait for the stream to finish
|
|
58
|
-
await new Promise((resolve) => {
|
|
59
|
-
writable.on('finish', resolve);
|
|
60
|
-
});
|
|
61
|
-
(0, bun_test_1.expect)(result).toContain('Run Terminal Command');
|
|
62
|
-
(0, bun_test_1.expect)(result).toContain('ls');
|
|
63
|
-
(0, bun_test_1.expect)(result).toContain('Read Files');
|
|
64
|
-
(0, bun_test_1.expect)(result).toContain('file.txt');
|
|
65
|
-
});
|
|
66
|
-
(0, bun_test_1.test)('handles text content between tool calls', async () => {
|
|
67
|
-
const xml = (0, tools_1.getToolCallString)('run_terminal_command', { command: 'ls' }) +
|
|
68
|
-
'Some text between tool calls' +
|
|
69
|
-
(0, tools_1.getToolCallString)('read_files', { paths: 'file.txt' });
|
|
70
|
-
let result = '';
|
|
71
|
-
const processor = (0, xml_stream_parser_1.createXMLStreamParser)(toolRenderers);
|
|
72
|
-
const writable = new stream_1.Writable({
|
|
73
|
-
write(chunk, encoding, callback) {
|
|
74
|
-
result += chunk.toString();
|
|
75
|
-
callback();
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
processor.pipe(writable);
|
|
79
|
-
processor.write(xml);
|
|
80
|
-
processor.end();
|
|
81
|
-
// Wait for the stream to finish
|
|
82
|
-
await new Promise((resolve) => {
|
|
83
|
-
writable.on('finish', resolve);
|
|
84
|
-
});
|
|
85
|
-
(0, bun_test_1.expect)(result).toContain('Run Terminal Command');
|
|
86
|
-
(0, bun_test_1.expect)(result).toContain('ls');
|
|
87
|
-
(0, bun_test_1.expect)(result).toContain('Some text between tool calls');
|
|
88
|
-
(0, bun_test_1.expect)(result).toContain('Read Files');
|
|
89
|
-
(0, bun_test_1.expect)(result).toContain('file.txt');
|
|
90
|
-
});
|
|
91
|
-
(0, bun_test_1.test)('processes chunks incrementally with output verification', async () => {
|
|
92
|
-
// Define chunks that will be written one at a time
|
|
93
|
-
const terminalCommand = (0, tools_1.getToolCallString)('run_terminal_command', {
|
|
94
|
-
command: 'npm install',
|
|
95
|
-
});
|
|
96
|
-
const codeSearch = (0, tools_1.getToolCallString)('code_search', { pattern: 'function' });
|
|
97
|
-
// Split the XML into chunks
|
|
98
|
-
const chunks = [
|
|
99
|
-
terminalCommand.slice(0, 15),
|
|
100
|
-
terminalCommand.slice(15, 30),
|
|
101
|
-
terminalCommand.slice(30, 40),
|
|
102
|
-
terminalCommand.slice(40, 50),
|
|
103
|
-
terminalCommand.slice(50),
|
|
104
|
-
codeSearch.slice(0, 15),
|
|
105
|
-
codeSearch.slice(15),
|
|
106
|
-
];
|
|
107
|
-
// Array to store output chunks as they're produced
|
|
108
|
-
const outputChunks = [];
|
|
109
|
-
// Create a writable stream that captures each output chunk
|
|
110
|
-
const writable = new stream_1.Writable({
|
|
111
|
-
write(chunk, encoding, callback) {
|
|
112
|
-
const chunkStr = chunk.toString();
|
|
113
|
-
outputChunks.push(chunkStr);
|
|
114
|
-
callback();
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
// Create the processor
|
|
118
|
-
const processor = (0, xml_stream_parser_1.createXMLStreamParser)(toolRenderers);
|
|
119
|
-
processor.pipe(writable);
|
|
120
|
-
// Process each chunk with a small delay between them
|
|
121
|
-
for (const chunk of chunks) {
|
|
122
|
-
processor.write(chunk);
|
|
123
|
-
// Small delay to simulate real-world streaming
|
|
124
|
-
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
125
|
-
}
|
|
126
|
-
processor.end();
|
|
127
|
-
// Wait for the stream to finish
|
|
128
|
-
await new Promise((resolve) => {
|
|
129
|
-
writable.on('finish', resolve);
|
|
130
|
-
});
|
|
131
|
-
// Verify the complete output
|
|
132
|
-
const fullOutput = (0, strip_ansi_1.default)(outputChunks.join(''));
|
|
133
|
-
(0, bun_test_1.expect)(fullOutput).toContain('Run Terminal Command');
|
|
134
|
-
(0, bun_test_1.expect)(fullOutput).toContain('npm install');
|
|
135
|
-
(0, bun_test_1.expect)(fullOutput).toContain('Code Search');
|
|
136
|
-
(0, bun_test_1.expect)(fullOutput).toContain('function');
|
|
137
|
-
// Verify incremental output - but don't make assumptions about which chunks contain what
|
|
138
|
-
// Just check that we got multiple output chunks (incremental processing)
|
|
139
|
-
(0, bun_test_1.expect)(outputChunks.length).toBeGreaterThan(1);
|
|
140
|
-
// Check that the terminal command appears before the code search in the output
|
|
141
|
-
const terminalCommandIndex = fullOutput.indexOf('Run Terminal Command');
|
|
142
|
-
const codeSearchIndex = fullOutput.indexOf('Code Search');
|
|
143
|
-
(0, bun_test_1.expect)(terminalCommandIndex).toBeLessThan(codeSearchIndex);
|
|
144
|
-
});
|
|
145
|
-
(0, bun_test_1.test)('processes text content incrementally', async () => {
|
|
146
|
-
// Define chunks that will be written one at a time
|
|
147
|
-
const chunks = ['hi', 'hi2', 'hi3 <yo>\nyo\n</yo>'];
|
|
148
|
-
// Array to store output chunks as they're produced
|
|
149
|
-
const outputChunks = [];
|
|
150
|
-
// Create a writable stream that captures each output chunk
|
|
151
|
-
const writable = new stream_1.Writable({
|
|
152
|
-
write(chunk, encoding, callback) {
|
|
153
|
-
const chunkStr = chunk.toString();
|
|
154
|
-
outputChunks.push(chunkStr);
|
|
155
|
-
callback();
|
|
156
|
-
},
|
|
157
|
-
});
|
|
158
|
-
// Create the processor
|
|
159
|
-
const processor = (0, xml_stream_parser_1.createXMLStreamParser)(toolRenderers);
|
|
160
|
-
processor.pipe(writable);
|
|
161
|
-
// Process each chunk with a small delay between them
|
|
162
|
-
for (const chunk of chunks) {
|
|
163
|
-
processor.write(chunk);
|
|
164
|
-
// Small delay to simulate real-world streaming
|
|
165
|
-
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
166
|
-
}
|
|
167
|
-
processor.end();
|
|
168
|
-
// Wait for the stream to finish
|
|
169
|
-
await new Promise((resolve) => {
|
|
170
|
-
writable.on('finish', resolve);
|
|
171
|
-
});
|
|
172
|
-
// Verify the complete output
|
|
173
|
-
const fullOutput = outputChunks.join('');
|
|
174
|
-
(0, bun_test_1.expect)(fullOutput).toEqual('hihi2hi3 <yo>\nyo\n</yo>');
|
|
175
|
-
(0, bun_test_1.expect)(outputChunks.length).toBeGreaterThan(3);
|
|
176
|
-
});
|
|
177
|
-
(0, bun_test_1.test)('real world example write to 4 files', async () => {
|
|
178
|
-
// Read the file content directly - no need for complex unescaping
|
|
179
|
-
const response = fs_1.default.readFileSync(path_1.default.join(__dirname, './response-example-4-files.txt'), 'utf-8');
|
|
180
|
-
// Array to store output chunks as they're produced
|
|
181
|
-
const outputChunks = [];
|
|
182
|
-
// Create a writable stream that captures each output chunk
|
|
183
|
-
const writable = new stream_1.Writable({
|
|
184
|
-
write(chunk, encoding, callback) {
|
|
185
|
-
const chunkStr = chunk.toString();
|
|
186
|
-
outputChunks.push(chunkStr);
|
|
187
|
-
callback();
|
|
188
|
-
},
|
|
189
|
-
});
|
|
190
|
-
let writeFileStartCount = 0;
|
|
191
|
-
let writeFileEndCount = 0;
|
|
192
|
-
const testToolRenderers = {
|
|
193
|
-
...toolRenderers,
|
|
194
|
-
write_file: {
|
|
195
|
-
...tool_renderers_1.defaultToolCallRenderer,
|
|
196
|
-
onToolStart: (toolName) => {
|
|
197
|
-
writeFileStartCount++;
|
|
198
|
-
return 'Write File';
|
|
199
|
-
},
|
|
200
|
-
onParamStart: (paramName, toolName) => {
|
|
201
|
-
return null;
|
|
202
|
-
},
|
|
203
|
-
onParamEnd: (paramName, toolName, content) => {
|
|
204
|
-
return null;
|
|
205
|
-
},
|
|
206
|
-
onToolEnd: (toolName, params) => {
|
|
207
|
-
writeFileEndCount++;
|
|
208
|
-
return null;
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
};
|
|
212
|
-
// Create the processor
|
|
213
|
-
const processor = (0, xml_stream_parser_1.createXMLStreamParser)(testToolRenderers);
|
|
214
|
-
processor.pipe(writable);
|
|
215
|
-
processor.write(response);
|
|
216
|
-
processor.end();
|
|
217
|
-
// Wait for the stream to finish
|
|
218
|
-
await new Promise((resolve) => {
|
|
219
|
-
writable.on('finish', resolve);
|
|
220
|
-
});
|
|
221
|
-
// Verify the complete output
|
|
222
|
-
const fullOutput = outputChunks.join('');
|
|
223
|
-
(0, bun_test_1.expect)(fullOutput).toContain('Write File'); // Check for expected output without worrying about formatting
|
|
224
|
-
(0, bun_test_1.expect)(writeFileEndCount).toBe(4);
|
|
225
|
-
// We expect multiple chunks for a large response
|
|
226
|
-
(0, bun_test_1.expect)(outputChunks.length).toBeGreaterThan(1);
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
//# sourceMappingURL=xml-stream-parser.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"xml-stream-parser.test.js","sourceRoot":"","sources":["../../../src/utils/__tests__/xml-stream-parser.test.ts"],"names":[],"mappings":";;;;;AAAA,4CAAmB;AACnB,gDAAuB;AACvB,mCAAiC;AAEjC,aAAa;AACb,uCAAiD;AACjD,kDAA0D;AAC1D,4DAAkC;AAElC,sDAA2D;AAC3D,4DAA4D;AAE5D,MAAM,aAAa,GAAG;IACpB,oBAAoB,EAAE,wCAAuB;IAC7C,UAAU,EAAE,wCAAuB;IACnC,UAAU,EAAE,wCAAuB;CACpC,CAAA;AAED,IAAA,mBAAQ,EAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,IAAA,eAAI,EAAC,iCAAiC,EAAE,KAAK,IAAI,EAAE;Q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AC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACjC,iDAAiD;QACjD,IAAA,iBAAM,EAAC,YAAY,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,CAAA;IAChD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/dist/utils/analytics.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.identified = void 0;
|
|
4
|
-
exports.initAnalytics = initAnalytics;
|
|
5
|
-
exports.flushAnalytics = flushAnalytics;
|
|
6
|
-
exports.trackEvent = trackEvent;
|
|
7
|
-
exports.identifyUser = identifyUser;
|
|
8
|
-
const posthog_node_1 = require("posthog-node");
|
|
9
|
-
// Store the identified user ID
|
|
10
|
-
let currentUserId;
|
|
11
|
-
let client;
|
|
12
|
-
exports.identified = false;
|
|
13
|
-
function initAnalytics() {
|
|
14
|
-
if (!process.env.NEXT_PUBLIC_POSTHOG_API_KEY ||
|
|
15
|
-
!process.env.NEXT_PUBLIC_APP_URL) {
|
|
16
|
-
throw new Error('NEXT_PUBLIC_POSTHOG_API_KEY or NEXT_PUBLIC_APP_URL is not set');
|
|
17
|
-
}
|
|
18
|
-
client = new posthog_node_1.PostHog(process.env.NEXT_PUBLIC_POSTHOG_API_KEY, {
|
|
19
|
-
host: `${process.env.NEXT_PUBLIC_APP_URL}/ingest`,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
async function flushAnalytics() {
|
|
23
|
-
if (!client) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
await client.flush();
|
|
27
|
-
}
|
|
28
|
-
function trackEvent(event, properties) {
|
|
29
|
-
const distinctId = currentUserId;
|
|
30
|
-
if (!distinctId) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
if (!client) {
|
|
34
|
-
throw new Error('Analytics client not initialized');
|
|
35
|
-
}
|
|
36
|
-
if (process.env.NEXT_PUBLIC_CB_ENVIRONMENT !== 'production') {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
client.capture({
|
|
40
|
-
distinctId,
|
|
41
|
-
event,
|
|
42
|
-
properties,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
function identifyUser(userId, properties) {
|
|
46
|
-
// Store the user ID for future events
|
|
47
|
-
currentUserId = userId;
|
|
48
|
-
if (!client) {
|
|
49
|
-
throw new Error('Analytics client not initialized');
|
|
50
|
-
}
|
|
51
|
-
if (process.env.NEXT_PUBLIC_CB_ENVIRONMENT !== 'production') {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
client.identify({
|
|
55
|
-
distinctId: userId,
|
|
56
|
-
properties,
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
//# sourceMappingURL=analytics.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"analytics.js","sourceRoot":"","sources":["../../src/utils/analytics.ts"],"names":[],"mappings":";;;AASA,sCAaC;AAED,wCAKC;AAED,gCAqBC;AAED,oCAgBC;AArED,+CAAsC;AAEtC,+BAA+B;AAC/B,IAAI,aAAiC,CAAA;AACrC,IAAI,MAA2B,CAAA;AAEpB,QAAA,UAAU,GAAY,KAAK,CAAA;AAEtC,SAAgB,aAAa;IAC3B,IACE,CAAC,OAAO,CAAC,GAAG,CAAC,2BAA2B;QACxC,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAChC,CAAC;QACD,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAA;IACH,CAAC;IAED,MAAM,GAAG,IAAI,sBAAO,CAAC,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE;QAC5D,IAAI,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,SAAS;KAClD,CAAC,CAAA;AACJ,CAAC;AAEM,KAAK,UAAU,cAAc;IAClC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ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