@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,191 @@
|
|
|
1
|
+
import { Effect, Stream } from "effect";
|
|
2
|
+
import { bufferedStream, ConnectionError, } from "../connection.js";
|
|
3
|
+
export const CONNECTION_STREAM_MEDIA_TYPE = "application/vnd.segmentstream.proxy-stream.v1+ndjson";
|
|
4
|
+
const MAX_FRAME_BYTES = 128 * 1024;
|
|
5
|
+
const MAX_CHUNK_BYTES = 65_536;
|
|
6
|
+
const MAX_LEGACY_BYTES = 4 * 1024 * 1024;
|
|
7
|
+
const CALL_TIMEOUT_MS = 40_000;
|
|
8
|
+
function invalid(connection, cause) {
|
|
9
|
+
return new ConnectionError({
|
|
10
|
+
connection,
|
|
11
|
+
reason: "invalid_response",
|
|
12
|
+
message: "invalid_response",
|
|
13
|
+
retryable: false,
|
|
14
|
+
...(cause === undefined ? {} : { cause }),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function object(value) {
|
|
18
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
function metadata(connection, value) {
|
|
21
|
+
if (!object(value) ||
|
|
22
|
+
Object.keys(value).length !== 2 ||
|
|
23
|
+
!Number.isInteger(value.statusCode) ||
|
|
24
|
+
Number(value.statusCode) < 100 ||
|
|
25
|
+
Number(value.statusCode) > 599 ||
|
|
26
|
+
!Array.isArray(value.headers) ||
|
|
27
|
+
value.headers.length > 100 ||
|
|
28
|
+
!value.headers.every((pair) => Array.isArray(pair) &&
|
|
29
|
+
pair.length === 2 &&
|
|
30
|
+
pair.every((item) => typeof item === "string"))) {
|
|
31
|
+
throw invalid(connection);
|
|
32
|
+
}
|
|
33
|
+
const headers = value.headers;
|
|
34
|
+
if (headers.reduce((size, [name, item]) => size + name.length + item.length, 0) > 16_384) {
|
|
35
|
+
throw invalid(connection);
|
|
36
|
+
}
|
|
37
|
+
return { status: Number(value.statusCode), headers };
|
|
38
|
+
}
|
|
39
|
+
async function* frames(reader, connection) {
|
|
40
|
+
let pending = Buffer.alloc(0);
|
|
41
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
42
|
+
for (;;) {
|
|
43
|
+
const next = await reader.read();
|
|
44
|
+
if (next.done) {
|
|
45
|
+
if (pending.length > 0) {
|
|
46
|
+
throw invalid(connection);
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
let offset = 0;
|
|
51
|
+
while (offset < next.value.length) {
|
|
52
|
+
const newline = next.value.indexOf(10, offset);
|
|
53
|
+
const end = newline < 0 ? next.value.length : newline + 1;
|
|
54
|
+
const part = next.value.subarray(offset, end);
|
|
55
|
+
if (pending.length + part.length > MAX_FRAME_BYTES) {
|
|
56
|
+
throw invalid(connection);
|
|
57
|
+
}
|
|
58
|
+
pending = Buffer.concat([pending, part]);
|
|
59
|
+
offset = end;
|
|
60
|
+
if (newline >= 0) {
|
|
61
|
+
const value = JSON.parse(decoder.decode(pending));
|
|
62
|
+
pending = Buffer.alloc(0);
|
|
63
|
+
yield value;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Negotiates once; never retries a provider operation to change response formats. */
|
|
69
|
+
export function openConnectionStream(input) {
|
|
70
|
+
return Effect.gen(function* () {
|
|
71
|
+
const controller = yield* Effect.acquireRelease(Effect.sync(() => new AbortController()), (controller) => Effect.sync(() => controller.abort()));
|
|
72
|
+
const signal = AbortSignal.any([controller.signal, AbortSignal.timeout(CALL_TIMEOUT_MS)]);
|
|
73
|
+
const failure = (cause) => {
|
|
74
|
+
if (cause instanceof ConnectionError) {
|
|
75
|
+
return cause;
|
|
76
|
+
}
|
|
77
|
+
const timeout = signal.aborted &&
|
|
78
|
+
signal.reason instanceof DOMException &&
|
|
79
|
+
signal.reason.name === "TimeoutError";
|
|
80
|
+
return new ConnectionError({
|
|
81
|
+
connection: input.connection,
|
|
82
|
+
reason: timeout ? "timeout" : "unavailable",
|
|
83
|
+
message: timeout ? "timeout" : "unavailable",
|
|
84
|
+
retryable: true,
|
|
85
|
+
cause,
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
const response = yield* Effect.tryPromise({
|
|
89
|
+
try: (interrupted) => input.request(AbortSignal.any([signal, interrupted])),
|
|
90
|
+
catch: failure,
|
|
91
|
+
});
|
|
92
|
+
if (response.body === null) {
|
|
93
|
+
return yield* invalid(input.connection);
|
|
94
|
+
}
|
|
95
|
+
let closed = false;
|
|
96
|
+
const closeReader = (reader) => Effect.suspend(() => {
|
|
97
|
+
if (closed) {
|
|
98
|
+
return Effect.void;
|
|
99
|
+
}
|
|
100
|
+
closed = true;
|
|
101
|
+
controller.abort();
|
|
102
|
+
return Effect.tryPromise({ try: () => reader.cancel(), catch: (cause) => cause }).pipe(Effect.timeout("1 second"), Effect.catch((cause) => Effect.logError("ontology.connection.stream_cleanup_failed", cause)));
|
|
103
|
+
});
|
|
104
|
+
const reader = yield* Effect.acquireRelease(Effect.sync(() => response.body.getReader()), closeReader);
|
|
105
|
+
const streamed = response.headers.get("content-type")?.split(";")[0]?.trim() === CONNECTION_STREAM_MEDIA_TYPE;
|
|
106
|
+
if (!response.ok || !streamed) {
|
|
107
|
+
return yield* Effect.tryPromise({
|
|
108
|
+
try: async () => {
|
|
109
|
+
const chunks = [];
|
|
110
|
+
let size = 0;
|
|
111
|
+
for (;;) {
|
|
112
|
+
const next = await reader.read();
|
|
113
|
+
if (next.done) {
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
size += next.value.length;
|
|
117
|
+
if (size > MAX_LEGACY_BYTES) {
|
|
118
|
+
throw invalid(input.connection);
|
|
119
|
+
}
|
|
120
|
+
chunks.push(next.value);
|
|
121
|
+
}
|
|
122
|
+
let value;
|
|
123
|
+
try {
|
|
124
|
+
value = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
125
|
+
}
|
|
126
|
+
catch (cause) {
|
|
127
|
+
throw response.ok
|
|
128
|
+
? invalid(input.connection, cause)
|
|
129
|
+
: input.refusal(response.status, undefined, cause);
|
|
130
|
+
}
|
|
131
|
+
if (!response.ok) {
|
|
132
|
+
throw input.refusal(response.status, value);
|
|
133
|
+
}
|
|
134
|
+
return bufferedStream(input.legacy(value));
|
|
135
|
+
},
|
|
136
|
+
catch: failure,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
const iterator = frames(reader, input.connection);
|
|
140
|
+
const first = yield* Effect.tryPromise({
|
|
141
|
+
try: () => iterator.next(),
|
|
142
|
+
catch: (cause) => cause instanceof SyntaxError || cause instanceof TypeError
|
|
143
|
+
? invalid(input.connection, cause)
|
|
144
|
+
: failure(cause),
|
|
145
|
+
});
|
|
146
|
+
const head = yield* Effect.try({
|
|
147
|
+
try: () => metadata(input.connection, first.value),
|
|
148
|
+
catch: (cause) => invalid(input.connection, cause),
|
|
149
|
+
});
|
|
150
|
+
// Pull with interruptible Effects: an async iterable's return() can wait forever
|
|
151
|
+
// behind a pending next(), preventing the reader's cancellation finalizer.
|
|
152
|
+
const body = Stream.unfold(false, (completed) => Effect.gen(function* () {
|
|
153
|
+
let ended = completed;
|
|
154
|
+
for (;;) {
|
|
155
|
+
if (signal.aborted) {
|
|
156
|
+
return yield* failure(signal.reason);
|
|
157
|
+
}
|
|
158
|
+
const next = yield* Effect.tryPromise({
|
|
159
|
+
try: () => iterator.next(),
|
|
160
|
+
catch: (cause) => cause instanceof SyntaxError || cause instanceof TypeError
|
|
161
|
+
? invalid(input.connection, cause)
|
|
162
|
+
: failure(cause),
|
|
163
|
+
});
|
|
164
|
+
if (next.done) {
|
|
165
|
+
return ended ? undefined : yield* failure({ error: "incomplete_stream" });
|
|
166
|
+
}
|
|
167
|
+
const value = next.value;
|
|
168
|
+
if (ended || !object(value) || Object.keys(value).length !== 1) {
|
|
169
|
+
return yield* invalid(input.connection);
|
|
170
|
+
}
|
|
171
|
+
if (value.end === true) {
|
|
172
|
+
ended = true;
|
|
173
|
+
}
|
|
174
|
+
else if (typeof value.error === "string") {
|
|
175
|
+
return yield* failure({ error: value.error });
|
|
176
|
+
}
|
|
177
|
+
else if (typeof value.data === "string") {
|
|
178
|
+
const bytes = Buffer.from(value.data, "base64");
|
|
179
|
+
if (bytes.length > MAX_CHUNK_BYTES || bytes.toString("base64") !== value.data) {
|
|
180
|
+
return yield* invalid(input.connection);
|
|
181
|
+
}
|
|
182
|
+
return [new Uint8Array(bytes), ended];
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
return yield* invalid(input.connection);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
})).pipe(Stream.ensuring(closeReader(reader)));
|
|
189
|
+
return { ...head, body };
|
|
190
|
+
});
|
|
191
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type ConnectionTransport } from "../connection.js";
|
|
2
|
+
/** The header Vercel sets on each function request: the deployment's OIDC token. */
|
|
3
|
+
export declare const OIDC_TOKEN_HEADER = "x-vercel-oidc-token";
|
|
4
|
+
/** Where `segmentstream exec` passes the local runtime context: a pipe's file descriptor. */
|
|
5
|
+
export declare const RUNTIME_CONTEXT_FD = "SEGMENTSTREAM_RUNTIME_CONTEXT_FD";
|
|
6
|
+
/** Who a connection call is made for. SegmentStream logs these; it never trusts them. */
|
|
7
|
+
export interface ConnectionAudit {
|
|
8
|
+
/** `<entity>.<action>`. */
|
|
9
|
+
readonly action: string;
|
|
10
|
+
readonly principalId: string;
|
|
11
|
+
readonly requestId: string;
|
|
12
|
+
}
|
|
13
|
+
/** Builds the transport of one action request. */
|
|
14
|
+
export type ConnectionTransportFactory = (input: {
|
|
15
|
+
/** The deployment's OIDC token, from the request or the environment. */
|
|
16
|
+
readonly identityToken: string | undefined;
|
|
17
|
+
readonly audit: ConnectionAudit;
|
|
18
|
+
}) => ConnectionTransport["Service"];
|
|
19
|
+
/** A connection the local grant covers, as the CLI describes it. */
|
|
20
|
+
export interface LocalConnection {
|
|
21
|
+
readonly key: string;
|
|
22
|
+
readonly apis: Readonly<Record<string, string>>;
|
|
23
|
+
readonly defaultApi: string | null;
|
|
24
|
+
}
|
|
25
|
+
/** The local runtime context `segmentstream exec --connection …` passes through a pipe. */
|
|
26
|
+
export interface LocalConnectionContext {
|
|
27
|
+
readonly apiUrl: string;
|
|
28
|
+
readonly workspaceId: string;
|
|
29
|
+
readonly proxyGrant: string;
|
|
30
|
+
readonly connections: ReadonlyArray<LocalConnection>;
|
|
31
|
+
}
|
|
32
|
+
/** The local runtime context is present but cannot be used. */
|
|
33
|
+
export declare class LocalConnectionContextError extends Error {
|
|
34
|
+
readonly name = "LocalConnectionContextError";
|
|
35
|
+
}
|
|
36
|
+
type Fetch = typeof fetch;
|
|
37
|
+
/**
|
|
38
|
+
* The transport of a deployed ontology service: each call goes to backend-next with the
|
|
39
|
+
* deployment's Vercel OIDC token, which proves the workspace application. The organization id only
|
|
40
|
+
* selects the tenant; backend-next admits the call only if the token's project is that tenant's
|
|
41
|
+
* application for the workspace, and only for a connection the deployed ontology declares.
|
|
42
|
+
*/
|
|
43
|
+
export declare function deployedConnections(environment: {
|
|
44
|
+
readonly segmentstreamUrl: string;
|
|
45
|
+
readonly workspaceId: string;
|
|
46
|
+
readonly organizationId: string;
|
|
47
|
+
}, fetchImpl?: Fetch): ConnectionTransportFactory;
|
|
48
|
+
/**
|
|
49
|
+
* The transport of `segmentstream exec --connection … -- npm run dev`: each call goes to the local
|
|
50
|
+
* proxy route with the CLI's one-hour grant, for the connections the grant covers.
|
|
51
|
+
*/
|
|
52
|
+
export declare function localConnections(context: LocalConnectionContext, fetchImpl?: Fetch): ConnectionTransportFactory;
|
|
53
|
+
/** Parses the context the CLI wrote, as the pipeline SDK does. */
|
|
54
|
+
export declare function parseLocalConnectionContext(text: string): LocalConnectionContext;
|
|
55
|
+
/**
|
|
56
|
+
* Reads the local runtime context from the pipe `segmentstream exec` opened, once, and removes the
|
|
57
|
+
* variable so that child processes cannot read it again. `undefined` when the CLI passed none.
|
|
58
|
+
*/
|
|
59
|
+
export declare function readLocalConnectionContext(environment: Record<string, string | undefined>): LocalConnectionContext | undefined;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { closeSync, readFileSync } from "node:fs";
|
|
2
|
+
import { Effect, Stream } from "effect";
|
|
3
|
+
import { CONNECTION_KEY, ConnectionError, MAXIMUM_CONNECTION_BODY_BYTES, MAXIMUM_CONNECTION_RESPONSE_BYTES, } from "../connection.js";
|
|
4
|
+
import { CONNECTION_STREAM_MEDIA_TYPE, openConnectionStream } from "./connection-stream.js";
|
|
5
|
+
/** The header Vercel sets on each function request: the deployment's OIDC token. */
|
|
6
|
+
export const OIDC_TOKEN_HEADER = "x-vercel-oidc-token";
|
|
7
|
+
/** Where `segmentstream exec` passes the local runtime context: a pipe's file descriptor. */
|
|
8
|
+
export const RUNTIME_CONTEXT_FD = "SEGMENTSTREAM_RUNTIME_CONTEXT_FD";
|
|
9
|
+
const MAXIMUM_CONTEXT_BYTES = 4 * 1_048_576;
|
|
10
|
+
/** The local runtime context is present but cannot be used. */
|
|
11
|
+
export class LocalConnectionContextError extends Error {
|
|
12
|
+
name = "LocalConnectionContextError";
|
|
13
|
+
}
|
|
14
|
+
const decoder = new TextDecoder();
|
|
15
|
+
function failure(connection, reason, message, requestId, cause) {
|
|
16
|
+
return new ConnectionError({
|
|
17
|
+
connection,
|
|
18
|
+
reason,
|
|
19
|
+
message,
|
|
20
|
+
retryable: reason === "unavailable" || reason === "timeout",
|
|
21
|
+
...(requestId === undefined ? {} : { requestId }),
|
|
22
|
+
...(cause === undefined ? {} : { cause }),
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
const REASONS = {
|
|
26
|
+
connection_authorization_required: "authorization_required",
|
|
27
|
+
connections_not_deployed: "not_deployed",
|
|
28
|
+
connections_redeployment_required: "not_deployed",
|
|
29
|
+
connection_not_found: "not_deployed",
|
|
30
|
+
connection_not_granted: "not_granted",
|
|
31
|
+
runtime_unauthorized: "not_granted",
|
|
32
|
+
runtime_value_not_granted: "not_granted",
|
|
33
|
+
unauthorized: "not_granted",
|
|
34
|
+
connection_provider_unavailable: "unavailable",
|
|
35
|
+
service_unavailable: "unavailable",
|
|
36
|
+
connection_proxy_unavailable: "timeout",
|
|
37
|
+
connection_provider_refused: "refused",
|
|
38
|
+
connection_response_too_large: "invalid_response",
|
|
39
|
+
invalid_connection: "invalid_request",
|
|
40
|
+
invalid_request: "invalid_request",
|
|
41
|
+
};
|
|
42
|
+
const MESSAGES = {
|
|
43
|
+
authorization_required: "Configure or authorize this connection in SegmentStream.",
|
|
44
|
+
not_deployed: "Deploy the workspace's connections/connections.py with this connection.",
|
|
45
|
+
not_granted: "SegmentStream did not grant this connection to the ontology service.",
|
|
46
|
+
unavailable: "The connection is temporarily unavailable.",
|
|
47
|
+
refused: "The provider refused the request.",
|
|
48
|
+
timeout: "The connection call exceeded its deadline.",
|
|
49
|
+
invalid_request: "The connection proxy refused the request.",
|
|
50
|
+
invalid_response: "The connection proxy answered with an invalid response.",
|
|
51
|
+
};
|
|
52
|
+
function isRecord(value) {
|
|
53
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
54
|
+
}
|
|
55
|
+
function isHeaderPairs(value) {
|
|
56
|
+
return (Array.isArray(value) &&
|
|
57
|
+
value.every((pair) => Array.isArray(pair) &&
|
|
58
|
+
pair.length === 2 &&
|
|
59
|
+
typeof pair[0] === "string" &&
|
|
60
|
+
typeof pair[1] === "string"));
|
|
61
|
+
}
|
|
62
|
+
/** The proxy's JSON answer, `{ statusCode, headers, body }` with a base64 body. */
|
|
63
|
+
function reply(connection, value) {
|
|
64
|
+
if (!isRecord(value) ||
|
|
65
|
+
typeof value.statusCode !== "number" ||
|
|
66
|
+
!isHeaderPairs(value.headers) ||
|
|
67
|
+
typeof value.body !== "string") {
|
|
68
|
+
throw failure(connection, "invalid_response", MESSAGES.invalid_response);
|
|
69
|
+
}
|
|
70
|
+
const body = Buffer.from(value.body, "base64");
|
|
71
|
+
if (body.byteLength > MAXIMUM_CONNECTION_BODY_BYTES) {
|
|
72
|
+
throw failure(connection, "invalid_response", "The provider's response exceeds 2 MiB.");
|
|
73
|
+
}
|
|
74
|
+
return { status: value.statusCode, headers: value.headers, body: new Uint8Array(body) };
|
|
75
|
+
}
|
|
76
|
+
/** A refusal from SegmentStream, by its error code. */
|
|
77
|
+
function refusal(connection, status, value, cause) {
|
|
78
|
+
const code = isRecord(value) && typeof value.error === "string" ? value.error : "";
|
|
79
|
+
const requestId = isRecord(value) && typeof value.requestId === "string" ? value.requestId : undefined;
|
|
80
|
+
const reason = REASONS[code] ?? (status >= 500 ? "unavailable" : "not_granted");
|
|
81
|
+
const detail = isRecord(value) && typeof value.detail === "string" ? value.detail : undefined;
|
|
82
|
+
return failure(connection, reason, detail ?? MESSAGES[reason], requestId, cause);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* A buffered call's reply, collected from a streamed one: streaming lifts the proxy's 2 MiB cap on
|
|
86
|
+
* buffered responses, and the collected body stays bounded so one response cannot exhaust the
|
|
87
|
+
* memory the service's concurrent requests share.
|
|
88
|
+
*/
|
|
89
|
+
function collected(connection, reply) {
|
|
90
|
+
const chunks = [];
|
|
91
|
+
let size = 0;
|
|
92
|
+
return Stream.runForEach(reply.body, (chunk) => {
|
|
93
|
+
size += chunk.byteLength;
|
|
94
|
+
if (size > MAXIMUM_CONNECTION_RESPONSE_BYTES) {
|
|
95
|
+
return Effect.fail(failure(connection, "invalid_response", "The provider's response exceeds 64 MiB. Read it with the connection's stream."));
|
|
96
|
+
}
|
|
97
|
+
chunks.push(chunk);
|
|
98
|
+
return Effect.void;
|
|
99
|
+
}).pipe(Effect.map(() => ({
|
|
100
|
+
status: reply.status,
|
|
101
|
+
headers: reply.headers,
|
|
102
|
+
body: new Uint8Array(Buffer.concat(chunks)),
|
|
103
|
+
})));
|
|
104
|
+
}
|
|
105
|
+
/** Shared admission and wire requests for buffered and streamed responses. */
|
|
106
|
+
function transport(fetchImpl, resolve) {
|
|
107
|
+
const open = (call) => resolve(call).pipe(Effect.flatMap((selected) => openConnectionStream({
|
|
108
|
+
connection: call.connection,
|
|
109
|
+
request: (signal) => fetchImpl(selected.url, {
|
|
110
|
+
method: "POST",
|
|
111
|
+
headers: {
|
|
112
|
+
...selected.headers,
|
|
113
|
+
"content-type": "application/json",
|
|
114
|
+
accept: CONNECTION_STREAM_MEDIA_TYPE,
|
|
115
|
+
},
|
|
116
|
+
body: JSON.stringify({
|
|
117
|
+
...(selected.call.api === undefined ? {} : { api: selected.call.api }),
|
|
118
|
+
method: selected.call.method,
|
|
119
|
+
path: selected.call.path,
|
|
120
|
+
headers: selected.call.headers,
|
|
121
|
+
body: Buffer.from(selected.call.body).toString("base64"),
|
|
122
|
+
}),
|
|
123
|
+
redirect: "error",
|
|
124
|
+
signal,
|
|
125
|
+
}),
|
|
126
|
+
legacy: (value) => reply(call.connection, value),
|
|
127
|
+
refusal: (status, value, cause) => refusal(call.connection, status, value, cause),
|
|
128
|
+
})));
|
|
129
|
+
return {
|
|
130
|
+
request: (call) => open(call).pipe(Effect.flatMap((reply) => collected(call.connection, reply)), Effect.scoped),
|
|
131
|
+
stream: (call) => open(call),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The transport of a deployed ontology service: each call goes to backend-next with the
|
|
136
|
+
* deployment's Vercel OIDC token, which proves the workspace application. The organization id only
|
|
137
|
+
* selects the tenant; backend-next admits the call only if the token's project is that tenant's
|
|
138
|
+
* application for the workspace, and only for a connection the deployed ontology declares.
|
|
139
|
+
*/
|
|
140
|
+
export function deployedConnections(environment, fetchImpl = fetch) {
|
|
141
|
+
const workspace = `${environment.segmentstreamUrl}/api/internal/v1/workspaces/${environment.workspaceId}`;
|
|
142
|
+
const base = `${workspace}/ontology/connections`;
|
|
143
|
+
return ({ identityToken, audit }) => transport(fetchImpl, (call) => {
|
|
144
|
+
if (identityToken === undefined || identityToken === "") {
|
|
145
|
+
return Effect.fail(failure(call.connection, "not_granted", "The request carries no Vercel OIDC token. Connections are available to production " +
|
|
146
|
+
"deployments, and locally through segmentstream exec --connection."));
|
|
147
|
+
}
|
|
148
|
+
return Effect.succeed({
|
|
149
|
+
url: `${base}/${encodeURIComponent(call.connection)}/request`,
|
|
150
|
+
headers: {
|
|
151
|
+
"x-segmentstream-runtime-identity": identityToken,
|
|
152
|
+
"x-segmentstream-organization-id": environment.organizationId,
|
|
153
|
+
"x-segmentstream-ontology-action": audit.action,
|
|
154
|
+
"x-segmentstream-ontology-principal": audit.principalId,
|
|
155
|
+
"x-segmentstream-request-id": audit.requestId,
|
|
156
|
+
},
|
|
157
|
+
call: { ...call, api: call.api },
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The transport of `segmentstream exec --connection … -- npm run dev`: each call goes to the local
|
|
163
|
+
* proxy route with the CLI's one-hour grant, for the connections the grant covers.
|
|
164
|
+
*/
|
|
165
|
+
export function localConnections(context, fetchImpl = fetch) {
|
|
166
|
+
const connections = new Map(context.connections.map((candidate) => [candidate.key, candidate]));
|
|
167
|
+
const workspace = `${context.apiUrl}/api/v1/workspaces/${context.workspaceId}`;
|
|
168
|
+
return () => transport(fetchImpl, (call) => {
|
|
169
|
+
const granted = connections.get(call.connection);
|
|
170
|
+
if (granted === undefined) {
|
|
171
|
+
return Effect.fail(failure(call.connection, "not_granted", `Run the service with segmentstream exec --connection ${call.connection}.`));
|
|
172
|
+
}
|
|
173
|
+
const api = call.api ?? granted.defaultApi ?? undefined;
|
|
174
|
+
if (api === undefined || !(api in granted.apis)) {
|
|
175
|
+
return Effect.fail(failure(call.connection, "invalid_request", api === undefined
|
|
176
|
+
? `The connection ${call.connection} has no default API; set api.`
|
|
177
|
+
: `The connection ${call.connection} declares no API named ${api}.`));
|
|
178
|
+
}
|
|
179
|
+
return Effect.succeed({
|
|
180
|
+
url: `${workspace}/connections/${encodeURIComponent(call.connection)}/request`,
|
|
181
|
+
headers: { "x-segmentstream-connection-grant": context.proxyGrant },
|
|
182
|
+
call: { ...call, api },
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
function localConnection(value) {
|
|
187
|
+
if (!isRecord(value) ||
|
|
188
|
+
typeof value.key !== "string" ||
|
|
189
|
+
!CONNECTION_KEY.test(value.key) ||
|
|
190
|
+
!isRecord(value.apis) ||
|
|
191
|
+
Object.values(value.apis).some((url) => typeof url !== "string") ||
|
|
192
|
+
(value.defaultApi !== null && typeof value.defaultApi !== "string")) {
|
|
193
|
+
throw new LocalConnectionContextError("The SegmentStream runtime context is invalid.");
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
key: value.key,
|
|
197
|
+
apis: value.apis,
|
|
198
|
+
defaultApi: value.defaultApi ?? null,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/** The URL without trailing slashes, in linear time: a regex would backtrack on many slashes. */
|
|
202
|
+
function withoutTrailingSlashes(url) {
|
|
203
|
+
let end = url.length;
|
|
204
|
+
while (end > 0 && url[end - 1] === "/") {
|
|
205
|
+
end -= 1;
|
|
206
|
+
}
|
|
207
|
+
return url.slice(0, end);
|
|
208
|
+
}
|
|
209
|
+
/** Parses the context the CLI wrote, as the pipeline SDK does. */
|
|
210
|
+
export function parseLocalConnectionContext(text) {
|
|
211
|
+
let value;
|
|
212
|
+
try {
|
|
213
|
+
value = JSON.parse(text);
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
throw new LocalConnectionContextError("The SegmentStream runtime context is invalid.");
|
|
217
|
+
}
|
|
218
|
+
if (!isRecord(value) ||
|
|
219
|
+
value.schemaVersion !== 3 ||
|
|
220
|
+
typeof value.apiUrl !== "string" ||
|
|
221
|
+
typeof value.workspaceId !== "string" ||
|
|
222
|
+
typeof value.proxyGrant !== "string" ||
|
|
223
|
+
value.proxyGrant === "" ||
|
|
224
|
+
!Array.isArray(value.connections)) {
|
|
225
|
+
throw new LocalConnectionContextError("The SegmentStream runtime context is invalid.");
|
|
226
|
+
}
|
|
227
|
+
const apiUrl = URL.canParse(value.apiUrl) ? new URL(value.apiUrl) : undefined;
|
|
228
|
+
if (apiUrl === undefined || apiUrl.protocol !== "https:" || apiUrl.username || apiUrl.search) {
|
|
229
|
+
throw new LocalConnectionContextError("The SegmentStream API URL is invalid.");
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
apiUrl: withoutTrailingSlashes(`${apiUrl.origin}${apiUrl.pathname}`),
|
|
233
|
+
workspaceId: value.workspaceId,
|
|
234
|
+
proxyGrant: value.proxyGrant,
|
|
235
|
+
connections: value.connections.map(localConnection),
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Reads the local runtime context from the pipe `segmentstream exec` opened, once, and removes the
|
|
240
|
+
* variable so that child processes cannot read it again. `undefined` when the CLI passed none.
|
|
241
|
+
*/
|
|
242
|
+
export function readLocalConnectionContext(environment) {
|
|
243
|
+
const raw = environment[RUNTIME_CONTEXT_FD];
|
|
244
|
+
if (raw === undefined) {
|
|
245
|
+
return undefined;
|
|
246
|
+
}
|
|
247
|
+
delete environment[RUNTIME_CONTEXT_FD];
|
|
248
|
+
if (!/^[0-9]+$/.test(raw) || Number(raw) < 3) {
|
|
249
|
+
throw new LocalConnectionContextError("The SegmentStream runtime context is unavailable. Run the service with segmentstream exec.");
|
|
250
|
+
}
|
|
251
|
+
const descriptor = Number(raw);
|
|
252
|
+
let bytes;
|
|
253
|
+
try {
|
|
254
|
+
bytes = readFileSync(descriptor);
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
throw new LocalConnectionContextError("The SegmentStream runtime context is unavailable. Run the service with segmentstream exec.");
|
|
258
|
+
}
|
|
259
|
+
finally {
|
|
260
|
+
try {
|
|
261
|
+
closeSync(descriptor);
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
// Already closed: the context was read, or there was nothing to read.
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (bytes.byteLength === 0 || bytes.byteLength > MAXIMUM_CONTEXT_BYTES) {
|
|
268
|
+
throw new LocalConnectionContextError("The SegmentStream runtime context is invalid.");
|
|
269
|
+
}
|
|
270
|
+
return parseLocalConnectionContext(decoder.decode(bytes));
|
|
271
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Yes-or-no questions about one shared state, answered by a decision model on AI Gateway, such as
|
|
3
|
+
* TypeSafe's Jev: each answer is the probability of "yes". The SDK asks them to rank `discover`'s
|
|
4
|
+
* entities by meaning, when the ontology opts in with `discovery: { model }`.
|
|
5
|
+
*/
|
|
6
|
+
export interface DecisionRequest {
|
|
7
|
+
readonly model: string;
|
|
8
|
+
/** What the questions are about: text, such as the caller's request. */
|
|
9
|
+
readonly state: string;
|
|
10
|
+
/** Each question's instructions by its id. */
|
|
11
|
+
readonly questions: Readonly<Record<string, string>>;
|
|
12
|
+
readonly signal?: AbortSignal;
|
|
13
|
+
}
|
|
14
|
+
/** The probability of "yes" by question id, for every question asked. */
|
|
15
|
+
export type Decide = (request: DecisionRequest) => Promise<Readonly<Record<string, number>>>;
|
|
16
|
+
/** A credential for AI Gateway: an API key, or the deployment's Vercel OIDC token. */
|
|
17
|
+
export interface GatewayCredential {
|
|
18
|
+
readonly token: string;
|
|
19
|
+
readonly method: "api-key" | "oidc";
|
|
20
|
+
}
|
|
21
|
+
/** AI Gateway refused or failed a decision, or answered something other than probabilities. */
|
|
22
|
+
export declare class DecisionFailed extends Error {
|
|
23
|
+
readonly name = "DecisionFailed";
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Asks AI Gateway's decision endpoint, as the AI SDK's `experimental_decide` does, without its
|
|
27
|
+
* dependencies: one POST with the state as a text part and one boolean question per id.
|
|
28
|
+
*/
|
|
29
|
+
export declare function gatewayDecisions(options: {
|
|
30
|
+
/** The credential for this call, or none: the call then fails without a request. */
|
|
31
|
+
readonly credential: () => GatewayCredential | undefined;
|
|
32
|
+
readonly fetch?: typeof fetch;
|
|
33
|
+
}): Decide;
|
|
34
|
+
/** AI Gateway's credential in this environment: `AI_GATEWAY_API_KEY`, else the OIDC token given. */
|
|
35
|
+
export declare function gatewayCredential(identityToken: string | undefined, environment?: Readonly<Record<string, string | undefined>>): GatewayCredential | undefined;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/** The decision endpoint of AI Gateway, as the AI SDK's gateway provider calls it. */
|
|
2
|
+
const GATEWAY_DECISIONS = "https://ai-gateway.vercel.sh/v4/ai/decision-model";
|
|
3
|
+
/** AI Gateway refused or failed a decision, or answered something other than probabilities. */
|
|
4
|
+
export class DecisionFailed extends Error {
|
|
5
|
+
name = "DecisionFailed";
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Asks AI Gateway's decision endpoint, as the AI SDK's `experimental_decide` does, without its
|
|
9
|
+
* dependencies: one POST with the state as a text part and one boolean question per id.
|
|
10
|
+
*/
|
|
11
|
+
export function gatewayDecisions(options) {
|
|
12
|
+
return async ({ model, state, questions, signal }) => {
|
|
13
|
+
const credential = options.credential();
|
|
14
|
+
if (credential === undefined) {
|
|
15
|
+
throw new DecisionFailed("No AI Gateway credential: set AI_GATEWAY_API_KEY, or run on Vercel with OIDC.");
|
|
16
|
+
}
|
|
17
|
+
const response = await (options.fetch ?? fetch)(GATEWAY_DECISIONS, {
|
|
18
|
+
method: "POST",
|
|
19
|
+
headers: {
|
|
20
|
+
authorization: `Bearer ${credential.token}`,
|
|
21
|
+
"ai-gateway-auth-method": credential.method,
|
|
22
|
+
"ai-gateway-protocol-version": "0.0.1",
|
|
23
|
+
"ai-decision-model-specification-version": "4",
|
|
24
|
+
"ai-model-id": model,
|
|
25
|
+
"content-type": "application/json",
|
|
26
|
+
},
|
|
27
|
+
body: JSON.stringify({
|
|
28
|
+
stateParts: [{ type: "text", text: state }],
|
|
29
|
+
questions: Object.fromEntries(Object.entries(questions).map(([id, instructions]) => [
|
|
30
|
+
id,
|
|
31
|
+
{ type: "boolean", instructions },
|
|
32
|
+
])),
|
|
33
|
+
}),
|
|
34
|
+
redirect: "error",
|
|
35
|
+
...(signal === undefined ? {} : { signal }),
|
|
36
|
+
});
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
throw new DecisionFailed(`AI Gateway answered HTTP ${response.status} for ${model}: ${(await response.text()).slice(0, 500)}`);
|
|
39
|
+
}
|
|
40
|
+
const body = (await response.json());
|
|
41
|
+
const answers = typeof body.answers === "object" && body.answers !== null
|
|
42
|
+
? body.answers
|
|
43
|
+
: {};
|
|
44
|
+
return Object.fromEntries(Object.keys(questions).map((id) => {
|
|
45
|
+
const answer = answers[id];
|
|
46
|
+
const probability = answer?.type === "boolean" ? answer.probability : undefined;
|
|
47
|
+
if (typeof probability !== "number" || !(probability >= 0 && probability <= 1)) {
|
|
48
|
+
throw new DecisionFailed(`${model} gave no probability for question ${id}.`);
|
|
49
|
+
}
|
|
50
|
+
return [id, probability];
|
|
51
|
+
}));
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** AI Gateway's credential in this environment: `AI_GATEWAY_API_KEY`, else the OIDC token given. */
|
|
55
|
+
export function gatewayCredential(identityToken, environment = process.env) {
|
|
56
|
+
const key = environment.AI_GATEWAY_API_KEY;
|
|
57
|
+
if (key !== undefined && key !== "") {
|
|
58
|
+
return { token: key, method: "api-key" };
|
|
59
|
+
}
|
|
60
|
+
return identityToken === undefined || identityToken === ""
|
|
61
|
+
? undefined
|
|
62
|
+
: { token: identityToken, method: "oidc" };
|
|
63
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PlannedAction } from "./plan.js";
|
|
2
|
+
/** `Requires lead:read.`, `Requires lead:create and lead:update.` */
|
|
3
|
+
export declare function requires(permissions: ReadonlyArray<string>): string;
|
|
4
|
+
/**
|
|
5
|
+
* What an action's route and its MCP tool say about it: its description, whether it is generated,
|
|
6
|
+
* the permissions it requires, the entities it declares it writes and the connections it calls.
|
|
7
|
+
*/
|
|
8
|
+
export declare function actionDescription({ action, generated, permissions, writes, }: PlannedAction): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** `Requires lead:read.`, `Requires lead:create and lead:update.` */
|
|
2
|
+
export function requires(permissions) {
|
|
3
|
+
return `Requires ${permissions.join(" and ")}.`;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* What an action's route and its MCP tool say about it: its description, whether it is generated,
|
|
7
|
+
* the permissions it requires, the entities it declares it writes and the connections it calls.
|
|
8
|
+
*/
|
|
9
|
+
export function actionDescription({ action, generated, permissions, writes, }) {
|
|
10
|
+
const origin = generated ? "Generated action." : "Action.";
|
|
11
|
+
const changes = writes === undefined
|
|
12
|
+
? ""
|
|
13
|
+
: writes.length > 0
|
|
14
|
+
? ` Writes ${writes.join(", ")}.`
|
|
15
|
+
: " Writes no records.";
|
|
16
|
+
const calls = action.connections.length > 0
|
|
17
|
+
? ` Calls ${action.connections.map((handle) => handle.key).join(", ")} before its transaction.`
|
|
18
|
+
: "";
|
|
19
|
+
return `${action.description}\n\n${origin} ${requires(permissions)}${changes}${calls}`;
|
|
20
|
+
}
|