connect.schema.ts404 lines · main
1import type { ConnectSchema, StepDefinition } from './Connect.types'
2
3/**
4 * Base install commands for each library.
5 */
6export const INSTALL_COMMANDS: Record<string, string> = {
7 brivenjs: 'npm install @supabase/supabase-js',
8 brivenpy: 'pip install briven',
9 brivenflutter: 'flutter pub add briven_flutter',
10 brivenswift:
11 'swift package add-dependency https://github.com/briven-community/briven-swift',
12 brivenkt: 'implementation("io.github.jan-tennert.briven:briven-kt:VERSION")',
13}
14
15/**
16 * Extra packages required by specific frameworks on top of the base library.
17 * Keyed by library, then by framework (or framework/variant for more specificity).
18 * The install step checks the most specific key first (e.g. "nextjs/app"),
19 * then falls back to the framework key (e.g. "nextjs").
20 */
21export const EXTRA_PACKAGES: Record<string, Record<string, string[]>> = {
22 brivenjs: {
23 'nextjs/app': ['@supabase/ssr'],
24 remix: ['@supabase/ssr'],
25 },
26}
27
28// ============================================================================
29// Step Definitions (reusable)
30// All content paths use template syntax: {{stateKey}} is replaced with state values
31// ============================================================================
32
33const frameworkInstallStep: StepDefinition = {
34 id: 'install',
35 title: 'Install package',
36 description: 'Run this command to install the required dependencies.',
37 content: 'steps/install',
38}
39
40const frameworkInstallPackagesStep: StepDefinition = {
41 id: 'install',
42 title: 'Install packages',
43 description: 'Run this command to install the required dependencies.',
44 content: 'steps/install',
45}
46
47const frameworkConfigureStep: StepDefinition = {
48 id: 'configure',
49 title: 'Add files',
50 description: 'Copy the following code into your project.',
51 content: '{{framework}}/{{frameworkVariant}}/{{library}}',
52}
53
54const frameworkNextJsFilesStep: StepDefinition = {
55 id: 'configure-nextjs',
56 title: 'Add files',
57 description:
58 'Add env variables, create Briven client helpers, and set up middleware to keep sessions refreshed.',
59 content: '{{framework}}/{{frameworkVariant}}/{{library}}',
60}
61
62const frameworkReactFilesStep: StepDefinition = {
63 id: 'configure-react',
64 title: 'Add files',
65 description: 'Add env variables, create a Briven client, and use it in your app to query data.',
66 content: '{{framework}}/{{frameworkVariant}}/{{library}}',
67}
68
69const frameworkShadcnStep: StepDefinition = {
70 id: 'shadcn-add',
71 title: 'Add Briven UI components',
72 description: 'Run this command to install the Briven shadcn components.',
73 content: 'steps/shadcn/command',
74}
75
76const frameworkShadcnEnvStep: StepDefinition = {
77 id: 'shadcn-env',
78 title: 'Set env variables',
79 description: 'Add the following values to your env file.',
80 content: 'steps/shadcn/env',
81}
82
83const frameworkShadcnExploreStep: StepDefinition = {
84 id: 'shadcn-explore',
85 title: 'Check out more UI components',
86 description: 'Add auth, realtime and storage functionality to your project',
87 content: 'steps/shadcn/explore',
88}
89
90const directConnectionStep: StepDefinition = {
91 id: 'connection',
92 title: 'Connection string',
93 description: 'Copy the connection details for your database.',
94 content: 'steps/direct-connection',
95}
96
97const directInstallStep: StepDefinition = {
98 id: 'direct-install',
99 title: 'Install dependencies',
100 description: 'Run this command to install the required dependencies.',
101 content: 'steps/direct-install',
102}
103
104const directFilesStep: StepDefinition = {
105 id: 'direct-files',
106 title: 'Add files',
107 description: 'Add the following files to your project.',
108 content: 'steps/direct-files',
109}
110
111const mcpConfigureStep: StepDefinition = {
112 id: 'configure-mcp',
113 title: 'Configure MCP',
114 description: 'Set up your MCP client.',
115 content: 'steps/mcp/cursor',
116}
117
118// Codex-specific MCP steps
119const codexAddServerStep: StepDefinition = {
120 id: 'codex-add-server',
121 title: 'Add the Briven MCP server to Codex',
122 description: 'Run this command to add the server.',
123 content: 'steps/mcp/codex/add-server',
124}
125
126const codexEnableRemoteStep: StepDefinition = {
127 id: 'codex-enable-remote',
128 title: 'Enable remote MCP client support',
129 description: 'Add this to your ~/.codex/config.toml file.',
130 content: 'steps/mcp/codex/enable-remote',
131}
132
133const codexAuthenticateStep: StepDefinition = {
134 id: 'codex-authenticate',
135 title: 'Authenticate',
136 description: 'Run the authentication command.',
137 content: 'steps/mcp/codex/authenticate',
138}
139
140const codexVerifyStep: StepDefinition = {
141 id: 'codex-verify',
142 title: 'Verify authentication',
143 description: 'Run /mcp inside Codex to verify.',
144 content: 'steps/mcp/codex/verify',
145}
146
147const claudeAddServerStep: StepDefinition = {
148 id: 'claude-add-server',
149 title: 'Add MCP server',
150 description: 'Add the MCP server to your project config using the command line.',
151 content: 'steps/mcp/claude-code/add-server',
152}
153
154const claudeAuthenticateStep: StepDefinition = {
155 id: 'claude-authenticate',
156 title: 'Authenticate',
157 description:
158 'After configuring the MCP server, you need to authenticate. In a regular terminal (not the IDE extension) run:',
159 content: 'steps/mcp/claude-code/authenticate',
160}
161
162const ormInstallStep: StepDefinition = {
163 id: 'install',
164 title: 'Install ORM',
165 description: 'Add the ORM to your project.',
166 content: 'steps/orm-install',
167}
168
169const ormConfigureStep: StepDefinition = {
170 id: 'configure',
171 title: 'Configure ORM',
172 description: 'Set up your ORM configuration.',
173 content: '{{orm}}',
174}
175
176const skillsInstallStep: StepDefinition = {
177 id: 'install-skills',
178 title: 'Install Agent Skills (Optional)',
179 description:
180 'Agent Skills give AI coding tools ready-made instructions, scripts, and resources for working with Briven more accurately and efficiently.',
181 content: 'steps/skills-install',
182}
183
184// ============================================================================
185// Main Schema
186// ============================================================================
187
188export const connectSchema: ConnectSchema = {
189 // -------------------------------------------------------------------------
190 // Mode Definitions
191 // -------------------------------------------------------------------------
192 modes: [
193 {
194 id: 'framework',
195 label: 'Framework',
196 description: 'Use a client library',
197 fields: ['framework', 'frameworkVariant', 'library', 'frameworkUi'],
198 },
199 {
200 id: 'direct',
201 label: 'Direct',
202 description: 'Connection string',
203 fields: ['connectionSource', 'connectionMethod', 'useSharedPooler', 'connectionType'],
204 },
205 {
206 id: 'orm',
207 label: 'ORM',
208 description: 'Third-party library',
209 fields: ['orm'],
210 },
211 {
212 id: 'mcp',
213 label: 'MCP',
214 description: 'Connect your agent',
215 fields: ['mcpClient', 'mcpReadonly', 'mcpFeatures'],
216 },
217 ],
218
219 // -------------------------------------------------------------------------
220 // Field Definitions
221 // -------------------------------------------------------------------------
222 fields: {
223 // Framework fields
224 framework: {
225 id: 'framework',
226 type: 'select',
227 label: 'Framework',
228 options: { source: 'frameworks' },
229 defaultValue: 'nextjs',
230 },
231 frameworkVariant: {
232 id: 'frameworkVariant',
233 type: 'select',
234 label: 'Variant',
235 options: { source: 'frameworkVariants' },
236 defaultValue: 'app',
237 dependsOn: { framework: ['nextjs', 'react'] }, // Only show for frameworks with multiple variants
238 },
239 library: {
240 id: 'library',
241 type: 'select',
242 label: 'Library',
243 options: { source: 'libraries' },
244 defaultValue: 'brivenjs',
245 },
246 frameworkUi: {
247 id: 'frameworkUi',
248 type: 'switch',
249 label: 'Shadcn',
250 description: 'Install components via the Briven shadcn registry.',
251 defaultValue: false,
252 dependsOn: { framework: ['nextjs', 'react'] },
253 },
254
255 // Direct connection fields
256 connectionSource: {
257 id: 'connectionSource',
258 type: 'select',
259 label: 'Source',
260 options: { source: 'connectionSources' },
261 defaultValue: undefined,
262 },
263 connectionMethod: {
264 id: 'connectionMethod',
265 type: 'radio-list',
266 label: 'Connection Method',
267 options: { source: 'connectionMethods' },
268 defaultValue: 'direct',
269 },
270 useSharedPooler: {
271 id: 'useSharedPooler',
272 type: 'switch',
273 label: 'Use IPv4 connection (Shared Pooler)',
274 description: 'Recommended when your network does not support IPv6',
275 defaultValue: false,
276 dependsOn: { connectionMethod: ['transaction'] },
277 },
278 connectionType: {
279 id: 'connectionType',
280 type: 'select',
281 label: 'Type',
282 options: { source: 'connectionTypes' },
283 defaultValue: 'uri',
284 },
285
286 // ORM fields
287 orm: {
288 id: 'orm',
289 type: 'radio-list',
290 label: 'ORM',
291 options: { source: 'orms' },
292 defaultValue: 'prisma',
293 },
294
295 // MCP fields
296 mcpClient: {
297 id: 'mcpClient',
298 type: 'select',
299 label: 'Client',
300 description: 'Choose the MCP client you are using.',
301 options: { source: 'mcpClients' },
302 defaultValue: 'claude-code',
303 },
304 mcpReadonly: {
305 id: 'mcpReadonly',
306 type: 'switch',
307 label: 'Read-only',
308 description: 'Only allow read operations on your database',
309 defaultValue: false,
310 },
311 mcpFeatures: {
312 id: 'mcpFeatures',
313 type: 'multi-select',
314 label: 'Feature groups',
315 description:
316 'Only enable a subset of features. Helps keep the number of tools within MCP client limits.',
317 options: { source: 'mcpFeatures' },
318 },
319 },
320
321 // -------------------------------------------------------------------------
322 // Steps - Conditional based on mode and nested selections
323 // -------------------------------------------------------------------------
324 steps: {
325 // Keys are field IDs; each field maps state values to step trees.
326 mode: {
327 framework: {
328 framework: {
329 nextjs: {
330 frameworkVariant: {
331 app: {
332 frameworkUi: {
333 true: [
334 frameworkInstallPackagesStep,
335 frameworkShadcnStep,
336 frameworkShadcnEnvStep,
337 frameworkShadcnExploreStep,
338 skillsInstallStep,
339 ],
340 DEFAULT: [
341 frameworkInstallPackagesStep,
342 frameworkNextJsFilesStep,
343 skillsInstallStep,
344 ],
345 },
346 },
347 DEFAULT: {
348 frameworkUi: {
349 true: [
350 frameworkInstallStep,
351 frameworkShadcnStep,
352 frameworkShadcnEnvStep,
353 frameworkShadcnExploreStep,
354 skillsInstallStep,
355 ],
356 DEFAULT: [frameworkInstallStep, frameworkNextJsFilesStep, skillsInstallStep],
357 },
358 },
359 },
360 },
361 react: {
362 frameworkUi: {
363 true: [
364 frameworkInstallStep,
365 frameworkShadcnStep,
366 frameworkShadcnEnvStep,
367 frameworkShadcnExploreStep,
368 skillsInstallStep,
369 ],
370 DEFAULT: [frameworkInstallStep, frameworkReactFilesStep, skillsInstallStep],
371 },
372 },
373 remix: [frameworkInstallPackagesStep, frameworkConfigureStep, skillsInstallStep],
374 DEFAULT: [frameworkInstallStep, frameworkConfigureStep, skillsInstallStep],
375 },
376 },
377 direct: {
378 connectionType: {
379 nodejs: [directInstallStep, directFilesStep, skillsInstallStep],
380 golang: [directInstallStep, directFilesStep, skillsInstallStep],
381 dotnet: [directInstallStep, directFilesStep, skillsInstallStep],
382 python: [directInstallStep, directFilesStep, skillsInstallStep],
383 sqlalchemy: [directInstallStep, directFilesStep, skillsInstallStep],
384 DEFAULT: [directConnectionStep, skillsInstallStep],
385 },
386 },
387 orm: [ormInstallStep, ormConfigureStep, skillsInstallStep],
388 mcp: {
389 mcpClient: {
390 codex: [
391 codexAddServerStep,
392 codexEnableRemoteStep,
393 codexAuthenticateStep,
394 codexVerifyStep,
395 skillsInstallStep,
396 ],
397 'claude-code': [claudeAddServerStep, claudeAuthenticateStep, skillsInstallStep],
398 DEFAULT: [mcpConfigureStep, skillsInstallStep],
399 },
400 },
401 DEFAULT: [skillsInstallStep],
402 },
403 },
404}