@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.
Files changed (100) hide show
  1. package/LICENSE +235 -0
  2. package/NOTICE +3 -0
  3. package/README.md +114 -0
  4. package/index.js +195 -0
  5. package/package.json +44 -0
  6. package/template/CONTRIBUTING.md +80 -0
  7. package/template/LICENSE +235 -0
  8. package/template/MIGRATIONS.md +197 -0
  9. package/template/NOTICE +3 -0
  10. package/template/README.md +875 -0
  11. package/template/docs/legal/INSTANCE-ACCEPTABLE-USE.md +98 -0
  12. package/template/docs/legal/INSTANCE-PRIVACY.md +112 -0
  13. package/template/docs/legal/README.md +11 -0
  14. package/template/docs/screenshot-desktop.jpg +0 -0
  15. package/template/docs/screenshot-mobile.jpg +0 -0
  16. package/template/gitignore +23 -0
  17. package/template/migrate-v0.164.0.sql +6 -0
  18. package/template/migrate-v0.167.0.sql +44 -0
  19. package/template/migrate-v0.20.0.sql +40 -0
  20. package/template/migrate-v0.20.2.sql +19 -0
  21. package/template/migrate-v0.20.3.sql +36 -0
  22. package/template/migrations/0001_init.sql +134 -0
  23. package/template/package.json +32 -0
  24. package/template/public/app.js +2778 -0
  25. package/template/public/apple-touch-icon.png +0 -0
  26. package/template/public/favicon-16.png +0 -0
  27. package/template/public/favicon-32.png +0 -0
  28. package/template/public/favicon.svg +5 -0
  29. package/template/public/icon-192.png +0 -0
  30. package/template/public/icon-512.png +0 -0
  31. package/template/public/index.html +329 -0
  32. package/template/public/manifest.webmanifest +14 -0
  33. package/template/public/streaming-client.js +207 -0
  34. package/template/public/stt.html +68 -0
  35. package/template/public/stt.js +16 -0
  36. package/template/public/styles.css +2068 -0
  37. package/template/public/voice-widget.js +195 -0
  38. package/template/schema.sql +283 -0
  39. package/template/src/ai-binding.ts +33 -0
  40. package/template/src/auth-kdf.ts +106 -0
  41. package/template/src/auth.ts +315 -0
  42. package/template/src/chunking.ts +161 -0
  43. package/template/src/discord.ts +353 -0
  44. package/template/src/env.ts +55 -0
  45. package/template/src/gateway-credentials.ts +97 -0
  46. package/template/src/health-schema.ts +25 -0
  47. package/template/src/index.ts +4180 -0
  48. package/template/src/longrun-params.ts +135 -0
  49. package/template/src/models.ts +214 -0
  50. package/template/src/output-extract.ts +128 -0
  51. package/template/src/parsers/anthropic-sse.ts +56 -0
  52. package/template/src/parsers/gemini-sse.ts +62 -0
  53. package/template/src/parsers/openai-sse.ts +60 -0
  54. package/template/src/parsers/sse-framer.ts +39 -0
  55. package/template/src/parsers/types.ts +16 -0
  56. package/template/src/parsers/workers-ai-sse.ts +43 -0
  57. package/template/src/parsers/xai-sse.ts +40 -0
  58. package/template/src/providers/anthropic.ts +208 -0
  59. package/template/src/providers/google.ts +150 -0
  60. package/template/src/providers/openai.ts +69 -0
  61. package/template/src/providers/workers-ai.ts +83 -0
  62. package/template/src/providers/xai.ts +159 -0
  63. package/template/src/proxied-image-params.ts +43 -0
  64. package/template/src/rate-limit.ts +77 -0
  65. package/template/src/searxng.ts +75 -0
  66. package/template/src/session.ts +114 -0
  67. package/template/src/stt-session.ts +206 -0
  68. package/template/src/stt-util.ts +19 -0
  69. package/template/src/types.ts +56 -0
  70. package/template/src/user-prefs.ts +63 -0
  71. package/template/src/utils.ts +73 -0
  72. package/template/src/zip.ts +137 -0
  73. package/template/tests/anthropic-sse.test.ts +149 -0
  74. package/template/tests/auth-kdf.test.ts +59 -0
  75. package/template/tests/auth-unit.test.ts +97 -0
  76. package/template/tests/chunking.test.ts +217 -0
  77. package/template/tests/discord.test.ts +184 -0
  78. package/template/tests/gateway-credentials.test.ts +65 -0
  79. package/template/tests/gemini-sse.test.ts +75 -0
  80. package/template/tests/google-gemini.test.ts +65 -0
  81. package/template/tests/health-schema.test.ts +35 -0
  82. package/template/tests/longrun-params.test.ts +128 -0
  83. package/template/tests/openai-sse.test.ts +71 -0
  84. package/template/tests/output-extract.test.ts +171 -0
  85. package/template/tests/proxied-image-params.test.ts +51 -0
  86. package/template/tests/rate-limit.test.ts +45 -0
  87. package/template/tests/searxng.test.ts +51 -0
  88. package/template/tests/sse-framer.test.ts +113 -0
  89. package/template/tests/stt-session.test.ts +35 -0
  90. package/template/tests/utils.test.ts +39 -0
  91. package/template/tests/workers-ai-sse.test.ts +67 -0
  92. package/template/tests/xai-sse.test.ts +60 -0
  93. package/template/tests/zip.test.ts +145 -0
  94. package/template/tests-integration/auth.test.ts +371 -0
  95. package/template/tests-integration/worker.test.ts +322 -0
  96. package/template/tsconfig.json +18 -0
  97. package/template/vitest.config.ts +18 -0
  98. package/template/vitest.node.config.ts +19 -0
  99. package/template/vitest.workers.config.ts +47 -0
  100. package/template/wrangler.example.toml +151 -0
