create-efforge 0.0.0-stage → 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 (237) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +140 -2
  3. package/dist/addon.js +115 -0
  4. package/dist/bin.js +6 -0
  5. package/dist/cli.js +9 -0
  6. package/dist/commands/add.js +440 -0
  7. package/dist/commands/create.js +186 -0
  8. package/dist/diff.js +72 -0
  9. package/dist/exec.js +20 -0
  10. package/dist/generate.js +181 -0
  11. package/dist/manifest.js +14 -0
  12. package/dist/projectName.js +41 -0
  13. package/dist/prompts/flow.js +111 -0
  14. package/dist/prompts/navigable.js +97 -0
  15. package/dist/routeTree.js +7 -0
  16. package/dist/rules.js +24 -0
  17. package/dist/slots.js +96 -0
  18. package/dist/stack.js +68 -0
  19. package/dist/transforms/addAlchemyResource.js +71 -0
  20. package/dist/transforms/addArrayItem.js +31 -0
  21. package/dist/transforms/addAuthPlugin.js +77 -0
  22. package/dist/transforms/addDevVar.js +18 -0
  23. package/dist/transforms/addExport.js +46 -0
  24. package/dist/transforms/addImport.js +11 -0
  25. package/dist/transforms/addLayer.js +31 -0
  26. package/dist/transforms/addServerFnMiddleware.js +62 -0
  27. package/dist/transforms/addWorkflowSecret.js +43 -0
  28. package/dist/transforms/addWranglerBinding.js +61 -0
  29. package/dist/transforms/appendAgentsSection.js +26 -0
  30. package/dist/transforms/errors.js +7 -0
  31. package/dist/transforms/index.js +40 -0
  32. package/dist/transforms/setWranglerValue.js +40 -0
  33. package/dist/transforms/util.js +219 -0
  34. package/dist/tree.js +1 -0
  35. package/dist/versions.js +73 -0
  36. package/dist/write.js +26 -0
  37. package/package.json +63 -4
  38. package/templates/ai/effect-ai-byok/addon.json +619 -0
  39. package/templates/ai/effect-ai-byok/files/core/llm-crypto.test.ts +47 -0
  40. package/templates/ai/effect-ai-byok/files/core/llm-crypto.ts +76 -0
  41. package/templates/ai/effect-ai-byok/files/core/llm-store.ts +21 -0
  42. package/templates/ai/effect-ai-byok/files/core/llm.ts +32 -0
  43. package/templates/ai/effect-ai-byok/files/drizzle/d1/20261018161056_llm_credential/migration.sql +9 -0
  44. package/templates/ai/effect-ai-byok/files/drizzle/d1/20261018161056_llm_credential/snapshot.json +944 -0
  45. package/templates/ai/effect-ai-byok/files/drizzle/pg/20261018161056_llm_credential/migration.sql +10 -0
  46. package/templates/ai/effect-ai-byok/files/drizzle/pg/20261018161056_llm_credential/snapshot.json +1232 -0
  47. package/templates/ai/effect-ai-byok/files/routes/ai.tsx +193 -0
  48. package/templates/ai/effect-ai-byok/files/schema/d1.ts +16 -0
  49. package/templates/ai/effect-ai-byok/files/schema/pg.ts +14 -0
  50. package/templates/ai/effect-ai-byok/files/server/ai-settings.ts +129 -0
  51. package/templates/ai/effect-ai-byok/files/server/ai.ts +25 -0
  52. package/templates/ai/effect-ai-byok/files/server/llm-env.ts +48 -0
  53. package/templates/ai/effect-ai-byok/files/server/llm-orgs.ts +146 -0
  54. package/templates/ai/effect-ai-byok/files/server/llm-provider.ts +56 -0
  55. package/templates/ai/effect-ai-byok/files/server/llm-store-drizzle.ts +48 -0
  56. package/templates/ai/effect-ai-byok/files/server/llm-store-sql-d1.ts +41 -0
  57. package/templates/ai/effect-ai-byok/files/server/llm-store-sql-pg.ts +41 -0
  58. package/templates/ai/effect-ai-byok/files/sql/d1.sql +8 -0
  59. package/templates/ai/effect-ai-byok/files/sql/pg.sql +8 -0
  60. package/templates/auth/better-auth/addon.json +424 -0
  61. package/templates/auth/better-auth/files/core/Auth.ts +18 -0
  62. package/templates/auth/better-auth/files/drizzle/d1/20261018161054_auth/migration.sql +51 -0
  63. package/templates/auth/better-auth/files/drizzle/d1/20261018161054_auth/snapshot.json +522 -0
  64. package/templates/auth/better-auth/files/drizzle/pg/20261018161053_auth/migration.sql +51 -0
  65. package/templates/auth/better-auth/files/drizzle/pg/20261018161053_auth/snapshot.json +680 -0
  66. package/templates/auth/better-auth/files/lib/auth-client.ts +4 -0
  67. package/templates/auth/better-auth/files/routes/app.tsx +54 -0
  68. package/templates/auth/better-auth/files/schema/d1/auth-schema.ts +86 -0
  69. package/templates/auth/better-auth/files/schema/pg/auth-schema.ts +73 -0
  70. package/templates/auth/better-auth/files/server/auth-live.ts +47 -0
  71. package/templates/auth/better-auth/files/server/session.ts +14 -0
  72. package/templates/auth/better-auth/files/shared/components/auth-card.tsx +32 -0
  73. package/templates/auth/better-auth/files/shared/components/user-menu.tsx +44 -0
  74. package/templates/auth/better-auth/files/shared/drizzle/d1/drizzle.config.ts +7 -0
  75. package/templates/auth/better-auth/files/shared/drizzle/pg/drizzle.config.ts +10 -0
  76. package/templates/auth/better-auth/files/shared/lib/form.ts +5 -0
  77. package/templates/auth/better-auth/files/shared/lib/redirect.ts +6 -0
  78. package/templates/auth/better-auth/files/shared/routes/app/index.tsx +54 -0
  79. package/templates/auth/better-auth/files/shared/routes/sign-in.tsx +85 -0
  80. package/templates/auth/better-auth/files/shared/routes/sign-up.tsx +91 -0
  81. package/templates/auth/better-auth/files/shared/server/auth-route.ts +15 -0
  82. package/templates/auth/better-auth/files/shared/server/auth.ts +22 -0
  83. package/templates/auth/better-auth/files/shared/server/db/d1-drizzle.ts +25 -0
  84. package/templates/auth/better-auth/files/shared/server/db/d1-effect-sql.ts +17 -0
  85. package/templates/auth/better-auth/files/shared/server/db/pg-drizzle.ts +32 -0
  86. package/templates/auth/better-auth/files/shared/server/db/pg-effect-sql.ts +29 -0
  87. package/templates/auth/better-auth/files/shared/server/require-session.ts +20 -0
  88. package/templates/auth/better-auth/files/sql/d1/0002_auth.sql +13 -0
  89. package/templates/auth/better-auth/files/sql/pg/0002_auth.sql +13 -0
  90. package/templates/auth/better-auth-orgs/addon.json +463 -0
  91. package/templates/auth/better-auth-orgs/files/components/org-switcher.tsx +65 -0
  92. package/templates/auth/better-auth-orgs/files/core/Auth.ts +20 -0
  93. package/templates/auth/better-auth-orgs/files/drizzle/d1/20261018161055_auth/migration.sql +88 -0
  94. package/templates/auth/better-auth-orgs/files/drizzle/d1/20261018161055_auth/snapshot.json +862 -0
  95. package/templates/auth/better-auth-orgs/files/drizzle/pg/20261018161055_auth/migration.sql +88 -0
  96. package/templates/auth/better-auth-orgs/files/drizzle/pg/20261018161055_auth/snapshot.json +1127 -0
  97. package/templates/auth/better-auth-orgs/files/lib/auth-client.ts +5 -0
  98. package/templates/auth/better-auth-orgs/files/routes/accept-invite.$id.tsx +68 -0
  99. package/templates/auth/better-auth-orgs/files/routes/app/settings/index.tsx +27 -0
  100. package/templates/auth/better-auth-orgs/files/routes/app/settings/members.tsx +198 -0
  101. package/templates/auth/better-auth-orgs/files/routes/app/settings.tsx +30 -0
  102. package/templates/auth/better-auth-orgs/files/routes/app.tsx +58 -0
  103. package/templates/auth/better-auth-orgs/files/routes/onboarding.tsx +66 -0
  104. package/templates/auth/better-auth-orgs/files/schema/d1/auth-schema.ts +139 -0
  105. package/templates/auth/better-auth-orgs/files/schema/pg/auth-schema.ts +124 -0
  106. package/templates/auth/better-auth-orgs/files/server/auth-live.ts +52 -0
  107. package/templates/auth/better-auth-orgs/files/server/session.ts +44 -0
  108. package/templates/auth/better-auth-orgs/files/sql/d1/0002_auth.sql +27 -0
  109. package/templates/auth/better-auth-orgs/files/sql/pg/0002_auth.sql +27 -0
  110. package/templates/base/addon.json +212 -0
  111. package/templates/base/files/AGENTS.md +70 -0
  112. package/templates/base/files/CLAUDE.md +1 -0
  113. package/templates/base/files/README.md +28 -0
  114. package/templates/base/files/core/package.json +13 -0
  115. package/templates/base/files/core/src/index.ts +2 -0
  116. package/templates/base/files/core/test/core.test.ts +4 -0
  117. package/templates/base/files/core/tsconfig.json +6 -0
  118. package/templates/base/files/gitignore +11 -0
  119. package/templates/base/files/pnpm-workspace.yaml +11 -0
  120. package/templates/base/files/root/package.json +16 -0
  121. package/templates/base/files/root/tsconfig.base.json +19 -0
  122. package/templates/base/files/root/turbo.json +9 -0
  123. package/templates/base/files/root/vite.config.ts +61 -0
  124. package/templates/base/files/web/components.json +21 -0
  125. package/templates/base/files/web/package.json +17 -0
  126. package/templates/base/files/web/src/components/theme-provider.tsx +57 -0
  127. package/templates/base/files/web/src/components/theme-toggle.tsx +34 -0
  128. package/templates/base/files/web/src/components/ui/avatar.tsx +93 -0
  129. package/templates/base/files/web/src/components/ui/button.tsx +61 -0
  130. package/templates/base/files/web/src/components/ui/card.tsx +74 -0
  131. package/templates/base/files/web/src/components/ui/dialog.tsx +141 -0
  132. package/templates/base/files/web/src/components/ui/dropdown-menu.tsx +225 -0
  133. package/templates/base/files/web/src/components/ui/input.tsx +20 -0
  134. package/templates/base/files/web/src/components/ui/label.tsx +18 -0
  135. package/templates/base/files/web/src/components/ui/sonner.tsx +45 -0
  136. package/templates/base/files/web/src/components/widgets.tsx +4 -0
  137. package/templates/base/files/web/src/lib/utils.ts +6 -0
  138. package/templates/base/files/web/src/router.tsx +12 -0
  139. package/templates/base/files/web/src/routes/__root.tsx +42 -0
  140. package/templates/base/files/web/src/routes/app/index.tsx +27 -0
  141. package/templates/base/files/web/src/routes/app/settings.tsx +29 -0
  142. package/templates/base/files/web/src/routes/app.tsx +47 -0
  143. package/templates/base/files/web/src/routes/index.tsx +51 -0
  144. package/templates/base/files/web/src/server/greeting.ts +12 -0
  145. package/templates/base/files/web/src/server/layers.ts +10 -0
  146. package/templates/base/files/web/src/server/runtime.ts +5 -0
  147. package/templates/base/files/web/src/styles.css +81 -0
  148. package/templates/base/files/web/tsconfig.json +11 -0
  149. package/templates/base/files/web/vite.config.ts +9 -0
  150. package/templates/database/d1/addon.json +118 -0
  151. package/templates/database/d1/files/package.json +12 -0
  152. package/templates/database/d1/files/tsconfig.json +5 -0
  153. package/templates/database/postgres/addon.json +142 -0
  154. package/templates/database/postgres/files/docker-compose.yml +21 -0
  155. package/templates/database/postgres/files/package.json +12 -0
  156. package/templates/database/postgres/files/runtime.ts +12 -0
  157. package/templates/database/postgres/files/tsconfig.json +5 -0
  158. package/templates/extras/browser/addon.json +173 -0
  159. package/templates/extras/browser/files/BrowserContainer.ts +14 -0
  160. package/templates/extras/browser/files/app/Dockerfile +15 -0
  161. package/templates/extras/browser/files/app/dockerignore +1 -0
  162. package/templates/extras/browser/files/app/package-lock +605 -0
  163. package/templates/extras/browser/files/app/package.json +9 -0
  164. package/templates/extras/browser/files/app/src/server.ts +78 -0
  165. package/templates/extras/browser/files/app/src/url-policy.ts +115 -0
  166. package/templates/extras/browser/files/app/tsconfig.json +6 -0
  167. package/templates/extras/browser/files/browser.ts +34 -0
  168. package/templates/extras/browser/files/core-browser.ts +21 -0
  169. package/templates/extras/browser/files/run-browser.ts +25 -0
  170. package/templates/extras/email/addon.json +182 -0
  171. package/templates/extras/email/files/core-mailer.ts +28 -0
  172. package/templates/extras/email/files/invitation-email.ts +38 -0
  173. package/templates/extras/email/files/mailer.ts +58 -0
  174. package/templates/extras/realtime/addon.json +135 -0
  175. package/templates/extras/realtime/files/Room.ts +46 -0
  176. package/templates/extras/realtime/files/core-realtime.ts +19 -0
  177. package/templates/extras/realtime/files/realtime-demo.tsx +40 -0
  178. package/templates/extras/realtime/files/realtime-limits.test.ts +32 -0
  179. package/templates/extras/realtime/files/realtime-limits.ts +35 -0
  180. package/templates/extras/realtime/files/realtime-route.ts +39 -0
  181. package/templates/extras/realtime/files/realtime.ts +39 -0
  182. package/templates/extras/realtime/files/use-room.ts +67 -0
  183. package/templates/extras/storage/addon.json +132 -0
  184. package/templates/extras/storage/files/core-storage.ts +64 -0
  185. package/templates/extras/storage/files/storage-route.ts +50 -0
  186. package/templates/extras/storage/files/storage-security.test.ts +71 -0
  187. package/templates/extras/storage/files/storage-security.ts +92 -0
  188. package/templates/extras/storage/files/storage.ts +84 -0
  189. package/templates/extras/workflows/addon.json +95 -0
  190. package/templates/extras/workflows/files/Example.ts +42 -0
  191. package/templates/extras/workflows/files/core-jobs.ts +45 -0
  192. package/templates/extras/workflows/files/example-job.ts +36 -0
  193. package/templates/extras/workflows/files/jobs.ts +34 -0
  194. package/templates/infra/alchemy/addon.json +37 -0
  195. package/templates/infra/alchemy/files/README.md +27 -0
  196. package/templates/infra/alchemy/files/alchemy.run.ts +36 -0
  197. package/templates/infra/alchemy/files/github/deploy.yml +63 -0
  198. package/templates/infra/alchemy/files/tsconfig.json +5 -0
  199. package/templates/infra/alchemy/files/vite.config.ts +30 -0
  200. package/templates/orm/drizzle/addon.json +188 -0
  201. package/templates/orm/drizzle/files/d1/Database.ts +7 -0
  202. package/templates/orm/drizzle/files/d1/drizzle/20261018154417_init/migration.sql +10 -0
  203. package/templates/orm/drizzle/files/d1/drizzle/20261018154417_init/snapshot.json +60 -0
  204. package/templates/orm/drizzle/files/d1/drizzle.config.ts +7 -0
  205. package/templates/orm/drizzle/files/d1/layer.ts +13 -0
  206. package/templates/orm/drizzle/files/d1/migrate.ts +37 -0
  207. package/templates/orm/drizzle/files/d1/schema.ts +15 -0
  208. package/templates/orm/drizzle/files/pg/Database.ts +7 -0
  209. package/templates/orm/drizzle/files/pg/drizzle/20261018154416_init/migration.sql +10 -0
  210. package/templates/orm/drizzle/files/pg/drizzle/20261018154416_init/snapshot.json +75 -0
  211. package/templates/orm/drizzle/files/pg/drizzle.config.ts +10 -0
  212. package/templates/orm/drizzle/files/pg/layer.ts +16 -0
  213. package/templates/orm/drizzle/files/pg/migrate.ts +24 -0
  214. package/templates/orm/drizzle/files/pg/schema.ts +11 -0
  215. package/templates/orm/drizzle/files/shared/index.ts +2 -0
  216. package/templates/orm/drizzle/files/shared/notes.ts +15 -0
  217. package/templates/orm/drizzle/files/shared/page.tsx +50 -0
  218. package/templates/orm/effect-sql/addon.json +124 -0
  219. package/templates/orm/effect-sql/files/d1/layer.ts +13 -0
  220. package/templates/orm/effect-sql/files/d1/migrate.ts +20 -0
  221. package/templates/orm/effect-sql/files/d1/schema.ts +7 -0
  222. package/templates/orm/effect-sql/files/d1-sql/0001_init.sql +10 -0
  223. package/templates/orm/effect-sql/files/pg/layer.ts +16 -0
  224. package/templates/orm/effect-sql/files/pg/migrate.ts +66 -0
  225. package/templates/orm/effect-sql/files/pg/schema.ts +7 -0
  226. package/templates/orm/effect-sql/files/pg-sql/0001_init.sql +10 -0
  227. package/templates/orm/effect-sql/files/shared/Database.ts +7 -0
  228. package/templates/orm/effect-sql/files/shared/index.ts +2 -0
  229. package/templates/orm/effect-sql/files/shared/notes.ts +18 -0
  230. package/templates/orm/effect-sql/files/shared/page.tsx +50 -0
  231. package/templates/runtime/cloudflare/addon.json +52 -0
  232. package/templates/runtime/cloudflare/files/cloudflare.ts +10 -0
  233. package/templates/runtime/cloudflare/files/routes.ts +5 -0
  234. package/templates/runtime/cloudflare/files/server.ts +22 -0
  235. package/templates/runtime/cloudflare/files/tsconfig.json +12 -0
  236. package/templates/runtime/cloudflare/files/vite.config.ts +20 -0
  237. 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,47 @@
