bunnyquery 1.20.1 → 1.21.0

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';
@@ -702,6 +703,8 @@ export type CallClaudeWithMcpParams = {
702
703
  * resolveWebAccess.
703
704
  */
704
705
  webAccess?: boolean;
706
+ /** The send's client reference (ChatTurnContext.cref), passed to forwardRequest. */
707
+ cref?: string;
705
708
  };
706
709
  // Poll cadence for every client-secret request the chat waits on. Shared by the
707
710
  // engine's own poll sites and imported by agent.vue; the widget carries its own
@@ -768,6 +771,10 @@ export type ChatTurnContext = {
768
771
  mcpToolsItemId?: string;
769
772
  /** Set by ChatSession once the turn's outcome was applied, so a later handler cannot apply it twice. */
770
773
  settled?: boolean;
774
+ /** The client reference of this send (reconciler plan, section 3 item 9): sent as
775
+ * forwardRequest's `cref`, so a send whose ack was lost is found by it and never sent
776
+ * twice. Set by ChatSession only when the host's skapi-js carries it (crefSupported). */
777
+ cref?: string;
771
778
  };
772
779
 
773
780
  type McpListToolsItem = { type: 'mcp_list_tools'; id: string; server_label: string; tools: any[] };
@@ -906,6 +913,7 @@ export async function callClaudeWithMcp({
906
913
  extractContent,
907
914
  fileUrls,
908
915
  webAccess,
916
+ cref,
909
917
  }: CallClaudeWithMcpParams) {
910
918
  // Resolved HERE and not only in callClaudeWithPublicMcp, so a host calling this
911
919
  // builder directly gets the same switch: the project's setting is the ceiling,
@@ -939,6 +947,7 @@ export async function callClaudeWithMcp({
939
947
  owner,
940
948
  ...pollOpt(),
941
949
  ...stream.transport,
950
+ ...(cref ? { cref } : {}),
942
951
  url: ANTHROPIC_MESSAGES_API_URL,
943
952
  method: 'POST',
944
953
  headers: {
@@ -1016,9 +1025,11 @@ export async function callClaudeWithPublicMcp(
1016
1025
  onResponse?: (res: any) => void,
1017
1026
  onError?: (err: any) => void,
1018
1027
  mcpScope?: { anonymous?: boolean; publicProjectId?: string },
1028
+ turn?: ChatTurnContext,
1019
1029
  ) {
1020
1030
  const endpoint = mcpEndpointFor(mcpScope?.anonymous, mcpScope?.publicProjectId, service);
1021
1031
  return callClaudeWithMcp({
1032
+ cref: turn?.cref,
1022
1033
  prompt,
1023
1034
  messages,
1024
1035
  service,
@@ -1125,6 +1136,7 @@ export async function callOpenAIWithPublicMcp(
1125
1136
  owner,
1126
1137
  ...pollOpt(),
1127
1138
  ...stream.transport,
1139
+ ...(turn && turn.cref ? { cref: turn.cref } : {}),
1128
1140
  url: OPENAI_RESPONSES_API_URL,
1129
1141
  method: 'POST',
1130
1142
  headers: {
@@ -1212,6 +1224,9 @@ export type AttachmentSaveInfo = {
1212
1224
  * message telling the agent to resume from where the saved records leave off.
1213
1225
  */
1214
1226
  continueIndexing?: boolean;
1227
+ /** The pass's client reference, passed to forwardRequest's `cref`: a pass whose ack was
1228
+ * lost on the way is found by it in the queue listing and never sent twice. */
1229
+ cref?: string;
1215
1230
  /**
1216
1231
  * For an image-vision file (PDF), the 0-based PAGE the render window should start at.
1217
1232
  * The worker renders [renderFrom, renderFrom+RENDER_PAGES_PER_WINDOW) and injects them
@@ -1440,6 +1455,7 @@ export async function notifyAgentSaveAttachment(info: AttachmentSaveInfo) {
1440
1455
  service,
1441
1456
  owner,
1442
1457
  ...pollOpt(),
1458
+ ...(info.cref ? { cref: info.cref } : {}),
1443
1459
  // Status push for this pass and the continuations the worker queues from it
1444
1460
  // (see ChatEngineConfig.statusPush). Absent unless the host turned it on.
1445
1461
  ...(statusPushEnabled() ? { notify: true } : {}),
@@ -1488,6 +1504,7 @@ export async function notifyAgentSaveAttachment(info: AttachmentSaveInfo) {
1488
1504
  service,
1489
1505
  owner,
1490
1506
  ...pollOpt(),
1507
+ ...(info.cref ? { cref: info.cref } : {}),
1491
1508
  // Status push for this pass and the continuations the worker queues from it
1492
1509
  // (see ChatEngineConfig.statusPush). Absent unless the host turned it on.
1493
1510
  ...(statusPushEnabled() ? { notify: true } : {}),
@@ -1736,19 +1753,27 @@ export type IndexRunPatch = {
1736
1753
  };
1737
1754
 
1738
1755
  /**
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.
1756
+ * Wrapper over the consumer's upsertIndexRunRecord hook. Never throws: a run record
1757
+ * must never be able to break the run itself. A missing hook or an unconfigured engine
1758
+ * is a no-op.
1759
+ *
1760
+ * The promise: with `report`, it rejects when the write failed (the hook threw or its
1761
+ * promise rejected), so a caller that retries (the settle lock) can see it; without
1762
+ * `report` it always resolves (fire and forget).
1742
1763
  */
1743
- export function upsertIndexRunRecordSafe(service: string, storagePath: string, patch: IndexRunPatch): void {
1744
- if (!service || !storagePath) return;
1764
+ export function upsertIndexRunRecordSafe(service: string, storagePath: string, patch: IndexRunPatch, opts?: { report?: boolean }): Promise<void> {
1765
+ const report = !!(opts && opts.report);
1766
+ if (!service || !storagePath) return Promise.resolve();
1767
+ let out: any;
1745
1768
  try {
1746
1769
  const hook = chatEngineConfig().upsertIndexRunRecord;
1747
- if (typeof hook !== 'function') return;
1748
- hook({ service, storagePath, patch });
1770
+ if (typeof hook !== 'function') return Promise.resolve();
1771
+ out = hook({ service, storagePath, patch });
1749
1772
  } catch (e) {
1750
- // best-effort by contract
1773
+ return report ? Promise.reject(e) : Promise.resolve();
1751
1774
  }
1775
+ const p = Promise.resolve(out).then(function () { return undefined; });
1776
+ return report ? p : p.catch(function () { return undefined; });
1752
1777
  }
1753
1778
 
1754
1779
  /**
@@ -1815,6 +1840,16 @@ export type BgTaskEntry = {
1815
1840
  /** When this client first tracked the pass (ms). A pass missing from a listing taken
1816
1841
  * BEFORE that proves nothing about it. */
1817
1842
  adoptedAt?: number;
1843
+ /** The identity this pass was dispatched or adopted under, pinned at that moment
1844
+ * (reconciler plan, section 3 item 1). Its settle, its by-id reads and the next
1845
+ * CONTINUE pass of a client-driven file use this, never the identity live at the
1846
+ * time, which a project or platform switch has moved on. Filled by the engine the
1847
+ * first time it sees the entry when a host pushed it without one. */
1848
+ identity?: ChatIdentity;
1849
+ /** The project owner, pinned with the identity (by-id reads are scoped by it). */
1850
+ owner?: string;
1851
+ /** History cache key of the chat this pass belongs to, pinned with the identity. */
1852
+ ownerKey?: string;
1818
1853
  };
1819
1854
 
1820
1855
  // Token the indexing agent appends to its final message ONLY when it has fully read and
@@ -1873,6 +1908,15 @@ export async function getChatHistory(
1873
1908
  * chat is fetched WITHOUT the bg-indexing queue while legacy items on
1874
1909
  * odd queue names survive. Older backends ignore it. */
1875
1910
  queue_exclude?: string;
1911
+ /** "ids": the light listing (id, status, times, queue, cref; no bodies). skapi-js 2.7.0. */
1912
+ fields?: 'ids';
1913
+ /** Only rows newer than this request id. skapi-js 2.7.0. */
1914
+ after?: string;
1915
+ /** Transport options for a reconciler read (skapi-js 2.7.0): its deadline, an
1916
+ * abort signal, and `fresh` (never join an identical listing in flight). */
1917
+ deadline?: number;
1918
+ signal?: any;
1919
+ fresh?: boolean;
1876
1920
  },
1877
1921
  fetchOptions: Record<string, any>,
1878
1922
  ) {
@@ -1891,6 +1935,11 @@ export async function getChatHistory(
1891
1935
  params.queue_exact ? { queue_exact: true } : {},
1892
1936
  params.compact ? { compact: true } : {},
1893
1937
  params.queue_exclude ? { queue_exclude: params.queue_exclude } : {},
1938
+ params.fields ? { fields: params.fields } : {},
1939
+ params.after ? { after: params.after } : {},
1940
+ params.deadline ? { deadline: params.deadline } : {},
1941
+ params.signal ? { signal: params.signal } : {},
1942
+ params.fresh ? { fresh: true } : {},
1894
1943
  );
1895
1944
 
1896
1945
  return resolveForwardRequestHistory()(