@qvac/core 0.3.4 → 0.4.0
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/README.md +19 -17
- package/dist-lib/lib/api/agents.d.ts +3 -3
- package/dist-lib/lib/api/agents.js +31 -20
- package/dist-lib/lib/api/approval-rules.d.ts +2 -2
- package/dist-lib/lib/api/approval-rules.js +2 -2
- package/dist-lib/lib/api/attachments.d.ts +2 -2
- package/dist-lib/lib/api/attachments.js +14 -25
- package/dist-lib/lib/api/chat-groups.d.ts +2 -2
- package/dist-lib/lib/api/chat-groups.js +9 -9
- package/dist-lib/lib/api/chat.d.ts +4 -2
- package/dist-lib/lib/api/chat.js +18 -18
- package/dist-lib/lib/api/chunks.d.ts +2 -2
- package/dist-lib/lib/api/chunks.js +27 -36
- package/dist-lib/lib/api/current-mesh.d.ts +7 -15
- package/dist-lib/lib/api/current-mesh.js +7 -22
- package/dist-lib/lib/api/devices.d.ts +4 -3
- package/dist-lib/lib/api/devices.js +18 -18
- package/dist-lib/lib/api/execution.d.ts +2 -2
- package/dist-lib/lib/api/execution.js +6 -6
- package/dist-lib/lib/api/files.d.ts +2 -2
- package/dist-lib/lib/api/files.js +4 -4
- package/dist-lib/lib/api/index.d.ts +12 -11
- package/dist-lib/lib/api/index.js +15 -13
- package/dist-lib/lib/api/inference-calls.d.ts +1 -1
- package/dist-lib/lib/api/inference-calls.js +2 -2
- package/dist-lib/lib/api/knowledge.d.ts +2 -2
- package/dist-lib/lib/api/knowledge.js +22 -11
- package/dist-lib/lib/api/local-files.d.ts +3 -0
- package/dist-lib/lib/api/local-files.js +23 -0
- package/dist-lib/lib/api/members.d.ts +6 -2
- package/dist-lib/lib/api/members.js +24 -17
- package/dist-lib/lib/api/mesh.d.ts +4 -5
- package/dist-lib/lib/api/mesh.js +7 -9
- package/dist-lib/lib/api/notifications.d.ts +2 -13
- package/dist-lib/lib/api/notifications.js +20 -52
- package/dist-lib/lib/api/rag.d.ts +2 -2
- package/dist-lib/lib/api/rag.js +4 -4
- package/dist-lib/lib/api/range.d.ts +11 -0
- package/dist-lib/lib/api/range.js +10 -0
- package/dist-lib/lib/api/sync.d.ts +2 -2
- package/dist-lib/lib/api/sync.js +3 -3
- package/dist-lib/lib/api/tool-activity.d.ts +2 -2
- package/dist-lib/lib/api/tool-activity.js +11 -10
- package/dist-lib/lib/api/tool-configs.d.ts +2 -2
- package/dist-lib/lib/api/tool-configs.js +6 -7
- package/dist-lib/lib/api/upload-frames.d.ts +9 -0
- package/dist-lib/lib/api/upload-frames.js +17 -0
- package/dist-lib/lib/api/watchable.d.ts +1 -6
- package/dist-lib/lib/api/watchable.js +4 -13
- package/dist-lib/lib/assistant/history.d.ts +3 -3
- package/dist-lib/lib/assistant-client.js +3 -2
- package/dist-lib/lib/assistant-tree.js +1 -1
- package/dist-lib/lib/assistant.d.ts +16 -14
- package/dist-lib/lib/assistant.js +166 -137
- package/dist-lib/lib/collabora/convert.js +1 -1
- package/dist-lib/lib/core/agent.d.ts +5 -7
- package/dist-lib/lib/core/agent.js +26 -6
- package/dist-lib/lib/core/archived-mesh.js +1 -0
- package/dist-lib/lib/core/chat-order.d.ts +20 -0
- package/dist-lib/lib/core/chat-order.js +96 -0
- package/dist-lib/lib/core/chat.d.ts +0 -5
- package/dist-lib/lib/core/chat.js +1 -3
- package/dist-lib/lib/core/chunk.d.ts +7 -14
- package/dist-lib/lib/core/chunk.js +17 -35
- package/dist-lib/lib/core/contract/agents.js +8 -0
- package/dist-lib/lib/core/contract/compute.d.ts +1 -1
- package/dist-lib/lib/core/contract/compute.js +1 -0
- package/dist-lib/lib/core/contract/joined-meshes.js +4 -3
- package/dist-lib/lib/core/contract/members.js +4 -3
- package/dist-lib/lib/core/contract/writers.js +5 -4
- package/dist-lib/lib/core/departures.js +5 -4
- package/dist-lib/lib/core/device-invites.js +2 -1
- package/dist-lib/lib/core/files/attachments.d.ts +8 -1
- package/dist-lib/lib/core/files/index.d.ts +4 -4
- package/dist-lib/lib/core/files/index.js +18 -8
- package/dist-lib/lib/core/files/local-index.d.ts +16 -0
- package/dist-lib/lib/core/files/local-index.js +38 -0
- package/dist-lib/lib/core/files/processing/document.js +2 -1
- package/dist-lib/lib/core/files/processing/ownership.js +6 -3
- package/dist-lib/lib/core/files/records/chunks.js +1 -0
- package/dist-lib/lib/core/files/records/reclaim.js +1 -0
- package/dist-lib/lib/core/files/records/routing.js +2 -1
- package/dist-lib/lib/core/files/store/blob.d.ts +1 -1
- package/dist-lib/lib/core/files/store/blob.js +6 -3
- package/dist-lib/lib/core/files/store/index.d.ts +1 -1
- package/dist-lib/lib/core/files/store/reference.js +4 -3
- package/dist-lib/lib/core/files/store/server.d.ts +8 -4
- package/dist-lib/lib/core/files/store/server.js +16 -12
- package/dist-lib/lib/core/files/store/sweep.js +2 -1
- package/dist-lib/lib/core/files/upload.d.ts +1 -1
- package/dist-lib/lib/core/hosted-agents.js +1 -1
- package/dist-lib/lib/core/image/cache-sweep.d.ts +1 -0
- package/dist-lib/lib/core/image/cache-sweep.js +7 -3
- package/dist-lib/lib/core/local/files.d.ts +24 -0
- package/dist-lib/lib/core/local/files.js +154 -0
- package/dist-lib/lib/core/local/index.d.ts +21 -5
- package/dist-lib/lib/core/local/index.js +75 -45
- package/dist-lib/lib/core/membership.d.ts +4 -1
- package/dist-lib/lib/core/membership.js +17 -2
- package/dist-lib/lib/core/mesh.d.ts +5 -0
- package/dist-lib/lib/core/mesh.js +11 -5
- package/dist-lib/lib/core/migrations/agent-indexes.d.ts +2 -0
- package/dist-lib/lib/core/migrations/agent-indexes.js +30 -0
- package/dist-lib/lib/core/migrations/file-index.d.ts +2 -0
- package/dist-lib/lib/core/migrations/file-index.js +27 -0
- package/dist-lib/lib/core/migrations/index.js +3 -1
- package/dist-lib/lib/core/notification.js +5 -5
- package/dist-lib/lib/core/range.d.ts +18 -0
- package/dist-lib/lib/core/range.js +17 -0
- package/dist-lib/lib/core/sync/index.js +39 -32
- package/dist-lib/lib/core/sync-status.js +3 -2
- package/dist-lib/lib/core/tool-activity.d.ts +2 -5
- package/dist-lib/lib/core/tool-activity.js +4 -7
- package/dist-lib/lib/core.d.ts +48 -29
- package/dist-lib/lib/core.js +465 -359
- package/dist-lib/lib/knowledge-search.d.ts +2 -2
- package/dist-lib/lib/kv-cache.js +1 -1
- package/dist-lib/lib/log.js +2 -3
- package/dist-lib/lib/mesh-scoped-engine.d.ts +8 -1
- package/dist-lib/lib/mesh-scoped-engine.js +62 -15
- package/dist-lib/lib/model-download.d.ts +14 -5
- package/dist-lib/lib/model-download.js +25 -17
- package/dist-lib/lib/run-transcript.d.ts +2 -2
- package/dist-lib/lib/run-transcript.js +3 -2
- package/dist-lib/lib/task.d.ts +1 -0
- package/dist-lib/lib/task.js +3 -2
- package/dist-lib/schema/build.js +4 -10
- package/dist-lib/schema/engine.js +261 -91
- package/dist-lib/schema/helpers.d.ts +4 -0
- package/dist-lib/schema/helpers.js +20 -0
- package/dist-lib/schema/local.d.ts +1 -1
- package/dist-lib/schema/local.js +70 -2
- package/dist-lib/schema/qvac.js +30 -0
- package/dist-lib/spec/bind.js +20 -3
- package/dist-lib/spec/calls.js +19 -15
- package/dist-lib/spec/capabilities.d.ts +42 -34
- package/dist-lib/spec/hrpc/hrpc.json +82 -30
- package/dist-lib/spec/hrpc/index.js +106 -57
- package/dist-lib/spec/hrpc/messages.js +5420 -5019
- package/dist-lib/spec/hyperschema/index.js +5424 -5023
- package/dist-lib/spec/hyperschema/schema.json +3202 -2666
- package/dist-lib/spec/hyperschema/types.d.ts +455 -319
- package/dist-lib/spec/local/hyperdb/db.json +119 -1
- package/dist-lib/spec/local/hyperdb/index.js +414 -2
- package/dist-lib/spec/local/hyperdb/messages.js +505 -124
- package/dist-lib/spec/local/hyperschema/index.js +203 -5
- package/dist-lib/spec/local/hyperschema/schema.json +136 -1
- package/dist-lib/spec/local/hyperschema/types.d.ts +32 -1
- package/dist-lib/spec/mesh/hyperdb/db.json +55 -3
- package/dist-lib/spec/mesh/hyperdb/index.js +119 -3
- package/dist-lib/spec/mesh/hyperdb/messages.js +244 -172
- package/dist-lib/spec/mesh/hyperdispatch/dispatch.json +7 -1
- package/dist-lib/spec/mesh/hyperdispatch/index.js +18 -1
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +74 -2
- package/dist-lib/spec/mesh/hyperschema/index.js +74 -2
- package/dist-lib/spec/mesh/hyperschema/schema.json +27 -1
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +9 -1
- package/package.json +6 -6
- package/tui/app.mjs +376 -151
- package/tui/boot.mjs +2 -1
- package/tui/lib/busy-words.mjs +2 -1
- package/tui/lib/knowledge-command.mjs +11 -10
- package/tui/lib/knowledge-import.mjs +7 -5
- package/tui/lib/render.mjs +4 -3
- package/tui/lib/usage.mjs +2 -1
- package/tui/main.mjs +2 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { deriveNotifications } from '../core/notification.js';
|
|
2
2
|
import { requireMesh } from './current-mesh.js';
|
|
3
3
|
import { watchable } from './watchable.js';
|
|
4
|
-
export function createNotificationsApi(
|
|
4
|
+
export function createNotificationsApi(pool, local, options = {}) {
|
|
5
5
|
return {
|
|
6
|
-
notificationsWatch: watchable('notificationsWatch', () => notificationSource(
|
|
7
|
-
ackNotification: async ({ chatId, seq, notificationId }) => {
|
|
6
|
+
notificationsWatch: watchable('notificationsWatch', async (request) => notificationSource(await requireMesh(pool, request.meshId), local), (request, source) => notificationSnapshot(source.mesh, local, request.limit, options.deviceId)),
|
|
7
|
+
ackNotification: async ({ chatId, seq, notificationId, meshId }) => {
|
|
8
8
|
if (notificationId) {
|
|
9
9
|
if ((chatId !== undefined && chatId !== null) || (seq ?? 0) !== 0) {
|
|
10
10
|
throw new Error('notification acknowledgement must select one source');
|
|
@@ -15,79 +15,47 @@ export function createNotificationsApi(current, local, options = {}) {
|
|
|
15
15
|
if (!chatId || seq === undefined || seq === null) {
|
|
16
16
|
throw new Error('chat acknowledgement requires chatId and seq');
|
|
17
17
|
}
|
|
18
|
-
await requireMesh(
|
|
18
|
+
await requireMesh(pool, meshId);
|
|
19
19
|
await local.ackChatNotify(chatId, seq);
|
|
20
20
|
}
|
|
21
21
|
return { ok: true };
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
function notificationSource(
|
|
26
|
-
let mesh = null;
|
|
27
|
-
let generation = 0;
|
|
28
|
-
let watching = false;
|
|
29
|
-
let listener = null;
|
|
30
|
-
const notify = () => listener?.();
|
|
31
|
-
const detach = () => {
|
|
32
|
-
mesh?.unwatch(notify);
|
|
33
|
-
mesh?.off('close', changed);
|
|
34
|
-
mesh = null;
|
|
35
|
-
};
|
|
36
|
-
const changed = () => {
|
|
37
|
-
const version = ++generation;
|
|
38
|
-
detach();
|
|
39
|
-
notify();
|
|
40
|
-
void Promise.resolve(current())
|
|
41
|
-
.then((next) => {
|
|
42
|
-
if (!watching || version !== generation || next?.closing || next?.closed)
|
|
43
|
-
return;
|
|
44
|
-
mesh = next;
|
|
45
|
-
mesh?.watch(notify);
|
|
46
|
-
mesh?.once('close', changed);
|
|
47
|
-
notify();
|
|
48
|
-
})
|
|
49
|
-
.catch(notify);
|
|
50
|
-
};
|
|
25
|
+
function notificationSource(mesh, local) {
|
|
51
26
|
return {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
local.watch(
|
|
56
|
-
options.changes?.watch(changed);
|
|
57
|
-
changed();
|
|
27
|
+
mesh,
|
|
28
|
+
watch(listener) {
|
|
29
|
+
mesh.watch(listener);
|
|
30
|
+
local.watch(listener);
|
|
58
31
|
},
|
|
59
|
-
unwatch() {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
detach();
|
|
63
|
-
local.unwatch(notify);
|
|
64
|
-
options.changes?.unwatch(changed);
|
|
65
|
-
listener = null;
|
|
32
|
+
unwatch(listener) {
|
|
33
|
+
mesh.unwatch(listener);
|
|
34
|
+
local.unwatch(listener);
|
|
66
35
|
},
|
|
67
|
-
once: (event,
|
|
68
|
-
off: (event,
|
|
36
|
+
once: (event, listener) => mesh.once(event, listener),
|
|
37
|
+
off: (event, listener) => mesh.off(event, listener),
|
|
69
38
|
get closing() {
|
|
70
|
-
return
|
|
39
|
+
return mesh.closing;
|
|
71
40
|
},
|
|
72
41
|
get closed() {
|
|
73
|
-
return
|
|
42
|
+
return mesh.closed;
|
|
74
43
|
}
|
|
75
44
|
};
|
|
76
45
|
}
|
|
77
|
-
async function notificationSnapshot(
|
|
78
|
-
const mesh = await current();
|
|
46
|
+
async function notificationSnapshot(mesh, local, requestedLimit, deviceId) {
|
|
79
47
|
let chats = { notifications: [] };
|
|
80
|
-
if (
|
|
48
|
+
if (!mesh.closing && !mesh.closed) {
|
|
81
49
|
try {
|
|
82
50
|
chats = await deriveNotifications(mesh, local, Number.MAX_SAFE_INTEGER, deviceId);
|
|
83
51
|
}
|
|
84
52
|
catch (error) {
|
|
85
|
-
if (
|
|
53
|
+
if (!mesh.closing && !mesh.closed)
|
|
86
54
|
throw error;
|
|
87
55
|
}
|
|
88
56
|
}
|
|
89
57
|
const models = await local.getModelNotifications();
|
|
90
|
-
if (mesh
|
|
58
|
+
if (mesh.closing || mesh.closed)
|
|
91
59
|
chats = { notifications: [] };
|
|
92
60
|
const notifications = [
|
|
93
61
|
...(chats.notifications ?? []),
|
|
@@ -2,6 +2,6 @@ import '../logger.ts';
|
|
|
2
2
|
import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
|
|
3
3
|
import type { QvacAgent } from '../../spec/mesh/hyperschema/types.d.ts';
|
|
4
4
|
import { type IndexingEmbedder, type VectorIndex } from '../core/files/index.ts';
|
|
5
|
-
import { type
|
|
5
|
+
import { type MeshPool } from './current-mesh.ts';
|
|
6
6
|
export declare const MAX_RAG_SEARCH_LIMIT = 20;
|
|
7
|
-
export declare function createRagApi(
|
|
7
|
+
export declare function createRagApi(pool: MeshPool, index: (meshId: string) => VectorIndex | null, embedder: (meshId: string) => IndexingEmbedder | null, effectiveCtxSize?: ((agent: QvacAgent | null) => Promise<number>) | null): Pick<CapabilityHandlers, 'ragSearch'>;
|
package/dist-lib/lib/api/rag.js
CHANGED
|
@@ -11,12 +11,12 @@ function clampLimit(limit) {
|
|
|
11
11
|
return DEFAULT_RAG_SEARCH_LIMIT;
|
|
12
12
|
return Math.min(Math.max(1, Math.floor(limit)), MAX_RAG_SEARCH_LIMIT);
|
|
13
13
|
}
|
|
14
|
-
export function createRagApi(
|
|
14
|
+
export function createRagApi(pool, index, embedder, effectiveCtxSize = null) {
|
|
15
15
|
return {
|
|
16
16
|
ragSearch: async ({ chatId, query, mode, limit, attachmentIds, meshId }) => {
|
|
17
17
|
let pendingFiles = [];
|
|
18
18
|
const respond = (overrides) => response({ pendingFiles, ...overrides });
|
|
19
|
-
const mesh = await requireMesh(
|
|
19
|
+
const mesh = await requireMesh(pool, meshId);
|
|
20
20
|
const chat = await getChat(mesh, chatId);
|
|
21
21
|
const toolMode = mode === 'tool';
|
|
22
22
|
if (!chat)
|
|
@@ -61,8 +61,8 @@ export function createRagApi(current, index, embedder, effectiveCtxSize = null)
|
|
|
61
61
|
scopeRows = rows.filter((row) => scopeIds.has(row.id));
|
|
62
62
|
}
|
|
63
63
|
const hasKnowledge = rows.length > 0;
|
|
64
|
-
const vectorIndex = index();
|
|
65
|
-
const embed = embedder();
|
|
64
|
+
const vectorIndex = index(meshId);
|
|
65
|
+
const embed = embedder(meshId);
|
|
66
66
|
if (!vectorIndex || !embed) {
|
|
67
67
|
return respond({ hasKnowledge, errorMessage: 'knowledge index unavailable on this device' });
|
|
68
68
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Bounds } from '../core/range.ts';
|
|
2
|
+
type WireBounds = {
|
|
3
|
+
gt?: number | null;
|
|
4
|
+
gte?: number | null;
|
|
5
|
+
lt?: number | null;
|
|
6
|
+
lte?: number | null;
|
|
7
|
+
reverse?: boolean | null;
|
|
8
|
+
limit?: number | null;
|
|
9
|
+
};
|
|
10
|
+
export declare function bounds({ gt, gte, lt, lte, reverse, limit }: WireBounds): Bounds;
|
|
11
|
+
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
|
|
2
|
-
import { type
|
|
3
|
-
export declare function createSyncApi(
|
|
2
|
+
import { type MeshPool } from './current-mesh.ts';
|
|
3
|
+
export declare function createSyncApi(pool: MeshPool): Pick<CapabilityHandlers, 'syncStatusWatch'>;
|
package/dist-lib/lib/api/sync.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { requireMesh } from './current-mesh.js';
|
|
2
2
|
import { watchable } from './watchable.js';
|
|
3
|
-
export function createSyncApi(
|
|
3
|
+
export function createSyncApi(pool) {
|
|
4
4
|
return {
|
|
5
|
-
syncStatusWatch: watchable('syncStatusWatch', async () => (await
|
|
5
|
+
syncStatusWatch: watchable('syncStatusWatch', async (request) => (await requireMesh(pool, request.meshId)).syncActivity ?? null, (_request, activity) => activity.snapshot())
|
|
6
6
|
};
|
|
7
7
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
|
|
2
|
-
import { type
|
|
2
|
+
import { type MeshPool } from './current-mesh.ts';
|
|
3
3
|
type ToolActivityCapabilities = Pick<CapabilityHandlers, 'listToolActivity' | 'toolActivityWatch' | 'recordToolActivity'>;
|
|
4
|
-
export declare function createToolActivityApi(
|
|
4
|
+
export declare function createToolActivityApi(pool: MeshPool, deviceId: Buffer | null): ToolActivityCapabilities;
|
|
5
5
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { listToolActivity, recordToolActivity } from '../core/tool-activity.js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { meshWatchable, requireMesh } from './current-mesh.js';
|
|
3
|
+
import { bounds } from './range.js';
|
|
4
|
+
import b4a from 'b4a';
|
|
4
5
|
const DEFAULT_LIMIT = 200;
|
|
5
6
|
const MAX_LIMIT = 1000;
|
|
6
7
|
const DECISIONS = new Set(['auto', 'allowed', 'denied', 'skip-all', 'blocked']);
|
|
@@ -11,7 +12,7 @@ function toEntry(row) {
|
|
|
11
12
|
return {
|
|
12
13
|
id: row.id,
|
|
13
14
|
agentId: row.agentId,
|
|
14
|
-
deviceId: row.originDeviceId
|
|
15
|
+
deviceId: b4a.toHex(row.originDeviceId),
|
|
15
16
|
chatId: row.chatId ?? undefined,
|
|
16
17
|
runId: row.runId ?? undefined,
|
|
17
18
|
toolName: row.toolName,
|
|
@@ -23,20 +24,20 @@ function toEntry(row) {
|
|
|
23
24
|
seq: row.seq ?? 0
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
|
-
export function createToolActivityApi(
|
|
27
|
-
const query = async ({ agentId,
|
|
27
|
+
export function createToolActivityApi(pool, deviceId) {
|
|
28
|
+
const query = async ({ agentId, ...input }, mesh) => ({
|
|
28
29
|
activities: (await listToolActivity(mesh, agentId, {
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
...bounds(input),
|
|
31
|
+
limit: Math.min(input.limit || DEFAULT_LIMIT, MAX_LIMIT)
|
|
31
32
|
})).map(toEntry)
|
|
32
33
|
});
|
|
33
34
|
return {
|
|
34
|
-
listToolActivity: async (request) => query(request, await requireMesh(
|
|
35
|
-
toolActivityWatch:
|
|
35
|
+
listToolActivity: async (request) => query(request, await requireMesh(pool, request.meshId)),
|
|
36
|
+
toolActivityWatch: meshWatchable('toolActivityWatch', pool, query),
|
|
36
37
|
recordToolActivity: async (request) => {
|
|
37
38
|
if (!deviceId)
|
|
38
39
|
throw new Error('cannot record tool activity without a device id');
|
|
39
|
-
return recordToolActivity(await requireMesh(
|
|
40
|
+
return recordToolActivity(await requireMesh(pool, request.meshId), {
|
|
40
41
|
agentId: request.agentId,
|
|
41
42
|
originDeviceId: deviceId,
|
|
42
43
|
toolName: request.toolName,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
|
|
2
2
|
import { getToolConfigs } from '../core/tool-configs.ts';
|
|
3
|
-
import { type
|
|
3
|
+
import { type MeshPool } from './current-mesh.ts';
|
|
4
4
|
type ToolConfigsCapabilities = Pick<CapabilityHandlers, 'setToolConfigs' | 'deleteToolConfigs' | 'listToolConfigs' | 'toolConfigsWatch'>;
|
|
5
|
-
export declare function createToolConfigsApi(
|
|
5
|
+
export declare function createToolConfigsApi(pool: MeshPool): ToolConfigsCapabilities;
|
|
6
6
|
export { getToolConfigs };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { deleteToolConfigs, getToolConfigs, listToolConfigs, setToolConfigs } from '../core/tool-configs.js';
|
|
2
|
-
import {
|
|
3
|
-
import { watchable } from './watchable.js';
|
|
2
|
+
import { meshWatchable, requireMesh } from './current-mesh.js';
|
|
4
3
|
function isRecord(value) {
|
|
5
4
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
6
5
|
}
|
|
@@ -9,19 +8,19 @@ function ensureSettingsPayload(value) {
|
|
|
9
8
|
throw new Error('tool configs must be a plain object');
|
|
10
9
|
return value;
|
|
11
10
|
}
|
|
12
|
-
export function createToolConfigsApi(
|
|
11
|
+
export function createToolConfigsApi(pool) {
|
|
13
12
|
const query = async ({ agentId }, mesh) => ({
|
|
14
13
|
configs: await listToolConfigs(mesh, agentId)
|
|
15
14
|
});
|
|
16
15
|
return {
|
|
17
|
-
setToolConfigs: async ({ agentId, toolName, settings }) => setToolConfigs(await requireMesh(
|
|
16
|
+
setToolConfigs: async ({ agentId, toolName, settings, meshId }) => setToolConfigs(await requireMesh(pool, meshId), {
|
|
18
17
|
agentId,
|
|
19
18
|
toolName,
|
|
20
19
|
settings: ensureSettingsPayload(settings)
|
|
21
20
|
}),
|
|
22
|
-
deleteToolConfigs: async ({ agentId, toolName }) => deleteToolConfigs(await requireMesh(
|
|
23
|
-
listToolConfigs: async (request) => query(request, await requireMesh(
|
|
24
|
-
toolConfigsWatch:
|
|
21
|
+
deleteToolConfigs: async ({ agentId, toolName, meshId }) => deleteToolConfigs(await requireMesh(pool, meshId), agentId, toolName),
|
|
22
|
+
listToolConfigs: async (request) => query(request, await requireMesh(pool, request.meshId)),
|
|
23
|
+
toolConfigsWatch: meshWatchable('toolConfigsWatch', pool, query)
|
|
25
24
|
};
|
|
26
25
|
}
|
|
27
26
|
export { getToolConfigs };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const UPLOAD_NAMES_NO_MESH = "an upload must name its mesh on its first frame";
|
|
2
|
+
export type UploadFrames<Frame> = AsyncIterable<Frame> | {
|
|
3
|
+
writeStream?: unknown;
|
|
4
|
+
on: (...args: never[]) => void;
|
|
5
|
+
};
|
|
6
|
+
export declare function openUpload<Frame>(frames: UploadFrames<Frame>): Promise<{
|
|
7
|
+
first: Frame;
|
|
8
|
+
rest: AsyncIterable<Frame>;
|
|
9
|
+
} | null>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { toAsyncIterable } from '../core/async-iterable.js';
|
|
2
|
+
export const UPLOAD_NAMES_NO_MESH = 'an upload must name its mesh on its first frame';
|
|
3
|
+
export async function openUpload(frames) {
|
|
4
|
+
const iterator = toAsyncIterable(frames)[Symbol.asyncIterator]();
|
|
5
|
+
const first = await iterator.next();
|
|
6
|
+
if (first.done)
|
|
7
|
+
return null;
|
|
8
|
+
const rest = replay(first.value, iterator);
|
|
9
|
+
if ('writeStream' in frames) {
|
|
10
|
+
Object.assign(rest, { writeStream: frames.writeStream });
|
|
11
|
+
}
|
|
12
|
+
return { first: first.value, rest };
|
|
13
|
+
}
|
|
14
|
+
async function* replay(first, rest) {
|
|
15
|
+
yield first;
|
|
16
|
+
yield* { [Symbol.asyncIterator]: () => rest };
|
|
17
|
+
}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { Readable } from 'streamx';
|
|
2
2
|
import '../logger.ts';
|
|
3
|
-
export interface WatchPin {
|
|
4
|
-
stale(): boolean;
|
|
5
|
-
watch(listener: () => void): void;
|
|
6
|
-
unwatch(listener: () => void): void;
|
|
7
|
-
}
|
|
8
3
|
interface WatchableStore {
|
|
9
4
|
watch(listener: () => void): void;
|
|
10
5
|
unwatch(listener: () => void): void;
|
|
@@ -13,5 +8,5 @@ interface WatchableStore {
|
|
|
13
8
|
closing?: unknown;
|
|
14
9
|
closed?: boolean;
|
|
15
10
|
}
|
|
16
|
-
export declare function watchable<TRequest, TResult, TStore extends WatchableStore = WatchableStore>(name: string, storeOf: (request: TRequest) => TStore | null | Promise<TStore | null>, query: (request: TRequest, store: TStore) => Promise<TResult>,
|
|
11
|
+
export declare function watchable<TRequest, TResult, TStore extends WatchableStore = WatchableStore>(name: string, storeOf: (request: TRequest) => TStore | null | Promise<TStore | null>, query: (request: TRequest, store: TStore) => Promise<TResult>, changes?: WatchableStore): (request: TRequest) => Readable & AsyncIterable<TResult>;
|
|
17
12
|
export {};
|
|
@@ -24,9 +24,8 @@ function snapshotEquals(a, b) {
|
|
|
24
24
|
function isRecord(value) {
|
|
25
25
|
return typeof value === 'object' && value !== null;
|
|
26
26
|
}
|
|
27
|
-
export function watchable(name, storeOf, query,
|
|
27
|
+
export function watchable(name, storeOf, query, changes) {
|
|
28
28
|
return (request) => {
|
|
29
|
-
const pin = pinOf?.(request) ?? null;
|
|
30
29
|
const resolved = storeOf(request);
|
|
31
30
|
const pending = resolved instanceof Promise ? resolved.catch(noop) : null;
|
|
32
31
|
let store = resolved instanceof Promise ? null : resolved;
|
|
@@ -57,22 +56,14 @@ export function watchable(name, storeOf, query, pinOf) {
|
|
|
57
56
|
wake?.resolve();
|
|
58
57
|
wake = null;
|
|
59
58
|
};
|
|
60
|
-
const
|
|
61
|
-
if (pin?.stale())
|
|
62
|
-
onStoreClose();
|
|
63
|
-
};
|
|
64
|
-
const storeGone = () => store === null ||
|
|
65
|
-
ended ||
|
|
66
|
-
Boolean(store.closed) ||
|
|
67
|
-
Boolean(store.closing) ||
|
|
68
|
-
Boolean(pin?.stale());
|
|
59
|
+
const storeGone = () => store === null || ended || Boolean(store.closed) || Boolean(store.closing);
|
|
69
60
|
const stream = new Readable({
|
|
70
61
|
async open(cb) {
|
|
71
62
|
if (pending)
|
|
72
63
|
store = (await pending) ?? null;
|
|
73
64
|
store?.watch(onChange);
|
|
65
|
+
changes?.watch(onChange);
|
|
74
66
|
store?.once?.('close', onStoreClose);
|
|
75
|
-
pin?.watch(onPinMove);
|
|
76
67
|
cb(null);
|
|
77
68
|
},
|
|
78
69
|
async read(cb) {
|
|
@@ -121,8 +112,8 @@ export function watchable(name, storeOf, query, pinOf) {
|
|
|
121
112
|
destroy(cb) {
|
|
122
113
|
reportChurn(true);
|
|
123
114
|
store?.unwatch(onChange);
|
|
115
|
+
changes?.unwatch(onChange);
|
|
124
116
|
store?.off?.('close', onStoreClose);
|
|
125
|
-
pin?.unwatch(onPinMove);
|
|
126
117
|
cb(null);
|
|
127
118
|
}
|
|
128
119
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AbortSignal } from 'bare-abort-controller';
|
|
2
2
|
import type { AssistantChunk } from '../../spec/hyperschema/types.d.ts';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ScopedCapabilities } from '../mesh-scoped-engine.ts';
|
|
4
4
|
import type { ChatMessage } from './message.ts';
|
|
5
5
|
export declare const TERMINAL_STATES: Set<string>;
|
|
6
6
|
export declare const HISTORY_TYPES: AssistantChunk['type'][];
|
|
@@ -9,13 +9,13 @@ export interface StaleToolRuns {
|
|
|
9
9
|
runIds: Set<string>;
|
|
10
10
|
questionChunkIds: Set<string>;
|
|
11
11
|
}
|
|
12
|
-
export declare function listHistoryChunks(engine: Pick<
|
|
12
|
+
export declare function listHistoryChunks(engine: Pick<ScopedCapabilities, 'listChunks'>, chatId: string): Promise<AssistantChunk[]>;
|
|
13
13
|
export declare function latestAttemptStarts(chunks: ReadonlyArray<AssistantChunk>): Map<string, number>;
|
|
14
14
|
export declare function beforeLatestAttempt(chunk: AssistantChunk, starts: Map<string, number>): boolean;
|
|
15
15
|
export interface CompactOptions {
|
|
16
16
|
readonly signal?: AbortSignal;
|
|
17
17
|
readonly onFold?: () => Promise<void> | void;
|
|
18
|
-
readonly meshId
|
|
18
|
+
readonly meshId: string;
|
|
19
19
|
}
|
|
20
20
|
export type CompactionTrigger = 'before-run' | 'overflow';
|
|
21
21
|
export interface CompactResult {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Client } from './client.js';
|
|
2
2
|
import { duplexPair } from '@qvac/harness/transport';
|
|
3
|
+
import b4a from 'b4a';
|
|
3
4
|
export class AssistantClient extends Client {
|
|
4
5
|
_inline;
|
|
5
6
|
constructor({ sidecar: spawnSidecar = true, storagePath, device, meshSeed, meshKey, bootstrapNodes, entry, ...engineOptions }) {
|
|
@@ -11,8 +12,8 @@ export class AssistantClient extends Client {
|
|
|
11
12
|
device?.name ?? '',
|
|
12
13
|
device?.capabilityProfile ?? '',
|
|
13
14
|
device?.recommendedModelName ?? '',
|
|
14
|
-
meshSeed
|
|
15
|
-
meshKey
|
|
15
|
+
meshSeed ? b4a.toHex(meshSeed) : '',
|
|
16
|
+
meshKey ? b4a.toHex(meshKey) : '',
|
|
16
17
|
(bootstrapNodes ?? []).map((node) => `${node.host}:${node.port}`).join(',')
|
|
17
18
|
];
|
|
18
19
|
const transport = spawnSidecar
|
|
@@ -77,7 +77,7 @@ export function assistantTree(opts) {
|
|
|
77
77
|
offDeleteModel = core.registerDeleteModel(harnessDeleteModel(harness));
|
|
78
78
|
offClearKvCache = core.registerClearKvCache(harnessClearKvCache(harness));
|
|
79
79
|
offDeleteChatKvCache = core.registerDeleteChatKvCache((chatId) => assistant.deleteChatKvCache(chatId));
|
|
80
|
-
offCompactChat = core.registerCompactChat((chatId) => assistant.compactChat(chatId));
|
|
80
|
+
offCompactChat = core.registerCompactChat((chatId, meshId) => assistant.compactChat(chatId, { meshId }));
|
|
81
81
|
offModelCatalogWatch = core.registerModelCatalogWatch(() => assistant.modelCatalogWatch());
|
|
82
82
|
offCustomModels = startCustomModelPusher(harness, core.local, logger);
|
|
83
83
|
offLoanableHarness = core.registerLoanableHarness((stream) => serveHarness(stream, harness));
|
|
@@ -2,7 +2,7 @@ import type { ModelCategory } from '@qvac/harness';
|
|
|
2
2
|
import type { Duplex } from 'streamx';
|
|
3
3
|
import ReadyResource from 'ready-resource';
|
|
4
4
|
import type { AssistantKvCacheDeletionResponse, AssistantModelCatalogRevision } from '../spec/hyperschema/types.d.ts';
|
|
5
|
-
import type { Capabilities } from './api/index.ts';
|
|
5
|
+
import type { Capabilities, SkillOptions } from './api/index.ts';
|
|
6
6
|
import type { DriveHost } from './core/fs-drives.ts';
|
|
7
7
|
import { type DiagnosticsSlice } from './diagnostics.ts';
|
|
8
8
|
import { type InferenceCallEntry } from './inference-calls.ts';
|
|
@@ -57,6 +57,7 @@ export declare class QvacAssistant extends ReadyResource {
|
|
|
57
57
|
private _readinessDirty;
|
|
58
58
|
private _reconciling;
|
|
59
59
|
private readonly _onlineBoot;
|
|
60
|
+
private readonly _accountSeen;
|
|
60
61
|
private _capability;
|
|
61
62
|
private _downloads;
|
|
62
63
|
private _state;
|
|
@@ -64,13 +65,12 @@ export declare class QvacAssistant extends ReadyResource {
|
|
|
64
65
|
private _harnessDeath;
|
|
65
66
|
private _refreshingDiagnostics;
|
|
66
67
|
private _meshList;
|
|
68
|
+
private _accountFrames;
|
|
69
|
+
private _accountMeshId;
|
|
67
70
|
private _advertisedOn;
|
|
68
|
-
private _chatList;
|
|
69
|
-
private _agentList;
|
|
70
|
-
private readonly _chatListWatch;
|
|
71
|
-
private readonly _agentWatch;
|
|
72
71
|
private readonly _meshListWatch;
|
|
73
|
-
private readonly
|
|
72
|
+
private readonly _accountWatch;
|
|
73
|
+
private readonly _meshConsumers;
|
|
74
74
|
private readonly _runs;
|
|
75
75
|
private readonly _seen;
|
|
76
76
|
private readonly _inferenceCalls;
|
|
@@ -119,15 +119,14 @@ export declare class QvacAssistant extends ReadyResource {
|
|
|
119
119
|
deleteModel(name: string): Promise<DeleteModelSummary>;
|
|
120
120
|
modelCatalogWatch(): AsyncIterable<AssistantModelCatalogRevision>;
|
|
121
121
|
retryModelDownload(name: string): Promise<void>;
|
|
122
|
-
skills(agentId?: string | null, modelName?: string | null, options?: {
|
|
123
|
-
readonly refresh?: boolean;
|
|
122
|
+
skills(agentId?: string | null, modelName?: string | null, options?: SkillOptions & {
|
|
124
123
|
readonly skipCredentialProbe?: boolean;
|
|
125
124
|
}): Promise<ReadonlyArray<Skill>>;
|
|
126
125
|
private _recordSkillReadiness;
|
|
127
126
|
tools(): Promise<ReadonlyArray<ToolCatalogEntry>>;
|
|
128
127
|
private _supervisedWatch;
|
|
129
|
-
private
|
|
130
|
-
private
|
|
128
|
+
private _reclaimDeletedChats;
|
|
129
|
+
private _reclaimRekeyedAgents;
|
|
131
130
|
private _reclaimAgentChatCaches;
|
|
132
131
|
private _reconcileCompaction;
|
|
133
132
|
private _senderNames;
|
|
@@ -135,9 +134,12 @@ export declare class QvacAssistant extends ReadyResource {
|
|
|
135
134
|
deleteChatKvCache(chatId: string): Promise<AssistantKvCacheDeletionResponse>;
|
|
136
135
|
private _deleteChatKvCache;
|
|
137
136
|
private _watchMeshList;
|
|
138
|
-
private
|
|
139
|
-
private
|
|
140
|
-
private
|
|
137
|
+
private _watchAccount;
|
|
138
|
+
private _syncMeshConsumers;
|
|
139
|
+
private _followAccount;
|
|
140
|
+
private _meshConsumer;
|
|
141
|
+
private _streamWatch;
|
|
142
|
+
private _dispatchRunRequests;
|
|
141
143
|
private _stopMeshIntake;
|
|
142
144
|
private _pruneSeen;
|
|
143
145
|
private _lenderFor;
|
|
@@ -161,7 +163,7 @@ export declare class QvacAssistant extends ReadyResource {
|
|
|
161
163
|
private _compactIfNearFull;
|
|
162
164
|
private _runCompaction;
|
|
163
165
|
private _lastRunMetrics;
|
|
164
|
-
compactChat(chatId: string, options
|
|
166
|
+
compactChat(chatId: string, options: CompactOptions): Promise<CompactResult>;
|
|
165
167
|
private _summarize;
|
|
166
168
|
private _autoTitle;
|
|
167
169
|
private _generateChatTitle;
|