@qvac/core 0.3.5 → 0.4.1
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/CHANGELOG.md +177 -9
- package/README.md +19 -17
- package/dist-lib/lib/api/agents.d.ts +3 -3
- package/dist-lib/lib/api/agents.js +31 -20
- package/dist-lib/lib/api/approval-rules.d.ts +2 -2
- package/dist-lib/lib/api/approval-rules.js +2 -2
- package/dist-lib/lib/api/attachments.d.ts +2 -2
- package/dist-lib/lib/api/attachments.js +14 -25
- package/dist-lib/lib/api/chat-groups.d.ts +2 -2
- package/dist-lib/lib/api/chat-groups.js +9 -9
- package/dist-lib/lib/api/chat.d.ts +4 -2
- package/dist-lib/lib/api/chat.js +18 -18
- package/dist-lib/lib/api/chunks.d.ts +2 -2
- package/dist-lib/lib/api/chunks.js +27 -36
- package/dist-lib/lib/api/current-mesh.d.ts +7 -15
- package/dist-lib/lib/api/current-mesh.js +7 -22
- package/dist-lib/lib/api/devices.d.ts +4 -3
- package/dist-lib/lib/api/devices.js +18 -18
- package/dist-lib/lib/api/execution.d.ts +2 -2
- package/dist-lib/lib/api/execution.js +6 -6
- package/dist-lib/lib/api/files.d.ts +2 -2
- package/dist-lib/lib/api/files.js +4 -4
- package/dist-lib/lib/api/index.d.ts +12 -11
- package/dist-lib/lib/api/index.js +15 -13
- package/dist-lib/lib/api/inference-calls.d.ts +1 -1
- package/dist-lib/lib/api/inference-calls.js +2 -2
- package/dist-lib/lib/api/knowledge.d.ts +2 -2
- package/dist-lib/lib/api/knowledge.js +22 -11
- package/dist-lib/lib/api/local-files.d.ts +3 -0
- package/dist-lib/lib/api/local-files.js +23 -0
- package/dist-lib/lib/api/members.d.ts +6 -2
- package/dist-lib/lib/api/members.js +24 -17
- package/dist-lib/lib/api/mesh.d.ts +4 -5
- package/dist-lib/lib/api/mesh.js +7 -9
- package/dist-lib/lib/api/notifications.d.ts +2 -13
- package/dist-lib/lib/api/notifications.js +20 -52
- package/dist-lib/lib/api/rag.d.ts +2 -2
- package/dist-lib/lib/api/rag.js +4 -4
- package/dist-lib/lib/api/range.d.ts +11 -0
- package/dist-lib/lib/api/range.js +10 -0
- package/dist-lib/lib/api/sync.d.ts +2 -2
- package/dist-lib/lib/api/sync.js +3 -3
- package/dist-lib/lib/api/tool-activity.d.ts +2 -2
- package/dist-lib/lib/api/tool-activity.js +11 -10
- package/dist-lib/lib/api/tool-configs.d.ts +2 -2
- package/dist-lib/lib/api/tool-configs.js +6 -7
- package/dist-lib/lib/api/upload-frames.d.ts +9 -0
- package/dist-lib/lib/api/upload-frames.js +17 -0
- package/dist-lib/lib/api/watchable.d.ts +1 -6
- package/dist-lib/lib/api/watchable.js +4 -13
- package/dist-lib/lib/assistant/history.d.ts +3 -3
- package/dist-lib/lib/assistant-client.js +3 -2
- package/dist-lib/lib/assistant-tree.js +1 -1
- package/dist-lib/lib/assistant.d.ts +16 -14
- package/dist-lib/lib/assistant.js +166 -137
- package/dist-lib/lib/collabora/convert.js +1 -1
- package/dist-lib/lib/core/agent.d.ts +5 -7
- package/dist-lib/lib/core/agent.js +26 -6
- package/dist-lib/lib/core/archived-mesh.js +1 -0
- package/dist-lib/lib/core/chat-order.d.ts +20 -0
- package/dist-lib/lib/core/chat-order.js +96 -0
- package/dist-lib/lib/core/chat.d.ts +0 -5
- package/dist-lib/lib/core/chat.js +1 -3
- package/dist-lib/lib/core/chunk.d.ts +7 -14
- package/dist-lib/lib/core/chunk.js +17 -35
- package/dist-lib/lib/core/contract/agents.js +8 -0
- package/dist-lib/lib/core/contract/compute.d.ts +1 -1
- package/dist-lib/lib/core/contract/compute.js +1 -0
- package/dist-lib/lib/core/contract/joined-meshes.js +4 -3
- package/dist-lib/lib/core/contract/members.js +4 -3
- package/dist-lib/lib/core/contract/writers.js +5 -4
- package/dist-lib/lib/core/departures.js +5 -4
- package/dist-lib/lib/core/device-invites.js +2 -1
- package/dist-lib/lib/core/files/attachments.d.ts +8 -1
- package/dist-lib/lib/core/files/index.d.ts +4 -4
- package/dist-lib/lib/core/files/index.js +18 -8
- package/dist-lib/lib/core/files/local-index.d.ts +16 -0
- package/dist-lib/lib/core/files/local-index.js +38 -0
- package/dist-lib/lib/core/files/processing/document.js +2 -1
- package/dist-lib/lib/core/files/processing/ownership.js +6 -3
- package/dist-lib/lib/core/files/records/chunks.js +1 -0
- package/dist-lib/lib/core/files/records/reclaim.js +1 -0
- package/dist-lib/lib/core/files/records/routing.js +2 -1
- package/dist-lib/lib/core/files/store/blob.d.ts +1 -1
- package/dist-lib/lib/core/files/store/blob.js +6 -3
- package/dist-lib/lib/core/files/store/index.d.ts +1 -1
- package/dist-lib/lib/core/files/store/reference.js +4 -3
- package/dist-lib/lib/core/files/store/server.d.ts +8 -4
- package/dist-lib/lib/core/files/store/server.js +16 -12
- package/dist-lib/lib/core/files/store/sweep.js +2 -1
- package/dist-lib/lib/core/files/upload.d.ts +1 -1
- package/dist-lib/lib/core/hosted-agents.js +1 -1
- package/dist-lib/lib/core/image/cache-sweep.d.ts +1 -0
- package/dist-lib/lib/core/image/cache-sweep.js +7 -3
- package/dist-lib/lib/core/local/files.d.ts +24 -0
- package/dist-lib/lib/core/local/files.js +154 -0
- package/dist-lib/lib/core/local/index.d.ts +21 -5
- package/dist-lib/lib/core/local/index.js +75 -45
- package/dist-lib/lib/core/membership.d.ts +4 -1
- package/dist-lib/lib/core/membership.js +17 -2
- package/dist-lib/lib/core/mesh.d.ts +5 -0
- package/dist-lib/lib/core/mesh.js +10 -5
- package/dist-lib/lib/core/migrations/agent-indexes.d.ts +2 -0
- package/dist-lib/lib/core/migrations/agent-indexes.js +30 -0
- package/dist-lib/lib/core/migrations/file-index.d.ts +2 -0
- package/dist-lib/lib/core/migrations/file-index.js +27 -0
- package/dist-lib/lib/core/migrations/index.js +3 -1
- package/dist-lib/lib/core/notification.js +5 -5
- package/dist-lib/lib/core/range.d.ts +18 -0
- package/dist-lib/lib/core/range.js +17 -0
- package/dist-lib/lib/core/sync/index.js +39 -32
- package/dist-lib/lib/core/sync-status.js +3 -2
- package/dist-lib/lib/core/tool-activity.d.ts +2 -5
- package/dist-lib/lib/core/tool-activity.js +4 -7
- package/dist-lib/lib/core.d.ts +48 -29
- package/dist-lib/lib/core.js +465 -359
- package/dist-lib/lib/knowledge-search.d.ts +2 -2
- package/dist-lib/lib/kv-cache.js +1 -1
- package/dist-lib/lib/log.js +2 -3
- package/dist-lib/lib/mesh-scoped-engine.d.ts +8 -1
- package/dist-lib/lib/mesh-scoped-engine.js +62 -15
- package/dist-lib/lib/model-download.d.ts +14 -5
- package/dist-lib/lib/model-download.js +25 -17
- package/dist-lib/lib/oauth/browser-connect.d.ts +0 -14
- package/dist-lib/lib/oauth/browser-connect.js +1 -26
- package/dist-lib/lib/oauth/token-exchange.d.ts +1 -2
- package/dist-lib/lib/oauth/token-exchange.js +1 -4
- package/dist-lib/lib/run-transcript.d.ts +2 -2
- package/dist-lib/lib/run-transcript.js +3 -2
- package/dist-lib/lib/task.d.ts +1 -0
- package/dist-lib/lib/task.js +3 -2
- package/dist-lib/schema/build.js +4 -10
- package/dist-lib/schema/engine.js +261 -91
- package/dist-lib/schema/field-order.js +1 -4
- package/dist-lib/schema/helpers.d.ts +4 -0
- package/dist-lib/schema/helpers.js +20 -0
- package/dist-lib/schema/local.d.ts +1 -1
- package/dist-lib/schema/local.js +70 -2
- package/dist-lib/schema/qvac.js +30 -0
- package/dist-lib/spec/bind.js +20 -3
- package/dist-lib/spec/calls.js +19 -15
- package/dist-lib/spec/capabilities.d.ts +42 -34
- package/dist-lib/spec/hrpc/hrpc.json +82 -30
- package/dist-lib/spec/hrpc/index.js +106 -57
- package/dist-lib/spec/hrpc/messages.js +5420 -5019
- package/dist-lib/spec/hyperschema/index.js +5424 -5023
- package/dist-lib/spec/hyperschema/schema.json +3202 -2666
- package/dist-lib/spec/hyperschema/types.d.ts +455 -319
- package/dist-lib/spec/local/hyperdb/db.json +119 -1
- package/dist-lib/spec/local/hyperdb/index.js +414 -2
- package/dist-lib/spec/local/hyperdb/messages.js +505 -124
- package/dist-lib/spec/local/hyperschema/index.js +203 -5
- package/dist-lib/spec/local/hyperschema/schema.json +136 -1
- package/dist-lib/spec/local/hyperschema/types.d.ts +32 -1
- package/dist-lib/spec/mesh/hyperdb/db.json +55 -3
- package/dist-lib/spec/mesh/hyperdb/index.js +119 -3
- package/dist-lib/spec/mesh/hyperdb/messages.js +244 -172
- package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +7 -1
- package/dist-lib/spec/mesh/hyperdispatch/index.js +18 -1
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +74 -2
- package/dist-lib/spec/mesh/hyperschema/index.js +74 -2
- package/dist-lib/spec/mesh/hyperschema/schema.json +27 -1
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +9 -1
- package/package.json +15 -9
- package/tui/app.mjs +376 -151
- package/tui/boot.mjs +2 -1
- package/tui/lib/busy-words.mjs +2 -1
- package/tui/lib/knowledge-command.mjs +11 -10
- package/tui/lib/knowledge-import.mjs +7 -5
- package/tui/lib/render.mjs +4 -3
- package/tui/lib/usage.mjs +2 -1
- package/tui/main.mjs +2 -1
- package/tui/lib/projection-env.mjs +0 -24
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import CorestoreStorage from 'hypercore-storage';
|
|
2
2
|
import HyperDB from 'hyperdb';
|
|
3
|
-
import type { LocalAccountRecovery, LocalAppConfig, LocalCapabilityProfile, LocalChatNotify, LocalCustomModel, LocalIdentity, LocalMemberProof, LocalMeshDeparture, LocalMeshMembership, LocalModelDownload, LocalModelNotify } from '../../../spec/local/hyperschema/types.d.ts';
|
|
3
|
+
import type { LocalAccountRecovery, LocalAppConfig, LocalCapabilityProfile, LocalChatNotify, LocalChatOrder, LocalCustomModel, LocalIdentity, LocalMemberProof, LocalMeshDeparture, LocalMeshMembership, LocalModelDownload, LocalModelNotify } from '../../../spec/local/hyperschema/types.d.ts';
|
|
4
4
|
import type { DeviceMetadata } from '../mesh.ts';
|
|
5
|
+
import { LocalFiles } from './files.ts';
|
|
5
6
|
export interface ResolvedSession {
|
|
6
7
|
readonly seed: Buffer;
|
|
7
8
|
readonly baseKey: Buffer | undefined;
|
|
@@ -12,6 +13,7 @@ export declare function openLocalStore(storage: CorestoreStorage): LocalStore;
|
|
|
12
13
|
declare class LocalStore {
|
|
13
14
|
private readonly _db;
|
|
14
15
|
private readonly _writeLock;
|
|
16
|
+
readonly files: LocalFiles;
|
|
15
17
|
constructor(db: HyperDB);
|
|
16
18
|
private _locked;
|
|
17
19
|
get(key: string): Promise<unknown>;
|
|
@@ -27,6 +29,19 @@ declare class LocalStore {
|
|
|
27
29
|
getChatNotify(chatId: string): Promise<LocalChatNotify | null>;
|
|
28
30
|
ackChatNotify(chatId: string, seq: number): Promise<void>;
|
|
29
31
|
clearChatNotify(chatId: string): Promise<void>;
|
|
32
|
+
writeChatOrder(meshKey: Buffer, rows: ReadonlyArray<{
|
|
33
|
+
chatId: string;
|
|
34
|
+
sortKey: Buffer;
|
|
35
|
+
}>, gone?: ReadonlyArray<string>): Promise<void>;
|
|
36
|
+
listChatOrder(meshKey: Buffer, { limit, before }?: {
|
|
37
|
+
limit?: number;
|
|
38
|
+
before?: {
|
|
39
|
+
sortKey: Buffer;
|
|
40
|
+
chatId: string;
|
|
41
|
+
};
|
|
42
|
+
}): Promise<LocalChatOrder[]>;
|
|
43
|
+
private _dropChatOrder;
|
|
44
|
+
private _chatOrderIn;
|
|
30
45
|
beginModelTransfer(name: string, { transferred }?: {
|
|
31
46
|
transferred?: boolean;
|
|
32
47
|
}): Promise<LocalModelNotify>;
|
|
@@ -47,7 +62,7 @@ declare class LocalStore {
|
|
|
47
62
|
renameDevice(publicKey: Buffer, name: string): Promise<void>;
|
|
48
63
|
saveDeviceProfile(publicKey: Buffer, capabilityProfile: LocalCapabilityProfile, recommendedModelName: string, platform?: string): Promise<void>;
|
|
49
64
|
readIdentity(): Promise<LocalIdentity | null>;
|
|
50
|
-
saveDisplayName(displayName: string): Promise<LocalIdentity | null>;
|
|
65
|
+
saveDisplayName(displayName: string, displayNameAt?: number): Promise<LocalIdentity | null>;
|
|
51
66
|
readMemberProof(meshKey: Buffer): Promise<LocalMemberProof | null>;
|
|
52
67
|
recordMemberProof(link: LocalMemberProof): Promise<void>;
|
|
53
68
|
readAccountRecovery(meshKey: Buffer): Promise<LocalAccountRecovery | null>;
|
|
@@ -72,21 +87,22 @@ declare class LocalStore {
|
|
|
72
87
|
recordMesh(deviceId: Buffer, key: Buffer, session: ResolvedSession, { account }?: {
|
|
73
88
|
account?: boolean;
|
|
74
89
|
}): Promise<void>;
|
|
75
|
-
|
|
90
|
+
setAccountMesh(deviceId: Buffer, key: Buffer): Promise<void>;
|
|
76
91
|
recordDeparture(key: Buffer, opts: {
|
|
77
92
|
creator: boolean;
|
|
78
93
|
}): Promise<void>;
|
|
79
94
|
departures(): Promise<LocalMeshDeparture[]>;
|
|
80
95
|
deleteDeparture(key: Buffer): Promise<void>;
|
|
81
96
|
archiveMesh(key: Buffer): Promise<void>;
|
|
97
|
+
forgetMesh(key: Buffer): Promise<void>;
|
|
82
98
|
markMeshMigrated(key: Buffer, migratedAt: number): Promise<void>;
|
|
83
|
-
|
|
99
|
+
adoptAccountMesh(deviceId: Buffer, key: Buffer, { account }: {
|
|
84
100
|
account?: Buffer | null;
|
|
85
101
|
}): Promise<void>;
|
|
86
102
|
private _pointersAt;
|
|
87
103
|
listMeshes(): Promise<LocalMeshMembership[]>;
|
|
88
104
|
listArchivedMeshes(): Promise<LocalMeshMembership[]>;
|
|
89
|
-
|
|
105
|
+
accountMesh(deviceId: Buffer): Promise<LocalMeshMembership | null>;
|
|
90
106
|
readMeshSession(key: Buffer): Promise<ResolvedSession | null>;
|
|
91
107
|
watch(listener: () => void): void;
|
|
92
108
|
unwatch(listener: () => void): void;
|
|
@@ -5,6 +5,10 @@ import ScopeLock from 'scope-lock';
|
|
|
5
5
|
import { MAX_DEVICE_NAME_CHARS, deviceNameWithinBounds } from '../../../schema/qvac.js';
|
|
6
6
|
import { generateMnemonic, mintIdentity } from '../identity.js';
|
|
7
7
|
import LocalDatabaseSpec from '../../../spec/local/hyperdb/index.js';
|
|
8
|
+
import b4a from 'b4a';
|
|
9
|
+
import { dropMeshFiles, LocalFiles } from './files.js';
|
|
10
|
+
const CHAT_ORDER = '@local/chat-order';
|
|
11
|
+
const CHAT_ORDER_BY_KEY = '@local/chat-order-by-key';
|
|
8
12
|
const CONFIG = '@local/config';
|
|
9
13
|
const ACTIVE_MESH = '@local/active-mesh';
|
|
10
14
|
const MESH_MEMBERSHIP = '@local/mesh-membership';
|
|
@@ -25,7 +29,7 @@ const CHAT_NOTIFY = '@local/chat-notify';
|
|
|
25
29
|
const MODEL_NOTIFY = '@local/model-notify';
|
|
26
30
|
const APP_CONFIG_ID = 'default';
|
|
27
31
|
function freshWriterSeed() {
|
|
28
|
-
return `local-${crypto.randomBytes(8)
|
|
32
|
+
return `local-${b4a.toHex(crypto.randomBytes(8))}`;
|
|
29
33
|
}
|
|
30
34
|
function sessionOf(row) {
|
|
31
35
|
return {
|
|
@@ -42,8 +46,10 @@ export function openLocalStore(storage) {
|
|
|
42
46
|
class LocalStore {
|
|
43
47
|
_db;
|
|
44
48
|
_writeLock = new ScopeLock();
|
|
49
|
+
files;
|
|
45
50
|
constructor(db) {
|
|
46
51
|
this._db = db;
|
|
52
|
+
this.files = new LocalFiles(db, (fn) => this._locked(fn));
|
|
47
53
|
}
|
|
48
54
|
async _locked(fn) {
|
|
49
55
|
await this._writeLock.lock();
|
|
@@ -125,6 +131,41 @@ class LocalStore {
|
|
|
125
131
|
await tx.flush();
|
|
126
132
|
});
|
|
127
133
|
}
|
|
134
|
+
writeChatOrder(meshKey, rows, gone = []) {
|
|
135
|
+
return this._locked(async () => {
|
|
136
|
+
const tx = this._db.transaction();
|
|
137
|
+
for (const row of rows) {
|
|
138
|
+
await tx.insert(CHAT_ORDER, { meshKey, ...row });
|
|
139
|
+
}
|
|
140
|
+
for (const chatId of gone)
|
|
141
|
+
await tx.delete(CHAT_ORDER, { meshKey, chatId });
|
|
142
|
+
await tx.flush();
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
listChatOrder(meshKey, { limit, before } = {}) {
|
|
146
|
+
return this._db
|
|
147
|
+
.find(CHAT_ORDER_BY_KEY, {
|
|
148
|
+
gte: { meshKey },
|
|
149
|
+
lt: before === undefined ? undefined : { meshKey, ...before },
|
|
150
|
+
lte: before === undefined ? { meshKey } : undefined,
|
|
151
|
+
reverse: true,
|
|
152
|
+
limit
|
|
153
|
+
})
|
|
154
|
+
.toArray();
|
|
155
|
+
}
|
|
156
|
+
async _dropChatOrder(tx, meshKey) {
|
|
157
|
+
for (const order of await this._chatOrderIn(tx, meshKey)) {
|
|
158
|
+
await tx.delete(CHAT_ORDER, { meshKey, chatId: order.chatId });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
_chatOrderIn(db, meshKey) {
|
|
162
|
+
return db
|
|
163
|
+
.find(CHAT_ORDER_BY_KEY, {
|
|
164
|
+
gte: { meshKey },
|
|
165
|
+
lte: { meshKey }
|
|
166
|
+
})
|
|
167
|
+
.toArray();
|
|
168
|
+
}
|
|
128
169
|
beginModelTransfer(name, { transferred = false } = {}) {
|
|
129
170
|
return this._locked(async () => {
|
|
130
171
|
const current = await this._db.get(MODEL_NOTIFY, { name });
|
|
@@ -133,7 +174,7 @@ class LocalStore {
|
|
|
133
174
|
return current;
|
|
134
175
|
const next = {
|
|
135
176
|
name,
|
|
136
|
-
transferId: pending ? current.transferId : crypto.randomBytes(16)
|
|
177
|
+
transferId: pending ? current.transferId : b4a.toHex(crypto.randomBytes(16)),
|
|
137
178
|
notificationId: current?.notificationId,
|
|
138
179
|
completedAt: current?.completedAt,
|
|
139
180
|
acknowledged: current?.acknowledged,
|
|
@@ -278,7 +319,7 @@ class LocalStore {
|
|
|
278
319
|
readIdentity() {
|
|
279
320
|
return this._db.get(IDENTITY, { id: IDENTITY_ID });
|
|
280
321
|
}
|
|
281
|
-
saveDisplayName(displayName) {
|
|
322
|
+
saveDisplayName(displayName, displayNameAt = Date.now()) {
|
|
282
323
|
return this._locked(async () => {
|
|
283
324
|
const tx = this._db.transaction();
|
|
284
325
|
const existing = await tx.get(IDENTITY, { id: IDENTITY_ID });
|
|
@@ -286,7 +327,7 @@ class LocalStore {
|
|
|
286
327
|
await tx.close();
|
|
287
328
|
return null;
|
|
288
329
|
}
|
|
289
|
-
const identity = { ...existing, displayName };
|
|
330
|
+
const identity = { ...existing, displayName, displayNameAt };
|
|
290
331
|
await tx.insert(IDENTITY, identity);
|
|
291
332
|
await tx.flush();
|
|
292
333
|
return identity;
|
|
@@ -322,6 +363,7 @@ class LocalStore {
|
|
|
322
363
|
await tx.insert(IDENTITY, {
|
|
323
364
|
id: IDENTITY_ID,
|
|
324
365
|
displayName: existing?.displayName ?? null,
|
|
366
|
+
displayNameAt: existing?.displayNameAt,
|
|
325
367
|
...identity
|
|
326
368
|
});
|
|
327
369
|
await tx.flush();
|
|
@@ -348,8 +390,9 @@ class LocalStore {
|
|
|
348
390
|
}
|
|
349
391
|
async resolveSession(deviceId, opts = {}) {
|
|
350
392
|
const current = await this._activeMembership(deviceId);
|
|
351
|
-
const
|
|
352
|
-
|
|
393
|
+
const named = opts.baseKey ? await this._membership(opts.baseKey) : null;
|
|
394
|
+
const resumed = [current, named].find((row) => row && opts.seed?.equals(row.seed)) ?? null;
|
|
395
|
+
if (opts.seed && !resumed) {
|
|
353
396
|
return {
|
|
354
397
|
seed: opts.seed,
|
|
355
398
|
baseKey: opts.baseKey,
|
|
@@ -357,8 +400,9 @@ class LocalStore {
|
|
|
357
400
|
compute: opts.compute ?? false
|
|
358
401
|
};
|
|
359
402
|
}
|
|
360
|
-
|
|
361
|
-
|
|
403
|
+
const session = resumed ?? current;
|
|
404
|
+
if (session && !opts.new)
|
|
405
|
+
return sessionOf(session);
|
|
362
406
|
return {
|
|
363
407
|
seed: crypto.randomBytes(32),
|
|
364
408
|
baseKey: undefined,
|
|
@@ -378,8 +422,7 @@ class LocalStore {
|
|
|
378
422
|
const pointer = await this._db.get(ACTIVE_MESH, { deviceId });
|
|
379
423
|
if (!pointer)
|
|
380
424
|
return this._migrateLegacySession(deviceId);
|
|
381
|
-
return
|
|
382
|
-
(await this._membership(pointer.homeMeshKey)));
|
|
425
|
+
return this._membership(pointer.homeMeshKey);
|
|
383
426
|
}
|
|
384
427
|
async _membership(key) {
|
|
385
428
|
if (!key)
|
|
@@ -397,11 +440,7 @@ class LocalStore {
|
|
|
397
440
|
return legacy;
|
|
398
441
|
const tx = this._db.transaction();
|
|
399
442
|
await tx.insert(MESH_MEMBERSHIP, { ...legacy, key });
|
|
400
|
-
await tx.insert(ACTIVE_MESH, {
|
|
401
|
-
deviceId,
|
|
402
|
-
activeMeshKey: key,
|
|
403
|
-
homeMeshKey: key
|
|
404
|
-
});
|
|
443
|
+
await tx.insert(ACTIVE_MESH, { deviceId, homeMeshKey: key });
|
|
405
444
|
const shipped = await tx.get(MEMBERSHIP, { id: MEMBERSHIP_ID });
|
|
406
445
|
if (shipped) {
|
|
407
446
|
const { memberId, proof, attestedAt } = shipped;
|
|
@@ -430,7 +469,6 @@ class LocalStore {
|
|
|
430
469
|
return this._locked(async () => {
|
|
431
470
|
const existing = await this._db.get(MESH_MEMBERSHIP, { key });
|
|
432
471
|
const minted = account && !existing && session.baseKey === undefined;
|
|
433
|
-
const pointer = minted ? await this._db.get(ACTIVE_MESH, { deviceId }) : null;
|
|
434
472
|
const tx = this._db.transaction();
|
|
435
473
|
await tx.insert(MESH_MEMBERSHIP, {
|
|
436
474
|
key,
|
|
@@ -439,24 +477,15 @@ class LocalStore {
|
|
|
439
477
|
compute: session.compute
|
|
440
478
|
});
|
|
441
479
|
if (minted) {
|
|
442
|
-
await tx.insert(ACTIVE_MESH, {
|
|
443
|
-
deviceId,
|
|
444
|
-
activeMeshKey: pointer?.activeMeshKey,
|
|
445
|
-
homeMeshKey: key
|
|
446
|
-
});
|
|
480
|
+
await tx.insert(ACTIVE_MESH, { deviceId, homeMeshKey: key });
|
|
447
481
|
}
|
|
448
482
|
await tx.flush();
|
|
449
483
|
});
|
|
450
484
|
}
|
|
451
|
-
|
|
485
|
+
setAccountMesh(deviceId, key) {
|
|
452
486
|
return this._locked(async () => {
|
|
453
|
-
const pointer = await this._db.get(ACTIVE_MESH, { deviceId });
|
|
454
487
|
const tx = this._db.transaction();
|
|
455
|
-
await tx.insert(ACTIVE_MESH, {
|
|
456
|
-
deviceId,
|
|
457
|
-
activeMeshKey: key,
|
|
458
|
-
homeMeshKey: pointer?.homeMeshKey
|
|
459
|
-
});
|
|
488
|
+
await tx.insert(ACTIVE_MESH, { deviceId, homeMeshKey: key });
|
|
460
489
|
await tx.flush();
|
|
461
490
|
});
|
|
462
491
|
}
|
|
@@ -504,6 +533,16 @@ class LocalStore {
|
|
|
504
533
|
}
|
|
505
534
|
for (const pointer of cleared)
|
|
506
535
|
await tx.insert(ACTIVE_MESH, pointer);
|
|
536
|
+
await this._dropChatOrder(tx, key);
|
|
537
|
+
await dropMeshFiles(tx, key);
|
|
538
|
+
await tx.flush();
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
forgetMesh(key) {
|
|
542
|
+
return this._locked(async () => {
|
|
543
|
+
const tx = this._db.transaction();
|
|
544
|
+
await this._dropChatOrder(tx, key);
|
|
545
|
+
await dropMeshFiles(tx, key);
|
|
507
546
|
await tx.flush();
|
|
508
547
|
});
|
|
509
548
|
}
|
|
@@ -517,25 +556,22 @@ class LocalStore {
|
|
|
517
556
|
await tx.flush();
|
|
518
557
|
});
|
|
519
558
|
}
|
|
520
|
-
|
|
559
|
+
adoptAccountMesh(deviceId, key, { account }) {
|
|
521
560
|
return this._locked(async () => {
|
|
522
561
|
const departed = [];
|
|
523
562
|
for await (const row of this._db.find(MESH_MEMBERSHIP)) {
|
|
524
563
|
if (!row.key.equals(key) && !row.leftAt)
|
|
525
564
|
departed.push(row);
|
|
526
565
|
}
|
|
527
|
-
const pointer = await this._db.get(ACTIVE_MESH, { deviceId });
|
|
528
566
|
const leftAt = Date.now();
|
|
529
567
|
const tx = this._db.transaction();
|
|
530
568
|
for (const row of departed) {
|
|
531
569
|
const wasHome = !!account?.equals(row.key);
|
|
532
570
|
await tx.insert(MESH_MEMBERSHIP, { ...row, leftAt, wasHome });
|
|
571
|
+
await this._dropChatOrder(tx, row.key);
|
|
572
|
+
await dropMeshFiles(tx, row.key);
|
|
533
573
|
}
|
|
534
|
-
await tx.insert(ACTIVE_MESH, {
|
|
535
|
-
deviceId,
|
|
536
|
-
activeMeshKey: pointer?.activeMeshKey,
|
|
537
|
-
homeMeshKey: key
|
|
538
|
-
});
|
|
574
|
+
await tx.insert(ACTIVE_MESH, { deviceId, homeMeshKey: key });
|
|
539
575
|
await tx.flush();
|
|
540
576
|
});
|
|
541
577
|
}
|
|
@@ -543,16 +579,10 @@ class LocalStore {
|
|
|
543
579
|
const cleared = [];
|
|
544
580
|
let home = false;
|
|
545
581
|
for await (const pointer of this._db.find(ACTIVE_MESH)) {
|
|
546
|
-
|
|
547
|
-
const aimed = pointer.homeMeshKey?.equals(key);
|
|
548
|
-
if (!active && !aimed)
|
|
582
|
+
if (!pointer.homeMeshKey?.equals(key))
|
|
549
583
|
continue;
|
|
550
|
-
home
|
|
551
|
-
cleared.push({
|
|
552
|
-
deviceId: pointer.deviceId,
|
|
553
|
-
activeMeshKey: active ? null : pointer.activeMeshKey,
|
|
554
|
-
homeMeshKey: aimed ? null : pointer.homeMeshKey
|
|
555
|
-
});
|
|
584
|
+
home = true;
|
|
585
|
+
cleared.push({ deviceId: pointer.deviceId, homeMeshKey: null });
|
|
556
586
|
}
|
|
557
587
|
return { cleared, home };
|
|
558
588
|
}
|
|
@@ -572,7 +602,7 @@ class LocalStore {
|
|
|
572
602
|
}
|
|
573
603
|
return rows;
|
|
574
604
|
}
|
|
575
|
-
async
|
|
605
|
+
async accountMesh(deviceId) {
|
|
576
606
|
const pointer = await this._db.get(ACTIVE_MESH, { deviceId });
|
|
577
607
|
return this._membership(pointer?.homeMeshKey);
|
|
578
608
|
}
|
|
@@ -18,7 +18,10 @@ export declare function attestUnattestedDevices(mesh: Mesh, { deviceKeyPair, log
|
|
|
18
18
|
export interface KnownMember {
|
|
19
19
|
readonly id: Buffer;
|
|
20
20
|
readonly name: string;
|
|
21
|
+
readonly updatedAt: number;
|
|
21
22
|
readonly proof: Buffer;
|
|
22
23
|
}
|
|
23
24
|
export declare function claimOwnMembership(mesh: Mesh, { deviceKeyPair, log }: MembershipContext, known: KnownMember): Promise<void>;
|
|
24
|
-
export declare function
|
|
25
|
+
export declare function namedAt(identity: Pick<LocalIdentity, 'displayNameAt'>): number;
|
|
26
|
+
export declare function legacyNameStamp(account: Mesh, { deviceKeyPair }: MembershipContext, identity: LocalIdentity): Promise<number | null>;
|
|
27
|
+
export declare function renameFoundedMember(mesh: Mesh, { deviceKeyPair, log }: MembershipContext, identity: LocalIdentity, adopt: (name: string, namedAt: number) => Promise<unknown>): Promise<void>;
|
|
@@ -62,7 +62,17 @@ export async function claimOwnMembership(mesh, { deviceKeyPair, log }, known) {
|
|
|
62
62
|
await mesh.refreshOurMember();
|
|
63
63
|
log?.info('membership', 'claimed our own member in a mesh a sibling device joined');
|
|
64
64
|
}
|
|
65
|
-
export
|
|
65
|
+
export function namedAt(identity) {
|
|
66
|
+
return identity.displayNameAt || 0;
|
|
67
|
+
}
|
|
68
|
+
export async function legacyNameStamp(account, { deviceKeyPair }, identity) {
|
|
69
|
+
const own = await account.view.get('@qvac/devices', { id: deviceKeyPair.publicKey });
|
|
70
|
+
if (!own?.memberId)
|
|
71
|
+
return null;
|
|
72
|
+
const member = await account.view.get('@qvac/members', { id: own.memberId });
|
|
73
|
+
return member && member.name === identity.displayName ? member.updatedAt : null;
|
|
74
|
+
}
|
|
75
|
+
export async function renameFoundedMember(mesh, { deviceKeyPair, log }, identity, adopt) {
|
|
66
76
|
if (!identity.displayName)
|
|
67
77
|
return;
|
|
68
78
|
const own = await mesh.view.get('@qvac/devices', { id: deviceKeyPair.publicKey });
|
|
@@ -71,8 +81,13 @@ export async function renameFoundedMember(mesh, { deviceKeyPair, log }, identity
|
|
|
71
81
|
const member = await mesh.view.get('@qvac/members', { id: own.memberId });
|
|
72
82
|
if (!member || member.name === identity.displayName)
|
|
73
83
|
return;
|
|
84
|
+
if (namedAt(identity) < member.updatedAt) {
|
|
85
|
+
await adopt(member.name, member.updatedAt);
|
|
86
|
+
log?.info('membership', 'another device of this member renamed it later, so this one follows');
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
74
89
|
await mesh.dispatch('update-member', {
|
|
75
|
-
member: { ...member, name: identity.displayName, updatedAt:
|
|
90
|
+
member: { ...member, name: identity.displayName, updatedAt: namedAt(identity) }
|
|
76
91
|
});
|
|
77
92
|
log?.info('membership', 'the member this device founded carries its user name');
|
|
78
93
|
}
|
|
@@ -11,6 +11,7 @@ import { Router } from '../../spec/mesh/hyperdispatch/index.js';
|
|
|
11
11
|
import type { QvacCapabilityProfile, QvacMember } from '../../spec/mesh/hyperschema/types.d.ts';
|
|
12
12
|
import type { BlindPeeringOpts } from './blind-peers.ts';
|
|
13
13
|
import type { AttachmentUrl } from './attachment-link.ts';
|
|
14
|
+
import type { MeshFileIndex } from './files/local-index.ts';
|
|
14
15
|
import { type DeviceAttestation } from './device-attestation.ts';
|
|
15
16
|
import { type SyncActivity } from './sync-status.ts';
|
|
16
17
|
export interface MeshView {
|
|
@@ -38,6 +39,7 @@ export interface MeshOptions {
|
|
|
38
39
|
bootFrom?: AutobeeOplogRef | null;
|
|
39
40
|
wakeup?: Wakeup;
|
|
40
41
|
attachmentUrl?: AttachmentUrl | null;
|
|
42
|
+
fileIndex?: MeshFileIndex | null;
|
|
41
43
|
}
|
|
42
44
|
export declare function isOurTrustedWriter(snap: HyperDB, writerKey: Buffer, ourMemberId: Buffer | null): Promise<boolean>;
|
|
43
45
|
export type BirthRow = {
|
|
@@ -79,6 +81,7 @@ export declare class Mesh extends ReadyResource {
|
|
|
79
81
|
private readonly _bootFrom;
|
|
80
82
|
private readonly _wakeup;
|
|
81
83
|
readonly attachmentUrl: AttachmentUrl | null;
|
|
84
|
+
readonly fileIndex: MeshFileIndex | null;
|
|
82
85
|
private readonly _scope;
|
|
83
86
|
readonly router: Router;
|
|
84
87
|
private readonly _keyPair;
|
|
@@ -142,6 +145,8 @@ export declare class Mesh extends ReadyResource {
|
|
|
142
145
|
pendingUploads(): number;
|
|
143
146
|
suspend(): Promise<void>;
|
|
144
147
|
resume(): Promise<void>;
|
|
148
|
+
syncChatOrder: ((chatIds: Set<string>) => Promise<void>) | null;
|
|
149
|
+
chatOrderBuilt: Promise<void>;
|
|
145
150
|
watch(listener: () => void): void;
|
|
146
151
|
unwatch(listener: () => void): void;
|
|
147
152
|
_autobeeIsTrusted(key: Buffer, reference: MeshView): Promise<boolean>;
|
|
@@ -19,6 +19,7 @@ import { assertComputeRoute } from './contract/compute.js';
|
|
|
19
19
|
import { registerRoutes } from './contract/index.js';
|
|
20
20
|
import { createSyncActivity } from './sync-status.js';
|
|
21
21
|
import { buildHealthAssistant } from './health-assistant.js';
|
|
22
|
+
import b4a from 'b4a';
|
|
22
23
|
const [MESH_KEYPAIR, MESH_ENCRYPTION, MESH_DEVICE] = crypto.namespace('qvac-assistant/mesh', 3);
|
|
23
24
|
const LIVE_WRITERS_BY_MOST_RECENT = '@qvac/live-writers-by-most-recent';
|
|
24
25
|
const WARMUP_COLLECTIONS = [
|
|
@@ -61,6 +62,7 @@ export class Mesh extends ReadyResource {
|
|
|
61
62
|
_bootFrom;
|
|
62
63
|
_wakeup;
|
|
63
64
|
attachmentUrl;
|
|
65
|
+
fileIndex;
|
|
64
66
|
_scope;
|
|
65
67
|
router;
|
|
66
68
|
_keyPair;
|
|
@@ -111,7 +113,7 @@ export class Mesh extends ReadyResource {
|
|
|
111
113
|
if (!peering?.blindPeers)
|
|
112
114
|
return [];
|
|
113
115
|
return [...peering.blindPeers.values()].map((bp) => ({
|
|
114
|
-
key: bp.remotePublicKey
|
|
116
|
+
key: b4a.toHex(bp.remotePublicKey).slice(0, 16),
|
|
115
117
|
connected: bp.connected,
|
|
116
118
|
connects: bp.connects,
|
|
117
119
|
uploaded: bp.uploaded
|
|
@@ -182,12 +184,13 @@ export class Mesh extends ReadyResource {
|
|
|
182
184
|
this._deviceId = opts.deviceId ?? null;
|
|
183
185
|
this._wakeup = opts.wakeup;
|
|
184
186
|
this.attachmentUrl = opts.attachmentUrl ?? null;
|
|
187
|
+
this.fileIndex = opts.fileIndex ?? null;
|
|
185
188
|
this.router = new Router();
|
|
186
189
|
this._keyPair = crypto.keyPair(crypto.hash([MESH_KEYPAIR, this._seed]));
|
|
187
190
|
this._deviceKeyPair = crypto.keyPair(crypto.hash([MESH_DEVICE, this._seed]));
|
|
188
191
|
this._encryptionKey = crypto.hash([MESH_ENCRYPTION, this._seed]);
|
|
189
192
|
this.discoveryKey = crypto.discoveryKey(this._keyPair.publicKey);
|
|
190
|
-
this._scope = ['p2p', 'mesh', this._keyPair.publicKey
|
|
193
|
+
this._scope = ['p2p', 'mesh', b4a.toHex(this._keyPair.publicKey).slice(0, 8)];
|
|
191
194
|
registerRoutes(this.router, { compute: this._compute });
|
|
192
195
|
}
|
|
193
196
|
async _open() {
|
|
@@ -243,7 +246,7 @@ export class Mesh extends ReadyResource {
|
|
|
243
246
|
this.files.start({ deviceId: this._deviceId });
|
|
244
247
|
}
|
|
245
248
|
startBlindPeering(dht) {
|
|
246
|
-
if (this.closing || !this.autobee || !this.blobs)
|
|
249
|
+
if (this.closing || this._blindPeering || !this.autobee || !this.blobs)
|
|
247
250
|
return;
|
|
248
251
|
this._blindPeering = new BlindPeering(dht, this._store, {
|
|
249
252
|
pick: 2,
|
|
@@ -407,6 +410,8 @@ export class Mesh extends ReadyResource {
|
|
|
407
410
|
await this._blindPeering.resume();
|
|
408
411
|
this._files?.resume();
|
|
409
412
|
}
|
|
413
|
+
syncChatOrder = null;
|
|
414
|
+
chatOrderBuilt = Promise.resolve();
|
|
410
415
|
watch(listener) {
|
|
411
416
|
this.view.watch(listener);
|
|
412
417
|
}
|
|
@@ -421,7 +426,7 @@ export class Mesh extends ReadyResource {
|
|
|
421
426
|
const trusted = await isOurTrustedWriter(snap, key, this._ourMemberId);
|
|
422
427
|
if (!trusted) {
|
|
423
428
|
this._log?.debug(this._scope, 'writer is no device of ours', {
|
|
424
|
-
writerKey:
|
|
429
|
+
writerKey: b4a.toHex(key).slice(0, 16)
|
|
425
430
|
});
|
|
426
431
|
}
|
|
427
432
|
return trusted;
|
|
@@ -440,7 +445,7 @@ export class Mesh extends ReadyResource {
|
|
|
440
445
|
})) {
|
|
441
446
|
if (await isOurTrustedWriter(snap, writer.writerKey, this._ourMemberId)) {
|
|
442
447
|
this._log?.debug(this._scope, 'vouching for a head', {
|
|
443
|
-
writerKey: writer.writerKey
|
|
448
|
+
writerKey: b4a.toHex(writer.writerKey).slice(0, 16),
|
|
444
449
|
length: writer.length
|
|
445
450
|
});
|
|
446
451
|
return { key: writer.writerKey, length: writer.length };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const ACTIVE_AGENTS = '@qvac/active-agents';
|
|
2
|
+
const AGENTS_BY_PROVIDER = '@qvac/agents-by-provider';
|
|
3
|
+
export async function reindexAgents(mesh) {
|
|
4
|
+
if (!mesh.writable)
|
|
5
|
+
return false;
|
|
6
|
+
const missing = await unindexedAgentIds(mesh);
|
|
7
|
+
if (missing.length === 0)
|
|
8
|
+
return false;
|
|
9
|
+
await mesh.dispatch('reindex-agents', { agentIds: missing });
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
async function unindexedAgentIds(mesh) {
|
|
13
|
+
const snap = mesh.view.snapshot();
|
|
14
|
+
try {
|
|
15
|
+
const indexed = new Set();
|
|
16
|
+
for await (const agent of snap.find(AGENTS_BY_PROVIDER)) {
|
|
17
|
+
indexed.add(agent.id);
|
|
18
|
+
}
|
|
19
|
+
const missing = [];
|
|
20
|
+
for await (const agent of snap.find(ACTIVE_AGENTS)) {
|
|
21
|
+
if (!indexed.has(agent.id)) {
|
|
22
|
+
missing.push(agent.id);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return missing;
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
await snap.close();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const CHUNKS = '@qvac/chunks';
|
|
2
|
+
const BATCH = 256;
|
|
3
|
+
export async function backfillFileIndex(mesh) {
|
|
4
|
+
const index = mesh.fileIndex;
|
|
5
|
+
if (!index)
|
|
6
|
+
return;
|
|
7
|
+
const snapshot = mesh.view.snapshot();
|
|
8
|
+
try {
|
|
9
|
+
let batch = [];
|
|
10
|
+
for await (const chunk of snapshot.find(CHUNKS)) {
|
|
11
|
+
if (mesh.closing)
|
|
12
|
+
return;
|
|
13
|
+
if (chunk.type !== 'attachment')
|
|
14
|
+
continue;
|
|
15
|
+
batch.push(chunk);
|
|
16
|
+
if (batch.length < BATCH)
|
|
17
|
+
continue;
|
|
18
|
+
await index.record(batch);
|
|
19
|
+
batch = [];
|
|
20
|
+
}
|
|
21
|
+
if (batch.length > 0)
|
|
22
|
+
await index.record(batch);
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
await snapshot.close();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { migrateAgentCatalog } from './agent-catalog.js';
|
|
2
2
|
import { migrateMembership } from './membership.js';
|
|
3
3
|
import { sealDeviceRows } from './seal.js';
|
|
4
|
+
import { reindexAgents } from './agent-indexes.js';
|
|
4
5
|
export async function runMigrations(mesh, context, { catalog = true } = {}) {
|
|
5
6
|
const membership = await migrateMembership(mesh, context);
|
|
6
7
|
const agents = catalog && (await migrateAgentCatalog(mesh, context));
|
|
7
8
|
const seal = await sealDeviceRows(mesh, context);
|
|
8
|
-
|
|
9
|
+
const indexed = await reindexAgents(mesh);
|
|
10
|
+
return membership || agents || seal || indexed;
|
|
9
11
|
}
|
|
@@ -18,11 +18,11 @@ export async function deriveNotifications(mesh, local, requestedLimit, deviceId)
|
|
|
18
18
|
const [statuses, approvals, messages] = await Promise.all([
|
|
19
19
|
(counter?.count ?? 0) <= ackedThrough
|
|
20
20
|
? []
|
|
21
|
-
: findChunksOfType(snap, chat.id, 'run-status', {
|
|
21
|
+
: findChunksOfType(snap, chat.id, 'run-status', { gte: ackedThrough }),
|
|
22
22
|
findChunksOfType(snap, chat.id, 'approval-request'),
|
|
23
23
|
(counter?.count ?? 0) <= ackedThrough
|
|
24
24
|
? []
|
|
25
|
-
: findChunksOfType(snap, chat.id, 'user-message', {
|
|
25
|
+
: findChunksOfType(snap, chat.id, 'user-message', { gte: ackedThrough })
|
|
26
26
|
]);
|
|
27
27
|
const terminalStatuses = statuses.filter((chunk) => {
|
|
28
28
|
const state = chunk.runStatus?.state;
|
|
@@ -111,7 +111,7 @@ export async function deriveNotifications(mesh, local, requestedLimit, deviceId)
|
|
|
111
111
|
}
|
|
112
112
|
const contentByChat = new Map();
|
|
113
113
|
for (const [chatId, terminalSeq] of terminalSeqByChat) {
|
|
114
|
-
contentByChat.set(chatId, await findChunksOfType(snap, chatId, 'content', {
|
|
114
|
+
contentByChat.set(chatId, await findChunksOfType(snap, chatId, 'content', { lte: terminalSeq }));
|
|
115
115
|
}
|
|
116
116
|
const agentNameById = new Map();
|
|
117
117
|
for (const agentId of new Set(selected.map((candidate) => candidate.agentId))) {
|
|
@@ -138,8 +138,8 @@ export async function deriveNotifications(mesh, local, requestedLimit, deviceId)
|
|
|
138
138
|
}
|
|
139
139
|
async function diagramRepairRunIds(snap, chatId, toSeq) {
|
|
140
140
|
const [users, requests] = await Promise.all([
|
|
141
|
-
findChunksOfType(snap, chatId, 'user-message', { toSeq }),
|
|
142
|
-
findChunksOfType(snap, chatId, 'run-request', { toSeq })
|
|
141
|
+
findChunksOfType(snap, chatId, 'user-message', { lte: toSeq }),
|
|
142
|
+
findChunksOfType(snap, chatId, 'run-request', { lte: toSeq })
|
|
143
143
|
]);
|
|
144
144
|
const records = [...users, ...requests];
|
|
145
145
|
const repairs = diagramRepairLinks(records, (chunk) => chunk.userMessage?.text ?? null);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type Bounds = {
|
|
2
|
+
gt?: number;
|
|
3
|
+
gte?: number;
|
|
4
|
+
lt?: number;
|
|
5
|
+
lte?: number;
|
|
6
|
+
reverse?: boolean;
|
|
7
|
+
limit?: number;
|
|
8
|
+
};
|
|
9
|
+
type Range<Key> = {
|
|
10
|
+
gt?: Key;
|
|
11
|
+
gte?: Key;
|
|
12
|
+
lt?: Key;
|
|
13
|
+
lte?: Key;
|
|
14
|
+
reverse?: boolean;
|
|
15
|
+
limit?: number;
|
|
16
|
+
};
|
|
17
|
+
export declare function keyRange<Key extends object>(prefix: Partial<Key>, field: keyof Key & string, { gt, gte, lt, lte, reverse, limit }?: Bounds): Range<Partial<Key>>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export function keyRange(prefix, field, { gt, gte, lt, lte, reverse, limit } = {}) {
|
|
2
|
+
const at = (value) => ({ ...prefix, [field]: value });
|
|
3
|
+
const range = { reverse: reverse === true, limit: limit || undefined };
|
|
4
|
+
if (gt !== undefined)
|
|
5
|
+
range.gt = at(gt);
|
|
6
|
+
if (gte !== undefined)
|
|
7
|
+
range.gte = at(gte);
|
|
8
|
+
if (lt !== undefined)
|
|
9
|
+
range.lt = at(lt);
|
|
10
|
+
if (lte !== undefined)
|
|
11
|
+
range.lte = at(lte);
|
|
12
|
+
if (range.gt === undefined && range.gte === undefined)
|
|
13
|
+
range.gte = { ...prefix };
|
|
14
|
+
if (range.lt === undefined && range.lte === undefined)
|
|
15
|
+
range.lte = { ...prefix };
|
|
16
|
+
return range;
|
|
17
|
+
}
|