@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,281 +0,0 @@
1
- import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2
- import * as crypto from "node:crypto";
3
- import * as http from "node:http";
4
- import * as net from "node:net";
5
- import { generateWorkerToken } from "@lobu/core";
6
- import { __testOnly, startHttpProxy, stopHttpProxy } from "../proxy/http-proxy";
7
-
8
- // Generate a stable 32-byte encryption key for tests
9
- const TEST_ENCRYPTION_KEY = crypto.randomBytes(32).toString("base64");
10
-
11
- // Single proxy server shared across all test suites
12
- let proxyPort: number;
13
- let proxyServer: http.Server;
14
-
15
- beforeAll(async () => {
16
- process.env.ENCRYPTION_KEY = TEST_ENCRYPTION_KEY;
17
- // Default to unrestricted for auth tests; domain tests use per-deployment config
18
- process.env.WORKER_ALLOWED_DOMAINS = "*";
19
-
20
- proxyPort = 10000 + Math.floor(Math.random() * 50000);
21
- proxyServer = await startHttpProxy(proxyPort, "127.0.0.1");
22
- });
23
-
24
- afterAll(async () => {
25
- await stopHttpProxy(proxyServer);
26
- delete process.env.ENCRYPTION_KEY;
27
- delete process.env.WORKER_ALLOWED_DOMAINS;
28
- });
29
-
30
- function makeBasicAuth(username: string, password: string): string {
31
- return `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`;
32
- }
33
-
34
- /**
35
- * Send a raw HTTP proxy request via TCP socket to avoid Bun's HTTP client
36
- * retrying on 407 responses.
37
- */
38
- function rawProxyRequest(
39
- targetUrl: string,
40
- options: { proxyAuth?: string } = {}
41
- ): Promise<{ statusCode: number; headers: string; body: string }> {
42
- return new Promise((resolve, reject) => {
43
- const socket = new net.Socket();
44
- socket.connect(proxyPort, "127.0.0.1", () => {
45
- let req = `GET ${targetUrl} HTTP/1.1\r\nHost: ${new URL(targetUrl).host}\r\n`;
46
- if (options.proxyAuth) {
47
- req += `Proxy-Authorization: ${options.proxyAuth}\r\n`;
48
- }
49
- req += "Connection: close\r\n\r\n";
50
- socket.write(req);
51
- });
52
-
53
- let data = "";
54
- socket.on("data", (chunk: Buffer) => {
55
- data += chunk.toString();
56
- });
57
-
58
- socket.on("end", () => {
59
- // Parse status code from first line: "HTTP/1.1 407 ..."
60
- const firstLineEnd = data.indexOf("\r\n");
61
- const statusLine = data.substring(0, firstLineEnd);
62
- const statusMatch = statusLine.match(/HTTP\/\d\.\d (\d+)/);
63
- const statusCode = statusMatch ? parseInt(statusMatch[1]!, 10) : 0;
64
-
65
- const headerEnd = data.indexOf("\r\n\r\n");
66
- const headers = data.substring(0, headerEnd);
67
- const body = headerEnd !== -1 ? data.substring(headerEnd + 4) : "";
68
-
69
- resolve({ statusCode, headers, body });
70
- });
71
-
72
- socket.on("error", reject);
73
- socket.setTimeout(5000, () => {
74
- socket.destroy();
75
- reject(new Error("Request timed out"));
76
- });
77
- });
78
- }
79
-
80
- /**
81
- * Send a CONNECT request through the proxy and return the raw response line.
82
- */
83
- function connectRequest(
84
- host: string,
85
- port: number,
86
- options: { proxyAuth?: string } = {}
87
- ): Promise<{ statusLine: string }> {
88
- return new Promise((resolve, reject) => {
89
- const socket = new net.Socket();
90
- socket.connect(proxyPort, "127.0.0.1", () => {
91
- let req = `CONNECT ${host}:${port} HTTP/1.1\r\nHost: ${host}:${port}\r\n`;
92
- if (options.proxyAuth) {
93
- req += `Proxy-Authorization: ${options.proxyAuth}\r\n`;
94
- }
95
- req += "\r\n";
96
- socket.write(req);
97
- });
98
-
99
- let data = "";
100
- socket.on("data", (chunk: Buffer) => {
101
- data += chunk.toString();
102
- const lineEnd = data.indexOf("\r\n");
103
- if (lineEnd !== -1) {
104
- socket.destroy();
105
- resolve({ statusLine: data.substring(0, lineEnd) });
106
- }
107
- });
108
-
109
- socket.on("error", reject);
110
- socket.setTimeout(5000, () => {
111
- socket.destroy();
112
- reject(new Error("CONNECT request timed out"));
113
- });
114
- });
115
- }
116
-
117
- function createValidToken(deploymentName: string): string {
118
- return generateWorkerToken("test-user", "test-conv", deploymentName, {
119
- channelId: "test-channel",
120
- platform: "test",
121
- });
122
- }
123
-
124
- // ─── Auth tests ──────────────────────────────────────────────────────────────
125
-
126
- describe("HTTP Proxy Authentication", () => {
127
- describe("HTTP requests", () => {
128
- test("rejects request with no auth (407)", async () => {
129
- const res = await rawProxyRequest("http://example.com/test");
130
- expect(res.statusCode).toBe(407);
131
- expect(res.headers.toLowerCase()).toContain("proxy-authenticate");
132
- });
133
-
134
- test("rejects request with invalid token (407)", async () => {
135
- const res = await rawProxyRequest("http://example.com/test", {
136
- proxyAuth: makeBasicAuth("my-deployment", "not-a-valid-token"),
137
- });
138
- expect(res.statusCode).toBe(407);
139
- });
140
-
141
- test("rejects request with deployment name mismatch (407)", async () => {
142
- const token = createValidToken("real-deployment");
143
- const res = await rawProxyRequest("http://example.com/test", {
144
- proxyAuth: makeBasicAuth("fake-deployment", token),
145
- });
146
- expect(res.statusCode).toBe(407);
147
- });
148
-
149
- test("rejects request with empty password (407)", async () => {
150
- const res = await rawProxyRequest("http://example.com/test", {
151
- proxyAuth: makeBasicAuth("my-deployment", ""),
152
- });
153
- expect(res.statusCode).toBe(407);
154
- });
155
-
156
- test("accepts request with valid token", async () => {
157
- const deploymentName = "test-worker-http";
158
- const token = createValidToken(deploymentName);
159
- const res = await rawProxyRequest("http://example.com/", {
160
- proxyAuth: makeBasicAuth(deploymentName, token),
161
- });
162
- // Should pass auth — either upstream response or 502 (network error)
163
- expect(res.statusCode).not.toBe(407);
164
- });
165
- });
166
-
167
- describe("CONNECT requests", () => {
168
- test("rejects CONNECT with no auth (407)", async () => {
169
- const res = await connectRequest("example.com", 443);
170
- expect(res.statusLine).toContain("407");
171
- });
172
-
173
- test("rejects CONNECT with invalid token (407)", async () => {
174
- const res = await connectRequest("example.com", 443, {
175
- proxyAuth: makeBasicAuth("my-deployment", "garbage-token"),
176
- });
177
- expect(res.statusLine).toContain("407");
178
- });
179
-
180
- test("rejects CONNECT with deployment mismatch (407)", async () => {
181
- const token = createValidToken("actual-deployment");
182
- const res = await connectRequest("example.com", 443, {
183
- proxyAuth: makeBasicAuth("wrong-deployment", token),
184
- });
185
- expect(res.statusLine).toContain("407");
186
- });
187
-
188
- test("accepts CONNECT with valid token (200)", async () => {
189
- const deploymentName = "test-worker-connect";
190
- const token = createValidToken(deploymentName);
191
- const res = await connectRequest("example.com", 443, {
192
- proxyAuth: makeBasicAuth(deploymentName, token),
193
- });
194
- expect(res.statusLine).toContain("200");
195
- });
196
- });
197
- });
198
-
199
- // ─── Startup tests ───────────────────────────────────────────────────────────
200
-
201
- describe("HTTP Proxy Startup", () => {
202
- test("rejects on port conflict (EADDRINUSE)", async () => {
203
- const blockingPort = 10000 + Math.floor(Math.random() * 50000);
204
- const blocker = http.createServer();
205
- await new Promise<void>((resolve) =>
206
- blocker.listen(blockingPort, "127.0.0.1", resolve)
207
- );
208
-
209
- try {
210
- await expect(
211
- startHttpProxy(blockingPort, "127.0.0.1")
212
- ).rejects.toMatchObject({ code: "EADDRINUSE" });
213
- } finally {
214
- await new Promise<void>((resolve, reject) =>
215
- blocker.close((err) => (err ? reject(err) : resolve()))
216
- );
217
- }
218
- });
219
-
220
- test("binds to specified host and port", async () => {
221
- const port = 10000 + Math.floor(Math.random() * 50000);
222
- const server = await startHttpProxy(port, "127.0.0.1");
223
- try {
224
- const addr = server.address();
225
- expect(addr).not.toBeNull();
226
- if (typeof addr === "object" && addr) {
227
- expect(addr.port).toBe(port);
228
- expect(addr.address).toBe("127.0.0.1");
229
- }
230
- } finally {
231
- await stopHttpProxy(server);
232
- }
233
- });
234
- });
235
-
236
- // ─── Domain filtering tests ──────────────────────────────────────────────────
237
- // Global config is WORKER_ALLOWED_DOMAINS=* (unrestricted), so all domains pass.
238
- // Domain restriction via per-agent grants requires Redis and is tested separately.
239
-
240
- describe("HTTP Proxy Domain Filtering (unrestricted mode)", () => {
241
- const deploymentName = "domain-test-worker";
242
-
243
- test("rejects request to loopback IP literal", async () => {
244
- const token = createValidToken(deploymentName);
245
- const res = await rawProxyRequest("http://127.0.0.1/", {
246
- proxyAuth: makeBasicAuth(deploymentName, token),
247
- });
248
- expect(res.statusCode).toBe(403);
249
- expect(res.body).toContain("Target IP not allowed");
250
- });
251
-
252
- test("rejects request to IPv4-mapped IPv6 loopback (hex form)", async () => {
253
- expect(__testOnly.isBlockedIpAddress("::ffff:7f00:1")).toBe(true);
254
- });
255
-
256
- test("rejects CONNECT when hostname resolves to loopback", async () => {
257
- const token = createValidToken(deploymentName);
258
- const res = await connectRequest("localhost", 443, {
259
- proxyAuth: makeBasicAuth(deploymentName, token),
260
- });
261
- expect(res.statusLine).toContain("403");
262
- });
263
-
264
- test("allows request to any domain in unrestricted mode", async () => {
265
- const token = createValidToken(deploymentName);
266
- const res = await rawProxyRequest("http://example.com/", {
267
- proxyAuth: makeBasicAuth(deploymentName, token),
268
- });
269
- // Passes auth + domain check — either upstream response or 502
270
- expect(res.statusCode).not.toBe(403);
271
- expect(res.statusCode).not.toBe(407);
272
- });
273
-
274
- test("allows CONNECT to any domain in unrestricted mode", async () => {
275
- const token = createValidToken(deploymentName);
276
- const res = await connectRequest("example.com", 443, {
277
- proxyAuth: makeBasicAuth(deploymentName, token),
278
- });
279
- expect(res.statusLine).toContain("200");
280
- });
281
- });
@@ -1,37 +0,0 @@
1
- import { beforeEach, describe, expect, test } from "bun:test";
2
- import { MockRedisClient } from "@lobu/core/testing";
3
- import { AgentSettingsStore } from "../auth/settings/agent-settings-store";
4
- import { InstructionService } from "../services/instruction-service";
5
-
6
- describe("InstructionService", () => {
7
- let store: AgentSettingsStore;
8
- let service: InstructionService;
9
-
10
- beforeEach(() => {
11
- store = new AgentSettingsStore(new MockRedisClient() as any);
12
- service = new InstructionService(undefined, store);
13
- });
14
-
15
- test("returns stronger fallback guidance when agent instructions are unconfigured", async () => {
16
- const sessionContext = await service.getSessionContext(
17
- "telegram",
18
- {
19
- agentId: "agent-1",
20
- userId: "user-1",
21
- workingDirectory: "/workspace/thread-1",
22
- } as any,
23
- { settingsUrl: "http://localhost:8080/api/v1/agents/agent-1/config" }
24
- );
25
-
26
- expect(sessionContext.agentInstructions).toContain(
27
- "## Agent Configuration Notice"
28
- );
29
- expect(sessionContext.agentInstructions).toContain(
30
- "IDENTITY.md, SOUL.md, USER.md"
31
- );
32
- expect(sessionContext.agentInstructions).not.toContain("ScheduleReminder");
33
- expect(sessionContext.agentInstructions).not.toContain(
34
- "Do not invent product capabilities"
35
- );
36
- });
37
- });
@@ -1,112 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { extractSettingsLinkButtons } from "../platform/link-buttons";
3
-
4
- describe("extractSettingsLinkButtons", () => {
5
- test("extracts settings link and replaces with label", () => {
6
- const content =
7
- "Click [Open Settings](https://example.com/connect/claim?claim=abc123) to continue";
8
- const { processedContent, linkButtons } =
9
- extractSettingsLinkButtons(content);
10
-
11
- expect(linkButtons).toHaveLength(1);
12
- expect(linkButtons[0]!.text).toBe("Open Settings");
13
- expect(linkButtons[0]!.url).toBe(
14
- "https://example.com/connect/claim?claim=abc123"
15
- );
16
- expect(processedContent).toBe("Click Open Settings to continue");
17
- expect(processedContent).not.toContain("https://");
18
- });
19
-
20
- test("extracts settings link with agent param", () => {
21
- const content =
22
- "[Settings](https://example.com/connect/claim?claim=abc&agent=agent-1)";
23
- const { linkButtons } = extractSettingsLinkButtons(content);
24
-
25
- expect(linkButtons).toHaveLength(1);
26
- expect(linkButtons[0]!.url).toBe(
27
- "https://example.com/connect/claim?claim=abc&agent=agent-1"
28
- );
29
- });
30
-
31
- test("extracts multiple settings links", () => {
32
- const content =
33
- "[First](https://a.com/connect/claim?claim=1) and [Second](https://b.com/connect/claim?claim=2)";
34
- const { processedContent, linkButtons } =
35
- extractSettingsLinkButtons(content);
36
-
37
- expect(linkButtons).toHaveLength(2);
38
- expect(processedContent).toBe("First and Second");
39
- });
40
-
41
- test("filters out localhost URLs", () => {
42
- const content =
43
- "[Settings](http://localhost:3000/connect/claim?claim=token)";
44
- const { processedContent, linkButtons } =
45
- extractSettingsLinkButtons(content);
46
-
47
- expect(linkButtons).toHaveLength(0);
48
- // Label still replaces the link
49
- expect(processedContent).toBe("Settings");
50
- });
51
-
52
- test("filters out 127.0.0.1 URLs", () => {
53
- const content = "[Settings](http://127.0.0.1/connect/claim?claim=token)";
54
- const { linkButtons } = extractSettingsLinkButtons(content);
55
- expect(linkButtons).toHaveLength(0);
56
- });
57
-
58
- test("does not match non-settings links", () => {
59
- const content = "[Home](https://example.com/home)";
60
- const { processedContent, linkButtons } =
61
- extractSettingsLinkButtons(content);
62
-
63
- expect(linkButtons).toHaveLength(0);
64
- expect(processedContent).toBe(content); // unchanged
65
- });
66
-
67
- test("does not match links without claim= parameter", () => {
68
- const content = "[Settings](https://example.com/agent)";
69
- const { processedContent, linkButtons } =
70
- extractSettingsLinkButtons(content);
71
-
72
- expect(linkButtons).toHaveLength(0);
73
- expect(processedContent).toBe(content);
74
- });
75
-
76
- test("returns empty buttons for content without links", () => {
77
- const content = "No links here, just plain text";
78
- const { processedContent, linkButtons } =
79
- extractSettingsLinkButtons(content);
80
-
81
- expect(linkButtons).toHaveLength(0);
82
- expect(processedContent).toBe(content);
83
- });
84
-
85
- test("handles HTTP and HTTPS", () => {
86
- const httpContent = "[A](http://example.com/connect/claim?claim=x)";
87
- const httpsContent = "[B](https://example.com/connect/claim?claim=y)";
88
-
89
- const httpResult = extractSettingsLinkButtons(httpContent);
90
- const httpsResult = extractSettingsLinkButtons(httpsContent);
91
-
92
- expect(httpResult.linkButtons).toHaveLength(1);
93
- expect(httpsResult.linkButtons).toHaveLength(1);
94
- });
95
-
96
- test("mixed localhost and remote links only keeps remote", () => {
97
- const content =
98
- "[Local](http://localhost/connect/claim?claim=a) and [Remote](https://app.com/connect/claim?claim=b)";
99
- const { linkButtons } = extractSettingsLinkButtons(content);
100
-
101
- expect(linkButtons).toHaveLength(1);
102
- expect(linkButtons[0]!.url).toContain("app.com");
103
- });
104
-
105
- test("keeps backward compatibility with legacy /agent claim links", () => {
106
- const content = "[Legacy](https://example.com/agent?claim=legacy)";
107
- const { linkButtons } = extractSettingsLinkButtons(content);
108
-
109
- expect(linkButtons).toHaveLength(1);
110
- expect(linkButtons[0]!.url).toBe("https://example.com/agent?claim=legacy");
111
- });
112
- });
@@ -1,32 +0,0 @@
1
- import { afterEach, describe, expect, test } from "bun:test";
2
- import { Lobu } from "../lobu";
3
-
4
- const originalMemoryUrl = process.env.MEMORY_URL;
5
- const originalAdminPassword = process.env.ADMIN_PASSWORD;
6
-
7
- afterEach(() => {
8
- if (originalMemoryUrl === undefined) {
9
- delete process.env.MEMORY_URL;
10
- } else {
11
- process.env.MEMORY_URL = originalMemoryUrl;
12
- }
13
-
14
- if (originalAdminPassword === undefined) {
15
- delete process.env.ADMIN_PASSWORD;
16
- } else {
17
- process.env.ADMIN_PASSWORD = originalAdminPassword;
18
- }
19
- });
20
-
21
- describe("Lobu", () => {
22
- test("applies config.memory to the gateway environment", () => {
23
- delete process.env.MEMORY_URL;
24
-
25
- new Lobu({
26
- redis: "redis://localhost:6379",
27
- memory: "https://memory.example.com",
28
- });
29
-
30
- expect(process.env.MEMORY_URL).toBe("https://memory.example.com");
31
- });
32
- });