paseo-plugin-genui 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (375) hide show
  1. package/LICENSE +202 -0
  2. package/OVERVIEW.md +21 -0
  3. package/README.md +77 -2
  4. package/assets/fonts/Excalifont-OFL.txt +109 -0
  5. package/assets/fonts/Excalifont-Regular-latin.woff2 +0 -0
  6. package/assets/icon.png +0 -0
  7. package/assets/icon.svg +1 -0
  8. package/assets/screenshot-chat.png +0 -0
  9. package/assets/screenshot-gallery.png +0 -0
  10. package/assets/screenshot-playground.png +0 -0
  11. package/client/components/content.tsx +468 -0
  12. package/client/components/data.tsx +967 -0
  13. package/client/components/dev.tsx +998 -0
  14. package/client/components/diagram.tsx +513 -0
  15. package/client/components/inputs.tsx +994 -0
  16. package/client/components/layout.tsx +239 -0
  17. package/client/components/media.tsx +428 -0
  18. package/client/components/project.tsx +641 -0
  19. package/client/components/widgets.tsx +836 -0
  20. package/client/gallery.tsx +449 -0
  21. package/client/live-ui.tsx +525 -0
  22. package/client/loaders.ts +342 -0
  23. package/client/markdown.tsx +172 -0
  24. package/client/node-renderer.tsx +149 -0
  25. package/client/render.tsx +186 -0
  26. package/client/runtime.ts +103 -0
  27. package/client/settings.tsx +57 -0
  28. package/client/web.ts +186 -0
  29. package/gallery/Acceptance-baseline.ui +1 -0
  30. package/gallery/Acceptance-checklist.ui +14 -0
  31. package/gallery/Acceptance-evidence.ui +9 -0
  32. package/gallery/Acceptance.ui +1 -0
  33. package/gallery/Badge.ui +3 -0
  34. package/gallery/Benchmark-context.ui +8 -0
  35. package/gallery/Benchmark-hyperfine.ui +1 -0
  36. package/gallery/Benchmark-runs-list.ui +9 -0
  37. package/gallery/Benchmark-runs.ui +1 -0
  38. package/gallery/Benchmark-vitest.ui +1 -0
  39. package/gallery/Benchmark.ui +9 -0
  40. package/gallery/Board-bb-tasks.ui +1 -0
  41. package/gallery/Board-gh-issues.ui +1 -0
  42. package/gallery/Board-gh-prs.ui +1 -0
  43. package/gallery/Board.ui +12 -0
  44. package/gallery/Button-destructive.ui +4 -0
  45. package/gallery/Button.ui +5 -0
  46. package/gallery/Calendar.ui +15 -0
  47. package/gallery/CalendarHeatmap-short.ui +11 -0
  48. package/gallery/CalendarHeatmap.ui +4 -0
  49. package/gallery/Callout.ui +4 -0
  50. package/gallery/Card.ui +4 -0
  51. package/gallery/Carousel.ui +8 -0
  52. package/gallery/Changes-paths.ui +1 -0
  53. package/gallery/Changes-uncommitted.ui +1 -0
  54. package/gallery/Changes.ui +1 -0
  55. package/gallery/Chart-area.ui +3 -0
  56. package/gallery/Chart-funnel.ui +3 -0
  57. package/gallery/Chart-heatmap.ui +11 -0
  58. package/gallery/Chart-pie.ui +3 -0
  59. package/gallery/Chart-radar.ui +3 -0
  60. package/gallery/Chart-scatter.ui +4 -0
  61. package/gallery/Chart-stacked.ui +5 -0
  62. package/gallery/Chart.ui +3 -0
  63. package/gallery/Checklist.ui +6 -0
  64. package/gallery/Choice.ui +8 -0
  65. package/gallery/Code.ui +3 -0
  66. package/gallery/Commits-limit.ui +1 -0
  67. package/gallery/Commits.ui +1 -0
  68. package/gallery/Compare-conditions.ui +4 -0
  69. package/gallery/Compare-three.ui +7 -0
  70. package/gallery/Compare.ui +4 -0
  71. package/gallery/Coverage-go.ui +1 -0
  72. package/gallery/Coverage-lcov.ui +1 -0
  73. package/gallery/Coverage-python.ui +1 -0
  74. package/gallery/Coverage.ui +1 -0
  75. package/gallery/DateInput.ui +5 -0
  76. package/gallery/Decision-percent.ui +10 -0
  77. package/gallery/Decision.ui +12 -0
  78. package/gallery/Dependencies-audit.ui +1 -0
  79. package/gallery/Dependencies-both.ui +1 -0
  80. package/gallery/Dependencies-list.ui +7 -0
  81. package/gallery/Dependencies-pip.ui +1 -0
  82. package/gallery/Dependencies-pnpm.ui +1 -0
  83. package/gallery/Dependencies.ui +1 -0
  84. package/gallery/Details.ui +4 -0
  85. package/gallery/Diagram-flow.ui +16 -0
  86. package/gallery/Diagram-sequence.ui +15 -0
  87. package/gallery/Diagram.ui +16 -0
  88. package/gallery/Diff.ui +3 -0
  89. package/gallery/Divider.ui +5 -0
  90. package/gallery/EditableTable.ui +9 -0
  91. package/gallery/Entity-list.ui +6 -0
  92. package/gallery/Entity.ui +8 -0
  93. package/gallery/Environments.ui +1 -0
  94. package/gallery/Estimate-points.ui +6 -0
  95. package/gallery/Estimate.ui +8 -0
  96. package/gallery/File.ui +4 -0
  97. package/gallery/Findings-biome.ui +1 -0
  98. package/gallery/Findings-eslint.ui +1 -0
  99. package/gallery/Findings-oxlint.ui +1 -0
  100. package/gallery/Findings-review.ui +1 -0
  101. package/gallery/Findings-ruff.ui +1 -0
  102. package/gallery/Findings-sarif.ui +1 -0
  103. package/gallery/Findings-ship.ui +11 -0
  104. package/gallery/Findings-tsc.ui +1 -0
  105. package/gallery/Findings.ui +7 -0
  106. package/gallery/Flashcards.ui +3 -0
  107. package/gallery/FollowUps.ui +4 -0
  108. package/gallery/Form.ui +8 -0
  109. package/gallery/Gallery-links.ui +8 -0
  110. package/gallery/Gallery-strip.ui +14 -0
  111. package/gallery/Gallery.ui +10 -0
  112. package/gallery/Gauge.ui +7 -0
  113. package/gallery/Grid.ui +8 -0
  114. package/gallery/Hotspots-photo.ui +8 -0
  115. package/gallery/Hotspots.ui +11 -0
  116. package/gallery/Icon.ui +5 -0
  117. package/gallery/Image.ui +4 -0
  118. package/gallery/ImageSearch-aspects.ui +6 -0
  119. package/gallery/ImageSearch.ui +4 -0
  120. package/gallery/Input.ui +5 -0
  121. package/gallery/Json-api.ui +1 -0
  122. package/gallery/Json.ui +8 -0
  123. package/gallery/KeyValue.ui +3 -0
  124. package/gallery/List-dots.ui +8 -0
  125. package/gallery/List.ui +8 -0
  126. package/gallery/ListEditor.ui +5 -0
  127. package/gallery/Logs-jsonl.ui +1 -0
  128. package/gallery/Logs-lines.ui +11 -0
  129. package/gallery/Logs-python.ui +1 -0
  130. package/gallery/Logs.ui +1 -0
  131. package/gallery/Map-city.ui +8 -0
  132. package/gallery/Map.ui +8 -0
  133. package/gallery/Metric.ui +3 -0
  134. package/gallery/OptionCards-multi.ui +10 -0
  135. package/gallery/OptionCards.ui +10 -0
  136. package/gallery/Pipeline-checks.ui +1 -0
  137. package/gallery/Pipeline-passed.ui +1 -0
  138. package/gallery/Pipeline-running.ui +1 -0
  139. package/gallery/Pipeline-stages.ui +13 -0
  140. package/gallery/Pipeline.ui +1 -0
  141. package/gallery/Plan.ui +9 -0
  142. package/gallery/Progress.ui +4 -0
  143. package/gallery/Provenance-deploy.ui +6 -0
  144. package/gallery/Provenance-no-receipt.ui +1 -0
  145. package/gallery/Provenance.ui +1 -0
  146. package/gallery/PullRequest.ui +1 -0
  147. package/gallery/Quiz.ui +6 -0
  148. package/gallery/Radio.ui +5 -0
  149. package/gallery/Rating.ui +5 -0
  150. package/gallery/Roadmap-sprint.ui +8 -0
  151. package/gallery/Roadmap-year.ui +9 -0
  152. package/gallery/Roadmap.ui +12 -0
  153. package/gallery/Row.ui +3 -0
  154. package/gallery/SegmentedBar-status.ui +8 -0
  155. package/gallery/SegmentedBar.ui +8 -0
  156. package/gallery/Select.ui +5 -0
  157. package/gallery/Slider.ui +7 -0
  158. package/gallery/Snippet.ui +3 -0
  159. package/gallery/Sources-chips.ui +4 -0
  160. package/gallery/Sources.ui +8 -0
  161. package/gallery/Sparkline.ui +6 -0
  162. package/gallery/Stack.ui +7 -0
  163. package/gallery/StackTrace-aggregate.ui +1 -0
  164. package/gallery/StackTrace-browser.ui +1 -0
  165. package/gallery/StackTrace-go.ui +1 -0
  166. package/gallery/StackTrace-java.ui +1 -0
  167. package/gallery/StackTrace-python.ui +1 -0
  168. package/gallery/StackTrace-rust.ui +1 -0
  169. package/gallery/StackTrace.ui +1 -0
  170. package/gallery/Status.ui +9 -0
  171. package/gallery/Stepper.ui +5 -0
  172. package/gallery/Steps.ui +8 -0
  173. package/gallery/Swatches-long-names.ui +4 -0
  174. package/gallery/Swatches-picker.ui +5 -0
  175. package/gallery/Swatches.ui +10 -0
  176. package/gallery/Table.ui +7 -0
  177. package/gallery/Tabs.ui +8 -0
  178. package/gallery/Tests-junit.ui +1 -0
  179. package/gallery/Tests-vitest-junit.ui +1 -0
  180. package/gallery/Tests-vitest.ui +1 -0
  181. package/gallery/Tests.ui +9 -0
  182. package/gallery/Text.ui +4 -0
  183. package/gallery/TextArea.ui +5 -0
  184. package/gallery/Threads-ids.ui +1 -0
  185. package/gallery/Threads.ui +1 -0
  186. package/gallery/Timeline.ui +8 -0
  187. package/gallery/Timer.ui +4 -0
  188. package/gallery/Toggle.ui +5 -0
  189. package/gallery/Transcript-text.ui +1 -0
  190. package/gallery/Transcript-untimed.ui +1 -0
  191. package/gallery/Transcript-whisper.ui +1 -0
  192. package/gallery/Transcript.ui +1 -0
  193. package/gallery/Tree.ui +3 -0
  194. package/gallery/Treemap-du.ui +1 -0
  195. package/gallery/Treemap-esbuild.ui +1 -0
  196. package/gallery/Treemap-tree.ui +7 -0
  197. package/gallery/Treemap.ui +18 -0
  198. package/gallery/Walkthrough.ui +9 -0
  199. package/gallery/Waterfall-har.ui +1 -0
  200. package/gallery/Waterfall-trace.ui +1 -0
  201. package/gallery/Waterfall.ui +11 -0
  202. package/gallery/data/acceptance/coil/viewport-lifecycle.json +25 -0
  203. package/gallery/data/acceptance/coil-gate.json +153 -0
  204. package/gallery/data/acceptance/orbit-baseline.json +163 -0
  205. package/gallery/data/acceptance/shots/gate-cell-opened.png +0 -0
  206. package/gallery/data/acceptance/shots/gate-light.png +0 -0
  207. package/gallery/data/acceptance/shots/gate-phone-dark.png +0 -0
  208. package/gallery/data/activity.json +1 -0
  209. package/gallery/data/bb-tasks-orb.json +420 -0
  210. package/gallery/data/biome.json +229 -0
  211. package/gallery/data/compare/status-after.png +0 -0
  212. package/gallery/data/compare/status-before.png +0 -0
  213. package/gallery/data/compare/status-dark-2x.png +0 -0
  214. package/gallery/data/compare/status-rerender.png +0 -0
  215. package/gallery/data/coverage-py.json +1 -0
  216. package/gallery/data/coverage-summary.json +1 -0
  217. package/gallery/data/coverage.out +23 -0
  218. package/gallery/data/deploys.json +1 -0
  219. package/gallery/data/device-runs.json +285 -0
  220. package/gallery/data/du-node-modules.txt +359 -0
  221. package/gallery/data/esbuild-meta.json +292 -0
  222. package/gallery/data/eslint.json +266 -0
  223. package/gallery/data/eslint.sarif +343 -0
  224. package/gallery/data/findings-review.json +76 -0
  225. package/gallery/data/gh-issues-nextjs.json +293 -0
  226. package/gallery/data/gh-pr-checks.json +272 -0
  227. package/gallery/data/gh-prs-nextjs.json +419 -0
  228. package/gallery/data/gh-run-failed.json +1 -0
  229. package/gallery/data/gh-run-passed.json +1 -0
  230. package/gallery/data/gh-run-running.json +1 -0
  231. package/gallery/data/github-release.json +57 -0
  232. package/gallery/data/hyperfine-startup.json +187 -0
  233. package/gallery/data/lcov.info +234 -0
  234. package/gallery/data/logs/media-sync.log +127 -0
  235. package/gallery/data/logs/thumbnailer.jsonl +17 -0
  236. package/gallery/data/logs/vitest-run.log +89 -0
  237. package/gallery/data/npm-audit.json +672 -0
  238. package/gallery/data/npm-outdated.json +179 -0
  239. package/gallery/data/oxlint.json +156 -0
  240. package/gallery/data/pip-outdated.json +68 -0
  241. package/gallery/data/pnpm-outdated.json +58 -0
  242. package/gallery/data/provenance/devicectl-install.json +35 -0
  243. package/gallery/data/provenance/install-timeout.log +4 -0
  244. package/gallery/data/provenance/iphone-install.json +72 -0
  245. package/gallery/data/provenance/iphone-no-receipt.json +57 -0
  246. package/gallery/data/provenance/live-home.jpg +0 -0
  247. package/gallery/data/provenance/live-probe.txt +10 -0
  248. package/gallery/data/provenance/xcodebuild-2811.log +19 -0
  249. package/gallery/data/provenance/xcodebuild-4712.log +19 -0
  250. package/gallery/data/pytest-junit.xml +64 -0
  251. package/gallery/data/python-org-trace.json +35 -0
  252. package/gallery/data/python-org.har +31 -0
  253. package/gallery/data/retry.ts +13 -0
  254. package/gallery/data/ruff.json +261 -0
  255. package/gallery/data/src/durations.py +63 -0
  256. package/gallery/data/src/json-logic.ts +156 -0
  257. package/gallery/data/src/mapMath.ts +135 -0
  258. package/gallery/data/src/semver/bump.go +73 -0
  259. package/gallery/data/traces/browser-error.json +5 -0
  260. package/gallery/data/traces/go/main.go +27 -0
  261. package/gallery/data/traces/go-panic.txt +16 -0
  262. package/gallery/data/traces/java-caused-by.txt +15 -0
  263. package/gallery/data/traces/node-aggregate.txt +30 -0
  264. package/gallery/data/traces/node-cause.txt +21 -0
  265. package/gallery/data/traces/py/deploy.json +5 -0
  266. package/gallery/data/traces/py/deploy.py +17 -0
  267. package/gallery/data/traces/py/settings.py +19 -0
  268. package/gallery/data/traces/python-chain.txt +30 -0
  269. package/gallery/data/traces/rust/main.rs +11 -0
  270. package/gallery/data/traces/rust-panic.txt +16 -0
  271. package/gallery/data/traces/shop/cart.mjs +19 -0
  272. package/gallery/data/traces/shop/pricing.mjs +12 -0
  273. package/gallery/data/traces/shop/status.mjs +9 -0
  274. package/gallery/data/traces/web/app.js +11 -0
  275. package/gallery/data/traces/web/index.html +1 -0
  276. package/gallery/data/traces/web/search.js +10 -0
  277. package/gallery/data/transcript/call-noisy.wav +0 -0
  278. package/gallery/data/transcript/call.json +362 -0
  279. package/gallery/data/transcript/call.wav +0 -0
  280. package/gallery/data/transcript/mlx-whisper-tiny.en-noisy.json +1 -0
  281. package/gallery/data/transcript/whisper-cpp-base.en-noisy.json +658 -0
  282. package/gallery/data/transcript/whisper-cpp-base.en.json +658 -0
  283. package/gallery/data/transcript/whisper-cpp-base.en.srt +16 -0
  284. package/gallery/data/transcript/whisper-cpp-tiny.en-noisy.json +619 -0
  285. package/gallery/data/tsc.txt +4 -0
  286. package/gallery/data/vitest-bench.json +119 -0
  287. package/gallery/data/vitest-junit.xml +133 -0
  288. package/gallery/data/vitest-report.json +612 -0
  289. package/gallery/images/bell.svg +10 -0
  290. package/gallery/images/bike.svg +47 -0
  291. package/gallery/images/footer-planet.webp +0 -0
  292. package/gallery/images/front-light.svg +13 -0
  293. package/gallery/images/golden-hour.webp +0 -0
  294. package/gallery/images/option-flowers.webp +0 -0
  295. package/gallery/images/option-hilltop.webp +0 -0
  296. package/gallery/images/option-meadow.webp +0 -0
  297. package/gallery/images/option-sky.webp +0 -0
  298. package/gallery/images/u-lock.svg +10 -0
  299. package/index.client.tsx +164 -0
  300. package/index.server.ts +216 -0
  301. package/package.json +50 -4
  302. package/paseo-plugin.json +14 -0
  303. package/server/data-source.ts +407 -0
  304. package/server/project.ts +981 -0
  305. package/server/web/address.ts +57 -0
  306. package/server/web/cache.ts +85 -0
  307. package/server/web/commons.ts +126 -0
  308. package/server/web/geocode.ts +40 -0
  309. package/server/web/image.ts +35 -0
  310. package/server/web/lookups.ts +248 -0
  311. package/server/web/net.ts +210 -0
  312. package/shared/core/acceptance.ts +744 -0
  313. package/shared/core/ast.ts +76 -0
  314. package/shared/core/benchmark.ts +743 -0
  315. package/shared/core/catalog.ts +733 -0
  316. package/shared/core/compare.ts +225 -0
  317. package/shared/core/coverage.ts +456 -0
  318. package/shared/core/data.ts +334 -0
  319. package/shared/core/decisions.ts +527 -0
  320. package/shared/core/dependencies.ts +604 -0
  321. package/shared/core/diagnostics.ts +24 -0
  322. package/shared/core/environments.ts +212 -0
  323. package/shared/core/evaluate.ts +737 -0
  324. package/shared/core/fields.ts +66 -0
  325. package/shared/core/findings.ts +1172 -0
  326. package/shared/core/form.ts +69 -0
  327. package/shared/core/index.ts +44 -0
  328. package/shared/core/junit.ts +252 -0
  329. package/shared/core/lexer.ts +275 -0
  330. package/shared/core/logs.ts +496 -0
  331. package/shared/core/markdown.ts +2374 -0
  332. package/shared/core/parser.ts +355 -0
  333. package/shared/core/perf-units.ts +228 -0
  334. package/shared/core/pipeline.ts +679 -0
  335. package/shared/core/project.ts +472 -0
  336. package/shared/core/provenance.ts +725 -0
  337. package/shared/core/stack-trace.ts +718 -0
  338. package/shared/core/streaming.ts +136 -0
  339. package/shared/core/test-results.ts +562 -0
  340. package/shared/core/thread-activity.ts +203 -0
  341. package/shared/core/tracking.ts +887 -0
  342. package/shared/core/transcript.ts +1364 -0
  343. package/shared/core/treemap.ts +446 -0
  344. package/shared/core/types.ts +70 -0
  345. package/shared/core/validate.ts +574 -0
  346. package/shared/core/waterfall.ts +536 -0
  347. package/shared/diagram/flowchart.ts +205 -0
  348. package/shared/diagram/layout.ts +440 -0
  349. package/shared/diagram/markdown.ts +135 -0
  350. package/shared/diagram/sequence.ts +122 -0
  351. package/shared/diagram/zoom.ts +114 -0
  352. package/shared/fallback.ts +120 -0
  353. package/shared/genui.test.ts +122 -0
  354. package/shared/instructions.ts +144 -0
  355. package/shared/logic/calendarMath.ts +130 -0
  356. package/shared/logic/chartMath.ts +289 -0
  357. package/shared/logic/choose-logic.ts +196 -0
  358. package/shared/logic/compare-logic.ts +270 -0
  359. package/shared/logic/content-model.ts +227 -0
  360. package/shared/logic/environments-logic.ts +53 -0
  361. package/shared/logic/explain-logic.ts +315 -0
  362. package/shared/logic/fieldLogic.ts +138 -0
  363. package/shared/logic/gallery-search.ts +71 -0
  364. package/shared/logic/icons.ts +322 -0
  365. package/shared/logic/json-logic.ts +153 -0
  366. package/shared/logic/mapMath.ts +133 -0
  367. package/shared/logic/project-logic.ts +39 -0
  368. package/shared/logic/references-model.ts +201 -0
  369. package/shared/logic/sketch.ts +165 -0
  370. package/shared/logic/supersession.ts +77 -0
  371. package/shared/logic/values.ts +133 -0
  372. package/shared/logic/widget-logic.ts +163 -0
  373. package/shared/rpc.ts +252 -0
  374. package/shared/segment.ts +81 -0
  375. package/shared/settings.ts +12 -0
