@lobu/gateway 3.0.8 → 3.0.12

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 (219) hide show
  1. package/dist/api/platform.d.ts.map +1 -1
  2. package/dist/api/platform.js +8 -26
  3. package/dist/api/platform.js.map +1 -1
  4. package/dist/auth/mcp/proxy.d.ts +14 -0
  5. package/dist/auth/mcp/proxy.d.ts.map +1 -1
  6. package/dist/auth/mcp/proxy.js +149 -13
  7. package/dist/auth/mcp/proxy.js.map +1 -1
  8. package/dist/cli/gateway.d.ts.map +1 -1
  9. package/dist/cli/gateway.js +29 -0
  10. package/dist/cli/gateway.js.map +1 -1
  11. package/dist/cli/index.js +2 -2
  12. package/dist/cli/index.js.map +1 -1
  13. package/dist/connections/chat-instance-manager.d.ts.map +1 -1
  14. package/dist/connections/chat-instance-manager.js +2 -1
  15. package/dist/connections/chat-instance-manager.js.map +1 -1
  16. package/dist/connections/interaction-bridge.d.ts +9 -2
  17. package/dist/connections/interaction-bridge.d.ts.map +1 -1
  18. package/dist/connections/interaction-bridge.js +132 -230
  19. package/dist/connections/interaction-bridge.js.map +1 -1
  20. package/dist/connections/message-handler-bridge.d.ts.map +1 -1
  21. package/dist/connections/message-handler-bridge.js +44 -26
  22. package/dist/connections/message-handler-bridge.js.map +1 -1
  23. package/dist/interactions.d.ts +9 -43
  24. package/dist/interactions.d.ts.map +1 -1
  25. package/dist/interactions.js +10 -52
  26. package/dist/interactions.js.map +1 -1
  27. package/dist/orchestration/base-deployment-manager.js +7 -7
  28. package/dist/orchestration/base-deployment-manager.js.map +1 -1
  29. package/dist/platform/unified-thread-consumer.d.ts.map +1 -1
  30. package/dist/platform/unified-thread-consumer.js +38 -34
  31. package/dist/platform/unified-thread-consumer.js.map +1 -1
  32. package/dist/routes/public/agent.d.ts +4 -0
  33. package/dist/routes/public/agent.d.ts.map +1 -1
  34. package/dist/routes/public/agent.js +21 -0
  35. package/dist/routes/public/agent.js.map +1 -1
  36. package/dist/services/core-services.d.ts.map +1 -1
  37. package/dist/services/core-services.js +4 -0
  38. package/dist/services/core-services.js.map +1 -1
  39. package/package.json +2 -2
  40. package/src/__tests__/agent-config-routes.test.ts +0 -254
  41. package/src/__tests__/agent-history-routes.test.ts +0 -72
  42. package/src/__tests__/agent-routes.test.ts +0 -68
  43. package/src/__tests__/agent-schedules-routes.test.ts +0 -59
  44. package/src/__tests__/agent-settings-store.test.ts +0 -323
  45. package/src/__tests__/bedrock-model-catalog.test.ts +0 -40
  46. package/src/__tests__/bedrock-openai-service.test.ts +0 -157
  47. package/src/__tests__/bedrock-provider-module.test.ts +0 -56
  48. package/src/__tests__/chat-instance-manager-slack.test.ts +0 -204
  49. package/src/__tests__/chat-response-bridge.test.ts +0 -131
  50. package/src/__tests__/config-memory-plugins.test.ts +0 -92
  51. package/src/__tests__/config-request-store.test.ts +0 -127
  52. package/src/__tests__/connection-routes.test.ts +0 -144
  53. package/src/__tests__/core-services-store-selection.test.ts +0 -92
  54. package/src/__tests__/docker-deployment.test.ts +0 -1211
  55. package/src/__tests__/embedded-deployment.test.ts +0 -342
  56. package/src/__tests__/grant-store.test.ts +0 -148
  57. package/src/__tests__/http-proxy.test.ts +0 -281
  58. package/src/__tests__/instruction-service.test.ts +0 -37
  59. package/src/__tests__/link-buttons.test.ts +0 -112
  60. package/src/__tests__/lobu.test.ts +0 -32
  61. package/src/__tests__/mcp-config-service.test.ts +0 -347
  62. package/src/__tests__/mcp-proxy.test.ts +0 -694
  63. package/src/__tests__/message-handler-bridge.test.ts +0 -17
  64. package/src/__tests__/model-selection.test.ts +0 -172
  65. package/src/__tests__/oauth-templates.test.ts +0 -39
  66. package/src/__tests__/platform-adapter-slack-send.test.ts +0 -114
  67. package/src/__tests__/platform-helpers-model-resolution.test.ts +0 -253
  68. package/src/__tests__/provider-inheritance.test.ts +0 -212
  69. package/src/__tests__/routes/cli-auth.test.ts +0 -337
  70. package/src/__tests__/routes/interactions.test.ts +0 -121
  71. package/src/__tests__/secret-proxy.test.ts +0 -85
  72. package/src/__tests__/session-manager.test.ts +0 -572
  73. package/src/__tests__/setup.ts +0 -133
  74. package/src/__tests__/skill-and-mcp-registry.test.ts +0 -203
  75. package/src/__tests__/slack-routes.test.ts +0 -161
  76. package/src/__tests__/system-config-resolver.test.ts +0 -75
  77. package/src/__tests__/system-message-limiter.test.ts +0 -89
  78. package/src/__tests__/system-skills-service.test.ts +0 -362
  79. package/src/__tests__/transcription-service.test.ts +0 -222
  80. package/src/__tests__/utils/rate-limiter.test.ts +0 -102
  81. package/src/__tests__/worker-connection-manager.test.ts +0 -497
  82. package/src/__tests__/worker-job-router.test.ts +0 -722
  83. package/src/api/index.ts +0 -1
  84. package/src/api/platform.ts +0 -292
  85. package/src/api/response-renderer.ts +0 -157
  86. package/src/auth/agent-metadata-store.ts +0 -168
  87. package/src/auth/api-auth-middleware.ts +0 -69
  88. package/src/auth/api-key-provider-module.ts +0 -213
  89. package/src/auth/base-provider-module.ts +0 -201
  90. package/src/auth/bedrock/provider-module.ts +0 -110
  91. package/src/auth/chatgpt/chatgpt-oauth-module.ts +0 -185
  92. package/src/auth/chatgpt/device-code-client.ts +0 -218
  93. package/src/auth/chatgpt/index.ts +0 -1
  94. package/src/auth/claude/oauth-module.ts +0 -280
  95. package/src/auth/cli/token-service.ts +0 -249
  96. package/src/auth/external/client.ts +0 -560
  97. package/src/auth/external/device-code-client.ts +0 -235
  98. package/src/auth/mcp/config-service.ts +0 -420
  99. package/src/auth/mcp/proxy.ts +0 -1086
  100. package/src/auth/mcp/string-substitution.ts +0 -17
  101. package/src/auth/mcp/tool-cache.ts +0 -90
  102. package/src/auth/oauth/base-client.ts +0 -267
  103. package/src/auth/oauth/client.ts +0 -153
  104. package/src/auth/oauth/credentials.ts +0 -7
  105. package/src/auth/oauth/providers.ts +0 -69
  106. package/src/auth/oauth/state-store.ts +0 -150
  107. package/src/auth/oauth-templates.ts +0 -179
  108. package/src/auth/provider-catalog.ts +0 -220
  109. package/src/auth/provider-model-options.ts +0 -41
  110. package/src/auth/settings/agent-settings-store.ts +0 -565
  111. package/src/auth/settings/auth-profiles-manager.ts +0 -216
  112. package/src/auth/settings/index.ts +0 -12
  113. package/src/auth/settings/model-preference-store.ts +0 -52
  114. package/src/auth/settings/model-selection.ts +0 -135
  115. package/src/auth/settings/resolved-settings-view.ts +0 -298
  116. package/src/auth/settings/template-utils.ts +0 -44
  117. package/src/auth/settings/token-service.ts +0 -88
  118. package/src/auth/system-env-store.ts +0 -98
  119. package/src/auth/user-agents-store.ts +0 -68
  120. package/src/channels/binding-service.ts +0 -214
  121. package/src/channels/index.ts +0 -4
  122. package/src/cli/gateway.ts +0 -1312
  123. package/src/cli/index.ts +0 -74
  124. package/src/commands/built-in-commands.ts +0 -80
  125. package/src/commands/command-dispatcher.ts +0 -94
  126. package/src/commands/command-reply-adapters.ts +0 -27
  127. package/src/config/file-loader.ts +0 -618
  128. package/src/config/index.ts +0 -588
  129. package/src/config/network-allowlist.ts +0 -71
  130. package/src/connections/chat-instance-manager.ts +0 -1284
  131. package/src/connections/chat-response-bridge.ts +0 -618
  132. package/src/connections/index.ts +0 -7
  133. package/src/connections/interaction-bridge.ts +0 -831
  134. package/src/connections/message-handler-bridge.ts +0 -415
  135. package/src/connections/platform-auth-methods.ts +0 -15
  136. package/src/connections/types.ts +0 -84
  137. package/src/gateway/connection-manager.ts +0 -291
  138. package/src/gateway/index.ts +0 -698
  139. package/src/gateway/job-router.ts +0 -201
  140. package/src/gateway-main.ts +0 -200
  141. package/src/index.ts +0 -41
  142. package/src/infrastructure/queue/index.ts +0 -12
  143. package/src/infrastructure/queue/queue-producer.ts +0 -148
  144. package/src/infrastructure/queue/redis-queue.ts +0 -361
  145. package/src/infrastructure/queue/types.ts +0 -133
  146. package/src/infrastructure/redis/system-message-limiter.ts +0 -94
  147. package/src/interactions/config-request-store.ts +0 -198
  148. package/src/interactions.ts +0 -363
  149. package/src/lobu.ts +0 -311
  150. package/src/metrics/prometheus.ts +0 -159
  151. package/src/modules/module-system.ts +0 -179
  152. package/src/orchestration/base-deployment-manager.ts +0 -900
  153. package/src/orchestration/deployment-utils.ts +0 -98
  154. package/src/orchestration/impl/docker-deployment.ts +0 -620
  155. package/src/orchestration/impl/embedded-deployment.ts +0 -268
  156. package/src/orchestration/impl/index.ts +0 -8
  157. package/src/orchestration/impl/k8s/deployment.ts +0 -1061
  158. package/src/orchestration/impl/k8s/helpers.ts +0 -610
  159. package/src/orchestration/impl/k8s/index.ts +0 -1
  160. package/src/orchestration/index.ts +0 -333
  161. package/src/orchestration/message-consumer.ts +0 -584
  162. package/src/orchestration/scheduled-wakeup.ts +0 -704
  163. package/src/permissions/approval-policy.ts +0 -36
  164. package/src/permissions/grant-store.ts +0 -219
  165. package/src/platform/file-handler.ts +0 -66
  166. package/src/platform/link-buttons.ts +0 -57
  167. package/src/platform/renderer-utils.ts +0 -44
  168. package/src/platform/response-renderer.ts +0 -84
  169. package/src/platform/unified-thread-consumer.ts +0 -187
  170. package/src/platform.ts +0 -318
  171. package/src/proxy/http-proxy.ts +0 -752
  172. package/src/proxy/proxy-manager.ts +0 -81
  173. package/src/proxy/secret-proxy.ts +0 -402
  174. package/src/proxy/token-refresh-job.ts +0 -143
  175. package/src/routes/internal/audio.ts +0 -141
  176. package/src/routes/internal/device-auth.ts +0 -652
  177. package/src/routes/internal/files.ts +0 -226
  178. package/src/routes/internal/history.ts +0 -69
  179. package/src/routes/internal/images.ts +0 -127
  180. package/src/routes/internal/interactions.ts +0 -84
  181. package/src/routes/internal/middleware.ts +0 -23
  182. package/src/routes/internal/schedule.ts +0 -226
  183. package/src/routes/internal/types.ts +0 -22
  184. package/src/routes/openapi-auto.ts +0 -239
  185. package/src/routes/public/agent-access.ts +0 -23
  186. package/src/routes/public/agent-config.ts +0 -675
  187. package/src/routes/public/agent-history.ts +0 -422
  188. package/src/routes/public/agent-schedules.ts +0 -296
  189. package/src/routes/public/agent.ts +0 -1086
  190. package/src/routes/public/agents.ts +0 -373
  191. package/src/routes/public/channels.ts +0 -191
  192. package/src/routes/public/cli-auth.ts +0 -896
  193. package/src/routes/public/connections.ts +0 -574
  194. package/src/routes/public/landing.ts +0 -16
  195. package/src/routes/public/oauth.ts +0 -147
  196. package/src/routes/public/settings-auth.ts +0 -104
  197. package/src/routes/public/slack.ts +0 -173
  198. package/src/routes/shared/agent-ownership.ts +0 -101
  199. package/src/routes/shared/token-verifier.ts +0 -34
  200. package/src/services/bedrock-model-catalog.ts +0 -217
  201. package/src/services/bedrock-openai-service.ts +0 -658
  202. package/src/services/core-services.ts +0 -1072
  203. package/src/services/image-generation-service.ts +0 -257
  204. package/src/services/instruction-service.ts +0 -318
  205. package/src/services/mcp-registry.ts +0 -94
  206. package/src/services/platform-helpers.ts +0 -287
  207. package/src/services/session-manager.ts +0 -262
  208. package/src/services/settings-resolver.ts +0 -74
  209. package/src/services/system-config-resolver.ts +0 -89
  210. package/src/services/system-skills-service.ts +0 -229
  211. package/src/services/transcription-service.ts +0 -684
  212. package/src/session.ts +0 -110
  213. package/src/spaces/index.ts +0 -1
  214. package/src/spaces/space-resolver.ts +0 -17
  215. package/src/stores/in-memory-agent-store.ts +0 -403
  216. package/src/stores/redis-agent-store.ts +0 -279
  217. package/src/utils/public-url.ts +0 -44
  218. package/src/utils/rate-limiter.ts +0 -94
  219. package/tsconfig.json +0 -33
