const DISCOVERY_PLACEHOLDER_PREFIX = '__takt_discovery_param__';
const FACET_SECTION_BY_KIND = {
    knowledge: 'knowledge',
    policy: 'policies',
    instruction: 'instructions',
    report_format: 'report_formats',
};
function buildPlaceholderRef(paramName, kind) {
    return `${DISCOVERY_PLACEHOLDER_PREFIX}_${kind}_${paramName}`;
}
function buildPlaceholderContent(paramName, kind) {
    return `[discovery placeholder for ${kind} param "${paramName}"]`;
}
function ensurePlaceholderFacet(raw, paramName, kind) {
    const sectionKey = FACET_SECTION_BY_KIND[kind];
    const existingSection = raw[sectionKey] ?? {};
    const placeholderRef = buildPlaceholderRef(paramName, kind);
    raw[sectionKey] = {
        ...existingSection,
        [placeholderRef]: existingSection[placeholderRef] ?? buildPlaceholderContent(paramName, kind),
    };
    return placeholderRef;
}
export function prepareCallableSubworkflowDiscoveryArgs(raw) {
    if (raw.subworkflow?.callable !== true) {
        return { raw, callableArgs: undefined };
    }
    const params = raw.subworkflow.params;
    if (!params || Object.keys(params).length === 0) {
        return { raw, callableArgs: undefined };
    }
    const prepared = structuredClone(raw);
    const callableArgs = new Map();
    for (const [paramName, definition] of Object.entries(params)) {
        if (definition.default !== undefined) {
            callableArgs.set(paramName, definition.default);
            continue;
        }
        const placeholderRef = ensurePlaceholderFacet(prepared, paramName, definition.facet_kind);
        callableArgs.set(paramName, definition.type === 'facet_ref[]' ? [placeholderRef] : placeholderRef);
    }
    return {
        raw: prepared,
        callableArgs: Object.fromEntries(callableArgs),
    };
}
//# sourceMappingURL=workflowCallableDiscoveryArgs.js.map