* feat: add initial VS Code extension plan and implementation tasks * feat(vscode): added initial version of an Openchamber VSCode extension * feat(vscode): enhance VS Code extension with theme integration and session management * feat(vscode): implement connection status handling and overlay in VSCode layout * feat: move extension to secondary sidebar * chore: upgrade @opencode-ai/sdk to 1.0.150 * vscode: editor bridge, file picker, click-to-open in tool parts * vscode: layout session lifecycle, theme sync, typography overrides * ui: compact mode for vscode, model search, autocomplete width fixes * perf: scroll force flag, raf placeholder, git polling backoff * ui: tool output styling, markdown code block fix, gitignore * refactor: update typography handling for VSCode runtime, remove unused styles * docs: update README with VS Code extension details and add extension image * docs: update changelog with new features and performance improvements
72 lines
2.5 KiB
TypeScript
72 lines
2.5 KiB
TypeScript
import type { DirectoryListResult, FileSearchQuery, FileSearchResult, FilesAPI } from '@openchamber/ui/lib/api/types';
|
|
|
|
// Use same endpoints as web - fetch interceptor handles URL rewriting
|
|
const normalizePath = (path: string): string => path.replace(/\\/g, '/');
|
|
|
|
export const createVSCodeFilesAPI = (): FilesAPI => ({
|
|
async listDirectory(path: string): Promise<DirectoryListResult> {
|
|
const target = normalizePath(path);
|
|
const response = await fetch('/api/fs/list', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ path: target }),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const error = await response.json().catch(() => ({ error: response.statusText }));
|
|
throw new Error(error.error || 'Failed to list directory');
|
|
}
|
|
|
|
return response.json();
|
|
},
|
|
|
|
async search(payload: FileSearchQuery): Promise<FileSearchResult[]> {
|
|
const response = await fetch('/api/fs/search', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
directory: normalizePath(payload.directory),
|
|
query: payload.query,
|
|
maxResults: payload.maxResults,
|
|
}),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const error = await response.json().catch(() => ({ error: response.statusText }));
|
|
throw new Error(error.error || 'Failed to search files');
|
|
}
|
|
|
|
const results = (await response.json()) as unknown;
|
|
if (!Array.isArray(results)) {
|
|
return [];
|
|
}
|
|
return results
|
|
.filter((item): item is FileSearchResult => !!item && typeof item === 'object' && typeof (item as { path?: string }).path === 'string')
|
|
.map((item) => ({
|
|
path: normalizePath((item as FileSearchResult).path),
|
|
score: (item as FileSearchResult).score,
|
|
preview: (item as FileSearchResult).preview,
|
|
}));
|
|
},
|
|
|
|
async createDirectory(path: string): Promise<{ success: boolean; path: string }> {
|
|
const target = normalizePath(path);
|
|
const response = await fetch('/api/fs/mkdir', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ path: target }),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const error = await response.json().catch(() => ({ error: response.statusText }));
|
|
throw new Error(error.error || 'Failed to create directory');
|
|
}
|
|
|
|
const result = await response.json();
|
|
return {
|
|
success: Boolean(result?.success),
|
|
path: typeof result?.path === 'string' ? normalizePath(result.path) : target,
|
|
};
|
|
},
|
|
});
|