@segmentstream/ontology 0.0.0-stage → 0.92.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/LICENSE +201 -0
- package/NOTICE +2 -0
- package/README.md +1655 -2
- package/dist/action.d.ts +193 -0
- package/dist/action.js +41 -0
- package/dist/agent-chat.d.ts +44 -0
- package/dist/agent-chat.js +91 -0
- package/dist/agent-task-contract.d.ts +64 -0
- package/dist/agent-task-contract.js +15 -0
- package/dist/agent-task.d.ts +39 -0
- package/dist/agent-task.js +112 -0
- package/dist/analyze.d.ts +215 -0
- package/dist/analyze.js +2438 -0
- package/dist/app-feedback.d.ts +167 -0
- package/dist/app-feedback.js +176 -0
- package/dist/authoring-input.d.ts +3 -0
- package/dist/authoring-input.js +107 -0
- package/dist/authoring-names.d.ts +4 -0
- package/dist/authoring-names.js +13 -0
- package/dist/authoring-records.d.ts +35 -0
- package/dist/authoring-records.js +264 -0
- package/dist/authoring.d.ts +15 -0
- package/dist/authoring.js +331 -0
- package/dist/bin/check.d.ts +30 -0
- package/dist/bin/check.js +99 -0
- package/dist/bin/load.d.ts +48 -0
- package/dist/bin/load.js +139 -0
- package/dist/bin/main.d.ts +31 -0
- package/dist/bin/main.js +121 -0
- package/dist/bin/migrate.d.ts +57 -0
- package/dist/bin/migrate.js +170 -0
- package/dist/bin/output.d.ts +31 -0
- package/dist/bin/output.js +84 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +31 -0
- package/dist/blob.d.ts +52 -0
- package/dist/blob.js +87 -0
- package/dist/channel-session.d.ts +16 -0
- package/dist/channel-session.js +16 -0
- package/dist/chat.d.ts +43 -0
- package/dist/chat.js +34 -0
- package/dist/confirmation.d.ts +46 -0
- package/dist/confirmation.js +41 -0
- package/dist/connection.d.ts +213 -0
- package/dist/connection.js +289 -0
- package/dist/deployment.d.ts +35 -0
- package/dist/deployment.js +76 -0
- package/dist/diagnostics.d.ts +27 -0
- package/dist/diagnostics.js +106 -0
- package/dist/emails.d.ts +70 -0
- package/dist/emails.js +221 -0
- package/dist/entity.d.ts +331 -0
- package/dist/entity.js +153 -0
- package/dist/errors.d.ts +154 -0
- package/dist/errors.js +109 -0
- package/dist/feedback-config.d.ts +24 -0
- package/dist/feedback-config.js +126 -0
- package/dist/files.d.ts +39 -0
- package/dist/files.js +4 -0
- package/dist/groups.d.ts +95 -0
- package/dist/groups.js +280 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.js +70 -0
- package/dist/internal/diagnostics.js +594 -0
- package/dist/legacy.d.ts +160 -0
- package/dist/legacy.js +270 -0
- package/dist/manifest-compatibility.d.ts +8 -0
- package/dist/manifest-compatibility.js +87 -0
- package/dist/manifest.d.ts +3329 -0
- package/dist/manifest.js +757 -0
- package/dist/me.d.ts +46 -0
- package/dist/me.js +109 -0
- package/dist/metric-filters.d.ts +48 -0
- package/dist/metric-filters.js +252 -0
- package/dist/metric-routes.d.ts +132 -0
- package/dist/metric-routes.js +498 -0
- package/dist/metric.d.ts +172 -0
- package/dist/metric.js +132 -0
- package/dist/migrate/apply.d.ts +94 -0
- package/dist/migrate/apply.js +526 -0
- package/dist/migrate/errors.d.ts +46 -0
- package/dist/migrate/errors.js +38 -0
- package/dist/migrate/index.d.ts +10 -0
- package/dist/migrate/index.js +7 -0
- package/dist/migrate/model.d.ts +2311 -0
- package/dist/migrate/model.js +148 -0
- package/dist/migrate/plan.d.ts +51 -0
- package/dist/migrate/plan.js +1856 -0
- package/dist/migrate/preview.d.ts +13 -0
- package/dist/migrate/preview.js +65 -0
- package/dist/migrate/storage.d.ts +226 -0
- package/dist/migrate/storage.js +774 -0
- package/dist/model-metrics.d.ts +22 -0
- package/dist/model-metrics.js +545 -0
- package/dist/names.d.ts +49 -0
- package/dist/names.js +110 -0
- package/dist/navigation-artifact.d.ts +13 -0
- package/dist/navigation-artifact.js +11 -0
- package/dist/navigation-catalog.d.ts +55 -0
- package/dist/navigation-catalog.js +297 -0
- package/dist/nitro-navigation.d.ts +3 -0
- package/dist/nitro-navigation.js +64 -0
- package/dist/nitro-workflows.d.ts +108 -0
- package/dist/nitro-workflows.js +286 -0
- package/dist/nitro.d.ts +40 -0
- package/dist/nitro.js +50 -0
- package/dist/ontology.d.ts +41 -0
- package/dist/ontology.js +46 -0
- package/dist/permissions.d.ts +198 -0
- package/dist/permissions.js +272 -0
- package/dist/property.d.ts +188 -0
- package/dist/property.js +301 -0
- package/dist/query.d.ts +245 -0
- package/dist/query.js +615 -0
- package/dist/relationship.d.ts +99 -0
- package/dist/relationship.js +33 -0
- package/dist/render.d.ts +81 -0
- package/dist/render.js +512 -0
- package/dist/replication/baseline.d.ts +51 -0
- package/dist/replication/baseline.js +215 -0
- package/dist/replication/bigquery.d.ts +37 -0
- package/dist/replication/bigquery.js +211 -0
- package/dist/replication/coverage.d.ts +14 -0
- package/dist/replication/coverage.js +53 -0
- package/dist/replication/evolution.d.ts +25 -0
- package/dist/replication/evolution.js +184 -0
- package/dist/replication/identities.d.ts +6 -0
- package/dist/replication/identities.js +47 -0
- package/dist/replication/legacy-baseline.d.ts +27 -0
- package/dist/replication/legacy-baseline.js +109 -0
- package/dist/replication/legacy-store.d.ts +19 -0
- package/dist/replication/legacy-store.js +63 -0
- package/dist/replication/lineage.d.ts +36 -0
- package/dist/replication/lineage.js +72 -0
- package/dist/replication/migrate.d.ts +21 -0
- package/dist/replication/migrate.js +84 -0
- package/dist/replication/model.d.ts +52 -0
- package/dist/replication/model.js +99 -0
- package/dist/replication/scans.d.ts +34 -0
- package/dist/replication/scans.js +158 -0
- package/dist/replication/schema.d.ts +11 -0
- package/dist/replication/schema.js +226 -0
- package/dist/replication/shadow-schema.d.ts +4 -0
- package/dist/replication/shadow-schema.js +61 -0
- package/dist/replication/shadow.d.ts +127 -0
- package/dist/replication/shadow.js +614 -0
- package/dist/replication/source-replacement.d.ts +33 -0
- package/dist/replication/source-replacement.js +76 -0
- package/dist/replication/store.d.ts +36 -0
- package/dist/replication/store.js +382 -0
- package/dist/replication/transaction.d.ts +23 -0
- package/dist/replication/transaction.js +88 -0
- package/dist/role.d.ts +61 -0
- package/dist/role.js +76 -0
- package/dist/runtime/action-deadlocks.d.ts +21 -0
- package/dist/runtime/action-deadlocks.js +130 -0
- package/dist/runtime/action-transactions.d.ts +35 -0
- package/dist/runtime/action-transactions.js +54 -0
- package/dist/runtime/agent-counters.d.ts +26 -0
- package/dist/runtime/agent-counters.js +98 -0
- package/dist/runtime/agent-tasks.d.ts +63 -0
- package/dist/runtime/agent-tasks.js +120 -0
- package/dist/runtime/agents.d.ts +15 -0
- package/dist/runtime/agents.js +457 -0
- package/dist/runtime/batch-diagnostics.d.ts +22 -0
- package/dist/runtime/batch-diagnostics.js +89 -0
- package/dist/runtime/batch.d.ts +52 -0
- package/dist/runtime/batch.js +534 -0
- package/dist/runtime/channel-session-revocation.d.ts +3 -0
- package/dist/runtime/channel-session-revocation.js +5 -0
- package/dist/runtime/channel-sessions.d.ts +4 -0
- package/dist/runtime/channel-sessions.js +61 -0
- package/dist/runtime/confirmations.d.ts +29 -0
- package/dist/runtime/confirmations.js +57 -0
- package/dist/runtime/cursor.d.ts +23 -0
- package/dist/runtime/cursor.js +100 -0
- package/dist/runtime/deployment.d.ts +7 -0
- package/dist/runtime/deployment.js +4 -0
- package/dist/runtime/errors.d.ts +118 -0
- package/dist/runtime/errors.js +109 -0
- package/dist/runtime/federation-tables.d.ts +2 -0
- package/dist/runtime/federation-tables.js +20 -0
- package/dist/runtime/federation.d.ts +42 -0
- package/dist/runtime/federation.js +222 -0
- package/dist/runtime/files.d.ts +39 -0
- package/dist/runtime/files.js +44 -0
- package/dist/runtime/generated-actions.d.ts +37 -0
- package/dist/runtime/generated-actions.js +307 -0
- package/dist/runtime/history.d.ts +91 -0
- package/dist/runtime/history.js +77 -0
- package/dist/runtime/ids.d.ts +6 -0
- package/dist/runtime/ids.js +39 -0
- package/dist/runtime/member-tables.d.ts +8 -0
- package/dist/runtime/member-tables.js +33 -0
- package/dist/runtime/member-writes.d.ts +78 -0
- package/dist/runtime/member-writes.js +202 -0
- package/dist/runtime/metric-query.d.ts +19 -0
- package/dist/runtime/metric-query.js +411 -0
- package/dist/runtime/model.d.ts +67 -0
- package/dist/runtime/model.js +150 -0
- package/dist/runtime/new-user-hook.d.ts +6 -0
- package/dist/runtime/new-user-hook.js +37 -0
- package/dist/runtime/oauth.d.ts +9 -0
- package/dist/runtime/oauth.js +299 -0
- package/dist/runtime/pipeline.d.ts +155 -0
- package/dist/runtime/pipeline.js +597 -0
- package/dist/runtime/postgres-tls.d.ts +10 -0
- package/dist/runtime/postgres-tls.js +14 -0
- package/dist/runtime/principals.d.ts +302 -0
- package/dist/runtime/principals.js +1307 -0
- package/dist/runtime/reads.d.ts +55 -0
- package/dist/runtime/reads.js +313 -0
- package/dist/runtime/records.d.ts +42 -0
- package/dist/runtime/records.js +245 -0
- package/dist/runtime/resolve-agent-identity.d.ts +6 -0
- package/dist/runtime/resolve-agent-identity.js +181 -0
- package/dist/runtime/service-binding.d.ts +18 -0
- package/dist/runtime/service-binding.js +266 -0
- package/dist/runtime/sign-in-links.d.ts +68 -0
- package/dist/runtime/sign-in-links.js +147 -0
- package/dist/runtime/sql-runtime.d.ts +131 -0
- package/dist/runtime/sql-runtime.js +362 -0
- package/dist/runtime/statement.d.ts +18 -0
- package/dist/runtime/statement.js +31 -0
- package/dist/runtime/user-identities.d.ts +66 -0
- package/dist/runtime/user-identities.js +106 -0
- package/dist/runtime/user-identity-sql.d.ts +86 -0
- package/dist/runtime/user-identity-sql.js +297 -0
- package/dist/runtime/user-roles.d.ts +16 -0
- package/dist/runtime/user-roles.js +32 -0
- package/dist/runtime/validation.d.ts +16 -0
- package/dist/runtime/validation.js +26 -0
- package/dist/runtime/where.d.ts +57 -0
- package/dist/runtime/where.js +404 -0
- package/dist/runtime/workflow-admission.d.ts +49 -0
- package/dist/runtime/workflow-admission.js +92 -0
- package/dist/runtime/workflow-argument-codec.d.ts +10 -0
- package/dist/runtime/workflow-argument-codec.js +120 -0
- package/dist/runtime/workflow-arguments.d.ts +17 -0
- package/dist/runtime/workflow-arguments.js +99 -0
- package/dist/runtime/workflow-starts.d.ts +203 -0
- package/dist/runtime/workflow-starts.js +493 -0
- package/dist/runtime/workflow-users.d.ts +9 -0
- package/dist/runtime/workflow-users.js +17 -0
- package/dist/runtime/workload.d.ts +25 -0
- package/dist/runtime/workload.js +24 -0
- package/dist/runtime/writes.d.ts +108 -0
- package/dist/runtime/writes.js +491 -0
- package/dist/runtime-source.d.ts +22 -0
- package/dist/runtime-source.js +28 -0
- package/dist/runtime.d.ts +310 -0
- package/dist/runtime.js +31 -0
- package/dist/server.d.ts +23 -0
- package/dist/server.js +107 -0
- package/dist/service/agent/attachments.d.ts +33 -0
- package/dist/service/agent/attachments.js +228 -0
- package/dist/service/agent/authentication.d.ts +22 -0
- package/dist/service/agent/authentication.js +58 -0
- package/dist/service/agent/confirmations.d.ts +5 -0
- package/dist/service/agent/confirmations.js +73 -0
- package/dist/service/agent/conversation-routes.d.ts +14 -0
- package/dist/service/agent/conversation-routes.js +45 -0
- package/dist/service/agent/conversations.d.ts +40 -0
- package/dist/service/agent/conversations.js +69 -0
- package/dist/service/agent/files.d.ts +12 -0
- package/dist/service/agent/files.js +69 -0
- package/dist/service/agent/protocol.d.ts +90 -0
- package/dist/service/agent/protocol.js +114 -0
- package/dist/service/agent/server.d.ts +28 -0
- package/dist/service/agent/server.js +374 -0
- package/dist/service/agent/task-caller.d.ts +21 -0
- package/dist/service/agent/task-caller.js +35 -0
- package/dist/service/agent/task-start.d.ts +53 -0
- package/dist/service/agent/task-start.js +161 -0
- package/dist/service/agent/tasks.d.ts +40 -0
- package/dist/service/agent/tasks.js +155 -0
- package/dist/service/api.d.ts +50 -0
- package/dist/service/api.js +288 -0
- package/dist/service/authentication.d.ts +227 -0
- package/dist/service/authentication.js +767 -0
- package/dist/service/caller-context.d.ts +24 -0
- package/dist/service/caller-context.js +6 -0
- package/dist/service/catalog.d.ts +42 -0
- package/dist/service/catalog.js +66 -0
- package/dist/service/channel/provider.d.ts +10 -0
- package/dist/service/channel/provider.js +1 -0
- package/dist/service/channel/providers/telegram.d.ts +18 -0
- package/dist/service/channel/providers/telegram.js +108 -0
- package/dist/service/channel/sessions.d.ts +5 -0
- package/dist/service/channel/sessions.js +53 -0
- package/dist/service/channel/sign-in.d.ts +7 -0
- package/dist/service/channel/sign-in.js +78 -0
- package/dist/service/chat/archive.d.ts +64 -0
- package/dist/service/chat/archive.js +62 -0
- package/dist/service/chat/attribution.d.ts +26 -0
- package/dist/service/chat/attribution.js +28 -0
- package/dist/service/chat/delivery.d.ts +18 -0
- package/dist/service/chat/delivery.js +251 -0
- package/dist/service/chat/diagnostics.d.ts +2 -0
- package/dist/service/chat/diagnostics.js +35 -0
- package/dist/service/chat/envelope.d.ts +96 -0
- package/dist/service/chat/envelope.js +39 -0
- package/dist/service/chat/idempotency.d.ts +19 -0
- package/dist/service/chat/idempotency.js +37 -0
- package/dist/service/chat/providers/telegram.d.ts +36 -0
- package/dist/service/chat/providers/telegram.js +133 -0
- package/dist/service/chat/reads.d.ts +25 -0
- package/dist/service/chat/reads.js +75 -0
- package/dist/service/chat/resolve.d.ts +34 -0
- package/dist/service/chat/resolve.js +150 -0
- package/dist/service/chat/routes.d.ts +23 -0
- package/dist/service/chat/routes.js +75 -0
- package/dist/service/chat/schemas.d.ts +43 -0
- package/dist/service/chat/schemas.js +31 -0
- package/dist/service/config.d.ts +218 -0
- package/dist/service/config.js +265 -0
- package/dist/service/connection-stream.d.ts +10 -0
- package/dist/service/connection-stream.js +191 -0
- package/dist/service/connections.d.ts +60 -0
- package/dist/service/connections.js +271 -0
- package/dist/service/decisions.d.ts +35 -0
- package/dist/service/decisions.js +63 -0
- package/dist/service/descriptions.d.ts +8 -0
- package/dist/service/descriptions.js +20 -0
- package/dist/service/discovery-schemas.d.ts +92 -0
- package/dist/service/discovery-schemas.js +59 -0
- package/dist/service/discovery-search.d.ts +30 -0
- package/dist/service/discovery-search.js +95 -0
- package/dist/service/discovery.d.ts +37 -0
- package/dist/service/discovery.js +436 -0
- package/dist/service/docs.d.ts +9 -0
- package/dist/service/docs.js +197 -0
- package/dist/service/errors.d.ts +145 -0
- package/dist/service/errors.js +704 -0
- package/dist/service/federation-provider.d.ts +36 -0
- package/dist/service/federation-provider.js +110 -0
- package/dist/service/federation-server.d.ts +20 -0
- package/dist/service/federation-server.js +249 -0
- package/dist/service/federation-status.d.ts +40 -0
- package/dist/service/federation-status.js +151 -0
- package/dist/service/handlers.d.ts +18 -0
- package/dist/service/handlers.js +287 -0
- package/dist/service/mcp/confirmation.d.ts +68 -0
- package/dist/service/mcp/confirmation.js +178 -0
- package/dist/service/mcp/find-input.d.ts +12 -0
- package/dist/service/mcp/find-input.js +122 -0
- package/dist/service/mcp/input-schema.d.ts +6 -0
- package/dist/service/mcp/input-schema.js +126 -0
- package/dist/service/mcp/listing.d.ts +26 -0
- package/dist/service/mcp/listing.js +92 -0
- package/dist/service/mcp/metric-tools.d.ts +85 -0
- package/dist/service/mcp/metric-tools.js +258 -0
- package/dist/service/mcp/request-log.d.ts +5 -0
- package/dist/service/mcp/request-log.js +53 -0
- package/dist/service/mcp/runtime-policy.d.ts +27 -0
- package/dist/service/mcp/runtime-policy.js +62 -0
- package/dist/service/mcp/server.d.ts +52 -0
- package/dist/service/mcp/server.js +861 -0
- package/dist/service/mcp/tools.d.ts +99 -0
- package/dist/service/mcp/tools.js +938 -0
- package/dist/service/member-file-routes.d.ts +22 -0
- package/dist/service/member-file-routes.js +52 -0
- package/dist/service/member-files.d.ts +245 -0
- package/dist/service/member-files.js +258 -0
- package/dist/service/metric-query-platform.d.ts +77 -0
- package/dist/service/metric-query-platform.js +198 -0
- package/dist/service/metric-query-scopes.d.ts +43 -0
- package/dist/service/metric-query-scopes.js +147 -0
- package/dist/service/metric-query.d.ts +48 -0
- package/dist/service/metric-query.js +200 -0
- package/dist/service/name-suggestions.d.ts +3 -0
- package/dist/service/name-suggestions.js +38 -0
- package/dist/service/navigation-schemas.d.ts +80 -0
- package/dist/service/navigation-schemas.js +49 -0
- package/dist/service/navigation.d.ts +20 -0
- package/dist/service/navigation.js +165 -0
- package/dist/service/oauth/protocol.d.ts +70 -0
- package/dist/service/oauth/protocol.js +157 -0
- package/dist/service/oauth/refresh-replay.d.ts +2 -0
- package/dist/service/oauth/refresh-replay.js +20 -0
- package/dist/service/oauth/server.d.ts +28 -0
- package/dist/service/oauth/server.js +769 -0
- package/dist/service/operations.d.ts +170 -0
- package/dist/service/operations.js +392 -0
- package/dist/service/plan.d.ts +57 -0
- package/dist/service/plan.js +96 -0
- package/dist/service/rate-limit.d.ts +22 -0
- package/dist/service/rate-limit.js +52 -0
- package/dist/service/record-reads.d.ts +21 -0
- package/dist/service/record-reads.js +155 -0
- package/dist/service/replication.d.ts +5 -0
- package/dist/service/replication.js +39 -0
- package/dist/service/runtime-contract.d.ts +508 -0
- package/dist/service/runtime-contract.js +18 -0
- package/dist/service/runtime-identity.d.ts +71 -0
- package/dist/service/runtime-identity.js +122 -0
- package/dist/service/schemas.d.ts +961 -0
- package/dist/service/schemas.js +639 -0
- package/dist/service/service.d.ts +21 -0
- package/dist/service/service.js +526 -0
- package/dist/service/warehouse-platform.d.ts +17 -0
- package/dist/service/warehouse-platform.js +122 -0
- package/dist/service/warehouse-query.d.ts +24 -0
- package/dist/service/warehouse-query.js +280 -0
- package/dist/service/webhooks.d.ts +106 -0
- package/dist/service/webhooks.js +233 -0
- package/dist/service/workflow-admission-provider.d.ts +31 -0
- package/dist/service/workflow-admission-provider.js +205 -0
- package/dist/service/workflow-argument-serialization.d.ts +2 -0
- package/dist/service/workflow-argument-serialization.js +14 -0
- package/dist/service/workflow-callback.d.ts +22 -0
- package/dist/service/workflow-callback.js +75 -0
- package/dist/service/workflow-deployment.d.ts +8 -0
- package/dist/service/workflow-deployment.js +131 -0
- package/dist/service/workflow-diagnostics.d.ts +23 -0
- package/dist/service/workflow-diagnostics.js +263 -0
- package/dist/service/workflow-errors.d.ts +26 -0
- package/dist/service/workflow-errors.js +181 -0
- package/dist/service/workflow-logging.d.ts +2 -0
- package/dist/service/workflow-logging.js +50 -0
- package/dist/service/workflow-queue-fence.d.ts +6 -0
- package/dist/service/workflow-queue-fence.js +66 -0
- package/dist/service/workflows.d.ts +200 -0
- package/dist/service/workflows.js +1549 -0
- package/dist/sign-in.d.ts +58 -0
- package/dist/sign-in.js +57 -0
- package/dist/source.d.ts +30 -0
- package/dist/source.js +107 -0
- package/dist/start-recovery-contract.d.ts +49 -0
- package/dist/start-recovery-contract.js +26 -0
- package/dist/start-recovery.d.ts +27 -0
- package/dist/start-recovery.js +81 -0
- package/dist/storage/api.d.ts +4 -0
- package/dist/storage/api.js +40 -0
- package/dist/storage/attachments.d.ts +146 -0
- package/dist/storage/attachments.js +733 -0
- package/dist/storage/authorization.d.ts +38 -0
- package/dist/storage/authorization.js +83 -0
- package/dist/storage/file-access.d.ts +17 -0
- package/dist/storage/file-access.js +8 -0
- package/dist/storage/limits.d.ts +12 -0
- package/dist/storage/limits.js +17 -0
- package/dist/storage/maintenance-auth.d.ts +20 -0
- package/dist/storage/maintenance-auth.js +24 -0
- package/dist/storage/maintenance.d.ts +11 -0
- package/dist/storage/maintenance.js +67 -0
- package/dist/storage/neon.d.ts +4 -0
- package/dist/storage/neon.js +318 -0
- package/dist/storage/operator.d.ts +11 -0
- package/dist/storage/operator.js +30 -0
- package/dist/storage/provider.d.ts +93 -0
- package/dist/storage/provider.js +36 -0
- package/dist/storage/sessions.d.ts +184 -0
- package/dist/storage/sessions.js +688 -0
- package/dist/storage/tables.d.ts +54 -0
- package/dist/storage/tables.js +205 -0
- package/dist/storage/transfers.d.ts +16 -0
- package/dist/storage/transfers.js +153 -0
- package/dist/storage/writes.d.ts +7 -0
- package/dist/storage/writes.js +88 -0
- package/dist/telegram.d.ts +35 -0
- package/dist/telegram.js +173 -0
- package/dist/user-identity.d.ts +28 -0
- package/dist/user-identity.js +106 -0
- package/dist/user.d.ts +75 -0
- package/dist/user.js +111 -0
- package/dist/warehouse-backed.d.ts +6 -0
- package/dist/warehouse-backed.js +495 -0
- package/dist/webhook-token.d.ts +11 -0
- package/dist/webhook-token.js +18 -0
- package/dist/webhooks.d.ts +40 -0
- package/dist/webhooks.js +55 -0
- package/dist/wire.d.ts +10 -0
- package/dist/wire.js +35 -0
- package/dist/workflow-runtime.d.ts +116 -0
- package/dist/workflow-runtime.js +109 -0
- package/dist/workflow-topics.d.ts +28 -0
- package/dist/workflow-topics.js +28 -0
- package/dist/workflow.d.ts +284 -0
- package/dist/workflow.js +259 -0
- package/dist/workflows.d.ts +24 -0
- package/dist/workflows.js +18 -0
- package/package.json +127 -4
package/dist/wire.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Schema, SchemaTransformation } from "effect";
|
|
2
|
+
/** An unknown-key message names at most this many accepted keys and counts the rest. */
|
|
3
|
+
const MAX_LISTED_KEYS = 30;
|
|
4
|
+
/**
|
|
5
|
+
* `Unknown operator. Expected one of: eq, ne, in`: what a closed struct reports for a key it does
|
|
6
|
+
* not declare, so that a caller can correct the key without guessing. Long lists are cut short.
|
|
7
|
+
*/
|
|
8
|
+
export function expectedOneOf(problem, accepted) {
|
|
9
|
+
if (accepted.length === 0) {
|
|
10
|
+
return `${problem}; there are none`;
|
|
11
|
+
}
|
|
12
|
+
const listed = accepted.slice(0, MAX_LISTED_KEYS).join(", ");
|
|
13
|
+
const rest = accepted.length - MAX_LISTED_KEYS;
|
|
14
|
+
return `${problem}. Expected one of: ${listed}${rest > 0 ? `, and ${rest} more` : ""}`;
|
|
15
|
+
}
|
|
16
|
+
/** A closed wire object with explicit key mappings and an unchanged decoded TypeScript shape. */
|
|
17
|
+
export function wireStruct(fields, mapping, unknownKey = "Unknown key") {
|
|
18
|
+
const codec = Schema.Struct(fields).pipe(Schema.encodeKeys(mapping));
|
|
19
|
+
const encodedFields = Object.fromEntries(Object.entries(fields).map(([key, field]) => [
|
|
20
|
+
mapping[key] ?? key,
|
|
21
|
+
field,
|
|
22
|
+
]));
|
|
23
|
+
const encodedKeys = Object.keys(encodedFields);
|
|
24
|
+
const unknown = Schema.String.check(Schema.isPattern(new RegExp(`^(?!(?:${encodedKeys.join("|")})$)`)));
|
|
25
|
+
const reverse = Object.fromEntries(Object.entries(mapping).map(([key, value]) => [value, key]));
|
|
26
|
+
const rename = (value, keys) => Object.fromEntries(Object.entries(value).map(([key, child]) => [keys[key] ?? key, child]));
|
|
27
|
+
const encoded = Schema.StructWithRest(Schema.Struct(encodedFields), [
|
|
28
|
+
Schema.Record(unknown, Schema.Never.annotate({ message: expectedOneOf(unknownKey, encodedKeys) })),
|
|
29
|
+
]);
|
|
30
|
+
const decoded = Schema.toType(codec);
|
|
31
|
+
return encoded.pipe(Schema.decodeTo(decoded, SchemaTransformation.transform({
|
|
32
|
+
decode: (value) => rename(value, reverse),
|
|
33
|
+
encode: (value) => rename(value, mapping),
|
|
34
|
+
})));
|
|
35
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { Effect } from "effect";
|
|
2
|
+
import type { AgentTaskResult, AgentTaskStart, AgentTaskStarted } from "./agent-task-contract.js";
|
|
3
|
+
import type { Connection } from "./connection.js";
|
|
4
|
+
import type { Files } from "./files.js";
|
|
5
|
+
import type { OntologyActions, OntologyReads, OntologyWrites } from "./runtime.js";
|
|
6
|
+
import type { StartRecoveryInput, StartRecoveryOutcome } from "./start-recovery-contract.js";
|
|
7
|
+
import type { WorkflowReservation } from "./runtime/workflow-admission.js";
|
|
8
|
+
/**
|
|
9
|
+
* The ontology service's workflow runtime, shared through `globalThis` so that every copy of this
|
|
10
|
+
* module a bundler makes sees the same one. This module imports none of the Workflow SDK: the
|
|
11
|
+
* service reaches it, and so does every process that bundles the service, such as the platform's
|
|
12
|
+
* backend on another SDK major; `installWorkflowRuntime()` in the `server` entry loads the SDK.
|
|
13
|
+
*
|
|
14
|
+
* Binding: the ontology service installs a {@link WorkflowBinding} when it builds its routes; the
|
|
15
|
+
* step callback that `ontologyWorkflows()` mounts builds the service first when nothing has. Inside
|
|
16
|
+
* a `"use step"` function, `run(effect)` reads the run from the Workflow SDK's step context (an
|
|
17
|
+
* AsyncLocalStorage the SDK sets around every step), and the binding checks the run's workflow,
|
|
18
|
+
* resolves its user and runs the effect with the ontology runtime bound to it.
|
|
19
|
+
*/
|
|
20
|
+
export { WORKFLOW_BASE_PATH } from "./workflow-topics.js";
|
|
21
|
+
/** The Workflow SDK's routes below the base path: `flow`, `step` and `webhook/<token>`. */
|
|
22
|
+
export declare const WORKFLOW_ROUTE_BASE = "/.well-known/workflow/v1";
|
|
23
|
+
/** What a step's effect may require: the ontology runtime, its actions and its connections. */
|
|
24
|
+
export type WorkflowStepServices = OntologyReads | OntologyWrites | OntologyActions | Connection<string> | Files;
|
|
25
|
+
/** The step that calls `run`, as the Workflow SDK's step context names it. */
|
|
26
|
+
export interface WorkflowStepContext {
|
|
27
|
+
/** The SDK's id of the run's workflow function, as the step's queue message names it. */
|
|
28
|
+
readonly workflowName: string;
|
|
29
|
+
readonly workflowRunId: string;
|
|
30
|
+
readonly stepId: string;
|
|
31
|
+
readonly attempt: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Runs a step's effect as the workflow user of the run's workflow, and the steps of `agentTask`: its
|
|
35
|
+
* start, which hands the agent the task, and its expiry, when the task's timeout passed first.
|
|
36
|
+
*/
|
|
37
|
+
export interface WorkflowBinding {
|
|
38
|
+
/** Checks that an authenticated queue delivery names a workflow this ontology declares. */
|
|
39
|
+
readonly admitWorkflow?: (workflowName: string) => void;
|
|
40
|
+
readonly run: (step: WorkflowStepContext, effect: Effect.Effect<unknown, unknown, WorkflowStepServices>) => Promise<unknown>;
|
|
41
|
+
readonly startAgentTask: (step: WorkflowStepContext, input: AgentTaskStart) => Promise<AgentTaskStarted>;
|
|
42
|
+
readonly expireAgentTask: (step: WorkflowStepContext, taskId: string) => Promise<AgentTaskResult>;
|
|
43
|
+
/** One sweep of the pending action-trigger starts, for the platform's start recovery run. */
|
|
44
|
+
readonly recoverStarts: (step: WorkflowStepContext, input: StartRecoveryInput) => Promise<StartRecoveryOutcome>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The platform's own workflow functions, which `ontologyWorkflows()` writes beside the workspace's
|
|
48
|
+
* and the Workflow SDK compiles with them. The generated Nitro plugin registers them at startup,
|
|
49
|
+
* compiled, so that the service starts them like a declared workflow's `run`.
|
|
50
|
+
*/
|
|
51
|
+
export interface PlatformWorkflows {
|
|
52
|
+
/** Sleeps, then starts the pending starts an action's request left; see `start-recovery.ts`. */
|
|
53
|
+
readonly recoverStarts: (...args: Array<never>) => Promise<unknown>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The Workflow SDK's `start`, world and `resumeHook`, loaded on first use. {@link installWorkflowRuntime}
|
|
57
|
+
* registers them for the service's workflow routes: the service itself imports none of the Workflow
|
|
58
|
+
* SDK, so a process that bundles the service without workflows, such as the platform's backend,
|
|
59
|
+
* carries none of it.
|
|
60
|
+
*/
|
|
61
|
+
export interface WorkflowSdk {
|
|
62
|
+
readonly allocateRun?: () => Promise<WorkflowReservation>;
|
|
63
|
+
/** Installs admission around the world's decoded queue handler, before the flow handler loads. */
|
|
64
|
+
readonly prepareCallback?: () => Promise<void>;
|
|
65
|
+
readonly start: (workflow: unknown, args: Array<unknown>, options: {
|
|
66
|
+
readonly namespace: string;
|
|
67
|
+
readonly attributes?: Readonly<Record<string, string>>;
|
|
68
|
+
readonly reservation?: WorkflowReservation;
|
|
69
|
+
}) => Promise<{
|
|
70
|
+
readonly runId: string;
|
|
71
|
+
}>;
|
|
72
|
+
readonly world: () => Promise<unknown>;
|
|
73
|
+
/** Hydrate only an error payload; inputs and outputs stay unresolved. */
|
|
74
|
+
readonly hydrateError?: (value: unknown, run: {
|
|
75
|
+
readonly runId: string;
|
|
76
|
+
readonly deploymentId?: string;
|
|
77
|
+
}, kind: "step" | "run") => Promise<unknown>;
|
|
78
|
+
/** `resumeHook` from `workflow/api`: it rejects with `HookNotFoundError` for a gone hook. */
|
|
79
|
+
readonly resumeHook: (token: string, payload: unknown) => Promise<unknown>;
|
|
80
|
+
}
|
|
81
|
+
/** Registers the Workflow SDK for the service's workflow routes; the first registration stays. */
|
|
82
|
+
export declare function setWorkflowSdk(sdk: WorkflowSdk): void;
|
|
83
|
+
/** Installs the binding of the service that serves this process's runs; the latest one wins. */
|
|
84
|
+
export declare function setWorkflowBinding(binding: WorkflowBinding | undefined): void;
|
|
85
|
+
export declare function workflowBinding(): WorkflowBinding | undefined;
|
|
86
|
+
/** Registers the platform's compiled workflow functions; the latest registration wins. */
|
|
87
|
+
export declare function setPlatformWorkflows(workflows: PlatformWorkflows | undefined): void;
|
|
88
|
+
/** The platform's workflow functions as the generated plugin registered them; `undefined` before. */
|
|
89
|
+
export declare function platformWorkflows(): PlatformWorkflows | undefined;
|
|
90
|
+
/** The Workflow SDK as `installWorkflowRuntime()` registered it; `undefined` before. */
|
|
91
|
+
export declare function workflowSdk(): WorkflowSdk | undefined;
|
|
92
|
+
/** `run` was called where no step runs: in a `"use workflow"` body or outside any workflow. */
|
|
93
|
+
export declare class WorkflowStepRequired extends Error {
|
|
94
|
+
constructor();
|
|
95
|
+
}
|
|
96
|
+
/** The step that is executing; throws outside a step. */
|
|
97
|
+
export declare function currentWorkflowStep(): WorkflowStepContext | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* Runs an Effect inside a `"use step"` function with the ontology runtime provided and bound to the
|
|
100
|
+
* run's workflow user: entity handles (`Lead.find`, `Lead.actions.addNote(…)`) and the workflow's
|
|
101
|
+
* connections work as in an action handler, with each read and action checked against the
|
|
102
|
+
* workflow user's permissions and recorded in history like any caller's. A failure rejects the
|
|
103
|
+
* promise, so the SDK records a failed step; a refusal that would repeat (a missing permission, a
|
|
104
|
+
* rejected action, an invalid input) is marked fatal and not retried. The rejection carries a
|
|
105
|
+
* sanitized message and the service logs the full cause. Outside a step it throws
|
|
106
|
+
* {@link WorkflowStepRequired}.
|
|
107
|
+
*/
|
|
108
|
+
export declare function run<A, E>(effect: Effect.Effect<A, E, WorkflowStepServices>): Promise<A>;
|
|
109
|
+
/**
|
|
110
|
+
* The step that is executing and the binding of the service that serves it. Throws
|
|
111
|
+
* {@link WorkflowStepRequired} outside a step, and before any service bound this process's runs.
|
|
112
|
+
*/
|
|
113
|
+
export declare function boundStep(): {
|
|
114
|
+
readonly binding: WorkflowBinding;
|
|
115
|
+
readonly step: WorkflowStepContext;
|
|
116
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { deploymentFromEnv, requireDeploymentCapability } from "./deployment.js";
|
|
2
|
+
/**
|
|
3
|
+
* The ontology service's workflow runtime, shared through `globalThis` so that every copy of this
|
|
4
|
+
* module a bundler makes sees the same one. This module imports none of the Workflow SDK: the
|
|
5
|
+
* service reaches it, and so does every process that bundles the service, such as the platform's
|
|
6
|
+
* backend on another SDK major; `installWorkflowRuntime()` in the `server` entry loads the SDK.
|
|
7
|
+
*
|
|
8
|
+
* Binding: the ontology service installs a {@link WorkflowBinding} when it builds its routes; the
|
|
9
|
+
* step callback that `ontologyWorkflows()` mounts builds the service first when nothing has. Inside
|
|
10
|
+
* a `"use step"` function, `run(effect)` reads the run from the Workflow SDK's step context (an
|
|
11
|
+
* AsyncLocalStorage the SDK sets around every step), and the binding checks the run's workflow,
|
|
12
|
+
* resolves its user and runs the effect with the ontology runtime bound to it.
|
|
13
|
+
*/
|
|
14
|
+
export { WORKFLOW_BASE_PATH } from "./workflow-topics.js";
|
|
15
|
+
/** The Workflow SDK's routes below the base path: `flow`, `step` and `webhook/<token>`. */
|
|
16
|
+
export const WORKFLOW_ROUTE_BASE = "/.well-known/workflow/v1";
|
|
17
|
+
const BINDING = Symbol.for("@segmentstream/ontology/workflow-binding");
|
|
18
|
+
const SDK = Symbol.for("@segmentstream/ontology/workflow-sdk");
|
|
19
|
+
const PLATFORM = Symbol.for("@segmentstream/ontology/platform-workflows");
|
|
20
|
+
const globals = globalThis;
|
|
21
|
+
/** Registers the Workflow SDK for the service's workflow routes; the first registration stays. */
|
|
22
|
+
export function setWorkflowSdk(sdk) {
|
|
23
|
+
globals[SDK] ??= sdk;
|
|
24
|
+
}
|
|
25
|
+
/** Installs the binding of the service that serves this process's runs; the latest one wins. */
|
|
26
|
+
export function setWorkflowBinding(binding) {
|
|
27
|
+
globals[BINDING] = binding;
|
|
28
|
+
}
|
|
29
|
+
export function workflowBinding() {
|
|
30
|
+
return globals[BINDING];
|
|
31
|
+
}
|
|
32
|
+
/** Registers the platform's compiled workflow functions; the latest registration wins. */
|
|
33
|
+
export function setPlatformWorkflows(workflows) {
|
|
34
|
+
globals[PLATFORM] = workflows;
|
|
35
|
+
}
|
|
36
|
+
/** The platform's workflow functions as the generated plugin registered them; `undefined` before. */
|
|
37
|
+
export function platformWorkflows() {
|
|
38
|
+
return globals[PLATFORM];
|
|
39
|
+
}
|
|
40
|
+
/** The Workflow SDK as `installWorkflowRuntime()` registered it; `undefined` before. */
|
|
41
|
+
export function workflowSdk() {
|
|
42
|
+
return globals[SDK];
|
|
43
|
+
}
|
|
44
|
+
/** `run` was called where no step runs: in a `"use workflow"` body or outside any workflow. */
|
|
45
|
+
export class WorkflowStepRequired extends Error {
|
|
46
|
+
constructor() {
|
|
47
|
+
super('run(effect) runs only inside a "use step" function of a declared workflow. The ' +
|
|
48
|
+
'"use workflow" body orchestrates steps and does no I/O of its own; code outside a ' +
|
|
49
|
+
"workflow reads and changes records through the ontology service's API.");
|
|
50
|
+
this.name = "WorkflowStepRequired";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The Workflow SDK's process-wide step context: an AsyncLocalStorage the SDK keeps on
|
|
55
|
+
* `globalThis` under this symbol and runs every step inside (`@workflow/core`'s
|
|
56
|
+
* `step/context-storage`). Reading it needs no import of the SDK, which a deployed function may not
|
|
57
|
+
* be able to resolve.
|
|
58
|
+
*/
|
|
59
|
+
const STEP_CONTEXT = Symbol.for("WORKFLOW_STEP_CONTEXT_STORAGE");
|
|
60
|
+
/** The step that is executing; throws outside a step. */
|
|
61
|
+
export function currentWorkflowStep() {
|
|
62
|
+
const storage = globalThis[STEP_CONTEXT];
|
|
63
|
+
const store = storage?.getStore();
|
|
64
|
+
const step = store?.stepMetadata;
|
|
65
|
+
const run = store?.workflowMetadata;
|
|
66
|
+
// A "use workflow" body has no step metadata, and code outside a run has no store at all.
|
|
67
|
+
if (typeof step?.stepId !== "string" ||
|
|
68
|
+
typeof run?.workflowName !== "string" ||
|
|
69
|
+
typeof run.workflowRunId !== "string") {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
workflowName: run.workflowName,
|
|
74
|
+
workflowRunId: run.workflowRunId,
|
|
75
|
+
stepId: step.stepId,
|
|
76
|
+
attempt: typeof step.attempt === "number" ? step.attempt : 1,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Runs an Effect inside a `"use step"` function with the ontology runtime provided and bound to the
|
|
81
|
+
* run's workflow user: entity handles (`Lead.find`, `Lead.actions.addNote(…)`) and the workflow's
|
|
82
|
+
* connections work as in an action handler, with each read and action checked against the
|
|
83
|
+
* workflow user's permissions and recorded in history like any caller's. A failure rejects the
|
|
84
|
+
* promise, so the SDK records a failed step; a refusal that would repeat (a missing permission, a
|
|
85
|
+
* rejected action, an invalid input) is marked fatal and not retried. The rejection carries a
|
|
86
|
+
* sanitized message and the service logs the full cause. Outside a step it throws
|
|
87
|
+
* {@link WorkflowStepRequired}.
|
|
88
|
+
*/
|
|
89
|
+
export async function run(effect) {
|
|
90
|
+
const { binding, step } = boundStep();
|
|
91
|
+
return (await binding.run(step, effect));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The step that is executing and the binding of the service that serves it. Throws
|
|
95
|
+
* {@link WorkflowStepRequired} outside a step, and before any service bound this process's runs.
|
|
96
|
+
*/
|
|
97
|
+
export function boundStep() {
|
|
98
|
+
requireDeploymentCapability(deploymentFromEnv(), "workflows");
|
|
99
|
+
const step = currentWorkflowStep();
|
|
100
|
+
if (step === undefined) {
|
|
101
|
+
throw new WorkflowStepRequired();
|
|
102
|
+
}
|
|
103
|
+
const binding = workflowBinding();
|
|
104
|
+
if (binding === undefined) {
|
|
105
|
+
throw new Error("No ontology service serves workflow runs in this process; the step callback that " +
|
|
106
|
+
"ontologyWorkflows() mounts builds it first.");
|
|
107
|
+
}
|
|
108
|
+
return { binding, step };
|
|
109
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ontology's queue and callback names, shared by the build (`./nitro.ts`) and the runtime
|
|
3
|
+
* (`./service/workflows.ts`). This module imports nothing.
|
|
4
|
+
*/
|
|
5
|
+
/** The path the Workflow SDK's callbacks for the ontology's runs live under. */
|
|
6
|
+
export declare const WORKFLOW_BASE_PATH = "/api/ontology";
|
|
7
|
+
/**
|
|
8
|
+
* The queue namespace of the ontology's runs, fixed at build time. The app and the agent of the
|
|
9
|
+
* same deployment run their own workflows on the SDK's default topics and on `eve<hex>`; this one
|
|
10
|
+
* keeps the ontology's messages on `__ontology_wkf_workflow_*`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const ONTOLOGY_QUEUE_NAMESPACE = "ontology";
|
|
13
|
+
/** The topic prefix of the ontology's queue: `__ontology_wkf_workflow_`. */
|
|
14
|
+
export declare const ONTOLOGY_QUEUE_PREFIX = "__ontology_wkf_workflow_";
|
|
15
|
+
/**
|
|
16
|
+
* The route of the Workflow SDK's queue callback, below the ontology service's path. Since
|
|
17
|
+
* Workflow SDK 5 a run's steps execute inside the flow callback and background steps come back on
|
|
18
|
+
* the workflow topic: there is no step route.
|
|
19
|
+
*/
|
|
20
|
+
export declare const WORKFLOW_FLOW_ROUTE = "/api/ontology/.well-known/workflow/v1/flow";
|
|
21
|
+
/** The queue trigger of the flow function: the ontology's namespaced workflow topic. */
|
|
22
|
+
export declare const WORKFLOW_QUEUE_TRIGGER: {
|
|
23
|
+
readonly type: "queue/v2beta";
|
|
24
|
+
readonly topic: "__ontology_wkf_workflow_*";
|
|
25
|
+
readonly consumer: "default";
|
|
26
|
+
readonly retryAfterSeconds: 5;
|
|
27
|
+
readonly initialDelaySeconds: 0;
|
|
28
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ontology's queue and callback names, shared by the build (`./nitro.ts`) and the runtime
|
|
3
|
+
* (`./service/workflows.ts`). This module imports nothing.
|
|
4
|
+
*/
|
|
5
|
+
/** The path the Workflow SDK's callbacks for the ontology's runs live under. */
|
|
6
|
+
export const WORKFLOW_BASE_PATH = "/api/ontology";
|
|
7
|
+
/**
|
|
8
|
+
* The queue namespace of the ontology's runs, fixed at build time. The app and the agent of the
|
|
9
|
+
* same deployment run their own workflows on the SDK's default topics and on `eve<hex>`; this one
|
|
10
|
+
* keeps the ontology's messages on `__ontology_wkf_workflow_*`.
|
|
11
|
+
*/
|
|
12
|
+
export const ONTOLOGY_QUEUE_NAMESPACE = "ontology";
|
|
13
|
+
/** The topic prefix of the ontology's queue: `__ontology_wkf_workflow_`. */
|
|
14
|
+
export const ONTOLOGY_QUEUE_PREFIX = `__${ONTOLOGY_QUEUE_NAMESPACE}_wkf_workflow_`;
|
|
15
|
+
/**
|
|
16
|
+
* The route of the Workflow SDK's queue callback, below the ontology service's path. Since
|
|
17
|
+
* Workflow SDK 5 a run's steps execute inside the flow callback and background steps come back on
|
|
18
|
+
* the workflow topic: there is no step route.
|
|
19
|
+
*/
|
|
20
|
+
export const WORKFLOW_FLOW_ROUTE = `${WORKFLOW_BASE_PATH}/.well-known/workflow/v1/flow`;
|
|
21
|
+
/** The queue trigger of the flow function: the ontology's namespaced workflow topic. */
|
|
22
|
+
export const WORKFLOW_QUEUE_TRIGGER = {
|
|
23
|
+
type: "queue/v2beta",
|
|
24
|
+
topic: `${ONTOLOGY_QUEUE_PREFIX}*`,
|
|
25
|
+
consumer: "default",
|
|
26
|
+
retryAfterSeconds: 5,
|
|
27
|
+
initialDelaySeconds: 0,
|
|
28
|
+
};
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import type { Schema } from "effect";
|
|
2
|
+
import type { ActionInput, ActionResult, AnyAction } from "./action.js";
|
|
3
|
+
import type { AnyConnectionHandle } from "./connection.js";
|
|
4
|
+
import type { ActionHandle, AnyStoredEntity } from "./entity.js";
|
|
5
|
+
import type { Edit } from "./runtime/history.js";
|
|
6
|
+
import type { Principal } from "./runtime.js";
|
|
7
|
+
import type { WebhookSignatureScheme } from "./webhooks.js";
|
|
8
|
+
/** Marks the values `workflow(…)` returns, so that `check` can tell them from look-alikes. */
|
|
9
|
+
export declare const WorkflowTypeId: unique symbol;
|
|
10
|
+
/** Marks the values trigger constructors such as `cron(…)` and `after(…)` return. */
|
|
11
|
+
export declare const WorkflowTriggerTypeId: unique symbol;
|
|
12
|
+
/** The most workflows one ontology may declare. */
|
|
13
|
+
export declare const MAX_WORKFLOWS = 50;
|
|
14
|
+
/** The most action triggers, `after(…)`, one ontology may declare across its workflows. */
|
|
15
|
+
export declare const MAX_ACTION_TRIGGERS = 20;
|
|
16
|
+
/**
|
|
17
|
+
* A cron trigger, `cron(name, expression, { description, input })`: the platform writes it into
|
|
18
|
+
* the workspace deployment's crons, and each invocation starts the workflow with `input`. Five
|
|
19
|
+
* fields, read in UTC.
|
|
20
|
+
*/
|
|
21
|
+
export interface CronTrigger<Name extends string = string, Input = unknown> {
|
|
22
|
+
readonly [WorkflowTriggerTypeId]: typeof WorkflowTriggerTypeId;
|
|
23
|
+
readonly kind: "cron";
|
|
24
|
+
/** A camelCase name, unique within its workflow: `weekdayMorning`. */
|
|
25
|
+
readonly name: Name;
|
|
26
|
+
/** When and why the workflow starts, for people, agents and the catalog. */
|
|
27
|
+
readonly description: string;
|
|
28
|
+
/** minute hour day-of-month month day-of-week, in UTC: `"0 8 * * 1-5"`. */
|
|
29
|
+
readonly cron: string;
|
|
30
|
+
/** The workflow's input, in TypeScript names; `undefined` when the trigger declares none. */
|
|
31
|
+
readonly input: Input | undefined;
|
|
32
|
+
}
|
|
33
|
+
export interface CronOptions<Input = unknown> {
|
|
34
|
+
/** Required, like every declaration: when and why the workflow starts. */
|
|
35
|
+
readonly description: string;
|
|
36
|
+
/** The workflow's input for this trigger. May be omitted when the workflow's input accepts `{}`. */
|
|
37
|
+
readonly input?: Input;
|
|
38
|
+
}
|
|
39
|
+
/** Declares a cron trigger; list it in `workflow(name, { triggers })`. UTC, five fields. */
|
|
40
|
+
export declare function cron<const Name extends string, Input = unknown>(name: Name, expression: string, options: CronOptions<Input>): CronTrigger<Name, Input>;
|
|
41
|
+
/**
|
|
42
|
+
* One committed run of an action, as an action trigger's `when` and `input` receive it: the facts
|
|
43
|
+
* history stores, as one value. `input` and `result` are typed from the action handle; for a trigger
|
|
44
|
+
* on an entity they are `unknown`.
|
|
45
|
+
*/
|
|
46
|
+
export interface ActionEvent<Input = unknown, Result = unknown> {
|
|
47
|
+
/** The qualified action as history records it: `<entity>.<action>`. */
|
|
48
|
+
readonly action: string;
|
|
49
|
+
/** Shared by every history row the run wrote, and carried by the run's `startedBy`. */
|
|
50
|
+
readonly actionId: string;
|
|
51
|
+
/** When the action ran, ISO 8601. */
|
|
52
|
+
readonly at: string;
|
|
53
|
+
/** Who ran the action, as after-commit hooks receive it. */
|
|
54
|
+
readonly principal: Principal;
|
|
55
|
+
/** The decoded input, in TypeScript names. */
|
|
56
|
+
readonly input: Input;
|
|
57
|
+
/** What the action's handler returned. */
|
|
58
|
+
readonly result: Result;
|
|
59
|
+
/** Every change the action made, as the action response lists them. */
|
|
60
|
+
readonly edits: ReadonlyArray<Edit>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The record of the trigger's entity an action edited: its id, and the stored record before and
|
|
64
|
+
* after the action. `before` is `undefined` on a create, `after` on a delete. Only stored
|
|
65
|
+
* properties and relationship ids; warehouse-backed properties are absent.
|
|
66
|
+
*/
|
|
67
|
+
export interface TriggerRecord<T = unknown> {
|
|
68
|
+
readonly record: string;
|
|
69
|
+
readonly before: T | undefined;
|
|
70
|
+
readonly after: T | undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A synchronous function of an action trigger: no `await`, no effects, no entity handles. It runs
|
|
74
|
+
* inside the action's transaction and reads only the event and the record.
|
|
75
|
+
*/
|
|
76
|
+
export type TriggerFunction<Event, T, Out> = (event: Event, record: TriggerRecord<T>) => Out;
|
|
77
|
+
/**
|
|
78
|
+
* An action trigger, `after(name, target, { description, when, input })`: starts the workflow after
|
|
79
|
+
* an action of `entity` commits, `action` or any of them. `when` and `input` are code: the manifest
|
|
80
|
+
* records the kind, the name, the description, the entity and the action, never the functions.
|
|
81
|
+
*/
|
|
82
|
+
export interface ActionTrigger<Name extends string = string, Input = unknown> {
|
|
83
|
+
readonly [WorkflowTriggerTypeId]: typeof WorkflowTriggerTypeId;
|
|
84
|
+
readonly kind: "action";
|
|
85
|
+
/** A camelCase name, unique within its workflow: `qualified`. */
|
|
86
|
+
readonly name: Name;
|
|
87
|
+
/** Which actions start the workflow and why, for people, agents and the catalog. */
|
|
88
|
+
readonly description: string;
|
|
89
|
+
/** The entity's wire name, `lead`; empty when the target is not a handle, which `check` reports. */
|
|
90
|
+
readonly entity: string;
|
|
91
|
+
/** The action's wire name, `change_status`; `undefined` for a trigger on the whole entity. */
|
|
92
|
+
readonly action: string | undefined;
|
|
93
|
+
/** The handle as declared, for `check`. */
|
|
94
|
+
readonly target: unknown;
|
|
95
|
+
/** Whether the run starts; omitted means always. */
|
|
96
|
+
readonly when: TriggerFunction<ActionEvent, unknown, boolean> | undefined;
|
|
97
|
+
/** The workflow's input, in TypeScript names; omitted means `{}`. */
|
|
98
|
+
readonly input: TriggerFunction<ActionEvent, unknown, Input> | undefined;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Where a webhook's deliveries are checked: a provider's signature format and the workspace secret
|
|
102
|
+
* that holds its signing secret. Without one, the webhook's URL ends in a token.
|
|
103
|
+
*/
|
|
104
|
+
export interface WebhookSignature {
|
|
105
|
+
readonly scheme: WebhookSignatureScheme;
|
|
106
|
+
/** A workspace secret's name, such as `stripe-webhook-signing-secret`; its value stays in the platform. */
|
|
107
|
+
readonly secret: string;
|
|
108
|
+
}
|
|
109
|
+
/** Meta's registration handshake; the verify token is a workspace secret, separate from the app secret. */
|
|
110
|
+
export interface WebhookVerification {
|
|
111
|
+
readonly scheme: "meta";
|
|
112
|
+
readonly verifyToken: string;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* A webhook trigger, `webhook(name, { description, signature, headers })`: the ontology service
|
|
116
|
+
* starts the workflow for each genuine delivery to `/api/webhooks/<name>`, with the delivery as its
|
|
117
|
+
* input. The workflow's `input` is `webhookDelivery`.
|
|
118
|
+
*/
|
|
119
|
+
export interface WebhookTrigger<Name extends string = string> {
|
|
120
|
+
readonly [WorkflowTriggerTypeId]: typeof WorkflowTriggerTypeId;
|
|
121
|
+
readonly kind: "webhook";
|
|
122
|
+
/** A camelCase name, unique among the ontology's webhooks; its wire name is the URL's segment. */
|
|
123
|
+
readonly name: Name;
|
|
124
|
+
/** What the provider sends and why, for people, agents and the catalog. */
|
|
125
|
+
readonly description: string;
|
|
126
|
+
/** How deliveries are checked; `undefined` for a token in the URL. */
|
|
127
|
+
readonly signature: WebhookSignature | undefined;
|
|
128
|
+
/** Optional registration handshake, answered without starting the workflow. */
|
|
129
|
+
readonly verification?: WebhookVerification | undefined;
|
|
130
|
+
/** Lowercase names of the request headers the delivery carries. */
|
|
131
|
+
readonly headers: ReadonlyArray<string>;
|
|
132
|
+
}
|
|
133
|
+
export interface WebhookOptions {
|
|
134
|
+
/** Required, like every declaration: what the provider sends and why. */
|
|
135
|
+
readonly description: string;
|
|
136
|
+
/**
|
|
137
|
+
* The provider's signature format and the workspace secret holding its signing secret. Omit it
|
|
138
|
+
* for a provider that signs nothing: the URL then ends in a token.
|
|
139
|
+
*/
|
|
140
|
+
readonly signature?: WebhookSignature;
|
|
141
|
+
/** Meta's GET registration handshake. Requires a Meta signature for POST deliveries. */
|
|
142
|
+
readonly verification?: WebhookVerification;
|
|
143
|
+
/** Lowercase request headers to pass to the workflow, at most ten: `["x-event-type"]`. */
|
|
144
|
+
readonly headers?: ReadonlyArray<string>;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Declares a webhook trigger; list it in `workflow(name, { input: webhookDelivery, triggers })`.
|
|
148
|
+
* A workflow with a webhook trigger has only webhook triggers.
|
|
149
|
+
*/
|
|
150
|
+
export declare function webhook<const Name extends string>(name: Name, options: WebhookOptions): WebhookTrigger<Name>;
|
|
151
|
+
/**
|
|
152
|
+
* What starts a workflow on its own. A discriminated union on `kind`: `cron`, `action` and
|
|
153
|
+
* `webhook`; other kinds are additions.
|
|
154
|
+
*/
|
|
155
|
+
export type WorkflowTrigger<Input = unknown> = CronTrigger<string, Input> | ActionTrigger<string, Input> | WebhookTrigger;
|
|
156
|
+
export interface AfterOptions<Event, T, Input> {
|
|
157
|
+
/** Required, like every declaration: which actions start the workflow and why. */
|
|
158
|
+
readonly description: string;
|
|
159
|
+
/** Whether the run starts, from the event and the record; synchronous. Omitted means always. */
|
|
160
|
+
readonly when?: TriggerFunction<Event, T, boolean>;
|
|
161
|
+
/**
|
|
162
|
+
* The workflow's input, from the event and the record; synchronous. Omitted means `{}`, which the
|
|
163
|
+
* workflow's input must accept.
|
|
164
|
+
*/
|
|
165
|
+
readonly input?: TriggerFunction<Event, T, Input>;
|
|
166
|
+
}
|
|
167
|
+
/** An authored action handle, `Lead.actions.changeStatus`. */
|
|
168
|
+
export type AnyActionHandle = AnyAction & ActionHandle;
|
|
169
|
+
/** The record type of an action handle's entity. */
|
|
170
|
+
type HandleRecord<A> = A extends ActionHandle<string, string, infer T> ? T : unknown;
|
|
171
|
+
/**
|
|
172
|
+
* Declares an action trigger; list it in `workflow(name, { triggers })`. The target is an action
|
|
173
|
+
* handle, `Lead.actions.changeStatus`, or an entity handle, `Lead`, for any of its actions, authored
|
|
174
|
+
* or generated. A trigger does not fire for an action the workflow's own user ran.
|
|
175
|
+
*/
|
|
176
|
+
export declare function after<const Name extends string, A extends AnyActionHandle, Input = unknown>(name: Name, target: A, options: AfterOptions<ActionEvent<ActionInput<A>, ActionResult<A>>, HandleRecord<A>, Input>): ActionTrigger<Name, Input>;
|
|
177
|
+
export declare function after<const Name extends string, E extends AnyStoredEntity, Input = unknown>(name: Name, target: E, options: AfterOptions<ActionEvent, E["Type"], Input>): ActionTrigger<Name, Input>;
|
|
178
|
+
/** The bounds of {@link changed}: the value before, the value after, or both. */
|
|
179
|
+
export interface ChangedBounds<V> {
|
|
180
|
+
/** The value before the action; `null` matches a record that had none or did not exist. */
|
|
181
|
+
readonly from?: V | null;
|
|
182
|
+
/** The value after the action; `null` matches a record that has none or was deleted. */
|
|
183
|
+
readonly to?: V | null;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* A `when` predicate: true when the record's `field` differs before and after the action and
|
|
187
|
+
* matches the bounds given. A missing record or value counts as no value, so a create that sets
|
|
188
|
+
* `status` changed it, and `{ to: "qualified" }` does not fire when it was already qualified.
|
|
189
|
+
*/
|
|
190
|
+
export declare function changed<T extends object, K extends keyof T & string>(field: K, bounds?: ChangedBounds<NoInfer<T[K]>>): TriggerFunction<unknown, T, boolean>;
|
|
191
|
+
/** Whether a function is declared `async`; action trigger functions must be synchronous. */
|
|
192
|
+
export declare function isAsyncFunction(value: unknown): boolean;
|
|
193
|
+
/** Whether a value was declared with a trigger constructor such as `cron(…)` or `after(…)`. */
|
|
194
|
+
export declare function isWorkflowTrigger(value: unknown): value is WorkflowTrigger;
|
|
195
|
+
/**
|
|
196
|
+
* Who started a run, as the ontology service passes it to the workflow function as its second
|
|
197
|
+
* argument and records it in plaintext run attributes: a trigger, a member through
|
|
198
|
+
* `POST /api/ontology/workflows/:workflow/start`, or the platform on behalf of a person.
|
|
199
|
+
*/
|
|
200
|
+
export interface WorkflowRunContext {
|
|
201
|
+
readonly startedBy: {
|
|
202
|
+
readonly kind: "trigger";
|
|
203
|
+
/** The trigger's kind; runs started before it was recorded omit it. */
|
|
204
|
+
readonly triggerKind?: "cron" | "action" | "webhook";
|
|
205
|
+
/** `<workflow>.<trigger>`, in wire names. */
|
|
206
|
+
readonly trigger: string;
|
|
207
|
+
/** For an action trigger: the action whose commit started the run. */
|
|
208
|
+
readonly actionId?: string;
|
|
209
|
+
/** For an action trigger evaluated per edited record: that record. */
|
|
210
|
+
readonly recordId?: string;
|
|
211
|
+
} | {
|
|
212
|
+
readonly kind: "member";
|
|
213
|
+
readonly userId: string;
|
|
214
|
+
} | {
|
|
215
|
+
readonly kind: "platform";
|
|
216
|
+
readonly userId: string | null;
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/** The function a workflow runs: a `"use workflow"` function of the decoded input. */
|
|
220
|
+
export type WorkflowFunction<Input> = (input: Input, context: WorkflowRunContext) => Promise<unknown>;
|
|
221
|
+
type AnyInputSchema = Schema.Codec<any, any>;
|
|
222
|
+
type InputOf<S> = S extends Schema.Codec<infer A, unknown> ? A : Record<string, never>;
|
|
223
|
+
export interface WorkflowOptions<S extends AnyInputSchema | undefined = undefined> {
|
|
224
|
+
/** Required, like every declaration: what the workflow does and why. */
|
|
225
|
+
readonly description: string;
|
|
226
|
+
/**
|
|
227
|
+
* The declared role, other than `member`, whose permissions the workflow's runs hold together
|
|
228
|
+
* with member's. Its runs act as the workflow's own service user.
|
|
229
|
+
*/
|
|
230
|
+
readonly role: string;
|
|
231
|
+
/** A `Schema.Struct` of the workflow's input. Omitted means `{}`. */
|
|
232
|
+
readonly input?: S;
|
|
233
|
+
/** The `"use workflow"` function. It receives the decoded input. */
|
|
234
|
+
readonly run: WorkflowFunction<InputOf<S>>;
|
|
235
|
+
/**
|
|
236
|
+
* What starts the workflow on its own: `cron(…)`, `after(…)` or `webhook(…)`. None means the
|
|
237
|
+
* app, the CLI or another workflow.
|
|
238
|
+
*/
|
|
239
|
+
readonly triggers?: ReadonlyArray<WorkflowTrigger>;
|
|
240
|
+
/** Connections a step calls directly, each listed in `defineOntology({ connections })`. */
|
|
241
|
+
readonly connections?: ReadonlyArray<AnyConnectionHandle>;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* A workflow: a durable process written with the Vercel Workflow SDK, run by the ontology service
|
|
245
|
+
* as its own keyless service user holding `role`. The declaration only records; `check` and the
|
|
246
|
+
* sandbox evaluation of `index.ts` never call `run`.
|
|
247
|
+
*/
|
|
248
|
+
export interface Workflow<Name extends string = string, Input = unknown> {
|
|
249
|
+
readonly [WorkflowTypeId]: typeof WorkflowTypeId;
|
|
250
|
+
/** A camelCase name, unique among the ontology's workflows. It names the workflow user. */
|
|
251
|
+
readonly name: Name;
|
|
252
|
+
readonly description: string;
|
|
253
|
+
readonly role: string;
|
|
254
|
+
/** The input schema, `undefined` when the workflow takes `{}`. */
|
|
255
|
+
readonly input: Schema.Top | undefined;
|
|
256
|
+
readonly run: WorkflowFunction<Input>;
|
|
257
|
+
readonly triggers: ReadonlyArray<WorkflowTrigger>;
|
|
258
|
+
readonly connections: ReadonlyArray<AnyConnectionHandle>;
|
|
259
|
+
}
|
|
260
|
+
/** Any workflow, whatever its input. */
|
|
261
|
+
export type AnyWorkflow = Workflow<string, any>;
|
|
262
|
+
/** Declares a workflow; list it in `defineOntology({ workflows })`. */
|
|
263
|
+
export declare function workflow<const Name extends string, S extends AnyInputSchema | undefined = undefined>(name: Name, options: WorkflowOptions<S>): Workflow<Name, InputOf<S>>;
|
|
264
|
+
/** Whether a value was declared with `workflow(…)`. */
|
|
265
|
+
export declare function isWorkflow(value: unknown): value is AnyWorkflow;
|
|
266
|
+
/** Which field of a cron expression does not parse. */
|
|
267
|
+
export type CronProblem = "fields" | "minute" | "hour" | "day_of_month" | "month" | "day_of_week" | "both_days";
|
|
268
|
+
/**
|
|
269
|
+
* The first minute after `after` at which the expression fires, in UTC, within the next 366 days;
|
|
270
|
+
* `undefined` for an invalid expression or one that does not fire in that time.
|
|
271
|
+
*/
|
|
272
|
+
export declare function nextCronTime(expression: string, after: Date): Date | undefined;
|
|
273
|
+
/**
|
|
274
|
+
* Whether a valid expression names no day that exists: a day of the month no listed month has,
|
|
275
|
+
* such as `0 0 31 4 *` or `0 0 30 2 *`. The 29th of February counts: it exists in leap years.
|
|
276
|
+
*/
|
|
277
|
+
export declare function cronNeverFires(expression: string): boolean;
|
|
278
|
+
/**
|
|
279
|
+
* Checks a cron expression by the syntax Vercel crons accept: five fields, read in UTC, each `*`,
|
|
280
|
+
* numbers, ranges, steps and lists, without month or day names, and with at most one of the day
|
|
281
|
+
* fields restricted. It validates syntax only. `undefined` when it parses.
|
|
282
|
+
*/
|
|
283
|
+
export declare function cronProblem(expression: string): CronProblem | undefined;
|
|
284
|
+
export {};
|