- Agent page uses contracts (AgentRun/AgentRunDetail/AgentGoalReport) instead of a local mirror; ?mock=1 stays as an explicit demo switch; run snapshot refreshes on agent.run_status; stream auto-follow only while the user stays near the bottom (abort stays reachable) - settings: Pi provider select incl. fake, new Agent runtime card (budgets, fakeScript) - download trace uses /tasks?subjectId= and /organization-records?downloadTaskId= instead of time-window engine run matching and path matching; new business-task tab with cancel/retry - workbench download dialog posts /acquisition-plans and shows per-slot rejection reasons - preference tag revision history; subscription search by title/kind; identity/alias/subscription lists show entity titles; slot cards show current asset summary; policy preview sample titles - DecisionSummary / IdentityRevisionList / ReleaseIdentityResult / TaskAccepted / PolicyPreviewSummary / OrganizePlanArtifactContent taken from contracts - docs: SSE for console (cookie) vs GET /events?after=&limit= JSON replay for API keys Co-Authored-By: Claude Opus 5.5 <[email protected]>
91 lines
3.4 KiB
TypeScript
91 lines
3.4 KiB
TypeScript
import { keepPreviousData, useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import {
|
|
ManualAcquisitionResult,
|
|
type ResolutionStatus,
|
|
WorkbenchReleaseDetail,
|
|
WorkbenchReleasePage,
|
|
} from "@umt/contracts";
|
|
import { apiMutate, apiParsed, cleanParams } from "./parse.ts";
|
|
|
|
// 站点工作台整理视图(W2-B:/sites/{id}/releases、/sites/{id}/releases/{rid})
|
|
|
|
export type ReleaseFilters = {
|
|
q?: string;
|
|
category?: string;
|
|
promotion?: string;
|
|
resolution?: ResolutionStatus;
|
|
};
|
|
|
|
export const releaseKeys = {
|
|
all: ["releases"] as const,
|
|
list: (siteId: string, f: ReleaseFilters, live: boolean) => ["releases", "list", siteId, f, live] as const,
|
|
detail: (siteId: string, rid: string) => ["releases", "detail", siteId, rid] as const,
|
|
};
|
|
|
|
/**
|
|
* 统一资源列表,游标分页。live=true 强制实时补查(只对第一页);否则让服务端按"本地无结果或快照过期"自行决定。
|
|
* 翻页时保留上一次数据,避免"提取失败 = 空列表"。
|
|
*/
|
|
export function useSiteReleases(siteId: string | undefined, filters: ReleaseFilters, live = false) {
|
|
return useInfiniteQuery({
|
|
queryKey: releaseKeys.list(siteId ?? "", filters, live),
|
|
enabled: !!siteId,
|
|
initialPageParam: undefined as string | undefined,
|
|
placeholderData: keepPreviousData,
|
|
queryFn: ({ pageParam, signal }) =>
|
|
apiParsed(WorkbenchReleasePage, "/api/v1/sites/:id/releases", {
|
|
pathParams: { id: siteId ?? "" },
|
|
params: cleanParams({
|
|
...filters,
|
|
cursor: pageParam,
|
|
limit: 50,
|
|
live: live && !pageParam ? "true" : undefined,
|
|
}),
|
|
signal,
|
|
}),
|
|
getNextPageParam: (last) => last.nextCursor ?? undefined,
|
|
});
|
|
}
|
|
|
|
/** 资源详情;refresh=true 时实时复核(失败保留既有数据并带 refreshError) */
|
|
export function useReleaseDetail(siteId: string | undefined, rid: string | undefined) {
|
|
return useQuery({
|
|
queryKey: releaseKeys.detail(siteId ?? "", rid ?? ""),
|
|
enabled: !!siteId && !!rid,
|
|
queryFn: ({ signal }) =>
|
|
apiParsed(WorkbenchReleaseDetail, "/api/v1/sites/:id/releases/:rid", {
|
|
pathParams: { id: siteId ?? "", rid: rid ?? "" },
|
|
signal,
|
|
}),
|
|
});
|
|
}
|
|
|
|
export function useRefreshReleaseDetail() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: ({ siteId, rid }: { siteId: string; rid: string }) =>
|
|
apiParsed(WorkbenchReleaseDetail, "/api/v1/sites/:id/releases/:rid", {
|
|
pathParams: { id: siteId, rid },
|
|
params: { refresh: "true" },
|
|
}),
|
|
onSuccess: (d, v) => qc.setQueryData(releaseKeys.detail(v.siteId, v.rid), d),
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 统一下载入口 POST /acquisition-plans:与自动收录同一条流程(download.plan → download.submit:
|
|
* 硬条件/预算/缓存阈值/授权 → 预留 Slot → submitDownload)。未生成计划时 submitted=false 并给出逐个 Slot 的原因。
|
|
*/
|
|
export function useSubmitRelease() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (body: { sourceReleaseId: string; slotId?: string; entityId?: string; note?: string }) =>
|
|
apiMutate("/api/v1/acquisition-plans", { body }).then((d) => ManualAcquisitionResult.parse(d)),
|
|
onSuccess: (r) => {
|
|
if (r.submitted) void qc.invalidateQueries({ queryKey: ["downloads"] });
|
|
void qc.invalidateQueries({ queryKey: ["inventory"] });
|
|
void qc.invalidateQueries({ queryKey: ["library"] });
|
|
},
|
|
});
|
|
}
|