@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,251 @@
|
|
|
1
|
+
import { telegramMarkdownLinks, telegramTextLinks, validateTelegramPreviews, } from "../../telegram.js";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { Cause, Effect } from "effect";
|
|
4
|
+
import { chatOperationId, chatPreviewDigest, } from "../../chat.js";
|
|
5
|
+
import { ActionRejected, PermissionDenied } from "../../errors.js";
|
|
6
|
+
import { isAllowed } from "../../permissions.js";
|
|
7
|
+
import { describeChatError } from "./diagnostics.js";
|
|
8
|
+
import { deliveryRequester } from "./attribution.js";
|
|
9
|
+
import { deliveryFingerprint, deliveryKeyDigest, deliveryScopeDigest } from "./idempotency.js";
|
|
10
|
+
import { renderTelegram, sendTelegram, TELEGRAM_MESSAGE_LIMIT } from "./providers/telegram.js";
|
|
11
|
+
import { chatResolver } from "./resolve.js";
|
|
12
|
+
export function makeChatDelivery(ontology, connections, archive, previews = {}) {
|
|
13
|
+
if (previews.settings) {
|
|
14
|
+
validateTelegramPreviews(previews.settings);
|
|
15
|
+
}
|
|
16
|
+
const attribution = ontology.config.chat?.attribution;
|
|
17
|
+
const separator = attribution?.separator ?? "\n\n";
|
|
18
|
+
const destination = ontology.manifest.chat?.telegram?.connection;
|
|
19
|
+
const destinationPreviews = previews.settings?.connection === destination ? previews : { ownOrigins: previews.ownOrigins };
|
|
20
|
+
return (context) => {
|
|
21
|
+
const check = (input, approved = true) => Effect.gen(function* () {
|
|
22
|
+
if (!isAllowed("agent_chat:post_message", context.principal)) {
|
|
23
|
+
return yield* new PermissionDenied({
|
|
24
|
+
message: "agent_chat:post_message is required.",
|
|
25
|
+
permission: "agent_chat:post_message",
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const user = yield* context.backend.get({ entity: "user", id: context.principal.id });
|
|
29
|
+
if (user.active !== true || user.kind !== context.principal.kind) {
|
|
30
|
+
return yield* new PermissionDenied({ message: "The requester is inactive." });
|
|
31
|
+
}
|
|
32
|
+
const requester = yield* deliveryRequester(context.caller, context.principal, String(user.name), attribution);
|
|
33
|
+
if (context.caller.kind === "runtime" &&
|
|
34
|
+
(context.backend.agents === undefined ||
|
|
35
|
+
(yield* context.backend.agents.actingMember(context.principal.id)) === undefined)) {
|
|
36
|
+
return yield* new PermissionDenied({
|
|
37
|
+
message: "The requester must still be paired and active.",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const target = yield* chatResolver(context.backend, context.principal).resolve(input.chat);
|
|
41
|
+
const connection = ontology.manifest.chat?.telegram?.connection;
|
|
42
|
+
const replyTo = input.replyTo ?? null;
|
|
43
|
+
const plainText = `${input.text}${separator}${requester.attribution}`;
|
|
44
|
+
if (target.provider !== "telegram" || !connection) {
|
|
45
|
+
return yield* new ActionRejected({
|
|
46
|
+
message: "Chat posting requires a configured Telegram provider connection.",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const finalText = yield* Effect.try({
|
|
50
|
+
try: () => renderTelegram(input.text, requester.attribution, separator),
|
|
51
|
+
catch: (cause) => new ActionRejected({ message: "The Markdown could not be rendered.", cause }),
|
|
52
|
+
});
|
|
53
|
+
if (!input.text.trim() ||
|
|
54
|
+
finalText.length > TELEGRAM_MESSAGE_LIMIT ||
|
|
55
|
+
plainText.length > TELEGRAM_MESSAGE_LIMIT ||
|
|
56
|
+
!/^-?[1-9][0-9]*$/.test(target.external_id) ||
|
|
57
|
+
(replyTo !== null &&
|
|
58
|
+
(!/^[1-9][0-9]*$/.test(replyTo) || !Number.isSafeInteger(Number(replyTo)))) ||
|
|
59
|
+
!input.idempotencyKey ||
|
|
60
|
+
input.idempotencyKey.length > 512) {
|
|
61
|
+
return yield* new ActionRejected({
|
|
62
|
+
message: "The exact attributed message or reply target is invalid or too long. Nothing was truncated.",
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const preview = {
|
|
66
|
+
chatId: target.id,
|
|
67
|
+
provider: target.provider,
|
|
68
|
+
externalId: target.external_id,
|
|
69
|
+
title: target.title,
|
|
70
|
+
attribution: requester.attribution,
|
|
71
|
+
text: input.text,
|
|
72
|
+
finalText,
|
|
73
|
+
replyTo,
|
|
74
|
+
};
|
|
75
|
+
if (context.caller.kind === "runtime" && approved) {
|
|
76
|
+
const envelope = context.envelope;
|
|
77
|
+
if (!envelope?.source ||
|
|
78
|
+
!envelope.expected ||
|
|
79
|
+
!envelope.operation_id ||
|
|
80
|
+
envelope.operation_id !== chatOperationId(envelope.session_id, envelope.call_id) ||
|
|
81
|
+
input.idempotencyKey !== envelope.operation_id ||
|
|
82
|
+
envelope.expected.chat_id !== target.id ||
|
|
83
|
+
envelope.expected.digest !== chatPreviewDigest(preview) ||
|
|
84
|
+
(envelope.source.provider === target.provider &&
|
|
85
|
+
envelope.source.chat_id === target.external_id)) {
|
|
86
|
+
return yield* new ActionRejected({
|
|
87
|
+
message: "A frozen approved cross-chat preview matching this call is required.",
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return { target, requester, connection, preview };
|
|
92
|
+
});
|
|
93
|
+
const report = (phase, cause) => Effect.logWarning("ontology.chat.delivery_diagnostic").pipe(Effect.annotateLogs({
|
|
94
|
+
phase,
|
|
95
|
+
requestId: context.requestId,
|
|
96
|
+
error: describeChatError(cause, (text) => context.identityToken ? text.split(context.identityToken).join("[redacted]") : text),
|
|
97
|
+
}));
|
|
98
|
+
return {
|
|
99
|
+
preview: (input) => check(input, false).pipe(Effect.map(({ preview }) => preview)),
|
|
100
|
+
validate: (input) => check(input).pipe(Effect.asVoid),
|
|
101
|
+
post: (input) => Effect.gen(function* () {
|
|
102
|
+
const { target, requester, connection, preview } = yield* check(input);
|
|
103
|
+
const operationId = context.envelope?.operation_id ?? randomUUID();
|
|
104
|
+
const scope = deliveryScopeDigest({
|
|
105
|
+
via: requester.via,
|
|
106
|
+
subjectId: requester.id,
|
|
107
|
+
clientId: requester.clientId,
|
|
108
|
+
});
|
|
109
|
+
const key = deliveryKeyDigest(input.idempotencyKey);
|
|
110
|
+
const fingerprint = deliveryFingerprint(preview, requester);
|
|
111
|
+
const event = {
|
|
112
|
+
eventId: `chat-delivery:${operationId}:reserve`,
|
|
113
|
+
operationId,
|
|
114
|
+
provider: target.provider,
|
|
115
|
+
chatId: target.external_id,
|
|
116
|
+
chatType: target.kind,
|
|
117
|
+
threadId: null,
|
|
118
|
+
participantIds: target.participantIds,
|
|
119
|
+
senderId: "agent",
|
|
120
|
+
senderName: "agent",
|
|
121
|
+
senderIsBot: true,
|
|
122
|
+
kind: "outbound",
|
|
123
|
+
messageId: null,
|
|
124
|
+
replyToMessageId: preview.replyTo,
|
|
125
|
+
sessionId: context.envelope?.session_id ?? null,
|
|
126
|
+
turnId: null,
|
|
127
|
+
// The claim binds text immutably. Keep the source here and the actual wire payload
|
|
128
|
+
// in argsSummary, which can record the plain retry without changing that binding.
|
|
129
|
+
text: `${input.text}${separator}${requester.attribution}`,
|
|
130
|
+
decision: null,
|
|
131
|
+
reason: null,
|
|
132
|
+
toolCallId: null,
|
|
133
|
+
toolName: null,
|
|
134
|
+
argsSummary: JSON.stringify({ text: preview.finalText, parse_mode: "MarkdownV2" }),
|
|
135
|
+
status: "requested",
|
|
136
|
+
attachments: [],
|
|
137
|
+
requestedBy: requester,
|
|
138
|
+
url: null,
|
|
139
|
+
at: new Date().toISOString(),
|
|
140
|
+
};
|
|
141
|
+
const reserve = yield* archive({
|
|
142
|
+
event,
|
|
143
|
+
delivery: { phase: "reserve", scope, key, fingerprint },
|
|
144
|
+
identityToken: context.identityToken,
|
|
145
|
+
}).pipe(Effect.tapError((error) => report("reserve", error)), Effect.mapError((cause) => new ActionRejected({
|
|
146
|
+
cause,
|
|
147
|
+
message: cause.diagnostic === "chat_archive_conflict"
|
|
148
|
+
? "This idempotency key is bound to another delivery. " +
|
|
149
|
+
"Replay the original input to recover its receipt."
|
|
150
|
+
: "Delivery could not be reserved. Retry only the same idempotency key; no send was authorized.",
|
|
151
|
+
})));
|
|
152
|
+
if (!reserve.claimed) {
|
|
153
|
+
if (reserve.version !== 1 || !reserve.duplicate || reserve.claimId !== undefined) {
|
|
154
|
+
return yield* new ActionRejected({
|
|
155
|
+
message: "The archive did not return a valid delivery receipt.",
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (reserve.status === "failed") {
|
|
159
|
+
return yield* new ActionRejected({
|
|
160
|
+
message: "This operation was refused. Its idempotency key is consumed.",
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
status: reserve.status,
|
|
165
|
+
message_id: reserve.messageId,
|
|
166
|
+
url: reserve.url,
|
|
167
|
+
duplicate: true,
|
|
168
|
+
history_recorded: reserve.historyRecorded,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
if (reserve.version !== 1 ||
|
|
172
|
+
reserve.duplicate ||
|
|
173
|
+
!reserve.claimId ||
|
|
174
|
+
reserve.operationId !== operationId ||
|
|
175
|
+
reserve.status !== "uncertain" ||
|
|
176
|
+
reserve.historyRecorded ||
|
|
177
|
+
reserve.messageId !== null ||
|
|
178
|
+
reserve.url !== null) {
|
|
179
|
+
return yield* new ActionRejected({
|
|
180
|
+
message: "The archive did not grant a fresh delivery claim.",
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
const outcome = yield* sendTelegram({
|
|
184
|
+
destination: target,
|
|
185
|
+
connection,
|
|
186
|
+
finalText: preview.finalText,
|
|
187
|
+
formattedLinks: [
|
|
188
|
+
...telegramMarkdownLinks(preview.text),
|
|
189
|
+
...telegramTextLinks(separator),
|
|
190
|
+
...telegramTextLinks(preview.attribution),
|
|
191
|
+
],
|
|
192
|
+
previews: destinationPreviews,
|
|
193
|
+
plainText: event.text,
|
|
194
|
+
replyTo: preview.replyTo,
|
|
195
|
+
transport: connections({
|
|
196
|
+
identityToken: context.identityToken,
|
|
197
|
+
audit: {
|
|
198
|
+
action: "agent_chat.post_message",
|
|
199
|
+
principalId: context.principal.id,
|
|
200
|
+
requestId: context.requestId,
|
|
201
|
+
},
|
|
202
|
+
}),
|
|
203
|
+
});
|
|
204
|
+
if (outcome.cause !== undefined) {
|
|
205
|
+
yield* report("provider", outcome.cause);
|
|
206
|
+
}
|
|
207
|
+
const saved = yield* archive({
|
|
208
|
+
event: {
|
|
209
|
+
...event,
|
|
210
|
+
eventId: `chat-delivery:${operationId}:receipt`,
|
|
211
|
+
status: outcome.status,
|
|
212
|
+
argsSummary: JSON.stringify(outcome.payload),
|
|
213
|
+
messageId: outcome.messageId,
|
|
214
|
+
url: outcome.url,
|
|
215
|
+
},
|
|
216
|
+
delivery: { phase: "receipt", scope, key, fingerprint, claimId: reserve.claimId },
|
|
217
|
+
identityToken: context.identityToken,
|
|
218
|
+
}).pipe(Effect.exit);
|
|
219
|
+
let historyRecorded = false;
|
|
220
|
+
if (saved._tag === "Failure") {
|
|
221
|
+
yield* report("receipt", Cause.squash(saved.cause));
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
historyRecorded =
|
|
225
|
+
saved.value.version === 1 &&
|
|
226
|
+
!saved.value.claimed &&
|
|
227
|
+
saved.value.operationId === operationId &&
|
|
228
|
+
saved.value.status === outcome.status &&
|
|
229
|
+
saved.value.messageId === outcome.messageId &&
|
|
230
|
+
saved.value.url === outcome.url &&
|
|
231
|
+
saved.value.historyRecorded;
|
|
232
|
+
if (!historyRecorded) {
|
|
233
|
+
yield* report("receipt", new Error("The archive did not acknowledge the exact delivery outcome."));
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (outcome.status === "failed") {
|
|
237
|
+
return yield* new ActionRejected({
|
|
238
|
+
message: "The provider refused the message. This operation key is consumed.",
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
return {
|
|
242
|
+
status: outcome.status,
|
|
243
|
+
message_id: outcome.messageId,
|
|
244
|
+
url: outcome.url,
|
|
245
|
+
duplicate: false,
|
|
246
|
+
history_recorded: historyRecorded,
|
|
247
|
+
};
|
|
248
|
+
}),
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Every cause and aggregate branch, with cycle protection and credential-value redaction. */
|
|
2
|
+
export function describeChatError(error, redact) {
|
|
3
|
+
const seen = new Set();
|
|
4
|
+
const pending = [{ value: error, label: "" }];
|
|
5
|
+
const lines = [];
|
|
6
|
+
while (pending.length > 0) {
|
|
7
|
+
const { value, label } = pending.pop();
|
|
8
|
+
if (value === null || typeof value !== "object") {
|
|
9
|
+
lines.push(`${label}${String(value)}`);
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
if (seen.has(value)) {
|
|
13
|
+
lines.push(`${label}[previously reported cause]`);
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
seen.add(value);
|
|
17
|
+
const record = value;
|
|
18
|
+
const name = typeof record.name === "string" ? record.name : String(record._tag ?? "Error");
|
|
19
|
+
const message = typeof record.message === "string" ? record.message : "Unknown failure";
|
|
20
|
+
const head = typeof record.stack === "string" ? record.stack : `${name}: ${message}`;
|
|
21
|
+
const diagnostic = [record.code, record.diagnostic]
|
|
22
|
+
.filter((part) => typeof part === "string")
|
|
23
|
+
.join("; ");
|
|
24
|
+
lines.push(`${label}${head}${diagnostic ? ` [${diagnostic}]` : ""}`);
|
|
25
|
+
if (Array.isArray(record.errors)) {
|
|
26
|
+
for (let index = record.errors.length - 1; index >= 0; index--) {
|
|
27
|
+
pending.push({ value: record.errors[index], label: `aggregate cause ${index + 1}: ` });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (record.cause !== undefined) {
|
|
31
|
+
pending.push({ value: record.cause, label: "caused by: " });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return redact(lines.join("\n"));
|
|
35
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Context, Effect, Schema } from "effect";
|
|
2
|
+
import { ActionRejected, PermissionDenied } from "../../errors.js";
|
|
3
|
+
import type { CallerContext } from "../caller-context.js";
|
|
4
|
+
declare const RuntimeEnvelope: Schema.Struct<{
|
|
5
|
+
readonly version: Schema.Literal<1>;
|
|
6
|
+
readonly session_id: Schema.String;
|
|
7
|
+
readonly call_id: Schema.String;
|
|
8
|
+
readonly operation_id: Schema.optionalKey<Schema.String>;
|
|
9
|
+
readonly source: Schema.optionalKey<Schema.Struct<{
|
|
10
|
+
readonly provider: Schema.Literal<"telegram">;
|
|
11
|
+
readonly chat_id: Schema.String;
|
|
12
|
+
readonly thread_id: Schema.String;
|
|
13
|
+
readonly message_id: Schema.optionalKey<Schema.String>;
|
|
14
|
+
readonly reply_to_message_id: Schema.optionalKey<Schema.String>;
|
|
15
|
+
readonly callback_query_id: Schema.optionalKey<Schema.String>;
|
|
16
|
+
readonly sender: Schema.optionalKey<Schema.String>;
|
|
17
|
+
readonly attachments: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
18
|
+
readonly file_id: Schema.String;
|
|
19
|
+
readonly file_unique_id: Schema.optionalKey<Schema.String>;
|
|
20
|
+
readonly kind: Schema.Literals<readonly ["photo", "document", "voice", "audio", "video", "video_note", "sticker", "animation"]>;
|
|
21
|
+
readonly media_type: Schema.optionalKey<Schema.String>;
|
|
22
|
+
readonly staged_id: Schema.String;
|
|
23
|
+
}>>>;
|
|
24
|
+
}>>;
|
|
25
|
+
readonly expected: Schema.optionalKey<Schema.Struct<{
|
|
26
|
+
readonly chat_id: Schema.String;
|
|
27
|
+
readonly digest: Schema.String;
|
|
28
|
+
}>>;
|
|
29
|
+
}>;
|
|
30
|
+
export type RuntimeChatEnvelope = typeof RuntimeEnvelope.Type;
|
|
31
|
+
declare const CurrentChatCall_base: Context.ServiceClass<CurrentChatCall, "@segmentstream/ontology/CurrentChatCall", {
|
|
32
|
+
readonly version: 1;
|
|
33
|
+
readonly session_id: string;
|
|
34
|
+
readonly call_id: string;
|
|
35
|
+
readonly source?: {
|
|
36
|
+
readonly provider: "telegram";
|
|
37
|
+
readonly chat_id: string;
|
|
38
|
+
readonly thread_id: string;
|
|
39
|
+
readonly message_id?: string | undefined;
|
|
40
|
+
readonly reply_to_message_id?: string | undefined;
|
|
41
|
+
readonly callback_query_id?: string | undefined;
|
|
42
|
+
readonly sender?: string | undefined;
|
|
43
|
+
readonly attachments?: readonly {
|
|
44
|
+
readonly kind: "photo" | "document" | "voice" | "audio" | "video" | "video_note" | "sticker" | "animation";
|
|
45
|
+
readonly file_id: string;
|
|
46
|
+
readonly staged_id: string;
|
|
47
|
+
readonly file_unique_id?: string | undefined;
|
|
48
|
+
readonly media_type?: string | undefined;
|
|
49
|
+
}[] | undefined;
|
|
50
|
+
} | undefined;
|
|
51
|
+
readonly operation_id?: string | undefined;
|
|
52
|
+
readonly expected?: {
|
|
53
|
+
readonly chat_id: string;
|
|
54
|
+
readonly digest: string;
|
|
55
|
+
} | undefined;
|
|
56
|
+
}>;
|
|
57
|
+
export declare class CurrentChatCall extends CurrentChatCall_base {
|
|
58
|
+
}
|
|
59
|
+
/** Consume Eve's all-tool application argument before any strict per-tool decoding. */
|
|
60
|
+
export declare function consumeChatEnvelope(args: Readonly<Record<string, unknown>>, caller: CallerContext): Effect.Effect<{
|
|
61
|
+
input: {
|
|
62
|
+
readonly [x: string]: unknown;
|
|
63
|
+
};
|
|
64
|
+
envelope: undefined;
|
|
65
|
+
} | {
|
|
66
|
+
input: {
|
|
67
|
+
readonly [x: string]: unknown;
|
|
68
|
+
};
|
|
69
|
+
envelope: {
|
|
70
|
+
readonly version: 1;
|
|
71
|
+
readonly session_id: string;
|
|
72
|
+
readonly call_id: string;
|
|
73
|
+
readonly source?: {
|
|
74
|
+
readonly provider: "telegram";
|
|
75
|
+
readonly chat_id: string;
|
|
76
|
+
readonly thread_id: string;
|
|
77
|
+
readonly message_id?: string | undefined;
|
|
78
|
+
readonly reply_to_message_id?: string | undefined;
|
|
79
|
+
readonly callback_query_id?: string | undefined;
|
|
80
|
+
readonly sender?: string | undefined;
|
|
81
|
+
readonly attachments?: readonly {
|
|
82
|
+
readonly kind: "photo" | "document" | "voice" | "audio" | "video" | "video_note" | "sticker" | "animation";
|
|
83
|
+
readonly file_id: string;
|
|
84
|
+
readonly staged_id: string;
|
|
85
|
+
readonly file_unique_id?: string | undefined;
|
|
86
|
+
readonly media_type?: string | undefined;
|
|
87
|
+
}[] | undefined;
|
|
88
|
+
} | undefined;
|
|
89
|
+
readonly operation_id?: string | undefined;
|
|
90
|
+
readonly expected?: {
|
|
91
|
+
readonly chat_id: string;
|
|
92
|
+
readonly digest: string;
|
|
93
|
+
} | undefined;
|
|
94
|
+
};
|
|
95
|
+
}, ActionRejected | PermissionDenied, never>;
|
|
96
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { RuntimeSource } from "../../runtime-source.js";
|
|
2
|
+
import { Context, Effect, Schema } from "effect";
|
|
3
|
+
import { ActionRejected, PermissionDenied } from "../../errors.js";
|
|
4
|
+
import { chatOperationId } from "../../chat.js";
|
|
5
|
+
const Id = Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(512));
|
|
6
|
+
const RuntimeEnvelope = Schema.Struct({
|
|
7
|
+
version: Schema.Literal(1),
|
|
8
|
+
session_id: Id,
|
|
9
|
+
call_id: Id,
|
|
10
|
+
operation_id: Schema.optionalKey(Id),
|
|
11
|
+
source: Schema.optionalKey(RuntimeSource),
|
|
12
|
+
expected: Schema.optionalKey(Schema.Struct({ chat_id: Id, digest: Schema.String.check(Schema.isPattern(/^[0-9a-f]{64}$/)) })),
|
|
13
|
+
});
|
|
14
|
+
export class CurrentChatCall extends Context.Service()("@segmentstream/ontology/CurrentChatCall") {
|
|
15
|
+
}
|
|
16
|
+
/** Consume Eve's all-tool application argument before any strict per-tool decoding. */
|
|
17
|
+
export function consumeChatEnvelope(args, caller) {
|
|
18
|
+
return Effect.gen(function* () {
|
|
19
|
+
const { _segmentstream: envelope, ...input } = args;
|
|
20
|
+
if (!Object.hasOwn(args, "_segmentstream")) {
|
|
21
|
+
return { input, envelope: undefined };
|
|
22
|
+
}
|
|
23
|
+
if (caller.kind !== "runtime") {
|
|
24
|
+
return yield* new PermissionDenied({
|
|
25
|
+
message: "Runtime arguments require verified agent runtime identity.",
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
const parsed = yield* Schema.decodeUnknownEffect(RuntimeEnvelope)(envelope, {
|
|
29
|
+
onExcessProperty: "error",
|
|
30
|
+
}).pipe(Effect.mapError(() => new ActionRejected({ message: "Invalid agent runtime call metadata." })));
|
|
31
|
+
if (parsed.operation_id !== undefined &&
|
|
32
|
+
parsed.operation_id !== chatOperationId(parsed.session_id, parsed.call_id)) {
|
|
33
|
+
return yield* new ActionRejected({
|
|
34
|
+
message: "The runtime operation does not match its call.",
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return { input, envelope: parsed };
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ChatPreview } from "../../chat.js";
|
|
2
|
+
import type { ConversationRequester } from "./attribution.js";
|
|
3
|
+
interface DeliveryScopeIdentifiers {
|
|
4
|
+
readonly via: ConversationRequester["via"];
|
|
5
|
+
readonly subjectId: string;
|
|
6
|
+
readonly clientId: string | null;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* An archive namespace, not a password/credential verifier. Only authenticated public
|
|
10
|
+
* identifiers enter this digest: caller kind, subject ID and registered OAuth client_id.
|
|
11
|
+
* Authentication projects the client ID separately from tokens, secretHash and grants;
|
|
12
|
+
* never serialize a caller, client or grant record here. Preserve this tuple's encoding
|
|
13
|
+
* (including runtime's original kind) so existing sent/uncertain claims stay consumed.
|
|
14
|
+
*/
|
|
15
|
+
export declare function deliveryScopeDigest(identifiers: DeliveryScopeIdentifiers): string;
|
|
16
|
+
export declare const deliveryKeyDigest: (idempotencyKey: string) => string;
|
|
17
|
+
/** Bind the exact post and public attribution fields; ignore unrelated record properties. */
|
|
18
|
+
export declare function deliveryFingerprint(preview: ChatPreview, requester: ConversationRequester): string;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
const digest = (serialized) => createHash("sha256").update(serialized).digest("hex");
|
|
3
|
+
/**
|
|
4
|
+
* An archive namespace, not a password/credential verifier. Only authenticated public
|
|
5
|
+
* identifiers enter this digest: caller kind, subject ID and registered OAuth client_id.
|
|
6
|
+
* Authentication projects the client ID separately from tokens, secretHash and grants;
|
|
7
|
+
* never serialize a caller, client or grant record here. Preserve this tuple's encoding
|
|
8
|
+
* (including runtime's original kind) so existing sent/uncertain claims stay consumed.
|
|
9
|
+
*/
|
|
10
|
+
export function deliveryScopeDigest(identifiers) {
|
|
11
|
+
return digest(JSON.stringify([
|
|
12
|
+
identifiers.via === "hq" ? "runtime" : identifiers.via,
|
|
13
|
+
identifiers.subjectId,
|
|
14
|
+
identifiers.via === "oauth" ? identifiers.clientId : null,
|
|
15
|
+
]));
|
|
16
|
+
}
|
|
17
|
+
export const deliveryKeyDigest = (idempotencyKey) => digest(JSON.stringify(idempotencyKey));
|
|
18
|
+
/** Bind the exact post and public attribution fields; ignore unrelated record properties. */
|
|
19
|
+
export function deliveryFingerprint(preview, requester) {
|
|
20
|
+
return digest(JSON.stringify([
|
|
21
|
+
preview.chatId,
|
|
22
|
+
preview.provider,
|
|
23
|
+
preview.externalId,
|
|
24
|
+
preview.finalText,
|
|
25
|
+
preview.text,
|
|
26
|
+
preview.replyTo,
|
|
27
|
+
{
|
|
28
|
+
id: requester.id,
|
|
29
|
+
kind: requester.kind,
|
|
30
|
+
name: requester.name,
|
|
31
|
+
via: requester.via,
|
|
32
|
+
clientId: requester.clientId,
|
|
33
|
+
clientName: requester.clientName,
|
|
34
|
+
attribution: requester.attribution,
|
|
35
|
+
},
|
|
36
|
+
]));
|
|
37
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type TelegramPreviewContext } from "../../../telegram.js";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { type ConnectionTransport } from "../../../connection.js";
|
|
4
|
+
import type { Destination } from "../resolve.js";
|
|
5
|
+
export declare const TELEGRAM_MESSAGE_LIMIT = 4096;
|
|
6
|
+
/** Render source independently so user Markdown cannot open an entity around the footer. */
|
|
7
|
+
export declare function renderTelegram(markdown: string, attribution: string, separator?: string): string;
|
|
8
|
+
interface TelegramPayload {
|
|
9
|
+
readonly text: string;
|
|
10
|
+
readonly parse_mode?: "MarkdownV2";
|
|
11
|
+
}
|
|
12
|
+
export interface ProviderOutcome {
|
|
13
|
+
readonly payload: TelegramPayload;
|
|
14
|
+
readonly status: "sent" | "uncertain" | "failed";
|
|
15
|
+
readonly messageId: string | null;
|
|
16
|
+
readonly url: string | null;
|
|
17
|
+
readonly cause?: unknown;
|
|
18
|
+
}
|
|
19
|
+
interface TelegramSend {
|
|
20
|
+
readonly transport: ConnectionTransport["Service"];
|
|
21
|
+
readonly connection: string;
|
|
22
|
+
readonly destination: Destination;
|
|
23
|
+
/** Links parsed before MarkdownV2 escaping, with the literal attribution added separately. */
|
|
24
|
+
readonly formattedLinks?: readonly string[];
|
|
25
|
+
readonly previews?: TelegramPreviewContext;
|
|
26
|
+
readonly finalText: string;
|
|
27
|
+
readonly plainText: string;
|
|
28
|
+
readonly replyTo: string | null;
|
|
29
|
+
readonly link_preview_options?: Readonly<Record<string, unknown>>;
|
|
30
|
+
readonly disable_web_page_preview?: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** One proxy POST, except one plain retry after a definite 400 entity parse refusal.
|
|
33
|
+
* Never retry an unknown outcome; never chunk, truncate or invoke an agent.
|
|
34
|
+
*/
|
|
35
|
+
export declare function sendTelegram(input: TelegramSend): Effect.Effect<ProviderOutcome>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { telegramMarkdownLinks, telegramTextLinks, telegramPreviewOptions, } from "../../../telegram.js";
|
|
2
|
+
import { escapeMarkdownV2, TelegramFormatConverter } from "@chat-adapter/telegram";
|
|
3
|
+
import { Cause, Effect } from "effect";
|
|
4
|
+
import { ConnectionError } from "../../../connection.js";
|
|
5
|
+
export const TELEGRAM_MESSAGE_LIMIT = 4096;
|
|
6
|
+
const converter = new TelegramFormatConverter();
|
|
7
|
+
/** Render source independently so user Markdown cannot open an entity around the footer. */
|
|
8
|
+
export function renderTelegram(markdown, attribution, separator = "\n\n") {
|
|
9
|
+
return `${converter.fromMarkdown(markdown)}${escapeMarkdownV2(separator)}_${escapeMarkdownV2(attribution)}_`;
|
|
10
|
+
}
|
|
11
|
+
const record = (value) => value !== null && typeof value === "object" && !Array.isArray(value)
|
|
12
|
+
? value
|
|
13
|
+
: {};
|
|
14
|
+
/** One proxy POST, except one plain retry after a definite 400 entity parse refusal.
|
|
15
|
+
* Never retry an unknown outcome; never chunk, truncate or invoke an agent.
|
|
16
|
+
*/
|
|
17
|
+
export function sendTelegram(input) {
|
|
18
|
+
return Effect.gen(function* () {
|
|
19
|
+
const formatted = yield* attemptTelegram(input, {
|
|
20
|
+
text: input.finalText,
|
|
21
|
+
parse_mode: "MarkdownV2",
|
|
22
|
+
});
|
|
23
|
+
if (!formatted.formattingRefused) {
|
|
24
|
+
return formatted;
|
|
25
|
+
}
|
|
26
|
+
const plain = yield* attemptTelegram(input, { text: input.plainText });
|
|
27
|
+
return {
|
|
28
|
+
...plain,
|
|
29
|
+
cause: plain.cause === undefined
|
|
30
|
+
? formatted.cause
|
|
31
|
+
: new AggregateError([formatted.cause, plain.cause], "Telegram plain retry failed."),
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function attemptTelegram(input, payload) {
|
|
36
|
+
return Effect.gen(function* () {
|
|
37
|
+
const result = yield* input.transport
|
|
38
|
+
.request({
|
|
39
|
+
connection: input.connection,
|
|
40
|
+
api: "bot",
|
|
41
|
+
method: "POST",
|
|
42
|
+
path: "/sendMessage",
|
|
43
|
+
headers: [["content-type", "application/json"]],
|
|
44
|
+
body: new TextEncoder().encode(JSON.stringify({
|
|
45
|
+
chat_id: input.destination.external_id,
|
|
46
|
+
...payload,
|
|
47
|
+
...telegramPreviewOptions({
|
|
48
|
+
link_preview_options: input.link_preview_options,
|
|
49
|
+
disable_web_page_preview: input.disable_web_page_preview,
|
|
50
|
+
}, payload.parse_mode === "MarkdownV2"
|
|
51
|
+
? (input.formattedLinks ?? telegramMarkdownLinks(input.plainText))
|
|
52
|
+
: telegramTextLinks(payload.text), input.previews),
|
|
53
|
+
...(input.replyTo === null
|
|
54
|
+
? {}
|
|
55
|
+
: {
|
|
56
|
+
reply_parameters: {
|
|
57
|
+
message_id: Number(input.replyTo),
|
|
58
|
+
allow_sending_without_reply: false,
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
61
|
+
})),
|
|
62
|
+
})
|
|
63
|
+
.pipe(Effect.exit);
|
|
64
|
+
if (result._tag === "Failure") {
|
|
65
|
+
const cause = Cause.squash(result.cause);
|
|
66
|
+
const definite = cause instanceof ConnectionError &&
|
|
67
|
+
[
|
|
68
|
+
"authorization_required",
|
|
69
|
+
"not_deployed",
|
|
70
|
+
"not_granted",
|
|
71
|
+
"invalid_request",
|
|
72
|
+
"refused",
|
|
73
|
+
].includes(cause.reason);
|
|
74
|
+
return {
|
|
75
|
+
payload,
|
|
76
|
+
status: definite ? "failed" : "uncertain",
|
|
77
|
+
messageId: null,
|
|
78
|
+
url: null,
|
|
79
|
+
cause,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
let body;
|
|
83
|
+
try {
|
|
84
|
+
body = record(JSON.parse(new TextDecoder().decode(result.value.body)));
|
|
85
|
+
}
|
|
86
|
+
catch (cause) {
|
|
87
|
+
return { payload, status: "uncertain", messageId: null, url: null, cause };
|
|
88
|
+
}
|
|
89
|
+
if (body.ok === false) {
|
|
90
|
+
return {
|
|
91
|
+
payload,
|
|
92
|
+
formattingRefused: result.value.status === 400 &&
|
|
93
|
+
typeof body.description === "string" &&
|
|
94
|
+
/can't parse entities/iu.test(body.description),
|
|
95
|
+
status: "failed",
|
|
96
|
+
messageId: null,
|
|
97
|
+
url: null,
|
|
98
|
+
cause: new Error(typeof body.description === "string" ? body.description : "Telegram refused the message."),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const message = record(body.result);
|
|
102
|
+
const chat = record(message.chat);
|
|
103
|
+
if (result.value.status < 200 ||
|
|
104
|
+
result.value.status >= 300 ||
|
|
105
|
+
body.ok !== true ||
|
|
106
|
+
!Number.isSafeInteger(message.message_id) ||
|
|
107
|
+
Number(message.message_id) < 1 ||
|
|
108
|
+
String(chat.id) !== input.destination.external_id ||
|
|
109
|
+
(input.replyTo !== null &&
|
|
110
|
+
String(record(message.reply_to_message).message_id) !== input.replyTo)) {
|
|
111
|
+
return {
|
|
112
|
+
payload,
|
|
113
|
+
status: "uncertain",
|
|
114
|
+
messageId: null,
|
|
115
|
+
url: null,
|
|
116
|
+
cause: new Error("Telegram success could not be verified."),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const messageId = String(message.message_id);
|
|
120
|
+
const username = typeof chat.username === "string" && /^[A-Za-z][A-Za-z0-9_]{3,31}$/.test(chat.username)
|
|
121
|
+
? chat.username
|
|
122
|
+
: null;
|
|
123
|
+
const privateChannel = /^-100[1-9][0-9]*$/.test(input.destination.external_id);
|
|
124
|
+
const url = input.destination.kind === "private"
|
|
125
|
+
? null
|
|
126
|
+
: username !== null
|
|
127
|
+
? `https://t.me/${username}/${messageId}`
|
|
128
|
+
: privateChannel
|
|
129
|
+
? `https://t.me/c/${input.destination.external_id.slice(4)}/${messageId}`
|
|
130
|
+
: null;
|
|
131
|
+
return { payload, status: "sent", messageId, url };
|
|
132
|
+
});
|
|
133
|
+
}
|