@burdenoff/fe-libs 2026.919.1 → 2026.920.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.
Files changed (47) hide show
  1. package/dist/shared/assistant/adminModeSendGate.d.ts +43 -0
  2. package/dist/shared/assistant/adminModeSendGate.d.ts.map +1 -1
  3. package/dist/shared/assistant/adminModeSendGate.js +33 -18
  4. package/dist/shared/assistant/api.d.ts +17 -0
  5. package/dist/shared/assistant/api.d.ts.map +1 -1
  6. package/dist/shared/assistant/api.js +88 -66
  7. package/dist/shared/assistant/attachmentTurn.d.ts +21 -0
  8. package/dist/shared/assistant/attachmentTurn.d.ts.map +1 -0
  9. package/dist/shared/assistant/attachmentTurn.js +48 -0
  10. package/dist/shared/assistant/attachments.d.ts +85 -6
  11. package/dist/shared/assistant/attachments.d.ts.map +1 -1
  12. package/dist/shared/assistant/attachments.js +165 -112
  13. package/dist/shared/assistant/conversation.d.ts +21 -0
  14. package/dist/shared/assistant/conversation.d.ts.map +1 -1
  15. package/dist/shared/assistant/documentExtract.d.ts +11 -2
  16. package/dist/shared/assistant/documentExtract.d.ts.map +1 -1
  17. package/dist/shared/assistant/documentExtract.js +39 -37
  18. package/dist/shared/assistant/gatewayLimits.d.ts +10 -0
  19. package/dist/shared/assistant/gatewayLimits.d.ts.map +1 -1
  20. package/dist/shared/assistant/gatewayLimits.js +2 -2
  21. package/dist/shared/assistant/i18nManifest.d.ts +5 -0
  22. package/dist/shared/assistant/i18nManifest.d.ts.map +1 -1
  23. package/dist/shared/assistant/i18nManifest.js +6 -1
  24. package/dist/shared/assistant/index.d.ts +2 -0
  25. package/dist/shared/assistant/index.d.ts.map +1 -1
  26. package/dist/shared/assistant/modeCapabilities.d.ts +25 -0
  27. package/dist/shared/assistant/modeCapabilities.d.ts.map +1 -1
  28. package/dist/shared/assistant/modeCapabilities.js +6 -2
  29. package/dist/shared/assistant/store.d.ts +26 -5
  30. package/dist/shared/assistant/store.d.ts.map +1 -1
  31. package/dist/shared/assistant/store.js +28 -18
  32. package/dist/shared/assistant/ui/AssistantApiCallsConsentDialog.d.ts +27 -10
  33. package/dist/shared/assistant/ui/AssistantApiCallsConsentDialog.d.ts.map +1 -1
  34. package/dist/shared/assistant/ui/AssistantApiCallsConsentDialog.js +22 -16
  35. package/dist/shared/assistant/ui/AssistantChatArea.d.ts.map +1 -1
  36. package/dist/shared/assistant/ui/AssistantChatArea.js +305 -272
  37. package/dist/shared/assistant/ui/composer/AssistantComposer.d.ts +12 -0
  38. package/dist/shared/assistant/ui/composer/AssistantComposer.d.ts.map +1 -1
  39. package/dist/shared/assistant/ui/composer/AssistantComposer.js +57 -57
  40. package/dist/shared/assistant/useAssistantAttachments.d.ts +12 -1
  41. package/dist/shared/assistant/useAssistantAttachments.d.ts.map +1 -1
  42. package/dist/shared/assistant/useAssistantAttachments.js +98 -98
  43. package/dist/shared/assistant/writeModeConsent.d.ts +99 -0
  44. package/dist/shared/assistant/writeModeConsent.d.ts.map +1 -0
  45. package/dist/shared/assistant/writeModeConsent.js +48 -0
  46. package/dist/shared-assistant.js +116 -114
  47. package/package.json +1 -1
@@ -3,7 +3,6 @@ import { AssistantPromptPart } from './types';
3
3
  export declare const MAX_ATTACHMENTS = 5;
4
4
  /** Per-file ceiling before downscaling (images) / rejection (everything else). */
5
5
  export declare const MAX_FILE_BYTES: number;
6
- /** Per-file inline budget for text-like content, in characters. */
7
6
  /**
8
7
  * Media types a provider will accept as a URL-only `file` part.
9
8
  *
@@ -27,9 +26,41 @@ export declare const PROVIDER_READABLE_FILE_MEDIA_TYPES: readonly ["application/
27
26
  * they normally travel as `image` parts with inline bytes.
28
27
  */
29
28
  export declare function isProviderReadableFilePart(mimeType: string | undefined): boolean;
29
+ /**
30
+ * Per-file inline budget for text-like content, in characters — the DEFAULT. A
31
+ * mode may set its own (`AssistantModeConfig.maxInlineCharsPerFile`); see
32
+ * `resolveAssistantInlineLimits`.
33
+ */
30
34
  export declare const MAX_INLINE_CHARS_PER_FILE = 8000;
