@qvac/core 0.2.1 → 0.2.2
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 +9 -4
- package/.claude/skills/pr-create/SKILL.md +24 -3
- package/.claude/skills/pr-review/SKILL.md +248 -40
- package/CLAUDE.md +1 -3
- 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 -9
- 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 +8 -8
- package/dist-lib/lib/api/chunks.js +11 -11
- package/dist-lib/lib/api/config.js +1 -1
- 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 +9 -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 +33 -33
- package/dist-lib/lib/api/instrument.js +1 -1
- package/dist-lib/lib/api/knowledge.js +4 -4
- 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 +88 -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.js +1 -1
- package/dist-lib/lib/api/tool-activity.js +4 -4
- package/dist-lib/lib/api/tool-configs.js +5 -5
- package/dist-lib/lib/api/watchable.js +1 -1
- 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 +32 -0
- package/dist-lib/lib/assistant/history.js +232 -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 +25 -285
- package/dist-lib/lib/assistant.js +250 -637
- 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 +1 -1
- package/dist-lib/lib/core/chunk.js +4 -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 +16 -3
- 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 +75 -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 +41 -3
- package/dist-lib/lib/core.js +525 -90
- 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 +4 -2
- 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 +96 -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.js +6 -6
- 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/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 +3 -3
- package/dist-lib/lib/oauth/token-exchange.js +1 -1
- package/dist-lib/lib/oauth.client.js +2 -2
- package/dist-lib/lib/oauth.js +12 -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.js +15 -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 +15 -9
- package/tui/README.md +7 -0
- package/tui/app.mjs +311 -14
- package/tui/lib/busy-words.mjs +57 -5
- package/tui/lib/export.mjs +1 -0
- package/tui/lib/render.mjs +9 -2
- package/tui/main.mjs +5 -2
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
import { raw, uint } from 'compact-encoding';
|
|
3
|
+
import Protomux, {} from 'protomux';
|
|
4
|
+
import { Duplex } from 'streamx';
|
|
5
|
+
const PROTOCOL = 'qvac/harness-loan';
|
|
6
|
+
function noop() { }
|
|
7
|
+
export const LOAN_UNREACHABLE = 'the device lending its model is not connected';
|
|
8
|
+
export const LOAN_REFUSED = 'the device would not lend its model';
|
|
9
|
+
export const LOAN_REVOKED = 'the device stopped lending its model';
|
|
10
|
+
export function loanFailureNotice(error) {
|
|
11
|
+
const message = error instanceof Error ? error.message : typeof error === 'string' ? error : '';
|
|
12
|
+
if (message.includes(LOAN_UNREACHABLE))
|
|
13
|
+
return LOAN_UNREACHABLE;
|
|
14
|
+
if (message.includes('CHANNEL_CLOSED'))
|
|
15
|
+
return LOAN_REFUSED;
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const bytes = raw;
|
|
19
|
+
const frame = {
|
|
20
|
+
preencode(state, f) {
|
|
21
|
+
uint.preencode(state, f.id);
|
|
22
|
+
uint.preencode(state, f.mine ? 1 : 0);
|
|
23
|
+
bytes.preencode(state, f.data);
|
|
24
|
+
},
|
|
25
|
+
encode(state, f) {
|
|
26
|
+
uint.encode(state, f.id);
|
|
27
|
+
uint.encode(state, f.mine ? 1 : 0);
|
|
28
|
+
bytes.encode(state, f.data);
|
|
29
|
+
},
|
|
30
|
+
decode(state) {
|
|
31
|
+
const id = uint.decode(state);
|
|
32
|
+
const mine = uint.decode(state) === 1;
|
|
33
|
+
return { id, mine, data: bytes.decode(state) };
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const ends = {
|
|
37
|
+
preencode(state, e) {
|
|
38
|
+
uint.preencode(state, e.id);
|
|
39
|
+
uint.preencode(state, e.mine ? 1 : 0);
|
|
40
|
+
},
|
|
41
|
+
encode(state, e) {
|
|
42
|
+
uint.encode(state, e.id);
|
|
43
|
+
uint.encode(state, e.mine ? 1 : 0);
|
|
44
|
+
},
|
|
45
|
+
decode(state) {
|
|
46
|
+
return { id: uint.decode(state), mine: uint.decode(state) === 1 };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export class HarnessLoan {
|
|
50
|
+
_opts;
|
|
51
|
+
_peers;
|
|
52
|
+
_nextId;
|
|
53
|
+
constructor(opts) {
|
|
54
|
+
this._opts = opts;
|
|
55
|
+
this._peers = new Map();
|
|
56
|
+
this._nextId = 1;
|
|
57
|
+
}
|
|
58
|
+
addStream(stream) {
|
|
59
|
+
const deviceId = b4a.toString(stream.remotePublicKey, 'hex');
|
|
60
|
+
if (this._peers.has(deviceId))
|
|
61
|
+
return;
|
|
62
|
+
const channel = Protomux.from(stream.noiseStream).createChannel({
|
|
63
|
+
protocol: PROTOCOL,
|
|
64
|
+
onclose: () => this._drop(deviceId)
|
|
65
|
+
});
|
|
66
|
+
if (!channel)
|
|
67
|
+
return;
|
|
68
|
+
const open = channel.addMessage({
|
|
69
|
+
encoding: uint,
|
|
70
|
+
onmessage: (id) => void this._serve(deviceId, id)
|
|
71
|
+
});
|
|
72
|
+
const data = channel.addMessage({
|
|
73
|
+
encoding: frame,
|
|
74
|
+
onmessage: (f) => this._deliver(deviceId, f)
|
|
75
|
+
});
|
|
76
|
+
const close = channel.addMessage({
|
|
77
|
+
encoding: ends,
|
|
78
|
+
onmessage: (e) => this._end(deviceId, e)
|
|
79
|
+
});
|
|
80
|
+
this._peers.set(deviceId, {
|
|
81
|
+
channel,
|
|
82
|
+
remoteKey: stream.remotePublicKey,
|
|
83
|
+
open,
|
|
84
|
+
data,
|
|
85
|
+
close,
|
|
86
|
+
borrowed: new Map(),
|
|
87
|
+
served: new Map()
|
|
88
|
+
});
|
|
89
|
+
channel.open();
|
|
90
|
+
}
|
|
91
|
+
borrow(deviceId) {
|
|
92
|
+
const peer = this._peers.get(deviceId);
|
|
93
|
+
if (!peer)
|
|
94
|
+
throw new Error(LOAN_UNREACHABLE);
|
|
95
|
+
const id = this._nextId;
|
|
96
|
+
this._nextId += 1;
|
|
97
|
+
const stream = this._attach(peer, id, true);
|
|
98
|
+
peer.open.send(id);
|
|
99
|
+
return stream;
|
|
100
|
+
}
|
|
101
|
+
async revalidate(allowed) {
|
|
102
|
+
for (const peer of [...this._peers.values()]) {
|
|
103
|
+
if (peer.served.size === 0)
|
|
104
|
+
continue;
|
|
105
|
+
if (await allowed(peer.remoteKey).catch(() => false))
|
|
106
|
+
continue;
|
|
107
|
+
for (const [id, stream] of [...peer.served]) {
|
|
108
|
+
peer.served.delete(id);
|
|
109
|
+
peer.close.send({ id, mine: false });
|
|
110
|
+
stream.destroy(new Error(LOAN_REVOKED));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
destroy() {
|
|
115
|
+
for (const [deviceId, peer] of [...this._peers]) {
|
|
116
|
+
try {
|
|
117
|
+
peer.channel.close();
|
|
118
|
+
}
|
|
119
|
+
catch { }
|
|
120
|
+
this._drop(deviceId);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
_attach(peer, id, mine) {
|
|
124
|
+
const held = mine ? peer.borrowed : peer.served;
|
|
125
|
+
const stream = new Duplex({
|
|
126
|
+
write: (chunk, cb) => {
|
|
127
|
+
peer.data.send({ id, mine, data: chunk });
|
|
128
|
+
cb(null);
|
|
129
|
+
},
|
|
130
|
+
final: (cb) => {
|
|
131
|
+
peer.close.send({ id, mine });
|
|
132
|
+
cb(null);
|
|
133
|
+
},
|
|
134
|
+
destroy: (cb) => {
|
|
135
|
+
if (held.delete(id))
|
|
136
|
+
peer.close.send({ id, mine });
|
|
137
|
+
cb(null);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
held.set(id, stream);
|
|
141
|
+
return stream;
|
|
142
|
+
}
|
|
143
|
+
async _serve(deviceId, id) {
|
|
144
|
+
const peer = this._peers.get(deviceId);
|
|
145
|
+
if (!peer || peer.served.has(id))
|
|
146
|
+
return;
|
|
147
|
+
const stream = this._attach(peer, id, false);
|
|
148
|
+
const served = await this._opts.onborrow(peer.remoteKey).catch(() => null);
|
|
149
|
+
if (!served) {
|
|
150
|
+
stream.destroy();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
stream.on('error', noop);
|
|
154
|
+
served.on('error', noop);
|
|
155
|
+
stream.pipe(served).pipe(stream);
|
|
156
|
+
}
|
|
157
|
+
_deliver(deviceId, f) {
|
|
158
|
+
const peer = this._peers.get(deviceId);
|
|
159
|
+
if (!peer)
|
|
160
|
+
return;
|
|
161
|
+
const held = f.mine ? peer.served : peer.borrowed;
|
|
162
|
+
held.get(f.id)?.push(f.data);
|
|
163
|
+
}
|
|
164
|
+
_end(deviceId, e) {
|
|
165
|
+
const peer = this._peers.get(deviceId);
|
|
166
|
+
if (!peer)
|
|
167
|
+
return;
|
|
168
|
+
const held = e.mine ? peer.served : peer.borrowed;
|
|
169
|
+
const stream = held.get(e.id);
|
|
170
|
+
if (!stream)
|
|
171
|
+
return;
|
|
172
|
+
held.delete(e.id);
|
|
173
|
+
stream.push(null);
|
|
174
|
+
stream.destroy();
|
|
175
|
+
}
|
|
176
|
+
_drop(deviceId) {
|
|
177
|
+
const peer = this._peers.get(deviceId);
|
|
178
|
+
if (!peer)
|
|
179
|
+
return;
|
|
180
|
+
this._peers.delete(deviceId);
|
|
181
|
+
for (const held of [peer.borrowed, peer.served]) {
|
|
182
|
+
for (const stream of held.values())
|
|
183
|
+
stream.destroy(new Error(LOAN_UNREACHABLE));
|
|
184
|
+
held.clear();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { QvacDevice, QvacSeedDefaultsOperation } from '../../../spec/mesh/hyperschema/types.d.ts';
|
|
2
2
|
import type { Mesh } from '../mesh.ts';
|
|
3
|
-
export declare
|
|
3
|
+
export declare const DEFAULT_AGENT_NAME = "QV.AC";
|
|
4
|
+
export declare function buildDefaultSeed(device: Pick<QvacDevice, 'id' | 'recommendedModelName'>, blindPeerKeys: ReadonlyArray<Buffer>, agentName?: string): QvacSeedDefaultsOperation;
|
|
4
5
|
export declare function isOwnRevokedRow(mesh: Mesh, device: QvacDevice): boolean;
|
|
5
6
|
export declare function isOwnKickedRow(mesh: Mesh, device: QvacDevice): boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { randomId } from
|
|
2
|
-
const DEFAULT_AGENT_NAME = 'QV.AC';
|
|
1
|
+
import { randomId } from '../id.js';
|
|
2
|
+
export const DEFAULT_AGENT_NAME = 'QV.AC';
|
|
3
3
|
const DEFAULT_AGENT_BIO = 'You are a helpful local assistant. Be clear, practical, and concise.';
|
|
4
4
|
const DEFAULT_AGENT_ICON = 'artificial-intelligence';
|
|
5
5
|
const DEFAULT_FIRST_CHAT_TITLE = 'New Chat';
|
|
@@ -32,13 +32,13 @@ function seedableChat(chat) {
|
|
|
32
32
|
updatedAt: chat.updatedAt
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
export function buildDefaultSeed(device, blindPeerKeys) {
|
|
35
|
+
export function buildDefaultSeed(device, blindPeerKeys, agentName = DEFAULT_AGENT_NAME) {
|
|
36
36
|
const now = Date.now();
|
|
37
37
|
const agentId = randomId();
|
|
38
38
|
return {
|
|
39
39
|
agent: seedableAgent({
|
|
40
40
|
id: agentId,
|
|
41
|
-
name:
|
|
41
|
+
name: agentName,
|
|
42
42
|
bio: DEFAULT_AGENT_BIO,
|
|
43
43
|
providerDeviceId: device.id,
|
|
44
44
|
modelName: device.recommendedModelName,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import ScopeLock from 'scope-lock';
|
|
3
|
-
import { getAgent, listAgents } from
|
|
4
|
-
import { agentSkillValues } from
|
|
3
|
+
import { getAgent, listAgents } from './agent.js';
|
|
4
|
+
import { agentSkillValues } from './skill-secrets.js';
|
|
5
5
|
const SCOPE = ['p2p', 'skill-values'];
|
|
6
6
|
export const LEGACY_HELD_AGENTS_KEY = 'skill-values.held-agents';
|
|
7
7
|
export function heldAgentsKey(meshKey) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { KeyPair } from 'hypercore-crypto';
|
|
2
|
+
import type IdentityKey from 'keet-identity-key';
|
|
2
3
|
export declare const MAX_PROOF_BYTES = 1024;
|
|
3
4
|
export interface MintedIdentity {
|
|
4
5
|
readonly publicKey: Buffer;
|
|
@@ -14,6 +15,7 @@ export interface ExpectedMemberClaim {
|
|
|
14
15
|
readonly attestation: Buffer;
|
|
15
16
|
}
|
|
16
17
|
export declare function generateMnemonic(): Promise<string>;
|
|
18
|
+
export declare function openIdentity(mnemonic: string): Promise<IdentityKey>;
|
|
17
19
|
export declare function mintIdentity(mnemonic: string, devicePublicKey: Buffer): Promise<MintedIdentity>;
|
|
18
20
|
export declare function attestDeviceProof(devicePublicKey: Buffer, parent: KeyPair, parentProof: Buffer): Promise<Buffer>;
|
|
19
21
|
export declare function verifyDeviceProof(proof: Buffer, expected: ExpectedDeviceProof): Promise<boolean>;
|
|
@@ -13,9 +13,11 @@ async function identityKey() {
|
|
|
13
13
|
export async function generateMnemonic() {
|
|
14
14
|
return (await identityKey()).generateMnemonic();
|
|
15
15
|
}
|
|
16
|
+
export async function openIdentity(mnemonic) {
|
|
17
|
+
return (await identityKey()).from({ mnemonic });
|
|
18
|
+
}
|
|
16
19
|
export async function mintIdentity(mnemonic, devicePublicKey) {
|
|
17
|
-
const
|
|
18
|
-
const identity = await IdentityKey.from({ mnemonic });
|
|
20
|
+
const identity = await openIdentity(mnemonic);
|
|
19
21
|
return { publicKey: identity.identityPublicKey, proof: await identity.bootstrap(devicePublicKey) };
|
|
20
22
|
}
|
|
21
23
|
export async function attestDeviceProof(devicePublicKey, parent, parentProof) {
|
|
@@ -12,6 +12,7 @@ export interface MeshInvite {
|
|
|
12
12
|
readonly memberInvite?: boolean;
|
|
13
13
|
readonly memberId?: Buffer;
|
|
14
14
|
readonly inviteNonce?: Buffer;
|
|
15
|
+
readonly compute?: boolean;
|
|
15
16
|
}
|
|
16
17
|
export declare function encodeMeshInvite(invite: MeshInvite): string;
|
|
17
18
|
export declare function decodeMeshInvite(raw: string): MeshInvite | null;
|
|
@@ -11,7 +11,8 @@ export function encodeMeshInvite(invite) {
|
|
|
11
11
|
blindPeers: [...(invite.blindPeers ?? [])],
|
|
12
12
|
memberInvite: invite.memberInvite ?? false,
|
|
13
13
|
memberId: invite.memberId ?? null,
|
|
14
|
-
inviteNonce: invite.inviteNonce ?? null
|
|
14
|
+
inviteNonce: invite.inviteNonce ?? null,
|
|
15
|
+
compute: invite.compute ?? false
|
|
15
16
|
};
|
|
16
17
|
return INVITE_PREFIX + z32.encode(encodeStruct(INVITE_STRUCT, payload));
|
|
17
18
|
}
|
|
@@ -37,6 +38,7 @@ export function decodeMeshInvite(raw) {
|
|
|
37
38
|
blindPeers: payload.blindPeers ?? [],
|
|
38
39
|
memberInvite: payload.memberInvite ?? false,
|
|
39
40
|
memberId: payload.memberId ?? undefined,
|
|
40
|
-
inviteNonce: payload.inviteNonce ?? undefined
|
|
41
|
+
inviteNonce: payload.inviteNonce ?? undefined,
|
|
42
|
+
compute: payload.compute ?? false
|
|
41
43
|
};
|
|
42
44
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import CorestoreStorage from 'hypercore-storage';
|
|
2
2
|
import HyperDB from 'hyperdb';
|
|
3
|
-
import type { LocalAppConfig, LocalCapabilityProfile, LocalChatNotify, LocalCustomModel, LocalIdentity, LocalMemberProof, LocalMeshDeparture, LocalMeshMembership, LocalModelDownload, LocalModelNotify } from '../../../spec/local/hyperschema/types.d.ts';
|
|
3
|
+
import type { LocalAccountRecovery, LocalAppConfig, LocalCapabilityProfile, LocalChatNotify, LocalCustomModel, LocalIdentity, LocalMemberProof, LocalMeshDeparture, LocalMeshMembership, LocalModelDownload, LocalModelNotify } from '../../../spec/local/hyperschema/types.d.ts';
|
|
4
4
|
import type { DeviceMetadata } from '../mesh.ts';
|
|
5
5
|
export interface ResolvedSession {
|
|
6
6
|
readonly seed: Buffer;
|
|
7
7
|
readonly baseKey: Buffer | undefined;
|
|
8
8
|
readonly writerSeed: string | undefined;
|
|
9
|
+
readonly compute: boolean;
|
|
9
10
|
}
|
|
10
11
|
export declare function openLocalStore(storage: CorestoreStorage): LocalStore;
|
|
11
12
|
declare class LocalStore {
|
|
@@ -46,8 +47,12 @@ declare class LocalStore {
|
|
|
46
47
|
renameDevice(publicKey: Buffer, name: string): Promise<void>;
|
|
47
48
|
saveDeviceProfile(publicKey: Buffer, capabilityProfile: LocalCapabilityProfile, recommendedModelName: string, platform?: string): Promise<void>;
|
|
48
49
|
readIdentity(): Promise<LocalIdentity | null>;
|
|
50
|
+
saveDisplayName(displayName: string): Promise<LocalIdentity | null>;
|
|
49
51
|
readMemberProof(meshKey: Buffer): Promise<LocalMemberProof | null>;
|
|
50
52
|
recordMemberProof(link: LocalMemberProof): Promise<void>;
|
|
53
|
+
readAccountRecovery(meshKey: Buffer): Promise<LocalAccountRecovery | null>;
|
|
54
|
+
recordAccountRecovery(row: LocalAccountRecovery): Promise<void>;
|
|
55
|
+
replaceIdentity(identity: Omit<LocalIdentity, 'id'>): Promise<void>;
|
|
51
56
|
ensureIdentity(devicePublicKey: Buffer, createdAt: number): Promise<{
|
|
52
57
|
identity: LocalIdentity;
|
|
53
58
|
mnemonic: string | null;
|
|
@@ -57,8 +62,9 @@ declare class LocalStore {
|
|
|
57
62
|
baseKey?: Buffer;
|
|
58
63
|
new?: boolean;
|
|
59
64
|
writerSeed?: string;
|
|
65
|
+
compute?: boolean;
|
|
60
66
|
}): Promise<ResolvedSession>;
|
|
61
|
-
createCandidateSession(seed: Buffer, baseKey: Buffer): ResolvedSession;
|
|
67
|
+
createCandidateSession(seed: Buffer, baseKey: Buffer, compute?: boolean): ResolvedSession;
|
|
62
68
|
private _activeMembership;
|
|
63
69
|
private _membership;
|
|
64
70
|
private _migrateLegacySession;
|
|
@@ -73,7 +79,10 @@ declare class LocalStore {
|
|
|
73
79
|
departures(): Promise<LocalMeshDeparture[]>;
|
|
74
80
|
deleteDeparture(key: Buffer): Promise<void>;
|
|
75
81
|
archiveMesh(key: Buffer): Promise<void>;
|
|
76
|
-
|
|
82
|
+
markMeshMigrated(key: Buffer, migratedAt: number): Promise<void>;
|
|
83
|
+
adoptHomeMesh(deviceId: Buffer, key: Buffer, { account }: {
|
|
84
|
+
account?: Buffer | null;
|
|
85
|
+
}): Promise<void>;
|
|
77
86
|
private _pointersAt;
|
|
78
87
|
listMeshes(): Promise<LocalMeshMembership[]>;
|
|
79
88
|
listArchivedMeshes(): Promise<LocalMeshMembership[]>;
|
|
@@ -2,7 +2,7 @@ import CorestoreStorage from 'hypercore-storage';
|
|
|
2
2
|
import HyperDB from 'hyperdb';
|
|
3
3
|
import crypto from 'hypercore-crypto';
|
|
4
4
|
import ScopeLock from 'scope-lock';
|
|
5
|
-
import { generateMnemonic, mintIdentity } from
|
|
5
|
+
import { generateMnemonic, mintIdentity } from '../identity.js';
|
|
6
6
|
import LocalDatabaseSpec from '../../../spec/local/hyperdb/index.js';
|
|
7
7
|
const CONFIG = '@local/config';
|
|
8
8
|
const ACTIVE_MESH = '@local/active-mesh';
|
|
@@ -17,6 +17,7 @@ const CUSTOM_MODEL = '@local/custom-model';
|
|
|
17
17
|
const IDENTITY = '@local/identity';
|
|
18
18
|
const IDENTITY_ID = 'identity';
|
|
19
19
|
const MEMBER_PROOF = '@local/member-proof';
|
|
20
|
+
const ACCOUNT_RECOVERY = '@local/account-recovery';
|
|
20
21
|
const MEMBERSHIP = '@local/membership';
|
|
21
22
|
const MEMBERSHIP_ID = 'membership';
|
|
22
23
|
const CHAT_NOTIFY = '@local/chat-notify';
|
|
@@ -29,7 +30,8 @@ function sessionOf(row) {
|
|
|
29
30
|
return {
|
|
30
31
|
seed: row.seed,
|
|
31
32
|
baseKey: row.key ?? undefined,
|
|
32
|
-
writerSeed: row.writerSeed ?? undefined
|
|
33
|
+
writerSeed: row.writerSeed ?? undefined,
|
|
34
|
+
compute: row.compute ?? false
|
|
33
35
|
};
|
|
34
36
|
}
|
|
35
37
|
export function openLocalStore(storage) {
|
|
@@ -270,6 +272,20 @@ class LocalStore {
|
|
|
270
272
|
readIdentity() {
|
|
271
273
|
return this._db.get(IDENTITY, { id: IDENTITY_ID });
|
|
272
274
|
}
|
|
275
|
+
saveDisplayName(displayName) {
|
|
276
|
+
return this._locked(async () => {
|
|
277
|
+
const tx = this._db.transaction();
|
|
278
|
+
const existing = await tx.get(IDENTITY, { id: IDENTITY_ID });
|
|
279
|
+
if (!existing) {
|
|
280
|
+
await tx.close();
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
const identity = { ...existing, displayName };
|
|
284
|
+
await tx.insert(IDENTITY, identity);
|
|
285
|
+
await tx.flush();
|
|
286
|
+
return identity;
|
|
287
|
+
});
|
|
288
|
+
}
|
|
273
289
|
readMemberProof(meshKey) {
|
|
274
290
|
return this._db.get(MEMBER_PROOF, { meshKey });
|
|
275
291
|
}
|
|
@@ -283,6 +299,28 @@ class LocalStore {
|
|
|
283
299
|
await tx.flush();
|
|
284
300
|
});
|
|
285
301
|
}
|
|
302
|
+
readAccountRecovery(meshKey) {
|
|
303
|
+
return this._db.get(ACCOUNT_RECOVERY, { meshKey });
|
|
304
|
+
}
|
|
305
|
+
recordAccountRecovery(row) {
|
|
306
|
+
return this._locked(async () => {
|
|
307
|
+
const tx = this._db.transaction();
|
|
308
|
+
await tx.insert(ACCOUNT_RECOVERY, row);
|
|
309
|
+
await tx.flush();
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
replaceIdentity(identity) {
|
|
313
|
+
return this._locked(async () => {
|
|
314
|
+
const tx = this._db.transaction();
|
|
315
|
+
const existing = await tx.get(IDENTITY, { id: IDENTITY_ID });
|
|
316
|
+
await tx.insert(IDENTITY, {
|
|
317
|
+
id: IDENTITY_ID,
|
|
318
|
+
displayName: existing?.displayName ?? null,
|
|
319
|
+
...identity
|
|
320
|
+
});
|
|
321
|
+
await tx.flush();
|
|
322
|
+
});
|
|
323
|
+
}
|
|
286
324
|
ensureIdentity(devicePublicKey, createdAt) {
|
|
287
325
|
return this._locked(async () => {
|
|
288
326
|
const existing = await this._db.get(IDENTITY, { id: IDENTITY_ID });
|
|
@@ -309,7 +347,8 @@ class LocalStore {
|
|
|
309
347
|
return {
|
|
310
348
|
seed: opts.seed,
|
|
311
349
|
baseKey: opts.baseKey,
|
|
312
|
-
writerSeed: opts.writerSeed ?? freshWriterSeed()
|
|
350
|
+
writerSeed: opts.writerSeed ?? freshWriterSeed(),
|
|
351
|
+
compute: opts.compute ?? false
|
|
313
352
|
};
|
|
314
353
|
}
|
|
315
354
|
if (current && !opts.new)
|
|
@@ -317,14 +356,16 @@ class LocalStore {
|
|
|
317
356
|
return {
|
|
318
357
|
seed: crypto.randomBytes(32),
|
|
319
358
|
baseKey: undefined,
|
|
320
|
-
writerSeed: undefined
|
|
359
|
+
writerSeed: undefined,
|
|
360
|
+
compute: opts.compute ?? false
|
|
321
361
|
};
|
|
322
362
|
}
|
|
323
|
-
createCandidateSession(seed, baseKey) {
|
|
363
|
+
createCandidateSession(seed, baseKey, compute = false) {
|
|
324
364
|
return {
|
|
325
365
|
seed,
|
|
326
366
|
baseKey,
|
|
327
|
-
writerSeed: freshWriterSeed()
|
|
367
|
+
writerSeed: freshWriterSeed(),
|
|
368
|
+
compute
|
|
328
369
|
};
|
|
329
370
|
}
|
|
330
371
|
async _activeMembership(deviceId) {
|
|
@@ -388,7 +429,8 @@ class LocalStore {
|
|
|
388
429
|
await tx.insert(MESH_MEMBERSHIP, {
|
|
389
430
|
key,
|
|
390
431
|
seed: session.seed,
|
|
391
|
-
writerSeed: session.writerSeed
|
|
432
|
+
writerSeed: session.writerSeed,
|
|
433
|
+
compute: session.compute
|
|
392
434
|
});
|
|
393
435
|
if (minted) {
|
|
394
436
|
await tx.insert(ACTIVE_MESH, {
|
|
@@ -445,17 +487,31 @@ class LocalStore {
|
|
|
445
487
|
archiveMesh(key) {
|
|
446
488
|
return this._locked(async () => {
|
|
447
489
|
const existing = await this._db.get(MESH_MEMBERSHIP, { key });
|
|
448
|
-
const
|
|
490
|
+
const { cleared, home } = await this._pointersAt(key);
|
|
449
491
|
const tx = this._db.transaction();
|
|
450
492
|
if (existing) {
|
|
451
|
-
await tx.insert(MESH_MEMBERSHIP, {
|
|
493
|
+
await tx.insert(MESH_MEMBERSHIP, {
|
|
494
|
+
...existing,
|
|
495
|
+
leftAt: Date.now(),
|
|
496
|
+
wasHome: home
|
|
497
|
+
});
|
|
452
498
|
}
|
|
453
|
-
for (const pointer of
|
|
499
|
+
for (const pointer of cleared)
|
|
454
500
|
await tx.insert(ACTIVE_MESH, pointer);
|
|
455
501
|
await tx.flush();
|
|
456
502
|
});
|
|
457
503
|
}
|
|
458
|
-
|
|
504
|
+
markMeshMigrated(key, migratedAt) {
|
|
505
|
+
return this._locked(async () => {
|
|
506
|
+
const existing = await this._db.get(MESH_MEMBERSHIP, { key });
|
|
507
|
+
if (!existing)
|
|
508
|
+
return;
|
|
509
|
+
const tx = this._db.transaction();
|
|
510
|
+
await tx.insert(MESH_MEMBERSHIP, { ...existing, migratedAt });
|
|
511
|
+
await tx.flush();
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
adoptHomeMesh(deviceId, key, { account }) {
|
|
459
515
|
return this._locked(async () => {
|
|
460
516
|
const departed = [];
|
|
461
517
|
for await (const row of this._db.find(MESH_MEMBERSHIP)) {
|
|
@@ -466,7 +522,8 @@ class LocalStore {
|
|
|
466
522
|
const leftAt = Date.now();
|
|
467
523
|
const tx = this._db.transaction();
|
|
468
524
|
for (const row of departed) {
|
|
469
|
-
|
|
525
|
+
const wasHome = !!account?.equals(row.key);
|
|
526
|
+
await tx.insert(MESH_MEMBERSHIP, { ...row, leftAt, wasHome });
|
|
470
527
|
}
|
|
471
528
|
await tx.insert(ACTIVE_MESH, {
|
|
472
529
|
deviceId,
|
|
@@ -478,18 +535,20 @@ class LocalStore {
|
|
|
478
535
|
}
|
|
479
536
|
async _pointersAt(key) {
|
|
480
537
|
const cleared = [];
|
|
538
|
+
let home = false;
|
|
481
539
|
for await (const pointer of this._db.find(ACTIVE_MESH)) {
|
|
482
540
|
const active = pointer.activeMeshKey?.equals(key);
|
|
483
|
-
const
|
|
484
|
-
if (!active && !
|
|
541
|
+
const aimed = pointer.homeMeshKey?.equals(key);
|
|
542
|
+
if (!active && !aimed)
|
|
485
543
|
continue;
|
|
544
|
+
home ||= !!aimed;
|
|
486
545
|
cleared.push({
|
|
487
546
|
deviceId: pointer.deviceId,
|
|
488
547
|
activeMeshKey: active ? null : pointer.activeMeshKey,
|
|
489
|
-
homeMeshKey:
|
|
548
|
+
homeMeshKey: aimed ? null : pointer.homeMeshKey
|
|
490
549
|
});
|
|
491
550
|
}
|
|
492
|
-
return cleared;
|
|
551
|
+
return { cleared, home };
|
|
493
552
|
}
|
|
494
553
|
async listMeshes() {
|
|
495
554
|
const rows = [];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { KeyPair } from 'hyperswarm';
|
|
2
2
|
import type { Logger } from '../../index.ts';
|
|
3
|
+
import type { LocalIdentity } from '../../spec/local/hyperschema/types.d.ts';
|
|
3
4
|
import type { QvacDevice } from '../../spec/mesh/hyperschema/types.d.ts';
|
|
4
5
|
import type { DeviceInvites } from './device-invites.ts';
|
|
5
6
|
import type { Mesh } from './mesh.ts';
|
|
@@ -16,6 +17,8 @@ export declare function membershipView(mesh: Mesh, deviceId: Buffer): Promise<Me
|
|
|
16
17
|
export declare function attestUnattestedDevices(mesh: Mesh, { deviceKeyPair, log }: MembershipContext, invites: DeviceInvites): Promise<void>;
|
|
17
18
|
export interface KnownMember {
|
|
18
19
|
readonly id: Buffer;
|
|
20
|
+
readonly name: string;
|
|
19
21
|
readonly proof: Buffer;
|
|
20
22
|
}
|
|
21
23
|
export declare function claimOwnMembership(mesh: Mesh, { deviceKeyPair, log }: MembershipContext, known: KnownMember): Promise<void>;
|
|
24
|
+
export declare function renameFoundedMember(mesh: Mesh, { deviceKeyPair, log }: MembershipContext, identity: LocalIdentity): Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { attestDeviceProof, attestMemberClaim, claimAttestation } from
|
|
1
|
+
import { attestDeviceProof, attestMemberClaim, claimAttestation } from './identity.js';
|
|
2
2
|
export async function membershipView(mesh, deviceId) {
|
|
3
3
|
const snap = mesh.view.snapshot();
|
|
4
4
|
try {
|
|
@@ -62,3 +62,17 @@ export async function claimOwnMembership(mesh, { deviceKeyPair, log }, known) {
|
|
|
62
62
|
await mesh.refreshOurMember();
|
|
63
63
|
log?.info('membership', 'claimed our own member in a mesh a sibling device joined');
|
|
64
64
|
}
|
|
65
|
+
export async function renameFoundedMember(mesh, { deviceKeyPair, log }, identity) {
|
|
66
|
+
if (!identity.displayName)
|
|
67
|
+
return;
|
|
68
|
+
const own = await mesh.view.get('@qvac/devices', { id: deviceKeyPair.publicKey });
|
|
69
|
+
if (!own?.memberId || !own.memberProof)
|
|
70
|
+
return;
|
|
71
|
+
const member = await mesh.view.get('@qvac/members', { id: own.memberId });
|
|
72
|
+
if (!member || member.name === identity.displayName)
|
|
73
|
+
return;
|
|
74
|
+
await mesh.dispatch('update-member', {
|
|
75
|
+
member: { ...member, name: identity.displayName, updatedAt: Date.now() }
|
|
76
|
+
});
|
|
77
|
+
log?.info('membership', 'the member this device founded carries its user name');
|
|
78
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getStruct } from '../../spec/hyperschema/index.js';
|
|
2
|
-
import { HandoffChannel } from
|
|
2
|
+
import { HandoffChannel } from './handoff-channel.js';
|
|
3
3
|
const PROTOCOL = 'qvac/mesh-seed-handoff';
|
|
4
4
|
export {};
|
|
5
5
|
export const SEED_REFUSED = 'the device holding this room would not share its seed';
|
|
@@ -28,6 +28,7 @@ export interface OrphanedBlobSweepStatus {
|
|
|
28
28
|
}
|
|
29
29
|
export interface MeshOptions {
|
|
30
30
|
seed?: Buffer;
|
|
31
|
+
compute?: boolean;
|
|
31
32
|
key?: Buffer | null;
|
|
32
33
|
writerSeed?: string;
|
|
33
34
|
deviceId?: Buffer;
|
|
@@ -48,7 +49,6 @@ export interface BirthMember {
|
|
|
48
49
|
readonly proof: Buffer;
|
|
49
50
|
}
|
|
50
51
|
export interface BirthClaim {
|
|
51
|
-
readonly deviceKeyPair?: KeyPair;
|
|
52
52
|
readonly memberId?: Buffer;
|
|
53
53
|
readonly inviteNonce?: Buffer | null;
|
|
54
54
|
}
|
|
@@ -70,6 +70,7 @@ export declare class Mesh extends ReadyResource {
|
|
|
70
70
|
get files(): Files;
|
|
71
71
|
private readonly _store;
|
|
72
72
|
private readonly _seed;
|
|
73
|
+
private readonly _compute;
|
|
73
74
|
private readonly _key;
|
|
74
75
|
private readonly _writerSeed;
|
|
75
76
|
private readonly _log;
|
|
@@ -97,6 +98,7 @@ export declare class Mesh extends ReadyResource {
|
|
|
97
98
|
get publicKey(): Buffer;
|
|
98
99
|
get devicePublicKey(): Buffer;
|
|
99
100
|
get key(): Buffer;
|
|
101
|
+
get compute(): boolean;
|
|
100
102
|
get encryptionKey(): Buffer;
|
|
101
103
|
get seed(): Buffer;
|
|
102
104
|
get blindPeerKeys(): ReadonlyArray<Buffer>;
|
|
@@ -123,6 +125,7 @@ export declare class Mesh extends ReadyResource {
|
|
|
123
125
|
private _sweepOrphanedBlobs;
|
|
124
126
|
get view(): HyperDB;
|
|
125
127
|
get localWriterKey(): Buffer<ArrayBufferLike>;
|
|
128
|
+
signDeviceClaim(secretKey: Buffer, deviceId: Buffer, joinedAt: number): Buffer;
|
|
126
129
|
get minted(): boolean;
|
|
127
130
|
get writable(): boolean;
|
|
128
131
|
get localLength(): number;
|
|
@@ -130,7 +133,7 @@ export declare class Mesh extends ReadyResource {
|
|
|
130
133
|
optimistic?: boolean;
|
|
131
134
|
}): Promise<void>;
|
|
132
135
|
batch(): MeshBatch;
|
|
133
|
-
appendBirthOp(
|
|
136
|
+
appendBirthOp(identity: Buffer | KeyPair, device?: DeviceMetadata, member?: BirthMember, claim?: BirthClaim, { room }?: {
|
|
134
137
|
room?: boolean;
|
|
135
138
|
}): Promise<void>;
|
|
136
139
|
get interrupted(): unknown;
|
|
@@ -155,8 +158,11 @@ export interface MeshDispatcher {
|
|
|
155
158
|
}
|
|
156
159
|
export declare class MeshBatch {
|
|
157
160
|
private readonly _autobee;
|
|
161
|
+
private readonly _compute;
|
|
158
162
|
private _ops;
|
|
159
|
-
constructor(autobee: Autobee<MeshView
|
|
163
|
+
constructor(autobee: Autobee<MeshView>, opts?: {
|
|
164
|
+
compute?: boolean;
|
|
165
|
+
});
|
|
160
166
|
get size(): number;
|
|
161
167
|
dispatch(name: string, payload: unknown): void;
|
|
162
168
|
flush(opts?: {
|