bunnyquery 1.16.1 → 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/bunnyquery.js CHANGED
@@ -536,8 +536,8 @@ 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.
537
537
  Knowledge lookup: Before saying you don't know or that something isn't in the chat history, ALWAYS query this project's database through the available MCP tools to look for the answer. The user's data is the source of truth - the chat transcript is not. Only respond with "I don't know" or "I couldn't find that" after you have actually searched the project's data and come back empty.
538
538
  ${groundingRules}
539
- NUMBERS FROM A SPREADSHEET: use queryGrid, never mental arithmetic over records. A total, a count, an average, a "how many mention X", a "which one is biggest" - all of those are computed server-side over EVERY row of the file and come back with the sheet, the row count and the row numbers they were made from. Records are a SAMPLE, and a sample added up is a confident wrong number. Quote the row count and the sheet alongside the figure so the reader can check it.
540
- CALL queryGrid describe FIRST, before any figure. Workbooks routinely state the same money more than once: a detail sheet, then per-song, per-album and per-artist sheets that each re-total it, plus a summary sheet whose bottom row is the file total. Those look like four different answers and are one. describe names which sheets restate which, and which rows are totals. Pick ONE sheet, say which you picked, and never add figures across a sheet and its summary. If the reply carries a warning about restatement, repeat it to the user.
539
+ FINDING THE DATA: the database is the way in, for every kind of file. Step 1, getTables with fetch_all true. When the list runs past one page, or no name obviously fits, search the table names with the words the user used, BOTH ways: condition "gte" (begins with) and condition "lte" (ends with). Step 2, pick EVERY table that could hold the answer, not the first that fits. Step 3, in each of those tables, getIndexes and getTags with fetch_all true to learn the exact index names and tag values; when the exact spelling is unknown, search both ways there too: getTags with condition "gte" and again with "lte"; getIndexes with order {by: "index_name", value: <the words>, condition: "gte"} and again with "lte". Step 4, getRecords in that table and group with the selector that matched: an index (string values take "gte" for begins with and "lte" for ends with), one exact tag, or no selector for the whole table, always with fetch_all true. A known id skips the steps: getUniqueId with the id, its start (condition "gte") or its end (condition "lte", a file name without its folder) lists it across every table with no table_name; then getRecords by unique_id, or getRecords with reference when a record_id or unique_id is known, adding table_name and access_group to narrow it.
540
+ NUMBERS FROM A SPREADSHEET are computed from the ROWS, never from one page and never from a guess. Each row of each sheet is one record in its table: reference "src::<path>", unique_id "row::<path>#<sheet>#R<n>", the cells by header name, plus "_sheet", "_row", "_grain" ("detail" or "summary") and, on a total or preamble row, "_row_type". Its tags carry the file name, the sheet, the grain and up to four key values of the row (a name, a code), so getRecords with one exact tag selects every row about that thing across all the files in the table. Workbooks state the same money more than once: a detail sheet, then per-song, per-album and per-artist sheets that re-total it, plus a summary. Use rows whose "_grain" is "detail" and whose "_row_type" is not "total", pick ONE sheet per file and say which, and never add a sheet to its summary. Fetch the COMPLETE matching set (fetch_all true, or page until pagination.complete is true), keep only the rows whose column or tag names what was asked, then add them up carefully, in groups, and check that the group sums agree with the grand total. Quote the row count, the sheet(s) and the file(s) the figure was made from and label it as calculated.
541
541
  A FILE TOTAL IS NOT A ROW'S TOTAL. The biggest number on a summary sheet is the whole file, not the thing that was asked about. Before quoting any figure, check it is scoped to what the question named: filter by the column that identifies it and report how many rows matched.
542
542
  ${documentRules}
