|
1 | 1 | import { z } from 'zod'; |
2 | 2 | import { ApiFactory } from '../shared/boilerplate/src/types.js'; |
3 | | -import { Memory, ServerContext, zKey, zMemory } from '../types.js'; |
| 3 | +import { Memory, ServerContext, zScope, zMemory } from '../types.js'; |
4 | 4 |
|
5 | 5 | const inputSchema = { |
6 | | - key: zKey, |
| 6 | + scope: zScope, |
7 | 7 | } as const; |
8 | 8 |
|
9 | 9 | const outputSchema = { |
10 | 10 | memories: z.array(zMemory).describe('The list of memories found.'), |
11 | | - key: zKey, |
| 11 | + scope: zScope, |
12 | 12 | } as const; |
13 | 13 |
|
14 | | -export const getMemoriesFactory: ApiFactory< |
| 14 | +export const recallFactory: ApiFactory< |
15 | 15 | ServerContext, |
16 | 16 | typeof inputSchema, |
17 | 17 | typeof outputSchema |
18 | 18 | > = ({ pgPool, schema }) => ({ |
19 | | - name: 'getMemories', |
| 19 | + name: 'recall', |
20 | 20 | method: 'get', |
21 | | - route: ['/memory', '/memory/:key'], |
| 21 | + route: ['/memory', '/memory/:scope'], |
22 | 22 | config: { |
23 | | - title: 'Retrieve memories by key', |
| 23 | + title: 'Retrieve memories by scope', |
24 | 24 | description: |
25 | | - 'This endpoint retrieves memories from the database, using the provided key as the scope.', |
| 25 | + 'This endpoint retrieves memories from the database, using the provided scope.', |
26 | 26 | inputSchema, |
27 | 27 | outputSchema, |
28 | 28 | }, |
29 | | - fn: async ({ key }) => { |
| 29 | + fn: async ({ scope }) => { |
30 | 30 | const result = await pgPool.query<Memory>( |
31 | 31 | /* sql */ ` |
32 | 32 | SELECT id, content, source, created_at, updated_at |
33 | 33 | FROM ${schema}.memory |
34 | | -WHERE key = $1 AND deleted_at IS NULL |
| 34 | +WHERE scope = $1 AND deleted_at IS NULL |
35 | 35 | `, |
36 | | - [key], |
| 36 | + [scope], |
37 | 37 | ); |
38 | 38 |
|
39 | 39 | return { |
40 | 40 | memories: result.rows, |
41 | | - key, |
| 41 | + scope, |
42 | 42 | }; |
43 | 43 | }, |
44 | 44 | }); |
0 commit comments