@qvac/core 1.0.0-rc.8 → 1.0.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 +243 -3
- package/README.md +1 -0
- package/dist-lib/lib/api/attachments.d.ts +1 -1
- package/dist-lib/lib/api/attachments.js +11 -0
- package/dist-lib/lib/api/chunks.d.ts +4 -2
- package/dist-lib/lib/api/chunks.js +6 -3
- package/dist-lib/lib/api/devices.js +6 -18
- package/dist-lib/lib/api/execution.d.ts +6 -2
- package/dist-lib/lib/api/execution.js +29 -3
- package/dist-lib/lib/api/host-run-log.d.ts +7 -1
- package/dist-lib/lib/api/host-run-log.js +3 -1
- package/dist-lib/lib/api/index.d.ts +3 -1
- package/dist-lib/lib/api/index.js +17 -6
- package/dist-lib/lib/api/members.js +13 -29
- package/dist-lib/lib/api/mesh.d.ts +2 -1
- package/dist-lib/lib/api/projects.d.ts +1 -1
- package/dist-lib/lib/api/projects.js +9 -5
- package/dist-lib/lib/api/rag-label.d.ts +4 -0
- package/dist-lib/lib/api/rag-label.js +21 -0
- package/dist-lib/lib/api/rag-lexical.d.ts +22 -0
- package/dist-lib/lib/api/rag-lexical.js +1058 -0
- package/dist-lib/lib/api/rag-manifest.d.ts +13 -0
- package/dist-lib/lib/api/rag-manifest.js +46 -0
- package/dist-lib/lib/api/rag-outline.d.ts +36 -0
- package/dist-lib/lib/api/rag-outline.js +426 -0
- package/dist-lib/lib/api/rag-plugin.d.ts +20 -0
- package/dist-lib/lib/api/rag-plugin.js +70 -0
- package/dist-lib/lib/api/rag-synthesis.d.ts +7 -0
- package/dist-lib/lib/api/rag-synthesis.js +102 -0
- package/dist-lib/lib/api/rag-targets.d.ts +23 -0
- package/dist-lib/lib/api/rag-targets.js +215 -0
- package/dist-lib/lib/api/rag-window.d.ts +5 -0
- package/dist-lib/lib/api/rag-window.js +46 -0
- package/dist-lib/lib/api/rag.d.ts +3 -2
- package/dist-lib/lib/api/rag.js +421 -181
- package/dist-lib/lib/api/served.js +8 -14
- package/dist-lib/lib/api/workspace.d.ts +8 -1
- package/dist-lib/lib/api/workspace.js +27 -13
- package/dist-lib/lib/assistant/harness.d.ts +9 -1
- package/dist-lib/lib/assistant/history.d.ts +11 -2
- package/dist-lib/lib/assistant/history.js +74 -4
- package/dist-lib/lib/assistant/media-round.d.ts +61 -0
- package/dist-lib/lib/assistant/media-round.js +111 -0
- package/dist-lib/lib/assistant/message.d.ts +7 -0
- package/dist-lib/lib/assistant/model-round.d.ts +12 -0
- package/dist-lib/lib/assistant/model-round.js +130 -17
- package/dist-lib/lib/assistant/pdf-pages.d.ts +16 -1
- package/dist-lib/lib/assistant/pdf-pages.js +67 -3
- package/dist-lib/lib/assistant/round-host.d.ts +22 -0
- package/dist-lib/lib/assistant/round-host.js +142 -8
- package/dist-lib/lib/assistant/upload.d.ts +12 -0
- package/dist-lib/lib/assistant/upload.js +36 -0
- package/dist-lib/lib/assistant-client.d.ts +1 -0
- package/dist-lib/lib/assistant-client.js +40 -19
- package/dist-lib/lib/assistant-tree.d.ts +2 -0
- package/dist-lib/lib/assistant-tree.js +41 -1
- package/dist-lib/lib/assistant.d.ts +15 -0
- package/dist-lib/lib/assistant.js +474 -89
- package/dist-lib/lib/client.d.ts +1 -0
- package/dist-lib/lib/client.js +4 -1
- package/dist-lib/lib/compaction.js +2 -2
- package/dist-lib/lib/core/agent.js +12 -45
- package/dist-lib/lib/core/approval-rules.js +1 -8
- package/dist-lib/lib/core/archived-mesh.d.ts +2 -1
- package/dist-lib/lib/core/archived-mesh.js +12 -8
- package/dist-lib/lib/core/chat-copy.d.ts +18 -3
- package/dist-lib/lib/core/chat-copy.js +74 -25
- package/dist-lib/lib/core/chat-fork.js +15 -6
- package/dist-lib/lib/core/chat-group.js +16 -24
- package/dist-lib/lib/core/chat-move.d.ts +9 -0
- package/dist-lib/lib/core/chat-move.js +94 -3
- package/dist-lib/lib/core/chat-order.js +12 -18
- package/dist-lib/lib/core/chat.js +38 -31
- package/dist-lib/lib/core/chunk.d.ts +2 -2
- package/dist-lib/lib/core/chunk.js +18 -25
- package/dist-lib/lib/core/collections.d.ts +2 -0
- package/dist-lib/lib/core/collections.js +2 -0
- package/dist-lib/lib/core/contract/activity.d.ts +4 -0
- package/dist-lib/lib/core/contract/activity.js +34 -4
- package/dist-lib/lib/core/contract/chat-group.d.ts +1 -0
- package/dist-lib/lib/core/contract/chat-group.js +21 -1
- package/dist-lib/lib/core/contract/chat.d.ts +9 -0
- package/dist-lib/lib/core/contract/chat.js +127 -5
- package/dist-lib/lib/core/contract/chunks.d.ts +1 -0
- package/dist-lib/lib/core/contract/chunks.js +37 -6
- package/dist-lib/lib/core/contract/features.d.ts +21 -0
- package/dist-lib/lib/core/contract/features.js +22 -0
- package/dist-lib/lib/core/contract/index.js +2 -0
- package/dist-lib/lib/core/contract/indexing.js +4 -2
- package/dist-lib/lib/core/contract/knowledge.js +5 -4
- package/dist-lib/lib/core/contract/members.js +16 -10
- package/dist-lib/lib/core/contract/mesh-kind.d.ts +1 -0
- package/dist-lib/lib/core/contract/mesh-kind.js +3 -1
- package/dist-lib/lib/core/contract/projects.d.ts +5 -0
- package/dist-lib/lib/core/contract/projects.js +13 -5
- package/dist-lib/lib/core/contract/roles.js +32 -4
- package/dist-lib/lib/core/contract/run-requests.d.ts +1 -0
- package/dist-lib/lib/core/contract/run-requests.js +35 -2
- package/dist-lib/lib/core/contract/seed-defaults.js +2 -2
- package/dist-lib/lib/core/contract/tool-configs.js +3 -2
- package/dist-lib/lib/core/contract/workspace.d.ts +2 -0
- package/dist-lib/lib/core/contract/workspace.js +40 -7
- package/dist-lib/lib/core/contract/writers.js +2 -2
- package/dist-lib/lib/core/departures.d.ts +3 -1
- package/dist-lib/lib/core/departures.js +3 -0
- package/dist-lib/lib/core/devices.js +1 -8
- package/dist-lib/lib/core/files/attachments.d.ts +2 -0
- package/dist-lib/lib/core/files/attachments.js +19 -1
- package/dist-lib/lib/core/files/index.d.ts +20 -4
- package/dist-lib/lib/core/files/index.js +132 -21
- package/dist-lib/lib/core/files/processing/document.d.ts +4 -0
- package/dist-lib/lib/core/files/processing/document.js +7 -0
- package/dist-lib/lib/core/files/processing/index.d.ts +13 -0
- package/dist-lib/lib/core/files/processing/index.js +144 -12
- package/dist-lib/lib/core/files/processing/protocol.js +13 -34
- package/dist-lib/lib/core/files/processing/state.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/build.d.ts +19 -2
- package/dist-lib/lib/core/files/rag/build.js +123 -19
- package/dist-lib/lib/core/files/rag/failure.js +2 -1
- package/dist-lib/lib/core/files/rag/index.d.ts +11 -3
- package/dist-lib/lib/core/files/rag/index.js +13 -1
- package/dist-lib/lib/core/files/rag/load.d.ts +6 -3
- package/dist-lib/lib/core/files/rag/load.js +27 -6
- package/dist-lib/lib/core/files/rag/plugin-index.d.ts +32 -0
- package/dist-lib/lib/core/files/rag/plugin-index.js +127 -0
- package/dist-lib/lib/core/files/rag/produce.d.ts +5 -3
- package/dist-lib/lib/core/files/rag/produce.js +104 -16
- package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +3 -1
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +62 -13
- package/dist-lib/lib/core/files/rag/text-cache.d.ts +28 -0
- package/dist-lib/lib/core/files/rag/text-cache.js +141 -0
- package/dist-lib/lib/core/files/records/knowledge.d.ts +1 -3
- package/dist-lib/lib/core/files/records/knowledge.js +7 -40
- package/dist-lib/lib/core/files/records/reclaim.js +5 -10
- package/dist-lib/lib/core/files/upload.js +68 -41
- package/dist-lib/lib/core/fs-drives.js +14 -26
- package/dist-lib/lib/core/invite.d.ts +1 -0
- package/dist-lib/lib/core/invite.js +4 -2
- package/dist-lib/lib/core/local/files.d.ts +1 -1
- package/dist-lib/lib/core/local/files.js +5 -5
- package/dist-lib/lib/core/local/index.d.ts +13 -6
- package/dist-lib/lib/core/local/index.js +103 -69
- package/dist-lib/lib/core/local/run-logs.d.ts +1 -1
- package/dist-lib/lib/core/local/run-logs.js +5 -5
- package/dist-lib/lib/core/mesh-processor.d.ts +19 -0
- package/dist-lib/lib/core/mesh-processor.js +87 -0
- package/dist-lib/lib/core/mesh.d.ts +48 -5
- package/dist-lib/lib/core/mesh.js +318 -129
- package/dist-lib/lib/core/migrations/agent-catalog.js +2 -8
- package/dist-lib/lib/core/migrations/agent-tools-scope.js +5 -11
- package/dist-lib/lib/core/migrations/workspace-from-0-21/index.d.ts +88 -0
- package/dist-lib/lib/core/migrations/workspace-from-0-21/index.js +731 -0
- package/dist-lib/lib/core/migrations/writer-links.d.ts +2 -0
- package/dist-lib/lib/core/migrations/writer-links.js +32 -0
- package/dist-lib/lib/core/project-keys.d.ts +6 -0
- package/dist-lib/lib/core/project-keys.js +11 -0
- package/dist-lib/lib/core/public-mesh.d.ts +3 -0
- package/dist-lib/lib/core/public-mesh.js +10 -8
- package/dist-lib/lib/core/run-requests.d.ts +3 -0
- package/dist-lib/lib/core/run-requests.js +21 -1
- package/dist-lib/lib/core/skill-availability.d.ts +33 -0
- package/dist-lib/lib/core/skill-availability.js +67 -0
- package/dist-lib/lib/core/sync/background.d.ts +0 -1
- package/dist-lib/lib/core/sync/background.js +2 -1
- package/dist-lib/lib/core/sync/changed.d.ts +4 -2
- package/dist-lib/lib/core/sync/changed.js +1 -1
- package/dist-lib/lib/core/sync/index.js +52 -10
- package/dist-lib/lib/core/sync/view-updates.d.ts +18 -12
- package/dist-lib/lib/core/sync/view-updates.js +82 -91
- package/dist-lib/lib/core/sync-status.js +97 -41
- package/dist-lib/lib/core/tool-activity.js +6 -12
- package/dist-lib/lib/core/tool-configs.js +17 -29
- package/dist-lib/lib/core/upgrade-summary.d.ts +19 -0
- package/dist-lib/lib/core/upgrade-summary.js +67 -0
- package/dist-lib/lib/core/view-read.d.ts +4 -0
- package/dist-lib/lib/core/view-read.js +23 -0
- package/dist-lib/lib/core/workspace-upgrade.d.ts +7 -0
- package/dist-lib/lib/core/workspace-upgrade.js +27 -16
- package/dist-lib/lib/core.d.ts +39 -42
- package/dist-lib/lib/core.js +661 -639
- package/dist-lib/lib/errors.d.ts +20 -0
- package/dist-lib/lib/errors.js +20 -0
- package/dist-lib/lib/llm-model-names.d.ts +1 -1
- package/dist-lib/lib/llm-model-names.js +1 -1
- package/dist-lib/lib/mesh-scoped-engine.js +4 -0
- package/dist-lib/lib/model-context.js +1 -2
- package/dist-lib/lib/probe-rounds.d.ts +7 -2
- package/dist-lib/lib/probe-rounds.js +6 -1
- package/dist-lib/lib/run-transcript.d.ts +4 -1
- package/dist-lib/lib/run-transcript.js +15 -6
- package/dist-lib/schema/engine.js +83 -6
- package/dist-lib/schema/indexes.d.ts +3 -0
- package/dist-lib/schema/indexes.js +5 -0
- package/dist-lib/schema/local.js +11 -2
- package/dist-lib/schema/qvac.js +49 -5
- package/dist-lib/spec/bind.js +34 -0
- package/dist-lib/spec/calls.js +5 -0
- package/dist-lib/spec/capabilities.d.ts +17 -0
- package/dist-lib/spec/hrpc/hrpc.json +65 -0
- package/dist-lib/spec/hrpc/index.js +68 -5
- package/dist-lib/spec/hrpc/messages.js +260 -23
- package/dist-lib/spec/hyperschema/index.js +260 -23
- package/dist-lib/spec/hyperschema/schema.json +181 -0
- package/dist-lib/spec/hyperschema/types.d.ts +48 -0
- package/dist-lib/spec/local/hyperdb/messages.js +270 -224
- package/dist-lib/spec/local/hyperschema/index.js +73 -38
- package/dist-lib/spec/local/hyperschema/schema.json +31 -0
- package/dist-lib/spec/local/hyperschema/types.d.ts +8 -0
- package/dist-lib/spec/mesh/hyperdb/db.json +39 -2
- package/dist-lib/spec/mesh/hyperdb/index.js +120 -3
- package/dist-lib/spec/mesh/hyperdb/messages.js +1328 -838
- package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +30 -0
- package/dist-lib/spec/mesh/hyperdispatch/index.js +86 -1
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +682 -287
- package/dist-lib/spec/mesh/hyperschema/index.js +682 -287
- package/dist-lib/spec/mesh/hyperschema/schema.json +201 -0
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +52 -0
- package/package.json +75 -70
- package/tui/README.md +2 -1
- package/tui/app.mjs +28 -7
- package/tui/boot.mjs +5 -1
- package/tui/lib/attachment-files.mjs +82 -0
- package/tui/lib/reopen-meshes.mjs +15 -0
- package/tui/main.mjs +4 -43
- package/worker/assistant-sidecar.mjs +10 -3
- package/worker/stow-entry.mjs +3 -52
|
@@ -1,18 +1,42 @@
|
|
|
1
1
|
import { liveDeviceForWriter, trackActivity } from './activity.js';
|
|
2
2
|
import { meshKind } from './mesh-kind.js';
|
|
3
|
-
import {
|
|
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';
|
|
3
|
+
import { FEATURES, isFeatureSupported } from './features.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, MOVED_OUT_CHATS, 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
|
}
|
|
8
8
|
export async function foreignChat(tx, chatId) {
|
|
9
9
|
if (!chatId ||
|
|
10
|
-
(await
|
|
10
|
+
!(await isFeatureSupported(tx, FEATURES.PROJECT_OWN_CHATS)) ||
|
|
11
11
|
(await meshKind(tx)) !== 'project') {
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
14
|
return (await tx.get(CHATS, { id: chatId })) === null;
|
|
15
15
|
}
|
|
16
|
+
export function nextUpdatedAt(prev, at) {
|
|
17
|
+
return Math.max(at, (prev ?? 0) + 1);
|
|
18
|
+
}
|
|
19
|
+
export const PATCHABLE_CHAT = [
|
|
20
|
+
'title',
|
|
21
|
+
'agentId',
|
|
22
|
+
'ragEnabled',
|
|
23
|
+
'webSearchEnabled',
|
|
24
|
+
'groupId',
|
|
25
|
+
'rank',
|
|
26
|
+
'rankedAt',
|
|
27
|
+
'projectId',
|
|
28
|
+
'knowledgeSourcesOff',
|
|
29
|
+
'suggestion'
|
|
30
|
+
];
|
|
31
|
+
export function patched(row, { from, fields, patchable }) {
|
|
32
|
+
const out = { ...row };
|
|
33
|
+
for (const field of patchable) {
|
|
34
|
+
if (fields?.includes(field)) {
|
|
35
|
+
out[field] = from[field];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
16
40
|
export function registerChatRoutes(router) {
|
|
17
41
|
router.add('@qvac/put-chat', trackActivity(async ({ chat }, { tx, log }) => {
|
|
18
42
|
const existing = await tx.get(CHATS, { id: chat.id });
|
|
@@ -23,7 +47,10 @@ export function registerChatRoutes(router) {
|
|
|
23
47
|
const readThrough = (await frozenRead(tx, existing))
|
|
24
48
|
? existing?.readThrough || undefined
|
|
25
49
|
: Math.max(existing?.readThrough || 0, chat.readThrough || 0) || undefined;
|
|
26
|
-
if (existing &&
|
|
50
|
+
if (existing &&
|
|
51
|
+
!chat.deletedAt &&
|
|
52
|
+
(existing.updatedAt ?? 0) > (chat.updatedAt ?? 0) &&
|
|
53
|
+
!(await isFeatureSupported(tx, FEATURES.KEEP_STALE_PUTS))) {
|
|
27
54
|
if (readThrough === (existing.readThrough || undefined)) {
|
|
28
55
|
log?.debug('contract', 'put-chat dropped: stale updatedAt', { id: chat.id });
|
|
29
56
|
return;
|
|
@@ -38,10 +65,13 @@ export function registerChatRoutes(router) {
|
|
|
38
65
|
}
|
|
39
66
|
const row = { ...chat, readThrough };
|
|
40
67
|
await tx.insert(CHATS, row);
|
|
68
|
+
await clearMovedOut(tx, chat.id);
|
|
41
69
|
log?.debug('contract', existing ? 'chat updated' : 'chat created', { id: chat.id });
|
|
42
70
|
return row;
|
|
43
71
|
}));
|
|
72
|
+
router.add('@qvac/patch-chat', trackActivity(patchChat));
|
|
44
73
|
router.add('@qvac/mark-chat-read', trackActivity(markChatRead));
|
|
74
|
+
router.add('@qvac/remove-chat-copy', trackActivity(removeChatCopy));
|
|
45
75
|
router.add('@qvac/purge-chat', trackActivity(async ({ chatId, at }, { tx, log }) => {
|
|
46
76
|
const chat = await tx.get(CHATS, { id: chatId });
|
|
47
77
|
if (!chat?.deletedAt) {
|
|
@@ -58,8 +88,100 @@ export function registerChatRoutes(router) {
|
|
|
58
88
|
return purged;
|
|
59
89
|
}));
|
|
60
90
|
}
|
|
91
|
+
async function removeChatCopy(op, { tx, log }) {
|
|
92
|
+
const { chatId } = op;
|
|
93
|
+
const chat = await tx.get(CHATS, { id: chatId });
|
|
94
|
+
const moved = chat ? !chat.deletedAt && chat.updatedAt === op.updatedAt : op.updatedAt === 0;
|
|
95
|
+
if (!moved || !(await isFeatureSupported(tx, FEATURES.CHAT_COPY_REMOVAL))) {
|
|
96
|
+
log?.debug('contract', 'remove-chat-copy dropped: the copy changed or is not one', { chatId });
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
await removeNamed(tx, op);
|
|
100
|
+
if (chat && !(await holdsRows(tx, chatId))) {
|
|
101
|
+
await removeChatRow(tx, chatId);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
await tx.insert(MOVED_OUT_CHATS, { chatId });
|
|
105
|
+
}
|
|
106
|
+
log?.debug('contract', 'chat copy rows removed', { chatId });
|
|
107
|
+
}
|
|
108
|
+
async function removeNamed(tx, op) {
|
|
109
|
+
const { chatId } = op;
|
|
110
|
+
for (const id of op.chunkIds ?? []) {
|
|
111
|
+
const chunk = await tx.get(CHUNKS, { id });
|
|
112
|
+
if (chunk?.chatId === chatId) {
|
|
113
|
+
await tx.delete(CHUNKS, { id });
|
|
114
|
+
await tx.delete(CHAT_CHUNKS, { chatId, seq: chunk.seq });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (const id of op.knowledgeIds ?? []) {
|
|
118
|
+
if ((await tx.get(KNOWLEDGE, { id }))?.chatId === chatId) {
|
|
119
|
+
await removeKnowledgeRows(tx, id);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (const id of op.toolActivityIds ?? []) {
|
|
123
|
+
if ((await tx.get(TOOL_ACTIVITY, { id }))?.chatId === chatId) {
|
|
124
|
+
await tx.delete(TOOL_ACTIVITY, { id });
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async function holdsRows(tx, chatId) {
|
|
129
|
+
const inChat = { gte: { chatId }, lte: { chatId } };
|
|
130
|
+
for (const index of [CHUNKS_BY_CHAT, KNOWLEDGE_BY_CHAT]) {
|
|
131
|
+
for await (const row of tx.find(index, inChat)) {
|
|
132
|
+
return !!row;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
async function removeChatRow(tx, chatId) {
|
|
138
|
+
const inChat = { gte: { chatId }, lte: { chatId } };
|
|
139
|
+
for (const read of await tx.find(CHAT_READS, inChat).toArray()) {
|
|
140
|
+
await tx.delete(CHAT_READS, { chatId, memberId: read.memberId });
|
|
141
|
+
}
|
|
142
|
+
const statuses = tx.find(INDEXING_STATUS_BY_CHAT, inChat);
|
|
143
|
+
for (const status of await statuses.toArray()) {
|
|
144
|
+
await tx.delete(INDEXING_STATUS, { id: status.id });
|
|
145
|
+
}
|
|
146
|
+
await tx.delete(CHATS, { id: chatId });
|
|
147
|
+
await tx.insert(MOVED_OUT_CHATS, { chatId });
|
|
148
|
+
}
|
|
149
|
+
export async function movedOut(tx, chatId) {
|
|
150
|
+
if (!(await isFeatureSupported(tx, FEATURES.CHAT_COPY_REMOVAL))) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
return (await tx.get(MOVED_OUT_CHATS, { chatId })) !== null;
|
|
154
|
+
}
|
|
155
|
+
async function clearMovedOut(tx, chatId) {
|
|
156
|
+
if (await movedOut(tx, chatId)) {
|
|
157
|
+
await tx.delete(MOVED_OUT_CHATS, { chatId });
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async function removeKnowledgeRows(tx, knowledgeId) {
|
|
161
|
+
const ofKnowledge = { gte: { knowledgeId }, lte: { knowledgeId } };
|
|
162
|
+
const artifacts = tx.find(KNOWLEDGE_ARTIFACTS_BY_KNOWLEDGE, ofKnowledge);
|
|
163
|
+
for (const artifact of await artifacts.toArray()) {
|
|
164
|
+
await tx.delete(KNOWLEDGE_ARTIFACTS, { id: artifact.id });
|
|
165
|
+
}
|
|
166
|
+
await tx.delete(KNOWLEDGE, { id: knowledgeId });
|
|
167
|
+
}
|
|
168
|
+
async function patchChat({ chat, fields }, { tx, log }) {
|
|
169
|
+
const existing = await tx.get(CHATS, { id: chat.id });
|
|
170
|
+
if (existing?.deletedAt) {
|
|
171
|
+
log?.debug('contract', 'patch-chat dropped: chat is deleted', { id: chat.id });
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const row = {
|
|
175
|
+
...patched(existing ?? chat, { from: chat, fields, patchable: PATCHABLE_CHAT }),
|
|
176
|
+
updatedAt: nextUpdatedAt(existing?.updatedAt, chat.updatedAt ?? 0)
|
|
177
|
+
};
|
|
178
|
+
await tx.insert(CHATS, row);
|
|
179
|
+
await clearMovedOut(tx, chat.id);
|
|
180
|
+
log?.debug('contract', 'chat patched', { id: chat.id });
|
|
181
|
+
return row;
|
|
182
|
+
}
|
|
61
183
|
async function frozenRead(tx, existing) {
|
|
62
|
-
return !!existing && (await
|
|
184
|
+
return !!existing && (await isFeatureSupported(tx, FEATURES.READ_ON_MEMBER_ROW));
|
|
63
185
|
}
|
|
64
186
|
async function markChatRead(read, { tx, node, log }) {
|
|
65
187
|
const { chatId } = read;
|
|
@@ -5,5 +5,6 @@ import type { RouterContext } from './types.ts';
|
|
|
5
5
|
export declare function runRequestOf(db: HyperDB, chatId: string, runId: string): Promise<QvacChunk | null>;
|
|
6
6
|
type Signed = Pick<RouterContext, 'tx' | 'node'>;
|
|
7
7
|
export declare function ownRunRequest(context: Signed, chatId: string | null | undefined, runId: string): Promise<QvacChunk | null>;
|
|
8
|
+
export declare function mayEditChunk(tx: HyperDB, chunk: QvacChunk, writerKey: Buffer): Promise<boolean>;
|
|
8
9
|
export declare function registerChunkRoutes(router: Router): void;
|
|
9
10
|
export {};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { devicesByWriterKey, liveDeviceForWriter, trackActivity } from './activity.js';
|
|
2
|
-
import { deleteChatChunks, foreignChat, isPurged, putChunk } from './chat.js';
|
|
2
|
+
import { deleteChatChunks, foreignChat, isPurged, movedOut, 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
|
+
import { FEATURES, isFeatureSupported } from './features.js';
|
|
5
6
|
import { runHasTerminalStatus, runnerRefusal, TERMINAL_RUN_STATES } from './run-requests.js';
|
|
6
7
|
import { CHUNK_PAYLOAD_FIELDS, ragSourcesWithinBounds } from '../../../schema/qvac.js';
|
|
7
8
|
import b4a from 'b4a';
|
|
8
|
-
import { CHAT_CHUNKS, CHUNKS, CHUNKS_BY_CHAT, DEVICES, RUN_REQUEST_BY_RUN } from '../collections.js';
|
|
9
|
+
import { CHAT_CHUNKS, CHUNKS, CHUNKS_BY_CHAT, DEVICES, RUN_REQUEST_BY_RUN, WRITER_ACTIVITY } from '../collections.js';
|
|
9
10
|
import { isProbeRound } from '../../probe-rounds.js';
|
|
10
11
|
const CREDITED_CHUNK_TYPES = new Set(['run-request', 'run-status']);
|
|
11
12
|
export function runRequestOf(db, chatId, runId) {
|
|
@@ -63,6 +64,35 @@ async function isOriginWriter(tx, chunk, writerKey) {
|
|
|
63
64
|
const device = await tx.get(DEVICES, { id: chunk.originDeviceId });
|
|
64
65
|
return !!device?.writerKey && b4a.equals(device.writerKey, writerKey);
|
|
65
66
|
}
|
|
67
|
+
async function signerDevice(tx, writerKey) {
|
|
68
|
+
const activity = await tx.get(WRITER_ACTIVITY, { writerKey });
|
|
69
|
+
const id = activity?.deviceId ?? (await devicesByWriterKey(tx, writerKey).one())?.id;
|
|
70
|
+
return id ? tx.get(DEVICES, { id }) : null;
|
|
71
|
+
}
|
|
72
|
+
async function isOriginsPerson(tx, chunk, writerKey) {
|
|
73
|
+
const signer = await signerDevice(tx, writerKey);
|
|
74
|
+
if (!signer || signer.revoked) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
if (b4a.equals(signer.id, chunk.originDeviceId)) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
const origin = await tx.get(DEVICES, { id: chunk.originDeviceId });
|
|
81
|
+
const claims = !(await projectRules(tx));
|
|
82
|
+
const [mine, theirs] = [personOf(signer, claims), origin && personOf(origin, claims)];
|
|
83
|
+
if (mine || theirs) {
|
|
84
|
+
return !!mine && !!theirs && b4a.equals(mine, theirs);
|
|
85
|
+
}
|
|
86
|
+
return claims;
|
|
87
|
+
}
|
|
88
|
+
export async function mayEditChunk(tx, chunk, writerKey) {
|
|
89
|
+
const byPerson = chunk.type === 'attachment' && (await isFeatureSupported(tx, FEATURES.PERSON_EDITS_ATTACHMENTS));
|
|
90
|
+
const mayEdit = byPerson ? isOriginsPerson : isOriginWriter;
|
|
91
|
+
return mayEdit(tx, chunk, writerKey);
|
|
92
|
+
}
|
|
93
|
+
function personOf(device, claims) {
|
|
94
|
+
return device.memberId ?? (claims ? device.claimedMemberId : null) ?? null;
|
|
95
|
+
}
|
|
66
96
|
async function isAdmittedWriter(tx, writerKey) {
|
|
67
97
|
for await (const device of devicesByWriterKey(tx, writerKey)) {
|
|
68
98
|
if (!device.revoked)
|
|
@@ -86,11 +116,12 @@ export function registerChunkRoutes(router) {
|
|
|
86
116
|
if (chunk) {
|
|
87
117
|
return;
|
|
88
118
|
}
|
|
89
|
-
if (await
|
|
119
|
+
if (!(await isFeatureSupported(tx, FEATURES.KEEP_LATE_CHUNKS)) &&
|
|
120
|
+
(await isPurged(tx, op.chatId))) {
|
|
90
121
|
log?.debug('contract', 'append-chunk dropped: chat is purged', { id: op.id });
|
|
91
122
|
return;
|
|
92
123
|
}
|
|
93
|
-
if (await foreignChat(tx, op.chatId)) {
|
|
124
|
+
if ((await foreignChat(tx, op.chatId)) && !(await movedOut(tx, op.chatId))) {
|
|
94
125
|
log?.warn('contract', 'append-chunk dropped: the chat is not in this project', {
|
|
95
126
|
id: op.id
|
|
96
127
|
});
|
|
@@ -185,8 +216,8 @@ export function registerChunkRoutes(router) {
|
|
|
185
216
|
log?.debug('contract', 'update-chunk dropped: unknown chunk', { id: op.id });
|
|
186
217
|
return;
|
|
187
218
|
}
|
|
188
|
-
if (!(await
|
|
189
|
-
log?.warn('contract',
|
|
219
|
+
if (!(await mayEditChunk(tx, chunk, node.key))) {
|
|
220
|
+
log?.warn('contract', "update-chunk dropped: writer is not the origin's device", {
|
|
190
221
|
id: op.id
|
|
191
222
|
});
|
|
192
223
|
return;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type HyperDB from 'hyperdb';
|
|
2
|
+
export declare const FEATURES: {
|
|
3
|
+
readonly KEEP_LATE_CHUNKS: 1;
|
|
4
|
+
readonly KEEP_STALE_PUTS: 1;
|
|
5
|
+
readonly PERSON_EDITS_ATTACHMENTS: 1;
|
|
6
|
+
readonly ROLE_ROUTES: 1;
|
|
7
|
+
readonly WORKSPACE_UPGRADE: 1;
|
|
8
|
+
readonly PROJECT_MEMBERSHIP: 1;
|
|
9
|
+
readonly PROJECT_OWN_CHATS: 1;
|
|
10
|
+
readonly KNOWLEDGE_BASE_IN_PROJECT: 1;
|
|
11
|
+
readonly READ_ON_MEMBER_ROW: 1;
|
|
12
|
+
readonly ACCOUNT_OWN_MEMBER: 1;
|
|
13
|
+
readonly ACCOUNT_SEEDS_NO_CHAT: 1;
|
|
14
|
+
readonly TOOL_CONFIGS_WITHOUT_AGENT: 1;
|
|
15
|
+
readonly SHIPPED_ROWS_INDEXED: 1;
|
|
16
|
+
readonly INDEXING_STALE_LEASE: 1;
|
|
17
|
+
readonly OWN_LEAVE_HOLDS: 1;
|
|
18
|
+
readonly CHAT_COPY_REMOVAL: 1;
|
|
19
|
+
};
|
|
20
|
+
export type Feature = (typeof FEATURES)[keyof typeof FEATURES];
|
|
21
|
+
export declare function isFeatureSupported(tx: HyperDB, feature: Feature): Promise<boolean>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { WORKSPACES_RULES, rulesVersion } from './mesh-rules.js';
|
|
2
|
+
export const FEATURES = {
|
|
3
|
+
KEEP_LATE_CHUNKS: WORKSPACES_RULES,
|
|
4
|
+
KEEP_STALE_PUTS: WORKSPACES_RULES,
|
|
5
|
+
PERSON_EDITS_ATTACHMENTS: WORKSPACES_RULES,
|
|
6
|
+
ROLE_ROUTES: WORKSPACES_RULES,
|
|
7
|
+
WORKSPACE_UPGRADE: WORKSPACES_RULES,
|
|
8
|
+
PROJECT_MEMBERSHIP: WORKSPACES_RULES,
|
|
9
|
+
PROJECT_OWN_CHATS: WORKSPACES_RULES,
|
|
10
|
+
KNOWLEDGE_BASE_IN_PROJECT: WORKSPACES_RULES,
|
|
11
|
+
READ_ON_MEMBER_ROW: WORKSPACES_RULES,
|
|
12
|
+
ACCOUNT_OWN_MEMBER: WORKSPACES_RULES,
|
|
13
|
+
ACCOUNT_SEEDS_NO_CHAT: WORKSPACES_RULES,
|
|
14
|
+
TOOL_CONFIGS_WITHOUT_AGENT: WORKSPACES_RULES,
|
|
15
|
+
SHIPPED_ROWS_INDEXED: WORKSPACES_RULES,
|
|
16
|
+
INDEXING_STALE_LEASE: WORKSPACES_RULES,
|
|
17
|
+
OWN_LEAVE_HOLDS: WORKSPACES_RULES,
|
|
18
|
+
CHAT_COPY_REMOVAL: WORKSPACES_RULES
|
|
19
|
+
};
|
|
20
|
+
export async function isFeatureSupported(tx, feature) {
|
|
21
|
+
return (await rulesVersion(tx)) >= feature;
|
|
22
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { registerActivityRoutes } from './activity.js';
|
|
1
2
|
import { registerAgentJoinRoutes } from './agent-join.js';
|
|
2
3
|
import { registerAgentRoutes } from './agents.js';
|
|
3
4
|
import { registerApprovalRuleRoutes } from './approval-rules.js';
|
|
@@ -53,6 +54,7 @@ function writersOnly(router) {
|
|
|
53
54
|
export function registerRoutes(target, { role = 'account' } = {}) {
|
|
54
55
|
const router = modelOutputOnly(writersOnly(roleDrops(target, role)));
|
|
55
56
|
registerWriterRoutes(router);
|
|
57
|
+
registerActivityRoutes(router);
|
|
56
58
|
registerChunkRoutes(router);
|
|
57
59
|
registerModelRequestRoutes(router);
|
|
58
60
|
registerRunRequestRoutes(router);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { trackActivity } from './activity.js';
|
|
2
2
|
import { oldestVersion } from './oldest-version.js';
|
|
3
3
|
import { claimSource } from '../files/index.js';
|
|
4
|
-
import {
|
|
4
|
+
import { FEATURES, isFeatureSupported } from './features.js';
|
|
5
5
|
import b4a from 'b4a';
|
|
6
6
|
import { INDEXING_STATUS, INDEXING_STATUS_BY_KNOWLEDGE, KNOWLEDGE, KNOWLEDGE_ARTIFACTS } from '../collections.js';
|
|
7
7
|
export const INDEXING_CLAIM_TTL_MS = 10 * 60 * 1000;
|
|
@@ -122,5 +122,7 @@ export function registerIndexingRoutes(router) {
|
|
|
122
122
|
}));
|
|
123
123
|
}
|
|
124
124
|
async function claimLeaseMs(tx) {
|
|
125
|
-
return (await
|
|
125
|
+
return (await isFeatureSupported(tx, FEATURES.INDEXING_STALE_LEASE))
|
|
126
|
+
? INDEXING_STALE_MS
|
|
127
|
+
: INDEXING_CLAIM_TTL_MS;
|
|
126
128
|
}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { trackActivity } from './activity.js';
|
|
2
|
-
import { foreignChat } from './chat.js';
|
|
2
|
+
import { foreignChat, movedOut } from './chat.js';
|
|
3
3
|
import { oldestVersion } from './oldest-version.js';
|
|
4
4
|
import { meshKind } from './mesh-kind.js';
|
|
5
5
|
import { inProject, signerMember } from './projects.js';
|
|
6
|
-
import {
|
|
6
|
+
import { FEATURES, isFeatureSupported } from './features.js';
|
|
7
7
|
import { assertArtifactOutput } from '../files/index.js';
|
|
8
8
|
import { CHATS, KNOWLEDGE, KNOWLEDGE_ARTIFACTS, KNOWLEDGE_CAPS } from '../collections.js';
|
|
9
9
|
export const KNOWLEDGE_CAP_ROW = 'mesh';
|
|
10
10
|
async function misplaced(tx, chatId) {
|
|
11
11
|
if (chatId) {
|
|
12
|
-
return foreignChat(tx, chatId);
|
|
12
|
+
return (await foreignChat(tx, chatId)) && !(await movedOut(tx, chatId));
|
|
13
13
|
}
|
|
14
|
-
return (await
|
|
14
|
+
return ((await isFeatureSupported(tx, FEATURES.KNOWLEDGE_BASE_IN_PROJECT)) &&
|
|
15
|
+
(await meshKind(tx)) !== 'project');
|
|
15
16
|
}
|
|
16
17
|
export function registerKnowledgeRoutes(router) {
|
|
17
18
|
router.add('@qvac/add-knowledge', trackActivity(async ({ knowledge }, { tx, log }) => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import crypto from 'hypercore-crypto';
|
|
2
2
|
import { bareDeviceProof, claimAttestation, verifyDeviceProof, verifyMemberClaim, verifyRecoveryClaim } from '../identity.js';
|
|
3
3
|
import { isKickedRow } from '../helpers/index.js';
|
|
4
|
-
import { liveDeviceForWriter, trackActivity } from './activity.js';
|
|
4
|
+
import { liveDeviceForWriter, markWriterLinked, trackActivity } from './activity.js';
|
|
5
5
|
import { accountKind, sharedKind } from './mesh-kind.js';
|
|
6
|
-
import {
|
|
6
|
+
import { FEATURES, isFeatureSupported } from './features.js';
|
|
7
7
|
import { admitDevice } from './writers.js';
|
|
8
8
|
import b4a from 'b4a';
|
|
9
9
|
import { DEVICES, MEMBERS, MESH_FOUNDERS } from '../collections.js';
|
|
@@ -32,7 +32,7 @@ export async function accountMember(tx) {
|
|
|
32
32
|
return only;
|
|
33
33
|
}
|
|
34
34
|
export async function outsideAccount(tx, memberId) {
|
|
35
|
-
if ((await
|
|
35
|
+
if (!(await isFeatureSupported(tx, FEATURES.ACCOUNT_OWN_MEMBER)) || !(await accountKind(tx))) {
|
|
36
36
|
return false;
|
|
37
37
|
}
|
|
38
38
|
const own = await accountMember(tx);
|
|
@@ -49,11 +49,11 @@ export async function linkMember(tx, device, { member, proof }) {
|
|
|
49
49
|
if (!existing) {
|
|
50
50
|
await tx.insert(MEMBERS, joined);
|
|
51
51
|
}
|
|
52
|
-
await tx
|
|
52
|
+
await linkDevice(tx, device, { memberId: member.id, proof, attestedAt: member.joinedAt });
|
|
53
53
|
return joined;
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
|
|
55
|
+
async function linkDevice(tx, device, { memberId, proof, attestedAt }) {
|
|
56
|
+
const linked = {
|
|
57
57
|
...device,
|
|
58
58
|
memberId,
|
|
59
59
|
memberProof: proof,
|
|
@@ -61,6 +61,8 @@ function link(device, { memberId, proof, attestedAt }) {
|
|
|
61
61
|
claimedMemberId: null,
|
|
62
62
|
inviteToken: null
|
|
63
63
|
};
|
|
64
|
+
await tx.insert(DEVICES, linked);
|
|
65
|
+
await markWriterLinked(tx, linked);
|
|
64
66
|
}
|
|
65
67
|
export function registerMemberRoutes(router) {
|
|
66
68
|
router.add('@qvac/mint-member', trackActivity(async ({ member, proof }, { tx, node, log }) => {
|
|
@@ -89,7 +91,7 @@ export function registerMemberRoutes(router) {
|
|
|
89
91
|
};
|
|
90
92
|
await tx.insert(MEMBERS, minted);
|
|
91
93
|
await tx.insert(MESH_FOUNDERS, { id: 'mesh', memberId: member.id });
|
|
92
|
-
await tx
|
|
94
|
+
await linkDevice(tx, minter, { memberId: member.id, proof, attestedAt: member.joinedAt });
|
|
93
95
|
log?.info('contract', 'member minted', { id: b4a.toHex(member.id).slice(0, 16) });
|
|
94
96
|
return minted;
|
|
95
97
|
}));
|
|
@@ -226,11 +228,11 @@ export function registerMemberRoutes(router) {
|
|
|
226
228
|
if (!admitted) {
|
|
227
229
|
return;
|
|
228
230
|
}
|
|
229
|
-
await tx
|
|
231
|
+
await linkDevice(tx, admitted, {
|
|
230
232
|
memberId,
|
|
231
233
|
proof: deviceProof,
|
|
232
234
|
attestedAt: payload.device.joinedAt
|
|
233
|
-
})
|
|
235
|
+
});
|
|
234
236
|
log?.info('contract', 'device recovered into its member', ids);
|
|
235
237
|
return payload.device;
|
|
236
238
|
}));
|
|
@@ -270,7 +272,11 @@ export function registerMemberRoutes(router) {
|
|
|
270
272
|
log?.debug('contract', 'attest-member-device dropped: not newer than the stored attestation');
|
|
271
273
|
return;
|
|
272
274
|
}
|
|
273
|
-
await tx
|
|
275
|
+
await linkDevice(tx, device, {
|
|
276
|
+
memberId: op.memberId,
|
|
277
|
+
proof: op.proof,
|
|
278
|
+
attestedAt: op.attestedAt
|
|
279
|
+
});
|
|
274
280
|
log?.info('contract', 'device attested to a member', {
|
|
275
281
|
id: b4a.toHex(op.deviceId).slice(0, 16)
|
|
276
282
|
});
|
|
@@ -3,4 +3,5 @@ import type { RouterContext } from './types.ts';
|
|
|
3
3
|
export declare function meshKind(tx: RouterContext['tx']): Promise<string | null>;
|
|
4
4
|
export declare function accountKind(tx: RouterContext['tx']): Promise<boolean>;
|
|
5
5
|
export declare function sharedKind(tx: RouterContext['tx']): Promise<boolean>;
|
|
6
|
+
export declare function isSharedKind(kind: string | null): boolean;
|
|
6
7
|
export declare function registerMeshKindRoutes(router: Router): void;
|
|
@@ -12,7 +12,9 @@ export async function accountKind(tx) {
|
|
|
12
12
|
return kind === null || kind === 'account' || kind === 'public';
|
|
13
13
|
}
|
|
14
14
|
export async function sharedKind(tx) {
|
|
15
|
-
|
|
15
|
+
return isSharedKind(await meshKind(tx));
|
|
16
|
+
}
|
|
17
|
+
export function isSharedKind(kind) {
|
|
16
18
|
return kind === 'shared' || kind === 'workspace' || kind === 'project';
|
|
17
19
|
}
|
|
18
20
|
async function mayMint(kind, { tx, host, node }) {
|
|
@@ -19,5 +19,10 @@ export declare function outsideProject(tx: HyperDB, memberId: Buffer | null | un
|
|
|
19
19
|
export declare function liveMember(tx: HyperDB, memberId: Buffer, since?: number): Promise<boolean>;
|
|
20
20
|
export declare function signerMember({ tx, node }: Signed): Promise<Buffer | null>;
|
|
21
21
|
export declare function projectOfGroup(tx: HyperDB, groupId: string): Promise<QvacProject | null>;
|
|
22
|
+
export interface Birth {
|
|
23
|
+
readonly signer: Buffer;
|
|
24
|
+
readonly groupId?: string | null;
|
|
25
|
+
}
|
|
26
|
+
export declare function bornMembers(tx: HyperDB, { signer, groupId }: Birth): Promise<Buffer[]>;
|
|
22
27
|
export declare function registerProjectRoutes(router: Router): void;
|
|
23
28
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { liveDeviceForWriter, liveDevicesOf, trackActivity } from './activity.js';
|
|
2
2
|
import { meshKind } from './mesh-kind.js';
|
|
3
|
-
import {
|
|
4
|
-
import { isWorkspace, readMemberKey, upgradeMembers } from './workspace.js';
|
|
3
|
+
import { FEATURES, isFeatureSupported } from './features.js';
|
|
4
|
+
import { countedMembers, isWorkspace, readMemberKey, upgradeMembers } from './workspace.js';
|
|
5
5
|
import { dropMemberAgentUses, dropUser } from './agents.js';
|
|
6
6
|
import { dropMemberHostKeys, dropProjectHostKeys, readProjectHostKey } from './project-host-keys.js';
|
|
7
7
|
import { dropListingDeviceKeys, dropProjectDeviceKeys, readProjectDeviceKey } from './project-device-keys.js';
|
|
@@ -54,7 +54,8 @@ export async function addedSince(tx, memberId, at) {
|
|
|
54
54
|
return ((await projectMember(tx, memberId))?.addedAt ?? 0) > at;
|
|
55
55
|
}
|
|
56
56
|
export async function projectRules(tx) {
|
|
57
|
-
return (await
|
|
57
|
+
return ((await isFeatureSupported(tx, FEATURES.PROJECT_MEMBERSHIP)) &&
|
|
58
|
+
(await meshKind(tx)) === 'project');
|
|
58
59
|
}
|
|
59
60
|
export async function outsideProject(tx, memberId) {
|
|
60
61
|
if (!(await projectRules(tx))) {
|
|
@@ -78,6 +79,13 @@ export async function projectOfGroup(tx, groupId) {
|
|
|
78
79
|
async function namesGroup(tx, groupId) {
|
|
79
80
|
return groupId === UNGROUPED || !!(await tx.get(CHAT_GROUPS, { id: groupId }));
|
|
80
81
|
}
|
|
82
|
+
export async function bornMembers(tx, { signer, groupId }) {
|
|
83
|
+
if (!groupId) {
|
|
84
|
+
return [signer];
|
|
85
|
+
}
|
|
86
|
+
const counted = (await countedMembers(tx)).filter((id) => !b4a.equals(id, signer));
|
|
87
|
+
return [signer, ...counted];
|
|
88
|
+
}
|
|
81
89
|
async function putProject({ project }, context) {
|
|
82
90
|
const { tx, log } = context;
|
|
83
91
|
if (!(await isWorkspace(tx))) {
|
|
@@ -108,7 +116,7 @@ async function putProject({ project }, context) {
|
|
|
108
116
|
}
|
|
109
117
|
const created = {
|
|
110
118
|
...project,
|
|
111
|
-
memberIds:
|
|
119
|
+
memberIds: await bornMembers(tx, { signer, groupId: project.groupId }),
|
|
112
120
|
createdBy: signer,
|
|
113
121
|
deletedAt: undefined
|
|
114
122
|
};
|
|
@@ -324,7 +332,7 @@ async function putProjectMember({ memberId, addedAt }, context) {
|
|
|
324
332
|
return;
|
|
325
333
|
}
|
|
326
334
|
}
|
|
327
|
-
const row = { memberId, addedAt };
|
|
335
|
+
const row = { memberId, addedAt: host.genesis ? undefined : addedAt };
|
|
328
336
|
await tx.insert(PROJECT_MEMBERS, row);
|
|
329
337
|
return row;
|
|
330
338
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CoreError } from '../../errors.js';
|
|
2
2
|
import { meshKind } from './mesh-kind.js';
|
|
3
|
-
import {
|
|
3
|
+
import { FEATURES, isFeatureSupported } from './features.js';
|
|
4
|
+
import { upgradeWriter } from './workspace.js';
|
|
4
5
|
const ALL = ['account', 'public', 'workspace', 'project'];
|
|
5
6
|
const CONTENT = ['public', 'project'];
|
|
6
7
|
const PRIVATE = ['account', 'project'];
|
|
@@ -42,6 +43,7 @@ export const ROUTE_ROLES = {
|
|
|
42
43
|
'@qvac/put-joined-mesh': PRIVATE,
|
|
43
44
|
'@qvac/remove-member': ALL,
|
|
44
45
|
'@qvac/reindex-agents': ALL,
|
|
46
|
+
'@qvac/reindex-writers': ALL,
|
|
45
47
|
'@qvac/put-mesh-invite-grant': PRIVATE,
|
|
46
48
|
'@qvac/claim-invite': PRIVATE,
|
|
47
49
|
'@qvac/mint-mesh-kind': ALL,
|
|
@@ -80,8 +82,34 @@ export const ROUTE_ROLES = {
|
|
|
80
82
|
'@qvac/agent-join': CONTENT,
|
|
81
83
|
'@qvac/take-run-request': CONTENT,
|
|
82
84
|
'@qvac/put-skill-secret': ['account'],
|
|
83
|
-
'@qvac/
|
|
85
|
+
'@qvac/continue-run-here': CONTENT,
|
|
86
|
+
'@qvac/reindex-chat-chunks': CONTENT,
|
|
87
|
+
'@qvac/patch-chat': CONTENT,
|
|
88
|
+
'@qvac/patch-chat-group': CONTENT,
|
|
89
|
+
'@qvac/remove-chat-copy': PROJECT
|
|
84
90
|
};
|
|
91
|
+
const HISTORY = new Set([
|
|
92
|
+
'@qvac/append-chunk',
|
|
93
|
+
'@qvac/update-chunk',
|
|
94
|
+
'@qvac/resolve-approval',
|
|
95
|
+
'@qvac/add-knowledge',
|
|
96
|
+
'@qvac/remove-knowledge',
|
|
97
|
+
'@qvac/add-knowledge-artifact',
|
|
98
|
+
'@qvac/claim-indexing',
|
|
99
|
+
'@qvac/resolve-indexing',
|
|
100
|
+
'@qvac/put-chat',
|
|
101
|
+
'@qvac/append-tool-activity',
|
|
102
|
+
'@qvac/migrate-agent-catalog',
|
|
103
|
+
'@qvac/put-chat-group',
|
|
104
|
+
'@qvac/purge-chat',
|
|
105
|
+
'@qvac/reindex-chat-chunks'
|
|
106
|
+
]);
|
|
107
|
+
async function asHistory(name, { tx, node }) {
|
|
108
|
+
if (!HISTORY.has(name)) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
return (await meshKind(tx)) !== 'workspace' || upgradeWriter(tx, node.key);
|
|
112
|
+
}
|
|
85
113
|
export function inRole(role, route) {
|
|
86
114
|
return ROUTE_ROLES[route]?.includes(role) ?? false;
|
|
87
115
|
}
|
|
@@ -108,11 +136,11 @@ export function roleDrops(router, role) {
|
|
|
108
136
|
add: (name, handler) => router.add(name, inRole(role, name) && !byKind(role)
|
|
109
137
|
? handler
|
|
110
138
|
: async (op, context) => {
|
|
111
|
-
if ((await
|
|
139
|
+
if (!(await isFeatureSupported(context.tx, FEATURES.ROLE_ROUTES))) {
|
|
112
140
|
return handler(op, context);
|
|
113
141
|
}
|
|
114
142
|
const applied = byKind(role) ? appliedRole(role, await meshKind(context.tx)) : role;
|
|
115
|
-
if (inRole(applied, name)) {
|
|
143
|
+
if (inRole(applied, name) || (await asHistory(name, context))) {
|
|
116
144
|
return handler(op, context);
|
|
117
145
|
}
|
|
118
146
|
context.log?.warn('contract', `${name} dropped: not a route of a ${applied} mesh`);
|
|
@@ -7,4 +7,5 @@ export declare function runHasTerminalStatus(tx: HyperDB, chatId: string, runId:
|
|
|
7
7
|
export declare function runnerRefusal(op: QvacAppendChunkOperation, { tx, node }: RouterContext): Promise<string | null>;
|
|
8
8
|
export declare function runTaker(tx: HyperDB, request: QvacChunk, writerKey: Buffer): Promise<Buffer | null>;
|
|
9
9
|
export declare function openToTake(request: QvacChunk | null): request is QvacChunk;
|
|
10
|
+
export declare function runMover(tx: HyperDB, request: QvacChunk, writerKey: Buffer): Promise<Buffer | null>;
|
|
10
11
|
export declare function registerRunRequestRoutes(router: Router): void;
|
|
@@ -2,12 +2,12 @@ import b4a from 'b4a';
|
|
|
2
2
|
import { liveDeviceForWriter, trackActivity } from './activity.js';
|
|
3
3
|
import { putChunk } from './chat.js';
|
|
4
4
|
import { ownerSigner } from './model-requests.js';
|
|
5
|
-
import {
|
|
5
|
+
import { FEATURES, isFeatureSupported } from './features.js';
|
|
6
6
|
import { chunkTypeOrdinal, terminalRunStates } from '../../../schema/indexes.js';
|
|
7
7
|
import { CHUNKS, CHUNKS_BY_TYPE, DEVICES, TERMINAL_RUN_STATUSES } from '../collections.js';
|
|
8
8
|
export const TERMINAL_RUN_STATES = new Set(terminalRunStates);
|
|
9
9
|
export async function runHasTerminalStatus(tx, chatId, runId) {
|
|
10
|
-
if ((await
|
|
10
|
+
if (!(await isFeatureSupported(tx, FEATURES.SHIPPED_ROWS_INDEXED))) {
|
|
11
11
|
const type = chunkTypeOrdinal('run-status');
|
|
12
12
|
const statuses = tx.find(CHUNKS_BY_TYPE, {
|
|
13
13
|
gte: { chatId, type },
|
|
@@ -49,6 +49,12 @@ export async function runTaker(tx, request, writerKey) {
|
|
|
49
49
|
export function openToTake(request) {
|
|
50
50
|
return request?.type === 'run-request' && !!request.runnerDeviceId && !request.runTakenBy;
|
|
51
51
|
}
|
|
52
|
+
export async function runMover(tx, request, writerKey) {
|
|
53
|
+
const signer = await liveDeviceForWriter(tx, writerKey);
|
|
54
|
+
const asker = !!signer && b4a.equals(signer.id, request.originDeviceId);
|
|
55
|
+
const elsewhere = !!request.runTakenBy && !b4a.equals(request.runTakenBy, request.originDeviceId);
|
|
56
|
+
return asker && elsewhere ? signer.id : null;
|
|
57
|
+
}
|
|
52
58
|
export function registerRunRequestRoutes(router) {
|
|
53
59
|
router.add('@qvac/take-run-request', trackActivity(async (op, { tx, node, log }) => {
|
|
54
60
|
const request = await tx.get(CHUNKS, { id: op.id });
|
|
@@ -78,4 +84,31 @@ export function registerRunRequestRoutes(router) {
|
|
|
78
84
|
await putChunk(tx, taken);
|
|
79
85
|
return taken;
|
|
80
86
|
}));
|
|
87
|
+
router.add('@qvac/continue-run-here', trackActivity(async (op, { tx, node, log }) => {
|
|
88
|
+
const request = await tx.get(CHUNKS, { id: op.id });
|
|
89
|
+
if (request?.type !== 'run-request' || !request.runId) {
|
|
90
|
+
log?.debug('contract', 'continue-run-here dropped: no run-request', { id: op.id });
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const runTakenBy = await runMover(tx, request, node.key);
|
|
94
|
+
if (!runTakenBy) {
|
|
95
|
+
log?.warn('contract', 'continue-run-here dropped: not its asker, or not taken elsewhere', {
|
|
96
|
+
id: op.id
|
|
97
|
+
});
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (await runHasTerminalStatus(tx, request.chatId, request.runId)) {
|
|
101
|
+
log?.debug('contract', 'continue-run-here dropped: the run has ended', { id: op.id });
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const moved = {
|
|
105
|
+
...request,
|
|
106
|
+
runTakenBy,
|
|
107
|
+
runTakenAt: op.at,
|
|
108
|
+
runMovedFrom: request.runTakenBy,
|
|
109
|
+
updatedAt: Math.max(request.updatedAt ?? 0, op.at)
|
|
110
|
+
};
|
|
111
|
+
await putChunk(tx, moved);
|
|
112
|
+
return moved;
|
|
113
|
+
}));
|
|
81
114
|
}
|