forked from longtao.wu/droboticflow
51 lines
2.3 KiB
TypeScript
51 lines
2.3 KiB
TypeScript
import type { ExecutionData, ExecutionRun, ExecutionRunSummary, LogEntry, ResourceUsage } from "../../types";
|
|
import { apiRequest } from "./client";
|
|
|
|
export { type ExecutionData, type LogEntry, type ResourceUsage };
|
|
|
|
type StorageBrowseTarget = {
|
|
sourcePath?: string;
|
|
connectionId?: string;
|
|
};
|
|
|
|
export const monitoringApi = {
|
|
listRuns: async () => (await apiRequest<{ items: ExecutionRunSummary[] }>("/api/runs")).items,
|
|
getRun: (runId: string) => apiRequest<ExecutionRun>(`/api/runs/${runId}`),
|
|
rerunSubtree: (runId: string, nodeId: string) =>
|
|
apiRequest<ExecutionRun>(`/api/runs/${runId}/rerun-subtree`, { method: "POST" }, { nodeId }),
|
|
stopRun: (runId: string) => apiRequest<ExecutionRun>(`/api/runs/${runId}/stop`, { method: "POST" }),
|
|
forceStopRun: (runId: string) => apiRequest<ExecutionRun>(`/api/runs/${runId}/force-stop`, { method: "POST" }),
|
|
getLogs: async (runId: string): Promise<LogEntry[]> =>
|
|
(await apiRequest<{ items: LogEntry[] }>(`/api/runs/${runId}/logs`)).items,
|
|
getResourceUsage: async (runId: string): Promise<ResourceUsage[]> =>
|
|
(await apiRequest<{ items: ResourceUsage[] }>(`/api/runs/${runId}/resources`)).items,
|
|
getExecutionData: async (runId: string): Promise<ExecutionData[]> =>
|
|
(await apiRequest<{ items: ExecutionData[] }>(`/api/runs/${runId}/artifacts`)).items,
|
|
listOssBuckets: async ({ sourcePath = "", connectionId = "" }: StorageBrowseTarget): Promise<string[]> => {
|
|
const query = new URLSearchParams();
|
|
if (connectionId.trim()) {
|
|
query.set("connectionId", connectionId.trim());
|
|
}
|
|
if (sourcePath.trim()) {
|
|
query.set("sourcePath", sourcePath.trim());
|
|
}
|
|
return (await apiRequest<{ items: string[] }>(`/api/storage/buckets?${query.toString()}`)).items;
|
|
},
|
|
listOssObjects: async (
|
|
{ sourcePath = "", connectionId = "" }: StorageBrowseTarget,
|
|
bucket: string,
|
|
prefix: string,
|
|
): Promise<string[]> => {
|
|
const query = new URLSearchParams();
|
|
if (connectionId.trim()) {
|
|
query.set("connectionId", connectionId.trim());
|
|
}
|
|
if (sourcePath.trim()) {
|
|
query.set("sourcePath", sourcePath.trim());
|
|
}
|
|
query.set("bucket", bucket);
|
|
query.set("prefix", prefix);
|
|
return (await apiRequest<{ items: string[] }>(`/api/storage/objects?${query.toString()}`)).items;
|
|
},
|
|
};
|