create-nextblock 0.14.0 → 0.14.2

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 (242) hide show
  1. package/docker-template/.dockerignore +23 -23
  2. package/docker-template/.env.docker.example +69 -69
  3. package/docker-template/docker/db/init/99-jwt.sql +6 -6
  4. package/docker-template/docker/db/init/99-roles.sql +25 -25
  5. package/docker-template/docker/kong/kong.yml +112 -112
  6. package/docker-template/scripts/docker-setup.mjs +310 -310
  7. package/libs/db/tsconfig.lib.json +3 -3
  8. package/libs/editor/tsconfig.lib.json +3 -3
  9. package/libs/ui/tsconfig.lib.json +3 -3
  10. package/libs/utils/tsconfig.json +3 -3
  11. package/package.json +1 -1
  12. package/project.json +19 -19
  13. package/templates/nextblock-template/.browserslistrc +11 -11
  14. package/templates/nextblock-template/.dockerignore +23 -23
  15. package/templates/nextblock-template/README.md +34 -34
  16. package/templates/nextblock-template/app/(auth-pages)/layout.tsx +9 -9
  17. package/templates/nextblock-template/app/(auth-pages)/post-sign-in/page.tsx +27 -27
  18. package/templates/nextblock-template/app/(auth-pages)/sign-up/page.tsx +46 -46
  19. package/templates/nextblock-template/app/(auth-pages)/two-factor/page.tsx +51 -51
  20. package/templates/nextblock-template/app/ToasterProvider.tsx +17 -17
  21. package/templates/nextblock-template/app/[slug]/pageClientActions.ts +7 -7
  22. package/templates/nextblock-template/app/actions/consent.ts +57 -57
  23. package/templates/nextblock-template/app/actions/postActions.ts +146 -146
  24. package/templates/nextblock-template/app/actions/twoFactorEmail.ts +22 -22
  25. package/templates/nextblock-template/app/api/ai/cortex/build-widget/route.ts +153 -153
  26. package/templates/nextblock-template/app/api/ai/generate-blocks/route.ts +96 -96
  27. package/templates/nextblock-template/app/api/brand/email-logo/route.ts +48 -48
  28. package/templates/nextblock-template/app/api/cms/check-updates/route.ts +44 -44
  29. package/templates/nextblock-template/app/api/cms/full-backup/export/route.ts +33 -33
  30. package/templates/nextblock-template/app/api/cms/full-backup/restore/route.ts +63 -63
  31. package/templates/nextblock-template/app/api/cron/reset-sandbox/route.ts +3490 -3490
  32. package/templates/nextblock-template/app/api/cron/reset-sandbox/sandboxResetSql.ts +5749 -5749
  33. package/templates/nextblock-template/app/api/cron/sync-currencies/route.ts +39 -39
  34. package/templates/nextblock-template/app/api/custom-blocks/db-relations/route.ts +92 -92
  35. package/templates/nextblock-template/app/api/custom-blocks/editor-definitions/route.ts +43 -43
  36. package/templates/nextblock-template/app/api/media/library/route.ts +69 -69
  37. package/templates/nextblock-template/app/api/media/r2-presigned/route.ts +53 -53
  38. package/templates/nextblock-template/app/api/media/record/route.ts +160 -160
  39. package/templates/nextblock-template/app/api/search/route.ts +43 -43
  40. package/templates/nextblock-template/app/article/[slug]/PostClientContent.tsx +441 -441
  41. package/templates/nextblock-template/app/auth/callback/route.ts +31 -31
  42. package/templates/nextblock-template/app/cart/page.tsx +7 -7
  43. package/templates/nextblock-template/app/cms/blocks/components/CustomBlockEditorPreview.tsx +160 -160
  44. package/templates/nextblock-template/app/cms/blocks/components/MediaLibraryModal.tsx +149 -149
  45. package/templates/nextblock-template/app/cms/blocks/editors/DynamicCustomBlockEditor.tsx +167 -167
  46. package/templates/nextblock-template/app/cms/blocks/editors/ImageBlockEditor.tsx +4 -2
  47. package/templates/nextblock-template/app/cms/blocks/editors/TextBlockEditor.tsx +90 -90
  48. package/templates/nextblock-template/app/cms/components/ConnectGitHubButton.tsx +122 -122
  49. package/templates/nextblock-template/app/cms/components/CortexAiPageContext.tsx +58 -58
  50. package/templates/nextblock-template/app/cms/components/FeedbackModal.tsx +36 -36
  51. package/templates/nextblock-template/app/cms/components/SystemAlertsBanner.tsx +112 -112
  52. package/templates/nextblock-template/app/cms/components/TwoFactorReminderBanner.tsx +45 -45
  53. package/templates/nextblock-template/app/cms/components/github-connect-actions.ts +102 -102
  54. package/templates/nextblock-template/app/cms/components/system-alerts-actions.ts +31 -31
  55. package/templates/nextblock-template/app/cms/custom-blocks/[id]/edit/page.tsx +66 -66
  56. package/templates/nextblock-template/app/cms/custom-blocks/actions.ts +519 -519
  57. package/templates/nextblock-template/app/cms/custom-blocks/components/BlocksLibraryTransferControls.tsx +256 -256
  58. package/templates/nextblock-template/app/cms/custom-blocks/components/DBRelationSelect.tsx +384 -384
  59. package/templates/nextblock-template/app/cms/custom-blocks/components/ImageR2Picker.tsx +221 -221
  60. package/templates/nextblock-template/app/cms/custom-blocks/new/page.tsx +12 -12
  61. package/templates/nextblock-template/app/cms/custom-blocks/page.tsx +438 -438
  62. package/templates/nextblock-template/app/cms/dashboard/actions.ts +228 -228
  63. package/templates/nextblock-template/app/cms/dashboard/components/DashboardOnboarding.tsx +130 -130
  64. package/templates/nextblock-template/app/cms/import-export/actions.ts +226 -226
  65. package/templates/nextblock-template/app/cms/layout.tsx +73 -73
  66. package/templates/nextblock-template/app/cms/media/components/FolderNavigator.tsx +273 -273
  67. package/templates/nextblock-template/app/cms/media/components/FolderTree.tsx +122 -122
  68. package/templates/nextblock-template/app/cms/media/components/MediaEditForm.tsx +26 -26
  69. package/templates/nextblock-template/app/cms/media/components/MediaGridClient.tsx +69 -69
  70. package/templates/nextblock-template/app/cms/navigation/components/NavigationMenuDnd.tsx +3 -3
  71. package/templates/nextblock-template/app/cms/products/attributes/page.tsx +12 -12
  72. package/templates/nextblock-template/app/cms/products/categories/page.tsx +12 -12
  73. package/templates/nextblock-template/app/cms/products/inventory/page.tsx +13 -13
  74. package/templates/nextblock-template/app/cms/products/new/page.tsx +135 -135
  75. package/templates/nextblock-template/app/cms/products/productFormData.ts +133 -133
  76. package/templates/nextblock-template/app/cms/products/settings/page.tsx +5 -5
  77. package/templates/nextblock-template/app/cms/promotions/PromotionsWorkspace.tsx +456 -456
  78. package/templates/nextblock-template/app/cms/promotions/actions.ts +115 -115
  79. package/templates/nextblock-template/app/cms/promotions/page.tsx +31 -31
  80. package/templates/nextblock-template/app/cms/revisions/service.ts +19 -19
  81. package/templates/nextblock-template/app/cms/revisions/utils.ts +132 -132
  82. package/templates/nextblock-template/app/cms/settings/backup-restore/BackupRestoreWorkspace.tsx +1004 -1004
  83. package/templates/nextblock-template/app/cms/settings/backup-restore/page.tsx +29 -29
  84. package/templates/nextblock-template/app/cms/settings/bot-protection/page.tsx +24 -24
  85. package/templates/nextblock-template/app/cms/settings/cortex-ai/SandboxCortexAiSettingsClient.tsx +688 -688
  86. package/templates/nextblock-template/app/cms/settings/currencies/actions.ts +331 -331
  87. package/templates/nextblock-template/app/cms/settings/currencies/page.tsx +494 -494
  88. package/templates/nextblock-template/app/cms/settings/email/page.tsx +28 -28
  89. package/templates/nextblock-template/app/cms/settings/extra-translations/ExtraTranslationsWorkspace.tsx +767 -767
  90. package/templates/nextblock-template/app/cms/settings/extra-translations/page.tsx +93 -93
  91. package/templates/nextblock-template/app/cms/settings/google-analytics/page.tsx +26 -26
  92. package/templates/nextblock-template/app/cms/settings/logos/[id]/edit/page.tsx +7 -7
  93. package/templates/nextblock-template/app/cms/settings/logos/components/BrandingSettingsForm.tsx +339 -339
  94. package/templates/nextblock-template/app/cms/settings/logos/components/DeleteLogoButton.tsx +21 -21
  95. package/templates/nextblock-template/app/cms/settings/logos/components/LogoForm.tsx +23 -21
  96. package/templates/nextblock-template/app/cms/settings/logos/components/SetActiveLogoButton.tsx +42 -42
  97. package/templates/nextblock-template/app/cms/settings/logos/components/SiteSeoSettingsForm.tsx +133 -133
  98. package/templates/nextblock-template/app/cms/settings/logos/new/page.tsx +8 -8
  99. package/templates/nextblock-template/app/cms/settings/packages/package-card.tsx +122 -122
  100. package/templates/nextblock-template/app/cms/settings/privacy/page.tsx +27 -27
  101. package/templates/nextblock-template/app/cms/settings/registration/page.tsx +27 -27
  102. package/templates/nextblock-template/app/cms/settings/security/components/SecurityPanel.tsx +9 -7
  103. package/templates/nextblock-template/app/cms/settings/security/page.tsx +33 -33
  104. package/templates/nextblock-template/app/cms/settings/taxes/page.tsx +21 -21
  105. package/templates/nextblock-template/app/cms/shipping/page.tsx +20 -20
  106. package/templates/nextblock-template/app/cms/users/components/DeleteUserButton.tsx +12 -12
  107. package/templates/nextblock-template/app/lib/site-settings.ts +105 -105
  108. package/templates/nextblock-template/app/profile/ProfilePageHeader.tsx +16 -16
  109. package/templates/nextblock-template/app/profile/ProfilePageMissingState.tsx +9 -9
  110. package/templates/nextblock-template/app/profile/account-links.ts +22 -22
  111. package/templates/nextblock-template/app/profile/orders/CustomerOrdersPageClient.tsx +124 -124
  112. package/templates/nextblock-template/app/profile/orders/page.tsx +19 -19
  113. package/templates/nextblock-template/app/profile/password/PasswordSettingsPageClient.tsx +128 -128
  114. package/templates/nextblock-template/app/profile/password/actions.ts +59 -59
  115. package/templates/nextblock-template/app/profile/password/page.tsx +27 -27
  116. package/templates/nextblock-template/app/setup/SetupWizard.tsx +678 -678
  117. package/templates/nextblock-template/app/setup/layout.tsx +13 -13
  118. package/templates/nextblock-template/app/setup/page.tsx +111 -111
  119. package/templates/nextblock-template/app/sitemap.ts +130 -130
  120. package/templates/nextblock-template/components/CartDrawerLoader.tsx +7 -7
  121. package/templates/nextblock-template/components/DeferredCartDrawer.tsx +23 -23
  122. package/templates/nextblock-template/components/DeferredGoogleAnalytics.tsx +70 -70
  123. package/templates/nextblock-template/components/DeferredGoogleTagManager.tsx +70 -70
  124. package/templates/nextblock-template/components/DeferredSpeedInsights.tsx +69 -69
  125. package/templates/nextblock-template/components/FeatureImageHero.tsx +47 -47
  126. package/templates/nextblock-template/components/FooterNavigation.tsx +32 -32
  127. package/templates/nextblock-template/components/HtmlScriptExecutor.tsx +47 -47
  128. package/templates/nextblock-template/components/LanguageSwitcher.tsx +2 -2
  129. package/templates/nextblock-template/components/PublicEnvBootstrap.tsx +30 -30
  130. package/templates/nextblock-template/components/ResponsiveNav.tsx +14 -14
  131. package/templates/nextblock-template/components/auth/AuthBotProtection.tsx +182 -182
  132. package/templates/nextblock-template/components/blocks/PostCardSkeleton.tsx +12 -12
  133. package/templates/nextblock-template/components/blocks/PostsGridBlock.tsx +12 -12
  134. package/templates/nextblock-template/components/blocks/ecommerceRendererLoaders.ts +23 -23
  135. package/templates/nextblock-template/components/blocks/renderers/FormBlockRenderer.tsx +249 -249
  136. package/templates/nextblock-template/components/blocks/types.ts +7 -7
  137. package/templates/nextblock-template/components/env-var-warning.tsx +3 -3
  138. package/templates/nextblock-template/components/form-message.tsx +32 -32
  139. package/templates/nextblock-template/components/media/YouTubeFacade.tsx +105 -105
  140. package/templates/nextblock-template/components/media/youtube-embed-replace.tsx +32 -32
  141. package/templates/nextblock-template/components/privacy/ConsentBanner.tsx +170 -170
  142. package/templates/nextblock-template/components/privacy/ConsentGatedAnalytics.tsx +70 -70
  143. package/templates/nextblock-template/components/renderers/CachedDynamicLayoutEngine.tsx +28 -28
  144. package/templates/nextblock-template/components/renderers/DynamicLayoutEngine.test.tsx +166 -166
  145. package/templates/nextblock-template/components/renderers/DynamicLayoutEngine.tsx +471 -471
  146. package/templates/nextblock-template/components/submit-button.tsx +23 -23
  147. package/templates/nextblock-template/components/theme-switcher.tsx +8 -8
  148. package/templates/nextblock-template/components/visual-editing/DeferredVisualEditing.tsx +21 -21
  149. package/templates/nextblock-template/context/AuthContext.tsx +23 -23
  150. package/templates/nextblock-template/context/language-rest-client.ts +32 -32
  151. package/templates/nextblock-template/docker/db/init/99-jwt.sql +6 -6
  152. package/templates/nextblock-template/docker/db/init/99-roles.sql +25 -25
  153. package/templates/nextblock-template/docker/kong/kong.yml +112 -112
  154. package/templates/nextblock-template/docs/01-PROJECT-OVERVIEW.md +94 -94
  155. package/templates/nextblock-template/docs/02-ECOMMERCE-CAPABILITIES.md +364 -364
  156. package/templates/nextblock-template/docs/03-CMS-AND-EDITOR.md +202 -202
  157. package/templates/nextblock-template/docs/04-DATABASE-AND-AUTH.md +246 -246
  158. package/templates/nextblock-template/docs/06-CLI-AND-SCAFFOLDING.md +176 -176
  159. package/templates/nextblock-template/docs/07-BLOCK-SDK-AND-EXTENSIBILITY.md +146 -146
  160. package/templates/nextblock-template/docs/10-CUSTOM-BLOCKS.md +222 -222
  161. package/templates/nextblock-template/docs/11-SELF-HOSTED-DOCKER.md +173 -173
  162. package/templates/nextblock-template/docs/12-VERCEL-DEPLOYMENT.md +170 -170
  163. package/templates/nextblock-template/docs/13-STAYING-UP-TO-DATE.md +151 -151
  164. package/templates/nextblock-template/docs/README.md +39 -39
  165. package/templates/nextblock-template/hooks/use-hotkeys.ts +21 -21
  166. package/templates/nextblock-template/hooks/useGlobalSearch.ts +101 -101
  167. package/templates/nextblock-template/index.d.ts +7 -7
  168. package/templates/nextblock-template/lib/app-secrets.ts +39 -39
  169. package/templates/nextblock-template/lib/auth/cookies.ts +47 -47
  170. package/templates/nextblock-template/lib/auth/crypto.ts +45 -45
  171. package/templates/nextblock-template/lib/auth/trustedDevices.ts +92 -92
  172. package/templates/nextblock-template/lib/auth-redirects.ts +46 -46
  173. package/templates/nextblock-template/lib/blocks/README.md +13 -13
  174. package/templates/nextblock-template/lib/botProtection/verify.ts +134 -134
  175. package/templates/nextblock-template/lib/cms-transfer/server.ts +2243 -2243
  176. package/templates/nextblock-template/lib/cms-transfer/types.ts +145 -145
  177. package/templates/nextblock-template/lib/custom-block-definitions.ts +87 -87
  178. package/templates/nextblock-template/lib/custom-block-r2-upload-shared.ts +178 -178
  179. package/templates/nextblock-template/lib/custom-block-r2-upload.test.ts +140 -140
  180. package/templates/nextblock-template/lib/custom-block-r2-upload.ts +88 -88
  181. package/templates/nextblock-template/lib/custom-block-relations.test.ts +227 -227
  182. package/templates/nextblock-template/lib/custom-block-relations.ts +279 -279
  183. package/templates/nextblock-template/lib/custom-block-safelist.ts +14 -14
  184. package/templates/nextblock-template/lib/editor/dynamic-extension-core.test.ts +172 -172
  185. package/templates/nextblock-template/lib/editor/dynamic-extension-core.ts +213 -213
  186. package/templates/nextblock-template/lib/editor/dynamic-extension-loader.ts +22 -22
  187. package/templates/nextblock-template/lib/editor/dynamic-extensions.tsx +193 -193
  188. package/templates/nextblock-template/lib/email/branding-format.test.ts +133 -133
  189. package/templates/nextblock-template/lib/email/branding-format.ts +123 -123
  190. package/templates/nextblock-template/lib/email/branding.ts +76 -76
  191. package/templates/nextblock-template/lib/full-backup/manifest.test.ts +121 -121
  192. package/templates/nextblock-template/lib/full-backup/manifest.ts +206 -206
  193. package/templates/nextblock-template/lib/full-backup/server.ts +743 -743
  194. package/templates/nextblock-template/lib/logos/active-logo.ts +53 -53
  195. package/templates/nextblock-template/lib/media/resolveMediaUrl.ts +54 -54
  196. package/templates/nextblock-template/lib/media/youtube.ts +99 -99
  197. package/templates/nextblock-template/lib/onboarding/actions.ts +31 -31
  198. package/templates/nextblock-template/lib/onboarding/status.ts +222 -222
  199. package/templates/nextblock-template/lib/posts/readTime.ts +60 -60
  200. package/templates/nextblock-template/lib/privacy/consent-client.ts +57 -57
  201. package/templates/nextblock-template/lib/privacy/contact-emails.ts +64 -64
  202. package/templates/nextblock-template/lib/privacy/settings.ts +115 -115
  203. package/templates/nextblock-template/lib/privacy/types.ts +69 -69
  204. package/templates/nextblock-template/lib/promotions/server.test.ts +74 -74
  205. package/templates/nextblock-template/lib/promotions/server.ts +741 -741
  206. package/templates/nextblock-template/lib/resolve-block-relations.test.ts +142 -142
  207. package/templates/nextblock-template/lib/resolve-block-relations.ts +255 -255
  208. package/templates/nextblock-template/lib/search/types.ts +27 -27
  209. package/templates/nextblock-template/lib/setup/actions.ts +460 -460
  210. package/templates/nextblock-template/lib/setup/env-status.ts +125 -125
  211. package/templates/nextblock-template/lib/setup/env-write.ts +111 -111
  212. package/templates/nextblock-template/lib/setup/migrations-bundle.ts +87 -87
  213. package/templates/nextblock-template/lib/setup/provisioning.ts +59 -59
  214. package/templates/nextblock-template/lib/setup/schema-apply.ts +408 -408
  215. package/templates/nextblock-template/lib/setup/system-config.ts +105 -105
  216. package/templates/nextblock-template/lib/setup/types.ts +18 -18
  217. package/templates/nextblock-template/lib/site-url.ts +48 -48
  218. package/templates/nextblock-template/lib/storage/provider.ts +66 -66
  219. package/templates/nextblock-template/lib/storage/supabase-storage.ts +103 -103
  220. package/templates/nextblock-template/lib/updates/check-upstream.ts +441 -441
  221. package/templates/nextblock-template/lib/updates/github-device.ts +206 -206
  222. package/templates/nextblock-template/lib/updates/repo-identity.ts +56 -56
  223. package/templates/nextblock-template/next-env.d.ts +1 -0
  224. package/templates/nextblock-template/package.json +6 -6
  225. package/templates/nextblock-template/postcss.config.js +6 -6
  226. package/templates/nextblock-template/scripts/backup.js +115 -115
  227. package/templates/nextblock-template/scripts/docker-setup.mjs +310 -310
  228. package/templates/nextblock-template/scripts/restore.js +385 -385
  229. package/templates/nextblock-template/scripts/verify-cortex-ai-build-widget.tsx +98 -98
  230. package/templates/nextblock-template/scripts/verify-cortex-ai-generate-blocks.ts +62 -62
  231. package/templates/nextblock-template/scripts/verify-cortex-ai-global-tools.ts +537 -537
  232. package/templates/nextblock-template/scripts/verify-cortex-ai-routing.ts +58 -58
  233. package/templates/nextblock-template/scripts/verify-custom-block-definitions.ts +188 -188
  234. package/templates/nextblock-template/scripts/verify-dynamic-custom-block-extensions.ts +123 -123
  235. package/templates/nextblock-template/scripts/verify-dynamic-layout-engine.tsx +133 -133
  236. package/templates/nextblock-template/scripts/verify-milestone-2-custom-blocks.ts +65 -65
  237. package/templates/nextblock-template/tailwind.config.js +25 -25
  238. package/templates/nextblock-template/tools/build-migrate.mjs +209 -209
  239. package/templates/nextblock-template/tools/configure-supabase-auth.js +282 -282
  240. package/templates/nextblock-template/tsconfig.tsbuildinfo +1 -1
  241. package/templates/nextblock-template/types/jsdom.d.ts +6 -6
  242. package/tsconfig.base.json +3 -3
