@coasys/ad4m 0.13.0-test-3 → 0.13.0-test-4

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 (334) hide show
  1. package/README.md +2 -25
  2. package/jest-setup.ts +1 -1
  3. package/lib/index.cjs +2406 -11070
  4. package/lib/index.js +2209 -10925
  5. package/lib/src/Ad4mClient.d.ts +7 -3
  6. package/lib/src/Ad4mClient.js +29 -13
  7. package/lib/src/agent/Agent.js +26 -272
  8. package/lib/src/agent/AgentClient.d.ts +10 -21
  9. package/lib/src/agent/AgentClient.js +75 -427
  10. package/lib/src/agent/AgentStatus.js +2 -37
  11. package/lib/src/ai/AIClient.d.ts +12 -4
  12. package/lib/src/ai/AIClient.js +81 -285
  13. package/lib/src/ai/AITypes.d.ts +55 -0
  14. package/lib/src/ai/AITypes.js +18 -0
  15. package/lib/src/ai/Tasks.js +10 -133
  16. package/lib/src/apiClient.d.ts +52 -0
  17. package/lib/src/apiClient.js +231 -0
  18. package/lib/src/expression/Expression.d.ts +1 -1
  19. package/lib/src/expression/Expression.js +13 -122
  20. package/lib/src/expression/ExpressionClient.d.ts +3 -3
  21. package/lib/src/expression/ExpressionClient.js +13 -76
  22. package/lib/src/expression/ExpressionRef.js +2 -25
  23. package/lib/src/generated/api/AIModelLoadingStatus.d.ts +7 -0
  24. package/lib/src/generated/api/AIModelLoadingStatus.js +2 -0
  25. package/lib/src/generated/api/AddLinkExpressionRequest.d.ts +6 -0
  26. package/lib/src/generated/api/AddLinkExpressionRequest.js +1 -0
  27. package/lib/src/generated/api/AddLinkRequest.d.ts +6 -0
  28. package/lib/src/generated/api/AddLinkRequest.js +1 -0
  29. package/lib/src/generated/api/AddLinksBulkRequest.d.ts +6 -0
  30. package/lib/src/generated/api/AddLinksBulkRequest.js +1 -0
  31. package/lib/src/generated/api/AddSdnaRequest.d.ts +6 -0
  32. package/lib/src/generated/api/AddSdnaRequest.js +2 -0
  33. package/lib/src/generated/api/ApplyTemplateRequest.d.ts +4 -0
  34. package/lib/src/generated/api/ApplyTemplateRequest.js +2 -0
  35. package/lib/src/generated/api/AuthInfoInput.d.ts +10 -0
  36. package/lib/src/generated/api/AuthInfoInput.js +1 -0
  37. package/lib/src/generated/api/CapabilityInput.d.ts +5 -0
  38. package/lib/src/generated/api/CapabilityInput.js +1 -0
  39. package/lib/src/generated/api/CommitBatchRequest.d.ts +3 -0
  40. package/lib/src/generated/api/CommitBatchRequest.js +2 -0
  41. package/lib/src/generated/api/ComputeLogEntry.d.ts +9 -0
  42. package/lib/src/generated/api/ComputeLogEntry.js +2 -0
  43. package/lib/src/generated/api/CreateExpressionRequest.d.ts +4 -0
  44. package/lib/src/generated/api/CreateExpressionRequest.js +2 -0
  45. package/lib/src/generated/api/CreatePerspectiveRequest.d.ts +3 -0
  46. package/lib/src/generated/api/CreatePerspectiveRequest.js +2 -0
  47. package/lib/src/generated/api/CreateSubjectRequest.d.ts +6 -0
  48. package/lib/src/generated/api/CreateSubjectRequest.js +2 -0
  49. package/lib/src/generated/api/EmbedRequest.d.ts +4 -0
  50. package/lib/src/generated/api/EmbedRequest.js +2 -0
  51. package/lib/src/generated/api/EntanglementProofInput.d.ts +6 -0
  52. package/lib/src/generated/api/EntanglementProofInput.js +2 -0
  53. package/lib/src/generated/api/ExecuteCommandsRequest.d.ts +4 -0
  54. package/lib/src/generated/api/ExecuteCommandsRequest.js +2 -0
  55. package/lib/src/generated/api/ExportRequest.d.ts +5 -0
  56. package/lib/src/generated/api/ExportRequest.js +2 -0
  57. package/lib/src/generated/api/ExpressionManyRequest.d.ts +3 -0
  58. package/lib/src/generated/api/ExpressionManyRequest.js +2 -0
  59. package/lib/src/generated/api/ExpressionProof.d.ts +4 -0
  60. package/lib/src/generated/api/ExpressionProof.js +2 -0
  61. package/lib/src/generated/api/ExpressionProofInput.d.ts +6 -0
  62. package/lib/src/generated/api/ExpressionProofInput.js +2 -0
  63. package/lib/src/generated/api/FriendSendMessageRequest.d.ts +3 -0
  64. package/lib/src/generated/api/FriendSendMessageRequest.js +2 -0
  65. package/lib/src/generated/api/FriendsListRequest.d.ts +3 -0
  66. package/lib/src/generated/api/FriendsListRequest.js +2 -0
  67. package/lib/src/generated/api/GenerateAgentRequest.d.ts +3 -0
  68. package/lib/src/generated/api/GenerateAgentRequest.js +2 -0
  69. package/lib/src/generated/api/GenerateJwtRequest.d.ts +4 -0
  70. package/lib/src/generated/api/GenerateJwtRequest.js +2 -0
  71. package/lib/src/generated/api/GetSubjectDataRequest.d.ts +4 -0
  72. package/lib/src/generated/api/GetSubjectDataRequest.js +2 -0
  73. package/lib/src/generated/api/ImportAgentRequest.d.ts +6 -0
  74. package/lib/src/generated/api/ImportAgentRequest.js +2 -0
  75. package/lib/src/generated/api/ImportRequest.d.ts +4 -0
  76. package/lib/src/generated/api/ImportRequest.js +2 -0
  77. package/lib/src/generated/api/JoinNeighbourhoodRequest.d.ts +3 -0
  78. package/lib/src/generated/api/JoinNeighbourhoodRequest.js +2 -0
  79. package/lib/src/generated/api/LanguageMetaInput.d.ts +6 -0
  80. package/lib/src/generated/api/LanguageMetaInput.js +2 -0
  81. package/lib/src/generated/api/Link.d.ts +5 -0
  82. package/lib/src/generated/api/Link.js +2 -0
  83. package/lib/src/generated/api/LinkExpression.d.ts +10 -0
  84. package/lib/src/generated/api/LinkExpression.js +1 -0
  85. package/lib/src/generated/api/LinkExpressionInput.d.ts +10 -0
  86. package/lib/src/generated/api/LinkExpressionInput.js +1 -0
  87. package/lib/src/generated/api/LinkInput.d.ts +5 -0
  88. package/lib/src/generated/api/LinkInput.js +2 -0
  89. package/lib/src/generated/api/LinkLanguageTemplatesRequest.d.ts +3 -0
  90. package/lib/src/generated/api/LinkLanguageTemplatesRequest.js +2 -0
  91. package/lib/src/generated/api/LinkMutations.d.ts +6 -0
  92. package/lib/src/generated/api/LinkMutations.js +1 -0
  93. package/lib/src/generated/api/LinkStatus.d.ts +1 -0
  94. package/lib/src/generated/api/LinkStatus.js +2 -0
  95. package/lib/src/generated/api/LockAgentRequest.d.ts +3 -0
  96. package/lib/src/generated/api/LockAgentRequest.js +2 -0
  97. package/lib/src/generated/api/ModelType.d.ts +1 -0
  98. package/lib/src/generated/api/ModelType.js +2 -0
  99. package/lib/src/generated/api/NotificationInput.d.ts +10 -0
  100. package/lib/src/generated/api/NotificationInput.js +2 -0
  101. package/lib/src/generated/api/OpenLinkRequest.d.ts +3 -0
  102. package/lib/src/generated/api/OpenLinkRequest.js +2 -0
  103. package/lib/src/generated/api/PermitCapabilityRequest.d.ts +3 -0
  104. package/lib/src/generated/api/PermitCapabilityRequest.js +2 -0
  105. package/lib/src/generated/api/PerspectiveInput.d.ts +4 -0
  106. package/lib/src/generated/api/PerspectiveInput.js +1 -0
  107. package/lib/src/generated/api/PromptRequest.d.ts +4 -0
  108. package/lib/src/generated/api/PromptRequest.js +2 -0
  109. package/lib/src/generated/api/PublishLanguageRequest.d.ts +5 -0
  110. package/lib/src/generated/api/PublishLanguageRequest.js +1 -0
  111. package/lib/src/generated/api/PublishNeighbourhoodRequest.d.ts +6 -0
  112. package/lib/src/generated/api/PublishNeighbourhoodRequest.js +1 -0
  113. package/lib/src/generated/api/QueryRequest.d.ts +7 -0
  114. package/lib/src/generated/api/QueryRequest.js +2 -0
  115. package/lib/src/generated/api/RemoveLinkRequest.d.ts +5 -0
  116. package/lib/src/generated/api/RemoveLinkRequest.js +1 -0
  117. package/lib/src/generated/api/RemoveLinksBulkRequest.d.ts +5 -0
  118. package/lib/src/generated/api/RemoveLinksBulkRequest.js +1 -0
  119. package/lib/src/generated/api/ResourceInput.d.ts +4 -0
  120. package/lib/src/generated/api/ResourceInput.js +2 -0
  121. package/lib/src/generated/api/SetDefaultModelRequest.d.ts +4 -0
  122. package/lib/src/generated/api/SetDefaultModelRequest.js +1 -0
  123. package/lib/src/generated/api/SetFreeHostingEnabledRequest.d.ts +3 -0
  124. package/lib/src/generated/api/SetFreeHostingEnabledRequest.js +2 -0
  125. package/lib/src/generated/api/SetMultiUserRequest.d.ts +3 -0
  126. package/lib/src/generated/api/SetMultiUserRequest.js +2 -0
  127. package/lib/src/generated/api/SetStatusRequest.d.ts +3 -0
  128. package/lib/src/generated/api/SetStatusRequest.js +2 -0
  129. package/lib/src/generated/api/SignMessageRequest.d.ts +3 -0
  130. package/lib/src/generated/api/SignMessageRequest.js +2 -0
  131. package/lib/src/generated/api/TrustedAgentsRequest.d.ts +3 -0
  132. package/lib/src/generated/api/TrustedAgentsRequest.js +2 -0
  133. package/lib/src/generated/api/UnlockAgentRequest.d.ts +4 -0
  134. package/lib/src/generated/api/UnlockAgentRequest.js +2 -0
  135. package/lib/src/generated/api/UpdateLinkRequest.d.ts +7 -0
  136. package/lib/src/generated/api/UpdateLinkRequest.js +1 -0
  137. package/lib/src/generated/api/UpdatePerspectiveRequest.d.ts +3 -0
  138. package/lib/src/generated/api/UpdatePerspectiveRequest.js +2 -0
  139. package/lib/src/generated/api/UserStatistics.d.ts +9 -0
  140. package/lib/src/generated/api/UserStatistics.js +2 -0
  141. package/lib/src/generated/api/VerificationRequestResult.d.ts +6 -0
  142. package/lib/src/generated/api/VerificationRequestResult.js +2 -0
  143. package/lib/src/generated/api/VerifySignatureRequest.d.ts +5 -0
  144. package/lib/src/generated/api/VerifySignatureRequest.js +2 -0
  145. package/lib/src/generated/api/WriteSettingsRequest.d.ts +3 -0
  146. package/lib/src/generated/api/WriteSettingsRequest.js +2 -0
  147. package/lib/src/generated/api/index.d.ts +42 -0
  148. package/lib/src/generated/api/index.js +7 -0
  149. package/lib/src/index.d.ts +6 -1
  150. package/lib/src/index.js +6 -1
  151. package/lib/src/jestSetup.d.ts +0 -1
  152. package/lib/src/jestSetup.js +1 -1
  153. package/lib/src/language/Icon.js +2 -21
  154. package/lib/src/language/Language.d.ts +1 -1
  155. package/lib/src/language/Language.js +10 -76
  156. package/lib/src/language/LanguageClient.d.ts +2 -2
  157. package/lib/src/language/LanguageClient.js +15 -105
  158. package/lib/src/language/LanguageHandle.js +2 -41
  159. package/lib/src/language/LanguageMeta.js +4 -75
  160. package/lib/src/language/LanguageRef.js +2 -25
  161. package/lib/src/links/Links.js +14 -111
  162. package/lib/src/model/Ad4mModel.d.ts +57 -38
  163. package/lib/src/model/Ad4mModel.js +594 -460
  164. package/lib/src/model/Ad4mModel.test.js +371 -815
  165. package/lib/src/model/ModelQueryBuilder.d.ts +9 -21
  166. package/lib/src/model/ModelQueryBuilder.js +138 -217
  167. package/lib/src/model/decorators.d.ts +22 -0
  168. package/lib/src/model/decorators.js +7 -0
  169. package/lib/src/model/hydration.d.ts +7 -60
  170. package/lib/src/model/hydration.js +7 -716
  171. package/lib/src/model/index.d.ts +0 -4
  172. package/lib/src/model/index.js +0 -4
  173. package/lib/src/model/model-manifest.d.ts +41 -0
  174. package/lib/src/model/model-manifest.js +11 -0
  175. package/lib/src/model/query-sparql.d.ts +4 -67
  176. package/lib/src/model/query-sparql.js +26 -322
  177. package/lib/src/model/query-sparql.test.js +35 -218
  178. package/lib/src/model/shacl-gen.js +4 -0
  179. package/lib/src/model/types.d.ts +47 -38
  180. package/lib/src/model/types.js +4 -1
  181. package/lib/src/neighbourhood/Neighbourhood.js +4 -32
  182. package/lib/src/neighbourhood/NeighbourhoodClient.d.ts +3 -3
  183. package/lib/src/neighbourhood/NeighbourhoodClient.js +40 -203
  184. package/lib/src/perspectives/LinkQuery.js +2 -42
  185. package/lib/src/perspectives/Perspective.d.ts +1 -1
  186. package/lib/src/perspectives/Perspective.js +10 -52
  187. package/lib/src/perspectives/PerspectiveClient.d.ts +12 -17
  188. package/lib/src/perspectives/PerspectiveClient.js +169 -429
  189. package/lib/src/perspectives/PerspectiveClient.test.js +55 -0
  190. package/lib/src/perspectives/PerspectiveDiff.js +4 -31
  191. package/lib/src/perspectives/PerspectiveHandle.js +3 -43
  192. package/lib/src/perspectives/PerspectiveProxy.d.ts +92 -71
  193. package/lib/src/perspectives/PerspectiveProxy.js +273 -310
  194. package/lib/src/runtime/RuntimeClient.d.ts +6 -6
  195. package/lib/src/runtime/RuntimeClient.js +93 -467
  196. package/lib/src/runtime/RuntimeTypes.d.ts +101 -0
  197. package/lib/src/runtime/RuntimeTypes.js +45 -0
  198. package/lib/src/shacl/SHACLShape.d.ts +7 -0
  199. package/lib/src/shacl/SHACLShape.js +19 -0
  200. package/lib/src/shacl/SHACLShape.test.js +82 -0
  201. package/lib/src/typeDefs.js +3 -628
  202. package/package.json +9 -24
  203. package/rollup.config.js +0 -7
  204. package/src/Ad4mClient.test.ts +1179 -1340
  205. package/src/Ad4mClient.ts +30 -15
  206. package/src/agent/Agent.ts +0 -99
  207. package/src/agent/AgentClient.ts +112 -526
  208. package/src/agent/AgentStatus.ts +0 -12
  209. package/src/ai/AIClient.ts +96 -296
  210. package/src/ai/AITypes.ts +66 -0
  211. package/src/ai/Tasks.ts +0 -52
  212. package/src/apiClient.ts +283 -0
  213. package/src/expression/Expression.ts +3 -43
  214. package/src/expression/ExpressionClient.ts +14 -77
  215. package/src/expression/ExpressionRef.ts +0 -6
  216. package/src/generated/api/AIModelLoadingStatus.ts +3 -0
  217. package/src/generated/api/AddLinkExpressionRequest.ts +4 -0
  218. package/src/generated/api/AddLinkRequest.ts +4 -0
  219. package/src/generated/api/AddLinksBulkRequest.ts +4 -0
  220. package/src/generated/api/AddSdnaRequest.ts +3 -0
  221. package/src/generated/api/ApplyTemplateRequest.ts +3 -0
  222. package/src/generated/api/AuthInfoInput.ts +4 -0
  223. package/src/generated/api/CapabilityInput.ts +4 -0
  224. package/src/generated/api/CommitBatchRequest.ts +3 -0
  225. package/src/generated/api/ComputeLogEntry.ts +3 -0
  226. package/src/generated/api/CreateExpressionRequest.ts +3 -0
  227. package/src/generated/api/CreatePerspectiveRequest.ts +3 -0
  228. package/src/generated/api/CreateSubjectRequest.ts +3 -0
  229. package/src/generated/api/EmbedRequest.ts +3 -0
  230. package/src/generated/api/EntanglementProofInput.ts +3 -0
  231. package/src/generated/api/ExecuteCommandsRequest.ts +3 -0
  232. package/src/generated/api/ExportRequest.ts +3 -0
  233. package/src/generated/api/ExpressionManyRequest.ts +3 -0
  234. package/src/generated/api/ExpressionProof.ts +3 -0
  235. package/src/generated/api/ExpressionProofInput.ts +3 -0
  236. package/src/generated/api/FriendSendMessageRequest.ts +3 -0
  237. package/src/generated/api/FriendsListRequest.ts +3 -0
  238. package/src/generated/api/GenerateAgentRequest.ts +3 -0
  239. package/src/generated/api/GenerateJwtRequest.ts +3 -0
  240. package/src/generated/api/GetSubjectDataRequest.ts +3 -0
  241. package/src/generated/api/ImportAgentRequest.ts +3 -0
  242. package/src/generated/api/ImportRequest.ts +3 -0
  243. package/src/generated/api/JoinNeighbourhoodRequest.ts +3 -0
  244. package/src/generated/api/LanguageMetaInput.ts +3 -0
  245. package/src/generated/api/Link.ts +3 -0
  246. package/src/generated/api/LinkExpression.ts +6 -0
  247. package/src/generated/api/LinkExpressionInput.ts +6 -0
  248. package/src/generated/api/LinkInput.ts +3 -0
  249. package/src/generated/api/LinkLanguageTemplatesRequest.ts +3 -0
  250. package/src/generated/api/LinkMutations.ts +5 -0
  251. package/src/generated/api/LinkStatus.ts +3 -0
  252. package/src/generated/api/LockAgentRequest.ts +3 -0
  253. package/src/generated/api/ModelType.ts +3 -0
  254. package/src/generated/api/NotificationInput.ts +3 -0
  255. package/src/generated/api/OpenLinkRequest.ts +3 -0
  256. package/src/generated/api/PermitCapabilityRequest.ts +3 -0
  257. package/src/generated/api/PerspectiveInput.ts +4 -0
  258. package/src/generated/api/PromptRequest.ts +3 -0
  259. package/src/generated/api/PublishLanguageRequest.ts +4 -0
  260. package/src/generated/api/PublishNeighbourhoodRequest.ts +4 -0
  261. package/src/generated/api/QueryRequest.ts +6 -0
  262. package/src/generated/api/RemoveLinkRequest.ts +4 -0
  263. package/src/generated/api/RemoveLinksBulkRequest.ts +4 -0
  264. package/src/generated/api/ResourceInput.ts +3 -0
  265. package/src/generated/api/SetDefaultModelRequest.ts +4 -0
  266. package/src/generated/api/SetFreeHostingEnabledRequest.ts +3 -0
  267. package/src/generated/api/SetMultiUserRequest.ts +3 -0
  268. package/src/generated/api/SetStatusRequest.ts +3 -0
  269. package/src/generated/api/SignMessageRequest.ts +3 -0
  270. package/src/generated/api/TrustedAgentsRequest.ts +3 -0
  271. package/src/generated/api/UnlockAgentRequest.ts +3 -0
  272. package/src/generated/api/UpdateLinkRequest.ts +5 -0
  273. package/src/generated/api/UpdatePerspectiveRequest.ts +3 -0
  274. package/src/generated/api/UserStatistics.ts +3 -0
  275. package/src/generated/api/VerificationRequestResult.ts +3 -0
  276. package/src/generated/api/VerifySignatureRequest.ts +3 -0
  277. package/src/generated/api/WriteSettingsRequest.ts +3 -0
  278. package/src/generated/api/index.ts +49 -0
  279. package/src/index.ts +6 -1
  280. package/src/jestSetup.ts +1 -1
  281. package/src/language/Icon.ts +0 -4
  282. package/src/language/Language.ts +2 -23
  283. package/src/language/LanguageClient.ts +21 -132
  284. package/src/language/LanguageHandle.ts +0 -14
  285. package/src/language/LanguageMeta.ts +0 -29
  286. package/src/language/LanguageRef.ts +0 -7
  287. package/src/links/Links.ts +0 -37
  288. package/src/model/Ad4mModel.test.ts +708 -876
  289. package/src/model/Ad4mModel.ts +613 -508
  290. package/src/model/ModelQueryBuilder.ts +178 -244
  291. package/src/model/decorators.ts +29 -0
  292. package/src/model/hydration.ts +9 -766
  293. package/src/model/index.ts +0 -4
  294. package/src/model/query-sparql.test.ts +34 -242
  295. package/src/model/query-sparql.ts +27 -337
  296. package/src/model/shacl-gen.ts +5 -0
  297. package/src/model/types.ts +51 -39
  298. package/src/neighbourhood/Neighbourhood.ts +0 -9
  299. package/src/neighbourhood/NeighbourhoodClient.ts +42 -207
  300. package/src/neighbourhood/NeighbourhoodProxy.test.ts +34 -36
  301. package/src/perspectives/LinkQuery.ts +0 -15
  302. package/src/perspectives/Perspective.ts +1 -12
  303. package/src/perspectives/PerspectiveClient.test.ts +206 -148
  304. package/src/perspectives/PerspectiveClient.ts +228 -442
  305. package/src/perspectives/PerspectiveDiff.ts +0 -8
  306. package/src/perspectives/PerspectiveHandle.ts +1 -12
  307. package/src/perspectives/PerspectiveProxy.test.ts +41 -0
  308. package/src/perspectives/PerspectiveProxy.ts +307 -348
  309. package/src/runtime/RuntimeClient.ts +112 -474
  310. package/src/runtime/RuntimeTypes.ts +144 -0
  311. package/src/shacl/SHACLShape.test.ts +94 -0
  312. package/src/shacl/SHACLShape.ts +27 -0
  313. package/src/typeDefs.ts +3 -5
  314. package/tsconfig.json +3 -7
  315. package/shims/reflect-metadata.ts +0 -0
  316. package/shims/type-graphql.ts +0 -75
  317. package/src/PubSub.ts +0 -17
  318. package/src/agent/AgentResolver.ts +0 -263
  319. package/src/ai/AIResolver.ts +0 -372
  320. package/src/buildSchema.ts +0 -43
  321. package/src/expression/ExpressionResolver.ts +0 -64
  322. package/src/language/LanguageResolver.ts +0 -98
  323. package/src/model/Subject.ts +0 -159
  324. package/src/model/hydration-batch.ts +0 -205
  325. package/src/model/hydration-batching.test.ts +0 -563
  326. package/src/model/prolog-facts.ts +0 -145
  327. package/src/model/query-prolog.ts +0 -148
  328. package/src/model/query-sparql-batch.ts +0 -301
  329. package/src/model/subscription-delta.test.ts +0 -207
  330. package/src/model/subscription-pool.ts +0 -211
  331. package/src/neighbourhood/NeighbourhoodResolver.ts +0 -100
  332. package/src/perspectives/PerspectiveResolver.ts +0 -364
  333. package/src/runtime/RuntimeResolver.ts +0 -749
  334. package/src/unwrapApolloResult.ts +0 -16
