@qvac/core 0.2.1 → 0.3.0
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/.claude/skills/compaction/SKILL.md +15 -6
- package/.claude/skills/js-house-style/SKILL.md +1 -0
- package/.claude/skills/pr-create/SKILL.md +66 -3
- package/.claude/skills/pr-review/SKILL.md +252 -40
- package/.claude/skills/release/SKILL.md +122 -0
- package/CLAUDE.md +8 -5
- package/README.md +3 -1
- package/dist-lib/client.js +1 -1
- package/dist-lib/index.js +8 -8
- package/dist-lib/lib/api/agents.d.ts +1 -1
- package/dist-lib/lib/api/agents.js +10 -10
- package/dist-lib/lib/api/app-config.js +1 -1
- package/dist-lib/lib/api/approval-rules.js +9 -5
- package/dist-lib/lib/api/attachments.js +25 -3
- package/dist-lib/lib/api/chat-groups.d.ts +1 -1
- package/dist-lib/lib/api/chat-groups.js +5 -4
- package/dist-lib/lib/api/chat.js +10 -10
- package/dist-lib/lib/api/chunks.d.ts +1 -1
- package/dist-lib/lib/api/chunks.js +11 -21
- package/dist-lib/lib/api/config.js +1 -1
- package/dist-lib/lib/api/current-mesh.d.ts +16 -1
- package/dist-lib/lib/api/current-mesh.js +18 -0
- package/dist-lib/lib/api/custom-models.js +2 -2
- package/dist-lib/lib/api/devices.d.ts +1 -1
- package/dist-lib/lib/api/devices.js +12 -9
- package/dist-lib/lib/api/diagnostics.js +1 -1
- package/dist-lib/lib/api/effective-ctx-size.js +1 -1
- package/dist-lib/lib/api/execution.js +4 -4
- package/dist-lib/lib/api/files.js +2 -2
- package/dist-lib/lib/api/index.d.ts +1 -0
- package/dist-lib/lib/api/index.js +34 -34
- package/dist-lib/lib/api/instrument.js +1 -1
- package/dist-lib/lib/api/knowledge.js +13 -9
- package/dist-lib/lib/api/logs.js +1 -1
- package/dist-lib/lib/api/members.d.ts +4 -1
- package/dist-lib/lib/api/members.js +87 -18
- package/dist-lib/lib/api/mesh.d.ts +13 -3
- package/dist-lib/lib/api/mesh.js +25 -2
- package/dist-lib/lib/api/model-download.js +1 -1
- package/dist-lib/lib/api/network.js +1 -1
- package/dist-lib/lib/api/notifications.js +3 -3
- package/dist-lib/lib/api/rag.js +7 -7
- package/dist-lib/lib/api/sync.d.ts +1 -1
- package/dist-lib/lib/api/sync.js +3 -2
- package/dist-lib/lib/api/tool-activity.js +5 -5
- package/dist-lib/lib/api/tool-configs.js +5 -5
- package/dist-lib/lib/api/watchable.d.ts +6 -1
- package/dist-lib/lib/api/watchable.js +14 -3
- package/dist-lib/lib/assistant/fetch-body.d.ts +5 -0
- package/dist-lib/lib/assistant/fetch-body.js +36 -0
- package/dist-lib/lib/assistant/harness.d.ts +225 -0
- package/dist-lib/lib/assistant/harness.js +154 -0
- package/dist-lib/lib/assistant/history.d.ts +31 -0
- package/dist-lib/lib/assistant/history.js +226 -0
- package/dist-lib/lib/assistant/message.d.ts +45 -0
- package/dist-lib/lib/assistant/message.js +47 -0
- package/dist-lib/lib/assistant/skill-encode.d.ts +21 -0
- package/dist-lib/lib/assistant/skill-encode.js +71 -0
- package/dist-lib/lib/assistant-client.js +2 -2
- package/dist-lib/lib/assistant-tree.js +10 -4
- package/dist-lib/lib/assistant.d.ts +28 -292
- package/dist-lib/lib/assistant.js +284 -716
- package/dist-lib/lib/audio-format.js +2 -2
- package/dist-lib/lib/client.js +2 -2
- package/dist-lib/lib/collabora/convert.js +1 -1
- package/dist-lib/lib/collabora/entry.js +1 -1
- package/dist-lib/lib/collabora/worker.js +1 -1
- package/dist-lib/lib/compaction.d.ts +1 -2
- package/dist-lib/lib/compaction.js +8 -6
- package/dist-lib/lib/constants.js +1 -1
- package/dist-lib/lib/core/account-recovery.d.ts +19 -0
- package/dist-lib/lib/core/account-recovery.js +50 -0
- package/dist-lib/lib/core/agent.js +8 -4
- package/dist-lib/lib/core/app-build.d.ts +1 -1
- package/dist-lib/lib/core/approval-rules.d.ts +1 -0
- package/dist-lib/lib/core/approval-rules.js +3 -1
- package/dist-lib/lib/core/archived-mesh.d.ts +25 -0
- package/dist-lib/lib/core/archived-mesh.js +162 -0
- package/dist-lib/lib/core/chat-activity.js +1 -1
- package/dist-lib/lib/core/chat-group.d.ts +1 -0
- package/dist-lib/lib/core/chat-group.js +24 -4
- package/dist-lib/lib/core/chat-search.js +2 -2
- package/dist-lib/lib/core/chat.js +5 -5
- package/dist-lib/lib/core/chunk.d.ts +2 -1
- package/dist-lib/lib/core/chunk.js +31 -4
- package/dist-lib/lib/core/contract/agents.js +1 -1
- package/dist-lib/lib/core/contract/approval-rules.js +6 -4
- package/dist-lib/lib/core/contract/attestations.js +1 -1
- package/dist-lib/lib/core/contract/chat-group.js +1 -1
- package/dist-lib/lib/core/contract/chat.js +1 -1
- package/dist-lib/lib/core/contract/chunks.js +2 -2
- package/dist-lib/lib/core/contract/compute.d.ts +11 -0
- package/dist-lib/lib/core/contract/compute.js +45 -0
- package/dist-lib/lib/core/contract/devices.js +19 -5
- package/dist-lib/lib/core/contract/index.d.ts +3 -1
- package/dist-lib/lib/core/contract/index.js +19 -16
- package/dist-lib/lib/core/contract/indexing.js +2 -2
- package/dist-lib/lib/core/contract/joined-meshes.js +1 -1
- package/dist-lib/lib/core/contract/knowledge.js +2 -2
- package/dist-lib/lib/core/contract/members.js +2 -2
- package/dist-lib/lib/core/contract/seal.d.ts +2 -0
- package/dist-lib/lib/core/contract/seal.js +8 -0
- package/dist-lib/lib/core/contract/seed-defaults.js +1 -1
- package/dist-lib/lib/core/contract/tool-activity.js +1 -1
- package/dist-lib/lib/core/contract/tool-configs.js +3 -3
- package/dist-lib/lib/core/contract/writers.js +66 -42
- package/dist-lib/lib/core/departures.js +1 -1
- package/dist-lib/lib/core/device-invites.js +1 -1
- package/dist-lib/lib/core/document-attachment.js +2 -2
- package/dist-lib/lib/core/files/attachments.js +3 -3
- package/dist-lib/lib/core/files/index.d.ts +2 -2
- package/dist-lib/lib/core/files/index.js +19 -19
- package/dist-lib/lib/core/files/knowledge.js +3 -3
- package/dist-lib/lib/core/files/preview/image.js +1 -1
- package/dist-lib/lib/core/files/preview/index.js +6 -6
- package/dist-lib/lib/core/files/processing/claims.js +1 -1
- package/dist-lib/lib/core/files/processing/document.js +5 -5
- package/dist-lib/lib/core/files/processing/index.js +8 -8
- package/dist-lib/lib/core/files/processing/ownership.js +1 -1
- package/dist-lib/lib/core/files/processing/protocol.js +3 -3
- package/dist-lib/lib/core/files/processing/source.js +1 -1
- package/dist-lib/lib/core/files/rag/artifact/codec.js +1 -1
- package/dist-lib/lib/core/files/rag/artifact/id.js +1 -1
- package/dist-lib/lib/core/files/rag/artifact/types.d.ts +4 -4
- package/dist-lib/lib/core/files/rag/build.js +2 -2
- package/dist-lib/lib/core/files/rag/chunk/chunking.js +2 -2
- package/dist-lib/lib/core/files/rag/document-types.d.ts +3 -3
- package/dist-lib/lib/core/files/rag/extract/document-types.d.ts +9 -9
- package/dist-lib/lib/core/files/rag/extract/extract.js +7 -7
- package/dist-lib/lib/core/files/rag/extract/html-text.js +1 -1
- package/dist-lib/lib/core/files/rag/extract/office-collabora.js +2 -2
- package/dist-lib/lib/core/files/rag/extract/pdf-platform.js +1 -1
- package/dist-lib/lib/core/files/rag/extract/pdf-text.js +1 -1
- package/dist-lib/lib/core/files/rag/extract/text-decoding.js +1 -1
- package/dist-lib/lib/core/files/rag/extract/types.d.ts +2 -2
- package/dist-lib/lib/core/files/rag/index.js +22 -22
- package/dist-lib/lib/core/files/rag/load.js +5 -5
- package/dist-lib/lib/core/files/rag/policy.js +2 -2
- package/dist-lib/lib/core/files/rag/produce.js +5 -5
- package/dist-lib/lib/core/files/rag/retrieval/coverage.js +2 -2
- package/dist-lib/lib/core/files/rag/retrieval/diversity.js +1 -1
- package/dist-lib/lib/core/files/rag/retrieval/floor.js +2 -2
- package/dist-lib/lib/core/files/rag/retrieval/format.js +1 -1
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +18 -11
- package/dist-lib/lib/core/files/rag/retrieval/knowledge.js +5 -5
- package/dist-lib/lib/core/files/rag/retrieval/scoring.js +2 -2
- package/dist-lib/lib/core/files/rag/retrieval/search.js +4 -4
- package/dist-lib/lib/core/files/rag/retrieval/selection.js +2 -2
- package/dist-lib/lib/core/files/rag/retrieval/sources.js +2 -2
- package/dist-lib/lib/core/files/rag/retrieval/terms.js +1 -1
- package/dist-lib/lib/core/files/rag/retrieval/web-sources.js +1 -1
- package/dist-lib/lib/core/files/records/chunks.js +1 -1
- package/dist-lib/lib/core/files/records/index.js +8 -8
- package/dist-lib/lib/core/files/records/knowledge.js +2 -2
- package/dist-lib/lib/core/files/records/output.js +1 -1
- package/dist-lib/lib/core/files/records/reclaim.js +5 -5
- package/dist-lib/lib/core/files/records/routing.js +7 -7
- package/dist-lib/lib/core/files/store/blob.js +2 -2
- package/dist-lib/lib/core/files/store/index.js +7 -7
- package/dist-lib/lib/core/files/store/reference.js +2 -2
- package/dist-lib/lib/core/files/store/server.js +1 -1
- package/dist-lib/lib/core/files/store/sweep.js +1 -1
- package/dist-lib/lib/core/files/upload-input.js +2 -2
- package/dist-lib/lib/core/files/upload.d.ts +1 -1
- package/dist-lib/lib/core/files/upload.js +6 -6
- package/dist-lib/lib/core/harness-loan.d.ts +29 -0
- package/dist-lib/lib/core/harness-loan.js +187 -0
- package/dist-lib/lib/core/helpers/index.d.ts +2 -1
- package/dist-lib/lib/core/helpers/index.js +4 -4
- package/dist-lib/lib/core/hosted-agents.js +2 -2
- package/dist-lib/lib/core/identity.d.ts +2 -0
- package/dist-lib/lib/core/identity.js +4 -2
- package/dist-lib/lib/core/invite.d.ts +1 -0
- package/dist-lib/lib/core/invite.js +4 -2
- package/dist-lib/lib/core/local/index.d.ts +12 -3
- package/dist-lib/lib/core/local/index.js +81 -16
- package/dist-lib/lib/core/membership.d.ts +3 -0
- package/dist-lib/lib/core/membership.js +15 -1
- package/dist-lib/lib/core/mesh-seed-handoff.js +1 -1
- package/dist-lib/lib/core/mesh.d.ts +9 -3
- package/dist-lib/lib/core/mesh.js +41 -26
- package/dist-lib/lib/core/migrations/agent-catalog.js +1 -1
- package/dist-lib/lib/core/migrations/index.js +5 -3
- package/dist-lib/lib/core/migrations/membership.js +2 -2
- package/dist-lib/lib/core/migrations/seal.d.ts +3 -0
- package/dist-lib/lib/core/migrations/seal.js +30 -0
- package/dist-lib/lib/core/next-frame.js +1 -1
- package/dist-lib/lib/core/notification.js +1 -1
- package/dist-lib/lib/core/ota-config.js +1 -1
- package/dist-lib/lib/core/secret-handoff.js +1 -1
- package/dist-lib/lib/core/send.js +3 -3
- package/dist-lib/lib/core/skill-overlay-handoff.js +1 -1
- package/dist-lib/lib/core/skill-overlay-receiver.js +2 -2
- package/dist-lib/lib/core/skill-secrets.js +3 -3
- package/dist-lib/lib/core/sync/devices.js +1 -1
- package/dist-lib/lib/core/sync/index.js +8 -5
- package/dist-lib/lib/core/sync-status.js +1 -1
- package/dist-lib/lib/core/system-info.js +1 -1
- package/dist-lib/lib/core/tool-activity.js +2 -2
- package/dist-lib/lib/core/tool-configs.js +2 -2
- package/dist-lib/lib/core.d.ts +42 -3
- package/dist-lib/lib/core.js +543 -100
- package/dist-lib/lib/credential-pusher.js +4 -4
- package/dist-lib/lib/deadline.js +1 -1
- package/dist-lib/lib/fs-drive-bridge.js +5 -3
- package/dist-lib/lib/integrations/index.js +3 -3
- package/dist-lib/lib/integrations/oauth-providers.js +1 -1
- package/dist-lib/lib/integrations/setup-routes.d.ts +5 -5
- package/dist-lib/lib/integrations/setup-routes.js +3 -3
- package/dist-lib/lib/knowledge-search.js +1 -1
- package/dist-lib/lib/log.js +3 -3
- package/dist-lib/lib/mesh-scoped-engine.d.ts +3 -0
- package/dist-lib/lib/mesh-scoped-engine.js +101 -0
- package/dist-lib/lib/model-context.d.ts +2 -2
- package/dist-lib/lib/model-context.js +1 -1
- package/dist-lib/lib/model-download.d.ts +2 -0
- package/dist-lib/lib/model-download.js +26 -11
- package/dist-lib/lib/oauth/asana.js +3 -3
- package/dist-lib/lib/oauth/browser-connect.js +1 -1
- package/dist-lib/lib/oauth/client.js +2 -2
- package/dist-lib/lib/oauth/common.d.ts +1 -1
- package/dist-lib/lib/oauth/common.js +1 -1
- package/dist-lib/lib/oauth/flow-core.js +3 -3
- package/dist-lib/lib/oauth/flow.js +2 -2
- package/dist-lib/lib/oauth/google.js +4 -4
- package/dist-lib/lib/oauth/host.js +3 -3
- package/dist-lib/lib/oauth/keys.js +1 -0
- package/dist-lib/lib/oauth/loopback.js +1 -1
- package/dist-lib/lib/oauth/notion.js +3 -3
- package/dist-lib/lib/oauth/providers.js +1 -1
- package/dist-lib/lib/oauth/resolve.js +1 -1
- package/dist-lib/lib/oauth/spotify.js +4 -3
- package/dist-lib/lib/oauth/token-exchange.js +1 -1
- package/dist-lib/lib/oauth/verify.d.ts +8 -0
- package/dist-lib/lib/oauth/verify.js +58 -0
- package/dist-lib/lib/oauth.client.js +2 -2
- package/dist-lib/lib/oauth.d.ts +1 -0
- package/dist-lib/lib/oauth.js +13 -12
- package/dist-lib/lib/run-notices.d.ts +7 -7
- package/dist-lib/lib/run-transcript.js +1 -1
- package/dist-lib/schema/build.js +12 -6
- package/dist-lib/schema/content.d.ts +11 -11
- package/dist-lib/schema/engine.js +193 -30
- package/dist-lib/schema/field-order.js +2 -2
- package/dist-lib/schema/local.js +18 -4
- package/dist-lib/schema/qvac.d.ts +3 -0
- package/dist-lib/schema/qvac.js +22 -6
- package/dist-lib/spec/bind.js +41 -0
- package/dist-lib/spec/calls.js +12 -0
- package/dist-lib/spec/capabilities.d.ts +36 -12
- package/dist-lib/spec/hrpc/hrpc.json +161 -5
- package/dist-lib/spec/hrpc/index.js +154 -9
- package/dist-lib/spec/hrpc/messages.js +549 -129
- package/dist-lib/spec/hyperschema/index.js +549 -129
- package/dist-lib/spec/hyperschema/schema.json +370 -40
- package/dist-lib/spec/hyperschema/types.d.ts +85 -1
- package/dist-lib/spec/local/hyperdb/db.json +15 -0
- package/dist-lib/spec/local/hyperdb/index.js +70 -1
- package/dist-lib/spec/local/hyperdb/messages.js +300 -117
- package/dist-lib/spec/local/hyperschema/index.js +97 -4
- package/dist-lib/spec/local/hyperschema/schema.json +58 -1
- package/dist-lib/spec/local/hyperschema/types.d.ts +14 -0
- package/dist-lib/spec/mesh/hyperdb/messages.js +393 -288
- package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +6 -0
- package/dist-lib/spec/mesh/hyperdispatch/index.js +18 -1
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +176 -85
- package/dist-lib/spec/mesh/hyperschema/index.js +176 -85
- package/dist-lib/spec/mesh/hyperschema/schema.json +71 -21
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +14 -1
- package/package.json +14 -8
- package/tui/README.md +7 -0
- package/tui/app.mjs +633 -55
- package/tui/lib/busy-words.mjs +57 -5
- package/tui/lib/export.mjs +1 -0
- package/tui/lib/render.mjs +25 -2
- package/tui/lib/selection.mjs +16 -0
- package/tui/lib/usage.mjs +54 -0
- package/tui/main.mjs +5 -2
package/dist-lib/lib/core.js
CHANGED
|
@@ -10,40 +10,44 @@ import Top from 'process-top';
|
|
|
10
10
|
import ReadyGuard from 'ready-guard';
|
|
11
11
|
import ReadyResource from 'ready-resource';
|
|
12
12
|
import ScopeLock from 'scope-lock';
|
|
13
|
-
import { createApi } from
|
|
14
|
-
import { NO_SUCH_MESH } from
|
|
15
|
-
import { BLIND_PEER_KEYS, BLIND_RELAY_KEYS } from
|
|
16
|
-
import { CoreBlobServer, parseBlobReferenceCoreKey, MemoryVectorIndex } from
|
|
17
|
-
import { removeChatAttachments, removeChatKnowledge } from
|
|
18
|
-
import { createFsDriveHost } from
|
|
19
|
-
import { sweepDriveStaging } from
|
|
20
|
-
import { closeCollaboraWorker } from
|
|
21
|
-
import { decodeMeshInvite, encodeMeshInvite } from
|
|
22
|
-
import { openLocalStore } from
|
|
23
|
-
import { getAgent, ownDefaultAgents } from
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
13
|
+
import { createApi } from './api/index.js';
|
|
14
|
+
import { NO_SUCH_MESH } from './api/current-mesh.js';
|
|
15
|
+
import { BLIND_PEER_KEYS, BLIND_RELAY_KEYS } from './core/blind-peers.js';
|
|
16
|
+
import { CoreBlobServer, parseBlobReferenceCoreKey, MemoryVectorIndex } from './core/files/index.js';
|
|
17
|
+
import { removeChatAttachments, removeChatKnowledge } from './core/chat.js';
|
|
18
|
+
import { createFsDriveHost } from './core/fs-drives.js';
|
|
19
|
+
import { sweepDriveStaging } from './fs-drive-bridge.js';
|
|
20
|
+
import { closeCollaboraWorker } from './collabora/worker.js';
|
|
21
|
+
import { decodeMeshInvite, encodeMeshInvite } from './core/invite.js';
|
|
22
|
+
import { openLocalStore } from './core/local/index.js';
|
|
23
|
+
import { getAgent, ownDefaultAgents } from './core/agent.js';
|
|
24
|
+
import { countContents, migrateContents, withArchivedMesh } from './core/archived-mesh.js';
|
|
25
|
+
import { HostedAgents } from './core/hosted-agents.js';
|
|
26
|
+
import { HarnessLoan } from './core/harness-loan.js';
|
|
27
|
+
import { duplexPair } from '@qvac/harness/transport';
|
|
28
|
+
import { MeshSeedHandoff } from './core/mesh-seed-handoff.js';
|
|
29
|
+
import { SecretHandoff } from './core/secret-handoff.js';
|
|
30
|
+
import { SkillOverlayHandoff } from './core/skill-overlay-handoff.js';
|
|
31
|
+
import { createSkillOverlayReceiver } from './core/skill-overlay-receiver.js';
|
|
32
|
+
import { createSkillSecretReceiver, HOST_REVOKED, NO_SUCH_AGENT, NOT_THE_HOST } from './core/skill-secrets.js';
|
|
33
|
+
import { attestMemberClaim, claimAttestation, openIdentity } from './core/identity.js';
|
|
34
|
+
import { openRecoveryCore, publishRecovery, readRecovery, recoveryKeys } from './core/account-recovery.js';
|
|
35
|
+
import { attestUnattestedDevices, claimOwnMembership, renameFoundedMember } from './core/membership.js';
|
|
36
|
+
import { openDeviceInvites } from './core/device-invites.js';
|
|
37
|
+
import { runMigrations } from './core/migrations/index.js';
|
|
38
|
+
import { advertiseDeviceVersion } from './core/devices.js';
|
|
39
|
+
import { OtaConfigReader, configCoreFor, resolveConfigChannel, vendoredMinSupportedVersion } from './core/ota-config.js';
|
|
40
|
+
import { updateRequired } from './core/min-version.js';
|
|
41
|
+
import { PendingDepartures } from './core/departures.js';
|
|
42
|
+
import { buildDefaultSeed } from './core/helpers/index.js';
|
|
43
|
+
import { Mesh } from './core/mesh.js';
|
|
44
|
+
import { raceResource } from './race-resource.js';
|
|
45
|
+
import { createSystemInfoSampler } from './core/system-info.js';
|
|
46
|
+
import { oauthStateKeyFor } from './credential-pusher.js';
|
|
47
|
+
import { setLogger } from './logger.js';
|
|
44
48
|
import { settleOnClose } from '@qvac/harness/rpc';
|
|
45
|
-
import { openLocalSpec } from
|
|
46
|
-
import { unref } from
|
|
49
|
+
import { openLocalSpec } from './spec-loader.js';
|
|
50
|
+
import { unref } from './unref.js';
|
|
47
51
|
import { local } from '../spec/index.js';
|
|
48
52
|
const QvacState = local.getEnum('@local/qvac-state');
|
|
49
53
|
const top = new Top();
|
|
@@ -54,6 +58,12 @@ const MESH_ID = /^[0-9a-f]{64}$/;
|
|
|
54
58
|
const MESH_BELOW_FLOOR = 'Build is below the mesh floor';
|
|
55
59
|
const LEAVE_HOME_REFUSED = 'Your account cannot be left while other meshes remain';
|
|
56
60
|
const ROOM_WITHOUT_ACCOUNT = 'A room needs an account mesh to be recorded in';
|
|
61
|
+
const NO_WRITABLE_ACCOUNT = 'The account mesh is not writable';
|
|
62
|
+
const NOT_AN_ARCHIVED_ACCOUNT = 'Not an account this device left';
|
|
63
|
+
const NO_ACCOUNT_TO_RECOVER = 'This device has no account to make recoverable';
|
|
64
|
+
const PHRASE_NOT_OURS = 'The phrase does not derive the identity this device holds';
|
|
65
|
+
const NO_RECOVERY_RECORD = 'No recovery record was found for this phrase';
|
|
66
|
+
const RECOVERY_WAIT_MS = 30_000;
|
|
57
67
|
export const MEMBER_INVITE_HOME_REFUSED = 'An account mesh cannot be invited into';
|
|
58
68
|
export const DEVICE_INVITE_ROOM_REFUSED = 'Only an account mesh can take a device invite';
|
|
59
69
|
export const INVITE_ACCOUNT_UNREADABLE = 'This device cannot reach its account to check';
|
|
@@ -83,6 +93,9 @@ export class Core extends ReadyResource {
|
|
|
83
93
|
_otaConfigCore;
|
|
84
94
|
_otaConfig = null;
|
|
85
95
|
_configPeering = null;
|
|
96
|
+
_recoveryCore = null;
|
|
97
|
+
_recoverySigner = null;
|
|
98
|
+
_recoveryPeering = null;
|
|
86
99
|
_localDevice;
|
|
87
100
|
_blindPeerKeys;
|
|
88
101
|
_blindPeeringOpts;
|
|
@@ -138,6 +151,8 @@ export class Core extends ReadyResource {
|
|
|
138
151
|
_blobServer = null;
|
|
139
152
|
_wakeup;
|
|
140
153
|
_meshSeedHandoff;
|
|
154
|
+
_harnessLoan;
|
|
155
|
+
_serveLoanedHarness = null;
|
|
141
156
|
_following = new Set();
|
|
142
157
|
_secretHandoff;
|
|
143
158
|
_skillOverlayHandoff;
|
|
@@ -245,6 +260,7 @@ export class Core extends ReadyResource {
|
|
|
245
260
|
this._meshSeedHandoff = new MeshSeedHandoff({
|
|
246
261
|
onrequest: (request, from) => this._serveMeshSeed(request, from)
|
|
247
262
|
});
|
|
263
|
+
this._harnessLoan = new HarnessLoan({ onborrow: (from) => this._lendHarness(from) });
|
|
248
264
|
this._minting = false;
|
|
249
265
|
this._leaving = false;
|
|
250
266
|
this._kicked = false;
|
|
@@ -312,11 +328,12 @@ export class Core extends ReadyResource {
|
|
|
312
328
|
await this._openOtaConfig();
|
|
313
329
|
await this._openBootMesh();
|
|
314
330
|
this._systemInfo = createSystemInfoSampler();
|
|
331
|
+
const meshStatus = this._meshStatusSource();
|
|
315
332
|
this._api = createApi({
|
|
316
333
|
state: this.local,
|
|
317
334
|
notificationLifetime: this,
|
|
318
|
-
mesh:
|
|
319
|
-
meshStatus
|
|
335
|
+
mesh: this._currentMeshAccessor(meshStatus),
|
|
336
|
+
meshStatus,
|
|
320
337
|
network: this._networkStatusSource(),
|
|
321
338
|
diagnostics: this._diagnosticsSource(),
|
|
322
339
|
logs: this._logSource(),
|
|
@@ -325,6 +342,7 @@ export class Core extends ReadyResource {
|
|
|
325
342
|
ragIndex: () => this._activeEntry()?.vectorIndex ?? null,
|
|
326
343
|
ragEmbed: () => this._indexedEmbedder,
|
|
327
344
|
platform: () => this._localDevice?.platform ?? null,
|
|
345
|
+
computeLender: () => this._computeLender(),
|
|
328
346
|
pushSkillSecret: (request) => this.pushSkillSecret(request),
|
|
329
347
|
listModels: this._hostsModelSource || this._listModels
|
|
330
348
|
? (options) => this._listModels?.(options) ?? Promise.resolve({ models: [] })
|
|
@@ -681,6 +699,8 @@ export class Core extends ReadyResource {
|
|
|
681
699
|
await this._departures.suspend();
|
|
682
700
|
if (this._configPeering)
|
|
683
701
|
await this._configPeering.suspend();
|
|
702
|
+
if (this._recoveryPeering)
|
|
703
|
+
await this._recoveryPeering.suspend();
|
|
684
704
|
if (this._swarm)
|
|
685
705
|
await this._swarm.suspend();
|
|
686
706
|
if (this._blobServer)
|
|
@@ -709,6 +729,8 @@ export class Core extends ReadyResource {
|
|
|
709
729
|
await this._swarm.resume();
|
|
710
730
|
if (this._configPeering)
|
|
711
731
|
await this._configPeering.resume();
|
|
732
|
+
if (this._recoveryPeering)
|
|
733
|
+
await this._recoveryPeering.resume();
|
|
712
734
|
for (const { mesh } of this._meshes.values())
|
|
713
735
|
await mesh.resume();
|
|
714
736
|
if (this._departures)
|
|
@@ -753,6 +775,7 @@ export class Core extends ReadyResource {
|
|
|
753
775
|
await this._discardCandidateMesh();
|
|
754
776
|
await this._departures?.close();
|
|
755
777
|
this._departures = null;
|
|
778
|
+
await this._closeRecovery();
|
|
756
779
|
await this._closeConfigPeering();
|
|
757
780
|
await this._closeOtaConfig();
|
|
758
781
|
await this._fsDrives?.close();
|
|
@@ -827,6 +850,7 @@ export class Core extends ReadyResource {
|
|
|
827
850
|
const mesh = new Mesh(this.store, {
|
|
828
851
|
seed: session.seed,
|
|
829
852
|
key: session.baseKey ?? null,
|
|
853
|
+
compute: session.compute,
|
|
830
854
|
deviceId,
|
|
831
855
|
writerSeed: session.writerSeed,
|
|
832
856
|
logger: this._log,
|
|
@@ -838,8 +862,16 @@ export class Core extends ReadyResource {
|
|
|
838
862
|
try {
|
|
839
863
|
await mesh.ready();
|
|
840
864
|
await raceResource(mesh.autobee, (async () => {
|
|
841
|
-
|
|
865
|
+
const birth = await this._mintBirthMember(mesh, deviceId, session);
|
|
866
|
+
await mesh.appendBirthOp(this._deviceKeyPair, this._localDevice ?? undefined, birth?.member, undefined, { room });
|
|
842
867
|
await this.local.recordMesh(deviceId, mesh.key, session, { account });
|
|
868
|
+
if (account && birth?.mnemonic) {
|
|
869
|
+
await this._publishRecovery(birth.mnemonic, {
|
|
870
|
+
meshKey: mesh.key,
|
|
871
|
+
seed: session.seed,
|
|
872
|
+
createdAt: Date.now()
|
|
873
|
+
});
|
|
874
|
+
}
|
|
843
875
|
})(), 'mesh');
|
|
844
876
|
}
|
|
845
877
|
catch (err) {
|
|
@@ -858,22 +890,203 @@ export class Core extends ReadyResource {
|
|
|
858
890
|
this._identityPublicKey = identity.publicKey;
|
|
859
891
|
this._holdIdentityPhrase(mnemonic);
|
|
860
892
|
return {
|
|
861
|
-
member: {
|
|
862
|
-
|
|
893
|
+
member: {
|
|
894
|
+
member: {
|
|
895
|
+
id: identity.publicKey,
|
|
896
|
+
name: identity.displayName ?? local.name,
|
|
897
|
+
joinedAt: now,
|
|
898
|
+
updatedAt: now
|
|
899
|
+
},
|
|
900
|
+
proof: identity.proof
|
|
901
|
+
},
|
|
902
|
+
mnemonic
|
|
863
903
|
};
|
|
864
904
|
}
|
|
905
|
+
async publishAccountRecovery(mnemonic) {
|
|
906
|
+
if (!this.opened)
|
|
907
|
+
await this.ready();
|
|
908
|
+
const home = await this.local.homeMesh(this._deviceKeyPair.publicKey);
|
|
909
|
+
if (!home)
|
|
910
|
+
throw new Error(NO_ACCOUNT_TO_RECOVER);
|
|
911
|
+
return this._publishRecovery(mnemonic, {
|
|
912
|
+
meshKey: home.key,
|
|
913
|
+
seed: home.seed,
|
|
914
|
+
createdAt: Date.now()
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
async accountRecoverable() {
|
|
918
|
+
if (!this.opened)
|
|
919
|
+
await this.ready();
|
|
920
|
+
const home = await this.local.homeMesh(this._deviceKeyPair.publicKey);
|
|
921
|
+
return home !== null && (await this.local.readAccountRecovery(home.key)) !== null;
|
|
922
|
+
}
|
|
923
|
+
async _publishRecovery(mnemonic, record) {
|
|
924
|
+
const identity = await openIdentity(mnemonic);
|
|
925
|
+
if (!this._identityPublicKey?.equals(identity.identityPublicKey)) {
|
|
926
|
+
throw new Error(PHRASE_NOT_OURS);
|
|
927
|
+
}
|
|
928
|
+
const core = await this._openOwnRecoveryCore(recoveryKeys(identity));
|
|
929
|
+
const appended = await publishRecovery(core, record);
|
|
930
|
+
const held = await readRecovery(core);
|
|
931
|
+
if (held?.meshKey.equals(record.meshKey))
|
|
932
|
+
await this._markRecoverable(held, core);
|
|
933
|
+
this._peerRecoveryCore(core);
|
|
934
|
+
return appended;
|
|
935
|
+
}
|
|
936
|
+
_markRecoverable(record, core) {
|
|
937
|
+
return this.local.recordAccountRecovery({
|
|
938
|
+
meshKey: record.meshKey,
|
|
939
|
+
coreKey: core.key,
|
|
940
|
+
publishedAt: record.createdAt
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
async _openOwnRecoveryCore(keys) {
|
|
944
|
+
const signer = keys.coreKeyPair.publicKey;
|
|
945
|
+
if (this._recoveryCore && this._recoverySigner?.equals(signer))
|
|
946
|
+
return this._recoveryCore;
|
|
947
|
+
const core = openRecoveryCore(this.store, keys);
|
|
948
|
+
await core.ready();
|
|
949
|
+
await this._adoptRecoveryCore(core, signer);
|
|
950
|
+
return core;
|
|
951
|
+
}
|
|
952
|
+
async _adoptRecoveryCore(core, signer) {
|
|
953
|
+
const previous = this._recoveryCore;
|
|
954
|
+
this._recoveryCore = core;
|
|
955
|
+
this._recoverySigner = signer;
|
|
956
|
+
await previous?.close();
|
|
957
|
+
}
|
|
958
|
+
async recoverAccount(mnemonic, { timeout = RECOVERY_WAIT_MS } = {}) {
|
|
959
|
+
await this._awaitMesh();
|
|
960
|
+
const identity = await openIdentity(mnemonic);
|
|
961
|
+
const keys = recoveryKeys(identity);
|
|
962
|
+
const core = openRecoveryCore(this.store, keys);
|
|
963
|
+
let record;
|
|
964
|
+
try {
|
|
965
|
+
record = await this._readRecovery(core, timeout);
|
|
966
|
+
}
|
|
967
|
+
catch (err) {
|
|
968
|
+
await core.close();
|
|
969
|
+
throw err;
|
|
970
|
+
}
|
|
971
|
+
await this._meshTransitionLock.lock();
|
|
972
|
+
let ownsTransition = false;
|
|
973
|
+
try {
|
|
974
|
+
if (this.closing)
|
|
975
|
+
throw new Error('Core is closing');
|
|
976
|
+
if (this._leaving || this._minting)
|
|
977
|
+
throw new Error('Mesh transition already in progress');
|
|
978
|
+
ownsTransition = true;
|
|
979
|
+
this._minting = true;
|
|
980
|
+
this._notifyStatus();
|
|
981
|
+
await this._recoverAccount(identity, record);
|
|
982
|
+
await this._markRecoverable(record, core);
|
|
983
|
+
await this._adoptRecoveryCore(core, keys.coreKeyPair.publicKey);
|
|
984
|
+
}
|
|
985
|
+
catch (err) {
|
|
986
|
+
await core.close();
|
|
987
|
+
throw err;
|
|
988
|
+
}
|
|
989
|
+
finally {
|
|
990
|
+
if (ownsTransition)
|
|
991
|
+
this._minting = false;
|
|
992
|
+
this._meshTransitionLock.unlock();
|
|
993
|
+
this._notifyStatus();
|
|
994
|
+
this._departures?.flush();
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
async _recoverAccount(identity, record) {
|
|
998
|
+
const deviceId = this._deviceKeyPair.publicKey;
|
|
999
|
+
const pooled = this._currentMesh(record.meshKey.toString('hex'));
|
|
1000
|
+
if (pooled?.writable) {
|
|
1001
|
+
if (!this._isActive(pooled))
|
|
1002
|
+
await this._handOffActive(pooled, this._activeEntry());
|
|
1003
|
+
}
|
|
1004
|
+
else {
|
|
1005
|
+
if (pooled)
|
|
1006
|
+
await this._retirePooledMesh(pooled);
|
|
1007
|
+
await this._joinMesh({ seed: record.seed, baseKey: record.meshKey, fastForward: null });
|
|
1008
|
+
}
|
|
1009
|
+
const mesh = this._currentMesh();
|
|
1010
|
+
if (!mesh?.key.equals(record.meshKey))
|
|
1011
|
+
throw new Error('the recovered account did not activate');
|
|
1012
|
+
if (this._identityPublicKey?.equals(identity.identityPublicKey))
|
|
1013
|
+
return;
|
|
1014
|
+
const proof = await identity.bootstrap(deviceId);
|
|
1015
|
+
const now = Date.now();
|
|
1016
|
+
await this.local.replaceIdentity({
|
|
1017
|
+
publicKey: identity.identityPublicKey,
|
|
1018
|
+
proof,
|
|
1019
|
+
createdAt: now
|
|
1020
|
+
});
|
|
1021
|
+
this._identityPublicKey = identity.identityPublicKey;
|
|
1022
|
+
await mesh.dispatch('attest-member-device', {
|
|
1023
|
+
deviceId,
|
|
1024
|
+
memberId: identity.identityPublicKey,
|
|
1025
|
+
proof,
|
|
1026
|
+
attestedAt: now
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
async _readRecovery(core, timeout) {
|
|
1030
|
+
await core.ready();
|
|
1031
|
+
this._peerRecoveryCore(core);
|
|
1032
|
+
try {
|
|
1033
|
+
const record = await readRecovery(core, { timeout });
|
|
1034
|
+
if (record)
|
|
1035
|
+
return record;
|
|
1036
|
+
}
|
|
1037
|
+
catch (err) {
|
|
1038
|
+
this._log?.warn(['p2p', 'mesh'], 'no blind peer served a recovery record', err);
|
|
1039
|
+
}
|
|
1040
|
+
throw new Error(NO_RECOVERY_RECORD);
|
|
1041
|
+
}
|
|
1042
|
+
_peerRecoveryCore(core) {
|
|
1043
|
+
if (!this._swarm || this.closing)
|
|
1044
|
+
return;
|
|
1045
|
+
const keys = this._resolveBlindPeerKeys();
|
|
1046
|
+
if (keys.length === 0)
|
|
1047
|
+
return;
|
|
1048
|
+
if (!this._recoveryPeering) {
|
|
1049
|
+
this._recoveryPeering = new BlindPeering(this._swarm.dht, this.store, {
|
|
1050
|
+
pick: keys.length,
|
|
1051
|
+
...this._blindPeeringOpts
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
this._recoveryPeering.addCoreBackground(core, { keys });
|
|
1055
|
+
this._log?.info(['p2p', 'mesh'], 'blind peering an account recovery core');
|
|
1056
|
+
}
|
|
1057
|
+
async _closeRecovery() {
|
|
1058
|
+
const peering = this._recoveryPeering;
|
|
1059
|
+
const core = this._recoveryCore;
|
|
1060
|
+
this._recoveryPeering = null;
|
|
1061
|
+
this._recoveryCore = null;
|
|
1062
|
+
this._recoverySigner = null;
|
|
1063
|
+
await peering?.close();
|
|
1064
|
+
await core?.close();
|
|
1065
|
+
}
|
|
865
1066
|
async _joinBirthMember(mesh, deviceId) {
|
|
866
1067
|
const local = this._localDevice;
|
|
867
1068
|
if (!local || mesh.localLength > 0)
|
|
868
1069
|
return undefined;
|
|
869
1070
|
const now = Date.now();
|
|
1071
|
+
const attestation = claimAttestation(mesh.publicKey, deviceId, mesh.localWriterKey);
|
|
1072
|
+
const known = await this._knownMember(mesh);
|
|
1073
|
+
if (known) {
|
|
1074
|
+
return {
|
|
1075
|
+
member: { id: known.id, name: known.name, joinedAt: now, updatedAt: now },
|
|
1076
|
+
proof: await attestMemberClaim(attestation, this._deviceKeyPair, known.proof)
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
870
1079
|
const { identity, mnemonic } = await this.local.ensureIdentity(deviceId, now);
|
|
871
1080
|
this._identityPublicKey = identity.publicKey;
|
|
872
1081
|
this._holdIdentityPhrase(mnemonic);
|
|
873
|
-
const attestation = claimAttestation(mesh.publicKey, deviceId, mesh.localWriterKey);
|
|
874
1082
|
const proof = await attestMemberClaim(attestation, this._deviceKeyPair, identity.proof);
|
|
875
1083
|
return {
|
|
876
|
-
member: {
|
|
1084
|
+
member: {
|
|
1085
|
+
id: identity.publicKey,
|
|
1086
|
+
name: identity.displayName ?? local.name,
|
|
1087
|
+
joinedAt: now,
|
|
1088
|
+
updatedAt: now
|
|
1089
|
+
},
|
|
877
1090
|
proof
|
|
878
1091
|
};
|
|
879
1092
|
}
|
|
@@ -1002,6 +1215,7 @@ export class Core extends ReadyResource {
|
|
|
1002
1215
|
}
|
|
1003
1216
|
await this._claimOwnMembership(mesh, context);
|
|
1004
1217
|
await attestUnattestedDevices(mesh, context, this._deviceInvites);
|
|
1218
|
+
await this._renameFoundedMember(mesh, context);
|
|
1005
1219
|
}
|
|
1006
1220
|
catch (err) {
|
|
1007
1221
|
this._log?.warn(['p2p', 'mesh'], 'settling membership failed', err);
|
|
@@ -1010,6 +1224,11 @@ export class Core extends ReadyResource {
|
|
|
1010
1224
|
entry.memberLock.unlock();
|
|
1011
1225
|
}
|
|
1012
1226
|
}
|
|
1227
|
+
async _renameFoundedMember(mesh, context) {
|
|
1228
|
+
const identity = await this.local.readIdentity();
|
|
1229
|
+
if (identity)
|
|
1230
|
+
await renameFoundedMember(mesh, context, identity);
|
|
1231
|
+
}
|
|
1013
1232
|
async _claimOwnMembership(mesh, context) {
|
|
1014
1233
|
if (mesh.ourMemberId)
|
|
1015
1234
|
return;
|
|
@@ -1024,9 +1243,14 @@ export class Core extends ReadyResource {
|
|
|
1024
1243
|
continue;
|
|
1025
1244
|
const own = await entry.mesh.view
|
|
1026
1245
|
.get('@qvac/devices', { id: deviceId })
|
|
1027
|
-
.catch(
|
|
1028
|
-
if (own?.memberId
|
|
1029
|
-
|
|
1246
|
+
.catch(noop);
|
|
1247
|
+
if (!own?.memberId || !own.memberProof)
|
|
1248
|
+
continue;
|
|
1249
|
+
const member = await entry.mesh.view
|
|
1250
|
+
.get('@qvac/members', { id: own.memberId })
|
|
1251
|
+
.catch(noop);
|
|
1252
|
+
if (member)
|
|
1253
|
+
return { id: member.id, name: member.name, proof: own.memberProof };
|
|
1030
1254
|
}
|
|
1031
1255
|
return null;
|
|
1032
1256
|
}
|
|
@@ -1289,7 +1513,7 @@ export class Core extends ReadyResource {
|
|
|
1289
1513
|
}
|
|
1290
1514
|
}
|
|
1291
1515
|
async _joinParkedMesh(invite, source, deviceId) {
|
|
1292
|
-
const session = this.local.createCandidateSession(invite.seed, invite.baseKey);
|
|
1516
|
+
const session = this.local.createCandidateSession(invite.seed, invite.baseKey, invite.compute);
|
|
1293
1517
|
let candidate;
|
|
1294
1518
|
try {
|
|
1295
1519
|
candidate = await this._openCandidateMesh(invite, session);
|
|
@@ -1319,11 +1543,18 @@ export class Core extends ReadyResource {
|
|
|
1319
1543
|
await this._retireMesh(candidate).catch((err) => this._log?.warn(['p2p', 'mesh'], 'withholding the joined mesh failed', err));
|
|
1320
1544
|
return;
|
|
1321
1545
|
}
|
|
1322
|
-
|
|
1546
|
+
if (candidate.compute) {
|
|
1547
|
+
this._wireMesh(this._poolEntry(candidate));
|
|
1548
|
+
this._bringMeshOnline(candidate);
|
|
1549
|
+
this._notifyStatus();
|
|
1550
|
+
}
|
|
1551
|
+
else {
|
|
1552
|
+
await this._handOffActive(candidate, outgoing);
|
|
1553
|
+
}
|
|
1323
1554
|
void this._departures?.drop(candidate.key).catch(noop);
|
|
1324
1555
|
void this._advertiseDeviceProfile(candidate, deviceId);
|
|
1325
1556
|
void this._settleMembership(candidate, { migrate: true });
|
|
1326
|
-
if (invite.memberInvite) {
|
|
1557
|
+
if (invite.memberInvite && !candidate.compute) {
|
|
1327
1558
|
void this._recordJoinedRoom(candidate.key);
|
|
1328
1559
|
void this._seedMemberDefaults(candidate);
|
|
1329
1560
|
}
|
|
@@ -1333,13 +1564,11 @@ export class Core extends ReadyResource {
|
|
|
1333
1564
|
const account = (await this._homeMeshKey()) ?? source?.key;
|
|
1334
1565
|
const rows = (await this.local.listMeshes()).filter((row) => !row.key.equals(joined));
|
|
1335
1566
|
const rooms = rows.filter((row) => !account?.equals(row.key));
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
for (const room of rooms)
|
|
1339
|
-
await this._releaseJoinedRoom(room.key, registry);
|
|
1567
|
+
if (account)
|
|
1568
|
+
await this._accountMesh();
|
|
1340
1569
|
for (const room of rooms)
|
|
1341
1570
|
await this._departIfPooled(room.key, 'room');
|
|
1342
|
-
await this.local.adoptHomeMesh(this._deviceKeyPair.publicKey, joined);
|
|
1571
|
+
await this.local.adoptHomeMesh(this._deviceKeyPair.publicKey, joined, { account });
|
|
1343
1572
|
if (account)
|
|
1344
1573
|
await this._departIfPooled(account, 'account');
|
|
1345
1574
|
}
|
|
@@ -1377,7 +1606,10 @@ export class Core extends ReadyResource {
|
|
|
1377
1606
|
if (!this._isPooled(mesh) || (await this._hasOwnDefaultAgent(mesh)))
|
|
1378
1607
|
return;
|
|
1379
1608
|
const deviceId = this._deviceKeyPair.publicKey;
|
|
1380
|
-
|
|
1609
|
+
const member = mesh.ourMemberId
|
|
1610
|
+
? await mesh.view.get('@qvac/members', { id: mesh.ourMemberId })
|
|
1611
|
+
: null;
|
|
1612
|
+
await mesh.dispatch('seed-defaults', buildDefaultSeed({ id: deviceId, recommendedModelName: local.recommendedModelName }, [], member?.name ?? local.name));
|
|
1381
1613
|
}
|
|
1382
1614
|
catch (error) {
|
|
1383
1615
|
this._log?.warn(['p2p', 'mesh'], 'seeding this member defaults in the room failed', error);
|
|
@@ -1431,7 +1663,7 @@ export class Core extends ReadyResource {
|
|
|
1431
1663
|
return null;
|
|
1432
1664
|
const home = await this._homeMeshKey();
|
|
1433
1665
|
const held = home ? this._currentMesh(home.toString('hex')) : null;
|
|
1434
|
-
const mesh = home ? await this._openPooledMesh(home.toString('hex')).catch(
|
|
1666
|
+
const mesh = home ? await this._openPooledMesh(home.toString('hex')).catch(noop) : null;
|
|
1435
1667
|
if (mesh && !mesh.writable) {
|
|
1436
1668
|
await Promise.race([mesh.waitForWritable(), this._closeSignal, after(ACCOUNT_WRITABLE_MS)]);
|
|
1437
1669
|
}
|
|
@@ -1450,6 +1682,7 @@ export class Core extends ReadyResource {
|
|
|
1450
1682
|
const candidate = new Mesh(this.store, {
|
|
1451
1683
|
seed: session.seed,
|
|
1452
1684
|
key: session.baseKey ?? null,
|
|
1685
|
+
compute: session.compute,
|
|
1453
1686
|
deviceId: this._deviceKeyPair.publicKey,
|
|
1454
1687
|
writerSeed: session.writerSeed,
|
|
1455
1688
|
logger: this._log,
|
|
@@ -1486,13 +1719,10 @@ export class Core extends ReadyResource {
|
|
|
1486
1719
|
const member = invite.memberInvite
|
|
1487
1720
|
? await this._joinBirthMember(candidate, this._deviceKeyPair.publicKey)
|
|
1488
1721
|
: undefined;
|
|
1489
|
-
const claim =
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
: { memberId: invite.memberId, inviteNonce: invite.inviteNonce })
|
|
1494
|
-
};
|
|
1495
|
-
await candidate.appendBirthOp(this._deviceKeyPair.publicKey, this._localDevice ?? undefined, member, claim);
|
|
1722
|
+
const claim = member || !invite.memberId
|
|
1723
|
+
? undefined
|
|
1724
|
+
: { memberId: invite.memberId, inviteNonce: invite.inviteNonce };
|
|
1725
|
+
await candidate.appendBirthOp(this._deviceKeyPair, this._localDevice ?? undefined, member, claim);
|
|
1496
1726
|
this._throwIfJoinCanceled();
|
|
1497
1727
|
if (!candidate.key.equals(invite.baseKey)) {
|
|
1498
1728
|
throw new Error('Device is not permitted to join the invited mesh');
|
|
@@ -1587,7 +1817,9 @@ export class Core extends ReadyResource {
|
|
|
1587
1817
|
entry.handlers = handlers;
|
|
1588
1818
|
mesh.on('kicked', () => this._onKicked(mesh));
|
|
1589
1819
|
mesh.on('unattested-device', () => void this._settleMembership(mesh));
|
|
1820
|
+
mesh.on('members-dirty', () => void this._revalidateLoans());
|
|
1590
1821
|
mesh.on('rooms-dirty', () => void this._followJoinedRooms(mesh));
|
|
1822
|
+
mesh.on('membership-tallied', () => this._notifyStatus());
|
|
1591
1823
|
mesh.on('membership', (own) => {
|
|
1592
1824
|
void this._recordMemberProof(mesh, own);
|
|
1593
1825
|
void this._followJoinedRooms(mesh);
|
|
@@ -1868,7 +2100,7 @@ export class Core extends ReadyResource {
|
|
|
1868
2100
|
for (const row of [...rows].sort((a, b) => preferred(b) - preferred(a))) {
|
|
1869
2101
|
const meshId = row.key.toString('hex');
|
|
1870
2102
|
const held = this._currentMesh(meshId);
|
|
1871
|
-
const mesh = await this._openPooledMesh(meshId).catch(
|
|
2103
|
+
const mesh = await this._openPooledMesh(meshId).catch(noop);
|
|
1872
2104
|
if (mesh?.writable)
|
|
1873
2105
|
return mesh;
|
|
1874
2106
|
if (mesh && !held)
|
|
@@ -1881,21 +2113,81 @@ export class Core extends ReadyResource {
|
|
|
1881
2113
|
await this.ready();
|
|
1882
2114
|
const home = await this._homeMeshKey();
|
|
1883
2115
|
const rows = await this.local.listMeshes();
|
|
1884
|
-
const labels = await this._meshLabels(home);
|
|
1885
|
-
return { meshes: rows.map((row) => this._meshEntry(row, home, labels)) };
|
|
1886
|
-
}
|
|
1887
|
-
async _meshLabels(home) {
|
|
1888
|
-
const labels = new Map();
|
|
1889
2116
|
const registry = home ? this._currentMesh(home.toString('hex')) : null;
|
|
1890
|
-
const
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
2117
|
+
const rooms = registry ? await this._ownRooms(registry) : new Map();
|
|
2118
|
+
return { meshes: rows.map((row) => this._meshEntry(row, home, rooms)) };
|
|
2119
|
+
}
|
|
2120
|
+
async listArchivedMeshes() {
|
|
2121
|
+
if (!this.opened)
|
|
2122
|
+
await this.ready();
|
|
2123
|
+
const rows = await this.local.listArchivedMeshes();
|
|
2124
|
+
return {
|
|
2125
|
+
meshes: rows.map((row) => ({
|
|
2126
|
+
meshId: row.key.toString('hex'),
|
|
2127
|
+
leftAt: row.leftAt,
|
|
2128
|
+
wasHome: row.wasHome,
|
|
2129
|
+
migratedAt: row.migratedAt
|
|
2130
|
+
}))
|
|
2131
|
+
};
|
|
2132
|
+
}
|
|
2133
|
+
async archivedMeshContents(meshId) {
|
|
2134
|
+
if (!this.opened)
|
|
2135
|
+
await this.ready();
|
|
2136
|
+
const row = await this._archivedRow(meshId);
|
|
2137
|
+
const home = await this._homeMeshKey();
|
|
2138
|
+
const account = home ? this._currentMesh(home.toString('hex')) : null;
|
|
2139
|
+
const counts = await this._withArchivedMesh(row, (mesh) => countContents(mesh, account));
|
|
2140
|
+
return { meshId, ...counts };
|
|
2141
|
+
}
|
|
2142
|
+
async migrateArchivedMesh(meshId) {
|
|
2143
|
+
if (!this.opened)
|
|
2144
|
+
await this.ready();
|
|
2145
|
+
await this._meshTransitionLock.lock();
|
|
2146
|
+
try {
|
|
2147
|
+
if (this.closing)
|
|
2148
|
+
throw new Error('Core is closing');
|
|
2149
|
+
const row = await this._archivedRow(meshId);
|
|
2150
|
+
if (row.migratedAt) {
|
|
2151
|
+
const none = { chats: 0, agents: 0, knowledge: 0 };
|
|
2152
|
+
return { meshId, migrated: false, migratedAt: row.migratedAt, ...none };
|
|
1896
2153
|
}
|
|
2154
|
+
const account = await this._accountMesh();
|
|
2155
|
+
if (!account)
|
|
2156
|
+
throw new Error(NO_WRITABLE_ACCOUNT);
|
|
2157
|
+
const counts = await this._withArchivedMesh(row, (mesh) => migrateContents(mesh, account));
|
|
2158
|
+
const migratedAt = Date.now();
|
|
2159
|
+
await this.local.markMeshMigrated(row.key, migratedAt);
|
|
2160
|
+
return { meshId, migrated: true, migratedAt, ...counts };
|
|
2161
|
+
}
|
|
2162
|
+
finally {
|
|
2163
|
+
this._meshTransitionLock.unlock();
|
|
1897
2164
|
}
|
|
1898
|
-
|
|
2165
|
+
}
|
|
2166
|
+
async _archivedRow(meshId) {
|
|
2167
|
+
const key = this._meshKeyOf(meshId);
|
|
2168
|
+
const row = (await this.local.listArchivedMeshes()).find((row) => row.key.equals(key));
|
|
2169
|
+
if (!row)
|
|
2170
|
+
throw new Error(`${NO_SUCH_MESH}: ${meshId}`);
|
|
2171
|
+
if (!row.wasHome)
|
|
2172
|
+
throw new Error(`${NOT_AN_ARCHIVED_ACCOUNT}: ${meshId}`);
|
|
2173
|
+
return row;
|
|
2174
|
+
}
|
|
2175
|
+
_withArchivedMesh(row, fn) {
|
|
2176
|
+
const pooled = this._currentMesh(row.key.toString('hex'));
|
|
2177
|
+
if (pooled)
|
|
2178
|
+
return fn(pooled);
|
|
2179
|
+
return withArchivedMesh(this.store, row, { storage: this.storage, deviceId: this._deviceKeyPair.publicKey, logger: this._log }, fn);
|
|
2180
|
+
}
|
|
2181
|
+
async _ownRooms(registry) {
|
|
2182
|
+
const rooms = new Map();
|
|
2183
|
+
const ours = registry.ourMemberId;
|
|
2184
|
+
if (!ours)
|
|
2185
|
+
return rooms;
|
|
2186
|
+
for await (const room of registry.view.find(JOINED_MESHES)) {
|
|
2187
|
+
if (!room.leftAt && room.memberId.equals(ours))
|
|
2188
|
+
rooms.set(room.meshKey.toString('hex'), room);
|
|
2189
|
+
}
|
|
2190
|
+
return rooms;
|
|
1899
2191
|
}
|
|
1900
2192
|
async _isOwnRoomIn(registry, meshKey) {
|
|
1901
2193
|
const ours = registry.ourMemberId;
|
|
@@ -1929,12 +2221,12 @@ export class Core extends ReadyResource {
|
|
|
1929
2221
|
});
|
|
1930
2222
|
this._notifyStatus();
|
|
1931
2223
|
}
|
|
1932
|
-
async createRoom({ shared = false } = {}) {
|
|
2224
|
+
async createRoom({ shared = false, compute = false } = {}) {
|
|
1933
2225
|
if (!this.opened)
|
|
1934
2226
|
await this.ready();
|
|
1935
2227
|
await this._meshTransitionLock.lock();
|
|
1936
2228
|
try {
|
|
1937
|
-
return await this._mintRoom(shared);
|
|
2229
|
+
return await this._mintRoom(shared, undefined, compute);
|
|
1938
2230
|
}
|
|
1939
2231
|
finally {
|
|
1940
2232
|
this._meshTransitionLock.unlock();
|
|
@@ -1957,9 +2249,11 @@ export class Core extends ReadyResource {
|
|
|
1957
2249
|
}
|
|
1958
2250
|
async _occupancyNotice(meshId) {
|
|
1959
2251
|
const mesh = this._currentMesh(meshId);
|
|
1960
|
-
const ours = mesh?.ourMemberId;
|
|
1961
2252
|
if (!mesh)
|
|
1962
2253
|
return undefined;
|
|
2254
|
+
if (!mesh.ourMemberId)
|
|
2255
|
+
await mesh.refreshOurMember();
|
|
2256
|
+
const ours = mesh.ourMemberId;
|
|
1963
2257
|
const snap = mesh.view.snapshot();
|
|
1964
2258
|
try {
|
|
1965
2259
|
for await (const member of snap.find('@qvac/members')) {
|
|
@@ -1976,20 +2270,15 @@ export class Core extends ReadyResource {
|
|
|
1976
2270
|
}
|
|
1977
2271
|
}
|
|
1978
2272
|
async _resolveSharedRoom(registry) {
|
|
1979
|
-
const
|
|
1980
|
-
if (!ours)
|
|
1981
|
-
return null;
|
|
1982
|
-
const marked = [];
|
|
1983
|
-
for await (const room of registry.view.find(JOINED_MESHES)) {
|
|
1984
|
-
if (room.shared && !room.leftAt && room.memberId.equals(ours))
|
|
1985
|
-
marked.push(room);
|
|
1986
|
-
}
|
|
2273
|
+
const marked = [...(await this._ownRooms(registry)).values()].filter((room) => room.shared);
|
|
1987
2274
|
if (marked.length === 0)
|
|
1988
2275
|
return null;
|
|
1989
2276
|
marked.sort((a, b) => a.joinedAt - b.joinedAt || Buffer.compare(a.meshKey, b.meshKey));
|
|
1990
2277
|
const [winner, ...losers] = marked;
|
|
1991
2278
|
for (const loser of losers)
|
|
1992
2279
|
await this._unmarkSharedRoom(registry, loser);
|
|
2280
|
+
if (losers.length > 0)
|
|
2281
|
+
this._notifyStatus();
|
|
1993
2282
|
return { meshId: winner.meshKey.toString('hex'), notice: unmarkedNotice(losers) };
|
|
1994
2283
|
}
|
|
1995
2284
|
async _unmarkSharedRoom(registry, room) {
|
|
@@ -2005,7 +2294,7 @@ export class Core extends ReadyResource {
|
|
|
2005
2294
|
}
|
|
2006
2295
|
});
|
|
2007
2296
|
}
|
|
2008
|
-
async _mintRoom(shared, resolved) {
|
|
2297
|
+
async _mintRoom(shared, resolved, compute = false) {
|
|
2009
2298
|
if (this.closing)
|
|
2010
2299
|
throw new Error('Core is closing');
|
|
2011
2300
|
if (this._blockedByMinVersion())
|
|
@@ -2015,7 +2304,7 @@ export class Core extends ReadyResource {
|
|
|
2015
2304
|
const registry = resolved ?? (await this._accountMesh());
|
|
2016
2305
|
if (!registry)
|
|
2017
2306
|
throw new Error(ROOM_WITHOUT_ACCOUNT);
|
|
2018
|
-
const mesh = await this._openMesh({ new: true, room: true });
|
|
2307
|
+
const mesh = await this._openMesh({ new: true, room: true, compute });
|
|
2019
2308
|
this._wireMesh(this._poolEntry(mesh));
|
|
2020
2309
|
this._bringMeshOnline(mesh, { new: true });
|
|
2021
2310
|
try {
|
|
@@ -2102,10 +2391,11 @@ export class Core extends ReadyResource {
|
|
|
2102
2391
|
this._bringMeshOnline(mesh);
|
|
2103
2392
|
return mesh;
|
|
2104
2393
|
}
|
|
2105
|
-
_meshEntry(row, home,
|
|
2394
|
+
_meshEntry(row, home, rooms) {
|
|
2106
2395
|
const meshId = row.key.toString('hex');
|
|
2107
2396
|
const mesh = this._currentMesh(meshId);
|
|
2108
2397
|
const active = meshId === this._activeMeshKey;
|
|
2398
|
+
const room = rooms.get(meshId);
|
|
2109
2399
|
return {
|
|
2110
2400
|
meshId,
|
|
2111
2401
|
state: this._meshEntryState(mesh, active),
|
|
@@ -2113,8 +2403,11 @@ export class Core extends ReadyResource {
|
|
|
2113
2403
|
open: mesh !== null,
|
|
2114
2404
|
active,
|
|
2115
2405
|
home: !!home?.equals(row.key),
|
|
2116
|
-
label:
|
|
2117
|
-
members: mesh?.membership.members ?? 0
|
|
2406
|
+
label: room?.label || undefined,
|
|
2407
|
+
members: mesh?.membership.members ?? 0,
|
|
2408
|
+
shared: room?.shared ?? false,
|
|
2409
|
+
sharedAt: room?.shared ? room.sharedAt : undefined,
|
|
2410
|
+
compute: row.compute ?? false
|
|
2118
2411
|
};
|
|
2119
2412
|
}
|
|
2120
2413
|
_meshEntryState(mesh, active) {
|
|
@@ -2142,6 +2435,42 @@ export class Core extends ReadyResource {
|
|
|
2142
2435
|
if (this._localDevice)
|
|
2143
2436
|
this._localDevice = { ...this._localDevice, name };
|
|
2144
2437
|
}
|
|
2438
|
+
async displayName() {
|
|
2439
|
+
const identity = await this.local.readIdentity();
|
|
2440
|
+
if (!identity)
|
|
2441
|
+
return null;
|
|
2442
|
+
return identity.displayName ?? (await this._accountMemberName(identity.publicKey));
|
|
2443
|
+
}
|
|
2444
|
+
async _accountMemberName(identityPublicKey) {
|
|
2445
|
+
const home = await this._homeMeshKey();
|
|
2446
|
+
const mesh = home ? this._currentMesh(home.toString('hex')) : null;
|
|
2447
|
+
if (!mesh)
|
|
2448
|
+
return null;
|
|
2449
|
+
const ours = mesh.ourMemberId;
|
|
2450
|
+
if (!ours || ours.equals(identityPublicKey))
|
|
2451
|
+
return null;
|
|
2452
|
+
const member = await mesh.view.get('@qvac/members', { id: ours });
|
|
2453
|
+
return member?.name ?? null;
|
|
2454
|
+
}
|
|
2455
|
+
async setDisplayName(name) {
|
|
2456
|
+
const displayName = name.trim();
|
|
2457
|
+
if (!displayName)
|
|
2458
|
+
throw new Error('a display name is required');
|
|
2459
|
+
const identity = await this.local.saveDisplayName(displayName);
|
|
2460
|
+
if (!identity)
|
|
2461
|
+
throw new Error('no identity to name: this device holds no account yet');
|
|
2462
|
+
const context = { deviceKeyPair: this._deviceKeyPair, log: this._log };
|
|
2463
|
+
for (const { mesh } of this._meshes.values()) {
|
|
2464
|
+
if (!mesh.writable)
|
|
2465
|
+
continue;
|
|
2466
|
+
try {
|
|
2467
|
+
await renameFoundedMember(mesh, context, identity);
|
|
2468
|
+
}
|
|
2469
|
+
catch (err) {
|
|
2470
|
+
this._log?.warn(['p2p', 'mesh'], 'naming the member in this mesh failed', err);
|
|
2471
|
+
}
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2145
2474
|
async saveDeviceProfileLocal(capabilityProfile, recommendedModelName, platform) {
|
|
2146
2475
|
const publicKey = this.devicePublicKey;
|
|
2147
2476
|
if (publicKey) {
|
|
@@ -2177,7 +2506,13 @@ export class Core extends ReadyResource {
|
|
|
2177
2506
|
async getMeshInvite(opts = {}) {
|
|
2178
2507
|
if (opts.memberInvite && opts.meshId)
|
|
2179
2508
|
await this._assertRoomIsHere(opts.meshId);
|
|
2180
|
-
|
|
2509
|
+
if (this.closing)
|
|
2510
|
+
return null;
|
|
2511
|
+
if (!this.opened)
|
|
2512
|
+
await this.ready();
|
|
2513
|
+
const target = opts.meshId ??
|
|
2514
|
+
(opts.memberInvite ? null : ((await this._homeMeshKey())?.toString('hex') ?? null));
|
|
2515
|
+
const mesh = target ? await this._openPooledMesh(target) : await this._awaitMesh();
|
|
2181
2516
|
if (!mesh)
|
|
2182
2517
|
return null;
|
|
2183
2518
|
const registry = await this._accountMesh();
|
|
@@ -2219,15 +2554,19 @@ export class Core extends ReadyResource {
|
|
|
2219
2554
|
seed: mesh.seed,
|
|
2220
2555
|
fastForward: head ? { key: head.key, length: head.length } : null,
|
|
2221
2556
|
additionalNodes,
|
|
2222
|
-
blindPeers: blindPeerRows.
|
|
2557
|
+
blindPeers: blindPeerRows.length
|
|
2558
|
+
? blindPeerRows.map((row) => row.key)
|
|
2559
|
+
: this._resolveBlindPeerKeys().slice(0, INVITE_BLIND_PEERS_LIMIT),
|
|
2223
2560
|
memberInvite: opts.memberInvite ?? false,
|
|
2224
2561
|
memberId,
|
|
2225
|
-
inviteNonce: memberId ? await this._deviceInvites.issue() : undefined
|
|
2562
|
+
inviteNonce: memberId ? await this._deviceInvites.issue() : undefined,
|
|
2563
|
+
compute: mesh.compute
|
|
2226
2564
|
};
|
|
2227
2565
|
}
|
|
2228
2566
|
async _closeSwarm() {
|
|
2229
2567
|
this._wakeup.destroy();
|
|
2230
2568
|
this._meshSeedHandoff.destroy();
|
|
2569
|
+
this._harnessLoan.destroy();
|
|
2231
2570
|
this._secretHandoff.destroy();
|
|
2232
2571
|
this._skillOverlayHandoff.destroy();
|
|
2233
2572
|
if (!this._swarm)
|
|
@@ -2281,13 +2620,23 @@ export class Core extends ReadyResource {
|
|
|
2281
2620
|
for await (const room of memberMesh.view.find(JOINED_MESHES)) {
|
|
2282
2621
|
if (this.closing || !this._isPooled(memberMesh))
|
|
2283
2622
|
return;
|
|
2284
|
-
if (!room.memberId.equals(ours)
|
|
2623
|
+
if (!room.memberId.equals(ours))
|
|
2285
2624
|
continue;
|
|
2286
2625
|
const meshId = room.meshKey.toString('hex');
|
|
2287
|
-
if (this.
|
|
2626
|
+
if (this._following.has(meshId))
|
|
2288
2627
|
continue;
|
|
2628
|
+
const held = this._currentMesh(meshId);
|
|
2289
2629
|
this._following.add(meshId);
|
|
2290
2630
|
try {
|
|
2631
|
+
if (room.leftAt) {
|
|
2632
|
+
if (held)
|
|
2633
|
+
await this._retireLeftRoom(held);
|
|
2634
|
+
else
|
|
2635
|
+
await this._archiveLeftRoomRow(room.meshKey);
|
|
2636
|
+
continue;
|
|
2637
|
+
}
|
|
2638
|
+
if (held)
|
|
2639
|
+
continue;
|
|
2291
2640
|
if (await this.local.readMeshSession(room.meshKey))
|
|
2292
2641
|
continue;
|
|
2293
2642
|
await this._openFollowedRoom(memberMesh, room.meshKey, ours);
|
|
@@ -2300,6 +2649,30 @@ export class Core extends ReadyResource {
|
|
|
2300
2649
|
}
|
|
2301
2650
|
}
|
|
2302
2651
|
}
|
|
2652
|
+
async _retireLeftRoom(room) {
|
|
2653
|
+
if (this._leaving || this._minting)
|
|
2654
|
+
return;
|
|
2655
|
+
try {
|
|
2656
|
+
if (await this._departureHasAudience(room)) {
|
|
2657
|
+
await this.local.recordDeparture(room.key, { creator: room.minted });
|
|
2658
|
+
}
|
|
2659
|
+
await this._announceDeparture(room);
|
|
2660
|
+
if (this._isActive(room))
|
|
2661
|
+
await this._replaceRevokedActiveMesh(room);
|
|
2662
|
+
else
|
|
2663
|
+
await this._departRevokedMesh(room);
|
|
2664
|
+
this._departures?.flush();
|
|
2665
|
+
}
|
|
2666
|
+
catch (error) {
|
|
2667
|
+
this._log?.warn(['p2p', 'mesh'], 'retiring a room the member left failed', error);
|
|
2668
|
+
}
|
|
2669
|
+
}
|
|
2670
|
+
async _archiveLeftRoomRow(meshKey) {
|
|
2671
|
+
if (!(await this.local.readMeshSession(meshKey)))
|
|
2672
|
+
return;
|
|
2673
|
+
await this.local.archiveMesh(meshKey);
|
|
2674
|
+
this._notifyStatus();
|
|
2675
|
+
}
|
|
2303
2676
|
async _openFollowedRoom(memberMesh, meshKey, ours) {
|
|
2304
2677
|
const seed = await this._requestRoomSeed(memberMesh, meshKey, ours);
|
|
2305
2678
|
if (!seed)
|
|
@@ -2320,12 +2693,66 @@ export class Core extends ReadyResource {
|
|
|
2320
2693
|
continue;
|
|
2321
2694
|
if (self && device.id.equals(self))
|
|
2322
2695
|
continue;
|
|
2323
|
-
const seed = await this._meshSeedHandoff.request(device.id, meshKey).catch(
|
|
2696
|
+
const seed = await this._meshSeedHandoff.request(device.id, meshKey).catch(noop);
|
|
2324
2697
|
if (seed)
|
|
2325
2698
|
return seed;
|
|
2326
2699
|
}
|
|
2327
2700
|
return null;
|
|
2328
2701
|
}
|
|
2702
|
+
registerLoanableHarness(serve) {
|
|
2703
|
+
this._serveLoanedHarness = serve;
|
|
2704
|
+
return () => {
|
|
2705
|
+
if (this._serveLoanedHarness === serve)
|
|
2706
|
+
this._serveLoanedHarness = null;
|
|
2707
|
+
};
|
|
2708
|
+
}
|
|
2709
|
+
borrowHarness(deviceId) {
|
|
2710
|
+
return this._harnessLoan.borrow(deviceId);
|
|
2711
|
+
}
|
|
2712
|
+
async _lendHarness(fromDeviceId) {
|
|
2713
|
+
const serve = this._serveLoanedHarness;
|
|
2714
|
+
if (!serve)
|
|
2715
|
+
return null;
|
|
2716
|
+
const asker = Buffer.from(fromDeviceId);
|
|
2717
|
+
if (!(await this._sharesComputeMesh(asker))) {
|
|
2718
|
+
this._log?.warn(['p2p', 'mesh'], 'loan refused: no compute mesh shared with that device');
|
|
2719
|
+
return null;
|
|
2720
|
+
}
|
|
2721
|
+
const [ours, theirs] = duplexPair();
|
|
2722
|
+
serve(ours);
|
|
2723
|
+
return theirs;
|
|
2724
|
+
}
|
|
2725
|
+
_revalidateLoans() {
|
|
2726
|
+
return this._harnessLoan.revalidate((device) => this._sharesComputeMesh(Buffer.from(device)));
|
|
2727
|
+
}
|
|
2728
|
+
async _computeLender() {
|
|
2729
|
+
const self = this.devicePublicKey?.toString('hex');
|
|
2730
|
+
const lenders = new Map();
|
|
2731
|
+
for (const entry of this._meshes.values()) {
|
|
2732
|
+
if (!entry.mesh.compute)
|
|
2733
|
+
continue;
|
|
2734
|
+
for await (const device of entry.mesh.view.find('@qvac/devices')) {
|
|
2735
|
+
const id = device.id.toString('hex');
|
|
2736
|
+
if (device.revoked || id === self)
|
|
2737
|
+
continue;
|
|
2738
|
+
lenders.set(id, device.id);
|
|
2739
|
+
}
|
|
2740
|
+
}
|
|
2741
|
+
const [only] = [...lenders.values()];
|
|
2742
|
+
return lenders.size === 1 ? only : null;
|
|
2743
|
+
}
|
|
2744
|
+
async _sharesComputeMesh(deviceId) {
|
|
2745
|
+
for (const entry of this._meshes.values()) {
|
|
2746
|
+
if (!entry.mesh.compute)
|
|
2747
|
+
continue;
|
|
2748
|
+
const device = await entry.mesh.view
|
|
2749
|
+
.get('@qvac/devices', { id: deviceId })
|
|
2750
|
+
.catch(noop);
|
|
2751
|
+
if (device && !device.revoked)
|
|
2752
|
+
return true;
|
|
2753
|
+
}
|
|
2754
|
+
return false;
|
|
2755
|
+
}
|
|
2329
2756
|
async _serveMeshSeed(request, fromDeviceId) {
|
|
2330
2757
|
const asker = Buffer.from(fromDeviceId);
|
|
2331
2758
|
if (!(await this._isOwnMemberDevice(asker))) {
|
|
@@ -2344,9 +2771,7 @@ export class Core extends ReadyResource {
|
|
|
2344
2771
|
const ours = entry.mesh.ourMemberId;
|
|
2345
2772
|
if (!ours)
|
|
2346
2773
|
continue;
|
|
2347
|
-
const row = await entry.mesh.view
|
|
2348
|
-
.get(JOINED_MESHES, { meshKey })
|
|
2349
|
-
.catch(() => null);
|
|
2774
|
+
const row = await entry.mesh.view.get(JOINED_MESHES, { meshKey }).catch(noop);
|
|
2350
2775
|
if (row?.memberId.equals(ours) && !row.leftAt)
|
|
2351
2776
|
return true;
|
|
2352
2777
|
}
|
|
@@ -2360,7 +2785,7 @@ export class Core extends ReadyResource {
|
|
|
2360
2785
|
continue;
|
|
2361
2786
|
const device = await entry.mesh.view
|
|
2362
2787
|
.get('@qvac/devices', { id: deviceId })
|
|
2363
|
-
.catch(
|
|
2788
|
+
.catch(noop);
|
|
2364
2789
|
if (!device)
|
|
2365
2790
|
continue;
|
|
2366
2791
|
if (device.revoked)
|
|
@@ -2487,6 +2912,7 @@ export class Core extends ReadyResource {
|
|
|
2487
2912
|
this._secretHandoff.addStream(conn);
|
|
2488
2913
|
this._skillOverlayHandoff.addStream(conn);
|
|
2489
2914
|
this._meshSeedHandoff.addStream(conn);
|
|
2915
|
+
this._harnessLoan.addStream(conn);
|
|
2490
2916
|
for (const entry of this._meshes.values()) {
|
|
2491
2917
|
entry.hostedAgents?.kick();
|
|
2492
2918
|
if (entry.mesh.ourMemberId)
|
|
@@ -2517,6 +2943,15 @@ export class Core extends ReadyResource {
|
|
|
2517
2943
|
});
|
|
2518
2944
|
this._notifyStatus();
|
|
2519
2945
|
}
|
|
2946
|
+
_currentMeshAccessor(status) {
|
|
2947
|
+
return Object.assign((meshId) => this._meshFor(meshId), {
|
|
2948
|
+
selection: {
|
|
2949
|
+
key: () => this._activeMeshKey,
|
|
2950
|
+
watch: (listener) => status.watch(listener),
|
|
2951
|
+
unwatch: (listener) => status.unwatch(listener)
|
|
2952
|
+
}
|
|
2953
|
+
});
|
|
2954
|
+
}
|
|
2520
2955
|
_meshStatusSource() {
|
|
2521
2956
|
return {
|
|
2522
2957
|
watch: (listener) => void this._statusListeners.add(listener),
|
|
@@ -2545,7 +2980,15 @@ export class Core extends ReadyResource {
|
|
|
2545
2980
|
select: (meshId) => this.selectMesh(meshId),
|
|
2546
2981
|
close: (meshId) => this.closeMesh(meshId),
|
|
2547
2982
|
label: (meshId, label) => this.setMeshLabel(meshId, label),
|
|
2548
|
-
createRoom: () => this.createRoom()
|
|
2983
|
+
createRoom: (opts) => this.createRoom(opts),
|
|
2984
|
+
listArchived: () => this.listArchivedMeshes(),
|
|
2985
|
+
archivedContents: (meshId) => this.archivedMeshContents(meshId),
|
|
2986
|
+
migrateArchived: (meshId) => this.migrateArchivedMesh(meshId),
|
|
2987
|
+
recoverable: () => this.accountRecoverable(),
|
|
2988
|
+
publishRecovery: async (phrase) => void (await this.publishAccountRecovery(phrase)),
|
|
2989
|
+
recover: (phrase, timeout) => this.recoverAccount(phrase, { timeout }),
|
|
2990
|
+
displayName: () => this.displayName(),
|
|
2991
|
+
setDisplayName: (name) => this.setDisplayName(name)
|
|
2549
2992
|
};
|
|
2550
2993
|
}
|
|
2551
2994
|
_networkStatusSource() {
|