@qvac/core 1.0.0-rc.6 → 1.0.0-rc.8

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 (67) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/dist-lib/lib/api/agents.js +5 -2
  3. package/dist-lib/lib/api/approval-rules.js +8 -5
  4. package/dist-lib/lib/api/chat.d.ts +1 -2
  5. package/dist-lib/lib/api/chat.js +4 -18
  6. package/dist-lib/lib/api/device-routes.d.ts +6 -1
  7. package/dist-lib/lib/api/device-routes.js +20 -1
  8. package/dist-lib/lib/api/index.d.ts +0 -1
  9. package/dist-lib/lib/api/index.js +1 -2
  10. package/dist-lib/lib/api/mesh.d.ts +1 -1
  11. package/dist-lib/lib/api/mesh.js +1 -1
  12. package/dist-lib/lib/api/rag.js +2 -5
  13. package/dist-lib/lib/api/sync.js +12 -2
  14. package/dist-lib/lib/assistant/model-round.d.ts +7 -1
  15. package/dist-lib/lib/assistant/model-round.js +33 -11
  16. package/dist-lib/lib/assistant-tree.js +7 -0
  17. package/dist-lib/lib/assistant.d.ts +3 -2
  18. package/dist-lib/lib/assistant.js +20 -19
  19. package/dist-lib/lib/core/archived-mesh.d.ts +1 -0
  20. package/dist-lib/lib/core/archived-mesh.js +11 -14
  21. package/dist-lib/lib/core/chat-copy.d.ts +0 -1
  22. package/dist-lib/lib/core/chat-copy.js +1 -2
  23. package/dist-lib/lib/core/chat-move.d.ts +3 -1
  24. package/dist-lib/lib/core/chat-move.js +5 -2
  25. package/dist-lib/lib/core/contract/joined-meshes.js +2 -1
  26. package/dist-lib/lib/core/local/index.d.ts +2 -1
  27. package/dist-lib/lib/core/local/index.js +3 -2
  28. package/dist-lib/lib/core/public-mesh.d.ts +6 -8
  29. package/dist-lib/lib/core/public-mesh.js +19 -29
  30. package/dist-lib/lib/core/sync/index.js +1 -1
  31. package/dist-lib/lib/core.d.ts +21 -8
  32. package/dist-lib/lib/core.js +233 -204
  33. package/dist-lib/lib/errors.d.ts +8 -12
  34. package/dist-lib/lib/errors.js +8 -12
  35. package/dist-lib/lib/model-download.d.ts +6 -1
  36. package/dist-lib/lib/model-download.js +16 -3
  37. package/dist-lib/lib/oauth/resolve.js +29 -8
  38. package/dist-lib/lib/oauth/token-exchange-core.js +11 -0
  39. package/dist-lib/schema/engine.js +10 -3
  40. package/dist-lib/schema/local.js +4 -2
  41. package/dist-lib/schema/qvac.js +2 -1
  42. package/dist-lib/spec/capabilities.d.ts +2 -2
  43. package/dist-lib/spec/hrpc/hrpc.json +1 -1
  44. package/dist-lib/spec/hrpc/index.js +1 -1
  45. package/dist-lib/spec/hrpc/messages.js +273 -250
  46. package/dist-lib/spec/hyperschema/index.js +273 -250
  47. package/dist-lib/spec/hyperschema/schema.json +27 -6
  48. package/dist-lib/spec/hyperschema/types.d.ts +7 -1
  49. package/dist-lib/spec/local/hyperdb/messages.js +26 -12
  50. package/dist-lib/spec/local/hyperschema/index.js +13 -6
  51. package/dist-lib/spec/local/hyperschema/schema.json +10 -0
  52. package/dist-lib/spec/local/hyperschema/types.d.ts +2 -0
  53. package/dist-lib/spec/mesh/hyperdb/messages.js +30 -6
  54. package/dist-lib/spec/mesh/hyperdispatch/messages.js +15 -3
  55. package/dist-lib/spec/mesh/hyperschema/index.js +15 -3
  56. package/dist-lib/spec/mesh/hyperschema/schema.json +5 -0
  57. package/dist-lib/spec/mesh/hyperschema/types.d.ts +1 -0
  58. package/package.json +10 -4
  59. package/tui/README.md +51 -0
  60. package/tui/app.mjs +88 -17
  61. package/tui/boot.mjs +23 -6
  62. package/tui/cli.mjs +93 -0
  63. package/tui/index.mjs +2 -87
  64. package/tui/lib/updater.mjs +86 -0
  65. package/tui/main.mjs +26 -15
  66. package/dist-lib/lib/core/chat-project.d.ts +0 -2
  67. package/dist-lib/lib/core/chat-project.js +0 -15
