| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| import { |
| WorkspacesClient, |
| type WorkspacesListResponse as SdkWorkspacesListResponse, |
| } from "@openhands/typescript-client/clients"; |
|
|
| import { LocalWorkspace, LocalWorkspaceParent } from "#/types/workspace"; |
|
|
| import { getAgentServerClientOptions } from "../agent-server-client-options"; |
|
|
| export interface WorkspacesListResponse { |
| workspaces: LocalWorkspace[]; |
| workspaceParents: LocalWorkspaceParent[]; |
| } |
|
|
| function client() { |
| return new WorkspacesClient(getAgentServerClientOptions()); |
| } |
|
|
| function toLocalWorkspacesResponse( |
| response: SdkWorkspacesListResponse, |
| ): WorkspacesListResponse { |
| return { |
| workspaces: response.workspaces.map(({ parentPath, ...workspace }) => ({ |
| ...workspace, |
| ...(parentPath ? { parentPath } : {}), |
| })), |
| workspaceParents: response.workspaceParents, |
| }; |
| } |
|
|
| class WorkspacesService { |
| static async listWorkspaces(): Promise<WorkspacesListResponse> { |
| return toLocalWorkspacesResponse(await client().listWorkspaces()); |
| } |
|
|
| static async addWorkspaces( |
| items: LocalWorkspace[], |
| ): Promise<WorkspacesListResponse> { |
| return toLocalWorkspacesResponse(await client().addWorkspaces(items)); |
| } |
|
|
| static async removeWorkspace(path: string): Promise<void> { |
| await client().deleteWorkspace(path); |
| } |
|
|
| static async addWorkspaceParents( |
| items: LocalWorkspaceParent[], |
| ): Promise<WorkspacesListResponse> { |
| return toLocalWorkspacesResponse(await client().addWorkspaceParents(items)); |
| } |
|
|
| static async removeWorkspaceParent(path: string): Promise<void> { |
| await client().deleteWorkspaceParent(path); |
| } |
| } |
|
|
| export default WorkspacesService; |
|
|