@qvac/core 0.11.1 → 0.11.3

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 (66) hide show
  1. package/CHANGELOG.md +88 -1
  2. package/README.md +19 -16
  3. package/dist-lib/lib/api/chunks.js +4 -2
  4. package/dist-lib/lib/api/rag.js +7 -5
  5. package/dist-lib/lib/assistant/history.d.ts +1 -0
  6. package/dist-lib/lib/assistant/history.js +1 -17
  7. package/dist-lib/lib/assistant/message.d.ts +4 -1
  8. package/dist-lib/lib/assistant/pdf-budget.d.ts +10 -2
  9. package/dist-lib/lib/assistant/pdf-budget.js +10 -11
  10. package/dist-lib/lib/assistant/pdf-pages.d.ts +18 -0
  11. package/dist-lib/lib/assistant/pdf-pages.js +75 -0
  12. package/dist-lib/lib/assistant-tree.d.ts +2 -0
  13. package/dist-lib/lib/assistant-tree.js +4 -2
  14. package/dist-lib/lib/assistant.d.ts +10 -6
  15. package/dist-lib/lib/assistant.js +205 -140
  16. package/dist-lib/lib/compaction.d.ts +2 -1
  17. package/dist-lib/lib/compaction.js +14 -4
  18. package/dist-lib/lib/constants.d.ts +3 -0
  19. package/dist-lib/lib/constants.js +3 -0
  20. package/dist-lib/lib/core/chat-activity.js +12 -15
  21. package/dist-lib/lib/core/chunk.d.ts +9 -1
  22. package/dist-lib/lib/core/chunk.js +42 -8
  23. package/dist-lib/lib/core/document-attachment.d.ts +6 -3
  24. package/dist-lib/lib/core/document-attachment.js +10 -5
  25. package/dist-lib/lib/core/files/attachments.js +3 -3
  26. package/dist-lib/lib/core/files/index.d.ts +1 -1
  27. package/dist-lib/lib/core/files/index.js +3 -2
  28. package/dist-lib/lib/core/files/processing/index.d.ts +1 -0
  29. package/dist-lib/lib/core/files/processing/index.js +8 -0
  30. package/dist-lib/lib/core/files/processing/settle.d.ts +1 -0
  31. package/dist-lib/lib/core/files/processing/settle.js +20 -13
  32. package/dist-lib/lib/core/files/rag/index.d.ts +1 -1
  33. package/dist-lib/lib/core/files/rag/index.js +1 -1
  34. package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +1 -0
  35. package/dist-lib/lib/core/files/rag/retrieval/full-text.js +3 -0
  36. package/dist-lib/lib/core/hosted-agents.d.ts +3 -0
  37. package/dist-lib/lib/core/hosted-agents.js +19 -0
  38. package/dist-lib/lib/core/notification.js +16 -13
  39. package/dist-lib/lib/core/pdf/figure.d.ts +22 -0
  40. package/dist-lib/lib/core/pdf/figure.js +64 -0
  41. package/dist-lib/lib/core/pdf/rasterize.d.ts +10 -1
  42. package/dist-lib/lib/core/pdf/rasterize.js +72 -22
  43. package/dist-lib/lib/core.d.ts +6 -0
  44. package/dist-lib/lib/core.js +5 -0
  45. package/dist-lib/lib/credential-pusher.d.ts +11 -7
  46. package/dist-lib/lib/credential-pusher.js +40 -8
  47. package/dist-lib/lib/integrations/setup-routes.js +7 -5
  48. package/dist-lib/lib/kv-cache-retention.d.ts +34 -0
  49. package/dist-lib/lib/kv-cache-retention.js +98 -0
  50. package/dist-lib/schema/content.js +2 -1
  51. package/dist-lib/schema/qvac.js +4 -2
  52. package/dist-lib/spec/hrpc/messages.js +4 -10
  53. package/dist-lib/spec/hyperschema/index.js +4 -10
  54. package/dist-lib/spec/hyperschema/schema.json +2 -1
  55. package/dist-lib/spec/hyperschema/types.d.ts +1 -1
  56. package/dist-lib/spec/mesh/hyperdb/messages.js +34 -14
  57. package/dist-lib/spec/mesh/hyperdispatch/messages.js +18 -8
  58. package/dist-lib/spec/mesh/hyperschema/index.js +18 -8
  59. package/dist-lib/spec/mesh/hyperschema/schema.json +11 -1
  60. package/dist-lib/spec/mesh/hyperschema/types.d.ts +3 -1
  61. package/package.json +6 -3
  62. package/tui/app.mjs +743 -266
  63. package/tui/boot.mjs +2 -2
  64. package/tui/lib/connect-sheet.mjs +350 -0
  65. package/tui/lib/setup.mjs +59 -25
  66. package/tui/lib/skill-connect.mjs +145 -0
