-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathremember.ts
More file actions
44 lines (40 loc) · 1.07 KB
/
remember.ts
File metadata and controls
44 lines (40 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { z } from 'zod';
import { ApiFactory } from '../shared/boilerplate/src/types.js';
import { ServerContext, zKey, zSource } from '../types.js';
const inputSchema = {
key: zKey,
content: z.string().min(1).describe('The content to remember.'),
source: zSource,
} as const;
const outputSchema = {
id: z.string().describe('The unique identifier of the new memory.'),
} as const;
export const rememberFactory: ApiFactory<
ServerContext,
typeof inputSchema,
typeof outputSchema
> = ({ pgPool, schema }) => ({
name: 'remember',
method: 'post',
route: '/memory',
config: {
title: 'Store a new memory',
description:
'This endpoint stores a new memory in the database, using the provided key as the scope.',
inputSchema,
outputSchema,
},
fn: async ({ key, content, source }) => {
const result = await pgPool.query<{ id: string }>(
/* sql */ `
INSERT INTO ${schema}.memory (key, content, source)
VALUES ($1, $2, $3)
RETURNING id
`,
[key, content, source || null],
);
return {
id: result.rows[0].id,
};
},
});