@qvac/core 1.0.0-rc.2 → 1.0.0-rc.5
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 +238 -12
- package/dist-lib/index.d.ts +3 -1
- package/dist-lib/index.js +1 -0
- package/dist-lib/lib/api/approval-rules.d.ts +1 -1
- package/dist-lib/lib/api/approval-rules.js +5 -1
- package/dist-lib/lib/api/chunk-delta.d.ts +7 -2
- package/dist-lib/lib/api/chunk-delta.js +89 -7
- package/dist-lib/lib/api/chunks.js +14 -8
- package/dist-lib/lib/api/config.d.ts +10 -3
- package/dist-lib/lib/api/config.js +51 -6
- package/dist-lib/lib/api/custom-models.js +3 -5
- package/dist-lib/lib/api/devices.js +3 -1
- package/dist-lib/lib/api/files.d.ts +1 -1
- package/dist-lib/lib/api/files.js +65 -8
- package/dist-lib/lib/api/index.d.ts +12 -2
- package/dist-lib/lib/api/index.js +6 -1
- package/dist-lib/lib/api/instrument.js +12 -4
- package/dist-lib/lib/api/members.js +7 -13
- package/dist-lib/lib/api/mesh.d.ts +1 -3
- package/dist-lib/lib/api/mesh.js +2 -2
- package/dist-lib/lib/api/notifications.js +8 -4
- package/dist-lib/lib/api/projects.js +5 -1
- package/dist-lib/lib/api/rag.js +32 -19
- package/dist-lib/lib/api/served.js +2 -1
- package/dist-lib/lib/api/workspace.js +0 -1
- package/dist-lib/lib/assistant/harness.d.ts +8 -2
- package/dist-lib/lib/assistant/harness.js +17 -4
- package/dist-lib/lib/assistant/history.d.ts +1 -1
- package/dist-lib/lib/assistant/history.js +19 -13
- package/dist-lib/lib/assistant/message.d.ts +6 -1
- package/dist-lib/lib/assistant/message.js +22 -2
- package/dist-lib/lib/assistant/model-round.d.ts +5 -0
- package/dist-lib/lib/assistant/model-round.js +47 -19
- package/dist-lib/lib/assistant/pdf-budget.d.ts +10 -2
- package/dist-lib/lib/assistant/pdf-budget.js +10 -11
- package/dist-lib/lib/assistant/pdf-pages.d.ts +25 -0
- package/dist-lib/lib/assistant/pdf-pages.js +75 -0
- package/dist-lib/lib/assistant/round-host.js +5 -3
- package/dist-lib/lib/assistant-client.d.ts +2 -1
- package/dist-lib/lib/assistant-client.js +24 -6
- package/dist-lib/lib/assistant-tree.d.ts +2 -0
- package/dist-lib/lib/assistant-tree.js +8 -5
- package/dist-lib/lib/assistant.d.ts +21 -7
- package/dist-lib/lib/assistant.js +481 -244
- package/dist-lib/lib/client.js +10 -1
- package/dist-lib/lib/compaction.d.ts +3 -1
- package/dist-lib/lib/compaction.js +18 -4
- package/dist-lib/lib/constants.d.ts +3 -0
- package/dist-lib/lib/constants.js +3 -0
- package/dist-lib/lib/core/agent-copies.js +7 -1
- package/dist-lib/lib/core/agent.js +1 -0
- package/dist-lib/lib/core/approval-rules.d.ts +5 -1
- package/dist-lib/lib/core/approval-rules.js +16 -1
- package/dist-lib/lib/core/chat-activity.js +13 -16
- package/dist-lib/lib/core/chat-copy.js +1 -1
- package/dist-lib/lib/core/chat-fork.js +2 -1
- package/dist-lib/lib/core/chat-move.d.ts +4 -0
- package/dist-lib/lib/core/chat-move.js +42 -11
- package/dist-lib/lib/core/chat.d.ts +0 -1
- package/dist-lib/lib/core/chat.js +1 -1
- package/dist-lib/lib/core/chunk.d.ts +14 -3
- package/dist-lib/lib/core/chunk.js +116 -25
- package/dist-lib/lib/core/collections.d.ts +12 -1
- package/dist-lib/lib/core/collections.js +12 -1
- package/dist-lib/lib/core/config-value.d.ts +7 -0
- package/dist-lib/lib/core/config-value.js +15 -0
- package/dist-lib/lib/core/contract/activity.d.ts +3 -2
- package/dist-lib/lib/core/contract/activity.js +39 -21
- package/dist-lib/lib/core/contract/agent-join.js +15 -19
- package/dist-lib/lib/core/contract/agents.js +8 -7
- package/dist-lib/lib/core/contract/chat.d.ts +3 -0
- package/dist-lib/lib/core/contract/chat.js +12 -1
- package/dist-lib/lib/core/contract/chunks.js +16 -6
- package/dist-lib/lib/core/contract/devices.js +6 -4
- package/dist-lib/lib/core/contract/index.js +2 -1
- package/dist-lib/lib/core/contract/invites.js +12 -31
- package/dist-lib/lib/core/contract/joined-meshes.js +2 -1
- package/dist-lib/lib/core/contract/mesh-rules.js +4 -0
- package/dist-lib/lib/core/contract/model-requests.js +7 -6
- package/dist-lib/lib/core/contract/project-device-keys.js +15 -6
- package/dist-lib/lib/core/contract/project-host-keys.js +5 -4
- package/dist-lib/lib/core/contract/projects.js +12 -13
- package/dist-lib/lib/core/contract/public-seeds.js +5 -5
- package/dist-lib/lib/core/contract/roles.js +2 -1
- package/dist-lib/lib/core/contract/run-requests.d.ts +1 -1
- package/dist-lib/lib/core/contract/run-requests.js +19 -13
- package/dist-lib/lib/core/contract/shipped-rows.d.ts +2 -0
- package/dist-lib/lib/core/contract/shipped-rows.js +22 -0
- package/dist-lib/lib/core/contract/workspace.js +6 -12
- package/dist-lib/lib/core/contract/writers.js +20 -6
- package/dist-lib/lib/core/deleted-agent-runs.d.ts +7 -0
- package/dist-lib/lib/core/deleted-agent-runs.js +46 -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/document-attachment.d.ts +6 -3
- package/dist-lib/lib/core/document-attachment.js +10 -5
- package/dist-lib/lib/core/files/attachments.js +3 -3
- package/dist-lib/lib/core/files/index.d.ts +8 -5
- package/dist-lib/lib/core/files/index.js +111 -18
- package/dist-lib/lib/core/files/processing/index.d.ts +1 -1
- package/dist-lib/lib/core/files/processing/index.js +8 -2
- package/dist-lib/lib/core/files/processing/source.d.ts +1 -0
- package/dist-lib/lib/core/files/processing/source.js +3 -0
- package/dist-lib/lib/core/files/processing/state.d.ts +1 -0
- package/dist-lib/lib/core/files/processing/state.js +7 -0
- package/dist-lib/lib/core/files/rag/build.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/build.js +14 -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/produce.js +1 -0
- package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +7 -1
- package/dist-lib/lib/core/first-event.d.ts +6 -0
- package/dist-lib/lib/core/first-event.js +13 -0
- package/dist-lib/lib/core/invite.d.ts +2 -2
- package/dist-lib/lib/core/invite.js +5 -4
- package/dist-lib/lib/core/local/index.d.ts +16 -1
- package/dist-lib/lib/core/local/index.js +119 -10
- package/dist-lib/lib/core/mesh.d.ts +14 -3
- package/dist-lib/lib/core/mesh.js +127 -54
- package/dist-lib/lib/core/migrations/chat-chunks.d.ts +4 -0
- package/dist-lib/lib/core/migrations/chat-chunks.js +47 -0
- package/dist-lib/lib/core/migrations/file-index.d.ts +1 -1
- package/dist-lib/lib/core/migrations/file-index.js +6 -2
- package/dist-lib/lib/core/migrations/index.d.ts +2 -1
- package/dist-lib/lib/core/migrations/index.js +66 -9
- package/dist-lib/lib/core/notification.js +96 -23
- package/dist-lib/lib/core/pdf/figure.d.ts +22 -0
- package/dist-lib/lib/core/pdf/figure.js +64 -0
- package/dist-lib/lib/core/pdf/rasterize.d.ts +10 -1
- package/dist-lib/lib/core/pdf/rasterize.js +72 -22
- package/dist-lib/lib/core/peer-duplex.js +57 -5
- package/dist-lib/lib/core/public-mesh.js +8 -2
- package/dist-lib/lib/core/run-requests.js +2 -3
- package/dist-lib/lib/core/senders.d.ts +7 -6
- package/dist-lib/lib/core/senders.js +23 -30
- package/dist-lib/lib/core/shared-agents.d.ts +1 -0
- package/dist-lib/lib/core/shared-agents.js +47 -19
- package/dist-lib/lib/core/skill-secrets.d.ts +3 -2
- package/dist-lib/lib/core/skill-secrets.js +4 -1
- package/dist-lib/lib/core/sync/background.d.ts +3 -15
- package/dist-lib/lib/core/sync/background.js +25 -102
- package/dist-lib/lib/core/sync/devices.js +6 -3
- package/dist-lib/lib/core/sync/index.js +25 -3
- package/dist-lib/lib/core/sync-status.js +3 -3
- package/dist-lib/lib/core/vault-managed-skills.d.ts +18 -0
- package/dist-lib/lib/core/vault-managed-skills.js +105 -0
- package/dist-lib/lib/core.d.ts +66 -10
- package/dist-lib/lib/core.js +768 -179
- package/dist-lib/lib/credential-pusher.d.ts +11 -7
- package/dist-lib/lib/credential-pusher.js +40 -8
- package/dist-lib/lib/device-tree.d.ts +18 -0
- package/dist-lib/lib/device-tree.js +32 -0
- package/dist-lib/lib/doctor/redact.js +1 -1
- package/dist-lib/lib/errors.d.ts +12 -0
- package/dist-lib/lib/errors.js +12 -0
- package/dist-lib/lib/fs-drive-bridge.d.ts +7 -0
- package/dist-lib/lib/fs-drive-bridge.js +308 -30
- package/dist-lib/lib/integrations/setup-routes.js +7 -5
- package/dist-lib/lib/knowledge-search.d.ts +1 -1
- package/dist-lib/lib/knowledge-search.js +5 -46
- package/dist-lib/lib/kv-cache-retention.d.ts +35 -0
- package/dist-lib/lib/kv-cache-retention.js +98 -0
- package/dist-lib/lib/latest-frame.d.ts +10 -0
- package/dist-lib/lib/latest-frame.js +48 -0
- package/dist-lib/lib/mesh-scoped-engine.js +1 -0
- package/dist-lib/lib/model-download.d.ts +6 -1
- package/dist-lib/lib/model-download.js +32 -17
- package/dist-lib/lib/oauth/resolve.js +13 -5
- package/dist-lib/lib/reconnecting-watch.js +19 -11
- package/dist-lib/lib/run-notices.d.ts +2 -0
- package/dist-lib/lib/run-notices.js +5 -0
- package/dist-lib/lib/run-replay.d.ts +13 -1
- package/dist-lib/lib/run-replay.js +58 -21
- package/dist-lib/schema/build.js +66 -57
- package/dist-lib/schema/config.d.ts +1 -1
- package/dist-lib/schema/config.js +1 -1
- package/dist-lib/schema/content.js +2 -1
- package/dist-lib/schema/engine.js +70 -6
- package/dist-lib/schema/field-order.js +7 -1
- package/dist-lib/schema/indexes.d.ts +4 -0
- package/dist-lib/schema/indexes.js +18 -0
- package/dist-lib/schema/local.js +9 -2
- package/dist-lib/schema/qvac.js +116 -6
- package/dist-lib/spec/bind.js +15 -0
- package/dist-lib/spec/calls.js +5 -0
- package/dist-lib/spec/capabilities.d.ts +10 -0
- package/dist-lib/spec/config/hyperconf/index.js +1 -1
- package/dist-lib/spec/hrpc/hrpc.json +65 -0
- package/dist-lib/spec/hrpc/index.js +63 -3
- package/dist-lib/spec/hrpc/messages.js +1537 -1395
- package/dist-lib/spec/hyperschema/index.js +1537 -1395
- package/dist-lib/spec/hyperschema/schema.json +126 -1
- package/dist-lib/spec/hyperschema/types.d.ts +33 -1
- package/dist-lib/spec/local/hyperdb/messages.js +110 -54
- package/dist-lib/spec/local/hyperschema/index.js +56 -28
- package/dist-lib/spec/local/hyperschema/schema.json +55 -20
- package/dist-lib/spec/local/hyperschema/types.d.ts +8 -1
- package/dist-lib/spec/mesh/hyperdb/db.json +255 -51
- package/dist-lib/spec/mesh/hyperdb/index.js +1063 -404
- package/dist-lib/spec/mesh/hyperdb/messages.js +1673 -1202
- package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +62 -56
- package/dist-lib/spec/mesh/hyperdispatch/index.js +156 -139
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +809 -632
- package/dist-lib/spec/mesh/hyperschema/index.js +809 -632
- package/dist-lib/spec/mesh/hyperschema/schema.json +293 -174
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +31 -1
- package/package.json +32 -26
- package/worker/assistant-sidecar.mjs +3 -0
- package/dist-lib/lib/core/files/processing/settle.d.ts +0 -13
- package/dist-lib/lib/core/files/processing/settle.js +0 -86
- package/dist-lib/lib/core/migrations/device-indexes.d.ts +0 -2
- package/dist-lib/lib/core/migrations/device-indexes.js +0 -7
|
@@ -13,7 +13,8 @@ import { keyRange } from './range.js';
|
|
|
13
13
|
import { runDefinition } from './shared-agents.js';
|
|
14
14
|
import { drivenBy, handedOff, offeredTo } from './run-driver.js';
|
|
15
15
|
import b4a from 'b4a';
|
|
16
|
-
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';
|
|
16
|
+
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';
|
|
17
|
+
const TERMINAL_RUN_STATES = new Set(['completed', 'failed', 'canceled']);
|
|
17
18
|
export const HISTORY_CHUNK_TYPES = [
|
|
18
19
|
'user-message',
|
|
19
20
|
'run-request',
|
|
@@ -22,12 +23,31 @@ export const HISTORY_CHUNK_TYPES = [
|
|
|
22
23
|
'compaction',
|
|
23
24
|
'round-reset'
|
|
24
25
|
];
|
|
25
|
-
|
|
26
|
+
const FALSY_RESULTS = new Map([
|
|
27
|
+
['false', false],
|
|
28
|
+
['0', 0],
|
|
29
|
+
['""', '']
|
|
30
|
+
]);
|
|
31
|
+
export function readChunk({ toolResult, ...chunk }) {
|
|
32
|
+
if (!toolResult) {
|
|
33
|
+
return { ...chunk, toolResult: null };
|
|
34
|
+
}
|
|
35
|
+
const stored = chunk.falsyResult ?? '';
|
|
36
|
+
const result = FALSY_RESULTS.has(stored) ? FALSY_RESULTS.get(stored) : (toolResult.result ?? null);
|
|
37
|
+
return { ...chunk, toolResult: { ...toolResult, result } };
|
|
38
|
+
}
|
|
39
|
+
export function linkChunks(store, chunks) {
|
|
26
40
|
const mint = store.attachmentUrl;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
return chunks.map((row) => {
|
|
42
|
+
const chunk = readChunk(row);
|
|
43
|
+
return mint && chunk.attachment
|
|
44
|
+
? { ...chunk, attachment: linkAttachment(mint, chunk.attachment) }
|
|
45
|
+
: chunk;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function falsyResultOf(payload) {
|
|
49
|
+
const result = payload.toolResult?.result;
|
|
50
|
+
return result === false || result === 0 || result === '' ? JSON.stringify(result) : undefined;
|
|
31
51
|
}
|
|
32
52
|
export async function recordLinks(store, chunks) {
|
|
33
53
|
await store.fileIndex?.record(chunks.filter((chunk) => chunk.attachment?.url));
|
|
@@ -39,7 +59,24 @@ export function findChunksOfType(snap, { chatId, type, ...bounds }) {
|
|
|
39
59
|
.find(CHUNKS_BY_TYPE, keyRange(prefix, 'seq', bounds))
|
|
40
60
|
.toArray();
|
|
41
61
|
}
|
|
42
|
-
export async function
|
|
62
|
+
export async function findChunksOfTypes(db, { chatId, types, ...bounds }) {
|
|
63
|
+
const ordered = await readChatOrdered(db, chatId, { types, ...bounds });
|
|
64
|
+
if (ordered) {
|
|
65
|
+
return ordered;
|
|
66
|
+
}
|
|
67
|
+
const byType = await Promise.all(types.map((type) => findChunksOfType(db, { chatId, type, ...bounds })));
|
|
68
|
+
return byType.flat().sort((left, right) => left.seq - right.seq);
|
|
69
|
+
}
|
|
70
|
+
export async function listChunks(store, input) {
|
|
71
|
+
const snap = store.view.snapshot();
|
|
72
|
+
try {
|
|
73
|
+
return linkChunks(store, await readChunks(snap, input));
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
await snap.close();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export async function readChunks(db, { chatId, type, types, ...bounds }) {
|
|
43
80
|
const selected = selectedChunkTypes(type, types);
|
|
44
81
|
if (selected?.length === 0) {
|
|
45
82
|
return [];
|
|
@@ -47,23 +84,66 @@ export async function listChunks(store, { chatId, type, types, ...bounds }) {
|
|
|
47
84
|
if (selected && selected.length > 1 && !isHistorySelection(selected)) {
|
|
48
85
|
throw new CoreError('CHUNK_TYPES_UNMAPPED');
|
|
49
86
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
87
|
+
if (selected?.length === 1) {
|
|
88
|
+
return findChunksOfType(db, { chatId, type: selected[0], ...bounds });
|
|
89
|
+
}
|
|
90
|
+
const history = selected !== null;
|
|
91
|
+
const ordered = history && bounds.limit
|
|
92
|
+
? null
|
|
93
|
+
: await readChatOrdered(db, chatId, {
|
|
94
|
+
types: history ? HISTORY_CHUNK_TYPES : null,
|
|
95
|
+
...bounds
|
|
96
|
+
});
|
|
97
|
+
if (ordered) {
|
|
98
|
+
return ordered;
|
|
99
|
+
}
|
|
100
|
+
return db
|
|
101
|
+
.find(history ? HISTORY_CHUNKS : CHUNKS_BY_CHAT, keyRange({ chatId }, 'seq', bounds))
|
|
102
|
+
.toArray();
|
|
103
|
+
}
|
|
104
|
+
async function readChatOrdered(db, chatId, { types, ...bounds }) {
|
|
105
|
+
const counter = await db.get(CHUNK_COUNTERS, { chatId });
|
|
106
|
+
if (!counter) {
|
|
107
|
+
return null;
|
|
63
108
|
}
|
|
64
|
-
|
|
65
|
-
|
|
109
|
+
const chunks = await db
|
|
110
|
+
.find(CHAT_CHUNKS, keyRange({ chatId }, 'seq', bounds))
|
|
111
|
+
.toArray();
|
|
112
|
+
const { first, last } = seqSpan(counter.count, bounds);
|
|
113
|
+
if (last < first) {
|
|
114
|
+
return chunks.length === 0 ? chunks : null;
|
|
115
|
+
}
|
|
116
|
+
const [low, high] = bounds.reverse ? [chunks.at(-1), chunks[0]] : [chunks[0], chunks.at(-1)];
|
|
117
|
+
const whole = chunks.length === last - first + 1 && low?.seq === first && high?.seq === last;
|
|
118
|
+
if (!whole) {
|
|
119
|
+
return null;
|
|
66
120
|
}
|
|
121
|
+
const settled = new Set(chunks
|
|
122
|
+
.filter((chunk) => TERMINAL_RUN_STATES.has(chunk.runStatus?.state ?? ''))
|
|
123
|
+
.map((c) => c.runId));
|
|
124
|
+
const selected = types ? chunks.filter((chunk) => types.includes(chunk.type)) : chunks;
|
|
125
|
+
return Promise.all(selected.map((chunk) => (changeable(chunk, settled) ? current(db, chunk) : chunk)));
|
|
126
|
+
}
|
|
127
|
+
function changeable(chunk, settled) {
|
|
128
|
+
return ((chunk.type === 'run-status' && !settled.has(chunk.runId)) ||
|
|
129
|
+
(chunk.type === 'approval-request' && chunk.approvalRequest?.status === 'pending') ||
|
|
130
|
+
(chunk.type === 'attachment' && !chunk.attachment?.deletedAt));
|
|
131
|
+
}
|
|
132
|
+
async function current(db, chunk) {
|
|
133
|
+
return (await db.get(CHUNKS, { id: chunk.id })) ?? chunk;
|
|
134
|
+
}
|
|
135
|
+
function seqSpan(count, { gt, gte, lt, lte, reverse, limit }) {
|
|
136
|
+
let first = Math.max(0, gte ?? 0, gt === undefined ? 0 : gt + 1);
|
|
137
|
+
let last = Math.min(count - 1, lte ?? Infinity, lt === undefined ? Infinity : lt - 1);
|
|
138
|
+
if (limit) {
|
|
139
|
+
if (reverse) {
|
|
140
|
+
first = Math.max(first, last - limit + 1);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
last = Math.min(last, first + limit - 1);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return { first, last };
|
|
67
147
|
}
|
|
68
148
|
export async function listAttachmentsByKind(store, { kind, origin, ...bounds }) {
|
|
69
149
|
const mediaKind = mediaKindOrdinal(kind);
|
|
@@ -94,6 +174,15 @@ function selectedChunkTypes(type, types) {
|
|
|
94
174
|
}
|
|
95
175
|
return [...selected];
|
|
96
176
|
}
|
|
177
|
+
export function selectsChunk({ chatId, type, types, gt, gte, lt, lte }, chunk) {
|
|
178
|
+
const selected = selectedChunkTypes(type, types);
|
|
179
|
+
return (chunk.chatId === chatId &&
|
|
180
|
+
(selected === null || selected.includes(chunk.type)) &&
|
|
181
|
+
(gt === undefined || chunk.seq > gt) &&
|
|
182
|
+
(gte === undefined || chunk.seq >= gte) &&
|
|
183
|
+
(lt === undefined || chunk.seq < lt) &&
|
|
184
|
+
(lte === undefined || chunk.seq <= lte));
|
|
185
|
+
}
|
|
97
186
|
function isHistorySelection(types) {
|
|
98
187
|
return (types.length === HISTORY_CHUNK_TYPES.length &&
|
|
99
188
|
types.every((type) => HISTORY_CHUNK_TYPES.includes(type)));
|
|
@@ -256,6 +345,7 @@ export async function appendChunk(store, { id = randomId(), chatId, runId, type,
|
|
|
256
345
|
capabilityArgs,
|
|
257
346
|
enhance,
|
|
258
347
|
sourceId,
|
|
348
|
+
falsyResult: falsyResultOf(payload),
|
|
259
349
|
round,
|
|
260
350
|
callId,
|
|
261
351
|
resumed,
|
|
@@ -298,7 +388,6 @@ export function updateOp(chunk, { id, runStatus, attachment }) {
|
|
|
298
388
|
'a run-status edits runStatus, an attachment edits attachment'
|
|
299
389
|
]);
|
|
300
390
|
}
|
|
301
|
-
const DEFAULT_APPROVAL_RULE_TTL_MS = 60 * 60 * 1000;
|
|
302
391
|
export async function othersApproval(store, id) {
|
|
303
392
|
const ask = await getChunk(store, id);
|
|
304
393
|
return !!ask && (await projectRun(store)) && !(await ownedByUs(store, ask));
|
|
@@ -312,13 +401,15 @@ export async function resolveApproval(store, { id, approved, scope, expiresAt, a
|
|
|
312
401
|
const ask = resolved.approvalRequest;
|
|
313
402
|
if (ask && (ask.status === 'approved' || ask.status === 'denied')) {
|
|
314
403
|
await putApprovalRule(rules, {
|
|
404
|
+
id,
|
|
315
405
|
toolName: ask.name,
|
|
316
406
|
resourceKind: ask.resource?.kind ?? undefined,
|
|
317
407
|
resourcePattern: ask.resource?.label ?? undefined,
|
|
318
408
|
decision: ask.status === 'approved' ? 'allow' : 'deny',
|
|
319
|
-
expiresAt
|
|
409
|
+
expiresAt,
|
|
320
410
|
agentId: ask.agentId ?? agentId,
|
|
321
|
-
effect: resolved.effect ?? undefined
|
|
411
|
+
effect: resolved.effect ?? undefined,
|
|
412
|
+
chatId: resolved.chatId
|
|
322
413
|
});
|
|
323
414
|
}
|
|
324
415
|
}
|
|
@@ -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";
|
|
@@ -67,8 +68,18 @@ export declare const LOCAL_RUN_LOG_STEPS = "@local/run-log-steps";
|
|
|
67
68
|
export declare const LOCAL_MESH_SESSION = "@local/mesh-session";
|
|
68
69
|
export declare const LOCAL_MESH_HISTORY = "@local/mesh-history";
|
|
69
70
|
export declare const LOCAL_MEMBERSHIP = "@local/membership";
|
|
70
|
-
export declare const INDEX_BACKFILLS = "@qvac/index-backfills";
|
|
71
71
|
export declare const LIVE_DEVICES_BY_WRITER_KEY = "@qvac/live-devices-by-writer-key";
|
|
72
|
+
export declare const LIVE_DEVICES_BY_MEMBER = "@qvac/live-devices-by-member";
|
|
73
|
+
export declare const DEVICES_BY_MEMBER = "@qvac/devices-by-member";
|
|
74
|
+
export declare const AGENT_HOSTS_BY_AGENT = "@qvac/agent-hosts-by-agent";
|
|
75
|
+
export declare const AGENT_HOSTS_BY_DEVICE = "@qvac/agent-hosts-by-device";
|
|
76
|
+
export declare const PUBLIC_SEEDS_BY_DEVICE = "@qvac/public-seeds-by-device";
|
|
77
|
+
export declare const PROJECT_HOST_KEYS_BY_DEVICE = "@qvac/project-host-keys-by-device";
|
|
78
|
+
export declare const PROJECT_DEVICE_KEYS_BY_DEVICE = "@qvac/project-device-keys-by-device";
|
|
79
|
+
export declare const PROJECT_DEVICE_KEYS_BY_MEMBER = "@qvac/project-device-keys-by-member";
|
|
80
|
+
export declare const AGENT_USERS_BY_USER = "@qvac/agent-users-by-user";
|
|
81
|
+
export declare const PROJECT_KEYS_BY_MEMBER = "@qvac/project-keys-by-member";
|
|
82
|
+
export declare const TERMINAL_RUN_STATUSES = "@qvac/terminal-run-statuses";
|
|
72
83
|
export declare const MEMBER_REMOVALS = "@qvac/member-removals";
|
|
73
84
|
export declare const INVITE_SEQUENCES = "@qvac/invite-sequences";
|
|
74
85
|
export declare const MESH_INVITE_SPENDS = "@qvac/mesh-invite-spends";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export const CHUNKS = '@qvac/chunks';
|
|
2
|
+
export const CHAT_CHUNKS = '@qvac/chat-chunks';
|
|
2
3
|
export const CHUNK_COUNTERS = '@qvac/chunk-counters';
|
|
3
4
|
export const AGENTS = '@qvac/agents';
|
|
4
5
|
export const APPROVAL_RULES = '@qvac/approval-rules';
|
|
@@ -67,8 +68,18 @@ export const LOCAL_RUN_LOG_STEPS = '@local/run-log-steps';
|
|
|
67
68
|
export const LOCAL_MESH_SESSION = '@local/mesh-session';
|
|
68
69
|
export const LOCAL_MESH_HISTORY = '@local/mesh-history';
|
|
69
70
|
export const LOCAL_MEMBERSHIP = '@local/membership';
|
|
70
|
-
export const INDEX_BACKFILLS = '@qvac/index-backfills';
|
|
71
71
|
export const LIVE_DEVICES_BY_WRITER_KEY = '@qvac/live-devices-by-writer-key';
|
|
72
|
+
export const LIVE_DEVICES_BY_MEMBER = '@qvac/live-devices-by-member';
|
|
73
|
+
export const DEVICES_BY_MEMBER = '@qvac/devices-by-member';
|
|
74
|
+
export const AGENT_HOSTS_BY_AGENT = '@qvac/agent-hosts-by-agent';
|
|
75
|
+
export const AGENT_HOSTS_BY_DEVICE = '@qvac/agent-hosts-by-device';
|
|
76
|
+
export const PUBLIC_SEEDS_BY_DEVICE = '@qvac/public-seeds-by-device';
|
|
77
|
+
export const PROJECT_HOST_KEYS_BY_DEVICE = '@qvac/project-host-keys-by-device';
|
|
78
|
+
export const PROJECT_DEVICE_KEYS_BY_DEVICE = '@qvac/project-device-keys-by-device';
|
|
79
|
+
export const PROJECT_DEVICE_KEYS_BY_MEMBER = '@qvac/project-device-keys-by-member';
|
|
80
|
+
export const AGENT_USERS_BY_USER = '@qvac/agent-users-by-user';
|
|
81
|
+
export const PROJECT_KEYS_BY_MEMBER = '@qvac/project-keys-by-member';
|
|
82
|
+
export const TERMINAL_RUN_STATUSES = '@qvac/terminal-run-statuses';
|
|
72
83
|
export const MEMBER_REMOVALS = '@qvac/member-removals';
|
|
73
84
|
export const INVITE_SEQUENCES = '@qvac/invite-sequences';
|
|
74
85
|
export const MESH_INVITE_SPENDS = '@qvac/mesh-invite-spends';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const QUARANTINE_PREFIX = "quarantine.";
|
|
2
|
+
export interface StoredConfigValue {
|
|
3
|
+
readonly value?: unknown;
|
|
4
|
+
readonly falsyValue?: string | null;
|
|
5
|
+
}
|
|
6
|
+
export declare function configValue(value: unknown): StoredConfigValue;
|
|
7
|
+
export declare function readConfigValue({ value, falsyValue }: StoredConfigValue): unknown;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const QUARANTINE_PREFIX = 'quarantine.';
|
|
2
|
+
const FALSY_VALUES = new Map([
|
|
3
|
+
['false', false],
|
|
4
|
+
['0', 0],
|
|
5
|
+
['""', '']
|
|
6
|
+
]);
|
|
7
|
+
export function configValue(value) {
|
|
8
|
+
return value === false || value === 0 || value === ''
|
|
9
|
+
? { value: null, falsyValue: JSON.stringify(value) }
|
|
10
|
+
: { value };
|
|
11
|
+
}
|
|
12
|
+
export function readConfigValue({ value, falsyValue }) {
|
|
13
|
+
const falsy = falsyValue ?? '';
|
|
14
|
+
return FALSY_VALUES.has(falsy) ? FALSY_VALUES.get(falsy) : (value ?? null);
|
|
15
|
+
}
|
|
@@ -7,8 +7,9 @@ type RouteHandler<T> = (op: T, ctx: RouterContext) => Promise<unknown>;
|
|
|
7
7
|
export declare function trackActivity<T>(handler: RouteHandler<T>): RouteHandler<T>;
|
|
8
8
|
export declare function devicesByWriterKey(tx: HyperDB, writerKey: Buffer): HyperDBStream<QvacDevice>;
|
|
9
9
|
export declare function liveDeviceForWriter(db: HyperDB, writerKey: Buffer): Promise<QvacDevice | null>;
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
10
|
+
export declare function liveDevicesOf(db: HyperDB, memberId: Buffer): Promise<QvacDevice[]>;
|
|
11
|
+
export declare function devicesOfMember(db: HyperDB, memberId: Buffer): Promise<QvacDevice[]>;
|
|
12
|
+
export declare function liveDevices(db: HyperDB): AsyncGenerator<QvacDevice>;
|
|
12
13
|
export interface MarkWriterRevokedOptions {
|
|
13
14
|
readonly revoked: boolean;
|
|
14
15
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
-
import {
|
|
2
|
+
import { WORKSPACES_RULES, rulesVersion } from './mesh-rules.js';
|
|
3
|
+
import { DEVICES, DEVICES_BY_WRITER_KEY, DEVICES_BY_MEMBER, LIVE_DEVICES_BY_MEMBER, LIVE_DEVICES_BY_WRITER_KEY, WRITER_ACTIVITY } from '../collections.js';
|
|
3
4
|
export function trackActivity(handler) {
|
|
4
5
|
return async (op, ctx) => {
|
|
5
6
|
const applied = await handler(op, ctx);
|
|
@@ -15,35 +16,52 @@ export function devicesByWriterKey(tx, writerKey) {
|
|
|
15
16
|
lte: { writerKey }
|
|
16
17
|
});
|
|
17
18
|
}
|
|
18
|
-
export
|
|
19
|
-
if (!(await liveDevicesIndexed(db))) {
|
|
20
|
-
for await (const device of devicesByWriterKey(db, writerKey)) {
|
|
21
|
-
if (!device.revoked)
|
|
22
|
-
return device;
|
|
23
|
-
}
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
19
|
+
export function liveDeviceForWriter(db, writerKey) {
|
|
26
20
|
return db.findOne(LIVE_DEVICES_BY_WRITER_KEY, {
|
|
27
21
|
gte: { writerKey },
|
|
28
22
|
lte: { writerKey }
|
|
29
23
|
});
|
|
30
24
|
}
|
|
31
|
-
|
|
32
|
-
return (
|
|
33
|
-
|
|
25
|
+
async function indexed(db) {
|
|
26
|
+
return (await rulesVersion(db)) >= WORKSPACES_RULES;
|
|
27
|
+
}
|
|
28
|
+
function ownerOf(device) {
|
|
29
|
+
return device.memberId ?? device.claimedMemberId ?? null;
|
|
30
|
+
}
|
|
31
|
+
async function scanDevicesOf(db, memberId) {
|
|
32
|
+
const rows = [];
|
|
33
|
+
for await (const device of db.find(DEVICES)) {
|
|
34
|
+
const owner = ownerOf(device);
|
|
35
|
+
if (owner && b4a.equals(owner, memberId)) {
|
|
36
|
+
rows.push(device);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return rows;
|
|
40
|
+
}
|
|
41
|
+
export async function liveDevicesOf(db, memberId) {
|
|
42
|
+
if (!(await indexed(db))) {
|
|
43
|
+
return (await scanDevicesOf(db, memberId)).filter((device) => !device.revoked);
|
|
44
|
+
}
|
|
45
|
+
return db
|
|
46
|
+
.find(LIVE_DEVICES_BY_MEMBER, { gte: { memberId }, lte: { memberId } })
|
|
47
|
+
.toArray();
|
|
34
48
|
}
|
|
35
|
-
export async function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
indexed.add(b4a.toHex(device.id));
|
|
49
|
+
export async function devicesOfMember(db, memberId) {
|
|
50
|
+
if (!(await indexed(db))) {
|
|
51
|
+
return scanDevicesOf(db, memberId);
|
|
39
52
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
53
|
+
return db.find(DEVICES_BY_MEMBER, { gte: { memberId }, lte: { memberId } }).toArray();
|
|
54
|
+
}
|
|
55
|
+
export async function* liveDevices(db) {
|
|
56
|
+
if (!(await indexed(db))) {
|
|
57
|
+
for await (const device of db.find(DEVICES)) {
|
|
58
|
+
if (!device.revoked && ownerOf(device)) {
|
|
59
|
+
yield device;
|
|
60
|
+
}
|
|
43
61
|
}
|
|
44
|
-
|
|
62
|
+
return;
|
|
45
63
|
}
|
|
46
|
-
|
|
64
|
+
yield* db.find(LIVE_DEVICES_BY_MEMBER);
|
|
47
65
|
}
|
|
48
66
|
export async function markWriterRevoked(tx, writerKey, opts) {
|
|
49
67
|
const { revoked } = opts;
|
|
@@ -3,16 +3,17 @@ import b4a from 'b4a';
|
|
|
3
3
|
import { devicesByWriterKey, liveDeviceForWriter, trackActivity } from './activity.js';
|
|
4
4
|
import { verifyWriterClaim } from '../device-attestation.js';
|
|
5
5
|
import { projectRules } from './projects.js';
|
|
6
|
-
import { AGENT_HOSTS, AGENTS, DEVICES } from '../collections.js';
|
|
6
|
+
import { AGENT_HOSTS, AGENT_HOSTS_BY_AGENT, AGENT_HOSTS_BY_DEVICE, AGENTS, DEVICES } from '../collections.js';
|
|
7
7
|
export function hostRowsOf(db, writerKey) {
|
|
8
8
|
return db.find(AGENT_HOSTS, { gte: { writerKey }, lte: { writerKey } }).toArray();
|
|
9
9
|
}
|
|
10
10
|
export async function hostedDevice(db, deviceId) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
return (await hostRowsFor(db, deviceId)).length > 0;
|
|
12
|
+
}
|
|
13
|
+
function hostRowsFor(db, deviceId) {
|
|
14
|
+
return db
|
|
15
|
+
.find(AGENT_HOSTS_BY_DEVICE, { gte: { deviceId }, lte: { deviceId } })
|
|
16
|
+
.toArray();
|
|
16
17
|
}
|
|
17
18
|
export async function dropHostRows(tx, writerKey) {
|
|
18
19
|
for (const { agentId } of await hostRowsOf(tx, writerKey)) {
|
|
@@ -20,12 +21,7 @@ export async function dropHostRows(tx, writerKey) {
|
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
23
|
export async function releaseHostedDevice({ tx, host }, deviceId, keep) {
|
|
23
|
-
const held =
|
|
24
|
-
for await (const row of tx.find(AGENT_HOSTS)) {
|
|
25
|
-
if (b4a.equals(row.deviceId, deviceId)) {
|
|
26
|
-
held.push(row);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
24
|
+
const held = await hostRowsFor(tx, deviceId);
|
|
29
25
|
const writers = new Map();
|
|
30
26
|
for (const { writerKey, agentId } of held) {
|
|
31
27
|
await tx.delete(AGENT_HOSTS, { writerKey, agentId });
|
|
@@ -41,13 +37,13 @@ export async function evictHosts({ tx, host }, agent) {
|
|
|
41
37
|
if (await projectRules(tx)) {
|
|
42
38
|
return;
|
|
43
39
|
}
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
40
|
+
const hosts = await tx
|
|
41
|
+
.find(AGENT_HOSTS_BY_AGENT, {
|
|
42
|
+
gte: { agentId: agent.id },
|
|
43
|
+
lte: { agentId: agent.id }
|
|
44
|
+
})
|
|
45
|
+
.toArray();
|
|
46
|
+
const gone = hosts.filter((row) => agent.deletedAt || !b4a.equals(row.deviceId, agent.providerDeviceId));
|
|
51
47
|
for (const { writerKey, agentId } of gone) {
|
|
52
48
|
await tx.delete(AGENT_HOSTS, { writerKey, agentId });
|
|
53
49
|
const serving = (await hostRowsOf(tx, writerKey)).length > 0;
|
|
@@ -5,7 +5,7 @@ import { dropMemberDeviceKeys } from './project-device-keys.js';
|
|
|
5
5
|
import { evictHosts } from './agent-join.js';
|
|
6
6
|
import { isWorkspace } from './workspace.js';
|
|
7
7
|
import { meshKind } from './mesh-kind.js';
|
|
8
|
-
import { AGENT_USERS, AGENTS, DEVICES, MEMBER_KEYS } from '../collections.js';
|
|
8
|
+
import { AGENT_USERS, AGENT_USERS_BY_USER, AGENTS, DEVICES, MEMBER_KEYS } from '../collections.js';
|
|
9
9
|
import { dropMemberSeeds, pruneHostSeeds } from './public-seeds.js';
|
|
10
10
|
import { pruneProjectHostKeys } from './project-host-keys.js';
|
|
11
11
|
async function memberOfDevice(tx, id) {
|
|
@@ -102,16 +102,17 @@ export async function dropMemberCopies(tx, deviceIds, at) {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
+
function usesBy(tx, userId) {
|
|
106
|
+
return tx.find(AGENT_USERS_BY_USER, { gte: { userId }, lte: { userId } }).toArray();
|
|
107
|
+
}
|
|
105
108
|
export async function dropUser(tx, userId) {
|
|
106
|
-
for (const row of await tx
|
|
107
|
-
|
|
108
|
-
await tx.delete(AGENT_USERS, { agentId: row.agentId, userId });
|
|
109
|
-
}
|
|
109
|
+
for (const row of await usesBy(tx, userId)) {
|
|
110
|
+
await tx.delete(AGENT_USERS, { agentId: row.agentId, userId });
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
export async function dropMemberAgentUses(tx, memberId, userId) {
|
|
113
|
-
for (const row of await tx
|
|
114
|
-
const agent =
|
|
114
|
+
for (const row of await usesBy(tx, userId)) {
|
|
115
|
+
const agent = await tx.get(AGENTS, { id: row.agentId });
|
|
115
116
|
const owner = agent && (await memberOfDevice(tx, agent.providerDeviceId));
|
|
116
117
|
if (owner && b4a.equals(owner, memberId)) {
|
|
117
118
|
await tx.delete(AGENT_USERS, { agentId: row.agentId, userId });
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type HyperDB from 'hyperdb';
|
|
2
2
|
import type { Router } from '../../../spec/mesh/hyperdispatch/index.js';
|
|
3
|
+
import type { QvacChunk } from '../../../spec/mesh/hyperschema/types.d.ts';
|
|
3
4
|
export declare function isPurged(tx: HyperDB, chatId: string): Promise<boolean>;
|
|
4
5
|
export declare function foreignChat(tx: HyperDB, chatId: string | null | undefined): Promise<boolean>;
|
|
5
6
|
export declare function registerChatRoutes(router: Router): void;
|
|
7
|
+
export declare function putChunk(tx: HyperDB, chunk: QvacChunk): Promise<void>;
|
|
8
|
+
export declare function deleteChatChunks(tx: HyperDB, chatId: string): Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { liveDeviceForWriter, trackActivity } from './activity.js';
|
|
2
2
|
import { meshKind } from './mesh-kind.js';
|
|
3
3
|
import { WORKSPACES_RULES, rulesVersion } from './mesh-rules.js';
|
|
4
|
-
import { CHATS, CHAT_READS, 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';
|
|
4
|
+
import { CHATS, CHAT_CHUNKS, CHAT_READS, 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';
|
|
5
5
|
export async function isPurged(tx, chatId) {
|
|
6
6
|
return (await tx.get(PURGED_CHATS, { chatId })) !== null;
|
|
7
7
|
}
|
|
@@ -81,12 +81,23 @@ async function markChatRead(read, { tx, node, log }) {
|
|
|
81
81
|
await tx.insert(CHAT_READS, row);
|
|
82
82
|
return row;
|
|
83
83
|
}
|
|
84
|
+
export async function putChunk(tx, chunk) {
|
|
85
|
+
await tx.insert(CHUNKS, chunk);
|
|
86
|
+
await tx.insert(CHAT_CHUNKS, chunk);
|
|
87
|
+
}
|
|
88
|
+
export async function deleteChatChunks(tx, chatId) {
|
|
89
|
+
const inChat = { gte: { chatId }, lte: { chatId } };
|
|
90
|
+
for (const chunk of await tx.find(CHAT_CHUNKS, inChat).toArray()) {
|
|
91
|
+
await tx.delete(CHAT_CHUNKS, { chatId, seq: chunk.seq });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
84
94
|
async function purgeChat(tx, chat) {
|
|
85
95
|
const chatId = chat.id;
|
|
86
96
|
const inChat = { gte: { chatId }, lte: { chatId } };
|
|
87
97
|
for (const id of await idsOf(tx.find(CHUNKS_BY_CHAT, inChat))) {
|
|
88
98
|
await tx.delete(CHUNKS, { id });
|
|
89
99
|
}
|
|
100
|
+
await deleteChatChunks(tx, chatId);
|
|
90
101
|
await tx.delete(CHUNK_COUNTERS, { chatId });
|
|
91
102
|
for (const read of await tx.find(CHAT_READS, inChat).toArray()) {
|
|
92
103
|
await tx.delete(CHAT_READS, { chatId, memberId: read.memberId });
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { devicesByWriterKey, liveDeviceForWriter, trackActivity } from './activity.js';
|
|
2
|
-
import { foreignChat, isPurged } from './chat.js';
|
|
2
|
+
import { deleteChatChunks, foreignChat, isPurged, putChunk } from './chat.js';
|
|
3
3
|
import { appendRow, asModelRequest, closeRounds, hostOutputRefusal, openRound, outputRefusal, roundChunkRefusal, served } from './model-requests.js';
|
|
4
4
|
import { outsideProject, projectRules, signerMember } from './projects.js';
|
|
5
5
|
import { runHasTerminalStatus, runnerRefusal, TERMINAL_RUN_STATES } from './run-requests.js';
|
|
6
6
|
import { CHUNK_PAYLOAD_FIELDS, ragSourcesWithinBounds } from '../../../schema/qvac.js';
|
|
7
7
|
import b4a from 'b4a';
|
|
8
|
-
import { CHUNKS, DEVICES, RUN_REQUEST_BY_RUN } from '../collections.js';
|
|
8
|
+
import { CHAT_CHUNKS, CHUNKS, CHUNKS_BY_CHAT, DEVICES, RUN_REQUEST_BY_RUN } from '../collections.js';
|
|
9
9
|
import { isProbeRound } from '../../probe-rounds.js';
|
|
10
10
|
const CREDITED_CHUNK_TYPES = new Set(['run-request', 'run-status']);
|
|
11
11
|
export function runRequestOf(db, chatId, runId) {
|
|
@@ -170,7 +170,7 @@ export function registerChunkRoutes(router) {
|
|
|
170
170
|
}
|
|
171
171
|
const appended = await appendRow(tx, { ...openRound(op), requesterMemberId });
|
|
172
172
|
if (round) {
|
|
173
|
-
await tx
|
|
173
|
+
await putChunk(tx, served(round, op.createdAt));
|
|
174
174
|
}
|
|
175
175
|
if (op.type === 'run-status' &&
|
|
176
176
|
TERMINAL_RUN_STATES.has(op.runStatus?.state ?? '') &&
|
|
@@ -199,7 +199,7 @@ export function registerChunkRoutes(router) {
|
|
|
199
199
|
return;
|
|
200
200
|
}
|
|
201
201
|
const next = { ...chunk, runStatus: op.runStatus, updatedAt: op.updatedAt };
|
|
202
|
-
await tx
|
|
202
|
+
await putChunk(tx, next);
|
|
203
203
|
return next;
|
|
204
204
|
}
|
|
205
205
|
if (chunk.type === 'attachment' && op.attachment !== null && op.attachment !== undefined) {
|
|
@@ -208,7 +208,7 @@ export function registerChunkRoutes(router) {
|
|
|
208
208
|
return;
|
|
209
209
|
}
|
|
210
210
|
const next = { ...chunk, attachment: op.attachment, updatedAt: op.updatedAt };
|
|
211
|
-
await tx
|
|
211
|
+
await putChunk(tx, next);
|
|
212
212
|
return next;
|
|
213
213
|
}
|
|
214
214
|
log?.warn('contract', 'update-chunk dropped: only a run-status (runStatus) or attachment (attachment) edits', { id: op.id });
|
|
@@ -238,8 +238,18 @@ export function registerChunkRoutes(router) {
|
|
|
238
238
|
},
|
|
239
239
|
updatedAt: op.resolvedAt
|
|
240
240
|
};
|
|
241
|
-
await tx
|
|
241
|
+
await putChunk(tx, resolved);
|
|
242
242
|
log?.info('contract', `approval ${op.approved ? 'approved' : 'denied'}`, { id: op.id });
|
|
243
243
|
return resolved;
|
|
244
244
|
}));
|
|
245
|
+
router.add('@qvac/reindex-chat-chunks', async ({ chatId }, { tx }) => {
|
|
246
|
+
if (await isPurged(tx, chatId)) {
|
|
247
|
+
await deleteChatChunks(tx, chatId);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const inChat = { gte: { chatId }, lte: { chatId } };
|
|
251
|
+
for (const chunk of await tx.find(CHUNKS_BY_CHAT, inChat).toArray()) {
|
|
252
|
+
await tx.insert(CHAT_CHUNKS, chunk);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
245
255
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { capDeviceName } from '../../../schema/qvac.js';
|
|
2
|
-
import {
|
|
2
|
+
import { trackActivity } from './activity.js';
|
|
3
|
+
import { reindexShippedRows } from './shipped-rows.js';
|
|
3
4
|
import { sealed } from './seal.js';
|
|
4
5
|
import { verifyWriterClaim } from '../device-attestation.js';
|
|
5
6
|
import b4a from 'b4a';
|
|
@@ -82,7 +83,7 @@ export function registerDeviceRoutes(router) {
|
|
|
82
83
|
await tx.insert(DEVICES, next);
|
|
83
84
|
return next;
|
|
84
85
|
}));
|
|
85
|
-
router.add('@qvac/report-device-capabilities', trackActivity(async ({ deviceId, installedToolNames, installedSkillNames, installedModelNames, cachedModelNames, readySkillNames, toolCatalog }, { tx, node, log }) => {
|
|
86
|
+
router.add('@qvac/report-device-capabilities', trackActivity(async ({ deviceId, installedToolNames, installedSkillNames, installedModelNames, cachedModelNames, readySkillNames, toolCatalog, customModels }, { tx, node, log }) => {
|
|
86
87
|
const existing = await tx.get(DEVICES, { id: deviceId });
|
|
87
88
|
if (!existing) {
|
|
88
89
|
log?.debug('contract', 'report-device-capabilities dropped: unknown device');
|
|
@@ -101,7 +102,8 @@ export function registerDeviceRoutes(router) {
|
|
|
101
102
|
installedModelNames: installedModelNames ?? [],
|
|
102
103
|
cachedModelNames: cachedModelNames ?? [],
|
|
103
104
|
readySkillNames: readySkillNames ?? existing.readySkillNames,
|
|
104
|
-
toolCatalog: toolCatalog ?? existing.toolCatalog
|
|
105
|
+
toolCatalog: toolCatalog ?? existing.toolCatalog,
|
|
106
|
+
customModels: customModels ?? existing.customModels
|
|
105
107
|
};
|
|
106
108
|
await tx.insert(DEVICES, next);
|
|
107
109
|
return next;
|
|
@@ -123,6 +125,6 @@ export function registerDeviceRoutes(router) {
|
|
|
123
125
|
return next;
|
|
124
126
|
}));
|
|
125
127
|
router.add('@qvac/reindex-devices', async (_op, { tx }) => {
|
|
126
|
-
await
|
|
128
|
+
await reindexShippedRows(tx);
|
|
127
129
|
});
|
|
128
130
|
}
|