@@ -1,6 +1,5 @@
1
- import { ApolloClient, gql } from "@apollo/client/core";
1
+ import { ApiClient } from "../apiClient";
2
2
  import { PerspectiveInput } from "../perspectives/Perspective";
3
- import unwrapApolloResult from "../unwrapApolloResult";
4
3
  import {
5
4
  Agent,
6
5
  Apps,
@@ -10,67 +9,20 @@ import {
10
9
  EntanglementProofInput,
11
10
  UserCreationResult,
12
11
  } from "./Agent";
13
- import { HostingUserInfo, PaymentRequestResult, ComputeLogEntry } from "../runtime/RuntimeResolver";
12
+ import { HostingUserInfo, PaymentRequestResult, ComputeLogEntry } from "../runtime/RuntimeTypes";
14
13
  import { AgentStatus } from "./AgentStatus";
15
- import { LinkMutations } from "../links/Links";
14
+ import { LinkMutations, LinkExpression } from "../links/Links";
16
15
  import { PerspectiveClient } from "../perspectives/PerspectiveClient";
17
- import { VerificationRequestResult } from "../runtime/RuntimeResolver";
18
-
19
- const AGENT_SUBITEMS = `
20
- did
21
- directMessageLanguage
22
- perspective {
23
- links {
24
- author, timestamp,
25
- proof {
26
- signature, key, valid, invalid
27
- }
28
- data {
29
- source, predicate, target
30
- }
31
- }
32
- }
33
- `;
34
-
35
- const Apps_FIELDS = `
36
- requestId
37
- revoked
38
- auth {
39
- appName
40
- appDesc
41
- appUrl
42
- appIconPath
43
- capabilities {
44
- with {
45
- domain
46
- pointers
47
- }
48
- can
49
- }
50
- }
51
- `;
52
-
53
- const AGENT_STATUS_FIELDS = `
54
- isInitialized
55
- isUnlocked
56
- did
57
- didDocument
58
- error
59
- `;
60
-
61
- const ENTANGLEMENT_PROOF_FIELDS = `
62
- did
63
- didSigningKeyId
64
- deviceKeyType
65
- deviceKey
66
- deviceKeySignedByDid
67
- didSignedByDeviceKey
68
- `;
69
-
70
- const AGENT_SIGNATURE_FIELDS = `
71
- signature
72
- publicKey
73
- `;
16
+ import { VerificationRequestResult } from "../runtime/RuntimeTypes";
17
+ import type {
18
+ GenerateAgentRequest,
19
+ ImportAgentRequest,
20
+ LockAgentRequest,
21
+ UnlockAgentRequest,
22
+ SignMessageRequest,
23
+ PermitCapabilityRequest,
24
+ GenerateJwtRequest,
25
+ } from "../generated/api";
74
26
 
75
27
  export interface InitializeArgs {
76
28
  did: string;
@@ -79,31 +31,33 @@ export interface InitializeArgs {
79
31
  passphrase: string;
80
32
  }
81
33
 
82
- export type AgentUpdatedCallback = (agent: Agent) => null;
83
- export type AgentStatusChangedCallback = (agent: Agent) => null;
84
- export type AgentAppsUpdatedCallback = () => null;
34
+ export type AgentUpdatedCallback = (agent: Agent) => void;
35
+ export type AgentStatusChangedCallback = (agent: Agent) => void;
36
+ export type AgentAppsUpdatedCallback = () => void;
85
37
  export type HostingUserInfoChangedCallback = (info: HostingUserInfo) => void;
86
38
  export type ComputeLogUpdatedCallback = (entry: ComputeLogEntry) => void;
87
- /**
88
- * Provides access to all functions regarding the local agent,
89
- * such as generating, locking, unlocking, importing the DID keystore,
90
- * as well as updating the publicly shared Agent expression.
91
- */
39
+
92
40
  export class AgentClient {
93
- #apolloClient: ApolloClient<any>;
41
+ #apiClient: ApiClient;
42
+ #baseUrl: string;
43
+ #token?: string;
94
44
  #appsChangedCallback: AgentAppsUpdatedCallback[];
95
45
  #updatedCallbacks: AgentUpdatedCallback[];
96
46
  #agentStatusChangedCallbacks: AgentStatusChangedCallback[];
97
47
  #hostingUserInfoChangedCallbacks: HostingUserInfoChangedCallback[];
98
48
  #computeLogUpdatedCallbacks: ComputeLogUpdatedCallback[];
49
+ #unsubscribers: (() => void)[];
99
50
 
100
- constructor(client: ApolloClient<any>, subscribe: boolean = true) {
101
- this.#apolloClient = client;
51
+ constructor(baseUrl: string, token?: string, subscribe: boolean = true, sharedApiClient?: ApiClient) {
52
+ this.#baseUrl = baseUrl;
53
+ this.#token = token;
54
+ this.#apiClient = sharedApiClient || new ApiClient(baseUrl, token);
102
55
  this.#updatedCallbacks = [];
103
56
  this.#agentStatusChangedCallbacks = [];
104
57
  this.#appsChangedCallback = [];
105
58
  this.#hostingUserInfoChangedCallbacks = [];
106
59
  this.#computeLogUpdatedCallbacks = [];
60
+ this.#unsubscribers = [];
107
61
 
108
62
  if (subscribe) {
109
63
  this.subscribeAgentUpdated();
@@ -112,155 +66,68 @@ export class AgentClient {
112
66
  }
113
67
  }
114
68
 
115
- /**
116
- * Returns the Agent expression of the local agent as it is shared
117
- * publicly via the AgentLanguage.
118
- *
119
- * I.e. this is the users profile.
120
- */
121
69
  async me(): Promise<Agent> {
122
- const { agent } = unwrapApolloResult(
123
- await this.#apolloClient.query({
124
- query: gql`query agent { agent { ${AGENT_SUBITEMS} } }`,
125
- })
126
- );
70
+ const agent = await this.#apiClient.call<Agent>('agent.get');
127
71
  let agentObject = new Agent(agent.did, agent.perspective);
128
72
  agentObject.directMessageLanguage = agent.directMessageLanguage;
129
73
  return agentObject;
130
74
  }
131
75
 
132
76
  async status(): Promise<AgentStatus> {
133
- const { agentStatus } = unwrapApolloResult(
134
- await this.#apolloClient.query({
135
- query: gql`query agentStatus {
136
- agentStatus {
137
- ${AGENT_STATUS_FIELDS}
138
- }
139
- }`,
140
- })
141
- );
77
+ const agentStatus = await this.#apiClient.call<AgentStatus>('agent.status');
142
78
  return new AgentStatus(agentStatus);
143
79
  }
144
80
 
145
81
  async generate(passphrase: string): Promise<AgentStatus> {
146
- const { agentGenerate } = unwrapApolloResult(
147
- await this.#apolloClient.mutate({
148
- mutation: gql`mutation agentGenerate(
149
- $passphrase: String!
150
- ) {
151
- agentGenerate(passphrase: $passphrase) {
152
- ${AGENT_STATUS_FIELDS}
153
- }
154
- }`,
155
- variables: { passphrase },
156
- })
157
- );
158
- return new AgentStatus(agentGenerate);
82
+ const result = await this.#apiClient.call<AgentStatus>('agent.generate', { passphrase });
83
+ return new AgentStatus(result);
159
84
  }
