bunnyquery 1.21.0 → 1.21.3
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/README.md +22 -6
- package/bunnyquery.js +118 -34
- package/dist/engine.cjs +106 -28
- package/dist/engine.cjs.map +1 -1
- package/dist/engine.d.mts +26 -2
- package/dist/engine.d.ts +26 -2
- package/dist/engine.mjs +106 -28
- package/dist/engine.mjs.map +1 -1
- package/package.json +1 -1
- package/src/engine/citations.ts +12 -0
- package/src/engine/config.ts +16 -2
- package/src/engine/prompts/chat_system_prompt.ts +3 -3
- package/src/engine/prompts/indexing_system_prompt.ts +3 -3
- package/src/engine/prompts/indexing_user_message.ts +20 -0
- package/src/engine/requests.ts +39 -2
- package/src/engine/retrieval_memory.ts +21 -6
- package/src/engine/session.ts +42 -9
package/dist/engine.cjs
CHANGED
|
@@ -278,6 +278,9 @@ function crefSupported() {
|
|
|
278
278
|
function windowedIndexingEnabled() {
|
|
279
279
|
return _config?.windowedIndexing === true;
|
|
280
280
|
}
|
|
281
|
+
function workerIndexEndingsEnabled() {
|
|
282
|
+
return _config?.workerIndexEndings === true;
|
|
283
|
+
}
|
|
281
284
|
function statusPushEnabled() {
|
|
282
285
|
return _config?.statusPush === true && typeof _config?.onRequestStatus === "function";
|
|
283
286
|
}
|
|
@@ -1065,8 +1068,8 @@ WHEN THE DATA DOES NOT HAVE IT, SAY SO. Once you have searched the way these rul
|
|
|
1065
1068
|
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.
|
|
1066
1069
|
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.`;
|
|
1067
1070
|
const webRule = webAccess ? `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 or a record. This is the one exception to the four sources named above.` : `This chat has no web tool: the web is never a source here.`;
|
|
1068
|
-
const documentRules = `DOCUMENTS (a contract, a report, a manual, a letter, any uploaded file the user asks about the content of):
|
|
1069
|
-
WRONG ANSWER: when the user says an answer is wrong (or sends "This answer seems wrong. Please check it again against the documents."), re-read the pages you cited and search again, passing searchText "question" = the user's ORIGINAL question that the disputed answer answered, never the complaint message itself. Then do exactly one of: correct the answer only; correct the answer and call correctSearchLink (when it is among your tools); or keep the answer and quote the text that supports it. Call correctSearchLink only with the page and an exact quote that prove it, and never change data on the user's word alone.`;
|
|
1071
|
+
const documentRules = `DOCUMENTS (a contract, a report, a manual, a letter, any uploaded file the user asks about the content of): when the user NAMED a file (its file name; a document title, a quote or a code they mention is NOT a file name: searchText finds those inside the files), first find its storage path by its "src::" record (see WHERE INDEXED CONTENT LIVES) using the name the user used, then find the page with searchText and that path. A spreadsheet's sheets are page text too: a hit names its sheet and rows, and the row itself is a record (its unique_id is the hit's row_id_prefix plus the row number); a spreadsheet indexed before 2026-11-25 has no page text, so read its rows instead (readFileContent, or its records). When they did not name a file, your FIRST call is searchText without a path: no table list, no file lookup before it. Never list or look up files (getUniqueId on "src::") to find out whether a document, quote or title exists before searching: searchText's hits name the file, and a search that finds nothing says what it could not cover. Either way follow searchText's description to the end, including asking the user once, after quick results, before it searches all files. QUOTE THE EXACT TEXT it returned and CITE THE FILE AND THE PAGE ("report.pdf, page 7"), or for a hit with "sheet" THE FILE AND THE SHEET ("quote.xlsx, sheet \uCD1D\uAD04"), never a sheet page's number; never present a paraphrase as a quote. A file with no page text is read with readFileContent instead and cited by its file name. In a long file (a manual, a book), when a search of the whole file gives too many hits or none that fit, call getFileOutline and search the chapter that fits with searchText page_from and page_to. When the user asks about the content of the documents, pass searchText "question": that question in the user's own words, without names or personal details that are not about the documents. Leave "question" out for anything else.
|
|
1072
|
+
WRONG ANSWER: when the user says an answer is wrong (or sends "This answer seems wrong. Please check it again against the documents."), re-read the pages you cited (for a sheet hit, the rows: by its row_id_prefix, never readFileContent on a sheet page) and search again, passing searchText "question" = the user's ORIGINAL question that the disputed answer answered, never the complaint message itself. Then do exactly one of: correct the answer only; correct the answer and call correctSearchLink (when it is among your tools); or keep the answer and quote the text that supports it. Call correctSearchLink only with the page and an exact quote that prove it, and never change data on the user's word alone.`;
|
|
1070
1073
|
const groupIsPublic = indexGroupLiteral === '"public"' || indexGroupLiteral === "0";
|
|
1071
1074
|
const accessGroupRule = `THIS PROJECT INDEXES AT access_group ${indexGroupLiteral}: pass access_group ${indexGroupLiteral} EXPLICITLY on EVERY query that names a table_name, whether it filters by index, by tag or by nothing, and never rely on a default: a group left off is NOT "all groups", and any user but the project's owner is then answered from access_group 0 (public) alone${groupIsPublic ? "" : `, so a table indexed at ${indexGroupLiteral} would look empty with its records sitting right there`}. Files uploaded before the project's setting changed may sit at another group, so when a table query comes back empty, retry it in the other groups among 0, 1 and "private" before concluding there is nothing. 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, and access_group WITHOUT table_name fails.`;
|
|
1072
1075
|
let systemPrompt = `
|
|
@@ -1075,7 +1078,7 @@ Scope: Only answer questions about this project and its data. Do not answer ques
|
|
|
1075
1078
|
Knowledge lookup: before saying you don't know, or that something isn't in the chat history, ALWAYS search this project's data with the tools: the project's data lives in its database, not in the earlier messages of this chat.
|
|
1076
1079
|
${groundingRules}
|
|
1077
1080
|
${webRule}
|
|
1078
|
-
FINDING THE DATA: the database is the way in, for every kind of file.
|
|
1081
|
+
FINDING THE DATA: the database is the way in, for every kind of file. A question about what the documents SAY (a procedure, a passage, a definition, how to fix or do something), or one that names a code, a number or a phrase to find (a quote no., a part no., a name), starts with searchText (DOCUMENTS below), not with getTables: the sheets of spreadsheets are in page text too. searchText finds WHICH file, sheet and row holds a value; a total, count or list over rows is still computed from the full row set (NUMBERS FROM A SPREADSHEET below). Everything else (numbers, rows, records, lists, counts, files) follows the search path in getTables' description, with one exception for this project: when getTables' one page is the whole list (end_of_list true), skip its table-name search even when no name fits: you already see every table, and a table is never named after a company, a person or a single fact, so when no table fits, the answer is in a document's text: use searchText (DOCUMENTS below). Pick EVERY table that could hold the answer, not the first that fits. Read getIndexes and getTags one page each, never with fetch_all: name and tag lists can be millions of characters long and are never read whole, so when the name is not on that page, search for it with the user's words as their descriptions say. Never call getTags with neither table_name nor tag: that lists every tag of every table. Then getRecords in that table and group with the selector that matched (an index, one exact tag, or none for the whole table), always with fetch_all true. WHERE INDEXED CONTENT LIVES: a document's extracted content (PDF, Word, slides, scans) is in table "document_entries", one record per row / entry / section, with its page in "page"; spreadsheet rows are in "spreadsheet_rows". Files indexed before 2026-11-20 may still hold theirs in other tables, so a file's records are found wherever they are with getRecords reference "src::<path>" (see the access group rule below); every later mention of a file's records means this call. Every stored file has a record whose unique_id is "src::<its storage path>", so getUniqueId with unique_id "src::" and condition "gte" lists every file across every table (add the start of a path to narrow it; condition "lte" with a file name alone finds it in any folder).
|
|
1079
1082
|
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, 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. A FILE TOTAL IS NOT A ROW'S TOTAL: the biggest number on a summary sheet is the whole file, not the thing asked about, so check every figure is scoped to what the question named (filter by the column that identifies it). Quote the row count, the sheet(s) and the file(s) the figure was made from and label it as calculated.
|
|
1080
1083
|
${documentRules}
|
|
1081
1084
|
${accessGroupRule}
|
|
@@ -1126,13 +1129,13 @@ function buildIndexingSystemPrompt(params) {
|
|
|
1126
1129
|
const { projectId, serviceName, serviceDescription } = params;
|
|
1127
1130
|
const accessGroup = params.accessGroup === "public" || params.accessGroup === "private" ? params.accessGroup : "authorized";
|
|
1128
1131
|
let systemPrompt = `You are a background indexing agent for project ${projectId}.
|
|
1129
|
-
- Image files (.jpg, .jpeg, .png, .gif, .webp) are ALREADY attached inline as image content blocks in the same message: look at them directly, and never fetch an image URL.
|
|
1132
|
+
- Image files (.jpg, .jpeg, .png, .gif, .webp) are ALREADY attached inline as image content blocks in the same message: look at them directly, and never fetch an image URL. Any other image file (.tif, .tiff, .bmp, .heic) is attached only when the message shows an image of it (the server attaches a converted copy when it can); when none is attached, index it from its metadata and never guess its contents.
|
|
1130
1133
|
- Most files (office documents like .docx/.xlsx/.pptx/.hwp/.hwpx/.ods, email messages (.eml), and text/data/code files like .csv/.tsv/.json/.xml/.txt/.md and source code) have ALREADY been extracted on the server and included inline in the user message between the "BEGIN FILE CONTENT" / "END FILE CONTENT" markers - read that directly. If the inline content is a "[skapi: ...]" note, the file could not be extracted - index it from its metadata only.
|
|
1131
1134
|
- BIG SPREADSHEETS / TEXT: the inline content may be only the FIRST part of a large file (it can end with a truncation or "more remains" note). UNLESS this message already embeds a window of the file (in which case the message tells you not to call readFileContent, and you must not), read big spreadsheets and big text/data files WITH THE readFileContent TOOL: it returns the file ONE WINDOW at a time (spreadsheets as coordinate-tagged grid rows, text as a range of characters). Pass the file's storage path. After each window: datafy it into records and SAVE them, THEN if the window says MORE REMAINS call readFileContent again with the cursor it gives you. Repeat until it says END OF FILE, so the WHOLE file is indexed - never stop after the first window.
|
|
1132
1135
|
- PDFs (scanned or not): you do NOT read a PDF with a tool or a URL. Its pages are RENDERED and embedded directly in the user message as IMAGE blocks, a WINDOW of pages at a time. LOOK at the embedded page images and datafy every one. The note beside them tells you whether MORE pages remain: if so, save this window's records and stop (a follow-up pass shows the next window automatically); only when the note says it was the LAST window is the PDF fully seen. Do NOT call readFileContent or web_fetch for a PDF.
|
|
1133
1136
|
- VISION: when the message (a readFileContent window, an embedded PDF page, or an inline attachment) includes IMAGES - scanned/rendered PDF pages, or photos embedded in a spreadsheet next to a row/block - LOOK at them and capture what they show as record data (the reading/values in a scanned table, the part/defect/condition visible in a photo). The image IS part of the data; correlate each photo with its labelled block ("PHOTO A3" markers tie a photo to that grid row).
|
|
1134
|
-
- TRANSCRIBE, DO NOT DESCRIBE. When an image contains ANY text - a label, tag, stamp, form field, serial/part number, handwriting - your FIRST job is to read the characters out and store them VERBATIM, not to describe the scene. A record saying "a red inspection tag with handwritten markings" is worthless: it is unsearchable and every such photo produces the same sentence. Put the characters you can actually read into these EXACT fields, not variations of them: "printed_text" (the pre-printed wording), "handwritten_text" (what a person wrote by hand), and, when you can resolve one, "part_no", "tag_id" and "date". Same reason as the fixed table names: a field called photo_text in one pass and visible_text_notes in the next cannot be queried together. Read PARTIAL values rather than skipping: "500.7402.
|
|
1135
|
-
- IMAGE FILES uploaded as the file itself: if ANY readable character appears ANYWHERE in the image (a label, a stamp, a sign in the background) it counts as an image WITH text - transcribe it per the rule above, and also capture the layout (what appears where) and every entity named. Only a truly text-free image gets description first: a one-line caption, then the objects present with their attributes (type, color, count, condition, position). Either way, save what you extract onto the file's "src::" record with updateRecords, TAG every entity and identifier visible, and INDEX the one number the image offers (a measured value, an amount, a count).
|
|
1137
|
+
- TRANSCRIBE, DO NOT DESCRIBE. When an image contains ANY text - a label, tag, stamp, form field, serial/part number, handwriting - your FIRST job is to read the characters out and store them VERBATIM, not to describe the scene. A record saying "a red inspection tag with handwritten markings" is worthless: it is unsearchable and every such photo produces the same sentence. Put the characters you can actually read into these EXACT fields, not variations of them: "printed_text" (the pre-printed wording), "handwritten_text" (what a person wrote by hand), and, when you can resolve one, "part_no", "serial_no", "tag_id" and "date". Every identifier you read (a serial number, a part number, a tag id, a model code) ALSO goes into "printed_text" or "handwritten_text", exactly as it appears, because those two fields are the image's searchable text. Text can appear at ANY angle (sideways, upside down, mirrored, along a curve): read it in its own orientation, and never call text unreadable only because it is turned. When it is upside down or sideways, watch the look-alikes (6 and 9, 0 and O, 1 and I, Latin and Cyrillic letters of the same shape). Same reason as the fixed table names: a field called photo_text in one pass and visible_text_notes in the next cannot be queried together. Read PARTIAL values rather than skipping: "500.7402.5[?][?]" beats nothing. Write [?] for each character that is genuinely unreadable and copy handwriting character for character - do NOT invent a character, and do NOT replace the whole transcription with a description of what the object looks like. A scene description is a nice extra AFTER the text, never instead of it.
|
|
1138
|
+
- IMAGE FILES uploaded as the file itself: if ANY readable character appears ANYWHERE in the image (a label, a stamp, a sign in the background) it counts as an image WITH text - transcribe it per the rule above, and also capture the layout (what appears where) and every entity named. Only a truly text-free image gets description first: a one-line caption, then the objects present with their attributes (type, color, count, condition, position). Either way, save what you extract onto the file's "src::" record with updateRecords, TAG every entity and identifier visible, and INDEX the one number the image offers (a measured value, an amount, a count). On that same record ALSO set "text_rotation" and "text_legibility". "text_rotation" is the CLOCKWISE turn, 0, 90, 180 or 270, that would make the image's main text upright AS THE IMAGE IS SHOWN TO YOU: 0 when it already reads normally; 180 when it is upside down; 90 when its lines run from bottom to top (the tops of the letters face left); 270 when its lines run from top to bottom (the tops of the letters face right). "text_legibility" is "clear", "partial" or "unreadable" ("none" when there is no text).
|
|
1136
1139
|
- Whatever the file type, this file's identity is "src::" + its storage path (the "storage path" metadata line) - never the inline content or a temporary URL. That record ALREADY EXISTS: the upload pipeline creates it in table "file_summaries" (access group "${accessGroup}") before indexing starts, so posting it again is rejected as a duplicate unique_id. Reference it from every record you write, and add what you learn to it with updateRecords. If that update unexpectedly reports the record does not exist, post it yourself ONCE with that exact "src::" unique_id (table "file_summaries", access group "${accessGroup}") and carry on; this is the ONE exception to the do-NOT-post-the-file-record rules elsewhere in these instructions, because the source identity must never be dropped just because an update failed.
|
|
1137
1140
|
- ACCESS GROUP (hard rule): every record you write for this file - the file record, per-row records, chapters, summaries, intermediates - MUST be posted with access group "${accessGroup}". Pass it explicitly on every postRecords call; do not leave it out and do not vary it between passes of the same file. An access group is part of a record's table key, so records saved under a different group than the file are in a different table and will not come back with the rest of it: a "public" file whose rows were saved as "authorized" is one an anonymous visitor can see the name of and none of the contents of, and a re-index cannot find the strays to clean them up. The one exception is the EXTRACTED MEDIA records in "__MEDIA__", which the pipeline creates for you - leave their group alone and only enrich them.
|
|
1138
1141
|
- REACHABILITY (hard rule): every record you write while indexing this file MUST be reachable from the file's "src::<storage path>" record by following reference - either reference that record directly, or reference something that already reaches it. A record with no reference, or one pointing outside this file's chain, is an ORPHAN: deleting or re-indexing the file removes the reachable records and leaves the orphan behind forever, where it keeps turning up in later answers as stale data. If you create an intermediate record that OTHER records reference (a page record that rows hang off, a sheet or section record), set source.can_remove_referencing_records to true on it; the delete cascade passes a delete through a record only when that record carries the flag OR a unique_id starting "src::" (the file record cascades because its unique_id starts with "src::"; the intermediates you create carry no "src::" id, so they need the flag), and it cascades ONE LEVEL AT A TIME, so EVERY intermediate record in a chain needs its own marker - an unmarked link stops the cascade there and everything below it survives as orphans. When in doubt, reference the file record directly and keep the chain flat.
|
|
@@ -1204,6 +1207,12 @@ ${options.inlineContentPlaceholder}
|
|
|
1204
1207
|
return head + `
|
|
1205
1208
|
Read this file with the readFileContent tool, using the storage path above - do NOT fetch a URL and do NOT rely on a single sample. readFileContent returns the file ONE WINDOW at a time: spreadsheets as coordinate-tagged grid rows (e.g. 'R4 A:E&I NUMBER | B:E1007'), text as a character range, and windows may include embedded photos - LOOK at any images and datafy what they show. Page through EVERY window: for each window SAVE records for its rows/items/pages (postRecords, one record per row/item; spreadsheet rows in "spreadsheet_rows", everything else in "document_entries"), THEN if the window says MORE REMAINS call readFileContent again with the cursor it gives you. Repeat until it says END OF FILE, so the WHOLE file is indexed. Do NOT stop after the first window and do NOT just write a summary. Set every record's reference to exactly "src::" + the storage path above; that file record already exists, so enrich it with updateRecords instead of posting it again.` + (attachment.url ? `
|
|
1206
1209
|
(A temporary URL is provided ONLY as a fallback if readFileContent fails: ${attachment.url})` : "");
|
|
1210
|
+
}
|
|
1211
|
+
if (options?.imageFile) {
|
|
1212
|
+
return head + `- temporary URL: ${attachment.url}
|
|
1213
|
+
` + (options.imageFile === "attached" ? `
|
|
1214
|
+
This is an IMAGE file, attached to this message as an image: read it there, not from the URL. ` : `
|
|
1215
|
+
This is an IMAGE file in a format the AI cannot take directly. When an image of it is attached to this message (the server converts it when it can), read it there; when none is attached, index the file from its metadata only and do not guess its contents. `) + `Transcribe every character FIRST, at whatever angle the text is: "printed_text", "handwritten_text", and "part_no" / "serial_no" / "tag_id", with every identifier also written inside "printed_text" or "handwritten_text". Then set "text_rotation" and "text_legibility" on the file's "src::" record, and only then describe what the image shows.`;
|
|
1207
1216
|
}
|
|
1208
1217
|
return head + `- temporary URL (fetch this to read the file contents): ${attachment.url}`;
|
|
1209
1218
|
}
|
|
@@ -1823,16 +1832,19 @@ function pushGroup(list, value) {
|
|
|
1823
1832
|
if (typeof value === "number" && isFinite(value)) pushUnique(list, String(value));
|
|
1824
1833
|
else pushUnique(list, value);
|
|
1825
1834
|
}
|
|
1826
|
-
function pushHit(list, path, page) {
|
|
1835
|
+
function pushHit(list, path, page, sheet) {
|
|
1827
1836
|
if (typeof path !== "string" || !path.trim()) return;
|
|
1828
1837
|
var n = typeof page === "number" ? page : Number(page);
|
|
1829
1838
|
if (!isFinite(n) || n <= 0) return;
|
|
1830
1839
|
n = Math.floor(n);
|
|
1840
|
+
var sh = typeof sheet === "string" && sheet.trim() ? sheet.trim() : "";
|
|
1831
1841
|
for (var i = 0; i < list.length; i++) {
|
|
1832
|
-
if (list[i].path === path && list[i].page === n) return;
|
|
1842
|
+
if (sh ? list[i].path === path && list[i].sheet === sh : list[i].path === path && list[i].page === n) return;
|
|
1833
1843
|
}
|
|
1834
1844
|
if (list.length >= RETRIEVAL_NOTE_MAX_ITEMS) return;
|
|
1835
|
-
|
|
1845
|
+
var hit = { path: path.trim(), page: n };
|
|
1846
|
+
if (sh) hit.sheet = sh;
|
|
1847
|
+
list.push(hit);
|
|
1836
1848
|
}
|
|
1837
1849
|
function pathFromSrcId(value) {
|
|
1838
1850
|
if (typeof value !== "string") return null;
|
|
@@ -1879,7 +1891,7 @@ function readHits(note, result) {
|
|
|
1879
1891
|
return;
|
|
1880
1892
|
}
|
|
1881
1893
|
if (typeof node.path === "string" && node.page !== void 0) {
|
|
1882
|
-
pushHit(note.hits, node.path, node.page);
|
|
1894
|
+
pushHit(note.hits, node.path, node.page, node.sheet);
|
|
1883
1895
|
}
|
|
1884
1896
|
for (var k in node) {
|
|
1885
1897
|
if (!Object.prototype.hasOwnProperty.call(node, k)) continue;
|
|
@@ -2008,8 +2020,16 @@ function formatRetrievalNote(note) {
|
|
|
2008
2020
|
}
|
|
2009
2021
|
byFile[h.path].push(h.page);
|
|
2010
2022
|
}
|
|
2023
|
+
var sheetsOf = {};
|
|
2024
|
+
for (var s2 = 0; s2 < note.hits.length; s2++) {
|
|
2025
|
+
var hs = note.hits[s2];
|
|
2026
|
+
if (hs.sheet) {
|
|
2027
|
+
if (!sheetsOf[hs.path]) sheetsOf[hs.path] = [];
|
|
2028
|
+
if (sheetsOf[hs.path].indexOf(hs.sheet) === -1) sheetsOf[hs.path].push(hs.sheet);
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2011
2031
|
parts.push("searchText hits " + order.map(function(p) {
|
|
2012
|
-
return p + " p" + byFile[p].join(", p");
|
|
2032
|
+
return sheetsOf[p] ? p + " sheet " + sheetsOf[p].join(", sheet ") : p + " p" + byFile[p].join(", p");
|
|
2013
2033
|
}).join("; "));
|
|
2014
2034
|
}
|
|
2015
2035
|
if (note.tools.length) parts.push("tools " + note.tools.join(", "));
|
|
@@ -2424,6 +2444,13 @@ function getVisionProfile(model) {
|
|
|
2424
2444
|
return { detail, pagesPerWindow: RENDER_PAGES_PER_WINDOW, tile: 1 };
|
|
2425
2445
|
}
|
|
2426
2446
|
var IMAGE_URL_REGEX = /\bhttps?:\/\/[^\s<>"'()\[\]]+?\.(?:jpg|jpeg|png|gif|webp)(?:\?[^\s<>"'()\[\]]*)?/gi;
|
|
2447
|
+
var INDEX_IMAGE_OTHER_EXT = /\.(?:tiff?|bmp|heic|heif)$/i;
|
|
2448
|
+
function indexingImageFile(attachment) {
|
|
2449
|
+
const url = typeof attachment.url === "string" ? attachment.url : "";
|
|
2450
|
+
if (url && new RegExp(IMAGE_URL_REGEX.source, "i").test(url)) return "attached";
|
|
2451
|
+
if (INDEX_IMAGE_OTHER_EXT.test(attachment.name || "") || INDEX_IMAGE_OTHER_EXT.test(attachment.storagePath || "")) return "maybe";
|
|
2452
|
+
return void 0;
|
|
2453
|
+
}
|
|
2427
2454
|
function transformContentWithImages(content) {
|
|
2428
2455
|
if (typeof content !== "string" || !content) {
|
|
2429
2456
|
return content;
|
|
@@ -2863,10 +2890,20 @@ async function notifyAgentSaveAttachment(info) {
|
|
|
2863
2890
|
save_media: !continuing
|
|
2864
2891
|
}))
|
|
2865
2892
|
} : {};
|
|
2866
|
-
const
|
|
2893
|
+
const singlePass = !visionFile && !windowedRead && !pagedRead && !continuing;
|
|
2894
|
+
const imageFile = singlePass && !parsedContent && !serverExtract ? indexingImageFile(attachment) : void 0;
|
|
2895
|
+
const fileUrlDetail = imageFile && platform === "openai" ? getOpenAIImageDetail(info.model || DEFAULT_OPENAI_MODEL) : void 0;
|
|
2896
|
+
const skapiFileUrls = attachment.url && attachment.storagePath ? {
|
|
2897
|
+
_skapi_file_urls: [{
|
|
2898
|
+
path: attachment.storagePath,
|
|
2899
|
+
url: attachment.url,
|
|
2900
|
+
...singlePass ? { index_end: true } : {},
|
|
2901
|
+
...fileUrlDetail ? { detail: fileUrlDetail } : {}
|
|
2902
|
+
}]
|
|
2903
|
+
} : {};
|
|
2867
2904
|
const userMessage = visionFile && renderPlaceholder ? buildIndexingRenderMessage(attachment, renderPlaceholder, renderFrom) : windowedRead && windowPlaceholder ? buildIndexingWindowMessage(attachment, windowPlaceholder, false) : continuing ? buildIndexingContinueMessage(attachment) : buildIndexingUserMessage(
|
|
2868
2905
|
attachment,
|
|
2869
|
-
parsedContent ? { inlineContent: parsedContent } : placeholder ? { inlineContentPlaceholder: placeholder } : pagedRead ? { pagedRead: true } : void 0
|
|
2906
|
+
parsedContent ? { inlineContent: parsedContent } : placeholder ? { inlineContentPlaceholder: placeholder } : pagedRead ? { pagedRead: true } : imageFile ? { imageFile } : void 0
|
|
2870
2907
|
);
|
|
2871
2908
|
const systemPrompt = buildIndexingSystemPrompt({
|
|
2872
2909
|
// The model copies this id verbatim into project_id tool calls, so it must be
|
|
@@ -3771,10 +3808,20 @@ function citationsFor(note) {
|
|
|
3771
3808
|
var out = [];
|
|
3772
3809
|
var hitPaths = [];
|
|
3773
3810
|
var byPath = {};
|
|
3811
|
+
var sheetsByPath = {};
|
|
3774
3812
|
var i;
|
|
3775
3813
|
for (i = 0; i < note.hits.length; i++) {
|
|
3776
3814
|
var h = note.hits[i];
|
|
3777
3815
|
if (!h || typeof h.path !== "string" || !isMintablePath(h.path)) continue;
|
|
3816
|
+
if (typeof h.sheet === "string" && h.sheet) {
|
|
3817
|
+
if (!byPath[h.path]) {
|
|
3818
|
+
byPath[h.path] = [];
|
|
3819
|
+
hitPaths.push(h.path);
|
|
3820
|
+
}
|
|
3821
|
+
if (!sheetsByPath[h.path]) sheetsByPath[h.path] = [];
|
|
3822
|
+
if (sheetsByPath[h.path].indexOf(h.sheet) === -1) sheetsByPath[h.path].push(h.sheet);
|
|
3823
|
+
continue;
|
|
3824
|
+
}
|
|
3778
3825
|
var page = typeof h.page === "number" ? h.page : Number(h.page);
|
|
3779
3826
|
if (!isFinite(page) || page <= 0) continue;
|
|
3780
3827
|
page = Math.floor(page);
|
|
@@ -3786,6 +3833,10 @@ function citationsFor(note) {
|
|
|
3786
3833
|
}
|
|
3787
3834
|
for (i = 0; i < hitPaths.length; i++) {
|
|
3788
3835
|
var p = hitPaths[i];
|
|
3836
|
+
var sheets = sheetsByPath[p] || [];
|
|
3837
|
+
for (var sj = 0; sj < sheets.length; sj++) {
|
|
3838
|
+
out.push({ path: p, label: citationFileName(p) + " \xB7 " + sheets[sj] });
|
|
3839
|
+
}
|
|
3789
3840
|
var pages = byPath[p].slice().sort(function(a, b) {
|
|
3790
3841
|
return a - b;
|
|
3791
3842
|
});
|
|
@@ -5874,6 +5925,18 @@ var _ChatSession = class _ChatSession {
|
|
|
5874
5925
|
/** Pages watching a project's background indexing queue (watchIndexQueue). */
|
|
5875
5926
|
this._iqWatches = [];
|
|
5876
5927
|
this._chainsRestored = false;
|
|
5928
|
+
/**
|
|
5929
|
+
* A run closed idle (a complete queue look found no pass of it) whose record still says
|
|
5930
|
+
* 'working': when it is THIS user's run of a client-driven file and no browser tab here
|
|
5931
|
+
* keeps its chain (a reload, a discarded tab, or a browser without localStorage lost
|
|
5932
|
+
* it), nothing will ever send its next pass, so run:: says CHAIN_LOST_TEXT. Never for a
|
|
5933
|
+
* worker-driven file (the worker writes its endings), another user's run (their chain is
|
|
5934
|
+
* in their browser), or a run whose next pass is being looked for.
|
|
5935
|
+
*/
|
|
5936
|
+
/** Files the last queue look listed pending or running, settled bubbles included. */
|
|
5937
|
+
this._rawListedIndexKeys = {};
|
|
5938
|
+
/** Runs found idle on one complete look, waiting for a second before "lost" (see below). */
|
|
5939
|
+
this._lostLooks = {};
|
|
5877
5940
|
/**
|
|
5878
5941
|
* Pick up indexing passes the WORKER minted, which no client ever dispatched.
|
|
5879
5942
|
*
|
|
@@ -6269,6 +6332,7 @@ var _ChatSession = class _ChatSession {
|
|
|
6269
6332
|
_recordLiveIndexKeys(lists) {
|
|
6270
6333
|
var next = {};
|
|
6271
6334
|
var running = {};
|
|
6335
|
+
var rawListed = {};
|
|
6272
6336
|
var truncated = false;
|
|
6273
6337
|
var runningTruncated = false;
|
|
6274
6338
|
var settledIds = {};
|
|
@@ -6291,6 +6355,11 @@ var _ChatSession = class _ChatSession {
|
|
|
6291
6355
|
for (var i = 0; i < list.length; i++) {
|
|
6292
6356
|
var item = list[i];
|
|
6293
6357
|
if (!item || item.status !== "pending" && item.status !== "running") continue;
|
|
6358
|
+
var rawRef = parseIndexingRequestText(listedRequestText(item));
|
|
6359
|
+
if (rawRef) {
|
|
6360
|
+
if (rawRef.path) rawListed[rawRef.path] = true;
|
|
6361
|
+
if (rawRef.name) rawListed[rawRef.name] = true;
|
|
6362
|
+
}
|
|
6294
6363
|
if (item.id && settledIds[item.id]) continue;
|
|
6295
6364
|
var text = listedRequestText(item);
|
|
6296
6365
|
if (!isIndexingRequestText(text)) continue;
|
|
@@ -6332,6 +6401,7 @@ var _ChatSession = class _ChatSession {
|
|
|
6332
6401
|
}
|
|
6333
6402
|
}
|
|
6334
6403
|
this.state.liveIndexKeys = next;
|
|
6404
|
+
this._rawListedIndexKeys = rawListed;
|
|
6335
6405
|
if (this.state.liveIndexRunningChecked !== !runningTruncated) changed = true;
|
|
6336
6406
|
var settledNow = this.state.liveIndexSettled || {};
|
|
6337
6407
|
var settledNext = {};
|
|
@@ -10154,33 +10224,40 @@ var _ChatSession = class _ChatSession {
|
|
|
10154
10224
|
else if (!Object.keys(self._openMap()).length && !self._viewMounted()) self._stopStatusPush();
|
|
10155
10225
|
});
|
|
10156
10226
|
}
|
|
10157
|
-
|
|
10158
|
-
|
|
10159
|
-
|
|
10160
|
-
* keeps its chain (a reload, a discarded tab, or a browser without localStorage lost
|
|
10161
|
-
* it), nothing will ever send its next pass, so run:: says CHAIN_LOST_TEXT. Never for a
|
|
10162
|
-
* worker-driven file (the worker writes its endings), another user's run (their chain is
|
|
10163
|
-
* in their browser), or a run whose next pass is being looked for.
|
|
10164
|
-
*/
|
|
10227
|
+
_lostKey(run) {
|
|
10228
|
+
return run.projectId + "\0" + run.storagePath + "\0" + run.since;
|
|
10229
|
+
}
|
|
10165
10230
|
_flipIfChainLost(run) {
|
|
10166
10231
|
var self = this;
|
|
10167
|
-
if (!run.owner) return;
|
|
10232
|
+
if (!run.owner) return false;
|
|
10233
|
+
var raw = this._rawListedIndexKeys || {};
|
|
10234
|
+
if (raw[run.storagePath] || run.filename && raw[run.filename]) {
|
|
10235
|
+
delete this._lostLooks[this._lostKey(run)];
|
|
10236
|
+
return true;
|
|
10237
|
+
}
|
|
10238
|
+
var lk = this._lostKey(run);
|
|
10239
|
+
if (!this._lostLooks[lk]) {
|
|
10240
|
+
this._lostLooks[lk] = 1;
|
|
10241
|
+
return true;
|
|
10242
|
+
}
|
|
10243
|
+
delete this._lostLooks[lk];
|
|
10168
10244
|
var live = null;
|
|
10169
10245
|
try {
|
|
10170
10246
|
live = this.host.getIdentity();
|
|
10171
10247
|
} catch (e2) {
|
|
10172
10248
|
live = null;
|
|
10173
10249
|
}
|
|
10174
|
-
if (!live || !live.userId || live.userId !== run.owner || live.projectId !== run.projectId) return;
|
|
10250
|
+
if (!live || !live.userId || live.userId !== run.owner || live.projectId !== run.projectId) return false;
|
|
10175
10251
|
var name = run.filename || run.storagePath.split("/").pop() || run.storagePath;
|
|
10176
|
-
if (this._isWorkerDrivenIndexing(name, void 0)) return;
|
|
10177
|
-
if (
|
|
10252
|
+
if (this._isWorkerDrivenIndexing(name, void 0)) return false;
|
|
10253
|
+
if (workerIndexEndingsEnabled() && !isPagedReadFile(name, void 0)) return false;
|
|
10254
|
+
if (this._chainKept(run.projectId, run.storagePath)) return false;
|
|
10178
10255
|
for (var q = 0; q < this.bgTaskQueue.length; q++) {
|
|
10179
10256
|
var e = this.bgTaskQueue[q];
|
|
10180
|
-
if (e && e.projectId === run.projectId && e.storagePath === run.storagePath) return;
|
|
10257
|
+
if (e && e.projectId === run.projectId && e.storagePath === run.storagePath) return false;
|
|
10181
10258
|
}
|
|
10182
10259
|
if (this._recPending) for (var c in this._recPending) {
|
|
10183
|
-
if (this._recPending[c].kind === "indexing" && this._recPending[c].projectId === run.projectId) return;
|
|
10260
|
+
if (this._recPending[c].kind === "indexing" && this._recPending[c].projectId === run.projectId) return false;
|
|
10184
10261
|
}
|
|
10185
10262
|
var projectId = run.projectId, path = run.storagePath;
|
|
10186
10263
|
runSettleSideEffect(projectId, bgIndexingQueueName(live.userId, projectId), "lost:" + projectId + ":" + path + ":" + run.since, function() {
|
|
@@ -10193,6 +10270,7 @@ var _ChatSession = class _ChatSession {
|
|
|
10193
10270
|
}
|
|
10194
10271
|
});
|
|
10195
10272
|
});
|
|
10273
|
+
return false;
|
|
10196
10274
|
}
|
|
10197
10275
|
/** A file run the queue says is live, or that this page has a pass queued for. */
|
|
10198
10276
|
_fileRunLive(run) {
|
|
@@ -10224,8 +10302,8 @@ var _ChatSession = class _ChatSession {
|
|
|
10224
10302
|
var closed = [];
|
|
10225
10303
|
for (var k in runs) {
|
|
10226
10304
|
if (runs[k].projectId !== projectId || this._fileRunLive(runs[k])) continue;
|
|
10305
|
+
if (this._flipIfChainLost(runs[k])) continue;
|
|
10227
10306
|
closed.push(runs[k].storagePath);
|
|
10228
|
-
this._flipIfChainLost(runs[k]);
|
|
10229
10307
|
delete runs[k];
|
|
10230
10308
|
if (!this._fileRunsIdle) this._fileRunsIdle = {};
|
|
10231
10309
|
this._fileRunsIdle[k] = true;
|