indusagi 0.12.6 → 0.12.7
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/dist/agent/index.d.ts +1 -0
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +2 -0
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/tools/bash.d.ts +45 -0
- package/dist/agent/tools/bash.d.ts.map +1 -0
- package/dist/agent/tools/bash.js +227 -0
- package/dist/agent/tools/bash.js.map +1 -0
- package/dist/agent/tools/edit-diff.d.ts +63 -0
- package/dist/agent/tools/edit-diff.d.ts.map +1 -0
- package/dist/agent/tools/edit-diff.js +241 -0
- package/dist/agent/tools/edit-diff.js.map +1 -0
- package/dist/agent/tools/edit.d.ts +37 -0
- package/dist/agent/tools/edit.d.ts.map +1 -0
- package/dist/agent/tools/edit.js +146 -0
- package/dist/agent/tools/edit.js.map +1 -0
- package/dist/agent/tools/find.d.ts +24 -0
- package/dist/agent/tools/find.d.ts.map +1 -0
- package/dist/agent/tools/find.js +132 -0
- package/dist/agent/tools/find.js.map +1 -0
- package/dist/agent/tools/grep.d.ts +43 -0
- package/dist/agent/tools/grep.d.ts.map +1 -0
- package/dist/agent/tools/grep.js +178 -0
- package/dist/agent/tools/grep.js.map +1 -0
- package/dist/agent/tools/index.d.ts +158 -0
- package/dist/agent/tools/index.d.ts.map +1 -0
- package/dist/agent/tools/index.js +128 -0
- package/dist/agent/tools/index.js.map +1 -0
- package/dist/agent/tools/ls.d.ts +38 -0
- package/dist/agent/tools/ls.d.ts.map +1 -0
- package/dist/agent/tools/ls.js +118 -0
- package/dist/agent/tools/ls.js.map +1 -0
- package/dist/agent/tools/path-utils.d.ts +8 -0
- package/dist/agent/tools/path-utils.d.ts.map +1 -0
- package/dist/agent/tools/path-utils.js +53 -0
- package/dist/agent/tools/path-utils.js.map +1 -0
- package/dist/agent/tools/read.d.ts +37 -0
- package/dist/agent/tools/read.d.ts.map +1 -0
- package/dist/agent/tools/read.js +168 -0
- package/dist/agent/tools/read.js.map +1 -0
- package/dist/agent/tools/task.d.ts +26 -0
- package/dist/agent/tools/task.d.ts.map +1 -0
- package/dist/agent/tools/task.js +30 -0
- package/dist/agent/tools/task.js.map +1 -0
- package/dist/agent/tools/todo-store.d.ts +20 -0
- package/dist/agent/tools/todo-store.d.ts.map +1 -0
- package/dist/agent/tools/todo-store.js +24 -0
- package/dist/agent/tools/todo-store.js.map +1 -0
- package/dist/agent/tools/todo.d.ts +26 -0
- package/dist/agent/tools/todo.d.ts.map +1 -0
- package/dist/agent/tools/todo.js +52 -0
- package/dist/agent/tools/todo.js.map +1 -0
- package/dist/agent/tools/truncate.d.ts +70 -0
- package/dist/agent/tools/truncate.d.ts.map +1 -0
- package/dist/agent/tools/truncate.js +205 -0
- package/dist/agent/tools/truncate.js.map +1 -0
- package/dist/agent/tools/utils/hook-runner.d.ts +9 -0
- package/dist/agent/tools/utils/hook-runner.d.ts.map +1 -0
- package/dist/agent/tools/utils/hook-runner.js +14 -0
- package/dist/agent/tools/utils/hook-runner.js.map +1 -0
- package/dist/agent/tools/utils/image-resize.d.ts +32 -0
- package/dist/agent/tools/utils/image-resize.d.ts.map +1 -0
- package/dist/agent/tools/utils/image-resize.js +42 -0
- package/dist/agent/tools/utils/image-resize.js.map +1 -0
- package/dist/agent/tools/utils/mime.d.ts +10 -0
- package/dist/agent/tools/utils/mime.d.ts.map +1 -0
- package/dist/agent/tools/utils/mime.js +48 -0
- package/dist/agent/tools/utils/mime.js.map +1 -0
- package/dist/agent/tools/utils/shell.d.ts +30 -0
- package/dist/agent/tools/utils/shell.d.ts.map +1 -0
- package/dist/agent/tools/utils/shell.js +137 -0
- package/dist/agent/tools/utils/shell.js.map +1 -0
- package/dist/agent/tools/webfetch.d.ts +34 -0
- package/dist/agent/tools/webfetch.d.ts.map +1 -0
- package/dist/agent/tools/webfetch.js +244 -0
- package/dist/agent/tools/webfetch.js.map +1 -0
- package/dist/agent/tools/websearch.d.ts +29 -0
- package/dist/agent/tools/websearch.d.ts.map +1 -0
- package/dist/agent/tools/websearch.js +69 -0
- package/dist/agent/tools/websearch.js.map +1 -0
- package/dist/agent/tools/write.d.ts +27 -0
- package/dist/agent/tools/write.d.ts.map +1 -0
- package/dist/agent/tools/write.js +78 -0
- package/dist/agent/tools/write.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Fetch Tool
|
|
3
|
+
*
|
|
4
|
+
* Fetches content from a specified URL.
|
|
5
|
+
* Supports text, markdown, and HTML format options.
|
|
6
|
+
*/
|
|
7
|
+
import { Type } from "@sinclair/typebox";
|
|
8
|
+
const MAX_RESPONSE_SIZE = 5 * 1024 * 1024; // 5MB
|
|
9
|
+
const DEFAULT_TIMEOUT = 30 * 1000; // 30 seconds
|
|
10
|
+
const webFetchSchema = Type.Object({
|
|
11
|
+
url: Type.String({ description: "The URL to fetch content from (must start with http:// or https://)" }),
|
|
12
|
+
format: Type.Optional(Type.Union([Type.Literal("text"), Type.Literal("markdown"), Type.Literal("html")], {
|
|
13
|
+
description: "The format to return the content in (text, markdown, or html). Defaults to markdown.",
|
|
14
|
+
})),
|
|
15
|
+
timeout: Type.Optional(Type.Number({ description: "Optional timeout in seconds (max 120). Default: 30" })),
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Simple HTML to text converter - strips HTML tags
|
|
19
|
+
*/
|
|
20
|
+
async function htmlToTextSimple(html) {
|
|
21
|
+
// Remove script and style elements
|
|
22
|
+
let text = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "");
|
|
23
|
+
text = text.replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, "");
|
|
24
|
+
text = text.replace(/<noscript\b[^<]*(?:(?!<\/noscript>)<[^<]*)*<\/noscript>/gi, "");
|
|
25
|
+
// Decode HTML entities
|
|
26
|
+
text = text.replace(/&/g, "&");
|
|
27
|
+
text = text.replace(/</g, "<");
|
|
28
|
+
text = text.replace(/>/g, ">");
|
|
29
|
+
text = text.replace(/"/g, '"');
|
|
30
|
+
text = text.replace(/'/g, "'");
|
|
31
|
+
text = text.replace(/ /g, " ");
|
|
32
|
+
// Remove all remaining HTML tags
|
|
33
|
+
text = text.replace(/<[^>]+>/g, " ");
|
|
34
|
+
// Normalize whitespace
|
|
35
|
+
text = text.replace(/\s+/g, " ");
|
|
36
|
+
text = text.trim();
|
|
37
|
+
return text;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Simple HTML to markdown converter - basic conversion only
|
|
41
|
+
*/
|
|
42
|
+
function htmlToMarkdownSimple(html) {
|
|
43
|
+
let markdown = html;
|
|
44
|
+
// Remove script, style, noscript, meta, link elements
|
|
45
|
+
markdown = markdown.replace(/<(script|style|noscript|meta|link)\b[^<]*(?:(?!<\/\1>)<[^<]*)*<\/\1>/gi, "");
|
|
46
|
+
// Headers
|
|
47
|
+
markdown = markdown.replace(/<h1\b[^>]*>(.*?)<\/h1>/gi, "# $1\n");
|
|
48
|
+
markdown = markdown.replace(/<h2\b[^>]*>(.*?)<\/h2>/gi, "## $1\n");
|
|
49
|
+
markdown = markdown.replace(/<h3\b[^>]*>(.*?)<\/h3>/gi, "### $1\n");
|
|
50
|
+
markdown = markdown.replace(/<h4\b[^>]*>(.*?)<\/h4>/gi, "#### $1\n");
|
|
51
|
+
markdown = markdown.replace(/<h5\b[^>]*>(.*?)<\/h5>/gi, "##### $1\n");
|
|
52
|
+
markdown = markdown.replace(/<h6\b[^>]*>(.*?)<\/h6>/gi, "###### $1\n");
|
|
53
|
+
// Bold and italic
|
|
54
|
+
markdown = markdown.replace(/<strong\b[^>]*>(.*?)<\/strong>/gi, "**$1**");
|
|
55
|
+
markdown = markdown.replace(/<b\b[^>]*>(.*?)<\/b>/gi, "**$1**");
|
|
56
|
+
markdown = markdown.replace(/<em\b[^>]*>(.*?)<\/em>/gi, "*$1*");
|
|
57
|
+
markdown = markdown.replace(/<i\b[^>]*>(.*?)<\/i>/gi, "*$1*");
|
|
58
|
+
// Links
|
|
59
|
+
markdown = markdown.replace(/<a\b[^>]*href="([^"]*)"[^>]*>(.*?)<\/a>/gi, "[$2]($1)");
|
|
60
|
+
// Images
|
|
61
|
+
markdown = markdown.replace(/<img\b[^>]*src="([^"]*)"[^>]*alt="([^"]*)"[^>]*>/gi, "");
|
|
62
|
+
markdown = markdown.replace(/<img\b[^>]*src="([^"]*)"[^>]*>/gi, "");
|
|
63
|
+
// Code blocks
|
|
64
|
+
markdown = markdown.replace(/<pre\b[^>]*><code\b[^>]*>(.*?)<\/code><\/pre>/gis, "```\n$1\n```");
|
|
65
|
+
markdown = markdown.replace(/<code\b[^>]*>(.*?)<\/code>/gi, "`$1`");
|
|
66
|
+
// Lists (basic)
|
|
67
|
+
markdown = markdown.replace(/<ul\b[^>]*>/gi, "");
|
|
68
|
+
markdown = markdown.replace(/<\/ul>/gi, "");
|
|
69
|
+
markdown = markdown.replace(/<ol\b[^>]*>/gi, "");
|
|
70
|
+
markdown = markdown.replace(/<\/ol>/gi, "");
|
|
71
|
+
markdown = markdown.replace(/<li\b[^>]*>/gi, "- ");
|
|
72
|
+
markdown = markdown.replace(/<\/li>/gi, "\n");
|
|
73
|
+
// Blockquotes
|
|
74
|
+
markdown = markdown.replace(/<blockquote\b[^>]*>(.*?)<\/blockquote>/gis, (match, content) => {
|
|
75
|
+
return content.split("\n").map((line) => `> ${line}`).join("\n");
|
|
76
|
+
});
|
|
77
|
+
// Horizontal rule
|
|
78
|
+
markdown = markdown.replace(/<hr\b[^>]*>/gi, "\n---\n");
|
|
79
|
+
// Paragraphs
|
|
80
|
+
markdown = markdown.replace(/<p\b[^>]*>/gi, "");
|
|
81
|
+
markdown = markdown.replace(/<\/p>/gi, "\n\n");
|
|
82
|
+
// Line breaks
|
|
83
|
+
markdown = markdown.replace(/<br\b[^>]*>/gi, "\n");
|
|
84
|
+
// Remove all remaining tags
|
|
85
|
+
markdown = markdown.replace(/<[^>]+>/g, "");
|
|
86
|
+
// Normalize whitespace
|
|
87
|
+
markdown = markdown.replace(/\n{3,}/g, "\n\n");
|
|
88
|
+
markdown = markdown.replace(/[ \t]+/g, " ");
|
|
89
|
+
markdown = markdown.trim();
|
|
90
|
+
return markdown;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Default fetch with timeout support
|
|
94
|
+
*/
|
|
95
|
+
async function fetchWithTimeout(url, options = {}, signal) {
|
|
96
|
+
const timeout = options.timeout || DEFAULT_TIMEOUT;
|
|
97
|
+
// Create an abort controller for timeout
|
|
98
|
+
const timeoutController = new AbortController();
|
|
99
|
+
const timeoutId = setTimeout(() => timeoutController.abort(), timeout);
|
|
100
|
+
// If an external signal is provided, abort timeout controller when it aborts
|
|
101
|
+
if (signal) {
|
|
102
|
+
if (signal.aborted) {
|
|
103
|
+
clearTimeout(timeoutId);
|
|
104
|
+
throw new Error("Request aborted by user");
|
|
105
|
+
}
|
|
106
|
+
signal.addEventListener("abort", () => {
|
|
107
|
+
clearTimeout(timeoutId);
|
|
108
|
+
}, { once: true });
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const response = await fetch(url, {
|
|
112
|
+
...options,
|
|
113
|
+
signal: timeoutController.signal,
|
|
114
|
+
});
|
|
115
|
+
clearTimeout(timeoutId);
|
|
116
|
+
return response;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
clearTimeout(timeoutId);
|
|
120
|
+
if (error.name === "AbortError") {
|
|
121
|
+
if (signal?.aborted) {
|
|
122
|
+
throw new Error("Request aborted by user");
|
|
123
|
+
}
|
|
124
|
+
throw new Error(`Request timed out after ${timeout / 1000} seconds`);
|
|
125
|
+
}
|
|
126
|
+
throw error;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
export function createWebFetchTool(options) {
|
|
130
|
+
const maxResponseSize = options?.maxResponseSize || MAX_RESPONSE_SIZE;
|
|
131
|
+
const defaultTimeout = options?.defaultTimeout || DEFAULT_TIMEOUT;
|
|
132
|
+
return {
|
|
133
|
+
name: "webfetch",
|
|
134
|
+
label: "webfetch",
|
|
135
|
+
description: "Fetches content from a specified URL. Takes a URL and optional format as input. Fetches URL content, converts to requested format (markdown by default). Returns content in the specified format. Use this tool when you need to retrieve and analyze web content. The URL must be a fully-formed valid URL starting with http:// or https://. Format options: 'markdown' (default), 'text', or 'html'. This tool is read-only and does not modify any files.",
|
|
136
|
+
parameters: webFetchSchema,
|
|
137
|
+
execute: async (_toolCallId, params, signal) => {
|
|
138
|
+
// Check if already aborted
|
|
139
|
+
if (signal?.aborted) {
|
|
140
|
+
throw new Error("Web fetch aborted");
|
|
141
|
+
}
|
|
142
|
+
// Validate URL
|
|
143
|
+
if (!params.url.startsWith("http://") && !params.url.startsWith("https://")) {
|
|
144
|
+
throw new Error("URL must start with http:// or https://");
|
|
145
|
+
}
|
|
146
|
+
// Calculate timeout
|
|
147
|
+
const timeout = Math.min((params.timeout ?? defaultTimeout / 1000) * 1000, 120000);
|
|
148
|
+
// Build Accept header based on requested format
|
|
149
|
+
let acceptHeader = "*/*";
|
|
150
|
+
switch (params.format) {
|
|
151
|
+
case "markdown":
|
|
152
|
+
acceptHeader =
|
|
153
|
+
"text/markdown;q=1.0, text/x-markdown;q=0.9, text/plain;q=0.8, text/html;q=0.7, */*;q=0.1";
|
|
154
|
+
break;
|
|
155
|
+
case "text":
|
|
156
|
+
acceptHeader = "text/plain;q=1.0, text/markdown;q=0.9, text/html;q=0.8, */*;q=0.1";
|
|
157
|
+
break;
|
|
158
|
+
case "html":
|
|
159
|
+
acceptHeader =
|
|
160
|
+
"text/html;q=1.0, application/xhtml+xml;q=0.9, text/plain;q=0.8, text/markdown;q=0.7, */*;q=0.1";
|
|
161
|
+
break;
|
|
162
|
+
default:
|
|
163
|
+
acceptHeader =
|
|
164
|
+
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8";
|
|
165
|
+
}
|
|
166
|
+
const headers = {
|
|
167
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36",
|
|
168
|
+
Accept: acceptHeader,
|
|
169
|
+
"Accept-Language": "en-US,en;q=0.9",
|
|
170
|
+
};
|
|
171
|
+
// Fetch URL
|
|
172
|
+
const response = await fetchWithTimeout(params.url, { ...headers, timeout }, signal);
|
|
173
|
+
if (!response.ok) {
|
|
174
|
+
throw new Error(`Request failed with status code: ${response.status}`);
|
|
175
|
+
}
|
|
176
|
+
// Check content length
|
|
177
|
+
const contentLength = response.headers.get("content-length");
|
|
178
|
+
if (contentLength && parseInt(contentLength) > maxResponseSize) {
|
|
179
|
+
throw new Error(`Response too large (exceeds ${(maxResponseSize / 1024 / 1024).toFixed(0)}MB limit)`);
|
|
180
|
+
}
|
|
181
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
182
|
+
const fetchedBytes = arrayBuffer.byteLength;
|
|
183
|
+
// Get content type
|
|
184
|
+
const contentType = response.headers.get("content-type") || "";
|
|
185
|
+
const mime = contentType.split(";")[0]?.trim().toLowerCase() || "";
|
|
186
|
+
// Check if response is an image
|
|
187
|
+
const isImage = mime.startsWith("image/") &&
|
|
188
|
+
mime !== "image/svg+xml" &&
|
|
189
|
+
mime !== "image/vnd.fastbidsheet";
|
|
190
|
+
// Build details
|
|
191
|
+
const details = {
|
|
192
|
+
url: params.url,
|
|
193
|
+
format: params.format,
|
|
194
|
+
timeout: params.timeout,
|
|
195
|
+
contentType: mime,
|
|
196
|
+
fetchedBytes,
|
|
197
|
+
};
|
|
198
|
+
// Return content based on type
|
|
199
|
+
if (isImage) {
|
|
200
|
+
const base64Content = Buffer.from(arrayBuffer).toString("base64");
|
|
201
|
+
return {
|
|
202
|
+
content: [
|
|
203
|
+
{ type: "text", text: "Image fetched successfully" },
|
|
204
|
+
{ type: "image", data: base64Content, mimeType: mime },
|
|
205
|
+
],
|
|
206
|
+
details,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
const content = Buffer.from(arrayBuffer).toString("utf-8");
|
|
210
|
+
let output;
|
|
211
|
+
// Handle content based on requested format and actual content type
|
|
212
|
+
const format = params.format || "markdown";
|
|
213
|
+
switch (format) {
|
|
214
|
+
case "markdown":
|
|
215
|
+
if (contentType.includes("text/html")) {
|
|
216
|
+
const markdown = htmlToMarkdownSimple(content);
|
|
217
|
+
output = [{ type: "text", text: markdown }];
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
output = [{ type: "text", text: content }];
|
|
221
|
+
}
|
|
222
|
+
break;
|
|
223
|
+
case "text":
|
|
224
|
+
if (contentType.includes("text/html")) {
|
|
225
|
+
const text = await htmlToTextSimple(content);
|
|
226
|
+
output = [{ type: "text", text: text }];
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
output = [{ type: "text", text: content }];
|
|
230
|
+
}
|
|
231
|
+
break;
|
|
232
|
+
case "html":
|
|
233
|
+
output = [{ type: "text", text: content }];
|
|
234
|
+
break;
|
|
235
|
+
default:
|
|
236
|
+
output = [{ type: "text", text: content }];
|
|
237
|
+
}
|
|
238
|
+
return { content: output, details };
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/** Default web fetch tool */
|
|
243
|
+
export const webFetchTool = createWebFetchTool();
|
|
244
|
+
//# sourceMappingURL=webfetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webfetch.js","sourceRoot":"","sources":["../../../src/agent/tools/webfetch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,MAAM,iBAAiB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,MAAM;AACjD,MAAM,eAAe,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;AAEhD,MAAM,cAAc,GAAG,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Y,GAAG,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Search Tool
|
|
3
|
+
*
|
|
4
|
+
* Performs real-time web searches using Exa AI API.
|
|
5
|
+
* Provides up-to-date information for current events and recent data.
|
|
6
|
+
*/
|
|
7
|
+
import type { AgentTool } from "../types.js";
|
|
8
|
+
declare const webSearchSchema: import("@sinclair/typebox").TObject<{
|
|
9
|
+
query: import("@sinclair/typebox").TString;
|
|
10
|
+
numResults: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
11
|
+
}>;
|
|
12
|
+
export interface WebSearchToolDetails {
|
|
13
|
+
query: string;
|
|
14
|
+
numResults?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface WebSearchToolOptions {
|
|
17
|
+
/** Custom API base URL (for testing or alternative endpoints) */
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
/** API key for Exa AI (if required) */
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function createWebSearchTool(options?: WebSearchToolOptions): AgentTool<typeof webSearchSchema>;
|
|
23
|
+
/** Default web search tool */
|
|
24
|
+
export declare const webSearchTool: AgentTool<import("@sinclair/typebox").TObject<{
|
|
25
|
+
query: import("@sinclair/typebox").TString;
|
|
26
|
+
numResults: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
27
|
+
}>, any>;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=websearch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websearch.d.ts","sourceRoot":"","sources":["../../../src/agent/tools/websearch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAI7C,QAAA,MAAM,eAAe;;;EAKnB,CAAC;AAEH,MAAM,WAAW,oBAAoB;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACpC,iEAAiE;IACjE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAeD,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,oBAAoB,GAAG,SAAS,CAAC,OAAO,eAAe,CAAC,CAqDrG;AAED,8BAA8B;AAC9B,eAAO,MAAM,aAAa;;;QAAwB,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Search Tool
|
|
3
|
+
*
|
|
4
|
+
* Performs real-time web searches using Exa AI API.
|
|
5
|
+
* Provides up-to-date information for current events and recent data.
|
|
6
|
+
*/
|
|
7
|
+
import { Type } from "@sinclair/typebox";
|
|
8
|
+
const webSearchSchema = Type.Object({
|
|
9
|
+
query: Type.String({ description: "Web search query" }),
|
|
10
|
+
numResults: Type.Optional(Type.Number({ description: "Number of search results to return (default: 8, max: 10)" })),
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Default web search implementation
|
|
14
|
+
*/
|
|
15
|
+
async function defaultWebSearch(query, numResults, signal) {
|
|
16
|
+
// Note: This is a simplified implementation. The full version would use the Exa AI API.
|
|
17
|
+
// For now, return a placeholder message.
|
|
18
|
+
return `Web search for: "${query}"\n\nNote: Full web search functionality requires Exa AI API configuration.`;
|
|
19
|
+
}
|
|
20
|
+
export function createWebSearchTool(options) {
|
|
21
|
+
return {
|
|
22
|
+
name: "websearch",
|
|
23
|
+
label: "websearch",
|
|
24
|
+
description: "Search the web using Exa AI - performs real-time web searches and can scrape content from specific URLs. Provides up-to-date information for current events and recent data. Use this tool for accessing information beyond knowledge cutoff. The current year is 2026. You MUST use this year when searching for recent information or current events (e.g., search for 'AI news 2026', NOT 'AI news 2025').",
|
|
25
|
+
parameters: webSearchSchema,
|
|
26
|
+
execute: async (_toolCallId, { query, numResults }, signal) => {
|
|
27
|
+
// Check if already aborted
|
|
28
|
+
if (signal?.aborted) {
|
|
29
|
+
throw new Error("Web search aborted");
|
|
30
|
+
}
|
|
31
|
+
let resultText;
|
|
32
|
+
try {
|
|
33
|
+
resultText = await defaultWebSearch(query, numResults, signal);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error.name === "AbortError") {
|
|
37
|
+
throw new Error("Web search request timed out or was aborted");
|
|
38
|
+
}
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
// Build output
|
|
42
|
+
let content;
|
|
43
|
+
if (!resultText || resultText.trim() === "") {
|
|
44
|
+
content = [
|
|
45
|
+
{
|
|
46
|
+
type: "text",
|
|
47
|
+
text: "No search results found. Please try a different query.",
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
content = [
|
|
53
|
+
{
|
|
54
|
+
type: "text",
|
|
55
|
+
text: resultText,
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
const details = {
|
|
60
|
+
query,
|
|
61
|
+
numResults,
|
|
62
|
+
};
|
|
63
|
+
return { content, details };
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** Default web search tool */
|
|
68
|
+
export const webSearchTool = createWebSearchTool();
|
|
69
|
+
//# sourceMappingURL=websearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websearch.js","sourceRoot":"","sources":["../../../src/agent/tools/websearch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,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,M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AU;qBAChB;iBACD,CAAC;YACH,CAAC;YAED,MAAM,OAAO,GAAyB;gBACrC,KAAK;gBACL,UAAU;aACV,CAAC;YAEF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;QAC7B,CAAC;KACD,CAAC;AACH,CAAC;AAED,8BAA8B;AAC9B,MAAM,CAAC,MAAM,aAAa,GAAG,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AgentTool } from "../types.js";
|
|
2
|
+
declare const writeSchema: import("@sinclair/typebox").TObject<{
|
|
3
|
+
path: import("@sinclair/typebox").TString;
|
|
4
|
+
content: import("@sinclair/typebox").TString;
|
|
5
|
+
}>;
|
|
6
|
+
/**
|
|
7
|
+
* Pluggable operations for the write tool.
|
|
8
|
+
* Override these to delegate file writing to remote systems (e.g., SSH).
|
|
9
|
+
*/
|
|
10
|
+
export interface WriteOperations {
|
|
11
|
+
/** Write content to a file */
|
|
12
|
+
writeFile: (absolutePath: string, content: string) => Promise<void>;
|
|
13
|
+
/** Create directory (recursively) */
|
|
14
|
+
mkdir: (dir: string) => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export interface WriteToolOptions {
|
|
17
|
+
/** Custom operations for file writing. Default: local filesystem */
|
|
18
|
+
operations?: WriteOperations;
|
|
19
|
+
}
|
|
20
|
+
export declare function createWriteTool(cwd: string, options?: WriteToolOptions): AgentTool<typeof writeSchema>;
|
|
21
|
+
/** Default write tool using process.cwd() - for backwards compatibility */
|
|
22
|
+
export declare const writeTool: AgentTool<import("@sinclair/typebox").TObject<{
|
|
23
|
+
path: import("@sinclair/typebox").TString;
|
|
24
|
+
content: import("@sinclair/typebox").TString;
|
|
25
|
+
}>, any>;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=write.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/agent/tools/write.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAM7C,QAAA,MAAM,WAAW;;;EAGf,CAAC;AAEH;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B,8BAA8B;IAC9B,SAAS,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,qCAAqC;IACrC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAOD,MAAM,WAAW,gBAAgB;IAChC,oEAAoE;IACpE,UAAU,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAC,OAAO,WAAW,CAAC,CAgFtG;AAED,2EAA2E;AAC3E,eAAO,MAAM,SAAS;;;QAAiC,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import { mkdir as fsMkdir, writeFile as fsWriteFile } from "fs/promises";
|
|
3
|
+
import { dirname } from "path";
|
|
4
|
+
import { resolveToCwd } from "./path-utils.js";
|
|
5
|
+
const writeSchema = Type.Object({
|
|
6
|
+
path: Type.String({ description: "Path to the file to write (relative or absolute)" }),
|
|
7
|
+
content: Type.String({ description: "Content to write to the file" }),
|
|
8
|
+
});
|
|
9
|
+
const defaultWriteOperations = {
|
|
10
|
+
writeFile: (path, content) => fsWriteFile(path, content, "utf-8"),
|
|
11
|
+
mkdir: (dir) => fsMkdir(dir, { recursive: true }).then(() => { }),
|
|
12
|
+
};
|
|
13
|
+
export function createWriteTool(cwd, options) {
|
|
14
|
+
const ops = options?.operations ?? defaultWriteOperations;
|
|
15
|
+
return {
|
|
16
|
+
name: "write",
|
|
17
|
+
label: "write",
|
|
18
|
+
description: "Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.",
|
|
19
|
+
parameters: writeSchema,
|
|
20
|
+
execute: async (_toolCallId, { path, content }, signal) => {
|
|
21
|
+
const absolutePath = resolveToCwd(path, cwd);
|
|
22
|
+
const dir = dirname(absolutePath);
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
// Check if already aborted
|
|
25
|
+
if (signal?.aborted) {
|
|
26
|
+
reject(new Error("Operation aborted"));
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let aborted = false;
|
|
30
|
+
// Set up abort handler
|
|
31
|
+
const onAbort = () => {
|
|
32
|
+
aborted = true;
|
|
33
|
+
reject(new Error("Operation aborted"));
|
|
34
|
+
};
|
|
35
|
+
if (signal) {
|
|
36
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
37
|
+
}
|
|
38
|
+
// Perform the write operation
|
|
39
|
+
(async () => {
|
|
40
|
+
try {
|
|
41
|
+
// Create parent directories if needed
|
|
42
|
+
await ops.mkdir(dir);
|
|
43
|
+
// Check if aborted before writing
|
|
44
|
+
if (aborted) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// Write the file
|
|
48
|
+
await ops.writeFile(absolutePath, content);
|
|
49
|
+
// Check if aborted after writing
|
|
50
|
+
if (aborted) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
// Clean up abort handler
|
|
54
|
+
if (signal) {
|
|
55
|
+
signal.removeEventListener("abort", onAbort);
|
|
56
|
+
}
|
|
57
|
+
resolve({
|
|
58
|
+
content: [{ type: "text", text: `Successfully wrote ${content.length} bytes to ${path}` }],
|
|
59
|
+
details: undefined,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
// Clean up abort handler
|
|
64
|
+
if (signal) {
|
|
65
|
+
signal.removeEventListener("abort", onAbort);
|
|
66
|
+
}
|
|
67
|
+
if (!aborted) {
|
|
68
|
+
reject(error);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
})();
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** Default write tool using process.cwd() - for backwards compatibility */
|
|
77
|
+
export const writeTool = createWriteTool(process.cwd());
|
|
78
|
+
//# sourceMappingURL=write.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"write.js","sourceRoot":"","sources":["../../../src/agent/tools/write.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,SAAS,IAAI,WAAW,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,kDAAkD,EAAE,CAAC;IACtF,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,8BAA8B,EAAE,CAAC;CACrE,CAAC,CAAC;AAaH,MAAM,sBAAsB,GAAoB;IAC/C,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC;IACjE,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;CAChE,CAAC;AAOF,MAAM,UAAU,eAAe,CAAC,GAAW,EAAE,OAA0B;IACtE,MAAM,GAAG,GAAG,OAAO,EAAE,UAAU,IAAI,sBAAsB,CAAC;IAE1D,OAAO;QACN,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,OAAO;QACd,W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4BACZ,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;wBAC9C,CAAC;wBAED,OAAO,CAAC;4BACP,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,sBAAsB,OAAO,CAAC,MAAM,aAAa,IAAI,EAAE,EAAE,CAAC;4BAC1F,OAAO,EAAE,SAAS;yBAClB,CAAC,CAAC;oBACJ,CAAC;oBAAC,OAAO,KAAU,EAAE,CAAC;wBACrB,yBAAyB;wBACzB,IAAI,MAAM,EAAE,CAAC;4BACZ,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;wBAC9C,CAAC;wBAED,IAAI,CAAC,OAAO,EAAE,CAAC;4BACd,MAAM,CAAC,KAAK,CAAC,CAAC;wBACf,CAAC;oBACF,CAAC;gBACF,CAAC,CAAC,EAAE,CAAC;YACN,CAAC,CACD,CAAC;QACH,CAAC;KACD,CAAC;AACH,CAAC;AAED,2EAA2E;AAC3E,MAAM,CAAC,MAAM,SAAS,GAAG,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "indusagi",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.7",
|
|
4
4
|
"description": "All-in-one package that re-exports indusagi-ai, indusagi-agent, indusagi-tui, and indusagi-webui. Now with Kimi (Moonshot AI) support!",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|