indusagi 0.12.5 → 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/dist/ai/index.d.ts +0 -1
- package/dist/ai/index.d.ts.map +1 -1
- package/dist/ai/index.js +0 -1
- package/dist/ai/index.js.map +1 -1
- package/dist/ai/models.generated.d.ts +34 -208
- package/dist/ai/models.generated.d.ts.map +1 -1
- package/dist/ai/models.generated.js +37 -211
- package/dist/ai/models.generated.js.map +1 -1
- package/dist/ai/providers/google-shared.d.ts +6 -1
- package/dist/ai/providers/google-shared.d.ts.map +1 -1
- package/dist/ai/providers/google-shared.js.map +1 -1
- package/dist/ai/providers/google-vertex.d.ts +1 -1
- package/dist/ai/providers/google-vertex.d.ts.map +1 -1
- package/dist/ai/providers/google-vertex.js.map +1 -1
- package/dist/ai/providers/google.d.ts +1 -1
- package/dist/ai/providers/google.d.ts.map +1 -1
- package/dist/ai/providers/google.js.map +1 -1
- package/dist/ai/providers/register-builtins.d.ts.map +1 -1
- package/dist/ai/providers/register-builtins.js +0 -6
- package/dist/ai/providers/register-builtins.js.map +1 -1
- package/dist/ai/types.d.ts +2 -2
- package/dist/ai/types.d.ts.map +1 -1
- package/dist/ai/utils/oauth/index.d.ts +1 -4
- package/dist/ai/utils/oauth/index.d.ts.map +1 -1
- package/dist/ai/utils/oauth/index.js +1 -10
- package/dist/ai/utils/oauth/index.js.map +1 -1
- package/dist/ai/utils/oauth/openai-codex.js +1 -1
- package/dist/ai/utils/oauth/openai-codex.js.map +1 -1
- package/package.json +1 -1
- package/dist/ai/providers/google-gemini-cli.d.ts +0 -74
- package/dist/ai/providers/google-gemini-cli.d.ts.map +0 -1
- package/dist/ai/providers/google-gemini-cli.js +0 -816
- package/dist/ai/providers/google-gemini-cli.js.map +0 -1
- package/dist/ai/utils/oauth/google-antigravity.d.ts +0 -26
- package/dist/ai/utils/oauth/google-antigravity.d.ts.map +0 -1
- package/dist/ai/utils/oauth/google-antigravity.js +0 -390
- package/dist/ai/utils/oauth/google-antigravity.js.map +0 -1
- package/dist/ai/utils/oauth/google-gemini-cli.d.ts +0 -26
- package/dist/ai/utils/oauth/google-gemini-cli.d.ts.map +0 -1
- package/dist/ai/utils/oauth/google-gemini-cli.js +0 -462
- package/dist/ai/utils/oauth/google-gemini-cli.js.map +0 -1
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared truncation utilities for tool outputs.
|
|
3
|
+
*
|
|
4
|
+
* Truncation is based on two independent limits - whichever is hit first wins:
|
|
5
|
+
* - Line limit (default: 2000 lines)
|
|
6
|
+
* - Byte limit (default: 50KB)
|
|
7
|
+
*
|
|
8
|
+
* Never returns partial lines (except bash tail truncation edge case).
|
|
9
|
+
*/
|
|
10
|
+
export const DEFAULT_MAX_LINES = 2000;
|
|
11
|
+
export const DEFAULT_MAX_BYTES = 50 * 1024; // 50KB
|
|
12
|
+
export const GREP_MAX_LINE_LENGTH = 500; // Max chars per grep match line
|
|
13
|
+
/**
|
|
14
|
+
* Format bytes as human-readable size.
|
|
15
|
+
*/
|
|
16
|
+
export function formatSize(bytes) {
|
|
17
|
+
if (bytes < 1024) {
|
|
18
|
+
return `${bytes}B`;
|
|
19
|
+
}
|
|
20
|
+
else if (bytes < 1024 * 1024) {
|
|
21
|
+
return `${(bytes / 1024).toFixed(1)}KB`;
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Truncate content from the head (keep first N lines/bytes).
|
|
29
|
+
* Suitable for file reads where you want to see the beginning.
|
|
30
|
+
*
|
|
31
|
+
* Never returns partial lines. If first line exceeds byte limit,
|
|
32
|
+
* returns empty content with firstLineExceedsLimit=true.
|
|
33
|
+
*/
|
|
34
|
+
export function truncateHead(content, options = {}) {
|
|
35
|
+
const maxLines = options.maxLines ?? DEFAULT_MAX_LINES;
|
|
36
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
37
|
+
const totalBytes = Buffer.byteLength(content, "utf-8");
|
|
38
|
+
const lines = content.split("\n");
|
|
39
|
+
const totalLines = lines.length;
|
|
40
|
+
// Check if no truncation needed
|
|
41
|
+
if (totalLines <= maxLines && totalBytes <= maxBytes) {
|
|
42
|
+
return {
|
|
43
|
+
content,
|
|
44
|
+
truncated: false,
|
|
45
|
+
truncatedBy: null,
|
|
46
|
+
totalLines,
|
|
47
|
+
totalBytes,
|
|
48
|
+
outputLines: totalLines,
|
|
49
|
+
outputBytes: totalBytes,
|
|
50
|
+
lastLinePartial: false,
|
|
51
|
+
firstLineExceedsLimit: false,
|
|
52
|
+
maxLines,
|
|
53
|
+
maxBytes,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
// Check if first line alone exceeds byte limit
|
|
57
|
+
const firstLineBytes = Buffer.byteLength(lines[0], "utf-8");
|
|
58
|
+
if (firstLineBytes > maxBytes) {
|
|
59
|
+
return {
|
|
60
|
+
content: "",
|
|
61
|
+
truncated: true,
|
|
62
|
+
truncatedBy: "bytes",
|
|
63
|
+
totalLines,
|
|
64
|
+
totalBytes,
|
|
65
|
+
outputLines: 0,
|
|
66
|
+
outputBytes: 0,
|
|
67
|
+
lastLinePartial: false,
|
|
68
|
+
firstLineExceedsLimit: true,
|
|
69
|
+
maxLines,
|
|
70
|
+
maxBytes,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// Collect complete lines that fit
|
|
74
|
+
const outputLinesArr = [];
|
|
75
|
+
let outputBytesCount = 0;
|
|
76
|
+
let truncatedBy = "lines";
|
|
77
|
+
for (let i = 0; i < lines.length && i < maxLines; i++) {
|
|
78
|
+
const line = lines[i];
|
|
79
|
+
const lineBytes = Buffer.byteLength(line, "utf-8") + (i > 0 ? 1 : 0); // +1 for newline
|
|
80
|
+
if (outputBytesCount + lineBytes > maxBytes) {
|
|
81
|
+
truncatedBy = "bytes";
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
outputLinesArr.push(line);
|
|
85
|
+
outputBytesCount += lineBytes;
|
|
86
|
+
}
|
|
87
|
+
// If we exited due to line limit
|
|
88
|
+
if (outputLinesArr.length >= maxLines && outputBytesCount <= maxBytes) {
|
|
89
|
+
truncatedBy = "lines";
|
|
90
|
+
}
|
|
91
|
+
const outputContent = outputLinesArr.join("\n");
|
|
92
|
+
const finalOutputBytes = Buffer.byteLength(outputContent, "utf-8");
|
|
93
|
+
return {
|
|
94
|
+
content: outputContent,
|
|
95
|
+
truncated: true,
|
|
96
|
+
truncatedBy,
|
|
97
|
+
totalLines,
|
|
98
|
+
totalBytes,
|
|
99
|
+
outputLines: outputLinesArr.length,
|
|
100
|
+
outputBytes: finalOutputBytes,
|
|
101
|
+
lastLinePartial: false,
|
|
102
|
+
firstLineExceedsLimit: false,
|
|
103
|
+
maxLines,
|
|
104
|
+
maxBytes,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Truncate content from the tail (keep last N lines/bytes).
|
|
109
|
+
* Suitable for bash output where you want to see the end (errors, final results).
|
|
110
|
+
*
|
|
111
|
+
* May return partial first line if the last line of original content exceeds byte limit.
|
|
112
|
+
*/
|
|
113
|
+
export function truncateTail(content, options = {}) {
|
|
114
|
+
const maxLines = options.maxLines ?? DEFAULT_MAX_LINES;
|
|
115
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
116
|
+
const totalBytes = Buffer.byteLength(content, "utf-8");
|
|
117
|
+
const lines = content.split("\n");
|
|
118
|
+
const totalLines = lines.length;
|
|
119
|
+
// Check if no truncation needed
|
|
120
|
+
if (totalLines <= maxLines && totalBytes <= maxBytes) {
|
|
121
|
+
return {
|
|
122
|
+
content,
|
|
123
|
+
truncated: false,
|
|
124
|
+
truncatedBy: null,
|
|
125
|
+
totalLines,
|
|
126
|
+
totalBytes,
|
|
127
|
+
outputLines: totalLines,
|
|
128
|
+
outputBytes: totalBytes,
|
|
129
|
+
lastLinePartial: false,
|
|
130
|
+
firstLineExceedsLimit: false,
|
|
131
|
+
maxLines,
|
|
132
|
+
maxBytes,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
// Work backwards from the end
|
|
136
|
+
const outputLinesArr = [];
|
|
137
|
+
let outputBytesCount = 0;
|
|
138
|
+
let truncatedBy = "lines";
|
|
139
|
+
let lastLinePartial = false;
|
|
140
|
+
for (let i = lines.length - 1; i >= 0 && outputLinesArr.length < maxLines; i--) {
|
|
141
|
+
const line = lines[i];
|
|
142
|
+
const lineBytes = Buffer.byteLength(line, "utf-8") + (outputLinesArr.length > 0 ? 1 : 0); // +1 for newline
|
|
143
|
+
if (outputBytesCount + lineBytes > maxBytes) {
|
|
144
|
+
truncatedBy = "bytes";
|
|
145
|
+
// Edge case: if we haven't added ANY lines yet and this line exceeds maxBytes,
|
|
146
|
+
// take the end of the line (partial)
|
|
147
|
+
if (outputLinesArr.length === 0) {
|
|
148
|
+
const truncatedLine = truncateStringToBytesFromEnd(line, maxBytes);
|
|
149
|
+
outputLinesArr.unshift(truncatedLine);
|
|
150
|
+
outputBytesCount = Buffer.byteLength(truncatedLine, "utf-8");
|
|
151
|
+
lastLinePartial = true;
|
|
152
|
+
}
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
outputLinesArr.unshift(line);
|
|
156
|
+
outputBytesCount += lineBytes;
|
|
157
|
+
}
|
|
158
|
+
// If we exited due to line limit
|
|
159
|
+
if (outputLinesArr.length >= maxLines && outputBytesCount <= maxBytes) {
|
|
160
|
+
truncatedBy = "lines";
|
|
161
|
+
}
|
|
162
|
+
const outputContent = outputLinesArr.join("\n");
|
|
163
|
+
const finalOutputBytes = Buffer.byteLength(outputContent, "utf-8");
|
|
164
|
+
return {
|
|
165
|
+
content: outputContent,
|
|
166
|
+
truncated: true,
|
|
167
|
+
truncatedBy,
|
|
168
|
+
totalLines,
|
|
169
|
+
totalBytes,
|
|
170
|
+
outputLines: outputLinesArr.length,
|
|
171
|
+
outputBytes: finalOutputBytes,
|
|
172
|
+
lastLinePartial,
|
|
173
|
+
firstLineExceedsLimit: false,
|
|
174
|
+
maxLines,
|
|
175
|
+
maxBytes,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Truncate a string to fit within a byte limit (from the end).
|
|
180
|
+
* Handles multi-byte UTF-8 characters correctly.
|
|
181
|
+
*/
|
|
182
|
+
function truncateStringToBytesFromEnd(str, maxBytes) {
|
|
183
|
+
const buf = Buffer.from(str, "utf-8");
|
|
184
|
+
if (buf.length <= maxBytes) {
|
|
185
|
+
return str;
|
|
186
|
+
}
|
|
187
|
+
// Start from the end, skip maxBytes back
|
|
188
|
+
let start = buf.length - maxBytes;
|
|
189
|
+
// Find a valid UTF-8 boundary (start of a character)
|
|
190
|
+
while (start < buf.length && (buf[start] & 0xc0) === 0x80) {
|
|
191
|
+
start++;
|
|
192
|
+
}
|
|
193
|
+
return buf.slice(start).toString("utf-8");
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Truncate a single line to max characters, adding [truncated] suffix.
|
|
197
|
+
* Used for grep match lines.
|
|
198
|
+
*/
|
|
199
|
+
export function truncateLine(line, maxChars = GREP_MAX_LINE_LENGTH) {
|
|
200
|
+
if (line.length <= maxChars) {
|
|
201
|
+
return { text: line, wasTruncated: false };
|
|
202
|
+
}
|
|
203
|
+
return { text: `${line.slice(0, maxChars)}... [truncated]`, wasTruncated: true };
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=truncate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truncate.js","sourceRoot":"","sources":["../../../src/agent/tools/truncate.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;A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,CAAC,EAAE,QAAQ,CAAC,iBAAiB,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;AAClF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Placeholder for HookRunner.
|
|
3
|
+
* In the future, this can be expanded to support extension hooks.
|
|
4
|
+
*/
|
|
5
|
+
export declare class HookRunner {
|
|
6
|
+
hasHandlers(name: string): boolean;
|
|
7
|
+
trigger<Name extends string>(name: Name, input: unknown, output: unknown): Promise<unknown>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=hook-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-runner.d.ts","sourceRoot":"","sources":["../../../../src/agent/tools/utils/hook-runner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qBAAa,UAAU;IAEtB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI5B,OAAO,CAAC,IAAI,SAAS,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;CAGjG"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Placeholder for HookRunner.
|
|
3
|
+
* In the future, this can be expanded to support extension hooks.
|
|
4
|
+
*/
|
|
5
|
+
export class HookRunner {
|
|
6
|
+
// Placeholder implementation
|
|
7
|
+
hasHandlers(name) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
async trigger(name, input, output) {
|
|
11
|
+
return output;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=hook-runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-runner.js","sourceRoot":"","sources":["../../../../src/agent/tools/utils/hook-runner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,OAAO,UAAU;IACtB,6BAA6B;IAC7B,WAAW,CAAC,IAAY;QACvB,OAAO,KAAK,CAAC;IACd,CAAC;IAED,KAAK,CAAC,OAAO,CAAsB,IAAU,EAAE,KAAc,EAAE,MAAe;QAC7E,OAAO,MAAM,CAAC;IACf,CAAC;CACD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image resize utilities for the read tool.
|
|
3
|
+
* This is a simplified version that handles basic image operations.
|
|
4
|
+
*/
|
|
5
|
+
import type { ImageContent } from "../../../ai/index.js";
|
|
6
|
+
export interface ImageResizeOptions {
|
|
7
|
+
maxWidth?: number;
|
|
8
|
+
maxHeight?: number;
|
|
9
|
+
maxBytes?: number;
|
|
10
|
+
jpegQuality?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface ResizedImage {
|
|
13
|
+
data: string;
|
|
14
|
+
mimeType: string;
|
|
15
|
+
originalWidth: number;
|
|
16
|
+
originalHeight: number;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
wasResized: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Resize an image to fit within specified max dimensions and file size.
|
|
23
|
+
* This is a simplified version that returns the original image unchanged.
|
|
24
|
+
* Full image processing requires @silvia-odwyer/photon-node.
|
|
25
|
+
*/
|
|
26
|
+
export declare function resizeImage(img: ImageContent, options?: ImageResizeOptions): Promise<ResizedImage>;
|
|
27
|
+
/**
|
|
28
|
+
* Format a dimension note for resized images.
|
|
29
|
+
* This helps the model understand coordinate mapping.
|
|
30
|
+
*/
|
|
31
|
+
export declare function formatDimensionNote(result: ResizedImage): string | undefined;
|
|
32
|
+
//# sourceMappingURL=image-resize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-resize.d.ts","sourceRoot":"","sources":["../../../../src/agent/tools/utils/image-resize.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;CACpB;AAYD;;;;GAIG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAYxG;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAO5E"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image resize utilities for the read tool.
|
|
3
|
+
* This is a simplified version that handles basic image operations.
|
|
4
|
+
*/
|
|
5
|
+
// 4.5MB - provides headroom below Anthropic's 5MB limit
|
|
6
|
+
const DEFAULT_MAX_BYTES = 4.5 * 1024 * 1024;
|
|
7
|
+
const DEFAULT_OPTIONS = {
|
|
8
|
+
maxWidth: 2000,
|
|
9
|
+
maxHeight: 2000,
|
|
10
|
+
maxBytes: DEFAULT_MAX_BYTES,
|
|
11
|
+
jpegQuality: 80,
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Resize an image to fit within specified max dimensions and file size.
|
|
15
|
+
* This is a simplified version that returns the original image unchanged.
|
|
16
|
+
* Full image processing requires @silvia-odwyer/photon-node.
|
|
17
|
+
*/
|
|
18
|
+
export async function resizeImage(img, options) {
|
|
19
|
+
// Note: Full image resize functionality requires photon-node
|
|
20
|
+
// For now, return the image unchanged
|
|
21
|
+
return {
|
|
22
|
+
data: img.data,
|
|
23
|
+
mimeType: img.mimeType,
|
|
24
|
+
originalWidth: 0,
|
|
25
|
+
originalHeight: 0,
|
|
26
|
+
width: 0,
|
|
27
|
+
height: 0,
|
|
28
|
+
wasResized: false,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Format a dimension note for resized images.
|
|
33
|
+
* This helps the model understand coordinate mapping.
|
|
34
|
+
*/
|
|
35
|
+
export function formatDimensionNote(result) {
|
|
36
|
+
if (!result.wasResized) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
const scale = result.originalWidth / result.width;
|
|
40
|
+
return `[Image: original ${result.originalWidth}x${result.originalHeight}, displayed at ${result.width}x${result.height}. Multiply coordinates by ${scale.toFixed(2)} to map to original image.]`;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=image-resize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-resize.js","sourceRoot":"","sources":["../../../../src/agent/tools/utils/image-resize.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqBH,wDAAwD;AACxD,MAAM,iBAAiB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAE5C,MAAM,eAAe,GAAiC;IACrD,QAAQ,EAAE,IAAI;IACd,SAAS,EAAE,IAAI;IACf,QAAQ,EAAE,iBAAiB;IAC3B,WAAW,EAAE,EAAE;CACf,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAAiB,EAAE,OAA4B;IAChF,6DAA6D;IAC7D,sCAAsC;IACtC,OAAO;QACN,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,aAAa,EAAE,CAAC;QAChB,cAAc,EAAE,CAAC;QACjB,KAAK,EAAE,CAAC;QACR,MAAM,EAAE,CAAC;QACT,UAAU,EAAE,KAAK;KACjB,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAoB;IACvD,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC;IAClD,OAAO,oBAAoB,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,cAAc,kBAAkB,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,6BAA6B,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,6BAA6B,CAAC;AACnM,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIME type detection utilities for the read tool.
|
|
3
|
+
* This is a simplified version that handles basic MIME detection.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Detect if a file is a supported image type by reading magic bytes.
|
|
7
|
+
* This is a simplified version that checks common image signatures.
|
|
8
|
+
*/
|
|
9
|
+
export declare function detectSupportedImageMimeTypeFromFile(filePath: string): Promise<string | null>;
|
|
10
|
+
//# sourceMappingURL=mime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mime.d.ts","sourceRoot":"","sources":["../../../../src/agent/tools/utils/mime.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH;;;GAGG;AACH,wBAAsB,oCAAoC,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAoCnG"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIME type detection utilities for the read tool.
|
|
3
|
+
* This is a simplified version that handles basic MIME detection.
|
|
4
|
+
*/
|
|
5
|
+
import { open } from "node:fs/promises";
|
|
6
|
+
const IMAGE_MIME_TYPES = new Set(["image/jpeg", "image/png", "image/gif", "image/webp"]);
|
|
7
|
+
const FILE_TYPE_SNIFF_BYTES = 4100;
|
|
8
|
+
/**
|
|
9
|
+
* Detect if a file is a supported image type by reading magic bytes.
|
|
10
|
+
* This is a simplified version that checks common image signatures.
|
|
11
|
+
*/
|
|
12
|
+
export async function detectSupportedImageMimeTypeFromFile(filePath) {
|
|
13
|
+
const fileHandle = await open(filePath, "r");
|
|
14
|
+
try {
|
|
15
|
+
const buffer = Buffer.alloc(FILE_TYPE_SNIFF_BYTES);
|
|
16
|
+
const { bytesRead } = await fileHandle.read(buffer, 0, FILE_TYPE_SNIFF_BYTES, 0);
|
|
17
|
+
if (bytesRead === 0) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
// Check for common image signatures
|
|
21
|
+
if (bytesRead >= 3 && buffer[0] === 0xff && buffer[1] === 0xd8 && buffer[2] === 0xff) {
|
|
22
|
+
return "image/jpeg";
|
|
23
|
+
}
|
|
24
|
+
if (bytesRead >= 8 &&
|
|
25
|
+
buffer[0] === 0x89 && buffer[1] === 0x50 && buffer[2] === 0x4e &&
|
|
26
|
+
buffer[3] === 0x47 && buffer[4] === 0x0d && buffer[5] === 0x0a &&
|
|
27
|
+
buffer[6] === 0x1a && buffer[7] === 0x0a) {
|
|
28
|
+
return "image/png";
|
|
29
|
+
}
|
|
30
|
+
if (bytesRead >= 6 &&
|
|
31
|
+
buffer[0] === 0x47 && buffer[1] === 0x49 && buffer[2] === 0x46 &&
|
|
32
|
+
buffer[3] === 0x38 &&
|
|
33
|
+
(buffer[4] === 0x37 || buffer[4] === 0x39) && buffer[5] === 0x61) {
|
|
34
|
+
return "image/gif";
|
|
35
|
+
}
|
|
36
|
+
if (bytesRead >= 12 &&
|
|
37
|
+
buffer[0] === 0x52 && buffer[1] === 0x49 && buffer[2] === 0x46 &&
|
|
38
|
+
buffer[3] === 0x46 && buffer[8] === 0x57 && buffer[9] === 0x45 &&
|
|
39
|
+
buffer[10] === 0x42 && buffer[11] === 0x50) {
|
|
40
|
+
return "image/webp";
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
await fileHandle.close();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=mime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mime.js","sourceRoot":"","sources":["../../../../src/agent/tools/utils/mime.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC,CAAC;AAEzF,MAAM,qBAAqB,GAAG,IAAI,CAAC;AAEnC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,oCAAoC,CAAC,QAAgB;IAC1E,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC7C,IAAI,CAAC;QACJ,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACnD,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,qBAAqB,EAAE,CAAC,CAAC,CAAC;QACjF,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC;QACb,CAAC;QAED,oCAAoC;QACpC,IAAI,SAAS,IAAI,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACtF,OAAO,YAAY,CAAC;QACrB,CAAC;QACD,IAAI,SAAS,IAAI,CAAC;YACjB,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK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@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell utilities for bash tool.
|
|
3
|
+
* Simplified version for indusagi agent framework.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Get shell configuration based on platform.
|
|
7
|
+
* Resolution order:
|
|
8
|
+
* 1. On Windows: Git Bash in known locations, then bash on PATH
|
|
9
|
+
* 2. On Unix: /bin/bash
|
|
10
|
+
* 3. Fallback: sh
|
|
11
|
+
*/
|
|
12
|
+
export declare function getShellConfig(): {
|
|
13
|
+
shell: string;
|
|
14
|
+
args: string[];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Get shell environment.
|
|
18
|
+
* Returns current environment with PATH unmodified.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getShellEnv(): NodeJS.ProcessEnv;
|
|
21
|
+
/**
|
|
22
|
+
* Sanitize binary output for display/storage.
|
|
23
|
+
* Removes characters that crash string-width or cause display issues.
|
|
24
|
+
*/
|
|
25
|
+
export declare function sanitizeBinaryOutput(str: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Kill a process and all its children (cross-platform)
|
|
28
|
+
*/
|
|
29
|
+
export declare function killProcessTree(pid: number): void;
|
|
30
|
+
//# sourceMappingURL=shell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../../../src/agent/tools/utils/shell.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA0BH;;;;;;GAMG;AACH,wBAAgB,cAAc,IAAI;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CA+ClE;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,MAAM,CAAC,UAAU,CAE/C;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAqBxD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAwBjD"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shell utilities for bash tool.
|
|
3
|
+
* Simplified version for indusagi agent framework.
|
|
4
|
+
*/
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { spawn, spawnSync } from "child_process";
|
|
7
|
+
let cachedShellConfig = null;
|
|
8
|
+
/**
|
|
9
|
+
* Find bash executable on PATH (Windows)
|
|
10
|
+
*/
|
|
11
|
+
function findBashOnPath() {
|
|
12
|
+
try {
|
|
13
|
+
const result = spawnSync("where", ["bash.exe"], { encoding: "utf-8", timeout: 5000 });
|
|
14
|
+
if (result.status === 0 && result.stdout) {
|
|
15
|
+
const firstMatch = result.stdout.trim().split(/\r?\n/)[0];
|
|
16
|
+
if (firstMatch && existsSync(firstMatch)) {
|
|
17
|
+
return firstMatch;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
// Ignore errors
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get shell configuration based on platform.
|
|
28
|
+
* Resolution order:
|
|
29
|
+
* 1. On Windows: Git Bash in known locations, then bash on PATH
|
|
30
|
+
* 2. On Unix: /bin/bash
|
|
31
|
+
* 3. Fallback: sh
|
|
32
|
+
*/
|
|
33
|
+
export function getShellConfig() {
|
|
34
|
+
if (cachedShellConfig) {
|
|
35
|
+
return cachedShellConfig;
|
|
36
|
+
}
|
|
37
|
+
if (process.platform === "win32") {
|
|
38
|
+
// Try Git Bash in known locations
|
|
39
|
+
const paths = [];
|
|
40
|
+
const programFiles = process.env.ProgramFiles;
|
|
41
|
+
if (programFiles) {
|
|
42
|
+
paths.push(`${programFiles}\\Git\\bin\\bash.exe`);
|
|
43
|
+
}
|
|
44
|
+
const programFilesX86 = process.env["ProgramFiles(x86)"];
|
|
45
|
+
if (programFilesX86) {
|
|
46
|
+
paths.push(`${programFilesX86}\\Git\\bin\\bash.exe`);
|
|
47
|
+
}
|
|
48
|
+
for (const path of paths) {
|
|
49
|
+
if (existsSync(path)) {
|
|
50
|
+
cachedShellConfig = { shell: path, args: ["-c"] };
|
|
51
|
+
return cachedShellConfig;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Fallback: search bash.exe on PATH (Cygwin, MSYS2, WSL, etc.)
|
|
55
|
+
const bashOnPath = findBashOnPath();
|
|
56
|
+
if (bashOnPath) {
|
|
57
|
+
cachedShellConfig = { shell: bashOnPath, args: ["-c"] };
|
|
58
|
+
return cachedShellConfig;
|
|
59
|
+
}
|
|
60
|
+
throw new Error(`No bash shell found on Windows. Options:\n` +
|
|
61
|
+
` 1. Install Git for Windows: https://git-scm.com/download/win\n` +
|
|
62
|
+
` 2. Add your bash to PATH (Cygwin, MSYS2, etc.)\n\n` +
|
|
63
|
+
`Searched Git Bash in:\n${paths.map((p) => ` ${p}`).join("\n")}`);
|
|
64
|
+
}
|
|
65
|
+
// Unix: prefer bash over sh
|
|
66
|
+
if (existsSync("/bin/bash")) {
|
|
67
|
+
cachedShellConfig = { shell: "/bin/bash", args: ["-c"] };
|
|
68
|
+
return cachedShellConfig;
|
|
69
|
+
}
|
|
70
|
+
cachedShellConfig = { shell: "sh", args: ["-c"] };
|
|
71
|
+
return cachedShellConfig;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get shell environment.
|
|
75
|
+
* Returns current environment with PATH unmodified.
|
|
76
|
+
*/
|
|
77
|
+
export function getShellEnv() {
|
|
78
|
+
return { ...process.env };
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Sanitize binary output for display/storage.
|
|
82
|
+
* Removes characters that crash string-width or cause display issues.
|
|
83
|
+
*/
|
|
84
|
+
export function sanitizeBinaryOutput(str) {
|
|
85
|
+
// Use Array.from to properly iterate over code points
|
|
86
|
+
return Array.from(str)
|
|
87
|
+
.filter((char) => {
|
|
88
|
+
const code = char.codePointAt(0);
|
|
89
|
+
// Skip if code point is undefined
|
|
90
|
+
if (code === undefined)
|
|
91
|
+
return false;
|
|
92
|
+
// Allow tab, newline, carriage return
|
|
93
|
+
if (code === 0x09 || code === 0x0a || code === 0x0d)
|
|
94
|
+
return true;
|
|
95
|
+
// Filter out control characters (0x00-0x1F, except 0x09, 0x0a, 0x0x0d)
|
|
96
|
+
if (code <= 0x1f)
|
|
97
|
+
return false;
|
|
98
|
+
// Filter out Unicode format characters
|
|
99
|
+
if (code >= 0xfff9 && code <= 0xfffb)
|
|
100
|
+
return false;
|
|
101
|
+
return true;
|
|
102
|
+
})
|
|
103
|
+
.join("");
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Kill a process and all its children (cross-platform)
|
|
107
|
+
*/
|
|
108
|
+
export function killProcessTree(pid) {
|
|
109
|
+
if (process.platform === "win32") {
|
|
110
|
+
// Use taskkill on Windows to kill process tree
|
|
111
|
+
try {
|
|
112
|
+
spawn("taskkill", ["/F", "/T", "/PID", String(pid)], {
|
|
113
|
+
stdio: "ignore",
|
|
114
|
+
detached: true,
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
// Ignore errors if taskkill fails
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
// Use SIGKILL on Unix/Linux/Mac
|
|
123
|
+
try {
|
|
124
|
+
process.kill(-pid, "SIGKILL");
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// Fallback to killing just the child if process group kill fails
|
|
128
|
+
try {
|
|
129
|
+
process.kill(pid, "SIGKILL");
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// Process already dead
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=shell.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell.js","sourceRoot":"","sources":["../../../../src/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EAAE,SAAS,CAAC,CAAC;YAC9B,CAAC;YAAC,MAAM,CAAC;gBACR,uBAAuB;YACxB,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 { AgentTool } from "../types.js";
|
|
8
|
+
declare const webFetchSchema: import("@sinclair/typebox").TObject<{
|
|
9
|
+
url: import("@sinclair/typebox").TString;
|
|
10
|
+
format: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"text">, import("@sinclair/typebox").TLiteral<"markdown">, import("@sinclair/typebox").TLiteral<"html">]>>;
|
|
11
|
+
timeout: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
12
|
+
}>;
|
|
13
|
+
export interface WebFetchToolDetails {
|
|
14
|
+
url: string;
|
|
15
|
+
format?: "text" | "markdown" | "html";
|
|
16
|
+
timeout?: number;
|
|
17
|
+
contentType?: string;
|
|
18
|
+
fetchedBytes?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface WebFetchToolOptions {
|
|
21
|
+
/** Maximum response size in bytes (default: 5MB) */
|
|
22
|
+
maxResponseSize?: number;
|
|
23
|
+
/** Default timeout in milliseconds (default: 30000) */
|
|
24
|
+
defaultTimeout?: number;
|
|
25
|
+
}
|
|
26
|
+
export declare function createWebFetchTool(options?: WebFetchToolOptions): AgentTool<typeof webFetchSchema>;
|
|
27
|
+
/** Default web fetch tool */
|
|
28
|
+
export declare const webFetchTool: AgentTool<import("@sinclair/typebox").TObject<{
|
|
29
|
+
url: import("@sinclair/typebox").TString;
|
|
30
|
+
format: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"text">, import("@sinclair/typebox").TLiteral<"markdown">, import("@sinclair/typebox").TLiteral<"html">]>>;
|
|
31
|
+
timeout: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
32
|
+
}>, any>;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=webfetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webfetch.d.ts","sourceRoot":"","sources":["../../../src/agent/tools/webfetch.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAO7C,QAAA,MAAM,cAAc;;;;EAQlB,CAAC;AAEH,MAAM,WAAW,mBAAmB;IACnC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,mBAAmB;IACnC,oDAAoD;IACpD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,uDAAuD;IACvD,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AA6ID,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,SAAS,CAAC,OAAO,cAAc,CAAC,CA+IlG;AAED,6BAA6B;AAC7B,eAAO,MAAM,YAAY;;;;QAAuB,CAAC"}
|