[OPIK-6425] [FE] feat: add Explain bridge contract + AssistantStore#7130
Closed
awkoy wants to merge 1 commit into
Closed
[OPIK-6425] [FE] feat: add Explain bridge contract + AssistantStore#7130awkoy wants to merge 1 commit into
awkoy wants to merge 1 commit into
Conversation
Implements the opik-frontend "Explain" bridge slice (G1, G1b, FE-1a, FE-1b, FE-2). Host-side foundation only; no user-facing UI yet. - Bridge contract: 7 explain/chat/console events + ExplainTarget in assistant-sidebar.ts; bump BRIDGE_PROTOCOL_VERSION 1->2; wire createHostListeners() + console:ready/explain:* handlers in the comet AssistantSidebar. Must stay byte-identical with ollie-console. - AssistantStore (zustand): console lifecycle status incl. 'waking', capabilities from console:ready, queued emitToConsole (flush on ready), explain state keyed by explainId, runExplain/cancelExplain/clearExplain with concurrency cap 3, ownership-guarded emit registration. - FE-1a: migrate sidebar open/width from PageLayout useState into the store, seeded from the same localStorage keys the console writes. - VER-4: compile-time contract assertion (tsc fails on a missing event) + runtime emitHostEvent dispatch smoke test. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment on lines
+201
to
+205
| clearExplain: (explainId) => { | ||
| set((s) => { | ||
| if (!s.explains[explainId]) return s; | ||
| const next = { ...s.explains }; | ||
| delete next[explainId]; |
Contributor
There was a problem hiding this comment.
clearExplain duplicates the state-removal block in cancelExplain, should we extract it into a shared helper or call it from cancelExplain after emitToConsole?
Want Baz to fix this for you? Activate Fixer
Comment on lines
+211
to
+213
| applyConsoleReady: ({ capabilities }) => { | ||
| const { consoleEmit, emitQueue } = get(); | ||
| set({ status: "ready", capabilities, emitQueue: [] }); |
Contributor
There was a problem hiding this comment.
applyConsoleReady should gate console:ready on bridgeVersion matching BRIDGE_PROTOCOL_VERSION, otherwise a mismatched console can still become ready and receive queued explain:*/chat:continue events.
Want Baz to fix this for you? Activate Fixer
Other fix methods
Prompt for AI Agents
Before applying, verify this suggestion against the current code. In
apps/opik-frontend/src/store/AssistantStore.ts around lines 211-220, in the
applyConsoleReady logic, gate the transition to status "ready" and the flushing of
emitQueue on the incoming console:ready payload’s bridgeVersion matching the expected
bridge protocol (BRIDGE_PROTOCOL_VERSION). Refactor applyConsoleReady to first read
bridgeVersion from the payload, compare it to the frontend’s expected version (or an
allowed range), and only then set status/capabilities and flush the queue; otherwise set
status to "error" or "unavailable" and clear or retain emitQueue so mismatched consoles
don’t receive explain:run/chat:continue events. Update imports/types as needed so
BRIDGE_PROTOCOL_VERSION is available in this store and bridgeVersion is correctly typed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Details
Implements the opik-frontend "Explain" bridge slice of OPIK-6425 (G1, G1b, FE-1a, FE-1b, FE-2). This lands the host-side foundation the Explain popover/cells build on; there is no user-facing UI yet (FE-3/FE-4/FE-5 follow). Frontend-only — no backend, migrations, or
v1changes.explain:run/cancel,chat:continue,console:ready,explain:chunk/done/error) +ExplainTargettoassistant-sidebar.ts, bumpsBRIDGE_PROTOCOL_VERSION1→2, and wirescreateHostListeners()+ theconsole:ready/explain:*handlers in the cometAssistantSidebar. Must stay byte-identical withollie-console/src/bridge.ts(separate repo; the mirror lands in lockstep).waking),capabilitiesfromconsole:ready, a queuedemitToConsolethat flushes on ready, per-explainIdstream state,runExplain/cancelExplain/clearExplainwith a hard concurrency cap of 3, and ownership-guarded emit registration (mirrors thewindow.opikBridgeguard for the sidebar↔OlliePage instance switch).PageLayoutuseStateinto the store, seeded from the sameassistant-sidebar-open/-widthlocalStorage keys the console writes (survives refresh/remount). Nav-sidebar key (sidebar-expanded) untouched.tsc --noEmitfails if any event key is missing from either map) + a runtimeemitHostEventdispatch smoke test.Out of scope (follow-ups): FE-3 ExplainButton/Popover, FE-4 Error-cell wiring, FE-5 BI events, the G3
EXPLAIN_ENABLEDflag, and theollie-console/ollie-assistrepo changes.Change checklist
Issues
AI-WATERMARK
AI-WATERMARK: yes
Testing
Commands (from
apps/opik-frontend):npm run typecheck— cleannpx vitest run src/store/AssistantStore.test.ts src/plugins/comet/AssistantSidebar.bridge.test.ts— 23 passingnpx eslinton all changed files — 0 problemsScenarios validated (unit, happy-dom):
console:readypromotes status toreadyand stores capabilities.emitToConsolebuffers before ready and flushes in order onceconsole:readyarrives.unregisteris a no-op; the owner'sunregistertears down the channel/status and drops in-flight explains (cap-slot leak fix).runExplainreturnsnullat cap; a finished or cancelled explain frees a slot.explainIdis ignored on chunk/done/error (cancel race).tscfails when an event key is removed (then restored);emitHostEventdispatches each new host event to subscribers with no cross-delivery.Regression check: a full
npx vitest runshows only 2 pre-existing failing files (src/lib/ls-migrations/*, alocalStorage.clearenv quirk) that fail identically onmain. This change adds 23 passing tests and introduces no regressions.Not run: Playwright E2E (VER-9) and cross-repo INT-1 — they depend on the
ollie-consolemirror + UI (FE-3+), which are out of this PR's scope.Documentation
N/A — no user-facing docs change (internal host bridge + zustand store only).
🤖 Generated with Claude Code