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.
- package/LICENSE +202 -0
- package/OVERVIEW.md +21 -0
- package/README.md +77 -2
- package/assets/fonts/Excalifont-OFL.txt +109 -0
- package/assets/fonts/Excalifont-Regular-latin.woff2 +0 -0
- package/assets/icon.png +0 -0
- package/assets/icon.svg +1 -0
- package/assets/screenshot-chat.png +0 -0
- package/assets/screenshot-gallery.png +0 -0
- package/assets/screenshot-playground.png +0 -0
- package/client/components/content.tsx +468 -0
- package/client/components/data.tsx +967 -0
- package/client/components/dev.tsx +998 -0
- package/client/components/diagram.tsx +513 -0
- package/client/components/inputs.tsx +994 -0
- package/client/components/layout.tsx +239 -0
- package/client/components/media.tsx +428 -0
- package/client/components/project.tsx +641 -0
- package/client/components/widgets.tsx +836 -0
- package/client/gallery.tsx +449 -0
- package/client/live-ui.tsx +525 -0
- package/client/loaders.ts +342 -0
- package/client/markdown.tsx +172 -0
- package/client/node-renderer.tsx +149 -0
- package/client/render.tsx +186 -0
- package/client/runtime.ts +103 -0
- package/client/settings.tsx +57 -0
- package/client/web.ts +186 -0
- package/gallery/Acceptance-baseline.ui +1 -0
- package/gallery/Acceptance-checklist.ui +14 -0
- package/gallery/Acceptance-evidence.ui +9 -0
- package/gallery/Acceptance.ui +1 -0
- package/gallery/Badge.ui +3 -0
- package/gallery/Benchmark-context.ui +8 -0
- package/gallery/Benchmark-hyperfine.ui +1 -0
- package/gallery/Benchmark-runs-list.ui +9 -0
- package/gallery/Benchmark-runs.ui +1 -0
- package/gallery/Benchmark-vitest.ui +1 -0
- package/gallery/Benchmark.ui +9 -0
- package/gallery/Board-bb-tasks.ui +1 -0
- package/gallery/Board-gh-issues.ui +1 -0
- package/gallery/Board-gh-prs.ui +1 -0
- package/gallery/Board.ui +12 -0
- package/gallery/Button-destructive.ui +4 -0
- package/gallery/Button.ui +5 -0
- package/gallery/Calendar.ui +15 -0
- package/gallery/CalendarHeatmap-short.ui +11 -0
- package/gallery/CalendarHeatmap.ui +4 -0
- package/gallery/Callout.ui +4 -0
- package/gallery/Card.ui +4 -0
- package/gallery/Carousel.ui +8 -0
- package/gallery/Changes-paths.ui +1 -0
- package/gallery/Changes-uncommitted.ui +1 -0
- package/gallery/Changes.ui +1 -0
- package/gallery/Chart-area.ui +3 -0
- package/gallery/Chart-funnel.ui +3 -0
- package/gallery/Chart-heatmap.ui +11 -0
- package/gallery/Chart-pie.ui +3 -0
- package/gallery/Chart-radar.ui +3 -0
- package/gallery/Chart-scatter.ui +4 -0
- package/gallery/Chart-stacked.ui +5 -0
- package/gallery/Chart.ui +3 -0
- package/gallery/Checklist.ui +6 -0
- package/gallery/Choice.ui +8 -0
- package/gallery/Code.ui +3 -0
- package/gallery/Commits-limit.ui +1 -0
- package/gallery/Commits.ui +1 -0
- package/gallery/Compare-conditions.ui +4 -0
- package/gallery/Compare-three.ui +7 -0
- package/gallery/Compare.ui +4 -0
- package/gallery/Coverage-go.ui +1 -0
- package/gallery/Coverage-lcov.ui +1 -0
- package/gallery/Coverage-python.ui +1 -0
- package/gallery/Coverage.ui +1 -0
- package/gallery/DateInput.ui +5 -0
- package/gallery/Decision-percent.ui +10 -0
- package/gallery/Decision.ui +12 -0
- package/gallery/Dependencies-audit.ui +1 -0
- package/gallery/Dependencies-both.ui +1 -0
- package/gallery/Dependencies-list.ui +7 -0
- package/gallery/Dependencies-pip.ui +1 -0
- package/gallery/Dependencies-pnpm.ui +1 -0
- package/gallery/Dependencies.ui +1 -0
- package/gallery/Details.ui +4 -0
- package/gallery/Diagram-flow.ui +16 -0
- package/gallery/Diagram-sequence.ui +15 -0
- package/gallery/Diagram.ui +16 -0
- package/gallery/Diff.ui +3 -0
- package/gallery/Divider.ui +5 -0
- package/gallery/EditableTable.ui +9 -0
- package/gallery/Entity-list.ui +6 -0
- package/gallery/Entity.ui +8 -0
- package/gallery/Environments.ui +1 -0
- package/gallery/Estimate-points.ui +6 -0
- package/gallery/Estimate.ui +8 -0
- package/gallery/File.ui +4 -0
- package/gallery/Findings-biome.ui +1 -0
- package/gallery/Findings-eslint.ui +1 -0
- package/gallery/Findings-oxlint.ui +1 -0
- package/gallery/Findings-review.ui +1 -0
- package/gallery/Findings-ruff.ui +1 -0
- package/gallery/Findings-sarif.ui +1 -0
- package/gallery/Findings-ship.ui +11 -0
- package/gallery/Findings-tsc.ui +1 -0
- package/gallery/Findings.ui +7 -0
- package/gallery/Flashcards.ui +3 -0
- package/gallery/FollowUps.ui +4 -0
- package/gallery/Form.ui +8 -0
- package/gallery/Gallery-links.ui +8 -0
- package/gallery/Gallery-strip.ui +14 -0
- package/gallery/Gallery.ui +10 -0
- package/gallery/Gauge.ui +7 -0
- package/gallery/Grid.ui +8 -0
- package/gallery/Hotspots-photo.ui +8 -0
- package/gallery/Hotspots.ui +11 -0
- package/gallery/Icon.ui +5 -0
- package/gallery/Image.ui +4 -0
- package/gallery/ImageSearch-aspects.ui +6 -0
- package/gallery/ImageSearch.ui +4 -0
- package/gallery/Input.ui +5 -0
- package/gallery/Json-api.ui +1 -0
- package/gallery/Json.ui +8 -0
- package/gallery/KeyValue.ui +3 -0
- package/gallery/List-dots.ui +8 -0
- package/gallery/List.ui +8 -0
- package/gallery/ListEditor.ui +5 -0
- package/gallery/Logs-jsonl.ui +1 -0
- package/gallery/Logs-lines.ui +11 -0
- package/gallery/Logs-python.ui +1 -0
- package/gallery/Logs.ui +1 -0
- package/gallery/Map-city.ui +8 -0
- package/gallery/Map.ui +8 -0
- package/gallery/Metric.ui +3 -0
- package/gallery/OptionCards-multi.ui +10 -0
- package/gallery/OptionCards.ui +10 -0
- package/gallery/Pipeline-checks.ui +1 -0
- package/gallery/Pipeline-passed.ui +1 -0
- package/gallery/Pipeline-running.ui +1 -0
- package/gallery/Pipeline-stages.ui +13 -0
- package/gallery/Pipeline.ui +1 -0
- package/gallery/Plan.ui +9 -0
- package/gallery/Progress.ui +4 -0
- package/gallery/Provenance-deploy.ui +6 -0
- package/gallery/Provenance-no-receipt.ui +1 -0
- package/gallery/Provenance.ui +1 -0
- package/gallery/PullRequest.ui +1 -0
- package/gallery/Quiz.ui +6 -0
- package/gallery/Radio.ui +5 -0
- package/gallery/Rating.ui +5 -0
- package/gallery/Roadmap-sprint.ui +8 -0
- package/gallery/Roadmap-year.ui +9 -0
- package/gallery/Roadmap.ui +12 -0
- package/gallery/Row.ui +3 -0
- package/gallery/SegmentedBar-status.ui +8 -0
- package/gallery/SegmentedBar.ui +8 -0
- package/gallery/Select.ui +5 -0
- package/gallery/Slider.ui +7 -0
- package/gallery/Snippet.ui +3 -0
- package/gallery/Sources-chips.ui +4 -0
- package/gallery/Sources.ui +8 -0
- package/gallery/Sparkline.ui +6 -0
- package/gallery/Stack.ui +7 -0
- package/gallery/StackTrace-aggregate.ui +1 -0
- package/gallery/StackTrace-browser.ui +1 -0
- package/gallery/StackTrace-go.ui +1 -0
- package/gallery/StackTrace-java.ui +1 -0
- package/gallery/StackTrace-python.ui +1 -0
- package/gallery/StackTrace-rust.ui +1 -0
- package/gallery/StackTrace.ui +1 -0
- package/gallery/Status.ui +9 -0
- package/gallery/Stepper.ui +5 -0
- package/gallery/Steps.ui +8 -0
- package/gallery/Swatches-long-names.ui +4 -0
- package/gallery/Swatches-picker.ui +5 -0
- package/gallery/Swatches.ui +10 -0
- package/gallery/Table.ui +7 -0
- package/gallery/Tabs.ui +8 -0
- package/gallery/Tests-junit.ui +1 -0
- package/gallery/Tests-vitest-junit.ui +1 -0
- package/gallery/Tests-vitest.ui +1 -0
- package/gallery/Tests.ui +9 -0
- package/gallery/Text.ui +4 -0
- package/gallery/TextArea.ui +5 -0
- package/gallery/Threads-ids.ui +1 -0
- package/gallery/Threads.ui +1 -0
- package/gallery/Timeline.ui +8 -0
- package/gallery/Timer.ui +4 -0
- package/gallery/Toggle.ui +5 -0
- package/gallery/Transcript-text.ui +1 -0
- package/gallery/Transcript-untimed.ui +1 -0
- package/gallery/Transcript-whisper.ui +1 -0
- package/gallery/Transcript.ui +1 -0
- package/gallery/Tree.ui +3 -0
- package/gallery/Treemap-du.ui +1 -0
- package/gallery/Treemap-esbuild.ui +1 -0
- package/gallery/Treemap-tree.ui +7 -0
- package/gallery/Treemap.ui +18 -0
- package/gallery/Walkthrough.ui +9 -0
- package/gallery/Waterfall-har.ui +1 -0
- package/gallery/Waterfall-trace.ui +1 -0
- package/gallery/Waterfall.ui +11 -0
- package/gallery/data/acceptance/coil/viewport-lifecycle.json +25 -0
- package/gallery/data/acceptance/coil-gate.json +153 -0
- package/gallery/data/acceptance/orbit-baseline.json +163 -0
- package/gallery/data/acceptance/shots/gate-cell-opened.png +0 -0
- package/gallery/data/acceptance/shots/gate-light.png +0 -0
- package/gallery/data/acceptance/shots/gate-phone-dark.png +0 -0
- package/gallery/data/activity.json +1 -0
- package/gallery/data/bb-tasks-orb.json +420 -0
- package/gallery/data/biome.json +229 -0
- package/gallery/data/compare/status-after.png +0 -0
- package/gallery/data/compare/status-before.png +0 -0
- package/gallery/data/compare/status-dark-2x.png +0 -0
- package/gallery/data/compare/status-rerender.png +0 -0
- package/gallery/data/coverage-py.json +1 -0
- package/gallery/data/coverage-summary.json +1 -0
- package/gallery/data/coverage.out +23 -0
- package/gallery/data/deploys.json +1 -0
- package/gallery/data/device-runs.json +285 -0
- package/gallery/data/du-node-modules.txt +359 -0
- package/gallery/data/esbuild-meta.json +292 -0
- package/gallery/data/eslint.json +266 -0
- package/gallery/data/eslint.sarif +343 -0
- package/gallery/data/findings-review.json +76 -0
- package/gallery/data/gh-issues-nextjs.json +293 -0
- package/gallery/data/gh-pr-checks.json +272 -0
- package/gallery/data/gh-prs-nextjs.json +419 -0
- package/gallery/data/gh-run-failed.json +1 -0
- package/gallery/data/gh-run-passed.json +1 -0
- package/gallery/data/gh-run-running.json +1 -0
- package/gallery/data/github-release.json +57 -0
- package/gallery/data/hyperfine-startup.json +187 -0
- package/gallery/data/lcov.info +234 -0
- package/gallery/data/logs/media-sync.log +127 -0
- package/gallery/data/logs/thumbnailer.jsonl +17 -0
- package/gallery/data/logs/vitest-run.log +89 -0
- package/gallery/data/npm-audit.json +672 -0
- package/gallery/data/npm-outdated.json +179 -0
- package/gallery/data/oxlint.json +156 -0
- package/gallery/data/pip-outdated.json +68 -0
- package/gallery/data/pnpm-outdated.json +58 -0
- package/gallery/data/provenance/devicectl-install.json +35 -0
- package/gallery/data/provenance/install-timeout.log +4 -0
- package/gallery/data/provenance/iphone-install.json +72 -0
- package/gallery/data/provenance/iphone-no-receipt.json +57 -0
- package/gallery/data/provenance/live-home.jpg +0 -0
- package/gallery/data/provenance/live-probe.txt +10 -0
- package/gallery/data/provenance/xcodebuild-2811.log +19 -0
- package/gallery/data/provenance/xcodebuild-4712.log +19 -0
- package/gallery/data/pytest-junit.xml +64 -0
- package/gallery/data/python-org-trace.json +35 -0
- package/gallery/data/python-org.har +31 -0
- package/gallery/data/retry.ts +13 -0
- package/gallery/data/ruff.json +261 -0
- package/gallery/data/src/durations.py +63 -0
- package/gallery/data/src/json-logic.ts +156 -0
- package/gallery/data/src/mapMath.ts +135 -0
- package/gallery/data/src/semver/bump.go +73 -0
- package/gallery/data/traces/browser-error.json +5 -0
- package/gallery/data/traces/go/main.go +27 -0
- package/gallery/data/traces/go-panic.txt +16 -0
- package/gallery/data/traces/java-caused-by.txt +15 -0
- package/gallery/data/traces/node-aggregate.txt +30 -0
- package/gallery/data/traces/node-cause.txt +21 -0
- package/gallery/data/traces/py/deploy.json +5 -0
- package/gallery/data/traces/py/deploy.py +17 -0
- package/gallery/data/traces/py/settings.py +19 -0
- package/gallery/data/traces/python-chain.txt +30 -0
- package/gallery/data/traces/rust/main.rs +11 -0
- package/gallery/data/traces/rust-panic.txt +16 -0
- package/gallery/data/traces/shop/cart.mjs +19 -0
- package/gallery/data/traces/shop/pricing.mjs +12 -0
- package/gallery/data/traces/shop/status.mjs +9 -0
- package/gallery/data/traces/web/app.js +11 -0
- package/gallery/data/traces/web/index.html +1 -0
- package/gallery/data/traces/web/search.js +10 -0
- package/gallery/data/transcript/call-noisy.wav +0 -0
- package/gallery/data/transcript/call.json +362 -0
- package/gallery/data/transcript/call.wav +0 -0
- package/gallery/data/transcript/mlx-whisper-tiny.en-noisy.json +1 -0
- package/gallery/data/transcript/whisper-cpp-base.en-noisy.json +658 -0
- package/gallery/data/transcript/whisper-cpp-base.en.json +658 -0
- package/gallery/data/transcript/whisper-cpp-base.en.srt +16 -0
- package/gallery/data/transcript/whisper-cpp-tiny.en-noisy.json +619 -0
- package/gallery/data/tsc.txt +4 -0
- package/gallery/data/vitest-bench.json +119 -0
- package/gallery/data/vitest-junit.xml +133 -0
- package/gallery/data/vitest-report.json +612 -0
- package/gallery/images/bell.svg +10 -0
- package/gallery/images/bike.svg +47 -0
- package/gallery/images/footer-planet.webp +0 -0
- package/gallery/images/front-light.svg +13 -0
- package/gallery/images/golden-hour.webp +0 -0
- package/gallery/images/option-flowers.webp +0 -0
- package/gallery/images/option-hilltop.webp +0 -0
- package/gallery/images/option-meadow.webp +0 -0
- package/gallery/images/option-sky.webp +0 -0
- package/gallery/images/u-lock.svg +10 -0
- package/index.client.tsx +164 -0
- package/index.server.ts +216 -0
- package/package.json +50 -4
- package/paseo-plugin.json +14 -0
- package/server/data-source.ts +407 -0
- package/server/project.ts +981 -0
- package/server/web/address.ts +57 -0
- package/server/web/cache.ts +85 -0
- package/server/web/commons.ts +126 -0
- package/server/web/geocode.ts +40 -0
- package/server/web/image.ts +35 -0
- package/server/web/lookups.ts +248 -0
- package/server/web/net.ts +210 -0
- package/shared/core/acceptance.ts +744 -0
- package/shared/core/ast.ts +76 -0
- package/shared/core/benchmark.ts +743 -0
- package/shared/core/catalog.ts +733 -0
- package/shared/core/compare.ts +225 -0
- package/shared/core/coverage.ts +456 -0
- package/shared/core/data.ts +334 -0
- package/shared/core/decisions.ts +527 -0
- package/shared/core/dependencies.ts +604 -0
- package/shared/core/diagnostics.ts +24 -0
- package/shared/core/environments.ts +212 -0
- package/shared/core/evaluate.ts +737 -0
- package/shared/core/fields.ts +66 -0
- package/shared/core/findings.ts +1172 -0
- package/shared/core/form.ts +69 -0
- package/shared/core/index.ts +44 -0
- package/shared/core/junit.ts +252 -0
- package/shared/core/lexer.ts +275 -0
- package/shared/core/logs.ts +496 -0
- package/shared/core/markdown.ts +2374 -0
- package/shared/core/parser.ts +355 -0
- package/shared/core/perf-units.ts +228 -0
- package/shared/core/pipeline.ts +679 -0
- package/shared/core/project.ts +472 -0
- package/shared/core/provenance.ts +725 -0
- package/shared/core/stack-trace.ts +718 -0
- package/shared/core/streaming.ts +136 -0
- package/shared/core/test-results.ts +562 -0
- package/shared/core/thread-activity.ts +203 -0
- package/shared/core/tracking.ts +887 -0
- package/shared/core/transcript.ts +1364 -0
- package/shared/core/treemap.ts +446 -0
- package/shared/core/types.ts +70 -0
- package/shared/core/validate.ts +574 -0
- package/shared/core/waterfall.ts +536 -0
- package/shared/diagram/flowchart.ts +205 -0
- package/shared/diagram/layout.ts +440 -0
- package/shared/diagram/markdown.ts +135 -0
- package/shared/diagram/sequence.ts +122 -0
- package/shared/diagram/zoom.ts +114 -0
- package/shared/fallback.ts +120 -0
- package/shared/genui.test.ts +122 -0
- package/shared/instructions.ts +144 -0
- package/shared/logic/calendarMath.ts +130 -0
- package/shared/logic/chartMath.ts +289 -0
- package/shared/logic/choose-logic.ts +196 -0
- package/shared/logic/compare-logic.ts +270 -0
- package/shared/logic/content-model.ts +227 -0
- package/shared/logic/environments-logic.ts +53 -0
- package/shared/logic/explain-logic.ts +315 -0
- package/shared/logic/fieldLogic.ts +138 -0
- package/shared/logic/gallery-search.ts +71 -0
- package/shared/logic/icons.ts +322 -0
- package/shared/logic/json-logic.ts +153 -0
- package/shared/logic/mapMath.ts +133 -0
- package/shared/logic/project-logic.ts +39 -0
- package/shared/logic/references-model.ts +201 -0
- package/shared/logic/sketch.ts +165 -0
- package/shared/logic/supersession.ts +77 -0
- package/shared/logic/values.ts +133 -0
- package/shared/logic/widget-logic.ts +163 -0
- package/shared/rpc.ts +252 -0
- package/shared/segment.ts +81 -0
- package/shared/settings.ts +12 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small Markdown subset for the prose around a diagram.
|
|
3
|
+
*
|
|
4
|
+
* Taking over a timeline item means taking over its text too, so this exists to
|
|
5
|
+
* keep that text readable. It covers what agents actually write around a
|
|
6
|
+
* diagram: headings, paragraphs, lists, code and inline emphasis. Anything else
|
|
7
|
+
* survives as plain text rather than as broken markup.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export type Inline =
|
|
11
|
+
| { kind: "text"; text: string }
|
|
12
|
+
| { kind: "bold"; text: string }
|
|
13
|
+
| { kind: "italic"; text: string }
|
|
14
|
+
| { kind: "code"; text: string };
|
|
15
|
+
|
|
16
|
+
export type Block =
|
|
17
|
+
| { kind: "heading"; level: number; content: Inline[] }
|
|
18
|
+
| { kind: "paragraph"; content: Inline[] }
|
|
19
|
+
| { kind: "bullet"; items: Inline[][] }
|
|
20
|
+
| { kind: "ordered"; items: Inline[][]; start: number }
|
|
21
|
+
| { kind: "code"; language: string; text: string }
|
|
22
|
+
| { kind: "quote"; content: Inline[] }
|
|
23
|
+
| { kind: "rule" };
|
|
24
|
+
|
|
25
|
+
const INLINE = /(`[^`]+`|\*\*[^*]+\*\*|__[^_]+__|\*[^*\n]+\*|_[^_\n]+_)/;
|
|
26
|
+
|
|
27
|
+
export function parseInline(text: string): Inline[] {
|
|
28
|
+
const out: Inline[] = [];
|
|
29
|
+
for (const piece of text.split(INLINE)) {
|
|
30
|
+
if (piece.length === 0) continue;
|
|
31
|
+
if (piece.startsWith("`") && piece.endsWith("`") && piece.length > 1) {
|
|
32
|
+
out.push({ kind: "code", text: piece.slice(1, -1) });
|
|
33
|
+
} else if ((piece.startsWith("**") && piece.endsWith("**")) || (piece.startsWith("__") && piece.endsWith("__"))) {
|
|
34
|
+
out.push({ kind: "bold", text: piece.slice(2, -2) });
|
|
35
|
+
} else if ((piece.startsWith("*") && piece.endsWith("*")) || (piece.startsWith("_") && piece.endsWith("_"))) {
|
|
36
|
+
out.push({ kind: "italic", text: piece.slice(1, -1) });
|
|
37
|
+
} else {
|
|
38
|
+
out.push({ kind: "text", text: piece });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const HEADING = /^(#{1,6})\s+(.*)$/;
|
|
45
|
+
const BULLET = /^\s*[-*+]\s+(.*)$/;
|
|
46
|
+
const ORDERED = /^\s*(\d+)[.)]\s+(.*)$/;
|
|
47
|
+
const QUOTE = /^>\s?(.*)$/;
|
|
48
|
+
const RULE = /^\s*([-*_])\s*(?:\1\s*){2,}$/;
|
|
49
|
+
const FENCE = /^\s*(`{3,}|~{3,})\s*(\S*)\s*$/;
|
|
50
|
+
|
|
51
|
+
export function parseMarkdown(source: string): Block[] {
|
|
52
|
+
const blocks: Block[] = [];
|
|
53
|
+
const lines = source.split("\n");
|
|
54
|
+
let paragraph: string[] = [];
|
|
55
|
+
|
|
56
|
+
const flush = () => {
|
|
57
|
+
const text = paragraph.join(" ").trim();
|
|
58
|
+
if (text.length > 0) blocks.push({ kind: "paragraph", content: parseInline(text) });
|
|
59
|
+
paragraph = [];
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
63
|
+
const line = lines[index];
|
|
64
|
+
|
|
65
|
+
const fence = FENCE.exec(line);
|
|
66
|
+
if (fence) {
|
|
67
|
+
flush();
|
|
68
|
+
const body: string[] = [];
|
|
69
|
+
index += 1;
|
|
70
|
+
while (index < lines.length && !FENCE.test(lines[index])) {
|
|
71
|
+
body.push(lines[index]);
|
|
72
|
+
index += 1;
|
|
73
|
+
}
|
|
74
|
+
blocks.push({ kind: "code", language: fence[2], text: body.join("\n") });
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (line.trim().length === 0) {
|
|
79
|
+
flush();
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (RULE.test(line)) {
|
|
83
|
+
flush();
|
|
84
|
+
blocks.push({ kind: "rule" });
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const heading = HEADING.exec(line);
|
|
89
|
+
if (heading) {
|
|
90
|
+
flush();
|
|
91
|
+
blocks.push({ kind: "heading", level: heading[1].length, content: parseInline(heading[2]) });
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const bullet = BULLET.exec(line);
|
|
96
|
+
if (bullet) {
|
|
97
|
+
flush();
|
|
98
|
+
const items: Inline[][] = [parseInline(bullet[1])];
|
|
99
|
+
while (index + 1 < lines.length) {
|
|
100
|
+
const next = BULLET.exec(lines[index + 1]);
|
|
101
|
+
if (!next) break;
|
|
102
|
+
items.push(parseInline(next[1]));
|
|
103
|
+
index += 1;
|
|
104
|
+
}
|
|
105
|
+
blocks.push({ kind: "bullet", items });
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const ordered = ORDERED.exec(line);
|
|
110
|
+
if (ordered) {
|
|
111
|
+
flush();
|
|
112
|
+
const items: Inline[][] = [parseInline(ordered[2])];
|
|
113
|
+
while (index + 1 < lines.length) {
|
|
114
|
+
const next = ORDERED.exec(lines[index + 1]);
|
|
115
|
+
if (!next) break;
|
|
116
|
+
items.push(parseInline(next[2]));
|
|
117
|
+
index += 1;
|
|
118
|
+
}
|
|
119
|
+
blocks.push({ kind: "ordered", items, start: Number(ordered[1]) });
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const quote = QUOTE.exec(line);
|
|
124
|
+
if (quote) {
|
|
125
|
+
flush();
|
|
126
|
+
blocks.push({ kind: "quote", content: parseInline(quote[1]) });
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
paragraph.push(line.trim());
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
flush();
|
|
134
|
+
return blocks;
|
|
135
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mermaid `sequenceDiagram` subset. Same rules as the flowchart parser: pure,
|
|
3
|
+
* synchronous, and honest about the lines it does not interpret.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type MessageStyle = "solid" | "dashed";
|
|
7
|
+
export type ArrowHead = "none" | "open" | "filled" | "async";
|
|
8
|
+
|
|
9
|
+
export interface SeqParticipant {
|
|
10
|
+
id: string;
|
|
11
|
+
label: string;
|
|
12
|
+
actor: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type SeqEvent =
|
|
16
|
+
| { kind: "message"; from: string; to: string; text: string; style: MessageStyle; arrow: ArrowHead }
|
|
17
|
+
| { kind: "note"; over: string[]; text: string };
|
|
18
|
+
|
|
19
|
+
export interface SequenceDiagram {
|
|
20
|
+
participants: SeqParticipant[];
|
|
21
|
+
events: SeqEvent[];
|
|
22
|
+
skipped: string[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const HEADER = /^\s*sequenceDiagram\s*$/i;
|
|
26
|
+
const PARTICIPANT = /^(participant|actor)\s+([\w.-]+)(?:\s+as\s+(.+))?$/i;
|
|
27
|
+
const NOTE = /^note\s+(?:(over)\s+([\w.,\s-]+)|(?:left|right)\s+of\s+([\w.-]+))\s*:\s*(.*)$/i;
|
|
28
|
+
|
|
29
|
+
/** Longest first so `-->>` is never read as `-->`. */
|
|
30
|
+
const ARROWS: { token: string; style: MessageStyle; arrow: ArrowHead }[] = [
|
|
31
|
+
{ token: "--)", style: "dashed", arrow: "async" },
|
|
32
|
+
{ token: "-->>", style: "dashed", arrow: "filled" },
|
|
33
|
+
{ token: "--x", style: "dashed", arrow: "open" },
|
|
34
|
+
{ token: "-->", style: "dashed", arrow: "none" },
|
|
35
|
+
{ token: "->>", style: "solid", arrow: "filled" },
|
|
36
|
+
{ token: "-)", style: "solid", arrow: "async" },
|
|
37
|
+
{ token: "-x", style: "solid", arrow: "open" },
|
|
38
|
+
{ token: "->", style: "solid", arrow: "none" },
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
/** Blocks whose contents still render; only the framing is dropped for now. */
|
|
42
|
+
const BLOCK = /^(loop|alt|else|opt|par|and|critical|rect|break|end|activate|deactivate|autonumber)\b/i;
|
|
43
|
+
|
|
44
|
+
export function parseSequence(source: string): SequenceDiagram | null {
|
|
45
|
+
const lines = source.split("\n");
|
|
46
|
+
if (!lines.some((line) => HEADER.test(line))) return null;
|
|
47
|
+
|
|
48
|
+
const participants = new Map<string, SeqParticipant>();
|
|
49
|
+
const events: SeqEvent[] = [];
|
|
50
|
+
const skipped: string[] = [];
|
|
51
|
+
let started = false;
|
|
52
|
+
|
|
53
|
+
const mention = (id: string) => {
|
|
54
|
+
if (!participants.has(id)) participants.set(id, { id, label: id, actor: false });
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
for (const original of lines) {
|
|
58
|
+
const line = original.replace(/%%.*$/, "").trim();
|
|
59
|
+
if (line.length === 0) continue;
|
|
60
|
+
if (HEADER.test(line)) {
|
|
61
|
+
started = true;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (!started) continue;
|
|
65
|
+
|
|
66
|
+
const declared = PARTICIPANT.exec(line);
|
|
67
|
+
if (declared) {
|
|
68
|
+
participants.set(declared[2], {
|
|
69
|
+
id: declared[2],
|
|
70
|
+
label: (declared[3] ?? declared[2]).trim(),
|
|
71
|
+
actor: declared[1].toLowerCase() === "actor",
|
|
72
|
+
});
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const note = NOTE.exec(line);
|
|
77
|
+
if (note) {
|
|
78
|
+
const over = (note[2] ?? note[3] ?? "")
|
|
79
|
+
.split(",")
|
|
80
|
+
.map((name) => name.trim())
|
|
81
|
+
.filter((name) => name.length > 0);
|
|
82
|
+
for (const name of over) mention(name);
|
|
83
|
+
events.push({ kind: "note", over, text: note[4].trim() });
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (BLOCK.test(line)) {
|
|
88
|
+
skipped.push(original.trim());
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const colon = line.indexOf(":");
|
|
93
|
+
const head = colon >= 0 ? line.slice(0, colon) : line;
|
|
94
|
+
const arrow = ARROWS.find((candidate) => head.includes(candidate.token));
|
|
95
|
+
if (!arrow || colon < 0) {
|
|
96
|
+
skipped.push(original.trim());
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const at = head.indexOf(arrow.token);
|
|
101
|
+
const from = head.slice(0, at).trim();
|
|
102
|
+
const to = head.slice(at + arrow.token.length).trim();
|
|
103
|
+
if (!/^[\w.-]+$/.test(from) || !/^[\w.-]+$/.test(to)) {
|
|
104
|
+
skipped.push(original.trim());
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Order of first appearance is the column order Mermaid uses.
|
|
109
|
+
mention(from);
|
|
110
|
+
mention(to);
|
|
111
|
+
events.push({
|
|
112
|
+
kind: "message",
|
|
113
|
+
from,
|
|
114
|
+
to,
|
|
115
|
+
text: line.slice(colon + 1).trim(),
|
|
116
|
+
style: arrow.style,
|
|
117
|
+
arrow: arrow.arrow,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return { participants: [...participants.values()], events, skipped };
|
|
122
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The zoom model behind the toolbar, kept pure so it can be tested without
|
|
3
|
+
* mounting anything.
|
|
4
|
+
*
|
|
5
|
+
* Zoom is a multiplier over the scale the drawing was fitted at: 1 is "as
|
|
6
|
+
* fitted", which is what the toolbar labels 100%. This is the same convention
|
|
7
|
+
* as Paseo's own diagram viewport, where the fit transform has scale 1, so a
|
|
8
|
+
* reader who knows one knows the other. The fitted scale itself depends on
|
|
9
|
+
* where the drawing sits: in the row it is `fitScale` from layout.ts, in the
|
|
10
|
+
* pop-out it is `fitBothScale` below.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const ZOOM_MIN = 0.25;
|
|
14
|
+
export const ZOOM_MAX = 4;
|
|
15
|
+
/** Paseo zooms by 1.25 in and 0.8 out; the two are exact inverses. */
|
|
16
|
+
export const ZOOM_STEP = 1.25;
|
|
17
|
+
|
|
18
|
+
const EPSILON = 1e-3;
|
|
19
|
+
|
|
20
|
+
export interface Size {
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function clampZoom(zoom: number): number {
|
|
26
|
+
return Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, zoom));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Snaps away the floating point residue of a multiply-then-divide, so stepping
|
|
31
|
+
* in and back out lands on exactly the value it started from.
|
|
32
|
+
*/
|
|
33
|
+
function snap(zoom: number): number {
|
|
34
|
+
return Math.round(zoom * 1e6) / 1e6;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function zoomIn(zoom: number): number {
|
|
38
|
+
return clampZoom(snap(zoom * ZOOM_STEP));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function zoomOut(zoom: number): number {
|
|
42
|
+
return clampZoom(snap(zoom / ZOOM_STEP));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function canZoomIn(zoom: number): boolean {
|
|
46
|
+
return zoom < ZOOM_MAX - EPSILON;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function canZoomOut(zoom: number): boolean {
|
|
50
|
+
return zoom > ZOOM_MIN + EPSILON;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function sameZoom(a: number, b: number): boolean {
|
|
54
|
+
return Math.abs(a - b) < EPSILON;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function zoomLabel(zoom: number): string {
|
|
58
|
+
return `${Math.round(zoom * 100)}%`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The zoom that shows the whole drawing across the row.
|
|
63
|
+
*
|
|
64
|
+
* The row's own fit stops shrinking at the readability floor and scrolls
|
|
65
|
+
* sideways past it; "fit to view" is the reader asking to see all of it anyway.
|
|
66
|
+
* It never goes above 1, because the default already grows small drawings as
|
|
67
|
+
* far as they should go, and 1 means the request was already satisfied.
|
|
68
|
+
*/
|
|
69
|
+
export function fitRowZoom(rowScale: number, naturalWidth: number, available: number): number {
|
|
70
|
+
if (!(rowScale > 0) || !(naturalWidth > 0) || !(available > 0)) return 1;
|
|
71
|
+
return Math.min(1, snap(available / (naturalWidth * rowScale)));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The scale that fits a drawing inside both axes of a viewport, with `padding`
|
|
76
|
+
* kept clear on every side. Unlike the row, the pop-out grows a small drawing
|
|
77
|
+
* as far as the window allows: seeing it large is the point of popping out.
|
|
78
|
+
*/
|
|
79
|
+
export function fitBothScale(natural: Size, viewport: Size, padding = 0): number {
|
|
80
|
+
const width = viewport.width - padding * 2;
|
|
81
|
+
const height = viewport.height - padding * 2;
|
|
82
|
+
if (!(natural.width > 0) || !(natural.height > 0) || !(width > 0) || !(height > 0)) return 1;
|
|
83
|
+
return Math.min(width / natural.width, height / natural.height);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface ToolbarState {
|
|
87
|
+
zoomIn: boolean;
|
|
88
|
+
zoomOut: boolean;
|
|
89
|
+
fit: boolean;
|
|
90
|
+
popOut: boolean;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Which drawing controls are worth pressing right now. A control that would
|
|
95
|
+
* change nothing is shown quiet rather than hidden, so the toolbar keeps its
|
|
96
|
+
* shape and the reader learns where the limits are.
|
|
97
|
+
*/
|
|
98
|
+
export function toolbarState({
|
|
99
|
+
zoom,
|
|
100
|
+
fitZoom,
|
|
101
|
+
showCode,
|
|
102
|
+
}: {
|
|
103
|
+
zoom: number;
|
|
104
|
+
fitZoom: number;
|
|
105
|
+
showCode: boolean;
|
|
106
|
+
}): ToolbarState {
|
|
107
|
+
if (showCode) return { zoomIn: false, zoomOut: false, fit: false, popOut: false };
|
|
108
|
+
return {
|
|
109
|
+
zoomIn: canZoomIn(zoom),
|
|
110
|
+
zoomOut: canZoomOut(zoom),
|
|
111
|
+
fit: !sameZoom(zoom, fitZoom),
|
|
112
|
+
popOut: true,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import {
|
|
2
|
+
collectLoads,
|
|
3
|
+
compile,
|
|
4
|
+
compileStreaming,
|
|
5
|
+
dataKey,
|
|
6
|
+
evaluate,
|
|
7
|
+
formatDiagnostics,
|
|
8
|
+
imageSearches,
|
|
9
|
+
initialState,
|
|
10
|
+
specToMarkdown,
|
|
11
|
+
type DataRequest,
|
|
12
|
+
type LoadedData,
|
|
13
|
+
type SearchedImage,
|
|
14
|
+
} from "./core";
|
|
15
|
+
import { projectRequests, toMarkdownWithProject } from "./core/markdown";
|
|
16
|
+
import { projectRequestKey, type ProjectRequest, type ProjectResult } from "./core/project";
|
|
17
|
+
import type { UiNode } from "./core/types";
|
|
18
|
+
|
|
19
|
+
type Loader = (request: DataRequest) => Promise<LoadedData>;
|
|
20
|
+
type ImageFinder = (query: string) => Promise<SearchedImage | null>;
|
|
21
|
+
export type ProjectReader = (request: ProjectRequest) => Promise<ProjectResult>;
|
|
22
|
+
|
|
23
|
+
async function findImages(roots: readonly UiNode[], find: ImageFinder | undefined): Promise<Map<string, SearchedImage | null>> {
|
|
24
|
+
if (find === undefined) return new Map();
|
|
25
|
+
return new Map(await Promise.all(imageSearches(roots).map(async (query) => [query, await find(query)] as const)));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function rootsMarkdown(roots: readonly UiNode[], find: ImageFinder | undefined, project: ProjectReader | undefined): Promise<string> {
|
|
29
|
+
const requests = project === undefined ? [] : projectRequests(roots);
|
|
30
|
+
const [images, answers] = await Promise.all([
|
|
31
|
+
findImages(roots, find),
|
|
32
|
+
Promise.all(requests.map(async (request) => [projectRequestKey(request), await project!(request)] as const)),
|
|
33
|
+
]);
|
|
34
|
+
return toMarkdownWithProject(roots, images, new Map(answers));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface Fence {
|
|
38
|
+
open: number;
|
|
39
|
+
close: number;
|
|
40
|
+
language: string;
|
|
41
|
+
body: string;
|
|
42
|
+
closed: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const FENCE_OPEN = /^ {0,3}(`{3,}|~{3,})\s*([A-Za-z0-9_-]*)/;
|
|
46
|
+
|
|
47
|
+
export function findFences(lines: readonly string[]): Fence[] {
|
|
48
|
+
const fences: Fence[] = [];
|
|
49
|
+
for (let index = 0; index < lines.length; index++) {
|
|
50
|
+
const open = FENCE_OPEN.exec(lines[index] ?? "");
|
|
51
|
+
if (open === null) continue;
|
|
52
|
+
const marker = open[1] ?? "```";
|
|
53
|
+
const closing = new RegExp(`^ {0,3}${marker[0] === "`" ? "`" : "~"}{${marker.length},}\\s*$`);
|
|
54
|
+
let close = index + 1;
|
|
55
|
+
while (close < lines.length && !closing.test(lines[close] ?? "")) close++;
|
|
56
|
+
fences.push({
|
|
57
|
+
open: index,
|
|
58
|
+
close,
|
|
59
|
+
language: (open[2] ?? "").toLowerCase(),
|
|
60
|
+
body: lines.slice(index + 1, close).join("\n"),
|
|
61
|
+
closed: close < lines.length,
|
|
62
|
+
});
|
|
63
|
+
index = close;
|
|
64
|
+
}
|
|
65
|
+
return fences;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function appPointer(html: string): string {
|
|
69
|
+
const title = /<title>([^<]{1,120})<\/title>/i.exec(html)?.[1]?.trim();
|
|
70
|
+
return `_Interactive app${title ? `: ${title}` : ""}. Open this reply in Paseo to use it._`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function uiMarkdown(spec: string, load: Loader, find: ImageFinder | undefined, project: ProjectReader | undefined): Promise<string> {
|
|
74
|
+
const { program } = compileStreaming(spec);
|
|
75
|
+
const requests = program === null ? [] : collectLoads(program);
|
|
76
|
+
const data = new Map(await Promise.all(requests.map(async (request) => [dataKey(request), await load(request)] as const)));
|
|
77
|
+
const compiled = compile(spec);
|
|
78
|
+
if (compiled.program === null) return specToMarkdown(spec, data);
|
|
79
|
+
const { roots } = evaluate(compiled.program, initialState(compiled.program, data), data);
|
|
80
|
+
return rootsMarkdown(roots, find, project);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export async function renderReplyMarkdown(text: string, load: Loader, find?: ImageFinder, project?: ProjectReader): Promise<string> {
|
|
84
|
+
const lines = text.split("\n");
|
|
85
|
+
const fences = findFences(lines).filter((fence) => fence.language === "ui" || fence.language === "app");
|
|
86
|
+
if (fences.length === 0) return text;
|
|
87
|
+
const output: string[] = [];
|
|
88
|
+
let next = 0;
|
|
89
|
+
for (const fence of fences) {
|
|
90
|
+
output.push(...lines.slice(next, fence.open));
|
|
91
|
+
output.push(fence.language === "app" ? appPointer(fence.body) : await uiMarkdown(fence.body, load, find, project));
|
|
92
|
+
next = fence.close + 1;
|
|
93
|
+
}
|
|
94
|
+
output.push(...lines.slice(next));
|
|
95
|
+
return output.join("\n");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function checkSpec(
|
|
99
|
+
spec: string,
|
|
100
|
+
load: Loader,
|
|
101
|
+
find?: ImageFinder,
|
|
102
|
+
project?: ProjectReader,
|
|
103
|
+
): Promise<{ readonly ok: boolean; readonly report: string }> {
|
|
104
|
+
const compiled = compile(spec);
|
|
105
|
+
if (compiled.program === null) {
|
|
106
|
+
return { ok: false, report: `The block does not compile:\n${formatDiagnostics(compiled.diagnostics)}` };
|
|
107
|
+
}
|
|
108
|
+
const requests = collectLoads(compiled.program);
|
|
109
|
+
const loaded = await Promise.all(requests.map(async (request) => [request, await load(request)] as const));
|
|
110
|
+
const data = new Map(loaded.map(([request, result]) => [dataKey(request), result] as const));
|
|
111
|
+
const { roots, diagnostics } = evaluate(compiled.program, initialState(compiled.program, data), data);
|
|
112
|
+
const problems = [
|
|
113
|
+
...loaded.flatMap(([request, result]) => (result.ok ? [] : [`${request.path}: ${result.error}`])),
|
|
114
|
+
...(diagnostics.length > 0 ? [formatDiagnostics(diagnostics)] : []),
|
|
115
|
+
];
|
|
116
|
+
const preview = `Text version of what the user will see:\n\n${await rootsMarkdown(roots, find, project)}`;
|
|
117
|
+
return problems.length === 0
|
|
118
|
+
? { ok: true, report: `No errors. ${preview}` }
|
|
119
|
+
: { ok: false, report: `Fix before replying:\n${problems.join("\n")}\n\n${preview}` };
|
|
120
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
collectLoads,
|
|
4
|
+
compile,
|
|
5
|
+
compileStreaming,
|
|
6
|
+
dataKey,
|
|
7
|
+
evaluate,
|
|
8
|
+
initialState,
|
|
9
|
+
} from "./core";
|
|
10
|
+
import { COMPONENTS, type ComponentName } from "./core/catalog";
|
|
11
|
+
import { checkSpec, findFences, renderReplyMarkdown } from "./fallback";
|
|
12
|
+
import {
|
|
13
|
+
AGENT_INSTRUCTIONS,
|
|
14
|
+
CODE_WORK_INSTRUCTIONS,
|
|
15
|
+
UI_REFERENCE,
|
|
16
|
+
UI_REFERENCE_MORE,
|
|
17
|
+
} from "./instructions";
|
|
18
|
+
import { splitTimelineMessage } from "./segment";
|
|
19
|
+
import { listGallery, loadGalleryFile, readGallerySpec } from "../server/data-source";
|
|
20
|
+
|
|
21
|
+
describe("paseo-plugin-genui core, instructions, and gallery", () => {
|
|
22
|
+
it("compiles every example in the agent instructions cleanly", () => {
|
|
23
|
+
for (const section of [
|
|
24
|
+
UI_REFERENCE,
|
|
25
|
+
UI_REFERENCE_MORE,
|
|
26
|
+
CODE_WORK_INSTRUCTIONS,
|
|
27
|
+
AGENT_INSTRUCTIONS,
|
|
28
|
+
]) {
|
|
29
|
+
const fences = findFences(section.split("\n")).filter((f) => f.language === "ui");
|
|
30
|
+
for (const fence of fences) {
|
|
31
|
+
const compiled = compile(fence.body);
|
|
32
|
+
expect(compiled.diagnostics, fence.body).toEqual([]);
|
|
33
|
+
expect(compiled.program).not.toBeNull();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("covers all 86 catalog components in the gallery and compiles + evaluates every gallery spec", async () => {
|
|
39
|
+
const files = await listGallery();
|
|
40
|
+
expect(files.length).toBeGreaterThanOrEqual(170);
|
|
41
|
+
|
|
42
|
+
const covered = new Set<string>();
|
|
43
|
+
for (const file of files) {
|
|
44
|
+
const comp = file.replace(/\.ui$/, "").split("-")[0]!;
|
|
45
|
+
covered.add(comp);
|
|
46
|
+
|
|
47
|
+
const source = await readGallerySpec(file);
|
|
48
|
+
const compiled = compile(source);
|
|
49
|
+
expect(compiled.diagnostics, `${file} compile diagnostics`).toEqual([]);
|
|
50
|
+
expect(compiled.program, `${file} program`).not.toBeNull();
|
|
51
|
+
|
|
52
|
+
const requests = collectLoads(compiled.program!);
|
|
53
|
+
const loadedPairs = await Promise.all(
|
|
54
|
+
requests.map(async (req) => [dataKey(req), await loadGalleryFile(req.path, req)] as const),
|
|
55
|
+
);
|
|
56
|
+
for (const [key, res] of loadedPairs) {
|
|
57
|
+
expect(res.ok, `${file} load ${key}`).toBe(true);
|
|
58
|
+
}
|
|
59
|
+
const data = new Map(loadedPairs);
|
|
60
|
+
const state = initialState(compiled.program!, data);
|
|
61
|
+
const evaluated = evaluate(compiled.program!, state, data);
|
|
62
|
+
expect(evaluated.diagnostics, `${file} evaluate diagnostics`).toEqual([]);
|
|
63
|
+
expect(evaluated.roots.length, `${file} roots`).toBeGreaterThan(0);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (const name of Object.keys(COMPONENTS) as ComponentName[]) {
|
|
67
|
+
expect(covered.has(name), `Gallery example for ${name}`).toBe(true);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("splits assistant messages into prose and streaming/complete ui and app blocks", () => {
|
|
72
|
+
const plain = "Hello world\n```ts\nconst x = 1;\n```";
|
|
73
|
+
expect(splitTimelineMessage(plain, "complete")).toBeUndefined();
|
|
74
|
+
|
|
75
|
+
const streaming = "Here is your estimate:\n```ui\n$seats = 10\nCard(\"Estimate\", [Metric(\"Seats\", $seats)])";
|
|
76
|
+
const splitStream = splitTimelineMessage(streaming, "streaming", "msg_1");
|
|
77
|
+
expect(splitStream?.items).toHaveLength(2);
|
|
78
|
+
expect(splitStream?.items[0]).toMatchObject({
|
|
79
|
+
kind: "genui-text",
|
|
80
|
+
data: { text: "Here is your estimate:", phase: "streaming" },
|
|
81
|
+
});
|
|
82
|
+
expect(splitStream?.items[1]).toMatchObject({
|
|
83
|
+
kind: "genui-block",
|
|
84
|
+
data: {
|
|
85
|
+
language: "ui",
|
|
86
|
+
complete: false,
|
|
87
|
+
fenceIndex: 0,
|
|
88
|
+
messageId: "msg_1",
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const streamCompile = compileStreaming("$seats = 10\nCard(\"Estimate\", [Metric(\"Seats\", $seats");
|
|
93
|
+
expect(streamCompile.program).not.toBeNull();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("renders replies containing ui and app blocks to plain markdown", async () => {
|
|
97
|
+
const reply = [
|
|
98
|
+
"Summary sentence.",
|
|
99
|
+
"```ui",
|
|
100
|
+
'Card("Metrics", [Metric("Latency", "14 ms")])',
|
|
101
|
+
"```",
|
|
102
|
+
"```app",
|
|
103
|
+
"<!doctype html><title>Pendulum</title><canvas></canvas>",
|
|
104
|
+
"```",
|
|
105
|
+
].join("\n");
|
|
106
|
+
|
|
107
|
+
const md = await renderReplyMarkdown(reply, (req) => loadGalleryFile(req.path, req));
|
|
108
|
+
expect(md).toContain("Summary sentence.");
|
|
109
|
+
expect(md).toContain("Latency");
|
|
110
|
+
expect(md).toContain("14 ms");
|
|
111
|
+
expect(md).toContain("Interactive app: Pendulum");
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("validates specs with checkSpec", async () => {
|
|
115
|
+
const valid = await checkSpec(
|
|
116
|
+
'Card("Test", [Metric("Users", "42")])',
|
|
117
|
+
(req) => loadGalleryFile(req.path, req),
|
|
118
|
+
);
|
|
119
|
+
expect(valid.ok).toBe(true);
|
|
120
|
+
expect(valid.report).toContain("No errors.");
|
|
121
|
+
});
|
|
122
|
+
});
|