UNPKG

n8n

Version:

n8n Workflow Automation Tool

66 lines 3.46 kB
"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); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AgentThreadsController = void 0; const decorators_1 = require("@n8n/decorators"); const not_found_error_1 = require("../../errors/response-errors/not-found.error"); const agent_execution_service_1 = require("./agent-execution.service"); let AgentThreadsController = class AgentThreadsController { constructor(agentExecutionService) { this.agentExecutionService = agentExecutionService; } async listThreads(req) { const limit = Math.min(Math.max(Number(req.query.limit) || 20, 1), 100); return await this.agentExecutionService.getThreads(req.params.projectId, req.params.agentId, limit, req.query.cursor); } async getThread(req) { const result = await this.agentExecutionService.getThreadDetail(req.params.threadId, req.params.projectId, req.params.agentId); if (!result) { throw new not_found_error_1.NotFoundError(`Thread "${req.params.threadId}" not found`); } return result; } async deleteThread(req) { const { projectId, agentId, threadId } = req.params; const deleted = await this.agentExecutionService.deleteThread(projectId, agentId, threadId); if (!deleted) { throw new not_found_error_1.NotFoundError(`Thread "${threadId}" not found`); } return { success: true }; } }; exports.AgentThreadsController = AgentThreadsController; __decorate([ (0, decorators_1.Get)('/:agentId/threads'), (0, decorators_1.ProjectScope)('agent:read'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AgentThreadsController.prototype, "listThreads", null); __decorate([ (0, decorators_1.Get)('/:agentId/threads/:threadId'), (0, decorators_1.ProjectScope)('agent:read'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AgentThreadsController.prototype, "getThread", null); __decorate([ (0, decorators_1.Delete)('/:agentId/threads/:threadId'), (0, decorators_1.ProjectScope)('agent:update'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AgentThreadsController.prototype, "deleteThread", null); exports.AgentThreadsController = AgentThreadsController = __decorate([ (0, decorators_1.RestController)('/projects/:projectId/agents/v2'), __metadata("design:paramtypes", [agent_execution_service_1.AgentExecutionService]) ], AgentThreadsController); //# sourceMappingURL=agent-threads.controller.js.map