@skyphusion/create-prism 1.3.1 → 1.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skyphusion/create-prism",
3
- "version": "1.3.1",
3
+ "version": "1.5.0",
4
4
  "description": "Scaffold a new prism deployment: a multimodal AI playground on Cloudflare Workers.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "author": "Conrad Rockenhaus",
@@ -8,6 +8,10 @@ redeploy.
8
8
 
9
9
  **Migration philosophy (read this first).** `schema.sql` is the canonical full schema for standing up a *fresh* database. It contains non-idempotent `ALTER TABLE` statements, so re-running it against a database that already has tables will raise `SQLITE_ERROR: duplicate column name` and, because `wrangler d1 execute --file` runs the whole file as one transaction, abort and roll back the entire run. **Never re-run `schema.sql` against an existing database.** To upgrade an existing deployment, apply only the delta for each version you're crossing, using the explicit commands below (or, for releases that ship one, the per-release `migrate-vX.Y.Z.sql` delta file). Apply each version's delta in order, then redeploy.
10
10
 
11
+ **Unreleased (cost per chat row, prism#258): one nullable column.** `chats.cost_usd REAL`, added by `migrations/0006_chat_cost.sql`. CI applies it before deploy. Self-hosters who do not use CI run `npx wrangler d1 migrations apply skyphusion-llm --remote` BEFORE deploying the new Worker; the Worker writes `cost_usd` on every chat insert, so a Worker deployed ahead of the column fails every chat write. Existing rows stay NULL (NULL means unknown, not zero). The figure is an estimate at the model's published list rate; see `src/pricing.ts` for its limits.
12
+
13
+ **Unreleased (funnel counters, prism#259): one nullable column and one table.** `users.first_output_at TEXT` and `funnel_daily`, added by `migrations/0007_funnel_counters.sql`. CI applies it before deploy. Self-hosters who do not use CI run `npx wrangler d1 migrations apply skyphusion-llm --remote` BEFORE deploying the new Worker: the Worker updates both on signup and on a first output. No data is back-filled. The operator reads the baseline with the queries in `docs/funnel-metrics.md`; there is no route.
14
+
11
15
  **v1.1.0 (account-scoped BYOK): BREAKING for existing BYOK users, no DDL.** `account_id` is a new key in the existing `user_prefs.prefs_json` blob. Every public-mode user saved before v1.1.0 (slug + token only) is refused with HTTP 412 `gateway_account_id_required` on every inference route until they add their 32-hex Cloudflare account ID under Account > AI Gateway, and their token must hold Workers AI Read as well as AI Gateway Run. A user who upgrades and does nothing loses inference. Tell your users before you tag. Access-mode installs using worker secrets are unaffected.
12
16
 
13
17
  v0.13.0 onward touched the D1 schema only at v0.20.0, v0.20.2, and v0.20.3; everything else in the v0.13.0 to v0.20.0 range is code-only. The pre-v0.13.0 migrations (v0.7.0 to v0.10.0) are below for anyone upgrading from very old deployments.
@@ -82,23 +82,27 @@ One Worker, no framework, no build step beyond TypeScript. The interesting parts
82
82
 
83
83
  ## Features
84
84
 
85
- **Full model catalog (93 entries):** tables below are generated from `src/models.ts`. Live list always wins: `GET /api/models`. The commercial control plane ([prism-control-plane](https://github.com/skyphusion-labs/prism-control-plane)) mirrors the same ids in `src/catalog.ts`.
85
+ **Full model catalog (107 entries):** tables below are generated from `src/models.ts`. Live list always wins: `GET /api/models`. The commercial control plane ([prism-control-plane](https://github.com/skyphusion-labs/prism-control-plane)) mirrors the same ids in `src/catalog.ts`.
86
86
 
87
87
  | Modality | Count |
88
88
  | --- | ---: |
89
- | Chat | 44 |
90
- | Image | 21 |
91
- | Video | 19 |
92
- | Text-to-speech (TTS) | 3 |
93
- | Speech-to-text (STT) | 4 |
89
+ | Chat | 57 |
90
+ | Image | 23 |
91
+ | Video | 20 |
92
+ | Text-to-speech (TTS) | 2 |
93
+ | Speech-to-text (STT) | 3 |
94
94
  | Music | 1 |
95
95
  | Live voice (Flux) | 1 |
96
- | **Total** | **93** |
96
+ | **Total** | **107** |
97
97
 
98
- #### Chat (44)
98
+ #### Chat (57)
99
99
 
100
100
  | Model id | Notes |
101
101
  | --- | --- |
102
+ | `anthropic/claude-fable-5.2` | Anthropic; binding |
103
+ | `anthropic/claude-opus-5.5` | Anthropic; binding |
104
+ | `anthropic/claude-sonnet-5.5` | Anthropic; binding |
105
+ | `anthropic/claude-haiku-5.5` | Anthropic; binding |
102
106
  | `anthropic/claude-fable-5` | Anthropic; binding |
103
107
  | `anthropic/claude-sonnet-5` | Anthropic |
104
108
  | `anthropic/claude-opus-5` | Anthropic |
@@ -107,18 +111,28 @@ One Worker, no framework, no build step beyond TypeScript. The interesting parts
107
111
  | `anthropic/claude-opus-4-6` | Anthropic |
108
112
  | `anthropic/claude-sonnet-4-6` | Anthropic |
109
113
  | `anthropic/claude-haiku-4-5` | Anthropic |
114
+ | `xai/grok-4.7` | xAI; binding |
110
115
  | `xai/grok-4.5` | xAI |
111
116
  | `xai/grok-4.3` | xAI |
112
117
  | `xai/grok-4.20-multi-agent-0309` | xAI multi-agent |
113
118
  | `xai/grok-4.20-0309-reasoning` | xAI reasoning |
114
119
  | `moonshotai/kimi-k3` | Moonshot UB |
115
- | `@cf/moonshotai/kimi-k2.6` | Workers AI |
116
- | `@cf/moonshotai/kimi-k2.7-code` | Workers AI, vision |
120
+ | `moonshotai/kimi-k3.1-pro` | Moonshot UB |
121
+ | `alibaba/qwen3.8-max` | Alibaba UB |
122
+ | `deepseek/deepseek-v4-pro` | DeepSeek UB |
123
+ | `minimax/m3` | MiniMax UB |
124
+ | `@cf/deepseek-ai/deepseek-v4.1-flash-1017` | Workers AI, vision |
125
+ | `@cf/zai-org/glm-5.3` | Workers AI |
126
+ | `@cf/thinkingmachines/inkling-2-small` | Workers AI, vision |
117
127
  | `@cf/openai/gpt-oss-120b` | Workers AI, reasoning |
118
128
  | `@cf/meta/llama-4-scout-17b-16e-instruct` | Workers AI, vision |
119
129
  | `@cf/google/gemma-4-26b-a4b-it` | Workers AI, vision |
120
130
  | `@cf/openai/gpt-oss-20b` | Workers AI |
121
131
  | `openai/gpt-5.5` | OpenAI UB |
132
+ | `openai/gpt-6.2-astra` | OpenAI UB |
133
+ | `openai/gpt-6.2-sol` | OpenAI UB |
134
+ | `openai/gpt-6.1-terra` | OpenAI UB |
135
+ | `openai/gpt-6-luna` | OpenAI UB |
122
136
  | `openai/gpt-5.5-pro` | OpenAI Responses |
123
137
  | `openai/gpt-5.6-sol` | OpenAI Responses |
124
138
  | `openai/gpt-5.6-terra` | OpenAI Responses |
@@ -128,54 +142,56 @@ One Worker, no framework, no build step beyond TypeScript. The interesting parts
128
142
  | `openai/o4-mini` | OpenAI reasoning |
129
143
  | `@cf/meta/llama-3.3-70b-instruct-fp8-fast` | Workers AI |
130
144
  | `@cf/meta/llama-3.2-11b-vision-instruct` | Workers AI, vision |
131
- | `@cf/meta/llama-3.2-3b-instruct` | Workers AI |
132
- | `@cf/qwen/qwen3-30b-a3b-fp8` | Workers AI |
133
- | `@cf/qwen/qwq-32b` | Workers AI, reasoning |
134
145
  | `@cf/qwen/qwen2.5-coder-32b-instruct` | Workers AI |
135
- | `@cf/deepseek-ai/deepseek-r1-distill-qwen-32b` | Workers AI |
146
+ | `@cf/qwen/qwen3.8-27b` | Workers AI, vision |
136
147
  | `@cf/mistralai/mistral-small-3.1-24b-instruct` | Workers AI, vision |
137
148
  | `@cf/zai-org/glm-4.7-flash` | Workers AI |
138
- | `@cf/zai-org/glm-5.2` | Workers AI |
139
- | `@cf/nvidia/nemotron-3-120b-a12b` | Workers AI |
140
149
  | `@cf/aisingapore/gemma-sea-lion-v4-27b-it` | Workers AI |
141
150
  | `google/gemini-3.1-pro` | Google Gemini, binding |
142
151
  | `google/gemini-3.5-flash` | Google Gemini, binding |
143
152
  | `google/gemini-3.6-flash` | Google Gemini, binding |
153
+ | `google/gemini-3.8-flash` | Google Gemini, binding |
154
+ | `google/gemini-4-argon` | Google Gemini, binding |
155
+ | `google/gemini-4-carbon` | Google Gemini, binding |
156
+ | `google/gemini-4-neon` | Google Gemini, binding |
157
+ | `google/gemini-4-hydrogen` | Google Gemini, binding |
144
158
  | `@cf/ibm-granite/granite-4.0-h-micro` | Workers AI |
145
- | `@cf/meta/llama-3.2-1b-instruct` | Workers AI |
146
159
 
147
- #### Image (21)
160
+ #### Image (23)
148
161
 
149
162
  | Model id | Notes |
150
163
  | --- | --- |
151
164
  | `google/nano-banana-pro` | Google UB |
152
165
  | `google/nano-banana-2` | Google UB |
153
166
  | `google/nano-banana-2-lite` | Google UB |
167
+ | `google/nano-banana-2.1` | Google UB |
154
168
  | `google/imagen-4` | Google UB |
155
169
  | `openai/gpt-image-1.5` | OpenAI UB; transparent PNG needs `OPENAI_API_KEY` |
156
170
  | `openai/gpt-image-2` | OpenAI UB; transparent PNG needs `OPENAI_API_KEY` |
157
171
  | `recraft/recraftv4` | Recraft UB |
158
172
  | `recraft/recraftv4-1` | Recraft UB |
159
173
  | `recraft/recraftv4-1-pro` | Recraft UB |
174
+ | `recraft/recraftv4-1-flash` | Recraft UB |
160
175
  | `xai/grok-imagine-image` | xAI UB |
161
176
  | `xai/grok-imagine-image-quality` | xAI UB |
177
+ | `xai/grok-imagine-image-2.0` | xAI UB |
162
178
  | `bytedance/seedream-5-pro` | ByteDance UB |
163
179
  | `bytedance/seedream-5-lite` | ByteDance UB |
180
+ | `bytedance/seedream-5.5` | ByteDance UB |
164
181
  | `@cf/black-forest-labs/flux-2-klein-9b` | FLUX 2; up to 4 refs |
165
182
  | `@cf/black-forest-labs/flux-2-klein-4b` | FLUX 2; up to 4 refs |
166
183
  | `@cf/black-forest-labs/flux-2-dev` | FLUX 2 multi-reference |
167
184
  | `@cf/black-forest-labs/flux-1-schnell` | FLUX-1 fast |
168
185
  | `@cf/leonardo/lucid-origin` | Leonardo |
169
186
  | `@cf/leonardo/phoenix-1.0` | Leonardo |
170
- | `@cf/lykon/dreamshaper-8-lcm` | Fast SD |
171
- | `@cf/stabilityai/stable-diffusion-xl-base-1.0` | SDXL |
172
187
 
173
- #### Video (19)
188
+ #### Video (20)
174
189
 
175
190
  | Model id | Notes |
176
191
  | --- | --- |
177
192
  | `google/veo-3.1` | Workflow long-run |
178
193
  | `google/veo-3.1-fast` | Workflow long-run |
194
+ | `bytedance/seedance-2.5` | Workflow long-run; i2v |
179
195
  | `bytedance/seedance-2.0` | Workflow long-run |
180
196
  | `bytedance/seedance-2.0-fast` | Workflow long-run |
181
197
  | `bytedance/seedance-2.0-mini` | Workflow long-run |
@@ -194,21 +210,19 @@ One Worker, no framework, no build step beyond TypeScript. The interesting parts
194
210
  | `vidu/q3-pro` | Workflow long-run |
195
211
  | `vidu/q3-turbo` | Workflow long-run |
196
212
 
197
- #### TTS (3)
213
+ #### TTS (2)
198
214
 
199
215
  | Model id | Notes |
200
216
  | --- | --- |
201
217
  | `@cf/deepgram/aura-2-en` | English |
202
218
  | `@cf/deepgram/aura-2-es` | Spanish speakers |
203
- | `@cf/myshell-ai/melotts` | Multilingual |
204
219
 
205
- #### STT (4)
220
+ #### STT (3)
206
221
 
207
222
  | Model id | Notes |
208
223
  | --- | --- |
209
224
  | `@cf/openai/whisper-large-v3-turbo` | Best quality |
210
225
  | `@cf/openai/whisper` | General |
211
- | `@cf/openai/whisper-tiny-en` | Fast English |
212
226
  | `@cf/deepgram/nova-3` | Accurate batch |
213
227
 
214
228
  #### Music (1)
@@ -233,7 +247,7 @@ One Worker, no framework, no build step beyond TypeScript. The interesting parts
233
247
 
234
248
  **Web search (v0.17.0):** opt-in retrieval source that queries the `skyphusion-search` Worker (service binding `SEARCH`) and Wikipedia (reference and lore) in parallel. Snippets folded into the system prompt the same way RAG chunks are. Per-turn toggle. Without the `SEARCH` binding that source reports absent; Wikipedia needs no setup. See [Web search](#web-search) below.
235
249
 
236
- **Streaming (v0.13.0+):** `POST /api/chat/stream` returns SSE for any chat model flagged `streaming: true` in the catalog. Token deltas surface as `{ type: "delta", text: "..." }` events, terminal completion as `{ type: "done", ... }` with token counts and conversation IDs. Client disconnect aborts the upstream model call immediately.
250
+ **Streaming (v0.13.0+):** `POST /api/chat/stream` returns SSE for any chat model flagged `streaming: true` in the catalog. Token deltas surface as `{ type: "delta", text: "..." }` events, terminal completion as `{ type: "done", ... }` with token counts, an estimated `cost_usd` (null when unknown; see [docs/cost-estimate.md](docs/cost-estimate.md)) and conversation IDs. Client disconnect aborts the upstream model call immediately.
237
251
 
238
252
  **Multi-turn conversations:** `conversation_id` plus `turn_index` on chat rows. Continuing a conversation pulls prior completed chat turns and assembles them for the next call. Mixed-model conversations allowed (start with Llama, continue with Claude). Text-only on continuation; prior images, audio, and video are not re-sent.
239
253
 
@@ -397,7 +411,7 @@ Do **not** use a **Bypass** policy on the main app URL. Bypass skips login, so t
397
411
 
398
412
  ### 7. Optional: web search
399
413
 
400
- Web search calls the `skyphusion-search` Worker through a service binding. The committed template already declares it:
414
+ Web search calls a `skyphusion-search` Worker through a service binding. search-mcp, which built that Worker, is retired, so the template ships the block commented out and web search is off by default (a replacement backend is tracked in #276). If you run that Worker, uncomment the block:
401
415
 
402
416
  ```toml
403
417
  [[services]]
@@ -406,7 +420,7 @@ service = "skyphusion-search"
406
420
  entrypoint = "SearchEntrypoint"
407
421
  ```
408
422
 
409
- Copy that block into your `wrangler.toml`. If you do not run a worker with that script name, delete the block instead: `wrangler deploy` fails when the service does not exist. With the binding absent, the response says that source is `absent` and Wikipedia still runs. Wikipedia needs no config. See [Web search](#web-search) below.
423
+ Leave it commented out if you do not run a worker with that script name: `wrangler deploy` fails with error 10143 when the service does not exist. With the binding absent, the response says that source is `absent` and Wikipedia still runs. Wikipedia needs no config. See [Web search](#web-search) below.
410
424
 
411
425
  ### 8. Local development
412
426
 
@@ -483,7 +497,7 @@ npm run deploy
483
497
 
484
498
  - **You (the host)** pay Cloudflare for Workers, D1, R2, and Vectorize: the storage and compute for the service itself.
485
499
  - **Each user** pays for every call that goes through the `aiRun` seam or a provider-native gateway endpoint, on their own Cloudflare account and gateway (v1.1.0): all partner models (Anthropic, xAI, Google, OpenAI, and the other Unified Billing providers, including image, video, and music), Workers AI chat, TTS, Whisper STT, FLUX.1 / Lucid Origin image gen, and the RAG embeddings (`@cf/baai/bge-base-en-v1.5`) behind document upload and retrieval.
486
- - **You (the host)** pay for the Workers AI paths that call the worker's `AI` binding directly because AI Gateway cannot proxy them, which means the user's account cannot be reached either: the six stream-incompatible image models (FLUX.2 Klein 9B / Klein 4B / Dev, Leonardo Phoenix 1.0, Dreamshaper 8 LCM, SDXL), Deepgram file STT, and the live-voice Flux socket. Bound this with Workers AI limits on your account or remove those models from `src/models.ts` on your instance.
500
+ - **You (the host)** pay for the Workers AI paths that call the worker's `AI` binding directly because AI Gateway cannot proxy them, which means the user's account cannot be reached either: the four stream-incompatible image models (FLUX.2 Klein 9B / Klein 4B / Dev, Leonardo Phoenix 1.0), Deepgram file STT, and the live-voice Flux socket. Bound this with Workers AI limits on your account or remove those models from `src/models.ts` on your instance.
487
501
  - **Control-plane users** (`pcp_` key) bill chat through prism-control-plane under its own metering, not through either account above. That plane stores no chat text. Media it generates, and reference images uploaded to it, are kept 30 days and then deleted ([its retention section](https://github.com/skyphusion-labs/prism-control-plane/blob/main/docs/CONTRACT.md)).
488
502
 
489
503
  **How it works.** In `AUTH_MODE=public`, the host funds a named set of demo capabilities on purpose. Every other inference call bills the user's own Cloudflare account.
@@ -494,7 +508,7 @@ This table was read from the code on `main` (v1.1.1). It shows what the code doe
494
508
 
495
509
  | Capability | Code path | Billed to |
496
510
  |---|---|---|
497
- | FLUX.2 Klein 9B, Klein 4B, Dev; Leonardo Phoenix 1.0; Dreamshaper 8 LCM; SDXL | `bypassGateway` in `src/routes/chat.ts` calls `env.AI.run` | **Host** |
511
+ | FLUX.2 Klein 9B, Klein 4B, Dev; Leonardo Phoenix 1.0 | `bypassGateway` in `src/routes/chat.ts` calls `env.AI.run` | **Host** |
498
512
  | Deepgram Nova-3 file speech-to-text | `viaDeepgram` in `src/routes/chat.ts` calls `env.AI.run` | **Host** |
499
513
  | Live voice (Deepgram Flux websocket) | `src/stt-session.ts` calls `env.AI.run` | **Host** |
500
514
  | Workers AI chat, TTS, Whisper, FLUX.1 schnell, Lucid Origin | `aiRun`, which uses the REST API on the user's account | User |
@@ -756,13 +770,12 @@ Video gen is the most expensive feature in this playground.
756
770
 
757
771
  Attach an audio file, pick a Whisper model, click Run. The worker calls Whisper directly via `env.AI.run` (no async; Whisper completes in seconds) and stores the transcript as the chat's `output` text. The audio's bytes are not persisted; only the transcript is kept on the row's attachment record, same convention as the chat-path audio attachments.
758
772
 
759
- Four one-shot models are exposed:
773
+ Three one-shot models are exposed:
760
774
  - `@cf/openai/whisper-large-v3-turbo` (default; best quality, multilingual)
761
775
  - `@cf/openai/whisper` (general purpose, slightly older)
762
- - `@cf/openai/whisper-tiny-en` (fast, English-only, beta)
763
776
  - `@cf/deepgram/nova-3` (Deepgram Nova-3; accurate)
764
777
 
765
- All four are hosted on Workers AI (no Unified Billing needed).
778
+ All three are hosted on Workers AI (no Unified Billing needed). Cloudflare retired `@cf/openai/whisper-tiny-en` on 2026-11-20 and names Nova-3 as its replacement.
766
779
 
767
780
  ## Voice chat
768
781
 
@@ -813,7 +826,7 @@ This is a Cloudflare-proxied (third-party) model, so it requires Unified Billing
813
826
 
814
827
  ## Image generation
815
828
 
816
- **21** image models in `src/models.ts` (or `GET /api/models?type=image`): Google Nano Banana Pro / 2 / Lite, Imagen 4, GPT Image 1.5 / 2, Recraft V4 / V4.1 / V4.1 Pro, xAI Grok Imagine Image (+ Quality), ByteDance Seedream 5 Pro / Lite, FLUX 2 Klein 9B/4B, FLUX 2 Dev, FLUX-1 schnell, Lucid Origin, Phoenix 1.0, Dreamshaper 8 LCM, Stable Diffusion XL. The eight FLUX/Leonardo/Lykon/Stability models run through Workers AI (no Unified Billing required); the rest are proxied partner models on Unified Billing (need CF credits). GPT Image 1.5 / 2 are opaque on the proxy by default; **optional deployer BYOK (v0.174.0):** set `OPENAI_API_KEY` for transparent PNG via `api.openai.com` (ignored in public mode, v1.0.5).
829
+ **23** image models in `src/models.ts` (or `GET /api/models?type=image`): Google Nano Banana Pro / 2 / 2.1 / 2 Lite, Imagen 4, GPT Image 1.5 / 2, Recraft V4 / V4.1 / V4.1 Pro / V4.1 Flash, xAI Grok Imagine Image (+ Quality, 2.0), ByteDance Seedream 5.5 / 5 Pro / 5 Lite, FLUX 2 Klein 9B/4B, FLUX 2 Dev, FLUX-1 schnell, Lucid Origin, Phoenix 1.0. The six FLUX/Leonardo models run through Workers AI (no Unified Billing required); the rest are proxied partner models on Unified Billing (need CF credits). GPT Image 1.5 / 2 are opaque on the proxy by default; **optional deployer BYOK (v0.174.0):** set `OPENAI_API_KEY` for transparent PNG via `api.openai.com` (ignored in public mode, v1.0.5).
817
830
 
818
831
  ### Google Nano Banana Pro (Unified Billing, v0.21.2)
819
832
 
@@ -840,14 +853,14 @@ Proxied image models return a URL and/or inline base64 in the `{ state, result }
840
853
 
841
854
  The three FLUX-2 models (Klein 9B, Klein 4B, Dev) accept up to 4 reference images for image-to-image generation. When you select a FLUX-2 model in the image-gen UI, an attach row appears alongside the prompt and negative-prompt fields. Pick up to 4 images; each is downscaled client-side to 512px max dimension (per the model spec) and sent as `input_image_0` through `input_image_3` multipart form fields.
842
855
 
843
- FLUX-1 schnell, Lucid Origin, Phoenix 1.0, and Dreamshaper 8 LCM are text-to-image only; no reference image input.
856
+ FLUX-1 schnell, Lucid Origin, and Phoenix 1.0 are text-to-image only; no reference image input.
844
857
 
845
858
  ### Gateway routing quirks
846
859
 
847
860
  As of 2026-Q1, three Workers AI image-gen models have transport-layer incompatibilities with the AI Gateway:
848
861
 
849
862
  - **FLUX-2 family** requires multipart-form input. Gateway can't proxy stream input.
850
- - **Phoenix 1.0** and **Dreamshaper 8 LCM** return ReadableStream output. Gateway can't proxy stream output.
863
+ - **Phoenix 1.0** returns ReadableStream output. Gateway can't proxy stream output.
851
864
 
852
865
  The worker detects these models and bypasses the gateway, calling `env.AI.run` directly. Cost: no AI Gateway observability/caching for these specific models (the persisted row's `ai_gateway_log_id` stays null). FLUX-1 schnell and Lucid Origin work through the gateway normally.
853
866
 
@@ -952,7 +965,7 @@ Per-turn opt-in: the toggle is not sticky across turns. Each turn decides indepe
952
965
 
953
966
  ### Setup
954
967
 
955
- Add the service binding to your `wrangler.toml` (already in `wrangler.example.toml`) and redeploy. Wikipedia needs no config.
968
+ Uncomment the service binding in your `wrangler.toml` (it ships commented out in `wrangler.example.toml`) and redeploy. Wikipedia needs no config.
956
969
 
957
970
  ```toml
958
971
  [[services]]
@@ -961,7 +974,7 @@ service = "skyphusion-search"
961
974
  entrypoint = "SearchEntrypoint"
962
975
  ```
963
976
 
964
- The binding calls the named entrypoint, not `POST /ask`. There is no Origin header and no Turnstile token. The search worker's script must export `SearchEntrypoint` (search-mcp). Delete the `[[services]]` block if that worker is not on your account.
977
+ The binding calls the named entrypoint, not `POST /ask`. There is no Origin header and no Turnstile token. The search worker's script must export `SearchEntrypoint` (search-mcp). Keep the `[[services]]` block commented out if that worker is not on your account.
965
978
 
966
979
  ### Caveats worth knowing
967
980
 
@@ -994,7 +1007,7 @@ Wire format:
994
1007
  ```
995
1008
  data: {"type":"delta","text":"..."}
996
1009
  data: {"type":"done","row_id":N,"latency_ms":N,"tokens_in":N|null,
997
- "tokens_out":N|null,"conversation_id":"...","turn_index":N}
1010
+ "tokens_out":N|null,"cost_usd":N|null,"conversation_id":"...","turn_index":N}
998
1011
  ```
999
1012
 
1000
1013
  Or, on error:
@@ -43,6 +43,13 @@ lose it, we have no way to email you a reset.
43
43
  - **Your control-plane client key, if you enter one:** the `pcp_` key that switches chat onto the
44
44
  Skyphusion-operated metered route (see "Metered chat through play-proxy" below). You only have one if
45
45
  Skyphusion Labs issued it to you.
46
+ - **When you first got an output:** one timestamp on your account record, set the first time a model
47
+ gives you a finished result. It lets the operator measure how long a new account takes to get its first
48
+ result. It is part of your account record, so deleting your account deletes it.
49
+ - **Anonymous daily counts:** the instance keeps one row per day with how many accounts were created, how
50
+ many got a first result, and how long that took in coarse buckets. The row has no account id, username,
51
+ IP address, model, or content, so it cannot be tied back to you and is not removed when you delete your
52
+ account. There is no third-party analytics in the path.
46
53
  - **Operational records** mechanically required to run the service: request and job state, and
47
54
  abuse-control counters (see "Abuse controls" below).
48
55
 
@@ -0,0 +1,22 @@
1
+ -- 0006: estimated cost per chat row (prism#258, Part of prism#251 Sprint 1).
2
+ --
3
+ -- WHY THIS IS A NUMBERED FILE IN migrations/: CI applies only migrations/ before
4
+ -- `wrangler deploy` (wrangler d1 migrations apply skyphusion-llm --remote). The
5
+ -- Worker now binds cost_usd in INSERT INTO chats. If this column shipped only as
6
+ -- a legacy migrate-v*.sql file, the deployed Worker would write to a column the
7
+ -- table does not have and every chat would fail to persist after the tokens were
8
+ -- spent. schema.sql carries the same column for fresh databases.
9
+ --
10
+ -- cost_usd is the ESTIMATED USD cost of one chat turn at the model's published
11
+ -- list rate (or, on the control-plane path, the plane's own charge). Display
12
+ -- only: it is never an input to a limit or a charge. REAL, nullable, NO default:
13
+ -- NULL means unknown (unpriced model, missing token count, non-chat or failed
14
+ -- row). NULL is not 0; 0 means a real zero rate. Existing rows stay NULL.
15
+ --
16
+ -- Not idempotent (SQLite has no ADD COLUMN IF NOT EXISTS); wrangler records the
17
+ -- file in d1_migrations and applies it once.
18
+ --
19
+ -- Apply to an existing database with:
20
+ -- npx wrangler d1 migrations apply skyphusion-llm --remote
21
+
22
+ ALTER TABLE chats ADD COLUMN cost_usd REAL;
@@ -0,0 +1,38 @@
1
+ -- 0007: funnel counters in D1 (prism#259, Part of prism#251 Sprint 1).
2
+ --
3
+ -- WHY THIS IS A NUMBERED FILE IN migrations/: CI applies only migrations/ before
4
+ -- deploy. The Worker now updates users.first_output_at and writes funnel_daily;
5
+ -- both must exist when the new Worker starts. schema.sql carries the same DDL
6
+ -- for fresh databases.
7
+ --
8
+ -- The epic needs a baseline and AGENTS.md forbids third-party telemetry, so the
9
+ -- counts live here. Two pieces, split on purpose (ernst S1-8):
10
+ --
11
+ -- users.first_output_at PER-ACCOUNT state, nullable. When this account first
12
+ -- got a finished output. It lives on the users row so
13
+ -- account deletion (src/auth.ts cascade) removes it
14
+ -- with the account. Set once, by
15
+ -- UPDATE ... WHERE first_output_at IS NULL.
16
+ --
17
+ -- funnel_daily DURABLE aggregates, one row per UTC day. NO account
18
+ -- id, no IP, no user agent, no model id, no
19
+ -- conversation id, no text. It survives account
20
+ -- deletion because it names no one.
21
+ --
22
+ -- Counts include bots until the signup bot check lands (Sprint 2). Access-mode
23
+ -- installs have no signups to count.
24
+
25
+ ALTER TABLE users ADD COLUMN first_output_at TEXT;
26
+
27
+ CREATE TABLE IF NOT EXISTS funnel_daily (
28
+ day TEXT PRIMARY KEY, -- UTC date, YYYY-MM-DD
29
+ signups INTEGER NOT NULL DEFAULT 0, -- accounts created that day
30
+ first_outputs INTEGER NOT NULL DEFAULT 0, -- accounts that got their first output that day
31
+ -- Time from signup to first output, for the first_outputs of that day.
32
+ -- The five buckets sum to first_outputs.
33
+ ttfo_lt_1m INTEGER NOT NULL DEFAULT 0, -- under 60 s
34
+ ttfo_1_5m INTEGER NOT NULL DEFAULT 0, -- 60 s up to 5 min
35
+ ttfo_5_30m INTEGER NOT NULL DEFAULT 0, -- 5 up to 30 min
36
+ ttfo_30m_24h INTEGER NOT NULL DEFAULT 0, -- 30 min up to 24 h
37
+ ttfo_ge_24h INTEGER NOT NULL DEFAULT 0 -- 24 h or more
38
+ );
@@ -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": "^2.1.0",
20
+ "unpdf": "^2.2.1",
21
21
  "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@cloudflare/vitest-pool-workers": "^0.23.0",
25
- "@cloudflare/workers-types": "^5.20261108.1",
25
+ "@cloudflare/workers-types": "^5.20261121.1",
26
26
  "@types/node": "^26.6.6",
27
27
  "@vitest/coverage-v8": "^4.1.12",
28
28
  "typescript": "^7.0.2",
29
29
  "vitest": "^4.1.8",
30
- "wrangler": "^4.158.0"
30
+ "wrangler": "^4.166.0"
31
31
  }
32
32
  }
@@ -44,7 +44,11 @@ CREATE TABLE IF NOT EXISTS chats (
44
44
  -- turn_index is monotonically increasing within a conversation.
45
45
  -- For backward compat, legacy rows are backfilled as conversation_id='legacy-<id>', turn_index=0.
46
46
  conversation_id TEXT,
47
- turn_index INTEGER
47
+ turn_index INTEGER,
48
+ -- prism#258: estimated list-price cost of a chat turn, USD. NULL when unpriced
49
+ -- or not a done chat row (NULL is not 0). Display only. Existing databases get
50
+ -- it from migrations/0006_chat_cost.sql.
51
+ cost_usd REAL
48
52
  );
49
53
 
50
54
  CREATE INDEX IF NOT EXISTS idx_chats_conversation
@@ -281,7 +285,11 @@ CREATE TABLE IF NOT EXISTS users (
281
285
  username_lc TEXT NOT NULL UNIQUE,
282
286
  password_hash TEXT NOT NULL,
283
287
  email TEXT,
284
- created_at TEXT NOT NULL DEFAULT (datetime('now'))
288
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
289
+ -- prism#259: when this account first got a finished output. Per-account, so it
290
+ -- lives on this row and account deletion removes it. Set once. Existing
291
+ -- databases get it from migrations/0007_funnel_counters.sql.
292
+ first_output_at TEXT
285
293
  );
286
294
 
287
295
  CREATE TABLE IF NOT EXISTS sessions (
@@ -304,6 +312,23 @@ CREATE TABLE IF NOT EXISTS auth_attempts (
304
312
  -- the code. The prune filters window_start; index it, exactly as
305
313
  -- idx_csp_reports_received does for the other prune-on-write table.
306
314
  CREATE INDEX IF NOT EXISTS idx_auth_attempts_window ON auth_attempts(window_start);
315
+
316
+ -- ---------- Funnel counters (prism#259) ----------
317
+ --
318
+ -- Durable daily aggregates for the signup-to-first-output baseline. One row per
319
+ -- UTC day. NO account id, IP, user agent, model id, conversation id or text, so
320
+ -- it survives account deletion because it names no one. Counts include bots
321
+ -- until the signup bot check lands. See docs/funnel-metrics.md.
322
+ CREATE TABLE IF NOT EXISTS funnel_daily (
323
+ day TEXT PRIMARY KEY,
324
+ signups INTEGER NOT NULL DEFAULT 0,
325
+ first_outputs INTEGER NOT NULL DEFAULT 0,
326
+ ttfo_lt_1m INTEGER NOT NULL DEFAULT 0,
327
+ ttfo_1_5m INTEGER NOT NULL DEFAULT 0,
328
+ ttfo_5_30m INTEGER NOT NULL DEFAULT 0,
329
+ ttfo_30m_24h INTEGER NOT NULL DEFAULT 0,
330
+ ttfo_ge_24h INTEGER NOT NULL DEFAULT 0
331
+ );
307
332
  -- 0004: CSP violation collector (fleet-chezmoi#1646).
308
333
  --
309
334
  -- Two tables, and the split is the point. `csp_report_buckets` is a rate-limit
@@ -28,6 +28,7 @@ import {
28
28
  parseSessionCookie,
29
29
  } from "./session";
30
30
  import { checkRateLimit, resetRateLimit } from "./rate-limit";
31
+ import { recordSignup } from "./funnel";
31
32
 
32
33
  export type AuthMode = "public" | "access";
33
34
 
@@ -163,6 +164,9 @@ export async function handleSignup(request: Request, env: Env): Promise<Response
163
164
  .bind(id, username, usernameLc, passwordHash)
164
165
  .run();
165
166
 
167
+ // prism#259: counted only after the INSERT succeeded; a counter error never fails signup.
168
+ await recordSignup(env);
169
+
166
170
  const token = await createSession(env.DB, id);
167
171
  return json(
168
172
  { user: { username } },
@@ -7,6 +7,7 @@
7
7
  // Contract: skyphusion-labs/prism-control-plane docs/CONTRACT.md
8
8
 
9
9
  import type { Env } from "./env";
10
+ import { planeCostUsd } from "./pricing";
10
11
  import type { UserPrefsJson } from "./user-prefs";
11
12
 
12
13
  export const DEFAULT_CONTROL_PLANE_URL = "https://play-proxy.skyphusion.org";
@@ -107,6 +108,11 @@ export interface ControlPlaneChatResult {
107
108
  model: string;
108
109
  usage: { prompt_tokens: number | null; completion_tokens: number | null };
109
110
  requestId: string | null;
111
+ /**
112
+ * What the plane charged, USD, from prism-usage-micro-usd when prism-metered is
113
+ * true. Null otherwise (prism#258). Never a catalog price.
114
+ */
115
+ costUsd: number | null;
110
116
  raw: unknown;
111
117
  }
112
118
 
@@ -189,6 +195,7 @@ export async function controlPlaneChat(
189
195
  completion_tokens: intOrNull(usageRaw?.completion_tokens ?? usageRaw?.output_tokens),
190
196
  },
191
197
  requestId,
198
+ costUsd: planeCostUsd(res.headers),
192
199
  raw: body,
193
200
  };
194
201
  }
@@ -0,0 +1,96 @@
1
+ // Funnel counters (prism#259, Part of prism#251 Sprint 1).
2
+ //
3
+ // First-party counts in D1, no third-party telemetry. Signup, first output, and
4
+ // the time between them. See docs/funnel-metrics.md for the operator query.
5
+ //
6
+ // Privacy shape (ernst S1-8):
7
+ // - Per-account state is one nullable column on the users row
8
+ // (users.first_output_at). Account deletion removes the row, so it removes
9
+ // this with it.
10
+ // - The durable numbers are funnel_daily: one row per UTC day, no account id,
11
+ // IP, user agent, model id, conversation id or text.
12
+ //
13
+ // Integrity (ernst S1-9):
14
+ // - A signup is counted only after the users INSERT succeeded.
15
+ // - First output is set once, by UPDATE ... WHERE first_output_at IS NULL, and
16
+ // the daily counter moves only when that UPDATE changed a row. So a second
17
+ // output, a retry or a race cannot count twice.
18
+ // - A counter error NEVER fails a signup or a chat: every entry point catches
19
+ // and logs counts only (no id, no text).
20
+ //
21
+ // Access mode (AUTH_MODE=access) has no users rows, so there is nothing to count
22
+ // and these are no-ops there.
23
+
24
+ import type { Env } from "./env";
25
+
26
+ type Bucket = "ttfo_lt_1m" | "ttfo_1_5m" | "ttfo_5_30m" | "ttfo_30m_24h" | "ttfo_ge_24h";
27
+
28
+ /** Bucket for a signup-to-first-output time in seconds. Negative (clock skew) counts as 0. */
29
+ export function ttfoBucket(seconds: number): Bucket {
30
+ const s = Number.isFinite(seconds) && seconds > 0 ? seconds : 0;
31
+ if (s < 60) return "ttfo_lt_1m";
32
+ if (s < 300) return "ttfo_1_5m";
33
+ if (s < 1800) return "ttfo_5_30m";
34
+ if (s < 86400) return "ttfo_30m_24h";
35
+ return "ttfo_ge_24h";
36
+ }
37
+
38
+ // SQLite datetime('now') form: "YYYY-MM-DD HH:MM:SS", UTC.
39
+ function sqliteUtcToMs(s: string): number {
40
+ return Date.parse(`${s.replace(" ", "T")}Z`);
41
+ }
42
+
43
+ function logCounterError(which: string, err: unknown): void {
44
+ // Counts and a reason class only: never an account id, username or text.
45
+ const reason = err instanceof Error ? err.name : "unknown";
46
+ console.warn(`funnel counter ${which} failed (${reason})`);
47
+ }
48
+
49
+ /** Count one signup. Call only AFTER the users INSERT succeeded. Never throws. */
50
+ export async function recordSignup(env: Env): Promise<void> {
51
+ try {
52
+ await env.DB.prepare(
53
+ `INSERT INTO funnel_daily (day, signups) VALUES (date('now'), 1)
54
+ ON CONFLICT(day) DO UPDATE SET signups = signups + 1`,
55
+ ).run();
56
+ } catch (err) {
57
+ logCounterError("signup", err);
58
+ }
59
+ }
60
+
61
+ // Column names come from ttfoBucket's closed set, never from input.
62
+ const BUCKET_SQL: Record<Bucket, string> = {
63
+ ttfo_lt_1m: `INSERT INTO funnel_daily (day, first_outputs, ttfo_lt_1m) VALUES (date('now'), 1, 1)
64
+ ON CONFLICT(day) DO UPDATE SET first_outputs = first_outputs + 1, ttfo_lt_1m = ttfo_lt_1m + 1`,
65
+ ttfo_1_5m: `INSERT INTO funnel_daily (day, first_outputs, ttfo_1_5m) VALUES (date('now'), 1, 1)
66
+ ON CONFLICT(day) DO UPDATE SET first_outputs = first_outputs + 1, ttfo_1_5m = ttfo_1_5m + 1`,
67
+ ttfo_5_30m: `INSERT INTO funnel_daily (day, first_outputs, ttfo_5_30m) VALUES (date('now'), 1, 1)
68
+ ON CONFLICT(day) DO UPDATE SET first_outputs = first_outputs + 1, ttfo_5_30m = ttfo_5_30m + 1`,
69
+ ttfo_30m_24h: `INSERT INTO funnel_daily (day, first_outputs, ttfo_30m_24h) VALUES (date('now'), 1, 1)
70
+ ON CONFLICT(day) DO UPDATE SET first_outputs = first_outputs + 1, ttfo_30m_24h = ttfo_30m_24h + 1`,
71
+ ttfo_ge_24h: `INSERT INTO funnel_daily (day, first_outputs, ttfo_ge_24h) VALUES (date('now'), 1, 1)
72
+ ON CONFLICT(day) DO UPDATE SET first_outputs = first_outputs + 1, ttfo_ge_24h = ttfo_ge_24h + 1`,
73
+ };
74
+
75
+ /**
76
+ * Record the account's first finished output, once. Call only for a row
77
+ * persisted as done. The daily counter moves only if this call is the one that
78
+ * set users.first_output_at. No users row (access mode) means no change and no
79
+ * count. Never throws.
80
+ */
81
+ export async function recordFirstOutput(env: Env, userId: string): Promise<void> {
82
+ try {
83
+ const set = await env.DB.prepare(
84
+ `UPDATE users SET first_output_at = datetime('now')
85
+ WHERE id = ? AND first_output_at IS NULL
86
+ RETURNING created_at, first_output_at`,
87
+ )
88
+ .bind(userId)
89
+ .first<{ created_at: string; first_output_at: string }>();
90
+ if (!set) return; // already counted, or no such account
91
+ const seconds = (sqliteUtcToMs(set.first_output_at) - sqliteUtcToMs(set.created_at)) / 1000;
92
+ await env.DB.prepare(BUCKET_SQL[ttfoBucket(seconds)]).run();
93
+ } catch (err) {
94
+ logCounterError("first_output", err);
95
+ }
96
+ }
@@ -50,6 +50,8 @@ function imageToVideoParams(
50
50
  case "bytedance/seedance-2.0":
51
51
  case "bytedance/seedance-2.0-fast":
52
52
  case "bytedance/seedance-2.0-mini":
53
+ // 2026-12 refresh: seedance-2.5 lists the same i2v fields on its CF model page.
54
+ case "bytedance/seedance-2.5":
53
55
  return {
54
56
  image: imageUrl,
55
57
  prompt: motion,