@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,9 +1,9 @@
|
|
|
1
|
-
import { changed } from './changed.js';
|
|
1
|
+
import { changed, liveRow } from './changed.js';
|
|
2
2
|
import { FileChanges } from './files.js';
|
|
3
3
|
import { syncDeviceRevocation, syncOwnMember } from './devices.js';
|
|
4
4
|
import { syncChatTombstone } from './chats.js';
|
|
5
5
|
import { syncNotificationChunk } from './chunks.js';
|
|
6
|
-
import { AGENT_HOSTS, AGENT_USERS, AGENTS, CHATS, CHAT_GROUPS, CHUNKS, CHUNK_COUNTERS, DEVICES, KNOWLEDGE, KNOWLEDGE_ARTIFACTS, MEMBER_KEYS, MEMBERS, MESH_NAMES, MESH_RULES, MESH_SEEDS,
|
|
6
|
+
import { AGENT_HOSTS, AGENT_USERS, AGENTS, CHATS, CHAT_GROUPS, CHUNKS, CHUNK_COUNTERS, DEVICES, KNOWLEDGE, KNOWLEDGE_ARTIFACTS, MEMBER_KEYS, MEMBERS, MESH_NAMES, MESH_RULES, MESH_SEEDS, PROJECT_DEVICE_SEALS, PROJECT_HOST_SEALS, PROJECT_MEMBER_SEALS, PROJECTS, PUBLIC_MESHES, PUBLIC_SEEDS, PURGED_CHATS, SKILL_SECRETS, WORKSPACE } from '../collections.js';
|
|
7
7
|
export async function syncChanges(mesh, view, from) {
|
|
8
8
|
if (mesh.closing)
|
|
9
9
|
return null;
|
|
@@ -17,6 +17,7 @@ export async function syncChanges(mesh, view, from) {
|
|
|
17
17
|
catch (err) {
|
|
18
18
|
mesh.log?.warn('sync', 'change sync cut short', err);
|
|
19
19
|
pass.membershipMoved = pass.agentsDirty = pass.meshesChanged = pass.nameChanged = true;
|
|
20
|
+
pass.runs = null;
|
|
20
21
|
pass.groupsChanged = pass.secretsChanged = true;
|
|
21
22
|
}
|
|
22
23
|
try {
|
|
@@ -58,6 +59,7 @@ function newPass() {
|
|
|
58
59
|
orderDirty: new Set(),
|
|
59
60
|
purged: new Map(),
|
|
60
61
|
notifications: [],
|
|
62
|
+
runs: { requests: [], deletedAgents: new Set() },
|
|
61
63
|
rulesRaised: false,
|
|
62
64
|
unattestedDevice: false,
|
|
63
65
|
membershipMoved: false,
|
|
@@ -101,6 +103,9 @@ async function settle(mesh, pass) {
|
|
|
101
103
|
if (pass.agentsDirty) {
|
|
102
104
|
mesh.emit('agents-dirty');
|
|
103
105
|
}
|
|
106
|
+
if (!pass.runs || pass.runs.requests.length || pass.runs.deletedAgents.size) {
|
|
107
|
+
mesh.emit('runs-landed', pass.runs);
|
|
108
|
+
}
|
|
104
109
|
if (pass.secretsChanged) {
|
|
105
110
|
mesh.emit('skill-secrets-dirty');
|
|
106
111
|
}
|
|
@@ -120,7 +125,7 @@ async function walkChanges(mesh, { snap, from, files, pass }) {
|
|
|
120
125
|
await files.add(change);
|
|
121
126
|
if (HOSTING.has(change.collection)) {
|
|
122
127
|
pass.agentsDirty = true;
|
|
123
|
-
pass.meshesChanged ||= change.collection ===
|
|
128
|
+
pass.meshesChanged ||= change.collection === PROJECT_HOST_SEALS;
|
|
124
129
|
continue;
|
|
125
130
|
}
|
|
126
131
|
if (change.type === 'delete') {
|
|
@@ -134,6 +139,10 @@ async function walkChanges(mesh, { snap, from, files, pass }) {
|
|
|
134
139
|
}
|
|
135
140
|
else if (change.collection === AGENTS) {
|
|
136
141
|
pass.agentsDirty = true;
|
|
142
|
+
const agent = changed(change, AGENTS) ? liveRow(change) : null;
|
|
143
|
+
if (agent?.deletedAt) {
|
|
144
|
+
pass.runs?.deletedAgents.add(agent.id);
|
|
145
|
+
}
|
|
137
146
|
}
|
|
138
147
|
else if (changed(change, CHATS)) {
|
|
139
148
|
pass.orderDirty.add(change.value.id);
|
|
@@ -147,6 +156,9 @@ async function walkChanges(mesh, { snap, from, files, pass }) {
|
|
|
147
156
|
}
|
|
148
157
|
else if (changed(change, CHUNKS)) {
|
|
149
158
|
pass.notifications.push(change.value);
|
|
159
|
+
if (change.value.type === 'run-request') {
|
|
160
|
+
pass.runs?.requests.push(change.value);
|
|
161
|
+
}
|
|
150
162
|
if (change.value.attachment) {
|
|
151
163
|
pass.attachments.push(change.value);
|
|
152
164
|
}
|
|
@@ -177,7 +189,7 @@ async function walkChanges(mesh, { snap, from, files, pass }) {
|
|
|
177
189
|
const HOSTING = new Set([
|
|
178
190
|
AGENT_USERS,
|
|
179
191
|
PUBLIC_SEEDS,
|
|
180
|
-
|
|
192
|
+
PROJECT_HOST_SEALS,
|
|
181
193
|
AGENT_HOSTS
|
|
182
194
|
]);
|
|
183
195
|
const FOLLOWED = new Set([
|
|
@@ -185,7 +197,7 @@ const FOLLOWED = new Set([
|
|
|
185
197
|
MESH_SEEDS,
|
|
186
198
|
PUBLIC_MESHES,
|
|
187
199
|
PROJECTS,
|
|
188
|
-
|
|
189
|
-
|
|
200
|
+
PROJECT_MEMBER_SEALS,
|
|
201
|
+
PROJECT_DEVICE_SEALS,
|
|
190
202
|
MEMBER_KEYS
|
|
191
203
|
]);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { QUARANTINE_PREFIX } from './config-value.ts';
|
|
2
|
+
import type { ConfigEntry, openLocalStore } from './local/index.ts';
|
|
3
|
+
import type { Logger } from '../logger-type.ts';
|
|
4
|
+
export type VaultManagedSkillField = 'access-token' | 'oauth-expiry' | 'setting';
|
|
5
|
+
export interface VaultManagedSkills {
|
|
6
|
+
readonly mode: 'vault-managed';
|
|
7
|
+
readonly classify: (configKey: string) => VaultManagedSkillField | null;
|
|
8
|
+
readonly migrateLegacy?: (entries: ReadonlyArray<ConfigEntry>, context: {
|
|
9
|
+
readonly safeEntries: ReadonlyArray<ConfigEntry>;
|
|
10
|
+
}) => Promise<ReadonlyArray<string>>;
|
|
11
|
+
}
|
|
12
|
+
export { QUARANTINE_PREFIX };
|
|
13
|
+
type LocalStore = ReturnType<typeof openLocalStore>;
|
|
14
|
+
export declare function validateVaultManagedSkill(policy: VaultManagedSkills | undefined, entry: ConfigEntry): void;
|
|
15
|
+
export declare function quarantinedSkillKeys(local: LocalStore): Promise<string[]>;
|
|
16
|
+
export declare function discardQuarantinedSkills(local: LocalStore, keys: ReadonlyArray<string>): Promise<string[]>;
|
|
17
|
+
export declare function releaseQuarantinedSkills(local: LocalStore, entries: ReadonlyArray<ConfigEntry>): Promise<void>;
|
|
18
|
+
export declare function prepareVaultManagedSkills(policy: VaultManagedSkills | undefined, local: LocalStore, log?: Logger | null): Promise<string[]>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { CoreError } from '../errors.js';
|
|
2
|
+
import { isRecord } from '../guards.js';
|
|
3
|
+
import { QUARANTINE_PREFIX } from './config-value.js';
|
|
4
|
+
import { SKILL_SECRET_PREFIX } from './contract/skill-secrets.js';
|
|
5
|
+
export { QUARANTINE_PREFIX };
|
|
6
|
+
function cleared(value) {
|
|
7
|
+
return value === null || value === undefined || value === '';
|
|
8
|
+
}
|
|
9
|
+
function accepted(policy, { key, value }) {
|
|
10
|
+
if (cleared(value))
|
|
11
|
+
return true;
|
|
12
|
+
const field = policy.classify(key);
|
|
13
|
+
if (field === 'access-token' || field === 'setting') {
|
|
14
|
+
return typeof value === 'string';
|
|
15
|
+
}
|
|
16
|
+
if (field !== 'oauth-expiry' || typeof value !== 'string') {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const state = JSON.parse(value);
|
|
21
|
+
return (isRecord(state) &&
|
|
22
|
+
Object.keys(state).every((key) => key === 'expiresAt') &&
|
|
23
|
+
(state.expiresAt === undefined ||
|
|
24
|
+
(typeof state.expiresAt === 'number' && Number.isFinite(state.expiresAt))));
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function reconnected(policy, entry) {
|
|
31
|
+
return !cleared(entry.value) && accepted(policy, entry);
|
|
32
|
+
}
|
|
33
|
+
export function validateVaultManagedSkill(policy, entry) {
|
|
34
|
+
if (policy && entry.key.startsWith(SKILL_SECRET_PREFIX) && !accepted(policy, entry)) {
|
|
35
|
+
throw new CoreError('SKILL_SECRET_NOT_VAULT_SAFE');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function migrate(policy, entries, { safeEntries, log }) {
|
|
39
|
+
try {
|
|
40
|
+
return new Set((await policy.migrateLegacy?.(entries, { safeEntries })) ?? []);
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
log?.warn('lifecycle', 'the vault took no skill values', err);
|
|
44
|
+
return new Set();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export async function quarantinedSkillKeys(local) {
|
|
48
|
+
const entries = await local.listPrefix(QUARANTINE_PREFIX + SKILL_SECRET_PREFIX);
|
|
49
|
+
return entries.map(({ key }) => key.slice(QUARANTINE_PREFIX.length));
|
|
50
|
+
}
|
|
51
|
+
export async function discardQuarantinedSkills(local, keys) {
|
|
52
|
+
const skills = keys.filter((key) => key.startsWith(SKILL_SECRET_PREFIX));
|
|
53
|
+
if (skills.length) {
|
|
54
|
+
await local.deleteAll(skills.map((key) => QUARANTINE_PREFIX + key));
|
|
55
|
+
}
|
|
56
|
+
return quarantinedSkillKeys(local);
|
|
57
|
+
}
|
|
58
|
+
export async function releaseQuarantinedSkills(local, entries) {
|
|
59
|
+
const set = entries.filter(({ key, value }) => key.startsWith(SKILL_SECRET_PREFIX) && !cleared(value));
|
|
60
|
+
if (set.length) {
|
|
61
|
+
await local.deleteAll(set.map(({ key }) => QUARANTINE_PREFIX + key));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export async function prepareVaultManagedSkills(policy, local, log = null) {
|
|
65
|
+
if (!policy)
|
|
66
|
+
return [];
|
|
67
|
+
const live = await local.listPrefix(SKILL_SECRET_PREFIX);
|
|
68
|
+
const held = new Set(live.filter((entry) => reconnected(policy, entry)).map(({ key }) => key));
|
|
69
|
+
const legacy = live.filter((entry) => !accepted(policy, entry));
|
|
70
|
+
const unsafe = new Set(legacy.map(({ key }) => key));
|
|
71
|
+
const waiting = [];
|
|
72
|
+
const stale = [];
|
|
73
|
+
for (const { key, value } of await local.listPrefix(QUARANTINE_PREFIX + SKILL_SECRET_PREFIX)) {
|
|
74
|
+
const original = key.slice(QUARANTINE_PREFIX.length);
|
|
75
|
+
if (held.has(original) || unsafe.has(original)) {
|
|
76
|
+
stale.push(original);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
waiting.push({ key: original, value });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const pending = [...legacy, ...waiting];
|
|
83
|
+
const migrated = pending.length
|
|
84
|
+
? await migrate(policy, pending, {
|
|
85
|
+
safeEntries: live.filter((entry) => accepted(policy, entry)),
|
|
86
|
+
log
|
|
87
|
+
})
|
|
88
|
+
: new Set();
|
|
89
|
+
return local.change(async (get) => {
|
|
90
|
+
const current = await Promise.all(pending.map(async ({ key }) => ({ key, value: await get(key) })));
|
|
91
|
+
const replaced = new Set(current.filter((entry) => reconnected(policy, entry)).map(({ key }) => key));
|
|
92
|
+
const kept = pending.filter(({ key }) => !migrated.has(key) && !replaced.has(key));
|
|
93
|
+
const quarantined = new Set(kept.map(({ key }) => key));
|
|
94
|
+
return {
|
|
95
|
+
result: [...quarantined],
|
|
96
|
+
set: kept.map(({ key, value }) => ({ key: QUARANTINE_PREFIX + key, value })),
|
|
97
|
+
delete: [
|
|
98
|
+
...legacy.filter(({ key }) => !replaced.has(key)).map(({ key }) => key),
|
|
99
|
+
...[...stale, ...waiting.map(({ key }) => key)]
|
|
100
|
+
.filter((key) => !quarantined.has(key))
|
|
101
|
+
.map((key) => QUARANTINE_PREFIX + key)
|
|
102
|
+
]
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
}
|
package/dist-lib/lib/core.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { type MeshInvite } from './core/invite.ts';
|
|
|
17
17
|
import { openLocalStore } from './core/local/index.ts';
|
|
18
18
|
import { type ArchivedMeshContents, type ArchivedMeshMigration } from './core/archived-mesh.ts';
|
|
19
19
|
import { type SkillSecretRequest } from './core/skill-secrets.ts';
|
|
20
|
+
import { type VaultManagedSkills } from './core/vault-managed-skills.ts';
|
|
20
21
|
import type { AppBuildMetadata } from './core/app-build.ts';
|
|
21
22
|
import { type ConfigCore } from './core/ota-config.ts';
|
|
22
23
|
import { Mesh, type DeviceMetadata, type ProjectIdentity } from './core/mesh.ts';
|
|
@@ -34,6 +35,7 @@ export interface FileGcOptions {
|
|
|
34
35
|
}
|
|
35
36
|
export interface CoreOptions {
|
|
36
37
|
storagePath: string;
|
|
38
|
+
skillSecrets?: VaultManagedSkills;
|
|
37
39
|
store?: Corestore;
|
|
38
40
|
swarm?: Hyperswarm;
|
|
39
41
|
wakeup?: Wakeup;
|
|
@@ -257,6 +259,8 @@ export declare class Core extends ReadyResource {
|
|
|
257
259
|
private readonly _projectKeySeals;
|
|
258
260
|
private readonly _hosting;
|
|
259
261
|
private readonly _skillSecrets;
|
|
262
|
+
private readonly _vaultManagedSkills;
|
|
263
|
+
private _quarantine;
|
|
260
264
|
private readonly _hostMeshes;
|
|
261
265
|
private readonly _hostJoins;
|
|
262
266
|
private readonly _agentListeners;
|
|
@@ -287,7 +291,7 @@ export declare class Core extends ReadyResource {
|
|
|
287
291
|
private _systemInfo;
|
|
288
292
|
private _statusError;
|
|
289
293
|
private _upgradeRequired;
|
|
290
|
-
constructor(transport: Transport, { storagePath, store, swarm, wakeup, logger, spec, bootstrapNodes, device, app, minSupportedVersion, otaConfigCore, blindPeerKeys, blindPeeringOpts, fileGc, autoDownloadModels, meshSeed, meshKey, additionalNodes, listModels, deleteModel, clearKvCache, deleteChatKvCache, compactChat, modelCatalogWatch, retryModelDownload, transcribe, detectLanguage, previewModelSource, speak, speakStream, embedder, extractors, skills, skillCatalog, tools, hostsModelSource, vectorIndex, apiLifecycle, network }: CoreOptions);
|
|
294
|
+
constructor(transport: Transport, { storagePath, skillSecrets, store, swarm, wakeup, logger, spec, bootstrapNodes, device, app, minSupportedVersion, otaConfigCore, blindPeerKeys, blindPeeringOpts, fileGc, autoDownloadModels, meshSeed, meshKey, additionalNodes, listModels, deleteModel, clearKvCache, deleteChatKvCache, compactChat, modelCatalogWatch, retryModelDownload, transcribe, detectLanguage, previewModelSource, speak, speakStream, embedder, extractors, skills, skillCatalog, tools, hostsModelSource, vectorIndex, apiLifecycle, network }: CoreOptions);
|
|
291
295
|
get devicePublicKey(): Buffer | null;
|
|
292
296
|
private _requireDeviceKeyPair;
|
|
293
297
|
get fsDrives(): DriveHost | null;
|
|
@@ -355,6 +359,7 @@ export declare class Core extends ReadyResource {
|
|
|
355
359
|
private _holdIdentityPhrase;
|
|
356
360
|
private _pushIdentityPhrase;
|
|
357
361
|
private _offerIdentityPhrase;
|
|
362
|
+
private _skillOauth;
|
|
358
363
|
private _startBlindPeering;
|
|
359
364
|
setBlindPeering(enabled: boolean): Promise<AssistantBlindPeering>;
|
|
360
365
|
private _peeredMeshes;
|
|
@@ -469,6 +474,7 @@ export declare class Core extends ReadyResource {
|
|
|
469
474
|
private _listenMesh;
|
|
470
475
|
private _wireForeign;
|
|
471
476
|
private _adoptAccount;
|
|
477
|
+
private _backfillModelPick;
|
|
472
478
|
private _publicMesh;
|
|
473
479
|
private _publicIdOf;
|
|
474
480
|
private _workspaceOfPublic;
|
|
@@ -618,6 +624,9 @@ export declare class Core extends ReadyResource {
|
|
|
618
624
|
previewMeshInvite(invite: string): MeshInvitePreview;
|
|
619
625
|
private _closeSwarm;
|
|
620
626
|
pushSkillSecret(request: SkillSecretRequest): Promise<void>;
|
|
627
|
+
private _offerQuarantined;
|
|
628
|
+
private _discardQuarantined;
|
|
629
|
+
private _releaseQuarantined;
|
|
621
630
|
private _followSkillSecrets;
|
|
622
631
|
private _followJoinedMeshes;
|
|
623
632
|
private _followJoinedMeshesPass;
|
package/dist-lib/lib/core.js
CHANGED
|
@@ -14,7 +14,7 @@ import ReadyResource from 'ready-resource';
|
|
|
14
14
|
import ScopeLock from 'scope-lock';
|
|
15
15
|
import { isAndroid } from 'which-runtime';
|
|
16
16
|
import { createApi } from './api/index.js';
|
|
17
|
-
import { writeAutoDownloadModels } from './api/app-config.js';
|
|
17
|
+
import { backfillLastModelName, readLastModelName, writeAutoDownloadModels } from './api/app-config.js';
|
|
18
18
|
import { requireOurAdmin, requireWorkspace } from './api/members.js';
|
|
19
19
|
import { projectName } from './api/projects.js';
|
|
20
20
|
import { createServedApi } from './api/served.js';
|
|
@@ -25,20 +25,21 @@ import { openSealedToDevice, sealToDevice } from './core/device-seal.js';
|
|
|
25
25
|
import { removedBy } from './core/contract/invites.js';
|
|
26
26
|
import { meshKind } from './core/contract/mesh-kind.js';
|
|
27
27
|
import { WORKSPACES_RULES, bornUnderRules, rulesVersion } from './core/contract/mesh-rules.js';
|
|
28
|
-
import { inProject, listedProject, listsMember, liveMember, projectMember, projectOfGroup,
|
|
28
|
+
import { inProject, listedProject, listsMember, liveMember, projectMember, projectOfGroup, projectKeys, readProject, UNGROUPED } from './core/contract/projects.js';
|
|
29
29
|
import { requireMesh } from './api/current-mesh.js';
|
|
30
30
|
import { CoreError } from './errors.js';
|
|
31
31
|
import { ChatMoves } from './core/chat-move.js';
|
|
32
32
|
import { purgeCores } from './core/purge.js';
|
|
33
33
|
import { copyContent } from './core/chat-copy.js';
|
|
34
34
|
import { followAgentCopies, keepCopyChats } from './core/agent-copies.js';
|
|
35
|
+
import { cancelDeletedAgentRuns } from './core/deleted-agent-runs.js';
|
|
35
36
|
import { devicesOfMember } from './core/contract/activity.js';
|
|
36
|
-
import { followPickedAgents, followSharedAgents, liveSharedAgent, pickAgent, shareAgent, unpickAgent } from './core/shared-agents.js';
|
|
37
|
+
import { followPickedAgents, followSharedAgents, ownerOf, liveSharedAgent, pickAgent, shareAgent, unpickAgent } from './core/shared-agents.js';
|
|
37
38
|
import { inRole, publicRoute } from './core/contract/roles.js';
|
|
38
39
|
import { freshPublicRecord, isOwnWorkspace, isPublicRecord, lostMint, onOwnSeed, leftPublicRecordKey, ownWorkspaceSeed, ownWorkspaces, publicMeshKey, publicRecordKey, publicSeed, servesAgents, servesChat, servesChunk } from './core/public-mesh.js';
|
|
39
40
|
import { memberBoxKeyPair, openSealedToMember } from './core/member-key.js';
|
|
40
|
-
import { dueProjectDeviceKeys, dueProjectHostKey, dueProjectKey } from './core/project-keys.js';
|
|
41
|
-
import {
|
|
41
|
+
import { dueProjectDeviceKeys, dueProjectHostKey, dueProjectKey, seedFingerprint, seedOpens } from './core/project-keys.js';
|
|
42
|
+
import { projectDeviceKeys } from './core/contract/project-device-keys.js';
|
|
42
43
|
import { agentJoin, freshHostRecord, hostRecordKey, hostState, hostTargets, isHostRecord } from './core/agent-hosting.js';
|
|
43
44
|
import { hostForWriter } from './core/contract/model-requests.js';
|
|
44
45
|
import { asEncoded, watchModels } from './models-watch.js';
|
|
@@ -55,11 +56,13 @@ import { backgroundSyncKey } from './core/local/files.js';
|
|
|
55
56
|
import { FOLD_PENDING, GROUPS_PENDING, agentsFoldKey, groupBuckets, groupRecordKey, isGroupRecord, liveGroups, projectsByGroup, upgradeCheckedKey } from './core/workspace-upgrade.js';
|
|
56
57
|
import { foldAgents, ownCopies } from './core/upgrade-agents.js';
|
|
57
58
|
import { MAX_MESH_NAME_CHARS, meshNameWithinBounds } from '../schema/qvac.js';
|
|
58
|
-
import { rehomeAgents } from './core/agent.js';
|
|
59
|
+
import { getDefaultAgent, mustGetActiveAgent, rehomeAgents } from './core/agent.js';
|
|
60
|
+
import { pickRunner } from './core/run-requests.js';
|
|
59
61
|
import { countContents, migrateContents, withArchivedMesh } from './core/archived-mesh.js';
|
|
60
62
|
import { isMobilePlatform } from '@qvac/harness/lib/models/model-catalog.ts';
|
|
61
63
|
import { storeSkillSecret, syncSkillSecrets } from './core/skill-secrets.js';
|
|
62
64
|
import { SKILL_SECRET_PREFIX } from './core/contract/skill-secrets.js';
|
|
65
|
+
import { discardQuarantinedSkills, prepareVaultManagedSkills, quarantinedSkillKeys, releaseQuarantinedSkills, validateVaultManagedSkill } from './core/vault-managed-skills.js';
|
|
63
66
|
import { attestDeviceProof, attestMemberClaim, chainTo, claimAttestation, delegationFits, openIdentity, pairingAnchorSeed } from './core/identity.js';
|
|
64
67
|
import { openRecoveryCore, publishRecovery, readRecovery, recoveryKeys } from './core/account-recovery.js';
|
|
65
68
|
import { claimOwnMembership, legacyNameStamp, namedAt, renameFoundedMember } from './core/membership.js';
|
|
@@ -90,6 +93,7 @@ const QVAC_CORE_NAMESPACE = 'qvac-core';
|
|
|
90
93
|
const MESH_ID = /^[0-9a-f]{64}$/;
|
|
91
94
|
export const DEVICE_UNKNOWN = 'This device has no device details: pass `device` when creating Core';
|
|
92
95
|
const RECOVERY_WAIT_MS = 30_000;
|
|
96
|
+
const WINNER_ADMISSION_WAIT_MS = 60_000;
|
|
93
97
|
const TOPIC_RETRY_MS = [1_000, 5_000, 15_000];
|
|
94
98
|
const MESH_DIED = 'the local database died';
|
|
95
99
|
const MESH_NOT_EMPTY = 'this mesh is not empty: everyone in it will see the newcomer arrive, and the newcomer replays the whole history of the mesh, including what earlier members wrote';
|
|
@@ -223,6 +227,8 @@ export class Core extends ReadyResource {
|
|
|
223
227
|
_projectKeySeals = new ScopeLock({ debounce: true });
|
|
224
228
|
_hosting = new ScopeLock({ debounce: true });
|
|
225
229
|
_skillSecrets = new ScopeLock({ debounce: true });
|
|
230
|
+
_vaultManagedSkills;
|
|
231
|
+
_quarantine = Promise.resolve([]);
|
|
226
232
|
_hostMeshes = new Set();
|
|
227
233
|
_hostJoins = new WeakMap();
|
|
228
234
|
_agentListeners = new Set();
|
|
@@ -253,7 +259,7 @@ export class Core extends ReadyResource {
|
|
|
253
259
|
_systemInfo;
|
|
254
260
|
_statusError;
|
|
255
261
|
_upgradeRequired;
|
|
256
|
-
constructor(transport, { storagePath, store = undefined, swarm = undefined, wakeup = undefined, logger = null, spec = openLocalSpec, bootstrapNodes = undefined, device = undefined, app = undefined, minSupportedVersion = undefined, otaConfigCore = undefined, blindPeerKeys = undefined, blindPeeringOpts = undefined, fileGc = null, autoDownloadModels = undefined, meshSeed = undefined, meshKey = undefined, additionalNodes = undefined, listModels = undefined, deleteModel = undefined, clearKvCache = undefined, deleteChatKvCache = undefined, compactChat = undefined, modelCatalogWatch = undefined, retryModelDownload = undefined, transcribe = undefined, detectLanguage = undefined, previewModelSource = undefined, speak = undefined, speakStream = undefined, embedder = undefined, extractors = undefined, skills = undefined, skillCatalog = undefined, tools = undefined, hostsModelSource = false, vectorIndex = undefined, apiLifecycle = undefined, network = undefined }) {
|
|
262
|
+
constructor(transport, { storagePath, skillSecrets = undefined, store = undefined, swarm = undefined, wakeup = undefined, logger = null, spec = openLocalSpec, bootstrapNodes = undefined, device = undefined, app = undefined, minSupportedVersion = undefined, otaConfigCore = undefined, blindPeerKeys = undefined, blindPeeringOpts = undefined, fileGc = null, autoDownloadModels = undefined, meshSeed = undefined, meshKey = undefined, additionalNodes = undefined, listModels = undefined, deleteModel = undefined, clearKvCache = undefined, deleteChatKvCache = undefined, compactChat = undefined, modelCatalogWatch = undefined, retryModelDownload = undefined, transcribe = undefined, detectLanguage = undefined, previewModelSource = undefined, speak = undefined, speakStream = undefined, embedder = undefined, extractors = undefined, skills = undefined, skillCatalog = undefined, tools = undefined, hostsModelSource = false, vectorIndex = undefined, apiLifecycle = undefined, network = undefined }) {
|
|
257
263
|
super();
|
|
258
264
|
this._transport = transport;
|
|
259
265
|
this._apiLifecycle = apiLifecycle ?? {
|
|
@@ -315,6 +321,7 @@ export class Core extends ReadyResource {
|
|
|
315
321
|
this._ragExtractors = extractors;
|
|
316
322
|
this._skills = skills ?? null;
|
|
317
323
|
this._skillCatalog = skillCatalog ?? null;
|
|
324
|
+
this._vaultManagedSkills = skillSecrets;
|
|
318
325
|
this._skillManagement = null;
|
|
319
326
|
this._tools = tools ?? null;
|
|
320
327
|
this._hostsModelSource = hostsModelSource;
|
|
@@ -392,6 +399,10 @@ export class Core extends ReadyResource {
|
|
|
392
399
|
return [...new Set(ids)].sort();
|
|
393
400
|
}
|
|
394
401
|
async _open() {
|
|
402
|
+
const { length: quarantined } = await this._offerQuarantined();
|
|
403
|
+
if (quarantined) {
|
|
404
|
+
this._log?.warn('lifecycle', 'skill values wait for the vault', { quarantined });
|
|
405
|
+
}
|
|
395
406
|
this._log?.info('lifecycle', 'core opening', {
|
|
396
407
|
app: this._app?.version ?? null,
|
|
397
408
|
build: this._app?.build ?? null,
|
|
@@ -517,11 +528,18 @@ export class Core extends ReadyResource {
|
|
|
517
528
|
return workspaceId === this._ownWorkspaceId ? null : workspaceId;
|
|
518
529
|
},
|
|
519
530
|
pushSkillSecret: (request) => this.pushSkillSecret(request),
|
|
520
|
-
|
|
521
|
-
|
|
531
|
+
beforeConfigSet: (entry) => validateVaultManagedSkill(this._vaultManagedSkills, entry),
|
|
532
|
+
onConfigSet: async (entry) => {
|
|
533
|
+
if (entry.key.startsWith(SKILL_SECRET_PREFIX)) {
|
|
522
534
|
void this._followSkillSecrets();
|
|
535
|
+
await this._releaseQuarantined([entry]);
|
|
523
536
|
}
|
|
524
537
|
},
|
|
538
|
+
listQuarantinedSkills: async () => ({ keys: await quarantinedSkillKeys(this.local) }),
|
|
539
|
+
retryQuarantinedSkills: async () => ({ keys: await this._offerQuarantined() }),
|
|
540
|
+
discardQuarantinedSkills: async ({ keys }) => ({
|
|
541
|
+
keys: await this._discardQuarantined(keys)
|
|
542
|
+
}),
|
|
525
543
|
storageRoot: path.dirname(this._storagePath),
|
|
526
544
|
listModels: this._hostsModelSource || this._listModels
|
|
527
545
|
? async (request) => (await this._readModelList(request)) ?? { models: [] }
|
|
@@ -641,6 +659,7 @@ export class Core extends ReadyResource {
|
|
|
641
659
|
})
|
|
642
660
|
: null
|
|
643
661
|
});
|
|
662
|
+
api.skillOauth = (request) => this._skillOauth(request);
|
|
644
663
|
this._servedToSiblings = servedToSiblings(api);
|
|
645
664
|
this._api = {
|
|
646
665
|
...api,
|
|
@@ -669,6 +688,7 @@ export class Core extends ReadyResource {
|
|
|
669
688
|
const rpc = settleOnClose(new HRPC(this._stream));
|
|
670
689
|
bindApi(rpc, this._api);
|
|
671
690
|
this._rpcs.add(rpc);
|
|
691
|
+
this._stream.on('close', () => this._rpcs.delete(rpc));
|
|
672
692
|
this._offlineBoot.exit();
|
|
673
693
|
void this._pushIdentityPhrase();
|
|
674
694
|
this._chatMoves
|
|
@@ -1280,6 +1300,7 @@ export class Core extends ReadyResource {
|
|
|
1280
1300
|
await mesh.appendBirthOp(this._requireDeviceKeyPair(), this._localDevice ?? undefined, {
|
|
1281
1301
|
member: birth?.member,
|
|
1282
1302
|
sharing,
|
|
1303
|
+
modelName: (await readLastModelName(this.local)) ?? undefined,
|
|
1283
1304
|
workspace,
|
|
1284
1305
|
project
|
|
1285
1306
|
});
|
|
@@ -1679,6 +1700,44 @@ export class Core extends ReadyResource {
|
|
|
1679
1700
|
return false;
|
|
1680
1701
|
}
|
|
1681
1702
|
}
|
|
1703
|
+
async _skillOauth(request) {
|
|
1704
|
+
const account = this._accountMesh();
|
|
1705
|
+
if (!account) {
|
|
1706
|
+
throw new CoreError('MESH_NOT_FOUND', ['account']);
|
|
1707
|
+
}
|
|
1708
|
+
const deviceId = this._requireDeviceKeyPair().publicKey;
|
|
1709
|
+
if (request.operation === 'target' && !isMobilePlatform(this._localDevice?.platform ?? '')) {
|
|
1710
|
+
return { phase: 'local', deviceId };
|
|
1711
|
+
}
|
|
1712
|
+
const agent = await mustGetActiveAgent(account, request.agentId);
|
|
1713
|
+
const owner = await ownerOf(account, agent);
|
|
1714
|
+
if (!owner || !account.ourMemberId || !b4a.equals(owner, account.ourMemberId)) {
|
|
1715
|
+
throw new CoreError('AGENT_NOT_OURS');
|
|
1716
|
+
}
|
|
1717
|
+
if (request.operation === 'target') {
|
|
1718
|
+
const mesh = await requireMesh(this._meshPool(), request.meshId ?? this._meshIdOf(account), {
|
|
1719
|
+
route: 'put-chat'
|
|
1720
|
+
});
|
|
1721
|
+
const runner = await pickRunner(mesh, {
|
|
1722
|
+
deviceId,
|
|
1723
|
+
peers: this.peerDeviceIds,
|
|
1724
|
+
agent
|
|
1725
|
+
});
|
|
1726
|
+
return { phase: runner ? 'ready' : 'local', deviceId: runner ?? deviceId };
|
|
1727
|
+
}
|
|
1728
|
+
for (const rpc of this._rpcs) {
|
|
1729
|
+
const response = await rpc.skillOauth(request);
|
|
1730
|
+
if (response.phase === 'unavailable') {
|
|
1731
|
+
continue;
|
|
1732
|
+
}
|
|
1733
|
+
if ((request.operation !== 'config' && response.phase === 'connected') ||
|
|
1734
|
+
(request.operation === 'disconnect' && response.phase === 'ready')) {
|
|
1735
|
+
await this._skillCatalog?.(request.agentId, null, { refresh: true });
|
|
1736
|
+
}
|
|
1737
|
+
return response;
|
|
1738
|
+
}
|
|
1739
|
+
throw new CoreError('DEVICE_ROUTE_NOT_SERVED', ['skillOauth']);
|
|
1740
|
+
}
|
|
1682
1741
|
_startBlindPeering(mesh) {
|
|
1683
1742
|
const peering = this._blindPeeringClient();
|
|
1684
1743
|
if (peering) {
|
|
@@ -2976,12 +3035,12 @@ export class Core extends ReadyResource {
|
|
|
2976
3035
|
await this._following.get(projectId);
|
|
2977
3036
|
}
|
|
2978
3037
|
const winner = this._pooled(projectId) ?? (await this._heldMesh(row.id));
|
|
2979
|
-
await winner?.waitForWritable();
|
|
2980
|
-
return winner;
|
|
3038
|
+
await winner?.waitForWritable(WINNER_ADMISSION_WAIT_MS);
|
|
3039
|
+
return winner?.writable ? winner : null;
|
|
2981
3040
|
}
|
|
2982
3041
|
async _copyGroup(workspace, project, { chats }) {
|
|
2983
3042
|
const deviceId = this._requireDeviceKeyPair().publicKey;
|
|
2984
|
-
await copyContent({ from: workspace, into: project, deviceId, chats });
|
|
3043
|
+
await copyContent({ from: workspace, into: project, deviceId, chats, endsOpenRuns: true });
|
|
2985
3044
|
}
|
|
2986
3045
|
async _addWorkspaceMembers(workspace, project) {
|
|
2987
3046
|
for (const memberId of await this._workspaceMembers(workspace)) {
|
|
@@ -3520,6 +3579,16 @@ export class Core extends ReadyResource {
|
|
|
3520
3579
|
this._notifyStatus();
|
|
3521
3580
|
void this._followPublicMesh(mesh);
|
|
3522
3581
|
void this._followSkillSecrets();
|
|
3582
|
+
void this._backfillModelPick(mesh);
|
|
3583
|
+
}
|
|
3584
|
+
async _backfillModelPick(mesh) {
|
|
3585
|
+
const deviceId = this._requireDeviceKeyPair().publicKey;
|
|
3586
|
+
try {
|
|
3587
|
+
await backfillLastModelName(this.local, async () => (await getDefaultAgent(mesh, deviceId))?.modelName ?? null);
|
|
3588
|
+
}
|
|
3589
|
+
catch (err) {
|
|
3590
|
+
this._log?.warn(['mesh'], 'backfilling the model pick failed', err);
|
|
3591
|
+
}
|
|
3523
3592
|
}
|
|
3524
3593
|
_publicMesh(workspaceId = this._accountId) {
|
|
3525
3594
|
return this._pooled(this._publicIdOf(workspaceId));
|
|
@@ -3566,8 +3635,9 @@ export class Core extends ReadyResource {
|
|
|
3566
3635
|
}
|
|
3567
3636
|
async _shareProjectSeed(batch, { workspace, project, agent, picking }) {
|
|
3568
3637
|
const projectId = project.key;
|
|
3569
|
-
const
|
|
3570
|
-
const
|
|
3638
|
+
const sealedBy = workspace.ourMemberId;
|
|
3639
|
+
const seed = sealedBy && (await this._heldProjectSeed(workspace, projectId));
|
|
3640
|
+
const sealing = seed && { projectId, seed, project: project.view, sealedBy, picking };
|
|
3571
3641
|
const due = sealing && (await dueProjectHostKey(workspace.view, agent, sealing));
|
|
3572
3642
|
if (due) {
|
|
3573
3643
|
batch.dispatch('put-project-host-key', due);
|
|
@@ -4052,7 +4122,12 @@ export class Core extends ReadyResource {
|
|
|
4052
4122
|
if (!this._isAccount(account) || !this._isPooled(into)) {
|
|
4053
4123
|
return;
|
|
4054
4124
|
}
|
|
4055
|
-
await copyContent({
|
|
4125
|
+
await copyContent({
|
|
4126
|
+
from: account,
|
|
4127
|
+
into,
|
|
4128
|
+
deviceId: this._requireDeviceKeyPair().publicKey,
|
|
4129
|
+
endsOpenRuns: true
|
|
4130
|
+
});
|
|
4056
4131
|
const latest = (await this._publicRecord(account, workspaceKey)) ?? record;
|
|
4057
4132
|
await this._savePublicRecord(account, workspaceKey, { ...latest, migrated: true });
|
|
4058
4133
|
this._log?.info(['p2p', 'mesh'], 'copied the account into its public mesh', {
|
|
@@ -4689,6 +4764,25 @@ export class Core extends ReadyResource {
|
|
|
4689
4764
|
};
|
|
4690
4765
|
mesh.on('chat-purged', () => void reclaim());
|
|
4691
4766
|
mesh.on('landed', () => void reclaim());
|
|
4767
|
+
let canceling = Promise.resolve();
|
|
4768
|
+
const cancelRuns = (landed) => {
|
|
4769
|
+
canceling = canceling
|
|
4770
|
+
.then(async () => {
|
|
4771
|
+
if (mesh.writable) {
|
|
4772
|
+
await cancelDeletedAgentRuns(mesh, deviceId, landed);
|
|
4773
|
+
}
|
|
4774
|
+
})
|
|
4775
|
+
.catch((error) => {
|
|
4776
|
+
if (!mesh.closing) {
|
|
4777
|
+
this._log?.warn(['p2p', 'mesh'], "canceling a deleted agent's runs failed", error);
|
|
4778
|
+
}
|
|
4779
|
+
});
|
|
4780
|
+
};
|
|
4781
|
+
const cancelAll = () => cancelRuns(null);
|
|
4782
|
+
mesh.on('runs-landed', cancelRuns);
|
|
4783
|
+
mesh.on('landed', cancelAll);
|
|
4784
|
+
mesh.autobee.on('writable', cancelAll);
|
|
4785
|
+
cancelAll();
|
|
4692
4786
|
const sweepLock = new ScopeLock({ debounce: true });
|
|
4693
4787
|
const sweep = async () => {
|
|
4694
4788
|
if (!(await sweepLock.lock()))
|
|
@@ -5219,11 +5313,11 @@ export class Core extends ReadyResource {
|
|
|
5219
5313
|
}
|
|
5220
5314
|
async _listProject(workspace, project, listing) {
|
|
5221
5315
|
const batch = workspace.batch();
|
|
5222
|
-
|
|
5316
|
+
const listed = { id: project.key, ...listing, seedFingerprint: seedFingerprint(project.seed) };
|
|
5317
|
+
batch.dispatch('put-project', { project: listed });
|
|
5223
5318
|
const ours = workspace.ourMemberId;
|
|
5224
|
-
const
|
|
5225
|
-
|
|
5226
|
-
: null;
|
|
5319
|
+
const sealing = ours && { projectId: project.key, seed: project.seed, sealedBy: ours };
|
|
5320
|
+
const own = sealing ? await dueProjectKey(workspace.view, ours, sealing) : null;
|
|
5227
5321
|
if (own) {
|
|
5228
5322
|
batch.dispatch('put-project-key', own);
|
|
5229
5323
|
}
|
|
@@ -5926,12 +6020,33 @@ export class Core extends ReadyResource {
|
|
|
5926
6020
|
await this.ready();
|
|
5927
6021
|
await storeSkillSecret({
|
|
5928
6022
|
local: this.local,
|
|
6023
|
+
validate: (entry) => validateVaultManagedSkill(this._vaultManagedSkills, entry),
|
|
5929
6024
|
setupFields: (skillName) => this._setupFields(skillName),
|
|
5930
|
-
onstored: () =>
|
|
6025
|
+
onstored: async (entries) => {
|
|
6026
|
+
await this._releaseQuarantined(entries);
|
|
6027
|
+
await this._skillCatalog?.(null, null, { refresh: true });
|
|
6028
|
+
}
|
|
5931
6029
|
}, request);
|
|
5932
6030
|
await this._followSkillSecrets();
|
|
5933
6031
|
}
|
|
6032
|
+
_offerQuarantined() {
|
|
6033
|
+
const offer = () => prepareVaultManagedSkills(this._vaultManagedSkills, this.local, this._log);
|
|
6034
|
+
this._quarantine = this._quarantine.then(offer, offer);
|
|
6035
|
+
return this._quarantine;
|
|
6036
|
+
}
|
|
6037
|
+
_discardQuarantined(keys) {
|
|
6038
|
+
const discard = () => discardQuarantinedSkills(this.local, keys);
|
|
6039
|
+
this._quarantine = this._quarantine.then(discard, discard);
|
|
6040
|
+
return this._quarantine;
|
|
6041
|
+
}
|
|
6042
|
+
async _releaseQuarantined(entries) {
|
|
6043
|
+
if (this._vaultManagedSkills) {
|
|
6044
|
+
await releaseQuarantinedSkills(this.local, entries);
|
|
6045
|
+
}
|
|
6046
|
+
}
|
|
5934
6047
|
async _followSkillSecrets() {
|
|
6048
|
+
if (this._vaultManagedSkills)
|
|
6049
|
+
return;
|
|
5935
6050
|
if (!(await this._skillSecrets.lock()))
|
|
5936
6051
|
return;
|
|
5937
6052
|
try {
|
|
@@ -6253,27 +6368,36 @@ export class Core extends ReadyResource {
|
|
|
6253
6368
|
}
|
|
6254
6369
|
}
|
|
6255
6370
|
async _sealListedMembers(workspace, row, seed) {
|
|
6371
|
+
const sealedBy = workspace.ourMemberId;
|
|
6372
|
+
if (!sealedBy) {
|
|
6373
|
+
return;
|
|
6374
|
+
}
|
|
6256
6375
|
const batch = workspace.batch();
|
|
6257
6376
|
for (const memberId of row.memberIds ?? []) {
|
|
6258
|
-
const due = await dueProjectKey(workspace.view, memberId, {
|
|
6377
|
+
const due = await dueProjectKey(workspace.view, memberId, {
|
|
6378
|
+
projectId: row.id,
|
|
6379
|
+
seed,
|
|
6380
|
+
sealedBy
|
|
6381
|
+
});
|
|
6259
6382
|
if (due) {
|
|
6260
6383
|
batch.dispatch('put-project-key', due);
|
|
6261
6384
|
}
|
|
6262
6385
|
}
|
|
6263
|
-
for (const due of await dueProjectDeviceKeys(workspace.view, row, seed)) {
|
|
6386
|
+
for (const due of await dueProjectDeviceKeys(workspace.view, row, { seed, sealedBy })) {
|
|
6264
6387
|
batch.dispatch('put-project-device-key', due);
|
|
6265
6388
|
}
|
|
6266
6389
|
await batch.flush();
|
|
6267
6390
|
}
|
|
6268
6391
|
async _sealProjectHosts(workspace, projectId, seed) {
|
|
6269
6392
|
const project = this._pooled(b4a.toHex(projectId));
|
|
6270
|
-
|
|
6393
|
+
const sealedBy = workspace.ourMemberId;
|
|
6394
|
+
if (!project || this._isForeign(project) || !sealedBy) {
|
|
6271
6395
|
return;
|
|
6272
6396
|
}
|
|
6273
6397
|
const batch = workspace.batch();
|
|
6274
6398
|
for (const user of await workspace.view.find(AGENT_USERS).toArray()) {
|
|
6275
6399
|
const agent = b4a.equals(user.userId, projectId) && (await liveSharedAgent(workspace, user.agentId));
|
|
6276
|
-
const sealing = { projectId, seed, project: project.view };
|
|
6400
|
+
const sealing = { projectId, seed, project: project.view, sealedBy };
|
|
6277
6401
|
const due = agent && (await dueProjectHostKey(workspace.view, agent, sealing));
|
|
6278
6402
|
if (due) {
|
|
6279
6403
|
batch.dispatch('put-project-host-key', due);
|
|
@@ -6294,19 +6418,29 @@ export class Core extends ReadyResource {
|
|
|
6294
6418
|
async _memberProjectSeed(workspace, projectId) {
|
|
6295
6419
|
const ours = workspace.ourMemberId;
|
|
6296
6420
|
const account = this._accountMesh();
|
|
6297
|
-
|
|
6421
|
+
const project = await readProject(workspace.view, projectId);
|
|
6422
|
+
if (!ours || !account || !project) {
|
|
6298
6423
|
return null;
|
|
6299
6424
|
}
|
|
6300
|
-
const row = await readProjectKey(workspace.view, projectId, ours);
|
|
6301
6425
|
const pair = memberBoxKeyPair(account.seed);
|
|
6302
|
-
|
|
6303
|
-
|
|
6304
|
-
|
|
6426
|
+
for (const row of await projectKeys(workspace.view, projectId, ours)) {
|
|
6427
|
+
const seed = b4a.equals(row.boxKey, pair.publicKey) && openSealedToMember(row.sealedSeed, pair);
|
|
6428
|
+
if (seed && seedOpens(project, seed)) {
|
|
6429
|
+
return seed;
|
|
6430
|
+
}
|
|
6431
|
+
}
|
|
6432
|
+
return null;
|
|
6305
6433
|
}
|
|
6306
6434
|
async _deviceProjectSeed(workspace, projectId) {
|
|
6307
6435
|
const device = this._requireDeviceKeyPair();
|
|
6308
|
-
const
|
|
6309
|
-
|
|
6436
|
+
const project = await readProject(workspace.view, projectId);
|
|
6437
|
+
for (const row of await projectDeviceKeys(workspace.view, projectId, device.publicKey)) {
|
|
6438
|
+
const seed = openSealedToDevice(row.sealedSeed, device);
|
|
6439
|
+
if (project && seed && seedOpens(project, seed)) {
|
|
6440
|
+
return seed;
|
|
6441
|
+
}
|
|
6442
|
+
}
|
|
6443
|
+
return null;
|
|
6310
6444
|
}
|
|
6311
6445
|
async _projectGone(projectId) {
|
|
6312
6446
|
if (this._isHidden(projectId, this._pooled(projectId)?.workspaceKey)) {
|