bunnyquery 1.4.0 → 1.4.3

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 CHANGED
@@ -24,6 +24,9 @@ you can build your own chat UI on top of it. See
24
24
  first load and on scroll-up.
25
25
  - **Attachments** — drag-and-drop files and folders, per-file upload status
26
26
  (uploading / failed / indexed), and overflow collapsing for large batches.
27
+ Images are read with vision/OCR, Office/text/code files are extracted
28
+ server-side, and PDFs are fetched by the model — see
29
+ [Supported file types](#supported-file-types).
27
30
  - **Attachment parser plugins** — register a client-side parser so the widget
28
31
  extracts text in the browser from formats the model can't otherwise read, and
29
32
  indexes it directly. See [Attachment parser plugins](#attachment-parser-plugins).
@@ -137,12 +140,79 @@ BunnyQuery.logout();
137
140
  > instance rather than re-mounting. On a successful mount it logs its version, e.g.
138
141
  > `[bunnyquery] v1.3.5`.
139
142
 
143
+ ## Supported file types
144
+
145
+ When a user attaches a file, BunnyQuery makes its contents available to the AI
146
+ automatically — detected by extension (with a MIME-type fallback), nothing to
147
+ configure. There are three paths, plus a couple of caveats.
148
+
149
+ ### 1. Images — read directly by the model (vision + OCR)
150
+
151
+ `.jpg` · `.jpeg` · `.png` · `.gif` · `.webp`
152
+
153
+ The image is attached to the request inline, so the model both **describes the
154
+ picture** and **reads any text in it (OCR)**. Works on both Claude and OpenAI.
155
+ Only images referenced in the **most recent** message are inlined (older links
156
+ may have expired).
157
+
158
+ ### 2. Documents, data & code — extracted on the server (inlined as text)
159
+
160
+ The skapi proxy downloads the file, extracts its text **server-side**, and
161
+ inlines that text into the request — the model reads it directly, with no
162
+ fetching. This keeps indexing consistent across model providers.
163
+
164
+ **Office & e-book** (binary/zip, parsed):
165
+ `.docx` · `.xlsx` · `.pptx` · `.hwp` · `.hwpx` · `.ods` · `.odt` · `.odp` · `.epub`
166
+
167
+ **Text, data, markup & source code** (decoded as text; `.html`/`.htm` have their
168
+ tags stripped):
169
+
170
+ ```
171
+ .csv .tsv .tab .txt .text .log .md .markdown .rst .json .ndjson .jsonl .geojson
172
+ .xml .yaml .yml .toml .ini .conf .cfg .properties .env .rtf .html .htm
173
+ .js .mjs .cjs .ts .tsx .jsx .py .rb .go .rs .java .kt .c .h .cpp .cc .hpp .cs
174
+ .php .swift .sh .bash .zsh .sql .css .scss .less .vue .svelte .tex .srt .vtt
175
+ ```
176
+
177
+ Plus a **MIME fallback**: any file whose content type is text-like (`text/*`,
178
+ `application/json`, `application/xml`, `*+json`, `*+xml`, `*+yaml`, …) is decoded
179
+ even when its extension isn't in the list above.
180
+
181
+ Encoding is auto-detected — UTF-8 (BOM-aware) → CP949/EUC-KR (Korean) → Latin-1.
182
+ Extracted text is capped at **200,000 characters**; longer files are truncated
183
+ with a `...[truncated for length; original N characters]` marker.
184
+
185
+ ### 3. PDFs & other links — fetched by the model
186
+
187
+ `.pdf` (and any file that is neither an image nor server-extractable) is handed
188
+ to the model as a temporary link, which it opens with its built-in web tool:
189
+ **Claude** via `web_fetch`, **OpenAI** via `web_search` (external web access is
190
+ enabled). Both can open and read PDFs, so PDFs work on either provider.
191
+
192
+ > A provider's web tool opens document/page-style URLs such as PDFs, but not
193
+ > necessarily a bare *data-file* download (e.g. a raw `.csv`/`.tsv` link). That's
194
+ > why those data formats are extracted **server-side** (path 2 above) instead of
195
+ > being left to the model to fetch.
196
+
197
+ ### Caveats
198
+
199
+ - **Legacy / macro Office** — `.doc` `.xls` `.ppt` (legacy binary) and `.docm`
200
+ `.xlsm` `.pptm` (macro-enabled) have no reliable server-side reader. They
201
+ upload fine but are indexed from **metadata only**; re-save as
202
+ `.docx` / `.xlsx` / `.pptx` (or PDF) to capture their contents.
203
+ - **Anything else** — a format covered by none of the above is indexed from its
204
+ metadata. To support it, register your own
205
+ [Attachment parser plugin](#attachment-parser-plugins) — it runs in the browser
206
+ and feeds parsed text straight into indexing.
207
+
140
208
  ## Attachment parser plugins
141
209
 
142
- By default the chat agent reads most uploads via the model's `web_fetch` tool
143
- (text, CSV, PDF, …), and Office/OpenDocument/EPUB files are extracted on the
144
- server. For any format that can be read by **neither** (e.g. a proprietary
145
- binary format), register a **parser plugin**: it runs in the browser, turns the
210
+ By default the chat agent reads images with vision/OCR, extracts
211
+ Office/OpenDocument/EPUB and text/data/code files on the server, and lets the
212
+ model fetch PDFs with its built-in web tool (`web_fetch` on Claude, `web_search`
213
+ on OpenAI) see [Supported file types](#supported-file-types). For any format
214
+ read by **none** of these (e.g. a proprietary binary format), register a
215
+ **parser plugin**: it runs in the browser, turns the
146
216
  uploaded file into text (or an HTML string), and the widget sends that content
147
217
  **inline** for indexing — no `web_fetch`, no server extraction for that file.
148
218
 
package/bunnyquery.js CHANGED
@@ -79,34 +79,74 @@
79
79
  "odp",
80
80
  "epub"
81
81
  ]);
82
- var WEB_FETCHABLE_TEXT_EXTENSIONS = /* @__PURE__ */ new Set([
82
+ var TEXT_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
83
83
  "csv",
84
84
  "tsv",
85
85
  "tab",
86
86
  "txt",
87
87
  "text",
88
+ "log",
88
89
  "md",
89
90
  "markdown",
91
+ "rst",
90
92
  "json",
91
93
  "ndjson",
92
94
  "jsonl",
95
+ "geojson",
93
96
  "xml",
94
97
  "yaml",
95
98
  "yml",
96
- "log",
97
- // RTF is a TEXT format (not a binary zip), so web_fetch can read it and the
98
- // model decodes its control words. Pin it here so a `.rtf` reported as
99
- // `application/msword` isn't misrouted to server-side extraction (which has no
100
- // .rtf extractor → "unsupported format" note).
99
+ "toml",
100
+ "ini",
101
+ "conf",
102
+ "cfg",
103
+ "properties",
104
+ "env",
101
105
  "rtf",
106
+ "html",
102
107
  "htm",
103
- "html"
108
+ "js",
109
+ "mjs",
110
+ "cjs",
111
+ "ts",
112
+ "tsx",
113
+ "jsx",
114
+ "py",
115
+ "rb",
116
+ "go",
117
+ "rs",
118
+ "java",
119
+ "kt",
120
+ "c",
121
+ "h",
122
+ "cpp",
123
+ "cc",
124
+ "hpp",
125
+ "cs",
126
+ "php",
127
+ "swift",
128
+ "sh",
129
+ "bash",
130
+ "zsh",
131
+ "sql",
132
+ "css",
133
+ "scss",
134
+ "less",
135
+ "vue",
136
+ "svelte",
137
+ "tex",
138
+ "srt",
139
+ "vtt"
104
140
  ]);
105
- function isOfficeFile(name, mime) {
141
+ function isTextMime(m) {
142
+ return m.startsWith("text/") || m.endsWith("+json") || m.endsWith("+xml") || m.endsWith("+yaml") || m === "application/json" || m === "application/ld+json" || m === "application/xml" || m === "application/yaml" || m === "application/x-yaml" || m === "application/javascript" || m === "application/x-javascript" || m === "application/x-sh" || m === "application/x-ndjson" || m === "application/csv" || m === "application/rtf" || m === "application/sql" || m === "application/toml";
143
+ }
144
+ function isServerExtractable(name, mime) {
106
145
  const ext = (name || "").split(".").pop()?.toLowerCase() || "";
107
146
  if (OFFICE_FILE_EXTENSIONS.has(ext)) return true;
108
- if (WEB_FETCHABLE_TEXT_EXTENSIONS.has(ext)) return false;
147
+ if (TEXT_FILE_EXTENSIONS.has(ext)) return true;
109
148
  const m = (mime || "").toLowerCase();
149
+ if (isTextMime(m)) return true;
110
150
  return m.includes("officedocument") || m.includes("opendocument") || m.includes("hwp") || m.includes("epub") || m === "application/msword" || m === "application/vnd.ms-excel" || m === "application/vnd.ms-powerpoint";
111
151
  }
112
152
  var _extractPlaceholderSeq = 0;
@@ -127,10 +167,10 @@ ${lines.join("\n")}`;
127
167
  let composedForLlm = composed;
128
168
  let extractContent;
129
169
  if (attachmentUrls.length > 0) {
130
- const officeFiles = attachmentUrls.filter((u) => isOfficeFile(u.name));
131
- if (officeFiles.length > 0) {
170
+ const extractFiles = attachmentUrls.filter((u) => isServerExtractable(u.name));
171
+ if (extractFiles.length > 0) {
132
172
  const directives = [];
133
- const sections = officeFiles.map((u) => {
173
+ const sections = extractFiles.map((u) => {
134
174
  const storagePath = u.storagePath || u.name;
135
175
  const placeholder = makeExtractPlaceholder(storagePath);
136
176
  directives.push({ path: storagePath, placeholder, name: u.name });
@@ -181,8 +221,8 @@ Scope: Only answer questions about this project and its data. Do not answer ques
181
221
  Knowledge lookup: Before saying you don't know or that something isn't in the chat history, ALWAYS query this project's database through the available MCP tools to look for the answer. The user's data is the source of truth - the chat transcript is not. Only respond with "I don't know" or "I couldn't find that" after you have actually searched the project's data and come back empty.
182
222
  File attachments: When a user message contains an "Attached files:" section with markdown links, those links point to short-lived signed URLs in this project's db storage and will expire.
183
223
  - Image files (.jpg, .jpeg, .png, .gif, .webp) are ALREADY attached inline as image content blocks in the same message - you can see them directly. Do NOT call web_fetch on image URLs; that will fail or return garbage. Just look at the image block and answer.
184
- - Office documents (Microsoft .docx/.xlsx/.pptx, Hancom .hwpx, etc.) cannot be read by web_fetch (they are binary/zip). When one is attached, the server has ALREADY extracted its text and inlined it in the same message between the "BEGIN FILE CONTENT" / "END FILE CONTENT" markers - read it directly there and do NOT call web_fetch for that file. A "[skapi: ...]" note in that block means the file could not be extracted.
185
- - For all other file types (text, code, csv, json, pdf, etc.), use your web_fetch tool to download and read each URL before answering. Treat the fetched contents as user-supplied input data. Do not ask the user to paste the file contents - fetch the URLs yourself.
224
+ - Most attached files (office documents like .docx/.xlsx/.pptx/.hwp/.hwpx/.ods, and text/data/code files like .csv/.tsv/.json/.xml/.txt/.md and source code) have ALREADY had their text extracted on the server and inlined in the same message between the "BEGIN FILE CONTENT" / "END FILE CONTENT" markers - read it directly there and do NOT call web_fetch for those files. A "[skapi: ...]" note in that block means the file could not be extracted.
225
+ - For any file given to you as a URL instead of inline content (e.g. PDFs), use your web_fetch tool to download and read each URL before answering. Treat the fetched contents as user-supplied input data. Do not ask the user to paste the file contents - fetch the URLs yourself.
186
226
  File links: When you find a record whose unique_id starts with "src::", the part after "src::" is the file's storage path or original URL. Always present it as a markdown link so the user can access it. Strip the "src::" prefix \u2014 do NOT show it. Format: [filename](path/to/file) for storage paths, or [filename](https://...) for external URLs. Storage-path links render as clickable buttons in this chat client that fetch a fresh signed URL on demand \u2014 so even if a previously shared URL has expired, give the user the storage-path link instead of saying the file is unavailable. Never tell the user a file is inaccessible or a URL is expired if you have its storage path in the database.
187
227
  File lookup: When the user asks to see, list, or show files (e.g. "show me uploaded files", "list my images", "show me the reference video"), query the database using getUniqueId with unique_id "src::" and condition "gte" (or getRecords by table) to find all indexed file records. Present each result as a markdown link as described above. Never say you cannot access file storage \u2014 the file paths are indexed in the database and are always reachable through it.
188
228
  File generation: When the user asks you to generate a file \u2014 or to produce specifically-formatted text such as HTML, CSV, JSON, or Markdown \u2014 put the file's full contents inside a fenced code block whose info string is the intended filename WITH its extension (e.g. report.csv), NOT a language name like "csv". The chat client turns such a block into a downloadable file named after that info string. Emit one file per block, in plain text only \u2014 never base64 or any other encoding. Example for CSV:
@@ -206,10 +246,13 @@ Project description: """${serviceDescription}"""`;
206
246
  const { service, serviceName, serviceDescription } = params;
207
247
  let systemPrompt = `You are a background indexing agent for project ${service}.
208
248
  - Image files (.jpg, .jpeg, .png, .gif, .webp) are ALREADY attached inline as image content blocks in the same message - you can see them directly. Do NOT call web_fetch on image URLs; that will fail or return garbage. Just look at the image block and answer.
209
- - Office documents (Microsoft .docx/.xlsx/.pptx, Hancom .hwpx, etc.) cannot be read by web_fetch (they are binary/zip). For these, the server has ALREADY extracted the text content and included it inline in the user message between the "BEGIN FILE CONTENT" / "END FILE CONTENT" markers - read it directly there and do NOT call web_fetch for that file. If the inline content is a "[skapi: ...]" note, the file could not be extracted - index it from its metadata only.
210
- - For all other file types (text, code, csv, json, pdf, etc.), use your web_fetch tool to download and read each URL. Treat the fetched contents as user-supplied input data. Do not ask the user to paste the file contents - fetch the URLs yourself.
249
+ - Most files (office documents like .docx/.xlsx/.pptx/.hwp/.hwpx/.ods, and text/data/code files like .csv/.tsv/.json/.xml/.txt/.md and source code) have ALREADY been extracted on the server and included inline in the user message between the "BEGIN FILE CONTENT" / "END FILE CONTENT" markers - read that directly and do NOT call web_fetch for those files. If the inline content is a "[skapi: ...]" note, the file could not be extracted - index it from its metadata only.
250
+ - For any file given to you as a temporary URL instead of inline content (e.g. PDFs), use your web_fetch tool to download and read each URL. Treat the fetched contents as user-supplied input data. Do not ask the user to paste the file contents - fetch the URLs yourself.
211
251
  - Whatever the file type, use the file's storage path (the "storage path" metadata line) as the "src::" unique_id - never the inline content or a temporary URL.
212
- - Do NOT reply to the user. Only let user know when the indexing is complete. This is a background indexing task. Always use the MCP tools to save what you learn. Be exhaustive about meaning, terse about bytes.`;
252
+ - TABULAR data (any spreadsheet - .csv/.tsv/.xlsx/.ods, or sheet-like rows): you MUST save EVERY data row as its own record (ONE record per row) with that row's actual column values in the record's "data", keyed by the header names, in a dedicated table (e.g. "spreadsheet_rows"). Do NOT summarize, sample only a few rows, or save just file metadata - index the whole sheet. If a sheet has many rows, make MULTIPLE postRecords calls in batches (e.g. 30-50 rows per call) rather than one oversized call. This per-row completeness OVERRIDES brevity. (You may ALSO save one file-level summary record, but the per-row records are mandatory.)
253
+ - EPUB / e-books / long-form books (.epub or any book-length prose, provided inline in reading order with chapter headings preserved): you MUST save ONE record per CHAPTER (or, when chapters are unclear, per major section/topic) in a dedicated table (e.g. "book_chapters") - never collapse the whole book into a single record. Each chapter record's "data" must capture the chapter title plus its order/number AND a substantive summary of that chapter's content (key events, arguments, characters, places, concepts, terms, notable quotes). Apply AS MANY relevant tags as possible to EVERY chapter record (characters, locations, themes, topics, key concepts, key terms, dates, named entities) so the book is easy to SEARCH and cross-reference later - this is the whole point. ALSO save one book-level record (title, author, language, overall summary, chapter list / table of contents, genre/subjects) and link each chapter record to it via reference. This per-chapter completeness OVERRIDES brevity; human-readable summaries only, never raw/binary bytes.
254
+ - This is a ONE-SHOT background indexing task: do ALL the MCP saving FIRST, never reply mid-task, and never ask the user questions or invite back-and-forth. Always use the MCP tools to save what you learn - be exhaustive about meaning (and, for tabular data, about every row). Never store raw or binary bytes (base64, blobs); describe them in human-readable text instead.
255
+ - Only AFTER every save is done, send exactly ONE final message summarizing what you indexed - never just "Indexing complete", and never a raw/base64/binary value or a large pasted dump. Keep it to a few factual sentences or a short markdown bullet list covering: the file name, its content type, each table you wrote to with its record/row count and the key columns/fields or topics captured, and anything that could not be extracted. Follow this shape - Indexed <file name> (<content type>): saved <N> records to <table(s)> capturing <key columns/fields or topics>; could not extract: <gaps, or none>.`;
213
256
  if (serviceDescription) {
214
257
  systemPrompt += `
215
258
  Project name: "${serviceName ?? ""}"
@@ -732,9 +775,9 @@ ${options.inlineContentPlaceholder}
732
775
  }
733
776
  async function notifyAgentSaveAttachment(info) {
734
777
  const { platform, service, owner, attachment, parsedContent } = info;
735
- const office = !parsedContent && isOfficeFile(attachment.name, attachment.mime);
736
- const placeholder = office ? makeExtractPlaceholder(attachment.storagePath) : void 0;
737
- const extractContent = office && placeholder ? [{ path: attachment.storagePath, placeholder, name: attachment.name, mime: attachment.mime }] : void 0;
778
+ const serverExtract = !parsedContent && isServerExtractable(attachment.name, attachment.mime);
779
+ const placeholder = serverExtract ? makeExtractPlaceholder(attachment.storagePath) : void 0;
780
+ const extractContent = serverExtract && placeholder ? [{ path: attachment.storagePath, placeholder, name: attachment.name, mime: attachment.mime }] : void 0;
738
781
  const skapiExtract = extractContent && extractContent.length ? { _skapi_extract: extractContent } : {};
739
782
  const userMessage = buildIndexingUserMessage(
740
783
  attachment,
@@ -2041,7 +2084,7 @@ ${options.inlineContentPlaceholder}
2041
2084
  (function() {
2042
2085
  var MCP_PROD = "https://mcp.broadwayinc.computer";
2043
2086
  var MCP_DEV = "https://mcp-dev.broadwayinc.computer";
2044
- var BQ_VERSION = "1.4.0" ;
2087
+ var BQ_VERSION = "1.4.3" ;
2045
2088
  var ATTACHMENT_URL_EXPIRES_SECONDS = 600;
2046
2089
  var GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/v2/auth";
2047
2090
  var GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
@@ -2449,6 +2492,43 @@ ${options.inlineContentPlaceholder}
2449
2492
  var mismatched = !!tok && !!currentSub && !!tokenSub && tokenSub !== currentSub;
2450
2493
  return expired || mismatched;
2451
2494
  }
2495
+ function refreshMcpToken() {
2496
+ var client = getStoredMcpClient();
2497
+ var current = getStoredMcpToken();
2498
+ if (!client || !current || !current.refresh_token) return Promise.resolve(null);
2499
+ var body = new URLSearchParams({
2500
+ grant_type: "refresh_token",
2501
+ refresh_token: current.refresh_token,
2502
+ client_id: client.client_id
2503
+ });
2504
+ var headers = { "Content-Type": "application/x-www-form-urlencoded" };
2505
+ if (client.client_secret) {
2506
+ headers.Authorization = basicAuthHeader(client.client_id, client.client_secret);
2507
+ }
2508
+ return fetch(mcpBaseUrl() + "/oauth/token", {
2509
+ method: "POST",
2510
+ headers,
2511
+ body: body.toString()
2512
+ }).then(function(res) {
2513
+ return res.ok ? res.json() : null;
2514
+ }).then(function(json) {
2515
+ if (!json || !json.access_token) return null;
2516
+ var token = Object.assign({}, json, {
2517
+ refresh_token: json.refresh_token || current.refresh_token,
2518
+ expires_at: typeof json.expires_in === "number" ? Date.now() + json.expires_in * 1e3 : void 0
2519
+ });
2520
+ lsSet(skey(SK.mcpToken), JSON.stringify(token));
2521
+ return token;
2522
+ }).catch(function() {
2523
+ return null;
2524
+ });
2525
+ }
2526
+ function ensureMcpGrantFresh() {
2527
+ if (!S.user || !mcpGrantNeedsRefresh(S.user)) return Promise.resolve(true);
2528
+ return refreshMcpToken().then(function(tok) {
2529
+ return !!(tok && !mcpGrantNeedsRefresh(S.user));
2530
+ });
2531
+ }
2452
2532
  function googleEnabled() {
2453
2533
  return !!S.opts.googleClientId;
2454
2534
  }
@@ -3716,6 +3796,8 @@ ${options.inlineContentPlaceholder}
3716
3796
  }
3717
3797
  function refreshSkapiSession() {
3718
3798
  return S.skapi.getProfile({ refreshToken: true }).then(function() {
3799
+ return ensureMcpGrantFresh();
3800
+ }).then(function() {
3719
3801
  return true;
3720
3802
  }).catch(function() {
3721
3803
  return false;
@@ -5056,9 +5138,12 @@ ${options.inlineContentPlaceholder}
5056
5138
  return;
5057
5139
  }
5058
5140
  if (mcpGrantNeedsRefresh(user)) {
5059
- return beginMcpOAuthOnLogin("chat").catch(function(err) {
5060
- console.error("[bunnyquery] MCP refresh failed", err);
5061
- return enterAfterLogin();
5141
+ return refreshMcpToken().then(function(tok) {
5142
+ if (tok && !mcpGrantNeedsRefresh(user)) return enterAfterLogin();
5143
+ return beginMcpOAuthOnLogin("chat").catch(function(err) {
5144
+ console.error("[bunnyquery] MCP refresh failed", err);
5145
+ return enterAfterLogin();
5146
+ });
5062
5147
  });
5063
5148
  }
5064
5149
  return enterAfterLogin();
@@ -5115,6 +5200,12 @@ ${options.inlineContentPlaceholder}
5115
5200
  scheduleAttachmentOverflowRecompute();
5116
5201
  });
5117
5202
  }
5203
+ if (!S._visBound && typeof document !== "undefined" && document.addEventListener) {
5204
+ S._visBound = true;
5205
+ document.addEventListener("visibilitychange", function() {
5206
+ if (document.visibilityState === "visible" && S.user) ensureMcpGrantFresh();
5207
+ });
5208
+ }
5118
5209
  boot();
5119
5210
  return PUBLIC;
5120
5211
  }
package/dist/engine.cjs CHANGED
@@ -84,36 +84,77 @@ var OFFICE_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
84
84
  "odp",
85
85
  "epub"
86
86
  ]);
87
- var WEB_FETCHABLE_TEXT_EXTENSIONS = /* @__PURE__ */ new Set([
87
+ var TEXT_FILE_EXTENSIONS = /* @__PURE__ */ new Set([
88
88
  "csv",
89
89
  "tsv",
90
90
  "tab",
91
91
  "txt",
92
92
  "text",
93
+ "log",
93
94
  "md",
94
95
  "markdown",
96
+ "rst",
95
97
  "json",
96
98
  "ndjson",
97
99
  "jsonl",
100
+ "geojson",
98
101
  "xml",
99
102
  "yaml",
100
103
  "yml",
101
- "log",
102
- // RTF is a TEXT format (not a binary zip), so web_fetch can read it and the
103
- // model decodes its control words. Pin it here so a `.rtf` reported as
104
- // `application/msword` isn't misrouted to server-side extraction (which has no
105
- // .rtf extractor → "unsupported format" note).
104
+ "toml",
105
+ "ini",
106
+ "conf",
107
+ "cfg",
108
+ "properties",
109
+ "env",
106
110
  "rtf",
111
+ "html",
107
112
  "htm",
108
- "html"
113
+ "js",
114
+ "mjs",
115
+ "cjs",
116
+ "ts",
117
+ "tsx",
118
+ "jsx",
119
+ "py",
120
+ "rb",
121
+ "go",
122
+ "rs",
123
+ "java",
124
+ "kt",
125
+ "c",
126
+ "h",
127
+ "cpp",
128
+ "cc",
129
+ "hpp",
130
+ "cs",
131
+ "php",
132
+ "swift",
133
+ "sh",
134
+ "bash",
135
+ "zsh",
136
+ "sql",
137
+ "css",
138
+ "scss",
139
+ "less",
140
+ "vue",
141
+ "svelte",
142
+ "tex",
143
+ "srt",
144
+ "vtt"
109
145
  ]);
110
- function isOfficeFile(name, mime) {
146
+ function isTextMime(m) {
147
+ return m.startsWith("text/") || m.endsWith("+json") || m.endsWith("+xml") || m.endsWith("+yaml") || m === "application/json" || m === "application/ld+json" || m === "application/xml" || m === "application/yaml" || m === "application/x-yaml" || m === "application/javascript" || m === "application/x-javascript" || m === "application/x-sh" || m === "application/x-ndjson" || m === "application/csv" || m === "application/rtf" || m === "application/sql" || m === "application/toml";
148
+ }
149
+ function isServerExtractable(name, mime) {
111
150
  const ext = (name || "").split(".").pop()?.toLowerCase() || "";
112
151
  if (OFFICE_FILE_EXTENSIONS.has(ext)) return true;
113
- if (WEB_FETCHABLE_TEXT_EXTENSIONS.has(ext)) return false;
152
+ if (TEXT_FILE_EXTENSIONS.has(ext)) return true;
114
153
  const m = (mime || "").toLowerCase();
154
+ if (isTextMime(m)) return true;
115
155
  return m.includes("officedocument") || m.includes("opendocument") || m.includes("hwp") || m.includes("epub") || m === "application/msword" || m === "application/vnd.ms-excel" || m === "application/vnd.ms-powerpoint";
116
156
  }
157
+ var isOfficeFile = isServerExtractable;
117
158
  var _extractPlaceholderSeq = 0;
118
159
  function makeExtractPlaceholder(seed) {
119
160
  _extractPlaceholderSeq += 1;
@@ -132,10 +173,10 @@ ${lines.join("\n")}`;
132
173
  let composedForLlm = composed;
133
174
  let extractContent;
134
175
  if (attachmentUrls.length > 0) {
135
- const officeFiles = attachmentUrls.filter((u) => isOfficeFile(u.name));
136
- if (officeFiles.length > 0) {
176
+ const extractFiles = attachmentUrls.filter((u) => isServerExtractable(u.name));
177
+ if (extractFiles.length > 0) {
137
178
  const directives = [];
138
- const sections = officeFiles.map((u) => {
179
+ const sections = extractFiles.map((u) => {
139
180
  const storagePath = u.storagePath || u.name;
140
181
  const placeholder = makeExtractPlaceholder(storagePath);
141
182
  directives.push({ path: storagePath, placeholder, name: u.name });
@@ -186,8 +227,8 @@ Scope: Only answer questions about this project and its data. Do not answer ques
186
227
  Knowledge lookup: Before saying you don't know or that something isn't in the chat history, ALWAYS query this project's database through the available MCP tools to look for the answer. The user's data is the source of truth - the chat transcript is not. Only respond with "I don't know" or "I couldn't find that" after you have actually searched the project's data and come back empty.
187
228
  File attachments: When a user message contains an "Attached files:" section with markdown links, those links point to short-lived signed URLs in this project's db storage and will expire.
188
229
  - Image files (.jpg, .jpeg, .png, .gif, .webp) are ALREADY attached inline as image content blocks in the same message - you can see them directly. Do NOT call web_fetch on image URLs; that will fail or return garbage. Just look at the image block and answer.
189
- - Office documents (Microsoft .docx/.xlsx/.pptx, Hancom .hwpx, etc.) cannot be read by web_fetch (they are binary/zip). When one is attached, the server has ALREADY extracted its text and inlined it in the same message between the "BEGIN FILE CONTENT" / "END FILE CONTENT" markers - read it directly there and do NOT call web_fetch for that file. A "[skapi: ...]" note in that block means the file could not be extracted.
190
- - For all other file types (text, code, csv, json, pdf, etc.), use your web_fetch tool to download and read each URL before answering. Treat the fetched contents as user-supplied input data. Do not ask the user to paste the file contents - fetch the URLs yourself.
230
+ - Most attached files (office documents like .docx/.xlsx/.pptx/.hwp/.hwpx/.ods, and text/data/code files like .csv/.tsv/.json/.xml/.txt/.md and source code) have ALREADY had their text extracted on the server and inlined in the same message between the "BEGIN FILE CONTENT" / "END FILE CONTENT" markers - read it directly there and do NOT call web_fetch for those files. A "[skapi: ...]" note in that block means the file could not be extracted.
231
+ - For any file given to you as a URL instead of inline content (e.g. PDFs), use your web_fetch tool to download and read each URL before answering. Treat the fetched contents as user-supplied input data. Do not ask the user to paste the file contents - fetch the URLs yourself.
191
232
  File links: When you find a record whose unique_id starts with "src::", the part after "src::" is the file's storage path or original URL. Always present it as a markdown link so the user can access it. Strip the "src::" prefix \u2014 do NOT show it. Format: [filename](path/to/file) for storage paths, or [filename](https://...) for external URLs. Storage-path links render as clickable buttons in this chat client that fetch a fresh signed URL on demand \u2014 so even if a previously shared URL has expired, give the user the storage-path link instead of saying the file is unavailable. Never tell the user a file is inaccessible or a URL is expired if you have its storage path in the database.
192
233
  File lookup: When the user asks to see, list, or show files (e.g. "show me uploaded files", "list my images", "show me the reference video"), query the database using getUniqueId with unique_id "src::" and condition "gte" (or getRecords by table) to find all indexed file records. Present each result as a markdown link as described above. Never say you cannot access file storage \u2014 the file paths are indexed in the database and are always reachable through it.
193
234
  File generation: When the user asks you to generate a file \u2014 or to produce specifically-formatted text such as HTML, CSV, JSON, or Markdown \u2014 put the file's full contents inside a fenced code block whose info string is the intended filename WITH its extension (e.g. report.csv), NOT a language name like "csv". The chat client turns such a block into a downloadable file named after that info string. Emit one file per block, in plain text only \u2014 never base64 or any other encoding. Example for CSV:
@@ -211,10 +252,13 @@ function buildIndexingSystemPrompt(params) {
211
252
  const { service, serviceName, serviceDescription } = params;
212
253
  let systemPrompt = `You are a background indexing agent for project ${service}.
213
254
  - Image files (.jpg, .jpeg, .png, .gif, .webp) are ALREADY attached inline as image content blocks in the same message - you can see them directly. Do NOT call web_fetch on image URLs; that will fail or return garbage. Just look at the image block and answer.
214
- - Office documents (Microsoft .docx/.xlsx/.pptx, Hancom .hwpx, etc.) cannot be read by web_fetch (they are binary/zip). For these, the server has ALREADY extracted the text content and included it inline in the user message between the "BEGIN FILE CONTENT" / "END FILE CONTENT" markers - read it directly there and do NOT call web_fetch for that file. If the inline content is a "[skapi: ...]" note, the file could not be extracted - index it from its metadata only.
215
- - For all other file types (text, code, csv, json, pdf, etc.), use your web_fetch tool to download and read each URL. Treat the fetched contents as user-supplied input data. Do not ask the user to paste the file contents - fetch the URLs yourself.
255
+ - Most files (office documents like .docx/.xlsx/.pptx/.hwp/.hwpx/.ods, and text/data/code files like .csv/.tsv/.json/.xml/.txt/.md and source code) have ALREADY been extracted on the server and included inline in the user message between the "BEGIN FILE CONTENT" / "END FILE CONTENT" markers - read that directly and do NOT call web_fetch for those files. If the inline content is a "[skapi: ...]" note, the file could not be extracted - index it from its metadata only.
256
+ - For any file given to you as a temporary URL instead of inline content (e.g. PDFs), use your web_fetch tool to download and read each URL. Treat the fetched contents as user-supplied input data. Do not ask the user to paste the file contents - fetch the URLs yourself.
216
257
  - Whatever the file type, use the file's storage path (the "storage path" metadata line) as the "src::" unique_id - never the inline content or a temporary URL.
217
- - Do NOT reply to the user. Only let user know when the indexing is complete. This is a background indexing task. Always use the MCP tools to save what you learn. Be exhaustive about meaning, terse about bytes.`;
258
+ - TABULAR data (any spreadsheet - .csv/.tsv/.xlsx/.ods, or sheet-like rows): you MUST save EVERY data row as its own record (ONE record per row) with that row's actual column values in the record's "data", keyed by the header names, in a dedicated table (e.g. "spreadsheet_rows"). Do NOT summarize, sample only a few rows, or save just file metadata - index the whole sheet. If a sheet has many rows, make MULTIPLE postRecords calls in batches (e.g. 30-50 rows per call) rather than one oversized call. This per-row completeness OVERRIDES brevity. (You may ALSO save one file-level summary record, but the per-row records are mandatory.)
259
+ - EPUB / e-books / long-form books (.epub or any book-length prose, provided inline in reading order with chapter headings preserved): you MUST save ONE record per CHAPTER (or, when chapters are unclear, per major section/topic) in a dedicated table (e.g. "book_chapters") - never collapse the whole book into a single record. Each chapter record's "data" must capture the chapter title plus its order/number AND a substantive summary of that chapter's content (key events, arguments, characters, places, concepts, terms, notable quotes). Apply AS MANY relevant tags as possible to EVERY chapter record (characters, locations, themes, topics, key concepts, key terms, dates, named entities) so the book is easy to SEARCH and cross-reference later - this is the whole point. ALSO save one book-level record (title, author, language, overall summary, chapter list / table of contents, genre/subjects) and link each chapter record to it via reference. This per-chapter completeness OVERRIDES brevity; human-readable summaries only, never raw/binary bytes.
260
+ - This is a ONE-SHOT background indexing task: do ALL the MCP saving FIRST, never reply mid-task, and never ask the user questions or invite back-and-forth. Always use the MCP tools to save what you learn - be exhaustive about meaning (and, for tabular data, about every row). Never store raw or binary bytes (base64, blobs); describe them in human-readable text instead.
261
+ - Only AFTER every save is done, send exactly ONE final message summarizing what you indexed - never just "Indexing complete", and never a raw/base64/binary value or a large pasted dump. Keep it to a few factual sentences or a short markdown bullet list covering: the file name, its content type, each table you wrote to with its record/row count and the key columns/fields or topics captured, and anything that could not be extracted. Follow this shape - Indexed <file name> (<content type>): saved <N> records to <table(s)> capturing <key columns/fields or topics>; could not extract: <gaps, or none>.`;
218
262
  if (serviceDescription) {
219
263
  systemPrompt += `
220
264
  Project name: "${serviceName ?? ""}"
@@ -740,9 +784,9 @@ async function callOpenAIWithPublicMcp(prompt, service, owner, messages, system,
740
784
  }
741
785
  async function notifyAgentSaveAttachment(info) {
742
786
  const { platform, service, owner, attachment, parsedContent } = info;
743
- const office = !parsedContent && isOfficeFile(attachment.name, attachment.mime);
744
- const placeholder = office ? makeExtractPlaceholder(attachment.storagePath) : void 0;
745
- const extractContent = office && placeholder ? [{ path: attachment.storagePath, placeholder, name: attachment.name, mime: attachment.mime }] : void 0;
787
+ const serverExtract = !parsedContent && isServerExtractable(attachment.name, attachment.mime);
788
+ const placeholder = serverExtract ? makeExtractPlaceholder(attachment.storagePath) : void 0;
789
+ const extractContent = serverExtract && placeholder ? [{ path: attachment.storagePath, placeholder, name: attachment.name, mime: attachment.mime }] : void 0;
746
790
  const skapiExtract = extractContent && extractContent.length ? { _skapi_extract: extractContent } : {};
747
791
  const userMessage = buildIndexingUserMessage(
748
792
  attachment,
@@ -2120,6 +2164,7 @@ exports.isAuthExpiredError = isAuthExpiredError;
2120
2164
  exports.isErrorResponseBody = isErrorResponseBody;
2121
2165
  exports.isNonRetryableRequestError = isNonRetryableRequestError;
2122
2166
  exports.isOfficeFile = isOfficeFile;
2167
+ exports.isServerExtractable = isServerExtractable;
2123
2168
  exports.listClaudeModels = listClaudeModels;
2124
2169
  exports.listOpenAIModels = listOpenAIModels;
2125
2170
  exports.makeExtractPlaceholder = makeExtractPlaceholder;