@qvac/core 0.6.4 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/CHANGELOG.md +78 -1
  2. package/README.md +20 -4
  3. package/dist-lib/lib/api/chat-move.d.ts +3 -0
  4. package/dist-lib/lib/api/chat-move.js +7 -0
  5. package/dist-lib/lib/api/chat.d.ts +1 -1
  6. package/dist-lib/lib/api/chat.js +2 -1
  7. package/dist-lib/lib/api/chunk-delta.d.ts +7 -0
  8. package/dist-lib/lib/api/chunk-delta.js +33 -0
  9. package/dist-lib/lib/api/chunks.d.ts +1 -1
  10. package/dist-lib/lib/api/chunks.js +6 -3
  11. package/dist-lib/lib/api/index.d.ts +2 -0
  12. package/dist-lib/lib/api/index.js +2 -0
  13. package/dist-lib/lib/api/mesh.d.ts +2 -1
  14. package/dist-lib/lib/api/mesh.js +4 -0
  15. package/dist-lib/lib/assistant/harness.d.ts +8 -10
  16. package/dist-lib/lib/assistant.js +1 -1
  17. package/dist-lib/lib/constants.d.ts +1 -0
  18. package/dist-lib/lib/constants.js +1 -0
  19. package/dist-lib/lib/core/archived-mesh.js +3 -42
  20. package/dist-lib/lib/core/chat-activity.js +23 -10
  21. package/dist-lib/lib/core/chat-copy.d.ts +24 -0
  22. package/dist-lib/lib/core/chat-copy.js +115 -0
  23. package/dist-lib/lib/core/chat-move.d.ts +65 -0
  24. package/dist-lib/lib/core/chat-move.js +525 -0
  25. package/dist-lib/lib/core/chat.d.ts +6 -0
  26. package/dist-lib/lib/core/chat.js +11 -3
  27. package/dist-lib/lib/core/collections.d.ts +2 -0
  28. package/dist-lib/lib/core/collections.js +2 -0
  29. package/dist-lib/lib/core/contract/compute.d.ts +1 -1
  30. package/dist-lib/lib/core/contract/compute.js +2 -1
  31. package/dist-lib/lib/core/contract/index.js +2 -0
  32. package/dist-lib/lib/core/contract/invites.d.ts +1 -0
  33. package/dist-lib/lib/core/contract/invites.js +1 -1
  34. package/dist-lib/lib/core/contract/mesh-name.d.ts +3 -0
  35. package/dist-lib/lib/core/contract/mesh-name.js +26 -0
  36. package/dist-lib/lib/core/contract/writers.js +10 -3
  37. package/dist-lib/lib/core/files/index.d.ts +1 -1
  38. package/dist-lib/lib/core/files/index.js +1 -1
  39. package/dist-lib/lib/core/files/preview/index.js +4 -1
  40. package/dist-lib/lib/core/files/processing/source.js +4 -1
  41. package/dist-lib/lib/core/files/store/index.d.ts +2 -1
  42. package/dist-lib/lib/core/files/store/index.js +2 -1
  43. package/dist-lib/lib/core/files/store/reference.d.ts +3 -0
  44. package/dist-lib/lib/core/files/store/reference.js +8 -0
  45. package/dist-lib/lib/core/files/store/sweep.js +3 -1
  46. package/dist-lib/lib/core/local/index.d.ts +4 -1
  47. package/dist-lib/lib/core/local/index.js +14 -1
  48. package/dist-lib/lib/core/mesh-seed-handoff.d.ts +3 -1
  49. package/dist-lib/lib/core/mesh-seed-handoff.js +1 -0
  50. package/dist-lib/lib/core/mesh.d.ts +5 -1
  51. package/dist-lib/lib/core/mesh.js +16 -1
  52. package/dist-lib/lib/core/sync/index.js +9 -1
  53. package/dist-lib/lib/core.d.ts +9 -0
  54. package/dist-lib/lib/core.js +156 -30
  55. package/dist-lib/lib/custom-model-pusher.js +9 -5
  56. package/dist-lib/lib/mesh-scoped-engine.js +5 -0
  57. package/dist-lib/schema/engine.js +80 -1
  58. package/dist-lib/schema/local.js +17 -0
  59. package/dist-lib/schema/qvac.d.ts +2 -0
  60. package/dist-lib/schema/qvac.js +16 -0
  61. package/dist-lib/spec/bind.js +25 -0
  62. package/dist-lib/spec/calls.js +5 -0
  63. package/dist-lib/spec/capabilities.d.ts +10 -0
  64. package/dist-lib/spec/hrpc/hrpc.json +65 -0
  65. package/dist-lib/spec/hrpc/index.js +66 -4
  66. package/dist-lib/spec/hrpc/messages.js +1398 -1154
  67. package/dist-lib/spec/hyperschema/index.js +1398 -1154
  68. package/dist-lib/spec/hyperschema/schema.json +204 -0
  69. package/dist-lib/spec/hyperschema/types.d.ts +47 -0
  70. package/dist-lib/spec/local/hyperdb/db.json +17 -1
  71. package/dist-lib/spec/local/hyperdb/index.js +83 -2
  72. package/dist-lib/spec/local/hyperdb/messages.js +340 -136
  73. package/dist-lib/spec/local/hyperschema/index.js +107 -2
  74. package/dist-lib/spec/local/hyperschema/schema.json +78 -1
  75. package/dist-lib/spec/local/hyperschema/types.d.ts +18 -1
  76. package/dist-lib/spec/mesh/hyperdb/db.json +16 -1
  77. package/dist-lib/spec/mesh/hyperdb/index.js +71 -2
  78. package/dist-lib/spec/mesh/hyperdb/messages.js +454 -228
  79. package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +7 -1
  80. package/dist-lib/spec/mesh/hyperdispatch/index.js +18 -1
  81. package/dist-lib/spec/mesh/hyperdispatch/messages.js +150 -2
  82. package/dist-lib/spec/mesh/hyperschema/index.js +150 -2
  83. package/dist-lib/spec/mesh/hyperschema/schema.json +76 -1
  84. package/dist-lib/spec/mesh/hyperschema/types.d.ts +21 -1
  85. package/package.json +5 -3
  86. package/tui/app.mjs +89 -3
  87. package/tui/lib/move-command.mjs +17 -0
