bunnyquery 1.15.5 → 1.16.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunnyquery",
3
- "version": "1.15.5",
3
+ "version": "1.16.0",
4
4
  "description": "Embeddable BunnyQuery AI chat widget + its framework-agnostic chat engine",
5
5
  "main": "bunnyquery.js",
6
6
  "exports": {
@@ -206,38 +206,29 @@ export interface ChatEngineConfig {
206
206
  };
207
207
  }) => void;
208
208
  /**
209
- * Opt in to LIVE STREAMING of chat turns.
209
+ * Deliver each relayed chunk over skapi's WEBSOCKET as well, so text lands as it
210
+ * is relayed instead of on the next poll tick. Off unless a host asks.
210
211
  *
211
- * Off by default, and for the same shipping-order reason `windowedIndexing`
212
- * is: THE BACKEND MUST SHIP FIRST. When on, every chat turn carries two
213
- * `stream` flags (see requests.ts chatStreamWiring) and the polling row
214
- * settles with a STATUS AND NO BODY, because the answer was the stream. On a
215
- * region whose polling worker does not relay, that same request either has
216
- * its unknown `since` cursor rejected or stores an SSE transcript where the
217
- * readers expect a parsed document, and the turn reads back as an empty
218
- * answer. So it stays off until the worker is deployed, then flips per
219
- * environment.
212
+ * Streaming itself is not a choice any more: the engine streams every chat turn
213
+ * whenever the host handed over the two streaming hooks below
214
+ * (`forwardRequestFinalize` and `forwardRequestStream`, or their deprecated
215
+ * names), and a host that wants buffered replies simply hands over neither. See
216
+ * liveStreamingEnabled(). This key only decides the TRANSPORT of a stream that is
217
+ * on anyway, so a host with no streaming hooks gets nothing from setting it.
220
218
  *
221
- * It also needs `forwardRequestFinalize` below (or its deprecated name,
222
- * `clientSecretRequestFinalize`): without it a streamed turn is never
223
- * finalized, so its row keeps a status and no body forever and a later
224
- * history load shows the question with an empty answer.
225
- */
226
- liveStreaming?: boolean;
227
- /**
228
- * Also push each relayed chunk over skapi's websocket, so text lands as it is
229
- * relayed instead of on the next poll tick. Requires `liveStreaming`.
230
- *
231
- * SEPARATE FROM `liveStreaming` ON PURPOSE, and off unless a host asks. It is a
232
- * pure accelerator with a safe fallback, so the reason is not risk to the chat, it
233
- * is what it does to the HOST'S OWN realtime: skapi's joinRealtime REPLACES the
219
+ * Off by default on purpose, and the reason is not risk to the chat (the socket
220
+ * is a pure accelerator with a safe fallback: the poll carries the read), it is
221
+ * what it does to the HOST'S OWN realtime. skapi's joinRealtime REPLACES the
234
222
  * connection's group rather than adding to it, so for the length of a turn this
235
223
  * takes the room. The dashboard owns its skapi instance and uses realtime for
236
224
  * nothing else, so it opts in. The embeddable widget is handed the EMBEDDER'S
237
225
  * instance and cannot know what their app does with it, so it stays off there
238
226
  * unless the embedder turns it on.
227
+ *
228
+ * Until 1.16.0 this key meant "stream at all" and the socket was
229
+ * `liveStreamingRealtime`; that name is now ignored.
239
230
  */
240
- liveStreamingRealtime?: boolean;
231
+ liveStreaming?: boolean;
241
232
  /**
242
233
  * Whether a CHAT answer may reach the open web: Claude's `web_fetch` and
243
234
  * OpenAI's `web_search` are attached to a chat request only when this
@@ -486,12 +477,23 @@ export function windowedIndexingEnabled(): boolean {
486
477
  }
487
478
 
488
479
  /** True when the consumer has opted in to live streaming of chat turns. */
