@dudko.dev/agent-web-react 0.0.40 → 0.0.41

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
@@ -853,7 +853,7 @@ use them standalone. The full guide: [docs/chat.md](docs/chat.md).
853
853
  | Component | Purpose |
854
854
  | --- | --- |
855
855
  | `<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`). |
856
- | `<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). |
856
+ | `<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. `convertFile` may return a chip `note` and `images` (`ConvertedImage`: `{ name, blob }`, e.g. a scanned PDF's pages) that go as pictures under the same bounds - see [docs/chat.md](docs/chat.md#attachments-images-pdfs-files-urls). |
857
857
  | `<MessageList>` | The transcript; each answer with its steps, tool calls, thoughts, usage. |
858
858
  | `<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`). |
859
859
  | `<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`). |
@@ -996,7 +996,9 @@ the hooks keep them in step, with nothing to configure beyond a shared `memory`
996
996
  for it (`sessionBusy`, "Waiting for the other tab to finish this conversation…", the goal shown
997
997
  queued - "waiting for the other tab to finish", `queuedForSession`, its `queued` entry marked
998
998
  `session`, while the wait lasts) and then goes, with that turn in the agent's memory; a saved chat
999
- keeps both turns, in order (`saveChat`: one transaction, merged by message identity).
999
+ keeps both turns, in order (`saveChat`: one transaction, merged by message identity) - also when
1000
+ a tab the browser froze saves its turn after the other tab saved the next one (each turn placed
1001
+ by when it began, `ChatMessage.startedAt`).
1000
1002
  - **Another tab deletes or upgrades the database** ("delete everything", a newer copy of the site):
1001
1003
  `ChatHistoryStore` closes its connection on `versionchange`, like the core's stores, so that tab is
