@dudko.dev/agent-web-react 0.0.35 → 0.0.36

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
@@ -845,7 +845,7 @@ 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. |
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). |
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`). |
package/dist/index.cjs CHANGED
@@ -176,6 +176,8 @@ __export(src_exports, {
176
176
  mcpAppSandboxShellCsp: () => mcpAppSandboxShellCsp,
177
177
  mcpAppSandboxTarget: () => mcpAppSandboxTarget,
178
178
  mediaFamilyOf: () => mediaFamilyOf,
179
+ menuKeyTarget: () => menuKeyTarget,
180
+ menuSections: () => menuSections,
179
181
  mergeChatRecord: () => mergeChatRecord,
180
182
  mergeLabels: () => mergeLabels,
181
183
  newChatId: () => newChatId,
@@ -2699,6 +2701,31 @@ var attachmentRefusal = (kind, caps, canConvertPdf = false) => {
2699
2701
  }
2700
2702
  return void 0;
2701
2703
  };
2704
+ var menuSections = (options) => {
2705
+ const out = [];
2706
+ for (const option of options) {
2707
+ const section = option.section || void 0;
2708
+ const last = out[out.length - 1];
2709
+ if (last && last.section === section) last.options.push(option);
2710
+ else out.push({ ...section ? { section } : {}, options: [option] });
2711
+ }
2712
+ return out;
2713
+ };
2714
+ var menuKeyTarget = (key, index, count) => {
2715
+ if (count <= 0) return void 0;
2716
+ switch (key) {
2717
+ case "ArrowDown":
2718
+ return index < 0 ? 0 : (index + 1) % count;
2719
+ case "ArrowUp":
2720
+ return index < 0 ? count - 1 : (index - 1 + count) % count;
2721
+ case "Home":
2722
+ return 0;
2723
+ case "End":
2724
+ return count - 1;
2725
+ default:
2726
+ return void 0;
2727
+ }
2728
+ };
2702
2729
  var formatElapsed = (ms) => {
2703
2730
  const s = Math.max(0, Math.floor(ms / 1e3));
2704
2731
  if (s < 60) return `${s}s`;
@@ -5509,6 +5536,34 @@ var thinkingDefaults = (l) => [
5509
5536
  ];
5510
5537
  var MODES = ["autopilot", "ask-writes", "ask-all", "read-only"];
5511
5538
  var ModeIcon = ({ mode }) => mode === "autopilot" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(BoltIcon, { size: 14 }) : mode === "read-only" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(EyeIcon, { size: 14 }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ShieldIcon, { size: 14 });
5539
+ var useMenuKeys = (open, menuRef, chipRef, close) => {
5540
+ (0, import_react12.useEffect)(() => {
5541
+ if (!open) return;
5542
+ const menu = menuRef.current;
5543
+ const rows = menu ? [...menu.querySelectorAll('[role^="menuitem"]')] : [];
5544
+ (rows.find((r) => r.getAttribute("aria-checked") === "true") ?? rows[0])?.focus();
5545
+ }, [open, menuRef]);
5546
+ return (e) => {
5547
+ const menu = menuRef.current;
5548
+ if (!menu) return;
5549
+ if (e.key === "Escape") {
5550
+ e.preventDefault();
5551
+ close();
5552
+ chipRef.current?.focus();
5553
+ return;
5554
+ }
5555
+ const rows = [...menu.querySelectorAll('[role^="menuitem"]')];
5556
+ const to = menuKeyTarget(
5557
+ e.key,
5558
+ rows.indexOf(document.activeElement),
5559
+ rows.length
5560
+ );
5561
+ if (to === void 0) return;
5562
+ e.preventDefault();
5563
+ rows[to].focus();
5564
+ };
5565
+ };
5566
+ var opensMenu = (key) => key === "ArrowDown" || key === "ArrowUp";
5512
5567
  var attachSeq = 0;
5513
5568
  var useIsoLayoutEffect3 = typeof window === "undefined" ? import_react12.useEffect : import_react12.useLayoutEffect;
5514
5569
  var useMenuPlacement = (open, anchor, align) => {
@@ -5600,6 +5655,10 @@ var AgentComposer = ({
5600
5655
  const rootRef = (0, import_react12.useRef)(null);
5601
5656
  const modelRef = (0, import_react12.useRef)(null);
5602
5657
  const modeRef = (0, import_react12.useRef)(null);
5658
+ const modelChipRef = (0, import_react12.useRef)(null);
5659
+ const modeChipRef = (0, import_react12.useRef)(null);
5660
+ const modelMenuRef = (0, import_react12.useRef)(null);
5661
+ const modeMenuRef = (0, import_react12.useRef)(null);
5603
5662
  const [dropRect, setDropRect] = (0, import_react12.useState)();
5604
5663
  const [compactBar, setCompactBar] = (0, import_react12.useState)(false);
5605
5664
  (0, import_react12.useEffect)(() => {
@@ -5728,6 +5787,9 @@ ${draftText}` : draftText);
5728
5787
  const commandsStyle = useMenuPlacement(paletteOpen, rootRef, "stretch");
