import { jsonRecord, optionalStringArray, stringValue } from "./jsonBoundary.js";
export function providerRecord(value) {
    const record = jsonRecord(value);
    if (record === undefined) {
        return { ok: false, message: "provider output must be an object" };
    }
    return { ok: true, output: record };
}
export function booleanField(record, field) {
    const value = record[field];
    return typeof value === "boolean" ? value : undefined;
}
export function finiteNumberField(record, field) {
    const value = record[field];
    return typeof value === "number" && Number.isFinite(value) ? value : undefined;
}
export function nonNegativeIntegerField(record, field) {
    const value = finiteNumberField(record, field);
    return value !== undefined && Number.isInteger(value) && value >= 0 ? value : undefined;
}
export function stringField(record, field) {
    return stringValue(record[field]);
}
export function stringArrayField(record, field) {
    if (record[field] === undefined) {
        return undefined;
    }
    const result = optionalStringArray(record[field]);
    if (!result.ok) {
        return undefined;
    }
    return result.values;
}
export function providerRejectedMessage(toolId) {
    return `${toolId} provider rejected the request`;
}
export function providerContractMessage(toolId) {
    return `${toolId} provider returned an invalid runtime-owned result`;
}
