@coasys/ad4m 0.13.0-test-flows-1 → 0.13.1-staging.2

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 (958) hide show
  1. package/README.md +1 -0
  2. package/lib/index.cjs +9613 -7069
  3. package/lib/index.js +7367 -4840
  4. package/lib/src/Ad4mClient.d.ts +12 -4
  5. package/lib/src/Ad4mClient.js +15 -11
  6. package/lib/src/Literal.js +3 -3
  7. package/lib/src/agent/Agent.d.ts +4 -1
  8. package/lib/src/agent/Agent.js +6 -0
  9. package/lib/src/agent/AgentClient.d.ts +9 -23
  10. package/lib/src/agent/AgentClient.js +68 -148
  11. package/lib/src/ai/AIClient.d.ts +10 -6
  12. package/lib/src/ai/AIClient.js +29 -27
  13. package/lib/src/apiClient.d.ts +54 -42
  14. package/lib/src/apiClient.js +279 -252
  15. package/lib/src/expression/Expression.d.ts +13 -4
  16. package/lib/src/expression/Expression.js +0 -1
  17. package/lib/src/expression/ExpressionClient.js +1 -1
  18. package/lib/src/generated/api/AIPromptExamples.d.ts +4 -0
  19. package/lib/src/generated/api/AIPromptExamples.js +2 -0
  20. package/lib/src/generated/api/AIPromptExamplesInput.d.ts +4 -0
  21. package/lib/src/generated/api/AIPromptExamplesInput.js +2 -0
  22. package/lib/src/generated/api/AITask.d.ts +11 -0
  23. package/lib/src/generated/api/AITaskInput.d.ts +8 -0
  24. package/lib/src/generated/api/AddAgentInfosRequest.d.ts +3 -0
  25. package/lib/src/generated/api/AddAgentInfosRequest.js +2 -0
  26. package/lib/src/generated/api/AddLinkExpressionRequest.d.ts +2 -2
  27. package/lib/src/generated/api/AddLinkRequest.d.ts +2 -2
  28. package/lib/src/generated/api/AddLinksBulkRequest.d.ts +2 -2
  29. package/lib/src/generated/api/AddSdnaRequest.d.ts +2 -2
  30. package/lib/src/generated/api/Agent.d.ts +6 -0
  31. package/lib/src/generated/api/AgentAddEntanglementProofsParams.d.ts +9 -0
  32. package/lib/src/generated/api/AgentByDidParams.d.ts +3 -0
  33. package/lib/src/generated/api/AgentByDidParams.js +2 -0
  34. package/lib/src/generated/api/AgentRemoveAppParams.d.ts +3 -0
  35. package/lib/src/generated/api/AgentRemoveAppParams.js +2 -0
  36. package/lib/src/generated/api/AgentRevokeTokenParams.d.ts +3 -0
  37. package/lib/src/generated/api/AgentRevokeTokenParams.js +2 -0
  38. package/lib/src/generated/api/AgentSignature.d.ts +4 -0
  39. package/lib/src/generated/api/AgentSignature.js +2 -0
  40. package/lib/src/generated/api/AgentStatus.d.ts +8 -0
  41. package/lib/src/generated/api/AgentStatusChangedEvent.d.ts +7 -0
  42. package/lib/src/generated/api/AgentUpdatedEvent.d.ts +7 -0
  43. package/lib/src/generated/api/AgentsByDidsRequest.d.ts +3 -0
  44. package/lib/src/generated/api/AgentsByDidsRequest.js +2 -0
  45. package/lib/src/generated/api/AiAddModelParams.d.ts +4 -0
  46. package/lib/src/generated/api/AiAddTaskParams.d.ts +4 -0
  47. package/lib/src/generated/api/AiDiscoverModelsParams.d.ts +8 -0
  48. package/lib/src/generated/api/AiDiscoverModelsParams.js +2 -0
  49. package/lib/src/generated/api/AiGetDefaultModelParams.d.ts +4 -0
  50. package/lib/src/generated/api/AiIdParams.d.ts +3 -0
  51. package/lib/src/generated/api/AiIdParams.js +2 -0
  52. package/lib/src/generated/api/AiModelLoadingStatusParams.d.ts +7 -0
  53. package/lib/src/generated/api/AiModelLoadingStatusParams.js +2 -0
  54. package/lib/src/generated/api/AiSetDefaultModelParams.d.ts +5 -0
  55. package/lib/src/generated/api/AiSetDefaultModelParams.js +1 -0
  56. package/lib/src/generated/api/AiTranscriptionCloseParams.d.ts +3 -0
  57. package/lib/src/generated/api/AiTranscriptionCloseParams.js +2 -0
  58. package/lib/src/generated/api/AiTranscriptionOpenParams.d.ts +5 -0
  59. package/lib/src/generated/api/AiTranscriptionOpenParams.js +1 -0
  60. package/lib/src/generated/api/AiUpdateModelParams.d.ts +5 -0
  61. package/lib/src/generated/api/AiUpdateModelParams.js +1 -0
  62. package/lib/src/generated/api/AiUpdateTaskParams.d.ts +4 -0
  63. package/lib/src/generated/api/AiUpdateTaskParams.js +1 -0
  64. package/lib/src/generated/api/Apps.d.ts +7 -0
  65. package/lib/src/generated/api/Apps.js +1 -0
  66. package/lib/src/generated/api/AuthInfo.d.ts +10 -0
  67. package/lib/src/generated/api/AuthInfo.js +1 -0
  68. package/lib/src/generated/api/AuthInfoInput.d.ts +4 -4
  69. package/lib/src/generated/api/AutoProcessorEvent.d.ts +89 -0
  70. package/lib/src/generated/api/AutoProcessorEvent.js +1 -0
  71. package/lib/src/generated/api/AutoProcessorNeighbourhoodState.d.ts +32 -0
  72. package/lib/src/generated/api/AutoProcessorNeighbourhoodState.js +1 -0
  73. package/lib/src/generated/api/AutoProcessorStep.d.ts +7 -0
  74. package/lib/src/generated/api/AutoProcessorStep.js +2 -0
  75. package/lib/src/generated/api/BroadcastRequest.d.ts +5 -0
  76. package/lib/src/generated/api/BroadcastRequest.js +2 -0
  77. package/lib/src/generated/api/CallSessionInfo.d.ts +23 -0
  78. package/lib/src/generated/api/CallSessionInfo.js +2 -0
  79. package/lib/src/generated/api/Capability.d.ts +5 -0
  80. package/lib/src/generated/api/Capability.js +1 -0
  81. package/lib/src/generated/api/CreateSubjectRequest.d.ts +2 -2
  82. package/lib/src/generated/api/CreateUserRequest.d.ts +4 -0
  83. package/lib/src/generated/api/CreateUserRequest.js +2 -0
  84. package/lib/src/generated/api/DateTime.d.ts +1 -0
  85. package/lib/src/generated/api/DateTime.js +2 -0
  86. package/lib/src/generated/api/DecoratedExpressionProof.d.ts +6 -0
  87. package/lib/src/generated/api/DecoratedExpressionProof.js +2 -0
  88. package/lib/src/generated/api/DecoratedLinkExpression.d.ts +10 -0
  89. package/lib/src/generated/api/DecoratedLinkExpression.js +1 -0
  90. package/lib/src/generated/api/DecoratedNeighbourhoodExpression.d.ts +8 -0
  91. package/lib/src/generated/api/DecoratedNeighbourhoodExpression.js +1 -0
  92. package/lib/src/generated/api/DecoratedPerspective.d.ts +4 -0
  93. package/lib/src/generated/api/DecoratedPerspective.js +1 -0
  94. package/lib/src/generated/api/DiscardBatchRequest.d.ts +3 -0
  95. package/lib/src/generated/api/DiscardBatchRequest.js +2 -0
  96. package/lib/src/generated/api/DisposeQueryRequest.d.ts +3 -0
  97. package/lib/src/generated/api/DisposeQueryRequest.js +2 -0
  98. package/lib/src/generated/api/EntanglementProof.d.ts +8 -0
  99. package/lib/src/generated/api/EntanglementProof.js +2 -0
  100. package/lib/src/generated/api/EntanglementProofInput.d.ts +1 -1
  101. package/lib/src/generated/api/EntanglementProofPreflightRequest.d.ts +4 -0
  102. package/lib/src/generated/api/EntanglementProofPreflightRequest.js +2 -0
  103. package/lib/src/generated/api/EntanglementProofsWrapper.d.ts +7 -0
  104. package/lib/src/generated/api/EntanglementProofsWrapper.js +1 -0
  105. package/lib/src/generated/api/Events.d.ts +56 -0
  106. package/lib/src/generated/api/Events.js +18 -0
  107. package/lib/src/generated/api/ExceptionInfo.d.ts +7 -0
  108. package/lib/src/generated/api/ExceptionInfo.js +1 -0
  109. package/lib/src/generated/api/ExceptionOccurredEvent.d.ts +7 -0
  110. package/lib/src/generated/api/ExceptionOccurredEvent.js +1 -0
  111. package/lib/src/generated/api/ExceptionType.d.ts +1 -0
  112. package/lib/src/generated/api/ExceptionType.js +2 -0
  113. package/lib/src/generated/api/ExecuteCommandsRequest.d.ts +4 -2
  114. package/lib/src/generated/api/ExportRequest.d.ts +1 -1
  115. package/lib/src/generated/api/ExpressionInteractRequest.d.ts +5 -0
  116. package/lib/src/generated/api/ExpressionInteractRequest.js +1 -0
  117. package/lib/src/generated/api/ExpressionProofInput.d.ts +4 -4
  118. package/lib/src/generated/api/ExpressionRendered.d.ts +11 -0
  119. package/lib/src/generated/api/ExpressionRendered.js +1 -0
  120. package/lib/src/generated/api/ExpressionUrlRequest.d.ts +3 -0
  121. package/lib/src/generated/api/ExpressionUrlRequest.js +2 -0
  122. package/lib/src/generated/api/FireOutcome.d.ts +14 -0
  123. package/lib/src/generated/api/FireOutcome.js +2 -0
  124. package/lib/src/generated/api/FlowStateChangedEvent.d.ts +38 -0
  125. package/lib/src/generated/api/FlowStateChangedEvent.js +2 -0
  126. package/lib/src/generated/api/FlowStateEntry.d.ts +18 -0
  127. package/lib/src/generated/api/FlowStateEntry.js +2 -0
  128. package/lib/src/generated/api/FriendSendMessageRequest.d.ts +1 -1
  129. package/lib/src/generated/api/HostRate.d.ts +7 -0
  130. package/lib/src/generated/api/HostRate.js +2 -0
  131. package/lib/src/generated/api/HostingInfoResult.d.ts +13 -0
  132. package/lib/src/generated/api/HostingInfoResult.js +1 -0
  133. package/lib/src/generated/api/HostingInfoUser.d.ts +9 -0
  134. package/lib/src/generated/api/HostingInfoUser.js +2 -0
  135. package/lib/src/generated/api/HostingRequestPaymentResult.d.ts +4 -0
  136. package/lib/src/generated/api/HostingRequestPaymentResult.js +2 -0
  137. package/lib/src/generated/api/HostingUserInfo.d.ts +6 -0
  138. package/lib/src/generated/api/HostingUserInfo.js +2 -0
  139. package/lib/src/generated/api/HostingVersionInfo.d.ts +7 -0
  140. package/lib/src/generated/api/HostingVersionInfo.js +2 -0
  141. package/lib/src/generated/api/HostingWalletResult.d.ts +8 -0
  142. package/lib/src/generated/api/HostingWalletResult.js +1 -0
  143. package/lib/src/generated/api/IceServer.d.ts +18 -0
  144. package/lib/src/generated/api/IceServer.js +2 -0
  145. package/lib/src/generated/api/Icon.d.ts +3 -0
  146. package/lib/src/generated/api/Icon.js +2 -0
  147. package/lib/src/generated/api/ImportResult.d.ts +15 -0
  148. package/lib/src/generated/api/ImportResult.js +1 -0
  149. package/lib/src/generated/api/ImportStats.d.ts +7 -0
  150. package/lib/src/generated/api/ImportStats.js +2 -0
  151. package/lib/src/generated/api/InteractionCall.d.ts +4 -0
  152. package/lib/src/generated/api/InteractionCall.js +2 -0
  153. package/lib/src/generated/api/InteractionCallWrapper.d.ts +6 -0
  154. package/lib/src/generated/api/InteractionCallWrapper.js +2 -0
  155. package/lib/src/generated/api/InteractionMeta.d.ts +6 -0
  156. package/lib/src/generated/api/InteractionMeta.js +1 -0
  157. package/lib/src/generated/api/InteractionParameter.d.ts +4 -0
  158. package/lib/src/generated/api/InteractionParameter.js +2 -0
  159. package/lib/src/generated/api/LanguageAddressParams.d.ts +3 -0
  160. package/lib/src/generated/api/LanguageAddressParams.js +2 -0
  161. package/lib/src/generated/api/LanguageHandle.d.ts +9 -0
  162. package/lib/src/generated/api/LanguageHandle.js +1 -0
  163. package/lib/src/generated/api/LanguageListParams.d.ts +3 -0
  164. package/lib/src/generated/api/LanguageListParams.js +2 -0
  165. package/lib/src/generated/api/LanguageMeta.d.ts +11 -0
  166. package/lib/src/generated/api/LanguageMeta.js +2 -0
  167. package/lib/src/generated/api/LanguageMetaInput.d.ts +2 -2
  168. package/lib/src/generated/api/LanguageRef.d.ts +4 -0
  169. package/lib/src/generated/api/LanguageRef.js +2 -0
  170. package/lib/src/generated/api/LanguageSettingsWrapper.d.ts +6 -0
  171. package/lib/src/generated/api/LanguageSettingsWrapper.js +2 -0
  172. package/lib/src/generated/api/LanguageWriteSettingsParams.d.ts +4 -0
  173. package/lib/src/generated/api/LanguageWriteSettingsParams.js +2 -0
  174. package/lib/src/generated/api/LinkExpressionInput.d.ts +1 -1
  175. package/lib/src/generated/api/LinkInput.d.ts +1 -1
  176. package/lib/src/generated/api/LinkMutationRequest.d.ts +12 -0
  177. package/lib/src/generated/api/LinkMutationRequest.js +1 -0
  178. package/lib/src/generated/api/LinkMutationsRequest.d.ts +5 -0
  179. package/lib/src/generated/api/LinkMutationsRequest.js +1 -0
  180. package/lib/src/generated/api/LinkStatus.d.ts +1 -1
  181. package/lib/src/generated/api/LinkUpdateInput.d.ts +5 -0
  182. package/lib/src/generated/api/LinkUpdateInput.js +1 -0
  183. package/lib/src/generated/api/LocalModel.d.ts +7 -0
  184. package/lib/src/generated/api/LocalModel.js +1 -0
  185. package/lib/src/generated/api/LocalModelInput.d.ts +7 -0
  186. package/lib/src/generated/api/LocalModelInput.js +1 -0
  187. package/lib/src/generated/api/MessageReceivedEvent.d.ts +7 -0
  188. package/lib/src/generated/api/MessageReceivedEvent.js +1 -0
  189. package/lib/src/generated/api/Model.d.ts +10 -0
  190. package/lib/src/generated/api/Model.js +1 -0
  191. package/lib/src/generated/api/ModelApi.d.ts +17 -0
  192. package/lib/src/generated/api/ModelApi.js +1 -0
  193. package/lib/src/generated/api/ModelApiInput.d.ts +11 -0
  194. package/lib/src/generated/api/ModelApiInput.js +2 -0
  195. package/lib/src/generated/api/ModelApiType.d.ts +1 -0
  196. package/lib/src/generated/api/ModelApiType.js +2 -0
  197. package/lib/src/generated/api/ModelInput.d.ts +9 -0
  198. package/lib/src/generated/api/ModelInput.js +1 -0
  199. package/lib/src/generated/api/ModelType.d.ts +1 -1
  200. package/lib/src/generated/api/Neighbourhood.d.ts +5 -0
  201. package/lib/src/generated/api/Neighbourhood.js +1 -0
  202. package/lib/src/generated/api/NeighbourhoodBroadcastParams.d.ts +7 -0
  203. package/lib/src/generated/api/NeighbourhoodBroadcastParams.js +1 -0
  204. package/lib/src/generated/api/NeighbourhoodOnlineStatusParams.d.ts +6 -0
  205. package/lib/src/generated/api/NeighbourhoodOnlineStatusParams.js +1 -0
  206. package/lib/src/generated/api/NeighbourhoodPerspectivePayload.d.ts +7 -0
  207. package/lib/src/generated/api/NeighbourhoodPerspectivePayload.js +1 -0
  208. package/lib/src/generated/api/NeighbourhoodPhase.d.ts +6 -0
  209. package/lib/src/generated/api/NeighbourhoodPhase.js +2 -0
  210. package/lib/src/generated/api/NeighbourhoodSignalFilter.d.ts +8 -0
  211. package/lib/src/generated/api/NeighbourhoodSignalFilter.js +1 -0
  212. package/lib/src/generated/api/NeighbourhoodSignalParams.d.ts +7 -0
  213. package/lib/src/generated/api/NeighbourhoodSignalParams.js +1 -0
  214. package/lib/src/generated/api/NeighbourhoodSignedPerspective.d.ts +8 -0
  215. package/lib/src/generated/api/NeighbourhoodSignedPerspective.js +1 -0
  216. package/lib/src/generated/api/NeighbourhoodUuidParams.d.ts +3 -0
  217. package/lib/src/generated/api/NeighbourhoodUuidParams.js +2 -0
  218. package/lib/src/generated/api/Notification.d.ts +16 -0
  219. package/lib/src/generated/api/Notification.js +2 -0
  220. package/lib/src/generated/api/NotificationGrantRequest.d.ts +6 -0
  221. package/lib/src/generated/api/NotificationGrantRequest.js +2 -0
  222. package/lib/src/generated/api/NotificationInput.d.ts +1 -1
  223. package/lib/src/generated/api/NotificationTriggeredEvent.d.ts +9 -0
  224. package/lib/src/generated/api/NotificationTriggeredEvent.js +1 -0
  225. package/lib/src/generated/api/OnlineAgent.d.ts +9 -0
  226. package/lib/src/generated/api/OnlineAgent.js +1 -0
  227. package/lib/src/generated/api/OutputRef.d.ts +12 -0
  228. package/lib/src/generated/api/OutputRef.js +2 -0
  229. package/lib/src/generated/api/OverlayView.d.ts +24 -0
  230. package/lib/src/generated/api/OverlayView.js +1 -0
  231. package/lib/src/generated/api/Perspective.d.ts +4 -0
  232. package/lib/src/generated/api/Perspective.js +1 -0
  233. package/lib/src/generated/api/PerspectiveAddAutoProcessorParams.d.ts +26 -0
  234. package/lib/src/generated/api/PerspectiveAddAutoProcessorParams.js +2 -0
  235. package/lib/src/generated/api/PerspectiveAddLinkExpressionParams.d.ts +7 -0
  236. package/lib/src/generated/api/PerspectiveAddLinkExpressionParams.js +1 -0
  237. package/lib/src/generated/api/PerspectiveAddLinkParams.d.ts +7 -0
  238. package/lib/src/generated/api/PerspectiveAddLinkParams.js +1 -0
  239. package/lib/src/generated/api/PerspectiveAddLinksParams.d.ts +7 -0
  240. package/lib/src/generated/api/PerspectiveAddLinksParams.js +1 -0
  241. package/lib/src/generated/api/PerspectiveAddSdnaParams.d.ts +14 -0
  242. package/lib/src/generated/api/PerspectiveAddSdnaParams.js +1 -0
  243. package/lib/src/generated/api/PerspectiveAddSdnaResult.d.ts +4 -0
  244. package/lib/src/generated/api/PerspectiveAddSdnaResult.js +2 -0
  245. package/lib/src/generated/api/PerspectiveCommitBatchParams.d.ts +4 -0
  246. package/lib/src/generated/api/PerspectiveCommitBatchParams.js +2 -0
  247. package/lib/src/generated/api/PerspectiveCreateSubjectParams.d.ts +7 -0
  248. package/lib/src/generated/api/PerspectiveCreateSubjectParams.js +2 -0
  249. package/lib/src/generated/api/PerspectiveDiscardBatchParams.d.ts +4 -0
  250. package/lib/src/generated/api/PerspectiveDiscardBatchParams.js +2 -0
  251. package/lib/src/generated/api/PerspectiveEvaluateGettersParams.d.ts +9 -0
  252. package/lib/src/generated/api/PerspectiveEvaluateGettersParams.js +2 -0
  253. package/lib/src/generated/api/PerspectiveExecuteCommandsParams.d.ts +7 -0
  254. package/lib/src/generated/api/PerspectiveExecuteCommandsParams.js +2 -0
  255. package/lib/src/generated/api/PerspectiveExpression.d.ts +8 -0
  256. package/lib/src/generated/api/PerspectiveExpression.js +1 -0
  257. package/lib/src/generated/api/PerspectiveFlowFiredParams.d.ts +8 -0
  258. package/lib/src/generated/api/PerspectiveFlowFiredParams.js +2 -0
  259. package/lib/src/generated/api/PerspectiveFlowProposalParams.d.ts +4 -0
  260. package/lib/src/generated/api/PerspectiveFlowProposalParams.js +2 -0
  261. package/lib/src/generated/api/PerspectiveFlowReceiptVerdict.d.ts +12 -0
  262. package/lib/src/generated/api/PerspectiveFlowReceiptVerdict.js +1 -0
  263. package/lib/src/generated/api/PerspectiveFlowStatesParams.d.ts +11 -0
  264. package/lib/src/generated/api/PerspectiveFlowStatesParams.js +2 -0
  265. package/lib/src/generated/api/PerspectiveFlowValidOutputsParams.d.ts +8 -0
  266. package/lib/src/generated/api/PerspectiveFlowValidOutputsParams.js +2 -0
  267. package/lib/src/generated/api/PerspectiveGetAllShaclParams.d.ts +7 -0
  268. package/lib/src/generated/api/PerspectiveGetAllShaclParams.js +2 -0
  269. package/lib/src/generated/api/PerspectiveGetSubjectDataParams.d.ts +5 -0
  270. package/lib/src/generated/api/PerspectiveGetSubjectDataParams.js +2 -0
  271. package/lib/src/generated/api/PerspectiveHandle.d.ts +10 -0
  272. package/lib/src/generated/api/PerspectiveHandle.js +1 -0
  273. package/lib/src/generated/api/PerspectiveLinkDiff.d.ts +9 -0
  274. package/lib/src/generated/api/PerspectiveLinkDiff.js +1 -0
  275. package/lib/src/generated/api/PerspectiveLinkMutationsParams.d.ts +6 -0
  276. package/lib/src/generated/api/PerspectiveLinkMutationsParams.js +1 -0
  277. package/lib/src/generated/api/PerspectiveLinkUpdatedWithOwner.d.ts +7 -0
  278. package/lib/src/generated/api/PerspectiveLinkUpdatedWithOwner.js +1 -0
  279. package/lib/src/generated/api/PerspectiveLinkWithOwner.d.ts +6 -0
  280. package/lib/src/generated/api/PerspectiveLinkWithOwner.js +1 -0
  281. package/lib/src/generated/api/PerspectiveMintFlowReceiptParams.d.ts +4 -0
  282. package/lib/src/generated/api/PerspectiveMintFlowReceiptParams.js +2 -0
  283. package/lib/src/generated/api/PerspectiveMintFlowReceiptResult.d.ts +9 -0
  284. package/lib/src/generated/api/PerspectiveMintFlowReceiptResult.js +1 -0
  285. package/lib/src/generated/api/PerspectiveModelQueryParams.d.ts +13 -0
  286. package/lib/src/generated/api/PerspectiveModelQueryParams.js +2 -0
  287. package/lib/src/generated/api/PerspectiveNamedShacl.d.ts +6 -0
  288. package/lib/src/generated/api/PerspectiveNamedShacl.js +1 -0
  289. package/lib/src/generated/api/PerspectiveProposeFlowTransitionParams.d.ts +8 -0
  290. package/lib/src/generated/api/PerspectiveProposeFlowTransitionParams.js +1 -0
  291. package/lib/src/generated/api/PerspectiveQueryLinksParams.d.ts +15 -0
  292. package/lib/src/generated/api/PerspectiveQueryLinksParams.js +2 -0
  293. package/lib/src/generated/api/PerspectiveQueryParams.d.ts +4 -0
  294. package/lib/src/generated/api/PerspectiveQueryParams.js +2 -0
  295. package/lib/src/generated/api/PerspectiveReceiptOutcome.d.ts +1 -0
  296. package/lib/src/generated/api/PerspectiveReceiptOutcome.js +2 -0
  297. package/lib/src/generated/api/PerspectiveRejectFlowProposalResult.d.ts +3 -0
  298. package/lib/src/generated/api/PerspectiveRejectFlowProposalResult.js +2 -0
  299. package/lib/src/generated/api/PerspectiveRemoveAutoProcessorParams.d.ts +4 -0
  300. package/lib/src/generated/api/PerspectiveRemoveAutoProcessorParams.js +2 -0
  301. package/lib/src/generated/api/PerspectiveRemoveLinkParams.d.ts +6 -0
  302. package/lib/src/generated/api/PerspectiveRemoveLinkParams.js +1 -0
  303. package/lib/src/generated/api/PerspectiveRemoveLinksParams.d.ts +6 -0
  304. package/lib/src/generated/api/PerspectiveRemoveLinksParams.js +1 -0
  305. package/lib/src/generated/api/PerspectiveRemoveSubjectParams.d.ts +6 -0
  306. package/lib/src/generated/api/PerspectiveRemoveSubjectParams.js +2 -0
  307. package/lib/src/generated/api/PerspectiveRemovedWithOwner.d.ts +5 -0
  308. package/lib/src/generated/api/PerspectiveRemovedWithOwner.js +2 -0
  309. package/lib/src/generated/api/PerspectiveResolveInterpretationParams.d.ts +8 -0
  310. package/lib/src/generated/api/PerspectiveResolveInterpretationParams.js +2 -0
  311. package/lib/src/generated/api/PerspectiveResynced.d.ts +8 -0
  312. package/lib/src/generated/api/PerspectiveResynced.js +2 -0
  313. package/lib/src/generated/api/PerspectiveShacl.d.ts +5 -0
  314. package/lib/src/generated/api/PerspectiveShacl.js +1 -0
  315. package/lib/src/generated/api/PerspectiveShaclNameParams.d.ts +4 -0
  316. package/lib/src/generated/api/PerspectiveShaclNameParams.js +2 -0
  317. package/lib/src/generated/api/PerspectiveSparqlParams.d.ts +8 -0
  318. package/lib/src/generated/api/PerspectiveSparqlParams.js +2 -0
  319. package/lib/src/generated/api/PerspectiveState.d.ts +1 -0
  320. package/lib/src/generated/api/PerspectiveState.js +2 -0
  321. package/lib/src/generated/api/PerspectiveStateFilter.d.ts +7 -0
  322. package/lib/src/generated/api/PerspectiveStateFilter.js +1 -0
  323. package/lib/src/generated/api/PerspectiveSubjectClassesOfParams.d.ts +4 -0
  324. package/lib/src/generated/api/PerspectiveSubjectClassesOfParams.js +2 -0
  325. package/lib/src/generated/api/PerspectiveSubscribed.d.ts +10 -0
  326. package/lib/src/generated/api/PerspectiveSubscribed.js +2 -0
  327. package/lib/src/generated/api/PerspectiveSubscriptionParams.d.ts +4 -0
  328. package/lib/src/generated/api/PerspectiveSubscriptionParams.js +2 -0
  329. package/lib/src/generated/api/PerspectiveUnsignedInput.d.ts +4 -0
  330. package/lib/src/generated/api/PerspectiveUnsignedInput.js +1 -0
  331. package/lib/src/generated/api/PerspectiveUpdateLinkParams.d.ts +8 -0
  332. package/lib/src/generated/api/PerspectiveUpdateLinkParams.js +1 -0
  333. package/lib/src/generated/api/PerspectiveUpdateParams.d.ts +4 -0
  334. package/lib/src/generated/api/PerspectiveUpdateParams.js +2 -0
  335. package/lib/src/generated/api/PerspectiveUpdateSubjectParams.d.ts +10 -0
  336. package/lib/src/generated/api/PerspectiveUpdateSubjectParams.js +2 -0
  337. package/lib/src/generated/api/PerspectiveUuidParams.d.ts +3 -0
  338. package/lib/src/generated/api/PerspectiveUuidParams.js +2 -0
  339. package/lib/src/generated/api/PerspectiveVerifyFlowReceiptParams.d.ts +9 -0
  340. package/lib/src/generated/api/PerspectiveVerifyFlowReceiptParams.js +1 -0
  341. package/lib/src/generated/api/PerspectiveWithOwner.d.ts +6 -0
  342. package/lib/src/generated/api/PerspectiveWithOwner.js +1 -0
  343. package/lib/src/generated/api/ProposeOutcome.d.ts +45 -0
  344. package/lib/src/generated/api/ProposeOutcome.js +1 -0
  345. package/lib/src/generated/api/PublicPerspectiveInput.d.ts +4 -0
  346. package/lib/src/generated/api/PublicPerspectiveInput.js +1 -0
  347. package/lib/src/generated/api/PublishNeighbourhoodRequest.d.ts +2 -2
  348. package/lib/src/generated/api/QuerySubscriptionUpdate.d.ts +19 -0
  349. package/lib/src/generated/api/QuerySubscriptionUpdate.js +2 -0
  350. package/lib/src/generated/api/QuerySubscriptionUpdateEvent.d.ts +7 -0
  351. package/lib/src/generated/api/QuerySubscriptionUpdateEvent.js +1 -0
  352. package/lib/src/generated/api/QueryUpdatesLagged.d.ts +7 -0
  353. package/lib/src/generated/api/QueryUpdatesLagged.js +2 -0
  354. package/lib/src/generated/api/RemoveLinkRequest.d.ts +1 -1
  355. package/lib/src/generated/api/RemoveLinksBulkRequest.d.ts +1 -1
  356. package/lib/src/generated/api/RemoveSubjectRequest.d.ts +9 -0
  357. package/lib/src/generated/api/RemoveSubjectRequest.js +2 -0
  358. package/lib/src/generated/api/RequestCapabilityRequest.d.ts +4 -0
  359. package/lib/src/generated/api/RequestCapabilityRequest.js +1 -0
  360. package/lib/src/generated/api/RequestPaymentRequest.d.ts +3 -0
  361. package/lib/src/generated/api/RequestPaymentRequest.js +2 -0
  362. package/lib/src/generated/api/Resource.d.ts +4 -0
  363. package/lib/src/generated/api/Resource.js +2 -0
  364. package/lib/src/generated/api/ResyncSubscriptionRequest.d.ts +3 -0
  365. package/lib/src/generated/api/ResyncSubscriptionRequest.js +2 -0
  366. package/lib/src/generated/api/RpcMethods.d.ts +961 -0
  367. package/lib/src/generated/api/RpcMethods.js +98 -0
  368. package/lib/src/generated/api/RunInterpretationRequest.d.ts +27 -1
  369. package/lib/src/generated/api/RunInterpretationWithHarnessRequest.d.ts +52 -0
  370. package/lib/src/generated/api/RunInterpretationWithHarnessRequest.js +1 -0
  371. package/lib/src/generated/api/RuntimeComputeLogParams.d.ts +14 -0
  372. package/lib/src/generated/api/RuntimeComputeLogParams.js +2 -0
  373. package/lib/src/generated/api/RuntimeFriendStatusParams.d.ts +3 -0
  374. package/lib/src/generated/api/RuntimeFriendStatusParams.js +2 -0
  375. package/lib/src/generated/api/RuntimeGrantNotificationParams.d.ts +4 -0
  376. package/lib/src/generated/api/RuntimeGrantNotificationParams.js +2 -0
  377. package/lib/src/generated/api/RuntimeImportPerspectiveResult.d.ts +4 -0
  378. package/lib/src/generated/api/RuntimeImportPerspectiveResult.js +2 -0
  379. package/lib/src/generated/api/RuntimeImportResult.d.ts +6 -0
  380. package/lib/src/generated/api/RuntimeImportResult.js +1 -0
  381. package/lib/src/generated/api/RuntimeInfo.d.ts +5 -0
  382. package/lib/src/generated/api/RuntimeInfo.js +2 -0
  383. package/lib/src/generated/api/RuntimeNotificationIdParams.d.ts +3 -0
  384. package/lib/src/generated/api/RuntimeNotificationIdParams.js +2 -0
  385. package/lib/src/generated/api/RuntimeSendFriendMessageParams.d.ts +8 -0
  386. package/lib/src/generated/api/RuntimeSendFriendMessageParams.js +1 -0
  387. package/lib/src/generated/api/RuntimeSetFreeHostingEnabledParams.d.ts +3 -0
  388. package/lib/src/generated/api/RuntimeSetFreeHostingEnabledParams.js +2 -0
  389. package/lib/src/generated/api/RuntimeUnytSendHotParams.d.ts +4 -0
  390. package/lib/src/generated/api/RuntimeUnytSendHotParams.js +2 -0
  391. package/lib/src/generated/api/RuntimeUnytWalletHistoryParams.d.ts +4 -0
  392. package/lib/src/generated/api/RuntimeUnytWalletHistoryParams.js +2 -0
  393. package/lib/src/generated/api/RuntimeUpdateNotificationParams.d.ts +11 -0
  394. package/lib/src/generated/api/RuntimeUpdateNotificationParams.js +2 -0
  395. package/lib/src/generated/api/SentMessage.d.ts +5 -0
  396. package/lib/src/generated/api/SentMessage.js +1 -0
  397. package/lib/src/generated/api/SetHostRatesRequest.d.ts +4 -0
  398. package/lib/src/generated/api/SetHostRatesRequest.js +1 -0
  399. package/lib/src/generated/api/SetHotWalletAddressRequest.d.ts +3 -0
  400. package/lib/src/generated/api/SetHotWalletAddressRequest.js +2 -0
  401. package/lib/src/generated/api/SetOnlineStatusRequest.d.ts +4 -0
  402. package/lib/src/generated/api/SetOnlineStatusRequest.js +2 -0
  403. package/lib/src/generated/api/SetUnytMembraneProofRequest.d.ts +6 -0
  404. package/lib/src/generated/api/SetUnytMembraneProofRequest.js +2 -0
  405. package/lib/src/generated/api/SetUserFreeAccessRequest.d.ts +4 -0
  406. package/lib/src/generated/api/SetUserFreeAccessRequest.js +2 -0
  407. package/lib/src/generated/api/SfuAddIceCandidateParams.d.ts +8 -0
  408. package/lib/src/generated/api/SfuAddIceCandidateParams.js +2 -0
  409. package/lib/src/generated/api/SfuAnswerServerOfferParams.d.ts +8 -0
  410. package/lib/src/generated/api/SfuAnswerServerOfferParams.js +2 -0
  411. package/lib/src/generated/api/SfuCallJoinParams.d.ts +14 -0
  412. package/lib/src/generated/api/SfuCallJoinParams.js +2 -0
  413. package/lib/src/generated/api/SfuCallRenegotiationOffer.d.ts +30 -0
  414. package/lib/src/generated/api/SfuCallRenegotiationOffer.js +1 -0
  415. package/lib/src/generated/api/SfuCascadePipe.d.ts +4 -0
  416. package/lib/src/generated/api/SfuCascadePipe.js +2 -0
  417. package/lib/src/generated/api/SfuCascadeStatus.d.ts +8 -0
  418. package/lib/src/generated/api/SfuCascadeStatus.js +1 -0
  419. package/lib/src/generated/api/SfuConfig.d.ts +52 -0
  420. package/lib/src/generated/api/SfuConfig.js +1 -0
  421. package/lib/src/generated/api/SfuDataMessage.d.ts +24 -0
  422. package/lib/src/generated/api/SfuDataMessage.js +2 -0
  423. package/lib/src/generated/api/SfuEnsureMembershipParams.d.ts +4 -0
  424. package/lib/src/generated/api/SfuEnsureMembershipParams.js +2 -0
  425. package/lib/src/generated/api/SfuMigrateEvent.d.ts +21 -0
  426. package/lib/src/generated/api/SfuMigrateEvent.js +2 -0
  427. package/lib/src/generated/api/SfuNeighbourhoodParams.d.ts +3 -0
  428. package/lib/src/generated/api/SfuNeighbourhoodParams.js +2 -0
  429. package/lib/src/generated/api/SfuParticipantQualityPreference.d.ts +7 -0
  430. package/lib/src/generated/api/SfuParticipantQualityPreference.js +2 -0
  431. package/lib/src/generated/api/SfuPerspectiveParams.d.ts +6 -0
  432. package/lib/src/generated/api/SfuPerspectiveParams.js +2 -0
  433. package/lib/src/generated/api/SfuQualityPreferenceParams.d.ts +8 -0
  434. package/lib/src/generated/api/SfuQualityPreferenceParams.js +2 -0
  435. package/lib/src/generated/api/SfuRoomInfo.d.ts +11 -0
  436. package/lib/src/generated/api/SfuRoomInfo.js +1 -0
  437. package/lib/src/generated/api/SfuRoomParams.d.ts +4 -0
  438. package/lib/src/generated/api/SfuRoomParams.js +2 -0
  439. package/lib/src/generated/api/SfuRoomParticipantInfo.d.ts +11 -0
  440. package/lib/src/generated/api/SfuRoomParticipantInfo.js +2 -0
  441. package/lib/src/generated/api/SfuRoomRoster.d.ts +13 -0
  442. package/lib/src/generated/api/SfuRoomRoster.js +2 -0
  443. package/lib/src/generated/api/SfuSendDataParams.d.ts +10 -0
  444. package/lib/src/generated/api/SfuSendDataParams.js +2 -0
  445. package/lib/src/generated/api/SfuSetConfigParams.d.ts +5 -0
  446. package/lib/src/generated/api/SfuSetConfigParams.js +1 -0
  447. package/lib/src/generated/api/SfuStatus.d.ts +24 -0
  448. package/lib/src/generated/api/SfuStatus.js +2 -0
  449. package/lib/src/generated/api/ShaclLinkTriple.d.ts +10 -0
  450. package/lib/src/generated/api/ShaclLinkTriple.js +2 -0
  451. package/lib/src/generated/api/SignalRequest.d.ts +5 -0
  452. package/lib/src/generated/api/SignalRequest.js +2 -0
  453. package/lib/src/generated/api/SubscribeQueryRequest.d.ts +3 -0
  454. package/lib/src/generated/api/SubscribeQueryRequest.js +2 -0
  455. package/lib/src/generated/api/TokenizerSource.d.ts +5 -0
  456. package/lib/src/generated/api/TokenizerSource.js +2 -0
  457. package/lib/src/generated/api/TokenizerSourceInput.d.ts +5 -0
  458. package/lib/src/generated/api/TokenizerSourceInput.js +2 -0
  459. package/lib/src/generated/api/TrackMapEntry.d.ts +17 -0
  460. package/lib/src/generated/api/TrackMapEntry.js +2 -0
  461. package/lib/src/generated/api/TranscriptionTextFilter.d.ts +5 -0
  462. package/lib/src/generated/api/TranscriptionTextFilter.js +2 -0
  463. package/lib/src/generated/api/TriggeredNotification.d.ts +6 -0
  464. package/lib/src/generated/api/TriggeredNotification.js +1 -0
  465. package/lib/src/generated/api/TrustedAgentsWrapper.d.ts +6 -0
  466. package/lib/src/generated/api/TrustedAgentsWrapper.js +2 -0
  467. package/lib/src/generated/api/UnlockAgentRequest.d.ts +1 -1
  468. package/lib/src/generated/api/UnytVersionInfo.d.ts +19 -0
  469. package/lib/src/generated/api/UnytVersionInfo.js +2 -0
  470. package/lib/src/generated/api/UpdateLinkRequest.d.ts +1 -1
  471. package/lib/src/generated/api/UpdateProfileRequest.d.ts +5 -0
  472. package/lib/src/generated/api/UpdateProfileRequest.js +1 -0
  473. package/lib/src/generated/api/UpdateSubjectRequest.d.ts +12 -0
  474. package/lib/src/generated/api/UpdateSubjectRequest.js +2 -0
  475. package/lib/src/generated/api/UserCreationResult.d.ts +5 -0
  476. package/lib/src/generated/api/UserCreationResult.js +2 -0
  477. package/lib/src/generated/api/UserStatistics.d.ts +2 -1
  478. package/lib/src/generated/api/UserStatistics.js +0 -1
  479. package/lib/src/generated/api/UsersAppInfo.d.ts +6 -0
  480. package/lib/src/generated/api/UsersAppInfo.js +2 -0
  481. package/lib/src/generated/api/UsersEmailParams.d.ts +3 -0
  482. package/lib/src/generated/api/UsersEmailParams.js +2 -0
  483. package/lib/src/generated/api/UsersEmailTestAction.d.ts +1 -0
  484. package/lib/src/generated/api/UsersEmailTestAction.js +2 -0
  485. package/lib/src/generated/api/UsersEmailTestParams.d.ts +14 -0
  486. package/lib/src/generated/api/UsersEmailTestParams.js +1 -0
  487. package/lib/src/generated/api/UsersEmailTestResult.d.ts +5 -0
  488. package/lib/src/generated/api/UsersEmailTestResult.js +2 -0
  489. package/lib/src/generated/api/UsersLoginParams.d.ts +8 -0
  490. package/lib/src/generated/api/UsersLoginParams.js +2 -0
  491. package/lib/src/generated/api/UsersRequestVerificationParams.d.ts +5 -0
  492. package/lib/src/generated/api/UsersRequestVerificationParams.js +1 -0
  493. package/lib/src/generated/api/UsersSetCreditsParams.d.ts +4 -0
  494. package/lib/src/generated/api/UsersSetCreditsParams.js +2 -0
  495. package/lib/src/generated/api/UsersVerifyEmailParams.d.ts +12 -0
  496. package/lib/src/generated/api/UsersVerifyEmailParams.js +2 -0
  497. package/lib/src/generated/api/ValidOutput.d.ts +29 -0
  498. package/lib/src/generated/api/ValidOutput.js +1 -0
  499. package/lib/src/generated/api/VoiceActivityParamsInput.d.ts +7 -0
  500. package/lib/src/generated/api/VoiceActivityParamsInput.js +2 -0
  501. package/lib/src/generated/api/index.d.ts +11 -0
  502. package/lib/src/generated/api/index.js +5 -3
  503. package/lib/src/generated/api/serde_json/JsonValue.d.ts +3 -0
  504. package/lib/src/generated/api/serde_json/JsonValue.js +2 -0
  505. package/lib/src/index.d.ts +9 -3
  506. package/lib/src/index.js +5 -3
  507. package/lib/src/language/LanguageClient.d.ts +3 -3
  508. package/lib/src/language/LanguageClient.js +6 -6
  509. package/lib/src/language/LanguageMeta.d.ts +1 -1
  510. package/lib/src/links/Links.d.ts +16 -5
  511. package/lib/src/links/Links.js +34 -0
  512. package/lib/src/model/Ad4mModel.d.ts +84 -0
  513. package/lib/src/model/Ad4mModel.js +365 -72
  514. package/lib/src/model/ModelQueryBuilder.d.ts +15 -13
  515. package/lib/src/model/ModelQueryBuilder.js +78 -221
  516. package/lib/src/model/decorators.d.ts +52 -2
  517. package/lib/src/model/decorators.js +83 -8
  518. package/lib/src/model/query-sparql.js +2 -3
  519. package/lib/src/model/shacl-gen.d.ts +3 -1
  520. package/lib/src/model/shacl-gen.js +40 -10
  521. package/lib/src/model/types.d.ts +19 -0
  522. package/lib/src/neighbourhood/MeshManager.d.ts +384 -0
  523. package/lib/src/neighbourhood/MeshManager.js +1144 -0
  524. package/lib/src/neighbourhood/Neighbourhood.d.ts +1 -1
  525. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +96 -5
  526. package/lib/src/neighbourhood/NeighbourhoodClient.js +211 -15
  527. package/lib/src/neighbourhood/NeighbourhoodProxy.d.ts +55 -1
  528. package/lib/src/neighbourhood/NeighbourhoodProxy.js +170 -3
  529. package/lib/src/neighbourhood/Session.d.ts +105 -0
  530. package/lib/src/neighbourhood/Session.js +412 -0
  531. package/lib/src/neighbourhood/SfuManager.d.ts +174 -0
  532. package/lib/src/neighbourhood/SfuManager.js +619 -0
  533. package/lib/src/neighbourhood/SfuTypes.d.ts +35 -0
  534. package/lib/src/neighbourhood/SfuTypes.js +8 -0
  535. package/lib/src/notifyListeners.d.ts +2 -0
  536. package/lib/src/notifyListeners.js +12 -0
  537. package/lib/src/perspectives/AutoProcessor.d.ts +12 -80
  538. package/lib/src/perspectives/FlowInstance.d.ts +73 -26
  539. package/lib/src/perspectives/FlowInstance.js +96 -31
  540. package/lib/src/perspectives/FlowModels.d.ts +30 -9
  541. package/lib/src/perspectives/FlowModels.js +43 -14
  542. package/lib/src/perspectives/InterpretationModels.d.ts +2 -0
  543. package/lib/src/perspectives/InterpretationModels.js +6 -0
  544. package/lib/src/perspectives/LiveQuery.d.ts +49 -0
  545. package/lib/src/perspectives/LiveQuery.js +169 -0
  546. package/lib/src/perspectives/Perspective.d.ts +8 -1
  547. package/lib/src/perspectives/Perspective.js +11 -0
  548. package/lib/src/perspectives/PerspectiveClient.d.ts +38 -65
  549. package/lib/src/perspectives/PerspectiveClient.js +87 -257
  550. package/lib/src/perspectives/PerspectiveDiff.d.ts +1 -1
  551. package/lib/src/perspectives/PerspectiveHandle.d.ts +15 -8
  552. package/lib/src/perspectives/PerspectiveHandle.js +25 -9
  553. package/lib/src/perspectives/PerspectiveProxy.d.ts +102 -228
  554. package/lib/src/perspectives/PerspectiveProxy.js +247 -673
  555. package/lib/src/perspectives/TextContent.d.ts +31 -0
  556. package/lib/src/perspectives/TextContent.js +52 -0
  557. package/lib/src/perspectives/WakerSubscriptionManager.d.ts +23 -0
  558. package/lib/src/perspectives/WakerSubscriptionManager.js +58 -21
  559. package/lib/src/runtime/RuntimeClient.d.ts +15 -27
  560. package/lib/src/runtime/RuntimeClient.js +57 -113
  561. package/lib/src/runtime/RuntimeTypes.d.ts +2 -2
  562. package/lib/src/runtime/RuntimeTypes.js +2 -2
  563. package/lib/src/shacl/SHACLFlow.d.ts +34 -6
  564. package/lib/src/shacl/SHACLFlow.js +62 -15
  565. package/lib/src/shacl/SHACLShape.d.ts +12 -0
  566. package/lib/src/shacl/SHACLShape.js +206 -321
  567. package/package.json +15 -16
  568. package/pnpm-workspace.yaml +4 -1
  569. package/src/Ad4mClient.test.ts +481 -144
  570. package/src/Ad4mClient.ts +16 -12
  571. package/src/Literal.test.ts +32 -0
  572. package/src/Literal.ts +3 -3
  573. package/src/agent/Agent.ts +8 -0
  574. package/src/agent/AgentClient.ts +87 -195
  575. package/src/agent/mutatePublicPerspective.test.ts +110 -0
  576. package/src/ai/AIClient.ts +40 -43
  577. package/src/ai/transcription-stream.test.ts +54 -0
  578. package/src/apiClient.test.ts +613 -185
  579. package/src/apiClient.ts +282 -288
  580. package/src/cache/cache.test.ts +7 -8
  581. package/src/expression/Expression.ts +12 -3
  582. package/src/expression/ExpressionClient.ts +6 -7
  583. package/src/generated/api/AIPromptExamples.ts +3 -0
  584. package/src/generated/api/AIPromptExamplesInput.ts +3 -0
  585. package/src/generated/api/AITask.ts +4 -0
  586. package/src/generated/api/AITaskInput.ts +4 -0
  587. package/src/generated/api/AddAgentInfosRequest.ts +3 -0
  588. package/src/generated/api/AddLinkExpressionRequest.ts +1 -1
  589. package/src/generated/api/AddLinkRequest.ts +1 -1
  590. package/src/generated/api/AddLinksBulkRequest.ts +1 -1
  591. package/src/generated/api/AddSdnaRequest.ts +1 -1
  592. package/src/generated/api/Agent.ts +4 -0
  593. package/src/generated/api/AgentAddEntanglementProofsParams.ts +8 -0
  594. package/src/generated/api/AgentByDidParams.ts +3 -0
  595. package/src/generated/api/AgentRemoveAppParams.ts +3 -0
  596. package/src/generated/api/AgentRevokeTokenParams.ts +3 -0
  597. package/src/generated/api/AgentSignature.ts +3 -0
  598. package/src/generated/api/AgentStatus.ts +4 -0
  599. package/src/generated/api/AgentStatusChangedEvent.ts +7 -0
  600. package/src/generated/api/AgentUpdatedEvent.ts +7 -0
  601. package/src/generated/api/AgentsByDidsRequest.ts +3 -0
  602. package/src/generated/api/AiAddModelParams.ts +4 -0
  603. package/src/generated/api/AiAddTaskParams.ts +4 -0
  604. package/src/generated/api/AiDiscoverModelsParams.ts +7 -0
  605. package/src/generated/api/AiGetDefaultModelParams.ts +4 -0
  606. package/src/generated/api/AiIdParams.ts +3 -0
  607. package/src/generated/api/AiModelLoadingStatusParams.ts +6 -0
  608. package/src/generated/api/AiSetDefaultModelParams.ts +4 -0
  609. package/src/generated/api/AiTranscriptionCloseParams.ts +3 -0
  610. package/src/generated/api/AiTranscriptionOpenParams.ts +4 -0
  611. package/src/generated/api/AiUpdateModelParams.ts +4 -0
  612. package/src/generated/api/AiUpdateTaskParams.ts +4 -0
  613. package/src/generated/api/Apps.ts +4 -0
  614. package/src/generated/api/AuthInfo.ts +4 -0
  615. package/src/generated/api/AuthInfoInput.ts +1 -1
  616. package/src/generated/api/AutoProcessorEvent.ts +90 -0
  617. package/src/generated/api/AutoProcessorNeighbourhoodState.ts +33 -0
  618. package/src/generated/api/AutoProcessorStep.ts +9 -0
  619. package/src/generated/api/BroadcastRequest.ts +3 -0
  620. package/src/generated/api/CallSessionInfo.ts +20 -0
  621. package/src/generated/api/Capability.ts +4 -0
  622. package/src/generated/api/CreateSubjectRequest.ts +1 -1
  623. package/src/generated/api/CreateUserRequest.ts +3 -0
  624. package/src/generated/api/DateTime.ts +3 -0
  625. package/src/generated/api/DecoratedExpressionProof.ts +3 -0
  626. package/src/generated/api/DecoratedLinkExpression.ts +6 -0
  627. package/src/generated/api/DecoratedNeighbourhoodExpression.ts +5 -0
  628. package/src/generated/api/DecoratedPerspective.ts +4 -0
  629. package/src/generated/api/DiscardBatchRequest.ts +3 -0
  630. package/src/generated/api/DisposeQueryRequest.ts +3 -0
  631. package/src/generated/api/EntanglementProof.ts +3 -0
  632. package/src/generated/api/EntanglementProofInput.ts +1 -1
  633. package/src/generated/api/EntanglementProofPreflightRequest.ts +3 -0
  634. package/src/generated/api/EntanglementProofsWrapper.ts +7 -0
  635. package/src/generated/api/Events.ts +77 -0
  636. package/src/generated/api/ExceptionInfo.ts +4 -0
  637. package/src/generated/api/ExceptionOccurredEvent.ts +7 -0
  638. package/src/generated/api/ExceptionType.ts +3 -0
  639. package/src/generated/api/ExecuteCommandsRequest.ts +1 -1
  640. package/src/generated/api/ExportRequest.ts +1 -1
  641. package/src/generated/api/ExpressionInteractRequest.ts +4 -0
  642. package/src/generated/api/ExpressionProofInput.ts +1 -1
  643. package/src/generated/api/ExpressionRendered.ts +6 -0
  644. package/src/generated/api/ExpressionUrlRequest.ts +3 -0
  645. package/src/generated/api/FireOutcome.ts +11 -0
  646. package/src/generated/api/FlowStateChangedEvent.ts +36 -0
  647. package/src/generated/api/FlowStateEntry.ts +18 -0
  648. package/src/generated/api/FriendSendMessageRequest.ts +1 -1
  649. package/src/generated/api/HostRate.ts +6 -0
  650. package/src/generated/api/HostingInfoResult.ts +13 -0
  651. package/src/generated/api/HostingInfoUser.ts +7 -0
  652. package/src/generated/api/HostingRequestPaymentResult.ts +3 -0
  653. package/src/generated/api/HostingUserInfo.ts +3 -0
  654. package/src/generated/api/HostingVersionInfo.ts +7 -0
  655. package/src/generated/api/HostingWalletResult.ts +8 -0
  656. package/src/generated/api/IceServer.ts +19 -0
  657. package/src/generated/api/Icon.ts +3 -0
  658. package/src/generated/api/ImportResult.ts +4 -0
  659. package/src/generated/api/ImportStats.ts +3 -0
  660. package/src/generated/api/InteractionCall.ts +3 -0
  661. package/src/generated/api/InteractionCallWrapper.ts +6 -0
  662. package/src/generated/api/InteractionMeta.ts +4 -0
  663. package/src/generated/api/InteractionParameter.ts +3 -0
  664. package/src/generated/api/LanguageAddressParams.ts +3 -0
  665. package/src/generated/api/LanguageHandle.ts +4 -0
  666. package/src/generated/api/LanguageListParams.ts +3 -0
  667. package/src/generated/api/LanguageMeta.ts +3 -0
  668. package/src/generated/api/LanguageMetaInput.ts +1 -1
  669. package/src/generated/api/LanguageRef.ts +3 -0
  670. package/src/generated/api/LanguageSettingsWrapper.ts +6 -0
  671. package/src/generated/api/LanguageWriteSettingsParams.ts +3 -0
  672. package/src/generated/api/LinkExpressionInput.ts +1 -1
  673. package/src/generated/api/LinkInput.ts +1 -1
  674. package/src/generated/api/LinkMutationRequest.ts +8 -0
  675. package/src/generated/api/LinkMutationsRequest.ts +4 -0
  676. package/src/generated/api/LinkStatus.ts +1 -1
  677. package/src/generated/api/LinkUpdateInput.ts +4 -0
  678. package/src/generated/api/LocalModel.ts +4 -0
  679. package/src/generated/api/LocalModelInput.ts +4 -0
  680. package/src/generated/api/MessageReceivedEvent.ts +7 -0
  681. package/src/generated/api/Model.ts +6 -0
  682. package/src/generated/api/ModelApi.ts +14 -0
  683. package/src/generated/api/ModelApiInput.ts +8 -0
  684. package/src/generated/api/ModelApiType.ts +3 -0
  685. package/src/generated/api/ModelInput.ts +6 -0
  686. package/src/generated/api/ModelType.ts +1 -1
  687. package/src/generated/api/Neighbourhood.ts +4 -0
  688. package/src/generated/api/NeighbourhoodBroadcastParams.ts +4 -0
  689. package/src/generated/api/NeighbourhoodOnlineStatusParams.ts +4 -0
  690. package/src/generated/api/NeighbourhoodPerspectivePayload.ts +9 -0
  691. package/src/generated/api/NeighbourhoodPhase.ts +8 -0
  692. package/src/generated/api/NeighbourhoodSignalFilter.ts +5 -0
  693. package/src/generated/api/NeighbourhoodSignalParams.ts +4 -0
  694. package/src/generated/api/NeighbourhoodSignedPerspective.ts +8 -0
  695. package/src/generated/api/NeighbourhoodUuidParams.ts +3 -0
  696. package/src/generated/api/Notification.ts +7 -0
  697. package/src/generated/api/NotificationGrantRequest.ts +6 -0
  698. package/src/generated/api/NotificationInput.ts +1 -1
  699. package/src/generated/api/NotificationTriggeredEvent.ts +8 -0
  700. package/src/generated/api/OnlineAgent.ts +9 -0
  701. package/src/generated/api/OutputRef.ts +11 -0
  702. package/src/generated/api/OverlayView.ts +25 -0
  703. package/src/generated/api/Perspective.ts +4 -0
  704. package/src/generated/api/PerspectiveAddAutoProcessorParams.ts +11 -0
  705. package/src/generated/api/PerspectiveAddLinkExpressionParams.ts +4 -0
  706. package/src/generated/api/PerspectiveAddLinkParams.ts +4 -0
  707. package/src/generated/api/PerspectiveAddLinksParams.ts +4 -0
  708. package/src/generated/api/PerspectiveAddSdnaParams.ts +7 -0
  709. package/src/generated/api/PerspectiveAddSdnaResult.ts +6 -0
  710. package/src/generated/api/PerspectiveCommitBatchParams.ts +3 -0
  711. package/src/generated/api/PerspectiveCreateSubjectParams.ts +3 -0
  712. package/src/generated/api/PerspectiveDiscardBatchParams.ts +3 -0
  713. package/src/generated/api/PerspectiveEvaluateGettersParams.ts +6 -0
  714. package/src/generated/api/PerspectiveExecuteCommandsParams.ts +3 -0
  715. package/src/generated/api/PerspectiveExpression.ts +5 -0
  716. package/src/generated/api/PerspectiveFlowFiredParams.ts +7 -0
  717. package/src/generated/api/PerspectiveFlowProposalParams.ts +3 -0
  718. package/src/generated/api/PerspectiveFlowReceiptVerdict.ts +8 -0
  719. package/src/generated/api/PerspectiveFlowStatesParams.ts +11 -0
  720. package/src/generated/api/PerspectiveFlowValidOutputsParams.ts +7 -0
  721. package/src/generated/api/PerspectiveGetAllShaclParams.ts +6 -0
  722. package/src/generated/api/PerspectiveGetSubjectDataParams.ts +3 -0
  723. package/src/generated/api/PerspectiveHandle.ts +5 -0
  724. package/src/generated/api/PerspectiveLinkDiff.ts +7 -0
  725. package/src/generated/api/PerspectiveLinkMutationsParams.ts +4 -0
  726. package/src/generated/api/PerspectiveLinkUpdatedWithOwner.ts +4 -0
  727. package/src/generated/api/PerspectiveLinkWithOwner.ts +4 -0
  728. package/src/generated/api/PerspectiveMintFlowReceiptParams.ts +3 -0
  729. package/src/generated/api/PerspectiveMintFlowReceiptResult.ts +9 -0
  730. package/src/generated/api/PerspectiveModelQueryParams.ts +10 -0
  731. package/src/generated/api/PerspectiveNamedShacl.ts +4 -0
  732. package/src/generated/api/PerspectiveProposeFlowTransitionParams.ts +4 -0
  733. package/src/generated/api/PerspectiveQueryLinksParams.ts +11 -0
  734. package/src/generated/api/PerspectiveQueryParams.ts +3 -0
  735. package/src/generated/api/PerspectiveReceiptOutcome.ts +3 -0
  736. package/src/generated/api/PerspectiveRejectFlowProposalResult.ts +3 -0
  737. package/src/generated/api/PerspectiveRemoveAutoProcessorParams.ts +3 -0
  738. package/src/generated/api/PerspectiveRemoveLinkParams.ts +4 -0
  739. package/src/generated/api/PerspectiveRemoveLinksParams.ts +4 -0
  740. package/src/generated/api/PerspectiveRemoveSubjectParams.ts +3 -0
  741. package/src/generated/api/PerspectiveRemovedWithOwner.ts +3 -0
  742. package/src/generated/api/PerspectiveResolveInterpretationParams.ts +6 -0
  743. package/src/generated/api/PerspectiveResynced.ts +7 -0
  744. package/src/generated/api/PerspectiveShacl.ts +4 -0
  745. package/src/generated/api/PerspectiveShaclNameParams.ts +3 -0
  746. package/src/generated/api/PerspectiveSparqlParams.ts +7 -0
  747. package/src/generated/api/PerspectiveState.ts +3 -0
  748. package/src/generated/api/PerspectiveStateFilter.ts +5 -0
  749. package/src/generated/api/PerspectiveSubjectClassesOfParams.ts +3 -0
  750. package/src/generated/api/PerspectiveSubscribed.ts +8 -0
  751. package/src/generated/api/PerspectiveSubscriptionParams.ts +3 -0
  752. package/src/generated/api/PerspectiveUnsignedInput.ts +4 -0
  753. package/src/generated/api/PerspectiveUpdateLinkParams.ts +5 -0
  754. package/src/generated/api/PerspectiveUpdateParams.ts +3 -0
  755. package/src/generated/api/PerspectiveUpdateSubjectParams.ts +7 -0
  756. package/src/generated/api/PerspectiveUuidParams.ts +3 -0
  757. package/src/generated/api/PerspectiveVerifyFlowReceiptParams.ts +9 -0
  758. package/src/generated/api/PerspectiveWithOwner.ts +4 -0
  759. package/src/generated/api/ProposeOutcome.ts +46 -0
  760. package/src/generated/api/PublicPerspectiveInput.ts +4 -0
  761. package/src/generated/api/PublishNeighbourhoodRequest.ts +2 -2
  762. package/src/generated/api/QuerySubscriptionUpdate.ts +10 -0
  763. package/src/generated/api/QuerySubscriptionUpdateEvent.ts +9 -0
  764. package/src/generated/api/QueryUpdatesLagged.ts +7 -0
  765. package/src/generated/api/RemoveLinkRequest.ts +1 -1
  766. package/src/generated/api/RemoveLinksBulkRequest.ts +1 -1
  767. package/src/generated/api/RemoveSubjectRequest.ts +7 -0
  768. package/src/generated/api/RequestCapabilityRequest.ts +4 -0
  769. package/src/generated/api/RequestPaymentRequest.ts +3 -0
  770. package/src/generated/api/Resource.ts +3 -0
  771. package/src/generated/api/ResyncSubscriptionRequest.ts +3 -0
  772. package/src/generated/api/RpcMethods.ts +479 -0
  773. package/src/generated/api/RunInterpretationRequest.ts +28 -2
  774. package/src/generated/api/RunInterpretationWithHarnessRequest.ts +51 -0
  775. package/src/generated/api/RuntimeComputeLogParams.ts +15 -0
  776. package/src/generated/api/RuntimeFriendStatusParams.ts +3 -0
  777. package/src/generated/api/RuntimeGrantNotificationParams.ts +3 -0
  778. package/src/generated/api/RuntimeImportPerspectiveResult.ts +3 -0
  779. package/src/generated/api/RuntimeImportResult.ts +8 -0
  780. package/src/generated/api/RuntimeInfo.ts +3 -0
  781. package/src/generated/api/RuntimeNotificationIdParams.ts +3 -0
  782. package/src/generated/api/RuntimeSendFriendMessageParams.ts +8 -0
  783. package/src/generated/api/RuntimeSetFreeHostingEnabledParams.ts +3 -0
  784. package/src/generated/api/RuntimeUnytSendHotParams.ts +3 -0
  785. package/src/generated/api/RuntimeUnytWalletHistoryParams.ts +3 -0
  786. package/src/generated/api/RuntimeUpdateNotificationParams.ts +3 -0
  787. package/src/generated/api/SentMessage.ts +4 -0
  788. package/src/generated/api/SetHostRatesRequest.ts +4 -0
  789. package/src/generated/api/SetHotWalletAddressRequest.ts +3 -0
  790. package/src/generated/api/SetOnlineStatusRequest.ts +3 -0
  791. package/src/generated/api/SetUnytMembraneProofRequest.ts +7 -0
  792. package/src/generated/api/SetUserFreeAccessRequest.ts +3 -0
  793. package/src/generated/api/SfuAddIceCandidateParams.ts +7 -0
  794. package/src/generated/api/SfuAnswerServerOfferParams.ts +7 -0
  795. package/src/generated/api/SfuCallJoinParams.ts +13 -0
  796. package/src/generated/api/SfuCallRenegotiationOffer.ts +29 -0
  797. package/src/generated/api/SfuCascadePipe.ts +3 -0
  798. package/src/generated/api/SfuCascadeStatus.ts +7 -0
  799. package/src/generated/api/SfuConfig.ts +53 -0
  800. package/src/generated/api/SfuDataMessage.ts +23 -0
  801. package/src/generated/api/SfuEnsureMembershipParams.ts +3 -0
  802. package/src/generated/api/SfuMigrateEvent.ts +20 -0
  803. package/src/generated/api/SfuNeighbourhoodParams.ts +3 -0
  804. package/src/generated/api/SfuParticipantQualityPreference.ts +6 -0
  805. package/src/generated/api/SfuPerspectiveParams.ts +6 -0
  806. package/src/generated/api/SfuQualityPreferenceParams.ts +7 -0
  807. package/src/generated/api/SfuRoomInfo.ts +7 -0
  808. package/src/generated/api/SfuRoomParams.ts +3 -0
  809. package/src/generated/api/SfuRoomParticipantInfo.ts +8 -0
  810. package/src/generated/api/SfuRoomRoster.ts +12 -0
  811. package/src/generated/api/SfuSendDataParams.ts +7 -0
  812. package/src/generated/api/SfuSetConfigParams.ts +4 -0
  813. package/src/generated/api/SfuStatus.ts +24 -0
  814. package/src/generated/api/ShaclLinkTriple.ts +8 -0
  815. package/src/generated/api/SignalRequest.ts +3 -0
  816. package/src/generated/api/SubscribeQueryRequest.ts +3 -0
  817. package/src/generated/api/TokenizerSource.ts +3 -0
  818. package/src/generated/api/TokenizerSourceInput.ts +3 -0
  819. package/src/generated/api/TrackMapEntry.ts +18 -0
  820. package/src/generated/api/TranscriptionTextFilter.ts +3 -0
  821. package/src/generated/api/TriggeredNotification.ts +4 -0
  822. package/src/generated/api/TrustedAgentsWrapper.ts +6 -0
  823. package/src/generated/api/UnlockAgentRequest.ts +1 -1
  824. package/src/generated/api/UnytVersionInfo.ts +20 -0
  825. package/src/generated/api/UpdateLinkRequest.ts +1 -1
  826. package/src/generated/api/UpdateProfileRequest.ts +4 -0
  827. package/src/generated/api/UpdateSubjectRequest.ts +10 -0
  828. package/src/generated/api/UserCreationResult.ts +3 -0
  829. package/src/generated/api/UserStatistics.ts +2 -1
  830. package/src/generated/api/UsersAppInfo.ts +6 -0
  831. package/src/generated/api/UsersEmailParams.ts +3 -0
  832. package/src/generated/api/UsersEmailTestAction.ts +3 -0
  833. package/src/generated/api/UsersEmailTestParams.ts +12 -0
  834. package/src/generated/api/UsersEmailTestResult.ts +7 -0
  835. package/src/generated/api/UsersLoginParams.ts +7 -0
  836. package/src/generated/api/UsersRequestVerificationParams.ts +4 -0
  837. package/src/generated/api/UsersSetCreditsParams.ts +3 -0
  838. package/src/generated/api/UsersVerifyEmailParams.ts +11 -0
  839. package/src/generated/api/ValidOutput.ts +30 -0
  840. package/src/generated/api/VoiceActivityParamsInput.ts +3 -0
  841. package/src/generated/api/index.ts +14 -2
  842. package/src/generated/api/serde_json/JsonValue.ts +3 -0
  843. package/src/index.ts +9 -3
  844. package/src/language/LanguageClient.ts +12 -13
  845. package/src/links/Links.ts +49 -3
  846. package/src/model/Ad4mModel.test.ts +480 -173
  847. package/src/model/Ad4mModel.ts +407 -77
  848. package/src/model/ModelQueryBuilder.ts +95 -255
  849. package/src/model/abstract-classes.test.ts +225 -0
  850. package/src/model/decorators.ts +145 -9
  851. package/src/model/query-sparql.ts +2 -3
  852. package/src/model/relation-filtering.test.ts +191 -0
  853. package/src/model/shacl-gen.ts +32 -9
  854. package/src/model/shacl-roundtrip.test.ts +52 -0
  855. package/src/model/types.ts +19 -0
  856. package/src/neighbourhood/MeshManager.test.ts +2640 -0
  857. package/src/neighbourhood/MeshManager.ts +1350 -0
  858. package/src/neighbourhood/NeighbourhoodClient.test.ts +60 -0
  859. package/src/neighbourhood/NeighbourhoodClient.ts +298 -27
  860. package/src/neighbourhood/NeighbourhoodProxy.test.ts +37 -9
  861. package/src/neighbourhood/NeighbourhoodProxy.ts +247 -1
  862. package/src/neighbourhood/Session.test.ts +800 -0
  863. package/src/neighbourhood/Session.ts +525 -0
  864. package/src/neighbourhood/SfuManager.test.ts +677 -0
  865. package/src/neighbourhood/SfuManager.ts +803 -0
  866. package/src/neighbourhood/SfuTypes.ts +40 -0
  867. package/src/notifyListeners.test.ts +19 -0
  868. package/src/notifyListeners.ts +10 -0
  869. package/src/perspectives/AutoProcessor.ts +13 -82
  870. package/src/perspectives/FlowInstance.ts +136 -32
  871. package/src/perspectives/FlowModels.ts +46 -11
  872. package/src/perspectives/InterpretationModels.ts +4 -0
  873. package/src/perspectives/LiveQuery.test.ts +197 -0
  874. package/src/perspectives/LiveQuery.ts +189 -0
  875. package/src/perspectives/Perspective.ts +18 -2
  876. package/src/perspectives/PerspectiveClient.test.ts +122 -45
  877. package/src/perspectives/PerspectiveClient.ts +146 -343
  878. package/src/perspectives/PerspectiveHandle.ts +32 -9
  879. package/src/perspectives/PerspectiveProxy.test.ts +216 -528
  880. package/src/perspectives/PerspectiveProxy.ts +259 -736
  881. package/src/perspectives/TextContent.test.ts +123 -0
  882. package/src/perspectives/TextContent.ts +36 -0
  883. package/src/perspectives/WakerSubscriptionManager.test.ts +136 -1
  884. package/src/perspectives/WakerSubscriptionManager.ts +69 -22
  885. package/src/perspectives/link-updated-type.test.ts +55 -0
  886. package/src/perspectives/listener-leaks.test.ts +204 -0
  887. package/src/perspectives/shacl-rpc.test.ts +22 -27
  888. package/src/runtime/RuntimeClient.ts +75 -157
  889. package/src/runtime/RuntimeTypes.ts +3 -3
  890. package/src/shacl/SHACLFlow.test.ts +49 -1
  891. package/src/shacl/SHACLFlow.ts +73 -15
  892. package/src/shacl/SHACLShape.test.ts +161 -16
  893. package/src/shacl/SHACLShape.ts +210 -439
  894. package/lib/shims/reflect-metadata.d.ts +0 -0
  895. package/lib/shims/reflect-metadata.js +0 -0
  896. package/lib/shims/type-graphql.d.ts +0 -32
  897. package/lib/shims/type-graphql.js +0 -70
  898. package/lib/src/PubSub.d.ts +0 -17
  899. package/lib/src/PubSub.js +0 -17
  900. package/lib/src/agent/AgentResolver.d.ts +0 -30
  901. package/lib/src/agent/AgentResolver.js +0 -325
  902. package/lib/src/ai/AIResolver.d.ts +0 -75
  903. package/lib/src/ai/AIResolver.js +0 -455
  904. package/lib/src/buildSchema.d.ts +0 -1
  905. package/lib/src/buildSchema.js +0 -38
  906. package/lib/src/expression/ExpressionResolver.d.ts +0 -10
  907. package/lib/src/expression/ExpressionResolver.js +0 -106
  908. package/lib/src/language/LanguageContext.d.ts +0 -37
  909. package/lib/src/language/LanguageContext.js +0 -2
  910. package/lib/src/language/LanguageResolver.d.ts +0 -19
  911. package/lib/src/language/LanguageResolver.js +0 -143
  912. package/lib/src/links/Links.test.js +0 -33
  913. package/lib/src/model/Ad4mModel.test.js +0 -2055
  914. package/lib/src/model/Subject.d.ts +0 -25
  915. package/lib/src/model/Subject.js +0 -164
  916. package/lib/src/model/hydration-batch.d.ts +0 -34
  917. package/lib/src/model/hydration-batch.js +0 -147
  918. package/lib/src/model/hydration-batching.test.d.ts +0 -7
  919. package/lib/src/model/hydration-batching.test.js +0 -456
  920. package/lib/src/model/model-manifest.d.ts +0 -41
  921. package/lib/src/model/model-manifest.js +0 -11
  922. package/lib/src/model/prolog-facts.d.ts +0 -37
  923. package/lib/src/model/prolog-facts.js +0 -134
  924. package/lib/src/model/query-cache.test.js +0 -43
  925. package/lib/src/model/query-prolog.d.ts +0 -15
  926. package/lib/src/model/query-prolog.js +0 -140
  927. package/lib/src/model/query-sparql-batch.d.ts +0 -17
  928. package/lib/src/model/query-sparql-batch.js +0 -260
  929. package/lib/src/model/query-sparql.test.js +0 -312
  930. package/lib/src/model/relation-filtering.test.js +0 -838
  931. package/lib/src/model/subscription-delta.test.d.ts +0 -24
  932. package/lib/src/model/subscription-delta.test.js +0 -180
  933. package/lib/src/model/subscription-pool.d.ts +0 -39
  934. package/lib/src/model/subscription-pool.js +0 -165
  935. package/lib/src/neighbourhood/NeighbourhoodProxy.test.js +0 -73
  936. package/lib/src/neighbourhood/NeighbourhoodResolver.d.ts +0 -24
  937. package/lib/src/neighbourhood/NeighbourhoodResolver.js +0 -182
  938. package/lib/src/perspectives/Perspective.test.js +0 -20
  939. package/lib/src/perspectives/PerspectiveClient.test.js +0 -224
  940. package/lib/src/perspectives/PerspectiveResolver.d.ts +0 -56
  941. package/lib/src/perspectives/PerspectiveResolver.js +0 -519
  942. package/lib/src/runtime/RuntimeResolver.d.ts +0 -173
  943. package/lib/src/runtime/RuntimeResolver.js +0 -1122
  944. package/lib/src/schema.gql +0 -631
  945. package/lib/src/shacl/SHACLFlow.test.js +0 -205
  946. package/lib/src/shacl/SHACLShape.test.js +0 -418
  947. package/lib/src/unwrapApolloResult.d.ts +0 -2
  948. package/lib/src/unwrapApolloResult.js +0 -14
  949. /package/lib/src/{links/Links.test.d.ts → generated/api/AITask.js} +0 -0
  950. /package/lib/src/{model/Ad4mModel.test.d.ts → generated/api/AITaskInput.js} +0 -0
  951. /package/lib/src/{model/query-cache.test.d.ts → generated/api/Agent.js} +0 -0
  952. /package/lib/src/{model/query-sparql.test.d.ts → generated/api/AgentAddEntanglementProofsParams.js} +0 -0
  953. /package/lib/src/{model/relation-filtering.test.d.ts → generated/api/AgentStatus.js} +0 -0
  954. /package/lib/src/{neighbourhood/NeighbourhoodProxy.test.d.ts → generated/api/AgentStatusChangedEvent.js} +0 -0
  955. /package/lib/src/{perspectives/Perspective.test.d.ts → generated/api/AgentUpdatedEvent.js} +0 -0
  956. /package/lib/src/{perspectives/PerspectiveClient.test.d.ts → generated/api/AiAddModelParams.js} +0 -0
  957. /package/lib/src/{shacl/SHACLFlow.test.d.ts → generated/api/AiAddTaskParams.js} +0 -0
  958. /package/lib/src/{shacl/SHACLShape.test.d.ts → generated/api/AiGetDefaultModelParams.js} +0 -0
