dist / toolBudget.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.compactToolDescriptions = compactToolDescriptions;
// Shorten prose only under context pressure; executable constraints and stored values stay exact.
function compactToolDescriptions(tools) {
    const shorten = (text, max) => text.length > max ? text.slice(0, max) + "…" : text;
    const schema = (value) => Array.isArray(value) ? value.map(schema) : value && typeof value === "object" ?
        Object.fromEntries(Object.entries(value).map(([key, child]) => [key,
            ["enum", "const", "default", "examples"].includes(key) ? child : key === "description" && typeof child === "string" ? shorten(child, 160) : schema(child)])) : value;
    return tools.map(tool => ({ type: "function", function: { ...tool.function,
            ...(tool.function.description ? { description: shorten(tool.function.description, 320) } : {}),
            ...(tool.function.parameters ? { parameters: schema(tool.function.parameters) } : {}),
        } }));
}