@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,811 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import {
|
|
3
|
+
AgentHarnessError,
|
|
4
|
+
boundToolOutput,
|
|
5
|
+
toolTimeoutMs,
|
|
6
|
+
validateJsonValue,
|
|
7
|
+
validateToolInput,
|
|
8
|
+
validateToolOutput,
|
|
9
|
+
type AgentTool,
|
|
10
|
+
type AgentToolAccessAuthorizer,
|
|
11
|
+
type JsonValue,
|
|
12
|
+
} from '@flowdular/sdk/harness';
|
|
13
|
+
import {
|
|
14
|
+
actorsEqual,
|
|
15
|
+
normalizeActor,
|
|
16
|
+
type Actor,
|
|
17
|
+
type UserActor,
|
|
18
|
+
} from '@flowdular/sdk/kernel';
|
|
19
|
+
import type { AgentActionInvocation } from '../domain/types.ts';
|
|
20
|
+
import {
|
|
21
|
+
DuplicateActionIdempotencyKeyError,
|
|
22
|
+
type AgentRepository,
|
|
23
|
+
} from '../services/repository.ts';
|
|
24
|
+
|
|
25
|
+
export const AGENT_ACTION_EXECUTION_CAPABILITY = 'agents.actions.v1';
|
|
26
|
+
|
|
27
|
+
export interface VersionedActionDescriptor {
|
|
28
|
+
readonly id: string;
|
|
29
|
+
readonly contractVersion: number;
|
|
30
|
+
readonly description: string;
|
|
31
|
+
readonly requiredPermissions: readonly string[];
|
|
32
|
+
readonly inputSchema: Readonly<Record<string, unknown>>;
|
|
33
|
+
readonly outputSchema: Readonly<Record<string, unknown>>;
|
|
34
|
+
readonly timeoutMs: number;
|
|
35
|
+
readonly idempotency: 'required';
|
|
36
|
+
readonly risk: 'read' | 'workspace-write';
|
|
37
|
+
readonly cancellation: 'cooperative' | 'not-supported';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ActionCancellationResult {
|
|
41
|
+
readonly actionInvocationId: string;
|
|
42
|
+
readonly state: 'acknowledged' | 'not-acknowledged' | 'not-supported';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ActionInvocationAccepted {
|
|
46
|
+
readonly actionInvocationId: string;
|
|
47
|
+
readonly created: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface ActionExecutionResult {
|
|
51
|
+
readonly actionInvocationId: string;
|
|
52
|
+
readonly status: 'succeeded' | 'failed' | 'refused' | 'cancelled';
|
|
53
|
+
readonly output?: JsonValue;
|
|
54
|
+
readonly code?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface AgentActionChildContext {
|
|
58
|
+
readonly tenantId: string;
|
|
59
|
+
readonly workflowRunId: string;
|
|
60
|
+
readonly actor: Actor;
|
|
61
|
+
readonly authorizationSubject?: UserActor;
|
|
62
|
+
readonly permissionSnapshot: readonly string[];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface AgentActionStartContext extends AgentActionChildContext {
|
|
66
|
+
readonly nodeRunId: string;
|
|
67
|
+
readonly signal: AbortSignal;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface AgentActionExecutionCapability {
|
|
71
|
+
listWorkflowActions(): Promise<readonly VersionedActionDescriptor[]>;
|
|
72
|
+
start(
|
|
73
|
+
request: {
|
|
74
|
+
readonly actionId: string;
|
|
75
|
+
readonly contractVersion: number;
|
|
76
|
+
readonly input: JsonValue;
|
|
77
|
+
readonly idempotencyKey: string;
|
|
78
|
+
},
|
|
79
|
+
context: AgentActionStartContext,
|
|
80
|
+
): Promise<ActionInvocationAccepted>;
|
|
81
|
+
getResult(
|
|
82
|
+
actionInvocationId: string,
|
|
83
|
+
context: AgentActionChildContext,
|
|
84
|
+
): Promise<ActionExecutionResult | null>;
|
|
85
|
+
requestCancel(
|
|
86
|
+
actionInvocationId: string,
|
|
87
|
+
context: AgentActionChildContext,
|
|
88
|
+
): Promise<ActionCancellationResult>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export class AgentActionCapabilityError extends Error {
|
|
92
|
+
constructor(
|
|
93
|
+
readonly code: string,
|
|
94
|
+
message: string,
|
|
95
|
+
) {
|
|
96
|
+
super(message);
|
|
97
|
+
this.name = 'AgentActionCapabilityError';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export interface AgentActionRuntime {
|
|
102
|
+
readonly capability: AgentActionExecutionCapability;
|
|
103
|
+
start(): void;
|
|
104
|
+
stop(): void;
|
|
105
|
+
dispose(): Promise<void>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function bounded(
|
|
109
|
+
value: string,
|
|
110
|
+
field: string,
|
|
111
|
+
minimum: number,
|
|
112
|
+
maximum: number,
|
|
113
|
+
) {
|
|
114
|
+
const normalized = value.trim();
|
|
115
|
+
if (normalized.length < minimum || normalized.length > maximum) {
|
|
116
|
+
throw new AgentActionCapabilityError(
|
|
117
|
+
'ACTION_INVALID_INPUT',
|
|
118
|
+
`${field} must contain between ${minimum} and ${maximum} characters.`,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
return normalized;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function canonical(value: JsonValue): string {
|
|
125
|
+
if (value === null || typeof value !== 'object') return JSON.stringify(value);
|
|
126
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;
|
|
127
|
+
return `{${Object.entries(value)
|
|
128
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
129
|
+
.map(([key, child]) => `${JSON.stringify(key)}:${canonical(child)}`)
|
|
130
|
+
.join(',')}}`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function workflowSchema(
|
|
134
|
+
value: Readonly<Record<string, unknown>> | undefined,
|
|
135
|
+
): Readonly<Record<string, unknown>> | null {
|
|
136
|
+
if (!value || Array.isArray(value) || typeof value !== 'object') return null;
|
|
137
|
+
try {
|
|
138
|
+
validateJsonValue(value, 'ACTION_SCHEMA_INVALID', 'Action schema');
|
|
139
|
+
const serialized = JSON.stringify(value);
|
|
140
|
+
if (serialized.length > 32_768) return null;
|
|
141
|
+
return JSON.parse(serialized) as Record<string, unknown>;
|
|
142
|
+
} catch {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function descriptor(tool: AgentTool): VersionedActionDescriptor | null {
|
|
148
|
+
const inputSchema = workflowSchema(tool.inputSchema);
|
|
149
|
+
const outputSchema = workflowSchema(tool.outputSchema);
|
|
150
|
+
if (
|
|
151
|
+
!Number.isSafeInteger(tool.contractVersion) ||
|
|
152
|
+
(tool.contractVersion ?? 0) < 1 ||
|
|
153
|
+
!inputSchema ||
|
|
154
|
+
!outputSchema ||
|
|
155
|
+
(tool.risk !== 'read' && tool.risk !== 'workspace-write') ||
|
|
156
|
+
tool.idempotency !== 'required' ||
|
|
157
|
+
(tool.risk === 'workspace-write' &&
|
|
158
|
+
tool.idempotencyProtection !== 'target-ledger') ||
|
|
159
|
+
(tool.cancellation !== 'cooperative' &&
|
|
160
|
+
tool.cancellation !== 'not-supported')
|
|
161
|
+
) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
id: tool.id,
|
|
166
|
+
contractVersion: tool.contractVersion!,
|
|
167
|
+
description: tool.description,
|
|
168
|
+
requiredPermissions: [...tool.requiredPermissions],
|
|
169
|
+
inputSchema,
|
|
170
|
+
outputSchema,
|
|
171
|
+
timeoutMs: toolTimeoutMs(tool.timeoutMs),
|
|
172
|
+
idempotency: 'required',
|
|
173
|
+
risk: tool.risk,
|
|
174
|
+
cancellation: tool.cancellation,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function safeCode(error: unknown): string {
|
|
179
|
+
if (
|
|
180
|
+
error instanceof AgentHarnessError ||
|
|
181
|
+
error instanceof AgentActionCapabilityError
|
|
182
|
+
) {
|
|
183
|
+
return error.code;
|
|
184
|
+
}
|
|
185
|
+
return 'ACTION_EXECUTION_FAILED';
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function trustedAuthorizationSubject(
|
|
189
|
+
actor: Actor,
|
|
190
|
+
subject?: UserActor,
|
|
191
|
+
): UserActor {
|
|
192
|
+
const supplied = subject ? normalizeActor(subject) : undefined;
|
|
193
|
+
const derived =
|
|
194
|
+
actor.kind === 'user'
|
|
195
|
+
? actor
|
|
196
|
+
: actor.kind === 'service'
|
|
197
|
+
? actor.configuredBy
|
|
198
|
+
: undefined;
|
|
199
|
+
const trusted = supplied ?? derived;
|
|
200
|
+
if (
|
|
201
|
+
!trusted ||
|
|
202
|
+
trusted.kind !== 'user' ||
|
|
203
|
+
(derived !== undefined && trusted.id !== derived.id)
|
|
204
|
+
) {
|
|
205
|
+
throw new AgentActionCapabilityError(
|
|
206
|
+
'ACTION_INVALID_DELEGATION',
|
|
207
|
+
'The workflow action requires a trusted delegated user.',
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
return trusted;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export function createAgentActionExecutionRuntime(
|
|
214
|
+
repository: AgentRepository,
|
|
215
|
+
tools: readonly AgentTool[],
|
|
216
|
+
options: {
|
|
217
|
+
readonly workerId?: string;
|
|
218
|
+
readonly leaseMs?: number;
|
|
219
|
+
readonly now?: () => number;
|
|
220
|
+
readonly authorizeToolAccess?: AgentToolAccessAuthorizer;
|
|
221
|
+
} = {},
|
|
222
|
+
): AgentActionRuntime {
|
|
223
|
+
const now = options.now ?? Date.now;
|
|
224
|
+
const leaseMs = options.leaseMs ?? 30_000;
|
|
225
|
+
if (!Number.isSafeInteger(leaseMs) || leaseMs < 1_000 || leaseMs > 300_000) {
|
|
226
|
+
throw new Error('Agent action lease must be between 1000 and 300000 ms.');
|
|
227
|
+
}
|
|
228
|
+
const workerId =
|
|
229
|
+
options.workerId ?? `agent-action-worker:${process.pid}:${randomUUID()}`;
|
|
230
|
+
const toolById = new Map(tools.map((tool) => [tool.id, tool]));
|
|
231
|
+
const actions = tools
|
|
232
|
+
.map(descriptor)
|
|
233
|
+
.filter((item): item is VersionedActionDescriptor => item !== null)
|
|
234
|
+
.sort((left, right) => left.id.localeCompare(right.id));
|
|
235
|
+
const actionById = new Map(actions.map((action) => [action.id, action]));
|
|
236
|
+
const inFlight = new Map<string, AbortController>();
|
|
237
|
+
const callerSignals = new Map<
|
|
238
|
+
string,
|
|
239
|
+
{ readonly signal: AbortSignal; readonly listener: () => void }
|
|
240
|
+
>();
|
|
241
|
+
const idleWaiters = new Set<() => void>();
|
|
242
|
+
let poll: ReturnType<typeof setInterval> | undefined;
|
|
243
|
+
let kickTimer: ReturnType<typeof setTimeout> | undefined;
|
|
244
|
+
let stopped = true;
|
|
245
|
+
let scheduled = false;
|
|
246
|
+
|
|
247
|
+
const detachCallerSignal = (id: string) => {
|
|
248
|
+
const caller = callerSignals.get(id);
|
|
249
|
+
if (!caller) return;
|
|
250
|
+
caller.signal.removeEventListener('abort', caller.listener);
|
|
251
|
+
callerSignals.delete(id);
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const finish = (id: string) => {
|
|
255
|
+
inFlight.delete(id);
|
|
256
|
+
detachCallerSignal(id);
|
|
257
|
+
if (inFlight.size === 0) {
|
|
258
|
+
for (const resolve of idleWaiters) resolve();
|
|
259
|
+
idleWaiters.clear();
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const execute = async (
|
|
264
|
+
invocation: AgentActionInvocation,
|
|
265
|
+
controller: AbortController,
|
|
266
|
+
) => {
|
|
267
|
+
const action = actionById.get(invocation.actionId);
|
|
268
|
+
const tool = toolById.get(invocation.actionId);
|
|
269
|
+
if (
|
|
270
|
+
!action ||
|
|
271
|
+
!tool ||
|
|
272
|
+
action.contractVersion !== invocation.contractVersion
|
|
273
|
+
) {
|
|
274
|
+
const completedAt = now();
|
|
275
|
+
await repository.failAction(
|
|
276
|
+
invocation.tenantId,
|
|
277
|
+
invocation.id,
|
|
278
|
+
workerId,
|
|
279
|
+
'ACTION_VERSION_MISSING',
|
|
280
|
+
completedAt,
|
|
281
|
+
{
|
|
282
|
+
tenantId: invocation.tenantId,
|
|
283
|
+
actorId: invocation.actor.id,
|
|
284
|
+
action: 'agent-action.failed',
|
|
285
|
+
subjectType: 'agent-action',
|
|
286
|
+
subjectId: invocation.id,
|
|
287
|
+
metadata: {
|
|
288
|
+
actionId: invocation.actionId,
|
|
289
|
+
code: 'ACTION_VERSION_MISSING',
|
|
290
|
+
},
|
|
291
|
+
occurredAt: completedAt,
|
|
292
|
+
},
|
|
293
|
+
);
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
const renewal = setInterval(
|
|
297
|
+
() => {
|
|
298
|
+
/* The timer cannot await, so a lost renewal aborts through the
|
|
299
|
+
controller the next tick observes. */
|
|
300
|
+
void repository
|
|
301
|
+
.renewActionLease(
|
|
302
|
+
invocation.tenantId,
|
|
303
|
+
invocation.id,
|
|
304
|
+
workerId,
|
|
305
|
+
now() + leaseMs,
|
|
306
|
+
)
|
|
307
|
+
.then((renewed) => {
|
|
308
|
+
if (!renewed) controller.abort('lease-lost');
|
|
309
|
+
})
|
|
310
|
+
.catch(() => controller.abort('lease-lost'));
|
|
311
|
+
},
|
|
312
|
+
Math.max(500, Math.floor(leaseMs / 2)),
|
|
313
|
+
);
|
|
314
|
+
renewal.unref?.();
|
|
315
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
316
|
+
let rejectAbort: (() => void) | undefined;
|
|
317
|
+
try {
|
|
318
|
+
const currentlyHeld = new Set(
|
|
319
|
+
invocation.authorizationSubject
|
|
320
|
+
? await (options.authorizeToolAccess?.({
|
|
321
|
+
tenantId: invocation.tenantId,
|
|
322
|
+
actor: invocation.authorizationSubject,
|
|
323
|
+
signal: controller.signal,
|
|
324
|
+
}) ?? [])
|
|
325
|
+
: [],
|
|
326
|
+
);
|
|
327
|
+
const permissions = new Set(
|
|
328
|
+
invocation.permissionSnapshot.filter((permission) =>
|
|
329
|
+
currentlyHeld.has(permission),
|
|
330
|
+
),
|
|
331
|
+
);
|
|
332
|
+
if (
|
|
333
|
+
action.requiredPermissions.some(
|
|
334
|
+
(permission) => !permissions.has(permission),
|
|
335
|
+
)
|
|
336
|
+
) {
|
|
337
|
+
throw new AgentActionCapabilityError(
|
|
338
|
+
'ACTION_PERMISSION_REVOKED',
|
|
339
|
+
'The workflow actor no longer has permission for this action.',
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
const aborted = new Promise<never>((_, reject) => {
|
|
343
|
+
rejectAbort = () =>
|
|
344
|
+
reject(
|
|
345
|
+
new AgentActionCapabilityError(
|
|
346
|
+
'ACTION_EXECUTION_ABORTED',
|
|
347
|
+
'Action execution was aborted.',
|
|
348
|
+
),
|
|
349
|
+
);
|
|
350
|
+
if (controller.signal.aborted) rejectAbort();
|
|
351
|
+
else
|
|
352
|
+
controller.signal.addEventListener('abort', rejectAbort, {
|
|
353
|
+
once: true,
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
const result = await Promise.race([
|
|
357
|
+
tool.execute(invocation.input, {
|
|
358
|
+
runId: invocation.workflowRunId,
|
|
359
|
+
tenantId: invocation.tenantId,
|
|
360
|
+
requestedBy: invocation.actor.id,
|
|
361
|
+
actor: invocation.actor,
|
|
362
|
+
...(invocation.authorizationSubject
|
|
363
|
+
? { authorizationSubject: invocation.authorizationSubject }
|
|
364
|
+
: {}),
|
|
365
|
+
...(invocation.actor.kind === 'agent'
|
|
366
|
+
? {
|
|
367
|
+
agentId: invocation.actor.id,
|
|
368
|
+
agentName: invocation.actor.label,
|
|
369
|
+
}
|
|
370
|
+
: {}),
|
|
371
|
+
idempotencyKey: invocation.idempotencyKey,
|
|
372
|
+
permissions,
|
|
373
|
+
signal: controller.signal,
|
|
374
|
+
}),
|
|
375
|
+
new Promise<never>((_, reject) => {
|
|
376
|
+
timer = setTimeout(() => {
|
|
377
|
+
reject(
|
|
378
|
+
new AgentActionCapabilityError(
|
|
379
|
+
'ACTION_TIMEOUT',
|
|
380
|
+
`Action ${action.id} exceeded ${action.timeoutMs} ms.`,
|
|
381
|
+
),
|
|
382
|
+
);
|
|
383
|
+
controller.abort('timeout');
|
|
384
|
+
}, action.timeoutMs);
|
|
385
|
+
}),
|
|
386
|
+
aborted,
|
|
387
|
+
]);
|
|
388
|
+
validateJsonValue(result, 'ACTION_OUTPUT_INVALID', 'Action output');
|
|
389
|
+
validateToolOutput(action.outputSchema, result);
|
|
390
|
+
const boundedOutput = boundToolOutput(result);
|
|
391
|
+
if (boundedOutput.truncated) {
|
|
392
|
+
throw new AgentActionCapabilityError(
|
|
393
|
+
'ACTION_OUTPUT_TOO_LARGE',
|
|
394
|
+
'Action output exceeds the 32768 character limit.',
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
const completedAt = now();
|
|
398
|
+
await repository.completeAction(
|
|
399
|
+
invocation.tenantId,
|
|
400
|
+
invocation.id,
|
|
401
|
+
workerId,
|
|
402
|
+
result as JsonValue,
|
|
403
|
+
completedAt,
|
|
404
|
+
{
|
|
405
|
+
tenantId: invocation.tenantId,
|
|
406
|
+
actorId: invocation.actor.id,
|
|
407
|
+
action: 'agent-action.succeeded',
|
|
408
|
+
subjectType: 'agent-action',
|
|
409
|
+
subjectId: invocation.id,
|
|
410
|
+
metadata: {
|
|
411
|
+
actionId: invocation.actionId,
|
|
412
|
+
contractVersion: invocation.contractVersion,
|
|
413
|
+
workflowRunId: invocation.workflowRunId,
|
|
414
|
+
},
|
|
415
|
+
occurredAt: completedAt,
|
|
416
|
+
},
|
|
417
|
+
);
|
|
418
|
+
} catch (error) {
|
|
419
|
+
if (
|
|
420
|
+
controller.signal.reason === 'cancelled' ||
|
|
421
|
+
controller.signal.reason === 'worker-shutdown' ||
|
|
422
|
+
controller.signal.reason === 'lease-lost'
|
|
423
|
+
) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
const code = safeCode(error);
|
|
427
|
+
const completedAt = now();
|
|
428
|
+
await repository.failAction(
|
|
429
|
+
invocation.tenantId,
|
|
430
|
+
invocation.id,
|
|
431
|
+
workerId,
|
|
432
|
+
code,
|
|
433
|
+
completedAt,
|
|
434
|
+
{
|
|
435
|
+
tenantId: invocation.tenantId,
|
|
436
|
+
actorId: invocation.actor.id,
|
|
437
|
+
action: 'agent-action.failed',
|
|
438
|
+
subjectType: 'agent-action',
|
|
439
|
+
subjectId: invocation.id,
|
|
440
|
+
metadata: { actionId: invocation.actionId, code },
|
|
441
|
+
occurredAt: completedAt,
|
|
442
|
+
},
|
|
443
|
+
);
|
|
444
|
+
} finally {
|
|
445
|
+
if (timer !== undefined) clearTimeout(timer);
|
|
446
|
+
if (rejectAbort)
|
|
447
|
+
controller.signal.removeEventListener('abort', rejectAbort);
|
|
448
|
+
clearInterval(renewal);
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
const drain = async () => {
|
|
453
|
+
if (stopped) return;
|
|
454
|
+
for (const candidate of await repository.listRecoverableActions(now(), 8)) {
|
|
455
|
+
if (inFlight.has(candidate.invocationId)) continue;
|
|
456
|
+
const claimedAt = now();
|
|
457
|
+
const invocation = await repository.claimAction(
|
|
458
|
+
candidate.tenantId,
|
|
459
|
+
candidate.invocationId,
|
|
460
|
+
workerId,
|
|
461
|
+
claimedAt,
|
|
462
|
+
claimedAt + leaseMs,
|
|
463
|
+
{
|
|
464
|
+
tenantId: candidate.tenantId,
|
|
465
|
+
actorId: workerId,
|
|
466
|
+
action: 'agent-action.claimed',
|
|
467
|
+
subjectType: 'agent-action',
|
|
468
|
+
subjectId: candidate.invocationId,
|
|
469
|
+
metadata: {},
|
|
470
|
+
occurredAt: claimedAt,
|
|
471
|
+
},
|
|
472
|
+
);
|
|
473
|
+
if (!invocation) continue;
|
|
474
|
+
const controller = new AbortController();
|
|
475
|
+
inFlight.set(invocation.id, controller);
|
|
476
|
+
void execute(invocation, controller)
|
|
477
|
+
.catch((error: unknown) => {
|
|
478
|
+
console.error(
|
|
479
|
+
`[agents] worker failed to settle action ${invocation.id}:`,
|
|
480
|
+
error instanceof Error ? error.message : error,
|
|
481
|
+
);
|
|
482
|
+
})
|
|
483
|
+
.finally(() => {
|
|
484
|
+
finish(invocation.id);
|
|
485
|
+
kick();
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
const kick = () => {
|
|
491
|
+
if (stopped || scheduled) return;
|
|
492
|
+
scheduled = true;
|
|
493
|
+
kickTimer = setTimeout(() => {
|
|
494
|
+
kickTimer = undefined;
|
|
495
|
+
scheduled = false;
|
|
496
|
+
try {
|
|
497
|
+
drain();
|
|
498
|
+
} catch (error) {
|
|
499
|
+
/* A transactional claim can fail with the row still queued. Keep the
|
|
500
|
+
process alive so the poller can retry after the database recovers. */
|
|
501
|
+
console.error(
|
|
502
|
+
'[agents] action worker drain failed:',
|
|
503
|
+
error instanceof Error ? error.message : error,
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
}, 0);
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
const cancellation = async (
|
|
510
|
+
actionInvocationId: string,
|
|
511
|
+
context: AgentActionChildContext,
|
|
512
|
+
): Promise<ActionCancellationResult> => {
|
|
513
|
+
const invocation = await repository.getAction(
|
|
514
|
+
context.tenantId,
|
|
515
|
+
actionInvocationId,
|
|
516
|
+
);
|
|
517
|
+
const actor = normalizeActor(context.actor);
|
|
518
|
+
const action = invocation ? actionById.get(invocation.actionId) : undefined;
|
|
519
|
+
if (
|
|
520
|
+
!invocation ||
|
|
521
|
+
invocation.workflowRunId !== context.workflowRunId ||
|
|
522
|
+
!actor ||
|
|
523
|
+
!actorsEqual(actor, invocation.actor) ||
|
|
524
|
+
!action ||
|
|
525
|
+
action.requiredPermissions.some(
|
|
526
|
+
(permission) => !context.permissionSnapshot.includes(permission),
|
|
527
|
+
)
|
|
528
|
+
) {
|
|
529
|
+
return { actionInvocationId, state: 'not-acknowledged' };
|
|
530
|
+
}
|
|
531
|
+
if (action?.cancellation !== 'cooperative') {
|
|
532
|
+
return { actionInvocationId, state: 'not-supported' };
|
|
533
|
+
}
|
|
534
|
+
const cancelledAt = now();
|
|
535
|
+
const previous = await repository.cancelAction(
|
|
536
|
+
invocation.tenantId,
|
|
537
|
+
invocation.id,
|
|
538
|
+
cancelledAt,
|
|
539
|
+
{
|
|
540
|
+
tenantId: invocation.tenantId,
|
|
541
|
+
actorId: context.actor.id,
|
|
542
|
+
action: 'agent-action.cancelled',
|
|
543
|
+
subjectType: 'agent-action',
|
|
544
|
+
subjectId: invocation.id,
|
|
545
|
+
metadata: { actionId: invocation.actionId },
|
|
546
|
+
occurredAt: cancelledAt,
|
|
547
|
+
},
|
|
548
|
+
);
|
|
549
|
+
if (previous === null) {
|
|
550
|
+
return { actionInvocationId, state: 'not-acknowledged' };
|
|
551
|
+
}
|
|
552
|
+
inFlight.get(invocation.id)?.abort('cancelled');
|
|
553
|
+
detachCallerSignal(invocation.id);
|
|
554
|
+
return { actionInvocationId, state: 'acknowledged' };
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
const capability: AgentActionExecutionCapability = {
|
|
558
|
+
listWorkflowActions: async () =>
|
|
559
|
+
actions.map((action) => ({
|
|
560
|
+
...action,
|
|
561
|
+
requiredPermissions: [...action.requiredPermissions],
|
|
562
|
+
inputSchema: structuredClone(action.inputSchema),
|
|
563
|
+
outputSchema: structuredClone(action.outputSchema),
|
|
564
|
+
})),
|
|
565
|
+
async start(request, context) {
|
|
566
|
+
if (context.signal.aborted) {
|
|
567
|
+
throw new AgentActionCapabilityError(
|
|
568
|
+
'ACTION_CANCELLED',
|
|
569
|
+
'Action invocation was cancelled before enqueue.',
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
const actor = normalizeActor(context.actor);
|
|
573
|
+
if (!actor) {
|
|
574
|
+
throw new AgentActionCapabilityError(
|
|
575
|
+
'ACTION_INVALID_ACTOR',
|
|
576
|
+
'Action actor is invalid.',
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
const tenantId = bounded(context.tenantId, 'tenantId', 1, 128);
|
|
580
|
+
const authorizationSubject = trustedAuthorizationSubject(
|
|
581
|
+
actor,
|
|
582
|
+
context.authorizationSubject,
|
|
583
|
+
);
|
|
584
|
+
const actionId = bounded(request.actionId, 'actionId', 3, 128);
|
|
585
|
+
const action = actionById.get(actionId);
|
|
586
|
+
if (!action || action.contractVersion !== request.contractVersion) {
|
|
587
|
+
throw new AgentActionCapabilityError(
|
|
588
|
+
'ACTION_VERSION_MISSING',
|
|
589
|
+
'Action contract version is unavailable.',
|
|
590
|
+
);
|
|
591
|
+
}
|
|
592
|
+
if (
|
|
593
|
+
action.requiredPermissions.some(
|
|
594
|
+
(permission) => !context.permissionSnapshot.includes(permission),
|
|
595
|
+
)
|
|
596
|
+
) {
|
|
597
|
+
throw new AgentActionCapabilityError(
|
|
598
|
+
'ACTION_PERMISSION_DENIED',
|
|
599
|
+
'The workflow actor lacks permission for this action.',
|
|
600
|
+
);
|
|
601
|
+
}
|
|
602
|
+
let authorized: readonly string[];
|
|
603
|
+
try {
|
|
604
|
+
authorized = await (options.authorizeToolAccess?.({
|
|
605
|
+
tenantId,
|
|
606
|
+
actor: authorizationSubject,
|
|
607
|
+
signal: context.signal,
|
|
608
|
+
}) ?? []);
|
|
609
|
+
} catch {
|
|
610
|
+
throw new AgentActionCapabilityError(
|
|
611
|
+
'ACTION_AUTHORIZATION_UNAVAILABLE',
|
|
612
|
+
'Live action authorization is unavailable.',
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
const livePermissions = new Set(authorized);
|
|
616
|
+
if (
|
|
617
|
+
action.requiredPermissions.some(
|
|
618
|
+
(permission) => !livePermissions.has(permission),
|
|
619
|
+
)
|
|
620
|
+
) {
|
|
621
|
+
throw new AgentActionCapabilityError(
|
|
622
|
+
'ACTION_PERMISSION_REVOKED',
|
|
623
|
+
'The workflow actor no longer has permission for this action.',
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
try {
|
|
627
|
+
validateJsonValue(
|
|
628
|
+
request.input,
|
|
629
|
+
'ACTION_INPUT_INVALID',
|
|
630
|
+
'Action input',
|
|
631
|
+
);
|
|
632
|
+
validateToolInput(action.inputSchema, request.input);
|
|
633
|
+
} catch (error) {
|
|
634
|
+
throw new AgentActionCapabilityError(
|
|
635
|
+
'ACTION_INPUT_INVALID',
|
|
636
|
+
error instanceof Error ? error.message : 'Action input is invalid.',
|
|
637
|
+
);
|
|
638
|
+
}
|
|
639
|
+
const inputJson = canonical(request.input);
|
|
640
|
+
if (inputJson.length > 32_768) {
|
|
641
|
+
throw new AgentActionCapabilityError(
|
|
642
|
+
'ACTION_INPUT_TOO_LARGE',
|
|
643
|
+
'Action input exceeds the 32768 character limit.',
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
const workflowRunId = bounded(
|
|
647
|
+
context.workflowRunId,
|
|
648
|
+
'workflowRunId',
|
|
649
|
+
1,
|
|
650
|
+
128,
|
|
651
|
+
);
|
|
652
|
+
const nodeRunId = bounded(context.nodeRunId, 'nodeRunId', 1, 128);
|
|
653
|
+
const idempotencyKey = bounded(
|
|
654
|
+
request.idempotencyKey,
|
|
655
|
+
'idempotencyKey',
|
|
656
|
+
8,
|
|
657
|
+
128,
|
|
658
|
+
);
|
|
659
|
+
const permissions = [...new Set(context.permissionSnapshot)].sort();
|
|
660
|
+
const requestHash = createHash('sha256')
|
|
661
|
+
.update(
|
|
662
|
+
JSON.stringify([
|
|
663
|
+
action.id,
|
|
664
|
+
action.contractVersion,
|
|
665
|
+
inputJson,
|
|
666
|
+
workflowRunId,
|
|
667
|
+
nodeRunId,
|
|
668
|
+
actor,
|
|
669
|
+
authorizationSubject,
|
|
670
|
+
permissions,
|
|
671
|
+
]),
|
|
672
|
+
)
|
|
673
|
+
.digest('hex');
|
|
674
|
+
const existing = await repository.findActionByIdempotencyKey(
|
|
675
|
+
tenantId,
|
|
676
|
+
idempotencyKey,
|
|
677
|
+
);
|
|
678
|
+
if (existing) {
|
|
679
|
+
if (existing.requestHash !== requestHash) {
|
|
680
|
+
throw new AgentActionCapabilityError(
|
|
681
|
+
'ACTION_IDEMPOTENCY_CONFLICT',
|
|
682
|
+
'The idempotency key is bound to another action request.',
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
return { actionInvocationId: existing.id, created: false };
|
|
686
|
+
}
|
|
687
|
+
const invocation: AgentActionInvocation = {
|
|
688
|
+
id: randomUUID(),
|
|
689
|
+
tenantId,
|
|
690
|
+
workflowRunId,
|
|
691
|
+
nodeRunId,
|
|
692
|
+
actionId: action.id,
|
|
693
|
+
contractVersion: action.contractVersion,
|
|
694
|
+
actor,
|
|
695
|
+
authorizationSubject,
|
|
696
|
+
permissionSnapshot: permissions,
|
|
697
|
+
input: request.input,
|
|
698
|
+
idempotencyKey,
|
|
699
|
+
requestHash,
|
|
700
|
+
status: 'queued',
|
|
701
|
+
output: null,
|
|
702
|
+
code: null,
|
|
703
|
+
attempt: 0,
|
|
704
|
+
queuedAt: now(),
|
|
705
|
+
startedAt: null,
|
|
706
|
+
completedAt: null,
|
|
707
|
+
leaseExpiresAt: null,
|
|
708
|
+
};
|
|
709
|
+
try {
|
|
710
|
+
await repository.enqueueAction(invocation, {
|
|
711
|
+
tenantId,
|
|
712
|
+
actorId: actor.id,
|
|
713
|
+
action: 'agent-action.queued',
|
|
714
|
+
subjectType: 'agent-action',
|
|
715
|
+
subjectId: invocation.id,
|
|
716
|
+
metadata: {
|
|
717
|
+
actionId: invocation.actionId,
|
|
718
|
+
contractVersion: invocation.contractVersion,
|
|
719
|
+
workflowRunId,
|
|
720
|
+
},
|
|
721
|
+
occurredAt: invocation.queuedAt,
|
|
722
|
+
});
|
|
723
|
+
} catch (error) {
|
|
724
|
+
if (error instanceof DuplicateActionIdempotencyKeyError) {
|
|
725
|
+
const raced = await repository.findActionByIdempotencyKey(
|
|
726
|
+
tenantId,
|
|
727
|
+
idempotencyKey,
|
|
728
|
+
);
|
|
729
|
+
if (raced?.requestHash === requestHash) {
|
|
730
|
+
return { actionInvocationId: raced.id, created: false };
|
|
731
|
+
}
|
|
732
|
+
throw new AgentActionCapabilityError(
|
|
733
|
+
'ACTION_IDEMPOTENCY_CONFLICT',
|
|
734
|
+
'The idempotency key is bound to another action request.',
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
throw error;
|
|
738
|
+
}
|
|
739
|
+
const listener = () => void cancellation(invocation.id, context);
|
|
740
|
+
callerSignals.set(invocation.id, { signal: context.signal, listener });
|
|
741
|
+
context.signal.addEventListener('abort', listener, { once: true });
|
|
742
|
+
/* Abort may race with durable enqueue before the listener exists. Recheck
|
|
743
|
+
after registration so an already-aborted signal cannot leave queued work. */
|
|
744
|
+
if (context.signal.aborted && callerSignals.has(invocation.id))
|
|
745
|
+
listener();
|
|
746
|
+
kick();
|
|
747
|
+
return { actionInvocationId: invocation.id, created: true };
|
|
748
|
+
},
|
|
749
|
+
async getResult(actionInvocationId, context) {
|
|
750
|
+
const invocation = await repository.getAction(
|
|
751
|
+
bounded(context.tenantId, 'tenantId', 1, 128),
|
|
752
|
+
bounded(actionInvocationId, 'actionInvocationId', 1, 128),
|
|
753
|
+
);
|
|
754
|
+
const actor = normalizeActor(context.actor);
|
|
755
|
+
const action = invocation
|
|
756
|
+
? actionById.get(invocation.actionId)
|
|
757
|
+
: undefined;
|
|
758
|
+
if (
|
|
759
|
+
!invocation ||
|
|
760
|
+
invocation.workflowRunId !== context.workflowRunId ||
|
|
761
|
+
!actor ||
|
|
762
|
+
!actorsEqual(actor, invocation.actor) ||
|
|
763
|
+
!action ||
|
|
764
|
+
action.requiredPermissions.some(
|
|
765
|
+
(permission) => !context.permissionSnapshot.includes(permission),
|
|
766
|
+
)
|
|
767
|
+
) {
|
|
768
|
+
return null;
|
|
769
|
+
}
|
|
770
|
+
if (invocation.status === 'queued' || invocation.status === 'running') {
|
|
771
|
+
return null;
|
|
772
|
+
}
|
|
773
|
+
return {
|
|
774
|
+
actionInvocationId: invocation.id,
|
|
775
|
+
status: invocation.status,
|
|
776
|
+
...(invocation.output === null ? {} : { output: invocation.output }),
|
|
777
|
+
...(invocation.code === null ? {} : { code: invocation.code }),
|
|
778
|
+
};
|
|
779
|
+
},
|
|
780
|
+
requestCancel: cancellation,
|
|
781
|
+
};
|
|
782
|
+
|
|
783
|
+
return {
|
|
784
|
+
capability,
|
|
785
|
+
async start() {
|
|
786
|
+
if (!stopped) return;
|
|
787
|
+
stopped = false;
|
|
788
|
+
poll = setInterval(kick, Math.max(1_000, Math.floor(leaseMs / 2)));
|
|
789
|
+
poll.unref?.();
|
|
790
|
+
kick();
|
|
791
|
+
},
|
|
792
|
+
stop() {
|
|
793
|
+
stopped = true;
|
|
794
|
+
if (poll !== undefined) clearInterval(poll);
|
|
795
|
+
poll = undefined;
|
|
796
|
+
if (kickTimer !== undefined) clearTimeout(kickTimer);
|
|
797
|
+
kickTimer = undefined;
|
|
798
|
+
scheduled = false;
|
|
799
|
+
},
|
|
800
|
+
async dispose() {
|
|
801
|
+
this.stop();
|
|
802
|
+
for (const id of callerSignals.keys()) detachCallerSignal(id);
|
|
803
|
+
for (const controller of inFlight.values()) {
|
|
804
|
+
controller.abort('worker-shutdown');
|
|
805
|
+
}
|
|
806
|
+
if (inFlight.size > 0) {
|
|
807
|
+
await new Promise<void>((resolve) => idleWaiters.add(resolve));
|
|
808
|
+
}
|
|
809
|
+
},
|
|
810
|
+
};
|
|
811
|
+
}
|