@lucern/sdk 0.2.0-alpha.1 → 0.2.0-alpha.10

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