Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

agentool

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

agentool - npm Package Compare versions

Comparing version
1.4.1
to
1.4.2
+245
dist/chunk-7HFEO5BW.cjs
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
var _chunkKONXT2SFcjs = require('./chunk-KONXT2SF.cjs');
// src/output-validator/index.ts
var _ajv = require('ajv');
var _ai = require('ai');
var _crypto = require('crypto');
var _zod = require('zod');
// src/output-validator/content.ts
var invalidToolInputMarker = "__agentoolOutputValidatorInvalidInput";
var invalidToolInputFallback = {
content: "",
[invalidToolInputMarker]: true
};
function getContentInput(input, schemaId, schemaHash) {
if (input[invalidToolInputMarker] === true) {
return invalidContent(
schemaId,
schemaHash,
"required",
'The output_validator tool input must include a non-empty content string. Expected shape: output_validator({"content":"<full JSON document as a string>"}). Do not call output_validator({}).'
);
}
if (typeof input.content !== "string") {
return invalidContent(
schemaId,
schemaHash,
input.content === void 0 ? "required" : "type",
'The output_validator content parameter must be a string containing the full final JSON document. Expected shape: output_validator({"content":"<full JSON document as a string>"}).'
);
}
if (input.content.trim().length === 0) {
return invalidContent(
schemaId,
schemaHash,
"minLength",
"The output_validator content parameter must not be blank. Pass the full final JSON document as the content string."
);
}
return { ok: true, content: input.content };
}
function parseJsonContent(content, schemaId, schemaHash) {
try {
return { ok: true, value: JSON.parse(content) };
} catch (error) {
return {
ok: false,
result: {
valid: false,
schemaId,
schemaHash,
message: "Content is not valid JSON. Provide the corrected full JSON document as the content string and validate again.",
errors: [{
path: "/",
message: `Content is not valid JSON: ${_chunkKONXT2SFcjs.extractErrorMessage.call(void 0, error)}`,
keyword: "parse"
}]
}
};
}
}
function invalidContent(schemaId, schemaHash, keyword, message) {
return {
ok: false,
result: {
valid: false,
schemaId,
schemaHash,
message: "The output_validator tool was called without a valid content string. Call it again with the full final JSON document in the content parameter.",
errors: [{
path: "/content",
message,
keyword,
params: {
expected: 'output_validator({"content":"<full JSON document as a string>"})'
}
}]
}
};
}
// src/output-validator/prompt.ts
function getPrompt(config = {}) {
const schemaLine = config.schemaId ? `Configured schema id: ${config.schemaId}.` : "The schema is configured by the application when this tool is created.";
return `Validate the exact final JSON response content against the configured output schema.
${schemaLine}
## When to Use
- Before returning a final answer that must match a structured JSON output contract
- After drafting the complete final JSON response, with the exact response text as the content
- Again after fixing any validation errors returned by this tool
## Usage Guidelines
- Call this tool before the final answer whenever structured output validation is required for the current turn.
- Pass exactly one argument object with the exact final JSON response text in the content parameter: {"content":"<full JSON document as a string>"}.
- Do not call this tool with {}, and do not put the JSON document outside the content parameter.
- If validation fails, revise the response to address every returned error and validate again.
- Only return the final answer after this tool reports valid: true.
- The configured schema may change between turns, so rely on the current tool instance and result schema id/hash.`;
}
// src/output-validator/index.ts
function createOutputValidator(config = {}) {
const schemaHash = getSchemaHash(config.schema);
const schemaId = _nullishCoalesce(config.schemaId, () => ( getSchemaLabel(config.schema)));
const compiled = compileSchema(config);
return _ai.tool.call(void 0, {
description: _nullishCoalesce(config.description, () => ( getPrompt({ schemaId }))),
inputSchema: _zod.z.object({
content: _zod.z.string().min(1).describe("Exact final JSON response text to validate")
}).catch(invalidToolInputFallback),
execute: async (input) => {
try {
if (config.schema === void 0) {
return "Error [output-validator]: No schema configured. Provide a schema via createOutputValidator({ schema }).";
}
if ("error" in compiled) {
return `Error [output-validator]: Invalid configured schema: ${compiled.error}`;
}
const contentInput = getContentInput(
input,
schemaId,
schemaHash
);
if (!contentInput.ok) {
return stringifyResult(contentInput.result);
}
const parsed = parseJsonContent(
contentInput.content,
schemaId,
schemaHash
);
if (!parsed.ok) {
return stringifyResult(parsed.result);
}
const valid = compiled.validate(parsed.value);
if (valid) {
return stringifyResult({
valid: true,
schemaId,
schemaHash,
message: "Output matches the configured schema."
});
}
return stringifyResult({
valid: false,
schemaId,
schemaHash,
message: "Output does not match the configured schema. Revise the JSON to address every error, then call output_validator again with the corrected full JSON document as the content string.",
errors: formatAjvErrors(compiled.validate.errors)
});
} catch (error) {
const msg = _chunkKONXT2SFcjs.extractErrorMessage.call(void 0, error);
return `Error [output-validator]: ${msg}`;
}
}
});
}
var outputValidator = createOutputValidator();
function compileSchema(config) {
if (config.schema === void 0) {
return { error: "No schema configured." };
}
try {
const ajvOptions = config.ajvOptions;
const ajv = new (0, _ajv.Ajv)({
allErrors: true,
strict: false,
...ajvOptions
});
const validate = ajv.compile(config.schema);
if (validate.$async === true) {
return { error: "Async JSON Schemas are not supported." };
}
return { validate };
} catch (error) {
return { error: _chunkKONXT2SFcjs.extractErrorMessage.call(void 0, error) };
}
}
function formatAjvErrors(errors) {
return (_nullishCoalesce(errors, () => ( []))).map((error) => ({
path: getErrorPath(error),
message: _nullishCoalesce(error.message, () => ( `failed schema keyword "${error.keyword}"`)),
keyword: error.keyword,
schemaPath: error.schemaPath,
params: error.params
}));
}
function getErrorPath(error) {
if (error.keyword === "required") {
const missing = getMissingProperty(error.params);
if (missing) {
return appendJsonPointer(error.instancePath, missing);
}
}
return error.instancePath || "/";
}
function getMissingProperty(params) {
const missing = params.missingProperty;
return typeof missing === "string" && missing.length > 0 ? missing : void 0;
}
function appendJsonPointer(base, segment) {
const prefix = base && base !== "/" ? base : "";
return `${prefix}/${escapeJsonPointerSegment(segment)}`;
}
function escapeJsonPointerSegment(segment) {
return segment.replace(/~/g, "~0").replace(/\//g, "~1");
}
function getSchemaLabel(schema) {
if (!isRecord(schema)) {
return void 0;
}
for (const key of ["$id", "id", "title"]) {
const value = schema[key];
if (typeof value === "string" && value.trim().length > 0) {
return value;
}
}
return void 0;
}
function getSchemaHash(schema) {
if (schema === void 0) {
return void 0;
}
try {
return _crypto.createHash.call(void 0, "sha256").update(JSON.stringify(schema)).digest("hex").slice(0, 12);
} catch (e) {
return void 0;
}
}
function stringifyResult(result) {
return JSON.stringify(result, null, 2);
}
function isRecord(value) {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
exports.getPrompt = getPrompt; exports.createOutputValidator = createOutputValidator; exports.outputValidator = outputValidator;
import {
extractErrorMessage
} from "./chunk-X6ZY2KFU.js";
// src/output-validator/index.ts
import { Ajv } from "ajv";
import { tool } from "ai";
import { createHash } from "crypto";
import { z } from "zod";
// src/output-validator/content.ts
var invalidToolInputMarker = "__agentoolOutputValidatorInvalidInput";
var invalidToolInputFallback = {
content: "",
[invalidToolInputMarker]: true
};
function getContentInput(input, schemaId, schemaHash) {
if (input[invalidToolInputMarker] === true) {
return invalidContent(
schemaId,
schemaHash,
"required",
'The output_validator tool input must include a non-empty content string. Expected shape: output_validator({"content":"<full JSON document as a string>"}). Do not call output_validator({}).'
);
}
if (typeof input.content !== "string") {
return invalidContent(
schemaId,
schemaHash,
input.content === void 0 ? "required" : "type",
'The output_validator content parameter must be a string containing the full final JSON document. Expected shape: output_validator({"content":"<full JSON document as a string>"}).'
);
}
if (input.content.trim().length === 0) {
return invalidContent(
schemaId,
schemaHash,
"minLength",
"The output_validator content parameter must not be blank. Pass the full final JSON document as the content string."
);
}
return { ok: true, content: input.content };
}
function parseJsonContent(content, schemaId, schemaHash) {
try {
return { ok: true, value: JSON.parse(content) };
} catch (error) {
return {
ok: false,
result: {
valid: false,
schemaId,
schemaHash,
message: "Content is not valid JSON. Provide the corrected full JSON document as the content string and validate again.",
errors: [{
path: "/",
message: `Content is not valid JSON: ${extractErrorMessage(error)}`,
keyword: "parse"
}]
}
};
}
}
function invalidContent(schemaId, schemaHash, keyword, message) {
return {
ok: false,
result: {
valid: false,
schemaId,
schemaHash,
message: "The output_validator tool was called without a valid content string. Call it again with the full final JSON document in the content parameter.",
errors: [{
path: "/content",
message,
keyword,
params: {
expected: 'output_validator({"content":"<full JSON document as a string>"})'
}
}]
}
};
}
// src/output-validator/prompt.ts
function getPrompt(config = {}) {
const schemaLine = config.schemaId ? `Configured schema id: ${config.schemaId}.` : "The schema is configured by the application when this tool is created.";
return `Validate the exact final JSON response content against the configured output schema.
${schemaLine}
## When to Use
- Before returning a final answer that must match a structured JSON output contract
- After drafting the complete final JSON response, with the exact response text as the content
- Again after fixing any validation errors returned by this tool
## Usage Guidelines
- Call this tool before the final answer whenever structured output validation is required for the current turn.
- Pass exactly one argument object with the exact final JSON response text in the content parameter: {"content":"<full JSON document as a string>"}.
- Do not call this tool with {}, and do not put the JSON document outside the content parameter.
- If validation fails, revise the response to address every returned error and validate again.
- Only return the final answer after this tool reports valid: true.
- The configured schema may change between turns, so rely on the current tool instance and result schema id/hash.`;
}
// src/output-validator/index.ts
function createOutputValidator(config = {}) {
const schemaHash = getSchemaHash(config.schema);
const schemaId = config.schemaId ?? getSchemaLabel(config.schema);
const compiled = compileSchema(config);
return tool({
description: config.description ?? getPrompt({ schemaId }),
inputSchema: z.object({
content: z.string().min(1).describe("Exact final JSON response text to validate")
}).catch(invalidToolInputFallback),
execute: async (input) => {
try {
if (config.schema === void 0) {
return "Error [output-validator]: No schema configured. Provide a schema via createOutputValidator({ schema }).";
}
if ("error" in compiled) {
return `Error [output-validator]: Invalid configured schema: ${compiled.error}`;
}
const contentInput = getContentInput(
input,
schemaId,
schemaHash
);
if (!contentInput.ok) {
return stringifyResult(contentInput.result);
}
const parsed = parseJsonContent(
contentInput.content,
schemaId,
schemaHash
);
if (!parsed.ok) {
return stringifyResult(parsed.result);
}
const valid = compiled.validate(parsed.value);
if (valid) {
return stringifyResult({
valid: true,
schemaId,
schemaHash,
message: "Output matches the configured schema."
});
}
return stringifyResult({
valid: false,
schemaId,
schemaHash,
message: "Output does not match the configured schema. Revise the JSON to address every error, then call output_validator again with the corrected full JSON document as the content string.",
errors: formatAjvErrors(compiled.validate.errors)
});
} catch (error) {
const msg = extractErrorMessage(error);
return `Error [output-validator]: ${msg}`;
}
}
});
}
var outputValidator = createOutputValidator();
function compileSchema(config) {
if (config.schema === void 0) {
return { error: "No schema configured." };
}
try {
const ajvOptions = config.ajvOptions;
const ajv = new Ajv({
allErrors: true,
strict: false,
...ajvOptions
});
const validate = ajv.compile(config.schema);
if (validate.$async === true) {
return { error: "Async JSON Schemas are not supported." };
}
return { validate };
} catch (error) {
return { error: extractErrorMessage(error) };
}
}
function formatAjvErrors(errors) {
return (errors ?? []).map((error) => ({
path: getErrorPath(error),
message: error.message ?? `failed schema keyword "${error.keyword}"`,
keyword: error.keyword,
schemaPath: error.schemaPath,
params: error.params
}));
}
function getErrorPath(error) {
if (error.keyword === "required") {
const missing = getMissingProperty(error.params);
if (missing) {
return appendJsonPointer(error.instancePath, missing);
}
}
return error.instancePath || "/";
}
function getMissingProperty(params) {
const missing = params.missingProperty;
return typeof missing === "string" && missing.length > 0 ? missing : void 0;
}
function appendJsonPointer(base, segment) {
const prefix = base && base !== "/" ? base : "";
return `${prefix}/${escapeJsonPointerSegment(segment)}`;
}
function escapeJsonPointerSegment(segment) {
return segment.replace(/~/g, "~0").replace(/\//g, "~1");
}
function getSchemaLabel(schema) {
if (!isRecord(schema)) {
return void 0;
}
for (const key of ["$id", "id", "title"]) {
const value = schema[key];
if (typeof value === "string" && value.trim().length > 0) {
return value;
}
}
return void 0;
}
function getSchemaHash(schema) {
if (schema === void 0) {
return void 0;
}
try {
return createHash("sha256").update(JSON.stringify(schema)).digest("hex").slice(0, 12);
} catch {
return void 0;
}
}
function stringifyResult(result) {
return JSON.stringify(result, null, 2);
}
function isRecord(value) {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
export {
getPrompt,
createOutputValidator,
outputValidator
};
+2
-2

@@ -20,3 +20,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});

var _chunkYRUGHL6Scjs = require('./chunk-YRUGHL6S.cjs');
var _chunk7HFEO5BWcjs = require('./chunk-7HFEO5BW.cjs');

@@ -181,2 +181,2 @@

exports.askUser = _chunkKUFZFNPTcjs.askUser; exports.askUserPrompt = _chunkKUFZFNPTcjs.getPrompt; exports.bash = _chunkDKN6WTRYcjs.bash; exports.bashPrompt = _chunkDKN6WTRYcjs.getPrompt; exports.compactMessages = _chunkB76NYX22cjs.compactMessages; exports.createAskUser = _chunkKUFZFNPTcjs.createAskUser; exports.createBash = _chunkDKN6WTRYcjs.createBash; exports.createDiff = _chunkOYLTQJXTcjs.createDiff; exports.createEdit = _chunk6ULQG2W2cjs.createEdit; exports.createGlob = _chunkBNICFVN5cjs.createGlob; exports.createGrep = _chunkNRU2KZIMcjs.createGrep; exports.createHttpRequest = _chunk5T3SQYI4cjs.createHttpRequest; exports.createLsp = _chunkNQIV6LBHcjs.createLsp; exports.createMemory = _chunkLNAR3NJQcjs.createMemory; exports.createMultiEdit = _chunkVPV6WG5Vcjs.createMultiEdit; exports.createOutputValidator = _chunkYRUGHL6Scjs.createOutputValidator; exports.createRead = _chunkHG5T47NAcjs.createRead; exports.createSleep = _chunkJYTOARJVcjs.createSleep; exports.createTaskCreate = _chunkSFDZRLSXcjs.createTaskCreate; exports.createTaskGet = _chunkXGDE7S2Dcjs.createTaskGet; exports.createTaskList = _chunk3FT4ZPB2cjs.createTaskList; exports.createTaskUpdate = _chunkT6STO7PScjs.createTaskUpdate; exports.createToolSearch = _chunk2JBLVFB7cjs.createToolSearch; exports.createWebFetch = _chunkG6ZVJA4Vcjs.createWebFetch; exports.createWebSearch = _chunkCM3VRCNXcjs.createWebSearch; exports.createWrite = _chunkABXTBB2Ncjs.createWrite; exports.diff = _chunkOYLTQJXTcjs.diff; exports.diffPrompt = _chunkOYLTQJXTcjs.getPrompt; exports.edit = _chunk6ULQG2W2cjs.edit; exports.editPrompt = _chunk6ULQG2W2cjs.getPrompt; exports.glob = _chunkBNICFVN5cjs.glob; exports.globPrompt = _chunkBNICFVN5cjs.getPrompt; exports.grep = _chunkNRU2KZIMcjs.grep; exports.grepPrompt = _chunkNRU2KZIMcjs.getPrompt; exports.httpRequest = _chunk5T3SQYI4cjs.httpRequest; exports.httpRequestPrompt = _chunk5T3SQYI4cjs.getPrompt; exports.lsp = _chunkNQIV6LBHcjs.lsp; exports.lspPrompt = _chunkNQIV6LBHcjs.getPrompt; exports.memory = _chunkLNAR3NJQcjs.memory; exports.memoryPrompt = _chunkLNAR3NJQcjs.getPrompt; exports.multiEdit = _chunkVPV6WG5Vcjs.multiEdit; exports.multiEditPrompt = _chunkVPV6WG5Vcjs.getPrompt; exports.outputValidator = _chunkYRUGHL6Scjs.outputValidator; exports.outputValidatorPrompt = _chunkYRUGHL6Scjs.getPrompt; exports.read = _chunkHG5T47NAcjs.read; exports.readPrompt = _chunkHG5T47NAcjs.getPrompt; exports.sleep = _chunkJYTOARJVcjs.sleep; exports.sleepPrompt = _chunkJYTOARJVcjs.getPrompt; exports.taskCreate = _chunkSFDZRLSXcjs.taskCreate; exports.taskCreatePrompt = _chunkSFDZRLSXcjs.getPrompt; exports.taskGet = _chunkXGDE7S2Dcjs.taskGet; exports.taskGetPrompt = _chunkXGDE7S2Dcjs.getPrompt; exports.taskList = _chunk3FT4ZPB2cjs.taskList; exports.taskListPrompt = _chunk3FT4ZPB2cjs.getPrompt; exports.taskUpdate = _chunkT6STO7PScjs.taskUpdate; exports.taskUpdatePrompt = _chunkT6STO7PScjs.getPrompt; exports.toolSearch = _chunk2JBLVFB7cjs.toolSearch; exports.toolSearchPrompt = _chunk2JBLVFB7cjs.getPrompt; exports.webFetch = _chunkG6ZVJA4Vcjs.webFetch; exports.webFetchPrompt = _chunkG6ZVJA4Vcjs.getPrompt; exports.webSearch = _chunkCM3VRCNXcjs.webSearch; exports.webSearchPrompt = _chunkCM3VRCNXcjs.getPrompt; exports.write = _chunkABXTBB2Ncjs.write; exports.writePrompt = _chunkABXTBB2Ncjs.getPrompt;
exports.askUser = _chunkKUFZFNPTcjs.askUser; exports.askUserPrompt = _chunkKUFZFNPTcjs.getPrompt; exports.bash = _chunkDKN6WTRYcjs.bash; exports.bashPrompt = _chunkDKN6WTRYcjs.getPrompt; exports.compactMessages = _chunkB76NYX22cjs.compactMessages; exports.createAskUser = _chunkKUFZFNPTcjs.createAskUser; exports.createBash = _chunkDKN6WTRYcjs.createBash; exports.createDiff = _chunkOYLTQJXTcjs.createDiff; exports.createEdit = _chunk6ULQG2W2cjs.createEdit; exports.createGlob = _chunkBNICFVN5cjs.createGlob; exports.createGrep = _chunkNRU2KZIMcjs.createGrep; exports.createHttpRequest = _chunk5T3SQYI4cjs.createHttpRequest; exports.createLsp = _chunkNQIV6LBHcjs.createLsp; exports.createMemory = _chunkLNAR3NJQcjs.createMemory; exports.createMultiEdit = _chunkVPV6WG5Vcjs.createMultiEdit; exports.createOutputValidator = _chunk7HFEO5BWcjs.createOutputValidator; exports.createRead = _chunkHG5T47NAcjs.createRead; exports.createSleep = _chunkJYTOARJVcjs.createSleep; exports.createTaskCreate = _chunkSFDZRLSXcjs.createTaskCreate; exports.createTaskGet = _chunkXGDE7S2Dcjs.createTaskGet; exports.createTaskList = _chunk3FT4ZPB2cjs.createTaskList; exports.createTaskUpdate = _chunkT6STO7PScjs.createTaskUpdate; exports.createToolSearch = _chunk2JBLVFB7cjs.createToolSearch; exports.createWebFetch = _chunkG6ZVJA4Vcjs.createWebFetch; exports.createWebSearch = _chunkCM3VRCNXcjs.createWebSearch; exports.createWrite = _chunkABXTBB2Ncjs.createWrite; exports.diff = _chunkOYLTQJXTcjs.diff; exports.diffPrompt = _chunkOYLTQJXTcjs.getPrompt; exports.edit = _chunk6ULQG2W2cjs.edit; exports.editPrompt = _chunk6ULQG2W2cjs.getPrompt; exports.glob = _chunkBNICFVN5cjs.glob; exports.globPrompt = _chunkBNICFVN5cjs.getPrompt; exports.grep = _chunkNRU2KZIMcjs.grep; exports.grepPrompt = _chunkNRU2KZIMcjs.getPrompt; exports.httpRequest = _chunk5T3SQYI4cjs.httpRequest; exports.httpRequestPrompt = _chunk5T3SQYI4cjs.getPrompt; exports.lsp = _chunkNQIV6LBHcjs.lsp; exports.lspPrompt = _chunkNQIV6LBHcjs.getPrompt; exports.memory = _chunkLNAR3NJQcjs.memory; exports.memoryPrompt = _chunkLNAR3NJQcjs.getPrompt; exports.multiEdit = _chunkVPV6WG5Vcjs.multiEdit; exports.multiEditPrompt = _chunkVPV6WG5Vcjs.getPrompt; exports.outputValidator = _chunk7HFEO5BWcjs.outputValidator; exports.outputValidatorPrompt = _chunk7HFEO5BWcjs.getPrompt; exports.read = _chunkHG5T47NAcjs.read; exports.readPrompt = _chunkHG5T47NAcjs.getPrompt; exports.sleep = _chunkJYTOARJVcjs.sleep; exports.sleepPrompt = _chunkJYTOARJVcjs.getPrompt; exports.taskCreate = _chunkSFDZRLSXcjs.taskCreate; exports.taskCreatePrompt = _chunkSFDZRLSXcjs.getPrompt; exports.taskGet = _chunkXGDE7S2Dcjs.taskGet; exports.taskGetPrompt = _chunkXGDE7S2Dcjs.getPrompt; exports.taskList = _chunk3FT4ZPB2cjs.taskList; exports.taskListPrompt = _chunk3FT4ZPB2cjs.getPrompt; exports.taskUpdate = _chunkT6STO7PScjs.taskUpdate; exports.taskUpdatePrompt = _chunkT6STO7PScjs.getPrompt; exports.toolSearch = _chunk2JBLVFB7cjs.toolSearch; exports.toolSearchPrompt = _chunk2JBLVFB7cjs.getPrompt; exports.webFetch = _chunkG6ZVJA4Vcjs.webFetch; exports.webFetchPrompt = _chunkG6ZVJA4Vcjs.getPrompt; exports.webSearch = _chunkCM3VRCNXcjs.webSearch; exports.webSearchPrompt = _chunkCM3VRCNXcjs.getPrompt; exports.write = _chunkABXTBB2Ncjs.write; exports.writePrompt = _chunkABXTBB2Ncjs.getPrompt;

@@ -20,3 +20,3 @@ import {

outputValidator
} from "./chunk-3274NKQV.js";
} from "./chunk-N7JAWBCI.js";
import {

@@ -23,0 +23,0 @@ compactMessages

@@ -5,3 +5,3 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true});

