bunnyquery 1.3.0 → 1.3.4

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/dist/engine.d.mts CHANGED
@@ -63,6 +63,27 @@ declare function composeUserMessage(text: string, attachmentUrls: Array<{
63
63
  storagePath?: string;
64
64
  }>): ComposedUserMessage;
65
65
 
66
+ /**
67
+ * Attachment helpers shared by every consumer's view layer.
68
+ *
69
+ * The upload ORCHESTRATION is per-consumer (agent.vue does admin storage
70
+ * accounting; the widget uses get-signed-url), but the failure-reporting shape
71
+ * is identical, so it lives here. When an upload or its indexing request fails,
72
+ * the orchestrator records the original `error.code` / `error.message` on the
73
+ * attachment (`att.errorCode` / `att.errorDetail`); this groups those failed
74
+ * attachments by (code, description) so a single report dialog can list each
75
+ * distinct error once with all the files it affected.
76
+ */
77
+ interface AttachmentFailureGroup {
78
+ /** The failing `error.code` (empty string when the error carried none). */
79
+ code: string;
80
+ /** The failing `error.message` / human description. */
81
+ message: string;
82
+ /** Display names of the attachments that hit this exact (code, message). */
83
+ files: string[];
84
+ }
85
+ declare function groupAttachmentFailures(attachments: any[]): AttachmentFailureGroup[];
86
+
66
87
  /**
67
88
  * BASE PROMPT — Chat assistant
68
89
  * ============================================================================
@@ -141,6 +162,7 @@ declare function buildIndexingUserMessage(attachment: IndexingAttachmentInfo, op
141
162
  */
142
163
  declare function getErrorMessage(input: any): string;
143
164
  declare function isErrorResponseBody(response: any): boolean;
165
+ declare function isNonRetryableRequestError(input: any): boolean;
144
166
  declare function isAuthExpiredError(input: any): boolean;
145
167
 
146
168
  declare var CONTEXT_WINDOW_DEFAULT: Record<string, number>;
@@ -472,4 +494,4 @@ declare class ChatSession {
472
494
  bumpGate(): void;
473
495
  }
474
496
 
