@travisennis/acai 0.0.7 → 0.0.8
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 +42 -25
- package/dist/agent/index.d.ts +21 -25
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +115 -104
- package/dist/cli.d.ts +2 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +21 -16
- package/dist/commands/add-directory/index.d.ts +3 -0
- package/dist/commands/add-directory/index.d.ts.map +1 -0
- package/dist/commands/{add-directory-command.js → add-directory/index.js} +6 -10
- package/dist/commands/add-directory/types.d.ts +6 -0
- package/dist/commands/add-directory/types.d.ts.map +1 -0
- package/dist/commands/add-directory/types.js +1 -0
- package/dist/commands/add-directory/utils.d.ts +3 -0
- package/dist/commands/add-directory/utils.d.ts.map +1 -0
- package/dist/commands/add-directory/utils.js +15 -0
- package/dist/commands/clear/index.d.ts +3 -0
- package/dist/commands/clear/index.d.ts.map +1 -0
- package/dist/commands/{clear-command.js → clear/index.js} +0 -2
- package/dist/commands/copy/index.d.ts +3 -0
- package/dist/commands/copy/index.d.ts.map +1 -0
- package/dist/commands/{copy-command.js → copy/index.js} +4 -26
- package/dist/commands/copy/types.d.ts +3 -0
- package/dist/commands/copy/types.d.ts.map +1 -0
- package/dist/commands/copy/types.js +1 -0
- package/dist/commands/copy/utils.d.ts +3 -0
- package/dist/commands/copy/utils.d.ts.map +1 -0
- package/dist/commands/copy/utils.js +22 -0
- package/dist/commands/{exit-command.d.ts → exit/index.d.ts} +4 -4
- package/dist/commands/exit/index.d.ts.map +1 -0
- package/dist/commands/exit/index.js +21 -0
- package/dist/commands/exit/types.d.ts +8 -0
- package/dist/commands/exit/types.d.ts.map +1 -0
- package/dist/commands/exit/types.js +1 -0
- package/dist/commands/exit/utils.d.ts +2 -0
- package/dist/commands/exit/utils.d.ts.map +1 -0
- package/dist/commands/exit/utils.js +13 -0
- package/dist/commands/generate-rules/index.d.ts +3 -0
- package/dist/commands/generate-rules/index.d.ts.map +1 -0
- package/dist/commands/{generate-rules-command.js → generate-rules/index.js} +55 -95
- package/dist/commands/generate-rules/utils.d.ts +5 -0
- package/dist/commands/generate-rules/utils.d.ts.map +1 -0
- package/dist/commands/generate-rules/utils.js +25 -0
- package/dist/commands/handoff/index.d.ts +3 -0
- package/dist/commands/handoff/index.d.ts.map +1 -0
- package/dist/commands/handoff/index.js +97 -0
- package/dist/commands/handoff/utils.d.ts +4 -0
- package/dist/commands/handoff/utils.d.ts.map +1 -0
- package/dist/commands/{handoff-command.js → handoff/utils.js} +24 -92
- package/dist/commands/health/index.d.ts +3 -0
- package/dist/commands/health/index.d.ts.map +1 -0
- package/dist/commands/health/index.js +56 -0
- package/dist/commands/health/utils.d.ts +15 -0
- package/dist/commands/health/utils.d.ts.map +1 -0
- package/dist/commands/health/utils.js +52 -0
- package/dist/commands/{help-command.d.ts → help/index.d.ts} +2 -2
- package/dist/commands/help/index.d.ts.map +1 -0
- package/dist/commands/{help-command.js → help/index.js} +1 -1
- package/dist/commands/history/index.d.ts +3 -0
- package/dist/commands/history/index.d.ts.map +1 -0
- package/dist/commands/{history-command.js → history/index.js} +16 -100
- package/dist/commands/history/types.d.ts +11 -0
- package/dist/commands/history/types.d.ts.map +1 -0
- package/dist/commands/history/types.js +1 -0
- package/dist/commands/history/utils.d.ts +4 -0
- package/dist/commands/history/utils.d.ts.map +1 -0
- package/dist/commands/history/utils.js +86 -0
- package/dist/commands/init/index.d.ts +3 -0
- package/dist/commands/init/index.d.ts.map +1 -0
- package/dist/commands/{init-command.js → init/index.js} +16 -7
- package/dist/commands/init-project/index.d.ts +3 -0
- package/dist/commands/init-project/index.d.ts.map +1 -0
- package/dist/commands/init-project/index.js +51 -0
- package/dist/commands/init-project/utils.d.ts +9 -0
- package/dist/commands/init-project/utils.d.ts.map +1 -0
- package/dist/commands/init-project/utils.js +43 -0
- package/dist/commands/list-directories/index.d.ts +3 -0
- package/dist/commands/list-directories/index.d.ts.map +1 -0
- package/dist/commands/{list-directories-command.js → list-directories/index.js} +1 -1
- package/dist/commands/list-tools/index.d.ts +3 -0
- package/dist/commands/list-tools/index.d.ts.map +1 -0
- package/dist/commands/{list-tools-command.js → list-tools/index.js} +4 -16
- package/dist/commands/manager.d.ts +2 -2
- package/dist/commands/manager.d.ts.map +1 -1
- package/dist/commands/manager.js +33 -43
- package/dist/commands/model/index.d.ts +3 -0
- package/dist/commands/model/index.d.ts.map +1 -0
- package/dist/commands/{model-command.js → model/index.js} +15 -52
- package/dist/commands/model/utils.d.ts +3 -0
- package/dist/commands/model/utils.d.ts.map +1 -0
- package/dist/commands/model/utils.js +5 -0
- package/dist/commands/{paste-command.d.ts → paste/index.d.ts} +2 -2
- package/dist/commands/paste/index.d.ts.map +1 -0
- package/dist/commands/{paste-command.js → paste/index.js} +6 -111
- package/dist/commands/paste/utils.d.ts +5 -0
- package/dist/commands/paste/utils.d.ts.map +1 -0
- package/dist/commands/paste/utils.js +86 -0
- package/dist/commands/pickup/index.d.ts +3 -0
- package/dist/commands/pickup/index.d.ts.map +1 -0
- package/dist/commands/pickup/index.js +138 -0
- package/dist/commands/pickup/types.d.ts +6 -0
- package/dist/commands/pickup/types.d.ts.map +1 -0
- package/dist/commands/pickup/types.js +1 -0
- package/dist/commands/pickup/utils.d.ts +7 -0
- package/dist/commands/pickup/utils.d.ts.map +1 -0
- package/dist/commands/pickup/utils.js +56 -0
- package/dist/commands/prompt/index.d.ts +5 -0
- package/dist/commands/prompt/index.d.ts.map +1 -0
- package/dist/commands/prompt/index.js +126 -0
- package/dist/commands/prompt/types.d.ts +15 -0
- package/dist/commands/prompt/types.d.ts.map +1 -0
- package/dist/commands/prompt/types.js +1 -0
- package/dist/commands/prompt/utils.d.ts +12 -0
- package/dist/commands/prompt/utils.d.ts.map +1 -0
- package/dist/commands/prompt/utils.js +107 -0
- package/dist/commands/remove-directory/index.d.ts +3 -0
- package/dist/commands/remove-directory/index.d.ts.map +1 -0
- package/dist/commands/{remove-directory-command.js → remove-directory/index.js} +2 -2
- package/dist/commands/reset/index.d.ts +3 -0
- package/dist/commands/reset/index.d.ts.map +1 -0
- package/dist/commands/{reset-command.js → reset/index.js} +7 -2
- package/dist/commands/reset/types.d.ts +1 -0
- package/dist/commands/reset/types.d.ts.map +1 -0
- package/dist/commands/reset/types.js +3 -0
- package/dist/commands/resources/index.d.ts +3 -0
- package/dist/commands/resources/index.d.ts.map +1 -0
- package/dist/commands/resources/index.js +84 -0
- package/dist/commands/review/index.d.ts +3 -0
- package/dist/commands/review/index.d.ts.map +1 -0
- package/dist/commands/review/index.js +126 -0
- package/dist/commands/review/types.d.ts +12 -0
- package/dist/commands/review/types.d.ts.map +1 -0
- package/dist/commands/review/types.js +1 -0
- package/dist/commands/review/utils.d.ts +4 -0
- package/dist/commands/review/utils.d.ts.map +1 -0
- package/dist/commands/review/utils.js +87 -0
- package/dist/commands/save/index.d.ts +3 -0
- package/dist/commands/save/index.d.ts.map +1 -0
- package/dist/commands/{save-command.js → save/index.js} +3 -3
- package/dist/commands/session/index.d.ts +3 -0
- package/dist/commands/session/index.d.ts.map +1 -0
- package/dist/commands/session/index.js +197 -0
- package/dist/commands/session/types.d.ts +13 -0
- package/dist/commands/session/types.d.ts.map +1 -0
- package/dist/commands/session/types.js +7 -0
- package/dist/commands/shell/index.d.ts +3 -0
- package/dist/commands/shell/index.d.ts.map +1 -0
- package/dist/commands/{shell-command.js → shell/index.js} +3 -3
- package/dist/commands/types.d.ts +2 -2
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/config.d.ts +25 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +45 -20
- package/dist/dedent.d.ts.map +1 -1
- package/dist/dedent.js +7 -7
- package/dist/execution/index.d.ts +1 -0
- package/dist/execution/index.d.ts.map +1 -1
- package/dist/execution/index.js +60 -64
- package/dist/formatting.d.ts +27 -0
- package/dist/formatting.d.ts.map +1 -1
- package/dist/formatting.js +40 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +138 -75
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +4 -11
- package/dist/mentions.d.ts.map +1 -1
- package/dist/mentions.js +3 -53
- package/dist/middleware/audit-message.d.ts +2 -2
- package/dist/middleware/audit-message.d.ts.map +1 -1
- package/dist/middleware/audit-message.js +40 -2
- package/dist/middleware/cache.d.ts +2 -2
- package/dist/middleware/cache.d.ts.map +1 -1
- package/dist/middleware/cache.js +111 -27
- package/dist/middleware/rate-limit.d.ts +2 -2
- package/dist/middleware/rate-limit.d.ts.map +1 -1
- package/dist/middleware/rate-limit.js +1 -0
- package/dist/models/ai-config.d.ts.map +1 -1
- package/dist/models/ai-config.js +46 -29
- package/dist/models/anthropic-provider.d.ts +14 -13
- package/dist/models/anthropic-provider.d.ts.map +1 -1
- package/dist/models/deepseek-provider.d.ts +9 -8
- package/dist/models/deepseek-provider.d.ts.map +1 -1
- package/dist/models/google-provider.d.ts +10 -9
- package/dist/models/google-provider.d.ts.map +1 -1
- package/dist/models/groq-provider.d.ts +8 -7
- package/dist/models/groq-provider.d.ts.map +1 -1
- package/dist/models/manager.d.ts +7 -4
- package/dist/models/manager.d.ts.map +1 -1
- package/dist/models/manager.js +5 -25
- package/dist/models/openai-provider.d.ts +11 -10
- package/dist/models/openai-provider.d.ts.map +1 -1
- package/dist/models/opencode-zen-provider.d.ts +23 -0
- package/dist/models/opencode-zen-provider.d.ts.map +1 -0
- package/dist/models/opencode-zen-provider.js +76 -0
- package/dist/models/openrouter-provider.d.ts +34 -29
- package/dist/models/openrouter-provider.d.ts.map +1 -1
- package/dist/models/openrouter-provider.js +95 -80
- package/dist/models/providers.d.ts +4 -4
- package/dist/models/providers.d.ts.map +1 -1
- package/dist/models/providers.js +7 -1
- package/dist/models/xai-provider.d.ts +9 -8
- package/dist/models/xai-provider.d.ts.map +1 -1
- package/dist/prompts/manager.d.ts +1 -1
- package/dist/prompts/manager.d.ts.map +1 -1
- package/dist/prompts/manager.js +1 -1
- package/dist/prompts.d.ts +0 -1
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +56 -406
- package/dist/repl/project-status.d.ts +19 -0
- package/dist/repl/project-status.d.ts.map +1 -0
- package/dist/repl/project-status.js +78 -0
- package/dist/repl-new.d.ts +15 -4
- package/dist/repl-new.d.ts.map +1 -1
- package/dist/repl-new.js +245 -42
- package/dist/{messages.d.ts → sessions/manager.d.ts} +10 -4
- package/dist/sessions/manager.d.ts.map +1 -0
- package/dist/{messages.js → sessions/manager.js} +60 -14
- package/dist/skills.d.ts +0 -4
- package/dist/skills.d.ts.map +1 -1
- package/dist/skills.js +100 -59
- package/dist/terminal/control.d.ts +1 -0
- package/dist/terminal/control.d.ts.map +1 -1
- package/dist/terminal/control.js +2 -0
- package/dist/terminal/formatting.d.ts +1 -2
- package/dist/terminal/formatting.d.ts.map +1 -1
- package/dist/terminal/formatting.js +1 -2
- package/dist/terminal/keys.d.ts +211 -0
- package/dist/terminal/keys.d.ts.map +1 -0
- package/dist/terminal/keys.js +546 -0
- package/dist/terminal/segmenter.d.ts +6 -0
- package/dist/terminal/segmenter.d.ts.map +1 -0
- package/dist/terminal/segmenter.js +11 -0
- package/dist/terminal/select-prompt.d.ts.map +1 -1
- package/dist/terminal/select-prompt.js +9 -21
- package/dist/terminal/string-width.d.ts.map +1 -1
- package/dist/terminal/string-width.js +40 -21
- package/dist/terminal/strip-ansi.d.ts.map +1 -1
- package/dist/terminal/strip-ansi.js +9 -15
- package/dist/tokens/tracker.d.ts.map +1 -1
- package/dist/tokens/tracker.js +58 -16
- package/dist/tools/bash.d.ts +9 -11
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +69 -123
- package/dist/tools/directory-tree.d.ts +9 -7
- package/dist/tools/directory-tree.d.ts.map +1 -1
- package/dist/tools/directory-tree.js +89 -70
- package/dist/tools/dynamic-tool-loader.d.ts +22 -4
- package/dist/tools/dynamic-tool-loader.d.ts.map +1 -1
- package/dist/tools/dynamic-tool-loader.js +39 -44
- package/dist/tools/edit-file.d.ts +6 -16
- package/dist/tools/edit-file.d.ts.map +1 -1
- package/dist/tools/edit-file.js +19 -76
- package/dist/tools/glob.d.ts +15 -16
- package/dist/tools/glob.d.ts.map +1 -1
- package/dist/tools/glob.js +77 -119
- package/dist/tools/grep.d.ts +19 -22
- package/dist/tools/grep.d.ts.map +1 -1
- package/dist/tools/grep.js +61 -108
- package/dist/tools/index.d.ts +200 -179
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +17 -315
- package/dist/tools/ls.d.ts +26 -0
- package/dist/tools/ls.d.ts.map +1 -0
- package/dist/tools/ls.js +80 -0
- package/dist/tools/read-file.d.ts +15 -15
- package/dist/tools/read-file.d.ts.map +1 -1
- package/dist/tools/read-file.js +49 -82
- package/dist/tools/save-file.d.ts +4 -4
- package/dist/tools/save-file.d.ts.map +1 -1
- package/dist/tools/save-file.js +37 -66
- package/dist/tools/think.d.ts +4 -4
- package/dist/tools/think.d.ts.map +1 -1
- package/dist/tools/think.js +9 -38
- package/dist/tools/types.d.ts +5 -25
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js +0 -9
- package/dist/tui/autocomplete/attachment-provider.d.ts +18 -0
- package/dist/tui/autocomplete/attachment-provider.d.ts.map +1 -0
- package/dist/tui/autocomplete/attachment-provider.js +159 -0
- package/dist/tui/autocomplete/base-provider.d.ts +17 -0
- package/dist/tui/autocomplete/base-provider.d.ts.map +1 -0
- package/dist/tui/autocomplete/base-provider.js +1 -0
- package/dist/tui/autocomplete/combined-provider.d.ts +20 -0
- package/dist/tui/autocomplete/combined-provider.d.ts.map +1 -0
- package/dist/tui/autocomplete/combined-provider.js +61 -0
- package/dist/tui/autocomplete/command-provider.d.ts +20 -0
- package/dist/tui/autocomplete/command-provider.d.ts.map +1 -0
- package/dist/tui/autocomplete/command-provider.js +90 -0
- package/dist/tui/autocomplete/file-search-provider.d.ts +16 -0
- package/dist/tui/autocomplete/file-search-provider.d.ts.map +1 -0
- package/dist/tui/autocomplete/file-search-provider.js +123 -0
- package/dist/tui/autocomplete/path-provider.d.ts +21 -0
- package/dist/tui/autocomplete/path-provider.d.ts.map +1 -0
- package/dist/tui/autocomplete/path-provider.js +164 -0
- package/dist/tui/autocomplete/utils.d.ts +16 -0
- package/dist/tui/autocomplete/utils.d.ts.map +1 -0
- package/dist/tui/autocomplete/utils.js +137 -0
- package/dist/tui/autocomplete.d.ts +12 -43
- package/dist/tui/autocomplete.d.ts.map +1 -1
- package/dist/tui/autocomplete.js +20 -465
- package/dist/tui/components/box.d.ts.map +1 -1
- package/dist/tui/components/box.js +16 -10
- package/dist/tui/components/editor.d.ts +1 -2
- package/dist/tui/components/editor.d.ts.map +1 -1
- package/dist/tui/components/editor.js +148 -107
- package/dist/tui/components/footer.d.ts +20 -7
- package/dist/tui/components/footer.d.ts.map +1 -1
- package/dist/tui/components/footer.js +89 -196
- package/dist/tui/components/input.d.ts.map +1 -1
- package/dist/tui/components/input.js +8 -7
- package/dist/tui/components/loader.d.ts +2 -1
- package/dist/tui/components/loader.d.ts.map +1 -1
- package/dist/tui/components/loader.js +7 -2
- package/dist/tui/components/markdown.d.ts +5 -4
- package/dist/tui/components/markdown.d.ts.map +1 -1
- package/dist/tui/components/markdown.js +51 -40
- package/dist/tui/components/modal.d.ts.map +1 -1
- package/dist/tui/components/modal.js +9 -8
- package/dist/tui/components/notification.d.ts +28 -0
- package/dist/tui/components/notification.d.ts.map +1 -0
- package/dist/tui/components/notification.js +63 -0
- package/dist/tui/components/progress-bar.d.ts.map +1 -1
- package/dist/tui/components/progress-bar.js +3 -15
- package/dist/tui/components/select-list.d.ts +0 -15
- package/dist/tui/components/select-list.d.ts.map +1 -1
- package/dist/tui/components/select-list.js +5 -28
- package/dist/tui/components/tool-execution.d.ts +3 -6
- package/dist/tui/components/tool-execution.d.ts.map +1 -1
- package/dist/tui/components/tool-execution.js +26 -38
- package/dist/tui/components/welcome.d.ts +8 -1
- package/dist/tui/components/welcome.d.ts.map +1 -1
- package/dist/tui/components/welcome.js +45 -6
- package/dist/tui/index.d.ts +4 -2
- package/dist/tui/index.d.ts.map +1 -1
- package/dist/tui/index.js +2 -2
- package/dist/tui/terminal.d.ts +2 -2
- package/dist/tui/terminal.d.ts.map +1 -1
- package/dist/tui/terminal.js +23 -19
- package/dist/tui/tui.d.ts +1 -0
- package/dist/tui/tui.d.ts.map +1 -1
- package/dist/tui/tui.js +24 -29
- package/dist/tui/utils.d.ts.map +1 -1
- package/dist/tui/utils.js +2 -3
- package/dist/utils/yaml.d.ts +11 -0
- package/dist/utils/yaml.d.ts.map +1 -0
- package/dist/utils/yaml.js +207 -0
- package/dist/utils/zod.d.ts +1 -0
- package/dist/utils/zod.d.ts.map +1 -1
- package/dist/utils/zod.js +17 -0
- package/package.json +31 -29
- package/bin/acai-wrapper.js +0 -26
- package/dist/api/exa/index.d.ts +0 -177
- package/dist/api/exa/index.d.ts.map +0 -1
- package/dist/api/exa/index.js +0 -439
- package/dist/commands/add-directory-command.d.ts +0 -3
- package/dist/commands/add-directory-command.d.ts.map +0 -1
- package/dist/commands/application-log-command.d.ts +0 -3
- package/dist/commands/application-log-command.d.ts.map +0 -1
- package/dist/commands/application-log-command.js +0 -43
- package/dist/commands/clear-command.d.ts +0 -3
- package/dist/commands/clear-command.d.ts.map +0 -1
- package/dist/commands/compact-command.d.ts +0 -3
- package/dist/commands/compact-command.d.ts.map +0 -1
- package/dist/commands/compact-command.js +0 -55
- package/dist/commands/context-command.d.ts +0 -3
- package/dist/commands/context-command.d.ts.map +0 -1
- package/dist/commands/context-command.js +0 -124
- package/dist/commands/copy-command.d.ts +0 -3
- package/dist/commands/copy-command.d.ts.map +0 -1
- package/dist/commands/edit-command.d.ts +0 -3
- package/dist/commands/edit-command.d.ts.map +0 -1
- package/dist/commands/edit-command.js +0 -42
- package/dist/commands/edit-prompt-command.d.ts +0 -3
- package/dist/commands/edit-prompt-command.d.ts.map +0 -1
- package/dist/commands/edit-prompt-command.js +0 -36
- package/dist/commands/exit-command.d.ts.map +0 -1
- package/dist/commands/exit-command.js +0 -30
- package/dist/commands/files-command.d.ts +0 -3
- package/dist/commands/files-command.d.ts.map +0 -1
- package/dist/commands/files-command.js +0 -68
- package/dist/commands/generate-rules-command.d.ts +0 -3
- package/dist/commands/generate-rules-command.d.ts.map +0 -1
- package/dist/commands/handoff-command.d.ts +0 -3
- package/dist/commands/handoff-command.d.ts.map +0 -1
- package/dist/commands/health-command.d.ts +0 -4
- package/dist/commands/health-command.d.ts.map +0 -1
- package/dist/commands/health-command.js +0 -118
- package/dist/commands/help-command.d.ts.map +0 -1
- package/dist/commands/history-command.d.ts +0 -3
- package/dist/commands/history-command.d.ts.map +0 -1
- package/dist/commands/init-command.d.ts +0 -3
- package/dist/commands/init-command.d.ts.map +0 -1
- package/dist/commands/last-log-command.d.ts +0 -3
- package/dist/commands/last-log-command.d.ts.map +0 -1
- package/dist/commands/last-log-command.js +0 -71
- package/dist/commands/list-directories-command.d.ts +0 -3
- package/dist/commands/list-directories-command.d.ts.map +0 -1
- package/dist/commands/list-tools-command.d.ts +0 -3
- package/dist/commands/list-tools-command.d.ts.map +0 -1
- package/dist/commands/model-command.d.ts +0 -3
- package/dist/commands/model-command.d.ts.map +0 -1
- package/dist/commands/paste-command.d.ts.map +0 -1
- package/dist/commands/pickup-command.d.ts +0 -3
- package/dist/commands/pickup-command.d.ts.map +0 -1
- package/dist/commands/pickup-command.js +0 -109
- package/dist/commands/prompt-command.d.ts +0 -21
- package/dist/commands/prompt-command.d.ts.map +0 -1
- package/dist/commands/prompt-command.js +0 -258
- package/dist/commands/remove-directory-command.d.ts +0 -3
- package/dist/commands/remove-directory-command.d.ts.map +0 -1
- package/dist/commands/reset-command.d.ts +0 -3
- package/dist/commands/reset-command.d.ts.map +0 -1
- package/dist/commands/rules-command.d.ts +0 -3
- package/dist/commands/rules-command.d.ts.map +0 -1
- package/dist/commands/rules-command.js +0 -73
- package/dist/commands/save-command.d.ts +0 -3
- package/dist/commands/save-command.d.ts.map +0 -1
- package/dist/commands/shell-command.d.ts +0 -3
- package/dist/commands/shell-command.d.ts.map +0 -1
- package/dist/commands/usage-command.d.ts +0 -3
- package/dist/commands/usage-command.d.ts.map +0 -1
- package/dist/commands/usage-command.js +0 -31
- package/dist/messages.d.ts.map +0 -1
- package/dist/repl/project-status-line.d.ts +0 -3
- package/dist/repl/project-status-line.d.ts.map +0 -1
- package/dist/repl/project-status-line.js +0 -61
- package/dist/repl/tool-call-repair.d.ts +0 -4
- package/dist/repl/tool-call-repair.d.ts.map +0 -1
- package/dist/repl/tool-call-repair.js +0 -54
- package/dist/terminal/markdown.d.ts +0 -2
- package/dist/terminal/markdown.d.ts.map +0 -1
- package/dist/terminal/markdown.js +0 -120
- package/dist/tokens/threshold.d.ts +0 -20
- package/dist/tokens/threshold.d.ts.map +0 -1
- package/dist/tokens/threshold.js +0 -67
- package/dist/tools/advanced-edit-file.d.ts +0 -69
- package/dist/tools/advanced-edit-file.d.ts.map +0 -1
- package/dist/tools/advanced-edit-file.js +0 -285
- package/dist/tools/agent.d.ts +0 -29
- package/dist/tools/agent.d.ts.map +0 -1
- package/dist/tools/agent.js +0 -117
- package/dist/tools/batch.d.ts +0 -34
- package/dist/tools/batch.d.ts.map +0 -1
- package/dist/tools/batch.js +0 -174
- package/dist/tools/code-interpreter.d.ts +0 -25
- package/dist/tools/code-interpreter.d.ts.map +0 -1
- package/dist/tools/code-interpreter.js +0 -183
- package/dist/tools/delete-file.d.ts +0 -24
- package/dist/tools/delete-file.d.ts.map +0 -1
- package/dist/tools/delete-file.js +0 -77
- package/dist/tools/dynamic-tool-parser.d.ts +0 -21
- package/dist/tools/dynamic-tool-parser.d.ts.map +0 -1
- package/dist/tools/dynamic-tool-parser.js +0 -22
- package/dist/tools/llm-edit-fixer.d.ts +0 -24
- package/dist/tools/llm-edit-fixer.d.ts.map +0 -1
- package/dist/tools/llm-edit-fixer.js +0 -136
- package/dist/tools/move-file.d.ts +0 -26
- package/dist/tools/move-file.d.ts.map +0 -1
- package/dist/tools/move-file.js +0 -65
- package/dist/tools/read-multiple-files.d.ts +0 -26
- package/dist/tools/read-multiple-files.d.ts.map +0 -1
- package/dist/tools/read-multiple-files.js +0 -196
- package/dist/tools/web-fetch.d.ts +0 -56
- package/dist/tools/web-fetch.d.ts.map +0 -1
- package/dist/tools/web-fetch.js +0 -247
- package/dist/tools/web-search.d.ts +0 -23
- package/dist/tools/web-search.d.ts.map +0 -1
- package/dist/tools/web-search.js +0 -148
- package/dist/tui/components/prompt-status.d.ts +0 -17
- package/dist/tui/components/prompt-status.d.ts.map +0 -1
- package/dist/tui/components/prompt-status.js +0 -26
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { formatFile } from "../formatting.js";
|
|
4
|
-
import style from "../terminal/style.js";
|
|
5
|
-
import { manageTokenLimit, TokenLimitExceededError, } from "../tokens/threshold.js";
|
|
6
|
-
import { joinWorkingDir, validatePath } from "../utils/filesystem/security.js";
|
|
7
|
-
export const ReadMultipleFilesTool = {
|
|
8
|
-
name: "readMultipleFiles",
|
|
9
|
-
};
|
|
10
|
-
const inputSchema = z.object({
|
|
11
|
-
paths: z.array(z.string()),
|
|
12
|
-
});
|
|
13
|
-
export const createReadMultipleFilesTool = async ({ workingDir, allowedDirs, tokenCounter, }) => {
|
|
14
|
-
const allowedDirectory = allowedDirs ?? [workingDir];
|
|
15
|
-
return {
|
|
16
|
-
toolDef: {
|
|
17
|
-
description: "Read the contents of multiple files simultaneously. This is more " +
|
|
18
|
-
"efficient than reading files one by one when you need to analyze " +
|
|
19
|
-
"or compare multiple files. Each file's content is returned with its " +
|
|
20
|
-
"path as a reference. Failed reads for individual files won't stop " +
|
|
21
|
-
"the entire operation. Only works within allowed directories.",
|
|
22
|
-
inputSchema,
|
|
23
|
-
},
|
|
24
|
-
async *execute({ paths }, { toolCallId, abortSignal }) {
|
|
25
|
-
try {
|
|
26
|
-
// Check if execution has been aborted
|
|
27
|
-
if (abortSignal?.aborted) {
|
|
28
|
-
throw new Error("Multiple file reading aborted");
|
|
29
|
-
}
|
|
30
|
-
yield {
|
|
31
|
-
name: ReadMultipleFilesTool.name,
|
|
32
|
-
id: toolCallId,
|
|
33
|
-
event: "tool-init",
|
|
34
|
-
data: `${paths.map((p) => style.cyan(p)).join(", ")}`,
|
|
35
|
-
};
|
|
36
|
-
if (abortSignal?.aborted) {
|
|
37
|
-
throw new Error("Multiple file reading aborted before reading files");
|
|
38
|
-
}
|
|
39
|
-
const results = await Promise.all(paths.map(async (filePath) => {
|
|
40
|
-
if (abortSignal?.aborted) {
|
|
41
|
-
throw new Error("Multiple file reading aborted during file processing");
|
|
42
|
-
}
|
|
43
|
-
const fileResult = await validateAndReadFile(filePath, workingDir, allowedDirectory);
|
|
44
|
-
return fileResult;
|
|
45
|
-
}));
|
|
46
|
-
const processedResults = await Promise.all(results.map(async (result) => {
|
|
47
|
-
if (result.error) {
|
|
48
|
-
return {
|
|
49
|
-
path: result.path,
|
|
50
|
-
content: `${result.path}: Error - ${result.error}`,
|
|
51
|
-
tokenCount: 0,
|
|
52
|
-
error: result.error,
|
|
53
|
-
truncated: false,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
// Apply token limit check to each file
|
|
57
|
-
try {
|
|
58
|
-
const managedResult = await manageTokenLimit(result.content ?? "", tokenCounter, "ReadMultipleFiles", "Use readFile with startLine/lineCount or grepFiles for targeted access");
|
|
59
|
-
return {
|
|
60
|
-
path: result.path,
|
|
61
|
-
content: formatFile(result.path, managedResult.content, "markdown"),
|
|
62
|
-
tokenCount: managedResult.tokenCount,
|
|
63
|
-
error: null,
|
|
64
|
-
exceededLimit: false,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
catch (error) {
|
|
68
|
-
if (error instanceof TokenLimitExceededError) {
|
|
69
|
-
return {
|
|
70
|
-
path: result.path,
|
|
71
|
-
content: error.message,
|
|
72
|
-
tokenCount: 0,
|
|
73
|
-
error: null,
|
|
74
|
-
exceededLimit: true,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
throw error;
|
|
78
|
-
}
|
|
79
|
-
}));
|
|
80
|
-
const formattedResults = processedResults.map((r) => r.content);
|
|
81
|
-
try {
|
|
82
|
-
const finalResult = await manageTokenLimit(formattedResults.join("\n---\n"), tokenCounter, "ReadMultipleFiles", "Reduce number of files or use more specific paths");
|
|
83
|
-
// Aggregate results with detailed breakdown
|
|
84
|
-
let totalTokens = 0;
|
|
85
|
-
let filesReadCount = 0;
|
|
86
|
-
let filesExceededLimitCount = 0;
|
|
87
|
-
let filesErrorCount = 0;
|
|
88
|
-
for (const processedResult of processedResults) {
|
|
89
|
-
if (processedResult.error) {
|
|
90
|
-
filesErrorCount++;
|
|
91
|
-
}
|
|
92
|
-
else if (processedResult.exceededLimit) {
|
|
93
|
-
filesExceededLimitCount++;
|
|
94
|
-
totalTokens += processedResult.tokenCount;
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
filesReadCount++;
|
|
98
|
-
totalTokens += processedResult.tokenCount;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
const parts = [];
|
|
102
|
-
if (filesReadCount > 0) {
|
|
103
|
-
parts.push(`Read ${filesReadCount} files successfully (${totalTokens} total tokens)`);
|
|
104
|
-
}
|
|
105
|
-
if (filesExceededLimitCount > 0) {
|
|
106
|
-
parts.push(`${filesExceededLimitCount} files exceeded token limit`);
|
|
107
|
-
}
|
|
108
|
-
if (filesErrorCount > 0) {
|
|
109
|
-
parts.push(`${filesErrorCount} files could not be read`);
|
|
110
|
-
}
|
|
111
|
-
// Note: If we reach here, finalResult succeeded (no TokenLimitExceededError thrown)
|
|
112
|
-
const completionMessage = `${parts.join(", ")}.`;
|
|
113
|
-
yield {
|
|
114
|
-
name: ReadMultipleFilesTool.name,
|
|
115
|
-
id: toolCallId,
|
|
116
|
-
event: "tool-completion",
|
|
117
|
-
data: completionMessage,
|
|
118
|
-
};
|
|
119
|
-
yield finalResult.content;
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
if (error instanceof TokenLimitExceededError) {
|
|
123
|
-
// Combined output exceeded limit
|
|
124
|
-
const parts = [];
|
|
125
|
-
let totalTokens = 0;
|
|
126
|
-
let filesReadCount = 0;
|
|
127
|
-
let filesExceededLimitCount = 0;
|
|
128
|
-
let filesErrorCount = 0;
|
|
129
|
-
for (const processedResult of processedResults) {
|
|
130
|
-
if (processedResult.error) {
|
|
131
|
-
filesErrorCount++;
|
|
132
|
-
}
|
|
133
|
-
else if (processedResult.exceededLimit) {
|
|
134
|
-
filesExceededLimitCount++;
|
|
135
|
-
totalTokens += processedResult.tokenCount;
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
filesReadCount++;
|
|
139
|
-
totalTokens += processedResult.tokenCount;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (filesReadCount > 0) {
|
|
143
|
-
parts.push(`Read ${filesReadCount} files successfully (${totalTokens} total tokens)`);
|
|
144
|
-
}
|
|
145
|
-
if (filesExceededLimitCount > 0) {
|
|
146
|
-
parts.push(`${filesExceededLimitCount} files exceeded token limit`);
|
|
147
|
-
}
|
|
148
|
-
if (filesErrorCount > 0) {
|
|
149
|
-
parts.push(`${filesErrorCount} files could not be read`);
|
|
150
|
-
}
|
|
151
|
-
parts.push(`Combined output exceeded token limit. ${error.message}`);
|
|
152
|
-
const completionMessage = `${parts.join(", ")}.`;
|
|
153
|
-
yield {
|
|
154
|
-
name: ReadMultipleFilesTool.name,
|
|
155
|
-
event: "tool-error",
|
|
156
|
-
id: toolCallId,
|
|
157
|
-
data: completionMessage,
|
|
158
|
-
};
|
|
159
|
-
yield error.message;
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
throw error;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
catch (error) {
|
|
166
|
-
const errorMsg = error.message;
|
|
167
|
-
yield {
|
|
168
|
-
name: ReadMultipleFilesTool.name,
|
|
169
|
-
id: toolCallId,
|
|
170
|
-
event: "tool-error",
|
|
171
|
-
data: errorMsg,
|
|
172
|
-
};
|
|
173
|
-
yield errorMsg;
|
|
174
|
-
}
|
|
175
|
-
},
|
|
176
|
-
};
|
|
177
|
-
};
|
|
178
|
-
async function validateAndReadFile(filePath, workingDir, allowedDirectory) {
|
|
179
|
-
try {
|
|
180
|
-
const validPath = await validatePath(joinWorkingDir(filePath, workingDir), allowedDirectory);
|
|
181
|
-
const content = await readFile(validPath, "utf-8");
|
|
182
|
-
return {
|
|
183
|
-
path: filePath,
|
|
184
|
-
content,
|
|
185
|
-
error: null,
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
catch (error) {
|
|
189
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
190
|
-
return {
|
|
191
|
-
path: filePath,
|
|
192
|
-
content: null,
|
|
193
|
-
error: errorMessage,
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { ToolCallOptions } from "ai";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import type { TokenCounter } from "../tokens/counter.ts";
|
|
4
|
-
import type { ToolResult } from "./types.ts";
|
|
5
|
-
export declare const WebFetchTool: {
|
|
6
|
-
name: "webFetch";
|
|
7
|
-
};
|
|
8
|
-
export declare const createWebFetchTool: (options: {
|
|
9
|
-
tokenCounter: TokenCounter;
|
|
10
|
-
}) => {
|
|
11
|
-
toolDef: {
|
|
12
|
-
description: string;
|
|
13
|
-
inputSchema: z.ZodObject<{
|
|
14
|
-
url: z.ZodString;
|
|
15
|
-
}, z.core.$strip>;
|
|
16
|
-
};
|
|
17
|
-
execute({ url }: {
|
|
18
|
-
url: string;
|
|
19
|
-
}, { toolCallId, abortSignal }: ToolCallOptions): AsyncGenerator<ToolResult>;
|
|
20
|
-
};
|
|
21
|
-
type ContentType = "text/plain" | "text/html" | "text/markdown" | "application/json" | "application/xml" | "application/pdf" | "image/png" | "image/jpeg" | "image/gif" | "image/webp" | "image/svg+xml" | "audio/mpeg" | "audio/wav" | "video/mp4" | "video/webm" | "application/zip" | "application/octet-stream";
|
|
22
|
-
export type ReadUrlResult = {
|
|
23
|
-
contentType: ContentType;
|
|
24
|
-
data: string;
|
|
25
|
-
};
|
|
26
|
-
export declare function readUrl(url: string, abortSignal?: AbortSignal | undefined): Promise<ReadUrlResult>;
|
|
27
|
-
export declare class HtmlCleaner {
|
|
28
|
-
static new(html: string): HtmlCleaner;
|
|
29
|
-
private html;
|
|
30
|
-
private constructor();
|
|
31
|
-
/**
|
|
32
|
-
* Cleans HTML content by removing unnecessary elements and simplifying structure
|
|
33
|
-
* @param {Object} [options] - Configuration options for cleaning
|
|
34
|
-
* @param {boolean} [options.simplify=true] - Whether to simplify HTML structure by removing redundant elements
|
|
35
|
-
* @param {boolean} [options.empty=true] - Whether to remove empty elements from the HTML
|
|
36
|
-
* @returns {string} Cleaned HTML content with removed whitespace and line breaks
|
|
37
|
-
*/
|
|
38
|
-
clean(options?: {
|
|
39
|
-
simplify?: boolean;
|
|
40
|
-
empty?: boolean;
|
|
41
|
-
}): string;
|
|
42
|
-
/**
|
|
43
|
-
* Removes scripts, styles, and comments from HTML
|
|
44
|
-
*/
|
|
45
|
-
private removeUnnecessaryElements;
|
|
46
|
-
/**
|
|
47
|
-
* Simplifies HTML structure by merging redundant tags
|
|
48
|
-
*/
|
|
49
|
-
private simplifyStructure;
|
|
50
|
-
/**
|
|
51
|
-
* Removes empty elements from HTML
|
|
52
|
-
*/
|
|
53
|
-
private removeEmptyElements;
|
|
54
|
-
}
|
|
55
|
-
export {};
|
|
56
|
-
//# sourceMappingURL=web-fetch.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"web-fetch.d.ts","sourceRoot":"","sources":["../../source/tools/web-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAE1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,YAAY;;CAExB,CAAC;AAMF,eAAO,MAAM,kBAAkB,GAAI,SAAS;IAAE,YAAY,EAAE,YAAY,CAAA;CAAE;;;;;;;qBAQ3D;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,+BACK,eAAe,GAC3C,cAAc,CAAC,UAAU,CAAC;CAmChC,CAAC;AAEF,KAAK,WAAW,GACZ,YAAY,GACZ,WAAW,GACX,eAAe,GACf,kBAAkB,GAClB,iBAAiB,GACjB,iBAAiB,GACjB,WAAW,GACX,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,eAAe,GACf,YAAY,GACZ,WAAW,GACX,WAAW,GACX,YAAY,GACZ,iBAAiB,GACjB,0BAA0B,CAAC;AAE/B,MAAM,MAAM,aAAa,GAAG;IAAE,WAAW,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvE,wBAAsB,OAAO,CAC3B,GAAG,EAAE,MAAM,EACX,WAAW,CAAC,EAAE,WAAW,GAAG,SAAS,GACpC,OAAO,CAAC,aAAa,CAAC,CA6HxB;AAED,qBAAa,WAAW;IACtB,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW;IAIrC,OAAO,CAAC,IAAI,CAAS;IAErB,OAAO;IAIP;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,MAAM;IAuBhE;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAyCjC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAuBzB;;OAEG;IACH,OAAO,CAAC,mBAAmB;CAG5B"}
|
package/dist/tools/web-fetch.js
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import { load } from "cheerio";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { logger } from "../logger.js";
|
|
4
|
-
import style from "../terminal/style.js";
|
|
5
|
-
export const WebFetchTool = {
|
|
6
|
-
name: "webFetch",
|
|
7
|
-
};
|
|
8
|
-
const inputSchema = z.object({
|
|
9
|
-
url: z.string().describe("The URL to fetch content from."),
|
|
10
|
-
});
|
|
11
|
-
export const createWebFetchTool = (options) => {
|
|
12
|
-
return {
|
|
13
|
-
toolDef: {
|
|
14
|
-
description: "Fetches the content of a given URL. It intelligently handles HTML content by attempting to use a specialized service for cleaner extraction, falling back to local cleaning if needed. For non-HTML content (like plain text or markdown), it fetches the raw content directly. IMPORTANT: Does not retrieve binary files.",
|
|
15
|
-
inputSchema,
|
|
16
|
-
},
|
|
17
|
-
async *execute({ url }, { toolCallId, abortSignal }) {
|
|
18
|
-
try {
|
|
19
|
-
yield {
|
|
20
|
-
name: WebFetchTool.name,
|
|
21
|
-
event: "tool-init",
|
|
22
|
-
id: toolCallId,
|
|
23
|
-
data: `${style.cyan(url)}`,
|
|
24
|
-
};
|
|
25
|
-
logger.info(`${style.cyan(url)}`);
|
|
26
|
-
const result = await readUrl(url, abortSignal);
|
|
27
|
-
const urlContent = result.data;
|
|
28
|
-
const tokenCount = options.tokenCounter.count(urlContent);
|
|
29
|
-
yield {
|
|
30
|
-
name: WebFetchTool.name,
|
|
31
|
-
event: "tool-completion",
|
|
32
|
-
id: toolCallId,
|
|
33
|
-
data: `Fetched URL (${tokenCount} tokens)`,
|
|
34
|
-
};
|
|
35
|
-
logger.info(`Successfully read URL: ${url} (${tokenCount} tokens)`);
|
|
36
|
-
yield urlContent;
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
const errorMessage = error.message;
|
|
40
|
-
yield {
|
|
41
|
-
name: WebFetchTool.name,
|
|
42
|
-
event: "tool-error",
|
|
43
|
-
id: toolCallId,
|
|
44
|
-
data: `${style.cyan(url)} ${errorMessage}`,
|
|
45
|
-
};
|
|
46
|
-
logger.error(`Error reading URL ${url}: ${errorMessage}`);
|
|
47
|
-
yield `Failed to read URL: ${errorMessage}`;
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
export async function readUrl(url, abortSignal) {
|
|
53
|
-
let initialResponse;
|
|
54
|
-
try {
|
|
55
|
-
// Initial fetch to check content type and potentially use directly
|
|
56
|
-
logger.debug(`Performing initial fetch for: ${url}`);
|
|
57
|
-
initialResponse = await fetch(url, { signal: abortSignal });
|
|
58
|
-
if (!initialResponse.ok) {
|
|
59
|
-
throw new Error(`HTTP error! status: ${initialResponse.status} ${initialResponse.statusText}`);
|
|
60
|
-
}
|
|
61
|
-
logger.debug(`Initial fetch successful for: ${url}, Status: ${initialResponse.status}`);
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
// If the initial fetch fails entirely, rethrow
|
|
65
|
-
logger.error(`Initial fetch failed for ${url}: ${error}`);
|
|
66
|
-
throw new Error(`Error fetching initial data for ${url}: ${error}`);
|
|
67
|
-
}
|
|
68
|
-
const contentType = initialResponse.headers.get("content-type") ??
|
|
69
|
-
"text/plain";
|
|
70
|
-
logger.debug(`Content-Type for ${url}: ${contentType}`);
|
|
71
|
-
// If content type is HTML, try Jina first
|
|
72
|
-
if (contentType.includes("text/html")) {
|
|
73
|
-
logger.info(`Detected HTML content for ${url}. Attempting Jina AI fetch.`);
|
|
74
|
-
try {
|
|
75
|
-
const apiKey = process.env["JINA_READER_API_KEY"];
|
|
76
|
-
if (!apiKey) {
|
|
77
|
-
logger.warn("JINA_READER_API_KEY not set. Skipping Jina fetch.");
|
|
78
|
-
throw new Error("Jina API key not available"); // Skip to fallback
|
|
79
|
-
}
|
|
80
|
-
const jinaReadUrl = `https://r.jina.ai/${url}`;
|
|
81
|
-
logger.debug(`Fetching with Jina: ${jinaReadUrl}`);
|
|
82
|
-
const jinaResponse = await fetch(jinaReadUrl, {
|
|
83
|
-
method: "GET",
|
|
84
|
-
headers: {
|
|
85
|
-
// biome-ignore lint/style/useNamingConvention: API requirement
|
|
86
|
-
Authorization: `Bearer ${apiKey}`,
|
|
87
|
-
"X-With-Generated-Alt": "true", // Optional: Ask Jina to include image descriptions
|
|
88
|
-
"X-With-Links-Summary": "true", // Optional: Ask Jina for a summary of links
|
|
89
|
-
},
|
|
90
|
-
signal: abortSignal,
|
|
91
|
-
});
|
|
92
|
-
if (jinaResponse.ok) {
|
|
93
|
-
const data = await jinaResponse.text();
|
|
94
|
-
logger.info(`Successfully fetched and processed HTML URL with Jina: ${url}`);
|
|
95
|
-
return {
|
|
96
|
-
contentType,
|
|
97
|
-
data,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
logger.warn(`Jina fetch failed for ${url} with status ${jinaResponse.status}: ${jinaResponse.statusText}. Falling back to direct fetch and clean.`);
|
|
101
|
-
// Fall through to use the initialResponse if Jina fails
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
logger.warn(`Error fetching from Jina for ${url}: ${error.message}. Falling back to direct fetch and clean.`);
|
|
105
|
-
// Fall through to use the initialResponse if Jina fails
|
|
106
|
-
}
|
|
107
|
-
// Fallback for HTML: Use the initial response and clean it
|
|
108
|
-
try {
|
|
109
|
-
logger.warn(`Falling back to direct fetch and cleaning for HTML URL: ${url}`);
|
|
110
|
-
const htmlText = await initialResponse.text();
|
|
111
|
-
logger.debug(`Cleaning HTML content for ${url} (length: ${htmlText.length})`);
|
|
112
|
-
const cleaner = HtmlCleaner.new(htmlText);
|
|
113
|
-
const processedText = cleaner.clean();
|
|
114
|
-
logger.info(`Successfully cleaned HTML content for ${url} (length: ${processedText.length})`);
|
|
115
|
-
return {
|
|
116
|
-
contentType,
|
|
117
|
-
data: processedText,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
catch (cleanError) {
|
|
121
|
-
logger.error(`Error cleaning HTML from fallback fetch for ${url}: ${cleanError}`);
|
|
122
|
-
throw new Error(`Error cleaning HTML from fallback fetch for ${url}: ${cleanError}`);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
// If not HTML, return the text directly from the initial response
|
|
127
|
-
logger.info(`Fetched non-HTML content directly: ${url} (Content-Type: ${contentType})`);
|
|
128
|
-
try {
|
|
129
|
-
if (contentType.startsWith("image/")) {
|
|
130
|
-
const arrayBuffer = await initialResponse.arrayBuffer();
|
|
131
|
-
const base64 = Buffer.from(arrayBuffer).toString("base64");
|
|
132
|
-
const base64Url = `data:${contentType};base64,${base64}`;
|
|
133
|
-
logger.debug(`Returning base64 image data for ${url} (length: ${base64.length})`);
|
|
134
|
-
return {
|
|
135
|
-
contentType,
|
|
136
|
-
data: base64Url,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
const textContent = await initialResponse.text();
|
|
140
|
-
logger.debug(`Returning raw text content for ${url} (length: ${textContent.length})`);
|
|
141
|
-
return {
|
|
142
|
-
contentType,
|
|
143
|
-
data: textContent,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
catch (textError) {
|
|
147
|
-
logger.error(`Error reading response for ${url}: ${textError}`);
|
|
148
|
-
throw new Error(`Error reading response for ${url}: ${textError}`);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
export class HtmlCleaner {
|
|
153
|
-
static new(html) {
|
|
154
|
-
return new HtmlCleaner(html);
|
|
155
|
-
}
|
|
156
|
-
html;
|
|
157
|
-
constructor(html) {
|
|
158
|
-
this.html = html;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Cleans HTML content by removing unnecessary elements and simplifying structure
|
|
162
|
-
* @param {Object} [options] - Configuration options for cleaning
|
|
163
|
-
* @param {boolean} [options.simplify=true] - Whether to simplify HTML structure by removing redundant elements
|
|
164
|
-
* @param {boolean} [options.empty=true] - Whether to remove empty elements from the HTML
|
|
165
|
-
* @returns {string} Cleaned HTML content with removed whitespace and line breaks
|
|
166
|
-
*/
|
|
167
|
-
clean(options) {
|
|
168
|
-
const { simplify = true, empty = true } = options ?? {};
|
|
169
|
-
const $ = load(this.html);
|
|
170
|
-
// Remove scripts, styles, and comments
|
|
171
|
-
this.removeUnnecessaryElements($);
|
|
172
|
-
// Simplify HTML structure
|
|
173
|
-
if (simplify) {
|
|
174
|
-
this.simplifyStructure($);
|
|
175
|
-
}
|
|
176
|
-
// Remove empty elements
|
|
177
|
-
if (empty) {
|
|
178
|
-
this.removeEmptyElements($);
|
|
179
|
-
}
|
|
180
|
-
// Get cleaned HTML
|
|
181
|
-
return $.html()
|
|
182
|
-
.trim()
|
|
183
|
-
.replace(/^\s*[\r\n]/gm, "");
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Removes scripts, styles, and comments from HTML
|
|
187
|
-
*/
|
|
188
|
-
removeUnnecessaryElements($) {
|
|
189
|
-
// Remove all script tags
|
|
190
|
-
$("script").remove();
|
|
191
|
-
// Remove all noscript tags
|
|
192
|
-
$("noscript").remove();
|
|
193
|
-
// Remove all style tags
|
|
194
|
-
$("style").remove();
|
|
195
|
-
// Remove all link tags (external stylesheets)
|
|
196
|
-
$('link[rel="stylesheet"]').remove();
|
|
197
|
-
// Remove all preload link tags
|
|
198
|
-
$('link[rel="preload"]').remove();
|
|
199
|
-
// Remove all link tags
|
|
200
|
-
$("link").remove();
|
|
201
|
-
// Remove all forms
|
|
202
|
-
$("form").remove();
|
|
203
|
-
// Remove comments
|
|
204
|
-
$("*")
|
|
205
|
-
.contents()
|
|
206
|
-
.each((_, element) => {
|
|
207
|
-
if (element.type === "comment") {
|
|
208
|
-
$(element).remove();
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
// Remove all inline styles
|
|
212
|
-
$("[style]").removeAttr("style");
|
|
213
|
-
// Remove all class attributes
|
|
214
|
-
$("[class]").removeAttr("class");
|
|
215
|
-
// Remove all id attributes
|
|
216
|
-
$("[id]").removeAttr("id");
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Simplifies HTML structure by merging redundant tags
|
|
220
|
-
*/
|
|
221
|
-
simplifyStructure($) {
|
|
222
|
-
// Merge nested divs
|
|
223
|
-
$("div div").each((_, element) => {
|
|
224
|
-
const $element = $(element);
|
|
225
|
-
const parent = $element.parent();
|
|
226
|
-
if (parent.children().length === 1 && parent.get(0)?.tagName === "div") {
|
|
227
|
-
$element.unwrap();
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
// Remove redundant spans
|
|
231
|
-
$("span").each((_, element) => {
|
|
232
|
-
const $element = $(element);
|
|
233
|
-
if (!$element.attr() || Object.keys($element.attr() ?? {}).length === 0) {
|
|
234
|
-
const h = $element.html();
|
|
235
|
-
if (h) {
|
|
236
|
-
$element.replaceWith(h);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Removes empty elements from HTML
|
|
243
|
-
*/
|
|
244
|
-
removeEmptyElements($) {
|
|
245
|
-
$(":empty").remove();
|
|
246
|
-
}
|
|
247
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { ToolCallOptions } from "ai";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import type { TokenCounter } from "../tokens/counter.ts";
|
|
4
|
-
import type { ToolResult } from "./types.ts";
|
|
5
|
-
export declare const WebSearchTool: {
|
|
6
|
-
name: "webSearch";
|
|
7
|
-
};
|
|
8
|
-
declare const inputSchema: z.ZodObject<{
|
|
9
|
-
query: z.ZodString;
|
|
10
|
-
}, z.core.$strip>;
|
|
11
|
-
export declare const createWebSearchTool: ({ tokenCounter, }: {
|
|
12
|
-
tokenCounter: TokenCounter;
|
|
13
|
-
}) => {
|
|
14
|
-
toolDef: {
|
|
15
|
-
description: string;
|
|
16
|
-
inputSchema: z.ZodObject<{
|
|
17
|
-
query: z.ZodString;
|
|
18
|
-
}, z.core.$strip>;
|
|
19
|
-
};
|
|
20
|
-
execute: ({ query }: z.infer<typeof inputSchema>, { toolCallId, abortSignal }: ToolCallOptions) => AsyncGenerator<ToolResult>;
|
|
21
|
-
};
|
|
22
|
-
export {};
|
|
23
|
-
//# sourceMappingURL=web-search.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"web-search.d.ts","sourceRoot":"","sources":["../../source/tools/web-search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAE1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAKzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,aAAa;;CAEzB,CAAC;AAEF,QAAA,MAAM,WAAW;;iBAEf,CAAC;AAEH,eAAO,MAAM,mBAAmB,GAAI,mBAEjC;IACD,YAAY,EAAE,YAAY,CAAC;CAC5B;;;;;;;yBAQc,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,+BACT,eAAe,KAC3C,cAAc,CAAC,UAAU,CAAC;CAwE9B,CAAC"}
|
package/dist/tools/web-search.js
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { SafeSearchType, search } from "duck-duck-scrape";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import Exa from "../api/exa/index.js";
|
|
4
|
-
import style from "../terminal/style.js";
|
|
5
|
-
import { manageTokenLimit, TokenLimitExceededError, } from "../tokens/threshold.js";
|
|
6
|
-
export const WebSearchTool = {
|
|
7
|
-
name: "webSearch",
|
|
8
|
-
};
|
|
9
|
-
const inputSchema = z.object({
|
|
10
|
-
query: z.string().describe("The search query."),
|
|
11
|
-
});
|
|
12
|
-
export const createWebSearchTool = ({ tokenCounter, }) => {
|
|
13
|
-
const toolDef = {
|
|
14
|
-
description: "Searches the web and returns match documents with their title, url, and text content. The query should be formulated as a natural language question.",
|
|
15
|
-
inputSchema,
|
|
16
|
-
};
|
|
17
|
-
const execute = async function* ({ query }, { toolCallId, abortSignal }) {
|
|
18
|
-
try {
|
|
19
|
-
// Check if execution has been aborted
|
|
20
|
-
if (abortSignal?.aborted) {
|
|
21
|
-
throw new Error("Web search aborted");
|
|
22
|
-
}
|
|
23
|
-
yield {
|
|
24
|
-
name: WebSearchTool.name,
|
|
25
|
-
event: "tool-init",
|
|
26
|
-
id: toolCallId,
|
|
27
|
-
data: `${style.cyan(query)}`,
|
|
28
|
-
};
|
|
29
|
-
if (abortSignal?.aborted) {
|
|
30
|
-
throw new Error("Web search aborted before search execution");
|
|
31
|
-
}
|
|
32
|
-
const result = await performSearch(query, abortSignal);
|
|
33
|
-
const sources = result.results.map((source) => `## ${source.title}\nURL: ${source.url}\n\n${source.text}`);
|
|
34
|
-
const resultText = `# Search Results:\n\n${sources.join("\n\n")}`;
|
|
35
|
-
try {
|
|
36
|
-
const searchResult = await manageTokenLimit(resultText, tokenCounter, "WebSearch", "Use more specific search queries or reduce number of results");
|
|
37
|
-
yield {
|
|
38
|
-
name: WebSearchTool.name,
|
|
39
|
-
event: "tool-completion",
|
|
40
|
-
id: toolCallId,
|
|
41
|
-
data: `Found ${result.results.length} results (${searchResult.tokenCount} tokens)`,
|
|
42
|
-
};
|
|
43
|
-
yield searchResult.content;
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
if (error instanceof TokenLimitExceededError) {
|
|
47
|
-
yield {
|
|
48
|
-
name: WebSearchTool.name,
|
|
49
|
-
event: "tool-error",
|
|
50
|
-
id: toolCallId,
|
|
51
|
-
data: error.message,
|
|
52
|
-
};
|
|
53
|
-
yield error.message;
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
throw error;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
61
|
-
yield {
|
|
62
|
-
name: WebSearchTool.name,
|
|
63
|
-
event: "tool-error",
|
|
64
|
-
id: toolCallId,
|
|
65
|
-
data: errorMessage,
|
|
66
|
-
};
|
|
67
|
-
yield errorMessage;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
return {
|
|
71
|
-
toolDef,
|
|
72
|
-
execute,
|
|
73
|
-
// No ask method needed for read-only tool
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
async function performSearch(query, abortSignal) {
|
|
77
|
-
// Check if EXA API key is available
|
|
78
|
-
const hasExaApiKey = process.env["EXA_API_KEY"] && process.env["EXA_API_KEY"].trim() !== "";
|
|
79
|
-
if (hasExaApiKey) {
|
|
80
|
-
// Use Exa search
|
|
81
|
-
try {
|
|
82
|
-
if (abortSignal?.aborted) {
|
|
83
|
-
throw new Error("Web search aborted before Exa search");
|
|
84
|
-
}
|
|
85
|
-
const exa = new Exa(process.env["EXA_API_KEY"]);
|
|
86
|
-
// Create a promise that races with the abort signal
|
|
87
|
-
const searchPromise = exa.searchAndContents(query, {
|
|
88
|
-
numResults: 5,
|
|
89
|
-
text: true,
|
|
90
|
-
});
|
|
91
|
-
const result = await Promise.race([
|
|
92
|
-
searchPromise,
|
|
93
|
-
new Promise((_, reject) => {
|
|
94
|
-
if (abortSignal) {
|
|
95
|
-
abortSignal.addEventListener("abort", () => {
|
|
96
|
-
reject(new Error("Web search aborted during Exa search"));
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}),
|
|
100
|
-
]);
|
|
101
|
-
return result;
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
// If Exa fails, fall back to duck duck scrape
|
|
105
|
-
console.info("Exa search failed, falling back to DuckDuckGo:", error);
|
|
106
|
-
return await searchWithDuckDuckGo(query, abortSignal);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
// Use DuckDuckGo search as fallback
|
|
111
|
-
console.info("EXA_API_KEY not set, using DuckDuckGo search");
|
|
112
|
-
return await searchWithDuckDuckGo(query, abortSignal);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
async function searchWithDuckDuckGo(query, abortSignal) {
|
|
116
|
-
try {
|
|
117
|
-
if (abortSignal?.aborted) {
|
|
118
|
-
throw new Error("Web search aborted before DuckDuckGo search");
|
|
119
|
-
}
|
|
120
|
-
// Create a promise that races with the abort signal
|
|
121
|
-
const searchPromise = search(query, {
|
|
122
|
-
safeSearch: SafeSearchType.MODERATE,
|
|
123
|
-
});
|
|
124
|
-
const searchResults = await Promise.race([
|
|
125
|
-
searchPromise,
|
|
126
|
-
new Promise((_, reject) => {
|
|
127
|
-
if (abortSignal) {
|
|
128
|
-
abortSignal.addEventListener("abort", () => {
|
|
129
|
-
reject(new Error("Web search aborted during DuckDuckGo search"));
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}),
|
|
133
|
-
]);
|
|
134
|
-
// Transform duck-duck-scrape results to match Exa format
|
|
135
|
-
// Take only first 5 results to match Exa behavior
|
|
136
|
-
const results = searchResults.results
|
|
137
|
-
.slice(0, 5)
|
|
138
|
-
.map((result) => ({
|
|
139
|
-
title: result.title,
|
|
140
|
-
url: result.url,
|
|
141
|
-
text: result.description || "",
|
|
142
|
-
}));
|
|
143
|
-
return { results };
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
throw new Error(`Failed to perform web search: ${error}`);
|
|
147
|
-
}
|
|
148
|
-
}
|