@qvac/core 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +67 -1
  2. package/dist-lib/lib/api/chat.d.ts +1 -1
  3. package/dist-lib/lib/api/chat.js +9 -0
  4. package/dist-lib/lib/api/index.d.ts +2 -1
  5. package/dist-lib/lib/api/index.js +2 -1
  6. package/dist-lib/lib/api/network.d.ts +8 -1
  7. package/dist-lib/lib/api/network.js +6 -0
  8. package/dist-lib/lib/assistant/harness.d.ts +2 -0
  9. package/dist-lib/lib/assistant.js +5 -0
  10. package/dist-lib/lib/core/agent.d.ts +2 -0
  11. package/dist-lib/lib/core/agent.js +16 -5
  12. package/dist-lib/lib/core/blind-peers.d.ts +4 -0
  13. package/dist-lib/lib/core/blind-peers.js +1 -0
  14. package/dist-lib/lib/core/chat-copy.d.ts +4 -0
  15. package/dist-lib/lib/core/chat-copy.js +1 -1
  16. package/dist-lib/lib/core/chat-fork.d.ts +21 -0
  17. package/dist-lib/lib/core/chat-fork.js +245 -0
  18. package/dist-lib/lib/core/chat-move.js +1 -4
  19. package/dist-lib/lib/core/chat.d.ts +1 -0
  20. package/dist-lib/lib/core/chat.js +1 -1
  21. package/dist-lib/lib/core/departures.d.ts +5 -1
  22. package/dist-lib/lib/core/departures.js +15 -1
  23. package/dist-lib/lib/core/fs-drives.d.ts +8 -1
  24. package/dist-lib/lib/core/fs-drives.js +47 -15
  25. package/dist-lib/lib/core/harness-loan.d.ts +4 -20
  26. package/dist-lib/lib/core/harness-loan.js +7 -184
  27. package/dist-lib/lib/core/id.d.ts +1 -0
  28. package/dist-lib/lib/core/id.js +3 -0
  29. package/dist-lib/lib/core/mesh.d.ts +3 -2
  30. package/dist-lib/lib/core/mesh.js +11 -1
  31. package/dist-lib/lib/core/migrations/agent-tools-scope.d.ts +2 -0
  32. package/dist-lib/lib/core/migrations/agent-tools-scope.js +24 -0
  33. package/dist-lib/lib/core/migrations/index.js +3 -1
  34. package/dist-lib/lib/core/peer-duplex.d.ts +32 -0
  35. package/dist-lib/lib/core/peer-duplex.js +207 -0
  36. package/dist-lib/lib/core.d.ts +17 -1
  37. package/dist-lib/lib/core.js +183 -10
  38. package/dist-lib/lib/doctor/checks.js +4 -1
  39. package/dist-lib/lib/mesh-scoped-engine.js +3 -0
  40. package/dist-lib/lib/model-download.d.ts +0 -9
  41. package/dist-lib/lib/model-download.js +1 -13
  42. package/dist-lib/schema/engine.js +45 -1
  43. package/dist-lib/schema/field-order.js +1 -1
  44. package/dist-lib/schema/qvac.js +10 -1
  45. package/dist-lib/spec/bind.js +14 -0
  46. package/dist-lib/spec/calls.js +3 -0
  47. package/dist-lib/spec/capabilities.d.ts +6 -0
  48. package/dist-lib/spec/hrpc/hrpc.json +39 -0
  49. package/dist-lib/spec/hrpc/index.js +41 -4
  50. package/dist-lib/spec/hrpc/messages.js +1420 -1289
  51. package/dist-lib/spec/hyperschema/index.js +1420 -1289
  52. package/dist-lib/spec/hyperschema/schema.json +102 -0
  53. package/dist-lib/spec/hyperschema/types.d.ts +29 -0
  54. package/dist-lib/spec/mesh/hyperdb/messages.js +295 -248
  55. package/dist-lib/spec/mesh/hyperdispatch/messages.js +45 -5
  56. package/dist-lib/spec/mesh/hyperschema/index.js +45 -5
  57. package/dist-lib/spec/mesh/hyperschema/schema.json +31 -1
  58. package/dist-lib/spec/mesh/hyperschema/types.d.ts +9 -1
  59. package/package.json +9 -6
  60. package/tui/app.mjs +121 -67
  61. package/tui/lib/fork-command.mjs +43 -0
