bunnyquery 1.2.2 → 1.3.0

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.
@@ -0,0 +1,62 @@
1
+ /**
2
+ * BASE PROMPT — Background file-indexing agent (user message)
3
+ * ============================================================================
4
+ * USER-role message paired with the indexing system prompt. Sent by
5
+ * notifyAgentSaveAttachment() each time a file is uploaded or re-indexed.
6
+ *
7
+ * NOTE: the leading line "A new file has just been uploaded. Index it now." and
8
+ * the "- name: ..." line are also what the chat client parses to build the
9
+ * "Indexing: <name>" history bubble — keep those fields on their own lines.
10
+ */
11
+
12
+ export type IndexingAttachmentInfo = {
13
+ /** Original file name. */
14
+ name: string;
15
+ /** Storage path within the project's db storage. */
16
+ storagePath: string;
17
+ /** MIME type, if detected. Omitted from the message when unknown. */
18
+ mime?: string;
19
+ /** File size in bytes, if known. Omitted from the message when unknown. */
20
+ size?: number;
21
+ /** Temporary signed URL the agent/MCP fetches to read the file contents. */
22
+ url: string;
23
+ };
24
+
25
+ export type BuildIndexingUserMessageOptions = {
26
+ /**
27
+ * For office files (.docx/.xlsx/.pptx) the model can't read the binary via
28
+ * web_fetch, so the proxy worker extracts the text server-side and replaces
29
+ * this exact token with it. When provided, the message embeds the token (and
30
+ * drops the temporary-URL line — there is nothing for the model to fetch).
31
+ */
32
+ inlineContentPlaceholder?: string;
33
+ };
34
+
35
+ export function buildIndexingUserMessage(
36
+ attachment: IndexingAttachmentInfo,
37
+ options?: BuildIndexingUserMessageOptions,
38
+ ): string {
39
+ const head =
40
+ `A new file has just been uploaded. Index it now.\n\n` +
41
+ `File metadata:\n` +
42
+ `- name: ${attachment.name}\n` +
43
+ `- storage path: ${attachment.storagePath}\n` +
44
+ (attachment.mime ? `- mime type: ${attachment.mime}\n` : '') +
45
+ (typeof attachment.size === 'number' ? `- size (bytes): ${attachment.size}\n` : '');
46
+
47
+ if (options?.inlineContentPlaceholder) {
48
+ // Office file: text was extracted on the server and is inlined below
49
+ // between the markers. Do NOT fetch any URL for this file.
50
+ return (
51
+ head +
52
+ `\nThe file's text content was extracted on the server and is provided inline below. ` +
53
+ `Read it directly — do NOT fetch any URL for this file. ` +
54
+ `Use the storage path above (not this content) for the "src::" unique_id.\n\n` +
55
+ `----- BEGIN FILE CONTENT -----\n` +
56
+ `${options.inlineContentPlaceholder}\n` +
57
+ `----- END FILE CONTENT -----`
58
+ );
59
+ }
60
+
61
+ return head + `- temporary URL (fetch this to read the file contents): ${attachment.url}`;
62
+ }