@qvac/core 1.0.0-rc.3 → 1.0.0-rc.6

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.
Files changed (135) hide show
  1. package/CHANGELOG.md +147 -36
  2. package/README.md +55 -4
  3. package/dist-lib/index.d.ts +2 -1
  4. package/dist-lib/lib/api/agents.d.ts +2 -1
  5. package/dist-lib/lib/api/agents.js +5 -1
  6. package/dist-lib/lib/api/app-config.d.ts +3 -0
  7. package/dist-lib/lib/api/app-config.js +20 -0
  8. package/dist-lib/lib/api/approval-rules.d.ts +1 -1
  9. package/dist-lib/lib/api/approval-rules.js +5 -1
  10. package/dist-lib/lib/api/config.d.ts +6 -2
  11. package/dist-lib/lib/api/config.js +9 -5
  12. package/dist-lib/lib/api/device-routes.d.ts +1 -1
  13. package/dist-lib/lib/api/device-routes.js +3 -1
  14. package/dist-lib/lib/api/index.d.ts +12 -2
  15. package/dist-lib/lib/api/index.js +8 -2
  16. package/dist-lib/lib/api/projects.js +3 -4
  17. package/dist-lib/lib/api/rag.js +5 -5
  18. package/dist-lib/lib/api/served.d.ts +2 -2
  19. package/dist-lib/lib/api/served.js +24 -1
  20. package/dist-lib/lib/assistant/harness.d.ts +3 -0
  21. package/dist-lib/lib/assistant/history.js +14 -2
  22. package/dist-lib/lib/assistant/message.d.ts +1 -0
  23. package/dist-lib/lib/assistant/model-round.d.ts +3 -0
  24. package/dist-lib/lib/assistant/model-round.js +18 -4
  25. package/dist-lib/lib/assistant/round-host.d.ts +2 -0
  26. package/dist-lib/lib/assistant/round-host.js +8 -0
  27. package/dist-lib/lib/assistant-tree.d.ts +2 -0
  28. package/dist-lib/lib/assistant-tree.js +4 -2
  29. package/dist-lib/lib/assistant.d.ts +12 -1
  30. package/dist-lib/lib/assistant.js +131 -15
  31. package/dist-lib/lib/client.js +4 -1
  32. package/dist-lib/lib/core/agent-copies.js +9 -2
  33. package/dist-lib/lib/core/agent-hosting.js +9 -4
  34. package/dist-lib/lib/core/agent.js +3 -1
  35. package/dist-lib/lib/core/approval-rules.d.ts +5 -1
  36. package/dist-lib/lib/core/approval-rules.js +16 -1
  37. package/dist-lib/lib/core/chat-copy.d.ts +1 -0
  38. package/dist-lib/lib/core/chat-copy.js +13 -2
  39. package/dist-lib/lib/core/chat.d.ts +0 -1
  40. package/dist-lib/lib/core/chat.js +0 -3
  41. package/dist-lib/lib/core/chunk.js +4 -3
  42. package/dist-lib/lib/core/collections.d.ts +7 -7
  43. package/dist-lib/lib/core/collections.js +7 -7
  44. package/dist-lib/lib/core/config-value.d.ts +1 -0
  45. package/dist-lib/lib/core/config-value.js +1 -0
  46. package/dist-lib/lib/core/contract/project-device-keys.d.ts +4 -2
  47. package/dist-lib/lib/core/contract/project-device-keys.js +12 -12
  48. package/dist-lib/lib/core/contract/project-host-keys.d.ts +5 -3
  49. package/dist-lib/lib/core/contract/project-host-keys.js +22 -11
  50. package/dist-lib/lib/core/contract/projects.d.ts +4 -2
  51. package/dist-lib/lib/core/contract/projects.js +29 -17
  52. package/dist-lib/lib/core/contract/workspace.js +2 -2
  53. package/dist-lib/lib/core/deleted-agent-runs.d.ts +8 -0
  54. package/dist-lib/lib/core/deleted-agent-runs.js +57 -0
  55. package/dist-lib/lib/core/files/index.d.ts +1 -1
  56. package/dist-lib/lib/core/files/index.js +4 -2
  57. package/dist-lib/lib/core/helpers/index.d.ts +1 -1
  58. package/dist-lib/lib/core/helpers/index.js +2 -2
  59. package/dist-lib/lib/core/local/index.d.ts +6 -0
  60. package/dist-lib/lib/core/local/index.js +14 -0
  61. package/dist-lib/lib/core/mesh.d.ts +2 -1
  62. package/dist-lib/lib/core/mesh.js +7 -5
  63. package/dist-lib/lib/core/project-keys.d.ts +5 -2
  64. package/dist-lib/lib/core/project-keys.js +15 -6
  65. package/dist-lib/lib/core/skill-secrets.d.ts +3 -2
  66. package/dist-lib/lib/core/skill-secrets.js +4 -1
  67. package/dist-lib/lib/core/sync/index.js +18 -6
  68. package/dist-lib/lib/core/vault-managed-skills.d.ts +18 -0
  69. package/dist-lib/lib/core/vault-managed-skills.js +105 -0
  70. package/dist-lib/lib/core.d.ts +10 -1
  71. package/dist-lib/lib/core.js +165 -31
  72. package/dist-lib/lib/errors.d.ts +8 -0
  73. package/dist-lib/lib/errors.js +8 -0
  74. package/dist-lib/lib/kv-cache-ledger.d.ts +22 -0
  75. package/dist-lib/lib/kv-cache-ledger.js +72 -0
  76. package/dist-lib/lib/kv-cache-retention.d.ts +1 -0
  77. package/dist-lib/lib/kv-cache-retention.js +5 -2
  78. package/dist-lib/lib/mesh-scoped-engine.js +1 -0
  79. package/dist-lib/lib/model-memory-cap.d.ts +3 -0
  80. package/dist-lib/lib/model-memory-cap.js +15 -6
  81. package/dist-lib/lib/run-replay.d.ts +3 -2
  82. package/dist-lib/lib/run-replay.js +16 -5
  83. package/dist-lib/lib/run-transcript.js +1 -1
  84. package/dist-lib/schema/config.d.ts +1 -1
  85. package/dist-lib/schema/config.js +1 -1
  86. package/dist-lib/schema/engine.js +87 -2
  87. package/dist-lib/schema/qvac.js +66 -3
  88. package/dist-lib/spec/bind.js +15 -0
  89. package/dist-lib/spec/calls.js +5 -0
  90. package/dist-lib/spec/capabilities.d.ts +10 -0
  91. package/dist-lib/spec/config/hyperconf/index.js +1 -1
  92. package/dist-lib/spec/hrpc/hrpc.json +65 -0
  93. package/dist-lib/spec/hrpc/index.js +63 -3
  94. package/dist-lib/spec/hrpc/messages.js +1302 -993
  95. package/dist-lib/spec/hyperschema/index.js +1302 -993
  96. package/dist-lib/spec/hyperschema/schema.json +227 -0
  97. package/dist-lib/spec/hyperschema/types.d.ts +45 -0
  98. package/dist-lib/spec/mesh/hyperdb/db.json +110 -0
  99. package/dist-lib/spec/mesh/hyperdb/index.js +498 -2
  100. package/dist-lib/spec/mesh/hyperdb/messages.js +1385 -892
  101. package/dist-lib/spec/mesh/hyperdispatch/messages.js +561 -301
  102. package/dist-lib/spec/mesh/hyperschema/index.js +561 -301
  103. package/dist-lib/spec/mesh/hyperschema/schema.json +343 -178
  104. package/dist-lib/spec/mesh/hyperschema/types.d.ts +40 -1
  105. package/package.json +34 -18
  106. package/tui/README.md +190 -0
  107. package/tui/app.mjs +8247 -0
  108. package/tui/boot.mjs +159 -0
  109. package/tui/index.mjs +89 -0
  110. package/tui/lib/boot-timing.mjs +41 -0
  111. package/tui/lib/busy-words.mjs +116 -0
  112. package/tui/lib/connect-sheet.mjs +350 -0
  113. package/tui/lib/device-target.mjs +64 -0
  114. package/tui/lib/export.mjs +194 -0
  115. package/tui/lib/folders-command.mjs +84 -0
  116. package/tui/lib/fork-command.mjs +43 -0
  117. package/tui/lib/knowledge-command.mjs +190 -0
  118. package/tui/lib/knowledge-import.mjs +153 -0
  119. package/tui/lib/local-path.mjs +21 -0
  120. package/tui/lib/move-command.mjs +17 -0
  121. package/tui/lib/render.mjs +225 -0
  122. package/tui/lib/save-file.mjs +88 -0
  123. package/tui/lib/select.mjs +81 -0
  124. package/tui/lib/selection.mjs +18 -0
  125. package/tui/lib/setup.mjs +135 -0
  126. package/tui/lib/sidebar.mjs +63 -0
  127. package/tui/lib/skill-connect.mjs +145 -0
  128. package/tui/lib/splash-art.mjs +107 -0
  129. package/tui/lib/splash.mjs +18 -0
  130. package/tui/lib/upload-frames.mjs +9 -0
  131. package/tui/lib/usage.mjs +59 -0
  132. package/tui/lib/wrap.mjs +143 -0
  133. package/tui/main.mjs +279 -0
  134. package/tui/plugins.mjs +158 -0
  135. package/worker/assistant-sidecar.mjs +1 -0
