Skip to content

Dataset page: AI Mode pill in the ActionBar (E6.2) - #521

Merged
neuromechanist merged 12 commits into
stagingfrom
feature/issue-517-ai-mode-pill
Nov 11, 2026
Merged

neuromechanist merged 12 commits into
stagingfrom
feature/issue-517-ai-mode-pill

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds the "AI Mode" pill to the dataset page ActionBar, directly after Download (board C1, E6.2).
It opens the Open Science Assistant widget as its centre-stage dialog with OSAChatWidget.open({ mode: "center" }).

  • Same shape and 44 px height as .action; brand teal (--brand-teal, #5bbad5) fill and border, #04121f text (new --on-teal token), weight 600, one 16 px sparkle (aria-hidden), hover a slightly darker teal, focus ring kept.
  • Shipped hidden; revealed only when window.OSAChatWidget.open is a function once the widget script has run. A build with no PUBLIC_OSA_* variables, a blocked widget script, and production's older pinned widget (no open()) keep it hidden. The wrapper ships hidden and is revealed with the pill, so the row gets no extra gap.
  • One-time hint under the pill (role="note", absolute, no layout shift): copy from the board, "How it works" link to docs.nemar.org/web/analyze-in-browser/ (new DOCS_ANALYZE_IN_BROWSER_PATH, built with resolveDocsBase), and "Got it". Dismissed by Got it, by using the pill, by following the link, and by Escape while focus is on the pill or in the hint; remembered in localStorage key nemar:ai-mode-hint:v1, with every read and write guarded (a blocked store means once per page load).
  • The hint is anchored to a position: relative wrapper around the pill, and the script keeps it inside the viewport with a 16 px gutter (pure placeAiModeHint), so it still works when the row wraps on a phone. Its colours are tokens (--ai-hint-*) with a dark counterpart in both dark blocks of tokens.css.
  • Logic is in the new pure module src/lib/osa-ai-mode.ts; osa-widget.ts is untouched and the widget pin is not bumped.
  • vitest.config.ts lets tokens.css through css.include (as it already did for eeg-viewer.css) so the token test can read it.

Part of OpenScience-Collective/osa#652, refs #517

Commands run

bun run typecheck   # 0 errors
bun run lint        # Checked 409 files, no fixes
bun run test        # 4692 passed, 14 skipped (includes 41 new: src/lib/osa-ai-mode.test.ts, test/ai-mode-pill.test.ts)

Dev server against the real develop widget and staging data, localhost:4321/dataset/xx099904 with PUBLIC_API_BASE_URL=https://api-test.nemar.org, PUBLIC_DATA_BASE_URL=https://data-test.nemar.org, PUBLIC_ZARR_BASE_URL=https://zarr-test.nemar.org, PUBLIC_OSA_WIDGET_SRC=...@develop/frontend/osa-chat-widget.js, PUBLIC_OSA_API_ENDPOINT=https://develop-widget.osc.earth/osa, PUBLIC_OSA_NOTEBOOK_URL=https://develop-notebook.osc.earth/osa/ (checked in Chrome):

  • Pill shown after Download, before View data; 44 px high, rgb(91, 186, 213) fill and border, rgb(4, 18, 31) text, weight 600, 14 px.
  • Hint shown on first visit under the pill (300 px wide, role="note", link https://docs.nemar.org/web/analyze-in-browser/).
  • Click opens the widget as role="dialog", class osa-center, named "AI Mode for xx099904"; the hint is dismissed and nemar:ai-mode-hint:v1 is stored.
  • After the click, and after Got it, a reload shows the pill and no hint.
  • Dark theme: hint lifts to the raised navy with a teal edge and stays legible.
  • 390 px viewport (headless Chrome, no scrollbar, re-run after review round 1; the earlier check was at 375 px, a 390 px frame with a scrollbar): the row wraps, the pill is in the first row, the hint is shifted to x 74 to 374 (inside the 16 px gutters), caret under the pill, no horizontal scroll.
  • Without the widget variables: no widget script, pill and wrapper display: none, row unchanged.
  • Not checked: test.nemar.org (needs a merge by someone else; confirm via curl -s https://test.nemar.org/version.json).

Screenshots (taken after review round 1, from the dev server above; hosted on the pr-521-screenshots branch, outside this PR's diff; keep that branch until the images are no longer needed, because deleting it breaks the three images below):

Light, 1280 px:

AI Mode pill and hint, light

Dark, 1280 px:

AI Mode pill and hint, dark

390 px wide (row wrapped, hint shifted inside the 16 px gutters, no horizontal scroll):

AI Mode pill and hint, 390 px

Notes for review

  • The brief said to reveal "at once if readyState is not loading". In a real browser the ActionBar module script runs at interactive, before the widget's deferred classic script, so that rule hid the pill on every load (found on the dev server). whenDocumentReady now runs at once only when readyState is complete; otherwise it waits for DOMContentLoaded, with load as the fallback for a script that runs after DOMContentLoaded already fired. Both orderings are tested.
  • .action's label is --fs-sm (14 px), not 15 px as the task text said; the pill keeps the shared 14 px.
  • On a wrapped row the hint overlays the second row's pills while shown, by design (absolute, no shift); it goes away with Got it, Escape, or a click on the pill that opens the widget.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review round 1: outcomes

Fix commits are on this branch (456bc6c, c0f91fd and the two before). bun run test (4692 passed, 14 skipped), bun run lint and bun run typecheck are clean.

  1. Screenshots / 390 px (important): fixed. Light, dark and 390 px screenshots are in the PR body (hosted on the pr-521-screenshots branch, outside the diff). The narrow check was re-run at a real 390 px viewport: hint at x 74 to 374, inside the 16 px gutters, no horizontal scroll.
  2. Click dismisses before knowing open() worked (suggestion): fixed. The handler is now if (openAiMode(widgetWindow)) dismiss();, so a failed open leaves the hint and the stored flag alone.
  3. Small touch targets for Got it and How it works (suggestion): fixed. Both now have min-block-size: 36px (Got it also gets wider padding); measured at 36 px in the browser. Test added.
  4. :has() wrapper and Escape (suggestion): fixed. The wrapper ships hidden and the script un-hides it with the pill, so there is no :has() dependency; Escape now dismisses a showing hint. Source tests updated. The hint overlaying the next row's pills on a wrapped row stays as designed (absolute, no layout shift), and is dismissible.
  5. Stale comment in docs-base.ts (suggestion): fixed. The block comment now covers all three constants.
  6. Leftover Closes #517 line (suggestion): fixed. Removed; the body keeps Part of OpenScience-Collective/osa#652, refs #517.
  7. Fragile source-slicing tests (suggestion): fixed. The tests now read whole elements with a depth-counting elementMarkup helper anchored on the opening tag instead of index arithmetic and literal closing strings. A comment notes that click and dismissal behaviour is covered in src/lib/osa-ai-mode.test.ts.
  8. readyState deviation note (note): no code change. Nothing to fix. Still to confirm on test.nemar.org after the staging merge: the pill shows, and keyboard focus returns to the pill when the centre dialog closes.

@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review round 2 outcomes (fix commits bc11d6a and 7898222 on this branch; `bun run test` 4692 passed, `bun run lint` and `bun run typecheck` clean):

  • Escape burns the one-time hint (ActionBar.astro, keydown): fixed. Escape now dismisses only when it is not default-prevented, the hint is showing, and focus is on the pill or inside the hint (wrap?.contains(document.activeElement)). Wiring test in test/ai-mode-pill.test.ts updated. Commit 7898222.
  • Focus dropped on dismiss: fixed. dismiss calls pill.focus() before hiding when focus is inside the hint. Wiring test added. Commit 7898222.
  • <span> wrapper holds block content: fixed. Wrapper is now a <div class="ai-mode">; CSS unchanged, tests updated to expect <div. Commit bc11d6a.
  • Stale PR body numbers and screenshots branch: fixed. Body now reads 4692 passed, 41 new, mentions the Escape behaviour, and notes that the pr-521-screenshots branch must be kept while the three images are needed. I am not deleting that branch; the images stay valid until someone removes it.

@neuromechanist
neuromechanist merged commit 7bc7815 into staging Nov 11, 2026
5 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-517-ai-mode-pill branch November 11, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant