bunnyquery 1.21.3 → 1.21.7

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
@@ -996,10 +996,12 @@ Extracted content of attached office files (read inline below; do NOT fetch thei
996
996
  const webAccess = params.webAccess === true;
997
997
  const g = params.indexAccessGroup;
998
998
  const indexGroupLiteral = typeof g === "number" ? String(g) : g === "public" || g === "private" || g === "authorized" || g === "admin" ? `"${g}"` : '"authorized"';
999
+ const reindexHint = canUpload === false ? `asking the project's owner to re-index that file` : `re-indexing that file (attach the same file again and choose to reindex it)`;
999
1000
  const groundingRules = `ANSWER ONLY FROM THE DATA. Every fact you state about this project's data - a name, a number, a date, a status, what a document says, whether something exists - must come from one of four places: a tool result returned in THIS conversation, a file or image attached to it (including one you read through its attachment link), the project description at the end of this prompt, or what the user told you themselves in this chat. Your general knowledge, the open internet and a plausible guess are NOT sources. Never use them to answer a question about the user's data, to fill a gap in it, or to complete a record that came back partial. A value that is not in what you retrieved is unknown: say it is not in the data instead of supplying a likely one.
1000
1001
  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`}.
1002
+ A CODE, NUMBER OR PHRASE THAT searchText DID NOT FIND: when it answers search_complete with no hit, and what its message says was NOT searched has been checked as it says (the skipped_without_page_text files, the records when the value could be in a table), keep the answer short: say plainly that it was not found, name what was searched (the file, and its pages when you searched only some of them, or files_searched files and total_pages_searched pages), and when a recently uploaded file or a photo should hold it, suggest ${reindexHint}, since small or handwritten characters can be misread at indexing. Never present a different file as the match, and never guess the value.
1001
1003
  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.
1002
- 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.`;
1004
+ These 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.`;
1003
1005
  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.`;
1004
1006
  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.
1005
1007
  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.`;
@@ -1067,7 +1069,7 @@ Project description: """${serviceDescription}"""`;
1067
1069
  - 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.
1068
1070
  - 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).
1069
1071
  - 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.
1070
- - 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).
1072
+ - 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). ALSO set "text_regions" on that record: a list of up to 4 boxes [left, top, right, bottom], each a fraction from 0 to 1 of the image AS IT IS SHOWN TO YOU (not turned upright), drawn tightly around a label, plate or handwritten area whose characters matter (a serial number, a part number, a tag id); [] when there is none. Where a label names a value (a form field, a plate line), write the value right after its label in "printed_text" or "handwritten_text", as "<label>: <value>" (the label's own words, then the characters written beside it), so the label and its value are found together.
1071
1073
  - 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.
1072
1074
  - 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.
1073
1075
  - 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.
@@ -1144,7 +1146,7 @@ Read this file with the readFileContent tool, using the storage path above - do
1144
1146
  return head + `- temporary URL: ${attachment.url}
1145
1147
  ` + (options.imageFile === "attached" ? `
1146
1148
  This is an IMAGE file, attached to this message as an image: read it there, not from the URL. ` : `
1147
- 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.`;
1149
+ 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". Write each label's value right after its label, as "<label>: <value>" (the label's own words, then the characters written beside it), reading small and handwritten characters closely; use [?] only for a character that is truly unreadable, and never put a guessed character in its place. Then set "text_rotation", "text_legibility" and "text_regions" on the file's "src::" record, and only then describe what the image shows. "text_regions" is a list of up to 4 boxes [left, top, right, bottom], each a fraction from 0 to 1 of the image exactly as it is shown to you here (not turned upright), drawn tightly around a label, plate or handwritten area whose characters matter (a serial number, a part number, a tag); [] when there is none.`;
1148
1150
  }
1149
1151
  return head + `- temporary URL (fetch this to read the file contents): ${attachment.url}`;
1150
1152
  }
@@ -3020,6 +3022,67 @@ Index the REMAINING windows - one record per row/item, looking at any page image
3020
3022
  return `[POST]${url.toLowerCase()}#${service}:${itemId}`;
3021
3023
  }
3022
3024
 
3025
+ // src/engine/time.ts
3026
+ function wallClockNow() {
3027
+ return Date.now();
3028
+ }
3029
+ function formatChatTimestamp(ms) {
3030
+ if (typeof ms !== "number" || !isFinite(ms) || ms <= 0) return "";
3031
+ try {
3032
+ return new Date(ms).toLocaleString(void 0, {
3033
+ year: "numeric",
3034
+ month: "short",
3035
+ day: "numeric",
3036
+ hour: "numeric",
3037
+ minute: "2-digit",
3038
+ second: "2-digit"
3039
+ });
3040
+ } catch (e) {
3041
+ return "";
3042
+ }
3043
+ }
3044
+ function formatDuration(ms) {
3045
+ if (typeof ms !== "number" || !isFinite(ms) || ms < 1e3) return "";
3046
+ var total = Math.floor(ms / 1e3);
3047
+ var h = Math.floor(total / 3600);
3048
+ var m = Math.floor(total % 3600 / 60);
3049
+ var s = total % 60;
3050
+ var out = [];
3051
+ if (h) out.push(h + "h");
3052
+ if (m) out.push(m + "m");
3053
+ out.push(s + "s");
3054
+ return out.join(" ");
3055
+ }
3056
+ function formatIndexDuration(ms) {
3057
+ if (typeof ms !== "number" || !isFinite(ms) || ms < 1e3) return "";
3058
+ var total = Math.floor(ms / 1e3);
3059
+ var h = Math.floor(total / 3600);
3060
+ var m = Math.floor(total % 3600 / 60);
3061
+ var s = total % 60;
3062
+ if (h) return h + " h" + (m ? " " + m + " min" : "");
3063
+ if (m) return m + " min" + (s ? " " + s + " s" : "");
3064
+ return s + " s";
3065
+ }
3066
+ function requestIdTimeMs(rid) {
3067
+ if (typeof rid !== "string") return 0;
3068
+ var stamp = rid.split(":")[0] || "";
3069
+ if (stamp.length !== 13) return 0;
3070
+ var alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
3071
+ var v = 0;
3072
+ for (var i = 0; i < stamp.length; i++) {
3073
+ var d = alphabet.indexOf(stamp.charAt(i).toUpperCase());
3074
+ if (d < 0) return 0;
3075
+ v = v * 32 + d;
3076
+ }
3077
+ return Math.floor(v / 2 / 1e6);
3078
+ }
3079
+ function messageTimeMs(m) {
3080
+ if (!m) return 0;
3081
+ var r = typeof m._serverItemId === "string" ? requestIdTimeMs(m._serverItemId) : 0;
3082
+ if (r > 0) return r;
3083
+ return typeof m._ts === "number" && m._ts > 0 ? m._ts : 0;
3084
+ }
3085
+
3023
3086
  // src/engine/indexing_groups.ts
