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/bunnyquery.js CHANGED
@@ -530,7 +530,7 @@ Extracted content of attached office files (read inline below; do NOT fetch thei
530
530
  WHEN THE DATA DOES NOT HAVE IT, SAY SO. Once you have searched the way these rules require and nothing answers the question, tell the user plainly, in their language, that this project's data does not contain it, and say what you searched (the tables, files or terms) so they can tell missing data from a missed search. Do not answer from memory instead, and do not turn a missing answer into a general explanation of the topic. Offer what would let you answer it: ${canUpload === false ? `another name or file to look under, or asking the project's owner to add it` : `the document to upload, or another name or file to look under`}.
531
531
  KEEP WHAT THE DATA SAYS APART FROM WHAT YOU WORKED OUT. A total you computed, a comparison, a trend, an interpretation or a recommendation is yours, not the data's: label it as such ("calculated from...", "this suggests...") and name the rows or files it was made from. Never present an estimate, an assumption or an inference as something the data states.
532
532
  These three rules govern every claim about the project's data. They do not limit the About BunnyQuery section (answer product questions from it), a greeting, or text the user explicitly asks you to write.`;
533
- const documentRules = `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 ? ` 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.` : `: this chat has no web tool.`}`;
533
+ const documentRules = `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 ? ` 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.` : `: this chat has no web tool.`}`;
534
534
  let systemPrompt = `
535
535
  You are a dedicated assistant for the project ID: "${projectId}".
536
536
  Scope: Only answer questions about this project and its data. Do not answer questions about other projects or topics unrelated to this project. When the user refers to "my database", "my data", or "my files", treat those as references to this project's database and file storage. The ONE exception is BunnyQuery itself - what this app is, what it can do, and how to use it - which is always in scope: answer it from the "About BunnyQuery" section at the end of this prompt.
@@ -948,6 +948,11 @@ Index the REMAINING windows - one record per row/item, looking at any page image
948
948
  return encodeURIComponent(s);
949
949
  }).join("/");
950
950
  }
951
+ function normalizeStoredPathTarget(value) {
952
+ var p = String(value || "").trim().replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+/g, "/");
953
+ if (!/\s/.test(p) && /%[0-9A-Fa-f]{2}/.test(p)) p = safeDecodeURIComponent(p);
954
+ return p;
955
+ }
951
956
  function normalizeAttachmentPathCandidate(value) {
952
957
  return safeDecodeURIComponent((value || "").trim()).replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+/g, "/");
953
958
  }
@@ -1107,14 +1112,14 @@ Index the REMAINING windows - one record per row/item, looking at any page image
1107
1112
  tail
1108
1113
  };
1109
1114
  }
1110
- var srcPath = readExpiredAttachmentHref(rawPath) || (srcIsUrl ? extractRemotePathFromAttachmentHref(rawPath, ctx.projectId) || normalizeAttachmentPathCandidate(rawPath) : rawPath.trim().replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+/g, "/"));
1115
+ var srcPath = readExpiredAttachmentHref(rawPath) || (srcIsUrl ? extractRemotePathFromAttachmentHref(rawPath, ctx.projectId) || normalizeAttachmentPathCandidate(rawPath) : normalizeStoredPathTarget(rawPath));
1111
1116
  var srcBuilt = asStoredFile(srcPath, srcPath);
1112
1117
  return srcBuilt ? { part: srcBuilt.part, tail } : null;
1113
1118
  }
1114
1119
  if (g4 && g5) {
1115
1120
  var dbTarget = /^db:(.+)$/i.exec(g5.trim());
1116
1121
  if (dbTarget) {
1117
- var rawDbPath = dbTarget[1].trim().replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+/g, "/");
1122
+ var rawDbPath = normalizeStoredPathTarget(dbTarget[1].replace(/\s+"[^"\n]*"\s*$/, ""));
1118
1123
  var declared = asStoredFile(rawDbPath, g4);
1119
1124
  if (!declared) return null;
1120
1125
  declared.part.label = truncateLabelForDisplay(g4);
@@ -1370,12 +1375,12 @@ Index the REMAINING windows - one record per row/item, looking at any page image
1370
1375
  function retrievalNoteFromText(text) {
1371
1376
  if (typeof text !== "string" || !text) return null;
1372
1377
  var note = emptyNote("answer");
1373
- var link = /\]\(db:([^)\s"]+)/g;
1378
+ var link = /\]\(db:((?:[^()\n"]|\([^()\n"]*\))+)(?:"[^"\n]*")?\)/g;
1374
1379
  var m;
1375
- while ((m = link.exec(text)) !== null) pushUnique(note.files, m[1]);
1376
- var src = /src::([^\s"'`<>)\]]+)/g;
1380
+ while ((m = link.exec(text)) !== null) pushUnique(note.files, normalizeStoredPathTarget(m[1]));
1381
+ var src = /src::(\S+)/g;
1377
1382
  while ((m = src.exec(text)) !== null) {
1378
- pushUnique(note.files, m[1].replace(/[.,;:!?]+$/, ""));
1383
+ pushUnique(note.files, normalizeStoredPathTarget(normalizeTrailingInlineToken(m[1])));
1379
1384
  }
