@coasys/ad4m 0.13.1-staging.6 → 0.13.1-staging.7

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.
Files changed (174) hide show
  1. package/lib/index.cjs +1130 -650
  2. package/lib/index.js +1130 -651
  3. package/lib/src/Ad4mClient.d.ts +3 -0
  4. package/lib/src/Ad4mClient.js +9 -2
  5. package/lib/src/agent/Agent.d.ts +5 -1
  6. package/lib/src/agent/Agent.js +3 -0
  7. package/lib/src/agent/AgentClient.d.ts +3 -0
  8. package/lib/src/agent/AgentClient.js +3 -0
  9. package/lib/src/agent/AgentStatus.d.ts +2 -0
  10. package/lib/src/agent/AgentStatus.js +2 -0
  11. package/lib/src/apiClient.d.ts +41 -0
  12. package/lib/src/apiClient.js +138 -1
  13. package/lib/src/generated/api/AgentStatus.d.ts +5 -0
  14. package/lib/src/generated/api/AgentWithIdentity.d.ts +14 -0
  15. package/lib/src/generated/api/AgentWithIdentity.js +1 -0
  16. package/lib/src/generated/api/BotView.d.ts +7 -0
  17. package/lib/src/generated/api/BotView.js +2 -0
  18. package/lib/src/generated/api/ClaimOfferParams.d.ts +13 -0
  19. package/lib/src/generated/api/ClaimOfferParams.js +2 -0
  20. package/lib/src/generated/api/ClaimOfferResult.d.ts +14 -0
  21. package/lib/src/generated/api/ClaimOfferResult.js +1 -0
  22. package/lib/src/generated/api/ClaimView.d.ts +11 -0
  23. package/lib/src/generated/api/ClaimView.js +2 -0
  24. package/lib/src/generated/api/CosignInceptParams.d.ts +10 -0
  25. package/lib/src/generated/api/CosignInceptParams.js +1 -0
  26. package/lib/src/generated/api/DeviceView.d.ts +17 -0
  27. package/lib/src/generated/api/DeviceView.js +1 -0
  28. package/lib/src/generated/api/DidBotScope.d.ts +7 -0
  29. package/lib/src/generated/api/DidBotScope.js +2 -0
  30. package/lib/src/generated/api/DidDocument.d.ts +16 -0
  31. package/lib/src/generated/api/DidDocument.js +1 -0
  32. package/lib/src/generated/api/DidDocumentMetadata.d.ts +18 -0
  33. package/lib/src/generated/api/DidDocumentMetadata.js +2 -0
  34. package/lib/src/generated/api/DidResolutionMetadata.d.ts +51 -0
  35. package/lib/src/generated/api/DidResolutionMetadata.js +1 -0
  36. package/lib/src/generated/api/DidResolutionResult.d.ts +16 -0
  37. package/lib/src/generated/api/DidResolutionResult.js +1 -0
  38. package/lib/src/generated/api/DidVerificationMethod.d.ts +17 -0
  39. package/lib/src/generated/api/DidVerificationMethod.js +1 -0
  40. package/lib/src/generated/api/Events.d.ts +2 -0
  41. package/lib/src/generated/api/ForkRecord.d.ts +11 -0
  42. package/lib/src/generated/api/ForkRecord.js +2 -0
  43. package/lib/src/generated/api/IdentityForkEvent.d.ts +10 -0
  44. package/lib/src/generated/api/IdentityForkEvent.js +2 -0
  45. package/lib/src/generated/api/IdentityLog.d.ts +18 -0
  46. package/lib/src/generated/api/IdentityLog.js +1 -0
  47. package/lib/src/generated/api/IdentityStatus.d.ts +48 -0
  48. package/lib/src/generated/api/IdentityStatus.js +1 -0
  49. package/lib/src/generated/api/JoinStatus.d.ts +10 -0
  50. package/lib/src/generated/api/JoinStatus.js +2 -0
  51. package/lib/src/generated/api/JoinStatusParams.d.ts +6 -0
  52. package/lib/src/generated/api/JoinStatusParams.js +2 -0
  53. package/lib/src/generated/api/LogParams.d.ts +17 -0
  54. package/lib/src/generated/api/LogParams.js +2 -0
  55. package/lib/src/generated/api/Offer.d.ts +14 -0
  56. package/lib/src/generated/api/Offer.js +1 -0
  57. package/lib/src/generated/api/OfferKind.d.ts +4 -0
  58. package/lib/src/generated/api/OfferKind.js +2 -0
  59. package/lib/src/generated/api/OfferListing.d.ts +9 -0
  60. package/lib/src/generated/api/OfferListing.js +1 -0
  61. package/lib/src/generated/api/OfferOpened.d.ts +6 -0
  62. package/lib/src/generated/api/OfferOpened.js +2 -0
  63. package/lib/src/generated/api/OfferState.d.ts +21 -0
  64. package/lib/src/generated/api/OfferState.js +1 -0
  65. package/lib/src/generated/api/OffersParams.d.ts +11 -0
  66. package/lib/src/generated/api/OffersParams.js +1 -0
  67. package/lib/src/generated/api/OpenOfferParams.d.ts +7 -0
  68. package/lib/src/generated/api/OpenOfferParams.js +1 -0
  69. package/lib/src/generated/api/PublishParams.d.ts +11 -0
  70. package/lib/src/generated/api/PublishParams.js +1 -0
  71. package/lib/src/generated/api/RequestBody.d.ts +15 -0
  72. package/lib/src/generated/api/RequestBody.js +2 -0
  73. package/lib/src/generated/api/ResetLogParams.d.ts +9 -0
  74. package/lib/src/generated/api/ResetLogParams.js +2 -0
  75. package/lib/src/generated/api/ResolveParams.d.ts +18 -0
  76. package/lib/src/generated/api/ResolveParams.js +2 -0
  77. package/lib/src/generated/api/RpcMethods.d.ts +68 -1
  78. package/lib/src/generated/api/RpcMethods.js +6 -0
  79. package/lib/src/generated/api/SignedBy.d.ts +8 -0
  80. package/lib/src/generated/api/SignedBy.js +2 -0
  81. package/lib/src/generated/api/SignedHead.d.ts +14 -0
  82. package/lib/src/generated/api/SignedHead.js +2 -0
  83. package/lib/src/generated/api/SignedOffer.d.ts +10 -0
  84. package/lib/src/generated/api/SignedOffer.js +1 -0
  85. package/lib/src/generated/api/SignedRequest.d.ts +8 -0
  86. package/lib/src/generated/api/SignedRequest.js +1 -0
  87. package/lib/src/generated/api/SkippedSource.d.ts +7 -0
  88. package/lib/src/generated/api/SkippedSource.js +2 -0
  89. package/lib/src/generated/api/StoreBehind.d.ts +13 -0
  90. package/lib/src/generated/api/StoreBehind.js +2 -0
  91. package/lib/src/generated/api/StoreInfo.d.ts +15 -0
  92. package/lib/src/generated/api/StoreInfo.js +2 -0
  93. package/lib/src/generated/api/index.d.ts +38 -0
  94. package/lib/src/identity/IdentityClient.d.ts +70 -0
  95. package/lib/src/identity/IdentityClient.js +97 -0
  96. package/lib/src/index.d.ts +1 -0
  97. package/lib/src/index.js +1 -0
  98. package/lib/src/model/Ad4mModel.d.ts +4 -0
  99. package/lib/src/model/Ad4mModel.js +12 -1
  100. package/lib/src/neighbourhood/MeshManager.d.ts +24 -0
  101. package/lib/src/neighbourhood/MeshManager.js +42 -1
  102. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +10 -0
  103. package/lib/src/neighbourhood/NeighbourhoodClient.js +16 -0
  104. package/lib/src/neighbourhood/Session.js +2 -0
  105. package/lib/src/neighbourhood/SfuManager.d.ts +30 -3
  106. package/lib/src/neighbourhood/SfuManager.js +78 -41
  107. package/lib/src/perspectives/FlowInstance.js +6 -4
  108. package/lib/src/shacl/SHACLFlow.d.ts +5 -3
  109. package/lib/src/shacl/SHACLFlow.js +121 -5
  110. package/package.json +2 -2
  111. package/src/Ad4mClient.test.ts +64 -4
  112. package/src/Ad4mClient.ts +8 -0
  113. package/src/agent/Agent.ts +9 -1
  114. package/src/agent/AgentClient.ts +5 -1
  115. package/src/agent/AgentStatus.ts +4 -0
  116. package/src/apiClient.test.ts +302 -0
  117. package/src/apiClient.ts +136 -1
  118. package/src/generated/api/AgentStatus.ts +6 -1
  119. package/src/generated/api/AgentWithIdentity.ts +12 -0
  120. package/src/generated/api/BotView.ts +6 -0
  121. package/src/generated/api/ClaimOfferParams.ts +14 -0
  122. package/src/generated/api/ClaimOfferResult.ts +11 -0
  123. package/src/generated/api/ClaimView.ts +6 -0
  124. package/src/generated/api/CosignInceptParams.ts +11 -0
  125. package/src/generated/api/DeviceView.ts +12 -0
  126. package/src/generated/api/DidBotScope.ts +6 -0
  127. package/src/generated/api/DidDocument.ts +8 -0
  128. package/src/generated/api/DidDocumentMetadata.ts +19 -0
  129. package/src/generated/api/DidResolutionMetadata.ts +52 -0
  130. package/src/generated/api/DidResolutionResult.ts +13 -0
  131. package/src/generated/api/DidVerificationMethod.ts +15 -0
  132. package/src/generated/api/Events.ts +2 -0
  133. package/src/generated/api/ForkRecord.ts +9 -0
  134. package/src/generated/api/IdentityForkEvent.ts +7 -0
  135. package/src/generated/api/IdentityLog.ts +17 -0
  136. package/src/generated/api/IdentityStatus.ts +49 -0
  137. package/src/generated/api/JoinStatus.ts +7 -0
  138. package/src/generated/api/JoinStatusParams.ts +6 -0
  139. package/src/generated/api/LogParams.ts +18 -0
  140. package/src/generated/api/Offer.ts +8 -0
  141. package/src/generated/api/OfferKind.ts +6 -0
  142. package/src/generated/api/OfferListing.ts +8 -0
  143. package/src/generated/api/OfferOpened.ts +6 -0
  144. package/src/generated/api/OfferState.ts +7 -0
  145. package/src/generated/api/OffersParams.ts +11 -0
  146. package/src/generated/api/OpenOfferParams.ts +7 -0
  147. package/src/generated/api/PublishParams.ts +12 -0
  148. package/src/generated/api/RequestBody.ts +7 -0
  149. package/src/generated/api/ResetLogParams.ts +10 -0
  150. package/src/generated/api/ResolveParams.ts +19 -0
  151. package/src/generated/api/RpcMethods.ts +38 -1
  152. package/src/generated/api/SignedBy.ts +6 -0
  153. package/src/generated/api/SignedHead.ts +10 -0
  154. package/src/generated/api/SignedOffer.ts +8 -0
  155. package/src/generated/api/SignedRequest.ts +7 -0
  156. package/src/generated/api/SkippedSource.ts +6 -0
  157. package/src/generated/api/StoreBehind.ts +14 -0
  158. package/src/generated/api/StoreInfo.ts +16 -0
  159. package/src/generated/api/index.ts +39 -0
  160. package/src/identity/IdentityClient.ts +111 -0
  161. package/src/index.ts +1 -0
  162. package/src/model/Ad4mModel.ts +11 -1
  163. package/src/model/write-round-trips.test.ts +111 -2
  164. package/src/neighbourhood/MeshManager.test.ts +87 -0
  165. package/src/neighbourhood/MeshManager.ts +50 -1
  166. package/src/neighbourhood/NeighbourhoodClient.test.ts +27 -0
  167. package/src/neighbourhood/NeighbourhoodClient.ts +19 -0
  168. package/src/neighbourhood/Session.test.ts +5 -0
  169. package/src/neighbourhood/Session.ts +2 -0
  170. package/src/neighbourhood/SfuManager.test.ts +293 -0
  171. package/src/neighbourhood/SfuManager.ts +92 -45
  172. package/src/perspectives/FlowInstance.ts +6 -4
  173. package/src/shacl/SHACLFlow.test.ts +221 -0
  174. package/src/shacl/SHACLFlow.ts +121 -5
