"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.RuntimeController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const runtime_service_1 = require("../service/runtime.service");
const access_context_1 = require("../../registry/service/access-context");
let RuntimeController = class RuntimeController {
    runtime;
    constructor(runtime) {
        this.runtime = runtime;
    }
    async createTask(command, tenantId, userId, userRole, authorization) {
        const access = (0, access_context_1.resolveAccessContext)({
            authorization,
            tenantIdHeader: tenantId,
            userIdHeader: userId,
            userRoleHeader: userRole
        });
        return await this.runtime.createTask(command, access);
    }
    cancel(taskId) {
        const task = this.runtime.stopTask(taskId);
        if (!task) {
            throw new common_1.NotFoundException('task not found');
        }
        return task;
    }
    getTask(taskId) {
        const task = this.runtime.getTask(taskId);
        if (!task) {
            throw new common_1.NotFoundException('task not found');
        }
        return task;
    }
};
exports.RuntimeController = RuntimeController;
__decorate([
    (0, common_1.Post)('tasks'),
    (0, swagger_1.ApiOperation)({ summary: '创建运行任务', description: '根据解析后的任务指令启动运行时执行。' }),
    (0, swagger_1.ApiBody)({
        description: '创建运行任务请求体',
        schema: {
            type: 'object',
            required: ['name', 'input'],
            properties: {
                name: { type: 'string', description: '任务名称' },
                input: { type: 'object', description: '任务输入参数' }
            }
        }
    }),
    (0, swagger_1.ApiResponse)({ status: 201, description: '任务创建成功。' }),
    __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)
], RuntimeController.prototype, "createTask", null);
__decorate([
    (0, common_1.Post)('tasks/:taskId/cancel'),
    (0, swagger_1.ApiOperation)({ summary: '取消运行任务', description: '根据任务 ID 取消正在执行的任务。' }),
    (0, swagger_1.ApiResponse)({ status: 201, description: '取消成功，返回任务最新状态。' }),
    (0, swagger_1.ApiResponse)({ status: 404, description: '任务不存在。' }),
    __param(0, (0, common_1.Param)('taskId')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Object)
], RuntimeController.prototype, "cancel", null);
__decorate([
    (0, common_1.Get)('tasks/:taskId'),
    (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)('taskId')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String]),
    __metadata("design:returntype", Object)
], RuntimeController.prototype, "getTask", null);
exports.RuntimeController = RuntimeController = __decorate([
    (0, common_1.Controller)('runtime'),
    (0, swagger_1.ApiTags)('智能体-运行时'),
    __metadata("design:paramtypes", [runtime_service_1.RuntimeService])
], RuntimeController);
//# sourceMappingURL=runtime.controller.js.map