475
- export { type AttachmentSaveInfo, BG_INDEXING_QUEUE_SUFFIX, type BgTaskEntry, type BoundedChatOptions, type BuildIndexingUserMessageOptions, CLAUDE_PER_REQUEST_INPUT_CAP, CONTEXT_WINDOW_BY_MODEL, CONTEXT_WINDOW_DEFAULT, type CallClaudeWithMcpParams, type ChatEngineConfig, type ChatHost, type ChatIdentity, type ChatMessage, ChatSession, type ChatState, type ChatSystemPromptParams, type ClaudeMcpServerRequest, type ClaudeMcpToolConfig, type ClaudeMessage, type ClaudeRole, type ComposedUserMessage, DEFAULT_CLAUDE_MODEL, DEFAULT_OPENAI_MODEL, EXPIRED_ATTACHMENT_URL_HOST, EXPIRED_ATTACHMENT_URL_ORIGIN, type ExtractDirective, HISTORY_TOKEN_BUDGET, type IndexingAttachmentInfo, type IndexingSystemPromptParams, LINK_LABEL_MAX_DISPLAY_CHARS, MAX_HISTORY_MESSAGES, MCP_NAME, MIN_INPUT_TOKEN_BUDGET, type MapHistoryOptions, OUTPUT_TOKEN_RESERVE, type OpenAIMessage, POLL_INTERVAL, TOOL_AND_RESPONSE_BUFFER, buildBoundedChatMessages, buildChatSystemPrompt, buildDisplayExpiredAttachmentHref, buildIndexingSystemPrompt, buildIndexingUserMessage, callClaudeWithMcp, callClaudeWithPublicMcp, callOpenAIWithPublicMcp, chatEngineConfig, composeUserMessage, configureChatEngine, createInlineLinkRegex, encodePathSegments, estimateMessageTokens, estimateTextTokens, extractClaudeText, extractLastUserTextFromRequest, extractOpenAIText, extractRemotePathFromAttachmentHref, filterListByClearHorizon, getChatHistory, getContextWindow, getErrorMessage, getExpiredAttachmentVisiblePath, isAuthExpiredError, isErrorResponseBody, isOfficeFile, listClaudeModels, listOpenAIModels, makeExtractPlaceholder, mapHistoryListToMessages, normalizeAttachmentPathCandidate, normalizeTextContent, notifyAgentSaveAttachment, safeDecodeURIComponent, sanitizeAttachmentLinksForHistory, stripFileBlocksFromHistory, transformContentWithImages, transformContentWithOpenAIImages, truncateLabelForDisplay };
497
+ export { type AttachmentFailureGroup, type AttachmentSaveInfo, BG_INDEXING_QUEUE_SUFFIX, type BgTaskEntry, type BoundedChatOptions, type BuildIndexingUserMessageOptions, CLAUDE_PER_REQUEST_INPUT_CAP, CONTEXT_WINDOW_BY_MODEL, CONTEXT_WINDOW_DEFAULT, type CallClaudeWithMcpParams, type ChatEngineConfig, type ChatHost, type ChatIdentity, type ChatMessage, ChatSession, type ChatState, type ChatSystemPromptParams, type ClaudeMcpServerRequest, type ClaudeMcpToolConfig, type ClaudeMessage, type ClaudeRole, type ComposedUserMessage, DEFAULT_CLAUDE_MODEL, DEFAULT_OPENAI_MODEL, EXPIRED_ATTACHMENT_URL_HOST, EXPIRED_ATTACHMENT_URL_ORIGIN, type ExtractDirective, HISTORY_TOKEN_BUDGET, type IndexingAttachmentInfo, type IndexingSystemPromptParams, LINK_LABEL_MAX_DISPLAY_CHARS, MAX_HISTORY_MESSAGES, MCP_NAME, MIN_INPUT_TOKEN_BUDGET, type MapHistoryOptions, OUTPUT_TOKEN_RESERVE, type OpenAIMessage, POLL_INTERVAL, TOOL_AND_RESPONSE_BUFFER, buildBoundedChatMessages, buildChatSystemPrompt, buildDisplayExpiredAttachmentHref, buildIndexingSystemPrompt, buildIndexingUserMessage, callClaudeWithMcp, callClaudeWithPublicMcp, callOpenAIWithPublicMcp, chatEngineConfig, composeUserMessage, configureChatEngine, createInlineLinkRegex, encodePathSegments, estimateMessageTokens, estimateTextTokens, extractClaudeText, extractLastUserTextFromRequest, extractOpenAIText, extractRemotePathFromAttachmentHref, filterListByClearHorizon, getChatHistory, getContextWindow, getErrorMessage, getExpiredAttachmentVisiblePath, groupAttachmentFailures, isAuthExpiredError, isErrorResponseBody, isNonRetryableRequestError, isOfficeFile, listClaudeModels, listOpenAIModels, makeExtractPlaceholder, mapHistoryListToMessages, normalizeAttachmentPathCandidate, normalizeTextContent, notifyAgentSaveAttachment, safeDecodeURIComponent, sanitizeAttachmentLinksForHistory, stripFileBlocksFromHistory, transformContentWithImages, transformContentWithOpenAIImages, truncateLabelForDisplay };
package/dist/engine.d.ts CHANGED
@@ -63,6 +63,27 @@ declare function composeUserMessage(text: string, attachmentUrls: Array<{
63
63
  storagePath?: string;
64
64
  }>): ComposedUserMessage;
65
65
 
66
+ /**
67
+ * Attachment helpers shared by every consumer's view layer.
68
+ *
69
+ * The upload ORCHESTRATION is per-consumer (agent.vue does admin storage
70
+ * accounting; the widget uses get-signed-url), but the failure-reporting shape
71
+ * is identical, so it lives here. When an upload or its indexing request fails,
72
+ * the orchestrator records the original `error.code` / `error.message` on the
73
+ * attachment (`att.errorCode` / `att.errorDetail`); this groups those failed
74
+ * attachments by (code, description) so a single report dialog can list each
75
+ * distinct error once with all the files it affected.
76
+ */
77
+ interface AttachmentFailureGroup {
78
+ /** The failing `error.code` (empty string when the error carried none). */
79
+ code: string;
80
+ /** The failing `error.message` / human description. */
81
+ message: string;
82
+ /** Display names of the attachments that hit this exact (code, message). */
83
+ files: string[];
84
+ }
85
+ declare function groupAttachmentFailures(attachments: any[]): AttachmentFailureGroup[];
86
+
66
87
  /**
67
88
  * BASE PROMPT — Chat assistant
68
89
  * ============================================================================
@@ -141,6 +162,7 @@ declare function buildIndexingUserMessage(attachment: IndexingAttachmentInfo, op
141
162
  */
