Repository navigation
[feat] canvas: download, import and pick the hosted example canvases - #390
Merged
allendyu merged 7 commits intoNov 19, 2026
Merged
Conversation
allendyu
force-pushed
the
feat/example-canvas-download
branch
4 times, most recently
from
November 18, 2026 02:25
01475d0 to
2a42556
Compare
## summary - Add `exampleCatalog.ts`: strict per-row validation (https on an allowlisted host, unique id, bilingual title, digest/byte types, `minAppVersion` gate) with three-tier loading — remote catalog, then the bundled copy, then a compiled-in list — so a missing file or an offline launch still offers the samples. Unusable rows are reported and dropped instead of hiding the rest. - Add `exampleDownload.ts`: https-only allowlist, streaming body read under a byte budget, deadline and caller cancellation, optional outer and inner SHA-256 checks, and content-based format detection. The shipped links deliver a ZIP wrapping exactly one `.canvas`, so the downloader unwraps one level and reports HTML login pages, non-archives and ambiguous containers separately rather than trusting the file name. - Ship both samples in `public/example-canvases.json` with the sizes and digests measured against the live links on 2026-11-17. - Keep the import call site untouched; the dialog that uses these modules and the `readCanvasArchive` hand-off follow in the next commit. ## validation - `node --test tests/exampleCatalog.test.ts tests/exampleDownload.test.ts`: 25 passed. - `tsc --noEmit` clean; `pre-commit run` clean after the hook normalized line endings. - Full frontend suite 856/857; the only failure is the pre-existing `browserHost` CJK temp-path case that also fails on clean `main`. - Manual end-to-end against the shipped links: both downloaded, unwrapped and read by `readCanvasArchive` (image: 12 nodes/5 assets; video: 17 nodes/ 9 assets), which also proves the recorded outer and inner digests.
## summary - Add `ExampleCanvasDialog`: a native `<dialog>` listing the catalog with the localized title, summary, size and archive version. Each row owns its status, so one failing sample never blocks the others. - Add `useExampleImport` and `runExampleImport`: download, hand the unwrapped archive to the caller's import path, and report `downloading → importing → done`. Cancelling during download returns the row to idle instead of showing an error, and a cancel that lands after the bytes arrive skips the import entirely. - Keep the archive out of component state: the blob is created for the import call and dropped afterwards, so no downloaded copy survives the import. - Classify failures for the reader — HTTP status, blocked page, non-archive, ambiguous container, digest mismatch, untrusted address — instead of showing one generic message. - Add an explicit manual-import fallback per row (share link plus code) for cases the hosted link itself is gone. - Add the 27 bilingual strings and register the catalog's Chinese sample names in `scripts/i18n-baseline.json`: they are data, not translatable UI copy. ## validation - `node --test tests/exampleImport.test.ts tests/exampleCatalog.test.ts tests/exampleDownload.test.ts`: 30 passed. - `tsc --noEmit` clean; `check-i18n` 0 problems; `pre-commit run` clean after the hook normalized line endings. - Full frontend suite 861/862; the only failure is the pre-existing `browserHost` CJK temp-path case that also fails on clean `main`. ## notes - The dialog is not rendered yet; wiring the empty-state button and the `readCanvasArchive` hand-off is the next change.
## summary - Wire the empty-state button to the picker: clicking "try the example canvas" loads the catalog and opens the dialog directly, so a fresh install with no local sample still has something to open. - Split the archive import in `useWorkspaceTransfer`: `importCanvasArchive` reads the archive, lands it as a project and returns the title/asset count while throwing on failure; `importDocument` keeps the toast-and-notify behaviour the file drop path already had. The picker uses the throwing variant so its own classifier can name the cause. - Leave the running version out of the `minAppVersion` gate: the frontend does not expose its own version yet, and filtering on an absent value would hide every sample. The gate still applies once a version is supplied. - Show the localized archive error when a failure has no dedicated code (for example "archive is newer than this app") instead of a generic message. - Keep the in-browser generated example and its `openExampleWorkspaceProject` recovery path intact for the paths that still use them. ## validation - `node --test tests/*.test.ts`: 862/863 passed. The only failure is the pre-existing `browserHost` CJK temp-path case that also fails on `main`. - `node --test` on the three example suites: 31 passed. - `tsc --noEmit` clean; `check-i18n` 0 problems; `pre-commit run` clean. - `vite build` succeeds and the output contains the dialog markup, the built-in catalog and `dist/example-canvases.json` with both entries, so the compiled fallback ships with the app. ## notes - The picker is clickable from the empty canvas now; a browser test that drives the download, the failure codes and the cache release follows next.
…he gate lane ## summary - Release the download explicitly: `fetchExampleCanvas` now returns a `release` handle that zeroes the wrapper and the unwrapped buffers, and `runExampleImport` calls it in a `finally`, so success, failure and cancel all leave no archive copy behind. The import result carries only metadata (`kind`, `innerEntry`, `outerBytes`), never the bytes. - Add `tests/browser/example_canvas_picker.mjs` and run it from `scripts/run-browser-suite.mjs` in the `gate` lane. It builds the fixture with the real exporter, serves it as a ZIP around one `.canvas`, and asserts: the empty canvas opens the picker, the wrapped download imports and switches to a two-node canvas, and an HTML page is reported without creating a project while the manual-import fallback stays reachable. Both the catalog and the sample are routed in-page, so the check needs no external host. - Document the picker in both user guides, including the ZIP-around-`.canvas` unwrapping and the manual fallback. ## validation - `node --test tests/*.test.ts`: 864/865. The only failure is the pre-existing `browserHost` CJK temp-path case that also fails on `main`. - The three example suites: 33 passed, including the new release assertions (buffers zeroed, idempotent, released on success and on import failure). - `tsc --noEmit` clean; `check-i18n` 0 problems; `check-browser-manifest` `80 entries, gate=24`; `check-browser-locale` 0 problems; `pre-commit` clean. ## verification limit - The browser check was **not executed here**: this machine cannot download a Chromium build (the Playwright CDN is unreachable and the cached archive is truncated). The manifest and locale checks confirm it is registered and synthesised correctly; the gate lane runs it on CI.
…ow progress ## summary - Fix the dark-mode overlap: the picker used `--cw-control-*`, which the app only defines under `[data-theme="light"]`, so in the default dark theme the dialog had no background and the empty canvas showed through its text. Dark colours are now the base and the light theme overrides them, matching how the other dialogs are themed. The backdrop is opaque enough to stop the bleed. - Drop the archive version from each row; the row now shows only the measured size. The size/version message keys are removed in both locales. - Show real download progress: the streaming reader reports received bytes and the declared total, the import status carries them, and the row renders a native `<progress>` bar with a percentage. When the server sends no `content-length` the bar stays indeterminate instead of inventing a total. - Release the download as soon as the import settles (success, failure or cancel), so the progress work does not leave a second copy behind. ## validation - `node --test tests/*.test.ts`: 867/868. The only failure is the pre-existing `browserHost` CJK temp-path case that also fails on `main`. - The three example suites: 36 passed, including new assertions that progress starts at 0 with the declared total, ends at the full size, and reports an unknown total when the header is absent. - `tsc --noEmit` clean; `check-i18n` 0 problems; `check-browser-manifest` and `check-browser-locale` clean; `vite build` succeeds and the emitted CSS now carries `background:#23242b` for the dialog. ## notes - The browser check still runs only on CI; this machine cannot fetch a Chromium build.
## summary - Add an "example canvases" row to the project menu, above "new canvas project". It opens the same picker the empty canvas offers, so choosing another sample no longer requires switching back to an empty canvas first. - Reuse the existing footer row styling instead of a new block, and close the menu before loading the catalog so the dialog is not stacked under it. - Extend the gate browser check: after closing the picker once, it opens the project menu, chooses the new row and asserts the picker comes back. ## validation - ode --test tests/*.test.ts: 867/868. The only failure is the pre-existing �rowserHost CJK temp-path case that also fails on main. - sc --noEmit clean; check-i18n 3061 keys, 0 problems; check-browser-manifest and check-browser-locale clean; �ite build succeeds. ## notes - The browser check still runs only on CI; this machine cannot fetch a Chromium build.
## summary - Replace the single "try the example canvas" button with two buttons on the same row as "configure models": 体验图片画布 and 体验视频画布. Each imports its own sample directly, showing a live progress bar, and the imported canvas then replaces the empty state so nothing lingers. - Bundle the catalog into the app instead of fetching it from the site root. The packaged server only mounts `/assets` and `/fonts`, so `/example-canvases.json` answered 404 and that fallback tier never worked outside the Vite dev server. The JSON now lives in `src/` and is imported with a JSON attribute, which also removes the second copy of the same data that used to live in TypeScript. - Keep the full picker behind the project menu, share the failure wording and the percentage calculation through `exampleFailure.ts`, and cache the loaded catalog so both entries and the picker resolve without refetching. - `useExampleImport.start` now reports success, which lets the caller clear the finished row immediately. ## validation - `node --test tests/*.test.ts`: 868/869. The only failure is the pre-existing `browserHost` CJK temp-path case that also fails on `main`. - The three example suites: 37 passed, including the bundled-copy tier and the progress events. - `tsc --noEmit` clean; `check-i18n` 3062 keys, 0 problems (the baseline drops from 173 to 165 lines because the sample titles moved from TypeScript into JSON); `check-browser-manifest` and `check-browser-locale` clean. - `vite build` succeeds and the bundle carries the catalog ids and URLs, while `dist/` no longer ships a root JSON file. - Reinstalled with `pip install -e ".[test]"` and served the packaged app: `/` answers 200, 8 projects read, 13 model configs, and the buttons download with a live percentage (evidence attached to the pull request). ## notes - The gate browser check covers both entry points; it still runs only on CI.
allendyu
force-pushed
the
feat/example-canvas-download
branch
from
November 19, 2026 02:27
2a42556 to
5ef5856
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Let the empty canvas offer a real example: import the two hosted samples from buttons next to "configure models", unwrap whatever the host serves, import it through the existing archive path, and open it. The full picker stays behind the project menu.
received / declared total, indeterminate when the host sends no length), then the imported canvas replaces the empty state. A failed attempt prints the same per-code sentence the picker uses; retrying clears it.workspace/example/exampleCatalog.ts): strict per-row validation (https on an allowlisted host, unique id, bilingual title, digest/byte types,minAppVersiongate). The bundled copy is imported JSON, not a file fetched from the site root: the packaged server only mounts/assetsand/fonts, so/example-canvases.jsonanswered 404 and that tier silently fell through. Importing it also removes the duplicate copy of the same data that lived in TypeScript.exampleDownload.ts): streaming read under a byte budget, deadline and cancellation, content-based detection. The shipped links deliver a ZIP wrapping exactly one.canvas, so the downloader unwraps one level and reports an HTML page, a non-archive or an ambiguous container separately instead of trusting the file name.sha256is checked against a direct archive andinner.sha256against the.canvasa wrapper carries. The shipped catalog therefore pins no transport digest, and the crash-prone outer check is gone from the fetch path.releasehandle that zeroes the wrapper and unwrapped buffers, called from afinally.readCanvasArchiveandimportWorkspaceDocumentremain the only import path; the transfer hook exposes a throwingimportCanvasArchiveso the picker can classify the cause while the file-drop path keeps its toast behaviour.Linked issue
No issue applies: this was scoped from a local design note rather than a repository issue. Happy to open a tracking issue if you prefer the work linked before merge.
Fixes #NorRefs #Nis included, or no issue appliesLabels
type:feat,area:canvas,area:docsTest plan
node --test tests/*.test.ts→ 874/875. The only failure,browserHost"Python discovery supports PATH-only installs…", is pre-existing on cleanmainin this Windows environment (CJK temp path resolves asALLEN_~1).exampleCatalog,exampleDownload,exampleImport) → 38 passed: catalog validation and both fallback tiers, ZIP-vs-canvas detection, ambiguous/nested archives, HTML bodies, streaming size cap, declaredcontent-lengthshort-circuit, digest semantics (direct archive vs wrapper), progress events, and release on success/failure/cancel.tests/browser/example_canvas_picker.mjswas executed locally and passes. Playwright's own browser download is blocked on this machine, so the check ran against the installed Chrome 157 throughCHROMIUM_PATH, with the isolated creation server and the Vite dev server. It covers: the empty-state button downloads with visible progress, the import completes and the bar disappears, the project menu still opens the picker, and an HTML response is reported inline without creating a project..canvas(27.7 MB / 26.1 MB), and are read byreadCanvasArchive— image: 12 nodes / 5 assets; video: 17 nodes / 9 assets.pip install -e ".[test]"and served the packaged build:/200, projects readable, 13 model configs, buttons download with a live percentage (evidence below). This is what exposed the 404 on/example-canvases.json.tsc --noEmitclean;check-i18n3065 keys 0 problems (baseline 173 → 165, because the sample titles moved from TypeScript into JSON);check-browser-manifest80 entries (gate=24);check-browser-locale0 problems;vite buildsucceeds.Evidence that it works
Empty canvas with the two buttons and the live progress bar:
The full picker in dark mode (opaque panel, size only):
The project-menu entry that reaches the same picker:
Provider verification
Bilingual UI
canvas.project.examples, and 27canvas.example.*keys inzh-CNanden-US; user guides updated in both languages.Notes for the reviewer
lanzoushares throughlz.qaiu.topto a Qiniu CDN path that contains a date, so the catalog stores the parser URL and re-resolves on every click (cache: "no-store"). If a link dies, the row reports the failure and the picker still offers manual import; swapping links is a catalog change only. Moving the two.canvasfiles to our own object storage would remove the dependency and let the catalog pin a real digest again.minAppVersionfiltering is inert until the frontend exposes its own version; unknown versions skip the gate rather than hiding every sample.