Apply remaining changes

This commit is contained in:
Chris Scott committed 2026-11-07 16:46:21 -05:00
1 parent 5846ee3c20
commit 8af2c189e9
33 files changed
+576 -130

No files matched your search

+23
View File
@@ -1,3 +1,5 @@
import { DEFAULTS } from '../config/defaults'
import { CHAT_ID_PATTERN } from '../schemas/chats'
import type { Repo } from '../types'
export const ASSISTANT_REPO_ID = 0
@@ -26,6 +28,27 @@ export function buildChatSessionPath(chatId: string, sessionId: string): string
return `/chats/${encodeURIComponent(chatId)}/sessions/${encodeURIComponent(sessionId)}`
}
/**
* Reads the chat id a workspace chat directory names. The directory must end in
* `<workspace>/<chats dir>/<chat id>`; a path nested deeper inside a chat, a different parent
* directory, or a malformed id yields null. Works without Node's `path` module.
*
* @param directory Session directory to read.
* @returns The chat id, or null when the directory is not a chat root.
*/
export function getChatIdFromDirectory(directory: string): string | null {
const normalized = trimTrailingChar(trimTrailingChar(directory.trim(), '/'), '\\')
if (!normalized) return null
const segments = normalized.split(/[\\/]/)
const chatId = segments[segments.length - 1]
const parent = segments[segments.length - 2]
if (!chatId || !parent) return null
if (parent !== DEFAULTS.WORKSPACE.CHATS_DIR) return null
return CHAT_ID_PATTERN.test(chatId) ? chatId : null
}
export function buildServerSessionPath(serverId: string, sessionId: string): string {
return `/servers/${encodeURIComponent(serverId)}/sessions/${encodeURIComponent(sessionId)}`
}