@skyphusion/create-prism 1.0.4 → 1.3.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 (45) hide show
  1. package/README.md +10 -8
  2. package/index.js +3 -2
  3. package/package.json +1 -1
  4. package/template/CONTRIBUTING.md +18 -3
  5. package/template/MIGRATIONS.md +52 -0
  6. package/template/README.md +79 -52
  7. package/template/docs/legal/INSTANCE-ACCEPTABLE-USE.md +5 -2
  8. package/template/docs/legal/INSTANCE-PRIVACY.md +128 -27
  9. package/template/migrations/0005_auth_attempts_retention.sql +23 -0
  10. package/template/package.json +6 -6
  11. package/template/public/app.js +21 -8
  12. package/template/public/index.html +23 -9
  13. package/template/public/styles.css +45 -7
  14. package/template/public/url-safety.js +6 -6
  15. package/template/schema.sql +6 -0
  16. package/template/src/ai-binding.ts +125 -3
  17. package/template/src/auth.ts +6 -0
  18. package/template/src/env.ts +38 -10
  19. package/template/src/gateway-credentials.ts +118 -22
  20. package/template/src/index.ts +2 -0
  21. package/template/src/providers/anthropic.ts +4 -4
  22. package/template/src/providers/openai-image.ts +10 -0
  23. package/template/src/providers/xai.ts +4 -4
  24. package/template/src/rate-limit.ts +26 -0
  25. package/template/src/routes/chat.ts +18 -9
  26. package/template/src/routes/prefs.ts +46 -5
  27. package/template/src/routes/rag.ts +135 -61
  28. package/template/src/routes/shared.ts +27 -11
  29. package/template/src/routes/workflow.ts +2 -5
  30. package/template/src/skyphusion-search.ts +108 -0
  31. package/template/src/user-prefs.ts +16 -3
  32. package/template/src/version.ts +1 -1
  33. package/template/tests/ai-binding-rest.test.ts +154 -0
  34. package/template/tests/csp.test.ts +11 -6
  35. package/template/tests/gateway-credentials.test.ts +101 -3
  36. package/template/tests/openai-image.test.ts +21 -1
  37. package/template/tests/rag-metadata-filter.test.ts +135 -0
  38. package/template/tests/skip-link.test.ts +164 -0
  39. package/template/tests/skyphusion-search.test.ts +144 -0
  40. package/template/tests/vectorize-backfill-metadata.test.ts +166 -0
  41. package/template/tests-integration/auth.test.ts +346 -2
  42. package/template/tests-integration/pdf-extract.test.ts +71 -0
  43. package/template/wrangler.example.toml +26 -11
  44. package/template/src/searxng.ts +0 -75
  45. package/template/tests/searxng.test.ts +0 -51
@@ -37,8 +37,12 @@ lose it, we have no way to email you a reset.
37
37
  - **Your content:** the prompts and chats you write, and the images, video, music, and voice you
38
38
  generate, plus any documents you add for retrieval (RAG). These are stored in the instance D1
39
39
  database and R2 bucket, keyed to your account by a stable, opaque account id.
