@pmate/chat-sdk 0.12.0-next.9 → 0.12.0-next.91
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.
- package/README.md +216 -83
- package/lib/advanced.d.ts +10 -0
- package/lib/advanced.js +10 -0
- package/lib/chat.d.ts +5 -0
- package/lib/chat.js +11 -0
- package/lib/chatContract.d.ts +158 -0
- package/lib/chatContract.js +1 -0
- package/lib/chatError.d.ts +31 -0
- package/lib/chatError.js +18 -0
- package/lib/chatTypes.d.ts +128 -0
- package/lib/chatTypes.js +1 -0
- package/lib/commands.d.ts +20 -0
- package/lib/commands.js +12 -0
- package/lib/components/ChatInputDesktop.js +5 -4
- package/lib/components/ChatInputMobile.js +5 -4
- package/lib/components/CommandMenu.d.ts +15 -0
- package/lib/components/CommandMenu.js +10 -0
- package/lib/credentials.d.ts +26 -0
- package/lib/credentials.js +110 -0
- package/lib/fileMetadata.d.ts +9 -0
- package/lib/fileMetadata.js +18 -0
- package/lib/framework.d.ts +11 -0
- package/lib/framework.js +12 -0
- package/lib/history.d.ts +4 -0
- package/lib/history.js +8 -0
- package/lib/hooks/useChatSnapshot.d.ts +4 -0
- package/lib/hooks/useChatSnapshot.js +9 -0
- package/lib/hooks/useComposerSuggestions.d.ts +50 -0
- package/lib/hooks/useComposerSuggestions.js +70 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +6 -0
- package/lib/internal/chatEngine.d.ts +131 -0
- package/lib/internal/chatEngine.js +306 -0
- package/lib/internal/chatRegistry.d.ts +4 -0
- package/lib/internal/chatRegistry.js +4 -0
- package/lib/internal/createPublicChat.d.ts +4 -0
- package/lib/internal/createPublicChat.js +62 -0
- package/lib/messageView.d.ts +6 -0
- package/lib/messageView.js +103 -0
- package/lib/runtime/batchedReadIndex.d.ts +16 -3
- package/lib/runtime/batchedReadIndex.js +50 -4
- package/lib/runtime/cachedMessage.d.ts +12 -0
- package/lib/runtime/cachedMessage.js +18 -0
- package/lib/runtime/chatClient.d.ts +8 -1
- package/lib/runtime/chatClient.js +18 -6
- package/lib/runtime/chatError.d.ts +5 -0
- package/lib/runtime/chatError.js +20 -0
- package/lib/runtime/chatSession.d.ts +141 -13
- package/lib/runtime/chatSession.js +797 -48
- package/lib/runtime/connectivity.d.ts +4 -0
- package/lib/runtime/connectivity.js +8 -0
- package/lib/runtime/conversationDirectory.d.ts +37 -0
- package/lib/runtime/conversationDirectory.js +116 -0
- package/lib/runtime/conversationRead.d.ts +14 -0
- package/lib/runtime/conversationRead.js +34 -0
- package/lib/runtime/conversationReading.d.ts +30 -0
- package/lib/runtime/conversationReading.js +47 -0
- package/lib/runtime/createChat.d.ts +14 -7
- package/lib/runtime/createChat.js +67 -24
- package/lib/runtime/durableSender.d.ts +97 -14
- package/lib/runtime/durableSender.js +787 -71
- package/lib/runtime/groupClient.d.ts +92 -0
- package/lib/runtime/groupClient.js +380 -0
- package/lib/runtime/groupDenial.d.ts +2 -0
- package/lib/runtime/groupDenial.js +4 -0
- package/lib/runtime/groupIdentity.d.ts +4 -0
- package/lib/runtime/groupIdentity.js +26 -0
- package/lib/runtime/inboxClient.d.ts +65 -0
- package/lib/runtime/inboxClient.js +268 -0
- package/lib/runtime/inboxGroup.d.ts +4 -0
- package/lib/runtime/inboxGroup.js +51 -0
- package/lib/runtime/inboxStore.d.ts +194 -0
- package/lib/runtime/inboxStore.js +329 -0
- package/lib/runtime/inboxTransport.d.ts +6 -0
- package/lib/runtime/inboxTransport.js +76 -0
- package/lib/runtime/index.d.ts +10 -0
- package/lib/runtime/index.js +8 -0
- package/lib/runtime/indexedDbRecovery.d.ts +6 -0
- package/lib/runtime/indexedDbRecovery.js +42 -0
- package/lib/runtime/messageClient.d.ts +37 -8
- package/lib/runtime/messageClient.js +366 -68
- package/lib/runtime/messageControls.d.ts +19 -0
- package/lib/runtime/messageControls.js +44 -0
- package/lib/runtime/messageDiscussionStore.d.ts +63 -0
- package/lib/runtime/messageDiscussionStore.js +147 -0
- package/lib/runtime/messageLaunch.d.ts +44 -0
- package/lib/runtime/messageLaunch.js +137 -0
- package/lib/runtime/messageQuotes.d.ts +3 -0
- package/lib/runtime/messageQuotes.js +17 -0
- package/lib/runtime/messageReaders.d.ts +5 -1
- package/lib/runtime/messageReaders.js +16 -5
- package/lib/runtime/messageStore.d.ts +51 -2
- package/lib/runtime/messageStore.js +264 -14
- package/lib/runtime/messageThread.d.ts +9 -0
- package/lib/runtime/messageThread.js +17 -0
- package/lib/runtime/messageTimeline.d.ts +51 -0
- package/lib/runtime/messageTimeline.js +121 -0
- package/lib/runtime/outboxSchema.d.ts +5 -0
- package/lib/runtime/outboxSchema.js +59 -0
- package/lib/runtime/outgoingContent.d.ts +95 -0
- package/lib/runtime/outgoingContent.js +121 -0
- package/lib/runtime/readBatchJournal.d.ts +35 -0
- package/lib/runtime/readBatchJournal.js +210 -0
- package/lib/runtime/readCounts.d.ts +7 -1
- package/lib/runtime/readCounts.js +108 -21
- package/lib/runtime/readIndex.d.ts +74 -7
- package/lib/runtime/readIndex.js +488 -33
- package/lib/runtime/readSchema.d.ts +2 -0
- package/lib/runtime/readSchema.js +58 -0
- package/lib/runtime/readSync.d.ts +8 -0
- package/lib/runtime/readSync.js +125 -17
- package/lib/runtime/readingClient.d.ts +22 -0
- package/lib/runtime/readingClient.js +141 -20
- package/lib/runtime/readingContent.d.ts +5 -0
- package/lib/runtime/readingContent.js +23 -0
- package/lib/runtime/responseCache.d.ts +41 -5
- package/lib/runtime/responseCache.js +182 -44
- package/lib/runtime/socialReadClient.d.ts +30 -4
- package/lib/runtime/socialReadClient.js +34 -8
- package/lib/runtime/voiceUpload.d.ts +2 -0
- package/lib/runtime/voiceUpload.js +27 -0
- package/lib/snapshot.d.ts +36 -0
- package/lib/snapshot.js +52 -0
- package/lib/types/chatInput.d.ts +3 -0
- package/package.json +32 -2
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { Dexie } from "dexie";
|
|
2
|
+
import { messageRequiresPlayback, isReadingControl } from "./readingContent.js";
|
|
3
|
+
import { messageThreadRoot } from "./messageThread.js";
|
|
4
|
+
import { projectInboxGroup } from "./inboxGroup.js";
|
|
5
|
+
import { readingCursor, sourcesInConversation } from "./readIndex.js";
|
|
6
|
+
export function inboxSequence(value) {
|
|
7
|
+
if (typeof value !== "string" || !/^(0|[1-9]\d{0,18})$/.test(value))
|
|
8
|
+
throw new Error("INVALID_INBOX_SEQUENCE");
|
|
9
|
+
const number = BigInt(value);
|
|
10
|
+
if (number > 9223372036854775807n)
|
|
11
|
+
throw new Error("INVALID_INBOX_SEQUENCE");
|
|
12
|
+
return number;
|
|
13
|
+
}
|
|
14
|
+
/** Normalized facts and derived positions commit with their Inbox cursor. No
|
|
15
|
+
* serialized full-history snapshot is persisted after each message. */
|
|
16
|
+
export class IndexedDbInbox {
|
|
17
|
+
scope;
|
|
18
|
+
db;
|
|
19
|
+
owner;
|
|
20
|
+
cursors;
|
|
21
|
+
messages;
|
|
22
|
+
facts;
|
|
23
|
+
positions;
|
|
24
|
+
explicit;
|
|
25
|
+
threads;
|
|
26
|
+
leases;
|
|
27
|
+
constructor(scope, options = {}) {
|
|
28
|
+
this.scope = scope;
|
|
29
|
+
this.owner = JSON.stringify([scope.accountId, scope.appId, scope.profileId]);
|
|
30
|
+
this.db = new Dexie(options.name ?? "pmate-chat-inbox-v1", { indexedDB: options.indexedDB ?? globalThis.indexedDB, IDBKeyRange: globalThis.IDBKeyRange });
|
|
31
|
+
this.db.version(1).stores({ cursors: "owner", messages: "[owner+thread+id],[owner+thread+seq],[owner+thread+time+id],[owner+thread],owner", facts: "[owner+kind+id],[owner+kind],[owner+thread],owner", positions: "[owner+thread+root],[owner+thread],owner", explicit: "[owner+thread+id],[owner+thread],owner", threads: "[owner+id],owner" });
|
|
32
|
+
this.db.version(2).stores({ leases: "owner" });
|
|
33
|
+
this.db.version(3).stores({ messages: "[owner+thread+id],[owner+thread+seq],[owner+thread+time+id],[owner+thread+changeSeq+id],[owner+thread],owner" });
|
|
34
|
+
this.cursors = this.db.table("cursors");
|
|
35
|
+
this.messages = this.db.table("messages");
|
|
36
|
+
this.facts = this.db.table("facts");
|
|
37
|
+
this.positions = this.db.table("positions");
|
|
38
|
+
this.explicit = this.db.table("explicit");
|
|
39
|
+
this.threads = this.db.table("threads");
|
|
40
|
+
this.leases = this.db.table("leases");
|
|
41
|
+
}
|
|
42
|
+
tables() { return [this.cursors, this.messages, this.facts, this.positions, this.explicit, this.threads]; }
|
|
43
|
+
cursor() { return this.cursors.get(this.owner); }
|
|
44
|
+
claimLease(token, now = Date.now()) {
|
|
45
|
+
return this.db.transaction("rw", this.leases, async () => {
|
|
46
|
+
const old = await this.leases.get(this.owner);
|
|
47
|
+
if (old && old.token !== token && old.expiresAt > now)
|
|
48
|
+
return false;
|
|
49
|
+
await this.leases.put({ owner: this.owner, token, expiresAt: now + 30000 });
|
|
50
|
+
return true;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
releaseLease(token) { return this.db.transaction("rw", this.leases, async () => { if ((await this.leases.get(this.owner))?.token === token)
|
|
54
|
+
await this.leases.delete(this.owner); }); }
|
|
55
|
+
identity(data) { if (data.appId !== this.scope.appId || data.profileId !== this.scope.profileId)
|
|
56
|
+
throw new Error("INBOX_IDENTITY_MISMATCH"); }
|
|
57
|
+
async bootstrap(input, expected) {
|
|
58
|
+
this.identity(input);
|
|
59
|
+
const start = inboxSequence(input.startSeq), head = inboxSequence(input.headSeq);
|
|
60
|
+
if (!input.epoch || start < 1n || start > head + 1n || !Number.isSafeInteger(input.windowStart) || !Array.isArray(input.basis))
|
|
61
|
+
throw new Error("INVALID_INBOX_BOOTSTRAP");
|
|
62
|
+
return this.db.transaction("rw", this.tables(), async () => {
|
|
63
|
+
const current = await this.cursor();
|
|
64
|
+
// A slower tab must never erase facts another tab committed while this
|
|
65
|
+
// bootstrap request was in flight. The caller catches up from that cursor.
|
|
66
|
+
if (expected !== undefined && JSON.stringify(current ?? null) !== JSON.stringify(expected)) {
|
|
67
|
+
if (current)
|
|
68
|
+
return current;
|
|
69
|
+
throw new Error("INBOX_BOOTSTRAP_CHANGED");
|
|
70
|
+
}
|
|
71
|
+
// A reset rebuilds current state, while older message cache stays available.
|
|
72
|
+
const old = await this.messages.where("owner").equals(this.owner).toArray();
|
|
73
|
+
await this.messages.bulkDelete(old.filter(row => row.acceptedAt >= input.windowStart).map(row => [row.owner, row.thread, row.id]));
|
|
74
|
+
for (const table of [this.facts, this.positions, this.explicit, this.threads])
|
|
75
|
+
await table.where("owner").equals(this.owner).delete();
|
|
76
|
+
for (const item of [...input.basis].sort((a, b) => inboxSequence(a.inboxSeq) < inboxSequence(b.inboxSeq) ? -1 : 1)) {
|
|
77
|
+
if (inboxSequence(item.inboxSeq) >= start)
|
|
78
|
+
throw new Error("INVALID_INBOX_BASIS_SEQUENCE");
|
|
79
|
+
await this.applyFact({ inboxSeq: item.inboxSeq, sourceId: item.id, acceptedAt: input.windowStart - 1, kind: item.kind, fact: item.fact }, input.windowStart, true);
|
|
80
|
+
}
|
|
81
|
+
const cursor = { owner: this.owner, epoch: input.epoch, seq: (start - 1n).toString(), windowStart: input.windowStart, initialized: false };
|
|
82
|
+
await this.cursors.put(cursor);
|
|
83
|
+
return cursor;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
async apply(page) {
|
|
87
|
+
this.identity(page);
|
|
88
|
+
inboxSequence(page.startSeq);
|
|
89
|
+
const next = inboxSequence(page.nextSeq), head = inboxSequence(page.headSeq);
|
|
90
|
+
if (page.resetRequired)
|
|
91
|
+
throw new Error("INBOX_RESET_REQUIRED");
|
|
92
|
+
if (next > head || !Array.isArray(page.events))
|
|
93
|
+
throw new Error("INVALID_INBOX_PAGE");
|
|
94
|
+
return this.db.transaction("rw", this.tables(), async () => {
|
|
95
|
+
const cursor = await this.cursor();
|
|
96
|
+
if (!cursor || cursor.epoch !== page.epoch)
|
|
97
|
+
throw new Error("INBOX_RESET_REQUIRED");
|
|
98
|
+
let sequence = inboxSequence(cursor.seq);
|
|
99
|
+
const changed = new Set();
|
|
100
|
+
for (const event of page.events) {
|
|
101
|
+
const incoming = inboxSequence(event.inboxSeq);
|
|
102
|
+
if (incoming <= sequence)
|
|
103
|
+
continue;
|
|
104
|
+
if (incoming !== sequence + 1n || incoming > head)
|
|
105
|
+
throw new Error("INBOX_SEQUENCE_GAP");
|
|
106
|
+
if (!Number.isSafeInteger(event.acceptedAt) || event.acceptedAt < 0 || !event.sourceId)
|
|
107
|
+
throw new Error("INVALID_INBOX_EVENT");
|
|
108
|
+
const thread = await this.applyFact(event, cursor.windowStart, false);
|
|
109
|
+
if (thread)
|
|
110
|
+
changed.add(thread);
|
|
111
|
+
sequence = incoming;
|
|
112
|
+
}
|
|
113
|
+
if (next > sequence)
|
|
114
|
+
throw new Error("INBOX_SEQUENCE_GAP");
|
|
115
|
+
const updated = { ...cursor, seq: sequence.toString(), initialized: cursor.initialized || sequence >= head };
|
|
116
|
+
await this.cursors.put(updated);
|
|
117
|
+
return { cursor: updated, threads: [...changed] };
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
async applyFact(event, windowStart, basis) {
|
|
121
|
+
const data = event.fact, owner = this.owner;
|
|
122
|
+
if (!data || data.appId !== this.scope.appId)
|
|
123
|
+
throw new Error("INBOX_FACT_IDENTITY_MISMATCH");
|
|
124
|
+
switch (event.kind) {
|
|
125
|
+
case "messageAdded": {
|
|
126
|
+
const message = data, thread = message.threadId;
|
|
127
|
+
if (!thread || !message.messageId || !message.from || !Number.isSafeInteger(message.seq) || message.seq < 1 || !["dm", "group"].includes(message.threadKind))
|
|
128
|
+
throw new Error("INVALID_INBOX_MESSAGE");
|
|
129
|
+
if (message.from !== this.scope.profileId && !message.recipients?.includes(this.scope.profileId) && !(message.threadKind === "dm" && message.to === this.scope.profileId))
|
|
130
|
+
throw new Error("INBOX_MESSAGE_INACCESSIBLE");
|
|
131
|
+
await this.threads.put({ owner, id: thread, kind: message.threadKind, teamId: message.teamId, targetId: message.to });
|
|
132
|
+
const body = message.body;
|
|
133
|
+
if (body?.kind === "group") {
|
|
134
|
+
await this.facts.put({ owner, kind: "groupControl", id: message.messageId, thread, value: data });
|
|
135
|
+
await this.facts.put({ owner, kind: "structure", id: thread, thread, value: { seq: event.inboxSeq } });
|
|
136
|
+
return thread;
|
|
137
|
+
}
|
|
138
|
+
if (basis || event.acceptedAt < windowStart)
|
|
139
|
+
return thread;
|
|
140
|
+
const root = messageThreadRoot(message.body) ?? "";
|
|
141
|
+
const recalls = await this.facts.get([owner, "recall", JSON.stringify([thread, message.messageId])]);
|
|
142
|
+
await this.messages.put({ owner, thread, id: message.messageId, acceptedAt: event.acceptedAt, time: message.serverCreatedAt, seq: message.seq, changeSeq: event.inboxSeq.padStart(19, "0"), root, recalled: recalls?.value.from === message.from, value: message });
|
|
143
|
+
const target = body?.kind === "recall" ? body.targetMessageId : body?.kind === "message" && body.content?.appId === this.scope.appId ? body.content?.recall?.messageId : undefined;
|
|
144
|
+
if (typeof target === "string") {
|
|
145
|
+
const key = JSON.stringify([thread, target]);
|
|
146
|
+
await this.facts.put({ owner, kind: "recall", id: key, thread, value: { from: message.from, target } });
|
|
147
|
+
const old = await this.messages.get([owner, thread, target]);
|
|
148
|
+
if (old && old.value.from === message.from)
|
|
149
|
+
await this.messages.update([owner, thread, target], { recalled: true, changeSeq: event.inboxSeq.padStart(19, "0") });
|
|
150
|
+
}
|
|
151
|
+
return thread;
|
|
152
|
+
}
|
|
153
|
+
case "readingUpdated": {
|
|
154
|
+
if (data.profileId !== this.scope.profileId || !data.threadId || !Number.isSafeInteger(data.readThroughSeq) || data.readThroughSeq < 0 || !Array.isArray(data.explicitReadMessageIds))
|
|
155
|
+
throw new Error("INVALID_INBOX_READING");
|
|
156
|
+
const thread = data.threadId, root = data.threadRootId ?? "", old = await this.positions.get([owner, thread, root]);
|
|
157
|
+
if (!old || data.readThroughSeq > old.seq)
|
|
158
|
+
await this.positions.put({ owner, thread, root, seq: data.readThroughSeq, messageId: data.readThroughMessageId });
|
|
159
|
+
if (data.explicitReadMessageIds.length)
|
|
160
|
+
await this.explicit.bulkPut(data.explicitReadMessageIds.map((id) => ({ owner, thread, id })));
|
|
161
|
+
return thread;
|
|
162
|
+
}
|
|
163
|
+
case "threadAssigned": {
|
|
164
|
+
if (!data.sourceThreadId || !data.threadId || !data.teamId)
|
|
165
|
+
throw new Error("INVALID_INBOX_ASSIGNMENT");
|
|
166
|
+
await this.facts.put({ owner, kind: event.kind, id: data.sourceThreadId, thread: data.sourceThreadId, value: data });
|
|
167
|
+
await this.facts.put({ owner, kind: "structure", id: data.sourceThreadId, thread: data.sourceThreadId, value: { seq: event.inboxSeq } });
|
|
168
|
+
return data.threadId;
|
|
169
|
+
}
|
|
170
|
+
case "threadOrganized": {
|
|
171
|
+
if (!data.threadId || !data.rootMessageId || !Array.isArray(data.messageIds) || !Number.isSafeInteger(data.revision))
|
|
172
|
+
throw new Error("INVALID_INBOX_ORGANIZATION");
|
|
173
|
+
const thread = data.threadId, key = JSON.stringify([thread, data.rootMessageId]), old = await this.facts.get([owner, event.kind, key]);
|
|
174
|
+
if (old && old.value.revision >= data.revision)
|
|
175
|
+
return thread;
|
|
176
|
+
const selected = await this.messages.bulkGet(data.messageIds.map((id) => [owner, thread, id]));
|
|
177
|
+
for (const message of selected) {
|
|
178
|
+
if (!message)
|
|
179
|
+
continue;
|
|
180
|
+
const position = await this.positions.get([owner, thread, message.root]);
|
|
181
|
+
if (!messageRequiresPlayback(message.value.body) && message.seq <= (position?.seq ?? 0))
|
|
182
|
+
await this.explicit.put({ owner, thread, id: message.id, preserved: true });
|
|
183
|
+
await this.messages.update([owner, thread, message.id], { root: data.rootMessageId, changeSeq: event.inboxSeq.padStart(19, "0") });
|
|
184
|
+
}
|
|
185
|
+
await this.facts.put({ owner, kind: event.kind, id: key, thread, value: data });
|
|
186
|
+
await this.facts.put({ owner, kind: "structure", id: thread, thread, value: { seq: event.inboxSeq } });
|
|
187
|
+
return thread;
|
|
188
|
+
}
|
|
189
|
+
case "relationshipUpdated": {
|
|
190
|
+
if (!data.pairId || ![data.actorId, data.targetId].includes(this.scope.profileId))
|
|
191
|
+
throw new Error("INVALID_INBOX_RELATIONSHIP");
|
|
192
|
+
await this.facts.put({ owner, kind: event.kind, id: data.pairId, thread: data.threadId, value: data });
|
|
193
|
+
return data.threadId;
|
|
194
|
+
}
|
|
195
|
+
default: throw new Error(`UNSUPPORTED_INBOX_EVENT:${event.kind}`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
async readingSnapshot() {
|
|
199
|
+
return this.db.transaction("r", this.tables(), async () => {
|
|
200
|
+
const cursor = await this.cursor(), owner = this.owner;
|
|
201
|
+
const [threads, rows, positions, explicit, facts] = await Promise.all([this.threads.where("owner").equals(owner).toArray(), this.messages.where("owner").equals(owner).toArray(), this.positions.where("owner").equals(owner).toArray(), this.explicit.where("owner").equals(owner).toArray(), this.facts.where("owner").equals(owner).toArray()]);
|
|
202
|
+
const byThread = new Map(threads.map(thread => [thread.id, { id: thread.id, kind: thread.kind, teamId: thread.teamId, messages: [], readThroughSeq: 0, explicitReadMessageIds: [], preservedReadMessageIds: [], messageThreadReadThrough: {} }]));
|
|
203
|
+
for (const position of positions) {
|
|
204
|
+
const thread = byThread.get(position.thread);
|
|
205
|
+
if (!thread)
|
|
206
|
+
continue;
|
|
207
|
+
if (position.root)
|
|
208
|
+
thread.messageThreadReadThrough[position.root] = position.seq;
|
|
209
|
+
else
|
|
210
|
+
thread.readThroughSeq = position.seq;
|
|
211
|
+
}
|
|
212
|
+
for (const item of explicit) {
|
|
213
|
+
const thread = byThread.get(item.thread);
|
|
214
|
+
if (thread)
|
|
215
|
+
(item.preserved ? thread.preservedReadMessageIds : thread.explicitReadMessageIds).push(item.id);
|
|
216
|
+
}
|
|
217
|
+
for (const fact of facts)
|
|
218
|
+
if (fact.kind === "threadAssigned") {
|
|
219
|
+
const thread = byThread.get(fact.value.sourceThreadId);
|
|
220
|
+
if (thread) {
|
|
221
|
+
thread.conversationId = fact.value.threadId;
|
|
222
|
+
thread.teamId = fact.value.teamId;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
const windowStart = Math.max(cursor?.windowStart ?? 0, Date.now() - 180 * 24 * 60 * 60 * 1000);
|
|
226
|
+
for (const row of rows) {
|
|
227
|
+
if (row.acceptedAt < windowStart)
|
|
228
|
+
continue;
|
|
229
|
+
const thread = byThread.get(row.thread);
|
|
230
|
+
if (!thread)
|
|
231
|
+
continue;
|
|
232
|
+
const message = row.value, body = message.body;
|
|
233
|
+
const mentions = body?.content?.mentions ?? body?.content?.content?.mentions ?? [];
|
|
234
|
+
const visible = body?.kind === undefined || ["message", "quote"].includes(body.kind) || body.kind === "contact" && ["friendRequest", "requestFriend"].includes(body.action);
|
|
235
|
+
thread.messages.push({ id: row.id, seq: row.seq, from: message.from, recipients: message.recipients ?? [], threadRootId: row.root || undefined, mentions: [...new Set(Array.isArray(mentions) ? mentions.filter(item => item && typeof item.id === "string" && (this.scope.appId !== "pmate:merry" || !["all", "所有人"].includes(item.name))).map(item => item.id) : [])].sort(), readPolicy: messageRequiresPlayback(message.body) ? "explicit" : "visible", recalled: row.recalled || !visible || body?.kind === "recall" || Boolean(body?.content?.recall), payload: null, readingControl: isReadingControl(message.body, this.scope.appId) });
|
|
236
|
+
}
|
|
237
|
+
for (const thread of byThread.values()) {
|
|
238
|
+
const canonical = thread.conversationId ?? thread.id;
|
|
239
|
+
const controls = facts.filter(fact => fact.kind === "groupControl" && (byThread.get(fact.thread)?.conversationId ?? fact.thread) === canonical).map(fact => ({ ...fact.value, teamId: thread.teamId }));
|
|
240
|
+
const group = thread.kind === "group" ? projectInboxGroup(this.scope.appId, threads.find(row => row.id === thread.id)?.targetId ?? "", thread.teamId, controls) : undefined;
|
|
241
|
+
if (group?.status === "dissolved") {
|
|
242
|
+
thread.messages = [];
|
|
243
|
+
thread.readThroughSeq = 0;
|
|
244
|
+
thread.explicitReadMessageIds = [];
|
|
245
|
+
delete thread.messageThreadReadThrough;
|
|
246
|
+
delete thread.preservedReadMessageIds;
|
|
247
|
+
}
|
|
248
|
+
else
|
|
249
|
+
thread.messages.sort((a, b) => a.seq - b.seq);
|
|
250
|
+
}
|
|
251
|
+
return { schemaVersion: 1, appId: this.scope.appId, profileId: this.scope.profileId, syncCursor: `inbox:${cursor?.epoch ?? "none"}:${cursor?.seq ?? "0"}`, threads: [...byThread.values()] };
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
async threadMessages(thread) { return (await this.messages.where("[owner+thread]").equals([this.owner, thread]).sortBy("seq")).map(row => ({ ...row.value, recalled: row.recalled, body: this.annotatedBody(row) })); }
|
|
255
|
+
async conversationMessages(thread, teamId) {
|
|
256
|
+
const assignments = (await this.facts.where("[owner+kind]").equals([this.owner, "threadAssigned"]).toArray()).filter(row => row.value.threadId === thread);
|
|
257
|
+
const sources = [thread, ...assignments.map(row => row.value.sourceThreadId)];
|
|
258
|
+
const messages = (await Promise.all(sources.map(source => this.threadMessages(source)))).flatMap(rows => rows.map(row => {
|
|
259
|
+
const assignment = assignments.find(item => item.value.sourceThreadId === row.threadId);
|
|
260
|
+
return assignment ? { ...row, sourceThreadId: row.threadId, threadId: thread, teamId: assignment.value.teamId } : row;
|
|
261
|
+
})).filter(row => row.teamId === teamId);
|
|
262
|
+
return messages.sort((a, b) => a.serverCreatedAt - b.serverCreatedAt || (a.messageId < b.messageId ? -1 : a.messageId > b.messageId ? 1 : 0));
|
|
263
|
+
}
|
|
264
|
+
async conversationMessage(thread, teamId, id) {
|
|
265
|
+
const assignments = (await this.facts.where("[owner+kind]").equals([this.owner, "threadAssigned"]).toArray()).filter(row => row.value.threadId === thread);
|
|
266
|
+
const sources = [thread, ...assignments.map(row => row.value.sourceThreadId)];
|
|
267
|
+
const rows = await this.messages.bulkGet(sources.map(source => [this.owner, source, id]));
|
|
268
|
+
for (const row of rows) {
|
|
269
|
+
if (!row)
|
|
270
|
+
continue;
|
|
271
|
+
const assignment = assignments.find(item => item.value.sourceThreadId === row.thread);
|
|
272
|
+
if ((assignment?.value.teamId ?? row.value.teamId) !== teamId)
|
|
273
|
+
continue;
|
|
274
|
+
return { ...row.value, recalled: row.recalled, body: this.annotatedBody(row), ...(assignment ? { sourceThreadId: row.thread, threadId: thread, teamId } : {}) };
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
async conversationChanges(thread, teamId, afterSeq, afterId = "") {
|
|
278
|
+
const assignments = (await this.facts.where("[owner+kind]").equals([this.owner, "threadAssigned"]).toArray()).filter(row => row.value.threadId === thread);
|
|
279
|
+
const sources = [thread, ...assignments.map(row => row.value.sourceThreadId)];
|
|
280
|
+
const rows = (await Promise.all(sources.map(source => this.messages.where("[owner+thread+changeSeq+id]").between([this.owner, source, afterSeq.padStart(19, "0"), afterId], [this.owner, source, Dexie.maxKey, Dexie.maxKey], false, true).limit(101).toArray()))).flat();
|
|
281
|
+
return rows.filter(row => (assignments.find(item => item.value.sourceThreadId === row.thread)?.value.teamId ?? row.value.teamId) === teamId).sort((a, b) => a.changeSeq.localeCompare(b.changeSeq) || a.id.localeCompare(b.id)).map(row => ({ changeSeq: row.changeSeq, id: row.id }));
|
|
282
|
+
}
|
|
283
|
+
async structureSequence(thread) {
|
|
284
|
+
const assignments = (await this.facts.where("[owner+kind]").equals([this.owner, "threadAssigned"]).toArray()).filter(row => row.value.threadId === thread);
|
|
285
|
+
const sources = [thread, ...assignments.map(row => row.value.sourceThreadId)];
|
|
286
|
+
const rows = await this.facts.bulkGet(sources.map(source => [this.owner, "structure", source]));
|
|
287
|
+
return rows.reduce((seq, row) => row && inboxSequence(row.value.seq) > seq ? inboxSequence(row.value.seq) : seq, 0n);
|
|
288
|
+
}
|
|
289
|
+
async discussionSummaries(thread, team, roots) {
|
|
290
|
+
return this.db.transaction("r", this.tables(), async () => {
|
|
291
|
+
const snapshot = await this.readingSnapshot(), messages = await this.conversationMessages(thread, team);
|
|
292
|
+
const sources = sourcesInConversation({ ...snapshot, pending: [] }, thread);
|
|
293
|
+
const reading = new Map(sources.flatMap(source => source.messages.map(message => [message.id, { message, source }])));
|
|
294
|
+
const organizations = await this.facts.where("[owner+kind]").equals([this.owner, "threadOrganized"]).toArray();
|
|
295
|
+
const items = [...new Set(roots)].sort().map(root => {
|
|
296
|
+
const original = reading.get(root);
|
|
297
|
+
if (!original || original.message.threadRootId || original.message.readingControl)
|
|
298
|
+
throw new Error("MESSAGE_THREAD_ROOT_NOT_FOUND");
|
|
299
|
+
const replies = messages.filter(message => messageThreadRoot(message.body) === root).filter(message => { const entry = reading.get(message.messageId); return entry && !entry.message.recalled && !entry.message.readingControl; });
|
|
300
|
+
const last = replies.at(-1);
|
|
301
|
+
const unread = replies.filter(message => {
|
|
302
|
+
if (message.from === this.scope.profileId)
|
|
303
|
+
return false;
|
|
304
|
+
const entry = reading.get(message.messageId);
|
|
305
|
+
return !entry.source.preservedReadMessageIds?.includes(message.messageId) && (entry.message.readPolicy === "explicit" ? !entry.source.explicitReadMessageIds.includes(message.messageId) : entry.message.seq > readingCursor(entry.source, root));
|
|
306
|
+
}).length;
|
|
307
|
+
const organization = organizations.find(row => row.value.threadId === thread && row.value.rootMessageId === root);
|
|
308
|
+
return { rootMessageId: root, replyCount: replies.length, unreadCount: unread, lastReplyId: last?.messageId ?? null, lastReplyAt: last?.serverCreatedAt ?? null, participantProfileIds: [...new Set(replies.map(message => message.from))].sort().slice(0, 3), ...(organization ? { ownerAgentId: organization.value.ownerAgentId } : {}) };
|
|
309
|
+
});
|
|
310
|
+
const cursor = await this.cursor();
|
|
311
|
+
return { items, revision: Number(cursor?.seq ?? "0") };
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
async group(groupId, teamId) {
|
|
315
|
+
const assignments = await this.facts.where("[owner+kind]").equals([this.owner, "threadAssigned"]).toArray();
|
|
316
|
+
const controls = (await this.facts.where("[owner+kind]").equals([this.owner, "groupControl"]).toArray()).map(row => {
|
|
317
|
+
const assignment = assignments.find(item => item.value.sourceThreadId === row.thread);
|
|
318
|
+
return assignment ? { ...row.value, teamId: assignment.value.teamId } : row.value;
|
|
319
|
+
});
|
|
320
|
+
return projectInboxGroup(this.scope.appId, groupId, teamId, controls);
|
|
321
|
+
}
|
|
322
|
+
annotatedBody(row) {
|
|
323
|
+
if (!row.root)
|
|
324
|
+
return row.value.body;
|
|
325
|
+
const body = row.value.body;
|
|
326
|
+
return { ...body, content: { ...body?.content, threadRootId: row.root } };
|
|
327
|
+
}
|
|
328
|
+
close() { this.db.close(); }
|
|
329
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { InboxClient } from "./inboxClient.js";
|
|
2
|
+
import type { CachedChatMessage } from "./cachedMessage.js";
|
|
3
|
+
import type { MessageTransport } from "./messageClient.js";
|
|
4
|
+
/** Existing message consumers page the local Inbox materialization. No history
|
|
5
|
+
* request or reading snapshot endpoint is used by this transport. */
|
|
6
|
+
export declare function inboxMessageTransport(inbox: InboxClient, team: string, root?: string): MessageTransport<CachedChatMessage>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { inboxSequence } from "./inboxStore.js";
|
|
2
|
+
import { messageThreadRoot } from "./messageThread.js";
|
|
3
|
+
const encode = (cursor) => `ib1:${encodeURIComponent(JSON.stringify(cursor))}`;
|
|
4
|
+
function decode(token) {
|
|
5
|
+
try {
|
|
6
|
+
if (!token.startsWith("ib1:"))
|
|
7
|
+
return;
|
|
8
|
+
const cursor = JSON.parse(decodeURIComponent(token.slice(4)));
|
|
9
|
+
inboxSequence(cursor.seq);
|
|
10
|
+
return cursor;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const cached = (message) => ({ ...message, id: message.messageId, timestamp: message.serverCreatedAt });
|
|
17
|
+
/** Existing message consumers page the local Inbox materialization. No history
|
|
18
|
+
* request or reading snapshot endpoint is used by this transport. */
|
|
19
|
+
export function inboxMessageTransport(inbox, team, root) {
|
|
20
|
+
const db = inbox.store;
|
|
21
|
+
const read = (run) => db.db.transaction("r", [db.cursors, db.messages, db.facts, db.threads], run);
|
|
22
|
+
const rows = async (thread) => {
|
|
23
|
+
const messages = await db.conversationMessages(thread, team);
|
|
24
|
+
const byId = new Map(messages.map(message => [message.messageId, message]));
|
|
25
|
+
return messages.filter(message => {
|
|
26
|
+
const body = message.body, content = body?.content;
|
|
27
|
+
const target = content?.reaction?.messageId ?? content?.recall?.messageId;
|
|
28
|
+
const selected = messageThreadRoot(message.body) ?? (typeof target === "string" ? messageThreadRoot(byId.get(target)?.body) : undefined);
|
|
29
|
+
return selected === root;
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
const metadata = async (thread) => {
|
|
33
|
+
const cursor = await db.cursor();
|
|
34
|
+
if (!cursor)
|
|
35
|
+
throw new Error("INBOX_NOT_INITIALIZED");
|
|
36
|
+
return { epoch: cursor.epoch, thread, team, root, seq: cursor.seq, id: "\uffff" };
|
|
37
|
+
};
|
|
38
|
+
const valid = (cursor, wanted) => cursor && cursor.epoch === wanted.epoch && cursor.thread === wanted.thread && cursor.team === wanted.team && cursor.root === wanted.root;
|
|
39
|
+
const load = (thread, signal) => read(async () => {
|
|
40
|
+
signal.throwIfAborted();
|
|
41
|
+
const current = await metadata(thread), all = await rows(thread), selected = all.slice(-100);
|
|
42
|
+
return { messages: selected.map(cached), checkpoint: encode(current), nextBefore: all.length > selected.length ? encode({ ...current, before: { time: selected[0].serverCreatedAt, id: selected[0].messageId } }) : null, hasMoreChanges: false, resetRequired: false };
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
local: true,
|
|
46
|
+
load,
|
|
47
|
+
changes: (thread, after, signal) => read(async () => {
|
|
48
|
+
signal.throwIfAborted();
|
|
49
|
+
const current = await metadata(thread), cursor = decode(after);
|
|
50
|
+
if (!valid(cursor, current) || await db.structureSequence(thread) > inboxSequence(cursor.seq))
|
|
51
|
+
return { messages: [], checkpoint: encode(current), resetRequired: true };
|
|
52
|
+
const changed = await db.conversationChanges(thread, team, cursor.seq, cursor.id ?? "\uffff");
|
|
53
|
+
const selected = changed.slice(0, 100), hasMore = changed.length > selected.length;
|
|
54
|
+
const messages = await Promise.all(selected.map(item => db.conversationMessage(thread, team, item.id)));
|
|
55
|
+
const visible = await Promise.all(messages.map(async (message) => {
|
|
56
|
+
if (!message)
|
|
57
|
+
return;
|
|
58
|
+
const content = message.body?.content, target = content?.reaction?.messageId ?? content?.recall?.messageId;
|
|
59
|
+
const targetMessage = typeof target === "string" ? await db.conversationMessage(thread, team, target) : undefined;
|
|
60
|
+
const selectedRoot = messageThreadRoot(message.body) ?? messageThreadRoot(targetMessage?.body);
|
|
61
|
+
return selectedRoot === root ? cached(message) : undefined;
|
|
62
|
+
}));
|
|
63
|
+
const last = selected.at(-1);
|
|
64
|
+
return { messages: visible.filter((message) => !!message), checkpoint: encode(hasMore && last ? { ...current, seq: BigInt(last.changeSeq).toString(), id: last.id } : current), hasMoreChanges: hasMore, resetRequired: false };
|
|
65
|
+
}),
|
|
66
|
+
older: (thread, before, signal) => read(async () => {
|
|
67
|
+
signal.throwIfAborted();
|
|
68
|
+
const current = await metadata(thread), cursor = decode(before);
|
|
69
|
+
if (!valid(cursor, current) || !cursor?.before || await db.structureSequence(thread) > inboxSequence(cursor.seq))
|
|
70
|
+
return { messages: [], checkpoint: encode(current), resetRequired: true };
|
|
71
|
+
const boundary = cursor.before, all = (await rows(thread)).filter(row => row.serverCreatedAt < boundary.time || row.serverCreatedAt === boundary.time && row.messageId < boundary.id);
|
|
72
|
+
const selected = all.slice(-100);
|
|
73
|
+
return { messages: selected.map(cached), checkpoint: encode(current), nextBefore: all.length > selected.length ? encode({ ...current, before: { time: selected[0].serverCreatedAt, id: selected[0].messageId } }) : null, hasMoreChanges: false, resetRequired: false };
|
|
74
|
+
}),
|
|
75
|
+
};
|
|
76
|
+
}
|
package/lib/runtime/index.d.ts
CHANGED
|
@@ -29,3 +29,13 @@ export * from "./durableSender.js";
|
|
|
29
29
|
export * from "./chatSession.js";
|
|
30
30
|
export * from "./messageReaders.js";
|
|
31
31
|
export * from "./createChat.js";
|
|
32
|
+
export * from "./conversationRead.js";
|
|
33
|
+
export { projectConversationReading, type ReadingCandidate, type MessageReadingState, type ConversationReadingView } from "./conversationReading.js";
|
|
34
|
+
export { projectMessageTimeline, type TimelineItem, type TimelineReaction, type TimelineReactionEvent } from "./messageTimeline.js";
|
|
35
|
+
export * from "./messageLaunch.js";
|
|
36
|
+
export * from "./outgoingContent.js";
|
|
37
|
+
export type { ChatGroup } from "./groupClient.js";
|
|
38
|
+
export type { ConversationTarget } from "./conversationDirectory.js";
|
|
39
|
+
export * from "./messageThread.js";
|
|
40
|
+
export * from "./inboxStore.js";
|
|
41
|
+
export * from "./inboxClient.js";
|
package/lib/runtime/index.js
CHANGED
|
@@ -29,3 +29,11 @@ export * from "./durableSender.js";
|
|
|
29
29
|
export * from "./chatSession.js";
|
|
30
30
|
export * from "./messageReaders.js";
|
|
31
31
|
export * from "./createChat.js";
|
|
32
|
+
export * from "./conversationRead.js";
|
|
33
|
+
export { projectConversationReading } from "./conversationReading.js";
|
|
34
|
+
export { projectMessageTimeline } from "./messageTimeline.js";
|
|
35
|
+
export * from "./messageLaunch.js";
|
|
36
|
+
export * from "./outgoingContent.js";
|
|
37
|
+
export * from "./messageThread.js";
|
|
38
|
+
export * from "./inboxStore.js";
|
|
39
|
+
export * from "./inboxClient.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Dexie } from "dexie";
|
|
2
|
+
/** WebKit can invalidate an IDB connection while the application is suspended.
|
|
3
|
+
* Only replay a whole rejected transaction; never replay individual requests or clear data. */
|
|
4
|
+
export declare function recoverableTransactions(db: Dexie, isClosed: () => boolean, options?: {
|
|
5
|
+
retryAbort?: boolean;
|
|
6
|
+
}): Dexie["transaction"];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** WebKit can invalidate an IDB connection while the application is suspended.
|
|
2
|
+
* Only replay a whole rejected transaction; never replay individual requests or clear data. */
|
|
3
|
+
export function recoverableTransactions(db, isClosed, options = {}) {
|
|
4
|
+
const transaction = async (args, attempt) => {
|
|
5
|
+
try {
|
|
6
|
+
return await db.transaction.apply(db, args);
|
|
7
|
+
}
|
|
8
|
+
catch (cause) {
|
|
9
|
+
const original = cause;
|
|
10
|
+
const error = new Error(original.message, { cause });
|
|
11
|
+
error.name = original.name;
|
|
12
|
+
Object.assign(error, { status: original.status, threadId: original.threadId, inner: original.inner, diagnostic: { source: "storage", database: db.name, tables: args.slice(1, -1).flat().map((table) => table.name ?? String(table)).join(","), mode: String(args[0]), attempt } });
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
let recovery;
|
|
17
|
+
return (async (...args) => {
|
|
18
|
+
try {
|
|
19
|
+
return await transaction(args, 1);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
const failure = error;
|
|
23
|
+
const aborted = options.retryAbort && (failure.name === "AbortError" || failure.inner?.name === "AbortError");
|
|
24
|
+
if (isClosed() || !aborted && (!(failure.name === "UnknownError" || failure.inner?.name === "UnknownError") || !/without an in-progress transaction/i.test(failure.message ?? "")))
|
|
25
|
+
throw error;
|
|
26
|
+
// An aborted transaction has already rolled back; replay without closing other live transactions.
|
|
27
|
+
if (aborted)
|
|
28
|
+
return transaction(args, 2);
|
|
29
|
+
if (!recovery) {
|
|
30
|
+
db.close({ disableAutoOpen: false });
|
|
31
|
+
const opening = db.open();
|
|
32
|
+
recovery = opening;
|
|
33
|
+
void opening.finally(() => { if (recovery === opening)
|
|
34
|
+
recovery = undefined; }).catch(() => { });
|
|
35
|
+
}
|
|
36
|
+
await recovery;
|
|
37
|
+
if (isClosed())
|
|
38
|
+
throw error;
|
|
39
|
+
return transaction(args, 2);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -7,6 +7,10 @@ export type MessagePage<T> = {
|
|
|
7
7
|
resetRequired?: boolean;
|
|
8
8
|
};
|
|
9
9
|
export type MessageTransport<T> = {
|
|
10
|
+
/** A durable local source can fill windows while the network is unavailable. */
|
|
11
|
+
local?: boolean;
|
|
12
|
+
/** Optional team-scoped authorization for fresh instances recovering a revoked cache. */
|
|
13
|
+
authorizeScope?: (signal: AbortSignal) => Promise<void>;
|
|
10
14
|
/** Authoritative history. Must include control state needed to merge old rows. */
|
|
11
15
|
load: (threadId: string, signal: AbortSignal) => Promise<MessagePage<T>>;
|
|
12
16
|
changes?: (threadId: string, after: string, signal: AbortSignal) => Promise<MessagePage<T>>;
|
|
@@ -36,9 +40,12 @@ export declare class MessageClient<T extends StoredMessage> {
|
|
|
36
40
|
private options;
|
|
37
41
|
private storage;
|
|
38
42
|
private watches;
|
|
43
|
+
private windowEdges;
|
|
44
|
+
private accessListeners;
|
|
39
45
|
private allListeners;
|
|
40
46
|
private reads;
|
|
41
47
|
private syncing;
|
|
48
|
+
private completedSyncs;
|
|
42
49
|
private paging;
|
|
43
50
|
private writes;
|
|
44
51
|
private activeWrites;
|
|
@@ -54,15 +61,37 @@ export declare class MessageClient<T extends StoredMessage> {
|
|
|
54
61
|
private queueBytes;
|
|
55
62
|
private pendingBytes;
|
|
56
63
|
private pendingRecords;
|
|
64
|
+
private legacyImports;
|
|
65
|
+
private revokingScope?;
|
|
66
|
+
private scopeReady?;
|
|
67
|
+
private scopeVersion;
|
|
68
|
+
private scopeAllowed;
|
|
69
|
+
private scopeDenied;
|
|
70
|
+
private enqueuing;
|
|
71
|
+
private ensureScope;
|
|
57
72
|
constructor(options: MessageClientOptions<T>);
|
|
73
|
+
/** Shared guard for sibling caches; it never authorizes a denied old instance. */
|
|
74
|
+
subscribeAccessRevoked(listener: () => void): () => void;
|
|
75
|
+
scopeAccess(): Promise<{
|
|
76
|
+
version: number;
|
|
77
|
+
allowed: boolean;
|
|
78
|
+
}>;
|
|
79
|
+
private authorizingScope?;
|
|
80
|
+
/** Recovery belongs to the SDK; withdrawn instances never regain authority. */
|
|
81
|
+
authorizeScope(): Promise<void>;
|
|
58
82
|
getSnapshot(thread: string): MessageSnapshot<T> | undefined;
|
|
83
|
+
/** Exact authoritative row only; migration-only rows never prove delivery. */
|
|
84
|
+
cachedMessage(thread: string, id: string): Promise<T>;
|
|
59
85
|
subscribe(thread: string, listener: () => void): () => void;
|
|
60
86
|
subscribeAll(listener: (threadId: string) => void): () => void;
|
|
61
87
|
/** Close the connection gap for saved windows with four bounded background lanes. */
|
|
62
|
-
restore(since: number): Promise<void>;
|
|
88
|
+
restore(since: number, threadId?: string): Promise<void>;
|
|
63
89
|
read(thread: string, limit?: number, refresh?: boolean): Promise<MessageSnapshot<T>>;
|
|
64
90
|
/** Application connection/wake events invalidate, rather than fetching directly. */
|
|
65
91
|
invalidate(thread: string): void;
|
|
92
|
+
private fallback;
|
|
93
|
+
/** Migration batches remain separate from authoritative message coverage. */
|
|
94
|
+
importLegacy(thread: string, messages: T[]): Promise<void>;
|
|
66
95
|
private reload;
|
|
67
96
|
/** Events are visible only after their atomic batch commits. */
|
|
68
97
|
receive(thread: string, messages: T[]): Promise<void>;
|
|
@@ -71,18 +100,18 @@ export declare class MessageClient<T extends StoredMessage> {
|
|
|
71
100
|
private release;
|
|
72
101
|
private flushWrites;
|
|
73
102
|
private runWrites;
|
|
103
|
+
private assertNetworkAvailable;
|
|
74
104
|
synchronize(thread: string): Promise<void>;
|
|
105
|
+
/** Keep an explicitly requested history range in the shared subscribed view. */
|
|
106
|
+
expandWindow(thread: string, page: MessageSnapshot<T>): Promise<void>;
|
|
75
107
|
earlier(thread: string, before: {
|
|
76
108
|
timestamp: number;
|
|
77
109
|
id: string;
|
|
78
|
-
}, limit?: number): Promise<
|
|
79
|
-
messages: T[];
|
|
80
|
-
hasEarlier: boolean;
|
|
81
|
-
resetVersion: number;
|
|
82
|
-
complete: boolean;
|
|
83
|
-
}>;
|
|
110
|
+
}, limit?: number, expand?: boolean): Promise<MessageSnapshot<T>>;
|
|
84
111
|
private fillWindow;
|
|
85
112
|
private denyView;
|
|
113
|
+
private denyScope;
|
|
114
|
+
revokeScope(): Promise<number>;
|
|
86
115
|
revoke(thread: string): Promise<void>;
|
|
87
|
-
close(): Promise<void>;
|
|
116
|
+
close(beforeDispose?: Promise<unknown>): Promise<void>;
|
|
88
117
|
}
|