Skip to content

feat: render vis code blocks as charts with GPT-Vis - #6945

Open
Rutvij97 wants to merge 1 commit into
ChatGPTNextWeb:mainfrom
Rutvij97:feat/vis-chart-code-blocks
Open

Rutvij97 wants to merge 1 commit into
ChatGPTNextWeb:mainfrom
Rutvij97:feat/vis-chart-code-blocks

Conversation

@Rutvij97

Copy link
Copy Markdown

💻 变更类型 | Change Type

  • feat
  • fix
  • refactor
  • perf
  • style
  • test
  • docs
  • ci
  • chore
  • build

🔀 变更说明 | Description of Change

Closes #6791.

Renders ```vis code blocks as data charts using GPT-Vis (@antv/gpt-vis, MIT), following the existing mermaid pattern in PreCode: the code block stays visible and the chart is shown below it.

  • app/components/vis-chart.tsx: new VisChart component. It loads @antv/gpt-vis with a dynamic import() only when a vis block is present, renders the block, destroys the chart on unmount or re-render, and hides itself (leaving the plain code block) if the syntax is invalid or rendering fails.
  • app/utils/vis.ts: dependency-free isVisSyntax() (so detection never pulls in the library) and getVisTheme(), which maps the app theme (light / dark / auto + prefers-color-scheme) to the GPT-Vis default / dark theme. Switching the theme re-renders the chart.
  • app/components/markdown.tsx: detect code.language-vis in the same debounced renderArtifacts pass as mermaid.
  • app/styles/markdown.scss: give the chart container a usable width (600px, capped at 100%) so it does not collapse to the width of a short code block.

Bundle size: the first-load JS is unchanged (/ stays at 626 kB / 716 kB first load in yarn build). GPT-Vis and its G2/G6 dependencies are split into lazy chunks (~2.5 MB raw, ~710 kB gzip) that are fetched only the first time a vis block is rendered.

📝 补充信息 | Additional Information

Tested locally (Node 22.17, yarn 1.22.19):

  • yarn test:ci: 38 suites, 182 tests passed (adds test/vis.test.ts and test/vis-chart.test.tsx, which mocks @antv/gpt-vis and covers render, theme, destroy on unmount, error fallback and non-vis input).
  • npx tsc --noEmit -p .: passed.
  • npx eslint and npx prettier --check on the changed files: no errors (the only warning is the existing exhaustive-deps warning on PreCode).
  • yarn build: passed, route sizes as above.
  • Manual check with next start: a vis line block renders a chart in light and dark theme and follows a live theme switch; an invalid block (vis notachart) shows only the code block and logs [Vis] Unsupported chart type.

Pre-existing on main, unchanged by this PR: yarn lint (next lint) crashes in unused-imports/no-unused-imports on app/constant.ts, and yarn export fails with "Server Actions are not supported with static export".

This branch has not been deployed

No deployments
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.

[Feature Request] 在对话中直接渲染 AI 生成的数据图表(vis 代码块)

1 participant