mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
Chat folders, ChatService and the /api/chats REST API
This commit is contained in:
1 parent
c6c13335e5
commit
666c1f0e0a
12 files changed
+623
-2
No files matched your search
@@ -29,6 +29,7 @@ export const DEFAULTS = {
|
||||
WORKSPACE: {
|
||||
BASE_PATH: './workspace',
|
||||
REPOS_DIR: 'repos',
|
||||
CHATS_DIR: 'chats',
|
||||
SCHEDULE_WORKTREES_DIR: 'schedule-worktrees',
|
||||
WALKTHROUGHS_DIR: 'walkthroughs',
|
||||
CONFIG_DIR: '.config/opencode',
|
||||
|
||||
@@ -87,6 +87,7 @@ export const ENV = {
|
||||
get BASE_PATH() { return resolveWorkspacePath() },
|
||||
get BROWSE_ROOT() { return resolveBrowseRoot() },
|
||||
REPOS_DIR: DEFAULTS.WORKSPACE.REPOS_DIR,
|
||||
CHATS_DIR: DEFAULTS.WORKSPACE.CHATS_DIR,
|
||||
SCHEDULE_WORKTREES_DIR: DEFAULTS.WORKSPACE.SCHEDULE_WORKTREES_DIR,
|
||||
WALKTHROUGHS_DIR: DEFAULTS.WORKSPACE.WALKTHROUGHS_DIR,
|
||||
CONFIG_DIR: DEFAULTS.WORKSPACE.CONFIG_DIR,
|
||||
@@ -148,6 +149,7 @@ export const ENV = {
|
||||
export const getWorkspacePath = () => ENV.WORKSPACE.BASE_PATH
|
||||
export const getBrowseRootPath = () => ENV.WORKSPACE.BROWSE_ROOT
|
||||
export const getReposPath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.REPOS_DIR)
|
||||
export const getChatsPath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.CHATS_DIR)
|
||||
export const getScheduleWorktreesPath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.SCHEDULE_WORKTREES_DIR)
|
||||
export const getWalkthroughsPath = () => path.join(ENV.WORKSPACE.BASE_PATH, ENV.WORKSPACE.WALKTHROUGHS_DIR)
|
||||
export const getAssistantModePath = () => path.join(getReposPath(), ASSISTANT_REPO_PATH)
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import { z } from 'zod'
|
||||
|
||||
export const CHAT_ID_PATTERN = /^(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})(\d{2})-[0-9a-f]{6}$/
|
||||
|
||||
export const ChatIdSchema = z.string().regex(CHAT_ID_PATTERN, 'Invalid chat id')
|
||||
|
||||
export const ChatSchema = z.object({
|
||||
id: ChatIdSchema,
|
||||
directory: z.string(),
|
||||
filesPath: z.string(),
|
||||
createdAt: z.number(),
|
||||
})
|
||||
|
||||
export const ListChatsQuerySchema = z.object({
|
||||
limit: z.coerce.number().int().min(1).max(50).default(10),
|
||||
cursor: ChatIdSchema.optional(),
|
||||
})
|
||||
|
||||
export const ListChatsResponseSchema = z.object({
|
||||
chats: z.array(ChatSchema),
|
||||
nextCursor: ChatIdSchema.optional(),
|
||||
})
|
||||
|
||||
export const CreateChatRequestSchema = z.object({
|
||||
title: z.string().optional(),
|
||||
agent: z.string().optional(),
|
||||
model: z.string().optional(),
|
||||
})
|
||||
|
||||
export const CreateChatResponseSchema = z.object({
|
||||
chat: ChatSchema,
|
||||
sessionId: z.string(),
|
||||
})
|
||||
|
||||
export const DeleteChatSessionResponseSchema = z.object({
|
||||
deleted: z.literal(true),
|
||||
folderRemoved: z.boolean(),
|
||||
})
|
||||
|
||||
export type Chat = z.infer<typeof ChatSchema>
|
||||
export type ListChatsQuery = z.infer<typeof ListChatsQuerySchema>
|
||||
export type ListChatsResponse = z.infer<typeof ListChatsResponseSchema>
|
||||
export type CreateChatRequest = z.infer<typeof CreateChatRequestSchema>
|
||||
export type CreateChatResponse = z.infer<typeof CreateChatResponseSchema>
|
||||
export type DeleteChatSessionResponse = z.infer<typeof DeleteChatSessionResponseSchema>
|
||||
|
||||
/** Reads the UTC creation time encoded in a chat id. */
|
||||
export function parseChatIdCreatedAt(id: string): number {
|
||||
const match = CHAT_ID_PATTERN.exec(id)
|
||||
if (!match) return NaN
|
||||
const [, year, month, day, hour, minute, second] = match
|
||||
return Date.UTC(
|
||||
Number(year),
|
||||
Number(month) - 1,
|
||||
Number(day),
|
||||
Number(hour),
|
||||
Number(minute),
|
||||
Number(second),
|
||||
)
|
||||
}
|
||||
@@ -24,3 +24,4 @@ export * from './change-walkthroughs'
|
||||
export * from './opencode-servers'
|
||||
export * from './secrets'
|
||||
export * from './device-pairing'
|
||||
export * from './chats'
|
||||
@@ -22,6 +22,10 @@ export function buildSessionPath(
|
||||
return `/repos/${repoId}/sessions/${sessionId}${search ? `?${search}` : ''}`
|
||||
}
|
||||
|
||||
export function buildChatSessionPath(chatId: string, sessionId: string): string {
|
||||
return `/chats/${encodeURIComponent(chatId)}/sessions/${encodeURIComponent(sessionId)}`
|
||||
}
|
||||
|
||||
export function buildServerSessionPath(serverId: string, sessionId: string): string {
|
||||
return `/servers/${encodeURIComponent(serverId)}/sessions/${encodeURIComponent(sessionId)}`
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user