@qvac/core 1.0.0-rc.3 → 1.0.0-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +106 -36
  2. package/dist-lib/index.d.ts +2 -1
  3. package/dist-lib/lib/api/approval-rules.d.ts +1 -1
  4. package/dist-lib/lib/api/approval-rules.js +5 -1
  5. package/dist-lib/lib/api/config.d.ts +6 -2
  6. package/dist-lib/lib/api/config.js +9 -5
  7. package/dist-lib/lib/api/index.d.ts +12 -2
  8. package/dist-lib/lib/api/index.js +6 -1
  9. package/dist-lib/lib/api/rag.js +5 -5
  10. package/dist-lib/lib/assistant/model-round.js +2 -2
  11. package/dist-lib/lib/assistant.d.ts +1 -0
  12. package/dist-lib/lib/assistant.js +16 -7
  13. package/dist-lib/lib/core/agent-copies.js +7 -1
  14. package/dist-lib/lib/core/agent.js +1 -0
  15. package/dist-lib/lib/core/approval-rules.d.ts +5 -1
  16. package/dist-lib/lib/core/approval-rules.js +16 -1
  17. package/dist-lib/lib/core/chunk.js +4 -3
  18. package/dist-lib/lib/core/config-value.d.ts +1 -0
  19. package/dist-lib/lib/core/config-value.js +1 -0
  20. package/dist-lib/lib/core/contract/workspace.js +2 -2
  21. package/dist-lib/lib/core/deleted-agent-runs.d.ts +7 -0
  22. package/dist-lib/lib/core/deleted-agent-runs.js +46 -0
  23. package/dist-lib/lib/core/files/index.d.ts +1 -1
  24. package/dist-lib/lib/core/files/index.js +4 -2
  25. package/dist-lib/lib/core/local/index.d.ts +6 -0
  26. package/dist-lib/lib/core/local/index.js +14 -0
  27. package/dist-lib/lib/core/mesh.d.ts +1 -1
  28. package/dist-lib/lib/core/mesh.js +3 -1
  29. package/dist-lib/lib/core/skill-secrets.d.ts +3 -2
  30. package/dist-lib/lib/core/skill-secrets.js +4 -1
  31. package/dist-lib/lib/core/sync/index.js +13 -1
  32. package/dist-lib/lib/core/vault-managed-skills.d.ts +18 -0
  33. package/dist-lib/lib/core/vault-managed-skills.js +105 -0
  34. package/dist-lib/lib/core.d.ts +8 -1
  35. package/dist-lib/lib/core.js +63 -6
  36. package/dist-lib/lib/errors.d.ts +8 -0
  37. package/dist-lib/lib/errors.js +8 -0
  38. package/dist-lib/lib/mesh-scoped-engine.js +1 -0
  39. package/dist-lib/schema/config.d.ts +1 -1
  40. package/dist-lib/schema/config.js +1 -1
  41. package/dist-lib/schema/engine.js +33 -1
  42. package/dist-lib/schema/qvac.js +4 -2
  43. package/dist-lib/spec/bind.js +12 -0
  44. package/dist-lib/spec/calls.js +4 -0
  45. package/dist-lib/spec/capabilities.d.ts +8 -0
  46. package/dist-lib/spec/config/hyperconf/index.js +1 -1
  47. package/dist-lib/spec/hrpc/hrpc.json +52 -0
  48. package/dist-lib/spec/hrpc/index.js +51 -3
  49. package/dist-lib/spec/hrpc/messages.js +1013 -954
  50. package/dist-lib/spec/hyperschema/index.js +1013 -954
  51. package/dist-lib/spec/hyperschema/schema.json +40 -0
  52. package/dist-lib/spec/hyperschema/types.d.ts +12 -0
  53. package/dist-lib/spec/mesh/hyperdb/messages.js +539 -501
  54. package/dist-lib/spec/mesh/hyperdispatch/messages.js +319 -300
  55. package/dist-lib/spec/mesh/hyperschema/index.js +319 -300
  56. package/dist-lib/spec/mesh/hyperschema/schema.json +188 -178
  57. package/dist-lib/spec/mesh/hyperschema/types.d.ts +3 -1
  58. package/package.json +12 -12
