BREAKING CHANGE(api): Migrate public API to ai-sdk v6 and refactor core agent architecture: replace class-based DualAgent/Driver/Guardian with a single runAgent function; introduce ts_tools factories for tools, a compactMessages compaction subpath, and truncateOutput utility; simplify ToolRegistry to return ToolSet and remove legacy BaseToolWrapper/tool classes; update package exports and dependencies and bump major version.
This commit is contained in:
78
ts_tools/tool.http.ts
Normal file
78
ts_tools/tool.http.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import * as plugins from './plugins.js';
|
||||
|
||||
export function httpTool(): plugins.ToolSet {
|
||||
return {
|
||||
http_get: plugins.tool({
|
||||
description: 'Make an HTTP GET request and return the response.',
|
||||
inputSchema: plugins.z.object({
|
||||
url: plugins.z.string().describe('URL to request'),
|
||||
headers: plugins.z
|
||||
.record(plugins.z.string())
|
||||
.optional()
|
||||
.describe('Request headers'),
|
||||
}),
|
||||
execute: async ({
|
||||
url,
|
||||
headers,
|
||||
}: {
|
||||
url: string;
|
||||
headers?: Record<string, string>;
|
||||
}) => {
|
||||
let req = plugins.smartrequest.default.create().url(url);
|
||||
if (headers) {
|
||||
req = req.headers(headers);
|
||||
}
|
||||
const response = await req.get();
|
||||
let body: string;
|
||||
try {
|
||||
const json = await response.json();
|
||||
body = JSON.stringify(json, null, 2);
|
||||
} catch {
|
||||
body = await response.text();
|
||||
}
|
||||
return plugins.truncateOutput(`HTTP ${response.status}\n${body}`).content;
|
||||
},
|
||||
}),
|
||||
|
||||
http_post: plugins.tool({
|
||||
description: 'Make an HTTP POST request with a JSON body.',
|
||||
inputSchema: plugins.z.object({
|
||||
url: plugins.z.string().describe('URL to request'),
|
||||
body: plugins.z
|
||||
.record(plugins.z.unknown())
|
||||
.optional()
|
||||
.describe('JSON body to send'),
|
||||
headers: plugins.z
|
||||
.record(plugins.z.string())
|
||||
.optional()
|
||||
.describe('Request headers'),
|
||||
}),
|
||||
execute: async ({
|
||||
url,
|
||||
body,
|
||||
headers,
|
||||
}: {
|
||||
url: string;
|
||||
body?: Record<string, unknown>;
|
||||
headers?: Record<string, string>;
|
||||
}) => {
|
||||
let req = plugins.smartrequest.default.create().url(url);
|
||||
if (headers) {
|
||||
req = req.headers(headers);
|
||||
}
|
||||
if (body) {
|
||||
req = req.json(body);
|
||||
}
|
||||
const response = await req.post();
|
||||
let responseBody: string;
|
||||
try {
|
||||
const json = await response.json();
|
||||
responseBody = JSON.stringify(json, null, 2);
|
||||
} catch {
|
||||
responseBody = await response.text();
|
||||
}
|
||||
return plugins.truncateOutput(`HTTP ${response.status}\n${responseBody}`).content;
|
||||
},
|
||||
}),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user