@lucern/sdk 0.2.0-alpha.6 → 0.2.0-alpha.8

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