File Manager & Filesystem Operations: - Add FileManagerTree component with drag-and-drop (dnd-kit), inline rename, right-click context menu, and compact sidebar mode - Add context-menu component (open, new file/folder, rename, duplicate, copy, paste, move, delete) rendered via portal - Add InlineRename component with validation and shake-on-error animation - Add useWorkspaceWatcher hook with SSE live-reload and polling fallback - Add API routes: mkdir, rename, copy, move, watch (SSE file-change events), and DELETE on /api/workspace/file with system-file protection - Add safeResolveNewPath and isSystemFile helpers to workspace lib - Replace inline WorkspaceTreeNode in sidebar with shared FileManagerTree (compact mode), add workspace refresh callback Object Relation Resolution: - Resolve relation fields to human-readable display labels server-side (resolveRelationLabels, resolveDisplayField helpers) - Add reverse relation discovery (findReverseRelations) — surfaces incoming links from other objects - Add display_field column migration (idempotent ALTER TABLE) and PATCH /api/workspace/objects/[name]/display-field endpoint - Enrich object API response with relationLabels, reverseRelations, effectiveDisplayField, and related_object_name per field - Add RelationCell, RelationChip, ReverseRelationCell, LinkIcon components to object-table with clickable cross-object navigation - Add relation label rendering to kanban cards - Extract ObjectView component in workspace page with display-field selector dropdown and relation/reverse-relation badge counts Chat Panel Extraction: - Extract chat logic from page.tsx into standalone ChatPanel component with forwardRef/useImperativeHandle for session control - ChatPanel supports file-scoped sessions (filePath param) and context-aware file chat sidebar - Simplify page.tsx to thin orchestrator delegating to ChatPanel - Add filePath filter to GET /api/web-sessions for scoped session lists Dependencies: - Add @dnd-kit/core, @dnd-kit/sortable, @dnd-kit/utilities - Add duckdbExec and parseRelationValue to workspace lib Co-authored-by: Cursor <cursoragent@cursor.com>
80 lines
2.1 KiB
TypeScript
80 lines
2.1 KiB
TypeScript
import { readFileSync, writeFileSync, existsSync, mkdirSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { homedir } from "node:os";
|
|
import { randomUUID } from "node:crypto";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
const WEB_CHAT_DIR = join(homedir(), ".openclaw", "web-chat");
|
|
const INDEX_FILE = join(WEB_CHAT_DIR, "index.json");
|
|
|
|
export type WebSessionMeta = {
|
|
id: string;
|
|
title: string;
|
|
createdAt: number;
|
|
updatedAt: number;
|
|
messageCount: number;
|
|
/** When set, this session is scoped to a specific workspace file. */
|
|
filePath?: string;
|
|
};
|
|
|
|
function ensureDir() {
|
|
if (!existsSync(WEB_CHAT_DIR)) {
|
|
mkdirSync(WEB_CHAT_DIR, { recursive: true });
|
|
}
|
|
}
|
|
|
|
function readIndex(): WebSessionMeta[] {
|
|
ensureDir();
|
|
if (!existsSync(INDEX_FILE)) {return [];}
|
|
try {
|
|
return JSON.parse(readFileSync(INDEX_FILE, "utf-8"));
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
function writeIndex(sessions: WebSessionMeta[]) {
|
|
ensureDir();
|
|
writeFileSync(INDEX_FILE, JSON.stringify(sessions, null, 2));
|
|
}
|
|
|
|
/** GET /api/web-sessions — list web chat sessions.
|
|
* ?filePath=... → returns only sessions scoped to that file.
|
|
* No filePath → returns only global (non-file) sessions. */
|
|
export async function GET(req: Request) {
|
|
const url = new URL(req.url);
|
|
const filePath = url.searchParams.get("filePath");
|
|
|
|
const all = readIndex();
|
|
const sessions = filePath
|
|
? all.filter((s) => s.filePath === filePath)
|
|
: all.filter((s) => !s.filePath);
|
|
|
|
return Response.json({ sessions });
|
|
}
|
|
|
|
/** POST /api/web-sessions — create a new web chat session */
|
|
export async function POST(req: Request) {
|
|
const body = await req.json().catch(() => ({}));
|
|
const id = randomUUID();
|
|
const session: WebSessionMeta = {
|
|
id,
|
|
title: body.title || "New Chat",
|
|
createdAt: Date.now(),
|
|
updatedAt: Date.now(),
|
|
messageCount: 0,
|
|
...(body.filePath ? { filePath: body.filePath } : {}),
|
|
};
|
|
|
|
const sessions = readIndex();
|
|
sessions.unshift(session);
|
|
writeIndex(sessions);
|
|
|
|
// Create empty .jsonl file
|
|
ensureDir();
|
|
writeFileSync(join(WEB_CHAT_DIR, `${id}.jsonl`), "");
|
|
|
|
return Response.json({ session });
|
|
}
|