@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,1395 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import {
|
|
3
|
+
normalizeActor,
|
|
4
|
+
type Actor,
|
|
5
|
+
type PlatformCapabilityRegistry,
|
|
6
|
+
type UserActor,
|
|
7
|
+
} from '@flowdular/sdk/kernel';
|
|
8
|
+
import {
|
|
9
|
+
AGENT_ACTION_EXECUTION_CAPABILITY,
|
|
10
|
+
AGENT_RUN_EXECUTION_CAPABILITY,
|
|
11
|
+
type AgentActionExecutionCapability,
|
|
12
|
+
type AgentRevisionExecutionCapability,
|
|
13
|
+
type AgentRevisionReference,
|
|
14
|
+
} from '@flowdular/sdk/modules/agents/server';
|
|
15
|
+
import {
|
|
16
|
+
compileWorkflowGraph,
|
|
17
|
+
EMPTY_WORKFLOW_GRAPH,
|
|
18
|
+
jsonByteSize,
|
|
19
|
+
jsonHash,
|
|
20
|
+
parseWorkflowGraph,
|
|
21
|
+
validateJsonSchema,
|
|
22
|
+
type WorkflowReferenceCatalog,
|
|
23
|
+
} from '../domain/graph.ts';
|
|
24
|
+
import type {
|
|
25
|
+
CreateWorkflowDefinitionInput,
|
|
26
|
+
JsonValue,
|
|
27
|
+
WorkflowAuditVerification,
|
|
28
|
+
WorkflowCancellationResult,
|
|
29
|
+
WorkflowCapabilityContext,
|
|
30
|
+
WorkflowCostRollupV1,
|
|
31
|
+
WorkflowDefinition,
|
|
32
|
+
WorkflowDefinitionDetail,
|
|
33
|
+
WorkflowDryRunResponseV1,
|
|
34
|
+
WorkflowEnqueueRequest,
|
|
35
|
+
WorkflowExecutionCapability,
|
|
36
|
+
WorkflowExecutionOrigin,
|
|
37
|
+
WorkflowGraphV1,
|
|
38
|
+
WorkflowInvocationContext,
|
|
39
|
+
WorkflowPublishedInspection,
|
|
40
|
+
WorkflowPublishedReference,
|
|
41
|
+
WorkflowRevision,
|
|
42
|
+
WorkflowRunAccepted,
|
|
43
|
+
WorkflowRunDetail,
|
|
44
|
+
WorkflowRunEventV1,
|
|
45
|
+
WorkflowRunFilters,
|
|
46
|
+
WorkflowRunPage,
|
|
47
|
+
WorkflowRunSummary,
|
|
48
|
+
WorkflowSimulationRequest,
|
|
49
|
+
WorkflowUsageRollupV1,
|
|
50
|
+
} from '../domain/types.ts';
|
|
51
|
+
import { WORKFLOW_LIMITS } from '../domain/types.ts';
|
|
52
|
+
import { WORKFLOWS_PERMISSIONS } from '../acl/permissions.ts';
|
|
53
|
+
import type { WorkflowCursorCodec } from './cursor-codec.ts';
|
|
54
|
+
import { safePayloadEvidence } from './payload-codec.ts';
|
|
55
|
+
import type {
|
|
56
|
+
WorkflowAuditPage,
|
|
57
|
+
WorkflowRunRecord,
|
|
58
|
+
WorkflowsRepository,
|
|
59
|
+
} from './repository.ts';
|
|
60
|
+
import { simulateWorkflow } from './simulation.ts';
|
|
61
|
+
|
|
62
|
+
const KEY = /^[a-z][a-z0-9-]{2,119}$/;
|
|
63
|
+
|
|
64
|
+
function pageLimit(
|
|
65
|
+
value: number | undefined,
|
|
66
|
+
field: string,
|
|
67
|
+
maximum: number,
|
|
68
|
+
fallback: number,
|
|
69
|
+
): number {
|
|
70
|
+
if (value === undefined) return fallback;
|
|
71
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > maximum) {
|
|
72
|
+
throw new WorkflowsServiceError(
|
|
73
|
+
'WORKFLOW_LIMIT_INVALID',
|
|
74
|
+
`${field} must be an integer between 1 and ${maximum}.`,
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function parsedGraph(value: unknown): WorkflowGraphV1 {
|
|
81
|
+
try {
|
|
82
|
+
return parseWorkflowGraph(value);
|
|
83
|
+
} catch {
|
|
84
|
+
throw new WorkflowsServiceError(
|
|
85
|
+
'WORKFLOW_GRAPH_INVALID',
|
|
86
|
+
'The workflow graph must use the version 1 JSON graph contract.',
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const PROVISIONAL_USAGE: WorkflowUsageRollupV1 = {
|
|
92
|
+
version: 1,
|
|
93
|
+
state: 'provisional',
|
|
94
|
+
inputTokens: 0,
|
|
95
|
+
outputTokens: 0,
|
|
96
|
+
totalTokens: 0,
|
|
97
|
+
includedChildRunIds: [],
|
|
98
|
+
pricedChildRuns: 0,
|
|
99
|
+
unpricedChildRuns: 0,
|
|
100
|
+
actionInvocations: 0,
|
|
101
|
+
unpricedActions: 0,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const PROVISIONAL_COST: WorkflowCostRollupV1 = {
|
|
105
|
+
version: 1,
|
|
106
|
+
state: 'provisional',
|
|
107
|
+
currency: 'USD',
|
|
108
|
+
amountMicros: 0,
|
|
109
|
+
pricingSnapshotIds: [],
|
|
110
|
+
unpricedChildRuns: 0,
|
|
111
|
+
unpricedActions: 0,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export class WorkflowsServiceError extends Error {
|
|
115
|
+
constructor(
|
|
116
|
+
readonly code: string,
|
|
117
|
+
message: string,
|
|
118
|
+
readonly status = 400,
|
|
119
|
+
readonly details?: JsonValue,
|
|
120
|
+
) {
|
|
121
|
+
super(message);
|
|
122
|
+
this.name = 'WorkflowsServiceError';
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface WorkflowsServiceOptions {
|
|
127
|
+
readonly capabilities: PlatformCapabilityRegistry;
|
|
128
|
+
readonly cursorCodec: WorkflowCursorCodec;
|
|
129
|
+
readonly now?: () => number;
|
|
130
|
+
readonly onRunQueued?: () => void;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Both agents.core capabilities a live path needs, resolved together. */
|
|
134
|
+
interface WorkflowExecutionCapabilities {
|
|
135
|
+
readonly agents: AgentRevisionExecutionCapability;
|
|
136
|
+
readonly actions: AgentActionExecutionCapability;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function bounded(
|
|
140
|
+
value: string,
|
|
141
|
+
field: string,
|
|
142
|
+
min: number,
|
|
143
|
+
max: number,
|
|
144
|
+
): string {
|
|
145
|
+
const normalized = value.trim();
|
|
146
|
+
if (normalized.length < min || normalized.length > max) {
|
|
147
|
+
throw new WorkflowsServiceError(
|
|
148
|
+
'WORKFLOW_INPUT_INVALID',
|
|
149
|
+
`${field} must contain between ${min} and ${max} characters.`,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
return normalized;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function trustedActor(actor: Actor): Actor {
|
|
156
|
+
const normalized = normalizeActor(actor);
|
|
157
|
+
if (!normalized) {
|
|
158
|
+
throw new WorkflowsServiceError(
|
|
159
|
+
'WORKFLOW_ACTOR_INVALID',
|
|
160
|
+
'The workflow actor is invalid.',
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
return normalized;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function trustedAuthorizationSubject(
|
|
167
|
+
actor: Actor,
|
|
168
|
+
subject?: UserActor,
|
|
169
|
+
): UserActor {
|
|
170
|
+
const trusted = trustedActor(actor);
|
|
171
|
+
const derived =
|
|
172
|
+
trusted.kind === 'user'
|
|
173
|
+
? trusted
|
|
174
|
+
: trusted.kind === 'service'
|
|
175
|
+
? trusted.configuredBy
|
|
176
|
+
: undefined;
|
|
177
|
+
const normalized = subject ? normalizeActor(subject) : derived;
|
|
178
|
+
if (!normalized || normalized.kind !== 'user') {
|
|
179
|
+
throw new WorkflowsServiceError(
|
|
180
|
+
'WORKFLOW_AUTHORIZATION_SUBJECT_REQUIRED',
|
|
181
|
+
'Agent-authored workflow runs require an explicit delegated user.',
|
|
182
|
+
403,
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
if (derived && normalized.id !== derived.id) {
|
|
186
|
+
throw new WorkflowsServiceError(
|
|
187
|
+
'WORKFLOW_AUTHORIZATION_SUBJECT_INVALID',
|
|
188
|
+
'The delegated user does not match the workflow actor authority.',
|
|
189
|
+
403,
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
return normalized;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function requirePermission(
|
|
196
|
+
permissions: readonly string[],
|
|
197
|
+
permission: string,
|
|
198
|
+
): void {
|
|
199
|
+
if (!permissions.includes(permission)) {
|
|
200
|
+
throw new WorkflowsServiceError(
|
|
201
|
+
'WORKFLOW_PERMISSION_DENIED',
|
|
202
|
+
'The workflow permission is required.',
|
|
203
|
+
403,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function digest(values: readonly string[]): string {
|
|
209
|
+
return `sha256:${createHash('sha256')
|
|
210
|
+
.update(JSON.stringify([...new Set(values)].sort()))
|
|
211
|
+
.digest('hex')}`;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function manualContext(
|
|
215
|
+
tenantId: string,
|
|
216
|
+
actor: Actor,
|
|
217
|
+
permissionSnapshot: readonly string[],
|
|
218
|
+
): WorkflowInvocationContext {
|
|
219
|
+
return {
|
|
220
|
+
tenantId,
|
|
221
|
+
actor: trustedActor(actor),
|
|
222
|
+
authorizationSubject: trustedAuthorizationSubject(actor),
|
|
223
|
+
origin: { kind: 'manual' },
|
|
224
|
+
permissionSnapshot: [...new Set(permissionSnapshot)].sort(),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function validateInputSize(input: JsonValue): void {
|
|
229
|
+
if (jsonByteSize(input) > WORKFLOW_LIMITS.maxInputBytes) {
|
|
230
|
+
throw new WorkflowsServiceError(
|
|
231
|
+
'WORKFLOW_LIMIT_EXCEEDED',
|
|
232
|
+
'Workflow input exceeds 64 KB.',
|
|
233
|
+
413,
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export class WorkflowsService {
|
|
239
|
+
readonly #now: () => number;
|
|
240
|
+
|
|
241
|
+
constructor(
|
|
242
|
+
private readonly repository: WorkflowsRepository,
|
|
243
|
+
private readonly options: WorkflowsServiceOptions,
|
|
244
|
+
) {
|
|
245
|
+
this.#now = options.now ?? Date.now;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
#agents(): AgentRevisionExecutionCapability | null {
|
|
249
|
+
return this.options.capabilities.get<AgentRevisionExecutionCapability>(
|
|
250
|
+
AGENT_RUN_EXECUTION_CAPABILITY,
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
#actions(): AgentActionExecutionCapability | null {
|
|
255
|
+
return this.options.capabilities.get<AgentActionExecutionCapability>(
|
|
256
|
+
AGENT_ACTION_EXECUTION_CAPABILITY,
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/* Presence is separate from resolution: an absent capability is a 503 the
|
|
261
|
+
caller reports before it reads a graph or a revision. */
|
|
262
|
+
#executionCapabilities(): WorkflowExecutionCapabilities | null {
|
|
263
|
+
const agents = this.#agents();
|
|
264
|
+
const actions = this.#actions();
|
|
265
|
+
return agents && actions ? { agents, actions } : null;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/* The graph compiler is synchronous and pure, so every reference the graph
|
|
269
|
+
names is resolved once here, before the compiler walks it. */
|
|
270
|
+
async #referenceCatalog(
|
|
271
|
+
capabilities: WorkflowExecutionCapabilities,
|
|
272
|
+
graph: WorkflowGraphV1,
|
|
273
|
+
context: WorkflowCapabilityContext,
|
|
274
|
+
): Promise<WorkflowReferenceCatalog> {
|
|
275
|
+
const { agents, actions } = capabilities;
|
|
276
|
+
const actionDescriptors = await actions.listWorkflowActions();
|
|
277
|
+
const revisions = new Map<string, AgentRevisionReference | null>();
|
|
278
|
+
for (const node of graph.nodes) {
|
|
279
|
+
if (node.type !== 'agent' && node.type !== 'agent-decision') continue;
|
|
280
|
+
/* validate() accepts an unparsed graph, so a node may pin nothing. An
|
|
281
|
+
unresolved pin reads as unavailable, which is what the compiler
|
|
282
|
+
already reports for a reference no catalog can find. */
|
|
283
|
+
const pinned: { agentId?: unknown; revision?: unknown } | undefined =
|
|
284
|
+
node.agent;
|
|
285
|
+
if (
|
|
286
|
+
typeof pinned?.agentId !== 'string' ||
|
|
287
|
+
typeof pinned.revision !== 'number'
|
|
288
|
+
) {
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
const key = `${pinned.agentId}:${pinned.revision}`;
|
|
292
|
+
if (revisions.has(key)) continue;
|
|
293
|
+
revisions.set(
|
|
294
|
+
key,
|
|
295
|
+
await agents.getRevision(pinned.agentId, pinned.revision, {
|
|
296
|
+
tenantId: context.tenantId,
|
|
297
|
+
workflowRunId: 'workflow-preflight',
|
|
298
|
+
actor: context.actor,
|
|
299
|
+
authorizationSubject: trustedAuthorizationSubject(
|
|
300
|
+
context.actor,
|
|
301
|
+
context.authorizationSubject,
|
|
302
|
+
),
|
|
303
|
+
permissionSnapshot: context.permissionSnapshot,
|
|
304
|
+
}),
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
return {
|
|
308
|
+
agent: (agentId, revision) => {
|
|
309
|
+
const reference = revisions.get(`${agentId}:${revision}`);
|
|
310
|
+
return {
|
|
311
|
+
available: reference?.status === 'active',
|
|
312
|
+
allowedTools: reference?.allowedTools ?? [],
|
|
313
|
+
};
|
|
314
|
+
},
|
|
315
|
+
action: (actionId, contractVersion) => {
|
|
316
|
+
const action = actionDescriptors.find(
|
|
317
|
+
(entry) =>
|
|
318
|
+
entry.id === actionId && entry.contractVersion === contractVersion,
|
|
319
|
+
);
|
|
320
|
+
return action
|
|
321
|
+
? {
|
|
322
|
+
available: true,
|
|
323
|
+
requiredPermissions: action.requiredPermissions,
|
|
324
|
+
risk: action.risk,
|
|
325
|
+
idempotency: action.idempotency,
|
|
326
|
+
}
|
|
327
|
+
: { available: false, requiredPermissions: [] };
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
async list(tenantId: string): Promise<readonly WorkflowDefinition[]> {
|
|
333
|
+
return await this.repository.listDefinitions(
|
|
334
|
+
bounded(tenantId, 'tenantId', 1, 128),
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
async detail(
|
|
339
|
+
tenantId: string,
|
|
340
|
+
workflowId: string,
|
|
341
|
+
): Promise<WorkflowDefinitionDetail> {
|
|
342
|
+
const detail = await this.repository.definitionDetail(
|
|
343
|
+
bounded(tenantId, 'tenantId', 1, 128),
|
|
344
|
+
bounded(workflowId, 'workflowId', 1, 128),
|
|
345
|
+
);
|
|
346
|
+
if (!detail) {
|
|
347
|
+
throw new WorkflowsServiceError(
|
|
348
|
+
'WORKFLOW_NOT_FOUND',
|
|
349
|
+
'The workflow was not found.',
|
|
350
|
+
404,
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
return detail;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
async create(
|
|
357
|
+
tenantId: string,
|
|
358
|
+
input: CreateWorkflowDefinitionInput,
|
|
359
|
+
actor: Actor,
|
|
360
|
+
): Promise<WorkflowDefinitionDetail> {
|
|
361
|
+
const now = this.#now();
|
|
362
|
+
const key = bounded(input.key, 'key', 3, 120);
|
|
363
|
+
if (!KEY.test(key)) {
|
|
364
|
+
throw new WorkflowsServiceError(
|
|
365
|
+
'WORKFLOW_INPUT_INVALID',
|
|
366
|
+
'Workflow key must be a lowercase slug.',
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
const definition: WorkflowDefinition = {
|
|
370
|
+
id: randomUUID(),
|
|
371
|
+
tenantId: bounded(tenantId, 'tenantId', 1, 128),
|
|
372
|
+
key,
|
|
373
|
+
name: bounded(input.name, 'name', 2, 160),
|
|
374
|
+
description: bounded(input.description, 'description', 0, 2_000),
|
|
375
|
+
status: 'active',
|
|
376
|
+
currentDraftRevision: 1,
|
|
377
|
+
publishedRevision: null,
|
|
378
|
+
createdAt: now,
|
|
379
|
+
updatedAt: now,
|
|
380
|
+
};
|
|
381
|
+
const report = compileWorkflowGraph(EMPTY_WORKFLOW_GRAPH);
|
|
382
|
+
const revision: WorkflowRevision = {
|
|
383
|
+
id: randomUUID(),
|
|
384
|
+
workflowId: definition.id,
|
|
385
|
+
revision: 1,
|
|
386
|
+
graph: EMPTY_WORKFLOW_GRAPH,
|
|
387
|
+
graphChecksum: report.graphChecksum,
|
|
388
|
+
compilerVersion: 1,
|
|
389
|
+
compiledOrder: report.compiledOrder,
|
|
390
|
+
publishedAt: null,
|
|
391
|
+
publishedBy: null,
|
|
392
|
+
};
|
|
393
|
+
try {
|
|
394
|
+
return await this.repository.createDefinition({
|
|
395
|
+
definition,
|
|
396
|
+
revision,
|
|
397
|
+
actor: trustedActor(actor),
|
|
398
|
+
origin: { kind: 'manual' },
|
|
399
|
+
});
|
|
400
|
+
} catch (error) {
|
|
401
|
+
if (String(error).includes('workflow_definitions.tenant_id')) {
|
|
402
|
+
throw new WorkflowsServiceError(
|
|
403
|
+
'WORKFLOW_KEY_CONFLICT',
|
|
404
|
+
'A workflow with this key already exists.',
|
|
405
|
+
409,
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
throw error;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
async update(
|
|
413
|
+
tenantId: string,
|
|
414
|
+
input: {
|
|
415
|
+
readonly workflowId: string;
|
|
416
|
+
readonly expectedRevision: number;
|
|
417
|
+
readonly name: string;
|
|
418
|
+
readonly description: string;
|
|
419
|
+
readonly graph: unknown;
|
|
420
|
+
},
|
|
421
|
+
actor: Actor,
|
|
422
|
+
): Promise<WorkflowDefinitionDetail> {
|
|
423
|
+
const current = await this.detail(tenantId, input.workflowId);
|
|
424
|
+
if (current.definition.status === 'archived') {
|
|
425
|
+
throw new WorkflowsServiceError(
|
|
426
|
+
'WORKFLOW_ARCHIVED',
|
|
427
|
+
'Archived workflows cannot be edited.',
|
|
428
|
+
409,
|
|
429
|
+
);
|
|
430
|
+
}
|
|
431
|
+
const graph = parsedGraph(input.graph);
|
|
432
|
+
const report = compileWorkflowGraph(graph);
|
|
433
|
+
if (
|
|
434
|
+
input.expectedRevision !== current.definition.currentDraftRevision ||
|
|
435
|
+
!Number.isSafeInteger(input.expectedRevision)
|
|
436
|
+
) {
|
|
437
|
+
throw new WorkflowsServiceError(
|
|
438
|
+
'WORKFLOW_REVISION_CONFLICT',
|
|
439
|
+
'The workflow draft changed before this save.',
|
|
440
|
+
409,
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
const now = this.#now();
|
|
444
|
+
const nextRevision = input.expectedRevision + 1;
|
|
445
|
+
const definition: WorkflowDefinition = {
|
|
446
|
+
...current.definition,
|
|
447
|
+
name: bounded(input.name, 'name', 2, 160),
|
|
448
|
+
description: bounded(input.description, 'description', 0, 2_000),
|
|
449
|
+
currentDraftRevision: nextRevision,
|
|
450
|
+
updatedAt: now,
|
|
451
|
+
};
|
|
452
|
+
const revision: WorkflowRevision = {
|
|
453
|
+
id: randomUUID(),
|
|
454
|
+
workflowId: definition.id,
|
|
455
|
+
revision: nextRevision,
|
|
456
|
+
graph,
|
|
457
|
+
graphChecksum: report.graphChecksum,
|
|
458
|
+
compilerVersion: 1,
|
|
459
|
+
compiledOrder: report.compiledOrder,
|
|
460
|
+
publishedAt: null,
|
|
461
|
+
publishedBy: null,
|
|
462
|
+
};
|
|
463
|
+
const saved = await this.repository.saveDraft({
|
|
464
|
+
definition,
|
|
465
|
+
revision,
|
|
466
|
+
expectedRevision: input.expectedRevision,
|
|
467
|
+
actor: trustedActor(actor),
|
|
468
|
+
origin: { kind: 'manual' },
|
|
469
|
+
});
|
|
470
|
+
if (saved === 'conflict') {
|
|
471
|
+
throw new WorkflowsServiceError(
|
|
472
|
+
'WORKFLOW_REVISION_CONFLICT',
|
|
473
|
+
'The workflow draft changed before this save.',
|
|
474
|
+
409,
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
return saved;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
async validate(
|
|
481
|
+
graph: unknown,
|
|
482
|
+
context: WorkflowInvocationContext,
|
|
483
|
+
): Promise<WorkflowDryRunResponseV1> {
|
|
484
|
+
const parsed = parsedGraph(graph);
|
|
485
|
+
const capabilities = this.#executionCapabilities();
|
|
486
|
+
return compileWorkflowGraph(
|
|
487
|
+
parsed,
|
|
488
|
+
capabilities
|
|
489
|
+
? await this.#referenceCatalog(capabilities, parsed, context)
|
|
490
|
+
: undefined,
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
async publish(
|
|
495
|
+
tenantId: string,
|
|
496
|
+
workflowId: string,
|
|
497
|
+
expectedRevision: number,
|
|
498
|
+
actor: Actor,
|
|
499
|
+
permissionSnapshot: readonly string[],
|
|
500
|
+
): Promise<WorkflowDefinitionDetail> {
|
|
501
|
+
const context = manualContext(tenantId, actor, permissionSnapshot);
|
|
502
|
+
const capabilities = this.#executionCapabilities();
|
|
503
|
+
if (!capabilities) {
|
|
504
|
+
throw new WorkflowsServiceError(
|
|
505
|
+
'WORKFLOW_LIVE_CAPABILITIES_UNAVAILABLE',
|
|
506
|
+
'Agent revision and action execution capabilities are required before publication.',
|
|
507
|
+
503,
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
const detail = await this.detail(tenantId, workflowId);
|
|
511
|
+
if (detail.definition.currentDraftRevision !== expectedRevision) {
|
|
512
|
+
throw new WorkflowsServiceError(
|
|
513
|
+
'WORKFLOW_REVISION_CONFLICT',
|
|
514
|
+
'The workflow draft changed before publication.',
|
|
515
|
+
409,
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
const report = compileWorkflowGraph(
|
|
519
|
+
detail.draft.graph,
|
|
520
|
+
await this.#referenceCatalog(capabilities, detail.draft.graph, context),
|
|
521
|
+
);
|
|
522
|
+
if (!report.valid) {
|
|
523
|
+
throw new WorkflowsServiceError(
|
|
524
|
+
'WORKFLOW_GRAPH_INVALID',
|
|
525
|
+
'The workflow graph cannot be published.',
|
|
526
|
+
400,
|
|
527
|
+
report.issues as unknown as JsonValue,
|
|
528
|
+
);
|
|
529
|
+
}
|
|
530
|
+
for (const permission of report.requiredPermissions) {
|
|
531
|
+
requirePermission(permissionSnapshot, permission);
|
|
532
|
+
}
|
|
533
|
+
const published = await this.repository.publish(
|
|
534
|
+
tenantId,
|
|
535
|
+
workflowId,
|
|
536
|
+
expectedRevision,
|
|
537
|
+
trustedActor(actor),
|
|
538
|
+
{ kind: 'manual' },
|
|
539
|
+
this.#now(),
|
|
540
|
+
);
|
|
541
|
+
if (published === 'conflict') {
|
|
542
|
+
throw new WorkflowsServiceError(
|
|
543
|
+
'WORKFLOW_REVISION_CONFLICT',
|
|
544
|
+
'The workflow draft changed before publication.',
|
|
545
|
+
409,
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
if (!published) {
|
|
549
|
+
throw new WorkflowsServiceError(
|
|
550
|
+
'WORKFLOW_NOT_FOUND',
|
|
551
|
+
'The workflow was not found.',
|
|
552
|
+
404,
|
|
553
|
+
);
|
|
554
|
+
}
|
|
555
|
+
return published;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
async archive(
|
|
559
|
+
tenantId: string,
|
|
560
|
+
workflowId: string,
|
|
561
|
+
actor: Actor,
|
|
562
|
+
): Promise<WorkflowDefinition> {
|
|
563
|
+
const definition = await this.repository.archive(
|
|
564
|
+
bounded(tenantId, 'tenantId', 1, 128),
|
|
565
|
+
bounded(workflowId, 'workflowId', 1, 128),
|
|
566
|
+
trustedActor(actor),
|
|
567
|
+
{ kind: 'manual' },
|
|
568
|
+
this.#now(),
|
|
569
|
+
);
|
|
570
|
+
if (!definition) {
|
|
571
|
+
throw new WorkflowsServiceError(
|
|
572
|
+
'WORKFLOW_NOT_FOUND',
|
|
573
|
+
'The workflow was not found.',
|
|
574
|
+
404,
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
return definition;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
async delete(
|
|
581
|
+
tenantId: string,
|
|
582
|
+
workflowId: string,
|
|
583
|
+
actor: Actor,
|
|
584
|
+
): Promise<void> {
|
|
585
|
+
const result = await this.repository.deleteDraft(
|
|
586
|
+
bounded(tenantId, 'tenantId', 1, 128),
|
|
587
|
+
bounded(workflowId, 'workflowId', 1, 128),
|
|
588
|
+
trustedActor(actor),
|
|
589
|
+
{ kind: 'manual' },
|
|
590
|
+
this.#now(),
|
|
591
|
+
);
|
|
592
|
+
if (result === 'not-found') {
|
|
593
|
+
throw new WorkflowsServiceError(
|
|
594
|
+
'WORKFLOW_NOT_FOUND',
|
|
595
|
+
'The workflow was not found.',
|
|
596
|
+
404,
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
if (result === 'in-use') {
|
|
600
|
+
throw new WorkflowsServiceError(
|
|
601
|
+
'WORKFLOW_DELETE_INELIGIBLE',
|
|
602
|
+
'Only an unpublished workflow without run history can be deleted.',
|
|
603
|
+
409,
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
async listAgentCatalog(
|
|
609
|
+
context: WorkflowInvocationContext,
|
|
610
|
+
): Promise<readonly unknown[]> {
|
|
611
|
+
const agents = this.#agents();
|
|
612
|
+
if (!agents) return [];
|
|
613
|
+
return (
|
|
614
|
+
await agents.listRevisions({
|
|
615
|
+
tenantId: context.tenantId,
|
|
616
|
+
workflowRunId: 'workflow-catalog',
|
|
617
|
+
actor: context.actor,
|
|
618
|
+
authorizationSubject: trustedAuthorizationSubject(
|
|
619
|
+
context.actor,
|
|
620
|
+
context.authorizationSubject,
|
|
621
|
+
),
|
|
622
|
+
permissionSnapshot: context.permissionSnapshot,
|
|
623
|
+
})
|
|
624
|
+
).map((agent) => ({
|
|
625
|
+
agentId: agent.agentId,
|
|
626
|
+
revision: agent.revision,
|
|
627
|
+
name: agent.name,
|
|
628
|
+
description: '',
|
|
629
|
+
status: agent.status,
|
|
630
|
+
supportsStructuredOutput: agent.supportsStructuredOutput,
|
|
631
|
+
allowedTools: agent.allowedTools,
|
|
632
|
+
}));
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
async listActionCatalog(
|
|
636
|
+
context: WorkflowInvocationContext,
|
|
637
|
+
): Promise<readonly unknown[]> {
|
|
638
|
+
const actions = this.#actions();
|
|
639
|
+
if (!actions) return [];
|
|
640
|
+
return (await actions.listWorkflowActions())
|
|
641
|
+
.filter(
|
|
642
|
+
(action) =>
|
|
643
|
+
(action.risk === 'read' || action.risk === 'workspace-write') &&
|
|
644
|
+
action.requiredPermissions.every((permission) =>
|
|
645
|
+
context.permissionSnapshot.includes(permission),
|
|
646
|
+
),
|
|
647
|
+
)
|
|
648
|
+
.map((action) => ({
|
|
649
|
+
actionId: action.id,
|
|
650
|
+
label: action.id,
|
|
651
|
+
description: action.description,
|
|
652
|
+
contractVersion: action.contractVersion,
|
|
653
|
+
risk: action.risk,
|
|
654
|
+
requiredPermissions: action.requiredPermissions,
|
|
655
|
+
inputSchema: action.inputSchema,
|
|
656
|
+
outputSchema: action.outputSchema,
|
|
657
|
+
}));
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
async #publishedDefinition(
|
|
661
|
+
tenantId: string,
|
|
662
|
+
workflowKey: string,
|
|
663
|
+
): Promise<{
|
|
664
|
+
readonly definition: WorkflowDefinition;
|
|
665
|
+
readonly revision: WorkflowRevision;
|
|
666
|
+
}> {
|
|
667
|
+
const definition = await this.repository.findDefinitionByKey(
|
|
668
|
+
tenantId,
|
|
669
|
+
workflowKey,
|
|
670
|
+
);
|
|
671
|
+
if (!definition) {
|
|
672
|
+
throw new WorkflowsServiceError(
|
|
673
|
+
'WORKFLOW_NOT_FOUND',
|
|
674
|
+
'The workflow was not found.',
|
|
675
|
+
404,
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
if (definition.status === 'archived') {
|
|
679
|
+
throw new WorkflowsServiceError(
|
|
680
|
+
'WORKFLOW_ARCHIVED',
|
|
681
|
+
'Archived workflows cannot start new runs.',
|
|
682
|
+
409,
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
if (definition.publishedRevision === null) {
|
|
686
|
+
throw new WorkflowsServiceError(
|
|
687
|
+
'WORKFLOW_NOT_PUBLISHED',
|
|
688
|
+
'The workflow has no published revision.',
|
|
689
|
+
409,
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
const revision = await this.repository.findRevision(
|
|
693
|
+
tenantId,
|
|
694
|
+
definition.id,
|
|
695
|
+
definition.publishedRevision,
|
|
696
|
+
);
|
|
697
|
+
if (!revision || revision.publishedAt === null) {
|
|
698
|
+
throw new WorkflowsServiceError(
|
|
699
|
+
'WORKFLOW_RECOVERY_INCONSISTENT',
|
|
700
|
+
'The published workflow revision is missing.',
|
|
701
|
+
500,
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
return { definition, revision };
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
async enqueue(
|
|
708
|
+
request: WorkflowEnqueueRequest,
|
|
709
|
+
context: WorkflowInvocationContext,
|
|
710
|
+
): Promise<WorkflowRunAccepted> {
|
|
711
|
+
const trustedContext: WorkflowInvocationContext = {
|
|
712
|
+
tenantId: bounded(context.tenantId, 'tenantId', 1, 128),
|
|
713
|
+
actor: trustedActor(context.actor),
|
|
714
|
+
authorizationSubject: trustedAuthorizationSubject(
|
|
715
|
+
context.actor,
|
|
716
|
+
context.authorizationSubject,
|
|
717
|
+
),
|
|
718
|
+
origin: context.origin,
|
|
719
|
+
permissionSnapshot: [...new Set(context.permissionSnapshot)].sort(),
|
|
720
|
+
};
|
|
721
|
+
requirePermission(
|
|
722
|
+
trustedContext.permissionSnapshot,
|
|
723
|
+
WORKFLOWS_PERMISSIONS.runsExecute,
|
|
724
|
+
);
|
|
725
|
+
const workflowKey = bounded(request.workflowKey, 'workflowKey', 3, 120);
|
|
726
|
+
const idempotencyKey = bounded(
|
|
727
|
+
request.idempotencyKey,
|
|
728
|
+
'idempotencyKey',
|
|
729
|
+
8,
|
|
730
|
+
200,
|
|
731
|
+
);
|
|
732
|
+
validateInputSize(request.input);
|
|
733
|
+
const { definition, revision } = await this.#publishedDefinition(
|
|
734
|
+
trustedContext.tenantId,
|
|
735
|
+
workflowKey,
|
|
736
|
+
);
|
|
737
|
+
const capabilities = this.#executionCapabilities();
|
|
738
|
+
if (!capabilities) {
|
|
739
|
+
throw new WorkflowsServiceError(
|
|
740
|
+
'WORKFLOW_LIVE_CAPABILITIES_UNAVAILABLE',
|
|
741
|
+
'Agent revision and action execution capabilities are unavailable.',
|
|
742
|
+
503,
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
const report = compileWorkflowGraph(
|
|
746
|
+
revision.graph,
|
|
747
|
+
await this.#referenceCatalog(
|
|
748
|
+
capabilities,
|
|
749
|
+
revision.graph,
|
|
750
|
+
trustedContext,
|
|
751
|
+
),
|
|
752
|
+
);
|
|
753
|
+
if (!report.valid) {
|
|
754
|
+
throw new WorkflowsServiceError(
|
|
755
|
+
'WORKFLOW_GRAPH_INVALID',
|
|
756
|
+
'The published workflow no longer passes live preflight.',
|
|
757
|
+
409,
|
|
758
|
+
report.issues as unknown as JsonValue,
|
|
759
|
+
);
|
|
760
|
+
}
|
|
761
|
+
for (const permission of report.requiredPermissions) {
|
|
762
|
+
requirePermission(trustedContext.permissionSnapshot, permission);
|
|
763
|
+
}
|
|
764
|
+
const inputNode = revision.graph.nodes.find(
|
|
765
|
+
(node) => node.type === 'input',
|
|
766
|
+
);
|
|
767
|
+
const inputSchemaId = inputNode?.outputPorts[0]?.schemaId;
|
|
768
|
+
if (
|
|
769
|
+
!inputSchemaId ||
|
|
770
|
+
validateJsonSchema(
|
|
771
|
+
request.input,
|
|
772
|
+
revision.graph.schemas[inputSchemaId] ?? {},
|
|
773
|
+
).length > 0
|
|
774
|
+
) {
|
|
775
|
+
throw new WorkflowsServiceError(
|
|
776
|
+
'WORKFLOW_INPUT_INVALID',
|
|
777
|
+
'Workflow input does not match the published input schema.',
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
const inputHash = jsonHash(request.input);
|
|
781
|
+
const existing = await this.repository.findRunByIdempotency(
|
|
782
|
+
trustedContext.tenantId,
|
|
783
|
+
idempotencyKey,
|
|
784
|
+
);
|
|
785
|
+
if (existing) {
|
|
786
|
+
if (
|
|
787
|
+
existing.workflowId !== definition.id ||
|
|
788
|
+
existing.inputHash !== inputHash
|
|
789
|
+
) {
|
|
790
|
+
throw new WorkflowsServiceError(
|
|
791
|
+
'WORKFLOW_IDEMPOTENCY_CONFLICT',
|
|
792
|
+
'The idempotency key belongs to another workflow invocation.',
|
|
793
|
+
409,
|
|
794
|
+
);
|
|
795
|
+
}
|
|
796
|
+
return {
|
|
797
|
+
runId: existing.id,
|
|
798
|
+
workflowId: existing.workflowId,
|
|
799
|
+
workflowRevision: existing.workflowRevision!,
|
|
800
|
+
status: 'queued',
|
|
801
|
+
created: false,
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
const now = this.#now();
|
|
805
|
+
const runId = randomUUID();
|
|
806
|
+
const run: WorkflowRunRecord = {
|
|
807
|
+
id: runId,
|
|
808
|
+
tenantId: trustedContext.tenantId,
|
|
809
|
+
workflowId: definition.id,
|
|
810
|
+
workflowKey: definition.key,
|
|
811
|
+
workflowName: definition.name,
|
|
812
|
+
workflowRevision: revision.revision,
|
|
813
|
+
graphChecksum: revision.graphChecksum,
|
|
814
|
+
graph: revision.graph,
|
|
815
|
+
compiledOrder: revision.compiledOrder,
|
|
816
|
+
mode: 'live',
|
|
817
|
+
status: 'queued',
|
|
818
|
+
actor: trustedContext.actor,
|
|
819
|
+
authorizationSubject: trustedContext.authorizationSubject!,
|
|
820
|
+
origin: trustedContext.origin,
|
|
821
|
+
permissionSnapshot: trustedContext.permissionSnapshot,
|
|
822
|
+
permissionDigest: digest(trustedContext.permissionSnapshot),
|
|
823
|
+
inputHash,
|
|
824
|
+
inputPayloadId: '',
|
|
825
|
+
idempotencyKey,
|
|
826
|
+
leaseOwner: null,
|
|
827
|
+
leaseExpiresAt: null,
|
|
828
|
+
cancellationRequestedAt: null,
|
|
829
|
+
queuedAt: now,
|
|
830
|
+
startedAt: null,
|
|
831
|
+
completedAt: null,
|
|
832
|
+
durationMs: null,
|
|
833
|
+
completedNodes: 0,
|
|
834
|
+
totalNodes: revision.graph.nodes.length,
|
|
835
|
+
failureCode: null,
|
|
836
|
+
usage: PROVISIONAL_USAGE,
|
|
837
|
+
cost: PROVISIONAL_COST,
|
|
838
|
+
};
|
|
839
|
+
await this.repository.createRun({
|
|
840
|
+
run,
|
|
841
|
+
input: request.input,
|
|
842
|
+
inputEvidence: safePayloadEvidence(request.input, inputSchemaId, {
|
|
843
|
+
schema: revision.graph.schemas[inputSchemaId] ?? {},
|
|
844
|
+
permissionSnapshot: trustedContext.permissionSnapshot,
|
|
845
|
+
}),
|
|
846
|
+
});
|
|
847
|
+
this.options.onRunQueued?.();
|
|
848
|
+
return {
|
|
849
|
+
runId,
|
|
850
|
+
workflowId: definition.id,
|
|
851
|
+
workflowRevision: revision.revision,
|
|
852
|
+
status: 'queued',
|
|
853
|
+
created: true,
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
async simulate(
|
|
858
|
+
request: WorkflowSimulationRequest,
|
|
859
|
+
context: WorkflowInvocationContext,
|
|
860
|
+
): Promise<WorkflowRunDetail> {
|
|
861
|
+
requirePermission(
|
|
862
|
+
context.permissionSnapshot,
|
|
863
|
+
WORKFLOWS_PERMISSIONS.runsExecute,
|
|
864
|
+
);
|
|
865
|
+
validateInputSize(request.input);
|
|
866
|
+
if (request.fixtures.length > WORKFLOW_LIMITS.maxNodes) {
|
|
867
|
+
throw new WorkflowsServiceError(
|
|
868
|
+
'WORKFLOW_LIMIT_EXCEEDED',
|
|
869
|
+
'Simulation fixtures exceed the graph node limit.',
|
|
870
|
+
413,
|
|
871
|
+
);
|
|
872
|
+
}
|
|
873
|
+
const detail = await this.detail(context.tenantId, request.workflowId);
|
|
874
|
+
const fixtureIds = new Set(
|
|
875
|
+
request.fixtures.map((fixture) => fixture.nodeId),
|
|
876
|
+
);
|
|
877
|
+
if (fixtureIds.size !== request.fixtures.length) {
|
|
878
|
+
throw new WorkflowsServiceError(
|
|
879
|
+
'WORKFLOW_INPUT_INVALID',
|
|
880
|
+
'Simulation fixtures must have unique node ids.',
|
|
881
|
+
);
|
|
882
|
+
}
|
|
883
|
+
const report = compileWorkflowGraph(detail.draft.graph, {
|
|
884
|
+
agent: () => true,
|
|
885
|
+
action: () => ({
|
|
886
|
+
available: true,
|
|
887
|
+
requiredPermissions: [],
|
|
888
|
+
risk: 'read',
|
|
889
|
+
idempotency: 'required',
|
|
890
|
+
}),
|
|
891
|
+
});
|
|
892
|
+
if (!report.valid) {
|
|
893
|
+
throw new WorkflowsServiceError(
|
|
894
|
+
'WORKFLOW_GRAPH_INVALID',
|
|
895
|
+
'The draft graph cannot be simulated.',
|
|
896
|
+
400,
|
|
897
|
+
report.issues as unknown as JsonValue,
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
const inputNode = detail.draft.graph.nodes.find(
|
|
901
|
+
(node) => node.type === 'input',
|
|
902
|
+
);
|
|
903
|
+
const inputSchemaId = inputNode?.outputPorts[0]?.schemaId;
|
|
904
|
+
const inputSchema = inputSchemaId
|
|
905
|
+
? detail.draft.graph.schemas[inputSchemaId]
|
|
906
|
+
: undefined;
|
|
907
|
+
if (
|
|
908
|
+
!inputSchemaId ||
|
|
909
|
+
validateJsonSchema(request.input, inputSchema ?? {}).length > 0
|
|
910
|
+
) {
|
|
911
|
+
throw new WorkflowsServiceError(
|
|
912
|
+
'WORKFLOW_INPUT_INVALID',
|
|
913
|
+
'Simulation input does not match the workflow input schema.',
|
|
914
|
+
);
|
|
915
|
+
}
|
|
916
|
+
const now = this.#now();
|
|
917
|
+
const runId = randomUUID();
|
|
918
|
+
const run = await this.repository.createRun({
|
|
919
|
+
run: {
|
|
920
|
+
id: runId,
|
|
921
|
+
tenantId: context.tenantId,
|
|
922
|
+
workflowId: detail.definition.id,
|
|
923
|
+
workflowKey: detail.definition.key,
|
|
924
|
+
workflowName: detail.definition.name,
|
|
925
|
+
workflowRevision: detail.draft.revision,
|
|
926
|
+
graphChecksum: detail.draft.graphChecksum,
|
|
927
|
+
graph: detail.draft.graph,
|
|
928
|
+
compiledOrder: report.compiledOrder,
|
|
929
|
+
mode: 'simulate',
|
|
930
|
+
status: 'queued',
|
|
931
|
+
actor: trustedActor(context.actor),
|
|
932
|
+
authorizationSubject: trustedAuthorizationSubject(
|
|
933
|
+
context.actor,
|
|
934
|
+
context.authorizationSubject,
|
|
935
|
+
),
|
|
936
|
+
origin: context.origin,
|
|
937
|
+
permissionSnapshot: [...new Set(context.permissionSnapshot)].sort(),
|
|
938
|
+
permissionDigest: digest(context.permissionSnapshot),
|
|
939
|
+
inputHash: jsonHash(request.input),
|
|
940
|
+
inputPayloadId: '',
|
|
941
|
+
idempotencyKey: null,
|
|
942
|
+
leaseOwner: null,
|
|
943
|
+
leaseExpiresAt: null,
|
|
944
|
+
cancellationRequestedAt: null,
|
|
945
|
+
queuedAt: now,
|
|
946
|
+
startedAt: null,
|
|
947
|
+
completedAt: null,
|
|
948
|
+
durationMs: null,
|
|
949
|
+
completedNodes: 0,
|
|
950
|
+
totalNodes: detail.draft.graph.nodes.length,
|
|
951
|
+
failureCode: null,
|
|
952
|
+
usage: { ...PROVISIONAL_USAGE, state: 'not-applicable' },
|
|
953
|
+
cost: { ...PROVISIONAL_COST, state: 'not-applicable' },
|
|
954
|
+
},
|
|
955
|
+
input: request.input,
|
|
956
|
+
inputEvidence: safePayloadEvidence(request.input, inputSchemaId, {
|
|
957
|
+
...(inputSchema ? { schema: inputSchema } : {}),
|
|
958
|
+
permissionSnapshot: context.permissionSnapshot,
|
|
959
|
+
}),
|
|
960
|
+
});
|
|
961
|
+
return simulateWorkflow(
|
|
962
|
+
this.repository,
|
|
963
|
+
run,
|
|
964
|
+
request.input,
|
|
965
|
+
request.fixtures,
|
|
966
|
+
);
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
async listRuns(
|
|
970
|
+
tenantId: string,
|
|
971
|
+
filters: WorkflowRunFilters,
|
|
972
|
+
): Promise<WorkflowRunPage> {
|
|
973
|
+
const normalizedTenant = bounded(tenantId, 'tenantId', 1, 128);
|
|
974
|
+
const limit = pageLimit(
|
|
975
|
+
filters.limit,
|
|
976
|
+
'limit',
|
|
977
|
+
WORKFLOW_LIMITS.maxInteractivePage,
|
|
978
|
+
50,
|
|
979
|
+
);
|
|
980
|
+
const normalized = { ...filters, limit, cursor: null };
|
|
981
|
+
const filterDigest = jsonHash(normalized as unknown as JsonValue);
|
|
982
|
+
let rawCursor: string | null = null;
|
|
983
|
+
if (filters.cursor) {
|
|
984
|
+
try {
|
|
985
|
+
const decoded = this.options.cursorCodec.decode<{
|
|
986
|
+
readonly tenantId: string;
|
|
987
|
+
readonly filterDigest: string;
|
|
988
|
+
readonly raw: string;
|
|
989
|
+
}>('wfrc1', filters.cursor);
|
|
990
|
+
if (
|
|
991
|
+
decoded.tenantId !== normalizedTenant ||
|
|
992
|
+
decoded.filterDigest !== filterDigest
|
|
993
|
+
) {
|
|
994
|
+
throw new WorkflowsServiceError(
|
|
995
|
+
'WORKFLOW_CURSOR_MISMATCH',
|
|
996
|
+
'The run cursor belongs to another tenant or filter.',
|
|
997
|
+
409,
|
|
998
|
+
);
|
|
999
|
+
}
|
|
1000
|
+
rawCursor = decoded.raw;
|
|
1001
|
+
} catch (error) {
|
|
1002
|
+
if (error instanceof WorkflowsServiceError) throw error;
|
|
1003
|
+
throw new WorkflowsServiceError(
|
|
1004
|
+
'WORKFLOW_CURSOR_INVALID',
|
|
1005
|
+
'The run cursor is invalid.',
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
const page = await this.repository.listRuns(normalizedTenant, {
|
|
1010
|
+
...filters,
|
|
1011
|
+
limit,
|
|
1012
|
+
cursor: rawCursor,
|
|
1013
|
+
});
|
|
1014
|
+
return {
|
|
1015
|
+
runs: page.runs,
|
|
1016
|
+
nextCursor: page.nextCursor
|
|
1017
|
+
? this.options.cursorCodec.encode('wfrc1', {
|
|
1018
|
+
tenantId: normalizedTenant,
|
|
1019
|
+
filterDigest,
|
|
1020
|
+
raw: page.nextCursor,
|
|
1021
|
+
})
|
|
1022
|
+
: null,
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
async getRun(
|
|
1027
|
+
tenantId: string,
|
|
1028
|
+
runId: string,
|
|
1029
|
+
): Promise<WorkflowRunSummary | null> {
|
|
1030
|
+
return await this.repository.getRun(
|
|
1031
|
+
bounded(tenantId, 'tenantId', 1, 128),
|
|
1032
|
+
bounded(runId, 'runId', 1, 128),
|
|
1033
|
+
);
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
async getRunDetail(
|
|
1037
|
+
tenantId: string,
|
|
1038
|
+
runId: string,
|
|
1039
|
+
): Promise<WorkflowRunDetail> {
|
|
1040
|
+
const detail = await this.repository.runDetail(
|
|
1041
|
+
bounded(tenantId, 'tenantId', 1, 128),
|
|
1042
|
+
bounded(runId, 'runId', 1, 128),
|
|
1043
|
+
);
|
|
1044
|
+
if (!detail) {
|
|
1045
|
+
throw new WorkflowsServiceError(
|
|
1046
|
+
'WORKFLOW_RUN_NOT_FOUND',
|
|
1047
|
+
'The workflow run was not found.',
|
|
1048
|
+
404,
|
|
1049
|
+
);
|
|
1050
|
+
}
|
|
1051
|
+
return detail;
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
async readEvents(
|
|
1055
|
+
tenantId: string,
|
|
1056
|
+
runId: string,
|
|
1057
|
+
afterSequence: number,
|
|
1058
|
+
limit: number = WORKFLOW_LIMITS.maxReplayEvents,
|
|
1059
|
+
): Promise<readonly WorkflowRunEventV1[]> {
|
|
1060
|
+
if (!Number.isSafeInteger(afterSequence) || afterSequence < 0) {
|
|
1061
|
+
throw new WorkflowsServiceError(
|
|
1062
|
+
'WORKFLOW_EVENT_CURSOR_INVALID',
|
|
1063
|
+
'The event sequence is invalid.',
|
|
1064
|
+
);
|
|
1065
|
+
}
|
|
1066
|
+
const replayLimit = pageLimit(
|
|
1067
|
+
limit,
|
|
1068
|
+
'limit',
|
|
1069
|
+
WORKFLOW_LIMITS.maxReplayEvents,
|
|
1070
|
+
WORKFLOW_LIMITS.maxReplayEvents,
|
|
1071
|
+
);
|
|
1072
|
+
const detail = await this.getRunDetail(tenantId, runId);
|
|
1073
|
+
const latestSequence = detail.events.at(-1)?.sequence ?? 0;
|
|
1074
|
+
if (afterSequence > latestSequence) {
|
|
1075
|
+
throw new WorkflowsServiceError(
|
|
1076
|
+
'WORKFLOW_EVENT_CURSOR_AHEAD',
|
|
1077
|
+
'The event cursor is ahead of the persisted stream.',
|
|
1078
|
+
409,
|
|
1079
|
+
);
|
|
1080
|
+
}
|
|
1081
|
+
return await this.repository.readEvents(
|
|
1082
|
+
tenantId,
|
|
1083
|
+
runId,
|
|
1084
|
+
afterSequence,
|
|
1085
|
+
replayLimit,
|
|
1086
|
+
);
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
eventCursor(tenantId: string, runId: string, sequence: number): string {
|
|
1090
|
+
if (!Number.isSafeInteger(sequence) || sequence < 0) {
|
|
1091
|
+
throw new WorkflowsServiceError(
|
|
1092
|
+
'WORKFLOW_EVENT_CURSOR_INVALID',
|
|
1093
|
+
'The event sequence is invalid.',
|
|
1094
|
+
);
|
|
1095
|
+
}
|
|
1096
|
+
return this.options.cursorCodec.encode('wfre1', {
|
|
1097
|
+
tenantId: bounded(tenantId, 'tenantId', 1, 128),
|
|
1098
|
+
runId: bounded(runId, 'runId', 1, 128),
|
|
1099
|
+
sequence,
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
eventSequence(tenantId: string, runId: string, cursor: string): number {
|
|
1104
|
+
try {
|
|
1105
|
+
const decoded = this.options.cursorCodec.decode<{
|
|
1106
|
+
readonly tenantId: string;
|
|
1107
|
+
readonly runId: string;
|
|
1108
|
+
readonly sequence: number;
|
|
1109
|
+
}>('wfre1', cursor);
|
|
1110
|
+
if (
|
|
1111
|
+
decoded.tenantId !== bounded(tenantId, 'tenantId', 1, 128) ||
|
|
1112
|
+
decoded.runId !== bounded(runId, 'runId', 1, 128) ||
|
|
1113
|
+
!Number.isSafeInteger(decoded.sequence) ||
|
|
1114
|
+
decoded.sequence < 0
|
|
1115
|
+
) {
|
|
1116
|
+
throw new Error('cursor-binding');
|
|
1117
|
+
}
|
|
1118
|
+
return decoded.sequence;
|
|
1119
|
+
} catch {
|
|
1120
|
+
throw new WorkflowsServiceError(
|
|
1121
|
+
'WORKFLOW_EVENT_CURSOR_INVALID',
|
|
1122
|
+
'The event cursor is invalid for this workflow run.',
|
|
1123
|
+
409,
|
|
1124
|
+
);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
async cancel(
|
|
1129
|
+
tenantId: string,
|
|
1130
|
+
runId: string,
|
|
1131
|
+
actor: Actor,
|
|
1132
|
+
): Promise<WorkflowCancellationResult> {
|
|
1133
|
+
const result = await this.repository.requestCancellation(
|
|
1134
|
+
bounded(tenantId, 'tenantId', 1, 128),
|
|
1135
|
+
bounded(runId, 'runId', 1, 128),
|
|
1136
|
+
trustedActor(actor),
|
|
1137
|
+
{ kind: 'manual' },
|
|
1138
|
+
this.#now(),
|
|
1139
|
+
);
|
|
1140
|
+
if (!result) {
|
|
1141
|
+
throw new WorkflowsServiceError(
|
|
1142
|
+
'WORKFLOW_RUN_NOT_FOUND',
|
|
1143
|
+
'The workflow run was not found.',
|
|
1144
|
+
404,
|
|
1145
|
+
);
|
|
1146
|
+
}
|
|
1147
|
+
this.options.onRunQueued?.();
|
|
1148
|
+
return {
|
|
1149
|
+
runId: result.run.id,
|
|
1150
|
+
status: result.run.status,
|
|
1151
|
+
requested: result.requested,
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
async retry(
|
|
1156
|
+
tenantId: string,
|
|
1157
|
+
runId: string,
|
|
1158
|
+
actor: Actor,
|
|
1159
|
+
permissionSnapshot: readonly string[],
|
|
1160
|
+
): Promise<WorkflowRunAccepted> {
|
|
1161
|
+
requirePermission(permissionSnapshot, WORKFLOWS_PERMISSIONS.runsExecute);
|
|
1162
|
+
const prior = await this.repository.getRun(
|
|
1163
|
+
bounded(tenantId, 'tenantId', 1, 128),
|
|
1164
|
+
bounded(runId, 'runId', 1, 128),
|
|
1165
|
+
);
|
|
1166
|
+
if (!prior) {
|
|
1167
|
+
throw new WorkflowsServiceError(
|
|
1168
|
+
'WORKFLOW_RUN_NOT_FOUND',
|
|
1169
|
+
'The workflow run was not found.',
|
|
1170
|
+
404,
|
|
1171
|
+
);
|
|
1172
|
+
}
|
|
1173
|
+
if (
|
|
1174
|
+
prior.mode !== 'live' ||
|
|
1175
|
+
!['failed', 'refused', 'cancelled'].includes(prior.status)
|
|
1176
|
+
) {
|
|
1177
|
+
throw new WorkflowsServiceError(
|
|
1178
|
+
'WORKFLOW_RUN_TERMINAL',
|
|
1179
|
+
'Only a terminal failed, refused, or cancelled live run can be retried.',
|
|
1180
|
+
409,
|
|
1181
|
+
);
|
|
1182
|
+
}
|
|
1183
|
+
const context = manualContext(tenantId, actor, permissionSnapshot);
|
|
1184
|
+
const capabilities = this.#executionCapabilities();
|
|
1185
|
+
if (!capabilities) {
|
|
1186
|
+
throw new WorkflowsServiceError(
|
|
1187
|
+
'WORKFLOW_LIVE_CAPABILITIES_UNAVAILABLE',
|
|
1188
|
+
'Agent and action execution capabilities are unavailable.',
|
|
1189
|
+
503,
|
|
1190
|
+
);
|
|
1191
|
+
}
|
|
1192
|
+
const report = compileWorkflowGraph(
|
|
1193
|
+
prior.graph,
|
|
1194
|
+
await this.#referenceCatalog(capabilities, prior.graph, context),
|
|
1195
|
+
);
|
|
1196
|
+
if (!report.valid) {
|
|
1197
|
+
throw new WorkflowsServiceError(
|
|
1198
|
+
'WORKFLOW_GRAPH_INVALID',
|
|
1199
|
+
'The pinned workflow revision no longer passes live preflight.',
|
|
1200
|
+
409,
|
|
1201
|
+
report.issues as unknown as JsonValue,
|
|
1202
|
+
);
|
|
1203
|
+
}
|
|
1204
|
+
for (const permission of report.requiredPermissions)
|
|
1205
|
+
requirePermission(permissionSnapshot, permission);
|
|
1206
|
+
const input = await this.repository.readExecutionPayload(
|
|
1207
|
+
tenantId,
|
|
1208
|
+
prior.id,
|
|
1209
|
+
prior.inputPayloadId,
|
|
1210
|
+
);
|
|
1211
|
+
const now = this.#now();
|
|
1212
|
+
const nextId = randomUUID();
|
|
1213
|
+
const inputNode = prior.graph.nodes.find((node) => node.type === 'input');
|
|
1214
|
+
const schemaId = inputNode?.outputPorts[0]?.schemaId ?? 'workflow.input';
|
|
1215
|
+
const created = await this.repository.createRun({
|
|
1216
|
+
run: {
|
|
1217
|
+
...prior,
|
|
1218
|
+
id: nextId,
|
|
1219
|
+
actor: context.actor,
|
|
1220
|
+
origin: context.origin,
|
|
1221
|
+
permissionSnapshot: context.permissionSnapshot,
|
|
1222
|
+
permissionDigest: digest(context.permissionSnapshot),
|
|
1223
|
+
status: 'queued',
|
|
1224
|
+
inputPayloadId: '',
|
|
1225
|
+
idempotencyKey: `retry:${prior.id}:${nextId}`,
|
|
1226
|
+
leaseOwner: null,
|
|
1227
|
+
leaseExpiresAt: null,
|
|
1228
|
+
cancellationRequestedAt: null,
|
|
1229
|
+
queuedAt: now,
|
|
1230
|
+
startedAt: null,
|
|
1231
|
+
completedAt: null,
|
|
1232
|
+
durationMs: null,
|
|
1233
|
+
completedNodes: 0,
|
|
1234
|
+
failureCode: null,
|
|
1235
|
+
usage: PROVISIONAL_USAGE,
|
|
1236
|
+
cost: PROVISIONAL_COST,
|
|
1237
|
+
},
|
|
1238
|
+
input,
|
|
1239
|
+
inputEvidence: safePayloadEvidence(input, schemaId, {
|
|
1240
|
+
schema: prior.graph.schemas[schemaId] ?? {},
|
|
1241
|
+
permissionSnapshot,
|
|
1242
|
+
}),
|
|
1243
|
+
});
|
|
1244
|
+
this.options.onRunQueued?.();
|
|
1245
|
+
return {
|
|
1246
|
+
runId: created.id,
|
|
1247
|
+
workflowId: created.workflowId,
|
|
1248
|
+
workflowRevision: created.workflowRevision!,
|
|
1249
|
+
status: 'queued',
|
|
1250
|
+
created: true,
|
|
1251
|
+
};
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
async listAudit(
|
|
1255
|
+
tenantId: string,
|
|
1256
|
+
limit: number,
|
|
1257
|
+
cursor?: string | null,
|
|
1258
|
+
): Promise<WorkflowAuditPage> {
|
|
1259
|
+
const normalizedTenant = bounded(tenantId, 'tenantId', 1, 128);
|
|
1260
|
+
const pageSize = pageLimit(
|
|
1261
|
+
limit,
|
|
1262
|
+
'limit',
|
|
1263
|
+
WORKFLOW_LIMITS.maxInteractivePage,
|
|
1264
|
+
50,
|
|
1265
|
+
);
|
|
1266
|
+
let beforeSequence: number | undefined;
|
|
1267
|
+
if (cursor) {
|
|
1268
|
+
try {
|
|
1269
|
+
const decoded = this.options.cursorCodec.decode<{
|
|
1270
|
+
readonly tenantId: string;
|
|
1271
|
+
readonly beforeSequence: number;
|
|
1272
|
+
}>('wfac1', cursor);
|
|
1273
|
+
if (decoded.tenantId !== normalizedTenant) {
|
|
1274
|
+
throw new WorkflowsServiceError(
|
|
1275
|
+
'WORKFLOW_CURSOR_MISMATCH',
|
|
1276
|
+
'The audit cursor belongs to another tenant.',
|
|
1277
|
+
409,
|
|
1278
|
+
);
|
|
1279
|
+
}
|
|
1280
|
+
beforeSequence = decoded.beforeSequence;
|
|
1281
|
+
} catch (error) {
|
|
1282
|
+
if (error instanceof WorkflowsServiceError) throw error;
|
|
1283
|
+
throw new WorkflowsServiceError(
|
|
1284
|
+
'WORKFLOW_CURSOR_INVALID',
|
|
1285
|
+
'The audit cursor is invalid.',
|
|
1286
|
+
);
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
const page = await this.repository.listAudit(
|
|
1290
|
+
normalizedTenant,
|
|
1291
|
+
pageSize,
|
|
1292
|
+
beforeSequence,
|
|
1293
|
+
);
|
|
1294
|
+
return {
|
|
1295
|
+
events: page.events,
|
|
1296
|
+
nextCursor: page.nextCursor
|
|
1297
|
+
? this.options.cursorCodec.encode('wfac1', {
|
|
1298
|
+
tenantId: normalizedTenant,
|
|
1299
|
+
beforeSequence: Number(page.nextCursor),
|
|
1300
|
+
})
|
|
1301
|
+
: null,
|
|
1302
|
+
};
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
async verifyAudit(tenantId: string): Promise<WorkflowAuditVerification> {
|
|
1306
|
+
return await this.repository.verifyAudit(
|
|
1307
|
+
bounded(tenantId, 'tenantId', 1, 128),
|
|
1308
|
+
);
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
executionDependencies(): {
|
|
1312
|
+
readonly agents: AgentRevisionExecutionCapability;
|
|
1313
|
+
readonly actions: AgentActionExecutionCapability;
|
|
1314
|
+
} | null {
|
|
1315
|
+
const agents = this.#agents();
|
|
1316
|
+
const actions = this.#actions();
|
|
1317
|
+
return agents && actions ? { agents, actions } : null;
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
async executionCapability(): Promise<WorkflowExecutionCapability> {
|
|
1321
|
+
return {
|
|
1322
|
+
listPublished: async (context) => {
|
|
1323
|
+
requirePermission(
|
|
1324
|
+
context.permissionSnapshot,
|
|
1325
|
+
WORKFLOWS_PERMISSIONS.read,
|
|
1326
|
+
);
|
|
1327
|
+
return await this.repository.listPublished(context.tenantId);
|
|
1328
|
+
},
|
|
1329
|
+
getPublishedReference: async (workflowKey, context) => {
|
|
1330
|
+
requirePermission(
|
|
1331
|
+
context.permissionSnapshot,
|
|
1332
|
+
WORKFLOWS_PERMISSIONS.read,
|
|
1333
|
+
);
|
|
1334
|
+
const reference = (
|
|
1335
|
+
await this.repository.listPublished(context.tenantId)
|
|
1336
|
+
).find(
|
|
1337
|
+
(candidate) =>
|
|
1338
|
+
candidate.key === bounded(workflowKey, 'workflowKey', 3, 120),
|
|
1339
|
+
);
|
|
1340
|
+
if (!reference) return null;
|
|
1341
|
+
const revision = await this.repository.findRevision(
|
|
1342
|
+
context.tenantId,
|
|
1343
|
+
reference.id,
|
|
1344
|
+
reference.revision,
|
|
1345
|
+
);
|
|
1346
|
+
if (!revision || revision.publishedAt === null) {
|
|
1347
|
+
throw new WorkflowsServiceError(
|
|
1348
|
+
'WORKFLOW_RECOVERY_INCONSISTENT',
|
|
1349
|
+
'The published workflow revision is missing.',
|
|
1350
|
+
500,
|
|
1351
|
+
);
|
|
1352
|
+
}
|
|
1353
|
+
const capabilities = this.#executionCapabilities();
|
|
1354
|
+
if (!capabilities) {
|
|
1355
|
+
throw new WorkflowsServiceError(
|
|
1356
|
+
'WORKFLOW_LIVE_CAPABILITIES_UNAVAILABLE',
|
|
1357
|
+
'Agent revision and action execution capabilities are required to inspect a workflow.',
|
|
1358
|
+
503,
|
|
1359
|
+
);
|
|
1360
|
+
}
|
|
1361
|
+
const report = compileWorkflowGraph(
|
|
1362
|
+
revision.graph,
|
|
1363
|
+
await this.#referenceCatalog(capabilities, revision.graph, context),
|
|
1364
|
+
);
|
|
1365
|
+
if (!report.valid) {
|
|
1366
|
+
throw new WorkflowsServiceError(
|
|
1367
|
+
'WORKFLOW_PUBLISHED_REFERENCE_UNAVAILABLE',
|
|
1368
|
+
'The published workflow references are no longer available.',
|
|
1369
|
+
409,
|
|
1370
|
+
report.issues as unknown as JsonValue,
|
|
1371
|
+
);
|
|
1372
|
+
}
|
|
1373
|
+
return {
|
|
1374
|
+
...reference,
|
|
1375
|
+
requiredPermissions: report.requiredPermissions,
|
|
1376
|
+
} satisfies WorkflowPublishedInspection;
|
|
1377
|
+
},
|
|
1378
|
+
enqueue: (request, context) => this.enqueue(request, context),
|
|
1379
|
+
getRun: async (runId, context) => {
|
|
1380
|
+
requirePermission(
|
|
1381
|
+
context.permissionSnapshot,
|
|
1382
|
+
WORKFLOWS_PERMISSIONS.runsRead,
|
|
1383
|
+
);
|
|
1384
|
+
return await this.getRun(context.tenantId, runId);
|
|
1385
|
+
},
|
|
1386
|
+
cancel: async (runId, context) => {
|
|
1387
|
+
requirePermission(
|
|
1388
|
+
context.permissionSnapshot,
|
|
1389
|
+
WORKFLOWS_PERMISSIONS.runsCancel,
|
|
1390
|
+
);
|
|
1391
|
+
return await this.cancel(context.tenantId, runId, context.actor);
|
|
1392
|
+
},
|
|
1393
|
+
};
|
|
1394
|
+
}
|
|
1395
|
+
}
|