@lucern/sdk 0.2.0-alpha.12 → 0.2.0-alpha.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 (317) hide show
  1. package/README.md +166 -609
  2. package/dist/index.js +3539 -6269
  3. package/dist/index.js.map +1 -1
  4. package/dist/{contracts → lucern/contracts/src}/auth-session.contract.d.ts +12 -14
  5. package/dist/{contracts → lucern/contracts/src}/context-pack.contract.d.ts +58 -56
  6. package/dist/{contracts → lucern/contracts/src}/lens-filter.contract.d.ts +8 -10
  7. package/dist/lucern/contracts/src/lens-workflow.contract.d.ts +84 -0
  8. package/dist/lucern/contracts/src/mcp-tools.contract.d.ts +151 -0
  9. package/dist/lucern/contracts/src/workflow-runtime.contract.d.ts +161 -0
  10. package/dist/lucern/mcp-server/src/context-pack-policy.d.ts +119 -0
  11. package/dist/lucern/mcp-server/src/context-pack-schema.d.ts +18 -0
  12. package/dist/lucern/modules/graph-primitives/src/ontology-matching.d.ts +78 -0
  13. package/dist/lucern/modules/graph-primitives/src/text-matching.d.ts +53 -0
  14. package/dist/lucern/packages/client-core/src/beliefs.d.ts +30 -0
  15. package/dist/lucern/packages/client-core/src/context.d.ts +29 -0
  16. package/dist/lucern/packages/client-core/src/contradictions.d.ts +11 -0
  17. package/dist/lucern/packages/client-core/src/edges.d.ts +11 -0
  18. package/dist/lucern/packages/client-core/src/events.d.ts +9 -0
  19. package/dist/lucern/packages/client-core/src/evidence.d.ts +21 -0
  20. package/dist/lucern/packages/client-core/src/graph.d.ts +17 -0
  21. package/dist/lucern/packages/client-core/src/identity.d.ts +7 -0
  22. package/dist/lucern/packages/client-core/src/ids.d.ts +7 -0
  23. package/dist/lucern/packages/client-core/src/ontologies.d.ts +13 -0
  24. package/dist/lucern/packages/client-core/src/questions.d.ts +39 -0
  25. package/dist/lucern/packages/client-core/src/search.d.ts +7 -0
  26. package/dist/lucern/packages/client-core/src/tasks.d.ts +13 -0
  27. package/dist/lucern/packages/client-core/src/topics.d.ts +17 -0
  28. package/dist/lucern/packages/client-core/src/webhooks.d.ts +35 -0
  29. package/dist/lucern/packages/client-core/src/worktrees.d.ts +17 -0
  30. package/dist/lucern/packages/domain-beliefs/src/beliefs.d.ts +283 -0
  31. package/dist/lucern/packages/domain-beliefs/src/index.d.ts +1 -0
  32. package/dist/lucern/packages/domain-context/src/compile.d.ts +11 -0
  33. package/dist/{contextPackCompiler.d.ts → lucern/packages/domain-context/src/context-pack-compiler.d.ts} +10 -11
  34. package/dist/lucern/packages/domain-context/src/index.d.ts +4 -0
  35. package/dist/lucern/packages/domain-context/src/ports.d.ts +58 -0
  36. package/dist/lucern/packages/domain-context/src/public-types.d.ts +1 -0
  37. package/dist/lucern/packages/domain-edges/src/contradictions.d.ts +59 -0
  38. package/dist/lucern/packages/domain-edges/src/edges.d.ts +91 -0
  39. package/dist/lucern/packages/domain-edges/src/index.d.ts +2 -0
  40. package/dist/lucern/packages/domain-evidence/src/evidence.d.ts +115 -0
  41. package/dist/lucern/packages/domain-evidence/src/index.d.ts +1 -0
  42. package/dist/lucern/packages/domain-graph/src/graph.d.ts +150 -0
  43. package/dist/lucern/packages/domain-identity/src/index.d.ts +1 -0
  44. package/dist/lucern/packages/domain-identity/src/whoami.d.ts +13 -0
  45. package/dist/lucern/packages/domain-ontologies/src/ontologies.d.ts +123 -0
  46. package/dist/lucern/packages/domain-questions/src/index.d.ts +1 -0
  47. package/dist/lucern/packages/domain-questions/src/questions.d.ts +147 -0
  48. package/dist/lucern/packages/domain-search/src/search.d.ts +97 -0
  49. package/dist/lucern/packages/domain-tasks/src/index.d.ts +1 -0
  50. package/dist/lucern/packages/domain-tasks/src/tasks.d.ts +102 -0
  51. package/dist/lucern/packages/domain-topics/src/index.d.ts +1 -0
  52. package/dist/lucern/packages/domain-topics/src/topics.d.ts +147 -0
  53. package/dist/lucern/packages/domain-worktrees/src/index.d.ts +1 -0
  54. package/dist/lucern/packages/domain-worktrees/src/worktrees.d.ts +185 -0
  55. package/dist/lucern/packages/events/src/index.d.ts +4 -0
  56. package/dist/lucern/packages/events/src/matching.d.ts +3 -0
  57. package/dist/lucern/packages/events/src/outbox.d.ts +15 -0
  58. package/dist/lucern/packages/events/src/types.d.ts +151 -0
  59. package/dist/lucern/packages/events/src/webhooks.d.ts +9 -0
  60. package/dist/lucern/packages/sdk-typescript/src/facade/beliefs.d.ts +15 -0
  61. package/dist/lucern/packages/sdk-typescript/src/facade/context.d.ts +12 -0
  62. package/dist/lucern/packages/sdk-typescript/src/facade/contradictions.d.ts +7 -0
  63. package/dist/lucern/packages/sdk-typescript/src/facade/edges.d.ts +7 -0
  64. package/dist/lucern/packages/sdk-typescript/src/facade/events.d.ts +6 -0
  65. package/dist/lucern/packages/sdk-typescript/src/facade/evidence.d.ts +21 -0
  66. package/dist/lucern/packages/sdk-typescript/src/facade/graph.d.ts +10 -0
  67. package/dist/lucern/packages/sdk-typescript/src/facade/identity.d.ts +5 -0
  68. package/dist/lucern/packages/sdk-typescript/src/facade/ontologies.d.ts +8 -0
  69. package/dist/lucern/packages/sdk-typescript/src/facade/questions.d.ts +39 -0
  70. package/dist/lucern/packages/sdk-typescript/src/facade/search.d.ts +5 -0
  71. package/dist/lucern/packages/sdk-typescript/src/facade/tasks.d.ts +8 -0
  72. package/dist/lucern/packages/sdk-typescript/src/facade/topics.d.ts +10 -0
  73. package/dist/lucern/packages/sdk-typescript/src/facade/webhooks.d.ts +16 -0
  74. package/dist/lucern/packages/sdk-typescript/src/facade/worktrees.d.ts +10 -0
  75. package/dist/lucern/packages/sdk-typescript/src/index.d.ts +28 -0
  76. package/dist/packages/sdk/src/adminClient.d.ts +89 -0
  77. package/dist/packages/sdk/src/answersClient.d.ts +5 -0
  78. package/dist/{audiencesClient.d.ts → packages/sdk/src/audiencesClient.d.ts} +18 -30
  79. package/dist/packages/sdk/src/auditClient.d.ts +21 -0
  80. package/dist/packages/sdk/src/beliefsClient.d.ts +52 -0
  81. package/dist/packages/sdk/src/client.d.ts +1558 -0
  82. package/dist/packages/sdk/src/contextClient.d.ts +9 -0
  83. package/dist/packages/sdk/src/contracts/api-enums.contract.d.ts +58 -0
  84. package/dist/{controlObjectOwnership.d.ts → packages/sdk/src/controlObjectOwnership.d.ts} +18 -35
  85. package/dist/{coreClient.d.ts → packages/sdk/src/coreClient.d.ts} +14 -38
  86. package/dist/packages/sdk/src/customTools.d.ts +65 -0
  87. package/dist/packages/sdk/src/decisionsClient.d.ts +97 -0
  88. package/dist/packages/sdk/src/graphClient.d.ts +191 -0
  89. package/dist/{harnessClient.d.ts → packages/sdk/src/harnessClient.d.ts} +33 -127
  90. package/dist/packages/sdk/src/identityClient.d.ts +104 -0
  91. package/dist/packages/sdk/src/index.d.ts +28 -0
  92. package/dist/packages/sdk/src/learningClient.d.ts +37 -0
  93. package/dist/{mcpParityClient.d.ts → packages/sdk/src/mcpParityClient.d.ts} +5 -11
  94. package/dist/packages/sdk/src/mcpParitySurface.d.ts +8 -0
  95. package/dist/{ontologyClient.d.ts → packages/sdk/src/ontologyClient.d.ts} +22 -44
  96. package/dist/packages/sdk/src/packsClient.d.ts +101 -0
  97. package/dist/{policyClient.d.ts → packages/sdk/src/policyClient.d.ts} +18 -113
  98. package/dist/packages/sdk/src/reportsClient.d.ts +31 -0
  99. package/dist/packages/sdk/src/schemaClient.d.ts +54 -0
  100. package/dist/packages/sdk/src/sdkSurface.d.ts +55 -0
  101. package/dist/packages/sdk/src/topicsClient.d.ts +45 -0
  102. package/dist/packages/sdk/src/types.d.ts +470 -0
  103. package/dist/packages/sdk/src/version.d.ts +2 -0
  104. package/dist/packages/sdk/src/workflowClient.d.ts +252 -0
  105. package/package.json +37 -92
  106. package/CHANGELOG.md +0 -13
  107. package/dist/adminClient.d.ts +0 -409
  108. package/dist/adminClient.js +0 -755
  109. package/dist/adminClient.js.map +0 -1
  110. package/dist/answersClient.d.ts +0 -23
  111. package/dist/answersClient.js +0 -333
  112. package/dist/answersClient.js.map +0 -1
  113. package/dist/audience/index.d.ts +0 -38
  114. package/dist/audience/index.js +0 -110
  115. package/dist/audience/index.js.map +0 -1
  116. package/dist/audiencesClient.js +0 -472
  117. package/dist/audiencesClient.js.map +0 -1
  118. package/dist/auditClient.d.ts +0 -29
  119. package/dist/auditClient.js +0 -386
  120. package/dist/auditClient.js.map +0 -1
  121. package/dist/beliefs/index.d.ts +0 -465
  122. package/dist/beliefs/index.js +0 -6433
  123. package/dist/beliefs/index.js.map +0 -1
  124. package/dist/beliefs/lifecycle.d.ts +0 -24
  125. package/dist/beliefs/lifecycle.js +0 -98
  126. package/dist/beliefs/lifecycle.js.map +0 -1
  127. package/dist/beliefsClient.d.ts +0 -241
  128. package/dist/beliefsClient.js +0 -646
  129. package/dist/beliefsClient.js.map +0 -1
  130. package/dist/client.d.ts +0 -2398
  131. package/dist/client.js +0 -6411
  132. package/dist/client.js.map +0 -1
  133. package/dist/contextClient.d.ts +0 -27
  134. package/dist/contextClient.js +0 -396
  135. package/dist/contextClient.js.map +0 -1
  136. package/dist/contextFacade.d.ts +0 -2
  137. package/dist/contextFacade.js +0 -73
  138. package/dist/contextFacade.js.map +0 -1
  139. package/dist/contextPackCompiler.js +0 -1091
  140. package/dist/contextPackCompiler.js.map +0 -1
  141. package/dist/contextPackPolicy.d.ts +0 -84
  142. package/dist/contextPackPolicy.js +0 -347
  143. package/dist/contextPackPolicy.js.map +0 -1
  144. package/dist/contextPackSchema.d.ts +0 -7
  145. package/dist/contextPackSchema.js +0 -203
  146. package/dist/contextPackSchema.js.map +0 -1
  147. package/dist/contextTypes.d.ts +0 -135
  148. package/dist/contextTypes.js +0 -3
  149. package/dist/contextTypes.js.map +0 -1
  150. package/dist/contracts/api-enums.contract.d.ts +0 -81
  151. package/dist/contracts/api-enums.contract.js +0 -98
  152. package/dist/contracts/api-enums.contract.js.map +0 -1
  153. package/dist/contracts/auth-session.contract.js +0 -48
  154. package/dist/contracts/auth-session.contract.js.map +0 -1
  155. package/dist/contracts/context-pack.contract.js +0 -98
  156. package/dist/contracts/context-pack.contract.js.map +0 -1
  157. package/dist/contracts/contextPack.d.ts +0 -1
  158. package/dist/contracts/contextPack.js +0 -98
  159. package/dist/contracts/contextPack.js.map +0 -1
  160. package/dist/contracts/index.d.ts +0 -9
  161. package/dist/contracts/index.js +0 -4928
  162. package/dist/contracts/index.js.map +0 -1
  163. package/dist/contracts/lens-filter.contract.js +0 -71
  164. package/dist/contracts/lens-filter.contract.js.map +0 -1
  165. package/dist/contracts/lens-workflow.contract.d.ts +0 -87
  166. package/dist/contracts/lens-workflow.contract.js +0 -123
  167. package/dist/contracts/lens-workflow.contract.js.map +0 -1
  168. package/dist/contracts/lensFilter.d.ts +0 -1
  169. package/dist/contracts/lensFilter.js +0 -71
  170. package/dist/contracts/lensFilter.js.map +0 -1
  171. package/dist/contracts/lensWorkflow.d.ts +0 -2
  172. package/dist/contracts/lensWorkflow.js +0 -123
  173. package/dist/contracts/lensWorkflow.js.map +0 -1
  174. package/dist/contracts/mcp-tools.contract.d.ts +0 -1
  175. package/dist/contracts/mcp-tools.contract.js +0 -3016
  176. package/dist/contracts/mcp-tools.contract.js.map +0 -1
  177. package/dist/contracts/mcpTools.d.ts +0 -1
  178. package/dist/contracts/mcpTools.js +0 -3016
  179. package/dist/contracts/mcpTools.js.map +0 -1
  180. package/dist/contracts/prompt.contract.d.ts +0 -26
  181. package/dist/contracts/prompt.contract.js +0 -12
  182. package/dist/contracts/prompt.contract.js.map +0 -1
  183. package/dist/contracts/prompt.d.ts +0 -1
  184. package/dist/contracts/prompt.js +0 -12
  185. package/dist/contracts/prompt.js.map +0 -1
  186. package/dist/contracts/sdk-tools.contract.d.ts +0 -2
  187. package/dist/contracts/sdk-tools.contract.js +0 -4164
  188. package/dist/contracts/sdk-tools.contract.js.map +0 -1
  189. package/dist/contracts/sdkTools.d.ts +0 -2
  190. package/dist/contracts/sdkTools.js +0 -4164
  191. package/dist/contracts/sdkTools.js.map +0 -1
  192. package/dist/contracts/workflow-runtime.contract.d.ts +0 -163
  193. package/dist/contracts/workflow-runtime.contract.js +0 -245
  194. package/dist/contracts/workflow-runtime.contract.js.map +0 -1
  195. package/dist/contracts/workflowRuntime.d.ts +0 -1
  196. package/dist/contracts/workflowRuntime.js +0 -245
  197. package/dist/contracts/workflowRuntime.js.map +0 -1
  198. package/dist/contradictions/index.d.ts +0 -158
  199. package/dist/contradictions/index.js +0 -6427
  200. package/dist/contradictions/index.js.map +0 -1
  201. package/dist/controlObjectOwnership.js +0 -215
  202. package/dist/controlObjectOwnership.js.map +0 -1
  203. package/dist/coreClient.js +0 -339
  204. package/dist/coreClient.js.map +0 -1
  205. package/dist/customTools.d.ts +0 -88
  206. package/dist/customTools.js +0 -248
  207. package/dist/customTools.js.map +0 -1
  208. package/dist/decisions/index.d.ts +0 -68
  209. package/dist/decisions/index.js +0 -6429
  210. package/dist/decisions/index.js.map +0 -1
  211. package/dist/decisionsClient.d.ts +0 -111
  212. package/dist/decisionsClient.js +0 -522
  213. package/dist/decisionsClient.js.map +0 -1
  214. package/dist/domainContext.d.ts +0 -1
  215. package/dist/domainContext.js +0 -3
  216. package/dist/domainContext.js.map +0 -1
  217. package/dist/edges/index.d.ts +0 -204
  218. package/dist/edges/index.js +0 -6428
  219. package/dist/edges/index.js.map +0 -1
  220. package/dist/events.d.ts +0 -178
  221. package/dist/events.js +0 -251
  222. package/dist/events.js.map +0 -1
  223. package/dist/eventsCore.d.ts +0 -49
  224. package/dist/eventsCore.js +0 -429
  225. package/dist/eventsCore.js.map +0 -1
  226. package/dist/evidence/index.d.ts +0 -295
  227. package/dist/evidence/index.js +0 -6428
  228. package/dist/evidence/index.js.map +0 -1
  229. package/dist/evidenceClient.d.ts +0 -119
  230. package/dist/evidenceClient.js +0 -350
  231. package/dist/evidenceClient.js.map +0 -1
  232. package/dist/facade/context.d.ts +0 -18
  233. package/dist/facade/context.js +0 -73
  234. package/dist/facade/context.js.map +0 -1
  235. package/dist/gatewayFacades.d.ts +0 -589
  236. package/dist/gatewayFacades.js +0 -2006
  237. package/dist/gatewayFacades.js.map +0 -1
  238. package/dist/graphClient.d.ts +0 -271
  239. package/dist/graphClient.js +0 -698
  240. package/dist/graphClient.js.map +0 -1
  241. package/dist/harnessClient.js +0 -607
  242. package/dist/harnessClient.js.map +0 -1
  243. package/dist/identityClient.d.ts +0 -140
  244. package/dist/identityClient.js +0 -497
  245. package/dist/identityClient.js.map +0 -1
  246. package/dist/index.d.ts +0 -45
  247. package/dist/learningClient.d.ts +0 -46
  248. package/dist/learningClient.js +0 -409
  249. package/dist/learningClient.js.map +0 -1
  250. package/dist/lenses/index.d.ts +0 -194
  251. package/dist/lenses/index.js +0 -6427
  252. package/dist/lenses/index.js.map +0 -1
  253. package/dist/mcpParityClient.js +0 -516
  254. package/dist/mcpParityClient.js.map +0 -1
  255. package/dist/mcpParitySurface.d.ts +0 -12
  256. package/dist/mcpParitySurface.js +0 -65
  257. package/dist/mcpParitySurface.js.map +0 -1
  258. package/dist/mcpTools-DPZxowDX.d.ts +0 -254
  259. package/dist/nodes/index.d.ts +0 -62
  260. package/dist/nodes/index.js +0 -6429
  261. package/dist/nodes/index.js.map +0 -1
  262. package/dist/ontologies/index.d.ts +0 -178
  263. package/dist/ontologies/index.js +0 -6430
  264. package/dist/ontologies/index.js.map +0 -1
  265. package/dist/ontologyClient.js +0 -513
  266. package/dist/ontologyClient.js.map +0 -1
  267. package/dist/opinion.d.ts +0 -11
  268. package/dist/opinion.js +0 -35
  269. package/dist/opinion.js.map +0 -1
  270. package/dist/packRuntime.d.ts +0 -2
  271. package/dist/packRuntime.js +0 -3
  272. package/dist/packRuntime.js.map +0 -1
  273. package/dist/packsClient.d.ts +0 -131
  274. package/dist/packsClient.js +0 -525
  275. package/dist/packsClient.js.map +0 -1
  276. package/dist/policyClient.js +0 -625
  277. package/dist/policyClient.js.map +0 -1
  278. package/dist/questions/index.d.ts +0 -297
  279. package/dist/questions/index.js +0 -6430
  280. package/dist/questions/index.js.map +0 -1
  281. package/dist/realtime/index.d.ts +0 -29
  282. package/dist/realtime/index.js +0 -23
  283. package/dist/realtime/index.js.map +0 -1
  284. package/dist/realtime/refs.d.ts +0 -17
  285. package/dist/realtime/refs.js +0 -9
  286. package/dist/realtime/refs.js.map +0 -1
  287. package/dist/reportsClient.d.ts +0 -41
  288. package/dist/reportsClient.js +0 -418
  289. package/dist/reportsClient.js.map +0 -1
  290. package/dist/schemaClient.d.ts +0 -64
  291. package/dist/schemaClient.js +0 -434
  292. package/dist/schemaClient.js.map +0 -1
  293. package/dist/sdkSurface.d.ts +0 -61
  294. package/dist/sdkSurface.js +0 -112
  295. package/dist/sdkSurface.js.map +0 -1
  296. package/dist/sdkTools-CwXJDACb.d.ts +0 -150
  297. package/dist/sourcesClient.d.ts +0 -24
  298. package/dist/sourcesClient.js +0 -339
  299. package/dist/sourcesClient.js.map +0 -1
  300. package/dist/topics/index.d.ts +0 -68
  301. package/dist/topics/index.js +0 -6428
  302. package/dist/topics/index.js.map +0 -1
  303. package/dist/topicsClient.d.ts +0 -84
  304. package/dist/topicsClient.js +0 -492
  305. package/dist/topicsClient.js.map +0 -1
  306. package/dist/types.d.ts +0 -715
  307. package/dist/types.js +0 -3
  308. package/dist/types.js.map +0 -1
  309. package/dist/version.d.ts +0 -4
  310. package/dist/version.js +0 -6
  311. package/dist/version.js.map +0 -1
  312. package/dist/workflowClient.d.ts +0 -316
  313. package/dist/workflowClient.js +0 -830
  314. package/dist/workflowClient.js.map +0 -1
  315. package/dist/worktrees/index.d.ts +0 -210
  316. package/dist/worktrees/index.js +0 -6430
  317. package/dist/worktrees/index.js.map +0 -1