160
85
 
161
86
  async import(args: InitializeArgs): Promise<AgentStatus> {
162
- let { did, didDocument, keystore, passphrase } = args;
163
- const { agentImport } = unwrapApolloResult(
164
- await this.#apolloClient.mutate({
165
- mutation: gql`mutation agentImport(
166
- $did: String!,
167
- $didDocument: String!,
168
- $keystore: String!,
169
- $passphrase: String!
170
- ) {
171
- agentImport(did: $did, didDocument: $didDocument, keystore: $keystore, passphrase: $passphrase) {
172
- ${AGENT_STATUS_FIELDS}
173
- }
174
- }`,
175
- variables: { did, didDocument, keystore, passphrase },
176
- })
177
- );
178
- return new AgentStatus(agentImport);
87
+ const result = await this.#apiClient.call<AgentStatus>('agent.import', { ...args });
88
+ return new AgentStatus(result);
179
89
  }
180
90
 
181
91
  async lock(passphrase: string): Promise<AgentStatus> {
182
- const { agentLock } = unwrapApolloResult(
183
- await this.#apolloClient.mutate({
184
- mutation: gql`mutation agentLock($passphrase: String!) {
185
- agentLock(passphrase: $passphrase) {
186
- ${AGENT_STATUS_FIELDS}
187
- }
188
- }`,
189
- variables: { passphrase },
190
- })
191
- );
192
- return new AgentStatus(agentLock);
92
+ const result = await this.#apiClient.call<AgentStatus>('agent.lock', { passphrase });
93
+ return new AgentStatus(result);
193
94
  }
