* 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
71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
import type { SettingsAPI, SettingsLoadResult, SettingsPayload } from '@openchamber/ui/lib/api/types';
|
|
|
|
// Use same endpoints as web - fetch interceptor handles URL rewriting
|
|
const SETTINGS_ENDPOINT = '/api/config/settings';
|
|
const RELOAD_ENDPOINT = '/api/config/reload';
|
|
|
|
const sanitizePayload = (data: unknown): SettingsPayload => {
|
|
if (!data || typeof data !== 'object') {
|
|
return {};
|
|
}
|
|
return data as SettingsPayload;
|
|
};
|
|
|
|
export const createVSCodeSettingsAPI = (): SettingsAPI => ({
|
|
async load(): Promise<SettingsLoadResult> {
|
|
const response = await fetch(SETTINGS_ENDPOINT, {
|
|
method: 'GET',
|
|
headers: { Accept: 'application/json' },
|
|
});
|
|
|
|
if (!response.ok) {
|
|
// Fallback to VS Code config
|
|
return {
|
|
settings: {
|
|
themeVariant: window.__VSCODE_CONFIG__?.theme === 'light' ? 'light' : 'dark',
|
|
lastDirectory: window.__VSCODE_CONFIG__?.workspaceFolder || '',
|
|
},
|
|
source: 'web',
|
|
};
|
|
}
|
|
|
|
const payload = sanitizePayload(await response.json().catch(() => ({})));
|
|
return {
|
|
settings: {
|
|
...payload,
|
|
// Override with VS Code settings
|
|
lastDirectory: window.__VSCODE_CONFIG__?.workspaceFolder || payload.lastDirectory || '',
|
|
},
|
|
source: 'web',
|
|
};
|
|
},
|
|
|
|
async save(changes: Partial<SettingsPayload>): Promise<SettingsPayload> {
|
|
const response = await fetch(SETTINGS_ENDPOINT, {
|
|
method: 'PUT',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Accept: 'application/json',
|
|
},
|
|
body: JSON.stringify(changes),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const error = await response.json().catch(() => ({ error: response.statusText }));
|
|
throw new Error(error.error || 'Failed to save settings');
|
|
}
|
|
|
|
const payload = sanitizePayload(await response.json().catch(() => ({})));
|
|
return payload;
|
|
},
|
|
|
|
async restartOpenCode(): Promise<{ restarted: boolean }> {
|
|
const response = await fetch(RELOAD_ENDPOINT, { method: 'POST' });
|
|
if (!response.ok) {
|
|
const error = await response.json().catch(() => ({ error: response.statusText }));
|
|
throw new Error(error.error || 'Failed to restart OpenCode');
|
|
}
|
|
return { restarted: true };
|
|
},
|
|
});
|