@skyphusion/create-prism 0.1.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/LICENSE +235 -0
- package/NOTICE +3 -0
- package/README.md +114 -0
- package/index.js +195 -0
- package/package.json +44 -0
- package/template/CONTRIBUTING.md +80 -0
- package/template/LICENSE +235 -0
- package/template/MIGRATIONS.md +197 -0
- package/template/NOTICE +3 -0
- package/template/README.md +875 -0
- package/template/docs/legal/INSTANCE-ACCEPTABLE-USE.md +98 -0
- package/template/docs/legal/INSTANCE-PRIVACY.md +112 -0
- package/template/docs/legal/README.md +11 -0
- package/template/docs/screenshot-desktop.jpg +0 -0
- package/template/docs/screenshot-mobile.jpg +0 -0
- package/template/gitignore +23 -0
- package/template/migrate-v0.164.0.sql +6 -0
- package/template/migrate-v0.167.0.sql +44 -0
- package/template/migrate-v0.20.0.sql +40 -0
- package/template/migrate-v0.20.2.sql +19 -0
- package/template/migrate-v0.20.3.sql +36 -0
- package/template/migrations/0001_init.sql +134 -0
- package/template/package.json +32 -0
- package/template/public/app.js +2778 -0
- package/template/public/apple-touch-icon.png +0 -0
- package/template/public/favicon-16.png +0 -0
- package/template/public/favicon-32.png +0 -0
- package/template/public/favicon.svg +5 -0
- package/template/public/icon-192.png +0 -0
- package/template/public/icon-512.png +0 -0
- package/template/public/index.html +329 -0
- package/template/public/manifest.webmanifest +14 -0
- package/template/public/streaming-client.js +207 -0
- package/template/public/stt.html +68 -0
- package/template/public/stt.js +16 -0
- package/template/public/styles.css +2068 -0
- package/template/public/voice-widget.js +195 -0
- package/template/schema.sql +283 -0
- package/template/src/ai-binding.ts +33 -0
- package/template/src/auth-kdf.ts +106 -0
- package/template/src/auth.ts +315 -0
- package/template/src/chunking.ts +161 -0
- package/template/src/discord.ts +353 -0
- package/template/src/env.ts +55 -0
- package/template/src/gateway-credentials.ts +97 -0
- package/template/src/health-schema.ts +25 -0
- package/template/src/index.ts +4180 -0
- package/template/src/longrun-params.ts +135 -0
- package/template/src/models.ts +214 -0
- package/template/src/output-extract.ts +128 -0
- package/template/src/parsers/anthropic-sse.ts +56 -0
- package/template/src/parsers/gemini-sse.ts +62 -0
- package/template/src/parsers/openai-sse.ts +60 -0
- package/template/src/parsers/sse-framer.ts +39 -0
- package/template/src/parsers/types.ts +16 -0
- package/template/src/parsers/workers-ai-sse.ts +43 -0
- package/template/src/parsers/xai-sse.ts +40 -0
- package/template/src/providers/anthropic.ts +208 -0
- package/template/src/providers/google.ts +150 -0
- package/template/src/providers/openai.ts +69 -0
- package/template/src/providers/workers-ai.ts +83 -0
- package/template/src/providers/xai.ts +159 -0
- package/template/src/proxied-image-params.ts +43 -0
- package/template/src/rate-limit.ts +77 -0
- package/template/src/searxng.ts +75 -0
- package/template/src/session.ts +114 -0
- package/template/src/stt-session.ts +206 -0
- package/template/src/stt-util.ts +19 -0
- package/template/src/types.ts +56 -0
- package/template/src/user-prefs.ts +63 -0
- package/template/src/utils.ts +73 -0
- package/template/src/zip.ts +137 -0
- package/template/tests/anthropic-sse.test.ts +149 -0
- package/template/tests/auth-kdf.test.ts +59 -0
- package/template/tests/auth-unit.test.ts +97 -0
- package/template/tests/chunking.test.ts +217 -0
- package/template/tests/discord.test.ts +184 -0
- package/template/tests/gateway-credentials.test.ts +65 -0
- package/template/tests/gemini-sse.test.ts +75 -0
- package/template/tests/google-gemini.test.ts +65 -0
- package/template/tests/health-schema.test.ts +35 -0
- package/template/tests/longrun-params.test.ts +128 -0
- package/template/tests/openai-sse.test.ts +71 -0
- package/template/tests/output-extract.test.ts +171 -0
- package/template/tests/proxied-image-params.test.ts +51 -0
- package/template/tests/rate-limit.test.ts +45 -0
- package/template/tests/searxng.test.ts +51 -0
- package/template/tests/sse-framer.test.ts +113 -0
- package/template/tests/stt-session.test.ts +35 -0
- package/template/tests/utils.test.ts +39 -0
- package/template/tests/workers-ai-sse.test.ts +67 -0
- package/template/tests/xai-sse.test.ts +60 -0
- package/template/tests/zip.test.ts +145 -0
- package/template/tests-integration/auth.test.ts +371 -0
- package/template/tests-integration/worker.test.ts +322 -0
- package/template/tsconfig.json +18 -0
- package/template/vitest.config.ts +18 -0
- package/template/vitest.node.config.ts +19 -0
- package/template/vitest.workers.config.ts +47 -0
- package/template/wrangler.example.toml +151 -0
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="32" height="32">
|
|
2
|
+
<rect width="32" height="32" rx="7" fill="#0E1730"/>
|
|
3
|
+
<circle cx="16" cy="16" r="10" stroke="#5BC3FF" stroke-width="2.2" fill="none"/>
|
|
4
|
+
<line x1="16" y1="3" x2="16" y2="29" stroke="#FF5BA8" stroke-width="2.2" stroke-linecap="round"/>
|
|
5
|
+
</svg>
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
|
|
6
|
+
<title>skyphusion</title>
|
|
7
|
+
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
|
8
|
+
<link rel="icon" href="/favicon-32.png" type="image/png" sizes="32x32">
|
|
9
|
+
<link rel="icon" href="/favicon-16.png" type="image/png" sizes="16x16">
|
|
10
|
+
<link rel="apple-touch-icon" href="/apple-touch-icon.png" sizes="180x180">
|
|
11
|
+
<link rel="manifest" href="/manifest.webmanifest">
|
|
12
|
+
<meta name="theme-color" content="#0a0e1a">
|
|
13
|
+
<link rel="stylesheet" href="/styles.css">
|
|
14
|
+
</head>
|
|
15
|
+
<body>
|
|
16
|
+
<!-- #80 public-mode first-party auth. Hidden by default; the boot probe
|
|
17
|
+
(GET /api/session) reveals it only when mode=public and no session.
|
|
18
|
+
Access / self-host deploys report mode=access and never show it. -->
|
|
19
|
+
<div id="auth-screen" class="auth-screen" hidden>
|
|
20
|
+
<form id="auth-form" class="auth-card" novalidate>
|
|
21
|
+
<div class="auth-brand">
|
|
22
|
+
<span class="brand-mark" aria-hidden="true"></span>
|
|
23
|
+
<span class="brand-name">skyphusion</span>
|
|
24
|
+
</div>
|
|
25
|
+
<p class="auth-sub">multimodal AI playground</p>
|
|
26
|
+
|
|
27
|
+
<div class="auth-tabs" role="tablist" aria-label="log in or sign up">
|
|
28
|
+
<button type="button" id="auth-tab-login" class="auth-tab" role="tab" aria-selected="false">log in</button>
|
|
29
|
+
<button type="button" id="auth-tab-signup" class="auth-tab" role="tab" aria-selected="true">sign up</button>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
<div id="auth-error" class="modal-error auth-error" role="alert" hidden></div>
|
|
33
|
+
|
|
34
|
+
<div class="auth-field">
|
|
35
|
+
<label for="auth-username">username</label>
|
|
36
|
+
<input id="auth-username" type="text" autocomplete="username" autocapitalize="none" spellcheck="false" maxlength="32">
|
|
37
|
+
<div id="auth-username-note" class="auth-note">3 to 32 characters: letters, numbers, hyphen, underscore.</div>
|
|
38
|
+
<div id="auth-username-err" class="auth-field-err" hidden></div>
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
<div class="auth-field">
|
|
42
|
+
<label for="auth-password">password</label>
|
|
43
|
+
<input id="auth-password" type="password" autocomplete="new-password" maxlength="200">
|
|
44
|
+
<div id="auth-password-err" class="auth-field-err" hidden></div>
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
<div id="auth-confirm-field" class="auth-field">
|
|
48
|
+
<label for="auth-password2">confirm password</label>
|
|
49
|
+
<input id="auth-password2" type="password" autocomplete="new-password" maxlength="200">
|
|
50
|
+
<div id="auth-password2-err" class="auth-field-err" hidden></div>
|
|
51
|
+
</div>
|
|
52
|
+
|
|
53
|
+
<button type="submit" id="auth-submit" class="auth-submit">create account</button>
|
|
54
|
+
|
|
55
|
+
<p class="auth-foot">
|
|
56
|
+
Inference runs on your own Cloudflare account: after you sign in, configure
|
|
57
|
+
an AI Gateway (slug plus a Unified Billing token) under Account. Workers,
|
|
58
|
+
storage, and retrieval are hosted; model spend is yours.
|
|
59
|
+
</p>
|
|
60
|
+
</form>
|
|
61
|
+
</div>
|
|
62
|
+
|
|
63
|
+
<div class="layout">
|
|
64
|
+
<!-- backdrop for the slide-in sidebar (focus mode: sidebar is an overlay) -->
|
|
65
|
+
<div id="sidebar-backdrop" class="sidebar-backdrop"></div>
|
|
66
|
+
|
|
67
|
+
<!-- slide-in sidebar -->
|
|
68
|
+
<aside class="sidebar">
|
|
69
|
+
<header class="sidebar-header">
|
|
70
|
+
<h1>history</h1>
|
|
71
|
+
<button id="new-chat" type="button">+ new</button>
|
|
72
|
+
</header>
|
|
73
|
+
<input id="history-search" class="history-search" type="search" placeholder="search history…" aria-label="search history">
|
|
74
|
+
<ul id="history-list" class="history-list"></ul>
|
|
75
|
+
<section class="projects-section">
|
|
76
|
+
<header class="sidebar-header">
|
|
77
|
+
<h2>projects</h2>
|
|
78
|
+
<button id="proj-new-btn" type="button">+ new</button>
|
|
79
|
+
</header>
|
|
80
|
+
<ul id="projects-list" class="projects-list"></ul>
|
|
81
|
+
<div id="proj-status" class="doc-status"></div>
|
|
82
|
+
</section>
|
|
83
|
+
<section class="documents-section">
|
|
84
|
+
<header class="sidebar-header">
|
|
85
|
+
<h2>documents</h2>
|
|
86
|
+
<button id="doc-upload-btn" type="button">+ upload</button>
|
|
87
|
+
</header>
|
|
88
|
+
<input id="doc-file-input" type="file" hidden>
|
|
89
|
+
<ul id="documents-list" class="documents-list"></ul>
|
|
90
|
+
<div id="doc-status" class="doc-status"></div>
|
|
91
|
+
</section>
|
|
92
|
+
</aside>
|
|
93
|
+
|
|
94
|
+
<!-- main column -->
|
|
95
|
+
<div class="main">
|
|
96
|
+
<header class="topbar">
|
|
97
|
+
<button id="sidebar-toggle" class="icon-btn" type="button" aria-label="Menu">☰</button>
|
|
98
|
+
<a class="brand" href="/" aria-label="skyphusion home">
|
|
99
|
+
<span class="brand-mark" aria-hidden="true"></span>
|
|
100
|
+
<span class="brand-name">skyphusion</span>
|
|
101
|
+
</a>
|
|
102
|
+
<div class="topbar-model">
|
|
103
|
+
<div id="model" class="model-picker"></div>
|
|
104
|
+
</div>
|
|
105
|
+
<button id="settings-toggle" class="icon-btn" type="button" aria-label="Prompt & options" title="prompt & options">⚙</button>
|
|
106
|
+
<div class="account">
|
|
107
|
+
<button id="account-toggle" class="icon-btn" type="button" aria-haspopup="true" aria-expanded="false" aria-label="Account & tools">
|
|
108
|
+
<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 3.6-7 8-7s8 3 8 7"/></svg>
|
|
109
|
+
</button>
|
|
110
|
+
<div id="account-menu" class="account-menu" role="menu" hidden>
|
|
111
|
+
<button id="account-user" class="account-row account-user" type="button" role="menuitem" title="AI Gateway settings">
|
|
112
|
+
<span class="account-ico"><svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="8" r="4"/><path d="M4 21c0-4 3.6-7 8-7s8 3 8 7"/></svg></span>
|
|
113
|
+
<span class="account-email" id="account-email">loading…</span>
|
|
114
|
+
</button>
|
|
115
|
+
<a class="account-row account-link" href="/stt.html" role="menuitem">
|
|
116
|
+
<span class="account-name">Voice</span>
|
|
117
|
+
<span class="account-sub">Conversational STT</span>
|
|
118
|
+
</a>
|
|
119
|
+
<a class="account-row account-link" href="https://github.com/skyphusion-labs/prism/blob/main/docs/legal/INSTANCE-PRIVACY.md" role="menuitem" target="_blank" rel="noopener">
|
|
120
|
+
<span class="account-name">Privacy notice</span>
|
|
121
|
+
<span class="account-sub">How this hosted instance handles your data</span>
|
|
122
|
+
</a>
|
|
123
|
+
<a class="account-row account-link" href="https://github.com/skyphusion-labs/prism/blob/main/docs/legal/INSTANCE-ACCEPTABLE-USE.md" role="menuitem" target="_blank" rel="noopener">
|
|
124
|
+
<span class="account-name">Acceptable use</span>
|
|
125
|
+
<span class="account-sub">Good-faith use policy for play.skyphusion.org</span>
|
|
126
|
+
</a>
|
|
127
|
+
<a class="account-row account-link" href="https://github.com/skyphusion-labs/prism" role="menuitem" target="_blank" rel="noopener">
|
|
128
|
+
<span class="account-name">Source code</span>
|
|
129
|
+
<span class="account-sub">AGPL-3.0; view or self-host this instance</span>
|
|
130
|
+
</a>
|
|
131
|
+
<button id="account-logout" class="account-row account-link account-logout" type="button" role="menuitem" hidden>
|
|
132
|
+
<span class="account-name">Log out</span>
|
|
133
|
+
<span class="account-sub">End this session</span>
|
|
134
|
+
</button>
|
|
135
|
+
<button id="account-delete" class="account-row account-link account-delete" type="button" role="menuitem" hidden>
|
|
136
|
+
<span class="account-name">Delete account</span>
|
|
137
|
+
<span class="account-sub">Permanently erase your account and data</span>
|
|
138
|
+
</button>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
</header>
|
|
142
|
+
|
|
143
|
+
<div id="gateway-banner" class="gateway-banner" hidden>
|
|
144
|
+
<span id="gateway-banner-text">AI Gateway not configured. Set your gateway slug and Cloudflare API token to run models on your account.</span>
|
|
145
|
+
<button id="gateway-banner-btn" type="button">Configure</button>
|
|
146
|
+
</div>
|
|
147
|
+
|
|
148
|
+
<!-- settings popover: system prompt + retrieval toggles + active project -->
|
|
149
|
+
<div id="settings-panel" class="settings-panel" hidden>
|
|
150
|
+
<div id="active-project-chip" class="active-project-chip" hidden>
|
|
151
|
+
<span class="apc-label">project:</span>
|
|
152
|
+
<span id="active-project-name" class="apc-name"></span>
|
|
153
|
+
<button id="active-project-clear" type="button" class="apc-clear" title="clear active project">✕</button>
|
|
154
|
+
</div>
|
|
155
|
+
<label class="settings-field">
|
|
156
|
+
<span id="system-prompt-label">system prompt</span>
|
|
157
|
+
<textarea id="system-prompt" rows="4" placeholder="optional"></textarea>
|
|
158
|
+
</label>
|
|
159
|
+
<label id="use-docs-row" class="use-docs-row" hidden>
|
|
160
|
+
<input id="use-docs" type="checkbox">
|
|
161
|
+
<span>use my docs</span>
|
|
162
|
+
</label>
|
|
163
|
+
<label id="use-web-search-row" class="use-docs-row" hidden>
|
|
164
|
+
<input id="use-web-search" type="checkbox">
|
|
165
|
+
<span>search the web</span>
|
|
166
|
+
</label>
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
<main class="conversation">
|
|
170
|
+
<header class="conv-head">
|
|
171
|
+
<span id="conv-title">new conversation</span>
|
|
172
|
+
<span id="output-meta"></span>
|
|
173
|
+
</header>
|
|
174
|
+
<div id="transcript" class="transcript"></div>
|
|
175
|
+
</main>
|
|
176
|
+
|
|
177
|
+
<!-- floating composer -->
|
|
178
|
+
<div class="input-area">
|
|
179
|
+
<!-- live conversational-STT panel; shown only for a "voice" model -->
|
|
180
|
+
<div id="voice-panel" hidden>
|
|
181
|
+
<div class="voice-controls">
|
|
182
|
+
<button id="voice-start" type="button">Start listening</button>
|
|
183
|
+
<span id="voice-status" class="voice-status">idle</span>
|
|
184
|
+
</div>
|
|
185
|
+
<div id="voice-live"><span class="voice-hint">(live transcript appears here)</span></div>
|
|
186
|
+
<div id="voice-turns"></div>
|
|
187
|
+
</div>
|
|
188
|
+
<div id="attachments" class="attachments"></div>
|
|
189
|
+
<div class="composer">
|
|
190
|
+
<input id="file-input" type="file" multiple accept="image/*,audio/*,video/*" hidden>
|
|
191
|
+
<div id="attach-row" class="attach-row">
|
|
192
|
+
<button id="attach-btn" type="button" class="composer-attach" title="attach a file" aria-label="attach a file">
|
|
193
|
+
<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"/></svg>
|
|
194
|
+
</button>
|
|
195
|
+
</div>
|
|
196
|
+
<label id="user-input-field" class="composer-field">
|
|
197
|
+
<span id="user-input-label" class="sr-only">your input</span>
|
|
198
|
+
<textarea id="user-input" rows="1" placeholder="enter to send, shift+enter for newline"></textarea>
|
|
199
|
+
</label>
|
|
200
|
+
<button id="voice-chat-toggle" type="button" class="composer-mic" title="voice chat (talk to the model, hear it reply)" aria-label="voice chat" hidden>
|
|
201
|
+
<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="2" width="6" height="11" rx="3"/><path d="M5 10a7 7 0 0 0 14 0M12 17v4"/></svg>
|
|
202
|
+
</button>
|
|
203
|
+
<button id="run" type="button" class="composer-send" title="send" aria-label="send">
|
|
204
|
+
<svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 20V5M6 11l6-6 6 6"/></svg>
|
|
205
|
+
</button>
|
|
206
|
+
</div>
|
|
207
|
+
<div class="composer-foot">
|
|
208
|
+
<span id="voice-chat-status" class="voice-chat-status"></span>
|
|
209
|
+
<span id="attach-hint" class="hint"></span>
|
|
210
|
+
</div>
|
|
211
|
+
</div>
|
|
212
|
+
</div>
|
|
213
|
+
</div>
|
|
214
|
+
|
|
215
|
+
<div id="account-delete-modal" class="modal" hidden>
|
|
216
|
+
<div class="modal-backdrop" data-modal-close="account-delete-modal"></div>
|
|
217
|
+
<div class="modal-panel" role="dialog" aria-labelledby="account-delete-title" aria-modal="true">
|
|
218
|
+
<header class="modal-header">
|
|
219
|
+
<h2 id="account-delete-title">delete account</h2>
|
|
220
|
+
<button class="modal-close" data-modal-close="account-delete-modal" type="button" title="close">✕</button>
|
|
221
|
+
</header>
|
|
222
|
+
<div class="modal-body">
|
|
223
|
+
<p class="modal-hint account-delete-warning">This permanently erases your account and everything tied to it: chats, projects, uploaded documents, generated artifacts, and saved AI Gateway settings. This cannot be undone.</p>
|
|
224
|
+
<label class="modal-field">
|
|
225
|
+
<span>confirm your password</span>
|
|
226
|
+
<input id="account-delete-password" type="password" autocomplete="current-password" placeholder="enter your password to confirm">
|
|
227
|
+
</label>
|
|
228
|
+
<div id="account-delete-error" class="modal-error" hidden></div>
|
|
229
|
+
</div>
|
|
230
|
+
<footer class="modal-actions">
|
|
231
|
+
<button id="account-delete-cancel" type="button">cancel</button>
|
|
232
|
+
<button id="account-delete-confirm" type="button" class="modal-danger-primary">delete my account</button>
|
|
233
|
+
</footer>
|
|
234
|
+
</div>
|
|
235
|
+
</div>
|
|
236
|
+
|
|
237
|
+
<div id="gateway-modal" class="modal" hidden>
|
|
238
|
+
<div class="modal-backdrop" data-modal-close="gateway-modal"></div>
|
|
239
|
+
<div class="modal-panel" role="dialog" aria-labelledby="gateway-modal-title" aria-modal="true">
|
|
240
|
+
<header class="modal-header">
|
|
241
|
+
<h2 id="gateway-modal-title">AI Gateway</h2>
|
|
242
|
+
<button class="modal-close" data-modal-close="gateway-modal" type="button" title="close">✕</button>
|
|
243
|
+
</header>
|
|
244
|
+
<div class="modal-body">
|
|
245
|
+
<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>
|
|
246
|
+
<label class="modal-field">
|
|
247
|
+
<span>gateway slug</span>
|
|
248
|
+
<input id="gateway-modal-id" type="text" autocomplete="off" placeholder="my-gateway-slug">
|
|
249
|
+
</label>
|
|
250
|
+
<label class="modal-field">
|
|
251
|
+
<span>Cloudflare API token</span>
|
|
252
|
+
<input id="gateway-modal-token" type="password" autocomplete="new-password" placeholder="leave blank to keep existing">
|
|
253
|
+
<span id="gateway-modal-token-hint" class="modal-hint"></span>
|
|
254
|
+
</label>
|
|
255
|
+
<label class="modal-field modal-check">
|
|
256
|
+
<input id="gateway-modal-clear-token" type="checkbox">
|
|
257
|
+
<span>clear saved token</span>
|
|
258
|
+
</label>
|
|
259
|
+
<div id="gateway-modal-error" class="modal-error" hidden></div>
|
|
260
|
+
</div>
|
|
261
|
+
<footer class="modal-actions">
|
|
262
|
+
<button id="gateway-modal-cancel" type="button">cancel</button>
|
|
263
|
+
<button id="gateway-modal-save" type="button" class="modal-primary">save</button>
|
|
264
|
+
</footer>
|
|
265
|
+
</div>
|
|
266
|
+
</div>
|
|
267
|
+
|
|
268
|
+
<div id="project-modal" class="modal" hidden>
|
|
269
|
+
<div class="modal-backdrop" data-modal-close="project-modal"></div>
|
|
270
|
+
<div class="modal-panel" role="dialog" aria-labelledby="project-modal-title" aria-modal="true">
|
|
271
|
+
<header class="modal-header">
|
|
272
|
+
<h2 id="project-modal-title">new project</h2>
|
|
273
|
+
<button class="modal-close" data-modal-close="project-modal" type="button" title="close">✕</button>
|
|
274
|
+
</header>
|
|
275
|
+
<div class="modal-body">
|
|
276
|
+
<label class="modal-field">
|
|
277
|
+
<span>name</span>
|
|
278
|
+
<input id="project-modal-name" type="text" maxlength="200" placeholder="MUDD">
|
|
279
|
+
</label>
|
|
280
|
+
<label class="modal-field">
|
|
281
|
+
<span>description (optional)</span>
|
|
282
|
+
<input id="project-modal-desc" type="text" maxlength="500" placeholder="short description shown in the project list">
|
|
283
|
+
</label>
|
|
284
|
+
<label class="modal-field">
|
|
285
|
+
<span>system prompt (optional)</span>
|
|
286
|
+
<textarea id="project-modal-prompt" rows="6" placeholder="default system prompt for chats in this project. per-turn system prompts override it."></textarea>
|
|
287
|
+
</label>
|
|
288
|
+
<div id="project-modal-error" class="modal-error" hidden></div>
|
|
289
|
+
</div>
|
|
290
|
+
<footer class="modal-actions">
|
|
291
|
+
<button id="project-modal-delete" type="button" class="modal-danger" hidden>delete</button>
|
|
292
|
+
<button id="project-modal-cancel" type="button">cancel</button>
|
|
293
|
+
<button id="project-modal-save" type="button" class="modal-primary">save</button>
|
|
294
|
+
</footer>
|
|
295
|
+
</div>
|
|
296
|
+
</div>
|
|
297
|
+
|
|
298
|
+
<div id="project-docs-modal" class="modal" hidden>
|
|
299
|
+
<div class="modal-backdrop" data-modal-close="project-docs-modal"></div>
|
|
300
|
+
<div class="modal-panel" role="dialog" aria-labelledby="project-docs-modal-title" aria-modal="true">
|
|
301
|
+
<header class="modal-header">
|
|
302
|
+
<h2 id="project-docs-modal-title">manage documents</h2>
|
|
303
|
+
<button class="modal-close" data-modal-close="project-docs-modal" type="button" title="close">✕</button>
|
|
304
|
+
</header>
|
|
305
|
+
<div class="modal-body">
|
|
306
|
+
<p class="modal-hint">check the documents you want in this project. retrieval and per-project chats will be scoped to these documents.</p>
|
|
307
|
+
<ul id="project-docs-modal-list" class="project-docs-modal-list"></ul>
|
|
308
|
+
<div id="project-docs-modal-empty" class="modal-empty" hidden>no documents uploaded yet. upload one in the documents section first.</div>
|
|
309
|
+
<div class="discord-import">
|
|
310
|
+
<h3 class="discord-import-title">import a Discord export</h3>
|
|
311
|
+
<p class="modal-hint">upload a DiscordChatExporter JSON export (exported without "format markdown"). it's parsed into conversation chunks and added to this project.</p>
|
|
312
|
+
<div class="discord-import-row">
|
|
313
|
+
<button id="discord-import-btn" type="button">choose JSON export</button>
|
|
314
|
+
<label class="discord-import-opt"><input id="discord-import-bots" type="checkbox" checked> include bot messages</label>
|
|
315
|
+
</div>
|
|
316
|
+
<input id="discord-import-file" type="file" accept="application/json,.json" hidden>
|
|
317
|
+
<div id="discord-import-status" class="discord-import-status" hidden></div>
|
|
318
|
+
</div>
|
|
319
|
+
</div>
|
|
320
|
+
<footer class="modal-actions">
|
|
321
|
+
<button id="project-docs-modal-close" type="button">done</button>
|
|
322
|
+
</footer>
|
|
323
|
+
</div>
|
|
324
|
+
</div>
|
|
325
|
+
|
|
326
|
+
<script src="/voice-widget.js"></script>
|
|
327
|
+
<script src="/app.js"></script>
|
|
328
|
+
</body>
|
|
329
|
+
</html>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "skyphusion-llm-public",
|
|
3
|
+
"short_name": "skyphusion",
|
|
4
|
+
"description": "Multimodal AI playground (chat, image, audio, video, RAG)",
|
|
5
|
+
"start_url": "/",
|
|
6
|
+
"display": "standalone",
|
|
7
|
+
"background_color": "#0E1730",
|
|
8
|
+
"theme_color": "#0E1730",
|
|
9
|
+
"icons": [
|
|
10
|
+
{ "src": "/icon-192.png", "sizes": "192x192", "type": "image/png" },
|
|
11
|
+
{ "src": "/icon-512.png", "sizes": "512x512", "type": "image/png" },
|
|
12
|
+
{ "src": "/favicon.svg", "sizes": "any", "type": "image/svg+xml", "purpose": "any" }
|
|
13
|
+
]
|
|
14
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// streaming-client.js
|
|
2
|
+
//
|
|
3
|
+
// Pass 1 of the v0.13.0 SSE rollout. Connects to POST /api/chat/stream,
|
|
4
|
+
// decodes the custom wire envelope, invokes callbacks for each delta and
|
|
5
|
+
// the terminal event. Intentionally framework-free so it drops into the
|
|
6
|
+
// existing vanilla-JS app.js without dependencies.
|
|
7
|
+
//
|
|
8
|
+
// Wire format expected from the server (text/event-stream):
|
|
9
|
+
// data: {"type":"delta","text":"..."}
|
|
10
|
+
// data: {"type":"done","row_id":N,"latency_ms":N,"tokens_in":N|null,
|
|
11
|
+
// "tokens_out":N|null,"conversation_id":"...","turn_index":N}
|
|
12
|
+
// data: {"type":"error","message":"..."}
|
|
13
|
+
//
|
|
14
|
+
// Anything else on the wire is ignored. Anthropic's native event names are
|
|
15
|
+
// stripped server-side; the client only sees the envelope above.
|
|
16
|
+
//
|
|
17
|
+
// Why not EventSource:
|
|
18
|
+
// EventSource is GET-only and doesn't let you set request headers or send
|
|
19
|
+
// a JSON body. POST + ReadableStream reader is the standard pattern for
|
|
20
|
+
// fetch-driven SSE.
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Open a streaming chat connection.
|
|
24
|
+
*
|
|
25
|
+
* @param {Object} body Same shape as POST /api/chat:
|
|
26
|
+
* { model, user_input, system_prompt?, attachments?, use_docs?, conversation_id? }
|
|
27
|
+
* @param {Object} callbacks
|
|
28
|
+
* onDelta(text: string) - one text fragment, called many times during a stream
|
|
29
|
+
* onDone(meta: {row_id, latency_ms, tokens_in, tokens_out, conversation_id, turn_index})
|
|
30
|
+
* - called exactly once on success
|
|
31
|
+
* onError(message: string)
|
|
32
|
+
* - called once on any failure; mutually exclusive with onDone
|
|
33
|
+
*
|
|
34
|
+
* @returns {Function} cancel() - aborts the in-flight stream. Safe to call after onDone/onError.
|
|
35
|
+
*/
|
|
36
|
+
export async function streamChat(body, callbacks) {
|
|
37
|
+
const controller = new AbortController();
|
|
38
|
+
const cancel = () => {
|
|
39
|
+
try { controller.abort(); } catch { /* already aborted */ }
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
let resp;
|
|
43
|
+
try {
|
|
44
|
+
resp = await fetch("/api/chat/stream", {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: { "content-type": "application/json" },
|
|
47
|
+
body: JSON.stringify(body),
|
|
48
|
+
signal: controller.signal,
|
|
49
|
+
});
|
|
50
|
+
} catch (err) {
|
|
51
|
+
if (err && err.name === "AbortError") return cancel;
|
|
52
|
+
callbacks.onError(err && err.message ? err.message : String(err));
|
|
53
|
+
return cancel;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Non-2xx responses from the streaming endpoint are JSON error bodies (the
|
|
57
|
+
// server only switches to SSE once validation passes). Parse and surface.
|
|
58
|
+
if (!resp.ok) {
|
|
59
|
+
let errBody;
|
|
60
|
+
try {
|
|
61
|
+
errBody = await resp.json();
|
|
62
|
+
} catch {
|
|
63
|
+
errBody = { error: `HTTP ${resp.status}` };
|
|
64
|
+
}
|
|
65
|
+
callbacks.onError(errBody.error || `HTTP ${resp.status}`);
|
|
66
|
+
return cancel;
|
|
67
|
+
}
|
|
68
|
+
if (!resp.body) {
|
|
69
|
+
callbacks.onError("No response body");
|
|
70
|
+
return cancel;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const reader = resp.body.getReader();
|
|
74
|
+
const decoder = new TextDecoder();
|
|
75
|
+
let buffer = "";
|
|
76
|
+
let sawTerminal = false; // tripped once we see "done" or "error"
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
while (true) {
|
|
80
|
+
const { done, value } = await reader.read();
|
|
81
|
+
if (done) break;
|
|
82
|
+
|
|
83
|
+
buffer += decoder.decode(value, { stream: true });
|
|
84
|
+
|
|
85
|
+
// SSE event boundary is \n\n. Within each event, we look only at
|
|
86
|
+
// `data:` lines. Multiple data lines per event would be concatenated
|
|
87
|
+
// by SSE spec, but the server never emits that, so the first data
|
|
88
|
+
// line wins.
|
|
89
|
+
const parts = buffer.split("\n\n");
|
|
90
|
+
buffer = parts.pop() ?? "";
|
|
91
|
+
|
|
92
|
+
for (const part of parts) {
|
|
93
|
+
if (!part.trim()) continue;
|
|
94
|
+
|
|
95
|
+
let payload = "";
|
|
96
|
+
for (const line of part.split("\n")) {
|
|
97
|
+
if (line.startsWith("data: ")) payload = line.slice(6);
|
|
98
|
+
else if (line.startsWith("data:")) payload = line.slice(5);
|
|
99
|
+
}
|
|
100
|
+
if (!payload) continue;
|
|
101
|
+
|
|
102
|
+
let event;
|
|
103
|
+
try {
|
|
104
|
+
event = JSON.parse(payload);
|
|
105
|
+
} catch {
|
|
106
|
+
continue; // malformed payload, skip
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (event.type === "delta" && typeof event.text === "string") {
|
|
110
|
+
callbacks.onDelta(event.text);
|
|
111
|
+
} else if (event.type === "done") {
|
|
112
|
+
sawTerminal = true;
|
|
113
|
+
callbacks.onDone({
|
|
114
|
+
row_id: event.row_id,
|
|
115
|
+
latency_ms: event.latency_ms,
|
|
116
|
+
tokens_in: event.tokens_in,
|
|
117
|
+
tokens_out: event.tokens_out,
|
|
118
|
+
conversation_id: event.conversation_id,
|
|
119
|
+
turn_index: event.turn_index,
|
|
120
|
+
});
|
|
121
|
+
} else if (event.type === "error") {
|
|
122
|
+
sawTerminal = true;
|
|
123
|
+
callbacks.onError(event.message || "Unknown stream error");
|
|
124
|
+
}
|
|
125
|
+
// unknown event types are ignored (forward compatibility)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Stream closed without a terminal event. Treat as truncation error
|
|
130
|
+
// unless the user cancelled us (in which case we don't fire onError).
|
|
131
|
+
if (!sawTerminal && !controller.signal.aborted) {
|
|
132
|
+
callbacks.onError("Stream closed unexpectedly");
|
|
133
|
+
}
|
|
134
|
+
} catch (err) {
|
|
135
|
+
if (err && err.name === "AbortError") {
|
|
136
|
+
// User-initiated cancel - don't fire onError.
|
|
137
|
+
return cancel;
|
|
138
|
+
}
|
|
139
|
+
if (!sawTerminal) {
|
|
140
|
+
callbacks.onError(err && err.message ? err.message : String(err));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return cancel;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ----- Integration sketch -----
|
|
148
|
+
//
|
|
149
|
+
// Drop the function above into your app.js (or import from a script tag /
|
|
150
|
+
// module). In the chat send handler, branch on whether the selected model
|
|
151
|
+
// has `streaming: true` in the catalog you already fetch from /api/models:
|
|
152
|
+
//
|
|
153
|
+
// async function sendChat() {
|
|
154
|
+
// const modelId = MODEL_SELECT.value;
|
|
155
|
+
// const modelEntry = MODELS.find(m => m.id === modelId);
|
|
156
|
+
// const body = {
|
|
157
|
+
// model: modelId,
|
|
158
|
+
// user_input: INPUT.value,
|
|
159
|
+
// system_prompt: SYSTEM_PROMPT.value || undefined,
|
|
160
|
+
// use_docs: USE_DOCS_CHECKBOX.checked,
|
|
161
|
+
// conversation_id: currentConversationId || undefined,
|
|
162
|
+
// attachments: collectedAttachments(),
|
|
163
|
+
// };
|
|
164
|
+
//
|
|
165
|
+
// if (modelEntry?.streaming) {
|
|
166
|
+
// // Streaming path
|
|
167
|
+
// const bubble = appendAssistantBubble(""); // empty bubble, fills as deltas arrive
|
|
168
|
+
// setSendButtonState("streaming");
|
|
169
|
+
//
|
|
170
|
+
// const cancelStream = await streamChat(body, {
|
|
171
|
+
// onDelta: (text) => {
|
|
172
|
+
// bubble.textContent += text;
|
|
173
|
+
// scrollChatToBottom();
|
|
174
|
+
// },
|
|
175
|
+
// onDone: (meta) => {
|
|
176
|
+
// currentConversationId = meta.conversation_id;
|
|
177
|
+
// markBubbleComplete(bubble, meta); // attach latency/token stats
|
|
178
|
+
// refreshHistorySidebar();
|
|
179
|
+
// setSendButtonState("idle");
|
|
180
|
+
// },
|
|
181
|
+
// onError: (msg) => {
|
|
182
|
+
// bubble.classList.add("error");
|
|
183
|
+
// bubble.textContent += `\n[stream error: ${msg}]`;
|
|
184
|
+
// setSendButtonState("idle");
|
|
185
|
+
// },
|
|
186
|
+
// });
|
|
187
|
+
// // Wire your "stop generating" button to call cancelStream().
|
|
188
|
+
//
|
|
189
|
+
// } else {
|
|
190
|
+
// // Existing non-streaming path (POST /api/chat, JSON in/out).
|
|
191
|
+
// // ... your current code ...
|
|
192
|
+
// }
|
|
193
|
+
// }
|
|
194
|
+
//
|
|
195
|
+
// Notes:
|
|
196
|
+
// - The catalog from /api/models now includes a `streaming` field on each
|
|
197
|
+
// entry. Anthropic models have it true; everything else is false (Pass 1).
|
|
198
|
+
// - On the assistant bubble, accumulate text via textContent +=, not
|
|
199
|
+
// innerHTML, to avoid breaking markdown rendering mid-stream. Defer
|
|
200
|
+
// markdown / syntax-highlighting until onDone fires, then re-render the
|
|
201
|
+
// bubble once with your existing pipeline.
|
|
202
|
+
// - If you have a markdown renderer, you'll likely want a "rendering mode"
|
|
203
|
+
// toggle: raw text during streaming, parsed markdown after onDone. Doing
|
|
204
|
+
// a partial markdown parse on every delta is expensive and visually
|
|
205
|
+
// janky (code fences open and close partway through).
|
|
206
|
+
// - The conversation_id flows back on onDone same as the non-stream path,
|
|
207
|
+
// so multi-turn continuation Just Works.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
|
|
6
|
+
<title>conversational STT - skyphusion-llm</title>
|
|
7
|
+
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
|
8
|
+
<link rel="icon" href="/favicon-32.png" type="image/png" sizes="32x32">
|
|
9
|
+
<link rel="icon" href="/favicon-16.png" type="image/png" sizes="16x16">
|
|
10
|
+
<link rel="apple-touch-icon" href="/apple-touch-icon.png" sizes="180x180">
|
|
11
|
+
<link rel="manifest" href="/manifest.webmanifest">
|
|
12
|
+
<meta name="theme-color" content="#0E1730">
|
|
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>
|
|
35
|
+
</head>
|
|
36
|
+
<body class="stt-body">
|
|
37
|
+
<!-- Conversational STT is a skyphusion-llm playground feature; standalone
|
|
38
|
+
page with its own minimal chrome. -->
|
|
39
|
+
<main class="stt-layout">
|
|
40
|
+
<header class="stt-page-header">
|
|
41
|
+
<a href="/" class="stt-back">← back to chat</a>
|
|
42
|
+
<h1>conversational STT</h1>
|
|
43
|
+
</header>
|
|
44
|
+
<p class="stt-status">
|
|
45
|
+
Real-time speech recognition with turn detection, powered by Deepgram Flux
|
|
46
|
+
(<code>@cf/deepgram/flux</code>) over a WebSocket. Click start, allow the mic, and talk.
|
|
47
|
+
</p>
|
|
48
|
+
|
|
49
|
+
<div class="stt-controls">
|
|
50
|
+
<button id="stt-start" type="button">Start listening</button>
|
|
51
|
+
<span id="stt-status" class="stt-status">idle</span>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<div id="stt-live" class="stt-live"><span class="stt-status">(live transcript appears here)</span></div>
|
|
55
|
+
|
|
56
|
+
<h2 class="stt-status">turns</h2>
|
|
57
|
+
<div id="stt-turns" class="stt-turns"></div>
|
|
58
|
+
|
|
59
|
+
<details>
|
|
60
|
+
<summary>raw events (debug)</summary>
|
|
61
|
+
<div id="stt-debug" class="stt-debug"></div>
|
|
62
|
+
</details>
|
|
63
|
+
</main>
|
|
64
|
+
|
|
65
|
+
<script src="/voice-widget.js"></script>
|
|
66
|
+
<script src="/stt.js"></script>
|
|
67
|
+
</body>
|
|
68
|
+
</html>
|