-
Notifications
You must be signed in to change notification settings - Fork 213
feat: custom chart plugins ("vibe coded charts") #945
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
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b856e1e
feat(shared): add custom chart plugin contract and relax chart_type
cursoragent 5ed0e0e
feat(backend): discover, serve, and hot-reload custom chart plugins
cursoragent 0acaa40
feat(frontend): render custom chart plugins with hot reload
cursoragent b60976e
docs: add example chart plugins and chart-plugins skill
cursoragent c4d4337
fix(frontend): open chart plugin hot-reload stream on subscribe
cursoragent a06cf59
Add more example and features to try + sse rendering of custom charts
Bl3f 463d39a
Add missing files
Bl3f b621e16
fix(charts): address PR review comments for custom chart plugins
cursoragent 066f32b
fix(charts): scope chart plugins per-project and block symlink traversal
cursoragent a8c2737
style: fix prettier formatting in chat-input.tsx
cursoragent b443c5b
fix(charts): sandbox server-side plugin network egress and tighten sy…
cursoragent ab39020
docs(skills): publish custom-charts skill in skills/ registry
cursoragent 179b443
fix(charts): detect IPv4-mapped/compatible IPv6 forms in SSRF guard
cursoragent 6c62340
fix(charts): pin resolved IP via proxy to close DNS-rebinding SSRF gap
cursoragent 45899d3
Merge origin/main into chart-plugins-system
cursoragent 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import type { ChartPluginManifest } from '@nao/shared'; | ||
| import type { FastifyRequest } from 'fastify'; | ||
| import { z } from 'zod/v4'; | ||
|
|
||
| import type { App } from '../app'; | ||
| import { chartHotReloadEnabled } from '../env'; | ||
| import { authMiddleware } from '../middleware/auth'; | ||
| import { type ChartPluginReloadEvent, chartPluginService } from '../services/chart-plugin.service'; | ||
| import { HandlerError } from '../utils/error'; | ||
|
|
||
| const fileParamsSchema = z.object({ | ||
| file: z.string().regex(/^[a-zA-Z0-9_-]+\.(js|mjs)$/, 'Invalid plugin file name'), | ||
| }); | ||
|
|
||
| /** | ||
| * Serves custom chart plugins to the frontend (authenticated; the plugin set is | ||
| * scoped to the requester's project): | ||
| * - `GET /api/charts/plugins` — manifest of available plugins | ||
| * - `GET /api/charts/plugins/:file` — a plugin's ES module source | ||
| * - `GET /api/charts/events` — SSE stream of hot-reload events | ||
| */ | ||
| export const chartPluginRoutes = async (app: App) => { | ||
| app.addHook('preHandler', authMiddleware); | ||
|
|
||
| app.get('/plugins', async (request): Promise<ChartPluginManifest> => { | ||
| const projectId = await ensureInitialized(request); | ||
| const plugins = chartPluginService.getPlugins(projectId).map(({ type, name, description, url }) => ({ | ||
| type, | ||
| name, | ||
| description, | ||
| url, | ||
| })); | ||
| return { plugins, version: chartPluginService.getVersion(projectId), hotReload: chartHotReloadEnabled }; | ||
| }); | ||
|
|
||
| app.get('/plugins/:file', { schema: { params: fileParamsSchema } }, async (request, reply) => { | ||
| const projectId = await ensureInitialized(request); | ||
| const type = request.params.file.replace(/\.[^.]+$/, ''); | ||
| const source = chartPluginService.getPluginSource(projectId, type); | ||
| if (source === null) { | ||
| throw new HandlerError('NOT_FOUND', `Chart plugin "${type}" not found`); | ||
| } | ||
| return reply | ||
| .header('Content-Type', 'text/javascript; charset=utf-8') | ||
| .header('Cache-Control', 'no-store') | ||
| .send(source); | ||
| }); | ||
|
|
||
| app.get('/events', async (request, reply) => { | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| if (!chartHotReloadEnabled) { | ||
| return reply.status(204).send(); | ||
| } | ||
|
|
||
| const projectId = await ensureInitialized(request); | ||
|
|
||
| reply.raw.writeHead(200, { | ||
| 'Content-Type': 'text/event-stream', | ||
| 'Cache-Control': 'no-cache, no-transform', | ||
| Connection: 'keep-alive', | ||
| }); | ||
| reply.raw.write(`event: ready\ndata: ${chartPluginService.getVersion(projectId)}\n\n`); | ||
|
|
||
| const onReload = ({ projectId: changedProjectId, version }: ChartPluginReloadEvent) => { | ||
| if (changedProjectId !== projectId) { | ||
| return; | ||
| } | ||
| reply.raw.write(`event: reload\ndata: ${version}\n\n`); | ||
| }; | ||
| chartPluginService.on('reload', onReload); | ||
|
|
||
| const heartbeat = setInterval(() => { | ||
| reply.raw.write(': ping\n\n'); | ||
| }, 25_000); | ||
|
|
||
| request.raw.on('close', () => { | ||
| clearInterval(heartbeat); | ||
| chartPluginService.off('reload', onReload); | ||
| }); | ||
|
|
||
| return reply.hijack(); | ||
| }); | ||
| }; | ||
|
|
||
| /** | ||
| * Lazily initializes the plugin service against the authenticated request's | ||
| * project so plugin source is only served for projects the caller can access. | ||
| * Returns the resolved project id to scope every subsequent read. | ||
| */ | ||
| async function ensureInitialized(request: FastifyRequest): Promise<string> { | ||
| if (!request.project) { | ||
| throw new HandlerError('NOT_FOUND', 'No project configured for this user'); | ||
| } | ||
| const projectId = request.project.id; | ||
| await chartPluginService.initialize(projectId); | ||
| return projectId; | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.