@travisennis/acai 0.0.4 → 0.0.5
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 +225 -6
- package/dist/api/exa/index.d.ts +177 -0
- package/dist/api/exa/index.d.ts.map +1 -0
- package/dist/api/exa/index.js +439 -0
- package/dist/cli.d.ts +3 -2
- package/dist/cli.d.ts.map +1 -0
- package/dist/commands/application-log-command.d.ts +1 -0
- package/dist/commands/application-log-command.d.ts.map +1 -0
- package/dist/commands/application-log-command.js +5 -3
- package/dist/commands/clear-command.d.ts +1 -0
- package/dist/commands/clear-command.d.ts.map +1 -0
- package/dist/commands/clear-command.js +2 -3
- package/dist/commands/compact-command.d.ts +1 -0
- package/dist/commands/compact-command.d.ts.map +1 -0
- package/dist/commands/compact-command.js +1 -1
- package/dist/commands/copy-command.d.ts +1 -0
- package/dist/commands/copy-command.d.ts.map +1 -0
- package/dist/commands/copy-command.js +3 -2
- package/dist/commands/edit-command.d.ts +1 -0
- package/dist/commands/edit-command.d.ts.map +1 -0
- package/dist/commands/edit-command.js +7 -5
- package/dist/commands/edit-prompt-command.d.ts +2 -1
- package/dist/commands/edit-prompt-command.d.ts.map +1 -0
- package/dist/commands/edit-prompt-command.js +15 -7
- package/dist/commands/exit-command.d.ts +13 -2
- package/dist/commands/exit-command.d.ts.map +1 -0
- package/dist/commands/exit-command.js +14 -2
- package/dist/commands/files-command.d.ts +1 -0
- package/dist/commands/files-command.d.ts.map +1 -0
- package/dist/commands/files-command.js +9 -8
- package/dist/commands/generate-rules-command.d.ts +1 -0
- package/dist/commands/generate-rules-command.d.ts.map +1 -0
- package/dist/commands/generate-rules-command.js +4 -3
- package/dist/commands/health-command.d.ts +3 -1
- package/dist/commands/health-command.d.ts.map +1 -0
- package/dist/commands/health-command.js +42 -5
- package/dist/commands/help-command.d.ts +1 -0
- package/dist/commands/help-command.d.ts.map +1 -0
- package/dist/commands/help-command.js +2 -3
- package/dist/commands/init-command.d.ts +1 -0
- package/dist/commands/init-command.d.ts.map +1 -0
- package/dist/commands/init-command.js +1 -2
- package/dist/commands/last-log-command.d.ts +1 -0
- package/dist/commands/last-log-command.d.ts.map +1 -0
- package/dist/commands/last-log-command.js +12 -17
- package/dist/commands/list-tools-command.d.ts +3 -0
- package/dist/commands/list-tools-command.d.ts.map +1 -0
- package/dist/commands/list-tools-command.js +61 -0
- package/dist/commands/manager.d.ts +7 -2
- package/dist/commands/manager.d.ts.map +1 -0
- package/dist/commands/manager.js +43 -6
- package/dist/commands/model-command.d.ts +1 -0
- package/dist/commands/model-command.d.ts.map +1 -0
- package/dist/commands/model-command.js +5 -5
- package/dist/commands/paste-command.d.ts +1 -0
- package/dist/commands/paste-command.d.ts.map +1 -0
- package/dist/commands/paste-command.js +6 -5
- package/dist/commands/prompt-command.d.ts +2 -1
- package/dist/commands/prompt-command.d.ts.map +1 -0
- package/dist/commands/prompt-command.js +62 -8
- package/dist/commands/reset-command.d.ts +1 -0
- package/dist/commands/reset-command.d.ts.map +1 -0
- package/dist/commands/reset-command.js +1 -1
- package/dist/commands/rules-command.d.ts +1 -0
- package/dist/commands/rules-command.d.ts.map +1 -0
- package/dist/commands/rules-command.js +5 -3
- package/dist/commands/save-command.d.ts +1 -0
- package/dist/commands/save-command.d.ts.map +1 -0
- package/dist/commands/save-command.js +1 -1
- package/dist/commands/shell-command.d.ts +3 -0
- package/dist/commands/shell-command.d.ts.map +1 -0
- package/dist/commands/shell-command.js +60 -0
- package/dist/commands/types.d.ts +9 -6
- package/dist/commands/types.d.ts.map +1 -0
- package/dist/commands/usage-command.d.ts +1 -0
- package/dist/commands/usage-command.d.ts.map +1 -0
- package/dist/commands/usage-command.js +2 -3
- package/dist/config.d.ts +22 -34
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +61 -15
- package/dist/conversation-analyzer.d.ts +2 -1
- package/dist/conversation-analyzer.d.ts.map +1 -0
- package/dist/dedent.d.ts +1 -0
- package/dist/dedent.d.ts.map +1 -0
- package/dist/execution/index.d.ts +112 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +432 -0
- package/dist/formatting.d.ts +2 -13
- package/dist/formatting.d.ts.map +1 -0
- package/dist/formatting.js +5 -64
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -4
- package/dist/logger.d.ts +1 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/mentions.d.ts +4 -0
- package/dist/mentions.d.ts.map +1 -0
- package/dist/mentions.js +42 -10
- package/dist/messages.d.ts +8 -20
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +33 -53
- package/dist/middleware/audit-message.d.ts +1 -0
- package/dist/middleware/audit-message.d.ts.map +1 -0
- package/dist/middleware/index.d.ts +1 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/rate-limit.d.ts +1 -0
- package/dist/middleware/rate-limit.d.ts.map +1 -0
- package/dist/models/ai-config.d.ts +1 -0
- package/dist/models/ai-config.d.ts.map +1 -0
- package/dist/models/anthropic-provider.d.ts +1 -0
- package/dist/models/anthropic-provider.d.ts.map +1 -0
- package/dist/models/deepseek-provider.d.ts +1 -0
- package/dist/models/deepseek-provider.d.ts.map +1 -0
- package/dist/models/google-provider.d.ts +1 -0
- package/dist/models/google-provider.d.ts.map +1 -0
- package/dist/models/groq-provider.d.ts +20 -0
- package/dist/models/groq-provider.d.ts.map +1 -0
- package/dist/models/groq-provider.js +31 -0
- package/dist/models/manager.d.ts +1 -0
- package/dist/models/manager.d.ts.map +1 -0
- package/dist/models/openai-provider.d.ts +2 -1
- package/dist/models/openai-provider.d.ts.map +1 -0
- package/dist/models/openrouter-provider.d.ts +31 -22
- package/dist/models/openrouter-provider.d.ts.map +1 -0
- package/dist/models/openrouter-provider.js +115 -1
- package/dist/models/providers.d.ts +4 -5
- package/dist/models/providers.d.ts.map +1 -0
- package/dist/models/providers.js +7 -3
- package/dist/models/xai-provider.d.ts +1 -0
- package/dist/models/xai-provider.d.ts.map +1 -0
- package/dist/parsing.d.ts +2 -1
- package/dist/parsing.d.ts.map +1 -0
- package/dist/prompts/manager.d.ts +14 -2
- package/dist/prompts/manager.d.ts.map +1 -0
- package/dist/prompts.d.ts +1 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +15 -11
- package/dist/repl/display-tool-messages.d.ts +4 -0
- package/dist/repl/display-tool-messages.d.ts.map +1 -0
- package/dist/repl/display-tool-messages.js +55 -0
- package/dist/repl/display-tool-use.d.ts +14 -0
- package/dist/repl/display-tool-use.d.ts.map +1 -0
- package/dist/repl/display-tool-use.js +63 -0
- package/dist/repl/get-prompt-header.d.ts +8 -0
- package/dist/repl/get-prompt-header.d.ts.map +1 -0
- package/dist/repl/get-prompt-header.js +38 -0
- package/dist/repl/tool-call-repair.d.ts +4 -0
- package/dist/repl/tool-call-repair.d.ts.map +1 -0
- package/dist/repl/tool-call-repair.js +50 -0
- package/dist/repl-prompt.d.ts +1 -0
- package/dist/repl-prompt.d.ts.map +1 -0
- package/dist/repl.d.ts +8 -4
- package/dist/repl.d.ts.map +1 -0
- package/dist/repl.js +108 -252
- package/dist/terminal/ansi-styles.d.ts +77 -0
- package/dist/terminal/ansi-styles.d.ts.map +1 -0
- package/dist/terminal/ansi-styles.js +215 -0
- package/dist/terminal/checkbox-prompt.d.ts +36 -0
- package/dist/terminal/checkbox-prompt.d.ts.map +1 -0
- package/dist/terminal/checkbox-prompt.js +362 -0
- package/dist/terminal/default-theme.d.ts +6 -0
- package/dist/terminal/default-theme.d.ts.map +1 -0
- package/dist/terminal/default-theme.js +182 -0
- package/dist/terminal/east-asian-width.d.ts +8 -0
- package/dist/terminal/east-asian-width.d.ts.map +1 -0
- package/dist/terminal/east-asian-width.js +409 -0
- package/dist/terminal/editor-prompt.d.ts +10 -0
- package/dist/terminal/editor-prompt.d.ts.map +1 -0
- package/dist/terminal/editor-prompt.js +61 -0
- package/dist/terminal/errors.d.ts +19 -0
- package/dist/terminal/errors.d.ts.map +1 -0
- package/dist/terminal/errors.js +37 -0
- package/dist/terminal/formatting.d.ts +1 -11
- package/dist/terminal/formatting.d.ts.map +1 -0
- package/dist/terminal/formatting.js +4 -20
- package/dist/terminal/highlight/index.d.ts +53 -0
- package/dist/terminal/highlight/index.d.ts.map +1 -0
- package/dist/terminal/highlight/index.js +90 -0
- package/dist/terminal/highlight/theme.d.ts +233 -0
- package/dist/terminal/highlight/theme.d.ts.map +1 -0
- package/dist/terminal/highlight/theme.js +83 -0
- package/dist/terminal/index.d.ts +16 -9
- package/dist/terminal/index.d.ts.map +1 -0
- package/dist/terminal/index.js +42 -126
- package/dist/terminal/input-prompt.d.ts +16 -0
- package/dist/terminal/input-prompt.d.ts.map +1 -0
- package/dist/terminal/input-prompt.js +181 -0
- package/dist/terminal/markdown-utils.d.ts +1 -0
- package/dist/terminal/markdown-utils.d.ts.map +1 -0
- package/dist/terminal/markdown.d.ts +1 -0
- package/dist/terminal/markdown.d.ts.map +1 -0
- package/dist/terminal/markdown.js +17 -12
- package/dist/terminal/search-prompt.d.ts +20 -0
- package/dist/terminal/search-prompt.d.ts.map +1 -0
- package/dist/terminal/search-prompt.js +279 -0
- package/dist/terminal/select-prompt.d.ts +26 -0
- package/dist/terminal/select-prompt.d.ts.map +1 -0
- package/dist/terminal/select-prompt.js +298 -0
- package/dist/terminal/string-width.d.ts +7 -0
- package/dist/terminal/string-width.d.ts.map +1 -0
- package/dist/terminal/string-width.js +61 -0
- package/dist/terminal/strip-ansi.d.ts +2 -0
- package/dist/terminal/strip-ansi.d.ts.map +1 -0
- package/dist/terminal/strip-ansi.js +20 -0
- package/dist/terminal/style.d.ts +191 -0
- package/dist/terminal/style.d.ts.map +1 -0
- package/dist/terminal/style.js +259 -0
- package/dist/terminal/supports-color.d.ts +1 -0
- package/dist/terminal/supports-color.d.ts.map +1 -0
- package/dist/terminal/supports-hyperlinks.d.ts +1 -3
- package/dist/terminal/supports-hyperlinks.d.ts.map +1 -0
- package/dist/terminal/supports-hyperlinks.js +1 -1
- package/dist/terminal/types.d.ts +1 -37
- package/dist/terminal/types.d.ts.map +1 -0
- package/dist/terminal/wrap-ansi.d.ts +8 -0
- package/dist/terminal/wrap-ansi.d.ts.map +1 -0
- package/dist/terminal/wrap-ansi.js +190 -0
- package/dist/{token-utils.d.ts → tokens/counter.d.ts} +1 -0
- package/dist/tokens/counter.d.ts.map +1 -0
- package/dist/{token-utils.js → tokens/counter.js} +1 -1
- package/dist/tokens/manage-output.d.ts +34 -0
- package/dist/tokens/manage-output.d.ts.map +1 -0
- package/dist/tokens/manage-output.js +44 -0
- package/dist/{token-tracker.d.ts → tokens/tracker.d.ts} +1 -0
- package/dist/tokens/tracker.d.ts.map +1 -0
- package/dist/tool-executor.d.ts +28 -0
- package/dist/tool-executor.d.ts.map +1 -0
- package/dist/tool-executor.js +74 -0
- package/dist/tools/agent.d.ts +3 -2
- package/dist/tools/agent.d.ts.map +1 -0
- package/dist/tools/agent.js +7 -4
- package/dist/tools/bash-utils.d.ts +7 -0
- package/dist/tools/bash-utils.d.ts.map +1 -0
- package/dist/tools/bash-utils.js +212 -0
- package/dist/tools/bash.d.ts +9 -7
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +95 -212
- package/dist/tools/code-interpreter.d.ts +1 -1
- package/dist/tools/code-interpreter.d.ts.map +1 -0
- package/dist/tools/code-interpreter.js +31 -96
- package/dist/tools/delete-file.d.ts +5 -3
- package/dist/tools/delete-file.d.ts.map +1 -0
- package/dist/tools/delete-file.js +47 -33
- package/dist/tools/directory-tree.d.ts +10 -1
- package/dist/tools/directory-tree.d.ts.map +1 -0
- package/dist/tools/directory-tree.js +91 -8
- package/dist/tools/dynamic-tool-loader.d.ts +12 -0
- package/dist/tools/dynamic-tool-loader.d.ts.map +1 -0
- package/dist/tools/dynamic-tool-loader.js +280 -0
- package/dist/tools/dynamic-tool-parser.d.ts +20 -0
- package/dist/tools/dynamic-tool-parser.d.ts.map +1 -0
- package/dist/tools/dynamic-tool-parser.js +21 -0
- package/dist/tools/edit-file.d.ts +10 -2
- package/dist/tools/edit-file.d.ts.map +1 -0
- package/dist/tools/edit-file.js +117 -40
- package/dist/tools/file-editing-utils.d.ts +2 -0
- package/dist/tools/file-editing-utils.d.ts.map +1 -0
- package/dist/tools/file-editing-utils.js +135 -0
- package/dist/tools/filesystem-utils.d.ts +6 -21
- package/dist/tools/filesystem-utils.d.ts.map +1 -0
- package/dist/tools/filesystem-utils.js +96 -148
- package/dist/tools/git-utils.d.ts +1 -0
- package/dist/tools/git-utils.d.ts.map +1 -0
- package/dist/tools/grep.d.ts +5 -3
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +67 -27
- package/dist/tools/index.d.ts +10 -16
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +33 -22
- package/dist/tools/move-file.d.ts +1 -0
- package/dist/tools/move-file.d.ts.map +1 -0
- package/dist/tools/move-file.js +12 -5
- package/dist/tools/read-file.d.ts +2 -1
- package/dist/tools/read-file.d.ts.map +1 -0
- package/dist/tools/read-file.js +13 -6
- package/dist/tools/read-multiple-files.d.ts +2 -1
- package/dist/tools/read-multiple-files.d.ts.map +1 -0
- package/dist/tools/read-multiple-files.js +90 -9
- package/dist/tools/save-file.d.ts +5 -3
- package/dist/tools/save-file.d.ts.map +1 -0
- package/dist/tools/save-file.js +64 -36
- package/dist/tools/think.d.ts +1 -0
- package/dist/tools/think.d.ts.map +1 -0
- package/dist/tools/think.js +5 -1
- package/dist/tools/types.d.ts +14 -1
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/web-fetch.d.ts +4 -2
- package/dist/tools/web-fetch.d.ts.map +1 -0
- package/dist/tools/web-fetch.js +2 -2
- package/dist/tools/web-search.d.ts +2 -1
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +46 -11
- package/dist/utils/filesystem.d.ts +23 -0
- package/dist/utils/filesystem.d.ts.map +1 -0
- package/dist/utils/filesystem.js +140 -0
- package/dist/utils/filetype-detection.d.ts +3 -0
- package/dist/utils/filetype-detection.d.ts.map +1 -0
- package/dist/utils/filetype-detection.js +112 -0
- package/dist/utils/glob.d.ts +52 -0
- package/dist/utils/glob.d.ts.map +1 -0
- package/dist/utils/glob.js +376 -0
- package/dist/utils/ignore.d.ts +104 -0
- package/dist/utils/ignore.d.ts.map +1 -0
- package/dist/utils/ignore.js +649 -0
- package/dist/utils/process.d.ts +3 -2
- package/dist/utils/process.d.ts.map +1 -0
- package/dist/utils/process.js +17 -2
- package/dist/utils/zod-utils.d.ts +4 -0
- package/dist/utils/zod-utils.d.ts.map +1 -0
- package/dist/utils/zod-utils.js +7 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +32 -30
- package/dist/tools/command-validation.d.ts +0 -11
- package/dist/tools/command-validation.js +0 -45
- /package/dist/{token-tracker.js → tokens/tracker.js} +0 -0
package/dist/tools/index.d.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import type { ModelManager } from "../models/manager.ts";
|
|
2
2
|
import type { Terminal } from "../terminal/index.ts";
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
3
|
+
import type { TokenCounter } from "../tokens/counter.ts";
|
|
4
|
+
import type { TokenTracker } from "../tokens/tracker.ts";
|
|
5
|
+
import type { ToolExecutor } from "../tool-executor.ts";
|
|
5
6
|
import type { Message } from "./types.ts";
|
|
6
|
-
export declare function initTools({ terminal, tokenCounter, events,
|
|
7
|
+
export declare function initTools({ terminal, tokenCounter, events, toolExecutor, }: {
|
|
7
8
|
terminal: Terminal;
|
|
8
9
|
tokenCounter: TokenCounter;
|
|
9
10
|
events: Map<string, Message[]>;
|
|
10
|
-
|
|
11
|
+
toolExecutor?: ToolExecutor;
|
|
11
12
|
}): Promise<{
|
|
12
13
|
readonly webSearch: import("ai").Tool<{
|
|
13
14
|
query: string;
|
|
14
15
|
}, string>;
|
|
15
16
|
readonly bash: import("ai").Tool<{
|
|
17
|
+
command: string;
|
|
16
18
|
cwd: string | null;
|
|
17
19
|
timeout: number | null;
|
|
18
|
-
command: string;
|
|
19
20
|
}, string>;
|
|
20
21
|
readonly webFetch: import("ai").Tool<{
|
|
21
22
|
url: string;
|
|
@@ -24,8 +25,8 @@ export declare function initTools({ terminal, tokenCounter, events, autoAcceptAl
|
|
|
24
25
|
thought: string;
|
|
25
26
|
}, string>;
|
|
26
27
|
readonly grepFiles: import("ai").Tool<{
|
|
27
|
-
path: string;
|
|
28
28
|
pattern: string;
|
|
29
|
+
path: string;
|
|
29
30
|
recursive: boolean | null;
|
|
30
31
|
ignoreCase: boolean | null;
|
|
31
32
|
filePattern: string | null;
|
|
@@ -35,15 +36,11 @@ export declare function initTools({ terminal, tokenCounter, events, autoAcceptAl
|
|
|
35
36
|
}, string>;
|
|
36
37
|
readonly codeInterpreter: import("ai").Tool<{
|
|
37
38
|
code: string;
|
|
38
|
-
type: "Typescript" | "JavaScript" | null;
|
|
39
39
|
timeoutSeconds: number | null;
|
|
40
40
|
}, string>;
|
|
41
41
|
readonly deleteFile: import("ai").Tool<{
|
|
42
42
|
path: string;
|
|
43
43
|
}, string>;
|
|
44
|
-
readonly directoryTree: import("ai").Tool<{
|
|
45
|
-
path: string;
|
|
46
|
-
}, string>;
|
|
47
44
|
readonly moveFile: import("ai").Tool<{
|
|
48
45
|
source: string;
|
|
49
46
|
destination: string;
|
|
@@ -77,9 +74,9 @@ export declare function initCliTools({ tokenCounter, }: {
|
|
|
77
74
|
query: string;
|
|
78
75
|
}, string>;
|
|
79
76
|
readonly bash: import("ai").Tool<{
|
|
77
|
+
command: string;
|
|
80
78
|
cwd: string | null;
|
|
81
79
|
timeout: number | null;
|
|
82
|
-
command: string;
|
|
83
80
|
}, string>;
|
|
84
81
|
readonly webFetch: import("ai").Tool<{
|
|
85
82
|
url: string;
|
|
@@ -88,8 +85,8 @@ export declare function initCliTools({ tokenCounter, }: {
|
|
|
88
85
|
thought: string;
|
|
89
86
|
}, string>;
|
|
90
87
|
readonly grepFiles: import("ai").Tool<{
|
|
91
|
-
path: string;
|
|
92
88
|
pattern: string;
|
|
89
|
+
path: string;
|
|
93
90
|
recursive: boolean | null;
|
|
94
91
|
ignoreCase: boolean | null;
|
|
95
92
|
filePattern: string | null;
|
|
@@ -99,15 +96,11 @@ export declare function initCliTools({ tokenCounter, }: {
|
|
|
99
96
|
}, string>;
|
|
100
97
|
readonly codeInterpreter: import("ai").Tool<{
|
|
101
98
|
code: string;
|
|
102
|
-
type: "Typescript" | "JavaScript" | null;
|
|
103
99
|
timeoutSeconds: number | null;
|
|
104
100
|
}, string>;
|
|
105
101
|
readonly deleteFile: import("ai").Tool<{
|
|
106
102
|
path: string;
|
|
107
103
|
}, string>;
|
|
108
|
-
readonly directoryTree: import("ai").Tool<{
|
|
109
|
-
path: string;
|
|
110
|
-
}, string>;
|
|
111
104
|
readonly moveFile: import("ai").Tool<{
|
|
112
105
|
source: string;
|
|
113
106
|
destination: string;
|
|
@@ -145,3 +138,4 @@ export declare function initAgents({ modelManager, tokenTracker, tokenCounter, e
|
|
|
145
138
|
prompt: string;
|
|
146
139
|
}, string>;
|
|
147
140
|
}>;
|
|
141
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAcxD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAe1C,wBAAsB,SAAS,CAAC,EAC9B,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,YAAY,GACb,EAAE;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IAC/B,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqGA;AAED,wBAAsB,YAAY,CAAC,EACjC,YAAY,GACb,EAAE;IACD,YAAY,EAAE,YAAY,CAAC;CAC5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+FA;AAED,wBAAsB,UAAU,CAAC,EAC/B,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;CAChC;;;;GAeA"}
|
package/dist/tools/index.js
CHANGED
|
@@ -2,7 +2,8 @@ import { createAgentTools } from "./agent.js";
|
|
|
2
2
|
import { createBashTool } from "./bash.js";
|
|
3
3
|
import { createCodeInterpreterTool } from "./code-interpreter.js";
|
|
4
4
|
import { createDeleteFileTool } from "./delete-file.js";
|
|
5
|
-
import { createDirectoryTreeTool } from "./directory-tree.
|
|
5
|
+
// import { createDirectoryTreeTool } from "./directory-tree.ts";
|
|
6
|
+
import { loadDynamicTools } from "./dynamic-tool-loader.js";
|
|
6
7
|
import { createEditFileTool } from "./edit-file.js";
|
|
7
8
|
import { createGrepTool } from "./grep.js";
|
|
8
9
|
import { createMoveFileTool } from "./move-file.js";
|
|
@@ -23,7 +24,7 @@ const sendDataHandler = (events) => {
|
|
|
23
24
|
}
|
|
24
25
|
};
|
|
25
26
|
};
|
|
26
|
-
export async function initTools({ terminal, tokenCounter, events,
|
|
27
|
+
export async function initTools({ terminal, tokenCounter, events, toolExecutor, }) {
|
|
27
28
|
const sendDataFn = sendDataHandler(events);
|
|
28
29
|
const readFileTool = await createReadFileTool({
|
|
29
30
|
workingDir: process.cwd(),
|
|
@@ -39,33 +40,35 @@ export async function initTools({ terminal, tokenCounter, events, autoAcceptAll,
|
|
|
39
40
|
workingDir: process.cwd(),
|
|
40
41
|
terminal,
|
|
41
42
|
sendData: sendDataFn,
|
|
42
|
-
|
|
43
|
+
toolExecutor,
|
|
43
44
|
});
|
|
44
45
|
const saveFileTool = await createSaveFileTool({
|
|
45
46
|
workingDir: process.cwd(),
|
|
46
47
|
sendData: sendDataFn,
|
|
47
48
|
terminal,
|
|
48
|
-
|
|
49
|
+
toolExecutor,
|
|
49
50
|
});
|
|
50
51
|
const moveFileTool = await createMoveFileTool({
|
|
51
52
|
workingDir: process.cwd(),
|
|
52
53
|
sendData: sendDataFn,
|
|
53
54
|
});
|
|
54
|
-
const directoryTreeTool = await createDirectoryTreeTool({
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
// const directoryTreeTool = await createDirectoryTreeTool({
|
|
56
|
+
// workingDir: process.cwd(),
|
|
57
|
+
// sendData: sendDataFn,
|
|
58
|
+
// tokenCounter,
|
|
59
|
+
// });
|
|
58
60
|
const deleteFileTool = await createDeleteFileTool({
|
|
59
61
|
workingDir: process.cwd(),
|
|
60
62
|
sendData: sendDataFn,
|
|
61
63
|
terminal,
|
|
62
|
-
|
|
64
|
+
toolExecutor,
|
|
63
65
|
});
|
|
64
66
|
const codeInterpreterTool = createCodeInterpreterTool({
|
|
65
67
|
sendData: sendDataFn,
|
|
66
68
|
});
|
|
67
69
|
const grepTool = createGrepTool({
|
|
68
70
|
sendData: sendDataFn,
|
|
71
|
+
tokenCounter,
|
|
69
72
|
});
|
|
70
73
|
const thinkTool = createThinkTool({
|
|
71
74
|
sendData: sendDataFn,
|
|
@@ -78,12 +81,16 @@ export async function initTools({ terminal, tokenCounter, events, autoAcceptAll,
|
|
|
78
81
|
sendData: sendDataFn,
|
|
79
82
|
tokenCounter,
|
|
80
83
|
});
|
|
81
|
-
const bashTool = createBashTool({
|
|
84
|
+
const bashTool = await createBashTool({
|
|
82
85
|
baseDir: process.cwd(),
|
|
83
86
|
sendData: sendDataFn,
|
|
84
87
|
tokenCounter,
|
|
85
88
|
terminal,
|
|
86
|
-
|
|
89
|
+
toolExecutor,
|
|
90
|
+
});
|
|
91
|
+
const dynamicTools = await loadDynamicTools({
|
|
92
|
+
baseDir: process.cwd(),
|
|
93
|
+
sendData: sendDataFn,
|
|
87
94
|
});
|
|
88
95
|
const tools = {
|
|
89
96
|
...readFileTool,
|
|
@@ -91,7 +98,7 @@ export async function initTools({ terminal, tokenCounter, events, autoAcceptAll,
|
|
|
91
98
|
...editFileTool,
|
|
92
99
|
...saveFileTool,
|
|
93
100
|
...moveFileTool,
|
|
94
|
-
...directoryTreeTool,
|
|
101
|
+
// ...directoryTreeTool,
|
|
95
102
|
...deleteFileTool,
|
|
96
103
|
...codeInterpreterTool,
|
|
97
104
|
...grepTool,
|
|
@@ -99,6 +106,7 @@ export async function initTools({ terminal, tokenCounter, events, autoAcceptAll,
|
|
|
99
106
|
...webFetchTool,
|
|
100
107
|
...bashTool,
|
|
101
108
|
...webSearchTool,
|
|
109
|
+
...dynamicTools,
|
|
102
110
|
};
|
|
103
111
|
return tools;
|
|
104
112
|
}
|
|
@@ -117,33 +125,32 @@ export async function initCliTools({ tokenCounter, }) {
|
|
|
117
125
|
workingDir: process.cwd(),
|
|
118
126
|
terminal: undefined,
|
|
119
127
|
sendData: undefined,
|
|
120
|
-
autoAcceptAll: true,
|
|
121
128
|
});
|
|
122
129
|
const saveFileTool = await createSaveFileTool({
|
|
123
130
|
workingDir: process.cwd(),
|
|
124
131
|
sendData: undefined,
|
|
125
132
|
terminal: undefined,
|
|
126
|
-
autoAcceptAll: true,
|
|
127
133
|
});
|
|
128
134
|
const moveFileTool = await createMoveFileTool({
|
|
129
135
|
workingDir: process.cwd(),
|
|
130
136
|
sendData: undefined,
|
|
131
137
|
});
|
|
132
|
-
const directoryTreeTool = await createDirectoryTreeTool({
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
138
|
+
// const directoryTreeTool = await createDirectoryTreeTool({
|
|
139
|
+
// workingDir: process.cwd(),
|
|
140
|
+
// sendData: undefined,
|
|
141
|
+
// tokenCounter,
|
|
142
|
+
// });
|
|
136
143
|
const deleteFileTool = await createDeleteFileTool({
|
|
137
144
|
workingDir: process.cwd(),
|
|
138
145
|
sendData: undefined,
|
|
139
146
|
terminal: undefined,
|
|
140
|
-
autoAcceptAll: true,
|
|
141
147
|
});
|
|
142
148
|
const codeInterpreterTool = createCodeInterpreterTool({
|
|
143
149
|
sendData: undefined,
|
|
144
150
|
});
|
|
145
151
|
const grepTool = createGrepTool({
|
|
146
152
|
sendData: undefined,
|
|
153
|
+
tokenCounter,
|
|
147
154
|
});
|
|
148
155
|
const thinkTool = createThinkTool({
|
|
149
156
|
sendData: undefined,
|
|
@@ -156,12 +163,15 @@ export async function initCliTools({ tokenCounter, }) {
|
|
|
156
163
|
sendData: undefined,
|
|
157
164
|
tokenCounter,
|
|
158
165
|
});
|
|
159
|
-
const bashTool = createBashTool({
|
|
166
|
+
const bashTool = await createBashTool({
|
|
160
167
|
baseDir: process.cwd(),
|
|
161
168
|
sendData: undefined,
|
|
162
169
|
tokenCounter,
|
|
163
170
|
terminal: undefined,
|
|
164
|
-
|
|
171
|
+
});
|
|
172
|
+
const dynamicTools = await loadDynamicTools({
|
|
173
|
+
baseDir: process.cwd(),
|
|
174
|
+
sendData: undefined,
|
|
165
175
|
});
|
|
166
176
|
const tools = {
|
|
167
177
|
...readFileTool,
|
|
@@ -169,7 +179,7 @@ export async function initCliTools({ tokenCounter, }) {
|
|
|
169
179
|
...editFileTool,
|
|
170
180
|
...saveFileTool,
|
|
171
181
|
...moveFileTool,
|
|
172
|
-
...directoryTreeTool,
|
|
182
|
+
// ...directoryTreeTool,
|
|
173
183
|
...deleteFileTool,
|
|
174
184
|
...codeInterpreterTool,
|
|
175
185
|
...grepTool,
|
|
@@ -177,6 +187,7 @@ export async function initCliTools({ tokenCounter, }) {
|
|
|
177
187
|
...webFetchTool,
|
|
178
188
|
...bashTool,
|
|
179
189
|
...webSearchTool,
|
|
190
|
+
...dynamicTools,
|
|
180
191
|
};
|
|
181
192
|
return tools;
|
|
182
193
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"move-file.d.ts","sourceRoot":"","sources":["../../source/tools/move-file.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,eAAO,MAAM,YAAY;;CAExB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAU,2BAGtC;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;;;;;EAsDA,CAAC"}
|
package/dist/tools/move-file.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import { tool } from "ai";
|
|
3
|
-
import chalk from "chalk";
|
|
4
3
|
import { z } from "zod";
|
|
4
|
+
import style from "../terminal/style.js";
|
|
5
5
|
import { joinWorkingDir, validatePath } from "./filesystem-utils.js";
|
|
6
6
|
export const MoveFileTool = {
|
|
7
7
|
name: "moveFile",
|
|
@@ -18,15 +18,22 @@ export const createMoveFileTool = async ({ workingDir, sendData, }) => {
|
|
|
18
18
|
source: z.string(),
|
|
19
19
|
destination: z.string(),
|
|
20
20
|
}),
|
|
21
|
-
execute: async ({ source, destination }, { toolCallId }) => {
|
|
21
|
+
execute: async ({ source, destination }, { toolCallId, abortSignal }) => {
|
|
22
|
+
// Check if execution has been aborted
|
|
23
|
+
if (abortSignal?.aborted) {
|
|
24
|
+
throw new Error("File move aborted");
|
|
25
|
+
}
|
|
22
26
|
try {
|
|
23
27
|
sendData?.({
|
|
24
28
|
id: toolCallId,
|
|
25
29
|
event: "tool-init",
|
|
26
|
-
data: `Moving file from ${
|
|
30
|
+
data: `Moving file from ${style.cyan(source)} to ${style.cyan(destination)}`,
|
|
27
31
|
});
|
|
28
|
-
const validSourcePath = await validatePath(joinWorkingDir(source, workingDir), allowedDirectory);
|
|
29
|
-
const validDestPath = await validatePath(joinWorkingDir(destination, workingDir), allowedDirectory);
|
|
32
|
+
const validSourcePath = await validatePath(joinWorkingDir(source, workingDir), allowedDirectory, { abortSignal });
|
|
33
|
+
const validDestPath = await validatePath(joinWorkingDir(destination, workingDir), allowedDirectory, { requireExistence: false, abortSignal });
|
|
34
|
+
if (abortSignal?.aborted) {
|
|
35
|
+
throw new Error("File move aborted before file operation");
|
|
36
|
+
}
|
|
30
37
|
await fs.rename(validSourcePath, validDestPath);
|
|
31
38
|
sendData?.({
|
|
32
39
|
id: toolCallId,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TokenCounter } from "../
|
|
1
|
+
import type { TokenCounter } from "../tokens/counter.ts";
|
|
2
2
|
import type { SendData } from "./types.ts";
|
|
3
3
|
export declare const ReadFileTool: {
|
|
4
4
|
name: "readFile";
|
|
@@ -15,3 +15,4 @@ export declare const createReadFileTool: ({ workingDir, sendData, tokenCounter,
|
|
|
15
15
|
lineCount: number | null;
|
|
16
16
|
}, string>;
|
|
17
17
|
}>;
|
|
18
|
+
//# sourceMappingURL=read-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-file.d.ts","sourceRoot":"","sources":["../../source/tools/read-file.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C,eAAO,MAAM,YAAY;;CAExB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAU,yCAItC;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,YAAY,EAAE,YAAY,CAAC;CAC5B;;;;;;;EAkHA,CAAC"}
|
package/dist/tools/read-file.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import { isNumber } from "@travisennis/stdlib/typeguards";
|
|
3
3
|
import { tool } from "ai";
|
|
4
|
-
import chalk from "chalk";
|
|
5
4
|
import { z } from "zod";
|
|
6
5
|
import { config } from "../config.js";
|
|
6
|
+
import style from "../terminal/style.js";
|
|
7
7
|
import { joinWorkingDir, validatePath } from "./filesystem-utils.js";
|
|
8
8
|
import { fileEncodingSchema } from "./types.js";
|
|
9
9
|
export const ReadFileTool = {
|
|
@@ -20,23 +20,30 @@ export const createReadFileTool = async ({ workingDir, sendData, tokenCounter, }
|
|
|
20
20
|
inputSchema: z.object({
|
|
21
21
|
path: z.string().describe("Absolute path to file to read"),
|
|
22
22
|
encoding: fileEncodingSchema.describe('Encoding format for reading the file. Use "utf-8" as default for text files'),
|
|
23
|
-
startLine: z
|
|
23
|
+
startLine: z.coerce
|
|
24
24
|
.number()
|
|
25
25
|
.nullable()
|
|
26
26
|
.describe("1-based line number to start reading from. Pass null to start at beginning of file"),
|
|
27
|
-
lineCount: z
|
|
27
|
+
lineCount: z.coerce
|
|
28
28
|
.number()
|
|
29
29
|
.nullable()
|
|
30
30
|
.describe("Maximum number of lines to read. Pass null to get all lines."),
|
|
31
31
|
}),
|
|
32
|
-
execute: async ({ path: providedPath, encoding, startLine, lineCount, }, { toolCallId }) => {
|
|
32
|
+
execute: async ({ path: providedPath, encoding, startLine, lineCount, }, { toolCallId, abortSignal }) => {
|
|
33
|
+
// Check if execution has been aborted
|
|
34
|
+
if (abortSignal?.aborted) {
|
|
35
|
+
throw new Error("File reading aborted");
|
|
36
|
+
}
|
|
33
37
|
sendData?.({
|
|
34
38
|
id: toolCallId,
|
|
35
39
|
event: "tool-init",
|
|
36
|
-
data: `Reading file: ${
|
|
40
|
+
data: `Reading file: ${style.cyan(providedPath)}${startLine ? style.cyan(`:${startLine}`) : ""}${lineCount ? style.cyan(`:${lineCount}`) : ""}`,
|
|
37
41
|
});
|
|
38
42
|
try {
|
|
39
|
-
const filePath = await validatePath(joinWorkingDir(providedPath, workingDir), allowedDirectory);
|
|
43
|
+
const filePath = await validatePath(joinWorkingDir(providedPath, workingDir), allowedDirectory, { abortSignal });
|
|
44
|
+
if (abortSignal?.aborted) {
|
|
45
|
+
throw new Error("File reading aborted before file read");
|
|
46
|
+
}
|
|
40
47
|
let file = await fs.readFile(filePath, { encoding });
|
|
41
48
|
// Apply line-based selection if requested
|
|
42
49
|
if (isNumber(startLine) || isNumber(lineCount)) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { TokenCounter } from "../
|
|
1
|
+
import type { TokenCounter } from "../tokens/counter.ts";
|
|
2
2
|
import type { SendData } from "./types.ts";
|
|
3
3
|
export declare const ReadMultipleFilesTool: {
|
|
4
4
|
name: "readMultipleFiles";
|
|
@@ -12,3 +12,4 @@ export declare const createReadMultipleFilesTool: ({ workingDir, sendData, token
|
|
|
12
12
|
paths: string[];
|
|
13
13
|
}, string>;
|
|
14
14
|
}>;
|
|
15
|
+
//# sourceMappingURL=read-multiple-files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-multiple-files.d.ts","sourceRoot":"","sources":["../../source/tools/read-multiple-files.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,eAAO,MAAM,qBAAqB;;CAEjC,CAAC;AAEF,eAAO,MAAM,2BAA2B,GAAU,yCAI/C;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,YAAY,EAAE,YAAY,CAAC;CAC5B;;;;EAmGA,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
1
2
|
import { tool } from "ai";
|
|
2
|
-
import chalk from "chalk";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { config } from "../config.js";
|
|
5
|
-
import {
|
|
5
|
+
import { formatFile } from "../formatting.js";
|
|
6
|
+
import style from "../terminal/style.js";
|
|
7
|
+
import { joinWorkingDir, validatePath } from "./filesystem-utils.js";
|
|
6
8
|
export const ReadMultipleFilesTool = {
|
|
7
9
|
name: "readMultipleFiles",
|
|
8
10
|
};
|
|
@@ -18,31 +20,64 @@ export const createReadMultipleFilesTool = async ({ workingDir, sendData, tokenC
|
|
|
18
20
|
inputSchema: z.object({
|
|
19
21
|
paths: z.array(z.string()),
|
|
20
22
|
}),
|
|
21
|
-
execute: async ({ paths }, { toolCallId }) => {
|
|
23
|
+
execute: async ({ paths }, { toolCallId, abortSignal }) => {
|
|
24
|
+
// Check if execution has been aborted
|
|
25
|
+
if (abortSignal?.aborted) {
|
|
26
|
+
throw new Error("Multiple file reading aborted");
|
|
27
|
+
}
|
|
22
28
|
sendData?.({
|
|
23
29
|
id: toolCallId,
|
|
24
30
|
event: "tool-init",
|
|
25
|
-
data: `Reading files: ${paths.map((p) =>
|
|
31
|
+
data: `Reading files: ${paths.map((p) => style.cyan(p)).join(", ")}`,
|
|
26
32
|
});
|
|
33
|
+
if (abortSignal?.aborted) {
|
|
34
|
+
throw new Error("Multiple file reading aborted before reading files");
|
|
35
|
+
}
|
|
27
36
|
const maxTokens = (await config.readProjectConfig()).tools.maxTokens;
|
|
28
|
-
const results = await Promise.all(paths.map((filePath) =>
|
|
37
|
+
const results = await Promise.all(paths.map(async (filePath) => {
|
|
38
|
+
if (abortSignal?.aborted) {
|
|
39
|
+
throw new Error("Multiple file reading aborted during file processing");
|
|
40
|
+
}
|
|
41
|
+
const fileResult = await validateAndReadFile(filePath, workingDir, allowedDirectory);
|
|
42
|
+
return countTokensAndCheckLimit(fileResult, tokenCounter, maxTokens);
|
|
43
|
+
}));
|
|
29
44
|
let totalTokens = 0;
|
|
30
45
|
let filesReadCount = 0;
|
|
46
|
+
let filesExceededLimitCount = 0;
|
|
47
|
+
let filesErrorCount = 0;
|
|
31
48
|
const formattedResults = results.map((result) => {
|
|
32
49
|
if (result.error) {
|
|
50
|
+
filesErrorCount++;
|
|
33
51
|
return `${result.path}: Error - ${result.error}`;
|
|
34
52
|
}
|
|
35
53
|
// Check if tokenCount is > 0, meaning it wasn't skipped
|
|
36
54
|
if (result.tokenCount > 0) {
|
|
37
55
|
filesReadCount++;
|
|
38
56
|
}
|
|
57
|
+
else if (result.content?.includes("exceeds maximum allowed tokens")) {
|
|
58
|
+
filesExceededLimitCount++;
|
|
59
|
+
}
|
|
39
60
|
totalTokens += result.tokenCount; // Add the token count (will be 0 for skipped files)
|
|
40
61
|
// Return content (or max token message)
|
|
41
|
-
return
|
|
62
|
+
return formatFile(result.path, result.content ?? "", "markdown");
|
|
42
63
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
64
|
+
let completionMessage;
|
|
65
|
+
if (filesReadCount === paths.length) {
|
|
66
|
+
completionMessage = `Read ${paths.length} files successfully (${totalTokens} total tokens).`;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
const parts = [];
|
|
70
|
+
if (filesReadCount > 0) {
|
|
71
|
+
parts.push(`Read ${filesReadCount} files successfully (${totalTokens} total tokens)`);
|
|
72
|
+
}
|
|
73
|
+
if (filesExceededLimitCount > 0) {
|
|
74
|
+
parts.push(`${filesExceededLimitCount} files exceeded token limit and were skipped`);
|
|
75
|
+
}
|
|
76
|
+
if (filesErrorCount > 0) {
|
|
77
|
+
parts.push(`${filesErrorCount} files could not be read`);
|
|
78
|
+
}
|
|
79
|
+
completionMessage = `${parts.join(", ")}.`;
|
|
80
|
+
}
|
|
46
81
|
sendData?.({
|
|
47
82
|
id: toolCallId,
|
|
48
83
|
event: "tool-completion",
|
|
@@ -53,3 +88,49 @@ export const createReadMultipleFilesTool = async ({ workingDir, sendData, tokenC
|
|
|
53
88
|
}),
|
|
54
89
|
};
|
|
55
90
|
};
|
|
91
|
+
async function validateAndReadFile(filePath, workingDir, allowedDirectory) {
|
|
92
|
+
try {
|
|
93
|
+
const validPath = await validatePath(joinWorkingDir(filePath, workingDir), allowedDirectory);
|
|
94
|
+
const content = await readFile(validPath, "utf-8");
|
|
95
|
+
return {
|
|
96
|
+
path: filePath,
|
|
97
|
+
content,
|
|
98
|
+
error: null,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
103
|
+
return {
|
|
104
|
+
path: filePath,
|
|
105
|
+
content: null,
|
|
106
|
+
error: errorMessage,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async function countTokensAndCheckLimit(fileResult, tokenCounter, maxTokens) {
|
|
111
|
+
if (fileResult.error || fileResult.content === null) {
|
|
112
|
+
return {
|
|
113
|
+
path: fileResult.path,
|
|
114
|
+
content: null,
|
|
115
|
+
tokenCount: 0,
|
|
116
|
+
error: fileResult.error,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
let tokenCount = 0;
|
|
120
|
+
try {
|
|
121
|
+
tokenCount = tokenCounter.count(fileResult.content);
|
|
122
|
+
}
|
|
123
|
+
catch (tokenError) {
|
|
124
|
+
console.error("Error calculating token count:", tokenError);
|
|
125
|
+
// Handle token calculation error if needed
|
|
126
|
+
}
|
|
127
|
+
const maxTokenMessage = `File content (${tokenCount} tokens) exceeds maximum allowed tokens (${maxTokens}). Use readFile with startLine/lineCount or grepFiles for targeted access.`;
|
|
128
|
+
const finalContent = tokenCount > maxTokens ? maxTokenMessage : fileResult.content;
|
|
129
|
+
const actualTokenCount = tokenCount > maxTokens ? 0 : tokenCount; // Don't count tokens for skipped files
|
|
130
|
+
return {
|
|
131
|
+
path: fileResult.path,
|
|
132
|
+
content: finalContent,
|
|
133
|
+
tokenCount: actualTokenCount,
|
|
134
|
+
error: null,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { Terminal } from "../terminal/index.ts";
|
|
2
|
+
import type { ToolExecutor } from "../tool-executor.ts";
|
|
2
3
|
import { type SendData } from "./types.ts";
|
|
3
4
|
export declare const SaveFileTool: {
|
|
4
5
|
name: "saveFile";
|
|
5
6
|
};
|
|
6
|
-
export declare const createSaveFileTool: ({ workingDir,
|
|
7
|
+
export declare const createSaveFileTool: ({ workingDir, terminal, sendData, toolExecutor, }: {
|
|
7
8
|
workingDir: string;
|
|
8
|
-
sendData?: SendData;
|
|
9
9
|
terminal?: Terminal;
|
|
10
|
-
|
|
10
|
+
sendData?: SendData;
|
|
11
|
+
toolExecutor?: ToolExecutor;
|
|
11
12
|
}) => Promise<{
|
|
12
13
|
saveFile: import("ai").Tool<{
|
|
13
14
|
path: string;
|
|
@@ -15,3 +16,4 @@ export declare const createSaveFileTool: ({ workingDir, sendData, terminal, auto
|
|
|
15
16
|
encoding: "utf8" | "ascii" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex";
|
|
16
17
|
}, string>;
|
|
17
18
|
}>;
|
|
19
|
+
//# sourceMappingURL=save-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"save-file.d.ts","sourceRoot":"","sources":["../../source/tools/save-file.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,KAAK,EAAe,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAErE,OAAO,EAAsB,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE/D,eAAO,MAAM,YAAY;;CAExB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAU,mDAKtC;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B;;;;;;EAoJA,CAAC"}
|