Files
openchamber/packages/vscode/webview/api/files.ts
T
Bohdan Triapitsyn 79143bff4c feat: massive chat reliability + UX pass (web/desktop/mobile/vscode) (#593)
## Added Features
- Add VS Code save-as-image flow for assistant messages via webview bridge + native save dialog.
- Add hourly desktop update checks after startup.
- Add new tool output display mode: `Changes` (auto-expand edit/write/patch only; keep activity expanded; mode guidance text).
- Add GitHub PR attachment flow in chat input with PR picker + attached PR chip/details.
- Add mobile overlay presentation for GitHub Issue and PR pickers (shared with desktop picker content).

## Fixes
- Save-gate project icon updates until explicit Save; allow icon removal with same save-gated behavior.
- Restore clickable chat action buttons in sticky header mode (desktop + Firefox hit-target issue).
- Clamp sticky user messages to bounded chat height and allow internal scrolling.
- Prevent drawer context crash during iPad/tablet orientation switching.
- Improve text-selection action menu placement on narrow screens.
- Move assistant message time into clock tooltip; keep duration display clean.
- Hide `Link GitHub Issue` row in VS Code chat input area (GitHub flow is not yet ready there).
- Remove laggy close animation in text-selection popover; keep open motion/positioning behavior.
- Fetch branches when picker opens and cache empty; show loading state instead of false “No branches found”.
- Fix share-image export metadata rendering (theme background resolution, timestamp rendering, footer alignment).
- Scope MCP services status/toggles to active directory to avoid cross-project leakage.
- Improve long user-message clamp behavior (40% cap variant, hidden scrollbar, scroll shadows, expansion detection).
- Fix desktop `Check for Updates` menu handler; prevent duplicate checks; show clear success/error toasts.
- Stabilize long user-message scrolling behavior (follow-up hardening).
- Avoid premature web update failure on slower servers.
- Restore user message image previews + fullscreen gallery navigation payload.
- Repair desktop chat drag-and-drop image attachments when native drop coords are missing.
- Move GitHub issue linking entry into Add attachment menu.
- Align header context usage percentage visuals with context panel.
- Align `@` file search with active project in all runtimes.
- Route `@` file discovery through OpenCode SDK `find.files`; remove legacy `/api/fs/search` reliance.
- Make chat `@` mention behavior consistent with files-style behavior.
- Keep status-row todos in stable order after status changes; add compact status icons; replace noisy priority labels.

## Refactors / UX Consistency
- Simplify chat attachment model and remove project file picker path.
- Keep composer focused on `@` mention file flow.
- Use direct `Attach files` action in VS Code instead of attachment dropdown path.
- Unify issue/PR picker behavior between desktop and mobile overlays.
2026-03-04 01:41:01 +02:00

120 lines
4.4 KiB
TypeScript

import type {
CommandExecResult,
DirectoryListResult,
FileSearchQuery,
FileSearchResult,
FilesAPI,
} from '@openchamber/ui/lib/api/types';
import { sendBridgeMessage, sendBridgeMessageWithOptions } from './bridge';
const normalizePath = (value: string): string => value.replace(/\\/g, '/');
export const createVSCodeFilesAPI = (): FilesAPI => ({
async listDirectory(path: string, options?: { respectGitignore?: boolean }): Promise<DirectoryListResult> {
const target = normalizePath(path);
const data = await sendBridgeMessage<{
directory?: string;
path?: string;
entries: Array<{ name: string; path: string; isDirectory: boolean }>;
}>('api:fs:list', {
path: target,
respectGitignore: options?.respectGitignore,
});
const directory = normalizePath(data?.directory || data?.path || target);
const entries = Array.isArray(data?.entries) ? data.entries : [];
return {
directory,
entries: entries.map((entry) => ({
name: entry.name,
path: normalizePath(entry.path),
isDirectory: Boolean(entry.isDirectory),
})),
};
},
async search(payload: FileSearchQuery): Promise<FileSearchResult[]> {
const directory = normalizePath(payload.directory);
const params = new URLSearchParams();
if (directory) {
params.set('directory', directory);
}
params.set('query', payload.query);
params.set('dirs', 'false');
params.set('type', 'file');
if (typeof payload.maxResults === 'number' && Number.isFinite(payload.maxResults)) {
params.set('limit', String(payload.maxResults));
}
const response = await fetch(`/api/find/file?${params.toString()}`);
if (!response.ok) {
const error = await response.json().catch(() => ({ error: response.statusText }));
throw new Error((error as { error?: string }).error || 'Failed to search files');
}
const result = (await response.json()) as string[];
const files = Array.isArray(result) ? result : [];
return files.map((relativePath) => ({
path: normalizePath(`${directory}/${relativePath}`),
preview: [normalizePath(relativePath)],
}));
},
async createDirectory(path: string): Promise<{ success: boolean; path: string }> {
const target = normalizePath(path);
const data = await sendBridgeMessage<{ success: boolean; path: string }>('api:fs:mkdir', { path: target });
return {
success: Boolean(data?.success),
path: typeof data?.path === 'string' ? normalizePath(data.path) : target,
};
},
async delete(path: string): Promise<{ success: boolean }> {
const target = normalizePath(path);
const data = await sendBridgeMessage<{ success: boolean }>('api:fs:delete', { path: target });
return { success: Boolean(data?.success) };
},
async rename(oldPath: string, newPath: string): Promise<{ success: boolean; path: string }> {
const data = await sendBridgeMessage<{ success: boolean; path: string }>('api:fs:rename', { oldPath, newPath });
return {
success: Boolean(data?.success),
path: typeof data?.path === 'string' ? normalizePath(data.path) : newPath,
};
},
async readFile(path: string): Promise<{ content: string; path: string }> {
const target = normalizePath(path);
const data = await sendBridgeMessage<{ content: string; path: string }>('api:fs:read', { path: target });
return {
content: typeof data?.content === 'string' ? data.content : '',
path: typeof data?.path === 'string' ? normalizePath(data.path) : target,
};
},
async writeFile(path: string, content: string): Promise<{ success: boolean; path: string }> {
const target = normalizePath(path);
const data = await sendBridgeMessage<{ success: boolean; path: string }>('api:fs:write', { path: target, content });
return {
success: Boolean(data?.success),
path: typeof data?.path === 'string' ? normalizePath(data.path) : target,
};
},
async execCommands(commands: string[], cwd: string): Promise<{ success: boolean; results: CommandExecResult[] }> {
const targetCwd = normalizePath(cwd);
// Use extended timeout for command execution (5 minutes)
const data = await sendBridgeMessageWithOptions<{ success: boolean; results?: CommandExecResult[] }>('api:fs:exec', {
commands,
cwd: targetCwd,
}, { timeoutMs: 300000 });
return {
success: Boolean(data?.success),
results: Array.isArray(data?.results) ? data.results : [],
};
},
});