Files
wehub-resource-sync 6ede33ccdb
Build and Push Docker Images / create_manifest (web, surfsense-web, , cpu) (push) Has been cancelled
Build and Push Docker Images / finalize_release (push) Has been cancelled
Obsidian Plugin Lint / lint (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / compute_version (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / verify_digests (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, , cpu) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda, cuda) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda126, cuda126) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:33:44 +08:00

99 lines
3.1 KiB
TypeScript

import { useQuery } from "@tanstack/react-query";
import { imageGenerationsApiService } from "@/lib/apis/image-generations-api.service";
import { podcastsApiService } from "@/lib/apis/podcasts-api.service";
import { reportsApiService } from "@/lib/apis/reports-api.service";
import { videoPresentationsApiService } from "@/lib/apis/video-presentations-api.service";
import type { LibraryArtifact, LibraryArtifactStatus } from "../model/artifact";
function podcastStatus(status: string): LibraryArtifactStatus {
if (status === "ready") return "ready";
if (status === "failed" || status === "cancelled") return "error";
return "running";
}
function videoStatus(status: string): LibraryArtifactStatus {
if (status === "ready") return "ready";
if (status === "failed") return "error";
return "running";
}
// Each list is fetched independently; one failing source shouldn't blank the
// whole library, so failures degrade to an empty slice.
async function fetchLibraryArtifacts(workspaceId: number): Promise<LibraryArtifact[]> {
const [reports, podcasts, videos, images] = await Promise.all([
reportsApiService.list(workspaceId).catch(() => []),
podcastsApiService.list(workspaceId).catch(() => []),
videoPresentationsApiService.list(workspaceId).catch(() => []),
imageGenerationsApiService.list(workspaceId).catch(() => []),
]);
const artifacts: LibraryArtifact[] = [];
for (const report of reports) {
const isResume = report.content_type === "typst";
artifacts.push({
key: `report-${report.id}`,
kind: isResume ? "resume" : "report",
entityId: report.id,
title: report.title,
status: report.report_metadata?.status === "failed" ? "error" : "ready",
createdAt: report.created_at,
contentType: isResume ? "typst" : "markdown",
sourceThreadId: report.thread_id,
});
}
for (const podcast of podcasts) {
artifacts.push({
key: `podcast-${podcast.id}`,
kind: "podcast",
entityId: podcast.id,
title: podcast.title,
status: podcastStatus(podcast.status),
createdAt: podcast.created_at,
contentType: "markdown",
sourceThreadId: podcast.thread_id,
});
}
for (const video of videos) {
artifacts.push({
key: `video-${video.id}`,
kind: "video",
entityId: video.id,
title: video.title,
status: videoStatus(video.status),
createdAt: video.created_at,
contentType: "markdown",
sourceThreadId: video.thread_id,
});
}
for (const image of images) {
artifacts.push({
key: `image-${image.id}`,
kind: "image",
entityId: image.id,
title: image.prompt,
status: image.is_success ? "ready" : "error",
createdAt: image.created_at,
contentType: "markdown",
});
}
return artifacts.sort(
(a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()
);
}
export function useLibraryArtifacts(workspaceId: number) {
const { data, isLoading, error, refetch } = useQuery({
queryKey: ["artifacts-library", workspaceId],
queryFn: () => fetchLibraryArtifacts(workspaceId),
enabled: Number.isFinite(workspaceId) && workspaceId > 0,
staleTime: 60 * 1000,
});
return { artifacts: data ?? [], loading: isLoading, error, refresh: refetch };
}