194
95
 
195
96
  async unlock(passphrase: string, holochain = true): Promise<AgentStatus> {
196
- const { agentUnlock } = unwrapApolloResult(
197
- await this.#apolloClient.mutate({
198
- mutation: gql`mutation agentUnlock($passphrase: String!, $holochain: Boolean!) {
199
- agentUnlock(passphrase: $passphrase, holochain: $holochain) {
200
- ${AGENT_STATUS_FIELDS}
201
- }
202
- }`,
203
- variables: { passphrase, holochain },
204
- })
205
- );
206
- return new AgentStatus(agentUnlock);
97
+ const result = await this.#apiClient.call<AgentStatus>('agent.unlock', { passphrase, holochain });
98
+ return new AgentStatus(result);
207
99
  }
208
100
 
209
101
  async byDID(did: string): Promise<Agent> {
210
- const { agentByDID } = unwrapApolloResult(
211
- await this.#apolloClient.query({
212
- query: gql`query agentByDID($did: String!) {
213
- agentByDID(did: $did) {
214
- ${AGENT_SUBITEMS}
215
- }
216
- }`,
217
- variables: { did },
218
- })
219
- );
220
- return agentByDID as Agent;
102
+ return this.#apiClient.call<Agent>('agent.byDid', { did });
221
103
  }