@@ -0,0 +1,1350 @@
1
+ /**
2
+ * Peer-to-peer WebRTC mesh transport for the AD4M SDK Session interface.
3
+ *
4
+ * Ported from WE Framework's call module (`mesh.ts` and `protocol.ts`), which
5
+ * stays wire-compatible with it: a WE mesh peer and an SDK mesh peer in the
6
+ * same call negotiate with each other.
7
+ *
8
+ * ## Mesh, not SFU
9
+ *
10
+ * Every participant connects to every other, so N participants means N−1
11
+ * connections each and each peer uploads its video N−1 times. That caps at
12
+ * roughly four to six peers before upstream bandwidth becomes the limit. The
13
+ * SFU path (`SfuManager`) handles larger rooms; this path needs no server.
14
+ *
15
+ * ## Membership comes from the roster; this class only negotiates
16
+ *
17
+ * {@link MeshManager.setRoster} receives whoever presence says is in the call.
18
+ * Connections are reconciled against it: appear → connect, disappear → tear
19
+ * down. There is no join or leave message, because a peer that crashes never
20
+ * sends one.
21
+ *
22
+ * ## Perfect negotiation
23
+ *
24
+ * Both peers see each other join at slightly different moments and both fire
25
+ * `negotiationneeded`, so offers collide. Each pair has a **polite** peer and
26
+ * an **impolite** one, decided by comparing DIDs, which needs no agreement
27
+ * round-trip. On collision the impolite peer ignores the incoming offer and
28
+ * the polite peer rolls back its own.
29
+ *
30
+ * ## The signalling channel is not reliable
31
+ *
32
+ * Perfect negotiation assumes a reliable ordered channel. Telepresence is
33
+ * neither: the executor confirms it took a message and nothing confirms a peer
34
+ * received it, sends are dispatched concurrently, and the first broadcast on a
35
+ * freshly joined neighbourhood has been measured at eighteen seconds. Against
36
+ * that, a lost offer deadlocks a pair, a candidate overtaking its description
37
+ * gets discarded, and concurrent handling corrupts the state machine. Four
38
+ * mechanisms fix that:
39
+ *
40
+ * 1. **Per-peer serialisation.** Signalling for one peer runs one message at a
41
+ * time ({@link MeshManager.enqueue}).
42
+ * 2. **Candidate buffering.** Candidates arriving before a remote description
43
+ * wait for one.
44
+ * 3. **A recovery ladder.** ICE restart → resend the description → rebuild the
45
+ * pair, escalating, on a sweep ({@link MeshManager.tick}).
46
+ * 4. **A `reset` message**, so a rebuild is agreed rather than unilateral.
47
+ *
48
+ * ## Which connection a message is about
49
+ *
50
+ * A pair has many connections over its life — a rebuild, a reset, a peer that
51
+ * reloads — and the two sides routinely disagree for a moment about which one
52
+ * is current. Applied to the wrong connection, a description is refused by the
53
+ * browser ("The order of m-lines in subsequent offer doesn't match order from
54
+ * previous offer/answer"). So every connection names itself
55
+ * ({@link PeerSlot.generation}) and every message says which connection sent it
56
+ * and which it is for ({@link CallGenerations}). See {@link MeshManager.placeOf}.
57
+ *
58
+ * ## Who repairs
59
+ *
60
+ * Recovery uses the same tie-break as offers: the impolite peer acts first.
61
+ * The polite peer runs the same ladder on a doubled deadline, which covers the
62
+ * case where the impolite side has no slot for the pair at all.
63
+ *
64
+ * ## Signalling via telepresence
65
+ *
66
+ * SDP and ICE travel through the neighbourhood's telepresence channel
67
+ * (`sendBroadcastU` / `addSignalHandler`). See {@link createTelepresenceChannel}.
68
+ */
69
+
70
+ import type { PerspectiveExpression, PerspectiveUnsignedInput } from "../perspectives/Perspective"
71
+ import type { SfuDataMessage } from "./SfuTypes"
72
+
73
+ // ── Protocol ────────────────────────────────────────────────────────
74
+
75
+ /**
76
+ * Checked on receipt; a mismatch is dropped. New message kinds and the
77
+ * generation fields were added without a bump: an old peer ignores a kind it
78
+ * does not know and never reads the generations, so old and new peers still
79
+ * converge. A bump would make them drop every message from each other.
80
+ */
81
+ export const CALL_PROTOCOL_VERSION = 1
82
+
83
+ /**
84
+ * Which of the sender's connections a message comes from, and which of the
85
+ * receiver's it is for. Both are optional; a message without them is read as
86
+ * it was before generations existed.
87
+ */
88
+ export interface CallGenerations {
89
+ /** The sender's connection, an id it chose when it made the connection. */
90
+ gen?: string
91
+ /** The receiver's connection as the sender last heard it named. */
92
+ peerGen?: string
93
+ }
94
+
95
+ export type CallBody =
96
+ /**
97
+ * `offer` numbers the offers of one connection: an offer carries its own,
98
+ * an answer the one it answers. An answer to an offer this side has since
99
+ * replaced is refused by the browser, so it is dropped instead. Optional:
100
+ * a peer predating it sends none, and its answers apply as before.
101
+ */
102
+ | { kind: "description"; description: RTCSessionDescriptionInit; offer?: number }
103
+ | { kind: "ice"; candidate: RTCIceCandidateInit }
104
+ /** Throw this pair's connection away and build a new one. */
105
+ | { kind: "reset" }
106
+ /** Application data, relayed over signalling because the mesh has no server. SDK-only. */
107
+ | { kind: "data"; label: string; data: string; binary: boolean }
108
+
109
+ export interface CallEnvelope extends CallGenerations {
110
+ v: number
111
+ call: string
112
+ }
113
+
114
+ export type CallMessage = CallEnvelope & CallBody
115
+
116
+ /**
117
+ * Narrow an untrusted payload off the transport.
118
+ *
119
+ * Everything arriving here was published by another agent, so it gets
120
+ * shape-checked before use. The sender id comes from the transport rather
121
+ * than the payload — a self-reported `from` would lack authentication.
122
+ */
123
+ export function parseCallMessage(payload: unknown): CallMessage | null {
124
+ if (typeof payload !== "object" || payload === null) return null
125
+ const msg = payload as Partial<CallMessage>
126
+
127
+ if (msg.v !== CALL_PROTOCOL_VERSION) return null
128
+ if (typeof msg.call !== "string" || !msg.call) return null
129
+
130
+ // A malformed generation is dropped rather than failing the message,
131
+ // which leaves it read as a message from a peer that predates them.
132
+ const envelope: CallEnvelope = { v: msg.v, call: msg.call }
133
+ if (typeof msg.gen === "string" && msg.gen) envelope.gen = msg.gen
134
+ if (typeof msg.peerGen === "string" && msg.peerGen) envelope.peerGen = msg.peerGen
135
+
136
+ if (msg.kind === "description") {
137
+ const description = (msg as { description?: unknown }).description
138
+ if (typeof description !== "object" || description === null) return null
139
+ const { type, sdp } = description as RTCSessionDescriptionInit
140
+ if (type !== "offer" && type !== "answer" && type !== "pranswer" && type !== "rollback") return null
141
+ if (sdp !== undefined && typeof sdp !== "string") return null
142
+ const offer = (msg as { offer?: unknown }).offer
143
+ return {
144
+ ...envelope,
145
+ kind: "description",
146
+ description: { type, sdp },
147
+ ...(Number.isSafeInteger(offer) ? { offer: offer as number } : {}),
148
+ }
149
+ }
150
+
151
+ if (msg.kind === "ice") {
152
+ const candidate = (msg as { candidate?: unknown }).candidate
153
+ if (typeof candidate !== "object" || candidate === null) return null
154
+ return { ...envelope, kind: "ice", candidate: candidate as RTCIceCandidateInit }
155
+ }
156
+
157
+ if (msg.kind === "reset") return { ...envelope, kind: "reset" }
158
+
159
+ if (msg.kind === "data") {
160
+ const { label, data, binary } = msg as { label?: unknown; data?: unknown; binary?: unknown }
161
+ if (typeof label !== "string" || typeof data !== "string") return null
162
+ return { ...envelope, kind: "data", label, data, binary: !!binary }
163
+ }
164
+
165
+ return null
166
+ }
167
+
168
+ // ── Signalling channel ──────────────────────────────────────────────
169
+
170
+ const RTC_PREDICATE = "ad4m://session/rtc"
171
+ const TARGET_ALL = "*"
172
+
173
+ /** Structurally an ephemeral channel, restated so this module carries
174
+ * no import-time dependency on any particular transport. */
175
+ export interface SignallingChannel {
176
+ publish(payload: unknown, to?: { agentId?: string }): void
177
+ onMessage(cb: (from: string, payload: unknown) => void): () => void
178
+ /**
179
+ * One result per publish, uncorrelated with the message. Optional: a
180
+ * transport that cannot tell what became of a send must not pretend.
181
+ * Where present, the mesh uses it to tell "the message was lost" from
182
+ * "the message has not gone yet" — see {@link MeshManager.outstanding}.
183
+ */
184
+ onPublishResult?(cb: (result: { ok: boolean; ms: number }) => void): () => void
185
+ /**
186
+ * Settles once messages published from now on reach `onMessage`.
187
+ * Optional: a transport that delivers from the moment `onMessage`
188
+ * returns has nothing to wait for. A peer told about this one before it
189
+ * listens would offer into the void until a repair resends.
190
+ */
191
+ listening?(): Promise<void>
192
+ }
193
+
194
+ /** Minimal telepresence surface the channel bridge needs. */
195
+ export interface TelepresenceProxy {
196
+ sendBroadcastU(status: PerspectiveUnsignedInput): Promise<boolean>
197
+ addSignalHandler(handler: (payload: PerspectiveExpression) => void): Promise<void>
198
+ removeSignalHandler(handler: (payload: PerspectiveExpression) => void): void
199
+ }
200
+
201
+ /**
202
+ * Bridge NeighbourhoodProxy telepresence to the SignallingChannel
203
+ * the mesh consumes.
204
+ *
205
+ * ## Why unicast runs emulated over broadcast
206
+ *
207
+ * AD4M exposes real directed send (`sendSignalU`), but it remains
208
+ * broken in current executor builds. This adapter addresses over
209
+ * broadcast: the recipient DID goes in the link's `target` and
210
+ * receivers drop anything not addressed to them. That provides
211
+ * **addressing, not privacy** — every peer still receives the payload.
212
+ */
213
+ export function createTelepresenceChannel(
214
+ proxy: TelepresenceProxy,
215
+ selfDid: string,
216
+ ): SignallingChannel {
217
+ const resultListeners = new Set<(result: { ok: boolean; ms: number }) => void>()
218
+ let subscribed: Promise<void> = Promise.resolve()
219
+ const report = (result: { ok: boolean; ms: number }) => {
220
+ for (const cb of resultListeners) {
221
+ try { cb(result) } catch (e) {
222
+ console.error("mesh: publish result listener error:", e)
223
+ }
224
+ }
225
+ }
226
+
227
+ return {
228
+ publish(payload, to) {
229
+ const started = Date.now()
230
+ // Every publish must report, or the mesh counts it outstanding forever
231
+ // and never repairs again — so a synchronous throw becomes a rejection.
232
+ let sent: Promise<boolean>
233
+ try {
234
+ sent = proxy.sendBroadcastU({
235
+ links: [{
236
+ source: JSON.stringify(payload),
237
+ predicate: RTC_PREDICATE,
238
+ target: to?.agentId ?? TARGET_ALL,
239
+ }],
240
+ })
241
+ } catch (err) {
242
+ sent = Promise.reject(err)
243
+ }
244
+ sent.then(
245
+ (ok) => report({ ok: ok !== false, ms: Date.now() - started }),
246
+ (err) => {
247
+ console.error("mesh: telepresence publish failed:", err)
248
+ report({ ok: false, ms: Date.now() - started })
249
+ },
250
+ )
251
+ },
252
+
253
+ onMessage(cb) {
254
+ const handler = (signal: PerspectiveExpression) => {
255
+ const link = signal?.data?.links?.[0]
256
+ if (!link?.author) return
257
+
258
+ /*
259
+ * The sender is the link's author, so it has to be one: the
260
+ * mesh acts on it (offers, answers, `reset`, rebuilds), and an
261
+ * author is only a claim until a signature backs it. The
262
+ * executor verifies both signatures on receipt and records the
263
+ * result in `proof.valid`. Accept a link only when the signal's
264
+ * signature and the link's own both hold, and both are by the
265
+ * same agent — a valid link relayed inside another agent's
266
+ * signal speaks for its author, not for whoever relayed it.
267
+ */
268
+ if (signal.proof?.valid !== true || link.proof?.valid !== true) return
269
+ if (link.author !== signal.author) return
270
+
271
+ const { source, predicate, target } = link.data ?? {}
272
+ if (typeof predicate !== "string" || predicate !== RTC_PREDICATE) return
273
+
274
+ // Emulated unicast: drop messages addressed to someone else
275
+ if (target && target !== TARGET_ALL && target !== selfDid) return
276
+ // Drop our own echo
277
+ if (link.author === selfDid) return
278
+
279
+ let parsed: unknown
280
+ try {
281
+ parsed = JSON.parse(source as string)
282
+ } catch {
283
+ return
284
+ }
285
+
286
+ cb(link.author as string, parsed)
287
+ }
288
+
289
+ subscribed = proxy.addSignalHandler(handler).catch((err) => {
290
+ console.warn("mesh: signal handler registration failed — inbound traffic will get missed:", err)
291
+ })
292
+
293
+ return () => proxy.removeSignalHandler(handler)
294
+ },
295
+
296
+ listening: () => subscribed,
297
+
298
+ onPublishResult(cb) {
299
+ resultListeners.add(cb)
300
+ return () => resultListeners.delete(cb)
301
+ },
302
+ }
303
+ }
304
+
305
+ // ── Mesh manager ────────────────────────────────────────────────────
306
+
307
+ export type MeshEvent =
308
+ | "participant-joined"
309
+ | "participant-left"
310
+ /** A participant's stream object or the liveness of its tracks changed:
311
+ * a rebuilt connection, or a remote track muted or unmuted. */
312
+ | "participant-updated"
313
+ | "stream-added"
314
+ | "stream-removed"
315
+ /** `(did, RTCPeerConnectionState)` */
316
+ | "peer-state"
317
+ /** `(did, { rung, attempts })` — a repair was attempted on this pair. */
318
+ | "peer-recovery"
319
+ | "error"
320
+
321
+ export type MeshEventCallback = (...args: any[]) => void
322
+
323
+ /** Which rung of the recovery ladder an attempt was on. */
324
+ export type RecoveryRung = "ice-restart" | "resend" | "rebuild"
325
+
326
+ export interface MeshParticipant {
327
+ did: string
328
+ stream: MediaStream
329
+ hasAudio: boolean
330
+ hasVideo: boolean
331
+ isActiveSpeaker: boolean
332
+ }
333
+
334
+ export interface MeshManagerOptions {
335
+ channel: SignallingChannel
336
+ callId: string
337
+ selfId: string
338
+ /** NAT traversal. Defaults to {@link DEFAULT_ICE_SERVERS} — public STUN, no TURN. */
339
+ iceServers?: RTCIceServer[]
340
+ /** Injected so tests can supply a fake. Receives the configuration the mesh decided on. */
341
+ createPeerConnection?: (configuration: RTCConfiguration) => RTCPeerConnection
342
+ /** Injectable clock, so the recovery ladder is testable without waiting out real deadlines. */
343
+ now?: () => number
344
+ /** How often the mesh looks at its own connections. `0` disables the timer;
345
+ * {@link MeshManager.tick} still works, which is how tests drive it. */
346
+ sweepMs?: number
347
+ }
348
+
349
+ /** Public STUN, and no TURN. Two servers, because ICE queries them in parallel. */
350
+ export const DEFAULT_ICE_SERVERS: RTCIceServer[] = [
351
+ { urls: ["stun:stun.l.google.com:19302", "stun:stun1.l.google.com:19302"] },
352
+ ]
353
+
354
+ /**
355
+ * How long a pair may sit unconnected before the impolite side intervenes.
356
+ * Only has to outlast a healthy negotiation: a send still in flight defers
357
+ * repair on its own (see {@link MeshManager.outstanding}).
358
+ */
359
+ export const HANDSHAKE_GRACE_MS = 10_000
360
+
361
+ /** How long each rung of the ladder is given before escalating to the next. */
362
+ export const RECOVERY_INTERVAL_MS = 8_000
363
+
364
+ /**
365
+ * How long `disconnected` is tolerated before an ICE restart. Shorter than the
366
+ * others: `disconnected` often recovers by itself within a second or two.
367
+ */
368
+ export const DISCONNECT_GRACE_MS = 5_000
369
+
370
+ /**
371
+ * How many times a pair is repaired before the mesh stops and lets `failed`
372
+ * stand. A pair that failed a full ladder four times needs TURN or a network,
373
+ * and neither is fixed by a fifth attempt. Reset by a successful connection.
374
+ */
375
+ export const MAX_RECOVERY_ATTEMPTS = 4
376
+
377
+ /** How often the mesh looks at its own connections, when not driven by hand. */
378
+ export const SWEEP_INTERVAL_MS = 2_000
379
+
380
+ /**
381
+ * The shortest gap between two repairs, whatever asks for them. A settled send
382
+ * calls `tick` and a repair publishes, so without a floor the two chase each
383
+ * other through every pair in the call. Below {@link SWEEP_INTERVAL_MS} so the
384
+ * ordinary cadence is never throttled.
385
+ */
386
+ export const REPAIR_SPACING_MS = 1_500
387
+
388
+ /** Candidates held for a remote description that has not arrived. */
389
+ const MAX_EARLY_CANDIDATES = 64
390
+
391
+ /** How many of a peer's replaced connections are remembered, so a late message from one is refused. */
392
+ const MAX_RETIRED_PER_PEER = 16
393
+
394
+ /** Signalling held from agents the roster has not listed yet. Bounded: it buffers for strangers. */
395
+ const MAX_PENDING_PEERS = 16
396
+ const MAX_PENDING_PER_PEER = 32
397
+
398
+ /** A name for a new connection. Unique enough among one peer's connections, which is all it is compared with. */
399
+ const newGeneration = () => Math.random().toString(36).slice(2, 10)
400
+
401
+ /** The `RTCStats` fields {@link MeshManager.transportOf} reads. */
402
+ interface RtcStatReport {
403
+ type?: string
404
+ id?: string
405
+ state?: string
406
+ localCandidateId?: string
407
+ candidateType?: string
408
+ }
409
+
410
+ interface PeerSlot {
411
+ pc: RTCPeerConnection
412
+ /** This connection's name, sent on everything it says. */
413
+ generation: string
414
+ /** The peer's connection this one is talking to, once the peer has named it. */
415
+ remoteGeneration: string | null
416
+ /** Decided by DID comparison — symmetric, so the two peers always disagree. */
417
+ polite: boolean
418
+ makingOffer: boolean
419
+ ignoreOffer: boolean
420
+ stream: MediaStream
421
+ /**
422
+ * The sender carrying each kind, remembered rather than looked up:
423
+ * `getSenders().find((s) => s.track?.kind === kind)` cannot find a sender
424
+ * whose track is `null`, which `replaceTrack(null)` leaves behind when a
425
+ * screen share stops. Sharing again then added a second video track and
426
+ * the peer's view froze on the dead first one.
427
+ */
428
+ senders: Map<"audio" | "video", RTCRtpSender>
429
+ /** The tail of this peer's signalling, so messages are applied one at a time. */
430
+ work: Promise<void>
431
+ /** A remote description has been applied, so candidates can be too. */
432
+ remoteReady: boolean
433
+ /** Candidates that cannot be applied yet, each with the peer connection that gathered it. */
434
+ earlyCandidates: { gen?: string; candidate: RTCIceCandidateInit }[]
435
+ /** The last description this side sent, so a lost one can be sent again rather than rebuilt. */
436
+ lastSent: Extract<CallBody, { kind: "description" }> | null
437
+ /** How many offers this connection has made: the last one's `offer` number. */
438
+ offers: number
439
+ /** The `offer` number of the peer's last applied offer, which this side's answer names. */
440
+ remoteOffer: number | undefined
441
+ /** The `sdp` already resent once. Resending is worth exactly one try per description. */
442
+ lastResent: string | null
443
+ /** Connected at least once: what broke is the transport, not a message. */
444
+ everConnected: boolean
445
+ /**
446
+ * When this side sent an offer that has had no answer yet, or 0. Tracked
447
+ * apart from the connection state because a pair renegotiates after it
448
+ * connects: the answerer's media travels in its own offer, sent once the
449
+ * pair is up. See {@link MeshManager.dueForRepair}.
450
+ */
451
+ offeredAt: number
452
+ /** The pending offer was made while the pair was already connected: a renegotiation. */
453
+ renegotiating: boolean
454
+ /** An offer this side held back until the pair connects; see `onnegotiationneeded`. */
455
+ offerDeferred: boolean
456
+ /** When this slot was created or last rebuilt — where the handshake deadline counts from. */
457
+ since: number
458
+ /** When the last repair was attempted, so rungs are spaced rather than fired in a burst. */
459
+ lastAttempt: number
460
+ /** How many repairs this pair has had. Reset by a successful connection. */
461
+ attempts: number
462
+ /** When ICE first reported `disconnected`, or 0. */
463
+ disconnectedAt: number
464
+ }
465
+
466
+ /** Whether a remote track currently carries media. A peer that leaves without
467
+ * saying so leaves its tracks `live` but `muted`. */
468
+ const isLive = (track: MediaStreamTrack) => track.readyState !== "ended" && !track.muted
469
+
470
+ export class MeshManager {
471
+ private channel: SignallingChannel
472
+ private callId: string
473
+ private selfId: string
474
+ private configuration: RTCConfiguration
475
+ private createPeerConnection: (configuration: RTCConfiguration) => RTCPeerConnection
476
+ private now: () => number
477
+ private sweepMs: number
478
+ private sweep: ReturnType<typeof setInterval> | null = null
479
+ private callbacks: Map<MeshEvent, MeshEventCallback[]> = new Map()
480
+ private slots: Map<string, PeerSlot> = new Map()
481
+ private states: Map<string, RTCPeerConnectionState> = new Map()
482
+ private outbound: Map<"audio" | "video", MediaStreamTrack | null> = new Map()
483
+ /** One stream for all outbound tracks, so a peer receives mic and camera grouped. */
484
+ private outboundStream: MediaStream | null = null
485
+ private closed = false
486
+ private channelUnsubscribe: (() => void) | null = null
487
+ private unwatchPublish: (() => void) | null = null
488
+ private pending: Map<string, CallMessage[]> = new Map()
489
+ /** The peer connections each peer has replaced. Kept past a slot, so a late message cannot revive one. */
490
+ private retired: Map<string, string[]> = new Map()
491
+ private dataListeners: Set<(msg: SfuDataMessage) => void> = new Set()
492
+ /**
493
+ * Sends published and not yet reported on. With an unreliable transport,
494
+ * "the peer never answered" and "the message has not left yet" look the
495
+ * same, and repairing the second piles sends onto a stalled executor. Stays
496
+ * zero on a transport without `onPublishResult`.
497
+ */
498
+ private outstanding = 0
499
+ /** When a sweep last repaired something — see {@link REPAIR_SPACING_MS}. */
500
+ private lastRepairAt = 0
501
+ /**
502
+ * Repairs of a connected pair's unanswered renegotiation, per peer, kept
503
+ * across rebuilds. A slot's `attempts` resets when its connection connects,
504
+ * which a rebuilt pair does before it renegotiates again — so a peer that
505
+ * never answers a renegotiation would be resent to and rebuilt forever.
506
+ * Cleared only when a renegotiation is answered.
507
+ */
508
+ private renegotiationRepairs: Map<string, number> = new Map()
509
+
510
+ constructor(options: MeshManagerOptions) {
511
+ this.channel = options.channel
512
+ this.callId = options.callId
513
+ this.selfId = options.selfId
514
+ this.configuration = {
515
+ iceServers: options.iceServers?.length ? options.iceServers : DEFAULT_ICE_SERVERS,
516
+ // Gather one candidate set before the handshake asks for it, so the
517
+ // STUN round trip is spent while the user reads the permission prompt.
518
+ iceCandidatePoolSize: 1,
519
+ }
520
+ this.createPeerConnection = options.createPeerConnection
521
+ ?? ((configuration) => new RTCPeerConnection(configuration))
522
+ this.now = options.now ?? (() => Date.now())
523
+ this.sweepMs = options.sweepMs ?? SWEEP_INTERVAL_MS
524
+ }
525
+
526
+ // ── Events ──────────────────────────────────────────────────────
527
+
528
+ on(event: MeshEvent, callback: MeshEventCallback): void {
529
+ if (!this.callbacks.has(event)) this.callbacks.set(event, [])
530
+ this.callbacks.get(event)!.push(callback)
531
+ }
532
+
533
+ off(event: MeshEvent, callback?: MeshEventCallback): void {
534
+ if (!callback) { this.callbacks.delete(event); return }
535
+ const cbs = this.callbacks.get(event)
536
+ if (cbs) {
537
+ const idx = cbs.indexOf(callback)
538
+ if (idx !== -1) cbs.splice(idx, 1)
539
+ if (cbs.length === 0) this.callbacks.delete(event)
540
+ }
541
+ }
542
+
543
+ private emit(event: MeshEvent, ...args: any[]): void {
544
+ const cbs = this.callbacks.get(event)
545
+ if (cbs) for (const cb of cbs) {
546
+ try { cb(...args) } catch (e) {
547
+ console.error(`mesh event handler error (${event}):`, e)
548
+ }
549
+ }
550
+ }
551
+
552
+ private fail(context: string, error: unknown): void {
553
+ this.emit("error", new Error(`${context}: ${error}`))
554
+ }
555
+
556
+ private participant(peerId: string, slot: PeerSlot): MeshParticipant {
557
+ return {
558
+ did: peerId,
559
+ stream: slot.stream,
560
+ hasAudio: slot.stream.getAudioTracks().some(isLive),
561
+ hasVideo: slot.stream.getVideoTracks().some(isLive),
562
+ isActiveSpeaker: false,
563
+ }
564
+ }
565
+
566
+ // ── Lifecycle ───────────────────────────────────────────────────
567
+
568
+ async join(localStream: MediaStream): Promise<void> {
569
+ this.outboundStream = new MediaStream()
570
+
571
+ for (const track of localStream.getAudioTracks()) {
572
+ this.outbound.set("audio", track)
573
+ this.outboundStream.addTrack(track)
574
+ }
575
+ for (const track of localStream.getVideoTracks()) {
576
+ this.outbound.set("video", track)
577
+ this.outboundStream.addTrack(track)
578
+ }
579
+
580
+ if (typeof this.channel.onPublishResult === "function") {
581
+ this.unwatchPublish = this.channel.onPublishResult(() => {
582
+ this.outstanding = Math.max(0, this.outstanding - 1)
583
+ // A send whose outcome is known is a reason to look now. Deferred,
584
+ // because a transport may report from inside `publish` and a repair
585
+ // publishes — a direct call would re-enter the sweep mid-repair.
586
+ queueMicrotask(() => this.tick())
587
+ })
588
+ }
589
+
590
+ this.channelUnsubscribe = this.channel.onMessage((from, payload) => {
591
+ if (this.closed || from === this.selfId) return
592
+
593
+ const message = parseCallMessage(payload)
594
+ if (!message || message.call !== this.callId) return
595
+
596
+ // The recipient is carried in the payload too, so a fanout-only
597
+ // transport cannot make a bystander negotiate. Data goes to all.
598
+ const to = (payload as { to?: unknown }).to
599
+ if (typeof to === "string" && to !== TARGET_ALL && to !== this.selfId) return
600
+
601
+ // Only peers the roster placed in the call. Without this, anyone on
602
+ // the channel could open a connection by sending an offer.
603
+ const slot = this.slots.get(from)
604
+
605
+ if (message.kind === "data") {
606
+ if (slot) this.handleData(from, message)
607
+ return
608
+ }
609
+
610
+ if (!slot) {
611
+ this.hold(from, message)
612
+ return
613
+ }
614
+
615
+ this.enqueue(from, slot, message)
616
+ })
617
+ // A session announces itself once `join` returns; peers offer at once.
618
+ await this.channel.listening?.()
619
+
620
+ /*
621
+ * Spend the transport's first-send cost on something that does not
622
+ * matter. The first broadcast on a freshly joined neighbourhood has
623
+ * been measured at eighteen seconds and every one after it at tens of
624
+ * milliseconds. Without this, the message paying that cost is the
625
+ * first SDP offer. It parses to nothing on every peer — no `kind`.
626
+ */
627
+ this.publish({ v: CALL_PROTOCOL_VERSION, call: this.callId, warm: true })
628
+
629
+ if (this.sweepMs > 0) this.sweep = setInterval(() => this.tick(), this.sweepMs)
630
+ }
631
+
632
+ async leave(): Promise<void> {
633
+ this.closed = true
634
+ if (this.sweep) { clearInterval(this.sweep); this.sweep = null }
635
+ this.unwatchPublish?.()
636
+ this.unwatchPublish = null
637
+ if (this.channelUnsubscribe) {
638
+ this.channelUnsubscribe()
639
+ this.channelUnsubscribe = null
640
+ }
641
+ this.pending.clear()
642
+ this.renegotiationRepairs.clear()
643
+ for (const peerId of [...this.slots.keys()]) this.removePeer(peerId)
644
+ this.outbound.clear()
645
+ this.outboundStream = null
646
+ }
647
+
648
+ async destroy(): Promise<void> {
649
+ await this.leave()
650
+ this.callbacks.clear()
651
+ this.dataListeners.clear()
652
+ }
653
+
654
+ // ── Roster management ───────────────────────────────────────────
655
+
656
+ /**
657
+ * Reconcile connections against who presence says belongs in the
658
+ * call. Excludes this agent.
659
+ */
660
+ setRoster(peerIds: string[]): void {
661
+ if (this.closed) return
662
+ const wanted = new Set(peerIds.filter((id) => id !== this.selfId))
663
+
664
+ for (const peerId of [...this.slots.keys()]) {
665
+ if (!wanted.has(peerId)) this.removePeer(peerId)
666
+ }
667
+ for (const peerId of wanted) {
668
+ if (this.slots.has(peerId)) continue
669
+ const slot = this.connect(peerId)
670
+ this.emit("participant-joined", this.participant(peerId, slot))
671
+ this.release(peerId, slot)
672
+ }
673
+ // Anything held for an agent the roster does not list will not get wanted.
674
+ for (const peerId of [...this.pending.keys()]) {
675
+ if (!wanted.has(peerId)) this.pending.delete(peerId)
676
+ }
677
+ }
678
+
679
+ // ── Participants and diagnostics ────────────────────────────────
680
+
681
+ getParticipants(): MeshParticipant[] {
682
+ return [...this.slots].map(([peerId, slot]) => this.participant(peerId, slot))
683
+ }
684
+
685
+ peerStates(): Map<string, RTCPeerConnectionState> {
686
+ return new Map(this.states)
687
+ }
688
+
689
+ /**
690
+ * Throw one pair's connection away and negotiate it again, telling the
691
+ * peer to do the same. The manual rung of the ladder: reachable from either
692
+ * side regardless of politeness, and it resets the automatic budget.
693
+ */
694
+ reconnect(peerId: string): void {
695
+ const slot = this.slots.get(peerId)
696
+ if (this.closed || !slot) return
697
+ slot.attempts = 0
698
+ this.renegotiationRepairs.delete(peerId)
699
+ this.rebuild(peerId, { announce: true, rung: "rebuild" })
700
+ }
701
+
702
+ /**
703
+ * How this pair's media reaches the other end — `host` on a LAN, `srflx`
704
+ * through NAT, `relay` through TURN — or `null` when nothing is connected.
705
+ * Separates "this pair needs TURN" from "the handshake never finished".
706
+ */
707
+ async transportOf(peerId: string): Promise<string | null> {
708
+ const slot = this.slots.get(peerId)
709
+ if (!slot || typeof slot.pc.getStats !== "function") return null
710
+ try {
711
+ const reports: RtcStatReport[] = []
712
+ ;(await slot.pc.getStats()).forEach((report: RtcStatReport) => reports.push(report))
713
+
714
+ const winner = reports.find((report) => report.type === "candidate-pair" && report.state === "succeeded")
715
+ const localId = winner?.localCandidateId
716
+ if (!localId) return null
717
+
718
+ const local = reports.find((report) => report.type === "local-candidate" && report.id === localId)
719
+ return local?.candidateType ?? null
720
+ } catch (error) {
721
+ this.fail(`reading transport stats for ${peerId}`, error)
722
+ return null
723
+ }
724
+ }
725
+
726
+ // ── Track replacement ────────────────────────────────────────────
727
+
728
+ /**
729
+ * Replace the outbound track of a given kind on every peer connection.
730
+ * Uses `RTCRtpSender.replaceTrack` on the sections declared up front, so
731
+ * muting, unmuting and camera↔screen swaps never renegotiate. Pass `null`
732
+ * to stop sending that kind.
733
+ */
734
+ async replaceTrack(kind: "audio" | "video", track: MediaStreamTrack | null): Promise<void> {
735
+ const previous = this.outbound.get(kind)
736
+ this.outbound.set(kind, track)
737
+ if (this.outboundStream) {
738
+ if (previous) this.outboundStream.removeTrack(previous)
739
+ if (track) this.outboundStream.addTrack(track)
740
+ }
741
+ if (this.closed) return
742
+
743
+ await Promise.all(
744
+ [...this.slots.entries()].map(async ([peerId, slot]) => {
745
+ try {
746
+ const sender = slot.senders.get(kind)
747
+ if (sender) {
748
+ await sender.replaceTrack(track)
749
+ } else if (track) {
750
+ // Only reachable if `addTransceiver` failed. This fires
751
+ // `negotiationneeded`, which perfect negotiation resolves.
752
+ slot.senders.set(kind, slot.pc.addTrack(track, this.outboundStream!))
753
+ }
754
+ } catch (error) {
755
+ this.fail(`replacing ${kind} track for ${peerId}`, error)
756
+ }
757
+ }),
758
+ )
759
+ }
760
+
761
+ // ── Data channel ────────────────────────────────────────────────
762
+
763
+ /**
764
+ * Send data to all other participants via the signalling channel.
765
+ * The mesh has no server-side relay — data rides the same
766
+ * telepresence broadcast the SDP/ICE messages use.
767
+ */
768
+ sendData(label: string, data: string, binary: boolean = false): void {
769
+ this.publish({ v: CALL_PROTOCOL_VERSION, call: this.callId, to: TARGET_ALL, kind: "data", label, data, binary })
770
+ }
771
+
772
+ subscribeDataChannel(callback: (msg: SfuDataMessage) => void): () => void {
773
+ this.dataListeners.add(callback)
774
+ return () => this.dataListeners.delete(callback)
775
+ }
776
+
777
+ private handleData(from: string, message: { label: string; data: string; binary: boolean }): void {
778
+ const msg: SfuDataMessage = {
779
+ senderDid: from,
780
+ neighbourhoodUrl: "",
781
+ roomName: this.callId,
782
+ channelLabel: message.label,
783
+ binary: message.binary,
784
+ data: message.data,
785
+ }
786
+ for (const cb of this.dataListeners) {
787
+ try { cb(msg) } catch (e) {
788
+ console.error("mesh: data listener error:", e)
789
+ }
790
+ }
791
+ }
792
+
793
+ // ── Sending ─────────────────────────────────────────────────────
794
+
795
+ /** Every publish goes through here, so {@link outstanding} counts exactly the reported ones. */
796
+ private publish(payload: object, to?: { agentId?: string }): void {
797
+ if (this.unwatchPublish) this.outstanding += 1
798
+ this.channel.publish(payload, to)
799
+ }
800
+
801
+ /**
802
+ * Addressed twice, on purpose: `to` on the publish lets a transport with
803
+ * native unicast send to one peer, and `to` in the payload makes a
804
+ * fanout-only transport filter on receipt.
805
+ */
806
+ private send(to: string, message: CallBody & CallGenerations): void {
807
+ this.publish({ v: CALL_PROTOCOL_VERSION, call: this.callId, to, ...message }, { agentId: to })
808
+ }
809
+
810
+ /** Which connections a message from this slot is between. */
811
+ private stamp(slot: PeerSlot): CallGenerations {
812
+ return slot.remoteGeneration ? { gen: slot.generation, peerGen: slot.remoteGeneration } : { gen: slot.generation }
813
+ }
814
+
815
+ private sendFrom(peerId: string, slot: PeerSlot, message: CallBody): void {
816
+ this.send(peerId, { ...message, ...this.stamp(slot) })
817
+ }
818
+
819
+ /** Send the connection's local description, numbered as {@link CallBody} describes. */
820
+ private sendDescription(peerId: string, slot: PeerSlot): void {
821
+ const { type, sdp } = slot.pc.localDescription!
822
+ const offer = type === "offer" ? ++slot.offers : slot.remoteOffer
823
+ slot.lastSent = { kind: "description", description: { type, sdp }, ...(offer !== undefined ? { offer } : {}) }
824
+ this.sendFrom(peerId, slot, slot.lastSent)
825
+ }
826
+
827
+ private retire(peerId: string, generation: string | null | undefined): void {
828
+ if (!generation) return
829
+ const list = this.retired.get(peerId) ?? []
830
+ if (list.includes(generation)) return
831
+ list.push(generation)
832
+ if (list.length > MAX_RETIRED_PER_PEER) list.shift()
833
+ this.retired.set(peerId, list)
834
+ }
835
+
836
+ // ── Peer connection management ──────────────────────────────────
837
+
838
+ private connect(peerId: string): PeerSlot {
839
+ const existing = this.slots.get(peerId)
840
+ if (existing) return existing
841
+
842
+ const pc = this.createPeerConnection(this.configuration)
843
+ const slot: PeerSlot = {
844
+ pc,
845
+ generation: newGeneration(),
846
+ remoteGeneration: null,
847
+ // Comparing DIDs gives each pair exactly one polite side
848
+ // without a round trip.
849
+ polite: this.selfId > peerId,
850
+ makingOffer: false,
851
+ ignoreOffer: false,
852
+ stream: new MediaStream(),
853
+ senders: new Map(),
854
+ work: Promise.resolve(),
855
+ remoteReady: false,
856
+ earlyCandidates: [],
857
+ lastSent: null,
858
+ offers: 0,
859
+ remoteOffer: undefined,
860
+ lastResent: null,
861
+ everConnected: false,
862
+ offeredAt: 0,
863
+ renegotiating: false,
864
+ offerDeferred: false,
865
+ since: this.now(),
866
+ lastAttempt: 0,
867
+ attempts: 0,
868
+ disconnectedAt: 0,
869
+ }
870
+ this.slots.set(peerId, slot)
871
+
872
+ const negotiate = async () => {
873
+ /*
874
+ * An answerer's first offer waits until the pair connects. Before
875
+ * that this side cannot know its answer arrived; if it was lost,
876
+ * the peer still has its offer out, reads this offer as glare and
877
+ * negotiates afresh, and both sides take the same DTLS role
878
+ * ("Failed to set SSL role"). Connecting proves the peer applied
879
+ * the answer: DTLS needs the fingerprint it carries. Once
880
+ * connected the roles are fixed, so later offers go at once.
881
+ * Read from the connection: the browser can fire this while the
882
+ * peer's offer is being applied, before any answer exists.
883
+ */
884
+ if (pc.remoteDescription?.type === "offer" && !slot.everConnected) {
885
+ slot.offerDeferred = true
886
+ return
887
+ }
888
+ slot.offerDeferred = false
889
+ try {
890
+ slot.makingOffer = true
891
+ /*
892
+ * Always an offer, never "whatever the state calls for". The
893
+ * browser can fire this during the rollback that accepting the
894
+ * peer's offer starts; a description picked from the state when
895
+ * the call runs is then the answer, and the answering path
896
+ * makes an offer in its place. If the peer's offer got here
897
+ * first the browser refuses, and asks again once stable.
898
+ */
899
+ await pc.setLocalDescription({ type: "offer" })
900
+ slot.offeredAt = this.now()
901
+ slot.renegotiating = pc.connectionState === "connected"
902
+ this.sendDescription(peerId, slot)
903
+ } catch (error) {
904
+ if (pc.signalingState === "stable") this.fail(`negotiating with ${peerId}`, error)
905
+ } finally {
906
+ slot.makingOffer = false
907
+ }
908
+ }
909
+ pc.onnegotiationneeded = negotiate
910
+
911
+ pc.onicecandidate = ({ candidate }) => {
912
+ if (candidate) this.sendFrom(peerId, slot, { kind: "ice", candidate: candidate.toJSON() })
913
+ }
914
+
915
+ pc.ontrack = ({ track }) => {
916
+ slot.stream.addTrack(track)
917
+ // Track events outlive the connection; a replaced one reports nothing.
918
+ const current = () => this.slots.get(peerId) === slot
919
+ const updated = () => {
920
+ if (current()) this.emit("participant-updated", this.participant(peerId, slot))
921
+ }
922
+ // A replaced track (camera → screen) arrives as a new track and
923
+ // the old one ends. Without this the tile would keep rendering it.
924
+ track.addEventListener("ended", () => {
925
+ slot.stream.removeTrack(track)
926
+ if (!current()) return
927
+ this.emit("stream-removed", slot.stream, track)
928
+ updated()
929
+ })
930
+ /*
931
+ * A remote track that stops receiving goes MUTED, not ended. When a
932
+ * peer leaves, crashes or drops off the network the track stays
933
+ * `live` for as long as the connection exists, and a `<video>`
934
+ * goes on painting the last decoded frame. Both edges, because a
935
+ * connection that recovers unmutes the same track.
936
+ */
937
+ track.addEventListener("mute", updated)
938
+ track.addEventListener("unmute", updated)
939
+ this.emit("stream-added", slot.stream, track)
940
+ }
941
+
942
+ pc.onconnectionstatechange = () => {
943
+ const state = pc.connectionState
944
+ this.states.set(peerId, state)
945
+ if (state === "connected") {
946
+ slot.everConnected = true
947
+ // The budget bounds one failure, not a session: a call that
948
+ // drops and recovers twice must not run out of repairs.
949
+ slot.attempts = 0
950
+ slot.disconnectedAt = 0
951
+ // Keep only candidates from a peer connection this one has not met.
952
+ slot.earlyCandidates = slot.earlyCandidates.filter((held) => held.gen && held.gen !== slot.remoteGeneration)
953
+ if (slot.offerDeferred && pc.signalingState === "stable") void negotiate()
954
+ }
955
+ if (state === "disconnected" && !slot.disconnectedAt) slot.disconnectedAt = this.now()
956
+ if (state === "connected" || state === "failed") slot.disconnectedAt = 0
957
+ this.emit("peer-state", peerId, state)
958
+ // `failed` is actionable at once — there is nothing in flight to wait for.
959
+ if (state === "failed") this.tick()
960
+ }
961
+
962
+ /*
963
+ * Both m-lines, before there is anything to put in them.
964
+ *
965
+ * A connection can only carry media of a kind it negotiated a section
966
+ * for, and `addTrack` creates one. An agent sending no video negotiated
967
+ * no video section, which left the *other* peer's camera with nowhere
968
+ * to arrive. Declaring both up front makes every track change a
969
+ * `replaceTrack` on an existing section.
970
+ */
971
+ for (const kind of ["audio", "video"] as const) {
972
+ try {
973
+ slot.senders.set(
974
+ kind,
975
+ pc.addTransceiver(kind, {
976
+ direction: "sendrecv",
977
+ streams: this.outboundStream ? [this.outboundStream] : [],
978
+ }).sender,
979
+ )
980
+ } catch (error) {
981
+ this.fail(`preparing ${kind} for ${peerId}`, error)
982
+ }
983
+ }
984
+
985
+ // Attach whatever already gets sent, so a peer joining mid-call
986
+ // receives our media without waiting for a toggle.
987
+ for (const [kind, track] of this.outbound) {
988
+ if (!track) continue
989
+ const sender = slot.senders.get(kind)
990
+ if (!sender) continue
991
+ void sender.replaceTrack(track).catch((error) =>
992
+ this.fail(`sending ${kind} to ${peerId}`, error),
993
+ )
994
+ }
995
+
996
+ return slot
997
+ }
998
+
999
+ /** Close one pair's connection, without telling anyone it happened. */
1000
+ private disconnect(peerId: string): void {
1001
+ const slot = this.slots.get(peerId)
1002
+ if (!slot) return
1003
+ slot.pc.onnegotiationneeded = null
1004
+ slot.pc.onicecandidate = null
1005
+ slot.pc.ontrack = null
1006
+ slot.pc.onconnectionstatechange = null
1007
+ try { slot.pc.close() } catch (error) {
1008
+ this.fail(`closing connection to ${peerId}`, error)
1009
+ }
1010
+ this.slots.delete(peerId)
1011
+ this.states.delete(peerId)
1012
+ // A late message from the peer's connection must not be mistaken for a
1013
+ // new one when the peer returns.
1014
+ this.retire(peerId, slot.remoteGeneration)
1015
+ // Held signalling belongs to the connection going away.
1016
+ this.pending.delete(peerId)
1017
+ }
1018
+
1019
+ /** The peer left the call. */
1020
+ private removePeer(peerId: string): void {
1021
+ const slot = this.slots.get(peerId)
1022
+ if (!slot) return
1023
+ this.disconnect(peerId)
1024
+ this.renegotiationRepairs.delete(peerId)
1025
+ this.emit("participant-left", this.participant(peerId, slot))
1026
+ }
1027
+
1028
+ // ── Pending message buffer ──────────────────────────────────────
1029
+
1030
+ /**
1031
+ * Signalling that arrived before the roster caught up, kept until it does.
1032
+ *
1033
+ * A peer who denied the microphone has no outbound tracks, so it never
1034
+ * fires `negotiationneeded` again after its offer is dropped. It joined and
1035
+ * connected to nobody. Bounded on both axes, because this buffers messages
1036
+ * from agents the roster has not vouched for. Overflow drops the oldest.
1037
+ */
1038
+ private hold(peerId: string, message: CallMessage): void {
1039
+ if (!this.pending.has(peerId) && this.pending.size >= MAX_PENDING_PEERS) return
1040
+ const queue = this.pending.get(peerId) ?? []
1041
+ queue.push(message)
1042
+ // An offer is followed by its candidates; dropping the oldest message
1043
+ // would drop the offer, which the pair cannot start without. Drop the
1044
+ // oldest message that is not a description or a reset instead.
1045
+ while (queue.length > MAX_PENDING_PER_PEER) {
1046
+ const spare = queue.findIndex((held) => held.kind !== "description" && held.kind !== "reset")
1047
+ queue.splice(spare === -1 ? 0 : spare, 1)
1048
+ }
1049
+ this.pending.set(peerId, queue)
1050
+ }
1051
+
1052
+ /** Replay what this peer sent while we were still learning it belongs here. */
1053
+ private release(peerId: string, slot: PeerSlot): void {
1054
+ const queue = this.pending.get(peerId)
1055
+ if (!queue) return
1056
+ this.pending.delete(peerId)
1057
+ // Enqueued rather than started all at once, on a connection that is
1058
+ // also about to fire `negotiationneeded` for its new transceivers.
1059
+ for (const message of queue) this.enqueue(peerId, slot, message)
1060
+ }
1061
+
1062
+ // ── Message handling ────────────────────────────────────────────
1063
+
1064
+ /** Put one message on this peer's queue. The chain never rejects — `handle` reports its own failures. */
1065
+ private enqueue(peerId: string, slot: PeerSlot, message: CallMessage): void {
1066
+ slot.work = slot.work.then(async () => {
1067
+ if (this.closed) return
1068
+ const current = this.slots.get(peerId)
1069
+ if (!current) return
1070
+ // The pair was rebuilt while this waited. A message that names its
1071
+ // connections follows the pair to its replacement and gets judged
1072
+ // there; one that does not is about a connection that is gone.
1073
+ if (current !== slot) {
1074
+ if (message.gen) this.enqueue(peerId, current, message)
1075
+ return
1076
+ }
1077
+ await this.handle(peerId, slot, message)
1078
+ })
1079
+ }
1080
+
1081
+ /**
1082
+ * Where a message stands against the connection this side holds for its sender.
1083
+ *
1084
+ * - `current` — from the peer connection this one talks to, or the first to
1085
+ * name itself, or it names nothing (a peer predating generations).
1086
+ * - `stale` — for a connection of this side's that was replaced, or from
1087
+ * one of the peer's that was. Nothing it says applies.
1088
+ * - `newer` — from a peer connection this side has not met: the peer has started over.
1089
+ */
1090
+ private placeOf(peerId: string, slot: PeerSlot, message: CallMessage): "current" | "stale" | "newer" {
1091
+ if (message.peerGen && message.peerGen !== slot.generation) return "stale"
1092
+ if (!message.gen) return "current"
1093
+ if (this.retired.get(peerId)?.includes(message.gen)) return "stale"
1094
+ if (!slot.remoteGeneration || slot.remoteGeneration === message.gen) return "current"
1095
+ return "newer"
1096
+ }
1097
+
1098
+ private async handle(peerId: string, slot: PeerSlot, message: CallMessage): Promise<void> {
1099
+ try {
1100
+ const place = this.placeOf(peerId, slot, message)
1101
+ if (place === "stale") return
1102
+ if (place === "current" && message.gen && !slot.remoteGeneration) slot.remoteGeneration = message.gen
1103
+
1104
+ if (message.kind === "reset") {
1105
+ // The peer is starting over. Rebuild to match and say nothing
1106
+ // back — two peers answering resets with resets is a loop.
1107
+ this.retire(peerId, message.gen)
1108
+ this.rebuild(peerId, { announce: false, rung: "rebuild" })
1109
+ return
1110
+ }
1111
+
1112
+ if (place === "newer") {
1113
+ // A candidate can overtake the offer it belongs to, so it waits.
1114
+ if (message.kind === "ice") {
1115
+ if (slot.earlyCandidates.length < MAX_EARLY_CANDIDATES) {
1116
+ slot.earlyCandidates.push({ gen: message.gen, candidate: message.candidate })
1117
+ }
1118
+ return
1119
+ }
1120
+ /*
1121
+ * The peer has a connection this side never heard from: a
1122
+ * reload, a rebuild whose reset was lost, a reset this offer
1123
+ * overtook. Applying its offer here is the "order of m-lines"
1124
+ * refusal, so this side starts over too, and applies the offer
1125
+ * at once — an offer of its own would collide with it. An
1126
+ * answer from an unknown connection has nothing to apply to;
1127
+ * the rebuilt side offers afresh.
1128
+ */
1129
+ const next = this.rebuild(peerId, { announce: false, rung: "rebuild" })
1130
+ next.earlyCandidates = slot.earlyCandidates.filter((held) => held.gen === message.gen)
1131
+ if (message.kind === "description" && message.description.type === "offer") {
1132
+ next.remoteGeneration = message.gen ?? null
1133
+ next.work = this.handle(peerId, next, message)
1134
+ }
1135
+ return
1136
+ }
1137
+
1138
+ if (message.kind === "description") {
1139
+ const { description } = message
1140
+ // An offer older than one already applied — overtaken on this
1141
+ // unordered transport — describes m-lines the connection has
1142
+ // moved past. The same number again is the resend rung's copy,
1143
+ // and is answered.
1144
+ if (
1145
+ description.type === "offer" &&
1146
+ message.offer !== undefined &&
1147
+ slot.remoteOffer !== undefined &&
1148
+ message.offer < slot.remoteOffer
1149
+ ) return
1150
+ const collision =
1151
+ description.type === "offer" &&
1152
+ (slot.makingOffer || slot.pc.signalingState !== "stable")
1153
+
1154
+ // The impolite peer wins a collision by ignoring the other's
1155
+ // offer; the polite peer yields, and `setRemoteDescription`
1156
+ // performs the implicit rollback that lets it accept.
1157
+ slot.ignoreOffer = !slot.polite && collision
1158
+ if (slot.ignoreOffer) return
1159
+ // An answer with no offer out is a late duplicate — the
1160
+ // resend rung got one answer for each copy. Expected on this
1161
+ // transport, so not an error.
1162
+ if (description.type === "answer" && slot.pc.signalingState === "stable") return
1163
+ // An answer to an earlier offer of this connection — a late copy
1164
+ // from the resend rung — would be refused against the current one.
1165
+ if (description.type === "answer" && message.offer !== undefined && message.offer !== slot.offers) return
1166
+
1167
+ await slot.pc.setRemoteDescription(description)
1168
+ if (description.type === "offer") slot.remoteOffer = message.offer
1169
+ // An answer settles this side's offer, and accepting the
1170
+ // peer's offer rolled it back. Either way none is pending.
1171
+ // An answered renegotiation is the evidence the connected-pair
1172
+ // repair waits for, so only that clears its budget.
1173
+ if (description.type === "answer" && slot.renegotiating) {
1174
+ this.renegotiationRepairs.delete(peerId)
1175
+ if (slot.pc.connectionState === "connected") slot.attempts = 0
1176
+ }
1177
+ slot.offeredAt = 0
1178
+ slot.renegotiating = false
1179
+ // Candidates become applicable exactly here. On an unordered
1180
+ // transport a candidate overtaking its offer is the normal case.
1181
+ slot.remoteReady = true
1182
+ await this.flushCandidates(peerId, slot)
1183
+
1184
+ if (description.type === "offer") {
1185
+ await slot.pc.setLocalDescription({ type: "answer" })
1186
+ this.sendDescription(peerId, slot)
1187
+ }
1188
+ return
1189
+ }
1190
+
1191
+ if (message.kind !== "ice") return
1192
+
1193
+ if (!slot.remoteReady) {
1194
+ if (slot.earlyCandidates.length < MAX_EARLY_CANDIDATES) {
1195
+ slot.earlyCandidates.push({ gen: message.gen, candidate: message.candidate })
1196
+ }
1197
+ return
1198
+ }
1199
+
1200
+ try {
1201
+ await slot.pc.addIceCandidate(message.candidate)
1202
+ } catch (error) {
1203
+ // Candidates for an offer we deliberately ignored will fail,
1204
+ // and that is expected. Anything else is real.
1205
+ if (!slot.ignoreOffer) throw error
1206
+ }
1207
+ } catch (error) {
1208
+ this.fail(`handling ${message.kind} from ${peerId}`, error)
1209
+ }
1210
+ }
1211
+
1212
+ private async flushCandidates(peerId: string, slot: PeerSlot): Promise<void> {
1213
+ if (!slot.earlyCandidates.length) return
1214
+ // Only this connection's. A candidate from a peer connection it has not met stays held.
1215
+ const mine = (held: { gen?: string }) => !held.gen || held.gen === slot.remoteGeneration
1216
+ const ready = slot.earlyCandidates.filter(mine).map((held) => held.candidate)
1217
+ slot.earlyCandidates = slot.earlyCandidates.filter((held) => !mine(held))
1218
+ for (const candidate of ready) {
1219
+ try {
1220
+ await slot.pc.addIceCandidate(candidate)
1221
+ } catch (error) {
1222
+ // One stale candidate must not stop the rest.
1223
+ this.fail(`applying a held candidate from ${peerId}`, error)
1224
+ }
1225
+ }
1226
+ }
1227
+
1228
+ // ── Recovery ────────────────────────────────────────────────────
1229
+
1230
+ /**
1231
+ * Throw this pair away and start again. Attempts carry over to the new
1232
+ * slot, or a pair that rebuilds every time would never reach
1233
+ * {@link MAX_RECOVERY_ATTEMPTS}.
1234
+ */
1235
+ private rebuild(peerId: string, opts: { announce: boolean; rung: RecoveryRung }): PeerSlot {
1236
+ const previous = this.slots.get(peerId)
1237
+ const attempts = (previous?.attempts ?? 0) + 1
1238
+ // Sent from the connection being thrown away, so the peer can tell a late reset from a new one.
1239
+ const farewell = previous ? this.stamp(previous) : {}
1240
+ this.disconnect(peerId)
1241
+ if (opts.announce) this.send(peerId, { kind: "reset", ...farewell })
1242
+ const slot = this.connect(peerId)
1243
+ slot.attempts = attempts
1244
+ slot.lastAttempt = this.now()
1245
+ // The participant's stream is a new object; consumers holding the old one render a dead stream.
1246
+ this.emit("participant-updated", this.participant(peerId, slot))
1247
+ this.emit("peer-recovery", peerId, { rung: opts.rung, attempts })
1248
+ return slot
1249
+ }
1250
+
1251
+ /**
1252
+ * One pair, one repair, on whichever rung its state calls for, cheapest first:
1253
+ *
1254
+ * 1. **ICE restart.** Keeps the connection and DTLS session; only
1255
+ * re-gathers the transport. For `failed` and a `disconnected` that did
1256
+ * not come back.
1257
+ * 2. **Resend the description.** For a handshake that never completed,
1258
+ * which on this transport means a message was dropped — either half.
1259
+ * 3. **Rebuild.** When there is nothing to resend, or the rungs above were tried.
1260
+ */
1261
+ private repair(peerId: string, slot: PeerSlot): void {
1262
+ slot.lastAttempt = this.now()
1263
+ const attempts = slot.attempts + 1
1264
+ slot.attempts = attempts
1265
+
1266
+ const state = slot.pc.connectionState
1267
+ const canRestart = typeof slot.pc.restartIce === "function"
1268
+
1269
+ if ((state === "failed" || state === "disconnected") && canRestart && slot.remoteReady) {
1270
+ try {
1271
+ slot.pc.restartIce()
1272
+ this.emit("peer-recovery", peerId, { rung: "ice-restart", attempts })
1273
+ return
1274
+ } catch (error) {
1275
+ this.fail(`restarting ice with ${peerId}`, error)
1276
+ }
1277
+ }
1278
+
1279
+ const unanswered = slot.offeredAt > 0 && slot.pc.signalingState === "have-local-offer"
1280
+ if (state === "connected") {
1281
+ this.renegotiationRepairs.set(peerId, (this.renegotiationRepairs.get(peerId) ?? 0) + 1)
1282
+ }
1283
+ if ((!slot.everConnected || unanswered) && slot.lastSent && slot.lastSent.description.sdp !== slot.lastResent) {
1284
+ slot.lastResent = slot.lastSent.description.sdp ?? null
1285
+ this.sendFrom(peerId, slot, slot.lastSent)
1286
+ this.emit("peer-recovery", peerId, { rung: "resend", attempts })
1287
+ return
1288
+ }
1289
+
1290
+ // Undo the increment `rebuild` is about to make again, so one repair counts once.
1291
+ slot.attempts = attempts - 1
1292
+ this.rebuild(peerId, { announce: true, rung: "rebuild" })
1293
+ }
1294
+
1295
+ /** Whether this pair has been given long enough, and whether it is this side's turn to act. */
1296
+ private dueForRepair(peerId: string, slot: PeerSlot, at: number): boolean {
1297
+ const state = slot.pc.connectionState
1298
+ if (slot.attempts >= MAX_RECOVERY_ATTEMPTS) return false
1299
+ /*
1300
+ * Connected, with an offer of this side's never answered. A pair
1301
+ * renegotiates after it connects — the answerer's media travels in
1302
+ * its own offer — and on a reordering transport that offer can reach
1303
+ * an impolite peer before the answer it follows, which reads it as
1304
+ * glare and ignores it. Nothing else revisits a connected pair, so
1305
+ * the media in that direction would never arrive. Only this side can
1306
+ * see the offer is pending, so it acts without the polite wait.
1307
+ */
1308
+ if (state === "connected") {
1309
+ if (!slot.offeredAt || slot.pc.signalingState !== "have-local-offer") return false
1310
+ if ((this.renegotiationRepairs.get(peerId) ?? 0) >= MAX_RECOVERY_ATTEMPTS) return false
1311
+ return at - Math.max(slot.offeredAt, slot.lastAttempt) >= RECOVERY_INTERVAL_MS
1312
+ }
1313
+
1314
+ // The impolite peer repairs first; the polite one waits twice as long,
1315
+ // which covers an impolite side whose roster never listed this peer.
1316
+ const patience = slot.polite ? 2 : 1
1317
+
1318
+ if (state === "disconnected" && slot.disconnectedAt) {
1319
+ return at - slot.disconnectedAt >= DISCONNECT_GRACE_MS * patience
1320
+ }
1321
+ if (state === "failed") {
1322
+ return at - Math.max(slot.lastAttempt, slot.since) >= RECOVERY_INTERVAL_MS * patience
1323
+ }
1324
+ // 'new' | 'connecting' | 'closed' — a handshake that has not finished.
1325
+ const from = slot.lastAttempt || slot.since
1326
+ const deadline = slot.lastAttempt ? RECOVERY_INTERVAL_MS : HANDSHAKE_GRACE_MS
1327
+ return at - from >= deadline * patience
1328
+ }
1329
+
1330
+ /**
1331
+ * Look at every connection and repair what is stuck. Driven by an internal
1332
+ * timer; public because tests drive it by hand.
1333
+ */
1334
+ tick(): void {
1335
+ if (this.closed) return
1336
+ // Nothing is repaired while a send is unaccounted for: an offer not
1337
+ // yet delivered and an offer lost look the same from here.
1338
+ if (this.outstanding > 0) return
1339
+ const at = this.now()
1340
+ if (this.lastRepairAt && at - this.lastRepairAt < REPAIR_SPACING_MS) return
1341
+ for (const [peerId, slot] of [...this.slots]) {
1342
+ if (!this.dueForRepair(peerId, slot, at)) continue
1343
+ this.lastRepairAt = at
1344
+ this.repair(peerId, slot)
1345
+ // One pair per sweep: a network that just came back has every pair
1346
+ // due at once, and a burst of offers is what made them fail.
1347
+ break
1348
+ }
1349
+ }
1350
+ }