@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.
- package/dist/api/platform.d.ts.map +1 -1
- package/dist/api/platform.js +8 -26
- package/dist/api/platform.js.map +1 -1
- package/dist/auth/mcp/proxy.d.ts +14 -0
- package/dist/auth/mcp/proxy.d.ts.map +1 -1
- package/dist/auth/mcp/proxy.js +149 -13
- package/dist/auth/mcp/proxy.js.map +1 -1
- package/dist/cli/gateway.d.ts.map +1 -1
- package/dist/cli/gateway.js +29 -0
- package/dist/cli/gateway.js.map +1 -1
- package/dist/cli/index.js +2 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/connections/chat-instance-manager.d.ts.map +1 -1
- package/dist/connections/chat-instance-manager.js +2 -1
- package/dist/connections/chat-instance-manager.js.map +1 -1
- package/dist/connections/interaction-bridge.d.ts +9 -2
- package/dist/connections/interaction-bridge.d.ts.map +1 -1
- package/dist/connections/interaction-bridge.js +132 -230
- package/dist/connections/interaction-bridge.js.map +1 -1
- package/dist/connections/message-handler-bridge.d.ts.map +1 -1
- package/dist/connections/message-handler-bridge.js +44 -26
- package/dist/connections/message-handler-bridge.js.map +1 -1
- package/dist/interactions.d.ts +9 -43
- package/dist/interactions.d.ts.map +1 -1
- package/dist/interactions.js +10 -52
- package/dist/interactions.js.map +1 -1
- package/dist/orchestration/base-deployment-manager.js +7 -7
- package/dist/orchestration/base-deployment-manager.js.map +1 -1
- package/dist/platform/unified-thread-consumer.d.ts.map +1 -1
- package/dist/platform/unified-thread-consumer.js +38 -34
- package/dist/platform/unified-thread-consumer.js.map +1 -1
- package/dist/routes/public/agent.d.ts +4 -0
- package/dist/routes/public/agent.d.ts.map +1 -1
- package/dist/routes/public/agent.js +21 -0
- package/dist/routes/public/agent.js.map +1 -1
- package/dist/services/core-services.d.ts.map +1 -1
- package/dist/services/core-services.js +4 -0
- package/dist/services/core-services.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/agent-config-routes.test.ts +0 -254
- package/src/__tests__/agent-history-routes.test.ts +0 -72
- package/src/__tests__/agent-routes.test.ts +0 -68
- package/src/__tests__/agent-schedules-routes.test.ts +0 -59
- package/src/__tests__/agent-settings-store.test.ts +0 -323
- package/src/__tests__/bedrock-model-catalog.test.ts +0 -40
- package/src/__tests__/bedrock-openai-service.test.ts +0 -157
- package/src/__tests__/bedrock-provider-module.test.ts +0 -56
- package/src/__tests__/chat-instance-manager-slack.test.ts +0 -204
- package/src/__tests__/chat-response-bridge.test.ts +0 -131
- package/src/__tests__/config-memory-plugins.test.ts +0 -92
- package/src/__tests__/config-request-store.test.ts +0 -127
- package/src/__tests__/connection-routes.test.ts +0 -144
- package/src/__tests__/core-services-store-selection.test.ts +0 -92
- package/src/__tests__/docker-deployment.test.ts +0 -1211
- package/src/__tests__/embedded-deployment.test.ts +0 -342
- package/src/__tests__/grant-store.test.ts +0 -148
- package/src/__tests__/http-proxy.test.ts +0 -281
- package/src/__tests__/instruction-service.test.ts +0 -37
- package/src/__tests__/link-buttons.test.ts +0 -112
- package/src/__tests__/lobu.test.ts +0 -32
- package/src/__tests__/mcp-config-service.test.ts +0 -347
- package/src/__tests__/mcp-proxy.test.ts +0 -694
- package/src/__tests__/message-handler-bridge.test.ts +0 -17
- package/src/__tests__/model-selection.test.ts +0 -172
- package/src/__tests__/oauth-templates.test.ts +0 -39
- package/src/__tests__/platform-adapter-slack-send.test.ts +0 -114
- package/src/__tests__/platform-helpers-model-resolution.test.ts +0 -253
- package/src/__tests__/provider-inheritance.test.ts +0 -212
- package/src/__tests__/routes/cli-auth.test.ts +0 -337
- package/src/__tests__/routes/interactions.test.ts +0 -121
- package/src/__tests__/secret-proxy.test.ts +0 -85
- package/src/__tests__/session-manager.test.ts +0 -572
- package/src/__tests__/setup.ts +0 -133
- package/src/__tests__/skill-and-mcp-registry.test.ts +0 -203
- package/src/__tests__/slack-routes.test.ts +0 -161
- package/src/__tests__/system-config-resolver.test.ts +0 -75
- package/src/__tests__/system-message-limiter.test.ts +0 -89
- package/src/__tests__/system-skills-service.test.ts +0 -362
- package/src/__tests__/transcription-service.test.ts +0 -222
- package/src/__tests__/utils/rate-limiter.test.ts +0 -102
- package/src/__tests__/worker-connection-manager.test.ts +0 -497
- package/src/__tests__/worker-job-router.test.ts +0 -722
- package/src/api/index.ts +0 -1
- package/src/api/platform.ts +0 -292
- package/src/api/response-renderer.ts +0 -157
- package/src/auth/agent-metadata-store.ts +0 -168
- package/src/auth/api-auth-middleware.ts +0 -69
- package/src/auth/api-key-provider-module.ts +0 -213
- package/src/auth/base-provider-module.ts +0 -201
- package/src/auth/bedrock/provider-module.ts +0 -110
- package/src/auth/chatgpt/chatgpt-oauth-module.ts +0 -185
- package/src/auth/chatgpt/device-code-client.ts +0 -218
- package/src/auth/chatgpt/index.ts +0 -1
- package/src/auth/claude/oauth-module.ts +0 -280
- package/src/auth/cli/token-service.ts +0 -249
- package/src/auth/external/client.ts +0 -560
- package/src/auth/external/device-code-client.ts +0 -235
- package/src/auth/mcp/config-service.ts +0 -420
- package/src/auth/mcp/proxy.ts +0 -1086
- package/src/auth/mcp/string-substitution.ts +0 -17
- package/src/auth/mcp/tool-cache.ts +0 -90
- package/src/auth/oauth/base-client.ts +0 -267
- package/src/auth/oauth/client.ts +0 -153
- package/src/auth/oauth/credentials.ts +0 -7
- package/src/auth/oauth/providers.ts +0 -69
- package/src/auth/oauth/state-store.ts +0 -150
- package/src/auth/oauth-templates.ts +0 -179
- package/src/auth/provider-catalog.ts +0 -220
- package/src/auth/provider-model-options.ts +0 -41
- package/src/auth/settings/agent-settings-store.ts +0 -565
- package/src/auth/settings/auth-profiles-manager.ts +0 -216
- package/src/auth/settings/index.ts +0 -12
- package/src/auth/settings/model-preference-store.ts +0 -52
- package/src/auth/settings/model-selection.ts +0 -135
- package/src/auth/settings/resolved-settings-view.ts +0 -298
- package/src/auth/settings/template-utils.ts +0 -44
- package/src/auth/settings/token-service.ts +0 -88
- package/src/auth/system-env-store.ts +0 -98
- package/src/auth/user-agents-store.ts +0 -68
- package/src/channels/binding-service.ts +0 -214
- package/src/channels/index.ts +0 -4
- package/src/cli/gateway.ts +0 -1312
- package/src/cli/index.ts +0 -74
- package/src/commands/built-in-commands.ts +0 -80
- package/src/commands/command-dispatcher.ts +0 -94
- package/src/commands/command-reply-adapters.ts +0 -27
- package/src/config/file-loader.ts +0 -618
- package/src/config/index.ts +0 -588
- package/src/config/network-allowlist.ts +0 -71
- package/src/connections/chat-instance-manager.ts +0 -1284
- package/src/connections/chat-response-bridge.ts +0 -618
- package/src/connections/index.ts +0 -7
- package/src/connections/interaction-bridge.ts +0 -831
- package/src/connections/message-handler-bridge.ts +0 -415
- package/src/connections/platform-auth-methods.ts +0 -15
- package/src/connections/types.ts +0 -84
- package/src/gateway/connection-manager.ts +0 -291
- package/src/gateway/index.ts +0 -698
- package/src/gateway/job-router.ts +0 -201
- package/src/gateway-main.ts +0 -200
- package/src/index.ts +0 -41
- package/src/infrastructure/queue/index.ts +0 -12
- package/src/infrastructure/queue/queue-producer.ts +0 -148
- package/src/infrastructure/queue/redis-queue.ts +0 -361
- package/src/infrastructure/queue/types.ts +0 -133
- package/src/infrastructure/redis/system-message-limiter.ts +0 -94
- package/src/interactions/config-request-store.ts +0 -198
- package/src/interactions.ts +0 -363
- package/src/lobu.ts +0 -311
- package/src/metrics/prometheus.ts +0 -159
- package/src/modules/module-system.ts +0 -179
- package/src/orchestration/base-deployment-manager.ts +0 -900
- package/src/orchestration/deployment-utils.ts +0 -98
- package/src/orchestration/impl/docker-deployment.ts +0 -620
- package/src/orchestration/impl/embedded-deployment.ts +0 -268
- package/src/orchestration/impl/index.ts +0 -8
- package/src/orchestration/impl/k8s/deployment.ts +0 -1061
- package/src/orchestration/impl/k8s/helpers.ts +0 -610
- package/src/orchestration/impl/k8s/index.ts +0 -1
- package/src/orchestration/index.ts +0 -333
- package/src/orchestration/message-consumer.ts +0 -584
- package/src/orchestration/scheduled-wakeup.ts +0 -704
- package/src/permissions/approval-policy.ts +0 -36
- package/src/permissions/grant-store.ts +0 -219
- package/src/platform/file-handler.ts +0 -66
- package/src/platform/link-buttons.ts +0 -57
- package/src/platform/renderer-utils.ts +0 -44
- package/src/platform/response-renderer.ts +0 -84
- package/src/platform/unified-thread-consumer.ts +0 -187
- package/src/platform.ts +0 -318
- package/src/proxy/http-proxy.ts +0 -752
- package/src/proxy/proxy-manager.ts +0 -81
- package/src/proxy/secret-proxy.ts +0 -402
- package/src/proxy/token-refresh-job.ts +0 -143
- package/src/routes/internal/audio.ts +0 -141
- package/src/routes/internal/device-auth.ts +0 -652
- package/src/routes/internal/files.ts +0 -226
- package/src/routes/internal/history.ts +0 -69
- package/src/routes/internal/images.ts +0 -127
- package/src/routes/internal/interactions.ts +0 -84
- package/src/routes/internal/middleware.ts +0 -23
- package/src/routes/internal/schedule.ts +0 -226
- package/src/routes/internal/types.ts +0 -22
- package/src/routes/openapi-auto.ts +0 -239
- package/src/routes/public/agent-access.ts +0 -23
- package/src/routes/public/agent-config.ts +0 -675
- package/src/routes/public/agent-history.ts +0 -422
- package/src/routes/public/agent-schedules.ts +0 -296
- package/src/routes/public/agent.ts +0 -1086
- package/src/routes/public/agents.ts +0 -373
- package/src/routes/public/channels.ts +0 -191
- package/src/routes/public/cli-auth.ts +0 -896
- package/src/routes/public/connections.ts +0 -574
- package/src/routes/public/landing.ts +0 -16
- package/src/routes/public/oauth.ts +0 -147
- package/src/routes/public/settings-auth.ts +0 -104
- package/src/routes/public/slack.ts +0 -173
- package/src/routes/shared/agent-ownership.ts +0 -101
- package/src/routes/shared/token-verifier.ts +0 -34
- package/src/services/bedrock-model-catalog.ts +0 -217
- package/src/services/bedrock-openai-service.ts +0 -658
- package/src/services/core-services.ts +0 -1072
- package/src/services/image-generation-service.ts +0 -257
- package/src/services/instruction-service.ts +0 -318
- package/src/services/mcp-registry.ts +0 -94
- package/src/services/platform-helpers.ts +0 -287
- package/src/services/session-manager.ts +0 -262
- package/src/services/settings-resolver.ts +0 -74
- package/src/services/system-config-resolver.ts +0 -89
- package/src/services/system-skills-service.ts +0 -229
- package/src/services/transcription-service.ts +0 -684
- package/src/session.ts +0 -110
- package/src/spaces/index.ts +0 -1
- package/src/spaces/space-resolver.ts +0 -17
- package/src/stores/in-memory-agent-store.ts +0 -403
- package/src/stores/redis-agent-store.ts +0 -279
- package/src/utils/public-url.ts +0 -44
- package/src/utils/rate-limiter.ts +0 -94
- package/tsconfig.json +0 -33
|
@@ -1,574 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Connection routes + webhook endpoint.
|
|
3
|
-
*
|
|
4
|
-
* Webhook: POST /api/v1/webhooks/:connectionId
|
|
5
|
-
* Read-only (auth: settings session cookie):
|
|
6
|
-
* GET /api/v1/connections
|
|
7
|
-
* GET /api/v1/connections/:id
|
|
8
|
-
* GET /api/v1/connections/:id/sandboxes
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|
12
|
-
import type { AgentConfigStore } from "@lobu/core";
|
|
13
|
-
import { createLogger } from "@lobu/core";
|
|
14
|
-
import { Hono } from "hono";
|
|
15
|
-
import type { UserAgentsStore } from "../../auth/user-agents-store";
|
|
16
|
-
import type { ChatInstanceManager } from "../../connections/chat-instance-manager";
|
|
17
|
-
import { verifyAgentAccess } from "./agent-access";
|
|
18
|
-
import { verifySettingsSession } from "./settings-auth";
|
|
19
|
-
|
|
20
|
-
const logger = createLogger("connection-routes");
|
|
21
|
-
const TAG = "Connections";
|
|
22
|
-
const ErrorResponseSchema = z.object({ error: z.string() });
|
|
23
|
-
const FlexibleObjectSchema = z.record(z.string(), z.unknown());
|
|
24
|
-
|
|
25
|
-
const UserConfigScopeSchema = z.enum([
|
|
26
|
-
"model",
|
|
27
|
-
"view-model",
|
|
28
|
-
"system-prompt",
|
|
29
|
-
"skills",
|
|
30
|
-
"schedules",
|
|
31
|
-
"permissions",
|
|
32
|
-
"packages",
|
|
33
|
-
]);
|
|
34
|
-
|
|
35
|
-
const ConnectionSettingsSchema = z.object({
|
|
36
|
-
allowFrom: z.array(z.string()).optional().openapi({
|
|
37
|
-
description:
|
|
38
|
-
"User IDs allowed to interact with this connection. Omit to allow all; empty array blocks all.",
|
|
39
|
-
}),
|
|
40
|
-
allowGroups: z.boolean().optional().openapi({
|
|
41
|
-
description: "Whether group messages are allowed (default true).",
|
|
42
|
-
}),
|
|
43
|
-
userConfigScopes: z.array(UserConfigScopeSchema).optional().openapi({
|
|
44
|
-
description:
|
|
45
|
-
"Scopes that end users are allowed to customize. Empty = no restrictions.",
|
|
46
|
-
}),
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const LOCAL_TEST_PLATFORMS = ["slack", "telegram", "whatsapp"] as const;
|
|
50
|
-
|
|
51
|
-
async function getLocalTestDefaultTarget(
|
|
52
|
-
manager: ChatInstanceManager,
|
|
53
|
-
connectionId: string
|
|
54
|
-
): Promise<string | undefined> {
|
|
55
|
-
const redis = manager.getServices().getQueue().getRedisClient();
|
|
56
|
-
const prefix = `chat:history:${connectionId}:`;
|
|
57
|
-
let cursor = "0";
|
|
58
|
-
|
|
59
|
-
do {
|
|
60
|
-
const [nextCursor, keys] = await redis.scan(
|
|
61
|
-
cursor,
|
|
62
|
-
"MATCH",
|
|
63
|
-
`${prefix}*`,
|
|
64
|
-
"COUNT",
|
|
65
|
-
20
|
|
66
|
-
);
|
|
67
|
-
cursor = nextCursor;
|
|
68
|
-
|
|
69
|
-
const match = keys[0];
|
|
70
|
-
if (match) {
|
|
71
|
-
return match.slice(prefix.length);
|
|
72
|
-
}
|
|
73
|
-
} while (cursor !== "0");
|
|
74
|
-
|
|
75
|
-
return undefined;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// --- Per-platform config Zod schemas (with OpenAPI annotations + platform discriminator) ---
|
|
79
|
-
// Field definitions mirror @lobu/core platform schemas; gateway adds .openapi()
|
|
80
|
-
// and the `platform` literal discriminator for the API layer.
|
|
81
|
-
|
|
82
|
-
const TelegramConfigSchema = z.object({
|
|
83
|
-
platform: z.literal("telegram"),
|
|
84
|
-
botToken: z.string().optional().openapi({
|
|
85
|
-
description:
|
|
86
|
-
"Telegram bot token from BotFather. Falls back to TELEGRAM_BOT_TOKEN env var.",
|
|
87
|
-
}),
|
|
88
|
-
mode: z.enum(["auto", "webhook", "polling"]).optional().openapi({
|
|
89
|
-
description: "Runtime mode: auto (default), webhook, or polling.",
|
|
90
|
-
}),
|
|
91
|
-
secretToken: z.string().optional().openapi({
|
|
92
|
-
description:
|
|
93
|
-
"Webhook secret token for x-telegram-bot-api-secret-token verification.",
|
|
94
|
-
}),
|
|
95
|
-
userName: z
|
|
96
|
-
.string()
|
|
97
|
-
.optional()
|
|
98
|
-
.openapi({ description: "Override bot username." }),
|
|
99
|
-
apiBaseUrl: z
|
|
100
|
-
.string()
|
|
101
|
-
.optional()
|
|
102
|
-
.openapi({ description: "Custom Telegram API base URL." }),
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
const SlackConfigSchema = z.object({
|
|
106
|
-
platform: z.literal("slack"),
|
|
107
|
-
botToken: z.string().optional().openapi({
|
|
108
|
-
description: "Bot token (xoxb-...). Required for single-workspace mode.",
|
|
109
|
-
}),
|
|
110
|
-
botUserId: z.string().optional().openapi({
|
|
111
|
-
description: "Bot user ID (fetched automatically if omitted).",
|
|
112
|
-
}),
|
|
113
|
-
signingSecret: z
|
|
114
|
-
.string()
|
|
115
|
-
.optional()
|
|
116
|
-
.openapi({ description: "Signing secret for webhook verification." }),
|
|
117
|
-
clientId: z.string().optional().openapi({
|
|
118
|
-
description: "Slack app client ID (required for OAuth / multi-workspace).",
|
|
119
|
-
}),
|
|
120
|
-
clientSecret: z.string().optional().openapi({
|
|
121
|
-
description:
|
|
122
|
-
"Slack app client secret (required for OAuth / multi-workspace).",
|
|
123
|
-
}),
|
|
124
|
-
encryptionKey: z.string().optional().openapi({
|
|
125
|
-
description:
|
|
126
|
-
"Base64-encoded 32-byte AES-256-GCM key for encrypting stored bot tokens.",
|
|
127
|
-
}),
|
|
128
|
-
installationKeyPrefix: z.string().optional().openapi({
|
|
129
|
-
description:
|
|
130
|
-
"State key prefix for workspace installations (default: slack:installation).",
|
|
131
|
-
}),
|
|
132
|
-
userName: z
|
|
133
|
-
.string()
|
|
134
|
-
.optional()
|
|
135
|
-
.openapi({ description: "Override bot username." }),
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
const DiscordConfigSchema = z.object({
|
|
139
|
-
platform: z.literal("discord"),
|
|
140
|
-
botToken: z
|
|
141
|
-
.string()
|
|
142
|
-
.optional()
|
|
143
|
-
.openapi({ description: "Discord bot token." }),
|
|
144
|
-
applicationId: z
|
|
145
|
-
.string()
|
|
146
|
-
.optional()
|
|
147
|
-
.openapi({ description: "Discord application ID." }),
|
|
148
|
-
publicKey: z.string().optional().openapi({
|
|
149
|
-
description: "Application public key for webhook signature verification.",
|
|
150
|
-
}),
|
|
151
|
-
mentionRoleIds: z.array(z.string()).optional().openapi({
|
|
152
|
-
description:
|
|
153
|
-
"Role IDs that trigger mention handlers (in addition to direct mentions).",
|
|
154
|
-
}),
|
|
155
|
-
userName: z
|
|
156
|
-
.string()
|
|
157
|
-
.optional()
|
|
158
|
-
.openapi({ description: "Override bot username." }),
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
const WhatsAppConfigSchema = z.object({
|
|
162
|
-
platform: z.literal("whatsapp"),
|
|
163
|
-
accessToken: z.string().optional().openapi({
|
|
164
|
-
description: "System User access token for WhatsApp Cloud API.",
|
|
165
|
-
}),
|
|
166
|
-
phoneNumberId: z
|
|
167
|
-
.string()
|
|
168
|
-
.optional()
|
|
169
|
-
.openapi({ description: "WhatsApp Business phone number ID." }),
|
|
170
|
-
appSecret: z.string().optional().openapi({
|
|
171
|
-
description:
|
|
172
|
-
"Meta App Secret for webhook HMAC-SHA256 signature verification.",
|
|
173
|
-
}),
|
|
174
|
-
verifyToken: z
|
|
175
|
-
.string()
|
|
176
|
-
.optional()
|
|
177
|
-
.openapi({ description: "Verify token for webhook challenge-response." }),
|
|
178
|
-
apiVersion: z
|
|
179
|
-
.string()
|
|
180
|
-
.optional()
|
|
181
|
-
.openapi({ description: "Meta Graph API version (default: v21.0)." }),
|
|
182
|
-
userName: z.string().optional().openapi({ description: "Bot display name." }),
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
const TeamsConfigSchema = z.object({
|
|
186
|
-
platform: z.literal("teams"),
|
|
187
|
-
appId: z.string().optional().openapi({ description: "Microsoft App ID." }),
|
|
188
|
-
appPassword: z
|
|
189
|
-
.string()
|
|
190
|
-
.optional()
|
|
191
|
-
.openapi({ description: "Microsoft App Password." }),
|
|
192
|
-
appTenantId: z
|
|
193
|
-
.string()
|
|
194
|
-
.optional()
|
|
195
|
-
.openapi({ description: "Microsoft App Tenant ID." }),
|
|
196
|
-
appType: z
|
|
197
|
-
.enum(["MultiTenant", "SingleTenant"])
|
|
198
|
-
.optional()
|
|
199
|
-
.openapi({ description: "Microsoft App Type." }),
|
|
200
|
-
userName: z
|
|
201
|
-
.string()
|
|
202
|
-
.optional()
|
|
203
|
-
.openapi({ description: "Override bot username." }),
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
const GoogleChatConfigSchema = z.object({
|
|
207
|
-
platform: z.literal("gchat"),
|
|
208
|
-
credentials: z.string().optional().openapi({
|
|
209
|
-
description:
|
|
210
|
-
"Service account credentials JSON string. Defaults to GOOGLE_CHAT_CREDENTIALS env var.",
|
|
211
|
-
}),
|
|
212
|
-
useApplicationDefaultCredentials: z.boolean().optional().openapi({
|
|
213
|
-
description:
|
|
214
|
-
"Use Application Default Credentials (ADC) instead of service account JSON.",
|
|
215
|
-
}),
|
|
216
|
-
endpointUrl: z.string().optional().openapi({
|
|
217
|
-
description:
|
|
218
|
-
"HTTP endpoint URL for button click actions. Required for HTTP endpoint apps.",
|
|
219
|
-
}),
|
|
220
|
-
googleChatProjectNumber: z.string().optional().openapi({
|
|
221
|
-
description:
|
|
222
|
-
"Google Cloud project number for verifying webhook JWTs. Defaults to GOOGLE_CHAT_PROJECT_NUMBER env var.",
|
|
223
|
-
}),
|
|
224
|
-
impersonateUser: z.string().optional().openapi({
|
|
225
|
-
description:
|
|
226
|
-
"User email for domain-wide delegation. Defaults to GOOGLE_CHAT_IMPERSONATE_USER env var.",
|
|
227
|
-
}),
|
|
228
|
-
pubsubAudience: z.string().optional().openapi({
|
|
229
|
-
description:
|
|
230
|
-
"Expected audience for Pub/Sub push JWT verification. Defaults to GOOGLE_CHAT_PUBSUB_AUDIENCE env var.",
|
|
231
|
-
}),
|
|
232
|
-
userName: z
|
|
233
|
-
.string()
|
|
234
|
-
.optional()
|
|
235
|
-
.openapi({ description: "Override bot username." }),
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
const PlatformAdapterConfigSchema = z.discriminatedUnion("platform", [
|
|
239
|
-
TelegramConfigSchema,
|
|
240
|
-
SlackConfigSchema,
|
|
241
|
-
DiscordConfigSchema,
|
|
242
|
-
WhatsAppConfigSchema,
|
|
243
|
-
TeamsConfigSchema,
|
|
244
|
-
GoogleChatConfigSchema,
|
|
245
|
-
]);
|
|
246
|
-
|
|
247
|
-
/** Derived from the discriminated union — no separate list to maintain. */
|
|
248
|
-
const SUPPORTED_PLATFORMS = PlatformAdapterConfigSchema.options.map(
|
|
249
|
-
(s) => s.shape.platform.value
|
|
250
|
-
) as [string, ...string[]];
|
|
251
|
-
const SupportedPlatformSchema = z.enum(SUPPORTED_PLATFORMS);
|
|
252
|
-
|
|
253
|
-
const PlatformConnectionSchema = z.object({
|
|
254
|
-
id: z.string(),
|
|
255
|
-
platform: SupportedPlatformSchema,
|
|
256
|
-
templateAgentId: z.string().optional(),
|
|
257
|
-
config: PlatformAdapterConfigSchema,
|
|
258
|
-
settings: ConnectionSettingsSchema,
|
|
259
|
-
metadata: FlexibleObjectSchema,
|
|
260
|
-
status: z.enum(["active", "stopped", "error"]),
|
|
261
|
-
errorMessage: z.string().optional(),
|
|
262
|
-
createdAt: z.number(),
|
|
263
|
-
updatedAt: z.number(),
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
const ConnectionIdParamsSchema = z.object({
|
|
267
|
-
id: z.string(),
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
const ListConnectionsQuerySchema = z.object({
|
|
271
|
-
platform: SupportedPlatformSchema.optional(),
|
|
272
|
-
templateAgentId: z.string().optional(),
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
const ListConnectionsRoute = createRoute({
|
|
276
|
-
method: "get",
|
|
277
|
-
path: "/api/v1/connections",
|
|
278
|
-
tags: [TAG],
|
|
279
|
-
summary: "List platform connections",
|
|
280
|
-
description:
|
|
281
|
-
"Lists Chat SDK-backed connections visible to the current settings session.",
|
|
282
|
-
request: {
|
|
283
|
-
query: ListConnectionsQuerySchema,
|
|
284
|
-
},
|
|
285
|
-
responses: {
|
|
286
|
-
200: {
|
|
287
|
-
description: "Connections",
|
|
288
|
-
content: {
|
|
289
|
-
"application/json": {
|
|
290
|
-
schema: z.object({
|
|
291
|
-
connections: z.array(PlatformConnectionSchema),
|
|
292
|
-
}),
|
|
293
|
-
},
|
|
294
|
-
},
|
|
295
|
-
},
|
|
296
|
-
401: {
|
|
297
|
-
description: "Unauthorized",
|
|
298
|
-
content: {
|
|
299
|
-
"application/json": {
|
|
300
|
-
schema: ErrorResponseSchema,
|
|
301
|
-
},
|
|
302
|
-
},
|
|
303
|
-
},
|
|
304
|
-
403: {
|
|
305
|
-
description: "Forbidden",
|
|
306
|
-
content: {
|
|
307
|
-
"application/json": {
|
|
308
|
-
schema: ErrorResponseSchema,
|
|
309
|
-
},
|
|
310
|
-
},
|
|
311
|
-
},
|
|
312
|
-
},
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
const GetConnectionRoute = createRoute({
|
|
316
|
-
method: "get",
|
|
317
|
-
path: "/api/v1/connections/{id}",
|
|
318
|
-
tags: [TAG],
|
|
319
|
-
summary: "Get a platform connection",
|
|
320
|
-
request: {
|
|
321
|
-
params: ConnectionIdParamsSchema,
|
|
322
|
-
},
|
|
323
|
-
responses: {
|
|
324
|
-
200: {
|
|
325
|
-
description: "Connection",
|
|
326
|
-
content: {
|
|
327
|
-
"application/json": {
|
|
328
|
-
schema: PlatformConnectionSchema,
|
|
329
|
-
},
|
|
330
|
-
},
|
|
331
|
-
},
|
|
332
|
-
401: {
|
|
333
|
-
description: "Unauthorized",
|
|
334
|
-
content: {
|
|
335
|
-
"application/json": {
|
|
336
|
-
schema: ErrorResponseSchema,
|
|
337
|
-
},
|
|
338
|
-
},
|
|
339
|
-
},
|
|
340
|
-
403: {
|
|
341
|
-
description: "Forbidden",
|
|
342
|
-
content: {
|
|
343
|
-
"application/json": {
|
|
344
|
-
schema: ErrorResponseSchema,
|
|
345
|
-
},
|
|
346
|
-
},
|
|
347
|
-
},
|
|
348
|
-
404: {
|
|
349
|
-
description: "Connection not found",
|
|
350
|
-
content: {
|
|
351
|
-
"application/json": {
|
|
352
|
-
schema: ErrorResponseSchema,
|
|
353
|
-
},
|
|
354
|
-
},
|
|
355
|
-
},
|
|
356
|
-
},
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
export function createConnectionWebhookRoutes(
|
|
360
|
-
manager: ChatInstanceManager
|
|
361
|
-
): Hono {
|
|
362
|
-
const router = new Hono();
|
|
363
|
-
|
|
364
|
-
router.post("/api/v1/webhooks/:connectionId", async (c) => {
|
|
365
|
-
const connectionId = c.req.param("connectionId");
|
|
366
|
-
if (!connectionId) {
|
|
367
|
-
return c.json({ error: "Missing connectionId" }, 400);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// Verify connection exists before processing
|
|
371
|
-
const connection = await manager.getConnection(connectionId);
|
|
372
|
-
if (!connection) {
|
|
373
|
-
logger.warn({ connectionId }, "Webhook received for unknown connection");
|
|
374
|
-
return c.json({ error: "Connection not found" }, 404);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
logger.debug(
|
|
378
|
-
{ connectionId, platform: connection.platform },
|
|
379
|
-
"Processing webhook"
|
|
380
|
-
);
|
|
381
|
-
|
|
382
|
-
try {
|
|
383
|
-
const response = await manager.handleWebhook(connectionId, c.req.raw);
|
|
384
|
-
return response;
|
|
385
|
-
} catch (error) {
|
|
386
|
-
logger.error({ connectionId, error: String(error) }, "Webhook error");
|
|
387
|
-
return c.json({ error: "Webhook processing failed" }, 500);
|
|
388
|
-
}
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
return router;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
export function createConnectionCrudRoutes(
|
|
395
|
-
manager: ChatInstanceManager,
|
|
396
|
-
accessConfig: {
|
|
397
|
-
userAgentsStore: UserAgentsStore;
|
|
398
|
-
agentMetadataStore: Pick<AgentConfigStore, "getMetadata" | "listSandboxes">;
|
|
399
|
-
}
|
|
400
|
-
): OpenAPIHono {
|
|
401
|
-
const app = new OpenAPIHono();
|
|
402
|
-
|
|
403
|
-
const listLocalTestPlatforms = async (c: any): Promise<any> => {
|
|
404
|
-
if (process.env.NODE_ENV === "production") {
|
|
405
|
-
return c.json({ error: "Not found" }, 404);
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
const supported = new Set<string>(LOCAL_TEST_PLATFORMS);
|
|
409
|
-
const connections = await manager.listConnections();
|
|
410
|
-
const platforms = [
|
|
411
|
-
...new Set(
|
|
412
|
-
connections
|
|
413
|
-
.filter(
|
|
414
|
-
(connection) =>
|
|
415
|
-
connection.status === "active" &&
|
|
416
|
-
manager.has(connection.id) &&
|
|
417
|
-
supported.has(connection.platform)
|
|
418
|
-
)
|
|
419
|
-
.map((connection) => connection.platform)
|
|
420
|
-
),
|
|
421
|
-
];
|
|
422
|
-
|
|
423
|
-
return c.json(platforms);
|
|
424
|
-
};
|
|
425
|
-
|
|
426
|
-
const listLocalTestTargets = async (c: any): Promise<any> => {
|
|
427
|
-
if (process.env.NODE_ENV === "production") {
|
|
428
|
-
return c.json({ error: "Not found" }, 404);
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
const supported = new Set<string>(LOCAL_TEST_PLATFORMS);
|
|
432
|
-
const connections = await manager.listConnections();
|
|
433
|
-
const targets = new Map<
|
|
434
|
-
string,
|
|
435
|
-
{ platform: string; defaultTarget?: string }
|
|
436
|
-
>();
|
|
437
|
-
|
|
438
|
-
for (const connection of connections) {
|
|
439
|
-
if (
|
|
440
|
-
connection.status !== "active" ||
|
|
441
|
-
!manager.has(connection.id) ||
|
|
442
|
-
!supported.has(connection.platform)
|
|
443
|
-
) {
|
|
444
|
-
continue;
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
if (!targets.has(connection.platform)) {
|
|
448
|
-
targets.set(connection.platform, {
|
|
449
|
-
platform: connection.platform,
|
|
450
|
-
defaultTarget: await getLocalTestDefaultTarget(
|
|
451
|
-
manager,
|
|
452
|
-
connection.id
|
|
453
|
-
),
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
return c.json([...targets.values()]);
|
|
459
|
-
};
|
|
460
|
-
|
|
461
|
-
app.get("/internal/connections/platforms", listLocalTestPlatforms);
|
|
462
|
-
app.get("/internal/connections/test-targets", listLocalTestTargets);
|
|
463
|
-
|
|
464
|
-
// Internal endpoint for server-to-server connection listing (no auth required)
|
|
465
|
-
const listAllConnections = async (c: any) => {
|
|
466
|
-
const { platform, templateAgentId } = c.req.query();
|
|
467
|
-
const connections = await manager.listConnections({
|
|
468
|
-
platform: platform || undefined,
|
|
469
|
-
templateAgentId: templateAgentId || undefined,
|
|
470
|
-
});
|
|
471
|
-
return c.json({ connections });
|
|
472
|
-
};
|
|
473
|
-
app.get("/internal/connections", listAllConnections);
|
|
474
|
-
|
|
475
|
-
app.openapi(ListConnectionsRoute, async (c): Promise<any> => {
|
|
476
|
-
const session = verifySettingsSession(c);
|
|
477
|
-
if (!session) {
|
|
478
|
-
return c.json({ error: "Unauthorized" }, 401);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
const { platform, templateAgentId } = c.req.valid("query");
|
|
482
|
-
let connections;
|
|
483
|
-
|
|
484
|
-
if (templateAgentId) {
|
|
485
|
-
if (!(await verifyAgentAccess(session, templateAgentId, accessConfig))) {
|
|
486
|
-
return c.json({ error: "Forbidden" }, 403);
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
connections = await manager.listConnections({
|
|
490
|
-
platform: platform || undefined,
|
|
491
|
-
templateAgentId,
|
|
492
|
-
});
|
|
493
|
-
} else {
|
|
494
|
-
if (!session.isAdmin && session.settingsMode !== "admin") {
|
|
495
|
-
return c.json({ error: "Forbidden" }, 403);
|
|
496
|
-
}
|
|
497
|
-
connections = await manager.listConnections({
|
|
498
|
-
platform: platform || undefined,
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
return c.json({ connections });
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
app.openapi(GetConnectionRoute, async (c): Promise<any> => {
|
|
506
|
-
const session = verifySettingsSession(c);
|
|
507
|
-
if (!session) {
|
|
508
|
-
return c.json({ error: "Unauthorized" }, 401);
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
const { id } = c.req.valid("param");
|
|
512
|
-
const connection = await manager.getConnection(id);
|
|
513
|
-
if (!connection) {
|
|
514
|
-
return c.json({ error: "Connection not found" }, 404);
|
|
515
|
-
}
|
|
516
|
-
if (
|
|
517
|
-
connection.templateAgentId &&
|
|
518
|
-
!(await verifyAgentAccess(
|
|
519
|
-
session,
|
|
520
|
-
connection.templateAgentId,
|
|
521
|
-
accessConfig
|
|
522
|
-
))
|
|
523
|
-
) {
|
|
524
|
-
return c.json({ error: "Forbidden" }, 403);
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
return c.json(connection);
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
// GET /api/v1/connections/:id/sandboxes — list sandbox agents for a connection
|
|
531
|
-
app.get("/api/v1/connections/:id/sandboxes", async (c): Promise<any> => {
|
|
532
|
-
const session = verifySettingsSession(c);
|
|
533
|
-
if (!session) {
|
|
534
|
-
return c.json({ error: "Unauthorized" }, 401);
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
const id = c.req.param("id");
|
|
538
|
-
const connection = await manager.getConnection(id);
|
|
539
|
-
if (!connection) {
|
|
540
|
-
return c.json({ error: "Connection not found" }, 404);
|
|
541
|
-
}
|
|
542
|
-
if (
|
|
543
|
-
connection.templateAgentId &&
|
|
544
|
-
!(await verifyAgentAccess(
|
|
545
|
-
session,
|
|
546
|
-
connection.templateAgentId,
|
|
547
|
-
accessConfig
|
|
548
|
-
))
|
|
549
|
-
) {
|
|
550
|
-
return c.json({ error: "Forbidden" }, 403);
|
|
551
|
-
}
|
|
552
|
-
if (
|
|
553
|
-
!connection.templateAgentId &&
|
|
554
|
-
!session.isAdmin &&
|
|
555
|
-
session.settingsMode !== "admin"
|
|
556
|
-
) {
|
|
557
|
-
return c.json({ error: "Forbidden" }, 403);
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
const sandboxes = await accessConfig.agentMetadataStore.listSandboxes(id);
|
|
561
|
-
return c.json({
|
|
562
|
-
sandboxes: sandboxes.map((s) => ({
|
|
563
|
-
agentId: s.agentId,
|
|
564
|
-
name: s.name,
|
|
565
|
-
description: s.description || "",
|
|
566
|
-
owner: s.owner,
|
|
567
|
-
createdAt: s.createdAt,
|
|
568
|
-
lastUsedAt: s.lastUsedAt ?? null,
|
|
569
|
-
})),
|
|
570
|
-
});
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
return app;
|
|
574
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Hono } from "hono";
|
|
2
|
-
|
|
3
|
-
export function createLandingRoutes() {
|
|
4
|
-
const app = new Hono();
|
|
5
|
-
|
|
6
|
-
app.get("/", (c) => {
|
|
7
|
-
return c.json({
|
|
8
|
-
name: "Lobu Gateway",
|
|
9
|
-
mode: "api-only",
|
|
10
|
-
docs: "/api/docs",
|
|
11
|
-
health: "/health",
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
return app;
|
|
16
|
-
}
|