mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(worktree): worktree tabs, server env vars, and multi-directory SSE (#240)
* loop: worktree-tabs-2 completed after 4 iterations * loop: server-env-vars completed after 7 iterations * feat(worktree): add worktree tabs and server env vars settings * refactor(worktree): multi-directory SSE support and workspace chip row * feat(workspace): collapsible workspace manager and sibling filtering * feat(workspace): workspace creation endpoint, refactored workspace manager, and tests * refactor(frontend): unify workspace label and remove dead code - extract shared workspaceLabel helper into api/repos and reuse in WorkspaceManager and RepoDetail directoryLabels - remove unused useSessions hook and subscribeToDirectory subscription - drop redundant frontend workspace dedup now guaranteed by backend - align WorktreeTabs empty-state test with create-workspace button
This commit is contained in:
1 parent
60ed756a0b
commit
b9236f7f20
38 files changed
+2423
-133
No files matched your search
@@ -29,10 +29,22 @@ function formatDetails(details: unknown): string | undefined {
|
||||
}
|
||||
|
||||
async function handleResponse(response: Response): Promise<never> {
|
||||
const data: ApiErrorResponse = await response.json().catch(() => ({ error: 'An error occurred' }))
|
||||
const text = await response.text().catch(() => '')
|
||||
const data: ApiErrorResponse = (() => {
|
||||
if (!text) return { error: 'An error occurred' }
|
||||
try {
|
||||
return JSON.parse(text) as ApiErrorResponse
|
||||
} catch {
|
||||
return { error: text }
|
||||
}
|
||||
})()
|
||||
const errorData = data as ApiErrorResponse & { message?: string; data?: { message?: unknown } }
|
||||
const openCodeMessage = typeof errorData.data?.message === 'string'
|
||||
? errorData.data.message
|
||||
: undefined
|
||||
const detail = data.detail || formatDetails(data.details)
|
||||
throw new FetchError(
|
||||
data.error || 'Request failed',
|
||||
data.error || errorData.message || openCodeMessage || 'Request failed',
|
||||
response.status,
|
||||
data.code,
|
||||
detail,
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { OpenCodeClient } from './opencode'
|
||||
|
||||
describe('OpenCodeClient', () => {
|
||||
const fetchMock = vi.fn()
|
||||
|
||||
beforeEach(() => {
|
||||
fetchMock.mockReset()
|
||||
vi.stubGlobal('fetch', fetchMock)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
it('treats empty successful session deletes as success', async () => {
|
||||
fetchMock.mockResolvedValue(new Response(null, { status: 204 }))
|
||||
|
||||
await expect(new OpenCodeClient('/api/opencode', '/repo').deleteSession('ses_1')).resolves.toBeUndefined()
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
'http://localhost/api/opencode/session/ses_1?directory=%2Frepo',
|
||||
expect.objectContaining({ method: 'DELETE' }),
|
||||
)
|
||||
})
|
||||
|
||||
it('deletes workspaces with directory routing', async () => {
|
||||
fetchMock.mockResolvedValue(new Response(null, { status: 204 }))
|
||||
|
||||
await expect(new OpenCodeClient('/api/opencode', '/repo').deleteWorkspace('wrk_stale')).resolves.toBeUndefined()
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith(
|
||||
'http://localhost/api/opencode/experimental/workspace/wrk_stale?directory=%2Frepo',
|
||||
expect.objectContaining({ method: 'DELETE' }),
|
||||
)
|
||||
})
|
||||
|
||||
it('preserves text error responses', async () => {
|
||||
fetchMock.mockResolvedValue(new Response('Workspace not found: wrk_stale', { status: 500 }))
|
||||
|
||||
await expect(new OpenCodeClient('/api/opencode', '/repo').deleteSession('ses_1')).rejects.toThrow(
|
||||
'Workspace not found: wrk_stale',
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -61,7 +61,14 @@ export class OpenCodeClient {
|
||||
}
|
||||
|
||||
async deleteSession(sessionID: string) {
|
||||
return fetchWrapper(`${this.baseURL}/session/${sessionID}`, {
|
||||
return fetchWrapperVoid(`${this.baseURL}/session/${sessionID}`, {
|
||||
method: 'DELETE',
|
||||
params: this.getParams(),
|
||||
})
|
||||
}
|
||||
|
||||
async deleteWorkspace(workspaceID: string) {
|
||||
return fetchWrapperVoid(`${this.baseURL}/experimental/workspace/${workspaceID}`, {
|
||||
method: 'DELETE',
|
||||
params: this.getParams(),
|
||||
})
|
||||
|
||||
@@ -38,6 +38,48 @@ export async function getRepo(id: number): Promise<Repo> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${id}`)
|
||||
}
|
||||
|
||||
export type RepoSibling = Repo & {
|
||||
currentBranch?: string
|
||||
workspaceId?: string
|
||||
workspaceType?: string
|
||||
workspaceName?: string
|
||||
}
|
||||
|
||||
export function workspaceLabel(workspace: RepoSibling): string {
|
||||
return (
|
||||
workspace.currentBranch ||
|
||||
workspace.branch ||
|
||||
workspace.workspaceName ||
|
||||
workspace.workspaceId ||
|
||||
'workspace'
|
||||
)
|
||||
}
|
||||
|
||||
export interface RepoWorkspace {
|
||||
id: string
|
||||
type: string
|
||||
name?: string | null
|
||||
branch?: string | null
|
||||
directory?: string | null
|
||||
projectID?: string
|
||||
}
|
||||
|
||||
export async function getRepoSiblings(id: number): Promise<RepoSibling[]> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${id}/siblings`)
|
||||
}
|
||||
|
||||
export async function deleteRepoWorkspace(repoId: number, workspaceId: string): Promise<void> {
|
||||
return fetchWrapperVoid(`${API_BASE_URL}/api/repos/${repoId}/workspaces/${workspaceId}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
}
|
||||
|
||||
export async function createRepoWorkspace(repoId: number): Promise<RepoWorkspace> {
|
||||
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/workspaces`, {
|
||||
method: 'POST',
|
||||
})
|
||||
}
|
||||
|
||||
export async function deleteRepo(id: number): Promise<void> {
|
||||
return fetchWrapperVoid(`${API_BASE_URL}/api/repos/${id}`, {
|
||||
method: 'DELETE',
|
||||
|
||||
@@ -4,6 +4,8 @@ import {
|
||||
DEFAULT_KEYBOARD_SHORTCUTS,
|
||||
DEFAULT_USER_PREFERENCES,
|
||||
DEFAULT_LEADER_KEY,
|
||||
BLOCKED_SERVER_ENV_KEYS,
|
||||
DEFAULT_SERVER_ENV_VARS,
|
||||
type TTSConfig,
|
||||
type STTConfig,
|
||||
type OpenCodeConfigContent,
|
||||
@@ -17,7 +19,7 @@ import {
|
||||
import type { NotificationPreferences } from '@opencode-manager/shared/types'
|
||||
|
||||
export type { TTSConfig, STTConfig, OpenCodeConfigContent, ModelConfig, ProviderConfig, NotificationPreferences, SkillFileInfo, CreateSkillRequest, UpdateSkillRequest, SkillScope }
|
||||
export { DEFAULT_TTS_CONFIG, DEFAULT_STT_CONFIG, DEFAULT_KEYBOARD_SHORTCUTS, DEFAULT_USER_PREFERENCES, DEFAULT_LEADER_KEY }
|
||||
export { DEFAULT_TTS_CONFIG, DEFAULT_STT_CONFIG, DEFAULT_KEYBOARD_SHORTCUTS, DEFAULT_USER_PREFERENCES, DEFAULT_LEADER_KEY, BLOCKED_SERVER_ENV_KEYS, DEFAULT_SERVER_ENV_VARS }
|
||||
|
||||
export interface CustomCommand {
|
||||
name: string
|
||||
@@ -63,6 +65,8 @@ export interface UserPreferences {
|
||||
notifications?: NotificationPreferences
|
||||
repoOrder?: number[]
|
||||
repoSortMode?: 'recent' | 'manual' | 'name'
|
||||
serverEnvVars?: Array<{ key: string; value: string }>
|
||||
disabledDefaultServerEnvVars?: string[]
|
||||
}
|
||||
|
||||
export interface SettingsResponse {
|
||||
|
||||
Reference in new issue
Block a user