543
543
  Complete answers over stored data: The database holds one record per spreadsheet row, and each uploaded file becomes many records. ONE file is routinely SPLIT ACROSS SEVERAL TABLES - a summary row in one table, its page or row content in another, its extracted photos and other media in "__MEDIA__", and the indexer often invents a differently-named table on each pass. An index or tag filter matches inside ONE table only and requires table_name: on getRecords, an index or tag sent with table_name but no access_group is auto-filled with access_group "authorized", but THIS project indexes at access_group ${indexGroupLiteral}, so pass access_group ${indexGroupLiteral} EXPLICITLY on EVERY query that names a table_name here, index or tag or plain - the auto-fill would search a group this project's data is not in and come back empty, and leaving access_group off a plain table query does NOT mean "all groups": unless you are the project's owner the server reads a table with no group as access_group 0 (public only), so a table indexed at ${indexGroupLiteral} comes back empty with its records sitting right there. Files uploaded before the project's setting changed may sit at another group, so when a scoped query comes back empty, retry it across the other groups (0, 1, "private") before concluding there is nothing, while an index or tag WITHOUT table_name FAILS with an error instead of answering, so read the error rather than guessing. Reference is the exception: reference ALONE spans EVERY table and EVERY access group, so getRecords with reference "src::<the file's storage path>" is the one call that returns a whole file's records wherever the indexer put them. Adding table_name narrows it to that table; access_group WITHOUT table_name fails with '"table" is required'; table_name on its own returns that whole table across all access groups ONLY for the project's owner, and only its access_group 0 records for any other user, so name the group whenever you name a table. For anything NOT scoped to a single file, call getTables FIRST, run the query once per table that could hold the answer, and combine the results. For any request that counts, sums, totals, lists every match, compares across records, finds which one, or asks whether something is present or ABSENT (for example "how many", "total spent", "which card", "is there any", "\uC5C6\uC5B4?", "\uD558\uB098\uB3C4 \uC5C6\uB098?"), you MUST read the COMPLETE matching set before answering. Query with fetch_all set to true, or page through getToolResponsePage until pagination.complete is true, across EVERY table and EVERY relevant file. A single default query returns only the first page (about 50 records). That is a SAMPLE. Never treat it as the whole dataset. If you already answered from one table and then realise another table holds more, do not simply apologise: re-run the sweep and give the complete answer.
@@ -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.16.1" ;
9170
+ var BQ_VERSION = "1.17.1" ;
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
@@ -580,8 +580,8 @@ 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.
581
581
  Knowledge lookup: Before saying you don't know or that something isn't in the chat history, ALWAYS query this project's database through the available MCP tools to look for the answer. The user's data is the source of truth - the chat transcript is not. Only respond with "I don't know" or "I couldn't find that" after you have actually searched the project's data and come back empty.
582
582
  ${groundingRules}
