@qvac/core 0.11.0 → 0.11.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 +80 -1
- package/dist-lib/index.d.ts +1 -0
- package/dist-lib/index.js +1 -0
- package/dist-lib/lib/api/chunk-delta.d.ts +6 -2
- package/dist-lib/lib/api/chunk-delta.js +69 -7
- package/dist-lib/lib/api/chunks.js +6 -2
- package/dist-lib/lib/api/config.d.ts +4 -1
- package/dist-lib/lib/api/config.js +23 -4
- package/dist-lib/lib/api/devices.js +3 -1
- package/dist-lib/lib/api/rag.js +4 -2
- package/dist-lib/lib/assistant/harness.d.ts +3 -1
- package/dist-lib/lib/assistant/harness.js +10 -0
- package/dist-lib/lib/assistant/history.js +25 -3
- package/dist-lib/lib/assistant/message.js +2 -2
- package/dist-lib/lib/assistant-tree.js +1 -1
- package/dist-lib/lib/assistant.d.ts +1 -0
- package/dist-lib/lib/assistant.js +14 -4
- package/dist-lib/lib/client.js +10 -1
- package/dist-lib/lib/core/archived-mesh.js +1 -0
- package/dist-lib/lib/core/chunk.d.ts +5 -2
- package/dist-lib/lib/core/chunk.js +74 -18
- package/dist-lib/lib/core/collections.d.ts +1 -0
- package/dist-lib/lib/core/collections.js +1 -0
- package/dist-lib/lib/core/config-value.d.ts +6 -0
- package/dist-lib/lib/core/config-value.js +14 -0
- package/dist-lib/lib/core/contract/chat.d.ts +1 -0
- package/dist-lib/lib/core/contract/chat.js +8 -1
- package/dist-lib/lib/core/contract/chunks.js +20 -6
- package/dist-lib/lib/core/contract/compute.d.ts +1 -1
- package/dist-lib/lib/core/contract/compute.js +2 -1
- package/dist-lib/lib/core/contract/devices.js +3 -2
- package/dist-lib/lib/core/departures.js +1 -0
- package/dist-lib/lib/core/devices.d.ts +2 -1
- package/dist-lib/lib/core/devices.js +4 -2
- package/dist-lib/lib/core/files/index.d.ts +1 -1
- package/dist-lib/lib/core/files/index.js +1 -1
- package/dist-lib/lib/core/files/rag/index.d.ts +1 -1
- package/dist-lib/lib/core/files/rag/index.js +1 -1
- package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +4 -1
- package/dist-lib/lib/core/inference-calls-receiver.js +2 -2
- package/dist-lib/lib/core/known-sender.d.ts +3 -0
- package/dist-lib/lib/core/known-sender.js +26 -0
- package/dist-lib/lib/core/local/index.d.ts +2 -0
- package/dist-lib/lib/core/local/index.js +17 -10
- package/dist-lib/lib/core/mesh.d.ts +5 -1
- package/dist-lib/lib/core/mesh.js +6 -6
- package/dist-lib/lib/core/migrations/chat-chunks.d.ts +4 -0
- package/dist-lib/lib/core/migrations/chat-chunks.js +43 -0
- package/dist-lib/lib/core/skill-overlay-receiver.js +2 -2
- package/dist-lib/lib/core/skill-secrets.js +2 -2
- package/dist-lib/lib/core.d.ts +11 -1
- package/dist-lib/lib/core.js +50 -5
- package/dist-lib/lib/device-tree.d.ts +18 -0
- package/dist-lib/lib/device-tree.js +32 -0
- package/dist-lib/schema/engine.js +20 -3
- package/dist-lib/schema/field-order.js +8 -1
- package/dist-lib/schema/local.js +7 -3
- package/dist-lib/schema/qvac.js +19 -2
- package/dist-lib/spec/hrpc/messages.js +1236 -1184
- package/dist-lib/spec/hyperschema/index.js +1236 -1184
- package/dist-lib/spec/hyperschema/schema.json +47 -0
- package/dist-lib/spec/hyperschema/types.d.ts +11 -0
- package/dist-lib/spec/local/hyperdb/messages.js +70 -20
- package/dist-lib/spec/local/hyperschema/index.js +36 -11
- package/dist-lib/spec/local/hyperschema/schema.json +21 -1
- package/dist-lib/spec/local/hyperschema/types.d.ts +5 -1
- package/dist-lib/spec/mesh/hyperdb/db.json +17 -1
- package/dist-lib/spec/mesh/hyperdb/index.js +83 -2
- package/dist-lib/spec/mesh/hyperdb/messages.js +573 -255
- 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 +121 -8
- package/dist-lib/spec/mesh/hyperschema/index.js +121 -8
- package/dist-lib/spec/mesh/hyperschema/schema.json +69 -1
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +19 -1
- package/package.json +9 -8
|
@@ -7,7 +7,8 @@ import { linkAttachment } from './attachment-link.js';
|
|
|
7
7
|
import { randomId } from './id.js';
|
|
8
8
|
import { keyRange } from './range.js';
|
|
9
9
|
import b4a from 'b4a';
|
|
10
|
-
import { AGENTS, ATTACHMENTS_BY_MEDIA_KIND, ATTACHMENTS_BY_MEDIA_KIND_ORIGIN, CHUNKS, CHUNKS_BY_CHAT, CHUNKS_BY_TYPE, HISTORY_CHUNKS, RUN_REQUESTS } from './collections.js';
|
|
10
|
+
import { AGENTS, ATTACHMENTS_BY_MEDIA_KIND, ATTACHMENTS_BY_MEDIA_KIND_ORIGIN, CHAT_CHUNKS, CHUNKS, CHUNKS_BY_CHAT, CHUNKS_BY_TYPE, CHUNK_COUNTERS, HISTORY_CHUNKS, RUN_REQUESTS } from './collections.js';
|
|
11
|
+
const TERMINAL_RUN_STATES = new Set(['completed', 'failed', 'canceled']);
|
|
11
12
|
export const HISTORY_CHUNK_TYPES = [
|
|
12
13
|
'user-message',
|
|
13
14
|
'run-request',
|
|
@@ -15,7 +16,7 @@ export const HISTORY_CHUNK_TYPES = [
|
|
|
15
16
|
'attachment',
|
|
16
17
|
'compaction'
|
|
17
18
|
];
|
|
18
|
-
function linkChunks(store, chunks) {
|
|
19
|
+
export function linkChunks(store, chunks) {
|
|
19
20
|
const mint = store.attachmentUrl;
|
|
20
21
|
if (!mint) {
|
|
21
22
|
return chunks;
|
|
@@ -32,7 +33,16 @@ export function findChunksOfType(snap, { chatId, type, ...bounds }) {
|
|
|
32
33
|
.find(CHUNKS_BY_TYPE, keyRange(prefix, 'seq', bounds))
|
|
33
34
|
.toArray();
|
|
34
35
|
}
|
|
35
|
-
export async function listChunks(store,
|
|
36
|
+
export async function listChunks(store, input) {
|
|
37
|
+
const snap = store.view.snapshot();
|
|
38
|
+
try {
|
|
39
|
+
return linkChunks(store, await readChunks(snap, input));
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
await snap.close();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export async function readChunks(db, { chatId, type, types, ...bounds }) {
|
|
36
46
|
const selected = selectedChunkTypes(type, types);
|
|
37
47
|
if (selected?.length === 0) {
|
|
38
48
|
return [];
|
|
@@ -40,23 +50,60 @@ export async function listChunks(store, { chatId, type, types, ...bounds }) {
|
|
|
40
50
|
if (selected && selected.length > 1 && !isHistorySelection(selected)) {
|
|
41
51
|
throw new CoreError('CHUNK_TYPES_UNMAPPED');
|
|
42
52
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (selected?.length === 1) {
|
|
46
|
-
const prefix = { chatId, type: chunkTypeOrdinal(selected[0]) };
|
|
47
|
-
const chunks = await snap
|
|
48
|
-
.find(CHUNKS_BY_TYPE, keyRange(prefix, 'seq', bounds))
|
|
49
|
-
.toArray();
|
|
50
|
-
return linkChunks(store, chunks);
|
|
51
|
-
}
|
|
52
|
-
const chunks = await snap
|
|
53
|
-
.find(selected ? HISTORY_CHUNKS : CHUNKS_BY_CHAT, keyRange({ chatId }, 'seq', bounds))
|
|
54
|
-
.toArray();
|
|
55
|
-
return linkChunks(store, chunks);
|
|
53
|
+
if (selected?.length === 1) {
|
|
54
|
+
return findChunksOfType(db, { chatId, type: selected[0], ...bounds });
|
|
56
55
|
}
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
const history = selected !== null;
|
|
57
|
+
const ordered = history && bounds.limit ? null : await readChatOrdered(db, chatId, bounds);
|
|
58
|
+
if (ordered) {
|
|
59
|
+
return history ? ordered.filter((chunk) => HISTORY_CHUNK_TYPES.includes(chunk.type)) : ordered;
|
|
60
|
+
}
|
|
61
|
+
return db
|
|
62
|
+
.find(history ? HISTORY_CHUNKS : CHUNKS_BY_CHAT, keyRange({ chatId }, 'seq', bounds))
|
|
63
|
+
.toArray();
|
|
64
|
+
}
|
|
65
|
+
async function readChatOrdered(db, chatId, bounds) {
|
|
66
|
+
const counter = await db.get(CHUNK_COUNTERS, { chatId });
|
|
67
|
+
if (!counter) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
const chunks = await db
|
|
71
|
+
.find(CHAT_CHUNKS, keyRange({ chatId }, 'seq', bounds))
|
|
72
|
+
.toArray();
|
|
73
|
+
const { first, last } = seqSpan(counter.count, bounds);
|
|
74
|
+
if (last < first) {
|
|
75
|
+
return chunks.length === 0 ? chunks : null;
|
|
76
|
+
}
|
|
77
|
+
const [low, high] = bounds.reverse ? [chunks.at(-1), chunks[0]] : [chunks[0], chunks.at(-1)];
|
|
78
|
+
const whole = chunks.length === last - first + 1 && low?.seq === first && high?.seq === last;
|
|
79
|
+
if (!whole) {
|
|
80
|
+
return null;
|
|
59
81
|
}
|
|
82
|
+
const settled = new Set(chunks
|
|
83
|
+
.filter((chunk) => TERMINAL_RUN_STATES.has(chunk.runStatus?.state ?? ''))
|
|
84
|
+
.map((c) => c.runId));
|
|
85
|
+
return Promise.all(chunks.map((chunk) => (changeable(chunk, settled) ? current(db, chunk) : chunk)));
|
|
86
|
+
}
|
|
87
|
+
function changeable(chunk, settled) {
|
|
88
|
+
return ((chunk.type === 'run-status' && !settled.has(chunk.runId)) ||
|
|
89
|
+
(chunk.type === 'approval-request' && chunk.approvalRequest?.status === 'pending') ||
|
|
90
|
+
(chunk.type === 'attachment' && !chunk.attachment?.deletedAt));
|
|
91
|
+
}
|
|
92
|
+
async function current(db, chunk) {
|
|
93
|
+
return (await db.get(CHUNKS, { id: chunk.id })) ?? chunk;
|
|
94
|
+
}
|
|
95
|
+
function seqSpan(count, { gt, gte, lt, lte, reverse, limit }) {
|
|
96
|
+
let first = Math.max(0, gte ?? 0, gt === undefined ? 0 : gt + 1);
|
|
97
|
+
let last = Math.min(count - 1, lte ?? Infinity, lt === undefined ? Infinity : lt - 1);
|
|
98
|
+
if (limit) {
|
|
99
|
+
if (reverse) {
|
|
100
|
+
first = Math.max(first, last - limit + 1);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
last = Math.min(last, first + limit - 1);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return { first, last };
|
|
60
107
|
}
|
|
61
108
|
export async function listAttachmentsByKind(store, { kind, origin, ...bounds }) {
|
|
62
109
|
const mediaKind = mediaKindOrdinal(kind);
|
|
@@ -87,6 +134,15 @@ function selectedChunkTypes(type, types) {
|
|
|
87
134
|
}
|
|
88
135
|
return [...selected];
|
|
89
136
|
}
|
|
137
|
+
export function selectsChunk({ chatId, type, types, gt, gte, lt, lte }, chunk) {
|
|
138
|
+
const selected = selectedChunkTypes(type, types);
|
|
139
|
+
return (chunk.chatId === chatId &&
|
|
140
|
+
(selected === null || selected.includes(chunk.type)) &&
|
|
141
|
+
(gt === undefined || chunk.seq > gt) &&
|
|
142
|
+
(gte === undefined || chunk.seq >= gte) &&
|
|
143
|
+
(lt === undefined || chunk.seq < lt) &&
|
|
144
|
+
(lte === undefined || chunk.seq <= lte));
|
|
145
|
+
}
|
|
90
146
|
function isHistorySelection(types) {
|
|
91
147
|
return (types.length === HISTORY_CHUNK_TYPES.length &&
|
|
92
148
|
types.every((type) => HISTORY_CHUNK_TYPES.includes(type)));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const CHUNKS = "@qvac/chunks";
|
|
2
|
+
export declare const CHAT_CHUNKS = "@qvac/chat-chunks";
|
|
2
3
|
export declare const CHUNK_COUNTERS = "@qvac/chunk-counters";
|
|
3
4
|
export declare const AGENTS = "@qvac/agents";
|
|
4
5
|
export declare const APPROVAL_RULES = "@qvac/approval-rules";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface StoredConfigValue {
|
|
2
|
+
readonly value?: unknown;
|
|
3
|
+
readonly falsyValue?: string | null;
|
|
4
|
+
}
|
|
5
|
+
export declare function configValue(value: unknown): StoredConfigValue;
|
|
6
|
+
export declare function readConfigValue({ value, falsyValue }: StoredConfigValue): unknown;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const FALSY_VALUES = new Map([
|
|
2
|
+
['false', false],
|
|
3
|
+
['0', 0],
|
|
4
|
+
['""', '']
|
|
5
|
+
]);
|
|
6
|
+
export function configValue(value) {
|
|
7
|
+
return value === false || value === 0 || value === ''
|
|
8
|
+
? { value: null, falsyValue: JSON.stringify(value) }
|
|
9
|
+
: { value };
|
|
10
|
+
}
|
|
11
|
+
export function readConfigValue({ value, falsyValue }) {
|
|
12
|
+
const falsy = falsyValue ?? '';
|
|
13
|
+
return FALSY_VALUES.has(falsy) ? FALSY_VALUES.get(falsy) : (value ?? null);
|
|
14
|
+
}
|
|
@@ -2,3 +2,4 @@ import type HyperDB from 'hyperdb';
|
|
|
2
2
|
import type { Router } from '../../../spec/mesh/hyperdispatch/index.js';
|
|
3
3
|
export declare function isPurged(tx: HyperDB, chatId: string): Promise<boolean>;
|
|
4
4
|
export declare function registerChatRoutes(router: Router): void;
|
|
5
|
+
export declare function deleteChatChunks(tx: HyperDB, chatId: string): Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { trackActivity } from './activity.js';
|
|
2
|
-
import { CHATS, CHUNKS, CHUNKS_BY_CHAT, CHUNK_COUNTERS, INDEXING_STATUS, INDEXING_STATUS_BY_CHAT, KNOWLEDGE, KNOWLEDGE_ARTIFACTS, KNOWLEDGE_ARTIFACTS_BY_KNOWLEDGE, KNOWLEDGE_BY_CHAT, PURGED_CHATS, TOOL_ACTIVITY, TOOL_ACTIVITY_BY_AGENT } from '../collections.js';
|
|
2
|
+
import { CHATS, CHAT_CHUNKS, CHUNKS, CHUNKS_BY_CHAT, CHUNK_COUNTERS, INDEXING_STATUS, INDEXING_STATUS_BY_CHAT, KNOWLEDGE, KNOWLEDGE_ARTIFACTS, KNOWLEDGE_ARTIFACTS_BY_KNOWLEDGE, KNOWLEDGE_BY_CHAT, PURGED_CHATS, TOOL_ACTIVITY, TOOL_ACTIVITY_BY_AGENT } from '../collections.js';
|
|
3
3
|
export async function isPurged(tx, chatId) {
|
|
4
4
|
return (await tx.get(PURGED_CHATS, { chatId })) !== null;
|
|
5
5
|
}
|
|
@@ -45,12 +45,19 @@ export function registerChatRoutes(router) {
|
|
|
45
45
|
return purged;
|
|
46
46
|
}));
|
|
47
47
|
}
|
|
48
|
+
export async function deleteChatChunks(tx, chatId) {
|
|
49
|
+
const inChat = { gte: { chatId }, lte: { chatId } };
|
|
50
|
+
for (const chunk of await tx.find(CHAT_CHUNKS, inChat).toArray()) {
|
|
51
|
+
await tx.delete(CHAT_CHUNKS, { chatId, seq: chunk.seq });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
48
54
|
async function purgeChat(tx, chat) {
|
|
49
55
|
const chatId = chat.id;
|
|
50
56
|
const inChat = { gte: { chatId }, lte: { chatId } };
|
|
51
57
|
for (const id of await idsOf(tx.find(CHUNKS_BY_CHAT, inChat))) {
|
|
52
58
|
await tx.delete(CHUNKS, { id });
|
|
53
59
|
}
|
|
60
|
+
await deleteChatChunks(tx, chatId);
|
|
54
61
|
await tx.delete(CHUNK_COUNTERS, { chatId });
|
|
55
62
|
for (const knowledge of await tx.find(KNOWLEDGE_BY_CHAT, inChat).toArray()) {
|
|
56
63
|
const ofKnowledge = { gte: { knowledgeId: knowledge.id }, lte: { knowledgeId: knowledge.id } };
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { devicesByWriterKey, trackActivity } from './activity.js';
|
|
2
|
-
import { isPurged } from './chat.js';
|
|
2
|
+
import { deleteChatChunks, isPurged } from './chat.js';
|
|
3
3
|
import { CHUNK_PAYLOAD_FIELDS, ragSourcesWithinBounds } from '../../../schema/qvac.js';
|
|
4
4
|
import { chunkTypeOrdinal } from '../../../schema/indexes.js';
|
|
5
5
|
import b4a from 'b4a';
|
|
6
|
-
import { CHUNKS, CHUNKS_BY_TYPE, CHUNK_COUNTERS, DEVICES } from '../collections.js';
|
|
6
|
+
import { CHAT_CHUNKS, CHUNKS, CHUNKS_BY_CHAT, CHUNKS_BY_TYPE, CHUNK_COUNTERS, DEVICES } from '../collections.js';
|
|
7
7
|
const TERMINAL_RUN_STATES = new Set(['completed', 'failed', 'canceled']);
|
|
8
8
|
const CREDITED_CHUNK_TYPES = new Set(['run-request', 'run-status']);
|
|
9
|
+
async function putChunk(tx, chunk) {
|
|
10
|
+
await tx.insert(CHUNKS, chunk);
|
|
11
|
+
await tx.insert(CHAT_CHUNKS, chunk);
|
|
12
|
+
}
|
|
9
13
|
async function runHasTerminalStatus(tx, chatId, runId) {
|
|
10
14
|
const type = chunkTypeOrdinal('run-status');
|
|
11
15
|
const statuses = tx.find(CHUNKS_BY_TYPE, {
|
|
@@ -99,7 +103,7 @@ export function registerChunkRoutes(router) {
|
|
|
99
103
|
count: prevCount + 1,
|
|
100
104
|
lastActivityAt: Math.max(counter?.lastActivityAt ?? 0, op.createdAt)
|
|
101
105
|
});
|
|
102
|
-
await tx
|
|
106
|
+
await putChunk(tx, appended);
|
|
103
107
|
return CREDITED_CHUNK_TYPES.has(op.type) ? appended : undefined;
|
|
104
108
|
}));
|
|
105
109
|
router.add('@qvac/update-chunk', trackActivity(async (op, { tx, node, log }) => {
|
|
@@ -122,7 +126,7 @@ export function registerChunkRoutes(router) {
|
|
|
122
126
|
return;
|
|
123
127
|
}
|
|
124
128
|
const next = { ...chunk, runStatus: op.runStatus, updatedAt: op.updatedAt };
|
|
125
|
-
await tx
|
|
129
|
+
await putChunk(tx, next);
|
|
126
130
|
return next;
|
|
127
131
|
}
|
|
128
132
|
if (chunk.type === 'attachment' && op.attachment !== null && op.attachment !== undefined) {
|
|
@@ -131,7 +135,7 @@ export function registerChunkRoutes(router) {
|
|
|
131
135
|
return;
|
|
132
136
|
}
|
|
133
137
|
const next = { ...chunk, attachment: op.attachment, updatedAt: op.updatedAt };
|
|
134
|
-
await tx
|
|
138
|
+
await putChunk(tx, next);
|
|
135
139
|
return next;
|
|
136
140
|
}
|
|
137
141
|
log?.warn('contract', 'update-chunk dropped: only a run-status (runStatus) or attachment (attachment) edits', { id: op.id });
|
|
@@ -161,8 +165,18 @@ export function registerChunkRoutes(router) {
|
|
|
161
165
|
},
|
|
162
166
|
updatedAt: op.resolvedAt
|
|
163
167
|
};
|
|
164
|
-
await tx
|
|
168
|
+
await putChunk(tx, resolved);
|
|
165
169
|
log?.info('contract', `approval ${op.approved ? 'approved' : 'denied'}`, { id: op.id });
|
|
166
170
|
return resolved;
|
|
167
171
|
}));
|
|
172
|
+
router.add('@qvac/reindex-chat-chunks', async ({ chatId }, { tx }) => {
|
|
173
|
+
if (await isPurged(tx, chatId)) {
|
|
174
|
+
await deleteChatChunks(tx, chatId);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const inChat = { gte: { chatId }, lte: { chatId } };
|
|
178
|
+
for (const chunk of await tx.find(CHUNKS_BY_CHAT, inChat).toArray()) {
|
|
179
|
+
await tx.insert(CHAT_CHUNKS, chunk);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
168
182
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Router } from '../../../spec/mesh/hyperdispatch/index.js';
|
|
2
|
-
declare const DROPPED: readonly ['@qvac/append-chunk', '@qvac/update-chunk', '@qvac/resolve-approval', '@qvac/put-agent', '@qvac/put-approval-rule', '@qvac/seed-defaults', '@qvac/add-knowledge', '@qvac/remove-knowledge', '@qvac/add-knowledge-artifact', '@qvac/claim-indexing', '@qvac/resolve-indexing', '@qvac/put-chat', '@qvac/put-tool-configs', '@qvac/append-tool-activity', '@qvac/migrate-agent-catalog', '@qvac/reindex-agents', '@qvac/put-chat-group', '@qvac/put-joined-mesh', '@qvac/purge-chat', '@qvac/name-mesh', '@qvac/put-mesh-seed'];
|
|
2
|
+
declare const DROPPED: readonly ['@qvac/append-chunk', '@qvac/update-chunk', '@qvac/resolve-approval', '@qvac/put-agent', '@qvac/put-approval-rule', '@qvac/seed-defaults', '@qvac/add-knowledge', '@qvac/remove-knowledge', '@qvac/add-knowledge-artifact', '@qvac/claim-indexing', '@qvac/resolve-indexing', '@qvac/put-chat', '@qvac/put-tool-configs', '@qvac/append-tool-activity', '@qvac/migrate-agent-catalog', '@qvac/reindex-agents', '@qvac/put-chat-group', '@qvac/put-joined-mesh', '@qvac/purge-chat', '@qvac/name-mesh', '@qvac/put-mesh-seed', '@qvac/reindex-chat-chunks'];
|
|
3
3
|
export type DroppedComputeRoute = (typeof DROPPED)[number];
|
|
4
4
|
export declare function droppedComputeRoutes(): ReadonlyArray<DroppedComputeRoute>;
|
|
5
5
|
export declare function assertComputeRoute(compute: boolean, name: string): void;
|
|
@@ -20,7 +20,8 @@ const DROPPED = [
|
|
|
20
20
|
'@qvac/put-joined-mesh',
|
|
21
21
|
'@qvac/purge-chat',
|
|
22
22
|
'@qvac/name-mesh',
|
|
23
|
-
'@qvac/put-mesh-seed'
|
|
23
|
+
'@qvac/put-mesh-seed',
|
|
24
|
+
'@qvac/reindex-chat-chunks'
|
|
24
25
|
];
|
|
25
26
|
const DROPPED_ROUTES = new Set(DROPPED);
|
|
26
27
|
export function droppedComputeRoutes() {
|
|
@@ -82,7 +82,7 @@ export function registerDeviceRoutes(router) {
|
|
|
82
82
|
await tx.insert(DEVICES, next);
|
|
83
83
|
return next;
|
|
84
84
|
}));
|
|
85
|
-
router.add('@qvac/report-device-capabilities', trackActivity(async ({ deviceId, installedToolNames, installedSkillNames, installedModelNames, cachedModelNames, readySkillNames, toolCatalog }, { tx, node, log }) => {
|
|
85
|
+
router.add('@qvac/report-device-capabilities', trackActivity(async ({ deviceId, installedToolNames, installedSkillNames, installedModelNames, cachedModelNames, readySkillNames, toolCatalog, customModels }, { tx, node, log }) => {
|
|
86
86
|
const existing = await tx.get(DEVICES, { id: deviceId });
|
|
87
87
|
if (!existing) {
|
|
88
88
|
log?.debug('contract', 'report-device-capabilities dropped: unknown device');
|
|
@@ -101,7 +101,8 @@ export function registerDeviceRoutes(router) {
|
|
|
101
101
|
installedModelNames: installedModelNames ?? [],
|
|
102
102
|
cachedModelNames: cachedModelNames ?? [],
|
|
103
103
|
readySkillNames: readySkillNames ?? existing.readySkillNames,
|
|
104
|
-
toolCatalog: toolCatalog ?? existing.toolCatalog
|
|
104
|
+
toolCatalog: toolCatalog ?? existing.toolCatalog,
|
|
105
|
+
customModels: customModels ?? existing.customModels
|
|
105
106
|
};
|
|
106
107
|
await tx.insert(DEVICES, next);
|
|
107
108
|
return next;
|
|
@@ -47,6 +47,7 @@ export class PendingDepartures {
|
|
|
47
47
|
seed: row.seed,
|
|
48
48
|
key: row.creator ? null : row.key,
|
|
49
49
|
writerSeed: row.writerSeed ?? undefined,
|
|
50
|
+
compute: row.compute,
|
|
50
51
|
deviceId: this._deviceId() ?? undefined,
|
|
51
52
|
logger: this._log,
|
|
52
53
|
blindPeerKeys: this._blindPeerKeys,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { QvacToolReportEntry } from '../../spec/mesh/hyperschema/types.d.ts';
|
|
1
|
+
import type { QvacCustomModelReportEntry, QvacToolReportEntry } from '../../spec/mesh/hyperschema/types.d.ts';
|
|
2
2
|
import type { AppBuildMetadata } from './app-build.ts';
|
|
3
3
|
import type { Mesh } from './mesh.ts';
|
|
4
4
|
export interface SaveDeviceCapabilitiesInput {
|
|
@@ -9,6 +9,7 @@ export interface SaveDeviceCapabilitiesInput {
|
|
|
9
9
|
cachedModelNames: string[];
|
|
10
10
|
readySkillNames?: string[] | null;
|
|
11
11
|
toolCatalog?: QvacToolReportEntry[] | null;
|
|
12
|
+
customModels?: QvacCustomModelReportEntry[] | null;
|
|
12
13
|
}
|
|
13
14
|
export declare function saveDeviceCapabilities(store: Mesh, input: SaveDeviceCapabilitiesInput, isAccount: (mesh: Mesh) => boolean): Promise<void>;
|
|
14
15
|
export declare function retractInventory(store: Mesh, deviceId: Buffer, isAccount: (mesh: Mesh) => boolean): Promise<void>;
|
|
@@ -32,7 +32,8 @@ export async function retractInventory(store, deviceId, isAccount) {
|
|
|
32
32
|
row.installedSkillNames,
|
|
33
33
|
row.installedModelNames,
|
|
34
34
|
row.cachedModelNames,
|
|
35
|
-
row.toolCatalog
|
|
35
|
+
row.toolCatalog,
|
|
36
|
+
row.customModels
|
|
36
37
|
].some((list) => list?.length) ||
|
|
37
38
|
(row.readySkillNames?.length ?? 0) > (trimmed.readySkillNames?.length ?? 0);
|
|
38
39
|
if (leaked) {
|
|
@@ -48,7 +49,8 @@ async function hostedOnly(store, input) {
|
|
|
48
49
|
installedModelNames: [],
|
|
49
50
|
cachedModelNames: [],
|
|
50
51
|
readySkillNames: readinessForAgents(input.readySkillNames ?? [], hosted),
|
|
51
|
-
toolCatalog: []
|
|
52
|
+
toolCatalog: [],
|
|
53
|
+
customModels: []
|
|
52
54
|
};
|
|
53
55
|
}
|
|
54
56
|
export async function advertiseDeviceVersion(store, deviceId, app) {
|
|
@@ -11,7 +11,7 @@ import { type IndexingProgress, type IndexingEmbedder, type RagExtractors, type
|
|
|
11
11
|
import type { Mesh } from '../mesh.ts';
|
|
12
12
|
import type { ChatFileKey } from './records/source.ts';
|
|
13
13
|
import type { SettleOptions } from './processing/settle.ts';
|
|
14
|
-
export { fullTextBudgetChars, fullTextHits, retrieveRagKnowledge, searchRagChunks, referencesPendingFile, type VectorHit, type RagDocumentRef } from './rag/index.ts';
|
|
14
|
+
export { fullTextBudgetChars, fullTextHits, retrievalBudgetTokens, retrieveRagKnowledge, searchRagChunks, referencesPendingFile, type VectorHit, type RagDocumentRef } from './rag/index.ts';
|
|
15
15
|
export { isKnowledgeRoutedAttachment } from './records/index.ts';
|
|
16
16
|
export { assertRemovableAt } from './records/index.ts';
|
|
17
17
|
export { assertArtifactOutput } from './records/index.ts';
|
|
@@ -15,7 +15,7 @@ import { PreviewProcessor, PREVIEW_VERSION, previewId } from './preview/index.js
|
|
|
15
15
|
import { CoreError } from '../../errors.js';
|
|
16
16
|
import { errorMessage } from '../../guards.js';
|
|
17
17
|
import { ACTIVE_KNOWLEDGE_BY_CHAT, AGENTS, CHATS, INDEXING_STATUS_BY_CHAT, KNOWLEDGE, KNOWLEDGE_ARTIFACTS_BY_KNOWLEDGE } from '../collections.js';
|
|
18
|
-
export { fullTextBudgetChars, fullTextHits, retrieveRagKnowledge, searchRagChunks, referencesPendingFile } from './rag/index.js';
|
|
18
|
+
export { fullTextBudgetChars, fullTextHits, retrievalBudgetTokens, retrieveRagKnowledge, searchRagChunks, referencesPendingFile } from './rag/index.js';
|
|
19
19
|
export { isKnowledgeRoutedAttachment } from './records/index.js';
|
|
20
20
|
export { assertRemovableAt } from './records/index.js';
|
|
21
21
|
export { assertArtifactOutput } from './records/index.js';
|
|
@@ -31,6 +31,6 @@ export declare class RagProcessor implements FileProcessor {
|
|
|
31
31
|
export { MAX_KNOWLEDGE_BYTES } from './limits.ts';
|
|
32
32
|
export { canIndexChat } from './policy.ts';
|
|
33
33
|
export type { IndexingEmbedder, IndexingProgress } from './produce.ts';
|
|
34
|
-
export { formatFullDocumentContext, fullTextBudgetChars, fullTextHits, isFullTextHit, isTruncatedFullTextHit } from './retrieval/full-text.ts';
|
|
34
|
+
export { formatFullDocumentContext, fullTextBudgetChars, fullTextHits, isFullTextHit, isTruncatedFullTextHit, retrievalBudgetTokens } from './retrieval/full-text.ts';
|
|
35
35
|
export { MemoryVectorIndex, RAG_DOCUMENT_KIND, RAG_KNOWLEDGE_OFF_NOTICE, RAG_TRUNCATED_NOTICE, RAG_UNAVAILABLE_NOTICE, WEB_TOOLS, chooseRagNotice, citedByPhraseOverlap, classifyRagDocument, createRagSourceTagFilter, encodeRagArtifact, formatRagContext, isSupportedRagDocument, isWholeDocumentQuery, referencedDocuments, referencesPendingFile, retrieveRagKnowledge, searchRagChunks, sourcesFromHits, webSourcesFromToolResult, withoutDataChannel } from 'rag-extract';
|
|
36
36
|
export type { RagArtifactPayload, RagDocumentRef, RagExtractors, RagSource, VectorHit, VectorIndex } from 'rag-extract';
|
|
@@ -70,5 +70,5 @@ export class RagProcessor {
|
|
|
70
70
|
}
|
|
71
71
|
export { MAX_KNOWLEDGE_BYTES } from './limits.js';
|
|
72
72
|
export { canIndexChat } from './policy.js';
|
|
73
|
-
export { formatFullDocumentContext, fullTextBudgetChars, fullTextHits, isFullTextHit, isTruncatedFullTextHit } from './retrieval/full-text.js';
|
|
73
|
+
export { formatFullDocumentContext, fullTextBudgetChars, fullTextHits, isFullTextHit, isTruncatedFullTextHit, retrievalBudgetTokens } from './retrieval/full-text.js';
|
|
74
74
|
export { MemoryVectorIndex, RAG_DOCUMENT_KIND, RAG_KNOWLEDGE_OFF_NOTICE, RAG_TRUNCATED_NOTICE, RAG_UNAVAILABLE_NOTICE, WEB_TOOLS, chooseRagNotice, citedByPhraseOverlap, classifyRagDocument, createRagSourceTagFilter, encodeRagArtifact, formatRagContext, isSupportedRagDocument, isWholeDocumentQuery, referencedDocuments, referencesPendingFile, retrieveRagKnowledge, searchRagChunks, sourcesFromHits, webSourcesFromToolResult, withoutDataChannel } from 'rag-extract';
|
|
@@ -2,6 +2,7 @@ import type { QvacKnowledge } from '../../../../../spec/mesh/hyperschema/types.d
|
|
|
2
2
|
import type { Mesh } from '../../../mesh.ts';
|
|
3
3
|
import { type VectorHit } from 'rag-extract';
|
|
4
4
|
export declare function fullTextBudgetChars(ctxSize: number): number;
|
|
5
|
+
export declare function retrievalBudgetTokens(ctxSize: number): number | undefined;
|
|
5
6
|
export interface IdentifiedHit {
|
|
6
7
|
readonly id: string;
|
|
7
8
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
-
import { classifyRagDocument, extractPdfHead, extractRagDocumentFromBytes, parseRagMetadata, RAG_DOCUMENT_KIND } from 'rag-extract';
|
|
2
|
+
import { classifyRagDocument, DEFAULT_CHUNK_BUDGET_TOKENS, extractPdfHead, extractRagDocumentFromBytes, parseRagMetadata, RAG_DOCUMENT_KIND } from 'rag-extract';
|
|
3
3
|
const DEFAULT_FULL_TEXT_BUDGET_TOKENS = 4096;
|
|
4
4
|
const CHARS_PER_TOKEN = 4;
|
|
5
5
|
const FULL_TEXT_KINDS = new Set([
|
|
@@ -14,6 +14,9 @@ export function fullTextBudgetChars(ctxSize) {
|
|
|
14
14
|
const tokens = ctxSize > 0 ? Math.floor(ctxSize / 2) : DEFAULT_FULL_TEXT_BUDGET_TOKENS;
|
|
15
15
|
return tokens * CHARS_PER_TOKEN;
|
|
16
16
|
}
|
|
17
|
+
export function retrievalBudgetTokens(ctxSize) {
|
|
18
|
+
return ctxSize > 0 ? Math.min(DEFAULT_CHUNK_BUDGET_TOKENS, Math.floor(ctxSize / 4)) : undefined;
|
|
19
|
+
}
|
|
17
20
|
const FULL_TEXT_HIT_PREFIX = 'full-text-';
|
|
18
21
|
export function isFullTextHit(hit) {
|
|
19
22
|
return hit.id.startsWith(FULL_TEXT_HIT_PREFIX);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import { getAgent } from './agent.js';
|
|
3
3
|
import { getChat } from './chat.js';
|
|
4
|
-
import { DEVICES } from './collections.js';
|
|
5
4
|
import { CoreError } from '../errors.js';
|
|
5
|
+
import { knownSender } from './known-sender.js';
|
|
6
6
|
const MAX_ANSWER_BYTES = 2 * 1024 * 1024;
|
|
7
7
|
export function createInferenceCallsReceiver(opts) {
|
|
8
8
|
return async (request, fromDeviceId) => {
|
|
9
|
-
const sender = await opts.mesh
|
|
9
|
+
const sender = await knownSender(opts.mesh, fromDeviceId);
|
|
10
10
|
if (!sender || sender.revoked) {
|
|
11
11
|
throw new CoreError('PEER_SENDER_REVOKED');
|
|
12
12
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DEVICES } from './collections.js';
|
|
2
|
+
import { ACK_TIMEOUT_MS } from './handoff-channel.js';
|
|
3
|
+
const SENDER_ROW_WAIT_MS = ACK_TIMEOUT_MS / 2;
|
|
4
|
+
export async function knownSender(mesh, deviceId) {
|
|
5
|
+
const read = () => mesh.view.get(DEVICES, { id: deviceId });
|
|
6
|
+
const row = await read();
|
|
7
|
+
if (row) {
|
|
8
|
+
return row;
|
|
9
|
+
}
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
const settle = (found) => {
|
|
12
|
+
clearTimeout(timer);
|
|
13
|
+
mesh.unwatch(check);
|
|
14
|
+
mesh.off('close', onClose);
|
|
15
|
+
resolve(found);
|
|
16
|
+
};
|
|
17
|
+
const onClose = () => settle(null);
|
|
18
|
+
const check = () => {
|
|
19
|
+
void read().then((found) => found && settle(found), onClose);
|
|
20
|
+
};
|
|
21
|
+
const timer = setTimeout(onClose, SENDER_ROW_WAIT_MS);
|
|
22
|
+
mesh.watch(check);
|
|
23
|
+
mesh.on('close', onClose);
|
|
24
|
+
check();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import CorestoreStorage from 'hypercore-storage';
|
|
2
2
|
import HyperDB from 'hyperdb';
|
|
3
3
|
import type { LocalAccountRecovery, LocalAppConfig, LocalCapabilityProfile, LocalChatMove, LocalMeshUpdate, LocalChatNotify, LocalChatOrder, LocalCustomModel, LocalIdentity, LocalMemberProof, LocalMeshDeparture, LocalMeshMembership, LocalModelDownload, LocalModelNotify } from '../../../spec/local/hyperschema/types.d.ts';
|
|
4
|
+
import type { QvacAutobeeHead } from '../../../spec/mesh/hyperschema/types.d.ts';
|
|
4
5
|
import type { DeviceMetadata } from '../mesh.ts';
|
|
5
6
|
import { LocalFiles } from './files.ts';
|
|
6
7
|
export interface ResolvedSession {
|
|
@@ -8,6 +9,7 @@ export interface ResolvedSession {
|
|
|
8
9
|
readonly baseKey: Buffer | undefined;
|
|
9
10
|
readonly writerSeed: string | undefined;
|
|
10
11
|
readonly compute: boolean;
|
|
12
|
+
readonly bootFrom?: QvacAutobeeHead | null;
|
|
11
13
|
}
|
|
12
14
|
export interface ArchivedMeshMembership extends LocalMeshMembership {
|
|
13
15
|
readonly leftAt: number;
|
|
@@ -9,6 +9,7 @@ import LocalDatabaseSpec from '../../../spec/local/hyperdb/index.js';
|
|
|
9
9
|
import b4a from 'b4a';
|
|
10
10
|
import { dropMeshFiles, LocalFiles } from './files.js';
|
|
11
11
|
import { LOCAL_ACCOUNT_RECOVERY, LOCAL_ACTIVE_MESH, LOCAL_APP_CONFIG, LOCAL_CHAT_MOVES, LOCAL_MESH_UPDATES, LOCAL_CHAT_NOTIFY, LOCAL_CHAT_ORDER, LOCAL_CHAT_ORDER_BY_KEY, LOCAL_CONFIG, LOCAL_CUSTOM_MODEL, LOCAL_DEVICE, LOCAL_IDENTITY, LOCAL_MEMBERSHIP, LOCAL_MEMBER_PROOF, LOCAL_MESH_DEPARTURE, LOCAL_MESH_HISTORY, LOCAL_MESH_MEMBERSHIP, LOCAL_MESH_SESSION, LOCAL_MODEL_DOWNLOAD, LOCAL_MODEL_NOTIFY } from '../collections.js';
|
|
12
|
+
import { configValue, readConfigValue } from '../config-value.js';
|
|
12
13
|
const IDENTITY_ID = 'identity';
|
|
13
14
|
const MEMBERSHIP_ID = 'membership';
|
|
14
15
|
const APP_CONFIG_ID = 'default';
|
|
@@ -20,7 +21,8 @@ function sessionOf(row) {
|
|
|
20
21
|
seed: row.seed,
|
|
21
22
|
baseKey: row.key ?? undefined,
|
|
22
23
|
writerSeed: row.writerSeed ?? undefined,
|
|
23
|
-
compute: row.compute ?? false
|
|
24
|
+
compute: row.compute ?? false,
|
|
25
|
+
bootFrom: row.bootKey ? { key: row.bootKey, length: row.bootLength ?? 0 } : null
|
|
24
26
|
};
|
|
25
27
|
}
|
|
26
28
|
export function openLocalStore(storage) {
|
|
@@ -46,12 +48,12 @@ class LocalStore {
|
|
|
46
48
|
}
|
|
47
49
|
async get(key) {
|
|
48
50
|
const row = await this._db.get(LOCAL_CONFIG, { key });
|
|
49
|
-
return row === null ? null : row
|
|
51
|
+
return row === null ? null : readConfigValue(row);
|
|
50
52
|
}
|
|
51
53
|
set(key, value) {
|
|
52
54
|
return this._locked(async () => {
|
|
53
55
|
const tx = this._db.transaction();
|
|
54
|
-
await tx.insert(LOCAL_CONFIG, { key, value });
|
|
56
|
+
await tx.insert(LOCAL_CONFIG, { key, ...configValue(value) });
|
|
55
57
|
await tx.flush();
|
|
56
58
|
});
|
|
57
59
|
}
|
|
@@ -59,7 +61,7 @@ class LocalStore {
|
|
|
59
61
|
return this._locked(async () => {
|
|
60
62
|
const tx = this._db.transaction();
|
|
61
63
|
for (const { key, value } of entries) {
|
|
62
|
-
await tx.insert(LOCAL_CONFIG, { key, value });
|
|
64
|
+
await tx.insert(LOCAL_CONFIG, { key, ...configValue(value) });
|
|
63
65
|
}
|
|
64
66
|
await tx.flush();
|
|
65
67
|
});
|
|
@@ -71,10 +73,10 @@ class LocalStore {
|
|
|
71
73
|
return null;
|
|
72
74
|
}
|
|
73
75
|
const tx = this._db.transaction();
|
|
74
|
-
await tx.insert(LOCAL_CONFIG, { key: toKey
|
|
76
|
+
await tx.insert(LOCAL_CONFIG, { ...row, key: toKey });
|
|
75
77
|
await tx.delete(LOCAL_CONFIG, { key: fromKey });
|
|
76
78
|
await tx.flush();
|
|
77
|
-
return row
|
|
79
|
+
return readConfigValue(row);
|
|
78
80
|
});
|
|
79
81
|
}
|
|
80
82
|
deleteAll(keys) {
|
|
@@ -510,7 +512,9 @@ class LocalStore {
|
|
|
510
512
|
seed: session.seed,
|
|
511
513
|
writerSeed: session.writerSeed,
|
|
512
514
|
compute: session.compute,
|
|
513
|
-
awaitingAdmission: existing?.awaitingAdmission
|
|
515
|
+
awaitingAdmission: existing?.awaitingAdmission,
|
|
516
|
+
bootKey: session.bootFrom?.key,
|
|
517
|
+
bootLength: session.bootFrom?.length
|
|
514
518
|
});
|
|
515
519
|
if (minted) {
|
|
516
520
|
await tx.insert(LOCAL_ACTIVE_MESH, { deviceId, homeMeshKey: key });
|
|
@@ -537,7 +541,8 @@ class LocalStore {
|
|
|
537
541
|
key: row.key,
|
|
538
542
|
seed: row.seed,
|
|
539
543
|
creator: opts.creator,
|
|
540
|
-
writerSeed: row.writerSeed
|
|
544
|
+
writerSeed: row.writerSeed,
|
|
545
|
+
compute: row.compute
|
|
541
546
|
});
|
|
542
547
|
await tx.flush();
|
|
543
548
|
});
|
|
@@ -590,12 +595,14 @@ class LocalStore {
|
|
|
590
595
|
const { awaitingAdmission } = opts;
|
|
591
596
|
return this._locked(async () => {
|
|
592
597
|
const existing = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
|
|
593
|
-
|
|
598
|
+
const settled = awaitingAdmission || !existing?.bootKey;
|
|
599
|
+
if (!existing || (!!existing.awaitingAdmission === awaitingAdmission && settled)) {
|
|
594
600
|
return;
|
|
595
601
|
}
|
|
602
|
+
const { bootKey, bootLength, ...rest } = existing;
|
|
596
603
|
const tx = this._db.transaction();
|
|
597
604
|
await tx.insert(LOCAL_MESH_MEMBERSHIP, {
|
|
598
|
-
...existing,
|
|
605
|
+
...(awaitingAdmission ? existing : rest),
|
|
599
606
|
awaitingAdmission
|
|
600
607
|
});
|
|
601
608
|
await tx.flush();
|
|
@@ -46,7 +46,11 @@ export interface MeshOptions {
|
|
|
46
46
|
slowDrainMs?: number;
|
|
47
47
|
}
|
|
48
48
|
export declare function meshPublicKeyFromSeed(seed: Buffer): Buffer;
|
|
49
|
-
export
|
|
49
|
+
export interface TrustScope {
|
|
50
|
+
readonly ourMemberId: Buffer | null;
|
|
51
|
+
readonly compute: boolean;
|
|
52
|
+
}
|
|
53
|
+
export declare function isTrustedWriter(snap: HyperDB, writerKey: Buffer, { ourMemberId, compute }: TrustScope): Promise<boolean>;
|
|
50
54
|
export type BirthRow = {
|
|
51
55
|
readonly id: Buffer;
|
|
52
56
|
readonly joinedAt: number;
|
|
@@ -36,7 +36,7 @@ const WARMUP_COLLECTIONS = [
|
|
|
36
36
|
'@qvac/members',
|
|
37
37
|
'@qvac/active-chats'
|
|
38
38
|
];
|
|
39
|
-
export async function
|
|
39
|
+
export async function isTrustedWriter(snap, writerKey, { ourMemberId, compute }) {
|
|
40
40
|
const device = await liveDeviceForWriter(snap, writerKey);
|
|
41
41
|
if (!device) {
|
|
42
42
|
return false;
|
|
@@ -44,7 +44,7 @@ export async function isOurTrustedWriter(snap, writerKey, ourMemberId) {
|
|
|
44
44
|
if (!ourMemberId) {
|
|
45
45
|
return true;
|
|
46
46
|
}
|
|
47
|
-
return !!device.memberId && b4a.equals(device.memberId, ourMemberId);
|
|
47
|
+
return !!device.memberId && (!compute || b4a.equals(device.memberId, ourMemberId));
|
|
48
48
|
}
|
|
49
49
|
export function claimableDevice(row) {
|
|
50
50
|
return {
|
|
@@ -665,9 +665,9 @@ export class Mesh extends ReadyResource {
|
|
|
665
665
|
return false;
|
|
666
666
|
const snap = reference.db.snapshot();
|
|
667
667
|
try {
|
|
668
|
-
const trusted = await
|
|
668
|
+
const trusted = await isTrustedWriter(snap, key, this);
|
|
669
669
|
if (!trusted) {
|
|
670
|
-
this._log?.debug(this._scope, 'writer is no device of
|
|
670
|
+
this._log?.debug(this._scope, 'writer is no live device of this mesh', {
|
|
671
671
|
writerKey: b4a.toHex(key).slice(0, 16)
|
|
672
672
|
});
|
|
673
673
|
}
|
|
@@ -685,7 +685,7 @@ export class Mesh extends ReadyResource {
|
|
|
685
685
|
for await (const writer of target.db.find(LIVE_WRITERS_BY_MOST_RECENT, {
|
|
686
686
|
reverse: true
|
|
687
687
|
})) {
|
|
688
|
-
if ((await
|
|
688
|
+
if ((await isTrustedWriter(snap, writer.writerKey, this)) ||
|
|
689
689
|
(await this._vouchedByItsRow(target, reference, writer.writerKey))) {
|
|
690
690
|
this._log?.debug(this._scope, 'vouching for a head', {
|
|
691
691
|
writerKey: b4a.toHex(writer.writerKey).slice(0, 16),
|
|
@@ -694,7 +694,7 @@ export class Mesh extends ReadyResource {
|
|
|
694
694
|
return { key: writer.writerKey, length: writer.length };
|
|
695
695
|
}
|
|
696
696
|
}
|
|
697
|
-
this._log?.debug(this._scope, 'vouching for no head: no writer
|
|
697
|
+
this._log?.debug(this._scope, 'vouching for no head: no live writer has been active');
|
|
698
698
|
return null;
|
|
699
699
|
}
|
|
700
700
|
finally {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Mesh } from '../mesh.ts';
|
|
2
|
+
export declare const REINDEX_FROM_APP_VERSION = "0.21.0";
|
|
3
|
+
export declare function floorExcludesBefore(range: string | null | undefined, release: string): boolean;
|
|
4
|
+
export declare function backfillChatChunks(mesh: Mesh): Promise<number>;
|