@@ -0,0 +1,2 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { Offer } from "./Offer";
2
+ import type { SignedBy } from "./SignedBy";
3
+ /**
4
+ * An offer signed by the identity's current master key (`coasys:offer`).
5
+ */
6
+ export type SignedOffer = {
7
+ offer: Offer;
8
+ by: SignedBy;
9
+ sig: string;
10
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { RequestBody } from "./RequestBody";
2
+ /**
3
+ * A request signed by a key of the identity (`X-Coasys-Request`).
4
+ */
5
+ export type SignedRequest = {
6
+ req: RequestBody;
7
+ sig: string;
8
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A source of a resolution the resolver did not read from.
3
+ */
4
+ export type SkippedSource = {
5
+ src: string;
6
+ reason: string;
7
+ };
@@ -0,0 +1,2 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ export {};
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The configured store answering a log behind this executor's cache (`identity.status`).
3
+ */
4
+ export type StoreBehind = {
5
+ /**
6
+ * When the executor first saw it behind (unix seconds; in this run of the executor).
7
+ */
8
+ since: number;
9
+ /**
10
+ * The seq of the store's head at its last answer; `null` when it answered no log.
11
+ */
12
+ seq: number | null;
13
+ };
@@ -0,0 +1,2 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ export {};
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The identity store an executor uses (`identity.status`).
3
+ */
4
+ export type StoreInfo = {
5
+ /**
6
+ * The store's base URL, as the agent language reaches it.
7
+ */
8
+ url: string;
9
+ /**
10
+ * Whether the executor trusts a key for the store (`identity.storeKeys`, or the seed's
11
+ * keys). Without one it accepts no head from it, so no `did:scid` record verifies, and
12
+ * `identity.publish` and `identity.claimOffer` refuse `no-store-keys`.
13
+ */
14
+ trusted: boolean;
15
+ };
@@ -0,0 +1,2 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ export {};
@@ -52,6 +52,44 @@ export type { UpdateLinkRequest } from "./UpdateLinkRequest";
52
52
  export type { UpdatePerspectiveRequest } from "./UpdatePerspectiveRequest";
53
53
  export type { VerifySignatureRequest } from "./VerifySignatureRequest";
54
54
  export type { WriteSettingsRequest } from "./WriteSettingsRequest";
55
+ export type { AgentWithIdentity } from "./AgentWithIdentity";
56
+ export type { BotView } from "./BotView";
57
+ export type { ClaimOfferParams } from "./ClaimOfferParams";
58
+ export type { ClaimOfferResult } from "./ClaimOfferResult";
59
+ export type { ClaimView } from "./ClaimView";
60
+ export type { CosignInceptParams } from "./CosignInceptParams";
61
+ export type { DeviceView } from "./DeviceView";
62
+ export type { DidBotScope } from "./DidBotScope";
63
+ export type { DidDocument } from "./DidDocument";
64
+ export type { DidDocumentMetadata } from "./DidDocumentMetadata";
65
+ export type { DidResolutionMetadata } from "./DidResolutionMetadata";
66
+ export type { DidResolutionResult } from "./DidResolutionResult";
67
+ export type { DidVerificationMethod } from "./DidVerificationMethod";
68
+ export type { ForkRecord } from "./ForkRecord";
69
+ export type { IdentityForkEvent } from "./IdentityForkEvent";
70
+ export type { IdentityLog } from "./IdentityLog";
71
+ export type { IdentityStatus } from "./IdentityStatus";
72
+ export type { JoinStatus } from "./JoinStatus";
73
+ export type { JoinStatusParams } from "./JoinStatusParams";
74
+ export type { LogParams } from "./LogParams";
75
+ export type { Offer } from "./Offer";
76
+ export type { OfferKind } from "./OfferKind";
77
+ export type { OfferListing } from "./OfferListing";
78
+ export type { OfferOpened } from "./OfferOpened";
79
+ export type { OfferState } from "./OfferState";
80
+ export type { OffersParams } from "./OffersParams";
81
+ export type { OpenOfferParams } from "./OpenOfferParams";
82
+ export type { PublishParams } from "./PublishParams";
83
+ export type { RequestBody } from "./RequestBody";
84
+ export type { ResetLogParams } from "./ResetLogParams";
85
+ export type { ResolveParams } from "./ResolveParams";
86
+ export type { SignedBy } from "./SignedBy";
87
+ export type { SignedHead } from "./SignedHead";
88
+ export type { SignedOffer } from "./SignedOffer";
89
+ export type { SignedRequest } from "./SignedRequest";
90
+ export type { SkippedSource } from "./SkippedSource";
91
+ export type { StoreBehind } from "./StoreBehind";
92
+ export type { StoreInfo } from "./StoreInfo";
55
93
  export { READ_METHODS, LONG_METHODS } from "./RpcMethods";
56
94
  export type { RpcMethods, RpcMethod } from "./RpcMethods";
57
95
  export { SCOPED_EVENTS } from "./Events";
@@ -0,0 +1,70 @@
1
+ import { ApiClient } from "../apiClient";
2
+ import type { ClaimOfferResult } from "../generated/api/ClaimOfferResult";
3
+ import type { DeviceView } from "../generated/api/DeviceView";
4
+ import type { DidResolutionResult } from "../generated/api/DidResolutionResult";
5
+ import type { IdentityLog } from "../generated/api/IdentityLog";
6
+ import type { IdentityStatus } from "../generated/api/IdentityStatus";
7
+ import type { JoinStatus } from "../generated/api/JoinStatus";
8
+ import type { OfferListing } from "../generated/api/OfferListing";
9
+ import type { OfferOpened } from "../generated/api/OfferOpened";
10
+ import type { SignedHead } from "../generated/api/SignedHead";
11
+ import type { SignedOffer } from "../generated/api/SignedOffer";
12
+ import type { SignedRequest } from "../generated/api/SignedRequest";
13
+ /**
14
+ * The executor's `did:scid:coasys:1` calls.
15
+ *
16
+ * The executor holds device keys only. Master keys and the 12 words stay with the app
17
+ * (`ad4m-identity-client`), which signs the events and offers these calls pass on.
18
+ * `agent.status()` and `agent.me()` carry `identity`, the `did:scid` the agent speaks for.
19
+ */
20
+ export declare class IdentityClient {
21
+ #private;
22
+ constructor(baseUrl: string, token?: string, sharedApiClient?: ApiClient);
23
+ /**
24
+ * This agent's identity, device key, `enc` key and the cached head. `storeBehind` is set
25
+ * (`{ since, seq }`) while the configured store answers the log behind the executor's cache,
26
+ * and `null` once it catches up. `store` is the identity store this executor uses
27
+ * (`{ url, trusted }`: its config's, else its network's) and whether it trusts a key for it;
28
+ * `null` when its network has no store, so identities cannot be created or linked there.
29
+ */
30
+ status(): Promise<IdentityStatus>;
31
+ /** A log through the executor's cache; `fresh` refreshes it from the store first. */
32
+ log(did: string, from?: number, fresh?: boolean): Promise<IdentityLog>;
33
+ /**
34
+ * Resolves a `did:scid:coasys:1` DID URL (`?src=`, `?versionId=`, `#d1`) or a bare device
35
+ * `did:key` to a W3C DID Core resolution result. The executor answers from its key-log
36
+ * cache unless `fresh`, or the cache lacks the log or the asked version. A refusal comes
37
+ * back as `didResolutionMetadata.error` (`invalidDid`, `invalidDidUrl`, `notFound`, …), not
38
+ * as a thrown error. With a fragment, `didDocument` is null and `verificationMethod` holds
39
+ * that method. For a `did:key`, `didResolutionMetadata["coasys:keyId"]` and
40
+ * `["coasys:keyValid"]` say which key of the person's log it is and whether it is valid.
41
+ */
42
+ resolve(didUrl: string, options?: {
43
+ fresh?: boolean;
44
+ accept?: string;
45
+ }): Promise<DidResolutionResult>;
46
+ /**
47
+ * Drops this executor's cached copy of `did`'s log (its events, accepted head and recorded
48
+ * forks); the next read refreshes from the configured store and takes the store's branch.
49
+ * The way out of an `identity-fork`. The operator (admin credential) only.
50
+ */
51
+ resetLog(did: string): Promise<boolean>;
52
+ /**
53
+ * Adds this agent's device-key proof to an `incept` that lists its key. For the main
54
+ * agent the admin credential only; a user's session for its own agent.
55
+ */
56
+ cosignIncept(event: unknown): Promise<unknown>;
57
+ /**
58
+ * Appends signed events through the agent language. For the main agent the admin
59
+ * credential only; a user's session for its own agent.
60
+ */
61
+ publish(events: unknown[]): Promise<SignedHead>;
62
+ openOffer(signedOffer: SignedOffer): Promise<OfferOpened>;
63
+ /** The identity's open and claimed offers, for a request signed by its current master key. */
64
+ offers(request: SignedRequest, wait?: number): Promise<OfferListing[]>;
65
+ /** Claims an offer link for this executor (the operator only). */
66
+ claimOffer(offer: string, hint?: string): Promise<ClaimOfferResult>;
67
+ joinStatus(offerId: string): Promise<JoinStatus>;
68
+ /** The identity's device keys, from its log. */
69
+ devices(): Promise<DeviceView[]>;
70
+ }
@@ -0,0 +1,97 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _IdentityClient_apiClient;
13
+ import { ApiClient } from "../apiClient";
14
+ /**
15
+ * The executor's `did:scid:coasys:1` calls.
16
+ *
17
+ * The executor holds device keys only. Master keys and the 12 words stay with the app
18
+ * (`ad4m-identity-client`), which signs the events and offers these calls pass on.
19
+ * `agent.status()` and `agent.me()` carry `identity`, the `did:scid` the agent speaks for.
20
+ */
21
+ export class IdentityClient {
22
+ constructor(baseUrl, token, sharedApiClient) {
23
+ _IdentityClient_apiClient.set(this, void 0);
24
+ __classPrivateFieldSet(this, _IdentityClient_apiClient, sharedApiClient || new ApiClient(baseUrl, token), "f");
25
+ }
26
+ /**
27
+ * This agent's identity, device key, `enc` key and the cached head. `storeBehind` is set
28
+ * (`{ since, seq }`) while the configured store answers the log behind the executor's cache,
29
+ * and `null` once it catches up. `store` is the identity store this executor uses
30
+ * (`{ url, trusted }`: its config's, else its network's) and whether it trusts a key for it;
31
+ * `null` when its network has no store, so identities cannot be created or linked there.
32
+ */
33
+ async status() {
34
+ return __classPrivateFieldGet(this, _IdentityClient_apiClient, "f").call("identity.status", {});
35
+ }
36
+ /** A log through the executor's cache; `fresh` refreshes it from the store first. */
37
+ async log(did, from, fresh) {
38
+ return __classPrivateFieldGet(this, _IdentityClient_apiClient, "f").call("identity.log", { did, from, fresh });
39
+ }
40
+ /**
41
+ * Resolves a `did:scid:coasys:1` DID URL (`?src=`, `?versionId=`, `#d1`) or a bare device
42
+ * `did:key` to a W3C DID Core resolution result. The executor answers from its key-log
43
+ * cache unless `fresh`, or the cache lacks the log or the asked version. A refusal comes
44
+ * back as `didResolutionMetadata.error` (`invalidDid`, `invalidDidUrl`, `notFound`, …), not
45
+ * as a thrown error. With a fragment, `didDocument` is null and `verificationMethod` holds
46
+ * that method. For a `did:key`, `didResolutionMetadata["coasys:keyId"]` and
47
+ * `["coasys:keyValid"]` say which key of the person's log it is and whether it is valid.
48
+ */
49
+ async resolve(didUrl, options = {}) {
50
+ return __classPrivateFieldGet(this, _IdentityClient_apiClient, "f").call("identity.resolve", {
51
+ didUrl,
52
+ fresh: options.fresh,
53
+ accept: options.accept,
54
+ });
55
+ }
56
+ /**
57
+ * Drops this executor's cached copy of `did`'s log (its events, accepted head and recorded
58
+ * forks); the next read refreshes from the configured store and takes the store's branch.
59
+ * The way out of an `identity-fork`. The operator (admin credential) only.
60
+ */
61
+ async resetLog(did) {
62
+ return __classPrivateFieldGet(this, _IdentityClient_apiClient, "f").call("identity.resetLog", { did });
63
+ }
64
+ /**
65
+ * Adds this agent's device-key proof to an `incept` that lists its key. For the main
66
+ * agent the admin credential only; a user's session for its own agent.
67
+ */
68
+ async cosignIncept(event) {
69
+ return __classPrivateFieldGet(this, _IdentityClient_apiClient, "f").call("identity.cosignIncept", { event: event });
70
+ }
71
+ /**
72
+ * Appends signed events through the agent language. For the main agent the admin
73
+ * credential only; a user's session for its own agent.
74
+ */
75
+ async publish(events) {
76
+ return __classPrivateFieldGet(this, _IdentityClient_apiClient, "f").call("identity.publish", { events: events });
77
+ }
78
+ async openOffer(signedOffer) {
79
+ return __classPrivateFieldGet(this, _IdentityClient_apiClient, "f").call("identity.openOffer", { signedOffer });
80
+ }
81
+ /** The identity's open and claimed offers, for a request signed by its current master key. */
82
+ async offers(request, wait) {
83
+ return __classPrivateFieldGet(this, _IdentityClient_apiClient, "f").call("identity.offers", { request, wait });
84
+ }
85
+ /** Claims an offer link for this executor (the operator only). */
86
+ async claimOffer(offer, hint) {
87
+ return __classPrivateFieldGet(this, _IdentityClient_apiClient, "f").call("identity.claimOffer", { offer, hint });
88
+ }
89
+ async joinStatus(offerId) {
90
+ return __classPrivateFieldGet(this, _IdentityClient_apiClient, "f").call("identity.joinStatus", { offerId });
91
+ }
92
+ /** The identity's device keys, from its log. */
93
+ async devices() {
94
+ return __classPrivateFieldGet(this, _IdentityClient_apiClient, "f").call("identity.devices", {});
95
+ }
96
+ }
97
+ _IdentityClient_apiClient = new WeakMap();
@@ -42,6 +42,7 @@ export * from "./DID";
42
42
  export * from "./utils";
43
43
  export * from "./agent/AgentClient";
44
44
  export * from "./ai/AIClient";
45
+ export * from "./identity/IdentityClient";
45
46
  export * from "./ai/Tasks";
46
47
  export * from "./runtime/RuntimeTypes";
47
48
  export { Model as AIModel, ModelApi, TokenizerSource, LocalModel, ModelType, ModelApiInput, TokenizerSourceInput, LocalModelInput, ModelInput, VoiceActivityParamsInput } from "./ai/AITypes";
package/lib/src/index.js CHANGED
@@ -41,6 +41,7 @@ export * from "./DID";
41
41
  export * from "./utils";
42
42
  export * from "./agent/AgentClient";
43
43
  export * from "./ai/AIClient";
44
+ export * from "./identity/IdentityClient";
44
45
  export * from "./ai/Tasks";
45
46
  export * from "./runtime/RuntimeTypes";
46
47
  export { Model as AIModel, ModelApi, TokenizerSource, LocalModel, ModelApiInput, TokenizerSourceInput, LocalModelInput, ModelInput, VoiceActivityParamsInput } from "./ai/AITypes";
@@ -120,6 +120,10 @@ export declare class Ad4mModel {
120
120
  private _baseExpression;
121
121
  private _perspective;
122
122
  private _snapshot;
123
+ /** True when the constructor minted the id: no record can hold links yet. */
124
+ private _idMinted;
125
+ /** Predicates this instance has already written relation links under (`add*`/`set*`), so they may hold links. */
126
+ private _relationsWritten;
123
127
  author: string;
124
128
  createdAt: any;
125
129
  updatedAt: any;
@@ -674,6 +674,10 @@ export class Ad4mModel {
674
674
  */
675
675
  constructor(perspective, baseExpression) {
676
676
  this._snapshot = null;
677
+ /** True when the constructor minted the id: no record can hold links yet. */
678
+ this._idMinted = false;
679
+ /** Predicates this instance has already written relation links under (`add*`/`set*`), so they may hold links. */
680
+ this._relationsWritten = new Set();
677
681
  // Use a dedicated `ad4m://obj/<id>` scheme for auto-generated
678
682
  // baseExpressions instead of `Literal.from(...).toUrl()`'s
679
683
  // `literal:string:<id>`. After typed-literal storage lands, the storage
@@ -684,6 +688,7 @@ export class Ad4mModel {
684
688
  // IRIs, so relation links like `<post> --has_comment--> <comment-id>`
685
689
  // round-trip correctly through the SPARQL store.
686
690
  this._baseExpression = baseExpression ? baseExpression : `ad4m://obj/${makeRandomId(24)}`;
691
+ this._idMinted = !baseExpression;
687
692
  this._perspective = perspective;
688
693
  }
689
694
  /**
@@ -1502,6 +1507,7 @@ export class Ad4mModel {
1502
1507
  console.warn(`Relation "${key}" has no metadata, skipping`);
1503
1508
  return;
1504
1509
  }
1510
+ this._relationsWritten.add(metadata.predicate);
1505
1511
  const abstractName = this.abstractName();
1506
1512
  if (abstractName) {
1507
1513
  if (value != null)
@@ -1525,6 +1531,7 @@ export class Ad4mModel {
1525
1531
  console.warn(`Relation "${key}" has no metadata, skipping`);
1526
1532
  return;
1527
1533
  }
1534
+ this._relationsWritten.add(metadata.predicate);
1528
1535
  const abstractName = this.abstractName();
1529
1536
  if (abstractName) {
1530
1537
  if (value != null)
@@ -1773,7 +1780,11 @@ export class Ad4mModel {
1773
1780
  }
1774
1781
  }
1775
1782
  else if (Array.isArray(value)) {
1776
- // Handle all arrays as relations, including empty ones (which clears the relation)
1783
+ // Handle all arrays as relations, including empty ones (which clears the relation).
1784
+ // A record being created under an id minted here has no links to
1785
+ // clear, so an empty relation there costs a round trip and writes nothing.
1786
+ if (value.length === 0 && !this._snapshot && this._idMinted && !this._relationsWritten.has(this.getRelationOptions(key)?.predicate ?? key))
1787
+ continue;
1777
1788
  await this.setRelationValues(key, value, batchId);
1778
1789
  }
1779
1790
  else if (value !== undefined && value !== null && value !== "") {
@@ -200,6 +200,13 @@ export interface MeshManagerOptions {
200
200
  /** How often the mesh looks at its own connections. `0` disables the timer;
201
201
  * {@link MeshManager.tick} still works, which is how tests drive it. */
202
202
  sweepMs?: number;
203
+ /** Called after a network change (see `ApiClient.onNetworkChange`): every
204
+ * pair restarts ICE then, rather than waiting for each to notice. */
205
+ onNetworkChange?: (callback: () => void) => () => void;
206
+ /** Called when a pair goes disconnected: checks the socket the signals
207
+ * go over now (see `ApiClient.checkConnection`). A dead one is redialled
208
+ * and `onNetworkChange` restarts every pair. */
209
+ checkConnection?: () => void;
203
210
  }
204
211
  /** Public STUN, and no TURN. Two servers, because ICE queries them in parallel. */
205
212
  export declare const DEFAULT_ICE_SERVERS: RTCIceServer[];
@@ -270,6 +277,9 @@ export declare class MeshManager {
270
277
  * Cleared only when a renegotiation is answered.
271
278
  */
272
279
  private renegotiationRepairs;
280
+ private onNetworkChange;
281
+ private unwatchNetwork;
282
+ private checkConnection;
273
283
  constructor(options: MeshManagerOptions);
274
284
  on(event: MeshEvent, callback: MeshEventCallback): void;
275
285
  off(event: MeshEvent, callback?: MeshEventCallback): void;
@@ -374,6 +384,20 @@ export declare class MeshManager {
374
384
  * 3. **Rebuild.** When there is nothing to resend, or the rungs above were tried.
375
385
  */
376
386
  private repair;
387
+ /**
388
+ * The network changed: every pair's path is likely gone, though ICE has
389
+ * noticed on none yet. Each negotiated pair takes the ladder's first rung
390
+ * now, all at once — an ICE restart is one offer per pair, and waiting
391
+ * for each to time out costs seconds of silence. Pairs still negotiating
392
+ * have nothing to restart; the sweep keeps looking after them.
393
+ *
394
+ * It skips the sweep's guards (`outstanding`, one pair per sweep) on
395
+ * purpose. They stop the sweep reading a slow send as a lost one and
396
+ * escalating every pair at once. Here nothing is judged lost, and the
397
+ * rung is the first one: one offer per pair, each to a different peer.
398
+ * A restart offer that is lost falls to the sweep, guards and all.
399
+ */
400
+ private restartAll;
377
401
  /** Whether this pair has been given long enough, and whether it is this side's turn to act. */
378
402
  private dueForRepair;
379
403
  /**
@@ -306,6 +306,7 @@ export class MeshManager {
306
306
  * Cleared only when a renegotiation is answered.
307
307
  */
308
308
  this.renegotiationRepairs = new Map();
309
+ this.unwatchNetwork = null;
309
310
  this.channel = options.channel;
310
311
  this.callId = options.callId;
311
312
  this.selfId = options.selfId;
@@ -319,6 +320,8 @@ export class MeshManager {
319
320
  ?? ((configuration) => new RTCPeerConnection(configuration));
320
321
  this.now = options.now ?? (() => Date.now());
321
322
  this.sweepMs = options.sweepMs ?? SWEEP_INTERVAL_MS;
323
+ this.onNetworkChange = options.onNetworkChange;
324
+ this.checkConnection = options.checkConnection;
322
325
  }
323
326
  // ── Events ──────────────────────────────────────────────────────
324
327
  on(event, callback) {
@@ -421,6 +424,7 @@ export class MeshManager {
421
424
  this.publish({ v: CALL_PROTOCOL_VERSION, call: this.callId, warm: true });
422
425
  if (this.sweepMs > 0)
423
426
  this.sweep = setInterval(() => this.tick(), this.sweepMs);
427
+ this.unwatchNetwork = this.onNetworkChange?.(() => this.restartAll()) ?? null;
424
428
  }
425
429
  async leave() {
426
430
  this.closed = true;
@@ -428,6 +432,8 @@ export class MeshManager {
428
432
  clearInterval(this.sweep);
429
433
  this.sweep = null;
430
434
  }
435
+ this.unwatchNetwork?.();
436
+ this.unwatchNetwork = null;
431
437
  this.unwatchPublish?.();
432
438
  this.unwatchPublish = null;
433
439
  if (this.channelUnsubscribe) {
@@ -743,8 +749,10 @@ export class MeshManager {
743
749
  if (slot.offerDeferred && pc.signalingState === "stable")
744
750
  void negotiate();
745
751
  }
746
- if (state === "disconnected" && !slot.disconnectedAt)
752
+ if (state === "disconnected" && !slot.disconnectedAt) {
747
753
  slot.disconnectedAt = this.now();
754
+ this.checkConnection?.();
755
+ }
748
756
  if (state === "connected" || state === "failed")
749
757
  slot.disconnectedAt = 0;
750
758
  this.emit("peer-state", peerId, state);
@@ -1082,6 +1090,39 @@ export class MeshManager {
1082
1090
  slot.attempts = attempts - 1;
1083
1091
  this.rebuild(peerId, { announce: true, rung: "rebuild" });
1084
1092
  }
1093
+ /**
1094
+ * The network changed: every pair's path is likely gone, though ICE has
1095
+ * noticed on none yet. Each negotiated pair takes the ladder's first rung
1096
+ * now, all at once — an ICE restart is one offer per pair, and waiting
1097
+ * for each to time out costs seconds of silence. Pairs still negotiating
1098
+ * have nothing to restart; the sweep keeps looking after them.
1099
+ *
1100
+ * It skips the sweep's guards (`outstanding`, one pair per sweep) on
1101
+ * purpose. They stop the sweep reading a slow send as a lost one and
1102
+ * escalating every pair at once. Here nothing is judged lost, and the
1103
+ * rung is the first one: one offer per pair, each to a different peer.
1104
+ * A restart offer that is lost falls to the sweep, guards and all.
1105
+ */
1106
+ restartAll() {
1107
+ if (this.closed)
1108
+ return;
1109
+ const at = this.now();
1110
+ for (const [peerId, slot] of this.slots) {
1111
+ if (!slot.remoteReady || typeof slot.pc.restartIce !== "function")
1112
+ continue;
1113
+ // Spaced from the sweep's next rung, but not charged to the pair's
1114
+ // budget: a network change judges no pair lost.
1115
+ slot.lastAttempt = at;
1116
+ try {
1117
+ slot.pc.restartIce();
1118
+ this.emit("peer-recovery", peerId, { rung: "ice-restart", attempts: slot.attempts });
1119
+ }
1120
+ catch (error) {
1121
+ this.fail(`restarting ice with ${peerId}`, error);
1122
+ }
1123
+ }
1124
+ this.lastRepairAt = at;
1125
+ }
1085
1126
  /** Whether this pair has been given long enough, and whether it is this side's turn to act. */
1086
1127
  dueForRepair(peerId, slot, at) {
1087
1128
  const state = slot.pc.connectionState;
@@ -32,6 +32,16 @@ export declare class NeighbourhoodClient {
32
32
  sfuCallLeave(neighbourhoodUrl: string, roomName: string): Promise<boolean>;
33
33
  sfuCallSetQualityPreference(neighbourhoodUrl: string, roomName: string, preference: SfuQualityPreference): Promise<boolean>;
34
34
  sfuCallAnswerServerOffer(neighbourhoodUrl: string, roomName: string, sdpAnswer: string): Promise<boolean>;
35
+ /** Ask the SFU to restart ICE on this agent's call connection. The offer
36
+ * arrives as an `sfu-call-renegotiation-offer` event; answer it with
37
+ * {@link sfuCallAnswerServerOffer}. */
38
+ sfuCallRestartIce(neighbourhoodUrl: string, roomName: string): Promise<boolean>;
39
+ /** Fires after a network change, once the client's socket is back on
40
+ * the new network. See {@link ApiClient.onNetworkChange}. */
41
+ onNetworkChange(callback: () => void): () => void;
42
+ /** Check the client's socket now: one that says nothing within a
43
+ * deadline is treated as a network change. See {@link ApiClient.checkConnection}. */
44
+ checkConnection(): void;
35
45
  sfuGetConfig(neighbourhoodUrl: string): Promise<SfuConfig>;
36
46
  sfuSetConfig(neighbourhoodUrl: string, config: SfuConfig): Promise<boolean>;
37
47
  sfuPeerForNeighbourhood(neighbourhoodUrl: string): Promise<string | null>;
@@ -156,6 +156,22 @@ export class NeighbourhoodClient {
156
156
  sdpAnswer,
157
157
  });
158
158
  }
159
+ /** Ask the SFU to restart ICE on this agent's call connection. The offer
160
+ * arrives as an `sfu-call-renegotiation-offer` event; answer it with
161
+ * {@link sfuCallAnswerServerOffer}. */
162
+ async sfuCallRestartIce(neighbourhoodUrl, roomName) {
163
+ return __classPrivateFieldGet(this, _NeighbourhoodClient_apiClient, "f").call("sfu.callRestartIce", { neighbourhoodUrl, roomName });
164
+ }
165
+ /** Fires after a network change, once the client's socket is back on
166
+ * the new network. See {@link ApiClient.onNetworkChange}. */
167
+ onNetworkChange(callback) {
168
+ return __classPrivateFieldGet(this, _NeighbourhoodClient_apiClient, "f").onNetworkChange(callback);
169
+ }
170
+ /** Check the client's socket now: one that says nothing within a
171
+ * deadline is treated as a network change. See {@link ApiClient.checkConnection}. */
172
+ checkConnection() {
173
+ __classPrivateFieldGet(this, _NeighbourhoodClient_apiClient, "f").checkConnection();
174
+ }
159
175
  async sfuGetConfig(neighbourhoodUrl) {
160
176
  return __classPrivateFieldGet(this, _NeighbourhoodClient_apiClient, "f").call("sfu.getConfig", { neighbourhoodUrl });
161
177
  }
@@ -240,6 +240,8 @@ export function createSession(config) {
240
240
  callId: roomId,
241
241
  selfId: agentDid,
242
242
  ...(meshIce.length > 0 ? { iceServers: meshIce } : {}),
243
+ onNetworkChange: (cb) => api.onNetworkChange(cb),
244
+ checkConnection: () => api.checkConnection(),
243
245
  });
244
246
  meshManager = mesh;
245
247
  wireMeshEvents(mesh);
@@ -26,6 +26,16 @@ export interface SfuNeighbourhoodApi {
26
26
  sfuCallSetQualityPreference(neighbourhoodUrl: string, roomName: string, preference: SfuQualityPreference): Promise<boolean>;
27
27
  sfuCallAnswerServerOffer(neighbourhoodUrl: string, roomName: string, sdpAnswer: string): Promise<boolean>;
28
28
  subscribeSfuCallRenegotiationOffer(targetDid: string, callback: (event: SfuCallRenegotiationOffer) => void): () => void;
29
+ /** Ask the SFU to restart ICE on this agent's connection; the offer
30
+ * arrives through `subscribeSfuCallRenegotiationOffer`. */
31
+ sfuCallRestartIce(neighbourhoodUrl: string, roomName: string): Promise<boolean>;
32
+ /** Called after a network change, once calls reach the executor again. */
33
+ onNetworkChange(callback: () => void): () => void;
34
+ /** Check the executor socket now; one found dead is redialled and
35
+ * `onNetworkChange` fires. Called when ICE goes disconnected, since a
36
+ * network switch the platform announced nothing for leaves that socket
37
+ * OPEN and dead, and the restart would go out on it. */
38
+ checkConnection(): void;
29
39
  sfuAddIceCandidate(neighbourhoodUrl: string, roomName: string, candidate: string): Promise<boolean>;
30
40
  sfuSendData(neighbourhoodUrl: string, roomName: string, channelLabel: string, data: string, binary?: boolean): Promise<boolean>;
31
41
  subscribeSfuDataChannel(callback: (message: SfuDataMessage) => void): () => void;
@@ -79,8 +89,8 @@ export declare class SfuManager {
79
89
  private static readonly MAX_RECONNECTS;
80
90
  /** How long one rebuild keeps retrying a join the executor cannot take yet. */
81
91
  private static readonly REJOIN_WINDOW_MS;
82
- /** How long ICE may stay disconnected before a rebuild: the executor's `ICE_DISCONNECT_GRACE`. */
83
- private static readonly DISCONNECT_GRACE_MS;
92
+ /** How long an ICE restart has to bring the connection back before a rebuild. */
93
+ private static readonly RESTART_TIMEOUT_MS;
84
94
  /** A rebuild is running: a second failure signal joins it rather than starting another. */
85
95
  private reconnecting;
86
96
  /** Bumped by `leave()`, so a reconnect in flight stops before rejoining. */
@@ -97,10 +107,17 @@ export declare class SfuManager {
97
107
  private qualityPreference;
98
108
  /** Server offers waiting to be applied, in arrival order, one at a time. */
99
109
  private offerQueue;
110
+ /** The last server offer answered. The executor sends an unanswered
111
+ * restart offer again when asked twice; one that was answered meanwhile
112
+ * must not be answered again, or that answer lands on its next offer. */
113
+ private answeredOffer;
100
114
  private renegotiationUnsubscribe;
101
115
  private rosterUnsubscribe;
102
116
  private dataChannelUnsubscribe;
103
- private disconnectedTimer;
117
+ /** An ICE restart is in flight until this fires: ICE going disconnected
118
+ * again joins it, a network change replaces it. */
119
+ private restartTimer;
120
+ private networkUnsubscribe;
104
121
  /** Running while the room's roster leaves this agent out: see `noticeRoster`. */
105
122
  private unlistedTimer;
106
123
  /** How long the roster may leave this agent out before the call is rebuilt. */
@@ -118,6 +135,16 @@ export declare class SfuManager {
118
135
  * `REJOIN_WINDOW_MS`, so the call comes back on its own once it can.
119
136
  */
120
137
  private reconnect;
138
+ /**
139
+ * Repair the connection in place: the SFU offers new ICE credentials
140
+ * (`sfuCallRestartIce`), the offer is answered like any server offer,
141
+ * and the browser gathers candidates on whatever network it has now.
142
+ * DTLS, tracks and the room slot stay. If the connection is not back
143
+ * within `RESTART_TIMEOUT_MS`, the call is rebuilt. One restart at a
144
+ * time: a call while one is in flight does nothing.
145
+ */
146
+ private restartIce;
147
+ private endRestart;
121
148
  on(event: SfuEvent, callback: SfuEventCallback): void;
122
149
  off(event: SfuEvent, callback?: SfuEventCallback): void;
123
150
  private emit;