222
104
 
223
105
  async updatePublicPerspective(perspective: PerspectiveInput): Promise<Agent> {
224
106
  const cleanedPerspective = JSON.parse(JSON.stringify(perspective));
225
107
  delete cleanedPerspective.__typename;
226
- cleanedPerspective.links.forEach((link) => {
108
+ cleanedPerspective.links.forEach((link: LinkExpression) => {
227
109
  delete link.__typename;
228
110
  delete link.data.__typename;
229
111
  delete link.proof.__typename;
230
112
  delete link.status;
231
113
  });
232
114
 
233
- const { agentUpdatePublicPerspective } = unwrapApolloResult(
234
- await this.#apolloClient.mutate({
235
- mutation: gql`mutation agentUpdatePublicPerspective($perspective: PerspectiveInput!) {
236
- agentUpdatePublicPerspective(perspective: $perspective) {
237
- ${AGENT_SUBITEMS}
238
- }
239
- }`,
240
- variables: { perspective: cleanedPerspective },
241
- })
242
- );
243
- const a = agentUpdatePublicPerspective;
115
+ const a = await this.#apiClient.call<Agent>('agent.updateProfile', { publicPerspective: cleanedPerspective });
244
116
  const agent = new Agent(a.did, a.perspective);
245
117
  agent.directMessageLanguage = a.directMessageLanguage;
246
118
  return agent;
247
119
  }
248
120
 
