@agentforge-io/nest 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (255) hide show
  1. package/README.md +486 -0
  2. package/dist/agent-forge.module.d.ts +21 -0
  3. package/dist/agent-forge.module.js +144 -0
  4. package/dist/agent-forge.module.js.map +1 -0
  5. package/dist/auth/current-user.decorator.d.ts +8 -0
  6. package/dist/auth/current-user.decorator.js +9 -0
  7. package/dist/auth/current-user.decorator.js.map +1 -0
  8. package/dist/auth/public.decorator.d.ts +2 -0
  9. package/dist/auth/public.decorator.js +8 -0
  10. package/dist/auth/public.decorator.js.map +1 -0
  11. package/dist/constants.d.ts +2 -0
  12. package/dist/constants.js +9 -0
  13. package/dist/constants.js.map +1 -0
  14. package/dist/core/agent-runner.service.d.ts +1 -0
  15. package/dist/core/agent-runner.service.js +6 -0
  16. package/dist/core/agent-runner.service.js.map +1 -0
  17. package/dist/core/orchestrator.service.d.ts +2 -0
  18. package/dist/core/orchestrator.service.js +7 -0
  19. package/dist/core/orchestrator.service.js.map +1 -0
  20. package/dist/core/tool-registry.service.d.ts +1 -0
  21. package/dist/core/tool-registry.service.js +6 -0
  22. package/dist/core/tool-registry.service.js.map +1 -0
  23. package/dist/database/entities/auth-identity.entity.d.ts +1 -0
  24. package/dist/database/entities/auth-identity.entity.js +6 -0
  25. package/dist/database/entities/auth-identity.entity.js.map +1 -0
  26. package/dist/database/entities/conversation.entity.d.ts +1 -0
  27. package/dist/database/entities/conversation.entity.js +6 -0
  28. package/dist/database/entities/conversation.entity.js.map +1 -0
  29. package/dist/database/entities/email-token.entity.d.ts +1 -0
  30. package/dist/database/entities/email-token.entity.js +6 -0
  31. package/dist/database/entities/email-token.entity.js.map +1 -0
  32. package/dist/database/entities/index.d.ts +7 -0
  33. package/dist/database/entities/index.js +16 -0
  34. package/dist/database/entities/index.js.map +1 -0
  35. package/dist/database/entities/message.entity.d.ts +1 -0
  36. package/dist/database/entities/message.entity.js +6 -0
  37. package/dist/database/entities/message.entity.js.map +1 -0
  38. package/dist/database/entities/refresh-token.entity.d.ts +1 -0
  39. package/dist/database/entities/refresh-token.entity.js +6 -0
  40. package/dist/database/entities/refresh-token.entity.js.map +1 -0
  41. package/dist/database/entities/subscription.entity.d.ts +1 -0
  42. package/dist/database/entities/subscription.entity.js +6 -0
  43. package/dist/database/entities/subscription.entity.js.map +1 -0
  44. package/dist/database/entities/usage-record.entity.d.ts +1 -0
  45. package/dist/database/entities/usage-record.entity.js +6 -0
  46. package/dist/database/entities/usage-record.entity.js.map +1 -0
  47. package/dist/database/entities/user.entity.d.ts +1 -0
  48. package/dist/database/entities/user.entity.js +6 -0
  49. package/dist/database/entities/user.entity.js.map +1 -0
  50. package/dist/decorators/agent-tool.decorator.d.ts +21 -0
  51. package/dist/decorators/agent-tool.decorator.js +12 -0
  52. package/dist/decorators/agent-tool.decorator.js.map +1 -0
  53. package/dist/decorators/rate-limit.decorator.d.ts +9 -0
  54. package/dist/decorators/rate-limit.decorator.js +11 -0
  55. package/dist/decorators/rate-limit.decorator.js.map +1 -0
  56. package/dist/decorators/require-plan.decorator.d.ts +2 -0
  57. package/dist/decorators/require-plan.decorator.js +8 -0
  58. package/dist/decorators/require-plan.decorator.js.map +1 -0
  59. package/dist/filters/agentforge-exception.filter.d.ts +5 -0
  60. package/dist/filters/agentforge-exception.filter.js +40 -0
  61. package/dist/filters/agentforge-exception.filter.js.map +1 -0
  62. package/dist/guards/rate-limit.guard.d.ts +10 -0
  63. package/dist/guards/rate-limit.guard.js +73 -0
  64. package/dist/guards/rate-limit.guard.js.map +1 -0
  65. package/dist/guards/usage-limit.guard.d.ts +11 -0
  66. package/dist/guards/usage-limit.guard.js +57 -0
  67. package/dist/guards/usage-limit.guard.js.map +1 -0
  68. package/dist/index.d.ts +16 -0
  69. package/dist/index.js +35 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/interceptors/usage-tracking.interceptor.d.ts +6 -0
  72. package/dist/interceptors/usage-tracking.interceptor.js +30 -0
  73. package/dist/interceptors/usage-tracking.interceptor.js.map +1 -0
  74. package/dist/modules/admin/admin-plans.controller.d.ts +11 -0
  75. package/dist/modules/admin/admin-plans.controller.js +97 -0
  76. package/dist/modules/admin/admin-plans.controller.js.map +1 -0
  77. package/dist/modules/admin/admin-tenant-agents.controller.d.ts +61 -0
  78. package/dist/modules/admin/admin-tenant-agents.controller.js +424 -0
  79. package/dist/modules/admin/admin-tenant-agents.controller.js.map +1 -0
  80. package/dist/modules/admin/admin-tenant-billing.controller.d.ts +51 -0
  81. package/dist/modules/admin/admin-tenant-billing.controller.js +119 -0
  82. package/dist/modules/admin/admin-tenant-billing.controller.js.map +1 -0
  83. package/dist/modules/admin/admin-tenants.controller.d.ts +43 -0
  84. package/dist/modules/admin/admin-tenants.controller.js +178 -0
  85. package/dist/modules/admin/admin-tenants.controller.js.map +1 -0
  86. package/dist/modules/admin/admin-users.controller.d.ts +41 -0
  87. package/dist/modules/admin/admin-users.controller.js +121 -0
  88. package/dist/modules/admin/admin-users.controller.js.map +1 -0
  89. package/dist/modules/admin/admin.module.d.ts +2 -0
  90. package/dist/modules/admin/admin.module.js +26 -0
  91. package/dist/modules/admin/admin.module.js.map +1 -0
  92. package/dist/modules/admin/platform-admin.guard.d.ts +7 -0
  93. package/dist/modules/admin/platform-admin.guard.js +52 -0
  94. package/dist/modules/admin/platform-admin.guard.js.map +1 -0
  95. package/dist/modules/agent/agent.controller.d.ts +34 -0
  96. package/dist/modules/agent/agent.controller.js +178 -0
  97. package/dist/modules/agent/agent.controller.js.map +1 -0
  98. package/dist/modules/agent/agent.module.d.ts +2 -0
  99. package/dist/modules/agent/agent.module.js +23 -0
  100. package/dist/modules/agent/agent.module.js.map +1 -0
  101. package/dist/modules/agent/agent.service.d.ts +2 -0
  102. package/dist/modules/agent/agent.service.js +7 -0
  103. package/dist/modules/agent/agent.service.js.map +1 -0
  104. package/dist/modules/agent/dto/create-conversation.dto.d.ts +8 -0
  105. package/dist/modules/agent/dto/create-conversation.dto.js +48 -0
  106. package/dist/modules/agent/dto/create-conversation.dto.js.map +1 -0
  107. package/dist/modules/agent/dto/send-message.dto.d.ts +12 -0
  108. package/dist/modules/agent/dto/send-message.dto.js +42 -0
  109. package/dist/modules/agent/dto/send-message.dto.js.map +1 -0
  110. package/dist/modules/agent/in-memory-prepared-stream.store.d.ts +1 -0
  111. package/dist/modules/agent/in-memory-prepared-stream.store.js +6 -0
  112. package/dist/modules/agent/in-memory-prepared-stream.store.js.map +1 -0
  113. package/dist/modules/agent/prepared-stream.service.d.ts +1 -0
  114. package/dist/modules/agent/prepared-stream.service.js +7 -0
  115. package/dist/modules/agent/prepared-stream.service.js.map +1 -0
  116. package/dist/modules/agent/prepared-stream.types.d.ts +1 -0
  117. package/dist/modules/agent/prepared-stream.types.js +6 -0
  118. package/dist/modules/agent/prepared-stream.types.js.map +1 -0
  119. package/dist/modules/agent/redis-prepared-stream.store.d.ts +9 -0
  120. package/dist/modules/agent/redis-prepared-stream.store.js +48 -0
  121. package/dist/modules/agent/redis-prepared-stream.store.js.map +1 -0
  122. package/dist/modules/auth/auth.controller.d.ts +63 -0
  123. package/dist/modules/auth/auth.controller.js +255 -0
  124. package/dist/modules/auth/auth.controller.js.map +1 -0
  125. package/dist/modules/auth/auth.module.d.ts +4 -0
  126. package/dist/modules/auth/auth.module.js +71 -0
  127. package/dist/modules/auth/auth.module.js.map +1 -0
  128. package/dist/modules/auth/auth.service.d.ts +2 -0
  129. package/dist/modules/auth/auth.service.js +7 -0
  130. package/dist/modules/auth/auth.service.js.map +1 -0
  131. package/dist/modules/auth/decorators/current-user.decorator.d.ts +8 -0
  132. package/dist/modules/auth/decorators/current-user.decorator.js +12 -0
  133. package/dist/modules/auth/decorators/current-user.decorator.js.map +1 -0
  134. package/dist/modules/auth/decorators/public.decorator.d.ts +2 -0
  135. package/dist/modules/auth/decorators/public.decorator.js +8 -0
  136. package/dist/modules/auth/decorators/public.decorator.js.map +1 -0
  137. package/dist/modules/auth/dto/login.dto.d.ts +4 -0
  138. package/dist/modules/auth/dto/login.dto.js +29 -0
  139. package/dist/modules/auth/dto/login.dto.js.map +1 -0
  140. package/dist/modules/auth/dto/register.dto.d.ts +5 -0
  141. package/dist/modules/auth/dto/register.dto.js +36 -0
  142. package/dist/modules/auth/dto/register.dto.js.map +1 -0
  143. package/dist/modules/auth/guards/jwt-auth.guard.d.ts +9 -0
  144. package/dist/modules/auth/guards/jwt-auth.guard.js +37 -0
  145. package/dist/modules/auth/guards/jwt-auth.guard.js.map +1 -0
  146. package/dist/modules/auth/guards/local-auth.guard.d.ts +4 -0
  147. package/dist/modules/auth/guards/local-auth.guard.js +18 -0
  148. package/dist/modules/auth/guards/local-auth.guard.js.map +1 -0
  149. package/dist/modules/auth/guards/oauth-configured.guard.d.ts +11 -0
  150. package/dist/modules/auth/guards/oauth-configured.guard.js +51 -0
  151. package/dist/modules/auth/guards/oauth-configured.guard.js.map +1 -0
  152. package/dist/modules/auth/oauth.controller.d.ts +20 -0
  153. package/dist/modules/auth/oauth.controller.js +208 -0
  154. package/dist/modules/auth/oauth.controller.js.map +1 -0
  155. package/dist/modules/auth/refresh-token.service.d.ts +2 -0
  156. package/dist/modules/auth/refresh-token.service.js +7 -0
  157. package/dist/modules/auth/refresh-token.service.js.map +1 -0
  158. package/dist/modules/auth/strategies/github.strategy.d.ts +12 -0
  159. package/dist/modules/auth/strategies/github.strategy.js +57 -0
  160. package/dist/modules/auth/strategies/github.strategy.js.map +1 -0
  161. package/dist/modules/auth/strategies/google.strategy.d.ts +19 -0
  162. package/dist/modules/auth/strategies/google.strategy.js +56 -0
  163. package/dist/modules/auth/strategies/google.strategy.js.map +1 -0
  164. package/dist/modules/auth/strategies/jwt.strategy.d.ts +18 -0
  165. package/dist/modules/auth/strategies/jwt.strategy.js +49 -0
  166. package/dist/modules/auth/strategies/jwt.strategy.js.map +1 -0
  167. package/dist/modules/auth/strategies/local.strategy.d.ts +11 -0
  168. package/dist/modules/auth/strategies/local.strategy.js +31 -0
  169. package/dist/modules/auth/strategies/local.strategy.js.map +1 -0
  170. package/dist/modules/billing/adapters/billing-adapter.interface.d.ts +1 -0
  171. package/dist/modules/billing/adapters/billing-adapter.interface.js +6 -0
  172. package/dist/modules/billing/adapters/billing-adapter.interface.js.map +1 -0
  173. package/dist/modules/billing/adapters/stripe/stripe.adapter.d.ts +19 -0
  174. package/dist/modules/billing/adapters/stripe/stripe.adapter.js +118 -0
  175. package/dist/modules/billing/adapters/stripe/stripe.adapter.js.map +1 -0
  176. package/dist/modules/billing/billing.controller.d.ts +54 -0
  177. package/dist/modules/billing/billing.controller.js +180 -0
  178. package/dist/modules/billing/billing.controller.js.map +1 -0
  179. package/dist/modules/billing/billing.module.d.ts +2 -0
  180. package/dist/modules/billing/billing.module.js +57 -0
  181. package/dist/modules/billing/billing.module.js.map +1 -0
  182. package/dist/modules/billing/billing.service.d.ts +2 -0
  183. package/dist/modules/billing/billing.service.js +7 -0
  184. package/dist/modules/billing/billing.service.js.map +1 -0
  185. package/dist/modules/billing/usage.service.d.ts +2 -0
  186. package/dist/modules/billing/usage.service.js +6 -0
  187. package/dist/modules/billing/usage.service.js.map +1 -0
  188. package/dist/modules/connectors/connectors.controller.d.ts +16 -0
  189. package/dist/modules/connectors/connectors.controller.js +142 -0
  190. package/dist/modules/connectors/connectors.controller.js.map +1 -0
  191. package/dist/modules/connectors/connectors.module.d.ts +2 -0
  192. package/dist/modules/connectors/connectors.module.js +20 -0
  193. package/dist/modules/connectors/connectors.module.js.map +1 -0
  194. package/dist/modules/conversation/conversation.module.d.ts +2 -0
  195. package/dist/modules/conversation/conversation.module.js +17 -0
  196. package/dist/modules/conversation/conversation.module.js.map +1 -0
  197. package/dist/modules/conversation/conversation.service.d.ts +1 -0
  198. package/dist/modules/conversation/conversation.service.js +7 -0
  199. package/dist/modules/conversation/conversation.service.js.map +1 -0
  200. package/dist/modules/email/adapters/email-adapter.interface.d.ts +1 -0
  201. package/dist/modules/email/adapters/email-adapter.interface.js +6 -0
  202. package/dist/modules/email/adapters/email-adapter.interface.js.map +1 -0
  203. package/dist/modules/email/adapters/noop.adapter.d.ts +1 -0
  204. package/dist/modules/email/adapters/noop.adapter.js +6 -0
  205. package/dist/modules/email/adapters/noop.adapter.js.map +1 -0
  206. package/dist/modules/email/adapters/resend.adapter.d.ts +1 -0
  207. package/dist/modules/email/adapters/resend.adapter.js +6 -0
  208. package/dist/modules/email/adapters/resend.adapter.js.map +1 -0
  209. package/dist/modules/email/email.module.d.ts +2 -0
  210. package/dist/modules/email/email.module.js +17 -0
  211. package/dist/modules/email/email.module.js.map +1 -0
  212. package/dist/modules/email/email.service.d.ts +1 -0
  213. package/dist/modules/email/email.service.js +6 -0
  214. package/dist/modules/email/email.service.js.map +1 -0
  215. package/dist/modules/email/templates/transactional.template.d.ts +18 -0
  216. package/dist/modules/email/templates/transactional.template.js +43 -0
  217. package/dist/modules/email/templates/transactional.template.js.map +1 -0
  218. package/dist/modules/mcp/mcp-admin.controller.d.ts +35 -0
  219. package/dist/modules/mcp/mcp-admin.controller.js +111 -0
  220. package/dist/modules/mcp/mcp-admin.controller.js.map +1 -0
  221. package/dist/modules/mcp/mcp.module.d.ts +8 -0
  222. package/dist/modules/mcp/mcp.module.js +38 -0
  223. package/dist/modules/mcp/mcp.module.js.map +1 -0
  224. package/dist/modules/public-chat/public-chat.controller.d.ts +54 -0
  225. package/dist/modules/public-chat/public-chat.controller.js +279 -0
  226. package/dist/modules/public-chat/public-chat.controller.js.map +1 -0
  227. package/dist/modules/public-chat/public-chat.module.d.ts +2 -0
  228. package/dist/modules/public-chat/public-chat.module.js +20 -0
  229. package/dist/modules/public-chat/public-chat.module.js.map +1 -0
  230. package/dist/modules/queue/jobs.controller.d.ts +23 -0
  231. package/dist/modules/queue/jobs.controller.js +98 -0
  232. package/dist/modules/queue/jobs.controller.js.map +1 -0
  233. package/dist/modules/queue/processors/agent.processor.d.ts +12 -0
  234. package/dist/modules/queue/processors/agent.processor.js +65 -0
  235. package/dist/modules/queue/processors/agent.processor.js.map +1 -0
  236. package/dist/modules/queue/queue.module.d.ts +5 -0
  237. package/dist/modules/queue/queue.module.js +55 -0
  238. package/dist/modules/queue/queue.module.js.map +1 -0
  239. package/dist/modules/queue/queue.service.d.ts +15 -0
  240. package/dist/modules/queue/queue.service.js +86 -0
  241. package/dist/modules/queue/queue.service.js.map +1 -0
  242. package/dist/providers/repositories.providers.d.ts +3 -0
  243. package/dist/providers/repositories.providers.js +35 -0
  244. package/dist/providers/repositories.providers.js.map +1 -0
  245. package/dist/providers/services.providers.d.ts +4 -0
  246. package/dist/providers/services.providers.js +142 -0
  247. package/dist/providers/services.providers.js.map +1 -0
  248. package/dist/redis/redis.provider.d.ts +3 -0
  249. package/dist/redis/redis.provider.js +48 -0
  250. package/dist/redis/redis.provider.js.map +1 -0
  251. package/dist/tsconfig.build.tsbuildinfo +1 -0
  252. package/dist/types/index.d.ts +1 -0
  253. package/dist/types/index.js +18 -0
  254. package/dist/types/index.js.map +1 -0
  255. package/package.json +63 -0