5729
5788
  const modelStyle = useMenuPlacement(menu === "model", modelRef, "left");
5730
5789
  const modeStyle = useMenuPlacement(menu === "mode", modeRef, "right");
5790
+ const closeMenu = () => setMenu(void 0);
5791
+ const modelMenuKeys = useMenuKeys(menu === "model", modelMenuRef, modelChipRef, closeMenu);
5792
+ const modeMenuKeys = useMenuKeys(menu === "mode", modeMenuRef, modeChipRef, closeMenu);
5731
5793
  (0, import_react12.useEffect)(() => setActive(0), [text2, menu]);
5732
5794
  (0, import_react12.useEffect)(() => {
5733
5795
  if (!menu) return;
@@ -6185,8 +6247,15 @@ ${draftText}` : draftText);
6185
6247
  "button",
6186
6248
  {
6187
6249
  type: "button",
6250
+ ref: modelChipRef,
6188
6251
  className: "awr-tchip awr-tchip--btn",
6189
6252
  onClick: () => setMenu(menu === "model" ? void 0 : "model"),
6253
+ onKeyDown: (e) => {
6254
+ if (menu !== "model" && opensMenu(e.key)) {
6255
+ e.preventDefault();
6256
+ setMenu("model");
6257
+ }
6258
+ },
6190
6259
  "aria-haspopup": "menu",
6191
6260
  "aria-expanded": menu === "model",
6192
6261
  title: [model?.label, thinkingLabel].filter(Boolean).join(" \xB7 "),
@@ -6196,47 +6265,81 @@ ${draftText}` : draftText);
6196
6265
  ]
6197
6266
  }
6198
6267
  ),
6199
- menu === "model" && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-menu awr-menu--pop", style: modelStyle, role: "menu", children: [
6200
- thinking && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
6201
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "awr-menu__head", children: L.thinking }),
6202
- thinkingOptions.map((o) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
6203
- "button",
6204
- {
6205
- type: "button",
6206
- role: "menuitemradio",
6207
- "aria-checked": thinking.value === o.id,
6208
- className: `awr-menu__item${thinking.value === o.id ? " is-active" : ""}`,
6209
- onClick: () => {
6210
- thinking.onChange(o.id);
6211
- setMenu(void 0);
6212
- },
6213
- children: o.label
6214
- },
6215
- o.id
6216
- ))
6217
- ] }),
6218
- model?.options?.length ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
6219
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "awr-menu__head", children: L.model }),
6220
- model.options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
6221
- "button",
6222
- {
6223
- type: "button",
6224
- role: "menuitemradio",
6225
- "aria-checked": model.value === o.id,
6226
- className: `awr-menu__item${model.value === o.id ? " is-active" : ""}`,
6227
- onClick: () => {
6228
- model.onSelect?.(o.id);
6229
- setMenu(void 0);
6230
- },
6231
- children: [
6232
- o.label,
6233
- o.group && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-menu__group", children: o.group })
6234
- ]
6235
- },
6236
- o.id
6237
- ))
6238
- ] }) : null
6239
- ] })
6268
+ menu === "model" && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
6269
+ "div",
6270
+ {
6271
+ className: "awr-menu awr-menu--pop",
6272
+ style: modelStyle,
6273
+ role: "menu",
6274
+ ref: modelMenuRef,
6275
+ onKeyDown: modelMenuKeys,
6276
+ children: [
6277
+ thinking && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
6278
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "awr-menu__head", children: L.thinking }),
6279
+ thinkingOptions.map((o) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
6280
+ "button",
6281
+ {
6282
+ type: "button",
6283
+ role: "menuitemradio",
6284
+ "aria-checked": thinking.value === o.id,
6285
+ className: `awr-menu__item${thinking.value === o.id ? " is-active" : ""}`,
6286
+ onClick: () => {
6287
+ thinking.onChange(o.id);
6288
+ setMenu(void 0);
6289
+ },
6290
+ children: o.label
6291
+ },
6292
+ o.id
6293
+ ))
6294
+ ] }),
6295
+ model?.options?.length ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
6296
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "awr-menu__head", children: L.model }),
6297
+ menuSections(model.options).map((run, i, runs) => {
6298
+ const rows = run.options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
6299
+ "button",
6300
+ {
6301
+ type: "button",
6302
+ role: "menuitemradio",
6303
+ "aria-checked": model.value === o.id,
6304
+ className: `awr-menu__item${model.value === o.id ? " is-active" : ""}`,
6305
+ onClick: () => {
6306
+ model.onSelect?.(o.id);
6307
+ setMenu(void 0);
6308
+ },
6309
+ children: [
6310
+ o.label,
6311
+ o.group && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-menu__group", children: o.group })
6312
+ ]
6313
+ },
6314
+ o.id
6315
+ ));
6316
+ if (run.section)
6317
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
6318
+ "div",
6319
+ {
6320
+ role: "group",
6321
+ "aria-label": run.section,
6322
+ className: "awr-menu__section",
6323
+ children: [
6324
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
6325
+ "div",
6326
+ {
6327
+ className: "awr-menu__head awr-menu__sectionhead",
6328
+ "aria-hidden": "true",
6329
+ children: run.section
6330
+ }
6331
+ ),
6332
+ rows
6333
+ ]
6334
+ },
6335
+ `s${i}`
6336
+ );
6337
+ return runs[i - 1]?.section ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "awr-menu__section awr-menu__section--plain", children: rows }, `s${i}`) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react12.Fragment, { children: rows }, `s${i}`);
6338
+ })
6339
+ ] }) : null
6340
+ ]
6341
+ }
6342
+ )
6240
6343
  ] }),
