import { anthropicSkillSummarizePractice } from "./anthropic.js";
import { deepmindSkillSummarizePractice } from "./deepmind.js";
import { openaiSkillSummarizePractice } from "./openai.js";
import { buildSkillBasePracticeAuditMetadata, createSkillBaseCoreHandler, createSkillBaseToolDefinition, injectRuntimeInvocationMetadata, jsonSchema } from "../_shared/baseToolAdapter.js";
import { executeSkillSummarize as executeSkillSummarizeCore } from "./core.js";
import { skillSummarizeDependencyDeclarations } from "./dependencies.js";
export { planSkillSummarize, skillSummarizeDescriptor, executeSkillSummarize as executeSkillSummarizeCore } from "./core.js";
const practices = [anthropicSkillSummarizePractice, openaiSkillSummarizePractice, deepmindSkillSummarizePractice];
function ordered(preferredProvider) {
    return preferredProvider === undefined ? practices : [...practices.filter((practice) => practice.providerName === preferredProvider), ...practices.filter((practice) => practice.providerName !== preferredProvider)];
}
export function selectSkillSummarizePractice(dependencies = {}) {
    for (const practice of ordered(dependencies.preferredProvider)) {
        const provider = practice.createProvider({ executor: dependencies.executor, provider: dependencies.provider });
        if (provider !== undefined)
            return { providerName: practice.providerName, practice, provider };
    }
    return { providerName: "praxis-native", practice: { providerName: "praxis-native", source: { kind: "praxis-native", label: "Praxis dry-run fallback", path: undefined }, directCliSupport: false, sideEffectPolicy: "read-only", notes: ["No runtime filesystem reader is available; extractive summaries from provided excerpts still work."], createProvider: () => undefined }, provider: undefined };
}
export async function executeSkillSummarize(request = {}) {
    const selection = selectSkillSummarizePractice(request);
    return executeSkillSummarizeCore({ ...request, provider: selection.provider, context: { ...request.context, auditMetadata: { ...(request.context?.auditMetadata ?? {}), ...buildSkillBasePracticeAuditMetadata({ providerName: selection.providerName, sourceLabel: selection.practice.source.label, sourceKind: selection.practice.source.kind, sourcePath: selection.practice.source.path, directCliSupport: selection.practice.directCliSupport, sideEffectPolicy: selection.practice.sideEffectPolicy, notes: selection.practice.notes }) } } });
}
export const skillSummarizeBaseToolDefinition = createSkillBaseToolDefinition({ toolId: "skill.summarize", title: "Skill Summarize", description: "Summarize local skill packages into model-visible metadata lines and concise bullets.", summary: "Use skill.summarize to produce budgeted skill metadata before activate/load.", riskLevel: "normal", permissionHints: ["skill:read"], dependencies: skillSummarizeDependencyDeclarations, inputSchema: jsonSchema("skill.summarize.input", { type: "object", additionalProperties: true }), outputSchema: jsonSchema("skill.summarize.output", { type: "object", additionalProperties: true }) });
export const skillSummarizeHandler = createSkillBaseCoreHandler(skillSummarizeBaseToolDefinition, async (request) => {
    const selection = selectSkillSummarizePractice({ ...request.input, executor: request.executor });
    return executeSkillSummarizeCore({ ...request.input, provider: selection.provider, context: { ...request.input.context, runtimeId: request.input.context?.runtimeId ?? request.runtimeId, sessionId: request.input.context?.sessionId ?? request.sessionId, invocationId: request.input.context?.invocationId ?? request.toolCallId, auditMetadata: injectRuntimeInvocationMetadata(buildSkillBasePracticeAuditMetadata({ providerName: selection.providerName, sourceLabel: selection.practice.source.label, sourceKind: selection.practice.source.kind, sourcePath: selection.practice.source.path, directCliSupport: selection.practice.directCliSupport, sideEffectPolicy: selection.practice.sideEffectPolicy, notes: selection.practice.notes }), request.input.context?.auditMetadata, request) } });
});