142
163
  declare function getErrorMessage(input: any): string;
143
164
  declare function isErrorResponseBody(response: any): boolean;
165
+ declare function isNonRetryableRequestError(input: any): boolean;
144
166
  declare function isAuthExpiredError(input: any): boolean;
145
167
 
146
168
  declare var CONTEXT_WINDOW_DEFAULT: Record<string, number>;
@@ -472,4 +494,4 @@ declare class ChatSession {
472
494
  bumpGate(): void;
473
495
  }
474
496
 
475
- export { type AttachmentSaveInfo, BG_INDEXING_QUEUE_SUFFIX, type BgTaskEntry, type BoundedChatOptions, type BuildIndexingUserMessageOptions, CLAUDE_PER_REQUEST_INPUT_CAP, CONTEXT_WINDOW_BY_MODEL, CONTEXT_WINDOW_DEFAULT, type CallClaudeWithMcpParams, type ChatEngineConfig, type ChatHost, type ChatIdentity, type ChatMessage, ChatSession, type ChatState, type ChatSystemPromptParams, type ClaudeMcpServerRequest, type ClaudeMcpToolConfig, type ClaudeMessage, type ClaudeRole, type ComposedUserMessage, DEFAULT_CLAUDE_MODEL, DEFAULT_OPENAI_MODEL, EXPIRED_ATTACHMENT_URL_HOST, EXPIRED_ATTACHMENT_URL_ORIGIN, type ExtractDirective, HISTORY_TOKEN_BUDGET, type IndexingAttachmentInfo, type IndexingSystemPromptParams, LINK_LABEL_MAX_DISPLAY_CHARS, MAX_HISTORY_MESSAGES, MCP_NAME, MIN_INPUT_TOKEN_BUDGET, type MapHistoryOptions, OUTPUT_TOKEN_RESERVE, type OpenAIMessage, POLL_INTERVAL, TOOL_AND_RESPONSE_BUFFER, buildBoundedChatMessages, buildChatSystemPrompt, buildDisplayExpiredAttachmentHref, buildIndexingSystemPrompt, buildIndexingUserMessage, callClaudeWithMcp, callClaudeWithPublicMcp, callOpenAIWithPublicMcp, chatEngineConfig, composeUserMessage, configureChatEngine, createInlineLinkRegex, encodePathSegments, estimateMessageTokens, estimateTextTokens, extractClaudeText, extractLastUserTextFromRequest, extractOpenAIText, extractRemotePathFromAttachmentHref, filterListByClearHorizon, getChatHistory, getContextWindow, getErrorMessage, getExpiredAttachmentVisiblePath, isAuthExpiredError, isErrorResponseBody, isOfficeFile, listClaudeModels, listOpenAIModels, makeExtractPlaceholder, mapHistoryListToMessages, normalizeAttachmentPathCandidate, normalizeTextContent, notifyAgentSaveAttachment, safeDecodeURIComponent, sanitizeAttachmentLinksForHistory, stripFileBlocksFromHistory, transformContentWithImages, transformContentWithOpenAIImages, truncateLabelForDisplay };
497
+ export { type AttachmentFailureGroup, type AttachmentSaveInfo, BG_INDEXING_QUEUE_SUFFIX, type BgTaskEntry, type BoundedChatOptions, type BuildIndexingUserMessageOptions, CLAUDE_PER_REQUEST_INPUT_CAP, CONTEXT_WINDOW_BY_MODEL, CONTEXT_WINDOW_DEFAULT, type CallClaudeWithMcpParams, type ChatEngineConfig, type ChatHost, type ChatIdentity, type ChatMessage, ChatSession, type ChatState, type ChatSystemPromptParams, type ClaudeMcpServerRequest, type ClaudeMcpToolConfig, type ClaudeMessage, type ClaudeRole, type ComposedUserMessage, DEFAULT_CLAUDE_MODEL, DEFAULT_OPENAI_MODEL, EXPIRED_ATTACHMENT_URL_HOST, EXPIRED_ATTACHMENT_URL_ORIGIN, type ExtractDirective, HISTORY_TOKEN_BUDGET, type IndexingAttachmentInfo, type IndexingSystemPromptParams, LINK_LABEL_MAX_DISPLAY_CHARS, MAX_HISTORY_MESSAGES, MCP_NAME, MIN_INPUT_TOKEN_BUDGET, type MapHistoryOptions, OUTPUT_TOKEN_RESERVE, type OpenAIMessage, POLL_INTERVAL, TOOL_AND_RESPONSE_BUFFER, buildBoundedChatMessages, buildChatSystemPrompt, buildDisplayExpiredAttachmentHref, buildIndexingSystemPrompt, buildIndexingUserMessage, callClaudeWithMcp, callClaudeWithPublicMcp, callOpenAIWithPublicMcp, chatEngineConfig, composeUserMessage, configureChatEngine, createInlineLinkRegex, encodePathSegments, estimateMessageTokens, estimateTextTokens, extractClaudeText, extractLastUserTextFromRequest, extractOpenAIText, extractRemotePathFromAttachmentHref, filterListByClearHorizon, getChatHistory, getContextWindow, getErrorMessage, getExpiredAttachmentVisiblePath, groupAttachmentFailures, isAuthExpiredError, isErrorResponseBody, isNonRetryableRequestError, isOfficeFile, listClaudeModels, listOpenAIModels, makeExtractPlaceholder, mapHistoryListToMessages, normalizeAttachmentPathCandidate, normalizeTextContent, notifyAgentSaveAttachment, safeDecodeURIComponent, sanitizeAttachmentLinksForHistory, stripFileBlocksFromHistory, transformContentWithImages, transformContentWithOpenAIImages, truncateLabelForDisplay };
package/dist/engine.mjs CHANGED
@@ -77,6 +77,28 @@ Extracted content of attached office files (read inline below; do NOT fetch thei
77
77
  return { composed, composedForLlm, extractContent };
78
78
  }