3024
3087
  function canonIndexKey(s) {
3025
3088
  return typeof s === "string" && s ? s.trim() : "";
@@ -3098,6 +3161,46 @@ Index the REMAINING windows - one record per row/item, looking at any page image
3098
3161
  grp.resolving = false;
3099
3162
  grp.resolvingReason = void 0;
3100
3163
  }
3164
+ function runRecordDurationMs(rec) {
3165
+ if (!rec || rec.status !== "done") return void 0;
3166
+ var a = rec.started;
3167
+ var b = rec.finished;
3168
+ if (typeof a !== "number" || typeof b !== "number" || !isFinite(a) || !isFinite(b) || b < a) return void 0;
3169
+ return b - a;
3170
+ }
3171
+ var RUN_DURATION_CLOCK_SLACK_MS = 6e4;
3172
+ var RUN_DURATION_SERVER_SLACK_MS = 5e3;
3173
+ function runRecordGroupDurationMs(grp, rec) {
3174
+ if (rec.status !== "done" || !grp.members.length) return void 0;
3175
+ var fin = rec.finished;
3176
+ if (typeof fin !== "number" || !isFinite(fin)) return void 0;
3177
+ var firstTs = messageTimeMs(grp.members[0].msg);
3178
+ var lastTs = messageTimeMs(grp.members[grp.members.length - 1].msg);
3179
+ if (!firstTs || !lastTs) return void 0;
3180
+ if (fin < firstTs || fin < lastTs - RUN_DURATION_SERVER_SLACK_MS) return void 0;
3181
+ var firstPassTs = 0;
3182
+ for (var i = 0; i < grp.members.length; i++) {
3183
+ var m = grp.members[i].msg;
3184
+ if (m.role !== "user") continue;
3185
+ var ref = readFileRef(m);
3186
+ if (ref && !ref.continued) firstPassTs = messageTimeMs(m);
3187
+ break;
3188
+ }
3189
+ var st = typeof rec.started === "number" && isFinite(rec.started) ? rec.started : void 0;
3190
+ var start;
3191
+ if (st !== void 0 && st > firstTs + RUN_DURATION_CLOCK_SLACK_MS) return void 0;
3192
+ if (firstPassTs) {
3193
+ start = st !== void 0 && st >= firstPassTs - RUN_DURATION_CLOCK_SLACK_MS ? st : firstPassTs;
3194
+ } else {
3195
+ if (st === void 0) return void 0;
3196
+ start = st;
3197
+ }
3198
+ return fin >= start ? fin - start : void 0;
3199
+ }
3200
+ function indexGroupDurationLabel(group) {
3201
+ if (!group || group.status !== "done" || !group.finished || group.resolving || group.queued) return "";
3202
+ return formatIndexDuration(group.durationMs);
3203
+ }
3101
3204
  function buildChatDisplayList(messages, opts) {
3102
3205
  var list = Array.isArray(messages) ? messages : [];
3103
3206
  var liveIndexKeys = opts && opts.liveIndexKeys || {};
@@ -3130,8 +3233,9 @@ Index the REMAINING windows - one record per row/item, looking at any page image
3130
3233
  var alreadySeen = !!(msg._serverItemId && runByItemId[msg._serverItemId]);
3131
3234
  var openId = openRunOfKey[key];
3132
3235
  var notLater = false;
3133
- if (openId && typeof msg._ts === "number" && typeof newestTsOfRun[openId] === "number") {
3134
- notLater = msg._ts <= newestTsOfRun[openId];
3236
+ var msgTime = messageTimeMs(msg);
3237
+ if (openId && msgTime > 0 && typeof newestTsOfRun[openId] === "number") {
3238
+ notLater = msgTime <= newestTsOfRun[openId];
3135
3239
  }
3136
3240
  if (!ref.continued && !alreadySeen && !notLater && openRunOfKey[key]) delete openRunOfKey[key];
3137
3241
  runId = openRunOfKey[key];
@@ -3145,9 +3249,10 @@ Index the REMAINING windows - one record per row/item, looking at any page image
3145
3249
  runId = runOfIndex[i - 1];
3146
3250
  }
3147
3251
  if (!runId) continue;
3148
- if (typeof msg._ts === "number") {
3252
+ var memberTime = messageTimeMs(msg);
3253
+ if (memberTime > 0) {
3149
3254
  var prevTs = newestTsOfRun[runId];
3150
- if (typeof prevTs !== "number" || msg._ts > prevTs) newestTsOfRun[runId] = msg._ts;
3255
+ if (typeof prevTs !== "number" || memberTime > prevTs) newestTsOfRun[runId] = memberTime;
3151
3256
  }
3152
3257
  var g = groups[runId];
3153
3258
  if (!g) {
@@ -3451,7 +3556,9 @@ Index the REMAINING windows - one record per row/item, looking at any page image
3451
3556
  resolvingReason: reason,
3452
3557
  stub: true,
3453
3558
  queued: waitingStub || live && !!runningKeys && !runningKeys[sp] && !runningKeys[canonIndexKey(sp)] && !runningKeys[fname] ? true : void 0,
3454
- stubError: rec.error || (st === "error" && !rec.error ? "Indexing did not finish." : void 0)
3559
+ stubError: rec.error || (st === "error" && !rec.error ? "Indexing did not finish." : void 0),
3560
+ // The stub IS the record, so a 'done' record's span is this run's.
3561
+ durationMs: st === "done" ? runRecordDurationMs(rec) : void 0
3455
3562
  };
3456
3563
  stubList.push({ started: typeof rec.started === "number" ? rec.started : Infinity, group: sg });
3457
3564
  }
@@ -3470,6 +3577,7 @@ Index the REMAINING windows - one record per row/item, looking at any page image
3470
3577
  tg.runKey = "run:" + (tg.path || tg.key) + "#" + trec.started;
3471
3578
  stubList.push({ started: trec.started, group: tg });
3472
3579
  overlayRunRecordVerdict(tg, trec, liveIndexKeys);
3580
+ tg.durationMs = runRecordGroupDurationMs(tg, trec);
3473
3581
  }
