corporateai 0.0.1

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 (704) hide show
  1. package/.dockerignore +10 -0
  2. package/.env.example +3 -0
  3. package/.github/workflows/publish-cli.yml +49 -0
  4. package/.mailmap +1 -0
  5. package/AGENTS.md +148 -0
  6. package/CONTRIBUTING.md +75 -0
  7. package/Dockerfile +59 -0
  8. package/Dockerfile.onboard-smoke +42 -0
  9. package/LICENSE +21 -0
  10. package/README.md +93 -0
  11. package/cli/esbuild.config.mjs +11 -0
  12. package/cli/package.json +24 -0
  13. package/cli/scripts/build-cli.mjs +5 -0
  14. package/cli/src/index.ts +27 -0
  15. package/docker-compose.quickstart.yml +18 -0
  16. package/docker-compose.untrusted-review.yml +33 -0
  17. package/docker-compose.yml +38 -0
  18. package/package.json +56 -0
  19. package/patches/embedded-postgres@18.1.0-beta.16.patch +0 -0
  20. package/pnpm-workspace.yaml +4 -0
  21. package/releases/.gitkeep +0 -0
  22. package/releases/v0.0.1.md +36 -0
  23. package/releases/v0.2.7.md +15 -0
  24. package/releases/v0.3.0.md +54 -0
  25. package/releases/v0.3.1.md +55 -0
  26. package/releases/v2026.318.0.md +66 -0
  27. package/releases/v2026.325.0.md +78 -0
  28. package/report/2026-03-13-08-46-token-optimization-implementation.md +48 -0
  29. package/scripts/backup-db.sh +17 -0
  30. package/scripts/build-npm.sh +80 -0
  31. package/scripts/check-forbidden-tokens.mjs +115 -0
  32. package/scripts/clean-onboard-git.sh +14 -0
  33. package/scripts/clean-onboard-npm.sh +13 -0
  34. package/scripts/clean-onboard-ref.sh +86 -0
  35. package/scripts/create-github-release.sh +99 -0
  36. package/scripts/dev-runner-paths.mjs +38 -0
  37. package/scripts/dev-runner.mjs +606 -0
  38. package/scripts/docker-onboard-smoke.sh +306 -0
  39. package/scripts/ensure-plugin-build-deps.mjs +47 -0
  40. package/scripts/generate-company-assets.ts +365 -0
  41. package/scripts/generate-npm-package-json.mjs +113 -0
  42. package/scripts/generate-org-chart-images.ts +694 -0
  43. package/scripts/generate-org-chart-satori-comparison.ts +225 -0
  44. package/scripts/generate-ui-package-json.mjs +31 -0
  45. package/scripts/kill-dev.sh +71 -0
  46. package/scripts/migrate-inline-env-secrets.ts +126 -0
  47. package/scripts/prepare-server-ui-dist.sh +22 -0
  48. package/scripts/provision-worktree.sh +333 -0
  49. package/scripts/release-lib.sh +306 -0
  50. package/scripts/release-package-map.mjs +169 -0
  51. package/scripts/release.sh +312 -0
  52. package/scripts/rollback-latest.sh +111 -0
  53. package/scripts/smoke/openclaw-docker-ui.sh +329 -0
  54. package/scripts/smoke/openclaw-gateway-e2e.sh +954 -0
  55. package/scripts/smoke/openclaw-join.sh +295 -0
  56. package/scripts/smoke/openclaw-sse-standalone.sh +146 -0
  57. package/scripts/workspace-compat.mjs +60 -0
  58. package/server/CHANGELOG.md +130 -0
  59. package/server/package.json +96 -0
  60. package/server/scripts/copy-onboarding-assets.mjs +10 -0
  61. package/server/scripts/dev-watch.ts +33 -0
  62. package/server/src/__tests__/activity-routes.test.ts +70 -0
  63. package/server/src/__tests__/adapter-models.test.ts +105 -0
  64. package/server/src/__tests__/adapter-session-codecs.test.ts +194 -0
  65. package/server/src/__tests__/agent-auth-jwt.test.ts +79 -0
  66. package/server/src/__tests__/agent-instructions-routes.test.ts +318 -0
  67. package/server/src/__tests__/agent-instructions-service.test.ts +361 -0
  68. package/server/src/__tests__/agent-permissions-routes.test.ts +275 -0
  69. package/server/src/__tests__/agent-shortname-collision.test.ts +69 -0
  70. package/server/src/__tests__/agent-skill-contract.test.ts +50 -0
  71. package/server/src/__tests__/agent-skills-routes.test.ts +462 -0
  72. package/server/src/__tests__/app-hmr-port.test.ts +19 -0
  73. package/server/src/__tests__/approval-routes-idempotency.test.ts +110 -0
  74. package/server/src/__tests__/approvals-service.test.ts +107 -0
  75. package/server/src/__tests__/assets.test.ts +250 -0
  76. package/server/src/__tests__/attachment-types.test.ts +97 -0
  77. package/server/src/__tests__/board-mutation-guard.test.ts +105 -0
  78. package/server/src/__tests__/budgets-service.test.ts +311 -0
  79. package/server/src/__tests__/claude-local-adapter-environment.test.ts +92 -0
  80. package/server/src/__tests__/claude-local-adapter.test.ts +31 -0
  81. package/server/src/__tests__/claude-local-skill-sync.test.ts +111 -0
  82. package/server/src/__tests__/cli-auth-routes.test.ts +230 -0
  83. package/server/src/__tests__/codex-local-adapter-environment.test.ts +143 -0
  84. package/server/src/__tests__/codex-local-adapter.test.ts +253 -0
  85. package/server/src/__tests__/codex-local-execute.test.ts +391 -0
  86. package/server/src/__tests__/codex-local-skill-injection.test.ts +175 -0
  87. package/server/src/__tests__/codex-local-skill-sync.test.ts +123 -0
  88. package/server/src/__tests__/companies-route-path-guard.test.ts +56 -0
  89. package/server/src/__tests__/company-branding-route.test.ts +196 -0
  90. package/server/src/__tests__/company-portability-routes.test.ts +175 -0
  91. package/server/src/__tests__/company-portability.test.ts +2186 -0
  92. package/server/src/__tests__/company-skills-routes.test.ts +113 -0
  93. package/server/src/__tests__/company-skills.test.ts +229 -0
  94. package/server/src/__tests__/costs-service.test.ts +226 -0
  95. package/server/src/__tests__/cursor-local-adapter-environment.test.ts +196 -0
  96. package/server/src/__tests__/cursor-local-adapter.test.ts +406 -0
  97. package/server/src/__tests__/cursor-local-execute.test.ts +263 -0
  98. package/server/src/__tests__/cursor-local-skill-injection.test.ts +104 -0
  99. package/server/src/__tests__/cursor-local-skill-sync.test.ts +145 -0
  100. package/server/src/__tests__/dev-runner-paths.test.ts +25 -0
  101. package/server/src/__tests__/dev-server-status.test.ts +66 -0
  102. package/server/src/__tests__/dev-watch-ignore.test.ts +42 -0
  103. package/server/src/__tests__/documents.test.ts +29 -0
  104. package/server/src/__tests__/error-handler.test.ts +53 -0
  105. package/server/src/__tests__/execution-workspace-policy.test.ts +170 -0
  106. package/server/src/__tests__/forbidden-tokens.test.ts +77 -0
  107. package/server/src/__tests__/gemini-local-adapter-environment.test.ts +135 -0
  108. package/server/src/__tests__/gemini-local-adapter.test.ts +190 -0
  109. package/server/src/__tests__/gemini-local-execute.test.ts +172 -0
  110. package/server/src/__tests__/gemini-local-skill-sync.test.ts +90 -0
  111. package/server/src/__tests__/health.test.ts +16 -0
  112. package/server/src/__tests__/heartbeat-process-recovery.test.ts +256 -0
  113. package/server/src/__tests__/heartbeat-run-summary.test.ts +33 -0
  114. package/server/src/__tests__/heartbeat-workspace-session.test.ts +334 -0
  115. package/server/src/__tests__/helpers/embedded-postgres.ts +7 -0
  116. package/server/src/__tests__/hire-hook.test.ts +181 -0
  117. package/server/src/__tests__/instance-settings-routes.test.ts +156 -0
  118. package/server/src/__tests__/invite-accept-gateway-defaults.test.ts +119 -0
  119. package/server/src/__tests__/invite-accept-replay.test.ts +92 -0
  120. package/server/src/__tests__/invite-expiry.test.ts +10 -0
  121. package/server/src/__tests__/invite-join-grants.test.ts +57 -0
  122. package/server/src/__tests__/invite-join-manager.test.ts +33 -0
  123. package/server/src/__tests__/invite-onboarding-text.test.ts +116 -0
  124. package/server/src/__tests__/issue-comment-reopen-routes.test.ts +146 -0
  125. package/server/src/__tests__/issue-goal-fallback.test.ts +99 -0
  126. package/server/src/__tests__/issues-checkout-wakeup.test.ts +48 -0
  127. package/server/src/__tests__/issues-goal-context-routes.test.ts +187 -0
  128. package/server/src/__tests__/issues-service.test.ts +317 -0
  129. package/server/src/__tests__/issues-user-context.test.ts +113 -0
  130. package/server/src/__tests__/log-redaction.test.ts +74 -0
  131. package/server/src/__tests__/monthly-spend-service.test.ts +90 -0
  132. package/server/src/__tests__/normalize-agent-mention-token.test.ts +41 -0
  133. package/server/src/__tests__/openclaw-gateway-adapter.test.ts +626 -0
  134. package/server/src/__tests__/openclaw-invite-prompt-route.test.ts +192 -0
  135. package/server/src/__tests__/opencode-local-adapter-environment.test.ts +97 -0
  136. package/server/src/__tests__/opencode-local-adapter.test.ts +226 -0
  137. package/server/src/__tests__/opencode-local-skill-sync.test.ts +91 -0
  138. package/server/src/__tests__/paperclip-env.test.ts +58 -0
  139. package/server/src/__tests__/paperclip-skill-utils.test.ts +63 -0
  140. package/server/src/__tests__/pi-local-adapter-environment.test.ts +102 -0
  141. package/server/src/__tests__/pi-local-skill-sync.test.ts +95 -0
  142. package/server/src/__tests__/plugin-dev-watcher.test.ts +68 -0
  143. package/server/src/__tests__/plugin-worker-manager.test.ts +43 -0
  144. package/server/src/__tests__/private-hostname-guard.test.ts +56 -0
  145. package/server/src/__tests__/project-shortname-resolution.test.ts +45 -0
  146. package/server/src/__tests__/quota-windows-service.test.ts +56 -0
  147. package/server/src/__tests__/quota-windows.test.ts +1109 -0
  148. package/server/src/__tests__/redaction.test.ts +66 -0
  149. package/server/src/__tests__/routines-e2e.test.ts +276 -0
  150. package/server/src/__tests__/routines-routes.test.ts +271 -0
  151. package/server/src/__tests__/routines-service.test.ts +424 -0
  152. package/server/src/__tests__/storage-local-provider.test.ts +78 -0
  153. package/server/src/__tests__/ui-branding.test.ts +82 -0
  154. package/server/src/__tests__/work-products.test.ts +95 -0
  155. package/server/src/__tests__/workspace-runtime.test.ts +1131 -0
  156. package/server/src/__tests__/worktree-config.test.ts +426 -0
  157. package/server/src/adapters/codex-models.ts +105 -0
  158. package/server/src/adapters/cursor-models.ts +171 -0
  159. package/server/src/adapters/http/execute.ts +42 -0
  160. package/server/src/adapters/http/index.ts +21 -0
  161. package/server/src/adapters/http/test.ts +116 -0
  162. package/server/src/adapters/index.ts +18 -0
  163. package/server/src/adapters/process/execute.ts +77 -0
  164. package/server/src/adapters/process/index.ts +24 -0
  165. package/server/src/adapters/process/test.ts +89 -0
  166. package/server/src/adapters/registry.ts +225 -0
  167. package/server/src/adapters/server-utils-compat.ts +57 -0
  168. package/server/src/adapters/types.ts +30 -0
  169. package/server/src/adapters/utils.ts +48 -0
  170. package/server/src/agent-auth-jwt.ts +141 -0
  171. package/server/src/app.ts +321 -0
  172. package/server/src/attachment-types.ts +74 -0
  173. package/server/src/auth/better-auth.ts +148 -0
  174. package/server/src/board-claim.ts +150 -0
  175. package/server/src/config-file.ts +17 -0
  176. package/server/src/config.ts +260 -0
  177. package/server/src/dev-server-status.ts +103 -0
  178. package/server/src/dev-watch-ignore.ts +36 -0
  179. package/server/src/errors.ts +34 -0
  180. package/server/src/home-paths.ts +95 -0
  181. package/server/src/index.ts +799 -0
  182. package/server/src/log-redaction.ts +146 -0
  183. package/server/src/middleware/auth.ts +178 -0
  184. package/server/src/middleware/board-mutation-guard.ts +66 -0
  185. package/server/src/middleware/error-handler.ts +71 -0
  186. package/server/src/middleware/index.ts +3 -0
  187. package/server/src/middleware/logger.ts +90 -0
  188. package/server/src/middleware/private-hostname-guard.ts +92 -0
  189. package/server/src/middleware/validate.ts +9 -0
  190. package/server/src/onboarding-assets/ceo/AGENTS.md +54 -0
  191. package/server/src/onboarding-assets/ceo/HEARTBEAT.md +72 -0
  192. package/server/src/onboarding-assets/ceo/SOUL.md +33 -0
  193. package/server/src/onboarding-assets/ceo/TOOLS.md +3 -0
  194. package/server/src/onboarding-assets/default/AGENTS.md +3 -0
  195. package/server/src/paths.ts +34 -0
  196. package/server/src/realtime/live-events-ws.ts +274 -0
  197. package/server/src/redaction.ts +59 -0
  198. package/server/src/routes/access.ts +2888 -0
  199. package/server/src/routes/activity.ts +89 -0
  200. package/server/src/routes/agents.ts +2313 -0
  201. package/server/src/routes/approvals.ts +346 -0
  202. package/server/src/routes/assets.ts +341 -0
  203. package/server/src/routes/authz.ts +52 -0
  204. package/server/src/routes/companies.ts +343 -0
  205. package/server/src/routes/company-skills.ts +300 -0
  206. package/server/src/routes/costs.ts +335 -0
  207. package/server/src/routes/dashboard.ts +19 -0
  208. package/server/src/routes/execution-workspaces.ts +182 -0
  209. package/server/src/routes/goals.ts +107 -0
  210. package/server/src/routes/health.ts +94 -0
  211. package/server/src/routes/index.ts +17 -0
  212. package/server/src/routes/instance-settings.ts +95 -0
  213. package/server/src/routes/issues-checkout-wakeup.ts +14 -0
  214. package/server/src/routes/issues.ts +1680 -0
  215. package/server/src/routes/llms.ts +86 -0
  216. package/server/src/routes/org-chart-svg.ts +777 -0
  217. package/server/src/routes/plugin-ui-static.ts +497 -0
  218. package/server/src/routes/plugins.ts +2220 -0
  219. package/server/src/routes/projects.ts +295 -0
  220. package/server/src/routes/routines.ts +300 -0
  221. package/server/src/routes/secrets.ts +166 -0
  222. package/server/src/routes/sidebar-badges.ts +52 -0
  223. package/server/src/secrets/external-stub-providers.ts +32 -0
  224. package/server/src/secrets/local-encrypted-provider.ts +135 -0
  225. package/server/src/secrets/provider-registry.ts +31 -0
  226. package/server/src/secrets/types.ts +23 -0
  227. package/server/src/services/access.ts +381 -0
  228. package/server/src/services/activity-log.ts +95 -0
  229. package/server/src/services/activity.ts +164 -0
  230. package/server/src/services/agent-instructions.ts +735 -0
  231. package/server/src/services/agent-permissions.ts +27 -0
  232. package/server/src/services/agents.ts +694 -0
  233. package/server/src/services/approvals.ts +273 -0
  234. package/server/src/services/assets.ts +23 -0
  235. package/server/src/services/board-auth.ts +355 -0
  236. package/server/src/services/budgets.ts +959 -0
  237. package/server/src/services/companies.ts +313 -0
  238. package/server/src/services/company-export-readme.ts +173 -0
  239. package/server/src/services/company-portability.ts +4263 -0
  240. package/server/src/services/company-skills.ts +2356 -0
  241. package/server/src/services/costs.ts +365 -0
  242. package/server/src/services/cron.ts +373 -0
  243. package/server/src/services/dashboard.ts +110 -0
  244. package/server/src/services/default-agent-instructions.ts +27 -0
  245. package/server/src/services/documents.ts +434 -0
  246. package/server/src/services/execution-workspace-policy.ts +210 -0
  247. package/server/src/services/execution-workspaces.ts +100 -0
  248. package/server/src/services/finance.ts +135 -0
  249. package/server/src/services/goals.ts +81 -0
  250. package/server/src/services/heartbeat-run-summary.ts +35 -0
  251. package/server/src/services/heartbeat.ts +3863 -0
  252. package/server/src/services/hire-hook.ts +114 -0
  253. package/server/src/services/index.ts +32 -0
  254. package/server/src/services/instance-settings.ts +138 -0
  255. package/server/src/services/issue-approvals.ts +175 -0
  256. package/server/src/services/issue-assignment-wakeup.ts +48 -0
  257. package/server/src/services/issue-goal-fallback.ts +56 -0
  258. package/server/src/services/issues.ts +1828 -0
  259. package/server/src/services/live-events.ts +55 -0
  260. package/server/src/services/plugin-capability-validator.ts +450 -0
  261. package/server/src/services/plugin-config-validator.ts +55 -0
  262. package/server/src/services/plugin-dev-watcher.ts +339 -0
  263. package/server/src/services/plugin-event-bus.ts +413 -0
  264. package/server/src/services/plugin-host-service-cleanup.ts +59 -0
  265. package/server/src/services/plugin-host-services.ts +1132 -0
  266. package/server/src/services/plugin-job-coordinator.ts +261 -0
  267. package/server/src/services/plugin-job-scheduler.ts +753 -0
  268. package/server/src/services/plugin-job-store.ts +466 -0
  269. package/server/src/services/plugin-lifecycle.ts +822 -0
  270. package/server/src/services/plugin-loader.ts +1955 -0
  271. package/server/src/services/plugin-log-retention.ts +87 -0
  272. package/server/src/services/plugin-manifest-validator.ts +164 -0
  273. package/server/src/services/plugin-registry.ts +683 -0
  274. package/server/src/services/plugin-runtime-sandbox.ts +222 -0
  275. package/server/src/services/plugin-secrets-handler.ts +355 -0
  276. package/server/src/services/plugin-state-store.ts +238 -0
  277. package/server/src/services/plugin-stream-bus.ts +81 -0
  278. package/server/src/services/plugin-tool-dispatcher.ts +449 -0
  279. package/server/src/services/plugin-tool-registry.ts +450 -0
  280. package/server/src/services/plugin-worker-manager.ts +1343 -0
  281. package/server/src/services/projects.ts +860 -0
  282. package/server/src/services/quota-windows.ts +65 -0
  283. package/server/src/services/routines.ts +1269 -0
  284. package/server/src/services/run-log-store.ts +156 -0
  285. package/server/src/services/secrets.ts +370 -0
  286. package/server/src/services/sidebar-badges.ts +56 -0
  287. package/server/src/services/work-products.ts +124 -0
  288. package/server/src/services/workspace-operation-log-store.ts +156 -0
  289. package/server/src/services/workspace-operations.ts +262 -0
  290. package/server/src/services/workspace-runtime.ts +1565 -0
  291. package/server/src/startup-banner.ts +176 -0
  292. package/server/src/storage/index.ts +35 -0
  293. package/server/src/storage/local-disk-provider.ts +89 -0
  294. package/server/src/storage/provider-registry.ts +18 -0
  295. package/server/src/storage/s3-provider.ts +153 -0
  296. package/server/src/storage/service.ts +131 -0
  297. package/server/src/storage/types.ts +63 -0
  298. package/server/src/ui-branding.ts +217 -0
  299. package/server/src/version.ts +10 -0
  300. package/server/src/worktree-config.ts +468 -0
  301. package/server/tsconfig.json +9 -0
  302. package/server/vitest.config.ts +7 -0
  303. package/skills/paperclip/SKILL.md +365 -0
  304. package/skills/paperclip/references/api-reference.md +647 -0
  305. package/skills/paperclip/references/company-skills.md +193 -0
  306. package/skills/paperclip-create-agent/SKILL.md +142 -0
  307. package/skills/paperclip-create-agent/references/api-reference.md +105 -0
  308. package/skills/paperclip-create-plugin/SKILL.md +102 -0
  309. package/skills/para-memory-files/SKILL.md +104 -0
  310. package/skills/para-memory-files/references/schemas.md +35 -0
  311. package/tests/e2e/onboarding.spec.ts +142 -0
  312. package/tests/e2e/playwright.config.ts +35 -0
  313. package/tests/release-smoke/docker-auth-onboarding.spec.ts +141 -0
  314. package/tests/release-smoke/playwright.config.ts +28 -0
  315. package/tsconfig.base.json +18 -0
  316. package/tsconfig.json +18 -0
  317. package/ui/README.md +12 -0
  318. package/ui/components.json +21 -0
  319. package/ui/index.html +47 -0
  320. package/ui/package.json +73 -0
  321. package/ui/public/android-chrome-192x192.png +0 -0
  322. package/ui/public/android-chrome-512x512.png +0 -0
  323. package/ui/public/apple-touch-icon.png +0 -0
  324. package/ui/public/brands/opencode-logo-dark-square.svg +18 -0
  325. package/ui/public/brands/opencode-logo-light-square.svg +18 -0
  326. package/ui/public/favicon-16x16.png +0 -0
  327. package/ui/public/favicon-32x32.png +0 -0
  328. package/ui/public/favicon.ico +0 -0
  329. package/ui/public/favicon.svg +9 -0
  330. package/ui/public/site.webmanifest +30 -0
  331. package/ui/public/sprites/1-D-1.png +0 -0
  332. package/ui/public/sprites/1-D-2.png +0 -0
  333. package/ui/public/sprites/1-D-3.png +0 -0
  334. package/ui/public/sprites/1-L-1.png +0 -0
  335. package/ui/public/sprites/1-R-1.png +0 -0
  336. package/ui/public/sprites/10-D-1.png +0 -0
  337. package/ui/public/sprites/10-D-2.png +0 -0
  338. package/ui/public/sprites/10-D-3.png +0 -0
  339. package/ui/public/sprites/10-L-1.png +0 -0
  340. package/ui/public/sprites/10-R-1.png +0 -0
  341. package/ui/public/sprites/11-D-1.png +0 -0
  342. package/ui/public/sprites/11-D-2.png +0 -0
  343. package/ui/public/sprites/11-D-3.png +0 -0
  344. package/ui/public/sprites/11-L-1.png +0 -0
  345. package/ui/public/sprites/11-R-1.png +0 -0
  346. package/ui/public/sprites/12-D-1.png +0 -0
  347. package/ui/public/sprites/12-D-2.png +0 -0
  348. package/ui/public/sprites/12-D-3.png +0 -0
  349. package/ui/public/sprites/12-L-1.png +0 -0
  350. package/ui/public/sprites/12-R-1.png +0 -0
  351. package/ui/public/sprites/13-D-1.png +0 -0
  352. package/ui/public/sprites/13-D-2.png +0 -0
  353. package/ui/public/sprites/13-D-3.png +0 -0
  354. package/ui/public/sprites/13-L-1.png +0 -0
  355. package/ui/public/sprites/13-R-1.png +0 -0
  356. package/ui/public/sprites/14-D-1.png +0 -0
  357. package/ui/public/sprites/14-D-2.png +0 -0
  358. package/ui/public/sprites/14-D-3.png +0 -0
  359. package/ui/public/sprites/14-L-1.png +0 -0
  360. package/ui/public/sprites/14-R-1.png +0 -0
  361. package/ui/public/sprites/2-D-1.png +0 -0
  362. package/ui/public/sprites/2-D-2.png +0 -0
  363. package/ui/public/sprites/2-D-3.png +0 -0
  364. package/ui/public/sprites/2-L-1.png +0 -0
  365. package/ui/public/sprites/2-R-1.png +0 -0
  366. package/ui/public/sprites/3-D-1.png +0 -0
  367. package/ui/public/sprites/3-D-2.png +0 -0
  368. package/ui/public/sprites/3-D-3.png +0 -0
  369. package/ui/public/sprites/3-L-1.png +0 -0
  370. package/ui/public/sprites/3-R-1.png +0 -0
  371. package/ui/public/sprites/4-D-1.png +0 -0
  372. package/ui/public/sprites/4-D-2.png +0 -0
  373. package/ui/public/sprites/4-D-3.png +0 -0
  374. package/ui/public/sprites/4-L-1.png +0 -0
  375. package/ui/public/sprites/4-R-1.png +0 -0
  376. package/ui/public/sprites/5-D-1.png +0 -0
  377. package/ui/public/sprites/5-D-2.png +0 -0
  378. package/ui/public/sprites/5-D-3.png +0 -0
  379. package/ui/public/sprites/5-L-1.png +0 -0
  380. package/ui/public/sprites/5-R-1.png +0 -0
  381. package/ui/public/sprites/6-D-1.png +0 -0
  382. package/ui/public/sprites/6-D-2.png +0 -0
  383. package/ui/public/sprites/6-D-3.png +0 -0
  384. package/ui/public/sprites/6-L-1.png +0 -0
  385. package/ui/public/sprites/6-R-1.png +0 -0
  386. package/ui/public/sprites/7-D-1.png +0 -0
  387. package/ui/public/sprites/7-D-2.png +0 -0
  388. package/ui/public/sprites/7-D-3.png +0 -0
  389. package/ui/public/sprites/7-L-1.png +0 -0
  390. package/ui/public/sprites/7-R-1.png +0 -0
  391. package/ui/public/sprites/8-D-1.png +0 -0
  392. package/ui/public/sprites/8-D-2.png +0 -0
  393. package/ui/public/sprites/8-D-3.png +0 -0
  394. package/ui/public/sprites/8-L-1.png +0 -0
  395. package/ui/public/sprites/8-R-1.png +0 -0
  396. package/ui/public/sprites/9-D-1.png +0 -0
  397. package/ui/public/sprites/9-D-2.png +0 -0
  398. package/ui/public/sprites/9-D-3.png +0 -0
  399. package/ui/public/sprites/9-L-1.png +0 -0
  400. package/ui/public/sprites/9-R-1.png +0 -0
  401. package/ui/public/sprites/ceo-lobster.png +0 -0
  402. package/ui/public/sw.js +42 -0
  403. package/ui/public/worktree-favicon-16x16.png +0 -0
  404. package/ui/public/worktree-favicon-32x32.png +0 -0
  405. package/ui/public/worktree-favicon.ico +0 -0
  406. package/ui/public/worktree-favicon.svg +9 -0
  407. package/ui/src/App.tsx +354 -0
  408. package/ui/src/adapters/claude-local/config-fields.tsx +138 -0
  409. package/ui/src/adapters/claude-local/index.ts +13 -0
  410. package/ui/src/adapters/codex-local/config-fields.tsx +104 -0
  411. package/ui/src/adapters/codex-local/index.ts +13 -0
  412. package/ui/src/adapters/cursor/config-fields.tsx +49 -0
  413. package/ui/src/adapters/cursor/index.ts +13 -0
  414. package/ui/src/adapters/gemini-local/config-fields.tsx +51 -0
  415. package/ui/src/adapters/gemini-local/index.ts +13 -0
  416. package/ui/src/adapters/http/build-config.ts +9 -0
  417. package/ui/src/adapters/http/config-fields.tsx +38 -0
  418. package/ui/src/adapters/http/index.ts +12 -0
  419. package/ui/src/adapters/http/parse-stdout.ts +5 -0
  420. package/ui/src/adapters/index.ts +9 -0
  421. package/ui/src/adapters/local-workspace-runtime-fields.tsx +5 -0
  422. package/ui/src/adapters/openclaw-gateway/config-fields.tsx +237 -0
  423. package/ui/src/adapters/openclaw-gateway/index.ts +13 -0
  424. package/ui/src/adapters/opencode-local/config-fields.tsx +72 -0
  425. package/ui/src/adapters/opencode-local/index.ts +13 -0
  426. package/ui/src/adapters/pi-local/config-fields.tsx +49 -0
  427. package/ui/src/adapters/pi-local/index.ts +13 -0
  428. package/ui/src/adapters/process/build-config.ts +18 -0
  429. package/ui/src/adapters/process/config-fields.tsx +77 -0
  430. package/ui/src/adapters/process/index.ts +12 -0
  431. package/ui/src/adapters/process/parse-stdout.ts +5 -0
  432. package/ui/src/adapters/registry.ts +34 -0
  433. package/ui/src/adapters/runtime-json-fields.tsx +122 -0
  434. package/ui/src/adapters/transcript.test.ts +30 -0
  435. package/ui/src/adapters/transcript.ts +62 -0
  436. package/ui/src/adapters/types.ts +34 -0
  437. package/ui/src/api/access.ts +160 -0
  438. package/ui/src/api/activity.ts +37 -0
  439. package/ui/src/api/agents.ts +194 -0
  440. package/ui/src/api/approvals.ts +25 -0
  441. package/ui/src/api/assets.ts +30 -0
  442. package/ui/src/api/auth.ts +74 -0
  443. package/ui/src/api/budgets.ts +21 -0
  444. package/ui/src/api/client.ts +50 -0
  445. package/ui/src/api/companies.ts +59 -0
  446. package/ui/src/api/companySkills.ts +55 -0
  447. package/ui/src/api/costs.ts +60 -0
  448. package/ui/src/api/dashboard.ts +7 -0
  449. package/ui/src/api/execution-workspaces.ts +27 -0
  450. package/ui/src/api/goals.ts +12 -0
  451. package/ui/src/api/health.ts +41 -0
  452. package/ui/src/api/heartbeats.ts +62 -0
  453. package/ui/src/api/index.ts +18 -0
  454. package/ui/src/api/instanceSettings.ts +19 -0
  455. package/ui/src/api/issues.ts +115 -0
  456. package/ui/src/api/plugins.ts +424 -0
  457. package/ui/src/api/projects.ts +34 -0
  458. package/ui/src/api/routines.ts +59 -0
  459. package/ui/src/api/secrets.ts +26 -0
  460. package/ui/src/api/sidebarBadges.ts +7 -0
  461. package/ui/src/components/AccountingModelCard.tsx +69 -0
  462. package/ui/src/components/ActiveAgentsPanel.tsx +157 -0
  463. package/ui/src/components/ActivityCharts.tsx +264 -0
  464. package/ui/src/components/ActivityRow.tsx +147 -0
  465. package/ui/src/components/AgentActionButtons.tsx +51 -0
  466. package/ui/src/components/AgentConfigForm.tsx +1468 -0
  467. package/ui/src/components/AgentIconPicker.tsx +81 -0
  468. package/ui/src/components/AgentProperties.tsx +107 -0
  469. package/ui/src/components/ApprovalCard.tsx +107 -0
  470. package/ui/src/components/ApprovalPayload.tsx +134 -0
  471. package/ui/src/components/AsciiArtAnimation.tsx +355 -0
  472. package/ui/src/components/BillerSpendCard.tsx +146 -0
  473. package/ui/src/components/BreadcrumbBar.tsx +113 -0
  474. package/ui/src/components/BudgetIncidentCard.tsx +101 -0
  475. package/ui/src/components/BudgetPolicyCard.tsx +220 -0
  476. package/ui/src/components/BudgetSidebarMarker.tsx +13 -0
  477. package/ui/src/components/ClaudeSubscriptionPanel.tsx +141 -0
  478. package/ui/src/components/CodexSubscriptionPanel.tsx +158 -0
  479. package/ui/src/components/CommandPalette.tsx +239 -0
  480. package/ui/src/components/CommentThread.tsx +503 -0
  481. package/ui/src/components/CompanyPatternIcon.tsx +212 -0
  482. package/ui/src/components/CompanyRail.tsx +329 -0
  483. package/ui/src/components/CompanySwitcher.tsx +81 -0
  484. package/ui/src/components/CopyText.tsx +56 -0
  485. package/ui/src/components/DevRestartBanner.tsx +89 -0
  486. package/ui/src/components/EmptyState.tsx +27 -0
  487. package/ui/src/components/EntityRow.tsx +69 -0
  488. package/ui/src/components/FilterBar.tsx +39 -0
  489. package/ui/src/components/FinanceBillerCard.tsx +45 -0
  490. package/ui/src/components/FinanceKindCard.tsx +44 -0
  491. package/ui/src/components/FinanceTimelineCard.tsx +72 -0
  492. package/ui/src/components/GoalProperties.tsx +165 -0
  493. package/ui/src/components/GoalTree.tsx +118 -0
  494. package/ui/src/components/Identity.tsx +39 -0
  495. package/ui/src/components/InlineEditor.tsx +248 -0
  496. package/ui/src/components/InlineEntitySelector.tsx +206 -0
  497. package/ui/src/components/InstanceSidebar.tsx +53 -0
  498. package/ui/src/components/IssueDocumentsSection.tsx +892 -0
  499. package/ui/src/components/IssueProperties.tsx +621 -0
  500. package/ui/src/components/IssueRow.tsx +149 -0
  501. package/ui/src/components/IssueWorkspaceCard.tsx +404 -0
  502. package/ui/src/components/IssuesList.tsx +889 -0
  503. package/ui/src/components/JsonSchemaForm.tsx +1048 -0
  504. package/ui/src/components/KanbanBoard.tsx +275 -0
  505. package/ui/src/components/Layout.tsx +441 -0
  506. package/ui/src/components/LiveRunWidget.tsx +160 -0
  507. package/ui/src/components/MarkdownBody.test.tsx +50 -0
  508. package/ui/src/components/MarkdownBody.tsx +152 -0
  509. package/ui/src/components/MarkdownEditor.tsx +622 -0
  510. package/ui/src/components/MetricCard.tsx +53 -0
  511. package/ui/src/components/MobileBottomNav.tsx +123 -0
  512. package/ui/src/components/NewAgentDialog.tsx +223 -0
  513. package/ui/src/components/NewGoalDialog.tsx +283 -0
  514. package/ui/src/components/NewIssueDialog.tsx +1473 -0
  515. package/ui/src/components/NewProjectDialog.tsx +451 -0
  516. package/ui/src/components/OnboardingWizard.tsx +1392 -0
  517. package/ui/src/components/OpenCodeLogoIcon.tsx +22 -0
  518. package/ui/src/components/PackageFileTree.tsx +318 -0
  519. package/ui/src/components/PageSkeleton.tsx +180 -0
  520. package/ui/src/components/PageTabBar.tsx +45 -0
  521. package/ui/src/components/PathInstructionsModal.tsx +143 -0
  522. package/ui/src/components/PriorityIcon.tsx +77 -0
  523. package/ui/src/components/ProjectProperties.tsx +1127 -0
  524. package/ui/src/components/PropertiesPanel.tsx +29 -0
  525. package/ui/src/components/ProviderQuotaCard.tsx +417 -0
  526. package/ui/src/components/QuotaBar.tsx +65 -0
  527. package/ui/src/components/ReportsToPicker.tsx +127 -0
  528. package/ui/src/components/ScheduleEditor.tsx +344 -0
  529. package/ui/src/components/ScrollToBottom.tsx +79 -0
  530. package/ui/src/components/Sidebar.tsx +130 -0
  531. package/ui/src/components/SidebarAgents.tsx +146 -0
  532. package/ui/src/components/SidebarNavItem.tsx +92 -0
  533. package/ui/src/components/SidebarProjects.tsx +234 -0
  534. package/ui/src/components/SidebarSection.tsx +17 -0
  535. package/ui/src/components/StatusBadge.tsx +15 -0
  536. package/ui/src/components/StatusIcon.tsx +71 -0
  537. package/ui/src/components/SwipeToArchive.tsx +152 -0
  538. package/ui/src/components/ToastViewport.tsx +99 -0
  539. package/ui/src/components/WorktreeBanner.tsx +25 -0
  540. package/ui/src/components/agent-config-defaults.ts +31 -0
  541. package/ui/src/components/agent-config-primitives.tsx +476 -0
  542. package/ui/src/components/transcript/RunTranscriptView.test.tsx +84 -0
  543. package/ui/src/components/transcript/RunTranscriptView.tsx +1015 -0
  544. package/ui/src/components/transcript/useLiveRunTranscripts.ts +297 -0
  545. package/ui/src/components/ui/avatar.tsx +107 -0
  546. package/ui/src/components/ui/badge.tsx +48 -0
  547. package/ui/src/components/ui/breadcrumb.tsx +109 -0
  548. package/ui/src/components/ui/button.tsx +64 -0
  549. package/ui/src/components/ui/card.tsx +92 -0
  550. package/ui/src/components/ui/checkbox.tsx +32 -0
  551. package/ui/src/components/ui/collapsible.tsx +33 -0
  552. package/ui/src/components/ui/command.tsx +194 -0
  553. package/ui/src/components/ui/dialog.tsx +156 -0
  554. package/ui/src/components/ui/dropdown-menu.tsx +257 -0
  555. package/ui/src/components/ui/input.tsx +21 -0
  556. package/ui/src/components/ui/label.tsx +22 -0
  557. package/ui/src/components/ui/popover.tsx +88 -0
  558. package/ui/src/components/ui/scroll-area.tsx +56 -0
  559. package/ui/src/components/ui/select.tsx +188 -0
  560. package/ui/src/components/ui/separator.tsx +28 -0
  561. package/ui/src/components/ui/sheet.tsx +143 -0
  562. package/ui/src/components/ui/skeleton.tsx +13 -0
  563. package/ui/src/components/ui/tabs.tsx +89 -0
  564. package/ui/src/components/ui/textarea.tsx +18 -0
  565. package/ui/src/components/ui/tooltip.tsx +57 -0
  566. package/ui/src/components/visual-office/AgentAvatar.tsx +99 -0
  567. package/ui/src/components/visual-office/OfficeViewExact.tsx +417 -0
  568. package/ui/src/components/visual-office/i18n.ts +52 -0
  569. package/ui/src/components/visual-office/office-view/CliUsagePanel.tsx +240 -0
  570. package/ui/src/components/visual-office/office-view/VirtualPadOverlay.tsx +104 -0
  571. package/ui/src/components/visual-office/office-view/buildScene-break-room.ts +248 -0
  572. package/ui/src/components/visual-office/office-view/buildScene-ceo-hallway.ts +345 -0
  573. package/ui/src/components/visual-office/office-view/buildScene-department-agent.ts +242 -0
  574. package/ui/src/components/visual-office/office-view/buildScene-departments.ts +360 -0
  575. package/ui/src/components/visual-office/office-view/buildScene-final-layers.ts +113 -0
  576. package/ui/src/components/visual-office/office-view/buildScene-types.ts +91 -0
  577. package/ui/src/components/visual-office/office-view/buildScene.ts +232 -0
  578. package/ui/src/components/visual-office/office-view/drawing-core.ts +374 -0
  579. package/ui/src/components/visual-office/office-view/drawing-furniture-a.ts +338 -0
  580. package/ui/src/components/visual-office/office-view/drawing-furniture-b.ts +241 -0
  581. package/ui/src/components/visual-office/office-view/model.ts +301 -0
  582. package/ui/src/components/visual-office/office-view/officeTicker.ts +455 -0
  583. package/ui/src/components/visual-office/office-view/officeTickerRoomAndDelivery.ts +133 -0
  584. package/ui/src/components/visual-office/office-view/themes-locale.ts +460 -0
  585. package/ui/src/components/visual-office/office-view/useCliUsage.ts +37 -0
  586. package/ui/src/components/visual-office/office-view/useOfficeDeliveryEffects.ts +465 -0
  587. package/ui/src/components/visual-office/office-view/useOfficePixiRuntime.ts +282 -0
  588. package/ui/src/components/visual-office/types.ts +123 -0
  589. package/ui/src/context/BreadcrumbContext.tsx +44 -0
  590. package/ui/src/context/CompanyContext.tsx +151 -0
  591. package/ui/src/context/DialogContext.tsx +135 -0
  592. package/ui/src/context/LiveUpdatesProvider.test.ts +119 -0
  593. package/ui/src/context/LiveUpdatesProvider.tsx +760 -0
  594. package/ui/src/context/PanelContext.tsx +73 -0
  595. package/ui/src/context/SidebarContext.tsx +43 -0
  596. package/ui/src/context/ThemeContext.tsx +83 -0
  597. package/ui/src/context/ToastContext.tsx +172 -0
  598. package/ui/src/fixtures/runTranscriptFixtures.ts +226 -0
  599. package/ui/src/hooks/useAgentOrder.ts +105 -0
  600. package/ui/src/hooks/useAutosaveIndicator.ts +72 -0
  601. package/ui/src/hooks/useCompanyPageMemory.test.ts +90 -0
  602. package/ui/src/hooks/useCompanyPageMemory.ts +79 -0
  603. package/ui/src/hooks/useDateRange.ts +120 -0
  604. package/ui/src/hooks/useInboxBadge.ts +132 -0
  605. package/ui/src/hooks/useKeyboardShortcuts.ts +40 -0
  606. package/ui/src/hooks/useProjectOrder.ts +106 -0
  607. package/ui/src/index.css +770 -0
  608. package/ui/src/lib/agent-icons.ts +99 -0
  609. package/ui/src/lib/agent-order.ts +107 -0
  610. package/ui/src/lib/agent-skills-state.test.ts +90 -0
  611. package/ui/src/lib/agent-skills-state.ts +41 -0
  612. package/ui/src/lib/assignees.test.ts +92 -0
  613. package/ui/src/lib/assignees.ts +82 -0
  614. package/ui/src/lib/color-contrast.ts +107 -0
  615. package/ui/src/lib/company-export-selection.test.ts +41 -0
  616. package/ui/src/lib/company-export-selection.ts +57 -0
  617. package/ui/src/lib/company-page-memory.ts +65 -0
  618. package/ui/src/lib/company-portability-sidebar.test.ts +101 -0
  619. package/ui/src/lib/company-portability-sidebar.ts +62 -0
  620. package/ui/src/lib/company-routes.ts +88 -0
  621. package/ui/src/lib/company-selection.test.ts +34 -0
  622. package/ui/src/lib/company-selection.ts +18 -0
  623. package/ui/src/lib/groupBy.ts +11 -0
  624. package/ui/src/lib/inbox.test.ts +404 -0
  625. package/ui/src/lib/inbox.ts +292 -0
  626. package/ui/src/lib/instance-settings.test.ts +26 -0
  627. package/ui/src/lib/instance-settings.ts +25 -0
  628. package/ui/src/lib/issueDetailBreadcrumb.ts +24 -0
  629. package/ui/src/lib/legacy-agent-config.test.ts +40 -0
  630. package/ui/src/lib/legacy-agent-config.ts +17 -0
  631. package/ui/src/lib/mention-aware-link-node.test.ts +50 -0
  632. package/ui/src/lib/mention-aware-link-node.ts +67 -0
  633. package/ui/src/lib/mention-chips.ts +168 -0
  634. package/ui/src/lib/mention-deletion.test.ts +87 -0
  635. package/ui/src/lib/mention-deletion.ts +143 -0
  636. package/ui/src/lib/model-utils.ts +16 -0
  637. package/ui/src/lib/onboarding-goal.test.ts +22 -0
  638. package/ui/src/lib/onboarding-goal.ts +18 -0
  639. package/ui/src/lib/onboarding-launch.test.ts +131 -0
  640. package/ui/src/lib/onboarding-launch.ts +54 -0
  641. package/ui/src/lib/onboarding-route.test.ts +80 -0
  642. package/ui/src/lib/onboarding-route.ts +51 -0
  643. package/ui/src/lib/portable-files.ts +42 -0
  644. package/ui/src/lib/project-order.ts +71 -0
  645. package/ui/src/lib/queryKeys.ts +140 -0
  646. package/ui/src/lib/recent-assignees.ts +36 -0
  647. package/ui/src/lib/router.tsx +76 -0
  648. package/ui/src/lib/routine-trigger-patch.test.ts +72 -0
  649. package/ui/src/lib/routine-trigger-patch.ts +31 -0
  650. package/ui/src/lib/status-colors.ts +108 -0
  651. package/ui/src/lib/timeAgo.ts +31 -0
  652. package/ui/src/lib/utils.ts +168 -0
  653. package/ui/src/lib/worktree-branding.ts +65 -0
  654. package/ui/src/lib/zip.test.ts +289 -0
  655. package/ui/src/lib/zip.ts +284 -0
  656. package/ui/src/main.tsx +67 -0
  657. package/ui/src/pages/Activity.tsx +141 -0
  658. package/ui/src/pages/AgentDetail.tsx +4053 -0
  659. package/ui/src/pages/Agents.tsx +415 -0
  660. package/ui/src/pages/ApprovalDetail.tsx +369 -0
  661. package/ui/src/pages/Approvals.tsx +132 -0
  662. package/ui/src/pages/Auth.tsx +180 -0
  663. package/ui/src/pages/BoardClaim.tsx +125 -0
  664. package/ui/src/pages/CliAuth.tsx +184 -0
  665. package/ui/src/pages/Companies.tsx +297 -0
  666. package/ui/src/pages/CompanyExport.tsx +1019 -0
  667. package/ui/src/pages/CompanyImport.tsx +1355 -0
  668. package/ui/src/pages/CompanySettings.tsx +661 -0
  669. package/ui/src/pages/CompanySkills.tsx +1171 -0
  670. package/ui/src/pages/Costs.tsx +1103 -0
  671. package/ui/src/pages/Dashboard.tsx +388 -0
  672. package/ui/src/pages/DesignGuide.tsx +1330 -0
  673. package/ui/src/pages/ExecutionWorkspaceDetail.tsx +82 -0
  674. package/ui/src/pages/GoalDetail.tsx +197 -0
  675. package/ui/src/pages/Goals.tsx +63 -0
  676. package/ui/src/pages/Inbox.tsx +1291 -0
  677. package/ui/src/pages/InstanceExperimentalSettings.tsx +139 -0
  678. package/ui/src/pages/InstanceGeneralSettings.tsx +104 -0
  679. package/ui/src/pages/InstanceSettings.tsx +284 -0
  680. package/ui/src/pages/InviteLanding.tsx +320 -0
  681. package/ui/src/pages/IssueDetail.tsx +1201 -0
  682. package/ui/src/pages/Issues.tsx +116 -0
  683. package/ui/src/pages/MyIssues.tsx +72 -0
  684. package/ui/src/pages/NewAgent.tsx +353 -0
  685. package/ui/src/pages/NotFound.tsx +66 -0
  686. package/ui/src/pages/Org.tsx +132 -0
  687. package/ui/src/pages/OrgChart.tsx +447 -0
  688. package/ui/src/pages/PluginManager.tsx +510 -0
  689. package/ui/src/pages/PluginPage.tsx +156 -0
  690. package/ui/src/pages/PluginSettings.tsx +836 -0
  691. package/ui/src/pages/ProjectDetail.tsx +633 -0
  692. package/ui/src/pages/Projects.tsx +87 -0
  693. package/ui/src/pages/RoutineDetail.tsx +1022 -0
  694. package/ui/src/pages/Routines.tsx +661 -0
  695. package/ui/src/pages/RunTranscriptUxLab.tsx +334 -0
  696. package/ui/src/pages/VisualOffice.tsx +243 -0
  697. package/ui/src/plugins/bridge-init.ts +69 -0
  698. package/ui/src/plugins/bridge.ts +476 -0
  699. package/ui/src/plugins/launchers.tsx +834 -0
  700. package/ui/src/plugins/slots.tsx +855 -0
  701. package/ui/tsconfig.json +21 -0
  702. package/ui/vite.config.ts +23 -0
  703. package/ui/vitest.config.ts +14 -0
  704. package/vitest.config.ts +11 -0