79
79
 
80
+ // src/engine/attachments.ts
81
+ function groupAttachmentFailures(attachments) {
82
+ const groups = {};
83
+ const order = [];
84
+ (attachments || []).forEach(function(att) {
85
+ if (!att || att.status !== "error" && att.status !== "indexError") return;
86
+ const code = String(att.errorCode || "");
87
+ const message = String(
88
+ att.errorDetail || att.errorMessage || (att.status === "indexError" ? "File indexing failed" : "File upload has failed")
89
+ );
90
+ const key = code + "\0" + message;
91
+ if (!groups[key]) {
92
+ groups[key] = { code, message, files: [] };
93
+ order.push(key);
94
+ }
95
+ groups[key].files.push(String(att.name || "(unnamed file)"));
96
+ });
97
+ return order.map(function(k) {
98
+ return groups[k];
99
+ });
100
+ }
101
+
80
102
  // src/engine/prompts/chat_system_prompt.ts
81
103
  function buildChatSystemPrompt(params) {
82
104
  const { formattedServiceId, serviceName, serviceDescription } = params;
@@ -171,6 +193,36 @@ function isErrorResponseBody(response) {
171
193
  }
172
194
  return false;
173
195
  }
196
+ function isNonRetryableRequestError(input) {
197
+ if (!input || typeof input !== "object") return false;
198
+ var status = typeof input.status_code === "number" ? input.status_code : typeof input.status === "number" ? input.status : void 0;
199
+ var param = void 0;
200
+ var blobs = [];
201
+ var sources = [input.error, input.body && input.body.error, input.body, input];
202
+ for (var i = 0; i < sources.length; i++) {
203
+ var e = sources[i];
204
+ if (!e) continue;
205
+ if (typeof e === "string") {
206
+ blobs.push(e);
207
+ continue;
208
+ }
209
+ if (typeof e !== "object") continue;
210
+ if (param === void 0 && e.param != null) param = e.param;
211
+ if (typeof e.code === "string") blobs.push(e.code);
212
+ if (typeof e.type === "string") blobs.push(e.type);
213
+ if (typeof e.message === "string") blobs.push(e.message);
214
+ }
215
+ var hay = blobs.join(" | ").toLowerCase();
216
+ if (hay.indexOf("unknown_parameter") !== -1 || hay.indexOf("unknown parameter") !== -1 || hay.indexOf("unsupported_parameter") !== -1 || hay.indexOf("unsupported parameter") !== -1) {
217
+ return true;
218
+ }
219
+ var isClientReqStatus = status === 400 || status === 422;
220
+ if (isClientReqStatus && param != null && param !== "") return true;
221
+ if (isClientReqStatus && hay.indexOf("invalid_request") !== -1 && (hay.indexOf("parameter") !== -1 || hay.indexOf("param") !== -1)) {
222
+ return true;
223
+ }
224
+ return false;
225
+ }
174
226
  function isAuthExpiredError(input) {
175
227
  if (!input) return false;
176
228
  var blobs = [];
@@ -953,10 +1005,10 @@ var ChatSession = class {
953
1005
  });
