Skip to content

Widget: host API and center-stage dialog (E6.1) - #705

Merged
neuromechanist merged 12 commits into
developfrom
feature/issue-701-host-api-dialog
Nov 11, 2026
Merged

neuromechanist merged 12 commits into
developfrom
feature/issue-701-host-api-dialog

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Summary

PR 1 of 2 for E6.1: the host API, the center-stage AI Mode dialog, the C2 start screen and the config that feeds it.
The diff without the runtime bundle is about 2,800 lines, over the 1,500-line limit, so the plan rail and Continue in notebook (board C3) follow as PR 2 on feature/issue-701-plan-rail, which closes #701.

  • OSAChatWidget.open({mode}?), close(), ask(text, {mode}?), setMode('corner' | 'center'), on(event, fn) (events open, close, modechange {mode}, send {text}). Calls before init() are queued and replayed in order; bad input warns and does nothing; ask goes through sendMessage; a throwing handler cannot break the widget; on returns an unsubscribe. setMode is a no-op in the pop-out.
  • Center is the same .osa-chat-window with an osa-center class and a scrim: role="dialog", aria-modal, inert page, scroll lock, Tab trap, Escape (History or Settings first, then dock), Move to corner, Close restores focus. Full screen at 600 px and under.
  • Header: AI Mode pill, dataset id plus an optional validated title from setDataset (1 to 200 characters), History, Move to corner, Settings, Close.
  • C2 start screen for an empty conversation (60 px field, 44 px pills from suggestionsToShow, cards, footer); the thread in a centered 760 px column otherwise.
  • widget.center_start {capabilities (max 3), note} and widget.analysis_docs {title, url} in WidgetConfig (validators, resolve()), WidgetConfigResponse and the widget's CONFIG; NEMAR sets them. The footer "How it works" link and a Settings row open the docs in a new tab with rel="noopener noreferrer", and do not exist when unset.
  • Docs in docs/community-widget.md, a CHANGELOG entry, and both new test files wired into the frontend-tests job.

Part of #701

Commands run

  • bun frontend/test-widget-host-api.js: 208 passed, 0 failed
  • bun frontend/browser-harness/center-stage-check.mjs: all checks passed in Chrome 157 at 1280x900 and 390x844, light and dark (real Tab key, Escape, viewport, 44 px targets, contrast)
  • every frontend/test-widget-*.js and the other frontend/test-*.js: exit 0
  • bun scripts/build-runtime-bundle.js && bun scripts/build-runtime-bundle.js --check: bundle is current (the runtime entry is unchanged)
  • node --check frontend/osa-chat-widget.js: ok
  • uv run ruff check . && uv run ruff format --check .: clean
  • uv run pytest tests/test_api tests/test_core tests/test_frontend: 3,522 passed, 6 skipped (tests/test_core/test_llm_service.py does not collect under the local Python 3.14 venv, a litellm/pydantic v1 issue that predates this change, so it was ignored)
  • curl -sI https://docs.nemar.org/web/analyze-in-browser/: HTTP/2 200

Not run here: the end-to-end check against develop-demo.osc.earth, which needs this branch deployed.

…alog

Adds widget.center_start (up to three capability cards and a footer note) and
widget.analysis_docs (https docs link) to WidgetConfig, the widget config
response and NEMAR's config. Tested: validators, GET /{community}, and every
registered community's docs link.
Adds open, close, ask, setMode and on to OSAChatWidget (queued before init),
the modal AI Mode dialog on the same window (inert page, scroll lock, Tab trap,
Escape and Move to corner dock it, Close restores focus), setDataset title, and
the start screen driven by widget.center_start and widget.analysis_docs.
Tested: test-widget-host-api.js, all widget suites, center-stage-check.mjs.
208 checks over the real widget in happy-dom: API shape, queue replay, refused
calls, events and throwing handlers, ask through sendMessage, the dialog, trap,
docking, focus return, the start screen and the docs link. Passing.
Real Tab key, Escape, viewport, 44 px targets and contrast at 1280x900 and
390x844 in light and dark, and both new test files as frontend-tests steps.
Passing locally in Chrome 157.
…list

Tested: test_embed_snippet_hygiene.py passes.
…screen keeps the disclaimer and feedback link; bounded host queue, pop-out warnings, new-tab hint, iframe in the Tab cycle; tests and docs (tested: host-api suite, all widget suites, center-stage harness in Chrome)
@neuromechanist

Copy link
Copy Markdown
Member Author

