indusagi-coding-agent 0.1.22 → 0.1.24
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/CHANGELOG.md +72 -11
- package/README.md +2 -36
- package/dist/cli/args.d.ts +117 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +231 -64
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/config-selector.d.ts +58 -2
- package/dist/cli/config-selector.d.ts.map +1 -1
- package/dist/cli/config-selector.js +130 -12
- package/dist/cli/config-selector.js.map +1 -1
- package/dist/cli/file-processor.d.ts +70 -2
- package/dist/cli/file-processor.d.ts.map +1 -1
- package/dist/cli/file-processor.js +240 -15
- package/dist/cli/file-processor.js.map +1 -1
- package/dist/cli/list-models.d.ts +63 -3
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +202 -27
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/login-handler.d.ts +82 -8
- package/dist/cli/login-handler.d.ts.map +1 -1
- package/dist/cli/login-handler.js +410 -77
- package/dist/cli/login-handler.js.map +1 -1
- package/dist/cli/session-picker.d.ts +74 -2
- package/dist/cli/session-picker.d.ts.map +1 -1
- package/dist/cli/session-picker.js +236 -12
- package/dist/cli/session-picker.js.map +1 -1
- package/dist/core/agent-session.d.ts +214 -9
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +214 -9
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bash-executor.d.ts +302 -12
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +302 -12
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/diagnostics.d.ts +191 -0
- package/dist/core/diagnostics.d.ts.map +1 -1
- package/dist/core/diagnostics.js +142 -0
- package/dist/core/diagnostics.js.map +1 -1
- package/dist/core/event-bus.d.ts +146 -0
- package/dist/core/event-bus.d.ts.map +1 -1
- package/dist/core/event-bus.js +93 -0
- package/dist/core/event-bus.js.map +1 -1
- package/dist/core/export-html/ansi-to-html.d.ts +4 -0
- package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
- package/dist/core/export-html/ansi-to-html.js +4 -0
- package/dist/core/export-html/ansi-to-html.js.map +1 -1
- package/dist/core/export-html/index.d.ts +128 -0
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +128 -0
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/tool-renderer.d.ts +4 -0
- package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
- package/dist/core/export-html/tool-renderer.js +4 -0
- package/dist/core/export-html/tool-renderer.js.map +1 -1
- package/dist/core/keybindings.d.ts +142 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +142 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/model-registry.d.ts +98 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +98 -1
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts +99 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +99 -1
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +0 -2
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-manager.d.ts +127 -0
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +125 -0
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/skills.js.map +1 -1
- package/dist/core/subagents.js.map +1 -1
- package/dist/core/tools/bash.d.ts +391 -11
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +269 -2
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit.d.ts +284 -6
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +238 -0
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/find.d.ts +169 -5
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +136 -0
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts +285 -5
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +247 -0
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +0 -18
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +1 -23
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts +6 -0
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +6 -0
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts +308 -7
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +231 -0
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/webfetch.d.ts +118 -3
- package/dist/core/tools/webfetch.d.ts.map +1 -1
- package/dist/core/tools/webfetch.js +118 -3
- package/dist/core/tools/webfetch.js.map +1 -1
- package/dist/core/tools/websearch.d.ts +130 -3
- package/dist/core/tools/websearch.d.ts.map +1 -1
- package/dist/core/tools/websearch.js +130 -3
- package/dist/core/tools/websearch.js.map +1 -1
- package/dist/core/tools/write.d.ts +251 -5
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +210 -0
- package/dist/core/tools/write.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts +164 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +164 -1
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts +297 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +297 -1
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +251 -1
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/user-message.d.ts +186 -1
- package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message.js +186 -1
- package/dist/modes/interactive/components/user-message.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1567 -13
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1567 -13
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts +422 -0
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +422 -0
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/print-mode.d.ts +538 -5
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +538 -5
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +921 -8
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +921 -8
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +802 -9
- package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-mode.js +802 -9
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +356 -3
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js +356 -3
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/modes/shared.d.ts +386 -0
- package/dist/modes/shared.d.ts.map +1 -0
- package/dist/modes/shared.js +543 -0
- package/dist/modes/shared.js.map +1 -0
- package/dist/utils/array.d.ts +389 -0
- package/dist/utils/array.d.ts.map +1 -0
- package/dist/utils/array.js +585 -0
- package/dist/utils/array.js.map +1 -0
- package/dist/utils/color-formatter.d.ts +318 -0
- package/dist/utils/color-formatter.d.ts.map +1 -0
- package/dist/utils/color-formatter.js +442 -0
- package/dist/utils/color-formatter.js.map +1 -0
- package/dist/utils/data-transformer.d.ts +326 -0
- package/dist/utils/data-transformer.d.ts.map +1 -0
- package/dist/utils/data-transformer.js +512 -0
- package/dist/utils/data-transformer.js.map +1 -0
- package/dist/utils/date-formatter.d.ts +281 -0
- package/dist/utils/date-formatter.d.ts.map +1 -0
- package/dist/utils/date-formatter.js +503 -0
- package/dist/utils/date-formatter.js.map +1 -0
- package/dist/utils/error-handler.d.ts +541 -0
- package/dist/utils/error-handler.d.ts.map +1 -0
- package/dist/utils/error-handler.js +726 -0
- package/dist/utils/error-handler.js.map +1 -0
- package/dist/utils/file-operations.d.ts +297 -0
- package/dist/utils/file-operations.d.ts.map +1 -0
- package/dist/utils/file-operations.js +505 -0
- package/dist/utils/file-operations.js.map +1 -0
- package/dist/utils/frontmatter.d.ts +268 -6
- package/dist/utils/frontmatter.d.ts.map +1 -1
- package/dist/utils/frontmatter.js +500 -21
- package/dist/utils/frontmatter.js.map +1 -1
- package/dist/utils/json-formatter.d.ts +259 -0
- package/dist/utils/json-formatter.d.ts.map +1 -0
- package/dist/utils/json-formatter.js +517 -0
- package/dist/utils/json-formatter.js.map +1 -0
- package/dist/utils/logger.d.ts +176 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +346 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/markdown-formatter.d.ts +211 -0
- package/dist/utils/markdown-formatter.d.ts.map +1 -0
- package/dist/utils/markdown-formatter.js +482 -0
- package/dist/utils/markdown-formatter.js.map +1 -0
- package/dist/utils/path-validator.d.ts +603 -0
- package/dist/utils/path-validator.d.ts.map +1 -0
- package/dist/utils/path-validator.js +870 -0
- package/dist/utils/path-validator.js.map +1 -0
- package/dist/utils/string-formatter.d.ts +609 -0
- package/dist/utils/string-formatter.d.ts.map +1 -0
- package/dist/utils/string-formatter.js +806 -0
- package/dist/utils/string-formatter.js.map +1 -0
- package/dist/utils/type-guards.d.ts +629 -0
- package/dist/utils/type-guards.d.ts.map +1 -0
- package/dist/utils/type-guards.js +662 -0
- package/dist/utils/type-guards.js.map +1 -0
- package/docs/COMPLETE-GUIDE.md +300 -0
- package/docs/MODES-ARCHITECTURE.md +565 -0
- package/docs/PRINT-MODE-GUIDE.md +456 -0
- package/docs/README.md +1 -2
- package/docs/RPC-GUIDE.md +705 -0
- package/docs/UTILS-IMPLEMENTATION-SUMMARY.md +647 -0
- package/docs/UTILS-MODULE-OVERVIEW.md +1480 -0
- package/docs/UTILS-QA-CHECKLIST.md +1061 -0
- package/docs/UTILS-USAGE-GUIDE.md +1419 -0
- package/package.json +3 -3
|
@@ -1,8 +1,135 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Web Search Tool
|
|
2
|
+
* Web Search Tool - Real-time search using Exa AI API
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* @module core/tools/websearch
|
|
5
|
+
* @description
|
|
6
|
+
* Implements the web search tool for the agent. Performs real-time web searches with:
|
|
7
|
+
* - Query-based information retrieval
|
|
8
|
+
* - Configurable result count
|
|
9
|
+
* - Search type options (fast, deep, auto)
|
|
10
|
+
* - Live crawling options
|
|
11
|
+
* - LLM-optimized context
|
|
12
|
+
* - Exa AI API integration
|
|
13
|
+
*
|
|
14
|
+
* ## Tool Interface
|
|
15
|
+
*
|
|
16
|
+
* **Input Parameters:**
|
|
17
|
+
* - `query` (required): Search query
|
|
18
|
+
* - `numResults` (optional): Number of results (1-10; default: 8)
|
|
19
|
+
* - `livecrawl` (optional): Crawling mode (fallback, preferred; default: fallback)
|
|
20
|
+
* - `type` (optional): Search type (auto, fast, deep; default: auto)
|
|
21
|
+
* - `contextMaxCharacters` (optional): Max context chars (default: 10000)
|
|
22
|
+
*
|
|
23
|
+
* **Output:**
|
|
24
|
+
* - Search results with snippets
|
|
25
|
+
* - URLs and relevance info
|
|
26
|
+
* - LLM-optimized context string
|
|
27
|
+
* - Error if API fails or disabled
|
|
28
|
+
*
|
|
29
|
+
* **Error Behavior:**
|
|
30
|
+
* - No API key: Tool error "Web search not available (no API key)"
|
|
31
|
+
* - Network error: Tool error "Search failed: ..."
|
|
32
|
+
* - API error: Tool error "Search API error: ..."
|
|
33
|
+
* - Timeout: Tool error "Search request timed out"
|
|
34
|
+
*
|
|
35
|
+
* ## Usage in Agent
|
|
36
|
+
*
|
|
37
|
+
* The agent uses this tool to:
|
|
38
|
+
* - Search for current information
|
|
39
|
+
* - Find recent news and events
|
|
40
|
+
* - Look up facts and statistics
|
|
41
|
+
* - Research new topics
|
|
42
|
+
* - Answer questions about current events
|
|
43
|
+
*
|
|
44
|
+
* ## Features
|
|
45
|
+
*
|
|
46
|
+
* **Search Types:**
|
|
47
|
+
* - **auto**: Balanced search (recommended)
|
|
48
|
+
* - **fast**: Quick results, less comprehensive
|
|
49
|
+
* - **deep**: Comprehensive search, more thorough
|
|
50
|
+
*
|
|
51
|
+
* **Live Crawling:**
|
|
52
|
+
* - **fallback**: Use cached content, crawl if needed
|
|
53
|
+
* - **preferred**: Prioritize live crawling for fresh content
|
|
54
|
+
*
|
|
55
|
+
* **LLM Optimization:**
|
|
56
|
+
* - Context formatted for language models
|
|
57
|
+
* - Configurable max characters
|
|
58
|
+
* - Snippets and relevance info included
|
|
59
|
+
* - Structured for easy parsing
|
|
60
|
+
*
|
|
61
|
+
* **Result Limiting:**
|
|
62
|
+
* - Min 1, max 10 results
|
|
63
|
+
* - Default 8 results
|
|
64
|
+
* - Configurable per query
|
|
65
|
+
*
|
|
66
|
+
* ## Security
|
|
67
|
+
*
|
|
68
|
+
* **API Authentication:**
|
|
69
|
+
* - Requires Exa AI API key
|
|
70
|
+
* - Key from environment variable or options
|
|
71
|
+
* - No key = tool not available
|
|
72
|
+
*
|
|
73
|
+
* **Query Validation:**
|
|
74
|
+
* - Non-empty query required
|
|
75
|
+
* - No injection attacks (sent to API as-is)
|
|
76
|
+
* - Safe to include user input
|
|
77
|
+
*
|
|
78
|
+
* **Rate Limiting:**
|
|
79
|
+
* - API enforces rate limits
|
|
80
|
+
* - Errors returned if exceeded
|
|
81
|
+
* - Exponential backoff recommended
|
|
82
|
+
*
|
|
83
|
+
* ## Customization
|
|
84
|
+
*
|
|
85
|
+
* **Custom Search Provider:**
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const customTool = createWebSearchTool({
|
|
88
|
+
* operations: {
|
|
89
|
+
* search: async (request, signal) => {
|
|
90
|
+
* // Custom search implementation
|
|
91
|
+
* return JSON.stringify(results);
|
|
92
|
+
* },
|
|
93
|
+
* },
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* ## Examples
|
|
98
|
+
*
|
|
99
|
+
* ### Basic search
|
|
100
|
+
* ```typescript
|
|
101
|
+
* // Agent calls: websearch {query: "latest news about AI"}
|
|
102
|
+
* // Returns: Top 8 news results
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* ### Deep search with more results
|
|
106
|
+
* ```typescript
|
|
107
|
+
* // Agent calls: websearch {
|
|
108
|
+
* // query: "TypeScript generics best practices",
|
|
109
|
+
* // numResults: 10,
|
|
110
|
+
* // type: "deep"
|
|
111
|
+
* // }
|
|
112
|
+
* // Returns: 10 comprehensive results
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* ### Fast search with live crawling
|
|
116
|
+
* ```typescript
|
|
117
|
+
* // Agent calls: websearch {
|
|
118
|
+
* // query: "stock market today",
|
|
119
|
+
* // type: "fast",
|
|
120
|
+
* // livecrawl: "preferred"
|
|
121
|
+
* // }
|
|
122
|
+
* // Returns: Quick results with live data
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* ## Attribution
|
|
126
|
+
*
|
|
127
|
+
* Based on: indusagi-agent websearch tool
|
|
128
|
+
* Modifications:
|
|
129
|
+
* - Added search type options
|
|
130
|
+
* - Added live crawl configuration
|
|
131
|
+
* - Added context optimization
|
|
132
|
+
* - Improved error handling
|
|
6
133
|
*/
|
|
7
134
|
import type { AgentTool } from "indusagi/agent";
|
|
8
135
|
declare const webSearchSchema: import("@sinclair/typebox").TObject<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websearch.d.ts","sourceRoot":"","sources":["../../../src/core/tools/websearch.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"websearch.d.ts","sourceRoot":"","sources":["../../../src/core/tools/websearch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAYhD,QAAA,MAAM,eAAe;;;;;;EA6BnB,CAAC;AAEH,MAAM,WAAW,oBAAoB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC;IACrC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAChC,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,oBAAoB;IACpC,iEAAiE;IACjE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IACnC;;OAEG;IACH,MAAM,EAAE,CAAC,OAAO,EAAE,gBAAgB,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7E;AAED,UAAU,gBAAgB;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE;YACV,KAAK,EAAE,MAAM,CAAC;YACd,UAAU,CAAC,EAAE,MAAM,CAAC;YACpB,SAAS,CAAC,EAAE,UAAU,GAAG,WAAW,CAAC;YACrC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;YAChC,oBAAoB,CAAC,EAAE,MAAM,CAAC;SAC9B,CAAC;KACF,CAAC;CACF;AAqED,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,SAAS,CAAC,OAAO,eAAe,CAAC,CAoErG;AAED,8BAA8B;AAC9B,eAAO,MAAM,aAAa;;;;;;QAAwB,CAAC"}
|
|
@@ -1,8 +1,135 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Web Search Tool
|
|
2
|
+
* Web Search Tool - Real-time search using Exa AI API
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* @module core/tools/websearch
|
|
5
|
+
* @description
|
|
6
|
+
* Implements the web search tool for the agent. Performs real-time web searches with:
|
|
7
|
+
* - Query-based information retrieval
|
|
8
|
+
* - Configurable result count
|
|
9
|
+
* - Search type options (fast, deep, auto)
|
|
10
|
+
* - Live crawling options
|
|
11
|
+
* - LLM-optimized context
|
|
12
|
+
* - Exa AI API integration
|
|
13
|
+
*
|
|
14
|
+
* ## Tool Interface
|
|
15
|
+
*
|
|
16
|
+
* **Input Parameters:**
|
|
17
|
+
* - `query` (required): Search query
|
|
18
|
+
* - `numResults` (optional): Number of results (1-10; default: 8)
|
|
19
|
+
* - `livecrawl` (optional): Crawling mode (fallback, preferred; default: fallback)
|
|
20
|
+
* - `type` (optional): Search type (auto, fast, deep; default: auto)
|
|
21
|
+
* - `contextMaxCharacters` (optional): Max context chars (default: 10000)
|
|
22
|
+
*
|
|
23
|
+
* **Output:**
|
|
24
|
+
* - Search results with snippets
|
|
25
|
+
* - URLs and relevance info
|
|
26
|
+
* - LLM-optimized context string
|
|
27
|
+
* - Error if API fails or disabled
|
|
28
|
+
*
|
|
29
|
+
* **Error Behavior:**
|
|
30
|
+
* - No API key: Tool error "Web search not available (no API key)"
|
|
31
|
+
* - Network error: Tool error "Search failed: ..."
|
|
32
|
+
* - API error: Tool error "Search API error: ..."
|
|
33
|
+
* - Timeout: Tool error "Search request timed out"
|
|
34
|
+
*
|
|
35
|
+
* ## Usage in Agent
|
|
36
|
+
*
|
|
37
|
+
* The agent uses this tool to:
|
|
38
|
+
* - Search for current information
|
|
39
|
+
* - Find recent news and events
|
|
40
|
+
* - Look up facts and statistics
|
|
41
|
+
* - Research new topics
|
|
42
|
+
* - Answer questions about current events
|
|
43
|
+
*
|
|
44
|
+
* ## Features
|
|
45
|
+
*
|
|
46
|
+
* **Search Types:**
|
|
47
|
+
* - **auto**: Balanced search (recommended)
|
|
48
|
+
* - **fast**: Quick results, less comprehensive
|
|
49
|
+
* - **deep**: Comprehensive search, more thorough
|
|
50
|
+
*
|
|
51
|
+
* **Live Crawling:**
|
|
52
|
+
* - **fallback**: Use cached content, crawl if needed
|
|
53
|
+
* - **preferred**: Prioritize live crawling for fresh content
|
|
54
|
+
*
|
|
55
|
+
* **LLM Optimization:**
|
|
56
|
+
* - Context formatted for language models
|
|
57
|
+
* - Configurable max characters
|
|
58
|
+
* - Snippets and relevance info included
|
|
59
|
+
* - Structured for easy parsing
|
|
60
|
+
*
|
|
61
|
+
* **Result Limiting:**
|
|
62
|
+
* - Min 1, max 10 results
|
|
63
|
+
* - Default 8 results
|
|
64
|
+
* - Configurable per query
|
|
65
|
+
*
|
|
66
|
+
* ## Security
|
|
67
|
+
*
|
|
68
|
+
* **API Authentication:**
|
|
69
|
+
* - Requires Exa AI API key
|
|
70
|
+
* - Key from environment variable or options
|
|
71
|
+
* - No key = tool not available
|
|
72
|
+
*
|
|
73
|
+
* **Query Validation:**
|
|
74
|
+
* - Non-empty query required
|
|
75
|
+
* - No injection attacks (sent to API as-is)
|
|
76
|
+
* - Safe to include user input
|
|
77
|
+
*
|
|
78
|
+
* **Rate Limiting:**
|
|
79
|
+
* - API enforces rate limits
|
|
80
|
+
* - Errors returned if exceeded
|
|
81
|
+
* - Exponential backoff recommended
|
|
82
|
+
*
|
|
83
|
+
* ## Customization
|
|
84
|
+
*
|
|
85
|
+
* **Custom Search Provider:**
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const customTool = createWebSearchTool({
|
|
88
|
+
* operations: {
|
|
89
|
+
* search: async (request, signal) => {
|
|
90
|
+
* // Custom search implementation
|
|
91
|
+
* return JSON.stringify(results);
|
|
92
|
+
* },
|
|
93
|
+
* },
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* ## Examples
|
|
98
|
+
*
|
|
99
|
+
* ### Basic search
|
|
100
|
+
* ```typescript
|
|
101
|
+
* // Agent calls: websearch {query: "latest news about AI"}
|
|
102
|
+
* // Returns: Top 8 news results
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* ### Deep search with more results
|
|
106
|
+
* ```typescript
|
|
107
|
+
* // Agent calls: websearch {
|
|
108
|
+
* // query: "TypeScript generics best practices",
|
|
109
|
+
* // numResults: 10,
|
|
110
|
+
* // type: "deep"
|
|
111
|
+
* // }
|
|
112
|
+
* // Returns: 10 comprehensive results
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* ### Fast search with live crawling
|
|
116
|
+
* ```typescript
|
|
117
|
+
* // Agent calls: websearch {
|
|
118
|
+
* // query: "stock market today",
|
|
119
|
+
* // type: "fast",
|
|
120
|
+
* // livecrawl: "preferred"
|
|
121
|
+
* // }
|
|
122
|
+
* // Returns: Quick results with live data
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* ## Attribution
|
|
126
|
+
*
|
|
127
|
+
* Based on: indusagi-agent websearch tool
|
|
128
|
+
* Modifications:
|
|
129
|
+
* - Added search type options
|
|
130
|
+
* - Added live crawl configuration
|
|
131
|
+
* - Added context optimization
|
|
132
|
+
* - Improved error handling
|
|
6
133
|
*/
|
|
7
134
|
import { Type } from "@sinclair/typebox";
|
|
8
135
|
const API_CONFIG = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websearch.js","sourceRoot":"","sources":["../../../src/core/tools/websearch.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"websearch.js","sourceRoot":"","sources":["../../../src/core/tools/websearch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoIG;AAIH,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,MAAM,UAAU,GAAG;IAClB,QAAQ,EAAE,oBAAoB;IAC9B,SAAS,EAAE;QACV,MAAM,EAAE,MAAM;KACd;IACD,mBAAmB,EAAE,CAAC;CACb,CAAC;AAEX,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC;IACnC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC;IACvD,UAAU,EAAE,IAAI,CAAC,QAAQ,CACxB,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,0DAA0D,EAAE,CAAC,CACxF;IACD,SAAS,EAAE,IAAI,CAAC,QAAQ,CACvB,IAAI,CAAC,KAAK,CAAC;QACV,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;QACxB,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;KACzB,EAAE;QACF,WAAW,EACV,sJAAsJ;KACvJ,CAAC,CACF;IACD,IAAI,EAAE,IAAI,CAAC,QAAQ,CAClB,IAAI,CAAC,KAA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,EAAE,CAAC"}
|
|
@@ -1,24 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write Tool - Create and overwrite files with automatic directory creation
|
|
3
|
+
*
|
|
4
|
+
* @module core/tools/write
|
|
5
|
+
* @description
|
|
6
|
+
* Implements the write tool for the agent. Creates or overwrites files with:
|
|
7
|
+
* - Automatic parent directory creation
|
|
8
|
+
* - Path validation and resolution
|
|
9
|
+
* - Remote execution support (SSH, containers)
|
|
10
|
+
* - UTF-8 encoding
|
|
11
|
+
*
|
|
12
|
+
* Based on file writing patterns from Anthropic's Claude API.
|
|
13
|
+
* Refactored for agent file system safety.
|
|
14
|
+
* - Atomic writes (file written as a whole unit)
|
|
15
|
+
*
|
|
16
|
+
* ## Tool Interface
|
|
17
|
+
*
|
|
18
|
+
* **Input Parameters:**
|
|
19
|
+
* - `path` (required): File path (relative or absolute)
|
|
20
|
+
* - `content` (required): File content as string
|
|
21
|
+
*
|
|
22
|
+
* **Output:**
|
|
23
|
+
* - Success: "File written" message
|
|
24
|
+
* - Errors: Path invalid, permission denied, disk full, etc.
|
|
25
|
+
*
|
|
26
|
+
* **Error Behavior:**
|
|
27
|
+
* - Invalid path → Tool error "Path outside working directory"
|
|
28
|
+
* - Permission denied → Tool error "EACCES: permission denied"
|
|
29
|
+
* - Disk full → Tool error "ENOSPC: no space left on device"
|
|
30
|
+
* - Other errors → Tool error with message
|
|
31
|
+
*
|
|
32
|
+
* ## Usage in Agent
|
|
33
|
+
*
|
|
34
|
+
* The agent uses this tool to:
|
|
35
|
+
* - Create new files (code, config, docs)
|
|
36
|
+
* - Overwrite existing files
|
|
37
|
+
* - Write generated content
|
|
38
|
+
* - Create boilerplate and scaffolding
|
|
39
|
+
* - Generate test fixtures
|
|
40
|
+
*
|
|
41
|
+
* Overwrites existing files completely (no merge).
|
|
42
|
+
*
|
|
43
|
+
* ## Features
|
|
44
|
+
*
|
|
45
|
+
* **Directory Creation:**
|
|
46
|
+
* - Automatically creates parent directories
|
|
47
|
+
* - Recursively creates full path
|
|
48
|
+
* - No errors if dirs already exist
|
|
49
|
+
*
|
|
50
|
+
* **Path Safety:**
|
|
51
|
+
* - All paths resolved relative to cwd
|
|
52
|
+
* - No path traversal (no ../../../etc/passwd)
|
|
53
|
+
* - Validates accessible location
|
|
54
|
+
*
|
|
55
|
+
* **Writing:**
|
|
56
|
+
* - UTF-8 encoding (standard for code)
|
|
57
|
+
* - Atomic write (no partial files)
|
|
58
|
+
* - Overwrites completely (not merge)
|
|
59
|
+
*
|
|
60
|
+
* **Permissions:**
|
|
61
|
+
* - Respects system umask
|
|
62
|
+
* - Files created with standard permissions
|
|
63
|
+
* - Errors on permission issues
|
|
64
|
+
*
|
|
65
|
+
* ## Security
|
|
66
|
+
*
|
|
67
|
+
* **Path validation:**
|
|
68
|
+
* - All paths resolved relative to cwd
|
|
69
|
+
* - No absolute paths outside cwd
|
|
70
|
+
* - Directory traversal prevented
|
|
71
|
+
*
|
|
72
|
+
* **Write safety:**
|
|
73
|
+
* - Cannot execute written files
|
|
74
|
+
* - Files written as text, not executable
|
|
75
|
+
* - Permission issues caught and reported
|
|
76
|
+
*
|
|
77
|
+
* **Disk safety:**
|
|
78
|
+
* - System handles disk full errors
|
|
79
|
+
* - Inode limit errors caught
|
|
80
|
+
* - No intentional DoS vectors
|
|
81
|
+
*
|
|
82
|
+
* ## Customization
|
|
83
|
+
*
|
|
84
|
+
* **Remote Execution (SSH):**
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const sshTool = createWriteTool(cwd, {
|
|
87
|
+
* operations: {
|
|
88
|
+
* writeFile: (path, content) => sshExec(`cat > ${path} << 'EOF'\n${content}\nEOF`),
|
|
89
|
+
* mkdir: (dir) => sshExec(`mkdir -p ${dir}`),
|
|
90
|
+
* },
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* ## Examples
|
|
95
|
+
*
|
|
96
|
+
* ### Create new file
|
|
97
|
+
* ```typescript
|
|
98
|
+
* // Agent calls: write {path: "hello.txt", content: "Hello, world!"}
|
|
99
|
+
* // Result: File created with content
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* ### Create in subdirectory
|
|
103
|
+
* ```typescript
|
|
104
|
+
* // Agent calls: write {path: "src/main.ts", content: "..."}
|
|
105
|
+
* // Result: src/ and src/main.ts created automatically
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* ### Overwrite existing file
|
|
109
|
+
* ```typescript
|
|
110
|
+
* // Agent calls: write {path: "existing.js", content: "..."}
|
|
111
|
+
* // Result: File completely replaced with new content
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* ## Attribution
|
|
115
|
+
*
|
|
116
|
+
* Based on: indusagi-agent write tool
|
|
117
|
+
* Modifications:
|
|
118
|
+
* - Added custom operations interface
|
|
119
|
+
* - Improved error messages
|
|
120
|
+
* - Added directory creation details
|
|
121
|
+
*/
|
|
1
122
|
import type { AgentTool } from "indusagi/agent";
|
|
123
|
+
/**
|
|
124
|
+
* JSON Schema for write tool parameters
|
|
125
|
+
* @internal
|
|
126
|
+
*/
|
|
2
127
|
declare const writeSchema: import("@sinclair/typebox").TObject<{
|
|
3
128
|
path: import("@sinclair/typebox").TString;
|
|
4
129
|
content: import("@sinclair/typebox").TString;
|
|
5
130
|
}>;
|
|
6
131
|
/**
|
|
7
|
-
* Pluggable
|
|
8
|
-
*
|
|
132
|
+
* Pluggable interface for file writing operations
|
|
133
|
+
*
|
|
134
|
+
* Allows custom implementations for:
|
|
135
|
+
* - Remote file systems (SSH, cloud storage)
|
|
136
|
+
* - Virtual file systems (in-memory, testing)
|
|
137
|
+
* - Custom permission models
|
|
138
|
+
* - Monitoring and auditing
|
|
139
|
+
*
|
|
140
|
+
* Implementations must respect working directory boundaries.
|
|
9
141
|
*/
|
|
10
142
|
export interface WriteOperations {
|
|
11
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* Write content to a file (overwrite if exists)
|
|
145
|
+
*
|
|
146
|
+
* Must handle:
|
|
147
|
+
* - Creating file if not exists
|
|
148
|
+
* - Overwriting if exists
|
|
149
|
+
* - UTF-8 encoding
|
|
150
|
+
*
|
|
151
|
+
* @param absolutePath - Full path to file (already validated)
|
|
152
|
+
* @param content - File content as string
|
|
153
|
+
* @throws Error on write failures
|
|
154
|
+
*/
|
|
12
155
|
writeFile: (absolutePath: string, content: string) => Promise<void>;
|
|
13
|
-
/**
|
|
156
|
+
/**
|
|
157
|
+
* Create directory (recursively)
|
|
158
|
+
*
|
|
159
|
+
* Must handle:
|
|
160
|
+
* - Creating directory if not exists
|
|
161
|
+
* - Creating parent directories
|
|
162
|
+
* - Not erroring if already exists
|
|
163
|
+
*
|
|
164
|
+
* @param dir - Directory path (already validated)
|
|
165
|
+
* @throws Error on creation failures
|
|
166
|
+
*/
|
|
14
167
|
mkdir: (dir: string) => Promise<void>;
|
|
15
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Configuration options for the write tool
|
|
171
|
+
*/
|
|
16
172
|
export interface WriteToolOptions {
|
|
17
|
-
/**
|
|
173
|
+
/**
|
|
174
|
+
* Custom operations for file writing
|
|
175
|
+
*
|
|
176
|
+
* Default: Local filesystem operations
|
|
177
|
+
* Custom: SSH, cloud storage, testing mocks
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* const tool = createWriteTool(cwd, {
|
|
182
|
+
* operations: {
|
|
183
|
+
* writeFile: (path, content) => sshExec(`cat > ${path}`, content),
|
|
184
|
+
* mkdir: (dir) => sshExec(`mkdir -p ${dir}`),
|
|
185
|
+
* },
|
|
186
|
+
* });
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
18
189
|
operations?: WriteOperations;
|
|
19
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Create a write tool with custom configuration
|
|
193
|
+
*
|
|
194
|
+
* Creates an AgentTool that can write files with:
|
|
195
|
+
* - Automatic parent directory creation
|
|
196
|
+
* - Path validation and resolution
|
|
197
|
+
* - Remote execution support
|
|
198
|
+
* - Proper error handling
|
|
199
|
+
*
|
|
200
|
+
* **Tool Behavior:**
|
|
201
|
+
* - Resolves paths relative to working directory
|
|
202
|
+
* - Prevents path traversal (no ../../../etc/passwd)
|
|
203
|
+
* - Creates parent directories automatically
|
|
204
|
+
* - Overwrites files completely (not merge/append)
|
|
205
|
+
* - Returns success message
|
|
206
|
+
*
|
|
207
|
+
* **Tool Parameters:**
|
|
208
|
+
* - `path` (required): File to write (relative or absolute)
|
|
209
|
+
* - `content` (required): File content as string
|
|
210
|
+
*
|
|
211
|
+
* **Tool Output:**
|
|
212
|
+
* - Success: "File written to <path>"
|
|
213
|
+
* - Errors: Tool error with message
|
|
214
|
+
*
|
|
215
|
+
* **Error Handling:**
|
|
216
|
+
* - Invalid path: Tool error "Path outside working directory"
|
|
217
|
+
* - Permission denied: Tool error "EACCES: permission denied"
|
|
218
|
+
* - Disk full: Tool error "ENOSPC: no space left on device"
|
|
219
|
+
* - Other errors: Tool error with message
|
|
220
|
+
*
|
|
221
|
+
* @param cwd - Working directory for relative path resolution
|
|
222
|
+
* - All relative paths resolved from this directory
|
|
223
|
+
* - Prevents directory traversal attacks
|
|
224
|
+
* - Can be overridden per execution
|
|
225
|
+
*
|
|
226
|
+
* @param options - Optional configuration
|
|
227
|
+
* - operations: Custom file writing backend (default: filesystem)
|
|
228
|
+
*
|
|
229
|
+
* @returns AgentTool instance ready to use
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* // Basic tool
|
|
234
|
+
* const tool = createWriteTool(process.cwd());
|
|
235
|
+
*
|
|
236
|
+
* // With remote backend (SSH)
|
|
237
|
+
* const remoteTool = createWriteTool(cwd, {
|
|
238
|
+
* operations: sshOperations,
|
|
239
|
+
* });
|
|
240
|
+
* ```
|
|
241
|
+
*
|
|
242
|
+
* @see WriteToolOptions for detailed configuration
|
|
243
|
+
* @see WriteOperations for custom backend interface
|
|
244
|
+
*/
|
|
20
245
|
export declare function createWriteTool(cwd: string, options?: WriteToolOptions): AgentTool<typeof writeSchema>;
|
|
21
246
|
/** Default write tool using process.cwd() - for backwards compatibility */
|
|
247
|
+
/**
|
|
248
|
+
* Default write tool instance
|
|
249
|
+
*
|
|
250
|
+
* Pre-created write tool using current process working directory.
|
|
251
|
+
* Supports automatic directory creation and file overwriting.
|
|
252
|
+
*
|
|
253
|
+
* Equivalent to:
|
|
254
|
+
* ```typescript
|
|
255
|
+
* const writeTool = createWriteTool(process.cwd());
|
|
256
|
+
* ```
|
|
257
|
+
*
|
|
258
|
+
* For custom configuration or remote backends, use createWriteTool() directly.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* import { writeTool } from "./tools/write.js";
|
|
263
|
+
* const agent = new Agent({ tools: [writeTool] });
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* @see createWriteTool for custom configuration
|
|
267
|
+
*/
|
|
22
268
|
export declare const writeTool: AgentTool<import("@sinclair/typebox").TObject<{
|
|
23
269
|
path: import("@sinclair/typebox").TString;
|
|
24
270
|
content: import("@sinclair/typebox").TString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/core/tools/write.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwHG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAUhD;;;GAGG;AACH,QAAA,MAAM,WAAW;;;EAGf,CAAC;AAEH;;;;;;;;;;GAUG;AACH,MAAM,WAAW,eAAe;IAC/B;;;;;;;;;;;OAWG;IACH,SAAS,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpE;;;;;;;;;;OAUG;IACH,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAWD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAChC;;;;;;;;;;;;;;;OAeG;IACH,UAAU,CAAC,EAAE,eAAe,CAAC;CAC7B;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC,OAAO,WAAW,CAAC,CAgFtG;AAED,2EAA2E;AAC3E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,SAAS;;;QAAiC,CAAC"}
|