connect.schema.ts 12 KB

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