@@ -0,0 +1,98 @@
1
+ # Acceptable use: the hosted Prism instance (play.skyphusion.org)
2
+
3
+ **Scope.** This applies to use of the one public Prism instance that Skyphusion Labs operates at
4
+ play.skyphusion.org. Prism is self-hosted software (AGPL-3.0-only); if you run your own instance, you
5
+ set your own rules as its operator. This notice governs our instance. It is not legal advice.
6
+
7
+ ## Your account
8
+
9
+ The hosted instance is open to self-serve signup: you create a username and password and use the
10
+ playground on your own account. In return:
11
+
12
+ - **Keep your credentials to yourself.** You are responsible for what happens under your account. Do
13
+ not share your login, and do not use someone else's account.
14
+ - **One human per account, signing up honestly.** No automated or bulk account creation, no bots
15
+ registering accounts, no evading a suspension by opening new accounts.
16
+ - **Signup and login are rate-limited**, and other basic abuse controls may be in place. Do not try to
17
+ defeat them.
18
+
19
+ ## Use it in good faith
20
+
21
+ The hosted instance is offered freely so people can try the Cloudflare AI stack. Do not abuse it:
22
+
23
+ - No attacks on, or interference with, the service or its infrastructure: no attempts to break,
24
+ overload, probe, or circumvent access controls, rate limits, or authentication.
25
+ - No illegal use, and no using it to produce or distribute unlawful, infringing, or malicious content.
26
+ - No harassment of, threats toward, or targeting of, other people.
27
+
28
+ ## You pay for your own model inference
29
+
30
+ The hosted instance does not pay for the models you run. You configure your own Cloudflare AI Gateway,
31
+ and model inference is billed to **your** Cloudflare Unified Billing account. That means:
32
+
33
+ - **Your gateway spend is yours.** You are solely responsible for the cost of the model calls you make
34
+ and for keeping your own AI Gateway credentials and billing in order. Skyphusion Labs does not
35
+ reimburse, cap, or manage your Cloudflare bill.
36
+ - **You own the content you generate**, and are responsible for it and for how you use it, subject to
37
+ the red lines below.
38
+
39
+ ## Do not abuse the host's infrastructure
40
+
41
+ Even though you pay for inference, Skyphusion Labs still pays to run the service itself (Workers, D1,
42
+ R2, and Vectorize compute and storage). Do not drain or abuse that:
43
+
44
+ - No using the instance as a free API, proxy, or backend for another application.
45
+ - No automated scraping of the service, no reselling or redistributing access to it.
46
+ - No stockpiling storage (uploads, generated media, RAG documents) beyond genuine personal use, and no
47
+ circumventing rate limits or account controls.
48
+
49
+ We may rate-limit, suspend, or terminate accounts, and block access to the hosted instance, to protect
50
+ the service and its infrastructure.
51
+
52
+ ## The absolute red line: child sexual abuse material (CSAM)
53
+
54
+ **Where we stand.** The Skyphusion Labs collective unequivocally condemns child sexual abuse material.
55
+ We do not condone it, in any form, for any reason, ever. Handing people a powerful generative tool
56
+ means some will try to use it for exactly this; that is precisely why this line is absolute.
57
+
58
+ **The prohibition.** You may not use the hosted instance to create, generate, attempt to generate,
59
+ request, solicit, or distribute any child sexual abuse material (CSAM): any sexual or sexualized
60
+ depiction of a minor, or of any person who is or appears to be a minor. This is zero-tolerance and has
61
+ no exceptions:
62
+
63
+ - It applies to **synthetic, AI-generated, "fake," fictional, cartoon, drawn, virtual, and "pretend"
64
+ depictions** exactly as much as to a photograph of a real child. It does not matter that no real
65
+ minor was involved or that the output is "just AI." There is no artistic, satirical, fictional, or
66
+ "age-play" exception.
67
+ - It covers **every generation path** on the instance: text-to-image, image-to-video, voice, and any
68
+ face, likeness, or lip-sync path.
69
+
70
+ **This is also the law.** United States federal law criminalizes computer-generated and synthetic
71
+ child sexual abuse material and obscene visual depictions of minors even where no actual child was
72
+ involved, including under **18 U.S.C. 1466A** and **18 U.S.C. 2252A**. The absence of a real child is
73
+ not a defense, and it is not one we recognize.
74
+
75
+ ## Non-consensual intimate imagery (NCII) and deepfakes
76
+
77
+ You may not use the hosted instance to create or distribute:
78
+
79
+ - **Non-consensual intimate imagery:** sexual or nude depictions of a real, identifiable person made
80
+ or shared without that person's consent, including "undressing" or sexualizing images of real people.
81
+ - **Non-consensual deepfakes and likeness abuse:** realistic depictions of a real, identifiable person
82
+ without their consent, especially where the result is intended or likely to deceive, defame,
83
+ defraud, harass, or exploit, including putting words or actions onto a real person, or using their
84
+ face, voice, or likeness without consent.
85
+
86
+ Consensual creative work with a person who has actually agreed, and clearly-labeled satire that does
87
+ not deceive, are different; the burden is on you to have that consent and to stay clear of the harms
88
+ above.
89
+
90
+ ## Enforcement
91
+
92
+ Because Skyphusion Labs operates this instance, we can and will act on abuse we become aware of on it.
93
+ For ordinary abuse (including infrastructure abuse) we may rate-limit, suspend, or terminate your
94
+ account and block access. For the CSAM / NCII bright line, we will terminate the account, preserve what
95
+ the law requires, and report to the National Center for Missing & Exploited Children (NCMEC), through
96
+ its CyberTipline, and to law enforcement. Our privacy stance is not a shield for this.
97
+
98
+ Not legal advice.
@@ -0,0 +1,112 @@
1
+ # Privacy notice: the hosted Prism instance (play.skyphusion.org)
2
+
3
+ **Scope.** This notice applies only to the one public Prism instance that Skyphusion Labs operates at
4
+ play.skyphusion.org. Prism is self-hosted software (AGPL-3.0-only). If you run your own Prism
5
+ instance, this notice does not apply to you: you are the operator of your instance, your data lives on
6
+ your own Cloudflare account, and Skyphusion Labs never sees it (see the project's README for the
7
+ self-hosted posture). This is a plain-language description of how the hosted instance handles data. It
8
+ is not legal advice.
9
+
10
+ ## Our headline, and the one honest exception
11
+
12
+ Across Skyphusion Labs the rule is simple: we do not want your data. The hosted Prism instance is the
13
+ one place where that is not literally zero. To give you a working playground with an account that
14
+ remembers your work, the hosted instance stores your account and the content you create. We keep it to
15
+ what is mechanically necessary to run the playground, and you can delete all of it yourself at any
16
+ time.
17
+
18
+ ## You sign in with a first-party account
19
+
20
+ The hosted instance uses its own username and password accounts. There is no Cloudflare Access, no
21
+ one-time-PIN email, and no third-party identity provider (Google, GitHub, and the like) in the path.
22
+ You sign up directly on play.skyphusion.org with a username and a password, and nothing else.
23
+
24
+ **We do not collect your email.** This release has no email, no password-reset, and no account-recovery
25
+ flow, so signup never asks for an email address and none is stored. Keep your password safe: if you
26
+ lose it, we have no way to email you a reset.
27
+
28
+ ## What the hosted instance stores (under your account)
29
+
30
+ - **Your account:** the username you choose, and your password stored **only** as a one-way hash
31
+ (PBKDF2-HMAC-SHA-256, with a per-account random salt and a high iteration count). We never store,
32
+ log, or transmit your password in plain text, and the hash cannot be reversed back into your
33
+ password.
34
+ - **Your session:** when you sign in, the instance sets an opaque session cookie. Server-side it keeps
35
+ only a SHA-256 hash of that session token (never the token itself), tied to your account and an
36
+ expiry. Logging out or deleting your account revokes the session immediately.
37
+ - **Your content:** the prompts and chats you write, and the images, video, music, and voice you
38
+ generate, plus any documents you add for retrieval (RAG). These are stored in the instance D1
39
+ database and R2 bucket, keyed to your account by a stable, opaque account id.
40
+ - **Your AI Gateway settings:** the gateway slug and Cloudflare AI Gateway token you enter so the
41
+ instance can run models on **your** account (see "How model inference is billed and routed" below).
42
+ - **Operational records** mechanically required to run the service: request and job state, and
43
+ abuse-control counters (see "Abuse controls" below).
44
+
45
+ ## Where it is stored
46
+
47
+ Everything above lives on Skyphusion Labs' own Cloudflare account: account and chat metadata, RAG
48
+ chunk text, session records, and your gateway settings in **D1**; all binary artifacts (uploads and
49
+ generated media) in **R2**; RAG embeddings in **Vectorize**. Nothing binary is stored in D1; chat rows
50
+ reference R2 keys.
51
+
52
+ ## How model inference is billed and routed (bring your own gateway)
53
+
54
+ The hosted instance does **not** pay for your model inference. Before you can run a paid or proxied
55
+ model you enter your own **Cloudflare AI Gateway** slug and an AI Gateway token in Account settings.
56
+ The instance stores those in its D1 database and uses them to send your model requests through **your**
57
+ AI Gateway, so inference is billed to **your** Cloudflare Unified Billing account, not ours. The
58
+ hosted worker has no gateway credentials of its own; with your settings unset, paid model calls fail
59
+ closed with a clear prompt to configure your gateway, rather than silently billing anyone else.
60
+
61
+ Treat the AI Gateway token you enter as you would any API credential. It is held in the instance
62
+ database solely to authorize your model calls, and deleting your account (below) removes it along with
63
+ everything else.
64
+
65
+ ## Abuse controls (transient IP processing)
66
+
67
+ To keep signup and login from being abused, the instance rate-limits those requests. It does this by
68
+ counting recent attempts against the caller's IP address (the address Cloudflare reports at the edge)
69
+ and, for login, the username being tried. IP addresses are processed for this abuse-control purpose
70
+ only; we do not use them to profile you, build a history, or track you across sessions.
71
+
72
+ ## What we do not do
73
+
74
+ No tracking, no advertising, no analytics or ad-tech, no profiling, no third-party data brokers. We do
75
+ not sell your data and we do not share it, with the single exception of the abuse bright line below
76
+ (CSAM / NCII), which we report as required by law.
77
+
78
+ ## Third parties in the path
79
+
80
+ The hosted instance runs on Cloudflare (Workers, D1, R2, Vectorize). Your model requests are sent
81
+ through the AI Gateway **you** configure, on your own Cloudflare account; the model providers reachable
82
+ through that gateway receive your prompt content in order to return a result, and handle it under their
83
+ own and your gateway's terms rather than ours.
84
+
85
+ **Web search is opt-in and does not use any third-party search API.** Prism has a per-turn web search
86
+ toggle. When you switch it on for a turn, the text of that one query is sent to the instance's own
87
+ self-hosted search service (SearXNG, run by Skyphusion Labs) and to keyless public sources such as
88
+ Wikipedia. No third-party search-API provider (and no per-provider API key) is in the path. The
89
+ snippets that come back are stored with the turn as retrieved context, the same way your RAG chunks
90
+ are. Your chat history, your uploaded documents, and your generated media are never sent out for
91
+ search. Leave the toggle off and no query leaves the instance.
92
+
93
+ ## Deleting your data
94
+
95
+ Account deletion is built into the app. From Account settings you delete your account (re-entering your
96
+ password to confirm), and it **cascades**: it removes your account record and sessions, your chats and
97
+ conversations, every generated artifact and uploaded document in R2, your RAG embeddings in Vectorize,
98
+ your projects, and your stored AI Gateway settings. Deletion is on you and takes effect on the
99
+ instance; we do not keep a shadow copy. If you self-host Prism instead, deletion is entirely in your
100
+ hands on your own instance.
101
+
102
+ ## The one bright line
103
+
104
+ This minimal-data, hands-off stance is not a shield for child sexual abuse material or non-consensual
105
+ intimate imagery. See the [instance Acceptable Use notice](INSTANCE-ACCEPTABLE-USE.md): that is the
106
+ one category we will act on and report.
107
+
108
+ ## Operator and contact
109
+
110
+ The hosted instance is operated by Skyphusion Labs. Data questions: **privacy@skyphusion.org**.
111
+
112
+ Not legal advice.
@@ -0,0 +1,11 @@
1
+ # Prism instance policies
2
+
3
+ These notices govern the one public Prism instance that Skyphusion Labs operates at
4
+ **play.skyphusion.org**. They describe our operation of our instance, and are separate from the
5
+ project's self-hosted posture in the top-level README: if you run your own Prism instance, you are its
6
+ operator and these notices do not bind you.
7
+
8
+ - [Privacy notice](INSTANCE-PRIVACY.md) -- what the hosted instance retains, and how to have it cleared.
9
+ - [Acceptable use](INSTANCE-ACCEPTABLE-USE.md) -- good-faith use, no wallet abuse, and the CSAM / NCII bright line.
10
+
11
+ Not legal advice.
@@ -0,0 +1,23 @@
1
+ node_modules/
2
+ .wrangler/
3
+ .dev.vars
4
+ .dev.vars.*
5
+ *.log
6
+ .DS_Store
7
+
8
+ # v0.12.0+: wrangler.toml is per-deployer (has your D1 id, your worker name);
9
+ # the committed template is wrangler.example.toml. Bootstrap with:
10
+ # cp wrangler.example.toml wrangler.toml (then fill in database_id and your name)
11
+ wrangler.toml
12
+ wrangler.production.toml
13
+
14
+ # Python bytecode (container app dirs)
15
+ __pycache__/
16
+ *.pyc
17
+
18
+ # Generated by `wrangler types`; this repo uses @cloudflare/workers-types instead (see CLAUDE.md).
19
+ worker-configuration.d.ts
20
+ .dev.access
21
+
22
+ # Vitest coverage output (code-coverage.yml regenerates it each run).
23
+ coverage/
@@ -0,0 +1,6 @@
1
+ -- v0.164.0: per-user AI Gateway credentials for public demo deployments.
2
+ CREATE TABLE IF NOT EXISTS user_prefs (
3
+ user_email TEXT PRIMARY KEY,
4
+ prefs_json TEXT NOT NULL DEFAULT '{}',
5
+ updated_at TEXT NOT NULL DEFAULT (datetime('now'))
6
+ );
@@ -0,0 +1,44 @@
1
+ -- Migration v0.167.0 (issue #80): first-party auth plane.
2
+ --
3
+ -- Adds the three tables the public-deployment auth core needs. Ownership
4
+ -- columns on existing tables (chats.user_email, documents.user_email, etc.) are
5
+ -- NOT renamed: in public mode they simply hold the opaque users.id string
6
+ -- instead of an Access email, so no data migration touches existing rows.
7
+ --
8
+ -- Apply to an existing DB with:
9
+ -- npx wrangler d1 execute skyphusion-llm --remote --file=./migrate-v0.167.0.sql
10
+ -- These are all CREATE TABLE / INDEX IF NOT EXISTS, so re-applying is a no-op.
11
+
12
+ -- Accounts. id is the opaque stable ownership key ("usr_" + 24 hex). username_lc
13
+ -- is the case-insensitive uniqueness key. password_hash is a PHC-style PBKDF2
14
+ -- string (see src/auth-kdf.ts). email is reserved for forward-compat (recovery)
15
+ -- and is not written by the v0.167.0 signup route.
16
+ CREATE TABLE IF NOT EXISTS users (
17
+ id TEXT PRIMARY KEY,
18
+ username TEXT NOT NULL,
19
+ username_lc TEXT NOT NULL UNIQUE,
20
+ password_hash TEXT NOT NULL,
21
+ email TEXT,
22
+ created_at TEXT NOT NULL DEFAULT (datetime('now'))
23
+ );
24
+
25
+ -- Sessions. token_hash is SHA-256(raw token) hex; the raw token lives only in
26
+ -- the httpOnly cookie, never in D1. Rows are dropped on logout, expiry, and
27
+ -- account deletion for instant server-side revocation.
28
+ CREATE TABLE IF NOT EXISTS sessions (
29
+ token_hash TEXT PRIMARY KEY,
30
+ user_id TEXT NOT NULL,
31
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
32
+ expires_at TEXT NOT NULL
33
+ );
34
+
35
+ CREATE INDEX IF NOT EXISTS idx_sessions_user ON sessions(user_id);
36
+
37
+ -- Signup/login rate-limit counters. bucket_key is e.g. "login:<ip>:<username>"
38
+ -- or "signup:<ip>"; count is the attempts in the current fixed window that
39
+ -- began at window_start. See src/rate-limit.ts.
40
+ CREATE TABLE IF NOT EXISTS auth_attempts (
41
+ bucket_key TEXT PRIMARY KEY,
42
+ count INTEGER NOT NULL DEFAULT 0,
43
+ window_start TEXT NOT NULL DEFAULT (datetime('now'))
44
+ );
@@ -0,0 +1,40 @@
1
+ -- v0.20.0 migration delta ONLY (projects + knowledge stores).
2
+ --
3
+ -- Adds the projects and project_documents tables plus their indexes. Every
4
+ -- statement uses CREATE TABLE / CREATE INDEX IF NOT EXISTS, so this delta is
5
+ -- safely re-runnable on its own. It is still a delta, not the full schema:
6
+ -- run this against an existing database, never the cumulative schema.sql
7
+ -- (which carries later non-idempotent ALTERs that abort the transaction).
8
+ --
9
+ -- Apply: wrangler d1 execute skyphusion-llm --remote --file=migrate-v0.20.0.sql
10
+
11
+ CREATE TABLE IF NOT EXISTS projects (
12
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
13
+ user_email TEXT NOT NULL,
14
+ name TEXT NOT NULL,
15
+ slug TEXT NOT NULL,
16
+ description TEXT,
17
+ system_prompt TEXT,
18
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
19
+ updated_at TEXT NOT NULL DEFAULT (datetime('now'))
20
+ );
21
+
22
+ CREATE INDEX IF NOT EXISTS idx_projects_user
23
+ ON projects(user_email, created_at DESC);
24
+
25
+ -- Slug uniqueness is per-user, not global. Two different users can both
26
+ -- have a project slugged 'mudd'.
27
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_projects_slug_user
28
+ ON projects(user_email, slug);
29
+
30
+ CREATE TABLE IF NOT EXISTS project_documents (
31
+ project_id INTEGER NOT NULL,
32
+ document_id INTEGER NOT NULL,
33
+ added_at TEXT NOT NULL DEFAULT (datetime('now')),
34
+ PRIMARY KEY (project_id, document_id),
35
+ FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
36
+ FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE
37
+ );
38
+
39
+ CREATE INDEX IF NOT EXISTS idx_project_documents_doc
40
+ ON project_documents(document_id);
@@ -0,0 +1,19 @@
1
+ -- v0.20.2 migration delta ONLY (conversation -> project association).
2
+ --
3
+ -- Adds project_id to the chats table plus a partial index. The ALTER is
4
+ -- NOT idempotent in SQLite (no IF NOT EXISTS for ADD COLUMN): run this file
5
+ -- exactly once. If the column already exists, re-running raises
6
+ -- "duplicate column name" and, because wrangler d1 execute runs the file as
7
+ -- one transaction, aborts and rolls back. Do not re-run; do not use the
8
+ -- cumulative schema.sql against an existing database.
9
+ --
10
+ -- To check whether it has already been applied:
11
+ -- wrangler d1 execute skyphusion-llm --remote --command "PRAGMA table_info(chats)"
12
+ -- and look for a project_id column.
13
+ --
14
+ -- Apply: wrangler d1 execute skyphusion-llm --remote --file=migrate-v0.20.2.sql
15
+
16
+ ALTER TABLE chats ADD COLUMN project_id INTEGER;
17
+
18
+ CREATE INDEX IF NOT EXISTS idx_chats_project
19
+ ON chats(project_id, created_at DESC) WHERE project_id IS NOT NULL;
@@ -0,0 +1,36 @@
1
+ -- v0.20.3 migration delta ONLY. Run this instead of the full schema.sql,
2
+ -- because schema.sql is cumulative and contains non-idempotent ALTER
3
+ -- statements from earlier releases (notably v0.20.2's chats.project_id) that
4
+ -- abort the whole transaction on re-run.
5
+ --
6
+ -- This file contains only the statements new in v0.20.3:
7
+ -- - project_messages table + indexes (idempotent via IF NOT EXISTS)
8
+ -- - four new columns on chunks (NOT idempotent; run once)
9
+ --
10
+ -- Apply: wrangler d1 execute skyphusion-llm --remote --file=migrate-v0.20.3.sql
11
+
12
+ CREATE TABLE IF NOT EXISTS project_messages (
13
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
14
+ project_id INTEGER NOT NULL,
15
+ document_id INTEGER NOT NULL,
16
+ user_email TEXT NOT NULL,
17
+ message_id TEXT NOT NULL,
18
+ channel TEXT NOT NULL,
19
+ author TEXT NOT NULL,
20
+ author_id TEXT,
21
+ is_bot INTEGER NOT NULL DEFAULT 0,
22
+ sent_at TEXT NOT NULL,
23
+ content TEXT NOT NULL,
24
+ FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
25
+ FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE
26
+ );
27
+
28
+ CREATE INDEX IF NOT EXISTS idx_project_messages_proj
29
+ ON project_messages(project_id, sent_at);
30
+ CREATE INDEX IF NOT EXISTS idx_project_messages_doc
31
+ ON project_messages(document_id);
32
+
33
+ ALTER TABLE chunks ADD COLUMN channel TEXT;
34
+ ALTER TABLE chunks ADD COLUMN authors TEXT;
35
+ ALTER TABLE chunks ADD COLUMN sent_at_start TEXT;
36
+ ALTER TABLE chunks ADD COLUMN sent_at_end TEXT;
@@ -0,0 +1,134 @@
1
+ -- D1 schema of record for skyphusion-llm (prism playground).
2
+ -- Squashed baseline (2026-07-07): replaces the manual migrate-v*.sql delta chain for CI.
3
+ -- Apply via: wrangler d1 migrations apply skyphusion-llm --remote
4
+ -- Idempotent on existing prod: CREATE TABLE/INDEX use IF NOT EXISTS.
5
+
6
+ CREATE TABLE IF NOT EXISTS chats (
7
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
8
+ user_email TEXT NOT NULL,
9
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
10
+ model TEXT NOT NULL,
11
+ model_type TEXT NOT NULL DEFAULT 'chat',
12
+ system_prompt TEXT,
13
+ user_input TEXT NOT NULL,
14
+ output TEXT NOT NULL DEFAULT '',
15
+ output_artifact TEXT,
16
+ attachments TEXT,
17
+ tokens_in INTEGER,
18
+ tokens_out INTEGER,
19
+ latency_ms INTEGER,
20
+ ai_gateway_log_id TEXT,
21
+ status TEXT NOT NULL DEFAULT 'done',
22
+ job_id TEXT,
23
+ job_provider TEXT,
24
+ job_error TEXT,
25
+ job_started_at TEXT,
26
+ retrieved_context TEXT,
27
+ conversation_id TEXT,
28
+ turn_index INTEGER,
29
+ project_id INTEGER
30
+ );
31
+
32
+ CREATE INDEX IF NOT EXISTS idx_chats_conversation
33
+ ON chats(conversation_id, turn_index);
34
+
35
+ CREATE INDEX IF NOT EXISTS idx_chats_user_created
36
+ ON chats(user_email, created_at DESC);
37
+
38
+ CREATE INDEX IF NOT EXISTS idx_chats_pending
39
+ ON chats(status, user_email) WHERE status = 'pending';
40
+
41
+ CREATE INDEX IF NOT EXISTS idx_chats_project
42
+ ON chats(project_id, created_at DESC) WHERE project_id IS NOT NULL;
43
+
44
+ CREATE TABLE IF NOT EXISTS documents (
45
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
46
+ user_email TEXT NOT NULL,
47
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
48
+ filename TEXT NOT NULL,
49
+ mime TEXT NOT NULL,
50
+ r2_key TEXT NOT NULL,
51
+ size_bytes INTEGER NOT NULL,
52
+ total_chars INTEGER NOT NULL DEFAULT 0,
53
+ chunk_count INTEGER NOT NULL DEFAULT 0
54
+ );
55
+
56
+ CREATE INDEX IF NOT EXISTS idx_documents_user_created
57
+ ON documents(user_email, created_at DESC);
58
+
59
+ CREATE TABLE IF NOT EXISTS chunks (
60
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
61
+ document_id INTEGER NOT NULL,
62
+ user_email TEXT NOT NULL,
63
+ chunk_index INTEGER NOT NULL,
64
+ text TEXT NOT NULL,
65
+ vector_id TEXT NOT NULL,
66
+ page INTEGER,
67
+ sheet TEXT,
68
+ channel TEXT,
69
+ authors TEXT,
70
+ sent_at_start TEXT,
71
+ sent_at_end TEXT,
72
+ FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE
73
+ );
74
+
75
+ CREATE INDEX IF NOT EXISTS idx_chunks_doc ON chunks(document_id);
76
+ CREATE INDEX IF NOT EXISTS idx_chunks_vector ON chunks(vector_id);
77
+ CREATE INDEX IF NOT EXISTS idx_chunks_user ON chunks(user_email);
78
+
79
+ CREATE TABLE IF NOT EXISTS projects (
80
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
81
+ user_email TEXT NOT NULL,
82
+ name TEXT NOT NULL,
83
+ slug TEXT NOT NULL,
84
+ description TEXT,
85
+ system_prompt TEXT,
86
+ created_at TEXT NOT NULL DEFAULT (datetime('now')),
87
+ updated_at TEXT NOT NULL DEFAULT (datetime('now'))
88
+ );
89
+
90
+ CREATE INDEX IF NOT EXISTS idx_projects_user
91
+ ON projects(user_email, created_at DESC);
92
+
93
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_projects_slug_user
94
+ ON projects(user_email, slug);
95
+
96
+ CREATE TABLE IF NOT EXISTS project_documents (
97
+ project_id INTEGER NOT NULL,
98
+ document_id INTEGER NOT NULL,
99
+ added_at TEXT NOT NULL DEFAULT (datetime('now')),
100
+ PRIMARY KEY (project_id, document_id),
101
+ FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
102
+ FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE
103
+ );
104
+
105
+ CREATE INDEX IF NOT EXISTS idx_project_documents_doc
106
+ ON project_documents(document_id);
107
+
108
+ CREATE TABLE IF NOT EXISTS project_messages (
109
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
110
+ project_id INTEGER NOT NULL,
111
+ document_id INTEGER NOT NULL,
112
+ user_email TEXT NOT NULL,
113
+ message_id TEXT NOT NULL,
114
+ channel TEXT NOT NULL,
115
+ author TEXT NOT NULL,
116
+ author_id TEXT,
117
+ is_bot INTEGER NOT NULL DEFAULT 0,
118
+ sent_at TEXT NOT NULL,
119
+ content TEXT NOT NULL,
120
+ FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
121
+ FOREIGN KEY (document_id) REFERENCES documents(id) ON DELETE CASCADE
122
+ );
123
+
124
+ CREATE INDEX IF NOT EXISTS idx_project_messages_proj
125
+ ON project_messages(project_id, sent_at);
126
+
127
+ CREATE INDEX IF NOT EXISTS idx_project_messages_doc
128
+ ON project_messages(document_id);
129
+
130
+ CREATE TABLE IF NOT EXISTS user_prefs (
131
+ user_email TEXT PRIMARY KEY,
132
+ prefs_json TEXT NOT NULL DEFAULT '{}',
133
+ updated_at TEXT NOT NULL DEFAULT (datetime('now'))
134
+ );
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "prism-app",
3
+ "version": "0.1.0",
4
+ "description": "Multimodal AI playground on Cloudflare Workers: 36 chat models, voice chat, image/video/music generation, RAG, and web search.",
5
+ "license": "AGPL-3.0-only",
6
+ "private": true,
7
+ "type": "module",
8
+ "scripts": {
9
+ "bootstrap": "node -e \"const fs=require('fs');if(fs.existsSync('wrangler.toml')){console.error('wrangler.toml already exists; not overwriting.');process.exit(1)}fs.copyFileSync('wrangler.example.toml','wrangler.toml');console.log('Created wrangler.toml from wrangler.example.toml. Fill in database_id (and worker name if you want a custom one) before deploying.')\"",
10
+ "dev": "wrangler dev",
11
+ "deploy": "wrangler deploy",
12
+ "typecheck": "tsc --noEmit",
13
+ "test": "vitest run",
14
+ "test:watch": "vitest",
15
+ "db:create": "wrangler d1 create skyphusion-llm",
16
+ "db:migrate:local": "wrangler d1 execute skyphusion-llm --local --file=schema.sql",
17
+ "db:migrate:remote": "wrangler d1 execute skyphusion-llm --remote --file=schema.sql"
18
+ },
19
+ "dependencies": {
20
+ "unpdf": "^1.6.0",
21
+ "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
22
+ },
23
+ "devDependencies": {
24
+ "@cloudflare/vitest-pool-workers": "^0.18.6",
25
+ "@cloudflare/workers-types": "^5.20260715.1",
26
+ "@types/node": "^26.1.1",
27
+ "@vitest/coverage-v8": "^4.1.10",
28
+ "typescript": "^7.0.2",
29
+ "vitest": "^4.1.8",
30
+ "wrangler": "^4.111.0"
31
+ }
32
+ }