489
- export function liveStreamingRealtimeEnabled(): boolean {
490
- return liveStreamingEnabled() && _config?.liveStreamingRealtime === true;
480
+ /** Socket delivery of the stream: the host asked (`liveStreaming`) AND the turn streams. */
481
+ export function liveStreamingSocketEnabled(): boolean {
482
+ return liveStreamingEnabled() && _config?.liveStreaming === true;
491
483
  }
492
484
 
485
+ /**
486
+ * Does this host stream chat turns? Yes whenever it handed over BOTH streaming hooks
487
+ * (the finalize that stores a streamed answer onto its row, and the chunk reader),
488
+ * under either spelling. There is no separate switch: streaming is how the engine
489
+ * reads a reply, and the two hooks are the capability it needs (skapiSupportsStreaming
490
+ * explains why those two methods ARE the capability). A host that wants buffered
491
+ * replies hands over neither, which is also what both clients do when the page's
492
+ * skapi-js is too old to carry skapi's half of the stream flag.
493
+ */
493
494
  export function liveStreamingEnabled(): boolean {
494
- return _config?.liveStreaming === true;
495
+ return typeof resolveForwardRequestFinalize() === 'function'
496
+ && typeof resolveForwardRequestStream() === 'function';
495
497
  }
496
498
 
497
499
  /**
@@ -565,17 +567,17 @@ export function resolveSkipDuplicateFiles(service?: string): Promise<boolean> {
565
567
  /**
566
568
  * True when a streamed turn whose answer never reached its row can be READ BACK.
567
569
  *
568
- * IT ASKS FOR THE READER AND NOT FOR `liveStreaming`, AND THAT SPLIT IS THE WHOLE
569
- * POINT. "Should NEW turns stream?" and "can an ALREADY streamed row be recovered?"
570
+ * IT ASKS FOR THE READER ALONE, NOT FOR WHETHER NEW TURNS STREAM, AND THAT SPLIT IS
571
+ * THE WHOLE POINT. "Should NEW turns stream?" and "can an ALREADY streamed row be recovered?"
570
572
  * are two different questions about two different sets of rows, and answering both
571
573
  * with one flag strands the second set the moment the first answer changes.
572
574
  *
573
575
  * The failure, and it is not hypothetical - it is what turning the feature off
574
576
  * does. A row streamed yesterday holds its answer in the chunk table and a status
575
- * and no body on the row; only csr-finalize ever copies one onto it. Flip
576
- * `liveStreaming` off today (an embedder drops the option, a dev rolls the flag
577
- * back after a bad deploy, a client's skapiSupportsStreaming probe degrades the
578
- * instance to buffered) and every one of those rows instantly becomes unmarked,
577
+ * and no body on the row; only csr-finalize ever copies one onto it. Take
578
+ * streaming away today (a host stops handing over the finalize hook, a client's
579
+ * skapiSupportsStreaming probe degrades the instance to buffered) and every one of
580
+ * those rows instantly becomes unmarked,
579
581
  * unrecoverable and unreadable: the mapper emits no bubble for it, the recovery
580
582
  * never looks at it, and its answer is unreachable with every byte of it still
581
583
  * stored. Rolling a rendering flag back must not delete anybody's history.
@@ -606,8 +608,8 @@ export function streamRecoveryEnabled(): boolean {
606
608
 
607
609
  /**
608
610
  * Does a given skapi INSTANCE support the streaming half of the protocol? Ask this
609
- * before honouring a `liveStreaming: true` opt-in, and degrade to buffered when the
610
- * answer is no.
611
+ * before handing the engine the two streaming hooks, and hand over neither (buffered
612
+ * replies) when the answer is no.
611
613
  *
612
614
  * THE FAILURE THIS PREVENTS, and it is the one the SDK's own docs call quiet. A
613
615
  * streamed turn carries TWO `stream` flags: skapi's (relay the destination's bytes
@@ -626,8 +628,8 @@ export function streamRecoveryEnabled(): boolean {
626
628
  * It lives in the ENGINE rather than in each client because the two clients are
627
629
  * diffed against each other and this is precisely the kind of predicate that forks:
628
630
  * the widget must ask it (init() takes the EMBEDDER's instance, and an embed page
629
- * pins its own skapi-js version, so `liveStreaming: true` is a REQUEST and this is
630
- * what grants it) and agent.vue must ask it too (its instance is the repo's own, so
631
+ * pins its own skapi-js version, so streaming is granted by this probe and never
632
+ * assumed) and agent.vue must ask it too (its instance is the repo's own, so
631
633
  * only a stale node_modules or an unbuilt skapi-js can fail it - which is exactly
632
634
  * the state a dev flipping the constant is most likely to be in, and a silently
633
635
  * empty chat is the worst possible way to find out).
@@ -24,7 +24,7 @@ export {
24
24
  // empty bubble where it used to get none, which is strictly worse than the bug.
25
25
  streamRecoveryEnabled,
26
26
  // Whether a given skapi INSTANCE can carry skapi's half of the stream flag. Both
27
- // clients gate their liveStreaming opt-in on it and degrade to buffered when it
27
+ // clients gate the streaming hooks they hand over on it and degrade to buffered when it
28
28
  // says no: an SDK too old to know the key drops it silently, leaving the
29
29
  // destination streaming SSE into a buffered row that reads back empty.
30
30
  skapiSupportsStreaming,
@@ -16,7 +16,7 @@
16
16
  */
17
17
  import { buildIndexingSystemPrompt, buildIndexingUserMessage, buildIndexingContinueMessage, buildIndexingRenderMessage, buildIndexingRenderContinueTemplate, buildIndexingWindowMessage } from './prompts';
18
18
  import { isServerExtractable, isPagedReadFile, isImageVisionFile, isWindowedReadFile, makeExtractPlaceholder, makeRenderPlaceholder, makeWindowPlaceholder, RENDER_PAGES_PER_WINDOW, type ExtractDirective, type FileUrlDirective } from './office';
19
- import { chatEngineConfig, resolveForwardRequest, resolveForwardRequestHistory, pollOpt, windowedIndexingEnabled, liveStreamingEnabled, liveStreamingRealtimeEnabled, resolveWebAccess } from './config';
19
+ import { chatEngineConfig, resolveForwardRequest, resolveForwardRequestHistory, pollOpt, windowedIndexingEnabled, liveStreamingEnabled, liveStreamingSocketEnabled, resolveWebAccess } from './config';
20
20
  // Output sizing lives in budget.ts so the request cap and the reserve the input
21
21
  // budget subtracts cannot drift; getMaxOutputTokens also clamps per model.
22
22
  import { getMaxOutputTokens, getModelContextWindow } from './budget';
@@ -228,7 +228,7 @@ const CHAT_STREAM_OFF: ChatStreamWiring = Object.freeze({
228
228
  }) as ChatStreamWiring;
229
229
 
230
230
  /**
231
- * Both stream flags for a CHAT turn, from the one `liveStreaming` opt-in.
231
+ * Both stream flags for a CHAT turn, on whenever the host handed over the streaming hooks.
232
232
  *
233
233
  * Chat turns only. Deliberately NOT called from:
234
234
  * * the model LISTING calls (listClaudeModels / listOpenAIModels) - plain GETs
@@ -258,9 +258,9 @@ export function chatStreamWiring(queue?: string): ChatStreamWiring {
258
258
  if (!liveStreamingEnabled()) return CHAT_STREAM_OFF;
259
259
  if (isBgIndexingQueue(queue)) return CHAT_STREAM_OFF;
260
260
  // Socket delivery is a separate opt-in from streaming itself: see
261
- // liveStreamingRealtime for why a host that does not own its skapi instance
261
+ // the `liveStreaming` key in config.ts for why a host that does not own its skapi instance
262
262
  // should leave it off.
263
- return liveStreamingRealtimeEnabled() ? CHAT_STREAM_ON_REALTIME : CHAT_STREAM_ON;
263
+ return liveStreamingSocketEnabled() ? CHAT_STREAM_ON_REALTIME : CHAT_STREAM_ON;
264
264
  }
265
265
 
266
266
  // Resolve the per-image `detail` for OpenAI. The version match tolerates a