Review round 1: outcomes (fixes pushed to this branch as 63ecea8 and the merge commit before it).

  • CHANGELOG.md conflict (important): fixed. develop merged into the branch, both entries kept; bun scripts/build-runtime-bundle.js --check is current, every frontend/test-widget-*.js suite and the center-stage harness (real Chrome) pass.
  • setMode('center') on the notebook tab (important): fixed. engageCenter now takes the window to the chat tab, so setMode, open and a later open of a remembered center all land on the chat. New test with a capsule community on the notebook tab; the docs say so.
  • ask() discards the typed draft (important): fixed. hostAsk restores the chat input (and the start field) after sendMessage clears it. Tests cover a draft typed in the chat input, one typed in the start field, and no draft. Docs updated.
  • Start screen hides the disclaimer and feedback link (important): fixed. The disclaimer row stays on the start screen; when center_start.note is set the note replaces the disclaimer text and the Send feedback link stays. Tests cover a community with no note (text and link shown, link opens the panel) and one with a note.
  • Unhandled rejections from the start form and pills (suggestion): fixed, both sends have .catch like hostAsk.
  • FOCUSABLE_SELECTOR omits iframe and contenteditable (suggestion): fixed by adding both to the selector, with a comment on the limit that keys inside a frame never reach the handler. The dialog never lays over the notebook tab after the fix above, so the frame is not in the cycle in practice.
  • Silent queue before init() (suggestion): fixed. The queue holds at most 50 calls (the next warns and is dropped); one console.warn fires if init() has not built the widget 5 s after the first call was kept (a timer, not the load event, so it also covers a page that loaded long ago). The pop-out's open, close and setMode now warn. Tests cover the cap, the idle warning and the no-warning case.
  • New-tab link not announced (suggestion): fixed, both links carry a visually hidden " (opens in a new tab)".
  • Tab-trap test oracle, console patching, Escape on feedback (suggestion): fixed. The cycle test names the expected controls by selector and checks the chat's hidden input is excluded; the suite's own pass/fail output no longer goes through the patched console, and listen() restores a listener left running, which covers the failure-between-listen-and-stop case without wrapping every block; an Escape case for the feedback overlay was added.
  • Registry-wide docs test (suggestion): fixed in part. It now GETs /{id}/ through create_community_router for every registered community with analysis_docs and asserts the served URL is https, and the validator length re-assertions are gone. Rejected: the registry._assistants.pop cleanup, which is the repository's existing convention (the registry has no public unregister, and the same call is used in several other test files); adding one is outside this PR.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Worker Deployment Required

Worker changes detected. After merging to main or develop, the workflow will automatically deploy the worker.

Manual deployment (if needed):

cd workers/osa-worker
wrangler deploy --env dev  # for develop branch
wrangler deploy            # for main branch

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Preview Deployment

Name Link
Preview URL https://feature-issue-701-host-api-d-demo.osc.earth
Branch feature/issue-701-host-api-dialog
Commit 55aaf0f

This preview will be updated automatically when you push new commits.

…dow first; test, docs and changelog (tested: notebook-entry suite fails without the fix, all widget suites, center-stage harness in Chrome)
…lls input listeners when the draft returns (tested: host-api suite, all widget suites)
@neuromechanist

Copy link
Copy Markdown
Member Author

Review round 2, outcomes (fix commits on this branch):

  • Important, dialog over the notebook tab (setTab, ~line 17039): fixed. setTab now docks the window (applyHostMode(container, 'corner'), plus the modechange event) when the notebook tab opens while the dialog is up, so the Continue in notebook and Open notebook buttons and the host-driven import all reach the notebook in the corner, with the page live again. The engageCenter comment and the docs sentence are now true; the focus-trap comment points at setTab. New cases in frontend/test-widget-notebook-entry.js (capsule community, Zarr dataset, the real card clicked from the dialog) assert the notebook tab is open, the window is docked with no dialog role, the page is not inert, the page hears modechange to corner, and the import still goes ahead. They fail with the fix removed (5 failures). Docs (docs/community-widget.md) and the changelog say so.
  • Suggestion, "waiting for init()" warning wording: fixed. The warning now reads "calls are waiting; OSAChatWidget.init() has not been called or did not finish building the widget", and the timer handle is cleared when it fires. The host-api test matches the new text.
  • Suggestion, ask() draft restore: fixed (the optional change). After the draft is put back, an input event is dispatched on the chat input so listeners that mirror it stay informed; the start field is still set directly so it is correct even before a listener exists.

Tested: all 27 widget suites in tests.yml pass (host-api 243 passed, notebook-entry 190 passed), frontend/browser-harness/center-stage-check.mjs in headless Chrome passes, tests/test_frontend/test_embed_snippet_hygiene.py 17 passed, ruff check clean. No Python changed.

@neuromechanist

Copy link
Copy Markdown
Member Author

PM verdict: ready. Acceptance criteria checked against the diff (host API suite, dialog and start-screen coverage, config validation and registry-wide https test, center-stage Chrome harness, CI wiring, docs and changelog); review rounds 1 and 2 have outcomes; branch updated with develop and every check passes. Merging (squash). This PR says 'Part of #701', so #701 stays open for PR 2.

@neuromechanist
neuromechanist merged commit 8fc86e7 into develop Nov 11, 2026
13 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-701-host-api-dialog branch November 11, 2026 09:36
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