@estiva-app/conversation 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,271 @@
1
+ import { FILE_ADDRESS as ADDRESS, FOLDER_ID, KIND_APP_DATA, KIND_CHANGE, KIND_COMMENT, KIND_MESSAGE } from './kinds.js';
2
+ import { byOrder } from './order.js';
3
+ import { anchorsOf, isCommentOn, peopleNamedInBody } from './strength.js';
4
+ import { groupThreads } from './threads.js';
5
+ export { KIND_CHANGE };
6
+ /** The field prefix of a membership change: `member:<pubkey>`. */
7
+ export const MEMBER_FIELD_PREFIX = 'member:';
8
+ const PUBKEY = /^[0-9a-f]{64}$/;
9
+ const tag = (event, name) => event.tags.find((t) => t[0] === name)?.[1];
10
+ /** The membership field for a person: `member:<pubkey>`. */
11
+ export function memberField(pubkey) {
12
+ if (!PUBKEY.test(pubkey))
13
+ throw new Error(`not a lowercase hex pubkey: ${JSON.stringify(pubkey)}`);
14
+ return `${MEMBER_FIELD_PREFIX}${pubkey}`;
15
+ }
16
+ /** The person a `member:<pubkey>` field names, or undefined when it is not one. */
17
+ export function memberOfField(field) {
18
+ if (!field?.startsWith(MEMBER_FIELD_PREFIX))
19
+ return undefined;
20
+ const pubkey = field.slice(MEMBER_FIELD_PREFIX.length);
21
+ return PUBKEY.test(pubkey) ? pubkey : undefined;
22
+ }
23
+ /**
24
+ * Does the message's content mention the person — a `nostr:npub…` in its body.
25
+ * A `p` tag alone is not a mention for membership: the comment builders tag
26
+ * the file's author and the parent's on every comment (§6.4), so a `p` would
27
+ * re-join an author who left.
28
+ */
29
+ export function mentions(event, pubkey) {
30
+ return peopleNamedInBody(event.content).has(pubkey);
31
+ }
32
+ /** The address of an addressable event, `<kind>:<pubkey>:<d>`. */
33
+ function addressOf(event) {
34
+ if (event.kind < 30000 || event.kind > 39999)
35
+ return undefined;
36
+ return `${event.kind}:${event.pubkey}:${tag(event, 'd') ?? ''}`;
37
+ }
38
+ /**
39
+ * The messages in a file's stream (§11.1): every root that is a comment on it,
40
+ * and every reply in those threads. A `kind:1111` reply whose root the read
41
+ * does not hold still counts when its `A` is the file — a reply copies its
42
+ * thread's object. A `kind:9` never roots a file's stream (§6.4, CON-20).
43
+ */
44
+ export function streamOf(file, events) {
45
+ const conversation = events.filter((e) => e.kind === KIND_COMMENT || e.kind === KIND_MESSAGE);
46
+ const { roots, replies, missingRoots } = groupThreads(conversation);
47
+ const missing = new Set(missingRoots);
48
+ const out = [];
49
+ for (const root of roots) {
50
+ if (!isCommentOn(root, file))
51
+ continue;
52
+ out.push(root, ...(replies[root.id] ?? []));
53
+ }
54
+ for (const id of missing) {
55
+ for (const reply of replies[id] ?? [])
56
+ if (reply.kind === KIND_COMMENT && anchorsOf(reply).includes(file))
57
+ out.push(reply);
58
+ }
59
+ return out.sort(byOrder);
60
+ }
61
+ const NOT_A_MEMBER = { member: false };
62
+ /**
63
+ * Every join and leave in a file's events, per person. `events` may hold
64
+ * anything; only the file's root versions, its stream and its `kind:1851`
65
+ * changes are read.
66
+ */
67
+ function stepsOf(file, events) {
68
+ const steps = new Map();
69
+ const add = (person, event, join, creation = false) => {
70
+ if (!PUBKEY.test(person))
71
+ return;
72
+ const list = steps.get(person) ?? [];
73
+ list.push({ event, join, creation });
74
+ steps.set(person, list);
75
+ };
76
+ // A relay keeps only the latest version of an addressable event, so the root
77
+ // the reader holds is usually the last edit. Its join is ordered first, so
78
+ // an edit after a leave does not make the author a member again.
79
+ const versions = events.filter((e) => addressOf(e) === file).sort(byOrder);
80
+ if (versions[0])
81
+ add(versions[0].pubkey, versions[0], true, true);
82
+ for (const message of streamOf(file, events)) {
83
+ add(message.pubkey, message, true);
84
+ for (const person of peopleNamedInBody(message.content))
85
+ add(person, message, true);
86
+ }
87
+ for (const change of events) {
88
+ if (change.kind !== KIND_CHANGE || !change.tags.some((t) => t[0] === 'a' && t[1] === file))
89
+ continue;
90
+ const field = tag(change, 'field');
91
+ const value = tag(change, 'value');
92
+ const member = memberOfField(field);
93
+ if (member !== undefined) {
94
+ if (value === 'true')
95
+ add(member, change, true);
96
+ else if (value === 'false' && change.pubkey === member)
97
+ add(member, change, false);
98
+ continue;
99
+ }
100
+ // A change with an empty value takes someone off (an unassign) and places nobody, whatever `p` it carries.
101
+ if (field?.startsWith(MEMBER_FIELD_PREFIX) || !value)
102
+ continue;
103
+ for (const t of change.tags)
104
+ if (t[0] === 'p' && typeof t[1] === 'string')
105
+ add(t[1], change, true);
106
+ }
107
+ return steps;
108
+ }
109
+ function fold(steps) {
110
+ if (!steps || steps.length === 0)
111
+ return NOT_A_MEMBER;
112
+ const ordered = [...steps].sort((a, b) => Number(b.creation ?? false) - Number(a.creation ?? false) || byOrder(a.event, b.event) || Number(a.join) - Number(b.join));
113
+ if (!ordered[ordered.length - 1].join)
114
+ return NOT_A_MEMBER;
115
+ // Since: the earliest second among the joins after the last leave — the creation's
116
+ // held version can be a later edit than the author's first comment.
117
+ let since;
118
+ for (const step of ordered) {
119
+ if (!step.join)
120
+ since = undefined;
121
+ else
122
+ since = since === undefined ? step.event.created_at : Math.min(since, step.event.created_at);
123
+ }
124
+ return { member: true, since };
125
+ }
126
+ /**
127
+ * One person's membership of one file (§11.8 *The fold*), from the file's own
128
+ * events: its root, its stream and its changes.
129
+ */
130
+ export function membershipOf(file, person, events) {
131
+ return fold(stepsOf(file, events).get(person));
132
+ }
133
+ /** Every member of a file and since when, from the file's own events. People who left are absent. */
134
+ export function membersOf(file, events) {
135
+ const members = new Map();
136
+ for (const [person, steps] of stepsOf(file, events)) {
137
+ const membership = fold(steps);
138
+ if (membership.member)
139
+ members.set(person, membership);
140
+ }
141
+ return members;
142
+ }
143
+ /**
144
+ * The filters that find every file a person may be a member of (§11.8): the
145
+ * changes that name them, what they wrote, and what mentions them. Each
146
+ * candidate file is then read and folded with {@link membershipOf}. The files
147
+ * they created are the app's own query; `since` bounds all three.
148
+ */
149
+ export function membershipFilters(person, since) {
150
+ if (!PUBKEY.test(person))
151
+ throw new Error(`not a lowercase hex pubkey: ${JSON.stringify(person)}`);
152
+ const bound = since === undefined ? {} : { since };
153
+ return [
154
+ { kinds: [KIND_CHANGE], '#p': [person], ...bound },
155
+ { kinds: [KIND_COMMENT, KIND_MESSAGE], authors: [person], ...bound },
156
+ { kinds: [KIND_COMMENT, KIND_MESSAGE], '#p': [person], ...bound },
157
+ ];
158
+ }
159
+ /**
160
+ * The files an event can make a person a member of: a change's `a`, a
161
+ * comment's `A` (or every `a` when it has none). A `kind:9` names none — its
162
+ * file, if any, is its root's, which the app resolves by reading the thread.
163
+ */
164
+ export function candidateFilesOf(event) {
165
+ if (event.kind === KIND_CHANGE)
166
+ return event.tags.filter((t) => t[0] === 'a' && ADDRESS.test(t[1] ?? '')).map((t) => t[1]);
167
+ return anchorsOf(event).filter((a) => ADDRESS.test(a));
168
+ }
169
+ /**
170
+ * A membership change (§11.8 *The membership change*): `true` adds a person,
171
+ * by anyone; `false` is a leave and counts only when the person signs it
172
+ * themselves. Tag order: `a`, `field`, `value`, `h`, `ts`, `p`.
173
+ *
174
+ * Sign one only when the person chose it — joining, leaving, or adding
175
+ * somebody. Never to migrate a private follow (§11.8 *Following, retired*).
176
+ *
177
+ * `content` is the note an activity feed shows, as for every change: a change
178
+ * with none renders as a blank line in Ship's feed. "Join", "Leave" or "Add"
179
+ * by default.
180
+ */
181
+ export function buildMembershipChange(pubkey, createdAtMs, args) {
182
+ const note = args.note ?? (!args.member ? 'Leave' : args.person === pubkey ? 'Join' : 'Add');
183
+ if (!ADDRESS.test(args.file))
184
+ throw new Error(`not a file address: ${JSON.stringify(args.file)}`);
185
+ if (!FOLDER_ID.test(args.folder))
186
+ throw new Error(`not a Folder id (lowercase UUID v4): ${JSON.stringify(args.folder)}`);
187
+ if (!Number.isSafeInteger(createdAtMs) || createdAtMs < 0)
188
+ throw new Error(`not epoch milliseconds: ${createdAtMs}`);
189
+ return {
190
+ pubkey,
191
+ created_at: Math.floor(createdAtMs / 1000),
192
+ kind: KIND_CHANGE,
193
+ tags: [
194
+ ['a', args.file],
195
+ ['field', memberField(args.person)],
196
+ ['value', args.member ? 'true' : 'false'],
197
+ ['h', args.folder],
198
+ ['ts', String(createdAtMs)],
199
+ ['p', args.person],
200
+ ],
201
+ content: note,
202
+ };
203
+ }
204
+ // ── Muting: private, suite-wide (§11.8 *Muting is private*, §12) ────────────
205
+ /** The `d` of the person's mute list. */
206
+ export const MUTED_D_TAG = 'estiva:muted:v1';
207
+ /** The `t` every §12 app-private blob carries. */
208
+ export const APPDATA_TAG = 'estiva-appdata';
209
+ const isMuteKey = (key) => typeof key === 'string' && (ADDRESS.test(key) || FOLDER_ID.test(key));
210
+ /** The mute list from its decrypted content, or undefined when it is not a v1 list. Unknown keys are dropped. */
211
+ export function parseMutedBlob(plaintext) {
212
+ let value;
213
+ try {
214
+ value = JSON.parse(plaintext);
215
+ }
216
+ catch {
217
+ return undefined;
218
+ }
219
+ if (!value || typeof value !== 'object')
220
+ return undefined;
221
+ const { v, updatedAt, keys } = value;
222
+ if (v !== 1 || typeof updatedAt !== 'number' || !Number.isFinite(updatedAt) || !Array.isArray(keys))
223
+ return undefined;
224
+ return { v: 1, updatedAt, keys: [...new Set(keys.filter(isMuteKey))].sort() };
225
+ }
226
+ /** The plaintext to encrypt to self: keys de-duplicated and sorted, so equal lists are equal bytes. */
227
+ export function serializeMutedBlob(keys, updatedAt) {
228
+ return JSON.stringify({ v: 1, updatedAt, keys: [...new Set([...keys].filter(isMuteKey))].sort() });
229
+ }
230
+ /**
231
+ * The unsigned `kind:30078` holding the encrypted mute list. Whole blob, last
232
+ * write wins (§12.3): a writer reads the current list, changes it, and writes
233
+ * all of it.
234
+ */
235
+ export function buildMutedEvent(pubkey, createdAtMs, ciphertext) {
236
+ return {
237
+ pubkey,
238
+ created_at: Math.floor(createdAtMs / 1000),
239
+ kind: KIND_APP_DATA,
240
+ tags: [
241
+ ['d', MUTED_D_TAG],
242
+ ['t', APPDATA_TAG],
243
+ ],
244
+ content: ciphertext,
245
+ };
246
+ }
247
+ /** The filter for the person's mute list. */
248
+ export function mutedFilter(pubkey) {
249
+ return { kinds: [KIND_APP_DATA], authors: [pubkey], '#d': [MUTED_D_TAG], limit: 1 };
250
+ }
251
+ /**
252
+ * The one migration from a retired `estiva:followed:v1` blob: its `muted`
253
+ * keys, to merge into the mute list. Peek wrote `muted` as a map of key to
254
+ * epoch ms, and for one day as a plain list; both read. Its followed `keys`
255
+ * are **not** returned — the list was private, so nothing may publish them as
256
+ * memberships — and a followed Folder is dropped, since the roster decides a
257
+ * general stream.
258
+ */
259
+ export function mutedFromFollowed(followedPlaintext) {
260
+ let value;
261
+ try {
262
+ value = JSON.parse(followedPlaintext);
263
+ }
264
+ catch {
265
+ return [];
266
+ }
267
+ const muted = value && typeof value === 'object' ? value.muted : undefined;
268
+ const keys = Array.isArray(muted) ? muted : muted && typeof muted === 'object' ? Object.keys(muted) : [];
269
+ return [...new Set(keys.filter(isMuteKey))].sort();
270
+ }
271
+ //# sourceMappingURL=membership.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"membership.js","sourceRoot":"","sources":["../src/membership.ts"],"names":[],"mappings":"AA8BA,OAAO,EAAE,YAAY,IAAI,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACvH,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,OAAO,EAAE,WAAW,EAAE,CAAA;AAEtB,kEAAkE;AAClE,MAAM,CAAC,MAAM,mBAAmB,GAAG,SAAS,CAAA;AAE5C,MAAM,MAAM,GAAG,gBAAgB,CAAA;AAO/B,MAAM,GAAG,GAAG,CAAC,KAAgC,EAAE,IAAY,EAAsB,EAAE,CAAC,KA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K,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IACxG,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;AACpD,CAAC"}
@@ -0,0 +1,214 @@
1
+ /**
2
+ * Read state — SPEC §11, NIP-RS: per person, not per app.
3
+ *
4
+ * `kind:30078` blobs, NIP-44 encrypted to self, **one per installation**,
5
+ * merged by taking the maximum timestamp per context. Reading a file in Ship
6
+ * marks it read in Peek because both name it the same way (§11.1) and both
7
+ * merge every slot.
8
+ *
9
+ * Ported from Peek's `readState.ts` and `readStateMerge.ts` and Ship's
10
+ * `readState.ts`, which had diverged. Where they differed the SPEC decided:
11
+ *
12
+ * - **The cap is in bytes, not a count** (§11.6). `/nip44/encrypt` refuses a
13
+ * plaintext over 65,535 bytes, and on production a slot is refused at
14
+ * ~771 contexts, so Ship's 10,000-context cap could never fire. Eviction is
15
+ * deterministic to the tie, so a merge does not hand an evicted context back.
16
+ * - **A slot whose coordinate carries another `client_id` is reported**, so
17
+ * the app can rotate rather than overwrite another installation on every
18
+ * write (Peek had it; Ship did not).
19
+ * - **An unreachable relay is not "no slots"**, and our own slot existing but
20
+ * not decrypting is not "first run" (Ship had both apart; kept).
21
+ *
22
+ * Nothing here opens a socket or touches the browser: the relay read, the
23
+ * signer, NIP-44 and storage are parameters.
24
+ */
25
+ import type { SignedEvent, UnsignedEvent } from '@estiva-app/protocol';
26
+ import type { QueryFn } from './decorations.js';
27
+ /** NIP-RS's own `t` tag. */
28
+ export declare const READ_STATE_TAG = "read-state";
29
+ /** The `d`-tag prefix the relay's NIP-RS predicate keys on (§11.6). */
30
+ export declare const READ_STATE_D_PREFIX = "read-state:";
31
+ /**
32
+ * Limits from NIP-RS and the reference implementation (§11.6).
33
+ * `MAX_CONTEXTS` binds only the merged view across slots: one blob meets
34
+ * {@link MAX_CONTEXTS_BYTES} far sooner.
35
+ */
36
+ export declare const MAX_CONTEXTS = 10000;
37
+ export declare const MAX_CONTEXT_ID_BYTES = 256;
38
+ export declare const MAX_TIMESTAMP = 4294967295;
39
+ export declare const MAX_CLIENT_ID_BYTES = 64;
40
+ /** The plaintext ceiling `/nip44/encrypt` enforces (SPEC §12.5), in bytes of UTF-8. */
41
+ export declare const MAX_BLOB_BYTES = 65535;
42
+ /**
43
+ * The bytes the `contexts` map may occupy: the ceiling less the envelope, sized
44
+ * at the **longest legal `client_id`**, so every installation holding the same
45
+ * contexts evicts the same ones.
46
+ */
47
+ export declare const MAX_CONTEXTS_BYTES: number;
48
+ /** A horizon of 90 days: what both apps used. NIP-RS fixes none (§11.6). */
49
+ export declare const READ_STATE_HORIZON_DAYS = 90;
50
+ /** A channel's context: the **bare** channel uuid. Undefined for anything else, never coerced. */
51
+ export declare function channelContext(channelUuid: string | null | undefined): string | undefined;
52
+ /** A file's context: its **bare** address, `d` verbatim (FOL-16). */
53
+ export declare function fileContext(address: string | null | undefined): string | undefined;
54
+ /** `thread:<root-event-id>`, NIP-RS's own scheme. */
55
+ export declare function threadContext(rootEventId: string | null | undefined): string | undefined;
56
+ /** `msg:<event-id>`, NIP-RS's own scheme. */
57
+ export declare function messageContext(eventId: string | null | undefined): string | undefined;
58
+ /** Epoch ms → the unix **seconds** NIP-RS stores, clamped to its range. */
59
+ export declare function toContextSeconds(atMs: number): number;
60
+ /**
61
+ * Is this a context id worth putting in a grow-only blob: a channel uuid, a
62
+ * file address, or `thread:`/`msg:` with 64 lowercase hex. The reserved
63
+ * `folder:` is refused until §11.5 specifies it.
64
+ */
65
+ export declare function isPublishableContextId(id: string): boolean;
66
+ /** This installation's slot. */
67
+ export interface SlotIdentity {
68
+ /** 32 lowercase hex; the `d` tag is `read-state:<slotId>`. */
69
+ slotId: string;
70
+ /** A stable name for this installation, 1–64 characters. */
71
+ clientId: string;
72
+ }
73
+ /** The storage a slot lives in — `localStorage` in a browser. It may throw. */
74
+ export interface SlotStorage {
75
+ getItem(key: string): string | null;
76
+ setItem(key: string, value: string): void;
77
+ }
78
+ /** `n` cryptographically random bytes — `(n) => crypto.getRandomValues(new Uint8Array(n))`. */
79
+ export type RandomBytes = (n: number) => Uint8Array;
80
+ /** Where a slot lives and how a new one is minted. */
81
+ export interface SlotSource {
82
+ storage: SlotStorage | undefined;
83
+ /** The app's own key (`estiva-peek:read-state-slot`, `ship.readstate.slot`), so it keeps the slot it has. */
84
+ storageKey: string;
85
+ /** Names the app in a new `client_id`: `peek` → `peek-1a2b3c4d`. */
86
+ clientPrefix: string;
87
+ random: RandomBytes;
88
+ }
89
+ /**
90
+ * This installation's slot, minted once and reused.
91
+ *
92
+ * Storage must survive a restart — a slot minted per session piles up past the
93
+ * reference client's eight. A storage that throws degrades to an ephemeral
94
+ * slot rather than failing the app.
95
+ */
96
+ export declare function loadSlotIdentity(source: SlotSource): SlotIdentity;
97
+ /**
98
+ * A new slot id with the same `client_id`, persisted. For one case: our
99
+ * coordinate carries another installation's `client_id`, and writing to it
100
+ * would overwrite theirs on every write.
101
+ */
102
+ export declare function rotateSlotId(identity: SlotIdentity, source: Omit<SlotSource, 'clientPrefix'>): SlotIdentity;
103
+ /** `read-state:<slot-id>`. */
104
+ export declare function readStateDTag(slotId: string): string;
105
+ /** A decrypted NIP-RS blob. */
106
+ export interface ReadStateBlob {
107
+ v: 1;
108
+ client_id: string;
109
+ /** Context id → unix seconds. */
110
+ contexts: Record<string, number>;
111
+ }
112
+ /**
113
+ * Parse a decrypted blob, dropping entries it cannot trust and keeping the
114
+ * rest. Undefined only when it is not a v1 blob at all — which the caller must
115
+ * keep apart from an empty one, so as not to republish over it.
116
+ */
117
+ export declare function parseReadStateBlob(plaintext: string | undefined): ReadStateBlob | undefined;
118
+ /** Serialize for encryption, keys sorted, so an unchanged set is an unchanged string. */
119
+ export declare function serializeReadStateBlob(blob: ReadStateBlob): string;
120
+ /** A context map trimmed to the byte ceiling, and what that cost. */
121
+ export interface CappedContexts {
122
+ contexts: Record<string, number>;
123
+ /** `JSON.stringify(contexts)` in bytes of UTF-8, braces included. */
124
+ bytes: number;
125
+ /** What was dropped, newest first. Empty is the normal case. */
126
+ evicted: string[];
127
+ }
128
+ /**
129
+ * Trim a context map to the byte budget, newest marker first, ties by key.
130
+ * Dropping the oldest marker costs one conversation looking unread; a blob
131
+ * over the ceiling is refused whole and costs all of them. Deterministic and
132
+ * idempotent, so a merge does not undo an eviction.
133
+ */
134
+ export declare function capContextsToBytes(contexts: Readonly<Record<string, number>>, budget?: number): CappedContexts;
135
+ /**
136
+ * Apply markers, taking the later of each (§11.4: never lower one), then cap.
137
+ * Unpublishable ids and out-of-range timestamps are dropped.
138
+ */
139
+ export declare function advanceContexts(current: Readonly<Record<string, number>>, updates: Readonly<Record<string, number>>): CappedContexts;
140
+ /**
141
+ * The unsigned `kind:30078` for one slot: exactly one `d`, exactly one
142
+ * `["t","read-state"]` (§11.6 — an event that misses the shape is stored as an
143
+ * ordinary one and merged by nobody), and no `h`.
144
+ */
145
+ export declare function buildReadStateEvent(pubkey: string, nowMs: number, slotId: string, ciphertext: string): UnsignedEvent;
146
+ /**
147
+ * Every slot **this person** owns within the horizon. One pubkey and no list
148
+ * variant: NIP-RS is not a read-receipt protocol.
149
+ */
150
+ export declare function allSlotsFilter(pubkey: string, nowMs: number, horizonDays?: number): Record<string, unknown>;
151
+ /** One slot as read from the relay. */
152
+ export interface SlotBlob {
153
+ dTag: string;
154
+ eventId: string;
155
+ createdAt: number;
156
+ blob: ReadStateBlob;
157
+ }
158
+ /** Every slot merged by the max rule, capped at {@link MAX_CONTEXTS} newest first, ties by key. */
159
+ export declare function mergeSlots(slots: readonly Pick<SlotBlob, 'blob'>[]): Record<string, number>;
160
+ /** Which slots are this installation's. */
161
+ export interface OwnSlotVerdict {
162
+ /** Our newest slot by `client_id`. */
163
+ mine: SlotBlob | undefined;
164
+ /** Older slots under our `client_id` — left by a rotation. */
165
+ staleDuplicates: SlotBlob[];
166
+ /** Our coordinate holds another installation's `client_id`: rotate before writing. */
167
+ coordinateConflicted: boolean;
168
+ }
169
+ export declare function classifyOwnSlots(slots: readonly SlotBlob[], identity: SlotIdentity): OwnSlotVerdict;
170
+ /**
171
+ * The effective marker (§11.3): the later of a context's own and its stream's.
172
+ * For a reply, `context` is `thread:<root>` and `stream` the file address or
173
+ * channel uuid. The channel never reaches into a file's stream — pass the
174
+ * file's address, not the channel, for a file's thread.
175
+ */
176
+ export declare function effectiveReadAt(merged: Readonly<Record<string, number>>, context: string, stream?: string): number | undefined;
177
+ /** NIP-44 to self. Estiva apps hold no key, so this is a round trip to the identity service. */
178
+ export interface Nip44 {
179
+ encrypt(plaintext: string): Promise<string>;
180
+ /** Undefined, or a throw, when it will not decrypt. */
181
+ decrypt(ciphertext: string): Promise<string | undefined>;
182
+ }
183
+ /** Read state as far as the relay can tell. */
184
+ export interface FetchedReadState {
185
+ /** False when the relay could not be asked — not the same as "no slots". */
186
+ reachable: boolean;
187
+ merged: Record<string, number>;
188
+ slots: SlotBlob[];
189
+ /** This installation's own blob, when the relay holds one at our coordinate and it decrypted. */
190
+ own?: ReadStateBlob;
191
+ /**
192
+ * Our coordinate exists and would not decrypt — typically a `429` from
193
+ * `/nip44/decrypt`. Publishing now would replace it with only this session's
194
+ * markers, so an app must not.
195
+ */
196
+ ownUndecryptable: boolean;
197
+ /** Our coordinate holds another installation's blob: {@link rotateSlotId} before writing. */
198
+ coordinateConflicted: boolean;
199
+ }
200
+ /** Fetch every slot within the horizon, decrypt what decrypts, merge. */
201
+ export declare function fetchReadState(query: QueryFn, pubkey: string, nip44: Pick<Nip44, 'decrypt'>, identity: SlotIdentity, nowMs: number, horizonDays?: number): Promise<FetchedReadState>;
202
+ /** Encrypt, sign and publish this slot's whole blob. The caller has already capped `contexts`. */
203
+ export declare function publishReadState(deps: {
204
+ sign: (event: UnsignedEvent) => Promise<SignedEvent>;
205
+ publish: (event: SignedEvent) => Promise<{
206
+ ok: boolean;
207
+ reason?: string;
208
+ }>;
209
+ nip44: Pick<Nip44, 'encrypt'>;
210
+ }, pubkey: string, identity: SlotIdentity, contexts: Readonly<Record<string, number>>, nowMs: number): Promise<{
211
+ ok: boolean;
212
+ reason?: string;
213
+ }>;
214
+ //# sourceMappingURL=readState.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readState.d.ts","sourceRoot":"","sources":["../src/readState.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEtE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAE/C,4BAA4B;AAC5B,eAAO,MAAM,cAAc,eAAe,CAAA;AAE1C,uEAAuE;AACvE,eAAO,MAAM,mBAAmB,gBAAgB,CAAA;AAEhD;;;;GAIG;AACH,eAAO,MAAM,YAAY,QAAS,CAAA;AAClC,eAAO,MAAM,oBAAoB,MAAM,CAAA;AACvC,eAAO,MAAM,aAAa,aAAgB,CAAA;AAC1C,eAAO,MAAM,mBAAmB,KAAK,CAAA;AAErC,uFAAuF;AACvF,eAAO,MAAM,cAAc,QAAS,CAAA;AAEpC;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,QACmF,CAAA;AAElH,4EAA4E;AAC5E,eAAO,MAAM,uBAAuB,KAAK,CAAA;AAiBzC,kGAAkG;AAClG,wBAAgB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAIzF;AAED,qEAAqE;AACrE,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAGlF;AAED,qDAAqD;AACrD,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAIxF;AAED,6C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