40
- - **Your AI Gateway settings:** the gateway slug and Cloudflare AI Gateway token you enter so the
41
- instance can run models on **your** account (see "How model inference is billed and routed" below).
40
+ - **Your AI Gateway settings:** the Cloudflare account ID, the gateway slug, and the Cloudflare AI
41
+ Gateway token you enter so the instance can run models on **your** account (see "How model inference
42
+ is billed and routed" below).
43
+ - **Your control-plane client key, if you enter one:** the `pcp_` key that switches chat onto the
44
+ Skyphusion-operated metered route (see "Metered chat through play-proxy" below). You only have one if
45
+ Skyphusion Labs issued it to you.
42
46
  - **Operational records** mechanically required to run the service: request and job state, and
43
47
  abuse-control counters (see "Abuse controls" below).
44
48
 
@@ -51,23 +55,105 @@ reference R2 keys.
51
55
 
52
56
  ## How model inference is billed and routed (bring your own gateway)
53
57
 
54
- The hosted instance does **not** pay for your model inference. Before you can run a paid or proxied
55
- model you enter your own **Cloudflare AI Gateway** slug and an AI Gateway token in Account settings.
56
- The instance stores those in its D1 database and uses them to send your model requests through **your**
57
- AI Gateway, so inference is billed to **your** Cloudflare Unified Billing account, not ours. The
58
- hosted worker has no gateway credentials of its own; with your settings unset, paid model calls fail
59
- closed with a clear prompt to configure your gateway, rather than silently billing anyone else.
60
-
61
- Treat the AI Gateway token you enter as you would any API credential. It is held in the instance
62
- database solely to authorize your model calls, and deleting your account (below) removes it along with
63
- everything else.
64
-
65
- ## Abuse controls (transient IP processing)
58
+ Before you can run a model you enter three things in Account settings: your **Cloudflare account ID**,
59
+ your **AI Gateway** slug, and a Cloudflare API token for that account. The instance stores them in its D1
60
+ database and uses them to send your model requests to **your** Cloudflare account and gateway, so that
61
+ inference is billed to **your** Cloudflare account, not ours. With any of the three missing, model calls
62
+ fail closed with a prompt naming what is missing, rather than running on our account. (The one route
63
+ that does not need the three is metered chat through play-proxy, below, which only exists if you have
64
+ entered a control-plane client key; everything other than chat still fails closed without them.)
65
+
66
+ **One exception: a few models run on our Cloudflare account.** Some Workers AI models cannot be routed
67
+ through an AI Gateway at all, so the instance runs them on its own Cloudflare account: live voice chat,
68
+ Deepgram file transcription, and six image models (FLUX.2 Klein 9B / Klein 4B / Dev, Leonardo Phoenix
69
+ 1.0, Dreamshaper 8 LCM, Stable Diffusion XL). For those, your prompt or audio goes to Cloudflare Workers
70
+ AI under our account rather than yours, and we pay for them.
71
+
72
+ **Correction (v1.1.0).** Earlier versions of this notice said your requests went through your gateway
73
+ whenever you entered a slug and token. That was not true: without an account ID the instance could only
74
+ address gateways on our own Cloudflare account, so those requests never reached your gateway. The
75
+ instance now requires the account ID and routes to your account; settings saved without one are refused
76
+ until you add it.
77
+
78
+ Treat the API token you enter as you would any API credential. It is held in the instance database
79
+ solely to authorize your model calls, and deleting your account (below) removes it along with
80
+ everything else. Your account ID is not a secret (it appears in every gateway URL) but is stored and
81
+ deleted the same way.
82
+
83
+ ## Metered chat through play-proxy (optional; a Skyphusion-operated route)
84
+
85
+ This section applies only if you have entered a **control-plane client key** (it starts with `pcp_`)
86
+ under Account settings > AI Gateway. Skyphusion Labs issues those keys by enrollment; if you never
87
+ entered one, nothing in this section happens and chat runs through your own gateway as described above.
88
+
89
+ **Correction.** Earlier versions of this notice did not mention this route at all, and said every model
90
+ request went through the gateway you configure. That was incomplete: the route has existed since Prism
91
+ v0.175.0 and the key has been stored with your gateway settings since then. The route itself is
92
+ unchanged; this section is the disclosure that was missing.
93
+
94
+ **Where your chat goes.** While a key is saved, your chat turns, and the conversation compaction that
95
+ summarizes older turns, are sent to `https://play-proxy.skyphusion.org`, a service called
96
+ prism-control-plane that Skyphusion Labs operates on its own Cloudflare account, instead of to your
97
+ gateway. That hostname is fixed in the software and checked against an allowlist on every call; you
98
+ cannot point it elsewhere from your account, and neither can anyone holding your key. Inference on this
99
+ route is metered against the control-plane account the key belongs to, not billed to your Cloudflare
100
+ account.
101
+
102
+ **What is sent.** For each chat turn: the model you chose; the system prompt in effect for that
103
+ conversation, which includes any compaction digest of earlier turns and, when you have retrieval or web
104
+ search switched on for the turn, the document excerpts and search snippets retrieved for it; the text of
105
+ the earlier turns still in context; your current message, including text extracted from any attachment;
106
+ and your client key, as the credential. Images are not forwarded on this route: a turn with an image
107
+ attached is refused with an error naming the control-plane route, rather than sent. Image, video, music,
108
+ and voice generation, transcription, document ingestion, and web search never use this route; they stay
109
+ exactly as described elsewhere in this notice.
110
+
111
+ **What comes back, and what this instance keeps.** The model's reply, token counts, and a request id.
112
+ The reply is stored with the turn in your chat the same way as on any other route, and the request id is
113
+ stored on that chat row. Both are deleted with your account.
114
+
115
+ **What the control plane keeps.** prism-control-plane is open source (AGPL-3.0-only) and publishes its
116
+ own retention statement as a binding part of its contract: it never stores prompt or completion text,
117
+ and a test in that repository fails the build if a column that could hold message text is ever added.
118
+ Its usage ledger keeps, per request, the token counts, the cost, the model id, the status, a request id,
119
+ and the id of the client key that made the call, plus a last-seen time on the key. That ledger is a
120
+ billing record; the control plane does not publish a deletion window for it, and deleting your Prism
121
+ account removes the key from this instance but does not touch that ledger. Read the statement itself:
122
+ [Privacy invariant in `docs/CONTRACT.md`](https://github.com/skyphusion-labs/prism-control-plane/blob/main/docs/CONTRACT.md#privacy-invariant-binding-on-every-version-of-this-contract)
123
+ and the matching section of its
124
+ [README](https://github.com/skyphusion-labs/prism-control-plane/blob/main/README.md#privacy-invariant).
125
+
126
+ **Beyond the control plane.** The control plane forwards your request to the provider that serves the
127
+ model you chose (the catalog names the provider) through an AI Gateway on Skyphusion Labs' Cloudflare
128
+ account with payload logging hard-wired off, so neither we nor Cloudflare keep the prompt or completion
129
+ bodies there. Cloudflare keeps a metadata row for each call (token counts, model, provider, status, cost,
130
+ duration; no content) under its own AI Gateway log retention. The model provider receives your prompt
131
+ content in order to return a result and handles it under its own terms, exactly as it would through
132
+ your own gateway.
133
+
134
+ **The key itself.** It is stored in the instance database alongside your gateway settings, shown back to
135
+ you only masked, cleared whenever you choose "clear control plane key" in Account settings, and deleted
136
+ with your account (below).
137
+
138
+ ## Abuse controls (bounded IP processing for signup and login)
66
139
 
67
140
  To keep signup and login from being abused, the instance rate-limits those requests. It does this by
68
141
  counting recent attempts against the caller's IP address (the address Cloudflare reports at the edge)
69
- and, for login, the username being tried. IP addresses are processed for this abuse-control purpose
70
- only; we do not use them to profile you, build a history, or track you across sessions.
142
+ and, for login, the username being tried. A counter row holds that key, a count, and the start of its
143
+ counting window, and nothing else. IP addresses are processed for this abuse-control purpose only; we
144
+ do not use them to profile you, build a history, or track you across sessions.
145
+
146
+ **How long a counter lives: at most 24 hours.** The counting windows are short (15 minutes for login,
147
+ 1 hour for signup); 24 hours is the outer bound on how long a row can sit in the database before it is
148
+ removed, and it is deliberately far longer than any counting window so a prune can never discard a
149
+ counter a rate-limit decision still depends on. A successful login clears its own counter immediately,
150
+ and every signup or login attempt deletes every counter older than 24 hours, so an address that stops
151
+ coming back is erased by the next attempt from anyone. The deletion runs on the write path itself, not
152
+ on a scheduled job, so a self-hosted instance inherits the same bound with no extra configuration.
153
+
154
+ **Correction (v1.1.1).** Earlier versions of this notice called this processing "transient" without
155
+ saying what that meant, and in fact nothing removed a counter that never saw a successful login: those
156
+ rows persisted indefinitely. v1.1.1 added the 24-hour bound above.
71
157
 
72
158
  ## What we do not do
73
159
 
@@ -80,24 +166,39 @@ not sell your data and we do not share it, with the single exception of the abus
80
166
  The hosted instance runs on Cloudflare (Workers, D1, R2, Vectorize). Your model requests are sent
81
167
  through the AI Gateway **you** configure, on your own Cloudflare account; the model providers reachable
82
168
  through that gateway receive your prompt content in order to return a result, and handle it under their
83
- own and your gateway's terms rather than ours.
169
+ own and your gateway's terms rather than ours. There are two exceptions: the short list of models above
170
+ that run on our Cloudflare account, which Cloudflare Workers AI processes under our account; and, only
171
+ if you have entered a control-plane client key, chat through play-proxy as described in "Metered chat
172
+ through play-proxy" above.
84
173
 
85
174
  **Web search is opt-in and does not use any third-party search API.** Prism has a per-turn web search
86
- toggle. When you switch it on for a turn, the text of that one query is sent to the instance's own
87
- self-hosted search service (SearXNG, run by Skyphusion Labs) and to keyless public sources such as
88
- Wikipedia. No third-party search-API provider (and no per-provider API key) is in the path. The
89
- snippets that come back are stored with the turn as retrieved context, the same way your RAG chunks
90
- are. Your chat history, your uploaded documents, and your generated media are never sent out for
91
- search. Leave the toggle off and no query leaves the instance.
175
+ toggle. When you switch it on for a turn, the text of that one query is sent to two places, and nowhere
176
+ else. One is Wikipedia (the public MediaWiki search endpoint), which needs no key. The other is the
177
+ `skyphusion-search` Worker, a Skyphusion Labs Worker on the same Cloudflare account, reached by a
178
+ service binding named `SEARCH` (not over the public internet, and not with an API key). That Worker
179
+ searches Skyphusion's public corpus. If the binding is not configured, that half does not run and the
180
+ response says so (`sources.web.status` is `absent`). If the call fails, the response says `failed`
181
+ rather than pretending the corpus had nothing. Wikipedia still answers in both cases. The snippets
182
+ that come back are stored with the turn as retrieved context, the same way your RAG chunks are. Your
183
+ chat history, your uploaded documents, and your generated media are never sent out for search. Leave
184
+ the toggle off and no query leaves the instance.
185
+
186
+ **Correction (2026-11-12).** Earlier versions of this notice said the query also went to a self-hosted
187
+ search service at search.skyphusion.org, and then that the hosted instance had no such service. That
188
+ host is gone. This version sends the query to the `skyphusion-search` Worker as described above. The
189
+ hosted worker has no search secret to remove.
92
190
 
93
191
  ## Deleting your data
94
192
 
95
193
  Account deletion is built into the app. From Account settings you delete your account (re-entering your
96
194
  password to confirm), and it **cascades**: it removes your account record and sessions, your chats and
97
- conversations, every generated artifact and uploaded document in R2, your RAG embeddings in Vectorize,
98
- your projects, and your stored AI Gateway settings. Deletion is on you and takes effect on the
99
- instance; we do not keep a shadow copy. If you self-host Prism instead, deletion is entirely in your
100
- hands on your own instance.
195
+ conversations (including the compaction digests of your conversations, which v1.1.1 added to the
196
+ cascade; before it, account deletion left those digests behind), every generated artifact and uploaded
197
+ document in R2, your RAG embeddings in Vectorize,
198
+ your projects, and your stored AI Gateway settings, including any control-plane client key. Deletion is
199
+ on you and takes effect on the instance; we do not keep a shadow copy. What the control plane's billing
200
+ ledger holds about calls made with your key is not on this instance; see "What the control plane keeps"
201
+ above. If you self-host Prism instead, deletion is entirely in your hands on your own instance.
101
202
 
102
203
  ## The one bright line
103
204
 
@@ -0,0 +1,23 @@
1
+ -- 0005: index the auth_attempts prune column (prism#192).
2
+ --
3
+ -- WHY THIS EXISTS: src/rate-limit.ts now prunes auth_attempts on write, the way
4
+ -- src/routes/csp-report.ts prunes csp_reports, because the hosted privacy
5
+ -- notice calls that section "transient IP processing" and nothing was actually
6
+ -- making it transient. Rows were removed only by a SUCCESSFUL login clearing
7
+ -- its own bucket, so a signup bucket, or a login:<ip>:<username> bucket that
8
+ -- never saw a success, persisted indefinitely.
9
+ --
10
+ -- The prune filters on window_start, which was unindexed; auth_attempts has
11
+ -- only its bucket_key primary key. csp_reports already carries
12
+ -- idx_csp_reports_received for exactly the same reason, so this matches the
13
+ -- established pattern rather than inventing one. The table is small (one row
14
+ -- per IP / username bucket), but the prune runs on EVERY signup and login
15
+ -- attempt, which is the hot path the limiter is supposed to protect.
16
+ --
17
+ -- No data change and no new column: safe to re-apply.
18
+ --
19
+ -- Apply to an existing database with:
20
+ -- npx wrangler d1 execute skyphusion-llm --remote --file=migrations/0005_auth_attempts_retention.sql
21
+ -- Fresh databases get this from schema.sql.
22
+
23
+ CREATE INDEX IF NOT EXISTS idx_auth_attempts_window ON auth_attempts(window_start);
@@ -17,16 +17,16 @@
17
17
  "db:migrate:remote": "wrangler d1 execute skyphusion-llm --remote --file=schema.sql"
18
18
  },
19
19
  "dependencies": {
20
- "unpdf": "^1.8.0",
20
+ "unpdf": "^2.1.0",
21
21
  "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
22
22
  },
23
23
  "devDependencies": {
24
- "@cloudflare/vitest-pool-workers": "^0.20.3",
25
- "@cloudflare/workers-types": "^5.20260809.1",
26
- "@types/node": "^26.2.0",
27
- "@vitest/coverage-v8": "^4.1.10",
24
+ "@cloudflare/vitest-pool-workers": "^0.23.0",
25
+ "@cloudflare/workers-types": "^5.20261108.1",
26
+ "@types/node": "^26.6.6",
27
+ "@vitest/coverage-v8": "^4.1.12",
28
28
  "typescript": "^7.0.2",
29
29
  "vitest": "^4.1.8",
30
- "wrangler": "^4.120.0"
30
+ "wrangler": "^4.158.0"
31
31
  }
32
32
  }
@@ -374,8 +374,11 @@ function renderGatewayBanner() {
374
374
  }
375
375
  gatewayBanner.hidden = false;
376
376
  if (gatewayBannerText) {
377
- gatewayBannerText.textContent =
378
- "Inference not configured. Set AI Gateway (BYOK) or a control-plane pcp_ client key under Account settings.";
377
+ // v1.1.0: saved before account ids existed (slug + token only). Say the
378
+ // one thing that is missing rather than "not configured".
379
+ gatewayBannerText.textContent = g.account_id_required
380
+ ? "Add your Cloudflare account ID under Account > AI Gateway. Without it your gateway is unreachable, so model calls are refused."
381
+ : "Inference not configured. Set AI Gateway (BYOK) or a control-plane pcp_ client key under Account settings.";
379
382
  }
380
383
  }
381
384
 
@@ -877,7 +880,7 @@ function renderRetrievedChunksHTML(chunks) {
877
880
  if (c.source_type === "web") {
878
881
  const score = (typeof c.score === "number") ? ` \u00b7 score ${c.score.toFixed(3)}` : "";
879
882
  const sourceLabel =
880
- c.source === "searxng" ? "web" :
883
+ c.source === "searxng" || c.source === "skyphusion-search" ? "web" :
881
884
  c.source === "wikipedia" ? "wikipedia" : "web";
882
885
  return `
883
886
  <details class="retrieved-chunk retrieved-web">
@@ -1435,7 +1438,7 @@ async function run() {
1435
1438
  if (m.type === "chat" && useDocsCheckbox.checked && state.documentCount > 0) {
1436
1439
  requestBody.use_docs = true;
1437
1440
  }
1438
- // v0.17.0: web search. Chat models only; SearXNG + Wikipedia when toggled (v0.166.0).
1441
+ // v0.17.0: web search. Chat models only; skyphusion-search + Wikipedia when toggled.
1439
1442
  if (m.type === "chat" && useWebSearchCheckbox.checked) {
1440
1443
  requestBody.use_web_search = true;
1441
1444
  }
@@ -1508,7 +1511,8 @@ async function run() {
1508
1511
  userInput.focus();
1509
1512
  // #80 fail-closed: 412 = no AI Gateway BYOK and no control-plane pcp_ key.
1510
1513
  // Open the account modal so either path can be configured.
1511
- if (err.status === 412 || err.code === "gateway_not_configured" || err.code === "cf_aig_token_required") {
1514
+ if (err.status === 412 || err.code === "gateway_not_configured" || err.code === "cf_aig_token_required"
1515
+ || err.code === "gateway_account_id_required") {
1512
1516
  openGatewayModal();
1513
1517
  }
1514
1518
  } finally {
@@ -2188,6 +2192,7 @@ const projectModalCancel = $("#project-modal-cancel");
2188
2192
  const projectModalDelete = $("#project-modal-delete");
2189
2193
 
2190
2194
  const gatewayModal = $("#gateway-modal");
2195
+ const gatewayModalAccount = $("#gateway-modal-account");
2191
2196
  const gatewayModalId = $("#gateway-modal-id");
2192
2197
  const gatewayModalToken = $("#gateway-modal-token");
2193
2198
  const gatewayModalTokenHint= $("#gateway-modal-token-hint");
@@ -2354,6 +2359,7 @@ async function openGatewayModal() {
2354
2359
  if (gatewayModalClearCp) gatewayModalClearCp.checked = false;
2355
2360
  try {
2356
2361
  const prefs = await api("/api/prefs");
2362
+ if (gatewayModalAccount) gatewayModalAccount.value = prefs.account_id || "";
2357
2363
  gatewayModalId.value = prefs.gateway_id || "";
2358
2364
  if (gatewayModalTokenHint) {
2359
2365
  gatewayModalTokenHint.textContent = prefs.cf_aig_token_set
@@ -2377,6 +2383,8 @@ async function openGatewayModal() {
2377
2383
  source: prefs.source,
2378
2384
  gateway_id: prefs.gateway_id,
2379
2385
  cf_aig_token_set: prefs.cf_aig_token_set,
2386
+ account_id: prefs.account_id,
2387
+ account_id_required: !!prefs.account_id_required,
2380
2388
  control_plane_configured: !!prefs.control_plane_configured,
2381
2389
  };
2382
2390
  renderGatewayBanner();
@@ -2387,7 +2395,8 @@ async function openGatewayModal() {
2387
2395
  gatewayModalError.hidden = false;
2388
2396
  }
2389
2397
  gatewayModal.hidden = false;
2390
- gatewayModalId.focus();
2398
+ if (gatewayModalAccount && !gatewayModalAccount.value) gatewayModalAccount.focus();
2399
+ else gatewayModalId.focus();
2391
2400
  }
2392
2401
 
2393
2402
  function closeGatewayModal() {
@@ -2412,7 +2421,9 @@ function showGatewayModalError(msg) {
2412
2421
 
2413
2422
  async function saveGatewayModal() {
2414
2423
  const gateway_id = gatewayModalId.value.trim();
2424
+ const account_id = gatewayModalAccount ? gatewayModalAccount.value.trim() : "";
2415
2425
  const body = {};
2426
+ if (gatewayModalAccount) body.account_id = account_id;
2416
2427
  if (gateway_id) body.gateway_id = gateway_id;
2417
2428
  else body.gateway_id = "";
2418
2429
  if (gatewayModalClear.checked) {
@@ -2426,8 +2437,8 @@ async function saveGatewayModal() {
2426
2437
  body.control_plane_key = gatewayModalCpKey.value.trim();
2427
2438
  }
2428
2439
  const hasCp = body.control_plane_key || body.clear_control_plane_key;
2429
- if (!gateway_id && !body.cf_aig_token && !body.clear_cf_aig_token && !hasCp) {
2430
- showGatewayModalError("enter a gateway slug, API token, and/or control-plane key");
2440
+ if (!account_id && !gateway_id && !body.cf_aig_token && !body.clear_cf_aig_token && !hasCp) {
2441
+ showGatewayModalError("enter your account ID, gateway slug, API token, and/or control-plane key");
2431
2442
  return;
2432
2443
  }
2433
2444
  try {
@@ -2437,6 +2448,8 @@ async function saveGatewayModal() {
2437
2448
  source: prefs.source,
2438
2449
  gateway_id: prefs.gateway_id,
2439
2450
  cf_aig_token_set: prefs.cf_aig_token_set,
2451
+ account_id: prefs.account_id,
2452
+ account_id_required: !!prefs.account_id_required,
2440
2453
  control_plane_configured: !!prefs.control_plane_configured,
2441
2454
  };
2442
2455
  renderGatewayBanner();
@@ -44,10 +44,19 @@
44
44
  </script>
45
45
  </head>
46
46
  <body>
47
- <a class="seo-skip" href="#auth-screen">Prism multimodal AI playground: sign up or log in</a>
47
+ <!-- fc#1700 skip link (WCAG 2.4.1 bypass blocks). Was an offscreen anchor
48
+ named seo-skip pointing at the conditionally-hidden auth panel, with no
49
+ :focus reveal anywhere: the first Tab on the page moved focus to an
50
+ element that stayed at x = -9999 and whose target was hidden. It now
51
+ names what it does, reveals itself on focus, and targets the main
52
+ content landmark. Kept first in the body; that position is the point. -->
53
+ <a class="skip-link" href="#main-content">Skip to main content</a>
48
54
  <!-- #80 public-mode first-party auth. Hidden by default; the boot probe
49
- (GET /api/session) reveals it only when mode=public and no session.
50
- Access / self-host deploys report mode=access and never show it. -->
55
+ (GET /api/models, the single unauthenticated entry point, which carries
56
+ mode + authenticated alongside the catalog) reveals it only when
57
+ mode=public and no session. There is no GET /api/session route; this
58
+ comment named one until fc#1700. Access / self-host deploys report
59
+ mode=access and never show it. -->
51
60
  <div id="auth-screen" class="auth-screen" hidden>
52
61
  <form id="auth-form" class="auth-card" novalidate>
53
62
  <div class="auth-brand">
@@ -85,9 +94,10 @@
85
94
  <button type="submit" id="auth-submit" class="auth-submit">create account</button>
86
95
 
87
96
  <p class="auth-foot">
88
- Inference runs on your own Cloudflare account: after you sign in, configure
89
- an AI Gateway (slug plus a Unified Billing token) under Account. Workers,
90
- storage, and retrieval are hosted; model spend is yours.
97
+ Inference runs on your own Cloudflare account: after you sign in, add your
98
+ account ID, an AI Gateway slug, and an API token under Account. Storage,
99
+ retrieval, live voice, Deepgram transcription, and six gateway-incompatible
100
+ Workers AI image models run on our account; all other model spend bills yours.
91
101
  </p>
92
102
  </form>
93
103
  </div>
@@ -173,7 +183,7 @@
173
183
  </header>
174
184
 
175
185
  <div id="gateway-banner" class="gateway-banner" hidden>
176
- <span id="gateway-banner-text">AI Gateway not configured. Set your gateway slug and Cloudflare API token to run models on your account.</span>
186
+ <span id="gateway-banner-text">AI Gateway not configured. Set your Cloudflare account ID, gateway slug, and API token to run models on your account.</span>
177
187
  <button id="gateway-banner-btn" type="button">Configure</button>
178
188
  </div>
179
189
 
@@ -198,7 +208,7 @@
198
208
  </label>
199
209
  </div>
200
210
 
201
- <main class="conversation">
211
+ <main class="conversation" id="main-content" tabindex="-1">
202
212
  <header class="conv-head">
203
213
  <span id="conv-title">new conversation</span>
204
214
  <span id="conv-compact-badge" class="conv-compact-badge" hidden title="Older turns are summarized for the model; full transcript still shown below">compacted</span>
@@ -277,7 +287,11 @@
277
287
  <button class="modal-close" data-modal-close="gateway-modal" type="button" title="close">&#x2715;</button>
278
288
  </header>
279
289
  <div class="modal-body">
280
- <p class="modal-hint">Connect your Cloudflare AI Gateway so model calls bill your account via Unified Billing. Create a gateway in the Cloudflare dashboard, enable Unified Billing for the providers you want, then paste the gateway slug and an API token with <strong>AI Gateway Run</strong> permission.</p>
290
+ <p class="modal-hint">Connect your Cloudflare AI Gateway so model calls bill your account via Unified Billing. Create a gateway in the Cloudflare dashboard and load credits, then paste your <strong>account ID</strong>, the gateway slug, and an API token scoped to that account with <strong>Workers AI Read</strong> and <strong>AI Gateway Run</strong>. All three are required: without the account ID a slug would resolve on this instance's account, so calls are refused instead.</p>
291
+ <label class="modal-field">
292
+ <span>Cloudflare account ID</span>
293
+ <input id="gateway-modal-account" type="text" autocomplete="off" spellcheck="false" maxlength="32" placeholder="32 hex characters, from your dashboard">
294
+ </label>
281
295
  <label class="modal-field">
282
296
  <span>gateway slug</span>
283
297
  <input id="gateway-modal-id" type="text" autocomplete="off" placeholder="my-gateway-slug">
@@ -25,17 +25,55 @@
25
25
 
26
26
  * { box-sizing: border-box; }
27
27
 
28
- /* Offscreen SEO/skip anchor, first focusable element in the body.
29
- The declarations below were an inline `style` attribute on the element
30
- until fc#1646: a report-only CSP observed it as the collector's first
31
- real finding (style-src-attr / blocked_uri inline), and an enforcing
32
- policy would drop the positioning and render the link on the page.
33
- Same two declarations, same computed result, no `unsafe-inline` needed. */
34
- .seo-skip {
28
+ /* Skip link (WCAG 2.4.1 bypass blocks), first focusable element in the body.
29
+ Offscreen until focused, on-screen while focused.
30
+
31
+ The offscreen declarations live here rather than in an inline `style`
32
+ attribute because an enforcing CSP drops style-src-attr: fc#1646 / #177
33
+ moved them out, and they stay out.
34
+
35
+ fc#1700 added the half that makes this an accessibility feature instead of
36
+ an invisible focus stop. Measured before the fix: the element was the first
37
+ focusable node in the body, and its bounding box was still x = -9999 AFTER
38
+ .focus(), so a keyboard user's first Tab on the credential page landed on a
39
+ link they could not see. The `:focus` rule below is what that measurement
40
+ was missing, so do not drop it without re-measuring.
41
+
42
+ The target is the main content landmark, not the auth panel: `#auth-screen`
43
+ is `hidden` until the public-mode boot probe reveals it, so the old href
44
+ aimed focus at a hidden element on every signed-in page. And when the gate
45
+ IS up, `body.auth-active .layout` is display:none, so there is no sidebar
46
+ to bypass and no target to land on: the link leaves the tab order entirely
47
+ in that state, which puts the first Tab on the auth form itself. */
48
+ .skip-link {
35
49
  position: absolute;
36
50
  left: -9999px;
51
+ top: 0;
52
+ z-index: 200; /* above .auth-screen (100) and the sidebar backdrop */
37
53
  }
38
54
 
55
+ .skip-link:focus {
56
+ left: 8px;
57
+ top: 8px;
58
+ padding: 10px 16px;
59
+ background: var(--bg-elev2);
60
+ color: var(--fg);
61
+ border: 1px solid var(--accent);
62
+ border-radius: var(--radius-sm);
63
+ box-shadow: var(--shadow), var(--shadow-glow);
64
+ outline: 2px solid var(--accent-cyan);
65
+ outline-offset: 2px;
66
+ text-decoration: none;
67
+ }
68
+
69
+ /* No skip link while the auth gate is up: nothing to bypass, nowhere to go. */
70
+ body.auth-active .skip-link { display: none; }
71
+
72
+ /* The skip target takes programmatic focus (tabindex="-1") so the next Tab
73
+ continues from the main column instead of restarting at the top of the
74
+ document. It is not keyboard-reachable on its own, so it gets no ring. */
75
+ #main-content:focus { outline: none; }
76
+
39
77
  html, body {
40
78
  margin: 0;
41
79
  padding: 0;
@@ -1,11 +1,11 @@
1
1
  // URL safety for values this app did not construct.
2
2
  //
3
- // Web-search results reach the transcript carrying a `url` field that
4
- // originates off-box. SearXNG hands upstream engine results through with a
5
- // truthiness filter only (src/searxng.ts filters on `r.url && r.title` and
6
- // never parses), src/routes/rag.ts maps them to source_type:"web", and the
7
- // value is persisted in retrieved_context and replayed on every subsequent
8
- // transcript render. So the string in an href there is not ours.
3
+ // Web-search rows reach the transcript carrying a `url` field that is
4
+ // persisted in retrieved_context and replayed on every later render.
5
+ // Current rows use a URL this worker built (src/skyphusion-search.ts).
6
+ // Older rows carry a URL from an upstream engine that the worker stored
7
+ // after a truthiness check only. Either way the href is replayed from D1,
8
+ // so the string is not trusted at render time.
9
9
  //
10
10
  // WHY ESCAPING IS THE WRONG TOOL HERE. escapeHtml() replaces & < > " ' and is
11
11
  // exactly right for stopping attribute injection. It does nothing whatever to
@@ -298,6 +298,12 @@ CREATE TABLE IF NOT EXISTS auth_attempts (
298
298
  count INTEGER NOT NULL DEFAULT 0,
299
299
  window_start TEXT NOT NULL DEFAULT (datetime('now'))
300
300
  );
301
+
302
+ -- prism#192: src/rate-limit.ts prunes this table on write (the csp_reports
303
+ -- pattern) so "transient IP processing" in the hosted privacy notice is true of
304
+ -- the code. The prune filters window_start; index it, exactly as
305
+ -- idx_csp_reports_received does for the other prune-on-write table.
306
+ CREATE INDEX IF NOT EXISTS idx_auth_attempts_window ON auth_attempts(window_start);
301
307
  -- 0004: CSP violation collector (fleet-chezmoi#1646).
302
308
  --
303
309
  -- Two tables, and the split is the point. `csp_report_buckets` is a rate-limit