249
121
  async mutatePublicPerspective(mutations: LinkMutations): Promise<Agent> {
250
- const perspectiveClient = new PerspectiveClient(this.#apolloClient);
251
- const agentClient = new AgentClient(this.#apolloClient);
122
+ const perspectiveClient = new PerspectiveClient(this.#baseUrl, this.#token);
252
123
 
253
- //Create the proxy perspective and load existing links
254
- const proxyPerspective = await perspectiveClient.add(
255
- "Agent Perspective Proxy"
256
- );
257
- const agentMe = await agentClient.me();
124
+ const proxyPerspective = await perspectiveClient.add("Agent Perspective Proxy");
125
+ const agentMe = await this.me();
258
126
 
259
127
  if (agentMe.perspective) {
260
128
  await proxyPerspective.loadSnapshot(agentMe.perspective);
261
129
  }
262
130
 
263
- //Make the mutations on the proxy perspective
264
131
  for (const addition of mutations.additions) {
265
132
  await proxyPerspective.add(addition);
266
133
  }
@@ -268,164 +135,72 @@ export class AgentClient {
268
135
  await proxyPerspective.remove(removal);
269
136
  }
270
137
 
271
- //Get the snapshot of the proxy perspective
272
138
  const snapshot = await proxyPerspective.snapshot();
273
- //Update the users public perspective
274
139
  const agent = await this.updatePublicPerspective(snapshot);
275
- //Cleanup and return
276
140
  await perspectiveClient.remove(proxyPerspective.uuid);
277
141
  return agent;
278
142
  }
279
143
 
280
- async updateDirectMessageLanguage(
281
- directMessageLanguage: string
282
- ): Promise<Agent> {
283
- const { agentUpdateDirectMessageLanguage } = unwrapApolloResult(
284
- await this.#apolloClient.mutate({
285
- mutation: gql`mutation agentUpdateDirectMessageLanguage($directMessageLanguage: String!) {
286
- agentUpdateDirectMessageLanguage(directMessageLanguage: $directMessageLanguage) {
287
- ${AGENT_SUBITEMS}
288
- }
289
- }`,
290
- variables: { directMessageLanguage },
291
- })
292
- );
293
- const a = agentUpdateDirectMessageLanguage;
144
+ async updateDirectMessageLanguage(directMessageLanguage: string): Promise<Agent> {
145
+ const a = await this.#apiClient.call<Agent>('agent.updateProfile', { dmLanguage: directMessageLanguage });
294
146
  const agent = new Agent(a.did, a.perspective);
295
147
  agent.directMessageLanguage = a.directMessageLanguage;
296
148
  return agent;
297
149
  }
298
150
 
299
- async addEntanglementProofs(
300
- proofs: EntanglementProofInput[]
301
- ): Promise<EntanglementProof[]> {
302
- const { agentAddEntanglementProofs } = unwrapApolloResult(
303
- await this.#apolloClient.mutate({
304
- mutation: gql`mutation agentAddEntanglementProofs($proofs: [EntanglementProofInput!]!) {
305
- agentAddEntanglementProofs(proofs: $proofs) {
306
- ${ENTANGLEMENT_PROOF_FIELDS}
307
- }
308
- }`,
309
- variables: { proofs },
310
- })
311
- );
312
- return agentAddEntanglementProofs;
313
- }
314
-
315
- async deleteEntanglementProofs(
316
- proofs: EntanglementProofInput[]
317
- ): Promise<EntanglementProof[]> {
318
- const { agentDeleteEntanglementProofs } = unwrapApolloResult(
319
- await this.#apolloClient.mutate({
320
- mutation: gql`mutation agentDeleteEntanglementProofs($proofs: [EntanglementProofInput!]!) {
321
- agentDeleteEntanglementProofs(proofs: $proofs) {
322
- ${ENTANGLEMENT_PROOF_FIELDS}
323
- }
324
- }`,
325
- variables: { proofs },
326
- })
327
- );
328
- return agentDeleteEntanglementProofs;
151
+ async addEntanglementProofs(proofs: EntanglementProofInput[]): Promise<EntanglementProof[]> {
152
+ return this.#apiClient.call<EntanglementProof[]>('agent.addEntanglementProofs', { proofs });
153
+ }
154
+
155
+ async deleteEntanglementProofs(proofs: EntanglementProofInput[]): Promise<EntanglementProof[]> {
156
+ return this.#apiClient.call<EntanglementProof[]>('agent.deleteEntanglementProofs', { proofs });
329
157
  }
330
158
 
331
159
  async getEntanglementProofs(): Promise<string[]> {
332
- const { agentGetEntanglementProofs } = unwrapApolloResult(
333
- await this.#apolloClient.query({
334
- query: gql`query agentGetEntanglementProofs {
335
- agentGetEntanglementProofs {
336
- ${ENTANGLEMENT_PROOF_FIELDS}
337
- }
338
- }`,
339
- })
340
- );
341
- return agentGetEntanglementProofs;
342
- }
343
-
344
- async entanglementProofPreFlight(
345
- deviceKey: string,
346
- deviceKeyType: string
347
- ): Promise<EntanglementProof> {
348
- const { agentEntanglementProofPreFlight } = unwrapApolloResult(
349
- await this.#apolloClient.mutate({
350
- mutation: gql`mutation agentEntanglementProofPreFlight($deviceKey: String!, $deviceKeyType: String!) {
351
- agentEntanglementProofPreFlight(deviceKey: $deviceKey, deviceKeyType: $deviceKeyType) {
352
- ${ENTANGLEMENT_PROOF_FIELDS}
353
- }
354
- }`,
355
- variables: { deviceKey, deviceKeyType },
356
- })
357
- );
358
- return agentEntanglementProofPreFlight;
160
+ return this.#apiClient.call<string[]>('agent.getEntanglementProofs');
161
+ }
162
+
163
+ async entanglementProofPreFlight(deviceKey: string, deviceKeyType: string): Promise<EntanglementProof> {
164
+ return this.#apiClient.call<EntanglementProof>('agent.entanglementProofPreflight', { deviceKey, deviceKeyType });
359
165
  }
360
166
 
361
- addUpdatedListener(listener) {
167
+ addUpdatedListener(listener: AgentUpdatedCallback) {
362
168
  this.#updatedCallbacks.push(listener);
363
169
  }
364
170
 
365
- addAppChangedListener(listener) {
171
+ addAppChangedListener(listener: AgentAppsUpdatedCallback) {
366
172
  this.#appsChangedCallback.push(listener);
367
173
  }
368
174
 
369
175
  subscribeAgentUpdated() {
370
- this.#apolloClient
371
- .subscribe({
372
- query: gql` subscription {
373
- agentUpdated { ${AGENT_SUBITEMS} }
374
- }
375
- `,
376
- })
377
- .subscribe({
378
- next: (result) => {
379
- const agent = result.data.agentUpdated;
380
- this.#updatedCallbacks.forEach((cb) => {
381
- cb(agent);
382
- });
383
- },
384
- error: (e) => console.error(e),
385
- });
176
+ const unsub = this.#apiClient.subscribe((data) => {
177
+ if (data.type === 'agent-updated') {
178
+ this.#updatedCallbacks.forEach((cb) => cb((data.agent || data) as Agent));
179
+ }
180
+ });
181
+ this.#unsubscribers.push(unsub);
386
182
  }
387
183
 
