@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
package/dist/render.js
ADDED
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
import { inputEntities, shortestRoutesFrom } from "./metric-routes.js";
|
|
2
|
+
import { QUERY_METRICS_ROUTE } from "./names.js";
|
|
3
|
+
import { isAllowed, permissionOf, READ_VERB, rolesGranting } from "./permissions.js";
|
|
4
|
+
import { REFERENCE_ANNOTATION } from "./property.js";
|
|
5
|
+
/** What an action of the manifest requires; version 1 manifests leave it implicit. */
|
|
6
|
+
export function actionPermission(entity, action) {
|
|
7
|
+
return action.permission ?? permissionOf(entity, action.name);
|
|
8
|
+
}
|
|
9
|
+
/** `Requires lead:changeStatus (member, sales).`: the permission and the roles that grant it. */
|
|
10
|
+
function requirement(subject, permission, roles) {
|
|
11
|
+
const granting = rolesGranting(roles, permission);
|
|
12
|
+
return granting.length === 0
|
|
13
|
+
? `${subject} ${permission}, which no role grants.`
|
|
14
|
+
: `${subject} ${permission} (${granting.join(", ")}).`;
|
|
15
|
+
}
|
|
16
|
+
const INDENT = " ";
|
|
17
|
+
function isRecord(value) {
|
|
18
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
function sentence(text) {
|
|
21
|
+
return /[.!?]$/.test(text) ? text : `${text}.`;
|
|
22
|
+
}
|
|
23
|
+
function withDescription(head, description) {
|
|
24
|
+
return description === undefined || description.length === 0 ? head : `${head}: ${description}`;
|
|
25
|
+
}
|
|
26
|
+
function formatValue(value) {
|
|
27
|
+
return typeof value === "string" ? value : JSON.stringify(value);
|
|
28
|
+
}
|
|
29
|
+
/** A warehouse-backed property's `unique` is an assertion the platform does not enforce. */
|
|
30
|
+
function propertyLines(input) {
|
|
31
|
+
const { property, warehouseBacked } = input;
|
|
32
|
+
const unique = warehouseBacked ? "unique, not enforced" : "unique";
|
|
33
|
+
const traits = [
|
|
34
|
+
property.type,
|
|
35
|
+
...(property.optional ? ["optional"] : []),
|
|
36
|
+
...(property.unique ? [unique] : []),
|
|
37
|
+
...(property.default !== undefined ? [`default ${formatValue(property.default)}`] : []),
|
|
38
|
+
...(property.min !== undefined ? [`min ${property.min}`] : []),
|
|
39
|
+
...(property.max !== undefined ? [`max ${property.max}`] : []),
|
|
40
|
+
...(property.maxLength !== undefined ? [`at most ${property.maxLength} characters`] : []),
|
|
41
|
+
...(property.managed ? ["changed only through actions"] : []),
|
|
42
|
+
];
|
|
43
|
+
const options = (property.options ?? []).map((option) => option.description.length === 0
|
|
44
|
+
? `${option.label} (${option.value})`
|
|
45
|
+
: `${option.label} (${option.value}) — ${option.description}`);
|
|
46
|
+
return [
|
|
47
|
+
withDescription(`${property.name} (${traits.join(", ")})`, property.description),
|
|
48
|
+
...options.map((option) => `${INDENT}${option}`),
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The inverse of a relationship as its target reads it, including its value-matched join key.
|
|
53
|
+
*/
|
|
54
|
+
function inverseLine(source, relationship) {
|
|
55
|
+
const { on, phrase, inverse } = relationship;
|
|
56
|
+
if (on === undefined) {
|
|
57
|
+
return `${phrase[1]} many ${source.plural} (${inverse})`;
|
|
58
|
+
}
|
|
59
|
+
return `${phrase[1]} ${source.plural} (${inverse}), matched on ${on.property}`;
|
|
60
|
+
}
|
|
61
|
+
function relationshipLines(entity, entities, all) {
|
|
62
|
+
const declared = entity.relationships.map((relationship) => {
|
|
63
|
+
const { on, phrase, name } = relationship;
|
|
64
|
+
const target = entities.get(relationship.to);
|
|
65
|
+
const label = target?.label ?? relationship.to;
|
|
66
|
+
const optional = relationship.optional === true ? ", optional" : "";
|
|
67
|
+
let head = `${phrase[0]} one ${label} (${name})${optional}`;
|
|
68
|
+
if (relationship.cardinality === "many") {
|
|
69
|
+
head = `${phrase[0]} many ${target?.plural ?? relationship.to} (${name})`;
|
|
70
|
+
}
|
|
71
|
+
else if (on !== undefined) {
|
|
72
|
+
// Value-matched: nothing promises a match, and the key is the declared property pair.
|
|
73
|
+
const key = `${on.property} = ${label}.${on.targetProperty}`;
|
|
74
|
+
head = `${phrase[0]} at most one ${label} (${name}), matched on ${key}`;
|
|
75
|
+
}
|
|
76
|
+
return withDescription(head, relationship.description);
|
|
77
|
+
});
|
|
78
|
+
const inverses = all.flatMap((source) => source.relationships
|
|
79
|
+
.filter((relationship) => relationship.to === entity.name)
|
|
80
|
+
.map((relationship) => inverseLine(source, relationship)));
|
|
81
|
+
return [...declared, ...inverses];
|
|
82
|
+
}
|
|
83
|
+
function inputType(schema) {
|
|
84
|
+
const reference = schema[REFERENCE_ANNOTATION];
|
|
85
|
+
if (typeof reference === "string") {
|
|
86
|
+
return `${reference} id`;
|
|
87
|
+
}
|
|
88
|
+
const branches = Array.isArray(schema.anyOf) ? schema.anyOf.filter(isRecord) : [];
|
|
89
|
+
const values = [
|
|
90
|
+
...(Array.isArray(schema.enum) ? schema.enum : []),
|
|
91
|
+
...branches.flatMap((branch) => (Array.isArray(branch.enum) ? branch.enum : [])),
|
|
92
|
+
];
|
|
93
|
+
if (values.length > 0) {
|
|
94
|
+
return `one of ${values.map(formatValue).join(", ")}`;
|
|
95
|
+
}
|
|
96
|
+
const formats = {
|
|
97
|
+
"date-time": "timestamp",
|
|
98
|
+
uri: "url",
|
|
99
|
+
uuid: "id",
|
|
100
|
+
};
|
|
101
|
+
if (typeof schema.format === "string") {
|
|
102
|
+
return formats[schema.format] ?? schema.format;
|
|
103
|
+
}
|
|
104
|
+
const types = { string: "text", array: "list" };
|
|
105
|
+
if (typeof schema.type === "string") {
|
|
106
|
+
return types[schema.type] ?? schema.type;
|
|
107
|
+
}
|
|
108
|
+
return typeof schema.$ref === "string" ? "object" : "any JSON value";
|
|
109
|
+
}
|
|
110
|
+
/** Input fields: required ones in declaration order, then optional ones by name. */
|
|
111
|
+
function inputLines(input) {
|
|
112
|
+
const properties = isRecord(input.properties) ? input.properties : {};
|
|
113
|
+
const required = Array.isArray(input.required)
|
|
114
|
+
? input.required.filter((name) => typeof name === "string")
|
|
115
|
+
: [];
|
|
116
|
+
const optional = Object.keys(properties)
|
|
117
|
+
.filter((name) => !required.includes(name))
|
|
118
|
+
.sort();
|
|
119
|
+
return [...required, ...optional].flatMap((name) => {
|
|
120
|
+
const schema = properties[name];
|
|
121
|
+
if (!isRecord(schema)) {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
const type = required.includes(name) ? inputType(schema) : `optional ${inputType(schema)}`;
|
|
125
|
+
const description = typeof schema.description === "string" ? schema.description : undefined;
|
|
126
|
+
return [withDescription(`${name} (${type})`, description)];
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
/** `Calls apollo: Apollo people search. Enriches new leads with company and title.` */
|
|
130
|
+
function connectionLines(action, connections) {
|
|
131
|
+
return (action.connections ?? []).map((key) => {
|
|
132
|
+
const description = connections.get(key);
|
|
133
|
+
return description === undefined || description === ""
|
|
134
|
+
? `Calls ${key}.`
|
|
135
|
+
: `Calls ${key}: ${sentence(description)}`;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function actionLines(action, required, connections) {
|
|
139
|
+
const input = inputLines(action.input);
|
|
140
|
+
return [
|
|
141
|
+
`${action.name} — ${action.description}`,
|
|
142
|
+
...(required !== undefined ? [`${INDENT}${required}`] : []),
|
|
143
|
+
...connectionLines(action, connections).map((line) => `${INDENT}${line}`),
|
|
144
|
+
...(input.length > 0
|
|
145
|
+
? [`${INDENT}Input:`, ...input.map((line) => `${INDENT}${INDENT}${line}`)]
|
|
146
|
+
: []),
|
|
147
|
+
];
|
|
148
|
+
}
|
|
149
|
+
function section(title, lines) {
|
|
150
|
+
return lines.length === 0
|
|
151
|
+
? []
|
|
152
|
+
: [`${INDENT}${title}:`, ...lines.map((line) => `${INDENT}${INDENT}${line}`)];
|
|
153
|
+
}
|
|
154
|
+
/** How a condition's operator reads between its property and its value. */
|
|
155
|
+
const CONDITION_OPERATORS = {
|
|
156
|
+
equals: "=",
|
|
157
|
+
notEquals: "!=",
|
|
158
|
+
gt: ">",
|
|
159
|
+
gte: ">=",
|
|
160
|
+
lt: "<",
|
|
161
|
+
lte: "<=",
|
|
162
|
+
contains: "contains",
|
|
163
|
+
startsWith: "starts with",
|
|
164
|
+
endsWith: "ends with",
|
|
165
|
+
};
|
|
166
|
+
function literal(value) {
|
|
167
|
+
return typeof value === "string" ? JSON.stringify(value) : String(value);
|
|
168
|
+
}
|
|
169
|
+
/** `status = "won"`, `status in ("won", "invoiced")`, `amount >= 100`, `name contains "x"`. */
|
|
170
|
+
function conditionText(condition, property) {
|
|
171
|
+
const { operator, value } = condition;
|
|
172
|
+
const values = Array.isArray(condition.values) ? condition.values : [];
|
|
173
|
+
const list = `(${values.map(literal).join(", ")})`;
|
|
174
|
+
switch (operator) {
|
|
175
|
+
case "in":
|
|
176
|
+
return `${property} in ${list}`;
|
|
177
|
+
case "notIn":
|
|
178
|
+
return `${property} not in ${list}`;
|
|
179
|
+
case "isNull":
|
|
180
|
+
return `${property} is null`;
|
|
181
|
+
case "isNotNull":
|
|
182
|
+
return `${property} is not null`;
|
|
183
|
+
case "between":
|
|
184
|
+
return `${property} between ${literal(values[0])} and ${literal(values[1])}`;
|
|
185
|
+
default: {
|
|
186
|
+
const symbol = CONDITION_OPERATORS[String(operator)] ?? String(operator);
|
|
187
|
+
return value === undefined
|
|
188
|
+
? `${property} ${symbol}`
|
|
189
|
+
: `${property} ${symbol} ${literal(value)}`;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/** How an aggregate reads in a sentence: `count`, `sum of amount`. */
|
|
194
|
+
const AGGREGATE_NAMES = {
|
|
195
|
+
count: "count",
|
|
196
|
+
sum: "sum",
|
|
197
|
+
countDistinct: "distinct count",
|
|
198
|
+
avg: "average",
|
|
199
|
+
min: "minimum",
|
|
200
|
+
max: "maximum",
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Every aggregate a metric reads: its own, top-level or inside arithmetic, and those of the
|
|
204
|
+
* metrics it references, followed once each.
|
|
205
|
+
*/
|
|
206
|
+
function readAggregates(entity, metric) {
|
|
207
|
+
const found = [];
|
|
208
|
+
const visited = new Set();
|
|
209
|
+
const visit = (expression, where, depth) => {
|
|
210
|
+
if (!isRecord(expression) || depth > 30) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const args = Array.isArray(expression.args) ? expression.args : [];
|
|
214
|
+
const name = AGGREGATE_NAMES[String(expression.op)];
|
|
215
|
+
if (expression.op === "filtered" && Array.isArray(expression.where)) {
|
|
216
|
+
const conditions = expression.where.filter(isRecord);
|
|
217
|
+
args.forEach((arg) => visit(arg, conditions, depth + 1));
|
|
218
|
+
}
|
|
219
|
+
else if (expression.op === "metric") {
|
|
220
|
+
const referenced = entity.metrics?.find((other) => other.name === expression.name);
|
|
221
|
+
if (referenced !== undefined && !visited.has(referenced.name)) {
|
|
222
|
+
visited.add(referenced.name);
|
|
223
|
+
visit(referenced.expression, undefined, depth + 1);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else if (name !== undefined) {
|
|
227
|
+
const [argument] = args;
|
|
228
|
+
const column = isRecord(argument) && argument.op === "column" ? argument.name : undefined;
|
|
229
|
+
found.push({ name, column, where });
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
args.forEach((arg) => visit(arg, where, depth + 1));
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
visited.add(metric.name);
|
|
236
|
+
visit(metric.expression, undefined, 0);
|
|
237
|
+
return found;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* The columns a metric is a balance over: its own `balanceOver`, and that of every metric its
|
|
241
|
+
* expression references, since an expression is a balance when any metric it reads is.
|
|
242
|
+
*/
|
|
243
|
+
function balanceColumns(entity, metric) {
|
|
244
|
+
const columns = new Set();
|
|
245
|
+
const visited = new Set();
|
|
246
|
+
const visit = (candidate) => {
|
|
247
|
+
if (visited.has(candidate.name)) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
visited.add(candidate.name);
|
|
251
|
+
if (candidate.balanceOver !== undefined) {
|
|
252
|
+
columns.add(candidate.balanceOver);
|
|
253
|
+
}
|
|
254
|
+
for (const name of referencedMetrics(candidate.expression)) {
|
|
255
|
+
const referenced = entity.metrics?.find((other) => other.name === name);
|
|
256
|
+
if (referenced !== undefined) {
|
|
257
|
+
visit(referenced);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
visit(metric);
|
|
262
|
+
return [...columns];
|
|
263
|
+
}
|
|
264
|
+
function referencedMetrics(expression) {
|
|
265
|
+
if (!isRecord(expression)) {
|
|
266
|
+
return [];
|
|
267
|
+
}
|
|
268
|
+
if (expression.op === "metric" && typeof expression.name === "string") {
|
|
269
|
+
return [expression.name];
|
|
270
|
+
}
|
|
271
|
+
return Array.isArray(expression.args) ? expression.args.flatMap(referencedMetrics) : [];
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* What a metric's definition adds to its description: the conditions its aggregates read rows by,
|
|
275
|
+
* and the property a balance must be grouped by or filtered to one day of. `Where …` only when every
|
|
276
|
+
* aggregate it reads, references followed, has the same conditions; otherwise a sentence per
|
|
277
|
+
* restricted aggregate. Columns read as the properties that map them, the names requests use.
|
|
278
|
+
*/
|
|
279
|
+
function metricNotes(entity, metric) {
|
|
280
|
+
const propertyOf = (column) => entity.properties.find((property) => (property.column ?? property.name) === column)?.name ??
|
|
281
|
+
String(column);
|
|
282
|
+
const aggregates = readAggregates(entity, metric).map(({ name, column, where }) => ({
|
|
283
|
+
name: column === undefined ? name : `${name} of ${propertyOf(column)}`,
|
|
284
|
+
conditions: where
|
|
285
|
+
?.map((condition) => conditionText(condition, propertyOf(condition.column)))
|
|
286
|
+
.join(" and "),
|
|
287
|
+
}));
|
|
288
|
+
const conditions = aggregates.map((aggregate) => aggregate.conditions);
|
|
289
|
+
const [first] = conditions;
|
|
290
|
+
const balances = balanceColumns(entity, metric).map((column) => `Balance over ${propertyOf(column)}: group by it or filter it to one day.`);
|
|
291
|
+
// "Where" holds only when every aggregate, references followed, reads by the same condition.
|
|
292
|
+
if (first !== undefined && conditions.every((candidate) => candidate === first)) {
|
|
293
|
+
return [`Where ${first}.`, ...balances];
|
|
294
|
+
}
|
|
295
|
+
const restricted = aggregates.flatMap(({ name, conditions: text }) => text === undefined ? [] : [`Its ${name} reads rows where ${text}.`]);
|
|
296
|
+
return [...new Set(restricted), ...balances];
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* A metric's description followed by its conditions and balance note, as `describe`, the MCP
|
|
300
|
+
* metric list and the console show it: `Revenue of won orders. Where status = "won".`
|
|
301
|
+
*/
|
|
302
|
+
export function metricDescription(entity, metric) {
|
|
303
|
+
const notes = metricNotes(entity, metric);
|
|
304
|
+
if (notes.length === 0) {
|
|
305
|
+
return metric.description;
|
|
306
|
+
}
|
|
307
|
+
const described = metric.description === "" ? [] : [sentence(metric.description)];
|
|
308
|
+
return [...described, ...notes].join(" ");
|
|
309
|
+
}
|
|
310
|
+
function renderEntity(entity, manifest, entities, options) {
|
|
311
|
+
const reader = options.as;
|
|
312
|
+
const actions = entity.actions.filter((action) => reader === undefined ||
|
|
313
|
+
isAllowed(actionPermission(entity.name, action), { permissions: reader }));
|
|
314
|
+
const read = entity.permissions?.read ?? permissionOf(entity.name, READ_VERB);
|
|
315
|
+
const connections = new Map((manifest.connections ?? []).map((connection) => [connection.key, connection.description]));
|
|
316
|
+
return [
|
|
317
|
+
`${entity.label} (${entity.plural.toLowerCase()}): ${entity.description}`,
|
|
318
|
+
`${INDENT}Identified by: ${entity.title}.`,
|
|
319
|
+
...(reader === undefined
|
|
320
|
+
? [`${INDENT}${requirement("Reading requires", read, manifest.roles)}`]
|
|
321
|
+
: []),
|
|
322
|
+
...(entity.source
|
|
323
|
+
? [`${INDENT}Source: ${entity.source.asset}; key: ${entity.source.key.join(", ")}.`]
|
|
324
|
+
: []),
|
|
325
|
+
...section("Properties", entity.properties.flatMap((property) => propertyLines({ property, warehouseBacked: entity.source !== undefined }))),
|
|
326
|
+
...section("Metrics", (entity.metrics ?? []).map((metric) => `${metric.name}: ${metricDescription(entity, metric)} (${metric.unit}).`)),
|
|
327
|
+
...section("Relationships", relationshipLines(entity, entities, manifest.entities)),
|
|
328
|
+
...section(reader === undefined ? "Actions" : "Actions you may run", actions.flatMap((action) => actionLines(action, reader === undefined
|
|
329
|
+
? requirement("Requires", actionPermission(entity.name, action), manifest.roles)
|
|
330
|
+
: undefined, connections))),
|
|
331
|
+
].join("\n");
|
|
332
|
+
}
|
|
333
|
+
function renderRoles(roles) {
|
|
334
|
+
return [
|
|
335
|
+
"Roles:",
|
|
336
|
+
...roles.flatMap((role) => [
|
|
337
|
+
`${INDENT}${role.name} — ${sentence(role.description)}`,
|
|
338
|
+
...(role.permissions === undefined
|
|
339
|
+
? []
|
|
340
|
+
: [
|
|
341
|
+
`${INDENT}${INDENT}Permissions: ${role.permissions.length === 0 ? "none" : role.permissions.join(", ")}.`,
|
|
342
|
+
]),
|
|
343
|
+
...(role.scopes ?? []).map((scope) => `${INDENT}${INDENT}Scoped: ${scope.permission} where ${JSON.stringify(scope.where)}.`),
|
|
344
|
+
]),
|
|
345
|
+
].join("\n");
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Renders the catalog as prose for agents and people: each entity with its properties, both
|
|
349
|
+
* directions of its relationships and its actions, then the roles with their permissions and the
|
|
350
|
+
* `where`, in wire form, of each scoped one. Without a reader, each action and each entity's reads
|
|
351
|
+
* say which permission they require and which roles grant it; with one, only the actions the reader
|
|
352
|
+
* may run are listed. A pure function of the manifest, so the console, the CLI and the service
|
|
353
|
+
* describe the same ontology.
|
|
354
|
+
*/
|
|
355
|
+
export function renderCatalog(manifest, options = {}) {
|
|
356
|
+
const entities = new Map(manifest.entities.map((entity) => [entity.name, entity]));
|
|
357
|
+
const sections = manifest.entities
|
|
358
|
+
.filter((entity) => entity.source === undefined ||
|
|
359
|
+
options.as === undefined ||
|
|
360
|
+
isAllowed(entity.permissions?.read ?? `${entity.name}:read`, { permissions: options.as }))
|
|
361
|
+
.map((entity) => renderEntity(entity, manifest, entities, options));
|
|
362
|
+
if (manifest.feedback !== undefined) {
|
|
363
|
+
sections.unshift(`Feedback: ${manifest.feedback.enabled ? "enabled" : "disabled"}; ` +
|
|
364
|
+
`files: ${manifest.feedback.files ? "enabled" : "disabled"} (explicit setting or another non-feedback blob); ` +
|
|
365
|
+
`builders: ${manifest.feedback.builders.join(", ") || "none"}.`);
|
|
366
|
+
}
|
|
367
|
+
const metricQueries = renderMetricQueries(manifest, options.as);
|
|
368
|
+
const parts = [
|
|
369
|
+
...sections,
|
|
370
|
+
renderRoles(manifest.roles),
|
|
371
|
+
...(metricQueries === "" ? [] : [metricQueries]),
|
|
372
|
+
];
|
|
373
|
+
return `${parts.join("\n\n")}\n`;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* The catalog as `describe` answers a reader: {@link renderCatalog} with the reader's permissions,
|
|
377
|
+
* or everything without them.
|
|
378
|
+
*/
|
|
379
|
+
export function describeCatalog(manifest, permissions) {
|
|
380
|
+
return renderCatalog(manifest, permissions === undefined ? {} : { as: permissions });
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* The rule every surface repeats (docs/ontology-aggregates-spec.md, "Three ways to ask"), naming
|
|
384
|
+
* the tool that computes metrics.
|
|
385
|
+
*/
|
|
386
|
+
export const RECORDS_OR_METRIC_QUERIES = "look at or change records through find and actions; count, sum or compare through query_metrics";
|
|
387
|
+
/** Whether the reader may read the entity; without a reader, everything is described. */
|
|
388
|
+
function readable(entity, permissions) {
|
|
389
|
+
return permissions === undefined || isAllowed(permissionOf(entity, READ_VERB), { permissions });
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Every metric of the entities the reader may read, warehouse-backed and stored alike, in
|
|
393
|
+
* declaration order. Without permissions, every metric.
|
|
394
|
+
*/
|
|
395
|
+
export function metricsFor(manifest, permissions) {
|
|
396
|
+
return manifest.entities
|
|
397
|
+
.filter((entity) => readable(entity.name, permissions))
|
|
398
|
+
.flatMap((entity) => (entity.metrics ?? []).map((metric) => ({
|
|
399
|
+
name: `${entity.name}.${metric.name}`,
|
|
400
|
+
entity,
|
|
401
|
+
metric,
|
|
402
|
+
})));
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* The metrics of the model whose every input entity the reader may read, in declaration order.
|
|
406
|
+
* Reading a model metric is reading its inputs. Without permissions, every one.
|
|
407
|
+
*/
|
|
408
|
+
export function modelMetricsFor(manifest, permissions) {
|
|
409
|
+
return (manifest.metrics ?? []).filter((metric) => inputEntities(metric).every((entity) => readable(entity, permissions)));
|
|
410
|
+
}
|
|
411
|
+
/** `a`, `a and b`, `a, b and c`. */
|
|
412
|
+
function listed(values) {
|
|
413
|
+
return values.length < 2
|
|
414
|
+
? values.join("")
|
|
415
|
+
: `${values.slice(0, -1).join(", ")} and ${values[values.length - 1]}`;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* How one alignment group reads: `sales.order_date aligns with plans.month`, and for an entity
|
|
419
|
+
* without a counterpart `listings has no counterpart for sales.order_date`. Members follow the
|
|
420
|
+
* metric's input entities, whatever order the document keeps them in.
|
|
421
|
+
*/
|
|
422
|
+
function alignmentClauses(metric, group) {
|
|
423
|
+
const order = inputEntities(metric);
|
|
424
|
+
const members = Object.entries(group).sort(([left], [right]) => order.indexOf(left) - order.indexOf(right));
|
|
425
|
+
const present = members.flatMap(([entity, property]) => property === null ? [] : [`${entity}.${property}`]);
|
|
426
|
+
const absent = members.flatMap(([entity, property]) => (property === null ? [entity] : []));
|
|
427
|
+
const [first, ...rest] = present;
|
|
428
|
+
if (first === undefined) {
|
|
429
|
+
return [];
|
|
430
|
+
}
|
|
431
|
+
return [
|
|
432
|
+
...(rest.length > 0 ? [`${first} aligns with ${listed(rest)}`] : []),
|
|
433
|
+
...absent.map((entity) => `${entity} has no counterpart for ${first}`),
|
|
434
|
+
];
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* A metric of the model as `describe`, the MCP tool and the instructions show it: its description,
|
|
438
|
+
* the entity metrics it reads and how their properties align. `Ordered over planned units. Reads
|
|
439
|
+
* sales.ordered and plans.planned_units; sales.order_date aligns with plans.month.`
|
|
440
|
+
*/
|
|
441
|
+
export function modelMetricDescription(metric) {
|
|
442
|
+
const clauses = [
|
|
443
|
+
`Reads ${listed(metric.inputs)}`,
|
|
444
|
+
...metric.align.flatMap((group) => alignmentClauses(metric, group)),
|
|
445
|
+
];
|
|
446
|
+
const described = metric.description === "" ? [] : [sentence(metric.description)];
|
|
447
|
+
return [...described, `${clauses.join("; ")}.`].join(" ");
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* The entities one entity reaches, with the shortest routes to each: exactly the routes metric query
|
|
451
|
+
* resolution weighs ({@link shortestRoutesFrom}). Only then is the reader applied: a target they may
|
|
452
|
+
* not read is left out, and so is any route through an entity they may not read, which the service
|
|
453
|
+
* would refuse. A target keeps `ambiguous` from before that filter, so a route is never shown as the
|
|
454
|
+
* only one when the resolver would ask for it to be written.
|
|
455
|
+
*/
|
|
456
|
+
export function reachesOf(manifest, from, permissions) {
|
|
457
|
+
return [...shortestRoutesFrom(manifest, from)].flatMap(([target, routes]) => {
|
|
458
|
+
const followed = routes.filter((route) => route.entities.every((entity) => readable(entity, permissions)));
|
|
459
|
+
return followed.length === 0
|
|
460
|
+
? []
|
|
461
|
+
: [
|
|
462
|
+
{
|
|
463
|
+
target,
|
|
464
|
+
routes: followed.map((route) => route.relationships.join(".")),
|
|
465
|
+
ambiguous: routes.length > 1,
|
|
466
|
+
},
|
|
467
|
+
];
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
/** `sales reaches product (product), region (product.region or listing.region; write the route).` */
|
|
471
|
+
function reachLine(entity, reaches) {
|
|
472
|
+
const targets = reaches.map(({ target, routes, ambiguous }) => `${target} (${routes.join(" or ")}${ambiguous ? "; write the route" : ""})`);
|
|
473
|
+
return `${entity} reaches ${targets.join(", ")}.`;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* The metric query part of the catalog's prose: every metric the reader may read, model-wide, the
|
|
477
|
+
* metrics of the model whose every input they may read, and per metric entity the entities it
|
|
478
|
+
* reaches. Empty when the reader may read no metric.
|
|
479
|
+
*/
|
|
480
|
+
export function renderMetricQueries(manifest, permissions) {
|
|
481
|
+
const metrics = metricsFor(manifest, permissions);
|
|
482
|
+
if (metrics.length === 0) {
|
|
483
|
+
return "";
|
|
484
|
+
}
|
|
485
|
+
const owners = [...new Set(metrics.map(({ entity }) => entity.name))];
|
|
486
|
+
const reachLines = owners.flatMap((owner) => {
|
|
487
|
+
const reaches = reachesOf(manifest, owner, permissions);
|
|
488
|
+
return reaches.length === 0 ? [] : [reachLine(owner, reaches)];
|
|
489
|
+
});
|
|
490
|
+
const metricLines = metrics.map(({ name, entity, metric }) => `${name} (${metric.unit}): ${sentence(metricDescription(entity, metric))}`);
|
|
491
|
+
const modelLines = modelMetricsFor(manifest, permissions).map((metric) => `${metric.name} (${metric.unit}): ${modelMetricDescription(metric)}`);
|
|
492
|
+
return [
|
|
493
|
+
`Metric queries: ${RECORDS_OR_METRIC_QUERIES} (POST /api/ontology/${QUERY_METRICS_ROUTE}, or the ` +
|
|
494
|
+
"query_metrics tool).",
|
|
495
|
+
`${INDENT}Metrics, as <entity>.<metric>:`,
|
|
496
|
+
...metricLines.map((line) => `${INDENT}${INDENT}${line}`),
|
|
497
|
+
...(modelLines.length === 0
|
|
498
|
+
? []
|
|
499
|
+
: [
|
|
500
|
+
`${INDENT}Metrics of the model, by name:`,
|
|
501
|
+
...modelLines.map((line) => `${INDENT}${INDENT}${line}`),
|
|
502
|
+
]),
|
|
503
|
+
...(reachLines.length === 0
|
|
504
|
+
? []
|
|
505
|
+
: [
|
|
506
|
+
`${INDENT}Group and filter by <entity>.<property>. Where a target says write the route, ` +
|
|
507
|
+
"name it from the metric's entity: <entity>.<relationship>.<property>. Through " +
|
|
508
|
+
"to-one relationships:",
|
|
509
|
+
...reachLines.map((line) => `${INDENT}${INDENT}${line}`),
|
|
510
|
+
]),
|
|
511
|
+
].join("\n");
|
|
512
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import type { SqlClient } from "effect/unstable/sql";
|
|
3
|
+
import type { OntologyManifest } from "../manifest.js";
|
|
4
|
+
import { type ReplicationFills, type ReplicationSelection, type ReplicationExclusion } from "./model.js";
|
|
5
|
+
import type { ReplicationLineage } from "./lineage.js";
|
|
6
|
+
export interface ReplicationTarget {
|
|
7
|
+
readonly generation: string;
|
|
8
|
+
readonly source_id: string;
|
|
9
|
+
readonly from_revision: string;
|
|
10
|
+
readonly manifest: OntologyManifest;
|
|
11
|
+
readonly selection: ReadonlyArray<ReplicationSelection>;
|
|
12
|
+
readonly protocol?: number;
|
|
13
|
+
readonly schema_version?: number;
|
|
14
|
+
readonly lineage?: ReplicationLineage | null;
|
|
15
|
+
readonly identities?: import("./identities.js").ReplicationIdentities | null;
|
|
16
|
+
readonly scans_complete?: boolean;
|
|
17
|
+
readonly backfill_sources?: ReadonlyArray<{
|
|
18
|
+
readonly table: string | null;
|
|
19
|
+
readonly skip?: boolean;
|
|
20
|
+
}>;
|
|
21
|
+
readonly baseline_complete?: boolean;
|
|
22
|
+
readonly backfill_complete?: boolean;
|
|
23
|
+
readonly initial_revision?: string | null;
|
|
24
|
+
readonly replay_complete?: boolean;
|
|
25
|
+
readonly fills?: ReplicationFills;
|
|
26
|
+
}
|
|
27
|
+
declare const ReplicationBaselineFailed_base: Schema.Class<ReplicationBaselineFailed, Schema.TaggedStruct<"ReplicationBaselineFailed", {
|
|
28
|
+
readonly message: Schema.String;
|
|
29
|
+
readonly cause: Schema.optionalKey<Schema.Unknown>;
|
|
30
|
+
}>, import("effect/Cause").YieldableError>;
|
|
31
|
+
/** An initial scan cannot be created with the requested state or record projection. */
|
|
32
|
+
export declare class ReplicationBaselineFailed extends ReplicationBaselineFailed_base {
|
|
33
|
+
}
|
|
34
|
+
interface BaselineInput {
|
|
35
|
+
readonly generation: string;
|
|
36
|
+
readonly manifest: OntologyManifest;
|
|
37
|
+
readonly exclusions?: ReadonlyArray<ReplicationExclusion>;
|
|
38
|
+
readonly selection: ReadonlyArray<ReplicationSelection>;
|
|
39
|
+
readonly newSource?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/** Enable capture in a short fenced transaction before scanning any business records. */
|
|
42
|
+
export declare const prepareReplicationBaseline: (sql: SqlClient.SqlClient, input: BaselineInput) => Effect.Effect<ReplicationTarget, import("effect/unstable/sql/SqlError").SqlError | ReplicationBaselineFailed, never>;
|
|
43
|
+
/**
|
|
44
|
+
* Commit one keyset page and its cursor together. Schema 5 locks source rows before allocating
|
|
45
|
+
* snapshot revisions; older schemas retain their revision-zero baseline protocol. A failed page
|
|
46
|
+
* retries without changing earlier pages, and capture covers inserts/deletes across pages.
|
|
47
|
+
*/
|
|
48
|
+
export declare const advanceReplicationBaseline: (sql: SqlClient.SqlClient, generation: string) => Effect.Effect<ReplicationTarget, import("effect/unstable/sql/SqlError").SqlError | ReplicationBaselineFailed, never>;
|
|
49
|
+
/** Prepare once, then advance a bounded page; subsequent calls resume the same durable target. */
|
|
50
|
+
export declare const createReplicationBaseline: (sql: SqlClient.SqlClient, input: BaselineInput) => Effect.Effect<ReplicationTarget, import("effect/unstable/sql/SqlError").SqlError | ReplicationBaselineFailed, never>;
|
|
51
|
+
export {};
|