feat: add metadata field to session

This commit is contained in:
Steve Korshakov 2025-07-13 20:11:44 -07:00
parent 98d14fc1d6
commit 5aa597186a
4 changed files with 19 additions and 3 deletions

View File

@ -0,0 +1,8 @@
/*
Warnings:
- Added the required column `metadata` to the `Session` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER TABLE "Session" ADD COLUMN "metadata" TEXT NOT NULL;

View File

@ -37,10 +37,12 @@ model Session {
tag String
accountId String
account Account @relation(fields: [accountId], references: [id])
metadata String
seq Int @default(0)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
messages SessionMessage[]
@@unique([accountId, tag])
}

View File

@ -160,13 +160,14 @@ export async function startApi() {
typed.post('/v1/sessions', {
schema: {
body: z.object({
tag: z.string()
tag: z.string(),
metadata: z.string()
})
},
preHandler: app.authenticate
}, async (request, reply) => {
const userId = request.user.id;
const { tag } = request.body;
const { tag, metadata } = request.body;
const session = await db.session.findFirst({
where: {
@ -179,6 +180,7 @@ export async function startApi() {
session: {
id: session.id,
seq: session.seq,
metadata: session.metadata,
createdAt: session.createdAt.getTime(),
updatedAt: session.updatedAt.getTime()
}
@ -201,7 +203,8 @@ export async function startApi() {
const session = await tx.session.create({
data: {
accountId: userId,
tag: tag
tag: tag,
metadata: metadata
}
});
@ -210,6 +213,7 @@ export async function startApi() {
t: 'new-session',
id: session.id,
seq: session.seq,
metadata: metadata,
createdAt: session.createdAt.getTime(),
updatedAt: session.updatedAt.getTime()
};
@ -238,6 +242,7 @@ export async function startApi() {
session: {
id: result.session.id,
seq: result.session.seq,
metadata: result.session.metadata,
createdAt: result.session.createdAt.getTime(),
updatedAt: result.session.updatedAt.getTime()
}

View File

@ -21,6 +21,7 @@ declare global {
t: 'new-session';
id: string;
seq: number;
metadata: string;
createdAt: number;
updatedAt: number;
};