v0.1.3 ff61cc9

chat.server.ts RawHistoryFolder

1import type { LibSQLDatabase } from "drizzle-orm/libsql";
2import { createLogger } from "$lib/utils/logger.server";
3import schema, { chatRooms } from "$lib/db/schema";
4import { eq } from "drizzle-orm";
5import { env } from "$env/dynamic/public";
6
7const log = createLogger('chat-utils');
8
9// Default chat room ID from environment variable
10export const DEFAULT_CHAT_ROOM_ID = env.PUBLIC_DEFAULT_CHAT_ROOM_ID || '00000000-0000-0000-0000-000000000001';
11
12// Type guard for LibSQL errors
13interface LibSQLError {
14    code: string;
15    message: string;
16}
17
18function isLibSQLError(error: unknown): error is LibSQLError {
19    return typeof error === 'object' && error !== null && 'code' in error;
20}
21
22// Function to ensure default chat room exists
23export async function ensureDefaultChatRoom(db: LibSQLDatabase<typeof schema>) {
24    log.debug('Ensuring default chat room exists...');
25    try {
26        // Use a transaction to handle concurrent creation attempts
27        await db.transaction(async (tx) => {
28            const defaultRoom = await tx.select()
29                .from(chatRooms)
30                .where(eq(chatRooms.id, DEFAULT_CHAT_ROOM_ID))
31                .get();
32
33            if (!defaultRoom) {
34                log.debug('Creating default chat room...');
35                await tx.insert(chatRooms).values({
36                    id: DEFAULT_CHAT_ROOM_ID,
37                    name: 'General',
38                    type: 'group',
39                    createdAt: Date.now()
40                });
41                log.debug('Default chat room created successfully');
42            } else {
43                log.debug('Default chat room already exists');
44            }
45        });
46    } catch (error: unknown) {
47        // If the error is a unique constraint violation, another process probably created the room
48        if (isLibSQLError(error) && error.code === 'SQLITE_CONSTRAINT') {
49            log.debug('Default chat room was created by another process');
50            return;
51        }
52        log.error('Error ensuring default chat room:', { error: error instanceof Error ? error.message : 'Unknown error' });
53        throw error;
54    }
55} 

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 3

Tags 8

↑↓ moveenter openesc close