@qvac/core 0.3.5 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +177 -9
- 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 +10 -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/oauth/browser-connect.d.ts +0 -14
- package/dist-lib/lib/oauth/browser-connect.js +1 -26
- package/dist-lib/lib/oauth/token-exchange.d.ts +1 -2
- package/dist-lib/lib/oauth/token-exchange.js +1 -4
- 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/field-order.js +1 -4
- 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 +15 -9
- 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
- package/tui/lib/projection-env.mjs +0 -24
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { appendChunk, listAttachmentsByKind, listChunks, listRunRequests, resolveApproval, updateChunk } from '../core/chunk.js';
|
|
1
|
+
import { appendChunk, listAttachmentsByKind, listChunks, listRunRequests, recordLinks, resolveApproval, updateChunk } from '../core/chunk.js';
|
|
2
2
|
import { meshWatchable, requireMesh } from './current-mesh.js';
|
|
3
|
-
|
|
3
|
+
import { bounds } from './range.js';
|
|
4
|
+
export function createChunksApi(pool, deviceId) {
|
|
4
5
|
return {
|
|
5
|
-
appendChunk: async ({ meshId, ...input }) => appendChunk(await requireMesh(
|
|
6
|
-
updateChunk: async ({ meshId,
|
|
7
|
-
await updateChunk(await requireMesh(
|
|
6
|
+
appendChunk: async ({ meshId, ...input }) => appendChunk(await requireMesh(pool, meshId), input),
|
|
7
|
+
updateChunk: async ({ meshId, chunkId, runStatus }) => {
|
|
8
|
+
await updateChunk(await requireMesh(pool, meshId), { id: chunkId, runStatus });
|
|
8
9
|
return { ok: true };
|
|
9
10
|
},
|
|
10
11
|
resolveApproval: async (input) => {
|
|
11
|
-
await resolveApproval(await requireMesh(
|
|
12
|
-
id: input.
|
|
12
|
+
await resolveApproval(await requireMesh(pool, input.meshId), {
|
|
13
|
+
id: input.chunkId,
|
|
13
14
|
approved: input.approved === true,
|
|
14
15
|
scope: input.scope ?? undefined,
|
|
15
16
|
expiresAt: input.expiresAt || undefined,
|
|
@@ -17,35 +18,25 @@ export function createChunksApi(current, deviceId) {
|
|
|
17
18
|
});
|
|
18
19
|
return { ok: true };
|
|
19
20
|
},
|
|
20
|
-
listChunks: async ({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
chunks: await
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
reverse: reverse === true,
|
|
36
|
-
limit: limit || undefined
|
|
37
|
-
})
|
|
38
|
-
}),
|
|
39
|
-
chunksWatch: meshWatchable('chunksWatch', current, async ({ chatId, type, types, fromSeq, reverse, limit }, mesh) => ({
|
|
40
|
-
chunks: await listChunks(mesh, {
|
|
41
|
-
chatId,
|
|
42
|
-
type: type ?? undefined,
|
|
43
|
-
types: types ?? undefined,
|
|
44
|
-
fromSeq: fromSeq || undefined,
|
|
45
|
-
reverse: reverse === true,
|
|
46
|
-
limit: limit || undefined
|
|
47
|
-
})
|
|
21
|
+
listChunks: async ({ meshId, ...input }) => {
|
|
22
|
+
const mesh = await requireMesh(pool, meshId);
|
|
23
|
+
return { chunks: await recordLinks(mesh, await listChunks(mesh, chunkSelection(input))) };
|
|
24
|
+
},
|
|
25
|
+
listAttachmentsByKind: async ({ meshId, ...input }) => {
|
|
26
|
+
const mesh = await requireMesh(pool, meshId);
|
|
27
|
+
const chunks = await listAttachmentsByKind(mesh, {
|
|
28
|
+
...bounds(input),
|
|
29
|
+
kind: input.kind,
|
|
30
|
+
origin: input.origin ?? undefined
|
|
31
|
+
});
|
|
32
|
+
return { chunks: await recordLinks(mesh, chunks) };
|
|
33
|
+
},
|
|
34
|
+
chunksWatch: meshWatchable('chunksWatch', pool, async ({ meshId, ...input }, mesh) => ({
|
|
35
|
+
chunks: await recordLinks(mesh, await listChunks(mesh, chunkSelection(input)))
|
|
48
36
|
})),
|
|
49
|
-
runRequestsWatch: meshWatchable('runRequestsWatch',
|
|
37
|
+
runRequestsWatch: meshWatchable('runRequestsWatch', pool, async (_request, mesh) => ({ chunks: await listRunRequests(mesh, deviceId) }))
|
|
50
38
|
};
|
|
51
39
|
}
|
|
40
|
+
function chunkSelection({ chatId, type, types, ...rest }) {
|
|
41
|
+
return { ...bounds(rest), chatId, type: type ?? undefined, types: types ?? undefined };
|
|
42
|
+
}
|
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
import type { Mesh } from '../core/mesh.ts';
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export interface MeshSelection {
|
|
8
|
-
key(): string | null;
|
|
2
|
+
export type MeshPool = (meshId: string) => Mesh | null | Promise<Mesh | null>;
|
|
3
|
+
export declare const NO_SUCH_MESH = "no such mesh";
|
|
4
|
+
export declare function requireMesh(pool: MeshPool, meshId: string): Promise<Mesh>;
|
|
5
|
+
export declare function isMissingMesh(err: unknown): boolean;
|
|
6
|
+
export declare function meshWatchable<TRequest extends MeshScoped, TResult>(name: string, pool: MeshPool, query: (request: TRequest, mesh: Mesh) => Promise<TResult>, changes?: {
|
|
9
7
|
watch(listener: () => void): void;
|
|
10
8
|
unwatch(listener: () => void): void;
|
|
11
|
-
}
|
|
12
|
-
export declare const NO_ACTIVE_MESH = "no active mesh";
|
|
13
|
-
export declare const NO_SUCH_MESH = "no such mesh";
|
|
14
|
-
export declare function requireMesh(current: CurrentMesh, meshId?: string | null): Promise<Mesh>;
|
|
15
|
-
export declare function isMeshTransition(err: unknown): boolean;
|
|
16
|
-
export declare function meshWatchable<TRequest extends MeshScoped | undefined, TResult>(name: string, current: CurrentMesh, query: (request: TRequest, mesh: Mesh) => Promise<TResult>): (request: TRequest) => import("streamx").Readable<import("streamx").ReadableEvents> & AsyncIterable<TResult>;
|
|
17
|
-
export declare function selectionPin(current: CurrentMesh, meshId?: string | null): WatchPin | null;
|
|
9
|
+
}): (request: TRequest) => import("streamx").Readable<import("streamx").ReadableEvents> & AsyncIterable<TResult>;
|
|
18
10
|
interface MeshScoped {
|
|
19
|
-
readonly meshId
|
|
11
|
+
readonly meshId: string;
|
|
20
12
|
}
|
|
21
13
|
export {};
|
|
@@ -1,31 +1,16 @@
|
|
|
1
1
|
import { watchable } from './watchable.js';
|
|
2
|
-
export const NO_ACTIVE_MESH = 'no active mesh';
|
|
3
2
|
export const NO_SUCH_MESH = 'no such mesh';
|
|
4
|
-
export async function requireMesh(
|
|
5
|
-
const mesh = await
|
|
3
|
+
export async function requireMesh(pool, meshId) {
|
|
4
|
+
const mesh = await pool(meshId);
|
|
6
5
|
if (!mesh)
|
|
7
|
-
throw new Error(
|
|
6
|
+
throw new Error(`${NO_SUCH_MESH}: ${meshId}`);
|
|
8
7
|
if (!mesh.opened)
|
|
9
8
|
await mesh.ready();
|
|
10
9
|
return mesh;
|
|
11
10
|
}
|
|
12
|
-
export function
|
|
13
|
-
return err instanceof Error && err.message
|
|
11
|
+
export function isMissingMesh(err) {
|
|
12
|
+
return err instanceof Error && err.message.startsWith(`${NO_SUCH_MESH}: `);
|
|
14
13
|
}
|
|
15
|
-
export function meshWatchable(name,
|
|
16
|
-
return watchable(name, (request) => requireMesh(
|
|
17
|
-
}
|
|
18
|
-
export function selectionPin(current, meshId) {
|
|
19
|
-
const selection = current.selection;
|
|
20
|
-
if (meshId || !selection)
|
|
21
|
-
return null;
|
|
22
|
-
const opened = selection.key();
|
|
23
|
-
return {
|
|
24
|
-
stale: () => {
|
|
25
|
-
const now = selection.key();
|
|
26
|
-
return now !== null && now !== opened;
|
|
27
|
-
},
|
|
28
|
-
watch: (listener) => selection.watch(listener),
|
|
29
|
-
unwatch: (listener) => selection.unwatch(listener)
|
|
30
|
-
};
|
|
14
|
+
export function meshWatchable(name, pool, query, changes) {
|
|
15
|
+
return watchable(name, (request) => requireMesh(pool, request.meshId), query, changes);
|
|
31
16
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { AssistantCapabilityProfile } from '../../spec/hyperschema/types.d.ts';
|
|
2
|
-
import {
|
|
2
|
+
import type { Mesh } from '../core/mesh.ts';
|
|
3
|
+
import { type MeshPool } from './current-mesh.ts';
|
|
3
4
|
import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
|
|
4
|
-
export declare function createDevicesApi(
|
|
5
|
+
export declare function createDevicesApi(pool: MeshPool, deviceId: Buffer, removeWriter: (writerKey: Buffer, deviceId: Buffer, mesh: Mesh) => Promise<void>, renameLocal: (name: string) => Promise<void>, saveProfileLocal: (capabilityProfile: AssistantCapabilityProfile, recommendedModelName: string, platform?: string) => Promise<void>, readLocalProfile: () => {
|
|
5
6
|
capabilityProfile: AssistantCapabilityProfile;
|
|
6
7
|
recommendedModelName: string;
|
|
7
8
|
platform?: string;
|
|
8
|
-
} | null, computeLender?: (() => Promise<Buffer | null>) | null): Pick<CapabilityHandlers, 'listDevices' | 'devicesWatch' | 'deviceInfo' | 'saveDeviceCapabilities' | 'saveDeviceProfile' | 'removeDevice' | 'renameDevice'>;
|
|
9
|
+
} | null, computeLender?: (() => Promise<Buffer | null>) | null): Pick<CapabilityHandlers, 'listDevices' | 'getDevice' | 'devicesWatch' | 'deviceInfo' | 'saveDeviceCapabilities' | 'saveDeviceProfile' | 'removeDevice' | 'renameDevice'>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { MAX_DEVICE_NAME_CHARS, deviceNameWithinBounds } from '../../schema/qvac.js';
|
|
2
2
|
import { saveDeviceCapabilities } from '../core/devices.js';
|
|
3
3
|
import { meshWatchable, requireMesh } from './current-mesh.js';
|
|
4
|
+
import b4a from 'b4a';
|
|
4
5
|
const DEVICES = '@qvac/devices';
|
|
5
6
|
function toEngineDevice(device, overrides = {}) {
|
|
6
7
|
return {
|
|
@@ -24,13 +25,13 @@ function toEngineDevice(device, overrides = {}) {
|
|
|
24
25
|
...overrides
|
|
25
26
|
};
|
|
26
27
|
}
|
|
27
|
-
export function createDevicesApi(
|
|
28
|
+
export function createDevicesApi(pool, deviceId, removeWriter, renameLocal, saveProfileLocal, readLocalProfile, computeLender = null) {
|
|
28
29
|
const mustGetDevice = async (mesh, id) => {
|
|
29
30
|
const snap = mesh.view.snapshot();
|
|
30
31
|
try {
|
|
31
32
|
const device = await snap.get(DEVICES, { id });
|
|
32
33
|
if (!device)
|
|
33
|
-
throw new Error(`device not found: ${
|
|
34
|
+
throw new Error(`device not found: ${b4a.toHex(id)}`);
|
|
34
35
|
return device;
|
|
35
36
|
}
|
|
36
37
|
finally {
|
|
@@ -48,15 +49,16 @@ export function createDevicesApi(current, deviceId, removeWriter, renameLocal, s
|
|
|
48
49
|
}
|
|
49
50
|
};
|
|
50
51
|
return {
|
|
51
|
-
listDevices: async (request) => list(await requireMesh(
|
|
52
|
-
|
|
52
|
+
listDevices: async (request) => list(await requireMesh(pool, request.meshId)),
|
|
53
|
+
getDevice: async ({ deviceId: id, meshId }) => toEngineDevice(await mustGetDevice(await requireMesh(pool, meshId), id)),
|
|
54
|
+
devicesWatch: meshWatchable('devicesWatch', pool, (_request, mesh) => list(mesh)),
|
|
53
55
|
deviceInfo: async () => {
|
|
54
56
|
logger.info(['api', 'devices'], 'deviceInfo handler reached');
|
|
55
57
|
const computeLenderId = (await computeLender?.()) ?? undefined;
|
|
56
58
|
return { id: deviceId, supportsKvCacheDeletion: true, computeLenderId };
|
|
57
59
|
},
|
|
58
60
|
saveDeviceCapabilities: async (input) => {
|
|
59
|
-
await saveDeviceCapabilities(await requireMesh(
|
|
61
|
+
await saveDeviceCapabilities(await requireMesh(pool, input.meshId), {
|
|
60
62
|
deviceId,
|
|
61
63
|
installedToolNames: input.installedToolNames ?? [],
|
|
62
64
|
installedSkillNames: input.installedSkillNames ?? [],
|
|
@@ -67,29 +69,27 @@ export function createDevicesApi(current, deviceId, removeWriter, renameLocal, s
|
|
|
67
69
|
});
|
|
68
70
|
return { ok: true };
|
|
69
71
|
},
|
|
70
|
-
removeDevice: async ({
|
|
71
|
-
if (
|
|
72
|
+
removeDevice: async ({ deviceId: target, meshId }) => {
|
|
73
|
+
if (target.equals(deviceId))
|
|
72
74
|
throw new Error('cannot remove own device, use leaveMesh');
|
|
73
|
-
const
|
|
75
|
+
const mesh = await requireMesh(pool, meshId);
|
|
76
|
+
const device = await mustGetDevice(mesh, target);
|
|
74
77
|
if (device.revoked)
|
|
75
78
|
return { ok: true };
|
|
76
79
|
if (!device.writerKey)
|
|
77
80
|
throw new Error('device has no writer key, cannot remove');
|
|
78
|
-
await removeWriter(device.writerKey,
|
|
81
|
+
await removeWriter(device.writerKey, target, mesh);
|
|
79
82
|
return { ok: true };
|
|
80
83
|
},
|
|
81
|
-
renameDevice: async ({
|
|
82
|
-
|
|
83
|
-
throw new Error('can only rename this device, a device owns its row');
|
|
84
|
-
}
|
|
85
|
-
const trimmed = name.trim();
|
|
84
|
+
renameDevice: async ({ meshId, config }) => {
|
|
85
|
+
const trimmed = config.name.trim();
|
|
86
86
|
if (!trimmed)
|
|
87
87
|
throw new Error('device name must not be empty');
|
|
88
88
|
if (!deviceNameWithinBounds(trimmed)) {
|
|
89
89
|
throw new Error(`device name must be at most ${MAX_DEVICE_NAME_CHARS} characters`);
|
|
90
90
|
}
|
|
91
|
-
const mesh = await requireMesh(
|
|
92
|
-
const device = await mustGetDevice(mesh,
|
|
91
|
+
const mesh = await requireMesh(pool, meshId);
|
|
92
|
+
const device = await mustGetDevice(mesh, deviceId);
|
|
93
93
|
await renameLocal(trimmed);
|
|
94
94
|
try {
|
|
95
95
|
await mesh.dispatch('update-device', { device: { ...device, name: trimmed } });
|
|
@@ -100,8 +100,8 @@ export function createDevicesApi(current, deviceId, removeWriter, renameLocal, s
|
|
|
100
100
|
}
|
|
101
101
|
return toEngineDevice(device, { name: trimmed });
|
|
102
102
|
},
|
|
103
|
-
saveDeviceProfile: async ({ capabilityProfile, recommendedModelName, platform }) => {
|
|
104
|
-
const mesh = await requireMesh(
|
|
103
|
+
saveDeviceProfile: async ({ capabilityProfile, recommendedModelName, platform, meshId }) => {
|
|
104
|
+
const mesh = await requireMesh(pool, meshId);
|
|
105
105
|
const prior = readLocalProfile();
|
|
106
106
|
await saveProfileLocal(capabilityProfile, recommendedModelName, platform ?? undefined);
|
|
107
107
|
try {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type MeshPool } from './current-mesh.ts';
|
|
2
2
|
import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
|
|
3
|
-
export declare function createExecutionApi(
|
|
3
|
+
export declare function createExecutionApi(pool: MeshPool, deviceId: Buffer): Pick<CapabilityHandlers, 'sendMessage' | 'runAgent' | 'stopRun'>;
|
|
@@ -3,9 +3,9 @@ import { randomId } from '../core/id.js';
|
|
|
3
3
|
import { parentRequestId, sendMessage } from '../core/send.js';
|
|
4
4
|
import { requireMesh } from './current-mesh.js';
|
|
5
5
|
const TERMINAL_STATES = new Set(['completed', 'failed', 'canceled']);
|
|
6
|
-
export function createExecutionApi(
|
|
6
|
+
export function createExecutionApi(pool, deviceId) {
|
|
7
7
|
return {
|
|
8
|
-
sendMessage: async (input) => sendMessage(await requireMesh(
|
|
8
|
+
sendMessage: async (input) => sendMessage(await requireMesh(pool, input.meshId), {
|
|
9
9
|
text: input.text,
|
|
10
10
|
chatId: input.chatId ?? undefined,
|
|
11
11
|
agentId: input.agentId ?? undefined,
|
|
@@ -13,8 +13,8 @@ export function createExecutionApi(current, deviceId) {
|
|
|
13
13
|
parentRunId: input.parentRunId ?? undefined,
|
|
14
14
|
originDeviceId: deviceId
|
|
15
15
|
}),
|
|
16
|
-
runAgent: async ({ chatId, agentId, parentRunId }) => {
|
|
17
|
-
const mesh = await requireMesh(
|
|
16
|
+
runAgent: async ({ chatId, agentId, parentRunId, meshId }) => {
|
|
17
|
+
const mesh = await requireMesh(pool, meshId);
|
|
18
18
|
const parentId = parentRunId ? await parentRequestId(mesh, chatId, parentRunId) : undefined;
|
|
19
19
|
await appendChunk(mesh, {
|
|
20
20
|
chatId,
|
|
@@ -26,8 +26,8 @@ export function createExecutionApi(current, deviceId) {
|
|
|
26
26
|
});
|
|
27
27
|
return { ok: true };
|
|
28
28
|
},
|
|
29
|
-
stopRun: async ({ chatId, runId }) => {
|
|
30
|
-
const mesh = await requireMesh(
|
|
29
|
+
stopRun: async ({ chatId, runId, meshId }) => {
|
|
30
|
+
const mesh = await requireMesh(pool, meshId);
|
|
31
31
|
const statuses = await listChunks(mesh, { chatId, type: 'run-status' });
|
|
32
32
|
const settled = statuses.some((c) => c.runId === runId && TERMINAL_STATES.has(c.runStatus?.state ?? ''));
|
|
33
33
|
if (settled)
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
|
|
2
|
-
import { type
|
|
3
|
-
export declare function createFilesApi(
|
|
2
|
+
import { type MeshPool } from './current-mesh.ts';
|
|
3
|
+
export declare function createFilesApi(pool: MeshPool): Pick<CapabilityHandlers, 'fileRead' | 'filePreview' | 'fileRetry'>;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { AbortController } from 'bare-abort-controller';
|
|
2
2
|
import { Readable } from 'streamx';
|
|
3
3
|
import { requireMesh } from './current-mesh.js';
|
|
4
|
-
export function createFilesApi(
|
|
4
|
+
export function createFilesApi(pool) {
|
|
5
5
|
return {
|
|
6
6
|
async filePreview(request) {
|
|
7
|
-
return (await requireMesh(
|
|
7
|
+
return (await requireMesh(pool, request.meshId)).files.preview(request);
|
|
8
8
|
},
|
|
9
9
|
async fileRetry(request) {
|
|
10
|
-
await (await requireMesh(
|
|
10
|
+
await (await requireMesh(pool, request.meshId)).files.retry(request);
|
|
11
11
|
return { ok: true };
|
|
12
12
|
},
|
|
13
13
|
fileRead(request) {
|
|
14
14
|
const abort = new AbortController();
|
|
15
15
|
async function* read() {
|
|
16
|
-
const mesh = await requireMesh(
|
|
16
|
+
const mesh = await requireMesh(pool, request.meshId);
|
|
17
17
|
const close = () => stream.destroy();
|
|
18
18
|
mesh.files.once('close', close);
|
|
19
19
|
try {
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
|
|
2
2
|
import type { AssistantCapabilityProfile, AssistantClearModelDownloadRequest, AssistantDeleteModelRequest, AssistantDeleteModelResponse, AssistantCompactChatResponse, AssistantKvCacheDeletionResponse, AssistantListModelsRequest, AssistantModelCatalogRevision, AssistantCopySkillResponse, AssistantDeleteSkillResponse, AssistantManagedSkillsResponse, AssistantModelInfoList, AssistantOkResponse, AssistantPushSkillSecretRequest, AssistantSkillCatalogResponse, AssistantSkillFileResponse, AssistantSpeakRequest, AssistantSpeakResponse, AssistantToolCatalogResponse, AssistantTranscribeRequest, AssistantTranscribeResponse } from '../../spec/hyperschema/types.d.ts';
|
|
3
3
|
import type { openLocalStore } from '../core/local/index.ts';
|
|
4
|
-
import type {
|
|
4
|
+
import type { Mesh } from '../core/mesh.ts';
|
|
5
|
+
import type { MeshPool } from './current-mesh.ts';
|
|
5
6
|
import { type DiagnosticsSource } from './diagnostics.ts';
|
|
6
7
|
import { type InferenceCallReader } from './inference-calls.ts';
|
|
7
8
|
import { type LogSource } from './logs.ts';
|
|
8
9
|
import { type MeshStatusSource } from './mesh.ts';
|
|
9
10
|
import { type NetworkSource } from './network.ts';
|
|
10
|
-
import { type NotificationLifetime } from './notifications.ts';
|
|
11
11
|
import type { IndexingEmbedder, VectorIndex } from '../core/files/index.ts';
|
|
12
12
|
interface ApiDeps {
|
|
13
13
|
state?: Awaited<ReturnType<typeof openLocalStore>> | null;
|
|
14
|
-
|
|
15
|
-
mesh?: CurrentMesh | null;
|
|
14
|
+
mesh?: MeshPool | null;
|
|
16
15
|
meshStatus?: MeshStatusSource | null;
|
|
17
16
|
network?: NetworkSource | null;
|
|
18
17
|
diagnostics?: DiagnosticsSource | null;
|
|
@@ -27,14 +26,14 @@ interface ApiDeps {
|
|
|
27
26
|
deleteModel?: ((options: AssistantDeleteModelRequest) => Promise<AssistantDeleteModelResponse>) | null;
|
|
28
27
|
clearKvCache?: (() => Promise<AssistantKvCacheDeletionResponse>) | null;
|
|
29
28
|
deleteChatKvCache?: ((chatId: string) => Promise<AssistantKvCacheDeletionResponse>) | null;
|
|
30
|
-
compactChat?: ((chatId: string) => Promise<AssistantCompactChatResponse>) | null;
|
|
29
|
+
compactChat?: ((chatId: string, meshId: string) => Promise<AssistantCompactChatResponse>) | null;
|
|
31
30
|
modelCatalogWatch?: (() => AsyncIterable<AssistantModelCatalogRevision>) | null;
|
|
32
31
|
retryModelDownload?: ((request: AssistantClearModelDownloadRequest) => Promise<void>) | null;
|
|
33
32
|
transcribe?: ((request: AssistantTranscribeRequest) => Promise<AssistantTranscribeResponse>) | null;
|
|
34
33
|
speak?: ((request: AssistantSpeakRequest) => Promise<AssistantSpeakResponse>) | null;
|
|
35
34
|
speakStream?: ((text: AsyncIterable<string>) => AsyncIterable<AssistantSpeakResponse>) | null;
|
|
36
35
|
deviceHost?: {
|
|
37
|
-
removeWriter: (writerKey: Buffer, deviceId: Buffer) => Promise<void>;
|
|
36
|
+
removeWriter: (writerKey: Buffer, deviceId: Buffer, mesh: Mesh) => Promise<void>;
|
|
38
37
|
renameLocal: (name: string) => Promise<void>;
|
|
39
38
|
saveProfileLocal: (capabilityProfile: AssistantCapabilityProfile, recommendedModelName: string, platform?: string) => Promise<void>;
|
|
40
39
|
readLocalProfile: () => {
|
|
@@ -43,14 +42,12 @@ interface ApiDeps {
|
|
|
43
42
|
platform?: string;
|
|
44
43
|
} | null;
|
|
45
44
|
} | null;
|
|
46
|
-
ragIndex?: (() => VectorIndex | null) | null;
|
|
47
|
-
ragEmbed?: (() => IndexingEmbedder | null) | null;
|
|
45
|
+
ragIndex?: ((meshId: string) => VectorIndex | null) | null;
|
|
46
|
+
ragEmbed?: ((meshId: string) => IndexingEmbedder | null) | null;
|
|
48
47
|
platform?: (() => string | null) | null;
|
|
49
48
|
computeLender?: (() => Promise<Buffer | null>) | null;
|
|
50
49
|
pushSkillSecret?: ((request: AssistantPushSkillSecretRequest) => Promise<void>) | null;
|
|
51
|
-
skills?: ((agentId?: string | null, modelName?: string | null, options?:
|
|
52
|
-
readonly refresh?: boolean;
|
|
53
|
-
}) => Promise<unknown>) | null;
|
|
50
|
+
skills?: ((agentId?: string | null, modelName?: string | null, options?: SkillOptions) => Promise<unknown>) | null;
|
|
54
51
|
skillCatalog?: ((agentId?: string | null, modelName?: string | null, options?: {
|
|
55
52
|
readonly refresh?: boolean;
|
|
56
53
|
}) => Promise<AssistantSkillCatalogResponse>) | null;
|
|
@@ -62,4 +59,8 @@ interface ApiDeps {
|
|
|
62
59
|
deleteOverlaySkill?: ((name: string, agentId?: string | null) => Promise<AssistantDeleteSkillResponse>) | null;
|
|
63
60
|
}
|
|
64
61
|
export type { Capabilities, WatchStream } from '../../spec/capabilities.d.ts';
|
|
62
|
+
export interface SkillOptions {
|
|
63
|
+
readonly refresh?: boolean;
|
|
64
|
+
readonly meshId?: string;
|
|
65
|
+
}
|
|
65
66
|
export declare function createApi(deps?: ApiDeps): Partial<CapabilityHandlers>;
|
|
@@ -15,6 +15,7 @@ import { createInferenceCallsApi } from './inference-calls.js';
|
|
|
15
15
|
import { createExecutionApi } from './execution.js';
|
|
16
16
|
import { createKnowledgeApi } from './knowledge.js';
|
|
17
17
|
import { createFilesApi } from './files.js';
|
|
18
|
+
import { createLocalFilesApi } from './local-files.js';
|
|
18
19
|
import { createLogsApi } from './logs.js';
|
|
19
20
|
import { instrument } from './instrument.js';
|
|
20
21
|
import { watchable } from './watchable.js';
|
|
@@ -33,13 +34,16 @@ export function createApi(deps = {}) {
|
|
|
33
34
|
const mesh = deps.mesh ?? null;
|
|
34
35
|
const retryModelDownload = deps.retryModelDownload;
|
|
35
36
|
const state = deps.state ?? null;
|
|
37
|
+
const members = mesh && deps.meshStatus ? createMembersApi(mesh, deps.meshStatus, state) : null;
|
|
36
38
|
return instrument({
|
|
37
39
|
...(state ? createConfigApi(state) : null),
|
|
38
40
|
...(state ? createAppConfigApi(state) : null),
|
|
39
41
|
...(state ? createModelDownloadApi(state) : null),
|
|
40
42
|
...(state ? createCustomModelApi(state) : null),
|
|
41
43
|
...(mesh ? createAgentsApi(mesh, deps.deviceId ?? null, deps.computeLender ?? null) : null),
|
|
42
|
-
...(mesh
|
|
44
|
+
...(mesh && state
|
|
45
|
+
? createChatApi(mesh, deps.deviceId ?? null, state, deps.inferenceCalls ?? null)
|
|
46
|
+
: null),
|
|
43
47
|
...(mesh ? createChatGroupsApi(mesh) : null),
|
|
44
48
|
...(mesh ? createApprovalRulesApi(mesh) : null),
|
|
45
49
|
...(mesh ? createChunksApi(mesh, deps.deviceId ?? null) : null),
|
|
@@ -49,6 +53,7 @@ export function createApi(deps = {}) {
|
|
|
49
53
|
...(mesh ? createAttachmentsApi(mesh, { deviceId: deps.deviceId }) : null),
|
|
50
54
|
...(mesh ? createKnowledgeApi(mesh, { deviceId: deps.deviceId }) : null),
|
|
51
55
|
...(mesh ? createFilesApi(mesh) : null),
|
|
56
|
+
...(state ? createLocalFilesApi(state.files) : null),
|
|
52
57
|
...(mesh
|
|
53
58
|
? createRagApi(mesh, deps.ragIndex ?? (() => null), deps.ragEmbed ?? (() => null), state
|
|
54
59
|
? async (agent) => effectiveCtxSize(agent, (await state.getAppConfigRow())?.ctxSize ?? 0, deps.platform?.() ?? null)
|
|
@@ -58,15 +63,9 @@ export function createApi(deps = {}) {
|
|
|
58
63
|
...(mesh ? createSyncApi(mesh) : null),
|
|
59
64
|
...(mesh ? createToolConfigsApi(mesh) : null),
|
|
60
65
|
...(mesh ? createToolActivityApi(mesh, deps.deviceId ?? null) : null),
|
|
61
|
-
...(mesh && state
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
lifetime: deps.notificationLifetime,
|
|
65
|
-
changes: deps.meshStatus ?? undefined
|
|
66
|
-
})
|
|
67
|
-
: null),
|
|
68
|
-
...(deps.meshStatus ? createMeshApi(deps.meshStatus) : null),
|
|
69
|
-
...(mesh ? createMembersApi(mesh, state) : null),
|
|
66
|
+
...(mesh && state ? createNotificationsApi(mesh, state, { deviceId: deps.deviceId }) : null),
|
|
67
|
+
...members,
|
|
68
|
+
...(deps.meshStatus && members ? createMeshApi(deps.meshStatus, members.updateMember) : null),
|
|
70
69
|
...(deps.network ? createNetworkApi(deps.network) : null),
|
|
71
70
|
...(deps.diagnostics ? createDiagnosticsApi(deps.diagnostics) : null),
|
|
72
71
|
...(deps.inferenceCalls ? createInferenceCallsApi(deps.inferenceCalls) : null),
|
|
@@ -88,10 +87,12 @@ export function createApi(deps = {}) {
|
|
|
88
87
|
...(deps.deleteModel ? { deleteModel: deps.deleteModel } : null),
|
|
89
88
|
...(deps.clearKvCache ? { clearKvCache: deps.clearKvCache } : null),
|
|
90
89
|
...(deps.deleteChatKvCache
|
|
91
|
-
? {
|
|
90
|
+
? {
|
|
91
|
+
deleteChatKvCache: ({ chatId }) => deps.deleteChatKvCache(chatId)
|
|
92
|
+
}
|
|
92
93
|
: null),
|
|
93
94
|
...(deps.compactChat
|
|
94
|
-
? { compactChat: ({
|
|
95
|
+
? { compactChat: ({ chatId, meshId }) => deps.compactChat(chatId, meshId) }
|
|
95
96
|
: null),
|
|
96
97
|
...(deps.modelCatalogWatch ? { modelCatalogWatch: deps.modelCatalogWatch } : null),
|
|
97
98
|
...(retryModelDownload
|
|
@@ -128,7 +129,8 @@ export function createApi(deps = {}) {
|
|
|
128
129
|
? {
|
|
129
130
|
skills: async (req) => ({
|
|
130
131
|
skills: await deps.skills?.(req?.agentId, req?.modelName, {
|
|
131
|
-
refresh: req?.refresh === true
|
|
132
|
+
refresh: req?.refresh === true,
|
|
133
|
+
meshId: req?.meshId || undefined
|
|
132
134
|
})
|
|
133
135
|
})
|
|
134
136
|
}
|
|
@@ -12,7 +12,7 @@ export interface InferenceCallAnswer {
|
|
|
12
12
|
truncated: boolean;
|
|
13
13
|
}
|
|
14
14
|
export interface InferenceCallReader {
|
|
15
|
-
list(chatId: string): Promise<InferenceCallAnswer>;
|
|
15
|
+
list(meshId: string, chatId: string): Promise<InferenceCallAnswer>;
|
|
16
16
|
forget(chatId: string): Promise<void>;
|
|
17
17
|
}
|
|
18
18
|
export declare function createInferenceCallsApi(reader: InferenceCallReader): Pick<CapabilityHandlers, 'inferenceCalls'>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export function createInferenceCallsApi(reader) {
|
|
2
2
|
return {
|
|
3
|
-
inferenceCalls: async ({ chatId }) => {
|
|
4
|
-
const answer = await reader.list(chatId);
|
|
3
|
+
inferenceCalls: async ({ chatId, meshId }) => {
|
|
4
|
+
const answer = await reader.list(meshId, chatId);
|
|
5
5
|
return {
|
|
6
6
|
calls: answer.calls.map((entry) => ({
|
|
7
7
|
runId: entry.runId,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
|
|
2
|
-
import { type
|
|
2
|
+
import { type MeshPool } from './current-mesh.ts';
|
|
3
3
|
export { MAX_KNOWLEDGE_BYTES } from '../core/files/knowledge.ts';
|
|
4
|
-
export declare function createKnowledgeApi(
|
|
4
|
+
export declare function createKnowledgeApi(pool: MeshPool, options?: {
|
|
5
5
|
maxBytes?: number;
|
|
6
6
|
inactivityMs?: number;
|
|
7
7
|
deviceId?: Buffer | null;
|
|
@@ -1,30 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { meshWatchable, requireMesh } from './current-mesh.js';
|
|
2
2
|
import { watchable } from './watchable.js';
|
|
3
|
+
import { openUpload, UPLOAD_NAMES_NO_MESH } from './upload-frames.js';
|
|
3
4
|
export { MAX_KNOWLEDGE_BYTES } from '../core/files/knowledge.js';
|
|
4
|
-
export function createKnowledgeApi(
|
|
5
|
+
export function createKnowledgeApi(pool, options = {}) {
|
|
5
6
|
return {
|
|
6
7
|
async *uploadKnowledge(frames) {
|
|
7
|
-
|
|
8
|
+
const upload = await openUpload(frames);
|
|
9
|
+
if (!upload)
|
|
10
|
+
return;
|
|
11
|
+
if (!upload.first.meshId)
|
|
12
|
+
throw new Error(UPLOAD_NAMES_NO_MESH);
|
|
13
|
+
const mesh = await requireMesh(pool, upload.first.meshId);
|
|
14
|
+
yield* mesh.files.knowledge(options).uploadKnowledge(upload.rest);
|
|
8
15
|
},
|
|
9
16
|
async *downloadKnowledge(request) {
|
|
10
|
-
yield* (await requireMesh(
|
|
17
|
+
yield* (await requireMesh(pool, request.meshId)).files
|
|
18
|
+
.knowledge(options)
|
|
19
|
+
.downloadKnowledge(request);
|
|
11
20
|
},
|
|
12
21
|
async removeKnowledge(request) {
|
|
13
|
-
return (await requireMesh(
|
|
22
|
+
return (await requireMesh(pool, request.meshId)).files
|
|
23
|
+
.knowledge(options)
|
|
24
|
+
.removeKnowledge(request);
|
|
14
25
|
},
|
|
15
26
|
async listKnowledge(request) {
|
|
16
|
-
return (await requireMesh(
|
|
27
|
+
return (await requireMesh(pool, request.meshId)).files
|
|
17
28
|
.knowledge(options)
|
|
18
29
|
.listKnowledge(request);
|
|
19
30
|
},
|
|
20
31
|
async listIndexing(request) {
|
|
21
|
-
return (await requireMesh(
|
|
32
|
+
return (await requireMesh(pool, request.meshId)).files
|
|
22
33
|
.knowledge(options)
|
|
23
34
|
.listIndexing(request);
|
|
24
35
|
},
|
|
25
|
-
knowledgeWatch:
|
|
26
|
-
indexingWatch: watchable('indexingWatch', async (request) => (await requireMesh(
|
|
27
|
-
fileStatusWatch: watchable('fileStatusWatch', async (request) => (await requireMesh(
|
|
28
|
-
indexingProgressWatch: watchable('indexingProgressWatch', async (request) => (await requireMesh(
|
|
36
|
+
knowledgeWatch: meshWatchable('knowledgeWatch', pool, async (request, mesh) => mesh.files.knowledge(options).listKnowledge(request)),
|
|
37
|
+
indexingWatch: watchable('indexingWatch', async (request) => (await requireMesh(pool, request.meshId)).files, ({ chatId }, files) => files.listIndexing(chatId)),
|
|
38
|
+
fileStatusWatch: watchable('fileStatusWatch', async (request) => (await requireMesh(pool, request.meshId)).files, ({ chatId }, files) => files.status(chatId)),
|
|
39
|
+
indexingProgressWatch: watchable('indexingProgressWatch', async (request) => (await requireMesh(pool, request.meshId)).files, ({ chatId }, files) => Promise.resolve({ entries: files.progress(chatId) }))
|
|
29
40
|
};
|
|
30
41
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import b4a from 'b4a';
|
|
2
|
+
export function createLocalFilesApi(files) {
|
|
3
|
+
return {
|
|
4
|
+
listLocalFiles: async (request) => {
|
|
5
|
+
const meshKey = request?.meshId ? Buffer.from(request.meshId, 'hex') : undefined;
|
|
6
|
+
return { files: (await files.live(meshKey)).map(toEngineFile) };
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function toEngineFile(file) {
|
|
11
|
+
return {
|
|
12
|
+
meshId: b4a.toHex(file.meshKey),
|
|
13
|
+
chatId: file.chatId,
|
|
14
|
+
attachmentId: file.attachmentId,
|
|
15
|
+
blobId: file.blobId,
|
|
16
|
+
fileName: file.fileName,
|
|
17
|
+
mimeType: file.mimeType,
|
|
18
|
+
byteLength: file.byteLength,
|
|
19
|
+
own: file.own,
|
|
20
|
+
lastAccessed: file.lastAccessed,
|
|
21
|
+
cleared: file.cleared
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import type { AssistantAccount } from '../../spec/hyperschema/types.d.ts';
|
|
1
2
|
import type { openLocalStore } from '../core/local/index.ts';
|
|
2
|
-
import { type
|
|
3
|
+
import { type MeshPool } from './current-mesh.ts';
|
|
3
4
|
import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
|
|
4
5
|
type LocalStore = Awaited<ReturnType<typeof openLocalStore>>;
|
|
5
|
-
export
|
|
6
|
+
export interface OwnMember {
|
|
7
|
+
account(): Promise<AssistantAccount>;
|
|
8
|
+
}
|
|
9
|
+
export declare function createMembersApi(pool: MeshPool, self: OwnMember, state?: LocalStore | null): Pick<CapabilityHandlers, 'listMembers' | 'membersWatch' | 'updateMember' | 'removeMember'>;
|
|
6
10
|
export {};
|