UNPKG

n8n

Version:

n8n Workflow Automation Tool

818 lines 39.9 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); 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 __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); 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.AgentsController = void 0; const api_types_1 = require("@n8n/api-types"); const decorators_1 = require("@n8n/decorators"); const crypto_1 = require("crypto"); const credentials_service_1 = require("../../credentials/credentials.service"); const conflict_error_1 = require("../../errors/response-errors/conflict.error"); const not_found_error_1 = require("../../errors/response-errors/not-found.error"); const agents_credential_provider_1 = require("./adapters/agents-credential-provider"); const agent_execution_service_1 = require("./agent-execution.service"); const agent_message_mapper_1 = require("./agent-message-mapper"); const agent_sse_stream_1 = require("./agent-sse-stream"); const agents_service_1 = require("./agents.service"); const agents_builder_service_1 = require("./builder/agents-builder.service"); const builder_tool_names_1 = require("./builder/builder-tool-names"); const agent_chat_integration_1 = require("./integrations/agent-chat-integration"); const agent_schedule_service_1 = require("./integrations/agent-schedule.service"); const chat_integration_service_1 = require("./integrations/chat-integration.service"); const agent_repository_1 = require("./repositories/agent.repository"); function makeBuilderToolEvents(send) { let streamingToolName; return { toolInputStart: (name) => { streamingToolName = name; }, toolInputDelta: (_toolCallId, delta) => { if (streamingToolName === builder_tool_names_1.BUILDER_TOOLS.BUILD_CUSTOM_TOOL) { send({ type: 'code-delta', delta }); } }, toolResult: (name) => { if (name === builder_tool_names_1.BUILDER_TOOLS.WRITE_CONFIG || name === builder_tool_names_1.BUILDER_TOOLS.PATCH_CONFIG) { send({ type: 'config-updated' }); streamingToolName = undefined; } if (name === builder_tool_names_1.BUILDER_TOOLS.CREATE_SKILL) { send({ type: 'config-updated' }); streamingToolName = undefined; } if (name === builder_tool_names_1.BUILDER_TOOLS.BUILD_CUSTOM_TOOL) { send({ type: 'tool-updated' }); streamingToolName = undefined; } }, }; } let AgentsController = class AgentsController { constructor(agentsService, agentsBuilderService, credentialsService, chatIntegrationService, agentScheduleService, agentRepository, agentExecutionService, chatIntegrationRegistry) { this.agentsService = agentsService; this.agentsBuilderService = agentsBuilderService; this.credentialsService = credentialsService; this.chatIntegrationService = chatIntegrationService; this.agentScheduleService = agentScheduleService; this.agentRepository = agentRepository; this.agentExecutionService = agentExecutionService; this.chatIntegrationRegistry = chatIntegrationRegistry; } async create(req, _res, payload) { const { projectId } = req.params; return await this.agentsService.create(projectId, payload.name); } async list(req) { if (req.query.all === 'true') { return await this.agentsService.findByUser(req.user.id); } return await this.agentsService.findByProjectId(req.params.projectId); } async getConfig(req) { const { projectId, agentId } = req.params; return await this.agentsService.getConfig(agentId, projectId); } async putConfig(req, _res, agentId, payload) { const { projectId } = req.params; const { config } = payload; return await this.agentsService.updateConfig(agentId, projectId, config); } async deleteTool(req, _res, agentId, toolId) { const { projectId } = req.params; await this.agentsService.deleteCustomTool(agentId, projectId, toolId); return { ok: true }; } async listSkills(req) { const { projectId, agentId } = req.params; return await this.agentsService.listSkills(agentId, projectId); } async getSkill(req, _res, agentId, skillId) { const { projectId } = req.params; return await this.agentsService.getSkill(agentId, projectId, skillId); } async createSkill(req, _res, agentId, payload) { const { projectId } = req.params; const skill = { name: payload.name, description: payload.description, instructions: payload.instructions, }; return await this.agentsService.createAndAttachSkill(agentId, projectId, skill); } async updateSkill(req, _res, agentId, skillId, payload) { const { projectId } = req.params; return await this.agentsService.updateSkill(agentId, projectId, skillId, payload); } async deleteSkill(req, _res, agentId, skillId) { const { projectId } = req.params; await this.agentsService.deleteSkill(agentId, projectId, skillId); return { ok: true }; } async listCredentials(req) { const { projectId } = req.params; const credentialProvider = new agents_credential_provider_1.AgentsCredentialProvider(this.credentialsService, projectId, req.user); return await credentialProvider.list(); } async getModelCatalog() { const { fetchProviderCatalog } = await Promise.resolve().then(() => __importStar(require('@n8n/agents'))); return await fetchProviderCatalog(); } listIntegrations() { return this.agentsService.listChatIntegrations(); } async listThreads(req) { const limit = Math.min(Math.max(Number(req.query.limit) || 20, 1), 100); return await this.agentExecutionService.getThreads(req.params.projectId, limit, req.query.cursor, req.query.agentId); } async getThread(req) { const result = await this.agentExecutionService.getThreadDetail(req.params.threadId, req.params.projectId, req.query.agentId); if (!result) { throw new not_found_error_1.NotFoundError(`Thread "${req.params.threadId}" not found`); } return result; } async deleteThread(req) { const { projectId, threadId } = req.params; const deleted = await this.agentExecutionService.deleteThread(projectId, threadId); if (!deleted) { throw new not_found_error_1.NotFoundError(`Thread "${threadId}" not found`); } return { success: true }; } async get(req, _res, agentId) { const agent = await this.agentsService.findById(agentId, req.params.projectId); if (!agent) { throw new not_found_error_1.NotFoundError(`Agent "${agentId}" not found`); } return agent; } async update(req, _res, agentId, payload) { const { name, description } = payload; let agent = await this.agentsService.findById(agentId, req.params.projectId); if (!agent) { throw new not_found_error_1.NotFoundError(`Agent "${agentId}" not found`); } if (name !== undefined) { agent = await this.agentsService.updateName(agentId, req.params.projectId, name); } if (description !== undefined && agent) { const latestUpdatedAt = agent.updatedAt instanceof Date ? agent.updatedAt.toISOString() : agent.updatedAt; agent = await this.agentsService.updateDescription(agentId, req.params.projectId, description, latestUpdatedAt); } return agent; } async delete(req, _res, agentId) { const deleted = await this.agentsService.delete(agentId, req.params.projectId); if (!deleted) { throw new not_found_error_1.NotFoundError(`Agent "${agentId}" not found`); } return { success: true }; } async publish(req, _res, agentId) { return await this.agentsService.publishAgent(agentId, req.params.projectId, req.user.id); } async unpublish(req, _res, agentId) { return await this.agentsService.unpublishAgent(agentId, req.params.projectId); } async revertToPublished(req, _res, agentId) { return await this.agentsService.revertToPublishedAgent(agentId, req.params.projectId); } async chat(req, res, agentId, payload) { const { projectId } = req.params; const { message, sessionId } = payload; const credentialProvider = new agents_credential_provider_1.AgentsCredentialProvider(this.credentialsService, projectId, req.user); const { send } = (0, agent_sse_stream_1.initSseStream)(res); if (sessionId) { const existing = await this.agentExecutionService.findThreadById(sessionId); if (existing && !(0, agent_execution_service_1.threadBelongsTo)(existing, projectId, agentId)) { send({ type: 'error', message: 'Session not found' }); res.end(); return; } } const threadId = sessionId ?? (0, crypto_1.randomUUID)(); const { missing } = await this.agentsService.validateAgentIsRunnable(agentId, projectId, credentialProvider); if (missing.length > 0) { send({ type: 'error', message: 'This agent is not ready to run yet.', errorCode: 'agent_misconfigured', missing, }); res.end(); return; } try { await (0, agent_sse_stream_1.pumpChunks)(this.agentsService.executeForChat({ agentId, projectId, message, userId: req.user.id, memory: { threadId, resourceId: req.user.id }, }), send); send({ type: 'done', sessionId: threadId }); } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Chat failed'; send({ type: 'error', message: errorMessage }); } res.end(); } async getChatMessages(req) { const { projectId, agentId, threadId } = req.params; const agent = await this.agentsService.findById(agentId, projectId); if (!agent) throw new not_found_error_1.NotFoundError(`Agent "${agentId}" not found`); const thread = await this.agentExecutionService.findThreadById(threadId); if (!thread || !(0, agent_execution_service_1.threadBelongsTo)(thread, projectId, agentId)) { throw new not_found_error_1.NotFoundError(`Thread "${threadId}" not found`); } return await this.agentsService.getChatMessages(threadId); } async getBuilderMessages(req) { const { projectId, agentId } = req.params; const agent = await this.agentsService.findById(agentId, projectId); if (!agent) throw new not_found_error_1.NotFoundError(`Agent "${agentId}" not found`); const memory = await this.agentsBuilderService.getBuilderMessages(agentId); const checkpoint = await this.agentsBuilderService.findOpenCheckpoint(agentId); const openSuspensions = Object.values(checkpoint?.pendingToolCalls ?? {}) .filter((tc) => tc.suspended) .map((tc) => ({ toolCallId: tc.toolCallId, runId: tc.runId, })); let messages; if (!checkpoint) { messages = (0, agent_message_mapper_1.messagesToDto)(memory); } else { const memoryIds = new Set(memory.map((m) => m.id)); const newFromCheckpoint = checkpoint.messageList.messages.filter((m) => !memoryIds.has(m.id)); messages = (0, agent_message_mapper_1.messagesToDto)([...memory, ...newFromCheckpoint]); } return { messages, openSuspensions }; } async clearBuilderMessages(req) { const { projectId, agentId } = req.params; const agent = await this.agentsService.findById(agentId, projectId); if (!agent) throw new not_found_error_1.NotFoundError(`Agent "${agentId}" not found`); await this.agentsBuilderService.clearBuilderMessages(agentId); return { ok: true }; } async getTestChatMessages(req) { const { projectId, agentId } = req.params; const agent = await this.agentsService.findById(agentId, projectId); if (!agent) throw new not_found_error_1.NotFoundError(`Agent "${agentId}" not found`); const messages = await this.agentsService.getTestChatMessages(agentId, req.user.id); return (0, agent_message_mapper_1.messagesToDto)(messages); } async clearTestChatMessages(req) { const { projectId, agentId } = req.params; const agent = await this.agentsService.findById(agentId, projectId); if (!agent) throw new not_found_error_1.NotFoundError(`Agent "${agentId}" not found`); await this.agentsService.clearTestChatMessages(agentId, req.user.id); return { ok: true }; } async build(req, res, agentId, payload) { const { projectId } = req.params; const { message } = payload; const agent = await this.agentsService.findById(agentId, projectId); if (!agent) throw new not_found_error_1.NotFoundError(`Agent "${agentId}" not found`); const credentialProvider = new agents_credential_provider_1.AgentsCredentialProvider(this.credentialsService, projectId, req.user); const { send } = (0, agent_sse_stream_1.initSseStream)(res); try { const suspended = await (0, agent_sse_stream_1.pumpChunks)(this.agentsBuilderService.buildAgent(agentId, projectId, message, credentialProvider, req.user), send, makeBuilderToolEvents(send)); if (!suspended) { send({ type: 'done' }); } } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Build failed'; const errorCode = error && typeof error === 'object' && 'code' in error ? error.code : undefined; send({ type: 'error', message: errorMessage, ...(typeof errorCode === 'string' ? { code: errorCode } : {}), }); } res.end(); } async buildResume(req, res, agentId, payload) { const { projectId } = req.params; const { runId, toolCallId, resumeData } = payload; const agent = await this.agentsService.findById(agentId, projectId); if (!agent) throw new not_found_error_1.NotFoundError(`Agent "${agentId}" not found`); const credentialProvider = new agents_credential_provider_1.AgentsCredentialProvider(this.credentialsService, projectId, req.user); const { send } = (0, agent_sse_stream_1.initSseStream)(res); try { const suspended = await (0, agent_sse_stream_1.pumpChunks)(this.agentsBuilderService.resumeBuild(agentId, projectId, runId, toolCallId, resumeData, credentialProvider, req.user), send, makeBuilderToolEvents(send)); if (!suspended) { send({ type: 'done' }); } } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Resume failed'; send({ type: 'error', message: errorMessage }); } res.end(); } async connectIntegration(req, _res, agentId, payload) { const { type, credentialId } = payload; const agent = await this.agentRepository.findByIdAndProjectId(agentId, req.params.projectId); if (!agent) throw new not_found_error_1.NotFoundError(`Agent "${agentId}" not found`); if (!agent.publishedVersion) throw new conflict_error_1.ConflictError(`Agent "${agentId}" must be published before connecting an integration`); const usableCredentials = await this.credentialsService.getCredentialsAUserCanUseInAWorkflow(req.user, { projectId: agent.projectId }); const credential = usableCredentials.find((c) => c.id === credentialId); if (!credential) throw new not_found_error_1.NotFoundError(`Credential "${credentialId}" not found`); await this.chatIntegrationService.connect(agentId, credentialId, type, req.user.id, agent.projectId); const existing = agent.integrations ?? []; const alreadyExists = existing.some((i) => (0, api_types_1.isAgentCredentialIntegration)(i) && i.type === type && i.credentialId === credentialId); if (!alreadyExists) { agent.integrations = [...existing, { type, credentialId, credentialName: credential.name }]; await this.agentRepository.save(agent); } await this.chatIntegrationService.broadcastIntegrationChange(agentId, type, credentialId, 'connect'); return { status: 'connected' }; } async disconnectIntegration(req, _res, agentId, payload) { const { type, credentialId } = payload; const agent = await this.agentRepository.findByIdAndProjectId(agentId, req.params.projectId); if (!agent) throw new not_found_error_1.NotFoundError(`Agent "${agentId}" not found`); await this.chatIntegrationService.disconnect(agentId, type, credentialId); agent.integrations = (agent.integrations ?? []).filter((i) => !(0, api_types_1.isAgentCredentialIntegration)(i) || i.type !== type || i.credentialId !== credentialId); await this.agentRepository.save(agent); await this.chatIntegrationService.broadcastIntegrationChange(agentId, type, credentialId, 'disconnect'); return { status: 'disconnected' }; } async getScheduleIntegration(req, _res, agentId) { const agent = await this.agentRepository.findByIdAndProjectId(agentId, req.params.projectId); if (!agent) throw new not_found_error_1.NotFoundError(`Agent "${agentId}" not found`); return this.agentScheduleService.getConfig(agent); } async updateScheduleIntegration(req, _res, agentId, payload) { const agent = await this.agentRepository.findByIdAndProjectId(agentId, req.params.projectId); if (!agent) throw new not_found_error_1.NotFoundError(`Agent "${agentId}" not found`); return await this.agentScheduleService.saveConfig(agent, payload.cronExpression, payload.wakeUpPrompt); } async activateScheduleIntegration(req, _res, agentId) { const agent = await this.agentRepository.findByIdAndProjectId(agentId, req.params.projectId); if (!agent) throw new not_found_error_1.NotFoundError(`Agent "${agentId}" not found`); return await this.agentScheduleService.activate(agent); } async deactivateScheduleIntegration(req, _res, agentId) { const agent = await this.agentRepository.findByIdAndProjectId(agentId, req.params.projectId); if (!agent) throw new not_found_error_1.NotFoundError(`Agent "${agentId}" not found`); return await this.agentScheduleService.deactivate(agent); } async integrationStatus(req, _res, agentId) { const agent = await this.agentRepository.findByIdAndProjectId(agentId, req.params.projectId); if (!agent) throw new not_found_error_1.NotFoundError(`Agent "${agentId}" not found`); const chatStatus = this.chatIntegrationService.getStatus(agentId); const schedule = this.agentScheduleService.getConfig(agent); const scheduleIntegrations = schedule.active ? [{ type: api_types_1.AGENT_SCHEDULE_TRIGGER_TYPE }] : []; const connectedIntegrations = [...chatStatus.integrations, ...scheduleIntegrations]; return { status: connectedIntegrations.length > 0 ? 'connected' : 'disconnected', integrations: connectedIntegrations, }; } async handleWebhook(req, res) { const { agentId, platform } = req.params; const webhookHandler = this.chatIntegrationService.getWebhookHandler(agentId, platform); if (!webhookHandler) { const integration = this.chatIntegrationRegistry.get(platform); const earlyResponse = integration?.handleUnauthenticatedWebhook?.(req.body); if (earlyResponse) { res.status(earlyResponse.status).json(earlyResponse.body); return; } res.status(404).json({ error: `No active ${platform} integration for agent "${agentId}"` }); return; } const forwardedProto = req.headers['x-forwarded-proto']; const protocol = (Array.isArray(forwardedProto) ? forwardedProto[0] : forwardedProto) ?? req.protocol; const forwardedHost = req.headers['x-forwarded-host']; const host = (Array.isArray(forwardedHost) ? forwardedHost[0] : forwardedHost) ?? req.headers.host ?? 'localhost'; const url = `${protocol}://${host}${req.originalUrl}`; let requestBody; if (req.method !== 'GET' && req.method !== 'HEAD') { const rawBody = req.rawBody; if (rawBody) { requestBody = rawBody.toString('utf-8'); } else if (req.headers['content-type']?.includes('application/json')) { requestBody = JSON.stringify(req.body); } else if (req.headers['content-type']?.includes('application/x-www-form-urlencoded')) { requestBody = new URLSearchParams(req.body).toString(); } else { requestBody = JSON.stringify(req.body); } } const sanitizedHeaders = {}; for (const [key, value] of Object.entries(req.headers)) { if (typeof value === 'string') { sanitizedHeaders[key] = value; } else if (Array.isArray(value)) { sanitizedHeaders[key] = value.join(', '); } } const webRequest = new globalThis.Request(url, { method: req.method, headers: sanitizedHeaders, body: requestBody, }); const backgroundTasks = []; const waitUntil = (task) => { backgroundTasks.push(task.catch((error) => { console.warn('[AgentsController] Background task failed:', error instanceof Error ? error.message : String(error)); })); }; const webResponse = await webhookHandler(webRequest, { waitUntil }); res.status(webResponse.status); webResponse.headers.forEach((value, key) => { res.setHeader(key, value); }); const body = await webResponse.text(); res.send(body); } }; exports.AgentsController = AgentsController; __decorate([ (0, decorators_1.Post)('/'), (0, decorators_1.ProjectScope)('agent:create'), __param(2, decorators_1.Body), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, api_types_1.CreateAgentDto]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "create", null); __decorate([ (0, decorators_1.Get)('/'), (0, decorators_1.ProjectScope)('agent:list'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "list", null); __decorate([ (0, decorators_1.Get)('/:agentId/config'), (0, decorators_1.ProjectScope)('agent:read'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "getConfig", null); __decorate([ (0, decorators_1.Put)('/:agentId/config'), (0, decorators_1.ProjectScope)('agent:update'), __param(2, (0, decorators_1.Param)('agentId')), __param(3, decorators_1.Body), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String, api_types_1.UpdateAgentConfigDto]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "putConfig", null); __decorate([ (0, decorators_1.Delete)('/:agentId/tools/:toolId'), (0, decorators_1.ProjectScope)('agent:update'), __param(2, (0, decorators_1.Param)('agentId')), __param(3, (0, decorators_1.Param)('toolId')), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String, String]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "deleteTool", null); __decorate([ (0, decorators_1.Get)('/:agentId/skills'), (0, decorators_1.ProjectScope)('agent:read'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "listSkills", null); __decorate([ (0, decorators_1.Get)('/:agentId/skills/:skillId'), (0, decorators_1.ProjectScope)('agent:read'), __param(2, (0, decorators_1.Param)('agentId')), __param(3, (0, decorators_1.Param)('skillId')), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String, String]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "getSkill", null); __decorate([ (0, decorators_1.Post)('/:agentId/skills'), (0, decorators_1.ProjectScope)('agent:update'), __param(2, (0, decorators_1.Param)('agentId')), __param(3, decorators_1.Body), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String, api_types_1.CreateAgentSkillDto]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "createSkill", null); __decorate([ (0, decorators_1.Patch)('/:agentId/skills/:skillId'), (0, decorators_1.ProjectScope)('agent:update'), __param(2, (0, decorators_1.Param)('agentId')), __param(3, (0, decorators_1.Param)('skillId')), __param(4, decorators_1.Body), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String, String, api_types_1.UpdateAgentSkillDto]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "updateSkill", null); __decorate([ (0, decorators_1.Delete)('/:agentId/skills/:skillId'), (0, decorators_1.ProjectScope)('agent:update'), __param(2, (0, decorators_1.Param)('agentId')), __param(3, (0, decorators_1.Param)('skillId')), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String, String]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "deleteSkill", null); __decorate([ (0, decorators_1.Get)('/:agentId/credentials'), (0, decorators_1.ProjectScope)('agent:read'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "listCredentials", null); __decorate([ (0, decorators_1.Get)('/catalog/models'), (0, decorators_1.ProjectScope)('agent:read'), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], AgentsController.prototype, "getModelCatalog", null); __decorate([ (0, decorators_1.Get)('/catalog/integrations'), (0, decorators_1.ProjectScope)('agent:read'), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Array) ], AgentsController.prototype, "listIntegrations", null); __decorate([ (0, decorators_1.Get)('/threads'), (0, decorators_1.ProjectScope)('agent:read'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "listThreads", null); __decorate([ (0, decorators_1.Get)('/threads/:threadId'), (0, decorators_1.ProjectScope)('agent:read'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "getThread", null); __decorate([ (0, decorators_1.Delete)('/threads/:threadId'), (0, decorators_1.ProjectScope)('agent:update'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "deleteThread", null); __decorate([ (0, decorators_1.Get)('/:agentId'), (0, decorators_1.ProjectScope)('agent:read'), __param(2, (0, decorators_1.Param)('agentId')), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "get", null); __decorate([ (0, decorators_1.Patch)('/:agentId'), (0, decorators_1.ProjectScope)('agent:update'), __param(2, (0, decorators_1.Param)('agentId')), __param(3, decorators_1.Body), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String, api_types_1.UpdateAgentDto]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "update", null); __decorate([ (0, decorators_1.Delete)('/:agentId'), (0, decorators_1.ProjectScope)('agent:delete'), __param(2, (0, decorators_1.Param)('agentId')), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "delete", null); __decorate([ (0, decorators_1.Post)('/:agentId/publish'), (0, decorators_1.ProjectScope)('agent:publish'), __param(2, (0, decorators_1.Param)('agentId')), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "publish", null); __decorate([ (0, decorators_1.Post)('/:agentId/unpublish'), (0, decorators_1.ProjectScope)('agent:unpublish'), __param(2, (0, decorators_1.Param)('agentId')), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "unpublish", null); __decorate([ (0, decorators_1.Post)('/:agentId/revert-to-published'), (0, decorators_1.ProjectScope)('agent:update'), __param(2, (0, decorators_1.Param)('agentId')), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "revertToPublished", null); __decorate([ (0, decorators_1.Post)('/:agentId/chat', { usesTemplates: true }), (0, decorators_1.ProjectScope)('agent:execute'), __param(2, (0, decorators_1.Param)('agentId')), __param(3, decorators_1.Body), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String, api_types_1.AgentChatMessageDto]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "chat", null); __decorate([ (0, decorators_1.Get)('/:agentId/chat/:threadId/messages'), (0, decorators_1.ProjectScope)('agent:read'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "getChatMessages", null); __decorate([ (0, decorators_1.Get)('/:agentId/build/messages'), (0, decorators_1.ProjectScope)('agent:read'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "getBuilderMessages", null); __decorate([ (0, decorators_1.Delete)('/:agentId/build/messages'), (0, decorators_1.ProjectScope)('agent:update'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "clearBuilderMessages", null); __decorate([ (0, decorators_1.Get)('/:agentId/chat/messages'), (0, decorators_1.ProjectScope)('agent:read'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "getTestChatMessages", null); __decorate([ (0, decorators_1.Delete)('/:agentId/chat/messages'), (0, decorators_1.ProjectScope)('agent:update'), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "clearTestChatMessages", null); __decorate([ (0, decorators_1.Post)('/:agentId/build', { usesTemplates: true }), (0, decorators_1.ProjectScope)('agent:update'), __param(2, (0, decorators_1.Param)('agentId')), __param(3, decorators_1.Body), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String, api_types_1.AgentChatMessageDto]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "build", null); __decorate([ (0, decorators_1.Post)('/:agentId/build/resume', { usesTemplates: true }), (0, decorators_1.ProjectScope)('agent:update'), __param(2, (0, decorators_1.Param)('agentId')), __param(3, decorators_1.Body), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String, api_types_1.AgentBuildResumeDto]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "buildResume", null); __decorate([ (0, decorators_1.Post)('/:agentId/integrations/connect'), (0, decorators_1.ProjectScope)('agent:update'), __param(2, (0, decorators_1.Param)('agentId')), __param(3, decorators_1.Body), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String, api_types_1.AgentIntegrationDto]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "connectIntegration", null); __decorate([ (0, decorators_1.Post)('/:agentId/integrations/disconnect'), (0, decorators_1.ProjectScope)('agent:update'), __param(2, (0, decorators_1.Param)('agentId')), __param(3, decorators_1.Body), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String, api_types_1.AgentIntegrationDto]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "disconnectIntegration", null); __decorate([ (0, decorators_1.Get)('/:agentId/integrations/schedule'), (0, decorators_1.ProjectScope)('agent:read'), __param(2, (0, decorators_1.Param)('agentId')), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "getScheduleIntegration", null); __decorate([ (0, decorators_1.Put)('/:agentId/integrations/schedule'), (0, decorators_1.ProjectScope)('agent:update'), __param(2, (0, decorators_1.Param)('agentId')), __param(3, decorators_1.Body), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String, api_types_1.UpdateAgentScheduleDto]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "updateScheduleIntegration", null); __decorate([ (0, decorators_1.Post)('/:agentId/integrations/schedule/activate'), (0, decorators_1.ProjectScope)('agent:update'), __param(2, (0, decorators_1.Param)('agentId')), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "activateScheduleIntegration", null); __decorate([ (0, decorators_1.Post)('/:agentId/integrations/schedule/deactivate'), (0, decorators_1.ProjectScope)('agent:update'), __param(2, (0, decorators_1.Param)('agentId')), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "deactivateScheduleIntegration", null); __decorate([ (0, decorators_1.Get)('/:agentId/integrations/status'), (0, decorators_1.ProjectScope)('agent:read'), __param(2, (0, decorators_1.Param)('agentId')), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object, String]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "integrationStatus", null); __decorate([ (0, decorators_1.Post)('/:agentId/webhooks/:platform', { skipAuth: true, allowBots: true }), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", Promise) ], AgentsController.prototype, "handleWebhook", null); exports.AgentsController = AgentsController = __decorate([ (0, decorators_1.RestController)('/projects/:projectId/agents/v2'), __metadata("design:paramtypes", [agents_service_1.AgentsService, agents_builder_service_1.AgentsBuilderService, credentials_service_1.CredentialsService, chat_integration_service_1.ChatIntegrationService, agent_schedule_service_1.AgentScheduleService, agent_repository_1.AgentRepository, agent_execution_service_1.AgentExecutionService, agent_chat_integration_1.ChatIntegrationRegistry]) ], AgentsController); //# sourceMappingURL=agents.controller.js.map