@@ -0,0 +1,1048 @@
1
+ import React, { useCallback, useMemo, useState } from "react";
2
+ import {
3
+ ChevronDown,
4
+ ChevronRight,
5
+ Eye,
6
+ EyeOff,
7
+ Plus,
8
+ Trash2,
9
+ } from "lucide-react";
10
+ import { cn } from "@/lib/utils";
11
+ import { Input } from "@/components/ui/input";
12
+ import { Textarea } from "@/components/ui/textarea";
13
+ import { Label } from "@/components/ui/label";
14
+ import { Checkbox } from "@/components/ui/checkbox";
15
+ import { Button } from "@/components/ui/button";
16
+ import {
17
+ Select,
18
+ SelectContent,
19
+ SelectItem,
20
+ SelectTrigger,
21
+ SelectValue,
22
+ } from "@/components/ui/select";
23
+
24
+ // ---------------------------------------------------------------------------
25
+ // Constants
26
+ // ---------------------------------------------------------------------------
27
+
28
+ /**
29
+ * Threshold for string length above which a Textarea is used instead of a standard Input.
30
+ */
31
+ const TEXTAREA_THRESHOLD = 200;
32
+
33
+ // ---------------------------------------------------------------------------
34
+ // Types
35
+ // ---------------------------------------------------------------------------
36
+
37
+ /**
38
+ * Subset of JSON Schema properties we understand for form rendering.
39
+ * We intentionally keep this loose (`Record<string, unknown>`) at the top
40
+ * level to match the `JsonSchema` type in shared, but narrow internally.
41
+ */
42
+ export interface JsonSchemaNode {
43
+ type?: string | string[];
44
+ title?: string;
45
+ description?: string;
46
+ default?: unknown;
47
+ enum?: unknown[];
48
+ const?: unknown;
49
+ format?: string;
50
+
51
+ // String constraints
52
+ minLength?: number;
53
+ maxLength?: number;
54
+ pattern?: string;
55
+
56
+ // Number constraints
57
+ minimum?: number;
58
+ maximum?: number;
59
+ exclusiveMinimum?: number;
60
+ exclusiveMaximum?: number;
61
+ multipleOf?: number;
62
+
63
+ // Object
64
+ properties?: Record<string, JsonSchemaNode>;
65
+ required?: string[];
66
+ additionalProperties?: boolean | JsonSchemaNode;
67
+
68
+ // Array
69
+ items?: JsonSchemaNode;
70
+ minItems?: number;
71
+ maxItems?: number;
72
+
73
+ // Metadata
74
+ readOnly?: boolean;
75
+ writeOnly?: boolean;
76
+
77
+ // Allow extra keys
78
+ [key: string]: unknown;
79
+ }
80
+
81
+ export interface JsonSchemaFormProps {
82
+ /** The JSON Schema to render. */
83
+ schema: JsonSchemaNode;
84
+ /** Current form values. */
85
+ values: Record<string, unknown>;
86
+ /** Called whenever any field value changes. */
87
+ onChange: (values: Record<string, unknown>) => void;
88
+ /** Validation errors keyed by JSON pointer path (e.g. "/apiKey"). */
89
+ errors?: Record<string, string>;
90
+ /** If true, all fields are disabled. */
91
+ disabled?: boolean;
92
+ /** Additional CSS class for the root container. */
93
+ className?: string;
94
+ }
95
+
96
+ // ---------------------------------------------------------------------------
97
+ // Helpers
98
+ // ---------------------------------------------------------------------------
99
+
100
+ /** Resolve the primary type string from a schema node. */
101
+ export function resolveType(schema: JsonSchemaNode): string {
102
+ if (schema.enum) return "enum";
103
+ if (schema.const !== undefined) return "const";
104
+ if (schema.format === "secret-ref") return "secret-ref";
105
+ if (Array.isArray(schema.type)) {
106
+ // Use the first non-null type
107
+ return schema.type.find((t) => t !== "null") ?? "string";
108
+ }
109
+ return schema.type ?? "string";
110
+ }
111
+
112
+ /** Human-readable label from schema title or property key. */
113
+ export function labelFromKey(key: string, schema: JsonSchemaNode): string {
114
+ if (schema.title) return schema.title;
115
+ // Convert camelCase / snake_case to Title Case
116
+ return key
117
+ .replace(/([a-z])([A-Z])/g, "$1 $2")
118
+ .replace(/[_-]+/g, " ")
119
+ .replace(/\b\w/g, (c) => c.toUpperCase());
120
+ }
121
+
122
+ /** Produce a sensible default value for a schema node. */
123
+ export function getDefaultForSchema(schema: JsonSchemaNode): unknown {
124
+ if (schema.default !== undefined) return schema.default;
125
+
126
+ const type = resolveType(schema);
127
+ switch (type) {
128
+ case "string":
129
+ case "secret-ref":
130
+ return "";
131
+ case "number":
132
+ case "integer":
133
+ return schema.minimum ?? 0;
134
+ case "boolean":
135
+ return false;
136
+ case "enum":
137
+ return schema.enum?.[0] ?? "";
138
+ case "array":
139
+ return [];
140
+ case "object": {
141
+ if (!schema.properties) return {};
142
+ const obj: Record<string, unknown> = {};
143
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
144
+ obj[key] = getDefaultForSchema(propSchema);
145
+ }
146
+ return obj;
147
+ }
148
+ default:
149
+ return "";
150
+ }
151
+ }
152
+
153
+ /** Validate a single field value against schema constraints. Returns error string or null. */
154
+ export function validateField(
155
+ value: unknown,
156
+ schema: JsonSchemaNode,
157
+ isRequired: boolean,
158
+ ): string | null {
159
+ const type = resolveType(schema);
160
+
161
+ // Required check
162
+ if (isRequired && (value === undefined || value === null || value === "")) {
163
+ return "This field is required";
164
+ }
165
+
166
+ // Skip further validation if empty and not required
167
+ if (value === undefined || value === null || value === "") return null;
168
+
169
+ if (type === "string" || type === "secret-ref") {
170
+ const str = String(value);
171
+ if (schema.minLength != null && str.length < schema.minLength) {
172
+ return `Must be at least ${schema.minLength} characters`;
173
+ }
174
+ if (schema.maxLength != null && str.length > schema.maxLength) {
175
+ return `Must be at most ${schema.maxLength} characters`;
176
+ }
177
+ if (schema.pattern) {
178
+ // Guard against ReDoS: reject overly complex patterns from plugin JSON Schemas.
179
+ // Limit pattern length and run the regex with a defensive try/catch.
180
+ const MAX_PATTERN_LENGTH = 512;
181
+ if (schema.pattern.length <= MAX_PATTERN_LENGTH) {
182
+ try {
183
+ const re = new RegExp(schema.pattern);
184
+ if (!re.test(str)) {
185
+ return `Must match pattern: ${schema.pattern}`;
186
+ }
187
+ } catch {
188
+ // Invalid regex in schema — skip
189
+ }
190
+ }
191
+ }
192
+ }
193
+
194
+ if (type === "number" || type === "integer") {
195
+ const num = Number(value);
196
+ if (isNaN(num)) return "Must be a valid number";
197
+ if (schema.minimum != null && num < schema.minimum) {
198
+ return `Must be at least ${schema.minimum}`;
199
+ }
200
+ if (schema.maximum != null && num > schema.maximum) {
201
+ return `Must be at most ${schema.maximum}`;
202
+ }
203
+ if (schema.exclusiveMinimum != null && num <= schema.exclusiveMinimum) {
204
+ return `Must be greater than ${schema.exclusiveMinimum}`;
205
+ }
206
+ if (schema.exclusiveMaximum != null && num >= schema.exclusiveMaximum) {
207
+ return `Must be less than ${schema.exclusiveMaximum}`;
208
+ }
209
+ if (type === "integer" && !Number.isInteger(num)) {
210
+ return "Must be a whole number";
211
+ }
212
+ if (schema.multipleOf != null && num % schema.multipleOf !== 0) {
213
+ return `Must be a multiple of ${schema.multipleOf}`;
214
+ }
215
+ }
216
+
217
+ if (type === "array") {
218
+ const arr = value as unknown[];
219
+ if (schema.minItems != null && arr.length < schema.minItems) {
220
+ return `Must have at least ${schema.minItems} items`;
221
+ }
222
+ if (schema.maxItems != null && arr.length > schema.maxItems) {
223
+ return `Must have at most ${schema.maxItems} items`;
224
+ }
225
+ }
226
+
227
+ return null;
228
+ }
229
+
230
+ /** Public API for validation */
231
+ export function validateJsonSchemaForm(
232
+ schema: JsonSchemaNode,
233
+ values: Record<string, unknown>,
234
+ path: string[] = [],
235
+ ): Record<string, string> {
236
+ const errors: Record<string, string> = {};
237
+ const properties = schema.properties ?? {};
238
+ const requiredFields = new Set(schema.required ?? []);
239
+
240
+ for (const [key, propSchema] of Object.entries(properties)) {
241
+ const fieldPath = [...path, key];
242
+ const errorKey = `/${fieldPath.join("/")}`;
243
+ const value = values[key];
244
+ const isRequired = requiredFields.has(key);
245
+ const type = resolveType(propSchema);
246
+
247
+ // Per-field validation
248
+ const fieldErr = validateField(value, propSchema, isRequired);
249
+ if (fieldErr) {
250
+ errors[errorKey] = fieldErr;
251
+ }
252
+
253
+ // Recurse into objects
254
+ if (type === "object" && propSchema.properties && typeof value === "object" && value !== null) {
255
+ Object.assign(
256
+ errors,
257
+ validateJsonSchemaForm(propSchema, value as Record<string, unknown>, fieldPath),
258
+ );
259
+ }
260
+
261
+ // Recurse into arrays
262
+ if (type === "array" && propSchema.items && Array.isArray(value)) {
263
+ const itemSchema = propSchema.items as JsonSchemaNode;
264
+ const isObjectItem = resolveType(itemSchema) === "object";
265
+
266
+ value.forEach((item, index) => {
267
+ const itemPath = [...fieldPath, String(index)];
268
+ const itemErrorKey = `/${itemPath.join("/")}`;
269
+
270
+ if (isObjectItem) {
271
+ Object.assign(
272
+ errors,
273
+ validateJsonSchemaForm(
274
+ itemSchema,
275
+ item as Record<string, unknown>,
276
+ itemPath,
277
+ ),
278
+ );
279
+ } else {
280
+ const itemErr = validateField(item, itemSchema, false);
281
+ if (itemErr) {
282
+ errors[itemErrorKey] = itemErr;
283
+ }
284
+ }
285
+ });
286
+ }
287
+ }
288
+
289
+ return errors;
290
+ }
291
+
292
+ /** Public API for default values */
293
+ export function getDefaultValues(schema: JsonSchemaNode): Record<string, unknown> {
294
+ const result: Record<string, unknown> = {};
295
+ const properties = schema.properties ?? {};
296
+
297
+ for (const [key, propSchema] of Object.entries(properties)) {
298
+ const def = getDefaultForSchema(propSchema);
299
+ if (def !== undefined) {
300
+ result[key] = def;
301
+ }
302
+ }
303
+
304
+ return result;
305
+ }
306
+
307
+ // ---------------------------------------------------------------------------
308
+ // Internal Components
309
+ // ---------------------------------------------------------------------------
310
+
311
+ interface FieldWrapperProps {
312
+ label: string;
313
+ description?: string;
314
+ required?: boolean;
315
+ error?: string;
316
+ disabled?: boolean;
317
+ children: React.ReactNode;
318
+ }
319
+
320
+ /**
321
+ * Common wrapper for form fields that handles labels, descriptions, and error messages.
322
+ */
323
+ const FieldWrapper = React.memo(({
324
+ label,
325
+ description,
326
+ required,
327
+ error,
328
+ disabled,
329
+ children,
330
+ }: FieldWrapperProps) => {
331
+ return (
332
+ <div className={cn("space-y-2", disabled && "opacity-60")}>
333
+ <div className="flex items-center justify-between">
334
+ {label && (
335
+ <Label className="text-sm font-medium">
336
+ {label}
337
+ {required && <span className="ml-1 text-destructive">*</span>}
338
+ </Label>
339
+ )}
340
+ </div>
341
+ {children}
342
+ {description && (
343
+ <p className="text-[12px] text-muted-foreground leading-relaxed">
344
+ {description}
345
+ </p>
346
+ )}
347
+ {error && (
348
+ <p className="text-[12px] font-medium text-destructive">{error}</p>
349
+ )}
350
+ </div>
351
+ );
352
+ });
353
+
354
+ FieldWrapper.displayName = "FieldWrapper";
355
+
356
+ interface FormFieldProps {
357
+ propSchema: JsonSchemaNode;
358
+ value: unknown;
359
+ onChange: (val: unknown) => void;
360
+ error?: string;
361
+ disabled?: boolean;
362
+ label: string;
363
+ isRequired?: boolean;
364
+ errors: Record<string, string>; // needed for recursion
365
+ path: string; // needed for recursion error filtering
366
+ }
367
+
368
+ /**
369
+ * Specialized field for boolean (checkbox) values.
370
+ */
371
+ const BooleanField = React.memo(({
372
+ id,
373
+ value,
374
+ onChange,
375
+ disabled,
376
+ label,
377
+ isRequired,
378
+ description,
379
+ error,
380
+ }: {
381
+ id: string;
382
+ value: unknown;
383
+ onChange: (val: unknown) => void;
384
+ disabled: boolean;
385
+ label: string;
386
+ isRequired?: boolean;
387
+ description?: string;
388
+ error?: string;
389
+ }) => (
390
+ <div className="flex items-start space-x-3 space-y-0">
391
+ <Checkbox
392
+ id={id}
393
+ checked={!!value}
394
+ onCheckedChange={onChange}
395
+ disabled={disabled}
396
+ />
397
+ <div className="grid gap-1.5 leading-none">
398
+ {label && (
399
+ <Label
400
+ htmlFor={id}
401
+ className="text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
402
+ >
403
+ {label}
404
+ {isRequired && <span className="ml-1 text-destructive">*</span>}
405
+ </Label>
406
+ )}
407
+ {description && (
408
+ <p className="text-xs text-muted-foreground">{description}</p>
409
+ )}
410
+ {error && (
411
+ <p className="text-xs font-medium text-destructive">{error}</p>
412
+ )}
413
+ </div>
414
+ </div>
415
+ ));
416
+
417
+ BooleanField.displayName = "BooleanField";
418
+
419
+ /**
420
+ * Specialized field for enum (select) values.
421
+ */
422
+ const EnumField = React.memo(({
423
+ value,
424
+ onChange,
425
+ disabled,
426
+ label,
427
+ isRequired,
428
+ description,
429
+ error,
430
+ options,
431
+ }: {
432
+ value: unknown;
433
+ onChange: (val: unknown) => void;
434
+ disabled: boolean;
435
+ label: string;
436
+ isRequired?: boolean;
437
+ description?: string;
438
+ error?: string;
439
+ options: unknown[];
440
+ }) => (
441
+ <FieldWrapper
442
+ label={label}
443
+ description={description}
444
+ required={isRequired}
445
+ error={error}
446
+ disabled={disabled}
447
+ >
448
+ <Select
449
+ value={String(value ?? "")}
450
+ onValueChange={onChange}
451
+ disabled={disabled}
452
+ >
453
+ <SelectTrigger className="w-full">
454
+ <SelectValue placeholder="Select an option" />
455
+ </SelectTrigger>
456
+ <SelectContent>
457
+ {options.map((option) => (
458
+ <SelectItem key={String(option)} value={String(option)}>
459
+ {String(option)}
460
+ </SelectItem>
461
+ ))}
462
+ </SelectContent>
463
+ </Select>
464
+ </FieldWrapper>
465
+ ));
466
+
467
+ EnumField.displayName = "EnumField";
468
+
469
+ /**
470
+ * Specialized field for secret-ref values, providing a toggleable password input.
471
+ */
472
+ const SecretField = React.memo(({
473
+ value,
474
+ onChange,
475
+ disabled,
476
+ label,
477
+ isRequired,
478
+ description,
479
+ error,
480
+ defaultValue,
481
+ }: {
482
+ value: unknown;
483
+ onChange: (val: unknown) => void;
484
+ disabled: boolean;
485
+ label: string;
486
+ isRequired?: boolean;
487
+ description?: string;
488
+ error?: string;
489
+ defaultValue?: unknown;
490
+ }) => {
491
+ const [isVisible, setIsVisible] = useState(false);
492
+ return (
493
+ <FieldWrapper
494
+ label={label}
495
+ description={
496
+ description ||
497
+ "This secret is stored securely via the Corporate secret provider."
498
+ }
499
+ required={isRequired}
500
+ error={error}
501
+ disabled={disabled}
502
+ >
503
+ <div className="relative">
504
+ <Input
505
+ type={isVisible ? "text" : "password"}
506
+ value={String(value ?? "")}
507
+ onChange={(e) => onChange(e.target.value)}
508
+ placeholder={String(defaultValue ?? "")}
509
+ disabled={disabled}
510
+ className="pr-10"
511
+ aria-invalid={!!error}
512
+ />
513
+ <Button
514
+ type="button"
515
+ variant="ghost"
516
+ size="sm"
517
+ className="absolute right-0 top-0 h-full px-3 py-2 hover:bg-transparent"
518
+ onClick={() => setIsVisible(!isVisible)}
519
+ disabled={disabled}
520
+ >
521
+ {isVisible ? (
522
+ <EyeOff className="h-4 w-4 text-muted-foreground" />
523
+ ) : (
524
+ <Eye className="h-4 w-4 text-muted-foreground" />
525
+ )}
526
+ <span className="sr-only">
527
+ {isVisible ? "Hide secret" : "Show secret"}
528
+ </span>
529
+ </Button>
530
+ </div>
531
+ </FieldWrapper>
532
+ );
533
+ });
534
+
535
+ SecretField.displayName = "SecretField";
536
+
537
+ /**
538
+ * Specialized field for numeric (number/integer) values.
539
+ */
540
+ const NumberField = React.memo(({
541
+ value,
542
+ onChange,
543
+ disabled,
544
+ label,
545
+ isRequired,
546
+ description,
547
+ error,
548
+ defaultValue,
549
+ type,
550
+ }: {
551
+ value: unknown;
552
+ onChange: (val: unknown) => void;
553
+ disabled: boolean;
554
+ label: string;
555
+ isRequired?: boolean;
556
+ description?: string;
557
+ error?: string;
558
+ defaultValue?: unknown;
559
+ type: "number" | "integer";
560
+ }) => (
561
+ <FieldWrapper
562
+ label={label}
563
+ description={description}
564
+ required={isRequired}
565
+ error={error}
566
+ disabled={disabled}
567
+ >
568
+ <Input
569
+ type="number"
570
+ step={type === "integer" ? "1" : "any"}
571
+ value={value !== undefined ? String(value) : ""}
572
+ onChange={(e) => {
573
+ const val = e.target.value;
574
+ onChange(val === "" ? undefined : Number(val));
575
+ }}
576
+ placeholder={String(defaultValue ?? "")}
577
+ disabled={disabled}
578
+ aria-invalid={!!error}
579
+ />
580
+ </FieldWrapper>
581
+ ));
582
+
583
+ NumberField.displayName = "NumberField";
584
+
585
+ /**
586
+ * Specialized field for string values, rendering either an Input or Textarea based on length or format.
587
+ */
588
+ const StringField = React.memo(({
589
+ value,
590
+ onChange,
591
+ disabled,
592
+ label,
593
+ isRequired,
594
+ description,
595
+ error,
596
+ defaultValue,
597
+ format,
598
+ maxLength,
599
+ }: {
600
+ value: unknown;
601
+ onChange: (val: unknown) => void;
602
+ disabled: boolean;
603
+ label: string;
604
+ isRequired?: boolean;
605
+ description?: string;
606
+ error?: string;
607
+ defaultValue?: unknown;
608
+ format?: string;
609
+ maxLength?: number;
610
+ }) => {
611
+ const isTextArea = format === "textarea" || (maxLength && maxLength > TEXTAREA_THRESHOLD);
612
+ return (
613
+ <FieldWrapper
614
+ label={label}
615
+ description={description}
616
+ required={isRequired}
617
+ error={error}
618
+ disabled={disabled}
619
+ >
620
+ {isTextArea ? (
621
+ <Textarea
622
+ value={String(value ?? "")}
623
+ onChange={(e) => onChange(e.target.value)}
624
+ placeholder={String(defaultValue ?? "")}
625
+ disabled={disabled}
626
+ className="min-h-[100px]"
627
+ aria-invalid={!!error}
628
+ />
629
+ ) : (
630
+ <Input
631
+ type="text"
632
+ value={String(value ?? "")}
633
+ onChange={(e) => onChange(e.target.value)}
634
+ placeholder={String(defaultValue ?? "")}
635
+ disabled={disabled}
636
+ aria-invalid={!!error}
637
+ />
638
+ )}
639
+ </FieldWrapper>
640
+ );
641
+ });
642
+
643
+ StringField.displayName = "StringField";
644
+
645
+ /**
646
+ * Specialized field for array values, handling dynamic addition and removal of items.
647
+ */
648
+ const ArrayField = React.memo(({
649
+ propSchema,
650
+ value,
651
+ onChange,
652
+ error,
653
+ disabled,
654
+ label,
655
+ errors,
656
+ path,
657
+ }: {
658
+ propSchema: JsonSchemaNode;
659
+ value: unknown;
660
+ onChange: (val: unknown) => void;
661
+ error?: string;
662
+ disabled: boolean;
663
+ label: string;
664
+ errors: Record<string, string>;
665
+ path: string;
666
+ }) => {
667
+ const items = Array.isArray(value) ? value : [];
668
+ const itemSchema = propSchema.items as JsonSchemaNode;
669
+ const isComplex = resolveType(itemSchema) === "object";
670
+
671
+ return (
672
+ <div className="space-y-4">
673
+ <div className="flex items-center justify-between">
674
+ <div>
675
+ <Label className="text-sm font-medium">{label}</Label>
676
+ {propSchema.description && (
677
+ <p className="text-xs text-muted-foreground">
678
+ {propSchema.description}
679
+ </p>
680
+ )}
681
+ </div>
682
+ <Button
683
+ type="button"
684
+ variant="outline"
685
+ size="sm"
686
+ disabled={
687
+ disabled ||
688
+ (propSchema.maxItems !== undefined &&
689
+ items.length >= (propSchema.maxItems as number))
690
+ }
691
+ onClick={() => {
692
+ const newItem = getDefaultForSchema(itemSchema);
693
+ onChange([...items, newItem]);
694
+ }}
695
+ >
696
+ <Plus className="mr-2 h-4 w-4" />
697
+ {isComplex ? "Add item" : "Add"}
698
+ </Button>
699
+ </div>
700
+
701
+ <div className="space-y-3">
702
+ {items.map((item, index) => (
703
+ <div
704
+ key={index}
705
+ className="group relative flex items-start space-x-2 rounded-lg border p-3"
706
+ >
707
+ <div className="flex-1">
708
+ <div className="mb-2 text-xs font-medium text-muted-foreground">
709
+ Item {index + 1}
710
+ </div>
711
+ <FormField
712
+ propSchema={itemSchema}
713
+ value={item}
714
+ label=""
715
+ path={`${path}/${index}`}
716
+ onChange={(newVal) => {
717
+ const newItems = [...items];
718
+ newItems[index] = newVal;
719
+ onChange(newItems);
720
+ }}
721
+ disabled={disabled}
722
+ errors={errors}
723
+ />
724
+ </div>
725
+ <Button
726
+ type="button"
727
+ variant="ghost"
728
+ size="icon"
729
+ className="h-8 w-8 text-muted-foreground hover:text-destructive"
730
+ disabled={
731
+ disabled ||
732
+ (propSchema.minItems !== undefined &&
733
+ items.length <= (propSchema.minItems as number))
734
+ }
735
+ onClick={() => {
736
+ const newItems = [...items];
737
+ newItems.splice(index, 1);
738
+ onChange(newItems);
739
+ }}
740
+ >
741
+ <Trash2 className="h-4 w-4" />
742
+ <span className="sr-only">Remove item</span>
743
+ </Button>
744
+ </div>
745
+ ))}
746
+ {items.length === 0 && (
747
+ <div className="rounded-lg border border-dashed p-4 text-center text-xs text-muted-foreground">
748
+ No items added yet.
749
+ </div>
750
+ )}
751
+ </div>
752
+ {error && (
753
+ <p className="text-xs font-medium text-destructive">{error}</p>
754
+ )}
755
+ </div>
756
+ );
757
+ });
758
+
759
+ ArrayField.displayName = "ArrayField";
760
+
761
+ /**
762
+ * Specialized field for object values, handling recursive rendering of nested properties.
763
+ */
764
+ const ObjectField = React.memo(({
765
+ propSchema,
766
+ value,
767
+ onChange,
768
+ disabled,
769
+ label,
770
+ errors,
771
+ path,
772
+ }: {
773
+ propSchema: JsonSchemaNode;
774
+ value: unknown;
775
+ onChange: (val: unknown) => void;
776
+ disabled: boolean;
777
+ label: string;
778
+ errors: Record<string, string>;
779
+ path: string;
780
+ }) => {
781
+ const [isCollapsed, setIsCollapsed] = useState(false);
782
+ const handleObjectChange = (newVal: Record<string, unknown>) => {
783
+ onChange(newVal);
784
+ };
785
+
786
+ return (
787
+ <div className="space-y-3 rounded-lg border p-4">
788
+ <button
789
+ type="button"
790
+ className="flex w-full items-center justify-between"
791
+ onClick={() => setIsCollapsed(!isCollapsed)}
792
+ >
793
+ <div className="text-left">
794
+ <Label className="cursor-pointer text-sm font-semibold">
795
+ {label}
796
+ </Label>
797
+ {propSchema.description && (
798
+ <p className="text-xs text-muted-foreground">
799
+ {propSchema.description}
800
+ </p>
801
+ )}
802
+ </div>
803
+ {isCollapsed ? (
804
+ <ChevronRight className="h-4 w-4 text-muted-foreground" />
805
+ ) : (
806
+ <ChevronDown className="h-4 w-4 text-muted-foreground" />
807
+ )}
808
+ </button>
809
+
810
+ {!isCollapsed && (
811
+ <div className="pt-2">
812
+ <JsonSchemaForm
813
+ schema={propSchema}
814
+ values={(value as Record<string, unknown>) ?? {}}
815
+ onChange={handleObjectChange}
816
+ disabled={disabled}
817
+ errors={Object.fromEntries(
818
+ Object.entries(errors)
819
+ .filter(([errPath]) => errPath.startsWith(`${path}/`))
820
+ .map(([errPath, err]) => [errPath.replace(path, ""), err]),
821
+ )}
822
+ />
823
+ </div>
824
+ )}
825
+ </div>
826
+ );
827
+ });
828
+
829
+ ObjectField.displayName = "ObjectField";
830
+
831
+ /**
832
+ * Orchestrator component that selects and renders the appropriate field type based on the schema node.
833
+ */
834
+ const FormField = React.memo(({
835
+ propSchema,
836
+ value,
837
+ onChange,
838
+ error,
839
+ disabled,
840
+ label,
841
+ isRequired,
842
+ errors,
843
+ path,
844
+ }: FormFieldProps) => {
845
+ const type = resolveType(propSchema);
846
+ const isReadOnly = disabled || propSchema.readOnly === true;
847
+
848
+ switch (type) {
849
+ case "boolean":
850
+ return (
851
+ <BooleanField
852
+ id={path}
853
+ value={value}
854
+ onChange={onChange}
855
+ disabled={isReadOnly}
856
+ label={label}
857
+ isRequired={isRequired}
858
+ description={propSchema.description}
859
+ error={error}
860
+ />
861
+ );
862
+
863
+ case "enum":
864
+ return (
865
+ <EnumField
866
+ value={value}
867
+ onChange={onChange}
868
+ disabled={isReadOnly}
869
+ label={label}
870
+ isRequired={isRequired}
871
+ description={propSchema.description}
872
+ error={error}
873
+ options={propSchema.enum ?? []}
874
+ />
875
+ );
876
+
877
+ case "secret-ref":
878
+ return (
879
+ <SecretField
880
+ value={value}
881
+ onChange={onChange}
882
+ disabled={isReadOnly}
883
+ label={label}
884
+ isRequired={isRequired}
885
+ description={propSchema.description}
886
+ error={error}
887
+ defaultValue={propSchema.default}
888
+ />
889
+ );
890
+
891
+ case "number":
892
+ case "integer":
893
+ return (
894
+ <NumberField
895
+ value={value}
896
+ onChange={onChange}
897
+ disabled={isReadOnly}
898
+ label={label}
899
+ isRequired={isRequired}
900
+ description={propSchema.description}
901
+ error={error}
902
+ defaultValue={propSchema.default}
903
+ type={type as "number" | "integer"}
904
+ />
905
+ );
906
+
907
+ case "array":
908
+ return (
909
+ <ArrayField
910
+ propSchema={propSchema}
911
+ value={value}
912
+ onChange={onChange}
913
+ error={error}
914
+ disabled={isReadOnly}
915
+ label={label}
916
+ errors={errors}
917
+ path={path}
918
+ />
919
+ );
920
+
921
+ case "object":
922
+ return (
923
+ <ObjectField
924
+ propSchema={propSchema}
925
+ value={value}
926
+ onChange={onChange}
927
+ disabled={isReadOnly}
928
+ label={label}
929
+ errors={errors}
930
+ path={path}
931
+ />
932
+ );
933
+
934
+ default: // string
935
+ return (
936
+ <StringField
937
+ value={value}
938
+ onChange={onChange}
939
+ disabled={isReadOnly}
940
+ label={label}
941
+ isRequired={isRequired}
942
+ description={propSchema.description}
943
+ error={error}
944
+ defaultValue={propSchema.default}
945
+ format={propSchema.format}
946
+ maxLength={propSchema.maxLength}
947
+ />
948
+ );
949
+ }
950
+ });
951
+
952
+ FormField.displayName = "FormField";
953
+
954
+ // ---------------------------------------------------------------------------
955
+ // Main Component
956
+ // ---------------------------------------------------------------------------
957
+
958
+ /**
959
+ * Main JsonSchemaForm component.
960
+ * Renders a form based on a subset of JSON Schema specification.
961
+ * Supports primitive types, enums, secrets, objects, and arrays with recursion.
962
+ */
963
+ export function JsonSchemaForm({
964
+ schema,
965
+ values,
966
+ onChange,
967
+ errors = {},
968
+ disabled,
969
+ className,
970
+ }: JsonSchemaFormProps) {
971
+ const type = resolveType(schema);
972
+
973
+ const handleRootScalarChange = useCallback((newVal: unknown) => {
974
+ // If root is a scalar, values IS the value
975
+ onChange(newVal as Record<string, unknown>);
976
+ }, [onChange]);
977
+
978
+ // If it's a scalar at root, render a single FormField
979
+ if (type !== "object") {
980
+ return (
981
+ <div className={className}>
982
+ <FormField
983
+ propSchema={schema}
984
+ value={values}
985
+ label=""
986
+ path=""
987
+ onChange={handleRootScalarChange}
988
+ disabled={disabled}
989
+ errors={errors}
990
+ />
991
+ </div>
992
+ );
993
+ }
994
+
995
+ // Memoize to avoid re-renders when parent provides new object references
996
+ const properties = useMemo(() => schema.properties ?? {}, [schema.properties]);
997
+ const requiredFields = useMemo(
998
+ () => new Set(schema.required ?? []),
999
+ [schema.required],
1000
+ );
1001
+
1002
+ const handleFieldChange = useCallback(
1003
+ (key: string, value: unknown) => {
1004
+ onChange({ ...values, [key]: value });
1005
+ },
1006
+ [onChange, values],
1007
+ );
1008
+
1009
+ if (Object.keys(properties).length === 0) {
1010
+ return (
1011
+ <div
1012
+ className={cn(
1013
+ "py-4 text-center text-sm text-muted-foreground",
1014
+ className,
1015
+ )}
1016
+ >
1017
+ No configuration options available.
1018
+ </div>
1019
+ );
1020
+ }
1021
+
1022
+ return (
1023
+ <div className={cn("space-y-6", className)}>
1024
+ {Object.entries(properties).map(([key, propSchema]) => {
1025
+ const value = values[key];
1026
+ const isRequired = requiredFields.has(key);
1027
+ const error = errors[`/${key}`];
1028
+ const label = labelFromKey(key, propSchema);
1029
+ const path = `/${key}`;
1030
+
1031
+ return (
1032
+ <FormField
1033
+ key={key}
1034
+ propSchema={propSchema}
1035
+ value={value}
1036
+ onChange={(val) => handleFieldChange(key, val)}
1037
+ error={error}
1038
+ disabled={disabled}
1039
+ label={label}
1040
+ isRequired={isRequired}
1041
+ errors={errors}
1042
+ path={path}
1043
+ />
1044
+ );
1045
+ })}
1046
+ </div>
1047
+ );
1048
+ }