954
1006
  };
955
1007
  var run = sendAndPoll().catch(function(err) {
956
- if (isAuthExpiredError(err)) return self.host.refreshSession().then(sendAndPoll);
1008
+ if (isAuthExpiredError(err) && !isNonRetryableRequestError(err)) return self.host.refreshSession().then(sendAndPoll);
957
1009
  throw err;
958
1010
  }).then(function(response) {
959
- if (isErrorResponseBody(response) && isAuthExpiredError(response)) {
1011
+ if (isErrorResponseBody(response) && isAuthExpiredError(response) && !isNonRetryableRequestError(response)) {
960
1012
  return self.host.refreshSession().then(sendAndPoll);
961
1013
  }
962
1014
  return response;
@@ -1574,7 +1626,7 @@ var ChatSession = class {
1574
1626
  return getChatHistory({ service: serviceId, owner, platform }, options);
1575
1627
  };
1576
1628
  return Promise.resolve().then(fetchHistory).catch(function(err) {
1577
- if (isAuthExpiredError(err)) return self.host.refreshSession().then(fetchHistory);
1629
+ if (isAuthExpiredError(err) && !isNonRetryableRequestError(err)) return self.host.refreshSession().then(fetchHistory);
1578
1630
  throw err;
1579
1631
  }).then(function(history) {
1580
1632
  if (token !== self.state.gateRefreshToken) return;
@@ -1721,6 +1773,8 @@ var ChatSession = class {
1721
1773
  att.status = "uploading";
1722
1774
  att.progress = 0;
1723
1775
  att.errorMessage = "";
1776
+ att.errorCode = "";
1777
+ att.errorDetail = "";
1724
1778
  this.host.renderAttachmentChips();
1725
1779
  var members = att.kind === "folder" ? (att.files || []).map(function(f) {
1726
1780
  return { file: f.file, relPath: f.path, storagePath: self.host.storagePathFor(f.path) };
@@ -1802,6 +1856,10 @@ var ChatSession = class {
1802
1856
  }, function(e) {
1803
1857
  console.error("[chat-engine] indexing request failed", e);
1804
1858
  anyIndexFailed = true;
1859
+ if (!att.errorCode && !att.errorDetail) {
1860
+ att.errorCode = e && (e.code || e.body && e.body.code) || "";
1861
+ att.errorDetail = e && (e.message || e.body && e.body.message) || (typeof e === "string" ? e : "");
1862
+ }
1805
1863
  });
1806
1864
  });
1807
1865
  });
@@ -1856,6 +1914,8 @@ var ChatSession = class {
1856
1914
  if (removed || aborted) return;
1857
1915
  att.status = "error";
1858
1916
  att.errorMessage = "File upload has failed";
1917
+ att.errorCode = err && (err.code || err.body && err.body.code) || "";
1918
+ att.errorDetail = err && (err.message || err.body && err.body.message) || (typeof err === "string" ? err : "");
1859
1919
  self.host.renderAttachmentChips();
1860
1920
  });
1861
1921
  });
@@ -1879,6 +1939,6 @@ var ChatSession = class {
1879
1939
  }
