import crypto from "node:crypto"; import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import { safeParseJsonWithSchema } from "openclaw/plugin-sdk/extension-shared"; import { z } from "zod"; import { getNostrRuntime } from "./runtime.js";
type _NostrBusStateV1 = {
version: 1; /** Unix timestamp (seconds) of the last processed event */
lastProcessedAt: number | null; /** Gateway startup timestamp (seconds) - events before this are old */
gatewayStartedAt: number | null;
};
type NostrBusState = {
version: 2; /** Unix timestamp (seconds) of the last processed event */
lastProcessedAt: number | null; /** Gateway startup timestamp (seconds) - events before this are old */
gatewayStartedAt: number | null; /** Recent processed event IDs for overlap dedupe across restarts */
recentEventIds: string[];
};
/** Profile publish state (separate from bus state) */
export type NostrProfileState = {
version: 1; /** Unix timestamp (seconds) of last successful profile publish */
lastPublishedAt: number | null; /** Event ID of the last published profile */
lastPublishedEventId: string | null; /** Per-relay publish results from last attempt */
lastPublishResults: Record<string, "ok" | "failed" | "timeout"> | null;
};
/** *Determinethe`since`timestampforsubscription. *Returnsthelaterof:lastProcessedAtorgatewayStartedAt(bothfromdisk), *fallingbackto`now`forfreshstarts.
*/
export function computeSinceTimestamp(
state: NostrBusState | null,
nowSec: number = Math.floor(Date.now() / 1000),
): number { if (!state) { return nowSec;
}
// Use the most recent timestamp we have const candidates = [state.lastProcessedAt, state.gatewayStartedAt].filter(
(t): t is number => t !== null && t > 0,
);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.