bunnyquery 1.19.3 → 1.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -2
- package/bunnyquery.css +21 -0
- package/bunnyquery.js +303 -18
- package/dist/engine.cjs +274 -14
- package/dist/engine.cjs.map +1 -1
- package/dist/engine.d.mts +102 -1
- package/dist/engine.d.ts +102 -1
- package/dist/engine.mjs +273 -15
- package/dist/engine.mjs.map +1 -1
- package/package.json +1 -1
- package/src/engine/config.ts +36 -0
- package/src/engine/index.ts +4 -0
- package/src/engine/prompts/chat_system_prompt.ts +10 -2
- package/src/engine/requests.ts +8 -2
- package/src/engine/session.ts +275 -10
- package/styles/chat.css +21 -0
package/dist/engine.cjs
CHANGED
|
@@ -257,6 +257,17 @@ function resolveForwardRequestStream() {
|
|
|
257
257
|
function windowedIndexingEnabled() {
|
|
258
258
|
return _config?.windowedIndexing === true;
|
|
259
259
|
}
|
|
260
|
+
function statusPushEnabled() {
|
|
261
|
+
return _config?.statusPush === true && typeof _config?.onRequestStatus === "function";
|
|
262
|
+
}
|
|
263
|
+
function statusPushLive() {
|
|
264
|
+
if (!statusPushEnabled() || typeof _config?.isRequestStatusLive !== "function") return false;
|
|
265
|
+
try {
|
|
266
|
+
return !!_config.isRequestStatusLive();
|
|
267
|
+
} catch (e) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
260
271
|
function liveStreamingSocketEnabled() {
|
|
261
272
|
return liveStreamingEnabled() && _config?.liveStreaming === true;
|
|
262
273
|
}
|
|
@@ -841,7 +852,8 @@ WHEN THE DATA DOES NOT HAVE IT, SAY SO. Once you have searched the way these rul
|
|
|
841
852
|
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.
|
|
842
853
|
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.`;
|
|
843
854
|
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.`;
|
|
844
|
-
const documentRules = `DOCUMENTS (a contract, a report, a manual, a letter, any uploaded file the user asks about the content of): FIRST FIND THE FILE, with getFileOutline when you know its storage path, otherwise by its "src::" record (see WHERE INDEXED CONTENT LIVES) using the name the user used. THEN FIND THE PAGE with searchText: with the file's path when the user named a file, without a path when they did not ("find a file that contains X"), and follow its description's steps 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"); never present a paraphrase as a quote. A file with no page text is read with readFileContent instead and cited by its file name
|
|
855
|
+
const documentRules = `DOCUMENTS (a contract, a report, a manual, a letter, any uploaded file the user asks about the content of): FIRST FIND THE FILE, with getFileOutline when you know its storage path, otherwise by its "src::" record (see WHERE INDEXED CONTENT LIVES) using the name the user used. THEN FIND THE PAGE with searchText: with the file's path when the user named a file, without a path when they did not ("find a file that contains X"), and follow its description's steps 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"); never present a paraphrase as a quote. A file with no page text is read with readFileContent instead and cited by its file name. For a long file (a manual, a book), call getFileOutline first 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.
|
|
856
|
+
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.`;
|
|
845
857
|
const groupIsPublic = indexGroupLiteral === '"public"' || indexGroupLiteral === "0";
|
|
846
858
|
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.`;
|
|
847
859
|
let systemPrompt = `
|
|
@@ -850,7 +862,6 @@ Scope: Only answer questions about this project and its data. Do not answer ques
|
|
|
850
862
|
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.
|
|
851
863
|
${groundingRules}
|
|
852
864
|
${webRule}
|
|
853
|
-
SAVED FINDINGS FIRST: where an earlier search found an answer is saved in table "search_findings" (one record per file page; its tags are the key words of the question that led there and of the search terms, stored lowercase without spaces). Before any other search, call getRecords with table_name "search_findings", access_group ${indexGroupLiteral} and tags set to ONE specific key word of the question (a name or a term, in the user's words; when nothing comes back, try one more word, or the word in the documents' language). A finding gives data.path and data.page: read THAT page (searchText with that path and the question's words) and answer from the page itself, quoting and citing it as usual. A finding is only a pointer, never the answer: when its page does not answer the question, or nothing is found, search as below.
|
|
854
865
|
FINDING THE DATA: the database is the way in, for every kind of file. Follow 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).
|
|
855
866
|
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.
|
|
856
867
|
${documentRules}
|
|
@@ -2640,6 +2651,9 @@ async function notifyAgentSaveAttachment(info) {
|
|
|
2640
2651
|
service,
|
|
2641
2652
|
owner,
|
|
2642
2653
|
...pollOpt(),
|
|
2654
|
+
// Status push for this pass and the continuations the worker queues from it
|
|
2655
|
+
// (see ChatEngineConfig.statusPush). Absent unless the host turned it on.
|
|
2656
|
+
...statusPushEnabled() ? { notify: true } : {},
|
|
2643
2657
|
url: OPENAI_RESPONSES_API_URL,
|
|
2644
2658
|
method: "POST",
|
|
2645
2659
|
headers: {
|
|
@@ -2684,6 +2698,9 @@ async function notifyAgentSaveAttachment(info) {
|
|
|
2684
2698
|
service,
|
|
2685
2699
|
owner,
|
|
2686
2700
|
...pollOpt(),
|
|
2701
|
+
// Status push for this pass and the continuations the worker queues from it
|
|
2702
|
+
// (see ChatEngineConfig.statusPush). Absent unless the host turned it on.
|
|
2703
|
+
...statusPushEnabled() ? { notify: true } : {},
|
|
2687
2704
|
url: ANTHROPIC_MESSAGES_API_URL,
|
|
2688
2705
|
method: "POST",
|
|
2689
2706
|
headers: {
|
|
@@ -5323,6 +5340,11 @@ var INDEX_DISPATCH_CLAIM_MS = 2 * 60 * 1e3;
|
|
|
5323
5340
|
var WORKER_PASS_ADOPT_ATTEMPTS = [0, 2e3, 6e3];
|
|
5324
5341
|
var RECENT_INDEX_PASS_EVIDENCE_MS = 10 * 60 * 1e3;
|
|
5325
5342
|
var ADOPT_TICK_MS = 10 * 1e3;
|
|
5343
|
+
var STATUS_PUSH_ADOPT_TICK_MS = 60 * 1e3;
|
|
5344
|
+
var CATCH_UP_MIN_GAP_MS = 2e3;
|
|
5345
|
+
var RETURN_WATCH_MS = 15 * 1e3;
|
|
5346
|
+
var RETURN_WATCH_SLEEP_GAP_MS = 45 * 1e3;
|
|
5347
|
+
var STATUS_NUDGE_MIN_GAP_MS = 2e3;
|
|
5326
5348
|
var EARLY_PROBE_SCHEDULE_MS = [400, 900, 1700];
|
|
5327
5349
|
var INDEXING_DRAIN_BUSY_POLL_MS = 8e3;
|
|
5328
5350
|
var INDEXING_DRAIN_CONFIRM_POLL_MS = 3e3;
|
|
@@ -5464,6 +5486,12 @@ function requestIdTimeMs(rid) {
|
|
|
5464
5486
|
}
|
|
5465
5487
|
return Math.floor(v / 2 / 1e6);
|
|
5466
5488
|
}
|
|
5489
|
+
var WRONG_ANSWER_MESSAGE = "This answer seems wrong. Please check it again against the documents.";
|
|
5490
|
+
var WRONG_ANSWER_LABEL = "Wrong answer?";
|
|
5491
|
+
function canReportWrongAnswer(msg) {
|
|
5492
|
+
var note = retrievalNoteOfAnswer(msg);
|
|
5493
|
+
return !!note && !answerUsedNoDataTool(note) && !msg.isCancelled;
|
|
5494
|
+
}
|
|
5467
5495
|
var _ChatSession = class _ChatSession {
|
|
5468
5496
|
constructor(host) {
|
|
5469
5497
|
// --- live streaming ----------------------------------------------------
|
|
@@ -5513,6 +5541,10 @@ var _ChatSession = class _ChatSession {
|
|
|
5513
5541
|
// bubble can never silently revert to its 200-char head.
|
|
5514
5542
|
this._hydratedBodies = {};
|
|
5515
5543
|
this._hydratingItems = {};
|
|
5544
|
+
/** The button's label and the message it sends, read off the session so the
|
|
5545
|
+
* clients need no extra import. */
|
|
5546
|
+
this.wrongAnswerLabel = WRONG_ANSWER_LABEL;
|
|
5547
|
+
this.wrongAnswerMessage = WRONG_ANSWER_MESSAGE;
|
|
5516
5548
|
this.typewriterQueue = Promise.resolve();
|
|
5517
5549
|
/**
|
|
5518
5550
|
* Pick up indexing passes the WORKER minted, which no client ever dispatched.
|
|
@@ -5549,6 +5581,27 @@ var _ChatSession = class _ChatSession {
|
|
|
5549
5581
|
* a reload starts without it and asks once, as before. */
|
|
5550
5582
|
this._idleVerdictAt = {};
|
|
5551
5583
|
this._adoptTickTimer = null;
|
|
5584
|
+
/** Start the ADOPT_TICK_MS follow-up if this page is tracking live indexing work and
|
|
5585
|
+
* is visible. Idempotent; each tick re-checks and stops when the work is gone, the tab
|
|
5586
|
+
* is hidden (resume restarts it through refreshLiveIndexState) or the view closed. */
|
|
5587
|
+
// ── RETURN CATCH-UP + REQUEST STATUS PUSH (owner, 2026-11-23) ──────────────
|
|
5588
|
+
// The rule: when the user comes back to the chat (the tab shown again, the computer
|
|
5589
|
+
// awake again, the network or the websocket back), the chat is re-read from the
|
|
5590
|
+
// server, so nothing that happened while they were away is missing. The re-read is
|
|
5591
|
+
// loadHistory's own first-page refresh, the one every mount runs: it keeps older pages
|
|
5592
|
+
// the user loaded, keeps a send still in flight, never lets an empty answer replace a
|
|
5593
|
+
// known one, re-attaches polls to whatever is still waiting, and reads back a streamed
|
|
5594
|
+
// answer nobody finalized. Status frames (statusPush) only make things faster; they
|
|
5595
|
+
// never decide anything on screen.
|
|
5596
|
+
this._catchUpAt = 0;
|
|
5597
|
+
this._catchUpTimer = null;
|
|
5598
|
+
this._returnWatchTimer = null;
|
|
5599
|
+
this._returnWatchAt = 0;
|
|
5600
|
+
this._returnListeners = false;
|
|
5601
|
+
this._statusUnsub = null;
|
|
5602
|
+
this._statusNudgeTimer = null;
|
|
5603
|
+
this._statusNudgeAt = 0;
|
|
5604
|
+
this._statusSeenConnect = false;
|
|
5552
5605
|
/** The last COMPLETE running+pending look at this user's bg queue: which pass ids were
|
|
5553
5606
|
* live. Complete means both lists came back shorter than their limit, so a tracked pass
|
|
5554
5607
|
* missing from it really has left the queue. */
|
|
@@ -5593,6 +5646,7 @@ var _ChatSession = class _ChatSession {
|
|
|
5593
5646
|
this.historyItemPolls = /* @__PURE__ */ new Map();
|
|
5594
5647
|
this._pauseReasons = /* @__PURE__ */ new Set();
|
|
5595
5648
|
this._resuming = false;
|
|
5649
|
+
this._wrongReported = {};
|
|
5596
5650
|
this._lidSeq = 0;
|
|
5597
5651
|
this._stageSeq = 0;
|
|
5598
5652
|
this._uploadBatches = 0;
|
|
@@ -6987,8 +7041,7 @@ var _ChatSession = class _ChatSession {
|
|
|
6987
7041
|
this._resuming = true;
|
|
6988
7042
|
return Promise.resolve().then(function() {
|
|
6989
7043
|
self.drainBgTaskQueue();
|
|
6990
|
-
|
|
6991
|
-
self.refreshLiveIndexState();
|
|
7044
|
+
return self.catchUpHistory();
|
|
6992
7045
|
}).catch(function(e) {
|
|
6993
7046
|
console.error("[chat-engine] resume polling failed", e);
|
|
6994
7047
|
}).then(function() {
|
|
@@ -8219,6 +8272,54 @@ var _ChatSession = class _ChatSession {
|
|
|
8219
8272
|
}
|
|
8220
8273
|
});
|
|
8221
8274
|
}
|
|
8275
|
+
/**
|
|
8276
|
+
* Does this bubble get the "Wrong answer?" button: the free function's gate,
|
|
8277
|
+
* and only on the latest answer, because the message it sends names no answer
|
|
8278
|
+
* and the model reads it right after the last one. An answer already reported
|
|
8279
|
+
* keeps its (disabled) button after the complaint turn lands below it.
|
|
8280
|
+
*/
|
|
8281
|
+
canReportWrongAnswer(msg) {
|
|
8282
|
+
if (!canReportWrongAnswer(msg)) return false;
|
|
8283
|
+
return this.wrongAnswerReported(msg) || this._isLatestAnswer(msg);
|
|
8284
|
+
}
|
|
8285
|
+
/** True when no chat turn follows `msg` in state.messages. Indexing rows and
|
|
8286
|
+
* cancelled turns do not count (neither reaches the model's history). Matched
|
|
8287
|
+
* by identity or by item id, since agent.vue hands in reactive proxies. */
|
|
8288
|
+
_isLatestAnswer(msg) {
|
|
8289
|
+
var list = this.state.messages || [];
|
|
8290
|
+
var sid = msg._serverItemId, lid = msg._localId;
|
|
8291
|
+
for (var i = list.length - 1; i >= 0; i--) {
|
|
8292
|
+
var m = list[i];
|
|
8293
|
+
if (!m) continue;
|
|
8294
|
+
if (m === msg || m.role === "assistant" && (sid && m._serverItemId === sid || lid && m._localId === lid)) return true;
|
|
8295
|
+
if (m.isBackgroundTask || m.isCancelled) continue;
|
|
8296
|
+
return false;
|
|
8297
|
+
}
|
|
8298
|
+
return false;
|
|
8299
|
+
}
|
|
8300
|
+
/** True once this answer's "Wrong answer?" was sent (one click per answer). */
|
|
8301
|
+
wrongAnswerReported(msg) {
|
|
8302
|
+
if (!msg) return false;
|
|
8303
|
+
if (msg._wrongReported) return true;
|
|
8304
|
+
var key = msg._serverItemId || msg._localId;
|
|
8305
|
+
return !!key && !!this._wrongReported[key];
|
|
8306
|
+
}
|
|
8307
|
+
/**
|
|
8308
|
+
* The "Wrong answer?" button: sends WRONG_ANSWER_MESSAGE as an ordinary visible
|
|
8309
|
+
* user turn through dispatchComposedMessage, so it reads the same after a reload
|
|
8310
|
+
* and both clients behave alike. The answer is marked first, so the button goes
|
|
8311
|
+
* disabled at once. False when the bubble does not qualify or was already used.
|
|
8312
|
+
* `pinned` is the caller's usual pinned identity and prompt (agent.vue pins them).
|
|
8313
|
+
*/
|
|
8314
|
+
reportWrongAnswer(msg, pinned) {
|
|
8315
|
+
if (this.wrongAnswerReported(msg) || !this.canReportWrongAnswer(msg)) return false;
|
|
8316
|
+
msg._wrongReported = true;
|
|
8317
|
+
var key = msg._serverItemId || msg._localId;
|
|
8318
|
+
if (key) this._wrongReported[key] = true;
|
|
8319
|
+
this.host.notify();
|
|
8320
|
+
this.dispatchComposedMessage(WRONG_ANSWER_MESSAGE, false, void 0, void 0, void 0, pinned);
|
|
8321
|
+
return true;
|
|
8322
|
+
}
|
|
8222
8323
|
/**
|
|
8223
8324
|
* Stop waiting for the reply to the chat turn that is running now, and move on.
|
|
8224
8325
|
*
|
|
@@ -9059,9 +9160,153 @@ var _ChatSession = class _ChatSession {
|
|
|
9059
9160
|
});
|
|
9060
9161
|
return found;
|
|
9061
9162
|
}
|
|
9062
|
-
/**
|
|
9063
|
-
*
|
|
9064
|
-
*
|
|
9163
|
+
/**
|
|
9164
|
+
* Re-read the chat from the server now (see the rule above). Safe to call from any
|
|
9165
|
+
* number of triggers at once: calls within CATCH_UP_MIN_GAP_MS of the last one run
|
|
9166
|
+
* once, at the end of the gap. Nothing happens while no chat view is mounted (the
|
|
9167
|
+
* mount loads the chat anyway) or while background polling is paused (the tab is
|
|
9168
|
+
* hidden: showing it calls this again).
|
|
9169
|
+
*/
|
|
9170
|
+
catchUpHistory() {
|
|
9171
|
+
var self = this;
|
|
9172
|
+
var id = this.host.getIdentity();
|
|
9173
|
+
if (!id.projectId || id.platform === "none") return Promise.resolve();
|
|
9174
|
+
if (!this.host.isViewMounted || !this.host.isViewMounted() || this.isPollingPaused()) return Promise.resolve();
|
|
9175
|
+
this._ensureReturnWatch();
|
|
9176
|
+
var wait = this._catchUpAt + CATCH_UP_MIN_GAP_MS - Date.now();
|
|
9177
|
+
if (wait > 0) {
|
|
9178
|
+
if (!this._catchUpTimer) {
|
|
9179
|
+
this._catchUpTimer = setTimeout(function() {
|
|
9180
|
+
self._catchUpTimer = null;
|
|
9181
|
+
self.catchUpHistory();
|
|
9182
|
+
}, wait);
|
|
9183
|
+
}
|
|
9184
|
+
return Promise.resolve();
|
|
9185
|
+
}
|
|
9186
|
+
this._catchUpAt = Date.now();
|
|
9187
|
+
return this.loadHistory(false, this.state.gateRefreshToken).catch(function(e) {
|
|
9188
|
+
console.error("[chat-engine] catch-up failed", e);
|
|
9189
|
+
});
|
|
9190
|
+
}
|
|
9191
|
+
/**
|
|
9192
|
+
* Watch for the moments the user comes back without the tab being hidden first: the
|
|
9193
|
+
* computer waking from sleep (the timer finds a gap far longer than its interval),
|
|
9194
|
+
* the network coming back, a page restored from the back-forward cache. Also starts
|
|
9195
|
+
* the status push listener. Runs while a chat view is mounted and stops itself when
|
|
9196
|
+
* none is.
|
|
9197
|
+
*/
|
|
9198
|
+
_ensureReturnWatch() {
|
|
9199
|
+
var self = this;
|
|
9200
|
+
if (typeof window === "undefined") return;
|
|
9201
|
+
if (!this._returnListeners) {
|
|
9202
|
+
this._returnListeners = true;
|
|
9203
|
+
var onBack = function() {
|
|
9204
|
+
if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
|
|
9205
|
+
self.catchUpHistory();
|
|
9206
|
+
};
|
|
9207
|
+
window.addEventListener("online", onBack);
|
|
9208
|
+
window.addEventListener("pageshow", function(ev) {
|
|
9209
|
+
if (ev && ev.persisted) onBack();
|
|
9210
|
+
});
|
|
9211
|
+
}
|
|
9212
|
+
this._startStatusPush();
|
|
9213
|
+
if (this._returnWatchTimer) return;
|
|
9214
|
+
this._returnWatchAt = Date.now();
|
|
9215
|
+
var look = function() {
|
|
9216
|
+
self._returnWatchTimer = null;
|
|
9217
|
+
if (!self.host.isViewMounted || !self.host.isViewMounted()) {
|
|
9218
|
+
self._stopStatusPush();
|
|
9219
|
+
return;
|
|
9220
|
+
}
|
|
9221
|
+
var now = Date.now();
|
|
9222
|
+
var gap = now - self._returnWatchAt;
|
|
9223
|
+
self._returnWatchAt = now;
|
|
9224
|
+
if (gap > RETURN_WATCH_SLEEP_GAP_MS && (typeof document === "undefined" || document.visibilityState !== "hidden")) {
|
|
9225
|
+
self.catchUpHistory();
|
|
9226
|
+
}
|
|
9227
|
+
self._returnWatchTimer = setTimeout(look, RETURN_WATCH_MS);
|
|
9228
|
+
};
|
|
9229
|
+
this._returnWatchTimer = setTimeout(look, RETURN_WATCH_MS);
|
|
9230
|
+
}
|
|
9231
|
+
/** Listen to request status frames while a chat view is mounted (statusPush on). */
|
|
9232
|
+
_startStatusPush() {
|
|
9233
|
+
if (this._statusUnsub || !statusPushEnabled()) return;
|
|
9234
|
+
var self = this;
|
|
9235
|
+
this._statusSeenConnect = false;
|
|
9236
|
+
try {
|
|
9237
|
+
var unsub = chatEngineConfig().onRequestStatus(function(ev) {
|
|
9238
|
+
self._onRequestStatus(ev);
|
|
9239
|
+
});
|
|
9240
|
+
this._statusUnsub = typeof unsub === "function" ? unsub : function() {
|
|
9241
|
+
};
|
|
9242
|
+
} catch (e) {
|
|
9243
|
+
this._statusUnsub = null;
|
|
9244
|
+
}
|
|
9245
|
+
}
|
|
9246
|
+
_stopStatusPush() {
|
|
9247
|
+
var unsub = this._statusUnsub;
|
|
9248
|
+
this._statusUnsub = null;
|
|
9249
|
+
if (this._statusNudgeTimer) {
|
|
9250
|
+
clearTimeout(this._statusNudgeTimer);
|
|
9251
|
+
this._statusNudgeTimer = null;
|
|
9252
|
+
}
|
|
9253
|
+
if (unsub) {
|
|
9254
|
+
try {
|
|
9255
|
+
unsub();
|
|
9256
|
+
} catch (e) {
|
|
9257
|
+
}
|
|
9258
|
+
}
|
|
9259
|
+
}
|
|
9260
|
+
/**
|
|
9261
|
+
* One status frame event. 'connected' (first connection, and every reconnect after a
|
|
9262
|
+
* drop, a sleep or the planned renewal) catches up, because frames sent while the
|
|
9263
|
+
* socket was down are lost. A status change of an indexing pass this page does not
|
|
9264
|
+
* poll runs the queue check now instead of at its next heartbeat; a pass that IS polled
|
|
9265
|
+
* was already woken by skapi-js itself. Chat turns are left to their own polls.
|
|
9266
|
+
*/
|
|
9267
|
+
_onRequestStatus(ev) {
|
|
9268
|
+
if (!ev || !this.host.isViewMounted()) return;
|
|
9269
|
+
if (ev.type === "connected") {
|
|
9270
|
+
if (!this._statusSeenConnect) {
|
|
9271
|
+
this._statusSeenConnect = true;
|
|
9272
|
+
return;
|
|
9273
|
+
}
|
|
9274
|
+
if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
|
|
9275
|
+
this.catchUpHistory();
|
|
9276
|
+
return;
|
|
9277
|
+
}
|
|
9278
|
+
if (ev.type !== "status" || typeof ev.id !== "string") return;
|
|
9279
|
+
if (!ev.queue || !isBgIndexingQueue(ev.queue)) return;
|
|
9280
|
+
if (this.historyItemPolls.has(ev.id)) return;
|
|
9281
|
+
var tracked = false;
|
|
9282
|
+
for (var i = 0; i < this.bgTaskQueue.length; i++) {
|
|
9283
|
+
var e = this.bgTaskQueue[i];
|
|
9284
|
+
if (e && e.id === ev.id) {
|
|
9285
|
+
tracked = !e.byListing;
|
|
9286
|
+
break;
|
|
9287
|
+
}
|
|
9288
|
+
}
|
|
9289
|
+
if (tracked) return;
|
|
9290
|
+
this._nudgeQueueCheck();
|
|
9291
|
+
}
|
|
9292
|
+
/** Run the queue check (adopt, settle by listing, page progress) now, at most once per
|
|
9293
|
+
* STATUS_NUDGE_MIN_GAP_MS, then let the heartbeat carry on. */
|
|
9294
|
+
_nudgeQueueCheck() {
|
|
9295
|
+
var self = this;
|
|
9296
|
+
if (this._statusNudgeTimer) return;
|
|
9297
|
+
var wait = Math.max(0, this._statusNudgeAt + STATUS_NUDGE_MIN_GAP_MS - Date.now());
|
|
9298
|
+
this._statusNudgeTimer = setTimeout(function() {
|
|
9299
|
+
self._statusNudgeTimer = null;
|
|
9300
|
+
self._statusNudgeAt = Date.now();
|
|
9301
|
+
var id = self.host.getIdentity();
|
|
9302
|
+
if (!id.projectId || id.platform !== "claude" && id.platform !== "openai") return;
|
|
9303
|
+
if (self.isPollingPaused() || !self.host.isViewMounted()) return;
|
|
9304
|
+
self._adoptWorkerIndexingPasses(0, false, true);
|
|
9305
|
+
self._settleByListing();
|
|
9306
|
+
self._refreshPageProgress();
|
|
9307
|
+
self._ensureAdoptTick();
|
|
9308
|
+
}, wait);
|
|
9309
|
+
}
|
|
9065
9310
|
_ensureAdoptTick() {
|
|
9066
9311
|
if (this._adoptTickTimer) return;
|
|
9067
9312
|
var self = this;
|
|
@@ -9082,7 +9327,7 @@ var _ChatSession = class _ChatSession {
|
|
|
9082
9327
|
self._settleByListing();
|
|
9083
9328
|
self._refreshPageProgress();
|
|
9084
9329
|
self._ensureAdoptTick();
|
|
9085
|
-
}, ADOPT_TICK_MS);
|
|
9330
|
+
}, statusPushLive() ? STATUS_PUSH_ADOPT_TICK_MS : ADOPT_TICK_MS);
|
|
9086
9331
|
}
|
|
9087
9332
|
/**
|
|
9088
9333
|
* Follow an indexing pass found in a loaded history page through the queue check
|
|
@@ -9164,12 +9409,8 @@ var _ChatSession = class _ChatSession {
|
|
|
9164
9409
|
this.state.messages.splice(idx + 1, 0, placeholder);
|
|
9165
9410
|
return true;
|
|
9166
9411
|
}
|
|
9167
|
-
/**
|
|
9168
|
-
* Save where a hard search found its answer (findings.ts), through the host's
|
|
9169
|
-
* saveSearchFinding hook. Never for an indexing pass, never twice for one turn, never
|
|
9170
|
-
* throws, never waited on.
|
|
9171
|
-
*/
|
|
9172
9412
|
_saveFindings(itemId, body, answer, note) {
|
|
9413
|
+
if (!_ChatSession.SAVE_SEARCH_FINDINGS) return;
|
|
9173
9414
|
try {
|
|
9174
9415
|
var save = chatEngineConfig().saveSearchFinding;
|
|
9175
9416
|
if (typeof save !== "function" || !note || !body) return;
|
|
@@ -9698,6 +9939,7 @@ var _ChatSession = class _ChatSession {
|
|
|
9698
9939
|
var id = this.host.getIdentity();
|
|
9699
9940
|
var svcId = id.projectId, plat = id.platform;
|
|
9700
9941
|
if (!svcId || plat === "none" || !this.host.isViewMounted()) return;
|
|
9942
|
+
this._ensureReturnWatch();
|
|
9701
9943
|
this._applyIndexCancellations();
|
|
9702
9944
|
this._sweepCancelledIndexing();
|
|
9703
9945
|
this._ensureAdoptTick();
|
|
@@ -9766,6 +10008,11 @@ var _ChatSession = class _ChatSession {
|
|
|
9766
10008
|
var executedAt;
|
|
9767
10009
|
var bp = entry2.poll({
|
|
9768
10010
|
latency: POLL_INTERVAL,
|
|
10011
|
+
// Status push (statusPushEnabled): a pass adopted from a listing is polled
|
|
10012
|
+
// slowly while frames arrive, like one this page dispatched. A dispatch
|
|
10013
|
+
// reply's poll decides that from the server's acknowledgement and
|
|
10014
|
+
// ignores this key.
|
|
10015
|
+
notify: statusPushEnabled(),
|
|
9769
10016
|
onResponse: function(_res, meta) {
|
|
9770
10017
|
if (meta && typeof meta.executed === "number" && meta.executed > 0) executedAt = meta.executed;
|
|
9771
10018
|
}
|
|
@@ -10414,7 +10661,7 @@ var _ChatSession = class _ChatSession {
|
|
|
10414
10661
|
}
|
|
10415
10662
|
}
|
|
10416
10663
|
};
|
|
10417
|
-
var pp = isBg ? item.poll(Object.assign({ latency: POLL_INTERVAL }, pollOpts)) : self._fgPollWithEarlyProbe(item, capturedId, pollOpts, {
|
|
10664
|
+
var pp = isBg ? item.poll(Object.assign({ latency: POLL_INTERVAL, notify: statusPushEnabled() }, pollOpts)) : self._fgPollWithEarlyProbe(item, capturedId, pollOpts, {
|
|
10418
10665
|
platform,
|
|
10419
10666
|
projectId,
|
|
10420
10667
|
owner,
|
|
@@ -10761,6 +11008,17 @@ var _ChatSession = class _ChatSession {
|
|
|
10761
11008
|
this.state.gateRefreshToken += 1;
|
|
10762
11009
|
}
|
|
10763
11010
|
};
|
|
11011
|
+
/**
|
|
11012
|
+
* Save where a hard search found its answer (findings.ts), through the host's
|
|
11013
|
+
* saveSearchFinding hook. Never for an indexing pass, never twice for one turn, never
|
|
11014
|
+
* throws, never waited on.
|
|
11015
|
+
*
|
|
11016
|
+
* OFF since 1.20.1 (owner, 2026-11-24): the MCP's searchText now learns which page answered
|
|
11017
|
+
* a question by itself (learned links, read first by every search), so the chat no longer
|
|
11018
|
+
* reads "search_findings" first (that read cost 7 to 8 s at the start of every turn in
|
|
11019
|
+
* production) and nothing is saved here. SAVE_SEARCH_FINDINGS turns it back on.
|
|
11020
|
+
*/
|
|
11021
|
+
_ChatSession.SAVE_SEARCH_FINDINGS = false;
|
|
10764
11022
|
/** How many passes one "Load more" brings into a file's row. */
|
|
10765
11023
|
_ChatSession.RUN_PASS_PAGE = 10;
|
|
10766
11024
|
var ChatSession = _ChatSession;
|
|
@@ -11028,6 +11286,8 @@ exports.shouldRescueInFlightMessage = shouldRescueInFlightMessage;
|
|
|
11028
11286
|
exports.skapiSupportsStreaming = skapiSupportsStreaming;
|
|
11029
11287
|
exports.skipDuplicateFilesEnabled = skipDuplicateFilesEnabled;
|
|
11030
11288
|
exports.skipDuplicateFilesFrom = skipDuplicateFilesFrom;
|
|
11289
|
+
exports.statusPushEnabled = statusPushEnabled;
|
|
11290
|
+
exports.statusPushLive = statusPushLive;
|
|
11031
11291
|
exports.streamRecoveryEnabled = streamRecoveryEnabled;
|
|
11032
11292
|
exports.streamRecoveryLabels = streamRecoveryLabels;
|
|
11033
11293
|
exports.streamRecoveryPhase = streamRecoveryPhase;
|