"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RegistryController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const dto_1 = require("../dto");
const registry_service_1 = require("../service/registry.service");
const access_context_1 = require("../service/access-context");
let RegistryController = class RegistryController {
    registry;
    constructor(registry) {
        this.registry = registry;
    }
    async listSkills(query, tenantId, userId, userRole, authorization) {
        const framework = query.framework;
        const module = query.module;
        const visibility = query.visibility;
        const access = (0, access_context_1.resolveAccessContext)({
            authorization,
            tenantIdHeader: tenantId,
            userIdHeader: userId,
            userRoleHeader: userRole,
            requestedVisibility: visibility
        });
        (0, access_context_1.assertResolvePolicy)(access);
        return {
            skills: await this.registry.listSkills({
                framework,
                module,
                tenantId: access.tenantId,
                visibility,
                userId: access.userId,
                userRole: access.userRole
            })
        };
    }
    async getSkill(skillId, tenantId, userId, userRole, authorization) {
        const access = (0, access_context_1.resolveAccessContext)({
            authorization,
            tenantIdHeader: tenantId,
            userIdHeader: userId,
            userRoleHeader: userRole
        });
        const skill = await this.registry.getSkill(skillId, access.tenantId, access.userId, access.userRole);
        if (!skill) {
            throw new common_1.NotFoundException('skill not found');
        }
        return skill;
    }
    async resolve(body, tenantId, userId, userRole, authorization) {
        const access = (0, access_context_1.resolveAccessContext)({
            authorization,
            tenantIdHeader: body.tenantId ?? tenantId,
            userIdHeader: body.userId ?? userId,
            userRoleHeader: userRole,
            requestedVisibility: body.visibility
        });
        (0, access_context_1.assertResolvePolicy)(access);
        return await this.registry.resolveSkills({
            ...body,
            tenantId: access.tenantId,
            userId: access.userId,
            userRole: access.userRole
        });
    }
};
exports.RegistryController = RegistryController;
__decorate([
    (0, common_1.Get)('skills'),
    (0, swagger_1.ApiOperation)({ summary: '查询技能列表', description: '按框架、模块、可见性等条件查询可见技能。' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: '查询成功，返回技能列表。' }),
    __param(0, (0, common_1.Query)()),
    __param(1, (0, common_1.Headers)('x-tenant-id')),
    __param(2, (0, common_1.Headers)('x-user-id')),
    __param(3, (0, common_1.Headers)('x-user-role')),
    __param(4, (0, common_1.Headers)('authorization')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [dto_1.RegistryListSkillsQueryDto, String, String, String, String]),
    __metadata("design:returntype", Promise)
], RegistryController.prototype, "listSkills", null);
__decorate([
    (0, common_1.Get)('skills/:skillId'),
    (0, swagger_1.ApiOperation)({ summary: '查询单个技能', description: '根据技能 ID 查询技能定义。' }),
    (0, swagger_1.ApiResponse)({ status: 200, description: '查询成功，返回技能定义。' }),
    (0, swagger_1.ApiResponse)({ status: 404, description: '技能不存在。' }),
    __param(0, (0, common_1.Param)('skillId')),
    __param(1, (0, common_1.Headers)('x-tenant-id')),
    __param(2, (0, common_1.Headers)('x-user-id')),
    __param(3, (0, common_1.Headers)('x-user-role')),
    __param(4, (0, common_1.Headers)('authorization')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, String, String, String, String]),
    __metadata("design:returntype", Promise)
], RegistryController.prototype, "getSkill", null);
__decorate([
    (0, common_1.Post)('skills/resolve'),
    (0, swagger_1.ApiOperation)({ summary: '解析技能执行图', description: '将输入指令解析为运行时可执行技能 DAG。' }),
    (0, swagger_1.ApiBody)({
        description: '技能解析请求体',
        schema: {
            type: 'object',
            required: ['command'],
            properties: {
                tenantId: { type: 'string', description: '租户 ID（可选）' },
                userId: { type: 'string', description: '用户 ID（可选）' },
                visibility: { type: 'string', description: '技能可见性范围（可选）' },
                command: { type: 'object', description: '待解析的任务指令' }
            }
        }
    }),
    (0, swagger_1.ApiResponse)({ status: 201, description: '解析成功，返回技能 DAG。' }),
    __param(0, (0, common_1.Body)()),
    __param(1, (0, common_1.Headers)('x-tenant-id')),
    __param(2, (0, common_1.Headers)('x-user-id')),
    __param(3, (0, common_1.Headers)('x-user-role')),
    __param(4, (0, common_1.Headers)('authorization')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, String, String, String, String]),
    __metadata("design:returntype", Promise)
], RegistryController.prototype, "resolve", null);
exports.RegistryController = RegistryController = __decorate([
    (0, common_1.Controller)('registry'),
    (0, swagger_1.ApiTags)('智能体-技能注册表'),
    __metadata("design:paramtypes", [registry_service_1.RegistryService])
], RegistryController);
//# sourceMappingURL=registry.controller.js.map