package/CHANGELOG.md CHANGED
@@ -13,6 +13,91 @@ release.
13
13
 
14
14
  ## [Unreleased]
15
15
 
16
+ ## [0.11.3] - 2026-10-28
17
+
18
+ ### Added
19
+
20
+ - The first run to complete stores which pictures of a PDF it sent, as an attachment chunk whose
21
+ `sourceId` is the PDF's attachment id, so later turns and other devices send the same ones. Do
22
+ not render an attachment chunk that carries a `sourceId`. (#640)
23
+
24
+ ### Changed
25
+
26
+ - A PDF's pictures reach a vision model cut to each figure and its caption, named by page and
27
+ figure, instead of as whole pages, and white pages are no longer sent. The PDF's text and its
28
+ pictures now share half the context window, less what the chat already holds, where each took
29
+ half before: a PDF whose whole text fit filled the window and compacted on the next message.
30
+ (#640)
31
+ - `bare-pdfium` is required at `^1.8.0`, for `imageBounds` and `pageBox`; a host that packages the
32
+ addon ships that version. (#640)
33
+
34
+ ## [0.11.2] - 2026-10-28
35
+
36
+ ### Added
37
+
38
+ - A chat's KV cache is deleted once the chat has been idle for the retention, so a device no
39
+ longer keeps the cache of every chat it ever ran. The chat itself is untouched; its next message
40
+ primes from history. An app sets its default with `kvCacheRetentionMs` on `assistantChild` (14
41
+ days without it, `0` for Never), and a device overrides it with `kvCache.retentionDays`. (#589)
42
+
43
+ ```js
44
+ import { assistantChild } from '@qvac/core'
45
+ import { KV_CACHE_RETENTION_KEY } from '@qvac/core/constants'
46
+
47
+ assistantChild({ harness, kvCacheRetentionMs: 30 * 24 * 60 * 60_000 })
48
+ await engine.configSet({ key: KV_CACHE_RETENTION_KEY, value: 7 })
49
+ ```
50
+
51
+ - Every credential a skill declares is pushed to the harness, not only the built-in keys and
52
+ OAuth tokens, so a skill with its own key no longer reads needs-setup for good and needs no core
53
+ release. Where a value may be sent is unchanged, and an overlay skill gets no credential. (#596)
54
+ - A credential with no setup block and no token provider gets a one-field token route named after
55
+ its key, so any setup UI can set it. (#591)
56
+ - `duck` sets a skill up through one sheet, opened by `/skill <name>`. (#592)
57
+
58
+ ### Changed
59
+
60
+ - `toolResult.result` is required on the wire, so a tool result of `false`, `0` or `''` reads
61
+ back as written from `listChunks` and `chunksWatch` instead of `null`. A device on 0.11.0 or
62
+ earlier, and a result one of those releases wrote, still read `null`. (#559)
63
+
64
+ ```js
65
+ // 0.11.1
66
+ { type: 'tool-result', toolResult: { name } }
67
+ // 0.11.2
68
+ { type: 'tool-result', toolResult: { name, result: null } }
69
+ ```
70
+
71
+ ### Removed
72
+
73
+ - `duck`'s `/cred`: every value is set through its skill's sheet. (#593)
74
+
75
+ ### Fixed
76
+
77
+ - Chat activity no longer diffs across a fast-forward it has not counted yet. It
78
+ dropped its cached view head only once `fastForwards` moved, which can be
79
+ after the view has landed on another core, and a diff from the old head read
80
+ every node of the new view. It now drops the head whenever the view is on
81
+ another core, as `chunksDeltaWatch` does. (#623)
82
+ - A device that does not hold a mesh no longer downloads most of it to show chat
83
+ activity and notifications. Both read a few chunk types per chat, each through
84
+ its type index and then row by row from `@qvac/chunks`; they now read the
85
+ chat's range of `@qvac/chat-chunks` once and keep those types, where that
86
+ range is whole. A member joining a 170-chat mesh with both open downloaded
87
+ about 39,000 blocks (155 MB) instead of 258,000 (640 MB), and on a device that
88
+ holds the mesh their first frames take 2.2 s and 3.7 s instead of 5.8 s and
89
+ 9.8 s. (#624)
90
+ - `compactChat` folds whole turns, so a chat whose messages were queued no longer keeps answers
91
+ without their questions. (#607)
92
+ - A run whose injected excerpts overflow the model window, with no older turns to fold, is retried
93
+ with half the excerpts instead of failing. (#599)
94
+ - `ragSearch` on a remote agent host waits for an attached file still replicating to it instead of
95
+ answering that the file is still being indexed. (#562)
96
+ - A chat whose first message carries a document is titled from the words the user typed, not the
97
+ document text. (#516)
98
+ - A re-homed agent's skill values are retried until the new host takes them; a host that refused
99
+ before it replicated the re-home left them unset. (#478)
100
+
16
101
  ## [0.11.1] - 2026-10-26
17
102
 
18
103
  ### Added
@@ -2003,7 +2088,9 @@ Published under the `release-0.1` dist-tag.
2003
2088
  await assistant.ready()
2004
2089
  ```
2005
2090
 
2006
- [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.11.1...HEAD
2091
+ [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.11.3...HEAD
2092
+ [0.11.3]: https://github.com/tetherto/qvac-core/compare/v0.11.2...v0.11.3
2093
+ [0.11.2]: https://github.com/tetherto/qvac-core/compare/v0.11.1...v0.11.2
2007
2094
  [0.11.1]: https://github.com/tetherto/qvac-core/compare/v0.11.0...v0.11.1
2008
2095
  [0.11.0]: https://github.com/tetherto/qvac-core/compare/v0.10.4...v0.11.0
2009
2096
  [0.10.4]: https://github.com/tetherto/qvac-core/compare/v0.10.3...v0.10.4
package/README.md CHANGED
@@ -661,19 +661,23 @@ skill's `allow_list` binds that key to the URL prefixes it may be sent to.
661
661
  Credentials are **per agent** (stored at `skills.<agentId>.<key>`), so two
662
662
  agents never share one connection.
663
663
 
664
- Fill a key with a slash command in the running TUI — see
665
- [The duck TUI](#the-duck-tui):
666
-
667
- - `/connect google` · `/connect spotify` · `/connect asana` · `/connect notion` — browser OAuth;
668
- the example stores the token and refreshes it on use.
669
- - `/cred <key> <value>` — set any credential key by hand, for a service with
670
- no built-in OAuth flow.
671
-
672
- `/connect google` needs `GOOGLE_OAUTH_CLIENT_ID` + `GOOGLE_OAUTH_CLIENT_SECRET`
673
- in env, `/connect spotify` needs `SPOTIFY_OAUTH_CLIENT_ID`, `/connect asana` needs
674
- `ASANA_OAUTH_CLIENT_ID` + `ASANA_OAUTH_CLIENT_SECRET` (an MCP-type app registered
675
- at app.asana.com); `/connect notion` needs nothing — its MCP server self-provisions
676
- a public client via dynamic registration (RFC 7591) + PKCE.
664
+ Set a skill up in the running TUI — see [The duck TUI](#the-duck-tui):
665
+
666
+ - `/skill <name>` — opens the skill's setup: what it needs, its fields, and the
667
+ button that finishes it. OAuth skills sign in through the browser and refresh
668
+ on use; a token skill saves its token; a folder skill checks the folder exists.
669
+ Secrets are masked while typed and never reach the transcript or ↑ history.
670
+ - `/skill on <name>` — turning on a skill that needs setup opens it first; the
671
+ skill turns on once the setup succeeds. `/skills` does the same on space.
672
+ - `/skill <name> set <field> [value]` — set one field from a script.
673
+ - `/skill <name> disconnect` — remove what the skill stored.
674
+ - `/connect <name>` is the same sheet, signing in straight away.
675
+
676
+ An OAuth skill asks for its own client app (Client ID and, unless it is
677
+ PKCE-only, Client Secret), and its sheet walks through creating one. Leave the
678
+ fields blank to use `<PROVIDER>_OAUTH_CLIENT_ID` + `<PROVIDER>_OAUTH_CLIENT_SECRET`
679
+ from the env when both are set. Notion needs nothing — its MCP server
680
+ self-provisions a public client via dynamic registration (RFC 7591) + PKCE.
677
681
 
678
682
  ### Notion
679
683
 
@@ -681,13 +685,12 @@ Notion runs over its official MCP server (`https://mcp.notion.com/mcp`) via
681
685
  the `mcp_call` tool, under the credential key `notion_mcp_access_token`:
682
686
 
683
687
  ```
684
- /connect notion # authorize in the browser, pick the pages to share
685
- /skill on notion # if the agent's skill scope is 'selected'
688
+ /skill on notion # sign in through the browser, then the skill turns on
686
689
  ```
687
690
 
688
691
  Then ask the assistant anything Notion — it loads the `notion` skill and calls
689
692
  `mcp_call` itself; the session handshake and auth are handled for you. A `401`
690
- in a tool result means the token expired — run `/connect notion` again.
693
+ in a tool result means the token expired — run `/skill notion connect` again.
691
694
 
692
695
  ## Development
693
696
 
@@ -1,4 +1,4 @@
1
- import { appendChunk, listAttachmentsByKind, listChunks, listRunRequests, recordLinks, resolveApproval, updateChunk } from '../core/chunk.js';
1
+ import { appendChunk, listAttachmentsByKind, listChunks, listRunRequests, readChunk, recordLinks, resolveApproval, updateChunk } from '../core/chunk.js';
2
2
  import { chunkDeltaStream, chunkDeltas } from './chunk-delta.js';
3
3
  import { meshWatchable, requireMesh } from './current-mesh.js';
4
4
  import { bounds } from './range.js';
@@ -41,7 +41,9 @@ export function createChunksApi(pool, deviceId, log) {
41
41
  const watch = meshWatchable(pool, (_request, mesh) => deltas(mesh), { name: 'chunksDeltaWatch', log });
42
42
  return chunkDeltaStream(watch(request));
43
43
  },
44
- runRequestsWatch: meshWatchable(pool, async (_request, mesh) => ({ chunks: await listRunRequests(mesh, deviceId) }), { name: 'runRequestsWatch', log })
44
+ runRequestsWatch: meshWatchable(pool, async (_request, mesh) => ({
45
+ chunks: (await listRunRequests(mesh, deviceId)).map(readChunk)
46
+ }), { name: 'runRequestsWatch', log })
45
47
  };
46
48
  }
47
49
  function chunkSelection({ chatId, type, types, ...rest }) {
@@ -48,16 +48,15 @@ export function createRagApi(pool, { index, embedder, effectiveCtxSize = null })
48
48
  if (!toolMode && !agentAllowsRagSearch(agent)) {
49
49
  return respond({ enabled: false });
50
50
  }
51
- if (rows.length === 0) {
52
- return respond({});
53
- }
54
51
  const namedRows = referencedDocuments(query, rows.map((row) => ({ id: row.id, title: row.fileName })));
55
52
  const unscoped = namedRows.length ? namedRows : rows;
56
53
  const requested = scopeIds.size ? scopeRows : unscoped;
57
- const waiting = requested.filter((row) => !mesh.files.hydratedArtifact(row.id));
54
+ const waiting = scopeIds.size
55
+ ? [...scopeIds].filter((id) => !mesh.files.hydratedArtifact(id))
56
+ : requested.filter((row) => !mesh.files.hydratedArtifact(row.id)).map((row) => row.id);
58
57
  if (waiting.length) {
59
58
  try {
60
- await mesh.files.settle(waiting.map((row) => row.id));
59
+ await mesh.files.settle(waiting, { chatId });
61
60
  }
62
61
  catch (err) {
63
62
  mesh.log?.warn('rag', 'indexing settle failed', { err });
@@ -65,6 +64,9 @@ export function createRagApi(pool, { index, embedder, effectiveCtxSize = null })
65
64
  rows = await mesh.files.listKnowledge(chatId);
66
65
  scopeRows = rows.filter((row) => scopeIds.has(row.id));
67
66
  }
67
+ if (rows.length === 0) {
68
+ return respond({});
69
+ }
68
70
  const hasKnowledge = rows.length > 0;
69
71
  const vectorIndex = index(meshId);
70
72
  const embed = embedder(meshId);
@@ -16,6 +16,7 @@ export interface CompactOptions {
16
16
  readonly signal?: AbortSignal;
17
17
  readonly onFold?: () => Promise<void> | void;
18
18
  readonly meshId: string;
19
+ readonly requestSeq?: number;
19
20
  }
20
21
  export type CompactionTrigger = 'before-run' | 'overflow';
21
22
  export interface CompactResult {
@@ -136,12 +136,6 @@ export function historyFromChunks(chunks, stale = {}, { senderNames = new Map(),
136
136
  }
137
137
  return turn;
138
138
  };
139
- const foldedRequests = foldedRequestRuns(chunks, source);
140
- for (const chunk of source) {
141
- if (chunk.runId && foldedRequests.has(chunk.runId) && (chunk.content || chunk.toolResult)) {
142
- anchor(chunk.runId);
143
- }
144
- }
145
139
  const afterRun = (runId) => {
146
140
  let at = history.indexOf(anchor(runId)) + 1;
147
141
  while (history[at]?.role === 'tool') {
@@ -185,7 +179,7 @@ export function historyFromChunks(chunks, stale = {}, { senderNames = new Map(),
185
179
  turn.documents = documents;
186
180
  }
187
181
  if (pdfs.length) {
188
- turn.pdfs = pdfs;
182
+ turn.pdfs = pdfs.map((ref) => ({ ...ref, pages: digests.get(ref.id) }));
189
183
  }
190
184
  history.push(turn);
191
185
  continue;
@@ -241,16 +235,6 @@ export function historyFromChunks(chunks, stale = {}, { senderNames = new Map(),
241
235
  }
242
236
  return history.filter((turn) => turn.role === 'user' || turn.content.length > 0 || kept.has(turn));
243
237
  }
244
- function foldedRequestRuns(chunks, kept) {
245
- const keptIds = new Set(kept.map((chunk) => chunk.id));
246
- const folded = new Set();
247
- for (const chunk of chunks) {
248
- if (chunk.type === 'run-request' && chunk.runId && !keptIds.has(chunk.id)) {
249
- folded.add(chunk.runId);
250
- }
251
- }
252
- return folded;
253
- }
254
238
  export function inputAvailableToRun(chunk, requestSeq) {
255
239
  const userInput = Boolean(chunk.userMessage || (chunk.attachment && !chunk.runId));
256
240
  return !userInput || chunk.seq < requestSeq;
@@ -12,7 +12,7 @@ export interface ChatMessage {
12
12
  audioAttachments?: AttachmentRef[];
13
13
  videos?: VideoRef[];
14
14
  documents?: DocumentAttachment[];
15
- pdfs?: AttachmentRef[];
15
+ pdfs?: PdfRef[];
16
16
  }
17
17
  export declare const IMAGE_ONLY_USER_PROMPT = "The user sent one or more images without any accompanying text. Describe what the images show and respond to anything notable in them.";
18
18
  export declare const DOCUMENT_ONLY_USER_PROMPT = "The user sent one or more documents without any accompanying text. Summarize the attached documents.";
@@ -50,6 +50,9 @@ export interface AttachmentRef {
50
50
  export interface VideoRef extends AttachmentRef {
51
51
  digest?: AttachmentRef;
52
52
  }
53
+ export interface PdfRef extends AttachmentRef {
54
+ pages?: AttachmentRef;
55
+ }
53
56
  export interface AttachInput {
54
57
  fileName: string;
55
58
  mimeType: string;
@@ -1,3 +1,11 @@
1
- export declare const MIN_PDF_PAGE_IMAGES = 2;
2
1
  export declare const MAX_PDF_PAGE_IMAGES = 32;
3
- export declare function pdfPageBudget(ctxSize: number): number;
2
+ export declare const CHARS_PER_TOKEN = 4;
3
+ export interface PdfReading {
4
+ readonly ctxSize: number;
5
+ readonly cacheTokens?: number;
6
+ }
7
+ export interface PdfRoom {
8
+ tokens: number;
9
+ images: number;
10
+ }
11
+ export declare function pdfImageRoom({ ctxSize, cacheTokens }: PdfReading, textChars: number): PdfRoom;
@@ -1,13 +1,12 @@
1
- import { MAX_IMAGE_WIDTH } from '../core/image/normalize.js';
2
- import { frameTokens } from './video-budget.js';
3
- const PAGE_TOKENS = frameTokens({
4
- width: MAX_IMAGE_WIDTH,
5
- height: Math.ceil(MAX_IMAGE_WIDTH * Math.SQRT2)
6
- });
7
- const PDF_SHARE = 0.5;
8
- export const MIN_PDF_PAGE_IMAGES = 2;
1
+ const DOCUMENT_SHARE = 0.5;
2
+ const ANSWER_SHARE = 0.25;
9
3
  export const MAX_PDF_PAGE_IMAGES = 32;
10
- export function pdfPageBudget(ctxSize) {
11
- const fits = Math.floor((ctxSize * PDF_SHARE) / PAGE_TOKENS);
12
- return Math.min(MAX_PDF_PAGE_IMAGES, Math.max(MIN_PDF_PAGE_IMAGES, fits));
4
+ export const CHARS_PER_TOKEN = 4;
5
+ export function pdfImageRoom({ ctxSize, cacheTokens }, textChars) {
6
+ const share = ctxSize * DOCUMENT_SHARE;
7
+ const free = cacheTokens === undefined ? share : Math.min(share, ctxSize * (1 - ANSWER_SHARE) - cacheTokens);
8
+ return {
9
+ tokens: Math.max(0, Math.floor(free - textChars / CHARS_PER_TOKEN)),
10
+ images: MAX_PDF_PAGE_IMAGES
11
+ };
13
12
  }
@@ -0,0 +1,18 @@
1
+ import type { PdfBounds } from '../core/pdf/figure.ts';
2
+ import type { PdfDoc } from '../core/pdf/rasterize.ts';
3
+ import type { PdfRoom } from './pdf-budget.ts';
4
+ export declare const PDF_PAGES_MIME = "application/vnd.qvac.pdf-pages";
5
+ export interface PdfShot {
6
+ readonly page: number;
7
+ readonly clip?: PdfBounds;
8
+ readonly label: string;
9
+ }
10
+ export interface PdfSelection {
11
+ readonly pageCount: number;
12
+ readonly shots: ReadonlyArray<PdfShot>;
13
+ readonly cutAt?: number;
14
+ }
15
+ export declare function pdfSelectionFileName(pdfFileName: string): string;
16
+ export declare function packPdfSelection(selection: PdfSelection): Uint8Array;
17
+ export declare function parsePdfSelection(bytes: Uint8Array): PdfSelection;
18
+ export declare function selectPdfPages(doc: PdfDoc, room: PdfRoom): Promise<PdfSelection>;
@@ -0,0 +1,75 @@
1
+ import b4a from 'b4a';
2
+ import * as z from 'zod';
3
+ import { frameTokens } from './video-budget.js';
4
+ export const PDF_PAGES_MIME = 'application/vnd.qvac.pdf-pages';
5
+ const BoundsSchema = z.object({
6
+ x: z.number(),
7
+ y: z.number(),
8
+ width: z.number().positive(),
9
+ height: z.number().positive()
10
+ });
11
+ const SelectionSchema = z.object({
12
+ version: z.literal(1),
13
+ pageCount: z.number().int().nonnegative(),
14
+ shots: z.array(z.object({
15
+ page: z.number().int().nonnegative(),
16
+ clip: BoundsSchema.optional(),
17
+ label: z.string()
18
+ })),
19
+ cutAt: z.number().int().nonnegative().optional()
20
+ });
21
+ export function pdfSelectionFileName(pdfFileName) {
22
+ return `${pdfFileName}.pages`;
23
+ }
24
+ export function packPdfSelection(selection) {
25
+ return b4a.from(JSON.stringify({ version: 1, ...selection }));
26
+ }
27
+ export function parsePdfSelection(bytes) {
28
+ const { version: _, ...selection } = SelectionSchema.parse(JSON.parse(b4a.toString(bytes)));
29
+ return selection;
30
+ }
31
+ function shotLabel(page, names = []) {
32
+ return names.length ? `page ${page + 1} (${names.join(', ')})` : `page ${page + 1}`;
33
+ }
34
+ export async function selectPdfPages(doc, room) {
35
+ const pageCount = doc.pageCount();
36
+ const shots = [];
37
+ let cutAt;
38
+ for (let page = 0; page < pageCount; page++) {
39
+ let shot;
40
+ try {
41
+ shot = await pictured(doc, page);
42
+ }
43
+ catch {
44
+ continue;
45
+ }
46
+ if (!shot) {
47
+ continue;
48
+ }
49
+ if (room.images <= 0) {
50
+ return { pageCount, shots, cutAt: cutAt ?? page };
51
+ }
52
+ const cost = frameTokens(doc.renderSize(page, shot.clip));
53
+ if (cost > room.tokens) {
54
+ cutAt ??= page;
55
+ continue;
56
+ }
57
+ room.tokens -= cost;
58
+ room.images--;
59
+ shots.push(shot);
60
+ }
61
+ return cutAt === undefined ? { pageCount, shots } : { pageCount, shots, cutAt };
62
+ }
63
+ async function pictured(doc, page) {
64
+ const flags = doc.pageFlags(page);
65
+ if (flags.hasText && !flags.hasImage) {
66
+ return null;
67
+ }
68
+ if (!flags.hasText && !flags.hasImage && (await doc.blank(page))) {
69
+ return null;
70
+ }
71
+ const figure = flags.hasText ? doc.figure(page) : null;
72
+ return figure
73
+ ? { page, clip: figure.clip, label: shotLabel(page, figure.names) }
74
+ : { page, label: shotLabel(page) };
75
+ }
@@ -26,6 +26,7 @@ export interface AssistantTreeOptions {
26
26
  runReplayDir?: string;
27
27
  imageCacheMaxBytes?: number;
28
28
  imageCacheMaxAgeMs?: number;
29
+ kvCacheRetentionMs?: number;
29
30
  embedder?: EmbedderFactory;
30
31
  extractors?: RagExtractors;
31
32
  onHarness?: OnHarness;
@@ -43,6 +44,7 @@ export interface AssistantChildOptions {
43
44
  runReplayDir?: string;
44
45
  imageCacheMaxBytes?: number;
45
46
  imageCacheMaxAgeMs?: number;
47
+ kvCacheRetentionMs?: number;
46
48
  embedder?: EmbedderFactory;
47
49
  extractors?: RagExtractors;
48
50
  onHarness?: OnHarness;
@@ -10,7 +10,7 @@ import { serveHarness } from '@qvac/harness';
10
10
  import { duplexPair } from '@qvac/harness/transport';
11
11
  import { lentHarness } from './lent-harness.js';
12
12
  export function assistantTree(opts) {
13
- const { core, harness, logger = null, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, embedder, extractors, onHarness, platform, preloadCurrentAgentModel, fakeModels = false } = opts;
13
+ const { core, harness, logger = null, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, kvCacheRetentionMs, embedder, extractors, onHarness, platform, preloadCurrentAgentModel, fakeModels = false } = opts;
14
14
  const sup = new Supervisor();
15
15
  const logged = ['child-died', 'child-restarting', 'child-ready', 'gave-up', 'stall'];
16
16
  for (const event of logged) {
@@ -80,6 +80,7 @@ export function assistantTree(opts) {
80
80
  runReplayDir,
81
81
  imageCacheMaxBytes,
82
82
  imageCacheMaxAgeMs,
83
+ kvCacheRetentionMs,
83
84
  platform,
84
85
  preloadCurrentAgentModel,
85
86
  drives: core.fsDrives ?? undefined,
@@ -243,7 +244,7 @@ export function assistantTree(opts) {
243
244
  return sup;
244
245
  }
245
246
  export function assistantChild(opts) {
246
- const { harness, core = 'core', logger = null, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, embedder, extractors, onHarness, preloadCurrentAgentModel, fakeModels, ...spec } = opts;
247
+ const { harness, core = 'core', logger = null, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, kvCacheRetentionMs, embedder, extractors, onHarness, preloadCurrentAgentModel, fakeModels, ...spec } = opts;
247
248
  return {
248
249
  ...spec,
249
250
  deps: [core],
@@ -257,6 +258,7 @@ export function assistantChild(opts) {
257
258
  runReplayDir,
258
259
  imageCacheMaxBytes,
259
260
  imageCacheMaxAgeMs,
261
+ kvCacheRetentionMs,
260
262
  embedder,
261
263
  extractors,
262
264
  onHarness,
@@ -25,6 +25,7 @@ export interface AssistantOptions {
25
25
  runReplayDir?: string;
26
26
  imageCacheMaxBytes?: number;
27
27
  imageCacheMaxAgeMs?: number;
28
+ kvCacheRetentionMs?: number;
28
29
  downloadRetryMs?: number;
29
30
  platform?: string;
30
31
  preloadCurrentAgentModel?: boolean;
@@ -95,18 +96,20 @@ export declare class QvacAssistant extends ReadyResource {
95
96
  private readonly _backgroundReplays;
96
97
  private readonly _inferenceCalls;
97
98
  private readonly _runReplay;
99
+ private readonly _kvRetention;
98
100
  private readonly _lifecycle;
99
101
  private readonly _audioTranscripts;
100
102
  private readonly _videoProbes;
101
- private readonly _pdfPages;
103
+ private readonly _pdfSelections;
102
104
  private readonly _chats;
103
105
  private readonly _runImageCacheNames;
104
106
  private readonly _reconciledCompactions;
105
107
  private readonly _chatAttribution;
108
+ private readonly _knowledgeCaps;
106
109
  private readonly _modelCatalog;
107
110
  private readonly _onHarnessStatus;
108
111
  private readonly _onModelCatalogEvent;
109
- constructor(engine: Capabilities, harness: Harness, { logger, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, downloadRetryMs, platform, preloadCurrentAgentModel, drives, borrowHarness, blobReadTimeoutMs, runIdleTimeoutMs, modelReloadDelayMs, pdfRasterizer: pdfRasterizerOption }?: AssistantOptions);
112
+ constructor(engine: Capabilities, harness: Harness, { logger, imageCacheDir, inferenceCallsDir, runReplayDir, imageCacheMaxBytes, imageCacheMaxAgeMs, kvCacheRetentionMs, downloadRetryMs, platform, preloadCurrentAgentModel, drives, borrowHarness, blobReadTimeoutMs, runIdleTimeoutMs, modelReloadDelayMs, pdfRasterizer: pdfRasterizerOption }?: AssistantOptions);
110
113
  private _requireDeviceId;
111
114
  _open(): Promise<void>;
112
115
  private _triggerModelWarm;
@@ -164,6 +167,7 @@ export declare class QvacAssistant extends ReadyResource {
164
167
  tools(): Promise<ReadonlyArray<ToolCatalogEntry>>;
165
168
  private _supervisedWatch;
166
169
  private _reclaimDeletedChats;
170
+ private _sweepIdleChatCaches;
167
171
  private _dropDeletedChat;
168
172
  private _followAgentEdits;
169
173
  private _reclaimAgentChatCaches;
@@ -225,13 +229,13 @@ export declare class QvacAssistant extends ReadyResource {
225
229
  private _hydrateTurnImages;
226
230
  private _hydrateImage;
227
231
  private _hydratePdfPages;
228
- private _pdfPageBudget;
232
+ private _pdfReading;
229
233
  private _customModel;
230
- private _hydrateTurnPdfs;
231
234
  private _tryHydratePdf;
232
235
  private _hydratePdf;
233
- private _renderPdf;
234
- private _renderPdfPage;
236
+ private _storedPdfSelection;
237
+ private _renderPdfShots;
238
+ private _storePdfSelections;
235
239
  private _compactIfNearFull;
236
240
  private _runCompaction;
237
241
  private _contextReading;