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.
- package/.dockerignore +10 -0
- package/.env.example +3 -0
- package/.github/workflows/publish-cli.yml +49 -0
- package/.mailmap +1 -0
- package/AGENTS.md +148 -0
- package/CONTRIBUTING.md +75 -0
- package/Dockerfile +59 -0
- package/Dockerfile.onboard-smoke +42 -0
- package/LICENSE +21 -0
- package/README.md +93 -0
- package/cli/esbuild.config.mjs +11 -0
- package/cli/package.json +24 -0
- package/cli/scripts/build-cli.mjs +5 -0
- package/cli/src/index.ts +27 -0
- package/docker-compose.quickstart.yml +18 -0
- package/docker-compose.untrusted-review.yml +33 -0
- package/docker-compose.yml +38 -0
- package/package.json +56 -0
- package/patches/embedded-postgres@18.1.0-beta.16.patch +0 -0
- package/pnpm-workspace.yaml +4 -0
- package/releases/.gitkeep +0 -0
- package/releases/v0.0.1.md +36 -0
- package/releases/v0.2.7.md +15 -0
- package/releases/v0.3.0.md +54 -0
- package/releases/v0.3.1.md +55 -0
- package/releases/v2026.318.0.md +66 -0
- package/releases/v2026.325.0.md +78 -0
- package/report/2026-03-13-08-46-token-optimization-implementation.md +48 -0
- package/scripts/backup-db.sh +17 -0
- package/scripts/build-npm.sh +80 -0
- package/scripts/check-forbidden-tokens.mjs +115 -0
- package/scripts/clean-onboard-git.sh +14 -0
- package/scripts/clean-onboard-npm.sh +13 -0
- package/scripts/clean-onboard-ref.sh +86 -0
- package/scripts/create-github-release.sh +99 -0
- package/scripts/dev-runner-paths.mjs +38 -0
- package/scripts/dev-runner.mjs +606 -0
- package/scripts/docker-onboard-smoke.sh +306 -0
- package/scripts/ensure-plugin-build-deps.mjs +47 -0
- package/scripts/generate-company-assets.ts +365 -0
- package/scripts/generate-npm-package-json.mjs +113 -0
- package/scripts/generate-org-chart-images.ts +694 -0
- package/scripts/generate-org-chart-satori-comparison.ts +225 -0
- package/scripts/generate-ui-package-json.mjs +31 -0
- package/scripts/kill-dev.sh +71 -0
- package/scripts/migrate-inline-env-secrets.ts +126 -0
- package/scripts/prepare-server-ui-dist.sh +22 -0
- package/scripts/provision-worktree.sh +333 -0
- package/scripts/release-lib.sh +306 -0
- package/scripts/release-package-map.mjs +169 -0
- package/scripts/release.sh +312 -0
- package/scripts/rollback-latest.sh +111 -0
- package/scripts/smoke/openclaw-docker-ui.sh +329 -0
- package/scripts/smoke/openclaw-gateway-e2e.sh +954 -0
- package/scripts/smoke/openclaw-join.sh +295 -0
- package/scripts/smoke/openclaw-sse-standalone.sh +146 -0
- package/scripts/workspace-compat.mjs +60 -0
- package/server/CHANGELOG.md +130 -0
- package/server/package.json +96 -0
- package/server/scripts/copy-onboarding-assets.mjs +10 -0
- package/server/scripts/dev-watch.ts +33 -0
- package/server/src/__tests__/activity-routes.test.ts +70 -0
- package/server/src/__tests__/adapter-models.test.ts +105 -0
- package/server/src/__tests__/adapter-session-codecs.test.ts +194 -0
- package/server/src/__tests__/agent-auth-jwt.test.ts +79 -0
- package/server/src/__tests__/agent-instructions-routes.test.ts +318 -0
- package/server/src/__tests__/agent-instructions-service.test.ts +361 -0
- package/server/src/__tests__/agent-permissions-routes.test.ts +275 -0
- package/server/src/__tests__/agent-shortname-collision.test.ts +69 -0
- package/server/src/__tests__/agent-skill-contract.test.ts +50 -0
- package/server/src/__tests__/agent-skills-routes.test.ts +462 -0
- package/server/src/__tests__/app-hmr-port.test.ts +19 -0
- package/server/src/__tests__/approval-routes-idempotency.test.ts +110 -0
- package/server/src/__tests__/approvals-service.test.ts +107 -0
- package/server/src/__tests__/assets.test.ts +250 -0
- package/server/src/__tests__/attachment-types.test.ts +97 -0
- package/server/src/__tests__/board-mutation-guard.test.ts +105 -0
- package/server/src/__tests__/budgets-service.test.ts +311 -0
- package/server/src/__tests__/claude-local-adapter-environment.test.ts +92 -0
- package/server/src/__tests__/claude-local-adapter.test.ts +31 -0
- package/server/src/__tests__/claude-local-skill-sync.test.ts +111 -0
- package/server/src/__tests__/cli-auth-routes.test.ts +230 -0
- package/server/src/__tests__/codex-local-adapter-environment.test.ts +143 -0
- package/server/src/__tests__/codex-local-adapter.test.ts +253 -0
- package/server/src/__tests__/codex-local-execute.test.ts +391 -0
- package/server/src/__tests__/codex-local-skill-injection.test.ts +175 -0
- package/server/src/__tests__/codex-local-skill-sync.test.ts +123 -0
- package/server/src/__tests__/companies-route-path-guard.test.ts +56 -0
- package/server/src/__tests__/company-branding-route.test.ts +196 -0
- package/server/src/__tests__/company-portability-routes.test.ts +175 -0
- package/server/src/__tests__/company-portability.test.ts +2186 -0
- package/server/src/__tests__/company-skills-routes.test.ts +113 -0
- package/server/src/__tests__/company-skills.test.ts +229 -0
- package/server/src/__tests__/costs-service.test.ts +226 -0
- package/server/src/__tests__/cursor-local-adapter-environment.test.ts +196 -0
- package/server/src/__tests__/cursor-local-adapter.test.ts +406 -0
- package/server/src/__tests__/cursor-local-execute.test.ts +263 -0
- package/server/src/__tests__/cursor-local-skill-injection.test.ts +104 -0
- package/server/src/__tests__/cursor-local-skill-sync.test.ts +145 -0
- package/server/src/__tests__/dev-runner-paths.test.ts +25 -0
- package/server/src/__tests__/dev-server-status.test.ts +66 -0
- package/server/src/__tests__/dev-watch-ignore.test.ts +42 -0
- package/server/src/__tests__/documents.test.ts +29 -0
- package/server/src/__tests__/error-handler.test.ts +53 -0
- package/server/src/__tests__/execution-workspace-policy.test.ts +170 -0
- package/server/src/__tests__/forbidden-tokens.test.ts +77 -0
- package/server/src/__tests__/gemini-local-adapter-environment.test.ts +135 -0
- package/server/src/__tests__/gemini-local-adapter.test.ts +190 -0
- package/server/src/__tests__/gemini-local-execute.test.ts +172 -0
- package/server/src/__tests__/gemini-local-skill-sync.test.ts +90 -0
- package/server/src/__tests__/health.test.ts +16 -0
- package/server/src/__tests__/heartbeat-process-recovery.test.ts +256 -0
- package/server/src/__tests__/heartbeat-run-summary.test.ts +33 -0
- package/server/src/__tests__/heartbeat-workspace-session.test.ts +334 -0
- package/server/src/__tests__/helpers/embedded-postgres.ts +7 -0
- package/server/src/__tests__/hire-hook.test.ts +181 -0
- package/server/src/__tests__/instance-settings-routes.test.ts +156 -0
- package/server/src/__tests__/invite-accept-gateway-defaults.test.ts +119 -0
- package/server/src/__tests__/invite-accept-replay.test.ts +92 -0
- package/server/src/__tests__/invite-expiry.test.ts +10 -0
- package/server/src/__tests__/invite-join-grants.test.ts +57 -0
- package/server/src/__tests__/invite-join-manager.test.ts +33 -0
- package/server/src/__tests__/invite-onboarding-text.test.ts +116 -0
- package/server/src/__tests__/issue-comment-reopen-routes.test.ts +146 -0
- package/server/src/__tests__/issue-goal-fallback.test.ts +99 -0
- package/server/src/__tests__/issues-checkout-wakeup.test.ts +48 -0
- package/server/src/__tests__/issues-goal-context-routes.test.ts +187 -0
- package/server/src/__tests__/issues-service.test.ts +317 -0
- package/server/src/__tests__/issues-user-context.test.ts +113 -0
- package/server/src/__tests__/log-redaction.test.ts +74 -0
- package/server/src/__tests__/monthly-spend-service.test.ts +90 -0
- package/server/src/__tests__/normalize-agent-mention-token.test.ts +41 -0
- package/server/src/__tests__/openclaw-gateway-adapter.test.ts +626 -0
- package/server/src/__tests__/openclaw-invite-prompt-route.test.ts +192 -0
- package/server/src/__tests__/opencode-local-adapter-environment.test.ts +97 -0
- package/server/src/__tests__/opencode-local-adapter.test.ts +226 -0
- package/server/src/__tests__/opencode-local-skill-sync.test.ts +91 -0
- package/server/src/__tests__/paperclip-env.test.ts +58 -0
- package/server/src/__tests__/paperclip-skill-utils.test.ts +63 -0
- package/server/src/__tests__/pi-local-adapter-environment.test.ts +102 -0
- package/server/src/__tests__/pi-local-skill-sync.test.ts +95 -0
- package/server/src/__tests__/plugin-dev-watcher.test.ts +68 -0
- package/server/src/__tests__/plugin-worker-manager.test.ts +43 -0
- package/server/src/__tests__/private-hostname-guard.test.ts +56 -0
- package/server/src/__tests__/project-shortname-resolution.test.ts +45 -0
- package/server/src/__tests__/quota-windows-service.test.ts +56 -0
- package/server/src/__tests__/quota-windows.test.ts +1109 -0
- package/server/src/__tests__/redaction.test.ts +66 -0
- package/server/src/__tests__/routines-e2e.test.ts +276 -0
- package/server/src/__tests__/routines-routes.test.ts +271 -0
- package/server/src/__tests__/routines-service.test.ts +424 -0
- package/server/src/__tests__/storage-local-provider.test.ts +78 -0
- package/server/src/__tests__/ui-branding.test.ts +82 -0
- package/server/src/__tests__/work-products.test.ts +95 -0
- package/server/src/__tests__/workspace-runtime.test.ts +1131 -0
- package/server/src/__tests__/worktree-config.test.ts +426 -0
- package/server/src/adapters/codex-models.ts +105 -0
- package/server/src/adapters/cursor-models.ts +171 -0
- package/server/src/adapters/http/execute.ts +42 -0
- package/server/src/adapters/http/index.ts +21 -0
- package/server/src/adapters/http/test.ts +116 -0
- package/server/src/adapters/index.ts +18 -0
- package/server/src/adapters/process/execute.ts +77 -0
- package/server/src/adapters/process/index.ts +24 -0
- package/server/src/adapters/process/test.ts +89 -0
- package/server/src/adapters/registry.ts +225 -0
- package/server/src/adapters/server-utils-compat.ts +57 -0
- package/server/src/adapters/types.ts +30 -0
- package/server/src/adapters/utils.ts +48 -0
- package/server/src/agent-auth-jwt.ts +141 -0
- package/server/src/app.ts +321 -0
- package/server/src/attachment-types.ts +74 -0
- package/server/src/auth/better-auth.ts +148 -0
- package/server/src/board-claim.ts +150 -0
- package/server/src/config-file.ts +17 -0
- package/server/src/config.ts +260 -0
- package/server/src/dev-server-status.ts +103 -0
- package/server/src/dev-watch-ignore.ts +36 -0
- package/server/src/errors.ts +34 -0
- package/server/src/home-paths.ts +95 -0
- package/server/src/index.ts +799 -0
- package/server/src/log-redaction.ts +146 -0
- package/server/src/middleware/auth.ts +178 -0
- package/server/src/middleware/board-mutation-guard.ts +66 -0
- package/server/src/middleware/error-handler.ts +71 -0
- package/server/src/middleware/index.ts +3 -0
- package/server/src/middleware/logger.ts +90 -0
- package/server/src/middleware/private-hostname-guard.ts +92 -0
- package/server/src/middleware/validate.ts +9 -0
- package/server/src/onboarding-assets/ceo/AGENTS.md +54 -0
- package/server/src/onboarding-assets/ceo/HEARTBEAT.md +72 -0
- package/server/src/onboarding-assets/ceo/SOUL.md +33 -0
- package/server/src/onboarding-assets/ceo/TOOLS.md +3 -0
- package/server/src/onboarding-assets/default/AGENTS.md +3 -0
- package/server/src/paths.ts +34 -0
- package/server/src/realtime/live-events-ws.ts +274 -0
- package/server/src/redaction.ts +59 -0
- package/server/src/routes/access.ts +2888 -0
- package/server/src/routes/activity.ts +89 -0
- package/server/src/routes/agents.ts +2313 -0
- package/server/src/routes/approvals.ts +346 -0
- package/server/src/routes/assets.ts +341 -0
- package/server/src/routes/authz.ts +52 -0
- package/server/src/routes/companies.ts +343 -0
- package/server/src/routes/company-skills.ts +300 -0
- package/server/src/routes/costs.ts +335 -0
- package/server/src/routes/dashboard.ts +19 -0
- package/server/src/routes/execution-workspaces.ts +182 -0
- package/server/src/routes/goals.ts +107 -0
- package/server/src/routes/health.ts +94 -0
- package/server/src/routes/index.ts +17 -0
- package/server/src/routes/instance-settings.ts +95 -0
- package/server/src/routes/issues-checkout-wakeup.ts +14 -0
- package/server/src/routes/issues.ts +1680 -0
- package/server/src/routes/llms.ts +86 -0
- package/server/src/routes/org-chart-svg.ts +777 -0
- package/server/src/routes/plugin-ui-static.ts +497 -0
- package/server/src/routes/plugins.ts +2220 -0
- package/server/src/routes/projects.ts +295 -0
- package/server/src/routes/routines.ts +300 -0
- package/server/src/routes/secrets.ts +166 -0
- package/server/src/routes/sidebar-badges.ts +52 -0
- package/server/src/secrets/external-stub-providers.ts +32 -0
- package/server/src/secrets/local-encrypted-provider.ts +135 -0
- package/server/src/secrets/provider-registry.ts +31 -0
- package/server/src/secrets/types.ts +23 -0
- package/server/src/services/access.ts +381 -0
- package/server/src/services/activity-log.ts +95 -0
- package/server/src/services/activity.ts +164 -0
- package/server/src/services/agent-instructions.ts +735 -0
- package/server/src/services/agent-permissions.ts +27 -0
- package/server/src/services/agents.ts +694 -0
- package/server/src/services/approvals.ts +273 -0
- package/server/src/services/assets.ts +23 -0
- package/server/src/services/board-auth.ts +355 -0
- package/server/src/services/budgets.ts +959 -0
- package/server/src/services/companies.ts +313 -0
- package/server/src/services/company-export-readme.ts +173 -0
- package/server/src/services/company-portability.ts +4263 -0
- package/server/src/services/company-skills.ts +2356 -0
- package/server/src/services/costs.ts +365 -0
- package/server/src/services/cron.ts +373 -0
- package/server/src/services/dashboard.ts +110 -0
- package/server/src/services/default-agent-instructions.ts +27 -0
- package/server/src/services/documents.ts +434 -0
- package/server/src/services/execution-workspace-policy.ts +210 -0
- package/server/src/services/execution-workspaces.ts +100 -0
- package/server/src/services/finance.ts +135 -0
- package/server/src/services/goals.ts +81 -0
- package/server/src/services/heartbeat-run-summary.ts +35 -0
- package/server/src/services/heartbeat.ts +3863 -0
- package/server/src/services/hire-hook.ts +114 -0
- package/server/src/services/index.ts +32 -0
- package/server/src/services/instance-settings.ts +138 -0
- package/server/src/services/issue-approvals.ts +175 -0
- package/server/src/services/issue-assignment-wakeup.ts +48 -0
- package/server/src/services/issue-goal-fallback.ts +56 -0
- package/server/src/services/issues.ts +1828 -0
- package/server/src/services/live-events.ts +55 -0
- package/server/src/services/plugin-capability-validator.ts +450 -0
- package/server/src/services/plugin-config-validator.ts +55 -0
- package/server/src/services/plugin-dev-watcher.ts +339 -0
- package/server/src/services/plugin-event-bus.ts +413 -0
- package/server/src/services/plugin-host-service-cleanup.ts +59 -0
- package/server/src/services/plugin-host-services.ts +1132 -0
- package/server/src/services/plugin-job-coordinator.ts +261 -0
- package/server/src/services/plugin-job-scheduler.ts +753 -0
- package/server/src/services/plugin-job-store.ts +466 -0
- package/server/src/services/plugin-lifecycle.ts +822 -0
- package/server/src/services/plugin-loader.ts +1955 -0
- package/server/src/services/plugin-log-retention.ts +87 -0
- package/server/src/services/plugin-manifest-validator.ts +164 -0
- package/server/src/services/plugin-registry.ts +683 -0
- package/server/src/services/plugin-runtime-sandbox.ts +222 -0
- package/server/src/services/plugin-secrets-handler.ts +355 -0
- package/server/src/services/plugin-state-store.ts +238 -0
- package/server/src/services/plugin-stream-bus.ts +81 -0
- package/server/src/services/plugin-tool-dispatcher.ts +449 -0
- package/server/src/services/plugin-tool-registry.ts +450 -0
- package/server/src/services/plugin-worker-manager.ts +1343 -0
- package/server/src/services/projects.ts +860 -0
- package/server/src/services/quota-windows.ts +65 -0
- package/server/src/services/routines.ts +1269 -0
- package/server/src/services/run-log-store.ts +156 -0
- package/server/src/services/secrets.ts +370 -0
- package/server/src/services/sidebar-badges.ts +56 -0
- package/server/src/services/work-products.ts +124 -0
- package/server/src/services/workspace-operation-log-store.ts +156 -0
- package/server/src/services/workspace-operations.ts +262 -0
- package/server/src/services/workspace-runtime.ts +1565 -0
- package/server/src/startup-banner.ts +176 -0
- package/server/src/storage/index.ts +35 -0
- package/server/src/storage/local-disk-provider.ts +89 -0
- package/server/src/storage/provider-registry.ts +18 -0
- package/server/src/storage/s3-provider.ts +153 -0
- package/server/src/storage/service.ts +131 -0
- package/server/src/storage/types.ts +63 -0
- package/server/src/ui-branding.ts +217 -0
- package/server/src/version.ts +10 -0
- package/server/src/worktree-config.ts +468 -0
- package/server/tsconfig.json +9 -0
- package/server/vitest.config.ts +7 -0
- package/skills/paperclip/SKILL.md +365 -0
- package/skills/paperclip/references/api-reference.md +647 -0
- package/skills/paperclip/references/company-skills.md +193 -0
- package/skills/paperclip-create-agent/SKILL.md +142 -0
- package/skills/paperclip-create-agent/references/api-reference.md +105 -0
- package/skills/paperclip-create-plugin/SKILL.md +102 -0
- package/skills/para-memory-files/SKILL.md +104 -0
- package/skills/para-memory-files/references/schemas.md +35 -0
- package/tests/e2e/onboarding.spec.ts +142 -0
- package/tests/e2e/playwright.config.ts +35 -0
- package/tests/release-smoke/docker-auth-onboarding.spec.ts +141 -0
- package/tests/release-smoke/playwright.config.ts +28 -0
- package/tsconfig.base.json +18 -0
- package/tsconfig.json +18 -0
- package/ui/README.md +12 -0
- package/ui/components.json +21 -0
- package/ui/index.html +47 -0
- package/ui/package.json +73 -0
- package/ui/public/android-chrome-192x192.png +0 -0
- package/ui/public/android-chrome-512x512.png +0 -0
- package/ui/public/apple-touch-icon.png +0 -0
- package/ui/public/brands/opencode-logo-dark-square.svg +18 -0
- package/ui/public/brands/opencode-logo-light-square.svg +18 -0
- package/ui/public/favicon-16x16.png +0 -0
- package/ui/public/favicon-32x32.png +0 -0
- package/ui/public/favicon.ico +0 -0
- package/ui/public/favicon.svg +9 -0
- package/ui/public/site.webmanifest +30 -0
- package/ui/public/sprites/1-D-1.png +0 -0
- package/ui/public/sprites/1-D-2.png +0 -0
- package/ui/public/sprites/1-D-3.png +0 -0
- package/ui/public/sprites/1-L-1.png +0 -0
- package/ui/public/sprites/1-R-1.png +0 -0
- package/ui/public/sprites/10-D-1.png +0 -0
- package/ui/public/sprites/10-D-2.png +0 -0
- package/ui/public/sprites/10-D-3.png +0 -0
- package/ui/public/sprites/10-L-1.png +0 -0
- package/ui/public/sprites/10-R-1.png +0 -0
- package/ui/public/sprites/11-D-1.png +0 -0
- package/ui/public/sprites/11-D-2.png +0 -0
- package/ui/public/sprites/11-D-3.png +0 -0
- package/ui/public/sprites/11-L-1.png +0 -0
- package/ui/public/sprites/11-R-1.png +0 -0
- package/ui/public/sprites/12-D-1.png +0 -0
- package/ui/public/sprites/12-D-2.png +0 -0
- package/ui/public/sprites/12-D-3.png +0 -0
- package/ui/public/sprites/12-L-1.png +0 -0
- package/ui/public/sprites/12-R-1.png +0 -0
- package/ui/public/sprites/13-D-1.png +0 -0
- package/ui/public/sprites/13-D-2.png +0 -0
- package/ui/public/sprites/13-D-3.png +0 -0
- package/ui/public/sprites/13-L-1.png +0 -0
- package/ui/public/sprites/13-R-1.png +0 -0
- package/ui/public/sprites/14-D-1.png +0 -0
- package/ui/public/sprites/14-D-2.png +0 -0
- package/ui/public/sprites/14-D-3.png +0 -0
- package/ui/public/sprites/14-L-1.png +0 -0
- package/ui/public/sprites/14-R-1.png +0 -0
- package/ui/public/sprites/2-D-1.png +0 -0
- package/ui/public/sprites/2-D-2.png +0 -0
- package/ui/public/sprites/2-D-3.png +0 -0
- package/ui/public/sprites/2-L-1.png +0 -0
- package/ui/public/sprites/2-R-1.png +0 -0
- package/ui/public/sprites/3-D-1.png +0 -0
- package/ui/public/sprites/3-D-2.png +0 -0
- package/ui/public/sprites/3-D-3.png +0 -0
- package/ui/public/sprites/3-L-1.png +0 -0
- package/ui/public/sprites/3-R-1.png +0 -0
- package/ui/public/sprites/4-D-1.png +0 -0
- package/ui/public/sprites/4-D-2.png +0 -0
- package/ui/public/sprites/4-D-3.png +0 -0
- package/ui/public/sprites/4-L-1.png +0 -0
- package/ui/public/sprites/4-R-1.png +0 -0
- package/ui/public/sprites/5-D-1.png +0 -0
- package/ui/public/sprites/5-D-2.png +0 -0
- package/ui/public/sprites/5-D-3.png +0 -0
- package/ui/public/sprites/5-L-1.png +0 -0
- package/ui/public/sprites/5-R-1.png +0 -0
- package/ui/public/sprites/6-D-1.png +0 -0
- package/ui/public/sprites/6-D-2.png +0 -0
- package/ui/public/sprites/6-D-3.png +0 -0
- package/ui/public/sprites/6-L-1.png +0 -0
- package/ui/public/sprites/6-R-1.png +0 -0
- package/ui/public/sprites/7-D-1.png +0 -0
- package/ui/public/sprites/7-D-2.png +0 -0
- package/ui/public/sprites/7-D-3.png +0 -0
- package/ui/public/sprites/7-L-1.png +0 -0
- package/ui/public/sprites/7-R-1.png +0 -0
- package/ui/public/sprites/8-D-1.png +0 -0
- package/ui/public/sprites/8-D-2.png +0 -0
- package/ui/public/sprites/8-D-3.png +0 -0
- package/ui/public/sprites/8-L-1.png +0 -0
- package/ui/public/sprites/8-R-1.png +0 -0
- package/ui/public/sprites/9-D-1.png +0 -0
- package/ui/public/sprites/9-D-2.png +0 -0
- package/ui/public/sprites/9-D-3.png +0 -0
- package/ui/public/sprites/9-L-1.png +0 -0
- package/ui/public/sprites/9-R-1.png +0 -0
- package/ui/public/sprites/ceo-lobster.png +0 -0
- package/ui/public/sw.js +42 -0
- package/ui/public/worktree-favicon-16x16.png +0 -0
- package/ui/public/worktree-favicon-32x32.png +0 -0
- package/ui/public/worktree-favicon.ico +0 -0
- package/ui/public/worktree-favicon.svg +9 -0
- package/ui/src/App.tsx +354 -0
- package/ui/src/adapters/claude-local/config-fields.tsx +138 -0
- package/ui/src/adapters/claude-local/index.ts +13 -0
- package/ui/src/adapters/codex-local/config-fields.tsx +104 -0
- package/ui/src/adapters/codex-local/index.ts +13 -0
- package/ui/src/adapters/cursor/config-fields.tsx +49 -0
- package/ui/src/adapters/cursor/index.ts +13 -0
- package/ui/src/adapters/gemini-local/config-fields.tsx +51 -0
- package/ui/src/adapters/gemini-local/index.ts +13 -0
- package/ui/src/adapters/http/build-config.ts +9 -0
- package/ui/src/adapters/http/config-fields.tsx +38 -0
- package/ui/src/adapters/http/index.ts +12 -0
- package/ui/src/adapters/http/parse-stdout.ts +5 -0
- package/ui/src/adapters/index.ts +9 -0
- package/ui/src/adapters/local-workspace-runtime-fields.tsx +5 -0
- package/ui/src/adapters/openclaw-gateway/config-fields.tsx +237 -0
- package/ui/src/adapters/openclaw-gateway/index.ts +13 -0
- package/ui/src/adapters/opencode-local/config-fields.tsx +72 -0
- package/ui/src/adapters/opencode-local/index.ts +13 -0
- package/ui/src/adapters/pi-local/config-fields.tsx +49 -0
- package/ui/src/adapters/pi-local/index.ts +13 -0
- package/ui/src/adapters/process/build-config.ts +18 -0
- package/ui/src/adapters/process/config-fields.tsx +77 -0
- package/ui/src/adapters/process/index.ts +12 -0
- package/ui/src/adapters/process/parse-stdout.ts +5 -0
- package/ui/src/adapters/registry.ts +34 -0
- package/ui/src/adapters/runtime-json-fields.tsx +122 -0
- package/ui/src/adapters/transcript.test.ts +30 -0
- package/ui/src/adapters/transcript.ts +62 -0
- package/ui/src/adapters/types.ts +34 -0
- package/ui/src/api/access.ts +160 -0
- package/ui/src/api/activity.ts +37 -0
- package/ui/src/api/agents.ts +194 -0
- package/ui/src/api/approvals.ts +25 -0
- package/ui/src/api/assets.ts +30 -0
- package/ui/src/api/auth.ts +74 -0
- package/ui/src/api/budgets.ts +21 -0
- package/ui/src/api/client.ts +50 -0
- package/ui/src/api/companies.ts +59 -0
- package/ui/src/api/companySkills.ts +55 -0
- package/ui/src/api/costs.ts +60 -0
- package/ui/src/api/dashboard.ts +7 -0
- package/ui/src/api/execution-workspaces.ts +27 -0
- package/ui/src/api/goals.ts +12 -0
- package/ui/src/api/health.ts +41 -0
- package/ui/src/api/heartbeats.ts +62 -0
- package/ui/src/api/index.ts +18 -0
- package/ui/src/api/instanceSettings.ts +19 -0
- package/ui/src/api/issues.ts +115 -0
- package/ui/src/api/plugins.ts +424 -0
- package/ui/src/api/projects.ts +34 -0
- package/ui/src/api/routines.ts +59 -0
- package/ui/src/api/secrets.ts +26 -0
- package/ui/src/api/sidebarBadges.ts +7 -0
- package/ui/src/components/AccountingModelCard.tsx +69 -0
- package/ui/src/components/ActiveAgentsPanel.tsx +157 -0
- package/ui/src/components/ActivityCharts.tsx +264 -0
- package/ui/src/components/ActivityRow.tsx +147 -0
- package/ui/src/components/AgentActionButtons.tsx +51 -0
- package/ui/src/components/AgentConfigForm.tsx +1468 -0
- package/ui/src/components/AgentIconPicker.tsx +81 -0
- package/ui/src/components/AgentProperties.tsx +107 -0
- package/ui/src/components/ApprovalCard.tsx +107 -0
- package/ui/src/components/ApprovalPayload.tsx +134 -0
- package/ui/src/components/AsciiArtAnimation.tsx +355 -0
- package/ui/src/components/BillerSpendCard.tsx +146 -0
- package/ui/src/components/BreadcrumbBar.tsx +113 -0
- package/ui/src/components/BudgetIncidentCard.tsx +101 -0
- package/ui/src/components/BudgetPolicyCard.tsx +220 -0
- package/ui/src/components/BudgetSidebarMarker.tsx +13 -0
- package/ui/src/components/ClaudeSubscriptionPanel.tsx +141 -0
- package/ui/src/components/CodexSubscriptionPanel.tsx +158 -0
- package/ui/src/components/CommandPalette.tsx +239 -0
- package/ui/src/components/CommentThread.tsx +503 -0
- package/ui/src/components/CompanyPatternIcon.tsx +212 -0
- package/ui/src/components/CompanyRail.tsx +329 -0
- package/ui/src/components/CompanySwitcher.tsx +81 -0
- package/ui/src/components/CopyText.tsx +56 -0
- package/ui/src/components/DevRestartBanner.tsx +89 -0
- package/ui/src/components/EmptyState.tsx +27 -0
- package/ui/src/components/EntityRow.tsx +69 -0
- package/ui/src/components/FilterBar.tsx +39 -0
- package/ui/src/components/FinanceBillerCard.tsx +45 -0
- package/ui/src/components/FinanceKindCard.tsx +44 -0
- package/ui/src/components/FinanceTimelineCard.tsx +72 -0
- package/ui/src/components/GoalProperties.tsx +165 -0
- package/ui/src/components/GoalTree.tsx +118 -0
- package/ui/src/components/Identity.tsx +39 -0
- package/ui/src/components/InlineEditor.tsx +248 -0
- package/ui/src/components/InlineEntitySelector.tsx +206 -0
- package/ui/src/components/InstanceSidebar.tsx +53 -0
- package/ui/src/components/IssueDocumentsSection.tsx +892 -0
- package/ui/src/components/IssueProperties.tsx +621 -0
- package/ui/src/components/IssueRow.tsx +149 -0
- package/ui/src/components/IssueWorkspaceCard.tsx +404 -0
- package/ui/src/components/IssuesList.tsx +889 -0
- package/ui/src/components/JsonSchemaForm.tsx +1048 -0
- package/ui/src/components/KanbanBoard.tsx +275 -0
- package/ui/src/components/Layout.tsx +441 -0
- package/ui/src/components/LiveRunWidget.tsx +160 -0
- package/ui/src/components/MarkdownBody.test.tsx +50 -0
- package/ui/src/components/MarkdownBody.tsx +152 -0
- package/ui/src/components/MarkdownEditor.tsx +622 -0
- package/ui/src/components/MetricCard.tsx +53 -0
- package/ui/src/components/MobileBottomNav.tsx +123 -0
- package/ui/src/components/NewAgentDialog.tsx +223 -0
- package/ui/src/components/NewGoalDialog.tsx +283 -0
- package/ui/src/components/NewIssueDialog.tsx +1473 -0
- package/ui/src/components/NewProjectDialog.tsx +451 -0
- package/ui/src/components/OnboardingWizard.tsx +1392 -0
- package/ui/src/components/OpenCodeLogoIcon.tsx +22 -0
- package/ui/src/components/PackageFileTree.tsx +318 -0
- package/ui/src/components/PageSkeleton.tsx +180 -0
- package/ui/src/components/PageTabBar.tsx +45 -0
- package/ui/src/components/PathInstructionsModal.tsx +143 -0
- package/ui/src/components/PriorityIcon.tsx +77 -0
- package/ui/src/components/ProjectProperties.tsx +1127 -0
- package/ui/src/components/PropertiesPanel.tsx +29 -0
- package/ui/src/components/ProviderQuotaCard.tsx +417 -0
- package/ui/src/components/QuotaBar.tsx +65 -0
- package/ui/src/components/ReportsToPicker.tsx +127 -0
- package/ui/src/components/ScheduleEditor.tsx +344 -0
- package/ui/src/components/ScrollToBottom.tsx +79 -0
- package/ui/src/components/Sidebar.tsx +130 -0
- package/ui/src/components/SidebarAgents.tsx +146 -0
- package/ui/src/components/SidebarNavItem.tsx +92 -0
- package/ui/src/components/SidebarProjects.tsx +234 -0
- package/ui/src/components/SidebarSection.tsx +17 -0
- package/ui/src/components/StatusBadge.tsx +15 -0
- package/ui/src/components/StatusIcon.tsx +71 -0
- package/ui/src/components/SwipeToArchive.tsx +152 -0
- package/ui/src/components/ToastViewport.tsx +99 -0
- package/ui/src/components/WorktreeBanner.tsx +25 -0
- package/ui/src/components/agent-config-defaults.ts +31 -0
- package/ui/src/components/agent-config-primitives.tsx +476 -0
- package/ui/src/components/transcript/RunTranscriptView.test.tsx +84 -0
- package/ui/src/components/transcript/RunTranscriptView.tsx +1015 -0
- package/ui/src/components/transcript/useLiveRunTranscripts.ts +297 -0
- package/ui/src/components/ui/avatar.tsx +107 -0
- package/ui/src/components/ui/badge.tsx +48 -0
- package/ui/src/components/ui/breadcrumb.tsx +109 -0
- package/ui/src/components/ui/button.tsx +64 -0
- package/ui/src/components/ui/card.tsx +92 -0
- package/ui/src/components/ui/checkbox.tsx +32 -0
- package/ui/src/components/ui/collapsible.tsx +33 -0
- package/ui/src/components/ui/command.tsx +194 -0
- package/ui/src/components/ui/dialog.tsx +156 -0
- package/ui/src/components/ui/dropdown-menu.tsx +257 -0
- package/ui/src/components/ui/input.tsx +21 -0
- package/ui/src/components/ui/label.tsx +22 -0
- package/ui/src/components/ui/popover.tsx +88 -0
- package/ui/src/components/ui/scroll-area.tsx +56 -0
- package/ui/src/components/ui/select.tsx +188 -0
- package/ui/src/components/ui/separator.tsx +28 -0
- package/ui/src/components/ui/sheet.tsx +143 -0
- package/ui/src/components/ui/skeleton.tsx +13 -0
- package/ui/src/components/ui/tabs.tsx +89 -0
- package/ui/src/components/ui/textarea.tsx +18 -0
- package/ui/src/components/ui/tooltip.tsx +57 -0
- package/ui/src/components/visual-office/AgentAvatar.tsx +99 -0
- package/ui/src/components/visual-office/OfficeViewExact.tsx +417 -0
- package/ui/src/components/visual-office/i18n.ts +52 -0
- package/ui/src/components/visual-office/office-view/CliUsagePanel.tsx +240 -0
- package/ui/src/components/visual-office/office-view/VirtualPadOverlay.tsx +104 -0
- package/ui/src/components/visual-office/office-view/buildScene-break-room.ts +248 -0
- package/ui/src/components/visual-office/office-view/buildScene-ceo-hallway.ts +345 -0
- package/ui/src/components/visual-office/office-view/buildScene-department-agent.ts +242 -0
- package/ui/src/components/visual-office/office-view/buildScene-departments.ts +360 -0
- package/ui/src/components/visual-office/office-view/buildScene-final-layers.ts +113 -0
- package/ui/src/components/visual-office/office-view/buildScene-types.ts +91 -0
- package/ui/src/components/visual-office/office-view/buildScene.ts +232 -0
- package/ui/src/components/visual-office/office-view/drawing-core.ts +374 -0
- package/ui/src/components/visual-office/office-view/drawing-furniture-a.ts +338 -0
- package/ui/src/components/visual-office/office-view/drawing-furniture-b.ts +241 -0
- package/ui/src/components/visual-office/office-view/model.ts +301 -0
- package/ui/src/components/visual-office/office-view/officeTicker.ts +455 -0
- package/ui/src/components/visual-office/office-view/officeTickerRoomAndDelivery.ts +133 -0
- package/ui/src/components/visual-office/office-view/themes-locale.ts +460 -0
- package/ui/src/components/visual-office/office-view/useCliUsage.ts +37 -0
- package/ui/src/components/visual-office/office-view/useOfficeDeliveryEffects.ts +465 -0
- package/ui/src/components/visual-office/office-view/useOfficePixiRuntime.ts +282 -0
- package/ui/src/components/visual-office/types.ts +123 -0
- package/ui/src/context/BreadcrumbContext.tsx +44 -0
- package/ui/src/context/CompanyContext.tsx +151 -0
- package/ui/src/context/DialogContext.tsx +135 -0
- package/ui/src/context/LiveUpdatesProvider.test.ts +119 -0
- package/ui/src/context/LiveUpdatesProvider.tsx +760 -0
- package/ui/src/context/PanelContext.tsx +73 -0
- package/ui/src/context/SidebarContext.tsx +43 -0
- package/ui/src/context/ThemeContext.tsx +83 -0
- package/ui/src/context/ToastContext.tsx +172 -0
- package/ui/src/fixtures/runTranscriptFixtures.ts +226 -0
- package/ui/src/hooks/useAgentOrder.ts +105 -0
- package/ui/src/hooks/useAutosaveIndicator.ts +72 -0
- package/ui/src/hooks/useCompanyPageMemory.test.ts +90 -0
- package/ui/src/hooks/useCompanyPageMemory.ts +79 -0
- package/ui/src/hooks/useDateRange.ts +120 -0
- package/ui/src/hooks/useInboxBadge.ts +132 -0
- package/ui/src/hooks/useKeyboardShortcuts.ts +40 -0
- package/ui/src/hooks/useProjectOrder.ts +106 -0
- package/ui/src/index.css +770 -0
- package/ui/src/lib/agent-icons.ts +99 -0
- package/ui/src/lib/agent-order.ts +107 -0
- package/ui/src/lib/agent-skills-state.test.ts +90 -0
- package/ui/src/lib/agent-skills-state.ts +41 -0
- package/ui/src/lib/assignees.test.ts +92 -0
- package/ui/src/lib/assignees.ts +82 -0
- package/ui/src/lib/color-contrast.ts +107 -0
- package/ui/src/lib/company-export-selection.test.ts +41 -0
- package/ui/src/lib/company-export-selection.ts +57 -0
- package/ui/src/lib/company-page-memory.ts +65 -0
- package/ui/src/lib/company-portability-sidebar.test.ts +101 -0
- package/ui/src/lib/company-portability-sidebar.ts +62 -0
- package/ui/src/lib/company-routes.ts +88 -0
- package/ui/src/lib/company-selection.test.ts +34 -0
- package/ui/src/lib/company-selection.ts +18 -0
- package/ui/src/lib/groupBy.ts +11 -0
- package/ui/src/lib/inbox.test.ts +404 -0
- package/ui/src/lib/inbox.ts +292 -0
- package/ui/src/lib/instance-settings.test.ts +26 -0
- package/ui/src/lib/instance-settings.ts +25 -0
- package/ui/src/lib/issueDetailBreadcrumb.ts +24 -0
- package/ui/src/lib/legacy-agent-config.test.ts +40 -0
- package/ui/src/lib/legacy-agent-config.ts +17 -0
- package/ui/src/lib/mention-aware-link-node.test.ts +50 -0
- package/ui/src/lib/mention-aware-link-node.ts +67 -0
- package/ui/src/lib/mention-chips.ts +168 -0
- package/ui/src/lib/mention-deletion.test.ts +87 -0
- package/ui/src/lib/mention-deletion.ts +143 -0
- package/ui/src/lib/model-utils.ts +16 -0
- package/ui/src/lib/onboarding-goal.test.ts +22 -0
- package/ui/src/lib/onboarding-goal.ts +18 -0
- package/ui/src/lib/onboarding-launch.test.ts +131 -0
- package/ui/src/lib/onboarding-launch.ts +54 -0
- package/ui/src/lib/onboarding-route.test.ts +80 -0
- package/ui/src/lib/onboarding-route.ts +51 -0
- package/ui/src/lib/portable-files.ts +42 -0
- package/ui/src/lib/project-order.ts +71 -0
- package/ui/src/lib/queryKeys.ts +140 -0
- package/ui/src/lib/recent-assignees.ts +36 -0
- package/ui/src/lib/router.tsx +76 -0
- package/ui/src/lib/routine-trigger-patch.test.ts +72 -0
- package/ui/src/lib/routine-trigger-patch.ts +31 -0
- package/ui/src/lib/status-colors.ts +108 -0
- package/ui/src/lib/timeAgo.ts +31 -0
- package/ui/src/lib/utils.ts +168 -0
- package/ui/src/lib/worktree-branding.ts +65 -0
- package/ui/src/lib/zip.test.ts +289 -0
- package/ui/src/lib/zip.ts +284 -0
- package/ui/src/main.tsx +67 -0
- package/ui/src/pages/Activity.tsx +141 -0
- package/ui/src/pages/AgentDetail.tsx +4053 -0
- package/ui/src/pages/Agents.tsx +415 -0
- package/ui/src/pages/ApprovalDetail.tsx +369 -0
- package/ui/src/pages/Approvals.tsx +132 -0
- package/ui/src/pages/Auth.tsx +180 -0
- package/ui/src/pages/BoardClaim.tsx +125 -0
- package/ui/src/pages/CliAuth.tsx +184 -0
- package/ui/src/pages/Companies.tsx +297 -0
- package/ui/src/pages/CompanyExport.tsx +1019 -0
- package/ui/src/pages/CompanyImport.tsx +1355 -0
- package/ui/src/pages/CompanySettings.tsx +661 -0
- package/ui/src/pages/CompanySkills.tsx +1171 -0
- package/ui/src/pages/Costs.tsx +1103 -0
- package/ui/src/pages/Dashboard.tsx +388 -0
- package/ui/src/pages/DesignGuide.tsx +1330 -0
- package/ui/src/pages/ExecutionWorkspaceDetail.tsx +82 -0
- package/ui/src/pages/GoalDetail.tsx +197 -0
- package/ui/src/pages/Goals.tsx +63 -0
- package/ui/src/pages/Inbox.tsx +1291 -0
- package/ui/src/pages/InstanceExperimentalSettings.tsx +139 -0
- package/ui/src/pages/InstanceGeneralSettings.tsx +104 -0
- package/ui/src/pages/InstanceSettings.tsx +284 -0
- package/ui/src/pages/InviteLanding.tsx +320 -0
- package/ui/src/pages/IssueDetail.tsx +1201 -0
- package/ui/src/pages/Issues.tsx +116 -0
- package/ui/src/pages/MyIssues.tsx +72 -0
- package/ui/src/pages/NewAgent.tsx +353 -0
- package/ui/src/pages/NotFound.tsx +66 -0
- package/ui/src/pages/Org.tsx +132 -0
- package/ui/src/pages/OrgChart.tsx +447 -0
- package/ui/src/pages/PluginManager.tsx +510 -0
- package/ui/src/pages/PluginPage.tsx +156 -0
- package/ui/src/pages/PluginSettings.tsx +836 -0
- package/ui/src/pages/ProjectDetail.tsx +633 -0
- package/ui/src/pages/Projects.tsx +87 -0
- package/ui/src/pages/RoutineDetail.tsx +1022 -0
- package/ui/src/pages/Routines.tsx +661 -0
- package/ui/src/pages/RunTranscriptUxLab.tsx +334 -0
- package/ui/src/pages/VisualOffice.tsx +243 -0
- package/ui/src/plugins/bridge-init.ts +69 -0
- package/ui/src/plugins/bridge.ts +476 -0
- package/ui/src/plugins/launchers.tsx +834 -0
- package/ui/src/plugins/slots.tsx +855 -0
- package/ui/tsconfig.json +21 -0
- package/ui/vite.config.ts +23 -0
- package/ui/vitest.config.ts +14 -0
- package/vitest.config.ts +11 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { and, eq, inArray, sql } from "drizzle-orm";
|
|
2
|
+
import type { Db } from "@corporateai/db";
|
|
3
|
+
import {
|
|
4
|
+
companyMemberships,
|
|
5
|
+
instanceUserRoles,
|
|
6
|
+
principalPermissionGrants,
|
|
7
|
+
} from "@corporateai/db";
|
|
8
|
+
import type { PermissionKey, PrincipalType } from "@corporateai/shared";
|
|
9
|
+
|
|
10
|
+
type MembershipRow = typeof companyMemberships.$inferSelect;
|
|
11
|
+
type GrantInput = {
|
|
12
|
+
permissionKey: PermissionKey;
|
|
13
|
+
scope?: Record<string, unknown> | null;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function accessService(db: Db) {
|
|
17
|
+
async function isInstanceAdmin(userId: string | null | undefined): Promise<boolean> {
|
|
18
|
+
if (!userId) return false;
|
|
19
|
+
const row = await db
|
|
20
|
+
.select({ id: instanceUserRoles.id })
|
|
21
|
+
.from(instanceUserRoles)
|
|
22
|
+
.where(and(eq(instanceUserRoles.userId, userId), eq(instanceUserRoles.role, "instance_admin")))
|
|
23
|
+
.then((rows) => rows[0] ?? null);
|
|
24
|
+
return Boolean(row);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function getMembership(
|
|
28
|
+
companyId: string,
|
|
29
|
+
principalType: PrincipalType,
|
|
30
|
+
principalId: string,
|
|
31
|
+
): Promise<MembershipRow | null> {
|
|
32
|
+
return db
|
|
33
|
+
.select()
|
|
34
|
+
.from(companyMemberships)
|
|
35
|
+
.where(
|
|
36
|
+
and(
|
|
37
|
+
eq(companyMemberships.companyId, companyId),
|
|
38
|
+
eq(companyMemberships.principalType, principalType),
|
|
39
|
+
eq(companyMemberships.principalId, principalId),
|
|
40
|
+
),
|
|
41
|
+
)
|
|
42
|
+
.then((rows) => rows[0] ?? null);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function hasPermission(
|
|
46
|
+
companyId: string,
|
|
47
|
+
principalType: PrincipalType,
|
|
48
|
+
principalId: string,
|
|
49
|
+
permissionKey: PermissionKey,
|
|
50
|
+
): Promise<boolean> {
|
|
51
|
+
const membership = await getMembership(companyId, principalType, principalId);
|
|
52
|
+
if (!membership || membership.status !== "active") return false;
|
|
53
|
+
const grant = await db
|
|
54
|
+
.select({ id: principalPermissionGrants.id })
|
|
55
|
+
.from(principalPermissionGrants)
|
|
56
|
+
.where(
|
|
57
|
+
and(
|
|
58
|
+
eq(principalPermissionGrants.companyId, companyId),
|
|
59
|
+
eq(principalPermissionGrants.principalType, principalType),
|
|
60
|
+
eq(principalPermissionGrants.principalId, principalId),
|
|
61
|
+
eq(principalPermissionGrants.permissionKey, permissionKey),
|
|
62
|
+
),
|
|
63
|
+
)
|
|
64
|
+
.then((rows) => rows[0] ?? null);
|
|
65
|
+
return Boolean(grant);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function canUser(
|
|
69
|
+
companyId: string,
|
|
70
|
+
userId: string | null | undefined,
|
|
71
|
+
permissionKey: PermissionKey,
|
|
72
|
+
): Promise<boolean> {
|
|
73
|
+
if (!userId) return false;
|
|
74
|
+
if (await isInstanceAdmin(userId)) return true;
|
|
75
|
+
return hasPermission(companyId, "user", userId, permissionKey);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function listMembers(companyId: string) {
|
|
79
|
+
return db
|
|
80
|
+
.select()
|
|
81
|
+
.from(companyMemberships)
|
|
82
|
+
.where(eq(companyMemberships.companyId, companyId))
|
|
83
|
+
.orderBy(sql`${companyMemberships.createdAt} desc`);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function listActiveUserMemberships(companyId: string) {
|
|
87
|
+
return db
|
|
88
|
+
.select()
|
|
89
|
+
.from(companyMemberships)
|
|
90
|
+
.where(
|
|
91
|
+
and(
|
|
92
|
+
eq(companyMemberships.companyId, companyId),
|
|
93
|
+
eq(companyMemberships.principalType, "user"),
|
|
94
|
+
eq(companyMemberships.status, "active"),
|
|
95
|
+
),
|
|
96
|
+
)
|
|
97
|
+
.orderBy(sql`${companyMemberships.createdAt} asc`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function setMemberPermissions(
|
|
101
|
+
companyId: string,
|
|
102
|
+
memberId: string,
|
|
103
|
+
grants: GrantInput[],
|
|
104
|
+
grantedByUserId: string | null,
|
|
105
|
+
) {
|
|
106
|
+
const member = await db
|
|
107
|
+
.select()
|
|
108
|
+
.from(companyMemberships)
|
|
109
|
+
.where(and(eq(companyMemberships.companyId, companyId), eq(companyMemberships.id, memberId)))
|
|
110
|
+
.then((rows) => rows[0] ?? null);
|
|
111
|
+
if (!member) return null;
|
|
112
|
+
|
|
113
|
+
await db.transaction(async (tx) => {
|
|
114
|
+
await tx
|
|
115
|
+
.delete(principalPermissionGrants)
|
|
116
|
+
.where(
|
|
117
|
+
and(
|
|
118
|
+
eq(principalPermissionGrants.companyId, companyId),
|
|
119
|
+
eq(principalPermissionGrants.principalType, member.principalType),
|
|
120
|
+
eq(principalPermissionGrants.principalId, member.principalId),
|
|
121
|
+
),
|
|
122
|
+
);
|
|
123
|
+
if (grants.length > 0) {
|
|
124
|
+
await tx.insert(principalPermissionGrants).values(
|
|
125
|
+
grants.map((grant) => ({
|
|
126
|
+
companyId,
|
|
127
|
+
principalType: member.principalType,
|
|
128
|
+
principalId: member.principalId,
|
|
129
|
+
permissionKey: grant.permissionKey,
|
|
130
|
+
scope: grant.scope ?? null,
|
|
131
|
+
grantedByUserId,
|
|
132
|
+
createdAt: new Date(),
|
|
133
|
+
updatedAt: new Date(),
|
|
134
|
+
})),
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
return member;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async function promoteInstanceAdmin(userId: string) {
|
|
143
|
+
const existing = await db
|
|
144
|
+
.select()
|
|
145
|
+
.from(instanceUserRoles)
|
|
146
|
+
.where(and(eq(instanceUserRoles.userId, userId), eq(instanceUserRoles.role, "instance_admin")))
|
|
147
|
+
.then((rows) => rows[0] ?? null);
|
|
148
|
+
if (existing) return existing;
|
|
149
|
+
return db
|
|
150
|
+
.insert(instanceUserRoles)
|
|
151
|
+
.values({
|
|
152
|
+
userId,
|
|
153
|
+
role: "instance_admin",
|
|
154
|
+
})
|
|
155
|
+
.returning()
|
|
156
|
+
.then((rows) => rows[0]);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function demoteInstanceAdmin(userId: string) {
|
|
160
|
+
return db
|
|
161
|
+
.delete(instanceUserRoles)
|
|
162
|
+
.where(and(eq(instanceUserRoles.userId, userId), eq(instanceUserRoles.role, "instance_admin")))
|
|
163
|
+
.returning()
|
|
164
|
+
.then((rows) => rows[0] ?? null);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function listUserCompanyAccess(userId: string) {
|
|
168
|
+
return db
|
|
169
|
+
.select()
|
|
170
|
+
.from(companyMemberships)
|
|
171
|
+
.where(and(eq(companyMemberships.principalType, "user"), eq(companyMemberships.principalId, userId)))
|
|
172
|
+
.orderBy(sql`${companyMemberships.createdAt} desc`);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async function setUserCompanyAccess(userId: string, companyIds: string[]) {
|
|
176
|
+
const existing = await listUserCompanyAccess(userId);
|
|
177
|
+
const existingByCompany = new Map(existing.map((row) => [row.companyId, row]));
|
|
178
|
+
const target = new Set(companyIds);
|
|
179
|
+
|
|
180
|
+
await db.transaction(async (tx) => {
|
|
181
|
+
const toDelete = existing.filter((row) => !target.has(row.companyId)).map((row) => row.id);
|
|
182
|
+
if (toDelete.length > 0) {
|
|
183
|
+
await tx.delete(companyMemberships).where(inArray(companyMemberships.id, toDelete));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
for (const companyId of target) {
|
|
187
|
+
if (existingByCompany.has(companyId)) continue;
|
|
188
|
+
await tx.insert(companyMemberships).values({
|
|
189
|
+
companyId,
|
|
190
|
+
principalType: "user",
|
|
191
|
+
principalId: userId,
|
|
192
|
+
status: "active",
|
|
193
|
+
membershipRole: "member",
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
return listUserCompanyAccess(userId);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async function ensureMembership(
|
|
202
|
+
companyId: string,
|
|
203
|
+
principalType: PrincipalType,
|
|
204
|
+
principalId: string,
|
|
205
|
+
membershipRole: string | null = "member",
|
|
206
|
+
status: "pending" | "active" | "suspended" = "active",
|
|
207
|
+
) {
|
|
208
|
+
const existing = await getMembership(companyId, principalType, principalId);
|
|
209
|
+
if (existing) {
|
|
210
|
+
if (existing.status !== status || existing.membershipRole !== membershipRole) {
|
|
211
|
+
const updated = await db
|
|
212
|
+
.update(companyMemberships)
|
|
213
|
+
.set({ status, membershipRole, updatedAt: new Date() })
|
|
214
|
+
.where(eq(companyMemberships.id, existing.id))
|
|
215
|
+
.returning()
|
|
216
|
+
.then((rows) => rows[0] ?? null);
|
|
217
|
+
return updated ?? existing;
|
|
218
|
+
}
|
|
219
|
+
return existing;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return db
|
|
223
|
+
.insert(companyMemberships)
|
|
224
|
+
.values({
|
|
225
|
+
companyId,
|
|
226
|
+
principalType,
|
|
227
|
+
principalId,
|
|
228
|
+
status,
|
|
229
|
+
membershipRole,
|
|
230
|
+
})
|
|
231
|
+
.returning()
|
|
232
|
+
.then((rows) => rows[0]);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
async function setPrincipalGrants(
|
|
236
|
+
companyId: string,
|
|
237
|
+
principalType: PrincipalType,
|
|
238
|
+
principalId: string,
|
|
239
|
+
grants: GrantInput[],
|
|
240
|
+
grantedByUserId: string | null,
|
|
241
|
+
) {
|
|
242
|
+
await db.transaction(async (tx) => {
|
|
243
|
+
await tx
|
|
244
|
+
.delete(principalPermissionGrants)
|
|
245
|
+
.where(
|
|
246
|
+
and(
|
|
247
|
+
eq(principalPermissionGrants.companyId, companyId),
|
|
248
|
+
eq(principalPermissionGrants.principalType, principalType),
|
|
249
|
+
eq(principalPermissionGrants.principalId, principalId),
|
|
250
|
+
),
|
|
251
|
+
);
|
|
252
|
+
if (grants.length === 0) return;
|
|
253
|
+
await tx.insert(principalPermissionGrants).values(
|
|
254
|
+
grants.map((grant) => ({
|
|
255
|
+
companyId,
|
|
256
|
+
principalType,
|
|
257
|
+
principalId,
|
|
258
|
+
permissionKey: grant.permissionKey,
|
|
259
|
+
scope: grant.scope ?? null,
|
|
260
|
+
grantedByUserId,
|
|
261
|
+
createdAt: new Date(),
|
|
262
|
+
updatedAt: new Date(),
|
|
263
|
+
})),
|
|
264
|
+
);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async function copyActiveUserMemberships(sourceCompanyId: string, targetCompanyId: string) {
|
|
269
|
+
const sourceMemberships = await listActiveUserMemberships(sourceCompanyId);
|
|
270
|
+
for (const membership of sourceMemberships) {
|
|
271
|
+
await ensureMembership(
|
|
272
|
+
targetCompanyId,
|
|
273
|
+
"user",
|
|
274
|
+
membership.principalId,
|
|
275
|
+
membership.membershipRole,
|
|
276
|
+
"active",
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
return sourceMemberships;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
async function listPrincipalGrants(
|
|
283
|
+
companyId: string,
|
|
284
|
+
principalType: PrincipalType,
|
|
285
|
+
principalId: string,
|
|
286
|
+
) {
|
|
287
|
+
return db
|
|
288
|
+
.select()
|
|
289
|
+
.from(principalPermissionGrants)
|
|
290
|
+
.where(
|
|
291
|
+
and(
|
|
292
|
+
eq(principalPermissionGrants.companyId, companyId),
|
|
293
|
+
eq(principalPermissionGrants.principalType, principalType),
|
|
294
|
+
eq(principalPermissionGrants.principalId, principalId),
|
|
295
|
+
),
|
|
296
|
+
)
|
|
297
|
+
.orderBy(principalPermissionGrants.permissionKey);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async function setPrincipalPermission(
|
|
301
|
+
companyId: string,
|
|
302
|
+
principalType: PrincipalType,
|
|
303
|
+
principalId: string,
|
|
304
|
+
permissionKey: PermissionKey,
|
|
305
|
+
enabled: boolean,
|
|
306
|
+
grantedByUserId: string | null,
|
|
307
|
+
scope: Record<string, unknown> | null = null,
|
|
308
|
+
) {
|
|
309
|
+
if (!enabled) {
|
|
310
|
+
await db
|
|
311
|
+
.delete(principalPermissionGrants)
|
|
312
|
+
.where(
|
|
313
|
+
and(
|
|
314
|
+
eq(principalPermissionGrants.companyId, companyId),
|
|
315
|
+
eq(principalPermissionGrants.principalType, principalType),
|
|
316
|
+
eq(principalPermissionGrants.principalId, principalId),
|
|
317
|
+
eq(principalPermissionGrants.permissionKey, permissionKey),
|
|
318
|
+
),
|
|
319
|
+
);
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
await ensureMembership(companyId, principalType, principalId, "member", "active");
|
|
324
|
+
|
|
325
|
+
const existing = await db
|
|
326
|
+
.select()
|
|
327
|
+
.from(principalPermissionGrants)
|
|
328
|
+
.where(
|
|
329
|
+
and(
|
|
330
|
+
eq(principalPermissionGrants.companyId, companyId),
|
|
331
|
+
eq(principalPermissionGrants.principalType, principalType),
|
|
332
|
+
eq(principalPermissionGrants.principalId, principalId),
|
|
333
|
+
eq(principalPermissionGrants.permissionKey, permissionKey),
|
|
334
|
+
),
|
|
335
|
+
)
|
|
336
|
+
.then((rows) => rows[0] ?? null);
|
|
337
|
+
|
|
338
|
+
if (existing) {
|
|
339
|
+
await db
|
|
340
|
+
.update(principalPermissionGrants)
|
|
341
|
+
.set({
|
|
342
|
+
scope,
|
|
343
|
+
grantedByUserId,
|
|
344
|
+
updatedAt: new Date(),
|
|
345
|
+
})
|
|
346
|
+
.where(eq(principalPermissionGrants.id, existing.id));
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
await db.insert(principalPermissionGrants).values({
|
|
351
|
+
companyId,
|
|
352
|
+
principalType,
|
|
353
|
+
principalId,
|
|
354
|
+
permissionKey,
|
|
355
|
+
scope,
|
|
356
|
+
grantedByUserId,
|
|
357
|
+
createdAt: new Date(),
|
|
358
|
+
updatedAt: new Date(),
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
return {
|
|
363
|
+
isInstanceAdmin,
|
|
364
|
+
canUser,
|
|
365
|
+
hasPermission,
|
|
366
|
+
getMembership,
|
|
367
|
+
ensureMembership,
|
|
368
|
+
listMembers,
|
|
369
|
+
listActiveUserMemberships,
|
|
370
|
+
copyActiveUserMemberships,
|
|
371
|
+
setMemberPermissions,
|
|
372
|
+
promoteInstanceAdmin,
|
|
373
|
+
demoteInstanceAdmin,
|
|
374
|
+
listUserCompanyAccess,
|
|
375
|
+
setUserCompanyAccess,
|
|
376
|
+
setPrincipalGrants,
|
|
377
|
+
listPrincipalGrants,
|
|
378
|
+
setPrincipalPermission,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import type { Db } from "@corporateai/db";
|
|
3
|
+
import { activityLog } from "@corporateai/db";
|
|
4
|
+
import { PLUGIN_EVENT_TYPES, type PluginEventType } from "@corporateai/shared";
|
|
5
|
+
import type { PluginEvent } from "@corporateai/plugin-sdk";
|
|
6
|
+
import { publishLiveEvent } from "./live-events.js";
|
|
7
|
+
import { redactCurrentUserValue } from "../log-redaction.js";
|
|
8
|
+
import { sanitizeRecord } from "../redaction.js";
|
|
9
|
+
import { logger } from "../middleware/logger.js";
|
|
10
|
+
import type { PluginEventBus } from "./plugin-event-bus.js";
|
|
11
|
+
import { instanceSettingsService } from "./instance-settings.js";
|
|
12
|
+
|
|
13
|
+
const PLUGIN_EVENT_SET: ReadonlySet<string> = new Set(PLUGIN_EVENT_TYPES);
|
|
14
|
+
|
|
15
|
+
let _pluginEventBus: PluginEventBus | null = null;
|
|
16
|
+
|
|
17
|
+
/** Wire the plugin event bus so domain events are forwarded to plugins. */
|
|
18
|
+
export function setPluginEventBus(bus: PluginEventBus): void {
|
|
19
|
+
if (_pluginEventBus) {
|
|
20
|
+
logger.warn("setPluginEventBus called more than once, replacing existing bus");
|
|
21
|
+
}
|
|
22
|
+
_pluginEventBus = bus;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface LogActivityInput {
|
|
26
|
+
companyId: string;
|
|
27
|
+
actorType: "agent" | "user" | "system";
|
|
28
|
+
actorId: string;
|
|
29
|
+
action: string;
|
|
30
|
+
entityType: string;
|
|
31
|
+
entityId: string;
|
|
32
|
+
agentId?: string | null;
|
|
33
|
+
runId?: string | null;
|
|
34
|
+
details?: Record<string, unknown> | null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function logActivity(db: Db, input: LogActivityInput) {
|
|
38
|
+
const currentUserRedactionOptions = {
|
|
39
|
+
enabled: (await instanceSettingsService(db).getGeneral()).censorUsernameInLogs,
|
|
40
|
+
};
|
|
41
|
+
const sanitizedDetails = input.details ? sanitizeRecord(input.details) : null;
|
|
42
|
+
const redactedDetails = sanitizedDetails
|
|
43
|
+
? redactCurrentUserValue(sanitizedDetails, currentUserRedactionOptions)
|
|
44
|
+
: null;
|
|
45
|
+
await db.insert(activityLog).values({
|
|
46
|
+
companyId: input.companyId,
|
|
47
|
+
actorType: input.actorType,
|
|
48
|
+
actorId: input.actorId,
|
|
49
|
+
action: input.action,
|
|
50
|
+
entityType: input.entityType,
|
|
51
|
+
entityId: input.entityId,
|
|
52
|
+
agentId: input.agentId ?? null,
|
|
53
|
+
runId: input.runId ?? null,
|
|
54
|
+
details: redactedDetails,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
publishLiveEvent({
|
|
58
|
+
companyId: input.companyId,
|
|
59
|
+
type: "activity.logged",
|
|
60
|
+
payload: {
|
|
61
|
+
actorType: input.actorType,
|
|
62
|
+
actorId: input.actorId,
|
|
63
|
+
action: input.action,
|
|
64
|
+
entityType: input.entityType,
|
|
65
|
+
entityId: input.entityId,
|
|
66
|
+
agentId: input.agentId ?? null,
|
|
67
|
+
runId: input.runId ?? null,
|
|
68
|
+
details: redactedDetails,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
if (_pluginEventBus && PLUGIN_EVENT_SET.has(input.action)) {
|
|
73
|
+
const event: PluginEvent = {
|
|
74
|
+
eventId: randomUUID(),
|
|
75
|
+
eventType: input.action as PluginEventType,
|
|
76
|
+
occurredAt: new Date().toISOString(),
|
|
77
|
+
actorId: input.actorId,
|
|
78
|
+
actorType: input.actorType,
|
|
79
|
+
entityId: input.entityId,
|
|
80
|
+
entityType: input.entityType,
|
|
81
|
+
companyId: input.companyId,
|
|
82
|
+
payload: {
|
|
83
|
+
...redactedDetails,
|
|
84
|
+
agentId: input.agentId ?? null,
|
|
85
|
+
runId: input.runId ?? null,
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
void _pluginEventBus.emit(event).then(({ errors }) => {
|
|
89
|
+
for (const { pluginId, error } of errors) {
|
|
90
|
+
logger.warn({ pluginId, eventType: event.eventType, err: error }, "plugin event handler failed");
|
|
91
|
+
}
|
|
92
|
+
}).catch(() => {});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { and, desc, eq, isNull, or, sql } from "drizzle-orm";
|
|
2
|
+
import type { Db } from "@corporateai/db";
|
|
3
|
+
import { activityLog, heartbeatRuns, issues } from "@corporateai/db";
|
|
4
|
+
|
|
5
|
+
export interface ActivityFilters {
|
|
6
|
+
companyId: string;
|
|
7
|
+
agentId?: string;
|
|
8
|
+
entityType?: string;
|
|
9
|
+
entityId?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function activityService(db: Db) {
|
|
13
|
+
const issueIdAsText = sql<string>`${issues.id}::text`;
|
|
14
|
+
return {
|
|
15
|
+
list: (filters: ActivityFilters) => {
|
|
16
|
+
const conditions = [eq(activityLog.companyId, filters.companyId)];
|
|
17
|
+
|
|
18
|
+
if (filters.agentId) {
|
|
19
|
+
conditions.push(eq(activityLog.agentId, filters.agentId));
|
|
20
|
+
}
|
|
21
|
+
if (filters.entityType) {
|
|
22
|
+
conditions.push(eq(activityLog.entityType, filters.entityType));
|
|
23
|
+
}
|
|
24
|
+
if (filters.entityId) {
|
|
25
|
+
conditions.push(eq(activityLog.entityId, filters.entityId));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return db
|
|
29
|
+
.select({ activityLog })
|
|
30
|
+
.from(activityLog)
|
|
31
|
+
.leftJoin(
|
|
32
|
+
issues,
|
|
33
|
+
and(
|
|
34
|
+
eq(activityLog.entityType, sql`'issue'`),
|
|
35
|
+
eq(activityLog.entityId, issueIdAsText),
|
|
36
|
+
),
|
|
37
|
+
)
|
|
38
|
+
.where(
|
|
39
|
+
and(
|
|
40
|
+
...conditions,
|
|
41
|
+
or(
|
|
42
|
+
sql`${activityLog.entityType} != 'issue'`,
|
|
43
|
+
isNull(issues.hiddenAt),
|
|
44
|
+
),
|
|
45
|
+
),
|
|
46
|
+
)
|
|
47
|
+
.orderBy(desc(activityLog.createdAt))
|
|
48
|
+
.then((rows) => rows.map((r) => r.activityLog));
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
forIssue: (issueId: string) =>
|
|
52
|
+
db
|
|
53
|
+
.select()
|
|
54
|
+
.from(activityLog)
|
|
55
|
+
.where(
|
|
56
|
+
and(
|
|
57
|
+
eq(activityLog.entityType, "issue"),
|
|
58
|
+
eq(activityLog.entityId, issueId),
|
|
59
|
+
),
|
|
60
|
+
)
|
|
61
|
+
.orderBy(desc(activityLog.createdAt)),
|
|
62
|
+
|
|
63
|
+
runsForIssue: (companyId: string, issueId: string) =>
|
|
64
|
+
db
|
|
65
|
+
.select({
|
|
66
|
+
runId: heartbeatRuns.id,
|
|
67
|
+
status: heartbeatRuns.status,
|
|
68
|
+
agentId: heartbeatRuns.agentId,
|
|
69
|
+
startedAt: heartbeatRuns.startedAt,
|
|
70
|
+
finishedAt: heartbeatRuns.finishedAt,
|
|
71
|
+
createdAt: heartbeatRuns.createdAt,
|
|
72
|
+
invocationSource: heartbeatRuns.invocationSource,
|
|
73
|
+
usageJson: heartbeatRuns.usageJson,
|
|
74
|
+
resultJson: heartbeatRuns.resultJson,
|
|
75
|
+
})
|
|
76
|
+
.from(heartbeatRuns)
|
|
77
|
+
.where(
|
|
78
|
+
and(
|
|
79
|
+
eq(heartbeatRuns.companyId, companyId),
|
|
80
|
+
or(
|
|
81
|
+
sql`${heartbeatRuns.contextSnapshot} ->> 'issueId' = ${issueId}`,
|
|
82
|
+
sql`exists (
|
|
83
|
+
select 1
|
|
84
|
+
from ${activityLog}
|
|
85
|
+
where ${activityLog.companyId} = ${companyId}
|
|
86
|
+
and ${activityLog.entityType} = 'issue'
|
|
87
|
+
and ${activityLog.entityId} = ${issueId}
|
|
88
|
+
and ${activityLog.runId} = ${heartbeatRuns.id}
|
|
89
|
+
)`,
|
|
90
|
+
),
|
|
91
|
+
),
|
|
92
|
+
)
|
|
93
|
+
.orderBy(desc(heartbeatRuns.createdAt)),
|
|
94
|
+
|
|
95
|
+
issuesForRun: async (runId: string) => {
|
|
96
|
+
const run = await db
|
|
97
|
+
.select({
|
|
98
|
+
companyId: heartbeatRuns.companyId,
|
|
99
|
+
contextSnapshot: heartbeatRuns.contextSnapshot,
|
|
100
|
+
})
|
|
101
|
+
.from(heartbeatRuns)
|
|
102
|
+
.where(eq(heartbeatRuns.id, runId))
|
|
103
|
+
.then((rows) => rows[0] ?? null);
|
|
104
|
+
if (!run) return [];
|
|
105
|
+
|
|
106
|
+
const fromActivity = await db
|
|
107
|
+
.selectDistinctOn([issueIdAsText], {
|
|
108
|
+
issueId: issues.id,
|
|
109
|
+
identifier: issues.identifier,
|
|
110
|
+
title: issues.title,
|
|
111
|
+
status: issues.status,
|
|
112
|
+
priority: issues.priority,
|
|
113
|
+
})
|
|
114
|
+
.from(activityLog)
|
|
115
|
+
.innerJoin(issues, eq(activityLog.entityId, issueIdAsText))
|
|
116
|
+
.where(
|
|
117
|
+
and(
|
|
118
|
+
eq(activityLog.companyId, run.companyId),
|
|
119
|
+
eq(activityLog.runId, runId),
|
|
120
|
+
eq(activityLog.entityType, "issue"),
|
|
121
|
+
isNull(issues.hiddenAt),
|
|
122
|
+
),
|
|
123
|
+
)
|
|
124
|
+
.orderBy(issueIdAsText);
|
|
125
|
+
|
|
126
|
+
const context = run.contextSnapshot;
|
|
127
|
+
const contextIssueId =
|
|
128
|
+
context && typeof context === "object" && typeof (context as Record<string, unknown>).issueId === "string"
|
|
129
|
+
? ((context as Record<string, unknown>).issueId as string)
|
|
130
|
+
: null;
|
|
131
|
+
if (!contextIssueId) return fromActivity;
|
|
132
|
+
if (fromActivity.some((issue) => issue.issueId === contextIssueId)) return fromActivity;
|
|
133
|
+
|
|
134
|
+
const fromContext = await db
|
|
135
|
+
.select({
|
|
136
|
+
issueId: issues.id,
|
|
137
|
+
identifier: issues.identifier,
|
|
138
|
+
title: issues.title,
|
|
139
|
+
status: issues.status,
|
|
140
|
+
priority: issues.priority,
|
|
141
|
+
})
|
|
142
|
+
.from(issues)
|
|
143
|
+
.where(
|
|
144
|
+
and(
|
|
145
|
+
eq(issues.companyId, run.companyId),
|
|
146
|
+
eq(issues.id, contextIssueId),
|
|
147
|
+
isNull(issues.hiddenAt),
|
|
148
|
+
),
|
|
149
|
+
)
|
|
150
|
+
.then((rows) => rows[0] ?? null);
|
|
151
|
+
|
|
152
|
+
if (!fromContext) return fromActivity;
|
|
153
|
+
return [fromContext, ...fromActivity];
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
create: (data: typeof activityLog.$inferInsert) =>
|
|
157
|
+
db
|
|
158
|
+
.insert(activityLog)
|
|
159
|
+
.values(data)
|
|
160
|
+
.returning()
|
|
161
|
+
.then((rows) => rows[0]),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
|