@qvac/core 0.6.5 → 0.6.7
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 +50 -1
- package/dist-lib/lib/assistant.d.ts +1 -0
- package/dist-lib/lib/assistant.js +9 -3
- package/dist-lib/lib/core/fs-drives.js +9 -6
- package/dist-lib/lib/core/handoff-channel.d.ts +1 -0
- package/dist-lib/lib/core/handoff-channel.js +7 -2
- package/dist-lib/lib/core/harness-loan.d.ts +1 -0
- package/dist-lib/lib/core/harness-loan.js +7 -2
- package/dist-lib/lib/core/protocol-pairing.d.ts +11 -0
- package/dist-lib/lib/core/protocol-pairing.js +22 -0
- package/dist-lib/lib/core.d.ts +14 -1
- package/dist-lib/lib/core.js +111 -42
- package/dist-lib/schema/config.d.ts +1 -1
- package/dist-lib/schema/config.js +1 -1
- package/dist-lib/spec/config/hyperconf/index.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -13,6 +13,53 @@ release.
|
|
|
13
13
|
|
|
14
14
|
## [Unreleased]
|
|
15
15
|
|
|
16
|
+
## [0.6.7] - 2026-10-06
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- `Core` accepts `store`, `swarm` and `wakeup`, so a host that is already a
|
|
21
|
+
peer-to-peer application passes the ones it runs rather than having Core
|
|
22
|
+
stand up a second of each. Core never closes, destroys or suspends what it
|
|
23
|
+
was passed, takes the device identity from a passed swarm's keypair, and
|
|
24
|
+
leaves replication and wakeup on a passed swarm to the host. `swarm`
|
|
25
|
+
requires `store` and `wakeup`. The host suspends Core before its store, and
|
|
26
|
+
resumes its store before resuming or closing Core. `storagePath` is
|
|
27
|
+
unchanged and still holds the device-local database. See
|
|
28
|
+
[the decision record](docs/decisions/2026-09-28-a-host-passes-core-its-corestore-and-swarm.md).
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
const core = new Core(transport, {
|
|
32
|
+
storagePath,
|
|
33
|
+
store: host.rootCorestore.namespace('qvac'),
|
|
34
|
+
swarm: host.swarm,
|
|
35
|
+
wakeup: host.wakeup
|
|
36
|
+
})
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
(#303)
|
|
40
|
+
|
|
41
|
+
### Changed
|
|
42
|
+
|
|
43
|
+
- `@qvac/skills` is pinned at 0.1.11. 0.1.12 grants the `pptx`, `docx`, `xlsx`
|
|
44
|
+
and `transcribe_music` tools, which `@qvac/harness` does not register yet, so
|
|
45
|
+
a range would let a fresh install read presentations, word and excel as
|
|
46
|
+
unsupported. (#321)
|
|
47
|
+
|
|
48
|
+
### Fixed
|
|
49
|
+
|
|
50
|
+
- The assistant reports readiness for an agent newly hosted in the account as
|
|
51
|
+
soon as it lands there, as it already did in a shared mesh, so a credential
|
|
52
|
+
handed off to an agent created from another device no longer waits on it.
|
|
53
|
+
(#320)
|
|
54
|
+
|
|
55
|
+
## [0.6.6] - 2026-10-05
|
|
56
|
+
|
|
57
|
+
### Changed
|
|
58
|
+
|
|
59
|
+
- The consensus floor, `VENDORED_MIN_SUPPORTED_VERSION`, is back to `>=0.19.0`.
|
|
60
|
+
The app ships the #308 apply change in 0.19, so that release is the floor; at
|
|
61
|
+
`>=0.20.0` a 0.19 build would withhold itself from its own meshes. (#317)
|
|
62
|
+
|
|
16
63
|
## [0.6.5] - 2026-10-01
|
|
17
64
|
|
|
18
65
|
### Added
|
|
@@ -1226,7 +1273,9 @@ Published under the `release-0.1` dist-tag.
|
|
|
1226
1273
|
await assistant.ready()
|
|
1227
1274
|
```
|
|
1228
1275
|
|
|
1229
|
-
[Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.6.
|
|
1276
|
+
[Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.6.7...HEAD
|
|
1277
|
+
[0.6.7]: https://github.com/tetherto/qvac-core/compare/v0.6.6...v0.6.7
|
|
1278
|
+
[0.6.6]: https://github.com/tetherto/qvac-core/compare/v0.6.5...v0.6.6
|
|
1230
1279
|
[0.6.5]: https://github.com/tetherto/qvac-core/compare/v0.6.4...v0.6.5
|
|
1231
1280
|
[0.6.4]: https://github.com/tetherto/qvac-core/compare/v0.6.3...v0.6.4
|
|
1232
1281
|
[0.6.3]: https://github.com/tetherto/qvac-core/compare/v0.6.2...v0.6.3
|
|
@@ -61,6 +61,7 @@ export declare class QvacAssistant extends ReadyResource {
|
|
|
61
61
|
private readonly _lastCapabilities;
|
|
62
62
|
private _sharedMeshes;
|
|
63
63
|
private readonly _hostedIn;
|
|
64
|
+
private _accountHosted;
|
|
64
65
|
private _readySkills;
|
|
65
66
|
private _recordingReadiness;
|
|
66
67
|
private _readinessDirty;
|
|
@@ -158,6 +158,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
158
158
|
_lastCapabilities = new Map();
|
|
159
159
|
_sharedMeshes = new Set();
|
|
160
160
|
_hostedIn = new Map();
|
|
161
|
+
_accountHosted = [];
|
|
161
162
|
_readySkills;
|
|
162
163
|
_recordingReadiness = false;
|
|
163
164
|
_readinessDirty = false;
|
|
@@ -582,17 +583,22 @@ export class QvacAssistant extends ReadyResource {
|
|
|
582
583
|
}
|
|
583
584
|
_followHosted(meshId, agents) {
|
|
584
585
|
const deviceId = this._deviceId;
|
|
585
|
-
|
|
586
|
+
const account = meshId === this._accountMeshId;
|
|
587
|
+
if (!deviceId || (!account && !this._sharedMeshes.has(meshId))) {
|
|
586
588
|
return;
|
|
587
589
|
}
|
|
588
590
|
const hosted = agents
|
|
589
591
|
.filter((agent) => !!agent.providerDeviceId && b4a.equals(agent.providerDeviceId, deviceId))
|
|
590
592
|
.map((agent) => agent.id)
|
|
591
593
|
.sort();
|
|
592
|
-
|
|
594
|
+
const known = account ? this._accountHosted : (this._hostedIn.get(meshId) ?? []);
|
|
595
|
+
if (sameNameList(known, hosted)) {
|
|
593
596
|
return;
|
|
594
597
|
}
|
|
595
|
-
if (
|
|
598
|
+
if (account) {
|
|
599
|
+
this._accountHosted = hosted;
|
|
600
|
+
}
|
|
601
|
+
else if (hosted.length > 0) {
|
|
596
602
|
this._hostedIn.set(meshId, hosted);
|
|
597
603
|
}
|
|
598
604
|
else {
|
|
@@ -21,7 +21,7 @@ async function openDrive(store, swarm, key) {
|
|
|
21
21
|
const topic = swarm.join(drive.discoveryKey, { server: false, client: true });
|
|
22
22
|
const donePeering = drive.findingPeers();
|
|
23
23
|
topic.flushed().then(donePeering, donePeering);
|
|
24
|
-
return drive;
|
|
24
|
+
return { drive, writable: drive.writable, topic };
|
|
25
25
|
}
|
|
26
26
|
export function createFsDriveHost(store, opts) {
|
|
27
27
|
const namespaced = store.namespace(NAMESPACE);
|
|
@@ -36,13 +36,13 @@ export function createFsDriveHost(store, opts) {
|
|
|
36
36
|
return cached;
|
|
37
37
|
}
|
|
38
38
|
const opening = withDeadline((async () => {
|
|
39
|
-
const
|
|
40
|
-
const blobs = await drive.getBlobs();
|
|
41
|
-
peering.addCoreBackground(drive.core, { keys: opts.blindPeerKeys });
|
|
39
|
+
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
42
|
if (blobs) {
|
|
43
43
|
peering.addCoreBackground(blobs.core, { keys: opts.blindPeerKeys });
|
|
44
44
|
}
|
|
45
|
-
return
|
|
45
|
+
return held;
|
|
46
46
|
})(), DRIVE_OPEN_TIMEOUT_MS);
|
|
47
47
|
drives.set(key, opening);
|
|
48
48
|
opening.catch(() => drives.delete(key));
|
|
@@ -53,7 +53,10 @@ export function createFsDriveHost(store, opts) {
|
|
|
53
53
|
drives.clear();
|
|
54
54
|
await Promise.all(settled
|
|
55
55
|
.filter((result) => result.status === 'fulfilled')
|
|
56
|
-
.map((
|
|
56
|
+
.map(async ({ value: { drive, topic } }) => {
|
|
57
|
+
await topic.destroy();
|
|
58
|
+
await drive.close();
|
|
59
|
+
}));
|
|
57
60
|
await peering.close();
|
|
58
61
|
}
|
|
59
62
|
return { acquire, close };
|
|
@@ -35,6 +35,7 @@ export declare class HandoffChannel<Req, Res, Ack extends {
|
|
|
35
35
|
private readonly _peers;
|
|
36
36
|
private readonly _waiters;
|
|
37
37
|
private _nextId;
|
|
38
|
+
private readonly _pairing;
|
|
38
39
|
constructor(opts: HandoffChannelOptions<Req, Res, Ack>);
|
|
39
40
|
addStream(stream: HandoffStream): void;
|
|
40
41
|
send(hostDeviceId: Uint8Array, request: Req, kind?: number): Promise<Res>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
-
import Protomux, {} from 'protomux';
|
|
3
2
|
import { errorMessage } from '../guards.js';
|
|
3
|
+
import { createProtocolPairing } from './protocol-pairing.js';
|
|
4
4
|
export const HOST_UNREACHABLE = 'the device hosting this agent is not connected';
|
|
5
5
|
export const HOST_SILENT = 'the device hosting this agent did not answer';
|
|
6
6
|
export const ACK_TIMEOUT_MS = 60_000;
|
|
@@ -10,19 +10,23 @@ export class HandoffChannel {
|
|
|
10
10
|
_peers;
|
|
11
11
|
_waiters;
|
|
12
12
|
_nextId;
|
|
13
|
+
_pairing;
|
|
13
14
|
constructor(opts) {
|
|
14
15
|
this._opts = opts;
|
|
15
16
|
this._ackTimeoutMs = opts.ackTimeoutMs ?? ACK_TIMEOUT_MS;
|
|
16
17
|
this._peers = new Map();
|
|
17
18
|
this._waiters = new Map();
|
|
18
19
|
this._nextId = 0;
|
|
20
|
+
this._pairing = createProtocolPairing(opts.protocol);
|
|
19
21
|
}
|
|
20
22
|
addStream(stream) {
|
|
21
23
|
const deviceId = b4a.toHex(stream.remotePublicKey);
|
|
22
24
|
if (this._peers.has(deviceId)) {
|
|
23
25
|
return;
|
|
24
26
|
}
|
|
25
|
-
const channel =
|
|
27
|
+
const channel = this._pairing
|
|
28
|
+
.mux(stream, () => this.addStream(stream))
|
|
29
|
+
.createChannel({
|
|
26
30
|
protocol: this._opts.protocol,
|
|
27
31
|
onclose: () => {
|
|
28
32
|
if (channel) {
|
|
@@ -69,6 +73,7 @@ export class HandoffChannel {
|
|
|
69
73
|
return promise;
|
|
70
74
|
}
|
|
71
75
|
destroy() {
|
|
76
|
+
this._pairing.destroy();
|
|
72
77
|
for (const peer of this._peers.values()) {
|
|
73
78
|
peer.channel.close();
|
|
74
79
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import { raw, uint } from 'compact-encoding';
|
|
3
|
-
import Protomux, {} from 'protomux';
|
|
4
3
|
import { Duplex } from 'streamx';
|
|
4
|
+
import { createProtocolPairing } from './protocol-pairing.js';
|
|
5
5
|
const PROTOCOL = 'qvac/harness-loan';
|
|
6
6
|
function noop() { }
|
|
7
7
|
export const LOAN_UNREACHABLE = 'the device lending its model is not connected';
|
|
@@ -57,17 +57,21 @@ export class HarnessLoan {
|
|
|
57
57
|
_opts;
|
|
58
58
|
_peers;
|
|
59
59
|
_nextId;
|
|
60
|
+
_pairing;
|
|
60
61
|
constructor(opts) {
|
|
61
62
|
this._opts = opts;
|
|
62
63
|
this._peers = new Map();
|
|
63
64
|
this._nextId = 1;
|
|
65
|
+
this._pairing = createProtocolPairing(PROTOCOL);
|
|
64
66
|
}
|
|
65
67
|
addStream(stream) {
|
|
66
68
|
const deviceId = b4a.toHex(stream.remotePublicKey);
|
|
67
69
|
if (this._peers.has(deviceId)) {
|
|
68
70
|
return;
|
|
69
71
|
}
|
|
70
|
-
const channel =
|
|
72
|
+
const channel = this._pairing
|
|
73
|
+
.mux(stream, () => this.addStream(stream))
|
|
74
|
+
.createChannel({
|
|
71
75
|
protocol: PROTOCOL,
|
|
72
76
|
onclose: () => this._drop(deviceId)
|
|
73
77
|
});
|
|
@@ -122,6 +126,7 @@ export class HarnessLoan {
|
|
|
122
126
|
}
|
|
123
127
|
}
|
|
124
128
|
destroy() {
|
|
129
|
+
this._pairing.destroy();
|
|
125
130
|
for (const [deviceId, peer] of [...this._peers]) {
|
|
126
131
|
try {
|
|
127
132
|
peer.channel.close();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Protomux from 'protomux';
|
|
2
|
+
export interface PairedStream {
|
|
3
|
+
readonly noiseStream: {
|
|
4
|
+
userData: unknown;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export interface ProtocolPairing {
|
|
8
|
+
mux(stream: PairedStream, onopen: () => void): Protomux;
|
|
9
|
+
destroy(): void;
|
|
10
|
+
}
|
|
11
|
+
export declare function createProtocolPairing(protocol: string): ProtocolPairing;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Protomux from 'protomux';
|
|
2
|
+
export function createProtocolPairing(protocol) {
|
|
3
|
+
const muxes = new Map();
|
|
4
|
+
function mux(stream, onopen) {
|
|
5
|
+
const paired = Protomux.from(stream.noiseStream);
|
|
6
|
+
if (!muxes.has(paired)) {
|
|
7
|
+
const onclose = () => muxes.delete(paired);
|
|
8
|
+
muxes.set(paired, onclose);
|
|
9
|
+
paired.pair({ protocol }, onopen);
|
|
10
|
+
paired.stream.once('close', onclose);
|
|
11
|
+
}
|
|
12
|
+
return paired;
|
|
13
|
+
}
|
|
14
|
+
function destroy() {
|
|
15
|
+
for (const [paired, onclose] of muxes) {
|
|
16
|
+
paired.unpair({ protocol });
|
|
17
|
+
paired.stream.off('close', onclose);
|
|
18
|
+
}
|
|
19
|
+
muxes.clear();
|
|
20
|
+
}
|
|
21
|
+
return { mux, destroy };
|
|
22
|
+
}
|
package/dist-lib/lib/core.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import Corestore from 'corestore';
|
|
2
2
|
import CorestoreStorage from 'hypercore-storage';
|
|
3
3
|
import type { BootstrapNode } from 'hyperswarm';
|
|
4
|
+
import Hyperswarm from 'hyperswarm';
|
|
5
|
+
import Wakeup from 'protomux-wakeup';
|
|
4
6
|
import ReadyGuard from 'ready-guard';
|
|
5
7
|
import ReadyResource from 'ready-resource';
|
|
6
8
|
import type { Logger } from '../index.ts';
|
|
@@ -32,6 +34,9 @@ export interface FileGcOptions {
|
|
|
32
34
|
}
|
|
33
35
|
export interface CoreOptions {
|
|
34
36
|
storagePath: string;
|
|
37
|
+
store?: Corestore;
|
|
38
|
+
swarm?: Hyperswarm;
|
|
39
|
+
wakeup?: Wakeup;
|
|
35
40
|
logger?: Logger | null;
|
|
36
41
|
spec?: () => Promise<CoreSpec>;
|
|
37
42
|
bootstrapNodes?: ReadonlyArray<BootstrapNode>;
|
|
@@ -133,6 +138,9 @@ export declare class Core extends ReadyResource {
|
|
|
133
138
|
store: Corestore;
|
|
134
139
|
rootCorestore: Corestore;
|
|
135
140
|
storage: CorestoreStorage;
|
|
141
|
+
private readonly _ownsStore;
|
|
142
|
+
private readonly _ownsSwarm;
|
|
143
|
+
private readonly _ownsWakeup;
|
|
136
144
|
local: ReturnType<typeof openLocalStore>;
|
|
137
145
|
private readonly _deviceInvites;
|
|
138
146
|
state: LocalQvacState;
|
|
@@ -211,6 +219,7 @@ export declare class Core extends ReadyResource {
|
|
|
211
219
|
private _identityPhrase;
|
|
212
220
|
private _identityPublicKey;
|
|
213
221
|
private _swarm;
|
|
222
|
+
private readonly _onSwarmConnection;
|
|
214
223
|
private _departures;
|
|
215
224
|
private _fsDrives;
|
|
216
225
|
private _blobServer;
|
|
@@ -233,6 +242,7 @@ export declare class Core extends ReadyResource {
|
|
|
233
242
|
private _kicked;
|
|
234
243
|
private _kickedPending;
|
|
235
244
|
private readonly _peers;
|
|
245
|
+
private _peerArrivedSuspended;
|
|
236
246
|
private readonly _statusListeners;
|
|
237
247
|
private _listing;
|
|
238
248
|
private readonly _diagnosticsProviders;
|
|
@@ -242,7 +252,7 @@ export declare class Core extends ReadyResource {
|
|
|
242
252
|
private _systemInfo;
|
|
243
253
|
private _statusError;
|
|
244
254
|
private _upgradeRequired;
|
|
245
|
-
constructor(transport: Transport, { storagePath, logger, spec, bootstrapNodes, device, app, minSupportedVersion, otaConfigCore, blindPeerKeys, blindPeeringOpts, fileGc, meshSeed, meshKey, additionalNodes, listModels, deleteModel, clearKvCache, deleteChatKvCache, compactChat, modelCatalogWatch, retryModelDownload, transcribe, detectLanguage, previewModelSource, speak, speakStream, embedder, extractors, skills, skillCatalog, tools, hostsModelSource, vectorIndex, apiLifecycle, grantWritableMs, accountWritableMs, grantVisibleMs }: CoreOptions);
|
|
255
|
+
constructor(transport: Transport, { storagePath, store, swarm, wakeup, logger, spec, bootstrapNodes, device, app, minSupportedVersion, otaConfigCore, blindPeerKeys, blindPeeringOpts, fileGc, meshSeed, meshKey, additionalNodes, listModels, deleteModel, clearKvCache, deleteChatKvCache, compactChat, modelCatalogWatch, retryModelDownload, transcribe, detectLanguage, previewModelSource, speak, speakStream, embedder, extractors, skills, skillCatalog, tools, hostsModelSource, vectorIndex, apiLifecycle, grantWritableMs, accountWritableMs, grantVisibleMs }: CoreOptions);
|
|
246
256
|
get devicePublicKey(): Buffer | null;
|
|
247
257
|
private _requireDeviceKeyPair;
|
|
248
258
|
get fsDrives(): DriveHost | null;
|
|
@@ -271,7 +281,9 @@ export declare class Core extends ReadyResource {
|
|
|
271
281
|
suspend(): Promise<void>;
|
|
272
282
|
resume(): Promise<void>;
|
|
273
283
|
private _refreshTopics;
|
|
284
|
+
private _joinedTopics;
|
|
274
285
|
_close(): Promise<void>;
|
|
286
|
+
private _closeStore;
|
|
275
287
|
private _openSwarm;
|
|
276
288
|
private _resolveBlindPeerKeys;
|
|
277
289
|
private _startMesh;
|
|
@@ -462,6 +474,7 @@ export declare class Core extends ReadyResource {
|
|
|
462
474
|
private _setupFields;
|
|
463
475
|
private _hostSkills;
|
|
464
476
|
private _onConnection;
|
|
477
|
+
private _retryOnPeer;
|
|
465
478
|
private _trackPeerConnection;
|
|
466
479
|
private _onPeerChange;
|
|
467
480
|
private _meshPool;
|
package/dist-lib/lib/core.js
CHANGED
|
@@ -11,6 +11,7 @@ import Top from 'process-top';
|
|
|
11
11
|
import ReadyGuard from 'ready-guard';
|
|
12
12
|
import ReadyResource from 'ready-resource';
|
|
13
13
|
import ScopeLock from 'scope-lock';
|
|
14
|
+
import { isAndroid } from 'which-runtime';
|
|
14
15
|
import { createApi } from './api/index.js';
|
|
15
16
|
import { NO_SUCH_MESH, requireMesh } from './api/current-mesh.js';
|
|
16
17
|
import { ChatMoves } from './core/chat-move.js';
|
|
@@ -116,6 +117,9 @@ export class Core extends ReadyResource {
|
|
|
116
117
|
store;
|
|
117
118
|
rootCorestore;
|
|
118
119
|
storage;
|
|
120
|
+
_ownsStore;
|
|
121
|
+
_ownsSwarm;
|
|
122
|
+
_ownsWakeup;
|
|
119
123
|
local;
|
|
120
124
|
_deviceInvites;
|
|
121
125
|
state;
|
|
@@ -194,6 +198,7 @@ export class Core extends ReadyResource {
|
|
|
194
198
|
_identityPhrase = null;
|
|
195
199
|
_identityPublicKey = null;
|
|
196
200
|
_swarm;
|
|
201
|
+
_onSwarmConnection;
|
|
197
202
|
_departures = null;
|
|
198
203
|
_fsDrives = null;
|
|
199
204
|
_blobServer = null;
|
|
@@ -216,6 +221,7 @@ export class Core extends ReadyResource {
|
|
|
216
221
|
_kicked;
|
|
217
222
|
_kickedPending;
|
|
218
223
|
_peers;
|
|
224
|
+
_peerArrivedSuspended = false;
|
|
219
225
|
_statusListeners;
|
|
220
226
|
_listing;
|
|
221
227
|
_diagnosticsProviders;
|
|
@@ -225,7 +231,7 @@ export class Core extends ReadyResource {
|
|
|
225
231
|
_systemInfo;
|
|
226
232
|
_statusError;
|
|
227
233
|
_upgradeRequired;
|
|
228
|
-
constructor(transport, { storagePath, logger = null, spec = openLocalSpec, bootstrapNodes = undefined, device = undefined, app = undefined, minSupportedVersion = undefined, otaConfigCore = undefined, blindPeerKeys = undefined, blindPeeringOpts = undefined, fileGc = null, 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, grantWritableMs = GRANT_WRITABLE_MS, accountWritableMs = ACCOUNT_WRITABLE_MS, grantVisibleMs = GRANT_VISIBLE_MS }) {
|
|
234
|
+
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, 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, grantWritableMs = GRANT_WRITABLE_MS, accountWritableMs = ACCOUNT_WRITABLE_MS, grantVisibleMs = GRANT_VISIBLE_MS }) {
|
|
229
235
|
super();
|
|
230
236
|
this._transport = transport;
|
|
231
237
|
this._apiLifecycle = apiLifecycle ?? {
|
|
@@ -236,15 +242,19 @@ export class Core extends ReadyResource {
|
|
|
236
242
|
if (logger) {
|
|
237
243
|
setLogger(logger);
|
|
238
244
|
}
|
|
245
|
+
if (swarm && (!store || !wakeup)) {
|
|
246
|
+
throw new Error('swarm may only be passed alongside store and wakeup');
|
|
247
|
+
}
|
|
248
|
+
this._ownsStore = !store;
|
|
249
|
+
this._ownsSwarm = !swarm;
|
|
250
|
+
this._ownsWakeup = !wakeup;
|
|
239
251
|
this._storagePath = storagePath;
|
|
240
252
|
this.storage = new CorestoreStorage(this._storagePath, {
|
|
241
253
|
blobGarbageCollectionAgeCutOff: 1.0,
|
|
242
254
|
blobGarbageCollectionForceThreshold: 0.5,
|
|
243
255
|
blobFileSize: 64 * 1024 * 1024
|
|
244
256
|
});
|
|
245
|
-
this.rootCorestore = new Corestore(this.storage, {
|
|
246
|
-
globalCache: new Rache()
|
|
247
|
-
});
|
|
257
|
+
this.rootCorestore = store ?? new Corestore(this.storage, { globalCache: new Rache() });
|
|
248
258
|
this.store = this.rootCorestore.namespace(QVAC_CORE_NAMESPACE);
|
|
249
259
|
this.local = openLocalStore(this.storage);
|
|
250
260
|
this._deviceInvites = openDeviceInvites(this.local);
|
|
@@ -317,8 +327,9 @@ export class Core extends ReadyResource {
|
|
|
317
327
|
this._api = null;
|
|
318
328
|
this._clients = new Set();
|
|
319
329
|
this._deviceKeyPair = null;
|
|
320
|
-
this._swarm = null;
|
|
321
|
-
this.
|
|
330
|
+
this._swarm = swarm ?? null;
|
|
331
|
+
this._onSwarmConnection = (conn) => this._onConnection(conn);
|
|
332
|
+
this._wakeup = wakeup ?? new Wakeup();
|
|
322
333
|
this._secretHandoff = new SecretHandoff({
|
|
323
334
|
onrequest: (request, from) => this._storeHandedOffSecret(request, from)
|
|
324
335
|
});
|
|
@@ -336,7 +347,7 @@ export class Core extends ReadyResource {
|
|
|
336
347
|
this._leaving = null;
|
|
337
348
|
this._kicked = false;
|
|
338
349
|
this._kickedPending = false;
|
|
339
|
-
this._peers = new
|
|
350
|
+
this._peers = new Map();
|
|
340
351
|
this._statusListeners = new Set();
|
|
341
352
|
this._listing = null;
|
|
342
353
|
this._diagnosticsProviders = new Set();
|
|
@@ -369,7 +380,7 @@ export class Core extends ReadyResource {
|
|
|
369
380
|
return this._peers.size;
|
|
370
381
|
}
|
|
371
382
|
get peerDeviceIds() {
|
|
372
|
-
const ids = [...this._peers].map((conn) => b4a.toHex(conn.remotePublicKey));
|
|
383
|
+
const ids = [...this._peers.keys()].map((conn) => b4a.toHex(conn.remotePublicKey));
|
|
373
384
|
return [...new Set(ids)].sort();
|
|
374
385
|
}
|
|
375
386
|
async _open() {
|
|
@@ -380,7 +391,8 @@ export class Core extends ReadyResource {
|
|
|
380
391
|
}
|
|
381
392
|
async _runBootOffline() {
|
|
382
393
|
try {
|
|
383
|
-
this._deviceKeyPair =
|
|
394
|
+
this._deviceKeyPair =
|
|
395
|
+
this._swarm?.keyPair ?? (await this.store.createKeyPair(SWARM_KEYPAIR_NAME));
|
|
384
396
|
this._identityPublicKey = (await this.local.readIdentity())?.publicKey ?? null;
|
|
385
397
|
this._localDevice = await this.local.ensureDevice(this._deviceKeyPair.publicKey, this._device);
|
|
386
398
|
const swarm = this._openSwarm(this._deviceKeyPair);
|
|
@@ -581,8 +593,7 @@ export class Core extends ReadyResource {
|
|
|
581
593
|
await mesh.close();
|
|
582
594
|
}
|
|
583
595
|
logger.info('core', 'closing storage');
|
|
584
|
-
await this.
|
|
585
|
-
await this.rootCorestore?.close();
|
|
596
|
+
await this._closeStore();
|
|
586
597
|
}
|
|
587
598
|
finally {
|
|
588
599
|
this._offlineBoot.destroy(err instanceof Error ? err : new Error(String(err)));
|
|
@@ -851,13 +862,15 @@ export class Core extends ReadyResource {
|
|
|
851
862
|
if (this._recoveryPeering) {
|
|
852
863
|
await this._recoveryPeering.suspend();
|
|
853
864
|
}
|
|
854
|
-
if (this._swarm) {
|
|
865
|
+
if (this._swarm && this._ownsSwarm) {
|
|
855
866
|
await this._swarm.suspend();
|
|
856
867
|
}
|
|
857
868
|
if (this._blobServer) {
|
|
858
869
|
await this._blobServer.suspend();
|
|
859
870
|
}
|
|
860
|
-
|
|
871
|
+
if (!isAndroid) {
|
|
872
|
+
await this.storage.suspend();
|
|
873
|
+
}
|
|
861
874
|
this._log?.info('lifecycle', 'core suspend');
|
|
862
875
|
}
|
|
863
876
|
async resume() {
|
|
@@ -877,11 +890,11 @@ export class Core extends ReadyResource {
|
|
|
877
890
|
await this.ready();
|
|
878
891
|
}
|
|
879
892
|
logger.info('core', 'resuming');
|
|
880
|
-
await this.
|
|
893
|
+
await this.storage.resume();
|
|
881
894
|
if (this._blobServer) {
|
|
882
895
|
await this._blobServer.resume();
|
|
883
896
|
}
|
|
884
|
-
if (this._swarm) {
|
|
897
|
+
if (this._swarm && this._ownsSwarm) {
|
|
885
898
|
await this._swarm.resume();
|
|
886
899
|
}
|
|
887
900
|
if (this._configPeering) {
|
|
@@ -897,6 +910,10 @@ export class Core extends ReadyResource {
|
|
|
897
910
|
await this._departures.resume();
|
|
898
911
|
}
|
|
899
912
|
this._departures?.flush();
|
|
913
|
+
if (this._peerArrivedSuspended) {
|
|
914
|
+
this._peerArrivedSuspended = false;
|
|
915
|
+
this._retryOnPeer();
|
|
916
|
+
}
|
|
900
917
|
this._startFileGc();
|
|
901
918
|
if (this._swarm) {
|
|
902
919
|
void this._refreshTopics(this._swarm).catch(noop);
|
|
@@ -905,15 +922,27 @@ export class Core extends ReadyResource {
|
|
|
905
922
|
this._log?.info('lifecycle', 'core resume');
|
|
906
923
|
}
|
|
907
924
|
async _refreshTopics(swarm) {
|
|
908
|
-
for (const discovery of
|
|
925
|
+
for (const discovery of this._joinedTopics(swarm)) {
|
|
909
926
|
await discovery.flushed();
|
|
910
927
|
await discovery.refresh();
|
|
911
928
|
}
|
|
912
929
|
}
|
|
930
|
+
_joinedTopics(swarm) {
|
|
931
|
+
if (this._ownsSwarm) {
|
|
932
|
+
return swarm.topics();
|
|
933
|
+
}
|
|
934
|
+
const meshes = [...this._meshes.values()].map(({ mesh }) => mesh);
|
|
935
|
+
if (this._candidateMesh) {
|
|
936
|
+
meshes.push(this._candidateMesh);
|
|
937
|
+
}
|
|
938
|
+
return meshes
|
|
939
|
+
.map((mesh) => swarm.status(mesh.discoveryKey))
|
|
940
|
+
.filter((discovery) => discovery !== null);
|
|
941
|
+
}
|
|
913
942
|
async _close() {
|
|
914
943
|
logger.info('core', 'closing');
|
|
915
944
|
if (this.state === QvacState.SUSPEND) {
|
|
916
|
-
await this.
|
|
945
|
+
await this.storage.resume();
|
|
917
946
|
}
|
|
918
947
|
this._catalogHooks.destroy(new Error('core is closing'));
|
|
919
948
|
this._modelCatalogWatchSource.destroy(new Error('core is closing'));
|
|
@@ -958,18 +987,29 @@ export class Core extends ReadyResource {
|
|
|
958
987
|
this._systemInfo?.destroy();
|
|
959
988
|
this._systemInfo = null;
|
|
960
989
|
logger.info('core', 'closing storage');
|
|
961
|
-
await this.
|
|
962
|
-
await this.rootCorestore?.close();
|
|
990
|
+
await this._closeStore();
|
|
963
991
|
this._log?.info('lifecycle', 'core closed');
|
|
964
992
|
}
|
|
993
|
+
async _closeStore() {
|
|
994
|
+
await this.store?.close();
|
|
995
|
+
if (this._ownsStore) {
|
|
996
|
+
await this.rootCorestore?.close();
|
|
997
|
+
}
|
|
998
|
+
await this.storage.close();
|
|
999
|
+
}
|
|
965
1000
|
_openSwarm(keyPair) {
|
|
966
|
-
this._swarm
|
|
1001
|
+
this._swarm ??= new Hyperswarm({
|
|
967
1002
|
keyPair,
|
|
968
1003
|
bootstrap: this._bootstrapNodes,
|
|
969
1004
|
relayThrough: this._bootstrapNodes ? undefined : () => BLIND_RELAY_KEYS
|
|
970
1005
|
});
|
|
971
|
-
this._swarm.on('connection',
|
|
972
|
-
|
|
1006
|
+
this._swarm.on('connection', this._onSwarmConnection);
|
|
1007
|
+
for (const conn of this._swarm.connections) {
|
|
1008
|
+
if (isPeerConnection(conn)) {
|
|
1009
|
+
this._onConnection(conn);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
this._log?.info(['p2p', 'swarm'], 'swarm opened', {
|
|
973
1013
|
deviceKey: b4a.toHex(keyPair.publicKey).slice(0, 8)
|
|
974
1014
|
});
|
|
975
1015
|
for (const node of this._additionalNodes ?? []) {
|
|
@@ -3568,7 +3608,9 @@ export class Core extends ReadyResource {
|
|
|
3568
3608
|
return { memberInvite: decoded.memberInvite ?? false, inviterName: decoded.inviterName };
|
|
3569
3609
|
}
|
|
3570
3610
|
async _closeSwarm() {
|
|
3571
|
-
this.
|
|
3611
|
+
if (this._ownsWakeup) {
|
|
3612
|
+
this._wakeup.destroy();
|
|
3613
|
+
}
|
|
3572
3614
|
this._meshSeedHandoff.destroy();
|
|
3573
3615
|
this._harnessLoan.destroy();
|
|
3574
3616
|
this._secretHandoff.destroy();
|
|
@@ -3579,6 +3621,15 @@ export class Core extends ReadyResource {
|
|
|
3579
3621
|
}
|
|
3580
3622
|
const swarm = this._swarm;
|
|
3581
3623
|
this._swarm = null;
|
|
3624
|
+
swarm.off('connection', this._onSwarmConnection);
|
|
3625
|
+
if (!this._ownsSwarm) {
|
|
3626
|
+
for (const detach of this._peers.values()) {
|
|
3627
|
+
detach();
|
|
3628
|
+
}
|
|
3629
|
+
this._peers.clear();
|
|
3630
|
+
await Promise.all([...this._meshes.values()].map(({ mesh }) => swarm.leave(mesh.discoveryKey)));
|
|
3631
|
+
return;
|
|
3632
|
+
}
|
|
3582
3633
|
for (const conn of swarm.connections) {
|
|
3583
3634
|
conn.destroy?.();
|
|
3584
3635
|
}
|
|
@@ -4371,47 +4422,62 @@ export class Core extends ReadyResource {
|
|
|
4371
4422
|
conn.on('error', noop);
|
|
4372
4423
|
return;
|
|
4373
4424
|
}
|
|
4374
|
-
this._trackPeerConnection(conn);
|
|
4375
4425
|
const remoteId = b4a.toHex(conn.remotePublicKey).slice(0, 8);
|
|
4376
4426
|
const start = Date.now();
|
|
4377
4427
|
let bytes = 0;
|
|
4378
4428
|
let connErr = null;
|
|
4379
4429
|
this._log?.info(['p2p', 'peer'], `got ${conn.isInitiator ? 'client' : 'server'} connection to ${remoteId}`);
|
|
4380
|
-
|
|
4430
|
+
const onerror = (err) => {
|
|
4381
4431
|
connErr = err;
|
|
4382
|
-
}
|
|
4383
|
-
|
|
4432
|
+
};
|
|
4433
|
+
const onclose = () => {
|
|
4384
4434
|
this._log?.info(['p2p', 'peer'], `connection closed to ${remoteId}, with err: ${connErr} (${Date.now() - start} ms ${bytes} bytes recv)`);
|
|
4385
|
-
}
|
|
4386
|
-
|
|
4435
|
+
};
|
|
4436
|
+
const ondata = (data) => {
|
|
4387
4437
|
bytes += data.byteLength;
|
|
4438
|
+
};
|
|
4439
|
+
conn.once('error', onerror);
|
|
4440
|
+
conn.once('close', onclose);
|
|
4441
|
+
conn.on('data', ondata);
|
|
4442
|
+
this._trackPeerConnection(conn, () => {
|
|
4443
|
+
conn.off('error', onerror);
|
|
4444
|
+
conn.off('close', onclose);
|
|
4445
|
+
conn.off('data', ondata);
|
|
4388
4446
|
});
|
|
4389
|
-
this._wakeup.addStream(conn);
|
|
4390
4447
|
this._secretHandoff.addStream(conn);
|
|
4391
4448
|
this._skillOverlayHandoff.addStream(conn);
|
|
4392
4449
|
this._meshSeedHandoff.addStream(conn);
|
|
4393
4450
|
this._harnessLoan.addStream(conn);
|
|
4394
4451
|
this._inferenceCallsHandoff.addStream(conn);
|
|
4452
|
+
if (this._ownsSwarm) {
|
|
4453
|
+
this._wakeup.addStream(conn);
|
|
4454
|
+
this.rootCorestore.replicate(conn);
|
|
4455
|
+
}
|
|
4456
|
+
if (this.suspended) {
|
|
4457
|
+
this._peerArrivedSuspended = true;
|
|
4458
|
+
return;
|
|
4459
|
+
}
|
|
4460
|
+
this._retryOnPeer();
|
|
4461
|
+
}
|
|
4462
|
+
_retryOnPeer() {
|
|
4395
4463
|
for (const entry of this._meshes.values()) {
|
|
4396
4464
|
entry.hostedAgents?.kick();
|
|
4397
4465
|
void this._followJoinedMeshes(entry.mesh);
|
|
4398
|
-
}
|
|
4399
|
-
this.rootCorestore.replicate(conn);
|
|
4400
|
-
for (const entry of this._meshes.values()) {
|
|
4401
4466
|
entry.mesh.files.reconnect();
|
|
4402
4467
|
}
|
|
4403
4468
|
}
|
|
4404
|
-
_trackPeerConnection(conn) {
|
|
4405
|
-
this._peers.add(conn);
|
|
4406
|
-
this._onPeerChange();
|
|
4407
|
-
let removed = false;
|
|
4469
|
+
_trackPeerConnection(conn, detach) {
|
|
4408
4470
|
const remove = () => {
|
|
4409
|
-
if (
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
this._peers.delete(conn);
|
|
4413
|
-
this._onPeerChange();
|
|
4471
|
+
if (this._peers.delete(conn)) {
|
|
4472
|
+
this._onPeerChange();
|
|
4473
|
+
}
|
|
4414
4474
|
};
|
|
4475
|
+
this._peers.set(conn, () => {
|
|
4476
|
+
detach();
|
|
4477
|
+
conn.off('close', remove);
|
|
4478
|
+
conn.off('error', remove);
|
|
4479
|
+
});
|
|
4480
|
+
this._onPeerChange();
|
|
4415
4481
|
conn.once('close', remove);
|
|
4416
4482
|
conn.once('error', remove);
|
|
4417
4483
|
}
|
|
@@ -4949,6 +5015,9 @@ function unmarkedNotice(losers) {
|
|
|
4949
5015
|
return `another device of yours opened a shared mesh at the same moment, so ${ids} is an ordinary mesh now`;
|
|
4950
5016
|
}
|
|
4951
5017
|
function noop() { }
|
|
5018
|
+
function isPeerConnection(conn) {
|
|
5019
|
+
return 'remotePublicKey' in conn;
|
|
5020
|
+
}
|
|
4952
5021
|
async function closeConfigReader(reader) {
|
|
4953
5022
|
if (!reader)
|
|
4954
5023
|
return;
|
|
@@ -6,7 +6,7 @@ const runtime = require('hyperconf/runtime')
|
|
|
6
6
|
const productionEncoding = schema.getEncoding('@conf/config')
|
|
7
7
|
const production = decode(
|
|
8
8
|
productionEncoding,
|
|
9
|
-
runtime.b4a.from('
|
|
9
|
+
runtime.b4a.from('CD49MC4xOS4w', 'base64')
|
|
10
10
|
)
|
|
11
11
|
|
|
12
12
|
const developmentEncoding = null
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qvac/core",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Peer-to-peer AI across your devices",
|
|
6
6
|
"engines": {
|
|
@@ -167,7 +167,7 @@
|
|
|
167
167
|
"mesh-recover-account": "bare examples/mesh-recover-account.mjs",
|
|
168
168
|
"mesh-user-names": "bare examples/mesh-user-names.mjs",
|
|
169
169
|
"test": "npm run test:bare && npm run bench:rag:test",
|
|
170
|
-
"test:bare": "QVAC_NO_SKILL_BIN_PROBE=1 brittle-jobs -j 2 --retries 1 --timeout 600000 'test/*.ts' 'test/{api,basic,rag}/**/*.ts' 'test/tui/**/!(helpers).ts'",
|
|
170
|
+
"test:bare": "QVAC_NO_SKILL_BIN_PROBE=1 brittle-jobs -j 2 --retries 1 --timeout 600000 'test/*.ts' 'test/{api,basic,host,rag}/**/*.ts' 'test/tui/**/!(helpers).ts'",
|
|
171
171
|
"test:model": "QVAC_TEST_MODELS=1 npm run test:bare",
|
|
172
172
|
"format": "prettier . --write",
|
|
173
173
|
"lint": "prettier . --check && lunte && tsc --noEmit",
|
|
@@ -240,7 +240,7 @@
|
|
|
240
240
|
},
|
|
241
241
|
"dependencies": {
|
|
242
242
|
"@qvac/harness": "^0.7.2",
|
|
243
|
-
"@qvac/skills": "
|
|
243
|
+
"@qvac/skills": "0.1.11",
|
|
244
244
|
"asenion": "^0.1.0",
|
|
245
245
|
"autobee": "^2.11.8",
|
|
246
246
|
"b4a": "^1.9.0",
|