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:
2026-03-06 11:39:01 +00:00
parent 903de44644
commit f9a9c9fb48
36 changed files with 3928 additions and 6586 deletions

53
ts_tools/tool.json.ts Normal file
View File

@@ -0,0 +1,53 @@
import * as plugins from './plugins.js';
export function jsonTool(): plugins.ToolSet {
return {
json_validate: plugins.tool({
description:
'Validate a JSON string and optionally check for required fields.',
inputSchema: plugins.z.object({
jsonString: plugins.z.string().describe('JSON string to validate'),
requiredFields: plugins.z
.array(plugins.z.string())
.optional()
.describe('Fields that must exist at the top level'),
}),
execute: async ({
jsonString,
requiredFields,
}: {
jsonString: string;
requiredFields?: string[];
}) => {
try {
const parsed = JSON.parse(jsonString);
if (requiredFields?.length) {
const missing = requiredFields.filter((f) => !(f in parsed));
if (missing.length) {
return `Invalid: missing required fields: ${missing.join(', ')}`;
}
}
const type = Array.isArray(parsed) ? 'array' : typeof parsed;
return `Valid JSON (${type})`;
} catch (e) {
return `Invalid JSON: ${(e as Error).message}`;
}
},
}),
json_transform: plugins.tool({
description: 'Parse a JSON string and return it pretty-printed.',
inputSchema: plugins.z.object({
jsonString: plugins.z.string().describe('JSON string to format'),
}),
execute: async ({ jsonString }: { jsonString: string }) => {
try {
const parsed = JSON.parse(jsonString);
return JSON.stringify(parsed, null, 2);
} catch (e) {
return `Error parsing JSON: ${(e as Error).message}`;
}
},
}),
};
}