1880
1940
  };
1881
1941
 
1882
- export { BG_INDEXING_QUEUE_SUFFIX, CLAUDE_PER_REQUEST_INPUT_CAP, CONTEXT_WINDOW_BY_MODEL, CONTEXT_WINDOW_DEFAULT, ChatSession, DEFAULT_CLAUDE_MODEL, DEFAULT_OPENAI_MODEL, EXPIRED_ATTACHMENT_URL_HOST, EXPIRED_ATTACHMENT_URL_ORIGIN, HISTORY_TOKEN_BUDGET, LINK_LABEL_MAX_DISPLAY_CHARS, MAX_HISTORY_MESSAGES, MCP_NAME, MIN_INPUT_TOKEN_BUDGET, OUTPUT_TOKEN_RESERVE, POLL_INTERVAL, TOOL_AND_RESPONSE_BUFFER, buildBoundedChatMessages, buildChatSystemPrompt, buildDisplayExpiredAttachmentHref, buildIndexingSystemPrompt, buildIndexingUserMessage, callClaudeWithMcp, callClaudeWithPublicMcp, callOpenAIWithPublicMcp, chatEngineConfig, composeUserMessage, configureChatEngine, createInlineLinkRegex, encodePathSegments, estimateMessageTokens, estimateTextTokens, extractClaudeText, extractLastUserTextFromRequest, extractOpenAIText, extractRemotePathFromAttachmentHref, filterListByClearHorizon, getChatHistory, getContextWindow, getErrorMessage, getExpiredAttachmentVisiblePath, isAuthExpiredError, isErrorResponseBody, isOfficeFile, listClaudeModels, listOpenAIModels, makeExtractPlaceholder, mapHistoryListToMessages, normalizeAttachmentPathCandidate, normalizeTextContent, notifyAgentSaveAttachment, safeDecodeURIComponent, sanitizeAttachmentLinksForHistory, stripFileBlocksFromHistory, transformContentWithImages, transformContentWithOpenAIImages, truncateLabelForDisplay };
1942
+ export { BG_INDEXING_QUEUE_SUFFIX, CLAUDE_PER_REQUEST_INPUT_CAP, CONTEXT_WINDOW_BY_MODEL, CONTEXT_WINDOW_DEFAULT, ChatSession, DEFAULT_CLAUDE_MODEL, DEFAULT_OPENAI_MODEL, EXPIRED_ATTACHMENT_URL_HOST, EXPIRED_ATTACHMENT_URL_ORIGIN, HISTORY_TOKEN_BUDGET, LINK_LABEL_MAX_DISPLAY_CHARS, MAX_HISTORY_MESSAGES, MCP_NAME, MIN_INPUT_TOKEN_BUDGET, OUTPUT_TOKEN_RESERVE, POLL_INTERVAL, TOOL_AND_RESPONSE_BUFFER, buildBoundedChatMessages, buildChatSystemPrompt, buildDisplayExpiredAttachmentHref, buildIndexingSystemPrompt, buildIndexingUserMessage, callClaudeWithMcp, callClaudeWithPublicMcp, callOpenAIWithPublicMcp, chatEngineConfig, composeUserMessage, configureChatEngine, createInlineLinkRegex, encodePathSegments, estimateMessageTokens, estimateTextTokens, extractClaudeText, extractLastUserTextFromRequest, extractOpenAIText, extractRemotePathFromAttachmentHref, filterListByClearHorizon, getChatHistory, getContextWindow, getErrorMessage, getExpiredAttachmentVisiblePath, groupAttachmentFailures, isAuthExpiredError, isErrorResponseBody, isNonRetryableRequestError, isOfficeFile, listClaudeModels, listOpenAIModels, makeExtractPlaceholder, mapHistoryListToMessages, normalizeAttachmentPathCandidate, normalizeTextContent, notifyAgentSaveAttachment, safeDecodeURIComponent, sanitizeAttachmentLinksForHistory, stripFileBlocksFromHistory, transformContentWithImages, transformContentWithOpenAIImages, truncateLabelForDisplay };
1883
1943
  //# sourceMappingURL=engine.mjs.map
1884
1944
  //# sourceMappingURL=engine.mjs.map