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
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { glob as globAsync } from 'glob';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
const MAX_RESULTS = 1000;
|
|
5
|
+
export async function globSearch(pattern, basePath) {
|
|
6
|
+
const cwd = basePath || process.cwd();
|
|
7
|
+
const matches = await globAsync(pattern, {
|
|
8
|
+
cwd,
|
|
9
|
+
nodir: false,
|
|
10
|
+
dot: true,
|
|
11
|
+
ignore: ['**/node_modules/**', '**/.git/**', '**/dist/**'],
|
|
12
|
+
});
|
|
13
|
+
const files = [];
|
|
14
|
+
for (const match of matches.slice(0, MAX_RESULTS)) {
|
|
15
|
+
const fullPath = path.join(cwd, match);
|
|
16
|
+
try {
|
|
17
|
+
const stats = fs.statSync(fullPath);
|
|
18
|
+
files.push({
|
|
19
|
+
path: fullPath,
|
|
20
|
+
relativePath: match,
|
|
21
|
+
size: stats.size,
|
|
22
|
+
modifiedTime: stats.mtime,
|
|
23
|
+
isDirectory: stats.isDirectory(),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// Skip files that can't be accessed
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// Sort by modification time (newest first)
|
|
31
|
+
files.sort((a, b) => b.modifiedTime.getTime() - a.modifiedTime.getTime());
|
|
32
|
+
return {
|
|
33
|
+
files,
|
|
34
|
+
totalCount: matches.length,
|
|
35
|
+
truncated: matches.length > MAX_RESULTS,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export class GlobTool {
|
|
39
|
+
name = 'Glob';
|
|
40
|
+
description = 'Find files matching a glob pattern';
|
|
41
|
+
parameters = {
|
|
42
|
+
type: 'object',
|
|
43
|
+
properties: {
|
|
44
|
+
pattern: {
|
|
45
|
+
type: 'string',
|
|
46
|
+
description: 'The glob pattern to match files against (e.g., "**/*.ts")',
|
|
47
|
+
},
|
|
48
|
+
path: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
description: 'The directory to search in (defaults to current directory)',
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
required: ['pattern'],
|
|
54
|
+
};
|
|
55
|
+
async execute(params) {
|
|
56
|
+
return globSearch(params.pattern, params.path);
|
|
57
|
+
}
|
|
58
|
+
formatResult(result) {
|
|
59
|
+
if (result.files.length === 0) {
|
|
60
|
+
return 'No files found matching the pattern';
|
|
61
|
+
}
|
|
62
|
+
const lines = result.files.map((f) => {
|
|
63
|
+
const type = f.isDirectory ? '[DIR]' : '[FILE]';
|
|
64
|
+
const size = f.isDirectory ? '' : ` (${formatSize(f.size)})`;
|
|
65
|
+
return `${type} ${f.relativePath}${size}`;
|
|
66
|
+
});
|
|
67
|
+
let output = lines.join('\n');
|
|
68
|
+
if (result.truncated) {
|
|
69
|
+
output += `\n\n... and ${result.totalCount - result.files.length} more files (truncated)`;
|
|
70
|
+
}
|
|
71
|
+
return output;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function formatSize(bytes) {
|
|
75
|
+
if (bytes < 1024)
|
|
76
|
+
return `${bytes} B`;
|
|
77
|
+
if (bytes < 1024 * 1024)
|
|
78
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
79
|
+
if (bytes < 1024 * 1024 * 1024)
|
|
80
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
81
|
+
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`;
|
|
82
|
+
}
|
|
83
|
+
export const globTool = new GlobTool();
|
|
84
|
+
//# sourceMappingURL=glob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glob.js","sourceRoot":"","sources":["../../src/tools/glob.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAgBzB,MAAM,WAAW,GAAG,IAAI,CAAC;AAEzB,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,OAAe,EACf,QAAiB;IAEjB,MAAM,GAAG,GAAG,QAAQ,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAEtC,MAAM,OAAO,GAAG,MAAM,SAAS,CAAC,OAAO,EAAE;QACvC,GAAG;QACH,KAAK,EAAE,KAAK;QACZ,GAAG,EAAE,IAAI;QACT,MAAM,EAAE,CAAC,oBAAoB,EAAE,YAAY,EAAE,YAAY,CAAC;KAC3D,CAAC,CAAC;IAEH,MAAM,KAAK,GAAe,EAAE,CAA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GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;IACpD,OAAO,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;AAC3D,CAAC;AAED,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export interface GrepMatch {
|
|
2
|
+
file: string;
|
|
3
|
+
line: number;
|
|
4
|
+
content: string;
|
|
5
|
+
context?: {
|
|
6
|
+
before: string[];
|
|
7
|
+
after: string[];
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export interface GrepResult {
|
|
11
|
+
matches: GrepMatch[];
|
|
12
|
+
fileCount: number;
|
|
13
|
+
totalMatches: number;
|
|
14
|
+
truncated: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface GrepOptions {
|
|
17
|
+
path?: string;
|
|
18
|
+
glob?: string;
|
|
19
|
+
caseInsensitive?: boolean;
|
|
20
|
+
contextBefore?: number;
|
|
21
|
+
contextAfter?: number;
|
|
22
|
+
maxResults?: number;
|
|
23
|
+
outputMode?: 'content' | 'files_with_matches' | 'count';
|
|
24
|
+
}
|
|
25
|
+
export declare function grepSearch(pattern: string, options?: GrepOptions): Promise<GrepResult>;
|
|
26
|
+
export declare class GrepTool {
|
|
27
|
+
name: string;
|
|
28
|
+
description: string;
|
|
29
|
+
parameters: {
|
|
30
|
+
type: string;
|
|
31
|
+
properties: {
|
|
32
|
+
pattern: {
|
|
33
|
+
type: string;
|
|
34
|
+
description: string;
|
|
35
|
+
};
|
|
36
|
+
path: {
|
|
37
|
+
type: string;
|
|
38
|
+
description: string;
|
|
39
|
+
};
|
|
40
|
+
glob: {
|
|
41
|
+
type: string;
|
|
42
|
+
description: string;
|
|
43
|
+
};
|
|
44
|
+
'-i': {
|
|
45
|
+
type: string;
|
|
46
|
+
description: string;
|
|
47
|
+
};
|
|
48
|
+
'-B': {
|
|
49
|
+
type: string;
|
|
50
|
+
description: string;
|
|
51
|
+
};
|
|
52
|
+
'-A': {
|
|
53
|
+
type: string;
|
|
54
|
+
description: string;
|
|
55
|
+
};
|
|
56
|
+
output_mode: {
|
|
57
|
+
type: string;
|
|
58
|
+
enum: string[];
|
|
59
|
+
description: string;
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
required: string[];
|
|
63
|
+
};
|
|
64
|
+
execute(params: {
|
|
65
|
+
pattern: string;
|
|
66
|
+
path?: string;
|
|
67
|
+
glob?: string;
|
|
68
|
+
'-i'?: boolean;
|
|
69
|
+
'-B'?: number;
|
|
70
|
+
'-A'?: number;
|
|
71
|
+
output_mode?: 'content' | 'files_with_matches' | 'count';
|
|
72
|
+
}): Promise<GrepResult>;
|
|
73
|
+
formatResult(result: GrepResult): string;
|
|
74
|
+
}
|
|
75
|
+
export declare const grepTool: GrepTool;
|
|
76
|
+
//# sourceMappingURL=grep.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grep.d.ts","sourceRoot":"","sources":["../../src/tools/grep.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE;QACR,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,KAAK,EAAE,MAAM,EAAE,CAAC;KACjB,CAAC;CACH;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,SAAS,GAAG,oBAAoB,GAAG,OAAO,CAAC;CACzD;AAKD,wBAAsB,UAAU,CAC9B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,UAAU,CAAC,CA4FrB;AAeD,qBAAa,QAAQ;IACnB,IAAI,SAAU;IACd,WAAW,SAAkC;IAE7C,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAkCR;IAEI,OAAO,CAAC,MAAM,EAAE;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,SAAS,GAAG,oBAAoB,GAAG,OAAO,CAAC;KAC1D,GAAG,OAAO,CAAC,UAAU,CAAC;IAWvB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM;CAkCzC;AAED,eAAO,MAAM,QAAQ,UAAiB,CAAC"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { glob as globAsync } from 'glob';
|
|
4
|
+
const MAX_RESULTS = 500;
|
|
5
|
+
const MAX_LINE_LENGTH = 500;
|
|
6
|
+
export async function grepSearch(pattern, options = {}) {
|
|
7
|
+
const { path: searchPath = process.cwd(), glob: globPattern = '**/*', caseInsensitive = false, contextBefore = 0, contextAfter = 0, maxResults = MAX_RESULTS, outputMode = 'content', } = options;
|
|
8
|
+
const regex = new RegExp(pattern, caseInsensitive ? 'gi' : 'g');
|
|
9
|
+
// Find files to search
|
|
10
|
+
const files = await globAsync(globPattern, {
|
|
11
|
+
cwd: searchPath,
|
|
12
|
+
nodir: true,
|
|
13
|
+
dot: true,
|
|
14
|
+
ignore: ['**/node_modules/**', '**/.git/**', '**/dist/**', '**/*.min.*'],
|
|
15
|
+
});
|
|
16
|
+
const matches = [];
|
|
17
|
+
let totalMatches = 0;
|
|
18
|
+
let filesWithMatches = 0;
|
|
19
|
+
for (const file of files) {
|
|
20
|
+
if (matches.length >= maxResults)
|
|
21
|
+
break;
|
|
22
|
+
const fullPath = path.join(searchPath, file);
|
|
23
|
+
try {
|
|
24
|
+
// Skip binary files
|
|
25
|
+
const content = fs.readFileSync(fullPath, 'utf-8');
|
|
26
|
+
if (isBinary(content))
|
|
27
|
+
continue;
|
|
28
|
+
const lines = content.split('\n');
|
|
29
|
+
let fileHasMatch = false;
|
|
30
|
+
for (let i = 0; i < lines.length; i++) {
|
|
31
|
+
if (matches.length >= maxResults)
|
|
32
|
+
break;
|
|
33
|
+
const line = lines[i];
|
|
34
|
+
if (regex.test(line)) {
|
|
35
|
+
regex.lastIndex = 0; // Reset regex state
|
|
36
|
+
totalMatches++;
|
|
37
|
+
fileHasMatch = true;
|
|
38
|
+
if (outputMode === 'content') {
|
|
39
|
+
const match = {
|
|
40
|
+
file: fullPath,
|
|
41
|
+
line: i + 1,
|
|
42
|
+
content: truncateLine(line),
|
|
43
|
+
};
|
|
44
|
+
if (contextBefore > 0 || contextAfter > 0) {
|
|
45
|
+
match.context = {
|
|
46
|
+
before: lines
|
|
47
|
+
.slice(Math.max(0, i - contextBefore), i)
|
|
48
|
+
.map(truncateLine),
|
|
49
|
+
after: lines
|
|
50
|
+
.slice(i + 1, i + 1 + contextAfter)
|
|
51
|
+
.map(truncateLine),
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
matches.push(match);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (fileHasMatch) {
|
|
59
|
+
filesWithMatches++;
|
|
60
|
+
if (outputMode === 'files_with_matches') {
|
|
61
|
+
matches.push({
|
|
62
|
+
file: fullPath,
|
|
63
|
+
line: 0,
|
|
64
|
+
content: '',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Skip files that can't be read
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
matches,
|
|
75
|
+
fileCount: filesWithMatches,
|
|
76
|
+
totalMatches,
|
|
77
|
+
truncated: totalMatches > maxResults,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function truncateLine(line) {
|
|
81
|
+
if (line.length > MAX_LINE_LENGTH) {
|
|
82
|
+
return line.slice(0, MAX_LINE_LENGTH) + '...';
|
|
83
|
+
}
|
|
84
|
+
return line;
|
|
85
|
+
}
|
|
86
|
+
function isBinary(content) {
|
|
87
|
+
// Check for null bytes which typically indicate binary content
|
|
88
|
+
const sample = content.slice(0, 8000);
|
|
89
|
+
return sample.includes('\0');
|
|
90
|
+
}
|
|
91
|
+
export class GrepTool {
|
|
92
|
+
name = 'Grep';
|
|
93
|
+
description = 'Search for patterns in files';
|
|
94
|
+
parameters = {
|
|
95
|
+
type: 'object',
|
|
96
|
+
properties: {
|
|
97
|
+
pattern: {
|
|
98
|
+
type: 'string',
|
|
99
|
+
description: 'The regular expression pattern to search for',
|
|
100
|
+
},
|
|
101
|
+
path: {
|
|
102
|
+
type: 'string',
|
|
103
|
+
description: 'Directory to search in (defaults to current directory)',
|
|
104
|
+
},
|
|
105
|
+
glob: {
|
|
106
|
+
type: 'string',
|
|
107
|
+
description: 'Glob pattern to filter files (e.g., "*.ts")',
|
|
108
|
+
},
|
|
109
|
+
'-i': {
|
|
110
|
+
type: 'boolean',
|
|
111
|
+
description: 'Case insensitive search',
|
|
112
|
+
},
|
|
113
|
+
'-B': {
|
|
114
|
+
type: 'number',
|
|
115
|
+
description: 'Number of lines to show before each match',
|
|
116
|
+
},
|
|
117
|
+
'-A': {
|
|
118
|
+
type: 'number',
|
|
119
|
+
description: 'Number of lines to show after each match',
|
|
120
|
+
},
|
|
121
|
+
output_mode: {
|
|
122
|
+
type: 'string',
|
|
123
|
+
enum: ['content', 'files_with_matches', 'count'],
|
|
124
|
+
description: 'Output mode',
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
required: ['pattern'],
|
|
128
|
+
};
|
|
129
|
+
async execute(params) {
|
|
130
|
+
return grepSearch(params.pattern, {
|
|
131
|
+
path: params.path,
|
|
132
|
+
glob: params.glob,
|
|
133
|
+
caseInsensitive: params['-i'],
|
|
134
|
+
contextBefore: params['-B'],
|
|
135
|
+
contextAfter: params['-A'],
|
|
136
|
+
outputMode: params.output_mode,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
formatResult(result) {
|
|
140
|
+
if (result.matches.length === 0) {
|
|
141
|
+
return 'No matches found';
|
|
142
|
+
}
|
|
143
|
+
const lines = [];
|
|
144
|
+
for (const match of result.matches) {
|
|
145
|
+
if (match.context?.before) {
|
|
146
|
+
for (let i = 0; i < match.context.before.length; i++) {
|
|
147
|
+
const lineNum = match.line - match.context.before.length + i;
|
|
148
|
+
lines.push(`${match.file}:${lineNum}: ${match.context.before[i]}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
lines.push(`${match.file}:${match.line}: ${match.content}`);
|
|
152
|
+
if (match.context?.after) {
|
|
153
|
+
for (let i = 0; i < match.context.after.length; i++) {
|
|
154
|
+
lines.push(`${match.file}:${match.line + i + 1}: ${match.context.after[i]}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
let output = lines.join('\n');
|
|
159
|
+
if (result.truncated) {
|
|
160
|
+
output += `\n\n... (${result.totalMatches} total matches, showing first ${result.matches.length})`;
|
|
161
|
+
}
|
|
162
|
+
return output;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
export const grepTool = new GrepTool();
|
|
166
|
+
//# sourceMappingURL=grep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grep.js","sourceRoot":"","sources":["../../src/tools/grep.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,MAAM,CAAC;AA6BzC,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,OAAe,EACf,UAAuB,EAAE;IAEzB,MAAM,EACJ,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,EAChC,IAAI,EAAE,WAAW,GAAG,MAAM,EAC1B,eAAe,GAAG,KAAK,EACvB,aAAa,GAAG,CAAC,EACjB,YAAY,GAAG,CAAC,EAChB,UAAU,GAAG,WAAW,EACxB,UAAU,GAAG,SAAS,GACvB,GAAG,OAAO,CAAC;IAEZ,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAEhE,uBAAuB;IACvB,MAAM,KAAK,GAAG,MAAM,SAAS,CAAC,WAAW,EAAE;QACzC,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,IAAI;QACX,GAAG,EAAE,IAAI;QACT,MAAM,EAAE,CAAC,oBAAoB,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,CAAC;KACzE,CAAC,CAAC;IAEH,MAAM,OAAO,GAAgB,EAAE,CAAC;IAChC,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,IAAI,gBAAgB,GAAG,CAAC,CAAC;IAEzB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,OAAO,CAAC,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EAAE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BashResult } from './bash.js';
|
|
2
|
+
import { ReadResult, WriteResult, EditResult } from './file.js';
|
|
3
|
+
import { GlobResult } from './glob.js';
|
|
4
|
+
import { GrepResult } from './grep.js';
|
|
5
|
+
import { Tool } from '../api/client.js';
|
|
6
|
+
export interface ToolDefinition {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
parameters: Record<string, unknown>;
|
|
10
|
+
execute: (params: Record<string, unknown>) => Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
export type ToolResult = BashResult | ReadResult | WriteResult | EditResult | GlobResult | GrepResult | unknown;
|
|
13
|
+
export declare class ToolRegistry {
|
|
14
|
+
private tools;
|
|
15
|
+
register(tool: ToolDefinition): void;
|
|
16
|
+
unregister(name: string): boolean;
|
|
17
|
+
get(name: string): ToolDefinition | undefined;
|
|
18
|
+
has(name: string): boolean;
|
|
19
|
+
getAll(): ToolDefinition[];
|
|
20
|
+
execute(name: string, params: Record<string, unknown>): Promise<ToolResult>;
|
|
21
|
+
toAPIFormat(): Tool[];
|
|
22
|
+
}
|
|
23
|
+
export declare const toolRegistry: ToolRegistry;
|
|
24
|
+
export * from './bash.js';
|
|
25
|
+
export * from './file.js';
|
|
26
|
+
export * from './glob.js';
|
|
27
|
+
export * from './grep.js';
|
|
28
|
+
export * from './mcp.js';
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,UAAU,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAiC,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/F,OAAO,EAAY,UAAU,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAY,UAAU,EAAE,MAAM,WAAW,CAAC;AAEjD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAChE;AAED,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,CAAC;AA4DhH,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAAiD;IAE9D,QAAQ,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI;IAIpC,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIjC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS;IAI7C,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI1B,MAAM,IAAI,cAAc,EAAE;IAIpB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC;IAqBjF,WAAW,IAAI,IAAI,EAAE;CA4BtB;AAED,eAAO,MAAM,YAAY,cAAqB,CAAC;AAE/C,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { bashTool } from './bash.js';
|
|
2
|
+
import { readTool, writeTool, editTool } from './file.js';
|
|
3
|
+
import { globTool } from './glob.js';
|
|
4
|
+
import { grepTool } from './grep.js';
|
|
5
|
+
import { mcpManager } from './mcp.js';
|
|
6
|
+
// Built-in tools registry
|
|
7
|
+
const builtInTools = new Map([
|
|
8
|
+
[
|
|
9
|
+
'Bash',
|
|
10
|
+
{
|
|
11
|
+
name: bashTool.name,
|
|
12
|
+
description: bashTool.description,
|
|
13
|
+
parameters: bashTool.parameters,
|
|
14
|
+
execute: (params) => bashTool.execute(params),
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
[
|
|
18
|
+
'Read',
|
|
19
|
+
{
|
|
20
|
+
name: readTool.name,
|
|
21
|
+
description: readTool.description,
|
|
22
|
+
parameters: readTool.parameters,
|
|
23
|
+
execute: (params) => readTool.execute(params),
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
[
|
|
27
|
+
'Write',
|
|
28
|
+
{
|
|
29
|
+
name: writeTool.name,
|
|
30
|
+
description: writeTool.description,
|
|
31
|
+
parameters: writeTool.parameters,
|
|
32
|
+
execute: (params) => writeTool.execute(params),
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
[
|
|
36
|
+
'Edit',
|
|
37
|
+
{
|
|
38
|
+
name: editTool.name,
|
|
39
|
+
description: editTool.description,
|
|
40
|
+
parameters: editTool.parameters,
|
|
41
|
+
execute: (params) => editTool.execute(params),
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
[
|
|
45
|
+
'Glob',
|
|
46
|
+
{
|
|
47
|
+
name: globTool.name,
|
|
48
|
+
description: globTool.description,
|
|
49
|
+
parameters: globTool.parameters,
|
|
50
|
+
execute: (params) => globTool.execute(params),
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
[
|
|
54
|
+
'Grep',
|
|
55
|
+
{
|
|
56
|
+
name: grepTool.name,
|
|
57
|
+
description: grepTool.description,
|
|
58
|
+
parameters: grepTool.parameters,
|
|
59
|
+
execute: (params) => grepTool.execute(params),
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
]);
|
|
63
|
+
export class ToolRegistry {
|
|
64
|
+
tools = new Map(builtInTools);
|
|
65
|
+
register(tool) {
|
|
66
|
+
this.tools.set(tool.name, tool);
|
|
67
|
+
}
|
|
68
|
+
unregister(name) {
|
|
69
|
+
return this.tools.delete(name);
|
|
70
|
+
}
|
|
71
|
+
get(name) {
|
|
72
|
+
return this.tools.get(name);
|
|
73
|
+
}
|
|
74
|
+
has(name) {
|
|
75
|
+
return this.tools.has(name);
|
|
76
|
+
}
|
|
77
|
+
getAll() {
|
|
78
|
+
return Array.from(this.tools.values());
|
|
79
|
+
}
|
|
80
|
+
async execute(name, params) {
|
|
81
|
+
// Check built-in tools first
|
|
82
|
+
const tool = this.tools.get(name);
|
|
83
|
+
if (tool) {
|
|
84
|
+
return tool.execute(params);
|
|
85
|
+
}
|
|
86
|
+
// Check MCP tools (format: mcp__server__tool)
|
|
87
|
+
if (name.startsWith('mcp__')) {
|
|
88
|
+
const parts = name.split('__');
|
|
89
|
+
if (parts.length >= 3) {
|
|
90
|
+
const serverName = parts[1];
|
|
91
|
+
const toolName = parts.slice(2).join('__');
|
|
92
|
+
return mcpManager.callTool(serverName, toolName, params);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
96
|
+
}
|
|
97
|
+
// Convert to OpenAI-compatible tool format for API requests
|
|
98
|
+
toAPIFormat() {
|
|
99
|
+
const tools = [];
|
|
100
|
+
for (const tool of this.tools.values()) {
|
|
101
|
+
tools.push({
|
|
102
|
+
type: 'function',
|
|
103
|
+
function: {
|
|
104
|
+
name: tool.name,
|
|
105
|
+
description: tool.description,
|
|
106
|
+
parameters: tool.parameters,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
// Add MCP tools
|
|
111
|
+
for (const { server, tool } of mcpManager.getAllTools()) {
|
|
112
|
+
tools.push({
|
|
113
|
+
type: 'function',
|
|
114
|
+
function: {
|
|
115
|
+
name: `mcp__${server}__${tool.name}`,
|
|
116
|
+
description: `[${server}] ${tool.description}`,
|
|
117
|
+
parameters: tool.inputSchema,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return tools;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
export const toolRegistry = new ToolRegistry();
|
|
125
|
+
export * from './bash.js';
|
|
126
|
+
export * from './file.js';
|
|
127
|
+
export * from './glob.js';
|
|
128
|
+
export * from './grep.js';
|
|
129
|
+
export * from './mcp.js';
|
|
130
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAc,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAuC,MAAM,WAAW,CAAC;AAC/F,OAAO,EAAE,QAAQ,EAAc,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAc,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAYtC,0BAA0B;AAC1B,MAAM,YAAY,GAAgC,IAAI,GAAG,CAAC;IACxD;QACE,MAAM;QACN;YACE,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,WAAW,EAAE,QAAQ,CAAC,WAAW;YACjC,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAgD,CAAC;SACxF;KACF;IACD;QACE,MAAM;QACN;YACE,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,WAAW,EAAE,QAAQ,CAAC,WAAW;YACjC,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAgD,CAAC;SACxF;KACF;IACD;QACE,OAAO;QACP;YACE,IAAI,EAAE,SAAS,CAAC,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BAChB,QAAQ,EAAE;oBACR,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,WAAW,EAAE,IAAI,CAAC,WAAW;oBAC7B,UAAU,EAAE,IAAI,CAAC,UAAU;iBAC5B;aACF,CAAC,CAAC;QACL,CAAC;QAED,gBAAgB;QAChB,KAAK,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,UAAU,CAAC,WAAW,EAAE,EAAE,CAAC;YACxD,KAAK,CAAC,IAAI,CAAC;gBACT,IAAI,EAAE,UAAU;gBAChB,QAAQ,EAAE;oBACR,IAAI,EAAE,QAAQ,MAAM,KAAK,IAAI,CAAC,IAAI,EAAE;oBACpC,WAAW,EAAE,IAAI,MAAM,KAAK,IAAI,CAAC,WAAW,EAAE;oBAC9C,UAAU,EAAE,IAAI,CAAC,WAAW;iBAC7B;aACF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC;AAE/C,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
export interface MCPServer {
|
|
3
|
+
name: string;
|
|
4
|
+
command: string;
|
|
5
|
+
args?: string[];
|
|
6
|
+
env?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
export interface MCPTool {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
inputSchema: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
export interface MCPRequest {
|
|
14
|
+
jsonrpc: '2.0';
|
|
15
|
+
id: number;
|
|
16
|
+
method: string;
|
|
17
|
+
params?: Record<string, unknown>;
|
|
18
|
+
}
|
|
19
|
+
export interface MCPResponse {
|
|
20
|
+
jsonrpc: '2.0';
|
|
21
|
+
id: number;
|
|
22
|
+
result?: unknown;
|
|
23
|
+
error?: {
|
|
24
|
+
code: number;
|
|
25
|
+
message: string;
|
|
26
|
+
data?: unknown;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export declare class MCPClient extends EventEmitter {
|
|
30
|
+
private server;
|
|
31
|
+
private process;
|
|
32
|
+
private requestId;
|
|
33
|
+
private pendingRequests;
|
|
34
|
+
private buffer;
|
|
35
|
+
private tools;
|
|
36
|
+
private serverName;
|
|
37
|
+
constructor(server: MCPServer);
|
|
38
|
+
start(): Promise<void>;
|
|
39
|
+
private handleData;
|
|
40
|
+
private send;
|
|
41
|
+
private initialize;
|
|
42
|
+
callTool(name: string, args: Record<string, unknown>): Promise<unknown>;
|
|
43
|
+
getTools(): MCPTool[];
|
|
44
|
+
getName(): string;
|
|
45
|
+
stop(): void;
|
|
46
|
+
}
|
|
47
|
+
export declare class MCPManager {
|
|
48
|
+
private clients;
|
|
49
|
+
addServer(server: MCPServer): Promise<MCPClient>;
|
|
50
|
+
getClient(name: string): MCPClient | undefined;
|
|
51
|
+
getAllTools(): Array<{
|
|
52
|
+
server: string;
|
|
53
|
+
tool: MCPTool;
|
|
54
|
+
}>;
|
|
55
|
+
callTool(serverName: string, toolName: string, args: Record<string, unknown>): Promise<unknown>;
|
|
56
|
+
stopAll(): void;
|
|
57
|
+
}
|
|
58
|
+
export declare const mcpManager: MCPManager;
|
|
59
|
+
//# sourceMappingURL=mcp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/tools/mcp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,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