388
184
  subscribeAppsChanged() {
389
- this.#apolloClient
390
- .subscribe({
391
- query: gql` subscription {
392
- agentAppsChanged {
393
- ${Apps_FIELDS}
394
- }
395
- }
396
- `,
397
- })
398
- .subscribe({
399
- next: (result) => {
400
- this.#appsChangedCallback.forEach((cb) => {
401
- cb();
402
- });
403
- },
404
- error: (e) => console.error(e),
405
- });
406
- }
407
-
408
- addAgentStatusChangedListener(listener) {
185
+ const unsub = this.#apiClient.subscribe((data) => {
186
+ if (data.type === 'apps-changed') {
187
+ this.#appsChangedCallback.forEach((cb) => cb());
188
+ }
189
+ });
190
+ this.#unsubscribers.push(unsub);
191
+ }
192
+
193
+ addAgentStatusChangedListener(listener: AgentStatusChangedCallback) {
409
194
  this.#agentStatusChangedCallbacks.push(listener);
410
195
  }
411
196
 
412
197
  subscribeAgentStatusChanged() {
413
- this.#apolloClient
414
- .subscribe({
415
- query: gql` subscription {
416
- agentStatusChanged { ${AGENT_STATUS_FIELDS} }
417
- }
418
- `,
419
- })
420
- .subscribe({
421
- next: (result) => {
422
- const agent = result.data.agentStatusChanged;
423
- this.#agentStatusChangedCallbacks.forEach((cb) => {
424
- cb(agent);
425
- });
426
- },
427
- error: (e) => console.error(e),
428
- });
198
+ const unsub = this.#apiClient.subscribe((data) => {
199
+ if (data.type === 'agent-status-changed') {
200
+ this.#agentStatusChangedCallbacks.forEach((cb) => cb((data.agent || data) as Agent));
201
+ }
202
+ });
203
+ this.#unsubscribers.push(unsub);
429
204
  }
430
205
 
431
206
  addHostingUserInfoChangedListener(listener: HostingUserInfoChangedCallback) {
@@ -433,24 +208,12 @@ export class AgentClient {
433
208
  }
434
209
 
435
210
  subscribeHostingUserInfoChanged() {
436
- this.#apolloClient
437
- .subscribe({
438
- query: gql`subscription {
439
- runtimeHostingUserInfoChanged {
440
- email
441
- remainingCredits
442
- hotWalletAddress
443
- freeAccess
444
- }
445
- }`,
446
- })
447
- .subscribe({
448
- next: (result) => {
449
- const info = result.data.runtimeHostingUserInfoChanged;
450
- this.#hostingUserInfoChangedCallbacks.forEach((cb) => cb(info));
451
- },
452
- error: (e) => console.error(e),
453
- });
211
+ const unsub = this.#apiClient.subscribe((data) => {
212
+ if (data.type === 'hosting-user-info-changed') {
213
+ this.#hostingUserInfoChangedCallbacks.forEach((cb) => cb((data.info || data) as HostingUserInfo));
214
+ }
215
+ });
216
+ this.#unsubscribers.push(unsub);
454
217
  }
455
218
 
456
219
  addComputeLogUpdatedListener(listener: ComputeLogUpdatedCallback) {
@@ -458,261 +221,84 @@ export class AgentClient {
458
221
  }
459
222
 
460
223
  subscribeComputeLogUpdated() {
461
- this.#apolloClient
462
- .subscribe({
463
- query: gql`subscription {
464
- runtimeComputeLogUpdated {
465
- id
466
- userEmail
467
- timestamp
468
- operation
469
- summary
470
- cost
471
- creditsAfter
472
- }
473
- }`,
474
- })
475
- .subscribe({
476
- next: (result) => {
477
- const entry = result.data.runtimeComputeLogUpdated;
478
- this.#computeLogUpdatedCallbacks.forEach((cb) => cb(entry));
479
- },
480
- error: (e) => console.error(e),
481
- });
224
+ const unsub = this.#apiClient.subscribe((data) => {
225
+ if (data.type === 'compute-log-updated') {
226
+ this.#computeLogUpdatedCallbacks.forEach((cb) => cb((data.entry || data) as ComputeLogEntry));
227
+ }
228
+ });
229
+ this.#unsubscribers.push(unsub);
482
230
  }
483
231
 
484
232
  async requestCapability(authInfo: AuthInfoInput): Promise<string> {
485
- const { agentRequestCapability } = unwrapApolloResult(
486
- await this.#apolloClient.mutate({
487
- mutation: gql`
488
- mutation agentRequestCapability($authInfo: AuthInfoInput!) {
489
- agentRequestCapability(authInfo: $authInfo)
490
- }
491
- `,
492
- variables: { authInfo },
493
- })
494
- );
495
- return agentRequestCapability;
233
+ return this.#apiClient.call<string>('agent.requestCapability', { authInfo });
496
234
  }
497
235
 
498
236
  async permitCapability(auth: string): Promise<string> {
499
- const { agentPermitCapability } = unwrapApolloResult(
500
- await this.#apolloClient.mutate({
501
- mutation: gql`
502
- mutation agentPermitCapability($auth: String!) {
503
- agentPermitCapability(auth: $auth)
504
- }
505
- `,
506
- variables: { auth },
507
- })
508
- );
509
- return agentPermitCapability;
237
+ return this.#apiClient.call<string>('agent.permitCapability', { auth });
510
238
  }
511
239
 
512
240
  async generateJwt(requestId: string, rand: string): Promise<string> {
513
- const { agentGenerateJwt } = unwrapApolloResult(
514
- await this.#apolloClient.mutate({
515
- mutation: gql`
516
- mutation agentGenerateJwt($requestId: String!, $rand: String!) {
517
- agentGenerateJwt(requestId: $requestId, rand: $rand)
518
- }
519
- `,
520
- variables: { requestId, rand },
521
- })
522
- );
523
- return agentGenerateJwt;
241
+ return this.#apiClient.call<string>('agent.generateJwt', { requestId, rand });
524
242
  }
525
243
 
526
244
  async getApps(): Promise<Apps[]> {
527
- const { agentGetApps } = unwrapApolloResult(
528
- await this.#apolloClient.mutate({
529
- mutation: gql`query agentGetApps {
530
- agentGetApps {
531
- ${Apps_FIELDS}
532
- }
533
- }`,
534
- })
535
- );
536
- return agentGetApps;
245
+ return this.#apiClient.call<Apps[]>('agent.getApps');
537
246
  }
538
247
 
539
248
  async removeApp(requestId: string): Promise<Apps[]> {
540
- const { agentRemoveApp } = unwrapApolloResult(
541
- await this.#apolloClient.mutate({
542
- mutation: gql`mutation agentRemoveApp($requestId: String!) {
543
- agentRemoveApp(requestId: $requestId) {
544
- ${Apps_FIELDS}
545
- }
546
- }`,
547
- variables: { requestId },
548
- })
549
- );
550
- return agentRemoveApp;
249
+ return this.#apiClient.call<Apps[]>('agent.removeApp', { id: requestId });
551
250
  }
552
251
 
