@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
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { ActionRuntime } from "../runtime-source.js";
|
|
2
|
+
import { Effect, Schema } from "effect";
|
|
3
|
+
import type { HttpServerRequest } from "effect/unstable/http";
|
|
4
|
+
import { PermissionDenied } from "../errors.js";
|
|
5
|
+
import { type ScopedPermission } from "../permissions.js";
|
|
6
|
+
import { type Query, type QueryResult } from "../query.js";
|
|
7
|
+
import { InvalidQuery } from "../runtime/errors.js";
|
|
8
|
+
import { CurrentPrincipal } from "./authentication.js";
|
|
9
|
+
import { type CallerContext } from "./caller-context.js";
|
|
10
|
+
import type { ChatDeliveryFactory } from "./chat/delivery.js";
|
|
11
|
+
import type { AfterCommitHook } from "./config.js";
|
|
12
|
+
import type { ReplicationKick } from "./replication.js";
|
|
13
|
+
import { type ConnectionTransportFactory } from "./connections.js";
|
|
14
|
+
import { InvalidActionInput, RequestId } from "./errors.js";
|
|
15
|
+
import type { ApiPlan, PlannedAction, PlannedEntity, Traversal } from "./plan.js";
|
|
16
|
+
import type { OntologyBackend } from "./runtime-contract.js";
|
|
17
|
+
/**
|
|
18
|
+
* What the service does for a caller, whatever the transport: the reads and actions of every entity
|
|
19
|
+
* and the caller's own account. The HTTP routes and the MCP tools both call these, so a permission
|
|
20
|
+
* check, a validation or a history row never depends on how the request arrived. Each requires the
|
|
21
|
+
* caller, as {@link CurrentPrincipal}, and the request id.
|
|
22
|
+
*/
|
|
23
|
+
/** The query the runtime receives: every key present only when set, and no empty `include`. */
|
|
24
|
+
export declare function toQuery(decoded: Query): Query;
|
|
25
|
+
/**
|
|
26
|
+
* Requires `<entity>:read` on every entity a request reads. A missing one fails the whole request,
|
|
27
|
+
* before anything is read: nothing is silently left out.
|
|
28
|
+
*/
|
|
29
|
+
export declare function requireRead(entities: ReadonlyArray<string>): Effect.Effect<undefined, PermissionDenied, CurrentPrincipal>;
|
|
30
|
+
/** The deployment's OIDC token: Vercel sets it on each request, and in the environment of builds. */
|
|
31
|
+
export declare function identityToken(request: HttpServerRequest.HttpServerRequest): string | undefined;
|
|
32
|
+
/** An action call, as a transport decoded it. */
|
|
33
|
+
export interface ActionCall {
|
|
34
|
+
/** In-process verified runtime boundary (for attachment promotion), never decoded from action input. */
|
|
35
|
+
readonly runtime?: ActionRuntime;
|
|
36
|
+
/** The input as the caller sent it; the runtime validates it against the action's input schema. */
|
|
37
|
+
readonly input: unknown;
|
|
38
|
+
readonly validateOnly: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Answer with what a person confirms before the action runs, in this chat language, as the
|
|
41
|
+
* action's `confirm` describes it, instead of running it; `null` for an action without one.
|
|
42
|
+
*/
|
|
43
|
+
readonly confirm?: {
|
|
44
|
+
readonly locale: string;
|
|
45
|
+
};
|
|
46
|
+
/** The request's other action options: the idempotency key and create intent of an upload. */
|
|
47
|
+
readonly options?: {
|
|
48
|
+
readonly idempotencyKey?: string;
|
|
49
|
+
readonly createIntent?: string;
|
|
50
|
+
};
|
|
51
|
+
/** The deployment's OIDC token, which authorizes the action's connection calls. */
|
|
52
|
+
readonly identityToken: string | undefined;
|
|
53
|
+
}
|
|
54
|
+
/** What an action answers: `{ result, validation, edits }`. */
|
|
55
|
+
export interface ActionAnswer {
|
|
56
|
+
readonly result: unknown;
|
|
57
|
+
readonly validation: {
|
|
58
|
+
readonly ok: boolean;
|
|
59
|
+
readonly issues: ReadonlyArray<unknown>;
|
|
60
|
+
};
|
|
61
|
+
readonly edits: ReadonlyArray<unknown>;
|
|
62
|
+
}
|
|
63
|
+
/** The caller, as `GET /api/ontology/me` answers. */
|
|
64
|
+
export interface Caller {
|
|
65
|
+
readonly user: {
|
|
66
|
+
readonly id: string;
|
|
67
|
+
readonly name: string;
|
|
68
|
+
readonly email: string | null;
|
|
69
|
+
readonly kind: string;
|
|
70
|
+
readonly active: boolean;
|
|
71
|
+
};
|
|
72
|
+
readonly roles: ReadonlyArray<string>;
|
|
73
|
+
readonly permissions: ReadonlyArray<string>;
|
|
74
|
+
/**
|
|
75
|
+
* The permissions of `permissions` held only for the records their `where` matches, in the wire
|
|
76
|
+
* form of the manifest's `roles[].scopes`. Absent when none is scoped.
|
|
77
|
+
*/
|
|
78
|
+
readonly scopes?: ReadonlyArray<{
|
|
79
|
+
readonly permission: string;
|
|
80
|
+
readonly where: ScopedPermission["where"];
|
|
81
|
+
}>;
|
|
82
|
+
readonly authentication: {
|
|
83
|
+
readonly kind: CallerContext["kind"];
|
|
84
|
+
readonly client: {
|
|
85
|
+
readonly id: string;
|
|
86
|
+
readonly name: string;
|
|
87
|
+
} | null;
|
|
88
|
+
readonly scope: string | null;
|
|
89
|
+
};
|
|
90
|
+
readonly attribution: string | null;
|
|
91
|
+
readonly attribution_separator?: string;
|
|
92
|
+
}
|
|
93
|
+
type Backend = OntologyBackend["Service"];
|
|
94
|
+
/**
|
|
95
|
+
* The operations of a planned ontology, bound to its backend, after-commit hooks, connections and,
|
|
96
|
+
* on deployments with one, the workspace's agent.
|
|
97
|
+
*/
|
|
98
|
+
export declare function makeOperations(backend: Backend, plan: ApiPlan, hooks: ReadonlyMap<string, AfterCommitHook>, connections: ConnectionTransportFactory, replicate: ReplicationKick, chatDelivery?: ChatDeliveryFactory): {
|
|
99
|
+
/** A page of records. Requires `read` on the entity and on every entity the query reaches. */
|
|
100
|
+
find: (planned: PlannedEntity, query: Query) => Effect.Effect<QueryResult<Readonly<Record<string, unknown>>>, PermissionDenied | import("../errors.js").NotFound | InvalidQuery | import("./errors.js").WarehouseReadUnavailable, RequestId | CurrentPrincipal>;
|
|
101
|
+
/** One record. Requires `read` on the entity. */
|
|
102
|
+
get: (planned: PlannedEntity, id: string) => Effect.Effect<Readonly<Record<string, unknown>>, PermissionDenied | import("../errors.js").NotFound | InvalidQuery | import("./errors.js").WarehouseReadUnavailable, RequestId | CurrentPrincipal>;
|
|
103
|
+
/** A page of a record's history, newest first. Requires `read` on the entity. */
|
|
104
|
+
history: (planned: PlannedEntity, id: string, params: {
|
|
105
|
+
readonly after?: string;
|
|
106
|
+
readonly limit?: number;
|
|
107
|
+
}) => Effect.Effect<QueryResult<{
|
|
108
|
+
readonly kind: "create" | "update" | "delete" | "link" | "unlink";
|
|
109
|
+
readonly id: string;
|
|
110
|
+
readonly at: string;
|
|
111
|
+
readonly action: string;
|
|
112
|
+
readonly changes: {
|
|
113
|
+
readonly [x: string]: {
|
|
114
|
+
readonly before: Schema.Json;
|
|
115
|
+
readonly after: Schema.Json;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
readonly principalId: string | null;
|
|
119
|
+
readonly recordId: string;
|
|
120
|
+
readonly actionId: string;
|
|
121
|
+
readonly execution?: {
|
|
122
|
+
readonly issuer: string;
|
|
123
|
+
readonly audience: string;
|
|
124
|
+
readonly organizationId: string;
|
|
125
|
+
readonly workspaceId: string;
|
|
126
|
+
readonly subject: string;
|
|
127
|
+
readonly deploymentId: string;
|
|
128
|
+
readonly ontologyDeploymentId: string;
|
|
129
|
+
readonly servingOntologyDeploymentId: string;
|
|
130
|
+
readonly ontologyOrigin: string;
|
|
131
|
+
readonly environment: "production" | "preview";
|
|
132
|
+
readonly jobName: string | null;
|
|
133
|
+
readonly runId: string;
|
|
134
|
+
readonly executionId: string | null;
|
|
135
|
+
readonly attemptId: string;
|
|
136
|
+
readonly generation: number;
|
|
137
|
+
readonly tokenId: string;
|
|
138
|
+
readonly issuedAt: number;
|
|
139
|
+
readonly expiresAt: number;
|
|
140
|
+
} | undefined;
|
|
141
|
+
}>, PermissionDenied | import("../errors.js").NotFound | InvalidQuery, CurrentPrincipal>;
|
|
142
|
+
/** The records a relationship reaches from one record, as a page of the target entity. */
|
|
143
|
+
traverse: (planned: PlannedEntity, traversal: Traversal, id: string, query: Query) => Effect.Effect<QueryResult<Readonly<Record<string, unknown>>>, PermissionDenied | import("../errors.js").NotFound | InvalidQuery | import("./errors.js").WarehouseReadUnavailable, RequestId | CurrentPrincipal>;
|
|
144
|
+
/** Runs an action as the caller, with the action's after-commit hook and connections. */
|
|
145
|
+
runAction: (planned: PlannedEntity, { name, generated }: PlannedAction, call: ActionCall) => Effect.Effect<{
|
|
146
|
+
result: {} | null;
|
|
147
|
+
validation: {
|
|
148
|
+
ok: boolean;
|
|
149
|
+
issues: readonly {
|
|
150
|
+
readonly path: readonly (string | number)[];
|
|
151
|
+
readonly message: string;
|
|
152
|
+
}[];
|
|
153
|
+
};
|
|
154
|
+
edits: readonly {
|
|
155
|
+
readonly entity: string;
|
|
156
|
+
readonly id: string;
|
|
157
|
+
readonly kind: "create" | "update" | "delete" | "link" | "unlink";
|
|
158
|
+
readonly changes: {
|
|
159
|
+
readonly [x: string]: {
|
|
160
|
+
readonly before: Schema.Json;
|
|
161
|
+
readonly after: Schema.Json;
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
}[];
|
|
165
|
+
}, import("../errors.js").ActionError | import("../connection.js").ConnectionError | import("../runtime/errors.js").WorkflowRecoveryUnavailable | import("../runtime/errors.js").TriggerInputInvalid | InvalidActionInput, RequestId | CurrentPrincipal>;
|
|
166
|
+
/** The caller's user, roles and permissions. It needs no permission. */
|
|
167
|
+
caller: Effect.Effect<Caller, never, CurrentPrincipal>;
|
|
168
|
+
};
|
|
169
|
+
export type Operations = ReturnType<typeof makeOperations>;
|
|
170
|
+
export {};
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { Effect, Option, Schema } from "effect";
|
|
2
|
+
import { editsFromWire, generatedResultFromWire, recordFromWire } from "../authoring-records.js";
|
|
3
|
+
import { nameToWire } from "../authoring-names.js";
|
|
4
|
+
import { principalFromWire } from "../authoring.js";
|
|
5
|
+
import { ActionRejected, PermissionDenied } from "../errors.js";
|
|
6
|
+
import { toCamelCase } from "../names.js";
|
|
7
|
+
import { missingPermission, permissionOf, READ_VERB, } from "../permissions.js";
|
|
8
|
+
import { includedRelationships } from "../query.js";
|
|
9
|
+
import { InvalidQuery } from "../runtime/errors.js";
|
|
10
|
+
import { CurrentPrincipal } from "./authentication.js";
|
|
11
|
+
import { currentCaller, CurrentCaller } from "./caller-context.js";
|
|
12
|
+
import { chatAttribution } from "./chat/attribution.js";
|
|
13
|
+
import { requireRuntimeOperation } from "./mcp/runtime-policy.js";
|
|
14
|
+
import { ChatDelivery } from "../chat.js";
|
|
15
|
+
import { withoutConfirmation } from "./mcp/confirmation.js";
|
|
16
|
+
import { consumeChatEnvelope, CurrentChatCall } from "./chat/envelope.js";
|
|
17
|
+
import { ChatPostWire, RuntimeChatPostWire } from "./chat/schemas.js";
|
|
18
|
+
import { OIDC_TOKEN_HEADER } from "./connections.js";
|
|
19
|
+
import { InvalidActionInput, RequestId } from "./errors.js";
|
|
20
|
+
import { recordReads } from "./record-reads.js";
|
|
21
|
+
import { AGENT_TASK_AUTHENTICATION } from "./agent/task-caller.js";
|
|
22
|
+
/**
|
|
23
|
+
* What the service does for a caller, whatever the transport: the reads and actions of every entity
|
|
24
|
+
* and the caller's own account. The HTTP routes and the MCP tools both call these, so a permission
|
|
25
|
+
* check, a validation or a history row never depends on how the request arrived. Each requires the
|
|
26
|
+
* caller, as {@link CurrentPrincipal}, and the request id.
|
|
27
|
+
*/
|
|
28
|
+
/** The query the runtime receives: every key present only when set, and no empty `include`. */
|
|
29
|
+
export function toQuery(decoded) {
|
|
30
|
+
const { include, ...rest } = decoded;
|
|
31
|
+
return includedRelationships(include).length > 0 ? { ...rest, include } : rest;
|
|
32
|
+
}
|
|
33
|
+
function page(result) {
|
|
34
|
+
return {
|
|
35
|
+
items: result.items,
|
|
36
|
+
nextCursor: result.nextCursor ?? null,
|
|
37
|
+
...(result.projected === true ? { projected: true } : {}),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function relationshipTargets(plan) {
|
|
41
|
+
return new Map(plan.entities.map((planned) => [
|
|
42
|
+
planned.name,
|
|
43
|
+
new Map(planned.traversals.map((traversal) => [traversal.name, traversal.target])),
|
|
44
|
+
]));
|
|
45
|
+
}
|
|
46
|
+
/** Adds the entities a `where` looks into through relationship filters, at any combinator depth. */
|
|
47
|
+
function filterReads(where, targets, reads) {
|
|
48
|
+
for (const [key, condition] of Object.entries(where ?? {})) {
|
|
49
|
+
if (key === "and" || key === "or") {
|
|
50
|
+
for (const part of condition) {
|
|
51
|
+
filterReads(part, targets, reads);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else if (key === "not") {
|
|
55
|
+
filterReads(condition, targets, reads);
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
const target = targets.get(key);
|
|
59
|
+
if (target !== undefined) {
|
|
60
|
+
reads.add(target);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The entities a query on `entity` reads: the entity, the entity of every relationship it includes,
|
|
67
|
+
* and the entity of every relationship its filter looks into.
|
|
68
|
+
*/
|
|
69
|
+
function queryReads(entity, query, targets) {
|
|
70
|
+
const own = targets.get(entity) ?? new Map();
|
|
71
|
+
const reads = new Set([entity]);
|
|
72
|
+
for (const name of includedRelationships(query.include)) {
|
|
73
|
+
const target = own.get(name);
|
|
74
|
+
if (target !== undefined) {
|
|
75
|
+
reads.add(target);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
filterReads(query.where, own, reads);
|
|
79
|
+
return [...reads];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Requires `<entity>:read` on every entity a request reads. A missing one fails the whole request,
|
|
83
|
+
* before anything is read: nothing is silently left out.
|
|
84
|
+
*/
|
|
85
|
+
export function requireRead(entities) {
|
|
86
|
+
return Effect.gen(function* () {
|
|
87
|
+
const principal = yield* CurrentPrincipal;
|
|
88
|
+
const missing = missingPermission(entities.map((entity) => permissionOf(entity, READ_VERB)), principal);
|
|
89
|
+
if (missing !== undefined) {
|
|
90
|
+
return yield* new PermissionDenied({
|
|
91
|
+
permission: missing,
|
|
92
|
+
message: `Reading requires ${missing}, which the principal's roles do not grant.`,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The configured hook as `runAction` runs it after the commit. A failure is logged with the request
|
|
99
|
+
* id here, so the action's caller still gets the committed result.
|
|
100
|
+
*/
|
|
101
|
+
function afterCommitOf(hook, request, ontology, run) {
|
|
102
|
+
return (committed) => {
|
|
103
|
+
const definition = ontology.config.entities.find((entity) => nameToWire(entity.name) === committed.entity)?.definition;
|
|
104
|
+
return Effect.tryPromise(async () => hook({
|
|
105
|
+
entity: toCamelCase(committed.entity),
|
|
106
|
+
action: toCamelCase(committed.action),
|
|
107
|
+
principal: principalFromWire(committed.principal),
|
|
108
|
+
input: request.generated ? recordFromWire(committed.input, definition) : committed.input,
|
|
109
|
+
result: request.generated
|
|
110
|
+
? generatedResultFromWire(committed.result, committed.action, definition)
|
|
111
|
+
: committed.result,
|
|
112
|
+
edits: editsFromWire(committed.edits, ontology.config.entities),
|
|
113
|
+
requestId: request.requestId,
|
|
114
|
+
...(run === undefined ? {} : { run }),
|
|
115
|
+
})).pipe(Effect.catchCause((cause) => Effect.logError("ontology.after_commit.failed", cause).pipe(Effect.annotateLogs({
|
|
116
|
+
requestId: request.requestId,
|
|
117
|
+
action: `${committed.entity}.${committed.action}`,
|
|
118
|
+
}))));
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** The deployment's OIDC token: Vercel sets it on each request, and in the environment of builds. */
|
|
122
|
+
export function identityToken(request) {
|
|
123
|
+
const header = request.headers[OIDC_TOKEN_HEADER];
|
|
124
|
+
return typeof header === "string" && header !== "" ? header : process.env.VERCEL_OIDC_TOKEN;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The caller as the backend's reads take it: present only when it holds scoped permissions, whose
|
|
128
|
+
* read scopes then leave out the rows outside them. Other callers read as before.
|
|
129
|
+
*/
|
|
130
|
+
const scopedReader = Effect.gen(function* () {
|
|
131
|
+
const principal = yield* CurrentPrincipal;
|
|
132
|
+
return principal.scopes === undefined || principal.scopes.length === 0
|
|
133
|
+
? {}
|
|
134
|
+
: { reader: principal };
|
|
135
|
+
});
|
|
136
|
+
function findOf(backend, targets, entity, query) {
|
|
137
|
+
// Every read checks the caller's permissions first; the backend is called only afterwards.
|
|
138
|
+
return requireRead(queryReads(entity, query, targets)).pipe(Effect.andThen(() => scopedReader), Effect.flatMap((reader) => backend.find({ entity, query, ...reader })), Effect.map(page));
|
|
139
|
+
}
|
|
140
|
+
function getOf(backend, entity, id) {
|
|
141
|
+
return requireRead([entity]).pipe(Effect.andThen(() => scopedReader), Effect.flatMap((reader) => backend.get({ entity, id, ...reader })));
|
|
142
|
+
}
|
|
143
|
+
function historyOf(backend, entity, id, params) {
|
|
144
|
+
return requireRead([entity]).pipe(Effect.andThen(() => scopedReader), Effect.flatMap((reader) => backend.history({ entity, id, ...params, ...reader })), Effect.map(page));
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Follows a relationship from one record with the query language: the record's own
|
|
148
|
+
* `<relationship>_id` for a `rel.one`, and for everything to-many a relationship path from the
|
|
149
|
+
* target back to the record (`lead.notes` is notes whose `lead` is the lead, `lead.tags` is tags
|
|
150
|
+
* some of whose `leads` is the lead), combined with the caller's query and paged like any find.
|
|
151
|
+
*/
|
|
152
|
+
function traverseOf(backend, targets, planned, traversal, id, query) {
|
|
153
|
+
return Effect.gen(function* () {
|
|
154
|
+
yield* requireRead([planned.name, ...queryReads(traversal.target, query, targets)]);
|
|
155
|
+
const reader = yield* scopedReader;
|
|
156
|
+
// A source outside the caller's read scope is not found, like any record they cannot read.
|
|
157
|
+
const source = yield* backend.get({ entity: planned.name, id, ...reader });
|
|
158
|
+
if (traversal.match !== undefined) {
|
|
159
|
+
const value = source[traversal.match.source];
|
|
160
|
+
if (value === null || value === undefined) {
|
|
161
|
+
return {
|
|
162
|
+
items: [],
|
|
163
|
+
nextCursor: null,
|
|
164
|
+
...(query.select === undefined ? {} : { projected: true }),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
const related = { [traversal.match.target]: { eq: value } };
|
|
168
|
+
const relatedPage = yield* backend.find({
|
|
169
|
+
entity: traversal.target,
|
|
170
|
+
query: {
|
|
171
|
+
...query,
|
|
172
|
+
where: query.where === undefined ? related : { and: [related, query.where] },
|
|
173
|
+
...(traversal.kind === "one" ? { limit: 2 } : {}),
|
|
174
|
+
},
|
|
175
|
+
...reader,
|
|
176
|
+
});
|
|
177
|
+
if (traversal.kind === "one" &&
|
|
178
|
+
(relatedPage.items.length > 1 || relatedPage.nextCursor !== null)) {
|
|
179
|
+
return yield* new InvalidQuery({
|
|
180
|
+
entity: planned.name,
|
|
181
|
+
message: "The target key of a to-one relationship is not unique.",
|
|
182
|
+
issues: [{ path: [], message: "The target key of a to-one relationship is not unique." }],
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
return page(relatedPage);
|
|
186
|
+
}
|
|
187
|
+
if (traversal.kind === "one") {
|
|
188
|
+
const targetId = source[`${traversal.name}_id`];
|
|
189
|
+
if (typeof targetId !== "string") {
|
|
190
|
+
return { items: [], nextCursor: null };
|
|
191
|
+
}
|
|
192
|
+
return page(yield* backend.find({
|
|
193
|
+
entity: traversal.target,
|
|
194
|
+
query: { ...query, where: { id: { eq: targetId } }, limit: 1 },
|
|
195
|
+
...reader,
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
198
|
+
const match = { id: { eq: id } };
|
|
199
|
+
const related = traversal.kind === "inverseOfOne"
|
|
200
|
+
? { [traversal.opposite]: match }
|
|
201
|
+
: { [traversal.opposite]: { some: match } };
|
|
202
|
+
const where = query.where === undefined ? related : { and: [related, query.where] };
|
|
203
|
+
return page(yield* backend.find({ entity: traversal.target, query: { ...query, where }, ...reader }));
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
function runActionOf(backend, plan, hooks, connections, replicate, chatDelivery) {
|
|
207
|
+
const ontology = plan.ontology;
|
|
208
|
+
return (planned, { name, generated }, call) => Effect.gen(function* () {
|
|
209
|
+
yield* requireRuntimeOperation({ entity: planned.name, action: name });
|
|
210
|
+
const principal = yield* CurrentPrincipal;
|
|
211
|
+
const caller = yield* currentCaller;
|
|
212
|
+
const raw = typeof call.input === "object" && call.input !== null && !Array.isArray(call.input)
|
|
213
|
+
? call.input
|
|
214
|
+
: {};
|
|
215
|
+
const consumed = yield* consumeChatEnvelope(withoutConfirmation(raw), caller);
|
|
216
|
+
const inherited = yield* Effect.serviceOption(CurrentChatCall);
|
|
217
|
+
const envelope = caller.kind === "runtime"
|
|
218
|
+
? (consumed.envelope ?? Option.getOrUndefined(inherited))
|
|
219
|
+
: undefined;
|
|
220
|
+
let input = Object.hasOwn(raw, "_segmentstream") || Object.hasOwn(raw, "_confirmation")
|
|
221
|
+
? consumed.input
|
|
222
|
+
: call.input;
|
|
223
|
+
// A chat post needs its requester's confirmation, and a task has none (spec decision 7).
|
|
224
|
+
if (planned.name === "agent_chat" &&
|
|
225
|
+
name === "post_message" &&
|
|
226
|
+
principal.authenticatedVia === AGENT_TASK_AUTHENTICATION) {
|
|
227
|
+
return yield* new ActionRejected({
|
|
228
|
+
message: "Agent tasks cannot post to chat in this release: agent_chat.post_message is refused " +
|
|
229
|
+
"for a task whatever its workflow's role grants.",
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
if (planned.name === "agent_chat" && name === "post_message" && caller.kind === "runtime") {
|
|
233
|
+
const values = yield* Schema.decodeUnknownEffect(RuntimeChatPostWire)(consumed.input, {
|
|
234
|
+
onExcessProperty: "error",
|
|
235
|
+
}).pipe(Effect.mapError(() => new ActionRejected({
|
|
236
|
+
message: "Runtime chat keys are application-owned; only chat, text and reply_to are accepted.",
|
|
237
|
+
})));
|
|
238
|
+
if (!envelope?.operation_id) {
|
|
239
|
+
return yield* new ActionRejected({ message: "A confirmed runtime call is required." });
|
|
240
|
+
}
|
|
241
|
+
input = { ...values, idempotency_key: envelope.operation_id };
|
|
242
|
+
}
|
|
243
|
+
const requestId = yield* RequestId;
|
|
244
|
+
const delivery = planned.name === "agent_chat" && (name === "post_message" || name === "preview_message")
|
|
245
|
+
? chatDelivery?.({
|
|
246
|
+
backend,
|
|
247
|
+
principal,
|
|
248
|
+
caller,
|
|
249
|
+
requestId,
|
|
250
|
+
identityToken: call.identityToken,
|
|
251
|
+
...(envelope === undefined ? {} : { envelope }),
|
|
252
|
+
})
|
|
253
|
+
: undefined;
|
|
254
|
+
const hook = hooks.get(`${planned.name}.${name}`);
|
|
255
|
+
const run = backend.runAction({
|
|
256
|
+
entity: planned.name,
|
|
257
|
+
action: name,
|
|
258
|
+
input,
|
|
259
|
+
...(call.runtime !== undefined
|
|
260
|
+
? { runtime: call.runtime }
|
|
261
|
+
: caller.kind === "runtime" && envelope?.source !== undefined
|
|
262
|
+
? { runtime: { source: envelope.source } }
|
|
263
|
+
: {}),
|
|
264
|
+
principal,
|
|
265
|
+
options: {
|
|
266
|
+
...call.options,
|
|
267
|
+
validateOnly: call.validateOnly,
|
|
268
|
+
...(call.confirm === undefined ? {} : { confirm: call.confirm }),
|
|
269
|
+
},
|
|
270
|
+
requestId,
|
|
271
|
+
connections: connections({
|
|
272
|
+
identityToken: call.identityToken,
|
|
273
|
+
audit: { action: `${planned.name}.${name}`, principalId: principal.id, requestId },
|
|
274
|
+
}),
|
|
275
|
+
...(hook || backend.replicationEnabled
|
|
276
|
+
? {
|
|
277
|
+
afterCommit: (committed) => Effect.gen(function* () {
|
|
278
|
+
if (hook) {
|
|
279
|
+
const run = ontology.config.hooks === undefined
|
|
280
|
+
? undefined
|
|
281
|
+
: async (target) => {
|
|
282
|
+
if (target.as !== "service" ||
|
|
283
|
+
backend.resolveHookService === undefined) {
|
|
284
|
+
throw new Error("Hook service execution is unavailable.");
|
|
285
|
+
}
|
|
286
|
+
const principal = await Effect.runPromise(backend.resolveHookService(nameToWire(ontology.config.hooks.role)));
|
|
287
|
+
const planned = plan.entities.find((entity) => entity.name === nameToWire(target.entity));
|
|
288
|
+
const action = planned?.actions.find((candidate) => candidate.name === nameToWire(target.action));
|
|
289
|
+
if (principal === undefined ||
|
|
290
|
+
planned === undefined ||
|
|
291
|
+
action === undefined) {
|
|
292
|
+
throw new Error("The hook principal or target action is unavailable.");
|
|
293
|
+
}
|
|
294
|
+
const answer = await Effect.runPromise(runActionOf(backend, plan, hooks, connections, replicate, chatDelivery)(planned, action, {
|
|
295
|
+
input: await Effect.runPromise(Schema.encodeUnknownEffect(action.action.input)(target.input)),
|
|
296
|
+
validateOnly: false,
|
|
297
|
+
identityToken: call.identityToken,
|
|
298
|
+
}).pipe(Effect.provideService(CurrentPrincipal, principal), Effect.provideService(CurrentCaller, {
|
|
299
|
+
kind: "service",
|
|
300
|
+
subjectId: principal.id,
|
|
301
|
+
}), Effect.provideService(RequestId, requestId)));
|
|
302
|
+
return answer.result;
|
|
303
|
+
};
|
|
304
|
+
yield* afterCommitOf(hook, { requestId, generated }, ontology, run)(committed);
|
|
305
|
+
}
|
|
306
|
+
if (committed.edits.length > 0 &&
|
|
307
|
+
(yield* backend.replicationEnabled ?? Effect.succeed(false))) {
|
|
308
|
+
yield* replicate(call.identityToken);
|
|
309
|
+
}
|
|
310
|
+
}).pipe(Effect.catchCause((cause) => Effect.logWarning("ontology.replication.deferred", cause))),
|
|
311
|
+
}
|
|
312
|
+
: {}),
|
|
313
|
+
});
|
|
314
|
+
const outcome = yield* delivery === undefined
|
|
315
|
+
? run
|
|
316
|
+
: run.pipe(Effect.provideService(ChatDelivery, delivery));
|
|
317
|
+
if (call.validateOnly &&
|
|
318
|
+
outcome.validation.ok &&
|
|
319
|
+
planned.name === "agent_chat" &&
|
|
320
|
+
name === "post_message" &&
|
|
321
|
+
delivery) {
|
|
322
|
+
const decoded = yield* Schema.decodeUnknownEffect(ChatPostWire)(input).pipe(Effect.mapError(() => new ActionRejected({ message: "Invalid exact chat post input." })));
|
|
323
|
+
yield* delivery.validate(decoded);
|
|
324
|
+
}
|
|
325
|
+
const { issues } = outcome.validation;
|
|
326
|
+
if (!outcome.validation.ok && !call.validateOnly) {
|
|
327
|
+
return yield* new InvalidActionInput({ issues });
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
result: outcome.result ?? null,
|
|
331
|
+
validation: { ok: outcome.validation.ok, issues },
|
|
332
|
+
edits: outcome.edits,
|
|
333
|
+
};
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* The caller: their user record and the roles and permissions authentication resolved. Anyone may
|
|
338
|
+
* learn who they are and what they may do.
|
|
339
|
+
*/
|
|
340
|
+
function callerOf(backend, ontology) {
|
|
341
|
+
return Effect.gen(function* () {
|
|
342
|
+
const principal = yield* CurrentPrincipal;
|
|
343
|
+
const caller = yield* currentCaller;
|
|
344
|
+
// Authentication resolved the principal from this user a moment ago; its absence is a defect.
|
|
345
|
+
const user = yield* backend.get({ entity: "user", id: principal.id }).pipe(Effect.orDie);
|
|
346
|
+
return {
|
|
347
|
+
user: {
|
|
348
|
+
id: principal.id,
|
|
349
|
+
name: String(user.name),
|
|
350
|
+
email: typeof user.email === "string" ? user.email : null,
|
|
351
|
+
kind: principal.kind,
|
|
352
|
+
active: user.active === true,
|
|
353
|
+
},
|
|
354
|
+
roles: principal.roles,
|
|
355
|
+
permissions: principal.permissions,
|
|
356
|
+
...(principal.scopes === undefined || principal.scopes.length === 0
|
|
357
|
+
? {}
|
|
358
|
+
: {
|
|
359
|
+
scopes: principal.scopes.map(({ permission, where }) => ({ permission, where })),
|
|
360
|
+
}),
|
|
361
|
+
authentication: {
|
|
362
|
+
kind: caller.kind,
|
|
363
|
+
client: caller.kind === "oauth" ? caller.client : null,
|
|
364
|
+
scope: caller.kind === "oauth" ? caller.scope : null,
|
|
365
|
+
},
|
|
366
|
+
attribution: chatAttribution(caller, String(user.name), ontology.config.chat?.attribution),
|
|
367
|
+
attribution_separator: ontology.config.chat?.attribution?.separator ?? "\n\n",
|
|
368
|
+
};
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* The operations of a planned ontology, bound to its backend, after-commit hooks, connections and,
|
|
373
|
+
* on deployments with one, the workspace's agent.
|
|
374
|
+
*/
|
|
375
|
+
export function makeOperations(backend, plan, hooks, connections, replicate, chatDelivery) {
|
|
376
|
+
const targets = relationshipTargets(plan);
|
|
377
|
+
const reads = recordReads(backend, plan);
|
|
378
|
+
return {
|
|
379
|
+
/** A page of records. Requires `read` on the entity and on every entity the query reaches. */
|
|
380
|
+
find: (planned, query) => findOf(reads, targets, planned.name, query),
|
|
381
|
+
/** One record. Requires `read` on the entity. */
|
|
382
|
+
get: (planned, id) => getOf(reads, planned.name, id),
|
|
383
|
+
/** A page of a record's history, newest first. Requires `read` on the entity. */
|
|
384
|
+
history: (planned, id, params) => historyOf(backend, planned.name, id, params),
|
|
385
|
+
/** The records a relationship reaches from one record, as a page of the target entity. */
|
|
386
|
+
traverse: (planned, traversal, id, query) => traverseOf(reads, targets, planned, traversal, id, query),
|
|
387
|
+
/** Runs an action as the caller, with the action's after-commit hook and connections. */
|
|
388
|
+
runAction: runActionOf(backend, plan, hooks, connections, replicate, chatDelivery),
|
|
389
|
+
/** The caller's user, roles and permissions. It needs no permission. */
|
|
390
|
+
caller: callerOf(backend, plan.ontology),
|
|
391
|
+
};
|
|
392
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { AnyAction } from "../action.js";
|
|
2
|
+
import type { ResolvedEntity } from "../analyze.js";
|
|
3
|
+
import type { Ontology } from "../ontology.js";
|
|
4
|
+
import type { GeneratedActionsProvider } from "./runtime-contract.js";
|
|
5
|
+
/**
|
|
6
|
+
* How a traversal reaches its records:
|
|
7
|
+
* - `one`: the record's own `rel.one` (`note → lead`), at most one record;
|
|
8
|
+
* - `many`: the record's own `rel.many` (`lead → tags`);
|
|
9
|
+
* - `inverseOfOne`: records whose `rel.one` points here (`lead → notes`);
|
|
10
|
+
* - `inverseOfMany`: records whose `rel.many` contains this record (`tag → leads`).
|
|
11
|
+
*/
|
|
12
|
+
export type TraversalKind = "one" | "many" | "inverseOfOne" | "inverseOfMany";
|
|
13
|
+
/** `GET /api/ontology/<entity>/{id}/<name>`. */
|
|
14
|
+
export interface Traversal {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly kind: TraversalKind;
|
|
17
|
+
/** The entity whose records the traversal returns. */
|
|
18
|
+
readonly target: string;
|
|
19
|
+
/** The name of the same relationship as seen from the target. */
|
|
20
|
+
readonly opposite: string;
|
|
21
|
+
/** The phrase from this entity's side, for example "is owned by" or "owns". */
|
|
22
|
+
readonly phrase: string;
|
|
23
|
+
readonly description: string;
|
|
24
|
+
/** A warehouse boundary is joined by these mapped properties, never by a fabricated foreign key. */
|
|
25
|
+
readonly match?: {
|
|
26
|
+
readonly source: string;
|
|
27
|
+
readonly target: string;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface PlannedAction {
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly action: AnyAction;
|
|
33
|
+
readonly generated: boolean;
|
|
34
|
+
/** Every permission a principal needs to run it. */
|
|
35
|
+
readonly permissions: ReadonlyArray<string>;
|
|
36
|
+
/** The entities an authored action declares it writes, by name; absent when it declares none. */
|
|
37
|
+
readonly writes?: ReadonlyArray<string>;
|
|
38
|
+
}
|
|
39
|
+
export interface PlannedEntity {
|
|
40
|
+
readonly name: string;
|
|
41
|
+
readonly resolved: ResolvedEntity;
|
|
42
|
+
/** Declared relationships first, then the inverses that land on this entity. */
|
|
43
|
+
readonly traversals: ReadonlyArray<Traversal>;
|
|
44
|
+
/** Generated actions first, then the authored ones. */
|
|
45
|
+
readonly actions: ReadonlyArray<PlannedAction>;
|
|
46
|
+
}
|
|
47
|
+
/** The routes the service derives from an ontology, shared by the API definition and its handlers. */
|
|
48
|
+
export interface ApiPlan {
|
|
49
|
+
readonly ontology: Ontology;
|
|
50
|
+
readonly entities: ReadonlyArray<PlannedEntity>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Plans the routes of a checked ontology. `check` already refuses names that would shadow a route of
|
|
54
|
+
* the service; this throws {@link InvalidOntology} when a generated action would shadow an authored
|
|
55
|
+
* one.
|
|
56
|
+
*/
|
|
57
|
+
export declare function planApi(ontology: Ontology, generatedActions: GeneratedActionsProvider): ApiPlan;
|