31
- /** Total inline budget across all attachments in one turn. */
35
+ /**
36
+ * Total inline budget across all attachments in one turn — the DEFAULT. A mode
37
+ * may set its own (`AssistantModeConfig.maxInlineCharsTotal`).
38
+ */
32
39
  export declare const MAX_INLINE_CHARS_TOTAL = 20000;
40
+ /**
41
+ * How much attachment TEXT one turn may carry inline: per file, and across all
42
+ * of them (BOFF-7334).
43
+ *
44
+ * ★★ Per mode, because one size did not fit. 8,000 characters a file is right
45
+ * for a question about a spreadsheet and far too little for a mode that BUILDS
46
+ * from one — BigConsole's Build designs a data sink from the CSV it is handed,
47
+ * and its own transport used to send 100,000 characters of it (decision D13:
48
+ * "per-mode inline cap for BC Build"). Every other mode keeps the defaults, and
49
+ * with them this module's behaviour byte for byte.
50
+ */
51
+ export interface AssistantInlineLimits {
52
+ /** Characters of any one file's text that may travel inline. */
53
+ readonly perFileChars: number;
54
+ /** Characters of text, across every file in the turn, that may travel inline. */
55
+ readonly totalChars: number;
56
+ }
57
+ /** What every mode gets unless it says otherwise. */
58
+ export declare const DEFAULT_INLINE_LIMITS: AssistantInlineLimits;
59
+ /** The fields of a mode's config that set its limits. */
60
+ export interface AssistantInlineLimitsConfig {
61
+ readonly maxInlineCharsPerFile?: number;
62
+ readonly maxInlineCharsTotal?: number;
63
+ }
33
64
  export type AssistantAttachmentKind = "image" | "text" | "document";
34
65
  export type AssistantAttachmentStatus = "pending" | "uploading" | "ready" | "error";
35
66
  export type AttachmentRejection = "too-many" | "too-large" | "empty" | "unreadable" | "unsupported-image";