1002
1004
  not held up; the next use opens a new, empty database (after an upgrade by a newer copy, an error
@@ -881,6 +881,14 @@ interface ChatMessage {
881
881
  * `useChatHistory` saves a chat from here with that tab's own copy, never this one.
882
882
  */
883
883
  remote?: true;
884
+ /**
885
+ * When the run of its turn began (ms epoch: the hook's `at` on `run.start`); the user message and
886
+ * the answer of a turn carry the same. Absent without the hook's timestamps and on chats saved
887
+ * before it existed. It keeps a turn in its place when two tabs save one chat: one run of a
888
+ * conversation goes at a time (the session lock), so the turn that began first is the earlier
889
+ * one, whichever tab saved first (`mergeChatRecord`).
890
+ */
891
+ startedAt?: number;
884
892
  /** User turn: what was attached (images, files). */
885
893
  attachments?: ChatAttachment[];
886
894
  /** Assistant turn: the run's steps — tool calls, thoughts, subagents — as they happened. */
@@ -881,6 +881,14 @@ interface ChatMessage {
881
881
  * `useChatHistory` saves a chat from here with that tab's own copy, never this one.
882
882
  */
883
883
  remote?: true;
884
+ /**
885
+ * When the run of its turn began (ms epoch: the hook's `at` on `run.start`); the user message and
886
+ * the answer of a turn carry the same. Absent without the hook's timestamps and on chats saved
887
+ * before it existed. It keeps a turn in its place when two tabs save one chat: one run of a
888
+ * conversation goes at a time (the session lock), so the turn that began first is the earlier
889
+ * one, whichever tab saved first (`mergeChatRecord`).
890
+ */
891
+ startedAt?: number;
884
892
  /** User turn: what was attached (images, files). */
885
893
  attachments?: ChatAttachment[];
886
894
  /** Assistant turn: the run's steps — tool calls, thoughts, subagents — as they happened. */
package/dist/index.cjs CHANGED
@@ -1004,6 +1004,7 @@ var applyEvent = (state, event, ctx) => {
1004
1004
  const base2 = resetRun(ctx.remote ? state : withoutSubmitted(state));
1005
1005
  const userId = `msg-${base2.seq}`;
1006
1006
  const assistantId = `msg-${base2.seq + 1}`;
1007
+ const began = ctx.at !== void 0 ? { startedAt: ctx.at } : {};
1007
1008
  return {
1008
1009
  ...base2,
1009
1010
  // Another tab's run keeps the view of it; a run of this tab's ends it (and any wait).
@@ -1021,6 +1022,7 @@ var applyEvent = (state, event, ctx) => {
1021
1022
  content: event.goal,
1022
1023
  pending: false,
1023
1024
  ...ctx.remote ? { remote: true } : {},
1025
+ ...began,
1024
1026
  ...ctx.attachments?.length ? { attachments: ctx.attachments } : {}
1025
1027
  },
1026
1028
  {
@@ -1028,7 +1030,8 @@ var applyEvent = (state, event, ctx) => {
1028
1030
  role: "assistant",
1029
1031
  content: "",
1030
1032
  pending: true,
1031
- ...ctx.remote ? { remote: true } : {}
1033
+ ...ctx.remote ? { remote: true } : {},
1034
+ ...began
1032
1035
  }
1033
1036
  ],
1034
1037
  seq: base2.seq + 2
@@ -2272,6 +2275,22 @@ var renumber = (own, after) => {
2272
2275
  );
2273
2276
  return own.map((m) => ({ ...m, id: `msg-${next += 1}` }));
2274
2277
  };
2278
+ var turnAt = (m) => typeof m.startedAt === "number" && Number.isFinite(m.startedAt) ? m.startedAt : void 0;
2279
+ var placeByTurn = (stored, own) => {
2280
+ let i = stored.length;
2281
+ while (i > 0 && turnAt(stored[i - 1]) !== void 0) i -= 1;
2282
+ const out = stored.slice(0, i);
2283
+ for (const m of own) {
2284
+ const at = turnAt(m);
2285
+ while (i < stored.length && (at === void 0 || turnAt(stored[i]) <= at)) {
2286
+ out.push(stored[i]);
2287
+ i += 1;
2288
+ }
2289
+ out.push(m);
2290
+ }
2291
+ return [...out, ...stored.slice(i)];
2292
+ };
2293
+ var ownUnsaved = (messages, base2) => messages.some((m) => !m.remote && !base2?.known.has(m));
2275
2294
  var unchangedSince = (messages, base2) => base2 !== void 0 && messages.length === base2.known.size && messages.every((m) => base2.known.has(m));
2276
2295
  var mergeChatRecord = (view, stored, base2, texts) => {
2277
2296
  const local = view.messages.filter((m) => !m.remote);
@@ -2279,7 +2298,7 @@ var mergeChatRecord = (view, stored, base2, texts) => {
2279
2298
  return { record: { ...view, messages: local }, merged: false };
2280
2299
  }
2281
2300
  const own = local.filter((m) => !base2?.known.has(m));
2282
- const messages = [...stored.messages, ...renumber(own, stored.messages)];
2301
+ const messages = placeByTurn(stored.messages, renumber(own, stored.messages));
2283
2302
  return {
2284
2303
  record: {
2285
2304
  ...view,
@@ -2392,9 +2411,10 @@ var useChatHistory = (agent, options = {}) => {
2392
2411
  void select(sessionId);
2393
2412
  return;
2394
2413
  }
2395
- if (remote || messages.length === 0) return;
2414
+ if (messages.length === 0) return;
2396
2415
  const base2 = baseRef.current?.id === sessionId ? baseRef.current : void 0;
2397
2416
  if (unchangedSince(messages, base2)) return;
2417
+ if (remote && !ownUnsaved(messages, base2)) return;
2398
2418
  const now = Date.now();
2399
2419
  const createdAt = createdRef.current.get(sessionId) ?? now;
2400
2420
  createdRef.current.set(sessionId, createdAt);
@@ -6967,6 +6987,47 @@ ${draftText}` : draftText);
6967
6987
  if (full) noRoom[full].push(name);
6968
6988
  else setPending((cur) => [...cur, a]);
6969
6989
  };
6990
+ const sendAs = async (name, f, kind, mediaType, transform, id) => {
6991
+ const blob = transform === "downscale" ? await downscaleImage(f, {
6992
+ maxDimension: imageMax,
6993
+ maxPixels: attachCfg.imageMaxPixels
6994
+ }) : f;
6995
+ const sentOver = attachmentOverLimit({ bytes: blob.size }, "sent", transform, bounds);
6996
+ if (sentOver) return overLimitText(name, sentOver);
6997
+ add(name, {
6998
+ id,
6999
+ name,
7000
+ kind,
7001
+ mediaType: blob.type || mediaType,
7002
+ dataUrl: await readDataUrl2(blob),
7003
+ bytes: blob.size,
7004
+ ...blob !== f ? { note: L.downscaledFrom(L.bytes(f.size)) } : {}
7005
+ });
7006
+ return void 0;
7007
+ };
7008
+ const addImage = async (name, blob, id) => {
7009
+ const mediaType = blob.type || "image/jpeg";
7010
+ if (attachmentKindOf(mediaType, name) !== "image") return L.binaryText(name);
7011
+ const transform = attachmentTransformOf({
7012
+ kind: "image",
7013
+ mediaType,
7014
+ imageMaxDimension: imageMax,
7015
+ converts: false
7016
+ });
7017
+ const size = transform === "downscale" ? await imageSizeOf(blob) : void 0;
7018
+ const over = attachmentOverLimit(
7019
+ { bytes: blob.size, pixels: size && size.width * size.height },
7020
+ "original",
7021
+ transform,
7022
+ bounds
7023
+ );
7024
+ if (over) return overLimitText(name, over);
7025
+ if (messageOverLimit(pendingRef.current, { kind: "image", bytes: 0 }, bounds) === "images") {
7026
+ noRoom.images.push(name);
7027
+ return void 0;
7028
+ }
7029
+ return sendAs(name, blob, "image", mediaType, transform, id);
7030
+ };
6970
7031
  for (const f of list) {
6971
7032
  const mediaType = f.type || "application/octet-stream";
6972
7033
  const name = f.name || `pasted-${Date.now()}.${mediaType.split("/")[1] ?? "bin"}`;
@@ -7005,9 +7066,9 @@ ${draftText}` : draftText);
7005
7066
  const converted = await convertFile(f);
7006
7067
  if (converted) {
7007
7068
  const bytes = new Blob([converted.text]).size;
7008
- const sentOver2 = attachmentOverLimit({ bytes }, "sent", transform, bounds);
7009
- if (sentOver2) {
7010
- problem = overLimitText(name, sentOver2);
7069
+ const sentOver = attachmentOverLimit({ bytes }, "sent", transform, bounds);
7070
+ if (sentOver) {
7071
+ problem = overLimitText(name, sentOver);
7011
7072
  continue;
7012
7073
  }
7013
7074
  add(name, {
@@ -7017,8 +7078,18 @@ ${draftText}` : draftText);
7017
7078
  mediaType: "text/markdown",
7018
7079
  text: converted.text,
7019
7080
  bytes,
7020
- note: L.convertedFrom(name)
7081
+ note: converted.note ?? L.convertedFrom(name)
7021
7082
  });
7083
+ const images = converted.images ?? [];
7084
+ if (images.length > 0) {
7085
+ const imageRefusal = attachmentRefusal("image", caps);
7086
+ if (imageRefusal) problem = imageRefusal;
7087
+ else
7088
+ for (const image of images) {
7089
+ const said3 = await addImage(image.name, image.blob, `att-${attachSeq += 1}`);
7090
+ if (said3) problem = said3;
7091
+ }
7092
+ }
7022
7093
  continue;
7023
7094
  }
7024
7095
  }
@@ -7026,24 +7097,8 @@ ${draftText}` : draftText);
7026
7097
  problem = refusal;
7027
7098
  continue;
7028
7099
  }
7029
- const blob = transform === "downscale" ? await downscaleImage(f, {
7030
- maxDimension: imageMax,
7031
- maxPixels: attachCfg.imageMaxPixels
7032
- }) : f;
7033
- const sentOver = attachmentOverLimit({ bytes: blob.size }, "sent", transform, bounds);
7034
- if (sentOver) {
7035
- problem = overLimitText(name, sentOver);
7036
- continue;
7037
- }
7038
- add(name, {
7039
- id,
7040
- name,
7041
- kind,
7042
- mediaType: blob.type || mediaType,
7043
- dataUrl: await readDataUrl2(blob),
7044
- bytes: blob.size,
7045
- ...blob !== f ? { note: L.downscaledFrom(L.bytes(f.size)) } : {}
7046
- });
7100
+ const said2 = await sendAs(name, f, kind, mediaType, transform, id);
7101
+ if (said2) problem = said2;
7047
7102
  } catch (err) {
7048
7103
  problem = `${name}: ${err instanceof Error ? err.message : String(err)}`;
7049
7104
  }