fix: add from __future__ import annotations to workspace_manager.py
Fixes NameError: ToolInstance not defined at runtime because type annotations are evaluated at class definition time. Deferring annotation evaluation with __future__ annotations keeps TYPE_CHECKING imports from causing runtime crashes. Also includes ruff formatting cleanup on workspace-related files.
This commit is contained in:
@@ -1,65 +1,82 @@
|
||||
/** Workspace API client. */
|
||||
|
||||
import { apiClient } from "./client";
|
||||
import type { Workspace, CreateWorkspaceRequest, SyncResult } from "../types/workspace";
|
||||
import type {
|
||||
Workspace,
|
||||
CreateWorkspaceRequest,
|
||||
SyncResult,
|
||||
} from "../types/workspace";
|
||||
|
||||
function workspaceUrl(projectId: string, repoId: string, workspaceId?: string) {
|
||||
const base = `/projects/${projectId}/repositories/${repoId}/workspaces`;
|
||||
return workspaceId ? `${base}/${workspaceId}` : base;
|
||||
const base = `/projects/${projectId}/repositories/${repoId}/workspaces`;
|
||||
return workspaceId ? `${base}/${workspaceId}` : base;
|
||||
}
|
||||
|
||||
export async function listWorkspaces(projectId: string, repoId: string): Promise<Workspace[]> {
|
||||
const response = await apiClient.get<Workspace[]>(workspaceUrl(projectId, repoId));
|
||||
return response.data;
|
||||
export async function listWorkspaces(
|
||||
projectId: string,
|
||||
repoId: string,
|
||||
): Promise<Workspace[]> {
|
||||
const response = await apiClient.get<Workspace[]>(
|
||||
workspaceUrl(projectId, repoId),
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function createWorkspace(
|
||||
projectId: string,
|
||||
repoId: string,
|
||||
data: CreateWorkspaceRequest,
|
||||
projectId: string,
|
||||
repoId: string,
|
||||
data: CreateWorkspaceRequest,
|
||||
): Promise<Workspace> {
|
||||
const response = await apiClient.post<Workspace>(workspaceUrl(projectId, repoId), data);
|
||||
return response.data;
|
||||
const response = await apiClient.post<Workspace>(
|
||||
workspaceUrl(projectId, repoId),
|
||||
data,
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getWorkspace(
|
||||
projectId: string,
|
||||
repoId: string,
|
||||
workspaceId: string,
|
||||
projectId: string,
|
||||
repoId: string,
|
||||
workspaceId: string,
|
||||
): Promise<Workspace> {
|
||||
const response = await apiClient.get<Workspace>(workspaceUrl(projectId, repoId, workspaceId));
|
||||
return response.data;
|
||||
const response = await apiClient.get<Workspace>(
|
||||
workspaceUrl(projectId, repoId, workspaceId),
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function updateWorkspace(
|
||||
projectId: string,
|
||||
repoId: string,
|
||||
workspaceId: string,
|
||||
data: Partial<CreateWorkspaceRequest>,
|
||||
projectId: string,
|
||||
repoId: string,
|
||||
workspaceId: string,
|
||||
data: Partial<CreateWorkspaceRequest>,
|
||||
): Promise<Workspace> {
|
||||
const response = await apiClient.patch<Workspace>(workspaceUrl(projectId, repoId, workspaceId), data);
|
||||
return response.data;
|
||||
const response = await apiClient.patch<Workspace>(
|
||||
workspaceUrl(projectId, repoId, workspaceId),
|
||||
data,
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function deleteWorkspace(
|
||||
projectId: string,
|
||||
repoId: string,
|
||||
workspaceId: string,
|
||||
force = false,
|
||||
projectId: string,
|
||||
repoId: string,
|
||||
workspaceId: string,
|
||||
force = false,
|
||||
): Promise<{ status: string }> {
|
||||
const response = await apiClient.delete<{ status: string }>(
|
||||
`${workspaceUrl(projectId, repoId, workspaceId)}?force=${force}`,
|
||||
);
|
||||
return response.data;
|
||||
const response = await apiClient.delete<{ status: string }>(
|
||||
`${workspaceUrl(projectId, repoId, workspaceId)}?force=${force}`,
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function syncWorkspace(
|
||||
projectId: string,
|
||||
repoId: string,
|
||||
workspaceId: string,
|
||||
projectId: string,
|
||||
repoId: string,
|
||||
workspaceId: string,
|
||||
): Promise<SyncResult> {
|
||||
const response = await apiClient.post<SyncResult>(
|
||||
`${workspaceUrl(projectId, repoId, workspaceId)}/sync`,
|
||||
);
|
||||
return response.data;
|
||||
const response = await apiClient.post<SyncResult>(
|
||||
`${workspaceUrl(projectId, repoId, workspaceId)}/sync`,
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user