@qvac/core 0.11.0 → 0.11.2
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 +148 -1
- package/README.md +19 -16
- package/dist-lib/index.d.ts +1 -0
- package/dist-lib/index.js +1 -0
- package/dist-lib/lib/api/chunk-delta.d.ts +6 -2
- package/dist-lib/lib/api/chunk-delta.js +69 -7
- package/dist-lib/lib/api/chunks.js +10 -4
- package/dist-lib/lib/api/config.d.ts +4 -1
- package/dist-lib/lib/api/config.js +23 -4
- package/dist-lib/lib/api/devices.js +3 -1
- package/dist-lib/lib/api/rag.js +11 -7
- package/dist-lib/lib/assistant/harness.d.ts +3 -1
- package/dist-lib/lib/assistant/harness.js +10 -0
- package/dist-lib/lib/assistant/history.d.ts +1 -0
- package/dist-lib/lib/assistant/history.js +9 -3
- package/dist-lib/lib/assistant/message.js +2 -2
- package/dist-lib/lib/assistant-tree.d.ts +2 -0
- package/dist-lib/lib/assistant-tree.js +5 -3
- package/dist-lib/lib/assistant.d.ts +6 -1
- package/dist-lib/lib/assistant.js +77 -24
- package/dist-lib/lib/client.js +10 -1
- package/dist-lib/lib/compaction.d.ts +2 -1
- package/dist-lib/lib/compaction.js +14 -4
- package/dist-lib/lib/constants.d.ts +3 -0
- package/dist-lib/lib/constants.js +3 -0
- package/dist-lib/lib/core/archived-mesh.js +1 -0
- package/dist-lib/lib/core/chat-activity.js +12 -15
- package/dist-lib/lib/core/chunk.d.ts +14 -3
- package/dist-lib/lib/core/chunk.js +112 -22
- package/dist-lib/lib/core/collections.d.ts +1 -0
- package/dist-lib/lib/core/collections.js +1 -0
- package/dist-lib/lib/core/config-value.d.ts +6 -0
- package/dist-lib/lib/core/config-value.js +14 -0
- package/dist-lib/lib/core/contract/chat.d.ts +1 -0
- package/dist-lib/lib/core/contract/chat.js +8 -1
- package/dist-lib/lib/core/contract/chunks.js +20 -6
- package/dist-lib/lib/core/contract/compute.d.ts +1 -1
- package/dist-lib/lib/core/contract/compute.js +2 -1
- package/dist-lib/lib/core/contract/devices.js +3 -2
- package/dist-lib/lib/core/departures.js +1 -0
- package/dist-lib/lib/core/devices.d.ts +2 -1
- package/dist-lib/lib/core/devices.js +4 -2
- package/dist-lib/lib/core/files/attachments.js +3 -3
- package/dist-lib/lib/core/files/index.d.ts +1 -1
- package/dist-lib/lib/core/files/index.js +3 -2
- package/dist-lib/lib/core/files/processing/index.d.ts +1 -0
- package/dist-lib/lib/core/files/processing/index.js +8 -0
- package/dist-lib/lib/core/files/processing/settle.d.ts +1 -0
- package/dist-lib/lib/core/files/processing/settle.js +20 -13
- package/dist-lib/lib/core/files/rag/index.d.ts +1 -1
- package/dist-lib/lib/core/files/rag/index.js +1 -1
- package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +1 -0
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +4 -1
- package/dist-lib/lib/core/hosted-agents.d.ts +3 -0
- package/dist-lib/lib/core/hosted-agents.js +19 -0
- package/dist-lib/lib/core/inference-calls-receiver.js +2 -2
- package/dist-lib/lib/core/known-sender.d.ts +3 -0
- package/dist-lib/lib/core/known-sender.js +26 -0
- package/dist-lib/lib/core/local/index.d.ts +2 -0
- package/dist-lib/lib/core/local/index.js +17 -10
- package/dist-lib/lib/core/mesh.d.ts +5 -1
- package/dist-lib/lib/core/mesh.js +6 -6
- package/dist-lib/lib/core/migrations/chat-chunks.d.ts +4 -0
- package/dist-lib/lib/core/migrations/chat-chunks.js +43 -0
- package/dist-lib/lib/core/notification.js +16 -13
- package/dist-lib/lib/core/skill-overlay-receiver.js +2 -2
- package/dist-lib/lib/core/skill-secrets.js +2 -2
- package/dist-lib/lib/core.d.ts +17 -1
- package/dist-lib/lib/core.js +55 -5
- package/dist-lib/lib/credential-pusher.d.ts +11 -7
- package/dist-lib/lib/credential-pusher.js +40 -8
- package/dist-lib/lib/device-tree.d.ts +18 -0
- package/dist-lib/lib/device-tree.js +32 -0
- package/dist-lib/lib/integrations/setup-routes.js +7 -5
- package/dist-lib/lib/kv-cache-retention.d.ts +34 -0
- package/dist-lib/lib/kv-cache-retention.js +98 -0
- package/dist-lib/schema/content.js +2 -1
- package/dist-lib/schema/engine.js +20 -3
- package/dist-lib/schema/field-order.js +8 -1
- package/dist-lib/schema/local.js +7 -3
- package/dist-lib/schema/qvac.js +23 -4
- package/dist-lib/spec/hrpc/messages.js +1240 -1194
- package/dist-lib/spec/hyperschema/index.js +1240 -1194
- package/dist-lib/spec/hyperschema/schema.json +49 -1
- package/dist-lib/spec/hyperschema/types.d.ts +12 -1
- package/dist-lib/spec/local/hyperdb/messages.js +70 -20
- package/dist-lib/spec/local/hyperschema/index.js +36 -11
- package/dist-lib/spec/local/hyperschema/schema.json +21 -1
- package/dist-lib/spec/local/hyperschema/types.d.ts +5 -1
- package/dist-lib/spec/mesh/hyperdb/db.json +17 -1
- package/dist-lib/spec/mesh/hyperdb/index.js +83 -2
- package/dist-lib/spec/mesh/hyperdb/messages.js +602 -264
- 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 +137 -14
- package/dist-lib/spec/mesh/hyperschema/index.js +137 -14
- package/dist-lib/spec/mesh/hyperschema/schema.json +79 -1
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +21 -1
- package/package.json +13 -9
- package/tui/app.mjs +743 -266
- package/tui/boot.mjs +2 -2
- package/tui/lib/connect-sheet.mjs +350 -0
- package/tui/lib/setup.mjs +59 -25
- package/tui/lib/skill-connect.mjs +145 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Harness } from './assistant.ts';
|
|
2
2
|
import { type ConfigEngine } from './oauth.ts';
|
|
3
|
-
import type { OAuthRouteLike } from './oauth/keys.ts';
|
|
3
|
+
import type { OAuthKeySpec, OAuthRouteLike } from './oauth/keys.ts';
|
|
4
4
|
export interface CredentialEntry {
|
|
5
5
|
key: string;
|
|
6
6
|
token?: string | null;
|
|
@@ -14,19 +14,21 @@ export interface SettingEntry {
|
|
|
14
14
|
value: string;
|
|
15
15
|
agentId?: string | null;
|
|
16
16
|
}
|
|
17
|
+
type PusherRoute = OAuthRouteLike & {
|
|
18
|
+
fields?: ReadonlyArray<{
|
|
19
|
+
key: string;
|
|
20
|
+
secret?: boolean;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
17
23
|
export interface PusherSkill {
|
|
18
24
|
name: string;
|
|
25
|
+
origin?: string;
|
|
19
26
|
credentials?: readonly string[];
|
|
20
27
|
requires?: {
|
|
21
28
|
credentials?: readonly string[];
|
|
22
29
|
};
|
|
23
30
|
setup?: {
|
|
24
|
-
routes?: ReadonlyArray<
|
|
25
|
-
fields?: ReadonlyArray<{
|
|
26
|
-
key: string;
|
|
27
|
-
secret?: boolean;
|
|
28
|
-
}>;
|
|
29
|
-
}>;
|
|
31
|
+
routes?: ReadonlyArray<PusherRoute>;
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
34
|
export interface CredentialEngine extends ConfigEngine {
|
|
@@ -67,6 +69,8 @@ export type CredentialPusherHandle = (() => Promise<void>) & {
|
|
|
67
69
|
};
|
|
68
70
|
export declare function nextRefreshDelay(entries: ReadonlyArray<Pick<CredentialEntry, 'expiresAt'>>, now?: number): number;
|
|
69
71
|
export declare function credentialOwners(catalog: ReadonlyArray<PusherSkill>): ReadonlyMap<string, readonly string[]>;
|
|
72
|
+
export declare function plainCredentialKeys(catalog: ReadonlyArray<PusherSkill>, specs: ReadonlyArray<OAuthKeySpec>): ReadonlyArray<string>;
|
|
70
73
|
export declare function settingFields(catalog: ReadonlyArray<PusherSkill>): ReadonlyArray<Pick<SettingEntry, 'skill' | 'key'>>;
|
|
71
74
|
export declare function settingConfigKey(agentId: string | undefined, skill: string, key: string): string;
|
|
72
75
|
export declare function startCredentialPusher(harness: CredentialTarget, engine: CredentialEngine, logger?: CredentialPusherLogger | null): CredentialPusherHandle;
|
|
76
|
+
export {};
|
|
@@ -8,6 +8,7 @@ import ScopeLock from 'scope-lock';
|
|
|
8
8
|
import { credentialSlots } from '@qvac/harness/lib/tools/skills/credential-slots.ts';
|
|
9
9
|
import { errorMessage } from './guards.js';
|
|
10
10
|
const PLAIN_KEYS = ['github_access_token', OBSIDIAN_VAULT_PATH_CREDENTIAL_KEY];
|
|
11
|
+
const PLAIN_KEY = /^[A-Za-z0-9_-]+$/;
|
|
11
12
|
const REFRESH_INTERVAL = 10 * 60 * 1000;
|
|
12
13
|
const MIN_REFRESH_DELAY = 30_000;
|
|
13
14
|
function storeKey(key, agentId) {
|
|
@@ -69,7 +70,7 @@ async function plainEntry(engine, key, agentId) {
|
|
|
69
70
|
}
|
|
70
71
|
export function credentialOwners(catalog) {
|
|
71
72
|
const owners = new Map();
|
|
72
|
-
for (const skill of catalog) {
|
|
73
|
+
for (const skill of trusted(catalog)) {
|
|
73
74
|
for (const key of credentialSlots(skill).flat()) {
|
|
74
75
|
const list = owners.get(key) ?? [];
|
|
75
76
|
if (!list.includes(skill.name)) {
|
|
@@ -80,6 +81,37 @@ export function credentialOwners(catalog) {
|
|
|
80
81
|
}
|
|
81
82
|
return owners;
|
|
82
83
|
}
|
|
84
|
+
function trusted(catalog) {
|
|
85
|
+
return catalog.filter((skill) => skill.origin !== 'overlay');
|
|
86
|
+
}
|
|
87
|
+
export function plainCredentialKeys(catalog, specs) {
|
|
88
|
+
const oauth = new Set(specs.map((spec) => spec.credentialKey));
|
|
89
|
+
const reserved = new Set();
|
|
90
|
+
const declared = new Set(PLAIN_KEYS);
|
|
91
|
+
for (const skill of trusted(catalog)) {
|
|
92
|
+
for (const key of credentialSlots(skill).flat()) {
|
|
93
|
+
declared.add(key);
|
|
94
|
+
}
|
|
95
|
+
for (const route of skill.setup?.routes ?? []) {
|
|
96
|
+
routeKeys(route, route.oauth ? reserved : declared);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const allowed = (key) => PLAIN_KEYS.includes(key) || (!reserved.has(key) && PLAIN_KEY.test(key));
|
|
100
|
+
return [...declared].filter((key) => !oauth.has(key) && allowed(key));
|
|
101
|
+
}
|
|
102
|
+
function routeKeys(route, into) {
|
|
103
|
+
if (route.oauth?.stateKey) {
|
|
104
|
+
into.add(route.oauth.stateKey);
|
|
105
|
+
}
|
|
106
|
+
if (route.credentialKey && !route.oauth) {
|
|
107
|
+
into.add(route.credentialKey);
|
|
108
|
+
}
|
|
109
|
+
for (const field of route.fields ?? []) {
|
|
110
|
+
if (route.oauth || field.secret === true) {
|
|
111
|
+
into.add(field.key);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
83
115
|
export function settingFields(catalog) {
|
|
84
116
|
const fields = [];
|
|
85
117
|
for (const skill of catalog) {
|
|
@@ -118,15 +150,14 @@ async function resolveEntry({ mk, failure, read }, { last, owners, logger }) {
|
|
|
118
150
|
}
|
|
119
151
|
}
|
|
120
152
|
async function resolveScope(agentId, resolution) {
|
|
121
|
-
const { engine, specs } = resolution;
|
|
122
|
-
const specKeys = new Set(specs.map((spec) => spec.credentialKey));
|
|
153
|
+
const { engine, specs, plainKeys } = resolution;
|
|
123
154
|
const pending = [
|
|
124
155
|
...specs.map((spec) => ({
|
|
125
156
|
mk: storeKey(spec.credentialKey, agentId),
|
|
126
157
|
failure: `credential resolve failed for ${spec.credentialKey}`,
|
|
127
158
|
read: () => oauthEntry(engine, spec, agentId)
|
|
128
159
|
})),
|
|
129
|
-
...
|
|
160
|
+
...plainKeys.map((key) => ({
|
|
130
161
|
mk: storeKey(key, agentId),
|
|
131
162
|
failure: `credential read failed for ${key}`,
|
|
132
163
|
read: () => plainEntry(engine, key, agentId)
|
|
@@ -192,10 +223,10 @@ export function startCredentialPusher(harness, engine, logger) {
|
|
|
192
223
|
logger?.warn('credential-pusher', `credential watch ended for ${key}`, errorMessage(err));
|
|
193
224
|
});
|
|
194
225
|
};
|
|
195
|
-
const syncWatches = (
|
|
226
|
+
const syncWatches = (pushedKeys, scopes) => {
|
|
196
227
|
if (disposed)
|
|
197
228
|
return;
|
|
198
|
-
const keys = new Set(
|
|
229
|
+
const keys = new Set(pushedKeys);
|
|
199
230
|
const wanted = new Set(scopes.flatMap((agentId) => [...keys].map((key) => scopedKey(agentId, key))));
|
|
200
231
|
for (const [key, stream] of watches) {
|
|
201
232
|
if (wanted.has(key))
|
|
@@ -272,10 +303,11 @@ export function startCredentialPusher(harness, engine, logger) {
|
|
|
272
303
|
}
|
|
273
304
|
const owners = credentialOwners(skills);
|
|
274
305
|
const specs = oauthSpecs(skills);
|
|
306
|
+
const plainKeys = plainCredentialKeys(skills, specs);
|
|
275
307
|
const { meshId, scopes } = await accountScopes(engine);
|
|
276
|
-
syncWatches(specs.map((spec) => spec.credentialKey), scopes);
|
|
308
|
+
syncWatches([...specs.map((spec) => spec.credentialKey), ...plainKeys], scopes);
|
|
277
309
|
syncAgentsWatch(meshId);
|
|
278
|
-
const resolution = { engine, last, owners, specs, logger };
|
|
310
|
+
const resolution = { engine, last, owners, specs, plainKeys, logger };
|
|
279
311
|
const resolved = await Promise.all(scopes.map((agentId) => resolveScope(agentId, resolution)));
|
|
280
312
|
entries.push(...resolved.flat());
|
|
281
313
|
if (disposed) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Supervisor from 'bare-supervisor';
|
|
2
|
+
import type { Transport } from '@qvac/harness/rpc';
|
|
3
|
+
import type { LoggerInterface } from '@qvac/logging';
|
|
4
|
+
import { type AssistantChildOptions } from './assistant-tree.ts';
|
|
5
|
+
import { Core, type CoreOptions } from './core.ts';
|
|
6
|
+
export interface DeviceTreeOptions {
|
|
7
|
+
core: Omit<CoreOptions, 'apiLifecycle'>;
|
|
8
|
+
assistant: Omit<AssistantChildOptions, 'core'>;
|
|
9
|
+
office?: {
|
|
10
|
+
close: () => unknown;
|
|
11
|
+
};
|
|
12
|
+
logger?: LoggerInterface | null;
|
|
13
|
+
}
|
|
14
|
+
export interface DeviceTree {
|
|
15
|
+
supervisor: Supervisor;
|
|
16
|
+
core: Core;
|
|
17
|
+
}
|
|
18
|
+
export declare function deviceTree(transport: Transport, opts: DeviceTreeOptions): DeviceTree;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import Supervisor from 'bare-supervisor';
|
|
2
|
+
import { assistantChild } from './assistant-tree.js';
|
|
3
|
+
import { Core } from './core.js';
|
|
4
|
+
export function deviceTree(transport, opts) {
|
|
5
|
+
const { office, logger = null } = opts;
|
|
6
|
+
const supervisor = new Supervisor();
|
|
7
|
+
const core = new Core(transport, {
|
|
8
|
+
...opts.core,
|
|
9
|
+
apiLifecycle: {
|
|
10
|
+
suspend: () => supervisor.suspend(),
|
|
11
|
+
resume: () => supervisor.resume()
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
if (office) {
|
|
15
|
+
supervisor.add('office', { start: () => office });
|
|
16
|
+
}
|
|
17
|
+
supervisor.add('core', {
|
|
18
|
+
deps: office ? ['office'] : [],
|
|
19
|
+
start: () => core,
|
|
20
|
+
presuspend: (handle) => handle.presuspend(),
|
|
21
|
+
suspend: (handle) => handle.suspend(),
|
|
22
|
+
wakeup: (handle) => handle.wakeup(),
|
|
23
|
+
resume: (handle) => handle.resume()
|
|
24
|
+
});
|
|
25
|
+
supervisor.add('assistant', assistantChild({ logger, ...opts.assistant }));
|
|
26
|
+
for (const event of ['child-died', 'child-restarting', 'stall']) {
|
|
27
|
+
supervisor.on(event, (payload) => logger?.warn('device-tree', event, { ...payload, error: payload.error?.message }));
|
|
28
|
+
}
|
|
29
|
+
supervisor.on('gave-up', ({ name, error }) => logger?.error('device-tree', `${name} gave up`, error?.message));
|
|
30
|
+
supervisor.on('power', (payload) => logger?.info('device-tree', 'power', payload));
|
|
31
|
+
return { supervisor, core };
|
|
32
|
+
}
|
|
@@ -47,10 +47,7 @@ function prioritizeVaultPicker(setup) {
|
|
|
47
47
|
function derivedRoutes(entry) {
|
|
48
48
|
const routes = [];
|
|
49
49
|
for (const key of credentialKeysFor(entry)) {
|
|
50
|
-
|
|
51
|
-
if (route) {
|
|
52
|
-
routes.push(route);
|
|
53
|
-
}
|
|
50
|
+
routes.push(credentialRoute(key));
|
|
54
51
|
}
|
|
55
52
|
const install = installRoute(entry);
|
|
56
53
|
if (install) {
|
|
@@ -79,7 +76,12 @@ function credentialRoute(credentialKey) {
|
|
|
79
76
|
fields: [{ key: credentialKey, label: token.label, secret: true, required: true }]
|
|
80
77
|
};
|
|
81
78
|
}
|
|
82
|
-
return
|
|
79
|
+
return {
|
|
80
|
+
kind: SETUP_ROUTE_KIND.token,
|
|
81
|
+
label: `Enter ${credentialKey}`,
|
|
82
|
+
credentialKey,
|
|
83
|
+
fields: [{ key: credentialKey, label: credentialKey, secret: true, required: true }]
|
|
84
|
+
};
|
|
83
85
|
}
|
|
84
86
|
function installRoute(entry) {
|
|
85
87
|
const steps = entry.metadata.install ?? [];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { LoggerInterface } from '@qvac/logging';
|
|
2
|
+
import type { Capabilities } from '../spec/capabilities.d.ts';
|
|
3
|
+
import type { AssistantChat } from '../spec/hyperschema/types.d.ts';
|
|
4
|
+
type RetentionEngine = Pick<Capabilities, 'configGet' | 'configSet' | 'listChats'>;
|
|
5
|
+
export interface KvCacheRetentionOptions {
|
|
6
|
+
readonly active: () => boolean;
|
|
7
|
+
readonly running: (chatId: string) => boolean;
|
|
8
|
+
readonly deleteChatKvCache: (chatId: string) => Promise<boolean>;
|
|
9
|
+
readonly defaultMs?: number | undefined;
|
|
10
|
+
readonly logger?: LoggerInterface | null;
|
|
11
|
+
readonly now?: () => number;
|
|
12
|
+
}
|
|
13
|
+
interface IdleWindow {
|
|
14
|
+
readonly from: number;
|
|
15
|
+
readonly cutoff: number;
|
|
16
|
+
}
|
|
17
|
+
export declare function kvCacheRetentionMs(value: unknown, defaultMs?: number): number | null;
|
|
18
|
+
export declare function kvCacheSweptKey(meshId: string): string;
|
|
19
|
+
export declare function idleChatIds(chats: ReadonlyArray<AssistantChat>, { from, cutoff }: IdleWindow): string[];
|
|
20
|
+
export declare class KvCacheRetention {
|
|
21
|
+
private readonly _engine;
|
|
22
|
+
private readonly _opts;
|
|
23
|
+
private readonly _now;
|
|
24
|
+
private readonly _queued;
|
|
25
|
+
private _queue;
|
|
26
|
+
private _timer;
|
|
27
|
+
constructor(engine: RetentionEngine, opts: KvCacheRetentionOptions);
|
|
28
|
+
sweep(meshId: string): Promise<void>;
|
|
29
|
+
start(meshIds: () => Iterable<string>): void;
|
|
30
|
+
stop(): void;
|
|
31
|
+
private _sweep;
|
|
32
|
+
private _deleteIdle;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { KV_CACHE_RETENTION_DAYS_DEFAULT, KV_CACHE_RETENTION_KEY } from './constants.js';
|
|
2
|
+
import { errorMessage } from './guards.js';
|
|
3
|
+
import { unref } from './unref.js';
|
|
4
|
+
const DAY_MS = 24 * 60 * 60_000;
|
|
5
|
+
const DEFAULT_MS = KV_CACHE_RETENTION_DAYS_DEFAULT * DAY_MS;
|
|
6
|
+
const SWEEP_TICK_MS = 60 * 60_000;
|
|
7
|
+
export function kvCacheRetentionMs(value, defaultMs = DEFAULT_MS) {
|
|
8
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
9
|
+
return defaultMs > 0 ? defaultMs : null;
|
|
10
|
+
}
|
|
11
|
+
return value > 0 ? value * DAY_MS : null;
|
|
12
|
+
}
|
|
13
|
+
export function kvCacheSweptKey(meshId) {
|
|
14
|
+
return `kvCache.sweptThrough.${meshId}`;
|
|
15
|
+
}
|
|
16
|
+
export function idleChatIds(chats, { from, cutoff }) {
|
|
17
|
+
return chats
|
|
18
|
+
.filter((chat) => {
|
|
19
|
+
const at = chat.lastActivityAt || chat.createdAt;
|
|
20
|
+
return at >= from && at < cutoff;
|
|
21
|
+
})
|
|
22
|
+
.map((chat) => chat.id);
|
|
23
|
+
}
|
|
24
|
+
export class KvCacheRetention {
|
|
25
|
+
_engine;
|
|
26
|
+
_opts;
|
|
27
|
+
_now;
|
|
28
|
+
_queued;
|
|
29
|
+
_queue;
|
|
30
|
+
_timer;
|
|
31
|
+
constructor(engine, opts) {
|
|
32
|
+
this._engine = engine;
|
|
33
|
+
this._opts = opts;
|
|
34
|
+
this._now = opts.now ?? Date.now;
|
|
35
|
+
this._queued = new Set();
|
|
36
|
+
this._queue = Promise.resolve();
|
|
37
|
+
this._timer = null;
|
|
38
|
+
}
|
|
39
|
+
sweep(meshId) {
|
|
40
|
+
if (this._queued.has(meshId)) {
|
|
41
|
+
return this._queue;
|
|
42
|
+
}
|
|
43
|
+
this._queued.add(meshId);
|
|
44
|
+
this._queue = this._queue.then(() => {
|
|
45
|
+
this._queued.delete(meshId);
|
|
46
|
+
return this._sweep(meshId).catch((err) => this._opts.logger?.warn('kv-cache-retention', 'sweep failed', {
|
|
47
|
+
meshId,
|
|
48
|
+
error: errorMessage(err)
|
|
49
|
+
}));
|
|
50
|
+
});
|
|
51
|
+
return this._queue;
|
|
52
|
+
}
|
|
53
|
+
start(meshIds) {
|
|
54
|
+
this._timer = setInterval(() => {
|
|
55
|
+
for (const meshId of meshIds()) {
|
|
56
|
+
void this.sweep(meshId);
|
|
57
|
+
}
|
|
58
|
+
}, SWEEP_TICK_MS);
|
|
59
|
+
unref(this._timer);
|
|
60
|
+
}
|
|
61
|
+
stop() {
|
|
62
|
+
if (this._timer) {
|
|
63
|
+
clearInterval(this._timer);
|
|
64
|
+
}
|
|
65
|
+
this._timer = null;
|
|
66
|
+
}
|
|
67
|
+
async _sweep(meshId) {
|
|
68
|
+
const retention = await this._engine.configGet({ key: KV_CACHE_RETENTION_KEY });
|
|
69
|
+
const retentionMs = kvCacheRetentionMs(retention.value, this._opts.defaultMs);
|
|
70
|
+
if (retentionMs === null || !this._opts.active()) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const markKey = kvCacheSweptKey(meshId);
|
|
74
|
+
const mark = await this._engine.configGet({ key: markKey });
|
|
75
|
+
const from = typeof mark.value === 'number' ? mark.value : 0;
|
|
76
|
+
const cutoff = this._now() - retentionMs;
|
|
77
|
+
if (cutoff <= from) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const { chats } = await this._engine.listChats({ meshId });
|
|
81
|
+
if (await this._deleteIdle(idleChatIds(chats ?? [], { from, cutoff }))) {
|
|
82
|
+
await this._engine.configSet({ key: markKey, value: cutoff });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async _deleteIdle(chatIds) {
|
|
86
|
+
let complete = true;
|
|
87
|
+
for (const chatId of chatIds) {
|
|
88
|
+
if (!this._opts.active())
|
|
89
|
+
return false;
|
|
90
|
+
if (this._opts.running(chatId))
|
|
91
|
+
continue;
|
|
92
|
+
if (!(await this._opts.deleteChatKvCache(chatId))) {
|
|
93
|
+
complete = false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return complete;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -95,9 +95,10 @@ export function registerContentTypes(ns, namespace) {
|
|
|
95
95
|
{ name: 'name', type: 'string', required: true },
|
|
96
96
|
{ name: 'arguments', type: 'json' }
|
|
97
97
|
]);
|
|
98
|
+
const result = namespace === 'assistant' ? { required: true } : {};
|
|
98
99
|
versioned('chunk-content-tool-result', [
|
|
99
100
|
{ name: 'name', type: 'string', required: true },
|
|
100
|
-
{ name: 'result', type: 'json' }
|
|
101
|
+
{ name: 'result', type: 'json', ...result }
|
|
101
102
|
]);
|
|
102
103
|
const attachment = [
|
|
103
104
|
{ name: 'id', type: 'string', required: true },
|
|
@@ -29,7 +29,13 @@ export function registerEngineTypes(ns) {
|
|
|
29
29
|
{ name: 'deviceId', type: 'fixed32' }
|
|
30
30
|
]
|
|
31
31
|
});
|
|
32
|
-
ns.register({
|
|
32
|
+
ns.register({
|
|
33
|
+
name: 'config-value',
|
|
34
|
+
fields: [
|
|
35
|
+
{ name: 'value', type: 'json' },
|
|
36
|
+
{ name: 'falsyValue', type: 'string' }
|
|
37
|
+
]
|
|
38
|
+
});
|
|
33
39
|
ns.register({
|
|
34
40
|
name: 'config-set-request',
|
|
35
41
|
fields: [
|
|
@@ -464,6 +470,15 @@ export function registerEngineTypes(ns) {
|
|
|
464
470
|
{ name: 'writeRootsRequired', type: 'bool' }
|
|
465
471
|
]
|
|
466
472
|
});
|
|
473
|
+
ns.register({
|
|
474
|
+
name: 'custom-model-report-entry',
|
|
475
|
+
fields: [
|
|
476
|
+
{ name: 'name', type: 'string', required: true },
|
|
477
|
+
{ name: 'label', type: 'string', required: true },
|
|
478
|
+
{ name: 'taskType', type: 'string' },
|
|
479
|
+
{ name: 'expectedSize', type: 'uint' }
|
|
480
|
+
]
|
|
481
|
+
});
|
|
467
482
|
ns.register({
|
|
468
483
|
name: 'device',
|
|
469
484
|
fields: [
|
|
@@ -483,7 +498,8 @@ export function registerEngineTypes(ns) {
|
|
|
483
498
|
{ name: 'platform', type: 'string' },
|
|
484
499
|
{ name: 'readySkillNames', type: 'string', array: true },
|
|
485
500
|
{ name: 'toolCatalog', type: '@assistant/tool-report-entry', array: true },
|
|
486
|
-
{ name: 'memberId', type: 'fixed32' }
|
|
501
|
+
{ name: 'memberId', type: 'fixed32' },
|
|
502
|
+
{ name: 'customModels', type: '@assistant/custom-model-report-entry', array: true }
|
|
487
503
|
]
|
|
488
504
|
});
|
|
489
505
|
ns.register({
|
|
@@ -519,7 +535,8 @@ export function registerEngineTypes(ns) {
|
|
|
519
535
|
{ name: 'cachedModelNames', type: 'string', array: true },
|
|
520
536
|
{ name: 'readySkillNames', type: 'string', array: true },
|
|
521
537
|
{ name: 'toolCatalog', type: '@assistant/tool-report-entry', array: true },
|
|
522
|
-
{ name: 'meshId', type: 'string', required: true }
|
|
538
|
+
{ name: 'meshId', type: 'string', required: true },
|
|
539
|
+
{ name: 'customModels', type: '@assistant/custom-model-report-entry', array: true }
|
|
523
540
|
]
|
|
524
541
|
});
|
|
525
542
|
ns.register({
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import fs from 'bare-fs';
|
|
2
2
|
import { spawnSync } from 'bare-subprocess';
|
|
3
|
-
const EXEMPT = {
|
|
3
|
+
const EXEMPT = {
|
|
4
|
+
'@qvac/writer-v1.device': 'add-writer carries a BirthRow or claimableDevice() from lib/core/mesh.ts, never customModels',
|
|
5
|
+
'@qvac/writer-claim-v1.device': 'claimableDevice() in lib/core/mesh.ts sends only the fields the released build decodes',
|
|
6
|
+
'@qvac/open-join-v1.device': 'claimableDevice() in lib/core/mesh.ts, as for the writer claim',
|
|
7
|
+
'@qvac/vouched-join-v1.device': 'deprecated: no build dispatches it, it is only replayed',
|
|
8
|
+
'@qvac/invite-claim-v1.device': 'deprecated: no build dispatches it, it is only replayed',
|
|
9
|
+
'@qvac/recovery-claim-v1.device': 'deprecated: no build dispatches it, it is only replayed'
|
|
10
|
+
};
|
|
4
11
|
export function assertFieldOrder(root, schemaFile, tags) {
|
|
5
12
|
const current = index(JSON.parse(fs.readFileSync(schemaFile, 'utf8')).schema);
|
|
6
13
|
const seen = new Set();
|
package/dist-lib/schema/local.js
CHANGED
|
@@ -8,7 +8,8 @@ export function registerLocalTypes(ns) {
|
|
|
8
8
|
});
|
|
9
9
|
versioned('config', [
|
|
10
10
|
{ name: 'key', type: 'string', required: true },
|
|
11
|
-
{ name: 'value', type: 'json' }
|
|
11
|
+
{ name: 'value', type: 'json' },
|
|
12
|
+
{ name: 'falsyValue', type: 'string' }
|
|
12
13
|
]);
|
|
13
14
|
versioned('mesh-session', [
|
|
14
15
|
{ name: 'deviceId', type: 'buffer', required: true },
|
|
@@ -101,7 +102,8 @@ export function registerLocalTypes(ns) {
|
|
|
101
102
|
{ name: 'key', type: 'buffer', required: true },
|
|
102
103
|
{ name: 'seed', type: 'buffer', required: true },
|
|
103
104
|
{ name: 'creator', type: 'bool' },
|
|
104
|
-
{ name: 'writerSeed', type: 'string' }
|
|
105
|
+
{ name: 'writerSeed', type: 'string' },
|
|
106
|
+
{ name: 'compute', type: 'bool' }
|
|
105
107
|
]);
|
|
106
108
|
versioned('active-mesh', [
|
|
107
109
|
{ name: 'deviceId', type: 'fixed32', required: true },
|
|
@@ -116,7 +118,9 @@ export function registerLocalTypes(ns) {
|
|
|
116
118
|
{ name: 'wasHome', type: 'bool' },
|
|
117
119
|
{ name: 'migratedAt', type: 'uint' },
|
|
118
120
|
{ name: 'compute', type: 'bool' },
|
|
119
|
-
{ name: 'awaitingAdmission', type: 'bool' }
|
|
121
|
+
{ name: 'awaitingAdmission', type: 'bool' },
|
|
122
|
+
{ name: 'bootKey', type: 'fixed32' },
|
|
123
|
+
{ name: 'bootLength', type: 'uint' }
|
|
120
124
|
]);
|
|
121
125
|
versioned('member-proof', [
|
|
122
126
|
{ name: 'meshKey', type: 'fixed32', required: true },
|
package/dist-lib/schema/qvac.js
CHANGED
|
@@ -83,7 +83,8 @@ export function registerQvacTypes(ns) {
|
|
|
83
83
|
{ name: 'capability', type: 'string' },
|
|
84
84
|
{ name: 'capabilityArgs', type: 'json' },
|
|
85
85
|
{ name: 'enhance', type: '@qvac/enhance-mode' },
|
|
86
|
-
{ name: 'sourceId', type: 'string' }
|
|
86
|
+
{ name: 'sourceId', type: 'string' },
|
|
87
|
+
{ name: 'falsyResult', type: 'string' }
|
|
87
88
|
]);
|
|
88
89
|
versioned('chunk-counter', [
|
|
89
90
|
{ name: 'chatId', type: 'string', required: true },
|
|
@@ -117,7 +118,8 @@ export function registerQvacTypes(ns) {
|
|
|
117
118
|
{ name: 'capability', type: 'string' },
|
|
118
119
|
{ name: 'capabilityArgs', type: 'json' },
|
|
119
120
|
{ name: 'enhance', type: '@qvac/enhance-mode' },
|
|
120
|
-
{ name: 'sourceId', type: 'string' }
|
|
121
|
+
{ name: 'sourceId', type: 'string' },
|
|
122
|
+
{ name: 'falsyResult', type: 'string' }
|
|
121
123
|
]);
|
|
122
124
|
versioned('update-chunk-operation', [
|
|
123
125
|
{ name: 'id', type: 'string', required: true },
|
|
@@ -221,6 +223,15 @@ export function registerQvacTypes(ns) {
|
|
|
221
223
|
{ name: 'writeRootsRequired', type: 'bool' }
|
|
222
224
|
]
|
|
223
225
|
});
|
|
226
|
+
ns.register({
|
|
227
|
+
name: 'custom-model-report-entry',
|
|
228
|
+
fields: [
|
|
229
|
+
{ name: 'name', type: 'string', required: true },
|
|
230
|
+
{ name: 'label', type: 'string', required: true },
|
|
231
|
+
{ name: 'taskType', type: 'string' },
|
|
232
|
+
{ name: 'expectedSize', type: 'uint' }
|
|
233
|
+
]
|
|
234
|
+
});
|
|
224
235
|
versioned('device', [
|
|
225
236
|
{ name: 'id', type: 'fixed32', required: true },
|
|
226
237
|
{ name: 'name', type: 'string', required: true },
|
|
@@ -246,7 +257,8 @@ export function registerQvacTypes(ns) {
|
|
|
246
257
|
{ name: 'attestedAt', type: 'uint' },
|
|
247
258
|
{ name: 'claimedMemberId', type: 'fixed32' },
|
|
248
259
|
{ name: 'inviteToken', type: 'fixed32' },
|
|
249
|
-
{ name: 'deviceSignature', type: 'buffer' }
|
|
260
|
+
{ name: 'deviceSignature', type: 'buffer' },
|
|
261
|
+
{ name: 'customModels', type: '@qvac/custom-model-report-entry', array: true }
|
|
250
262
|
]);
|
|
251
263
|
versioned('writer', [
|
|
252
264
|
{ name: 'writerKey', type: 'buffer', required: true },
|
|
@@ -288,7 +300,8 @@ export function registerQvacTypes(ns) {
|
|
|
288
300
|
{ name: 'installedModelNames', type: 'string', array: true },
|
|
289
301
|
{ name: 'cachedModelNames', type: 'string', array: true },
|
|
290
302
|
{ name: 'readySkillNames', type: 'string', array: true },
|
|
291
|
-
{ name: 'toolCatalog', type: '@qvac/tool-report-entry', array: true }
|
|
303
|
+
{ name: 'toolCatalog', type: '@qvac/tool-report-entry', array: true },
|
|
304
|
+
{ name: 'customModels', type: '@qvac/custom-model-report-entry', array: true }
|
|
292
305
|
]);
|
|
293
306
|
versioned('put-agent-operation', [{ name: 'agent', type: '@qvac/agent', required: true }]);
|
|
294
307
|
versioned('put-chat-operation', [{ name: 'chat', type: '@qvac/chat', required: true }]);
|
|
@@ -587,6 +600,7 @@ export function registerQvacTypes(ns) {
|
|
|
587
600
|
{ name: 'meshKey', type: 'fixed32', required: true },
|
|
588
601
|
{ name: 'seed', type: 'fixed32', required: true }
|
|
589
602
|
]);
|
|
603
|
+
versioned('reindex-chat-chunks-operation', [{ name: 'chatId', type: 'string', required: true }]);
|
|
590
604
|
}
|
|
591
605
|
export function registerQvacCollections(dbns, helpersPath) {
|
|
592
606
|
dbns.require(helpersPath);
|
|
@@ -918,6 +932,7 @@ export function registerQvacCollections(dbns, helpersPath) {
|
|
|
918
932
|
dbns.collections.register({ name: 'purged-chats', schema: '@qvac/purged-chat', key: ['chatId'] });
|
|
919
933
|
dbns.collections.register({ name: 'mesh-names', schema: '@qvac/mesh-name', key: ['id'] });
|
|
920
934
|
dbns.collections.register({ name: 'mesh-seeds', schema: '@qvac/mesh-seed', key: ['meshKey'] });
|
|
935
|
+
dbns.collections.register({ name: 'chat-chunks', schema: '@qvac/chunk', key: ['chatId', 'seq'] });
|
|
921
936
|
}
|
|
922
937
|
export function registerQvacDispatch(ds) {
|
|
923
938
|
ds.register({ name: 'append-chunk', requestType: '@qvac/append-chunk-operation' });
|
|
@@ -986,4 +1001,8 @@ export function registerQvacDispatch(ds) {
|
|
|
986
1001
|
ds.register({ name: 'name-mesh', requestType: '@qvac/name-mesh-operation' });
|
|
987
1002
|
ds.register({ name: 'open-join', requestType: '@qvac/open-join' });
|
|
988
1003
|
ds.register({ name: 'put-mesh-seed', requestType: '@qvac/mesh-seed' });
|
|
1004
|
+
ds.register({
|
|
1005
|
+
name: 'reindex-chat-chunks',
|
|
1006
|
+
requestType: '@qvac/reindex-chat-chunks-operation'
|
|
1007
|
+
});
|
|
989
1008
|
}
|