57e7a92cd1
- Add animate-pulse CSS animation for loading states - Add Ctrl+I/Ctrl+B markdown shortcuts in chat input - Improve chat input resize with mirror element - Add reasoning duration display and shimmer effect - Add confirmation dialog for deleting all models - Simplify RowVirtualizerDynamic resize handling - Fix DialogType imports (type -> value) - Fix ollama cloud model name resolution - Make vllm auth header optional - Various icon and styling fixes
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import { createInsertSchema } from 'drizzle-orm/zod';
|
|
import { db } from '~~/server/lib/db';
|
|
import { agents } from '~~/drizzle/schema';
|
|
import { userEvents } from '~~/server/utils/events';
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
await protectRoute(event);
|
|
|
|
const userId = event.context.user!.id;
|
|
|
|
const result = await readValidatedBody(event,
|
|
createInsertSchema(agents).safeParse
|
|
);
|
|
|
|
if (!result.success) {
|
|
throw createError({
|
|
statusCode: 400,
|
|
message: result.error.issues[0]!.message,
|
|
});
|
|
}
|
|
|
|
if (!result.data.userId) {
|
|
result.data.userId = userId;
|
|
}
|
|
|
|
if (result.data.userId !== userId) {
|
|
throw createError({
|
|
statusCode: 403,
|
|
statusMessage: 'Forbidden',
|
|
data: {
|
|
code: 'FORBIDDEN',
|
|
ok: false,
|
|
}
|
|
});
|
|
}
|
|
|
|
// @ts-expect-error - shut up
|
|
await db.insert(agents).values(result.data).onConflictDoNothing();
|
|
userEvents.emit(userId, 'agents', {
|
|
op: 'create',
|
|
payload: result.data,
|
|
});
|
|
|
|
return { ok: true };
|
|
})
|