3474
3582
  }
3475
3583
  stubList.sort(function(a, b) {
@@ -3905,6 +4013,22 @@ Index the REMAINING windows - one record per row/item, looking at any page image
3905
4013
  var INLINE_LINK_GLYPH = "\u2197";
3906
4014
  var INLINE_LINK_UNAVAILABLE_GLYPH = "\u2715";
3907
4015
  var INLINE_LINK_UNAVAILABLE_SUFFIX = " (unavailable)";
4016
+ var FIT_LABEL_TAIL_CHARS = 8;
4017
+ function splitLabelForFit(name) {
4018
+ var chars = Array.from(String(name == null ? "" : name));
4019
+ var dot = -1;
4020
+ for (var i = chars.length - 1; i > 0; i--) {
4021
+ if (chars[i] === ".") {
4022
+ dot = i;
4023
+ break;
4024
+ }
4025
+ if (chars[i] === " " || chars[i] === "/" || chars.length - i > 10) break;
4026
+ }
4027
+ var extStart = dot > 0 && dot < chars.length - 1 ? dot : chars.length;
4028
+ var tailStart = Math.max(0, extStart - FIT_LABEL_TAIL_CHARS);
4029
+ if (tailStart < 4) return { stem: chars.join(""), tail: "" };
4030
+ return { stem: chars.slice(0, tailStart).join(""), tail: chars.slice(tailStart).join("") };
4031
+ }
3908
4032
  function renderInlineLinkHtml(link, opts) {
3909
4033
  var o = opts || {};
3910
4034
  var unavailable = !!o.unavailable;
@@ -3917,7 +4041,16 @@ Index the REMAINING windows - one record per row/item, looking at any page image
3917
4041
  if (unavailable) cls.push("is-unavailable");
3918
4042
  if (preview) cls.push("is-image-preview");
3919
4043
  var glyphHtml = '<span class="bq-link-glyph" translate="no">' + (unavailable ? INLINE_LINK_UNAVAILABLE_GLYPH : INLINE_LINK_GLYPH) + "</span>";
3920
- var labelHtml = glyphHtml + escapeInlineHtml(link.label + (unavailable ? INLINE_LINK_UNAVAILABLE_SUFFIX : refreshing ? " (fetching...)" : ""));
4044
+ var stateSuffix = unavailable ? INLINE_LINK_UNAVAILABLE_SUFFIX : refreshing ? " (fetching...)" : "";
4045
+ var fit = !!o.fitLabel && !preview;
4046
+ if (fit) cls.push("bq-link-fit");
4047
+ var labelHtml;
4048
+ if (fit) {
4049
+ var split = splitLabelForFit(full);
4050
+ labelHtml = glyphHtml + '<span class="bq-link-stem">' + escapeInlineHtml(split.stem) + "</span>" + (split.tail ? '<span class="bq-link-tail">' + escapeInlineHtml(split.tail) + "</span>" : "") + (stateSuffix ? '<span class="bq-link-tail">' + escapeInlineHtml(stateSuffix) + "</span>" : "");
4051
+ } else {
4052
+ labelHtml = glyphHtml + escapeInlineHtml(link.label + stateSuffix);
4053
+ }
3921
4054
  var attrs = ['class="' + cls.join(" ") + '"'];
3922
4055
  if (unavailable) attrs.push('aria-disabled="true"', 'data-bq-unavailable="1"');
3923
4056
  else attrs.push('href="' + escapeInlineHtml(link.href) + '"', 'target="_blank"', 'rel="noopener noreferrer"');
@@ -4052,38 +4185,6 @@ Index the REMAINING windows - one record per row/item, looking at any page image
4052
4185
  return closest.call(img, PREVIEW_LAYOUT_BOX_SELECTOR) || img;
4053
4186
  }
4054
4187
 
4055
- // src/engine/time.ts
4056
- function wallClockNow() {
4057
- return Date.now();
4058
- }
4059
- function formatChatTimestamp(ms) {
4060
- if (typeof ms !== "number" || !isFinite(ms) || ms <= 0) return "";
4061
- try {
4062
- return new Date(ms).toLocaleString(void 0, {
4063
- year: "numeric",
4064
- month: "short",
4065
- day: "numeric",
4066
- hour: "numeric",
4067
- minute: "2-digit",
4068
- second: "2-digit"
4069
- });
4070
- } catch (e) {
4071
- return "";
4072
- }
4073
- }
4074
- function formatDuration(ms) {
4075
- if (typeof ms !== "number" || !isFinite(ms) || ms < 1e3) return "";
4076
- var total = Math.floor(ms / 1e3);
4077
- var h = Math.floor(total / 3600);
4078
- var m = Math.floor(total % 3600 / 60);
4079
- var s = total % 60;
4080
- var out = [];
4081
- if (h) out.push(h + "h");
4082
- if (m) out.push(m + "m");
4083
- out.push(s + "s");
4084
- return out.join(" ");
4085
- }
4086
-
4087
4188
  // src/engine/ai_agent.ts
4088
4189
  function normalizePlatform(raw) {
4089
4190
  var p = (raw || "").trim().toLowerCase();
@@ -5647,25 +5748,16 @@ Index the REMAINING windows - one record per row/item, looking at any page image
5647
5748
  }
5648
5749
  var LIVE_PAINT_MIN_MS = 250;
5649
5750
  var LIVE_TYPE_MAX_STEP = 1200;
5650
- function requestIdTimeMs(rid) {
5651
- if (typeof rid !== "string") return 0;
5652
- var stamp = rid.split(":")[0] || "";
5653
- if (stamp.length !== 13) return 0;
5654
- var alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
5655
- var v = 0;
5656
- for (var i = 0; i < stamp.length; i++) {
5657
- var d = alphabet.indexOf(stamp.charAt(i).toUpperCase());
5658
- if (d < 0) return 0;
5659
- v = v * 32 + d;
5660
- }
5661
- return Math.floor(v / 2 / 1e6);
5662
- }
5663
5751
  var WRONG_ANSWER_MESSAGE = "This answer seems wrong. Please check it again against the documents.";
5664
5752
  var WRONG_ANSWER_LABEL = "Wrong answer?";
5665
5753
  function canReportWrongAnswer(msg) {
5666
5754
  var note = retrievalNoteOfAnswer(msg);
5667
5755
  return !!note && !answerUsedNoDataTool(note) && !msg.isCancelled;
5668
5756
  }
5757
+ var UPLOAD_CANCELLED_MESSAGE = "Upload cancelled";
5758
+ function isUploadCancelledError(err) {
5759
+ return !!err && (err.code === "CANCELLED" || err.message === UPLOAD_CANCELLED_MESSAGE);
5760
+ }
5669
5761
  var _ChatSession = class _ChatSession {
5670
5762
  constructor(host) {
5671
5763
  // --- live streaming ----------------------------------------------------
@@ -11587,15 +11679,18 @@ Index the REMAINING windows - one record per row/item, looking at any page image
11587
11679
  self.updateHistoryCache();
11588
11680
  });
11589
11681
  }
11590
- /** Insert bubbles before the first message that is newer than them (by `_ts`); messages
11591
- * without a time are skipped over, and the end of the list takes them otherwise. */
11682
+ /** Insert bubbles before the first message that is newer than them; messages whose time
11683
+ * is unknown are skipped over, and the end of the list takes them otherwise. A message's
11684
+ * time is its `_ts`, else (2026-11-25) the time in its request id: a live worker pass
11685
+ * adopted from the queue carries no `_ts`, and a file's older passes loaded by opening its
11686
+ * row (loadRunPasses) used to land AFTER it, which split one run into two rows. */
11592
11687
  _insertByTime(bubbles) {
11593
- var at = bubbles[0] && bubbles[0]._ts;
11688
+ var at = messageTimeMs(bubbles[0]);
11594
11689
  var idx = this.state.messages.length;
11595
- if (typeof at === "number") {
11690
+ if (at > 0) {
11596
11691
  for (var i = 0; i < this.state.messages.length; i++) {
11597
- var t = this.state.messages[i] && this.state.messages[i]._ts;
11598
- if (typeof t === "number" && t > at) {
11692
+ var t = messageTimeMs(this.state.messages[i]);
11693
+ if (t > 0 && t > at) {
11599
11694
  idx = i;
11600
11695
  break;
11601
11696
  }
@@ -12828,6 +12923,29 @@ Index the REMAINING windows - one record per row/item, looking at any page image
12828
12923
  });
12829
12924
  }
12830
12925
  // --- attachment upload orchestration ---------------------------------
12926
+ /**
12927
+ * The user cancelled this chip's upload (the widget's per-chip x or "Cancel all
12928
+ * uploads"). Stops the bytes now when they are moving (the host's abort), and
12929
+ * leaves a flag every later step of uploadSingleAttachment checks, so a cancel
12930
+ * that lands between steps (the get-signed-url round trip before the bytes, or
12931
+ * the src:: record and the indexing request after them) still stops the file
12932
+ * from being indexed and from being attached to the chat turn. A member whose
12933
+ * indexing request has already gone out is past cancelling: it shows as an
12934
+ * indexing row with its own Stop. Returns false for a chip that is not being
12935
+ * uploaded by this session any more.
12936
+ */
12937
+ cancelAttachmentUpload(att) {
12938
+ if (!att || att._cancelled) return false;
12939
+ if (att.status !== "uploading" && !att._batchId) return false;
12940
+ att._cancelled = true;
12941
+ if (typeof att._abort === "function") {
12942
+ try {
12943
+ att._abort();
12944
+ } catch (e) {
12945
+ }
12946
+ }
12947
+ return true;
12948
+ }
12831
12949
  // Upload one attachment (a file = 1 member, a folder = N) to db storage and
12832
12950
  // queue indexing per member. The bytes I/O + chip rendering go through host
12833
12951
  // hooks; the overwrite/reindex flow, status lifecycle, and indexing live here.
@@ -12850,6 +12968,17 @@ Index the REMAINING windows - one record per row/item, looking at any page image
12850
12968
  var anyIndexFailed = false;
12851
12969
  var reusedCount = 0;
12852
12970
  att.reused = false;
12971
+ att._storedCount = 0;
12972
+ att._indexQueuedCount = 0;
12973
+ att._indexQueued = false;
12974
+ var cancelError = function() {
12975
+ var e = new Error(UPLOAD_CANCELLED_MESSAGE);
12976
+ e.code = "CANCELLED";
12977
+ return e;
12978
+ };
12979
+ var checkCancel = function() {
12980
+ if (att._cancelled) throw cancelError();
12981
+ };
12853
12982
  delete att.duplicates;
12854
12983
  var chain = Promise.resolve();
12855
12984
  var findDuplicate = function(member) {
@@ -12866,10 +12995,12 @@ Index the REMAINING windows - one record per row/item, looking at any page image
12866
12995
  };
12867
12996
  members.forEach(function(member, idx) {
12868
12997
  chain = chain.then(function() {
12998
+ checkCancel();
12869
12999
  var hadExists = false;
12870
13000
  var skipped = false;
12871
13001
  var duplicateOf = null;
12872
13002
  var existedBefore = false;
13003
+ var madeRecord = false;
12873
13004
  var onProg = function(p) {
12874
13005
  if (p && p.total) {
12875
13006
  att.progress = Math.floor((idx + p.loaded / p.total) / total * 100);
@@ -12877,14 +13008,33 @@ Index the REMAINING windows - one record per row/item, looking at any page image
12877
13008
  }
12878
13009
  };
12879
13010
  var doMemberUpload = function(checkExistence) {
13011
+ checkCancel();
12880
13012
  return self.host.uploadFile({
12881
13013
  file: member.file,
12882
13014
  storagePath: member.storagePath,
12883
13015
  checkExistence,
12884
13016
  onProgress: onProg,
13017
+ // The host hands its abort over just before the bytes start. A
13018
+ // cancel made during the get-signed-url round trip had nothing to
13019
+ // abort yet, so it is applied here, before anything is sent: a
13020
+ // storage POST that never completes leaves no object behind.
12885
13021
  setAbort: function(abort) {
12886
13022
  att._abort = abort;
13023
+ if (att._cancelled) {
13024
+ try {
13025
+ abort();
13026
+ } catch (e) {
13027
+ }
13028
+ }
12887
13029
  }
13030
+ }).then(function(r) {
13031
+ att._abort = null;
13032
+ att._storedCount = (att._storedCount || 0) + 1;
13033
+ return r;
13034
+ }, function(err) {
13035
+ att._abort = null;
13036
+ if (att._cancelled) throw cancelError();
13037
+ throw err;
12888
13038
  });
12889
13039
  };
12890
13040
  if (isIndexRetry) {
@@ -12918,12 +13068,14 @@ Index the REMAINING windows - one record per row/item, looking at any page image
12918
13068
  existedBefore = true;
12919
13069
  });
12920
13070
  }).then(function() {
13071
+ checkCancel();
12921
13072
  if (skipped) return;
12922
13073
  return Promise.resolve(self.host.getTemporaryUrl(duplicateOf || member.storagePath)).catch(function(err) {
12923
13074
  var ecode = err && (err.code || err.body && err.body.code);
12924
13075
  var emsg = String(err && (err.message || err.body && err.body.message) || err || "");
12925
13076
  var refused = /no access to this file/i.test(emsg) || ecode === "INVALID_REQUEST" && /access/i.test(emsg);
12926
13077
  if (duplicateOf || !refused || typeof self.host.ensureFileIndexRecord !== "function") throw err;
13078
+ madeRecord = !existedBefore;
12927
13079
  return Promise.resolve(self.host.ensureFileIndexRecord(member.storagePath, {
12928
13080
  name: member.file.name,
12929
13081
  mime: member.file.type || self.host.getMimeType(member.file.name),
@@ -12933,6 +13085,13 @@ Index the REMAINING windows - one record per row/item, looking at any page image
12933
13085
  });
12934
13086
  });
12935
13087
  }).then(function(url) {
13088
+ if (att._cancelled) {
13089
+ var dropEarly = madeRecord && typeof self.host.deleteExistingFileRecord === "function" ? Promise.resolve(self.host.deleteExistingFileRecord(member.storagePath)).catch(function() {
13090
+ }) : Promise.resolve();
13091
+ return dropEarly.then(function() {
13092
+ throw cancelError();
13093
+ });
13094
+ }
12936
13095
  if (skipped) return;
12937
13096
  if (duplicateOf) {
12938
13097
  urls.push({ name: member.relPath, url, storagePath: duplicateOf });
@@ -12961,13 +13120,14 @@ Index the REMAINING windows - one record per row/item, looking at any page image
12961
13120
  var mime = member.file.type || self.host.getMimeType(member.file.name);
12962
13121
  var alreadyIndexing = false;
12963
13122
  var existingGroup = null;
13123
+ var clearedOld = false;
12964
13124
  var preIndex = self.claimIndexRun(member.storagePath).then(function(claimed) {
12965
13125
  alreadyIndexing = !claimed;
12966
13126
  if (alreadyIndexing) {
12967
13127
  console.log("[chat-engine] skipping a duplicate index request for", member.storagePath);
12968
13128
  return;
12969
13129
  }
12970
- if (!existedBefore) return;
13130
+ if (!existedBefore || att._cancelled) return;
12971
13131
  var readGroup = typeof self.host.readFileAccessGroup === "function" ? Promise.resolve(self.host.readFileAccessGroup(member.storagePath)).then(function(g) {
12972
13132
  existingGroup = g || null;
12973
13133
  }, function(err) {
@@ -12975,7 +13135,9 @@ Index the REMAINING windows - one record per row/item, looking at any page image
12975
13135
  throw err;
12976
13136
  }) : Promise.resolve();
12977
13137
  return readGroup.then(function() {
13138
+ if (att._cancelled) return;
12978
13139
  if (typeof self.host.deleteExistingFileRecord === "function") {
13140
+ clearedOld = true;
12979
13141
  return Promise.resolve(self.host.deleteExistingFileRecord(member.storagePath)).catch(function() {
12980
13142
  });
12981
13143
  }
@@ -12983,7 +13145,9 @@ Index the REMAINING windows - one record per row/item, looking at any page image
12983
13145
  });
12984
13146
  preIndex = preIndex.then(function() {
12985
13147
  if (alreadyIndexing) return;
13148
+ if (att._cancelled && !clearedOld) return;
12986
13149
  if (typeof self.host.ensureFileIndexRecord !== "function") return;
13150
+ if (!existedBefore) madeRecord = true;
12987
13151
  return Promise.resolve(self.host.ensureFileIndexRecord(member.storagePath, {
12988
13152
  name: member.file.name,
12989
13153
  mime: mime || void 0,
@@ -13004,10 +13168,28 @@ Index the REMAINING windows - one record per row/item, looking at any page image
13004
13168
  }).catch(function() {
13005
13169
  });
13006
13170
  });
13171
+ var abandonIfCancelled = function() {
13172
+ if (!att._cancelled) return;
13173
+ if (!alreadyIndexing) self.releaseIndexRun(member.storagePath);
13174
+ var drop = !existedBefore && !alreadyIndexing && madeRecord && typeof self.host.deleteExistingFileRecord === "function" ? Promise.resolve(self.host.deleteExistingFileRecord(member.storagePath)).catch(function() {
13175
+ }) : Promise.resolve();
13176
+ return drop.then(function() {
13177
+ throw cancelError();
13178
+ });
13179
+ };
13007
13180
  return preIndex.then(function() {
13181
+ return abandonIfCancelled();
13182
+ }).then(function() {
13008
13183
  return parseAttachmentContent(member.file, member.file.name, mime || void 0);
13184
+ }).then(function(parsedContent) {
13185
+ return Promise.resolve(abandonIfCancelled()).then(function() {
13186
+ return parsedContent;
13187
+ });
13009
13188
  }).then(function(parsedContent) {
13010
13189
  if (alreadyIndexing) return;
13190
+ att._indexQueuedCount = (att._indexQueuedCount || 0) + 1;
13191
+ if (att.kind !== "folder") att._indexQueued = true;
13192
+ self.host.renderAttachmentChips();
13011
13193
  return self.trackIndexDispatch(notifyAgentSaveAttachment({
13012
13194
  platform: id.platform,
13013
13195
  model: id.model,
@@ -13063,6 +13245,7 @@ Index the REMAINING windows - one record per row/item, looking at any page image
13063
13245
  });
13064
13246
  });
13065
13247
  return chain.then(function() {
13248
+ checkCancel();
13066
13249
  att._abort = null;
13067
13250
  att.progress = 100;
13068
13251
  if (att.kind === "folder") att.uploadedUrls = urls.map(function(u) {
@@ -13123,12 +13306,20 @@ Index the REMAINING windows - one record per row/item, looking at any page image
13123
13306
  return a.id === att.id;
13124
13307
  });
13125
13308
  var aborted = err && (err.message === "Aborted" || err === "Aborted");
13309
+ if (att._cancelled || isUploadCancelledError(err)) {
13310
+ att.status = "cancelled";
13311
+ att._abort = null;
13312
+ self.host.renderAttachmentChips();
13313
+ return;
13314
+ }
13126
13315
  if (removed || aborted) return;
13127
13316
  att.status = "error";
13128
13317
  att.errorMessage = "File upload has failed";
13129
13318
  att.errorCode = err && (err.code || err.body && err.body.code) || "";
13130
13319
  att.errorDetail = err && (err.message || err.body && err.body.message) || (typeof err === "string" ? err : "");
13131
13320
  self.host.renderAttachmentChips();
13321
+ }).then(function() {
13322
+ att._settledBatch = att._batchId || true;
13132
13323
  });
13133
13324
  });
13134
13325
  });
@@ -13159,7 +13350,7 @@ Index the REMAINING windows - one record per row/item, looking at any page image
13159
13350
  (function() {
13160
13351
  var MCP_PROD = "https://mcp.skapi.com";
13161
13352
  var MCP_DEV = "https://mcp-dev.broadwayinc.computer";
13162
- var BQ_VERSION = "1.21.3" ;
13353
+ var BQ_VERSION = "1.21.7" ;
13163
13354
  var ATTACHMENT_URL_EXPIRES_SECONDS = 600;
13164
13355
  var GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
13165
13356
  var GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
@@ -14950,6 +15141,8 @@ Index the REMAINING windows - one record per row/item, looking at any page image
14950
15141
  attachmentWarning: "",
14951
15142
  attachmentCapNotice: "",
14952
15143
  // informational "N files not added" when an add hit MAX_ATTACHMENT_FILE_COUNT
15144
+ attachmentCancelNotice: "",
15145
+ // "Upload cancelled: <file>." after the user cancelled uploads
14953
15146
  attachmentsRow: null,
14954
15147
  // .bq-attachments DOM node
14955
15148
  attachBtnEl: null,
@@ -15305,6 +15498,10 @@ Index the REMAINING windows - one record per row/item, looking at any page image
15305
15498
  updateComposerControls();
15306
15499
  return;
15307
15500
  }
15501
+ if (CS.attachmentCancelNotice) {
15502
+ CS.attachmentCancelNotice = "";
15503
+ renderAttachmentChips();
15504
+ }
15308
15505
  if (inputEl) {
15309
15506
  inputEl.value = "";
15310
15507
  autoGrowInput(inputEl);
@@ -15413,11 +15610,12 @@ Index the REMAINING windows - one record per row/item, looking at any page image
15413
15610
  function fileToAnchorHtml(filename, href) {
15414
15611
  return '<a class="bq-file-download" href="' + escapeHtml(href) + '" download="' + escapeHtml(filename) + '" target="_blank" rel="noopener noreferrer"><span class="bq-link-glyph" translate="no">\u2197</span>' + escapeHtml(filename) + "</a>";
15415
15612
  }
15416
- function linkToAnchorHtml(link, allowImagePreview) {
15613
+ function linkToAnchorHtml(link, allowImagePreview, fitLabel) {
15417
15614
  return renderInlineLinkHtml(link, {
15418
15615
  refreshing: !!refreshingLinkMap[link.expiredHref || link.href],
15419
15616
  allowImagePreview,
15420
- unavailable: isLinkUnavailable(link, unavailableLinkMap)
15617
+ unavailable: isLinkUnavailable(link, unavailableLinkMap),
15618
+ fitLabel: !!fitLabel
15421
15619
  });
15422
15620
  }
15423
15621
  function citationChipsHtml(note) {
@@ -15457,6 +15655,7 @@ Index the REMAINING windows - one record per row/item, looking at any page image
15457
15655
  }
15458
15656
  function parseMsgPartsHtml(content, opts) {
15459
15657
  var noPreviews = !!(opts && opts.imagePreviews === false);
15658
+ var fitLinks = !!(opts && opts.fitLinkLabels);
15460
15659
  var placeholderHtml = [];
15461
15660
  var PH = function(idx) {
15462
15661
  return "\uE000BQ" + idx + "\uE001";
@@ -15492,7 +15691,7 @@ Index the REMAINING windows - one record per row/item, looking at any page image
15492
15691
  var built = buildLinkPartFromGroups(full, args[0], args[1], args[2], args[3], args[4], args[5]);
15493
15692
  if (!built) return full;
15494
15693
  var allow = previewsLeft > 0;
15495
- var html2 = linkToAnchorHtml(built.part, allow);
15694
+ var html2 = linkToAnchorHtml(built.part, allow, fitLinks);
15496
15695
  if (allow && built.part.image) previewsLeft--;
15497
15696
  return pushPlaceholder(html2) + (built.tail || "");
15498
15697
  });
@@ -15611,14 +15810,15 @@ Index the REMAINING windows - one record per row/item, looking at any page image
15611
15810
  });
15612
15811
  }
15613
15812
  if (xhr.upload && typeof onProgress === "function") xhr.upload.onprogress = onProgress;
15813
+ touch();
15814
+ xhr.send(form);
15614
15815
  if (typeof setAbort === "function") setAbort(function() {
15816
+ clearIdle();
15615
15817
  try {
15616
15818
  xhr.abort();
15617
15819
  } catch (e) {
15618
15820
  }
15619
15821
  });
15620
- touch();
15621
- xhr.send(form);
15622
15822
  });
15623
15823
  }
15624
15824
  function uploadFileToDb(file, storagePath, onProgress, setAbort, checkExistence) {
@@ -16003,6 +16203,7 @@ Index the REMAINING windows - one record per row/item, looking at any page image
16003
16203
  remaining -= count;
16004
16204
  changed = true;
16005
16205
  });
16206
+ CS.attachmentCancelNotice = "";
16006
16207
  CS.attachmentCapNotice = dropped > 0 ? "You can attach up to " + MAX_ATTACHMENT_FILE_COUNT + " files per message. " + dropped + " file" + (dropped === 1 ? " was" : "s were") + " not added." : "";
16007
16208
  if (changed) {
16008
16209
  recomputeAttachmentWarning();
@@ -16100,7 +16301,17 @@ Index the REMAINING windows - one record per row/item, looking at any page image
16100
16301
  ids.forEach(function(id) {
16101
16302
  idset[id] = true;
16102
16303
  });
16304
+ var inFlight = inFlightUploadAttachments().filter(function(a) {
16305
+ return idset[a.id];
16306
+ });
16307
+ if (inFlight.length) {
16308
+ cancelAttachmentUploads(inFlight);
16309
+ inFlight.forEach(function(a) {
16310
+ delete idset[a.id];
16311
+ });
16312
+ }
16103
16313
  CS.attachments = CS.attachments.filter(function(a) {
16314
+ if (idset[a.id] && a._batchId && a.status === "uploading") return true;
16104
16315
  if (idset[a.id]) {
16105
16316
  if (a._abort) {
16106
16317
  try {
@@ -16125,6 +16336,10 @@ Index the REMAINING windows - one record per row/item, looking at any page image
16125
16336
  });
16126
16337
  if (i === -1) return;
16127
16338
  var att = CS.attachments[i];
16339
+ if (isInFlightUpload(att)) {
16340
+ cancelAttachmentUploads([att]);
16341
+ return;
16342
+ }
16128
16343
  if (att._abort) {
16129
16344
  try {
16130
16345
  att._abort();
@@ -16138,6 +16353,57 @@ Index the REMAINING windows - one record per row/item, looking at any page image
16138
16353
  updateComposerControls();
16139
16354
  scheduleAttachmentOverflowRecompute();
16140
16355
  }
16356
+ function isInFlightUpload(a) {
16357
+ if (!a || a._cancelled) return false;
16358
+ if (a.kind !== "folder" && a._indexQueued) return false;
16359
+ if (a.status === "uploading") return true;
16360
+ if (a._settledBatch && a._settledBatch === a._batchId) return false;
16361
+ return !!a._batchId && a.status !== "done" && a.status !== "cancelled";
16362
+ }
16363
+ function inFlightUploadAttachments() {
16364
+ return CS.attachments.filter(isInFlightUpload);
16365
+ }
16366
+ function cancelAttachmentUploads(atts) {
16367
+ var cancelled = (atts || []).filter(isInFlightUpload);
16368
+ if (!cancelled.length) return;
16369
+ var ids = {};
16370
+ cancelled.forEach(function(a) {
16371
+ if (!session.cancelAttachmentUpload(a)) a._cancelled = true;
16372
+ ids[a.id] = true;
16373
+ });
16374
+ CS.attachments = CS.attachments.filter(function(a) {
16375
+ return !ids[a.id];
16376
+ });
16377
+ CS.attachmentCancelNotice = uploadCancelNotice(cancelled);
16378
+ CS.attachmentCapNotice = "";
16379
+ CS.visibleAttachmentCount = Infinity;
16380
+ recomputeAttachmentWarning();
16381
+ renderAttachmentChips();
16382
+ updateComposerControls();
16383
+ scheduleAttachmentOverflowRecompute();
16384
+ }
16385
+ function uploadCancelNotice(list) {
16386
+ var names = list.map(function(a) {
16387
+ return a.kind === "folder" ? a.name + "/" : a.name;
16388
+ });
16389
+ var text = list.length === 1 ? "Upload cancelled: " + names[0] + "." : list.length + " uploads cancelled: " + names.slice(0, 3).join(", ") + (names.length > 3 ? " and " + (names.length - 3) + " more." : ".");
16390
+ var queued = 0, stored = 0;
16391
+ list.forEach(function(a) {
16392
+ var q = a._indexQueuedCount || 0;
16393
+ queued += q;
16394
+ var landed = Math.max(0, (a._storedCount || 0) - q);
16395
+ if (!landed && a.status === "uploading" && (a.progress || 0) >= 100) landed = 1;
16396
+ stored += landed;
16397
+ });
16398
+ if (queued) {
16399
+ text += " " + queued + (queued === 1 ? " file had" : " files had") + " already gone to indexing; stop " + (queued === 1 ? "it from its row" : "them from their rows") + " in the chat.";
16400
+ }
16401
+ if (stored) {
16402
+ var subject = list.length === 1 && stored === 1 && !queued ? "Its" : stored === 1 ? "One file's" : stored + " files'";
16403
+ text += " " + subject + " bytes had already been sent, so " + (stored === 1 ? "it" : "they") + " may stay in storage, but " + (stored === 1 ? "it was" : "they were") + " not indexed or added to the chat.";
16404
+ }
16405
+ return text;
16406
+ }
16141
16407
  function clearAttachments() {
16142
16408
  CS.attachments = CS.attachments.filter(function(a) {
16143
16409
  return !!a._batchId;
@@ -16154,6 +16420,8 @@ Index the REMAINING windows - one record per row/item, looking at any page image
16154
16420
  if (a.status !== "error" && a.status !== "indexError") return false;
16155
16421
  a._abort = null;
16156
16422
  delete a._batchId;
16423
+ delete a._indexQueued;
16424
+ delete a._settledBatch;
16157
16425
  return true;
16158
16426
  });
16159
16427
  CS.attachmentCapNotice = "";
@@ -16184,11 +16452,32 @@ Index the REMAINING windows - one record per row/item, looking at any page image
16184
16452
  var row = CS.attachmentsRow;
16185
16453
  if (!row) return;
16186
16454
  row.innerHTML = "";
16187
- if (!CS.attachments.length && !CS.attachmentWarning && !CS.attachmentCapNotice) {
16455
+ if (!CS.attachments.length && !CS.attachmentWarning && !CS.attachmentCapNotice && !CS.attachmentCancelNotice) {
16188
16456
  row.style.display = "none";
16189
16457
  return;
16190
16458
  }
16191
16459
  row.style.display = "";
16460
+ if (CS.attachmentCancelNotice) {
16461
+ var cancelNoticeClose = h("button", {
16462
+ class: "bq-attachment-remove",
16463
+ type: "button",
16464
+ title: "Dismiss",
16465
+ "aria-label": "Dismiss",
16466
+ text: "\xD7"
16467
+ });
16468
+ cancelNoticeClose.addEventListener("click", function(e) {
16469
+ e.stopPropagation();
16470
+ CS.attachmentCancelNotice = "";
16471
+ renderAttachmentChips();
16472
+ scheduleAttachmentOverflowRecompute();
16473
+ });
16474
+ row.appendChild(h(
16475
+ "div",
16476
+ { class: "bq-attachment-warning is-notice", role: "status" },
16477
+ h("span", { text: CS.attachmentCancelNotice }),
16478
+ cancelNoticeClose
16479
+ ));
16480
+ }
16192
16481
  if (CS.attachmentCapNotice) {
16193
16482
  row.appendChild(h("div", { class: "bq-attachment-warning" }, h("span", { text: CS.attachmentCapNotice })));
16194
16483
  }
@@ -16223,7 +16512,20 @@ Index the REMAINING windows - one record per row/item, looking at any page image
16223
16512
  var meta = att.status === "error" ? "(Failed)" : att.status === "indexError" ? "(Error)" : preparing ? "Preparing" : finalizing ? "Finalizing" : att.status === "uploading" ? att.progress + "%" : isFolder ? "(" + (att.files ? att.files.length : 0) + ")" : att.reused ? "already uploaded" : formatBytes(att.file ? att.file.size : att.size);
16224
16513
  chip.appendChild(h("span", { class: "bq-attachment-meta", text: meta }));
16225
16514
  if (clickable) chip.appendChild(h("span", { class: "bq-attachment-arrow", text: "\u2197" }));
16226
- if (att.status !== "uploading" && att.status !== "done") {
16515
+ if (isInFlightUpload(att)) {
16516
+ var cancelBtn = h("button", {
16517
+ class: "bq-attachment-remove",
16518
+ type: "button",
16519
+ title: "Cancel upload",
16520
+ "aria-label": "Cancel upload of " + att.name,
16521
+ text: "\xD7"
16522
+ });
16523
+ cancelBtn.addEventListener("click", function(e) {
16524
+ e.stopPropagation();
16525
+ cancelAttachmentUploads([att]);
16526
+ });
16527
+ chip.appendChild(cancelBtn);
16528
+ } else if (att.status !== "uploading" && att.status !== "done") {
16227
16529
  var rm = h("button", { class: "bq-attachment-remove", type: "button", title: "Remove", text: "\xD7" });
16228
16530
  rm.addEventListener("click", function(e) {
16229
16531
  e.stopPropagation();
@@ -16269,6 +16571,19 @@ Index the REMAINING windows - one record per row/item, looking at any page image
16269
16571
  });
16270
16572
  row.appendChild(removeAll);
16271
16573
  }
16574
+ var inFlight = inFlightUploadAttachments();
16575
+ if (inFlight.length >= 2) {
16576
+ var cancelAll = h("button", {
16577
+ class: "bq-attachment-remove-all",
16578
+ type: "button",
16579
+ title: "Cancel all " + inFlight.length + " uploads"
16580
+ }, "Cancel all uploads \xD7");
16581
+ cancelAll.addEventListener("click", function(e) {
16582
+ e.stopPropagation();
16583
+ cancelAttachmentUploads(inFlightUploadAttachments());
16584
+ });
16585
+ row.appendChild(cancelAll);
16586
+ }
16272
16587
  }
16273
16588
  function uploadsFrozenForUser() {
16274
16589
  if (!S.user) return true;
@@ -16536,7 +16851,9 @@ Index the REMAINING windows - one record per row/item, looking at any page image
16536
16851
  anchor.click();
16537
16852
  return;
16538
16853
  }
16539
- var busy = document.createTextNode(" (fetching...)");
16854
+ var busy = document.createElement("span");
16855
+ busy.className = "bq-link-tail";
16856
+ busy.textContent = " (fetching...)";
16540
16857
  anchor.classList.add("is-refreshing");
16541
16858
  anchor.appendChild(busy);
16542
16859
  var unbusy = function() {
@@ -16845,11 +17162,11 @@ Index the REMAINING windows - one record per row/item, looking at any page image
16845
17162
  return indexGroupVerb(group) + " " + nameLabel;
16846
17163
  }
16847
17164
  function indexGroupCount(group) {
16848
- if (group.stub) return "";
17165
+ if (group.stub) return indexGroupDurationLabel(group);
16849
17166
  var prog = group.status === "active" && session && session.pageProgressFor ? session.pageProgressFor(group.path || group.key, group.name) : null;
16850
17167
  var pages = prog ? prog.total ? prog.saved + " of " + prog.total + " pages" : prog.saved + " pages" : "";
16851
17168
  var passes = group.passCount <= 1 && !group.mayHaveOlder ? "" : group.passCount + (group.mayHaveOlder ? "+" : "") + " passes";
16852
- return [pages, passes].filter(Boolean).join(" \xB7 ");
17169
+ return [pages, passes, indexGroupDurationLabel(group)].filter(Boolean).join(" \xB7 ");
16853
17170
  }
16854
17171
  var markerSweep = { svc: "", at: 0, gen: 0, done: {}, runs: {}, partial: false, inflight: null };
16855
17172
  var MARKER_SWEEP_TTL_MS = 3e4;
@@ -17230,7 +17547,7 @@ Index the REMAINING windows - one record per row/item, looking at any page image
17230
17547
  var label = h(
17231
17548
  "span",
17232
17549
  { class: "bq-index-label" },
17233
- h("span", { class: "bq-md", html: parseMsgPartsHtml(indexGroupLabel(group), { imagePreviews: false }) })
17550
+ h("span", { class: "bq-md", html: parseMsgPartsHtml(indexGroupLabel(group), { imagePreviews: false, fitLinkLabels: true }) })
17234
17551
  );
17235
17552
  label.addEventListener("click", function(e) {
17236
17553
  if (e.target && e.target.closest && e.target.closest("a")) e.stopPropagation();
@@ -17595,6 +17912,7 @@ Index the REMAINING windows - one record per row/item, looking at any page image
17595
17912
  CS.uploadingAttachments = false;
17596
17913
  CS.attachmentWarning = "";
17597
17914
  CS.attachmentCapNotice = "";
17915
+ CS.attachmentCancelNotice = "";
17598
17916
  CS.attachmentsRow = null;
17599
17917
  CS.attachBtnEl = null;
17600
17918
  CS.sendBtnEl = null;