@qvac/core 1.0.0-rc.2 → 1.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +158 -2
- package/dist-lib/index.d.ts +1 -0
- package/dist-lib/index.js +1 -0
- package/dist-lib/lib/api/chunk-delta.d.ts +7 -2
- package/dist-lib/lib/api/chunk-delta.js +89 -7
- package/dist-lib/lib/api/chunks.js +14 -8
- package/dist-lib/lib/api/config.d.ts +4 -1
- package/dist-lib/lib/api/config.js +45 -4
- package/dist-lib/lib/api/custom-models.js +3 -5
- package/dist-lib/lib/api/devices.js +3 -1
- package/dist-lib/lib/api/files.d.ts +1 -1
- package/dist-lib/lib/api/files.js +65 -8
- package/dist-lib/lib/api/instrument.js +12 -4
- package/dist-lib/lib/api/members.js +7 -13
- package/dist-lib/lib/api/mesh.d.ts +1 -3
- package/dist-lib/lib/api/mesh.js +2 -2
- package/dist-lib/lib/api/notifications.js +8 -4
- package/dist-lib/lib/api/projects.js +5 -1
- package/dist-lib/lib/api/rag.js +32 -19
- package/dist-lib/lib/api/served.js +2 -1
- package/dist-lib/lib/api/workspace.js +0 -1
- package/dist-lib/lib/assistant/harness.d.ts +8 -2
- package/dist-lib/lib/assistant/harness.js +17 -4
- package/dist-lib/lib/assistant/history.d.ts +1 -1
- package/dist-lib/lib/assistant/history.js +19 -13
- package/dist-lib/lib/assistant/message.d.ts +6 -1
- package/dist-lib/lib/assistant/message.js +22 -2
- package/dist-lib/lib/assistant/model-round.d.ts +5 -0
- package/dist-lib/lib/assistant/model-round.js +46 -18
- package/dist-lib/lib/assistant/pdf-budget.d.ts +10 -2
- package/dist-lib/lib/assistant/pdf-budget.js +10 -11
- package/dist-lib/lib/assistant/pdf-pages.d.ts +25 -0
- package/dist-lib/lib/assistant/pdf-pages.js +75 -0
- package/dist-lib/lib/assistant/round-host.js +5 -3
- package/dist-lib/lib/assistant-client.d.ts +2 -1
- package/dist-lib/lib/assistant-client.js +24 -6
- package/dist-lib/lib/assistant-tree.d.ts +2 -0
- package/dist-lib/lib/assistant-tree.js +8 -5
- package/dist-lib/lib/assistant.d.ts +20 -7
- package/dist-lib/lib/assistant.js +468 -240
- package/dist-lib/lib/client.js +10 -1
- package/dist-lib/lib/compaction.d.ts +3 -1
- package/dist-lib/lib/compaction.js +18 -4
- package/dist-lib/lib/constants.d.ts +3 -0
- package/dist-lib/lib/constants.js +3 -0
- package/dist-lib/lib/core/chat-activity.js +13 -16
- package/dist-lib/lib/core/chat-copy.js +1 -1
- package/dist-lib/lib/core/chat-fork.js +2 -1
- package/dist-lib/lib/core/chat-move.d.ts +4 -0
- package/dist-lib/lib/core/chat-move.js +42 -11
- package/dist-lib/lib/core/chat.d.ts +0 -1
- package/dist-lib/lib/core/chat.js +1 -1
- package/dist-lib/lib/core/chunk.d.ts +14 -3
- package/dist-lib/lib/core/chunk.js +112 -22
- package/dist-lib/lib/core/collections.d.ts +12 -1
- package/dist-lib/lib/core/collections.js +12 -1
- package/dist-lib/lib/core/config-value.d.ts +6 -0
- package/dist-lib/lib/core/config-value.js +14 -0
- package/dist-lib/lib/core/contract/activity.d.ts +3 -2
- package/dist-lib/lib/core/contract/activity.js +39 -21
- package/dist-lib/lib/core/contract/agent-join.js +15 -19
- package/dist-lib/lib/core/contract/agents.js +8 -7
- package/dist-lib/lib/core/contract/chat.d.ts +3 -0
- package/dist-lib/lib/core/contract/chat.js +12 -1
- package/dist-lib/lib/core/contract/chunks.js +16 -6
- package/dist-lib/lib/core/contract/devices.js +6 -4
- package/dist-lib/lib/core/contract/index.js +2 -1
- package/dist-lib/lib/core/contract/invites.js +12 -31
- package/dist-lib/lib/core/contract/joined-meshes.js +2 -1
- package/dist-lib/lib/core/contract/mesh-rules.js +4 -0
- package/dist-lib/lib/core/contract/model-requests.js +7 -6
- package/dist-lib/lib/core/contract/project-device-keys.js +15 -6
- package/dist-lib/lib/core/contract/project-host-keys.js +5 -4
- package/dist-lib/lib/core/contract/projects.js +12 -13
- package/dist-lib/lib/core/contract/public-seeds.js +5 -5
- package/dist-lib/lib/core/contract/roles.js +2 -1
- package/dist-lib/lib/core/contract/run-requests.d.ts +1 -1
- package/dist-lib/lib/core/contract/run-requests.js +19 -13
- package/dist-lib/lib/core/contract/shipped-rows.d.ts +2 -0
- package/dist-lib/lib/core/contract/shipped-rows.js +22 -0
- package/dist-lib/lib/core/contract/workspace.js +4 -10
- package/dist-lib/lib/core/contract/writers.js +20 -6
- package/dist-lib/lib/core/devices.d.ts +2 -1
- package/dist-lib/lib/core/devices.js +4 -2
- package/dist-lib/lib/core/document-attachment.d.ts +6 -3
- package/dist-lib/lib/core/document-attachment.js +10 -5
- package/dist-lib/lib/core/files/attachments.js +3 -3
- package/dist-lib/lib/core/files/index.d.ts +8 -5
- package/dist-lib/lib/core/files/index.js +109 -18
- package/dist-lib/lib/core/files/processing/index.d.ts +1 -1
- package/dist-lib/lib/core/files/processing/index.js +8 -2
- package/dist-lib/lib/core/files/processing/source.d.ts +1 -0
- package/dist-lib/lib/core/files/processing/source.js +3 -0
- package/dist-lib/lib/core/files/processing/state.d.ts +1 -0
- package/dist-lib/lib/core/files/processing/state.js +7 -0
- package/dist-lib/lib/core/files/rag/build.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/build.js +14 -1
- package/dist-lib/lib/core/files/rag/index.d.ts +1 -1
- package/dist-lib/lib/core/files/rag/index.js +1 -1
- package/dist-lib/lib/core/files/rag/produce.js +1 -0
- package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +2 -0
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +7 -1
- package/dist-lib/lib/core/first-event.d.ts +6 -0
- package/dist-lib/lib/core/first-event.js +13 -0
- package/dist-lib/lib/core/invite.d.ts +2 -2
- package/dist-lib/lib/core/invite.js +5 -4
- package/dist-lib/lib/core/local/index.d.ts +10 -1
- package/dist-lib/lib/core/local/index.js +105 -10
- package/dist-lib/lib/core/mesh.d.ts +15 -4
- package/dist-lib/lib/core/mesh.js +128 -57
- package/dist-lib/lib/core/migrations/chat-chunks.d.ts +4 -0
- package/dist-lib/lib/core/migrations/chat-chunks.js +47 -0
- package/dist-lib/lib/core/migrations/file-index.d.ts +1 -1
- package/dist-lib/lib/core/migrations/file-index.js +6 -2
- package/dist-lib/lib/core/migrations/index.d.ts +2 -1
- package/dist-lib/lib/core/migrations/index.js +66 -9
- package/dist-lib/lib/core/notification.js +96 -23
- package/dist-lib/lib/core/pdf/figure.d.ts +22 -0
- package/dist-lib/lib/core/pdf/figure.js +64 -0
- package/dist-lib/lib/core/pdf/rasterize.d.ts +10 -1
- package/dist-lib/lib/core/pdf/rasterize.js +72 -22
- package/dist-lib/lib/core/peer-duplex.js +57 -5
- package/dist-lib/lib/core/public-mesh.js +8 -2
- package/dist-lib/lib/core/run-requests.js +2 -3
- package/dist-lib/lib/core/senders.d.ts +7 -6
- package/dist-lib/lib/core/senders.js +23 -30
- package/dist-lib/lib/core/shared-agents.d.ts +1 -0
- package/dist-lib/lib/core/shared-agents.js +47 -19
- package/dist-lib/lib/core/sync/background.d.ts +3 -15
- package/dist-lib/lib/core/sync/background.js +25 -102
- package/dist-lib/lib/core/sync/devices.js +6 -3
- package/dist-lib/lib/core/sync/index.js +12 -2
- package/dist-lib/lib/core/sync-status.js +3 -3
- package/dist-lib/lib/core.d.ts +59 -10
- package/dist-lib/lib/core.js +706 -174
- package/dist-lib/lib/credential-pusher.d.ts +11 -7
- package/dist-lib/lib/credential-pusher.js +40 -8
- package/dist-lib/lib/device-tree.d.ts +18 -0
- package/dist-lib/lib/device-tree.js +32 -0
- package/dist-lib/lib/doctor/redact.js +1 -1
- package/dist-lib/lib/errors.d.ts +4 -0
- package/dist-lib/lib/errors.js +4 -0
- package/dist-lib/lib/fs-drive-bridge.d.ts +7 -0
- package/dist-lib/lib/fs-drive-bridge.js +308 -30
- package/dist-lib/lib/integrations/setup-routes.js +7 -5
- package/dist-lib/lib/knowledge-search.d.ts +1 -1
- package/dist-lib/lib/knowledge-search.js +5 -46
- package/dist-lib/lib/kv-cache-retention.d.ts +35 -0
- package/dist-lib/lib/kv-cache-retention.js +98 -0
- package/dist-lib/lib/latest-frame.d.ts +10 -0
- package/dist-lib/lib/latest-frame.js +48 -0
- package/dist-lib/lib/model-download.d.ts +6 -1
- package/dist-lib/lib/model-download.js +32 -17
- package/dist-lib/lib/oauth/resolve.js +13 -5
- package/dist-lib/lib/reconnecting-watch.js +19 -11
- package/dist-lib/lib/run-notices.d.ts +2 -0
- package/dist-lib/lib/run-notices.js +5 -0
- package/dist-lib/lib/run-replay.d.ts +13 -1
- package/dist-lib/lib/run-replay.js +58 -21
- package/dist-lib/schema/build.js +66 -57
- package/dist-lib/schema/content.js +2 -1
- package/dist-lib/schema/engine.js +37 -5
- package/dist-lib/schema/field-order.js +7 -1
- package/dist-lib/schema/indexes.d.ts +4 -0
- package/dist-lib/schema/indexes.js +18 -0
- package/dist-lib/schema/local.js +9 -2
- package/dist-lib/schema/qvac.js +112 -4
- package/dist-lib/spec/bind.js +3 -0
- package/dist-lib/spec/calls.js +1 -0
- package/dist-lib/spec/capabilities.d.ts +2 -0
- package/dist-lib/spec/hrpc/hrpc.json +13 -0
- package/dist-lib/spec/hrpc/index.js +15 -3
- package/dist-lib/spec/hrpc/messages.js +1475 -1392
- package/dist-lib/spec/hyperschema/index.js +1475 -1392
- package/dist-lib/spec/hyperschema/schema.json +86 -1
- package/dist-lib/spec/hyperschema/types.d.ts +21 -1
- package/dist-lib/spec/local/hyperdb/messages.js +110 -54
- package/dist-lib/spec/local/hyperschema/index.js +56 -28
- package/dist-lib/spec/local/hyperschema/schema.json +55 -20
- package/dist-lib/spec/local/hyperschema/types.d.ts +8 -1
- package/dist-lib/spec/mesh/hyperdb/db.json +255 -51
- package/dist-lib/spec/mesh/hyperdb/index.js +1063 -404
- package/dist-lib/spec/mesh/hyperdb/messages.js +1647 -1214
- package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +62 -56
- package/dist-lib/spec/mesh/hyperdispatch/index.js +156 -139
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +787 -629
- package/dist-lib/spec/mesh/hyperschema/index.js +787 -629
- package/dist-lib/spec/mesh/hyperschema/schema.json +283 -174
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +29 -1
- package/package.json +23 -17
- package/worker/assistant-sidecar.mjs +3 -0
- package/dist-lib/lib/core/files/processing/settle.d.ts +0 -13
- package/dist-lib/lib/core/files/processing/settle.js +0 -86
- package/dist-lib/lib/core/migrations/device-indexes.d.ts +0 -2
- package/dist-lib/lib/core/migrations/device-indexes.js +0 -7
|
@@ -15,8 +15,19 @@ export async function yieldTurn(signal) {
|
|
|
15
15
|
throw new AbortedError();
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
+
function pageProgress(onExtracting) {
|
|
19
|
+
let chain = Promise.resolve();
|
|
20
|
+
return {
|
|
21
|
+
report: ({ pages, total }) => {
|
|
22
|
+
chain = chain.then(() => onExtracting?.(pages, total));
|
|
23
|
+
chain.catch(noop);
|
|
24
|
+
},
|
|
25
|
+
settled: () => chain
|
|
26
|
+
};
|
|
27
|
+
}
|
|
18
28
|
export async function buildArtifactPayload(input) {
|
|
19
29
|
const { embedder, knowledge, artifactId, bytes, signal, onProgress, onExtracted, extractors } = input;
|
|
30
|
+
const pages = pageProgress(input.onExtracting);
|
|
20
31
|
const document = await extractRagDocumentFromBytes({
|
|
21
32
|
id: artifactId,
|
|
22
33
|
artifactId,
|
|
@@ -26,7 +37,8 @@ export async function buildArtifactPayload(input) {
|
|
|
26
37
|
fileName: knowledge.fileName,
|
|
27
38
|
mimeType: knowledge.mimeType,
|
|
28
39
|
bytes
|
|
29
|
-
}, { extractors, signal });
|
|
40
|
+
}, { extractors, signal, onProgress: pages.report });
|
|
41
|
+
await pages.settled();
|
|
30
42
|
await yieldTurn(signal);
|
|
31
43
|
await onExtracted?.();
|
|
32
44
|
const chunks = chunkRagDocuments([document], {});
|
|
@@ -69,3 +81,4 @@ export async function buildArtifactPayload(input) {
|
|
|
69
81
|
}))
|
|
70
82
|
};
|
|
71
83
|
}
|
|
84
|
+
function noop() { }
|
|
@@ -39,6 +39,6 @@ export { joinedIndex } from './joined-index.ts';
|
|
|
39
39
|
export { canIndexKnowledge } from './policy.ts';
|
|
40
40
|
export type { IndexingDevice } from './policy.ts';
|
|
41
41
|
export type { IndexingEmbedder, IndexingProgress } from './produce.ts';
|
|
42
|
-
export { formatFullDocumentContext, fullTextBudgetChars, fullTextHits, isFullTextHit, isTruncatedFullTextHit } from './retrieval/full-text.ts';
|
|
42
|
+
export { formatFullDocumentContext, fullTextBudgetChars, fullTextHits, fullTextAttachmentId, isFullTextHit, isTruncatedFullTextHit, retrievalBudgetTokens } from './retrieval/full-text.ts';
|
|
43
43
|
export { MemoryVectorIndex, RAG_DOCUMENT_KIND, RAG_KNOWLEDGE_OFF_NOTICE, RAG_TRUNCATED_NOTICE, RAG_UNAVAILABLE_NOTICE, WEB_TOOLS, chooseRagNotice, citedByPhraseOverlap, classifyRagDocument, createRagSourceTagFilter, encodeRagArtifact, formatRagContext, isSupportedRagDocument, isWholeDocumentQuery, referencedDocuments, referencesPendingFile, retrieveRagKnowledge, searchRagChunks, sourcesFromHits, webSourcesFromToolResult, withoutDataChannel } from 'rag-extract';
|
|
44
44
|
export type { RagArtifactPayload, RagDocumentRef, RagExtractors, RagSource, VectorHit, VectorIndex } from 'rag-extract';
|
|
@@ -90,5 +90,5 @@ export class RagProcessor {
|
|
|
90
90
|
export { MAX_KNOWLEDGE_BYTES } from './limits.js';
|
|
91
91
|
export { joinedIndex } from './joined-index.js';
|
|
92
92
|
export { canIndexKnowledge } from './policy.js';
|
|
93
|
-
export { formatFullDocumentContext, fullTextBudgetChars, fullTextHits, isFullTextHit, isTruncatedFullTextHit } from './retrieval/full-text.js';
|
|
93
|
+
export { formatFullDocumentContext, fullTextBudgetChars, fullTextHits, fullTextAttachmentId, isFullTextHit, isTruncatedFullTextHit, retrievalBudgetTokens } from './retrieval/full-text.js';
|
|
94
94
|
export { MemoryVectorIndex, RAG_DOCUMENT_KIND, RAG_KNOWLEDGE_OFF_NOTICE, RAG_TRUNCATED_NOTICE, RAG_UNAVAILABLE_NOTICE, WEB_TOOLS, chooseRagNotice, citedByPhraseOverlap, classifyRagDocument, createRagSourceTagFilter, encodeRagArtifact, formatRagContext, isSupportedRagDocument, isWholeDocumentQuery, referencedDocuments, referencesPendingFile, retrieveRagKnowledge, searchRagChunks, sourcesFromHits, webSourcesFromToolResult, withoutDataChannel } from 'rag-extract';
|
|
@@ -2,10 +2,12 @@ import type { QvacKnowledge } from '../../../../../spec/mesh/hyperschema/types.d
|
|
|
2
2
|
import type { Mesh } from '../../../mesh.ts';
|
|
3
3
|
import { type VectorHit } from 'rag-extract';
|
|
4
4
|
export declare function fullTextBudgetChars(ctxSize: number): number;
|
|
5
|
+
export declare function retrievalBudgetTokens(ctxSize: number): number | undefined;
|
|
5
6
|
export interface IdentifiedHit {
|
|
6
7
|
readonly id: string;
|
|
7
8
|
}
|
|
8
9
|
export declare function isFullTextHit(hit: IdentifiedHit): boolean;
|
|
10
|
+
export declare function fullTextAttachmentId(hit: IdentifiedHit): string | null;
|
|
9
11
|
export type FullTextCoverage = {
|
|
10
12
|
readonly unit: 'pages';
|
|
11
13
|
readonly included: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as z from 'zod';
|
|
2
|
-
import { classifyRagDocument, extractPdfHead, extractRagDocumentFromBytes, parseRagMetadata, RAG_DOCUMENT_KIND } from 'rag-extract';
|
|
2
|
+
import { classifyRagDocument, DEFAULT_CHUNK_BUDGET_TOKENS, extractPdfHead, extractRagDocumentFromBytes, parseRagMetadata, RAG_DOCUMENT_KIND } from 'rag-extract';
|
|
3
3
|
const DEFAULT_FULL_TEXT_BUDGET_TOKENS = 4096;
|
|
4
4
|
const CHARS_PER_TOKEN = 4;
|
|
5
5
|
const FULL_TEXT_KINDS = new Set([
|
|
@@ -14,10 +14,16 @@ export function fullTextBudgetChars(ctxSize) {
|
|
|
14
14
|
const tokens = ctxSize > 0 ? Math.floor(ctxSize / 2) : DEFAULT_FULL_TEXT_BUDGET_TOKENS;
|
|
15
15
|
return tokens * CHARS_PER_TOKEN;
|
|
16
16
|
}
|
|
17
|
+
export function retrievalBudgetTokens(ctxSize) {
|
|
18
|
+
return ctxSize > 0 ? Math.min(DEFAULT_CHUNK_BUDGET_TOKENS, Math.floor(ctxSize / 4)) : undefined;
|
|
19
|
+
}
|
|
17
20
|
const FULL_TEXT_HIT_PREFIX = 'full-text-';
|
|
18
21
|
export function isFullTextHit(hit) {
|
|
19
22
|
return hit.id.startsWith(FULL_TEXT_HIT_PREFIX);
|
|
20
23
|
}
|
|
24
|
+
export function fullTextAttachmentId(hit) {
|
|
25
|
+
return isFullTextHit(hit) ? hit.id.slice(FULL_TEXT_HIT_PREFIX.length) : null;
|
|
26
|
+
}
|
|
21
27
|
const FullTextExtrasSchema = z.object({
|
|
22
28
|
truncated: z.boolean().optional().catch(undefined),
|
|
23
29
|
coverage: z
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function firstEvent(sources) {
|
|
2
|
+
return new Promise((resolve) => {
|
|
3
|
+
const done = () => {
|
|
4
|
+
for (const [emitter, name] of sources) {
|
|
5
|
+
emitter.off(name, done);
|
|
6
|
+
}
|
|
7
|
+
resolve();
|
|
8
|
+
};
|
|
9
|
+
for (const [emitter, name] of sources) {
|
|
10
|
+
emitter.once(name, done);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { QvacAutobeeHead } from '../../spec/mesh/hyperschema/types.d.ts';
|
|
1
|
+
import type { QvacAutobeeHead, QvacInvitePublicHead } from '../../spec/mesh/hyperschema/types.d.ts';
|
|
2
2
|
import type { RecoveryProof } from './mesh.ts';
|
|
3
3
|
export interface MeshInviteNode {
|
|
4
4
|
readonly host: string;
|
|
@@ -13,13 +13,13 @@ export interface MeshInvite {
|
|
|
13
13
|
readonly memberInvite?: boolean;
|
|
14
14
|
readonly memberId?: Buffer;
|
|
15
15
|
readonly inviteNonce?: Buffer;
|
|
16
|
-
readonly compute?: boolean;
|
|
17
16
|
readonly recovery?: RecoveryProof;
|
|
18
17
|
readonly inviterName?: string;
|
|
19
18
|
readonly deviceSeed?: Buffer;
|
|
20
19
|
readonly deviceProof?: Buffer;
|
|
21
20
|
readonly workspace?: boolean;
|
|
22
21
|
readonly workspaceName?: string;
|
|
22
|
+
readonly publicHeads?: ReadonlyArray<QvacInvitePublicHead>;
|
|
23
23
|
}
|
|
24
24
|
export declare function encodeMeshInvite(invite: MeshInvite): string;
|
|
25
25
|
export declare function decodeMeshInvite(raw: string): MeshInvite | null;
|
|
@@ -15,12 +15,13 @@ export function encodeMeshInvite(invite) {
|
|
|
15
15
|
memberInvite: invite.memberInvite ?? false,
|
|
16
16
|
memberId: invite.memberId ?? null,
|
|
17
17
|
inviteNonce: invite.inviteNonce ?? null,
|
|
18
|
-
compute:
|
|
18
|
+
compute: false,
|
|
19
19
|
inviterName: invite.inviterName ?? null,
|
|
20
20
|
deviceSeed: invite.deviceSeed ?? null,
|
|
21
21
|
deviceProof: invite.deviceProof ?? null,
|
|
22
22
|
workspace: invite.workspace ?? false,
|
|
23
|
-
workspaceName: invite.workspaceName ?? null
|
|
23
|
+
workspaceName: invite.workspaceName ?? null,
|
|
24
|
+
publicHeads: [...(invite.publicHeads ?? [])]
|
|
24
25
|
};
|
|
25
26
|
const prefix = invite.memberInvite ? MEMBER_INVITE_PREFIX : DEVICE_INVITE_PREFIX;
|
|
26
27
|
return prefix + z32.encode(encodeStruct(INVITE_STRUCT, payload));
|
|
@@ -50,11 +51,11 @@ export function decodeMeshInvite(raw) {
|
|
|
50
51
|
memberInvite: payload.memberInvite ?? false,
|
|
51
52
|
memberId: payload.memberId ?? undefined,
|
|
52
53
|
inviteNonce: payload.inviteNonce ?? undefined,
|
|
53
|
-
compute: payload.compute ?? false,
|
|
54
54
|
inviterName: payload.inviterName ?? undefined,
|
|
55
55
|
deviceSeed: payload.deviceSeed ?? undefined,
|
|
56
56
|
deviceProof: payload.deviceProof ?? undefined,
|
|
57
57
|
workspace: payload.workspace ?? false,
|
|
58
|
-
workspaceName: payload.workspaceName ?? undefined
|
|
58
|
+
workspaceName: payload.workspaceName ?? undefined,
|
|
59
|
+
publicHeads: payload.publicHeads ?? []
|
|
59
60
|
};
|
|
60
61
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import CorestoreStorage from 'hypercore-storage';
|
|
2
2
|
import HyperDB from 'hyperdb';
|
|
3
3
|
import type { LocalAccountRecovery, LocalAppConfig, LocalCapabilityProfile, LocalChatMove, LocalMeshUpdate, LocalMeshName, LocalChatNotify, LocalChatOrder, LocalCustomModel, LocalIdentity, LocalMemberProof, LocalMeshDeparture, LocalMeshMembership, LocalMeshPurge, LocalModelDownload, LocalModelNotify } from '../../../spec/local/hyperschema/types.d.ts';
|
|
4
|
+
import type { QvacAutobeeHead } from '../../../spec/mesh/hyperschema/types.d.ts';
|
|
4
5
|
import type { DeviceMetadata } from '../mesh.ts';
|
|
5
6
|
import type { MeshRole } from '../contract/roles.ts';
|
|
6
7
|
import { LocalFiles } from './files.ts';
|
|
@@ -46,6 +47,7 @@ export interface ResolvedSession {
|
|
|
46
47
|
readonly writerSeed: string | undefined;
|
|
47
48
|
readonly role?: MeshRole;
|
|
48
49
|
readonly workspaceKey?: Buffer;
|
|
50
|
+
readonly bootFrom?: QvacAutobeeHead | null;
|
|
49
51
|
}
|
|
50
52
|
export interface ArchivedMeshMembership extends LocalMeshMembership {
|
|
51
53
|
readonly leftAt: number;
|
|
@@ -146,7 +148,7 @@ declare class LocalStore {
|
|
|
146
148
|
putModelDownloadRow(row: LocalModelDownload): Promise<void>;
|
|
147
149
|
deleteModelDownloadRow(name: string): Promise<void>;
|
|
148
150
|
getCustomModelRows(): Promise<LocalCustomModel[]>;
|
|
149
|
-
|
|
151
|
+
putCustomModelRowIfLabelAvailable(row: LocalCustomModel): Promise<boolean>;
|
|
150
152
|
deleteCustomModelRow(name: string): Promise<void>;
|
|
151
153
|
ensureDevice(publicKey: Buffer, seed?: DeviceMetadata): Promise<DeviceMetadata | null>;
|
|
152
154
|
renameDevice(publicKey: Buffer, name: string): Promise<void>;
|
|
@@ -164,6 +166,7 @@ declare class LocalStore {
|
|
|
164
166
|
meshNames(): Promise<LocalMeshName[]>;
|
|
165
167
|
keepMeshName(row: LocalMeshName): Promise<void>;
|
|
166
168
|
recordChatMove(row: LocalChatMove): Promise<void>;
|
|
169
|
+
dropChatMove({ meshKey, chatId }: LocalChatMove): Promise<void>;
|
|
167
170
|
recordAccountRecovery(row: LocalAccountRecovery): Promise<void>;
|
|
168
171
|
replaceIdentity(identity: Omit<LocalIdentity, 'id'>): Promise<void>;
|
|
169
172
|
ensureIdentity(devicePublicKey: Buffer, createdAt: number): Promise<EnsuredIdentity>;
|
|
@@ -180,6 +183,10 @@ declare class LocalStore {
|
|
|
180
183
|
departureRole(departure: LocalMeshDeparture): Promise<MeshRole>;
|
|
181
184
|
deleteDeparture(key: Buffer): Promise<void>;
|
|
182
185
|
archiveMesh(key: Buffer): Promise<void>;
|
|
186
|
+
markRetired(keys: Buffer[], accountKey: Buffer): Promise<void>;
|
|
187
|
+
unretire(accountKey: Buffer): Promise<Buffer[]>;
|
|
188
|
+
markKicked(key: Buffer): Promise<void>;
|
|
189
|
+
restoreMesh(key: Buffer): Promise<void>;
|
|
183
190
|
readPurge(key: Buffer): Promise<LocalMeshPurge | null>;
|
|
184
191
|
pendingPurges(): Promise<LocalMeshPurge[]>;
|
|
185
192
|
dropMesh(key: Buffer, opts?: DropMeshOptions): Promise<boolean>;
|
|
@@ -189,6 +196,8 @@ declare class LocalStore {
|
|
|
189
196
|
private _dropMeshConfig;
|
|
190
197
|
private _dropRows;
|
|
191
198
|
markAwaitingAdmission(key: Buffer, opts: MarkAwaitingAdmissionOptions): Promise<void>;
|
|
199
|
+
markJoinedUnder(key: Buffer, joinedAt: number): Promise<void>;
|
|
200
|
+
joinedUnder(key: Buffer): Promise<number | null>;
|
|
192
201
|
setMeshRole(key: Buffer, role: MeshRole): Promise<void>;
|
|
193
202
|
awaitsAdmission(key: Buffer): Promise<boolean>;
|
|
194
203
|
markMeshMigrated(key: Buffer, migratedAt: number): Promise<void>;
|
|
@@ -10,6 +10,7 @@ import b4a from 'b4a';
|
|
|
10
10
|
import { dropMeshFileCursors, LocalFiles } from './files.js';
|
|
11
11
|
import { LocalRunLogs } from './run-logs.js';
|
|
12
12
|
import { LOCAL_ACCOUNT_RECOVERY, LOCAL_ACTIVE_MESH, LOCAL_APP_CONFIG, LOCAL_CHAT_MOVES, LOCAL_MESH_UPDATES, LOCAL_MESH_PURGES, LOCAL_MESH_NAMES, LOCAL_CHAT_NOTIFY, LOCAL_CHAT_ORDER, LOCAL_CHAT_ORDER_BY_KEY, LOCAL_CONFIG, LOCAL_CUSTOM_MODEL, LOCAL_FILES, LOCAL_DEVICE, LOCAL_IDENTITY, LOCAL_MEMBERSHIP, LOCAL_MEMBER_PROOF, LOCAL_MESH_DEPARTURE, LOCAL_MESH_HISTORY, LOCAL_MESH_MEMBERSHIP, LOCAL_MESH_SESSION, LOCAL_MODEL_DOWNLOAD, LOCAL_MODEL_NOTIFY, LOCAL_RUN_LOGS, LOCAL_RUN_LOG_STEPS } from '../collections.js';
|
|
13
|
+
import { configValue, readConfigValue } from '../config-value.js';
|
|
13
14
|
export const MESH_LOCAL_COLLECTIONS = [
|
|
14
15
|
{ collection: LOCAL_MESH_MEMBERSHIP, field: 'key' },
|
|
15
16
|
{ collection: LOCAL_MESH_DEPARTURE, field: 'key' },
|
|
@@ -36,7 +37,8 @@ function sessionOf(row) {
|
|
|
36
37
|
baseKey: row.key ?? undefined,
|
|
37
38
|
writerSeed: row.writerSeed ?? undefined,
|
|
38
39
|
role: meshRole(row.role),
|
|
39
|
-
workspaceKey: row.workspaceKey ?? undefined
|
|
40
|
+
workspaceKey: row.workspaceKey ?? undefined,
|
|
41
|
+
bootFrom: row.bootKey ? { key: row.bootKey, length: row.bootLength ?? 0 } : null
|
|
40
42
|
};
|
|
41
43
|
}
|
|
42
44
|
function meshRole(role) {
|
|
@@ -70,12 +72,12 @@ class LocalStore {
|
|
|
70
72
|
}
|
|
71
73
|
async get(key) {
|
|
72
74
|
const row = await this._db.get(LOCAL_CONFIG, { key });
|
|
73
|
-
return row === null ? null : row
|
|
75
|
+
return row === null ? null : readConfigValue(row);
|
|
74
76
|
}
|
|
75
77
|
set(key, value) {
|
|
76
78
|
return this._locked(async () => {
|
|
77
79
|
const tx = this._db.transaction();
|
|
78
|
-
await tx.insert(LOCAL_CONFIG, { key, value });
|
|
80
|
+
await tx.insert(LOCAL_CONFIG, { key, ...configValue(value) });
|
|
79
81
|
await tx.flush();
|
|
80
82
|
});
|
|
81
83
|
}
|
|
@@ -83,7 +85,7 @@ class LocalStore {
|
|
|
83
85
|
return this._locked(async () => {
|
|
84
86
|
const tx = this._db.transaction();
|
|
85
87
|
for (const { key, value } of entries) {
|
|
86
|
-
await tx.insert(LOCAL_CONFIG, { key, value });
|
|
88
|
+
await tx.insert(LOCAL_CONFIG, { key, ...configValue(value) });
|
|
87
89
|
}
|
|
88
90
|
await tx.flush();
|
|
89
91
|
});
|
|
@@ -95,10 +97,10 @@ class LocalStore {
|
|
|
95
97
|
return null;
|
|
96
98
|
}
|
|
97
99
|
const tx = this._db.transaction();
|
|
98
|
-
await tx.insert(LOCAL_CONFIG, { key: toKey
|
|
100
|
+
await tx.insert(LOCAL_CONFIG, { ...row, key: toKey });
|
|
99
101
|
await tx.delete(LOCAL_CONFIG, { key: fromKey });
|
|
100
102
|
await tx.flush();
|
|
101
|
-
return row
|
|
103
|
+
return readConfigValue(row);
|
|
102
104
|
});
|
|
103
105
|
}
|
|
104
106
|
deleteAll(keys) {
|
|
@@ -285,11 +287,20 @@ class LocalStore {
|
|
|
285
287
|
}
|
|
286
288
|
return rows;
|
|
287
289
|
}
|
|
288
|
-
|
|
290
|
+
putCustomModelRowIfLabelAvailable(row) {
|
|
289
291
|
return this._locked(async () => {
|
|
292
|
+
const rows = [];
|
|
293
|
+
for await (const current of this._db.find(LOCAL_CUSTOM_MODEL)) {
|
|
294
|
+
rows.push(current);
|
|
295
|
+
}
|
|
296
|
+
const taken = rows.some((current) => (current.label || current.name) === row.label && current.name !== row.name);
|
|
297
|
+
if (taken) {
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
290
300
|
const tx = this._db.transaction();
|
|
291
301
|
await tx.insert(LOCAL_CUSTOM_MODEL, row);
|
|
292
302
|
await tx.flush();
|
|
303
|
+
return true;
|
|
293
304
|
});
|
|
294
305
|
}
|
|
295
306
|
deleteCustomModelRow(name) {
|
|
@@ -427,6 +438,13 @@ class LocalStore {
|
|
|
427
438
|
await tx.flush();
|
|
428
439
|
});
|
|
429
440
|
}
|
|
441
|
+
dropChatMove({ meshKey, chatId }) {
|
|
442
|
+
return this._locked(async () => {
|
|
443
|
+
const tx = this._db.transaction();
|
|
444
|
+
await tx.delete(LOCAL_CHAT_MOVES, { meshKey, chatId });
|
|
445
|
+
await tx.flush();
|
|
446
|
+
});
|
|
447
|
+
}
|
|
430
448
|
recordAccountRecovery(row) {
|
|
431
449
|
return this._locked(async () => {
|
|
432
450
|
const tx = this._db.transaction();
|
|
@@ -563,8 +581,11 @@ class LocalStore {
|
|
|
563
581
|
seed: session.seed,
|
|
564
582
|
writerSeed: session.writerSeed,
|
|
565
583
|
awaitingAdmission: existing?.awaitingAdmission,
|
|
584
|
+
bootKey: session.bootFrom?.key,
|
|
585
|
+
bootLength: session.bootFrom?.length,
|
|
566
586
|
role: session.role ?? existing?.role,
|
|
567
|
-
workspaceKey: session.workspaceKey ?? existing?.workspaceKey
|
|
587
|
+
workspaceKey: session.workspaceKey ?? existing?.workspaceKey,
|
|
588
|
+
joinedAt: existing?.joinedAt
|
|
568
589
|
});
|
|
569
590
|
if (minted) {
|
|
570
591
|
await tx.insert(LOCAL_ACTIVE_MESH, { deviceId, homeMeshKey: key });
|
|
@@ -640,6 +661,64 @@ class LocalStore {
|
|
|
640
661
|
await tx.flush();
|
|
641
662
|
});
|
|
642
663
|
}
|
|
664
|
+
markRetired(keys, accountKey) {
|
|
665
|
+
return this._locked(async () => {
|
|
666
|
+
const tx = this._db.transaction();
|
|
667
|
+
for (const key of keys) {
|
|
668
|
+
const existing = await tx.get(LOCAL_MESH_MEMBERSHIP, { key });
|
|
669
|
+
if (existing) {
|
|
670
|
+
await tx.insert(LOCAL_MESH_MEMBERSHIP, {
|
|
671
|
+
...existing,
|
|
672
|
+
retiredUnder: accountKey
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
await tx.flush();
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
unretire(accountKey) {
|
|
680
|
+
return this._locked(async () => {
|
|
681
|
+
const keys = [];
|
|
682
|
+
const tx = this._db.transaction();
|
|
683
|
+
for await (const row of this._db.find(LOCAL_MESH_MEMBERSHIP)) {
|
|
684
|
+
if (row.retiredUnder && b4a.equals(row.retiredUnder, accountKey)) {
|
|
685
|
+
await tx.insert(LOCAL_MESH_MEMBERSHIP, {
|
|
686
|
+
...row,
|
|
687
|
+
retiredUnder: undefined
|
|
688
|
+
});
|
|
689
|
+
keys.push(row.key);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
await tx.flush();
|
|
693
|
+
return keys;
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
markKicked(key) {
|
|
697
|
+
return this._locked(async () => {
|
|
698
|
+
const existing = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
|
|
699
|
+
if (!existing) {
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
const tx = this._db.transaction();
|
|
703
|
+
await tx.insert(LOCAL_MESH_MEMBERSHIP, { ...existing, kicked: true });
|
|
704
|
+
await tx.flush();
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
restoreMesh(key) {
|
|
708
|
+
return this._locked(async () => {
|
|
709
|
+
const existing = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
|
|
710
|
+
if (!existing) {
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
const tx = this._db.transaction();
|
|
714
|
+
await tx.insert(LOCAL_MESH_MEMBERSHIP, {
|
|
715
|
+
...existing,
|
|
716
|
+
leftAt: undefined,
|
|
717
|
+
wasHome: undefined
|
|
718
|
+
});
|
|
719
|
+
await tx.flush();
|
|
720
|
+
});
|
|
721
|
+
}
|
|
643
722
|
readPurge(key) {
|
|
644
723
|
return this._db.get(LOCAL_MESH_PURGES, { key });
|
|
645
724
|
}
|
|
@@ -716,17 +795,33 @@ class LocalStore {
|
|
|
716
795
|
const { awaitingAdmission } = opts;
|
|
717
796
|
return this._locked(async () => {
|
|
718
797
|
const existing = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
|
|
719
|
-
|
|
798
|
+
const settled = awaitingAdmission || !existing?.bootKey;
|
|
799
|
+
if (!existing || (!!existing.awaitingAdmission === awaitingAdmission && settled)) {
|
|
720
800
|
return;
|
|
721
801
|
}
|
|
802
|
+
const { bootKey, bootLength, ...rest } = existing;
|
|
722
803
|
const tx = this._db.transaction();
|
|
723
804
|
await tx.insert(LOCAL_MESH_MEMBERSHIP, {
|
|
724
|
-
...existing,
|
|
805
|
+
...(awaitingAdmission ? existing : rest),
|
|
725
806
|
awaitingAdmission
|
|
726
807
|
});
|
|
727
808
|
await tx.flush();
|
|
728
809
|
});
|
|
729
810
|
}
|
|
811
|
+
markJoinedUnder(key, joinedAt) {
|
|
812
|
+
return this._locked(async () => {
|
|
813
|
+
const existing = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
|
|
814
|
+
if (!existing || existing.joinedAt === joinedAt) {
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
const tx = this._db.transaction();
|
|
818
|
+
await tx.insert(LOCAL_MESH_MEMBERSHIP, { ...existing, joinedAt });
|
|
819
|
+
await tx.flush();
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
async joinedUnder(key) {
|
|
823
|
+
return (await this._membership(key))?.joinedAt || null;
|
|
824
|
+
}
|
|
730
825
|
setMeshRole(key, role) {
|
|
731
826
|
return this._locked(async () => {
|
|
732
827
|
const existing = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
|
|
@@ -49,11 +49,13 @@ export interface MeshOptions {
|
|
|
49
49
|
pendingUpdates?: PendingUpdates | null;
|
|
50
50
|
slowWriteMs?: number;
|
|
51
51
|
slowDrainMs?: number;
|
|
52
|
-
syncBatch?: number;
|
|
53
|
-
syncPauseMs?: number;
|
|
54
52
|
}
|
|
53
|
+
export declare const SCHEMA_VERSION: number;
|
|
55
54
|
export declare function meshPublicKeyFromSeed(seed: Buffer): Buffer;
|
|
56
|
-
export
|
|
55
|
+
export interface TrustScope {
|
|
56
|
+
readonly ourMemberId: Buffer | null;
|
|
57
|
+
}
|
|
58
|
+
export declare function isTrustedWriter(snap: HyperDB, writerKey: Buffer, { ourMemberId }: TrustScope): Promise<boolean>;
|
|
57
59
|
export type BirthRow = {
|
|
58
60
|
readonly id: Buffer;
|
|
59
61
|
readonly joinedAt: number;
|
|
@@ -141,6 +143,8 @@ export declare class Mesh extends ReadyResource {
|
|
|
141
143
|
private readonly _slowDrainMs;
|
|
142
144
|
private _stallReported;
|
|
143
145
|
private _admitted;
|
|
146
|
+
private _refused;
|
|
147
|
+
private _kickSeen;
|
|
144
148
|
private _birth;
|
|
145
149
|
private _rulesRaised;
|
|
146
150
|
private _autobee;
|
|
@@ -200,6 +204,8 @@ export declare class Mesh extends ReadyResource {
|
|
|
200
204
|
private _watchStall;
|
|
201
205
|
private _endStall;
|
|
202
206
|
private _reportStall;
|
|
207
|
+
private _fastForwardHeld;
|
|
208
|
+
private _writersHeld;
|
|
203
209
|
private _coresNotHeld;
|
|
204
210
|
private _coreHeld;
|
|
205
211
|
batch(): MeshBatch;
|
|
@@ -213,7 +219,7 @@ export declare class Mesh extends ReadyResource {
|
|
|
213
219
|
private _seedDefaults;
|
|
214
220
|
get interrupted(): unknown;
|
|
215
221
|
throwIfInterrupted(): void;
|
|
216
|
-
waitForWritable(
|
|
222
|
+
waitForWritable(): Promise<void>;
|
|
217
223
|
pendingUploads(): number;
|
|
218
224
|
suspend(): Promise<void>;
|
|
219
225
|
resume(): void;
|
|
@@ -238,8 +244,13 @@ export declare class Mesh extends ReadyResource {
|
|
|
238
244
|
private _arrive;
|
|
239
245
|
private _readLanding;
|
|
240
246
|
checkOwnAdmission(): Promise<void>;
|
|
247
|
+
kickDirty(): Promise<void>;
|
|
248
|
+
private _kickState;
|
|
249
|
+
readKicked(): Promise<boolean>;
|
|
250
|
+
checkResumedRefusal(): Promise<boolean>;
|
|
241
251
|
checkResumedRevocation(): Promise<'kicked' | 'left' | null>;
|
|
242
252
|
ownWriterRefused(): Promise<boolean>;
|
|
253
|
+
private _ownRow;
|
|
243
254
|
}
|
|
244
255
|
export interface MeshDispatcher {
|
|
245
256
|
dispatch(name: string, payload: unknown): void | Promise<void>;
|