-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathone-line-chat-dashboard.html
More file actions
258 lines (240 loc) · 9.38 KB
/
one-line-chat-dashboard.html
File metadata and controls
258 lines (240 loc) · 9.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Renderify Killer Demo: One-Line Chat Dashboard</title>
<style>
:root {
--bg: #f4f7fb;
--panel: #ffffff;
--ink: #152339;
--muted: #5d6f86;
--line: #d8e1ec;
--accent: #0f766e;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
background: radial-gradient(circle at 5% 10%, #d8f4ef 0, var(--bg) 42%);
color: var(--ink);
font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
}
.page {
max-width: 1120px;
margin: 0 auto;
padding: 20px;
}
.headline {
margin: 0 0 8px;
font-size: 26px;
}
.hint {
margin: 0 0 14px;
color: var(--muted);
}
.layout {
display: grid;
grid-template-columns: 320px 1fr;
gap: 14px;
}
.panel {
background: var(--panel);
border: 1px solid var(--line);
border-radius: 12px;
padding: 14px;
}
.chat-bubble {
border-radius: 12px;
background: #edf3fb;
padding: 10px;
color: #21344f;
margin-bottom: 10px;
}
.mount {
min-height: 360px;
border: 1px dashed #bfd5cb;
border-radius: 12px;
padding: 10px;
background: #fbfffe;
}
.status {
margin-top: 8px;
color: var(--muted);
font-size: 13px;
}
pre {
margin: 0;
max-height: 220px;
overflow: auto;
border-radius: 8px;
padding: 10px;
background: #0e1e33;
color: #d8e8ff;
font-size: 12px;
}
@media (max-width: 960px) {
.layout {
grid-template-columns: 1fr;
}
}
</style>
</head>
<body>
<div class="page">
<h1 class="headline">One-Line Embed: AI Chat Dashboard</h1>
<p class="hint">
Goal: drop a single call into chat UI and render a fully interactive dashboard.
</p>
<div class="layout">
<section class="panel">
<div class="chat-bubble">
User: Build an analytics dashboard with KPI toggles and a multi-point bar chart.
</div>
<div class="chat-bubble">
Assistant emitted RuntimePlan + TSX source. Render through the trusted source lane.
</div>
<pre id="apiSnippet"></pre>
<div id="status" class="status">Rendering...</div>
</section>
<section class="panel">
<div id="mount" class="mount"></div>
</section>
</div>
</div>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script type="importmap">
{
"imports": {
"@renderify/ir": "../../packages/ir/dist/ir.esm.js",
"@renderify/security": "../../packages/security/dist/security.esm.js",
"es-module-lexer": "https://ga.jspm.io/npm:es-module-lexer@1.7.0/dist/lexer.js",
"preact": "https://ga.jspm.io/npm:preact@10.28.3/dist/preact.module.js",
"preact/hooks": "https://ga.jspm.io/npm:preact@10.28.3/hooks/dist/hooks.module.js",
"preact/jsx-runtime": "https://ga.jspm.io/npm:preact@10.28.3/jsx-runtime/dist/jsxRuntime.module.js",
"preact-render-to-string": "https://ga.jspm.io/npm:preact-render-to-string@6.6.5/dist/index.module.js"
}
}
</script>
<script type="module">
import { renderTrustedPlanInBrowser } from "../../packages/runtime/dist/runtime.esm.js";
const plan = {
specVersion: "runtime-plan/v1",
id: "killer_chat_dashboard",
version: 1,
root: { type: "text", value: "loading" },
capabilities: {
domWrite: true,
allowedModules: ["preact", "preact/hooks"],
maxExecutionMs: 5000,
},
imports: ["preact", "preact/hooks"],
moduleManifest: {
preact: {
resolvedUrl: "https://ga.jspm.io/npm:preact@10.28.3/dist/preact.module.js",
signer: "examples",
},
"preact/hooks": {
resolvedUrl: "https://ga.jspm.io/npm:preact@10.28.3/hooks/dist/hooks.module.js",
signer: "examples",
},
"preact/jsx-runtime": {
resolvedUrl: "https://ga.jspm.io/npm:preact@10.28.3/jsx-runtime/dist/jsxRuntime.module.js",
signer: "examples",
},
},
source: {
language: "tsx",
runtime: "preact",
exportName: "default",
code: [
"import { h } from 'preact';",
"import { useMemo, useState } from 'preact/hooks';",
"",
"export default function Dashboard() {",
" const [metric, setMetric] = useState('revenue');",
" const data = useMemo(() => [",
" { day: 'Mon', revenue: 120, users: 44 },",
" { day: 'Tue', revenue: 176, users: 58 },",
" { day: 'Wed', revenue: 148, users: 52 },",
" { day: 'Thu', revenue: 222, users: 74 },",
" { day: 'Fri', revenue: 261, users: 91 },",
" { day: 'Sat', revenue: 238, users: 87 },",
" { day: 'Sun', revenue: 312, users: 119 },",
" { day: 'Mon+', revenue: 286, users: 102 },",
" { day: 'Tue+', revenue: 334, users: 128 },",
" ], []);",
" const key = metric === 'revenue' ? 'revenue' : 'users';",
" const width = 620;",
" const height = 310;",
" const pad = 30;",
" const chartHeight = height - pad * 2;",
" const chartWidth = width - pad * 2;",
" const max = Math.max(...data.map((entry) => entry[key]));",
" const gap = 8;",
" const barWidth = Math.max(10, chartWidth / data.length - gap);",
" const bars = data.map((entry, index) => {",
" const value = entry[key];",
" const x = pad + index * (barWidth + gap);",
" const barHeight = (value / Math.max(1, max)) * chartHeight;",
" const y = height - pad - barHeight;",
" return { x, y, barHeight, day: entry.day, value };",
" });",
" const axisTicks = 4;",
" return (",
" <section style={{ fontFamily: 'IBM Plex Sans, sans-serif' }}>",
" <h2 style={{ margin: '0 0 6px' }}>Revenue Assistant Dashboard</h2>",
" <p style={{ marginTop: 0, color: '#4b5f79' }}>Generated by LLM, rendered by Renderify runtime.</p>",
" <div style={{ display: 'flex', gap: 8, marginBottom: 12 }}>",
" <button type='button' onClick={() => setMetric('revenue')}>Revenue</button>",
" <button type='button' onClick={() => setMetric('users')}>Users</button>",
" </div>",
" <div style={{ overflowX: 'auto' }}>",
" <svg width={width} height={height} viewBox={`0 0 ${width} ${height}`} role='img' aria-label='Metric bar chart'>",
" {Array.from({ length: axisTicks + 1 }).map((_, tickIndex) => {",
" const y = pad + (tickIndex * chartHeight) / axisTicks;",
" return <line key={`grid-${tickIndex}`} x1={pad} y1={y} x2={width - pad} y2={y} stroke='#e6edf7' strokeDasharray='4 4' />;",
" })}",
" <line x1={pad} y1={height - pad} x2={width - pad} y2={height - pad} stroke='#d1d8e6' />",
" <line x1={pad} y1={pad} x2={pad} y2={height - pad} stroke='#d1d8e6' />",
" {bars.map((bar) => (",
" <g key={bar.day}>",
" <rect",
" x={bar.x}",
" y={bar.y}",
" width={barWidth}",
" height={bar.barHeight}",
" rx={6}",
" fill={metric === 'revenue' ? '#0f766e' : '#1d4ed8'}",
" opacity={0.9}",
" />",
" <text x={bar.x + barWidth / 2} y={height - 9} textAnchor='middle' fontSize='11' fill='#5c6f88'>{bar.day}</text>",
" <text x={bar.x + barWidth / 2} y={Math.max(pad + 12, bar.y - 6)} textAnchor='middle' fontSize='11' fill='#2a3f58'>{bar.value}</text>",
" </g>",
" ))}",
" </svg>",
" </div>",
" <p style={{ marginBottom: 0 }}>Current metric: <strong>{metric}</strong> · Data points: <strong>{data.length}</strong></p>",
" </section>",
" );",
"}",
].join("\n"),
},
};
const statusEl = document.getElementById("status");
const snippetEl = document.getElementById("apiSnippet");
snippetEl.textContent =
"await renderTrustedPlanInBrowser(plan, { target: '#mount' });";
(async () => {
try {
await renderTrustedPlanInBrowser(plan, { target: "#mount" });
statusEl.textContent = "Rendered with trusted one-line API.";
} catch (error) {
statusEl.textContent = `Render failed: ${error?.message ?? String(error)}`;
}
})();
</script>
</body>
</html>