b6f89f9df0
- Resolve 57 merge conflicts from codebase restructure - Port dev feature code to new directory structure: * Update import paths to use @/ aliases * Add backward-compatible API signatures (createInstance, startInstance, deleteInstance) * Add missing type exports (ProjectWithRepos, InstanceHealth, Branch, BranchesResponse) * Extend Session and GitRepository types for dev features * Extend TerminalComponent props for mobile terminal wrapper * Add missing icon names (bell, drag, undo) Quality gates: tsc pass (0 errors), build pass, 127/131 tests pass (4 pre-existing failures unrelated to merge)
131 lines
3.5 KiB
TypeScript
131 lines
3.5 KiB
TypeScript
import { apiClient } from "./client";
|
|
import type { Session } from "../types/session";
|
|
import type { ToolInstance } from "../types/tool-instance";
|
|
|
|
export type { Session } from "../types/session";
|
|
export type { ToolInstance } from "../types/tool-instance";
|
|
|
|
export interface InstanceHealth {
|
|
healthy: boolean;
|
|
container_status: string;
|
|
container_health: string | null;
|
|
container_exit_code: number | null;
|
|
tunnel_status: string;
|
|
tunnel_status_code: number | null;
|
|
probe_status: string;
|
|
last_probe_output: string | null;
|
|
error: string | null;
|
|
}
|
|
|
|
export async function listInstances(
|
|
projectId: string,
|
|
repoId: string,
|
|
): Promise<ToolInstance[]> {
|
|
const response = await apiClient.get(
|
|
`/projects/${projectId}/repositories/${repoId}/instances`,
|
|
);
|
|
return response.data.instances;
|
|
}
|
|
|
|
export async function createInstance(
|
|
projectId: string,
|
|
repoId: string,
|
|
toolTypeId: string,
|
|
displayName?: string,
|
|
_cloneMode?: string,
|
|
_branch?: string,
|
|
_newBranch?: string,
|
|
configProfileId?: string,
|
|
_sshKeyIds?: string[],
|
|
workspaceId?: string,
|
|
): Promise<ToolInstance> {
|
|
const response = await apiClient.post(
|
|
`/projects/${projectId}/repositories/${repoId}/instances`,
|
|
{
|
|
tool_type_id: toolTypeId,
|
|
display_name: displayName,
|
|
workspace_id: workspaceId || undefined,
|
|
config_profile_id: configProfileId || undefined,
|
|
},
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function startInstance(
|
|
projectId: string,
|
|
repoId: string,
|
|
instanceId: string,
|
|
configProfileId?: string,
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
_sshKeyIds?: string[],
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
_retries?: number,
|
|
): Promise<{ status: string; url?: string }> {
|
|
const response = await apiClient.post(
|
|
`/projects/${projectId}/repositories/${repoId}/instances/${instanceId}/start`,
|
|
{ config_profile_id: configProfileId },
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function stopInstance(
|
|
projectId: string,
|
|
repoId: string,
|
|
instanceId: string,
|
|
): Promise<{ status: string }> {
|
|
const response = await apiClient.post(
|
|
`/projects/${projectId}/repositories/${repoId}/instances/${instanceId}/stop`,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function restartInstance(
|
|
projectId: string,
|
|
repoId: string,
|
|
instanceId: string,
|
|
): Promise<{ status: string; url?: string }> {
|
|
const response = await apiClient.post(
|
|
`/projects/${projectId}/repositories/${repoId}/instances/${instanceId}/restart`,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function deleteInstance(
|
|
projectId: string,
|
|
repoId: string,
|
|
instanceId: string,
|
|
force?: boolean,
|
|
): Promise<void> {
|
|
const url = force
|
|
? `/projects/${projectId}/repositories/${repoId}/instances/${instanceId}?force=true`
|
|
: `/projects/${projectId}/repositories/${repoId}/instances/${instanceId}`;
|
|
await apiClient.delete(url);
|
|
}
|
|
|
|
export async function getUserSessions(): Promise<Session[]> {
|
|
const response = await apiClient.get("/users/me/sessions");
|
|
return response.data.sessions;
|
|
}
|
|
|
|
export async function checkInstanceHealth(
|
|
projectId: string,
|
|
repoId: string,
|
|
instanceId: string,
|
|
): Promise<{ healthy: boolean; status_code: number | null; error?: string }> {
|
|
const response = await apiClient.get(
|
|
`/projects/${projectId}/repositories/${repoId}/instances/${instanceId}/health`,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
export async function recreateInstanceTunnel(
|
|
projectId: string,
|
|
repoId: string,
|
|
instanceId: string,
|
|
): Promise<{ status: string; url?: string }> {
|
|
const response = await apiClient.post(
|
|
`/projects/${projectId}/repositories/${repoId}/instances/${instanceId}/recreate-tunnel`,
|
|
);
|
|
return response.data;
|
|
}
|