-
Notifications
You must be signed in to change notification settings - Fork 0
feat(observer): draw relayflow runs; carry message metadata on realtime events #450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
22a19c8
feat(observer): draw relayflow runs; carry message metadata on realti…
a1de55e
fix(observer): make relayflow live state monotonic
miyaontherelay e5c709c
docs: mark observer event changes as patch releases
miyaontherelay f4a1c56
test(observer-dashboard): compile JSX with the automatic runtime unde…
prpmdev-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
21 changes: 21 additions & 0 deletions
21
packages/observer-dashboard/src/components/RunPanel.test.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import React from 'react'; | ||
| import { renderToStaticMarkup } from 'react-dom/server'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { RunPanel } from './RunPanel'; | ||
|
|
||
| describe('RunPanel', () => { | ||
| it('renders each step state as text instead of relying on icon color', () => { | ||
| const html = renderToStaticMarkup(<RunPanel run={{ | ||
| runId: '01TEST', | ||
| flow: 'review', | ||
| status: 'running', | ||
| steps: [ | ||
| { id: 'inspect', type: 'deterministic', dependsOn: [], state: 'running' }, | ||
| { id: 'report', type: 'agent', dependsOn: ['inspect'], state: 'pending' }, | ||
| ], | ||
| }} />); | ||
|
|
||
| expect(html).toContain('running · deterministic'); | ||
| expect(html).toContain('pending · agent'); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| 'use client'; | ||
|
|
||
| import { CheckCircle2, ChevronRight, Circle, Loader2, PauseCircle, Workflow, XCircle } from 'lucide-react'; | ||
| import { cn } from '../lib/utils'; | ||
| import { stepColumns, type RelayflowRun, type RelayflowStep, type RelayflowStepState } from '../lib/relayflow-run'; | ||
|
|
||
| const STATE_STYLE: Record<RelayflowStepState, { icon: typeof Circle; tone: string }> = { | ||
| pending: { icon: Circle, tone: 'border-[var(--border-default)] text-[var(--text-faint)]' }, | ||
| running: { icon: Loader2, tone: 'border-[var(--brand-primary)] text-[var(--brand-primary-strong)] bg-[var(--brand-primary-faint)]' }, | ||
| completed: { icon: CheckCircle2, tone: 'border-[var(--status-success)] text-[var(--status-success)] bg-[var(--status-success-soft)]' }, | ||
| failed: { icon: XCircle, tone: 'border-[var(--status-danger)] text-[var(--status-danger)] bg-[var(--status-danger-soft)]' }, | ||
| parked: { icon: PauseCircle, tone: 'border-[var(--status-warning)] text-[var(--status-warning)] bg-[var(--status-warning-soft)]' }, | ||
| }; | ||
|
|
||
| const RUN_TONE: Record<string, string> = { | ||
| running: 'text-[var(--brand-primary-strong)]', | ||
| completed: 'text-[var(--status-success)]', | ||
| failed: 'text-[var(--status-danger)]', | ||
| canceled: 'text-[var(--status-danger)]', | ||
| parked: 'text-[var(--status-warning)]', | ||
| }; | ||
|
|
||
| /** The run's step graph, drawn from the newest snapshot its channel carries. */ | ||
| export function RunPanel({ run }: { run: RelayflowRun }) { | ||
| const done = run.steps.filter(step => step.state === 'completed').length; | ||
| const columns = stepColumns(run.steps); | ||
| return ( | ||
| <div className="sticky top-0 z-10 border-b border-[var(--border-default)] bg-[var(--surface-card)] px-5 py-3"> | ||
| <div className="flex flex-wrap items-center gap-2 text-sm"> | ||
| <Workflow className="h-4 w-4 text-[var(--brand-primary)]" /> | ||
| <span className="font-semibold text-[var(--foreground)]">{run.flow}</span> | ||
| <span className={cn('brand-pill text-[11px] font-medium uppercase tracking-[0.16em]', RUN_TONE[run.status])}> | ||
| {run.status} | ||
| </span> | ||
| {run.completionReason && run.completionReason !== 'success' && ( | ||
| <span className="text-xs text-[var(--status-danger)]">{run.completionReason}</span> | ||
| )} | ||
| <span className="ml-auto text-xs text-[var(--text-muted)]"> | ||
| {done}/{run.steps.length} steps · <span className="font-mono">{run.runId}</span> | ||
| </span> | ||
| </div> | ||
| {columns.length > 0 && ( | ||
| <div className="mt-3 flex items-start gap-2 overflow-x-auto pb-1"> | ||
| {columns.map((column, index) => ( | ||
| <div key={index} className="flex items-center gap-2"> | ||
| {index > 0 && <ChevronRight className="h-4 w-4 shrink-0 text-[var(--text-faint)]" />} | ||
| <div className="flex flex-col gap-1.5"> | ||
| {column.map(step => <StepChip key={step.id} step={step} />)} | ||
| </div> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| /** Render one step with a visible, screen-reader-readable state label. */ | ||
| function StepChip({ step }: { step: RelayflowStep }) { | ||
| const { icon: Icon, tone } = STATE_STYLE[step.state]; | ||
| const detail = [ | ||
| step.state, | ||
| step.type, | ||
| step.elapsedMs === undefined ? undefined : formatElapsed(step.elapsedMs), | ||
| step.attempt !== undefined && step.attempt > 1 ? `attempt ${step.attempt}` : undefined, | ||
| ].filter(Boolean).join(' · '); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| return ( | ||
| <div | ||
| className={cn('flex min-w-[9rem] items-center gap-2 rounded-xl border px-2.5 py-1.5', tone)} | ||
| title={step.completionReason ? `completionReason: ${step.completionReason}` : undefined} | ||
| > | ||
| <Icon className={cn('h-3.5 w-3.5 shrink-0', step.state === 'running' && 'animate-spin')} /> | ||
| <div className="min-w-0"> | ||
| <div className="truncate text-xs font-semibold text-[var(--foreground)]">{step.id}</div> | ||
| <div className="truncate text-[11px] opacity-80">{detail}</div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| /** Format a millisecond duration compactly for the run panel. */ | ||
| function formatElapsed(ms: number): string { | ||
| if (ms < 1_000) return `${ms}ms`; | ||
| if (ms < 60_000) return `${(ms / 1_000).toFixed(1)}s`; | ||
| return `${Math.floor(ms / 60_000)}m ${Math.round((ms % 60_000) / 1_000)}s`; | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import type { MessageWithMeta } from '@relaycast/sdk'; | ||
| import { latestRelayflowRun, stepColumns, type RelayflowStep } from './relayflow-run'; | ||
|
|
||
| /** Build a minimal persisted or realtime message for projection selection. */ | ||
| function message(id: string, createdAt: string, metadata?: Record<string, unknown>): MessageWithMeta { | ||
| return { | ||
| id, channelId: 'c', agentName: 'flow', agentId: 'a', text: 't', blocks: null, | ||
| ...(metadata ? { metadata } : {}), | ||
| hasAttachments: false, threadId: null, attachments: [], createdAt, replyCount: 0, reactions: [], readByCount: 0, | ||
| } as MessageWithMeta; | ||
| } | ||
|
|
||
| /** Build a valid single-step relayflow v1 snapshot. */ | ||
| function snapshot(status: string, state: string) { | ||
| return { relayflow: { version: 1, event: 'x', run: { | ||
| runId: 'R1', flow: 'hello', status, | ||
| steps: [{ id: 'greet', type: 'deterministic', dependsOn: [], state }], | ||
| } } }; | ||
| } | ||
|
|
||
| describe('latestRelayflowRun', () => { | ||
| it('returns the newest snapshot regardless of message order', () => { | ||
| const run = latestRelayflowRun([ | ||
| message('3', '2026-09-23T00:00:02.000Z', snapshot('completed', 'completed')), | ||
| message('1', '2026-09-23T00:00:00.000Z', snapshot('running', 'pending')), | ||
| message('2', '2026-09-23T00:00:01.000Z', snapshot('running', 'running')), | ||
| ]); | ||
| expect(run?.status).toBe('completed'); | ||
| expect(run?.steps[0]?.state).toBe('completed'); | ||
| }); | ||
|
|
||
| it('uses the later snowflake even when timestamps are skewed or replayed', () => { | ||
| const run = latestRelayflowRun([ | ||
| message('228601462569775105', '2026-09-23T00:00:00.000Z', snapshot('completed', 'completed')), | ||
| message('228601462569775104', '2026-09-23T00:05:00.000Z', snapshot('running', 'running')), | ||
| ]); | ||
| expect(run?.status).toBe('completed'); | ||
| }); | ||
|
|
||
| it('ignores ordinary messages and malformed or unknown-version metadata', () => { | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| expect(latestRelayflowRun([message('1', '2026-09-23T00:00:00.000Z')])).toBeNull(); | ||
| expect(latestRelayflowRun([message('1', '2026-09-23T00:00:00.000Z', { relayflow: { version: 2, run: {} } })])).toBeNull(); | ||
| expect(latestRelayflowRun([message('1', '2026-09-23T00:00:00.000Z', { relayflow: { version: 1, run: { runId: 1 } } })])).toBeNull(); | ||
| const run = latestRelayflowRun([message('1', '2026-09-23T00:00:00.000Z', { relayflow: { version: 1, run: { | ||
| runId: 'R', flow: 'f', status: 'running', steps: [{ id: 'ok', state: 'running' }, { id: 'bad', state: 'exploded' }, 7], | ||
| } } })]); | ||
| expect(run?.steps.map(step => step.id)).toEqual(['ok']); | ||
| }); | ||
|
|
||
| it('selects the newest valid snapshot across malformed messages', () => { | ||
| const run = latestRelayflowRun([ | ||
| message('228601462569775104', '2026-09-23T00:00:00.000Z', snapshot('running', 'running')), | ||
| message('228601462569775105', '2026-09-23T00:00:01.000Z', { relayflow: { version: 1, run: { runId: 7 } } }), | ||
| message('228601462569775106', '2026-09-23T00:00:02.000Z', snapshot('completed', 'completed')), | ||
| ]); | ||
| expect(run?.status).toBe('completed'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('stepColumns', () => { | ||
| const step = (id: string, dependsOn: string[] = []): RelayflowStep => ({ id, type: 'deterministic', dependsOn, state: 'pending' }); | ||
|
|
||
| it('groups steps by dependency depth in declaration order', () => { | ||
| const columns = stepColumns([step('a'), step('b'), step('c', ['a']), step('d', ['b', 'c'])]); | ||
| expect(columns.map(column => column.map(s => s.id))).toEqual([['a', 'b'], ['c'], ['d']]); | ||
| }); | ||
|
|
||
| it('puts every cycle member at depth zero and its dependents after it', () => { | ||
| const columns = stepColumns([ | ||
| step('x', ['missing']), | ||
| step('y', ['z']), | ||
| step('z', ['y']), | ||
| step('after-cycle', ['z']), | ||
| ]); | ||
| expect(columns.map(column => column.map(s => s.id))).toEqual([ | ||
| ['x', 'y', 'z'], | ||
| ['after-cycle'], | ||
| ]); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.