@skyphusion/create-prism 0.175.6 → 1.0.4

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": "0.175.6",
3
+ "version": "1.0.4",
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",
@@ -4,7 +4,49 @@
4
4
  [![Typecheck](https://github.com/skyphusion-labs/prism/actions/workflows/typecheck.yml/badge.svg)](https://github.com/skyphusion-labs/prism/actions/workflows/typecheck.yml)
5
5
  [![Voice chat](https://img.shields.io/badge/%F0%9F%8E%99%EF%B8%8F_voice_chat-speak_%26_hear_chat_models-6d8cff)](#voice-chat)
6
6
 
7
- A multimodal AI playground deployed as a single Cloudflare Worker. **Live demo:** https://play.skyphusion.org (free signup, bring your own AI Gateway). **~45 chat models** across Workers AI, Anthropic, xAI, OpenAI, Google, and Moonshot (see `GET /api/models`), **hands-free voice chat** (talk to any chat model and hear it reply), image / TTS / STT / video / music generation, cross-model artifact reuse within a conversation (v0.21.7), RAG over files of any type (v0.23.0), projects that scope a knowledge base and system prompt, Discord chat-log ingestion, opt-in web search via self-hosted SearXNG and Wikipedia, SSE streaming on supported chat models, and multi-turn conversations. One web UI with first-party accounts, per-user history, R2 for all binary artifacts.
7
+ A multimodal AI playground deployed as a single Cloudflare Worker. **Live demo:** https://play.skyphusion.org (free signup, bring your own AI Gateway). Catalog breadth is live at `GET /api/models` (and `src/models.ts`): **93** models (44 chat + 21 image + 19 video + 3 TTS + 4 STT + 1 music + 1 live voice); the tables under [Features](#features) list every id. Native clients hit the commercial plane ([prism-control-plane](https://github.com/skyphusion-labs/prism-control-plane)); this Worker is the playground surface (RAG, projects, compact, web search). **Hands-free voice chat**, cross-model artifact reuse, RAG, projects, Discord ingestion, web search, SSE streaming, and multi-turn conversations (with optional **compact**). One web UI with first-party accounts, per-user history, R2 for all binary artifacts.
8
+
9
+ ```mermaid
10
+ flowchart TB
11
+ subgraph browser["Browser / play.skyphusion.org"]
12
+ UI["public/ app.js<br/>chat · image · video · voice"]
13
+ end
14
+
15
+ subgraph worker["Worker: skyphusion-llm"]
16
+ Auth["AUTH_MODE public or access"]
17
+ Chat["/api/chat · /api/chat/stream"]
18
+ Multi["image · TTS · STT · video · music"]
19
+ RAG["Vectorize + D1 RAG"]
20
+ WF["LongRunWorkflow<br/>video · music"]
21
+ end
22
+
23
+ subgraph store["Bindings"]
24
+ D1["D1 history + chunks"]
25
+ R2["R2 artifacts"]
26
+ VZ["Vectorize embeddings"]
27
+ end
28
+
29
+ subgraph ai["Cloudflare AI"]
30
+ GW["AI Gateway"]
31
+ Run["env.AI.run"]
32
+ end
33
+
34
+ subgraph native["Native apps optional"]
35
+ iOS["prism-ios → play-proxy<br/>control plane not this Worker"]
36
+ end
37
+
38
+ UI --> Auth --> Chat
39
+ Auth --> Multi
40
+ Chat --> Run
41
+ Multi --> Run
42
+ Multi --> WF
43
+ Chat --> RAG
44
+ RAG --> VZ
45
+ Chat --> D1
46
+ Multi --> R2
47
+ Run --> GW
48
+ iOS -.->|"separate host<br/>play-proxy.skyphusion.org"| native
49
+ ```
8
50
 
9
51
  <p align="center">
10
52
  <img src="docs/screenshot-desktop.jpg" alt="Desktop UI: image generation with Nano Banana Pro" width="800"><br><br>
@@ -36,27 +78,150 @@ One Worker, no framework, no build step beyond TypeScript. The interesting parts
36
78
  - **Cloudflare Workflows** owns long-running Unified Billing video and music generation (30s to 3min jobs). The `LongRunWorkflow` class holds the blocking `env.AI.run` call alive across step boundaries that `ctx.waitUntil` cannot.
37
79
  - **Two auth modes, one identity seam.** An `AUTH_MODE` setting picks how the worker learns who you are: **public** mode (the hosted product) runs first-party username/password accounts behind an opaque server-side session cookie, while **access** mode (the default, for private self-host) trusts Cloudflare Access's `Cf-Access-Authenticated-User-Email`. Either way a single stable, opaque account id scopes history and R2 ownership (`customMetadata.user_email`), so cross-user access is impossible even if a UUID is guessed.
38
80
  - **Client-side video keyframe extraction** sends 8 evenly-spaced frames to vision-capable chat models instead of uploading the full video file.
39
- - **Searchable model picker** (v0.111.0) groups the live catalog (~94 entries across 7 modalities as of v0.174.3) with capability badges (vision, stream) inline; type to filter by name.
81
+ - **Searchable model picker** (v0.111.0) groups the live catalog from `GET /api/models` (chat + image + video + speech + music) with capability badges (vision, stream) inline; type to filter by name.
40
82
 
41
83
  ## Features
42
84
 
43
- **Chat (see `GET /api/models` / `src/models.ts` for the live list):**
44
- - Workers AI: Llama 4 Scout, Llama 3.x family, Qwen3 30B / QwQ 32B / Qwen2.5 Coder 32B, DeepSeek R1, Mistral Small 3.1, Gemma 4 26B, Granite 4 Micro, Nemotron 3 120B, GLM-4.7 Flash / GLM-5.2, GPT-OSS 120B / 20B, Kimi K2.6 / K2.7 Code, SEA-LION v4 27B, LLaVA 1.5 7B (single-shot vision; the one non-streaming model)
45
- - Anthropic (Unified Billing): Sonnet 5, Opus 5, Opus 4.8 / 4.7 / 4.6, Sonnet 4.6, Haiku 4.5 (all streaming; Fable needs `binding: true`)
46
- - xAI (Unified Billing): Grok 4.5, Grok 4.3, Grok 4.20 (Multi-Agent and Reasoning)
47
- - OpenAI (Unified Billing): GPT-5.5 / 5.5-pro, GPT-5.6 Sol / Terra / Luna (Responses API), GPT-5.4 / mini, o4-mini
48
- - Google Gemini (Unified Billing): Gemini 3.1 Pro, 3.5 Flash, 3.6 Flash
49
- - Moonshot (Unified Billing): Kimi K3
50
-
51
- **Image generation:** Google Nano Banana Pro / Nano Banana 2 / Lite / Imagen 4 (Unified Billing), GPT Image 1.5 and GPT Image 2 (opaque on the proxy; transparent PNG only when `OPENAI_API_KEY` is set, v0.174.0), Recraft V4 / V4.1 / V4.1 Pro (opaque, art-directed), 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. FLUX.2 models accept up to 4 reference images (v0.16.0) for image-to-image generation, downscaled client-side to 512px.
52
-
53
- **Video generation:** Google Veo 3.1 / 3.1 Fast, ByteDance Seedance 2.0 / 2.0 Fast / Mini, MiniMax Hailuo 2.3 / 2.3 Fast, RunwayML Gen-4.5, Alibaba HappyHorse 1.0 and 1.1 T2V / I2V plus Wan 2.7 I2V, PixVerse v6 / v5.6, Vidu Q3 Pro / Q3 Turbo, xAI Grok Imagine Video and Video 1.5. All route through Unified Billing and durable Cloudflare Workflows.
54
-
55
- **Music generation:** MiniMax Music 2.6 (Unified Billing, durable via Workflows).
56
-
57
- **Text-to-speech:** Aura-2 EN / ES, MeloTTS.
58
-
59
- **Speech-to-text:** Whisper Large v3 Turbo / Whisper / Whisper Tiny EN and Deepgram Nova-3 (one-shot transcription), plus **Deepgram Flux** conversational/streaming STT with live turn detection over a WebSocket (v0.108.0).
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`.
86
+
87
+ | Modality | Count |
88
+ | --- | ---: |
89
+ | Chat | 44 |
90
+ | Image | 21 |
91
+ | Video | 19 |
92
+ | Text-to-speech (TTS) | 3 |
93
+ | Speech-to-text (STT) | 4 |
94
+ | Music | 1 |
95
+ | Live voice (Flux) | 1 |
96
+ | **Total** | **93** |
97
+
98
+ #### Chat (44)
99
+
100
+ | Model id | Notes |
101
+ | --- | --- |
102
+ | `anthropic/claude-fable-5` | Anthropic; binding |
103
+ | `anthropic/claude-sonnet-5` | Anthropic |
104
+ | `anthropic/claude-opus-5` | Anthropic |
105
+ | `anthropic/claude-opus-4-8` | Anthropic |
106
+ | `anthropic/claude-opus-4-7` | Anthropic |
107
+ | `anthropic/claude-opus-4-6` | Anthropic |
108
+ | `anthropic/claude-sonnet-4-6` | Anthropic |
109
+ | `anthropic/claude-haiku-4-5` | Anthropic |
110
+ | `xai/grok-4.5` | xAI |
111
+ | `xai/grok-4.3` | xAI |
112
+ | `xai/grok-4.20-multi-agent-0309` | xAI multi-agent |
113
+ | `xai/grok-4.20-0309-reasoning` | xAI reasoning |
114
+ | `moonshotai/kimi-k3` | Moonshot UB |
115
+ | `@cf/moonshotai/kimi-k2.6` | Workers AI |
116
+ | `@cf/moonshotai/kimi-k2.7-code` | Workers AI, vision |
117
+ | `@cf/openai/gpt-oss-120b` | Workers AI, reasoning |
118
+ | `@cf/meta/llama-4-scout-17b-16e-instruct` | Workers AI, vision |
119
+ | `@cf/google/gemma-4-26b-a4b-it` | Workers AI, vision |
120
+ | `@cf/openai/gpt-oss-20b` | Workers AI |
121
+ | `openai/gpt-5.5` | OpenAI UB |
122
+ | `openai/gpt-5.5-pro` | OpenAI Responses |
123
+ | `openai/gpt-5.6-sol` | OpenAI Responses |
124
+ | `openai/gpt-5.6-terra` | OpenAI Responses |
125
+ | `openai/gpt-5.6-luna` | OpenAI Responses |
126
+ | `openai/gpt-5.4` | OpenAI UB |
127
+ | `openai/gpt-5.4-mini` | OpenAI UB |
128
+ | `openai/o4-mini` | OpenAI reasoning |
129
+ | `@cf/meta/llama-3.3-70b-instruct-fp8-fast` | Workers AI |
130
+ | `@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
+ | `@cf/qwen/qwen2.5-coder-32b-instruct` | Workers AI |
135
+ | `@cf/deepseek-ai/deepseek-r1-distill-qwen-32b` | Workers AI |
136
+ | `@cf/mistralai/mistral-small-3.1-24b-instruct` | Workers AI, vision |
137
+ | `@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
+ | `@cf/aisingapore/gemma-sea-lion-v4-27b-it` | Workers AI |
141
+ | `google/gemini-3.1-pro` | Google Gemini, binding |
142
+ | `google/gemini-3.5-flash` | Google Gemini, binding |
143
+ | `google/gemini-3.6-flash` | Google Gemini, binding |
144
+ | `@cf/ibm-granite/granite-4.0-h-micro` | Workers AI |
145
+ | `@cf/meta/llama-3.2-1b-instruct` | Workers AI |
146
+
147
+ #### Image (21)
148
+
149
+ | Model id | Notes |
150
+ | --- | --- |
151
+ | `google/nano-banana-pro` | Google UB |
152
+ | `google/nano-banana-2` | Google UB |
153
+ | `google/nano-banana-2-lite` | Google UB |
154
+ | `google/imagen-4` | Google UB |
155
+ | `openai/gpt-image-1.5` | OpenAI UB; transparent PNG needs `OPENAI_API_KEY` |
156
+ | `openai/gpt-image-2` | OpenAI UB; transparent PNG needs `OPENAI_API_KEY` |
157
+ | `recraft/recraftv4` | Recraft UB |
158
+ | `recraft/recraftv4-1` | Recraft UB |
159
+ | `recraft/recraftv4-1-pro` | Recraft UB |
160
+ | `xai/grok-imagine-image` | xAI UB |
161
+ | `xai/grok-imagine-image-quality` | xAI UB |
162
+ | `bytedance/seedream-5-pro` | ByteDance UB |
163
+ | `bytedance/seedream-5-lite` | ByteDance UB |
164
+ | `@cf/black-forest-labs/flux-2-klein-9b` | FLUX 2; up to 4 refs |
165
+ | `@cf/black-forest-labs/flux-2-klein-4b` | FLUX 2; up to 4 refs |
166
+ | `@cf/black-forest-labs/flux-2-dev` | FLUX 2 multi-reference |
167
+ | `@cf/black-forest-labs/flux-1-schnell` | FLUX-1 fast |
168
+ | `@cf/leonardo/lucid-origin` | Leonardo |
169
+ | `@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
+
173
+ #### Video (19)
174
+
175
+ | Model id | Notes |
176
+ | --- | --- |
177
+ | `google/veo-3.1` | Workflow long-run |
178
+ | `google/veo-3.1-fast` | Workflow long-run |
179
+ | `bytedance/seedance-2.0` | Workflow long-run |
180
+ | `bytedance/seedance-2.0-fast` | Workflow long-run |
181
+ | `bytedance/seedance-2.0-mini` | Workflow long-run |
182
+ | `minimax/hailuo-2.3` | i2v-required |
183
+ | `minimax/hailuo-2.3-fast` | i2v-required |
184
+ | `xai/grok-imagine-video` | ZDR upload_url |
185
+ | `xai/grok-imagine-video-1.5-preview` | ZDR upload_url |
186
+ | `runwayml/gen-4.5` | Workflow long-run |
187
+ | `alibaba/hh1-t2v` | HappyHorse 1.0 T2V |
188
+ | `alibaba/hh1-i2v` | HappyHorse 1.0 I2V |
189
+ | `alibaba/hh1.1-t2v` | HappyHorse 1.1 T2V |
190
+ | `alibaba/hh1.1-i2v` | HappyHorse 1.1 I2V |
191
+ | `alibaba/wan-2.7-i2v` | Wan 2.7 I2V |
192
+ | `pixverse/v6` | Workflow long-run |
193
+ | `pixverse/v5.6` | Workflow long-run |
194
+ | `vidu/q3-pro` | Workflow long-run |
195
+ | `vidu/q3-turbo` | Workflow long-run |
196
+
197
+ #### TTS (3)
198
+
199
+ | Model id | Notes |
200
+ | --- | --- |
201
+ | `@cf/deepgram/aura-2-en` | English |
202
+ | `@cf/deepgram/aura-2-es` | Spanish speakers |
203
+ | `@cf/myshell-ai/melotts` | Multilingual |
204
+
205
+ #### STT (4)
206
+
207
+ | Model id | Notes |
208
+ | --- | --- |
209
+ | `@cf/openai/whisper-large-v3-turbo` | Best quality |
210
+ | `@cf/openai/whisper` | General |
211
+ | `@cf/openai/whisper-tiny-en` | Fast English |
212
+ | `@cf/deepgram/nova-3` | Accurate batch |
213
+
214
+ #### Music (1)
215
+
216
+ | Model id | Notes |
217
+ | --- | --- |
218
+ | `minimax/music-2.6` | Workflow long-run |
219
+
220
+ #### Live voice (1)
221
+
222
+ | Model id | Notes |
223
+ | --- | --- |
224
+ | `@cf/deepgram/flux` | Streaming STT over WebSocket |
60
225
 
61
226
  **Voice chat: talk to any model, hear it reply (v0.118.0):** a mic button on any chat model starts a hands-free loop, your speech is transcribed by Flux, each finished turn is sent to the selected model through the normal chat path, and the reply is spoken back via Aura-2 TTS. Works with every chat model in the catalog; the conversation saves to history like any other, and the whole loop runs on Cloudflare (no third-party STT/TTS). See [Voice chat](#voice-chat).
62
227
 
@@ -70,9 +235,11 @@ One Worker, no framework, no build step beyond TypeScript. The interesting parts
70
235
 
71
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.
72
237
 
73
- **Multi-turn conversations:** `conversation_id` plus `turn_index` on chat rows. Continuing a conversation pulls prior turns and assembles a full message history 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.
238
+ **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
+
240
+ **Conversation compact (v0.175.7):** long threads re-send every prior turn into the model context by default. The UI **compact** control (conversation header) asks a chat model to summarize older turns; the next call injects that summary into the system prompt and only re-sends the recent raw turns (default keep last 2). The full UI transcript is unchanged. **Expand** clears the summary so the next turn uses full history again. API: `POST` / `DELETE /api/conversations/:id/compact`; `GET /api/conversations/:id` returns `compact: null | { summary, through_turn_index, keep_recent, model, updated_at }`.
74
241
 
75
- **UI (focus-mode redesign, v0.110.0+):** a single centered conversation column with a floating composer; the sidebar (searchable history, projects, documents) is a slide-in overlay; a searchable model picker (type to filter, v0.111.0); a ⚙ popover for the system prompt + retrieval toggles and an account menu in the top bar; a paperclip attach button and a voice-chat mic. Capability-aware mode switching (vision-only attachment types; image-mode re-skins to "negative prompt"; TTS / STT / video / music / voice hide irrelevant inputs), FLUX.2 reference-image attach UI (v0.16.0), per-turn web-search toggle (v0.17.0), per-user replay-able history with attachments and generated artifacts, Enter to send / Shift+Enter for newline. Mobile-optimized (safe-area insets, touch targets, no iOS zoom).
242
+ **UI (focus-mode redesign, v0.110.0+):** a single centered conversation column with a floating composer; the sidebar (searchable history, projects, documents) is a slide-in overlay; a searchable model picker (type to filter, v0.111.0); a ⚙ popover for the system prompt + retrieval toggles and an account menu in the top bar; a paperclip attach button and a voice-chat mic; conversation header **compact** / **expand** when a thread has enough turns (v0.175.7). Capability-aware mode switching (vision-only attachment types; image-mode re-skins to "negative prompt"; TTS / STT / video / music / voice hide irrelevant inputs), FLUX.2 reference-image attach UI (v0.16.0), per-turn web-search toggle (v0.17.0), per-user replay-able history with attachments and generated artifacts, Enter to send / Shift+Enter for newline. Mobile-optimized (safe-area insets, touch targets, no iOS zoom).
76
243
 
77
244
  **Auth (two modes via `AUTH_MODE`):** **public** (the hosted product) is first-party username/password signup with an opaque session cookie and mandatory per-user BYOK: each user brings their own AI Gateway, the worker holds no gateway secrets, and inference bills the user, never the host. **access** (the default, for private self-host) puts Cloudflare Access on the worker URL and scopes per-user history and R2 ownership via `Cf-Access-Authenticated-User-Email` (free up to 50 seats on Zero Trust). See [Running the public service](#running-the-public-service).
78
245
 
@@ -362,9 +529,11 @@ The worker is the only public surface. R2 is private; the worker streams objects
362
529
  | GET/WS | `/api/stt/stream` | WebSocket for conversational STT (Deepgram Flux via the `SttSession` DO); persists the transcript to history on close |
363
530
  | POST | `/api/tts` | Synthesize text to speech (Aura-2) and stream the audio back (no history row); used by the voice-chat loop |
364
531
  | GET | `/api/conversations` | List the caller's conversations (grouped by `conversation_id`, includes each conversation's `project_id`) |
365
- | GET | `/api/conversations/:id` | Full transcript for a conversation |
366
- | DELETE | `/api/conversations/:id` | Cascade delete of all turns plus R2 artifacts |
532
+ | GET | `/api/conversations/:id` | Full transcript for a conversation; includes `compact` state when set (v0.175.7) |
533
+ | DELETE | `/api/conversations/:id` | Cascade delete of all turns plus R2 artifacts (and compact state) |
367
534
  | PATCH | `/api/conversations/:id/project` | Move a conversation to a project, or clear it (`{project_id: number \| null}`) |
535
+ | POST | `/api/conversations/:id/compact` | Summarize older turns for model context (`{ keep_recent?, model? }`; v0.175.7) |
536
+ | DELETE | `/api/conversations/:id/compact` | Clear compact summary; next turn uses full raw history (v0.175.7) |
368
537
  | GET | `/api/history/:id` | One chat row with full attachment + output references |
369
538
  | DELETE | `/api/history/:id` | Delete a single chat row and clean up its R2 objects |
370
539
  | GET | `/api/job/:id` | Poll an async video / music generation job's status |
@@ -792,7 +961,6 @@ If your use case is the legal-research pattern (citation accuracy matters, sourc
792
961
 
793
962
  ## Streaming
794
963
 
795
- `POST /api/chat/stream` accepts the same request body as `POST /api/chat` and returns `text/event-stream`. Available for any chat model flagged `streaming: true` in the catalog (almost all chat models; LLaVA 1.5 is the usual single-shot exception). Providers include Workers AI, Anthropic, xAI, OpenAI (Chat Completions and Responses), Google Gemini, and Moonshot.
796
964
 
797
965
  Wire format:
798
966
 
@@ -827,7 +995,6 @@ Note: AI Gateway does not surface `cf-aig-log-id` on proxied SSE responses, so s
827
995
  - `capabilities`: array. Currently only `"vision"` is recognized; applies to chat models only.
828
996
  - `provider` (optional): `"workers-ai"` (default) | `"anthropic"` | `"xai"` | `"openai"` | `"google"` | `"moonshotai"` | `"bytedance"` | `"minimax"` | `"runwayml"` | `"alibaba"` | `"pixverse"` | `"vidu"` | `"recraft"` (Unified Billing). Drives the call dispatch.
829
997
  - `api` (optional, OpenAI chat only): `"responses"` for Responses API models (v0.173.0); omit for Chat Completions.
830
- - `streaming` (optional, chat only): when `true`, the model is eligible for `POST /api/chat/stream`. Nearly all chat models; LLaVA 1.5 is the usual non-stream exception.
831
998
 
832
999
  Full Workers AI catalog: https://developers.cloudflare.com/workers-ai/models/. Skip anything tagged "Planned deprecation."
833
1000
 
@@ -0,0 +1,24 @@
1
+ -- Conversation compact state (v0.175.7 / prism compact ability).
2
+ --
3
+ -- Multi-turn chat currently resends every prior turn text into the model
4
+ -- context. A long thread blows the window. Compact stores a model-written
5
+ -- summary of older turns; the next chat turn injects that summary and only
6
+ -- the recent raw turns. The full transcript in chats stays intact for the UI.
7
+ --
8
+ -- through_turn_index is inclusive: turns with turn_index <= through_turn_index
9
+ -- are covered by summary and are NOT re-sent as raw user/assistant pairs.
10
+ -- keep_recent is recorded for display; the authoritative cut is through_turn_index.
11
+
12
+ CREATE TABLE IF NOT EXISTS conversation_compact (
13
+ conversation_id TEXT NOT NULL,
14
+ user_email TEXT NOT NULL,
15
+ summary TEXT NOT NULL,
16
+ through_turn_index INTEGER NOT NULL,
17
+ keep_recent INTEGER NOT NULL DEFAULT 2,
18
+ model TEXT NOT NULL,
19
+ updated_at TEXT NOT NULL DEFAULT (datetime('now')),
20
+ PRIMARY KEY (conversation_id, user_email)
21
+ );
22
+
23
+ CREATE INDEX IF NOT EXISTS idx_conversation_compact_user
24
+ ON conversation_compact(user_email);
@@ -0,0 +1,58 @@
1
+ -- 0004: CSP violation collector (fleet-chezmoi#1646).
2
+ --
3
+ -- Two tables, and the split is the point. `csp_report_buckets` is a rate-limit
4
+ -- counter and could have reused `auth_attempts`, which already has exactly this
5
+ -- shape and a prefixed bucket-key namespace. It deliberately does not.
6
+ --
7
+ -- WHY: the collector's write endpoint is UNAUTHENTICATED by construction, because
8
+ -- browsers post CSP reports without credentials. Pointing an unauthenticated
9
+ -- public write path at the same table the LOGIN limiter depends on means a flood
10
+ -- against the collector contends with sign-in. One extra table is a cheap price
11
+ -- for not coupling a public write path to the auth path.
12
+ --
13
+ -- Apply to an existing database with:
14
+ -- npx wrangler d1 execute skyphusion-llm --remote --file=migrations/0004_csp_reports.sql
15
+ -- Fresh databases get this from schema.sql.
16
+
17
+ -- Collected violations. Every column is a BOUNDED projection of an
18
+ -- attacker-controlled report body; nothing is stored verbatim.
19
+ --
20
+ -- NOT STORED, deliberately: `script-sample`. It can carry fragments of inline
21
+ -- script from a page that handles a credential, and a violation is diagnosable
22
+ -- from the directive plus the blocked URI without it.
23
+ CREATE TABLE IF NOT EXISTS csp_reports (
24
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
25
+ received_at TEXT NOT NULL DEFAULT (datetime('now')),
26
+ -- document_uri is stored with query and fragment STRIPPED. The SPA puts
27
+ -- nothing in URLs (measured), so this costs nothing today and stops the
28
+ -- collector becoming the first place a URL-borne value is persisted.
29
+ document_uri TEXT,
30
+ referrer TEXT,
31
+ violated_directive TEXT,
32
+ effective_directive TEXT,
33
+ blocked_uri TEXT,
34
+ disposition TEXT,
35
+ status_code INTEGER,
36
+ source_file TEXT,
37
+ line_number INTEGER,
38
+ column_number INTEGER
39
+ );
40
+
41
+ -- Read path is operator-only and deliberately has no HTTP endpoint: there is no
42
+ -- admin role on this product, so an authenticated read route would let any
43
+ -- signed-up user read operator diagnostics from a credential-handling page.
44
+ -- Operators query with:
45
+ -- npx wrangler d1 execute skyphusion-llm --remote \
46
+ -- --command "SELECT received_at, effective_directive, blocked_uri, document_uri
47
+ -- FROM csp_reports ORDER BY id DESC LIMIT 50;"
48
+ CREATE INDEX IF NOT EXISTS idx_csp_reports_received ON csp_reports(received_at);
49
+
50
+ -- Rate-limit buckets for the collector, isolated from auth_attempts per the note
51
+ -- above. `dropped` is what makes shedding VISIBLE: without it a rate-limited
52
+ -- estate and a quiet one produce an identical empty table.
53
+ CREATE TABLE IF NOT EXISTS csp_report_buckets (
54
+ bucket_key TEXT PRIMARY KEY,
55
+ count INTEGER NOT NULL DEFAULT 0,
56
+ dropped INTEGER NOT NULL DEFAULT 0,
57
+ window_start TEXT NOT NULL DEFAULT (datetime('now'))
58
+ );
@@ -21,12 +21,12 @@
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.19.1",
25
- "@cloudflare/workers-types": "^5.20260804.1",
26
- "@types/node": "^26.1.2",
24
+ "@cloudflare/vitest-pool-workers": "^0.20.3",
25
+ "@cloudflare/workers-types": "^5.20260809.1",
26
+ "@types/node": "^26.2.0",
27
27
  "@vitest/coverage-v8": "^4.1.10",
28
28
  "typescript": "^7.0.2",
29
29
  "vitest": "^4.1.8",
30
- "wrangler": "^4.118.0"
30
+ "wrangler": "^4.120.0"
31
31
  }
32
32
  }
@@ -192,6 +192,9 @@ const userInput = $("#user-input");
192
192
  const runBtn = $("#run");
193
193
  const transcriptEl = $("#transcript");
194
194
  const convTitleEl = $("#conv-title");
195
+ const convCompactBadge = $("#conv-compact-badge");
196
+ const convCompactBtn = $("#conv-compact-btn");
197
+ const convUncompactBtn = $("#conv-uncompact-btn");
195
198
  const outputMeta = $("#output-meta");
196
199
  const historyList = $("#history-list");
197
200
  const accountEmail = $("#account-email");
@@ -260,6 +263,8 @@ const state = {
260
263
  gateway: null,
261
264
  currentConversationId: null,
262
265
  currentTurns: [],
266
+ /** Compact summary for model context (v0.175.7); null when expanded. */
267
+ currentCompact: null,
263
268
  modelsById: {},
264
269
  pendingAttachments: [],
265
270
  pollTimer: null,
@@ -629,7 +634,7 @@ async function handleFiles(files) {
629
634
  // STT and FLUX-2 despite the affordance UI being shown.
630
635
  const isFlux2 = m.id.startsWith("@cf/black-forest-labs/flux-2-");
631
636
  // v0.21.10: image-input (i2v) models accept a source image too. Without this,
632
- // the early guard dropped the file before the per-file branch ran — which
637
+ // the early guard dropped the file before the per-file branch ran -- which
633
638
  // killed BOTH the picker and drag/drop for i2v (the v0.21.9 fix patched
634
639
  // downstream of this return and never reached).
635
640
  const isImageInput = (m.capabilities || []).includes("image-input");
@@ -881,7 +886,7 @@ function renderRetrievedChunksHTML(chunks) {
881
886
  <span class="rc-file">${escapeHtml(c.title || "?")}</span>
882
887
  <span class="rc-meta">${escapeHtml(sourceLabel)}${score}</span>
883
888
  </summary>
884
- <pre class="rc-text"><a href="${escapeHtml(c.url || "#")}" target="_blank" rel="noopener noreferrer">${escapeHtml(c.url || "")}</a>
889
+ <pre class="rc-text"><a href="${escapeHtml(window.safeHref(c.url))}" target="_blank" rel="noopener noreferrer">${escapeHtml(c.url || "")}</a>
885
890
 
886
891
  ${escapeHtml(c.snippet || "")}</pre>
887
892
  </details>`;
@@ -1157,9 +1162,10 @@ async function loadConversations() {
1157
1162
 
1158
1163
  async function loadConversation(id) {
1159
1164
  stopPolling();
1160
- const { turns } = await api(`/api/conversations/${encodeURIComponent(id)}`);
1165
+ const data = await api(`/api/conversations/${encodeURIComponent(id)}`);
1161
1166
  state.currentConversationId = id;
1162
- state.currentTurns = turns || [];
1167
+ state.currentTurns = data.turns || [];
1168
+ state.currentCompact = data.compact || null;
1163
1169
 
1164
1170
  // Set the model picker to the most-recent turn's model so the user can
1165
1171
  // continue with the same model by default (they can switch before submitting).
@@ -1175,6 +1181,7 @@ async function loadConversation(id) {
1175
1181
 
1176
1182
  renderTranscript(state.currentTurns);
1177
1183
  updateConvTitle();
1184
+ updateCompactControls();
1178
1185
 
1179
1186
  // If the latest turn is still pending (async video/music job), resume polling.
1180
1187
  const last = state.currentTurns[state.currentTurns.length - 1];
@@ -1193,6 +1200,7 @@ function newChat() {
1193
1200
  stopPolling();
1194
1201
  state.currentConversationId = null;
1195
1202
  state.currentTurns = [];
1203
+ state.currentCompact = null;
1196
1204
  userInput.value = "";
1197
1205
  autoGrowUserInput();
1198
1206
  state.pendingAttachments = [];
@@ -1200,6 +1208,7 @@ function newChat() {
1200
1208
  renderTranscript([]);
1201
1209
  outputMeta.textContent = "";
1202
1210
  updateConvTitle();
1211
+ updateCompactControls();
1203
1212
  userInput.focus();
1204
1213
  }
1205
1214
 
@@ -1214,6 +1223,78 @@ function updateConvTitle() {
1214
1223
  }
1215
1224
  }
1216
1225
 
1226
+ /** Show compact/expand controls when the open conversation has enough chat turns. */
1227
+ function updateCompactControls() {
1228
+ if (!convCompactBtn || !convUncompactBtn || !convCompactBadge) return;
1229
+ const chatTurns = (state.currentTurns || []).filter(
1230
+ (t) => t.model_type === "chat" && t.status === "done" && t.user_input && t.output,
1231
+ );
1232
+ const hasConv = !!state.currentConversationId && chatTurns.length > 0;
1233
+ const compacted = !!state.currentCompact;
1234
+ // Need keep_recent(2) + at least one turn to summarize.
1235
+ const canCompact = hasConv && chatTurns.length >= 3;
1236
+
1237
+ convCompactBadge.hidden = !compacted;
1238
+ convCompactBtn.hidden = !canCompact || compacted;
1239
+ convUncompactBtn.hidden = !compacted;
1240
+ convCompactBtn.disabled = false;
1241
+ convUncompactBtn.disabled = false;
1242
+ }
1243
+
1244
+ async function compactCurrentConversation() {
1245
+ if (!state.currentConversationId) return;
1246
+ convCompactBtn.disabled = true;
1247
+ convCompactBtn.textContent = "compacting…";
1248
+ try {
1249
+ const model = modelSelect.value || undefined;
1250
+ const data = await api(
1251
+ `/api/conversations/${encodeURIComponent(state.currentConversationId)}/compact`,
1252
+ {
1253
+ method: "POST",
1254
+ body: JSON.stringify({ keep_recent: 2, model }),
1255
+ },
1256
+ );
1257
+ state.currentCompact = data.compact || null;
1258
+ updateCompactControls();
1259
+ const n = data.turns_summarized ?? 0;
1260
+ const k = data.turns_kept_raw ?? 0;
1261
+ outputMeta.textContent = `compacted ${n} turn${n === 1 ? "" : "s"}; keeping ${k} recent raw`;
1262
+ } catch (err) {
1263
+ outputMeta.textContent = err?.message || "compact failed";
1264
+ } finally {
1265
+ convCompactBtn.textContent = "compact";
1266
+ updateCompactControls();
1267
+ }
1268
+ }
1269
+
1270
+ async function uncompactCurrentConversation() {
1271
+ if (!state.currentConversationId) return;
1272
+ convUncompactBtn.disabled = true;
1273
+ try {
1274
+ await api(
1275
+ `/api/conversations/${encodeURIComponent(state.currentConversationId)}/compact`,
1276
+ { method: "DELETE" },
1277
+ );
1278
+ state.currentCompact = null;
1279
+ outputMeta.textContent = "expanded — next turn uses full history";
1280
+ updateCompactControls();
1281
+ } catch (err) {
1282
+ outputMeta.textContent = err?.message || "expand failed";
1283
+ updateCompactControls();
1284
+ }
1285
+ }
1286
+
1287
+ if (convCompactBtn) {
1288
+ convCompactBtn.addEventListener("click", () => {
1289
+ compactCurrentConversation();
1290
+ });
1291
+ }
1292
+ if (convUncompactBtn) {
1293
+ convUncompactBtn.addEventListener("click", () => {
1294
+ uncompactCurrentConversation();
1295
+ });
1296
+ }
1297
+
1217
1298
  // ---------- Transcript rendering ----------
1218
1299
 
1219
1300
  function renderTranscript(turns) {
@@ -2311,6 +2392,17 @@ async function openGatewayModal() {
2311
2392
 
2312
2393
  function closeGatewayModal() {
2313
2394
  if (gatewayModal) gatewayModal.hidden = true;
2395
+ // Drop the plaintext credentials out of the DOM on the way out, so no
2396
+ // client-side copy of either secret outlives the modal that collected
2397
+ // it. The clear lives HERE rather than at the call sites because every
2398
+ // dismissal already routes through this function (save success, the
2399
+ // cancel button, the backdrop, the X affordance, Escape): one clear on
2400
+ // the single chokepoint holds by construction, where five clears hold
2401
+ // only while all five stay correct. Adding a sixth dismissal path gets
2402
+ // this for free; tests/public-url-safety.test.ts asserts the routing
2403
+ // stays true so that stops being an assumption.
2404
+ if (gatewayModalToken) gatewayModalToken.value = "";
2405
+ if (gatewayModalCpKey) gatewayModalCpKey.value = "";
2314
2406
  }
2315
2407
 
2316
2408
  function showGatewayModalError(msg) {
@@ -2767,6 +2859,17 @@ function openAccountDeleteModal() {
2767
2859
  }
2768
2860
  function closeAccountDeleteModal() {
2769
2861
  if (accountDeleteModal) accountDeleteModal.hidden = true;
2862
+ // Drop the password out of the DOM on the way out, matching the AI Gateway
2863
+ // modal. All four dismissal paths route through here (the backdrop and the
2864
+ // close affordance via data-modal-close, Escape, and the cancel button), and
2865
+ // the success path calls location.reload(), so the value cannot outlive the
2866
+ // modal by either route.
2867
+ //
2868
+ // Deliberately NOT cleared on a failed delete: a wrong password leaves the
2869
+ // modal open with the value intact so the user can correct it. Clearing on
2870
+ // dismissal and clearing on every error are different rules, and only the
2871
+ // first one is wanted here.
2872
+ if (accountDeletePassword) accountDeletePassword.value = "";
2770
2873
  }
2771
2874
  async function submitAccountDelete() {
2772
2875
  const password = accountDeletePassword ? accountDeletePassword.value : "";
@@ -44,7 +44,7 @@
44
44
  </script>
45
45
  </head>
46
46
  <body>
47
- <a class="seo-skip" href="#auth-screen" style="position:absolute;left:-9999px">Prism multimodal AI playground: sign up or log in</a>
47
+ <a class="seo-skip" href="#auth-screen">Prism multimodal AI playground: sign up or log in</a>
48
48
  <!-- #80 public-mode first-party auth. Hidden by default; the boot probe
49
49
  (GET /api/session) reveals it only when mode=public and no session.
50
50
  Access / self-host deploys report mode=access and never show it. -->
@@ -201,6 +201,9 @@
201
201
  <main class="conversation">
202
202
  <header class="conv-head">
203
203
  <span id="conv-title">new conversation</span>
204
+ <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>
205
+ <button id="conv-compact-btn" type="button" class="conv-compact-btn" hidden title="Summarize older turns so the model uses less context">compact</button>
206
+ <button id="conv-uncompact-btn" type="button" class="conv-compact-btn conv-uncompact-btn" hidden title="Clear summary; next turn resends full history">expand</button>
204
207
  <span id="output-meta"></span>
205
208
  </header>
206
209
  <div id="transcript" class="transcript"></div>
@@ -366,6 +369,7 @@
366
369
  </div>
367
370
  </div>
368
371
 
372
+ <script src="/url-safety.js"></script>
369
373
  <script src="/voice-widget.js"></script>
370
374
  <script src="/app.js"></script>
371
375
  </body>
@@ -0,0 +1,25 @@
1
+ /* Conversational STT page chrome. Loaded by stt.html alongside styles.css.
2
+ These rules lived in an inline <style> block in stt.html until fc#1646.
3
+ An enforcing `style-src 'self'` blocks an inline <style> element, which
4
+ would have taken the entire layout of this page; an external sheet needs
5
+ no policy exception. Rules are unchanged, only relocated and dedented. */
6
+
7
+ .stt-layout { max-width: 820px; margin: 0 auto; padding: 1rem; }
8
+ .stt-controls { display: flex; align-items: center; gap: 1rem; margin: 1rem 0; }
9
+ #stt-start { font-size: 1rem; padding: 0.6rem 1.4rem; border-radius: 999px; cursor: pointer; }
10
+ #stt-start.is-live { background: #b3122c; color: #fff; }
11
+ .stt-status { opacity: 0.8; font-size: 0.9rem; }
12
+ .stt-live { min-height: 3.5rem; font-size: 1.25rem; line-height: 1.5; padding: 0.75rem 1rem;
13
+ border: 1px solid rgba(255,255,255,0.15); border-radius: 10px; margin-bottom: 1rem; }
14
+ .stt-live-interim { opacity: 0.55; font-style: italic; }
15
+ .stt-turns { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1.5rem; }
16
+ .stt-turn { padding: 0.5rem 0.75rem; border-radius: 8px; background: rgba(255,255,255,0.05); }
17
+ .stt-meta { font-size: 0.78rem; opacity: 0.6; }
18
+ .stt-debug { font-family: ui-monospace, monospace; font-size: 0.72rem; white-space: pre-wrap;
19
+ max-height: 220px; overflow-y: auto; background: rgba(0,0,0,0.25); padding: 0.5rem;
20
+ border-radius: 8px; }
21
+ .stt-debug-row { padding: 1px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
22
+ summary { cursor: pointer; opacity: 0.8; }
23
+ .stt-page-header { margin-bottom: 0.5rem; }
24
+ .stt-back { font-size: 0.85rem; opacity: 0.7; text-decoration: none; }
25
+ .stt-back:hover { opacity: 1; }
@@ -11,27 +11,7 @@
11
11
  <link rel="manifest" href="/manifest.webmanifest">
12
12
  <meta name="theme-color" content="#0E1730">
13
13
  <link rel="stylesheet" href="/styles.css">
14
- <style>
15
- .stt-layout { max-width: 820px; margin: 0 auto; padding: 1rem; }
16
- .stt-controls { display: flex; align-items: center; gap: 1rem; margin: 1rem 0; }
17
- #stt-start { font-size: 1rem; padding: 0.6rem 1.4rem; border-radius: 999px; cursor: pointer; }
18
- #stt-start.is-live { background: #b3122c; color: #fff; }
19
- .stt-status { opacity: 0.8; font-size: 0.9rem; }
20
- .stt-live { min-height: 3.5rem; font-size: 1.25rem; line-height: 1.5; padding: 0.75rem 1rem;
21
- border: 1px solid rgba(255,255,255,0.15); border-radius: 10px; margin-bottom: 1rem; }
22
- .stt-live-interim { opacity: 0.55; font-style: italic; }
23
- .stt-turns { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1.5rem; }
24
- .stt-turn { padding: 0.5rem 0.75rem; border-radius: 8px; background: rgba(255,255,255,0.05); }
25
- .stt-meta { font-size: 0.78rem; opacity: 0.6; }
26
- .stt-debug { font-family: ui-monospace, monospace; font-size: 0.72rem; white-space: pre-wrap;
27
- max-height: 220px; overflow-y: auto; background: rgba(0,0,0,0.25); padding: 0.5rem;
28
- border-radius: 8px; }
29
- .stt-debug-row { padding: 1px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
30
- summary { cursor: pointer; opacity: 0.8; }
31
- .stt-page-header { margin-bottom: 0.5rem; }
32
- .stt-back { font-size: 0.85rem; opacity: 0.7; text-decoration: none; }
33
- .stt-back:hover { opacity: 1; }
34
- </style>
14
+ <link rel="stylesheet" href="/stt.css">
35
15
  </head>
36
16
  <body class="stt-body">
37
17
  <!-- Conversational STT is a skyphusion-llm playground feature; standalone