@@ -41,13 +41,14 @@ export function createRagApi(pool, { index, embedder, effectiveCtxSize = null })
41
41
  const kept = (id) => !off.has('chat') || scopeIds.has(id);
42
42
  const chatKnowledge = async () => (await mesh.files.listKnowledge(chatId)).filter((row) => kept(row.id));
43
43
  const chatFiles = async () => (await mesh.files.status(chatId)).files.filter((file) => kept(file.fileId));
44
- if (!immediate) {
45
- await mesh.files.indexingHere(chatId);
44
+ const indexingHere = (files) => files.filter((file) => scopeIds.has(file.fileId) && mesh.files.indexesHere(file)).length;
45
+ if (!immediate && scopeIds.size > 0) {
46
+ await mesh.files.indexingHere(chatId, [...scopeIds]);
46
47
  }
47
48
  const chatRows = await chatKnowledge();
48
49
  const initialFiles = await chatFiles();
49
50
  pendingFiles = pendingFileNames(initialFiles);
50
- chatFilesIndexingHere = initialFiles.filter((file) => mesh.files.indexesHere(file)).length;
51
+ chatFilesIndexingHere = indexingHere(initialFiles);
51
52
  const scopeRows = chatRows.filter((row) => scopeIds.has(row.id));
52
53
  const project = off.has('project')
53
54
  ? null
@@ -63,10 +64,9 @@ export function createRagApi(pool, { index, embedder, effectiveCtxSize = null })
63
64
  });