@@ -0,0 +1,525 @@
1
+ import type { PluginTheme } from "@getpaseo/plugin";
2
+ import { openExternalUrl, usePaseo, type PluginTimelineItemProps } from "@getpaseo/plugin/client";
3
+ import { Icon, copyText, useRevealedText, useToast } from "@getpaseo/plugin/client/react-native";
4
+ import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
5
+ import { Pressable, StyleSheet, Text, View } from "react-native";
6
+ import {
7
+ collectLoads,
8
+ compileStreaming,
9
+ dataKey,
10
+ evaluate,
11
+ initialState,
12
+ type LoadedData,
13
+ type Program,
14
+ } from "../shared/core";
15
+ import type { Action, Diagnostic, Value } from "../shared/core/types";
16
+ import type { GenUiBlockData, GenUiTextData } from "../shared/rpc";
17
+ import { useAudioLoader, useImageLoader, useLoadedData, useTextLoader, type FileScope } from "./loaders";
18
+ import { MarkdownText } from "./markdown";
19
+ import { RenderNodes } from "./render";
20
+ import { UiRuntimeContext, type UiRuntime } from "./runtime";
21
+ import { canRenderWebIframe, mountSandboxedAppIframe, readStorage, writeStorage } from "./web";
22
+
23
+ function readStoredValues(storageKey: string): Record<string, Value> {
24
+ const raw = readStorage(storageKey);
25
+ if (raw === null) return {};
26
+ try {
27
+ const saved: unknown = JSON.parse(raw);
28
+ if (typeof saved !== "object" || saved === null || Array.isArray(saved)) return {};
29
+ return Object.fromEntries(Object.entries(saved as Record<string, Value>));
30
+ } catch {
31
+ return {};
32
+ }
33
+ }
34
+
35
+ export function LiveUi({
36
+ program,
37
+ compileDiagnostics,
38
+ source,
39
+ stateKey,
40
+ data,
41
+ send,
42
+ openFile,
43
+ loadImage,
44
+ readText,
45
+ loadAudio,
46
+ playAudio,
47
+ superseded = false,
48
+ agentId,
49
+ blockKey,
50
+ theme,
51
+ compact,
52
+ platform,
53
+ footerLabel,
54
+ }: {
55
+ program: Program;
56
+ compileDiagnostics: readonly Diagnostic[];
57
+ source: string;
58
+ stateKey: string;
59
+ data?: ReadonlyMap<string, LoadedData>;
60
+ send(text: string): Promise<void>;
61
+ openFile: UiRuntime["openFile"];
62
+ loadImage: UiRuntime["loadImage"];
63
+ readText: UiRuntime["readText"];
64
+ loadAudio: UiRuntime["loadAudio"];
65
+ playAudio: UiRuntime["playAudio"];
66
+ superseded?: boolean;
67
+ agentId: string | null;
68
+ blockKey: string | null;
69
+ theme: PluginTheme;
70
+ compact: boolean;
71
+ platform: "ios" | "android" | "web";
72
+ footerLabel?: string;
73
+ }) {
74
+ const toast = useToast();
75
+ const initial = useMemo(() => initialState(program, data), [program, data]);
76
+ const [changed, setChanged] = useState(() => readStoredValues(stateKey));
77
+ const state = useMemo(
78
+ () =>
79
+ Object.fromEntries(
80
+ Object.entries(initial).map(([name, value]) => [
81
+ name,
82
+ Object.hasOwn(changed, name) ? changed[name]! : value,
83
+ ]),
84
+ ),
85
+ [initial, changed],
86
+ );
87
+
88
+ useEffect(() => {
89
+ if (Object.keys(changed).length === 0) return;
90
+ writeStorage(stateKey, JSON.stringify(changed));
91
+ }, [stateKey, changed]);
92
+
93
+ const answerKey = `${stateKey}:answer`;
94
+ const [answer, setAnswer] = useState<string | null>(() => readStorage(answerKey));
95
+
96
+ const setValue = useCallback(
97
+ (name: string, value: Value) => {
98
+ if (Object.hasOwn(initial, name)) {
99
+ setChanged((prev) => ({ ...prev, [name]: value }));
100
+ }
101
+ },
102
+ [initial],
103
+ );
104
+
105
+ const runAction = useCallback(
106
+ async (action: Action) => {
107
+ switch (action.type) {
108
+ case "set":
109
+ setValue(action.name, action.value);
110
+ return;
111
+ case "send":
112
+ await send(action.text);
113
+ setAnswer(action.text);
114
+ writeStorage(answerKey, action.text);
115
+ return;
116
+ case "openUrl":
117
+ await openExternalUrl(action.url);
118
+ return;
119
+ case "copy":
120
+ await copyText(action.text);
121
+ toast.show("Copied", { variant: "success" });
122
+ return;
123
+ }
124
+ },
125
+ [answerKey, send, setValue, toast],
126
+ );
127
+
128
+ const runtime = useMemo<UiRuntime>(
129
+ () => ({
130
+ setValue,
131
+ openFile,
132
+ loadImage,
133
+ readText,
134
+ loadAudio,
135
+ playAudio,
136
+ answer,
137
+ superseded,
138
+ agentId,
139
+ blockKey,
140
+ theme,
141
+ compact,
142
+ platform,
143
+ async run(actions) {
144
+ try {
145
+ for (const action of actions) await runAction(action);
146
+ } catch (cause) {
147
+ toast.error(cause instanceof Error ? cause.message : String(cause));
148
+ }
149
+ },
150
+ }),
151
+ [
152
+ setValue,
153
+ openFile,
154
+ loadImage,
155
+ readText,
156
+ loadAudio,
157
+ playAudio,
158
+ answer,
159
+ superseded,
160
+ agentId,
161
+ blockKey,
162
+ theme,
163
+ compact,
164
+ platform,
165
+ runAction,
166
+ toast,
167
+ ],
168
+ );
169
+
170
+ const { roots, diagnostics } = useMemo(
171
+ () => evaluate(program, state, data),
172
+ [program, state, data],
173
+ );
174
+ const allDiagnostics = useMemo(
175
+ () => [...compileDiagnostics, ...diagnostics],
176
+ [compileDiagnostics, diagnostics],
177
+ );
178
+ const files = useMemo(() => collectLoads(program), [program]);
179
+
180
+ return (
181
+ <UiRuntimeContext.Provider value={runtime}>
182
+ <View style={{ gap: 6, marginVertical: 4 }}>
183
+ <View style={{ gap: compact ? 8 : 10 }}>
184
+ <RenderNodes nodes={roots} isolate />
185
+ </View>
186
+ <SourceFooter
187
+ source={source}
188
+ diagnostics={allDiagnostics}
189
+ fileCount={files.length}
190
+ theme={theme}
191
+ label={footerLabel}
192
+ />
193
+ </View>
194
+ </UiRuntimeContext.Provider>
195
+ );
196
+ }
197
+
198
+ function SourceFooter({
199
+ source,
200
+ diagnostics,
201
+ fileCount,
202
+ theme,
203
+ label,
204
+ }: {
205
+ source: string;
206
+ diagnostics: readonly Diagnostic[];
207
+ fileCount: number;
208
+ theme: PluginTheme;
209
+ label?: string;
210
+ }) {
211
+ const [open, setOpen] = useState(false);
212
+ const toast = useToast();
213
+
214
+ return (
215
+ <View style={{ gap: 4 }}>
216
+ <View style={{ flexDirection: "row", justifyContent: "space-between", alignItems: "center" }}>
217
+ {label ? (
218
+ <Text style={{ color: theme.colors.foregroundMuted, fontSize: 11, fontFamily: "monospace" }}>
219
+ {label}
220
+ </Text>
221
+ ) : (
222
+ <View />
223
+ )}
224
+ <View style={{ flexDirection: "row", alignItems: "center", gap: 10 }}>
225
+ {diagnostics.length > 0 ? (
226
+ <Text style={{ color: theme.colors.statusWarning, fontSize: 11 }}>
227
+ {diagnostics.length} warning{diagnostics.length === 1 ? "" : "s"}
228
+ </Text>
229
+ ) : null}
230
+ <Pressable
231
+ onPress={() => setOpen((o) => !o)}
232
+ style={{ flexDirection: "row", alignItems: "center", gap: 4 }}
233
+ >
234
+ <Icon name="Code" size={11} color={theme.colors.foregroundMuted} />
235
+ <Text style={{ color: theme.colors.foregroundMuted, fontSize: 11 }}>
236
+ {open ? "Hide source" : "Source"}
237
+ {fileCount > 0 ? ` (${fileCount} file${fileCount === 1 ? "" : "s"})` : ""}
238
+ </Text>
239
+ </Pressable>
240
+ </View>
241
+ </View>
242
+ {open ? (
243
+ <View
244
+ style={{
245
+ borderRadius: 8,
246
+ borderWidth: StyleSheet.hairlineWidth,
247
+ borderColor: theme.colors.border,
248
+ backgroundColor: theme.colors.surface2,
249
+ padding: 10,
250
+ gap: 8,
251
+ }}
252
+ >
253
+ <View style={{ flexDirection: "row", justifyContent: "space-between", alignItems: "center" }}>
254
+ <Text style={{ color: theme.colors.foregroundMuted, fontSize: 11 }}>Spec source</Text>
255
+ <Pressable
256
+ onPress={() => {
257
+ void copyText(source).then(
258
+ () => toast.show("Source copied", { variant: "success" }),
259
+ () => toast.error("Could not copy"),
260
+ );
261
+ }}
262
+ >
263
+ <Icon name="Copy" size={12} color={theme.colors.foregroundMuted} />
264
+ </Pressable>
265
+ </View>
266
+ <Text
267
+ selectable
268
+ style={{ color: theme.colors.foreground, fontFamily: "monospace", fontSize: 11.5 }}
269
+ >
270
+ {source}
271
+ </Text>
272
+ {diagnostics.length > 0 ? (
273
+ <View style={{ gap: 2 }}>
274
+ {diagnostics.map((d, i) => (
275
+ <Text
276
+ key={i}
277
+ style={{
278
+ color:
279
+ d.severity === "error"
280
+ ? theme.colors.statusDanger
281
+ : theme.colors.statusWarning,
282
+ fontFamily: "monospace",
283
+ fontSize: 11,
284
+ }}
285
+ >
286
+ {d.line}:{d.column} {d.severity}: {d.message}
287
+ </Text>
288
+ ))}
289
+ </View>
290
+ ) : null}
291
+ </View>
292
+ ) : null}
293
+ </View>
294
+ );
295
+ }
296
+
297
+ export function AppBlockView({
298
+ html,
299
+ complete,
300
+ theme,
301
+ }: {
302
+ html: string;
303
+ complete: boolean;
304
+ theme: PluginTheme;
305
+ }) {
306
+ const containerRef = useRef<View | null>(null);
307
+ const [height, setHeight] = useState(180);
308
+ const [error, setError] = useState<string | null>(null);
309
+ const webSupported = canRenderWebIframe();
310
+
311
+ useEffect(() => {
312
+ if (!complete || !webSupported || !containerRef.current) return;
313
+ setError(null);
314
+ return mountSandboxedAppIframe(containerRef.current, {
315
+ html,
316
+ theme,
317
+ height,
318
+ onHeight: setHeight,
319
+ onError: setError,
320
+ });
321
+ }, [complete, html, theme, webSupported]);
322
+
323
+ if (!complete) {
324
+ return (
325
+ <View
326
+ style={{
327
+ borderRadius: 12,
328
+ borderWidth: StyleSheet.hairlineWidth,
329
+ borderColor: theme.colors.border,
330
+ backgroundColor: theme.colors.surface1,
331
+ padding: 16,
332
+ }}
333
+ >
334
+ <Text style={{ color: theme.colors.foregroundMuted, fontSize: 12.5 }}>Building app…</Text>
335
+ </View>
336
+ );
337
+ }
338
+
339
+ return (
340
+ <View style={{ gap: 6, marginVertical: 4 }}>
341
+ <View
342
+ style={{
343
+ borderRadius: 12,
344
+ borderWidth: StyleSheet.hairlineWidth,
345
+ borderColor: theme.colors.border,
346
+ backgroundColor: theme.colors.surface1,
347
+ padding: 12,
348
+ gap: 6,
349
+ }}
350
+ >
351
+ {webSupported ? (
352
+ <View ref={containerRef} style={{ width: "100%", minHeight: height }} />
353
+ ) : (
354
+ <View style={{ gap: 6 }}>
355
+ <Text style={{ color: theme.colors.foregroundMuted, fontSize: 12 }}>
356
+ Interactive HTML app (open on desktop or web to run):
357
+ </Text>
358
+ <Text
359
+ selectable
360
+ style={{ color: theme.colors.foreground, fontFamily: "monospace", fontSize: 11.5 }}
361
+ >
362
+ {html}
363
+ </Text>
364
+ </View>
365
+ )}
366
+ {error ? (
367
+ <Text style={{ color: theme.colors.statusDanger, fontSize: 11.5 }}>{error}</Text>
368
+ ) : null}
369
+ </View>
370
+ <SourceFooter source={html} diagnostics={[]} fileCount={0} theme={theme} />
371
+ </View>
372
+ );
373
+ }
374
+
375
+ export function SpecBlockView({
376
+ code,
377
+ complete,
378
+ stateKey,
379
+ scope,
380
+ send,
381
+ openFile,
382
+ playAudio,
383
+ theme,
384
+ compact,
385
+ platform,
386
+ footerLabel,
387
+ }: {
388
+ code: string;
389
+ complete: boolean;
390
+ stateKey: string;
391
+ scope: FileScope;
392
+ send(text: string): Promise<void>;
393
+ openFile: UiRuntime["openFile"];
394
+ playAudio: UiRuntime["playAudio"];
395
+ theme: PluginTheme;
396
+ compact: boolean;
397
+ platform: "ios" | "android" | "web";
398
+ footerLabel?: string;
399
+ }) {
400
+ const result = useMemo(() => compileStreaming(code), [code]);
401
+ const lastGood = useRef(result.program === null ? null : result);
402
+ if (result.program !== null) lastGood.current = result;
403
+ const shown = lastGood.current;
404
+
405
+ const data = useLoadedData(scope, shown?.program ?? null);
406
+ const loadImage = useImageLoader(scope);
407
+ const readText = useTextLoader(scope);
408
+ const loadAudio = useAudioLoader(scope);
409
+
410
+ if (!shown?.program) {
411
+ if (!complete) {
412
+ return (
413
+ <View
414
+ style={{
415
+ borderRadius: 12,
416
+ borderWidth: StyleSheet.hairlineWidth,
417
+ borderColor: theme.colors.border,
418
+ backgroundColor: theme.colors.surface1,
419
+ padding: 16,
420
+ }}
421
+ >
422
+ <Text style={{ color: theme.colors.foregroundMuted, fontSize: 12.5 }}>Building UI…</Text>
423
+ </View>
424
+ );
425
+ }
426
+ return (
427
+ <View
428
+ style={{
429
+ borderRadius: 10,
430
+ borderWidth: StyleSheet.hairlineWidth,
431
+ borderColor: theme.colors.statusDanger,
432
+ backgroundColor: theme.colors.surface1,
433
+ padding: 12,
434
+ gap: 6,
435
+ }}
436
+ >
437
+ <Text style={{ color: theme.colors.statusDanger, fontSize: 12.5, fontWeight: "600" }}>
438
+ This UI couldn&apos;t be rendered
439
+ </Text>
440
+ {result.diagnostics.map((d, idx) => (
441
+ <Text
442
+ key={idx}
443
+ style={{ color: theme.colors.foregroundMuted, fontFamily: "monospace", fontSize: 11.5 }}
444
+ >
445
+ {d.line}:{d.column} {d.severity}: {d.message}
446
+ </Text>
447
+ ))}
448
+ <SourceFooter source={code} diagnostics={result.diagnostics} fileCount={0} theme={theme} />
449
+ </View>
450
+ );
451
+ }
452
+
453
+ const agentId = scope === "gallery" ? null : scope.agentId;
454
+ return (
455
+ <LiveUi
456
+ program={shown.program}
457
+ compileDiagnostics={result.complete ? result.diagnostics : []}
458
+ source={code}
459
+ stateKey={stateKey}
460
+ data={data}
461
+ send={send}
462
+ openFile={openFile}
463
+ loadImage={loadImage}
464
+ readText={readText}
465
+ loadAudio={loadAudio}
466
+ playAudio={playAudio}
467
+ agentId={agentId}
468
+ blockKey={scope === "gallery" ? null : stateKey}
469
+ theme={theme}
470
+ compact={compact}
471
+ platform={platform}
472
+ footerLabel={footerLabel}
473
+ />
474
+ );
475
+ }
476
+
477
+ export function TimelineBlockItem({
478
+ agentId,
479
+ item,
480
+ timestamp,
481
+ theme,
482
+ layout,
483
+ playAudio,
484
+ }: PluginTimelineItemProps<GenUiBlockData> & {
485
+ playAudio: UiRuntime["playAudio"];
486
+ }) {
487
+ const paseo = usePaseo();
488
+ const { language, code, complete, fenceIndex, messageId } = item.data;
489
+ const stateKey = `paseo.genui:${agentId}:${messageId ?? timestamp.getTime()}:${fenceIndex}`;
490
+
491
+ const send = useCallback(
492
+ async (text: string) => {
493
+ await paseo.agents.ref(agentId).send(text);
494
+ },
495
+ [paseo, agentId],
496
+ );
497
+
498
+ if (language === "app") {
499
+ return <AppBlockView html={code} complete={complete} theme={theme} />;
500
+ }
501
+
502
+ return (
503
+ <SpecBlockView
504
+ code={code}
505
+ complete={complete}
506
+ stateKey={stateKey}
507
+ scope={{ agentId }}
508
+ send={send}
509
+ openFile={null}
510
+ playAudio={playAudio}
511
+ theme={theme}
512
+ compact={layout.compact}
513
+ platform={layout.platform}
514
+ />
515
+ );
516
+ }
517
+
518
+ export function TimelineTextItem({
519
+ item,
520
+ theme,
521
+ layout,
522
+ }: PluginTimelineItemProps<GenUiTextData>) {
523
+ const revealed = useRevealedText(item.data.text, item.data.phase ?? "complete");
524
+ return <MarkdownText text={revealed} theme={theme} compact={layout.compact} />;
525
+ }