bunnyquery 1.20.1 → 1.21.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.
@@ -8,7 +8,7 @@
8
8
  * `forwardRequest*` keys (the only ones read)
9
9
  * - MCP endpoint URL -> chatEngineConfig().mcpBaseUrl
10
10
  * - `poll` on each request -> pollOpt() (set per consumer; see config.ts)
11
- * - Vue `reactive`/`ref` removed (bgTaskQueue/agentViewMounted are app-level
11
+ * - Vue `reactive`/`ref` removed (bgTaskQueue is app-level
12
12
  * state that stays in the consumer, not here;
13
13
  * only the BgTaskEntry TYPE lives here)
14
14
  */
@@ -17,6 +17,7 @@ import { isServerExtractable, isPagedReadFile, isImageVisionFile, isWindowedRead
17
17
  import { chatEngineConfig, resolveForwardRequest, resolveForwardRequestHistory, pollOpt, windowedIndexingEnabled, liveStreamingEnabled, liveStreamingSocketEnabled, resolveWebAccess, resolveAnswerMode, statusPushEnabled } from './config';
18
18
  import { type AnswerMode } from './project_settings';
19
19
  import { csrEnvelopeError } from './errors';
20
+ import type { ChatIdentity } from './host';
20
21
  // Output sizing lives in budget.ts so the request cap and the reserve the input
21
22
  // budget subtracts cannot drift; getMaxOutputTokens also clamps per model.
22
23
  import { getMaxOutputTokens, getModelContextWindow } from './budget';
@@ -572,6 +573,19 @@ export type ClaudeMcpServerRequest = {
572
573
  const IMAGE_URL_REGEX =
573
574
  /\bhttps?:\/\/[^\s<>"'()\[\]]+?\.(?:jpg|jpeg|png|gif|webp)(?:\?[^\s<>"'()\[\]]*)?/gi;
574
575
 
576
+ // An IMAGE file being indexed (2026-11-25), and whether its indexing message carries it as an
577
+ // image block. 'attached' only when the file's URL is one IMAGE_URL_REGEX turns into a block
578
+ // (so the message never claims a picture that is not there); 'maybe' for an image format the
579
+ // providers do not take, which a newer worker attaches as a converted copy and an older one
580
+ // does not attach at all; undefined for every other file.
581
+ const INDEX_IMAGE_OTHER_EXT = /\.(?:tiff?|bmp|heic|heif)$/i;
582
+ function indexingImageFile(attachment: { name?: string; storagePath?: string; url?: string }): 'attached' | 'maybe' | undefined {
583
+ const url = typeof attachment.url === 'string' ? attachment.url : '';
584
+ if (url && new RegExp(IMAGE_URL_REGEX.source, 'i').test(url)) return 'attached';
585
+ if (INDEX_IMAGE_OTHER_EXT.test(attachment.name || '') || INDEX_IMAGE_OTHER_EXT.test(attachment.storagePath || '')) return 'maybe';
586
+ return undefined;
587
+ }
588
+
575
589
  export function transformContentWithImages(
576
590
  content: string,
577
591
  ): string | Array<Record<string, any>> {
@@ -702,6 +716,8 @@ export type CallClaudeWithMcpParams = {
702
716
  * resolveWebAccess.
703
717
  */
704
718
  webAccess?: boolean;
719
+ /** The send's client reference (ChatTurnContext.cref), passed to forwardRequest. */
720
+ cref?: string;
705
721
  };
706
722
  // Poll cadence for every client-secret request the chat waits on. Shared by the
707
723
  // engine's own poll sites and imported by agent.vue; the widget carries its own
@@ -768,6 +784,10 @@ export type ChatTurnContext = {
768
784
  mcpToolsItemId?: string;
769
785
  /** Set by ChatSession once the turn's outcome was applied, so a later handler cannot apply it twice. */
770
786
  settled?: boolean;
787
+ /** The client reference of this send (reconciler plan, section 3 item 9): sent as
788
+ * forwardRequest's `cref`, so a send whose ack was lost is found by it and never sent
789
+ * twice. Set by ChatSession only when the host's skapi-js carries it (crefSupported). */
790
+ cref?: string;
771
791
  };
772
792
 
773
793
  type McpListToolsItem = { type: 'mcp_list_tools'; id: string; server_label: string; tools: any[] };
@@ -906,6 +926,7 @@ export async function callClaudeWithMcp({
906
926
  extractContent,
907
927
  fileUrls,
908
928
  webAccess,
929
+ cref,
909
930
  }: CallClaudeWithMcpParams) {
910
931
  // Resolved HERE and not only in callClaudeWithPublicMcp, so a host calling this
911
932
  // builder directly gets the same switch: the project's setting is the ceiling,
@@ -939,6 +960,7 @@ export async function callClaudeWithMcp({
939
960
  owner,
940
961
  ...pollOpt(),
941
962
  ...stream.transport,
963
+ ...(cref ? { cref } : {}),
942
964
  url: ANTHROPIC_MESSAGES_API_URL,
943
965
  method: 'POST',
944
966
  headers: {
@@ -1016,9 +1038,11 @@ export async function callClaudeWithPublicMcp(
1016
1038
  onResponse?: (res: any) => void,
1017
1039
  onError?: (err: any) => void,
1018
1040
  mcpScope?: { anonymous?: boolean; publicProjectId?: string },
1041
+ turn?: ChatTurnContext,
1019
1042
  ) {
1020
1043
  const endpoint = mcpEndpointFor(mcpScope?.anonymous, mcpScope?.publicProjectId, service);
1021
1044
  return callClaudeWithMcp({
1045
+ cref: turn?.cref,
1022
1046
  prompt,
1023
1047
  messages,
1024
1048
  service,
@@ -1125,6 +1149,7 @@ export async function callOpenAIWithPublicMcp(
1125
1149
  owner,
1126
1150
  ...pollOpt(),
1127
1151
  ...stream.transport,
1152
+ ...(turn && turn.cref ? { cref: turn.cref } : {}),
1128
1153
  url: OPENAI_RESPONSES_API_URL,
1129
1154
  method: 'POST',
1130
1155
  headers: {
@@ -1212,6 +1237,9 @@ export type AttachmentSaveInfo = {
1212
1237
  * message telling the agent to resume from where the saved records leave off.
1213
1238
  */
1214
1239
  continueIndexing?: boolean;
1240
+ /** The pass's client reference, passed to forwardRequest's `cref`: a pass whose ack was
1241
+ * lost on the way is found by it in the queue listing and never sent twice. */
1242
+ cref?: string;
1215
1243
  /**
1216
1244
  * For an image-vision file (PDF), the 0-based PAGE the render window should start at.
1217
1245
  * The worker renders [renderFrom, renderFrom+RENDER_PAGES_PER_WINDOW) and injects them
@@ -1382,8 +1410,30 @@ export async function notifyAgentSaveAttachment(info: AttachmentSaveInfo) {
1382
1410
  // content arrives another way (server-side extraction, rendered pages) - the
1383
1411
  // url still appears as the attachment link, and a dead link in front of the
1384
1412
  // model is worth avoiding either way.
1413
+ // index_end (2026-11-25): a file read in ONE pass (an image, or any file not rendered,
1414
+ // windowed or paged) has no chain for the worker to end, so its done:: and run:: were
1415
+ // written only by a page that saw the pass settle, and a page closed or opened mid-pass
1416
+ // left it 'working' or flipped it to "the page was closed". With the flag the worker writes
1417
+ // the ending itself (an older worker ignores the key). The client still writes its own,
1418
+ // with the same verdict rule, so the two never disagree.
1419
+ const singlePass = !visionFile && !windowedRead && !pagedRead && !continuing;
1420
+ // An IMAGE file read in this one pass (2026-11-25): its message asks for a transcription at
1421
+ // any angle plus text_rotation, and claims an attached image only when this engine attaches
1422
+ // one (see indexingImageFile). On OpenAI the entry also carries the image `detail` the
1423
+ // model takes, for the image block a newer worker adds for a converted TIFF (an older
1424
+ // worker ignores the key).
1425
+ const imageFile = singlePass && !parsedContent && !serverExtract ? indexingImageFile(attachment) : undefined;
1426
+ const fileUrlDetail = imageFile && platform === 'openai'
1427
+ ? getOpenAIImageDetail(info.model || DEFAULT_OPENAI_MODEL)
1428
+ : undefined;
1385
1429
  const skapiFileUrls = attachment.url && attachment.storagePath
1386
- ? { _skapi_file_urls: [{ path: attachment.storagePath, url: attachment.url }] }
1430
+ ? {
1431
+ _skapi_file_urls: [{
1432
+ path: attachment.storagePath, url: attachment.url,
1433
+ ...(singlePass ? { index_end: true } : {}),
1434
+ ...(fileUrlDetail ? { detail: fileUrlDetail } : {}),
1435
+ }],
1436
+ }
1387
1437
  : {};
1388
1438
 
1389
1439
  const userMessage = (visionFile && renderPlaceholder)
@@ -1400,7 +1450,9 @@ export async function notifyAgentSaveAttachment(info: AttachmentSaveInfo) {
1400
1450
  ? { inlineContentPlaceholder: placeholder }
1401
1451
  : pagedRead
1402
1452
  ? { pagedRead: true }
1403
- : undefined,
1453
+ : imageFile
1454
+ ? { imageFile }
1455
+ : undefined,
1404
1456
  );
1405
1457
 
1406
1458
  const systemPrompt = buildIndexingSystemPrompt({
@@ -1440,6 +1492,7 @@ export async function notifyAgentSaveAttachment(info: AttachmentSaveInfo) {
1440
1492
  service,
1441
1493
  owner,
1442
1494
  ...pollOpt(),
1495
+ ...(info.cref ? { cref: info.cref } : {}),
1443
1496
  // Status push for this pass and the continuations the worker queues from it
1444
1497
  // (see ChatEngineConfig.statusPush). Absent unless the host turned it on.
1445
1498
  ...(statusPushEnabled() ? { notify: true } : {}),
@@ -1488,6 +1541,7 @@ export async function notifyAgentSaveAttachment(info: AttachmentSaveInfo) {
1488
1541
  service,
1489
1542
  owner,
1490
1543
  ...pollOpt(),
1544
+ ...(info.cref ? { cref: info.cref } : {}),
1491
1545
  // Status push for this pass and the continuations the worker queues from it
1492
1546
  // (see ChatEngineConfig.statusPush). Absent unless the host turned it on.
1493
1547
  ...(statusPushEnabled() ? { notify: true } : {}),
@@ -1736,19 +1790,27 @@ export type IndexRunPatch = {
1736
1790
  };
1737
1791
 
1738
1792
  /**
1739
- * Fire-and-forget wrapper over the consumer's upsertIndexRunRecord hook.
1740
- * Safe everywhere: missing hook, unconfigured engine, and consumer throws all
1741
- * reduce to a no-op — a run record must never be able to break the run itself.
1793
+ * Wrapper over the consumer's upsertIndexRunRecord hook. Never throws: a run record
1794
+ * must never be able to break the run itself. A missing hook or an unconfigured engine
1795
+ * is a no-op.
1796
+ *
1797
+ * The promise: with `report`, it rejects when the write failed (the hook threw or its
1798
+ * promise rejected), so a caller that retries (the settle lock) can see it; without
1799
+ * `report` it always resolves (fire and forget).
1742
1800
  */
1743
- export function upsertIndexRunRecordSafe(service: string, storagePath: string, patch: IndexRunPatch): void {
1744
- if (!service || !storagePath) return;
1801
+ export function upsertIndexRunRecordSafe(service: string, storagePath: string, patch: IndexRunPatch, opts?: { report?: boolean }): Promise<void> {
1802
+ const report = !!(opts && opts.report);
1803
+ if (!service || !storagePath) return Promise.resolve();
1804
+ let out: any;
1745
1805
  try {
1746
1806
  const hook = chatEngineConfig().upsertIndexRunRecord;
1747
- if (typeof hook !== 'function') return;
1748
- hook({ service, storagePath, patch });
1807
+ if (typeof hook !== 'function') return Promise.resolve();
1808
+ out = hook({ service, storagePath, patch });
1749
1809
  } catch (e) {
1750
- // best-effort by contract
1810
+ return report ? Promise.reject(e) : Promise.resolve();
1751
1811
  }
1812
+ const p = Promise.resolve(out).then(function () { return undefined; });
1813
+ return report ? p : p.catch(function () { return undefined; });
1752
1814
  }
1753
1815
 
1754
1816
  /**
@@ -1815,6 +1877,16 @@ export type BgTaskEntry = {
1815
1877
  /** When this client first tracked the pass (ms). A pass missing from a listing taken
1816
1878
  * BEFORE that proves nothing about it. */
1817
1879
  adoptedAt?: number;
1880
+ /** The identity this pass was dispatched or adopted under, pinned at that moment
1881
+ * (reconciler plan, section 3 item 1). Its settle, its by-id reads and the next
1882
+ * CONTINUE pass of a client-driven file use this, never the identity live at the
1883
+ * time, which a project or platform switch has moved on. Filled by the engine the
1884
+ * first time it sees the entry when a host pushed it without one. */
1885
+ identity?: ChatIdentity;
1886
+ /** The project owner, pinned with the identity (by-id reads are scoped by it). */
1887
+ owner?: string;
1888
+ /** History cache key of the chat this pass belongs to, pinned with the identity. */
1889
+ ownerKey?: string;
1818
1890
  };
1819
1891
 
1820
1892
  // Token the indexing agent appends to its final message ONLY when it has fully read and
@@ -1873,6 +1945,15 @@ export async function getChatHistory(
1873
1945
  * chat is fetched WITHOUT the bg-indexing queue while legacy items on
1874
1946
  * odd queue names survive. Older backends ignore it. */
1875
1947
  queue_exclude?: string;
1948
+ /** "ids": the light listing (id, status, times, queue, cref; no bodies). skapi-js 2.7.0. */
1949
+ fields?: 'ids';
1950
+ /** Only rows newer than this request id. skapi-js 2.7.0. */
1951
+ after?: string;
1952
+ /** Transport options for a reconciler read (skapi-js 2.7.0): its deadline, an
1953
+ * abort signal, and `fresh` (never join an identical listing in flight). */
1954
+ deadline?: number;
1955
+ signal?: any;
1956
+ fresh?: boolean;
1876
1957
  },
1877
1958
  fetchOptions: Record<string, any>,
1878
1959
  ) {
@@ -1891,6 +1972,11 @@ export async function getChatHistory(
1891
1972
  params.queue_exact ? { queue_exact: true } : {},
1892
1973
  params.compact ? { compact: true } : {},
1893
1974
  params.queue_exclude ? { queue_exclude: params.queue_exclude } : {},
1975
+ params.fields ? { fields: params.fields } : {},
1976
+ params.after ? { after: params.after } : {},
1977
+ params.deadline ? { deadline: params.deadline } : {},
1978
+ params.signal ? { signal: params.signal } : {},
1979
+ params.fresh ? { fresh: true } : {},
1894
1980
  );
1895
1981
 
1896
1982
  return resolveForwardRequestHistory()(
@@ -39,7 +39,8 @@
39
39
 
40
40
  import { normalizeStoredPathTarget, normalizeTrailingInlineToken } from './links';
41
41
 
42
- export type RetrievalHit = { path: string; page: number };
42
+ /** sheet: the hit was on a spreadsheet's sheet page (MCP 2026-11-25), whose page number means nothing to a reader. */
43
+ export type RetrievalHit = { path: string; page: number; sheet?: string };
43
44
 
44
45
  export type RetrievalNote = {
45
46
  /** Storage paths (the part after "src::") the turn read, queried or linked. */
@@ -97,16 +98,21 @@ function pushGroup(list: string[], value: unknown): void {
97
98
  else pushUnique(list, value);
98
99
  }
99
100
 
100
- function pushHit(list: RetrievalHit[], path: unknown, page: unknown): void {
101
+ function pushHit(list: RetrievalHit[], path: unknown, page: unknown, sheet?: unknown): void {
101
102
  if (typeof path !== 'string' || !path.trim()) return;
102
103
  var n = typeof page === 'number' ? page : Number(page);
103
104
  if (!isFinite(n) || n <= 0) return;
104
105
  n = Math.floor(n);
106
+ var sh = typeof sheet === 'string' && sheet.trim() ? sheet.trim() : '';
105
107
  for (var i = 0; i < list.length; i++) {
106
- if (list[i].path === path && list[i].page === n) return;
108
+ // one slot per sheet, whatever page of it was hit: several pages of one sheet must not
109
+ // crowd the document hits out of the note
110
+ if (sh ? (list[i].path === path && list[i].sheet === sh) : (list[i].path === path && list[i].page === n)) return;
107
111
  }
108
112
  if (list.length >= RETRIEVAL_NOTE_MAX_ITEMS) return;
109
- list.push({ path: path.trim(), page: n });
113
+ var hit: RetrievalHit = { path: path.trim(), page: n };
114
+ if (sh) hit.sheet = sh;
115
+ list.push(hit);
110
116
  }
111
117
 
112
118
  /** A storage path out of a src:: id, or null when the value is not one. */
@@ -161,7 +167,7 @@ function readHits(note: RetrievalNote, result: any): void {
161
167
  return;
162
168
  }
163
169
  if (typeof node.path === 'string' && node.page !== undefined) {
164
- pushHit(note.hits, node.path, node.page);
170
+ pushHit(note.hits, node.path, node.page, node.sheet);
165
171
  }
166
172
  for (var k in node) {
167
173
  if (!Object.prototype.hasOwnProperty.call(node, k)) continue;
@@ -353,8 +359,17 @@ export function formatRetrievalNote(note: RetrievalNote | null | undefined): str
353
359
  if (!byFile[h.path]) { byFile[h.path] = []; order.push(h.path); }
354
360
  byFile[h.path].push(h.page);
355
361
  }
362
+ // A spreadsheet hit is named by its sheet: its page number is no place a reader can open.
363
+ var sheetsOf: Record<string, string[]> = {};
364
+ for (var s2 = 0; s2 < note.hits.length; s2++) {
365
+ var hs = note.hits[s2];
366
+ if (hs.sheet) {
367
+ if (!sheetsOf[hs.path]) sheetsOf[hs.path] = [];
368
+ if (sheetsOf[hs.path].indexOf(hs.sheet) === -1) sheetsOf[hs.path].push(hs.sheet);
369
+ }
370
+ }
356
371
  parts.push('searchText hits ' + order.map(function (p) {
357
- return p + ' p' + byFile[p].join(', p');
372
+ return sheetsOf[p] ? p + ' sheet ' + sheetsOf[p].join(', sheet ') : p + ' p' + byFile[p].join(', p');
358
373
  }).join('; '));
359
374
  }
360
375
  if (note.tools.length) parts.push('tools ' + note.tools.join(', '));