@axiom-lattice/gateway 3.0.2 → 3.0.4

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 (155) hide show
  1. package/dist/index.js +37 -9
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.mjs +37 -9
  4. package/dist/index.mjs.map +1 -1
  5. package/package.json +9 -6
  6. package/.eslintrc.json +0 -22
  7. package/.turbo/turbo-build.log +0 -46
  8. package/AGENTS.md +0 -112
  9. package/CHANGELOG.md +0 -1190
  10. package/LOGGER_CONFIG.md +0 -135
  11. package/RESUME_STREAM_CONTENT_BASED.md +0 -326
  12. package/RESUME_STREAM_README.md +0 -388
  13. package/jest.config.js +0 -72
  14. package/public/sdk/README.md +0 -695
  15. package/public/sdk/dashboard-engine-skill.md +0 -1122
  16. package/public/sdk/dashboard-single-file-spec.md +0 -357
  17. package/public/sdk/data-query-sdk-skill.md +0 -307
  18. package/public/sdk/data-query-sdk.d.ts +0 -252
  19. package/public/sdk/data-query-sdk.js +0 -970
  20. package/public/sdk/occupancy-dashboard.html +0 -363
  21. package/public/sdk/test-dashboard.html +0 -690
  22. package/scripts/seed-lark-installation.ts +0 -54
  23. package/src/__tests__/__mocks__/e2b.ts +0 -1
  24. package/src/__tests__/a2a.test.ts +0 -428
  25. package/src/__tests__/channel-installations.test.ts +0 -199
  26. package/src/__tests__/data-query.test.ts +0 -77
  27. package/src/__tests__/sandbox-provider-registration.test.ts +0 -74
  28. package/src/__tests__/setup.ts +0 -5
  29. package/src/__tests__/workspace.test.ts +0 -400
  30. package/src/channels/__tests__/routes.test.ts +0 -50
  31. package/src/channels/lark/LarkChannelAdapter.ts +0 -217
  32. package/src/channels/lark/README.md +0 -187
  33. package/src/channels/lark/__tests__/controller.test.ts +0 -136
  34. package/src/channels/lark/__tests__/mapping-service.test.ts +0 -118
  35. package/src/channels/lark/__tests__/parser.test.ts +0 -72
  36. package/src/channels/lark/__tests__/sender.test.ts +0 -37
  37. package/src/channels/lark/__tests__/verification.test.ts +0 -157
  38. package/src/channels/lark/controller.ts +0 -48
  39. package/src/channels/lark/mapping-service.ts +0 -138
  40. package/src/channels/lark/parser.ts +0 -68
  41. package/src/channels/lark/routes.ts +0 -22
  42. package/src/channels/lark/sender.ts +0 -58
  43. package/src/channels/lark/types.ts +0 -20
  44. package/src/channels/lark/verification.ts +0 -32
  45. package/src/channels/registry.ts +0 -20
  46. package/src/channels/routes.ts +0 -30
  47. package/src/channels/wechat/WechatChannelAdapter.ts +0 -294
  48. package/src/channels/wechat/__tests__/context-store.test.ts +0 -148
  49. package/src/channels/wechat/context-store.ts +0 -54
  50. package/src/channels/wechat/controller.ts +0 -59
  51. package/src/channels/wechat/routes.ts +0 -7
  52. package/src/channels/wechat/types.ts +0 -62
  53. package/src/channels/wechat/wechat-client.ts +0 -162
  54. package/src/config/local-a2a-templates.ts +0 -59
  55. package/src/config.ts +0 -124
  56. package/src/controllers/__tests__/assistant-local-a2a.test.ts +0 -147
  57. package/src/controllers/__tests__/local-a2a-templates.test.ts +0 -112
  58. package/src/controllers/__tests__/mime.test.ts +0 -74
  59. package/src/controllers/__tests__/resources.test.ts +0 -122
  60. package/src/controllers/__tests__/run.test.ts +0 -115
  61. package/src/controllers/__tests__/tasks.test.ts +0 -215
  62. package/src/controllers/__tests__/workflow-tracking.test.ts +0 -113
  63. package/src/controllers/agent_task.ts +0 -72
  64. package/src/controllers/assistant.ts +0 -490
  65. package/src/controllers/auth.ts +0 -524
  66. package/src/controllers/channel-bindings.ts +0 -135
  67. package/src/controllers/channel-installations.ts +0 -409
  68. package/src/controllers/collections.ts +0 -176
  69. package/src/controllers/config.ts +0 -126
  70. package/src/controllers/connections.ts +0 -181
  71. package/src/controllers/data-query.ts +0 -236
  72. package/src/controllers/database-configs.ts +0 -440
  73. package/src/controllers/embeddings.ts +0 -22
  74. package/src/controllers/entries.ts +0 -167
  75. package/src/controllers/eval.ts +0 -513
  76. package/src/controllers/export-import.ts +0 -166
  77. package/src/controllers/health.ts +0 -36
  78. package/src/controllers/local-a2a-templates.ts +0 -18
  79. package/src/controllers/local-a2a.ts +0 -149
  80. package/src/controllers/mcp-configs.ts +0 -673
  81. package/src/controllers/memory.ts +0 -257
  82. package/src/controllers/menu-items.ts +0 -114
  83. package/src/controllers/metrics-configs.ts +0 -1061
  84. package/src/controllers/middleware-types.ts +0 -15
  85. package/src/controllers/models.ts +0 -199
  86. package/src/controllers/personal-assistant.ts +0 -191
  87. package/src/controllers/resources.ts +0 -477
  88. package/src/controllers/run.ts +0 -338
  89. package/src/controllers/sandbox.ts +0 -255
  90. package/src/controllers/schedules.ts +0 -336
  91. package/src/controllers/skills.ts +0 -256
  92. package/src/controllers/tasks.ts +0 -213
  93. package/src/controllers/tenants.ts +0 -121
  94. package/src/controllers/thread_status.ts +0 -66
  95. package/src/controllers/threads.ts +0 -260
  96. package/src/controllers/tools.ts +0 -139
  97. package/src/controllers/users.ts +0 -135
  98. package/src/controllers/workflow-tracking.ts +0 -693
  99. package/src/controllers/workspace.ts +0 -879
  100. package/src/export_registrations/a2a-api-key.registration.ts +0 -89
  101. package/src/export_registrations/agent.registration.ts +0 -80
  102. package/src/export_registrations/binding.registration.ts +0 -106
  103. package/src/export_registrations/channel-installation.registration.ts +0 -88
  104. package/src/export_registrations/collection.registration.ts +0 -85
  105. package/src/export_registrations/connection.registration.ts +0 -97
  106. package/src/export_registrations/database-config.registration.ts +0 -94
  107. package/src/export_registrations/eval.registration.ts +0 -334
  108. package/src/export_registrations/index.ts +0 -31
  109. package/src/export_registrations/mcp-config.registration.ts +0 -97
  110. package/src/export_registrations/menu.registration.ts +0 -91
  111. package/src/export_registrations/metrics-config.registration.ts +0 -94
  112. package/src/export_registrations/skill.registration.ts +0 -88
  113. package/src/export_registrations/task.registration.ts +0 -99
  114. package/src/index.ts +0 -497
  115. package/src/logger/Logger.ts +0 -186
  116. package/src/router/MessageContext.ts +0 -14
  117. package/src/router/MessageRouter.ts +0 -490
  118. package/src/router/middlewares/auditLogger.ts +0 -34
  119. package/src/router/middlewares/deduplication.ts +0 -38
  120. package/src/router/middlewares/index.ts +0 -3
  121. package/src/router/middlewares/rateLimit.ts +0 -46
  122. package/src/routes/__tests__/a2a-test-connection.test.ts +0 -177
  123. package/src/routes/a2a-bridge.ts +0 -266
  124. package/src/routes/a2a-test-connection.ts +0 -126
  125. package/src/routes/a2a.ts +0 -851
  126. package/src/routes/channel-bindings.ts +0 -11
  127. package/src/routes/channel-installations.ts +0 -33
  128. package/src/routes/index.ts +0 -640
  129. package/src/routes/menu-items.ts +0 -10
  130. package/src/routes/resource-routes.ts +0 -35
  131. package/src/routes/stt.ts +0 -102
  132. package/src/schemas/data-query.ts +0 -69
  133. package/src/schemas/index.ts +0 -852
  134. package/src/services/ExportImportService.ts +0 -296
  135. package/src/services/__tests__/ExportImportService.test.ts +0 -130
  136. package/src/services/__tests__/eval-runner.test.ts +0 -131
  137. package/src/services/__tests__/local-a2a.test.ts +0 -124
  138. package/src/services/agent_task_consumer.ts +0 -348
  139. package/src/services/collection_service.ts +0 -258
  140. package/src/services/eval-runner.ts +0 -283
  141. package/src/services/local-a2a.ts +0 -354
  142. package/src/services/queue_service.ts +0 -104
  143. package/src/services/sandbox_service.ts +0 -223
  144. package/src/services/skill_service.ts +0 -97
  145. package/src/services/supabase.ts +0 -60
  146. package/src/swagger.ts +0 -77
  147. package/src/types/index.ts +0 -118
  148. package/src/types/koa.d.ts +0 -7
  149. package/src/utils/__tests__/local-a2a-runtime.test.ts +0 -77
  150. package/src/utils/__tests__/path-containment.test.ts +0 -35
  151. package/src/utils/a2a-url.ts +0 -20
  152. package/src/utils/local-a2a-runtime.ts +0 -107
  153. package/src/utils/mime.ts +0 -44
  154. package/src/utils/path-containment.ts +0 -38
  155. package/tsconfig.json +0 -26
