-
Notifications
You must be signed in to change notification settings - Fork 3.3k
feat(intelligence): add architecture diagram viewer #2687
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
sanil-23
merged 7 commits into
tinyhumansai:main
from
sunilkumarvalmiki:codex/OH-1854-diagram-viewer
May 28, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9d508cb
feat(intelligence): add architecture diagram viewer
sunilkumarvalmiki f9931b8
Merge branch 'main' into pr/2687
sanil-23 4cf6c32
chore(pr-fix): sync app/src-tauri/Cargo.lock after merge
sanil-23 0fdf860
Merge remote-tracking branch 'upstream/main' into pr/2687
sanil-23 1ef6dec
Merge remote-tracking branch 'upstream/main' into pr/2687
sanil-23 4ac7378
Merge remote-tracking branch 'upstream/main' into pr/2687
sanil-23 234cae1
Merge remote-tracking branch 'upstream/main' into pr/2687
sanil-23 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { fireEvent, screen } from '@testing-library/react'; | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import { renderWithProviders } from '../../test/test-utils'; | ||
| import DiagramViewerTab, { buildDiagramImageUrl } from './DiagramViewerTab'; | ||
|
|
||
| vi.mock('../../utils/tauriCommands/config', () => ({ | ||
| openhumanGetDashboardSettings: vi | ||
| .fn() | ||
| .mockResolvedValue({ | ||
| result: { | ||
| diagram_viewer: { | ||
| enabled: true, | ||
| source_url: 'http://localhost:8787/workspace/diagrams/latest.png', | ||
| refresh_interval_seconds: 10, | ||
| }, | ||
| }, | ||
| logs: [], | ||
| }), | ||
| })); | ||
|
|
||
| describe('buildDiagramImageUrl', () => { | ||
| it('adds a cache-busting refresh parameter to absolute URLs', () => { | ||
| expect(buildDiagramImageUrl('http://localhost:8787/latest.png?format=png', 4)).toBe( | ||
| 'http://localhost:8787/latest.png?format=png&openhuman_refresh=4' | ||
| ); | ||
| }); | ||
|
|
||
| it('adds a cache-busting refresh parameter to relative URLs', () => { | ||
| expect(buildDiagramImageUrl('/workspace/diagrams/latest.png', 2)).toBe( | ||
| '/workspace/diagrams/latest.png?openhuman_refresh=2' | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('DiagramViewerTab', () => { | ||
| it('refreshes the diagram image URL on demand', async () => { | ||
| renderWithProviders(<DiagramViewerTab />); | ||
|
|
||
| const image = await screen.findByRole('img', { | ||
| name: 'Latest generated OpenHuman architecture diagram', | ||
| }); | ||
| expect(image).toHaveAttribute('src', expect.stringContaining('openhuman_refresh=0')); | ||
|
|
||
| fireEvent.click(screen.getByRole('button', { name: 'Refresh diagram' })); | ||
|
|
||
| expect( | ||
| screen.getByRole('img', { name: 'Latest generated OpenHuman architecture diagram' }) | ||
| ).toHaveAttribute('src', expect.stringContaining('openhuman_refresh=1')); | ||
| }); | ||
|
|
||
| it('shows an empty state instead of a broken image after load failure', async () => { | ||
| renderWithProviders(<DiagramViewerTab />); | ||
|
|
||
| const image = await screen.findByRole('img', { | ||
| name: 'Latest generated OpenHuman architecture diagram', | ||
| }); | ||
| fireEvent.error(image); | ||
|
|
||
| expect(screen.getByText('No diagram available yet')).toBeInTheDocument(); | ||
| expect( | ||
| screen.getByText('npx skills add yizhiyanhua-ai/fireworks-tech-graph') | ||
| ).toBeInTheDocument(); | ||
| expect( | ||
| screen.getByText( | ||
| 'Generate an architecture diagram of the current swarm in dark terminal style' | ||
| ) | ||
| ).toBeInTheDocument(); | ||
| expect( | ||
| screen.queryByRole('img', { name: 'Latest generated OpenHuman architecture diagram' }) | ||
| ).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
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,160 @@ | ||
| import { useCallback, useEffect, useMemo, useState } from 'react'; | ||
| import { LuImage, LuRefreshCw } from 'react-icons/lu'; | ||
|
|
||
| import { useT } from '../../lib/i18n/I18nContext'; | ||
| import { | ||
| type DiagramViewerSettings, | ||
| openhumanGetDashboardSettings, | ||
| } from '../../utils/tauriCommands/config'; | ||
|
|
||
| const DEFAULT_SETTINGS: DiagramViewerSettings = { | ||
| enabled: true, | ||
| source_url: 'http://localhost:8787/workspace/diagrams/latest.png', | ||
| refresh_interval_seconds: 10, | ||
| }; | ||
|
|
||
| type ImageState = 'idle' | 'loaded' | 'error'; | ||
|
|
||
| function normalizeSettings( | ||
| settings?: Partial<DiagramViewerSettings> | null | ||
| ): DiagramViewerSettings { | ||
| const sourceUrl = settings?.source_url?.trim() || DEFAULT_SETTINGS.source_url; | ||
| const refreshInterval = Number(settings?.refresh_interval_seconds); | ||
|
|
||
| return { | ||
| enabled: settings?.enabled ?? DEFAULT_SETTINGS.enabled, | ||
| source_url: sourceUrl, | ||
| refresh_interval_seconds: | ||
| Number.isFinite(refreshInterval) && refreshInterval > 0 | ||
| ? Math.round(refreshInterval) | ||
| : DEFAULT_SETTINGS.refresh_interval_seconds, | ||
| }; | ||
| } | ||
|
|
||
| export function buildDiagramImageUrl(sourceUrl: string, refreshKey: number): string { | ||
| try { | ||
| const url = new URL(sourceUrl); | ||
| url.searchParams.set('openhuman_refresh', String(refreshKey)); | ||
| return url.toString(); | ||
| } catch { | ||
| const separator = sourceUrl.includes('?') ? '&' : '?'; | ||
| return `${sourceUrl}${separator}openhuman_refresh=${refreshKey}`; | ||
| } | ||
| } | ||
|
|
||
| export default function DiagramViewerTab() { | ||
| const { t } = useT(); | ||
| const [settings, setSettings] = useState<DiagramViewerSettings>(DEFAULT_SETTINGS); | ||
| const [refreshKey, setRefreshKey] = useState(0); | ||
| const [imageState, setImageState] = useState<ImageState>('idle'); | ||
|
|
||
| useEffect(() => { | ||
| let alive = true; | ||
|
|
||
| openhumanGetDashboardSettings() | ||
| .then(response => { | ||
| if (!alive) return; | ||
| setSettings(normalizeSettings(response.result.diagram_viewer)); | ||
| }) | ||
| .catch(() => { | ||
| if (!alive) return; | ||
| setSettings(DEFAULT_SETTINGS); | ||
| }); | ||
|
|
||
| return () => { | ||
| alive = false; | ||
| }; | ||
| }, []); | ||
|
|
||
| const refreshDiagram = useCallback(() => { | ||
| setImageState('idle'); | ||
| setRefreshKey(prev => prev + 1); | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| if (!settings.enabled || settings.refresh_interval_seconds <= 0) return undefined; | ||
|
|
||
| const interval = window.setInterval(refreshDiagram, settings.refresh_interval_seconds * 1000); | ||
| return () => window.clearInterval(interval); | ||
| }, [refreshDiagram, settings.enabled, settings.refresh_interval_seconds]); | ||
|
|
||
| const sourceUrl = settings.source_url.trim(); | ||
| const imageUrl = useMemo( | ||
| () => (sourceUrl ? buildDiagramImageUrl(sourceUrl, refreshKey) : ''), | ||
| [refreshKey, sourceUrl] | ||
| ); | ||
|
|
||
| const showImage = settings.enabled && sourceUrl.length > 0 && imageState !== 'error'; | ||
| const showEmptyState = !settings.enabled || sourceUrl.length === 0 || imageState === 'error'; | ||
|
|
||
| return ( | ||
| <section className="space-y-5" aria-labelledby="diagram-viewer-title"> | ||
| <div className="flex flex-wrap items-start justify-between gap-3"> | ||
| <div> | ||
| <h2 | ||
| id="diagram-viewer-title" | ||
| className="text-lg font-semibold text-stone-900 dark:text-neutral-100"> | ||
| {t('intelligence.diagram.title')} | ||
| </h2> | ||
| <p className="mt-1 text-sm text-stone-500 dark:text-neutral-400"> | ||
| {t('intelligence.diagram.description')} | ||
| </p> | ||
| </div> | ||
| <button | ||
| type="button" | ||
| onClick={refreshDiagram} | ||
| className="inline-flex items-center gap-2 rounded-md border border-stone-200 bg-white px-3 py-2 text-sm font-medium text-stone-700 transition-colors hover:bg-stone-50 dark:border-neutral-700 dark:bg-neutral-900 dark:text-neutral-200 dark:hover:bg-neutral-800" | ||
| aria-label={t('intelligence.diagram.refreshAria')}> | ||
| <LuRefreshCw aria-hidden="true" className="h-4 w-4" /> | ||
| {t('intelligence.diagram.refresh')} | ||
| </button> | ||
| </div> | ||
|
|
||
| {showEmptyState && ( | ||
| <div className="flex min-h-72 flex-col items-center justify-center gap-3 rounded-lg border border-dashed border-stone-300 bg-stone-50 px-6 py-10 text-center dark:border-neutral-700 dark:bg-neutral-950/60"> | ||
| <div className="flex h-12 w-12 items-center justify-center rounded-full bg-primary-50 text-primary-600 dark:bg-primary-500/10 dark:text-primary-300"> | ||
| <LuImage aria-hidden="true" className="h-6 w-6" /> | ||
| </div> | ||
| <div> | ||
| <h3 className="text-sm font-semibold text-stone-900 dark:text-neutral-100"> | ||
| {t('intelligence.diagram.emptyTitle')} | ||
| </h3> | ||
| <p className="mt-1 max-w-md text-sm text-stone-500 dark:text-neutral-400"> | ||
| {t('intelligence.diagram.emptyDescription')} | ||
| </p> | ||
| </div> | ||
| <div className="flex max-w-full flex-col gap-2"> | ||
| <code className="max-w-full overflow-x-auto rounded-md bg-white px-3 py-2 text-xs text-stone-600 dark:bg-neutral-900 dark:text-neutral-300"> | ||
| {t('intelligence.diagram.skillInstallCommand')} | ||
| </code> | ||
| <code className="max-w-full overflow-x-auto rounded-md bg-white px-3 py-2 text-xs text-stone-600 dark:bg-neutral-900 dark:text-neutral-300"> | ||
| {t('intelligence.diagram.promptExample')} | ||
| </code> | ||
| </div> | ||
| </div> | ||
| )} | ||
|
|
||
| {showImage && ( | ||
| <figure className="space-y-3"> | ||
| <img | ||
| key={imageUrl} | ||
| src={imageUrl} | ||
| alt={t('intelligence.diagram.imageAlt')} | ||
| className="block w-full rounded-lg border border-stone-200 bg-white object-contain dark:border-neutral-800 dark:bg-neutral-950" | ||
| onLoad={() => setImageState('loaded')} | ||
| onError={() => setImageState('error')} | ||
| /> | ||
| <figcaption className="flex flex-wrap items-center justify-between gap-2 text-xs text-stone-500 dark:text-neutral-400"> | ||
| <span> | ||
| {t('intelligence.diagram.refreshesEvery').replace( | ||
| '{seconds}', | ||
| String(settings.refresh_interval_seconds) | ||
| )} | ||
| </span> | ||
| <span className="max-w-full truncate">{sourceUrl}</span> | ||
| </figcaption> | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| </figure> | ||
| )} | ||
| </section> | ||
| ); | ||
| } | ||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[minor] Manual
{seconds}substitution is fragile — a translator typo on the placeholder breaks this silently. If there's a standard interpolation helper inuseT()or the i18n layer, use that instead. If not, at least assert the placeholder exists in the string in a test.