1380
1385
  return noteHasContent(note) ? note : null;
1381
1386
  }
@@ -9162,7 +9167,7 @@ Index the REMAINING windows - one record per row/item, looking at any page image
9162
9167
  (function() {
9163
9168
  var MCP_PROD = "https://mcp.broadwayinc.computer";
9164
9169
  var MCP_DEV = "https://mcp-dev.broadwayinc.computer";
9165
- var BQ_VERSION = "1.17.0" ;
9170
+ var BQ_VERSION = "1.18.0" ;
9166
9171
  var ATTACHMENT_URL_EXPIRES_SECONDS = 600;
9167
9172
  var GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
9168
9173
  var GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
package/dist/engine.cjs CHANGED
@@ -574,7 +574,7 @@ function buildChatSystemPrompt(params) {
574
574
  WHEN THE DATA DOES NOT HAVE IT, SAY SO. Once you have searched the way these rules require and nothing answers the question, tell the user plainly, in their language, that this project's data does not contain it, and say what you searched (the tables, files or terms) so they can tell missing data from a missed search. Do not answer from memory instead, and do not turn a missing answer into a general explanation of the topic. Offer what would let you answer it: ${canUpload === false ? `another name or file to look under, or asking the project's owner to add it` : `the document to upload, or another name or file to look under`}.
575
575
  KEEP WHAT THE DATA SAYS APART FROM WHAT YOU WORKED OUT. A total you computed, a comparison, a trend, an interpretation or a recommendation is yours, not the data's: label it as such ("calculated from...", "this suggests...") and name the rows or files it was made from. Never present an estimate, an assumption or an inference as something the data states.
576
576
  These three rules govern every claim about the project's data. They do not limit the About BunnyQuery section (answer product questions from it), a greeting, or text the user explicitly asks you to write.`;
577
- const documentRules = `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 ? ` 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.` : `: this chat has no web tool.`}`;
577
+ const documentRules = `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 ? ` 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.` : `: this chat has no web tool.`}`;
578
578
  let systemPrompt = `
579
579
  You are a dedicated assistant for the project ID: "${projectId}".
580
580
  Scope: Only answer questions about this project and its data. Do not answer questions about other projects or topics unrelated to this project. When the user refers to "my database", "my data", or "my files", treat those as references to this project's database and file storage. The ONE exception is BunnyQuery itself - what this app is, what it can do, and how to use it - which is always in scope: answer it from the "About BunnyQuery" section at the end of this prompt.
@@ -1025,6 +1025,11 @@ function encodePathSegments(path) {
1025
1025
  return encodeURIComponent(s);
1026
1026
  }).join("/");
1027
1027
  }
1028
+ function normalizeStoredPathTarget(value) {
1029
+ var p = String(value || "").trim().replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+/g, "/");
1030
+ if (!/\s/.test(p) && /%[0-9A-Fa-f]{2}/.test(p)) p = safeDecodeURIComponent(p);
1031
+ return p;
1032
+ }
1028
1033
  function normalizeAttachmentPathCandidate(value) {
1029
1034
  return safeDecodeURIComponent((value || "").trim()).replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+/g, "/");
1030
1035
  }
@@ -1190,14 +1195,14 @@ function classifyInlineLink(full, groups, ctx) {
1190
1195
  tail
1191
1196
  };
1192
1197
  }
1193
- var srcPath = readExpiredAttachmentHref(rawPath) || (srcIsUrl ? extractRemotePathFromAttachmentHref(rawPath, ctx.projectId) || normalizeAttachmentPathCandidate(rawPath) : rawPath.trim().replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+/g, "/"));
1198
+ var srcPath = readExpiredAttachmentHref(rawPath) || (srcIsUrl ? extractRemotePathFromAttachmentHref(rawPath, ctx.projectId) || normalizeAttachmentPathCandidate(rawPath) : normalizeStoredPathTarget(rawPath));
1194
1199
  var srcBuilt = asStoredFile(srcPath, srcPath);
1195
1200
  return srcBuilt ? { part: srcBuilt.part, tail } : null;
1196
1201
  }
1197
1202
  if (g4 && g5) {
1198
1203
  var dbTarget = /^db:(.+)$/i.exec(g5.trim());
1199
1204
  if (dbTarget) {
1200
- var rawDbPath = dbTarget[1].trim().replace(/\\/g, "/").replace(/^\/+/, "").replace(/\/+/g, "/");
1205
+ var rawDbPath = normalizeStoredPathTarget(dbTarget[1].replace(/\s+"[^"\n]*"\s*$/, ""));
1201
1206
  var declared = asStoredFile(rawDbPath, g4);
1202
1207
  if (!declared) return null;
1203
1208
  declared.part.label = truncateLabelForDisplay(g4);
@@ -1453,12 +1458,12 @@ function noteFromToolBlocks(body) {
1453
1458
  function retrievalNoteFromText(text) {
1454
1459
  if (typeof text !== "string" || !text) return null;
1455
1460
  var note = emptyNote("answer");
1456
- var link = /\]\(db:([^)\s"]+)/g;
1461
+ var link = /\]\(db:((?:[^()\n"]|\([^()\n"]*\))+)(?:"[^"\n]*")?\)/g;
1457
1462
  var m;
1458
- while ((m = link.exec(text)) !== null) pushUnique(note.files, m[1]);
1459
- var src = /src::([^\s"'`<>)\]]+)/g;
1463
+ while ((m = link.exec(text)) !== null) pushUnique(note.files, normalizeStoredPathTarget(m[1]));
1464
+ var src = /src::(\S+)/g;
1460
1465
  while ((m = src.exec(text)) !== null) {
1461
- pushUnique(note.files, m[1].replace(/[.,;:!?]+$/, ""));
1466
+ pushUnique(note.files, normalizeStoredPathTarget(normalizeTrailingInlineToken(m[1])));
1462
1467
  }
1463
1468
  return noteHasContent(note) ? note : null;
1464
1469
  }
@@ -9536,6 +9541,7 @@ exports.normalizeChatGreeting = normalizeChatGreeting;
9536
9541
  exports.normalizeExt = normalizeExt;
9537
9542
  exports.normalizeProjectAccessSetting = normalizeProjectAccessSetting;
9538
9543
  exports.normalizeSkipDuplicateFiles = normalizeSkipDuplicateFiles;
9544
+ exports.normalizeStoredPathTarget = normalizeStoredPathTarget;
9539
9545
  exports.normalizeTextContent = normalizeTextContent;
9540
9546
  exports.normalizeTrailingInlineToken = normalizeTrailingInlineToken;
9541
9547
  exports.normalizeUploadAccessGroup = normalizeUploadAccessGroup;