- 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]>
73 lines
2.5 KiB
TypeScript
73 lines
2.5 KiB
TypeScript
import { keepPreviousData, useInfiniteQuery, useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import {
|
|
cursorPage,
|
|
MediaEntity,
|
|
Subscription,
|
|
type SubscriptionCreate,
|
|
type SubscriptionMediaKind,
|
|
type SubscriptionStatus,
|
|
type SubscriptionUpdate,
|
|
} from "@umt/contracts";
|
|
import { api } from "~/lib/api.ts";
|
|
import { getParsed, parseOrThrow } from "./library.ts";
|
|
|
|
// 订阅:单次收录 / 持续追踪,仅本季 / 接续后续季(REQ §6.5)
|
|
|
|
export const subscriptionKeys = {
|
|
all: ["subscriptions"] as const,
|
|
list: (f: SubscriptionFilters) => ["subscriptions", "list", f] as const,
|
|
};
|
|
|
|
export type SubscriptionFilters = {
|
|
status?: SubscriptionStatus;
|
|
mediaEntityId?: string;
|
|
mediaKind?: SubscriptionMediaKind;
|
|
/** 标题 / 原名 / 别名 / 未建档检索词 */
|
|
q?: string;
|
|
};
|
|
|
|
const Page = cursorPage(Subscription);
|
|
|
|
export function useSubscriptions(filters: SubscriptionFilters) {
|
|
return useInfiniteQuery({
|
|
queryKey: subscriptionKeys.list(filters),
|
|
initialPageParam: undefined as string | undefined,
|
|
queryFn: ({ pageParam, signal }) =>
|
|
getParsed(Page, "/subscriptions", { ...filters, cursor: pageParam, limit: 50 }, signal),
|
|
getNextPageParam: (last) => last.nextCursor ?? undefined,
|
|
placeholderData: keepPreviousData,
|
|
});
|
|
}
|
|
|
|
export function useCreateSubscription() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: (body: SubscriptionCreate) =>
|
|
api.post<unknown>("/subscriptions", body).then((d) => parseOrThrow(Subscription, d, "/subscriptions")),
|
|
onSuccess: () => {
|
|
void qc.invalidateQueries({ queryKey: subscriptionKeys.all });
|
|
void qc.invalidateQueries({ queryKey: ["slots"] });
|
|
void qc.invalidateQueries({ queryKey: ["library"] });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useUpdateSubscription() {
|
|
const qc = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: ({ id, ...body }: SubscriptionUpdate & { id: string }) =>
|
|
api.patch<unknown>(`/subscriptions/${id}`, body).then((d) => parseOrThrow(Subscription, d, "/subscriptions")),
|
|
onSuccess: () => void qc.invalidateQueries({ queryKey: subscriptionKeys.all }),
|
|
});
|
|
}
|
|
|
|
/** 订阅行上显示作品标题(旧 ID 自动跳转);按 ID 缓存 */
|
|
export function useEntityTitle(id: string | null | undefined) {
|
|
return useQuery({
|
|
queryKey: ["library", "entity-row", id ?? ""],
|
|
enabled: !!id,
|
|
staleTime: 5 * 60_000,
|
|
queryFn: ({ signal }) => getParsed(MediaEntity, `/media-entities/${id}`, undefined, signal),
|
|
});
|
|
}
|