import { zodToJsonSchema } from 'zod-to-json-schema';
/**
 * Creates a CapabilityDefinition from a user-friendly options object.
 * Converts Zod schemas to JSON Schema for serializable metadata,
 * and wraps tool functions with context currying.
 */
export function defineCapability(options) {
    // Build serializable tool definitions from Zod schemas
    const toolDefs = options.tools.map((tool) => ({
        name: tool.name,
        description: tool.description,
        parameterSchema: zodToJsonSchema(tool.schema, {
            $refStrategy: 'none',
        }),
        ...(tool.internalBubbles ? { internalBubbles: tool.internalBubbles } : {}),
        ...(tool.requiresApproval
            ? { requiresApproval: tool.requiresApproval }
            : {}),
        ...(tool.masterTool ? { masterTool: tool.masterTool } : {}),
    }));
    // Build serializable metadata
    const metadata = {
        id: options.id,
        name: options.name,
        description: options.description,
        icon: options.icon,
        category: options.category,
        version: options.version ?? '1.0.0',
        requiredCredentials: options.requiredCredentials,
        optionalCredentials: options.optionalCredentials,
        inputs: options.inputs,
        tools: toolDefs,
        systemPromptAddition: typeof options.systemPrompt === 'string'
            ? options.systemPrompt
            : undefined,
        modelConfigOverride: options.modelConfigOverride,
        delegationHint: typeof options.delegationHint === 'string'
            ? options.delegationHint
            : undefined,
        hidden: options.hidden,
        providers: options.providers,
    };
    // Build tool factory that curries context into each tool func
    const createTools = (ctx) => {
        const toolFuncs = {};
        for (const tool of options.tools) {
            toolFuncs[tool.name] = tool.func(ctx);
        }
        return toolFuncs;
    };
    // Build system prompt factory
    const createSystemPrompt = typeof options.systemPrompt === 'function'
        ? options.systemPrompt
        : undefined;
    // Build delegation hint factory
    const createDelegationHint = typeof options.delegationHint === 'function'
        ? options.delegationHint
        : undefined;
    // Build response append factory
    const createResponseAppend = typeof options.responseAppend === 'function'
        ? options.responseAppend
        : typeof options.responseAppend === 'string'
            ? () => options.responseAppend
            : undefined;
    return {
        metadata,
        createTools,
        createSystemPrompt,
        createDelegationHint,
        createResponseAppend,
        hooks: options.hooks,
    };
}
//# sourceMappingURL=define-capability.js.map