@qvac/core 0.11.2 → 0.11.4

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 CHANGED
@@ -13,6 +13,52 @@ release.
13
13
 
14
14
  ## [Unreleased]
15
15
 
16
+ ## [0.11.4] - 2026-10-30
17
+
18
+ ### Changed
19
+
20
+ - A `mesh write` or `mesh drain` stall now keeps reporting while it lasts (#649). Each `… still pending`
21
+ line carries `reports` (1, 2, 3 …), and the wait doubles between reports. It also names:
22
+ - `fastForwarding`: the head a fast-forward is booting onto, with how much of that core this
23
+ device and its peers hold, or `null`.
24
+ - `peerLength` and `peerHeld` on every `missing` core: how far the furthest connected peer
25
+ knows that core, and how much of it that peer holds from block 0.
26
+ - `writers` on a mesh still joining: each writer it knows, with the same holdings.
27
+ - The logs now name the build and what an open did to an older mesh (#650):
28
+ - `core opening` is the first line of a launch. It names the app's `version`, `build` and
29
+ `channel`, and the mesh `schema` this core applies. A mesh's own `opening` line names the
30
+ `schema` too.
31
+ - `migrations ran` follows each pass on open. It lists the steps that wrote, each step's `ms`,
32
+ and the step that threw as `failed`. A pass still going after 15 s logs
33
+ `migrations still running` with its current step, again after 30 s, 60 s, and so on.
34
+ - `copied chats into chat-chunks` and `recorded the files the mesh already held` give each
35
+ backfill's count and `ms`.
36
+
37
+ ### Fixed
38
+
39
+ - The assistant no longer logs `saveDeviceCapabilities failed` while the account mesh is still
40
+ joining. Core refuses the report with `MESH_STILL_JOINING` until this device is a writer, and the
41
+ assistant already reports again once the account turns writable, so the refusal was never a
42
+ failure. (#648)
43
+
44
+ ## [0.11.3] - 2026-10-28
45
+
46
+ ### Added
47
+
48
+ - The first run to complete stores which pictures of a PDF it sent, as an attachment chunk whose
49
+ `sourceId` is the PDF's attachment id, so later turns and other devices send the same ones. Do
50
+ not render an attachment chunk that carries a `sourceId`. (#640)
51
+
52
+ ### Changed
53
+
54
+ - A PDF's pictures reach a vision model cut to each figure and its caption, named by page and
55
+ figure, instead of as whole pages, and white pages are no longer sent. The PDF's text and its
56
+ pictures now share half the context window, less what the chat already holds, where each took
57
+ half before: a PDF whose whole text fit filled the window and compacted on the next message.
58
+ (#640)
59
+ - `bare-pdfium` is required at `^1.8.0`, for `imageBounds` and `pageBox`; a host that packages the
60
+ addon ships that version. (#640)
61
+
16
62
  ## [0.11.2] - 2026-10-28
17
63
 
18
64
  ### Added
@@ -2070,7 +2116,9 @@ Published under the `release-0.1` dist-tag.
2070
2116
  await assistant.ready()
2071
2117
  ```
2072
2118
 
2073
- [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.11.2...HEAD
2119
+ [Unreleased]: https://github.com/tetherto/qvac-core/compare/v0.11.4...HEAD
2120
+ [0.11.4]: https://github.com/tetherto/qvac-core/compare/v0.11.3...v0.11.4
2121
+ [0.11.3]: https://github.com/tetherto/qvac-core/compare/v0.11.2...v0.11.3
2074
2122
  [0.11.2]: https://github.com/tetherto/qvac-core/compare/v0.11.1...v0.11.2
2075
2123
  [0.11.1]: https://github.com/tetherto/qvac-core/compare/v0.11.0...v0.11.1
2076
2124
  [0.11.0]: https://github.com/tetherto/qvac-core/compare/v0.10.4...v0.11.0
@@ -179,7 +179,7 @@ export function historyFromChunks(chunks, stale = {}, { senderNames = new Map(),
179
179
  turn.documents = documents;
180
180
  }
181
181
  if (pdfs.length) {
182
- turn.pdfs = pdfs;
182
+ turn.pdfs = pdfs.map((ref) => ({ ...ref, pages: digests.get(ref.id) }));
183
183
  }
184
184
  history.push(turn);
185
185
  continue;
@@ -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
+ }
@@ -100,7 +100,7 @@ export declare class QvacAssistant extends ReadyResource {
100
100
  private readonly _lifecycle;
101
101
  private readonly _audioTranscripts;
102
102
  private readonly _videoProbes;
103
- private readonly _pdfPages;
103
+ private readonly _pdfSelections;
104
104
  private readonly _chats;
105
105
  private readonly _runImageCacheNames;
106
106
  private readonly _reconciledCompactions;
@@ -229,13 +229,13 @@ export declare class QvacAssistant extends ReadyResource {
229
229
  private _hydrateTurnImages;
230
230
  private _hydrateImage;
231
231
  private _hydratePdfPages;
232
- private _pdfPageBudget;
232
+ private _pdfReading;
233
233
  private _customModel;
234
- private _hydrateTurnPdfs;
235
234
  private _tryHydratePdf;
236
235
  private _hydratePdf;
237
- private _renderPdf;
238
- private _renderPdfPage;
236
+ private _storedPdfSelection;
237
+ private _renderPdfShots;
238
+ private _storePdfSelections;
239
239
  private _compactIfNearFull;
240
240
  private _runCompaction;
241
241
  private _contextReading;