- 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]>
57 lines
2.1 KiB
TypeScript
57 lines
2.1 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import {
|
|
cursorPage,
|
|
PolicyPreviewSummary,
|
|
PolicyRevision,
|
|
type PolicyRevisionCreate,
|
|
type PolicyRevisionUpdate,
|
|
type PolicyStatus,
|
|
} from "@umt/contracts";
|
|
import { api } from "~/lib/api.ts";
|
|
import { getParsed, parseOrThrow } from "./library.ts";
|
|
|
|
// 策略版本:草案 → 预览 → 授权发布 → 版本化 / 回滚(REQ §6.4)
|
|
|
|
export const policyKeys = {
|
|
all: ["policies"] as const,
|
|
list: (f: PolicyFilters) => ["policies", "list", f] as const,
|
|
};
|
|
|
|
export type PolicyFilters = { policyKey?: string; status?: PolicyStatus };
|
|
|
|
const Page = cursorPage(PolicyRevision);
|
|
|
|
export function usePolicyRevisions(filters: PolicyFilters = {}) {
|
|
return useQuery({
|
|
queryKey: policyKeys.list(filters),
|
|
queryFn: ({ signal }) => getParsed(Page, "/policy-revisions", { ...filters, limit: 200 }, signal),
|
|
});
|
|
}
|
|
|
|
/** 预览结果(合同 PolicyPreviewSummary;存在 policy_revision.preview) */
|
|
export const PolicyPreview = PolicyPreviewSummary;
|
|
export type PolicyPreview = PolicyPreviewSummary;
|
|
|
|
const parse = (d: unknown) => parseOrThrow(PolicyRevision, d, "/policy-revisions");
|
|
|
|
function useAction<V>(fn: (v: V) => Promise<unknown>) {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (v: V) => fn(v).then(parse),
|
|
onSuccess: () => {
|
|
void qc.invalidateQueries({ queryKey: policyKeys.all });
|
|
void qc.invalidateQueries({ queryKey: ["subscriptions"] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export const useCreatePolicy = () => useAction((body: PolicyRevisionCreate) => api.post("/policy-revisions", body));
|
|
export const useUpdatePolicy = () =>
|
|
useAction(({ id, ...body }: PolicyRevisionUpdate & { id: string }) => api.patch(`/policy-revisions/${id}`, body));
|
|
export const usePreviewPolicy = () => useAction((id: string) => api.post(`/policy-revisions/${id}/preview`));
|
|
export const usePublishPolicy = () =>
|
|
useAction((v: { id: string; expectedRevision: number }) =>
|
|
api.post(`/policy-revisions/${v.id}/publish`, { expectedRevision: v.expectedRevision }),
|
|
);
|
|
export const useRollbackPolicy = () => useAction((id: string) => api.post(`/policy-revisions/${id}/rollback`));
|