@@ -16,6 +16,7 @@ export interface ChatMovesOptions {
16
16
  readonly log: LoggerInterface | null;
17
17
  readonly account?: () => Mesh | null;
18
18
  readonly agents?: AgentPicks | null;
19
+ readonly meshIdOf?: (key: Buffer) => string;
19
20
  }
20
21
  export declare class ChatMoves {
21
22
  private readonly _open;
@@ -23,6 +24,7 @@ export declare class ChatMoves {
23
24
  private readonly _deviceId;
24
25
  private readonly _log;
25
26
  private readonly _agents;
27
+ private readonly _meshIdOf;
26
28
  private readonly _listeners;
27
29
  private readonly _settling;
28
30
  private readonly _moving;
@@ -30,7 +32,7 @@ export declare class ChatMoves {
30
32
  private readonly _onChange;
31
33
  private _patching;
32
34
  private _closing;
33
- constructor(open: OpenMesh, local: LocalStore, { deviceId, log, account, agents }: ChatMovesOptions);
35
+ constructor(open: OpenMesh, local: LocalStore, { deviceId, log, account, agents, meshIdOf }: ChatMovesOptions);
34
36
  get closing(): boolean;
35
37
  watch(listener: () => void): void;
36
38
  unwatch(listener: () => void): void;
@@ -26,6 +26,7 @@ export class ChatMoves {
26
26
  _deviceId;
27
27
  _log;
28
28
  _agents;
29
+ _meshIdOf;
29
30
  _listeners = new Set();
30
31
  _settling = new Map();
31
32
  _moving = new Map();
@@ -33,12 +34,13 @@ export class ChatMoves {
33
34
  _onChange = () => this._changed();
34
35
  _patching = Promise.resolve();
35
36
  _closing = false;
36
- constructor(open, local, { deviceId, log, account, agents }) {
37
+ constructor(open, local, { deviceId, log, account, agents, meshIdOf = hex }) {
37
38
  this._open = open;
38
39
  this._local = local;
39
40
  this._deviceId = deviceId;
40
41
  this._log = log;
41
42
  this._agents = agents ?? accountPicks(account ?? (() => null));
43
+ this._meshIdOf = meshIdOf;
42
44
  }
43
45
  get closing() {
44
46
  return this._closing;
@@ -73,7 +75,7 @@ export class ChatMoves {
73
75
  return {
74
76
  meshId,
75
77
  chatId,
76
- targetMeshId: hex(row.targetMeshKey),
78
+ targetMeshId: row.targetMeshId ?? this._meshIdOf(row.targetMeshKey),
77
79
  targetChatId: row.targetChatId,
78
80
  state: stateOf(row, waiting.length),
79
81
  files: row.carried + waiting.length,
@@ -131,6 +133,7 @@ export class ChatMoves {
131
133
  meshKey: pair.source.key,
132
134
  chatId,
133
135
  targetMeshKey: pair.target.key,
136
+ targetMeshId,
134
137
  targetChatId,
135
138
  agentId: await landingAgentId(pair.target, chat.agentId, agentId),
136
139
  carried: 0,
@@ -39,6 +39,7 @@ function merge(mesh, existing, rejoin) {
39
39
  shared: remarks ? mesh.shared : existing.shared,
40
40
  sharedAt: remarks ? mesh.sharedAt : existing.sharedAt,
41
41
  workspace: existing.workspace || mesh.workspace,
42
- kicked: rejoin ? mesh.kicked : mesh.kicked || existing.kicked
42
+ kicked: rejoin ? mesh.kicked : mesh.kicked || existing.kicked,
43
+ initial: existing.initial || mesh.initial
43
44
  };
44
45
  }
@@ -105,6 +105,7 @@ export interface CandidateSessionOptions {
105
105
  export interface RecordMeshOptions {
106
106
  readonly deviceId: Buffer;
107
107
  readonly account?: boolean;
108
+ readonly initial?: boolean;
108
109
  }
109
110
  export interface DropMeshOptions {
110
111
  readonly keepDeparture?: boolean;
@@ -182,7 +183,7 @@ declare class LocalStore {
182
183
  private _membership;
183
184
  private _migrateLegacySession;
184
185
  private _legacyMembership;
185
- recordMesh(key: Buffer, session: ResolvedSession, { deviceId, account }: RecordMeshOptions): Promise<void>;
186
+ recordMesh(key: Buffer, session: ResolvedSession, { deviceId, account, initial }: RecordMeshOptions): Promise<void>;
186
187
  setAccountMesh(deviceId: Buffer, key: Buffer): Promise<void>;
187
188
  recordDeparture(key: Buffer, opts: RecordDepartureOptions): Promise<void>;
188
189
  departures(): Promise<LocalMeshDeparture[]>;
@@ -584,7 +584,7 @@ class LocalStore {
584
584
  }
585
585
  return { key: session.meshKey ?? null, seed: session.meshSeed, writerSeed: null };
586
586
  }
587
- recordMesh(key, session, { deviceId, account = false }) {
587
+ recordMesh(key, session, { deviceId, account = false, initial }) {
588
588
  return this._locked(async () => {
589
589
  const existing = await this._db.get(LOCAL_MESH_MEMBERSHIP, { key });
590
590
  const minted = account && !existing && session.baseKey === undefined;
@@ -599,7 +599,8 @@ class LocalStore {
599
599
  bootLength: session.bootFrom?.length,
600
600
  role: session.role ?? existing?.role,
601
601
  workspaceKey: session.workspaceKey ?? existing?.workspaceKey,
602
- joinedAt: existing?.joinedAt
602
+ joinedAt: existing?.joinedAt,
603
+ initial: initial || existing?.initial
603
604
  });
604
605
  if (minted) {
605
606
  await tx.insert(LOCAL_ACTIVE_MESH, { deviceId, homeMeshKey: key });
@@ -1,15 +1,13 @@
1
1
  import type { QvacChat, QvacJoinedMesh } from '../../spec/mesh/hyperschema/types.d.ts';
2
2
  import type { Mesh } from './mesh.ts';
3
3
  export declare function publicSeed(accountSeed: Buffer, workspaceKey: Buffer): Buffer;
4
- export declare function ownWorkspaceSeed(accountSeed: Buffer): Buffer;
5
- export declare function isOwnWorkspace(account: Mesh, workspace: Mesh): boolean;
6
- export declare function onOwnSeed(account: Mesh, meshKey: Buffer): Promise<boolean>;
7
- export interface OwnWorkspaces {
8
- readonly own: Buffer | null;
9
- readonly lost: QvacJoinedMesh[];
4
+ export declare function ourRows(account: Mesh): Promise<QvacJoinedMesh[]>;
5
+ export interface OldChats {
6
+ readonly mark: string;
7
+ readonly messages: boolean;
10
8
  }
11
- export declare function ownWorkspaces(account: Mesh): Promise<OwnWorkspaces>;
12
- export declare function lostMint(account: Mesh, meshKey: Buffer): Promise<boolean>;
9
+ export declare function oldChats(account: Mesh): Promise<OldChats | null>;
10
+ export declare function derivedSeed(account: Mesh): Buffer;
13
11
  export declare function publicMeshKey(account: Mesh, workspaceKey: Buffer): Promise<Buffer | null>;
14
12
  export declare function servesAgents(mesh: Mesh, deviceId: Buffer): Promise<boolean>;
15
13
  export declare function servesChat(mesh: Mesh, deviceId: Buffer, chatId: string): Promise<boolean>;
@@ -1,42 +1,32 @@
1
1
  import b4a from 'b4a';
2
2
  import crypto from 'hypercore-crypto';
3
3
  import { isRecord } from '../guards.js';
4
- import { ACTIVE_CHATS_BY_AGENT, AGENTS, CHATS, CHUNKS, JOINED_MESHES, MESH_SEEDS, PUBLIC_MESHES } from './collections.js';
4
+ import { ACTIVE_CHATS_BY_AGENT, AGENTS, CHATS, CHUNKS, CHUNK_COUNTERS, JOINED_MESHES, PUBLIC_MESHES } from './collections.js';
5
5
  const PUBLIC = b4a.from('public');
6
- const WORKSPACE = b4a.from('workspace');
7
6
  export function publicSeed(accountSeed, workspaceKey) {
8
7
  return crypto.hash([PUBLIC, accountSeed, workspaceKey]);
9
8
  }
10
- export function ownWorkspaceSeed(accountSeed) {
11
- return crypto.hash([WORKSPACE, accountSeed]);
12
- }
13
- export function isOwnWorkspace(account, workspace) {
14
- return (workspace.role === 'workspace' && b4a.equals(workspace.seed, ownWorkspaceSeed(account.seed)));
15
- }
16
- export async function onOwnSeed(account, meshKey) {
17
- const held = await account.view.get(MESH_SEEDS, { meshKey });
18
- return !!held && b4a.equals(held.seed, ownWorkspaceSeed(account.seed));
19
- }
20
- export async function ownWorkspaces(account) {
9
+ export async function ourRows(account) {
21
10
  const ours = account.ourMemberId;
22
- const mints = [];
23
- for await (const joined of account.view.find(JOINED_MESHES)) {
24
- const mine = !!ours && !!joined.workspace && b4a.equals(joined.memberId, ours);
25
- if (mine && (await onOwnSeed(account, joined.meshKey))) {
26
- mints.push(joined);
27
- }
11
+ const rows = await account.view.find(JOINED_MESHES).toArray();
12
+ return rows.filter((row) => ours && b4a.equals(row.memberId, ours));
13
+ }
14
+ export async function oldChats(account) {
15
+ let chats = 0;
16
+ let chunks = 0;
17
+ let last = 0;
18
+ for await (const chat of account.view.find(CHATS)) {
19
+ if (chat.deletedAt)
20
+ continue;
21
+ const counter = await account.view.get(CHUNK_COUNTERS, { chatId: chat.id });
22
+ chats++;
23
+ chunks += counter?.count ?? 0;
24
+ last = Math.max(last, counter?.lastActivityAt ?? 0, chat.updatedAt ?? 0);
28
25
  }
29
- const live = mints
30
- .filter((joined) => !joined.leftAt)
31
- .sort((a, b) => b4a.compare(a.meshKey, b.meshKey));
32
- return { own: live[0]?.meshKey ?? null, lost: mints.filter((joined) => joined !== live[0]) };
26
+ return chats ? { mark: `${chats}:${chunks}:${last}`, messages: chunks > 0 } : null;
33
27
  }
34
- export async function lostMint(account, meshKey) {
35
- if (!(await onOwnSeed(account, meshKey))) {
36
- return false;
37
- }
38
- const { own } = await ownWorkspaces(account);
39
- return !own || !b4a.equals(own, meshKey);
28
+ export function derivedSeed(account) {
29
+ return crypto.hash([b4a.from('workspace'), account.seed]);
40
30
  }
41
31
  export async function publicMeshKey(account, workspaceKey) {
42
32
  const id = b4a.toHex(workspaceKey);
@@ -112,7 +112,7 @@ async function settle(mesh, pass) {
112
112
  if (pass.orderDirty.size && mesh.syncChatOrder) {
113
113
  await mesh.syncChatOrder(pass.orderDirty);
114
114
  }
115
- mesh.emit('meshes-dirty', pass.meshesChanged, pass.groupsChanged);
115
+ mesh.emit('meshes-dirty', pass.meshesChanged, pass.groupsChanged, pass.orderDirty.size > 0);
116
116
  if (pass.nameChanged) {
117
117
  await mesh.refreshName();
118
118
  mesh.emit('mesh-named');
@@ -24,6 +24,10 @@ import { Mesh, type DeviceMetadata, type ProjectIdentity } from './core/mesh.ts'
24
24
  import { type Stream, type Transport } from '@qvac/harness/rpc';
25
25
  import { type CoreSpec } from './spec-loader.ts';
26
26
  import { type LocalQvacState } from '../spec/index.js';
27
+ export interface SiblingDownloads {
28
+ asked(name: string): Promise<void>;
29
+ resumed(name: string): void;
30
+ }
27
31
  export interface ClearOldFilesOptions {
28
32
  readonly olderThanMs: number;
29
33
  readonly includeOwn?: boolean;
@@ -185,6 +189,7 @@ export declare class Core extends ReadyResource {
185
189
  private _modelCatalogWatch;
186
190
  private _modelCatalogWatchSource;
187
191
  private _retryModelDownload;
192
+ private _siblingDownloads;
188
193
  private _transcribe;
189
194
  private _detectLanguage;
190
195
  private _previewModelSource;
@@ -245,14 +250,16 @@ export declare class Core extends ReadyResource {
245
250
  private _publicBoots;
246
251
  private readonly _meshNames;
247
252
  private _ownWorkspaceId;
253
+ private _ownDecided;
248
254
  private readonly _publicWriters;
249
255
  private readonly _leftPublic;
250
256
  private readonly _publicWaiters;
251
257
  private readonly _publicFollow;
252
258
  private readonly _publicMerges;
253
- private readonly _publicCarries;
254
- private readonly _ownCarries;
259
+ private readonly _publicDrops;
255
260
  private _publicMigration;
261
+ private _copyAgain;
262
+ private _accountCopied;
256
263
  private readonly _agentCopies;
257
264
  private readonly _sharedAgents;
258
265
  private readonly _memberKeyWrites;
@@ -272,6 +279,7 @@ export declare class Core extends ReadyResource {
272
279
  private _backfill;
273
280
  private _leaving;
274
281
  private readonly _kickedMeshes;
282
+ private readonly _haltedMeshes;
275
283
  private readonly _kickCloses;
276
284
  private readonly _retiredMeshes;
277
285
  private _retiredAccount;
@@ -389,6 +397,7 @@ export declare class Core extends ReadyResource {
389
397
  private _stopEntryIndexing;
390
398
  private _releaseVectorIndex;
391
399
  private _withdrawFromMesh;
400
+ private _markHalted;
392
401
  private _reviewKick;
393
402
  private _onKicked;
394
403
  private _kickOutlivesTransition;
@@ -484,7 +493,6 @@ export declare class Core extends ReadyResource {
484
493
  private _shareProjectSeed;
485
494
  private _shareMemberKey;
486
495
  private _writeMemberKey;
487
- private _contentMesh;
488
496
  private _devicesOf;
489
497
  private _hasPublic;
490
498
  private _publicOf;
@@ -492,14 +500,13 @@ export declare class Core extends ReadyResource {
492
500
  private _publicWorkspaces;
493
501
  private _settlePublicMeshes;
494
502
  private _settleOwnWorkspace;
503
+ private _mintsOwnWorkspace;
504
+ private _markDerivedInitial;
495
505
  private _mintOwnWorkspace;
496
506
  private _setOwnWorkspace;
497
507
  private _retireLeftPublic;
498
508
  private _leftWorkspaces;
499
- private _carryLostMint;
500
- private _carryProjects;
501
- private _carryAgentUsers;
502
- private _carryLeftPublic;
509
+ private _dropLeftPublic;
503
510
  private _settlePublicMesh;
504
511
  private _publicRecord;
505
512
  private _savePublicRecord;
@@ -508,6 +515,8 @@ export declare class Core extends ReadyResource {
508
515
  private _mintPublicBirth;
509
516
  private _mergeLostMint;
510
517
  private _migrateIntoPublic;
518
+ private _recordCopied;
519
+ private _markCopied;
511
520
  private _followAgentCopies;
512
521
  private _keepAgentCopies;
513
522
  private _agentPicks;
@@ -576,7 +585,8 @@ export declare class Core extends ReadyResource {
576
585
  private _readMeshList;
577
586
  listArchivedMeshes(): Promise<AssistantArchivedMeshList>;
578
587
  archivedMeshContents(meshId: string): Promise<ArchivedMeshContents>;
579
- migrateArchivedMesh(meshId: string): Promise<ArchivedMeshMigration>;
588
+ migrateArchivedMesh(meshId: string, workspaceId: string): Promise<ArchivedMeshMigration>;
589
+ private _archiveDestination;
580
590
  private _archivedRow;
581
591
  private _withArchivedMesh;
582
592
  private _ownMeshes;
@@ -674,8 +684,10 @@ export declare class Core extends ReadyResource {
674
684
  private _servedMeshList;
675
685
  private _foreignEntry;
676
686
  private _definesAgents;
687
+ private _refuseAccountContent;
677
688
  private _routesToPublic;
678
689
  private _routedMesh;
690
+ private _holdsPublic;
679
691
  private _publicById;
680
692
  private _meshStatusSource;
681
693
  private _blindPeeringSource;
@@ -701,6 +713,7 @@ export declare class Core extends ReadyResource {
701
713
  private _readModels;
702
714
  private _openModelCatalogWatchSource;
703
715
  private _resetModelCatalogWatchSource;
716
+ registerSiblingDownloads(hooks: SiblingDownloads): () => void;
704
717
  registerRetryModelDownload(hook: (name: string) => Promise<void>): () => void;
705
718
  registerSkills(hook: (agentId?: string | null, modelName?: string | null, options?: SkillOptions) => Promise<unknown>): () => void;
706
719
  registerSkillCatalog(hook: (agentId?: string | null, modelName?: string | null, options?: SkillCatalogOptions) => Promise<AssistantSkillCatalogResponse>): () => void;