@@ -1,5 +1,5 @@
1
1
  import type { Router } from '../../../spec/mesh/hyperdispatch/index.js';
2
- declare const DROPPED: readonly ['@qvac/append-chunk', '@qvac/update-chunk', '@qvac/resolve-approval', '@qvac/put-agent', '@qvac/put-approval-rule', '@qvac/seed-defaults', '@qvac/add-knowledge', '@qvac/remove-knowledge', '@qvac/add-knowledge-artifact', '@qvac/claim-indexing', '@qvac/resolve-indexing', '@qvac/put-chat', '@qvac/put-tool-configs', '@qvac/append-tool-activity', '@qvac/migrate-agent-catalog', '@qvac/reindex-agents', '@qvac/put-chat-group', '@qvac/put-joined-mesh', '@qvac/purge-chat'];
2
+ declare const DROPPED: readonly ['@qvac/append-chunk', '@qvac/update-chunk', '@qvac/resolve-approval', '@qvac/put-agent', '@qvac/put-approval-rule', '@qvac/seed-defaults', '@qvac/add-knowledge', '@qvac/remove-knowledge', '@qvac/add-knowledge-artifact', '@qvac/claim-indexing', '@qvac/resolve-indexing', '@qvac/put-chat', '@qvac/put-tool-configs', '@qvac/append-tool-activity', '@qvac/migrate-agent-catalog', '@qvac/reindex-agents', '@qvac/put-chat-group', '@qvac/put-joined-mesh', '@qvac/purge-chat', '@qvac/name-mesh'];
3
3
  export type DroppedComputeRoute = (typeof DROPPED)[number];
4
4
  export declare function droppedComputeRoutes(): ReadonlyArray<DroppedComputeRoute>;