@@ -1,2006 +0,0 @@
1
- // src/coreClient.ts
2
- var LucernApiError = class extends Error {
3
- code;
4
- status;
5
- invariant;
6
- suggestion;
7
- details;
8
- requestId;
9
- correlationId;
10
- policyTraceId;
11
- constructor(args) {
12
- super(args.message);
13
- this.name = "LucernApiError";
14
- this.code = args.code;
15
- this.status = args.status;
16
- this.invariant = args.invariant;
17
- this.suggestion = args.suggestion;
18
- this.details = args.details;
19
- this.requestId = args.requestId;
20
- this.correlationId = args.correlationId;
21
- this.policyTraceId = args.policyTraceId;
22
- }
23
- };
24
- function toQueryString(scope) {
25
- const params = new URLSearchParams();
26
- if (scope.tenantId) {
27
- params.set("tenantId", scope.tenantId);
28
- }
29
- if (scope.workspaceId) {
30
- params.set("workspaceId", scope.workspaceId);
31
- }
32
- for (const [key, value] of Object.entries(scope)) {
33
- if (key === "tenantId" || key === "workspaceId") {
34
- continue;
35
- }
36
- if (value === void 0) {
37
- continue;
38
- }
39
- params.set(key, String(value));
40
- }
41
- const serialized = params.toString();
42
- return serialized.length > 0 ? `?${serialized}` : "";
43
- }
44
- function fillRandomBytes(length) {
45
- const bytes = new Uint8Array(length);
46
- if (typeof globalThis.crypto?.getRandomValues === "function") {
47
- globalThis.crypto.getRandomValues(bytes);
48
- return bytes;
49
- }
50
- for (let index = 0; index < length; index += 1) {
51
- bytes[index] = Math.floor(Math.random() * 256);
52
- }
53
- return bytes;
54
- }
55
- function generatePortableRequestId() {
56
- if (typeof globalThis.crypto?.randomUUID === "function") {
57
- return globalThis.crypto.randomUUID();
58
- }
59
- const bytes = fillRandomBytes(16);
60
- bytes[6] = bytes[6] & 15 | 64;
61
- bytes[8] = bytes[8] & 63 | 128;
62
- const hex = Array.from(bytes, (value) => value.toString(16).padStart(2, "0"));
63
- return `${hex.slice(0, 4).join("")}-${hex.slice(4, 6).join("")}-${hex.slice(
64
- 6,
65
- 8
66
- ).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10).join("")}`;
67
- }
68
- function randomIdempotencyKey() {
69
- return generatePortableRequestId();
70
- }
71
- function isRetryableStatus(status) {
72
- return status >= 500 || status === 408 || status === 429;
73
- }
74
- function fallbackErrorCode(status) {
75
- if (status === 401) {
76
- return "AUTHENTICATION_REQUIRED";
77
- }
78
- if (status === 403) {
79
- return "FORBIDDEN";
80
- }
81
- if (status === 404) {
82
- return "NOT_FOUND";
83
- }
84
- if (status === 408) {
85
- return "UPSTREAM_ERROR";
86
- }
87
- if (status === 409) {
88
- return "CONFLICT";
89
- }
90
- if (status === 429) {
91
- return "RATE_LIMIT_EXCEEDED";
92
- }
93
- if (status >= 500) {
94
- return "UPSTREAM_ERROR";
95
- }
96
- return "INTERNAL_ERROR";
97
- }
98
- function delay(ms) {
99
- return new Promise((resolve) => setTimeout(resolve, ms));
100
- }
101
- function parseRetryAfterMs(value) {
102
- if (!value) {
103
- return null;
104
- }
105
- const trimmed = value.trim();
106
- if (!trimmed) {
107
- return null;
108
- }
109
- const numeric = Number(trimmed);
110
- if (Number.isFinite(numeric)) {
111
- return Math.max(0, Math.round(numeric * 1e3));
112
- }
113
- const parsedDate = Date.parse(trimmed);
114
- if (Number.isFinite(parsedDate)) {
115
- return Math.max(0, parsedDate - Date.now());
116
- }
117
- return null;
118
- }
119
- function computeRetryDelayMs(args) {
120
- const baseDelay = args.status === 429 ? Math.max(
121
- args.retryAfterMs ?? 0,
122
- Math.min(1e3 * 2 ** args.attempt, 1e4)
123
- ) : Math.min(1e3 * 2 ** args.attempt, 4e3);
124
- if (args.status !== 429) {
125
- return baseDelay;
126
- }
127
- const jitterWindow = Math.max(250, Math.round(baseDelay * 0.25));
128
- return baseDelay + Math.round(Math.random() * jitterWindow);
129
- }
130
- function timeoutError(timeoutMs) {
131
- const error = new Error(`Request timed out after ${timeoutMs}ms`);
132
- error.name = "AbortError";
133
- return error;
134
- }
135
- function readPolicySummaryFromDetails(details) {
136
- if (!details || typeof details !== "object" || Array.isArray(details)) {
137
- return null;
138
- }
139
- const directSummary = details.summary;
140
- if (typeof directSummary === "string" && directSummary.trim().length > 0) {
141
- return directSummary.trim();
142
- }
143
- const policy = details.policy;
144
- if (!policy || typeof policy !== "object" || Array.isArray(policy)) {
145
- return null;
146
- }
147
- const explanation = policy.explanation;
148
- if (!explanation || typeof explanation !== "object" || Array.isArray(explanation)) {
149
- return null;
150
- }
151
- const nestedSummary = explanation.summary;
152
- if (typeof nestedSummary === "string" && nestedSummary.trim().length > 0) {
153
- return nestedSummary.trim();
154
- }
155
- return null;
156
- }
157
- function createGatewayRequestClient(config = {}) {
158
- const fetchImpl = config.fetchImpl ?? fetch;
159
- const baseUrl = config.baseUrl?.replace(/\/+$/, "") ?? "";
160
- const maxRetries = config.maxRetries ?? 2;
161
- const requestIdFactory = config.requestIdFactory ?? (() => generatePortableRequestId());
162
- async function resolveAuthHeaders() {
163
- if (!config.getAuthHeaders) {
164
- return {};
165
- }
166
- return await config.getAuthHeaders();
167
- }
168
- async function fetchWithTimeout(url, init, timeoutMs) {
169
- const controller = new AbortController();
170
- const timer = setTimeout(() => controller.abort(), timeoutMs);
171
- try {
172
- return await fetchImpl(url, { ...init, signal: controller.signal });
173
- } catch (error) {
174
- if (controller.signal.aborted) {
175
- throw timeoutError(timeoutMs);
176
- }
177
- throw error;
178
- } finally {
179
- clearTimeout(timer);
180
- }
181
- }
182
- async function parsePayload(response) {
183
- const text = await response.text();
184
- if (!text) {
185
- return null;
186
- }
187
- try {
188
- return JSON.parse(text);
189
- } catch {
190
- return null;
191
- }
192
- }
193
- function resolveTimeoutMs(method, requestTimeoutMs) {
194
- if (typeof requestTimeoutMs === "number") {
195
- return requestTimeoutMs;
196
- }
197
- const methodTimeoutMs = config.timeoutMsByMethod?.[method];
198
- if (typeof methodTimeoutMs === "number") {
199
- return methodTimeoutMs;
200
- }
201
- return config.timeoutMs ?? 15e3;
202
- }
203
- function buildApiError(args) {
204
- const failure = args.failure;
205
- const legacyError = failure && typeof failure.error === "object" && failure.error !== null ? failure.error : failure?.legacyError;
206
- const correlationId = failure?.correlationId ?? args.response.headers.get("x-lucern-correlation-id")?.trim() ?? args.requestId;
207
- const policyTraceId = failure?.policyTraceId ?? args.response.headers.get("x-lucern-policy-trace-id")?.trim() ?? null;
208
- const details = failure?.details ?? legacyError?.details;
209
- const policySummary = readPolicySummaryFromDetails(details);
210
- return new LucernApiError({
211
- code: failure?.code ?? legacyError?.code ?? fallbackErrorCode(args.response.status),
212
- message: policySummary ?? (typeof failure?.error === "string" ? failure.error : legacyError?.message ?? (args.response.ok ? "Platform API returned an invalid success payload." : "Platform API request failed.")),
213
- status: args.response.status,
214
- invariant: failure?.invariant,
215
- suggestion: failure?.suggestion,
216
- details,
217
- requestId: args.requestId,
218
- correlationId,
219
- policyTraceId
220
- });
221
- }
222
- async function request(args) {
223
- const authHeaders = await resolveAuthHeaders();
224
- const method = args.method ?? "GET";
225
- const timeoutMs = resolveTimeoutMs(method, args.timeoutMs);
226
- const headers = new Headers({
227
- "content-type": "application/json",
228
- ...authHeaders
229
- });
230
- if (args.idempotencyKey) {
231
- headers.set("idempotency-key", args.idempotencyKey);
232
- }
233
- const requestId = headers.get("x-correlation-id")?.trim() || headers.get("x-request-id")?.trim() || args.requestId || requestIdFactory();
234
- if (!headers.has("x-correlation-id") && !headers.has("x-request-id")) {
235
- headers.set("x-correlation-id", requestId);
236
- }
237
- const url = `${baseUrl}${args.path}`;
238
- const serializedBody = args.body ? JSON.stringify(args.body) : void 0;
239
- const init = {
240
- method,
241
- headers,
242
- body: serializedBody
243
- };
244
- let lastError;
245
- for (let attempt = 0; attempt <= maxRetries; attempt++) {
246
- const hookRequestContext = {
247
- requestId,
248
- attempt,
249
- maxRetries,
250
- method,
251
- path: args.path,
252
- url,
253
- headers: new Headers(headers),
254
- body: serializedBody,
255
- timeoutMs
256
- };
257
- await config.onRequest?.(hookRequestContext);
258
- const startedAt = Date.now();
259
- try {
260
- const response = await fetchWithTimeout(url, init, timeoutMs);
261
- const responseClone = response.clone();
262
- const payload = await parsePayload(response);
263
- const retryAfterMs = parseRetryAfterMs(
264
- response.headers.get("Retry-After")
265
- );
266
- if (!response.ok || !payload?.success) {
267
- const failure = payload && !payload.success ? payload : null;
268
- const apiError = buildApiError({
269
- requestId,
270
- response,
271
- failure
272
- });
273
- const willRetry = attempt < maxRetries && isRetryableStatus(response.status);
274
- await config.onResponse?.({
275
- ...hookRequestContext,
276
- durationMs: Date.now() - startedAt,
277
- status: response.status,
278
- response: responseClone,
279
- error: apiError,
280
- correlationId: apiError.correlationId ?? requestId,
281
- policyTraceId: apiError.policyTraceId ?? null,
282
- retryAfterMs,
283
- willRetry
284
- });
285
- if (willRetry) {
286
- lastError = apiError;
287
- await delay(
288
- computeRetryDelayMs({
289
- attempt,
290
- status: response.status,
291
- retryAfterMs
292
- })
293
- );
294
- continue;
295
- }
296
- throw apiError;
297
- }
298
- const successPayload = payload;
299
- await config.onResponse?.({
300
- ...hookRequestContext,
301
- durationMs: Date.now() - startedAt,
302
- status: response.status,
303
- response: responseClone,
304
- correlationId: successPayload.correlationId ?? response.headers.get("x-lucern-correlation-id")?.trim() ?? requestId,
305
- policyTraceId: successPayload.policyTraceId ?? response.headers.get("x-lucern-policy-trace-id")?.trim() ?? null,
306
- idempotentReplay: successPayload.idempotentReplay,
307
- retryAfterMs,
308
- willRetry: false
309
- });
310
- return successPayload;
311
- } catch (fetchError) {
312
- if (fetchError instanceof LucernApiError) {
313
- throw fetchError;
314
- }
315
- const willRetry = attempt < maxRetries;
316
- await config.onResponse?.({
317
- ...hookRequestContext,
318
- durationMs: Date.now() - startedAt,
319
- error: fetchError,
320
- correlationId: requestId,
321
- policyTraceId: null,
322
- willRetry
323
- });
324
- lastError = fetchError;
325
- if (willRetry) {
326
- await delay(computeRetryDelayMs({ attempt }));
327
- }
328
- }
329
- }
330
- throw lastError instanceof Error ? lastError : new Error("Platform API request failed after retries.");
331
- }
332
- return {
333
- request
334
- };
335
- }
336
-
337
- // src/opinion.ts
338
- function clamp01(value) {
339
- if (!Number.isFinite(value)) {
340
- return 0;
341
- }
342
- return Math.max(0, Math.min(1, value));
343
- }
344
- function vacuous(baseRate = 0.5) {
345
- return { b: 0, d: 0, u: 1, a: clamp01(baseRate) };
346
- }
347
- function dogmatic(probability, baseRate = 0.5) {
348
- const p = clamp01(probability);
349
- return { b: p, d: 1 - p, u: 0, a: clamp01(baseRate) };
350
- }
351
- function opinionFromBaseRate(probability) {
352
- return vacuous(clamp01(probability));
353
- }
354
- function opinionFromDogmatic(probability, baseRate = 0.5) {
355
- return dogmatic(clamp01(probability), clamp01(baseRate));
356
- }
357
- function opinionFromProjected(probability, uncertainty, baseRate = 0.5) {
358
- const p = clamp01(probability);
359
- const u = clamp01(uncertainty);
360
- const remainingMass = 1 - u;
361
- return {
362
- b: p * remainingMass,
363
- d: (1 - p) * remainingMass,
364
- u,
365
- a: clamp01(baseRate)
366
- };
367
- }
368
-
369
- // src/sdkSurface.ts
370
- function asRecord(value) {
371
- return value && typeof value === "object" ? value : {};
372
- }
373
- function cleanString(value) {
374
- return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
375
- }
376
- function normalizeVerificationStatus(value) {
377
- const status = cleanString(value);
378
- if (!status) {
379
- return void 0;
380
- }
381
- if (status === "verified") {
382
- return "human_verified";
383
- }
384
- if (status === "rejected") {
385
- return "contradicted";
386
- }
387
- return status;
388
- }
389
- function cloneWith(value, patch) {
390
- return { ...value, ...patch };
391
- }
392
- function resolveTopicId(value) {
393
- return cleanString(value.topicId);
394
- }
395
- function resolveText(value) {
396
- return cleanString(value.text) ?? cleanString(value.canonicalText);
397
- }
398
- function withTopicAlias(value) {
399
- const topicId = cleanString(value.topicId) ?? void 0;
400
- if (!topicId) {
401
- return value;
402
- }
403
- return cloneWith(value, { topicId });
404
- }
405
- function withTextAlias(value) {
406
- const text = cleanString(value.text) ?? cleanString(value.canonicalText) ?? void 0;
407
- if (!text) {
408
- return value;
409
- }
410
- return cloneWith(value, { text, canonicalText: text });
411
- }
412
- function withSdkAliases(value) {
413
- return withTopicAlias(withTextAlias(value));
414
- }
415
- function normalizeNodeWriteInput(value) {
416
- const topicId = resolveTopicId(value);
417
- const text = resolveText(value);
418
- const verificationStatus = normalizeVerificationStatus(value.verificationStatus);
419
- const next = { ...value };
420
- if (topicId) {
421
- next.topicId = topicId;
422
- }
423
- if (text) {
424
- next.text = text;
425
- next.canonicalText = text;
426
- }
427
- if (verificationStatus) {
428
- next.verificationStatus = verificationStatus;
429
- }
430
- return next;
431
- }
432
- function normalizeNodeVerificationStatus(value) {
433
- return normalizeVerificationStatus(value);
434
- }
435
- function normalizeTopicQuery(value) {
436
- const topicId = cleanString(value.topicId);
437
- if (!topicId) {
438
- return value;
439
- }
440
- return { ...value, topicId };
441
- }
442
- function asListItems(data, legacyKey) {
443
- if (Array.isArray(data)) {
444
- return data;
445
- }
446
- const record = asRecord(data);
447
- if (Array.isArray(record.items)) {
448
- return record.items;
449
- }
450
- if (legacyKey && Array.isArray(record[legacyKey])) {
451
- return record[legacyKey];
452
- }
453
- return [];
454
- }
455
- function createListResult(items, legacyKey) {
456
- const result = {
457
- items,
458
- total: items.length
459
- };
460
- if (legacyKey) {
461
- result[legacyKey] = items;
462
- }
463
- return result;
464
- }
465
- function mapGatewayData(response, mapper) {
466
- return {
467
- ...response,
468
- data: mapper(response.data)
469
- };
470
- }
471
- function mapAliasedList(data, legacyKey) {
472
- const items = asListItems(data, legacyKey).map(
473
- (item) => withSdkAliases(item)
474
- );
475
- return createListResult(items, legacyKey);
476
- }
477
-
478
- // src/ontologyClient.ts
479
- function createOntologyClient(config = {}) {
480
- const gateway = createGatewayRequestClient(config);
481
- return {
482
- /**
483
- * List ontology definitions matching optional filters.
484
- */
485
- async list(filters = {}) {
486
- return gateway.request({
487
- path: `/api/platform/v1/ontologies${toQueryString(filters)}`
488
- }).then(
489
- (response) => mapGatewayData(response, (data) => {
490
- const record = data && typeof data === "object" && !Array.isArray(data) ? data : {};
491
- const ontologies = Array.isArray(record.ontologies) ? record.ontologies : Array.isArray(record.definitions) ? record.definitions : Array.isArray(data) ? data : [];
492
- const total = typeof record.total === "number" && Number.isFinite(record.total) ? record.total : ontologies.length;
493
- return {
494
- ...record,
495
- ...createListResult(ontologies, "definitions"),
496
- ontologies,
497
- total
498
- };
499
- })
500
- );
501
- },
502
- /**
503
- * Get an ontology definition by identifier.
504
- */
505
- async get(id) {
506
- return gateway.request({
507
- path: `/api/platform/v1/ontologies/${encodeURIComponent(id)}`
508
- });
509
- },
510
- /**
511
- * Bind an ontology definition to a topic.
512
- */
513
- async bind(input, idempotencyKey) {
514
- return gateway.request({
515
- path: `/api/platform/v1/ontologies/${encodeURIComponent(input.ontologyId)}/bind`,
516
- method: "POST",
517
- body: {
518
- topicId: input.topicId
519
- },
520
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
521
- });
522
- },
523
- /**
524
- * List ontology definitions.
525
- */
526
- async listDefinitions(filters = {}) {
527
- return this.list(filters);
528
- },
529
- /**
530
- * Get an ontology definition.
531
- */
532
- async getDefinition(id) {
533
- return this.get(id);
534
- },
535
- /**
536
- * Create an ontology definition.
537
- */
538
- async createDefinition(input, idempotencyKey) {
539
- return gateway.request({
540
- path: "/api/platform/v1/ontologies",
541
- method: "POST",
542
- body: input,
543
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
544
- });
545
- },
546
- /**
547
- * Update an ontology definition.
548
- */
549
- async updateDefinition(id, input, idempotencyKey) {
550
- return gateway.request({
551
- path: `/api/platform/v1/ontologies/${encodeURIComponent(id)}`,
552
- method: "PATCH",
553
- body: input,
554
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
555
- });
556
- },
557
- /**
558
- * Archive an ontology definition.
559
- */
560
- async archiveDefinition(id, idempotencyKey) {
561
- return gateway.request({
562
- path: `/api/platform/v1/ontologies/${encodeURIComponent(id)}`,
563
- method: "DELETE",
564
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
565
- });
566
- },
567
- /**
568
- * List versions for an ontology definition.
569
- */
570
- async listVersions(ontologyId, filters = {}) {
571
- return gateway.request({
572
- path: `/api/platform/v1/ontologies/${encodeURIComponent(ontologyId)}/versions${toQueryString(filters)}`
573
- }).then(
574
- (response) => mapGatewayData(
575
- response,
576
- (data) => createListResult(Array.isArray(data) ? data : [], "versions")
577
- )
578
- );
579
- },
580
- /**
581
- * Create an ontology version.
582
- */
583
- async createVersion(ontologyId, input, idempotencyKey) {
584
- return gateway.request({
585
- path: `/api/platform/v1/ontologies/${encodeURIComponent(ontologyId)}/versions`,
586
- method: "POST",
587
- body: input,
588
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
589
- });
590
- },
591
- /**
592
- * Publish an ontology version.
593
- */
594
- async publishVersion(ontologyId, versionId, idempotencyKey) {
595
- return gateway.request({
596
- path: `/api/platform/v1/ontologies/${encodeURIComponent(ontologyId)}/versions/${encodeURIComponent(versionId)}/publish`,
597
- method: "POST",
598
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
599
- });
600
- },
601
- /**
602
- * Deprecate an ontology version.
603
- */
604
- async deprecateVersion(ontologyId, versionId, idempotencyKey) {
605
- return gateway.request({
606
- path: `/api/platform/v1/ontologies/${encodeURIComponent(ontologyId)}/versions/${encodeURIComponent(versionId)}/deprecate`,
607
- method: "POST",
608
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
609
- });
610
- },
611
- /**
612
- * List topics directly bound to a specific ontology definition.
613
- * Uses the topics gateway with ontologyId filter.
614
- */
615
- async listTopics(ontologyId) {
616
- return gateway.request({
617
- path: `/api/platform/v1/topics?ontologyId=${encodeURIComponent(ontologyId)}`
618
- }).then(
619
- (response) => mapGatewayData(
620
- response,
621
- (data) => createListResult(Array.isArray(data) ? data : [], "topics")
622
- )
623
- );
624
- },
625
- /**
626
- * @deprecated Use listTopics.
627
- */
628
- async listTopicsByOntology(ontologyId) {
629
- return this.listTopics(ontologyId);
630
- }
631
- };
632
- }
633
-
634
- // src/graphClient.ts
635
- function createGraphClient(config = {}) {
636
- const gateway = createGatewayRequestClient(config);
637
- return {
638
- /**
639
- * List graph nodes matching the provided filters.
640
- */
641
- async listNodes(query) {
642
- return gateway.request({
643
- path: `/api/platform/v1/graph/nodes${toQueryString(
644
- normalizeTopicQuery(query)
645
- )}`
646
- }).then(
647
- (response) => mapGatewayData(response, (data) => mapAliasedList(data, "nodes"))
648
- );
649
- },
650
- /**
651
- * @deprecated Use listNodes.
652
- */
653
- async queryNodes(query) {
654
- return this.listNodes(query);
655
- },
656
- /**
657
- * Retrieve a single graph node by nodeId or globalId.
658
- */
659
- async getNode(query) {
660
- return gateway.request({
661
- path: `/api/platform/v1/graph/nodes${toQueryString(query)}`
662
- }).then(
663
- (response) => mapGatewayData(
664
- response,
665
- (data) => withSdkAliases(data)
666
- )
667
- );
668
- },
669
- /**
670
- * Create a graph node.
671
- */
672
- async createNode(input, idempotencyKey) {
673
- return gateway.request({
674
- path: "/api/platform/v1/graph/nodes",
675
- method: "POST",
676
- body: normalizeNodeWriteInput(input),
677
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
678
- }).then(
679
- (response) => mapGatewayData(
680
- response,
681
- (data) => withSdkAliases(data)
682
- )
683
- );
684
- },
685
- /**
686
- * Update a graph node.
687
- */
688
- async updateNode(input, idempotencyKey) {
689
- return gateway.request({
690
- path: "/api/platform/v1/graph/nodes",
691
- method: "PUT",
692
- body: normalizeNodeWriteInput(input),
693
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
694
- }).then(
695
- (response) => mapGatewayData(
696
- response,
697
- (data) => withSdkAliases(data)
698
- )
699
- );
700
- },
701
- /**
702
- * Batch create graph nodes through the admin route surface.
703
- */
704
- async batchCreateNodes(input, idempotencyKey) {
705
- return gateway.request({
706
- path: "/api/platform/v1/graph/nodes/batch",
707
- method: "POST",
708
- body: {
709
- nodes: input.nodes.map((node) => normalizeNodeWriteInput(node))
710
- },
711
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
712
- });
713
- },
714
- /**
715
- * Supersede an existing graph node with a new canonical version.
716
- */
717
- async supersedeNode(input, idempotencyKey) {
718
- return gateway.request({
719
- path: "/api/platform/v1/graph/nodes/supersede",
720
- method: "POST",
721
- body: input,
722
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
723
- });
724
- },
725
- /**
726
- * Update a node's verification status.
727
- */
728
- async verifyNode(input, idempotencyKey) {
729
- const verificationStatus = normalizeNodeVerificationStatus(input.verificationStatus) ?? input.verificationStatus;
730
- return gateway.request({
731
- path: "/api/platform/v1/graph/nodes/verify",
732
- method: "POST",
733
- body: {
734
- ...input,
735
- verificationStatus
736
- },
737
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
738
- });
739
- },
740
- /**
741
- * Permanently delete a node via the admin-only hard-delete route.
742
- */
743
- async hardDeleteNode(input, idempotencyKey) {
744
- return gateway.request({
745
- path: "/api/platform/v1/graph/nodes/hard-delete",
746
- method: "POST",
747
- body: input,
748
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
749
- });
750
- },
751
- /**
752
- * List graph edges matching the provided filters.
753
- */
754
- async listEdges(query) {
755
- return gateway.request({
756
- path: `/api/platform/v1/graph/edges${toQueryString(
757
- normalizeTopicQuery(query)
758
- )}`
759
- }).then(
760
- (response) => mapGatewayData(
761
- response,
762
- (data) => mapAliasedList(data, "edges")
763
- )
764
- );
765
- },
766
- /**
767
- * @deprecated Use listEdges.
768
- */
769
- async queryEdges(query) {
770
- return this.listEdges(query);
771
- },
772
- /**
773
- * Create a graph edge.
774
- */
775
- async createEdge(input, idempotencyKey) {
776
- return gateway.request({
777
- path: "/api/platform/v1/graph/edges",
778
- method: "POST",
779
- body: normalizeTopicQuery(input),
780
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
781
- });
782
- },
783
- /**
784
- * Delete one or more edges matching the provided filter.
785
- */
786
- async deleteEdge(query, idempotencyKey) {
787
- return gateway.request({
788
- path: `/api/platform/v1/graph/edges${toQueryString(query)}`,
789
- method: "DELETE",
790
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
791
- });
792
- },
793
- /**
794
- * Retrieve a graph neighborhood around a root node.
795
- */
796
- async neighborhood(query) {
797
- return gateway.request({
798
- path: `/api/platform/v1/graph/neighborhood${toQueryString(query)}`
799
- });
800
- },
801
- /**
802
- * Traverse the graph from a starting node.
803
- */
804
- async traverse(query) {
805
- return gateway.request({
806
- path: "/api/platform/v1/graph/traverse",
807
- method: "POST",
808
- body: normalizeTopicQuery(query)
809
- });
810
- },
811
- /**
812
- * Analyze graph structure for a topic.
813
- */
814
- async analyze(query = {}) {
815
- const normalized = normalizeTopicQuery(query);
816
- return gateway.request({
817
- path: `/api/platform/v1/graph/analyze${toQueryString({
818
- topicId: typeof normalized.topicId === "string" ? normalized.topicId : void 0,
819
- metric: typeof normalized.metric === "string" ? normalized.metric : void 0,
820
- limit: typeof normalized.limit === "number" ? normalized.limit : void 0
821
- })}`
822
- });
823
- },
824
- /**
825
- * Detect confirmation-bias patterns for a topic graph.
826
- */
827
- async bias(query = {}) {
828
- const normalized = normalizeTopicQuery(query);
829
- return gateway.request({
830
- path: `/api/platform/v1/graph/bias${toQueryString({
831
- topicId: typeof normalized.topicId === "string" ? normalized.topicId : void 0,
832
- threshold: typeof normalized.threshold === "number" ? normalized.threshold : void 0,
833
- limit: typeof normalized.limit === "number" ? normalized.limit : void 0
834
- })}`
835
- });
836
- },
837
- /**
838
- * Find graph gaps for beliefs that still need testing.
839
- */
840
- async gaps(query) {
841
- const normalized = normalizeTopicQuery(query);
842
- return gateway.request({
843
- path: `/api/platform/v1/graph/gaps${toQueryString({
844
- topicId: typeof normalized.topicId === "string" ? normalized.topicId : void 0,
845
- minConfidence: typeof normalized.minConfidence === "number" ? normalized.minConfidence : void 0
846
- })}`
847
- });
848
- },
849
- /**
850
- * Search across graph resources within a topic.
851
- */
852
- async search(query) {
853
- return gateway.request({
854
- path: "/api/platform/v1/search",
855
- method: "POST",
856
- body: normalizeTopicQuery(query)
857
- });
858
- },
859
- /**
860
- * Retrieve a graph neighborhood around a root node.
861
- */
862
- async getNeighborhood(query) {
863
- return this.neighborhood(query);
864
- },
865
- /**
866
- * Retrieve the shortest known path between two graph nodes.
867
- */
868
- async getPath(query) {
869
- return gateway.request({
870
- path: `/api/platform/v1/graph/path${toQueryString(query)}`
871
- });
872
- },
873
- /**
874
- * Retrieve graph analytics for the requested metric.
875
- */
876
- async getAnalytics(query = {}) {
877
- return gateway.request({
878
- path: `/api/platform/v1/graph/analytics${toQueryString(query)}`
879
- });
880
- }
881
- };
882
- }
883
-
884
- // src/identityClient.ts
885
- function createIdentityWhoamiClient(config = {}) {
886
- const gateway = createGatewayRequestClient(config);
887
- return {
888
- async whoami() {
889
- return gateway.request({
890
- path: "/api/platform/v1/identity/whoami"
891
- });
892
- }
893
- };
894
- }
895
- function createIdentityClient(config = {}) {
896
- const gateway = createGatewayRequestClient(config);
897
- const whoamiClient = createIdentityWhoamiClient(config);
898
- const requestPrincipalWrite = (method, input, idempotencyKey) => gateway.request({
899
- path: "/api/platform/v1/identity/principals",
900
- method,
901
- body: input,
902
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
903
- });
904
- return {
905
- /**
906
- * Resolve the current authenticated identity summary.
907
- */
908
- async whoami() {
909
- return whoamiClient.whoami().then(
910
- (response) => mapGatewayData(response, (data) => ({
911
- principalId: data.principalId,
912
- principalType: data.principalType,
913
- tenantId: data.tenantId ?? null,
914
- workspaceId: data.workspaceId ?? null,
915
- scopes: Array.isArray(data.scopes) ? data.scopes : [],
916
- roles: Array.isArray(data.roles) ? data.roles : [],
917
- isPlatformAdmin: data.isPlatformAdmin === true,
918
- isTenantAdmin: data.isTenantAdmin === true,
919
- isWorkspaceAdmin: data.isWorkspaceAdmin === true,
920
- authMode: data.authMode,
921
- sessionId: data.sessionId,
922
- delegatedBy: data.delegatedBy,
923
- expiresAt: data.expiresAt
924
- }))
925
- );
926
- },
927
- /**
928
- * List principals in the current identity scope.
929
- */
930
- async listPrincipals(query = {}) {
931
- return gateway.request({
932
- path: `/api/platform/v1/identity/principals${toQueryString(query)}`
933
- }).then(
934
- (response) => mapGatewayData(
935
- response,
936
- (data) => createListResult(
937
- Array.isArray(data) ? data : [],
938
- "principals"
939
- )
940
- )
941
- );
942
- },
943
- /**
944
- * Create a principal.
945
- */
946
- async createPrincipal(input, idempotencyKey) {
947
- return requestPrincipalWrite("POST", input, idempotencyKey);
948
- },
949
- /**
950
- * Update a principal.
951
- */
952
- async updatePrincipal(input, idempotencyKey) {
953
- return requestPrincipalWrite("PATCH", input, idempotencyKey);
954
- },
955
- /**
956
- * @deprecated Use createPrincipal or updatePrincipal.
957
- */
958
- async upsertPrincipal(input, idempotencyKey) {
959
- return requestPrincipalWrite("PATCH", input, idempotencyKey);
960
- },
961
- /**
962
- * List keys in the current identity scope.
963
- */
964
- async listKeys(query = {}) {
965
- return gateway.request({
966
- path: `/api/platform/v1/identity/keys${toQueryString(query)}`
967
- }).then(
968
- (response) => mapGatewayData(
969
- response,
970
- (data) => createListResult(Array.isArray(data) ? data : [], "keys")
971
- )
972
- );
973
- },
974
- /**
975
- * Create an API key.
976
- */
977
- async createKey(input, idempotencyKey) {
978
- return gateway.request({
979
- path: "/api/platform/v1/identity/keys",
980
- method: "POST",
981
- body: input,
982
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
983
- });
984
- },
985
- /**
986
- * Rotate an API key.
987
- */
988
- async rotateKey(keyId, input = {}, idempotencyKey) {
989
- return gateway.request({
990
- path: `/api/platform/v1/identity/keys/${encodeURIComponent(keyId)}/rotate`,
991
- method: "POST",
992
- body: input,
993
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
994
- });
995
- },
996
- /**
997
- * Delete an API key by revoking it.
998
- */
999
- async deleteKey(keyId, input = {}, idempotencyKey) {
1000
- return gateway.request({
1001
- path: `/api/platform/v1/identity/keys/${encodeURIComponent(keyId)}/revoke`,
1002
- method: "POST",
1003
- body: input,
1004
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
1005
- });
1006
- },
1007
- /**
1008
- * @deprecated Use deleteKey.
1009
- */
1010
- async revokeKey(keyId, input = {}, idempotencyKey) {
1011
- return this.deleteKey(keyId, input, idempotencyKey);
1012
- },
1013
- /**
1014
- * Search Clerk users by email or display attributes.
1015
- */
1016
- async searchClerkUsers(q) {
1017
- return gateway.request({
1018
- path: `/api/platform/v1/identity/clerk-users${toQueryString({ q })}`
1019
- });
1020
- }
1021
- };
1022
- }
1023
-
1024
- // src/topicsClient.ts
1025
- function asRecord2(value) {
1026
- return value && typeof value === "object" ? value : {};
1027
- }
1028
- function cleanString2(value) {
1029
- return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
1030
- }
1031
- function normalizeTopicRecord(value) {
1032
- const record = asRecord2(value);
1033
- const topicId = cleanString2(record.topicId) ?? cleanString2(record.id) ?? cleanString2(record._id);
1034
- return withTopicAlias({
1035
- ...record,
1036
- ...topicId ? { topicId } : {}
1037
- });
1038
- }
1039
- function normalizeTopicTreeNode(value) {
1040
- return normalizeTopicRecord(value);
1041
- }
1042
- function createTopicsClient(config = {}) {
1043
- const gateway = createGatewayRequestClient(config);
1044
- return {
1045
- async list(query = {}) {
1046
- const topicId = resolveTopicId(query);
1047
- return gateway.request({
1048
- path: `/api/platform/v1/topics${toQueryString({
1049
- ...topicId ? { topicId } : {},
1050
- ontologyId: query.ontologyId,
1051
- parentTopicId: query.parentTopicId,
1052
- status: query.status,
1053
- type: query.type
1054
- })}`
1055
- }).then(
1056
- (response) => mapGatewayData(response, (data) => {
1057
- const record = asRecord2(data);
1058
- const items = Array.isArray(record.topics) ? record.topics.map(normalizeTopicRecord) : [];
1059
- return {
1060
- ...createListResult(items, "topics"),
1061
- ...record,
1062
- topics: items,
1063
- total: typeof record.total === "number" ? record.total : items.length
1064
- };
1065
- })
1066
- );
1067
- },
1068
- async get(topicId) {
1069
- return gateway.request({
1070
- path: `/api/platform/v1/topics/${encodeURIComponent(topicId)}`
1071
- }).then(
1072
- (response) => mapGatewayData(
1073
- response,
1074
- (data) => normalizeTopicRecord(asRecord2(data).topic ?? data)
1075
- )
1076
- );
1077
- },
1078
- async create(input, idempotencyKey) {
1079
- const topicId = resolveTopicId(input);
1080
- return gateway.request({
1081
- path: "/api/platform/v1/topics",
1082
- method: "POST",
1083
- body: {
1084
- ...input,
1085
- ...topicId ? { topicId } : {},
1086
- type: input.type ?? "theme"
1087
- },
1088
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
1089
- }).then(
1090
- (response) => mapGatewayData(response, (data) => normalizeTopicRecord(data))
1091
- );
1092
- },
1093
- async update(topicId, input, idempotencyKey) {
1094
- return gateway.request({
1095
- path: `/api/platform/v1/topics/${encodeURIComponent(topicId)}`,
1096
- method: "PATCH",
1097
- body: input,
1098
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
1099
- }).then(
1100
- (response) => mapGatewayData(response, (data) => normalizeTopicRecord(data))
1101
- );
1102
- },
1103
- async getTree(topicId, query = {}) {
1104
- return gateway.request({
1105
- path: `/api/platform/v1/topics/${encodeURIComponent(topicId)}/tree${toQueryString(
1106
- query
1107
- )}`
1108
- }).then(
1109
- (response) => mapGatewayData(response, (data) => {
1110
- const record = asRecord2(data);
1111
- return {
1112
- tree: Array.isArray(record.tree) ? record.tree.map(normalizeTopicTreeNode) : []
1113
- };
1114
- })
1115
- );
1116
- },
1117
- async getCoverage(topicId, query = {}) {
1118
- return gateway.request({
1119
- path: `/api/platform/v1/topics/${encodeURIComponent(topicId)}/coverage${toQueryString(
1120
- query
1121
- )}`
1122
- });
1123
- },
1124
- async remove(topicId, idempotencyKey) {
1125
- return gateway.request({
1126
- path: "/api/platform/v1/topics/remove",
1127
- method: "POST",
1128
- body: { id: topicId },
1129
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
1130
- });
1131
- },
1132
- async bulkCreate(input, idempotencyKey) {
1133
- return gateway.request({
1134
- path: "/api/platform/v1/topics/bulk",
1135
- method: "POST",
1136
- body: input,
1137
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
1138
- });
1139
- }
1140
- };
1141
- }
1142
-
1143
- // src/gatewayFacades.ts
1144
- function normalizeBeliefConfidenceInput(input) {
1145
- const opinion = "opinion" in input ? input.opinion : input.interpretation === "base_rate" ? opinionFromBaseRate(input.confidence) : input.interpretation === "dogmatic" ? opinionFromDogmatic(input.confidence, input.baseRate) : opinionFromProjected(
1146
- input.confidence,
1147
- input.uncertainty,
1148
- input.baseRate
1149
- );
1150
- return {
1151
- belief: opinion.b,
1152
- disbelief: opinion.d,
1153
- uncertainty: opinion.u,
1154
- baseRate: opinion.a,
1155
- trigger: input.trigger,
1156
- rationale: input.rationale,
1157
- maxInlinePropagationTargets: input.maxInlinePropagationTargets
1158
- };
1159
- }
1160
- function serializeTypes(types) {
1161
- return Array.isArray(types) && types.length > 0 ? types.join(",") : void 0;
1162
- }
1163
- function createBeliefsFacade(config = {}) {
1164
- const gateway = createGatewayRequestClient(config);
1165
- return {
1166
- async create(input, idempotencyKey = randomIdempotencyKey()) {
1167
- return gateway.request({
1168
- path: "/api/platform/v1/beliefs",
1169
- method: "POST",
1170
- body: input,
1171
- idempotencyKey
1172
- });
1173
- },
1174
- async get(id) {
1175
- return gateway.request({
1176
- path: `/api/platform/v1/beliefs/${encodeURIComponent(id)}`
1177
- });
1178
- },
1179
- async list(query) {
1180
- return gateway.request({
1181
- path: `/api/platform/v1/beliefs${toQueryString({
1182
- topicId: query.topicId,
1183
- status: query.status,
1184
- worktreeId: query.worktreeId,
1185
- minConfidence: query.minConfidence,
1186
- limit: query.limit,
1187
- cursor: query.cursor
1188
- })}`
1189
- });
1190
- },
1191
- async refine(id, input, idempotencyKey = randomIdempotencyKey()) {
1192
- return gateway.request({
1193
- path: `/api/platform/v1/beliefs/${encodeURIComponent(id)}`,
1194
- method: "PATCH",
1195
- body: input,
1196
- idempotencyKey
1197
- });
1198
- },
1199
- async fork(id, input, idempotencyKey = randomIdempotencyKey()) {
1200
- return gateway.request({
1201
- path: `/api/platform/v1/beliefs/${encodeURIComponent(id)}/fork`,
1202
- method: "POST",
1203
- body: input,
1204
- idempotencyKey
1205
- });
1206
- },
1207
- async updateConfidence(id, input, idempotencyKey = randomIdempotencyKey()) {
1208
- return gateway.request({
1209
- path: `/api/platform/v1/beliefs/${encodeURIComponent(id)}/confidence`,
1210
- method: "POST",
1211
- body: normalizeBeliefConfidenceInput(input),
1212
- idempotencyKey
1213
- });
1214
- },
1215
- async updateStatus(input, idempotencyKey = randomIdempotencyKey()) {
1216
- return gateway.request({
1217
- path: "/api/platform/v1/beliefs/update-status",
1218
- method: "POST",
1219
- body: input,
1220
- idempotencyKey
1221
- });
1222
- },
1223
- async updateRationale(input, idempotencyKey = randomIdempotencyKey()) {
1224
- return gateway.request({
1225
- path: "/api/platform/v1/beliefs/update-rationale",
1226
- method: "POST",
1227
- body: input,
1228
- idempotencyKey
1229
- });
1230
- },
1231
- async linkBeliefs(input, idempotencyKey = randomIdempotencyKey()) {
1232
- return gateway.request({
1233
- path: "/api/platform/v1/beliefs/link",
1234
- method: "POST",
1235
- body: input,
1236
- idempotencyKey
1237
- });
1238
- },
1239
- async unlinkEvidence(input, idempotencyKey = randomIdempotencyKey()) {
1240
- return gateway.request({
1241
- path: "/api/platform/v1/beliefs/unlink-evidence",
1242
- method: "POST",
1243
- body: input,
1244
- idempotencyKey
1245
- });
1246
- },
1247
- async updateCriticality(input, idempotencyKey = randomIdempotencyKey()) {
1248
- return gateway.request({
1249
- path: "/api/platform/v1/beliefs/update-criticality",
1250
- method: "POST",
1251
- body: input,
1252
- idempotencyKey
1253
- });
1254
- },
1255
- async batchUpdateCriticality(input, idempotencyKey = randomIdempotencyKey()) {
1256
- return gateway.request({
1257
- path: "/api/platform/v1/beliefs/batch-update-criticality",
1258
- method: "POST",
1259
- body: input,
1260
- idempotencyKey
1261
- });
1262
- },
1263
- async reassignTopic(input, idempotencyKey = randomIdempotencyKey()) {
1264
- return gateway.request({
1265
- path: "/api/platform/v1/beliefs/reassign-topic",
1266
- method: "POST",
1267
- body: input,
1268
- idempotencyKey
1269
- });
1270
- },
1271
- async archive(id, input = {}, idempotencyKey = randomIdempotencyKey()) {
1272
- return gateway.request({
1273
- path: `/api/platform/v1/beliefs/${encodeURIComponent(id)}`,
1274
- method: "DELETE",
1275
- body: input,
1276
- idempotencyKey
1277
- });
1278
- },
1279
- async lineage(id) {
1280
- return gateway.request({
1281
- path: `/api/platform/v1/beliefs/${encodeURIComponent(id)}/lineage`
1282
- });
1283
- },
1284
- async confidenceHistory(id) {
1285
- return gateway.request({
1286
- path: `/api/platform/v1/beliefs/${encodeURIComponent(id)}/confidence-history`
1287
- });
1288
- },
1289
- async opinionHistory(id) {
1290
- return gateway.request({
1291
- path: `/api/platform/v1/beliefs/${encodeURIComponent(id)}/confidence-history`
1292
- });
1293
- },
1294
- async createContract(id, input, idempotencyKey = randomIdempotencyKey()) {
1295
- return gateway.request({
1296
- path: `/api/platform/v1/beliefs/${encodeURIComponent(id)}/contracts`,
1297
- method: "POST",
1298
- body: input,
1299
- idempotencyKey
1300
- });
1301
- },
1302
- async bisect(id, input, idempotencyKey = randomIdempotencyKey()) {
1303
- return gateway.request({
1304
- path: `/api/platform/v1/beliefs/${encodeURIComponent(id)}/bisect`,
1305
- method: "POST",
1306
- body: input,
1307
- idempotencyKey
1308
- });
1309
- }
1310
- };
1311
- }
1312
- function createContradictionsFacade(config = {}) {
1313
- const gateway = createGatewayRequestClient(config);
1314
- return {
1315
- async flag(input, idempotencyKey = randomIdempotencyKey()) {
1316
- return gateway.request({
1317
- path: "/api/platform/v1/contradictions",
1318
- method: "POST",
1319
- body: input,
1320
- idempotencyKey
1321
- });
1322
- },
1323
- async list(query) {
1324
- return gateway.request({
1325
- path: `/api/platform/v1/contradictions${toQueryString({
1326
- topicId: query.topicId,
1327
- status: query.status,
1328
- limit: query.limit,
1329
- cursor: query.cursor
1330
- })}`
1331
- });
1332
- },
1333
- async get(id) {
1334
- return gateway.request({
1335
- path: `/api/platform/v1/contradictions/${encodeURIComponent(id)}`
1336
- });
1337
- }
1338
- };
1339
- }
1340
- function createEdgesFacade(config = {}) {
1341
- const gateway = createGatewayRequestClient(config);
1342
- return {
1343
- async create(input, idempotencyKey = randomIdempotencyKey()) {
1344
- return gateway.request({
1345
- path: "/api/platform/v1/edges",
1346
- method: "POST",
1347
- body: input,
1348
- idempotencyKey
1349
- });
1350
- },
1351
- async list(query) {
1352
- return gateway.request({
1353
- path: `/api/platform/v1/edges${toQueryString({
1354
- sourceId: query.sourceId,
1355
- edgeType: query.edgeType,
1356
- limit: query.limit,
1357
- cursor: query.cursor
1358
- })}`
1359
- });
1360
- },
1361
- async traverse(input, idempotencyKey = randomIdempotencyKey()) {
1362
- return gateway.request({
1363
- path: "/api/platform/v1/edges/traverse",
1364
- method: "POST",
1365
- body: input,
1366
- idempotencyKey
1367
- });
1368
- },
1369
- async update(input, idempotencyKey = randomIdempotencyKey()) {
1370
- return gateway.request({
1371
- path: "/api/platform/v1/edges/update",
1372
- method: "POST",
1373
- body: input,
1374
- idempotencyKey
1375
- });
1376
- },
1377
- async remove(input, idempotencyKey = randomIdempotencyKey()) {
1378
- return gateway.request({
1379
- path: "/api/platform/v1/edges/remove",
1380
- method: "POST",
1381
- body: input,
1382
- idempotencyKey
1383
- });
1384
- },
1385
- async removeBetween(input, idempotencyKey = randomIdempotencyKey()) {
1386
- return gateway.request({
1387
- path: "/api/platform/v1/edges/remove-between",
1388
- method: "POST",
1389
- body: input,
1390
- idempotencyKey
1391
- });
1392
- },
1393
- async batchCreate(input, idempotencyKey = randomIdempotencyKey()) {
1394
- return gateway.request({
1395
- path: "/api/platform/v1/edges/batch",
1396
- method: "POST",
1397
- body: input,
1398
- idempotencyKey
1399
- });
1400
- },
1401
- async delete(input, idempotencyKey = randomIdempotencyKey()) {
1402
- return gateway.request({
1403
- path: "/api/platform/v1/edges/delete",
1404
- method: "POST",
1405
- body: input,
1406
- idempotencyKey
1407
- });
1408
- }
1409
- };
1410
- }
1411
- function createEvidenceFacade(config = {}) {
1412
- const gateway = createGatewayRequestClient(config);
1413
- return {
1414
- async create(input, idempotencyKey = randomIdempotencyKey()) {
1415
- return gateway.request({
1416
- path: "/api/platform/v1/evidence",
1417
- method: "POST",
1418
- body: input,
1419
- idempotencyKey
1420
- });
1421
- },
1422
- async get(id) {
1423
- return gateway.request({
1424
- path: `/api/platform/v1/evidence/${encodeURIComponent(id)}`
1425
- });
1426
- },
1427
- async list(query) {
1428
- return gateway.request({
1429
- path: `/api/platform/v1/evidence${toQueryString({
1430
- topicId: query.topicId,
1431
- targetId: query.targetId,
1432
- limit: query.limit,
1433
- cursor: query.cursor
1434
- })}`
1435
- });
1436
- },
1437
- async link(input, idempotencyKey = randomIdempotencyKey()) {
1438
- return gateway.request({
1439
- path: `/api/platform/v1/evidence/${encodeURIComponent(input.evidenceId)}/link`,
1440
- method: "POST",
1441
- body: {
1442
- targetId: input.targetId,
1443
- targetType: input.targetType,
1444
- weight: input.weight,
1445
- rationale: input.rationale
1446
- },
1447
- idempotencyKey
1448
- });
1449
- },
1450
- async search(query, idempotencyKey = randomIdempotencyKey()) {
1451
- return gateway.request({
1452
- path: "/api/platform/v1/evidence/search",
1453
- method: "POST",
1454
- body: query,
1455
- idempotencyKey
1456
- });
1457
- },
1458
- async updateStatus(input, idempotencyKey = randomIdempotencyKey()) {
1459
- return gateway.request({
1460
- path: "/api/platform/v1/evidence/update-status",
1461
- method: "POST",
1462
- body: input,
1463
- idempotencyKey
1464
- });
1465
- },
1466
- async update(input, idempotencyKey = randomIdempotencyKey()) {
1467
- return gateway.request({
1468
- path: "/api/platform/v1/evidence/update",
1469
- method: "POST",
1470
- body: input,
1471
- idempotencyKey
1472
- });
1473
- },
1474
- async flagIncorrect(input, idempotencyKey = randomIdempotencyKey()) {
1475
- return gateway.request({
1476
- path: "/api/platform/v1/evidence/flag-incorrect",
1477
- method: "POST",
1478
- body: input,
1479
- idempotencyKey
1480
- });
1481
- },
1482
- async remove(input, idempotencyKey = randomIdempotencyKey()) {
1483
- return gateway.request({
1484
- path: "/api/platform/v1/evidence/remove",
1485
- method: "POST",
1486
- body: input,
1487
- idempotencyKey
1488
- });
1489
- },
1490
- async updateVerificationStatus(input, idempotencyKey = randomIdempotencyKey()) {
1491
- return gateway.request({
1492
- path: "/api/platform/v1/evidence/update-verification-status",
1493
- method: "POST",
1494
- body: input,
1495
- idempotencyKey
1496
- });
1497
- }
1498
- };
1499
- }
1500
- function createEventsFacade(config = {}) {
1501
- const gateway = createGatewayRequestClient(config);
1502
- return {
1503
- async list(query = {}) {
1504
- return gateway.request({
1505
- path: `/api/platform/v1/events${toQueryString({
1506
- topicId: query.topicId,
1507
- after: query.after,
1508
- types: serializeTypes(query.types),
1509
- startTime: query.startTime,
1510
- endTime: query.endTime,
1511
- limit: query.limit
1512
- })}`
1513
- });
1514
- },
1515
- async replay(input, idempotencyKey = randomIdempotencyKey()) {
1516
- return gateway.request({
1517
- path: "/api/platform/v1/events/replay",
1518
- method: "POST",
1519
- body: input,
1520
- idempotencyKey
1521
- });
1522
- }
1523
- };
1524
- }
1525
- function createGraphFacade(config = {}) {
1526
- const graphClient = createGraphClient(config);
1527
- const gateway = createGatewayRequestClient(config);
1528
- return {
1529
- async neighborhood(input) {
1530
- return graphClient.neighborhood({
1531
- globalId: input.globalId,
1532
- globalIds: Array.isArray(input.globalIds) ? input.globalIds.join(",") : input.globalIds,
1533
- maxDepth: input.maxDepth
1534
- });
1535
- },
1536
- async traverse(input) {
1537
- return graphClient.traverse(input);
1538
- },
1539
- async analyze(input = {}) {
1540
- return graphClient.analyze(input);
1541
- },
1542
- async bias(input = {}) {
1543
- return graphClient.bias(input);
1544
- },
1545
- async gaps(input) {
1546
- return graphClient.gaps(input);
1547
- },
1548
- async falsify(input, idempotencyKey = randomIdempotencyKey()) {
1549
- return gateway.request({
1550
- path: "/api/platform/v1/graph/falsify",
1551
- method: "POST",
1552
- body: input,
1553
- idempotencyKey
1554
- });
1555
- }
1556
- };
1557
- }
1558
- function createIdentityFacade(config = {}) {
1559
- const identityClient = createIdentityClient(config);
1560
- return {
1561
- async whoami() {
1562
- const response = await identityClient.whoami();
1563
- return Object.assign({}, response, response.data);
1564
- }
1565
- };
1566
- }
1567
- function createOntologiesFacade(config = {}) {
1568
- const ontologyClient = createOntologyClient(config);
1569
- const gateway = createGatewayRequestClient(config);
1570
- return {
1571
- async get(id) {
1572
- return gateway.request({
1573
- path: `/api/platform/v1/ontologies/${encodeURIComponent(id)}`
1574
- });
1575
- },
1576
- async list(query = {}) {
1577
- return ontologyClient.list(query);
1578
- },
1579
- async bind(input, idempotencyKey) {
1580
- return gateway.request({
1581
- path: `/api/platform/v1/ontologies/${encodeURIComponent(input.ontologyId)}/bind`,
1582
- method: "POST",
1583
- body: {
1584
- topicId: input.topicId
1585
- },
1586
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
1587
- });
1588
- },
1589
- async match(input, idempotencyKey) {
1590
- return gateway.request({
1591
- path: "/api/platform/v1/ontologies/match",
1592
- method: "POST",
1593
- body: input,
1594
- idempotencyKey
1595
- });
1596
- }
1597
- };
1598
- }
1599
- function createQuestionsFacade(config = {}) {
1600
- const gateway = createGatewayRequestClient(config);
1601
- return {
1602
- async create(input, idempotencyKey = randomIdempotencyKey()) {
1603
- return gateway.request({
1604
- path: "/api/platform/v1/questions",
1605
- method: "POST",
1606
- body: input,
1607
- idempotencyKey
1608
- });
1609
- },
1610
- async get(id) {
1611
- return gateway.request({
1612
- path: `/api/platform/v1/questions/${encodeURIComponent(id)}`
1613
- });
1614
- },
1615
- async list(query) {
1616
- return gateway.request({
1617
- path: `/api/platform/v1/questions${toQueryString({
1618
- topicId: query.topicId,
1619
- status: query.status,
1620
- priority: query.priority,
1621
- worktreeId: query.worktreeId,
1622
- limit: query.limit,
1623
- cursor: query.cursor
1624
- })}`
1625
- });
1626
- },
1627
- async answer(id, input, idempotencyKey = randomIdempotencyKey()) {
1628
- return gateway.request({
1629
- path: `/api/platform/v1/questions/${encodeURIComponent(id)}/answer`,
1630
- method: "POST",
1631
- body: input,
1632
- idempotencyKey
1633
- });
1634
- },
1635
- async refine(id, input, idempotencyKey = randomIdempotencyKey()) {
1636
- return gateway.request({
1637
- path: `/api/platform/v1/questions/${encodeURIComponent(id)}/refine`,
1638
- method: "POST",
1639
- body: input,
1640
- idempotencyKey
1641
- });
1642
- },
1643
- async archive(id, input = {}, idempotencyKey = randomIdempotencyKey()) {
1644
- return gateway.request({
1645
- path: `/api/platform/v1/questions/${encodeURIComponent(id)}`,
1646
- method: "DELETE",
1647
- body: input,
1648
- idempotencyKey
1649
- });
1650
- },
1651
- async updateStatus(id, input, idempotencyKey = randomIdempotencyKey()) {
1652
- return gateway.request({
1653
- path: `/api/platform/v1/questions/${encodeURIComponent(id)}/status`,
1654
- method: "PATCH",
1655
- body: input,
1656
- idempotencyKey
1657
- });
1658
- },
1659
- async batchCreate(input, idempotencyKey = randomIdempotencyKey()) {
1660
- return gateway.request({
1661
- path: "/api/platform/v1/questions/batch",
1662
- method: "POST",
1663
- body: input,
1664
- idempotencyKey
1665
- });
1666
- },
1667
- async add(input, idempotencyKey = randomIdempotencyKey()) {
1668
- return gateway.request({
1669
- path: "/api/platform/v1/questions/add",
1670
- method: "POST",
1671
- body: input,
1672
- idempotencyKey
1673
- });
1674
- },
1675
- async updatePriority(input, idempotencyKey = randomIdempotencyKey()) {
1676
- return gateway.request({
1677
- path: "/api/platform/v1/questions/update-priority",
1678
- method: "POST",
1679
- body: input,
1680
- idempotencyKey
1681
- });
1682
- },
1683
- async advanceToConviction(input, idempotencyKey = randomIdempotencyKey()) {
1684
- return gateway.request({
1685
- path: "/api/platform/v1/questions/advance-to-conviction",
1686
- method: "POST",
1687
- body: input,
1688
- idempotencyKey
1689
- });
1690
- },
1691
- async updateConviction(input, idempotencyKey = randomIdempotencyKey()) {
1692
- return gateway.request({
1693
- path: "/api/platform/v1/questions/update-conviction",
1694
- method: "POST",
1695
- body: input,
1696
- idempotencyKey
1697
- });
1698
- },
1699
- async finalizeConviction(input, idempotencyKey = randomIdempotencyKey()) {
1700
- return gateway.request({
1701
- path: "/api/platform/v1/questions/finalize-conviction",
1702
- method: "POST",
1703
- body: input,
1704
- idempotencyKey
1705
- });
1706
- },
1707
- async update(input, idempotencyKey = randomIdempotencyKey()) {
1708
- return gateway.request({
1709
- path: "/api/platform/v1/questions/update",
1710
- method: "POST",
1711
- body: input,
1712
- idempotencyKey
1713
- });
1714
- },
1715
- async delete(input, idempotencyKey = randomIdempotencyKey()) {
1716
- return gateway.request({
1717
- path: "/api/platform/v1/questions/delete",
1718
- method: "POST",
1719
- body: input,
1720
- idempotencyKey
1721
- });
1722
- }
1723
- };
1724
- }
1725
- function createSearchFacade(config = {}) {
1726
- const gateway = createGatewayRequestClient(config);
1727
- return {
1728
- async query(input) {
1729
- return gateway.request({
1730
- path: "/api/platform/v1/search",
1731
- method: "POST",
1732
- body: input
1733
- });
1734
- }
1735
- };
1736
- }
1737
- function createTasksFacade(config = {}) {
1738
- const gateway = createGatewayRequestClient(config);
1739
- return {
1740
- async create(input, idempotencyKey = randomIdempotencyKey()) {
1741
- return gateway.request({
1742
- path: "/api/platform/v1/tasks",
1743
- method: "POST",
1744
- body: input,
1745
- idempotencyKey
1746
- });
1747
- },
1748
- async update(input, idempotencyKey = randomIdempotencyKey()) {
1749
- return gateway.request({
1750
- path: `/api/platform/v1/tasks/${encodeURIComponent(input.id)}`,
1751
- method: "PATCH",
1752
- body: {
1753
- title: input.title,
1754
- description: input.description,
1755
- priority: input.priority,
1756
- status: input.status,
1757
- linkedBeliefId: input.linkedBeliefId,
1758
- linkedQuestionId: input.linkedQuestionId,
1759
- linkedWorktreeId: input.linkedWorktreeId,
1760
- metadata: input.metadata
1761
- },
1762
- idempotencyKey
1763
- });
1764
- },
1765
- async complete(input, idempotencyKey = randomIdempotencyKey()) {
1766
- return gateway.request({
1767
- path: `/api/platform/v1/tasks/${encodeURIComponent(input.id)}/complete`,
1768
- method: "POST",
1769
- body: {
1770
- outputSummary: input.outputSummary
1771
- },
1772
- idempotencyKey
1773
- });
1774
- },
1775
- async list(query) {
1776
- return gateway.request({
1777
- path: `/api/platform/v1/tasks${toQueryString({
1778
- topicId: query.topicId,
1779
- worktreeId: query.worktreeId,
1780
- status: query.status,
1781
- limit: query.limit
1782
- })}`
1783
- });
1784
- }
1785
- };
1786
- }
1787
- function createTopicsFacade(config = {}) {
1788
- const topicsClient = createTopicsClient(config);
1789
- return {
1790
- async create(input, idempotencyKey) {
1791
- return topicsClient.create(input, idempotencyKey);
1792
- },
1793
- async get(id) {
1794
- return topicsClient.get(id);
1795
- },
1796
- async list(query = {}) {
1797
- return topicsClient.list(query);
1798
- },
1799
- async update(input, idempotencyKey) {
1800
- const { id, ...rest } = input;
1801
- return topicsClient.update(id, rest, idempotencyKey);
1802
- },
1803
- async tree(input) {
1804
- return topicsClient.getTree(input.id, {
1805
- maxDepth: input.maxDepth
1806
- });
1807
- },
1808
- async coverage(input) {
1809
- return topicsClient.getCoverage(input.id, {
1810
- includeDescendants: input.includeDescendants,
1811
- maxDepth: input.maxDepth
1812
- });
1813
- },
1814
- async remove(id, idempotencyKey = randomIdempotencyKey()) {
1815
- return topicsClient.remove(id, idempotencyKey);
1816
- },
1817
- async bulkCreate(input, idempotencyKey = randomIdempotencyKey()) {
1818
- return topicsClient.bulkCreate(input, idempotencyKey);
1819
- }
1820
- };
1821
- }
1822
- function createWebhooksFacade(config = {}) {
1823
- const gateway = createGatewayRequestClient(config);
1824
- return {
1825
- async create(input, idempotencyKey = randomIdempotencyKey()) {
1826
- return gateway.request({
1827
- path: "/api/platform/v1/webhooks",
1828
- method: "POST",
1829
- body: input,
1830
- idempotencyKey
1831
- });
1832
- },
1833
- async list(query = {}) {
1834
- return gateway.request({
1835
- path: `/api/platform/v1/webhooks${toQueryString({
1836
- topicId: query.topicId
1837
- })}`
1838
- });
1839
- },
1840
- async get(id) {
1841
- return gateway.request({
1842
- path: `/api/platform/v1/webhooks/${encodeURIComponent(id)}`
1843
- });
1844
- },
1845
- async update(id, input, idempotencyKey = randomIdempotencyKey()) {
1846
- return gateway.request({
1847
- path: `/api/platform/v1/webhooks/${encodeURIComponent(id)}`,
1848
- method: "PATCH",
1849
- body: input,
1850
- idempotencyKey
1851
- });
1852
- },
1853
- async delete(id, idempotencyKey = randomIdempotencyKey()) {
1854
- return gateway.request({
1855
- path: `/api/platform/v1/webhooks/${encodeURIComponent(id)}`,
1856
- method: "DELETE",
1857
- idempotencyKey
1858
- });
1859
- },
1860
- async test(id, input = {}, idempotencyKey = randomIdempotencyKey()) {
1861
- return gateway.request({
1862
- path: `/api/platform/v1/webhooks/${encodeURIComponent(id)}/test`,
1863
- method: "POST",
1864
- body: input,
1865
- idempotencyKey
1866
- });
1867
- },
1868
- async deliveries(id, query = {}) {
1869
- return gateway.request({
1870
- path: `/api/platform/v1/webhooks/${encodeURIComponent(id)}/deliveries${toQueryString({
1871
- limit: query.limit
1872
- })}`
1873
- });
1874
- },
1875
- async health(id) {
1876
- return gateway.request({
1877
- path: `/api/platform/v1/webhooks/${encodeURIComponent(id)}/health`
1878
- });
1879
- }
1880
- };
1881
- }
1882
- function createWorktreesFacade(config = {}) {
1883
- const gateway = createGatewayRequestClient(config);
1884
- return {
1885
- async create(input, idempotencyKey = randomIdempotencyKey()) {
1886
- return gateway.request({
1887
- path: "/api/platform/v1/worktrees",
1888
- method: "POST",
1889
- body: input,
1890
- idempotencyKey
1891
- });
1892
- },
1893
- async list(query) {
1894
- return gateway.request({
1895
- path: `/api/platform/v1/worktrees${toQueryString({
1896
- topicId: query.topicId,
1897
- status: query.status,
1898
- limit: query.limit
1899
- })}`
1900
- });
1901
- },
1902
- async activate(input, idempotencyKey = randomIdempotencyKey()) {
1903
- return gateway.request({
1904
- path: `/api/platform/v1/worktrees/${encodeURIComponent(input.id)}/activate`,
1905
- method: "POST",
1906
- body: {},
1907
- idempotencyKey
1908
- });
1909
- },
1910
- async update(input, idempotencyKey = randomIdempotencyKey()) {
1911
- return gateway.request({
1912
- path: `/api/platform/v1/worktrees/${encodeURIComponent(input.id)}`,
1913
- method: "PATCH",
1914
- body: {
1915
- objective: input.objective,
1916
- hypothesis: input.hypothesis,
1917
- rationale: input.rationale,
1918
- track: input.track,
1919
- trackPosition: input.trackPosition,
1920
- executionBand: input.executionBand,
1921
- executionOrder: input.executionOrder,
1922
- dependsOn: input.dependsOn,
1923
- blocks: input.blocks,
1924
- gate: input.gate,
1925
- status: input.status,
1926
- topicId: input.topicId,
1927
- additionalTopicIds: input.additionalTopicIds,
1928
- proofArtifacts: input.proofArtifacts,
1929
- staffingHint: input.staffingHint,
1930
- lastReconciledAt: input.lastReconciledAt,
1931
- autoFixPolicy: input.autoFixPolicy,
1932
- lensId: input.lensId
1933
- },
1934
- idempotencyKey
1935
- });
1936
- },
1937
- async merge(input, idempotencyKey = randomIdempotencyKey()) {
1938
- return gateway.request({
1939
- path: `/api/platform/v1/worktrees/${encodeURIComponent(input.id)}/merge`,
1940
- method: "POST",
1941
- body: {
1942
- summary: input.summary,
1943
- outcomes: input.outcomes
1944
- },
1945
- idempotencyKey
1946
- });
1947
- },
1948
- async updateTargets(input, idempotencyKey = randomIdempotencyKey()) {
1949
- return gateway.request({
1950
- path: `/api/platform/v1/worktrees/${encodeURIComponent(input.id)}/targets`,
1951
- method: "POST",
1952
- body: {
1953
- addBeliefIds: input.addBeliefIds,
1954
- addQuestionIds: input.addQuestionIds,
1955
- removeBeliefIds: input.removeBeliefIds,
1956
- removeQuestionIds: input.removeQuestionIds
1957
- },
1958
- idempotencyKey
1959
- });
1960
- },
1961
- async complete(input, idempotencyKey = randomIdempotencyKey()) {
1962
- return gateway.request({
1963
- path: "/api/platform/v1/worktrees/complete",
1964
- method: "POST",
1965
- body: input,
1966
- idempotencyKey
1967
- });
1968
- },
1969
- async advancePhase(input, idempotencyKey = randomIdempotencyKey()) {
1970
- return gateway.request({
1971
- path: "/api/platform/v1/worktrees/advance-phase",
1972
- method: "POST",
1973
- body: input,
1974
- idempotencyKey
1975
- });
1976
- },
1977
- async setPhase(input, idempotencyKey = randomIdempotencyKey()) {
1978
- return gateway.request({
1979
- path: "/api/platform/v1/worktrees/set-phase",
1980
- method: "POST",
1981
- body: input,
1982
- idempotencyKey
1983
- });
1984
- },
1985
- async patchState(input, idempotencyKey = randomIdempotencyKey()) {
1986
- return gateway.request({
1987
- path: "/api/platform/v1/worktrees/patch-state",
1988
- method: "POST",
1989
- body: input,
1990
- idempotencyKey
1991
- });
1992
- },
1993
- async bulkCreate(input, idempotencyKey = randomIdempotencyKey()) {
1994
- return gateway.request({
1995
- path: "/api/platform/v1/worktrees/bulk",
1996
- method: "POST",
1997
- body: input,
1998
- idempotencyKey
1999
- });
2000
- }
2001
- };
2002
- }
2003
-
2004
- export { createBeliefsFacade, createContradictionsFacade, createEdgesFacade, createEventsFacade, createEvidenceFacade, createGraphFacade, createIdentityFacade, createOntologiesFacade, createQuestionsFacade, createSearchFacade, createTasksFacade, createTopicsFacade, createWebhooksFacade, createWorktreesFacade };
2005
- //# sourceMappingURL=gatewayFacades.js.map
2006
- //# sourceMappingURL=gatewayFacades.js.map