bunnyquery 1.15.0 → 1.15.2
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 +4 -2
- package/bunnyquery.js +182 -21
- package/dist/engine.cjs +178 -19
- package/dist/engine.cjs.map +1 -1
- package/dist/engine.d.mts +211 -27
- package/dist/engine.d.ts +211 -27
- package/dist/engine.mjs +169 -20
- package/dist/engine.mjs.map +1 -1
- package/package.json +1 -1
- package/src/engine/config.ts +76 -23
- package/src/engine/duplicates.ts +115 -0
- package/src/engine/host.ts +12 -0
- package/src/engine/index.ts +20 -0
- package/src/engine/project_settings.ts +47 -6
- package/src/engine/prompts/index.ts +1 -0
- package/src/engine/prompts/indexing_user_message.ts +23 -0
- package/src/engine/requests.ts +11 -8
- package/src/engine/session.ts +108 -9
package/README.md
CHANGED
|
@@ -140,7 +140,8 @@ Mounts the widget. Returns the `BunnyQuery` object.
|
|
|
140
140
|
| `attachmentParsers` | `array` | `null` | Client-side attachment parsers. See [Attachment parser plugins](#attachment-parser-plugins). |
|
|
141
141
|
| `windowedIndexing` | `boolean` | `true` | Server-driven windowed indexing for text and grid files (see [file types](#supported-file-types)). Pass `false` to fall back to agent-driven paging, which keeps the traversal inside the model's turn budget and the tab open. |
|
|
142
142
|
| `allowAnonymous` | `boolean` | `null` | Open the chat with no login for visitors without an account. `null` follows the project's own "Allow anonymous users" setting (`getConnectionInfo().conf.require_login`); `true`/`false` pins it. |
|
|
143
|
-
| `webAccess` | `boolean` | `null` | Whether the chat's answers may reach the open web (Claude `web_fetch`, OpenAI `web_search`).
|
|
143
|
+
| `webAccess` | `boolean` | `null` | Whether the chat's answers may reach the open web (Claude `web_fetch`, OpenAI `web_search`). The project's own **Web access for answers** switch on its Project Settings page (the `web_access` key of the project's `bq::settings` record, **off** unless the owner turned it on) is the **ceiling**, and this option may only restrict below it: `effective = projectSetting && webAccess !== false`. `null` or `true` follows the project; `false` turns the web off for this page whatever the project says; a value above the project setting has no effect. With the web off, answers come only from the project's files and database. Indexing is not affected. |
|
|
144
|
+
| `skipDuplicateFiles` | `boolean` | `null` | Whether a chat attachment the signed-in user **already uploaded** to this project (same stored file name, same size in bytes, same uploader, found from the file's `src::` record) is skipped: it is neither uploaded nor indexed again, the chip reads "already uploaded", and the message uses the stored copy's url. The project's **Skip duplicate files** setting (the `skip_duplicate_files` key of `bq::settings`, **on** unless the owner turned it off) is the **ceiling**, and this option may only restrict below it: `effective = projectSetting && skipDuplicateFiles !== false`. `null` or `true` follows the project; `false` lets this page re-upload duplicates; a value above the project setting has no effect. The check never blocks an upload: a failed lookup uploads as usual. |
|
|
144
145
|
| `liveStreaming` | `boolean` | `true` | Paint a chat answer into its bubble as it arrives, instead of at the end. On by default; pass `false` for buffered replies. Still a **request**, not a switch: the widget honours it only when your page's `skapi-js` actually carries skapi's half of the stream flag (it checks for `forwardRequestStream` and `forwardRequestFinalize`, or their older names `clientSecretRequestStream` and `clientSecretRequestFinalize` on an earlier `skapi-js`), and otherwise warns once and falls back to buffered replies. An older SDK silently drops the flag, which would leave the destination streaming SSE into a buffered row that reads back empty. It also needs a polling worker that relays the response bytes, which every deployed region now has; against a self-hosted worker that does not, pass `false`. |
|
|
145
146
|
| `liveStreamingRealtime` | `boolean` | `false` | Deliver streamed chunks over skapi's websocket instead of waiting for the next poll tick. Requires `liveStreaming`. Off unless you ask for it: skapi's `joinRealtime` **replaces** the connection's group, so for the length of a turn it takes the room out from under whatever else your app uses realtime for. Purely an accelerator; with it off the reply still streams, on the poll's cadence. |
|
|
146
147
|
|
|
@@ -492,7 +493,8 @@ helpers. See the `.d.ts` shipped with `bunnyquery/engine`.
|
|
|
492
493
|
| `attachmentParsers` | `array?` | Client-side attachment parsers, registered at configure time. More can be added later with `registerAttachmentParser()`. See [Attachment parser plugins](#attachment-parser-plugins). |
|
|
493
494
|
| `windowedIndexing` | `boolean?` | Opt in to **server-driven** windowed indexing for text and grid files (see [file types](#supported-file-types)). Off by default in the engine; the widget passes it as `true`. The deployed skapi workers support it; only leave it off against a self-hosted worker that does not yet strip the `_skapi_window` directive, where it would reach the provider as an unknown body field and fail the call terminally with no retry. |
|
|
494
495
|
| `liveStreaming` | `boolean?` | Opt in to **live streaming** of chat turns. Off by default in the engine (the widget passes it as `true`), and the backend ships first: a streamed row settles with a status and NO body (the answer was the stream), so against a worker that does not relay, the turn reads back empty. Pair it with `forwardRequestFinalize` and `forwardRequestStream`, and gate it on `skapiSupportsStreaming(skapi)`. |
|
|
495
|
-
| `webAccess` | `boolean?` | Whether a chat turn may reach the open web: Claude's `web_fetch` and OpenAI's `web_search` are attached to a chat request only when this resolves to `true`.
|
|
496
|
+
| `webAccess` | `boolean?` | Whether a chat turn may reach the open web: Claude's `web_fetch` and OpenAI's `web_search` are attached to a chat request only when this resolves to `true`. The project's own `web_access` setting (the `bq::settings` record, read through `configureProjectSettings`; **off** unless the project owner turned it on) is the **ceiling** and this option may only restrict below it: `effective = projectSetting && webAccess !== false`. Leave it out or pass `true` to follow the project; `false` turns the web off for your host; a value above the project setting has no effect. `webAccessEnabled(serviceId)` and `resolveWebAccess(serviceId, override?)` answer the resolved switch (sync from the cache, or awaiting the settings fetch; `override` is a per-call host value that restricts the same way). Indexing passes keep their tools regardless. Pass the same value to `buildChatSystemPrompt({ webAccess })` so the prompt matches the tool list. |
|
|
497
|
+
| `skipDuplicateFiles` | `boolean?` | Whether an attachment the signed-in user already uploaded to the project (same stored name, same size, same uploader) is skipped by `ChatSession`'s upload path: not uploaded, not indexed, the turn using the stored copy's url. The project's `skip_duplicate_files` setting (**on** unless the owner turned it off) is the **ceiling** and this option may only restrict: `effective = projectSetting && skipDuplicateFiles !== false`. The check runs only when the host implements the optional `findDuplicateUpload(file)` hook; `findDuplicateUpload(skapi, { name, size }, userId, { service? })` from the barrel is the ready-made implementation (an ends-with `getUniqueId` lookup narrowed to `src::<name>` and `src::.../<name>`, then the first record whose `data.size_bytes` and `user_id` match; it never throws, a failed lookup answers `null` and the file uploads as usual). `skipDuplicateFilesEnabled(serviceId)` and `resolveSkipDuplicateFiles(serviceId)` answer the resolved switch. |
|
|
496
498
|
| `forwardRequestFinalize` | `function?` | `skapi.forwardRequestFinalize`, bound to your Skapi instance. Stores the version of a streamed turn that history keeps (the engine sends the assembled provider body, so it reads back exactly like a buffered turn) and releases that request's chunks. Without it a streamed turn is never finalized and its row stays empty. |
|
|
497
499
|
| `forwardRequestStream` | `function?` | `skapi.forwardRequestStream`, bound to your Skapi instance. The **second half of the durability guarantee**: a row that settles while no poll is attached (closed tab, discarded background tab, slept device) is never finalized, so its answer stays in the chunk store and its history row is terminal and empty. Given the request id this drains that turn's chunks in one pass; the engine parses them exactly as it parses a live stream and finalizes what it read, so each row is recovered at most once. Without it the engine mints no recovery marker at all and behaves as it did before streaming. |
|
|
498
500
|
| `onLiveStreamUpdate` | `function?` | Observation hook for a streaming turn (`{ serverItemId, ownerKey, phase, text, thinkingText, toolNames, complete, errored }`). The engine already paints the answer text itself, so this is only for affordances it does not decide the presentation of. Never throw from it. |
|
package/bunnyquery.js
CHANGED
|
@@ -61,6 +61,13 @@
|
|
|
61
61
|
function webAccessFrom(data) {
|
|
62
62
|
return data ? normalizeWebAccess(data.web_access) : DEFAULT_WEB_ACCESS;
|
|
63
63
|
}
|
|
64
|
+
var DEFAULT_SKIP_DUPLICATE_FILES = true;
|
|
65
|
+
function normalizeSkipDuplicateFiles(value) {
|
|
66
|
+
return value !== false;
|
|
67
|
+
}
|
|
68
|
+
function skipDuplicateFilesFrom(data) {
|
|
69
|
+
return data ? normalizeSkipDuplicateFiles(data.skip_duplicate_files) : DEFAULT_SKIP_DUPLICATE_FILES;
|
|
70
|
+
}
|
|
64
71
|
var CHAT_GREETING_MAX_LENGTH = 400;
|
|
65
72
|
function normalizeChatGreeting(value) {
|
|
66
73
|
if (typeof value !== "string") return "";
|
|
@@ -203,16 +210,25 @@
|
|
|
203
210
|
function liveStreamingEnabled() {
|
|
204
211
|
return _config?.liveStreaming === true;
|
|
205
212
|
}
|
|
213
|
+
function underCeiling(projectSetting, option, override) {
|
|
214
|
+
if (!projectSetting) return false;
|
|
215
|
+
if (option === false) return false;
|
|
216
|
+
if (override === false) return false;
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
206
219
|
function webAccessEnabled(service) {
|
|
207
220
|
const opt = _config ? _config.webAccess : void 0;
|
|
208
|
-
|
|
209
|
-
return webAccessFrom(service ? cachedProjectSettings(service) : null);
|
|
221
|
+
return underCeiling(webAccessFrom(service ? cachedProjectSettings(service) : null), opt);
|
|
210
222
|
}
|
|
211
|
-
function resolveWebAccess(service) {
|
|
223
|
+
function resolveWebAccess(service, override) {
|
|
212
224
|
const opt = _config ? _config.webAccess : void 0;
|
|
213
|
-
if (
|
|
214
|
-
|
|
215
|
-
|
|
225
|
+
if (!service) return Promise.resolve(underCeiling(webAccessFrom(null), opt, override));
|
|
226
|
+
return loadProjectSettings(service).then(webAccessFrom, () => false).then((setting) => underCeiling(setting, opt, override));
|
|
227
|
+
}
|
|
228
|
+
function resolveSkipDuplicateFiles(service) {
|
|
229
|
+
const opt = _config ? _config.skipDuplicateFiles : void 0;
|
|
230
|
+
if (!service) return Promise.resolve(underCeiling(skipDuplicateFilesFrom(null), opt));
|
|
231
|
+
return loadProjectSettings(service).then(skipDuplicateFilesFrom, () => skipDuplicateFilesFrom(null)).then((setting) => underCeiling(setting, opt));
|
|
216
232
|
}
|
|
217
233
|
function streamRecoveryEnabled() {
|
|
218
234
|
if (!_config) return false;
|
|
@@ -228,6 +244,54 @@
|
|
|
228
244
|
return p === void 0 ? {} : { poll: p };
|
|
229
245
|
}
|
|
230
246
|
|
|
247
|
+
// src/engine/duplicates.ts
|
|
248
|
+
var DUPLICATE_LOOKUP_MAX_CANDIDATES = 25;
|
|
249
|
+
var SRC_PREFIX = "src::";
|
|
250
|
+
function isDuplicateCandidateId(uniqueId, name) {
|
|
251
|
+
if (typeof uniqueId !== "string" || !name) return false;
|
|
252
|
+
if (uniqueId.indexOf(SRC_PREFIX) !== 0) return false;
|
|
253
|
+
if (uniqueId === SRC_PREFIX + name) return true;
|
|
254
|
+
const tail = "/" + name;
|
|
255
|
+
return uniqueId.length > SRC_PREFIX.length + tail.length && uniqueId.slice(-tail.length) === tail;
|
|
256
|
+
}
|
|
257
|
+
function listOf(res) {
|
|
258
|
+
if (!res) return [];
|
|
259
|
+
if (Array.isArray(res)) return res;
|
|
260
|
+
return Array.isArray(res.list) ? res.list : [];
|
|
261
|
+
}
|
|
262
|
+
async function findDuplicateUpload(skapi, file, userId, opts) {
|
|
263
|
+
try {
|
|
264
|
+
if (!skapi || typeof skapi.getUniqueId !== "function" || typeof skapi.getRecords !== "function") return null;
|
|
265
|
+
const name = file && typeof file.name === "string" ? file.name : "";
|
|
266
|
+
const size = file && typeof file.size === "number" ? file.size : NaN;
|
|
267
|
+
if (!name || !(size >= 0) || !userId) return null;
|
|
268
|
+
const service = opts && opts.service ? { service: opts.service } : {};
|
|
269
|
+
const found = listOf(await skapi.getUniqueId(Object.assign({ unique_id: name, condition: "<=" }, service)));
|
|
270
|
+
const ids = [];
|
|
271
|
+
for (const item of found) {
|
|
272
|
+
const id = item && typeof item === "object" ? item.unique_id : item;
|
|
273
|
+
if (isDuplicateCandidateId(id, name) && ids.indexOf(id) === -1) ids.push(id);
|
|
274
|
+
if (ids.length >= DUPLICATE_LOOKUP_MAX_CANDIDATES) break;
|
|
275
|
+
}
|
|
276
|
+
for (const uniqueId of ids) {
|
|
277
|
+
let record = null;
|
|
278
|
+
try {
|
|
279
|
+
record = listOf(await skapi.getRecords(Object.assign({ unique_id: uniqueId }, service)))[0] || null;
|
|
280
|
+
} catch {
|
|
281
|
+
continue;
|
|
282
|
+
}
|
|
283
|
+
if (!record || typeof record !== "object") continue;
|
|
284
|
+
const data = record.data && typeof record.data === "object" ? record.data : null;
|
|
285
|
+
if (!data || data.size_bytes !== size) continue;
|
|
286
|
+
if (record.user_id !== userId) continue;
|
|
287
|
+
return { storagePath: uniqueId.slice(SRC_PREFIX.length), uniqueId, record };
|
|
288
|
+
}
|
|
289
|
+
return null;
|
|
290
|
+
} catch {
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
231
295
|
// src/engine/office.ts
|
|
232
296
|
var OFFICE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
233
297
|
"doc",
|
|
@@ -637,6 +701,10 @@ Records for the earlier pages are ALREADY saved (they reference "${src}"). The N
|
|
|
637
701
|
` : "") + `- access group (use this for EVERY record you write for this file): ${indexingAccessGroup(attachment)}
|
|
638
702
|
`;
|
|
639
703
|
}
|
|
704
|
+
var PAGE_TEXT_TABLE = "page_texts";
|
|
705
|
+
var PAGE_TEXT_RULE = `PAGE TEXT for pages WITHOUT a text layer: for EVERY page whose label (its first label, when the page is split into strips) carries NO "Embedded text layer" block, ALSO post exactly ONE record in table "${PAGE_TEXT_TABLE}" with data {"page": <its document page number from the label, 1-based>, "page_text": "<the page's complete text exactly as printed, verbatim, in reading order, nothing summarised or left out>"}, reference "src::" + the storage path above, in addition to the records above. A page WITH an embedded text layer gets NO such record: its text is already stored.
|
|
706
|
+
|
|
707
|
+
`;
|
|
640
708
|
function buildRenderDatafy(placeholder) {
|
|
641
709
|
return `
|
|
642
710
|
${placeholder}
|
|
@@ -647,7 +715,7 @@ Each image is preceded by a label giving its DOCUMENT PAGE number. That label is
|
|
|
647
715
|
|
|
648
716
|
Transcribe COMPLETELY, not representatively. A table with twenty rows gets twenty records, not a sample of the first few - if a page has more rows than you can save comfortably, still save them all rather than summarising. Where a page carries an embedded text layer it is quoted above that page's image: it is the exact text and should be preferred over reading the pixels, with the image used for layout, tables, stamps and handwriting.
|
|
649
717
|
|
|
650
|
-
Save records for THIS window of pages only, then stop and report what you saved. Do NOT try to read the rest of the file and do NOT worry about the pages after this window: if any remain, the next window is rendered and sent to you automatically. Report only the pages you were actually shown - never imply you have seen the whole document.`;
|
|
718
|
+
` + PAGE_TEXT_RULE + `Save records for THIS window of pages only, then stop and report what you saved. Do NOT try to read the rest of the file and do NOT worry about the pages after this window: if any remain, the next window is rendered and sent to you automatically. Report only the pages you were actually shown - never imply you have seen the whole document.`;
|
|
651
719
|
}
|
|
652
720
|
function buildIndexingWindowMessage(attachment, placeholder, isContinuation, positionLabel) {
|
|
653
721
|
const src = `src::${attachment.storagePath}`;
|
|
@@ -1151,7 +1219,7 @@ Index the REMAINING windows - one record per row/item, looking at any page image
|
|
|
1151
1219
|
var FILE_KEYS = ["path", "storage_path", "storagePath", "file", "file_path", "filePath"];
|
|
1152
1220
|
var TABLE_KEYS = ["table_name", "tableName"];
|
|
1153
1221
|
var GROUP_KEYS = ["access_group", "accessGroup"];
|
|
1154
|
-
var
|
|
1222
|
+
var SRC_PREFIX2 = "src::";
|
|
1155
1223
|
var RESULT_WALK_MAX_NODES = 400;
|
|
1156
1224
|
var RESULT_WALK_MAX_DEPTH = 5;
|
|
1157
1225
|
function isWebToolName(name) {
|
|
@@ -1180,8 +1248,8 @@ Index the REMAINING windows - one record per row/item, looking at any page image
|
|
|
1180
1248
|
}
|
|
1181
1249
|
function pathFromSrcId(value) {
|
|
1182
1250
|
if (typeof value !== "string") return null;
|
|
1183
|
-
if (value.indexOf(
|
|
1184
|
-
var rest = value.slice(
|
|
1251
|
+
if (value.indexOf(SRC_PREFIX2) !== 0) return null;
|
|
1252
|
+
var rest = value.slice(SRC_PREFIX2.length).trim();
|
|
1185
1253
|
return rest ? rest : null;
|
|
1186
1254
|
}
|
|
1187
1255
|
function parseJsonLoose(value) {
|
|
@@ -2811,7 +2879,7 @@ Index the REMAINING windows - one record per row/item, looking at any page image
|
|
|
2811
2879
|
fileUrls,
|
|
2812
2880
|
webAccess
|
|
2813
2881
|
}) {
|
|
2814
|
-
const web = typeof webAccess === "boolean" ? webAccess :
|
|
2882
|
+
const web = await resolveWebAccess(service, typeof webAccess === "boolean" ? webAccess : void 0);
|
|
2815
2883
|
const mcpServerDefinition = {
|
|
2816
2884
|
type: "url",
|
|
2817
2885
|
name: mcpServer.name,
|
|
@@ -4289,6 +4357,9 @@ Index the REMAINING windows - one record per row/item, looking at any page image
|
|
|
4289
4357
|
this._liveIndexKey = "";
|
|
4290
4358
|
this._liveIndexAt = 0;
|
|
4291
4359
|
this._indexClaims = {};
|
|
4360
|
+
this._bgQueueByFile = null;
|
|
4361
|
+
this._bgQueueStamp = { arr: null, length: 0, first: void 0, last: void 0 };
|
|
4362
|
+
this._bgQueueIndexRebuilds = 0;
|
|
4292
4363
|
}
|
|
4293
4364
|
/** What the display layer needs to decide whether a run is finished. `keys` holds
|
|
4294
4365
|
* every file the server still has indexing work for; `checked` is false until the
|
|
@@ -4325,13 +4396,10 @@ Index the REMAINING windows - one record per row/item, looking at any page image
|
|
|
4325
4396
|
*/
|
|
4326
4397
|
hasLiveIndexRun(storagePath) {
|
|
4327
4398
|
if (!storagePath) return false;
|
|
4328
|
-
var
|
|
4399
|
+
var scoped = this._indexClaimKey(storagePath);
|
|
4400
|
+
var claimed = this._indexClaims[scoped];
|
|
4329
4401
|
if (claimed && nowMs() - claimed < INDEX_DISPATCH_CLAIM_MS) return true;
|
|
4330
|
-
|
|
4331
|
-
for (var i = 0; i < this.bgTaskQueue.length; i++) {
|
|
4332
|
-
var e = this.bgTaskQueue[i];
|
|
4333
|
-
if (e && e.storagePath === storagePath && e.projectId === id.projectId && e.platform === id.platform) return true;
|
|
4334
|
-
}
|
|
4402
|
+
if (this._bgQueueIndex()[scoped] > 0) return true;
|
|
4335
4403
|
return this.state.messages.some(function(m) {
|
|
4336
4404
|
if (!m.isBackgroundTask || m.role !== "user" || m.isCancelled) return false;
|
|
4337
4405
|
if (!(m.isPendingQueued || m.isPendingInProcess || m.isSendingToServer)) return false;
|
|
@@ -4344,6 +4412,47 @@ Index the REMAINING windows - one record per row/item, looking at any page image
|
|
|
4344
4412
|
var id = this.host.getIdentity();
|
|
4345
4413
|
return indexScopeKey(id.projectId, id.platform) + "|" + storagePath;
|
|
4346
4414
|
}
|
|
4415
|
+
/**
|
|
4416
|
+
* bgTaskQueue as a map: scoped path (indexScopeKey(projectId, platform) +
|
|
4417
|
+
* '|' + storagePath, the key the claims and the stops use) -> entries.
|
|
4418
|
+
*
|
|
4419
|
+
* The array stays the source of truth because the engine does not own every
|
|
4420
|
+
* write to it: both hosts hand in their own array (the dashboard a Vue
|
|
4421
|
+
* reactive one it pushes to from the Files page and splices from its
|
|
4422
|
+
* fallback poller), and tests push to it directly. So the map is DERIVED, and
|
|
4423
|
+
* rebuilt when a cheap stamp says the array changed: its identity, its length,
|
|
4424
|
+
* its first and its last entry.
|
|
4425
|
+
*
|
|
4426
|
+
* Why that stamp is exact for this array: every write to bgTaskQueue is either
|
|
4427
|
+
* a push of a NEW entry object or a splice that removes one (nothing inserts
|
|
4428
|
+
* in the middle, replaces in place or re-pushes a removed entry). Under those
|
|
4429
|
+
* two operations, same length plus same last entry means the same contents:
|
|
4430
|
+
* a push changes the last entry unless that same push is removed again, and a
|
|
4431
|
+
* removal changes the length unless a push restores it, which changes the
|
|
4432
|
+
* last entry. The first entry is in the stamp as margin. A rebuild is one
|
|
4433
|
+
* pass over the array, paid once per change instead of once per claim.
|
|
4434
|
+
*/
|
|
4435
|
+
_bgQueueIndex() {
|
|
4436
|
+
var q = this.bgTaskQueue;
|
|
4437
|
+
var n = q ? q.length : 0;
|
|
4438
|
+
var first = n ? q[0] : void 0;
|
|
4439
|
+
var last = n ? q[n - 1] : void 0;
|
|
4440
|
+
var st = this._bgQueueStamp;
|
|
4441
|
+
if (this._bgQueueByFile && st.arr === q && st.length === n && st.first === first && st.last === last) {
|
|
4442
|
+
return this._bgQueueByFile;
|
|
4443
|
+
}
|
|
4444
|
+
var idx = {};
|
|
4445
|
+
for (var i = 0; i < n; i++) {
|
|
4446
|
+
var e = q[i];
|
|
4447
|
+
if (!e || !e.storagePath) continue;
|
|
4448
|
+
var k = indexScopeKey(e.projectId, e.platform) + "|" + e.storagePath;
|
|
4449
|
+
idx[k] = (idx[k] || 0) + 1;
|
|
4450
|
+
}
|
|
4451
|
+
this._bgQueueByFile = idx;
|
|
4452
|
+
this._bgQueueStamp = { arr: q, length: n, first, last };
|
|
4453
|
+
this._bgQueueIndexRebuilds++;
|
|
4454
|
+
return idx;
|
|
4455
|
+
}
|
|
4347
4456
|
/**
|
|
4348
4457
|
* Take this file's indexing slot, or report that someone already has it.
|
|
4349
4458
|
*
|
|
@@ -8341,11 +8450,26 @@ Index the REMAINING windows - one record per row/item, looking at any page image
|
|
|
8341
8450
|
if (!total) return Promise.reject(new Error("Empty attachment"));
|
|
8342
8451
|
var urls = [];
|
|
8343
8452
|
var anyIndexFailed = false;
|
|
8453
|
+
var reusedCount = 0;
|
|
8454
|
+
att.reused = false;
|
|
8344
8455
|
var chain = Promise.resolve();
|
|
8456
|
+
var findDuplicate = function(member) {
|
|
8457
|
+
if (typeof self.host.findDuplicateUpload !== "function") return Promise.resolve(null);
|
|
8458
|
+
var storedName = String(member.storagePath || "").split("/").filter(Boolean).pop() || member.file.name;
|
|
8459
|
+
return resolveSkipDuplicateFiles(id.projectId).then(function(on) {
|
|
8460
|
+
if (!on) return null;
|
|
8461
|
+
return Promise.resolve(self.host.findDuplicateUpload({ name: storedName, size: member.file.size })).then(function(hit) {
|
|
8462
|
+
return hit && typeof hit.storagePath === "string" && hit.storagePath ? hit.storagePath : null;
|
|
8463
|
+
});
|
|
8464
|
+
}).catch(function() {
|
|
8465
|
+
return null;
|
|
8466
|
+
});
|
|
8467
|
+
};
|
|
8345
8468
|
members.forEach(function(member, idx) {
|
|
8346
8469
|
chain = chain.then(function() {
|
|
8347
8470
|
var hadExists = false;
|
|
8348
8471
|
var skipped = false;
|
|
8472
|
+
var duplicateOf = null;
|
|
8349
8473
|
var existedBefore = false;
|
|
8350
8474
|
var onProg = function(p) {
|
|
8351
8475
|
if (p && p.total) {
|
|
@@ -8364,7 +8488,14 @@ Index the REMAINING windows - one record per row/item, looking at any page image
|
|
|
8364
8488
|
}
|
|
8365
8489
|
});
|
|
8366
8490
|
};
|
|
8367
|
-
return
|
|
8491
|
+
return findDuplicate(member).then(function(dup) {
|
|
8492
|
+
if (dup) {
|
|
8493
|
+
duplicateOf = dup;
|
|
8494
|
+
console.log("[chat-engine] skipping an upload the user already has:", member.storagePath, "->", dup);
|
|
8495
|
+
return;
|
|
8496
|
+
}
|
|
8497
|
+
return doMemberUpload(true);
|
|
8498
|
+
}).catch(function(err) {
|
|
8368
8499
|
var code = err && (err.code || err.body && err.body.code);
|
|
8369
8500
|
var msg = err && (err.message || err.body && err.body.message || (typeof err === "string" ? err : ""));
|
|
8370
8501
|
var isExists = code === "EXISTS" || msg && /exist/i.test(msg);
|
|
@@ -8384,9 +8515,20 @@ Index the REMAINING windows - one record per row/item, looking at any page image
|
|
|
8384
8515
|
});
|
|
8385
8516
|
}).then(function() {
|
|
8386
8517
|
if (skipped) return;
|
|
8387
|
-
return self.host.getTemporaryUrl(member.storagePath);
|
|
8518
|
+
return self.host.getTemporaryUrl(duplicateOf || member.storagePath);
|
|
8388
8519
|
}).then(function(url) {
|
|
8389
8520
|
if (skipped) return;
|
|
8521
|
+
if (duplicateOf) {
|
|
8522
|
+
urls.push({ name: member.relPath, url, storagePath: duplicateOf });
|
|
8523
|
+
reusedCount += 1;
|
|
8524
|
+
if (att.kind !== "folder") {
|
|
8525
|
+
att.uploadedUrl = url;
|
|
8526
|
+
att.storagePath = duplicateOf;
|
|
8527
|
+
att.reused = true;
|
|
8528
|
+
} else att.reusedCount = reusedCount;
|
|
8529
|
+
self.host.renderAttachmentChips();
|
|
8530
|
+
return;
|
|
8531
|
+
}
|
|
8390
8532
|
urls.push({ name: member.relPath, url, storagePath: member.storagePath });
|
|
8391
8533
|
if (att.kind !== "folder") {
|
|
8392
8534
|
att.uploadedUrl = url;
|
|
@@ -9018,7 +9160,7 @@ Index the REMAINING windows - one record per row/item, looking at any page image
|
|
|
9018
9160
|
(function() {
|
|
9019
9161
|
var MCP_PROD = "https://mcp.broadwayinc.computer";
|
|
9020
9162
|
var MCP_DEV = "https://mcp-dev.broadwayinc.computer";
|
|
9021
|
-
var BQ_VERSION = "1.15.
|
|
9163
|
+
var BQ_VERSION = "1.15.2" ;
|
|
9022
9164
|
var ATTACHMENT_URL_EXPIRES_SECONDS = 600;
|
|
9023
9165
|
var GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
|
|
9024
9166
|
var GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
@@ -10858,6 +11000,13 @@ Index the REMAINING windows - one record per row/item, looking at any page image
|
|
|
10858
11000
|
uploadAccessGroup: function(path) {
|
|
10859
11001
|
return resolveUploadAccessGroup(path);
|
|
10860
11002
|
},
|
|
11003
|
+
// "Already uploaded by this user?" from the src:: file records. The engine
|
|
11004
|
+
// asks only while the skip-duplicates switch is on; null means upload.
|
|
11005
|
+
findDuplicateUpload: function(file) {
|
|
11006
|
+
var uid = S.user && S.user.user_id;
|
|
11007
|
+
if (!uid) return Promise.resolve(null);
|
|
11008
|
+
return findDuplicateUpload(S.skapi, file, uid, { service: S.projectId });
|
|
11009
|
+
},
|
|
10861
11010
|
storagePathFor: function(relPath) {
|
|
10862
11011
|
return attachmentStoragePath(relPath);
|
|
10863
11012
|
},
|
|
@@ -11839,7 +11988,7 @@ Index the REMAINING windows - one record per row/item, looking at any page image
|
|
|
11839
11988
|
});
|
|
11840
11989
|
chip.appendChild(h("span", { class: "bq-attachment-icon", html: isFolder ? FOLDER_ICON_SVG : FILE_ICON_SVG }));
|
|
11841
11990
|
chip.appendChild(h("span", { class: "bq-attachment-name", text: att.name, title: att.name }));
|
|
11842
|
-
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) + ")" : formatBytes(att.file ? att.file.size : att.size);
|
|
11991
|
+
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);
|
|
11843
11992
|
chip.appendChild(h("span", { class: "bq-attachment-meta", text: meta }));
|
|
11844
11993
|
if (clickable) chip.appendChild(h("span", { class: "bq-attachment-arrow", text: "\u2197" }));
|
|
11845
11994
|
if (att.status !== "uploading" && att.status !== "done") {
|
|
@@ -13663,6 +13812,15 @@ Index the REMAINING windows - one record per row/item, looking at any page image
|
|
|
13663
13812
|
// true/false pins it for this page, both ways. Read at
|
|
13664
13813
|
// configureChatEngine time and when each chat request is built.
|
|
13665
13814
|
webAccess: null,
|
|
13815
|
+
// Whether a chat attachment the signed-in user ALREADY uploaded to this
|
|
13816
|
+
// project (same file name, same size, same uploader) is skipped: not
|
|
13817
|
+
// uploaded again, not indexed again, the message using the stored
|
|
13818
|
+
// copy. null = follow the project's own "Skip duplicate files" setting
|
|
13819
|
+
// (`skip_duplicate_files` in the bq::settings record), which is ON
|
|
13820
|
+
// unless the owner turned it off. The project setting is the ceiling:
|
|
13821
|
+
// false here restricts below it for this page, true has no effect on
|
|
13822
|
+
// a project that turned it off.
|
|
13823
|
+
skipDuplicateFiles: null,
|
|
13666
13824
|
// Server-driven windowed indexing; read at configureChatEngine time.
|
|
13667
13825
|
// Listed here so the defaults object is the full opt surface.
|
|
13668
13826
|
windowedIndexing: true,
|
|
@@ -13744,6 +13902,9 @@ Index the REMAINING windows - one record per row/item, looking at any page image
|
|
|
13744
13902
|
// chat request (off unless the owner turned it on). Passing the null
|
|
13745
13903
|
// default through would read as a decision.
|
|
13746
13904
|
webAccess: typeof S.opts.webAccess === "boolean" ? S.opts.webAccess : void 0,
|
|
13905
|
+
// Skip duplicate uploads. Same hand-over rule: only a pinned boolean is
|
|
13906
|
+
// passed, and the project's setting is the ceiling the engine applies.
|
|
13907
|
+
skipDuplicateFiles: typeof S.opts.skipDuplicateFiles === "boolean" ? S.opts.skipDuplicateFiles : void 0,
|
|
13747
13908
|
// ---- live streaming (mirrored in agent.vue's ai_agent.ts) --------
|
|
13748
13909
|
// On by default since every region's polling worker relays the
|
|
13749
13910
|
// response bytes. It used to be off for the shipping-order reason
|