forked from longtao.wu/droboticflow
103 lines
3.6 KiB
TypeScript
103 lines
3.6 KiB
TypeScript
import type {
|
|
AnnotationRevision,
|
|
AnnotationReview,
|
|
AnnotationSegment,
|
|
AnnotationTaskDetail,
|
|
AnnotationTaskRecord,
|
|
AnnotationTemplate,
|
|
AnnotationWorkgroup,
|
|
AnnotationWorkloadSummary,
|
|
ProjectAnnotationMembership,
|
|
SemanticLabelDefinition,
|
|
} from "../../types";
|
|
import { apiRequest } from "./client";
|
|
|
|
const query = (values: Record<string, string | undefined>) => {
|
|
const params = new URLSearchParams();
|
|
for (const [key, value] of Object.entries(values)) {
|
|
if (value) params.set(key, value);
|
|
}
|
|
const encoded = params.toString();
|
|
return encoded ? `?${encoded}` : "";
|
|
};
|
|
|
|
export const annotationOperationsApi = {
|
|
listWorkgroups: async () => (await apiRequest<{ items: AnnotationWorkgroup[] }>("/api/annotation-workgroups")).items,
|
|
createWorkgroup: (payload: { name: string; vendorId: string; description?: string }) =>
|
|
apiRequest<AnnotationWorkgroup>("/api/annotation-workgroups", { method: "POST" }, payload),
|
|
listMemberships: async (projectId?: string) =>
|
|
(await apiRequest<{ items: ProjectAnnotationMembership[] }>(`/api/annotation-memberships${query({ projectId })}`))
|
|
.items,
|
|
createMembership: (payload: {
|
|
projectId: string;
|
|
userId: string;
|
|
workgroupId: string;
|
|
assignmentRole: ProjectAnnotationMembership["assignmentRole"];
|
|
}) => apiRequest<ProjectAnnotationMembership>("/api/annotation-memberships", { method: "POST" }, payload),
|
|
listTemplates: async (projectId?: string) =>
|
|
(await apiRequest<{ items: AnnotationTemplate[] }>(`/api/annotation-templates${query({ projectId })}`)).items,
|
|
createTemplate: (payload: {
|
|
projectId: string;
|
|
name: string;
|
|
version: number;
|
|
labels: SemanticLabelDefinition[];
|
|
phrases?: string[];
|
|
prelabel: AnnotationTemplate["prelabel"];
|
|
}) => apiRequest<AnnotationTemplate>("/api/annotation-templates", { method: "POST" }, payload),
|
|
publishTemplate: (id: string) =>
|
|
apiRequest<AnnotationTemplate>(`/api/annotation-templates/${id}/publish`, { method: "POST" }),
|
|
listTasks: async (
|
|
filters: {
|
|
projectId?: string;
|
|
status?: string;
|
|
workgroupId?: string;
|
|
vendorId?: string;
|
|
workflowId?: string;
|
|
runId?: string;
|
|
nodeId?: string;
|
|
artifactId?: string;
|
|
} = {},
|
|
) =>
|
|
(await apiRequest<{ items: AnnotationTaskRecord[] }>(`/api/annotation-tasks${query(filters)}`)).items,
|
|
getTask: (id: string) => apiRequest<AnnotationTaskDetail>(`/api/annotation-tasks/${id}`),
|
|
createTask: (payload: {
|
|
projectId: string;
|
|
dataTaskId?: string;
|
|
workflowId?: string;
|
|
runId?: string;
|
|
nodeId?: string;
|
|
artifactId?: string;
|
|
sourceVideo: string;
|
|
clipStart: number;
|
|
clipEnd: number;
|
|
templateId: string;
|
|
workgroupId: string;
|
|
assignedUserId?: string;
|
|
}) => apiRequest<AnnotationTaskRecord>("/api/annotation-tasks", { method: "POST" }, payload),
|
|
submitRevision: (
|
|
taskId: string,
|
|
payload: { segments: AnnotationSegment[]; changeReason?: string; durationSeconds?: number },
|
|
) =>
|
|
apiRequest<{ task: AnnotationTaskRecord; revision: AnnotationRevision }>(
|
|
`/api/annotation-tasks/${taskId}/revisions`,
|
|
{ method: "POST" },
|
|
payload,
|
|
),
|
|
review: (
|
|
taskId: string,
|
|
payload: {
|
|
stage: AnnotationReview["stage"];
|
|
decision: AnnotationReview["decision"];
|
|
comment?: string;
|
|
durationSeconds?: number;
|
|
},
|
|
) =>
|
|
apiRequest<{ task: AnnotationTaskRecord; review: AnnotationReview }>(
|
|
`/api/annotation-tasks/${taskId}/reviews`,
|
|
{ method: "POST" },
|
|
payload,
|
|
),
|
|
workloadSummary: (projectId?: string) =>
|
|
apiRequest<AnnotationWorkloadSummary>(`/api/annotation-workload-summary${query({ projectId })}`),
|
|
};
|