@@ -1,198 +0,0 @@
1
- import type { SkillConfig } from "@lobu/core";
2
- import type Redis from "ioredis";
3
- import type { AgentSettingsStore } from "../auth/settings/agent-settings-store";
4
- import type { GrantStore } from "../permissions/grant-store";
5
-
6
- const CONFIG_REQUEST_KEY_PREFIX = "pending-config:";
7
-
8
- export interface PendingConfigSkill {
9
- repo: string;
10
- name?: string;
11
- description?: string;
12
- mcpServers?: Array<{
13
- id: string;
14
- name?: string;
15
- url?: string;
16
- type?: string;
17
- command?: string;
18
- args?: string[];
19
- }>;
20
- nixPackages?: string[];
21
- permissions?: string[];
22
- providers?: string[];
23
- }
24
-
25
- export interface PendingConfigRequest {
26
- agentId: string;
27
- reason: string;
28
- message?: string;
29
- skills?: PendingConfigSkill[];
30
- mcpServers?: Array<{
31
- id: string;
32
- name?: string;
33
- url?: string;
34
- type?: string;
35
- command?: string;
36
- args?: string[];
37
- }>;
38
- nixPackages?: string[];
39
- grants?: string[];
40
- providers?: string[];
41
- }
42
-
43
- export async function getPendingConfigRequest(
44
- redis: Redis,
45
- requestId: string
46
- ): Promise<PendingConfigRequest | null> {
47
- const raw = await redis.get(`${CONFIG_REQUEST_KEY_PREFIX}${requestId}`);
48
- if (!raw) return null;
49
- try {
50
- return JSON.parse(raw) as PendingConfigRequest;
51
- } catch {
52
- return null;
53
- }
54
- }
55
-
56
- export async function deletePendingConfigRequest(
57
- redis: Redis,
58
- requestId: string
59
- ): Promise<void> {
60
- await redis.del(`${CONFIG_REQUEST_KEY_PREFIX}${requestId}`);
61
- }
62
-
63
- export function buildConfigRequestText(request: PendingConfigRequest): string {
64
- const lines = ["Configuration Change Request", `Reason: ${request.reason}`];
65
-
66
- if (request.message?.trim()) {
67
- lines.push(`Note: ${request.message.trim()}`);
68
- }
69
-
70
- if (request.skills?.length) {
71
- const names = request.skills.map((skill) => skill.name || skill.repo);
72
- lines.push(`Skills: ${names.join(", ")}`);
73
- }
74
-
75
- if (request.mcpServers?.length) {
76
- const ids = request.mcpServers.map((mcp) => mcp.name || mcp.id);
77
- lines.push(`MCP servers: ${ids.join(", ")}`);
78
- }
79
-
80
- if (request.nixPackages?.length) {
81
- lines.push(`Packages: ${request.nixPackages.join(", ")}`);
82
- }
83
-
84
- if (request.grants?.length) {
85
- lines.push(`Permissions: ${request.grants.join(", ")}`);
86
- }
87
-
88
- if (request.providers?.length) {
89
- lines.push(
90
- `Required providers (not changed by this approval): ${request.providers.join(", ")}`
91
- );
92
- }
93
-
94
- return lines.join("\n");
95
- }
96
-
97
- function mergeSkill(
98
- existingSkills: SkillConfig[],
99
- skill: PendingConfigSkill
100
- ): void {
101
- const nextSkill: SkillConfig = {
102
- repo: skill.repo,
103
- name: skill.name || skill.repo,
104
- description: skill.description || "",
105
- enabled: true,
106
- mcpServers: skill.mcpServers as SkillConfig["mcpServers"],
107
- nixPackages: skill.nixPackages,
108
- permissions: skill.permissions,
109
- providers: skill.providers,
110
- };
111
-
112
- const existingIndex = existingSkills.findIndex(
113
- (entry) => entry.repo === skill.repo
114
- );
115
-
116
- if (existingIndex >= 0 && existingSkills[existingIndex]) {
117
- existingSkills[existingIndex] = {
118
- ...existingSkills[existingIndex],
119
- ...nextSkill,
120
- enabled: true,
121
- };
122
- return;
123
- }
124
-
125
- existingSkills.push(nextSkill);
126
- }
127
-
128
- function mergeMcpServers(
129
- current: Record<string, Record<string, unknown>>,
130
- mcpServers: NonNullable<PendingConfigRequest["mcpServers"]>
131
- ): Record<string, Record<string, unknown>> {
132
- const merged = { ...current };
133
-
134
- for (const mcp of mcpServers) {
135
- const existing = merged[mcp.id] || {};
136
- merged[mcp.id] = {
137
- ...existing,
138
- enabled: true,
139
- ...(mcp.url ? { url: mcp.url } : {}),
140
- ...(mcp.type ? { type: mcp.type } : {}),
141
- ...(mcp.command ? { command: mcp.command } : {}),
142
- ...(mcp.args?.length ? { args: mcp.args } : {}),
143
- ...(mcp.name ? { name: mcp.name } : {}),
144
- };
145
- }
146
-
147
- return merged;
148
- }
149
-
150
- export async function applyPendingConfigRequest(
151
- agentSettingsStore: AgentSettingsStore,
152
- grantStore: GrantStore | undefined,
153
- request: PendingConfigRequest
154
- ): Promise<void> {
155
- const settings = await agentSettingsStore.getSettings(request.agentId);
156
- const nextSkills = [...(settings?.skillsConfig?.skills || [])];
157
-
158
- for (const skill of request.skills || []) {
159
- mergeSkill(nextSkills, skill);
160
- }
161
-
162
- const nextMcpServers = mergeMcpServers(
163
- (settings?.mcpServers || {}) as Record<string, Record<string, unknown>>,
164
- request.mcpServers || []
165
- );
166
-
167
- const existingPackages = settings?.nixConfig?.packages || [];
168
- const nextPackages = Array.from(
169
- new Set([...(existingPackages || []), ...(request.nixPackages || [])])
170
- );
171
-
172
- const updates: Record<string, unknown> = {};
173
- if (request.skills?.length) {
174
- updates.skillsConfig = { skills: nextSkills };
175
- }
176
- if (request.mcpServers?.length) {
177
- updates.mcpServers = nextMcpServers;
178
- }
179
- if (request.nixPackages?.length) {
180
- updates.nixConfig = {
181
- ...(settings?.nixConfig || {}),
182
- packages: nextPackages,
183
- };
184
- }
185
-
186
- if (Object.keys(updates).length > 0) {
187
- await agentSettingsStore.updateSettings(
188
- request.agentId,
189
- updates as Record<string, any>
190
- );
191
- }
192
-
193
- if (grantStore && request.grants?.length) {
194
- for (const pattern of request.grants) {
195
- await grantStore.grant(request.agentId, pattern, null);
196
- }
197
- }
198
- }
@@ -1,363 +0,0 @@
1
- #!/usr/bin/env bun
2
-
3
- import { randomUUID } from "node:crypto";
4
- import { EventEmitter } from "node:events";
5
- import { createLogger, type UserSuggestion } from "@lobu/core";
6
-
7
- const logger = createLogger("interactions");
8
-
9
- /**
10
- * Payload emitted on "question:created" — platform renderers listen for this.
11
- */
12
- export interface PostedQuestion {
13
- id: string;
14
- userId: string;
15
- conversationId: string;
16
- channelId: string;
17
- teamId?: string;
18
- connectionId?: string;
19
- question: string;
20
- options: string[];
21
- }
22
-
23
- /**
24
- * Payload emitted on "link-button:created" — platform renderers listen for this.
25
- */
26
- export interface PostedLinkButton {
27
- id: string;
28
- userId: string;
29
- conversationId: string;
30
- channelId: string;
31
- teamId?: string;
32
- connectionId?: string;
33
- platform: string;
34
- url: string;
35
- label: string;
36
- linkType: "settings" | "install" | "oauth";
37
- }
38
-
39
- /**
40
- * Payload emitted on "grant:requested" — platform renderers listen for this.
41
- */
42
- export interface PostedGrantRequest {
43
- id: string;
44
- userId: string;
45
- agentId: string;
46
- conversationId: string;
47
- channelId: string;
48
- teamId?: string;
49
- connectionId?: string;
50
- domains: string[];
51
- reason: string;
52
- }
53
-
54
- /**
55
- * Payload emitted on "package:requested" — platform renderers listen for this.
56
- */
57
- export interface PostedPackageRequest {
58
- id: string;
59
- userId: string;
60
- agentId: string;
61
- conversationId: string;
62
- channelId: string;
63
- teamId?: string;
64
- packages: string[];
65
- reason: string;
66
- }
67
-
68
- /**
69
- * Payload emitted on "config:requested" — platform renderers listen for this.
70
- */
71
- export interface PostedConfigRequest {
72
- id: string;
73
- userId: string;
74
- agentId: string;
75
- conversationId: string;
76
- channelId: string;
77
- teamId?: string;
78
- connectionId?: string;
79
- text: string;
80
- }
81
-
82
- /**
83
- * Payload emitted on "status-message:created" — platform renderers listen for this.
84
- */
85
- export interface PostedStatusMessage {
86
- id: string;
87
- conversationId: string;
88
- channelId: string;
89
- teamId?: string;
90
- connectionId?: string;
91
- platform: string;
92
- text: string;
93
- }
94
-
95
- /**
96
- * Platform-agnostic interaction service (fire-and-forget).
97
- * Posts questions with buttons; no Redis, no blocking, no state machine.
98
- * User clicks → platform converts to regular message → normal queue.
99
- */
100
- export class InteractionService extends EventEmitter {
101
- private beforeCreateHook?: (
102
- userId: string,
103
- conversationId: string
104
- ) => Promise<void>;
105
-
106
- /**
107
- * Set a hook to run before creating interactions.
108
- * Used by platforms to stop streams before interaction messages appear.
109
- */
110
- setBeforeCreateHook(
111
- hook: (userId: string, conversationId: string) => Promise<void>
112
- ): void {
113
- this.beforeCreateHook = hook;
114
- }
115
-
116
- /**
117
- * Post a question with button options (non-blocking, fire-and-forget).
118
- * Emits "question:created" for platform renderers.
119
- */
120
- async postQuestion(
121
- userId: string,
122
- conversationId: string,
123
- channelId: string,
124
- teamId: string | undefined,
125
- connectionId: string | undefined,
126
- question: string,
127
- options: string[]
128
- ): Promise<PostedQuestion> {
129
- if (this.beforeCreateHook) {
130
- await this.beforeCreateHook(userId, conversationId);
131
- }
132
-
133
- const posted: PostedQuestion = {
134
- id: `q_${randomUUID()}`,
135
- userId,
136
- conversationId,
137
- channelId,
138
- teamId,
139
- connectionId,
140
- question,
141
- options,
142
- };
143
-
144
- logger.info(
145
- `Posted question ${posted.id} for conversation ${conversationId}`
146
- );
147
-
148
- this.emit("question:created", posted);
149
- return posted;
150
- }
151
-
152
- /**
153
- * Post a grant request with approve/deny buttons (non-blocking, fire-and-forget).
154
- * Emits "grant:requested" for platform renderers.
155
- */
156
- async postGrantRequest(
157
- userId: string,
158
- agentId: string,
159
- conversationId: string,
160
- channelId: string,
161
- teamId: string | undefined,
162
- connectionId: string | undefined,
163
- domains: string[],
164
- reason: string
165
- ): Promise<PostedGrantRequest> {
166
- if (this.beforeCreateHook) {
167
- await this.beforeCreateHook(userId, conversationId);
168
- }
169
-
170
- const posted: PostedGrantRequest = {
171
- id: `gr_${randomUUID()}`,
172
- userId,
173
- agentId,
174
- conversationId,
175
- channelId,
176
- teamId,
177
- connectionId,
178
- domains,
179
- reason,
180
- };
181
-
182
- logger.info(
183
- `Posted grant request ${posted.id} for agent ${agentId} domains=${domains.join(",")}`
184
- );
185
-
186
- this.emit("grant:requested", posted);
187
- return posted;
188
- }
189
-
190
- /**
191
- * Post a package install request with approve/deny buttons (non-blocking, fire-and-forget).
192
- * Emits "package:requested" for platform renderers.
193
- */
194
- async postPackageRequest(
195
- userId: string,
196
- agentId: string,
197
- conversationId: string,
198
- channelId: string,
199
- teamId: string | undefined,
200
- packages: string[],
201
- reason: string
202
- ): Promise<PostedPackageRequest> {
203
- if (this.beforeCreateHook) {
204
- await this.beforeCreateHook(userId, conversationId);
205
- }
206
-
207
- const posted: PostedPackageRequest = {
208
- id: `pkg_${randomUUID()}`,
209
- userId,
210
- agentId,
211
- conversationId,
212
- channelId,
213
- teamId,
214
- packages,
215
- reason,
216
- };
217
-
218
- logger.info(
219
- `Posted package request ${posted.id} for agent ${agentId} packages=${packages.join(",")}`
220
- );
221
-
222
- this.emit("package:requested", posted);
223
- return posted;
224
- }
225
-
226
- /**
227
- * Post a config request with approve/deny buttons (non-blocking).
228
- * Emits "config:requested" for platform renderers.
229
- */
230
- async postConfigRequest(
231
- userId: string,
232
- agentId: string,
233
- conversationId: string,
234
- channelId: string,
235
- teamId: string | undefined,
236
- connectionId: string | undefined,
237
- text: string
238
- ): Promise<PostedConfigRequest> {
239
- if (this.beforeCreateHook) {
240
- await this.beforeCreateHook(userId, conversationId);
241
- }
242
-
243
- const posted: PostedConfigRequest = {
244
- id: `cfg_${randomUUID()}`,
245
- userId,
246
- agentId,
247
- conversationId,
248
- channelId,
249
- teamId,
250
- connectionId,
251
- text,
252
- };
253
-
254
- logger.info(
255
- `Posted config request ${posted.id} for agent ${agentId} conversation ${conversationId}`
256
- );
257
-
258
- this.emit("config:requested", posted);
259
- return posted;
260
- }
261
-
262
- /**
263
- * Post a link button (non-blocking, fire-and-forget).
264
- * Emits "link-button:created" for platform renderers.
265
- */
266
- async postLinkButton(
267
- userId: string,
268
- conversationId: string,
269
- channelId: string,
270
- teamId: string | undefined,
271
- connectionId: string | undefined,
272
- platform: string,
273
- url: string,
274
- label: string,
275
- linkType: "settings" | "install" | "oauth"
276
- ): Promise<PostedLinkButton> {
277
- if (this.beforeCreateHook) {
278
- await this.beforeCreateHook(userId, conversationId);
279
- }
280
-
281
- const posted: PostedLinkButton = {
282
- id: `lb_${randomUUID()}`,
283
- userId,
284
- conversationId,
285
- channelId,
286
- teamId,
287
- connectionId,
288
- platform,
289
- url,
290
- label,
291
- linkType,
292
- };
293
-
294
- logger.info(
295
- `Posted link button ${posted.id} for conversation ${conversationId} (${linkType})`
296
- );
297
-
298
- this.emit("link-button:created", posted);
299
- return posted;
300
- }
301
-
302
- /**
303
- * Post a plain text status message (non-blocking, fire-and-forget).
304
- * Emits "status-message:created" for platform renderers.
305
- */
306
- async postStatusMessage(
307
- conversationId: string,
308
- channelId: string,
309
- teamId: string | undefined,
310
- connectionId: string | undefined,
311
- platform: string,
312
- text: string
313
- ): Promise<PostedStatusMessage> {
314
- if (this.beforeCreateHook) {
315
- await this.beforeCreateHook("", conversationId);
316
- }
317
-
318
- const posted: PostedStatusMessage = {
319
- id: `sm_${randomUUID()}`,
320
- conversationId,
321
- channelId,
322
- teamId,
323
- connectionId,
324
- platform,
325
- text,
326
- };
327
-
328
- logger.info(
329
- `Posted status message ${posted.id} for conversation ${conversationId}`
330
- );
331
-
332
- this.emit("status-message:created", posted);
333
- return posted;
334
- }
335
-
336
- /**
337
- * Create non-blocking suggestions.
338
- * Emits event immediately, no state tracking needed.
339
- */
340
- async createSuggestion(
341
- userId: string,
342
- conversationId: string,
343
- channelId: string,
344
- teamId: string | undefined,
345
- prompts: Array<{ title: string; message: string }>
346
- ): Promise<void> {
347
- const suggestion: UserSuggestion = {
348
- id: `sug_${randomUUID()}`,
349
- userId,
350
- conversationId,
351
- channelId,
352
- teamId,
353
- blocking: false,
354
- prompts,
355
- };
356
-
357
- logger.info(
358
- `Created suggestion ${suggestion.id} for conversation ${conversationId}`
359
- );
360
-
361
- this.emit("suggestion:created", suggestion);
362
- }
363
- }