@dudko.dev/agent-web-react 0.0.37 → 0.0.38

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
@@ -206,7 +206,7 @@ function Custom() {
206
206
  | `compact()` | summarise the stored transcript now |
207
207
  | `sessionId` / `loadChat(chat)` | the memory session; switch conversations |
208
208
  | `subagents`, `skills`, `discoveredTools`, `compactions`, `budget` | the rest of the run, folded. `subagents` is a **tree**: static subagents and the helpers the model started (`subagents.dynamic`), each node with `parentId` / `depth`, status, model, tokens, tool calls and time; `subagentTree(subagents)` nests it - see [docs/chat.md](docs/chat.md#subagents-and-helpers-the-tree) |
209
- | `media`, `transcripts`, `decisions` | absent until there is one: the files the run generated (`MediaView[]`: a path in the workspace, never bytes), the audio it transcribed (`TranscriptView[]`), and the decision model's answers that came before any step (`DecisionView[]`; later ones are on their step) |
209
+ | `media`, `transcripts`, `decisions` | absent until there is one: the files the run generated (`MediaView[]`: a path in the workspace, never bytes; `references` - the paths of the reference pictures a picture was made with, and whether they were `used`), the audio it transcribed (`TranscriptView[]`), and the decision model's answers that came before any step (`DecisionView[]`; later ones are on their step) |
210
210
  | `learned`, `learnedNow`, `fetches` | the agent's notebook (`LessonView[]`, survives `reset`), what it wrote this run, and the `web_fetch` requests this run made (`FetchView[]`) |
211
211
  | `queued`, `notes`, `undelivered`, `replan` | steering: messages waiting, shown (and where), left over; the last replan decision (`byUser` when a message caused it; `failed` + `error` when the replanner call itself failed and the run went on with its plan) |
212
212
  | `steps[i].tier`, `.model`, `.tierReason`, `.escalations`, `.replanFailed` | with the core's `executorTiers`: the tier and model a step is on, why it started there, and its escalations (`StepEscalationView[]`); a tool call of an escalated attempt has `attempt`, a write that was not run twice `replayed`. `replanFailed`: the replanner failed after this step (a warning). All absent when tiers are off — see [docs/chat.md](docs/chat.md#model-tiers-escalation-and-a-replanner-that-failed) |
@@ -845,11 +845,11 @@ use them standalone. The full guide: [docs/chat.md](docs/chat.md).
845
845
  | Component | Purpose |
846
846
  | --- | --- |
847
847
  | `<AgentChat>` | Full panel: transcript with per-answer activity + composer + optional history and files panels. Reads a `controller` prop or the `<AgentProvider>` context. Says when the conversation runs in another tab of the site, waits for an answer there, or waits for it (`showOtherTabs`). |
848
- | `<AgentComposer>` | The input and its toolbar: attachments, commands, timer, agents, model/thinking, consent, mic, send/stop. The model menu takes `section` per option (a heading over each run of options, e.g. one per provider); both chip menus work from the keyboard (arrows, Home / End, Escape) - see [docs/chat.md](docs/chat.md#the-model-menu-sections-and-keys). |
848
+ | `<AgentComposer>` | The input and its toolbar: attachments, commands, timer, agents, model/thinking, consent, mic, send/stop. The model menu takes `section` per option (a heading over each run of options, e.g. one per provider); both chip menus work from the keyboard (arrows, Home / End, Escape) - see [docs/chat.md](docs/chat.md#the-model-menu-sections-and-keys). `attachments` takes `{ accept, maxBytes, imageMaxDimension, imageMaxPixels, maxSourceBytes, imageMaxSourcePixels, maxImages, maxTotalBytes }`: `maxBytes` (20 MB) is checked on what is sent, so a photo over it is downscaled (1568 px / 1.15 MP) and sent with the note "downscaled from …", and a file `convertFile` turns into text is judged by its text - neither is refused for its original; that original may be up to `maxSourceBytes` (50 MB, never below `maxBytes`), and a picture's up to `imageMaxSourcePixels` (200 MP, read from the header before decoding); one message holds at most `maxImages` pictures (20) and `maxTotalBytes` (20 MB) of attachments as they go - a file past either is left out in words, the rest kept - see [docs/chat.md](docs/chat.md#attachments-images-pdfs-files-urls). |
849
849
  | `<MessageList>` | The transcript; each answer with its steps, tool calls, thoughts, usage. |
850
850
  | `<StepList>` / `<ToolCallRow>` | Execution steps / one tool call with its cost and images. With model tiers: the tier / model badge, the escalation line, the earlier attempt's calls (`showTiers`); a replanner failure as a warning (`showReplanFailed`); the decision model's note (`showDecisions`); the subagent tree under its step (`showSubagents`); a `web_search` call's results as plain text and safe links (`showSearchResults`). |
851
851
  | `<SubagentTree>` / `<SubagentRow>` | The run's subagents - static ones and the helpers the model started - as an indented tree: status, model, tokens, time and a Stop button per node (`onStop`, `showUsage`, `showTools`, `renderSubagent`). |
852
- | `<GeneratedMedia>` / `<TranscriptBlock>` | A file a media tool wrote, read from the workspace: an image inline or a native audio player (only the types the core generates; never SVG) / a folded "Transcript of …" block. `<MessageList files showMedia renderMedia>` places them in the answer. |
852
+ | `<GeneratedMedia>` / `<TranscriptBlock>` | A file a media tool wrote, read from the workspace: an image inline or a native audio player (only the types the core generates; never SVG) - a picture made with reference pictures names them under it ("Reference: me.jpg", or that the image model took none: labels `mediaReferences` / `mediaReferencesUnused`) / a folded "Transcript of …" block. `<MessageList files showMedia renderMedia>` places them in the answer. |
853
853
  | `<ImageViewer>` / `<ImageThumb>` | A picture opened over the chat, in the page (never in a new window): fitted to the screen, previous / next within its message (arrows, swipe), zoom, Download as a file; a modal dialog with a focus trap, Esc / backdrop / close. Every picture `<MessageList>` draws is an `<ImageThumb>`; `<AgentChat imageViewer={false}>` keeps the old link in a new tab, `renderImageViewer` draws your own. See [docs/chat.md](docs/chat.md#pictures-open-in-the-page-the-image-viewer). |
854
854
  | `<FileChips>` / `<FileChip>` | The files an answer wrote to the workspace (the core's `file.written` / `file.deleted`), as chips: name, kind, size, open, download; an inline preview (text with line numbers, a picture, your own rendering through `renderFileContent`), and an `.html` file in a sandboxed frame with Preview / Source. `<MessageList files showFileChips htmlPreview renderFile renderFileContent>` places them under the answer. |
855
855
  | `<SandboxedFrame>` / `<SourceView>` | Untrusted HTML inside chrome the host draws: `<iframe sandbox>` without `allow-same-origin`, by `srcdoc`, no network, fixed height (`html`, `scripts`, `title`, `label`, `actions`, `footer`, `height`) / a file's text with line numbers, never markup. See [the boundary](#the-html-preview-is-a-security-boundary). |
@@ -1027,6 +1027,16 @@ interface MediaView {
1027
1027
  bytes: number;
1028
1028
  /** The media model that made it. */
1029
1029
  model: string;
1030
+ /**
1031
+ * The reference pictures of a `generate_image` call that had `images`: whether they were sent
1032
+ * to the image model (`used`; false: it takes none, the picture was made from the text), how
1033
+ * many, and their paths. Never their bytes.
1034
+ */
1035
+ references?: {
1036
+ used: boolean;
1037
+ count: number;
1038
+ paths: string[];
1039
+ };
1030
1040
  /** The step whose tool call made it, when the event named one. */
1031
1041
  stepId?: string;
1032
1042
  }
@@ -1027,6 +1027,16 @@ interface MediaView {
1027
1027
  bytes: number;
1028
1028
  /** The media model that made it. */
1029
1029
  model: string;
1030
+ /**
1031
+ * The reference pictures of a `generate_image` call that had `images`: whether they were sent
1032
+ * to the image model (`used`; false: it takes none, the picture was made from the text), how
1033
+ * many, and their paths. Never their bytes.
1034
+ */
1035
+ references?: {
1036
+ used: boolean;
1037
+ count: number;
1038
+ paths: string[];
1039
+ };
1030
1040
  /** The step whose tool call made it, when the event named one. */
1031
1041
  stepId?: string;
1032
1042
  }
package/dist/index.cjs CHANGED
@@ -34,6 +34,7 @@ __export(src_exports, {
34
34
  APP_MAX_HEIGHT: () => APP_MAX_HEIGHT,
35
35
  APP_MIN_HEIGHT: () => APP_MIN_HEIGHT,
36
36
  ASK_USER_TOOL_NAME: () => ASK_USER_TOOL_NAME,
37
+ ATTACHMENT_BOUNDS: () => ATTACHMENT_BOUNDS,
37
38
  AgentChat: () => AgentChat,
38
39
  AgentComposer: () => AgentComposer,
39
40
  AgentLabelsProvider: () => AgentLabelsProvider,
@@ -128,7 +129,9 @@ __export(src_exports, {
128
129
  askUserOutputKept: () => askUserOutputKept,
129
130
  askUserWith: () => askUserWith,
130
131
  attachmentKindOf: () => attachmentKindOf,
132
+ attachmentOverLimit: () => attachmentOverLimit,
131
133
  attachmentRefusal: () => attachmentRefusal,
134
+ attachmentTransformOf: () => attachmentTransformOf,
132
135
  buildMcpAppDocument: () => buildMcpAppDocument,
133
136
  buildMcpAppSandboxShell: () => buildMcpAppSandboxShell,
134
137
  buildSandboxedDocument: () => buildSandboxedDocument,
@@ -163,6 +166,7 @@ __export(src_exports, {
163
166
  formatElapsed: () => formatElapsed,
164
167
  grantedAppCsp: () => grantedAppCsp,
165
168
  imageExtensionOf: () => imageExtensionOf,
169
+ imageSizeOf: () => imageSizeOf,
166
170
  isMcpAppSandboxMessage: () => isMcpAppSandboxMessage,
167
171
  isWebGPUAvailable: () => import_agent_web8.isWebGPUAvailable,
168
172
  lessonsOf: () => lessonsOf,
@@ -180,6 +184,7 @@ __export(src_exports, {
180
184
  menuSections: () => menuSections,
181
185
  mergeChatRecord: () => mergeChatRecord,
182
186
  mergeLabels: () => mergeLabels,
187
+ messageOverLimit: () => messageOverLimit,
183
188
  newChatId: () => newChatId,
184
189
  noticesOf: () => noticesOf,
185
190
  onStorageChange: () => import_agent_web8.onStorageChange,
@@ -667,6 +672,13 @@ var mediaOf = (event, withStep) => ({
667
672
  mediaType: event.mediaType,
668
673
  bytes: event.bytes,
669
674
  model: event.model,
675
+ ...event.references ? {
676
+ references: {
677
+ used: event.references.used === true,
678
+ count: event.references.count,
679
+ paths: [...event.references.paths]
680
+ }
681
+ } : {},
670
682
  ...withStep && event.step ? { stepId: event.step.id } : {}
671
683
  });
672
684
  var addApp = (state, event, by) => {
@@ -2695,7 +2707,8 @@ var attachmentKindOf = (mediaType, name) => {
2695
2707
  };
2696
2708
  var withAttachments = (text2, files) => {
2697
2709
  const texts = files.filter((f) => f.kind === "text" && f.text !== void 0);
2698
- if (texts.length === 0) return text2;
2710
+ const saved = files.filter((f) => f.kind !== "text" && f.path);
2711
+ if (texts.length === 0 && saved.length === 0) return text2;
2699
2712
  const blocks = texts.map((f) => {
2700
2713
  const body = f.text;
2701
2714
  const fence = body.includes("```") ? "~~~" : "```";
@@ -2705,10 +2718,46 @@ ${fence}
2705
2718
  ${body}
2706
2719
  ${fence}`;
2707
2720
  });
2708
- return `${text2}
2709
-
2710
- Attached file(s):
2711
- ${blocks.join("\n\n")}`;
2721
+ const kind = (f) => f.kind === "image" ? "picture" : f.kind === "pdf" ? "PDF" : "file";
2722
+ const lines = saved.map(
2723
+ (f) => `- ${kind(f)} "${f.name.replace(/["\s]+/g, " ").trim()}" (also saved as ${f.path})`
2724
+ );
2725
+ return [
2726
+ text2,
2727
+ ...blocks.length ? [`Attached file(s):
2728
+ ${blocks.join("\n\n")}`] : [],
2729
+ ...lines.length ? [`Also attached:
2730
+ ${lines.join("\n")}`] : []
2731
+ ].join("\n\n");
2732
+ };
2733
+ var ATTACHMENT_BOUNDS = {
2734
+ maxBytes: 20 * 1024 * 1024,
2735
+ // The largest JPEGs a phone writes (a 200 MP shot: ~20-40 MB) pass, and a long PDF with its
2736
+ // pictures; past this it is read into memory for nothing the model would get.
2737
+ maxSourceBytes: 50 * 1024 * 1024,
2738
+ // The largest phone sensor (200 MP: 16320 × 12240) passes, ~800 MB decoded; past this is a
2739
+ // scan, a render or a decompression bomb (a PNG of a few KB can declare 30000 × 30000 px).
2740
+ imageMaxSourcePixels: 2e8,
2741
+ // Under what the providers take in one request (Anthropic: 100 pictures, 32 MB; OpenAI: 50 MB).
2742
+ maxImages: 20,
2743
+ maxTotalBytes: 20 * 1024 * 1024
2744
+ };
2745
+ var attachmentTransformOf = (input) => input.converts ? "convert" : input.kind === "image" && input.imageMaxDimension !== false && input.mediaType !== "image/gif" && input.mediaType !== "image/svg+xml" ? "downscale" : "none";
2746
+ var attachmentOverLimit = (file, stage, transform, bounds) => {
2747
+ if (stage === "original" && transform !== "none") {
2748
+ const sourceBytes = Math.max(bounds.maxSourceBytes, bounds.maxBytes);
2749
+ if (file.bytes > sourceBytes) return { bound: "bytes", limit: sourceBytes };
2750
+ if (transform === "downscale" && file.pixels !== void 0 && file.pixels > bounds.imageMaxSourcePixels)
2751
+ return { bound: "pixels", limit: bounds.imageMaxSourcePixels };
2752
+ return void 0;
2753
+ }
2754
+ return file.bytes > bounds.maxBytes ? { bound: "bytes", limit: bounds.maxBytes } : void 0;
2755
+ };
2756
+ var messageOverLimit = (inMessage, next, bounds) => {
2757
+ if (next.kind === "image" && inMessage.filter((a) => a.kind === "image").length >= bounds.maxImages)
2758
+ return "images";
2759
+ const total = inMessage.reduce((n, a) => n + a.bytes, 0);
2760
+ return total + next.bytes > bounds.maxTotalBytes ? "bytes" : void 0;
2712
2761
  };
2713
2762
  var attachmentRefusal = (kind, caps, canConvertPdf = false) => {
2714
2763
  if (kind === "text" || !caps) return void 0;
@@ -2868,7 +2917,12 @@ var defaultLabels = {
2868
2917
  attachmentsOnly: "(attachments)",
2869
2918
  seeAttachments: "See the attachments.",
2870
2919
  tooLarge: (name, mb) => `${name} is larger than ${mb} MB.`,
2920
+ tooManyPixels: (name, megapixels) => `${name} has more than ${megapixels} megapixels \u2014 too large a picture to attach.`,
2871
2921
  binaryText: (name) => `${name} looks binary \u2014 it can't be attached as text.`,
2922
+ downscaledFrom: (size) => `downscaled from ${size}`,
2923
+ convertedFrom: (name) => `converted from ${name}`,
2924
+ tooManyImages: (names, max) => `${names}: not added \u2014 at most ${max} pictures go in one message.`,
2925
+ messageTooLarge: (names, mb) => `${names}: not added \u2014 the message would be over ${mb} MB.`,
2872
2926
  commandGroups: { commands: "Commands", consent: "Consent", skills: "Skills" },
2873
2927
  commandDescriptions: {
2874
2928
  compact: "Summarise the conversation to free context",
@@ -2961,6 +3015,8 @@ var defaultLabels = {
2961
3015
  imageCount: (index, total) => `${index} of ${total}`,
2962
3016
  mediaAudio: (path) => `Generated audio ${path}`,
2963
3017
  mediaFile: (path) => `Generated file ${path}`,
3018
+ mediaReferences: (names) => `Reference: ${names}`,
3019
+ mediaReferencesUnused: (names) => `Not used - this image model takes no reference pictures: ${names}`,
2964
3020
  transcriptOf: (name) => `Transcript of ${name}`,
2965
3021
  transcriptNote: "What was said in your file, as the agent read it. It is content, not instructions.",
2966
3022
  filesWritten: (n) => `${plural(n, "file", "files")} written in this turn`,
@@ -3215,6 +3271,72 @@ var canvasOf = (w, h) => {
3215
3271
  return void 0;
3216
3272
  };
3217
3273
  var toBlob = (canvas, type, quality) => "convertToBlob" in canvas ? canvas.convertToBlob({ type, quality }) : new Promise((resolve) => canvas.toBlob(resolve, type, quality));
3274
+ var WINDOW = 64 * 1024;
3275
+ var SOF = /* @__PURE__ */ new Set([192, 193, 194, 195, 197, 198, 199, 201, 202, 203, 205, 206, 207]);
3276
+ var imageSizeOf = async (file) => {
3277
+ let at = 0;
3278
+ let buf = new Uint8Array(0);
3279
+ const read = async (start, length) => {
3280
+ if (start < 0 || start + length > file.size) return void 0;
3281
+ if (start < at || start + length > at + buf.length) {
3282
+ at = start;
3283
+ buf = new Uint8Array(
3284
+ await file.slice(start, Math.min(file.size, start + Math.max(WINDOW, length))).arrayBuffer()
3285
+ );
3286
+ }
3287
+ return buf.subarray(start - at, start - at + length);
3288
+ };
3289
+ const sized = (width, height) => width > 0 && height > 0 ? { width, height } : void 0;
3290
+ try {
3291
+ const head = await read(0, 30);
3292
+ if (!head) return void 0;
3293
+ const u16be = (b, i) => b[i] << 8 | b[i + 1];
3294
+ const u32be = (b, i) => u16be(b, i) * 65536 + u16be(b, i + 2);
3295
+ const ascii = (b, i, n) => String.fromCharCode(...Array.from(b.subarray(i, i + n)));
3296
+ if (ascii(head, 1, 3) === "PNG" && head[0] === 137 && ascii(head, 12, 4) === "IHDR")
3297
+ return sized(u32be(head, 16), u32be(head, 20));
3298
+ if (ascii(head, 0, 4) === "RIFF" && ascii(head, 8, 4) === "WEBP") {
3299
+ const chunk = ascii(head, 12, 4);
3300
+ const u16le = (i) => head[i] | head[i + 1] << 8;
3301
+ const u24le = (i) => u16le(i) | head[i + 2] << 16;
3302
+ if (chunk === "VP8X") return sized(u24le(24) + 1, u24le(27) + 1);
3303
+ if (chunk === "VP8L" && head[20] === 47) {
3304
+ const bits = (u16le(21) | u16le(23) << 16) >>> 0;
3305
+ return sized((bits & 16383) + 1, (bits >>> 14 & 16383) + 1);
3306
+ }
3307
+ if (chunk === "VP8 " && head[23] === 157 && head[24] === 1 && head[25] === 42)
3308
+ return sized(u16le(26) & 16383, u16le(28) & 16383);
3309
+ return void 0;
3310
+ }
3311
+ if (head[0] === 255 && head[1] === 216) {
3312
+ let p = 2;
3313
+ for (let segments = 0; segments < 4096; segments++) {
3314
+ const m = await read(p, 4);
3315
+ if (!m || m[0] !== 255) return void 0;
3316
+ const marker = m[1];
3317
+ if (marker === 255) {
3318
+ p += 1;
3319
+ continue;
3320
+ }
3321
+ if (marker === 1 || marker >= 208 && marker <= 216) {
3322
+ p += 2;
3323
+ continue;
3324
+ }
3325
+ if (marker === 217 || marker === 218) return void 0;
3326
+ const length = u16be(m, 2);
3327
+ if (length < 2) return void 0;
3328
+ if (SOF.has(marker)) {
3329
+ const frame = await read(p + 4, 5);
3330
+ return frame ? sized(u16be(frame, 3), u16be(frame, 1)) : void 0;
3331
+ }
3332
+ p += 2 + length;
3333
+ }
3334
+ }
3335
+ return void 0;
3336
+ } catch {
3337
+ return void 0;
3338
+ }
3339
+ };
3218
3340
  var downscaleImage = async (file, opts = {}) => {
3219
3341
  const maxDimension = opts.maxDimension ?? 1568;
3220
3342
  const maxPixels = opts.maxPixels ?? 115e4;
@@ -5670,7 +5792,12 @@ var AgentComposer = ({
5670
5792
  const MODE_CHIP = L.modes;
5671
5793
  const DEFAULT_THINKING = thinkingDefaults(L);
5672
5794
  const [text2, setText] = (0, import_react12.useState)("");
5673
- const [pending, setPending] = (0, import_react12.useState)([]);
5795
+ const [pending, setPendingState] = (0, import_react12.useState)([]);
5796
+ const pendingRef = (0, import_react12.useRef)([]);
5797
+ const setPending = (next) => {
5798
+ pendingRef.current = typeof next === "function" ? next(pendingRef.current) : next;
5799
+ setPendingState(pendingRef.current);
5800
+ };
5674
5801
  const [menu, setMenu] = (0, import_react12.useState)(void 0);
5675
5802
  const [active, setActive] = (0, import_react12.useState)(0);
5676
5803
  const [dismissed, setDismissed] = (0, import_react12.useState)(() => /* @__PURE__ */ new Set());
@@ -5835,17 +5962,44 @@ ${draftText}` : draftText);
5835
5962
  void cmd.run?.(args);
5836
5963
  };
5837
5964
  const attachCfg = typeof attachments === "object" ? attachments : {};
5838
- const maxBytes = attachCfg.maxBytes ?? 20 * 1024 * 1024;
5965
+ const bounds = {
5966
+ maxBytes: attachCfg.maxBytes ?? ATTACHMENT_BOUNDS.maxBytes,
5967
+ maxSourceBytes: attachCfg.maxSourceBytes ?? ATTACHMENT_BOUNDS.maxSourceBytes,
5968
+ imageMaxSourcePixels: attachCfg.imageMaxSourcePixels ?? ATTACHMENT_BOUNDS.imageMaxSourcePixels,
5969
+ maxImages: attachCfg.maxImages ?? ATTACHMENT_BOUNDS.maxImages,
5970
+ maxTotalBytes: attachCfg.maxTotalBytes ?? ATTACHMENT_BOUNDS.maxTotalBytes
5971
+ };
5839
5972
  const imageMax = attachCfg.imageMaxDimension ?? 1568;
5973
+ const overLimitText = (name, over) => over.bound === "pixels" ? L.tooManyPixels(name, Math.round(over.limit / 1e6)) : L.tooLarge(name, Math.round(over.limit / 1024 / 1024));
5840
5974
  const addFiles = async (list) => {
5841
- const added = [];
5842
5975
  let problem;
5976
+ const noRoom = { images: [], bytes: [] };
5977
+ const add = (name, a) => {
5978
+ const full = messageOverLimit(pendingRef.current, a, bounds);
5979
+ if (full) noRoom[full].push(name);
5980
+ else setPending((cur) => [...cur, a]);
5981
+ };
5843
5982
  for (const f of list) {
5844
5983
  const mediaType = f.type || "application/octet-stream";
5845
5984
  const name = f.name || `pasted-${Date.now()}.${mediaType.split("/")[1] ?? "bin"}`;
5846
5985
  const kind = attachmentKindOf(mediaType, name);
5847
- if (f.size > maxBytes) {
5848
- problem = L.tooLarge(name, Math.round(maxBytes / 1024 / 1024));
5986
+ const refusal = attachmentRefusal(kind, caps);
5987
+ const converts = Boolean(convertFile && (refusal || kind === "pdf" && convert === "always"));
5988
+ const transform = attachmentTransformOf({
5989
+ kind,
5990
+ mediaType,
5991
+ imageMaxDimension: imageMax,
5992
+ converts
5993
+ });
5994
+ const size = transform === "downscale" ? await imageSizeOf(f) : void 0;
5995
+ const pixels = size && size.width * size.height;
5996
+ const over = attachmentOverLimit({ bytes: f.size, pixels }, "original", transform, bounds);
5997
+ if (over) {
5998
+ problem = overLimitText(name, over);
5999
+ continue;
6000
+ }
6001
+ if (kind === "image" && transform !== "convert" && messageOverLimit(pendingRef.current, { kind, bytes: 0 }, bounds) === "images") {
6002
+ noRoom.images.push(name);
5849
6003
  continue;
5850
6004
  }
5851
6005
  try {
@@ -5856,22 +6010,26 @@ ${draftText}` : draftText);
5856
6010
  problem = L.binaryText(name);
5857
6011
  continue;
5858
6012
  }
5859
- added.push({ id, name, kind, mediaType, text: content, bytes: f.size });
6013
+ add(name, { id, name, kind, mediaType, text: content, bytes: f.size });
5860
6014
  continue;
5861
6015
  }
5862
- const refusal = attachmentRefusal(kind, caps);
5863
- const wantConvert = convertFile && (refusal || kind === "pdf" && convert === "always");
5864
- if (wantConvert && convertFile) {
6016
+ if (converts && convertFile) {
5865
6017
  const converted = await convertFile(f);
5866
6018
  if (converted) {
5867
- added.push({
6019
+ const bytes = new Blob([converted.text]).size;
6020
+ const sentOver2 = attachmentOverLimit({ bytes }, "sent", transform, bounds);
6021
+ if (sentOver2) {
6022
+ problem = overLimitText(name, sentOver2);
6023
+ continue;
6024
+ }
6025
+ add(name, {
5868
6026
  id,
5869
6027
  name: converted.name ?? `${name}.md`,
5870
6028
  kind: "text",
5871
6029
  mediaType: "text/markdown",
5872
6030
  text: converted.text,
5873
- bytes: converted.text.length,
5874
- note: `converted from ${name}`
6031
+ bytes,
6032
+ note: L.convertedFrom(name)
5875
6033
  });
5876
6034
  continue;
5877
6035
  }
@@ -5880,25 +6038,35 @@ ${draftText}` : draftText);
5880
6038
  problem = refusal;
5881
6039
  continue;
5882
6040
  }
5883
- const blob = kind === "image" && imageMax !== false ? await downscaleImage(f, {
6041
+ const blob = transform === "downscale" ? await downscaleImage(f, {
5884
6042
  maxDimension: imageMax,
5885
6043
  maxPixels: attachCfg.imageMaxPixels
5886
6044
  }) : f;
5887
- added.push({
6045
+ const sentOver = attachmentOverLimit({ bytes: blob.size }, "sent", transform, bounds);
6046
+ if (sentOver) {
6047
+ problem = overLimitText(name, sentOver);
6048
+ continue;
6049
+ }
6050
+ add(name, {
5888
6051
  id,
5889
6052
  name,
5890
6053
  kind,
5891
6054
  mediaType: blob.type || mediaType,
5892
6055
  dataUrl: await readDataUrl2(blob),
5893
6056
  bytes: blob.size,
5894
- ...blob !== f ? { note: `downscaled from ${L.bytes(f.size)}` } : {}
6057
+ ...blob !== f ? { note: L.downscaledFrom(L.bytes(f.size)) } : {}
5895
6058
  });
5896
6059
  } catch (err) {
5897
6060
  problem = `${name}: ${err instanceof Error ? err.message : String(err)}`;
5898
6061
  }
5899
6062
  }
5900
- setAttachError(problem);
5901
- if (added.length) setPending((cur) => [...cur, ...added]);
6063
+ const names = (list2) => list2.length > 3 ? `${list2.slice(0, 3).join(", ")}, \u2026` : list2.join(", ");
6064
+ const said = [
6065
+ problem,
6066
+ noRoom.images.length ? L.tooManyImages(names(noRoom.images), bounds.maxImages) : "",
6067
+ noRoom.bytes.length ? L.messageTooLarge(names(noRoom.bytes), Math.round(bounds.maxTotalBytes / 1024 / 1024)) : ""
6068
+ ];
6069
+ setAttachError(said.filter(Boolean).join(" ") || void 0);
5902
6070
  if (fileRef.current) fileRef.current.value = "";
5903
6071
  };
5904
6072
  const onPaste = (e) => {
@@ -6167,7 +6335,10 @@ ${draftText}` : draftText);
6167
6335
  if (renderAttachment) return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: renderAttachment(a, remove) }, a.id);
6168
6336
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "awr-chip awr-file", title: a.note ?? a.mediaType, children: [
6169
6337
  a.kind === "image" && a.dataUrl ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("img", { className: "awr-file__thumb", src: a.dataUrl, alt: a.name }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(FileIcon, { size: 14 }),
6170
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-file__name", children: a.name }),
6338
+ a.note ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "awr-file__text", children: [
6339
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-file__name", children: a.name }),
6340
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-file__note", children: a.note })
6341
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-file__name", children: a.name }),
6171
6342
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
6172
6343
  "button",
6173
6344
  {
@@ -7459,13 +7630,14 @@ var useFileUrl = (files, path, mediaType) => {
7459
7630
  }, [files, path, mediaType]);
7460
7631
  return url;
7461
7632
  };
7633
+ var baseName = (path) => path.split(/[\\/]/).filter(Boolean).pop() ?? path;
7462
7634
  var GeneratedMedia = ({ media, files, labels }) => {
7463
7635
  const L = useLabels(labels);
7464
7636
  const family = mediaFamilyOf(media.mediaType);
7465
7637
  const type = family ? media.mediaType.toLowerCase().split(";")[0].trim() : void 0;
7466
7638
  const url = useFileUrl(files, media.path, type);
7467
7639
  if (url && family === "image") {
7468
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
7640
+ const thumb = /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
7469
7641
  ImageThumb,
7470
7642
  {
7471
7643
  className: "awr-media awr-media--image",
@@ -7477,6 +7649,20 @@ var GeneratedMedia = ({ media, files, labels }) => {
7477
7649
  labels
7478
7650
  }
7479
7651
  );
7652
+ const refs = media.references;
7653
+ if (!refs || refs.paths.length === 0) return thumb;
7654
+ const names = refs.paths.map(baseName).join(", ");
7655
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("span", { className: "awr-media-refs", children: [
7656
+ thumb,
7657
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
7658
+ "span",
7659
+ {
7660
+ className: `awr-media__refs${refs.used ? "" : " awr-media__refs--unused"}`,
7661
+ title: refs.paths.join("\n"),
7662
+ children: refs.used ? L.mediaReferences(names) : L.mediaReferencesUnused(names)
7663
+ }
7664
+ )
7665
+ ] });
7480
7666
  }
7481
7667
  if (url && family === "audio") {
7482
7668
  return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { className: "awr-media awr-media--audio", title: media.path, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
@@ -9727,6 +9913,7 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
9727
9913
  APP_MAX_HEIGHT,
9728
9914
  APP_MIN_HEIGHT,
9729
9915
  ASK_USER_TOOL_NAME,
9916
+ ATTACHMENT_BOUNDS,
9730
9917
  AgentChat,
9731
9918
  AgentComposer,
9732
9919
  AgentLabelsProvider,
@@ -9821,7 +10008,9 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
9821
10008
  askUserOutputKept,
9822
10009
  askUserWith,
9823
10010
  attachmentKindOf,
10011
+ attachmentOverLimit,
9824
10012
  attachmentRefusal,
10013
+ attachmentTransformOf,
9825
10014
  buildMcpAppDocument,
9826
10015
  buildMcpAppSandboxShell,
9827
10016
  buildSandboxedDocument,
@@ -9856,6 +10045,7 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
9856
10045
  formatElapsed,
9857
10046
  grantedAppCsp,
9858
10047
  imageExtensionOf,
10048
+ imageSizeOf,
9859
10049
  isMcpAppSandboxMessage,
9860
10050
  isWebGPUAvailable,
9861
10051
  lessonsOf,
@@ -9873,6 +10063,7 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
9873
10063
  menuSections,
9874
10064
  mergeChatRecord,
9875
10065
  mergeLabels,
10066
+ messageOverLimit,
9876
10067
  newChatId,
9877
10068
  noticesOf,
9878
10069
  onStorageChange,