@abloatai/ablo 0.36.0 → 0.37.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/AGENTS.md +2 -2
- package/CHANGELOG.md +55 -2014
- package/NOTICE +2 -2
- package/README.md +45 -63
- package/assets/banner.png +0 -0
- package/dist/auth.d.ts +2 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +2 -0
- package/dist/auth.js.map +1 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +3 -0
- package/dist/client.js.map +1 -0
- package/dist/coordination.d.ts +2 -0
- package/dist/coordination.d.ts.map +1 -0
- package/dist/coordination.js +2 -0
- package/dist/coordination.js.map +1 -0
- package/dist/index.d.ts +3 -114
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -163
- package/dist/index.js.map +1 -0
- package/dist/react.d.ts +4 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +3 -0
- package/dist/react.js.map +1 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +2 -0
- package/dist/schema.js.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +2 -0
- package/dist/server.js.map +1 -0
- package/dist/source-conformance.d.ts +2 -0
- package/dist/source-conformance.d.ts.map +1 -0
- package/dist/source-conformance.js +2 -0
- package/dist/source-conformance.js.map +1 -0
- package/dist/source-drizzle.d.ts +2 -0
- package/dist/source-drizzle.d.ts.map +1 -0
- package/dist/source-drizzle.js +2 -0
- package/dist/source-drizzle.js.map +1 -0
- package/dist/source-kysely.d.ts +2 -0
- package/dist/source-kysely.d.ts.map +1 -0
- package/dist/source-kysely.js +2 -0
- package/dist/source-kysely.js.map +1 -0
- package/dist/source-next.d.ts +2 -0
- package/dist/source-next.d.ts.map +1 -0
- package/dist/source-next.js +2 -0
- package/dist/source-next.js.map +1 -0
- package/dist/source.d.ts +2 -0
- package/dist/source.d.ts.map +1 -0
- package/dist/source.js +2 -0
- package/dist/source.js.map +1 -0
- package/dist/wire.d.ts +2 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +2 -0
- package/dist/wire.js.map +1 -0
- package/docs/agents.md +1 -1
- package/docs/api-keys.md +7 -6
- package/docs/api.md +10 -10
- package/docs/client-behavior.md +5 -5
- package/docs/coordination.md +52 -62
- package/docs/data-sources.md +1 -1
- package/docs/examples/agent-human.md +4 -4
- package/docs/examples/ai-sdk-tool.md +1 -1
- package/docs/examples/existing-python-backend.md +15 -4
- package/docs/examples/nextjs.md +27 -6
- package/docs/examples/server-agent.md +2 -2
- package/docs/how-it-works.md +4 -4
- package/docs/identity.md +2 -1
- package/docs/integration-guide.md +24 -13
- package/docs/internal/README.md +18 -0
- package/docs/internal/agent-fleet-coordination-design.md +171 -0
- package/docs/internal/agent-orchestration.md +58 -0
- package/docs/internal/commit-identifiers.md +91 -0
- package/docs/internal/concurrency-open-decisions.md +37 -0
- package/docs/internal/data-source-reverse-channel.md +150 -0
- package/docs/internal/per-field-conflict-detection.md +165 -0
- package/docs/internal/postgres-replication.md +64 -0
- package/docs/internal/serializable-schema.md +119 -0
- package/docs/internal/structure.md +32 -0
- package/docs/mcp.md +2 -2
- package/docs/migration.md +3 -3
- package/docs/quickstart.md +2 -2
- package/docs/react.md +5 -5
- package/docs/schema-contract.md +3 -3
- package/docs/sessions.md +91 -37
- package/examples/README.md +2 -2
- package/examples/data-source/README.md +1 -1
- package/examples/data-source/ablo-driver.ts +1 -1
- package/examples/data-source/customer-server.ts +1 -1
- package/examples/data-source/run.ts +1 -1
- package/examples/data-source/schema.ts +1 -1
- package/examples/quickstart.ts +2 -2
- package/llms.txt +8 -8
- package/package.json +63 -166
- package/bin/ablo.cjs +0 -39
- package/dist/BaseSyncedStore.d.ts +0 -843
- package/dist/BaseSyncedStore.js +0 -1971
- package/dist/Database.d.ts +0 -323
- package/dist/Database.js +0 -1502
- package/dist/InstanceCache.d.ts +0 -237
- package/dist/InstanceCache.js +0 -1166
- package/dist/LazyReferenceCollection.d.ts +0 -177
- package/dist/LazyReferenceCollection.js +0 -461
- package/dist/Model.d.ts +0 -454
- package/dist/Model.js +0 -919
- package/dist/ModelRegistry.d.ts +0 -225
- package/dist/ModelRegistry.js +0 -539
- package/dist/NetworkMonitor.d.ts +0 -28
- package/dist/NetworkMonitor.js +0 -79
- package/dist/RuntimeContext.d.ts +0 -52
- package/dist/RuntimeContext.js +0 -80
- package/dist/SyncClient.d.ts +0 -541
- package/dist/SyncClient.js +0 -2202
- package/dist/adapters/alwaysOnline.d.ts +0 -14
- package/dist/adapters/alwaysOnline.js +0 -17
- package/dist/adapters/inMemoryStorage.d.ts +0 -31
- package/dist/adapters/inMemoryStorage.js +0 -110
- package/dist/ai-sdk/coordinatedTool.d.ts +0 -120
- package/dist/ai-sdk/coordinatedTool.js +0 -134
- package/dist/ai-sdk/coordinationContext.d.ts +0 -46
- package/dist/ai-sdk/coordinationContext.js +0 -106
- package/dist/ai-sdk/index.d.ts +0 -121
- package/dist/ai-sdk/index.js +0 -121
- package/dist/ai-sdk/wrap.d.ts +0 -65
- package/dist/ai-sdk/wrap.js +0 -39
- package/dist/auth/index.d.ts +0 -1
- package/dist/auth/index.js +0 -8
- package/dist/batching/index.d.ts +0 -55
- package/dist/batching/index.js +0 -147
- package/dist/client/Ablo.d.ts +0 -231
- package/dist/client/Ablo.js +0 -160
- package/dist/client/abloClient.d.ts +0 -309
- package/dist/client/abloClient.js +0 -13
- package/dist/client/clientPrelude.d.ts +0 -52
- package/dist/client/clientPrelude.js +0 -60
- package/dist/client/consoleLogger.d.ts +0 -35
- package/dist/client/consoleLogger.js +0 -44
- package/dist/client/coreClient.d.ts +0 -60
- package/dist/client/coreClient.js +0 -118
- package/dist/client/createInternalComponents.d.ts +0 -50
- package/dist/client/createInternalComponents.js +0 -98
- package/dist/client/createModelProxy.d.ts +0 -248
- package/dist/client/createModelProxy.js +0 -884
- package/dist/client/humans.d.ts +0 -69
- package/dist/client/humans.js +0 -78
- package/dist/client/modelRegistration.d.ts +0 -10
- package/dist/client/modelRegistration.js +0 -312
- package/dist/client/options.d.ts +0 -461
- package/dist/client/options.js +0 -7
- package/dist/client/reactiveEngine.d.ts +0 -53
- package/dist/client/reactiveEngine.js +0 -688
- package/dist/client/resourceTypes.d.ts +0 -12
- package/dist/client/resourceTypes.js +0 -10
- package/dist/client/schemaConfig.d.ts +0 -44
- package/dist/client/schemaConfig.js +0 -185
- package/dist/client/storeCluster.d.ts +0 -47
- package/dist/client/storeCluster.js +0 -118
- package/dist/client/storeLifecycle.d.ts +0 -61
- package/dist/client/storeLifecycle.js +0 -231
- package/dist/client/validateAbloOptions.d.ts +0 -42
- package/dist/client/validateAbloOptions.js +0 -43
- package/dist/client/wsMutationExecutor.d.ts +0 -27
- package/dist/client/wsMutationExecutor.js +0 -72
- package/dist/context.d.ts +0 -42
- package/dist/context.js +0 -81
- package/dist/coordination/ClaimLog.d.ts +0 -26
- package/dist/coordination/ClaimLog.js +0 -32
- package/dist/coordination/index.d.ts +0 -1
- package/dist/coordination/index.js +0 -8
- package/dist/core/index.d.ts +0 -33
- package/dist/core/index.js +0 -48
- package/dist/docs/catalog.d.ts +0 -72
- package/dist/docs/catalog.js +0 -230
- package/dist/docs/index.d.ts +0 -10
- package/dist/docs/index.js +0 -10
- package/dist/environment.d.ts +0 -1
- package/dist/environment.js +0 -8
- package/dist/interfaces/index.d.ts +0 -311
- package/dist/interfaces/index.js +0 -9
- package/dist/keys/index.d.ts +0 -1
- package/dist/keys/index.js +0 -8
- package/dist/mutators/RecordingMutation.d.ts +0 -36
- package/dist/mutators/RecordingMutation.js +0 -182
- package/dist/mutators/Transaction.d.ts +0 -40
- package/dist/mutators/Transaction.js +0 -58
- package/dist/mutators/UndoManager.d.ts +0 -258
- package/dist/mutators/UndoManager.js +0 -658
- package/dist/mutators/defineMutators.d.ts +0 -60
- package/dist/mutators/defineMutators.js +0 -18
- package/dist/mutators/inverseOp.d.ts +0 -126
- package/dist/mutators/inverseOp.js +0 -71
- package/dist/mutators/mutateActions.d.ts +0 -45
- package/dist/mutators/mutateActions.js +0 -105
- package/dist/mutators/readerActions.d.ts +0 -33
- package/dist/mutators/readerActions.js +0 -57
- package/dist/mutators/undoApply.d.ts +0 -51
- package/dist/mutators/undoApply.js +0 -117
- package/dist/policy/index.d.ts +0 -21
- package/dist/policy/index.js +0 -20
- package/dist/query/QueryProcessor.d.ts +0 -75
- package/dist/query/QueryProcessor.js +0 -255
- package/dist/query/client.d.ts +0 -64
- package/dist/query/client.js +0 -138
- package/dist/query/types.d.ts +0 -85
- package/dist/query/types.js +0 -16
- package/dist/react/AbloProvider.d.ts +0 -242
- package/dist/react/AbloProvider.js +0 -458
- package/dist/react/ClientSideSuspense.d.ts +0 -36
- package/dist/react/ClientSideSuspense.js +0 -17
- package/dist/react/DefaultFallback.d.ts +0 -24
- package/dist/react/DefaultFallback.js +0 -43
- package/dist/react/context.d.ts +0 -55
- package/dist/react/context.js +0 -29
- package/dist/react/createAbloReact.d.ts +0 -56
- package/dist/react/createAbloReact.js +0 -51
- package/dist/react/index.d.ts +0 -62
- package/dist/react/index.js +0 -69
- package/dist/react/internalContext.d.ts +0 -33
- package/dist/react/internalContext.js +0 -3
- package/dist/react/useAblo.d.ts +0 -82
- package/dist/react/useAblo.js +0 -120
- package/dist/react/useCurrentUserId.d.ts +0 -22
- package/dist/react/useCurrentUserId.js +0 -34
- package/dist/react/useErrorListener.d.ts +0 -20
- package/dist/react/useErrorListener.js +0 -38
- package/dist/react/useMutationFailureListener.d.ts +0 -26
- package/dist/react/useMutationFailureListener.js +0 -38
- package/dist/react/useMutators.d.ts +0 -56
- package/dist/react/useMutators.js +0 -84
- package/dist/react/useReactive.d.ts +0 -35
- package/dist/react/useReactive.js +0 -123
- package/dist/react/useSyncStatus.d.ts +0 -59
- package/dist/react/useSyncStatus.js +0 -76
- package/dist/react/useUndoScope.d.ts +0 -34
- package/dist/react/useUndoScope.js +0 -81
- package/dist/schema/coordination.d.ts +0 -112
- package/dist/schema/coordination.js +0 -133
- package/dist/schema/ddl.d.ts +0 -97
- package/dist/schema/ddl.js +0 -491
- package/dist/schema/ddlLock.d.ts +0 -35
- package/dist/schema/ddlLock.js +0 -46
- package/dist/schema/diff.d.ts +0 -225
- package/dist/schema/diff.js +0 -289
- package/dist/schema/generate.d.ts +0 -19
- package/dist/schema/generate.js +0 -86
- package/dist/schema/index.d.ts +0 -42
- package/dist/schema/index.js +0 -80
- package/dist/schema/queries.d.ts +0 -201
- package/dist/schema/queries.js +0 -144
- package/dist/schema/select.d.ts +0 -40
- package/dist/schema/select.js +0 -90
- package/dist/schema/serialize.d.ts +0 -115
- package/dist/schema/serialize.js +0 -265
- package/dist/schema/sugar.d.ts +0 -109
- package/dist/schema/sugar.js +0 -83
- package/dist/schema/syncDeltaRow.d.ts +0 -6
- package/dist/schema/syncDeltaRow.js +0 -6
- package/dist/server/adapter.d.ts +0 -173
- package/dist/server/adapter.js +0 -18
- package/dist/server/commit.d.ts +0 -107
- package/dist/server/commit.js +0 -1
- package/dist/server/index.d.ts +0 -14
- package/dist/server/index.js +0 -2
- package/dist/server/readConfig.d.ts +0 -80
- package/dist/server/readConfig.js +0 -8
- package/dist/server/storageMode.d.ts +0 -23
- package/dist/server/storageMode.js +0 -17
- package/dist/source/adapter.d.ts +0 -83
- package/dist/source/adapter.js +0 -24
- package/dist/source/adapters/drizzle.d.ts +0 -48
- package/dist/source/adapters/drizzle.js +0 -219
- package/dist/source/adapters/kysely.d.ts +0 -42
- package/dist/source/adapters/kysely.js +0 -205
- package/dist/source/adapters/kyselyMutationCore.d.ts +0 -76
- package/dist/source/adapters/kyselyMutationCore.js +0 -125
- package/dist/source/adapters/memory.d.ts +0 -13
- package/dist/source/adapters/memory.js +0 -130
- package/dist/source/adapters/prisma.d.ts +0 -63
- package/dist/source/adapters/prisma.js +0 -202
- package/dist/source/conformance.d.ts +0 -37
- package/dist/source/conformance.js +0 -215
- package/dist/source/connector.d.ts +0 -95
- package/dist/source/connector.js +0 -266
- package/dist/source/connectorProtocol.d.ts +0 -154
- package/dist/source/connectorProtocol.js +0 -163
- package/dist/source/contract.d.ts +0 -195
- package/dist/source/contract.js +0 -164
- package/dist/source/factory.d.ts +0 -92
- package/dist/source/factory.js +0 -286
- package/dist/source/idempotency.d.ts +0 -61
- package/dist/source/idempotency.js +0 -144
- package/dist/source/index.d.ts +0 -23
- package/dist/source/index.js +0 -30
- package/dist/source/migrations.d.ts +0 -21
- package/dist/source/migrations.js +0 -103
- package/dist/source/next.d.ts +0 -32
- package/dist/source/next.js +0 -25
- package/dist/source/pushQueue.d.ts +0 -134
- package/dist/source/pushQueue.js +0 -256
- package/dist/source/signing.d.ts +0 -92
- package/dist/source/signing.js +0 -162
- package/dist/source/types.d.ts +0 -401
- package/dist/source/types.js +0 -59
- package/dist/storeContract.d.ts +0 -145
- package/dist/storeContract.js +0 -12
- package/dist/stores/DatabaseManager.d.ts +0 -107
- package/dist/stores/DatabaseManager.js +0 -388
- package/dist/stores/ObjectStore.d.ts +0 -115
- package/dist/stores/ObjectStore.js +0 -393
- package/dist/stores/ObjectStoreContract.d.ts +0 -38
- package/dist/stores/ObjectStoreContract.js +0 -1
- package/dist/stores/StoreManager.d.ts +0 -114
- package/dist/stores/StoreManager.js +0 -304
- package/dist/stores/SyncActionStore.d.ts +0 -99
- package/dist/stores/SyncActionStore.js +0 -506
- package/dist/stores/openIDBWithTimeout.d.ts +0 -65
- package/dist/stores/openIDBWithTimeout.js +0 -153
- package/dist/stores/syncAction.d.ts +0 -26
- package/dist/stores/syncAction.js +0 -16
- package/dist/surface.d.ts +0 -36
- package/dist/surface.js +0 -75
- package/dist/sync/BootstrapFetcher.d.ts +0 -284
- package/dist/sync/BootstrapFetcher.js +0 -964
- package/dist/sync/ConnectionManager.d.ts +0 -8
- package/dist/sync/ConnectionManager.js +0 -8
- package/dist/sync/OnDemandLoader.d.ts +0 -231
- package/dist/sync/OnDemandLoader.js +0 -743
- package/dist/sync/SubscriptionManager.d.ts +0 -159
- package/dist/sync/SubscriptionManager.js +0 -243
- package/dist/sync/SyncWebSocket.d.ts +0 -173
- package/dist/sync/SyncWebSocket.js +0 -438
- package/dist/sync/awaitClaimGrant.d.ts +0 -6
- package/dist/sync/awaitClaimGrant.js +0 -6
- package/dist/sync/bootstrapApply.d.ts +0 -73
- package/dist/sync/bootstrapApply.js +0 -73
- package/dist/sync/commitFrames.d.ts +0 -8
- package/dist/sync/commitFrames.js +0 -8
- package/dist/sync/contextPorts.d.ts +0 -18
- package/dist/sync/contextPorts.js +0 -31
- package/dist/sync/createClaimStream.d.ts +0 -7
- package/dist/sync/createClaimStream.js +0 -7
- package/dist/sync/createPresenceStream.d.ts +0 -69
- package/dist/sync/createPresenceStream.js +0 -200
- package/dist/sync/createSnapshot.d.ts +0 -29
- package/dist/sync/createSnapshot.js +0 -118
- package/dist/sync/credentialLifecycle.d.ts +0 -7
- package/dist/sync/credentialLifecycle.js +0 -7
- package/dist/sync/deltaPipeline.d.ts +0 -114
- package/dist/sync/deltaPipeline.js +0 -278
- package/dist/sync/groupChange.d.ts +0 -116
- package/dist/sync/groupChange.js +0 -244
- package/dist/sync/participants.d.ts +0 -132
- package/dist/sync/participants.js +0 -346
- package/dist/sync/persistedPrefix.d.ts +0 -12
- package/dist/sync/persistedPrefix.js +0 -22
- package/dist/sync/schemaDrift.d.ts +0 -55
- package/dist/sync/schemaDrift.js +0 -53
- package/dist/sync/schemas.d.ts +0 -71
- package/dist/sync/schemas.js +0 -94
- package/dist/sync/syncCursor.d.ts +0 -40
- package/dist/sync/syncCursor.js +0 -55
- package/dist/sync/syncPlan.d.ts +0 -54
- package/dist/sync/syncPlan.js +0 -50
- package/dist/sync/wsFrameHandlers.d.ts +0 -8
- package/dist/sync/wsFrameHandlers.js +0 -8
- package/dist/syncLog/contract.d.ts +0 -20
- package/dist/syncLog/contract.js +0 -19
- package/dist/syncLog/index.d.ts +0 -1
- package/dist/syncLog/index.js +0 -1
- package/dist/transaction/ablo.d.ts +0 -88
- package/dist/transaction/ablo.js +0 -33
- package/dist/transaction/auth/apiKey.d.ts +0 -152
- package/dist/transaction/auth/apiKey.js +0 -419
- package/dist/transaction/auth/bootstrapScope.d.ts +0 -15
- package/dist/transaction/auth/bootstrapScope.js +0 -1
- package/dist/transaction/auth/capability.d.ts +0 -212
- package/dist/transaction/auth/capability.js +0 -224
- package/dist/transaction/auth/credentialEndpoint.d.ts +0 -61
- package/dist/transaction/auth/credentialEndpoint.js +0 -86
- package/dist/transaction/auth/credentialPolicy.d.ts +0 -148
- package/dist/transaction/auth/credentialPolicy.js +0 -125
- package/dist/transaction/auth/credentialSource.d.ts +0 -30
- package/dist/transaction/auth/credentialSource.js +0 -55
- package/dist/transaction/auth/hostedEndpoints.d.ts +0 -21
- package/dist/transaction/auth/hostedEndpoints.js +0 -21
- package/dist/transaction/auth/identity.d.ts +0 -55
- package/dist/transaction/auth/identity.js +0 -210
- package/dist/transaction/auth/index.d.ts +0 -162
- package/dist/transaction/auth/index.js +0 -304
- package/dist/transaction/auth/schemas.d.ts +0 -59
- package/dist/transaction/auth/schemas.js +0 -85
- package/dist/transaction/auth/sessionMint.d.ts +0 -28
- package/dist/transaction/auth/sessionMint.js +0 -85
- package/dist/transaction/coordination/awaitClaimGrant.d.ts +0 -56
- package/dist/transaction/coordination/awaitClaimGrant.js +0 -124
- package/dist/transaction/coordination/claimHeartbeatLoop.d.ts +0 -84
- package/dist/transaction/coordination/claimHeartbeatLoop.js +0 -108
- package/dist/transaction/coordination/claimMeta.d.ts +0 -49
- package/dist/transaction/coordination/claimMeta.js +0 -52
- package/dist/transaction/coordination/createClaimStream.d.ts +0 -64
- package/dist/transaction/coordination/createClaimStream.js +0 -475
- package/dist/transaction/coordination/events.d.ts +0 -74
- package/dist/transaction/coordination/events.js +0 -7
- package/dist/transaction/coordination/index.d.ts +0 -19
- package/dist/transaction/coordination/index.js +0 -45
- package/dist/transaction/coordination/locator.d.ts +0 -104
- package/dist/transaction/coordination/locator.js +0 -102
- package/dist/transaction/coordination/schema.d.ts +0 -1536
- package/dist/transaction/coordination/schema.js +0 -1177
- package/dist/transaction/coordination/targetConflict.d.ts +0 -2
- package/dist/transaction/coordination/targetConflict.js +0 -107
- package/dist/transaction/coordination/trace.d.ts +0 -78
- package/dist/transaction/coordination/trace.js +0 -138
- package/dist/transaction/durableWrites.d.ts +0 -62
- package/dist/transaction/durableWrites.js +0 -71
- package/dist/transaction/environment.d.ts +0 -105
- package/dist/transaction/environment.js +0 -108
- package/dist/transaction/errorCodes.d.ts +0 -403
- package/dist/transaction/errorCodes.js +0 -484
- package/dist/transaction/errors.d.ts +0 -428
- package/dist/transaction/errors.js +0 -686
- package/dist/transaction/footprint.d.ts +0 -111
- package/dist/transaction/footprint.js +0 -0
- package/dist/transaction/index.d.ts +0 -20
- package/dist/transaction/index.js +0 -20
- package/dist/transaction/keys/index.d.ts +0 -87
- package/dist/transaction/keys/index.js +0 -207
- package/dist/transaction/log/syncDeltaRow.d.ts +0 -158
- package/dist/transaction/log/syncDeltaRow.js +0 -95
- package/dist/transaction/logPosition.d.ts +0 -97
- package/dist/transaction/logPosition.js +0 -125
- package/dist/transaction/logger.d.ts +0 -16
- package/dist/transaction/logger.js +0 -7
- package/dist/transaction/observability.d.ts +0 -53
- package/dist/transaction/observability.js +0 -19
- package/dist/transaction/persistence.d.ts +0 -12
- package/dist/transaction/persistence.js +0 -11
- package/dist/transaction/plugin.d.ts +0 -285
- package/dist/transaction/plugin.js +0 -106
- package/dist/transaction/policy/types.d.ts +0 -217
- package/dist/transaction/policy/types.js +0 -126
- package/dist/transaction/resources/functionalUpdate.d.ts +0 -79
- package/dist/transaction/resources/functionalUpdate.js +0 -87
- package/dist/transaction/resources/httpResources.d.ts +0 -321
- package/dist/transaction/resources/httpResources.js +0 -7
- package/dist/transaction/resources/modelOperations.d.ts +0 -427
- package/dist/transaction/resources/modelOperations.js +0 -12
- package/dist/transaction/resources/mutationOptions.d.ts +0 -66
- package/dist/transaction/resources/mutationOptions.js +0 -9
- package/dist/transaction/resources/where.d.ts +0 -101
- package/dist/transaction/resources/where.js +0 -115
- package/dist/transaction/resources/writeOptionsSchema.d.ts +0 -47
- package/dist/transaction/resources/writeOptionsSchema.js +0 -73
- package/dist/transaction/schema/field.d.ts +0 -120
- package/dist/transaction/schema/field.js +0 -265
- package/dist/transaction/schema/fieldRef.d.ts +0 -38
- package/dist/transaction/schema/fieldRef.js +0 -11
- package/dist/transaction/schema/loadStrategy.d.ts +0 -45
- package/dist/transaction/schema/loadStrategy.js +0 -46
- package/dist/transaction/schema/model.d.ts +0 -379
- package/dist/transaction/schema/model.js +0 -123
- package/dist/transaction/schema/openapi.d.ts +0 -58
- package/dist/transaction/schema/openapi.js +0 -501
- package/dist/transaction/schema/relation.d.ts +0 -204
- package/dist/transaction/schema/relation.js +0 -104
- package/dist/transaction/schema/residency.d.ts +0 -29
- package/dist/transaction/schema/residency.js +0 -25
- package/dist/transaction/schema/roles.d.ts +0 -249
- package/dist/transaction/schema/roles.js +0 -230
- package/dist/transaction/schema/schema.d.ts +0 -351
- package/dist/transaction/schema/schema.js +0 -325
- package/dist/transaction/schema/tenancy.d.ts +0 -139
- package/dist/transaction/schema/tenancy.js +0 -190
- package/dist/transaction/transactionLayer.d.ts +0 -82
- package/dist/transaction/transactionLayer.js +0 -24
- package/dist/transaction/transactions/settlement/commitEnvelope.d.ts +0 -143
- package/dist/transaction/transactions/settlement/commitEnvelope.js +0 -161
- package/dist/transaction/transactions/settlement/httpCommitEnvelope.d.ts +0 -53
- package/dist/transaction/transactions/settlement/httpCommitEnvelope.js +0 -207
- package/dist/transaction/transactions/settlement/idempotencyKey.d.ts +0 -10
- package/dist/transaction/transactions/settlement/idempotencyKey.js +0 -9
- package/dist/transaction/transactions/settlement/pendingWrite.d.ts +0 -112
- package/dist/transaction/transactions/settlement/pendingWrite.js +0 -20
- package/dist/transaction/transport/commitFrames.d.ts +0 -90
- package/dist/transaction/transport/commitFrames.js +0 -134
- package/dist/transaction/transport/connectionManager.d.ts +0 -215
- package/dist/transaction/transport/connectionManager.js +0 -673
- package/dist/transaction/transport/credentialLifecycle.d.ts +0 -177
- package/dist/transaction/transport/credentialLifecycle.js +0 -324
- package/dist/transaction/transport/heartbeat.d.ts +0 -65
- package/dist/transaction/transport/heartbeat.js +0 -93
- package/dist/transaction/transport/httpClient.d.ts +0 -131
- package/dist/transaction/transport/httpClient.js +0 -146
- package/dist/transaction/transport/httpOptions.d.ts +0 -33
- package/dist/transaction/transport/httpOptions.js +0 -12
- package/dist/transaction/transport/httpTransport.d.ts +0 -8
- package/dist/transaction/transport/httpTransport.js +0 -1388
- package/dist/transaction/transport/networkProbe.d.ts +0 -84
- package/dist/transaction/transport/networkProbe.js +0 -207
- package/dist/transaction/transport/wsFrameHandlers.d.ts +0 -128
- package/dist/transaction/transport/wsFrameHandlers.js +0 -429
- package/dist/transaction/transport/wsTransport.d.ts +0 -574
- package/dist/transaction/transport/wsTransport.js +0 -1023
- package/dist/transaction/types/assertExact.d.ts +0 -17
- package/dist/transaction/types/assertExact.js +0 -1
- package/dist/transaction/types/global.d.ts +0 -107
- package/dist/transaction/types/global.js +0 -40
- package/dist/transaction/types/index.d.ts +0 -205
- package/dist/transaction/types/index.js +0 -56
- package/dist/transaction/types/modelData.d.ts +0 -10
- package/dist/transaction/types/modelData.js +0 -9
- package/dist/transaction/types/participant.d.ts +0 -20
- package/dist/transaction/types/participant.js +0 -10
- package/dist/transaction/types/streams.d.ts +0 -550
- package/dist/transaction/types/streams.js +0 -11
- package/dist/transaction/utils/asyncIterator.d.ts +0 -34
- package/dist/transaction/utils/asyncIterator.js +0 -135
- package/dist/transaction/utils/duration.d.ts +0 -50
- package/dist/transaction/utils/duration.js +0 -77
- package/dist/transaction/utils/json.d.ts +0 -57
- package/dist/transaction/utils/json.js +0 -276
- package/dist/transaction/wire/accountResponses.d.ts +0 -420
- package/dist/transaction/wire/accountResponses.js +0 -290
- package/dist/transaction/wire/auth.d.ts +0 -56
- package/dist/transaction/wire/auth.js +0 -63
- package/dist/transaction/wire/bootstrapReason.d.ts +0 -9
- package/dist/transaction/wire/bootstrapReason.js +0 -8
- package/dist/transaction/wire/claimEvent.d.ts +0 -76
- package/dist/transaction/wire/claimEvent.js +0 -73
- package/dist/transaction/wire/claims.d.ts +0 -530
- package/dist/transaction/wire/claims.js +0 -327
- package/dist/transaction/wire/commit.d.ts +0 -603
- package/dist/transaction/wire/commit.js +0 -321
- package/dist/transaction/wire/delta.d.ts +0 -250
- package/dist/transaction/wire/delta.js +0 -147
- package/dist/transaction/wire/errorEnvelope.d.ts +0 -72
- package/dist/transaction/wire/errorEnvelope.js +0 -123
- package/dist/transaction/wire/feedCursor.d.ts +0 -60
- package/dist/transaction/wire/feedCursor.js +0 -82
- package/dist/transaction/wire/feedEvent.d.ts +0 -204
- package/dist/transaction/wire/feedEvent.js +0 -65
- package/dist/transaction/wire/frames.d.ts +0 -194
- package/dist/transaction/wire/frames.js +0 -50
- package/dist/transaction/wire/inboundFrames.d.ts +0 -562
- package/dist/transaction/wire/inboundFrames.js +0 -116
- package/dist/transaction/wire/index.d.ts +0 -54
- package/dist/transaction/wire/index.js +0 -83
- package/dist/transaction/wire/listEnvelope.d.ts +0 -37
- package/dist/transaction/wire/listEnvelope.js +0 -42
- package/dist/transaction/wire/modelMutations.d.ts +0 -31
- package/dist/transaction/wire/modelMutations.js +0 -52
- package/dist/transaction/wire/modelResponses.d.ts +0 -85
- package/dist/transaction/wire/modelResponses.js +0 -43
- package/dist/transaction/wire/modelShape.d.ts +0 -78
- package/dist/transaction/wire/modelShape.js +0 -74
- package/dist/transaction/wire/protocol.d.ts +0 -38
- package/dist/transaction/wire/protocol.js +0 -38
- package/dist/transaction/wire/protocolVersion.d.ts +0 -73
- package/dist/transaction/wire/protocolVersion.js +0 -83
- package/dist/transactions/mutations/MutationQueue.d.ts +0 -661
- package/dist/transactions/mutations/MutationQueue.js +0 -2807
- package/dist/transactions/mutations/MutationStore.d.ts +0 -20
- package/dist/transactions/mutations/MutationStore.js +0 -53
- package/dist/transactions/mutations/UnconfirmedWrites.d.ts +0 -82
- package/dist/transactions/mutations/UnconfirmedWrites.js +0 -104
- package/dist/transactions/mutations/coalesceRules.d.ts +0 -58
- package/dist/transactions/mutations/coalesceRules.js +0 -140
- package/dist/transactions/mutations/commitLatency.d.ts +0 -52
- package/dist/transactions/mutations/commitLatency.js +0 -130
- package/dist/transactions/mutations/commitOutboxStore.d.ts +0 -28
- package/dist/transactions/mutations/commitOutboxStore.js +0 -26
- package/dist/transactions/mutations/commitPayload.d.ts +0 -165
- package/dist/transactions/mutations/commitPayload.js +0 -152
- package/dist/transactions/mutations/deltaConfirmation.d.ts +0 -63
- package/dist/transactions/mutations/deltaConfirmation.js +0 -235
- package/dist/transactions/mutations/durableWriteStore.d.ts +0 -14
- package/dist/transactions/mutations/durableWriteStore.js +0 -12
- package/dist/transactions/mutations/optimisticApply.d.ts +0 -49
- package/dist/transactions/mutations/optimisticApply.js +0 -65
- package/dist/transactions/mutations/replayValidation.d.ts +0 -187
- package/dist/transactions/mutations/replayValidation.js +0 -164
- package/dist/utils/mobxSetup.d.ts +0 -53
- package/dist/utils/mobxSetup.js +0 -330
- package/dist/views/QueryView.d.ts +0 -79
- package/dist/views/QueryView.js +0 -218
- package/dist/views/ViewRegistry.d.ts +0 -20
- package/dist/views/ViewRegistry.js +0 -55
- package/dist/views/incrementalView.d.ts +0 -45
- package/dist/views/incrementalView.js +0 -69
- package/dist/webhooks/events.d.ts +0 -43
- package/dist/webhooks/events.js +0 -42
- package/dist/webhooks/index.d.ts +0 -8
- package/dist/webhooks/index.js +0 -8
- package/dist/wire/index.d.ts +0 -1
- package/dist/wire/index.js +0 -8
|
@@ -1,1177 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { syncGroupInputSchema } from '../schema/roles.js';
|
|
3
|
-
import { isFieldRef } from '../schema/fieldRef.js';
|
|
4
|
-
/**
|
|
5
|
-
* The wire schemas for coordination — the shapes that keep agents and people
|
|
6
|
-
* from overwriting each other on a shared row. Coordination works in three
|
|
7
|
-
* layers, from outermost to innermost:
|
|
8
|
-
*
|
|
9
|
-
* 1. Presence (observation): who is working where. It reports, never blocks.
|
|
10
|
-
* 2. Claims (pessimistic leases): `claim_begin` / `claim_abandon` grant one
|
|
11
|
-
* participant exclusive intent on a target while others wait.
|
|
12
|
-
* 3. Stale-context (optimistic): a `readAt` watermark plus an `onStale` write
|
|
13
|
-
* guard that catches a lost update when the row moved after you read it.
|
|
14
|
-
*
|
|
15
|
-
* These Zod schemas are the single definition of each shape. Both the client
|
|
16
|
-
* SDK and the server derive their TypeScript types from them with `z.infer`
|
|
17
|
-
* rather than re-declaring the shapes, and the server validates inbound frames
|
|
18
|
-
* against them at runtime.
|
|
19
|
-
*/
|
|
20
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
21
|
-
// Shared primitives
|
|
22
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
23
|
-
/**
|
|
24
|
-
* A span within a text-bearing part of a row (section body, doc, cell).
|
|
25
|
-
*
|
|
26
|
-
* Overlap is judged on the line axis alone: two ranges conflict when their
|
|
27
|
-
* `[startLine, endLine]` intervals intersect, and columns ride along for
|
|
28
|
-
* display. An editor that addresses by integer position rather than by line
|
|
29
|
-
* maps that position axis straight onto `startLine`/`endLine` — the test is
|
|
30
|
-
* plain interval intersection and never assumes the units are lines of a file.
|
|
31
|
-
*/
|
|
32
|
-
export const targetRangeSchema = z
|
|
33
|
-
.object({
|
|
34
|
-
startLine: z.number(),
|
|
35
|
-
endLine: z.number(),
|
|
36
|
-
startColumn: z.number().optional(),
|
|
37
|
-
endColumn: z.number().optional(),
|
|
38
|
-
})
|
|
39
|
-
// An inverted span claims nothing and collides with nothing — reject it at
|
|
40
|
-
// the boundary instead of granting a lease that never excludes anyone.
|
|
41
|
-
.refine((range) => range.startLine <= range.endLine, {
|
|
42
|
-
message: 'range.startLine must not be greater than range.endLine.',
|
|
43
|
-
});
|
|
44
|
-
/**
|
|
45
|
-
* Name an app-defined part of a row for a claim target: `part('B2')` for a
|
|
46
|
-
* cell, `part('sec_intro')` for a section. The conflict rule compares part
|
|
47
|
-
* names as opaque case-insensitive strings, so any name is legal on the
|
|
48
|
-
* wire — this marker exists purely so the type surface stays definite about
|
|
49
|
-
* the model's own fields.
|
|
50
|
-
*/
|
|
51
|
-
export function part(name) {
|
|
52
|
-
return { part: name };
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* The wire spelling of a part name, from whichever spelling the caller used.
|
|
56
|
-
*
|
|
57
|
-
* Three, because they are three different promises. A {@link FieldRef} —
|
|
58
|
-
* `schema.fields.tasks.status` — is a field the schema declares, so a name that
|
|
59
|
-
* does not exist never compiles. `part('B2')` is a name the schema does not
|
|
60
|
-
* know and says so. A bare string is neither, and survives only because the
|
|
61
|
-
* erased `SchemaRecord` view and untyped callers still need it.
|
|
62
|
-
*
|
|
63
|
-
* All three become the same string here: the wire has always carried names, and
|
|
64
|
-
* what differs is how much was known before the crossing.
|
|
65
|
-
*/
|
|
66
|
-
export function partName(value) {
|
|
67
|
-
if (typeof value === 'string')
|
|
68
|
-
return value;
|
|
69
|
-
return isFieldRef(value) ? value.field : value.part;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* One claimable part name.
|
|
73
|
-
*
|
|
74
|
-
* Names compare as opaque strings, so any name is legal — except one that is
|
|
75
|
-
* plainly several. A caller who needed to claim two parts and had only `field`
|
|
76
|
-
* to say it in packed them into one delimited string, and because
|
|
77
|
-
* `blocks:b_1,b_2` and `blocks:b_1` are different names, both writers were
|
|
78
|
-
* granted a lease on `b_1` and one of their updates was lost with nothing
|
|
79
|
-
* raised. `fields` exists to say that, and refusing the packed spelling is what
|
|
80
|
-
* makes the mistake visible at the moment it is made rather than as a missing
|
|
81
|
-
* update later.
|
|
82
|
-
*
|
|
83
|
-
* Deliberately narrow: only the comma, because that is what a caller reaches
|
|
84
|
-
* for to join a list. A part name is otherwise free.
|
|
85
|
-
*/
|
|
86
|
-
const partNameSchema = z.string().refine((name) => !name.includes(','), {
|
|
87
|
-
message: 'A part name cannot contain a comma. Claim several parts with `fields: [a, b]` — two names in one `field` compare as a single unrelated name, so both writers would be granted the same part.',
|
|
88
|
-
});
|
|
89
|
-
export const participantKindSchema = z.enum(['user', 'agent', 'system']);
|
|
90
|
-
const _participantKindContract = true;
|
|
91
|
-
void _participantKindContract;
|
|
92
|
-
/**
|
|
93
|
-
* Parses a participant kind from an inbound frame, tolerating an older wire
|
|
94
|
-
* dialect. Some presence and claim frames label a non-agent participant
|
|
95
|
-
* `'human'`, while the rest of the surface uses `'user'` for the same
|
|
96
|
-
* participant. This normalizes `'human'` to `'user'` on read so every consumer
|
|
97
|
-
* switches on one vocabulary. Producers emit the canonical
|
|
98
|
-
* {@link participantKindSchema} values, and the output union is never widened.
|
|
99
|
-
*/
|
|
100
|
-
export const wireParticipantKindSchema = z.preprocess((value) => (value === 'human' ? 'user' : value), participantKindSchema);
|
|
101
|
-
/**
|
|
102
|
-
* Resolves a peer's kind from an inbound presence or claim frame. It prefers
|
|
103
|
-
* the server-stamped `participantKind` (normalized through
|
|
104
|
-
* {@link wireParticipantKindSchema}). A frame from an older server that omits
|
|
105
|
-
* that field falls back to the `isAgent` boolean, which can tell 'agent' from
|
|
106
|
-
* 'user' but can never report 'system'.
|
|
107
|
-
*/
|
|
108
|
-
export function participantKindFromWire(wireKind, isAgent) {
|
|
109
|
-
const parsed = wireParticipantKindSchema.safeParse(wireKind);
|
|
110
|
-
if (parsed.success)
|
|
111
|
-
return parsed.data;
|
|
112
|
-
return isAgent ? 'agent' : 'user';
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Reads the peer-visible description a claim or presence frame carries in its
|
|
116
|
-
* opaque `meta.description`. This is the single place that unpacks that field.
|
|
117
|
-
* A caller that has an explicit `description` should prefer it
|
|
118
|
-
* (`explicit ?? fromMeta`).
|
|
119
|
-
*
|
|
120
|
-
* The parameter is `unknown` because that is the honest requirement: this reads
|
|
121
|
-
* one optional string off a value it does not own. Demanding the wire's open
|
|
122
|
-
* record instead forced every caller holding a claim's *declared* `meta` — the
|
|
123
|
-
* shape registered on `Register`'s `ClaimMeta` slot — through a conversion to
|
|
124
|
-
* ask a question that never needed one.
|
|
125
|
-
*/
|
|
126
|
-
export function descriptionFromMeta(meta) {
|
|
127
|
-
if (typeof meta !== 'object' || meta === null)
|
|
128
|
-
return undefined;
|
|
129
|
-
if (!('description' in meta))
|
|
130
|
-
return undefined;
|
|
131
|
-
const { description } = meta;
|
|
132
|
-
return typeof description === 'string' ? description : undefined;
|
|
133
|
-
}
|
|
134
|
-
/** The default a claim carries when its holder describes no work. */
|
|
135
|
-
export const DEFAULT_CLAIM_DESCRIPTION = 'editing';
|
|
136
|
-
/**
|
|
137
|
-
* Resolves the peer-visible description of a claim from the places a caller may
|
|
138
|
-
* have put it, falling back to a plain default.
|
|
139
|
-
*
|
|
140
|
-
* `reason` was this field's name before it was renamed, and the rename shipped
|
|
141
|
-
* without leaving anything behind — so the wire kept accepting both spellings
|
|
142
|
-
* while the SDK type quietly offered only one, and two branches "fixed" the
|
|
143
|
-
* gap in opposite directions without either being contradicted by a compiler.
|
|
144
|
-
* The precedence is declared once, here, and both the client and the server
|
|
145
|
-
* read it from this function rather than each spelling out the same `??` chain.
|
|
146
|
-
*
|
|
147
|
-
* A caller whose default differs — a claim taken around a `create` describes
|
|
148
|
-
* itself as `'creating'` — passes that word as `fallback`; the precedence above
|
|
149
|
-
* it stays this function's.
|
|
150
|
-
*/
|
|
151
|
-
export function claimDescription(source, fallback = DEFAULT_CLAIM_DESCRIPTION) {
|
|
152
|
-
return (source.description ??
|
|
153
|
-
descriptionFromMeta(source.meta) ??
|
|
154
|
-
source.reason ??
|
|
155
|
-
fallback);
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* What a coordination event points at — the locator shared by all three
|
|
159
|
-
* layers. It names an entity, optionally narrowed to a path, range, or field,
|
|
160
|
-
* and carries opaque application metadata.
|
|
161
|
-
*/
|
|
162
|
-
export const targetRefSchema = z.object({
|
|
163
|
-
entityType: z.string(),
|
|
164
|
-
entityId: z.string(),
|
|
165
|
-
path: z.string().optional(),
|
|
166
|
-
range: targetRangeSchema.optional(),
|
|
167
|
-
field: partNameSchema.optional(),
|
|
168
|
-
/**
|
|
169
|
-
* Several named parts of one row, claimed together — three sections of a
|
|
170
|
-
* document, two cells of a table.
|
|
171
|
-
*
|
|
172
|
-
* This exists because there was no way to say it. A caller who needed it
|
|
173
|
-
* packed the set into `field` as one delimited string, and the conflict rule
|
|
174
|
-
* compares `field` for equality: `blocks:b_1` and `blocks:b_1,b_2` read as
|
|
175
|
-
* unrelated targets, so both writers were granted a lease on `b_1` and one
|
|
176
|
-
* of their updates was lost with nothing raised. A set compares as a set —
|
|
177
|
-
* overlapping sets conflict, disjoint sets do not.
|
|
178
|
-
*
|
|
179
|
-
* `field` remains for the single-field case and is read as a set of one, so
|
|
180
|
-
* a claim naming `field` and a claim naming `fields` still compare correctly
|
|
181
|
-
* against each other.
|
|
182
|
-
*/
|
|
183
|
-
fields: z.array(partNameSchema).readonly().optional(),
|
|
184
|
-
meta: z.record(z.string(), z.unknown()).optional(),
|
|
185
|
-
});
|
|
186
|
-
/**
|
|
187
|
-
* The same locator in the spelling the wait line and the claim handle use —
|
|
188
|
-
* `{ type, id }` for the entity, the sub-entity half unchanged. It is a
|
|
189
|
-
* projection of {@link targetRefSchema} rather than a second declaration, so a
|
|
190
|
-
* member added to the locator reaches the wait line without anyone editing it;
|
|
191
|
-
* a hand-written copy here is how `fields` came to be missing from queue frames.
|
|
192
|
-
*/
|
|
193
|
-
const streamTargetSchema = targetRefSchema
|
|
194
|
-
.omit({ entityType: true, entityId: true })
|
|
195
|
-
.extend({ type: z.string(), id: z.string() });
|
|
196
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
197
|
-
// Layer 3 — optimistic stale-context (the write guard)
|
|
198
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
199
|
-
/**
|
|
200
|
-
* How the server treats a write whose snapshot watermark (`readAt`) is older
|
|
201
|
-
* than the target row's latest change. There are three dispositions:
|
|
202
|
-
* • `notify` — hold the write and return a {@link StaleNotification}
|
|
203
|
-
* carrying the current value, so the actor (agent or human)
|
|
204
|
-
* can resolve it.
|
|
205
|
-
* • `reject` — throw `AbloStaleContextError`, the default when `readAt`
|
|
206
|
-
* is present.
|
|
207
|
-
* • `overwrite` — apply the write blindly, last write wins, with no signal.
|
|
208
|
-
*/
|
|
209
|
-
export const onStaleModeSchema = z.enum(['reject', 'overwrite', 'notify']);
|
|
210
|
-
/**
|
|
211
|
-
* The optimistic guard carried on a commit operation. `readAt` is the
|
|
212
|
-
* snapshot watermark from `context.capture` (null/absent ⇒ unguarded write).
|
|
213
|
-
* `bypass` is the explicit, recorded override of a *foreign* pessimistic
|
|
214
|
-
* claim — see the claim layer below.
|
|
215
|
-
*/
|
|
216
|
-
export const writeGuardSchema = z.object({
|
|
217
|
-
readAt: z.number().nullish(),
|
|
218
|
-
onStale: onStaleModeSchema.nullish(),
|
|
219
|
-
bypass: z.boolean().optional(),
|
|
220
|
-
});
|
|
221
|
-
/**
|
|
222
|
-
* The advisory returned to a committer whose write hit a stale-context
|
|
223
|
-
* conflict under `onStale: 'notify'` — it reports that the value the committer
|
|
224
|
-
* reasoned against changed while they were away. Rather than throwing, the
|
|
225
|
-
* server hands back the conflicting field's current value as data so the
|
|
226
|
-
* actor — an agent or a human — can reconcile and re-commit. A claim is the
|
|
227
|
-
* prospective form of the same idea (coordinate before acting); this
|
|
228
|
-
* notification is the in-flight form (here is what changed, you resolve). It
|
|
229
|
-
* rides on the commit acknowledgement alongside `lastSyncId`; an empty or
|
|
230
|
-
* absent array means nothing the committer depended on moved.
|
|
231
|
-
*
|
|
232
|
-
* Only `onStale: 'notify'` produces this. The conflicting operation was held,
|
|
233
|
-
* not written, and the actor reconciles against `currentValues` and
|
|
234
|
-
* re-commits. `reject` throws instead, and `overwrite` proceeds silently —
|
|
235
|
-
* neither notifies.
|
|
236
|
-
*/
|
|
237
|
-
export const staleNotificationSchema = z.object({
|
|
238
|
-
/** Names this object's type; every returned object carries such a tag. */
|
|
239
|
-
object: z.literal('stale_notification').optional(),
|
|
240
|
-
/** Model name of the conflicting row. */
|
|
241
|
-
model: z.string(),
|
|
242
|
-
/** Row id. */
|
|
243
|
-
id: z.string(),
|
|
244
|
-
/** The watermark the committer reasoned against (its `readAt`). */
|
|
245
|
-
readAt: z.number(),
|
|
246
|
-
/**
|
|
247
|
-
* Newest delta id on the row — the committer's new watermark. Re-capture
|
|
248
|
-
* context at/after this id to reconcile.
|
|
249
|
-
*/
|
|
250
|
-
observedSyncId: z.number(),
|
|
251
|
-
/**
|
|
252
|
-
* Fields whose concurrent change collided with this write (intersection of
|
|
253
|
-
* the committer's written columns and a newer delta's `changed_fields`).
|
|
254
|
-
* Empty ⇒ a whole-entity change (CREATE/DELETE/legacy delta).
|
|
255
|
-
*/
|
|
256
|
-
conflictingFields: z.array(z.string()),
|
|
257
|
-
/**
|
|
258
|
-
* The live values of `conflictingFields` after the conflict — the piece a
|
|
259
|
-
* plain stale error omits. It lets the actor reconcile without a follow-up read.
|
|
260
|
-
*/
|
|
261
|
-
currentValues: z.record(z.string(), z.unknown()),
|
|
262
|
-
/** Who wrote the conflicting delta. */
|
|
263
|
-
writtenBy: z.object({
|
|
264
|
-
kind: participantKindSchema,
|
|
265
|
-
id: z.string(),
|
|
266
|
-
}),
|
|
267
|
-
/**
|
|
268
|
-
* Set when this notification is for a GROUP premise (e.g. `report:abc`,
|
|
269
|
-
* `section:s1`) rather than a single row — "something in the group you read
|
|
270
|
-
* changed." For a group notification `conflictingFields`/`currentValues` are
|
|
271
|
-
* empty (the change could span many rows); re-read the group at
|
|
272
|
-
* `observedSyncId` to reconcile. Absent ⇒ a row-scoped notification.
|
|
273
|
-
*/
|
|
274
|
-
group: z.string().optional(),
|
|
275
|
-
});
|
|
276
|
-
/**
|
|
277
|
-
* One entry in a commit's batch premise — a read it was based on, so the
|
|
278
|
-
* server can ask "did anything I looked at change?" — broader than the
|
|
279
|
-
* write-target check, which only validates the rows being written. The server
|
|
280
|
-
* re-runs stale detection against each entry at its `readAt`; a moved premise
|
|
281
|
-
* fires the entry's `onStale` disposition (default `reject`) across the whole
|
|
282
|
-
* batch (`notify` holds every write and notifies, `reject` aborts, `overwrite`
|
|
283
|
-
* proceeds silently). An entry comes at one of two granularities:
|
|
284
|
-
*
|
|
285
|
-
* • Row — `{ model, id, readAt, fields? }`: did this specific row, or these
|
|
286
|
-
* specific fields, change?
|
|
287
|
-
* • Group — `{ group, readAt }`: did anything in this sync group change?
|
|
288
|
-
* `group` is a sync-group key such as `report:abc` or `section:s1`, the
|
|
289
|
-
* same unit a participant watches and claims.
|
|
290
|
-
*
|
|
291
|
-
* See `packages/sync-engine/docs/concurrency-convention.md` (§4) for the
|
|
292
|
-
* governing convention and the receive → reconcile loop.
|
|
293
|
-
*/
|
|
294
|
-
const readRowDependencySchema = z.object({
|
|
295
|
-
model: z.string(),
|
|
296
|
-
id: z.string(),
|
|
297
|
-
readAt: z.number(),
|
|
298
|
-
fields: z.array(z.string()).readonly().optional(),
|
|
299
|
-
onStale: onStaleModeSchema.optional(),
|
|
300
|
-
});
|
|
301
|
-
const readGroupDependencySchema = z.object({
|
|
302
|
-
group: z.string(),
|
|
303
|
-
readAt: z.number(),
|
|
304
|
-
onStale: onStaleModeSchema.optional(),
|
|
305
|
-
});
|
|
306
|
-
export const readDependencySchema = z.union([
|
|
307
|
-
readRowDependencySchema,
|
|
308
|
-
readGroupDependencySchema,
|
|
309
|
-
]);
|
|
310
|
-
/**
|
|
311
|
-
* A durable premise — what a participant is watching so that a later
|
|
312
|
-
* change to it opens a {@link StaleNotification}. Where a {@link ReadDependency}
|
|
313
|
-
* is checked once at commit and discarded, a `TrackDependency` is kept and
|
|
314
|
-
* re-checked against every future delta. The row form watches one object; the
|
|
315
|
-
* group form watches a whole sync group ("anything in `report:abc`"). See
|
|
316
|
-
* `packages/sync-engine/docs/groups.md` for how it drives change propagation.
|
|
317
|
-
*
|
|
318
|
-
* It is a PROJECTION of the ephemeral premise, not a second declaration of the
|
|
319
|
-
* same reference: a track names its target exactly as a read does, and the
|
|
320
|
-
* three ways it differs are stated here as omissions the compiler holds.
|
|
321
|
-
*
|
|
322
|
-
* • no `onStale` — a track always notifies; that is what tracking is;
|
|
323
|
-
* • no `fields` — a track fires at row grain, because the server keeps one
|
|
324
|
-
* row per tracked target and reports that the target moved, not which
|
|
325
|
-
* column did (`track_dependencies` has no field axis to store one in);
|
|
326
|
-
* • `readAt` optional — it defaults to the watermark of the commit that
|
|
327
|
-
* registered the track, so a caller with nothing to say about when it last
|
|
328
|
-
* looked gets "from here on".
|
|
329
|
-
*
|
|
330
|
-
* A field added to the premise reaches both halves; a field the durable half
|
|
331
|
-
* genuinely cannot carry has to be omitted here on purpose, in one line, rather
|
|
332
|
-
* than by being quietly left out of a copy.
|
|
333
|
-
*/
|
|
334
|
-
const trackReadAtSchema = { readAt: z.number().optional() };
|
|
335
|
-
export const trackDependencySchema = z.union([
|
|
336
|
-
readRowDependencySchema
|
|
337
|
-
.omit({ onStale: true, fields: true, readAt: true })
|
|
338
|
-
.extend(trackReadAtSchema),
|
|
339
|
-
readGroupDependencySchema
|
|
340
|
-
.omit({ onStale: true, readAt: true })
|
|
341
|
-
.extend(trackReadAtSchema),
|
|
342
|
-
]);
|
|
343
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
344
|
-
// Layer 2 — pessimistic claims and leases
|
|
345
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
346
|
-
/**
|
|
347
|
-
* The lifecycle of a claim. When absent on the wire it means `'active'` (an
|
|
348
|
-
* additive back-compat default). The server stamps `'active'` on `claim_begin`
|
|
349
|
-
* and emits one terminal frame — `committed`, `canceled`, or `expired` — as the
|
|
350
|
-
* claim ends, so contenders learn how it resolved, not merely that it vanished.
|
|
351
|
-
*/
|
|
352
|
-
export const wireClaimStatusSchema = z.enum([
|
|
353
|
-
'active',
|
|
354
|
-
'committed',
|
|
355
|
-
'expired',
|
|
356
|
-
'canceled',
|
|
357
|
-
]);
|
|
358
|
-
/**
|
|
359
|
-
* Every lifecycle state of a claim, as a caller sees it.
|
|
360
|
-
*
|
|
361
|
-
* `active` is the current holder — the lock itself. `queued` is waiting in line
|
|
362
|
-
* behind the holder and carries an advisory `position`. The rest are terminal
|
|
363
|
-
* and drop the claim from the synced set.
|
|
364
|
-
*
|
|
365
|
-
* Distinct from {@link wireClaimStatusSchema}, which never carries `queued`
|
|
366
|
-
* because the wire frame for a waiter is a different message. This is the one a
|
|
367
|
-
* published contract describes, so it is a schema rather than a bare TS union —
|
|
368
|
-
* a union cannot be derived into the API reference.
|
|
369
|
-
*/
|
|
370
|
-
export const publicClaimStatusSchema = z.enum([
|
|
371
|
-
'active',
|
|
372
|
-
'queued',
|
|
373
|
-
'committed',
|
|
374
|
-
'expired',
|
|
375
|
-
'canceled',
|
|
376
|
-
]);
|
|
377
|
-
/**
|
|
378
|
-
* @deprecated Renamed to {@link wireClaimStatusSchema} — this is the wire enum,
|
|
379
|
-
* which never carries `'queued'`; the five-state public status lives in
|
|
380
|
-
* types/streams. Removed in 0.36.0.
|
|
381
|
-
*/
|
|
382
|
-
export const claimStatusSchema = wireClaimStatusSchema;
|
|
383
|
-
/**
|
|
384
|
-
* Server-owned grant stamps — minted once when a claim is first granted and
|
|
385
|
-
* preserved verbatim across a re-announce of the same `claimId`, so neither a
|
|
386
|
-
* reconnect nor a client-supplied value can move them (unlike `declaredAt`,
|
|
387
|
-
* which the client sends afresh each announce). Both optional: a frame without
|
|
388
|
-
* them stays valid, and the feature each backs simply does not engage.
|
|
389
|
-
*/
|
|
390
|
-
const grantStampFields = {
|
|
391
|
-
/**
|
|
392
|
-
* The monotonic fencing token minted for this grant (Option B). Strictly
|
|
393
|
-
* increasing per entity across successive grants, so a write that carries it
|
|
394
|
-
* is rejected at commit if a later holder already advanced the entity's
|
|
395
|
-
* high-water. A token-less write is simply not fence-checked.
|
|
396
|
-
*/
|
|
397
|
-
fenceToken: z.number().optional(),
|
|
398
|
-
/**
|
|
399
|
-
* Lease origin (epoch ms): when THIS holding was acquired. The cumulative-
|
|
400
|
-
* hold ceiling measures a holder's fair share from here — and because it
|
|
401
|
-
* survives a re-announce, a reconnect cannot rewind the clock.
|
|
402
|
-
*/
|
|
403
|
-
acquiredAt: z.number().optional(),
|
|
404
|
-
};
|
|
405
|
-
/**
|
|
406
|
-
* A holder as the participant blocked behind them sees it: who has the row,
|
|
407
|
-
* what they said they are doing, and until when.
|
|
408
|
-
*
|
|
409
|
-
* This is the smaller half of a claim, so it is declared first and the full
|
|
410
|
-
* claim extends it — the waiter's view cannot omit a member the holder's view
|
|
411
|
-
* has, because there is nowhere for it to be omitted. Listing what to keep was
|
|
412
|
-
* the bug: this named `field` and not `path`, `range`, or `fields`, so a waiter
|
|
413
|
-
* could see that a row was held but never which part of it, and every locator
|
|
414
|
-
* member added later would have been missing here too.
|
|
415
|
-
*/
|
|
416
|
-
export const wireClaimSummarySchema = targetRefSchema.extend({
|
|
417
|
-
claimId: z.string(),
|
|
418
|
-
/**
|
|
419
|
-
* Peer-visible description of the work being done (`'rewriting the risk
|
|
420
|
-
* section to match Q3'`). The server stamps a default when a frame carries
|
|
421
|
-
* none.
|
|
422
|
-
*/
|
|
423
|
-
description: z.string().optional(),
|
|
424
|
-
/** Server-stamped declaration time (epoch ms). */
|
|
425
|
-
declaredAt: z.number(),
|
|
426
|
-
/** Server-computed TTL deadline (epoch ms). Readers treat as advisory. */
|
|
427
|
-
expiresAt: z.number(),
|
|
428
|
-
/**
|
|
429
|
-
* On whose authority the holder acts, and under which grant — stamped by the
|
|
430
|
-
* server off the connection's credential, never accepted from the frame. The
|
|
431
|
-
* same three fields the delta this claim produces will record, so "who is
|
|
432
|
-
* doing this" and "who did this" answer in one vocabulary.
|
|
433
|
-
*
|
|
434
|
-
* On the summary rather than the full claim because this is precisely what a
|
|
435
|
-
* blocked waiter needs: yielding to a colleague and queuing behind another
|
|
436
|
-
* customer's agent are different decisions.
|
|
437
|
-
*
|
|
438
|
-
* All three optional and additive — an older server omits them, which is a
|
|
439
|
-
* different fact from a holder that has no delegator.
|
|
440
|
-
*/
|
|
441
|
-
onBehalfOfId: z.string().nullish(),
|
|
442
|
-
onBehalfOfKind: wireParticipantKindSchema.nullish(),
|
|
443
|
-
capabilityId: z.string().nullish(),
|
|
444
|
-
});
|
|
445
|
-
/**
|
|
446
|
-
* The full claim as its holder's own frames carry it — the waiter's view plus
|
|
447
|
-
* the lifecycle and grant stamps that belong to the holding itself.
|
|
448
|
-
*/
|
|
449
|
-
const wireClaimBaseSchema = wireClaimSummarySchema.extend({
|
|
450
|
-
status: wireClaimStatusSchema.optional(),
|
|
451
|
-
...grantStampFields,
|
|
452
|
-
});
|
|
453
|
-
/** Why a claim ended in a non-success terminal state. */
|
|
454
|
-
export const claimErrorSchema = z.object({
|
|
455
|
-
code: z.string(),
|
|
456
|
-
message: z.string().optional(),
|
|
457
|
-
/** Participant already holding the target (conflict rejections). */
|
|
458
|
-
heldBy: z.string().optional(),
|
|
459
|
-
heldByClaimId: z.string().optional(),
|
|
460
|
-
heldByExpiresAt: z.number().optional(),
|
|
461
|
-
/** Rich holder context for conflict rejections. Additive: older frames omit it. */
|
|
462
|
-
heldByClaim: wireClaimSummarySchema.optional(),
|
|
463
|
-
/** Optional conflict-policy explanation. Additive: older frames omit it. */
|
|
464
|
-
policyReason: z.string().optional(),
|
|
465
|
-
});
|
|
466
|
-
/**
|
|
467
|
-
* Why a claim ended without its holder releasing it, or was refused.
|
|
468
|
-
*
|
|
469
|
-
* A closed set, because the two refusals are different guarantees and a reader
|
|
470
|
-
* has to be able to tell them apart: `conflict` means someone holds the row
|
|
471
|
-
* right now and you may queue behind them, while `coordination_unavailable`
|
|
472
|
-
* means the coordinator could not answer, so nothing is known about the row.
|
|
473
|
-
* `expired` and `preempted` are the two ways a lease you held ends.
|
|
474
|
-
*
|
|
475
|
-
* The rejection frame's `reason` stays a plain string on the wire — it is
|
|
476
|
-
* frozen, and an older server may send a word not listed here. This is the
|
|
477
|
-
* reader's side of it: a value that parses becomes the typed reason, and one
|
|
478
|
-
* that does not is simply absent rather than smuggled through as prose.
|
|
479
|
-
* {@link claimExpiredSchema} and {@link claimLostSchema} already spelled their
|
|
480
|
-
* reasons as enums; this brings the refusals into line.
|
|
481
|
-
*/
|
|
482
|
-
export const claimEventReasonSchema = z.enum([
|
|
483
|
-
'conflict',
|
|
484
|
-
'coordination_unavailable',
|
|
485
|
-
'expired',
|
|
486
|
-
'preempted',
|
|
487
|
-
]);
|
|
488
|
-
/**
|
|
489
|
-
* A declared, pending-mutation claim — the unit broadcast inside a presence
|
|
490
|
-
* frame's `activeClaims`. The client supplies the descriptive `targetRef`
|
|
491
|
-
* fields, a `description` of the work, and a chosen `claimId`; the server stamps
|
|
492
|
-
* `declaredAt` and `expiresAt` and may set `status` and `error`. Those last
|
|
493
|
-
* two are optional, so one shape serves both the server, which sets them, and
|
|
494
|
-
* the leaner SDK view, which reads a claim without them.
|
|
495
|
-
*/
|
|
496
|
-
export const wireClaimSchema = wireClaimBaseSchema.extend({
|
|
497
|
-
error: claimErrorSchema.optional(),
|
|
498
|
-
});
|
|
499
|
-
export const claimRejectionSchema = z.object({
|
|
500
|
-
claimId: z.string(),
|
|
501
|
-
/**
|
|
502
|
-
* Why the claim was refused, as one of {@link claimEventReasonSchema}'s
|
|
503
|
-
* words — so a caller can branch on it. `conflict` means someone holds the
|
|
504
|
-
* row right now and you may queue behind them; `coordination_unavailable`
|
|
505
|
-
* means the coordinator could not answer, so nothing is known about it.
|
|
506
|
-
* Those are different decisions, and a free string made them one.
|
|
507
|
-
*
|
|
508
|
-
* The wire spelling is frozen and an older server may send a word not listed
|
|
509
|
-
* there, so this reads the way {@link wireParticipantKindSchema} reads its
|
|
510
|
-
* dialect: a value that parses becomes the typed reason, and one that does
|
|
511
|
-
* not is absent rather than smuggled through as prose. Prose has its own
|
|
512
|
-
* field — `policyReason` below — which is why nothing is lost by refusing to
|
|
513
|
-
* carry it here.
|
|
514
|
-
*
|
|
515
|
-
* The registry code a caller finally sees on `AbloClaimedError`
|
|
516
|
-
* (`claim_conflict`) stays a separate vocabulary, mapped at the throw. Two
|
|
517
|
-
* small vocabularies with one mapping point beat one vocabulary and a
|
|
518
|
-
* projection of it that has to be maintained as the registry grows.
|
|
519
|
-
*/
|
|
520
|
-
reason: z.preprocess((value) => (claimEventReasonSchema.safeParse(value).success ? value : undefined), claimEventReasonSchema.optional()),
|
|
521
|
-
target: targetRefSchema.optional(),
|
|
522
|
-
heldBy: z.string().optional(),
|
|
523
|
-
/**
|
|
524
|
-
* Whether the holder blocking this claim is a person, an agent, or the
|
|
525
|
-
* system. The server already derives this from the holder's id when it
|
|
526
|
-
* builds the conflict; carrying it means a caller can decide how to respond
|
|
527
|
-
* — yield to a person, queue behind an agent — without parsing an opaque id
|
|
528
|
-
* for a prefix and guessing. Additive: an older server omits it.
|
|
529
|
-
*/
|
|
530
|
-
heldByKind: wireParticipantKindSchema.optional(),
|
|
531
|
-
heldByClaimId: z.string().optional(),
|
|
532
|
-
heldByExpiresAt: z.number().optional(),
|
|
533
|
-
heldByClaim: wireClaimSummarySchema.optional(),
|
|
534
|
-
policyReason: z.string().optional(),
|
|
535
|
-
});
|
|
536
|
-
/**
|
|
537
|
-
* The point-to-point notification sent to a holder whose lease ended without
|
|
538
|
-
* a successful commit. This remains a wire-shaped target because it arrives
|
|
539
|
-
* directly from the WebSocket; the schema is the single validation boundary
|
|
540
|
-
* before the event reaches public `claims.onLost` listeners.
|
|
541
|
-
*/
|
|
542
|
-
export const claimLostSchema = z.object({
|
|
543
|
-
claimId: z.string(),
|
|
544
|
-
reason: z.enum(['expired', 'preempted']),
|
|
545
|
-
target: targetRefSchema,
|
|
546
|
-
});
|
|
547
|
-
/**
|
|
548
|
-
* The lease is ours without waiting — the target was free when the claim
|
|
549
|
-
* arrived. `fenceToken` is present whenever the coordinator minted one, and a
|
|
550
|
-
* write carries it back so a lapsed lease cannot apply late.
|
|
551
|
-
*/
|
|
552
|
-
export const claimAcquiredSchema = z.object({
|
|
553
|
-
claimId: z.string(),
|
|
554
|
-
fenceToken: z.number().optional(),
|
|
555
|
-
target: targetRefSchema,
|
|
556
|
-
});
|
|
557
|
-
/**
|
|
558
|
-
* A queued claim reached the head of the line and the lease is now ours. The
|
|
559
|
-
* shape matches {@link claimAcquiredSchema} exactly — the two frames differ
|
|
560
|
-
* only in whether the caller waited — but they stay separate declarations
|
|
561
|
-
* because they are separate wire contracts, and collapsing them would let a
|
|
562
|
-
* change to one silently redefine the other.
|
|
563
|
-
*/
|
|
564
|
-
export const claimGrantedSchema = z.object({
|
|
565
|
-
claimId: z.string(),
|
|
566
|
-
fenceToken: z.number().optional(),
|
|
567
|
-
target: targetRefSchema,
|
|
568
|
-
});
|
|
569
|
-
/**
|
|
570
|
-
* Our claim is waiting in line behind a live holder — the same conflict
|
|
571
|
-
* {@link claimRejectionSchema} reports, delivered as a wait rather than a
|
|
572
|
-
* refusal, plus the caller's `position`.
|
|
573
|
-
*
|
|
574
|
-
* `reason` is the one member that does not carry over as required. A refusal
|
|
575
|
-
* states why it refused; a wait has only ever named the conflict through
|
|
576
|
-
* `heldBy`/`heldByClaim`, and no server has ever stamped `reason` on this
|
|
577
|
-
* frame. Requiring it here — inherited silently by extending the rejection
|
|
578
|
-
* schema — made the parse boundary reject every genuine `claim_queued` as
|
|
579
|
-
* malformed the moment frame validation went in. Optional is what the wire
|
|
580
|
-
* actually is, and it stays derived from the rejection field so the two cannot
|
|
581
|
-
* describe the value differently.
|
|
582
|
-
*
|
|
583
|
-
* `position` is advisory: a privileged reorder can move it up, so a caller
|
|
584
|
-
* that asserts monotonic position will fail in production. Only the arrival of
|
|
585
|
-
* a grant is authoritative.
|
|
586
|
-
*/
|
|
587
|
-
export const claimQueuedSchema = claimRejectionSchema.extend({
|
|
588
|
-
position: z.number(),
|
|
589
|
-
reason: claimRejectionSchema.shape.reason.optional(),
|
|
590
|
-
});
|
|
591
|
-
/**
|
|
592
|
-
* One entry in a wait-line snapshot.
|
|
593
|
-
*
|
|
594
|
-
* NOTE — this is the third spelling of a target locator on the wire: here it is
|
|
595
|
-
* `{ type, id }`, the HTTP claim DTO uses `{ model, id }`
|
|
596
|
-
* ({@link modelTargetSchema}), and the claim frames use
|
|
597
|
-
* `{ entityType, entityId }` ({@link targetRefSchema}). The schema describes
|
|
598
|
-
* what the server sends today rather than what it should send; unifying the
|
|
599
|
-
* three is a coordinated protocol change scheduled behind the protocol version.
|
|
600
|
-
* Until it happens, the translation between the spellings lives in one place —
|
|
601
|
-
* `wireTarget`, `modelTarget` and `streamTarget` in ./locator.ts — so no hop
|
|
602
|
-
* gets to invent a fourth.
|
|
603
|
-
*/
|
|
604
|
-
export const claimQueueEntrySchema = z.object({
|
|
605
|
-
object: z.literal('claim'),
|
|
606
|
-
id: z.string(),
|
|
607
|
-
status: z.literal('queued'),
|
|
608
|
-
target: streamTargetSchema,
|
|
609
|
-
/**
|
|
610
|
-
* Peer-visible description of the work. A claim may be declared without one,
|
|
611
|
-
* and the public `Claim` promises the field is always there — so the default
|
|
612
|
-
* lives here, applied as the frame is decoded, rather than being restated by
|
|
613
|
-
* each reader.
|
|
614
|
-
*/
|
|
615
|
-
description: z.string().default('editing'),
|
|
616
|
-
heldBy: z.string().optional(),
|
|
617
|
-
participantKind: wireParticipantKindSchema.optional(),
|
|
618
|
-
position: z.number(),
|
|
619
|
-
expiresAt: z.number(),
|
|
620
|
-
});
|
|
621
|
-
/**
|
|
622
|
-
* The whole wait line for one row, rebroadcast to that row's peers on every
|
|
623
|
-
* queue mutation. This is what backs the reactive
|
|
624
|
-
* `ablo.<model>.claim.queue({ id })` read, which is why it carries the full
|
|
625
|
-
* line rather than a delta against it.
|
|
626
|
-
*/
|
|
627
|
-
export const claimQueueSchema = z.object({
|
|
628
|
-
target: streamTargetSchema.pick({ type: true, id: true }),
|
|
629
|
-
queue: z.array(claimQueueEntrySchema),
|
|
630
|
-
});
|
|
631
|
-
/**
|
|
632
|
-
* A held claim's TTL lapsed server-side. The claim is already inactive by the
|
|
633
|
-
* time this arrives, so a consumer either re-claims with a fresh credential or
|
|
634
|
-
* accepts the drop; there is nothing to release.
|
|
635
|
-
*/
|
|
636
|
-
export const claimExpiredSchema = z.object({
|
|
637
|
-
claimId: z.string(),
|
|
638
|
-
});
|
|
639
|
-
/**
|
|
640
|
-
* What a {@link ModelClaim} points at — the target locator as SDK callers see
|
|
641
|
-
* it, keyed by `model` and `id` rather than the wire schema's `entityType` and
|
|
642
|
-
* `entityId`. This is the public `ModelTarget` shape.
|
|
643
|
-
*/
|
|
644
|
-
export const modelTargetSchema = z
|
|
645
|
-
.object({
|
|
646
|
-
model: z.string(),
|
|
647
|
-
id: z.string(),
|
|
648
|
-
path: z.string().optional(),
|
|
649
|
-
range: targetRangeSchema.optional(),
|
|
650
|
-
field: z.string().optional(),
|
|
651
|
-
/** Several named parts at once — see {@link targetRefSchema}. */
|
|
652
|
-
fields: z.array(z.string()).readonly().optional(),
|
|
653
|
-
meta: z.record(z.string(), z.unknown()).optional(),
|
|
654
|
-
})
|
|
655
|
-
.readonly();
|
|
656
|
-
/**
|
|
657
|
-
* The two states a claim can be observed in while it still exists.
|
|
658
|
-
*
|
|
659
|
-
* Derived from {@link publicClaimStatusSchema} rather than spelled again: the
|
|
660
|
-
* other three are terminal and drop the claim from the observable set, so a
|
|
661
|
-
* listing or a peer's view can only ever see these. Extracting them by name
|
|
662
|
-
* means a state added to the public vocabulary is a deliberate decision about
|
|
663
|
-
* whether it is observable, not a silent omission.
|
|
664
|
-
*/
|
|
665
|
-
export const heldClaimStatusSchema = publicClaimStatusSchema.extract([
|
|
666
|
-
'active',
|
|
667
|
-
'queued',
|
|
668
|
-
]);
|
|
669
|
-
/**
|
|
670
|
-
* ONE CLAIM — everything true about a lease at a moment: what it points at, who
|
|
671
|
-
* holds it, what they said they are doing, where it stands, and until when.
|
|
672
|
-
*
|
|
673
|
-
* Every caller-facing surface that answers a question about a claim is a
|
|
674
|
-
* PROJECTION of this record, never a second object: {@link modelClaimSchema} is
|
|
675
|
-
* what a peer may see, and `claimStateSchema` (`wire/claims.ts`) is what a
|
|
676
|
-
* caller polls about a claim of its own. Each is pinned to this record, so a
|
|
677
|
-
* field added here either reaches the people it was declared for or fails to
|
|
678
|
-
* compile.
|
|
679
|
-
*
|
|
680
|
-
* Before this, the peer-visible shape was a standalone `z.object` deriving from
|
|
681
|
-
* nothing, and the polling shape was a third. That is why it took reading four
|
|
682
|
-
* files to answer whether a heartbeat's progress reaches an asker — the
|
|
683
|
-
* declaring surface and the observing surface were kept in step by hand, and
|
|
684
|
-
* three of their shared fields had already drifted on how strictly they parse.
|
|
685
|
-
*
|
|
686
|
-
* What this record deliberately does NOT unify is the socket family
|
|
687
|
-
* ({@link wireClaimSchema} and its base). Those carry the same claim under the
|
|
688
|
-
* `entityType`/`entityId` locator rather than `model`/`id`, and they already
|
|
689
|
-
* derive from one another; collapsing the two locator spellings is a wire
|
|
690
|
-
* rename, not a projection.
|
|
691
|
-
*/
|
|
692
|
-
export const claimRecordSchema = z.object({
|
|
693
|
-
/** The claim's identity. Spelled `claimId` where a message names a claim it
|
|
694
|
-
* is not itself, and `id` where the claim is the resource. */
|
|
695
|
-
id: z.string(),
|
|
696
|
-
/** Who holds it. */
|
|
697
|
-
actor: z.string(),
|
|
698
|
-
/** Parsed through {@link wireParticipantKindSchema}, so a legacy `'human'`
|
|
699
|
-
* frame normalizes to `'user'`. */
|
|
700
|
-
participantKind: wireParticipantKindSchema,
|
|
701
|
-
/**
|
|
702
|
-
* On whose authority the holder acts — the same three fields, with the same
|
|
703
|
-
* meanings, that `deltaAttributionSchema` records on every delta the claim
|
|
704
|
-
* goes on to produce, and sourced the same way: off the credential the
|
|
705
|
-
* connection authenticated with, never from the caller.
|
|
706
|
-
*
|
|
707
|
-
* A claim that carries only `actor` can say who is doing something and not
|
|
708
|
-
* who asked for it. "What is agent a7f3 doing" is a debugging question;
|
|
709
|
-
* "what is running on behalf of this customer right now" is an operations
|
|
710
|
-
* question, and until these are here it is answerable only in hindsight,
|
|
711
|
-
* against the audit log, after the fact.
|
|
712
|
-
*
|
|
713
|
-
* Null rather than absent when there is genuinely no delegator or no grant —
|
|
714
|
-
* a person acting directly is their own principal, and a session holds no
|
|
715
|
-
* capability.
|
|
716
|
-
*/
|
|
717
|
-
onBehalfOfId: z.string().nullable(),
|
|
718
|
-
onBehalfOfKind: wireParticipantKindSchema.nullable(),
|
|
719
|
-
capabilityId: z.string().nullable(),
|
|
720
|
-
/**
|
|
721
|
-
* What the holder said they are doing (`'rewriting the risk section'`).
|
|
722
|
-
*
|
|
723
|
-
* A caller may declare it as `description`, as the older `reason`, or inside
|
|
724
|
-
* `meta`; {@link claimDescription} resolves those to this one field with a
|
|
725
|
-
* declared precedence, so only one of them is ever a shape.
|
|
726
|
-
*/
|
|
727
|
-
description: z.string(),
|
|
728
|
-
/** Holding the row, or waiting in line for it. */
|
|
729
|
-
status: heldClaimStatusSchema,
|
|
730
|
-
/**
|
|
731
|
-
* Place in the wait line. Advisory: a privileged caller can reorder the
|
|
732
|
-
* queue, so a position can go UP between reads — only `status` is
|
|
733
|
-
* authoritative.
|
|
734
|
-
*/
|
|
735
|
-
position: z.number().int().nonnegative(),
|
|
736
|
-
/**
|
|
737
|
-
* When the lease lapses without a heartbeat, in epoch milliseconds — the same
|
|
738
|
-
* encoding as the WebSocket {@link WireClaim}, so one timestamp
|
|
739
|
-
* representation spans the wire, the SDK, HTTP, and errors. There is no ISO
|
|
740
|
-
* string anywhere.
|
|
741
|
-
*/
|
|
742
|
-
expiresAt: z.number().int(),
|
|
743
|
-
/** The grant's fencing token, minted at acquisition. Present on a claim that
|
|
744
|
-
* is held, never on one that is queued. */
|
|
745
|
-
fenceToken: z.number().int(),
|
|
746
|
-
/** The row, and which part of it. */
|
|
747
|
-
target: modelTargetSchema,
|
|
748
|
-
/**
|
|
749
|
-
* The claim's metadata as an OPEN record — including what the coordinator
|
|
750
|
-
* writes there rather than the holder. A heartbeat's `details` lands here as
|
|
751
|
-
* `progress` (last beat wins), so an asker reads
|
|
752
|
-
* `claim.state({ id })?.meta.progress`. It is presence, not a checkpoint: it
|
|
753
|
-
* dies with the lease.
|
|
754
|
-
*
|
|
755
|
-
* This is the same bag the wire carries; what is new is that it has a home at
|
|
756
|
-
* the CLAIM level. Both projections used to file it under `target` alone, and
|
|
757
|
-
* `target.meta` is typed as the shape the program registered for its own claim
|
|
758
|
-
* metadata — so a server-written key was unreadable there by construction:
|
|
759
|
-
* `target.meta.progress` does not typecheck for any program that declared a
|
|
760
|
-
* shape, and the value was arriving in a slot whose type forbids it.
|
|
761
|
-
*
|
|
762
|
-
* Two views of one field, each typed for its reader: `target.meta` stays the
|
|
763
|
-
* holder's declared shape, and this stays open, because a peer reading someone
|
|
764
|
-
* else's claim has no grounds to assume the writer's declaration.
|
|
765
|
-
*/
|
|
766
|
-
meta: z.record(z.string(), z.unknown()).optional(),
|
|
767
|
-
});
|
|
768
|
-
/**
|
|
769
|
-
* A claim as SDK callers and the HTTP claim routes see it
|
|
770
|
-
* (`ablo.<model>.claim.state`, `GET /v1/claims`) — the resolved, peer-readable
|
|
771
|
-
* view of one active or queued claim. The client's `ModelClaim` type derives
|
|
772
|
-
* from this shape.
|
|
773
|
-
*
|
|
774
|
-
* Everything but the deprecated `field` is projected from
|
|
775
|
-
* {@link claimRecordSchema}. Four members are optional here and required on the
|
|
776
|
-
* record, and the split is the same in each case: the record says what a claim
|
|
777
|
-
* IS, while a peer's view of one may legitimately have been built without them
|
|
778
|
-
* — a queued claim has no `fenceToken`, a held one has no `position`, an older
|
|
779
|
-
* producer sends no `status`, and a claim may be declared with no description.
|
|
780
|
-
*/
|
|
781
|
-
export const modelClaimSchema = claimRecordSchema
|
|
782
|
-
.partial({
|
|
783
|
-
description: true,
|
|
784
|
-
status: true,
|
|
785
|
-
position: true,
|
|
786
|
-
fenceToken: true,
|
|
787
|
-
// Additive: a server that predates the delegation trio omits all three,
|
|
788
|
-
// which is a different fact from a claim that has no delegator (null).
|
|
789
|
-
onBehalfOfId: true,
|
|
790
|
-
onBehalfOfKind: true,
|
|
791
|
-
capabilityId: true,
|
|
792
|
-
})
|
|
793
|
-
.extend({
|
|
794
|
-
/**
|
|
795
|
-
* @deprecated Read `target.field` instead, and `target.fields` for a claim
|
|
796
|
-
* on several parts of the row. Removed in 0.36.0.
|
|
797
|
-
*
|
|
798
|
-
* This says the same thing as `target.field` and nothing keeps the two
|
|
799
|
-
* agreeing, so a producer that sets one and not the other publishes a
|
|
800
|
-
* claim that contradicts itself. It also cannot express a field set at
|
|
801
|
-
* all, which is the reason `target.fields` exists.
|
|
802
|
-
*/
|
|
803
|
-
field: z.string().optional(),
|
|
804
|
-
})
|
|
805
|
-
.readonly();
|
|
806
|
-
/**
|
|
807
|
-
* The peer-visible view covers the record. A field added to a claim is either
|
|
808
|
-
* projected to the people it was declared for, or deliberately dropped by an
|
|
809
|
-
* `.omit` here — never missing because nobody remembered the second object.
|
|
810
|
-
*/
|
|
811
|
-
const _modelClaimCoversRecord = true;
|
|
812
|
-
void _modelClaimCoversRecord;
|
|
813
|
-
/**
|
|
814
|
-
* The `claim_begin` payload a client sends. It carries the descriptive target
|
|
815
|
-
* and a `description` of the work, an optional duration hint, and the opt-in
|
|
816
|
-
* fair-queue flag. The server stamps the lifecycle and timestamp fields, so they
|
|
817
|
-
* are not part of this inbound shape — this is exactly what the server validates
|
|
818
|
-
* on ingest.
|
|
819
|
-
*/
|
|
820
|
-
export const claimBeginPayloadSchema = targetRefSchema.extend({
|
|
821
|
-
claimId: z.string(),
|
|
822
|
-
/** Peer-visible description of the work. The server stamps `'editing'` when a
|
|
823
|
-
* frame carries none. */
|
|
824
|
-
description: z.string().optional(),
|
|
825
|
-
/** Hint for `expiresAt`; the server caps it. */
|
|
826
|
-
estimatedMs: z.number().optional(),
|
|
827
|
-
/**
|
|
828
|
-
* Opt into the fair wait queue. When the target is already held, the server
|
|
829
|
-
* enqueues this claim in FIFO order and replies `claim_queued`, then
|
|
830
|
-
* `claim_granted` later, instead of `claim_rejected`. A client that sets this
|
|
831
|
-
* must be ready to handle the grant.
|
|
832
|
-
*/
|
|
833
|
-
queue: z.boolean().optional(),
|
|
834
|
-
});
|
|
835
|
-
/**
|
|
836
|
-
* The `claim_abandon` payload a client sends. `entityType` and `entityId` let
|
|
837
|
-
* the server dequeue a claim that is still waiting (not yet held) from the FIFO
|
|
838
|
-
* line; abandoning a claim that is already held needs only `claimId`.
|
|
839
|
-
*/
|
|
840
|
-
export const claimAbandonPayloadSchema = z.object({
|
|
841
|
-
claimId: z.string(),
|
|
842
|
-
entityType: z.string().optional(),
|
|
843
|
-
entityId: z.string().optional(),
|
|
844
|
-
});
|
|
845
|
-
/**
|
|
846
|
-
* The `claim_reorder` payload a client sends. A privileged participant, such as
|
|
847
|
-
* a supervisor over its sub-agents, re-ranks the FIFO wait queue for an entity:
|
|
848
|
-
* `order` lists waiters by `heldBy` and `claimId` in the desired priority, and
|
|
849
|
-
* any waiter not listed keeps its relative order behind those that are. The
|
|
850
|
-
* server gates who may call this and drops an unauthorized sender. Where
|
|
851
|
-
* `claim_abandon` acts on the caller's own entry, a reorder acts on other
|
|
852
|
-
* participants' queue positions — which is why it is gated.
|
|
853
|
-
*/
|
|
854
|
-
export const claimReorderPayloadSchema = z.object({
|
|
855
|
-
entityType: z.string(),
|
|
856
|
-
entityId: z.string(),
|
|
857
|
-
order: z.array(z.object({ heldBy: z.string(), claimId: z.string() })),
|
|
858
|
-
});
|
|
859
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
860
|
-
// Heartbeat — the async / long-running-work surface of a claim.
|
|
861
|
-
//
|
|
862
|
-
// A claim's TTL is crash cleanup, not a work-duration estimate. Work that
|
|
863
|
-
// outlives it — an agent run, a background worker's job — keeps its lease by
|
|
864
|
-
// BEATING: request `claim_heartbeat`, reply `claim_heartbeat_ack`. One field
|
|
865
|
-
// set serves every shape; the single and batched payloads are both derived
|
|
866
|
-
// from it, and the WebSocket frame and HTTP routes are two encodings of the
|
|
867
|
-
// same messages. Everything long-running-work-related on the wire lives in
|
|
868
|
-
// this block.
|
|
869
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
870
|
-
/**
|
|
871
|
-
* The one field set behind every heartbeat message. The single-claim payload
|
|
872
|
-
* refines it; the batched payload picks from it — there is deliberately no
|
|
873
|
-
* second shape to keep in sync.
|
|
874
|
-
*/
|
|
875
|
-
const claimHeartbeatFieldsSchema = z.object({
|
|
876
|
-
claimId: z.string().optional(),
|
|
877
|
-
entityType: z.string().optional(),
|
|
878
|
-
entityId: z.string().optional(),
|
|
879
|
-
/** Requested extension from now; the server clamps it, and an extension
|
|
880
|
-
* never shortens a lease. */
|
|
881
|
-
ttlMs: z.number().positive().optional(),
|
|
882
|
-
/**
|
|
883
|
-
* Lightweight progress the beat carries along ("42/100 pages") — stored
|
|
884
|
-
* as the claim's `meta.progress` (last beat wins) and peer-visible via
|
|
885
|
-
* `claim.state` while the lease is held. This is presence, not a
|
|
886
|
-
* checkpoint: it dies with the lease. Crash-recoverable progress belongs
|
|
887
|
-
* in the data itself — write a row, and every subscriber already sees it.
|
|
888
|
-
*/
|
|
889
|
-
details: z.record(z.string(), z.unknown()).optional(),
|
|
890
|
-
});
|
|
891
|
-
/**
|
|
892
|
-
* The `claim_heartbeat` payload a client sends to extend a lease it holds (or
|
|
893
|
-
* refresh its slot in the wait queue) past the liveness window — the
|
|
894
|
-
* work-duration signal for long-running holders, distinct from the connection
|
|
895
|
-
* keepalive.
|
|
896
|
-
*
|
|
897
|
-
* The claim is identified either way: by `claimId`, or — since a claim is
|
|
898
|
-
* singular per (actor, entity) — by the full `entityType`/`entityId` target
|
|
899
|
-
* ("my claim on this row"). At least one of the two must be present. The
|
|
900
|
-
* target also lets the server resolve without a scan and is required to
|
|
901
|
-
* refresh a *queued* claim (a waiter is not in the holder set the server
|
|
902
|
-
* would otherwise search).
|
|
903
|
-
*/
|
|
904
|
-
export const claimHeartbeatPayloadSchema = claimHeartbeatFieldsSchema.refine((payload) => payload.claimId !== undefined ||
|
|
905
|
-
(payload.entityType !== undefined && payload.entityId !== undefined), {
|
|
906
|
-
message: 'a heartbeat must identify its claim — pass claimId, or entityType and entityId together',
|
|
907
|
-
});
|
|
908
|
-
/**
|
|
909
|
-
* The server's reply to a `claim_heartbeat`. For a socketless worker the
|
|
910
|
-
* heartbeat reply is the only inbound signal path, so it carries the lease's
|
|
911
|
-
* fate rather than a bare ok: `held` (extended to `expiresAt`), `queued`
|
|
912
|
-
* (slot refreshed; `position` is the current place in line), or `lost` (the
|
|
913
|
-
* lease expired and the queue moved on — the worker should abandon or
|
|
914
|
-
* re-queue, and any write it still attempts is caught by its `readAt` guard).
|
|
915
|
-
*/
|
|
916
|
-
export const claimHeartbeatAckPayloadSchema = z.object({
|
|
917
|
-
claimId: z.string(),
|
|
918
|
-
status: z.enum(['held', 'queued', 'lost']),
|
|
919
|
-
expiresAt: z.number().optional(),
|
|
920
|
-
position: z.number().optional(),
|
|
921
|
-
/**
|
|
922
|
-
* How many participants are waiting in line behind a held lease — the
|
|
923
|
-
* cooperative-yield pressure signal (present on `held`). A worker that can
|
|
924
|
-
* checkpoint may choose to release early when others wait. Hard
|
|
925
|
-
* cancellation needs no extra field: a preempted, expired, or revoked
|
|
926
|
-
* lease answers the next beat with `lost`.
|
|
927
|
-
*/
|
|
928
|
-
queueDepth: z.number().optional(),
|
|
929
|
-
});
|
|
930
|
-
/**
|
|
931
|
-
* The batched heartbeat — one request extends every lease the caller holds
|
|
932
|
-
* on its plane (the socketless twin of the WebSocket keepalive, which renews
|
|
933
|
-
* all held leases on every ping). For a worker holding many rows this is one
|
|
934
|
-
* round trip per cadence instead of one per claim. Queued slots are not
|
|
935
|
-
* batch-refreshed: a waiter knows its target and beats it directly.
|
|
936
|
-
*/
|
|
937
|
-
export const claimHeartbeatBatchPayloadSchema = claimHeartbeatFieldsSchema.pick({ ttlMs: true });
|
|
938
|
-
/** Reply to a batched heartbeat: one ack entry per lease that was extended. */
|
|
939
|
-
export const claimHeartbeatBatchAckPayloadSchema = z.object({
|
|
940
|
-
results: z.array(claimHeartbeatAckPayloadSchema),
|
|
941
|
-
});
|
|
942
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
943
|
-
// Read interest — what a connection receives
|
|
944
|
-
//
|
|
945
|
-
// Two frames set it, and they differ in exactly one way: whether the
|
|
946
|
-
// interest is leased.
|
|
947
|
-
//
|
|
948
|
-
// • `claim` — a PARTICIPANT claim. Adds a scope under a handle, with a
|
|
949
|
-
// TTL and an optional capability token, and announces the sender into
|
|
950
|
-
// that scope's roster. This is the frame `ablo.<model>.join(...)` sends;
|
|
951
|
-
// `release` drops it. Several may be open on one connection at once.
|
|
952
|
-
// • `update_subscription` — REPLACES the connection's whole read set. No
|
|
953
|
-
// handle, no lease, no roster entry.
|
|
954
|
-
//
|
|
955
|
-
// Both are bounded by the connection credential's grant, and both name their
|
|
956
|
-
// groups the same way, so both parse their `syncGroups` through the same
|
|
957
|
-
// element schema. Neither is the row lease — that is `claim_begin`, in the
|
|
958
|
-
// pessimistic-claims block above, which shares only a word.
|
|
959
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
960
|
-
/**
|
|
961
|
-
* How many scopes one frame may name. A coarse abuse ceiling, not a business
|
|
962
|
-
* limit: a connection legitimately watches a handful of entities, and a list
|
|
963
|
-
* this long is an amplification attempt rather than a workload. Declared here,
|
|
964
|
-
* beside the two frames it bounds, so neither can be given a different answer.
|
|
965
|
-
*/
|
|
966
|
-
export const MAX_FRAME_SYNC_GROUPS = 200;
|
|
967
|
-
/**
|
|
968
|
-
* The sync groups a scope-subscription frame names. Each entry is a
|
|
969
|
-
* {@link syncGroupInputSchema} (`'default'` or a branded `kind:id`), so a
|
|
970
|
-
* malformed group is rejected on ingest rather than silently indexed — a group
|
|
971
|
-
* that does not parse matches nothing, and subscribing to nothing quietly is
|
|
972
|
-
* the failure this element type exists to prevent.
|
|
973
|
-
*
|
|
974
|
-
* Strict because this is untrusted client input, and shared because the two
|
|
975
|
-
* frames below carry the same value: when they disagreed, `claim` accepted a
|
|
976
|
-
* malformed group that `update_subscription` refused, and the connection
|
|
977
|
-
* ended up leased to a scope it could never receive.
|
|
978
|
-
*/
|
|
979
|
-
const frameSyncGroupsSchema = z
|
|
980
|
-
.array(syncGroupInputSchema)
|
|
981
|
-
.max(MAX_FRAME_SYNC_GROUPS);
|
|
982
|
-
/**
|
|
983
|
-
* The `claim` payload a client sends — the frame behind `join`.
|
|
984
|
-
*
|
|
985
|
-
* It opens one participant claim: the connection is added to each named
|
|
986
|
-
* scope's fan-out under `claimId`, announced into its presence roster, and
|
|
987
|
-
* holds that interest until `release`, the TTL lapses, or the socket closes.
|
|
988
|
-
* The handle is client-chosen because the client must be able to `release`
|
|
989
|
-
* the exact claim it opened while others stay open.
|
|
990
|
-
*
|
|
991
|
-
* This shape was, for a long time, written three times — built as a literal in
|
|
992
|
-
* the transport, restated as an interface on the server, and read back through
|
|
993
|
-
* a cast in the frame handler — which is how the frame came to be the only
|
|
994
|
-
* coordination message with no runtime check on the way in.
|
|
995
|
-
*/
|
|
996
|
-
export const participantClaimPayloadSchema = z.object({
|
|
997
|
-
/** Client-chosen handle. Echoed on `claim_ack`; names the claim to `release`. */
|
|
998
|
-
claimId: z.string().min(1),
|
|
999
|
-
syncGroups: frameSyncGroupsSchema,
|
|
1000
|
-
/**
|
|
1001
|
-
* A narrower capability to present for this claim than the connection's own.
|
|
1002
|
-
* Absent means the connection's credential governs it.
|
|
1003
|
-
*/
|
|
1004
|
-
capabilityToken: z.string().optional(),
|
|
1005
|
-
/**
|
|
1006
|
-
* Crash cleanup, in seconds. The server caps it at the capability's own TTL;
|
|
1007
|
-
* absent means the claim lives until `release` or disconnect.
|
|
1008
|
-
*/
|
|
1009
|
-
ttlSeconds: z.number().optional(),
|
|
1010
|
-
});
|
|
1011
|
-
/**
|
|
1012
|
-
* The `release` payload — drop one participant claim by its handle.
|
|
1013
|
-
*
|
|
1014
|
-
* A projection of the claim it releases rather than a second object, so the
|
|
1015
|
-
* handle cannot be spelled one way when opened and another when dropped.
|
|
1016
|
-
* Idempotent by contract: the server accepts an unknown handle silently, so a
|
|
1017
|
-
* client releasing everything at shutdown never has to check what is still open.
|
|
1018
|
-
*/
|
|
1019
|
-
export const participantReleasePayloadSchema = participantClaimPayloadSchema.pick({ claimId: true });
|
|
1020
|
-
/**
|
|
1021
|
-
* The `update_subscription` payload a client sends. It replaces the
|
|
1022
|
-
* connection's read interest with the complete set of sync groups — the
|
|
1023
|
-
* unleased counterpart to {@link participantClaimPayloadSchema}, with no
|
|
1024
|
-
* handle, no TTL, and no roster entry.
|
|
1025
|
-
*/
|
|
1026
|
-
export const updateSubscriptionPayloadSchema = z.object({
|
|
1027
|
-
syncGroups: frameSyncGroupsSchema,
|
|
1028
|
-
});
|
|
1029
|
-
/**
|
|
1030
|
-
* `subscription_ack` payload (server → client). Echoes the connection's
|
|
1031
|
-
* effective read set after the update (unchanged on rejection — the update is
|
|
1032
|
-
* atomic). `error` is present iff `success` is false (e.g. a scoped key
|
|
1033
|
-
* requesting a group outside its grant). `syncGroups` is lenient
|
|
1034
|
-
* (`z.string()`) here, not branded: it is the server's own echo for display,
|
|
1035
|
-
* not untrusted input, and includes base anchors like `org:<id>`.
|
|
1036
|
-
*/
|
|
1037
|
-
export const subscriptionAckPayloadSchema = z.object({
|
|
1038
|
-
success: z.boolean(),
|
|
1039
|
-
syncGroups: z.array(z.string()),
|
|
1040
|
-
error: z.object({ code: z.string(), message: z.string() }).optional(),
|
|
1041
|
-
});
|
|
1042
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
1043
|
-
// Commit operation — carries the optimistic write-guard (Layer 3)
|
|
1044
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
1045
|
-
export const commitOperationTypeSchema = z.enum([
|
|
1046
|
-
'CREATE',
|
|
1047
|
-
'UPDATE',
|
|
1048
|
-
'DELETE',
|
|
1049
|
-
'ARCHIVE',
|
|
1050
|
-
'UNARCHIVE',
|
|
1051
|
-
]);
|
|
1052
|
-
/**
|
|
1053
|
-
* A single mutation in a commit batch, as it arrives on the wire. Extends the
|
|
1054
|
-
* optimistic `writeGuard` (`readAt`/`onStale`/`bypass`) — the structural link
|
|
1055
|
-
* that makes "every write is stale-guarded" legible in the type, not just in
|
|
1056
|
-
* prose.
|
|
1057
|
-
*/
|
|
1058
|
-
export const commitOperationSchema = writeGuardSchema.extend({
|
|
1059
|
-
type: commitOperationTypeSchema,
|
|
1060
|
-
model: z.string(),
|
|
1061
|
-
id: z.string().nullish(),
|
|
1062
|
-
input: z.record(z.string(), z.unknown()).nullish(),
|
|
1063
|
-
/** Per-op client tx id, echoed on the broadcast delta. */
|
|
1064
|
-
transactionId: z.string().nullish(),
|
|
1065
|
-
/**
|
|
1066
|
-
* The fencing token from the held claim this write belongs to (Option B).
|
|
1067
|
-
* Present only on a write issued under a claim that was granted one; the
|
|
1068
|
-
* server checks it against the entity's persisted high-water and rejects a
|
|
1069
|
-
* stale token. Absent (nullish) on every unclaimed write — those are governed
|
|
1070
|
-
* by version-CAS and the Option A blind-write guard, unchanged.
|
|
1071
|
-
*/
|
|
1072
|
-
fenceToken: z.number().nullish(),
|
|
1073
|
-
});
|
|
1074
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
1075
|
-
// Layer 1 — presence (observation only; it never enforces)
|
|
1076
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
1077
|
-
export const presenceKindSchema = z.enum(['enter', 'update', 'leave']);
|
|
1078
|
-
/**
|
|
1079
|
-
* What a participant is actively working on (agents fill this in).
|
|
1080
|
-
*
|
|
1081
|
-
* The two backpressure fields are part of the frame, not an extension of it:
|
|
1082
|
-
* an agent worker announces them on every step, and an orchestrator reading
|
|
1083
|
-
* peer activity routes work by them. They are declared here because a reader
|
|
1084
|
-
* that validates this frame would otherwise drop them on the floor — the
|
|
1085
|
-
* server passes both through without interpreting either.
|
|
1086
|
-
*/
|
|
1087
|
-
export const presenceActivitySchema = targetRefSchema.extend({
|
|
1088
|
-
action: z.string(),
|
|
1089
|
-
detail: z.string().optional(),
|
|
1090
|
-
/** Backpressure signal in `[0, 1]`: `0` idle, `1` at capacity. */
|
|
1091
|
-
loadFactor: z.number().optional(),
|
|
1092
|
-
/** Gate for new assignments; absent means yes. */
|
|
1093
|
-
acceptingNewWork: z.boolean().optional(),
|
|
1094
|
-
});
|
|
1095
|
-
/**
|
|
1096
|
-
* Full `presence_update` frame as the server broadcasts it. The activity +
|
|
1097
|
-
* `activeClaims` are the observation surface for the other two layers —
|
|
1098
|
-
* rendered, never acted on as enforcement.
|
|
1099
|
-
*
|
|
1100
|
-
* Open for the same reason {@link presenceUpdatePayloadSchema} is, and it has to
|
|
1101
|
-
* be the same in both directions: whatever vocabulary an application announces
|
|
1102
|
-
* through presence, it reads back off its peers' frames. A reader that parsed
|
|
1103
|
-
* this strictly would validate the frame and quietly discard the part the
|
|
1104
|
-
* application actually came for.
|
|
1105
|
-
*/
|
|
1106
|
-
export const presenceUpdateSchema = z.object({
|
|
1107
|
-
kind: presenceKindSchema,
|
|
1108
|
-
/**
|
|
1109
|
-
* Who the frame is about. Required, because every one of the five sites that
|
|
1110
|
-
* builds a presence frame stamps it from the connection's identity — an
|
|
1111
|
-
* anonymous presence frame has never been sent and would say nothing. It was
|
|
1112
|
-
* optional here for as long as nothing parsed the frame, and the hand-written
|
|
1113
|
-
* copy the transport used to carry declared it required; two descriptions of
|
|
1114
|
-
* one frame can disagree indefinitely while neither is ever checked.
|
|
1115
|
-
*/
|
|
1116
|
-
userId: z.string(),
|
|
1117
|
-
syncGroups: z.array(z.string()).optional(),
|
|
1118
|
-
timestamp: z.number().optional(),
|
|
1119
|
-
status: z.string(),
|
|
1120
|
-
timezone: z.string().optional(),
|
|
1121
|
-
customStatus: z.string().optional(),
|
|
1122
|
-
activity: presenceActivitySchema.optional(),
|
|
1123
|
-
isAgent: z.boolean().optional(),
|
|
1124
|
-
/**
|
|
1125
|
-
* Server-stamped canonical kind. Additive — older servers omit it and
|
|
1126
|
-
* readers fall back to `isAgent` (see {@link participantKindFromWire}).
|
|
1127
|
-
*/
|
|
1128
|
-
participantKind: wireParticipantKindSchema.optional(),
|
|
1129
|
-
activeClaims: z.array(wireClaimSchema).optional(),
|
|
1130
|
-
delegatedFrom: z.string().nullish(),
|
|
1131
|
-
}).catchall(z.unknown());
|
|
1132
|
-
/**
|
|
1133
|
-
* @deprecated Renamed to {@link presenceUpdateSchema}. Removed in 0.36.0.
|
|
1134
|
-
*
|
|
1135
|
-
* `Frame` was the only such suffix in this vocabulary: every other frame the
|
|
1136
|
-
* server sends is named plainly — {@link claimLostSchema},
|
|
1137
|
-
* {@link claimAcquiredSchema}, {@link claimRejectionSchema} — and the client's
|
|
1138
|
-
* half carries `Payload`. One name did not follow the rule the other fifteen do.
|
|
1139
|
-
*/
|
|
1140
|
-
export const presenceUpdateFrameSchema = presenceUpdateSchema;
|
|
1141
|
-
/**
|
|
1142
|
-
* The `presence_update` payload a client SENDS — deliberately much smaller
|
|
1143
|
-
* than the frame the server broadcasts back.
|
|
1144
|
-
*
|
|
1145
|
-
* Everything that identifies or situates the participant is stamped by the
|
|
1146
|
-
* server and cannot be declared here: `userId`, `participantKind`, `isAgent`,
|
|
1147
|
-
* `syncGroups`, `timestamp`, `kind`, and `delegatedFrom` all come from the
|
|
1148
|
-
* connection's own identity. A client that sends them is not believed — an
|
|
1149
|
-
* older SDK once hardcoded `isAgent: true` on every announce, and because the
|
|
1150
|
-
* payload was spread into the broadcast unfiltered, every human session
|
|
1151
|
-
* rendered to its peers as an agent. Parsing an inbound payload through this
|
|
1152
|
-
* schema and broadcasting the *result* is what makes that structurally
|
|
1153
|
-
* impossible rather than a rule the broadcast has to remember.
|
|
1154
|
-
*
|
|
1155
|
-
* `status` is a plain string, matching the outbound frame: the three canonical
|
|
1156
|
-
* values are conventions the presence UI understands, not a closed set the
|
|
1157
|
-
* protocol enforces.
|
|
1158
|
-
*
|
|
1159
|
-
* The payload is deliberately OPEN — `catchall` keeps keys this schema does not
|
|
1160
|
-
* name. Presence is the one frame an application extends: an agent mesh
|
|
1161
|
-
* announces its own coordination vocabulary through it and reads it back off
|
|
1162
|
-
* peer frames, without the protocol having to learn each app's words. So the
|
|
1163
|
-
* fields named here are validated and typed, and anything else rides along
|
|
1164
|
-
* untouched. Openness is not the same as trust: the server-stamped identity
|
|
1165
|
-
* fields are applied AFTER this payload is spread into the broadcast, so a
|
|
1166
|
-
* client that sends its own `userId` or `isAgent` is overwritten either way.
|
|
1167
|
-
*/
|
|
1168
|
-
export const presenceUpdatePayloadSchema = z
|
|
1169
|
-
.object({
|
|
1170
|
-
status: z.string().optional(),
|
|
1171
|
-
activity: presenceActivitySchema.optional(),
|
|
1172
|
-
/** The sender's own open claims, which replace what the server holds. */
|
|
1173
|
-
activeClaims: z.array(wireClaimSchema).optional(),
|
|
1174
|
-
timezone: z.string().optional(),
|
|
1175
|
-
customStatus: z.string().optional(),
|
|
1176
|
-
})
|
|
1177
|
-
.catchall(z.unknown());
|