1
+ import { Effect } from "effect"
2
+ import { describe, expect, it } from "vitest"
3
+ import { decryptSecret, encryptSecret, loadEncryptionKey } from "../src/llm-crypto"
4
+
5
+ const keyText = btoa(String.fromCharCode(...new Uint8Array(32).fill(7)))
6
+ const run = <A, E>(effect: Effect.Effect<A, E>) => Effect.runPromise(effect)
7
+
8
+ describe("llm-crypto", () => {
9
+ it("round-trips a secret and never stores it in the clear", async () => {
10
+ const key = await run(loadEncryptionKey(keyText))
11
+ const sealed = await run(encryptSecret(key, "sk-secret-1234", "org_1"))
12
+ expect(sealed).not.toContain("sk-secret")
13
+ expect(sealed.startsWith("v1.")).toBe(true)
14
+ expect(await run(decryptSecret(key, sealed, "org_1"))).toBe("sk-secret-1234")
15
+ })
16
+
17
+ it("uses a fresh IV each time", async () => {
18
+ const key = await run(loadEncryptionKey(keyText))
19
+ const [a, b] = await Promise.all([
20
+ run(encryptSecret(key, "same", "org_1")),
21
+ run(encryptSecret(key, "same", "org_1")),
22
+ ])
23
+ expect(a).not.toBe(b)
24
+ })
25
+
26
+ it("refuses a ciphertext moved to another organization or tampered with", async () => {
27
+ const key = await run(loadEncryptionKey(keyText))
28
+ const sealed = await run(encryptSecret(key, "sk-secret", "org_1"))
29
+ expect(await run(Effect.flip(decryptSecret(key, sealed, "org_2")))).toMatchObject({
30
+ _tag: "LlmError",
31
+ })
32
+ const parts = sealed.split(".")
33
+ const tampered = `${parts[0]}.${parts[1]}.${btoa("x".repeat(24))}`
34
+ expect(await run(Effect.flip(decryptSecret(key, tampered, "org_1")))).toMatchObject({
35
+ _tag: "LlmError",
36
+ })
37
+ })
38
+
39
+ it("rejects a missing, malformed or wrong-sized key at load time", async () => {
40
+ const errors = await Promise.all(
41
+ [undefined, "", "not base64!", btoa("short")].map((bad) =>
42
+ run(Effect.flip(loadEncryptionKey(bad))),
43
+ ),
44
+ )
45
+ for (const error of errors) expect(error).toMatchObject({ _tag: "LlmConfigError" })
46
+ })
47
+ })