@lobu/gateway 3.0.5 → 3.0.6
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.
- package/package.json +2 -2
- package/src/__tests__/agent-config-routes.test.ts +254 -0
- package/src/__tests__/agent-history-routes.test.ts +72 -0
- package/src/__tests__/agent-routes.test.ts +68 -0
- package/src/__tests__/agent-schedules-routes.test.ts +59 -0
- package/src/__tests__/agent-settings-store.test.ts +323 -0
- package/src/__tests__/chat-instance-manager-slack.test.ts +204 -0
- package/src/__tests__/chat-response-bridge.test.ts +131 -0
- package/src/__tests__/config-memory-plugins.test.ts +92 -0
- package/src/__tests__/config-request-store.test.ts +127 -0
- package/src/__tests__/connection-routes.test.ts +144 -0
- package/src/__tests__/core-services-store-selection.test.ts +92 -0
- package/src/__tests__/docker-deployment.test.ts +1211 -0
- package/src/__tests__/embedded-deployment.test.ts +342 -0
- package/src/__tests__/grant-store.test.ts +148 -0
- package/src/__tests__/http-proxy.test.ts +281 -0
- package/src/__tests__/instruction-service.test.ts +37 -0
- package/src/__tests__/link-buttons.test.ts +112 -0
- package/src/__tests__/lobu.test.ts +32 -0
- package/src/__tests__/mcp-config-service.test.ts +347 -0
- package/src/__tests__/mcp-proxy.test.ts +696 -0
- package/src/__tests__/message-handler-bridge.test.ts +17 -0
- package/src/__tests__/model-selection.test.ts +172 -0
- package/src/__tests__/oauth-templates.test.ts +39 -0
- package/src/__tests__/platform-adapter-slack-send.test.ts +114 -0
- package/src/__tests__/platform-helpers-model-resolution.test.ts +253 -0
- package/src/__tests__/provider-inheritance.test.ts +212 -0
- package/src/__tests__/routes/cli-auth.test.ts +337 -0
- package/src/__tests__/routes/interactions.test.ts +121 -0
- package/src/__tests__/secret-proxy.test.ts +85 -0
- package/src/__tests__/session-manager.test.ts +572 -0
- package/src/__tests__/setup.ts +133 -0
- package/src/__tests__/skill-and-mcp-registry.test.ts +203 -0
- package/src/__tests__/slack-routes.test.ts +161 -0
- package/src/__tests__/system-config-resolver.test.ts +75 -0
- package/src/__tests__/system-message-limiter.test.ts +89 -0
- package/src/__tests__/system-skills-service.test.ts +362 -0
- package/src/__tests__/transcription-service.test.ts +222 -0
- package/src/__tests__/utils/rate-limiter.test.ts +102 -0
- package/src/__tests__/worker-connection-manager.test.ts +497 -0
- package/src/__tests__/worker-job-router.test.ts +722 -0
- package/src/api/index.ts +1 -0
- package/src/api/platform.ts +292 -0
- package/src/api/response-renderer.ts +157 -0
- package/src/auth/agent-metadata-store.ts +168 -0
- package/src/auth/api-auth-middleware.ts +69 -0
- package/src/auth/api-key-provider-module.ts +213 -0
- package/src/auth/base-provider-module.ts +201 -0
- package/src/auth/chatgpt/chatgpt-oauth-module.ts +185 -0
- package/src/auth/chatgpt/device-code-client.ts +218 -0
- package/src/auth/chatgpt/index.ts +1 -0
- package/src/auth/claude/oauth-module.ts +280 -0
- package/src/auth/cli/token-service.ts +249 -0
- package/src/auth/external/client.ts +560 -0
- package/src/auth/external/device-code-client.ts +225 -0
- package/src/auth/mcp/config-service.ts +392 -0
- package/src/auth/mcp/proxy.ts +1088 -0
- package/src/auth/mcp/string-substitution.ts +17 -0
- package/src/auth/mcp/tool-cache.ts +90 -0
- package/src/auth/oauth/base-client.ts +267 -0
- package/src/auth/oauth/client.ts +153 -0
- package/src/auth/oauth/credentials.ts +7 -0
- package/src/auth/oauth/providers.ts +69 -0
- package/src/auth/oauth/state-store.ts +150 -0
- package/src/auth/oauth-templates.ts +179 -0
- package/src/auth/provider-catalog.ts +220 -0
- package/src/auth/provider-model-options.ts +41 -0
- package/src/auth/settings/agent-settings-store.ts +565 -0
- package/src/auth/settings/auth-profiles-manager.ts +216 -0
- package/src/auth/settings/index.ts +12 -0
- package/src/auth/settings/model-preference-store.ts +52 -0
- package/src/auth/settings/model-selection.ts +135 -0
- package/src/auth/settings/resolved-settings-view.ts +298 -0
- package/src/auth/settings/template-utils.ts +44 -0
- package/src/auth/settings/token-service.ts +88 -0
- package/src/auth/system-env-store.ts +98 -0
- package/src/auth/user-agents-store.ts +68 -0
- package/src/channels/binding-service.ts +214 -0
- package/src/channels/index.ts +4 -0
- package/src/cli/gateway.ts +1304 -0
- package/src/cli/index.ts +74 -0
- package/src/commands/built-in-commands.ts +80 -0
- package/src/commands/command-dispatcher.ts +94 -0
- package/src/commands/command-reply-adapters.ts +27 -0
- package/src/config/file-loader.ts +618 -0
- package/src/config/index.ts +588 -0
- package/src/config/network-allowlist.ts +71 -0
- package/src/connections/chat-instance-manager.ts +1284 -0
- package/src/connections/chat-response-bridge.ts +618 -0
- package/src/connections/index.ts +7 -0
- package/src/connections/interaction-bridge.ts +831 -0
- package/src/connections/message-handler-bridge.ts +415 -0
- package/src/connections/platform-auth-methods.ts +15 -0
- package/src/connections/types.ts +84 -0
- package/src/gateway/connection-manager.ts +291 -0
- package/src/gateway/index.ts +700 -0
- package/src/gateway/job-router.ts +201 -0
- package/src/gateway-main.ts +200 -0
- package/src/index.ts +41 -0
- package/src/infrastructure/queue/index.ts +12 -0
- package/src/infrastructure/queue/queue-producer.ts +148 -0
- package/src/infrastructure/queue/redis-queue.ts +361 -0
- package/src/infrastructure/queue/types.ts +133 -0
- package/src/infrastructure/redis/system-message-limiter.ts +94 -0
- package/src/interactions/config-request-store.ts +198 -0
- package/src/interactions.ts +363 -0
- package/src/lobu.ts +311 -0
- package/src/metrics/prometheus.ts +159 -0
- package/src/modules/module-system.ts +179 -0
- package/src/orchestration/base-deployment-manager.ts +900 -0
- package/src/orchestration/deployment-utils.ts +98 -0
- package/src/orchestration/impl/docker-deployment.ts +620 -0
- package/src/orchestration/impl/embedded-deployment.ts +268 -0
- package/src/orchestration/impl/index.ts +8 -0
- package/src/orchestration/impl/k8s/deployment.ts +1061 -0
- package/src/orchestration/impl/k8s/helpers.ts +610 -0
- package/src/orchestration/impl/k8s/index.ts +1 -0
- package/src/orchestration/index.ts +333 -0
- package/src/orchestration/message-consumer.ts +584 -0
- package/src/orchestration/scheduled-wakeup.ts +704 -0
- package/src/permissions/approval-policy.ts +36 -0
- package/src/permissions/grant-store.ts +219 -0
- package/src/platform/file-handler.ts +66 -0
- package/src/platform/link-buttons.ts +57 -0
- package/src/platform/renderer-utils.ts +44 -0
- package/src/platform/response-renderer.ts +84 -0
- package/src/platform/unified-thread-consumer.ts +187 -0
- package/src/platform.ts +318 -0
- package/src/proxy/http-proxy.ts +752 -0
- package/src/proxy/proxy-manager.ts +81 -0
- package/src/proxy/secret-proxy.ts +402 -0
- package/src/proxy/token-refresh-job.ts +143 -0
- package/src/routes/internal/audio.ts +141 -0
- package/src/routes/internal/device-auth.ts +566 -0
- package/src/routes/internal/files.ts +226 -0
- package/src/routes/internal/history.ts +69 -0
- package/src/routes/internal/images.ts +127 -0
- package/src/routes/internal/interactions.ts +84 -0
- package/src/routes/internal/middleware.ts +23 -0
- package/src/routes/internal/schedule.ts +226 -0
- package/src/routes/internal/types.ts +22 -0
- package/src/routes/openapi-auto.ts +239 -0
- package/src/routes/public/agent-access.ts +23 -0
- package/src/routes/public/agent-config.ts +675 -0
- package/src/routes/public/agent-history.ts +422 -0
- package/src/routes/public/agent-schedules.ts +296 -0
- package/src/routes/public/agent.ts +1086 -0
- package/src/routes/public/agents.ts +373 -0
- package/src/routes/public/channels.ts +191 -0
- package/src/routes/public/cli-auth.ts +883 -0
- package/src/routes/public/connections.ts +574 -0
- package/src/routes/public/landing.ts +16 -0
- package/src/routes/public/oauth.ts +147 -0
- package/src/routes/public/settings-auth.ts +104 -0
- package/src/routes/public/slack.ts +173 -0
- package/src/routes/shared/agent-ownership.ts +101 -0
- package/src/routes/shared/token-verifier.ts +34 -0
- package/src/services/core-services.ts +1053 -0
- package/src/services/image-generation-service.ts +257 -0
- package/src/services/instruction-service.ts +318 -0
- package/src/services/mcp-registry.ts +94 -0
- package/src/services/platform-helpers.ts +287 -0
- package/src/services/session-manager.ts +262 -0
- package/src/services/settings-resolver.ts +74 -0
- package/src/services/system-config-resolver.ts +90 -0
- package/src/services/system-skills-service.ts +229 -0
- package/src/services/transcription-service.ts +684 -0
- package/src/session.ts +110 -0
- package/src/spaces/index.ts +1 -0
- package/src/spaces/space-resolver.ts +17 -0
- package/src/stores/in-memory-agent-store.ts +403 -0
- package/src/stores/redis-agent-store.ts +279 -0
- package/src/utils/public-url.ts +44 -0
- package/src/utils/rate-limiter.ts +94 -0
- package/tsconfig.json +33 -0
|
@@ -0,0 +1,198 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,363 @@
|
|
|
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
|
+
}
|