@coasys/ad4m 0.13.0-test-interpretation-2 → 0.13.0-test-model-layer
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/lib/index.cjs +1982 -498
- package/lib/index.js +1982 -499
- package/lib/src/ai/AIClient.js +6 -3
- package/lib/src/apiClient.d.ts +40 -4
- package/lib/src/apiClient.js +149 -9
- package/lib/src/index.d.ts +3 -1
- package/lib/src/index.js +2 -0
- package/lib/src/model/Ad4mModel.d.ts +6 -5
- package/lib/src/model/Ad4mModel.js +246 -29
- package/lib/src/model/Ad4mModel.test.js +480 -735
- package/lib/src/model/decorators.d.ts +147 -4
- package/lib/src/model/decorators.js +70 -24
- package/lib/src/model/model-manifest.d.ts +41 -0
- package/lib/src/model/model-manifest.js +11 -0
- package/lib/src/model/query-sparql.test.js +92 -10
- package/lib/src/model/shacl-gen.js +33 -0
- package/lib/src/model/types.d.ts +9 -0
- package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +33 -33
- package/lib/src/perspectives/AutoProcessor.d.ts +90 -24
- package/lib/src/perspectives/FlowInstance.d.ts +187 -0
- package/lib/src/perspectives/FlowInstance.js +336 -0
- package/lib/src/perspectives/FlowModels.d.ts +94 -0
- package/lib/src/perspectives/FlowModels.js +182 -0
- package/lib/src/perspectives/InterpretationModels.d.ts +12 -22
- package/lib/src/perspectives/InterpretationModels.js +2 -6
- package/lib/src/perspectives/PerspectiveClient.d.ts +68 -7
- package/lib/src/perspectives/PerspectiveClient.js +105 -10
- package/lib/src/perspectives/PerspectiveProxy.d.ts +142 -57
- package/lib/src/perspectives/PerspectiveProxy.js +388 -274
- package/lib/src/shacl/SHACLFlow.d.ts +273 -47
- package/lib/src/shacl/SHACLFlow.js +397 -88
- package/lib/src/shacl/SHACLShape.d.ts +8 -0
- package/lib/src/shacl/SHACLShape.js +17 -0
- package/lib/src/shacl/SHACLShape.test.js +82 -0
- package/package.json +2 -2
- package/src/ai/AIClient.ts +6 -3
- package/src/apiClient.test.ts +227 -0
- package/src/apiClient.ts +185 -9
- package/src/index.ts +3 -1
- package/src/model/Ad4mModel.test.ts +645 -0
- package/src/model/Ad4mModel.ts +245 -26
- package/src/model/decorators.ts +216 -35
- package/src/model/relation-filtering.test.ts +70 -20
- package/src/model/shacl-gen.ts +36 -0
- package/src/model/shacl-roundtrip.test.ts +130 -0
- package/src/model/types.ts +7 -0
- package/src/perspectives/AutoProcessor.ts +94 -24
- package/src/perspectives/FlowInstance.ts +369 -0
- package/src/perspectives/FlowModels.ts +157 -0
- package/src/perspectives/InterpretationModels.ts +13 -25
- package/src/perspectives/PerspectiveClient.test.ts +67 -6
- package/src/perspectives/PerspectiveClient.ts +142 -12
- package/src/perspectives/PerspectiveProxy.test.ts +406 -0
- package/src/perspectives/PerspectiveProxy.ts +459 -289
- package/src/perspectives/shacl-rpc.test.ts +258 -0
- package/src/shacl/SHACLFlow.test.ts +762 -35
- package/src/shacl/SHACLFlow.ts +680 -112
- package/src/shacl/SHACLShape.ts +31 -0
- package/lib/src/generated/rest/AIModelLoadingStatus.d.ts +0 -7
- package/lib/src/generated/rest/AIModelLoadingStatus.js +0 -2
- package/lib/src/generated/rest/AddAgentInfosRequest.d.ts +0 -3
- package/lib/src/generated/rest/AddAgentInfosRequest.js +0 -2
- package/lib/src/generated/rest/AddLinkExpressionRequest.d.ts +0 -6
- package/lib/src/generated/rest/AddLinkExpressionRequest.js +0 -1
- package/lib/src/generated/rest/AddLinkRequest.d.ts +0 -6
- package/lib/src/generated/rest/AddLinkRequest.js +0 -1
- package/lib/src/generated/rest/AddLinksBulkRequest.d.ts +0 -6
- package/lib/src/generated/rest/AddLinksBulkRequest.js +0 -1
- package/lib/src/generated/rest/AddSdnaRequest.d.ts +0 -6
- package/lib/src/generated/rest/AddSdnaRequest.js +0 -2
- package/lib/src/generated/rest/ApplyTemplateRequest.d.ts +0 -4
- package/lib/src/generated/rest/ApplyTemplateRequest.js +0 -2
- package/lib/src/generated/rest/AuthInfoInput.d.ts +0 -10
- package/lib/src/generated/rest/AuthInfoInput.js +0 -1
- package/lib/src/generated/rest/BroadcastRequest.d.ts +0 -6
- package/lib/src/generated/rest/BroadcastRequest.js +0 -1
- package/lib/src/generated/rest/CapabilityInput.d.ts +0 -5
- package/lib/src/generated/rest/CapabilityInput.js +0 -1
- package/lib/src/generated/rest/CommitBatchRequest.d.ts +0 -3
- package/lib/src/generated/rest/CommitBatchRequest.js +0 -2
- package/lib/src/generated/rest/ComputeLogEntry.d.ts +0 -9
- package/lib/src/generated/rest/ComputeLogEntry.js +0 -2
- package/lib/src/generated/rest/CreateExpressionRequest.d.ts +0 -4
- package/lib/src/generated/rest/CreateExpressionRequest.js +0 -2
- package/lib/src/generated/rest/CreatePerspectiveRequest.d.ts +0 -3
- package/lib/src/generated/rest/CreatePerspectiveRequest.js +0 -2
- package/lib/src/generated/rest/CreateSubjectRequest.d.ts +0 -6
- package/lib/src/generated/rest/CreateSubjectRequest.js +0 -2
- package/lib/src/generated/rest/CreateUserRequest.d.ts +0 -4
- package/lib/src/generated/rest/CreateUserRequest.js +0 -2
- package/lib/src/generated/rest/CreateUserResponse.d.ts +0 -5
- package/lib/src/generated/rest/CreateUserResponse.js +0 -2
- package/lib/src/generated/rest/DecoratedExpressionProof.d.ts +0 -6
- package/lib/src/generated/rest/DecoratedExpressionProof.js +0 -2
- package/lib/src/generated/rest/DecoratedLinkExpression.d.ts +0 -10
- package/lib/src/generated/rest/DecoratedLinkExpression.js +0 -1
- package/lib/src/generated/rest/DisposeQueryRequest.d.ts +0 -3
- package/lib/src/generated/rest/DisposeQueryRequest.js +0 -2
- package/lib/src/generated/rest/EmailTestRequest.d.ts +0 -6
- package/lib/src/generated/rest/EmailTestRequest.js +0 -2
- package/lib/src/generated/rest/EmbedRequest.d.ts +0 -4
- package/lib/src/generated/rest/EmbedRequest.js +0 -2
- package/lib/src/generated/rest/EntanglementProofInput.d.ts +0 -6
- package/lib/src/generated/rest/EntanglementProofInput.js +0 -2
- package/lib/src/generated/rest/EntanglementProofPreflightRequest.d.ts +0 -4
- package/lib/src/generated/rest/EntanglementProofPreflightRequest.js +0 -2
- package/lib/src/generated/rest/ExecuteCommandsRequest.d.ts +0 -4
- package/lib/src/generated/rest/ExecuteCommandsRequest.js +0 -2
- package/lib/src/generated/rest/ExportRequest.d.ts +0 -5
- package/lib/src/generated/rest/ExportRequest.js +0 -2
- package/lib/src/generated/rest/ExpressionManyRequest.d.ts +0 -3
- package/lib/src/generated/rest/ExpressionManyRequest.js +0 -2
- package/lib/src/generated/rest/ExpressionProof.d.ts +0 -4
- package/lib/src/generated/rest/ExpressionProof.js +0 -2
- package/lib/src/generated/rest/ExpressionProofInput.d.ts +0 -6
- package/lib/src/generated/rest/ExpressionProofInput.js +0 -2
- package/lib/src/generated/rest/FriendSendMessageRequest.d.ts +0 -3
- package/lib/src/generated/rest/FriendSendMessageRequest.js +0 -2
- package/lib/src/generated/rest/FriendsListRequest.d.ts +0 -3
- package/lib/src/generated/rest/FriendsListRequest.js +0 -2
- package/lib/src/generated/rest/GenerateAgentRequest.d.ts +0 -3
- package/lib/src/generated/rest/GenerateAgentRequest.js +0 -2
- package/lib/src/generated/rest/GenerateJwtRequest.d.ts +0 -4
- package/lib/src/generated/rest/GenerateJwtRequest.js +0 -2
- package/lib/src/generated/rest/GetSubjectDataRequest.d.ts +0 -4
- package/lib/src/generated/rest/GetSubjectDataRequest.js +0 -2
- package/lib/src/generated/rest/HostingInfoResponse.d.ts +0 -5
- package/lib/src/generated/rest/HostingInfoResponse.js +0 -2
- package/lib/src/generated/rest/HostingWalletResponse.d.ts +0 -4
- package/lib/src/generated/rest/HostingWalletResponse.js +0 -2
- package/lib/src/generated/rest/ImportAgentRequest.d.ts +0 -6
- package/lib/src/generated/rest/ImportAgentRequest.js +0 -2
- package/lib/src/generated/rest/ImportRequest.d.ts +0 -4
- package/lib/src/generated/rest/ImportRequest.js +0 -2
- package/lib/src/generated/rest/JoinNeighbourhoodRequest.d.ts +0 -3
- package/lib/src/generated/rest/JoinNeighbourhoodRequest.js +0 -2
- package/lib/src/generated/rest/KeepAliveQueryRequest.d.ts +0 -3
- package/lib/src/generated/rest/KeepAliveQueryRequest.js +0 -2
- package/lib/src/generated/rest/LanguageMetaInput.d.ts +0 -6
- package/lib/src/generated/rest/LanguageMetaInput.js +0 -2
- package/lib/src/generated/rest/Link.d.ts +0 -5
- package/lib/src/generated/rest/Link.js +0 -2
- package/lib/src/generated/rest/LinkExpression.d.ts +0 -10
- package/lib/src/generated/rest/LinkExpression.js +0 -1
- package/lib/src/generated/rest/LinkExpressionInput.d.ts +0 -10
- package/lib/src/generated/rest/LinkExpressionInput.js +0 -1
- package/lib/src/generated/rest/LinkInput.d.ts +0 -5
- package/lib/src/generated/rest/LinkInput.js +0 -2
- package/lib/src/generated/rest/LinkLanguageTemplatesRequest.d.ts +0 -3
- package/lib/src/generated/rest/LinkLanguageTemplatesRequest.js +0 -2
- package/lib/src/generated/rest/LinkMutationRequest.d.ts +0 -12
- package/lib/src/generated/rest/LinkMutationRequest.js +0 -1
- package/lib/src/generated/rest/LinkMutationResponse.d.ts +0 -9
- package/lib/src/generated/rest/LinkMutationResponse.js +0 -1
- package/lib/src/generated/rest/LinkMutations.d.ts +0 -6
- package/lib/src/generated/rest/LinkMutations.js +0 -1
- package/lib/src/generated/rest/LinkMutationsRequest.d.ts +0 -5
- package/lib/src/generated/rest/LinkMutationsRequest.js +0 -1
- package/lib/src/generated/rest/LinkStatus.d.ts +0 -1
- package/lib/src/generated/rest/LinkStatus.js +0 -2
- package/lib/src/generated/rest/LinkUpdateInput.d.ts +0 -5
- package/lib/src/generated/rest/LinkUpdateInput.js +0 -1
- package/lib/src/generated/rest/LockAgentRequest.d.ts +0 -3
- package/lib/src/generated/rest/LockAgentRequest.js +0 -2
- package/lib/src/generated/rest/LoginUserRequest.d.ts +0 -5
- package/lib/src/generated/rest/LoginUserRequest.js +0 -2
- package/lib/src/generated/rest/ModelType.d.ts +0 -1
- package/lib/src/generated/rest/ModelType.js +0 -2
- package/lib/src/generated/rest/NotificationGrantRequest.d.ts +0 -3
- package/lib/src/generated/rest/NotificationGrantRequest.js +0 -2
- package/lib/src/generated/rest/NotificationInput.d.ts +0 -10
- package/lib/src/generated/rest/NotificationInput.js +0 -2
- package/lib/src/generated/rest/OpenLinkRequest.d.ts +0 -3
- package/lib/src/generated/rest/OpenLinkRequest.js +0 -2
- package/lib/src/generated/rest/PermitCapabilityRequest.d.ts +0 -3
- package/lib/src/generated/rest/PermitCapabilityRequest.js +0 -2
- package/lib/src/generated/rest/PerspectiveInput.d.ts +0 -4
- package/lib/src/generated/rest/PerspectiveInput.js +0 -1
- package/lib/src/generated/rest/PromptRequest.d.ts +0 -4
- package/lib/src/generated/rest/PromptRequest.js +0 -2
- package/lib/src/generated/rest/PublicPerspectiveInput.d.ts +0 -4
- package/lib/src/generated/rest/PublicPerspectiveInput.js +0 -1
- package/lib/src/generated/rest/PublishLanguageRequest.d.ts +0 -5
- package/lib/src/generated/rest/PublishLanguageRequest.js +0 -1
- package/lib/src/generated/rest/PublishNeighbourhoodRequest.d.ts +0 -6
- package/lib/src/generated/rest/PublishNeighbourhoodRequest.js +0 -1
- package/lib/src/generated/rest/QueryRequest.d.ts +0 -7
- package/lib/src/generated/rest/QueryRequest.js +0 -2
- package/lib/src/generated/rest/RemoveLinkRequest.d.ts +0 -5
- package/lib/src/generated/rest/RemoveLinkRequest.js +0 -1
- package/lib/src/generated/rest/RemoveLinksBulkRequest.d.ts +0 -5
- package/lib/src/generated/rest/RemoveLinksBulkRequest.js +0 -1
- package/lib/src/generated/rest/RequestCapabilityRequest.d.ts +0 -4
- package/lib/src/generated/rest/RequestCapabilityRequest.js +0 -1
- package/lib/src/generated/rest/RequestPaymentRequest.d.ts +0 -3
- package/lib/src/generated/rest/RequestPaymentRequest.js +0 -2
- package/lib/src/generated/rest/RequestVerificationRequest.d.ts +0 -4
- package/lib/src/generated/rest/RequestVerificationRequest.js +0 -2
- package/lib/src/generated/rest/ResourceInput.d.ts +0 -4
- package/lib/src/generated/rest/ResourceInput.js +0 -2
- package/lib/src/generated/rest/SetDefaultModelRequest.d.ts +0 -4
- package/lib/src/generated/rest/SetDefaultModelRequest.js +0 -1
- package/lib/src/generated/rest/SetFreeHostingEnabledRequest.d.ts +0 -3
- package/lib/src/generated/rest/SetFreeHostingEnabledRequest.js +0 -2
- package/lib/src/generated/rest/SetHotWalletAddressRequest.d.ts +0 -3
- package/lib/src/generated/rest/SetHotWalletAddressRequest.js +0 -2
- package/lib/src/generated/rest/SetMultiUserRequest.d.ts +0 -3
- package/lib/src/generated/rest/SetMultiUserRequest.js +0 -2
- package/lib/src/generated/rest/SetOnlineStatusRequest.d.ts +0 -5
- package/lib/src/generated/rest/SetOnlineStatusRequest.js +0 -1
- package/lib/src/generated/rest/SetStatusRequest.d.ts +0 -3
- package/lib/src/generated/rest/SetStatusRequest.js +0 -2
- package/lib/src/generated/rest/SetUserFreeAccessRequest.d.ts +0 -4
- package/lib/src/generated/rest/SetUserFreeAccessRequest.js +0 -2
- package/lib/src/generated/rest/SignMessageRequest.d.ts +0 -3
- package/lib/src/generated/rest/SignMessageRequest.js +0 -2
- package/lib/src/generated/rest/SignalRequest.d.ts +0 -6
- package/lib/src/generated/rest/SignalRequest.js +0 -1
- package/lib/src/generated/rest/SubscribeQueryRequest.d.ts +0 -3
- package/lib/src/generated/rest/SubscribeQueryRequest.js +0 -2
- package/lib/src/generated/rest/SubscribeQueryResponse.d.ts +0 -4
- package/lib/src/generated/rest/SubscribeQueryResponse.js +0 -2
- package/lib/src/generated/rest/TrustedAgentsRequest.d.ts +0 -3
- package/lib/src/generated/rest/TrustedAgentsRequest.js +0 -2
- package/lib/src/generated/rest/UnlockAgentRequest.d.ts +0 -4
- package/lib/src/generated/rest/UnlockAgentRequest.js +0 -2
- package/lib/src/generated/rest/UpdateLinkRequest.d.ts +0 -7
- package/lib/src/generated/rest/UpdateLinkRequest.js +0 -1
- package/lib/src/generated/rest/UpdatePerspectiveRequest.d.ts +0 -3
- package/lib/src/generated/rest/UpdatePerspectiveRequest.js +0 -2
- package/lib/src/generated/rest/UpdateProfileRequest.d.ts +0 -5
- package/lib/src/generated/rest/UpdateProfileRequest.js +0 -1
- package/lib/src/generated/rest/UserStatistics.d.ts +0 -9
- package/lib/src/generated/rest/UserStatistics.js +0 -2
- package/lib/src/generated/rest/VerificationRequestResult.d.ts +0 -6
- package/lib/src/generated/rest/VerificationRequestResult.js +0 -2
- package/lib/src/generated/rest/VerifyEmailRequest.d.ts +0 -6
- package/lib/src/generated/rest/VerifyEmailRequest.js +0 -2
- package/lib/src/generated/rest/VerifySignatureRequest.d.ts +0 -5
- package/lib/src/generated/rest/VerifySignatureRequest.js +0 -2
- package/lib/src/generated/rest/WriteSettingsRequest.d.ts +0 -3
- package/lib/src/generated/rest/WriteSettingsRequest.js +0 -2
- package/lib/src/generated/rest/index.d.ts +0 -73
- package/lib/src/generated/rest/index.js +0 -8
- package/lib/src/generated/rest/routes.d.ts +0 -587
- package/lib/src/generated/rest/routes.js +0 -3
- package/lib/src/model/query-surreal.d.ts +0 -44
- package/lib/src/model/query-surreal.js +0 -249
- package/lib/src/model/surreal-utils.d.ts +0 -42
- package/lib/src/model/surreal-utils.js +0 -128
- package/lib/src/perspectives/PerspectiveProxy.test.d.ts +0 -1
- package/lib/src/perspectives/PerspectiveProxy.test.js +0 -34
- package/lib/src/restClient.d.ts +0 -52
- package/lib/src/restClient.js +0 -227
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _QuerySubscriptionProxy_instances, _QuerySubscriptionProxy_uuid, _QuerySubscriptionProxy_subscriptionId, _QuerySubscriptionProxy_client, _QuerySubscriptionProxy_callbacks, _QuerySubscriptionProxy_keepaliveTimer, _QuerySubscriptionProxy_unsubscribe, _QuerySubscriptionProxy_latestResult, _QuerySubscriptionProxy_disposed, _QuerySubscriptionProxy_initialized, _QuerySubscriptionProxy_initResolve, _QuerySubscriptionProxy_initReject, _QuerySubscriptionProxy_initTimeoutId, _QuerySubscriptionProxy_query, _QuerySubscriptionProxy_notifyCallbacks, _PerspectiveProxy_handle, _PerspectiveProxy_client, _PerspectiveProxy_perspectiveLinkAddedCallbacks, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, _PerspectiveProxy_perspectiveSyncStateChangeCallbacks, _PerspectiveProxy_ensuredSubjectClasses;
|
|
12
|
+
var _QuerySubscriptionProxy_instances, _QuerySubscriptionProxy_uuid, _QuerySubscriptionProxy_subscriptionId, _QuerySubscriptionProxy_client, _QuerySubscriptionProxy_callbacks, _QuerySubscriptionProxy_keepaliveTimer, _QuerySubscriptionProxy_unsubscribe, _QuerySubscriptionProxy_reconnectUnsub, _QuerySubscriptionProxy_latestResult, _QuerySubscriptionProxy_disposed, _QuerySubscriptionProxy_initialized, _QuerySubscriptionProxy_initResolve, _QuerySubscriptionProxy_initReject, _QuerySubscriptionProxy_initTimeoutId, _QuerySubscriptionProxy_query, _QuerySubscriptionProxy_generation, _QuerySubscriptionProxy_deliverResult, _QuerySubscriptionProxy_startKeepalive, _QuerySubscriptionProxy_notifyCallbacks, _PerspectiveProxy_handle, _PerspectiveProxy_client, _PerspectiveProxy_perspectiveLinkAddedCallbacks, _PerspectiveProxy_perspectiveLinkRemovedCallbacks, _PerspectiveProxy_perspectiveLinkUpdatedCallbacks, _PerspectiveProxy_perspectiveSyncStateChangeCallbacks, _PerspectiveProxy_ensuredSubjectClasses;
|
|
13
13
|
import { Link } from "../links/Links";
|
|
14
14
|
import { LinkQuery } from "./LinkQuery";
|
|
15
15
|
import { Literal } from "../Literal";
|
|
@@ -77,6 +77,7 @@ export class QuerySubscriptionProxy {
|
|
|
77
77
|
_QuerySubscriptionProxy_callbacks.set(this, void 0);
|
|
78
78
|
_QuerySubscriptionProxy_keepaliveTimer.set(this, void 0);
|
|
79
79
|
_QuerySubscriptionProxy_unsubscribe.set(this, void 0);
|
|
80
|
+
_QuerySubscriptionProxy_reconnectUnsub.set(this, void 0);
|
|
80
81
|
_QuerySubscriptionProxy_latestResult.set(this, void 0);
|
|
81
82
|
_QuerySubscriptionProxy_disposed.set(this, false);
|
|
82
83
|
_QuerySubscriptionProxy_initialized.set(this, void 0);
|
|
@@ -84,6 +85,15 @@ export class QuerySubscriptionProxy {
|
|
|
84
85
|
_QuerySubscriptionProxy_initReject.set(this, void 0);
|
|
85
86
|
_QuerySubscriptionProxy_initTimeoutId.set(this, void 0);
|
|
86
87
|
_QuerySubscriptionProxy_query.set(this, void 0);
|
|
88
|
+
// Monotonic token guarding the three concurrent writers of
|
|
89
|
+
// `#unsubscribe`/`#subscriptionId` (full subscribe() from the keepalive
|
|
90
|
+
// and init-timeout retry paths, and the reconnect swap handler). Each
|
|
91
|
+
// writer bumps it on entry and re-checks after every await; a mismatch
|
|
92
|
+
// means a newer writer took over while we were suspended, so the stale
|
|
93
|
+
// continuation must back out instead of clobbering the newer state
|
|
94
|
+
// (worst case otherwise: an overwritten-but-never-called unsubscribe
|
|
95
|
+
// leaks its callback in ApiClient._wsCallbacks for the client lifetime).
|
|
96
|
+
_QuerySubscriptionProxy_generation.set(this, 0);
|
|
87
97
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_uuid, uuid, "f");
|
|
88
98
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_query, query, "f");
|
|
89
99
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_client, client, "f");
|
|
@@ -96,6 +106,26 @@ export class QuerySubscriptionProxy {
|
|
|
96
106
|
}), "f");
|
|
97
107
|
}
|
|
98
108
|
async subscribe() {
|
|
109
|
+
var _a;
|
|
110
|
+
// Invalidate any suspended writer (older subscribe() or reconnect
|
|
111
|
+
// swap parked on an await) — see #generation.
|
|
112
|
+
const generation = __classPrivateFieldSet(this, _QuerySubscriptionProxy_generation, (_a = __classPrivateFieldGet(this, _QuerySubscriptionProxy_generation, "f"), ++_a), "f");
|
|
113
|
+
// Remove any prior reconnect listener FIRST — before we touch
|
|
114
|
+
// `#unsubscribe`. Rationale: `#unsubscribe()` calls into
|
|
115
|
+
// `ApiClient.subscribe()`'s deleter, which closes the WebSocket
|
|
116
|
+
// whenever this query owned the last `_wsCallbacks` entry (and no
|
|
117
|
+
// RPCs are pending). The subsequent `subscribeQuery()` below then
|
|
118
|
+
// re-opens a fresh socket, and that fresh `onopen` fires the
|
|
119
|
+
// reconnect callback set. If the OLD reconnect listener is still
|
|
120
|
+
// in that set, it re-enters this method, closes the socket again,
|
|
121
|
+
// reopens again … an endless resubscribe loop. Clearing the
|
|
122
|
+
// listener up-front breaks the cycle; a fresh listener is
|
|
123
|
+
// installed at the end of a successful subscribe(), and a
|
|
124
|
+
// full-retry recovery listener in the catch block on failure.
|
|
125
|
+
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_reconnectUnsub, "f")) {
|
|
126
|
+
__classPrivateFieldGet(this, _QuerySubscriptionProxy_reconnectUnsub, "f").call(this);
|
|
127
|
+
__classPrivateFieldSet(this, _QuerySubscriptionProxy_reconnectUnsub, undefined, "f");
|
|
128
|
+
}
|
|
99
129
|
// Clean up previous subscription attempt if retrying
|
|
100
130
|
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_unsubscribe, "f")) {
|
|
101
131
|
__classPrivateFieldGet(this, _QuerySubscriptionProxy_unsubscribe, "f").call(this);
|
|
@@ -115,19 +145,22 @@ export class QuerySubscriptionProxy {
|
|
|
115
145
|
// Initialize the query subscription
|
|
116
146
|
let initialResult;
|
|
117
147
|
initialResult = await __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").subscribeQuery(__classPrivateFieldGet(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet(this, _QuerySubscriptionProxy_query, "f"));
|
|
148
|
+
// A newer writer (another subscribe() or a reconnect swap) took
|
|
149
|
+
// over while we awaited — back out without touching shared state,
|
|
150
|
+
// and release the now-orphaned server-side subscription so it
|
|
151
|
+
// doesn't linger until its keepalive TTL expires.
|
|
152
|
+
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_disposed, "f") || __classPrivateFieldGet(this, _QuerySubscriptionProxy_generation, "f") !== generation) {
|
|
153
|
+
__classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").disposeQuerySubscription(__classPrivateFieldGet(this, _QuerySubscriptionProxy_uuid, "f"), initialResult.subscriptionId)
|
|
154
|
+
.catch(e => console.error('Error disposing superseded query subscription:', e));
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
118
157
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_subscriptionId, initialResult.subscriptionId, "f");
|
|
119
158
|
// Process the initial result immediately for fast UX.
|
|
120
159
|
// The subscribeQuery() RPC call already returns the initial result,
|
|
121
160
|
// so treat that as successful initialization instead of waiting for a
|
|
122
161
|
// follow-up WebSocket update that may never arrive until the query changes.
|
|
123
162
|
if (initialResult.result !== undefined) {
|
|
124
|
-
|
|
125
|
-
__classPrivateFieldGet(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_notifyCallbacks).call(this, initialResult.result);
|
|
126
|
-
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_initResolve, "f")) {
|
|
127
|
-
__classPrivateFieldGet(this, _QuerySubscriptionProxy_initResolve, "f").call(this, true);
|
|
128
|
-
__classPrivateFieldSet(this, _QuerySubscriptionProxy_initResolve, undefined, "f");
|
|
129
|
-
__classPrivateFieldSet(this, _QuerySubscriptionProxy_initReject, undefined, "f");
|
|
130
|
-
}
|
|
163
|
+
__classPrivateFieldGet(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_deliverResult).call(this, initialResult.result);
|
|
131
164
|
}
|
|
132
165
|
else {
|
|
133
166
|
console.warn('⚠️ No initial result returned from subscribeQuery!');
|
|
@@ -142,21 +175,7 @@ export class QuerySubscriptionProxy {
|
|
|
142
175
|
}, 30000), "f");
|
|
143
176
|
}
|
|
144
177
|
// Subscribe to query updates
|
|
145
|
-
__classPrivateFieldSet(this, _QuerySubscriptionProxy_unsubscribe, __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").subscribeToQueryUpdates(__classPrivateFieldGet(this, _QuerySubscriptionProxy_subscriptionId, "f"), (updateResult) =>
|
|
146
|
-
// Clear timeout on first message
|
|
147
|
-
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_initTimeoutId, "f")) {
|
|
148
|
-
clearTimeout(__classPrivateFieldGet(this, _QuerySubscriptionProxy_initTimeoutId, "f"));
|
|
149
|
-
__classPrivateFieldSet(this, _QuerySubscriptionProxy_initTimeoutId, undefined, "f");
|
|
150
|
-
}
|
|
151
|
-
// Resolve the initialization promise (only resolves once)
|
|
152
|
-
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_initResolve, "f")) {
|
|
153
|
-
__classPrivateFieldGet(this, _QuerySubscriptionProxy_initResolve, "f").call(this, true);
|
|
154
|
-
__classPrivateFieldSet(this, _QuerySubscriptionProxy_initResolve, undefined, "f"); // Prevent double-resolve
|
|
155
|
-
__classPrivateFieldSet(this, _QuerySubscriptionProxy_initReject, undefined, "f");
|
|
156
|
-
}
|
|
157
|
-
__classPrivateFieldSet(this, _QuerySubscriptionProxy_latestResult, updateResult, "f");
|
|
158
|
-
__classPrivateFieldGet(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_notifyCallbacks).call(this, updateResult);
|
|
159
|
-
}), "f");
|
|
178
|
+
__classPrivateFieldSet(this, _QuerySubscriptionProxy_unsubscribe, __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").subscribeToQueryUpdates(__classPrivateFieldGet(this, _QuerySubscriptionProxy_subscriptionId, "f"), (updateResult) => __classPrivateFieldGet(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_deliverResult).call(this, updateResult)), "f");
|
|
160
179
|
}
|
|
161
180
|
catch (error) {
|
|
162
181
|
console.error('Error setting up subscription:', error);
|
|
@@ -166,36 +185,117 @@ export class QuerySubscriptionProxy {
|
|
|
166
185
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_initResolve, undefined, "f");
|
|
167
186
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_initReject, undefined, "f");
|
|
168
187
|
}
|
|
188
|
+
// Restore reconnect recovery before rethrowing. The listener was
|
|
189
|
+
// removed at the top of this method; without re-installing one
|
|
190
|
+
// here, a single failed resubscribe (e.g. subscribeQuery timing
|
|
191
|
+
// out during a network flap) would leave the proxy permanently
|
|
192
|
+
// dead: the keepalive loop stops itself on resubscribe failure,
|
|
193
|
+
// and nothing else retries. The recovery listener runs the FULL
|
|
194
|
+
// subscribe() (not the swap-in-place handler) because after a
|
|
195
|
+
// failed attempt there is no keepalive loop left to feed the new
|
|
196
|
+
// server subscription — subscribe() restarts it. This is
|
|
197
|
+
// loop-safe: in this failed state the proxy owns no
|
|
198
|
+
// `_wsCallbacks` entry (the old one was unsubscribed at the top
|
|
199
|
+
// of this method and no new one got registered), so the
|
|
200
|
+
// subscribe() it triggers has nothing to unsubscribe → the
|
|
201
|
+
// socket never closes/reopens under it → no re-entrant onopen.
|
|
202
|
+
if (!__classPrivateFieldGet(this, _QuerySubscriptionProxy_disposed, "f") && __classPrivateFieldGet(this, _QuerySubscriptionProxy_generation, "f") === generation && __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").onReconnect) {
|
|
203
|
+
__classPrivateFieldSet(this, _QuerySubscriptionProxy_reconnectUnsub, __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").onReconnect(() => {
|
|
204
|
+
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_disposed, "f"))
|
|
205
|
+
return;
|
|
206
|
+
console.log('WebSocket reconnected — retrying failed subscription for query:', __classPrivateFieldGet(this, _QuerySubscriptionProxy_query, "f"));
|
|
207
|
+
this.subscribe().catch(e => {
|
|
208
|
+
console.error('Error during subscription retry after reconnect:', e);
|
|
209
|
+
});
|
|
210
|
+
}), "f");
|
|
211
|
+
}
|
|
169
212
|
throw error; // Re-throw so caller knows it failed
|
|
170
213
|
}
|
|
171
|
-
// Start keepalive loop
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
214
|
+
// Start keepalive loop
|
|
215
|
+
__classPrivateFieldGet(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_startKeepalive).call(this, generation);
|
|
216
|
+
// Register for reconnect notification — on WebSocket reconnect,
|
|
217
|
+
// immediately re-establish a fresh server-side subscription instead
|
|
218
|
+
// of waiting up to 30s for the keepalive to fail.
|
|
219
|
+
//
|
|
220
|
+
// We deliberately do NOT call `this.subscribe()` here. Full subscribe
|
|
221
|
+
// runs `#unsubscribe` first, which delegates to `ApiClient.subscribe`'s
|
|
222
|
+
// deleter — that closes the WebSocket when this query owned the LAST
|
|
223
|
+
// `_wsCallbacks` entry. The subsequent `subscribeQuery` reopens the
|
|
224
|
+
// socket, whose fresh `onopen` fires every registered reconnect
|
|
225
|
+
// callback again → recursion (CodeRabbit's original finding). And
|
|
226
|
+
// during that close→reopen gap, RPCs in flight from OTHER proxies
|
|
227
|
+
// fail with `503 WebSocket not connected` (observed in
|
|
228
|
+
// integration-tests-mcp `should fire onWake when mention uses agent DID`
|
|
229
|
+
// after PR #899's initial fix — the WakerSubscriptionManager tests
|
|
230
|
+
// share a wakerClient across cases, so any dying reconnect handler
|
|
231
|
+
// interferes with sibling subscriptions).
|
|
232
|
+
//
|
|
233
|
+
// The correct shape is a swap-in-place: get a new server-side
|
|
234
|
+
// subscription ID via `subscribeQuery`, register a new client-side
|
|
235
|
+
// callback FIRST, and only then unsubscribe the old one. That way
|
|
236
|
+
// `_wsCallbacks.size` never dips to 0 during the transition, so the
|
|
237
|
+
// socket doesn't close, no reconnect loop, and no cross-proxy 503s.
|
|
238
|
+
// Any prior listener was already removed at the top of this method
|
|
239
|
+
// (see the note there for why cleanup must run before `#unsubscribe`,
|
|
240
|
+
// not here).
|
|
241
|
+
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").onReconnect) {
|
|
242
|
+
__classPrivateFieldSet(this, _QuerySubscriptionProxy_reconnectUnsub, __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").onReconnect(async () => {
|
|
243
|
+
var _a;
|
|
244
|
+
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_disposed, "f"))
|
|
245
|
+
return;
|
|
246
|
+
// The handler is a writer of `#unsubscribe`/`#subscriptionId`
|
|
247
|
+
// too, so it takes its own generation — see #generation.
|
|
248
|
+
const swapGeneration = __classPrivateFieldSet(this, _QuerySubscriptionProxy_generation, (_a = __classPrivateFieldGet(this, _QuerySubscriptionProxy_generation, "f"), ++_a), "f");
|
|
249
|
+
console.log('WebSocket reconnected — re-establishing server subscription for query:', __classPrivateFieldGet(this, _QuerySubscriptionProxy_query, "f"));
|
|
182
250
|
try {
|
|
183
|
-
await this.
|
|
184
|
-
|
|
251
|
+
const newInitial = await __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").subscribeQuery(__classPrivateFieldGet(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet(this, _QuerySubscriptionProxy_query, "f"));
|
|
252
|
+
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_disposed, "f") || __classPrivateFieldGet(this, _QuerySubscriptionProxy_generation, "f") !== swapGeneration) {
|
|
253
|
+
// A newer writer took over while we awaited — back out
|
|
254
|
+
// and release the orphaned server-side subscription.
|
|
255
|
+
__classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").disposeQuerySubscription(__classPrivateFieldGet(this, _QuerySubscriptionProxy_uuid, "f"), newInitial.subscriptionId)
|
|
256
|
+
.catch(e => console.error('Error disposing superseded query subscription:', e));
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const newSubId = newInitial.subscriptionId;
|
|
260
|
+
// Register the NEW client-side callback BEFORE removing the
|
|
261
|
+
// old one — keeps `_wsCallbacks.size >= 1` across the swap.
|
|
262
|
+
const newUnsub = __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").subscribeToQueryUpdates(newSubId, (updateResult) => __classPrivateFieldGet(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_deliverResult).call(this, updateResult));
|
|
263
|
+
const oldUnsub = __classPrivateFieldGet(this, _QuerySubscriptionProxy_unsubscribe, "f");
|
|
264
|
+
__classPrivateFieldSet(this, _QuerySubscriptionProxy_unsubscribe, newUnsub, "f");
|
|
265
|
+
__classPrivateFieldSet(this, _QuerySubscriptionProxy_subscriptionId, newSubId, "f");
|
|
266
|
+
if (oldUnsub)
|
|
267
|
+
oldUnsub();
|
|
268
|
+
// Our generation bump invalidated the running keepalive
|
|
269
|
+
// loop — restart it under our generation so the new
|
|
270
|
+
// server subscription keeps receiving keepalives.
|
|
271
|
+
clearTimeout(__classPrivateFieldGet(this, _QuerySubscriptionProxy_keepaliveTimer, "f"));
|
|
272
|
+
__classPrivateFieldGet(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_startKeepalive).call(this, swapGeneration);
|
|
273
|
+
// Deliver the fresh initial result if the server included one
|
|
274
|
+
// (matches the eager-delivery path in the main subscribe() body).
|
|
275
|
+
// #deliverResult also clears a still-pending init timeout and
|
|
276
|
+
// resolves #initialized, keeping this path symmetric with the
|
|
277
|
+
// update callback in subscribe() — without it, a swap landing
|
|
278
|
+
// while initialization was pending would leave the 30s init
|
|
279
|
+
// timer armed and trigger a spurious full resubscribe.
|
|
280
|
+
if (newInitial.result !== undefined) {
|
|
281
|
+
__classPrivateFieldGet(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_deliverResult).call(this, newInitial.result);
|
|
282
|
+
}
|
|
185
283
|
}
|
|
186
|
-
catch (
|
|
187
|
-
console.error('Error
|
|
188
|
-
//
|
|
189
|
-
|
|
284
|
+
catch (error) {
|
|
285
|
+
console.error('Error re-establishing subscription after reconnect:', error);
|
|
286
|
+
// Our generation bump invalidated the running keepalive
|
|
287
|
+
// loop; if nothing newer superseded us, restart it so
|
|
288
|
+
// liveness is preserved — its keepAliveQuery against the
|
|
289
|
+
// dead old subscription will fail and fall back to a
|
|
290
|
+
// full subscribe(). The reconnect listener also remains
|
|
291
|
+
// installed, so a later reconnect retries this handler.
|
|
292
|
+
if (!__classPrivateFieldGet(this, _QuerySubscriptionProxy_disposed, "f") && __classPrivateFieldGet(this, _QuerySubscriptionProxy_generation, "f") === swapGeneration) {
|
|
293
|
+
clearTimeout(__classPrivateFieldGet(this, _QuerySubscriptionProxy_keepaliveTimer, "f"));
|
|
294
|
+
__classPrivateFieldGet(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_startKeepalive).call(this, swapGeneration);
|
|
295
|
+
}
|
|
190
296
|
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (!__classPrivateFieldGet(this, _QuerySubscriptionProxy_disposed, "f")) {
|
|
194
|
-
__classPrivateFieldSet(this, _QuerySubscriptionProxy_keepaliveTimer, setTimeout(keepaliveLoop, 30000), "f");
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
// Start the first keepalive loop
|
|
198
|
-
__classPrivateFieldSet(this, _QuerySubscriptionProxy_keepaliveTimer, setTimeout(keepaliveLoop, 30000), "f");
|
|
297
|
+
}), "f");
|
|
298
|
+
}
|
|
199
299
|
}
|
|
200
300
|
/** Get the subscription ID for this query subscription
|
|
201
301
|
*
|
|
@@ -268,11 +368,19 @@ export class QuerySubscriptionProxy {
|
|
|
268
368
|
* will not receive any more updates. The instance should be discarded.
|
|
269
369
|
*/
|
|
270
370
|
dispose() {
|
|
371
|
+
var _a;
|
|
271
372
|
__classPrivateFieldSet(this, _QuerySubscriptionProxy_disposed, true, "f");
|
|
373
|
+
// Invalidate any suspended writer so a mid-flight subscribe() or
|
|
374
|
+
// reconnect swap backs out instead of resurrecting state.
|
|
375
|
+
__classPrivateFieldSet(this, _QuerySubscriptionProxy_generation, (_a = __classPrivateFieldGet(this, _QuerySubscriptionProxy_generation, "f"), _a++, _a), "f");
|
|
272
376
|
clearTimeout(__classPrivateFieldGet(this, _QuerySubscriptionProxy_keepaliveTimer, "f"));
|
|
273
377
|
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_unsubscribe, "f")) {
|
|
274
378
|
__classPrivateFieldGet(this, _QuerySubscriptionProxy_unsubscribe, "f").call(this);
|
|
275
379
|
}
|
|
380
|
+
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_reconnectUnsub, "f")) {
|
|
381
|
+
__classPrivateFieldGet(this, _QuerySubscriptionProxy_reconnectUnsub, "f").call(this);
|
|
382
|
+
__classPrivateFieldSet(this, _QuerySubscriptionProxy_reconnectUnsub, undefined, "f");
|
|
383
|
+
}
|
|
276
384
|
__classPrivateFieldGet(this, _QuerySubscriptionProxy_callbacks, "f").clear();
|
|
277
385
|
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_initTimeoutId, "f")) {
|
|
278
386
|
clearTimeout(__classPrivateFieldGet(this, _QuerySubscriptionProxy_initTimeoutId, "f"));
|
|
@@ -285,7 +393,58 @@ export class QuerySubscriptionProxy {
|
|
|
285
393
|
}
|
|
286
394
|
}
|
|
287
395
|
}
|
|
288
|
-
_QuerySubscriptionProxy_uuid = new WeakMap(), _QuerySubscriptionProxy_subscriptionId = new WeakMap(), _QuerySubscriptionProxy_client = new WeakMap(), _QuerySubscriptionProxy_callbacks = new WeakMap(), _QuerySubscriptionProxy_keepaliveTimer = new WeakMap(), _QuerySubscriptionProxy_unsubscribe = new WeakMap(), _QuerySubscriptionProxy_latestResult = new WeakMap(), _QuerySubscriptionProxy_disposed = new WeakMap(), _QuerySubscriptionProxy_initialized = new WeakMap(), _QuerySubscriptionProxy_initResolve = new WeakMap(), _QuerySubscriptionProxy_initReject = new WeakMap(), _QuerySubscriptionProxy_initTimeoutId = new WeakMap(), _QuerySubscriptionProxy_query = new WeakMap(), _QuerySubscriptionProxy_instances = new WeakSet(),
|
|
396
|
+
_QuerySubscriptionProxy_uuid = new WeakMap(), _QuerySubscriptionProxy_subscriptionId = new WeakMap(), _QuerySubscriptionProxy_client = new WeakMap(), _QuerySubscriptionProxy_callbacks = new WeakMap(), _QuerySubscriptionProxy_keepaliveTimer = new WeakMap(), _QuerySubscriptionProxy_unsubscribe = new WeakMap(), _QuerySubscriptionProxy_reconnectUnsub = new WeakMap(), _QuerySubscriptionProxy_latestResult = new WeakMap(), _QuerySubscriptionProxy_disposed = new WeakMap(), _QuerySubscriptionProxy_initialized = new WeakMap(), _QuerySubscriptionProxy_initResolve = new WeakMap(), _QuerySubscriptionProxy_initReject = new WeakMap(), _QuerySubscriptionProxy_initTimeoutId = new WeakMap(), _QuerySubscriptionProxy_query = new WeakMap(), _QuerySubscriptionProxy_generation = new WeakMap(), _QuerySubscriptionProxy_instances = new WeakSet(), _QuerySubscriptionProxy_deliverResult = function _QuerySubscriptionProxy_deliverResult(result) {
|
|
397
|
+
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_initTimeoutId, "f")) {
|
|
398
|
+
clearTimeout(__classPrivateFieldGet(this, _QuerySubscriptionProxy_initTimeoutId, "f"));
|
|
399
|
+
__classPrivateFieldSet(this, _QuerySubscriptionProxy_initTimeoutId, undefined, "f");
|
|
400
|
+
}
|
|
401
|
+
// Resolve the initialization promise (only resolves once)
|
|
402
|
+
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_initResolve, "f")) {
|
|
403
|
+
__classPrivateFieldGet(this, _QuerySubscriptionProxy_initResolve, "f").call(this, true);
|
|
404
|
+
__classPrivateFieldSet(this, _QuerySubscriptionProxy_initResolve, undefined, "f"); // Prevent double-resolve
|
|
405
|
+
__classPrivateFieldSet(this, _QuerySubscriptionProxy_initReject, undefined, "f");
|
|
406
|
+
}
|
|
407
|
+
__classPrivateFieldSet(this, _QuerySubscriptionProxy_latestResult, result, "f");
|
|
408
|
+
__classPrivateFieldGet(this, _QuerySubscriptionProxy_instances, "m", _QuerySubscriptionProxy_notifyCallbacks).call(this, result);
|
|
409
|
+
}, _QuerySubscriptionProxy_startKeepalive = function _QuerySubscriptionProxy_startKeepalive(generation) {
|
|
410
|
+
const keepaliveLoop = async () => {
|
|
411
|
+
// Generation check kills orphaned loops: a loop whose
|
|
412
|
+
// keepAliveQuery was in flight while a newer writer ran is not
|
|
413
|
+
// cancelled by clearTimeout and would otherwise reschedule
|
|
414
|
+
// itself alongside the newer loop.
|
|
415
|
+
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_disposed, "f") || __classPrivateFieldGet(this, _QuerySubscriptionProxy_generation, "f") !== generation)
|
|
416
|
+
return;
|
|
417
|
+
try {
|
|
418
|
+
await __classPrivateFieldGet(this, _QuerySubscriptionProxy_client, "f").keepAliveQuery(__classPrivateFieldGet(this, _QuerySubscriptionProxy_uuid, "f"), __classPrivateFieldGet(this, _QuerySubscriptionProxy_subscriptionId, "f"));
|
|
419
|
+
}
|
|
420
|
+
catch (e) {
|
|
421
|
+
if (__classPrivateFieldGet(this, _QuerySubscriptionProxy_disposed, "f") || __classPrivateFieldGet(this, _QuerySubscriptionProxy_generation, "f") !== generation)
|
|
422
|
+
return;
|
|
423
|
+
console.error('Error in keepalive:', e);
|
|
424
|
+
// try to reinitialize the subscription
|
|
425
|
+
console.log('Reinitializing subscription for query:', __classPrivateFieldGet(this, _QuerySubscriptionProxy_query, "f"));
|
|
426
|
+
try {
|
|
427
|
+
await this.subscribe();
|
|
428
|
+
console.log('Subscription reinitialized');
|
|
429
|
+
}
|
|
430
|
+
catch (resubscribeError) {
|
|
431
|
+
console.error('Error during resubscription from keepalive:', resubscribeError);
|
|
432
|
+
// Don't schedule another keepalive on resubscribe failure.
|
|
433
|
+
// Recovery is not lost: the failed subscribe() installed a
|
|
434
|
+
// reconnect listener that retries the full subscribe.
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
// subscribe() succeeded and started its own keepalive loop
|
|
438
|
+
// under a new generation — this loop is done.
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
// Schedule next keepalive if still the active generation
|
|
442
|
+
if (!__classPrivateFieldGet(this, _QuerySubscriptionProxy_disposed, "f") && __classPrivateFieldGet(this, _QuerySubscriptionProxy_generation, "f") === generation) {
|
|
443
|
+
__classPrivateFieldSet(this, _QuerySubscriptionProxy_keepaliveTimer, setTimeout(keepaliveLoop, 30000), "f");
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
__classPrivateFieldSet(this, _QuerySubscriptionProxy_keepaliveTimer, setTimeout(keepaliveLoop, 30000), "f");
|
|
447
|
+
}, _QuerySubscriptionProxy_notifyCallbacks = function _QuerySubscriptionProxy_notifyCallbacks(result) {
|
|
289
448
|
for (const callback of __classPrivateFieldGet(this, _QuerySubscriptionProxy_callbacks, "f")) {
|
|
290
449
|
try {
|
|
291
450
|
callback(result);
|
|
@@ -484,8 +643,8 @@ export class PerspectiveProxy {
|
|
|
484
643
|
* });
|
|
485
644
|
* ```
|
|
486
645
|
*/
|
|
487
|
-
async get(query) {
|
|
488
|
-
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").queryLinks(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, query);
|
|
646
|
+
async get(query, options) {
|
|
647
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").queryLinks(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, query, options);
|
|
489
648
|
}
|
|
490
649
|
/**
|
|
491
650
|
* Runs generic LLM interpretation over a conversation transcript, turning it
|
|
@@ -500,8 +659,38 @@ export class PerspectiveProxy {
|
|
|
500
659
|
* @param basePrefix URI namespace for new instance identities, e.g. `soa://ext/`
|
|
501
660
|
* @param classes local names of the subject classes to extract into; omit for all
|
|
502
661
|
*/
|
|
503
|
-
async runInterpretation(transcript, basePrefix, classes) {
|
|
504
|
-
|
|
662
|
+
async runInterpretation(transcript, basePrefix, classes, options) {
|
|
663
|
+
// Grouped into an options bag rather than continuing the client's positional list.
|
|
664
|
+
// The scopes were already unreachable from here for that reason, and a fourth, fifth and
|
|
665
|
+
// sixth positional parameter would have made `undefined, undefined, { … }` the normal way
|
|
666
|
+
// to ask for the only one of them most callers want.
|
|
667
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").runInterpretation(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, transcript, basePrefix, classes, options?.existingScope, options?.mintScope, options?.observe);
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Harness-dispatched interpretation pass over this perspective (design v3
|
|
671
|
+
* §6 — the tool-calling counterpart to {@link runInterpretation}). The LLM
|
|
672
|
+
* sees a live per-class tool surface (`{Class}_query`, `{Class}_get`,
|
|
673
|
+
* `{Class}_propose_create`, `{Class}_propose_link_child`, …) and drives
|
|
674
|
+
* the extraction via tool calls; buffered proposals drain through the
|
|
675
|
+
* same overlay gate the single-shot path uses.
|
|
676
|
+
*
|
|
677
|
+
* @param transcript ordered `{ speaker, text }` turns
|
|
678
|
+
* @param basePrefix URI namespace new instance identities are minted under
|
|
679
|
+
* @param maxToolCalls upper bound on tool calls the harness will make in
|
|
680
|
+
* one pass (must be > 0 — use {@link runInterpretation} for the
|
|
681
|
+
* classic single-shot path)
|
|
682
|
+
* @param classes local names of the subject classes to extract into; omit for all
|
|
683
|
+
* @param modelOverride optional model override; omit for the default LLM
|
|
684
|
+
*/
|
|
685
|
+
async runInterpretationWithHarness(transcript, basePrefix, maxToolCalls, classes, modelOverride,
|
|
686
|
+
// Optional live-debug observability. When both `observationId` and
|
|
687
|
+
// `emitDebugEvents` are supplied, every dispatched tool call fires
|
|
688
|
+
// `ToolCall` + `ToolResult` events on the `auto-processor-event`
|
|
689
|
+
// topic keyed by `observationId`. Subscribe with
|
|
690
|
+
// {@link addAutoProcessorEventListener} to render the harness loop
|
|
691
|
+
// live in a UI. Absent = fast headless path (no telemetry cost).
|
|
692
|
+
observationId, emitDebugEvents) {
|
|
693
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").runInterpretationWithHarness(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, transcript, basePrefix, maxToolCalls, classes, modelOverride, undefined, observationId, emitDebugEvents);
|
|
505
694
|
}
|
|
506
695
|
/**
|
|
507
696
|
* Register a neighbourhood auto-processor on this perspective. The executor
|
|
@@ -512,6 +701,24 @@ export class PerspectiveProxy {
|
|
|
512
701
|
async addAutoProcessor(config) {
|
|
513
702
|
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").addAutoProcessor(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, config);
|
|
514
703
|
}
|
|
704
|
+
/**
|
|
705
|
+
* Stop an auto-processor by deleting its config.
|
|
706
|
+
*
|
|
707
|
+
* The registration is data — the watch loop reads the processor set back out of the
|
|
708
|
+
* perspective's graph on every tick — so deleting the config is what stops it, and there is
|
|
709
|
+
* nothing else to unregister. The config is `Shared`, so this stops the processor for the
|
|
710
|
+
* neighbourhood rather than only for this peer.
|
|
711
|
+
*
|
|
712
|
+
* Resolves `true` when there was a processor to remove and `false` when there was not; a
|
|
713
|
+
* processor another peer has already removed is not an error.
|
|
714
|
+
*
|
|
715
|
+
* The processor's `InterpretationRun` nodes stay: they are the record of what it did and the
|
|
716
|
+
* processed-turn cursor, so a processor later registered under the same id resumes where this
|
|
717
|
+
* one left off rather than re-reading every turn.
|
|
718
|
+
*/
|
|
719
|
+
async removeAutoProcessor(processorId) {
|
|
720
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").removeAutoProcessor(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, processorId);
|
|
721
|
+
}
|
|
515
722
|
/**
|
|
516
723
|
* Pending interpretation overlays on this perspective — LLM suggestions the
|
|
517
724
|
* §4 divergence gate staged rather than applied, awaiting human accept/reject.
|
|
@@ -572,8 +779,8 @@ export class PerspectiveProxy {
|
|
|
572
779
|
* `);
|
|
573
780
|
* ```
|
|
574
781
|
*/
|
|
575
|
-
async infer(query) {
|
|
576
|
-
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").queryProlog(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, query);
|
|
782
|
+
async infer(query, options) {
|
|
783
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").queryProlog(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, query, options);
|
|
577
784
|
}
|
|
578
785
|
/**
|
|
579
786
|
* Executes a SPARQL query against the perspective's link cache.
|
|
@@ -583,19 +790,25 @@ export class PerspectiveProxy {
|
|
|
583
790
|
* Mutating operations (DELETE, UPDATE, INSERT, CREATE, DROP, DEFINE, etc.) are
|
|
584
791
|
* blocked for security reasons. Use the perspective's add/remove methods to modify links.
|
|
585
792
|
*
|
|
586
|
-
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
*
|
|
793
|
+
* **Cancellation:** Pass `{ signal }` from an `AbortController` to abort
|
|
794
|
+
* an in-flight query. The executor receives `request.cancel` over the
|
|
795
|
+
* WebSocket and short-circuits the JSON reply. Caveat: Oxigraph itself
|
|
796
|
+
* cannot be interrupted mid-evaluation, so an already-running scan will
|
|
797
|
+
* keep its blocking thread busy until it completes; what's saved is the
|
|
798
|
+
* serialise + network + client-deserialise tax on the result. Aborted
|
|
799
|
+
* calls reject with `DOMException('Aborted', 'AbortError')` — match
|
|
800
|
+
* `fetch()` for handling. Cached results bypass the round-trip entirely
|
|
801
|
+
* and are returned synchronously, ignoring the signal.
|
|
590
802
|
*
|
|
591
|
-
* @param query - SPARQL query string
|
|
803
|
+
* @param query - SPARQL query string (read-only operations only)
|
|
804
|
+
* @param options - Optional call options (e.g. AbortSignal for cancellation)
|
|
592
805
|
* @returns Query results as parsed JSON
|
|
593
806
|
*/
|
|
594
|
-
async querySparql(query) {
|
|
807
|
+
async querySparql(query, options) {
|
|
595
808
|
const cached = getCachedResult(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, query);
|
|
596
809
|
if (cached !== undefined)
|
|
597
810
|
return cached;
|
|
598
|
-
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").querySparql(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, query);
|
|
811
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").querySparql(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, query, options);
|
|
599
812
|
setCachedResult(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, query, result);
|
|
600
813
|
return result;
|
|
601
814
|
}
|
|
@@ -610,8 +823,43 @@ export class PerspectiveProxy {
|
|
|
610
823
|
* @param queryJson - Structured query as JSON string
|
|
611
824
|
* @returns Object with `instances` array and `totalCount`
|
|
612
825
|
*/
|
|
613
|
-
async modelQuery(className, queryJson) {
|
|
614
|
-
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").modelQuery(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson);
|
|
826
|
+
async modelQuery(className, queryJson, options) {
|
|
827
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").modelQuery(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, className, queryJson, options);
|
|
828
|
+
}
|
|
829
|
+
/** Resolve each URI to the names of every subject class it is an instance of.
|
|
830
|
+
*
|
|
831
|
+
* The counterpart of {@link isSubjectInstance}, which asks the same question
|
|
832
|
+
* one class at a time. Without this, finding the class of an arbitrary URI
|
|
833
|
+
* meant looping over every registered class — a round trip each — and doing
|
|
834
|
+
* it again for every URI.
|
|
835
|
+
*
|
|
836
|
+
* Class membership in AD4M is structural — a URI belongs to a class when it
|
|
837
|
+
* carries that class's flags and required properties — so membership is **not
|
|
838
|
+
* exclusive**: an instance conforms to its parent classes, and to any
|
|
839
|
+
* unrelated class whose required set happens to be a subset of what it
|
|
840
|
+
* carries. Every match is returned.
|
|
841
|
+
*
|
|
842
|
+
* The list is ordered **most specific first**, meaning by the number of
|
|
843
|
+
* triples the class requires — a subclass requires everything its parent does
|
|
844
|
+
* and more — with ties broken alphabetically so that every peer answers
|
|
845
|
+
* identically. A caller that can only act on one class should take
|
|
846
|
+
* `classes[0]`, but that head is only a heuristic: it is arbitrary between two
|
|
847
|
+
* unrelated classes requiring the same number of triples, which is exactly
|
|
848
|
+
* the case the full list exists to expose.
|
|
849
|
+
*
|
|
850
|
+
* A URI is **absent from the result** when no *registered* class matched it.
|
|
851
|
+
* That covers two situations, and nothing here separates them: the URI may
|
|
852
|
+
* not be a subject instance at all, or it may be an instance of a class this
|
|
853
|
+
* perspective has not registered. Absence is used rather than an empty list
|
|
854
|
+
* because an empty list would claim the stronger thing — that the URI belongs
|
|
855
|
+
* to no class — which this cannot know.
|
|
856
|
+
*
|
|
857
|
+
* @param uris The expression URIs to classify.
|
|
858
|
+
*/
|
|
859
|
+
async subjectClassesOf(uris) {
|
|
860
|
+
if (uris.length === 0)
|
|
861
|
+
return {};
|
|
862
|
+
return await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").subjectClassesOf(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, uris);
|
|
615
863
|
}
|
|
616
864
|
/**
|
|
617
865
|
* Evaluate property getters for a batch of instances in a single RPC call.
|
|
@@ -947,116 +1195,48 @@ export class PerspectiveProxy {
|
|
|
947
1195
|
}
|
|
948
1196
|
});
|
|
949
1197
|
}
|
|
950
|
-
/**
|
|
1198
|
+
/**
|
|
1199
|
+
* Returns all Social DNA flows that can be started from the given expression.
|
|
1200
|
+
*
|
|
1201
|
+
* Post-`flowable` retirement: a flow is a candidate iff its `inputTypes`
|
|
1202
|
+
* declaration is compatible with the expression. Matching rules:
|
|
1203
|
+
* - Empty `inputTypes` or one containing the `"any"` wildcard → always
|
|
1204
|
+
* matches (same behaviour as the legacy `flowable === "any"` case).
|
|
1205
|
+
* - Otherwise, at least one of the expression's registered subject-class
|
|
1206
|
+
* URIs (resolved via {@link subjectClassesOf}) must appear in
|
|
1207
|
+
* `inputTypes`. This is the concrete-type match the design doc's §5
|
|
1208
|
+
* spawn engine calls for; without it, a flow declaring
|
|
1209
|
+
* `inputTypes: ["Task"]` was previously *never* returned by
|
|
1210
|
+
* `availableFlows("some-task-uri")` — the entire point of typed
|
|
1211
|
+
* flows was silently unreachable (James PR #929 J#3).
|
|
1212
|
+
*
|
|
1213
|
+
* The expression is classified against the perspective's registered
|
|
1214
|
+
* classes only. An expression whose class is not registered on this
|
|
1215
|
+
* perspective matches no typed flow (absence, not falsehood — same
|
|
1216
|
+
* discipline as {@link subjectClassesOf}); typed flows requiring
|
|
1217
|
+
* unknown classes are still returned to their untyped-caller peers.
|
|
1218
|
+
*/
|
|
951
1219
|
async availableFlows(exprAddr) {
|
|
952
1220
|
const allFlowNames = await this.sdnaFlows();
|
|
1221
|
+
if (allFlowNames.length === 0)
|
|
1222
|
+
return [];
|
|
1223
|
+
const classesOf = await this.subjectClassesOf([exprAddr]);
|
|
1224
|
+
const exprClasses = classesOf[exprAddr] ?? [];
|
|
953
1225
|
const available = [];
|
|
954
1226
|
for (const name of allFlowNames) {
|
|
955
1227
|
const flow = await this.getFlow(name);
|
|
956
1228
|
if (!flow)
|
|
957
1229
|
continue;
|
|
958
|
-
if (flow.
|
|
1230
|
+
if (flow.inputTypes.length === 0 || flow.inputTypes.includes("any")) {
|
|
959
1231
|
available.push(name);
|
|
1232
|
+
continue;
|
|
960
1233
|
}
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
const pattern = flow.flowable;
|
|
964
|
-
const source = pattern.source || exprAddr;
|
|
965
|
-
const links = await this.get(new LinkQuery({
|
|
966
|
-
source,
|
|
967
|
-
predicate: pattern.predicate,
|
|
968
|
-
target: pattern.target
|
|
969
|
-
}));
|
|
970
|
-
if (links.length > 0) {
|
|
971
|
-
available.push(name);
|
|
972
|
-
}
|
|
1234
|
+
if (exprClasses.some(cls => flow.inputTypes.includes(cls))) {
|
|
1235
|
+
available.push(name);
|
|
973
1236
|
}
|
|
974
1237
|
}
|
|
975
1238
|
return available;
|
|
976
1239
|
}
|
|
977
|
-
/** Starts the Social DNA flow @param flowName on the expression @param exprAddr */
|
|
978
|
-
async startFlow(flowName, exprAddr) {
|
|
979
|
-
const flow = await this.getFlow(flowName);
|
|
980
|
-
if (!flow)
|
|
981
|
-
throw `Flow "${flowName}" not found`;
|
|
982
|
-
if (flow.startAction.length === 0)
|
|
983
|
-
throw `Flow "${flowName}" has no start action`;
|
|
984
|
-
await this.executeAction(flow.startAction, exprAddr, undefined);
|
|
985
|
-
}
|
|
986
|
-
/** Returns all expressions in the given state of given Social DNA flow */
|
|
987
|
-
async expressionsInFlowState(flowName, flowState) {
|
|
988
|
-
const flow = await this.getFlow(flowName);
|
|
989
|
-
if (!flow)
|
|
990
|
-
return [];
|
|
991
|
-
// Find the state with the matching value
|
|
992
|
-
const state = flow.states.find(s => s.value === flowState);
|
|
993
|
-
if (!state)
|
|
994
|
-
return [];
|
|
995
|
-
// Query for expressions matching this state's check pattern
|
|
996
|
-
const pattern = state.stateCheck;
|
|
997
|
-
const links = await this.get(new LinkQuery({
|
|
998
|
-
predicate: pattern.predicate,
|
|
999
|
-
target: pattern.target
|
|
1000
|
-
}));
|
|
1001
|
-
// Return the sources (expression addresses) - use source if pattern has no explicit source
|
|
1002
|
-
return links.map(l => pattern.source ? l.data.target : l.data.source);
|
|
1003
|
-
}
|
|
1004
|
-
/** Returns the given expression's flow state with regard to given Social DNA flow */
|
|
1005
|
-
async flowState(flowName, exprAddr) {
|
|
1006
|
-
const flow = await this.getFlow(flowName);
|
|
1007
|
-
if (!flow)
|
|
1008
|
-
throw `Flow "${flowName}" not found`;
|
|
1009
|
-
// Check each state to find which one the expression is in
|
|
1010
|
-
for (const state of flow.states) {
|
|
1011
|
-
const pattern = state.stateCheck;
|
|
1012
|
-
const source = pattern.source || exprAddr;
|
|
1013
|
-
const links = await this.get(new LinkQuery({
|
|
1014
|
-
source,
|
|
1015
|
-
predicate: pattern.predicate,
|
|
1016
|
-
target: pattern.target
|
|
1017
|
-
}));
|
|
1018
|
-
if (links.length > 0)
|
|
1019
|
-
return state.value;
|
|
1020
|
-
}
|
|
1021
|
-
throw `Expression "${exprAddr}" is not in any state of flow "${flowName}"`;
|
|
1022
|
-
}
|
|
1023
|
-
/** Returns available action names, with regard to Social DNA flow and expression's flow state */
|
|
1024
|
-
async flowActions(flowName, exprAddr) {
|
|
1025
|
-
const flow = await this.getFlow(flowName);
|
|
1026
|
-
if (!flow)
|
|
1027
|
-
return [];
|
|
1028
|
-
// Determine current state
|
|
1029
|
-
let currentStateName = null;
|
|
1030
|
-
for (const state of flow.states) {
|
|
1031
|
-
const pattern = state.stateCheck;
|
|
1032
|
-
const source = pattern.source || exprAddr;
|
|
1033
|
-
const links = await this.get(new LinkQuery({
|
|
1034
|
-
source,
|
|
1035
|
-
predicate: pattern.predicate,
|
|
1036
|
-
target: pattern.target
|
|
1037
|
-
}));
|
|
1038
|
-
if (links.length > 0) {
|
|
1039
|
-
currentStateName = state.name;
|
|
1040
|
-
break;
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
if (!currentStateName)
|
|
1044
|
-
return [];
|
|
1045
|
-
// Return transitions available from current state
|
|
1046
|
-
return flow.transitions
|
|
1047
|
-
.filter(t => t.fromState === currentStateName)
|
|
1048
|
-
.map(t => t.actionName);
|
|
1049
|
-
}
|
|
1050
|
-
/** Runs given Social DNA flow action */
|
|
1051
|
-
async runFlowAction(flowName, exprAddr, actionName) {
|
|
1052
|
-
const flow = await this.getFlow(flowName);
|
|
1053
|
-
if (!flow)
|
|
1054
|
-
throw `Flow "${flowName}" not found`;
|
|
1055
|
-
const transition = flow.transitions.find(t => t.actionName === actionName);
|
|
1056
|
-
if (!transition)
|
|
1057
|
-
throw `Action "${actionName}" not found in flow "${flowName}"`;
|
|
1058
|
-
await this.executeAction(transition.actions, exprAddr, undefined);
|
|
1059
|
-
}
|
|
1060
1240
|
/** Returns the perspective's Social DNA code
|
|
1061
1241
|
* This will return all SDNA code elements in an array.
|
|
1062
1242
|
*/
|
|
@@ -1236,111 +1416,45 @@ export class PerspectiveProxy {
|
|
|
1236
1416
|
await this.addLinks(allLinks);
|
|
1237
1417
|
}
|
|
1238
1418
|
/**
|
|
1239
|
-
* Retrieve a SHACL shape by name from this Perspective
|
|
1419
|
+
* Retrieve a SHACL shape by name from this Perspective (one RPC call).
|
|
1420
|
+
* The executor resolves the full shape (including property sub-shapes)
|
|
1421
|
+
* in-process and returns link triples for client-side reconstruction.
|
|
1240
1422
|
*/
|
|
1241
1423
|
async getShacl(name) {
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
const shapeUriLinks = await this.get(new LinkQuery({
|
|
1245
|
-
source: nameMapping.toUrl(),
|
|
1246
|
-
predicate: "ad4m://shacl_shape_uri"
|
|
1247
|
-
}));
|
|
1248
|
-
if (shapeUriLinks.length === 0) {
|
|
1424
|
+
const result = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").getShacl(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, name);
|
|
1425
|
+
if (!result)
|
|
1249
1426
|
return null;
|
|
1250
|
-
|
|
1251
|
-
const shapeUri = shapeUriLinks[0].data.target;
|
|
1252
|
-
// First get property shape URIs so we can query everything in one go
|
|
1253
|
-
const propertyLinks = await this.get(new LinkQuery({
|
|
1254
|
-
source: shapeUri,
|
|
1255
|
-
predicate: "sh://property"
|
|
1256
|
-
}));
|
|
1257
|
-
// Fetch all links from the shape and its property shapes. These reads are
|
|
1258
|
-
// independent of each other, so fire them concurrently rather than one RPC
|
|
1259
|
-
// round trip at a time — over a remote (non-loopback) connection, a shape with
|
|
1260
|
-
// a dozen properties otherwise pays a dozen sequential round trips just to load.
|
|
1261
|
-
const sourceUris = [shapeUri, ...propertyLinks.map(l => l.data.target)];
|
|
1262
|
-
const linksByUri = await Promise.all(sourceUris.map(uri => this.get(new LinkQuery({ source: uri }))));
|
|
1263
|
-
// Dedupe by (source, predicate, target): a perspective that's accumulated duplicate
|
|
1264
|
-
// SDNA links (e.g. from repeated registration attempts, or executor-side sync bugs)
|
|
1265
|
-
// would otherwise feed the same triple into SHACLShape.fromLinks more than once —
|
|
1266
|
-
// harmless for scalar fields like targetClass (first match wins) but can surface as
|
|
1267
|
-
// visibly duplicated properties for repeated sh://property links. Cheap: this is an
|
|
1268
|
-
// in-memory pass over data already fetched, no extra round trips.
|
|
1269
|
-
const seenLinks = new Set();
|
|
1270
|
-
const allLinks = [];
|
|
1271
|
-
for (const links of linksByUri) {
|
|
1272
|
-
for (const l of links) {
|
|
1273
|
-
const key = `${l.data.source} ${l.data.predicate} ${l.data.target}`;
|
|
1274
|
-
if (seenLinks.has(key))
|
|
1275
|
-
continue;
|
|
1276
|
-
seenLinks.add(key);
|
|
1277
|
-
allLinks.push({
|
|
1278
|
-
source: l.data.source,
|
|
1279
|
-
predicate: l.data.predicate,
|
|
1280
|
-
target: l.data.target
|
|
1281
|
-
});
|
|
1282
|
-
}
|
|
1283
|
-
}
|
|
1284
|
-
const shapeLinks = allLinks;
|
|
1285
|
-
return SHACLShape.fromLinks(shapeLinks, shapeUri);
|
|
1427
|
+
return SHACLShape.fromLinks(result.links, result.shapeUri);
|
|
1286
1428
|
}
|
|
1287
1429
|
/**
|
|
1288
|
-
* List the names of every SHACL shape stored in this Perspective
|
|
1289
|
-
* each shape's full definition (properties, target class, etc.) — just the cheap
|
|
1290
|
-
* `ad4m://has_shacl` enumeration, one round trip regardless of how many shapes exist.
|
|
1291
|
-
* Use this to check which shapes are actually worth resolving via `getShacl()` before
|
|
1292
|
-
* paying for each one's full (multi-round-trip) fetch.
|
|
1430
|
+
* List the names of every SHACL shape stored in this Perspective (one RPC call).
|
|
1293
1431
|
*/
|
|
1294
1432
|
async getShaclNames() {
|
|
1295
|
-
|
|
1296
|
-
source: "ad4m://self",
|
|
1297
|
-
predicate: "ad4m://has_shacl"
|
|
1298
|
-
}));
|
|
1299
|
-
// Dedupe: a perspective with duplicate `has_shacl` links (see the dedup note in
|
|
1300
|
-
// getShacl()) would otherwise report the same name more than once, causing callers
|
|
1301
|
-
// to redundantly resolve (or redundantly disambiguate) it multiple times.
|
|
1302
|
-
const names = nameLinks.map((nameLink) => {
|
|
1303
|
-
const name = Literal.fromUrl(nameLink.data.target).get();
|
|
1304
|
-
return name.replace('shacl://', '');
|
|
1305
|
-
});
|
|
1306
|
-
return [...new Set(names)];
|
|
1433
|
+
return __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").getShaclNames(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
1307
1434
|
}
|
|
1308
1435
|
/**
|
|
1309
|
-
* Resolve
|
|
1310
|
-
*
|
|
1311
|
-
* `
|
|
1312
|
-
*
|
|
1313
|
-
*
|
|
1314
|
-
*
|
|
1436
|
+
* Resolve a shape's `sh:targetClass` by name (one RPC call).
|
|
1437
|
+
*
|
|
1438
|
+
* `PerspectiveClient.getShaclTargetClass` now returns `undefined` on
|
|
1439
|
+
* "not found" already (see review r3897752023 — the null→undefined
|
|
1440
|
+
* coercion used to happen here and be duplicated one layer down),
|
|
1441
|
+
* so this method is a pure passthrough.
|
|
1315
1442
|
*/
|
|
1316
1443
|
async getShaclTargetClass(name) {
|
|
1317
|
-
|
|
1318
|
-
const shapeUriLinks = await this.get(new LinkQuery({
|
|
1319
|
-
source: nameMapping.toUrl(),
|
|
1320
|
-
predicate: "ad4m://shacl_shape_uri"
|
|
1321
|
-
}));
|
|
1322
|
-
if (shapeUriLinks.length === 0) {
|
|
1323
|
-
return undefined;
|
|
1324
|
-
}
|
|
1325
|
-
const shapeUri = shapeUriLinks[0].data.target;
|
|
1326
|
-
const shapeOwnLinks = await this.get(new LinkQuery({ source: shapeUri }));
|
|
1327
|
-
return shapeOwnLinks.find(l => l.data.predicate === "sh://targetClass")?.data.target;
|
|
1444
|
+
return __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").getShaclTargetClass(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid, name);
|
|
1328
1445
|
}
|
|
1329
1446
|
/**
|
|
1330
|
-
* Get all SHACL shapes stored in this Perspective
|
|
1447
|
+
* Get all SHACL shapes stored in this Perspective (one RPC call).
|
|
1448
|
+
* The executor resolves all shapes in-process and returns them in bulk.
|
|
1331
1449
|
*/
|
|
1332
1450
|
async getAllShacl() {
|
|
1333
|
-
const
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
const shape = await this.getShacl(shapeName);
|
|
1341
|
-
return shape ? { name: shapeName, shape } : null;
|
|
1342
|
-
}));
|
|
1343
|
-
return results.filter((s) => s !== null);
|
|
1451
|
+
const entries = await __classPrivateFieldGet(this, _PerspectiveProxy_client, "f").getAllShacl(__classPrivateFieldGet(this, _PerspectiveProxy_handle, "f").uuid);
|
|
1452
|
+
return entries
|
|
1453
|
+
.map(({ name, shapeUri, links }) => {
|
|
1454
|
+
const shape = SHACLShape.fromLinks(links, shapeUri);
|
|
1455
|
+
return shape ? { name, shape } : null;
|
|
1456
|
+
})
|
|
1457
|
+
.filter((s) => s !== null);
|
|
1344
1458
|
}
|
|
1345
1459
|
/**
|
|
1346
1460
|
* **Recommended way to add Flow definitions.**
|
|
@@ -1355,28 +1469,26 @@ export class PerspectiveProxy {
|
|
|
1355
1469
|
* ```typescript
|
|
1356
1470
|
* import { SHACLFlow } from '@coasys/ad4m';
|
|
1357
1471
|
*
|
|
1358
|
-
* const
|
|
1359
|
-
*
|
|
1360
|
-
*
|
|
1361
|
-
*
|
|
1362
|
-
*
|
|
1363
|
-
*
|
|
1364
|
-
*
|
|
1365
|
-
*
|
|
1366
|
-
*
|
|
1367
|
-
*
|
|
1368
|
-
*
|
|
1369
|
-
*
|
|
1370
|
-
*
|
|
1371
|
-
*
|
|
1372
|
-
*
|
|
1373
|
-
*
|
|
1374
|
-
*
|
|
1375
|
-
*
|
|
1376
|
-
* ]
|
|
1377
|
-
* });
|
|
1472
|
+
* const deliveryFlow = new SHACLFlow('Delivery', 'delivery://');
|
|
1473
|
+
* deliveryFlow.inputTypes = ['Task'];
|
|
1474
|
+
* deliveryFlow.interpretationHint =
|
|
1475
|
+
* 'Advance a Task through delivery: Identified → Scoped → InProgress → Review → Done.';
|
|
1476
|
+
*
|
|
1477
|
+
* deliveryFlow.addState({ name: 'Identified', value: 0 });
|
|
1478
|
+
* deliveryFlow.addState({ name: 'Scoped', value: 1 });
|
|
1479
|
+
* deliveryFlow.addState({ name: 'InProgress', value: 2 });
|
|
1480
|
+
* deliveryFlow.addState({ name: 'Review', value: 3 });
|
|
1481
|
+
* deliveryFlow.addState({ name: 'Done', value: 4 });
|
|
1482
|
+
*
|
|
1483
|
+
* deliveryFlow.addTransition({ actionName: 'Scope', fromState: 'Identified', toState: 'Scoped', actions: [] });
|
|
1484
|
+
* deliveryFlow.addTransition({ actionName: 'Start', fromState: 'Scoped', toState: 'InProgress', actions: [] });
|
|
1485
|
+
* deliveryFlow.addTransition({ actionName: 'Submit', fromState: 'InProgress', toState: 'Review', actions: [] });
|
|
1486
|
+
* deliveryFlow.addTransition({ actionName: 'Accept', fromState: 'Review', toState: 'Done', actions: [] });
|
|
1487
|
+
*
|
|
1488
|
+
* // Optional: n distinct DIDs must co-sign a proposal before it fires.
|
|
1489
|
+
* deliveryFlow.consensusRule = { n: 2 };
|
|
1378
1490
|
*
|
|
1379
|
-
* await perspective.addFlow('
|
|
1491
|
+
* await perspective.addFlow('Delivery', deliveryFlow);
|
|
1380
1492
|
* ```
|
|
1381
1493
|
*/
|
|
1382
1494
|
async addFlow(name, flow) {
|
|
@@ -1421,7 +1533,7 @@ export class PerspectiveProxy {
|
|
|
1421
1533
|
return null;
|
|
1422
1534
|
}
|
|
1423
1535
|
const flowUri = flowUriLinks[0].data.target;
|
|
1424
|
-
// Fetch flow-level links (hasState, hasTransition,
|
|
1536
|
+
// Fetch flow-level links (hasState, hasTransition, startAction, inputTypes/outputTypes/…)
|
|
1425
1537
|
const flowLevelLinks = await this.get(new LinkQuery({ source: flowUri }));
|
|
1426
1538
|
// Collect state and transition URIs, then fetch their child links
|
|
1427
1539
|
const childUris = flowLevelLinks
|
|
@@ -1487,7 +1599,9 @@ export class PerspectiveProxy {
|
|
|
1487
1599
|
* with the properties of the subject class.
|
|
1488
1600
|
* @param exprAddr The address of the expression to be turned into a subject instance
|
|
1489
1601
|
* @param initialValues Optional initial values for properties. If provided, these will be
|
|
1490
|
-
* merged with constructor actions for better performance.
|
|
1602
|
+
* merged with constructor actions for better performance. A collection property accepts
|
|
1603
|
+
* an array value and stores one entry per element; scalar properties store arrays/objects
|
|
1604
|
+
* as a single JSON value.
|
|
1491
1605
|
* @param batchId Optional batch ID for grouping operations. If provided, returns the expression address
|
|
1492
1606
|
* instead of the subject proxy since the subject won't exist until the batch is committed.
|
|
1493
1607
|
* @returns A proxy object for the created subject, or just the expression address if in batch mode
|