@@ -3,7 +3,7 @@ import type Hyperswarm from 'hyperswarm';
3
3
  import type Wakeup from 'protomux-wakeup';
4
4
  import type { Logger } from '../../index.ts';
5
5
  import type { LocalMeshDeparture } from '../../spec/local/hyperschema/types.d.ts';
6
- import type { BlindPeeringOpts } from './blind-peers.ts';
6
+ import type { BlindPeeringOpts, StartBlindPeeringOpts } from './blind-peers.ts';
7
7
  interface DepartureRows {
8
8
  departures(): Promise<LocalMeshDeparture[]>;
9
9
  deleteDeparture(key: Buffer): Promise<void>;
@@ -15,6 +15,7 @@ export interface PendingDeparturesOptions {
15
15
  logger?: Logger | null;
16
16
  blindPeerKeys?: ReadonlyArray<Buffer>;
17
17
  blindPeeringOpts?: BlindPeeringOpts;
18
+ blindPeering?: boolean;
18
19
  wakeup?: Wakeup;
19
20
  }
20
21
  export declare class PendingDepartures {
@@ -31,6 +32,7 @@ export declare class PendingDepartures {
31
32
  private readonly _parked;
32
33
  private readonly _lock;
33
34
  private _closing;
35
+ private _blindPeering;
34
36
  constructor(store: Corestore, local: DepartureRows, opts: PendingDeparturesOptions);
35
37
  flush(): void;
36
38
  private _flush;
@@ -39,6 +41,8 @@ export declare class PendingDepartures {
39
41
  park(key: Buffer): Promise<void>;
40
42
  unpark(key: Buffer): void;
41
43
  drop(key: Buffer): Promise<void>;
44
+ startBlindPeering(opts?: StartBlindPeeringOpts): void;
45
+ stopBlindPeering(): Promise<void>;
42
46
  suspend(): Promise<void>;
43
47
  resume(): Promise<void>;
44
48
  close(): Promise<void>;
@@ -16,6 +16,7 @@ export class PendingDepartures {
16
16
  _parked = new Set();
17
17
  _lock = new ScopeLock();
18
18
  _closing = false;
19
+ _blindPeering;
19
20
  constructor(store, local, opts) {
20
21
  this._store = store;
21
22
  this._local = local;
@@ -26,6 +27,7 @@ export class PendingDepartures {
26
27
  this._blindPeerKeys = opts.blindPeerKeys ?? [];
27
28
  this._blindPeeringOpts = opts.blindPeeringOpts;
28
29
  this._wakeup = opts.wakeup;
30
+ this._blindPeering = opts.blindPeering ?? true;
29
31
  }
30
32
  flush() {
31
33
  void this._flush().catch((err) => this._log?.warn(SCOPE, 'departure flush failed', err));
@@ -71,7 +73,9 @@ export class PendingDepartures {
71
73
  return;
72
74
  }
73
75
  this._swarm.join(mesh.discoveryKey, { server: true, client: true });
74
- mesh.startBlindPeering(this._swarm.dht);
76
+ if (this._blindPeering) {
77
+ mesh.startBlindPeering(this._swarm.dht);
78
+ }
75
79
  this._log?.info(scope, 'reopened a departed mesh to deliver its removal');
76
80
  const announced = await this._announce(mesh);
77
81
  if (announced === 'closed' || (announced === 'sent' && !(await waitForDelivery(mesh)))) {
@@ -124,6 +128,16 @@ export class PendingDepartures {
124
128
  drop(key) {
125
129
  return this._local.deleteDeparture(key);
126
130
  }
131
+ startBlindPeering(opts = {}) {
132
+ this._blindPeering = true;
133
+ for (const { mesh } of this._active.values()) {
134
+ mesh.startBlindPeering(this._swarm.dht, opts);
135
+ }
136
+ }
137
+ async stopBlindPeering() {
138
+ this._blindPeering = false;
139
+ await Promise.all([...this._active.values()].map(({ mesh }) => mesh.stopBlindPeering()));
140
+ }
127
141
  async suspend() {
128
142
  for (const { mesh } of this._active.values()) {
129
143
  await mesh.suspend();
@@ -10,9 +10,16 @@ export interface DriveHost {
10
10
  acquire(key: string): Promise<AcquiredDrive>;
11
11
  close(): Promise<void>;
12
12
  }
13
+ export interface PeeredDriveHost extends DriveHost {
14
+ startBlindPeering(): Promise<void>;
15
+ stopBlindPeering(): Promise<void>;
16
+ suspend(): Promise<void>;
17
+ resume(): Promise<void>;
18
+ }
13
19
  export interface DriveHostOptions {
14
20
  readonly swarm: Hyperswarm;
15
21
  readonly blindPeerKeys: ReadonlyArray<Buffer>;
16
22
  readonly blindPeeringOpts?: BlindPeeringOpts;
23
+ readonly blindPeering?: boolean;
17
24
  }
18
- export declare function createFsDriveHost(store: Corestore, opts: DriveHostOptions): DriveHost;
25
+ export declare function createFsDriveHost(store: Corestore, opts: DriveHostOptions): PeeredDriveHost;
@@ -25,11 +25,23 @@ async function openDrive(store, swarm, key) {
25
25
  }
26
26
  export function createFsDriveHost(store, opts) {
27
27
  const namespaced = store.namespace(NAMESPACE);
28
- const peering = new BlindPeering(opts.swarm.dht, namespaced, {
29
- pick: 2,
30
- ...opts.blindPeeringOpts
31
- });
32
28
  const drives = new Map();
29
+ let suspended = false;
30
+ let peering = opts.blindPeering === false ? null : startPeering();
31
+ function startPeering() {
32
+ return new BlindPeering(opts.swarm.dht, namespaced, {
33
+ pick: 2,
34
+ suspended,
35
+ ...opts.blindPeeringOpts
36
+ });
37
+ }
38
+ async function peer(held) {
39
+ const blobs = await held.drive.getBlobs();
40
+ peering?.addCoreBackground(held.drive.core, { keys: opts.blindPeerKeys });
41
+ if (blobs) {
42
+ peering?.addCoreBackground(blobs.core, { keys: opts.blindPeerKeys });
43
+ }
44
+ }
33
45
  async function acquire(key) {
34
46
  const cached = drives.get(key);
35
47
  if (cached) {
@@ -37,27 +49,47 @@ export function createFsDriveHost(store, opts) {
37
49
  }
38
50
  const opening = withDeadline((async () => {
39
51
  const held = await openDrive(namespaced, opts.swarm, key);
40
- const blobs = await held.drive.getBlobs();
41
- peering.addCoreBackground(held.drive.core, { keys: opts.blindPeerKeys });
42
- if (blobs) {
43
- peering.addCoreBackground(blobs.core, { keys: opts.blindPeerKeys });
44
- }
52
+ await peer(held);
45
53
  return held;
46
54
  })(), DRIVE_OPEN_TIMEOUT_MS);
47
55
  drives.set(key, opening);
48
56
  opening.catch(() => drives.delete(key));
49
57
  return opening;
50
58
  }
51
- async function close() {
59
+ async function opened() {
52
60
  const settled = await Promise.allSettled(drives.values());
53
- drives.clear();
54
- await Promise.all(settled
61
+ return settled
55
62
  .filter((result) => result.status === 'fulfilled')
56
- .map(async ({ value: { drive, topic } }) => {
63
+ .map(({ value }) => value);
64
+ }
65
+ async function startBlindPeering() {
66
+ if (peering) {
67
+ return;
68
+ }
69
+ peering = startPeering();
70
+ await Promise.all((await opened()).map(peer));
71
+ }
72
+ async function stopBlindPeering() {
73
+ const closing = peering;
74
+ peering = null;
75
+ await closing?.close();
76
+ }
77
+ async function suspend() {
78
+ suspended = true;
79
+ await peering?.suspend();
80
+ }
81
+ async function resume() {
82
+ suspended = false;
83
+ await peering?.resume();
84
+ }
85
+ async function close() {
86
+ const held = await opened();
87
+ drives.clear();
88
+ await Promise.all(held.map(async ({ drive, topic }) => {
57
89
  await topic.destroy();
58
90
  await drive.close();
59
91
  }));
60
- await peering.close();
92
+ await peering?.close();
61
93
  }
62
- return { acquire, close };
94
+ return { acquire, startBlindPeering, stopBlindPeering, suspend, resume, close };
63
95
  }
@@ -1,30 +1,14 @@
1
- import { Duplex } from 'streamx';
1
+ import type { Duplex } from 'streamx';
2
+ import { PeerDuplexChannel, type PeerStream } from './peer-duplex.ts';
2
3
  export declare const LOAN_UNREACHABLE = "the device lending its model is not connected";
3
4
  export declare const LOAN_REFUSED = "the device would not lend its model";
4
5
  export declare const LOAN_REVOKED = "the device stopped lending its model";
5
6
  export declare function loanFailureNotice(error: unknown): string | null;
6
- export interface LoanStream {
7
- readonly remotePublicKey: Uint8Array;
8
- readonly noiseStream: {
9
- userData: unknown;
10
- };
11
- }
7
+ export type LoanStream = PeerStream;
12
8
  export interface HarnessLoanOptions {
13
9
  readonly onborrow: (fromDeviceId: Uint8Array) => Promise<Duplex | null>;
14
10
  }
15
- export declare class HarnessLoan {
16
- private readonly _opts;
17
- private readonly _peers;
18
- private _nextId;
19
- private readonly _pairing;
11
+ export declare class HarnessLoan extends PeerDuplexChannel {
20
12
  constructor(opts: HarnessLoanOptions);
21
- addStream(stream: LoanStream): void;
22
13
  borrow(deviceId: string): Duplex;
23
- revalidate(allowed: (deviceId: Uint8Array) => Promise<boolean>): Promise<void>;
24
- destroy(): void;
25
- private _attach;
26
- private _serve;
27
- private _deliver;
28
- private _end;
29
- private _drop;
30
14
  }
@@ -1,9 +1,5 @@
1
- import b4a from 'b4a';
2
- import { raw, uint } from 'compact-encoding';
3
- import { Duplex } from 'streamx';
4
- import { createProtocolPairing } from './protocol-pairing.js';
1
+ import { PeerDuplexChannel } from './peer-duplex.js';
5
2
  const PROTOCOL = 'qvac/harness-loan';
6
- function noop() { }
7
3
  export const LOAN_UNREACHABLE = 'the device lending its model is not connected';
8
4
  export const LOAN_REFUSED = 'the device would not lend its model';
9
5
  export const LOAN_REVOKED = 'the device stopped lending its model';
@@ -22,189 +18,16 @@ function messageOf(error) {
22
18
  return error.message;
23
19
  return typeof error === 'string' ? error : '';
24
20
  }
25
- const bytes = raw;
26
- const frame = {
27
- preencode(state, f) {
28
- uint.preencode(state, f.id);
29
- uint.preencode(state, f.mine ? 1 : 0);
30
- bytes.preencode(state, f.data);
31
- },
32
- encode(state, f) {
33
- uint.encode(state, f.id);
34
- uint.encode(state, f.mine ? 1 : 0);
35
- bytes.encode(state, f.data);
36
- },
37
- decode(state) {
38
- const id = uint.decode(state);
39
- const mine = uint.decode(state) === 1;
40
- return { id, mine, data: bytes.decode(state) };
41
- }
42
- };
43
- const ends = {
44
- preencode(state, e) {
45
- uint.preencode(state, e.id);
46
- uint.preencode(state, e.mine ? 1 : 0);
47
- },
48
- encode(state, e) {
49
- uint.encode(state, e.id);
50
- uint.encode(state, e.mine ? 1 : 0);
51
- },
52
- decode(state) {
53
- return { id: uint.decode(state), mine: uint.decode(state) === 1 };
54
- }
55
- };
56
- export class HarnessLoan {
57
- _opts;
58
- _peers;
59
- _nextId;
60
- _pairing;
21
+ export class HarnessLoan extends PeerDuplexChannel {
61
22
  constructor(opts) {
62
- this._opts = opts;
63
- this._peers = new Map();
64
- this._nextId = 1;
65
- this._pairing = createProtocolPairing(PROTOCOL);
66
- }
67
- addStream(stream) {
68
- const deviceId = b4a.toHex(stream.remotePublicKey);
69
- if (this._peers.has(deviceId)) {
70
- return;
71
- }
72
- const channel = this._pairing
73
- .mux(stream, () => this.addStream(stream))
74
- .createChannel({
23
+ super({
75
24
  protocol: PROTOCOL,
76
- onclose: () => this._drop(deviceId)
77
- });
78
- if (!channel) {
79
- return;
80
- }
81
- const open = channel.addMessage({
82
- encoding: uint,
83
- onmessage: (id) => void this._serve(deviceId, id)
25
+ onaccept: opts.onborrow,
26
+ unreachable: LOAN_UNREACHABLE,
27
+ revoked: LOAN_REVOKED
84
28
  });
85
- const data = channel.addMessage({
86
- encoding: frame,
87
- onmessage: (f) => this._deliver(deviceId, f)
88
- });
89
- const close = channel.addMessage({
90
- encoding: ends,
91
- onmessage: (e) => this._end(deviceId, e)
92
- });
93
- this._peers.set(deviceId, {
94
- channel,
95
- remoteKey: stream.remotePublicKey,
96
- open,
97
- data,
98
- close,
99
- borrowed: new Map(),
100
- served: new Map()
101
- });
102
- channel.open();
103
29
  }
104
30
  borrow(deviceId) {
105
- const peer = this._peers.get(deviceId);
106
- if (!peer) {
107
- throw new Error(LOAN_UNREACHABLE);
108
- }
109
- const id = this._nextId;
110
- this._nextId += 1;
111
- const stream = this._attach(peer, id, { mine: true });
112
- peer.open.send(id);
113
- return stream;
114
- }
115
- async revalidate(allowed) {
116
- for (const peer of [...this._peers.values()]) {
117
- if (peer.served.size === 0)
118
- continue;
119
- if (await allowed(peer.remoteKey).catch(() => false))
120
- continue;
121
- for (const [id, stream] of [...peer.served]) {
122
- peer.served.delete(id);
123
- peer.close.send({ id, mine: false });
124
- stream.destroy(new Error(LOAN_REVOKED));
125
- }
126
- }
127
- }
128
- destroy() {
129
- this._pairing.destroy();
130
- for (const [deviceId, peer] of [...this._peers]) {
131
- try {
132
- peer.channel.close();
133
- }
134
- catch { }
135
- this._drop(deviceId);
136
- }
137
- }
138
- _attach(peer, id, opts) {
139
- const { mine } = opts;
140
- const held = mine ? peer.borrowed : peer.served;
141
- const stream = new Duplex({
142
- write: (chunk, cb) => {
143
- peer.data.send({ id, mine, data: chunk });
144
- cb(null);
145
- },
146
- final: (cb) => {
147
- peer.close.send({ id, mine });
148
- cb(null);
149
- },
150
- destroy: (cb) => {
151
- if (held.delete(id)) {
152
- peer.close.send({ id, mine });
153
- }
154
- cb(null);
155
- }
156
- });
157
- held.set(id, stream);
158
- return stream;
159
- }
160
- async _serve(deviceId, id) {
161
- const peer = this._peers.get(deviceId);
162
- if (!peer || peer.served.has(id)) {
163
- return;
164
- }
165
- const stream = this._attach(peer, id, { mine: false });
166
- const served = await this._opts.onborrow(peer.remoteKey).catch(noop);
167
- if (!served) {
168
- stream.destroy();
169
- return;
170
- }
171
- stream.on('error', noop);
172
- served.on('error', noop);
173
- stream.pipe(served).pipe(stream);
174
- }
175
- _deliver(deviceId, f) {
176
- const peer = this._peers.get(deviceId);
177
- if (!peer) {
178
- return;
179
- }
180
- const held = f.mine ? peer.served : peer.borrowed;
181
- held.get(f.id)?.push(f.data);
182
- }
183
- _end(deviceId, e) {
184
- const peer = this._peers.get(deviceId);
185
- if (!peer) {
186
- return;
187
- }
188
- const held = e.mine ? peer.served : peer.borrowed;
189
- const stream = held.get(e.id);
190
- if (!stream) {
191
- return;
192
- }
193
- held.delete(e.id);
194
- stream.push(null);
195
- stream.destroy();
196
- }
197
- _drop(deviceId) {
198
- const peer = this._peers.get(deviceId);
199
- if (!peer) {
200
- return;
201
- }
202
- this._peers.delete(deviceId);
203
- for (const held of [peer.borrowed, peer.served]) {
204
- for (const stream of held.values()) {
205
- stream.destroy(new Error(LOAN_UNREACHABLE));
206
- }
207
- held.clear();
208
- }
31
+ return this.dial(deviceId);
209
32
  }
210
33
  }
@@ -1 +1,2 @@
1
1
  export declare function randomId(): string;
2
+ export declare function derivedId(...parts: string[]): string;
@@ -3,3 +3,6 @@ import crypto from 'hypercore-crypto';
3
3
  export function randomId() {
4
4
  return b4a.toHex(crypto.randomBytes(16));
5
5
  }
6
+ export function derivedId(...parts) {
7
+ return b4a.toHex(crypto.hash(parts.map((part) => b4a.from(part))).subarray(0, 16));
8
+ }
@@ -9,7 +9,7 @@ import { Files } from './files/index.ts';
9
9
  import type { Logger } from '../../index.ts';
10
10
  import { Router } from '../../spec/mesh/hyperdispatch/index.js';
11
11
  import type { QvacCapabilityProfile, QvacDevice, QvacMember, QvacMeshName } from '../../spec/mesh/hyperschema/types.d.ts';
12
- import type { BlindPeeringOpts } from './blind-peers.ts';
12
+ import type { BlindPeeringOpts, StartBlindPeeringOpts } from './blind-peers.ts';
13
13
  import type { AttachmentUrl } from './attachment-link.ts';
14
14
  import type { MeshFileIndex } from './files/local-index.ts';
15
15
  import { type DeviceAttestation } from './device-attestation.ts';
@@ -139,7 +139,8 @@ export declare class Mesh extends ReadyResource {
139
139
  attestDevice(deviceId: Buffer): DeviceAttestation;
140
140
  constructor(store: Corestore, opts?: MeshOptions);
141
141
  _open(): Promise<void>;
142
- startBlindPeering(dht: unknown): void;
142
+ startBlindPeering(dht: unknown, { suspended }?: StartBlindPeeringOpts): void;
143
+ stopBlindPeering(): Promise<void>;
143
144
  openBlobs(coreKey: Buffer): Promise<Hyperblobs>;
144
145
  interruptBoot(): void;
145
146
  _close(): Promise<void>;
@@ -292,12 +292,13 @@ export class Mesh extends ReadyResource {
292
292
  void this._sweepOrphanedBlobs(this.blobs.core.length);
293
293
  this.files.start({ deviceId: this._deviceId });
294
294
  }
295
- startBlindPeering(dht) {
295
+ startBlindPeering(dht, { suspended = false } = {}) {
296
296
  if (this.closing || this._blindPeering || !this._autobee || !this._blobs) {
297
297
  return;
298
298
  }
299
299
  this._blindPeering = new BlindPeering(dht, this._store, {
300
300
  pick: 2,
301
+ suspended,
301
302
  wakeup: this._wakeup,
302
303
  ...this._blindPeeringOpts
303
304
  });
@@ -311,6 +312,15 @@ export class Mesh extends ReadyResource {
311
312
  });
312
313
  this._log?.info(this._scope, 'blind peering started');
313
314
  }
315
+ async stopBlindPeering() {
316
+ const peering = this._blindPeering;
317
+ if (!peering) {
318
+ return;
319
+ }
320
+ this._blindPeering = null;
321
+ await peering.close();
322
+ this._log?.info(this._scope, 'blind peering stopped');
323
+ }
314
324
  async openBlobs(coreKey) {
315
325
  const core = this._store.get({ key: coreKey, encryptionKey: this._encryptionKey });
316
326
  const blobs = new Hyperblobs(core);
@@ -0,0 +1,2 @@
1
+ import type { Mesh } from '../mesh.ts';
2
+ export declare function migrateAgentToolsScope(mesh: Mesh): Promise<boolean>;
@@ -0,0 +1,24 @@
1
+ import { allTools } from '../agent.js';
2
+ import { AGENTS } from '../collections.js';
3
+ export async function migrateAgentToolsScope(mesh) {
4
+ const scoped = await selectedScopeAgents(mesh);
5
+ for (const agent of scoped) {
6
+ await mesh.dispatch('put-agent', { agent: { ...agent, ...allTools() } });
7
+ }
8
+ return scoped.length > 0;
9
+ }
10
+ async function selectedScopeAgents(mesh) {
11
+ const snap = mesh.view.snapshot();
12
+ try {
13
+ const scoped = [];
14
+ for await (const agent of snap.find(AGENTS)) {
15
+ if (!agent.deletedAt && agent.toolsScope === 'selected') {
16
+ scoped.push(agent);
17
+ }
18
+ }
19
+ return scoped;
20
+ }
21
+ finally {
22
+ await snap.close();
23
+ }
24
+ }
@@ -1,4 +1,5 @@
1
1
  import { migrateAgentCatalog } from './agent-catalog.js';
2
+ import { migrateAgentToolsScope } from './agent-tools-scope.js';
2
3
  import { migrateMembership } from './membership.js';
3
4
  import { sealDeviceRows } from './seal.js';
4
5
  import { reindexAgents } from './agent-indexes.js';
@@ -9,5 +10,6 @@ export async function runMigrations(mesh, context, { catalog = true } = {}) {
9
10
  const agents = catalog && (await migrateAgentCatalog(mesh, context));
10
11
  const seal = await sealDeviceRows(mesh, context);
11
12
  const indexed = await reindexAgents(mesh);
12
- return devices || membership || agents || seal || indexed;
13
+ const tools = await migrateAgentToolsScope(mesh);
14
+ return devices || membership || agents || seal || indexed || tools;
13
15
  }
@@ -0,0 +1,32 @@
1
+ import { Duplex } from 'streamx';
2
+ export interface PeerStream {
3
+ readonly remotePublicKey: Uint8Array;
4
+ readonly noiseStream: {
5
+ userData: unknown;
6
+ };
7
+ }
8
+ export interface PeerDuplexOptions {
9
+ readonly protocol: string;
10
+ readonly onaccept: (fromDeviceId: Uint8Array) => Promise<Duplex | null>;
11
+ readonly unreachable: string;
12
+ readonly revoked: string;
13
+ readonly onchange?: (deviceId: string) => void;
14
+ }
15
+ export declare class PeerDuplexChannel {
16
+ private readonly _opts;
17
+ private readonly _peers;
18
+ private _nextId;
19
+ private readonly _pairing;
20
+ constructor(opts: PeerDuplexOptions);
21
+ addStream(stream: PeerStream): void;
22
+ isOpen(deviceId: string): boolean;
23
+ dial(deviceId: string): Duplex;
24
+ revalidate(allowed: (deviceId: Uint8Array) => Promise<boolean>): Promise<void>;
25
+ destroy(): void;
26
+ private _opened;
27
+ private _attach;
28
+ private _serve;
29
+ private _deliver;
30
+ private _end;
31
+ private _drop;
32
+ }