if(!["role","text","reply","broadcast"].includes(v.addressingMode))thrownewError("addressingMode is invalid.");
if(!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/.test(v.observedAt)||Number.isNaN(Date.parse(v.observedAt)))thrownewError("observedAt must be RFC3339.");
if(!/^[a-f0-9]{64}$/.test(v.payloadHash))thrownewError("payloadHash must be sha256 hex.");
returnv;
}
exportfunctionparseBinding(value){constv=record(value,"target binding");exact(v.schemaVersion,feedbackBindingSchema,"binding schema");for(constkof["bindingId","guildId","channelId","targetPersonaId","targetRepoName","targetRuntimeId","producerId","producerRuntimeId","sourceVisibility","dataClassification","deliveryStorePath"])text(v[k],k);constexpected={public:"public_feedback",organization:"organization_feedback",private:"private_feedback"}[v.sourceVisibility];if(!expected||v.dataClassification!==expected)thrownewError("sourceVisibility and dataClassification must be the exact admitted pair.");returnv;}
exportfunctionparseActorLink(value){constv=record(value,"actor link");exact(v.schemaVersion,actorLinkSchema,"actor link schema");for(constkof["linkId","guildId","discordAuthorId","bifrostActorId","heimdallActorRef"])text(v[k],k);returnv;}
exportfunctionparseDelivery(value){constv=record(value,"delivery");exact(v.schemaVersion,feedbackDeliverySchema,"delivery schema");for(constkof["admissionId","packetSha256","sourceObserverId","sourceObserverRuntimeId","provider","bifrostAdmissionReceiptId","authority","providerIdentityId"])text(v[k],k);exact(v.sourceObserverId,"bifrost-discord","sourceObserverId");exact(v.provider,"bifrost","provider");exact(v.authority,"feedback_only","authority");if(!(v.providerSignatureinstanceofUint8Array)||v.providerSignature.length!==64)thrownewError("providerSignature must be 64 bytes.");constp=record(v.packet,"packet");for(constkof["feedbackId","sourceEventId","sourceActorId","actorClassification","discordGuildId","discordChannelId","discordMessageId","targetRuntimeId","targetRepository","targetPersonaId","sourceRoomId","feedbackText","contentSha256","sourceVisibility","dataClassification"])text(p[k],k);if(!Array.isArray(p.sourceDiscussionRefs)||p.sourceDiscussionRefs.length===0)thrownewError("sourceDiscussionRefs are required.");if(p.privateStateIncluded!==false)thrownewError("privateStateIncluded describes embedded private machine state and must be false.");returnv;}
exportfunctionparsePendingFailure(value){constv=record(value,"pending failure");exact(v.schemaVersion,feedbackPendingFailureSchema,"pending failure schema");for(constkof["failureId","eventId","lastError","lastAttemptAt"])text(v[k],k);if(v.failureId!==v.eventId)thrownewError("failureId must equal eventId.");if(!Number.isSafeInteger(v.attemptCount)||v.attemptCount<1||v.attemptCount>1_000_000)thrownewError("attemptCount is invalid.");if(Buffer.byteLength(v.lastError,"utf8")>512)thrownewError("lastError exceeds 512 UTF-8 bytes.");if(!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/.test(v.lastAttemptAt)||Number.isNaN(Date.parse(v.lastAttemptAt)))thrownewError("lastAttemptAt must be RFC3339.");if(v.privateStateExposed!==false)thrownewError("privateStateExposed must be false.");returnv;}