POST /api/upload had no auth check: anyone could push files to the HF
dataset with the Space owner's token, and any cookie value was cached as
the storage token. It now goes through requireEditor (after the per-IP
rate limit, before the body is buffered), accepts PNG, JPEG, GIF, WebP
and AVIF only (detected from the bytes, SVG refused) and answers 413
past 10 MB.
requireEditor now tells apart 401 (no or invalid session) from 403
(signed in without write access). The citation routes, which fetch
DOIs and URLs on the server, use it too.
Co-authored-by: Cursor <cursoragent@cursor.com>
feat(storage): first-class data - no silent failures in the persistence pipeline
The "Saved" label in the top bar used to be a comforting lie:
several failure modes (createRepo 403 on a missing manage-repos
scope, writeFileSync on a readonly FS, uploadFile mid-debounce
network blip) all collapsed into a console.error that the editor
never surfaced. A user could type for an hour, see "Saved" the
whole time, lose their tab, and discover only after the container
rebuilt that nothing had ever made it to the dataset.
Make every link in the chain observable, and make the worst signal
always win in the UI.
Backend
-------
- In-memory `StorageStatus` tracker in hf-storage.ts:
- `datasetReady` (createRepo succeeded or returned 409)
- `lastLocalSaveAt` / `lastCloudPushAt` epoch ms
- `pendingPush` (a debounce timer is armed)
- `lastError {stage, message, statusCode, at, docName}` where
`stage` is one of `dataset-create | local-save | cloud-push`
Every write path records success; every error path records the
failure. Success on one stage clears the error for …
feat(storage): private dataset by default + /d/* reverse proxy
The dataset that backs persistence was being created `private: false`
on every first write. For org-owned Spaces with strict data
policies (notably `HuggingFaceBio/carbon-tokenization`) this could
either silently fail (org blocks public dataset creation) or be
flat-out wrong (working drafts of an internal research paper
shouldn't be sitting on a public dataset).
Flip the default to `private: true`. The complication this creates
is that published articles' `<img>` tags, og:image and PDF
download all pointed at `huggingface.co/datasets/.../resolve/...`
URLs that would now 401 for anonymous viewers. Solve that with a
small reverse-proxy route on the editor itself.
- New `GET /d/:path*` handler streams from
`huggingface.co/datasets/${id}/resolve/main/${path}` to the
caller, attaching the right HF token along the way:
1. cookie token from the current request (most viewers are
signed in on private Spaces anyway)
2. last-known cached user token (any signed-in request warm…
Three references slipped through the HF Inference migration:
the system diagram, the API route table (/api/chat description)
and the agent sequence diagram all still named OpenRouter as the
LLM backend. Replace them with HF Inference (Providers) to match
the actual implementation in stream-handler.ts.
Co-authored-by: Cursor <cursoragent@cursor.com>
fix(agent): default back to gpt-oss-120b, pin Llama 3.3 to Together
Groq (HF Router's :fastest pick for Llama 3.3 70B) validates tool calls
very strictly and was rejecting the editor's 18-tool registry with
"Failed to call a function. Please adjust your prompt." Fireworks has
deprecated the Llama 3.3 checkpoint; Nscale doesn't support the `tools`
parameter at all. Together serves the same model with full
tool-calling support, so pin Llama 3.3 to `:together`.
Restore openai/gpt-oss-120b as the default - it's HF's trending
tool-calling model and the reasoning-strip fix already covers the
Cerebras round-trip case.
Co-authored-by: Cursor <cursoragent@cursor.com>
fix(agent): strip reasoning_content from history, default to Llama 3.3 70B
Reasoning models (gpt-oss-*, DeepSeek R1, ...) emit a `reasoning` UI part
alongside their text answer. The AI SDK persists those parts and on the
next turn round-trips them as `reasoning_content` on the assistant
message - which some HF Inference Providers (notably Cerebras, the
default for gpt-oss) reject with 400 wrong_api_format. The model doesn't
need to see its own prior reasoning to keep the conversation going, so
filter those parts out before convertToModelMessages.
While we're at it, swap the default model from gpt-oss-120b to
meta-llama/Llama-3.3-70B-Instruct: it doesn't emit reasoning, works
across every provider exposing it, and is a more conservative starting
point for first-time forkers.
Co-authored-by: Cursor <cursoragent@cursor.com>
feat(agent): switch AI backend from OpenRouter to HF Inference Providers
The chat panel and embed studio now call Hugging Face Inference Providers
(OpenAI-compatible router at https://router.huggingface.co/v1) via
@ai-sdk/openai-compatible, using the logged-in editor's OAuth token when
available and falling back to HF_TOKEN. Forking the Space no longer
requires wiring an OpenRouter API key - the user's own HF token funds
their own inference.
- Replace @openrouter/ai-sdk-provider with @ai-sdk/openai-compatible
- Forward the OAuth cookie token per request, fallback to HF_TOKEN
- Refresh AVAILABLE_MODELS to HF-served, tool-calling-capable models
(gpt-oss 120B/20B, Llama 3.3 70B, Qwen3 Coder 480B, DeepSeek V3.1)
- Add inference-api to hf_oauth_scopes and document the new env vars
(HF_INFERENCE_MODEL, expanded HF_TOKEN role) in README + SPECIFICATION
- Update agent-chat tests to expect the new "Hugging Face token" error
Co-authored-by: Cursor <cursoragent@cursor.com>
docs: refresh README, architecture, spec and add agent teams proposal
- README: align env var table with real backend (OPENROUTER_API_KEY, HF_DATASET_ID, SPACE_ID,
PUBLISH_BASE_URL, ENABLE_PDF, OAUTH_SCOPES) and fix prerequisites
- ARCHITECTURE / SPECIFICATION: describe the new transformer pipeline, embed studio flow,
mobile TOC + CommentPopover; drop the deleted CommentsSidebar reference
- TESTS: announce the Playwright E2E suite as part of the stack and add 4.1.4 for the
upload rate limiter; note the split between fast hermetic suite and opt-in E2E
- Add AGENT_TEAMS_PROPOSAL.md to track the upcoming multi-agent collaboration design
Made-with: Cursor
fix: prevent seed race condition with Y.Map guard and defensive checks
- Add Y.Map("meta").seeded flag to prevent multiple clients from
seeding the same empty doc concurrently (Yjs merge duplication)
- Set seededRef early to prevent re-entry
- Add authors array length check in seedFrontmatter as extra guard
Made-with: Cursor