@agi-cli/sdk 0.1.53 → 0.1.55
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/package.json +52 -27
- package/src/agent/types.ts +1 -1
- package/src/auth/src/index.ts +70 -0
- package/src/auth/src/oauth.ts +172 -0
- package/src/config/src/index.ts +120 -0
- package/src/config/src/manager.ts +102 -0
- package/src/config/src/paths.ts +98 -0
- package/src/core/src/errors.ts +102 -0
- package/src/core/src/index.ts +75 -0
- package/src/core/src/providers/resolver.ts +84 -0
- package/src/core/src/streaming/artifacts.ts +41 -0
- package/src/core/src/tools/builtin/bash.ts +90 -0
- package/src/core/src/tools/builtin/bash.txt +7 -0
- package/src/core/src/tools/builtin/edit.ts +152 -0
- package/src/core/src/tools/builtin/edit.txt +7 -0
- package/src/core/src/tools/builtin/file-cache.ts +39 -0
- package/src/core/src/tools/builtin/finish.ts +11 -0
- package/src/core/src/tools/builtin/finish.txt +5 -0
- package/src/core/src/tools/builtin/fs/cd.ts +19 -0
- package/src/core/src/tools/builtin/fs/cd.txt +5 -0
- package/src/core/src/tools/builtin/fs/index.ts +20 -0
- package/src/core/src/tools/builtin/fs/ls.ts +60 -0
- package/src/core/src/tools/builtin/fs/ls.txt +8 -0
- package/src/core/src/tools/builtin/fs/pwd.ts +17 -0
- package/src/core/src/tools/builtin/fs/pwd.txt +5 -0
- package/src/core/src/tools/builtin/fs/read.ts +80 -0
- package/src/core/src/tools/builtin/fs/read.txt +8 -0
- package/src/core/src/tools/builtin/fs/tree.ts +71 -0
- package/src/core/src/tools/builtin/fs/tree.txt +8 -0
- package/src/core/src/tools/builtin/fs/util.ts +95 -0
- package/src/core/src/tools/builtin/fs/write.ts +61 -0
- package/src/core/src/tools/builtin/fs/write.txt +8 -0
- package/src/core/src/tools/builtin/git.commit.txt +6 -0
- package/src/core/src/tools/builtin/git.diff.txt +5 -0
- package/src/core/src/tools/builtin/git.status.txt +5 -0
- package/src/core/src/tools/builtin/git.ts +128 -0
- package/src/core/src/tools/builtin/grep.ts +140 -0
- package/src/core/src/tools/builtin/grep.txt +9 -0
- package/src/core/src/tools/builtin/ignore.ts +45 -0
- package/src/core/src/tools/builtin/patch.ts +269 -0
- package/src/core/src/tools/builtin/patch.txt +7 -0
- package/src/core/src/tools/builtin/plan.ts +58 -0
- package/src/core/src/tools/builtin/plan.txt +6 -0
- package/src/core/src/tools/builtin/progress.ts +55 -0
- package/src/core/src/tools/builtin/progress.txt +7 -0
- package/src/core/src/tools/builtin/ripgrep.ts +102 -0
- package/src/core/src/tools/builtin/ripgrep.txt +7 -0
- package/src/core/src/tools/builtin/websearch.ts +219 -0
- package/src/core/src/tools/builtin/websearch.txt +12 -0
- package/src/core/src/tools/loader.ts +398 -0
- package/src/core/src/types/index.ts +11 -0
- package/src/core/src/types/types.ts +4 -0
- package/src/index.ts +57 -58
- package/src/prompts/src/agents/build.txt +5 -0
- package/src/prompts/src/agents/general.txt +6 -0
- package/src/prompts/src/agents/plan.txt +13 -0
- package/src/prompts/src/base.txt +14 -0
- package/src/prompts/src/debug.ts +104 -0
- package/src/prompts/src/index.ts +1 -0
- package/src/prompts/src/modes/oneshot.txt +9 -0
- package/src/prompts/src/providers/anthropic.txt +151 -0
- package/src/prompts/src/providers/anthropicSpoof.txt +1 -0
- package/src/prompts/src/providers/default.txt +310 -0
- package/src/prompts/src/providers/google.txt +155 -0
- package/src/prompts/src/providers/openai.txt +310 -0
- package/src/prompts/src/providers.ts +116 -0
- package/src/providers/src/authorization.ts +17 -0
- package/src/providers/src/catalog.ts +4201 -0
- package/src/providers/src/env.ts +26 -0
- package/src/providers/src/index.ts +12 -0
- package/src/providers/src/pricing.ts +135 -0
- package/src/providers/src/utils.ts +24 -0
- package/src/providers/src/validate.ts +39 -0
- package/src/types/src/auth.ts +26 -0
- package/src/types/src/config.ts +40 -0
- package/src/types/src/index.ts +14 -0
- package/src/types/src/provider.ts +28 -0
- package/src/global.d.ts +0 -4
- package/src/tools/builtin/fs.ts +0 -1
- package/src/tools/builtin/git.ts +0 -1
- package/src/web-ui.ts +0 -8
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { tool, type Tool } from 'ai';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import DESCRIPTION from './ripgrep.txt' with { type: 'text' };
|
|
6
|
+
|
|
7
|
+
export function buildRipgrepTool(projectRoot: string): {
|
|
8
|
+
name: string;
|
|
9
|
+
tool: Tool;
|
|
10
|
+
} {
|
|
11
|
+
const rg = tool({
|
|
12
|
+
description: DESCRIPTION,
|
|
13
|
+
inputSchema: z.object({
|
|
14
|
+
query: z.string().min(1).describe('Search pattern (regex by default)'),
|
|
15
|
+
path: z
|
|
16
|
+
.string()
|
|
17
|
+
.optional()
|
|
18
|
+
.default('.')
|
|
19
|
+
.describe('Relative path to search in'),
|
|
20
|
+
ignoreCase: z.boolean().optional().default(false),
|
|
21
|
+
glob: z
|
|
22
|
+
.array(z.string())
|
|
23
|
+
.optional()
|
|
24
|
+
.describe('One or more glob patterns to include'),
|
|
25
|
+
maxResults: z.number().int().min(1).max(5000).optional().default(500),
|
|
26
|
+
}),
|
|
27
|
+
async execute({
|
|
28
|
+
query,
|
|
29
|
+
path = '.',
|
|
30
|
+
ignoreCase,
|
|
31
|
+
glob,
|
|
32
|
+
maxResults = 500,
|
|
33
|
+
}: {
|
|
34
|
+
query: string;
|
|
35
|
+
path?: string;
|
|
36
|
+
ignoreCase?: boolean;
|
|
37
|
+
glob?: string[];
|
|
38
|
+
maxResults?: number;
|
|
39
|
+
}) {
|
|
40
|
+
function expandTilde(p: string) {
|
|
41
|
+
const home = process.env.HOME || process.env.USERPROFILE || '';
|
|
42
|
+
if (!home) return p;
|
|
43
|
+
if (p === '~') return home;
|
|
44
|
+
if (p.startsWith('~/')) return `${home}/${p.slice(2)}`;
|
|
45
|
+
return p;
|
|
46
|
+
}
|
|
47
|
+
const p = expandTilde(String(path ?? '.')).trim();
|
|
48
|
+
const isAbs = p.startsWith('/') || /^[A-Za-z]:[\\/]/.test(p);
|
|
49
|
+
const target = p ? (isAbs ? p : join(projectRoot, p)) : projectRoot;
|
|
50
|
+
const args = ['--no-heading', '--line-number', '--color=never'];
|
|
51
|
+
if (ignoreCase) args.push('-i');
|
|
52
|
+
if (Array.isArray(glob)) for (const g of glob) args.push('-g', g);
|
|
53
|
+
args.push('--max-count', String(maxResults));
|
|
54
|
+
args.push(query);
|
|
55
|
+
args.push(target);
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
return await new Promise((resolve) => {
|
|
59
|
+
const proc = spawn('rg', args, { cwd: projectRoot });
|
|
60
|
+
let stdout = '';
|
|
61
|
+
let stderr = '';
|
|
62
|
+
|
|
63
|
+
proc.stdout.on('data', (data) => {
|
|
64
|
+
stdout += data.toString();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
proc.stderr.on('data', (data) => {
|
|
68
|
+
stderr += data.toString();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
proc.on('close', (code) => {
|
|
72
|
+
if (code !== 0 && code !== 1) {
|
|
73
|
+
resolve({ count: 0, matches: [], error: stderr.trim() });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const lines = stdout
|
|
78
|
+
.split('\n')
|
|
79
|
+
.filter(Boolean)
|
|
80
|
+
.slice(0, maxResults);
|
|
81
|
+
const matches = lines.map((l) => {
|
|
82
|
+
const parts = l.split(':');
|
|
83
|
+
if (parts.length < 3) return { file: '', line: 0, text: l };
|
|
84
|
+
const file = parts[0];
|
|
85
|
+
const line = Number.parseInt(parts[1], 10);
|
|
86
|
+
const text = parts.slice(2).join(':');
|
|
87
|
+
return { file, line, text };
|
|
88
|
+
});
|
|
89
|
+
resolve({ count: matches.length, matches });
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
proc.on('error', (err) => {
|
|
93
|
+
resolve({ count: 0, matches: [], error: String(err) });
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
} catch (err) {
|
|
97
|
+
return { count: 0, matches: [], error: String(err) };
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
return { name: 'ripgrep', tool: rg };
|
|
102
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
- Search files using ripgrep (rg) with regex patterns
|
|
2
|
+
- Returns a flat list of matches with `file`, `line`, and `text`
|
|
3
|
+
- Supports include globs and case-insensitive search
|
|
4
|
+
|
|
5
|
+
Usage tips:
|
|
6
|
+
- Use the Grep tool for a friendly summary grouped by file
|
|
7
|
+
- Use the Glob tool first to limit the search set if needed
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { tool, type Tool } from 'ai';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import DESCRIPTION from './websearch.txt' with { type: 'text' };
|
|
4
|
+
|
|
5
|
+
export function buildWebSearchTool(): {
|
|
6
|
+
name: string;
|
|
7
|
+
tool: Tool;
|
|
8
|
+
} {
|
|
9
|
+
const websearch = tool({
|
|
10
|
+
description: DESCRIPTION,
|
|
11
|
+
inputSchema: z
|
|
12
|
+
.object({
|
|
13
|
+
url: z
|
|
14
|
+
.string()
|
|
15
|
+
.optional()
|
|
16
|
+
.describe(
|
|
17
|
+
'URL to fetch content from (mutually exclusive with query)',
|
|
18
|
+
),
|
|
19
|
+
query: z
|
|
20
|
+
.string()
|
|
21
|
+
.optional()
|
|
22
|
+
.describe(
|
|
23
|
+
'Search query to search the web (mutually exclusive with url)',
|
|
24
|
+
),
|
|
25
|
+
maxLength: z
|
|
26
|
+
.number()
|
|
27
|
+
.optional()
|
|
28
|
+
.default(50000)
|
|
29
|
+
.describe(
|
|
30
|
+
'Maximum content length to return (default: 50000 characters)',
|
|
31
|
+
),
|
|
32
|
+
})
|
|
33
|
+
.strict()
|
|
34
|
+
.refine((data) => (data.url ? !data.query : !!data.query), {
|
|
35
|
+
message: 'Must provide either url or query, but not both',
|
|
36
|
+
}),
|
|
37
|
+
async execute({
|
|
38
|
+
url,
|
|
39
|
+
query,
|
|
40
|
+
maxLength,
|
|
41
|
+
}: {
|
|
42
|
+
url?: string;
|
|
43
|
+
query?: string;
|
|
44
|
+
maxLength?: number;
|
|
45
|
+
}) {
|
|
46
|
+
const maxLen = maxLength ?? 50000;
|
|
47
|
+
|
|
48
|
+
if (url) {
|
|
49
|
+
// Fetch URL content
|
|
50
|
+
try {
|
|
51
|
+
const response = await fetch(url, {
|
|
52
|
+
headers: {
|
|
53
|
+
'User-Agent':
|
|
54
|
+
'Mozilla/5.0 (compatible; AGI-Bot/1.0; +https://github.com/anthropics/agi)',
|
|
55
|
+
Accept:
|
|
56
|
+
'text/html,application/xhtml+xml,application/xml;q=0.9,text/plain;q=0.8,*/*;q=0.7',
|
|
57
|
+
},
|
|
58
|
+
redirect: 'follow',
|
|
59
|
+
signal: AbortSignal.timeout(30000), // 30 second timeout
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
`HTTP error! status: ${response.status} ${response.statusText}`,
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const contentType = response.headers.get('content-type') || '';
|
|
69
|
+
let content = '';
|
|
70
|
+
|
|
71
|
+
if (
|
|
72
|
+
contentType.includes('text/') ||
|
|
73
|
+
contentType.includes('application/json') ||
|
|
74
|
+
contentType.includes('application/xml') ||
|
|
75
|
+
contentType.includes('application/xhtml')
|
|
76
|
+
) {
|
|
77
|
+
content = await response.text();
|
|
78
|
+
} else {
|
|
79
|
+
return {
|
|
80
|
+
error: `Unsupported content type: ${contentType}. Only text-based content can be fetched.`,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Strip HTML tags for better readability (basic cleaning)
|
|
85
|
+
const cleanContent = content
|
|
86
|
+
.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
|
|
87
|
+
.replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, '')
|
|
88
|
+
.replace(/<[^>]+>/g, ' ')
|
|
89
|
+
.replace(/\s+/g, ' ')
|
|
90
|
+
.trim();
|
|
91
|
+
|
|
92
|
+
const truncated = cleanContent.slice(0, maxLen);
|
|
93
|
+
const wasTruncated = cleanContent.length > maxLen;
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
url,
|
|
97
|
+
content: truncated,
|
|
98
|
+
contentLength: cleanContent.length,
|
|
99
|
+
truncated: wasTruncated,
|
|
100
|
+
contentType,
|
|
101
|
+
};
|
|
102
|
+
} catch (error) {
|
|
103
|
+
const errorMessage =
|
|
104
|
+
error instanceof Error ? error.message : String(error);
|
|
105
|
+
return {
|
|
106
|
+
error: `Failed to fetch URL: ${errorMessage}`,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (query) {
|
|
112
|
+
// Web search functionality
|
|
113
|
+
// Use DuckDuckGo's HTML search (doesn't require API key)
|
|
114
|
+
try {
|
|
115
|
+
const searchUrl = `https://html.duckduckgo.com/html/?q=${encodeURIComponent(query)}`;
|
|
116
|
+
const response = await fetch(searchUrl, {
|
|
117
|
+
headers: {
|
|
118
|
+
'User-Agent':
|
|
119
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
|
|
120
|
+
Accept: 'text/html',
|
|
121
|
+
},
|
|
122
|
+
redirect: 'follow',
|
|
123
|
+
signal: AbortSignal.timeout(30000),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
if (!response.ok) {
|
|
127
|
+
throw new Error(`Search failed: ${response.status}`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const html = await response.text();
|
|
131
|
+
|
|
132
|
+
// Parse DuckDuckGo results (basic parsing)
|
|
133
|
+
const results: Array<{
|
|
134
|
+
title: string;
|
|
135
|
+
url: string;
|
|
136
|
+
snippet: string;
|
|
137
|
+
}> = [];
|
|
138
|
+
|
|
139
|
+
// Match result blocks
|
|
140
|
+
const resultPattern =
|
|
141
|
+
/<a[^>]+class="result__a"[^>]+href="([^"]+)"[^>]*>([^<]+)<\/a>[\s\S]*?<a[^>]+class="result__snippet"[^>]*>([\s\S]*?)<\/a>/gi;
|
|
142
|
+
|
|
143
|
+
let match: RegExpExecArray | null = null;
|
|
144
|
+
match = resultPattern.exec(html);
|
|
145
|
+
while (match !== null && results.length < 10) {
|
|
146
|
+
const url = match[1]?.trim();
|
|
147
|
+
const title = match[2]?.trim();
|
|
148
|
+
let snippet = match[3]?.trim();
|
|
149
|
+
|
|
150
|
+
if (url && title) {
|
|
151
|
+
// Clean snippet
|
|
152
|
+
snippet = snippet
|
|
153
|
+
?.replace(/<[^>]+>/g, '')
|
|
154
|
+
.replace(/\s+/g, ' ')
|
|
155
|
+
.trim();
|
|
156
|
+
|
|
157
|
+
results.push({
|
|
158
|
+
title,
|
|
159
|
+
url,
|
|
160
|
+
snippet: snippet || '',
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
match = resultPattern.exec(html);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Fallback: simpler pattern if the above doesn't work
|
|
167
|
+
if (results.length === 0) {
|
|
168
|
+
const simplePattern =
|
|
169
|
+
/<a[^>]+rel="nofollow"[^>]+href="([^"]+)"[^>]*>([^<]+)<\/a>/gi;
|
|
170
|
+
match = simplePattern.exec(html);
|
|
171
|
+
while (match !== null && results.length < 10) {
|
|
172
|
+
const url = match[1]?.trim();
|
|
173
|
+
const title = match[2]?.trim();
|
|
174
|
+
if (url && title && url.startsWith('http')) {
|
|
175
|
+
results.push({
|
|
176
|
+
title,
|
|
177
|
+
url,
|
|
178
|
+
snippet: '',
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
match = simplePattern.exec(html);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (results.length === 0) {
|
|
186
|
+
return {
|
|
187
|
+
error:
|
|
188
|
+
'No search results found. The search service may have changed its format or blocked the request.',
|
|
189
|
+
query,
|
|
190
|
+
suggestion:
|
|
191
|
+
'Try using the url parameter to fetch a specific webpage instead.',
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
query,
|
|
197
|
+
results,
|
|
198
|
+
count: results.length,
|
|
199
|
+
};
|
|
200
|
+
} catch (error) {
|
|
201
|
+
const errorMessage =
|
|
202
|
+
error instanceof Error ? error.message : String(error);
|
|
203
|
+
return {
|
|
204
|
+
error: `Search failed: ${errorMessage}`,
|
|
205
|
+
query,
|
|
206
|
+
suggestion:
|
|
207
|
+
'Search services may be temporarily unavailable. Try using the url parameter to fetch a specific webpage instead.',
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
error: 'Must provide either url or query parameter',
|
|
214
|
+
};
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
return { name: 'websearch', tool: websearch };
|
|
219
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
- Search the web or fetch content from URLs
|
|
2
|
+
- Use `query` to search the web and get a list of results with titles, URLs, and snippets
|
|
3
|
+
- Use `url` to fetch and read the content of a specific webpage
|
|
4
|
+
- Returns cleaned, text-based content (HTML tags are stripped)
|
|
5
|
+
- Cannot be used for both search and URL fetch in the same call
|
|
6
|
+
|
|
7
|
+
Usage tips:
|
|
8
|
+
- For research: use `query` to find relevant pages, then `url` to read specific ones
|
|
9
|
+
- Search returns up to 10 results with titles, URLs, and snippets
|
|
10
|
+
- URL fetching works for text-based content (HTML, JSON, XML, plain text)
|
|
11
|
+
- Content is automatically truncated if it exceeds maxLength (default 50,000 chars)
|
|
12
|
+
- Use this to gather current information, read documentation, or verify facts
|