@coasys/ad4m 0.13.1-staging.1 → 0.13.1-staging.3
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 +4199 -1221
- package/lib/index.js +4189 -1222
- package/lib/src/Ad4mClient.d.ts +7 -0
- package/lib/src/Ad4mClient.js +9 -0
- package/lib/src/apiClient.d.ts +13 -0
- package/lib/src/apiClient.js +67 -12
- package/lib/src/generated/api/AgentsByDidsRequest.d.ts +3 -0
- package/lib/src/generated/api/AuthInfo.d.ts +4 -0
- package/lib/src/generated/api/CallSessionInfo.d.ts +23 -0
- package/lib/src/generated/api/DiscardBatchRequest.d.ts +3 -0
- package/lib/src/generated/api/Events.d.ts +13 -3
- package/lib/src/generated/api/Events.js +1 -0
- package/lib/src/generated/api/FlowStateChangedEvent.d.ts +38 -0
- package/lib/src/generated/api/FlowStateEntry.d.ts +18 -0
- package/lib/src/generated/api/FlowStateEntry.js +2 -0
- package/lib/src/generated/api/IceServer.d.ts +18 -0
- package/lib/src/generated/api/IceServer.js +2 -0
- package/lib/src/generated/api/OnlineAgent.d.ts +4 -0
- package/lib/src/generated/api/PerspectiveDiscardBatchParams.d.ts +4 -0
- package/lib/src/generated/api/PerspectiveDiscardBatchParams.js +2 -0
- package/lib/src/generated/api/PerspectiveFlowFiredParams.d.ts +8 -0
- package/lib/src/generated/api/PerspectiveFlowFiredParams.js +2 -0
- package/lib/src/generated/api/PerspectiveFlowStatesParams.d.ts +11 -0
- package/lib/src/generated/api/PerspectiveFlowStatesParams.js +2 -0
- package/lib/src/generated/api/PerspectiveGetAllShaclParams.d.ts +7 -0
- package/lib/src/generated/api/PerspectiveGetAllShaclParams.js +2 -0
- package/lib/src/generated/api/PerspectiveModelQueryParams.d.ts +6 -1
- package/lib/src/generated/api/PerspectiveRemoveSubjectParams.d.ts +6 -0
- package/lib/src/generated/api/PerspectiveRemoveSubjectParams.js +2 -0
- package/lib/src/generated/api/PerspectiveResynced.d.ts +8 -0
- package/lib/src/generated/api/PerspectiveResynced.js +2 -0
- package/lib/src/generated/api/PerspectiveSubscribed.d.ts +10 -0
- package/lib/src/generated/api/PerspectiveSubscribed.js +2 -0
- package/lib/src/generated/api/PerspectiveUpdateSubjectParams.d.ts +10 -0
- package/lib/src/generated/api/PerspectiveUpdateSubjectParams.js +2 -0
- package/lib/src/generated/api/QuerySubscriptionUpdate.d.ts +19 -0
- package/lib/src/generated/api/QuerySubscriptionUpdate.js +2 -0
- package/lib/src/generated/api/QuerySubscriptionUpdateEvent.d.ts +7 -0
- package/lib/src/generated/api/QuerySubscriptionUpdateEvent.js +1 -0
- package/lib/src/generated/api/QueryUpdatesLagged.d.ts +7 -0
- package/lib/src/generated/api/QueryUpdatesLagged.js +2 -0
- package/lib/src/generated/api/RemoveSubjectRequest.d.ts +9 -0
- package/lib/src/generated/api/RemoveSubjectRequest.js +2 -0
- package/lib/src/generated/api/ResyncSubscriptionRequest.d.ts +3 -0
- package/lib/src/generated/api/ResyncSubscriptionRequest.js +2 -0
- package/lib/src/generated/api/RpcMethods.d.ts +134 -14
- package/lib/src/generated/api/RpcMethods.js +12 -0
- package/lib/src/generated/api/RuntimeInfo.d.ts +5 -0
- package/lib/src/generated/api/SfuAddIceCandidateParams.d.ts +8 -0
- package/lib/src/generated/api/SfuAddIceCandidateParams.js +2 -0
- package/lib/src/generated/api/SfuAnswerServerOfferParams.d.ts +8 -0
- package/lib/src/generated/api/SfuAnswerServerOfferParams.js +2 -0
- package/lib/src/generated/api/SfuCallJoinParams.d.ts +14 -0
- package/lib/src/generated/api/SfuCallJoinParams.js +2 -0
- package/lib/src/generated/api/SfuCallRenegotiationOffer.d.ts +30 -0
- package/lib/src/generated/api/SfuCallRenegotiationOffer.js +1 -0
- package/lib/src/generated/api/SfuCascadePipe.d.ts +4 -0
- package/lib/src/generated/api/SfuCascadePipe.js +2 -0
- package/lib/src/generated/api/SfuCascadeStatus.d.ts +8 -0
- package/lib/src/generated/api/SfuCascadeStatus.js +1 -0
- package/lib/src/generated/api/SfuConfig.d.ts +52 -0
- package/lib/src/generated/api/SfuConfig.js +1 -0
- package/lib/src/generated/api/SfuDataMessage.d.ts +24 -0
- package/lib/src/generated/api/SfuDataMessage.js +2 -0
- package/lib/src/generated/api/SfuEnsureMembershipParams.d.ts +4 -0
- package/lib/src/generated/api/SfuEnsureMembershipParams.js +2 -0
- package/lib/src/generated/api/SfuMigrateEvent.d.ts +21 -0
- package/lib/src/generated/api/SfuMigrateEvent.js +2 -0
- package/lib/src/generated/api/SfuNeighbourhoodParams.d.ts +3 -0
- package/lib/src/generated/api/SfuNeighbourhoodParams.js +2 -0
- package/lib/src/generated/api/SfuParticipantQualityPreference.d.ts +7 -0
- package/lib/src/generated/api/SfuParticipantQualityPreference.js +2 -0
- package/lib/src/generated/api/SfuPerspectiveParams.d.ts +6 -0
- package/lib/src/generated/api/SfuPerspectiveParams.js +2 -0
- package/lib/src/generated/api/SfuQualityPreferenceParams.d.ts +8 -0
- package/lib/src/generated/api/SfuQualityPreferenceParams.js +2 -0
- package/lib/src/generated/api/SfuRoomInfo.d.ts +11 -0
- package/lib/src/generated/api/SfuRoomInfo.js +1 -0
- package/lib/src/generated/api/SfuRoomParams.d.ts +4 -0
- package/lib/src/generated/api/SfuRoomParams.js +2 -0
- package/lib/src/generated/api/SfuRoomParticipantInfo.d.ts +11 -0
- package/lib/src/generated/api/SfuRoomParticipantInfo.js +2 -0
- package/lib/src/generated/api/SfuRoomRoster.d.ts +13 -0
- package/lib/src/generated/api/SfuRoomRoster.js +2 -0
- package/lib/src/generated/api/SfuSendDataParams.d.ts +10 -0
- package/lib/src/generated/api/SfuSendDataParams.js +2 -0
- package/lib/src/generated/api/SfuSetConfigParams.d.ts +5 -0
- package/lib/src/generated/api/SfuSetConfigParams.js +1 -0
- package/lib/src/generated/api/SfuStatus.d.ts +24 -0
- package/lib/src/generated/api/SfuStatus.js +2 -0
- package/lib/src/generated/api/TrackMapEntry.d.ts +17 -0
- package/lib/src/generated/api/TrackMapEntry.js +2 -0
- package/lib/src/generated/api/UpdateSubjectRequest.d.ts +12 -0
- package/lib/src/generated/api/UpdateSubjectRequest.js +2 -0
- package/lib/src/generated/api/index.d.ts +3 -0
- package/lib/src/index.d.ts +8 -0
- package/lib/src/index.js +5 -0
- package/lib/src/model/Ad4mModel.d.ts +84 -0
- package/lib/src/model/Ad4mModel.js +279 -22
- package/lib/src/model/ModelQueryBuilder.d.ts +23 -38
- package/lib/src/model/ModelQueryBuilder.js +97 -274
- package/lib/src/model/decorators.d.ts +32 -0
- package/lib/src/model/decorators.js +40 -1
- package/lib/src/model/query-common.js +7 -1
- package/lib/src/model/shacl-gen.d.ts +3 -1
- package/lib/src/model/shacl-gen.js +13 -1
- package/lib/src/model/types.d.ts +52 -2
- package/lib/src/model/types.js +8 -0
- package/lib/src/neighbourhood/MeshManager.d.ts +384 -0
- package/lib/src/neighbourhood/MeshManager.js +1144 -0
- package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +91 -0
- package/lib/src/neighbourhood/NeighbourhoodClient.js +196 -0
- package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +55 -1
- package/lib/src/neighbourhood/NeighbourhoodProxy.js +170 -3
- package/lib/src/neighbourhood/Session.d.ts +105 -0
- package/lib/src/neighbourhood/Session.js +412 -0
- package/lib/src/neighbourhood/SfuManager.d.ts +174 -0
- package/lib/src/neighbourhood/SfuManager.js +619 -0
- package/lib/src/neighbourhood/SfuTypes.d.ts +35 -0
- package/lib/src/neighbourhood/SfuTypes.js +8 -0
- package/lib/src/perspectives/Container.d.ts +41 -0
- package/lib/src/perspectives/Container.js +62 -0
- package/lib/src/perspectives/FlowInstance.d.ts +63 -24
- package/lib/src/perspectives/FlowInstance.js +74 -31
- package/lib/src/perspectives/FlowModels.d.ts +0 -16
- package/lib/src/perspectives/FlowModels.js +8 -16
- package/lib/src/perspectives/LiveQuery.d.ts +49 -0
- package/lib/src/perspectives/LiveQuery.js +169 -0
- package/lib/src/perspectives/PerspectiveClient.d.ts +24 -15
- package/lib/src/perspectives/PerspectiveClient.js +33 -36
- package/lib/src/perspectives/PerspectiveProxy.d.ts +71 -168
- package/lib/src/perspectives/PerspectiveProxy.js +128 -476
- package/lib/src/perspectives/TextContent.d.ts +31 -0
- package/lib/src/perspectives/TextContent.js +52 -0
- package/lib/src/perspectives/WakerSubscriptionManager.d.ts +111 -6
- package/lib/src/perspectives/WakerSubscriptionManager.js +290 -48
- package/lib/src/runtime/RuntimeTypes.d.ts +2 -0
- package/lib/src/shacl/SHACLFlow.d.ts +7 -4
- package/lib/src/shacl/SHACLFlow.js +7 -4
- package/lib/src/shacl/SHACLShape.d.ts +9 -0
- package/lib/src/shacl/SHACLShape.js +37 -0
- package/package.json +2 -2
- package/pnpm-workspace.yaml +4 -1
- package/src/Ad4mClient.test.ts +90 -18
- package/src/Ad4mClient.ts +10 -0
- package/src/apiClient.test.ts +128 -2
- package/src/apiClient.ts +64 -11
- package/src/generated/api/AgentsByDidsRequest.ts +3 -0
- package/src/generated/api/AuthInfo.ts +6 -1
- package/src/generated/api/CallSessionInfo.ts +20 -0
- package/src/generated/api/DiscardBatchRequest.ts +3 -0
- package/src/generated/api/Events.ts +14 -3
- package/src/generated/api/FlowStateChangedEvent.ts +36 -0
- package/src/generated/api/FlowStateEntry.ts +18 -0
- package/src/generated/api/IceServer.ts +19 -0
- package/src/generated/api/OnlineAgent.ts +6 -1
- package/src/generated/api/PerspectiveDiscardBatchParams.ts +3 -0
- package/src/generated/api/PerspectiveFlowFiredParams.ts +7 -0
- package/src/generated/api/PerspectiveFlowStatesParams.ts +11 -0
- package/src/generated/api/PerspectiveGetAllShaclParams.ts +6 -0
- package/src/generated/api/PerspectiveModelQueryParams.ts +5 -1
- package/src/generated/api/PerspectiveRemoveSubjectParams.ts +3 -0
- package/src/generated/api/PerspectiveResynced.ts +7 -0
- package/src/generated/api/PerspectiveSubscribed.ts +8 -0
- package/src/generated/api/PerspectiveUpdateSubjectParams.ts +7 -0
- package/src/generated/api/QuerySubscriptionUpdate.ts +10 -0
- package/src/generated/api/QuerySubscriptionUpdateEvent.ts +9 -0
- package/src/generated/api/QueryUpdatesLagged.ts +7 -0
- package/src/generated/api/RemoveSubjectRequest.ts +7 -0
- package/src/generated/api/ResyncSubscriptionRequest.ts +3 -0
- package/src/generated/api/RpcMethods.ts +68 -8
- package/src/generated/api/RuntimeInfo.ts +6 -1
- package/src/generated/api/SfuAddIceCandidateParams.ts +7 -0
- package/src/generated/api/SfuAnswerServerOfferParams.ts +7 -0
- package/src/generated/api/SfuCallJoinParams.ts +13 -0
- package/src/generated/api/SfuCallRenegotiationOffer.ts +29 -0
- package/src/generated/api/SfuCascadePipe.ts +3 -0
- package/src/generated/api/SfuCascadeStatus.ts +7 -0
- package/src/generated/api/SfuConfig.ts +53 -0
- package/src/generated/api/SfuDataMessage.ts +23 -0
- package/src/generated/api/SfuEnsureMembershipParams.ts +3 -0
- package/src/generated/api/SfuMigrateEvent.ts +20 -0
- package/src/generated/api/{KeepAliveQueryRequest.ts → SfuNeighbourhoodParams.ts} +1 -1
- package/src/generated/api/SfuParticipantQualityPreference.ts +6 -0
- package/src/generated/api/{PerspectiveSubscribeQueryResult.ts → SfuPerspectiveParams.ts} +4 -1
- package/src/generated/api/SfuQualityPreferenceParams.ts +7 -0
- package/src/generated/api/SfuRoomInfo.ts +7 -0
- package/src/generated/api/SfuRoomParams.ts +3 -0
- package/src/generated/api/SfuRoomParticipantInfo.ts +8 -0
- package/src/generated/api/SfuRoomRoster.ts +12 -0
- package/src/generated/api/SfuSendDataParams.ts +7 -0
- package/src/generated/api/SfuSetConfigParams.ts +4 -0
- package/src/generated/api/SfuStatus.ts +24 -0
- package/src/generated/api/TrackMapEntry.ts +18 -0
- package/src/generated/api/UpdateSubjectRequest.ts +10 -0
- package/src/generated/api/index.ts +3 -0
- package/src/index.ts +8 -0
- package/src/model/Ad4mModel.test.ts +255 -231
- package/src/model/Ad4mModel.ts +322 -23
- package/src/model/ModelQueryBuilder.ts +112 -316
- package/src/model/abstract-classes.test.ts +225 -0
- package/src/model/containment-scope.test.ts +104 -0
- package/src/model/decorators.ts +81 -0
- package/src/model/query-common.ts +10 -1
- package/src/model/shacl-gen.ts +13 -0
- package/src/model/types.ts +63 -2
- package/src/neighbourhood/MeshManager.test.ts +2640 -0
- package/src/neighbourhood/MeshManager.ts +1350 -0
- package/src/neighbourhood/NeighbourhoodClient.ts +271 -0
- package/src/neighbourhood/NeighbourhoodProxy.test.ts +23 -0
- package/src/neighbourhood/NeighbourhoodProxy.ts +247 -1
- package/src/neighbourhood/Session.test.ts +800 -0
- package/src/neighbourhood/Session.ts +525 -0
- package/src/neighbourhood/SfuManager.test.ts +677 -0
- package/src/neighbourhood/SfuManager.ts +803 -0
- package/src/neighbourhood/SfuTypes.ts +40 -0
- package/src/perspectives/Container.test.ts +65 -0
- package/src/perspectives/Container.ts +46 -0
- package/src/perspectives/FlowInstance.ts +108 -31
- package/src/perspectives/FlowModels.ts +8 -18
- package/src/perspectives/LiveQuery.test.ts +197 -0
- package/src/perspectives/LiveQuery.ts +189 -0
- package/src/perspectives/PerspectiveClient.ts +51 -51
- package/src/perspectives/PerspectiveProxy.test.ts +93 -398
- package/src/perspectives/PerspectiveProxy.ts +133 -537
- package/src/perspectives/TextContent.test.ts +123 -0
- package/src/perspectives/TextContent.ts +36 -0
- package/src/perspectives/WakerSubscriptionManager.test.ts +421 -21
- package/src/perspectives/WakerSubscriptionManager.ts +349 -62
- package/src/runtime/RuntimeTypes.ts +2 -0
- package/src/shacl/SHACLFlow.ts +7 -4
- package/src/shacl/SHACLShape.test.ts +2 -1
- package/src/shacl/SHACLShape.ts +49 -0
- package/lib/src/generated/api/KeepAliveQueryRequest.d.ts +0 -3
- package/lib/src/generated/api/PerspectiveModelSubscribeResult.d.ts +0 -7
- package/lib/src/generated/api/PerspectiveQuerySubscriptionFilter.d.ts +0 -6
- package/lib/src/generated/api/PerspectiveSubscribeQueryResult.d.ts +0 -4
- package/src/generated/api/PerspectiveModelSubscribeResult.ts +0 -6
- package/src/generated/api/PerspectiveQuerySubscriptionFilter.ts +0 -3
- /package/lib/src/generated/api/{KeepAliveQueryRequest.js → AgentsByDidsRequest.js} +0 -0
- /package/lib/src/generated/api/{PerspectiveModelSubscribeResult.js → CallSessionInfo.js} +0 -0
- /package/lib/src/generated/api/{PerspectiveQuerySubscriptionFilter.js → DiscardBatchRequest.js} +0 -0
- /package/lib/src/generated/api/{PerspectiveSubscribeQueryResult.js → FlowStateChangedEvent.js} +0 -0
package/lib/src/Ad4mClient.d.ts
CHANGED
|
@@ -38,6 +38,13 @@ export declare class Ad4mClient {
|
|
|
38
38
|
* handler.
|
|
39
39
|
*/
|
|
40
40
|
on<K extends EventName>(type: K, handler: (event: EventMap[K]) => void, filter?: EventFilter): () => void;
|
|
41
|
+
/**
|
|
42
|
+
* Call `callback` once when the executor refuses this client's token
|
|
43
|
+
* (expired, revoked, or no session). Every call then fails with a 401
|
|
44
|
+
* `RpcError` and the client stops reconnecting: log in again and build a
|
|
45
|
+
* new client. Returns a function that removes the callback.
|
|
46
|
+
*/
|
|
47
|
+
onAuthFailed(callback: (reason: string) => void): () => void;
|
|
41
48
|
/** Close all event connections and clear in-memory caches */
|
|
42
49
|
close(): void;
|
|
43
50
|
}
|
package/lib/src/Ad4mClient.js
CHANGED
|
@@ -95,6 +95,15 @@ export class Ad4mClient {
|
|
|
95
95
|
on(type, handler, filter) {
|
|
96
96
|
return __classPrivateFieldGet(this, _Ad4mClient_apiClient, "f").on(type, handler, filter);
|
|
97
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Call `callback` once when the executor refuses this client's token
|
|
100
|
+
* (expired, revoked, or no session). Every call then fails with a 401
|
|
101
|
+
* `RpcError` and the client stops reconnecting: log in again and build a
|
|
102
|
+
* new client. Returns a function that removes the callback.
|
|
103
|
+
*/
|
|
104
|
+
onAuthFailed(callback) {
|
|
105
|
+
return __classPrivateFieldGet(this, _Ad4mClient_apiClient, "f").onAuthFailed(callback);
|
|
106
|
+
}
|
|
98
107
|
/** Close all event connections and clear in-memory caches */
|
|
99
108
|
close() {
|
|
100
109
|
__classPrivateFieldGet(this, _Ad4mClient_agentClient, "f").clearByDidCache();
|
package/lib/src/apiClient.d.ts
CHANGED
|
@@ -47,6 +47,10 @@ export declare class ApiClient {
|
|
|
47
47
|
/** `on()` handlers by event type; a type with none has no entry. */
|
|
48
48
|
private _handlers;
|
|
49
49
|
private _reconnectCallbacks;
|
|
50
|
+
private _authFailedCallbacks;
|
|
51
|
+
/** Set once the executor refused the token: the reason. The client then
|
|
52
|
+
* never connects again; a new token needs a new client. */
|
|
53
|
+
private _authFailed;
|
|
50
54
|
private _hasConnectedOnce;
|
|
51
55
|
private _pendingCalls;
|
|
52
56
|
private _wsReconnectTimer;
|
|
@@ -61,7 +65,11 @@ export declare class ApiClient {
|
|
|
61
65
|
private _getWsUrl;
|
|
62
66
|
private _ensureWs;
|
|
63
67
|
private _onOpen;
|
|
68
|
+
/** `reason` is set when the executor asked to try again later; calls that fail carry it. */
|
|
64
69
|
private _onClose;
|
|
70
|
+
/** The executor refused the token: fail every call with 401, stop
|
|
71
|
+
* reconnecting and tell the `onAuthFailed` callbacks, once. */
|
|
72
|
+
private _failAuth;
|
|
65
73
|
private _startPing;
|
|
66
74
|
private _stopPing;
|
|
67
75
|
private _scheduleReconnect;
|
|
@@ -102,6 +110,11 @@ export declare class ApiClient {
|
|
|
102
110
|
* Does NOT fire on the initial connection — only on reconnects.
|
|
103
111
|
* Returns an unsubscribe function. */
|
|
104
112
|
onReconnect(callback: () => void): () => void;
|
|
113
|
+
/** Register a callback that fires once when the executor refuses this
|
|
114
|
+
* client's token: a 401 reply, or a socket closed with code 1008. Every
|
|
115
|
+
* call then fails with a 401 `RpcError` and the client does not reconnect;
|
|
116
|
+
* build a new client to use another token. Returns an unsubscribe function. */
|
|
117
|
+
onAuthFailed(callback: (reason: string) => void): () => void;
|
|
105
118
|
/** Close the WebSocket and reject pending calls. */
|
|
106
119
|
closeAll(): void;
|
|
107
120
|
}
|
package/lib/src/apiClient.js
CHANGED
|
@@ -27,7 +27,12 @@ function nextId() {
|
|
|
27
27
|
* for the next socket is safe for writes too. This covers an executor that
|
|
28
28
|
* is still binding its port (about 1.5 s with the reconnect backoff). */
|
|
29
29
|
const MAX_CONNECT_ATTEMPTS = 3;
|
|
30
|
-
const closedError = () => new RpcError(503, 'WebSocket connection closed');
|
|
30
|
+
const closedError = (reason) => new RpcError(503, reason || 'WebSocket connection closed');
|
|
31
|
+
/** Close code for "try again later": the executor's wallet is locked, so it cannot check the
|
|
32
|
+
* token yet. The token may be good: reconnect as for any close, and pass the reason on. */
|
|
33
|
+
const CLOSE_TRY_AGAIN_LATER = 1013;
|
|
34
|
+
/** Close code the executor uses when the socket's token opens no session, expired or was revoked. */
|
|
35
|
+
const CLOSE_AUTH_FAILED = 1008;
|
|
31
36
|
export class ApiClient {
|
|
32
37
|
constructor(baseUrl, token, webSocketImpl, fetchImpl) {
|
|
33
38
|
// ── WebSocket ───────────────────────────────────────────────────────────
|
|
@@ -38,6 +43,10 @@ export class ApiClient {
|
|
|
38
43
|
/** `on()` handlers by event type; a type with none has no entry. */
|
|
39
44
|
this._handlers = new Map();
|
|
40
45
|
this._reconnectCallbacks = new Set();
|
|
46
|
+
this._authFailedCallbacks = new Set();
|
|
47
|
+
/** Set once the executor refused the token: the reason. The client then
|
|
48
|
+
* never connects again; a new token needs a new client. */
|
|
49
|
+
this._authFailed = null;
|
|
41
50
|
this._hasConnectedOnce = false;
|
|
42
51
|
this._pendingCalls = new Map();
|
|
43
52
|
this._wsReconnectTimer = null;
|
|
@@ -73,6 +82,8 @@ export class ApiClient {
|
|
|
73
82
|
_ensureWs() {
|
|
74
83
|
if (this._ws)
|
|
75
84
|
return;
|
|
85
|
+
if (this._authFailed !== null)
|
|
86
|
+
throw new RpcError(401, this._authFailed);
|
|
76
87
|
const WsImpl = this._webSocketImpl ?? globalThis.WebSocket;
|
|
77
88
|
const ws = new WsImpl(this._getWsUrl());
|
|
78
89
|
this._ws = ws;
|
|
@@ -81,9 +92,17 @@ export class ApiClient {
|
|
|
81
92
|
resolve();
|
|
82
93
|
this._onOpen(ws);
|
|
83
94
|
};
|
|
84
|
-
ws.onclose = () => {
|
|
85
|
-
|
|
86
|
-
|
|
95
|
+
ws.onclose = (event) => {
|
|
96
|
+
// Classify the close for watchApplied() as for every other waiting call.
|
|
97
|
+
reject(event?.code === CLOSE_AUTH_FAILED
|
|
98
|
+
? new RpcError(401, event.reason || 'token expired or revoked')
|
|
99
|
+
: closedError(event?.code === CLOSE_TRY_AGAIN_LATER ? event.reason : undefined));
|
|
100
|
+
if (event?.code === CLOSE_AUTH_FAILED && this._ws === ws) {
|
|
101
|
+
this._failAuth(event.reason || 'token expired or revoked');
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
this._onClose(ws, event?.code === CLOSE_TRY_AGAIN_LATER ? event.reason : undefined);
|
|
105
|
+
}
|
|
87
106
|
};
|
|
88
107
|
});
|
|
89
108
|
// Only watchApplied() awaits this; a close before open is not an error otherwise.
|
|
@@ -103,10 +122,15 @@ export class ApiClient {
|
|
|
103
122
|
if (!pending)
|
|
104
123
|
return; // late reply to a timed-out or aborted call, or a cancel ack
|
|
105
124
|
const error = parsed.error;
|
|
106
|
-
if (error)
|
|
107
|
-
pending.reject(new RpcError(error.code ?? 500, error.message ?? 'Unknown error'));
|
|
108
|
-
else
|
|
125
|
+
if (!error) {
|
|
109
126
|
pending.resolve(parsed.result);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const rpcError = new RpcError(error.code ?? 500, error.message ?? 'Unknown error');
|
|
130
|
+
pending.reject(rpcError);
|
|
131
|
+
// The executor answers 401 only when the token stopped working, then closes the socket.
|
|
132
|
+
if (rpcError.status === 401)
|
|
133
|
+
this._failAuth(rpcError.body);
|
|
110
134
|
return;
|
|
111
135
|
}
|
|
112
136
|
if (parsed.type === 'pong')
|
|
@@ -155,7 +179,8 @@ export class ApiClient {
|
|
|
155
179
|
}
|
|
156
180
|
this._hasConnectedOnce = true;
|
|
157
181
|
}
|
|
158
|
-
|
|
182
|
+
/** `reason` is set when the executor asked to try again later; calls that fail carry it. */
|
|
183
|
+
_onClose(ws, reason) {
|
|
159
184
|
// A socket closed by _closeWs() can report after a new one exists.
|
|
160
185
|
if (this._ws !== ws)
|
|
161
186
|
return;
|
|
@@ -170,12 +195,25 @@ export class ApiClient {
|
|
|
170
195
|
pending.retry = false;
|
|
171
196
|
}
|
|
172
197
|
else {
|
|
173
|
-
pending.reject(closedError());
|
|
198
|
+
pending.reject(closedError(reason));
|
|
174
199
|
}
|
|
175
200
|
}
|
|
176
201
|
if (this._handlers.size > 0 || this._pendingCalls.size > 0)
|
|
177
202
|
this._scheduleReconnect();
|
|
178
203
|
}
|
|
204
|
+
/** The executor refused the token: fail every call with 401, stop
|
|
205
|
+
* reconnecting and tell the `onAuthFailed` callbacks, once. */
|
|
206
|
+
_failAuth(reason) {
|
|
207
|
+
if (this._authFailed !== null)
|
|
208
|
+
return;
|
|
209
|
+
this._authFailed = reason;
|
|
210
|
+
const error = new RpcError(401, reason);
|
|
211
|
+
for (const pending of this._pendingCalls.values())
|
|
212
|
+
pending.reject(error);
|
|
213
|
+
this._closeWs();
|
|
214
|
+
for (const cb of [...this._authFailedCallbacks])
|
|
215
|
+
callSafely(cb, 'Error in auth-failed callback:', reason);
|
|
216
|
+
}
|
|
179
217
|
_startPing() {
|
|
180
218
|
this._stopPing();
|
|
181
219
|
this._wsPingTimer = setInterval(() => {
|
|
@@ -191,7 +229,7 @@ export class ApiClient {
|
|
|
191
229
|
}
|
|
192
230
|
}
|
|
193
231
|
_scheduleReconnect() {
|
|
194
|
-
if (this._wsReconnectTimer)
|
|
232
|
+
if (this._wsReconnectTimer || this._authFailed !== null)
|
|
195
233
|
return;
|
|
196
234
|
const delay = this._wsReconnectDelay;
|
|
197
235
|
this._wsReconnectDelay = Math.min(this._wsReconnectDelay * 2, MAX_RECONNECT_DELAY_MS);
|
|
@@ -291,7 +329,9 @@ export class ApiClient {
|
|
|
291
329
|
regs.add(reg);
|
|
292
330
|
this._scheduleWatch();
|
|
293
331
|
}
|
|
294
|
-
|
|
332
|
+
// A client whose token was refused keeps the handler but opens no socket.
|
|
333
|
+
if (this._authFailed === null)
|
|
334
|
+
this._ensureWs();
|
|
295
335
|
return () => {
|
|
296
336
|
const regs = this._handlers.get(type);
|
|
297
337
|
if (!regs?.delete(reg))
|
|
@@ -358,10 +398,13 @@ export class ApiClient {
|
|
|
358
398
|
if (key === this._watching)
|
|
359
399
|
return;
|
|
360
400
|
this._watching = key;
|
|
361
|
-
|
|
401
|
+
const sent = this._request('events.watch', events).then(() => { this._watchRetries = 0; }, (e) => {
|
|
362
402
|
if (this._watching !== key)
|
|
363
403
|
return;
|
|
364
404
|
this._watching = null;
|
|
405
|
+
// A refused token (401) gets no next socket: watchApplied() must not resolve.
|
|
406
|
+
if (e instanceof RpcError && e.status === 401)
|
|
407
|
+
throw e;
|
|
365
408
|
// A closed socket (503) gets the watch again when the next one opens.
|
|
366
409
|
if (e instanceof RpcError && e.status === 503)
|
|
367
410
|
return;
|
|
@@ -373,6 +416,9 @@ export class ApiClient {
|
|
|
373
416
|
}, WATCH_RETRY_DELAY_MS);
|
|
374
417
|
}
|
|
375
418
|
});
|
|
419
|
+
// Only watchApplied() awaits this; a refused watch is not an unhandled rejection otherwise.
|
|
420
|
+
sent.catch(() => { });
|
|
421
|
+
this._watchSent = sent;
|
|
376
422
|
}
|
|
377
423
|
_closeWs() {
|
|
378
424
|
this._stopPing();
|
|
@@ -396,6 +442,14 @@ export class ApiClient {
|
|
|
396
442
|
this._reconnectCallbacks.add(callback);
|
|
397
443
|
return () => { this._reconnectCallbacks.delete(callback); };
|
|
398
444
|
}
|
|
445
|
+
/** Register a callback that fires once when the executor refuses this
|
|
446
|
+
* client's token: a 401 reply, or a socket closed with code 1008. Every
|
|
447
|
+
* call then fails with a 401 `RpcError` and the client does not reconnect;
|
|
448
|
+
* build a new client to use another token. Returns an unsubscribe function. */
|
|
449
|
+
onAuthFailed(callback) {
|
|
450
|
+
this._authFailedCallbacks.add(callback);
|
|
451
|
+
return () => { this._authFailedCallbacks.delete(callback); };
|
|
452
|
+
}
|
|
399
453
|
/** Close the WebSocket and reject pending calls. */
|
|
400
454
|
closeAll() {
|
|
401
455
|
for (const pending of this._pendingCalls.values()) {
|
|
@@ -404,6 +458,7 @@ export class ApiClient {
|
|
|
404
458
|
this._closeWs();
|
|
405
459
|
this._handlers.clear();
|
|
406
460
|
this._reconnectCallbacks.clear();
|
|
461
|
+
this._authFailedCallbacks.clear();
|
|
407
462
|
// A reused client must not fire onReconnect on its next first open.
|
|
408
463
|
this._hasConnectedOnce = false;
|
|
409
464
|
}
|
|
@@ -6,5 +6,9 @@ export type AuthInfo = {
|
|
|
6
6
|
appUrl: string | null;
|
|
7
7
|
appIconPath: string | null;
|
|
8
8
|
capabilities: Array<Capability> | null;
|
|
9
|
+
/**
|
|
10
|
+
* The user a multi-user token is minted for: the login name of a managed agent's
|
|
11
|
+
* account. The token's `sub` carries the agent's DID; this stays as the account's name.
|
|
12
|
+
*/
|
|
9
13
|
userEmail: string | null;
|
|
10
14
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result of a `call_join` — SDP answer + optional cascade redirect +
|
|
3
|
+
* stream mapping for the joining peer.
|
|
4
|
+
*/
|
|
5
|
+
export type CallSessionInfo = {
|
|
6
|
+
roomName: string;
|
|
7
|
+
neighbourhoodUrl: string;
|
|
8
|
+
participantId: string;
|
|
9
|
+
sdpAnswer: string;
|
|
10
|
+
/**
|
|
11
|
+
* When set, the join was not served here: the caller should join this
|
|
12
|
+
* DID's SFU node instead (cascade load redirect). Only a `callJoin` with
|
|
13
|
+
* `acceptRedirect` gets one.
|
|
14
|
+
*/
|
|
15
|
+
redirectTo?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Roster of existing participants at join time, format:
|
|
18
|
+
* `"participantId:did"` (local) or `"remote-did:did"` (cascade).
|
|
19
|
+
* For track-to-DID attribution, use the `track_mapping` field on
|
|
20
|
+
* each renegotiation offer — the SDP mids are assigned there.
|
|
21
|
+
*/
|
|
22
|
+
streamMapping: Array<string>;
|
|
23
|
+
};
|
|
@@ -5,16 +5,21 @@ import type { Apps } from "./Apps";
|
|
|
5
5
|
import type { AutoProcessorEvent } from "./AutoProcessorEvent";
|
|
6
6
|
import type { AutoProcessorNeighbourhoodState } from "./AutoProcessorNeighbourhoodState";
|
|
7
7
|
import type { ExceptionOccurredEvent } from "./ExceptionOccurredEvent";
|
|
8
|
+
import type { FlowStateChangedEvent } from "./FlowStateChangedEvent";
|
|
8
9
|
import type { HostingUserInfo } from "./HostingUserInfo";
|
|
9
10
|
import type { MessageReceivedEvent } from "./MessageReceivedEvent";
|
|
10
11
|
import type { NeighbourhoodSignalFilter } from "./NeighbourhoodSignalFilter";
|
|
11
12
|
import type { NotificationTriggeredEvent } from "./NotificationTriggeredEvent";
|
|
12
13
|
import type { PerspectiveLinkUpdatedWithOwner } from "./PerspectiveLinkUpdatedWithOwner";
|
|
13
14
|
import type { PerspectiveLinkWithOwner } from "./PerspectiveLinkWithOwner";
|
|
14
|
-
import type { PerspectiveQuerySubscriptionFilter } from "./PerspectiveQuerySubscriptionFilter";
|
|
15
15
|
import type { PerspectiveRemovedWithOwner } from "./PerspectiveRemovedWithOwner";
|
|
16
16
|
import type { PerspectiveStateFilter } from "./PerspectiveStateFilter";
|
|
17
17
|
import type { PerspectiveWithOwner } from "./PerspectiveWithOwner";
|
|
18
|
+
import type { QuerySubscriptionUpdateEvent } from "./QuerySubscriptionUpdateEvent";
|
|
19
|
+
import type { SfuCallRenegotiationOffer } from "./SfuCallRenegotiationOffer";
|
|
20
|
+
import type { SfuDataMessage } from "./SfuDataMessage";
|
|
21
|
+
import type { SfuMigrateEvent } from "./SfuMigrateEvent";
|
|
22
|
+
import type { SfuRoomRoster } from "./SfuRoomRoster";
|
|
18
23
|
import type { TranscriptionTextFilter } from "./TranscriptionTextFilter";
|
|
19
24
|
/** Every event the executor emits: its payload (the message without `type`). */
|
|
20
25
|
export interface EventMap {
|
|
@@ -35,12 +40,17 @@ export interface EventMap {
|
|
|
35
40
|
"exception-occurred": ExceptionOccurredEvent;
|
|
36
41
|
"transcription-text": TranscriptionTextFilter;
|
|
37
42
|
"model-loading-status": AIModelLoadingStatus;
|
|
38
|
-
"query-subscription-update":
|
|
43
|
+
"query-subscription-update": QuerySubscriptionUpdateEvent;
|
|
39
44
|
"auto-processor-event": AutoProcessorEvent;
|
|
40
45
|
"auto-processor-neighbourhood-state": AutoProcessorNeighbourhoodState;
|
|
46
|
+
"sfu-call-renegotiation-offer": SfuCallRenegotiationOffer;
|
|
47
|
+
"sfu-migrate": SfuMigrateEvent;
|
|
48
|
+
"sfu-data": SfuDataMessage;
|
|
49
|
+
"sfu-room-roster": SfuRoomRoster;
|
|
50
|
+
"flow-state-changed": FlowStateChangedEvent;
|
|
41
51
|
}
|
|
42
52
|
export type EventName = keyof EventMap;
|
|
43
53
|
/** Events about one perspective: they carry `perspectiveUuid`. */
|
|
44
|
-
export type ScopedEventName = "perspective-added" | "perspective-removed" | "perspective-updated" | "sync-state-change" | "link-added" | "link-removed" | "link-updated" | "signal" | "notification-triggered" | "query-subscription-update" | "auto-processor-event" | "auto-processor-neighbourhood-state";
|
|
54
|
+
export type ScopedEventName = "perspective-added" | "perspective-removed" | "perspective-updated" | "sync-state-change" | "link-added" | "link-removed" | "link-updated" | "signal" | "notification-triggered" | "query-subscription-update" | "auto-processor-event" | "auto-processor-neighbourhood-state" | "flow-state-changed";
|
|
45
55
|
/** {@link ScopedEventName} as a set. */
|
|
46
56
|
export declare const SCOPED_EVENTS: ReadonlySet<EventName>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An instance's derived state moved, or an edge settled, on one agent's
|
|
3
|
+
* replica. Published once per change by that agent's pass, and delivered
|
|
4
|
+
* only to that agent's sockets.
|
|
5
|
+
*
|
|
6
|
+
* A catch-up pass (this agent's first over an instance here) publishes one
|
|
7
|
+
* too, with `caught_up` set: it reports no settles — whatever settled
|
|
8
|
+
* before this replica watched is not news — but it is the first state this
|
|
9
|
+
* agent's clients can show, and the only signal they get of it.
|
|
10
|
+
*/
|
|
11
|
+
export type FlowStateChangedEvent = {
|
|
12
|
+
perspectiveUuid: string;
|
|
13
|
+
/**
|
|
14
|
+
* The agent whose replica derived this. The delivery filter matches it
|
|
15
|
+
* against the socket's agent; nobody else receives the event.
|
|
16
|
+
*/
|
|
17
|
+
agentDid: string;
|
|
18
|
+
instance: string;
|
|
19
|
+
/**
|
|
20
|
+
* The state this agent had recorded before; for a seeded row, the
|
|
21
|
+
* flow's first state. `None` exactly when `caught_up`: this agent had no
|
|
22
|
+
* row, so its clients had no state to show (`currentStateName` is
|
|
23
|
+
* `undefined`), and naming the first state would claim a move nobody saw.
|
|
24
|
+
*/
|
|
25
|
+
from: string | null;
|
|
26
|
+
to: string;
|
|
27
|
+
/**
|
|
28
|
+
* Proposals this pass marked fired: the atoms of every edge that settled
|
|
29
|
+
* since the previous pass. Empty when the state moved without a new
|
|
30
|
+
* settle, e.g. back, after a vote was withdrawn — and on a catch-up,
|
|
31
|
+
* whose marks record history rather than report it.
|
|
32
|
+
*/
|
|
33
|
+
firedProposals: Array<string>;
|
|
34
|
+
/**
|
|
35
|
+
* This was the agent's first pass over the instance here.
|
|
36
|
+
*/
|
|
37
|
+
caughtUp: boolean;
|
|
38
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One row of this agent's bookkeeping, as `perspective.flowStates` returns
|
|
3
|
+
* it. An instance with no entry is one this agent has neither derived nor
|
|
4
|
+
* minted here: a client must not guess its state.
|
|
5
|
+
*/
|
|
6
|
+
export type FlowStateEntry = {
|
|
7
|
+
instance: string;
|
|
8
|
+
/**
|
|
9
|
+
* The state this agent's pass last derived. `None` for a row seeded at
|
|
10
|
+
* mint and not derived yet: the instance stands at its flow's first
|
|
11
|
+
* state, which only the flow definition names.
|
|
12
|
+
*/
|
|
13
|
+
currentState: string | null;
|
|
14
|
+
/**
|
|
15
|
+
* RFC 3339 time of the pass that last wrote this state; `None` with it.
|
|
16
|
+
*/
|
|
17
|
+
derivedAt: string | null;
|
|
18
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One ICE server entry as understood by browser `RTCConfiguration` —
|
|
3
|
+
* mirrors the WebIDL shape so clients can pass it through unchanged.
|
|
4
|
+
*/
|
|
5
|
+
export type IceServer = {
|
|
6
|
+
/**
|
|
7
|
+
* One or more URLs (`stun:`, `turn:`, `turns:`).
|
|
8
|
+
*/
|
|
9
|
+
urls: Array<string>;
|
|
10
|
+
/**
|
|
11
|
+
* TURN username, when applicable.
|
|
12
|
+
*/
|
|
13
|
+
username?: string;
|
|
14
|
+
/**
|
|
15
|
+
* TURN long-term credential, when applicable.
|
|
16
|
+
*/
|
|
17
|
+
credential?: string;
|
|
18
|
+
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { PerspectiveExpression } from "./PerspectiveExpression";
|
|
2
2
|
export type OnlineAgent = {
|
|
3
3
|
did: string;
|
|
4
|
+
/**
|
|
5
|
+
* Empty when the agent has not set a status: the link language reports
|
|
6
|
+
* such an agent with a `null` status.
|
|
7
|
+
*/
|
|
4
8
|
status: PerspectiveExpression;
|
|
5
9
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `perspective.flowStates`: the calling agent's recorded state of each flow
|
|
3
|
+
* instance (#1424). Instances it has not derived yet are absent.
|
|
4
|
+
*/
|
|
5
|
+
export type PerspectiveFlowStatesParams = {
|
|
6
|
+
uuid: string;
|
|
7
|
+
/**
|
|
8
|
+
* Narrow to these instance URIs; all of the agent's instances if absent.
|
|
9
|
+
*/
|
|
10
|
+
instances?: Array<string>;
|
|
11
|
+
};
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Wire names stay snake_case, as the handlers read them.
|
|
3
|
+
*
|
|
4
|
+
* Exactly one of `class_name` and `class_names`: one class, or one query over
|
|
5
|
+
* the union of several (#1238), whose rows carry `__subjectClass` and
|
|
6
|
+
* `__subjectClasses`.
|
|
3
7
|
*/
|
|
4
8
|
export type PerspectiveModelQueryParams = {
|
|
5
9
|
uuid: string;
|
|
6
|
-
class_name
|
|
10
|
+
class_name?: string;
|
|
11
|
+
class_names?: Array<string>;
|
|
7
12
|
query_json: string;
|
|
8
13
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reply to `perspective.subscribeQuery` / `perspective.modelSubscribe`:
|
|
3
|
+
* the first result, as JSON, at its revision (0 unless a change was
|
|
4
|
+
* published while it was computed).
|
|
5
|
+
*/
|
|
6
|
+
export type PerspectiveSubscribed = {
|
|
7
|
+
subscriptionId: string;
|
|
8
|
+
result: any;
|
|
9
|
+
revision: number;
|
|
10
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The change from revision `revision - 1` to `revision` (see
|
|
3
|
+
* `perspective_instance::subscriptions::result_delta`): model results
|
|
4
|
+
* carry `ids`, `upsert` and `totalCount`; query results carry `added` and
|
|
5
|
+
* `removed` rows; a result that could not be diffed comes whole as
|
|
6
|
+
* `result`.
|
|
7
|
+
*/
|
|
8
|
+
export type QuerySubscriptionUpdate = {
|
|
9
|
+
perspectiveUuid: string;
|
|
10
|
+
uuid: string;
|
|
11
|
+
subscriptionId: string;
|
|
12
|
+
revision: number;
|
|
13
|
+
ids?: Array<string>;
|
|
14
|
+
upsert?: Array<any>;
|
|
15
|
+
totalCount?: number;
|
|
16
|
+
added?: Array<any>;
|
|
17
|
+
removed?: Array<any>;
|
|
18
|
+
result?: any;
|
|
19
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { QuerySubscriptionUpdate } from "./QuerySubscriptionUpdate";
|
|
2
|
+
import type { QueryUpdatesLagged } from "./QueryUpdatesLagged";
|
|
3
|
+
/**
|
|
4
|
+
* `query-subscription-update`: one change to a live query, delivered only
|
|
5
|
+
* to the connection that opened it, or [`QueryUpdatesLagged`].
|
|
6
|
+
*/
|
|
7
|
+
export type QuerySubscriptionUpdateEvent = QuerySubscriptionUpdate | QueryUpdatesLagged;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|