- POST /organization-records: sourcePaths must resolve (realpath) under a
registered library_root or downloader path-mapping host path; `..` and
symlink escapes rejected (400), dryRun included. Move requires an admin
session, or an API key with an automation_grant covering the entity or a
matching one-time approval (consumed on use), else 403. Manual Move from a
managed download_task with unsatisfied H&R returns 409 and opens a
decision; never silently downgraded to Copy.
- Series slot completion: total episode count is unknown while units are
provisional, so the slot is not satisfied and the subscription keeps
tracking; coverage is registered per actual file (creating provisional
episode units), and already_in_library files count as verified presence.
- POST /engine/runs/{id}/retry (admin): re-enqueue by original task name and
raw input with idempotency key retry:<id>:<n>, audited; retry button on
the run detail page.
- E7 regular series e2e, E8 AT24 tag removal / task disappearance e2e.
- All workspace members and root set to version 0.1.0; CHANGELOG.md.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
64 lines
2.3 KiB
TypeScript
64 lines
2.3 KiB
TypeScript
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import type { CursorPage, EngineRun, EngineRunDetail, EngineStats } from "@umt/contracts";
|
|
import { apiData } from "~/lib/api.ts";
|
|
import { qk } from "~/lib/query-keys.ts";
|
|
|
|
export type EngineRunFilters = { status?: string; workflowName?: string };
|
|
|
|
/** 终态:不能再 cancel */
|
|
export const ENGINE_TERMINAL = new Set(["completed", "succeeded", "failed", "canceled"]);
|
|
|
|
export function useEngineRuns(filters: EngineRunFilters) {
|
|
return useInfiniteQuery({
|
|
queryKey: qk.list("engine", filters),
|
|
initialPageParam: undefined as string | undefined,
|
|
queryFn: ({ pageParam, signal }) =>
|
|
apiData<CursorPage<EngineRun>>("/engine/runs", { params: { ...filters, cursor: pageParam, limit: 50 }, signal }),
|
|
getNextPageParam: (last) => last.nextCursor ?? undefined,
|
|
});
|
|
}
|
|
|
|
export function useEngineRun(id: string | undefined) {
|
|
return useQuery({
|
|
queryKey: qk.detail("engine", id ?? ""),
|
|
queryFn: ({ signal }) => apiData<EngineRunDetail>("/engine/runs/{id}", { pathParams: { id: id ?? "" }, signal }),
|
|
enabled: !!id,
|
|
// 非终态每 5 秒兜底刷新(SSE 事件驱动是主路径)
|
|
refetchInterval: (q) => (q.state.data && !ENGINE_TERMINAL.has(q.state.data.status) ? 5_000 : false),
|
|
});
|
|
}
|
|
|
|
export function useEngineStats() {
|
|
return useQuery({
|
|
queryKey: qk.engineStats,
|
|
queryFn: ({ signal }) => apiData<EngineStats>("/engine/stats", { signal }),
|
|
refetchInterval: 30_000,
|
|
});
|
|
}
|
|
|
|
export function useCancelEngineRun() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: ({ id, reason }: { id: string; reason?: string }) =>
|
|
apiData<{ canceled: boolean }>("/engine/runs/{id}/cancel", {
|
|
method: "POST",
|
|
pathParams: { id },
|
|
body: { reason },
|
|
}),
|
|
onSettled: () => qc.invalidateQueries({ queryKey: qk.all("engine") }),
|
|
});
|
|
}
|
|
|
|
/** 重跑已结束的 run:服务端按原任务名与原始输入重新入队,返回新 runId */
|
|
export function useRetryEngineRun() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: ({ id }: { id: string }) =>
|
|
apiData<{ runId: string; retryOf: string; attempt: number }>("/engine/runs/{id}/retry", {
|
|
method: "POST",
|
|
pathParams: { id },
|
|
}),
|
|
onSettled: () => qc.invalidateQueries({ queryKey: qk.all("engine") }),
|
|
});
|
|
}
|