553
252
  async revokeToken(requestId: string): Promise<Apps[]> {
554
- const { agentRevokeToken } = unwrapApolloResult(
555
- await this.#apolloClient.mutate({
556
- mutation: gql`mutation agentRevokeToken($requestId: String!) {
557
- agentRevokeToken(requestId: $requestId) {
558
- ${Apps_FIELDS}
559
- }
560
- }`,
561
- variables: { requestId },
562
- })
563
- );
564
- return agentRevokeToken;
253
+ return this.#apiClient.call<Apps[]>('agent.revokeToken', { token: requestId });
565
254
  }
566
255
 
567
256
  async isLocked(): Promise<boolean> {
568
- const { agentIsLocked } = unwrapApolloResult(
569
- await this.#apolloClient.mutate({
570
- mutation: gql`
571
- query agentIsLocked {
572
- agentIsLocked
573
- }
574
- `,
575
- })
576
- );
577
- return agentIsLocked;
257
+ return this.#apiClient.call<boolean>('agent.isLocked');
578
258
  }
579
259
 
580
260
  async signMessage(message: string): Promise<string> {
581
- const { agentSignMessage } = unwrapApolloResult(
582
- await this.#apolloClient.mutate({
583
- mutation: gql`mutation agentSignMessage($message: String!) {
584
- agentSignMessage(message: $message) {
585
- ${AGENT_SIGNATURE_FIELDS}
586
- }
587
- }`,
588
- variables: { message },
589
- })
590
- );
591
- return agentSignMessage;
261
+ return this.#apiClient.call<string>('agent.sign', { message });
592
262
  }
593
263
 
594
264
  // Multi-user methods
595
265
  async createUser(email: string, password: string, appInfo?: AuthInfoInput): Promise<UserCreationResult> {
596
- const { runtimeCreateUser } = unwrapApolloResult(
597
- await this.#apolloClient.mutate({
598
- mutation: gql`mutation runtimeCreateUser($email: String!, $password: String!, $appInfo: AuthInfoInput) {
599
- runtimeCreateUser(email: $email, password: $password, appInfo: $appInfo) {
600
- did
601
- success
602
- error
603
- }
604
- }`,
605
- variables: { email, password, appInfo },
606
- })
607
- );
608
- return runtimeCreateUser;
266
+ return this.#apiClient.call<UserCreationResult>('user.create', { email, password, appInfo });
609
267
  }
610
268
 
611
269
  async loginUser(email: string, password: string): Promise<string> {
612
- const { runtimeLoginUser } = unwrapApolloResult(
613
- await this.#apolloClient.mutate({
614
- mutation: gql`mutation runtimeLoginUser($email: String!, $password: String!) {
615
- runtimeLoginUser(email: $email, password: $password)
616
- }`,
617
- variables: { email, password },
618
- })
619
- );
620
- return runtimeLoginUser;
270
+ return this.#apiClient.call<string>('user.login', { email, password });
621
271
  }
622
272
 
623
273
  async requestLoginVerification(email: string, appInfo?: AuthInfoInput): Promise<VerificationRequestResult> {
624
- const { runtimeRequestLoginVerification } = unwrapApolloResult(
625
- await this.#apolloClient.mutate({
626
- mutation: gql`mutation runtimeRequestLoginVerification($email: String!, $appInfo: AuthInfoInput) {
627
- runtimeRequestLoginVerification(email: $email, appInfo: $appInfo) {
628
- success
629
- message
630
- requiresPassword
631
- isExistingUser
632
- }
633
- }`,
634
- variables: { email, appInfo },
635
- })
636
- );
637
- return runtimeRequestLoginVerification;
274
+ return this.#apiClient.call<VerificationRequestResult>('user.requestVerification', { email, appInfo });
638
275
  }
639
276
 
640
277
  async verifyEmailCode(email: string, code: string, verificationType: string): Promise<string> {
641
- const { runtimeVerifyEmailCode } = unwrapApolloResult(
642
- await this.#apolloClient.mutate({
643
- mutation: gql`mutation runtimeVerifyEmailCode($email: String!, $code: String!, $verificationType: String!) {
644
- runtimeVerifyEmailCode(email: $email, code: $code, verificationType: $verificationType)
645
- }`,
646
- variables: { email, code, verificationType },
647
- })
648
- );
649
- return runtimeVerifyEmailCode;
278
+ return this.#apiClient.call<string>('user.verifyEmail', { email, code, verificationType });
650
279
  }
651
280
 
652
281
  // Hosting methods
653
-
654
282
  async hostingUserInfo(): Promise<HostingUserInfo> {
655
- const { runtimeHostingUserInfo } = unwrapApolloResult(
656
- await this.#apolloClient.query({
657
- query: gql`query runtimeHostingUserInfo {
658
- runtimeHostingUserInfo {
659
- email
660
- remainingCredits
661
- hotWalletAddress
662
- freeAccess
663
- }
664
- }`,
665
- })
283
+ const resp = await this.#apiClient.call<any>('hosting.info');
284
+ const info = resp?.userInfo || resp;
285
+ return new HostingUserInfo(
286
+ info.email || '',
287
+ info.freeAccess ? 'unlimited' : String(info.credits ?? info.remainingCredits ?? '0'),
288
+ info.hotWalletAddress || undefined,
289
+ !!info.freeAccess,
666
290
  );
667
- return runtimeHostingUserInfo;
668
291
  }
669
292
 
670
293
  async computeLog(since?: string, limit?: number, userEmail?: string): Promise<ComputeLogEntry[]> {
671
- const { runtimeComputeLog } = unwrapApolloResult(
672
- await this.#apolloClient.query({
673
- query: gql`query runtimeComputeLog($since: String, $limit: Int, $userEmail: String) {
674
- runtimeComputeLog(since: $since, limit: $limit, userEmail: $userEmail) {
675
- id
676
- userEmail
677
- timestamp
678
- operation
679
- summary
680
- cost
681
- creditsAfter
682
- }
683
- }`,
684
- variables: { since, limit, userEmail },
685
- fetchPolicy: 'network-only',
686
- })
687
- );
688
- return runtimeComputeLog;
294
+ return this.#apiClient.call<ComputeLogEntry[]>('runtime.computeLog', { since, limit, userEmail });
689
295
  }
690
296
 
691
297
  async setHotWalletAddress(address: string): Promise<boolean> {
692
- const { runtimeSetHotWalletAddress } = unwrapApolloResult(
693
- await this.#apolloClient.mutate({
694
- mutation: gql`mutation runtimeSetHotWalletAddress($address: String!) {
695
- runtimeSetHotWalletAddress(address: $address)
696
- }`,
697
- variables: { address },
698
- })
699
- );
700
- return runtimeSetHotWalletAddress;
298
+ return this.#apiClient.call<boolean>('hosting.setHotWallet', { address });
701
299
  }
702
300
 
703
301
  async requestPayment(amountHOT: string): Promise<PaymentRequestResult> {
704
- const { runtimeRequestPayment } = unwrapApolloResult(
705
- await this.#apolloClient.mutate({
706
- mutation: gql`mutation runtimeRequestPayment($amountHOT: String!) {
707
- runtimeRequestPayment(amountHOT: $amountHOT) {
708
- success
709
- message
710
- }
711
- }`,
712
- variables: { amountHOT },
713
- })
714
- );
715
- return runtimeRequestPayment;
302
+ return this.#apiClient.call<PaymentRequestResult>('hosting.requestPayment', { amountHOT });
716
303
  }
717
-
718
304
  }