583
- NUMBERS FROM A SPREADSHEET: use queryGrid, never mental arithmetic over records. A total, a count, an average, a "how many mention X", a "which one is biggest" - all of those are computed server-side over EVERY row of the file and come back with the sheet, the row count and the row numbers they were made from. Records are a SAMPLE, and a sample added up is a confident wrong number. Quote the row count and the sheet alongside the figure so the reader can check it.
584
- CALL queryGrid describe FIRST, before any figure. Workbooks routinely state the same money more than once: a detail sheet, then per-song, per-album and per-artist sheets that each re-total it, plus a summary sheet whose bottom row is the file total. Those look like four different answers and are one. describe names which sheets restate which, and which rows are totals. Pick ONE sheet, say which you picked, and never add figures across a sheet and its summary. If the reply carries a warning about restatement, repeat it to the user.
583
+ FINDING THE DATA: the database is the way in, for every kind of file. Step 1, getTables with fetch_all true. When the list runs past one page, or no name obviously fits, search the table names with the words the user used, BOTH ways: condition "gte" (begins with) and condition "lte" (ends with). Step 2, pick EVERY table that could hold the answer, not the first that fits. Step 3, in each of those tables, getIndexes and getTags with fetch_all true to learn the exact index names and tag values; when the exact spelling is unknown, search both ways there too: getTags with condition "gte" and again with "lte"; getIndexes with order {by: "index_name", value: <the words>, condition: "gte"} and again with "lte". Step 4, getRecords in that table and group with the selector that matched: an index (string values take "gte" for begins with and "lte" for ends with), one exact tag, or no selector for the whole table, always with fetch_all true. A known id skips the steps: getUniqueId with the id, its start (condition "gte") or its end (condition "lte", a file name without its folder) lists it across every table with no table_name; then getRecords by unique_id, or getRecords with reference when a record_id or unique_id is known, adding table_name and access_group to narrow it.
584
+ NUMBERS FROM A SPREADSHEET are computed from the ROWS, never from one page and never from a guess. Each row of each sheet is one record in its table: reference "src::<path>", unique_id "row::<path>#<sheet>#R<n>", the cells by header name, plus "_sheet", "_row", "_grain" ("detail" or "summary") and, on a total or preamble row, "_row_type". Its tags carry the file name, the sheet, the grain and up to four key values of the row (a name, a code), so getRecords with one exact tag selects every row about that thing across all the files in the table. Workbooks state the same money more than once: a detail sheet, then per-song, per-album and per-artist sheets that re-total it, plus a summary. Use rows whose "_grain" is "detail" and whose "_row_type" is not "total", pick ONE sheet per file and say which, and never add a sheet to its summary. Fetch the COMPLETE matching set (fetch_all true, or page until pagination.complete is true), keep only the rows whose column or tag names what was asked, then add them up carefully, in groups, and check that the group sums agree with the grand total. Quote the row count, the sheet(s) and the file(s) the figure was made from and label it as calculated.
585
585
  A FILE TOTAL IS NOT A ROW'S TOTAL. The biggest number on a summary sheet is the whole file, not the thing that was asked about. Before quoting any figure, check it is scoped to what the question named: filter by the column that identifies it and report how many rows matched.
586
586
  ${documentRules}
587
587
  Complete answers over stored data: The database holds one record per spreadsheet row, and each uploaded file becomes many records. ONE file is routinely SPLIT ACROSS SEVERAL TABLES - a summary row in one table, its page or row content in another, its extracted photos and other media in "__MEDIA__", and the indexer often invents a differently-named table on each pass. An index or tag filter matches inside ONE table only and requires table_name: on getRecords, an index or tag sent with table_name but no access_group is auto-filled with access_group "authorized", but THIS project indexes at access_group ${indexGroupLiteral}, so pass access_group ${indexGroupLiteral} EXPLICITLY on EVERY query that names a table_name here, index or tag or plain - the auto-fill would search a group this project's data is not in and come back empty, and leaving access_group off a plain table query does NOT mean "all groups": unless you are the project's owner the server reads a table with no group as access_group 0 (public only), so a table indexed at ${indexGroupLiteral} comes back empty with its records sitting right there. Files uploaded before the project's setting changed may sit at another group, so when a scoped query comes back empty, retry it across the other groups (0, 1, "private") before concluding there is nothing, while an index or tag WITHOUT table_name FAILS with an error instead of answering, so read the error rather than guessing. Reference is the exception: reference ALONE spans EVERY table and EVERY access group, so getRecords with reference "src::<the file's storage path>" is the one call that returns a whole file's records wherever the indexer put them. Adding table_name narrows it to that table; access_group WITHOUT table_name fails with '"table" is required'; table_name on its own returns that whole table across all access groups ONLY for the project's owner, and only its access_group 0 records for any other user, so name the group whenever you name a table. For anything NOT scoped to a single file, call getTables FIRST, run the query once per table that could hold the answer, and combine the results. For any request that counts, sums, totals, lists every match, compares across records, finds which one, or asks whether something is present or ABSENT (for example "how many", "total spent", "which card", "is there any", "\uC5C6\uC5B4?", "\uD558\uB098\uB3C4 \uC5C6\uB098?"), you MUST read the COMPLETE matching set before answering. Query with fetch_all set to true, or page through getToolResponsePage until pagination.complete is true, across EVERY table and EVERY relevant file. A single default query returns only the first page (about 50 records). That is a SAMPLE. Never treat it as the whole dataset. If you already answered from one table and then realise another table holds more, do not simply apologise: re-run the sweep and give the complete answer.
@@ -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;