@qvac/core 1.0.0-rc.6 → 1.0.0-rc.7
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/dist-lib/lib/api/agents.js +5 -2
- package/dist-lib/lib/api/approval-rules.js +8 -5
- package/dist-lib/lib/api/chat.d.ts +1 -2
- package/dist-lib/lib/api/chat.js +4 -18
- package/dist-lib/lib/api/index.d.ts +0 -1
- package/dist-lib/lib/api/index.js +1 -2
- package/dist-lib/lib/api/mesh.d.ts +1 -1
- package/dist-lib/lib/api/mesh.js +1 -1
- package/dist-lib/lib/api/sync.js +12 -2
- package/dist-lib/lib/assistant.d.ts +0 -1
- package/dist-lib/lib/assistant.js +10 -13
- package/dist-lib/lib/core/archived-mesh.d.ts +1 -0
- package/dist-lib/lib/core/archived-mesh.js +11 -14
- package/dist-lib/lib/core/chat-copy.d.ts +0 -1
- package/dist-lib/lib/core/chat-copy.js +1 -2
- package/dist-lib/lib/core/chat-move.d.ts +3 -1
- package/dist-lib/lib/core/chat-move.js +5 -2
- package/dist-lib/lib/core/contract/joined-meshes.js +2 -1
- package/dist-lib/lib/core/local/index.d.ts +2 -1
- package/dist-lib/lib/core/local/index.js +3 -2
- package/dist-lib/lib/core/public-mesh.d.ts +6 -8
- package/dist-lib/lib/core/public-mesh.js +19 -29
- package/dist-lib/lib/core/sync/index.js +1 -1
- package/dist-lib/lib/core.d.ts +15 -8
- package/dist-lib/lib/core.js +219 -203
- package/dist-lib/lib/errors.d.ts +4 -12
- package/dist-lib/lib/errors.js +4 -12
- package/dist-lib/schema/engine.js +10 -3
- package/dist-lib/schema/local.js +4 -2
- package/dist-lib/schema/qvac.js +2 -1
- package/dist-lib/spec/capabilities.d.ts +2 -2
- package/dist-lib/spec/hrpc/hrpc.json +1 -1
- package/dist-lib/spec/hrpc/index.js +1 -1
- package/dist-lib/spec/hrpc/messages.js +273 -250
- package/dist-lib/spec/hyperschema/index.js +273 -250
- package/dist-lib/spec/hyperschema/schema.json +27 -6
- package/dist-lib/spec/hyperschema/types.d.ts +7 -1
- package/dist-lib/spec/local/hyperdb/messages.js +26 -12
- package/dist-lib/spec/local/hyperschema/index.js +13 -6
- package/dist-lib/spec/local/hyperschema/schema.json +10 -0
- package/dist-lib/spec/local/hyperschema/types.d.ts +2 -0
- package/dist-lib/spec/mesh/hyperdb/messages.js +30 -6
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +15 -3
- package/dist-lib/spec/mesh/hyperschema/index.js +15 -3
- package/dist-lib/spec/mesh/hyperschema/schema.json +5 -0
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +1 -0
- package/package.json +1 -1
- package/tui/app.mjs +47 -12
|
@@ -67,8 +67,11 @@ export function createAgentsApi(pool, { deviceId, changed = null, modelPicked =
|
|
|
67
67
|
};
|
|
68
68
|
const agentHolder = async (meshId, agentId) => {
|
|
69
69
|
const mesh = await requireMesh(pool, meshId);
|
|
70
|
-
const
|
|
71
|
-
|
|
70
|
+
const named = mesh.role === 'account' && b4a.toHex(mesh.key) === meshId;
|
|
71
|
+
if (named || (await getAgent(mesh, agentId))) {
|
|
72
|
+
return mesh;
|
|
73
|
+
}
|
|
74
|
+
return requireMesh(pool, meshId, CHAT_ROWS);
|
|
72
75
|
};
|
|
73
76
|
return {
|
|
74
77
|
createAgent: async ({ meshId, config }) => {
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { listApprovalRules, removeApprovalRule } from '../core/approval-rules.js';
|
|
2
2
|
import { requireMesh } from './current-mesh.js';
|
|
3
|
+
const RULE_ROWS = { route: 'put-approval-rule' };
|
|
3
4
|
export function createApprovalRulesApi(pool) {
|
|
4
5
|
return {
|
|
5
6
|
listApprovalRules: async (request) => {
|
|
6
7
|
const mesh = await requireMesh(pool, request.meshId);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const account = await requireMesh(pool, request.meshId, RULE_ROWS);
|
|
9
|
+
const rules = await listApprovalRules(mesh);
|
|
10
|
+
if (account !== mesh) {
|
|
11
|
+
rules.push(...(await listApprovalRules(account)));
|
|
12
|
+
}
|
|
13
|
+
return { rules, ourMemberId: mesh.ourMemberId ?? undefined };
|
|
11
14
|
},
|
|
12
15
|
removeApprovalRule: async ({ meshId, ruleId }) => {
|
|
13
|
-
await removeApprovalRule(await requireMesh(pool, meshId,
|
|
16
|
+
await removeApprovalRule(await requireMesh(pool, meshId, RULE_ROWS), ruleId);
|
|
14
17
|
return { ok: true };
|
|
15
18
|
}
|
|
16
19
|
};
|
|
@@ -16,9 +16,8 @@ export interface CreateChatApiOptions {
|
|
|
16
16
|
} | null;
|
|
17
17
|
readonly deletedProject?: ProjectGone;
|
|
18
18
|
readonly projectOf?: ProjectOf | null;
|
|
19
|
-
readonly workspaceOf?: ((projectId: string) => Promise<string | null>) | null;
|
|
20
19
|
readonly log: LoggerInterface | null;
|
|
21
20
|
}
|
|
22
21
|
type ProjectGone = ((projectId: string) => Promise<boolean>) | null;
|
|
23
|
-
export declare function createChatApi(pool: MeshPool, local: LocalStore, { account, agents, deviceId, inferenceCalls, deletedProject, projectOf,
|
|
22
|
+
export declare function createChatApi(pool: MeshPool, local: LocalStore, { account, agents, deviceId, inferenceCalls, deletedProject, projectOf, log }: CreateChatApiOptions): ChatCapabilities;
|
|
24
23
|
export {};
|
package/dist-lib/lib/api/chat.js
CHANGED
|
@@ -9,7 +9,6 @@ import { forkChat } from '../core/chat-fork.js';
|
|
|
9
9
|
import { listChatPage } from '../core/chat-order.js';
|
|
10
10
|
import { searchChats } from '../core/chat-search.js';
|
|
11
11
|
import { heldMesh, meshWatchable, requireMesh } from './current-mesh.js';
|
|
12
|
-
import { CHATS } from '../core/collections.js';
|
|
13
12
|
const SEARCH_SUPERSEDED_ABORT = 'superseded by a newer chat search';
|
|
14
13
|
const WORKSPACE_ROWS = { route: 'put-project' };
|
|
15
14
|
async function projectLink(pool, chat, { projectId, projectOf }) {
|
|
@@ -44,15 +43,8 @@ async function listedIn(pool, chat, { project, projectOf }) {
|
|
|
44
43
|
async function liveLink(chat, gone) {
|
|
45
44
|
return chat.projectId && (await gone?.(chat.projectId)) ? { ...chat, projectId: undefined } : chat;
|
|
46
45
|
}
|
|
47
|
-
export function createChatApi(pool, local, { account = () => null, agents = null, deviceId, inferenceCalls = null, deletedProject = null, projectOf = null,
|
|
46
|
+
export function createChatApi(pool, local, { account = () => null, agents = null, deviceId, inferenceCalls = null, deletedProject = null, projectOf = null, log }) {
|
|
48
47
|
const picks = agents ?? accountPicks(account);
|
|
49
|
-
const linkScope = async (meshId, projectId) => {
|
|
50
|
-
const named = account();
|
|
51
|
-
if (!projectId || !named || b4a.toHex(named.key) !== meshId) {
|
|
52
|
-
return meshId;
|
|
53
|
-
}
|
|
54
|
-
return (await workspaceOf?.(projectId)) ?? meshId;
|
|
55
|
-
};
|
|
56
48
|
let searchAbort = null;
|
|
57
49
|
const chatList = (mesh, { limit, cursor }) => listChatPage(mesh, local, { limit: limit || undefined, cursor: cursor ?? undefined }).then(async (page) => ({
|
|
58
50
|
...page,
|
|
@@ -64,8 +56,7 @@ export function createChatApi(pool, local, { account = () => null, agents = null
|
|
|
64
56
|
if (shared && !projectId) {
|
|
65
57
|
throw new CoreError('CHAT_SHARED_NEEDS_PROJECT');
|
|
66
58
|
}
|
|
67
|
-
const
|
|
68
|
-
const mesh = await requireMesh(pool, scope);
|
|
59
|
+
const mesh = await requireMesh(pool, meshId);
|
|
69
60
|
const link = await projectLink(pool, mesh, { projectId, projectOf });
|
|
70
61
|
if (shared && link) {
|
|
71
62
|
const project = await requireMesh(pool, link);
|
|
@@ -76,7 +67,7 @@ export function createChatApi(pool, local, { account = () => null, agents = null
|
|
|
76
67
|
await picks.pick(mesh, agentId);
|
|
77
68
|
return {
|
|
78
69
|
...(await createChat(mesh, { agentId, title: config.title, projectId: link })),
|
|
79
|
-
meshId
|
|
70
|
+
meshId
|
|
80
71
|
};
|
|
81
72
|
},
|
|
82
73
|
listChats: async (request) => chatList(await requireMesh(pool, request.meshId), request),
|
|
@@ -98,12 +89,7 @@ export function createChatApi(pool, local, { account = () => null, agents = null
|
|
|
98
89
|
return set;
|
|
99
90
|
},
|
|
100
91
|
setChatProject: async ({ chatId, meshId, projectId }) => {
|
|
101
|
-
const
|
|
102
|
-
const mesh = await requireMesh(pool, scope);
|
|
103
|
-
const elsewhere = scope !== meshId && !(await mesh.view.get(CHATS, { id: chatId }));
|
|
104
|
-
if (elsewhere && (await (await requireMesh(pool, meshId)).view.get(CHATS, { id: chatId }))) {
|
|
105
|
-
throw new CoreError('CHAT_PROJECT_OTHER_WORKSPACE');
|
|
106
|
-
}
|
|
92
|
+
const mesh = await requireMesh(pool, meshId);
|
|
107
93
|
return setChatProject(mesh, chatId, await projectLink(pool, mesh, { projectId, projectOf }));
|
|
108
94
|
},
|
|
109
95
|
forkChat: async ({ meshId, targetMeshId, config, ...cut }) => {
|
|
@@ -76,7 +76,6 @@ interface ApiDeps {
|
|
|
76
76
|
deletedProject?: ((projectId: string) => Promise<boolean>) | null;
|
|
77
77
|
projectOf?: ProjectOf | null;
|
|
78
78
|
nameOf?: NameOf | null;
|
|
79
|
-
workspaceOf?: ((projectId: string) => Promise<string | null>) | null;
|
|
80
79
|
pushSkillSecret?: ((request: AssistantPushSkillSecretRequest) => Promise<void>) | null;
|
|
81
80
|
listQuarantinedSkills?: (() => Promise<AssistantQuarantinedSkillKeys>) | null;
|
|
82
81
|
retryQuarantinedSkills?: (() => Promise<AssistantQuarantinedSkillKeys>) | null;
|
|
@@ -79,7 +79,6 @@ export function createApi(deps = {}) {
|
|
|
79
79
|
inferenceCalls: deps.inferenceCalls ?? null,
|
|
80
80
|
deletedProject: deps.deletedProject ?? null,
|
|
81
81
|
projectOf: deps.projectOf ?? null,
|
|
82
|
-
workspaceOf: deps.workspaceOf ?? null,
|
|
83
82
|
log
|
|
84
83
|
})
|
|
85
84
|
: null),
|
|
@@ -138,7 +137,7 @@ export function createApi(deps = {}) {
|
|
|
138
137
|
...(mesh && state
|
|
139
138
|
? createHostRunLogApi(routed(mesh, 'append-chunk'), state.runLogs, deps.deviceId ?? null)
|
|
140
139
|
: null),
|
|
141
|
-
...(mesh ? createSyncApi(
|
|
140
|
+
...(mesh ? createSyncApi(mesh, log) : null),
|
|
142
141
|
...(mesh ? createToolConfigsApi(routed(mesh, 'put-tool-configs'), log) : null),
|
|
143
142
|
...(mesh
|
|
144
143
|
? createToolActivityApi(routed(mesh, 'append-tool-activity'), deps.deviceId ?? null, log)
|
|
@@ -37,7 +37,7 @@ export interface MeshStatusSource {
|
|
|
37
37
|
}): Promise<string>;
|
|
38
38
|
listArchived(): Promise<AssistantArchivedMeshList>;
|
|
39
39
|
archivedContents(meshId: string): Promise<AssistantArchivedMeshContents>;
|
|
40
|
-
migrateArchived(meshId: string): Promise<AssistantArchivedMeshMigration>;
|
|
40
|
+
migrateArchived(meshId: string, workspaceId: string): Promise<AssistantArchivedMeshMigration>;
|
|
41
41
|
recoverable(): Promise<boolean>;
|
|
42
42
|
publishRecovery(phrase: string): Promise<void>;
|
|
43
43
|
recover(phrase: string, timeout?: number): Promise<void>;
|
package/dist-lib/lib/api/mesh.js
CHANGED
|
@@ -49,7 +49,7 @@ export function createMeshApi(status, updateMember, log) {
|
|
|
49
49
|
},
|
|
50
50
|
listArchivedMeshes: () => status.listArchived(),
|
|
51
51
|
archivedMeshContents: ({ meshId }) => status.archivedContents(meshId),
|
|
52
|
-
migrateArchivedMesh: ({ meshId }) => status.migrateArchived(meshId),
|
|
52
|
+
migrateArchivedMesh: ({ meshId, workspaceId }) => status.migrateArchived(meshId, workspaceId),
|
|
53
53
|
accountRecoverable: async () => ({
|
|
54
54
|
recoverable: await status.recoverable()
|
|
55
55
|
}),
|
package/dist-lib/lib/api/sync.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isCoreError } from '../errors.js';
|
|
2
|
+
import { requireMesh, routed } from './current-mesh.js';
|
|
2
3
|
import { watchable } from './watchable.js';
|
|
3
4
|
export function createSyncApi(pool, log) {
|
|
5
|
+
const chats = routed(pool, 'append-chunk');
|
|
4
6
|
return {
|
|
5
|
-
syncStatusWatch: watchable(async (request) =>
|
|
7
|
+
syncStatusWatch: watchable(async (request) => {
|
|
8
|
+
const mesh = await requireMesh(chats, request.meshId, { follow: true }).catch((err) => {
|
|
9
|
+
if (isCoreError(err, 'ROUTE_NEEDS_WORKSPACE')) {
|
|
10
|
+
return requireMesh(pool, request.meshId, { follow: true });
|
|
11
|
+
}
|
|
12
|
+
throw err;
|
|
13
|
+
});
|
|
14
|
+
return mesh.syncActivity ?? null;
|
|
15
|
+
}, (_request, activity) => activity.snapshot(), { name: 'syncStatusWatch', log })
|
|
6
16
|
};
|
|
7
17
|
}
|
|
@@ -281,7 +281,6 @@ export class QvacAssistant extends ReadyResource {
|
|
|
281
281
|
_deviceId;
|
|
282
282
|
_info;
|
|
283
283
|
_lastCapabilities = new Map();
|
|
284
|
-
_ownWorkspace = null;
|
|
285
284
|
_listed = [];
|
|
286
285
|
_accountHosted = [];
|
|
287
286
|
_readySkills;
|
|
@@ -1407,7 +1406,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1407
1406
|
const read = new Set();
|
|
1408
1407
|
const closed = new Set();
|
|
1409
1408
|
for (const mesh of this._listed) {
|
|
1410
|
-
if (mesh.
|
|
1409
|
+
if (mesh.account)
|
|
1411
1410
|
continue;
|
|
1412
1411
|
if (!mesh.open) {
|
|
1413
1412
|
closed.add(mesh.meshId);
|
|
@@ -1552,11 +1551,9 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1552
1551
|
}
|
|
1553
1552
|
_syncMeshConsumers(meshes) {
|
|
1554
1553
|
this._listed = meshes;
|
|
1555
|
-
const consumed = meshes.filter((mesh) => mesh.open
|
|
1556
|
-
const open = new Set(consumed.map((mesh) => mesh.meshId));
|
|
1557
|
-
const served = new Set(consumed.filter((mesh) => mesh.served).map((mesh) => mesh.meshId));
|
|
1554
|
+
const consumed = new Map(meshes.filter((mesh) => mesh.open).map((mesh) => [mesh.meshId, mesh]));
|
|
1558
1555
|
for (const [meshId, consumer] of this._meshConsumers) {
|
|
1559
|
-
if (
|
|
1556
|
+
if (consumed.has(meshId))
|
|
1560
1557
|
continue;
|
|
1561
1558
|
consumer.stop();
|
|
1562
1559
|
this._meshConsumers.delete(meshId);
|
|
@@ -1566,18 +1563,14 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1566
1563
|
}
|
|
1567
1564
|
this._servedChats.delete(meshId);
|
|
1568
1565
|
}
|
|
1569
|
-
for (const meshId of
|
|
1570
|
-
const consumer = this._meshConsumers.get(meshId) ?? this._meshConsumer(
|
|
1566
|
+
for (const [meshId, entry] of consumed) {
|
|
1567
|
+
const consumer = this._meshConsumers.get(meshId) ?? this._meshConsumer(entry);
|
|
1571
1568
|
this._meshConsumers.set(meshId, consumer);
|
|
1572
1569
|
consumer.start();
|
|
1573
1570
|
}
|
|
1574
1571
|
}
|
|
1575
1572
|
_followAccount(account) {
|
|
1576
1573
|
this._accountMeshId = account.meshId ?? null;
|
|
1577
|
-
if ((account.ownWorkspace ?? null) !== this._ownWorkspace) {
|
|
1578
|
-
this._ownWorkspace = account.ownWorkspace ?? null;
|
|
1579
|
-
this._syncMeshConsumers(this._listed);
|
|
1580
|
-
}
|
|
1581
1574
|
const on = account.meshId ? `${account.meshId}:${account.writable}` : null;
|
|
1582
1575
|
if (on === null) {
|
|
1583
1576
|
this._advertisedOn = null;
|
|
@@ -1593,7 +1586,11 @@ export class QvacAssistant extends ReadyResource {
|
|
|
1593
1586
|
void this._reconcileDeviceProfile();
|
|
1594
1587
|
this._triggerModelWarm();
|
|
1595
1588
|
}
|
|
1596
|
-
_meshConsumer(meshId, served) {
|
|
1589
|
+
_meshConsumer({ meshId, served = false, account }) {
|
|
1590
|
+
if (account) {
|
|
1591
|
+
const agents = this._streamWatch(`agent:${meshId}`, () => this._engine.agentsWatch({ meshId }), (frames) => this._followAgentEdits(meshId, frames));
|
|
1592
|
+
return { start: () => agents.start(), stop: () => agents.stop() };
|
|
1593
|
+
}
|
|
1597
1594
|
const watches = [
|
|
1598
1595
|
this._streamWatch(`chat-list:${meshId}`, () => this._engine.chatsWatch({ meshId }), (frames) => this._reclaimDeletedChats(frames, meshId, served)),
|
|
1599
1596
|
this._streamWatch(`kv-cache-retention:${meshId}`, () => this._engine.configWatch({ key: KV_CACHE_RETENTION_KEY }), (frames) => this._sweepIdleChatCaches(meshId, frames))
|
|
@@ -13,6 +13,7 @@ export interface ArchivedMeshContents extends ArchivedMeshCounts {
|
|
|
13
13
|
readonly meshId: string;
|
|
14
14
|
}
|
|
15
15
|
export interface ArchivedMeshMigration extends ArchivedMeshContents {
|
|
16
|
+
readonly workspaceId: string;
|
|
16
17
|
readonly migrated: boolean;
|
|
17
18
|
readonly migratedAt: number;
|
|
18
19
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import crypto from 'hypercore-crypto';
|
|
3
3
|
import { copyBlob, copyChunks, stripped } from './chat-copy.js';
|
|
4
|
-
import {
|
|
4
|
+
import { publicMeshKey, publicSeed } from './public-mesh.js';
|
|
5
5
|
import { Mesh } from './mesh.js';
|
|
6
6
|
import { recordedRole } from './local/index.js';
|
|
7
7
|
import { ACTIVE_AGENTS, ACTIVE_CHATS, ACTIVE_CHAT_GROUPS, ACTIVE_TOOL_CONFIGS_BY_AGENT, AGENTS, KNOWLEDGE, MESH_SEEDS } from './collections.js';
|
|
@@ -37,26 +37,23 @@ export async function withArchivedMesh(row, opts, fn) {
|
|
|
37
37
|
await mesh.close();
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
async function
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
keys.push(row.meshKey);
|
|
40
|
+
async function migratedWorkspace(account, opts) {
|
|
41
|
+
for await (const { meshKey } of account.view.find(MESH_SEEDS)) {
|
|
42
|
+
const record = await opts.publicRecord?.(meshKey);
|
|
43
|
+
if (record?.migrated) {
|
|
44
|
+
return { workspaceKey: meshKey, record };
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
|
-
return
|
|
47
|
+
return null;
|
|
49
48
|
}
|
|
50
49
|
async function openArchivedPublic(account, opts) {
|
|
51
|
-
const
|
|
52
|
-
const
|
|
50
|
+
const migrated = await migratedWorkspace(account, opts);
|
|
51
|
+
const workspaceKey = migrated?.workspaceKey;
|
|
52
|
+
const record = migrated?.record;
|
|
53
53
|
const key = record?.key
|
|
54
54
|
? b4a.from(record.key, 'hex')
|
|
55
55
|
: workspaceKey && (await publicMeshKey(account, workspaceKey));
|
|
56
|
-
if (!workspaceKey ||
|
|
57
|
-
!record?.migrated ||
|
|
58
|
-
!key ||
|
|
59
|
-
!(await opts.storage.hasCore(crypto.discoveryKey(key)))) {
|
|
56
|
+
if (!workspaceKey || !record || !key || !(await opts.storage.hasCore(crypto.discoveryKey(key)))) {
|
|
60
57
|
return null;
|
|
61
58
|
}
|
|
62
59
|
const mesh = new Mesh(opts.store, {
|
|
@@ -35,7 +35,6 @@ export declare function stripped<T extends {
|
|
|
35
35
|
export interface ContentCopy extends MeshCopy {
|
|
36
36
|
readonly deviceId: Buffer;
|
|
37
37
|
readonly chats?: ReadonlySet<string>;
|
|
38
|
-
readonly unlinkProjects?: boolean;
|
|
39
38
|
readonly endsOpenRuns?: boolean;
|
|
40
39
|
}
|
|
41
40
|
export declare function copyContent(copy: ContentCopy): Promise<void>;
|
|
@@ -222,9 +222,8 @@ async function copyRows(snap, copy, remap) {
|
|
|
222
222
|
}
|
|
223
223
|
if (await newer(into, CHATS, chat)) {
|
|
224
224
|
const groupId = copy.chats ? undefined : chat.groupId;
|
|
225
|
-
const projectId = copy.unlinkProjects ? undefined : chat.projectId;
|
|
226
225
|
batch.dispatch('put-chat', {
|
|
227
|
-
chat: { ...stripped(chat), agentId: agent?.id ?? chat.agentId, groupId
|
|
226
|
+
chat: { ...stripped(chat), agentId: agent?.id ?? chat.agentId, groupId }
|
|
228
227
|
});
|
|
229
228
|
}
|
|
230
229
|
}
|
|
@@ -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:
|
|
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
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
12
|
-
export declare function
|
|
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,
|
|
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
|
|
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
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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
|
|
35
|
-
|
|
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');
|
package/dist-lib/lib/core.d.ts
CHANGED
|
@@ -245,14 +245,16 @@ export declare class Core extends ReadyResource {
|
|
|
245
245
|
private _publicBoots;
|
|
246
246
|
private readonly _meshNames;
|
|
247
247
|
private _ownWorkspaceId;
|
|
248
|
+
private _ownDecided;
|
|
248
249
|
private readonly _publicWriters;
|
|
249
250
|
private readonly _leftPublic;
|
|
250
251
|
private readonly _publicWaiters;
|
|
251
252
|
private readonly _publicFollow;
|
|
252
253
|
private readonly _publicMerges;
|
|
253
|
-
private readonly
|
|
254
|
-
private readonly _ownCarries;
|
|
254
|
+
private readonly _publicDrops;
|
|
255
255
|
private _publicMigration;
|
|
256
|
+
private _copyAgain;
|
|
257
|
+
private _accountCopied;
|
|
256
258
|
private readonly _agentCopies;
|
|
257
259
|
private readonly _sharedAgents;
|
|
258
260
|
private readonly _memberKeyWrites;
|
|
@@ -272,6 +274,7 @@ export declare class Core extends ReadyResource {
|
|
|
272
274
|
private _backfill;
|
|
273
275
|
private _leaving;
|
|
274
276
|
private readonly _kickedMeshes;
|
|
277
|
+
private readonly _haltedMeshes;
|
|
275
278
|
private readonly _kickCloses;
|
|
276
279
|
private readonly _retiredMeshes;
|
|
277
280
|
private _retiredAccount;
|
|
@@ -389,6 +392,7 @@ export declare class Core extends ReadyResource {
|
|
|
389
392
|
private _stopEntryIndexing;
|
|
390
393
|
private _releaseVectorIndex;
|
|
391
394
|
private _withdrawFromMesh;
|
|
395
|
+
private _markHalted;
|
|
392
396
|
private _reviewKick;
|
|
393
397
|
private _onKicked;
|
|
394
398
|
private _kickOutlivesTransition;
|
|
@@ -484,7 +488,6 @@ export declare class Core extends ReadyResource {
|
|
|
484
488
|
private _shareProjectSeed;
|
|
485
489
|
private _shareMemberKey;
|
|
486
490
|
private _writeMemberKey;
|
|
487
|
-
private _contentMesh;
|
|
488
491
|
private _devicesOf;
|
|
489
492
|
private _hasPublic;
|
|
490
493
|
private _publicOf;
|
|
@@ -492,14 +495,13 @@ export declare class Core extends ReadyResource {
|
|
|
492
495
|
private _publicWorkspaces;
|
|
493
496
|
private _settlePublicMeshes;
|
|
494
497
|
private _settleOwnWorkspace;
|
|
498
|
+
private _mintsOwnWorkspace;
|
|
499
|
+
private _markDerivedInitial;
|
|
495
500
|
private _mintOwnWorkspace;
|
|
496
501
|
private _setOwnWorkspace;
|
|
497
502
|
private _retireLeftPublic;
|
|
498
503
|
private _leftWorkspaces;
|
|
499
|
-
private
|
|
500
|
-
private _carryProjects;
|
|
501
|
-
private _carryAgentUsers;
|
|
502
|
-
private _carryLeftPublic;
|
|
504
|
+
private _dropLeftPublic;
|
|
503
505
|
private _settlePublicMesh;
|
|
504
506
|
private _publicRecord;
|
|
505
507
|
private _savePublicRecord;
|
|
@@ -508,6 +510,8 @@ export declare class Core extends ReadyResource {
|
|
|
508
510
|
private _mintPublicBirth;
|
|
509
511
|
private _mergeLostMint;
|
|
510
512
|
private _migrateIntoPublic;
|
|
513
|
+
private _recordCopied;
|
|
514
|
+
private _markCopied;
|
|
511
515
|
private _followAgentCopies;
|
|
512
516
|
private _keepAgentCopies;
|
|
513
517
|
private _agentPicks;
|
|
@@ -576,7 +580,8 @@ export declare class Core extends ReadyResource {
|
|
|
576
580
|
private _readMeshList;
|
|
577
581
|
listArchivedMeshes(): Promise<AssistantArchivedMeshList>;
|
|
578
582
|
archivedMeshContents(meshId: string): Promise<ArchivedMeshContents>;
|
|
579
|
-
migrateArchivedMesh(meshId: string): Promise<ArchivedMeshMigration>;
|
|
583
|
+
migrateArchivedMesh(meshId: string, workspaceId: string): Promise<ArchivedMeshMigration>;
|
|
584
|
+
private _archiveDestination;
|
|
580
585
|
private _archivedRow;
|
|
581
586
|
private _withArchivedMesh;
|
|
582
587
|
private _ownMeshes;
|
|
@@ -674,8 +679,10 @@ export declare class Core extends ReadyResource {
|
|
|
674
679
|
private _servedMeshList;
|
|
675
680
|
private _foreignEntry;
|
|
676
681
|
private _definesAgents;
|
|
682
|
+
private _refuseAccountContent;
|
|
677
683
|
private _routesToPublic;
|
|
678
684
|
private _routedMesh;
|
|
685
|
+
private _holdsPublic;
|
|
679
686
|
private _publicById;
|
|
680
687
|
private _meshStatusSource;
|
|
681
688
|
private _blindPeeringSource;
|