@segmentstream/ontology 0.0.0-stage → 0.92.1
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,526 @@
|
|
|
1
|
+
import { Cause, Context, Effect, Layer, Redacted } from "effect";
|
|
2
|
+
import { HttpRouter, HttpServer, HttpServerError, HttpServerRequest } from "effect/unstable/http";
|
|
3
|
+
import { HttpApiBuilder, HttpApiSecurity } from "effect/unstable/httpapi";
|
|
4
|
+
import { storageMaintenanceAuthenticationLayer } from "../storage/maintenance-auth.js";
|
|
5
|
+
import { validateDeploymentStorage } from "../storage/provider.js";
|
|
6
|
+
import { captureRuntimeFailure } from "../internal/diagnostics.js";
|
|
7
|
+
import { deploymentFromEnv, DeploymentAdmissionError, requireDeploymentCapability, } from "../deployment.js";
|
|
8
|
+
import { RuntimeDeployment } from "../runtime/deployment.js";
|
|
9
|
+
import { nameToWire } from "../authoring-names.js";
|
|
10
|
+
import { bundledNavigationCatalog } from "../navigation-artifact.js";
|
|
11
|
+
import { parsePageCatalog } from "../navigation-catalog.js";
|
|
12
|
+
import { isAllowed } from "../permissions.js";
|
|
13
|
+
import { sqlServiceRuntime } from "../runtime/service-binding.js";
|
|
14
|
+
import { neonSignInLinks, segmentstreamSignInLinks } from "../runtime/sign-in-links.js";
|
|
15
|
+
import { memberFileRoutes } from "./member-file-routes.js";
|
|
16
|
+
import { attachmentsLayer } from "./agent/attachments.js";
|
|
17
|
+
import { filesLayer } from "./agent/files.js";
|
|
18
|
+
import { platformConversations } from "./agent/conversations.js";
|
|
19
|
+
import { conversationRoutes } from "./agent/conversation-routes.js";
|
|
20
|
+
import { makeChatDelivery } from "./chat/delivery.js";
|
|
21
|
+
import { platformDeliveryArchive } from "./chat/archive.js";
|
|
22
|
+
import { chatRoutes } from "./chat/routes.js";
|
|
23
|
+
import { agentLayer } from "./agent/server.js";
|
|
24
|
+
import { agentTasksLayer } from "./agent/tasks.js";
|
|
25
|
+
import { makeMetricQueries } from "./metric-query.js";
|
|
26
|
+
import { platformMetricQueries } from "./metric-query-platform.js";
|
|
27
|
+
import { platformWarehouseQueries, WarehouseQueries } from "./warehouse-platform.js";
|
|
28
|
+
import { ErrorResponsesLive, buildApi } from "./api.js";
|
|
29
|
+
import { CurrentPrincipal, authenticationLayer, neonAuthSessionExchange, tokenVerifier, withPrincipal, } from "./authentication.js";
|
|
30
|
+
import { currentCaller } from "./caller-context.js";
|
|
31
|
+
import { OntologyServiceConfigError, } from "./config.js";
|
|
32
|
+
import { RequestId, failureResponse, internalError, errorBodyForWire, routeNotFound, toServerResponse, } from "./errors.js";
|
|
33
|
+
import { deployedConnections, localConnections } from "./connections.js";
|
|
34
|
+
import { DocsRoute } from "./docs.js";
|
|
35
|
+
import { handlersLayer } from "./handlers.js";
|
|
36
|
+
import { deployedReplication } from "./replication.js";
|
|
37
|
+
import { mcpLayer } from "./mcp/server.js";
|
|
38
|
+
import { runtimeAllows } from "./mcp/runtime-policy.js";
|
|
39
|
+
import { suggestNames } from "./name-suggestions.js";
|
|
40
|
+
import { observeMcpRequest } from "./mcp/request-log.js";
|
|
41
|
+
import { oauthLayer } from "./oauth/server.js";
|
|
42
|
+
import { federationLayer } from "./federation-server.js";
|
|
43
|
+
import { channelSessionLayer } from "./channel/sessions.js";
|
|
44
|
+
import { channelSignInLayer } from "./channel/sign-in.js";
|
|
45
|
+
import { telegramAppProvider } from "./channel/providers/telegram.js";
|
|
46
|
+
import { planApi } from "./plan.js";
|
|
47
|
+
import { deployedWebhookTokenVerifier, deployedWebhookVerifier } from "./webhooks.js";
|
|
48
|
+
import { vercelWorkflowEngine, workflowStarter, workflowsLayer } from "./workflows.js";
|
|
49
|
+
import { deploymentWorkflowEngine } from "./workflow-deployment.js";
|
|
50
|
+
import { OntologyBackend } from "./runtime-contract.js";
|
|
51
|
+
import { runtimeCredential, runtimeTokenVerifier, } from "./runtime-identity.js";
|
|
52
|
+
/** The header every response carries: the hash of the manifest the service serves. */
|
|
53
|
+
export const ONTOLOGY_HASH_HEADER = "x-ontology-hash";
|
|
54
|
+
/** The header every response carries: the correlation id quoted in error bodies and logs. */
|
|
55
|
+
export const REQUEST_ID_HEADER = "x-request-id";
|
|
56
|
+
function runtimeFailureValues(config) {
|
|
57
|
+
const storage = config.blobStorage ? Redacted.value(config.blobStorage) : undefined;
|
|
58
|
+
const password = URL.parse(Redacted.value(config.databaseUrl))?.password;
|
|
59
|
+
let decodedPassword = password;
|
|
60
|
+
try {
|
|
61
|
+
decodedPassword = password === undefined ? undefined : decodeURIComponent(password);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// Diagnostic redaction must not replace the original failure on an invalid URI escape.
|
|
65
|
+
}
|
|
66
|
+
return [
|
|
67
|
+
Redacted.value(config.databaseUrl),
|
|
68
|
+
password,
|
|
69
|
+
decodedPassword,
|
|
70
|
+
config.appCredential ? Redacted.value(config.appCredential) : undefined,
|
|
71
|
+
config.cronSecret ? Redacted.value(config.cronSecret) : undefined,
|
|
72
|
+
config.webhookSecret ? Redacted.value(config.webhookSecret) : undefined,
|
|
73
|
+
config.storageMaintenanceKey ? Redacted.value(config.storageMaintenanceKey) : undefined,
|
|
74
|
+
storage?.accessKeyId,
|
|
75
|
+
storage?.secretAccessKey,
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
function afterCommitHooks(plan, hooks = {}) {
|
|
79
|
+
const actions = new Set(plan.entities.flatMap(({ name, actions: planned }) => planned.map((action) => `${name}.${action.name}`)));
|
|
80
|
+
const entries = Object.entries(hooks).map(([key, hook]) => [key.split(".").map(nameToWire).join("."), hook]);
|
|
81
|
+
const unknown = Object.keys(hooks).filter((key) => !actions.has(key.split(".").map(nameToWire).join(".")));
|
|
82
|
+
if (unknown.length > 0) {
|
|
83
|
+
throw new OntologyServiceConfigError({
|
|
84
|
+
message: `afterCommit names actions the ontology does not have: ${unknown.join(", ")}.`,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (new Set(entries.map(([key]) => key)).size !== entries.length) {
|
|
88
|
+
throw new OntologyServiceConfigError({
|
|
89
|
+
message: "afterCommit names collide after snake_case conversion.",
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
return new Map(entries);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Requests that match no route, and defects that escape a route's own error handling, still get a
|
|
96
|
+
* JSON error with the request id.
|
|
97
|
+
*/
|
|
98
|
+
function unmatchedRoutes(plan, verifyToken, exchangeSession, verifyRuntime) {
|
|
99
|
+
return Layer.unwrap(Effect.gen(function* () {
|
|
100
|
+
const backend = yield* OntologyBackend;
|
|
101
|
+
return HttpRouter.middleware()((httpEffect) => Effect.gen(function* () {
|
|
102
|
+
const requestId = yield* RequestId;
|
|
103
|
+
const request = yield* HttpServerRequest.HttpServerRequest;
|
|
104
|
+
const bare = toServerResponse(routeNotFound(requestId));
|
|
105
|
+
const notFound = Effect.gen(function* () {
|
|
106
|
+
if (request.method !== "POST") {
|
|
107
|
+
return bare;
|
|
108
|
+
}
|
|
109
|
+
const url = new URL(request.url, "http://ontology.local");
|
|
110
|
+
const path = url.pathname;
|
|
111
|
+
const match = /^\/api\/ontology\/([a-z][a-z0-9_]*)\/actions\/([A-Za-z][A-Za-z0-9_]*)$/.exec(path);
|
|
112
|
+
const entity = match === null ? undefined : plan.entities.find(({ name }) => name === match[1]);
|
|
113
|
+
if (match === null || entity === undefined) {
|
|
114
|
+
return bare;
|
|
115
|
+
}
|
|
116
|
+
// Route matching precedes Authentication. Reuse its credential/session checks, but keep
|
|
117
|
+
// the original bare 404 for every authentication failure on an unmatched route.
|
|
118
|
+
const credential = yield* HttpApiBuilder.securityDecode(HttpApiSecurity.bearer).pipe(Effect.provideService(HttpServerRequest.ParsedSearchParams, HttpServerRequest.searchParamsFromURL(url)));
|
|
119
|
+
const runtime = runtimeCredential(verifyRuntime, request);
|
|
120
|
+
const authenticated = yield* withPrincipal(credential, verifyToken, backend, Effect.gen(function* () {
|
|
121
|
+
const principal = yield* CurrentPrincipal;
|
|
122
|
+
const caller = yield* currentCaller;
|
|
123
|
+
const visible = entity.actions.filter((action) => action.permissions.every((permission) => isAllowed(permission, principal)) &&
|
|
124
|
+
runtimeAllows(caller, { entity: entity.name, action: action.name }));
|
|
125
|
+
const suggestions = suggestNames(match[2], visible.map(({ name }) => name));
|
|
126
|
+
return toServerResponse(routeNotFound(requestId, suggestions));
|
|
127
|
+
}), {
|
|
128
|
+
session: { request, exchange: exchangeSession },
|
|
129
|
+
...(runtime === undefined ? {} : { runtime }),
|
|
130
|
+
});
|
|
131
|
+
return authenticated.status === 404 ? authenticated : bare;
|
|
132
|
+
});
|
|
133
|
+
return yield* httpEffect.pipe(Effect.catchIf(HttpServerError.isHttpServerError, (error) => error.reason instanceof HttpServerError.RouteNotFound
|
|
134
|
+
? notFound
|
|
135
|
+
: failureResponse(Cause.fail(error), requestId)), Effect.catchDefect((defect) => failureResponse(Cause.die(defect), requestId)));
|
|
136
|
+
}), { global: true });
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
function decorate(response, requestId, hash, durationMs) {
|
|
140
|
+
const headers = new Headers(response.headers);
|
|
141
|
+
headers.set(ONTOLOGY_HASH_HEADER, hash);
|
|
142
|
+
headers.set(REQUEST_ID_HEADER, requestId);
|
|
143
|
+
headers.append("server-timing", `ontology;dur=${durationMs}`);
|
|
144
|
+
if (!headers.get("content-type")?.startsWith("text/event-stream")) {
|
|
145
|
+
headers.set("cache-control", "private, no-store");
|
|
146
|
+
}
|
|
147
|
+
return new Response(response.body, {
|
|
148
|
+
status: response.status,
|
|
149
|
+
statusText: response.statusText,
|
|
150
|
+
headers,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The ontology service: the derived HttpApi, the MCP server at `/mcp` and the agent's pairing routes,
|
|
155
|
+
* wired to the runtime, behind Neon Auth, app-token, API-key and runtime-token authentication.
|
|
156
|
+
* Every response carries `x-ontology-hash`
|
|
157
|
+
* and `x-request-id`; failures answer with a JSON error and never a stack or SQL.
|
|
158
|
+
*/
|
|
159
|
+
export function createOntologyService(ontology, config) {
|
|
160
|
+
const ambient = deploymentFromEnv();
|
|
161
|
+
const requested = ambient.target === "preview" ? ambient : (config.deployment ?? ambient);
|
|
162
|
+
const deployment = deploymentFromEnv({
|
|
163
|
+
SEGMENTSTREAM_DEPLOYMENT_TARGET: requested.target,
|
|
164
|
+
SEGMENTSTREAM_ONTOLOGY_DEPLOYMENT_ID: requested.deploymentId,
|
|
165
|
+
SEGMENTSTREAM_PREVIEW_EXPIRES_AT: requested.target === "preview" ? requested.expiresAt : undefined,
|
|
166
|
+
SEGMENTSTREAM_PREVIEW_HOST: requested.target === "preview" ? requested.host : undefined,
|
|
167
|
+
});
|
|
168
|
+
const preview = deployment.target === "preview";
|
|
169
|
+
config = {
|
|
170
|
+
...config,
|
|
171
|
+
deployment,
|
|
172
|
+
...(preview
|
|
173
|
+
? {
|
|
174
|
+
oidc: ontology.signIn.browser ? config.oidc : undefined,
|
|
175
|
+
runtimeIdentity: undefined,
|
|
176
|
+
localConnections: undefined,
|
|
177
|
+
cronSecret: undefined,
|
|
178
|
+
agentOrigin: undefined,
|
|
179
|
+
channels: undefined,
|
|
180
|
+
channelAppProviders: undefined,
|
|
181
|
+
}
|
|
182
|
+
: {}),
|
|
183
|
+
};
|
|
184
|
+
if (preview && !config.neonAuth && !ontology.signIn.browser?.methods.includes("segmentstream")) {
|
|
185
|
+
throw new DeploymentAdmissionError("preview_configuration_invalid");
|
|
186
|
+
}
|
|
187
|
+
if (preview && config.blobStorage) {
|
|
188
|
+
validateDeploymentStorage(Redacted.value(config.blobStorage), deployment);
|
|
189
|
+
}
|
|
190
|
+
const bundledNavigation = bundledNavigationCatalog();
|
|
191
|
+
if (bundledNavigation !== undefined &&
|
|
192
|
+
config.navigation !== undefined &&
|
|
193
|
+
JSON.stringify(parsePageCatalog(config.navigation)) !== JSON.stringify(bundledNavigation)) {
|
|
194
|
+
throw new OntologyServiceConfigError({ message: "navigation_catalog_override" });
|
|
195
|
+
}
|
|
196
|
+
const navigation = bundledNavigation ?? config.navigation;
|
|
197
|
+
const telegram = config.channels?.telegram;
|
|
198
|
+
const testKey = telegram?.miniApp?.testPublicKeyHex;
|
|
199
|
+
const telegramConnection = ontology.manifest.chat?.telegram?.connection;
|
|
200
|
+
if (telegram?.miniApp && (!telegramConnection || telegram.connection !== telegramConnection)) {
|
|
201
|
+
throw new OntologyServiceConfigError({ message: "invalid_channel_connection" });
|
|
202
|
+
}
|
|
203
|
+
if (testKey !== undefined && !/^[0-9a-f]{64}$/i.test(testKey)) {
|
|
204
|
+
throw new OntologyServiceConfigError({ message: "invalid_channel_test_key" });
|
|
205
|
+
}
|
|
206
|
+
const channelApps = [
|
|
207
|
+
...(config.channelAppProviders ?? []),
|
|
208
|
+
...(telegram?.miniApp && telegramConnection
|
|
209
|
+
? [telegramAppProvider(telegramConnection, testKey)]
|
|
210
|
+
: []),
|
|
211
|
+
];
|
|
212
|
+
if (channelApps.some((adapter, i) => !/^[a-z][a-z0-9_-]{0,63}$/.test(adapter.provider) ||
|
|
213
|
+
channelApps.findIndex((other) => other.provider === adapter.provider) !== i ||
|
|
214
|
+
adapter.provider === "logout")) {
|
|
215
|
+
throw new OntologyServiceConfigError({ message: "invalid_channel_provider" });
|
|
216
|
+
}
|
|
217
|
+
if (config.mcpStreamMaxDurationMs !== undefined &&
|
|
218
|
+
(!Number.isInteger(config.mcpStreamMaxDurationMs) ||
|
|
219
|
+
config.mcpStreamMaxDurationMs <= 0 ||
|
|
220
|
+
config.mcpStreamMaxDurationMs > 2_147_483_647)) {
|
|
221
|
+
throw new OntologyServiceConfigError({
|
|
222
|
+
message: "mcpStreamMaxDurationMs must be a positive integer within the timer range.",
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
if (config.blobStorage &&
|
|
226
|
+
(!config.storageMaintenanceKey || Redacted.value(config.storageMaintenanceKey).length < 32)) {
|
|
227
|
+
throw new OntologyServiceConfigError({
|
|
228
|
+
message: "File storage requires a deployment maintenance credential of at least 32 characters.",
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
if (config.oauthRefreshReuseGraceMs !== undefined &&
|
|
232
|
+
(!Number.isFinite(config.oauthRefreshReuseGraceMs) || config.oauthRefreshReuseGraceMs < 0)) {
|
|
233
|
+
throw new OntologyServiceConfigError({
|
|
234
|
+
message: "OAuth refresh reuse grace must be nonnegative milliseconds.",
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
const browser = ontology.signIn.browser;
|
|
238
|
+
if (browser) {
|
|
239
|
+
if (!config.browserRevisionClientId) {
|
|
240
|
+
throw new OntologyServiceConfigError({ message: "browser_auth_revision_missing" });
|
|
241
|
+
}
|
|
242
|
+
const binding = config.browserAuth;
|
|
243
|
+
const expected = {
|
|
244
|
+
methods: browser.methods,
|
|
245
|
+
primary: browser.primary,
|
|
246
|
+
auto_redirect: browser.autoRedirect,
|
|
247
|
+
...(browser.local ? { local: browser.local } : {}),
|
|
248
|
+
};
|
|
249
|
+
if (binding?.version !== 1 ||
|
|
250
|
+
binding.manifest_digest !== ontology.manifest.hash ||
|
|
251
|
+
JSON.stringify(binding.browser, ["methods", "primary", "auto_redirect", "local", "port"]) !==
|
|
252
|
+
JSON.stringify(expected, ["methods", "primary", "auto_redirect", "local", "port"])) {
|
|
253
|
+
throw new OntologyServiceConfigError({ message: "browser_auth_binding_mismatch" });
|
|
254
|
+
}
|
|
255
|
+
if (browser.methods.includes("segmentstream") &&
|
|
256
|
+
config.browserEnvironment !== "local" &&
|
|
257
|
+
!deployment.deploymentId) {
|
|
258
|
+
throw new OntologyServiceConfigError({ message: "browser_auth_deployment_missing" });
|
|
259
|
+
}
|
|
260
|
+
if (browser.methods.includes("segmentstream") && !config.oidc) {
|
|
261
|
+
throw new OntologyServiceConfigError({ message: "browser_auth_provider_missing" });
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
const runtime = config.runtime ?? sqlServiceRuntime;
|
|
265
|
+
const plan = planApi(ontology, runtime.generatedActions);
|
|
266
|
+
const built = buildApi(plan);
|
|
267
|
+
const hooks = afterCommitHooks(plan, preview ? {} : config.afterCommit);
|
|
268
|
+
const federationConfig = config.oidc && browser
|
|
269
|
+
? {
|
|
270
|
+
...config.oidc,
|
|
271
|
+
environment: config.browserEnvironment ?? deployment.target,
|
|
272
|
+
deploymentId: config.browserEnvironment === "local" ? undefined : deployment.deploymentId,
|
|
273
|
+
manifestDigest: ontology.manifest.hash,
|
|
274
|
+
}
|
|
275
|
+
: config.oidc;
|
|
276
|
+
const browserRevision = browser
|
|
277
|
+
? {
|
|
278
|
+
issuer: config.browserRevisionIssuer ??
|
|
279
|
+
config.oidc?.issuer ??
|
|
280
|
+
`${new URL(config.segmentstreamUrl).origin}/oidc`,
|
|
281
|
+
clientId: config.browserRevisionClientId,
|
|
282
|
+
manifestDigest: ontology.manifest.hash,
|
|
283
|
+
...(config.browserEnvironment !== "local" ? { deploymentId: deployment.deploymentId } : {}),
|
|
284
|
+
}
|
|
285
|
+
: undefined;
|
|
286
|
+
const verifyToken = tokenVerifier({
|
|
287
|
+
...config,
|
|
288
|
+
browserRevision,
|
|
289
|
+
...(browser ? { browserMethods: browser.methods, oidc: federationConfig } : {}),
|
|
290
|
+
});
|
|
291
|
+
const exchangeSession = config.neonAuth === undefined || (browser && !browser.methods.includes("email"))
|
|
292
|
+
? undefined
|
|
293
|
+
: neonAuthSessionExchange(config.neonAuth);
|
|
294
|
+
const verifyRuntime = config.runtimeIdentity === undefined ? undefined : runtimeTokenVerifier(config.runtimeIdentity);
|
|
295
|
+
const workflowEngine = deploymentWorkflowEngine(config.workflowEngine ?? vercelWorkflowEngine, deployment);
|
|
296
|
+
const backend = runtime.connect({
|
|
297
|
+
deployment,
|
|
298
|
+
ontology,
|
|
299
|
+
databaseUrl: config.databaseUrl,
|
|
300
|
+
...(config.blobStorage ? { blobStorage: config.blobStorage } : {}),
|
|
301
|
+
workflowStarter: workflowStarter(ontology, workflowEngine),
|
|
302
|
+
...(browser &&
|
|
303
|
+
!browser.methods.includes("email") &&
|
|
304
|
+
!preview &&
|
|
305
|
+
config.browserEnvironment !== "local" &&
|
|
306
|
+
config.agentOrigin
|
|
307
|
+
? {
|
|
308
|
+
signInLinks: segmentstreamSignInLinks({
|
|
309
|
+
segmentstreamUrl: config.segmentstreamUrl,
|
|
310
|
+
workspaceId: config.workspaceId,
|
|
311
|
+
organizationId: config.organizationId,
|
|
312
|
+
identityToken: () => process.env.VERCEL_OIDC_TOKEN,
|
|
313
|
+
}),
|
|
314
|
+
}
|
|
315
|
+
: {}),
|
|
316
|
+
// Links open the production app, so previews, which have no production origin, send none.
|
|
317
|
+
...((!browser || browser.methods.includes("email")) &&
|
|
318
|
+
config.neonAuth !== undefined &&
|
|
319
|
+
config.agentOrigin !== undefined &&
|
|
320
|
+
config.browserEnvironment !== "local" &&
|
|
321
|
+
!preview
|
|
322
|
+
? {
|
|
323
|
+
signInLinks: neonSignInLinks({
|
|
324
|
+
baseUrl: config.neonAuth.baseUrl,
|
|
325
|
+
origin: config.agentOrigin,
|
|
326
|
+
}),
|
|
327
|
+
}
|
|
328
|
+
: {}),
|
|
329
|
+
});
|
|
330
|
+
const connections = preview
|
|
331
|
+
? () => ({
|
|
332
|
+
request: () => Effect.die(new DeploymentAdmissionError("preview_capability_unavailable", "connections")),
|
|
333
|
+
stream: () => Effect.die(new DeploymentAdmissionError("preview_capability_unavailable", "connections")),
|
|
334
|
+
})
|
|
335
|
+
: (config.connections ??
|
|
336
|
+
(config.localConnections === undefined
|
|
337
|
+
? deployedConnections(config)
|
|
338
|
+
: localConnections(config.localConnections)));
|
|
339
|
+
const replicate = deployedReplication(config);
|
|
340
|
+
const chatDelivery = makeChatDelivery(ontology, connections, config.chatArchive ?? platformDeliveryArchive(config), { settings: config.channels?.telegram, ownOrigins: config.appOrigins });
|
|
341
|
+
const conversations = config.runtimeIdentity === undefined ? undefined : platformConversations(config);
|
|
342
|
+
const metricQueries = makeMetricQueries({
|
|
343
|
+
ontology,
|
|
344
|
+
transport: platformMetricQueries({ ...config, manifestHash: ontology.manifest.hash }),
|
|
345
|
+
});
|
|
346
|
+
const routes = HttpApiBuilder.layer(built.api).pipe(Layer.provide(handlersLayer(built, hooks, connections, replicate, metricQueries, chatDelivery, preview || deployment.deploymentId ? deployment : undefined)), Layer.provide([
|
|
347
|
+
authenticationLayer(verifyToken, exchangeSession, verifyRuntime),
|
|
348
|
+
ErrorResponsesLive,
|
|
349
|
+
storageMaintenanceAuthenticationLayer(config.storageMaintenanceKey),
|
|
350
|
+
]));
|
|
351
|
+
const mcp = config.mcp === false
|
|
352
|
+
? Layer.empty
|
|
353
|
+
: Layer.mergeAll(mcpLayer({
|
|
354
|
+
built,
|
|
355
|
+
hooks,
|
|
356
|
+
connections,
|
|
357
|
+
verifyToken,
|
|
358
|
+
verifyRuntime,
|
|
359
|
+
replicate,
|
|
360
|
+
metricQueries,
|
|
361
|
+
chatDelivery,
|
|
362
|
+
conversations,
|
|
363
|
+
...(navigation === undefined ? {} : { navigation }),
|
|
364
|
+
appOrigins: config.appOrigins,
|
|
365
|
+
streamMaxDurationMs: config.mcpStreamMaxDurationMs,
|
|
366
|
+
workspaceId: config.workspaceId,
|
|
367
|
+
decide: config.decisions,
|
|
368
|
+
}), preview
|
|
369
|
+
? Layer.empty
|
|
370
|
+
: oauthLayer({ verifyToken, refreshReuseGraceMs: config.oauthRefreshReuseGraceMs }));
|
|
371
|
+
const agent = preview ? Layer.empty : agentLayer({ verifyToken, verifyRuntime, exchangeSession });
|
|
372
|
+
const agentTasks = preview
|
|
373
|
+
? Layer.empty
|
|
374
|
+
: agentTasksLayer({
|
|
375
|
+
verifyToken,
|
|
376
|
+
verifyRuntime,
|
|
377
|
+
workspaceId: config.workspaceId,
|
|
378
|
+
engine: config.workflowEngine ?? vercelWorkflowEngine,
|
|
379
|
+
});
|
|
380
|
+
const attachments = preview
|
|
381
|
+
? Layer.empty
|
|
382
|
+
: attachmentsLayer({
|
|
383
|
+
plan: built.plan,
|
|
384
|
+
hooks,
|
|
385
|
+
connections,
|
|
386
|
+
replicate,
|
|
387
|
+
verifyToken,
|
|
388
|
+
verifyRuntime,
|
|
389
|
+
});
|
|
390
|
+
const application = Layer.mergeAll(channelApps.length > 0
|
|
391
|
+
? Layer.merge(channelSessionLayer(config), channelSignInLayer(channelApps, config, connections))
|
|
392
|
+
: Layer.empty, federationLayer(federationConfig, verifyToken, { ontology, browserRevision }), routes, preview
|
|
393
|
+
? Layer.empty
|
|
394
|
+
: chatRoutes({
|
|
395
|
+
built,
|
|
396
|
+
hooks,
|
|
397
|
+
connections,
|
|
398
|
+
replicate,
|
|
399
|
+
chatDelivery,
|
|
400
|
+
conversations,
|
|
401
|
+
verifyToken,
|
|
402
|
+
verifyRuntime,
|
|
403
|
+
exchangeSession,
|
|
404
|
+
}), mcp, agent, agentTasks, attachments, memberFileRoutes({
|
|
405
|
+
plan: built.plan,
|
|
406
|
+
hooks,
|
|
407
|
+
connections,
|
|
408
|
+
replicate,
|
|
409
|
+
chatDelivery,
|
|
410
|
+
verifyToken,
|
|
411
|
+
exchangeSession,
|
|
412
|
+
}), preview ? Layer.empty : filesLayer({ plan: built.plan, verifyRuntime }), conversations === undefined
|
|
413
|
+
? Layer.empty
|
|
414
|
+
: conversationRoutes({
|
|
415
|
+
transport: conversations,
|
|
416
|
+
verifyToken,
|
|
417
|
+
verifyRuntime,
|
|
418
|
+
exchangeSession,
|
|
419
|
+
}), workflowsLayer({
|
|
420
|
+
deployment,
|
|
421
|
+
plan: built.plan,
|
|
422
|
+
hooks,
|
|
423
|
+
connections,
|
|
424
|
+
replicate,
|
|
425
|
+
chatDelivery,
|
|
426
|
+
verifyToken,
|
|
427
|
+
verifyRuntime,
|
|
428
|
+
exchangeSession,
|
|
429
|
+
workspaceId: config.workspaceId,
|
|
430
|
+
cronSecret: config.cronSecret,
|
|
431
|
+
engine: workflowEngine,
|
|
432
|
+
agentOrigin: config.agentOrigin,
|
|
433
|
+
agentTransport: config.agentTaskTransport,
|
|
434
|
+
webhookSecret: config.webhookSecret,
|
|
435
|
+
webhookVerifier: config.webhookVerifier ??
|
|
436
|
+
deployedWebhookVerifier({
|
|
437
|
+
segmentstreamUrl: config.segmentstreamUrl,
|
|
438
|
+
workspaceId: config.workspaceId,
|
|
439
|
+
organizationId: config.organizationId,
|
|
440
|
+
deploymentId: deployment.deploymentId,
|
|
441
|
+
...(preview ? { previewCredential: config.appCredential } : {}),
|
|
442
|
+
}),
|
|
443
|
+
webhookTokenVerifier: config.webhookTokenVerifier ??
|
|
444
|
+
deployedWebhookTokenVerifier({
|
|
445
|
+
segmentstreamUrl: config.segmentstreamUrl,
|
|
446
|
+
workspaceId: config.workspaceId,
|
|
447
|
+
organizationId: config.organizationId,
|
|
448
|
+
deploymentId: deployment.deploymentId,
|
|
449
|
+
...(preview ? { previewCredential: config.appCredential } : {}),
|
|
450
|
+
}),
|
|
451
|
+
}), DocsRoute, unmatchedRoutes(plan, verifyToken, exchangeSession, verifyRuntime)).pipe(Layer.provide(Layer.succeed(RuntimeDeployment, deployment)), Layer.provide(backend), Layer.provide(Layer.succeed(WarehouseQueries)(config.warehouseQueries ??
|
|
452
|
+
platformWarehouseQueries({ ...config, manifestHash: ontology.manifest.hash }))), Layer.provide(HttpServer.layerServices));
|
|
453
|
+
const web = HttpRouter.toWebHandler(application, { disableLogger: true });
|
|
454
|
+
const hash = ontology.manifest.hash;
|
|
455
|
+
// Only names from the deployed plan enter diagnostics; arbitrary path segments may be private.
|
|
456
|
+
function operationOf(request) {
|
|
457
|
+
const path = new URL(request.url).pathname;
|
|
458
|
+
const parts = path.split("/");
|
|
459
|
+
const entity = plan.entities.find((candidate) => candidate.name === parts[3]);
|
|
460
|
+
if (parts[1] === "api" && parts[2] === "ontology" && entity !== undefined) {
|
|
461
|
+
return `/api/ontology/${entity.name}/*`;
|
|
462
|
+
}
|
|
463
|
+
if (parts[1] === "api" && parts[2] === "webhooks") {
|
|
464
|
+
const declared = ontology.workflows.some((workflow) => workflow.triggers.some((trigger) => trigger.kind === "webhook" && trigger.name === parts[3]));
|
|
465
|
+
// Never the token segment.
|
|
466
|
+
return declared ? `/api/webhooks/${parts[3]}` : "/api/webhooks/*";
|
|
467
|
+
}
|
|
468
|
+
return path === "/mcp" ? "/mcp" : "/api/ontology/*";
|
|
469
|
+
}
|
|
470
|
+
return {
|
|
471
|
+
api: built.api,
|
|
472
|
+
dispose: web.dispose,
|
|
473
|
+
async handler(request) {
|
|
474
|
+
const started = performance.now();
|
|
475
|
+
const requestId = crypto.randomUUID();
|
|
476
|
+
const logMcpRequest = observeMcpRequest(request);
|
|
477
|
+
let response;
|
|
478
|
+
try {
|
|
479
|
+
requireDeploymentCapability(deployment);
|
|
480
|
+
if (preview) {
|
|
481
|
+
const path = new URL(request.url).pathname;
|
|
482
|
+
const blocked = /^\/api\/ontology\/(?:agent|agents|chat|conversations|attachments|channels)(?:\/|$)/.test(path)
|
|
483
|
+
? "agents"
|
|
484
|
+
: undefined;
|
|
485
|
+
if (blocked) {
|
|
486
|
+
throw new DeploymentAdmissionError("preview_capability_unavailable", blocked);
|
|
487
|
+
}
|
|
488
|
+
if (/^\/api\/ontology\/(?:oauth|oidc)(?:\/|$)/.test(path) ||
|
|
489
|
+
(!browser && /^\/api\/ontology\/federation(?:\/|$)/.test(path)) ||
|
|
490
|
+
path.startsWith("/.well-known/oauth")) {
|
|
491
|
+
throw new DeploymentAdmissionError("preview_authentication_unavailable");
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
response = await web.handler(request, Context.make(RequestId, requestId));
|
|
495
|
+
}
|
|
496
|
+
catch (error) {
|
|
497
|
+
if (error instanceof DeploymentAdmissionError) {
|
|
498
|
+
response = Response.json({
|
|
499
|
+
error: error.code,
|
|
500
|
+
detail: error.code,
|
|
501
|
+
request_id: requestId,
|
|
502
|
+
...(error.capability ? { capability: error.capability } : {}),
|
|
503
|
+
}, { status: error.status });
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
// The runtime could not be built or the router itself failed: log everything, answer little.
|
|
507
|
+
captureRuntimeFailure(error, { service: "ontology", boundary: "ontology.request.failed", requestId }, process.env, runtimeFailureValues(config));
|
|
508
|
+
const failure = internalError(requestId);
|
|
509
|
+
response = Response.json(errorBodyForWire(failure.body), { status: failure.status });
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
const durationMs = Math.round((performance.now() - started) * 100) / 100;
|
|
513
|
+
const timing = {
|
|
514
|
+
requestId,
|
|
515
|
+
at: new Date().toISOString(),
|
|
516
|
+
operation: operationOf(request),
|
|
517
|
+
method: request.method,
|
|
518
|
+
status: response.status,
|
|
519
|
+
durationMs,
|
|
520
|
+
};
|
|
521
|
+
console.info(JSON.stringify({ event: "ontology.request", ...timing }));
|
|
522
|
+
await logMcpRequest?.(response, requestId, durationMs);
|
|
523
|
+
return decorate(response, requestId, hash, durationMs);
|
|
524
|
+
},
|
|
525
|
+
};
|
|
526
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Context, Effect } from "effect";
|
|
2
|
+
import type { StoredRecord } from "../runtime.js";
|
|
3
|
+
import { type MetricQueryEnvironment } from "./metric-query-platform.js";
|
|
4
|
+
import { WarehouseReadUnavailable } from "./errors.js";
|
|
5
|
+
import type { WarehouseStatement } from "./warehouse-query.js";
|
|
6
|
+
export type WarehouseReadTransport = (input: {
|
|
7
|
+
readonly statement: WarehouseStatement;
|
|
8
|
+
readonly requestId: string;
|
|
9
|
+
readonly principalId: string;
|
|
10
|
+
}) => Effect.Effect<ReadonlyArray<StoredRecord>, WarehouseReadUnavailable>;
|
|
11
|
+
declare const WarehouseQueries_base: Context.ServiceClass<WarehouseQueries, "@segmentstream/ontology/WarehouseQueries", WarehouseReadTransport>;
|
|
12
|
+
/** One shared deployment budget, used by REST and MCP alike. */
|
|
13
|
+
export declare class WarehouseQueries extends WarehouseQueries_base {
|
|
14
|
+
}
|
|
15
|
+
/** Uses the existing workspace-scoped, byte-limited read-only warehouse query API. */
|
|
16
|
+
export declare function platformWarehouseQueries(environment: MetricQueryEnvironment, fetchImpl?: typeof fetch): WarehouseReadTransport;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Context, Effect, Redacted } from "effect";
|
|
2
|
+
import { describeError, securePlatform, } from "./metric-query-platform.js";
|
|
3
|
+
import { WarehouseReadUnavailable } from "./errors.js";
|
|
4
|
+
import { fixedWindowLimiter } from "./rate-limit.js";
|
|
5
|
+
/** One shared deployment budget, used by REST and MCP alike. */
|
|
6
|
+
export class WarehouseQueries extends Context.Service()("@segmentstream/ontology/WarehouseQueries") {
|
|
7
|
+
}
|
|
8
|
+
function object(value) {
|
|
9
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
10
|
+
}
|
|
11
|
+
/** Uses the existing workspace-scoped, byte-limited read-only warehouse query API. */
|
|
12
|
+
export function platformWarehouseQueries(environment, fetchImpl = fetch) {
|
|
13
|
+
const limiter = fixedWindowLimiter({ limit: 30, windowMs: 60_000, maxKeys: 10_000 });
|
|
14
|
+
const credential = environment.appCredential === undefined ? undefined : Redacted.value(environment.appCredential);
|
|
15
|
+
const configured = credential !== undefined && securePlatform(environment.segmentstreamUrl);
|
|
16
|
+
const base = `${environment.segmentstreamUrl.replace(/\/$/, "")}/api/v1/workspaces/` +
|
|
17
|
+
`${encodeURIComponent(environment.workspaceId)}/warehouse/queries`;
|
|
18
|
+
return (input) => Effect.gen(function* () {
|
|
19
|
+
if (!configured || credential === undefined) {
|
|
20
|
+
return yield* new WarehouseReadUnavailable({ reason: "not_configured" });
|
|
21
|
+
}
|
|
22
|
+
const retryAfterSeconds = limiter.take(input.principalId);
|
|
23
|
+
if (retryAfterSeconds !== undefined) {
|
|
24
|
+
return yield* new WarehouseReadUnavailable({ reason: "limited", retryAfterSeconds });
|
|
25
|
+
}
|
|
26
|
+
return yield* Effect.tryPromise({
|
|
27
|
+
try: async (signal) => {
|
|
28
|
+
const bounded = AbortSignal.any([signal, AbortSignal.timeout(60_000)]);
|
|
29
|
+
const pageSize = Math.min(input.statement.maxRows, 1000);
|
|
30
|
+
const send = async (url, body) => {
|
|
31
|
+
const response = await fetchImpl(url, {
|
|
32
|
+
method: body === undefined ? "GET" : "POST",
|
|
33
|
+
headers: {
|
|
34
|
+
authorization: `Bearer ${credential}`,
|
|
35
|
+
"content-type": "application/json",
|
|
36
|
+
"x-segmentstream-request-id": input.requestId,
|
|
37
|
+
},
|
|
38
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
39
|
+
redirect: "error",
|
|
40
|
+
signal: bounded,
|
|
41
|
+
});
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
const correlation = response.headers.get("x-request-id") ?? "unknown";
|
|
44
|
+
throw new Error(`Warehouse query failed: HTTP ${response.status}; request ${correlation}.`);
|
|
45
|
+
}
|
|
46
|
+
const payload = await response.json();
|
|
47
|
+
if (!object(payload) ||
|
|
48
|
+
!object(payload.query) ||
|
|
49
|
+
!["running", "done"].includes(String(payload.query.state))) {
|
|
50
|
+
throw new Error("Invalid warehouse query response.");
|
|
51
|
+
}
|
|
52
|
+
return payload.query;
|
|
53
|
+
};
|
|
54
|
+
let page = await send(base, {
|
|
55
|
+
sql: input.statement.sql,
|
|
56
|
+
parameters: input.statement.parameters,
|
|
57
|
+
pageSize,
|
|
58
|
+
});
|
|
59
|
+
const queryId = page.id;
|
|
60
|
+
const read = (pageToken) => {
|
|
61
|
+
if (typeof queryId !== "string" || queryId === "") {
|
|
62
|
+
throw new Error("The warehouse query has no continuation id.");
|
|
63
|
+
}
|
|
64
|
+
const search = new URLSearchParams({ pageSize: String(pageSize) });
|
|
65
|
+
if (pageToken !== undefined) {
|
|
66
|
+
search.set("pageToken", pageToken);
|
|
67
|
+
}
|
|
68
|
+
return send(`${base}/${encodeURIComponent(queryId)}?${search}`);
|
|
69
|
+
};
|
|
70
|
+
while (page.state === "running") {
|
|
71
|
+
await new Promise((resolve, reject) => {
|
|
72
|
+
const finish = () => {
|
|
73
|
+
bounded.removeEventListener("abort", abort);
|
|
74
|
+
resolve();
|
|
75
|
+
};
|
|
76
|
+
const timer = setTimeout(finish, 250);
|
|
77
|
+
const abort = () => {
|
|
78
|
+
clearTimeout(timer);
|
|
79
|
+
reject(bounded.reason);
|
|
80
|
+
};
|
|
81
|
+
if (bounded.aborted) {
|
|
82
|
+
abort();
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
bounded.addEventListener("abort", abort, { once: true });
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
page = await read();
|
|
89
|
+
}
|
|
90
|
+
const records = [];
|
|
91
|
+
const tokens = new Set();
|
|
92
|
+
for (;;) {
|
|
93
|
+
if (!Array.isArray(page.rows) || !page.rows.every(object)) {
|
|
94
|
+
throw new Error("Invalid warehouse record rows.");
|
|
95
|
+
}
|
|
96
|
+
records.push(...page.rows);
|
|
97
|
+
if (records.length > input.statement.maxRows) {
|
|
98
|
+
throw new Error("The warehouse exceeded the bounded record query.");
|
|
99
|
+
}
|
|
100
|
+
const token = page.nextPageToken;
|
|
101
|
+
if (token === undefined || token === null || token === "") {
|
|
102
|
+
return records;
|
|
103
|
+
}
|
|
104
|
+
if (typeof token !== "string" ||
|
|
105
|
+
tokens.has(token) ||
|
|
106
|
+
records.length >= input.statement.maxRows) {
|
|
107
|
+
throw new Error("Invalid warehouse continuation.");
|
|
108
|
+
}
|
|
109
|
+
tokens.add(token);
|
|
110
|
+
page = await read(token);
|
|
111
|
+
if (page.state !== "done") {
|
|
112
|
+
throw new Error("A completed warehouse page became pending.");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
catch: (cause) => cause,
|
|
117
|
+
}).pipe(Effect.catch((cause) => Effect.logWarning("ontology.warehouse_records.failed").pipe(Effect.annotateLogs({
|
|
118
|
+
requestId: input.requestId,
|
|
119
|
+
cause: describeError(cause, (text) => text.split(credential).join("[redacted]")),
|
|
120
|
+
}), Effect.andThen(Effect.fail(new WarehouseReadUnavailable({ reason: "upstream", cause }))))));
|
|
121
|
+
});
|
|
122
|
+
}
|