var _chunkYRUGHL6Scjs = require('../chunk-YRUGHL6S.cjs');
var _chunk7HFEO5BWcjs = require('../chunk-7HFEO5BW.cjs');
require('../chunk-KONXT2SF.cjs');

@@ -12,2 +12,2 @@

exports.createOutputValidator = _chunkYRUGHL6Scjs.createOutputValidator; exports.outputValidator = _chunkYRUGHL6Scjs.outputValidator; exports.outputValidatorPrompt = _chunkYRUGHL6Scjs.getPrompt;
exports.createOutputValidator = _chunk7HFEO5BWcjs.createOutputValidator; exports.outputValidator = _chunk7HFEO5BWcjs.outputValidator; exports.outputValidatorPrompt = _chunk7HFEO5BWcjs.getPrompt;

@@ -5,3 +5,3 @@ import {

outputValidator
} from "../chunk-3274NKQV.js";
} from "../chunk-N7JAWBCI.js";
import "../chunk-X6ZY2KFU.js";

@@ -8,0 +8,0 @@ export {

{
"name": "agentool",
"version": "1.4.1",
"version": "1.4.2",
"type": "module",

@@ -5,0 +5,0 @@ "description": "22 AI agent tools + context-compaction helper as standalone Vercel AI SDK modules",

import {
extractErrorMessage
} from "./chunk-X6ZY2KFU.js";
// src/output-validator/index.ts
import { Ajv } from "ajv";
import { tool } from "ai";
import { createHash } from "crypto";
import { z } from "zod";
// src/output-validator/prompt.ts
function getPrompt(config = {}) {
const schemaLine = config.schemaId ? `Configured schema id: ${config.schemaId}.` : "The schema is configured by the application when this tool is created.";
return `Validate the exact final JSON response content against the configured output schema.
${schemaLine}
## When to Use
- Before returning a final answer that must match a structured JSON output contract
- After drafting the complete final JSON response, with the exact response text as the content
- Again after fixing any validation errors returned by this tool
## Usage Guidelines
- Call this tool before the final answer whenever structured output validation is required for the current turn.
- Pass the exact final JSON response text in the content parameter.
- If validation fails, revise the response to address every returned error and validate again.
- Only return the final answer after this tool reports valid: true.
- The configured schema may change between turns, so rely on the current tool instance and result schema id/hash.`;
}
// src/output-validator/index.ts
function createOutputValidator(config = {}) {
const schemaHash = getSchemaHash(config.schema);
const schemaId = config.schemaId ?? getSchemaLabel(config.schema);
const compiled = compileSchema(config);
return tool({
description: config.description ?? getPrompt({ schemaId }),
inputSchema: z.object({
content: z.string().describe("Exact final JSON response text to validate")
}),
execute: async ({ content }) => {
try {
if (config.schema === void 0) {
return "Error [output-validator]: No schema configured. Provide a schema via createOutputValidator({ schema }).";
}
if ("error" in compiled) {
return `Error [output-validator]: Invalid configured schema: ${compiled.error}`;
}
const parsed = parseJsonContent(content, schemaId, schemaHash);
if (!parsed.ok) {
return stringifyResult(parsed.result);
}
const valid = compiled.validate(parsed.value);
if (valid) {
return stringifyResult({
valid: true,
schemaId,
schemaHash,
message: "Output matches the configured schema."
});
}
return stringifyResult({
valid: false,
schemaId,
schemaHash,
errors: formatAjvErrors(compiled.validate.errors)
});
} catch (error) {
const msg = extractErrorMessage(error);
return `Error [output-validator]: ${msg}`;
}
}
});
}
var outputValidator = createOutputValidator();
function compileSchema(config) {
if (config.schema === void 0) {
return { error: "No schema configured." };
}
try {
const ajvOptions = config.ajvOptions;
const ajv = new Ajv({
allErrors: true,
strict: false,
...ajvOptions
});
const validate = ajv.compile(config.schema);
if (validate.$async === true) {
return { error: "Async JSON Schemas are not supported." };
}
return { validate };
} catch (error) {
return { error: extractErrorMessage(error) };
}
}
function parseJsonContent(content, schemaId, schemaHash) {
try {
return { ok: true, value: JSON.parse(content) };
} catch (error) {
const msg = extractErrorMessage(error);
return {
ok: false,
result: {
valid: false,
schemaId,
schemaHash,
errors: [
{
path: "/",
message: `Content is not valid JSON: ${msg}`,
keyword: "parse"
}
]
}
};
}
}
function formatAjvErrors(errors) {
return (errors ?? []).map((error) => ({
path: getErrorPath(error),
message: error.message ?? `failed schema keyword "${error.keyword}"`,
keyword: error.keyword,
schemaPath: error.schemaPath,
params: error.params
}));
}
function getErrorPath(error) {
if (error.keyword === "required") {
const missing = getMissingProperty(error.params);
if (missing) {
return appendJsonPointer(error.instancePath, missing);
}
}
return error.instancePath || "/";
}
function getMissingProperty(params) {
const missing = params.missingProperty;
return typeof missing === "string" && missing.length > 0 ? missing : void 0;
}
function appendJsonPointer(base, segment) {
const prefix = base && base !== "/" ? base : "";
return `${prefix}/${escapeJsonPointerSegment(segment)}`;
}
function escapeJsonPointerSegment(segment) {
return segment.replace(/~/g, "~0").replace(/\//g, "~1");
}
function getSchemaLabel(schema) {
if (!isRecord(schema)) {
return void 0;
}
for (const key of ["$id", "id", "title"]) {
const value = schema[key];
if (typeof value === "string" && value.trim().length > 0) {
return value;
}
}
return void 0;
}
function getSchemaHash(schema) {
if (schema === void 0) {
return void 0;
}
try {
return createHash("sha256").update(JSON.stringify(schema)).digest("hex").slice(0, 12);
} catch {
return void 0;
}
}
function stringifyResult(result) {
return JSON.stringify(result, null, 2);
}
function isRecord(value) {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
export {
getPrompt,
createOutputValidator,
outputValidator
};
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
var _chunkKONXT2SFcjs = require('./chunk-KONXT2SF.cjs');
// src/output-validator/index.ts
var _ajv = require('ajv');
var _ai = require('ai');
var _crypto = require('crypto');
var _zod = require('zod');
// src/output-validator/prompt.ts
function getPrompt(config = {}) {
const schemaLine = config.schemaId ? `Configured schema id: ${config.schemaId}.` : "The schema is configured by the application when this tool is created.";
return `Validate the exact final JSON response content against the configured output schema.
${schemaLine}
## When to Use
- Before returning a final answer that must match a structured JSON output contract
- After drafting the complete final JSON response, with the exact response text as the content
- Again after fixing any validation errors returned by this tool
## Usage Guidelines
- Call this tool before the final answer whenever structured output validation is required for the current turn.
- Pass the exact final JSON response text in the content parameter.
- If validation fails, revise the response to address every returned error and validate again.
- Only return the final answer after this tool reports valid: true.
- The configured schema may change between turns, so rely on the current tool instance and result schema id/hash.`;
}
// src/output-validator/index.ts
function createOutputValidator(config = {}) {
const schemaHash = getSchemaHash(config.schema);
const schemaId = _nullishCoalesce(config.schemaId, () => ( getSchemaLabel(config.schema)));
const compiled = compileSchema(config);
return _ai.tool.call(void 0, {
description: _nullishCoalesce(config.description, () => ( getPrompt({ schemaId }))),
inputSchema: _zod.z.object({
content: _zod.z.string().describe("Exact final JSON response text to validate")
}),
execute: async ({ content }) => {
try {
if (config.schema === void 0) {
return "Error [output-validator]: No schema configured. Provide a schema via createOutputValidator({ schema }).";
}
if ("error" in compiled) {
return `Error [output-validator]: Invalid configured schema: ${compiled.error}`;
}
const parsed = parseJsonContent(content, schemaId, schemaHash);
if (!parsed.ok) {
return stringifyResult(parsed.result);
}
const valid = compiled.validate(parsed.value);
if (valid) {
return stringifyResult({
valid: true,
schemaId,
schemaHash,
message: "Output matches the configured schema."
});
}
return stringifyResult({
valid: false,
schemaId,
schemaHash,
errors: formatAjvErrors(compiled.validate.errors)
});
} catch (error) {
const msg = _chunkKONXT2SFcjs.extractErrorMessage.call(void 0, error);
return `Error [output-validator]: ${msg}`;
}
}
});
}
var outputValidator = createOutputValidator();
function compileSchema(config) {
if (config.schema === void 0) {
return { error: "No schema configured." };
}
try {
const ajvOptions = config.ajvOptions;
const ajv = new (0, _ajv.Ajv)({
allErrors: true,
strict: false,
...ajvOptions
});
const validate = ajv.compile(config.schema);
if (validate.$async === true) {
return { error: "Async JSON Schemas are not supported." };
}
return { validate };
} catch (error) {
return { error: _chunkKONXT2SFcjs.extractErrorMessage.call(void 0, error) };
}
}
function parseJsonContent(content, schemaId, schemaHash) {
try {
return { ok: true, value: JSON.parse(content) };
} catch (error) {
const msg = _chunkKONXT2SFcjs.extractErrorMessage.call(void 0, error);
return {
ok: false,
result: {
valid: false,
schemaId,
schemaHash,
errors: [
{
path: "/",
message: `Content is not valid JSON: ${msg}`,
keyword: "parse"
}
]
}
};
}
}
function formatAjvErrors(errors) {
return (_nullishCoalesce(errors, () => ( []))).map((error) => ({
path: getErrorPath(error),
message: _nullishCoalesce(error.message, () => ( `failed schema keyword "${error.keyword}"`)),
keyword: error.keyword,
schemaPath: error.schemaPath,
params: error.params
}));
}
function getErrorPath(error) {
if (error.keyword === "required") {
const missing = getMissingProperty(error.params);
if (missing) {
return appendJsonPointer(error.instancePath, missing);
}
}
return error.instancePath || "/";
}
function getMissingProperty(params) {
const missing = params.missingProperty;
return typeof missing === "string" && missing.length > 0 ? missing : void 0;
}
function appendJsonPointer(base, segment) {
const prefix = base && base !== "/" ? base : "";
return `${prefix}/${escapeJsonPointerSegment(segment)}`;
}
function escapeJsonPointerSegment(segment) {
return segment.replace(/~/g, "~0").replace(/\//g, "~1");
}
function getSchemaLabel(schema) {
if (!isRecord(schema)) {
return void 0;
}
for (const key of ["$id", "id", "title"]) {
const value = schema[key];
if (typeof value === "string" && value.trim().length > 0) {
return value;
}
}
return void 0;
}
function getSchemaHash(schema) {
if (schema === void 0) {
return void 0;
}
try {
return _crypto.createHash.call(void 0, "sha256").update(JSON.stringify(schema)).digest("hex").slice(0, 12);
} catch (e) {
return void 0;
}
}
function stringifyResult(result) {
return JSON.stringify(result, null, 2);
}
function isRecord(value) {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
exports.getPrompt = getPrompt; exports.createOutputValidator = createOutputValidator; exports.outputValidator = outputValidator;