bunnyquery 1.17.0 → 1.18.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.17.0",
3
+ "version": "1.18.0",
4
4
  "description": "Embeddable BunnyQuery AI chat widget + its framework-agnostic chat engine",
5
5
  "main": "bunnyquery.js",
6
6
  "exports": {
@@ -206,6 +206,24 @@ export function encodePathSegments(path: string): string {
206
206
  return path.split('/').filter(Boolean).map(function (s) { return encodeURIComponent(s); }).join('/');
207
207
  }
208
208
 
209
+ /**
210
+ * A stored-file path the MODEL wrote (a `db:` link target or a `src::` token).
211
+ *
212
+ * The prompt says the path is written exactly as stored, NOT url-encoded, and
213
+ * models do not always obey: a GPT answer linked `db:testing/2023-09%20(1).xlsx`
214
+ * for the stored file `testing/2023-09 (1).xlsx`, and the chip minted a url for a
215
+ * key that does not exist. A stored name CAN contain a literal "%20" too, which
216
+ * is why this does not decode unconditionally. The two are told apart by the one
217
+ * thing an encoder never leaves behind: raw whitespace. A path with a real space
218
+ * in it was not encoded and is kept as written; a path with no whitespace and a
219
+ * valid %XX escape was, and is decoded.
220
+ */
221
+ export function normalizeStoredPathTarget(value: string): string {
222
+ var p = String(value || '').trim().replace(/\\/g, '/').replace(/^\/+/, '').replace(/\/+/g, '/');
223
+ if (!/\s/.test(p) && /%[0-9A-Fa-f]{2}/.test(p)) p = safeDecodeURIComponent(p);
224
+ return p;
225
+ }
226
+
209
227
  export function normalizeAttachmentPathCandidate(value: string): string {
210
228
  return safeDecodeURIComponent((value || '').trim()).replace(/\\/g, '/').replace(/^\/+/, '').replace(/\/+/g, '/');
211
229
  }
@@ -529,9 +547,9 @@ export function classifyInlineLink(
529
547
  var srcPath = readExpiredAttachmentHref(rawPath)
530
548
  || (srcIsUrl
531
549
  ? (extractRemotePathFromAttachmentHref(rawPath, ctx.projectId) || normalizeAttachmentPathCandidate(rawPath))
532
- // bare stored path: same NON-decoding normalize as the db: branch; only
533
- // URL-derived paths genuinely arrive percent-encoded.
534
- : rawPath.trim().replace(/\\/g, '/').replace(/^\/+/, '').replace(/\/+/g, '/'));
550
+ // bare stored path: same normalize as the db: branch (decoded only when
551
+ // the model visibly url-encoded it, see normalizeStoredPathTarget).
552
+ : normalizeStoredPathTarget(rawPath));
535
553
  var srcBuilt = asStoredFile(srcPath, srcPath);
536
554
  return srcBuilt ? { part: srcBuilt.part, tail: tail } : null;
537
555
  }
