locdotech-ai 1.0.0
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/README.md +104 -0
- package/bin/ai.js +16 -0
- package/dist/api/client.d.ts +75 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +86 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/index.d.ts +4 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +4 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/streaming.d.ts +15 -0
- package/dist/api/streaming.d.ts.map +1 -0
- package/dist/api/streaming.js +87 -0
- package/dist/api/streaming.js.map +1 -0
- package/dist/api/websocket.d.ts +20 -0
- package/dist/api/websocket.d.ts.map +1 -0
- package/dist/api/websocket.js +80 -0
- package/dist/api/websocket.js.map +1 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +72 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/clear.d.ts +3 -0
- package/dist/commands/clear.d.ts.map +1 -0
- package/dist/commands/clear.js +13 -0
- package/dist/commands/clear.js.map +1 -0
- package/dist/commands/config.d.ts +3 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +116 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/help.d.ts +3 -0
- package/dist/commands/help.d.ts.map +1 -0
- package/dist/commands/help.js +42 -0
- package/dist/commands/help.js.map +1 -0
- package/dist/commands/history.d.ts +3 -0
- package/dist/commands/history.d.ts.map +1 -0
- package/dist/commands/history.js +62 -0
- package/dist/commands/history.js.map +1 -0
- package/dist/commands/index.d.ts +30 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +54 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/commands/model.d.ts +3 -0
- package/dist/commands/model.d.ts.map +1 -0
- package/dist/commands/model.js +57 -0
- package/dist/commands/model.js.map +1 -0
- package/dist/commands/quit.d.ts +3 -0
- package/dist/commands/quit.d.ts.map +1 -0
- package/dist/commands/quit.js +16 -0
- package/dist/commands/quit.js.map +1 -0
- package/dist/commands/status.d.ts +3 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/status.js +39 -0
- package/dist/commands/status.js.map +1 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +2 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/settings.d.ts +18 -0
- package/dist/config/settings.d.ts.map +1 -0
- package/dist/config/settings.js +56 -0
- package/dist/config/settings.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +100 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/bash.d.ts +41 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +100 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/file.d.ts +107 -0
- package/dist/tools/file.d.ts.map +1 -0
- package/dist/tools/file.js +189 -0
- package/dist/tools/file.js.map +1 -0
- package/dist/tools/glob.d.ts +38 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/glob.js +84 -0
- package/dist/tools/glob.js.map +1 -0
- package/dist/tools/grep.d.ts +76 -0
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +166 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/index.d.ts +29 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +130 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/mcp.d.ts +59 -0
- package/dist/tools/mcp.d.ts.map +1 -0
- package/dist/tools/mcp.js +155 -0
- package/dist/tools/mcp.js.map +1 -0
- package/dist/ui/App.d.ts +6 -0
- package/dist/ui/App.d.ts.map +1 -0
- package/dist/ui/App.js +161 -0
- package/dist/ui/App.js.map +1 -0
- package/dist/ui/components/CodeBlock.d.ts +9 -0
- package/dist/ui/components/CodeBlock.d.ts.map +1 -0
- package/dist/ui/components/CodeBlock.js +83 -0
- package/dist/ui/components/CodeBlock.js.map +1 -0
- package/dist/ui/components/Input.d.ts +11 -0
- package/dist/ui/components/Input.d.ts.map +1 -0
- package/dist/ui/components/Input.js +93 -0
- package/dist/ui/components/Input.js.map +1 -0
- package/dist/ui/components/Message.d.ts +7 -0
- package/dist/ui/components/Message.d.ts.map +1 -0
- package/dist/ui/components/Message.js +86 -0
- package/dist/ui/components/Message.js.map +1 -0
- package/dist/ui/components/ModelSelector.d.ts +7 -0
- package/dist/ui/components/ModelSelector.d.ts.map +1 -0
- package/dist/ui/components/ModelSelector.js +23 -0
- package/dist/ui/components/ModelSelector.js.map +1 -0
- package/dist/ui/components/Permission.d.ts +9 -0
- package/dist/ui/components/Permission.d.ts.map +1 -0
- package/dist/ui/components/Permission.js +41 -0
- package/dist/ui/components/Permission.js.map +1 -0
- package/dist/ui/components/StatusBar.d.ts +11 -0
- package/dist/ui/components/StatusBar.d.ts.map +1 -0
- package/dist/ui/components/StatusBar.js +9 -0
- package/dist/ui/components/StatusBar.js.map +1 -0
- package/dist/ui/components/TaskList.d.ts +12 -0
- package/dist/ui/components/TaskList.d.ts.map +1 -0
- package/dist/ui/components/TaskList.js +21 -0
- package/dist/ui/components/TaskList.js.map +1 -0
- package/dist/ui/components/ToolCall.d.ts +16 -0
- package/dist/ui/components/ToolCall.d.ts.map +1 -0
- package/dist/ui/components/ToolCall.js +50 -0
- package/dist/ui/components/ToolCall.js.map +1 -0
- package/dist/ui/components/index.d.ts +8 -0
- package/dist/ui/components/index.d.ts.map +1 -0
- package/dist/ui/components/index.js +8 -0
- package/dist/ui/components/index.js.map +1 -0
- package/dist/ui/hooks/index.d.ts +4 -0
- package/dist/ui/hooks/index.d.ts.map +1 -0
- package/dist/ui/hooks/index.js +4 -0
- package/dist/ui/hooks/index.js.map +1 -0
- package/dist/ui/hooks/useChat.d.ts +42 -0
- package/dist/ui/hooks/useChat.d.ts.map +1 -0
- package/dist/ui/hooks/useChat.js +305 -0
- package/dist/ui/hooks/useChat.js.map +1 -0
- package/dist/ui/hooks/useHistory.d.ts +14 -0
- package/dist/ui/hooks/useHistory.d.ts.map +1 -0
- package/dist/ui/hooks/useHistory.js +123 -0
- package/dist/ui/hooks/useHistory.js.map +1 -0
- package/dist/ui/hooks/useTools.d.ts +19 -0
- package/dist/ui/hooks/useTools.d.ts.map +1 -0
- package/dist/ui/hooks/useTools.js +54 -0
- package/dist/ui/hooks/useTools.js.map +1 -0
- package/dist/ui/themes/index.d.ts +21 -0
- package/dist/ui/themes/index.d.ts.map +1 -0
- package/dist/ui/themes/index.js +40 -0
- package/dist/ui/themes/index.js.map +1 -0
- package/dist/utils/auth.d.ts +5 -0
- package/dist/utils/auth.d.ts.map +1 -0
- package/dist/utils/auth.js +42 -0
- package/dist/utils/auth.js.map +1 -0
- package/dist/utils/format.d.ts +11 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +71 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +18 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +61 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +64 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { render } from 'ink';
|
|
4
|
+
import { parseArgs } from './cli.js';
|
|
5
|
+
import { App } from './ui/App.js';
|
|
6
|
+
import { hasApiKey, promptForApiKey } from './utils/auth.js';
|
|
7
|
+
import { loadSettings } from './config/index.js';
|
|
8
|
+
import { client } from './api/client.js';
|
|
9
|
+
// Non-interactive mode: send prompt and print response
|
|
10
|
+
async function runNonInteractive(prompt) {
|
|
11
|
+
const settings = loadSettings();
|
|
12
|
+
console.log(`\n[Model: ${settings.model}]\n`);
|
|
13
|
+
console.log(`You: ${prompt}\n`);
|
|
14
|
+
console.log('AI: ');
|
|
15
|
+
const messages = [
|
|
16
|
+
{ role: 'user', content: prompt }
|
|
17
|
+
];
|
|
18
|
+
const request = {
|
|
19
|
+
model: settings.model,
|
|
20
|
+
messages,
|
|
21
|
+
stream: true,
|
|
22
|
+
max_tokens: settings.maxTokens,
|
|
23
|
+
temperature: settings.temperature,
|
|
24
|
+
};
|
|
25
|
+
try {
|
|
26
|
+
let fullResponse = '';
|
|
27
|
+
for await (const chunk of client.chatStream(request)) {
|
|
28
|
+
const choice = chunk.choices[0];
|
|
29
|
+
if (choice?.delta?.content) {
|
|
30
|
+
process.stdout.write(choice.delta.content);
|
|
31
|
+
fullResponse += choice.delta.content;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
console.log('\n');
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.error('\nError:', error instanceof Error ? error.message : String(error));
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Check if running in a TTY (interactive terminal)
|
|
42
|
+
function isTTY() {
|
|
43
|
+
return process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
44
|
+
}
|
|
45
|
+
async function main() {
|
|
46
|
+
try {
|
|
47
|
+
// Parse command line arguments
|
|
48
|
+
const { prompt, options } = parseArgs();
|
|
49
|
+
// Check for API key
|
|
50
|
+
if (!hasApiKey()) {
|
|
51
|
+
if (!isTTY()) {
|
|
52
|
+
console.error('API key is required. Set it with: ai --api-key <your-key>');
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
const key = await promptForApiKey();
|
|
56
|
+
if (!key) {
|
|
57
|
+
console.error('API key is required to use AI Router CLI.');
|
|
58
|
+
console.error('Set it with: ai --api-key <your-key>');
|
|
59
|
+
console.error('Or use: /config apiKey <your-key>');
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Load settings
|
|
64
|
+
const settings = loadSettings();
|
|
65
|
+
// If prompt is provided and not in TTY, use non-interactive mode
|
|
66
|
+
if (prompt && !isTTY()) {
|
|
67
|
+
await runNonInteractive(prompt);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// If prompt provided but in TTY, still show header
|
|
71
|
+
if (!isTTY() && !prompt) {
|
|
72
|
+
console.error('Interactive mode requires a TTY terminal.');
|
|
73
|
+
console.error('Usage: ai "your prompt here"');
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
// Startup info is shown by WelcomeHeader component in the React app
|
|
77
|
+
// Render the React/Ink application
|
|
78
|
+
const { waitUntilExit } = render(React.createElement(App, { initialPrompt: prompt }));
|
|
79
|
+
await waitUntilExit();
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
console.error('Fatal error:', error instanceof Error ? error.message : String(error));
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Handle uncaught errors
|
|
87
|
+
process.on('uncaughtException', (error) => {
|
|
88
|
+
console.error('Uncaught exception:', error.message);
|
|
89
|
+
process.exit(1);
|
|
90
|
+
});
|
|
91
|
+
process.on('unhandledRejection', (reason) => {
|
|
92
|
+
console.error('Unhandled rejection:', reason);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
});
|
|
95
|
+
// Run main
|
|
96
|
+
main().catch((error) => {
|
|
97
|
+
console.error('Failed to start:', error);
|
|
98
|
+
process.exit(1);
|
|
99
|
+
});
|
|
100
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;A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K,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;IACzC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface BashResult {
|
|
2
|
+
stdout: string;
|
|
3
|
+
stderr: string;
|
|
4
|
+
exitCode: number;
|
|
5
|
+
error?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface BashOptions {
|
|
8
|
+
cwd?: string;
|
|
9
|
+
timeout?: number;
|
|
10
|
+
env?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
export declare function executeBash(command: string, options?: BashOptions): Promise<BashResult>;
|
|
13
|
+
export declare class BashTool {
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
parameters: {
|
|
17
|
+
type: string;
|
|
18
|
+
properties: {
|
|
19
|
+
command: {
|
|
20
|
+
type: string;
|
|
21
|
+
description: string;
|
|
22
|
+
};
|
|
23
|
+
cwd: {
|
|
24
|
+
type: string;
|
|
25
|
+
description: string;
|
|
26
|
+
};
|
|
27
|
+
timeout: {
|
|
28
|
+
type: string;
|
|
29
|
+
description: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
required: string[];
|
|
33
|
+
};
|
|
34
|
+
execute(params: {
|
|
35
|
+
command: string;
|
|
36
|
+
cwd?: string;
|
|
37
|
+
timeout?: number;
|
|
38
|
+
}): Promise<BashResult>;
|
|
39
|
+
}
|
|
40
|
+
export declare const bashTool: BashTool;
|
|
41
|
+
//# sourceMappingURL=bash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../src/tools/bash.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAKD,wBAAsB,WAAW,CAC/B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,UAAU,CAAC,CA0ErB;AAED,qBAAa,QAAQ;IACnB,IAAI,SAAU;IACd,WAAW,SAAsC;IAEjD,UAAU;;;;;;;;;;;;;;;;;MAiBR;IAEI,OAAO,CAAC,MAAM,EAAE;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,UAAU,CAAC;CAMxB;AAED,eAAO,MAAM,QAAQ,UAAiB,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import * as os from 'os';
|
|
3
|
+
const DEFAULT_TIMEOUT = 120000; // 2 minutes
|
|
4
|
+
const MAX_OUTPUT_LENGTH = 30000;
|
|
5
|
+
export async function executeBash(command, options = {}) {
|
|
6
|
+
const { cwd = process.cwd(), timeout = DEFAULT_TIMEOUT, env } = options;
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
const isWindows = os.platform() === 'win32';
|
|
9
|
+
const shell = isWindows ? 'cmd.exe' : '/bin/bash';
|
|
10
|
+
const shellArgs = isWindows ? ['/c', command] : ['-c', command];
|
|
11
|
+
const spawnOptions = {
|
|
12
|
+
cwd,
|
|
13
|
+
shell: false,
|
|
14
|
+
env: { ...process.env, ...env },
|
|
15
|
+
windowsHide: true,
|
|
16
|
+
};
|
|
17
|
+
const proc = spawn(shell, shellArgs, spawnOptions);
|
|
18
|
+
let stdout = '';
|
|
19
|
+
let stderr = '';
|
|
20
|
+
let killed = false;
|
|
21
|
+
const timeoutId = setTimeout(() => {
|
|
22
|
+
killed = true;
|
|
23
|
+
proc.kill('SIGTERM');
|
|
24
|
+
setTimeout(() => {
|
|
25
|
+
if (!proc.killed) {
|
|
26
|
+
proc.kill('SIGKILL');
|
|
27
|
+
}
|
|
28
|
+
}, 5000);
|
|
29
|
+
}, timeout);
|
|
30
|
+
proc.stdout?.on('data', (data) => {
|
|
31
|
+
stdout += data.toString();
|
|
32
|
+
if (stdout.length > MAX_OUTPUT_LENGTH) {
|
|
33
|
+
stdout = stdout.slice(0, MAX_OUTPUT_LENGTH) + '\n... (output truncated)';
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
proc.stderr?.on('data', (data) => {
|
|
37
|
+
stderr += data.toString();
|
|
38
|
+
if (stderr.length > MAX_OUTPUT_LENGTH) {
|
|
39
|
+
stderr = stderr.slice(0, MAX_OUTPUT_LENGTH) + '\n... (output truncated)';
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
proc.on('close', (code) => {
|
|
43
|
+
clearTimeout(timeoutId);
|
|
44
|
+
if (killed) {
|
|
45
|
+
resolve({
|
|
46
|
+
stdout,
|
|
47
|
+
stderr,
|
|
48
|
+
exitCode: -1,
|
|
49
|
+
error: `Command timed out after ${timeout}ms`,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
resolve({
|
|
54
|
+
stdout,
|
|
55
|
+
stderr,
|
|
56
|
+
exitCode: code ?? 0,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
proc.on('error', (err) => {
|
|
61
|
+
clearTimeout(timeoutId);
|
|
62
|
+
resolve({
|
|
63
|
+
stdout,
|
|
64
|
+
stderr,
|
|
65
|
+
exitCode: -1,
|
|
66
|
+
error: err.message,
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
export class BashTool {
|
|
72
|
+
name = 'Bash';
|
|
73
|
+
description = 'Execute bash commands in a shell';
|
|
74
|
+
parameters = {
|
|
75
|
+
type: 'object',
|
|
76
|
+
properties: {
|
|
77
|
+
command: {
|
|
78
|
+
type: 'string',
|
|
79
|
+
description: 'The command to execute',
|
|
80
|
+
},
|
|
81
|
+
cwd: {
|
|
82
|
+
type: 'string',
|
|
83
|
+
description: 'Working directory for the command',
|
|
84
|
+
},
|
|
85
|
+
timeout: {
|
|
86
|
+
type: 'number',
|
|
87
|
+
description: 'Timeout in milliseconds (max 600000)',
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
required: ['command'],
|
|
91
|
+
};
|
|
92
|
+
async execute(params) {
|
|
93
|
+
return executeBash(params.command, {
|
|
94
|
+
cwd: params.cwd,
|
|
95
|
+
timeout: params.timeout,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export const bashTool = new BashTool();
|
|
100
|
+
//# sourceMappingURL=bash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bash.js","sourceRoot":"","sources":["../../src/tools/bash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAgB,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAezB,MAAM,eAAe,GAAG,MAAM,CAAC,CAAC,YAAY;AAC5C,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAEhC,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAe,EACf,UAAuB,EAAE;IAEzB,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,GAAG,eAAe,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IAExE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,MAAM,SAAS,GAAG,EAAE,CAAC,QAAQ,EAAE,KAAK,OAAO,CAAC;QAC5C,MAAM,KAAK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AAE;gBACH,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,mCAAmC;aACjD;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,sCAAsC;aACpD;SACF;QACD,QAAQ,EAAE,CAAC,SAAS,CAAC;KACtB,CAAC;IAEF,KAAK,CAAC,OAAO,CAAC,MAIb;QACC,OAAO,WAAW,CAAC,MAAM,CAAC,OAAO,EAAE;YACjC,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
export interface ReadResult {
|
|
2
|
+
content: string;
|
|
3
|
+
lineCount: number;
|
|
4
|
+
truncated: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface WriteResult {
|
|
7
|
+
success: boolean;
|
|
8
|
+
path: string;
|
|
9
|
+
error?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface EditResult {
|
|
12
|
+
success: boolean;
|
|
13
|
+
matchCount: number;
|
|
14
|
+
error?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function readFile(filePath: string, options?: {
|
|
17
|
+
offset?: number;
|
|
18
|
+
limit?: number;
|
|
19
|
+
}): Promise<ReadResult>;
|
|
20
|
+
export declare function writeFile(filePath: string, content: string): Promise<WriteResult>;
|
|
21
|
+
export declare function editFile(filePath: string, oldString: string, newString: string, replaceAll?: boolean): Promise<EditResult>;
|
|
22
|
+
export declare class ReadTool {
|
|
23
|
+
name: string;
|
|
24
|
+
description: string;
|
|
25
|
+
parameters: {
|
|
26
|
+
type: string;
|
|
27
|
+
properties: {
|
|
28
|
+
file_path: {
|
|
29
|
+
type: string;
|
|
30
|
+
description: string;
|
|
31
|
+
};
|
|
32
|
+
offset: {
|
|
33
|
+
type: string;
|
|
34
|
+
description: string;
|
|
35
|
+
};
|
|
36
|
+
limit: {
|
|
37
|
+
type: string;
|
|
38
|
+
description: string;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
required: string[];
|
|
42
|
+
};
|
|
43
|
+
execute(params: {
|
|
44
|
+
file_path: string;
|
|
45
|
+
offset?: number;
|
|
46
|
+
limit?: number;
|
|
47
|
+
}): Promise<ReadResult>;
|
|
48
|
+
}
|
|
49
|
+
export declare class WriteTool {
|
|
50
|
+
name: string;
|
|
51
|
+
description: string;
|
|
52
|
+
parameters: {
|
|
53
|
+
type: string;
|
|
54
|
+
properties: {
|
|
55
|
+
file_path: {
|
|
56
|
+
type: string;
|
|
57
|
+
description: string;
|
|
58
|
+
};
|
|
59
|
+
content: {
|
|
60
|
+
type: string;
|
|
61
|
+
description: string;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
required: string[];
|
|
65
|
+
};
|
|
66
|
+
execute(params: {
|
|
67
|
+
file_path: string;
|
|
68
|
+
content: string;
|
|
69
|
+
}): Promise<WriteResult>;
|
|
70
|
+
}
|
|
71
|
+
export declare class EditTool {
|
|
72
|
+
name: string;
|
|
73
|
+
description: string;
|
|
74
|
+
parameters: {
|
|
75
|
+
type: string;
|
|
76
|
+
properties: {
|
|
77
|
+
file_path: {
|
|
78
|
+
type: string;
|
|
79
|
+
description: string;
|
|
80
|
+
};
|
|
81
|
+
old_string: {
|
|
82
|
+
type: string;
|
|
83
|
+
description: string;
|
|
84
|
+
};
|
|
85
|
+
new_string: {
|
|
86
|
+
type: string;
|
|
87
|
+
description: string;
|
|
88
|
+
};
|
|
89
|
+
replace_all: {
|
|
90
|
+
type: string;
|
|
91
|
+
description: string;
|
|
92
|
+
default: boolean;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
required: string[];
|
|
96
|
+
};
|
|
97
|
+
execute(params: {
|
|
98
|
+
file_path: string;
|
|
99
|
+
old_string: string;
|
|
100
|
+
new_string: string;
|
|
101
|
+
replace_all?: boolean;
|
|
102
|
+
}): Promise<EditResult>;
|
|
103
|
+
}
|
|
104
|
+
export declare const readTool: ReadTool;
|
|
105
|
+
export declare const writeTool: WriteTool;
|
|
106
|
+
export declare const editTool: EditTool;
|
|
107
|
+
//# sourceMappingURL=file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.d.ts","sourceRoot":"","sources":["../../src/tools/file.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAKD,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5C,OAAO,CAAC,UAAU,CAAC,CAiCrB;AAED,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,WAAW,CAAC,CAyBtB;AAED,wBAAsB,QAAQ,CAC5B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,UAAU,UAAQ,GACjB,OAAO,CAAC,UAAU,CAAC,CAqDrB;AAMD,qBAAa,QAAQ;IACnB,IAAI,SAAU;IACd,WAAW,SAAqC;IAEhD,UAAU;;;;;;;;;;;;;;;;;MAiBR;IAEI,OAAO,CAAC,MAAM,EAAE;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,GAAG,OAAO,CAAC,UAAU,CAAC;CAMxB;AAED,qBAAa,SAAS;IACpB,IAAI,SAAW;IACf,WAAW,SAA6B;IAExC,UAAU;;;;;;;;;;;;;MAaR;IAEI,OAAO,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC;CAGpF;AAED,qBAAa,QAAQ;IACnB,IAAI,SAAU;IACd,WAAW,SAAmC;IAE9C,UAAU;;;;;;;;;;;;;;;;;;;;;;MAsBR;IAEI,OAAO,CAAC,MAAM,EAAE;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,CAAC,EAAE,OAAO,CAAC;KACvB,GAAG,OAAO,CAAC,UAAU,CAAC;CAQxB;AAED,eAAO,MAAM,QAAQ,UAAiB,CAAC;AACvC,eAAO,MAAM,SAAS,WAAkB,CAAC;AACzC,eAAO,MAAM,QAAQ,UAAiB,CAAC"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
const MAX_LINES = 2000;
|
|
4
|
+
const MAX_LINE_LENGTH = 2000;
|
|
5
|
+
export async function readFile(filePath, options) {
|
|
6
|
+
const { offset = 0, limit = MAX_LINES } = options || {};
|
|
7
|
+
const absolutePath = path.isAbsolute(filePath)
|
|
8
|
+
? filePath
|
|
9
|
+
: path.resolve(process.cwd(), filePath);
|
|
10
|
+
if (!fs.existsSync(absolutePath)) {
|
|
11
|
+
throw new Error(`File not found: ${absolutePath}`);
|
|
12
|
+
}
|
|
13
|
+
const content = fs.readFileSync(absolutePath, 'utf-8');
|
|
14
|
+
const lines = content.split('\n');
|
|
15
|
+
const startLine = offset;
|
|
16
|
+
const endLine = Math.min(startLine + limit, lines.length);
|
|
17
|
+
const selectedLines = lines.slice(startLine, endLine);
|
|
18
|
+
// Format with line numbers
|
|
19
|
+
const numberedLines = selectedLines.map((line, i) => {
|
|
20
|
+
const lineNum = startLine + i + 1;
|
|
21
|
+
const truncatedLine = line.length > MAX_LINE_LENGTH
|
|
22
|
+
? line.slice(0, MAX_LINE_LENGTH) + '...'
|
|
23
|
+
: line;
|
|
24
|
+
return `${String(lineNum).padStart(6)}\t${truncatedLine}`;
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
content: numberedLines.join('\n'),
|
|
28
|
+
lineCount: lines.length,
|
|
29
|
+
truncated: endLine < lines.length,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export async function writeFile(filePath, content) {
|
|
33
|
+
try {
|
|
34
|
+
const absolutePath = path.isAbsolute(filePath)
|
|
35
|
+
? filePath
|
|
36
|
+
: path.resolve(process.cwd(), filePath);
|
|
37
|
+
// Ensure directory exists
|
|
38
|
+
const dir = path.dirname(absolutePath);
|
|
39
|
+
if (!fs.existsSync(dir)) {
|
|
40
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
41
|
+
}
|
|
42
|
+
fs.writeFileSync(absolutePath, content, 'utf-8');
|
|
43
|
+
return {
|
|
44
|
+
success: true,
|
|
45
|
+
path: absolutePath,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
return {
|
|
50
|
+
success: false,
|
|
51
|
+
path: filePath,
|
|
52
|
+
error: error instanceof Error ? error.message : String(error),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export async function editFile(filePath, oldString, newString, replaceAll = false) {
|
|
57
|
+
try {
|
|
58
|
+
const absolutePath = path.isAbsolute(filePath)
|
|
59
|
+
? filePath
|
|
60
|
+
: path.resolve(process.cwd(), filePath);
|
|
61
|
+
if (!fs.existsSync(absolutePath)) {
|
|
62
|
+
throw new Error(`File not found: ${absolutePath}`);
|
|
63
|
+
}
|
|
64
|
+
let content = fs.readFileSync(absolutePath, 'utf-8');
|
|
65
|
+
// Count matches
|
|
66
|
+
const regex = new RegExp(escapeRegExp(oldString), 'g');
|
|
67
|
+
const matches = content.match(regex);
|
|
68
|
+
const matchCount = matches ? matches.length : 0;
|
|
69
|
+
if (matchCount === 0) {
|
|
70
|
+
return {
|
|
71
|
+
success: false,
|
|
72
|
+
matchCount: 0,
|
|
73
|
+
error: 'No matches found for the specified text',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (matchCount > 1 && !replaceAll) {
|
|
77
|
+
return {
|
|
78
|
+
success: false,
|
|
79
|
+
matchCount,
|
|
80
|
+
error: `Found ${matchCount} matches. Use replaceAll option to replace all occurrences.`,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// Perform replacement
|
|
84
|
+
if (replaceAll) {
|
|
85
|
+
content = content.replace(regex, newString);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
content = content.replace(oldString, newString);
|
|
89
|
+
}
|
|
90
|
+
fs.writeFileSync(absolutePath, content, 'utf-8');
|
|
91
|
+
return {
|
|
92
|
+
success: true,
|
|
93
|
+
matchCount: replaceAll ? matchCount : 1,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
return {
|
|
98
|
+
success: false,
|
|
99
|
+
matchCount: 0,
|
|
100
|
+
error: error instanceof Error ? error.message : String(error),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function escapeRegExp(string) {
|
|
105
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
106
|
+
}
|
|
107
|
+
export class ReadTool {
|
|
108
|
+
name = 'Read';
|
|
109
|
+
description = 'Read a file from the filesystem';
|
|
110
|
+
parameters = {
|
|
111
|
+
type: 'object',
|
|
112
|
+
properties: {
|
|
113
|
+
file_path: {
|
|
114
|
+
type: 'string',
|
|
115
|
+
description: 'The absolute or relative path to the file to read',
|
|
116
|
+
},
|
|
117
|
+
offset: {
|
|
118
|
+
type: 'number',
|
|
119
|
+
description: 'Line number to start reading from (0-based)',
|
|
120
|
+
},
|
|
121
|
+
limit: {
|
|
122
|
+
type: 'number',
|
|
123
|
+
description: 'Number of lines to read',
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
required: ['file_path'],
|
|
127
|
+
};
|
|
128
|
+
async execute(params) {
|
|
129
|
+
return readFile(params.file_path, {
|
|
130
|
+
offset: params.offset,
|
|
131
|
+
limit: params.limit,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export class WriteTool {
|
|
136
|
+
name = 'Write';
|
|
137
|
+
description = 'Write content to a file';
|
|
138
|
+
parameters = {
|
|
139
|
+
type: 'object',
|
|
140
|
+
properties: {
|
|
141
|
+
file_path: {
|
|
142
|
+
type: 'string',
|
|
143
|
+
description: 'The absolute or relative path to the file to write',
|
|
144
|
+
},
|
|
145
|
+
content: {
|
|
146
|
+
type: 'string',
|
|
147
|
+
description: 'The content to write to the file',
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
required: ['file_path', 'content'],
|
|
151
|
+
};
|
|
152
|
+
async execute(params) {
|
|
153
|
+
return writeFile(params.file_path, params.content);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
export class EditTool {
|
|
157
|
+
name = 'Edit';
|
|
158
|
+
description = 'Edit a file by replacing text';
|
|
159
|
+
parameters = {
|
|
160
|
+
type: 'object',
|
|
161
|
+
properties: {
|
|
162
|
+
file_path: {
|
|
163
|
+
type: 'string',
|
|
164
|
+
description: 'The absolute or relative path to the file to edit',
|
|
165
|
+
},
|
|
166
|
+
old_string: {
|
|
167
|
+
type: 'string',
|
|
168
|
+
description: 'The text to replace',
|
|
169
|
+
},
|
|
170
|
+
new_string: {
|
|
171
|
+
type: 'string',
|
|
172
|
+
description: 'The replacement text',
|
|
173
|
+
},
|
|
174
|
+
replace_all: {
|
|
175
|
+
type: 'boolean',
|
|
176
|
+
description: 'Replace all occurrences',
|
|
177
|
+
default: false,
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
required: ['file_path', 'old_string', 'new_string'],
|
|
181
|
+
};
|
|
182
|
+
async execute(params) {
|
|
183
|
+
return editFile(params.file_path, params.old_string, params.new_string, params.replace_all);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
export const readTool = new ReadTool();
|
|
187
|
+
export const writeTool = new WriteTool();
|
|
188
|
+
export const editTool = new EditTool();
|
|
189
|
+
//# sourceMappingURL=file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../src/tools/file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAoB7B,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,MAAM,eAAe,GAAG,IAAI,CAAC;AAE7B,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,QAAgB,EAChB,OAA6C;IAE7C,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE,KAAK,GAAG,SAAS,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAExD,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;QAC5C,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,QAAQ,CAAC,CAAC;IAE1C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,mBAAmB,YAAY,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACvD,MA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E;gBACT,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,mDAAmD;aACjE;YACD,UAAU,EAAE;gBACV,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,qBAAqB;aACnC;YACD,UAAU,EAAE;gBACV,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,sBAAsB;aACpC;YACD,WAAW,EAAE;gBACX,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,yBAAyB;gBACtC,OAAO,EAAE,KAAK;aACf;SACF;QACD,QAAQ,EAAE,CAAC,WAAW,EAAE,YAAY,EAAE,YAAY,CAAC;KACpD,CAAC;IAEF,KAAK,CAAC,OAAO,CAAC,MAKb;QACC,OAAO,QAAQ,CACb,MAAM,CAAC,SAAS,EAChB,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,WAAW,CACnB,CAAC;IACJ,CAAC;CACF;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;AACvC,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;AACzC,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface GlobResult {
|
|
2
|
+
files: FileInfo[];
|
|
3
|
+
totalCount: number;
|
|
4
|
+
truncated: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface FileInfo {
|
|
7
|
+
path: string;
|
|
8
|
+
relativePath: string;
|
|
9
|
+
size: number;
|
|
10
|
+
modifiedTime: Date;
|
|
11
|
+
isDirectory: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function globSearch(pattern: string, basePath?: string): Promise<GlobResult>;
|
|
14
|
+
export declare class GlobTool {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
parameters: {
|
|
18
|
+
type: string;
|
|
19
|
+
properties: {
|
|
20
|
+
pattern: {
|
|
21
|
+
type: string;
|
|
22
|
+
description: string;
|
|
23
|
+
};
|
|
24
|
+
path: {
|
|
25
|
+
type: string;
|
|
26
|
+
description: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
required: string[];
|
|
30
|
+
};
|
|
31
|
+
execute(params: {
|
|
32
|
+
pattern: string;
|
|
33
|
+
path?: string;
|
|
34
|
+
}): Promise<GlobResult>;
|
|
35
|
+
formatResult(result: GlobResult): string;
|
|
36
|
+
}
|
|
37
|
+
export declare const globTool: GlobTool;
|
|
38
|
+
//# sourceMappingURL=glob.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../src/tools/glob.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,IAAI,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;CACtB;AAID,wBAAsB,UAAU,CAC9B,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,UAAU,CAAC,CAqCrB;AAED,qBAAa,QAAQ;IACnB,IAAI,SAAU;IACd,WAAW,SAAwC;IAEnD,UAAU;;;;;;;;;;;;;MAaR;IAEI,OAAO,CAAC,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,CAAC;IAI9E,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM;CAmBzC;AAUD,eAAO,MAAM,QAAQ,UAAiB,CAAC"}
|