import type { BlockReadProps, BlockSpec } from "@agent-native/core/blocks"; import { useT } from "@agent-native/core/client/i18n"; import { sourceComponentBlockConfig, type SourceComponentData, } from "@shared/source-component-block"; import { IconAlertTriangle, IconBox, IconDatabase, IconExternalLink, IconPhoto, IconLink, IconTable, } from "@tabler/icons-react"; function providerLabel(provider: string) { if (provider === "builder") return "Builder"; return provider.trim() || "Source"; } function sourceEditStateLabel( state: SourceComponentData["sourceEditState"] | undefined, t: ReturnType, ) { if (state === "needs-review") { return t("editor.sourceComponent.needsAttention"); } if (state === "safe-to-edit") { return t("editor.sourceComponent.previewAvailable"); } return t("editor.properties.readOnly"); } function safeHttpUrl(value: string | undefined) { if (!value) return null; try { const url = new URL(value); if (url.protocol !== "https:" && url.protocol !== "http:") return null; return url; } catch { return null; } } function youtubeEmbedUrl(value: string | undefined) { const url = safeHttpUrl(value); if (!url) return null; if (url.hostname === "youtu.be") { const id = url.pathname.replace(/^\/+/, "").split("/")[0]; return id ? `https://www.youtube.com/embed/${id}` : null; } if ( url.hostname === "youtube.com" || url.hostname === "www.youtube.com" || url.hostname === "m.youtube.com" ) { const id = url.searchParams.get("v"); if (id) return `https://www.youtube.com/embed/${id}`; if (url.pathname.startsWith("/embed/")) return url.toString(); } return null; } function SourceImagePreview({ url, alt }: { url: string; alt?: string }) { return (
{alt {alt ? (
{alt}
) : null}
); } function SourceEmbedPreview({ url }: { url: string }) { const embedUrl = youtubeEmbedUrl(url); if (embedUrl) { return (