bunnyquery 1.18.0 → 1.19.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 +22 -16
- package/bunnyquery.css +29 -0
- package/bunnyquery.js +8975 -7340
- package/dist/engine.cjs +8620 -7395
- package/dist/engine.cjs.map +1 -1
- package/dist/engine.d.mts +475 -193
- package/dist/engine.d.ts +475 -193
- package/dist/engine.mjs +8614 -7396
- package/dist/engine.mjs.map +1 -1
- package/package.json +1 -1
- package/src/engine/config.ts +72 -138
- package/src/engine/duplicates.ts +114 -35
- package/src/engine/findings.ts +305 -0
- package/src/engine/history.ts +27 -2
- package/src/engine/host.ts +31 -1
- package/src/engine/index.ts +15 -1
- package/src/engine/indexing_groups.ts +60 -0
- package/src/engine/prompts/chat_system_prompt.ts +2 -1
- package/src/engine/prompts/indexing_system_prompt.ts +2 -2
- package/src/engine/prompts/indexing_user_message.ts +4 -3
- package/src/engine/requests.ts +57 -3
- package/src/engine/retrieval_memory.ts +11 -0
- package/src/engine/session.ts +932 -87
- package/src/widget.css +15 -0
- package/styles/chat.css +14 -0
|
@@ -145,7 +145,7 @@ export function buildIndexingUserMessage(
|
|
|
145
145
|
head +
|
|
146
146
|
`\nRead this file with the readFileContent tool, using the storage path above - do NOT fetch a URL and do NOT rely on a single sample. ` +
|
|
147
147
|
`readFileContent returns the file ONE WINDOW at a time: spreadsheets as coordinate-tagged grid rows (e.g. 'R4 A:E&I NUMBER | B:E1007'), scanned/large PDFs as rendered PAGE IMAGES, and windows may include embedded photos - LOOK at any images and datafy what they show. ` +
|
|
148
|
-
`Page through EVERY window: for each window SAVE records for its rows/items/pages (postRecords, one record per row/item), THEN if the window says MORE REMAINS call readFileContent again with the cursor it gives you. Repeat until it says END OF FILE, so the WHOLE file is indexed. ` +
|
|
148
|
+
`Page through EVERY window: for each window SAVE records for its rows/items/pages (postRecords, one record per row/item; spreadsheet rows in "spreadsheet_rows", everything else in "document_entries"), THEN if the window says MORE REMAINS call readFileContent again with the cursor it gives you. Repeat until it says END OF FILE, so the WHOLE file is indexed. ` +
|
|
149
149
|
`Do NOT stop after the first window and do NOT just write a summary. Set every record's reference to exactly "src::" + the storage path above; that file record already exists, so enrich it with updateRecords instead of posting it again.` +
|
|
150
150
|
(attachment.url ? `\n(A temporary URL is provided ONLY as a fallback if readFileContent fails: ${attachment.url})` : '')
|
|
151
151
|
);
|
|
@@ -264,7 +264,8 @@ function buildRenderDatafy(placeholder: string): string {
|
|
|
264
264
|
return (
|
|
265
265
|
`\n${placeholder}\n\n` +
|
|
266
266
|
`LOOK at each rendered page image in this message and DATAFY what it shows: for EVERY page ` +
|
|
267
|
-
`call postRecords and save records
|
|
267
|
+
`call postRecords and save records in table "document_entries", with "page" set to the DOCUMENT PAGE number ` +
|
|
268
|
+
`from the page's label - one record per row / table entry / line item visible on the page ` +
|
|
268
269
|
`(or one record for the page if it is prose), capturing every value you can read (OCR the text, read tables ` +
|
|
269
270
|
`cell by cell, describe any photos/diagrams). Set EVERY record's reference to exactly "src::" + the storage path above. That file record ALREADY EXISTS, so do NOT post it, and do NOT give your page records a "src::" unique_id of their own. A record with no reference back to it is an ORPHAN: re-indexing the file deletes the linked records and leaves the orphan behind forever as stale data.\n\n` +
|
|
270
271
|
`Each image is preceded by a label giving its DOCUMENT PAGE number. That label is the page's identity - ` +
|
|
@@ -317,7 +318,7 @@ export function buildIndexingWindowMessage(
|
|
|
317
318
|
where +
|
|
318
319
|
`\n${placeholder}\n\n` +
|
|
319
320
|
`DATAFY this window: call postRecords and save records for everything in it - ONE RECORD PER ROW ` +
|
|
320
|
-
`for tabular data (keyed by the column headers), or one record per section for prose. Capture every ` +
|
|
321
|
+
`for tabular data (keyed by the column headers), or one record per section for prose in table "document_entries". Capture every ` +
|
|
321
322
|
`value you can read. The file-level record ALREADY EXISTS with unique_id "src::" + the storage path above: do NOT post it (a duplicate unique_id is rejected), enrich it with updateRecords, ` +
|
|
322
323
|
`and link every row/section record to it by reference.\n\n` +
|
|
323
324
|
`If this window has PHOTOS attached as images, LOOK at each one and datafy what it actually shows. ` +
|
package/src/engine/requests.ts
CHANGED
|
@@ -5,9 +5,7 @@
|
|
|
5
5
|
* original are dependency-injection seams:
|
|
6
6
|
* - `skapi.clientSecretRequest*` -> resolveForwardRequest*() in config.ts,
|
|
7
7
|
* which dispatches through the host's
|
|
8
|
-
* `forwardRequest*` keys
|
|
9
|
-
* `clientSecretRequest*` ones a host written
|
|
10
|
-
* before the rename still injects
|
|
8
|
+
* `forwardRequest*` keys (the only ones read)
|
|
11
9
|
* - MCP endpoint URL -> chatEngineConfig().mcpBaseUrl
|
|
12
10
|
* - `poll` on each request -> pollOpt() (set per consumer; see config.ts)
|
|
13
11
|
* - Vue `reactive`/`ref` removed (bgTaskQueue/agentViewMounted are app-level
|
|
@@ -1399,6 +1397,53 @@ export const BG_INDEXING_QUEUE_SUFFIX = '-bg';
|
|
|
1399
1397
|
* fall back to the live-queue probe (fetchLiveIndexingKeys) before reading
|
|
1400
1398
|
* absence as anything.
|
|
1401
1399
|
*/
|
|
1400
|
+
/** What the MCP's /internal/index-reset answered. */
|
|
1401
|
+
export type IndexResetResult = {
|
|
1402
|
+
path: string;
|
|
1403
|
+
/** The access group the old file record had, or null when there was none. */
|
|
1404
|
+
access_group: string | number | null;
|
|
1405
|
+
removed: number;
|
|
1406
|
+
missing: number;
|
|
1407
|
+
failed: number;
|
|
1408
|
+
decorations: number;
|
|
1409
|
+
ambiguous: number;
|
|
1410
|
+
ms?: number;
|
|
1411
|
+
};
|
|
1412
|
+
|
|
1413
|
+
/**
|
|
1414
|
+
* Clear a file's index on the SERVER before a Reindex or an Overwrite (owner,
|
|
1415
|
+
* 2026-11-20): the MCP's /internal/index-reset removes the file record (and, through its
|
|
1416
|
+
* cascade, everything referencing it), the agent's decorated per-window ids and the
|
|
1417
|
+
* done::/run:: markers, in parallel, as the signed-in user. Reached through the host's
|
|
1418
|
+
* forwardRequest with "$ACCESS_TOKEN", which skapi fills in with the caller's own token,
|
|
1419
|
+
* so no client code ever holds it.
|
|
1420
|
+
*
|
|
1421
|
+
* Resolves to the server's answer, or null when the call could not be made or answered
|
|
1422
|
+
* something else (an older MCP without the route, a timeout): the caller then clears
|
|
1423
|
+
* the index itself, as it always did. Never rejects.
|
|
1424
|
+
*/
|
|
1425
|
+
export async function resetFileIndexOnServer(args: { service: string; owner?: string; storagePath: string }): Promise<IndexResetResult | null> {
|
|
1426
|
+
try {
|
|
1427
|
+
const base = String(mcpUrl() || '').replace(/\/+$/, '');
|
|
1428
|
+
if (!base || !args || !args.service || !args.storagePath) return null;
|
|
1429
|
+
const res: any = await forwardRequest({
|
|
1430
|
+
service: args.service,
|
|
1431
|
+
...(args.owner ? { owner: args.owner } : {}),
|
|
1432
|
+
url: base + '/internal/index-reset',
|
|
1433
|
+
method: 'POST',
|
|
1434
|
+
headers: { 'content-type': 'application/json', Authorization: 'Bearer $ACCESS_TOKEN' },
|
|
1435
|
+
data: { project_id: args.service, path: args.storagePath },
|
|
1436
|
+
});
|
|
1437
|
+
const body = typeof res === 'string' ? JSON.parse(res) : res;
|
|
1438
|
+
if (body && typeof body === 'object' && typeof body.removed === 'number' && body.path === args.storagePath) {
|
|
1439
|
+
return body as IndexResetResult;
|
|
1440
|
+
}
|
|
1441
|
+
return null;
|
|
1442
|
+
} catch {
|
|
1443
|
+
return null;
|
|
1444
|
+
}
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1402
1447
|
export function indexDoneUniqueId(storagePath: string): string {
|
|
1403
1448
|
return 'done::' + storagePath;
|
|
1404
1449
|
}
|
|
@@ -1510,6 +1555,15 @@ export type BgTaskEntry = {
|
|
|
1510
1555
|
* once everything finishes. Absent for work with no chat turn behind it (the dbfile
|
|
1511
1556
|
* page, an attachment-only send, a worker-adopted pass), which appends as before. */
|
|
1512
1557
|
stageId?: string;
|
|
1558
|
+
/** Settled from the 10-second queue check instead of its own poll (owner, 2026-11-20).
|
|
1559
|
+
* Set by drainBgTaskQueue on every pass when the host has csrHistoryItemLookup, and on
|
|
1560
|
+
* adoption for the worker's lanes. Polls on one queue run one at a time in skapi-js, so
|
|
1561
|
+
* a pass that finished waited behind every pass ahead of it; see
|
|
1562
|
+
* ChatSession._settleByListing. */
|
|
1563
|
+
byListing?: boolean;
|
|
1564
|
+
/** When this client first tracked the pass (ms). A pass missing from a listing taken
|
|
1565
|
+
* BEFORE that proves nothing about it. */
|
|
1566
|
+
adoptedAt?: number;
|
|
1513
1567
|
};
|
|
1514
1568
|
|
|
1515
1569
|
// Token the indexing agent appends to its final message ONLY when it has fully read and
|
|
@@ -146,6 +146,9 @@ function readArguments(note: RetrievalNote, args: any): void {
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
/** Collect { path, page } pairs out of a tool RESULT, bounded. */
|
|
149
|
+
/** A JSON string inside a tool result longer than this is not parsed for hits. */
|
|
150
|
+
const RESULT_STRING_MAX_CHARS = 2 * 1024 * 1024;
|
|
151
|
+
|
|
149
152
|
function readHits(note: RetrievalNote, result: any): void {
|
|
150
153
|
var parsed = parseJsonLoose(result);
|
|
151
154
|
if (!parsed || typeof parsed !== 'object') return;
|
|
@@ -164,6 +167,14 @@ function readHits(note: RetrievalNote, result: any): void {
|
|
|
164
167
|
if (!Object.prototype.hasOwnProperty.call(node, k)) continue;
|
|
165
168
|
var v = node[k];
|
|
166
169
|
if (v && typeof v === 'object') walk(v, depth + 1);
|
|
170
|
+
// The MCP's paginated envelope carries the tool's own result as a JSON STRING
|
|
171
|
+
// ({"message": "Response retrieved...", "content": "{\"hits\": [...]}"}), so the
|
|
172
|
+
// hits were never seen and no turn remembered its pages (found 2026-11-20).
|
|
173
|
+
else if (typeof v === 'string' && v.length > 1 && v.length <= RESULT_STRING_MAX_CHARS
|
|
174
|
+
&& (v.charAt(0) === '{' || v.charAt(0) === '[')) {
|
|
175
|
+
var inner = parseJsonLoose(v);
|
|
176
|
+
if (inner && typeof inner === 'object') walk(inner, depth + 1);
|
|
177
|
+
}
|
|
167
178
|
}
|
|
168
179
|
};
|
|
169
180
|
walk(parsed, 0);
|