import { computed, handler, NAME, pattern, Stream, type TrustedActionWriteWithIntegrity, UI, type VNode, Writable, } from "commonfabric"; export const TRUSTED_FACT_CHECK_GATE_SURFACE = "TrustedFactCheckGateSurface"; export const TRUSTED_FACT_CHECK_DISCLAIMER_EVIDENCE = "TrustedFactCheckDisclaimerEvidence"; const FACT_CHECK_GATE_ACTION = "TrustedApproveFactCheckGate"; export const commitTrustedFactCheckGate = handler< void, { factCheckClaim: Writable; factCheckResult: Writable; } >((_, { factCheckClaim, factCheckResult }) => { const claim = factCheckClaim.get().trim(); factCheckResult.set( claim ? `Fact-check gate opened for: ${claim}` : "", ); }); export interface TrustedFactCheckGateSurfaceInput { factCheckClaim: Writable; factCheckResult: Writable; } export interface TrustedFactCheckGateSurfaceOutput { [NAME]: string; [UI]: VNode; factCheckResult: TrustedActionWriteWithIntegrity< string, typeof commitTrustedFactCheckGate, typeof FACT_CHECK_GATE_ACTION, typeof TRUSTED_FACT_CHECK_GATE_SURFACE, [ typeof TRUSTED_FACT_CHECK_GATE_SURFACE, typeof TRUSTED_FACT_CHECK_DISCLAIMER_EVIDENCE, ] >; releaseFactCheckGate: Stream; } export const TrustedFactCheckGateSurface = pattern< TrustedFactCheckGateSurfaceInput, TrustedFactCheckGateSurfaceOutput >(({ factCheckClaim, factCheckResult }) => { const releaseFactCheckGate = commitTrustedFactCheckGate({ factCheckClaim, factCheckResult, }); return { [NAME]: computed(() => "Trusted Fact Check Gate Surface"), [UI]: ( Trusted fact-check gate Fact-check the claim before allowing it to leave the trusted boundary. {TRUSTED_FACT_CHECK_DISCLAIMER_EVIDENCE} {factCheckClaim} Release after fact-check Fact-check result
{factCheckResult}
), factCheckResult, releaseFactCheckGate, }; });