@flowdular/sdk 0.1.0
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/.ai/agents/README.md +27 -0
- package/.ai/agents/module-executor.md +36 -0
- package/.ai/agents/reviewer.md +23 -0
- package/.ai/agents/sandbox/agentic-engineer.md +31 -0
- package/.ai/agents/sandbox/backend-engineer.md +36 -0
- package/.ai/agents/sandbox/business-manager.md +23 -0
- package/.ai/agents/sandbox/frontend-engineer.md +27 -0
- package/.ai/agents/sandbox/ux-designer.md +23 -0
- package/.ai/agents/spec-author.md +29 -0
- package/.ai/blueprints/add-migration/README.md +5 -0
- package/.ai/blueprints/add-migration/allowed-paths.yaml +23 -0
- package/.ai/blueprints/add-migration/blueprint.json +14 -0
- package/.ai/blueprints/add-migration/examples/invalid/input-destructive.json +6 -0
- package/.ai/blueprints/add-migration/examples/invalid/plan-unnumbered-file.json +9 -0
- package/.ai/blueprints/add-migration/examples/valid/input.json +6 -0
- package/.ai/blueprints/add-migration/examples/valid/plan.json +9 -0
- package/.ai/blueprints/add-migration/gates.yaml +30 -0
- package/.ai/blueprints/add-migration/input.schema.json +23 -0
- package/.ai/blueprints/add-migration/plan.schema.json +54 -0
- package/.ai/blueprints/add-migration/required-files.yaml +18 -0
- package/.ai/blueprints/add-migration/spec-requirements.yaml +13 -0
- package/.ai/blueprints/add-migration/steps.yaml +62 -0
- package/.ai/blueprints/author-spec/README.md +5 -0
- package/.ai/blueprints/author-spec/allowed-paths.yaml +7 -0
- package/.ai/blueprints/author-spec/blueprint.json +14 -0
- package/.ai/blueprints/author-spec/examples/invalid/input-missing-outcome.json +5 -0
- package/.ai/blueprints/author-spec/examples/valid/input.json +6 -0
- package/.ai/blueprints/author-spec/gates.yaml +13 -0
- package/.ai/blueprints/author-spec/input.schema.json +20 -0
- package/.ai/blueprints/author-spec/plan.schema.json +14 -0
- package/.ai/blueprints/author-spec/required-files.yaml +6 -0
- package/.ai/blueprints/author-spec/spec-requirements.yaml +35 -0
- package/.ai/blueprints/author-spec/steps.yaml +28 -0
- package/.ai/blueprints/author-spec/templates/module.yaml +45 -0
- package/.ai/blueprints/bug-fix/README.md +5 -0
- package/.ai/blueprints/bug-fix/allowed-paths.yaml +29 -0
- package/.ai/blueprints/bug-fix/blueprint.json +14 -0
- package/.ai/blueprints/bug-fix/examples/invalid/input-no-symptom.json +4 -0
- package/.ai/blueprints/bug-fix/examples/invalid/plan-no-test.json +8 -0
- package/.ai/blueprints/bug-fix/examples/valid/input.json +6 -0
- package/.ai/blueprints/bug-fix/examples/valid/plan.json +8 -0
- package/.ai/blueprints/bug-fix/gates.yaml +30 -0
- package/.ai/blueprints/bug-fix/input.schema.json +25 -0
- package/.ai/blueprints/bug-fix/plan.schema.json +53 -0
- package/.ai/blueprints/bug-fix/required-files.yaml +7 -0
- package/.ai/blueprints/bug-fix/spec-requirements.yaml +7 -0
- package/.ai/blueprints/bug-fix/steps.yaml +51 -0
- package/.ai/blueprints/core-extend/README.md +5 -0
- package/.ai/blueprints/core-extend/allowed-paths.yaml +49 -0
- package/.ai/blueprints/core-extend/blueprint.json +14 -0
- package/.ai/blueprints/core-extend/examples/invalid/input-unknown-package.json +5 -0
- package/.ai/blueprints/core-extend/examples/invalid/plan-missing-gates.json +7 -0
- package/.ai/blueprints/core-extend/examples/valid/input.json +6 -0
- package/.ai/blueprints/core-extend/examples/valid/plan.json +10 -0
- package/.ai/blueprints/core-extend/gates.yaml +16 -0
- package/.ai/blueprints/core-extend/input.schema.json +54 -0
- package/.ai/blueprints/core-extend/plan.schema.json +39 -0
- package/.ai/blueprints/core-extend/required-files.yaml +36 -0
- package/.ai/blueprints/core-extend/spec-requirements.yaml +17 -0
- package/.ai/blueprints/core-extend/steps.yaml +54 -0
- package/.ai/blueprints/edit-module/README.md +9 -0
- package/.ai/blueprints/edit-module/allowed-paths.yaml +27 -0
- package/.ai/blueprints/edit-module/blueprint.json +20 -0
- package/.ai/blueprints/edit-module/examples/invalid/input-unknown-change.json +5 -0
- package/.ai/blueprints/edit-module/examples/invalid/plan-touches-platform.json +15 -0
- package/.ai/blueprints/edit-module/examples/valid/input.json +5 -0
- package/.ai/blueprints/edit-module/examples/valid/plan.json +25 -0
- package/.ai/blueprints/edit-module/gates.yaml +30 -0
- package/.ai/blueprints/edit-module/input.schema.json +31 -0
- package/.ai/blueprints/edit-module/plan.schema.json +65 -0
- package/.ai/blueprints/edit-module/required-files.yaml +80 -0
- package/.ai/blueprints/edit-module/spec-requirements.yaml +15 -0
- package/.ai/blueprints/edit-module/steps.yaml +115 -0
- package/.ai/blueprints/new-module/README.md +7 -0
- package/.ai/blueprints/new-module/allowed-paths.yaml +27 -0
- package/.ai/blueprints/new-module/blueprint.json +20 -0
- package/.ai/blueprints/new-module/examples/invalid/input-spec-outside-modules.json +4 -0
- package/.ai/blueprints/new-module/examples/invalid/plan-unknown-gate.json +8 -0
- package/.ai/blueprints/new-module/examples/valid/input.json +5 -0
- package/.ai/blueprints/new-module/examples/valid/plan.json +22 -0
- package/.ai/blueprints/new-module/gates.yaml +30 -0
- package/.ai/blueprints/new-module/input.schema.json +21 -0
- package/.ai/blueprints/new-module/plan.schema.json +58 -0
- package/.ai/blueprints/new-module/required-files.yaml +73 -0
- package/.ai/blueprints/new-module/spec-requirements.yaml +30 -0
- package/.ai/blueprints/new-module/steps.yaml +138 -0
- package/.ai/blueprints/release/README.md +5 -0
- package/.ai/blueprints/release/allowed-paths.yaml +19 -0
- package/.ai/blueprints/release/blueprint.json +14 -0
- package/.ai/blueprints/release/examples/invalid/input-bad-version.json +4 -0
- package/.ai/blueprints/release/examples/invalid/plan-bad-branch.json +7 -0
- package/.ai/blueprints/release/examples/valid/input.json +5 -0
- package/.ai/blueprints/release/examples/valid/plan.json +20 -0
- package/.ai/blueprints/release/gates.yaml +20 -0
- package/.ai/blueprints/release/input.schema.json +24 -0
- package/.ai/blueprints/release/plan.schema.json +46 -0
- package/.ai/blueprints/release/required-files.yaml +19 -0
- package/.ai/blueprints/release/spec-requirements.yaml +8 -0
- package/.ai/blueprints/release/steps.yaml +47 -0
- package/.ai/blueprints/security-review/README.md +5 -0
- package/.ai/blueprints/security-review/allowed-paths.yaml +6 -0
- package/.ai/blueprints/security-review/blueprint.json +14 -0
- package/.ai/blueprints/security-review/examples/invalid/input-unknown-kind.json +4 -0
- package/.ai/blueprints/security-review/examples/invalid/plan-finding-without-scenario.json +14 -0
- package/.ai/blueprints/security-review/examples/valid/input.json +4 -0
- package/.ai/blueprints/security-review/examples/valid/plan.json +19 -0
- package/.ai/blueprints/security-review/gates.yaml +22 -0
- package/.ai/blueprints/security-review/input.schema.json +20 -0
- package/.ai/blueprints/security-review/plan.schema.json +65 -0
- package/.ai/blueprints/security-review/required-files.yaml +6 -0
- package/.ai/blueprints/security-review/spec-requirements.yaml +9 -0
- package/.ai/blueprints/security-review/steps.yaml +38 -0
- package/.ai/policies/capabilities.yaml +164 -0
- package/.ai/policies/model-routing.yaml +72 -0
- package/.ai/policies/path-ownership.yaml +65 -0
- package/.ai/policies/task-budgets.yaml +37 -0
- package/.ai/references/catalog/LICENSE +21 -0
- package/.ai/references/catalog/migrations/0001_catalog_core.down.sql +2 -0
- package/.ai/references/catalog/migrations/0001_catalog_core.up.sql +21 -0
- package/.ai/references/catalog/migrations/0002_catalog_history.down.sql +3 -0
- package/.ai/references/catalog/migrations/0002_catalog_history.up.sql +20 -0
- package/.ai/references/catalog/migrations/0003_catalog_history_service_actors.down.sql +3 -0
- package/.ai/references/catalog/migrations/0003_catalog_history_service_actors.up.sql +36 -0
- package/.ai/references/catalog/migrations/0004_catalog_idempotency_ledger.down.sql +3 -0
- package/.ai/references/catalog/migrations/0004_catalog_idempotency_ledger.up.sql +19 -0
- package/.ai/references/catalog/migrations/README.md +3 -0
- package/.ai/references/catalog/module.json +27 -0
- package/.ai/references/catalog/package.json +49 -0
- package/.ai/references/catalog/spec/module.yaml +86 -0
- package/.ai/references/catalog/src/acl/permissions.ts +6 -0
- package/.ai/references/catalog/src/agent/tools.ts +164 -0
- package/.ai/references/catalog/src/api/endpoints.ts +243 -0
- package/.ai/references/catalog/src/client/CatalogHistoryDrawer.tsrx +123 -0
- package/.ai/references/catalog/src/client/CatalogItemForm.tsrx +190 -0
- package/.ai/references/catalog/src/client/CatalogView.tsrx +473 -0
- package/.ai/references/catalog/src/client/api.ts +111 -0
- package/.ai/references/catalog/src/client/contribution.tsrx +61 -0
- package/.ai/references/catalog/src/client/index.ts +18 -0
- package/.ai/references/catalog/src/client/navigation-copy.ts +9 -0
- package/.ai/references/catalog/src/client/state.ts +24 -0
- package/.ai/references/catalog/src/domain/types.ts +32 -0
- package/.ai/references/catalog/src/domain/variables.ts +111 -0
- package/.ai/references/catalog/src/index.ts +31 -0
- package/.ai/references/catalog/src/platform.ts +35 -0
- package/.ai/references/catalog/src/server/index.ts +4 -0
- package/.ai/references/catalog/src/server/runtime.ts +86 -0
- package/.ai/references/catalog/src/services/catalog-service.ts +306 -0
- package/.ai/references/catalog/src/services/database-repository.ts +440 -0
- package/.ai/references/catalog/src/services/index.ts +4 -0
- package/.ai/references/catalog/src/services/migration.ts +171 -0
- package/.ai/references/catalog/src/services/repository.ts +36 -0
- package/.ai/references/catalog/src/services/target-idempotency.ts +59 -0
- package/.ai/references/catalog/tests/agent-tools.test.ts +277 -0
- package/.ai/references/catalog/tests/endpoints.test.ts +320 -0
- package/.ai/references/catalog/tests/idempotency.test.ts +297 -0
- package/.ai/references/catalog/tests/migrations.test.ts +149 -0
- package/.ai/references/catalog/tests/module.test.ts +271 -0
- package/.ai/references/catalog/tests/support/database.ts +76 -0
- package/.ai/references/catalog/translations/en.json +101 -0
- package/.ai/references/catalog/translations/pl.json +101 -0
- package/.ai/references/catalog/tsconfig.json +15 -0
- package/.ai/references/catalog/vitest.config.ts +16 -0
- package/.ai/references/catalog.provenance.json +55 -0
- package/.ai/skills/README.md +36 -0
- package/.ai/skills/agent-tool-design/SKILL.md +209 -0
- package/.ai/skills/auth-security-review/SKILL.md +96 -0
- package/.ai/skills/auto-review/SKILL.md +112 -0
- package/.ai/skills/bug-hunt/SKILL.md +110 -0
- package/.ai/skills/business-agent-design/SKILL.md +188 -0
- package/.ai/skills/cli-extension/SKILL.md +114 -0
- package/.ai/skills/core-extend/SKILL.md +104 -0
- package/.ai/skills/database-adapter/SKILL.md +204 -0
- package/.ai/skills/database-adapter/references/first-run-and-matrix.md +105 -0
- package/.ai/skills/migration-authoring/SKILL.md +167 -0
- package/.ai/skills/module-new/SKILL.md +180 -0
- package/.ai/skills/module-update/SKILL.md +100 -0
- package/.ai/skills/perf-audit/SKILL.md +105 -0
- package/.ai/skills/release-eject-pr/SKILL.md +113 -0
- package/.ai/skills/spec-approval/SKILL.md +112 -0
- package/.ai/skills/test-hardening/SKILL.md +86 -0
- package/.ai/skills/translations-i18n/SKILL.md +85 -0
- package/.ai/skills/ux-design/SKILL.md +97 -0
- package/.ai/skills/variables/SKILL.md +164 -0
- package/.ai/skills/workflow-development/SKILL.md +199 -0
- package/AGENTS.md +59 -0
- package/LICENSE +21 -0
- package/README.md +24 -0
- package/docs/agent-contract.md +45 -0
- package/docs/design-system.md +217 -0
- package/modules/agents/migrations/0001_agents_core.down.sql +4 -0
- package/modules/agents/migrations/0001_agents_core.up.sql +106 -0
- package/modules/agents/migrations/0002_provider_connections.down.sql +1 -0
- package/modules/agents/migrations/0002_provider_connections.up.sql +34 -0
- package/modules/agents/migrations/0003_resource_audit.down.sql +1 -0
- package/modules/agents/migrations/0003_resource_audit.up.sql +25 -0
- package/modules/agents/migrations/0004_run_grants.down.sql +1 -0
- package/modules/agents/migrations/0004_run_grants.up.sql +19 -0
- package/modules/agents/migrations/0005_long_running_limits.down.sql +2 -0
- package/modules/agents/migrations/0005_long_running_limits.up.sql +14 -0
- package/modules/agents/migrations/0006_agent_skills.down.sql +3 -0
- package/modules/agents/migrations/0006_agent_skills.up.sql +44 -0
- package/modules/agents/migrations/0007_model_readiness.down.sql +1 -0
- package/modules/agents/migrations/0007_model_readiness.up.sql +18 -0
- package/modules/agents/migrations/0008_output_limits.down.sql +2 -0
- package/modules/agents/migrations/0008_output_limits.up.sql +8 -0
- package/modules/agents/migrations/0009_agent_audit_v3.down.sql +1 -0
- package/modules/agents/migrations/0009_agent_audit_v3.up.sql +25 -0
- package/modules/agents/migrations/0012_agent_run_costs.down.sql +3 -0
- package/modules/agents/migrations/0012_agent_run_costs.up.sql +32 -0
- package/modules/agents/migrations/0013_workflow_prerequisites.down.sql +3 -0
- package/modules/agents/migrations/0013_workflow_prerequisites.up.sql +97 -0
- package/modules/agents/migrations/0014_agent_action_audit.down.sql +1 -0
- package/modules/agents/migrations/0014_agent_action_audit.up.sql +25 -0
- package/modules/agents/migrations/0015_agent_run_actors.down.sql +1 -0
- package/modules/agents/migrations/0015_agent_run_actors.up.sql +17 -0
- package/modules/agents/migrations/0016_module_owned_agents.down.sql +6 -0
- package/modules/agents/migrations/0016_module_owned_agents.up.sql +68 -0
- package/modules/agents/migrations/0017_agent_authorization_subjects.down.sql +2 -0
- package/modules/agents/migrations/0017_agent_authorization_subjects.up.sql +18 -0
- package/modules/agents/migrations/0018_agent_child_tenant_isolation.down.sql +12 -0
- package/modules/agents/migrations/0018_agent_child_tenant_isolation.up.sql +88 -0
- package/modules/agents/migrations/0019_background_recovery_grants.down.sql +6 -0
- package/modules/agents/migrations/0019_background_recovery_grants.up.sql +17 -0
- package/modules/agents/migrations/0020_provider_summary_role.down.sql +2 -0
- package/modules/agents/migrations/0020_provider_summary_role.up.sql +17 -0
- package/modules/agents/migrations/0021_agents_agent_reconciliation_role.down.sql +4 -0
- package/modules/agents/migrations/0021_agents_agent_reconciliation_role.up.sql +7 -0
- package/modules/agents/migrations/README.md +39 -0
- package/modules/agents/module.json +38 -0
- package/modules/agents/package.json +56 -0
- package/modules/agents/spec/module.yaml +271 -0
- package/modules/agents/spec/procedures-compatibility.md +63 -0
- package/modules/agents/src/acl/permissions.ts +13 -0
- package/modules/agents/src/api/endpoints.ts +1122 -0
- package/modules/agents/src/cli/commands.json +29 -0
- package/modules/agents/src/cli/index.ts +162 -0
- package/modules/agents/src/client/AgentDashboardWidget.tsrx +32 -0
- package/modules/agents/src/client/AgentDefinitionForm.tsrx +362 -0
- package/modules/agents/src/client/AgentDefinitionList.tsrx +127 -0
- package/modules/agents/src/client/AgentPlaygroundView.tsrx +246 -0
- package/modules/agents/src/client/AgentProcedureForm.tsrx +182 -0
- package/modules/agents/src/client/AgentProcedureList.tsrx +118 -0
- package/modules/agents/src/client/AgentProceduresView.tsrx +253 -0
- package/modules/agents/src/client/AgentProvidersView.tsrx +248 -0
- package/modules/agents/src/client/AgentRunsView.tsrx +304 -0
- package/modules/agents/src/client/AgentUsageView.tsrx +233 -0
- package/modules/agents/src/client/AgentsView.tsrx +339 -0
- package/modules/agents/src/client/ModuleAgentBindingForm.tsrx +239 -0
- package/modules/agents/src/client/ModuleAgentList.tsrx +122 -0
- package/modules/agents/src/client/ProviderConnectionForm.tsrx +273 -0
- package/modules/agents/src/client/ProviderConnectionList.tsrx +229 -0
- package/modules/agents/src/client/ProviderModelEditor.tsrx +313 -0
- package/modules/agents/src/client/RunTimeline.tsrx +212 -0
- package/modules/agents/src/client/agents.css +349 -0
- package/modules/agents/src/client/api.ts +373 -0
- package/modules/agents/src/client/contribution.tsrx +181 -0
- package/modules/agents/src/client/index.ts +21 -0
- package/modules/agents/src/client/presentation.ts +162 -0
- package/modules/agents/src/client/state.ts +100 -0
- package/modules/agents/src/domain/context-variables.ts +58 -0
- package/modules/agents/src/domain/run-timeline.ts +145 -0
- package/modules/agents/src/domain/types.ts +481 -0
- package/modules/agents/src/index.ts +88 -0
- package/modules/agents/src/platform.ts +82 -0
- package/modules/agents/src/server/action-execution.ts +811 -0
- package/modules/agents/src/server/define-agent.ts +170 -0
- package/modules/agents/src/server/index.ts +67 -0
- package/modules/agents/src/server/run-execution.ts +231 -0
- package/modules/agents/src/server/run-queue.ts +96 -0
- package/modules/agents/src/server/runtime.ts +448 -0
- package/modules/agents/src/server/tools.ts +18 -0
- package/modules/agents/src/services/agent-service.ts +2167 -0
- package/modules/agents/src/services/credential-vault.ts +133 -0
- package/modules/agents/src/services/database-repository.ts +2786 -0
- package/modules/agents/src/services/index.ts +33 -0
- package/modules/agents/src/services/migration.ts +1152 -0
- package/modules/agents/src/services/module-agent-preflight.ts +76 -0
- package/modules/agents/src/services/outbound-policy.ts +136 -0
- package/modules/agents/src/services/provider-broker.ts +80 -0
- package/modules/agents/src/services/provider-repository.ts +589 -0
- package/modules/agents/src/services/provider-service.ts +968 -0
- package/modules/agents/src/services/repository.ts +294 -0
- package/modules/agents/src/services/run-grant.ts +305 -0
- package/modules/agents/src/services/usage-service.ts +119 -0
- package/modules/agents/src/services/worker.ts +442 -0
- package/modules/agents/src/settings.ts +244 -0
- package/modules/agents/translations/en.json +403 -0
- package/modules/agents/translations/pl.json +403 -0
- package/modules/auth/README.md +215 -0
- package/modules/auth/migrations/0001_auth_core.up.sql +108 -0
- package/modules/auth/migrations/0002_bundled_module_scopes.up.sql +26 -0
- package/modules/auth/migrations/0003_agent_core_scopes.up.sql +12 -0
- package/modules/auth/migrations/0004_owner_only_development_scopes.up.sql +8 -0
- package/modules/auth/migrations/0005_agent_provider_scopes.up.sql +13 -0
- package/modules/auth/migrations/0006_tenant_slug.up.sql +6 -0
- package/modules/auth/migrations/0007_sandbox_scopes.up.sql +13 -0
- package/modules/auth/migrations/0008_api_tokens.up.sql +43 -0
- package/modules/auth/migrations/0009_module_settings.up.sql +24 -0
- package/modules/auth/migrations/0010_sign_in_lockout.up.sql +11 -0
- package/modules/auth/migrations/0011_session_ids_and_password_reset.up.sql +7 -0
- package/modules/auth/migrations/0012_roles.up.sql +31 -0
- package/modules/auth/migrations/0013_audit.up.sql +27 -0
- package/modules/auth/migrations/0014_audit_actor.up.sql +4 -0
- package/modules/auth/migrations/0015_account_security.up.sql +81 -0
- package/modules/auth/module.json +26 -0
- package/modules/auth/package.json +61 -0
- package/modules/auth/spec/module.yaml +190 -0
- package/modules/auth/src/acl/scopes.ts +86 -0
- package/modules/auth/src/api/attempt-limiter.ts +42 -0
- package/modules/auth/src/api/client-address.ts +14 -0
- package/modules/auth/src/api/cookies.ts +52 -0
- package/modules/auth/src/api/origin.ts +40 -0
- package/modules/auth/src/cli/commands.json +74 -0
- package/modules/auth/src/cli/database.ts +51 -0
- package/modules/auth/src/cli/greenfield.ts +173 -0
- package/modules/auth/src/cli/index.ts +184 -0
- package/modules/auth/src/cli/provisioning.ts +211 -0
- package/modules/auth/src/client/AuthBackdrop.tsrx +137 -0
- package/modules/auth/src/client/AuthenticationCore.tsrx +630 -0
- package/modules/auth/src/client/PasswordChangeRequired.tsrx +145 -0
- package/modules/auth/src/client/PublicAuthFlows.tsrx +379 -0
- package/modules/auth/src/client/api.ts +464 -0
- package/modules/auth/src/client/audit/AuditView.tsrx +357 -0
- package/modules/auth/src/client/audit/api.ts +164 -0
- package/modules/auth/src/client/audit/audit-columns.tsrx +47 -0
- package/modules/auth/src/client/audit/audit-row.ts +38 -0
- package/modules/auth/src/client/auth.css +483 -0
- package/modules/auth/src/client/contribution.tsrx +100 -0
- package/modules/auth/src/client/index.ts +32 -0
- package/modules/auth/src/client/security/SecurityView.tsrx +253 -0
- package/modules/auth/src/client/settings/PreferencesCard.tsrx +65 -0
- package/modules/auth/src/client/settings/SettingsView.tsrx +212 -0
- package/modules/auth/src/client/settings/WorkspaceCard.tsrx +59 -0
- package/modules/auth/src/client/settings/api.ts +115 -0
- package/modules/auth/src/client/slug.ts +26 -0
- package/modules/auth/src/client/state.ts +115 -0
- package/modules/auth/src/client/tokens/ApiTokenForm.tsrx +153 -0
- package/modules/auth/src/client/tokens/ApiTokenSecret.tsrx +35 -0
- package/modules/auth/src/client/tokens/ApiTokensView.tsrx +216 -0
- package/modules/auth/src/client/tokens/api.ts +59 -0
- package/modules/auth/src/client/tokens/state.ts +26 -0
- package/modules/auth/src/client/tokens/token-columns.tsrx +64 -0
- package/modules/auth/src/client/translations.ts +23 -0
- package/modules/auth/src/domain/types.ts +152 -0
- package/modules/auth/src/index.ts +42 -0
- package/modules/auth/src/middleware/authentication.ts +97 -0
- package/modules/auth/src/platform.ts +0 -0
- package/modules/auth/src/server/actor.ts +12 -0
- package/modules/auth/src/server/audit-endpoints.ts +51 -0
- package/modules/auth/src/server/composition.ts +9 -0
- package/modules/auth/src/server/endpoints.ts +893 -0
- package/modules/auth/src/server/http.ts +153 -0
- package/modules/auth/src/server/index.ts +37 -0
- package/modules/auth/src/server/roles-endpoints.ts +120 -0
- package/modules/auth/src/server/runtime.ts +705 -0
- package/modules/auth/src/server/session-endpoints.ts +86 -0
- package/modules/auth/src/server/session-security.ts +62 -0
- package/modules/auth/src/server/token-endpoints.ts +106 -0
- package/modules/auth/src/services/auth-service-error.ts +11 -0
- package/modules/auth/src/services/auth-service.ts +2309 -0
- package/modules/auth/src/services/database-repository.ts +1825 -0
- package/modules/auth/src/services/mail-delivery.ts +27 -0
- package/modules/auth/src/services/migration.ts +591 -0
- package/modules/auth/src/services/password.ts +115 -0
- package/modules/auth/src/services/repository.ts +395 -0
- package/modules/auth/src/services/settings-store.ts +92 -0
- package/modules/auth/src/services/totp.ts +135 -0
- package/modules/auth/src/services/validation.ts +186 -0
- package/modules/auth/src/settings.ts +150 -0
- package/modules/auth/translations/en.json +263 -0
- package/modules/auth/translations/pl.json +263 -0
- package/modules/automations/migrations/0001_automations_core.down.sql +10 -0
- package/modules/automations/migrations/0001_automations_core.up.sql +76 -0
- package/modules/automations/migrations/0002_automations_targets.down.sql +9 -0
- package/modules/automations/migrations/0002_automations_targets.up.sql +37 -0
- package/modules/automations/migrations/0003_automations_scheduler_role.down.sql +3 -0
- package/modules/automations/migrations/0003_automations_scheduler_role.up.sql +19 -0
- package/modules/automations/migrations/0004_automations_trigger_routing_role.down.sql +3 -0
- package/modules/automations/migrations/0004_automations_trigger_routing_role.up.sql +18 -0
- package/modules/automations/migrations/README.md +3 -0
- package/modules/automations/module.json +31 -0
- package/modules/automations/package.json +55 -0
- package/modules/automations/spec/module.yaml +93 -0
- package/modules/automations/src/acl/permissions.ts +10 -0
- package/modules/automations/src/api/endpoints.ts +480 -0
- package/modules/automations/src/client/AutomationScheduleForm.tsrx +218 -0
- package/modules/automations/src/client/AutomationSchedulesView.tsrx +339 -0
- package/modules/automations/src/client/AutomationTriggerForm.tsrx +190 -0
- package/modules/automations/src/client/AutomationTriggersView.tsrx +329 -0
- package/modules/automations/src/client/api.ts +148 -0
- package/modules/automations/src/client/contribution.tsrx +70 -0
- package/modules/automations/src/client/index.ts +20 -0
- package/modules/automations/src/client/presentation.ts +38 -0
- package/modules/automations/src/client/state.ts +40 -0
- package/modules/automations/src/client/target-selection.ts +44 -0
- package/modules/automations/src/domain/cadence.ts +44 -0
- package/modules/automations/src/domain/types.ts +110 -0
- package/modules/automations/src/domain/variables.ts +178 -0
- package/modules/automations/src/index.ts +39 -0
- package/modules/automations/src/platform.ts +73 -0
- package/modules/automations/src/server/execution.ts +77 -0
- package/modules/automations/src/server/index.ts +39 -0
- package/modules/automations/src/server/runtime.ts +218 -0
- package/modules/automations/src/server/targets.ts +116 -0
- package/modules/automations/src/services/automations-service.ts +10 -0
- package/modules/automations/src/services/database-repository.ts +763 -0
- package/modules/automations/src/services/index.ts +5 -0
- package/modules/automations/src/services/migration.ts +223 -0
- package/modules/automations/src/services/repository.ts +119 -0
- package/modules/automations/src/services/schedule-service.ts +837 -0
- package/modules/automations/src/services/secret-vault.ts +124 -0
- package/modules/automations/src/services/trigger-service.ts +648 -0
- package/modules/automations/src/settings.ts +69 -0
- package/modules/automations/translations/en.json +126 -0
- package/modules/automations/translations/pl.json +126 -0
- package/modules/automations-workflows-integration/module.json +27 -0
- package/modules/automations-workflows-integration/package.json +48 -0
- package/modules/automations-workflows-integration/spec/module.yaml +93 -0
- package/modules/automations-workflows-integration/src/index.ts +14 -0
- package/modules/automations-workflows-integration/src/platform.ts +24 -0
- package/modules/automations-workflows-integration/src/server/adapter.ts +272 -0
- package/modules/automations-workflows-integration/src/server/index.ts +11 -0
- package/modules/automations-workflows-integration/src/server/tools.ts +0 -0
- package/modules/automations-workflows-integration/translations/en.json +21 -0
- package/modules/automations-workflows-integration/translations/pl.json +21 -0
- package/modules/profile/migrations/0001_profile_core.down.sql +1 -0
- package/modules/profile/migrations/0001_profile_core.up.sql +13 -0
- package/modules/profile/migrations/0002_profile_language.down.sql +1 -0
- package/modules/profile/migrations/0002_profile_language.up.sql +12 -0
- package/modules/profile/migrations/README.md +3 -0
- package/modules/profile/module.json +23 -0
- package/modules/profile/package.json +55 -0
- package/modules/profile/spec/module.yaml +136 -0
- package/modules/profile/src/acl/permissions.ts +5 -0
- package/modules/profile/src/api/endpoints.ts +184 -0
- package/modules/profile/src/client/DisplayNameCard.tsrx +59 -0
- package/modules/profile/src/client/LanguageCard.tsrx +89 -0
- package/modules/profile/src/client/PasswordCard.tsrx +79 -0
- package/modules/profile/src/client/ProfileView.tsrx +192 -0
- package/modules/profile/src/client/SessionsCard.tsrx +158 -0
- package/modules/profile/src/client/api.ts +134 -0
- package/modules/profile/src/client/contribution.tsrx +61 -0
- package/modules/profile/src/client/index.ts +15 -0
- package/modules/profile/src/client/password.ts +41 -0
- package/modules/profile/src/client/sessions-api.ts +52 -0
- package/modules/profile/src/client/state.ts +23 -0
- package/modules/profile/src/domain/types.ts +21 -0
- package/modules/profile/src/index.ts +21 -0
- package/modules/profile/src/platform.ts +23 -0
- package/modules/profile/src/server/index.ts +7 -0
- package/modules/profile/src/server/runtime.ts +84 -0
- package/modules/profile/src/services/database-repository.ts +154 -0
- package/modules/profile/src/services/index.ts +6 -0
- package/modules/profile/src/services/migration.ts +58 -0
- package/modules/profile/src/services/profile-service.ts +114 -0
- package/modules/profile/src/services/repository.ts +13 -0
- package/modules/profile/translations/en.json +58 -0
- package/modules/profile/translations/pl.json +58 -0
- package/modules/sandbox/migrations/0001_sandbox_core.down.sql +6 -0
- package/modules/sandbox/migrations/0001_sandbox_core.up.sql +70 -0
- package/modules/sandbox/migrations/0002_sandbox_session_lifecycle.down.sql +36 -0
- package/modules/sandbox/migrations/0002_sandbox_session_lifecycle.up.sql +37 -0
- package/modules/sandbox/migrations/README.md +7 -0
- package/modules/sandbox/module.json +31 -0
- package/modules/sandbox/package.json +56 -0
- package/modules/sandbox/spec/module.yaml +111 -0
- package/modules/sandbox/src/acl/permissions.ts +18 -0
- package/modules/sandbox/src/api/endpoints.ts +439 -0
- package/modules/sandbox/src/cli/commands.json +84 -0
- package/modules/sandbox/src/cli/index.ts +450 -0
- package/modules/sandbox/src/client/SandboxAccessView.tsrx +191 -0
- package/modules/sandbox/src/client/SandboxGrantForm.tsrx +134 -0
- package/modules/sandbox/src/client/SandboxGrantList.tsrx +83 -0
- package/modules/sandbox/src/client/SandboxSessionList.tsrx +56 -0
- package/modules/sandbox/src/client/api.ts +87 -0
- package/modules/sandbox/src/client/contribution.tsrx +47 -0
- package/modules/sandbox/src/client/index.ts +18 -0
- package/modules/sandbox/src/client/presentation.ts +47 -0
- package/modules/sandbox/src/client/state.ts +20 -0
- package/modules/sandbox/src/domain/types.ts +125 -0
- package/modules/sandbox/src/index.ts +33 -0
- package/modules/sandbox/src/platform.ts +28 -0
- package/modules/sandbox/src/server/index.ts +20 -0
- package/modules/sandbox/src/server/runtime.ts +119 -0
- package/modules/sandbox/src/services/database-repository.ts +567 -0
- package/modules/sandbox/src/services/directory.ts +33 -0
- package/modules/sandbox/src/services/index.ts +19 -0
- package/modules/sandbox/src/services/migration.ts +145 -0
- package/modules/sandbox/src/services/repository.ts +55 -0
- package/modules/sandbox/src/services/sandbox-service-error.ts +10 -0
- package/modules/sandbox/src/services/sandbox-service.ts +533 -0
- package/modules/sandbox/translations/en.json +77 -0
- package/modules/sandbox/translations/pl.json +77 -0
- package/modules/system/module.json +18 -0
- package/modules/system/package.json +56 -0
- package/modules/system/spec/module.yaml +104 -0
- package/modules/system/src/acl/permissions.ts +10 -0
- package/modules/system/src/client/ModuleSettingRow.tsrx +191 -0
- package/modules/system/src/client/ModuleSettingsSection.tsrx +155 -0
- package/modules/system/src/client/ModulesView.tsrx +241 -0
- package/modules/system/src/client/api.ts +36 -0
- package/modules/system/src/client/contribution.tsrx +48 -0
- package/modules/system/src/client/index.ts +26 -0
- package/modules/system/src/client/module-columns.tsrx +66 -0
- package/modules/system/src/client/overview-api.ts +30 -0
- package/modules/system/src/client/setting-copy.ts +30 -0
- package/modules/system/src/client/settings-api.ts +57 -0
- package/modules/system/src/client/state.ts +16 -0
- package/modules/system/src/index.ts +11 -0
- package/modules/system/src/platform.ts +11 -0
- package/modules/system/src/server/endpoints.ts +372 -0
- package/modules/system/src/server/index.ts +11 -0
- package/modules/system/src/server/module-catalog.ts +117 -0
- package/modules/system/translations/en.json +64 -0
- package/modules/system/translations/pl.json +64 -0
- package/modules/users/migrations/README.md +3 -0
- package/modules/users/module.json +27 -0
- package/modules/users/package.json +54 -0
- package/modules/users/spec/module.yaml +79 -0
- package/modules/users/src/acl/permissions.ts +6 -0
- package/modules/users/src/api/endpoints.ts +222 -0
- package/modules/users/src/client/InviteMemberForm.tsrx +62 -0
- package/modules/users/src/client/MemberDrawer.tsrx +298 -0
- package/modules/users/src/client/RoleForm.tsrx +140 -0
- package/modules/users/src/client/RolesView.tsrx +288 -0
- package/modules/users/src/client/UserAccountForm.tsrx +86 -0
- package/modules/users/src/client/UsersView.tsrx +486 -0
- package/modules/users/src/client/api.ts +172 -0
- package/modules/users/src/client/contribution.tsrx +92 -0
- package/modules/users/src/client/index.ts +19 -0
- package/modules/users/src/client/member-columns.tsrx +52 -0
- package/modules/users/src/client/roles-api.ts +90 -0
- package/modules/users/src/client/state.ts +42 -0
- package/modules/users/src/index.ts +27 -0
- package/modules/users/src/platform.ts +11 -0
- package/modules/users/src/services/index.ts +2 -0
- package/modules/users/src/services/users-service.ts +142 -0
- package/modules/users/translations/en.json +133 -0
- package/modules/users/translations/pl.json +133 -0
- package/modules/workflows/migrations/0001_workflows_core.down.sql +19 -0
- package/modules/workflows/migrations/0001_workflows_core.up.sql +228 -0
- package/modules/workflows/migrations/0002_workflows_authorization_subject.down.sql +1 -0
- package/modules/workflows/migrations/0002_workflows_authorization_subject.up.sql +9 -0
- package/modules/workflows/migrations/0003_workflows_worker_role.up.sql +34 -0
- package/modules/workflows/migrations/README.md +7 -0
- package/modules/workflows/module.json +31 -0
- package/modules/workflows/package.json +55 -0
- package/modules/workflows/spec/module.yaml +227 -0
- package/modules/workflows/src/acl/permissions.ts +10 -0
- package/modules/workflows/src/api/endpoints.ts +852 -0
- package/modules/workflows/src/client/WorkflowCanvas.tsrx +819 -0
- package/modules/workflows/src/client/WorkflowCreateForm.tsrx +111 -0
- package/modules/workflows/src/client/WorkflowEditor.tsrx +443 -0
- package/modules/workflows/src/client/WorkflowExecutionHistory.tsrx +169 -0
- package/modules/workflows/src/client/WorkflowFixtureDrawer.tsrx +206 -0
- package/modules/workflows/src/client/WorkflowInputForm.tsrx +125 -0
- package/modules/workflows/src/client/WorkflowInputSchemaEditor.tsrx +185 -0
- package/modules/workflows/src/client/WorkflowInspector.tsrx +471 -0
- package/modules/workflows/src/client/WorkflowLiveConfirmation.tsrx +67 -0
- package/modules/workflows/src/client/WorkflowMappingEditor.tsrx +283 -0
- package/modules/workflows/src/client/WorkflowNodePalette.tsrx +50 -0
- package/modules/workflows/src/client/WorkflowPointerField.tsrx +178 -0
- package/modules/workflows/src/client/WorkflowRevisionReview.tsrx +49 -0
- package/modules/workflows/src/client/WorkflowRunInspector.tsrx +143 -0
- package/modules/workflows/src/client/WorkflowTestPanel.tsrx +109 -0
- package/modules/workflows/src/client/WorkflowValidationPanel.tsrx +139 -0
- package/modules/workflows/src/client/WorkflowsView.tsrx +1060 -0
- package/modules/workflows/src/client/api.ts +312 -0
- package/modules/workflows/src/client/canvas-model.ts +472 -0
- package/modules/workflows/src/client/connected-node.ts +71 -0
- package/modules/workflows/src/client/contribution.tsrx +57 -0
- package/modules/workflows/src/client/create-model.ts +15 -0
- package/modules/workflows/src/client/draft-repair.ts +86 -0
- package/modules/workflows/src/client/index.ts +19 -0
- package/modules/workflows/src/client/input-model.ts +124 -0
- package/modules/workflows/src/client/mapping-model.ts +110 -0
- package/modules/workflows/src/client/pointer-model.ts +123 -0
- package/modules/workflows/src/client/presentation.ts +62 -0
- package/modules/workflows/src/client/run-actions.ts +19 -0
- package/modules/workflows/src/client/state.ts +57 -0
- package/modules/workflows/src/client/viewport.ts +107 -0
- package/modules/workflows/src/client/workflows.css +899 -0
- package/modules/workflows/src/domain/events.ts +399 -0
- package/modules/workflows/src/domain/graph.ts +1136 -0
- package/modules/workflows/src/domain/types.ts +563 -0
- package/modules/workflows/src/index.ts +27 -0
- package/modules/workflows/src/platform.ts +49 -0
- package/modules/workflows/src/server/index.ts +13 -0
- package/modules/workflows/src/server/runtime.ts +266 -0
- package/modules/workflows/src/services/cursor-codec.ts +62 -0
- package/modules/workflows/src/services/database-repository.ts +2407 -0
- package/modules/workflows/src/services/index.ts +6 -0
- package/modules/workflows/src/services/migration.ts +375 -0
- package/modules/workflows/src/services/payload-codec.ts +264 -0
- package/modules/workflows/src/services/repository.ts +285 -0
- package/modules/workflows/src/services/simulation.ts +359 -0
- package/modules/workflows/src/services/worker.ts +1196 -0
- package/modules/workflows/src/services/workflows-service.ts +1395 -0
- package/modules/workflows/translations/en.json +348 -0
- package/modules/workflows/translations/pl.json +348 -0
- package/modules.json +41 -0
- package/package.json +125 -0
- package/packages/ai-provider/package.json +46 -0
- package/packages/ai-provider/src/catalog.ts +102 -0
- package/packages/ai-provider/src/errors.ts +110 -0
- package/packages/ai-provider/src/index.ts +33 -0
- package/packages/ai-provider/src/model.ts +198 -0
- package/packages/ai-provider/src/pricing.ts +73 -0
- package/packages/cli-protocol/package.json +40 -0
- package/packages/cli-protocol/src/index.ts +113 -0
- package/packages/client/package.json +46 -0
- package/packages/client/src/ApplicationShell.tsrx +374 -0
- package/packages/client/src/contributions.ts +172 -0
- package/packages/client/src/i18n/index.ts +30 -0
- package/packages/client/src/i18n/locale.ts +25 -0
- package/packages/client/src/i18n/locales/en.json +66 -0
- package/packages/client/src/i18n/locales/pl.json +66 -0
- package/packages/client/src/i18n/runtime.ts +201 -0
- package/packages/client/src/i18n/translations.ts +88 -0
- package/packages/client/src/index.ts +55 -0
- package/packages/client/src/routing.ts +9 -0
- package/packages/client/src/shell/BrandMark.tsrx +10 -0
- package/packages/client/src/shell/CommandPalette.tsrx +79 -0
- package/packages/client/src/shell/ContributionOutlets.tsrx +31 -0
- package/packages/client/src/shell/DashboardView.tsrx +60 -0
- package/packages/client/src/shell/MobileHeader.tsrx +24 -0
- package/packages/client/src/shell/OrganizationSwitcher.tsrx +100 -0
- package/packages/client/src/shell/OverviewCharts.tsrx +167 -0
- package/packages/client/src/shell/PrimaryNavigation.tsrx +75 -0
- package/packages/client/src/shell/Sidebar.tsrx +76 -0
- package/packages/client/src/shell/Topbar.tsrx +44 -0
- package/packages/client/src/shell/UserMenu.tsrx +103 -0
- package/packages/client/src/shell/WorkspaceContent.tsrx +30 -0
- package/packages/client/src/shell/identity.ts +12 -0
- package/packages/client/src/shell/navigation.ts +68 -0
- package/packages/client/src/shell/shell.css +734 -0
- package/packages/client/src/shell/types.ts +29 -0
- package/packages/client/src/state.ts +63 -0
- package/packages/client/src/web.ts +39 -0
- package/packages/coding-agent/package.json +44 -0
- package/packages/coding-agent/src/drivers/byok.ts +322 -0
- package/packages/coding-agent/src/drivers/claude-code.ts +290 -0
- package/packages/coding-agent/src/drivers/codex.ts +281 -0
- package/packages/coding-agent/src/index.ts +56 -0
- package/packages/coding-agent/src/registry.ts +119 -0
- package/packages/coding-agent/src/roles/contract.ts +60 -0
- package/packages/coding-agent/src/roles/defaults.ts +134 -0
- package/packages/coding-agent/src/roles/handoff.ts +41 -0
- package/packages/coding-agent/src/roles/registry.ts +156 -0
- package/packages/coding-agent/src/roles/skills.ts +72 -0
- package/packages/coding-agent/src/roles/sync.ts +88 -0
- package/packages/coding-agent/src/types.ts +102 -0
- package/packages/coding-agent/src/workspace.ts +275 -0
- package/packages/contracts/package.json +38 -0
- package/packages/contracts/schemas/blueprint.schema.json +48 -0
- package/packages/contracts/schemas/cli-extension.schema.json +90 -0
- package/packages/contracts/schemas/module-artifact.schema.json +82 -0
- package/packages/contracts/schemas/module-catalog.schema.json +48 -0
- package/packages/contracts/schemas/module-spec.schema.json +111 -0
- package/packages/contracts/schemas/module.schema.json +156 -0
- package/packages/contracts/schemas/platform-spec.schema.json +17 -0
- package/packages/contracts/schemas/project.schema.json +270 -0
- package/packages/contracts/src/index.ts +191 -0
- package/packages/contracts/src/module-distribution.ts +47 -0
- package/packages/contracts/src/schemas.ts +18 -0
- package/packages/contracts/src/variables.ts +156 -0
- package/packages/contracts/src/web.ts +60 -0
- package/packages/database/package.json +43 -0
- package/packages/database/src/contracts.ts +399 -0
- package/packages/database/src/index.ts +112 -0
- package/packages/database/src/migrations.ts +444 -0
- package/packages/database/src/postgresql.ts +517 -0
- package/packages/database/src/provider.ts +639 -0
- package/packages/database/src/record-history.ts +201 -0
- package/packages/database/src/registry.ts +265 -0
- package/packages/database/src/reset.ts +87 -0
- package/packages/database-pglite/package.json +42 -0
- package/packages/database-pglite/src/driver.ts +168 -0
- package/packages/database-pglite/src/index.ts +2 -0
- package/packages/database-testing/package.json +44 -0
- package/packages/database-testing/src/index.ts +8 -0
- package/packages/database-testing/src/pglite.ts +124 -0
- package/packages/database-testing/src/postgres.ts +184 -0
- package/packages/database-testing/src/provider.ts +43 -0
- package/packages/database-testing/src/vitest-preset.ts +23 -0
- package/packages/dev-console/README.md +6 -0
- package/packages/dev-console/package.json +38 -0
- package/packages/dev-console/src/index.mjs +220 -0
- package/packages/harness/package.json +47 -0
- package/packages/harness/schemas/task-packet.schema.json +48 -0
- package/packages/harness/src/catalog.ts +24 -0
- package/packages/harness/src/errors.ts +9 -0
- package/packages/harness/src/index.ts +53 -0
- package/packages/harness/src/preamble.ts +31 -0
- package/packages/harness/src/runtime.ts +833 -0
- package/packages/harness/src/task-packet.ts +86 -0
- package/packages/harness/src/tool-adapters.ts +106 -0
- package/packages/harness/src/tool-contract.ts +242 -0
- package/packages/harness/src/vercel-ai-provider.ts +198 -0
- package/packages/kernel/package.json +44 -0
- package/packages/kernel/src/acl.ts +20 -0
- package/packages/kernel/src/actor.ts +139 -0
- package/packages/kernel/src/agent-registry.ts +81 -0
- package/packages/kernel/src/capability-registry.ts +28 -0
- package/packages/kernel/src/errors.ts +9 -0
- package/packages/kernel/src/index.ts +90 -0
- package/packages/kernel/src/legacy-local-state.ts +103 -0
- package/packages/kernel/src/module-compatibility.ts +70 -0
- package/packages/kernel/src/module-registry.ts +124 -0
- package/packages/kernel/src/module-settings.ts +403 -0
- package/packages/kernel/src/record-history.ts +146 -0
- package/packages/kernel/src/runtime-config.ts +51 -0
- package/packages/kernel/src/tool-registry.ts +25 -0
- package/packages/kernel/src/variable-registry.ts +339 -0
- package/packages/sandbox/README.md +691 -0
- package/packages/sandbox/bin/flowdular-sandbox.mjs +393 -0
- package/packages/sandbox/dist/client/assets/App-ClMOrpyg.js +11 -0
- package/packages/sandbox/dist/client/assets/PreviewHost-BHiHrfbQ.js +1 -0
- package/packages/sandbox/dist/client/assets/auto-buGEq6de.js +3 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-BSMlKf0J.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-400-normal-CEL4l2ZJ.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Ael50iVv.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-500-normal-Bq9vWWag.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-DMdlQ8Kv.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-400-normal-xuaO2J-f.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BIfNGwUT.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-cyrillic-ext-500-normal-BqneJy0T.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-BmRBH3aV.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-400-normal-D3D2R8hC.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CAhNIIs5.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-latin-ext-500-normal-CZ70TYgx.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-BulugwFq.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-400-normal-DDuiU_S-.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-C8zxqsMH.woff +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-mono-vietnamese-500-normal-DZ4AoWbu.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-cyrillic-ext-wght-normal-d45eAU9y.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-cyrillic-wght-normal-BAAhND-U.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-greek-wght-normal-CmyJS8uq.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-latin-ext-wght-normal-CIII54If.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-latin-wght-normal-IvpUvPa2.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/ibm-plex-sans-vietnamese-wght-normal-Dg1JeJN0.woff2 +0 -0
- package/packages/sandbox/dist/client/assets/index-CvwhlQ87.js +4 -0
- package/packages/sandbox/dist/client/assets/styles-BPWaGf55.js +3 -0
- package/packages/sandbox/dist/client/assets/styles-Dx1_KOag.css +1 -0
- package/packages/sandbox/dist/client/favicon.svg +1 -0
- package/packages/sandbox/dist/server/assets/auto-CVGNYyb3.js +12785 -0
- package/packages/sandbox/dist/server/assets/chunk-DDJLRBDX-3OUNo51g.js +4125 -0
- package/packages/sandbox/dist/server/assets/nodefs-DVSI7kG0.js +24 -0
- package/packages/sandbox/dist/server/assets/opfs-ahp-D56iokt1.js +388 -0
- package/packages/sandbox/dist/server/assets/token-Bvaq7Anz.js +55 -0
- package/packages/sandbox/dist/server/assets/token-util-BqSvdIPQ.js +3 -0
- package/packages/sandbox/dist/server/assets/token-util-CktFFT4z.js +494 -0
- package/packages/sandbox/dist/server/entry.js +91671 -0
- package/packages/sandbox/dist/server/favicon.svg +1 -0
- package/packages/sandbox/dist/server/index.html +161 -0
- package/packages/sandbox/index.html +159 -0
- package/packages/sandbox/octane.config.ts +36 -0
- package/packages/sandbox/package.json +83 -0
- package/packages/sandbox/public/favicon.svg +1 -0
- package/packages/sandbox/public/og.png +0 -0
- package/packages/sandbox/src/App.tsrx +924 -0
- package/packages/sandbox/src/client/ApprovalHandoff.tsrx +39 -0
- package/packages/sandbox/src/client/ChatPane.tsrx +694 -0
- package/packages/sandbox/src/client/ConnectView.tsrx +86 -0
- package/packages/sandbox/src/client/DiffPane.tsrx +150 -0
- package/packages/sandbox/src/client/EjectModal.tsrx +571 -0
- package/packages/sandbox/src/client/GateResults.tsrx +60 -0
- package/packages/sandbox/src/client/GitHubSettingsModal.tsrx +219 -0
- package/packages/sandbox/src/client/NewSessionForm.tsrx +214 -0
- package/packages/sandbox/src/client/SessionBar.tsrx +151 -0
- package/packages/sandbox/src/client/SessionPicker.tsrx +472 -0
- package/packages/sandbox/src/client/SpecEditor.tsrx +109 -0
- package/packages/sandbox/src/client/SpecReviewCard.tsrx +321 -0
- package/packages/sandbox/src/client/WorkCard.tsrx +128 -0
- package/packages/sandbox/src/client/WorkbenchModal.tsrx +161 -0
- package/packages/sandbox/src/client/WorkspaceMenu.tsrx +100 -0
- package/packages/sandbox/src/client/api.ts +797 -0
- package/packages/sandbox/src/client/attachments.ts +73 -0
- package/packages/sandbox/src/client/dashboard.ts +46 -0
- package/packages/sandbox/src/client/github-settings.ts +48 -0
- package/packages/sandbox/src/client/highlight.ts +105 -0
- package/packages/sandbox/src/client/i18n.ts +32 -0
- package/packages/sandbox/src/client/locales/en.json +466 -0
- package/packages/sandbox/src/client/locales/pl.json +466 -0
- package/packages/sandbox/src/client/session-labels.ts +77 -0
- package/packages/sandbox/src/client/state.ts +108 -0
- package/packages/sandbox/src/index.ts +10 -0
- package/packages/sandbox/src/preview/PreviewHost.tsrx +373 -0
- package/packages/sandbox/src/preview/load-module.ts +16 -0
- package/packages/sandbox/src/server/attachments.ts +308 -0
- package/packages/sandbox/src/server/auto-review.ts +181 -0
- package/packages/sandbox/src/server/checkpoints.ts +90 -0
- package/packages/sandbox/src/server/config.ts +460 -0
- package/packages/sandbox/src/server/dashboard.ts +245 -0
- package/packages/sandbox/src/server/delivery/configuration.ts +193 -0
- package/packages/sandbox/src/server/delivery/git-pr.ts +1473 -0
- package/packages/sandbox/src/server/delivery/index.ts +83 -0
- package/packages/sandbox/src/server/delivery/local.ts +151 -0
- package/packages/sandbox/src/server/delivery/official-modules.ts +516 -0
- package/packages/sandbox/src/server/delivery/plan.ts +218 -0
- package/packages/sandbox/src/server/delivery/policies.ts +239 -0
- package/packages/sandbox/src/server/delivery/record.ts +41 -0
- package/packages/sandbox/src/server/delivery/steps.ts +464 -0
- package/packages/sandbox/src/server/delivery/types.ts +158 -0
- package/packages/sandbox/src/server/dependencies.ts +88 -0
- package/packages/sandbox/src/server/diff.ts +230 -0
- package/packages/sandbox/src/server/gates.ts +388 -0
- package/packages/sandbox/src/server/index.ts +139 -0
- package/packages/sandbox/src/server/path-guard.ts +282 -0
- package/packages/sandbox/src/server/planning.ts +749 -0
- package/packages/sandbox/src/server/platform-client.ts +189 -0
- package/packages/sandbox/src/server/preview-database-host.ts +340 -0
- package/packages/sandbox/src/server/preview-database-protocol.ts +163 -0
- package/packages/sandbox/src/server/preview-database-proxy.ts +356 -0
- package/packages/sandbox/src/server/preview-database.ts +109 -0
- package/packages/sandbox/src/server/preview-ipc.ts +15 -0
- package/packages/sandbox/src/server/preview-modules.ts +83 -0
- package/packages/sandbox/src/server/preview-revision.ts +44 -0
- package/packages/sandbox/src/server/preview-runtime.ts +467 -0
- package/packages/sandbox/src/server/preview-worker-manager.ts +436 -0
- package/packages/sandbox/src/server/preview-worker.ts +168 -0
- package/packages/sandbox/src/server/reference.ts +251 -0
- package/packages/sandbox/src/server/routes.ts +2258 -0
- package/packages/sandbox/src/server/runtime.ts +188 -0
- package/packages/sandbox/src/server/session-owner.ts +23 -0
- package/packages/sandbox/src/server/sessions.ts +849 -0
- package/packages/sandbox/src/server/spec.ts +471 -0
- package/packages/sandbox/src/server/turn-lifecycle.ts +56 -0
- package/packages/sandbox/src/server/turns.ts +993 -0
- package/packages/sandbox/src/server/workspace-install.ts +266 -0
- package/packages/sandbox/src/server/workspace-root.ts +73 -0
- package/packages/sandbox/src/styles.css +1573 -0
- package/packages/sandbox/vite.config.ts +133 -0
- package/packages/server/package.json +43 -0
- package/packages/server/src/application-routes.ts +21 -0
- package/packages/server/src/composition.ts +48 -0
- package/packages/server/src/endpoint.ts +142 -0
- package/packages/server/src/http.ts +128 -0
- package/packages/server/src/index.ts +46 -0
- package/packages/server/src/response-lifetime.ts +56 -0
- package/packages/server/src/security-headers.ts +130 -0
- package/packages/server/src/web-html.ts +55 -0
- package/packages/server/src/web.ts +361 -0
- package/packages/ui/package.json +46 -0
- package/packages/ui/src/brand/BrandMark.tsrx +66 -0
- package/packages/ui/src/brand/mark.ts +44 -0
- package/packages/ui/src/components/Alert.tsrx +17 -0
- package/packages/ui/src/components/Avatar.tsrx +18 -0
- package/packages/ui/src/components/Button.tsrx +29 -0
- package/packages/ui/src/components/Chart.tsrx +274 -0
- package/packages/ui/src/components/CheckGrid.tsrx +93 -0
- package/packages/ui/src/components/ConfirmDialog.tsrx +63 -0
- package/packages/ui/src/components/Drawer.tsrx +71 -0
- package/packages/ui/src/components/EmptyState.tsrx +26 -0
- package/packages/ui/src/components/Filters.tsrx +39 -0
- package/packages/ui/src/components/FormField.tsrx +27 -0
- package/packages/ui/src/components/Kpi.tsrx +36 -0
- package/packages/ui/src/components/PageHeader.tsrx +26 -0
- package/packages/ui/src/components/ScopeSummary.tsrx +76 -0
- package/packages/ui/src/components/SearchField.tsrx +24 -0
- package/packages/ui/src/components/SettingRow.tsrx +50 -0
- package/packages/ui/src/components/Switch.tsrx +21 -0
- package/packages/ui/src/components/Table.tsrx +267 -0
- package/packages/ui/src/components/TableCard.tsrx +52 -0
- package/packages/ui/src/components/Tag.tsrx +28 -0
- package/packages/ui/src/components/VariableField.tsrx +284 -0
- package/packages/ui/src/components/VariableInput.tsrx +7 -0
- package/packages/ui/src/components/VariableSelect.tsrx +72 -0
- package/packages/ui/src/components/VariableTextarea.tsrx +9 -0
- package/packages/ui/src/components/variable-field.ts +61 -0
- package/packages/ui/src/components/variable-select.ts +69 -0
- package/packages/ui/src/icons/Icon.tsrx +56 -0
- package/packages/ui/src/index.ts +81 -0
- package/packages/ui/src/initials.ts +10 -0
- package/packages/ui/src/styles/base.css +71 -0
- package/packages/ui/src/styles/components.css +1859 -0
- package/packages/ui/src/styles/index.css +3 -0
- package/packages/ui/src/styles/tokens.css +124 -0
- package/tsconfig.base.json +18 -0
|
@@ -0,0 +1,763 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import type { DatabaseHandle, DatabaseTransaction } from '@flowdular/sdk/database';
|
|
3
|
+
import { runDatabaseMigrations } from '@flowdular/sdk/database';
|
|
4
|
+
import { normalizeActor } from '@flowdular/sdk/kernel';
|
|
5
|
+
import type { UserActor } from '@flowdular/sdk/kernel';
|
|
6
|
+
import type {
|
|
7
|
+
AutomationAuditEvent,
|
|
8
|
+
AutomationAuditVerification,
|
|
9
|
+
} from '../domain/types.ts';
|
|
10
|
+
import { databaseMigrations } from './migration.ts';
|
|
11
|
+
import type {
|
|
12
|
+
AutomationScheduleRouting,
|
|
13
|
+
AutomationsRepository,
|
|
14
|
+
AutomationTriggerRecord,
|
|
15
|
+
StoredAutomationSchedule,
|
|
16
|
+
StoredAutomationTrigger,
|
|
17
|
+
StoredAutomationTriggerWithSecret,
|
|
18
|
+
} from './repository.ts';
|
|
19
|
+
import type { EncryptedSecret } from './secret-vault.ts';
|
|
20
|
+
|
|
21
|
+
interface ScheduleRow {
|
|
22
|
+
id: string;
|
|
23
|
+
tenant_id: string;
|
|
24
|
+
agent_id: string;
|
|
25
|
+
target_kind: string;
|
|
26
|
+
target_key: string | null;
|
|
27
|
+
configured_by_json: string | null;
|
|
28
|
+
permission_snapshot_json: string;
|
|
29
|
+
label: string;
|
|
30
|
+
input_template: string;
|
|
31
|
+
cadence: string;
|
|
32
|
+
enabled: number | bigint | string;
|
|
33
|
+
disabled_reason: string | null;
|
|
34
|
+
next_run_at: number | bigint | string;
|
|
35
|
+
last_run_at: number | bigint | string | null;
|
|
36
|
+
last_run_id: string | null;
|
|
37
|
+
last_error: string | null;
|
|
38
|
+
created_at: number | bigint | string;
|
|
39
|
+
updated_at: number | bigint | string;
|
|
40
|
+
created_by: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface TriggerRow {
|
|
44
|
+
id: string;
|
|
45
|
+
tenant_id: string;
|
|
46
|
+
agent_id: string;
|
|
47
|
+
target_kind: string;
|
|
48
|
+
target_key: string | null;
|
|
49
|
+
configured_by_json: string | null;
|
|
50
|
+
permission_snapshot_json: string;
|
|
51
|
+
label: string;
|
|
52
|
+
secret_key_id: string;
|
|
53
|
+
secret_iv: string;
|
|
54
|
+
secret_tag: string;
|
|
55
|
+
secret_ciphertext: string;
|
|
56
|
+
secret_revision: number | bigint | string;
|
|
57
|
+
enabled: number | bigint | string;
|
|
58
|
+
created_at: number | bigint | string;
|
|
59
|
+
updated_at: number | bigint | string;
|
|
60
|
+
created_by: string;
|
|
61
|
+
last_fired_at: number | bigint | string | null;
|
|
62
|
+
accepted_count: number | bigint | string;
|
|
63
|
+
rejected_count: number | bigint | string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface AuditRow {
|
|
67
|
+
id: string;
|
|
68
|
+
tenant_id: string;
|
|
69
|
+
sequence: number | bigint | string;
|
|
70
|
+
actor_id: string;
|
|
71
|
+
action: string;
|
|
72
|
+
subject_type: AutomationAuditEvent['subjectType'];
|
|
73
|
+
subject_id: string;
|
|
74
|
+
metadata_json: string;
|
|
75
|
+
occurred_at: number | bigint | string;
|
|
76
|
+
previous_hash: string | null;
|
|
77
|
+
event_hash: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/* PostgreSQL returns BIGINT as a string. The audit hash covers sequence and
|
|
81
|
+
occurredAt, so a string here would break the chain rather than merely look
|
|
82
|
+
wrong. */
|
|
83
|
+
function integer(value: number | bigint | string): number {
|
|
84
|
+
const normalized = Number(value);
|
|
85
|
+
if (!Number.isSafeInteger(normalized)) {
|
|
86
|
+
throw new Error('The automations database returned an invalid integer.');
|
|
87
|
+
}
|
|
88
|
+
return normalized;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function optionalInteger(
|
|
92
|
+
value: number | bigint | string | null,
|
|
93
|
+
): number | null {
|
|
94
|
+
return value === null ? null : integer(value);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function configuredBy(value: string | null, createdBy: string): UserActor {
|
|
98
|
+
try {
|
|
99
|
+
const actor = normalizeActor(JSON.parse(value ?? 'null'));
|
|
100
|
+
if (actor?.kind === 'user') return actor;
|
|
101
|
+
} catch {
|
|
102
|
+
/* Pre-ledger and manually repaired rows retain created_by as the safe
|
|
103
|
+
authority provenance instead of accepting malformed JSON. */
|
|
104
|
+
}
|
|
105
|
+
return { kind: 'user', id: createdBy, label: createdBy };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function permissionSnapshot(value: string): readonly string[] {
|
|
109
|
+
try {
|
|
110
|
+
const parsed = JSON.parse(value) as unknown;
|
|
111
|
+
if (
|
|
112
|
+
!Array.isArray(parsed) ||
|
|
113
|
+
parsed.some((entry) => typeof entry !== 'string')
|
|
114
|
+
)
|
|
115
|
+
return [];
|
|
116
|
+
return [...new Set(parsed)].sort();
|
|
117
|
+
} catch {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function schedule(row: ScheduleRow): StoredAutomationSchedule {
|
|
123
|
+
const targetKind = row.target_kind || 'agent';
|
|
124
|
+
const targetKey = row.target_key ?? row.agent_id;
|
|
125
|
+
return {
|
|
126
|
+
id: row.id,
|
|
127
|
+
tenantId: row.tenant_id,
|
|
128
|
+
targetKind,
|
|
129
|
+
targetKey,
|
|
130
|
+
agentId: targetKind === 'agent' ? targetKey : '',
|
|
131
|
+
label: row.label,
|
|
132
|
+
inputTemplate: row.input_template,
|
|
133
|
+
cadence: row.cadence,
|
|
134
|
+
enabled: integer(row.enabled) === 1,
|
|
135
|
+
disabledReason: row.disabled_reason,
|
|
136
|
+
nextRunAt: integer(row.next_run_at),
|
|
137
|
+
lastRunAt: optionalInteger(row.last_run_at),
|
|
138
|
+
lastRunId: row.last_run_id,
|
|
139
|
+
lastError: row.last_error,
|
|
140
|
+
createdAt: integer(row.created_at),
|
|
141
|
+
updatedAt: integer(row.updated_at),
|
|
142
|
+
createdBy: row.created_by,
|
|
143
|
+
configuredBy: configuredBy(row.configured_by_json, row.created_by),
|
|
144
|
+
permissionSnapshot: permissionSnapshot(row.permission_snapshot_json),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function trigger(row: TriggerRow): StoredAutomationTrigger {
|
|
149
|
+
const targetKind = row.target_kind || 'agent';
|
|
150
|
+
const targetKey = row.target_key ?? row.agent_id;
|
|
151
|
+
return {
|
|
152
|
+
id: row.id,
|
|
153
|
+
tenantId: row.tenant_id,
|
|
154
|
+
targetKind,
|
|
155
|
+
targetKey,
|
|
156
|
+
agentId: targetKind === 'agent' ? targetKey : '',
|
|
157
|
+
label: row.label,
|
|
158
|
+
enabled: integer(row.enabled) === 1,
|
|
159
|
+
secretRevision: integer(row.secret_revision),
|
|
160
|
+
createdAt: integer(row.created_at),
|
|
161
|
+
updatedAt: integer(row.updated_at),
|
|
162
|
+
createdBy: row.created_by,
|
|
163
|
+
lastFiredAt: optionalInteger(row.last_fired_at),
|
|
164
|
+
acceptedCount: integer(row.accepted_count),
|
|
165
|
+
rejectedCount: integer(row.rejected_count),
|
|
166
|
+
configuredBy: configuredBy(row.configured_by_json, row.created_by),
|
|
167
|
+
permissionSnapshot: permissionSnapshot(row.permission_snapshot_json),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function encrypted(row: TriggerRow): EncryptedSecret {
|
|
172
|
+
return {
|
|
173
|
+
keyId: row.secret_key_id,
|
|
174
|
+
iv: row.secret_iv,
|
|
175
|
+
tag: row.secret_tag,
|
|
176
|
+
ciphertext: row.secret_ciphertext,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function stableMetadata(
|
|
181
|
+
metadata: Readonly<Record<string, string | number | boolean>>,
|
|
182
|
+
): string {
|
|
183
|
+
return JSON.stringify(
|
|
184
|
+
Object.fromEntries(
|
|
185
|
+
Object.entries(metadata).sort(([left], [right]) =>
|
|
186
|
+
left.localeCompare(right),
|
|
187
|
+
),
|
|
188
|
+
),
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function auditHash(value: {
|
|
193
|
+
tenantId: string;
|
|
194
|
+
sequence: number | bigint | string;
|
|
195
|
+
actorId: string;
|
|
196
|
+
action: string;
|
|
197
|
+
subjectType: AutomationAuditEvent['subjectType'];
|
|
198
|
+
subjectId: string;
|
|
199
|
+
metadataJson: string;
|
|
200
|
+
occurredAt: number;
|
|
201
|
+
previousHash: string | null;
|
|
202
|
+
}): string {
|
|
203
|
+
return createHash('sha256')
|
|
204
|
+
.update(
|
|
205
|
+
JSON.stringify([
|
|
206
|
+
value.tenantId,
|
|
207
|
+
value.sequence,
|
|
208
|
+
value.actorId,
|
|
209
|
+
value.action,
|
|
210
|
+
value.subjectType,
|
|
211
|
+
value.subjectId,
|
|
212
|
+
value.metadataJson,
|
|
213
|
+
value.occurredAt,
|
|
214
|
+
value.previousHash,
|
|
215
|
+
]),
|
|
216
|
+
)
|
|
217
|
+
.digest('hex');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function audit(row: AuditRow): AutomationAuditEvent {
|
|
221
|
+
return {
|
|
222
|
+
id: row.id,
|
|
223
|
+
tenantId: row.tenant_id,
|
|
224
|
+
sequence: integer(row.sequence),
|
|
225
|
+
actorId: row.actor_id,
|
|
226
|
+
action: row.action,
|
|
227
|
+
subjectType: row.subject_type,
|
|
228
|
+
subjectId: row.subject_id,
|
|
229
|
+
metadata: JSON.parse(row.metadata_json) as Readonly<
|
|
230
|
+
Record<string, string | number | boolean>
|
|
231
|
+
>,
|
|
232
|
+
occurredAt: integer(row.occurred_at),
|
|
233
|
+
previousHash: row.previous_hash,
|
|
234
|
+
eventHash: row.event_hash,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const SCHEDULE_INSERT_COLUMNS = `(id, tenant_id, agent_id, target_kind, target_key,
|
|
239
|
+
configured_by_json, permission_snapshot_json,
|
|
240
|
+
label, input_template, cadence, enabled,
|
|
241
|
+
disabled_reason, next_run_at, last_run_at, last_run_id, last_error,
|
|
242
|
+
created_at, updated_at, created_by)`;
|
|
243
|
+
|
|
244
|
+
const TRIGGER_INSERT_COLUMNS = `(id, tenant_id, agent_id, target_kind, target_key,
|
|
245
|
+
configured_by_json, permission_snapshot_json,
|
|
246
|
+
label, secret_key_id, secret_iv, secret_tag,
|
|
247
|
+
secret_ciphertext, secret_revision, enabled, created_at, updated_at,
|
|
248
|
+
created_by, last_fired_at, accepted_count, rejected_count)`;
|
|
249
|
+
|
|
250
|
+
const AUDIT_INSERT_COLUMNS = `(id, tenant_id, sequence, actor_id, action,
|
|
251
|
+
subject_type, subject_id, metadata_json, occurred_at,
|
|
252
|
+
previous_hash, event_hash)`;
|
|
253
|
+
|
|
254
|
+
function markers(count: number): string {
|
|
255
|
+
return Array.from({ length: count }, (_value, index) => `$${index + 1}`).join(
|
|
256
|
+
', ',
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const SQL = {
|
|
261
|
+
listSchedules: `SELECT * FROM automations_schedules WHERE tenant_id = $1
|
|
262
|
+
ORDER BY lower(label), id`,
|
|
263
|
+
getSchedule: `SELECT * FROM automations_schedules
|
|
264
|
+
WHERE tenant_id = $1 AND id = $2`,
|
|
265
|
+
createSchedule: `INSERT INTO automations_schedules
|
|
266
|
+
${SCHEDULE_INSERT_COLUMNS}
|
|
267
|
+
VALUES (${markers(19)})`,
|
|
268
|
+
updateSchedule: `UPDATE automations_schedules SET agent_id = $1,
|
|
269
|
+
target_kind = $2, target_key = $3, configured_by_json = $4,
|
|
270
|
+
permission_snapshot_json = $5, label = $6, input_template = $7,
|
|
271
|
+
cadence = $8, enabled = $9, disabled_reason = $10,
|
|
272
|
+
next_run_at = $11, updated_at = $12
|
|
273
|
+
WHERE tenant_id = $13 AND id = $14`,
|
|
274
|
+
deleteSchedule: `DELETE FROM automations_schedules
|
|
275
|
+
WHERE tenant_id = $1 AND id = $2`,
|
|
276
|
+
/* Read through the cross-tenant background lease; the write that follows
|
|
277
|
+
uses the tenant of the row this returned. */
|
|
278
|
+
listDueSchedules: `SELECT tenant_id, id, next_run_at
|
|
279
|
+
FROM automations_schedules WHERE enabled = 1
|
|
280
|
+
AND next_run_at <= $1 ORDER BY next_run_at, id LIMIT $2`,
|
|
281
|
+
advanceSchedule: `UPDATE automations_schedules SET next_run_at = $1,
|
|
282
|
+
last_run_at = $2, last_run_id = $3, last_error = $4,
|
|
283
|
+
updated_at = $5
|
|
284
|
+
WHERE tenant_id = $6 AND id = $7 AND enabled = 1
|
|
285
|
+
AND next_run_at = $8`,
|
|
286
|
+
disableSchedule: `UPDATE automations_schedules SET enabled = 0,
|
|
287
|
+
disabled_reason = $1, updated_at = $2
|
|
288
|
+
WHERE tenant_id = $3 AND id = $4 AND enabled = 1`,
|
|
289
|
+
listTriggers: `SELECT * FROM automations_triggers WHERE tenant_id = $1
|
|
290
|
+
ORDER BY lower(label), id`,
|
|
291
|
+
getTrigger: `SELECT * FROM automations_triggers
|
|
292
|
+
WHERE tenant_id = $1 AND id = $2`,
|
|
293
|
+
/* Read through the cross-tenant background lease. It routes a webhook to a
|
|
294
|
+
tenant and nothing more; the trigger itself is read again under that
|
|
295
|
+
tenant, where the secret and the target actually live. */
|
|
296
|
+
findTriggerTenant: `SELECT tenant_id FROM automations_triggers WHERE id = $1`,
|
|
297
|
+
createTrigger: `INSERT INTO automations_triggers
|
|
298
|
+
${TRIGGER_INSERT_COLUMNS}
|
|
299
|
+
VALUES (${markers(20)})`,
|
|
300
|
+
updateTrigger: `UPDATE automations_triggers SET agent_id = $1,
|
|
301
|
+
target_kind = $2, target_key = $3, configured_by_json = $4,
|
|
302
|
+
permission_snapshot_json = $5, label = $6, enabled = $7,
|
|
303
|
+
updated_at = $8 WHERE tenant_id = $9 AND id = $10`,
|
|
304
|
+
rotateTriggerSecret: `UPDATE automations_triggers SET secret_key_id = $1,
|
|
305
|
+
secret_iv = $2, secret_tag = $3, secret_ciphertext = $4,
|
|
306
|
+
secret_revision = secret_revision + 1, updated_at = $5
|
|
307
|
+
WHERE tenant_id = $6 AND id = $7`,
|
|
308
|
+
deleteTrigger: `DELETE FROM automations_triggers
|
|
309
|
+
WHERE tenant_id = $1 AND id = $2`,
|
|
310
|
+
recordTriggerOutcome: `UPDATE automations_triggers SET last_fired_at = $1,
|
|
311
|
+
accepted_count = accepted_count + $2,
|
|
312
|
+
rejected_count = rejected_count + $3
|
|
313
|
+
WHERE tenant_id = $4 AND id = $5`,
|
|
314
|
+
latestAudit: `SELECT sequence, event_hash FROM automations_audit_events
|
|
315
|
+
WHERE tenant_id = $1 ORDER BY sequence DESC LIMIT 1`,
|
|
316
|
+
insertAudit: `INSERT INTO automations_audit_events
|
|
317
|
+
${AUDIT_INSERT_COLUMNS}
|
|
318
|
+
VALUES (${markers(11)})`,
|
|
319
|
+
listAudit: `SELECT * FROM automations_audit_events WHERE tenant_id = $1
|
|
320
|
+
ORDER BY sequence DESC LIMIT $2`,
|
|
321
|
+
auditChain: `SELECT * FROM automations_audit_events WHERE tenant_id = $1
|
|
322
|
+
ORDER BY sequence ASC`,
|
|
323
|
+
} as const;
|
|
324
|
+
|
|
325
|
+
export async function migrateAutomationsDatabase(
|
|
326
|
+
database: DatabaseHandle,
|
|
327
|
+
): Promise<void> {
|
|
328
|
+
await runDatabaseMigrations(database, 'automations.core', databaseMigrations);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export interface AutomationsDatabaseHandles {
|
|
332
|
+
/** Tenant-scoped handle used by every request-time read and write. */
|
|
333
|
+
readonly runtime: DatabaseHandle;
|
|
334
|
+
/**
|
|
335
|
+
* Cross-tenant read handle for the scheduler poll and the webhook lookup.
|
|
336
|
+
* It reads only what the tables' own FOR SELECT policy grants and writes
|
|
337
|
+
* nothing; the write that follows uses the tenant of the row it returned.
|
|
338
|
+
*/
|
|
339
|
+
readonly background: DatabaseHandle;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** A repository over platform-owned PostgreSQL handles. */
|
|
343
|
+
export class DatabaseAutomationsRepository implements AutomationsRepository {
|
|
344
|
+
constructor(private readonly handles: AutomationsDatabaseHandles) {}
|
|
345
|
+
|
|
346
|
+
async listSchedules(
|
|
347
|
+
tenantId: string,
|
|
348
|
+
): Promise<readonly StoredAutomationSchedule[]> {
|
|
349
|
+
const result = await this.#read<ScheduleRow>(tenantId, {
|
|
350
|
+
text: SQL.listSchedules,
|
|
351
|
+
parameters: [tenantId],
|
|
352
|
+
});
|
|
353
|
+
return result.map(schedule);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
async getSchedule(
|
|
357
|
+
tenantId: string,
|
|
358
|
+
scheduleId: string,
|
|
359
|
+
): Promise<StoredAutomationSchedule | null> {
|
|
360
|
+
const rows = await this.#read<ScheduleRow>(tenantId, {
|
|
361
|
+
text: SQL.getSchedule,
|
|
362
|
+
parameters: [tenantId, scheduleId],
|
|
363
|
+
});
|
|
364
|
+
return rows[0] ? schedule(rows[0]) : null;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
async createSchedule(
|
|
368
|
+
record: StoredAutomationSchedule,
|
|
369
|
+
): Promise<StoredAutomationSchedule> {
|
|
370
|
+
await this.#write(record.tenantId, {
|
|
371
|
+
text: SQL.createSchedule,
|
|
372
|
+
parameters: [
|
|
373
|
+
record.id,
|
|
374
|
+
record.tenantId,
|
|
375
|
+
record.agentId,
|
|
376
|
+
record.targetKind,
|
|
377
|
+
record.targetKey,
|
|
378
|
+
JSON.stringify(record.configuredBy),
|
|
379
|
+
JSON.stringify([...new Set(record.permissionSnapshot)].sort()),
|
|
380
|
+
record.label,
|
|
381
|
+
record.inputTemplate,
|
|
382
|
+
record.cadence,
|
|
383
|
+
record.enabled ? 1 : 0,
|
|
384
|
+
record.disabledReason,
|
|
385
|
+
record.nextRunAt,
|
|
386
|
+
record.lastRunAt,
|
|
387
|
+
record.lastRunId,
|
|
388
|
+
record.lastError,
|
|
389
|
+
record.createdAt,
|
|
390
|
+
record.updatedAt,
|
|
391
|
+
record.createdBy,
|
|
392
|
+
],
|
|
393
|
+
});
|
|
394
|
+
return record;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
async updateSchedule(
|
|
398
|
+
record: StoredAutomationSchedule,
|
|
399
|
+
): Promise<StoredAutomationSchedule> {
|
|
400
|
+
const affected = await this.#write(record.tenantId, {
|
|
401
|
+
text: SQL.updateSchedule,
|
|
402
|
+
parameters: [
|
|
403
|
+
record.agentId,
|
|
404
|
+
record.targetKind,
|
|
405
|
+
record.targetKey,
|
|
406
|
+
JSON.stringify(record.configuredBy),
|
|
407
|
+
JSON.stringify([...new Set(record.permissionSnapshot)].sort()),
|
|
408
|
+
record.label,
|
|
409
|
+
record.inputTemplate,
|
|
410
|
+
record.cadence,
|
|
411
|
+
record.enabled ? 1 : 0,
|
|
412
|
+
record.disabledReason,
|
|
413
|
+
record.nextRunAt,
|
|
414
|
+
record.updatedAt,
|
|
415
|
+
record.tenantId,
|
|
416
|
+
record.id,
|
|
417
|
+
],
|
|
418
|
+
});
|
|
419
|
+
if (affected !== 1) throw new Error('Automation schedule not found.');
|
|
420
|
+
return (await this.getSchedule(record.tenantId, record.id))!;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
async deleteSchedule(tenantId: string, scheduleId: string): Promise<boolean> {
|
|
424
|
+
const affected = await this.#write(tenantId, {
|
|
425
|
+
text: SQL.deleteSchedule,
|
|
426
|
+
parameters: [tenantId, scheduleId],
|
|
427
|
+
});
|
|
428
|
+
return affected === 1;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
async listDueSchedules(
|
|
432
|
+
now: number,
|
|
433
|
+
limit: number,
|
|
434
|
+
): Promise<readonly AutomationScheduleRouting[]> {
|
|
435
|
+
const result = await this.handles.background.query<{
|
|
436
|
+
tenant_id: string;
|
|
437
|
+
id: string;
|
|
438
|
+
next_run_at: number | bigint | string;
|
|
439
|
+
}>({
|
|
440
|
+
text: SQL.listDueSchedules,
|
|
441
|
+
parameters: [now, limit],
|
|
442
|
+
});
|
|
443
|
+
return result.rows.map((row) => ({
|
|
444
|
+
tenantId: row.tenant_id,
|
|
445
|
+
id: row.id,
|
|
446
|
+
nextRunAt: integer(row.next_run_at),
|
|
447
|
+
}));
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
async advanceSchedule(input: {
|
|
451
|
+
readonly tenantId: string;
|
|
452
|
+
readonly scheduleId: string;
|
|
453
|
+
readonly firedSlot: number;
|
|
454
|
+
readonly nextRunAt: number;
|
|
455
|
+
readonly lastRunAt: number;
|
|
456
|
+
readonly lastRunId: string | null;
|
|
457
|
+
readonly lastError: string | null;
|
|
458
|
+
}): Promise<boolean> {
|
|
459
|
+
const affected = await this.#write(input.tenantId, {
|
|
460
|
+
text: SQL.advanceSchedule,
|
|
461
|
+
parameters: [
|
|
462
|
+
input.nextRunAt,
|
|
463
|
+
input.lastRunAt,
|
|
464
|
+
input.lastRunId,
|
|
465
|
+
input.lastError,
|
|
466
|
+
input.lastRunAt,
|
|
467
|
+
input.tenantId,
|
|
468
|
+
input.scheduleId,
|
|
469
|
+
input.firedSlot,
|
|
470
|
+
],
|
|
471
|
+
});
|
|
472
|
+
return affected === 1;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
async disableSchedule(
|
|
476
|
+
tenantId: string,
|
|
477
|
+
scheduleId: string,
|
|
478
|
+
reason: string,
|
|
479
|
+
now: number,
|
|
480
|
+
): Promise<boolean> {
|
|
481
|
+
const affected = await this.#write(tenantId, {
|
|
482
|
+
text: SQL.disableSchedule,
|
|
483
|
+
parameters: [reason, now, tenantId, scheduleId],
|
|
484
|
+
});
|
|
485
|
+
return affected === 1;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
async listTriggers(
|
|
489
|
+
tenantId: string,
|
|
490
|
+
): Promise<readonly StoredAutomationTrigger[]> {
|
|
491
|
+
const rows = await this.#read<TriggerRow>(tenantId, {
|
|
492
|
+
text: SQL.listTriggers,
|
|
493
|
+
parameters: [tenantId],
|
|
494
|
+
});
|
|
495
|
+
return rows.map(trigger);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
async getTrigger(
|
|
499
|
+
tenantId: string,
|
|
500
|
+
triggerId: string,
|
|
501
|
+
): Promise<StoredAutomationTrigger | null> {
|
|
502
|
+
const rows = await this.#read<TriggerRow>(tenantId, {
|
|
503
|
+
text: SQL.getTrigger,
|
|
504
|
+
parameters: [tenantId, triggerId],
|
|
505
|
+
});
|
|
506
|
+
return rows[0] ? trigger(rows[0]) : null;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
async findTriggerForFire(
|
|
510
|
+
triggerId: string,
|
|
511
|
+
): Promise<StoredAutomationTriggerWithSecret | null> {
|
|
512
|
+
/* A webhook arrives with an identifier and no tenant. The cross-tenant
|
|
513
|
+
lease may learn only which tenant owns the identifier; the trigger is
|
|
514
|
+
then read under that tenant, and every later write uses it too. */
|
|
515
|
+
const routing = await this.handles.background.query<{ tenant_id: string }>({
|
|
516
|
+
text: SQL.findTriggerTenant,
|
|
517
|
+
parameters: [triggerId],
|
|
518
|
+
});
|
|
519
|
+
const tenantId = routing.rows[0]?.tenant_id;
|
|
520
|
+
if (tenantId === undefined) return null;
|
|
521
|
+
const rows = await this.#read<TriggerRow>(tenantId, {
|
|
522
|
+
text: SQL.getTrigger,
|
|
523
|
+
parameters: [tenantId, triggerId],
|
|
524
|
+
});
|
|
525
|
+
const row = rows[0];
|
|
526
|
+
return row ? { ...trigger(row), secret: encrypted(row) } : null;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
async createTrigger(
|
|
530
|
+
record: AutomationTriggerRecord,
|
|
531
|
+
): Promise<StoredAutomationTrigger> {
|
|
532
|
+
await this.#write(record.tenantId, {
|
|
533
|
+
text: SQL.createTrigger,
|
|
534
|
+
parameters: [
|
|
535
|
+
record.id,
|
|
536
|
+
record.tenantId,
|
|
537
|
+
record.agentId,
|
|
538
|
+
record.targetKind,
|
|
539
|
+
record.targetKey,
|
|
540
|
+
JSON.stringify(record.configuredBy),
|
|
541
|
+
JSON.stringify([...new Set(record.permissionSnapshot)].sort()),
|
|
542
|
+
record.label,
|
|
543
|
+
record.secret.keyId,
|
|
544
|
+
record.secret.iv,
|
|
545
|
+
record.secret.tag,
|
|
546
|
+
record.secret.ciphertext,
|
|
547
|
+
record.secretRevision,
|
|
548
|
+
record.enabled ? 1 : 0,
|
|
549
|
+
record.createdAt,
|
|
550
|
+
record.updatedAt,
|
|
551
|
+
record.createdBy,
|
|
552
|
+
record.lastFiredAt,
|
|
553
|
+
record.acceptedCount,
|
|
554
|
+
record.rejectedCount,
|
|
555
|
+
],
|
|
556
|
+
});
|
|
557
|
+
return (await this.getTrigger(record.tenantId, record.id))!;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
async updateTrigger(
|
|
561
|
+
record: StoredAutomationTrigger,
|
|
562
|
+
): Promise<StoredAutomationTrigger | null> {
|
|
563
|
+
const affected = await this.#write(record.tenantId, {
|
|
564
|
+
text: SQL.updateTrigger,
|
|
565
|
+
parameters: [
|
|
566
|
+
record.agentId,
|
|
567
|
+
record.targetKind,
|
|
568
|
+
record.targetKey,
|
|
569
|
+
JSON.stringify(record.configuredBy),
|
|
570
|
+
JSON.stringify([...new Set(record.permissionSnapshot)].sort()),
|
|
571
|
+
record.label,
|
|
572
|
+
record.enabled ? 1 : 0,
|
|
573
|
+
record.updatedAt,
|
|
574
|
+
record.tenantId,
|
|
575
|
+
record.id,
|
|
576
|
+
],
|
|
577
|
+
});
|
|
578
|
+
return affected === 1 ? this.getTrigger(record.tenantId, record.id) : null;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
async rotateTriggerSecret(
|
|
582
|
+
tenantId: string,
|
|
583
|
+
triggerId: string,
|
|
584
|
+
secret: EncryptedSecret,
|
|
585
|
+
now: number,
|
|
586
|
+
): Promise<StoredAutomationTrigger | null> {
|
|
587
|
+
const affected = await this.#write(tenantId, {
|
|
588
|
+
text: SQL.rotateTriggerSecret,
|
|
589
|
+
parameters: [
|
|
590
|
+
secret.keyId,
|
|
591
|
+
secret.iv,
|
|
592
|
+
secret.tag,
|
|
593
|
+
secret.ciphertext,
|
|
594
|
+
now,
|
|
595
|
+
tenantId,
|
|
596
|
+
triggerId,
|
|
597
|
+
],
|
|
598
|
+
});
|
|
599
|
+
return affected === 1 ? this.getTrigger(tenantId, triggerId) : null;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
async deleteTrigger(tenantId: string, triggerId: string): Promise<boolean> {
|
|
603
|
+
const affected = await this.#write(tenantId, {
|
|
604
|
+
text: SQL.deleteTrigger,
|
|
605
|
+
parameters: [tenantId, triggerId],
|
|
606
|
+
});
|
|
607
|
+
return affected === 1;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
async recordTriggerOutcome(
|
|
611
|
+
tenantId: string,
|
|
612
|
+
triggerId: string,
|
|
613
|
+
accepted: boolean,
|
|
614
|
+
occurredAt: number,
|
|
615
|
+
): Promise<void> {
|
|
616
|
+
await this.#write(tenantId, {
|
|
617
|
+
text: SQL.recordTriggerOutcome,
|
|
618
|
+
parameters: [
|
|
619
|
+
occurredAt,
|
|
620
|
+
accepted ? 1 : 0,
|
|
621
|
+
accepted ? 0 : 1,
|
|
622
|
+
tenantId,
|
|
623
|
+
triggerId,
|
|
624
|
+
],
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
/* The previous hash is read and the next event written inside one
|
|
629
|
+
transaction, so two writers cannot fork the tenant chain. */
|
|
630
|
+
async appendAuditEvent(
|
|
631
|
+
event: Omit<
|
|
632
|
+
AutomationAuditEvent,
|
|
633
|
+
'id' | 'sequence' | 'previousHash' | 'eventHash'
|
|
634
|
+
>,
|
|
635
|
+
): Promise<AutomationAuditEvent> {
|
|
636
|
+
return this.handles.runtime.transaction(
|
|
637
|
+
async (transaction) => {
|
|
638
|
+
const latest = await transaction.query<{
|
|
639
|
+
sequence: number | bigint | string;
|
|
640
|
+
event_hash: string;
|
|
641
|
+
}>({
|
|
642
|
+
text: SQL.latestAudit,
|
|
643
|
+
parameters: [event.tenantId],
|
|
644
|
+
});
|
|
645
|
+
const previous = latest.rows[0];
|
|
646
|
+
const sequence = (previous ? integer(previous.sequence) : 0) + 1;
|
|
647
|
+
const previousHash = previous?.event_hash ?? null;
|
|
648
|
+
const metadataJson = stableMetadata(event.metadata);
|
|
649
|
+
const created: AutomationAuditEvent = {
|
|
650
|
+
...event,
|
|
651
|
+
id: randomUUID(),
|
|
652
|
+
sequence,
|
|
653
|
+
previousHash,
|
|
654
|
+
eventHash: auditHash({
|
|
655
|
+
tenantId: event.tenantId,
|
|
656
|
+
sequence,
|
|
657
|
+
actorId: event.actorId,
|
|
658
|
+
action: event.action,
|
|
659
|
+
subjectType: event.subjectType,
|
|
660
|
+
subjectId: event.subjectId,
|
|
661
|
+
metadataJson,
|
|
662
|
+
occurredAt: event.occurredAt,
|
|
663
|
+
previousHash,
|
|
664
|
+
}),
|
|
665
|
+
};
|
|
666
|
+
await transaction.execute({
|
|
667
|
+
text: SQL.insertAudit,
|
|
668
|
+
parameters: [
|
|
669
|
+
created.id,
|
|
670
|
+
created.tenantId,
|
|
671
|
+
created.sequence,
|
|
672
|
+
created.actorId,
|
|
673
|
+
created.action,
|
|
674
|
+
created.subjectType,
|
|
675
|
+
created.subjectId,
|
|
676
|
+
metadataJson,
|
|
677
|
+
created.occurredAt,
|
|
678
|
+
created.previousHash,
|
|
679
|
+
created.eventHash,
|
|
680
|
+
],
|
|
681
|
+
});
|
|
682
|
+
return created;
|
|
683
|
+
},
|
|
684
|
+
{ access: 'write', tenantId: event.tenantId },
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
async listAuditEvents(
|
|
689
|
+
tenantId: string,
|
|
690
|
+
limit: number,
|
|
691
|
+
): Promise<readonly AutomationAuditEvent[]> {
|
|
692
|
+
const rows = await this.#read<AuditRow>(tenantId, {
|
|
693
|
+
text: SQL.listAudit,
|
|
694
|
+
parameters: [tenantId, limit],
|
|
695
|
+
});
|
|
696
|
+
return rows.map(audit);
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
async verifyAuditChain(
|
|
700
|
+
tenantId: string,
|
|
701
|
+
): Promise<AutomationAuditVerification> {
|
|
702
|
+
const rows = await this.#read<AuditRow>(tenantId, {
|
|
703
|
+
text: SQL.auditChain,
|
|
704
|
+
parameters: [tenantId],
|
|
705
|
+
});
|
|
706
|
+
const events = rows.map(audit);
|
|
707
|
+
let previousHash: string | null = null;
|
|
708
|
+
let expectedSequence = 1;
|
|
709
|
+
for (const event of events) {
|
|
710
|
+
const expected = auditHash({
|
|
711
|
+
tenantId: event.tenantId,
|
|
712
|
+
sequence: event.sequence,
|
|
713
|
+
actorId: event.actorId,
|
|
714
|
+
action: event.action,
|
|
715
|
+
subjectType: event.subjectType,
|
|
716
|
+
subjectId: event.subjectId,
|
|
717
|
+
metadataJson: stableMetadata(event.metadata),
|
|
718
|
+
occurredAt: event.occurredAt,
|
|
719
|
+
previousHash: event.previousHash,
|
|
720
|
+
});
|
|
721
|
+
if (
|
|
722
|
+
event.sequence !== expectedSequence ||
|
|
723
|
+
event.previousHash !== previousHash ||
|
|
724
|
+
expected !== event.eventHash
|
|
725
|
+
) {
|
|
726
|
+
return { verified: false, brokenAt: event.id };
|
|
727
|
+
}
|
|
728
|
+
previousHash = event.eventHash;
|
|
729
|
+
expectedSequence += 1;
|
|
730
|
+
}
|
|
731
|
+
return { verified: true, brokenAt: null };
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
async #read<Row extends object>(
|
|
735
|
+
tenantId: string,
|
|
736
|
+
statement: { readonly text: string; readonly parameters: unknown[] },
|
|
737
|
+
): Promise<readonly Row[]> {
|
|
738
|
+
const result = await this.handles.runtime.transaction(
|
|
739
|
+
(transaction: DatabaseTransaction) =>
|
|
740
|
+
transaction.query<Row>({
|
|
741
|
+
text: statement.text,
|
|
742
|
+
parameters: statement.parameters as never,
|
|
743
|
+
}),
|
|
744
|
+
{ access: 'read', tenantId },
|
|
745
|
+
);
|
|
746
|
+
return result.rows;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
async #write(
|
|
750
|
+
tenantId: string,
|
|
751
|
+
statement: { readonly text: string; readonly parameters: unknown[] },
|
|
752
|
+
): Promise<number> {
|
|
753
|
+
const result = await this.handles.runtime.transaction(
|
|
754
|
+
(transaction: DatabaseTransaction) =>
|
|
755
|
+
transaction.execute({
|
|
756
|
+
text: statement.text,
|
|
757
|
+
parameters: statement.parameters as never,
|
|
758
|
+
}),
|
|
759
|
+
{ access: 'write', tenantId },
|
|
760
|
+
);
|
|
761
|
+
return result.affectedRows;
|
|
762
|
+
}
|
|
763
|
+
}
|