6241
6344
  /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-toolbar__spacer" }),
6242
6345
  toolbarEnd,
@@ -6245,9 +6348,16 @@ ${draftText}` : draftText);
6245
6348
  "button",
6246
6349
  {
6247
6350
  type: "button",
6351
+ ref: modeChipRef,
6248
6352
  className: `awr-tchip awr-tchip--btn awr-mode awr-mode--${agent.approvalMode}`,
6249
6353
  title: MODE_CHIP[agent.approvalMode].hint,
6250
6354
  onClick: () => setMenu(menu === "mode" ? void 0 : "mode"),
6355
+ onKeyDown: (e) => {
6356
+ if (menu !== "mode" && opensMenu(e.key)) {
6357
+ e.preventDefault();
6358
+ setMenu("mode");
6359
+ }
6360
+ },
6251
6361
  "aria-haspopup": "menu",
6252
6362
  "aria-expanded": menu === "mode",
6253
6363
  "aria-label": `${L.toolConsent}: ${MODE_CHIP[agent.approvalMode].label}`,
@@ -6257,29 +6367,39 @@ ${draftText}` : draftText);
6257
6367
  ]
6258
6368
  }
6259
6369
  ),
6260
- menu === "mode" && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "awr-menu awr-menu--pop", style: modeStyle, role: "menu", children: [
6261
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "awr-menu__head", children: L.toolConsent }),
6262
- MODES.map((m) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
6263
- "button",
6264
- {
6265
- type: "button",
6266
- role: "menuitemradio",
6267
- "aria-checked": agent.approvalMode === m,
6268
- className: `awr-menu__item${agent.approvalMode === m ? " is-active" : ""}`,
6269
- onClick: () => {
6270
- agent.setApprovalMode(m);
6271
- setMenu(void 0);
6272
- },
6273
- children: [
6274
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ModeIcon, { mode: m }),
6275
- " ",
6276
- MODE_CHIP[m].label,
6277
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-menu__desc", children: MODE_CHIP[m].hint })
6278
- ]
6279
- },
6280
- m
6281
- ))
6282
- ] })
6370
+ menu === "mode" && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
6371
+ "div",
6372
+ {
6373
+ className: "awr-menu awr-menu--pop",
6374
+ style: modeStyle,
6375
+ role: "menu",
6376
+ ref: modeMenuRef,
6377
+ onKeyDown: modeMenuKeys,
6378
+ children: [
6379
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "awr-menu__head", children: L.toolConsent }),
6380
+ MODES.map((m) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
6381
+ "button",
6382
+ {
6383
+ type: "button",
6384
+ role: "menuitemradio",
6385
+ "aria-checked": agent.approvalMode === m,
6386
+ className: `awr-menu__item${agent.approvalMode === m ? " is-active" : ""}`,
6387
+ onClick: () => {
6388
+ agent.setApprovalMode(m);
6389
+ setMenu(void 0);
6390
+ },
6391
+ children: [
6392
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ModeIcon, { mode: m }),
6393
+ " ",
6394
+ MODE_CHIP[m].label,
6395
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "awr-menu__desc", children: MODE_CHIP[m].hint })
6396
+ ]
6397
+ },
6398
+ m
6399
+ ))
6400
+ ]
6401
+ }
6402
+ )
6283
6403
  ] }),
6284
6404
  canSteer && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "awr-sendbtn", onClick: submit, "aria-label": L.steer, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SendIcon, { size: 16 }) }),
6285
6405
  busy ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
@@ -9725,6 +9845,8 @@ var import_agent_web8 = require("@dudko.dev/agent-web");
9725
9845
  mcpAppSandboxShellCsp,
9726
9846
  mcpAppSandboxTarget,
9727
9847
  mediaFamilyOf,
9848
+ menuKeyTarget,
9849
+ menuSections,
9728
9850
  mergeChatRecord,
9729
9851
  mergeLabels,
9730
9852
  newChatId,