@qvac/core 0.9.0 → 0.10.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/CHANGELOG.md +94 -1
- package/README.md +4 -4
- package/dist-lib/index.d.ts +0 -1
- package/dist-lib/index.js +0 -1
- package/dist-lib/lib/api/agents.d.ts +7 -1
- package/dist-lib/lib/api/agents.js +2 -2
- package/dist-lib/lib/api/app-config.d.ts +2 -1
- package/dist-lib/lib/api/app-config.js +2 -2
- package/dist-lib/lib/api/attachments.js +3 -2
- package/dist-lib/lib/api/chat-move.d.ts +2 -1
- package/dist-lib/lib/api/chat-move.js +2 -2
- package/dist-lib/lib/api/chat.d.ts +3 -1
- package/dist-lib/lib/api/chat.js +5 -5
- package/dist-lib/lib/api/chunks.d.ts +2 -1
- package/dist-lib/lib/api/chunks.js +3 -3
- package/dist-lib/lib/api/config.d.ts +2 -1
- package/dist-lib/lib/api/config.js +2 -2
- package/dist-lib/lib/api/current-mesh.d.ts +1 -3
- package/dist-lib/lib/api/current-mesh.js +4 -10
- package/dist-lib/lib/api/custom-models.d.ts +7 -1
- package/dist-lib/lib/api/custom-models.js +10 -8
- package/dist-lib/lib/api/device-routes.d.ts +0 -2
- package/dist-lib/lib/api/device-routes.js +4 -5
- package/dist-lib/lib/api/devices.d.ts +3 -1
- package/dist-lib/lib/api/devices.js +9 -8
- package/dist-lib/lib/api/diagnostics.d.ts +2 -1
- package/dist-lib/lib/api/diagnostics.js +2 -2
- package/dist-lib/lib/api/index.d.ts +2 -0
- package/dist-lib/lib/api/index.js +39 -21
- package/dist-lib/lib/api/instrument.d.ts +2 -2
- package/dist-lib/lib/api/instrument.js +10 -11
- package/dist-lib/lib/api/knowledge.d.ts +3 -1
- package/dist-lib/lib/api/knowledge.js +9 -7
- package/dist-lib/lib/api/logs.js +3 -3
- package/dist-lib/lib/api/members.d.ts +6 -1
- package/dist-lib/lib/api/members.js +11 -10
- package/dist-lib/lib/api/mesh.d.ts +2 -2
- package/dist-lib/lib/api/mesh.js +6 -6
- package/dist-lib/lib/api/model-download.d.ts +2 -1
- package/dist-lib/lib/api/model-download.js +2 -2
- package/dist-lib/lib/api/network.d.ts +3 -2
- package/dist-lib/lib/api/network.js +4 -4
- package/dist-lib/lib/api/notifications.d.ts +3 -1
- package/dist-lib/lib/api/notifications.js +5 -4
- package/dist-lib/lib/api/rag.d.ts +0 -1
- package/dist-lib/lib/api/rag.js +3 -4
- package/dist-lib/lib/api/sync.d.ts +2 -1
- package/dist-lib/lib/api/sync.js +2 -2
- package/dist-lib/lib/api/tool-activity.d.ts +2 -1
- package/dist-lib/lib/api/tool-activity.js +4 -3
- package/dist-lib/lib/api/tool-configs.d.ts +2 -1
- package/dist-lib/lib/api/tool-configs.js +4 -3
- package/dist-lib/lib/api/upload-frames.d.ts +0 -1
- package/dist-lib/lib/api/upload-frames.js +0 -1
- package/dist-lib/lib/api/watchable.d.ts +3 -2
- package/dist-lib/lib/api/watchable.js +2 -3
- package/dist-lib/lib/assistant/fake-models.d.ts +2 -4
- package/dist-lib/lib/assistant/harness.js +8 -6
- package/dist-lib/lib/assistant-client.d.ts +2 -0
- package/dist-lib/lib/assistant-client.js +4 -3
- package/dist-lib/lib/assistant-tree.d.ts +3 -3
- package/dist-lib/lib/assistant.d.ts +2 -2
- package/dist-lib/lib/assistant.js +11 -11
- package/dist-lib/lib/client.d.ts +2 -2
- package/dist-lib/lib/core/agent.js +5 -4
- package/dist-lib/lib/core/archived-mesh.d.ts +2 -3
- package/dist-lib/lib/core/archived-mesh.js +3 -3
- package/dist-lib/lib/core/chat-activity.js +5 -3
- package/dist-lib/lib/core/chat-copy.d.ts +0 -1
- package/dist-lib/lib/core/chat-copy.js +2 -2
- package/dist-lib/lib/core/chat-fork.d.ts +0 -6
- package/dist-lib/lib/core/chat-fork.js +11 -17
- package/dist-lib/lib/core/chat-group.js +8 -7
- package/dist-lib/lib/core/chat-move.d.ts +4 -6
- package/dist-lib/lib/core/chat-move.js +14 -15
- package/dist-lib/lib/core/chat-order.d.ts +2 -1
- package/dist-lib/lib/core/chat-order.js +15 -2
- package/dist-lib/lib/core/chat.js +8 -7
- package/dist-lib/lib/core/chunk.js +13 -8
- package/dist-lib/lib/core/collections.d.ts +1 -0
- package/dist-lib/lib/core/collections.js +1 -0
- package/dist-lib/lib/core/contract/compute.d.ts +0 -4
- package/dist-lib/lib/core/contract/compute.js +2 -9
- package/dist-lib/lib/core/contract/types.d.ts +2 -2
- package/dist-lib/lib/core/departures.d.ts +2 -2
- package/dist-lib/lib/core/device-control.d.ts +0 -2
- package/dist-lib/lib/core/device-control.js +5 -6
- package/dist-lib/lib/core/files/attachments.js +5 -4
- package/dist-lib/lib/core/files/index.d.ts +2 -1
- package/dist-lib/lib/core/files/index.js +20 -8
- package/dist-lib/lib/core/files/processing/claims.js +3 -3
- package/dist-lib/lib/core/files/processing/document.d.ts +2 -0
- package/dist-lib/lib/core/files/processing/document.js +3 -0
- package/dist-lib/lib/core/files/processing/index.js +4 -2
- package/dist-lib/lib/core/files/processing/source.d.ts +3 -0
- package/dist-lib/lib/core/files/processing/source.js +5 -3
- package/dist-lib/lib/core/files/processing/state.js +1 -0
- package/dist-lib/lib/core/files/rag/index.d.ts +3 -0
- package/dist-lib/lib/core/files/rag/index.js +3 -1
- package/dist-lib/lib/core/files/rag/load.js +6 -3
- package/dist-lib/lib/core/files/rag/produce.js +3 -3
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +1 -1
- package/dist-lib/lib/core/files/rag/similarity.d.ts +2 -2
- package/dist-lib/lib/core/files/rag/similarity.js +2 -3
- package/dist-lib/lib/core/files/records/chunks.js +1 -1
- package/dist-lib/lib/core/files/records/knowledge.js +2 -1
- package/dist-lib/lib/core/files/records/purge.js +9 -5
- package/dist-lib/lib/core/files/records/reclaim.js +20 -48
- package/dist-lib/lib/core/files/records/sweep.d.ts +3 -0
- package/dist-lib/lib/core/files/records/sweep.js +9 -3
- package/dist-lib/lib/core/files/store/blob.d.ts +2 -0
- package/dist-lib/lib/core/files/store/blob.js +2 -2
- package/dist-lib/lib/core/files/store/index.d.ts +1 -0
- package/dist-lib/lib/core/files/store/index.js +2 -0
- package/dist-lib/lib/core/files/store/reference.js +4 -2
- package/dist-lib/lib/core/files/upload.d.ts +1 -1
- package/dist-lib/lib/core/files/upload.js +10 -9
- package/dist-lib/lib/core/handoff-channel.d.ts +6 -4
- package/dist-lib/lib/core/handoff-channel.js +8 -9
- package/dist-lib/lib/core/harness-loan.d.ts +0 -2
- package/dist-lib/lib/core/harness-loan.js +3 -4
- package/dist-lib/lib/core/hosted-agents.d.ts +2 -2
- package/dist-lib/lib/core/inference-calls-handoff.d.ts +2 -2
- package/dist-lib/lib/core/inference-calls-handoff.js +6 -5
- package/dist-lib/lib/core/inference-calls-receiver.d.ts +0 -2
- package/dist-lib/lib/core/inference-calls-receiver.js +5 -7
- package/dist-lib/lib/core/local/index.d.ts +4 -1
- package/dist-lib/lib/core/local/index.js +23 -2
- package/dist-lib/lib/core/membership.d.ts +2 -2
- package/dist-lib/lib/core/mesh.d.ts +13 -7
- package/dist-lib/lib/core/mesh.js +55 -47
- package/dist-lib/lib/core/migrations/file-index.js +2 -4
- package/dist-lib/lib/core/next-frame.js +2 -1
- package/dist-lib/lib/core/pdf/rasterize.d.ts +2 -1
- package/dist-lib/lib/core/pdf/rasterize.js +5 -5
- package/dist-lib/lib/core/peer-duplex.d.ts +3 -3
- package/dist-lib/lib/core/peer-duplex.js +4 -4
- package/dist-lib/lib/core/secret-handoff.d.ts +2 -2
- package/dist-lib/lib/core/secret-handoff.js +7 -4
- package/dist-lib/lib/core/send.js +3 -2
- package/dist-lib/lib/core/skill-overlay-handoff.d.ts +2 -2
- package/dist-lib/lib/core/skill-overlay-handoff.js +6 -5
- package/dist-lib/lib/core/skill-overlay-receiver.js +5 -5
- package/dist-lib/lib/core/skill-secrets.d.ts +0 -5
- package/dist-lib/lib/core/skill-secrets.js +5 -9
- package/dist-lib/lib/core/sync/changed.d.ts +20 -0
- package/dist-lib/lib/core/sync/changed.js +7 -0
- package/dist-lib/lib/core/sync/devices.js +1 -1
- package/dist-lib/lib/core/sync/files.d.ts +1 -0
- package/dist-lib/lib/core/sync/files.js +50 -72
- package/dist-lib/lib/core/sync/index.d.ts +1 -2
- package/dist-lib/lib/core/sync/index.js +40 -62
- package/dist-lib/lib/core/sync/view-updates.d.ts +33 -0
- package/dist-lib/lib/core/sync/view-updates.js +133 -0
- package/dist-lib/lib/core/system-info.d.ts +2 -2
- package/dist-lib/lib/core/system-info.js +10 -11
- package/dist-lib/lib/core/tool-configs.js +6 -6
- package/dist-lib/lib/core.d.ts +1 -7
- package/dist-lib/lib/core.js +147 -131
- package/dist-lib/lib/custom-model-pusher.d.ts +2 -4
- package/dist-lib/lib/custom-model-task.d.ts +2 -1
- package/dist-lib/lib/custom-model-task.js +2 -2
- package/dist-lib/lib/downloads-allowed-pusher.d.ts +2 -4
- package/dist-lib/lib/errors.d.ts +603 -0
- package/dist-lib/lib/errors.js +552 -0
- package/dist-lib/lib/log.d.ts +7 -6
- package/dist-lib/lib/log.js +10 -6
- package/dist-lib/lib/logger-type.d.ts +2 -5
- package/dist-lib/lib/model-download-status.d.ts +2 -2
- package/dist-lib/lib/model-download.d.ts +2 -2
- package/dist-lib/lib/model-download.js +3 -2
- package/dist-lib/lib/model-idle-pusher.d.ts +2 -4
- package/dist-lib/lib/model-memory-cap.d.ts +2 -4
- package/dist-lib/lib/oauth/browser-connect.js +3 -2
- package/dist-lib/lib/oauth/flow-core.js +3 -3
- package/dist-lib/lib/oauth/loopback.js +10 -9
- package/dist-lib/lib/oauth/providers.js +4 -2
- package/dist-lib/lib/oauth/register.js +3 -2
- package/dist-lib/lib/oauth/token-exchange-core.js +5 -4
- package/dist-lib/lib/run-transcript.d.ts +2 -2
- package/dist-lib/lib/task.js +2 -1
- package/dist-lib/schema/engine.js +6 -3
- package/dist-lib/schema/field-order.js +1 -3
- package/dist-lib/schema/local.js +11 -0
- package/dist-lib/spec/hrpc/messages.js +20 -9
- package/dist-lib/spec/hyperschema/index.js +20 -9
- package/dist-lib/spec/hyperschema/schema.json +15 -0
- package/dist-lib/spec/hyperschema/types.d.ts +3 -0
- package/dist-lib/spec/local/hyperdb/db.json +16 -1
- package/dist-lib/spec/local/hyperdb/index.js +71 -2
- package/dist-lib/spec/local/hyperdb/messages.js +300 -143
- package/dist-lib/spec/local/hyperschema/index.js +82 -2
- package/dist-lib/spec/local/hyperschema/schema.json +43 -1
- package/dist-lib/spec/local/hyperschema/types.d.ts +12 -1
- package/package.json +9 -2
- package/tui/app.mjs +1 -1
- package/worker/assistant-sidecar.mjs +7 -0
- package/dist-lib/lib/log-levels.d.ts +0 -7
- package/dist-lib/lib/log-levels.js +0 -1
- package/dist-lib/lib/logger.d.ts +0 -5
- package/dist-lib/lib/logger.js +0 -18
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Readable } from 'streamx';
|
|
2
|
-
import '
|
|
2
|
+
import type { LoggerInterface } from '@qvac/logging';
|
|
3
3
|
export declare function snapshotEquals(a: unknown, b: unknown): boolean;
|
|
4
4
|
interface WatchableStore {
|
|
5
5
|
watch(listener: () => void): void;
|
|
@@ -12,7 +12,8 @@ interface WatchableStore {
|
|
|
12
12
|
}
|
|
13
13
|
export interface WatchableOptions {
|
|
14
14
|
readonly name: string;
|
|
15
|
+
readonly log: LoggerInterface | null;
|
|
15
16
|
readonly changes?: WatchableStore;
|
|
16
17
|
}
|
|
17
|
-
export declare function watchable<TRequest, TResult, TStore extends WatchableStore = WatchableStore>(storeOf: (request: TRequest) => TStore | null | Promise<TStore | null>, query: (request: TRequest, store: TStore) => Promise<TResult>, { name, changes }: WatchableOptions): (request: TRequest) => Readable & AsyncIterable<TResult>;
|
|
18
|
+
export declare function watchable<TRequest, TResult, TStore extends WatchableStore = WatchableStore>(storeOf: (request: TRequest) => TStore | null | Promise<TStore | null>, query: (request: TRequest, store: TStore) => Promise<TResult>, { name, log, changes }: WatchableOptions): (request: TRequest) => Readable & AsyncIterable<TResult>;
|
|
18
19
|
export {};
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import { Readable } from 'streamx';
|
|
3
3
|
import { frameReadable } from '../frame-readable.js';
|
|
4
|
-
import '../logger.js';
|
|
5
4
|
import { asError, isRecord } from '../guards.js';
|
|
6
5
|
const SCOPE = ['api', 'watch'];
|
|
7
6
|
const CHURN_WINDOW_MS = 30_000;
|
|
@@ -26,7 +25,7 @@ export function snapshotEquals(a, b) {
|
|
|
26
25
|
}
|
|
27
26
|
return keys.every((key) => snapshotEquals(a[key], b[key]));
|
|
28
27
|
}
|
|
29
|
-
export function watchable(storeOf, query, { name, changes }) {
|
|
28
|
+
export function watchable(storeOf, query, { name, log, changes }) {
|
|
30
29
|
return (request) => {
|
|
31
30
|
const resolved = storeOf(request);
|
|
32
31
|
const pending = resolved instanceof Promise ? resolved.catch(noop) : null;
|
|
@@ -45,7 +44,7 @@ export function watchable(storeOf, query, { name, changes }) {
|
|
|
45
44
|
if (!force && elapsed < CHURN_WINDOW_MS) {
|
|
46
45
|
return;
|
|
47
46
|
}
|
|
48
|
-
|
|
47
|
+
log?.debug(SCOPE, `${name} woke with no change`, { woke: churn, ms: elapsed });
|
|
49
48
|
churn = 0;
|
|
50
49
|
reportedAt = now;
|
|
51
50
|
};
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import type { openLocalStore } from '../core/local/index.ts';
|
|
2
2
|
import type { Harness } from './harness.ts';
|
|
3
|
+
import type { LoggerInterface } from '@qvac/logging';
|
|
3
4
|
export declare const MAX_QUACKS = 500;
|
|
4
5
|
type LocalStore = Awaited<ReturnType<typeof openLocalStore>>;
|
|
5
6
|
export type FakeModelsSource = Pick<LocalStore, 'get' | 'watch' | 'unwatch'>;
|
|
6
|
-
interface Logger {
|
|
7
|
-
warn(...args: unknown[]): void;
|
|
8
|
-
}
|
|
9
7
|
export interface FakeModelsOptions {
|
|
10
8
|
enabled?: () => boolean;
|
|
11
9
|
paceMs?: number;
|
|
@@ -15,7 +13,7 @@ export declare function readFakeModels(state: Pick<FakeModelsSource, 'get'>): Pr
|
|
|
15
13
|
export interface FakeModelsWatchOptions {
|
|
16
14
|
initial: boolean;
|
|
17
15
|
onChange: (enabled: boolean) => void;
|
|
18
|
-
logger?:
|
|
16
|
+
logger?: LoggerInterface | null;
|
|
19
17
|
}
|
|
20
18
|
export declare function watchFakeModels(state: FakeModelsSource, opts: FakeModelsWatchOptions): () => Promise<void>;
|
|
21
19
|
export declare function withFakeModels(harness: Harness, opts?: FakeModelsOptions): Harness;
|
|
@@ -3,6 +3,7 @@ import { RUN_FAILURE_REASONS } from '../run-notices.js';
|
|
|
3
3
|
import { MODEL_TASK_TYPES } from '../../schema/engine.js';
|
|
4
4
|
import { toEngineSkill } from './skill-encode.js';
|
|
5
5
|
import { isRecord } from '../guards.js';
|
|
6
|
+
import { CoreError } from '../errors.js';
|
|
6
7
|
export function isHarnessEvent(event, type) {
|
|
7
8
|
return event.type === type;
|
|
8
9
|
}
|
|
@@ -34,7 +35,7 @@ export const DELETE_CONTRACT_MATCHES = true;
|
|
|
34
35
|
export function harnessPreviewModelSource(harness) {
|
|
35
36
|
return async ({ src, mmprojSrc }) => {
|
|
36
37
|
if (!harness.previewModelSource) {
|
|
37
|
-
throw new
|
|
38
|
+
throw new CoreError('CAPABILITY_UNSUPPORTED', ['previewModelSource']);
|
|
38
39
|
}
|
|
39
40
|
const preview = await harness.previewModelSource({ src, mmprojSrc: mmprojSrc ?? undefined });
|
|
40
41
|
return {
|
|
@@ -47,7 +48,7 @@ export function harnessPreviewModelSource(harness) {
|
|
|
47
48
|
export function harnessTranscribe(harness) {
|
|
48
49
|
return async ({ audio, model }) => {
|
|
49
50
|
if (!harness.transcribe) {
|
|
50
|
-
throw new
|
|
51
|
+
throw new CoreError('CAPABILITY_UNSUPPORTED', ['transcribe']);
|
|
51
52
|
}
|
|
52
53
|
return { text: await harness.transcribe({ audio, model: model ?? '' }) };
|
|
53
54
|
};
|
|
@@ -55,7 +56,7 @@ export function harnessTranscribe(harness) {
|
|
|
55
56
|
export function harnessDetectLanguage(harness) {
|
|
56
57
|
return async ({ text, topK }) => {
|
|
57
58
|
if (!harness.detectLanguage) {
|
|
58
|
-
throw new
|
|
59
|
+
throw new CoreError('CAPABILITY_UNSUPPORTED', ['detectLanguage']);
|
|
59
60
|
}
|
|
60
61
|
const languages = await harness.detectLanguage({ text, topK: topK || undefined });
|
|
61
62
|
return {
|
|
@@ -69,8 +70,9 @@ export function harnessDetectLanguage(harness) {
|
|
|
69
70
|
}
|
|
70
71
|
export function harnessSpeak(harness) {
|
|
71
72
|
return async ({ text, model }) => {
|
|
72
|
-
if (!harness.speak)
|
|
73
|
-
throw new
|
|
73
|
+
if (!harness.speak) {
|
|
74
|
+
throw new CoreError('CAPABILITY_UNSUPPORTED', ['speak']);
|
|
75
|
+
}
|
|
74
76
|
const { audio, sampleRate } = await harness.speak({ text, model: model ?? '' });
|
|
75
77
|
return { audio, sampleRate };
|
|
76
78
|
};
|
|
@@ -136,7 +138,7 @@ export function toolReportEntry(tool) {
|
|
|
136
138
|
export function harnessSpeakStream(harness) {
|
|
137
139
|
return async function* (text) {
|
|
138
140
|
if (!harness.speakStream) {
|
|
139
|
-
throw new
|
|
141
|
+
throw new CoreError('CAPABILITY_UNSUPPORTED', ['speakStream']);
|
|
140
142
|
}
|
|
141
143
|
for await (const { audio, sampleRate } of harness.speakStream({ model: '', text })) {
|
|
142
144
|
yield { audio, sampleRate };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Core } from './core.ts';
|
|
2
2
|
import type { DeviceMetadata } from './core/mesh.ts';
|
|
3
|
+
import type { Logger } from './logger-type.ts';
|
|
3
4
|
import { Client, type ClientOptions } from './client.ts';
|
|
4
5
|
export interface AssistantClientOptions extends ClientOptions {
|
|
6
|
+
logger?: Logger | null;
|
|
5
7
|
sidecar?: boolean;
|
|
6
8
|
storagePath: string;
|
|
7
9
|
device?: DeviceMetadata;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Client } from './client.js';
|
|
2
2
|
import { duplexPair } from '@qvac/harness/transport';
|
|
3
3
|
import b4a from 'b4a';
|
|
4
|
+
import { CoreError } from './errors.js';
|
|
4
5
|
export class AssistantClient extends Client {
|
|
5
6
|
_inline;
|
|
6
7
|
constructor({ sidecar: spawnSidecar = true, storagePath, device, meshSeed, meshKey, bootstrapNodes, entry, ...engineOptions }) {
|
|
7
8
|
const inline = { core: null };
|
|
8
9
|
if (spawnSidecar && !entry) {
|
|
9
|
-
throw new
|
|
10
|
+
throw new CoreError('SIDECAR_ENTRY_MISSING');
|
|
10
11
|
}
|
|
11
12
|
const sidecarEntry = spawnSidecar ? entry : undefined;
|
|
12
13
|
const args = [
|
|
@@ -22,10 +23,10 @@ export class AssistantClient extends Client {
|
|
|
22
23
|
? async () => {
|
|
23
24
|
const { default: sidecarRunner } = await import('bare-supervisor/runner/sidecar');
|
|
24
25
|
const { ipc, exit } = sidecarRunner(sidecarEntry, args, engineOptions.logger ?? null);
|
|
25
|
-
const died = exit.then((code) =>
|
|
26
|
+
const died = exit.then((code) => new CoreError('SIDECAR_EXITED', [code]));
|
|
26
27
|
const failure = await Promise.race([ipc.ready.then(() => null), died]);
|
|
27
28
|
if (failure) {
|
|
28
|
-
throw
|
|
29
|
+
throw failure;
|
|
29
30
|
}
|
|
30
31
|
return ipc;
|
|
31
32
|
}
|
|
@@ -3,7 +3,7 @@ import { type Harness } from './assistant.ts';
|
|
|
3
3
|
import { Client } from './client.ts';
|
|
4
4
|
import type { Core } from './core.ts';
|
|
5
5
|
import type { IndexingEmbedder, RagExtractors } from './core/files/index.ts';
|
|
6
|
-
import type {
|
|
6
|
+
import type { LoggerInterface } from '@qvac/logging';
|
|
7
7
|
export interface HarnessContext {
|
|
8
8
|
engine: Client;
|
|
9
9
|
onDeath: (error?: Error) => void;
|
|
@@ -19,7 +19,7 @@ export type OnHarness = (harness: Harness, ctx: {
|
|
|
19
19
|
export interface AssistantTreeOptions {
|
|
20
20
|
core: Core;
|
|
21
21
|
harness: HarnessFactory | ChildSpec<Harness>;
|
|
22
|
-
logger?:
|
|
22
|
+
logger?: LoggerInterface | null;
|
|
23
23
|
imageCacheDir?: string;
|
|
24
24
|
inferenceCallsDir?: string;
|
|
25
25
|
runReplayDir?: string;
|
|
@@ -36,7 +36,7 @@ export declare function assistantTree(opts: AssistantTreeOptions): Supervisor;
|
|
|
36
36
|
export interface AssistantChildOptions {
|
|
37
37
|
harness: HarnessFactory | ChildSpec<Harness>;
|
|
38
38
|
core?: string;
|
|
39
|
-
logger?:
|
|
39
|
+
logger?: LoggerInterface | null;
|
|
40
40
|
imageCacheDir?: string;
|
|
41
41
|
inferenceCallsDir?: string;
|
|
42
42
|
runReplayDir?: string;
|
|
@@ -7,7 +7,7 @@ import { type PdfRasterizer } from './core/pdf/rasterize.ts';
|
|
|
7
7
|
import type { DriveHost } from './core/fs-drives.ts';
|
|
8
8
|
import { type DiagnosticsSlice } from './diagnostics.ts';
|
|
9
9
|
import { type InferenceCallPage } from './inference-calls.ts';
|
|
10
|
-
import type {
|
|
10
|
+
import type { LoggerInterface } from '@qvac/logging';
|
|
11
11
|
import { type DeleteModelSummary, type Harness, type ListModelsOptions, type ModelInfo, type ToolCatalogEntry } from './assistant/harness.ts';
|
|
12
12
|
import type { Skill } from './assistant/skill-encode.ts';
|
|
13
13
|
import { type CompactOptions, type CompactResult } from './assistant/history.ts';
|
|
@@ -19,7 +19,7 @@ export declare const CAPTURE_INFERENCE_CALLS_KEY = "inspector.captureInferenceCa
|
|
|
19
19
|
export declare const CAPTURE_ON = "on";
|
|
20
20
|
export declare const CAPTURE_OFF = "off";
|
|
21
21
|
export interface AssistantOptions {
|
|
22
|
-
logger?:
|
|
22
|
+
logger?: LoggerInterface | null;
|
|
23
23
|
imageCacheDir?: string;
|
|
24
24
|
inferenceCallsDir?: string;
|
|
25
25
|
runReplayDir?: string;
|
|
@@ -17,7 +17,6 @@ import { acceptedRepairCount, historyBranches, isPromptChunk } from './core/prom
|
|
|
17
17
|
import ReadyGuard from 'ready-guard';
|
|
18
18
|
import ReadyResource from 'ready-resource';
|
|
19
19
|
import { local } from '../spec/index.js';
|
|
20
|
-
import { isMissingMesh } from './api/current-mesh.js';
|
|
21
20
|
import { meshScoped } from './mesh-scoped-engine.js';
|
|
22
21
|
import { buildTitlePrompt, deriveChatTitle, isDefaultChatTitle, parseTitleResponse } from './chat-title.js';
|
|
23
22
|
import { matchApprovalRule } from './core/approval-rules.js';
|
|
@@ -26,7 +25,7 @@ import { attachTurnDocumentIds, formatRagContext, chooseRagNotice, RAG_KNOWLEDGE
|
|
|
26
25
|
import { annotateDocumentAttachments, documentUnreadNotice, documentUnreadReason } from './core/document-attachment.js';
|
|
27
26
|
import { imageCacheKey, imageCacheName, sweepImageCache } from './core/image/cache-sweep.js';
|
|
28
27
|
import { IMAGE_MIMES, normalizeImageForModel } from './core/image/normalize.js';
|
|
29
|
-
import { MAX_PDF_PAGE_IMAGES,
|
|
28
|
+
import { MAX_PDF_PAGE_IMAGES, createPdfRasterizer } from './core/pdf/rasterize.js';
|
|
30
29
|
import { recordBackends, summarizeRuns } from './diagnostics.js';
|
|
31
30
|
import { resolveFsGrants } from './fs-drive-bridge.js';
|
|
32
31
|
import { InferenceCallStore } from './inference-calls.js';
|
|
@@ -48,6 +47,7 @@ import { annotateUnreadableImages, audioTranscriptBlock, backfillDocumentOnlyTur
|
|
|
48
47
|
import { drainBody, raceInactivity } from './assistant/fetch-body.js';
|
|
49
48
|
import { GENERIC_ACKNOWLEDGEMENTS, HISTORY_TYPES, SKILL_TOOL, TERMINAL_STATES, couldNameSenders, historyFromChunks, inputAvailableToRun, listHistoryChunks, senderAttribution, senderNamesFrom, staleToolRunIds } from './assistant/history.js';
|
|
50
49
|
import { errorMessage, isRecord } from './guards.js';
|
|
50
|
+
import { CoreError, isCoreError } from './errors.js';
|
|
51
51
|
export { harnessClearKvCache, harnessDeleteModel, harnessListModels, harnessPreviewModelSource, harnessSkillCatalog, harnessSkillManagement, harnessDetectLanguage, harnessSpeak, harnessSpeakStream, harnessTools, harnessTranscribe } from './assistant/harness.js';
|
|
52
52
|
export {} from './assistant/skill-encode.js';
|
|
53
53
|
export { annotateUnreadableImages, unheardAudioNotice, unreadableImagesNotice, DOCUMENT_ONLY_USER_PROMPT, IMAGE_AND_DOCUMENT_USER_PROMPT, IMAGE_ONLY_USER_PROMPT, nameSenders } from './assistant/message.js';
|
|
@@ -196,7 +196,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
196
196
|
_modelCatalog = new ModelCatalogRevisionHub();
|
|
197
197
|
_onHarnessStatus;
|
|
198
198
|
_onModelCatalogEvent;
|
|
199
|
-
constructor(engine, harness, { logger = null, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, downloadRetryMs, platform = os.platform(), preloadCurrentAgentModel = true, drives, borrowHarness, blobReadTimeoutMs = BLOB_READ_TIMEOUT_MS, pdfRasterizer: pdfRasterizerOption
|
|
199
|
+
constructor(engine, harness, { logger = null, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, downloadRetryMs, platform = os.platform(), preloadCurrentAgentModel = true, drives, borrowHarness, blobReadTimeoutMs = BLOB_READ_TIMEOUT_MS, pdfRasterizer: pdfRasterizerOption } = {}) {
|
|
200
200
|
super();
|
|
201
201
|
this._engine = engine;
|
|
202
202
|
this._harness = harness;
|
|
@@ -211,7 +211,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
211
211
|
this._mobileClass = isMobilePlatform(platform);
|
|
212
212
|
this._preloadCurrentAgentModel = preloadCurrentAgentModel;
|
|
213
213
|
this._blobReadTimeoutMs = blobReadTimeoutMs;
|
|
214
|
-
this._pdfRasterizer = pdfRasterizerOption;
|
|
214
|
+
this._pdfRasterizer = pdfRasterizerOption ?? createPdfRasterizer(logger);
|
|
215
215
|
this._deviceId = null;
|
|
216
216
|
this._info = { toolNames: [], skills: [], supportsImages: false };
|
|
217
217
|
this._readySkills = null;
|
|
@@ -593,7 +593,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
593
593
|
this._lastCapabilities.set(meshId, key);
|
|
594
594
|
}
|
|
595
595
|
catch (err) {
|
|
596
|
-
if (
|
|
596
|
+
if (isCoreError(err, 'MESH_NOT_FOUND')) {
|
|
597
597
|
return;
|
|
598
598
|
}
|
|
599
599
|
this._log?.error('assistant', 'saveDeviceCapabilities failed', err);
|
|
@@ -700,7 +700,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
700
700
|
this._harness.off?.('status', this._onHarnessStatus);
|
|
701
701
|
this._harness.off?.('model', this._onModelCatalogEvent);
|
|
702
702
|
this._warmAbort.abort(RUNNER_CLOSED);
|
|
703
|
-
this._onlineBoot.destroy(new
|
|
703
|
+
this._onlineBoot.destroy(new CoreError('ASSISTANT_CLOSING'));
|
|
704
704
|
for (const run of this._runs.values()) {
|
|
705
705
|
run.controller.abort(RUNNER_CLOSED);
|
|
706
706
|
}
|
|
@@ -802,10 +802,10 @@ export class QvacAssistant extends ReadyResource {
|
|
|
802
802
|
}
|
|
803
803
|
async loadModel(name) {
|
|
804
804
|
if (!this._harness.loadModel) {
|
|
805
|
-
throw new
|
|
805
|
+
throw new CoreError('MODEL_RUNTIME_UNSUPPORTED', ['preload']);
|
|
806
806
|
}
|
|
807
807
|
if (!(await this._isCached(name))) {
|
|
808
|
-
throw new
|
|
808
|
+
throw new CoreError('MODEL_NOT_DOWNLOADED', [name]);
|
|
809
809
|
}
|
|
810
810
|
const config = await this._engine.getConfig({}).catch(noop);
|
|
811
811
|
const agent = await this._agentRunning(name, config?.activeAgentId ?? null);
|
|
@@ -848,7 +848,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
848
848
|
}
|
|
849
849
|
async _unloadModel(name) {
|
|
850
850
|
if (!this._harness.unloadModel) {
|
|
851
|
-
throw new
|
|
851
|
+
throw new CoreError('MODEL_RUNTIME_UNSUPPORTED', ['unload']);
|
|
852
852
|
}
|
|
853
853
|
const holders = [...this._runs.values()].filter((run) => run.executing && !run.borrowed && run.model === name);
|
|
854
854
|
for (const run of holders) {
|
|
@@ -909,7 +909,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
909
909
|
}
|
|
910
910
|
async retryModelDownload(name) {
|
|
911
911
|
if (!this._downloads) {
|
|
912
|
-
throw new
|
|
912
|
+
throw new CoreError('MODEL_DOWNLOAD_UNAVAILABLE');
|
|
913
913
|
}
|
|
914
914
|
await this._downloads.retry(name);
|
|
915
915
|
}
|
|
@@ -984,7 +984,7 @@ export class QvacAssistant extends ReadyResource {
|
|
|
984
984
|
let stopped = false;
|
|
985
985
|
const settle = (err) => {
|
|
986
986
|
running = false;
|
|
987
|
-
if (err !== null && !stopped && !
|
|
987
|
+
if (err !== null && !stopped && !isCoreError(err, 'MESH_NOT_FOUND')) {
|
|
988
988
|
this._log?.error('assistant', `${label} watch failed`, err);
|
|
989
989
|
}
|
|
990
990
|
if (again) {
|
package/dist-lib/lib/client.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import ReadyResource from 'ready-resource';
|
|
2
2
|
import type { Capabilities } from './api/index.ts';
|
|
3
3
|
import type { CapabilityHandlers } from '../spec/capabilities.d.ts';
|
|
4
|
-
import type {
|
|
4
|
+
import type { LoggerInterface } from '@qvac/logging';
|
|
5
5
|
import { type EngineSpec } from './spec-loader.ts';
|
|
6
6
|
import { type Transport } from '@qvac/harness/rpc';
|
|
7
7
|
export interface ClientOptions {
|
|
8
|
-
logger?:
|
|
8
|
+
logger?: LoggerInterface | null;
|
|
9
9
|
spec?: () => Promise<EngineSpec>;
|
|
10
10
|
handlers?: Partial<CapabilityHandlers>;
|
|
11
11
|
}
|
|
@@ -2,6 +2,7 @@ import { softDeleteChatsForAgent } from './chat.js';
|
|
|
2
2
|
import { randomId } from './id.js';
|
|
3
3
|
import { softDeleteToolConfigsForAgent } from './tool-configs.js';
|
|
4
4
|
import b4a from 'b4a';
|
|
5
|
+
import { CoreError } from '../errors.js';
|
|
5
6
|
import { ACTIVE_AGENTS, AGENTS, AGENTS_BY_PROVIDER, DEFAULT_AGENTS, DEVICES } from './collections.js';
|
|
6
7
|
const DEFAULT_ICON_NAME = 'artificial-intelligence';
|
|
7
8
|
export function allTools() {
|
|
@@ -78,14 +79,14 @@ export async function liveProviderIds(store) {
|
|
|
78
79
|
export async function mustGetAgent(store, id) {
|
|
79
80
|
const agent = await getAgent(store, id);
|
|
80
81
|
if (!agent) {
|
|
81
|
-
throw new
|
|
82
|
+
throw new CoreError('AGENT_NOT_FOUND', [id]);
|
|
82
83
|
}
|
|
83
84
|
return agent;
|
|
84
85
|
}
|
|
85
86
|
export async function mustGetActiveAgent(store, id) {
|
|
86
87
|
const agent = await mustGetAgent(store, id);
|
|
87
88
|
if (agent.deletedAt) {
|
|
88
|
-
throw new
|
|
89
|
+
throw new CoreError('AGENT_NOT_FOUND', [id]);
|
|
89
90
|
}
|
|
90
91
|
return agent;
|
|
91
92
|
}
|
|
@@ -153,7 +154,7 @@ export async function updateAgent(store, agentId, input) {
|
|
|
153
154
|
if (input.clearIsDefault && current.isDefault) {
|
|
154
155
|
const own = await ownDefaultAgents(store);
|
|
155
156
|
if (own.length === 1 && own[0].id === current.id) {
|
|
156
|
-
throw new
|
|
157
|
+
throw new CoreError('AGENT_LAST_DEFAULT');
|
|
157
158
|
}
|
|
158
159
|
}
|
|
159
160
|
const enabledSkills = patch(input.enabledSkills, current.enabledSkills);
|
|
@@ -203,7 +204,7 @@ export async function rehomeAgents(store, from, to) {
|
|
|
203
204
|
export async function deleteAgent(store, deviceId, id) {
|
|
204
205
|
const current = await mustGetAgent(store, id);
|
|
205
206
|
if (current.isDefault) {
|
|
206
|
-
throw new
|
|
207
|
+
throw new CoreError('AGENT_DEFAULT_UNDELETABLE');
|
|
207
208
|
}
|
|
208
209
|
const deletedAt = Date.now();
|
|
209
210
|
const updated = {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type Corestore from 'corestore';
|
|
2
2
|
import type CorestoreStorage from 'hypercore-storage';
|
|
3
|
-
import type {
|
|
3
|
+
import type { LoggerInterface } from '@qvac/logging';
|
|
4
4
|
import type { LocalMeshMembership } from '../../spec/local/hyperschema/types.d.ts';
|
|
5
5
|
import { Mesh } from './mesh.ts';
|
|
6
|
-
export declare const NO_ARCHIVE_HELD = "No archive is held for this mesh";
|
|
7
6
|
export interface ArchivedMeshCounts {
|
|
8
7
|
readonly chats: number;
|
|
9
8
|
readonly agents: number;
|
|
@@ -20,7 +19,7 @@ export interface ArchivedMeshOptions {
|
|
|
20
19
|
readonly store: Corestore;
|
|
21
20
|
readonly storage: CorestoreStorage;
|
|
22
21
|
readonly deviceId: Buffer;
|
|
23
|
-
readonly logger:
|
|
22
|
+
readonly logger: LoggerInterface | null;
|
|
24
23
|
}
|
|
25
24
|
export declare function withArchivedMesh<T>(row: LocalMeshMembership, opts: ArchivedMeshOptions, fn: (mesh: Mesh) => Promise<T>): Promise<T>;
|
|
26
25
|
export declare function countContents(mesh: Mesh, into?: Mesh | null): Promise<ArchivedMeshCounts>;
|
|
@@ -2,11 +2,11 @@ import crypto from 'hypercore-crypto';
|
|
|
2
2
|
import { copyBlob, copyChunks, stripped } from './chat-copy.js';
|
|
3
3
|
import { Mesh } from './mesh.js';
|
|
4
4
|
import { ACTIVE_AGENTS, ACTIVE_CHATS, ACTIVE_CHAT_GROUPS, ACTIVE_TOOL_CONFIGS_BY_AGENT, AGENTS, KNOWLEDGE } from './collections.js';
|
|
5
|
+
import { CoreError } from '../errors.js';
|
|
5
6
|
const MIGRATED_SUFFIX = ' (migrated)';
|
|
6
|
-
export const NO_ARCHIVE_HELD = 'No archive is held for this mesh';
|
|
7
7
|
export async function withArchivedMesh(row, opts, fn) {
|
|
8
8
|
if (!(await opts.storage.hasCore(crypto.discoveryKey(row.key)))) {
|
|
9
|
-
throw new
|
|
9
|
+
throw new CoreError('ARCHIVE_NOT_FOUND');
|
|
10
10
|
}
|
|
11
11
|
const mesh = new Mesh(opts.store, {
|
|
12
12
|
seed: row.seed,
|
|
@@ -18,7 +18,7 @@ export async function withArchivedMesh(row, opts, fn) {
|
|
|
18
18
|
await mesh.ready();
|
|
19
19
|
try {
|
|
20
20
|
if (mesh.localLength === 0) {
|
|
21
|
-
throw new
|
|
21
|
+
throw new CoreError('ARCHIVE_NOT_FOUND');
|
|
22
22
|
}
|
|
23
23
|
await mesh.autobee.update();
|
|
24
24
|
return await fn(mesh);
|
|
@@ -16,17 +16,19 @@ const catalogs = new WeakMap();
|
|
|
16
16
|
export function listChatActivity(store, chatIds) {
|
|
17
17
|
let catalog = catalogs.get(store);
|
|
18
18
|
if (!catalog) {
|
|
19
|
-
catalog = new ChatActivityCatalog();
|
|
19
|
+
catalog = new ChatActivityCatalog(store.log);
|
|
20
20
|
catalogs.set(store, catalog);
|
|
21
21
|
}
|
|
22
22
|
return catalog.list(store, chatIds);
|
|
23
23
|
}
|
|
24
24
|
class ChatActivityCatalog {
|
|
25
|
+
_log;
|
|
25
26
|
_lock;
|
|
26
27
|
_chats;
|
|
27
28
|
_head;
|
|
28
29
|
_forwards;
|
|
29
|
-
constructor() {
|
|
30
|
+
constructor(log) {
|
|
31
|
+
this._log = log;
|
|
30
32
|
this._lock = new ScopeLock();
|
|
31
33
|
this._chats = new Map();
|
|
32
34
|
this._head = null;
|
|
@@ -117,7 +119,7 @@ class ChatActivityCatalog {
|
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
catch (err) {
|
|
120
|
-
|
|
122
|
+
this._log?.warn('chat-activity', 'diff from the cached head failed, rebuilding', err);
|
|
121
123
|
return false;
|
|
122
124
|
}
|
|
123
125
|
for (const [chatId, chunks] of chunksByChat) {
|
|
@@ -9,7 +9,6 @@ export interface ChatMoveCopy extends MeshCopy {
|
|
|
9
9
|
readonly originDeviceId: Buffer;
|
|
10
10
|
readonly references: Map<string, string>;
|
|
11
11
|
}
|
|
12
|
-
export declare const CHUNK_IN_ANOTHER_CHAT = "the target already holds this chat under another id";
|
|
13
12
|
export declare function copyChunks(snap: HyperDB, chatId: string, { from, into }: MeshCopy): Promise<void>;
|
|
14
13
|
export declare function copyMovedChunks(snap: HyperDB, chatId: string, copy: ChatMoveCopy): Promise<number>;
|
|
15
14
|
export declare function copyMovedKnowledge(snap: HyperDB, chatId: string, copy: ChatMoveCopy): Promise<void>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
2
|
import { PENDING_BLOB_REFERENCE, isPendingBlobReference, parseBlobReference } from './files/store/index.js';
|
|
3
|
+
import { CoreError } from '../errors.js';
|
|
3
4
|
import { inlineReference } from './files/store/inline.js';
|
|
4
5
|
import { CHUNKS, CHUNKS_BY_CHAT, KNOWLEDGE, KNOWLEDGE_BY_CHAT } from './collections.js';
|
|
5
|
-
export const CHUNK_IN_ANOTHER_CHAT = 'the target already holds this chat under another id';
|
|
6
6
|
export async function copyChunks(snap, chatId, { from, into }) {
|
|
7
7
|
const batch = into.batch();
|
|
8
8
|
for (const chunk of await chunksOf(snap, chatId)) {
|
|
@@ -89,7 +89,7 @@ export function removedReference({ mimeType }) {
|
|
|
89
89
|
async function heldInTarget(into, { collection, id, chatId }) {
|
|
90
90
|
const existing = await into.view.get(collection, { id });
|
|
91
91
|
if (existing && existing.chatId !== chatId) {
|
|
92
|
-
throw new
|
|
92
|
+
throw new CoreError('CHAT_MOVE_ID_CONFLICT');
|
|
93
93
|
}
|
|
94
94
|
return !!existing;
|
|
95
95
|
}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { type ChatListing } from './chat.ts';
|
|
2
2
|
import type { Mesh } from './mesh.ts';
|
|
3
|
-
export declare const NO_SUCH_TURN = "no turn of this chat has that run id";
|
|
4
|
-
export declare const TURN_RUNNING = "a turn up to the fork point is still running; fork once it has finished";
|
|
5
|
-
export declare const NOTHING_BEFORE = "nothing comes before the first turn, so there is nothing to fork";
|
|
6
|
-
export declare const AGENT_REQUIRED = "a chat forked into another mesh needs an agent of that mesh";
|
|
7
|
-
export declare const FILE_ARRIVING = "a file in this chat is still arriving; fork once it has landed";
|
|
8
|
-
export declare const FILE_NOT_HERE = "a file in this chat is not on this device yet; open it here first";
|
|
9
3
|
export interface ForkMeshes {
|
|
10
4
|
readonly from: Mesh;
|
|
11
5
|
readonly into: Mesh;
|
|
@@ -1,27 +1,21 @@
|
|
|
1
1
|
import b4a from 'b4a';
|
|
2
|
+
import { CoreError } from '../errors.js';
|
|
2
3
|
import { mustGetActiveAgent } from './agent.js';
|
|
3
4
|
import { TERMINAL_RUN_STATES, enrichChat, listSidebar } from './chat.js';
|
|
4
5
|
import { copyBlob, removedReference, stripped } from './chat-copy.js';
|
|
5
|
-
import { COMPUTE_MESH, NOT_A_WRITER } from './chat-move.js';
|
|
6
6
|
import { chatSortKey } from './chat-order.js';
|
|
7
7
|
import { isPendingBlobReference } from './files/index.js';
|
|
8
8
|
import { groupAttachmentsByMessage } from './files/records/linkage.js';
|
|
9
9
|
import { derivedId, randomId } from './id.js';
|
|
10
10
|
import { rankOnTop } from './rank.js';
|
|
11
11
|
import { CHATS, CHUNKS_BY_CHAT, KNOWLEDGE_BY_CHAT } from './collections.js';
|
|
12
|
-
export const NO_SUCH_TURN = 'no turn of this chat has that run id';
|
|
13
|
-
export const TURN_RUNNING = 'a turn up to the fork point is still running; fork once it has finished';
|
|
14
|
-
export const NOTHING_BEFORE = 'nothing comes before the first turn, so there is nothing to fork';
|
|
15
|
-
export const AGENT_REQUIRED = 'a chat forked into another mesh needs an agent of that mesh';
|
|
16
|
-
export const FILE_ARRIVING = 'a file in this chat is still arriving; fork once it has landed';
|
|
17
|
-
export const FILE_NOT_HERE = 'a file in this chat is not on this device yet; open it here first';
|
|
18
12
|
export async function forkChat(meshes, input) {
|
|
19
13
|
const { into } = meshes;
|
|
20
14
|
if (meshes.from.compute || into.compute) {
|
|
21
|
-
throw new
|
|
15
|
+
throw new CoreError('CHAT_COMPUTE_MESH');
|
|
22
16
|
}
|
|
23
17
|
if (!into.writable) {
|
|
24
|
-
throw new
|
|
18
|
+
throw new CoreError('CHAT_TARGET_NOT_WRITER');
|
|
25
19
|
}
|
|
26
20
|
const plan = await forkPlan(meshes, input);
|
|
27
21
|
const batch = into.batch();
|
|
@@ -41,7 +35,7 @@ async function forkPlan(meshes, input) {
|
|
|
41
35
|
try {
|
|
42
36
|
const source = await snap.get(CHATS, { id: input.chatId });
|
|
43
37
|
if (!source || source.deletedAt) {
|
|
44
|
-
throw new
|
|
38
|
+
throw new CoreError('CHAT_NOT_FOUND', [input.chatId]);
|
|
45
39
|
}
|
|
46
40
|
const all = await chunksOf(snap, source.id);
|
|
47
41
|
const cut = forkCut(all, input);
|
|
@@ -63,7 +57,7 @@ function forkCut(chunks, input) {
|
|
|
63
57
|
const end = input.runId ? endAt(requests, input) : settledEnd(requests, finished);
|
|
64
58
|
const included = requests.slice(0, end);
|
|
65
59
|
if (included.some((request) => !finished.has(request.runId ?? ''))) {
|
|
66
|
-
throw new
|
|
60
|
+
throw new CoreError('CHAT_FORK_TURN_RUNNING');
|
|
67
61
|
}
|
|
68
62
|
const turns = new Set(requests.map((request) => request.runId));
|
|
69
63
|
const runs = new Set(included.map((request) => request.runId));
|
|
@@ -84,18 +78,18 @@ function forkCut(chunks, input) {
|
|
|
84
78
|
function endAt(requests, { runId, exclusive }) {
|
|
85
79
|
const at = requests.findIndex((request) => request.runId === runId);
|
|
86
80
|
if (at === -1) {
|
|
87
|
-
throw new
|
|
81
|
+
throw new CoreError('CHAT_FORK_NO_SUCH_TURN');
|
|
88
82
|
}
|
|
89
83
|
const end = exclusive ? at : at + 1;
|
|
90
84
|
if (end === 0) {
|
|
91
|
-
throw new
|
|
85
|
+
throw new CoreError('CHAT_FORK_NOTHING_BEFORE');
|
|
92
86
|
}
|
|
93
87
|
return end;
|
|
94
88
|
}
|
|
95
89
|
function settledEnd(requests, finished) {
|
|
96
90
|
const running = requests.findIndex((request) => !finished.has(request.runId ?? ''));
|
|
97
91
|
if (running === 0) {
|
|
98
|
-
throw new
|
|
92
|
+
throw new CoreError('CHAT_FORK_TURN_RUNNING');
|
|
99
93
|
}
|
|
100
94
|
return running === -1 ? requests.length : running;
|
|
101
95
|
}
|
|
@@ -146,7 +140,7 @@ async function forkAgentId(ctx, { source, agentId }) {
|
|
|
146
140
|
return (await mustGetActiveAgent(ctx.into, agentId)).id;
|
|
147
141
|
}
|
|
148
142
|
if (!ctx.same) {
|
|
149
|
-
throw new
|
|
143
|
+
throw new CoreError('CHAT_FORK_AGENT_REQUIRED');
|
|
150
144
|
}
|
|
151
145
|
return source.agentId;
|
|
152
146
|
}
|
|
@@ -205,7 +199,7 @@ async function forkedReference(ctx, file) {
|
|
|
205
199
|
return removedReference(file);
|
|
206
200
|
}
|
|
207
201
|
if (isPendingBlobReference(file.blobId)) {
|
|
208
|
-
throw new
|
|
202
|
+
throw new CoreError('CHAT_FORK_FILE_ARRIVING');
|
|
209
203
|
}
|
|
210
204
|
const known = ctx.references.get(file.blobId);
|
|
211
205
|
if (known) {
|
|
@@ -213,7 +207,7 @@ async function forkedReference(ctx, file) {
|
|
|
213
207
|
}
|
|
214
208
|
const copied = await copyBlob(ctx.from, ctx.into, file.blobId);
|
|
215
209
|
if (!copied) {
|
|
216
|
-
throw new
|
|
210
|
+
throw new CoreError('CHAT_FORK_FILE_NOT_HERE');
|
|
217
211
|
}
|
|
218
212
|
ctx.references.set(file.blobId, copied);
|
|
219
213
|
return copied;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CoreError } from '../errors.js';
|
|
1
2
|
import { randomId } from './id.js';
|
|
2
3
|
import { place } from './rank.js';
|
|
3
4
|
import { ACTIVE_CHAT_GROUPS, CHAT_GROUPS } from './collections.js';
|
|
@@ -43,24 +44,24 @@ export async function getChatGroup(store, id) {
|
|
|
43
44
|
export async function mustGetChatGroup(store, id) {
|
|
44
45
|
const group = await getChatGroup(store, id);
|
|
45
46
|
if (!group) {
|
|
46
|
-
throw new
|
|
47
|
+
throw new CoreError('CHAT_GROUP_NOT_FOUND', [id]);
|
|
47
48
|
}
|
|
48
49
|
return group;
|
|
49
50
|
}
|
|
50
51
|
export async function mustGetActiveChatGroup(store, id) {
|
|
51
52
|
const group = await mustGetChatGroup(store, id);
|
|
52
53
|
if (group.deletedAt) {
|
|
53
|
-
throw new
|
|
54
|
+
throw new CoreError('CHAT_GROUP_NOT_FOUND', [id]);
|
|
54
55
|
}
|
|
55
56
|
return group;
|
|
56
57
|
}
|
|
57
58
|
function assertGroupName(name) {
|
|
58
59
|
const trimmed = name.trim();
|
|
59
60
|
if (!trimmed) {
|
|
60
|
-
throw new
|
|
61
|
+
throw new CoreError('CHAT_GROUP_NAME_EMPTY');
|
|
61
62
|
}
|
|
62
63
|
if (trimmed.length > NAME_MAX_LENGTH) {
|
|
63
|
-
throw new
|
|
64
|
+
throw new CoreError('CHAT_GROUP_NAME_TOO_LONG', [NAME_MAX_LENGTH]);
|
|
64
65
|
}
|
|
65
66
|
return trimmed;
|
|
66
67
|
}
|
|
@@ -88,7 +89,7 @@ export async function renameChatGroup(store, id, name) {
|
|
|
88
89
|
export async function moveChatGroup(store, id, { afterId }) {
|
|
89
90
|
const anchor = afterId || undefined;
|
|
90
91
|
if (anchor === id) {
|
|
91
|
-
throw new
|
|
92
|
+
throw new CoreError('CHAT_GROUP_ANCHOR_SELF', [id]);
|
|
92
93
|
}
|
|
93
94
|
const now = Date.now();
|
|
94
95
|
const snap = store.view.snapshot();
|
|
@@ -97,7 +98,7 @@ export async function moveChatGroup(store, id, { afterId }) {
|
|
|
97
98
|
try {
|
|
98
99
|
const group = await snap.get(CHAT_GROUPS, { id });
|
|
99
100
|
if (!group || group.deletedAt) {
|
|
100
|
-
throw new
|
|
101
|
+
throw new CoreError('CHAT_GROUP_NOT_FOUND', [id]);
|
|
101
102
|
}
|
|
102
103
|
current = group;
|
|
103
104
|
const siblings = (await listChatGroupsIn(snap)).filter((sibling) => sibling.id !== id);
|
|
@@ -105,7 +106,7 @@ export async function moveChatGroup(store, id, { afterId }) {
|
|
|
105
106
|
if (anchor) {
|
|
106
107
|
at = siblings.findIndex((sibling) => sibling.id === anchor);
|
|
107
108
|
if (at === -1) {
|
|
108
|
-
throw new
|
|
109
|
+
throw new CoreError('CHAT_GROUP_NOT_FOUND', [anchor]);
|
|
109
110
|
}
|
|
110
111
|
}
|
|
111
112
|
placement = place(siblings, groupSortKey, { at, now });
|