chore(ai): event schema validation tool + fixes

- Created `scripts/agent/validate-events.mjs` to validate event builders against schemas.
- Refactored `buildVideoPostEvent` in `js/nostrEventSchemas.js` to automatically generate the required `s` (storage pointer) tag if missing, using `infoHash`, `url`, or `videoRootId`.
- Verified that `js/utils/storagePointer.js` exists and is imported correctly.
- Updated `docs/nostr-event-schemas.md` to reflect the auto-generation behavior.
- Verified fixes with `scripts/agent/validate-events.mjs` and existing unit tests.

Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-01-27 05:47:05 +00:00
1 parent 0d70cbbcfc
commit f5233a93f3
3 files changed
+44 -1

No files matched your search

+36
View File
@@ -9,6 +9,10 @@ import {
WATCH_HISTORY_LIST_IDENTIFIER,
WATCH_HISTORY_VERSION_TAG_VALUE,
} from "./config.js";
import {
buildStoragePointerValue,
deriveStoragePointerFromUrl,
} from "./utils/storagePointer.js";
export const NOTE_TYPES = Object.freeze({
VIDEO_POST: "videoPost",
@@ -889,6 +893,38 @@ export function buildVideoPostEvent(params) {
tags.push(...sanitizedAdditionalTags.map((tag) => tag.slice()));
}
const hasSTag = tags.some((t) => t[0] === "s");
if (!hasSTag) {
let contentObj = content;
if (typeof content === "string") {
try {
contentObj = JSON.parse(content);
} catch (e) {
contentObj = {};
}
}
contentObj = contentObj || {};
let pointer = "";
if (contentObj.infoHash) {
pointer = buildStoragePointerValue({
provider: "btih",
prefix: contentObj.infoHash,
});
} else if (contentObj.url) {
pointer = deriveStoragePointerFromUrl(contentObj.url);
}
if (!pointer && (dTagValue || contentObj.videoRootId)) {
const prefix = dTagValue || contentObj.videoRootId;
pointer = buildStoragePointerValue({ provider: "nostr", prefix });
}
if (pointer) {
tags.push(["s", pointer]);
}
}
let serializedContent = "";
if (typeof content === "string") {
serializedContent = content;