@@ -1,688 +1,688 @@
1
- 'use client';
2
-
3
- import React, { useEffect, useState } from 'react';
4
- import {
5
- Alert,
6
- AlertDescription,
7
- AlertTitle,
8
- Badge,
9
- Button,
10
- Card,
11
- CardContent,
12
- CardDescription,
13
- CardHeader,
14
- CardTitle,
15
- Input,
16
- Label,
17
- SearchableSelect,
18
- } from '@nextblock-cms/ui';
19
- import {
20
- AlertTriangle,
21
- Brain,
22
- CheckCircle2,
23
- ChevronDown,
24
- ChevronRight,
25
- Cpu,
26
- ImageIcon,
27
- Info,
28
- KeyRound,
29
- Lock,
30
- SlidersHorizontal,
31
- Trash2,
32
- } from 'lucide-react';
33
- import {
34
- createCortexAiStoredModelSelection,
35
- type CortexAiStoredModelSelection,
36
- } from '@nextblock-cms/cortex/client';
37
- import type { CortexAiAgentSettings } from '@nextblock-cms/cortex';
38
-
39
- const CORTEX_AI_SANDBOX_KEY_LOCAL_STORAGE = 'cortex_ai_sandbox_openrouter_api_key';
40
- const CORTEX_AI_SANDBOX_MODEL_LOCAL_STORAGE = 'cortex_ai_sandbox_openrouter_model_selection';
41
- const CORTEX_AI_SETTINGS_CHANGED_EVENT = 'nextblock:cortex-ai-settings-changed';
42
-
43
- type SandboxCortexAiSettingsClientProps = {
44
- compatibleModels: Array<{
45
- id: string;
46
- name: string;
47
- pricing: Record<string, string>;
48
- context_length: number | null;
49
- created?: number | null;
50
- architecture?: {
51
- modality?: string;
52
- tokenizer?: string;
53
- instruct_type?: string | null;
54
- } | null;
55
- description?: string;
56
- top_provider?: {
57
- max_completion_tokens?: number | null;
58
- is_moderated?: boolean;
59
- } | null;
60
- }>;
61
- isPackageActive: boolean;
62
- hasEnvOpenRouterKey: boolean;
63
- maskedEnvOpenRouterKey: string | null;
64
- modelCatalogError: string | null;
65
- activeStockProvider: 'pexels' | 'unsplash' | null;
66
- hasStoredPexelsKey: boolean;
67
- maskedStoredPexelsKey: string | null;
68
- hasStoredUnsplashKey: boolean;
69
- maskedStoredUnsplashKey: string | null;
70
- hasEnvPexelsKey: boolean;
71
- hasEnvUnsplashKey: boolean;
72
- unsplashAppName: string | null;
73
- agentSettings: CortexAiAgentSettings;
74
- };
75
-
76
- function formatTokenPrice(value: string | undefined) {
77
- const amount = Number(value);
78
- if (!Number.isFinite(amount)) return null;
79
- if (amount === 0) return '$0';
80
- const perMillion = amount * 1_000_000;
81
- return `$${perMillion < 0.01 ? perMillion.toFixed(4) : perMillion.toFixed(2)}`;
82
- }
83
-
84
- function formatModelPricing(pricing: Record<string, string>) {
85
- const promptPrice = formatTokenPrice(pricing.prompt);
86
- const completionPrice = formatTokenPrice(pricing.completion);
87
- if (promptPrice === '$0' && completionPrice === '$0') return 'Free';
88
- if (promptPrice && completionPrice) return `${promptPrice}/1M input - ${completionPrice}/1M output`;
89
- return 'Pricing varies';
90
- }
91
-
92
- function getMaskedKey(key: string) {
93
- if (key.length <= 8) return '****';
94
- return `**** ${key.slice(-4)}`;
95
- }
96
-
97
- function notifyCortexAiSettingsChanged() {
98
- window.dispatchEvent(new Event(CORTEX_AI_SETTINGS_CHANGED_EVENT));
99
- }
100
-
101
- function StatusPill({
102
- label,
103
- value,
104
- active,
105
- detail,
106
- }: {
107
- label: string;
108
- value: string;
109
- active: boolean;
110
- detail?: string | null;
111
- }) {
112
- return (
113
- <div className="flex min-w-[8rem] flex-col gap-1 rounded-md border bg-muted/30 px-3 py-2">
114
- <span className="text-[10px] font-semibold uppercase tracking-wider text-muted-foreground">
115
- {label}
116
- </span>
117
- <div className="flex items-center gap-2">
118
- <span className={`h-2 w-2 rounded-full ${active ? 'bg-emerald-500' : 'bg-muted-foreground/40'}`} />
119
- <span className="text-sm font-medium">{value}</span>
120
- </div>
121
- {detail && <span className="truncate font-mono text-[11px] text-muted-foreground">{detail}</span>}
122
- </div>
123
- );
124
- }
125
-
126
- // Sandbox mirrors the production layout, but every server-backed setting is
127
- // read-only: the settings actions refuse to write to the shared sandbox DB, and
128
- // only the OpenRouter key + model have a per-visitor override channel
129
- // (localStorage -> x-sandbox-openrouter-* headers).
130
- function ReadOnlyRow({
131
- label,
132
- value,
133
- detail,
134
- }: {
135
- label: string;
136
- value: string;
137
- detail?: string | null;
138
- }) {
139
- return (
140
- <div className="flex items-center justify-between gap-3 rounded-md border bg-muted/20 px-3 py-2">
141
- <span className="text-xs font-medium">{label}</span>
142
- <div className="flex items-center gap-2 text-right">
143
- <span className="text-xs text-muted-foreground">{value}</span>
144
- {detail && <span className="font-mono text-[11px] text-muted-foreground">{detail}</span>}
145
- </div>
146
- </div>
147
- );
148
- }
149
-
150
- export function SandboxCortexAiSettingsClient({
151
- compatibleModels,
152
- isPackageActive,
153
- hasEnvOpenRouterKey,
154
- maskedEnvOpenRouterKey,
155
- modelCatalogError,
156
- activeStockProvider,
157
- hasStoredPexelsKey,
158
- maskedStoredPexelsKey,
159
- hasStoredUnsplashKey,
160
- maskedStoredUnsplashKey,
161
- hasEnvPexelsKey,
162
- hasEnvUnsplashKey,
163
- unsplashAppName,
164
- agentSettings,
165
- }: SandboxCortexAiSettingsClientProps) {
166
- const [mounted, setMounted] = useState(false);
167
- const [sandboxKey, setSandboxKey] = useState<string | null>(null);
168
- const [sandboxModel, setSandboxModel] = useState<CortexAiStoredModelSelection | null>(null);
169
- const [inputValue, setInputValue] = useState('');
170
- const [modelInput, setModelInput] = useState<string>('');
171
- const [successMessage, setSuccessMessage] = useState<string | null>(null);
172
- const [showAdvanced, setShowAdvanced] = useState(false);
173
-
174
- useEffect(() => {
175
- try {
176
- const storedKey = window.localStorage.getItem(CORTEX_AI_SANDBOX_KEY_LOCAL_STORAGE);
177
- if (storedKey) {
178
- setSandboxKey(storedKey);
179
- }
180
-
181
- const storedModel = window.localStorage.getItem(CORTEX_AI_SANDBOX_MODEL_LOCAL_STORAGE);
182
- if (storedModel) {
183
- const parsed = JSON.parse(storedModel) as CortexAiStoredModelSelection;
184
- setSandboxModel(parsed);
185
- setModelInput(parsed.modelId);
186
- }
187
- } catch (error) {
188
- console.error('Failed to read Cortex AI sandbox settings from localStorage', error);
189
- }
190
- setMounted(true);
191
- }, []);
192
-
193
- const handleSaveKey = (e: React.FormEvent) => {
194
- e.preventDefault();
195
- const key = inputValue.trim();
196
- if (!key) return;
197
-
198
- try {
199
- window.localStorage.setItem(CORTEX_AI_SANDBOX_KEY_LOCAL_STORAGE, key);
200
- setSandboxKey(key);
201
- setInputValue('');
202
- notifyCortexAiSettingsChanged();
203
- setSuccessMessage('Sandbox OpenRouter key saved to your browser.');
204
- setTimeout(() => setSuccessMessage(null), 3000);
205
- } catch (error) {
206
- console.error('Failed to save sandbox key', error);
207
- }
208
- };
209
-
210
- const handleClearKey = () => {
211
- try {
212
- window.localStorage.removeItem(CORTEX_AI_SANDBOX_KEY_LOCAL_STORAGE);
213
- window.localStorage.removeItem(CORTEX_AI_SANDBOX_MODEL_LOCAL_STORAGE);
214
- setSandboxKey(null);
215
- setSandboxModel(null);
216
- setModelInput('');
217
- notifyCortexAiSettingsChanged();
218
- setSuccessMessage('Sandbox OpenRouter key cleared from your browser.');
219
- setTimeout(() => setSuccessMessage(null), 3000);
220
- } catch (error) {
221
- console.error('Failed to clear sandbox key', error);
222
- }
223
- };
224
-
225
- const handleSaveModel = (e: React.FormEvent<HTMLFormElement>) => {
226
- e.preventDefault();
227
- const formData = new FormData(e.currentTarget);
228
- const modelId = String(formData.get('openrouter_model_id') || '').trim();
229
- if (!modelId) return;
230
-
231
- const selectedModel = compatibleModels.find((m) => m.id === modelId);
232
- if (!selectedModel) return;
233
-
234
- try {
235
- const storedSelection = createCortexAiStoredModelSelection(selectedModel as any);
236
- window.localStorage.setItem(
237
- CORTEX_AI_SANDBOX_MODEL_LOCAL_STORAGE,
238
- JSON.stringify(storedSelection)
239
- );
240
- setSandboxModel(storedSelection);
241
- notifyCortexAiSettingsChanged();
242
- setSuccessMessage('Sandbox Cortex AI model selection saved to your browser.');
243
- setTimeout(() => setSuccessMessage(null), 3000);
244
- } catch (error) {
245
- console.error('Failed to save sandbox model', error);
246
- }
247
- };
248
-
249
- const handleClearModel = () => {
250
- try {
251
- window.localStorage.removeItem(CORTEX_AI_SANDBOX_MODEL_LOCAL_STORAGE);
252
- setSandboxModel(null);
253
- setModelInput('');
254
- notifyCortexAiSettingsChanged();
255
- setSuccessMessage('Sandbox Cortex AI model selection cleared.');
256
- setTimeout(() => setSuccessMessage(null), 3000);
257
- } catch (error) {
258
- console.error('Failed to clear sandbox model', error);
259
- }
260
- };
261
-
262
- if (!mounted) {
263
- return null; // Avoid hydration mismatch
264
- }
265
-
266
- const selectedModelIsInCatalog = compatibleModels.some(
267
- (model) => model.id === sandboxModel?.modelId
268
- );
269
-
270
- const modelOptions =
271
- sandboxModel && !selectedModelIsInCatalog
272
- ? [
273
- {
274
- context_length: sandboxModel.contextLength,
275
- created: null,
276
- expirationDate: null,
277
- id: sandboxModel.modelId,
278
- name: `${sandboxModel.name} (saved)`,
279
- pricing: sandboxModel.pricing,
280
- supportedParameters: sandboxModel.supportedParameters,
281
- },
282
- ...compatibleModels,
283
- ]
284
- : compatibleModels;
285
-
286
- const canSelectModel = !!sandboxKey && compatibleModels.length > 0;
287
- const maskedSandboxKey = sandboxKey ? getMaskedKey(sandboxKey) : null;
288
- const isKeyDirty = inputValue.trim().length > 0;
289
- const isModelDirty = modelInput !== (sandboxModel?.modelId || '');
290
-
291
- const searchableOptions = modelOptions.map((model) => ({
292
- value: model.id,
293
- label: model.name,
294
- description: `${model.id} - ${formatModelPricing(model.pricing as any)}`,
295
- }));
296
-
297
- const keySourceValue = sandboxKey ? 'Sandbox BYOK' : hasEnvOpenRouterKey ? 'Environment' : 'None';
298
- // Ordered by preference (Pexels primary, Unsplash fallback). Configured = a
299
- // stored DB key OR an env var for that provider.
300
- const configuredStockProviders = [
301
- hasStoredPexelsKey || hasEnvPexelsKey ? { name: 'Pexels', stored: hasStoredPexelsKey } : null,
302
- hasStoredUnsplashKey || hasEnvUnsplashKey
303
- ? { name: 'Unsplash', stored: hasStoredUnsplashKey }
304
- : null,
305
- ].filter(Boolean) as Array<{ name: string; stored: boolean }>;
306
- const stockValue =
307
- configuredStockProviders.length > 0
308
- ? configuredStockProviders.map((provider) => provider.name).join(' + ')
309
- : 'Off';
310
-
311
- return (
312
- <div className="mx-auto w-full max-w-5xl space-y-4 px-4 py-6">
313
- <div className="flex items-center gap-2.5">
314
- <Brain className="h-6 w-6 text-primary" />
315
- <div>
316
- <h1 className="text-xl font-semibold leading-tight">
317
- NextBlock Cortex AI{' '}
318
- <Badge variant="secondary" className="ml-1 align-middle font-normal">
319
- Sandbox
320
- </Badge>
321
- </h1>
322
- <p className="text-xs text-muted-foreground">
323
- Manage the OpenRouter model key used by Cortex AI in your own browser session.
324
- </p>
325
- </div>
326
- </div>
327
-
328
- {successMessage && (
329
- <Alert variant="success">
330
- <CheckCircle2 className="h-4 w-4" />
331
- <AlertTitle>Saved</AlertTitle>
332
- <AlertDescription>{successMessage}</AlertDescription>
333
- </Alert>
334
- )}
335
-
336
- {/* Compact status strip */}
337
- <div className="flex flex-wrap gap-2">
338
- <StatusPill
339
- label="Package"
340
- value={isPackageActive ? 'Active' : 'Inactive'}
341
- active={isPackageActive}
342
- />
343
- <StatusPill
344
- label="Model key"
345
- value={keySourceValue}
346
- active={Boolean(sandboxKey) || hasEnvOpenRouterKey}
347
- detail={maskedSandboxKey || maskedEnvOpenRouterKey}
348
- />
349
- <StatusPill
350
- label="Model"
351
- value={sandboxModel ? sandboxModel.name : 'Free registry'}
352
- active={Boolean(sandboxModel)}
353
- />
354
- <StatusPill
355
- label="Stock photos"
356
- value={stockValue}
357
- active={Boolean(activeStockProvider)}
358
- />
359
- </div>
360
-
361
- <Alert
362
- variant="warning"
363
- className="border-amber-200 bg-amber-50 text-amber-900 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-200"
364
- >
365
- <Info className="h-4 w-4" />
366
- <AlertTitle>Sandbox environment active</AlertTitle>
367
- <AlertDescription>
368
- The key and model you set here are stored{' '}
369
- <strong>only in your own browser (localStorage)</strong> and are never written to the
370
- shared sandbox database. Server-backed settings below are read-only here.
371
- </AlertDescription>
372
- </Alert>
373
-
374
- {hasEnvOpenRouterKey && !sandboxKey && (
375
- <Alert>
376
- <KeyRound className="h-4 w-4" />
377
- <AlertTitle>Free-model lock active</AlertTitle>
378
- <AlertDescription>
379
- Cortex AI will only use the configured free OpenRouter models until you save a sandbox
380
- key to your browser.
381
- </AlertDescription>
382
- </Alert>
383
- )}
384
-
385
- {/* OpenRouter BYOK + Model side by side */}
386
- <div className="grid gap-4 lg:grid-cols-2">
387
- <Card>
388
- <CardHeader className="flex flex-row items-start justify-between space-y-0 pb-3">
389
- <div>
390
- <CardTitle className="text-base">OpenRouter key</CardTitle>
391
- <CardDescription className="text-xs">
392
- Saved to your browser only, never uploaded.
393
- </CardDescription>
394
- </div>
395
- {sandboxKey && (
396
- <Button
397
- type="button"
398
- onClick={handleClearKey}
399
- variant="ghost"
400
- size="sm"
401
- className="h-7 text-destructive hover:text-destructive"
402
- >
403
- <Trash2 className="mr-1.5 h-3.5 w-3.5" />
404
- Clear
405
- </Button>
406
- )}
407
- </CardHeader>
408
- <CardContent className="pt-0">
409
- <form onSubmit={handleSaveKey} className="flex items-end gap-2">
410
- <div className="flex-1 space-y-1.5">
411
- <Label htmlFor="openrouter_api_key" className="text-xs">
412
- API key
413
- </Label>
414
- <Input
415
- id="openrouter_api_key"
416
- name="openrouter_api_key"
417
- type="password"
418
- autoComplete="off"
419
- minLength={12}
420
- placeholder={sandboxKey ? 'Enter new key to overwrite...' : 'sk-or-v1-...'}
421
- value={inputValue}
422
- onChange={(e) => setInputValue(e.target.value)}
423
- required
424
- />
425
- </div>
426
- <Button type="submit" disabled={!isKeyDirty} size="sm">
427
- <KeyRound className="mr-1.5 h-3.5 w-3.5" />
428
- Save
429
- </Button>
430
- </form>
431
- </CardContent>
432
- </Card>
433
-
434
- <Card>
435
- <CardHeader className="flex flex-row items-start justify-between space-y-0 pb-3">
436
- <div>
437
- <CardTitle className="text-base">OpenRouter model</CardTitle>
438
- <CardDescription className="text-xs">
439
- Needs a sandbox key; supports tools + structured output.
440
- </CardDescription>
441
- </div>
442
- {sandboxModel && (
443
- <Button
444
- type="button"
445
- onClick={handleClearModel}
446
- variant="ghost"
447
- size="sm"
448
- className="h-7 text-destructive hover:text-destructive"
449
- >
450
- <Trash2 className="mr-1.5 h-3.5 w-3.5" />
451
- Clear
452
- </Button>
453
- )}
454
- </CardHeader>
455
- <CardContent className="space-y-2 pt-0">
456
- {modelCatalogError && (
457
- <Alert variant="warning">
458
- <AlertTriangle className="h-4 w-4" />
459
- <AlertTitle>Model catalog unavailable</AlertTitle>
460
- <AlertDescription>{modelCatalogError}</AlertDescription>
461
- </Alert>
462
- )}
463
- <form onSubmit={handleSaveModel} className="flex items-end gap-2">
464
- <input type="hidden" name="openrouter_model_id" value={modelInput} />
465
- <div className="flex-1 space-y-1.5">
466
- <Label htmlFor="openrouter_model_id_select" className="text-xs">
467
- Model
468
- </Label>
469
- <SearchableSelect
470
- options={searchableOptions}
471
- value={modelInput}
472
- onChange={(val) => setModelInput(val)}
473
- disabled={!canSelectModel}
474
- placeholder="Select a compatible model..."
475
- />
476
- </div>
477
- <Button type="submit" disabled={!canSelectModel || !isModelDirty} size="sm">
478
- <Cpu className="mr-1.5 h-3.5 w-3.5" />
479
- Save
480
- </Button>
481
- </form>
482
- <p className="text-[11px] text-muted-foreground">
483
- {canSelectModel
484
- ? `${compatibleModels.length} compatible models available.`
485
- : 'Cortex AI uses the free registry until a sandbox key + model are set.'}
486
- </p>
487
- </CardContent>
488
- </Card>
489
- </div>
490
-
491
- {/* Stock photos - read-only in sandbox */}
492
- <Card>
493
- <CardHeader className="pb-3">
494
- <CardTitle className="flex flex-wrap items-center gap-2 text-base">
495
- <ImageIcon className="h-4 w-4" />
496
- Stock photos
497
- {configuredStockProviders.length > 0 ? (
498
- configuredStockProviders.map((provider, index) => (
499
- <Badge
500
- key={provider.name}
501
- variant={index === 0 ? 'default' : 'secondary'}
502
- className="ml-0.5 font-normal"
503
- >
504
- {provider.name} · {index === 0 ? 'primary' : 'fallback'}
505
- {!provider.stored && ' (env)'}
506
- </Badge>
507
- ))
508
- ) : (
509
- <Badge variant="outline" className="ml-0.5">
510
- Not configured
511
- </Badge>
512
- )}
513
- <Badge variant="outline" className="ml-auto gap-1 font-normal">
514
- <Lock className="h-3 w-3" />
515
- Read-only
516
- </Badge>
517
- </CardTitle>
518
- <CardDescription className="text-xs">
519
- A Pexels/Unsplash key lets Cortex insert real photos into pages. Pexels is used first;
520
- Cortex automatically falls back to Unsplash if Pexels is rate-limited.
521
- </CardDescription>
522
- </CardHeader>
523
- <CardContent className="space-y-4 pt-0">
524
- <div className="grid gap-4 md:grid-cols-2">
525
- <div className="rounded-md border bg-muted/20 p-3 text-sm">
526
- <p className="font-medium">What this does</p>
527
- <p className="mt-1 text-xs text-muted-foreground">
528
- When you ask Cortex to build or revamp a page, a stock key lets it fetch relevant,
529
- high-quality photos for the hero and sections automatically — instant, zero
530
- image-generation cost, and you can save any photo into your media library with one
531
- click. Without a key Cortex still builds pages, but uses gradient/theme backgrounds
532
- instead of photos, and it will not call the photo tool at all.
533
- </p>
534
- <p className="mt-3 text-[11px] text-muted-foreground">
535
- In your own NextBlock install you add these keys on this page and they are encrypted
536
- into your database. In the shared sandbox they are provided by the host environment
537
- and cannot be changed.
538
- </p>
539
- </div>
540
-
541
- <div className="space-y-2">
542
- <ReadOnlyRow
543
- label="Pexels API key"
544
- value={
545
- hasStoredPexelsKey
546
- ? 'Configured (stored)'
547
- : hasEnvPexelsKey
548
- ? 'Configured (env)'
549
- : 'Not set'
550
- }
551
- detail={maskedStoredPexelsKey}
552
- />
553
- <ReadOnlyRow
554
- label="Unsplash Access key"
555
- value={
556
- hasStoredUnsplashKey
557
- ? 'Configured (stored)'
558
- : hasEnvUnsplashKey
559
- ? 'Configured (env)'
560
- : 'Not set'
561
- }
562
- detail={maskedStoredUnsplashKey}
563
- />
564
- <ReadOnlyRow label="Unsplash app name" value={unsplashAppName || 'Not set'} />
565
- <p className="text-[11px] text-muted-foreground">
566
- {configuredStockProviders.length > 0
567
- ? `Using ${configuredStockProviders.map((provider) => provider.name).join(', ')}.`
568
- : 'No provider configured in this sandbox.'}
569
- </p>
570
- </div>
571
- </div>
572
- </CardContent>
573
- </Card>
574
-
575
- {/* Advanced settings (collapsed by default) - read-only in sandbox */}
576
- <div>
577
- <button
578
- type="button"
579
- onClick={() => setShowAdvanced((open) => !open)}
580
- className="flex w-full items-center gap-2 rounded-md border bg-muted/20 px-3 py-2 text-left text-sm font-medium hover:bg-muted/40"
581
- >
582
- <SlidersHorizontal className="h-4 w-4" />
583
- Advanced settings
584
- <span className="ml-auto text-xs text-muted-foreground">
585
- {agentSettings.maxOutputTokens === null
586
- ? 'Unlimited output'
587
- : `${agentSettings.maxOutputTokens} tokens`}{' '}
588
- · {agentSettings.maxSteps} steps
589
- </span>
590
- {showAdvanced ? (
591
- <ChevronDown className="h-4 w-4" />
592
- ) : (
593
- <ChevronRight className="h-4 w-4" />
594
- )}
595
- </button>
596
-
597
- {showAdvanced && (
598
- <Card className="mt-2">
599
- <CardHeader className="pb-3">
600
- <CardTitle className="flex items-center gap-2 text-base">
601
- Agent tuning
602
- <Badge variant="outline" className="gap-1 font-normal">
603
- <Lock className="h-3 w-3" />
604
- Read-only
605
- </Badge>
606
- </CardTitle>
607
- <CardDescription className="text-xs">
608
- Controls how much room the page-building agent has. These are set by the sandbox host
609
- and shared by every visitor, so they cannot be edited here.
610
- </CardDescription>
611
- </CardHeader>
612
- <CardContent className="space-y-4 pt-0">
613
- <div className="grid gap-4 sm:grid-cols-2">
614
- <div className="space-y-1.5">
615
- <Label htmlFor="max_output_tokens" className="text-xs">
616
- Max output tokens per step
617
- </Label>
618
- <Input
619
- id="max_output_tokens"
620
- type="text"
621
- value={
622
- agentSettings.maxOutputTokens === null
623
- ? 'Unlimited'
624
- : String(agentSettings.maxOutputTokens)
625
- }
626
- readOnly
627
- disabled
628
- />
629
- <p className="text-[11px] text-muted-foreground">
630
- The per-step output budget. Range 256–200,000, or Unlimited. Default 16,000.
631
- </p>
632
- </div>
633
- <div className="space-y-1.5">
634
- <Label htmlFor="max_steps" className="text-xs">
635
- Max tool steps
636
- </Label>
637
- <Input
638
- id="max_steps"
639
- type="text"
640
- value={String(agentSettings.maxSteps)}
641
- readOnly
642
- disabled
643
- />
644
- <p className="text-[11px] text-muted-foreground">
645
- Range 2–100 tool-call rounds. Default 8; each step is one model call.
646
- </p>
647
- </div>
648
- <div className="space-y-1.5">
649
- <Label htmlFor="temperature" className="text-xs">
650
- Temperature
651
- </Label>
652
- <Input
653
- id="temperature"
654
- type="text"
655
- value={String(agentSettings.temperature)}
656
- readOnly
657
- disabled
658
- />
659
- <p className="text-[11px] text-muted-foreground">
660
- Range 0–2. Cortex default 0.1 (low = reliable; most models default higher).
661
- </p>
662
- </div>
663
- <div className="space-y-1.5">
664
- <Label htmlFor="response_timeout_seconds" className="text-xs">
665
- Response timeout (seconds)
666
- </Label>
667
- <Input
668
- id="response_timeout_seconds"
669
- type="text"
670
- value={String(Math.round(agentSettings.responseTimeoutMs / 1000))}
671
- readOnly
672
- disabled
673
- />
674
- <p className="text-[11px] text-muted-foreground">
675
- Range 15–600s. Default 120; aborts only after this long with no activity.
676
- </p>
677
- </div>
678
- </div>
679
- <p className="text-[11px] text-muted-foreground">
680
- Applies to the global page-building agent. Editable on a self-hosted install.
681
- </p>
682
- </CardContent>
683
- </Card>
684
- )}
685
- </div>
686
- </div>
687
- );
688
- }
1
+ 'use client';
2
+
3
+ import React, { useEffect, useState } from 'react';
4
+ import {
5
+ Alert,
6
+ AlertDescription,
7
+ AlertTitle,
8
+ Badge,
9
+ Button,
10
+ Card,
11
+ CardContent,
12
+ CardDescription,
13
+ CardHeader,
14
+ CardTitle,
15
+ Input,
16
+ Label,
17
+ SearchableSelect,
18
+ } from '@nextblock-cms/ui';
19
+ import {
20
+ AlertTriangle,
21
+ Brain,
22
+ CheckCircle2,
23
+ ChevronDown,
24
+ ChevronRight,
25
+ Cpu,
26
+ ImageIcon,
27
+ Info,
28
+ KeyRound,
29
+ Lock,
30
+ SlidersHorizontal,
31
+ Trash2,
32
+ } from 'lucide-react';
33
+ import {
34
+ createCortexAiStoredModelSelection,
35
+ type CortexAiStoredModelSelection,
36
+ } from '@nextblock-cms/cortex/client';
37
+ import type { CortexAiAgentSettings } from '@nextblock-cms/cortex';
38
+
39
+ const CORTEX_AI_SANDBOX_KEY_LOCAL_STORAGE = 'cortex_ai_sandbox_openrouter_api_key';
40
+ const CORTEX_AI_SANDBOX_MODEL_LOCAL_STORAGE = 'cortex_ai_sandbox_openrouter_model_selection';
41
+ const CORTEX_AI_SETTINGS_CHANGED_EVENT = 'nextblock:cortex-ai-settings-changed';
42
+
43
+ type SandboxCortexAiSettingsClientProps = {
44
+ compatibleModels: Array<{
45
+ id: string;
46
+ name: string;
47
+ pricing: Record<string, string>;
48
+ context_length: number | null;
49
+ created?: number | null;
50
+ architecture?: {
51
+ modality?: string;
52
+ tokenizer?: string;
53
+ instruct_type?: string | null;
54
+ } | null;
55
+ description?: string;
56
+ top_provider?: {
57
+ max_completion_tokens?: number | null;
58
+ is_moderated?: boolean;
59
+ } | null;
60
+ }>;
61
+ isPackageActive: boolean;
62
+ hasEnvOpenRouterKey: boolean;
63
+ maskedEnvOpenRouterKey: string | null;
64
+ modelCatalogError: string | null;
65
+ activeStockProvider: 'pexels' | 'unsplash' | null;
66
+ hasStoredPexelsKey: boolean;
67
+ maskedStoredPexelsKey: string | null;
68
+ hasStoredUnsplashKey: boolean;
69
+ maskedStoredUnsplashKey: string | null;
70
+ hasEnvPexelsKey: boolean;
71
+ hasEnvUnsplashKey: boolean;
72
+ unsplashAppName: string | null;
73
+ agentSettings: CortexAiAgentSettings;
74
+ };
75
+
76
+ function formatTokenPrice(value: string | undefined) {
77
+ const amount = Number(value);
78
+ if (!Number.isFinite(amount)) return null;
79
+ if (amount === 0) return '$0';
80
+ const perMillion = amount * 1_000_000;
81
+ return `$${perMillion < 0.01 ? perMillion.toFixed(4) : perMillion.toFixed(2)}`;
82
+ }
83
+
84
+ function formatModelPricing(pricing: Record<string, string>) {
85
+ const promptPrice = formatTokenPrice(pricing.prompt);
86
+ const completionPrice = formatTokenPrice(pricing.completion);
87
+ if (promptPrice === '$0' && completionPrice === '$0') return 'Free';
88
+ if (promptPrice && completionPrice) return `${promptPrice}/1M input - ${completionPrice}/1M output`;
89
+ return 'Pricing varies';
90
+ }
91
+
92
+ function getMaskedKey(key: string) {
93
+ if (key.length <= 8) return '****';
94
+ return `**** ${key.slice(-4)}`;
95
+ }
96
+
97
+ function notifyCortexAiSettingsChanged() {
98
+ window.dispatchEvent(new Event(CORTEX_AI_SETTINGS_CHANGED_EVENT));
99
+ }
100
+
101
+ function StatusPill({
102
+ label,
103
+ value,
104
+ active,
105
+ detail,
106
+ }: {
107
+ label: string;
108
+ value: string;
109
+ active: boolean;
110
+ detail?: string | null;
111
+ }) {
112
+ return (
113
+ <div className="flex min-w-[8rem] flex-col gap-1 rounded-md border bg-muted/30 px-3 py-2">
114
+ <span className="text-[10px] font-semibold uppercase tracking-wider text-muted-foreground">
115
+ {label}
116
+ </span>
117
+ <div className="flex items-center gap-2">
118
+ <span className={`h-2 w-2 rounded-full ${active ? 'bg-emerald-500' : 'bg-muted-foreground/40'}`} />
119
+ <span className="text-sm font-medium">{value}</span>
120
+ </div>
121
+ {detail && <span className="truncate font-mono text-[11px] text-muted-foreground">{detail}</span>}
122
+ </div>
123
+ );
124
+ }
125
+
126
+ // Sandbox mirrors the production layout, but every server-backed setting is
127
+ // read-only: the settings actions refuse to write to the shared sandbox DB, and
128
+ // only the OpenRouter key + model have a per-visitor override channel
129
+ // (localStorage -> x-sandbox-openrouter-* headers).
130
+ function ReadOnlyRow({
131
+ label,
132
+ value,
133
+ detail,
134
+ }: {
135
+ label: string;
136
+ value: string;
137
+ detail?: string | null;
138
+ }) {
139
+ return (
140
+ <div className="flex items-center justify-between gap-3 rounded-md border bg-muted/20 px-3 py-2">
141
+ <span className="text-xs font-medium">{label}</span>
142
+ <div className="flex items-center gap-2 text-right">
143
+ <span className="text-xs text-muted-foreground">{value}</span>
144
+ {detail && <span className="font-mono text-[11px] text-muted-foreground">{detail}</span>}
145
+ </div>
146
+ </div>
147
+ );
148
+ }
149
+
150
+ export function SandboxCortexAiSettingsClient({
151
+ compatibleModels,
152
+ isPackageActive,
153
+ hasEnvOpenRouterKey,
154
+ maskedEnvOpenRouterKey,
155
+ modelCatalogError,
156
+ activeStockProvider,
157
+ hasStoredPexelsKey,
158
+ maskedStoredPexelsKey,
159
+ hasStoredUnsplashKey,
160
+ maskedStoredUnsplashKey,
161
+ hasEnvPexelsKey,
162
+ hasEnvUnsplashKey,
163
+ unsplashAppName,
164
+ agentSettings,
165
+ }: SandboxCortexAiSettingsClientProps) {
166
+ const [mounted, setMounted] = useState(false);
167
+ const [sandboxKey, setSandboxKey] = useState<string | null>(null);
168
+ const [sandboxModel, setSandboxModel] = useState<CortexAiStoredModelSelection | null>(null);
169
+ const [inputValue, setInputValue] = useState('');
170
+ const [modelInput, setModelInput] = useState<string>('');
171
+ const [successMessage, setSuccessMessage] = useState<string | null>(null);
172
+ const [showAdvanced, setShowAdvanced] = useState(false);
173
+
174
+ useEffect(() => {
175
+ try {
176
+ const storedKey = window.localStorage.getItem(CORTEX_AI_SANDBOX_KEY_LOCAL_STORAGE);
177
+ if (storedKey) {
178
+ setSandboxKey(storedKey);
179
+ }
180
+
181
+ const storedModel = window.localStorage.getItem(CORTEX_AI_SANDBOX_MODEL_LOCAL_STORAGE);
182
+ if (storedModel) {
183
+ const parsed = JSON.parse(storedModel) as CortexAiStoredModelSelection;
184
+ setSandboxModel(parsed);
185
+ setModelInput(parsed.modelId);
186
+ }
187
+ } catch (error) {
188
+ console.error('Failed to read Cortex AI sandbox settings from localStorage', error);
189
+ }
190
+ setMounted(true);
191
+ }, []);
192
+
193
+ const handleSaveKey = (e: React.FormEvent) => {
194
+ e.preventDefault();
195
+ const key = inputValue.trim();
196
+ if (!key) return;
197
+
198
+ try {
199
+ window.localStorage.setItem(CORTEX_AI_SANDBOX_KEY_LOCAL_STORAGE, key);
200
+ setSandboxKey(key);
201
+ setInputValue('');
202
+ notifyCortexAiSettingsChanged();
203
+ setSuccessMessage('Sandbox OpenRouter key saved to your browser.');
204
+ setTimeout(() => setSuccessMessage(null), 3000);
205
+ } catch (error) {
206
+ console.error('Failed to save sandbox key', error);
207
+ }
208
+ };
209
+
210
+ const handleClearKey = () => {
211
+ try {
212
+ window.localStorage.removeItem(CORTEX_AI_SANDBOX_KEY_LOCAL_STORAGE);
213
+ window.localStorage.removeItem(CORTEX_AI_SANDBOX_MODEL_LOCAL_STORAGE);
214
+ setSandboxKey(null);
215
+ setSandboxModel(null);
216
+ setModelInput('');
217
+ notifyCortexAiSettingsChanged();
218
+ setSuccessMessage('Sandbox OpenRouter key cleared from your browser.');
219
+ setTimeout(() => setSuccessMessage(null), 3000);
220
+ } catch (error) {
221
+ console.error('Failed to clear sandbox key', error);
222
+ }
223
+ };
224
+
225
+ const handleSaveModel = (e: React.FormEvent<HTMLFormElement>) => {
226
+ e.preventDefault();
227
+ const formData = new FormData(e.currentTarget);
228
+ const modelId = String(formData.get('openrouter_model_id') || '').trim();
229
+ if (!modelId) return;
230
+
231
+ const selectedModel = compatibleModels.find((m) => m.id === modelId);
232
+ if (!selectedModel) return;
233
+
234
+ try {
235
+ const storedSelection = createCortexAiStoredModelSelection(selectedModel as any);
236
+ window.localStorage.setItem(
237
+ CORTEX_AI_SANDBOX_MODEL_LOCAL_STORAGE,
238
+ JSON.stringify(storedSelection)
239
+ );
240
+ setSandboxModel(storedSelection);
241
+ notifyCortexAiSettingsChanged();
242
+ setSuccessMessage('Sandbox Cortex AI model selection saved to your browser.');
243
+ setTimeout(() => setSuccessMessage(null), 3000);
244
+ } catch (error) {
245
+ console.error('Failed to save sandbox model', error);
246
+ }
247
+ };
248
+
249
+ const handleClearModel = () => {
250
+ try {
251
+ window.localStorage.removeItem(CORTEX_AI_SANDBOX_MODEL_LOCAL_STORAGE);
252
+ setSandboxModel(null);
253
+ setModelInput('');
254
+ notifyCortexAiSettingsChanged();
255
+ setSuccessMessage('Sandbox Cortex AI model selection cleared.');
256
+ setTimeout(() => setSuccessMessage(null), 3000);
257
+ } catch (error) {
258
+ console.error('Failed to clear sandbox model', error);
259
+ }
260
+ };
261
+
262
+ if (!mounted) {
263
+ return null; // Avoid hydration mismatch
264
+ }
265
+
266
+ const selectedModelIsInCatalog = compatibleModels.some(
267
+ (model) => model.id === sandboxModel?.modelId
268
+ );
269
+
270
+ const modelOptions =
271
+ sandboxModel && !selectedModelIsInCatalog
272
+ ? [
273
+ {
274
+ context_length: sandboxModel.contextLength,
275
+ created: null,
276
+ expirationDate: null,
277
+ id: sandboxModel.modelId,
278
+ name: `${sandboxModel.name} (saved)`,
279
+ pricing: sandboxModel.pricing,
280
+ supportedParameters: sandboxModel.supportedParameters,
281
+ },
282
+ ...compatibleModels,
283
+ ]
284
+ : compatibleModels;
285
+
286
+ const canSelectModel = !!sandboxKey && compatibleModels.length > 0;
287
+ const maskedSandboxKey = sandboxKey ? getMaskedKey(sandboxKey) : null;
288
+ const isKeyDirty = inputValue.trim().length > 0;
289
+ const isModelDirty = modelInput !== (sandboxModel?.modelId || '');
290
+
291
+ const searchableOptions = modelOptions.map((model) => ({
292
+ value: model.id,
293
+ label: model.name,
294
+ description: `${model.id} - ${formatModelPricing(model.pricing as any)}`,
295
+ }));
296
+
297
+ const keySourceValue = sandboxKey ? 'Sandbox BYOK' : hasEnvOpenRouterKey ? 'Environment' : 'None';
298
+ // Ordered by preference (Pexels primary, Unsplash fallback). Configured = a
299
+ // stored DB key OR an env var for that provider.
300
+ const configuredStockProviders = [
301
+ hasStoredPexelsKey || hasEnvPexelsKey ? { name: 'Pexels', stored: hasStoredPexelsKey } : null,
302
+ hasStoredUnsplashKey || hasEnvUnsplashKey
303
+ ? { name: 'Unsplash', stored: hasStoredUnsplashKey }
304
+ : null,
305
+ ].filter(Boolean) as Array<{ name: string; stored: boolean }>;
306
+ const stockValue =
307
+ configuredStockProviders.length > 0
308
+ ? configuredStockProviders.map((provider) => provider.name).join(' + ')
309
+ : 'Off';
310
+
311
+ return (
312
+ <div className="mx-auto w-full max-w-5xl space-y-4 px-4 py-6">
313
+ <div className="flex items-center gap-2.5">
314
+ <Brain className="h-6 w-6 text-primary" />
315
+ <div>
316
+ <h1 className="text-xl font-semibold leading-tight">
317
+ NextBlock Cortex AI{' '}
318
+ <Badge variant="secondary" className="ml-1 align-middle font-normal">
319
+ Sandbox
320
+ </Badge>
321
+ </h1>
322
+ <p className="text-xs text-muted-foreground">
323
+ Manage the OpenRouter model key used by Cortex AI in your own browser session.
324
+ </p>
325
+ </div>
326
+ </div>
327
+
328
+ {successMessage && (
329
+ <Alert variant="success">
330
+ <CheckCircle2 className="h-4 w-4" />
331
+ <AlertTitle>Saved</AlertTitle>
332
+ <AlertDescription>{successMessage}</AlertDescription>
333
+ </Alert>
334
+ )}
335
+
336
+ {/* Compact status strip */}
337
+ <div className="flex flex-wrap gap-2">
338
+ <StatusPill
339
+ label="Package"
340
+ value={isPackageActive ? 'Active' : 'Inactive'}
341
+ active={isPackageActive}
342
+ />
343
+ <StatusPill
344
+ label="Model key"
345
+ value={keySourceValue}
346
+ active={Boolean(sandboxKey) || hasEnvOpenRouterKey}
347
+ detail={maskedSandboxKey || maskedEnvOpenRouterKey}
348
+ />
349
+ <StatusPill
350
+ label="Model"
351
+ value={sandboxModel ? sandboxModel.name : 'Free registry'}
352
+ active={Boolean(sandboxModel)}
353
+ />
354
+ <StatusPill
355
+ label="Stock photos"
356
+ value={stockValue}
357
+ active={Boolean(activeStockProvider)}
358
+ />
359
+ </div>
360
+
361
+ <Alert
362
+ variant="warning"
363
+ className="border-amber-200 bg-amber-50 text-amber-900 dark:border-amber-800 dark:bg-amber-950/30 dark:text-amber-200"
364
+ >
365
+ <Info className="h-4 w-4" />
366
+ <AlertTitle>Sandbox environment active</AlertTitle>
367
+ <AlertDescription>
368
+ The key and model you set here are stored{' '}
369
+ <strong>only in your own browser (localStorage)</strong> and are never written to the
370
+ shared sandbox database. Server-backed settings below are read-only here.
371
+ </AlertDescription>
372
+ </Alert>
373
+
374
+ {hasEnvOpenRouterKey && !sandboxKey && (
375
+ <Alert>
376
+ <KeyRound className="h-4 w-4" />
377
+ <AlertTitle>Free-model lock active</AlertTitle>
378
+ <AlertDescription>
379
+ Cortex AI will only use the configured free OpenRouter models until you save a sandbox
380
+ key to your browser.
381
+ </AlertDescription>
382
+ </Alert>
383
+ )}
384
+
385
+ {/* OpenRouter BYOK + Model side by side */}
386
+ <div className="grid gap-4 lg:grid-cols-2">
387
+ <Card>
388
+ <CardHeader className="flex flex-row items-start justify-between space-y-0 pb-3">
389
+ <div>
390
+ <CardTitle className="text-base">OpenRouter key</CardTitle>
391
+ <CardDescription className="text-xs">
392
+ Saved to your browser only, never uploaded.
393
+ </CardDescription>
394
+ </div>
395
+ {sandboxKey && (
396
+ <Button
397
+ type="button"
398
+ onClick={handleClearKey}
399
+ variant="ghost"
400
+ size="sm"
401
+ className="h-7 text-destructive hover:text-destructive"
402
+ >
403
+ <Trash2 className="mr-1.5 h-3.5 w-3.5" />
404
+ Clear
405
+ </Button>
406
+ )}
407
+ </CardHeader>
408
+ <CardContent className="pt-0">
409
+ <form onSubmit={handleSaveKey} className="flex items-end gap-2">
410
+ <div className="flex-1 space-y-1.5">
411
+ <Label htmlFor="openrouter_api_key" className="text-xs">
412
+ API key
413
+ </Label>
414
+ <Input
415
+ id="openrouter_api_key"
416
+ name="openrouter_api_key"
417
+ type="password"
418
+ autoComplete="off"
419
+ minLength={12}
420
+ placeholder={sandboxKey ? 'Enter new key to overwrite...' : 'sk-or-v1-...'}
421
+ value={inputValue}
422
+ onChange={(e) => setInputValue(e.target.value)}
423
+ required
424
+ />
425
+ </div>
426
+ <Button type="submit" disabled={!isKeyDirty} size="sm">
427
+ <KeyRound className="mr-1.5 h-3.5 w-3.5" />
428
+ Save
429
+ </Button>
430
+ </form>
431
+ </CardContent>
432
+ </Card>
433
+
434
+ <Card>
435
+ <CardHeader className="flex flex-row items-start justify-between space-y-0 pb-3">
436
+ <div>
437
+ <CardTitle className="text-base">OpenRouter model</CardTitle>
438
+ <CardDescription className="text-xs">
439
+ Needs a sandbox key; supports tools + structured output.
440
+ </CardDescription>
441
+ </div>
442
+ {sandboxModel && (
443
+ <Button
444
+ type="button"
445
+ onClick={handleClearModel}
446
+ variant="ghost"
447
+ size="sm"
448
+ className="h-7 text-destructive hover:text-destructive"
449
+ >
450
+ <Trash2 className="mr-1.5 h-3.5 w-3.5" />
451
+ Clear
452
+ </Button>
453
+ )}
454
+ </CardHeader>
455
+ <CardContent className="space-y-2 pt-0">
456
+ {modelCatalogError && (
457
+ <Alert variant="warning">
458
+ <AlertTriangle className="h-4 w-4" />
459
+ <AlertTitle>Model catalog unavailable</AlertTitle>
460
+ <AlertDescription>{modelCatalogError}</AlertDescription>
461
+ </Alert>
462
+ )}
463
+ <form onSubmit={handleSaveModel} className="flex items-end gap-2">
464
+ <input type="hidden" name="openrouter_model_id" value={modelInput} />
465
+ <div className="flex-1 space-y-1.5">
466
+ <Label htmlFor="openrouter_model_id_select" className="text-xs">
467
+ Model
468
+ </Label>
469
+ <SearchableSelect
470
+ options={searchableOptions}
471
+ value={modelInput}
472
+ onChange={(val) => setModelInput(val)}
473
+ disabled={!canSelectModel}
474
+ placeholder="Select a compatible model..."
475
+ />
476
+ </div>
477
+ <Button type="submit" disabled={!canSelectModel || !isModelDirty} size="sm">
478
+ <Cpu className="mr-1.5 h-3.5 w-3.5" />
479
+ Save
480
+ </Button>
481
+ </form>
482
+ <p className="text-[11px] text-muted-foreground">
483
+ {canSelectModel
484
+ ? `${compatibleModels.length} compatible models available.`
485
+ : 'Cortex AI uses the free registry until a sandbox key + model are set.'}
486
+ </p>
487
+ </CardContent>
488
+ </Card>
489
+ </div>
490
+
491
+ {/* Stock photos - read-only in sandbox */}
492
+ <Card>
493
+ <CardHeader className="pb-3">
494
+ <CardTitle className="flex flex-wrap items-center gap-2 text-base">
495
+ <ImageIcon className="h-4 w-4" />
496
+ Stock photos
497
+ {configuredStockProviders.length > 0 ? (
498
+ configuredStockProviders.map((provider, index) => (
499
+ <Badge
500
+ key={provider.name}
501
+ variant={index === 0 ? 'default' : 'secondary'}
502
+ className="ml-0.5 font-normal"
503
+ >
504
+ {provider.name} · {index === 0 ? 'primary' : 'fallback'}
505
+ {!provider.stored && ' (env)'}
506
+ </Badge>
507
+ ))
508
+ ) : (
509
+ <Badge variant="outline" className="ml-0.5">
510
+ Not configured
511
+ </Badge>
512
+ )}
513
+ <Badge variant="outline" className="ml-auto gap-1 font-normal">
514
+ <Lock className="h-3 w-3" />
515
+ Read-only
516
+ </Badge>
517
+ </CardTitle>
518
+ <CardDescription className="text-xs">
519
+ A Pexels/Unsplash key lets Cortex insert real photos into pages. Pexels is used first;
520
+ Cortex automatically falls back to Unsplash if Pexels is rate-limited.
521
+ </CardDescription>
522
+ </CardHeader>
523
+ <CardContent className="space-y-4 pt-0">
524
+ <div className="grid gap-4 md:grid-cols-2">
525
+ <div className="rounded-md border bg-muted/20 p-3 text-sm">
526
+ <p className="font-medium">What this does</p>
527
+ <p className="mt-1 text-xs text-muted-foreground">
528
+ When you ask Cortex to build or revamp a page, a stock key lets it fetch relevant,
529
+ high-quality photos for the hero and sections automatically — instant, zero
530
+ image-generation cost, and you can save any photo into your media library with one
531
+ click. Without a key Cortex still builds pages, but uses gradient/theme backgrounds
532
+ instead of photos, and it will not call the photo tool at all.
533
+ </p>
534
+ <p className="mt-3 text-[11px] text-muted-foreground">
535
+ In your own NextBlock install you add these keys on this page and they are encrypted
536
+ into your database. In the shared sandbox they are provided by the host environment
537
+ and cannot be changed.
538
+ </p>
539
+ </div>
540
+
541
+ <div className="space-y-2">
542
+ <ReadOnlyRow
543
+ label="Pexels API key"
544
+ value={
545
+ hasStoredPexelsKey
546
+ ? 'Configured (stored)'
547
+ : hasEnvPexelsKey
548
+ ? 'Configured (env)'
549
+ : 'Not set'
550
+ }
551
+ detail={maskedStoredPexelsKey}
552
+ />
553
+ <ReadOnlyRow
554
+ label="Unsplash Access key"
555
+ value={
556
+ hasStoredUnsplashKey
557
+ ? 'Configured (stored)'
558
+ : hasEnvUnsplashKey
559
+ ? 'Configured (env)'
560
+ : 'Not set'
561
+ }
562
+ detail={maskedStoredUnsplashKey}
563
+ />
564
+ <ReadOnlyRow label="Unsplash app name" value={unsplashAppName || 'Not set'} />
565
+ <p className="text-[11px] text-muted-foreground">
566
+ {configuredStockProviders.length > 0
567
+ ? `Using ${configuredStockProviders.map((provider) => provider.name).join(', ')}.`
568
+ : 'No provider configured in this sandbox.'}
569
+ </p>
570
+ </div>
571
+ </div>
572
+ </CardContent>
573
+ </Card>
574
+
575
+ {/* Advanced settings (collapsed by default) - read-only in sandbox */}
576
+ <div>
577
+ <button
578
+ type="button"
579
+ onClick={() => setShowAdvanced((open) => !open)}
580
+ className="flex w-full items-center gap-2 rounded-md border bg-muted/20 px-3 py-2 text-left text-sm font-medium hover:bg-muted/40"
581
+ >
582
+ <SlidersHorizontal className="h-4 w-4" />
583
+ Advanced settings
584
+ <span className="ml-auto text-xs text-muted-foreground">
585
+ {agentSettings.maxOutputTokens === null
586
+ ? 'Unlimited output'
587
+ : `${agentSettings.maxOutputTokens} tokens`}{' '}
588
+ · {agentSettings.maxSteps} steps
589
+ </span>
590
+ {showAdvanced ? (
591
+ <ChevronDown className="h-4 w-4" />
592
+ ) : (
593
+ <ChevronRight className="h-4 w-4" />
594
+ )}
595
+ </button>
596
+
597
+ {showAdvanced && (
598
+ <Card className="mt-2">
599
+ <CardHeader className="pb-3">
600
+ <CardTitle className="flex items-center gap-2 text-base">
601
+ Agent tuning
602
+ <Badge variant="outline" className="gap-1 font-normal">
603
+ <Lock className="h-3 w-3" />
604
+ Read-only
605
+ </Badge>
606
+ </CardTitle>
607
+ <CardDescription className="text-xs">
608
+ Controls how much room the page-building agent has. These are set by the sandbox host
609
+ and shared by every visitor, so they cannot be edited here.
610
+ </CardDescription>
611
+ </CardHeader>
612
+ <CardContent className="space-y-4 pt-0">
613
+ <div className="grid gap-4 sm:grid-cols-2">
614
+ <div className="space-y-1.5">
615
+ <Label htmlFor="max_output_tokens" className="text-xs">
616
+ Max output tokens per step
617
+ </Label>
618
+ <Input
619
+ id="max_output_tokens"
620
+ type="text"
621
+ value={
622
+ agentSettings.maxOutputTokens === null
623
+ ? 'Unlimited'
624
+ : String(agentSettings.maxOutputTokens)
625
+ }
626
+ readOnly
627
+ disabled
628
+ />
629
+ <p className="text-[11px] text-muted-foreground">
630
+ The per-step output budget. Range 256–200,000, or Unlimited. Default 16,000.
631
+ </p>
632
+ </div>
633
+ <div className="space-y-1.5">
634
+ <Label htmlFor="max_steps" className="text-xs">
635
+ Max tool steps
636
+ </Label>
637
+ <Input
638
+ id="max_steps"
639
+ type="text"
640
+ value={String(agentSettings.maxSteps)}
641
+ readOnly
642
+ disabled
643
+ />
644
+ <p className="text-[11px] text-muted-foreground">
645
+ Range 2–100 tool-call rounds. Default 8; each step is one model call.
646
+ </p>
647
+ </div>
648
+ <div className="space-y-1.5">
649
+ <Label htmlFor="temperature" className="text-xs">
650
+ Temperature
651
+ </Label>
652
+ <Input
653
+ id="temperature"
654
+ type="text"
655
+ value={String(agentSettings.temperature)}
656
+ readOnly
657
+ disabled
658
+ />
659
+ <p className="text-[11px] text-muted-foreground">
660
+ Range 0–2. Cortex default 0.1 (low = reliable; most models default higher).
661
+ </p>
662
+ </div>
663
+ <div className="space-y-1.5">
664
+ <Label htmlFor="response_timeout_seconds" className="text-xs">
665
+ Response timeout (seconds)
666
+ </Label>
667
+ <Input
668
+ id="response_timeout_seconds"
669
+ type="text"
670
+ value={String(Math.round(agentSettings.responseTimeoutMs / 1000))}
671
+ readOnly
672
+ disabled
673
+ />
674
+ <p className="text-[11px] text-muted-foreground">
675
+ Range 15–600s. Default 120; aborts only after this long with no activity.
676
+ </p>
677
+ </div>
678
+ </div>
679
+ <p className="text-[11px] text-muted-foreground">
680
+ Applies to the global page-building agent. Editable on a self-hosted install.
681
+ </p>
682
+ </CardContent>
683
+ </Card>
684
+ )}
685
+ </div>
686
+ </div>
687
+ );
688
+ }