@@ -0,0 +1,279 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.PublicChatController = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const swagger_1 = require("@nestjs/swagger");
18
+ const core_1 = require("@agentforge-io/core");
19
+ const public_decorator_1 = require("../../auth/public.decorator");
20
+ let PublicChatController = class PublicChatController {
21
+ constructor(chatTokens, agents, conversations) {
22
+ this.chatTokens = chatTokens;
23
+ this.agents = agents;
24
+ this.conversations = conversations;
25
+ }
26
+ async getAgent(token, req) {
27
+ const t = await this.authorize(token, req);
28
+ const agent = await this.resolveAgent(t.agentId);
29
+ const extra = agent;
30
+ return {
31
+ agent: {
32
+ id: agent.id,
33
+ slug: extra.slug ?? agent.id,
34
+ name: agent.name,
35
+ description: agent.description,
36
+ },
37
+ theme: extra.appearance ?? null,
38
+ };
39
+ }
40
+ async createConversation(token, body, req) {
41
+ if (!body?.initialMessage || !body?.browserSessionId) {
42
+ throw new common_1.BadRequestException('initialMessage and browserSessionId are required');
43
+ }
44
+ const t = await this.authorize(token, req);
45
+ const result = await this.agents.createConversation({
46
+ userId: browserUserId(body.browserSessionId),
47
+ agentId: t.agentId,
48
+ title: undefined,
49
+ metadata: { source: 'public-chat', tokenName: t.name },
50
+ initialMessage: body.initialMessage,
51
+ });
52
+ return {
53
+ conversation: { id: result.conversation.id },
54
+ firstResponse: result.firstResponse,
55
+ };
56
+ }
57
+ async sendMessage(token, conversationId, body, req) {
58
+ if (!body?.content || !body?.browserSessionId) {
59
+ throw new common_1.BadRequestException('content and browserSessionId are required');
60
+ }
61
+ const t = await this.authorize(token, req);
62
+ await this.assertConversationBelongsToToken(conversationId, body.browserSessionId, t.agentId);
63
+ return this.agents.sendMessage({
64
+ conversationId,
65
+ userId: browserUserId(body.browserSessionId),
66
+ content: body.content,
67
+ });
68
+ }
69
+ async streamCreate(token, body, req, res) {
70
+ if (!body?.content || !body?.browserSessionId) {
71
+ throw new common_1.BadRequestException('content and browserSessionId are required');
72
+ }
73
+ const t = await this.authorize(token, req);
74
+ openSse(res);
75
+ try {
76
+ const userId = browserUserId(body.browserSessionId);
77
+ for await (const evt of this.agents.streamCreateConversation({
78
+ userId,
79
+ agentId: t.agentId,
80
+ title: undefined,
81
+ metadata: { source: 'public-chat', tokenName: t.name },
82
+ content: body.content,
83
+ })) {
84
+ if (evt.kind === 'conversation') {
85
+ writeSse(res, 'conversation', { id: evt.conversationId });
86
+ }
87
+ else {
88
+ writeChunk(res, evt.chunk);
89
+ }
90
+ }
91
+ writeSse(res, 'done', {});
92
+ }
93
+ catch (err) {
94
+ writeSse(res, 'error', { message: err.message });
95
+ }
96
+ finally {
97
+ res.end();
98
+ }
99
+ }
100
+ async streamSend(token, conversationId, body, req, res) {
101
+ if (!body?.content || !body?.browserSessionId) {
102
+ throw new common_1.BadRequestException('content and browserSessionId are required');
103
+ }
104
+ const t = await this.authorize(token, req);
105
+ await this.assertConversationBelongsToToken(conversationId, body.browserSessionId, t.agentId);
106
+ openSse(res);
107
+ try {
108
+ for await (const chunk of this.agents.streamMessage({
109
+ conversationId,
110
+ userId: browserUserId(body.browserSessionId),
111
+ content: body.content,
112
+ })) {
113
+ writeChunk(res, chunk);
114
+ }
115
+ writeSse(res, 'done', {});
116
+ }
117
+ catch (err) {
118
+ writeSse(res, 'error', { message: err.message });
119
+ }
120
+ finally {
121
+ res.end();
122
+ }
123
+ }
124
+ async getConversation(token, conversationId, browserSessionId, req) {
125
+ if (!browserSessionId) {
126
+ throw new common_1.BadRequestException('browserSessionId is required');
127
+ }
128
+ const t = await this.authorize(token, req);
129
+ await this.assertConversationBelongsToToken(conversationId, browserSessionId, t.agentId);
130
+ const history = await this.conversations.getHistory(conversationId, browserUserId(browserSessionId));
131
+ return {
132
+ conversationId: history.conversationId,
133
+ status: history.status,
134
+ messages: history.messages.map((m) => ({
135
+ id: m.id,
136
+ role: m.role,
137
+ content: m.content,
138
+ createdAt: m.createdAt,
139
+ })),
140
+ };
141
+ }
142
+ async endConversation(token, conversationId, body, req) {
143
+ if (!body?.browserSessionId) {
144
+ throw new common_1.BadRequestException('browserSessionId is required');
145
+ }
146
+ const t = await this.authorize(token, req);
147
+ await this.assertConversationBelongsToToken(conversationId, body.browserSessionId, t.agentId);
148
+ await this.conversations.markCompleted(conversationId);
149
+ }
150
+ async authorize(rawToken, req) {
151
+ const origin = req.headers.origin ?? undefined;
152
+ try {
153
+ return await this.chatTokens.authorize(rawToken, origin);
154
+ }
155
+ catch (err) {
156
+ if (err instanceof core_1.ChatTokenError) {
157
+ if (err.status === 404)
158
+ throw new common_1.NotFoundException(err.message);
159
+ if (err.status === 403)
160
+ throw new common_1.ForbiddenException(err.message);
161
+ throw new common_1.BadRequestException(err.message);
162
+ }
163
+ throw err;
164
+ }
165
+ }
166
+ async resolveAgent(agentId) {
167
+ return this.agents.resolveAgent({ agentId });
168
+ }
169
+ async assertConversationBelongsToToken(conversationId, browserSessionId, agentId) {
170
+ const conv = await this.conversations.ensureOwned(conversationId, browserUserId(browserSessionId));
171
+ if (conv.agentId !== agentId) {
172
+ throw new common_1.NotFoundException('Conversation not found');
173
+ }
174
+ }
175
+ };
176
+ exports.PublicChatController = PublicChatController;
177
+ __decorate([
178
+ (0, common_1.Get)('agent'),
179
+ (0, swagger_1.ApiOperation)({ summary: 'Return the agent summary the widget renders against' }),
180
+ __param(0, (0, common_1.Param)('token')),
181
+ __param(1, (0, common_1.Req)()),
182
+ __metadata("design:type", Function),
183
+ __metadata("design:paramtypes", [String, Object]),
184
+ __metadata("design:returntype", Promise)
185
+ ], PublicChatController.prototype, "getAgent", null);
186
+ __decorate([
187
+ (0, common_1.Post)('conversations'),
188
+ (0, common_1.HttpCode)(common_1.HttpStatus.CREATED),
189
+ (0, swagger_1.ApiOperation)({ summary: 'Create a public chat conversation (non-streaming)' }),
190
+ __param(0, (0, common_1.Param)('token')),
191
+ __param(1, (0, common_1.Body)()),
192
+ __param(2, (0, common_1.Req)()),
193
+ __metadata("design:type", Function),
194
+ __metadata("design:paramtypes", [String, Object, Object]),
195
+ __metadata("design:returntype", Promise)
196
+ ], PublicChatController.prototype, "createConversation", null);
197
+ __decorate([
198
+ (0, common_1.Post)('conversations/:conversationId/messages'),
199
+ (0, common_1.HttpCode)(common_1.HttpStatus.OK),
200
+ (0, swagger_1.ApiOperation)({ summary: 'Send a message into an existing conversation (non-streaming)' }),
201
+ __param(0, (0, common_1.Param)('token')),
202
+ __param(1, (0, common_1.Param)('conversationId')),
203
+ __param(2, (0, common_1.Body)()),
204
+ __param(3, (0, common_1.Req)()),
205
+ __metadata("design:type", Function),
206
+ __metadata("design:paramtypes", [String, String, Object, Object]),
207
+ __metadata("design:returntype", Promise)
208
+ ], PublicChatController.prototype, "sendMessage", null);
209
+ __decorate([
210
+ (0, common_1.Post)('conversations/stream'),
211
+ (0, swagger_1.ApiOperation)({ summary: 'Open a conversation and stream the first reply (SSE)' }),
212
+ __param(0, (0, common_1.Param)('token')),
213
+ __param(1, (0, common_1.Body)()),
214
+ __param(2, (0, common_1.Req)()),
215
+ __param(3, (0, common_1.Res)()),
216
+ __metadata("design:type", Function),
217
+ __metadata("design:paramtypes", [String, Object, Object, Object]),
218
+ __metadata("design:returntype", Promise)
219
+ ], PublicChatController.prototype, "streamCreate", null);
220
+ __decorate([
221
+ (0, common_1.Post)('conversations/:conversationId/messages/stream'),
222
+ (0, swagger_1.ApiOperation)({ summary: 'Stream an assistant reply to an existing conversation (SSE)' }),
223
+ __param(0, (0, common_1.Param)('token')),
224
+ __param(1, (0, common_1.Param)('conversationId')),
225
+ __param(2, (0, common_1.Body)()),
226
+ __param(3, (0, common_1.Req)()),
227
+ __param(4, (0, common_1.Res)()),
228
+ __metadata("design:type", Function),
229
+ __metadata("design:paramtypes", [String, String, Object, Object, Object]),
230
+ __metadata("design:returntype", Promise)
231
+ ], PublicChatController.prototype, "streamSend", null);
232
+ __decorate([
233
+ (0, common_1.Get)('conversations/:conversationId'),
234
+ (0, swagger_1.ApiOperation)({ summary: 'Fetch a previously-opened conversation transcript' }),
235
+ __param(0, (0, common_1.Param)('token')),
236
+ __param(1, (0, common_1.Param)('conversationId')),
237
+ __param(2, (0, common_1.Query)('browserSessionId')),
238
+ __param(3, (0, common_1.Req)()),
239
+ __metadata("design:type", Function),
240
+ __metadata("design:paramtypes", [String, String, String, Object]),
241
+ __metadata("design:returntype", Promise)
242
+ ], PublicChatController.prototype, "getConversation", null);
243
+ __decorate([
244
+ (0, common_1.Post)('conversations/:conversationId/end'),
245
+ (0, common_1.HttpCode)(common_1.HttpStatus.NO_CONTENT),
246
+ (0, swagger_1.ApiOperation)({ summary: 'Mark a conversation as completed (read-only after)' }),
247
+ __param(0, (0, common_1.Param)('token')),
248
+ __param(1, (0, common_1.Param)('conversationId')),
249
+ __param(2, (0, common_1.Body)()),
250
+ __param(3, (0, common_1.Req)()),
251
+ __metadata("design:type", Function),
252
+ __metadata("design:paramtypes", [String, String, Object, Object]),
253
+ __metadata("design:returntype", Promise)
254
+ ], PublicChatController.prototype, "endConversation", null);
255
+ exports.PublicChatController = PublicChatController = __decorate([
256
+ (0, swagger_1.ApiTags)('Public chat'),
257
+ (0, public_decorator_1.Public)(),
258
+ (0, common_1.Controller)('public/chat/:token'),
259
+ __metadata("design:paramtypes", [core_1.ChatTokenService,
260
+ core_1.AgentService,
261
+ core_1.ConversationService])
262
+ ], PublicChatController);
263
+ function browserUserId(browserSessionId) {
264
+ return `browser:${browserSessionId}`;
265
+ }
266
+ function openSse(res) {
267
+ res.setHeader('Content-Type', 'text/event-stream');
268
+ res.setHeader('Cache-Control', 'no-cache, no-transform');
269
+ res.setHeader('Connection', 'keep-alive');
270
+ res.flushHeaders?.();
271
+ }
272
+ function writeSse(res, event, data) {
273
+ res.write(`event: ${event}\n`);
274
+ res.write(`data: ${JSON.stringify(data)}\n\n`);
275
+ }
276
+ function writeChunk(res, chunk) {
277
+ res.write(`data: ${JSON.stringify(chunk)}\n\n`);
278
+ }
279
+ //# sourceMappingURL=public-chat.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public-chat.controller.js","sourceRoot":"","sources":["../../../src/modules/public-chat/public-chat.controller.ts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;IAGnD,GAAG,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare class PublicChatModule {
2
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.PublicChatModule = void 0;
10
+ const common_1 = require("@nestjs/common");
11
+ const public_chat_controller_1 = require("./public-chat.controller");
12
+ let PublicChatModule = class PublicChatModule {
13
+ };
14
+ exports.PublicChatModule = PublicChatModule;
15
+ exports.PublicChatModule = PublicChatModule = __decorate([
16
+ (0, common_1.Module)({
17
+ controllers: [public_chat_controller_1.PublicChatController],
18
+ })
19
+ ], PublicChatModule);
20
+ //# sourceMappingURL=public-chat.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public-chat.module.js","sourceRoot":"","sources":["../../../src/modules/public-chat/public-chat.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,qEAAgE;AAWzD,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;CAAG,CAAA;AAAnB,4CAAgB;2BAAhB,gBAAgB;IAH5B,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,6CAAoB,CAAC;KACpC,CAAC;GACW,gBAAgB,CAAG"}
@@ -0,0 +1,23 @@
1
+ import { type JobQueue } from '@agentforge-io/core';
2
+ import type { AgentJobPayload, AgentJobResult } from '../../types';
3
+ interface EnqueueBody {
4
+ conversationId: string;
5
+ agentId: string;
6
+ messages: unknown[];
7
+ overrides?: unknown;
8
+ jobId?: string;
9
+ priority?: number;
10
+ attempts?: number;
11
+ }
12
+ export declare class JobsController {
13
+ private readonly queue;
14
+ constructor(queue: JobQueue<AgentJobPayload, AgentJobResult>);
15
+ enqueue(body: EnqueueBody, userId: string): Promise<{
16
+ jobId: string;
17
+ estimatedWait: number;
18
+ }>;
19
+ metrics(): Promise<import("@agentforge-io/core").QueueMetrics>;
20
+ status(jobId: string): Promise<import("@agentforge-io/core").JobStatus<AgentJobResult>>;
21
+ cancel(jobId: string): Promise<void>;
22
+ }
23
+ export {};
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.JobsController = void 0;
16
+ const common_1 = require("@nestjs/common");
17
+ const swagger_1 = require("@nestjs/swagger");
18
+ const crypto_1 = require("crypto");
19
+ const core_1 = require("@agentforge-io/core");
20
+ const current_user_decorator_1 = require("../../auth/current-user.decorator");
21
+ let JobsController = class JobsController {
22
+ constructor(queue) {
23
+ this.queue = queue;
24
+ }
25
+ async enqueue(body, userId) {
26
+ if (!body?.conversationId || !body?.agentId || !Array.isArray(body?.messages)) {
27
+ throw new common_1.BadRequestException('conversationId, agentId, and messages[] are required');
28
+ }
29
+ const jobId = body.jobId ?? (0, crypto_1.randomUUID)();
30
+ return this.queue.enqueue({
31
+ jobId,
32
+ userId,
33
+ conversationId: body.conversationId,
34
+ messageId: jobId,
35
+ agentId: body.agentId,
36
+ messages: body.messages,
37
+ overrides: body.overrides,
38
+ }, { priority: body.priority, attempts: body.attempts });
39
+ }
40
+ metrics() {
41
+ return this.queue.getMetrics();
42
+ }
43
+ async status(jobId) {
44
+ const result = await this.queue.getJobStatus(jobId);
45
+ if (result.status === 'not_found') {
46
+ throw new common_1.NotFoundException(`Job ${jobId} not found`);
47
+ }
48
+ return result;
49
+ }
50
+ async cancel(jobId) {
51
+ const ok = await this.queue.cancelJob(jobId);
52
+ if (!ok) {
53
+ throw new common_1.BadRequestException(`Job ${jobId} cannot be cancelled (already started, finished, or not found)`);
54
+ }
55
+ }
56
+ };
57
+ exports.JobsController = JobsController;
58
+ __decorate([
59
+ (0, common_1.Post)(),
60
+ (0, swagger_1.ApiOperation)({ summary: 'Enqueue an agent-turn job' }),
61
+ (0, common_1.HttpCode)(common_1.HttpStatus.ACCEPTED),
62
+ __param(0, (0, common_1.Body)()),
63
+ __param(1, (0, current_user_decorator_1.CurrentUser)('userId')),
64
+ __metadata("design:type", Function),
65
+ __metadata("design:paramtypes", [Object, String]),
66
+ __metadata("design:returntype", Promise)
67
+ ], JobsController.prototype, "enqueue", null);
68
+ __decorate([
69
+ (0, common_1.Get)('metrics'),
70
+ (0, swagger_1.ApiOperation)({ summary: 'Aggregate queue counters' }),
71
+ __metadata("design:type", Function),
72
+ __metadata("design:paramtypes", []),
73
+ __metadata("design:returntype", void 0)
74
+ ], JobsController.prototype, "metrics", null);
75
+ __decorate([
76
+ (0, common_1.Get)(':jobId'),
77
+ (0, swagger_1.ApiOperation)({ summary: 'Get job status + progress' }),
78
+ __param(0, (0, common_1.Param)('jobId')),
79
+ __metadata("design:type", Function),
80
+ __metadata("design:paramtypes", [String]),
81
+ __metadata("design:returntype", Promise)
82
+ ], JobsController.prototype, "status", null);
83
+ __decorate([
84
+ (0, common_1.Delete)(':jobId'),
85
+ (0, swagger_1.ApiOperation)({ summary: 'Cancel a waiting/delayed job' }),
86
+ (0, common_1.HttpCode)(common_1.HttpStatus.NO_CONTENT),
87
+ __param(0, (0, common_1.Param)('jobId')),
88
+ __metadata("design:type", Function),
89
+ __metadata("design:paramtypes", [String]),
90
+ __metadata("design:returntype", Promise)
91
+ ], JobsController.prototype, "cancel", null);
92
+ exports.JobsController = JobsController = __decorate([
93
+ (0, swagger_1.ApiTags)('Jobs'),
94
+ (0, common_1.Controller)('jobs'),
95
+ __param(0, (0, common_1.Inject)(core_1.JOB_QUEUE)),
96
+ __metadata("design:paramtypes", [Object])
97
+ ], JobsController);
98
+ //# sourceMappingURL=jobs.controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jobs.controller.js","sourceRoot":"","sources":["../../../src/modules/queue/jobs.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAYwB;AACxB,6CAAwD;AACxD,mCAAoC;AACpC,8CAA+D;AAE/D,8EAAgE;AAmBzD,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,YAEmB,KAAgD;QAAhD,UAAK,GAAL,KAAK,CAA2C;IAChE,CAAC;IAKE,AAAN,KAAK,CAAC,OAAO,CACH,IAAiB,EACF,MAAc;QAErC,IAAI,CAAC,IAAI,EAAE,cAAc,IAAI,CAAC,IAAI,EAAE,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC;YAC9E,MAAM,IAAI,4BAAmB,CAC3B,sDAAsD,CACvD,CAAC;QACJ,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,IAAA,mBAAU,GAAE,CAAC;QACzC,OAAO,IAA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vB;AAID;IAFC,IAAA,YAAG,EAAC,SAAS,CAAC;IACd,IAAA,sBAAY,EAAC,EAAE,OAAO,EAAE,0BAA0B,EAAE,CAAC;;;;6CAGrD;AAIK;IAFL,IAAA,YAAG,EAAC,QAAQ,CAAC;IACb,IAAA,sBAAY,EAAC,EAAE,OAAO,EAAE,2BAA2B,EAAE,CAAC;IACzC,WAAA,IAAA,cAAK,EAAC,OAAO,CAAC,CAAA;;;;4CAM3B;AAKK;IAHL,IAAA,eAAM,EAAC,QAAQ,CAAC;IAChB,IAAA,sBAAY,EAAC,EAAE,OAAO,EAAE,8BAA8B,EAAE,CAAC;IACzD,IAAA,iBAAQ,EAAC,mBAAU,CAAC,UAAU,CAAC;IAClB,WAAA,IAAA,cAAK,EAAC,OAAO,CAAC,CAAA;;;;4CAO3B;yBA3DU,cAAc;IAF1B,IAAA,iBAAO,EAAC,MAAM,CAAC;IACf,IAAA,mBAAU,EAAC,MAAM,CAAC;IAGd,WAAA,IAAA,eAAM,EAAC,gBAAS,CAAC,CAAA;;GAFT,cAAc,CA4D1B"}
@@ -0,0 +1,12 @@
1
+ import { WorkerHost } from '@nestjs/bullmq';
2
+ import { Job } from 'bullmq';
3
+ import { AgentJobWorker } from '@agentforge-io/core';
4
+ import type { AgentJobPayload, AgentJobResult } from '../../../types';
5
+ export declare class AgentProcessor extends WorkerHost {
6
+ private readonly jobWorker;
7
+ private readonly logger;
8
+ constructor(jobWorker: AgentJobWorker);
9
+ process(job: Job<AgentJobPayload>): Promise<AgentJobResult>;
10
+ onCompleted(job: Job): void;
11
+ onFailed(job: Job, error: Error): void;
12
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var AgentProcessor_1;
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.AgentProcessor = void 0;
14
+ const common_1 = require("@nestjs/common");
15
+ const bullmq_1 = require("@nestjs/bullmq");
16
+ const bullmq_2 = require("bullmq");
17
+ const core_1 = require("@agentforge-io/core");
18
+ const constants_1 = require("../../../constants");
19
+ let AgentProcessor = AgentProcessor_1 = class AgentProcessor extends bullmq_1.WorkerHost {
20
+ constructor(jobWorker) {
21
+ super();
22
+ this.jobWorker = jobWorker;
23
+ this.logger = new common_1.Logger(AgentProcessor_1.name);
24
+ }
25
+ async process(job) {
26
+ const ctx = {
27
+ jobId: job.id ?? job.data.jobId,
28
+ updateProgress: async (percent) => {
29
+ await job.updateProgress(percent);
30
+ },
31
+ };
32
+ try {
33
+ return await this.jobWorker.process(job.data, ctx);
34
+ }
35
+ catch (error) {
36
+ const message = error instanceof Error ? error.message : String(error);
37
+ this.logger.error(`Job ${job.id} failed: ${message}`);
38
+ throw error;
39
+ }
40
+ }
41
+ onCompleted(job) {
42
+ this.logger.debug(`Job ${job.id} completed in ${Date.now() - job.timestamp}ms`);
43
+ }
44
+ onFailed(job, error) {
45
+ this.logger.error(`Job ${job.id} failed after ${job.attemptsMade} attempts: ${error.message}`);
46
+ }
47
+ };
48
+ exports.AgentProcessor = AgentProcessor;
49
+ __decorate([
50
+ (0, bullmq_1.OnWorkerEvent)('completed'),
51
+ __metadata("design:type", Function),
52
+ __metadata("design:paramtypes", [bullmq_2.Job]),
53
+ __metadata("design:returntype", void 0)
54
+ ], AgentProcessor.prototype, "onCompleted", null);
55
+ __decorate([
56
+ (0, bullmq_1.OnWorkerEvent)('failed'),
57
+ __metadata("design:type", Function),
58
+ __metadata("design:paramtypes", [bullmq_2.Job, Error]),
59
+ __metadata("design:returntype", void 0)
60
+ ], AgentProcessor.prototype, "onFailed", null);
61
+ exports.AgentProcessor = AgentProcessor = AgentProcessor_1 = __decorate([
62
+ (0, bullmq_1.Processor)(constants_1.AGENT_QUEUE_NAME),
63
+ __metadata("design:paramtypes", [core_1.AgentJobWorker])
64
+ ], AgentProcessor);
65
+ //# sourceMappingURL=agent.processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.processor.js","sourceRoot":"","sources":["../../../../src/modules/queue/processors/agent.processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAwC;AACxC,2CAAsE;AACtE,mCAA6B;AAC7B,8CAAqD;AAErD,kDAAsD;AAS/C,IAAM,cAAc,sBAApB,MAAM,cAAe,SAAQ,mBAAU;IAG5C,YAA6B,SAAyB;QACpD,KAAK,EAAE,CAAC;QADmB,cAAS,GAAT,SAAS,CAAgB;QAFrC,WAAM,GAAG,IAAI,eAAM,CAAC,gBAAc,CAAC,IAAI,CAAC,CAAC;IAI1D,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAyB;QACrC,MAAM,GAAG,GAAe;YACtB,KAAK,EAAE,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK;YAC/B,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;gBAChC,MAAM,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YACpC,CAAC;SACF,CAAC;QAEF,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACrD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,EAAE,YAAY,OAAO,EAAE,CAAC,CAAC;YACtD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAGD,WAAW,CAAC,GAAQ;QAClB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,EAAE,iBAAiB,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,SAAS,IAAI,CAAC,CAAC;IAClF,CAAC;IAGD,QAAQ,CAAC,GAAQ,EAAE,KAAY;QAC7B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,EAAE,iBAAiB,GAAG,CAAC,YAAY,cAAc,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACjG,CAAC;CACF,CAAA;AAjCY,wCAAc;AAyBzB;IADC,IAAA,sBAAa,EAAC,WAAW,CAAC;;qCACV,YAAG;;iDAEnB;AAGD;IADC,IAAA,sBAAa,EAAC,QAAQ,CAAC;;qCACV,YAAG,EAAS,KAAK;;8CAE9B;yBAhCU,cAAc;IAD1B,IAAA,kBAAS,EAAC,4BAAgB,CAAC;qCAIc,qBAAc;GAH3C,cAAc,CAiC1B"}
@@ -0,0 +1,5 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import type { AgentForgeConfig } from '../../types';
3
+ export declare class QueueModule {
4
+ static forRoot(config: AgentForgeConfig): DynamicModule;
5
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ 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;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var QueueModule_1;
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.QueueModule = void 0;
11
+ const common_1 = require("@nestjs/common");
12
+ const bullmq_1 = require("@nestjs/bullmq");
13
+ const queue_service_1 = require("./queue.service");
14
+ const agent_processor_1 = require("./processors/agent.processor");
15
+ const constants_1 = require("../../constants");
16
+ let QueueModule = QueueModule_1 = class QueueModule {
17
+ static forRoot(config) {
18
+ if (!config.queue?.enabled) {
19
+ return { module: QueueModule_1, providers: [], exports: [] };
20
+ }
21
+ if (!config.redis) {
22
+ throw new Error('Redis config is required when queue is enabled. Add a redis config to AgentForgeModule.forRoot()');
23
+ }
24
+ return {
25
+ module: QueueModule_1,
26
+ imports: [
27
+ bullmq_1.BullModule.forRoot({
28
+ connection: {
29
+ host: config.redis.host,
30
+ port: config.redis.port,
31
+ password: config.redis.password,
32
+ db: config.redis.db,
33
+ tls: config.redis.tls ? {} : undefined,
34
+ },
35
+ }),
36
+ bullmq_1.BullModule.registerQueue({
37
+ name: constants_1.AGENT_QUEUE_NAME,
38
+ defaultJobOptions: config.queue.defaultJobOptions ?? {
39
+ attempts: 3,
40
+ backoff: { type: 'exponential', delay: 2000 },
41
+ removeOnComplete: 100,
42
+ removeOnFail: 50,
43
+ },
44
+ }),
45
+ ],
46
+ providers: [queue_service_1.QueueService, agent_processor_1.AgentProcessor],
47
+ exports: [queue_service_1.QueueService, bullmq_1.BullModule],
48
+ };
49
+ }
50
+ };
51
+ exports.QueueModule = QueueModule;
52
+ exports.QueueModule = QueueModule = QueueModule_1 = __decorate([
53
+ (0, common_1.Module)({})
54
+ ], QueueModule);
55
+ //# sourceMappingURL=queue.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.module.js","sourceRoot":"","sources":["../../../src/modules/queue/queue.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,2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AAC;IACJ,CAAC;CACF,CAAA;AAtCY,kCAAW;sBAAX,WAAW;IADvB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,WAAW,CAsCvB"}
@@ -0,0 +1,15 @@
1
+ import { Queue } from 'bullmq';
2
+ import type { JobQueue, JobStatus, EnqueueOptions, QueueMetrics } from '@agentforge-io/core';
3
+ import type { AgentJobPayload, AgentJobResult } from '../../types';
4
+ export declare class QueueService implements JobQueue<AgentJobPayload, AgentJobResult> {
5
+ private readonly queue;
6
+ private readonly logger;
7
+ constructor(queue: Queue<AgentJobPayload, AgentJobResult>);
8
+ enqueue(payload: AgentJobPayload, opts?: EnqueueOptions): Promise<{
9
+ jobId: string;
10
+ estimatedWait: number;
11
+ }>;
12
+ getJobStatus(jobId: string): Promise<JobStatus<AgentJobResult>>;
13
+ cancelJob(jobId: string): Promise<boolean>;
14
+ getMetrics(): Promise<QueueMetrics>;
15
+ }