@qvac/core 1.0.0-rc.3 → 1.0.0-rc.6
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 +147 -36
- package/README.md +55 -4
- package/dist-lib/index.d.ts +2 -1
- package/dist-lib/lib/api/agents.d.ts +2 -1
- package/dist-lib/lib/api/agents.js +5 -1
- package/dist-lib/lib/api/app-config.d.ts +3 -0
- package/dist-lib/lib/api/app-config.js +20 -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/config.d.ts +6 -2
- package/dist-lib/lib/api/config.js +9 -5
- package/dist-lib/lib/api/device-routes.d.ts +1 -1
- package/dist-lib/lib/api/device-routes.js +3 -1
- package/dist-lib/lib/api/index.d.ts +12 -2
- package/dist-lib/lib/api/index.js +8 -2
- package/dist-lib/lib/api/projects.js +3 -4
- package/dist-lib/lib/api/rag.js +5 -5
- package/dist-lib/lib/api/served.d.ts +2 -2
- package/dist-lib/lib/api/served.js +24 -1
- package/dist-lib/lib/assistant/harness.d.ts +3 -0
- package/dist-lib/lib/assistant/history.js +14 -2
- package/dist-lib/lib/assistant/message.d.ts +1 -0
- package/dist-lib/lib/assistant/model-round.d.ts +3 -0
- package/dist-lib/lib/assistant/model-round.js +18 -4
- package/dist-lib/lib/assistant/round-host.d.ts +2 -0
- package/dist-lib/lib/assistant/round-host.js +8 -0
- package/dist-lib/lib/assistant-tree.d.ts +2 -0
- package/dist-lib/lib/assistant-tree.js +4 -2
- package/dist-lib/lib/assistant.d.ts +12 -1
- package/dist-lib/lib/assistant.js +131 -15
- package/dist-lib/lib/client.js +4 -1
- package/dist-lib/lib/core/agent-copies.js +9 -2
- package/dist-lib/lib/core/agent-hosting.js +9 -4
- package/dist-lib/lib/core/agent.js +3 -1
- 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-copy.d.ts +1 -0
- package/dist-lib/lib/core/chat-copy.js +13 -2
- package/dist-lib/lib/core/chat.d.ts +0 -1
- package/dist-lib/lib/core/chat.js +0 -3
- package/dist-lib/lib/core/chunk.js +4 -3
- package/dist-lib/lib/core/collections.d.ts +7 -7
- package/dist-lib/lib/core/collections.js +7 -7
- package/dist-lib/lib/core/config-value.d.ts +1 -0
- package/dist-lib/lib/core/config-value.js +1 -0
- package/dist-lib/lib/core/contract/project-device-keys.d.ts +4 -2
- package/dist-lib/lib/core/contract/project-device-keys.js +12 -12
- package/dist-lib/lib/core/contract/project-host-keys.d.ts +5 -3
- package/dist-lib/lib/core/contract/project-host-keys.js +22 -11
- package/dist-lib/lib/core/contract/projects.d.ts +4 -2
- package/dist-lib/lib/core/contract/projects.js +29 -17
- package/dist-lib/lib/core/contract/workspace.js +2 -2
- package/dist-lib/lib/core/deleted-agent-runs.d.ts +8 -0
- package/dist-lib/lib/core/deleted-agent-runs.js +57 -0
- package/dist-lib/lib/core/files/index.d.ts +1 -1
- package/dist-lib/lib/core/files/index.js +4 -2
- package/dist-lib/lib/core/helpers/index.d.ts +1 -1
- package/dist-lib/lib/core/helpers/index.js +2 -2
- package/dist-lib/lib/core/local/index.d.ts +6 -0
- package/dist-lib/lib/core/local/index.js +14 -0
- package/dist-lib/lib/core/mesh.d.ts +2 -1
- package/dist-lib/lib/core/mesh.js +7 -5
- package/dist-lib/lib/core/project-keys.d.ts +5 -2
- package/dist-lib/lib/core/project-keys.js +15 -6
- 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/index.js +18 -6
- 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 +10 -1
- package/dist-lib/lib/core.js +165 -31
- package/dist-lib/lib/errors.d.ts +8 -0
- package/dist-lib/lib/errors.js +8 -0
- package/dist-lib/lib/kv-cache-ledger.d.ts +22 -0
- package/dist-lib/lib/kv-cache-ledger.js +72 -0
- package/dist-lib/lib/kv-cache-retention.d.ts +1 -0
- package/dist-lib/lib/kv-cache-retention.js +5 -2
- package/dist-lib/lib/mesh-scoped-engine.js +1 -0
- package/dist-lib/lib/model-memory-cap.d.ts +3 -0
- package/dist-lib/lib/model-memory-cap.js +15 -6
- package/dist-lib/lib/run-replay.d.ts +3 -2
- package/dist-lib/lib/run-replay.js +16 -5
- package/dist-lib/lib/run-transcript.js +1 -1
- package/dist-lib/schema/config.d.ts +1 -1
- package/dist-lib/schema/config.js +1 -1
- package/dist-lib/schema/engine.js +87 -2
- package/dist-lib/schema/qvac.js +66 -3
- 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 +1302 -993
- package/dist-lib/spec/hyperschema/index.js +1302 -993
- package/dist-lib/spec/hyperschema/schema.json +227 -0
- package/dist-lib/spec/hyperschema/types.d.ts +45 -0
- package/dist-lib/spec/mesh/hyperdb/db.json +110 -0
- package/dist-lib/spec/mesh/hyperdb/index.js +498 -2
- package/dist-lib/spec/mesh/hyperdb/messages.js +1385 -892
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +561 -301
- package/dist-lib/spec/mesh/hyperschema/index.js +561 -301
- package/dist-lib/spec/mesh/hyperschema/schema.json +343 -178
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +40 -1
- package/package.json +34 -18
- package/tui/README.md +190 -0
- package/tui/app.mjs +8247 -0
- package/tui/boot.mjs +159 -0
- package/tui/index.mjs +89 -0
- package/tui/lib/boot-timing.mjs +41 -0
- package/tui/lib/busy-words.mjs +116 -0
- package/tui/lib/connect-sheet.mjs +350 -0
- package/tui/lib/device-target.mjs +64 -0
- package/tui/lib/export.mjs +194 -0
- package/tui/lib/folders-command.mjs +84 -0
- package/tui/lib/fork-command.mjs +43 -0
- package/tui/lib/knowledge-command.mjs +190 -0
- package/tui/lib/knowledge-import.mjs +153 -0
- package/tui/lib/local-path.mjs +21 -0
- package/tui/lib/move-command.mjs +17 -0
- package/tui/lib/render.mjs +225 -0
- package/tui/lib/save-file.mjs +88 -0
- package/tui/lib/select.mjs +81 -0
- package/tui/lib/selection.mjs +18 -0
- package/tui/lib/setup.mjs +135 -0
- package/tui/lib/sidebar.mjs +63 -0
- package/tui/lib/skill-connect.mjs +145 -0
- package/tui/lib/splash-art.mjs +107 -0
- package/tui/lib/splash.mjs +18 -0
- package/tui/lib/upload-frames.mjs +9 -0
- package/tui/lib/usage.mjs +59 -0
- package/tui/lib/wrap.mjs +143 -0
- package/tui/main.mjs +279 -0
- package/tui/plugins.mjs +158 -0
- package/worker/assistant-sidecar.mjs +1 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type HyperDB from 'hyperdb';
|
|
2
|
-
import type {
|
|
3
|
-
export
|
|
2
|
+
import type { QvacProjectHostSeal, QvacSetProjectListingOperation } from '../../../spec/mesh/hyperschema/types.d.ts';
|
|
3
|
+
export type HostKeySlot = Pick<QvacProjectHostSeal, 'projectId' | 'deviceId' | 'sealedBy'>;
|
|
4
|
+
export declare function readProjectHostKey(tx: HyperDB, { projectId, deviceId, sealedBy }: HostKeySlot): Promise<QvacProjectHostSeal | null>;
|
|
5
|
+
export declare function projectHostKeys(tx: HyperDB, projectId: Buffer, deviceId: Buffer): Promise<QvacProjectHostSeal[]>;
|
|
4
6
|
export declare function dropProjectHostKeys(tx: HyperDB, projectId: Buffer): Promise<void>;
|
|
5
|
-
export declare function dropMemberHostKeys(tx: HyperDB, projectId
|
|
7
|
+
export declare function dropMemberHostKeys(tx: HyperDB, { projectId, memberId, removed }: Omit<QvacSetProjectListingOperation, 'removedAt'>): Promise<void>;
|
|
6
8
|
export declare function dropDeviceHostKeys(tx: HyperDB, deviceId: Buffer): Promise<void>;
|
|
7
9
|
export declare function pruneProjectHostKeys(tx: HyperDB, deviceId: Buffer): Promise<void>;
|
|
@@ -1,41 +1,52 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
-
import { DEVICES,
|
|
2
|
+
import { DEVICES, PROJECT_HOST_SEALS, PROJECT_HOST_SEALS_BY_DEVICE } from '../collections.js';
|
|
3
3
|
import { liveAgentsOn, usesAny } from './public-seeds.js';
|
|
4
|
-
export function readProjectHostKey(tx, projectId, deviceId) {
|
|
5
|
-
return tx.get(
|
|
4
|
+
export function readProjectHostKey(tx, { projectId, deviceId, sealedBy }) {
|
|
5
|
+
return tx.get(PROJECT_HOST_SEALS, { projectId, deviceId, sealedBy });
|
|
6
|
+
}
|
|
7
|
+
export function projectHostKeys(tx, projectId, deviceId) {
|
|
8
|
+
const range = { gte: { projectId, deviceId }, lte: { projectId, deviceId } };
|
|
9
|
+
return tx.find(PROJECT_HOST_SEALS, range).toArray();
|
|
10
|
+
}
|
|
11
|
+
function dropRow(tx, { projectId, deviceId, sealedBy }) {
|
|
12
|
+
return tx.delete(PROJECT_HOST_SEALS, { projectId, deviceId, sealedBy });
|
|
6
13
|
}
|
|
7
14
|
function hostKeysOf(tx, projectId) {
|
|
8
15
|
const range = { gte: { projectId }, lte: { projectId } };
|
|
9
|
-
return tx.find(
|
|
16
|
+
return tx.find(PROJECT_HOST_SEALS, range).toArray();
|
|
10
17
|
}
|
|
11
18
|
export async function dropProjectHostKeys(tx, projectId) {
|
|
12
19
|
for (const row of await hostKeysOf(tx, projectId)) {
|
|
13
|
-
await tx
|
|
20
|
+
await dropRow(tx, row);
|
|
14
21
|
}
|
|
15
22
|
}
|
|
16
|
-
export async function dropMemberHostKeys(tx, projectId, memberId) {
|
|
23
|
+
export async function dropMemberHostKeys(tx, { projectId, memberId, removed }) {
|
|
17
24
|
for (const row of await hostKeysOf(tx, projectId)) {
|
|
18
25
|
const device = await tx.get(DEVICES, { id: row.deviceId });
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
const hosted = !!device?.memberId && b4a.equals(device.memberId, memberId);
|
|
27
|
+
if (hosted || (removed && b4a.equals(row.sealedBy, memberId))) {
|
|
28
|
+
await dropRow(tx, row);
|
|
21
29
|
}
|
|
22
30
|
}
|
|
23
31
|
}
|
|
24
32
|
function hostKeysSealedTo(tx, deviceId) {
|
|
25
33
|
return tx
|
|
26
|
-
.find(
|
|
34
|
+
.find(PROJECT_HOST_SEALS_BY_DEVICE, {
|
|
35
|
+
gte: { deviceId },
|
|
36
|
+
lte: { deviceId }
|
|
37
|
+
})
|
|
27
38
|
.toArray();
|
|
28
39
|
}
|
|
29
40
|
export async function dropDeviceHostKeys(tx, deviceId) {
|
|
30
41
|
for (const row of await hostKeysSealedTo(tx, deviceId)) {
|
|
31
|
-
await tx
|
|
42
|
+
await dropRow(tx, row);
|
|
32
43
|
}
|
|
33
44
|
}
|
|
34
45
|
export async function pruneProjectHostKeys(tx, deviceId) {
|
|
35
46
|
const agents = await liveAgentsOn(tx, deviceId);
|
|
36
47
|
for (const row of await hostKeysSealedTo(tx, deviceId)) {
|
|
37
48
|
if (!(await usesAny(tx, agents, row.projectId))) {
|
|
38
|
-
await tx
|
|
49
|
+
await dropRow(tx, row);
|
|
39
50
|
}
|
|
40
51
|
}
|
|
41
52
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type HyperDB from 'hyperdb';
|
|
2
2
|
import type { Router } from '../../../spec/mesh/hyperdispatch/index.js';
|
|
3
|
-
import type { QvacProject,
|
|
3
|
+
import type { QvacProject, QvacProjectMemberSeal, QvacProjectMember } from '../../../spec/mesh/hyperschema/types.d.ts';
|
|
4
4
|
import type { RouterContext } from './types.ts';
|
|
5
5
|
type Signed = Pick<RouterContext, 'tx' | 'node'>;
|
|
6
6
|
export declare const UNGROUPED = "@qvac/ungrouped";
|
|
7
7
|
export declare function readProject(tx: HyperDB, id: Buffer): Promise<QvacProject | null>;
|
|
8
|
-
export
|
|
8
|
+
export type MemberSealSlot = Pick<QvacProjectMemberSeal, 'projectId' | 'memberId' | 'sealedBy'>;
|
|
9
|
+
export declare function readProjectKey(tx: HyperDB, { projectId, memberId, sealedBy }: MemberSealSlot): Promise<QvacProjectMemberSeal | null>;
|
|
10
|
+
export declare function projectKeys(tx: HyperDB, projectId: Buffer, memberId?: Buffer): Promise<QvacProjectMemberSeal[]>;
|
|
9
11
|
export declare function dropMemberProjectKeys(tx: HyperDB, memberId: Buffer): Promise<void>;
|
|
10
12
|
export declare function listsMember(project: Pick<QvacProject, 'memberIds'>, memberId: Buffer): boolean;
|
|
11
13
|
export declare function listedProject(project: QvacProject, memberId: Buffer): boolean;
|
|
@@ -7,26 +7,35 @@ import { dropMemberHostKeys, dropProjectHostKeys, readProjectHostKey } from './p
|
|
|
7
7
|
import { dropListingDeviceKeys, dropProjectDeviceKeys, readProjectDeviceKey } from './project-device-keys.js';
|
|
8
8
|
import b4a from 'b4a';
|
|
9
9
|
import { SEALED_SEED_BYTES } from '../device-seal.js';
|
|
10
|
-
import { AGENT_USERS, AGENTS, CHAT_GROUPS, DEVICES, MESH_FOUNDERS,
|
|
10
|
+
import { AGENT_USERS, AGENTS, CHAT_GROUPS, DEVICES, MESH_FOUNDERS, PROJECT_DEVICE_SEALS, PROJECT_HOST_SEALS, PROJECT_MEMBER_SEALS, PROJECT_MEMBER_SEALS_BY_MEMBER, PROJECT_MEMBERS, PROJECTS } from '../collections.js';
|
|
11
11
|
export const UNGROUPED = '@qvac/ungrouped';
|
|
12
12
|
export function readProject(tx, id) {
|
|
13
13
|
return tx.get(PROJECTS, { id });
|
|
14
14
|
}
|
|
15
|
-
export function readProjectKey(tx, projectId, memberId) {
|
|
16
|
-
return tx.get(
|
|
15
|
+
export function readProjectKey(tx, { projectId, memberId, sealedBy }) {
|
|
16
|
+
return tx.get(PROJECT_MEMBER_SEALS, { projectId, memberId, sealedBy });
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
export function projectKeys(tx, projectId, memberId) {
|
|
19
|
+
const key = memberId ? { projectId, memberId } : { projectId };
|
|
20
|
+
return tx.find(PROJECT_MEMBER_SEALS, { gte: key, lte: key }).toArray();
|
|
21
|
+
}
|
|
22
|
+
function dropSeal(tx, { projectId, memberId, sealedBy }) {
|
|
23
|
+
return tx.delete(PROJECT_MEMBER_SEALS, { projectId, memberId, sealedBy });
|
|
24
|
+
}
|
|
25
|
+
async function dropProjectKeys(tx, projectId, match = () => true) {
|
|
26
|
+
for (const row of (await projectKeys(tx, projectId)).filter(match)) {
|
|
27
|
+
await dropSeal(tx, row);
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
30
|
export async function dropMemberProjectKeys(tx, memberId) {
|
|
25
31
|
const rows = await tx
|
|
26
|
-
.find(
|
|
32
|
+
.find(PROJECT_MEMBER_SEALS_BY_MEMBER, {
|
|
33
|
+
gte: { memberId },
|
|
34
|
+
lte: { memberId }
|
|
35
|
+
})
|
|
27
36
|
.toArray();
|
|
28
37
|
for (const row of rows) {
|
|
29
|
-
await tx
|
|
38
|
+
await dropSeal(tx, row);
|
|
30
39
|
}
|
|
31
40
|
}
|
|
32
41
|
export function listsMember(project, memberId) {
|
|
@@ -132,11 +141,11 @@ async function setProjectListing({ projectId, memberId, removed, removedAt }, co
|
|
|
132
141
|
const listed = memberIds.length === 0 ? await tombstone(next, context) : next;
|
|
133
142
|
await tx.insert(PROJECTS, listed);
|
|
134
143
|
if (removed) {
|
|
135
|
-
await tx
|
|
144
|
+
await dropProjectKeys(tx, projectId, (row) => [row.memberId, row.sealedBy].some((id) => b4a.equals(id, memberId)));
|
|
136
145
|
await dropListingDeviceKeys(tx, projectId, memberId);
|
|
137
146
|
await dropMemberAgentUses(tx, memberId, projectId);
|
|
138
147
|
}
|
|
139
|
-
await dropMemberHostKeys(tx, projectId, memberId);
|
|
148
|
+
await dropMemberHostKeys(tx, { projectId, memberId, removed });
|
|
140
149
|
return listed;
|
|
141
150
|
}
|
|
142
151
|
async function tombstone(project, { tx, node }) {
|
|
@@ -187,17 +196,18 @@ async function putProjectKey(op, context) {
|
|
|
187
196
|
log?.warn('contract', 'put-project-key dropped: not a sealed seed');
|
|
188
197
|
return;
|
|
189
198
|
}
|
|
190
|
-
const held = await readProjectKey(tx, op
|
|
199
|
+
const held = await readProjectKey(tx, { ...op, sealedBy: signer });
|
|
191
200
|
if (held && b4a.equals(held.boxKey, op.boxKey)) {
|
|
192
201
|
return;
|
|
193
202
|
}
|
|
194
203
|
const row = {
|
|
195
204
|
projectId: op.projectId,
|
|
196
205
|
memberId: op.memberId,
|
|
206
|
+
sealedBy: signer,
|
|
197
207
|
boxKey: op.boxKey,
|
|
198
208
|
sealedSeed: op.sealedSeed
|
|
199
209
|
};
|
|
200
|
-
await tx.insert(
|
|
210
|
+
await tx.insert(PROJECT_MEMBER_SEALS, row);
|
|
201
211
|
return row;
|
|
202
212
|
}
|
|
203
213
|
async function putProjectHostKey(op, context) {
|
|
@@ -235,16 +245,17 @@ async function putProjectHostKey(op, context) {
|
|
|
235
245
|
log?.warn('contract', 'put-project-host-key dropped: not a sealed seed');
|
|
236
246
|
return;
|
|
237
247
|
}
|
|
238
|
-
if (await readProjectHostKey(tx, op
|
|
248
|
+
if (await readProjectHostKey(tx, { ...op, sealedBy: signer })) {
|
|
239
249
|
return;
|
|
240
250
|
}
|
|
241
251
|
const row = {
|
|
242
252
|
projectId: op.projectId,
|
|
243
253
|
deviceId: op.deviceId,
|
|
254
|
+
sealedBy: signer,
|
|
244
255
|
agentId: op.agentId,
|
|
245
256
|
sealedSeed: op.sealedSeed
|
|
246
257
|
};
|
|
247
|
-
await tx.insert(
|
|
258
|
+
await tx.insert(PROJECT_HOST_SEALS, row);
|
|
248
259
|
return row;
|
|
249
260
|
}
|
|
250
261
|
async function countedDevice(tx, { memberId, deviceId }) {
|
|
@@ -276,16 +287,17 @@ async function putProjectDeviceKey(op, context) {
|
|
|
276
287
|
log?.warn('contract', 'put-project-device-key dropped: not a sealed seed');
|
|
277
288
|
return;
|
|
278
289
|
}
|
|
279
|
-
if (await readProjectDeviceKey(tx, op
|
|
290
|
+
if (await readProjectDeviceKey(tx, { ...op, sealedBy: signer })) {
|
|
280
291
|
return;
|
|
281
292
|
}
|
|
282
293
|
const row = {
|
|
283
294
|
projectId: op.projectId,
|
|
284
295
|
deviceId: op.deviceId,
|
|
296
|
+
sealedBy: signer,
|
|
285
297
|
memberId: op.memberId,
|
|
286
298
|
sealedSeed: op.sealedSeed
|
|
287
299
|
};
|
|
288
|
-
await tx.insert(
|
|
300
|
+
await tx.insert(PROJECT_DEVICE_SEALS, row);
|
|
289
301
|
return row;
|
|
290
302
|
}
|
|
291
303
|
async function putProjectMember({ memberId, addedAt }, context) {
|
|
@@ -245,7 +245,7 @@ async function putMemberKey(op, context) {
|
|
|
245
245
|
await tx.insert(MEMBER_KEYS, row);
|
|
246
246
|
return row;
|
|
247
247
|
}
|
|
248
|
-
async function upgradeToWorkspace(
|
|
248
|
+
async function upgradeToWorkspace(_op, context) {
|
|
249
249
|
const { tx, log } = context;
|
|
250
250
|
const kind = await meshKind(tx);
|
|
251
251
|
const onRules = (await rulesVersion(tx)) >= WORKSPACES_RULES;
|
|
@@ -270,7 +270,7 @@ async function upgradeToWorkspace({ upgradedAt }, context) {
|
|
|
270
270
|
}
|
|
271
271
|
}
|
|
272
272
|
await tx.insert(MESH_KINDS, { id: 'mesh', kind: 'workspace' });
|
|
273
|
-
const row = { id: WORKSPACE_ROW, updatedAt:
|
|
273
|
+
const row = { id: WORKSPACE_ROW, updatedAt: 0, upgradeMemberIds };
|
|
274
274
|
await tx.insert(WORKSPACE, row);
|
|
275
275
|
log?.info('contract', 'shared mesh upgraded to a workspace');
|
|
276
276
|
return row;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { QvacChunk } from '../../spec/mesh/hyperschema/types.d.ts';
|
|
2
|
+
import type { Mesh } from './mesh.ts';
|
|
3
|
+
export interface LandedRuns {
|
|
4
|
+
readonly requests: QvacChunk[];
|
|
5
|
+
readonly deletedAgents: Set<string>;
|
|
6
|
+
}
|
|
7
|
+
export declare function cancelDeletedAgentRuns(mesh: Mesh, deviceId: Buffer, landed: LandedRuns | null): Promise<void>;
|
|
8
|
+
export declare function cancelRunsForAgent(mesh: Mesh, deviceId: Buffer, agentId: string): Promise<void>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { AGENT_DELETED, cancelActiveRuns } from './chat.js';
|
|
2
|
+
import { AGENTS, CHATS, RUN_REQUESTS } from './collections.js';
|
|
3
|
+
import { runHasTerminalStatus } from './contract/run-requests.js';
|
|
4
|
+
export async function cancelDeletedAgentRuns(mesh, deviceId, landed) {
|
|
5
|
+
const deleted = landed ? await deletedOf(mesh, landed) : await allDeleted(mesh);
|
|
6
|
+
if (deleted.size === 0) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const requests = landed && landed.deletedAgents.size === 0
|
|
10
|
+
? landed.requests
|
|
11
|
+
: await mesh.view.find(RUN_REQUESTS).toArray();
|
|
12
|
+
const asking = await openRunsOf(mesh, requests, deleted);
|
|
13
|
+
for (const [chatId, agentIds] of asking) {
|
|
14
|
+
if (mesh.closing || !mesh.writable)
|
|
15
|
+
return;
|
|
16
|
+
const chat = await mesh.view.get(CHATS, { id: chatId });
|
|
17
|
+
if (!chat || chat.deletedAt) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
for (const agentId of agentIds) {
|
|
21
|
+
await cancelActiveRuns(mesh, chatId, {
|
|
22
|
+
deviceId,
|
|
23
|
+
agentId,
|
|
24
|
+
reason: AGENT_DELETED,
|
|
25
|
+
queuedOnly: !deleted.has(chat.agentId)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function cancelRunsForAgent(mesh, deviceId, agentId) {
|
|
31
|
+
return cancelDeletedAgentRuns(mesh, deviceId, { requests: [], deletedAgents: new Set([agentId]) });
|
|
32
|
+
}
|
|
33
|
+
async function openRunsOf(mesh, requests, deleted) {
|
|
34
|
+
const asking = new Map();
|
|
35
|
+
for (const { chatId, runId, runRequest } of requests) {
|
|
36
|
+
const agentId = runRequest?.agentId ?? '';
|
|
37
|
+
if (runId && deleted.has(agentId) && !(await runHasTerminalStatus(mesh.view, chatId, runId))) {
|
|
38
|
+
asking.set(chatId, (asking.get(chatId) ?? new Set()).add(agentId));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return asking;
|
|
42
|
+
}
|
|
43
|
+
async function deletedOf(mesh, { requests, deletedAgents }) {
|
|
44
|
+
const deleted = new Set(deletedAgents);
|
|
45
|
+
const asked = new Set(requests.map((r) => r.runRequest?.agentId).filter((id) => !!id));
|
|
46
|
+
for (const id of asked) {
|
|
47
|
+
const agent = await mesh.view.get(AGENTS, { id });
|
|
48
|
+
if (agent?.deletedAt) {
|
|
49
|
+
deleted.add(id);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return deleted;
|
|
53
|
+
}
|
|
54
|
+
async function allDeleted(mesh) {
|
|
55
|
+
const agents = await mesh.view.find(AGENTS).toArray();
|
|
56
|
+
return new Set(agents.filter((agent) => agent.deletedAt).map((agent) => agent.id));
|
|
57
|
+
}
|
|
@@ -115,7 +115,7 @@ export declare class Files extends EventEmitter {
|
|
|
115
115
|
clearLoaded(processorId?: string): void;
|
|
116
116
|
hydratedArtifact(id: string): string | null;
|
|
117
117
|
ready(chatId: string, ids: string[]): Promise<AssistantFileStatusList>;
|
|
118
|
-
indexingHere(chatId: string): Promise<void>;
|
|
118
|
+
indexingHere(chatId: string, ids: string[]): Promise<void>;
|
|
119
119
|
indexesHere(file: AssistantFileStatus): boolean;
|
|
120
120
|
private _until;
|
|
121
121
|
private _changes;
|
|
@@ -405,8 +405,10 @@ export class Files extends EventEmitter {
|
|
|
405
405
|
return files.every(settledFile) ? files : null;
|
|
406
406
|
});
|
|
407
407
|
}
|
|
408
|
-
async indexingHere(chatId) {
|
|
409
|
-
|
|
408
|
+
async indexingHere(chatId, ids) {
|
|
409
|
+
const wanted = new Set(ids);
|
|
410
|
+
this._processing?.prioritize(ids);
|
|
411
|
+
await this._until(chatId, (files) => files.some((file) => wanted.has(file.fileId) && this.indexesHere(file)) ? null : files);
|
|
410
412
|
}
|
|
411
413
|
indexesHere(file) {
|
|
412
414
|
const rag = file.processors.find((entry) => entry.processorId === 'rag');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { QvacDevice, QvacSeedDefaultsOperation } from '../../../spec/mesh/hyperschema/types.d.ts';
|
|
2
2
|
import type { Mesh } from '../mesh.ts';
|
|
3
3
|
export declare const DEFAULT_AGENT_NAME = "QV.AC";
|
|
4
|
-
export declare function buildDefaultSeed(device: Pick<QvacDevice, 'id' | 'recommendedModelName'>, blindPeerKeys: ReadonlyArray<Buffer
|
|
4
|
+
export declare function buildDefaultSeed(device: Pick<QvacDevice, 'id' | 'recommendedModelName'>, blindPeerKeys: ReadonlyArray<Buffer>, modelName?: string): QvacSeedDefaultsOperation;
|
|
5
5
|
export declare function isOwnRevokedRow(mesh: Mesh, device: QvacDevice): boolean;
|
|
6
6
|
export declare function isKickedRow(device: QvacDevice): boolean;
|
|
7
7
|
export declare function isOwnKickedRow(mesh: Mesh, device: QvacDevice): boolean;
|
|
@@ -33,7 +33,7 @@ function seedableChat(chat) {
|
|
|
33
33
|
updatedAt: chat.updatedAt
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
export function buildDefaultSeed(device, blindPeerKeys) {
|
|
36
|
+
export function buildDefaultSeed(device, blindPeerKeys, modelName = device.recommendedModelName) {
|
|
37
37
|
const now = Date.now();
|
|
38
38
|
const agentId = randomId();
|
|
39
39
|
return {
|
|
@@ -42,7 +42,7 @@ export function buildDefaultSeed(device, blindPeerKeys) {
|
|
|
42
42
|
name: DEFAULT_AGENT_NAME,
|
|
43
43
|
bio: DEFAULT_AGENT_BIO,
|
|
44
44
|
providerDeviceId: device.id,
|
|
45
|
-
modelName
|
|
45
|
+
modelName,
|
|
46
46
|
reasoning: 'inherit',
|
|
47
47
|
enabledSkills: [],
|
|
48
48
|
enabledTools: [],
|
|
@@ -52,6 +52,11 @@ export interface ResolvedSession {
|
|
|
52
52
|
export interface ArchivedMeshMembership extends LocalMeshMembership {
|
|
53
53
|
readonly leftAt: number;
|
|
54
54
|
}
|
|
55
|
+
export interface ConfigChange<T> {
|
|
56
|
+
readonly result: T;
|
|
57
|
+
readonly set: ReadonlyArray<ConfigEntry>;
|
|
58
|
+
readonly delete: ReadonlyArray<string>;
|
|
59
|
+
}
|
|
55
60
|
export interface ConfigEntry {
|
|
56
61
|
readonly key: string;
|
|
57
62
|
readonly value: unknown;
|
|
@@ -129,6 +134,7 @@ declare class LocalStore {
|
|
|
129
134
|
setAll(entries: ReadonlyArray<ConfigEntry>): Promise<void>;
|
|
130
135
|
rekey(fromKey: string, toKey: string): Promise<unknown>;
|
|
131
136
|
deleteAll(keys: ReadonlyArray<string>): Promise<void>;
|
|
137
|
+
change<T>(plan: (get: (key: string) => Promise<unknown>) => Promise<ConfigChange<T>>): Promise<T>;
|
|
132
138
|
deletePrefix(prefix: string): Promise<void>;
|
|
133
139
|
listPrefix(prefix: string): Promise<ConfigEntry[]>;
|
|
134
140
|
getAppConfigRow(): Promise<LocalAppConfig | null>;
|
|
@@ -112,6 +112,20 @@ class LocalStore {
|
|
|
112
112
|
await tx.flush();
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
|
+
change(plan) {
|
|
116
|
+
return this._locked(async () => {
|
|
117
|
+
const { result, set, delete: drop } = await plan((key) => this.get(key));
|
|
118
|
+
const tx = this._db.transaction();
|
|
119
|
+
for (const { key, value } of set) {
|
|
120
|
+
await tx.insert(LOCAL_CONFIG, { key, ...configValue(value) });
|
|
121
|
+
}
|
|
122
|
+
for (const key of drop) {
|
|
123
|
+
await tx.delete(LOCAL_CONFIG, { key });
|
|
124
|
+
}
|
|
125
|
+
await tx.flush();
|
|
126
|
+
return result;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
115
129
|
deletePrefix(prefix) {
|
|
116
130
|
return this._locked(async () => {
|
|
117
131
|
const tx = this._db.transaction();
|
|
@@ -73,6 +73,7 @@ interface BirthOptions {
|
|
|
73
73
|
readonly member?: BirthMember;
|
|
74
74
|
readonly sharing?: boolean;
|
|
75
75
|
readonly defaults?: boolean;
|
|
76
|
+
readonly modelName?: string | undefined;
|
|
76
77
|
readonly workspace?: WorkspaceIdentity;
|
|
77
78
|
readonly project?: ProjectIdentity;
|
|
78
79
|
}
|
|
@@ -219,7 +220,7 @@ export declare class Mesh extends ReadyResource {
|
|
|
219
220
|
private _seedDefaults;
|
|
220
221
|
get interrupted(): unknown;
|
|
221
222
|
throwIfInterrupted(): void;
|
|
222
|
-
waitForWritable(): Promise<void>;
|
|
223
|
+
waitForWritable(timeout?: number): Promise<void>;
|
|
223
224
|
pendingUploads(): number;
|
|
224
225
|
suspend(): Promise<void>;
|
|
225
226
|
resume(): void;
|
|
@@ -686,7 +686,7 @@ export class Mesh extends ReadyResource {
|
|
|
686
686
|
get joined() {
|
|
687
687
|
return this._joined;
|
|
688
688
|
}
|
|
689
|
-
async _appendBirthOp(identity, device, { member, sharing = false, defaults = true, workspace, project } = {}) {
|
|
689
|
+
async _appendBirthOp(identity, device, { member, sharing = false, defaults = true, modelName, workspace, project } = {}) {
|
|
690
690
|
if (this.autobee.local.length > 0)
|
|
691
691
|
return;
|
|
692
692
|
const { publicKey: deviceId, secretKey } = 'secretKey' in identity ? identity : { publicKey: identity, secretKey: null };
|
|
@@ -722,7 +722,7 @@ export class Mesh extends ReadyResource {
|
|
|
722
722
|
birth.dispatch('name-mesh', { name: project.name, namedAt: row.joinedAt });
|
|
723
723
|
}
|
|
724
724
|
if (!sharing) {
|
|
725
|
-
this._seedDefaults(birth, row, defaults);
|
|
725
|
+
this._seedDefaults(birth, row, { defaults, modelName });
|
|
726
726
|
}
|
|
727
727
|
}
|
|
728
728
|
await birth.flush();
|
|
@@ -749,7 +749,7 @@ export class Mesh extends ReadyResource {
|
|
|
749
749
|
}
|
|
750
750
|
return this._role === 'workspace' || this._role === 'public' ? this._role : 'shared';
|
|
751
751
|
}
|
|
752
|
-
_seedDefaults(birth, row, defaults) {
|
|
752
|
+
_seedDefaults(birth, row, { defaults, modelName }) {
|
|
753
753
|
if (!inRole(this._role, '@qvac/seed-defaults')) {
|
|
754
754
|
for (const key of this._blindPeerKeys) {
|
|
755
755
|
birth.dispatch('put-mesh-blind-peer', { key });
|
|
@@ -760,7 +760,7 @@ export class Mesh extends ReadyResource {
|
|
|
760
760
|
return;
|
|
761
761
|
}
|
|
762
762
|
const peers = inRole(this._role, '@qvac/put-mesh-blind-peer') ? this._blindPeerKeys : [];
|
|
763
|
-
birth.dispatch('seed-defaults', buildDefaultSeed(row, peers));
|
|
763
|
+
birth.dispatch('seed-defaults', buildDefaultSeed(row, peers, modelName));
|
|
764
764
|
birth.dispatch('put-agent', { agent: buildHealthAssistant(row) });
|
|
765
765
|
}
|
|
766
766
|
get interrupted() {
|
|
@@ -771,15 +771,17 @@ export class Mesh extends ReadyResource {
|
|
|
771
771
|
throw this.interrupted;
|
|
772
772
|
}
|
|
773
773
|
}
|
|
774
|
-
async waitForWritable() {
|
|
774
|
+
async waitForWritable(timeout) {
|
|
775
775
|
if (this.closing || this.autobee.writable)
|
|
776
776
|
return;
|
|
777
777
|
await new Promise((resolve) => {
|
|
778
778
|
const done = () => {
|
|
779
|
+
clearTimeout(timer);
|
|
779
780
|
this.autobee.off('writable', done);
|
|
780
781
|
this.off('close', done);
|
|
781
782
|
resolve();
|
|
782
783
|
};
|
|
784
|
+
const timer = timeout === undefined ? undefined : setTimeout(done, timeout);
|
|
783
785
|
this.autobee.on('writable', done);
|
|
784
786
|
this.on('close', done);
|
|
785
787
|
});
|
|
@@ -3,11 +3,14 @@ import type { QvacAgent, QvacProject, QvacProjectDeviceKey, QvacProjectHostKey,
|
|
|
3
3
|
export interface ProjectSeed {
|
|
4
4
|
readonly projectId: Buffer;
|
|
5
5
|
readonly seed: Buffer;
|
|
6
|
+
readonly sealedBy: Buffer;
|
|
6
7
|
}
|
|
7
8
|
export interface ProjectHostSeed extends ProjectSeed {
|
|
8
9
|
readonly project: HyperDB;
|
|
9
10
|
readonly picking?: boolean;
|
|
10
11
|
}
|
|
11
|
-
export declare function
|
|
12
|
+
export declare function seedFingerprint(seed: Buffer): Buffer;
|
|
13
|
+
export declare function seedOpens(project: QvacProject, seed: Buffer): boolean;
|
|
14
|
+
export declare function dueProjectKey(view: HyperDB, memberId: Buffer, { projectId, seed, sealedBy }: ProjectSeed): Promise<QvacProjectKey | null>;
|
|
12
15
|
export declare function dueProjectHostKey(view: HyperDB, agent: QvacAgent, seal: ProjectHostSeed): Promise<QvacProjectHostKey | null>;
|
|
13
|
-
export declare function dueProjectDeviceKeys(view: HyperDB, row: QvacProject, seed:
|
|
16
|
+
export declare function dueProjectDeviceKeys(view: HyperDB, row: QvacProject, { seed, sealedBy }: Omit<ProjectSeed, 'projectId'>): Promise<QvacProjectDeviceKey[]>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
+
import crypto from 'hypercore-crypto';
|
|
2
3
|
import { AGENT_USERS, AGENTS, DEVICES } from './collections.js';
|
|
3
4
|
import { readProjectHostKey } from './contract/project-host-keys.js';
|
|
4
5
|
import { readProjectDeviceKey } from './contract/project-device-keys.js';
|
|
@@ -6,9 +7,16 @@ import { listsMember, readProject, readProjectKey } from './contract/projects.js
|
|
|
6
7
|
import { readMemberKey, upgradeMembers } from './contract/workspace.js';
|
|
7
8
|
import { sealToDevice } from './device-seal.js';
|
|
8
9
|
import { sealToMember } from './member-key.js';
|
|
9
|
-
|
|
10
|
+
const [SEED_FINGERPRINT] = crypto.namespace('qvac-assistant/seed-fingerprint', 1);
|
|
11
|
+
export function seedFingerprint(seed) {
|
|
12
|
+
return crypto.hash([SEED_FINGERPRINT, seed]);
|
|
13
|
+
}
|
|
14
|
+
export function seedOpens(project, seed) {
|
|
15
|
+
return !project.seedFingerprint || b4a.equals(seedFingerprint(seed), project.seedFingerprint);
|
|
16
|
+
}
|
|
17
|
+
export async function dueProjectKey(view, memberId, { projectId, seed, sealedBy }) {
|
|
10
18
|
const key = await readMemberKey(view, memberId);
|
|
11
|
-
const held = key && (await readProjectKey(view, projectId, memberId));
|
|
19
|
+
const held = key && (await readProjectKey(view, { projectId, memberId, sealedBy }));
|
|
12
20
|
if (!key || (held && b4a.equals(held.boxKey, key.boxKey))) {
|
|
13
21
|
return null;
|
|
14
22
|
}
|
|
@@ -22,7 +30,7 @@ async function usedBy(view, agent, seal) {
|
|
|
22
30
|
return (!!seal.picking || !!(await view.get(AGENT_USERS, { agentId: agent.id, userId: seal.projectId })));
|
|
23
31
|
}
|
|
24
32
|
export async function dueProjectHostKey(view, agent, seal) {
|
|
25
|
-
const { projectId, seed, project } = seal;
|
|
33
|
+
const { projectId, seed, project, sealedBy } = seal;
|
|
26
34
|
const deviceId = agent.providerDeviceId;
|
|
27
35
|
const row = await readProject(view, projectId);
|
|
28
36
|
const host = await view.get(DEVICES, { id: deviceId });
|
|
@@ -34,12 +42,12 @@ export async function dueProjectHostKey(view, agent, seal) {
|
|
|
34
42
|
if (!(await usedBy(view, agent, seal))) {
|
|
35
43
|
return null;
|
|
36
44
|
}
|
|
37
|
-
if (await readProjectHostKey(view, projectId, deviceId)) {
|
|
45
|
+
if (await readProjectHostKey(view, { projectId, deviceId, sealedBy })) {
|
|
38
46
|
return null;
|
|
39
47
|
}
|
|
40
48
|
return { projectId, deviceId, agentId: agent.id, sealedSeed: sealToDevice(seed, deviceId) };
|
|
41
49
|
}
|
|
42
|
-
export async function dueProjectDeviceKeys(view, row, seed) {
|
|
50
|
+
export async function dueProjectDeviceKeys(view, row, { seed, sealedBy }) {
|
|
43
51
|
if (!row.groupId) {
|
|
44
52
|
return [];
|
|
45
53
|
}
|
|
@@ -47,7 +55,8 @@ export async function dueProjectDeviceKeys(view, row, seed) {
|
|
|
47
55
|
const due = [];
|
|
48
56
|
for await (const { id, memberId, revoked } of view.find(DEVICES)) {
|
|
49
57
|
const listed = memberId && counted.some((member) => b4a.equals(member, memberId));
|
|
50
|
-
|
|
58
|
+
const slot = { projectId: row.id, deviceId: id, sealedBy };
|
|
59
|
+
if (!memberId || !listed || revoked || (await readProjectDeviceKey(view, slot))) {
|
|
51
60
|
continue;
|
|
52
61
|
}
|
|
53
62
|
due.push({ projectId: row.id, deviceId: id, memberId, sealedSeed: sealToDevice(seed, id) });
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { AssistantPushSkillSecretRequest } from '../../spec/hyperschema/types.d.ts';
|
|
2
|
-
import type { openLocalStore } from './local/index.ts';
|
|
2
|
+
import type { ConfigEntry, openLocalStore } from './local/index.ts';
|
|
3
3
|
import type { Mesh } from './mesh.ts';
|
|
4
4
|
export type SkillSecretRequest = AssistantPushSkillSecretRequest;
|
|
5
5
|
export type SetupFields = (skillName: string) => Promise<ReadonlyMap<string, boolean> | null>;
|
|
6
6
|
export interface SkillSecretsOptions {
|
|
7
7
|
readonly local: ReturnType<typeof openLocalStore>;
|
|
8
8
|
readonly setupFields: SetupFields;
|
|
9
|
-
readonly
|
|
9
|
+
readonly validate?: (entry: ConfigEntry) => void;
|
|
10
|
+
readonly onstored: (entries: ReadonlyArray<ConfigEntry>) => Promise<unknown>;
|
|
10
11
|
}
|
|
11
12
|
export declare function storeSkillSecret(opts: SkillSecretsOptions, request: SkillSecretRequest): Promise<void>;
|
|
12
13
|
export declare function isDeviceKey(key: string): boolean;
|
|
@@ -22,8 +22,11 @@ export async function storeSkillSecret(opts, request) {
|
|
|
22
22
|
if (entries.length === 0) {
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
+
for (const entry of entries) {
|
|
26
|
+
opts.validate?.(entry);
|
|
27
|
+
}
|
|
25
28
|
await opts.local.setAll(entries);
|
|
26
|
-
await opts.onstored();
|
|
29
|
+
await opts.onstored(entries);
|
|
27
30
|
}
|
|
28
31
|
export function isDeviceKey(key) {
|
|
29
32
|
return DEVICE_SHARED_CREDENTIAL_KEYS.has(key.slice(key.lastIndexOf('.') + 1));
|