5
5
  export declare class ComputeRouteDropped extends Error {
@@ -17,7 +17,8 @@ const DROPPED = [
17
17
  '@qvac/reindex-agents',
18
18
  '@qvac/put-chat-group',
19
19
  '@qvac/put-joined-mesh',
20
- '@qvac/purge-chat'
20
+ '@qvac/purge-chat',
21
+ '@qvac/name-mesh'
21
22
  ];
22
23
  const DROPPED_ROUTES = new Set(DROPPED);
23
24
  export function droppedComputeRoutes() {
@@ -12,6 +12,7 @@ import { registerKnowledgeRoutes } from './knowledge.js';
12
12
  import { registerJoinedMeshRoutes } from './joined-meshes.js';
13
13
  import { registerMemberRoutes } from './members.js';
14
14
  import { registerMeshKindRoutes } from './mesh-kind.js';
15
+ import { registerMeshNameRoutes } from './mesh-name.js';
15
16
  import { registerSeedDefaultsRoutes } from './seed-defaults.js';
16
17
  import { registerToolActivityRoutes } from './tool-activity.js';
17
18
  import { registerToolConfigsRoutes } from './tool-configs.js';
@@ -54,6 +55,7 @@ export function registerRoutes(target, { compute = false } = {}) {
54
55
  registerMemberRoutes(router);
55
56
  registerInviteRoutes(router, { compute });
56
57
  registerMeshKindRoutes(router, { compute });
58
+ registerMeshNameRoutes(router);
57
59
  if (compute) {
58
60
  registerComputeDrops(router);
59
61
  }
@@ -10,6 +10,7 @@ interface InviteStandingOptions {
10
10
  }
11
11
  export declare function inviteStanding(tx: HyperDB, { device, memberId, grant, compute }: InviteStandingOptions): Promise<'present' | 'removed' | null>;
12
12
  export declare function belongsToAnotherMember(tx: HyperDB, device: QvacDevice | null, memberId: Buffer): Promise<boolean>;
13
+ export declare function removedBy(tx: HyperDB, device: QvacDevice): Promise<'itself' | 'own-member' | 'another-member'>;
13
14
  export declare function registerInviteRoutes(router: Router, { compute }?: {
14
15
  compute?: boolean | undefined;
15
16
  }): void;
@@ -55,7 +55,7 @@ export async function belongsToAnotherMember(tx, device, memberId) {
55
55
  return false;
56
56
  return !device.revoked || (await removedBy(tx, device)) === 'another-member';
57
57
  }
58
- async function removedBy(tx, device) {
58
+ export async function removedBy(tx, device) {
59
59
  if (!isKickedRow(device))
60
60
  return 'itself';
61
61
  const owner = device.memberId ?? device.claimedMemberId;
@@ -0,0 +1,3 @@
1
+ import type { Router } from '../../../spec/mesh/hyperdispatch/index.js';
2
+ export declare const MESH_NAME_ROW = "mesh";
3
+ export declare function registerMeshNameRoutes(router: Router): void;
@@ -0,0 +1,26 @@
1
+ import { liveDeviceForWriter, trackActivity } from './activity.js';
2
+ import { meshNameWithinBounds } from '../../../schema/qvac.js';
3
+ import { MESH_NAMES } from '../collections.js';
4
+ export const MESH_NAME_ROW = 'mesh';
5
+ export function registerMeshNameRoutes(router) {
6
+ router.add('@qvac/name-mesh', trackActivity(async ({ name, namedAt }, { tx, node, log }) => {
7
+ if (!meshNameWithinBounds(name)) {
8
+ log?.warn('contract', 'name-mesh dropped: name over the cap', { length: name.length });
9
+ return;
10
+ }
11
+ const existing = await tx.get(MESH_NAMES, { id: MESH_NAME_ROW });
12
+ if (existing && existing.namedAt >= namedAt) {
13
+ log?.debug('contract', 'name-mesh dropped: stale namedAt', { namedAt });
14
+ return;
15
+ }
16
+ const row = {
17
+ id: MESH_NAME_ROW,
18
+ name,
19
+ namedAt,
20
+ namedBy: (await liveDeviceForWriter(tx, node.key))?.memberId
21
+ };
22
+ await tx.insert(MESH_NAMES, row);
23
+ log?.debug('contract', 'mesh named', { namedAt });
24
+ return row;
25
+ }));
26
+ }
@@ -3,7 +3,7 @@ import { devicesByWriterKey, liveDeviceForWriter, markWriterRevoked, trackActivi
3
3
  import { recordMemberRemoval } from './grant-order.js';
4
4
  import { verifyMemberWriterClaim, verifyWriterClaim } from '../device-attestation.js';
5
5
  import { meshKind } from './mesh-kind.js';
6
- import { isKickedRow } from '../helpers/index.js';
6
+ import { removedBy } from './invites.js';
7
7
  import { verifyDeviceProof } from '../identity.js';
8
8
  import { sealed } from './seal.js';
9
9
  import b4a from 'b4a';
@@ -125,6 +125,10 @@ async function revokeWriter(payload, context) {
125
125
  context.log?.debug('contract', 'remove-writer: no device row to revoke');
126
126
  return;
127
127
  }
128
+ if (existing.revoked && b4a.equals(context.node.key, payload.writerKey)) {
129
+ context.log?.debug('contract', 'remove-writer: already revoked, the leave changes nothing');
130
+ return;
131
+ }
128
132
  const current = existing.writerKey;
129
133
  if (current && !b4a.equals(current, payload.writerKey)) {
130
134
  if (b4a.equals(context.node.key, payload.writerKey) || b4a.equals(context.node.key, current)) {
@@ -279,13 +283,16 @@ export function registerWriterRoutes(router) {
279
283
  return;
280
284
  }
281
285
  const existing = await tx.get(DEVICES, { id });
282
- if (existing && isKickedRow(existing) && (await meshKind(tx)) === 'shared') {
286
+ if (existing?.revoked &&
287
+ (await meshKind(tx)) === 'shared' &&
288
+ (await removedBy(tx, existing)) === 'another-member') {
283
289
  log?.warn('contract', 'vouched-join dropped: the joiner was removed from this mesh');
284
290
  return;
285
291
  }
286
292
  if (existing &&
287
293
  !existing.revoked &&
288
- !(existing.writerKey && b4a.equals(existing.writerKey, writerKey))) {
294
+ !(existing.writerKey && b4a.equals(existing.writerKey, writerKey)) &&
295
+ !(device.joinedAt > existing.joinedAt)) {
289
296
  log?.warn('contract', 'vouched-join dropped: the joiner is live here on another writer');
290
297
  return;
291
298
  }
@@ -124,5 +124,5 @@ export declare class Files extends EventEmitter {
124
124
  export { MemoryVectorIndex, RAG_KNOWLEDGE_OFF_NOTICE, RAG_TRUNCATED_NOTICE, RAG_UNAVAILABLE_NOTICE, WEB_TOOLS, chooseRagNotice, citedByPhraseOverlap, createRagSourceTagFilter, formatFullDocumentContext, formatRagContext, isFullTextHit, isWholeDocumentQuery, referencedDocuments, isTruncatedFullTextHit, sourcesFromHits, webSourcesFromToolResult, withoutDataChannel } from './rag/index.ts';
125
125
  export type { IndexingEmbedder, RagExtractors, RagSource, VectorIndex } from './rag/index.ts';
126
126
  export { attachTurnDocumentIds, groupAttachmentsByMessage } from './records/index.ts';
127
- export { CoreBlobServer, parseBlobReferenceCoreKey } from './store/index.ts';
127
+ export { CoreBlobServer, PENDING_BLOB_REFERENCE, isPendingBlobReference, parseBlobReferenceCoreKey } from './store/index.ts';
128
128
  export type { MeshBlobKeys } from './store/index.ts';
@@ -647,4 +647,4 @@ function fileState(processor, opts) {
647
647
  }
648
648
  export { MemoryVectorIndex, RAG_KNOWLEDGE_OFF_NOTICE, RAG_TRUNCATED_NOTICE, RAG_UNAVAILABLE_NOTICE, WEB_TOOLS, chooseRagNotice, citedByPhraseOverlap, createRagSourceTagFilter, formatFullDocumentContext, formatRagContext, isFullTextHit, isWholeDocumentQuery, referencedDocuments, isTruncatedFullTextHit, sourcesFromHits, webSourcesFromToolResult, withoutDataChannel } from './rag/index.js';
649
649
  export { attachTurnDocumentIds, groupAttachmentsByMessage } from './records/index.js';
650
- export { CoreBlobServer, parseBlobReferenceCoreKey } from './store/index.js';
650
+ export { CoreBlobServer, PENDING_BLOB_REFERENCE, isPendingBlobReference, parseBlobReferenceCoreKey } from './store/index.js';
@@ -1,7 +1,7 @@
1
1
  import b4a from 'b4a';
2
2
  import crypto from 'hypercore-crypto';
3
3
  import { processorArtifactId } from '../records/index.js';
4
- import { parseBlobReference } from '../store/index.js';
4
+ import { isPendingBlobReference, parseBlobReference } from '../store/index.js';
5
5
  import { IMAGE_MIMES } from '../../image/normalize.js';
6
6
  import { previewEncoder } from './image.js';
7
7
  import { AbortedError } from '@qvac/harness/race-abort';
@@ -151,6 +151,9 @@ export function previewId(file) {
151
151
  });
152
152
  }
153
153
  function previewSource(file) {
154
+ if (isPendingBlobReference(file.blobId)) {
155
+ return hash([file.blobId]);
156
+ }
154
157
  const { blobId, coreKey } = parseBlobReference(file.blobId);
155
158
  return hash([
156
159
  coreKey ?? '',
@@ -1,4 +1,4 @@
1
- import { isInvalidBlobReferenceError, compareBlobReferences } from '../store/index.js';
1
+ import { isInvalidBlobReferenceError, isPendingBlobReference, compareBlobReferences } from '../store/index.js';
2
2
  import { AbortController } from 'bare-abort-controller';
3
3
  import { AbortedError } from '@qvac/harness/race-abort';
4
4
  const BLOB_RETRY_MS = 30_000;
@@ -27,6 +27,9 @@ export class IndexingSource {
27
27
  return this.retry.reconnect(onRetry);
28
28
  }
29
29
  async read(id, blobRef, signal) {
30
+ if (isPendingBlobReference(blobRef)) {
31
+ return { kind: 'missing', retryAt: Date.now() + this._retryMs };
32
+ }
30
33
  try {
31
34
  const bytes = await this._readBytes(blobRef, { signal, wait: !this._download });
32
35
  this.retry.markFound(id);
@@ -4,7 +4,8 @@ import { stringifyBlobId, writeBlob, type BlobHost } from './blob.ts';
4
4
  import { readBlobReference, readBlobReferenceBytes, downloadBlobReference } from './reference.ts';
5
5
  export { CoreBlobServer } from './server.ts';
6
6
  export type { MeshBlobKeys, MeshForBlobCore } from './server.ts';
7
- export { compareBlobReferences, isInvalidBlobReferenceError, parseBlobReference, parseBlobReferenceCoreKey } from './reference.ts';
7
+ export { compareBlobReferences, isInvalidBlobReferenceError, isPendingBlobReference, parseBlobReference, parseBlobReferenceCoreKey } from './reference.ts';
8
+ export { PENDING_BLOB_REFERENCE } from './reference.ts';
8
9
  export type { BlobReferenceReadOptions } from './reference.ts';
9
10
  export type { WriteProgress } from './blob.ts';
10
11
  export { MAX_INLINE_BYTES, MAX_REFERENCE_CHARS } from './inline.ts';
@@ -5,7 +5,8 @@ import { inlineReference } from './inline.js';
5
5
  import { clearBlob, compactBlobCores, stringifyBlobId, writeBlob } from './blob.js';
6
6
  import { parseBlobReference, readBlobReference, readBlobReferenceBytes, downloadBlobReference } from './reference.js';
7
7
  export { CoreBlobServer } from './server.js';
8
- export { compareBlobReferences, isInvalidBlobReferenceError, parseBlobReference, parseBlobReferenceCoreKey } from './reference.js';
8
+ export { compareBlobReferences, isInvalidBlobReferenceError, isPendingBlobReference, parseBlobReference, parseBlobReferenceCoreKey } from './reference.js';
9
+ export { PENDING_BLOB_REFERENCE } from './reference.js';
9
10
  export { MAX_INLINE_BYTES, MAX_REFERENCE_CHARS } from './inline.js';
10
11
  export class BlobStore extends EventEmitter {
11
12
  blobs;
@@ -2,6 +2,7 @@ import type { BlobId } from 'hyperblobs';
2
2
  import { type BlobHost, type BlobReadChunk } from './blob.ts';
3
3
  import type { AbortSignal } from 'bare-abort-controller';
4
4
  import { type InlinePayload } from './inline.ts';
5
+ import { PENDING_BLOB_REFERENCE } from '../../../constants.ts';
5
6
  export interface ParsedBlobReference {
6
7
  readonly blobId: BlobId;
7
8
  readonly coreKey?: string;
@@ -12,6 +13,8 @@ export interface BlobReferenceReadOptions {
12
13
  readonly wait?: boolean;
13
14
  readonly signal?: AbortSignal;
14
15
  }
16
+ export { PENDING_BLOB_REFERENCE };
17
+ export declare function isPendingBlobReference(blobReference: string): boolean;
15
18
  export declare function isInvalidBlobReferenceError(error: unknown): error is TypeError;
16
19
  export declare function parseBlobReferenceCoreKey(blobReference: string): string | undefined;
17
20
  export declare function parseBlobReference(blobReference: string): ParsedBlobReference;
@@ -3,10 +3,15 @@ import { AbortedError, raceAbort } from '@qvac/harness/race-abort';
3
3
  import { MAX_REFERENCE_CHARS, readInline } from './inline.js';
4
4
  import b4a from 'b4a';
5
5
  import { isRecord } from '../../../guards.js';
6
+ import { PENDING_BLOB_REFERENCE } from '../../../constants.js';
6
7
  const CORE_KEY_PATTERN = /^[0-9a-f]{64}$/;
7
8
  const DEFAULT_REMOTE_TIMEOUT_MS = 15_000;
8
9
  const INVALID_BLOB_REFERENCE = 'invalid blob reference';
9
10
  const BLOB_UNAVAILABLE = 'blob unavailable';
11
+ export { PENDING_BLOB_REFERENCE };
12
+ export function isPendingBlobReference(blobReference) {
13
+ return blobReference === PENDING_BLOB_REFERENCE;
14
+ }
10
15
  function invalidBlobReference() {
11
16
  return new TypeError(INVALID_BLOB_REFERENCE);
12
17
  }
@@ -108,6 +113,9 @@ async function closeRemote(remote) {
108
113
  catch { }
109
114
  }
110
115
  export async function* readBlobReference(mesh, blobReference, options = {}) {
116
+ if (isPendingBlobReference(blobReference)) {
117
+ throw blobUnavailable();
118
+ }
111
119
  const { blobId, coreKey, inline } = parseBlobReference(blobReference);
112
120
  if (options.signal?.aborted) {
113
121
  throw new AbortedError();
@@ -1,4 +1,4 @@
1
- import { parseBlobReference, parseBlobReferenceCoreKey } from './reference.js';
1
+ import { isPendingBlobReference, parseBlobReference, parseBlobReferenceCoreKey } from './reference.js';
2
2
  import b4a from 'b4a';
3
3
  export async function sweepUnreferenced(blobs, references, coreLength) {
4
4
  const ranges = [];
@@ -10,6 +10,8 @@ export async function sweepUnreferenced(blobs, references, coreLength) {
10
10
  await clearGaps(blobs, mergeRanges(ranges), coreLength);
11
11
  }
12
12
  function addLocalRange(ranges, reference, { localCoreKey, coreLength }) {
13
+ if (isPendingBlobReference(reference))
14
+ return;
13
15
  const coreKey = parseBlobReferenceCoreKey(reference);
14
16
  if (coreKey && coreKey !== localCoreKey) {
15
17
  return;
@@ -1,6 +1,6 @@
1
1
  import CorestoreStorage from 'hypercore-storage';
2
2
  import HyperDB from 'hyperdb';
3
- import type { LocalAccountRecovery, LocalAppConfig, LocalCapabilityProfile, LocalChatNotify, LocalChatOrder, LocalCustomModel, LocalIdentity, LocalMemberProof, LocalMeshDeparture, LocalMeshMembership, LocalModelDownload, LocalModelNotify } from '../../../spec/local/hyperschema/types.d.ts';
3
+ import type { LocalAccountRecovery, LocalAppConfig, LocalCapabilityProfile, LocalChatMove, LocalChatNotify, LocalChatOrder, LocalCustomModel, LocalIdentity, LocalMemberProof, LocalMeshDeparture, LocalMeshMembership, LocalModelDownload, LocalModelNotify } from '../../../spec/local/hyperschema/types.d.ts';
4
4
  import type { DeviceMetadata } from '../mesh.ts';
5
5
  import { LocalFiles } from './files.ts';
6
6
  export interface ResolvedSession {
@@ -104,6 +104,9 @@ declare class LocalStore {
104
104
  readMemberProof(meshKey: Buffer): Promise<LocalMemberProof | null>;
105
105
  recordMemberProof(link: LocalMemberProof): Promise<void>;
106
106
  readAccountRecovery(meshKey: Buffer): Promise<LocalAccountRecovery | null>;
107
+ readChatMove(meshKey: Buffer, chatId: string): Promise<LocalChatMove | null>;
108
+ listChatMoves(): Promise<LocalChatMove[]>;
109
+ recordChatMove(row: LocalChatMove): Promise<void>;
107
110
  recordAccountRecovery(row: LocalAccountRecovery): Promise<void>;
108
111
  replaceIdentity(identity: Omit<LocalIdentity, 'id'>): Promise<void>;
109
112
  ensureIdentity(devicePublicKey: Buffer, createdAt: number): Promise<EnsuredIdentity>;
@@ -7,7 +7,7 @@ import { generateMnemonic, mintIdentity } from '../identity.js';
7
7
  import LocalDatabaseSpec from '../../../spec/local/hyperdb/index.js';
8
8
  import b4a from 'b4a';
9
9
  import { dropMeshFiles, LocalFiles } from './files.js';
10
- import { LOCAL_ACCOUNT_RECOVERY, LOCAL_ACTIVE_MESH, LOCAL_APP_CONFIG, LOCAL_CHAT_NOTIFY, LOCAL_CHAT_ORDER, LOCAL_CHAT_ORDER_BY_KEY, LOCAL_CONFIG, LOCAL_CUSTOM_MODEL, 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 } from '../collections.js';
10
+ import { LOCAL_ACCOUNT_RECOVERY, LOCAL_ACTIVE_MESH, LOCAL_APP_CONFIG, LOCAL_CHAT_MOVES, LOCAL_CHAT_NOTIFY, LOCAL_CHAT_ORDER, LOCAL_CHAT_ORDER_BY_KEY, LOCAL_CONFIG, LOCAL_CUSTOM_MODEL, 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 } from '../collections.js';
11
11
  const IDENTITY_ID = 'identity';
12
12
  const MEMBERSHIP_ID = 'membership';
13
13
  const APP_CONFIG_ID = 'default';
@@ -347,6 +347,19 @@ class LocalStore {
347
347
  readAccountRecovery(meshKey) {
348
348
  return this._db.get(LOCAL_ACCOUNT_RECOVERY, { meshKey });
349
349
  }
350
+ readChatMove(meshKey, chatId) {
351
+ return this._db.get(LOCAL_CHAT_MOVES, { meshKey, chatId });
352
+ }
353
+ listChatMoves() {
354
+ return this._db.find(LOCAL_CHAT_MOVES).toArray();
355
+ }
356
+ recordChatMove(row) {
357
+ return this._locked(async () => {
358
+ const tx = this._db.transaction();
359
+ await tx.insert(LOCAL_CHAT_MOVES, row);
360
+ await tx.flush();
361
+ });
362
+ }
350
363
  recordAccountRecovery(row) {
351
364
  return this._locked(async () => {
352
365
  const tx = this._db.transaction();
@@ -3,8 +3,10 @@ import type { AssistantMeshAdmissionRequest, AssistantMeshSeedRequest } from '..
3
3
  export { type HandoffStream };
4
4
  export declare const SEED_REFUSED = "the device holding this mesh would not share its seed";
5
5
  export declare const SEED_ASKER_UNSEEN = "the device holding this mesh has not seen the asking device yet";
6
+ export declare const ADMISSION_DEFERRED = "the device holding this mesh cannot admit the asking device yet";
6
7
  export type MeshAdmissionRequest = AssistantMeshAdmissionRequest;
7
8
  export type MeshSeedRequest = AssistantMeshSeedRequest | MeshAdmissionRequest;
9
+ export type MeshAdmissionClaim = Omit<MeshSeedRequest, 'meshKey'>;
8
10
  export type MeshSeedResult = {
9
11
  readonly seed: Buffer;
10
12
  } | {
@@ -20,6 +22,6 @@ export declare class MeshSeedHandoff {
20
22
  constructor(opts: MeshSeedHandoffOptions);
21
23
  addStream(stream: HandoffStream): void;
22
24
  request(holderDeviceId: Uint8Array, meshKey: Buffer): Promise<Buffer | null>;
23
- admit(holderDeviceId: Uint8Array, meshKey: Buffer, claim: Omit<MeshSeedRequest, 'meshKey'>): Promise<boolean>;
25
+ admit(holderDeviceId: Uint8Array, meshKey: Buffer, claim: MeshAdmissionClaim): Promise<boolean>;
24
26
  destroy(): void;
25
27
  }
@@ -4,6 +4,7 @@ const PROTOCOL = 'qvac/mesh-seed-handoff';
4
4
  export {};
5
5
  export const SEED_REFUSED = 'the device holding this mesh would not share its seed';
6
6
  export const SEED_ASKER_UNSEEN = 'the device holding this mesh has not seen the asking device yet';
7
+ export const ADMISSION_DEFERRED = 'the device holding this mesh cannot admit the asking device yet';
7
8
  const handoff = getStruct('@assistant/mesh-seed-handoff');
8
9
  const handoffAck = getStruct('@assistant/mesh-seed-handoff-ack');
9
10
  const admissionHandoff = getStruct('@assistant/mesh-admission-handoff');
@@ -8,7 +8,7 @@ import ReadyResource from 'ready-resource';
8
8
  import { Files } from './files/index.ts';
9
9
  import type { Logger } from '../../index.ts';
10
10
  import { Router } from '../../spec/mesh/hyperdispatch/index.js';
11
- import type { QvacCapabilityProfile, QvacDevice, QvacMember } from '../../spec/mesh/hyperschema/types.d.ts';
11
+ import type { QvacCapabilityProfile, QvacDevice, QvacMember, QvacMeshName } from '../../spec/mesh/hyperschema/types.d.ts';
12
12
  import type { BlindPeeringOpts } from './blind-peers.ts';
13
13
  import type { AttachmentUrl } from './attachment-link.ts';
14
14
  import type { MeshFileIndex } from './files/local-index.ts';
@@ -113,6 +113,7 @@ export declare class Mesh extends ReadyResource {
113
113
  private _bootInterrupted;
114
114
  private _localWriterUploadedLength;
115
115
  private _ourMemberId;
116
+ private _name;
116
117
  private _membership;
117
118
  private readonly _deviceId;
118
119
  private readonly _grantExpiry;
@@ -138,6 +139,9 @@ export declare class Mesh extends ReadyResource {
138
139
  get membership(): MembershipStats;
139
140
  refreshMembership(): Promise<void>;
140
141
  refreshOurMember(): Promise<void>;
142
+ get name(): QvacMeshName | null;
143
+ refreshName(): Promise<void>;
144
+ setName(name: string): Promise<void>;
141
145
  refreshGrantExpiry(): Promise<void>;
142
146
  bornKind(): Promise<string | null | undefined>;
143
147
  waitForGenesis(timeout: number): Promise<string | null | undefined>;
@@ -18,12 +18,13 @@ import { GrantExpiry } from './grant-expiry.js';
18
18
  import { grantKeyPair, signInviteClaim } from './invite-grants.js';
19
19
  import { liveDeviceForWriter } from './contract/activity.js';
20
20
  import { assertComputeRoute } from './contract/compute.js';
21
+ import { MESH_NAME_ROW } from './contract/mesh-name.js';
21
22
  import { registerRoutes } from './contract/index.js';
22
23
  import { createSyncActivity } from './sync-status.js';
23
24
  import { buildHealthAssistant } from './health-assistant.js';
24
25
  import b4a from 'b4a';
25
26
  import { errorMessage, isRecord } from '../guards.js';
26
- import { ACTIVE_AGENTS, ACTIVE_CHATS, DEVICES, LIVE_WRITERS_BY_MOST_RECENT, MEMBERS, MESH_KINDS } from './collections.js';
27
+ import { ACTIVE_AGENTS, ACTIVE_CHATS, DEVICES, LIVE_WRITERS_BY_MOST_RECENT, MEMBERS, MESH_KINDS, MESH_NAMES } from './collections.js';
27
28
  const [MESH_KEYPAIR, MESH_ENCRYPTION, MESH_DEVICE] = crypto.namespace('qvac-assistant/mesh', 3);
28
29
  export function meshPublicKeyFromSeed(seed) {
29
30
  return crypto.keyPair(crypto.hash([MESH_KEYPAIR, seed])).publicKey;
@@ -82,6 +83,7 @@ export class Mesh extends ReadyResource {
82
83
  _bootInterrupted = false;
83
84
  _localWriterUploadedLength = 0;
84
85
  _ourMemberId = null;
86
+ _name = null;
85
87
  _membership = {
86
88
  members: 0,
87
89
  attested: 0,
@@ -195,6 +197,19 @@ export class Mesh extends ReadyResource {
195
197
  this.emit('membership', membership);
196
198
  }
197
199
  }
200
+ get name() {
201
+ return this._name;
202
+ }
203
+ async refreshName() {
204
+ this._name = await this.view.get(MESH_NAMES, { id: MESH_NAME_ROW });
205
+ }
206
+ async setName(name) {
207
+ const current = await this.view.get(MESH_NAMES, { id: MESH_NAME_ROW });
208
+ await this.dispatch('name-mesh', {
209
+ name,
210
+ namedAt: Math.max(Date.now(), (current?.namedAt ?? 0) + 1)
211
+ });
212
+ }
198
213
  refreshGrantExpiry() {
199
214
  return this._grantExpiry.refresh();
200
215
  }
@@ -2,7 +2,7 @@ import { FileChanges } from './files.js';
2
2
  import { syncDeviceRevocation, syncOwnMember } from './devices.js';
3
3
  import { syncChatTombstone } from './chats.js';
4
4
  import { syncNotificationChunk } from './chunks.js';
5
- import { AGENTS, CHATS, CHUNKS, CHUNK_COUNTERS, DEVICES, KNOWLEDGE, KNOWLEDGE_ARTIFACTS, MEMBERS, PURGED_CHATS } from '../collections.js';
5
+ import { AGENTS, CHATS, CHUNKS, CHUNK_COUNTERS, DEVICES, KNOWLEDGE, KNOWLEDGE_ARTIFACTS, MEMBERS, MESH_NAMES, PURGED_CHATS } from '../collections.js';
6
6
  export async function syncChanges(mesh, view, from) {
7
7
  if (mesh.closing)
8
8
  return;
@@ -15,6 +15,7 @@ export async function syncChanges(mesh, view, from) {
15
15
  const orderDirty = new Set();
16
16
  const purged = new Map();
17
17
  let kindChanged = false;
18
+ let nameChanged = false;
18
19
  const snap = view.db.snapshot();
19
20
  const files = new FileChanges(snap, from);
20
21
  try {
@@ -66,6 +67,9 @@ export async function syncChanges(mesh, view, from) {
66
67
  else if (change.collection === '@qvac/mesh-kinds') {
67
68
  kindChanged = true;
68
69
  }
70
+ else if (change.collection === MESH_NAMES) {
71
+ nameChanged = true;
72
+ }
69
73
  }
70
74
  indexingDirty = await files.ids();
71
75
  }
@@ -102,6 +106,10 @@ export async function syncChanges(mesh, view, from) {
102
106
  if (kindChanged) {
103
107
  mesh.emit('mesh-kind');
104
108
  }
109
+ if (nameChanged) {
110
+ await mesh.refreshName();
111
+ mesh.emit('mesh-named');
112
+ }
105
113
  }
106
114
  function changed(change, collection) {
107
115
  return change.collection === collection;
@@ -81,6 +81,7 @@ export declare const ACCOUNT_MEMBER_UNKNOWN = "This device is not part of its ac
81
81
  export declare const AWAITING_ADMISSION = "awaiting-admission";
82
82
  export declare const MEMBER_INVITE_HOME_REFUSED = "An account mesh cannot be invited into";
83
83
  export declare const DEVICE_INVITE_MESH_REFUSED = "Only an account mesh can take a device invite";
84
+ export declare const MESH_NAME_ACCOUNT_REFUSED = "An account mesh has no shared name";
84
85
  export declare const INVITE_ACCOUNT_UNREADABLE = "This device cannot reach its account to check";
85
86
  export declare const MESH_HELD_BY_SIBLING = "Another of your devices holds this mesh: bring that device online, or invite from it instead";
86
87
  export declare const INVITE_GRANT_REVOKED = "This invite was revoked";
@@ -204,6 +205,7 @@ export declare class Core extends ReadyResource {
204
205
  private readonly _rpcs;
205
206
  private _stream;
206
207
  private _api;
208
+ private _chatMoves;
207
209
  private readonly _clients;
208
210
  private _deviceKeyPair;
209
211
  private _identityPhrase;
@@ -217,6 +219,8 @@ export declare class Core extends ReadyResource {
217
219
  private readonly _harnessLoan;
218
220
  private _serveLoanedHarness;
219
221
  private readonly _following;
222
+ private readonly _admissionRetries;
223
+ private readonly _admissionRetryPending;
220
224
  private _revokingInMeshes;
221
225
  private _revokeInMeshesAgain;
222
226
  private _sweepUnknownEverywhere;
@@ -374,6 +378,7 @@ export declare class Core extends ReadyResource {
374
378
  private _departureHasAudience;
375
379
  private _announceDeparture;
376
380
  leaveMesh(meshId: string): Promise<void>;
381
+ private _departOnLogout;
377
382
  private _isStoredAccount;
378
383
  private _storedAccountKey;
379
384
  listMeshes(): Promise<AssistantMeshList>;
@@ -386,6 +391,7 @@ export declare class Core extends ReadyResource {
386
391
  private _ownMeshes;
387
392
  private _isOwnMeshIn;
388
393
  setMeshLabel(meshId: string, label: string): Promise<void>;
394
+ setMeshName(meshId: string, name: string): Promise<void>;
389
395
  createMesh({ shared, compute }?: CreateMeshOptions): Promise<string>;
390
396
  sharedMesh(): Promise<SharedMesh>;
391
397
  private _occupancyNotice;
@@ -429,6 +435,8 @@ export declare class Core extends ReadyResource {
429
435
  private _openFollowedMesh;
430
436
  private _requestMeshSeed;
431
437
  private _requestMeshAdmission;
438
+ private _askSiblingsToAdmit;
439
+ private _retryAdmission;
432
440
  private _liveSiblings;
433
441
  registerLoanableHarness(serve: (stream: LoanStreamDuplex) => void): () => void;
434
442
  borrowHarness(deviceId: string): LoanStreamDuplex;
@@ -441,6 +449,7 @@ export declare class Core extends ReadyResource {
441
449
  private _admitIntoMesh;
442
450
  private _admitIntoMeshLocked;
443
451
  private _isJoinedMeshKey;
452
+ private _removedFor;
444
453
  private _askerStanding;
445
454
  private _skillOverlayOp;
446
455
  private _resolveAgentHost;