@@ -1,440 +0,0 @@
1
- import { FastifyRequest, FastifyReply } from "fastify";
2
- import {
3
- getStoreLattice,
4
- sqlDatabaseManager,
5
- } from "@axiom-lattice/core";
6
- import type {
7
- DatabaseConfigStore,
8
- DatabaseConfigEntry,
9
- CreateDatabaseConfigRequest,
10
- UpdateDatabaseConfigRequest,
11
- DatabaseConfig,
12
- } from "@axiom-lattice/protocols";
13
- import { randomUUID } from "crypto";
14
-
15
- /**
16
- * Database Config Controller
17
- * Handles database configuration CRUD operations
18
- */
19
-
20
- /**
21
- * Get tenant ID from authenticated user context
22
- * Falls back to request headers for backward compatibility
23
- */
24
- function getTenantId(request: FastifyRequest): string {
25
- // First try to get from authenticated user context
26
- const userTenantId = (request as any).user?.tenantId;
27
- if (userTenantId) {
28
- return userTenantId;
29
- }
30
-
31
- // Fallback to request headers for backward compatibility
32
- return (request.headers["x-tenant-id"] as string) || "default";
33
- }
34
-
35
- /**
36
- * Database config list response
37
- */
38
- interface DatabaseConfigListResponse {
39
- success: boolean;
40
- message: string;
41
- data: {
42
- records: DatabaseConfigEntry[];
43
- total: number;
44
- };
45
- }
46
-
47
- /**
48
- * Database config response
49
- */
50
- interface DatabaseConfigResponse {
51
- success: boolean;
52
- message: string;
53
- data?: DatabaseConfigEntry;
54
- }
55
-
56
- /**
57
- * Test connection response
58
- */
59
- interface TestConnectionResponse {
60
- success: boolean;
61
- message: string;
62
- data?: {
63
- connected: boolean;
64
- latency?: number;
65
- error?: string;
66
- };
67
- }
68
-
69
- /**
70
- * Get all database configs for a tenant
71
- */
72
- export async function getDatabaseConfigList(
73
- request: FastifyRequest,
74
- reply: FastifyReply
75
- ): Promise<DatabaseConfigListResponse> {
76
- const tenantId = getTenantId(request);
77
-
78
- try {
79
- const storeLattice = getStoreLattice("default", "database");
80
- const store: DatabaseConfigStore = storeLattice.store;
81
-
82
- const configs = await store.getAllConfigs(tenantId);
83
-
84
- console.log('Backend: getAllConfigs returned:', configs);
85
- if (configs.length > 0) {
86
- console.log('Backend: First config key:', configs[0].key);
87
- }
88
-
89
- return {
90
- success: true,
91
- message: "Database configurations retrieved successfully",
92
- data: {
93
- records: configs,
94
- total: configs.length,
95
- },
96
- };
97
- } catch (error) {
98
- console.error("Failed to get database configs:", error);
99
- return {
100
- success: false,
101
- message: "Failed to retrieve database configurations",
102
- data: {
103
- records: [],
104
- total: 0,
105
- },
106
- };
107
- }
108
- }
109
-
110
- /**
111
- * Get database config by key
112
- */
113
- export async function getDatabaseConfig(
114
- request: FastifyRequest,
115
- reply: FastifyReply
116
- ): Promise<DatabaseConfigResponse> {
117
- const tenantId = getTenantId(request);
118
- const { key } = request.params as { key: string };
119
-
120
- try {
121
- const storeLattice = getStoreLattice("default", "database");
122
- const store: DatabaseConfigStore = storeLattice.store;
123
-
124
- const config = await store.getConfigByKey(tenantId, key);
125
-
126
- if (!config) {
127
- return {
128
- success: false,
129
- message: "Database configuration not found",
130
- };
131
- }
132
-
133
- return {
134
- success: true,
135
- message: "Database configuration retrieved successfully",
136
- data: config,
137
- };
138
- } catch (error) {
139
- console.error("Failed to get database config:", error);
140
- return {
141
- success: false,
142
- message: "Failed to retrieve database configuration",
143
- };
144
- }
145
- }
146
-
147
- /**
148
- * Create new database config
149
- */
150
- export async function createDatabaseConfig(
151
- request: FastifyRequest,
152
- reply: FastifyReply
153
- ): Promise<DatabaseConfigResponse> {
154
- const tenantId = getTenantId(request);
155
- const body = request.body as CreateDatabaseConfigRequest & { id?: string };
156
-
157
- try {
158
- const storeLattice = getStoreLattice("default", "database");
159
- const store: DatabaseConfigStore = storeLattice.store;
160
-
161
- // Check if key already exists
162
- const existing = await store.getConfigByKey(tenantId, body.key);
163
- if (existing) {
164
- reply.code(409);
165
- return {
166
- success: false,
167
- message: "Database configuration with this key already exists",
168
- };
169
- }
170
-
171
- const id = body.id || randomUUID();
172
- const config = await store.createConfig(tenantId, id, body);
173
-
174
- // Auto-register to SqlDatabaseManager
175
- try {
176
- sqlDatabaseManager.registerDatabase(tenantId, config.key, config.config);
177
- } catch (error) {
178
- console.warn("Failed to auto-register database:", error);
179
- }
180
-
181
- reply.code(201);
182
- return {
183
- success: true,
184
- message: "Database configuration created successfully",
185
- data: config,
186
- };
187
- } catch (error) {
188
- console.error("Failed to create database config:", error);
189
- return {
190
- success: false,
191
- message: "Failed to create database configuration",
192
- };
193
- }
194
- }
195
-
196
- /**
197
- * Update database config
198
- */
199
- export async function updateDatabaseConfig(
200
- request: FastifyRequest,
201
- reply: FastifyReply
202
- ): Promise<DatabaseConfigResponse> {
203
- const tenantId = getTenantId(request);
204
- const { key } = request.params as { key: string };
205
- const updates = request.body as Partial<UpdateDatabaseConfigRequest>;
206
-
207
- try {
208
- const storeLattice = getStoreLattice("default", "database");
209
- const store: DatabaseConfigStore = storeLattice.store;
210
-
211
- const existing = await store.getConfigByKey(tenantId, key);
212
- if (!existing) {
213
- reply.code(404);
214
- return {
215
- success: false,
216
- message: "Database configuration not found",
217
- };
218
- }
219
-
220
- const updated = await store.updateConfig(tenantId, existing.id, updates);
221
-
222
- if (!updated) {
223
- return {
224
- success: false,
225
- message: "Failed to update database configuration",
226
- };
227
- }
228
-
229
- // Re-register to SqlDatabaseManager if config changed
230
- if (updates.config) {
231
- try {
232
- sqlDatabaseManager.registerDatabase(tenantId, updated.key, updated.config);
233
- } catch (error) {
234
- console.warn("Failed to re-register database:", error);
235
- }
236
- }
237
-
238
- return {
239
- success: true,
240
- message: "Database configuration updated successfully",
241
- data: updated,
242
- };
243
- } catch (error) {
244
- console.error("Failed to update database config:", error);
245
- return {
246
- success: false,
247
- message: "Failed to update database configuration",
248
- };
249
- }
250
- }
251
-
252
- /**
253
- * Delete database config by key or id
254
- */
255
- export async function deleteDatabaseConfig(
256
- request: FastifyRequest,
257
- reply: FastifyReply
258
- ): Promise<DatabaseConfigResponse> {
259
- const tenantId = getTenantId(request);
260
- const { keyOrId } = request.params as { keyOrId: string };
261
-
262
- try {
263
- const storeLattice = getStoreLattice("default", "database");
264
- const store: DatabaseConfigStore = storeLattice.store;
265
-
266
- console.log('Delete request - keyOrId:', keyOrId);
267
-
268
- // Try to find by key first, then by id
269
- let config = await store.getConfigByKey(tenantId, keyOrId);
270
- let configKey = keyOrId;
271
-
272
- if (!config) {
273
- // Try to find by id
274
- config = await store.getConfigById(tenantId, keyOrId);
275
- if (config) {
276
- configKey = config.key;
277
- }
278
- }
279
-
280
- if (!config) {
281
- reply.code(404);
282
- return {
283
- success: false,
284
- message: "Database configuration not found",
285
- };
286
- }
287
-
288
- console.log('Found config to delete:', { id: config.id, key: config.key });
289
-
290
- const deleted = await store.deleteConfig(tenantId, config.id);
291
-
292
- if (!deleted) {
293
- return {
294
- success: false,
295
- message: "Failed to delete database configuration",
296
- };
297
- }
298
-
299
- // Remove from SqlDatabaseManager
300
- try {
301
- if (sqlDatabaseManager.hasDatabase(tenantId, configKey)) {
302
- await sqlDatabaseManager.removeDatabase(tenantId, configKey);
303
- }
304
- } catch (error) {
305
- console.warn("Failed to remove from SqlDatabaseManager:", error);
306
- }
307
-
308
- return {
309
- success: true,
310
- message: "Database configuration deleted successfully",
311
- };
312
- } catch (error) {
313
- console.error("Failed to delete database config:", error);
314
- return {
315
- success: false,
316
- message: "Failed to delete database configuration",
317
- };
318
- }
319
- }
320
-
321
- /**
322
- * Test database connection
323
- */
324
- export async function testDatabaseConnection(
325
- request: FastifyRequest,
326
- reply: FastifyReply
327
- ): Promise<TestConnectionResponse> {
328
- const tenantId = getTenantId(request);
329
- const { key } = request.params as { key: string };
330
-
331
- try {
332
- const storeLattice = getStoreLattice("default", "database");
333
- const store: DatabaseConfigStore = storeLattice.store;
334
-
335
- const config = await store.getConfigByKey(tenantId, key);
336
- if (!config) {
337
- reply.code(404);
338
- return {
339
- success: false,
340
- message: "Database configuration not found",
341
- };
342
- }
343
-
344
- // Register temporarily for testing
345
- const testKey = `__test_${key}_${Date.now()}`;
346
- sqlDatabaseManager.registerDatabase(tenantId, testKey, config.config);
347
-
348
- const startTime = Date.now();
349
- const db = await sqlDatabaseManager.getDatabase(tenantId, testKey);
350
-
351
- try {
352
- // Try to connect and list tables
353
- await db.connect();
354
- await db.listTables();
355
- const latency = Date.now() - startTime;
356
-
357
- // Disconnect gracefully with delay to ensure all operations complete
358
- await new Promise(resolve => setTimeout(resolve, 100));
359
- await db.disconnect();
360
-
361
- // Cleanup
362
- await sqlDatabaseManager.removeDatabase(tenantId, testKey);
363
-
364
- return {
365
- success: true,
366
- message: "Connection test successful",
367
- data: {
368
- connected: true,
369
- latency,
370
- },
371
- };
372
- } catch (error) {
373
- // Cleanup on error
374
- try {
375
- await db.disconnect();
376
- await sqlDatabaseManager.removeDatabase(tenantId, testKey);
377
- } catch { /* cleanup error, ignore */ }
378
-
379
- return {
380
- success: true,
381
- message: "Connection test failed",
382
- data: {
383
- connected: false,
384
- error: error instanceof Error ? error.message : "Unknown error",
385
- },
386
- };
387
- }
388
- } catch (error) {
389
- console.error("Failed to test database connection:", error);
390
- return {
391
- success: false,
392
- message: "Failed to test database connection",
393
- data: {
394
- connected: false,
395
- error: error instanceof Error ? error.message : "Unknown error",
396
- },
397
- };
398
- }
399
- }
400
-
401
- /**
402
- * Register database config routes
403
- */
404
- export function registerDatabaseConfigRoutes(app: any): void {
405
- // Get all configs
406
- app.get(
407
- "/api/database-configs",
408
- getDatabaseConfigList
409
- );
410
-
411
- // Get config by key
412
- app.get(
413
- "/api/database-configs/:key",
414
- getDatabaseConfig
415
- );
416
-
417
- // Create config
418
- app.post(
419
- "/api/database-configs",
420
- createDatabaseConfig
421
- );
422
-
423
- // Update config
424
- app.put(
425
- "/api/database-configs/:key",
426
- updateDatabaseConfig
427
- );
428
-
429
- // Delete config by key or id
430
- app.delete(
431
- "/api/database-configs/:keyOrId",
432
- deleteDatabaseConfig
433
- );
434
-
435
- // Test connection
436
- app.post(
437
- "/api/database-configs/:key/test",
438
- testDatabaseConnection
439
- );
440
- }
@@ -1,22 +0,0 @@
1
- import { FastifyRequest, FastifyReply } from "fastify";
2
- import { embeddingsLatticeManager } from "@axiom-lattice/core";
3
-
4
- export async function listEmbeddings(
5
- _request: FastifyRequest,
6
- _reply: FastifyReply
7
- ): Promise<any> {
8
- try {
9
- const info = embeddingsLatticeManager.getAllEmbeddingsInfo();
10
- return {
11
- success: true,
12
- message: "Successfully retrieved embedding models",
13
- data: { records: info, total: info.length },
14
- };
15
- } catch (error: any) {
16
- return {
17
- success: false,
18
- message: `Failed to retrieve embeddings: ${error.message}`,
19
- data: { records: [], total: 0 },
20
- };
21
- }
22
- }
@@ -1,167 +0,0 @@
1
- import { FastifyRequest, FastifyReply } from "fastify";
2
- import { CollectionService } from "../services/collection_service";
3
-
4
- const collectionService = new CollectionService();
5
-
6
- export async function listEntries(
7
- request: FastifyRequest<{ Params: { name: string } }>,
8
- reply: FastifyReply
9
- ): Promise<any> {
10
- try {
11
- const { name } = request.params;
12
- const entries = await collectionService.getEntries(request, name);
13
- return {
14
- success: true,
15
- message: "Successfully retrieved entries",
16
- data: { records: entries, total: entries.length },
17
- };
18
- } catch (error: any) {
19
- return reply.status(500).send({
20
- success: false,
21
- message: `Failed to retrieve entries: ${error.message}`,
22
- data: { records: [], total: 0 },
23
- });
24
- }
25
- }
26
-
27
- export async function createEntry(
28
- request: FastifyRequest<{ Params: { name: string }; Body: { content: string; metadata?: Record<string, unknown> } }>,
29
- reply: FastifyReply
30
- ): Promise<any> {
31
- try {
32
- const { name } = request.params;
33
- const data = request.body;
34
- if (!data.content) {
35
- return reply.status(400).send({ success: false, message: "content is required" });
36
- }
37
-
38
- const entry = await collectionService.createEntry(request, name, data);
39
- return reply.status(201).send({
40
- success: true,
41
- message: "Successfully created entry",
42
- data: entry,
43
- });
44
- } catch (error: any) {
45
- if (error.message?.includes("not found")) {
46
- return reply.status(404).send({ success: false, message: error.message });
47
- }
48
- return reply.status(500).send({
49
- success: false,
50
- message: `Failed to create entry: ${error.message}`,
51
- });
52
- }
53
- }
54
-
55
- export async function getEntry(
56
- request: FastifyRequest<{ Params: { name: string; id: string } }>,
57
- reply: FastifyReply
58
- ): Promise<any> {
59
- try {
60
- const { name, id } = request.params;
61
- const entry = await collectionService.getEntry(request, name, id);
62
-
63
- if (!entry) {
64
- return reply.status(404).send({ success: false, message: "Entry not found" });
65
- }
66
-
67
- return {
68
- success: true,
69
- message: "Successfully retrieved entry",
70
- data: entry,
71
- };
72
- } catch (error: any) {
73
- return reply.status(500).send({
74
- success: false,
75
- message: `Failed to retrieve entry: ${error.message}`,
76
- });
77
- }
78
- }
79
-
80
- export async function updateEntry(
81
- request: FastifyRequest<{ Params: { name: string; id: string }; Body: { content?: string; metadata?: Record<string, unknown> } }>,
82
- reply: FastifyReply
83
- ): Promise<any> {
84
- try {
85
- const { name, id } = request.params;
86
- const data = request.body;
87
-
88
- const entry = await collectionService.updateEntry(request, name, id, data);
89
-
90
- if (!entry) {
91
- return reply.status(404).send({ success: false, message: "Entry not found" });
92
- }
93
-
94
- return {
95
- success: true,
96
- message: "Successfully updated entry",
97
- data: entry,
98
- };
99
- } catch (error: any) {
100
- if (error.message?.includes("not found")) {
101
- return reply.status(404).send({ success: false, message: error.message });
102
- }
103
- return reply.status(500).send({
104
- success: false,
105
- message: `Failed to update entry: ${error.message}`,
106
- });
107
- }
108
- }
109
-
110
- export async function deleteEntry(
111
- request: FastifyRequest<{ Params: { name: string; id: string } }>,
112
- reply: FastifyReply
113
- ): Promise<any> {
114
- try {
115
- const { name, id } = request.params;
116
- const result = await collectionService.deleteEntry(request, name, id);
117
-
118
- if (!result) {
119
- return reply.status(404).send({ success: false, message: "Entry not found" });
120
- }
121
-
122
- return { success: true, message: "Successfully deleted entry" };
123
- } catch (error: any) {
124
- return reply.status(500).send({
125
- success: false,
126
- message: `Failed to delete entry: ${error.message}`,
127
- });
128
- }
129
- }
130
-
131
- export async function searchEntries(
132
- request: FastifyRequest<{
133
- Params: { name: string };
134
- Body: { query: string; filter?: Record<string, unknown>; top_k?: number };
135
- }>,
136
- reply: FastifyReply
137
- ): Promise<any> {
138
- try {
139
- const { name } = request.params;
140
- const { query, filter, top_k } = request.body;
141
-
142
- if (!query) {
143
- return reply.status(400).send({ success: false, message: "query is required" });
144
- }
145
-
146
- const entries = await collectionService.searchEntries(request, name, {
147
- query,
148
- filter,
149
- top_k,
150
- });
151
-
152
- return {
153
- success: true,
154
- message: "Search completed",
155
- data: { records: entries, total: entries.length },
156
- };
157
- } catch (error: any) {
158
- if (error.message?.includes("not found")) {
159
- return reply.status(404).send({ success: false, message: error.message });
160
- }
161
- return reply.status(500).send({
162
- success: false,
163
- message: `Search failed: ${error.message}`,
164
- data: { records: [], total: 0 },
165
- });
166
- }
167
- }