create-efforge 0.0.0-stage → 0.2.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 +21 -0
- package/README.md +88 -2
- package/dist/addon.js +115 -0
- package/dist/bin.js +13 -0
- package/dist/cli.js +28 -0
- package/dist/commands/add.js +640 -0
- package/dist/commands/create.js +319 -0
- package/dist/commands/list.js +80 -0
- package/dist/diff.js +72 -0
- package/dist/exec.js +33 -0
- package/dist/generate.js +181 -0
- package/dist/manifest.js +14 -0
- package/dist/projectName.js +41 -0
- package/dist/prompts/flow.js +122 -0
- package/dist/prompts/navigable.js +193 -0
- package/dist/routeTree.js +7 -0
- package/dist/rules.js +27 -0
- package/dist/slots.js +116 -0
- package/dist/stack.js +68 -0
- package/dist/transforms/addAlchemyResource.js +71 -0
- package/dist/transforms/addArrayItem.js +31 -0
- package/dist/transforms/addAuthPlugin.js +77 -0
- package/dist/transforms/addDevVar.js +18 -0
- package/dist/transforms/addExport.js +46 -0
- package/dist/transforms/addImport.js +11 -0
- package/dist/transforms/addLayer.js +31 -0
- package/dist/transforms/addServerFnMiddleware.js +62 -0
- package/dist/transforms/addWorkflowSecret.js +43 -0
- package/dist/transforms/addWranglerBinding.js +61 -0
- package/dist/transforms/appendAgentsSection.js +26 -0
- package/dist/transforms/errors.js +7 -0
- package/dist/transforms/index.js +40 -0
- package/dist/transforms/setWranglerValue.js +40 -0
- package/dist/transforms/util.js +219 -0
- package/dist/tree.js +1 -0
- package/dist/versions.js +73 -0
- package/dist/write.js +28 -0
- package/package.json +63 -4
- package/templates/ai/effect-ai-byok/addon.json +619 -0
- package/templates/ai/effect-ai-byok/files/core/llm-crypto.test.ts +52 -0
- package/templates/ai/effect-ai-byok/files/core/llm-crypto.ts +76 -0
- package/templates/ai/effect-ai-byok/files/core/llm-store.ts +21 -0
- package/templates/ai/effect-ai-byok/files/core/llm.ts +32 -0
- package/templates/ai/effect-ai-byok/files/drizzle/d1/20261018161056_llm_credential/migration.sql +9 -0
- package/templates/ai/effect-ai-byok/files/drizzle/d1/20261018161056_llm_credential/snapshot.json +944 -0
- package/templates/ai/effect-ai-byok/files/drizzle/pg/20261018161056_llm_credential/migration.sql +10 -0
- package/templates/ai/effect-ai-byok/files/drizzle/pg/20261018161056_llm_credential/snapshot.json +1232 -0
- package/templates/ai/effect-ai-byok/files/routes/ai.tsx +193 -0
- package/templates/ai/effect-ai-byok/files/schema/d1.ts +16 -0
- package/templates/ai/effect-ai-byok/files/schema/pg.ts +14 -0
- package/templates/ai/effect-ai-byok/files/server/ai-settings.ts +129 -0
- package/templates/ai/effect-ai-byok/files/server/ai.ts +25 -0
- package/templates/ai/effect-ai-byok/files/server/llm-env.ts +48 -0
- package/templates/ai/effect-ai-byok/files/server/llm-orgs.ts +146 -0
- package/templates/ai/effect-ai-byok/files/server/llm-provider.ts +56 -0
- package/templates/ai/effect-ai-byok/files/server/llm-store-drizzle.ts +48 -0
- package/templates/ai/effect-ai-byok/files/server/llm-store-sql-d1.ts +41 -0
- package/templates/ai/effect-ai-byok/files/server/llm-store-sql-pg.ts +41 -0
- package/templates/ai/effect-ai-byok/files/sql/d1.sql +8 -0
- package/templates/ai/effect-ai-byok/files/sql/pg.sql +8 -0
- package/templates/auth/better-auth/addon.json +424 -0
- package/templates/auth/better-auth/files/core/Auth.ts +18 -0
- package/templates/auth/better-auth/files/drizzle/d1/20261018161054_auth/migration.sql +51 -0
- package/templates/auth/better-auth/files/drizzle/d1/20261018161054_auth/snapshot.json +522 -0
- package/templates/auth/better-auth/files/drizzle/pg/20261018161053_auth/migration.sql +51 -0
- package/templates/auth/better-auth/files/drizzle/pg/20261018161053_auth/snapshot.json +680 -0
- package/templates/auth/better-auth/files/lib/auth-client.ts +4 -0
- package/templates/auth/better-auth/files/routes/app.tsx +54 -0
- package/templates/auth/better-auth/files/schema/d1/auth-schema.ts +86 -0
- package/templates/auth/better-auth/files/schema/pg/auth-schema.ts +73 -0
- package/templates/auth/better-auth/files/server/auth-live.ts +47 -0
- package/templates/auth/better-auth/files/server/session.ts +14 -0
- package/templates/auth/better-auth/files/shared/components/auth-card.tsx +32 -0
- package/templates/auth/better-auth/files/shared/components/user-menu.tsx +44 -0
- package/templates/auth/better-auth/files/shared/drizzle/d1/drizzle.config.ts +7 -0
- package/templates/auth/better-auth/files/shared/drizzle/pg/drizzle.config.ts +10 -0
- package/templates/auth/better-auth/files/shared/lib/form.ts +5 -0
- package/templates/auth/better-auth/files/shared/lib/redirect.ts +6 -0
- package/templates/auth/better-auth/files/shared/routes/app/index.tsx +54 -0
- package/templates/auth/better-auth/files/shared/routes/sign-in.tsx +85 -0
- package/templates/auth/better-auth/files/shared/routes/sign-up.tsx +91 -0
- package/templates/auth/better-auth/files/shared/server/auth-route.ts +15 -0
- package/templates/auth/better-auth/files/shared/server/auth.ts +22 -0
- package/templates/auth/better-auth/files/shared/server/db/d1-drizzle.ts +25 -0
- package/templates/auth/better-auth/files/shared/server/db/d1-effect-sql.ts +17 -0
- package/templates/auth/better-auth/files/shared/server/db/pg-drizzle.ts +32 -0
- package/templates/auth/better-auth/files/shared/server/db/pg-effect-sql.ts +29 -0
- package/templates/auth/better-auth/files/shared/server/require-session.ts +20 -0
- package/templates/auth/better-auth/files/sql/d1/0002_auth.sql +13 -0
- package/templates/auth/better-auth/files/sql/pg/0002_auth.sql +13 -0
- package/templates/auth/better-auth-orgs/addon.json +463 -0
- package/templates/auth/better-auth-orgs/files/components/org-switcher.tsx +65 -0
- package/templates/auth/better-auth-orgs/files/core/Auth.ts +20 -0
- package/templates/auth/better-auth-orgs/files/drizzle/d1/20261018161055_auth/migration.sql +88 -0
- package/templates/auth/better-auth-orgs/files/drizzle/d1/20261018161055_auth/snapshot.json +862 -0
- package/templates/auth/better-auth-orgs/files/drizzle/pg/20261018161055_auth/migration.sql +88 -0
- package/templates/auth/better-auth-orgs/files/drizzle/pg/20261018161055_auth/snapshot.json +1127 -0
- package/templates/auth/better-auth-orgs/files/lib/auth-client.ts +5 -0
- package/templates/auth/better-auth-orgs/files/routes/accept-invite.$id.tsx +68 -0
- package/templates/auth/better-auth-orgs/files/routes/app/settings/index.tsx +27 -0
- package/templates/auth/better-auth-orgs/files/routes/app/settings/members.tsx +202 -0
- package/templates/auth/better-auth-orgs/files/routes/app/settings.tsx +30 -0
- package/templates/auth/better-auth-orgs/files/routes/app.tsx +58 -0
- package/templates/auth/better-auth-orgs/files/routes/onboarding.tsx +66 -0
- package/templates/auth/better-auth-orgs/files/schema/d1/auth-schema.ts +139 -0
- package/templates/auth/better-auth-orgs/files/schema/pg/auth-schema.ts +124 -0
- package/templates/auth/better-auth-orgs/files/server/auth-live.ts +52 -0
- package/templates/auth/better-auth-orgs/files/server/session.ts +44 -0
- package/templates/auth/better-auth-orgs/files/sql/d1/0002_auth.sql +27 -0
- package/templates/auth/better-auth-orgs/files/sql/pg/0002_auth.sql +27 -0
- package/templates/base/addon.json +216 -0
- package/templates/base/files/AGENTS.md +82 -0
- package/templates/base/files/CLAUDE.md +1 -0
- package/templates/base/files/README.md +32 -0
- package/templates/base/files/core/package.json +13 -0
- package/templates/base/files/core/src/index.ts +2 -0
- package/templates/base/files/core/test/core.test.ts +4 -0
- package/templates/base/files/core/tsconfig.json +6 -0
- package/templates/base/files/gitignore +11 -0
- package/templates/base/files/pnpm-workspace.yaml +11 -0
- package/templates/base/files/root/lint/effect-tests.js +45 -0
- package/templates/base/files/root/package.json +16 -0
- package/templates/base/files/root/tsconfig.base.json +19 -0
- package/templates/base/files/root/turbo.json +9 -0
- package/templates/base/files/root/vite.config.ts +86 -0
- package/templates/base/files/web/components.json +21 -0
- package/templates/base/files/web/package.json +17 -0
- package/templates/base/files/web/src/components/theme-provider.tsx +57 -0
- package/templates/base/files/web/src/components/theme-toggle.tsx +34 -0
- package/templates/base/files/web/src/components/ui/avatar.tsx +93 -0
- package/templates/base/files/web/src/components/ui/button.tsx +61 -0
- package/templates/base/files/web/src/components/ui/card.tsx +74 -0
- package/templates/base/files/web/src/components/ui/dialog.tsx +141 -0
- package/templates/base/files/web/src/components/ui/dropdown-menu.tsx +225 -0
- package/templates/base/files/web/src/components/ui/input.tsx +20 -0
- package/templates/base/files/web/src/components/ui/label.tsx +18 -0
- package/templates/base/files/web/src/components/ui/sonner.tsx +45 -0
- package/templates/base/files/web/src/components/widgets.tsx +4 -0
- package/templates/base/files/web/src/lib/utils.ts +6 -0
- package/templates/base/files/web/src/router.tsx +12 -0
- package/templates/base/files/web/src/routes/__root.tsx +42 -0
- package/templates/base/files/web/src/routes/app/index.tsx +27 -0
- package/templates/base/files/web/src/routes/app/settings.tsx +29 -0
- package/templates/base/files/web/src/routes/app.tsx +47 -0
- package/templates/base/files/web/src/routes/index.tsx +51 -0
- package/templates/base/files/web/src/server/greeting.ts +12 -0
- package/templates/base/files/web/src/server/layers.ts +10 -0
- package/templates/base/files/web/src/server/runtime.ts +5 -0
- package/templates/base/files/web/src/styles.css +81 -0
- package/templates/base/files/web/tsconfig.json +11 -0
- package/templates/base/files/web/vite.config.ts +9 -0
- package/templates/database/d1/addon.json +118 -0
- package/templates/database/d1/files/package.json +12 -0
- package/templates/database/d1/files/tsconfig.json +5 -0
- package/templates/database/postgres/addon.json +142 -0
- package/templates/database/postgres/files/docker-compose.yml +21 -0
- package/templates/database/postgres/files/package.json +12 -0
- package/templates/database/postgres/files/runtime.ts +12 -0
- package/templates/database/postgres/files/tsconfig.json +5 -0
- package/templates/extras/browser/addon.json +173 -0
- package/templates/extras/browser/files/BrowserContainer.ts +14 -0
- package/templates/extras/browser/files/app/Dockerfile +15 -0
- package/templates/extras/browser/files/app/dockerignore +1 -0
- package/templates/extras/browser/files/app/package-lock +605 -0
- package/templates/extras/browser/files/app/package.json +9 -0
- package/templates/extras/browser/files/app/src/server.ts +78 -0
- package/templates/extras/browser/files/app/src/url-policy.ts +115 -0
- package/templates/extras/browser/files/app/tsconfig.json +6 -0
- package/templates/extras/browser/files/browser.ts +34 -0
- package/templates/extras/browser/files/core-browser.ts +21 -0
- package/templates/extras/browser/files/run-browser.ts +25 -0
- package/templates/extras/email/addon.json +182 -0
- package/templates/extras/email/files/core-mailer.ts +28 -0
- package/templates/extras/email/files/invitation-email.ts +38 -0
- package/templates/extras/email/files/mailer.ts +58 -0
- package/templates/extras/realtime/addon.json +135 -0
- package/templates/extras/realtime/files/Room.ts +46 -0
- package/templates/extras/realtime/files/core-realtime.ts +19 -0
- package/templates/extras/realtime/files/realtime-demo.tsx +40 -0
- package/templates/extras/realtime/files/realtime-limits.test.ts +32 -0
- package/templates/extras/realtime/files/realtime-limits.ts +35 -0
- package/templates/extras/realtime/files/realtime-route.ts +39 -0
- package/templates/extras/realtime/files/realtime.ts +39 -0
- package/templates/extras/realtime/files/use-room.ts +67 -0
- package/templates/extras/storage/addon.json +132 -0
- package/templates/extras/storage/files/core-storage.ts +64 -0
- package/templates/extras/storage/files/storage-route.ts +50 -0
- package/templates/extras/storage/files/storage-security.test.ts +71 -0
- package/templates/extras/storage/files/storage-security.ts +92 -0
- package/templates/extras/storage/files/storage.ts +84 -0
- package/templates/extras/workflows/addon.json +95 -0
- package/templates/extras/workflows/files/Example.ts +42 -0
- package/templates/extras/workflows/files/core-jobs.ts +45 -0
- package/templates/extras/workflows/files/example-job.ts +36 -0
- package/templates/extras/workflows/files/jobs.ts +34 -0
- package/templates/infra/alchemy/addon.json +37 -0
- package/templates/infra/alchemy/files/README.md +27 -0
- package/templates/infra/alchemy/files/alchemy.run.ts +36 -0
- package/templates/infra/alchemy/files/github/deploy.yml +63 -0
- package/templates/infra/alchemy/files/tsconfig.json +5 -0
- package/templates/infra/alchemy/files/vite.config.ts +30 -0
- package/templates/orm/drizzle/addon.json +188 -0
- package/templates/orm/drizzle/files/d1/Database.ts +7 -0
- package/templates/orm/drizzle/files/d1/drizzle/20261018154417_init/migration.sql +10 -0
- package/templates/orm/drizzle/files/d1/drizzle/20261018154417_init/snapshot.json +60 -0
- package/templates/orm/drizzle/files/d1/drizzle.config.ts +7 -0
- package/templates/orm/drizzle/files/d1/layer.ts +13 -0
- package/templates/orm/drizzle/files/d1/migrate.ts +37 -0
- package/templates/orm/drizzle/files/d1/schema.ts +15 -0
- package/templates/orm/drizzle/files/pg/Database.ts +7 -0
- package/templates/orm/drizzle/files/pg/drizzle/20261018154416_init/migration.sql +10 -0
- package/templates/orm/drizzle/files/pg/drizzle/20261018154416_init/snapshot.json +75 -0
- package/templates/orm/drizzle/files/pg/drizzle.config.ts +10 -0
- package/templates/orm/drizzle/files/pg/layer.ts +16 -0
- package/templates/orm/drizzle/files/pg/migrate.ts +24 -0
- package/templates/orm/drizzle/files/pg/schema.ts +11 -0
- package/templates/orm/drizzle/files/shared/index.ts +2 -0
- package/templates/orm/drizzle/files/shared/notes.ts +15 -0
- package/templates/orm/drizzle/files/shared/page.tsx +50 -0
- package/templates/orm/effect-sql/addon.json +124 -0
- package/templates/orm/effect-sql/files/d1/layer.ts +13 -0
- package/templates/orm/effect-sql/files/d1/migrate.ts +20 -0
- package/templates/orm/effect-sql/files/d1/schema.ts +7 -0
- package/templates/orm/effect-sql/files/d1-sql/0001_init.sql +10 -0
- package/templates/orm/effect-sql/files/pg/layer.ts +16 -0
- package/templates/orm/effect-sql/files/pg/migrate.ts +66 -0
- package/templates/orm/effect-sql/files/pg/schema.ts +7 -0
- package/templates/orm/effect-sql/files/pg-sql/0001_init.sql +10 -0
- package/templates/orm/effect-sql/files/shared/Database.ts +7 -0
- package/templates/orm/effect-sql/files/shared/index.ts +2 -0
- package/templates/orm/effect-sql/files/shared/notes.ts +18 -0
- package/templates/orm/effect-sql/files/shared/page.tsx +50 -0
- package/templates/runtime/cloudflare/addon.json +52 -0
- package/templates/runtime/cloudflare/files/cloudflare.ts +10 -0
- package/templates/runtime/cloudflare/files/routes.ts +5 -0
- package/templates/runtime/cloudflare/files/server.ts +22 -0
- package/templates/runtime/cloudflare/files/tsconfig.json +12 -0
- package/templates/runtime/cloudflare/files/vite.config.ts +20 -0
- package/templates/runtime/cloudflare/files/wrangler.jsonc +8 -0
|
@@ -0,0 +1,619 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "ai/effect-ai-byok",
|
|
3
|
+
"title": "Effect AI (bring your own key)",
|
|
4
|
+
"description": "An Llm service on Effect AI with Anthropic, OpenAI, OpenRouter and Ollama providers; keys come from the environment, or are saved encrypted per organization when auth has organizations.",
|
|
5
|
+
"files": [
|
|
6
|
+
{
|
|
7
|
+
"path": "files/core/llm.ts",
|
|
8
|
+
"target": "packages/core/src/llm.ts"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"path": "files/server/llm-provider.ts",
|
|
12
|
+
"target": "apps/web/src/server/llm-provider.ts"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"path": "files/server/ai.ts",
|
|
16
|
+
"target": "apps/web/src/server/ai.ts"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"path": "files/server/llm-env.ts",
|
|
20
|
+
"target": "apps/web/src/server/llm.ts",
|
|
21
|
+
"when": {
|
|
22
|
+
"auth": [
|
|
23
|
+
"none",
|
|
24
|
+
"better-auth"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"path": "files/server/llm-orgs.ts",
|
|
30
|
+
"target": "apps/web/src/server/llm.ts",
|
|
31
|
+
"when": {
|
|
32
|
+
"auth": [
|
|
33
|
+
"better-auth-orgs"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"path": "files/core/llm-crypto.ts",
|
|
39
|
+
"target": "packages/core/src/llm-crypto.ts",
|
|
40
|
+
"when": {
|
|
41
|
+
"auth": [
|
|
42
|
+
"better-auth-orgs"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"path": "files/core/llm-crypto.test.ts",
|
|
48
|
+
"target": "packages/core/test/llm-crypto.test.ts",
|
|
49
|
+
"when": {
|
|
50
|
+
"auth": [
|
|
51
|
+
"better-auth-orgs"
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"path": "files/core/llm-store.ts",
|
|
57
|
+
"target": "packages/core/src/llm-store.ts",
|
|
58
|
+
"when": {
|
|
59
|
+
"auth": [
|
|
60
|
+
"better-auth-orgs"
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"path": "files/server/ai-settings.ts",
|
|
66
|
+
"target": "apps/web/src/server/ai-settings.ts",
|
|
67
|
+
"when": {
|
|
68
|
+
"auth": [
|
|
69
|
+
"better-auth-orgs"
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"path": "files/routes/ai.tsx",
|
|
75
|
+
"target": "apps/web/src/routes/app/settings/ai.tsx",
|
|
76
|
+
"when": {
|
|
77
|
+
"auth": [
|
|
78
|
+
"better-auth-orgs"
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"path": "files/server/llm-store-drizzle.ts",
|
|
84
|
+
"target": "apps/web/src/server/llm-store.ts",
|
|
85
|
+
"when": {
|
|
86
|
+
"auth": [
|
|
87
|
+
"better-auth-orgs"
|
|
88
|
+
],
|
|
89
|
+
"orm": [
|
|
90
|
+
"drizzle"
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"path": "files/server/llm-store-sql-pg.ts",
|
|
96
|
+
"target": "apps/web/src/server/llm-store.ts",
|
|
97
|
+
"when": {
|
|
98
|
+
"auth": [
|
|
99
|
+
"better-auth-orgs"
|
|
100
|
+
],
|
|
101
|
+
"orm": [
|
|
102
|
+
"effect-sql"
|
|
103
|
+
],
|
|
104
|
+
"database": [
|
|
105
|
+
"postgres"
|
|
106
|
+
]
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"path": "files/server/llm-store-sql-d1.ts",
|
|
111
|
+
"target": "apps/web/src/server/llm-store.ts",
|
|
112
|
+
"when": {
|
|
113
|
+
"auth": [
|
|
114
|
+
"better-auth-orgs"
|
|
115
|
+
],
|
|
116
|
+
"orm": [
|
|
117
|
+
"effect-sql"
|
|
118
|
+
],
|
|
119
|
+
"database": [
|
|
120
|
+
"d1"
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"path": "files/schema/pg.ts",
|
|
126
|
+
"target": "packages/db/src/ai-schema.ts",
|
|
127
|
+
"when": {
|
|
128
|
+
"auth": [
|
|
129
|
+
"better-auth-orgs"
|
|
130
|
+
],
|
|
131
|
+
"orm": [
|
|
132
|
+
"drizzle"
|
|
133
|
+
],
|
|
134
|
+
"database": [
|
|
135
|
+
"postgres"
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
"path": "files/schema/d1.ts",
|
|
141
|
+
"target": "packages/db/src/ai-schema.ts",
|
|
142
|
+
"when": {
|
|
143
|
+
"auth": [
|
|
144
|
+
"better-auth-orgs"
|
|
145
|
+
],
|
|
146
|
+
"orm": [
|
|
147
|
+
"drizzle"
|
|
148
|
+
],
|
|
149
|
+
"database": [
|
|
150
|
+
"d1"
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"path": "files/sql/pg.sql",
|
|
156
|
+
"target": "packages/db/migrations/0003_llm_credential.sql",
|
|
157
|
+
"when": {
|
|
158
|
+
"auth": [
|
|
159
|
+
"better-auth-orgs"
|
|
160
|
+
],
|
|
161
|
+
"orm": [
|
|
162
|
+
"effect-sql"
|
|
163
|
+
],
|
|
164
|
+
"database": [
|
|
165
|
+
"postgres"
|
|
166
|
+
]
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"path": "files/sql/d1.sql",
|
|
171
|
+
"target": "packages/db/migrations/0003_llm_credential.sql",
|
|
172
|
+
"when": {
|
|
173
|
+
"auth": [
|
|
174
|
+
"better-auth-orgs"
|
|
175
|
+
],
|
|
176
|
+
"orm": [
|
|
177
|
+
"effect-sql"
|
|
178
|
+
],
|
|
179
|
+
"database": [
|
|
180
|
+
"d1"
|
|
181
|
+
]
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"path": "files/drizzle/pg/20261018161056_llm_credential/migration.sql",
|
|
186
|
+
"target": "packages/db/drizzle/20261018161056_llm_credential/migration.sql",
|
|
187
|
+
"when": {
|
|
188
|
+
"auth": [
|
|
189
|
+
"better-auth-orgs"
|
|
190
|
+
],
|
|
191
|
+
"orm": [
|
|
192
|
+
"drizzle"
|
|
193
|
+
],
|
|
194
|
+
"database": [
|
|
195
|
+
"postgres"
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"path": "files/drizzle/pg/20261018161056_llm_credential/snapshot.json",
|
|
201
|
+
"target": "packages/db/drizzle/20261018161056_llm_credential/snapshot.json",
|
|
202
|
+
"when": {
|
|
203
|
+
"auth": [
|
|
204
|
+
"better-auth-orgs"
|
|
205
|
+
],
|
|
206
|
+
"orm": [
|
|
207
|
+
"drizzle"
|
|
208
|
+
],
|
|
209
|
+
"database": [
|
|
210
|
+
"postgres"
|
|
211
|
+
]
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
"path": "files/drizzle/d1/20261018161056_llm_credential/migration.sql",
|
|
216
|
+
"target": "packages/db/drizzle/20261018161056_llm_credential/migration.sql",
|
|
217
|
+
"when": {
|
|
218
|
+
"auth": [
|
|
219
|
+
"better-auth-orgs"
|
|
220
|
+
],
|
|
221
|
+
"orm": [
|
|
222
|
+
"drizzle"
|
|
223
|
+
],
|
|
224
|
+
"database": [
|
|
225
|
+
"d1"
|
|
226
|
+
]
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
"path": "files/drizzle/d1/20261018161056_llm_credential/snapshot.json",
|
|
231
|
+
"target": "packages/db/drizzle/20261018161056_llm_credential/snapshot.json",
|
|
232
|
+
"when": {
|
|
233
|
+
"auth": [
|
|
234
|
+
"better-auth-orgs"
|
|
235
|
+
],
|
|
236
|
+
"orm": [
|
|
237
|
+
"drizzle"
|
|
238
|
+
],
|
|
239
|
+
"database": [
|
|
240
|
+
"d1"
|
|
241
|
+
]
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
],
|
|
245
|
+
"dependencies": {
|
|
246
|
+
"apps/web": [
|
|
247
|
+
"@effect/ai-anthropic",
|
|
248
|
+
"@effect/ai-openai",
|
|
249
|
+
"@effect/ai-openrouter"
|
|
250
|
+
]
|
|
251
|
+
},
|
|
252
|
+
"devDependencies": {},
|
|
253
|
+
"envVars": [
|
|
254
|
+
{
|
|
255
|
+
"name": "LLM_ENCRYPTION_KEY",
|
|
256
|
+
"example": "openssl rand -base64 32",
|
|
257
|
+
"description": "AES-GCM key (32 random bytes, base64) that encrypts each organization's saved API key; the app refuses to start without a valid one",
|
|
258
|
+
"when": {
|
|
259
|
+
"auth": [
|
|
260
|
+
"better-auth-orgs"
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
"name": "LLM_PROVIDER",
|
|
266
|
+
"example": "anthropic",
|
|
267
|
+
"description": "anthropic | openai | openrouter | ollama",
|
|
268
|
+
"when": {
|
|
269
|
+
"auth": [
|
|
270
|
+
"none",
|
|
271
|
+
"better-auth"
|
|
272
|
+
]
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
"name": "LLM_MODEL",
|
|
277
|
+
"example": "claude-sonnet-5-5",
|
|
278
|
+
"description": "Model id for the provider",
|
|
279
|
+
"when": {
|
|
280
|
+
"auth": [
|
|
281
|
+
"none",
|
|
282
|
+
"better-auth"
|
|
283
|
+
]
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
"name": "LLM_API_KEY",
|
|
288
|
+
"example": "sk-...",
|
|
289
|
+
"description": "Provider API key (not needed for a local Ollama); a Worker secret in production",
|
|
290
|
+
"when": {
|
|
291
|
+
"auth": [
|
|
292
|
+
"none",
|
|
293
|
+
"better-auth"
|
|
294
|
+
]
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
{
|
|
298
|
+
"name": "LLM_BASE_URL",
|
|
299
|
+
"example": "",
|
|
300
|
+
"description": "Optional OpenAI-compatible endpoint (openai, ollama)",
|
|
301
|
+
"when": {
|
|
302
|
+
"auth": [
|
|
303
|
+
"none",
|
|
304
|
+
"better-auth"
|
|
305
|
+
]
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
],
|
|
309
|
+
"requires": [],
|
|
310
|
+
"conflicts": [],
|
|
311
|
+
"transforms": [
|
|
312
|
+
{
|
|
313
|
+
"name": "addExport",
|
|
314
|
+
"args": {
|
|
315
|
+
"file": "packages/core/src/index.ts",
|
|
316
|
+
"export": "*",
|
|
317
|
+
"from": "./llm"
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
"name": "addLayer",
|
|
322
|
+
"args": {
|
|
323
|
+
"file": "apps/web/src/server/layers.ts",
|
|
324
|
+
"import": "LlmLive",
|
|
325
|
+
"from": "./llm",
|
|
326
|
+
"layer": "LlmLive"
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
"name": "addServerFnMiddleware",
|
|
331
|
+
"args": {
|
|
332
|
+
"file": "apps/web/src/server/ai.ts",
|
|
333
|
+
"middleware": "requireSession",
|
|
334
|
+
"import": "requireSession",
|
|
335
|
+
"from": "./require-session"
|
|
336
|
+
},
|
|
337
|
+
"when": {
|
|
338
|
+
"auth": [
|
|
339
|
+
"better-auth",
|
|
340
|
+
"better-auth-orgs"
|
|
341
|
+
]
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
"name": "addExport",
|
|
346
|
+
"args": {
|
|
347
|
+
"file": "packages/db/src/index.ts",
|
|
348
|
+
"export": "*",
|
|
349
|
+
"from": "./ai-schema.ts"
|
|
350
|
+
},
|
|
351
|
+
"when": {
|
|
352
|
+
"auth": [
|
|
353
|
+
"better-auth-orgs"
|
|
354
|
+
],
|
|
355
|
+
"orm": [
|
|
356
|
+
"drizzle"
|
|
357
|
+
]
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
"name": "addArrayItem",
|
|
362
|
+
"args": {
|
|
363
|
+
"file": "apps/web/src/routes/app/settings.tsx",
|
|
364
|
+
"name": "tabs",
|
|
365
|
+
"item": "{ to: \"/app/settings/ai\", label: \"AI\" }"
|
|
366
|
+
},
|
|
367
|
+
"when": {
|
|
368
|
+
"auth": [
|
|
369
|
+
"better-auth-orgs"
|
|
370
|
+
]
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
"name": "addDevVar",
|
|
375
|
+
"args": {
|
|
376
|
+
"name": "LLM_ENCRYPTION_KEY",
|
|
377
|
+
"value": "ZGV2LW9ubHktbGxtLWtleS1yZXBsYWNlLW1lLTMyISE="
|
|
378
|
+
},
|
|
379
|
+
"when": {
|
|
380
|
+
"auth": [
|
|
381
|
+
"better-auth-orgs"
|
|
382
|
+
]
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
"name": "addDevVar",
|
|
387
|
+
"args": {
|
|
388
|
+
"name": "LLM_PROVIDER",
|
|
389
|
+
"value": "anthropic"
|
|
390
|
+
},
|
|
391
|
+
"when": {
|
|
392
|
+
"auth": [
|
|
393
|
+
"none",
|
|
394
|
+
"better-auth"
|
|
395
|
+
]
|
|
396
|
+
}
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
"name": "addDevVar",
|
|
400
|
+
"args": {
|
|
401
|
+
"name": "LLM_MODEL",
|
|
402
|
+
"value": "claude-sonnet-5-5"
|
|
403
|
+
},
|
|
404
|
+
"when": {
|
|
405
|
+
"auth": [
|
|
406
|
+
"none",
|
|
407
|
+
"better-auth"
|
|
408
|
+
]
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
"name": "addImport",
|
|
413
|
+
"args": {
|
|
414
|
+
"file": "infra/alchemy.run.ts",
|
|
415
|
+
"import": "* as Config",
|
|
416
|
+
"from": "effect/Config"
|
|
417
|
+
},
|
|
418
|
+
"when": {
|
|
419
|
+
"infra": [
|
|
420
|
+
"alchemy"
|
|
421
|
+
]
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
"name": "addAlchemyResource",
|
|
426
|
+
"args": {
|
|
427
|
+
"name": "llmEncryptionKey",
|
|
428
|
+
"code": "const llmEncryptionKey = yield* Config.Redacted(\"LLM_ENCRYPTION_KEY\")",
|
|
429
|
+
"binding": "LLM_ENCRYPTION_KEY"
|
|
430
|
+
},
|
|
431
|
+
"when": {
|
|
432
|
+
"infra": [
|
|
433
|
+
"alchemy"
|
|
434
|
+
],
|
|
435
|
+
"auth": [
|
|
436
|
+
"better-auth-orgs"
|
|
437
|
+
]
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
"name": "addWorkflowSecret",
|
|
442
|
+
"args": {
|
|
443
|
+
"name": "LLM_ENCRYPTION_KEY"
|
|
444
|
+
},
|
|
445
|
+
"when": {
|
|
446
|
+
"infra": [
|
|
447
|
+
"alchemy"
|
|
448
|
+
],
|
|
449
|
+
"auth": [
|
|
450
|
+
"better-auth-orgs"
|
|
451
|
+
]
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
"name": "addAlchemyResource",
|
|
456
|
+
"args": {
|
|
457
|
+
"name": "llmProvider",
|
|
458
|
+
"code": "const llmProvider = yield* Config.String(\"LLM_PROVIDER\")",
|
|
459
|
+
"binding": "LLM_PROVIDER"
|
|
460
|
+
},
|
|
461
|
+
"when": {
|
|
462
|
+
"infra": [
|
|
463
|
+
"alchemy"
|
|
464
|
+
],
|
|
465
|
+
"auth": [
|
|
466
|
+
"none",
|
|
467
|
+
"better-auth"
|
|
468
|
+
]
|
|
469
|
+
}
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
"name": "addAlchemyResource",
|
|
473
|
+
"args": {
|
|
474
|
+
"name": "llmModel",
|
|
475
|
+
"code": "const llmModel = yield* Config.String(\"LLM_MODEL\")",
|
|
476
|
+
"binding": "LLM_MODEL"
|
|
477
|
+
},
|
|
478
|
+
"when": {
|
|
479
|
+
"infra": [
|
|
480
|
+
"alchemy"
|
|
481
|
+
],
|
|
482
|
+
"auth": [
|
|
483
|
+
"none",
|
|
484
|
+
"better-auth"
|
|
485
|
+
]
|
|
486
|
+
}
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
"name": "addAlchemyResource",
|
|
490
|
+
"args": {
|
|
491
|
+
"name": "llmApiKey",
|
|
492
|
+
"code": "const llmApiKey = yield* Config.Redacted(\"LLM_API_KEY\")",
|
|
493
|
+
"binding": "LLM_API_KEY"
|
|
494
|
+
},
|
|
495
|
+
"when": {
|
|
496
|
+
"infra": [
|
|
497
|
+
"alchemy"
|
|
498
|
+
],
|
|
499
|
+
"auth": [
|
|
500
|
+
"none",
|
|
501
|
+
"better-auth"
|
|
502
|
+
]
|
|
503
|
+
}
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
"name": "addAlchemyResource",
|
|
507
|
+
"args": {
|
|
508
|
+
"name": "llmBaseUrl",
|
|
509
|
+
"code": "// empty uses the provider's default endpoint\nconst llmBaseUrl = yield* Config.String(\"LLM_BASE_URL\").pipe(Config.withDefault(\"\"))",
|
|
510
|
+
"binding": "LLM_BASE_URL"
|
|
511
|
+
},
|
|
512
|
+
"when": {
|
|
513
|
+
"infra": [
|
|
514
|
+
"alchemy"
|
|
515
|
+
],
|
|
516
|
+
"auth": [
|
|
517
|
+
"none",
|
|
518
|
+
"better-auth"
|
|
519
|
+
]
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
{
|
|
523
|
+
"name": "addWorkflowSecret",
|
|
524
|
+
"args": {
|
|
525
|
+
"name": "LLM_PROVIDER"
|
|
526
|
+
},
|
|
527
|
+
"when": {
|
|
528
|
+
"infra": [
|
|
529
|
+
"alchemy"
|
|
530
|
+
],
|
|
531
|
+
"auth": [
|
|
532
|
+
"none",
|
|
533
|
+
"better-auth"
|
|
534
|
+
]
|
|
535
|
+
}
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
"name": "addWorkflowSecret",
|
|
539
|
+
"args": {
|
|
540
|
+
"name": "LLM_MODEL"
|
|
541
|
+
},
|
|
542
|
+
"when": {
|
|
543
|
+
"infra": [
|
|
544
|
+
"alchemy"
|
|
545
|
+
],
|
|
546
|
+
"auth": [
|
|
547
|
+
"none",
|
|
548
|
+
"better-auth"
|
|
549
|
+
]
|
|
550
|
+
}
|
|
551
|
+
},
|
|
552
|
+
{
|
|
553
|
+
"name": "addWorkflowSecret",
|
|
554
|
+
"args": {
|
|
555
|
+
"name": "LLM_API_KEY"
|
|
556
|
+
},
|
|
557
|
+
"when": {
|
|
558
|
+
"infra": [
|
|
559
|
+
"alchemy"
|
|
560
|
+
],
|
|
561
|
+
"auth": [
|
|
562
|
+
"none",
|
|
563
|
+
"better-auth"
|
|
564
|
+
]
|
|
565
|
+
}
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
"name": "addWorkflowSecret",
|
|
569
|
+
"args": {
|
|
570
|
+
"name": "LLM_BASE_URL"
|
|
571
|
+
},
|
|
572
|
+
"when": {
|
|
573
|
+
"infra": [
|
|
574
|
+
"alchemy"
|
|
575
|
+
],
|
|
576
|
+
"auth": [
|
|
577
|
+
"none",
|
|
578
|
+
"better-auth"
|
|
579
|
+
]
|
|
580
|
+
}
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
"name": "appendAgentsSection",
|
|
584
|
+
"args": {
|
|
585
|
+
"id": "ai",
|
|
586
|
+
"content": "## AI (Effect AI, bring your own key)\n\n- Use the `Llm` service from `@repo/core` (`generateText(prompt)`); do not call a provider SDK from app code. `apps/web/src/server/llm-provider.ts` holds `makeLlmLayer({ provider, apiKey, model, baseUrl })`, which builds the Effect `LanguageModel` (`effect/ai`) for `anthropic`, `openai`, `openrouter` or `ollama` (OpenAI-compatible, set a base URL). `@effect/ai` 0.37 is Effect 3: do not add it.\n- `apps/web/src/server/ai.ts` is a demo server function (`generateText`); it is NOT gated because this project has no auth: anyone who can reach the app can call it and spend the configured API key. Add auth (`efforge add auth/better-auth`) or remove the demo before deploying. Gate any server function you add that spends model tokens the same way.\n- Never log, return or store the API key in the clear."
|
|
587
|
+
},
|
|
588
|
+
"when": {
|
|
589
|
+
"auth": [
|
|
590
|
+
"none"
|
|
591
|
+
]
|
|
592
|
+
}
|
|
593
|
+
},
|
|
594
|
+
{
|
|
595
|
+
"name": "appendAgentsSection",
|
|
596
|
+
"args": {
|
|
597
|
+
"id": "ai",
|
|
598
|
+
"content": "## AI (Effect AI, bring your own key)\n\n- Use the `Llm` service from `@repo/core` (`generateText(prompt)`); do not call a provider SDK from app code. `apps/web/src/server/llm-provider.ts` holds `makeLlmLayer({ provider, apiKey, model, baseUrl })`, which builds the Effect `LanguageModel` (`effect/ai`) for `anthropic`, `openai`, `openrouter` or `ollama` (OpenAI-compatible, set a base URL). `@effect/ai` 0.37 is Effect 3: do not add it.\n- `apps/web/src/server/ai.ts` is a demo server function (`generateText`); it is gated by `requireSession`. Gate any server function you add that spends model tokens the same way.\n- Never log, return or store the API key in the clear."
|
|
599
|
+
},
|
|
600
|
+
"when": {
|
|
601
|
+
"auth": [
|
|
602
|
+
"better-auth"
|
|
603
|
+
]
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
"name": "appendAgentsSection",
|
|
608
|
+
"args": {
|
|
609
|
+
"id": "ai",
|
|
610
|
+
"content": "## AI (Effect AI, bring your own key)\n\n- Use the `Llm` service from `@repo/core` (`generateText(prompt)`); do not call a provider SDK from app code. `apps/web/src/server/llm-provider.ts` holds `makeLlmLayer({ provider, apiKey, model, baseUrl })`, which builds the Effect `LanguageModel` (`effect/ai`) for `anthropic`, `openai`, `openrouter` or `ollama` (OpenAI-compatible, set a base URL). `@effect/ai` 0.37 is Effect 3: do not add it.\n- Each organization saves its own key at `/app/settings/ai`, stored in the `llm_credential` table (`packages/db`), encrypted with AES-GCM (WebCrypto) using `LLM_ENCRYPTION_KEY` (32 random bytes, base64: `openssl rand -base64 32`; the app refuses to start without a valid one). Rotating that key makes saved keys unreadable, so organizations must enter theirs again.\n- The key never goes back to the browser (only its last four characters, to owners and admins). Only owners and admins can set, clear or test it; keep that check on the server.\n- `apps/web/src/server/ai.ts` is a demo server function (`generateText`) behind `requireSession`. Gate any server function you add that spends model tokens the same way.\n- Never log, return or store the API key in the clear."
|
|
611
|
+
},
|
|
612
|
+
"when": {
|
|
613
|
+
"auth": [
|
|
614
|
+
"better-auth-orgs"
|
|
615
|
+
]
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
]
|
|
619
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, it } from "@effect/vitest"
|
|
2
|
+
import { Effect } from "effect"
|
|
3
|
+
import { decryptSecret, encryptSecret, loadEncryptionKey } from "../src/llm-crypto"
|
|
4
|
+
|
|
5
|
+
const keyText = btoa(String.fromCharCode(...new Uint8Array(32).fill(7)))
|
|
6
|
+
|
|
7
|
+
describe("llm-crypto", () => {
|
|
8
|
+
it.effect("round-trips a secret and never stores it in the clear", () =>
|
|
9
|
+
Effect.gen(function* () {
|
|
10
|
+
const key = yield* loadEncryptionKey(keyText)
|
|
11
|
+
const sealed = yield* encryptSecret(key, "sk-secret-1234", "org_1")
|
|
12
|
+
expect(sealed).not.toContain("sk-secret")
|
|
13
|
+
expect(sealed.startsWith("v1.")).toBe(true)
|
|
14
|
+
expect(yield* decryptSecret(key, sealed, "org_1")).toBe("sk-secret-1234")
|
|
15
|
+
}),
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
it.effect("uses a fresh IV each time", () =>
|
|
19
|
+
Effect.gen(function* () {
|
|
20
|
+
const key = yield* loadEncryptionKey(keyText)
|
|
21
|
+
const [a, b] = yield* Effect.all(
|
|
22
|
+
[encryptSecret(key, "same", "org_1"), encryptSecret(key, "same", "org_1")],
|
|
23
|
+
{ concurrency: "unbounded" },
|
|
24
|
+
)
|
|
25
|
+
expect(a).not.toBe(b)
|
|
26
|
+
}),
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
it.effect("refuses a ciphertext moved to another organization or tampered with", () =>
|
|
30
|
+
Effect.gen(function* () {
|
|
31
|
+
const key = yield* loadEncryptionKey(keyText)
|
|
32
|
+
const sealed = yield* encryptSecret(key, "sk-secret", "org_1")
|
|
33
|
+
expect(yield* Effect.flip(decryptSecret(key, sealed, "org_2"))).toMatchObject({
|
|
34
|
+
_tag: "LlmError",
|
|
35
|
+
})
|
|
36
|
+
const parts = sealed.split(".")
|
|
37
|
+
const tampered = `${parts[0]}.${parts[1]}.${btoa("x".repeat(24))}`
|
|
38
|
+
expect(yield* Effect.flip(decryptSecret(key, tampered, "org_1"))).toMatchObject({
|
|
39
|
+
_tag: "LlmError",
|
|
40
|
+
})
|
|
41
|
+
}),
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
it.effect("rejects a missing, malformed or wrong-sized key at load time", () =>
|
|
45
|
+
Effect.gen(function* () {
|
|
46
|
+
const errors = yield* Effect.forEach([undefined, "", "not base64!", btoa("short")], (bad) =>
|
|
47
|
+
Effect.flip(loadEncryptionKey(bad)),
|
|
48
|
+
)
|
|
49
|
+
for (const error of errors) expect(error).toMatchObject({ _tag: "LlmConfigError" })
|
|
50
|
+
}),
|
|
51
|
+
)
|
|
52
|
+
})
|