@@ -0,0 +1,46 @@
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 chats = new Set();
13
+ for (const { chatId, runId, runRequest } of requests) {
14
+ const asked = runId && deleted.has(runRequest?.agentId ?? '');
15
+ if (asked && !(await runHasTerminalStatus(mesh.view, chatId, runId))) {
16
+ chats.add(chatId);
17
+ }
18
+ }
19
+ for (const chatId of chats) {
20
+ if (mesh.closing || !mesh.writable)
21
+ return;
22
+ const chat = await mesh.view.get(CHATS, { id: chatId });
23
+ if (chat && !chat.deletedAt && deleted.has(chat.agentId)) {
24
+ await cancelActiveRuns(mesh, chatId, {
25
+ deviceId,
26
+ agentId: chat.agentId,
27
+ reason: AGENT_DELETED
28
+ });
29
+ }
30
+ }
31
+ }
32
+ async function deletedOf(mesh, { requests, deletedAgents }) {
33
+ const deleted = new Set(deletedAgents);
34
+ const asked = new Set(requests.map((r) => r.runRequest?.agentId).filter((id) => !!id));
35
+ for (const id of asked) {
36
+ const agent = await mesh.view.get(AGENTS, { id });
37
+ if (agent?.deletedAt) {
38
+ deleted.add(id);
39
+ }
40
+ }
41
+ return deleted;
42
+ }
43
+ async function allDeleted(mesh) {
44
+ const agents = await mesh.view.find(AGENTS).toArray();
45
+ return new Set(agents.filter((agent) => agent.deletedAt).map((agent) => agent.id));
46
+ }
@@ -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
- await this._until(chatId, (files) => files.some((file) => this.indexesHere(file)) ? null : files);
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');
@@ -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();
@@ -219,7 +219,7 @@ export declare class Mesh extends ReadyResource {
219
219
  private _seedDefaults;
220
220
  get interrupted(): unknown;
221
221
  throwIfInterrupted(): void;
222
- waitForWritable(): Promise<void>;
222
+ waitForWritable(timeout?: number): Promise<void>;
223
223
  pendingUploads(): number;
224
224
  suspend(): Promise<void>;
225
225
  resume(): void;
@@ -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
  });
@@ -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 onstored: () => Promise<unknown>;
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));
@@ -1,4 +1,4 @@
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';
@@ -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
  }
@@ -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
  }