@@ -546,11 +564,13 @@ export function classifyInlineLink(
546
564
  // EMITTING it; until then this branch simply never fires.
547
565
  var dbTarget = /^db:(.+)$/i.exec(g5.trim());
548
566
  if (dbTarget) {
549
- // NON-decoding normalize: the prompt guarantees a db: target is the path exactly
550
- // as stored, NOT url-encoded, and the MCP's own key builder refuses to decode
551
- // bare paths for the same corruption: percent-decoding here turned a stored name
552
- // containing a literal "%20" into the wrong key.
553
- var rawDbPath = dbTarget[1].trim().replace(/\\/g, '/').replace(/^\/+/, '').replace(/\/+/g, '/');
567
+ // The prompt asks for the path exactly as stored, NOT url-encoded, and the
568
+ // MCP's own key builder never decodes a bare path. Decoding every target
569
+ // turned a stored name containing a literal "%20" into the wrong key, and
570
+ // decoding none sent a model's encoded `2023-09%20(1).xlsx` to a key that
571
+ // does not exist. normalizeStoredPathTarget decodes only the visibly encoded.
572
+ // A markdown title, `[a](db:x.pdf "title")`, is not part of the path.
573
+ var rawDbPath = normalizeStoredPathTarget(dbTarget[1].replace(/\s+"[^"\n]*"\s*$/, ''));
554
574
  var declared = asStoredFile(rawDbPath, g4);
555
575
  if (!declared) return null;
556
576
  declared.part.label = truncateLabelForDisplay(g4);
@@ -112,8 +112,13 @@ These three rules govern every claim about the project's data. They do not limit
112
112
  // readFileContent; nothing found is said as such. The last sentence follows
113
113
  // the web switch: with the web off the chat has no such tool, with it on a web
114
114
  // fact must be marked as one. Additive: the rules around it are unchanged.
115
+ // Quick search first (2026-11-15): a file the user names is found by getUniqueId gte / lte and
116
+ // searched by path. "Find a file that contains X" is searchText WITHOUT path, which narrows by
117
+ // itself (the MCP reads every file named like the query first, across calls): quick results are
118
+ // given and the full search is offered once (cursor = full_scan_cursor, which leaves the quick
119
+ // files out); with no quick match the full search runs unasked.
115
120
  const documentRules =
116
- `DOCUMENTS (a contract, a report, a manual, a letter, any uploaded file the user asks about the content of): FIRST FIND THE FILE, with getFileOutline when you know its storage path, otherwise with getUniqueId using unique_id "src::" and condition "gte" (narrow it by the name the user used). THEN FIND THE PAGE: call searchText with the file's path and the words the user asked about; it returns the file, the page and the matching excerpt. QUOTE THE EXACT TEXT it returned and CITE THE FILE AND THE PAGE ("report.pdf, page 7"); never present a paraphrase as a quote. If searchText answers no_page_text, the file was indexed before page text existed: read it with readFileContent instead, paging with the cursor until END OF FILE, and cite the file. When searchText and the file's records come back empty over files that HAVE page text, say that the data does not have it and name the files and the terms you searched. Never fill the gap from your general knowledge, and never from the web${webAccess
121
+ `DOCUMENTS (a contract, a report, a manual, a letter, any uploaded file the user asks about the content of): FIRST FIND THE FILE, with getFileOutline when you know its storage path, otherwise with getUniqueId using unique_id "src::" and condition "gte" (narrow it by the name the user used; condition "lte" with the file name alone finds it in any folder). THEN FIND THE PAGE: call searchText with the file's path and the words the user asked about; it returns the file, the page and the matching excerpt. When the user did not name a file ("find a file that contains X"), call searchText WITHOUT path: it narrows by itself. It first searches every file whose name matches: while quick_complete is false, keep its hits and call again with next_cursor without answering yet. When quick_complete is true, give the quick results, then ALWAYS ask the user once whether they want all files searched too, since they may be looking for something else, and only if they say yes call searchText again with cursor = full_scan_cursor (it leaves out the files already searched). With no quick match it searches every other file itself: follow next_cursor until search_complete is true, and once its hits answer the question, answer and ask the user before reading the rest. QUOTE THE EXACT TEXT it returned and CITE THE FILE AND THE PAGE ("report.pdf, page 7"); never present a paraphrase as a quote. If searchText answers no_page_text, the file was indexed before page text existed: read it with readFileContent instead, paging with the cursor until END OF FILE, and cite the file. When searchText and the file's records come back empty over files that HAVE page text, say that the data does not have it and name the files and the terms you searched. Never fill the gap from your general knowledge, and never from the web${webAccess
117
122
  ? ` without saying so. WEB ACCESS IS ON for this project: when the user asks for something that is not in the project's data, you may search the web for it, but every such fact must be marked as coming from the web (name the site), kept apart from what the project's data says, and never used to fill in or complete a document's content. This is the one exception to the four sources named above.`
118
123
  : `: this chat has no web tool.`}`;
119
124
 
@@ -37,6 +37,8 @@
37
37
  * requests to today.
38
38
  */
39
39
 
40
+ import { normalizeStoredPathTarget, normalizeTrailingInlineToken } from './links';
41
+
40
42
  export type RetrievalHit = { path: string; page: number };
41
43
 
42
44
  export type RetrievalNote = {
@@ -259,16 +261,22 @@ function noteFromToolBlocks(body: any): RetrievalNote | null {
259
261
  export function retrievalNoteFromText(text: string | null | undefined): RetrievalNote | null {
260
262
  if (typeof text !== 'string' || !text) return null;
261
263
  var note = emptyNote('answer');
262
- // [label](db:path) and [label](db:path "title"); the path ends at the closing
263
- // paren or at the title's opening quote. Bounded character class, no nested
264
- // quantifiers, so a long answer cannot make this slow.
265
- var link = /\]\(db:([^)\s"]+)/g;
264
+ // [label](db:path) and [label](db:path "title"). The path is read with the SAME
265
+ // grammar the chip renderer uses (createInlineLinkRegex's path branch): spaces
266
+ // allowed, one level of balanced parens. The old `[^)\s"]+` stopped at the
267
+ // first space or ")", so `db:testing/2023-09 (1).xlsx` was remembered as
268
+ // `testing/2023-09` and the encoded form as `testing/2023-09%20(1`, and the
269
+ // citation chip drawn from this note linked to a file that does not exist.
270
+ // One character per step and disjoint alternatives, so it stays linear.
271
+ var link = /\]\(db:((?:[^()\n"]|\([^()\n"]*\))+)(?:"[^"\n]*")?\)/g;
266
272
  var m: RegExpExecArray | null;
267
- while ((m = link.exec(text)) !== null) pushUnique(note.files, m[1]);
268
- var src = /src::([^\s"'`<>)\]]+)/g;
273
+ while ((m = link.exec(text)) !== null) pushUnique(note.files, normalizeStoredPathTarget(m[1]));
274
+ // src::<token>, read exactly as classifyInlineLink reads it: the token runs to
275
+ // whitespace and normalizeTrailingInlineToken drops sentence punctuation and
276
+ // unmatched wrappers while keeping a balanced `(1)` inside the name.
277
+ var src = /src::(\S+)/g;
269
278
  while ((m = src.exec(text)) !== null) {
270
- // Trailing sentence punctuation is prose, not path.
271
- pushUnique(note.files, m[1].replace(/[.,;:!?]+$/, ''));
279
+ pushUnique(note.files, normalizeStoredPathTarget(normalizeTrailingInlineToken(m[1])));
272
280
  }
273
281
  return noteHasContent(note) ? note : null;
274
282
  }