@@ -67,8 +98,10 @@ export interface AssistantAttachment {
67
98
  /** Short-lived presigned URL, resolved at send time. */
68
99
  downloadUrl?: string;
69
100
  /**
70
- * Inlined content for this attachment, already truncated to
71
- * `MAX_INLINE_CHARS_PER_FILE`. Text files carry the file itself; PDF/DOCX/XLSX
101
+ * Inlined content for this attachment, already truncated to the per-file
102
+ * limit it was prepared with (`largestInlineCharsPerFile` of the modes on
103
+ * offer; `MAX_INLINE_CHARS_PER_FILE` by default). The send cuts it again to
104
+ * the sending mode's limit. Text files carry the file itself; PDF/DOCX/XLSX
72
105
  * carry whatever `extractDocumentText` pulled out of them (BOFF-6291).
73
106
  */
74
107
  textContent?: string;
@@ -257,14 +290,17 @@ export declare const PROMPT_ENVELOPE_RESERVE_BYTES = 2048;
257
290
  * Attachments that failed to upload are omitted: the user already sees the
258
291
  * failure in the composer, and a half-described file only confuses the model.
259
292
  */
260
- export declare function buildAttachmentPromptBlock(attachments: AssistantAttachment[], userText?: string): string;
293
+ export declare function buildAttachmentPromptBlock(attachments: AssistantAttachment[], userText?: string, limits?: AssistantInlineLimits): string;
261
294
  /**
262
295
  * Compose the text actually sent to the agent: the user's words, then the
263
296
  * attachment block. The user-facing bubble keeps the raw text (attachments are
264
297
  * rendered as chips there), matching how `buildPromptForMode` already separates
265
298
  * agent-only preamble from displayed content.
299
+ *
300
+ * `limits` are the sending MODE's (`resolveAssistantInlineLimits`); the default
301
+ * is what every mode had before modes could choose.
266
302
  */
267
- export declare function buildPromptWithAttachments(content: string, attachments: AssistantAttachment[]): string;
303
+ export declare function buildPromptWithAttachments(content: string, attachments: AssistantAttachment[], limits?: AssistantInlineLimits): string;
268
304
  export type { AssistantPromptPart };
269
305
  /**
270
306
  * How many images may travel INLINE in one turn.
@@ -313,6 +349,49 @@ export declare const MAX_TURN_BODY_BYTES = 262144;
313
349
  export declare const TURN_BODY_HEADROOM_BYTES = 32768;
314
350
  /** What the modelled part of the body must fit inside. */
315
351
  export declare const MAX_INLINE_TURN_BODY_BYTES: number;
352
+ /**
353
+ * The most text, per file or per turn, a mode may ask to inline: 200,000
354
+ * characters.
355
+ *
356
+ * ★ Bounded by the request body, which is where an over-large turn dies. Every
357
+ * character is at least one byte, so more characters than the body has bytes
358
+ * left after the prompt envelope can never travel. It is also no more than a
359
+ * document extraction ever holds (`MAX_EXTRACTED_CHARS`), so a document can use
360
+ * all of it. Within the ceiling, whether a given turn fits is still MEASURED —
361
+ * non-ASCII text and JSON escaping cost more than a byte a character — by
362
+ * `capTextToBody`.
363
+ */
364
+ export declare const MAX_CONFIGURABLE_INLINE_CHARS: number;
365
+ /**
366
+ * The inline limits of the mode a turn is sent in (BOFF-7334).
367
+ *
368
+ * - Neither field set (or no config at all): `DEFAULT_INLINE_LIMITS`, the very
369
+ * object, so every existing mode keeps today's budget.
370
+ * - `maxInlineCharsPerFile` alone: that per file, and a total of at least the
371
+ * default — never less than one such file. Asking for 100,000 a file should
372
+ * not be silently held to a 20,000 total.
373
+ * - `maxInlineCharsTotal` alone: that total, per file unchanged.
374
+ * - Per file never exceeds the total; both are bounded by
375
+ * `MAX_CONFIGURABLE_INLINE_CHARS`.
376
+ *
377
+ * ★ Pass the config for EXACTLY the mode being sent in (`findAssistantModeConfig`),
378
+ * never a display fallback to another mode's — the same rule as
379
+ * `resolveAssistantModeCapabilities`, for the same reason: one mode's budget must
380
+ * not be lent to another.
381
+ */
382
+ export declare function resolveAssistantInlineLimits(config?: AssistantInlineLimitsConfig | null): AssistantInlineLimits;
383
+ /**
384
+ * How much of one file to KEEP when it is attached, before anyone knows which
385
+ * mode it will be sent in: the largest per-file limit among the modes offered.
386
+ *
387
+ * ★ Not the current mode's. A file attached in Ask and sent after switching to
388
+ * a mode with a larger limit would otherwise arrive already cut to Ask's 8,000
389
+ * characters. Keeping the largest costs only memory — at most
390
+ * `MAX_ATTACHMENTS` × `MAX_CONFIGURABLE_INLINE_CHARS` — because the send cuts
391
+ * every file to the SENDING mode's limit (`applyInlineBudget`). A product whose
392
+ * modes all use the defaults keeps exactly 8,000, as before.
393
+ */
394
+ export declare function largestInlineCharsPerFile(modes: readonly AssistantInlineLimitsConfig[] | null | undefined): number;
316
395
  /**
317
396
  * Encode settings for the copy of an image that travels INSIDE the turn.
318
397
  *
@@ -1 +1 @@
1
- {"version":3,"file":"attachments.d.ts","sourceRoot":"","sources":["../../../src/shared/assistant/attachments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GA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ACjC,mBAAmB,EAAE,GAAG,SAAS,CA4DnC"}
@@ -1,18 +1,21 @@
1
1
  import { MAX_REQUEST_BODY_BYTES as e } from "./gatewayLimits.js";
2
- import { formatPageRanges as t, isMostlyImagePages as n, truncatePagesForInline as r } from "./documentText.js";
2
+ import { MAX_EXTRACTED_CHARS as t, formatPageRanges as n, isMostlyImagePages as r, truncatePagesForInline as i } from "./documentText.js";
3
3
  //#region src/shared/assistant/attachments.ts
4
- var i = 5, a = 10 * 1024 * 1024, o = ["application/pdf", "text/plain"];
5
- function s(e) {
4
+ var a = 5, o = 10 * 1024 * 1024, s = ["application/pdf", "text/plain"];
5
+ function c(e) {
6
6
  if (!e) return !1;
7
7
  let t = e.split(";")[0]?.trim().toLowerCase() ?? "";
8
- return t.startsWith("image/") ? !0 : o.includes(t);
8
+ return t.startsWith("image/") ? !0 : s.includes(t);
9
9
  }
10
- var c = 8e3, l = 2e4, u = class extends Error {
10
+ var l = 8e3, u = 2e4, d = Object.freeze({
11
+ perFileChars: l,
12
+ totalChars: u
13
+ }), f = class extends Error {
11
14
  constructor(e) {
12
15
  super(e), this.reason = e, this.name = "AttachmentRejectedError";
13
16
  }
14
17
  };
15
- function d(e) {
18
+ function ee(e) {
16
19
  return {
17
20
  id: e.id,
18
21
  filename: e.filename,
@@ -22,7 +25,7 @@ function d(e) {
22
25
  fileId: e.fileId
23
26
  };
24
27
  }
25
- var f = new Set([
28
+ var p = new Set([
26
29
  "txt",
27
30
  "md",
28
31
  "markdown",
@@ -46,31 +49,31 @@ var f = new Set([
46
49
  "toml",
47
50
  "conf"
48
51
  ]);
49
- function p(e) {
52
+ function m(e) {
50
53
  let t = e.lastIndexOf(".");
51
54
  return t >= 0 ? e.slice(t + 1).toLowerCase() : "";
52
55
  }
53
- function m(e, t) {
54
- return e.startsWith("image/") ? "image" : e.startsWith("text/") || e === "application/json" || e === "application/xml" || e === "application/x-yaml" || f.has(p(t)) ? "text" : "document";
56
+ function te(e, t) {
57
+ return e.startsWith("image/") ? "image" : e.startsWith("text/") || e === "application/json" || e === "application/xml" || e === "application/x-yaml" || p.has(m(t)) ? "text" : "document";
55
58
  }
56
- var h = {
59
+ var ne = {
57
60
  "application/pdf": "pdf",
58
61
  "application/x-pdf": "pdf",
59
62
  "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
60
63
  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx"
61
- }, g = {
64
+ }, h = {
62
65
  pdf: "pdf",
63
66
  docx: "docx",
64
67
  xlsx: "xlsx"
65
68
  };
66
- function ee(e, t) {
67
- return h[e.toLowerCase()] ?? g[p(t)] ?? null;
69
+ function g(e, t) {
70
+ return ne[e.toLowerCase()] ?? h[m(t)] ?? null;
68
71
  }
69
72
  var _ = [
70
73
  "image/*",
71
74
  "text/*",
72
- ...[...f].map((e) => `.${e}`),
73
- ...Object.keys(g).map((e) => `.${e}`)
75
+ ...[...p].map((e) => `.${e}`),
76
+ ...Object.keys(h).map((e) => `.${e}`)
74
77
  ].join(",");
75
78
  function v(e) {
76
79
  return e < 1024 ? `${e} B` : e < 1024 * 1024 ? `${(e / 1024).toFixed(1)} KB` : `${(e / (1024 * 1024)).toFixed(1)} MB`;
@@ -84,10 +87,10 @@ function b(e) {
84
87
  function x(e, t) {
85
88
  return y(e, t) ? "in-flight" : t.some((e) => e.status === "error") ? "failed" : null;
86
89
  }
87
- function S(e, t) {
90
+ function re(e, t) {
88
91
  return t >= 5 ? "too-many" : e.size === 0 ? "empty" : e.size > 10485760 && !e.type.startsWith("image/") ? "too-large" : null;
89
92
  }
90
- function C(e, t) {
93
+ function S(e, t) {
91
94
  if (e.length <= t) return {
92
95
  text: e,
93
96
  truncated: !1
@@ -98,107 +101,107 @@ function C(e, t) {
98
101
  truncated: !0
99
102
  };
100
103
  }
101
- function w(e) {
104
+ function C(e) {
102
105
  return [
103
106
  " ```",
104
107
  ...e.split("\n").map((e) => ` ${e}`),
105
108
  " ```"
106
109
  ];
107
110
  }
108
- function T(e) {
111
+ function w(e) {
109
112
  return e?.pageNumbers?.length ? e.pageNumbers : e?.pagesIncluded ? Array.from({ length: e.pagesIncluded }, (e, t) => t + 1) : [];
110
113
  }
111
- function E(e) {
112
- let n = e.extraction, r = [];
113
- if (n?.pageCount) {
114
- let e = T(n);
115
- e.length >= n.pageCount ? r.push(`${n.pageCount} page${n.pageCount === 1 ? "" : "s"}`) : e.length === 1 ? r.push(`page ${e[0]} of ${n.pageCount}`) : r.push(`pages ${t(e)} of ${n.pageCount}`);
114
+ function T(e) {
115
+ let t = e.extraction, r = [];
116
+ if (t?.pageCount) {
117
+ let e = w(t);
118
+ e.length >= t.pageCount ? r.push(`${t.pageCount} page${t.pageCount === 1 ? "" : "s"}`) : e.length === 1 ? r.push(`page ${e[0]} of ${t.pageCount}`) : r.push(`pages ${n(e)} of ${t.pageCount}`);
116
119
  }
117
- if (n?.sheetNames?.length && r.push(`sheets: ${n.sheetNames.join(", ")}`), e.textTruncated && e.textContent) {
118
- let t = n?.sourceChars;
119
- r.push(t && t > e.textContent.length ? `first ${e.textContent.length} characters of ${t}; truncated` : `first ${e.textContent.length} characters; truncated`);
120
+ if (t?.sheetNames?.length && r.push(`sheets: ${t.sheetNames.join(", ")}`), e.textTruncated && e.textContent) {
121
+ let n = t?.sourceChars;
122
+ r.push(n && n > e.textContent.length ? `first ${e.textContent.length} characters of ${n}; truncated` : `first ${e.textContent.length} characters; truncated`);
120
123
  }
121
124
  return r.length > 0 ? ` (${r.join("; ")})` : "";
122
125
  }
123
- var D = " Do NOT guess at, summarise or characterise its contents — you have not seen them.", O = [" Fetch the URL above if you can; otherwise ask the user to paste the relevant section as text.", D];
124
- function k(e) {
125
- let n = e.extraction;
126
- if (!n?.pageCount) return [];
127
- let r = new Set(T(n)), i = new Set(n.imagePages ?? []), a = [...i].filter((e) => !r.has(e)).sort((e, t) => e - t), o = [];
126
+ var E = " Do NOT guess at, summarise or characterise its contents — you have not seen them.", D = [" Fetch the URL above if you can; otherwise ask the user to paste the relevant section as text.", E];
127
+ function O(e) {
128
+ let t = e.extraction;
129
+ if (!t?.pageCount) return [];
130
+ let r = new Set(w(t)), i = new Set(t.imagePages ?? []), a = [...i].filter((e) => !r.has(e)).sort((e, t) => e - t), o = [];
128
131
  if (a.length > 0) {
129
- let e = a.length === 1 ? `Page ${a[0]}` : `Pages ${t(a)}`;
132
+ let e = a.length === 1 ? `Page ${a[0]}` : `Pages ${n(a)}`;
130
133
  o.push(` ${e} of this document contain no extractable text — they are images.`, " Nothing about those pages is available to you.");
131
134
  }
132
135
  let s = [];
133
- for (let e = 1; e <= n.pageCount; e += 1) !r.has(e) && !i.has(e) && s.push(e);
136
+ for (let e = 1; e <= t.pageCount; e += 1) !r.has(e) && !i.has(e) && s.push(e);
134
137
  if (s.length > 0) {
135
- let e = s.length === 1 ? `Page ${s[0]}` : `Pages ${t(s)}`;
138
+ let e = s.length === 1 ? `Page ${s[0]}` : `Pages ${n(s)}`;
136
139
  o.push(` ${e} of this document ${s.length === 1 ? "was" : "were"} not read at all.`);
137
140
  }
138
- return o.length > 0 && o.push(D), o;
141
+ return o.length > 0 && o.push(E), o;
139
142
  }
140
- function A(e) {
143
+ function k(e) {
141
144
  let t = e.extraction;
142
145
  if (!t || t.status === "unsupported") return [" Binary file — contents not inlined. Fetch the URL above if you can; otherwise ask the user", " to paste the relevant section as text."];
143
146
  if (t.status === "no-text") return t.format === "docx" || t.format === "xlsx" ? [
144
147
  " NO TEXT AVAILABLE — this document holds no readable text; it is either empty or contains only",
145
148
  " images, charts or drawings, none of which carry text. No text could be extracted.",
146
- ...O
149
+ ...D
147
150
  ] : [
148
151
  ` NO TEXT AVAILABLE — this document appears to be scanned images; no text could be extracted${t.pagesScanned && t.pageCount && t.pagesScanned < t.pageCount ? ` (the first ${t.pagesScanned} of ${t.pageCount} pages were checked)` : ""}.`,
149
152
  " There is no text layer to read, so nothing about its contents is available to you.",
150
- ...O
153
+ ...D
151
154
  ];
152
155
  if (t.status === "encrypted") return [
153
156
  " NO TEXT AVAILABLE — this document is encrypted or password-protected; it could not be opened",
154
157
  " and no text could be extracted.",
155
- ...O
158
+ ...D
156
159
  ];
157
- if (t.status === "corrupt") return [` NO TEXT AVAILABLE — this file could not be read${t.detail ? ` (${t.detail})` : ""}; no text could be extracted.`, ...O];
160
+ if (t.status === "corrupt") return [` NO TEXT AVAILABLE — this file could not be read${t.detail ? ` (${t.detail})` : ""}; no text could be extracted.`, ...D];
158
161
  if (!e.textContent) return [
159
162
  " Text WAS extracted from this document but is omitted because this turn ran out of inline budget,",
160
163
  " not because it is unavailable. Ask the user which part matters so they can re-send just that",
161
164
  " section, or fetch the URL above if you can.",
162
- D
165
+ E
163
166
  ];
164
- let r = t.pagesScanned ?? t.pageCount ?? 0, i = t.textPageCount;
165
- if (t.pageCount && i !== void 0 && n(i, r)) {
166
- let n = r - i;
167
+ let n = t.pagesScanned ?? t.pageCount ?? 0, i = t.textPageCount;
168
+ if (t.pageCount && i !== void 0 && r(i, n)) {
169
+ let r = n - i;
167
170
  return [
168
171
  ` NOT READ — this document is mostly images. Only ${i} of its ${t.pageCount} page${t.pageCount === 1 ? "" : "s"} carr${i === 1 ? "ies" : "y"} a text layer;`,
169
- ` the other ${n} contain no extractable text at all. Treat this as a document you have NOT`,
172
+ ` the other ${r} contain no extractable text at all. Treat this as a document you have NOT`,
170
173
  " read: the fragment below is the whole of what was available, not a summary of the document.",
171
- ...k(e),
172
- ` The only extractable text${E(e)}:`,
173
- ...w(e.textContent)
174
+ ...O(e),
175
+ ` The only extractable text${T(e)}:`,
176
+ ...C(e.textContent)
174
177
  ];
175
178
  }
176
179
  return [
177
- ` Extracted text${E(e)}:`,
178
- ...w(e.textContent),
179
- ...k(e)
180
+ ` Extracted text${T(e)}:`,
181
+ ...C(e.textContent),
182
+ ...O(e)
180
183
  ];
181
184
  }
182
- function j(e, t, n = M) {
185
+ function A(e, t, n = j) {
183
186
  let r = [`[${t + 1}] ${e.filename} — ${e.mimeType}, ${v(e.size)}`];
184
- return e.downloadUrl && r.push(` URL: ${e.downloadUrl}`), e.kind === "text" && e.textContent ? r.push(e.textTruncated ? ` Contents (first ${e.textContent.length} characters of ${v(e.size)}; truncated):` : " Contents:", ...w(e.textContent)) : e.kind === "document" ? r.push(...A(e)) : e.kind === "image" ? n.has(e.id) ? r.push(" NOT VIEWABLE IN THIS MESSAGE — this image did not fit the request-size budget, so only its URL", " travelled; its pixels are NOT attached. Fetch the URL above if you can; otherwise ask the user", " to describe it.", D) : r.push(" If this image is attached to the message as an image you can view, answer from what you see in it.", " If you cannot view attached images, say so plainly and ask the user to describe it — never guess.") : e.kind === "text" ? r.push(" Text file — contents omitted because this turn ran out of inline budget, not because they are", " unavailable. Fetch the URL above if you can; otherwise ask the user which part matters so they", " can re-send just that section.") : r.push(" Binary file — contents not inlined. Fetch the URL above if you can; otherwise ask the user", " to paste the relevant section as text."), r.join("\n");
187
+ return e.downloadUrl && r.push(` URL: ${e.downloadUrl}`), e.kind === "text" && e.textContent ? r.push(e.textTruncated ? ` Contents (first ${e.textContent.length} characters of ${v(e.size)}; truncated):` : " Contents:", ...C(e.textContent)) : e.kind === "document" ? r.push(...k(e)) : e.kind === "image" ? n.has(e.id) ? r.push(" NOT VIEWABLE IN THIS MESSAGE — this image did not fit the request-size budget, so only its URL", " travelled; its pixels are NOT attached. Fetch the URL above if you can; otherwise ask the user", " to describe it.", E) : r.push(" If this image is attached to the message as an image you can view, answer from what you see in it.", " If you cannot view attached images, say so plainly and ask the user to describe it — never guess.") : e.kind === "text" ? r.push(" Text file — contents omitted because this turn ran out of inline budget, not because they are", " unavailable. Fetch the URL above if you can; otherwise ask the user which part matters so they", " can re-send just that section.") : r.push(" Binary file — contents not inlined. Fetch the URL above if you can; otherwise ask the user", " to paste the relevant section as text."), r.join("\n");
185
188
  }
186
- var M = /* @__PURE__ */ new Set();
187
- function N(e, t) {
188
- let n = l, i = t, a = [...e], o = (e) => {
189
- let t = !!e.extraction, a = Math.min(n, c, t ? i : Infinity);
190
- if (a <= 0) return {
189
+ var j = /* @__PURE__ */ new Set();
190
+ function M(e, t) {
191
+ let n = t.totalChars, r = t.documentChars, a = [...e], o = (e) => {
192
+ let a = !!e.extraction, o = Math.min(n, t.perFileChars, a ? r : Infinity);
193
+ if (o <= 0) return {
191
194
  ...e,
192
195
  textContent: void 0,
193
196
  textTruncated: !0
194
197
  };
195
198
  if (e.documentPages?.length) {
196
- let t = r(e.documentPages, a);
199
+ let t = i(e.documentPages, o);
197
200
  return t.text === "" ? {
198
201
  ...e,
199
202
  textContent: void 0,
200
203
  textTruncated: !0
201
- } : (n -= t.text.length, i -= t.text.length, {
204
+ } : (n -= t.text.length, r -= t.text.length, {
202
205
  ...e,
203
206
  textContent: t.text,
204
207
  textTruncated: e.textTruncated || t.truncated,
@@ -209,11 +212,11 @@ function N(e, t) {
209
212
  } } : {}
210
213
  });
211
214
  }
212
- let { text: o, truncated: s } = C(e.textContent ?? "", a);
213
- return n -= o.length, t && (i -= o.length), {
215
+ let { text: s, truncated: c } = S(e.textContent ?? "", o);
216
+ return n -= s.length, a && (r -= s.length), {
214
217
  ...e,
215
- textContent: o,
216
- textTruncated: e.textTruncated || s
218
+ textContent: s,
219
+ textTruncated: e.textTruncated || c
217
220
  };
218
221
  };
219
222
  for (let t of [!1, !0]) e.forEach((e, n) => {
@@ -221,76 +224,126 @@ function N(e, t) {
221
224
  });
222
225
  return a;
223
226
  }
224
- function P(e, t, n) {
225
- let r = N(e, t);
227
+ var ie = (e) => ({
228
+ perFileChars: e.perFileChars,
229
+ totalChars: e.totalChars,
230
+ documentChars: e.totalChars
231
+ });
232
+ function N(e, t, n) {
233
+ let r = M(e, t);
226
234
  return [
227
235
  "",
228
236
  `--- Attachments (${e.length}) ---`,
229
237
  "The user attached the following file(s) to this message.",
230
- ...r.map((e, t) => j(e, t, n)),
238
+ ...r.map((e, t) => A(e, t, n)),
231
239
  "--- End attachments ---"
232
240
  ].join("\n");
233
241
  }
234
- var F = 2048;
235
- function I(e, t) {
236
- let n = Q(e);
237
- if (n.length === 0) return {
238
- documentChars: l,
239
- demotedImageIds: M
242
+ var P = 2048;
243
+ function ae(e, t, n) {
244
+ let r = L(e, t, n);
245
+ return F(n) ? {
246
+ budget: R(e, t, r.budget, r.demotedImageIds),
247
+ demotedImageIds: r.demotedImageIds
248
+ } : r;
249
+ }
250
+ function F(e) {
251
+ return e.perFileChars > d.perFileChars || e.totalChars > d.totalChars;
252
+ }
253
+ var I = (e, t) => e ? `${e}\n${t}` : t.trimStart();
254
+ function L(e, t, n) {
255
+ let r = ie(n), i = (e) => ({
256
+ ...r,
257
+ documentChars: e
258
+ }), a = Q(e);
259
+ if (a.length === 0) return {
260
+ budget: r,
261
+ demotedImageIds: j
240
262
  };
241
- let r = (r, i, a) => {
242
- let o = new Set(n.slice(0, r).map((e) => e.id)), s = P(e, i, a), c = t ? `${t}\n${s}` : s.trimStart(), { media: l } = $(e, o);
243
- return J(c, [{
263
+ let o = (n, r, o) => {
264
+ let s = new Set(a.slice(0, n).map((e) => e.id)), c = I(t, N(e, i(r), o)), { media: l } = $(e, s);
265
+ return X(c, [{
244
266
  type: "text",
245
267
  text: c
246
- }, ...l]) + F <= U;
268
+ }, ...l]) + P <= G;
247
269
  };
248
- for (let e = n.length; e >= 0; --e) {
249
- let t = new Set(n.slice(e).map((e) => e.id));
250
- if (r(e, 2e4, t)) return {
251
- documentChars: l,
270
+ for (let e = a.length; e >= 0; --e) {
271
+ let t = new Set(a.slice(e).map((e) => e.id));
272
+ if (o(e, r.documentChars, t)) return {
273
+ budget: r,
252
274
  demotedImageIds: t
253
275
  };
254
- if (!r(e, 0, t)) continue;
255
- let i = 0, a = l;
256
- for (; i < a;) {
257
- let n = Math.ceil((i + a) / 2);
258
- r(e, n, t) ? i = n : a = n - 1;
276
+ if (!o(e, 0, t)) continue;
277
+ let n = 0, s = r.documentChars;
278
+ for (; n < s;) {
279
+ let r = Math.ceil((n + s) / 2);
280
+ o(e, r, t) ? n = r : s = r - 1;
259
281
  }
260
282
  return {
261
- documentChars: i,
283
+ budget: i(n),
262
284
  demotedImageIds: t
263
285
  };
264
286
  }
265
287
  return {
266
- documentChars: l,
267
- demotedImageIds: new Set(n.map((e) => e.id))
288
+ budget: r,
289
+ demotedImageIds: new Set(a.map((e) => e.id))
268
290
  };
269
291
  }
270
- function L(e, t = "") {
271
- let n = b(e);
272
- if (n.length === 0) return "";
273
- let r = I(n, t);
274
- return P(n, r.documentChars, r.demotedImageIds);
292
+ function R(e, t, n, r) {
293
+ let i = (e) => ({
294
+ perFileChars: n.perFileChars,
295
+ totalChars: e,
296
+ documentChars: Math.min(n.documentChars, e)
297
+ }), a = (n) => X(I(t, N(e, n, r))) + P <= G;
298
+ if (a(n)) return n;
299
+ if (!a(i(0))) return i(0);
300
+ let o = 0, s = n.totalChars;
301
+ for (; o < s;) {
302
+ let e = Math.ceil((o + s) / 2);
303
+ a(i(e)) ? o = e : s = e - 1;
304
+ }
305
+ return i(o);
275
306
  }
276
- function R(e, t) {
277
- let n = L(t, e);
278
- return n ? e ? `${e}\n${n}` : n.trimStart() : e;
307
+ function z(e, t = "", n = d) {
308
+ let r = b(e);
309
+ if (r.length === 0) return "";
310
+ let i = ae(r, t, n);
311
+ return N(r, i.budget, i.demotedImageIds);
279
312
  }
280
- var z = 3, B = 15e5, V = e, H = 32768, U = V - H, W = 768, G = .6, K = typeof TextEncoder == "function" ? new TextEncoder() : null;
313
+ function B(e, t, n = d) {
314
+ let r = z(t, e, n);
315
+ return r ? I(e, r) : e;
316
+ }
317
+ var V = 3, H = 15e5, U = e, W = 32768, G = U - W, K = Math.min(t, G - P);
281
318
  function q(e) {
282
- return K ? K.encode(e).length : e.length;
319
+ if (!(typeof e != "number" || !Number.isFinite(e) || e < 1)) return Math.min(Math.floor(e), K);
283
320
  }
284
- function J(e, t) {
285
- return q(JSON.stringify({
321
+ function J(e) {
322
+ let t = q(e?.maxInlineCharsPerFile), n = q(e?.maxInlineCharsTotal);
323
+ if (t === void 0 && n === void 0) return d;
324
+ let r = t ?? d.perFileChars, i = n ?? Math.max(d.totalChars, r);
325
+ return Object.freeze({
326
+ perFileChars: Math.min(r, i),
327
+ totalChars: i
328
+ });
329
+ }
330
+ function oe(e) {
331
+ return (e ?? []).reduce((e, t) => Math.max(e, J(t).perFileChars), d.perFileChars);
332
+ }
333
+ var se = 768, ce = .6, Y = typeof TextEncoder == "function" ? new TextEncoder() : null;
334
+ function le(e) {
335
+ return Y ? Y.encode(e).length : e.length;
336
+ }
337
+ function X(e, t) {
338
+ return le(JSON.stringify({
286
339
  prompt: e,
287
340
  parts: t ?? []
288
341
  }));
289
342
  }
290
- function Y(e) {
343
+ function ue(e) {
291
344
  return b(e).filter((e) => e.kind === "image" && !!(e.inlineDataUrl ?? e.previewUrl)).length;
292
345
  }
293
- function X(e) {
346
+ function de(e) {
294
347
  return (e ?? []).filter((e) => e.type === "image" && !!e.data).length;
295
348
  }
296
349
  function Z(e) {
@@ -332,7 +385,7 @@ function $(e, t) {
332
385
  });
333
386
  continue;
334
387
  }
335
- i.downloadUrl && s(i.mimeType) && n.push({
388
+ i.downloadUrl && c(i.mimeType) && n.push({
336
389
  type: "file",
337
390
  mimeType: i.mimeType,
338
391
  url: i.downloadUrl,
@@ -344,15 +397,15 @@ function $(e, t) {
344
397
  inlinedIndices: r
345
398
  };
346
399
  }
347
- function te(e, t) {
400
+ function fe(e, t) {
348
401
  let n = b(t);
349
402
  if (n.length === 0) return;
350
403
  let { media: r, inlinedIndices: i } = $(n, new Set(Q(n).map((e) => e.id)));
351
404
  if (r.length !== 0) {
352
- for (; i.length > 0 && J(e, [{
405
+ for (; i.length > 0 && X(e, [{
353
406
  type: "text",
354
407
  text: e
355
- }, ...r]) > U;) {
408
+ }, ...r]) > G;) {
356
409
  let e = i.pop();
357
410
  if (e === void 0) break;
358
411
  let t = r[e];
@@ -363,14 +416,14 @@ function te(e, t) {
363
416
  name: t.name
364
417
  } : r.splice(e, 1));
365
418
  }
366
- if (r.length !== 0 && !(J(e, [{
419
+ if (r.length !== 0 && !(X(e, [{
367
420
  type: "text",
368
421
  text: e
369
- }, ...r]) > U)) return [{
422
+ }, ...r]) > G)) return [{
370
423
  type: "text",
371
424
  text: e
372
425
  }, ...r];
373
426
  }
374
427
  }
375
428
  //#endregion
376
- export { _ as ATTACHMENT_ACCEPT, u as AttachmentRejectedError, W as INLINE_IMAGE_MAX_DIM, G as INLINE_IMAGE_QUALITY, i as MAX_ATTACHMENTS, a as MAX_FILE_BYTES, c as MAX_INLINE_CHARS_PER_FILE, l as MAX_INLINE_CHARS_TOTAL, B as MAX_INLINE_IMAGE_BASE64_CHARS, z as MAX_INLINE_IMAGE_PARTS, U as MAX_INLINE_TURN_BODY_BYTES, V as MAX_TURN_BODY_BYTES, F as PROMPT_ENVELOPE_RESERVE_BYTES, o as PROVIDER_READABLE_FILE_MEDIA_TYPES, H as TURN_BODY_HEADROOM_BYTES, L as buildAttachmentPromptBlock, te as buildPromptParts, R as buildPromptWithAttachments, m as classifyAttachment, Y as countInlineImageCandidates, X as countInlinedImageParts, ee as detectDocumentFormat, J as estimateTurnBodyBytes, v as formatBytes, x as getAttachmentSendBlocker, p as getExtension, b as getSendableAttachments, y as hasAttachmentWorkInFlight, s as isProviderReadableFilePart, Z as parseDataUrl, d as toMessageAttachment, C as truncateForInline, S as validateFile };
429
+ export { _ as ATTACHMENT_ACCEPT, f as AttachmentRejectedError, d as DEFAULT_INLINE_LIMITS, se as INLINE_IMAGE_MAX_DIM, ce as INLINE_IMAGE_QUALITY, a as MAX_ATTACHMENTS, K as MAX_CONFIGURABLE_INLINE_CHARS, o as MAX_FILE_BYTES, l as MAX_INLINE_CHARS_PER_FILE, u as MAX_INLINE_CHARS_TOTAL, H as MAX_INLINE_IMAGE_BASE64_CHARS, V as MAX_INLINE_IMAGE_PARTS, G as MAX_INLINE_TURN_BODY_BYTES, U as MAX_TURN_BODY_BYTES, P as PROMPT_ENVELOPE_RESERVE_BYTES, s as PROVIDER_READABLE_FILE_MEDIA_TYPES, W as TURN_BODY_HEADROOM_BYTES, z as buildAttachmentPromptBlock, fe as buildPromptParts, B as buildPromptWithAttachments, te as classifyAttachment, ue as countInlineImageCandidates, de as countInlinedImageParts, g as detectDocumentFormat, X as estimateTurnBodyBytes, v as formatBytes, x as getAttachmentSendBlocker, m as getExtension, b as getSendableAttachments, y as hasAttachmentWorkInFlight, c as isProviderReadableFilePart, oe as largestInlineCharsPerFile, Z as parseDataUrl, J as resolveAssistantInlineLimits, ee as toMessageAttachment, S as truncateForInline, re as validateFile };