@@ -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
+ }
@@ -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;
@@ -618,6 +622,9 @@ export declare class Core extends ReadyResource {
618
622
  previewMeshInvite(invite: string): MeshInvitePreview;
619
623
  private _closeSwarm;
620
624
  pushSkillSecret(request: SkillSecretRequest): Promise<void>;
625
+ private _offerQuarantined;
626
+ private _discardQuarantined;
627
+ private _releaseQuarantined;
621
628
  private _followSkillSecrets;
622
629
  private _followJoinedMeshes;
623
630
  private _followJoinedMeshesPass;
@@ -32,6 +32,7 @@ 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
37
  import { followPickedAgents, followSharedAgents, liveSharedAgent, pickAgent, shareAgent, unpickAgent } from './core/shared-agents.js';
37
38
  import { inRole, publicRoute } from './core/contract/roles.js';
@@ -60,6 +61,7 @@ import { countContents, migrateContents, withArchivedMesh } from './core/archive
60
61
  import { isMobilePlatform } from '@qvac/harness/lib/models/model-catalog.ts';
61
62
  import { storeSkillSecret, syncSkillSecrets } from './core/skill-secrets.js';
62
63
  import { SKILL_SECRET_PREFIX } from './core/contract/skill-secrets.js';
64
+ import { discardQuarantinedSkills, prepareVaultManagedSkills, quarantinedSkillKeys, releaseQuarantinedSkills, validateVaultManagedSkill } from './core/vault-managed-skills.js';
63
65
  import { attestDeviceProof, attestMemberClaim, chainTo, claimAttestation, delegationFits, openIdentity, pairingAnchorSeed } from './core/identity.js';
64
66
  import { openRecoveryCore, publishRecovery, readRecovery, recoveryKeys } from './core/account-recovery.js';
65
67
  import { claimOwnMembership, legacyNameStamp, namedAt, renameFoundedMember } from './core/membership.js';
@@ -90,6 +92,7 @@ const QVAC_CORE_NAMESPACE = 'qvac-core';
90
92
  const MESH_ID = /^[0-9a-f]{64}$/;
91
93
  export const DEVICE_UNKNOWN = 'This device has no device details: pass `device` when creating Core';
92
94
  const RECOVERY_WAIT_MS = 30_000;
95
+ const WINNER_ADMISSION_WAIT_MS = 60_000;
93
96
  const TOPIC_RETRY_MS = [1_000, 5_000, 15_000];
94
97
  const MESH_DIED = 'the local database died';
95
98
  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 +226,8 @@ export class Core extends ReadyResource {
223
226
  _projectKeySeals = new ScopeLock({ debounce: true });
224
227
  _hosting = new ScopeLock({ debounce: true });
225
228
  _skillSecrets = new ScopeLock({ debounce: true });
229
+ _vaultManagedSkills;
230
+ _quarantine = Promise.resolve([]);
226
231
  _hostMeshes = new Set();
227
232
  _hostJoins = new WeakMap();
228
233
  _agentListeners = new Set();
@@ -253,7 +258,7 @@ export class Core extends ReadyResource {
253
258
  _systemInfo;
254
259
  _statusError;
255
260
  _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 }) {
261
+ 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
262
  super();
258
263
  this._transport = transport;
259
264
  this._apiLifecycle = apiLifecycle ?? {
@@ -315,6 +320,7 @@ export class Core extends ReadyResource {
315
320
  this._ragExtractors = extractors;
316
321
  this._skills = skills ?? null;
317
322
  this._skillCatalog = skillCatalog ?? null;
323
+ this._vaultManagedSkills = skillSecrets;
318
324
  this._skillManagement = null;
319
325
  this._tools = tools ?? null;
320
326
  this._hostsModelSource = hostsModelSource;
@@ -392,6 +398,10 @@ export class Core extends ReadyResource {
392
398
  return [...new Set(ids)].sort();
393
399
  }
394
400
  async _open() {
401
+ const { length: quarantined } = await this._offerQuarantined();
402
+ if (quarantined) {
403
+ this._log?.warn('lifecycle', 'skill values wait for the vault', { quarantined });
404
+ }
395
405
  this._log?.info('lifecycle', 'core opening', {
396
406
  app: this._app?.version ?? null,
397
407
  build: this._app?.build ?? null,
@@ -517,11 +527,18 @@ export class Core extends ReadyResource {
517
527
  return workspaceId === this._ownWorkspaceId ? null : workspaceId;
518
528
  },
519
529
  pushSkillSecret: (request) => this.pushSkillSecret(request),
520
- onConfigSet: (key) => {
521
- if (key.startsWith(SKILL_SECRET_PREFIX)) {
530
+ beforeConfigSet: (entry) => validateVaultManagedSkill(this._vaultManagedSkills, entry),
531
+ onConfigSet: async (entry) => {
532
+ if (entry.key.startsWith(SKILL_SECRET_PREFIX)) {
522
533
  void this._followSkillSecrets();
534
+ await this._releaseQuarantined([entry]);
523
535
  }
524
536
  },
537
+ listQuarantinedSkills: async () => ({ keys: await quarantinedSkillKeys(this.local) }),
538
+ retryQuarantinedSkills: async () => ({ keys: await this._offerQuarantined() }),
539
+ discardQuarantinedSkills: async ({ keys }) => ({
540
+ keys: await this._discardQuarantined(keys)
541
+ }),
525
542
  storageRoot: path.dirname(this._storagePath),
526
543
  listModels: this._hostsModelSource || this._listModels
527
544
  ? async (request) => (await this._readModelList(request)) ?? { models: [] }
@@ -2976,8 +2993,8 @@ export class Core extends ReadyResource {
2976
2993
  await this._following.get(projectId);
2977
2994
  }
2978
2995
  const winner = this._pooled(projectId) ?? (await this._heldMesh(row.id));
2979
- await winner?.waitForWritable();
2980
- return winner;
2996
+ await winner?.waitForWritable(WINNER_ADMISSION_WAIT_MS);
2997
+ return winner?.writable ? winner : null;
2981
2998
  }
2982
2999
  async _copyGroup(workspace, project, { chats }) {
2983
3000
  const deviceId = this._requireDeviceKeyPair().publicKey;
@@ -4689,6 +4706,25 @@ export class Core extends ReadyResource {
4689
4706
  };
4690
4707
  mesh.on('chat-purged', () => void reclaim());
4691
4708
  mesh.on('landed', () => void reclaim());
4709
+ let canceling = Promise.resolve();
4710
+ const cancelRuns = (landed) => {
4711
+ canceling = canceling
4712
+ .then(async () => {
4713
+ if (mesh.writable) {
4714
+ await cancelDeletedAgentRuns(mesh, deviceId, landed);
4715
+ }
4716
+ })
4717
+ .catch((error) => {
4718
+ if (!mesh.closing) {
4719
+ this._log?.warn(['p2p', 'mesh'], "canceling a deleted agent's runs failed", error);
4720
+ }
4721
+ });
4722
+ };
4723
+ const cancelAll = () => cancelRuns(null);
4724
+ mesh.on('runs-landed', cancelRuns);
4725
+ mesh.on('landed', cancelAll);
4726
+ mesh.autobee.on('writable', cancelAll);
4727
+ cancelAll();
4692
4728
  const sweepLock = new ScopeLock({ debounce: true });
4693
4729
  const sweep = async () => {
4694
4730
  if (!(await sweepLock.lock()))
@@ -5926,12 +5962,33 @@ export class Core extends ReadyResource {
5926
5962
  await this.ready();
5927
5963
  await storeSkillSecret({
5928
5964
  local: this.local,
5965
+ validate: (entry) => validateVaultManagedSkill(this._vaultManagedSkills, entry),
5929
5966
  setupFields: (skillName) => this._setupFields(skillName),
5930
- onstored: () => this._skillCatalog?.(null, null, { refresh: true }) ?? Promise.resolve()
5967
+ onstored: async (entries) => {
5968
+ await this._releaseQuarantined(entries);
5969
+ await this._skillCatalog?.(null, null, { refresh: true });
5970
+ }
5931
5971
  }, request);
5932
5972
  await this._followSkillSecrets();
5933
5973
  }
5974
+ _offerQuarantined() {
5975
+ const offer = () => prepareVaultManagedSkills(this._vaultManagedSkills, this.local, this._log);
5976
+ this._quarantine = this._quarantine.then(offer, offer);
5977
+ return this._quarantine;
5978
+ }
5979
+ _discardQuarantined(keys) {
5980
+ const discard = () => discardQuarantinedSkills(this.local, keys);
5981
+ this._quarantine = this._quarantine.then(discard, discard);
5982
+ return this._quarantine;
5983
+ }
5984
+ async _releaseQuarantined(entries) {
5985
+ if (this._vaultManagedSkills) {
5986
+ await releaseQuarantinedSkills(this.local, entries);
5987
+ }
5988
+ }
5934
5989
  async _followSkillSecrets() {
5990
+ if (this._vaultManagedSkills)
5991
+ return;
5935
5992
  if (!(await this._skillSecrets.lock()))
5936
5993
  return;
5937
5994
  try {
@@ -383,6 +383,10 @@ declare const DEFINITIONS: {
383
383
  readonly code: 100625;
384
384
  readonly message: () => string;
385
385
  };
386
+ readonly SKILL_SECRET_NOT_VAULT_SAFE: {
387
+ readonly code: 100626;
388
+ readonly message: () => string;
389
+ };
386
390
  readonly CHAT_NOT_FOUND: {
387
391
  readonly code: 100701;
388
392
  readonly message: (chatId: string) => string;
@@ -499,6 +503,10 @@ declare const DEFINITIONS: {
499
503
  readonly code: 100730;
500
504
  readonly message: (chunkId: string) => string;
501
505
  };
506
+ readonly APPROVAL_RULE_NOT_FOUND: {
507
+ readonly code: 100731;
508
+ readonly message: (ruleId: string) => string;
509
+ };
502
510
  readonly CHAT_MOVE_NOT_FOUND: {
503
511
  readonly code: 100801;
504
512
  readonly message: () => string;
@@ -297,6 +297,10 @@ const DEFINITIONS = {
297
297
  code: 100625,
298
298
  message: () => "This chat's agent is no longer shared with you: pick another agent"
299
299
  },
300
+ SKILL_SECRET_NOT_VAULT_SAFE: {
301
+ code: 100626,
302
+ message: () => 'Vault-managed skill state requires vault migration or reconnect'
303
+ },
300
304
  CHAT_NOT_FOUND: {
301
305
  code: 100701,
302
306
  message: (chatId) => `chat not found: ${chatId}`
@@ -413,6 +417,10 @@ const DEFINITIONS = {
413
417
  code: 100730,
414
418
  message: (chunkId) => `run-request ${chunkId} is not open to take`
415
419
  },
420
+ APPROVAL_RULE_NOT_FOUND: {
421
+ code: 100731,
422
+ message: (ruleId) => `no approval rule of yours: ${ruleId}`
423
+ },
416
424
  CHAT_MOVE_NOT_FOUND: {
417
425
  code: 100801,
418
426
  message: () => 'no move of this chat is recorded on this device'
@@ -95,6 +95,7 @@ export const MESH_SCOPED = new Set([
95
95
  'membersWatch',
96
96
  'removeMember',
97
97
  'listApprovalRules',
98
+ 'removeApprovalRule',
98
99
  'ragSearch',
99
100
  'runAgent',
100
101
  'sendMessage',
@@ -1,3 +1,3 @@
1
1
  import type { Registry } from './content.ts';
2
2
  export declare function registerConfigTypes(ns: Registry): void;
3
- export declare const VENDORED_MIN_SUPPORTED_VERSION = ">=0.21.0";
3
+ export declare const VENDORED_MIN_SUPPORTED_VERSION = ">=0.22.0";
@@ -4,4 +4,4 @@ export function registerConfigTypes(ns) {
4
4
  fields: [{ name: 'minSupportedVersion', type: 'string', required: true }]
5
5
  });
6
6
  }
7
- export const VENDORED_MIN_SUPPORTED_VERSION = '>=0.21.0';
7
+ export const VENDORED_MIN_SUPPORTED_VERSION = '>=0.22.0';