bunnyquery 1.17.0 → 1.17.1

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.17.1",
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);
@@ -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
  }