64
65
  if (fullText) {
65
66
  const read = new Set(scopeRows.map((row) => row.id));
66
- const unread = initialFiles.filter((file) => !read.has(file.fileId));
67
67
  return respond({
68
68
  pendingFiles: pendingFileNames(initialFiles, read),
69
- chatFilesIndexingHere: unread.filter((file) => mesh.files.indexesHere(file)).length,
69
+ chatFilesIndexingHere: 0,
70
70
  searchedCount: fullText.length,
71
71
  indexEmpty: false,
72
72
  hasKnowledge: true,
@@ -3,11 +3,11 @@ import type { AssistantMeshList } from '../../spec/hyperschema/types.d.ts';
3
3
  import type { CapabilityHandlers } from '../../spec/capabilities.d.ts';
4
4
  import { type MeshPool } from './current-mesh.ts';
5
5
  import type { MeshStatusSource } from './mesh.ts';
6
- export declare const SERVED_ROUTES: readonly ["listMeshes", "meshesWatch", "chatsWatch", "listChunks", "chunksWatch", "appendChunk", "modelRequestsWatch", "takeModelRequest", "settleModelRequest"];
6
+ export declare const SERVED_ROUTES: readonly ["listMeshes", "meshesWatch", "listChats", "chatsWatch", "listChunks", "chunksWatch", "appendChunk", "modelRequestsWatch", "takeModelRequest", "settleModelRequest"];
7
7
  export type ServedRoutes = Pick<CapabilityHandlers, (typeof SERVED_ROUTES)[number]>;
8
8
  export interface ServedOptions {
9
9
  readonly pool: MeshPool;
10
- readonly local: Partial<Pick<CapabilityHandlers, 'chatsWatch' | 'appendChunk'>>;
10
+ readonly local: Partial<Pick<CapabilityHandlers, 'listChats' | 'chatsWatch' | 'appendChunk'>>;
11
11
  readonly foreign: (meshId: string) => boolean;
12
12
  readonly status: Pick<MeshStatusSource, 'watch' | 'unwatch'>;
13
13
  readonly list: () => Promise<AssistantMeshList>;
@@ -1,3 +1,4 @@
1
+ import { lastActivity } from '../core/chat.js';
1
2
  import { readChunk } from '../core/chunk.js';
2
3
  import { listModelRequests } from '../core/model-requests.js';
3
4
  import { servedChats } from '../core/public-mesh.js';
@@ -7,6 +8,7 @@ import { watchable } from './watchable.js';
7
8
  export const SERVED_ROUTES = [
8
9
  'listMeshes',
9
10
  'meshesWatch',
11
+ 'listChats',
10
12
  'chatsWatch',
11
13
  'listChunks',
12
14
  'chunksWatch',
@@ -30,13 +32,18 @@ export function createServedApi({ pool, local, foreign, status, list, deviceId,
30
32
  const live = await listModelRequests(mesh);
31
33
  return { chunks: live.filter((round) => chats.has(round.chatId)).map(readChunk) };
32
34
  }, { name: 'modelRequestsWatch', log });
33
- const { chatsWatch: ownChats = chatsWatch, appendChunk: ownAppend = chunks.appendChunk } = local;
35
+ const listChats = async ({ meshId }) => {
36
+ const mesh = await requireMesh(pool, meshId, { wide: true });
37
+ return { chats: deviceId ? await servedListing(mesh, deviceId) : [] };
38
+ };
39
+ const { listChats: ownList = listChats, chatsWatch: ownChats = chatsWatch, appendChunk: ownAppend = chunks.appendChunk } = local;
34
40
  return {
35
41
  listMeshes: list,
36
42
  meshesWatch: watchable(() => status, list, {
37
43
  name: 'meshesWatch',
38
44
  log
39
45
  }),
46
+ listChats: (request) => (foreign(request.meshId) ? listChats(request) : ownList(request)),
40
47
  chatsWatch: (request) => (foreign(request.meshId) ? chatsWatch(request) : ownChats(request)),
41
48
  listChunks: chunks.listChunks,
42
49
  chunksWatch: chunks.chunksWatch,
@@ -46,3 +53,19 @@ export function createServedApi({ pool, local, foreign, status, list, deviceId,
46
53
  settleModelRequest: chunks.settleModelRequest
47
54
  };
48
55
  }
56
+ async function servedListing(mesh, deviceId) {
57
+ const snap = mesh.view.snapshot();
58
+ try {
59
+ const activity = await lastActivity(snap);
60
+ return (await servedChats(mesh, deviceId)).map(({ id, agentId, title, createdAt }) => ({
61
+ id,
62
+ agentId,
63
+ title,
64
+ createdAt,
65
+ lastActivityAt: activity.get(id) || createdAt
66
+ }));
67
+ }
68
+ finally {
69
+ await snap.close();
70
+ }
71
+ }
@@ -128,6 +128,9 @@ export interface Harness {
128
128
  approve?: (call: ApprovalCall) => Promise<boolean>;
129
129
  attach?: (input: AttachInput) => Promise<AssistantChunkContentAttachment>;
130
130
  fetchAttachment?: (query: FetchAttachmentOptions) => Promise<FetchedAttachment | AttachmentMeta | null>;
131
+ showImage?: (query: {
132
+ attachmentId: string;
133
+ }) => Promise<string | null>;
131
134
  progress?: (update: ImageProgress | null) => void;
132
135
  input?: AsyncIterable<RunInput>;
133
136
  signal?: AbortSignal;
@@ -77,6 +77,12 @@ export function historyFromChunks(chunks, stale = {}, { sentRuns = new Map(), as
77
77
  }
78
78
  }
79
79
  const byMessage = groupAttachmentsByMessage(attachments, userMessages);
80
+ const byId = new Map();
81
+ for (const { attachment } of attachments) {
82
+ if (attachment && !attachment.deletedAt) {
83
+ byId.set(attachment.id, attachment);
84
+ }
85
+ }
80
86
  const digests = derivedAttachments(chunks);
81
87
  const steered = steeredQuestions(source, sentRuns);
82
88
  const history = [];
@@ -104,7 +110,7 @@ export function historyFromChunks(chunks, stale = {}, { sentRuns = new Map(), as
104
110
  }
105
111
  const sent = live ? sentRuns.get(live) : undefined;
106
112
  if (sent) {
107
- const replayed = sent.map((message) => ({ ...message }));
113
+ const replayed = sent.map((message) => shownAgain(message, byId));
108
114
  history.push(...replayed);
109
115
  for (const message of [...replayed, turn]) {
110
116
  kept.add(message);
@@ -213,6 +219,10 @@ export function historyFromChunks(chunks, stale = {}, { sentRuns = new Map(), as
213
219
  }
214
220
  return history.filter((turn) => turn.role === 'user' || turn.content.length > 0 || kept.has(turn));
215
221
  }
222
+ function shownAgain({ imageIds, ...turn }, byId) {
223
+ const images = (imageIds ?? []).flatMap((id) => byId.get(id) ?? []);
224
+ return images.length ? { ...turn, images } : turn;
225
+ }
216
226
  function steeredQuestions(chunks, sentRuns) {
217
227
  const into = new Map();
218
228
  for (const chunk of chunks) {
@@ -262,7 +272,9 @@ export function replayFromChunks(rounds) {
262
272
  }
263
273
  const turns = chunk.modelRequest?.state === 'done' ? chunk.modelRequest.toolTurns : undefined;
264
274
  if (Array.isArray(turns)) {
265
- sentRuns.set(chunk.runId, turns.filter(isChatMessage).map(({ role, content }) => ({ role, content })));
275
+ sentRuns.set(chunk.runId, turns
276
+ .filter(isChatMessage)
277
+ .map(({ role, content, imageIds }) => imageIds ? { role, content, imageIds } : { role, content }));
266
278
  }
267
279
  }
268
280
  return { sentRuns, readRuns };
@@ -9,6 +9,7 @@ export interface ChatMessage {
9
9
  attachments?: {
10
10
  path: string;
11
11
  }[];
12
+ imageIds?: string[];
12
13
  images?: AttachmentRef[];
13
14
  audioAttachments?: AttachmentRef[];
14
15
  videos?: VideoRef[];
@@ -12,6 +12,7 @@ export interface MediaRef {
12
12
  readonly frame?: number | undefined;
13
13
  readonly frames?: number | undefined;
14
14
  }
15
+ export declare function wholeImageId(ref: MediaRef | undefined): string | undefined;
15
16
  export interface MediaSource {
16
17
  readonly ref: MediaRef;
17
18
  readonly attachment: AttachmentRef;
@@ -59,6 +60,7 @@ export declare class OwnerRounds {
59
60
  ranHere(round: number | undefined): boolean;
60
61
  retook(): boolean;
61
62
  echoed(type: string, text: string): boolean;
63
+ retire(): Promise<void>;
62
64
  private _round;
63
65
  probe({ kind, prompt, modelId, responseFormat, signal }: Probe): Promise<string>;
64
66
  private _probed;
@@ -68,6 +70,7 @@ export declare class OwnerRounds {
68
70
  private _switchedTo;
69
71
  private _sendContext;
70
72
  private _options;
73
+ private _namedImages;
71
74
  private _media;
72
75
  private _knownSets;
73
76
  private _readKnownSets;
@@ -1,5 +1,5 @@
1
1
  import b4a from 'b4a';
2
- import { ToolSets } from '@qvac/harness';
2
+ import { renderedTools, ToolSets } from '@qvac/harness';
3
3
  import { AbortedError } from '@qvac/harness/race-abort';
4
4
  import * as z from 'zod';
5
5
  import { errorMessage, isRecord } from '../guards.js';
@@ -9,6 +9,9 @@ import { PdfBoundsSchema } from './pdf-pages.js';
9
9
  import { isProbeRound, PROBE_KINDS } from '../probe-rounds.js';
10
10
  const message = z.custom((value) => isRecord(value) && typeof value.role === 'string' && typeof value.content === 'string');
11
11
  const record = () => z.custom((value) => isRecord(value));
12
+ export function wholeImageId(ref) {
13
+ return ref && ref.page === undefined && ref.frame === undefined ? ref.id : undefined;
14
+ }
12
15
  const mediaRef = z.object({
13
16
  id: z.string(),
14
17
  page: z.number().optional(),
@@ -70,6 +73,13 @@ export class OwnerRounds {
70
73
  this._echoes.splice(at, 1);
71
74
  return true;
72
75
  }
76
+ async retire() {
77
+ const { engine, chatId, runId } = this._opts;
78
+ const { chunks } = await engine.listChunks({ chatId, type: 'model-request' });
79
+ const live = (chunks ?? []).filter((chunk) => chunk.runId === runId &&
80
+ (chunk.modelRequest?.state === 'open' || chunk.modelRequest?.state === 'taken'));
81
+ await Promise.all(live.map((chunk) => engine.cancelModelRequest({ chunkId: chunk.id }).catch(noop)));
82
+ }
73
83
  async _round(request, io) {
74
84
  if (io.signal.aborted)
75
85
  throw new AbortedError();
@@ -83,7 +93,7 @@ export class OwnerRounds {
83
93
  round: request.round,
84
94
  cacheKey: request.cacheKey,
85
95
  promptPrefix: request.promptPrefix,
86
- toolTurns: request.history.slice(input),
96
+ toolTurns: request.history.slice(input).map((turn) => this._namedImages(turn)),
87
97
  options: await this._options(request, system)
88
98
  };
89
99
  const agentId = (await this._switchedTo()) ?? this._opts.agentId;
@@ -94,7 +104,7 @@ export class OwnerRounds {
94
104
  round,
95
105
  modelId,
96
106
  messages: history,
97
- tools,
107
+ tools: renderedTools(tools, history),
98
108
  generationParams,
99
109
  responseFormat,
100
110
  toolDialect,
@@ -254,6 +264,10 @@ export class OwnerRounds {
254
264
  }
255
265
  return options;
256
266
  }
267
+ _namedImages(turn) {
268
+ const imageIds = (turn.attachments ?? []).flatMap(({ path }) => wholeImageId(this._opts.media?.(path)) ?? []);
269
+ return imageIds.length ? { ...turn, imageIds } : turn;
270
+ }
257
271
  _media(history) {
258
272
  const media = history.flatMap((turn, at) => {
259
273
  const refs = (turn.attachments ?? []).flatMap(({ path }) => this._opts.media?.(path) ?? []);
@@ -510,7 +524,7 @@ export async function servedRequest(engine, round, media) {
510
524
  const history = [
511
525
  ...(system === null ? [] : [{ role: 'system', content: system }]),
512
526
  ...input,
513
- ...toolTurns.data.map(({ attachments: _owners, ...turn }) => turn)
527
+ ...toolTurns.data.map(({ attachments: _owners, imageIds: _named, ...turn }) => turn)
514
528
  ];
515
529
  await showMedia(history, {
516
530
  all,
@@ -9,6 +9,7 @@ export interface RoundHostOptions {
9
9
  readonly serve: NonNullable<Harness['serveModelRound']>;
10
10
  readonly deviceId: () => Buffer;
11
11
  readonly media?: RoundMedia | null;
12
+ readonly built?: (meshId: string, chatId: string) => void;
12
13
  readonly log?: LoggerInterface | null;
13
14
  }
14
15
  export interface RoundMedia {
@@ -28,6 +29,7 @@ export declare class RoundHost {
28
29
  constructor(opts: RoundHostOptions);
29
30
  follow(meshId: string, frames: WatchStream<AssistantChunkList>): Promise<void>;
30
31
  left(chatId: string, agentId: string): string[];
32
+ holds(chatId: string): boolean;
31
33
  stop(): void;
32
34
  private _reconcile;
33
35
  private _pick;
@@ -41,6 +41,10 @@ export class RoundHost {
41
41
  this._built.delete(at);
42
42
  return keys;
43
43
  }
44
+ holds(chatId) {
45
+ const base = chatKvCacheKey(chatId);
46
+ return [...this._keys.keys()].some((key) => key.startsWith(`${base}/`));
47
+ }
44
48
  stop() {
45
49
  for (const { controller } of this._serving.values()) {
46
50
  controller.abort(LEFT);
@@ -78,6 +82,7 @@ export class RoundHost {
78
82
  }
79
83
  _serve(meshId, round) {
80
84
  const serving = {
85
+ meshId,
81
86
  controller: new AbortController(),
82
87
  taken: false,
83
88
  takenAt: 0
@@ -132,6 +137,9 @@ export class RoundHost {
132
137
  return this._probe(engine, { round, request, serving });
133
138
  }
134
139
  const key = this._claimKey(round, request.cacheKey);
140
+ if (key && round.chatId) {
141
+ this._opts.built?.(serving.meshId, round.chatId);
142
+ }
135
143
  const transcript = new RunTranscript(engine, {
136
144
  chatId: round.chatId,
137
145
  runId: request.runId,
@@ -24,6 +24,7 @@ export interface AssistantTreeOptions {
24
24
  imageCacheDir?: string;
25
25
  inferenceCallsDir?: string;
26
26
  runReplayDir?: string;
27
+ kvCacheChatsDir?: string;
27
28
  imageCacheMaxBytes?: number;
28
29
  imageCacheMaxAgeMs?: number;
29
30
  kvCacheRetentionMs?: number;
@@ -42,6 +43,7 @@ export interface AssistantChildOptions {
42
43
  imageCacheDir?: string;
43
44
  inferenceCallsDir?: string;
44
45
  runReplayDir?: string;
46
+ kvCacheChatsDir?: string;
45
47
  imageCacheMaxBytes?: number;
46
48
  imageCacheMaxAgeMs?: number;
47
49
  kvCacheRetentionMs?: number;
@@ -8,7 +8,7 @@ import { startModelMemoryCap } from './model-memory-cap.js';
8
8
  import { startDownloadsAllowedPusher } from './downloads-allowed-pusher.js';
9
9
  import { duplexPair } from '@qvac/harness/transport';
10
10
  export function assistantTree(opts) {
11
- const { core, harness, logger = null, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, kvCacheRetentionMs, embedder, extractors, onHarness, platform, preloadCurrentAgentModel, fakeModels = false } = opts;
11
+ const { core, harness, logger = null, imageCacheDir, inferenceCallsDir, runReplayDir, kvCacheChatsDir, imageCacheMaxBytes, imageCacheMaxAgeMs, kvCacheRetentionMs, embedder, extractors, onHarness, platform, preloadCurrentAgentModel, fakeModels = false } = opts;
12
12
  const sup = new Supervisor();
13
13
  const logged = ['child-died', 'child-restarting', 'child-ready', 'gave-up', 'stall'];
14
14
  for (const event of logged) {
@@ -75,6 +75,7 @@ export function assistantTree(opts) {
75
75
  imageCacheDir,
76
76
  inferenceCallsDir,
77
77
  runReplayDir,
78
+ kvCacheChatsDir,
78
79
  imageCacheMaxBytes,
79
80
  imageCacheMaxAgeMs,
80
81
  kvCacheRetentionMs,
@@ -239,7 +240,7 @@ export function assistantTree(opts) {
239
240
  return sup;
240
241
  }
241
242
  export function assistantChild(opts) {
242
- const { harness, core = 'core', logger = null, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, kvCacheRetentionMs, embedder, extractors, onHarness, preloadCurrentAgentModel, fakeModels, ...spec } = opts;
243
+ const { harness, core = 'core', logger = null, imageCacheDir, inferenceCallsDir, runReplayDir, kvCacheChatsDir, imageCacheMaxBytes, imageCacheMaxAgeMs, kvCacheRetentionMs, embedder, extractors, onHarness, preloadCurrentAgentModel, fakeModels, ...spec } = opts;
243
244
  return {
244
245
  ...spec,
245
246
  deps: [core],
@@ -251,6 +252,7 @@ export function assistantChild(opts) {
251
252
  imageCacheDir,
252
253
  inferenceCallsDir,
253
254
  runReplayDir,
255
+ kvCacheChatsDir,
254
256
  imageCacheMaxBytes,
255
257
  imageCacheMaxAgeMs,
256
258
  kvCacheRetentionMs,
@@ -25,6 +25,7 @@ export interface AssistantOptions {
25
25
  imageCacheDir?: string;
26
26
  inferenceCallsDir?: string;
27
27
  runReplayDir?: string;
28
+ kvCacheChatsDir?: string;
28
29
  imageCacheMaxBytes?: number;
29
30
  imageCacheMaxAgeMs?: number;
30
31
  kvCacheRetentionMs?: number;
@@ -75,6 +76,7 @@ export declare class QvacAssistant extends ReadyResource {
75
76
  private _reconciling;
76
77
  private readonly _onlineBoot;
77
78
  private readonly _accountSeen;
79
+ private readonly _meshesSeen;
78
80
  private _capability;
79
81
  private _downloads;
80
82
  private _state;
@@ -101,6 +103,8 @@ export declare class QvacAssistant extends ReadyResource {
101
103
  private readonly _runReplay;
102
104
  private readonly _roundHost;
103
105
  private readonly _kvRetention;
106
+ private readonly _kvLedger;
107
+ private _orphanSweep;
104
108
  private readonly _lifecycle;
105
109
  private readonly _suggesting;
106
110
  private readonly _audioTranscripts;
@@ -115,7 +119,7 @@ export declare class QvacAssistant extends ReadyResource {
115
119
  private readonly _modelCatalog;
116
120
  private readonly _onHarnessStatus;
117
121
  private readonly _onModelCatalogEvent;
118
- constructor(engine: Capabilities, harness: Harness, { logger, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, kvCacheRetentionMs, downloadRetryMs, platform, preloadCurrentAgentModel, drives, blobReadTimeoutMs, runIdleTimeoutMs, modelReloadDelayMs, pdfRasterizer: pdfRasterizerOption }?: AssistantOptions);
122
+ constructor(engine: Capabilities, harness: Harness, { logger, imageCacheDir, inferenceCallsDir, runReplayDir, kvCacheChatsDir, imageCacheMaxBytes, imageCacheMaxAgeMs, kvCacheRetentionMs, downloadRetryMs, platform, preloadCurrentAgentModel, drives, blobReadTimeoutMs, runIdleTimeoutMs, modelReloadDelayMs, pdfRasterizer: pdfRasterizerOption }?: AssistantOptions);
119
123
  private _requireDeviceId;
120
124
  _open(): Promise<void>;
121
125
  private _triggerModelWarm;
@@ -165,6 +169,7 @@ export declare class QvacAssistant extends ReadyResource {
165
169
  private _unloadModel;
166
170
  modelUsers(name: string): Promise<AssistantModelUsers>;
167
171
  private _meshModelUsers;
172
+ private _runModel;
168
173
  private _runnableHost;
169
174
  notifyModelCatalog(): void;
170
175
  cachedModelsChanged(): void;
@@ -184,6 +189,11 @@ export declare class QvacAssistant extends ReadyResource {
184
189
  deleteChatKvCache(chatId: string): Promise<AssistantKvCacheDeletionResponse>;
185
190
  private _reclaimChatKvCache;
186
191
  clearKvCache(): Promise<AssistantKvCacheDeletionResponse>;
192
+ private _recordKvCache;
193
+ private _reclaimOrphanedKvCaches;
194
+ private _sweepOrphanedKvCaches;
195
+ private _knownChats;
196
+ private _kvCacheInUse;
187
197
  private _clearPreReplayCaches;
188
198
  private _inspectCall;
189
199
  private _inspectRound;
@@ -236,6 +246,7 @@ export declare class QvacAssistant extends ReadyResource {
236
246
  private _openVideo;
237
247
  private _hearVideo;
238
248
  private _hydrateImages;
249
+ private _showImage;
239
250
  private _hydrateTurnImages;
240
251
  private _servedMedia;
241
252
  private _servedFile;