@lucern/sdk 0.2.0-alpha.13 → 0.2.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (317) hide show
  1. package/README.md +166 -609
  2. package/dist/index.js +3539 -6269
  3. package/dist/index.js.map +1 -1
  4. package/dist/{contracts → lucern/contracts/src}/auth-session.contract.d.ts +12 -14
  5. package/dist/{contracts → lucern/contracts/src}/context-pack.contract.d.ts +58 -56
  6. package/dist/{contracts → lucern/contracts/src}/lens-filter.contract.d.ts +8 -10
  7. package/dist/lucern/contracts/src/lens-workflow.contract.d.ts +84 -0
  8. package/dist/lucern/contracts/src/mcp-tools.contract.d.ts +151 -0
  9. package/dist/lucern/contracts/src/workflow-runtime.contract.d.ts +161 -0
  10. package/dist/lucern/mcp-server/src/context-pack-policy.d.ts +119 -0
  11. package/dist/lucern/mcp-server/src/context-pack-schema.d.ts +18 -0
  12. package/dist/lucern/modules/graph-primitives/src/ontology-matching.d.ts +78 -0
  13. package/dist/lucern/modules/graph-primitives/src/text-matching.d.ts +53 -0
  14. package/dist/lucern/packages/client-core/src/beliefs.d.ts +30 -0
  15. package/dist/lucern/packages/client-core/src/context.d.ts +29 -0
  16. package/dist/lucern/packages/client-core/src/contradictions.d.ts +11 -0
  17. package/dist/lucern/packages/client-core/src/edges.d.ts +11 -0
  18. package/dist/lucern/packages/client-core/src/events.d.ts +9 -0
  19. package/dist/lucern/packages/client-core/src/evidence.d.ts +21 -0
  20. package/dist/lucern/packages/client-core/src/graph.d.ts +17 -0
  21. package/dist/lucern/packages/client-core/src/identity.d.ts +7 -0
  22. package/dist/lucern/packages/client-core/src/ids.d.ts +7 -0
  23. package/dist/lucern/packages/client-core/src/ontologies.d.ts +13 -0
  24. package/dist/lucern/packages/client-core/src/questions.d.ts +39 -0
  25. package/dist/lucern/packages/client-core/src/search.d.ts +7 -0
  26. package/dist/lucern/packages/client-core/src/tasks.d.ts +13 -0
  27. package/dist/lucern/packages/client-core/src/topics.d.ts +17 -0
  28. package/dist/lucern/packages/client-core/src/webhooks.d.ts +35 -0
  29. package/dist/lucern/packages/client-core/src/worktrees.d.ts +17 -0
  30. package/dist/lucern/packages/domain-beliefs/src/beliefs.d.ts +283 -0
  31. package/dist/lucern/packages/domain-beliefs/src/index.d.ts +1 -0
  32. package/dist/lucern/packages/domain-context/src/compile.d.ts +11 -0
  33. package/dist/{contextPackCompiler.d.ts → lucern/packages/domain-context/src/context-pack-compiler.d.ts} +10 -11
  34. package/dist/lucern/packages/domain-context/src/index.d.ts +4 -0
  35. package/dist/lucern/packages/domain-context/src/ports.d.ts +58 -0
  36. package/dist/lucern/packages/domain-context/src/public-types.d.ts +1 -0
  37. package/dist/lucern/packages/domain-edges/src/contradictions.d.ts +59 -0
  38. package/dist/lucern/packages/domain-edges/src/edges.d.ts +91 -0
  39. package/dist/lucern/packages/domain-edges/src/index.d.ts +2 -0
  40. package/dist/lucern/packages/domain-evidence/src/evidence.d.ts +115 -0
  41. package/dist/lucern/packages/domain-evidence/src/index.d.ts +1 -0
  42. package/dist/lucern/packages/domain-graph/src/graph.d.ts +150 -0
  43. package/dist/lucern/packages/domain-identity/src/index.d.ts +1 -0
  44. package/dist/lucern/packages/domain-identity/src/whoami.d.ts +13 -0
  45. package/dist/lucern/packages/domain-ontologies/src/ontologies.d.ts +123 -0
  46. package/dist/lucern/packages/domain-questions/src/index.d.ts +1 -0
  47. package/dist/lucern/packages/domain-questions/src/questions.d.ts +147 -0
  48. package/dist/lucern/packages/domain-search/src/search.d.ts +97 -0
  49. package/dist/lucern/packages/domain-tasks/src/index.d.ts +1 -0
  50. package/dist/lucern/packages/domain-tasks/src/tasks.d.ts +102 -0
  51. package/dist/lucern/packages/domain-topics/src/index.d.ts +1 -0
  52. package/dist/lucern/packages/domain-topics/src/topics.d.ts +147 -0
  53. package/dist/lucern/packages/domain-worktrees/src/index.d.ts +1 -0
  54. package/dist/lucern/packages/domain-worktrees/src/worktrees.d.ts +185 -0
  55. package/dist/lucern/packages/events/src/index.d.ts +4 -0
  56. package/dist/lucern/packages/events/src/matching.d.ts +3 -0
  57. package/dist/lucern/packages/events/src/outbox.d.ts +15 -0
  58. package/dist/lucern/packages/events/src/types.d.ts +151 -0
  59. package/dist/lucern/packages/events/src/webhooks.d.ts +9 -0
  60. package/dist/lucern/packages/sdk-typescript/src/facade/beliefs.d.ts +15 -0
  61. package/dist/lucern/packages/sdk-typescript/src/facade/context.d.ts +12 -0
  62. package/dist/lucern/packages/sdk-typescript/src/facade/contradictions.d.ts +7 -0
  63. package/dist/lucern/packages/sdk-typescript/src/facade/edges.d.ts +7 -0
  64. package/dist/lucern/packages/sdk-typescript/src/facade/events.d.ts +6 -0
  65. package/dist/lucern/packages/sdk-typescript/src/facade/evidence.d.ts +21 -0
  66. package/dist/lucern/packages/sdk-typescript/src/facade/graph.d.ts +10 -0
  67. package/dist/lucern/packages/sdk-typescript/src/facade/identity.d.ts +5 -0
  68. package/dist/lucern/packages/sdk-typescript/src/facade/ontologies.d.ts +8 -0
  69. package/dist/lucern/packages/sdk-typescript/src/facade/questions.d.ts +39 -0
  70. package/dist/lucern/packages/sdk-typescript/src/facade/search.d.ts +5 -0
  71. package/dist/lucern/packages/sdk-typescript/src/facade/tasks.d.ts +8 -0
  72. package/dist/lucern/packages/sdk-typescript/src/facade/topics.d.ts +10 -0
  73. package/dist/lucern/packages/sdk-typescript/src/facade/webhooks.d.ts +16 -0
  74. package/dist/lucern/packages/sdk-typescript/src/facade/worktrees.d.ts +10 -0
  75. package/dist/lucern/packages/sdk-typescript/src/index.d.ts +28 -0
  76. package/dist/packages/sdk/src/adminClient.d.ts +89 -0
  77. package/dist/packages/sdk/src/answersClient.d.ts +5 -0
  78. package/dist/{audiencesClient.d.ts → packages/sdk/src/audiencesClient.d.ts} +18 -30
  79. package/dist/packages/sdk/src/auditClient.d.ts +21 -0
  80. package/dist/packages/sdk/src/beliefsClient.d.ts +52 -0
  81. package/dist/packages/sdk/src/client.d.ts +1558 -0
  82. package/dist/packages/sdk/src/contextClient.d.ts +9 -0
  83. package/dist/packages/sdk/src/contracts/api-enums.contract.d.ts +58 -0
  84. package/dist/{controlObjectOwnership.d.ts → packages/sdk/src/controlObjectOwnership.d.ts} +18 -35
  85. package/dist/{coreClient.d.ts → packages/sdk/src/coreClient.d.ts} +14 -38
  86. package/dist/packages/sdk/src/customTools.d.ts +65 -0
  87. package/dist/packages/sdk/src/decisionsClient.d.ts +97 -0
  88. package/dist/packages/sdk/src/graphClient.d.ts +191 -0
  89. package/dist/{harnessClient.d.ts → packages/sdk/src/harnessClient.d.ts} +33 -127
  90. package/dist/packages/sdk/src/identityClient.d.ts +104 -0
  91. package/dist/packages/sdk/src/index.d.ts +28 -0
  92. package/dist/packages/sdk/src/learningClient.d.ts +37 -0
  93. package/dist/{mcpParityClient.d.ts → packages/sdk/src/mcpParityClient.d.ts} +5 -11
  94. package/dist/packages/sdk/src/mcpParitySurface.d.ts +8 -0
  95. package/dist/{ontologyClient.d.ts → packages/sdk/src/ontologyClient.d.ts} +22 -44
  96. package/dist/packages/sdk/src/packsClient.d.ts +101 -0
  97. package/dist/{policyClient.d.ts → packages/sdk/src/policyClient.d.ts} +18 -113
  98. package/dist/packages/sdk/src/reportsClient.d.ts +31 -0
  99. package/dist/packages/sdk/src/schemaClient.d.ts +54 -0
  100. package/dist/packages/sdk/src/sdkSurface.d.ts +55 -0
  101. package/dist/packages/sdk/src/topicsClient.d.ts +45 -0
  102. package/dist/packages/sdk/src/types.d.ts +470 -0
  103. package/dist/packages/sdk/src/version.d.ts +2 -0
  104. package/dist/packages/sdk/src/workflowClient.d.ts +252 -0
  105. package/package.json +37 -92
  106. package/CHANGELOG.md +0 -13
  107. package/dist/adminClient.d.ts +0 -409
  108. package/dist/adminClient.js +0 -755
  109. package/dist/adminClient.js.map +0 -1
  110. package/dist/answersClient.d.ts +0 -23
  111. package/dist/answersClient.js +0 -333
  112. package/dist/answersClient.js.map +0 -1
  113. package/dist/audience/index.d.ts +0 -38
  114. package/dist/audience/index.js +0 -110
  115. package/dist/audience/index.js.map +0 -1
  116. package/dist/audiencesClient.js +0 -472
  117. package/dist/audiencesClient.js.map +0 -1
  118. package/dist/auditClient.d.ts +0 -29
  119. package/dist/auditClient.js +0 -386
  120. package/dist/auditClient.js.map +0 -1
  121. package/dist/beliefs/index.d.ts +0 -465
  122. package/dist/beliefs/index.js +0 -6433
  123. package/dist/beliefs/index.js.map +0 -1
  124. package/dist/beliefs/lifecycle.d.ts +0 -24
  125. package/dist/beliefs/lifecycle.js +0 -98
  126. package/dist/beliefs/lifecycle.js.map +0 -1
  127. package/dist/beliefsClient.d.ts +0 -241
  128. package/dist/beliefsClient.js +0 -646
  129. package/dist/beliefsClient.js.map +0 -1
  130. package/dist/client.d.ts +0 -2398
  131. package/dist/client.js +0 -6411
  132. package/dist/client.js.map +0 -1
  133. package/dist/contextClient.d.ts +0 -27
  134. package/dist/contextClient.js +0 -396
  135. package/dist/contextClient.js.map +0 -1
  136. package/dist/contextFacade.d.ts +0 -2
  137. package/dist/contextFacade.js +0 -73
  138. package/dist/contextFacade.js.map +0 -1
  139. package/dist/contextPackCompiler.js +0 -1091
  140. package/dist/contextPackCompiler.js.map +0 -1
  141. package/dist/contextPackPolicy.d.ts +0 -84
  142. package/dist/contextPackPolicy.js +0 -347
  143. package/dist/contextPackPolicy.js.map +0 -1
  144. package/dist/contextPackSchema.d.ts +0 -7
  145. package/dist/contextPackSchema.js +0 -203
  146. package/dist/contextPackSchema.js.map +0 -1
  147. package/dist/contextTypes.d.ts +0 -135
  148. package/dist/contextTypes.js +0 -3
  149. package/dist/contextTypes.js.map +0 -1
  150. package/dist/contracts/api-enums.contract.d.ts +0 -81
  151. package/dist/contracts/api-enums.contract.js +0 -98
  152. package/dist/contracts/api-enums.contract.js.map +0 -1
  153. package/dist/contracts/auth-session.contract.js +0 -48
  154. package/dist/contracts/auth-session.contract.js.map +0 -1
  155. package/dist/contracts/context-pack.contract.js +0 -98
  156. package/dist/contracts/context-pack.contract.js.map +0 -1
  157. package/dist/contracts/contextPack.d.ts +0 -1
  158. package/dist/contracts/contextPack.js +0 -98
  159. package/dist/contracts/contextPack.js.map +0 -1
  160. package/dist/contracts/index.d.ts +0 -9
  161. package/dist/contracts/index.js +0 -4928
  162. package/dist/contracts/index.js.map +0 -1
  163. package/dist/contracts/lens-filter.contract.js +0 -71
  164. package/dist/contracts/lens-filter.contract.js.map +0 -1
  165. package/dist/contracts/lens-workflow.contract.d.ts +0 -87
  166. package/dist/contracts/lens-workflow.contract.js +0 -123
  167. package/dist/contracts/lens-workflow.contract.js.map +0 -1
  168. package/dist/contracts/lensFilter.d.ts +0 -1
  169. package/dist/contracts/lensFilter.js +0 -71
  170. package/dist/contracts/lensFilter.js.map +0 -1
  171. package/dist/contracts/lensWorkflow.d.ts +0 -2
  172. package/dist/contracts/lensWorkflow.js +0 -123
  173. package/dist/contracts/lensWorkflow.js.map +0 -1
  174. package/dist/contracts/mcp-tools.contract.d.ts +0 -1
  175. package/dist/contracts/mcp-tools.contract.js +0 -3016
  176. package/dist/contracts/mcp-tools.contract.js.map +0 -1
  177. package/dist/contracts/mcpTools.d.ts +0 -1
  178. package/dist/contracts/mcpTools.js +0 -3016
  179. package/dist/contracts/mcpTools.js.map +0 -1
  180. package/dist/contracts/prompt.contract.d.ts +0 -26
  181. package/dist/contracts/prompt.contract.js +0 -12
  182. package/dist/contracts/prompt.contract.js.map +0 -1
  183. package/dist/contracts/prompt.d.ts +0 -1
  184. package/dist/contracts/prompt.js +0 -12
  185. package/dist/contracts/prompt.js.map +0 -1
  186. package/dist/contracts/sdk-tools.contract.d.ts +0 -2
  187. package/dist/contracts/sdk-tools.contract.js +0 -4164
  188. package/dist/contracts/sdk-tools.contract.js.map +0 -1
  189. package/dist/contracts/sdkTools.d.ts +0 -2
  190. package/dist/contracts/sdkTools.js +0 -4164
  191. package/dist/contracts/sdkTools.js.map +0 -1
  192. package/dist/contracts/workflow-runtime.contract.d.ts +0 -163
  193. package/dist/contracts/workflow-runtime.contract.js +0 -245
  194. package/dist/contracts/workflow-runtime.contract.js.map +0 -1
  195. package/dist/contracts/workflowRuntime.d.ts +0 -1
  196. package/dist/contracts/workflowRuntime.js +0 -245
  197. package/dist/contracts/workflowRuntime.js.map +0 -1
  198. package/dist/contradictions/index.d.ts +0 -158
  199. package/dist/contradictions/index.js +0 -6427
  200. package/dist/contradictions/index.js.map +0 -1
  201. package/dist/controlObjectOwnership.js +0 -215
  202. package/dist/controlObjectOwnership.js.map +0 -1
  203. package/dist/coreClient.js +0 -339
  204. package/dist/coreClient.js.map +0 -1
  205. package/dist/customTools.d.ts +0 -88
  206. package/dist/customTools.js +0 -248
  207. package/dist/customTools.js.map +0 -1
  208. package/dist/decisions/index.d.ts +0 -68
  209. package/dist/decisions/index.js +0 -6429
  210. package/dist/decisions/index.js.map +0 -1
  211. package/dist/decisionsClient.d.ts +0 -111
  212. package/dist/decisionsClient.js +0 -522
  213. package/dist/decisionsClient.js.map +0 -1
  214. package/dist/domainContext.d.ts +0 -1
  215. package/dist/domainContext.js +0 -3
  216. package/dist/domainContext.js.map +0 -1
  217. package/dist/edges/index.d.ts +0 -204
  218. package/dist/edges/index.js +0 -6428
  219. package/dist/edges/index.js.map +0 -1
  220. package/dist/events.d.ts +0 -178
  221. package/dist/events.js +0 -251
  222. package/dist/events.js.map +0 -1
  223. package/dist/eventsCore.d.ts +0 -49
  224. package/dist/eventsCore.js +0 -429
  225. package/dist/eventsCore.js.map +0 -1
  226. package/dist/evidence/index.d.ts +0 -295
  227. package/dist/evidence/index.js +0 -6428
  228. package/dist/evidence/index.js.map +0 -1
  229. package/dist/evidenceClient.d.ts +0 -119
  230. package/dist/evidenceClient.js +0 -350
  231. package/dist/evidenceClient.js.map +0 -1
  232. package/dist/facade/context.d.ts +0 -18
  233. package/dist/facade/context.js +0 -73
  234. package/dist/facade/context.js.map +0 -1
  235. package/dist/gatewayFacades.d.ts +0 -589
  236. package/dist/gatewayFacades.js +0 -2006
  237. package/dist/gatewayFacades.js.map +0 -1
  238. package/dist/graphClient.d.ts +0 -271
  239. package/dist/graphClient.js +0 -698
  240. package/dist/graphClient.js.map +0 -1
  241. package/dist/harnessClient.js +0 -607
  242. package/dist/harnessClient.js.map +0 -1
  243. package/dist/identityClient.d.ts +0 -140
  244. package/dist/identityClient.js +0 -497
  245. package/dist/identityClient.js.map +0 -1
  246. package/dist/index.d.ts +0 -45
  247. package/dist/learningClient.d.ts +0 -46
  248. package/dist/learningClient.js +0 -409
  249. package/dist/learningClient.js.map +0 -1
  250. package/dist/lenses/index.d.ts +0 -194
  251. package/dist/lenses/index.js +0 -6427
  252. package/dist/lenses/index.js.map +0 -1
  253. package/dist/mcpParityClient.js +0 -516
  254. package/dist/mcpParityClient.js.map +0 -1
  255. package/dist/mcpParitySurface.d.ts +0 -12
  256. package/dist/mcpParitySurface.js +0 -65
  257. package/dist/mcpParitySurface.js.map +0 -1
  258. package/dist/mcpTools-DPZxowDX.d.ts +0 -254
  259. package/dist/nodes/index.d.ts +0 -62
  260. package/dist/nodes/index.js +0 -6429
  261. package/dist/nodes/index.js.map +0 -1
  262. package/dist/ontologies/index.d.ts +0 -178
  263. package/dist/ontologies/index.js +0 -6430
  264. package/dist/ontologies/index.js.map +0 -1
  265. package/dist/ontologyClient.js +0 -513
  266. package/dist/ontologyClient.js.map +0 -1
  267. package/dist/opinion.d.ts +0 -11
  268. package/dist/opinion.js +0 -35
  269. package/dist/opinion.js.map +0 -1
  270. package/dist/packRuntime.d.ts +0 -2
  271. package/dist/packRuntime.js +0 -3
  272. package/dist/packRuntime.js.map +0 -1
  273. package/dist/packsClient.d.ts +0 -131
  274. package/dist/packsClient.js +0 -525
  275. package/dist/packsClient.js.map +0 -1
  276. package/dist/policyClient.js +0 -625
  277. package/dist/policyClient.js.map +0 -1
  278. package/dist/questions/index.d.ts +0 -297
  279. package/dist/questions/index.js +0 -6430
  280. package/dist/questions/index.js.map +0 -1
  281. package/dist/realtime/index.d.ts +0 -29
  282. package/dist/realtime/index.js +0 -23
  283. package/dist/realtime/index.js.map +0 -1
  284. package/dist/realtime/refs.d.ts +0 -17
  285. package/dist/realtime/refs.js +0 -9
  286. package/dist/realtime/refs.js.map +0 -1
  287. package/dist/reportsClient.d.ts +0 -41
  288. package/dist/reportsClient.js +0 -418
  289. package/dist/reportsClient.js.map +0 -1
  290. package/dist/schemaClient.d.ts +0 -64
  291. package/dist/schemaClient.js +0 -434
  292. package/dist/schemaClient.js.map +0 -1
  293. package/dist/sdkSurface.d.ts +0 -61
  294. package/dist/sdkSurface.js +0 -112
  295. package/dist/sdkSurface.js.map +0 -1
  296. package/dist/sdkTools-CwXJDACb.d.ts +0 -150
  297. package/dist/sourcesClient.d.ts +0 -24
  298. package/dist/sourcesClient.js +0 -339
  299. package/dist/sourcesClient.js.map +0 -1
  300. package/dist/topics/index.d.ts +0 -68
  301. package/dist/topics/index.js +0 -6428
  302. package/dist/topics/index.js.map +0 -1
  303. package/dist/topicsClient.d.ts +0 -84
  304. package/dist/topicsClient.js +0 -492
  305. package/dist/topicsClient.js.map +0 -1
  306. package/dist/types.d.ts +0 -715
  307. package/dist/types.js +0 -3
  308. package/dist/types.js.map +0 -1
  309. package/dist/version.d.ts +0 -4
  310. package/dist/version.js +0 -6
  311. package/dist/version.js.map +0 -1
  312. package/dist/workflowClient.d.ts +0 -316
  313. package/dist/workflowClient.js +0 -830
  314. package/dist/workflowClient.js.map +0 -1
  315. package/dist/worktrees/index.d.ts +0 -210
  316. package/dist/worktrees/index.js +0 -6430
  317. package/dist/worktrees/index.js.map +0 -1
@@ -1,646 +0,0 @@
1
- // src/coreClient.ts
2
- var LucernApiError = class extends Error {
3
- code;
4
- status;
5
- invariant;
6
- suggestion;
7
- details;
8
- requestId;
9
- correlationId;
10
- policyTraceId;
11
- constructor(args) {
12
- super(args.message);
13
- this.name = "LucernApiError";
14
- this.code = args.code;
15
- this.status = args.status;
16
- this.invariant = args.invariant;
17
- this.suggestion = args.suggestion;
18
- this.details = args.details;
19
- this.requestId = args.requestId;
20
- this.correlationId = args.correlationId;
21
- this.policyTraceId = args.policyTraceId;
22
- }
23
- };
24
- function fillRandomBytes(length) {
25
- const bytes = new Uint8Array(length);
26
- if (typeof globalThis.crypto?.getRandomValues === "function") {
27
- globalThis.crypto.getRandomValues(bytes);
28
- return bytes;
29
- }
30
- for (let index = 0; index < length; index += 1) {
31
- bytes[index] = Math.floor(Math.random() * 256);
32
- }
33
- return bytes;
34
- }
35
- function generatePortableRequestId() {
36
- if (typeof globalThis.crypto?.randomUUID === "function") {
37
- return globalThis.crypto.randomUUID();
38
- }
39
- const bytes = fillRandomBytes(16);
40
- bytes[6] = bytes[6] & 15 | 64;
41
- bytes[8] = bytes[8] & 63 | 128;
42
- const hex = Array.from(bytes, (value) => value.toString(16).padStart(2, "0"));
43
- return `${hex.slice(0, 4).join("")}-${hex.slice(4, 6).join("")}-${hex.slice(
44
- 6,
45
- 8
46
- ).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10).join("")}`;
47
- }
48
- function randomIdempotencyKey() {
49
- return generatePortableRequestId();
50
- }
51
- function isRetryableStatus(status) {
52
- return status >= 500 || status === 408 || status === 429;
53
- }
54
- function fallbackErrorCode(status) {
55
- if (status === 401) {
56
- return "AUTHENTICATION_REQUIRED";
57
- }
58
- if (status === 403) {
59
- return "FORBIDDEN";
60
- }
61
- if (status === 404) {
62
- return "NOT_FOUND";
63
- }
64
- if (status === 408) {
65
- return "UPSTREAM_ERROR";
66
- }
67
- if (status === 409) {
68
- return "CONFLICT";
69
- }
70
- if (status === 429) {
71
- return "RATE_LIMIT_EXCEEDED";
72
- }
73
- if (status >= 500) {
74
- return "UPSTREAM_ERROR";
75
- }
76
- return "INTERNAL_ERROR";
77
- }
78
- function delay(ms) {
79
- return new Promise((resolve) => setTimeout(resolve, ms));
80
- }
81
- function parseRetryAfterMs(value) {
82
- if (!value) {
83
- return null;
84
- }
85
- const trimmed = value.trim();
86
- if (!trimmed) {
87
- return null;
88
- }
89
- const numeric = Number(trimmed);
90
- if (Number.isFinite(numeric)) {
91
- return Math.max(0, Math.round(numeric * 1e3));
92
- }
93
- const parsedDate = Date.parse(trimmed);
94
- if (Number.isFinite(parsedDate)) {
95
- return Math.max(0, parsedDate - Date.now());
96
- }
97
- return null;
98
- }
99
- function computeRetryDelayMs(args) {
100
- const baseDelay = args.status === 429 ? Math.max(
101
- args.retryAfterMs ?? 0,
102
- Math.min(1e3 * 2 ** args.attempt, 1e4)
103
- ) : Math.min(1e3 * 2 ** args.attempt, 4e3);
104
- if (args.status !== 429) {
105
- return baseDelay;
106
- }
107
- const jitterWindow = Math.max(250, Math.round(baseDelay * 0.25));
108
- return baseDelay + Math.round(Math.random() * jitterWindow);
109
- }
110
- function timeoutError(timeoutMs) {
111
- const error = new Error(`Request timed out after ${timeoutMs}ms`);
112
- error.name = "AbortError";
113
- return error;
114
- }
115
- function readPolicySummaryFromDetails(details) {
116
- if (!details || typeof details !== "object" || Array.isArray(details)) {
117
- return null;
118
- }
119
- const directSummary = details.summary;
120
- if (typeof directSummary === "string" && directSummary.trim().length > 0) {
121
- return directSummary.trim();
122
- }
123
- const policy = details.policy;
124
- if (!policy || typeof policy !== "object" || Array.isArray(policy)) {
125
- return null;
126
- }
127
- const explanation = policy.explanation;
128
- if (!explanation || typeof explanation !== "object" || Array.isArray(explanation)) {
129
- return null;
130
- }
131
- const nestedSummary = explanation.summary;
132
- if (typeof nestedSummary === "string" && nestedSummary.trim().length > 0) {
133
- return nestedSummary.trim();
134
- }
135
- return null;
136
- }
137
- function createGatewayRequestClient(config = {}) {
138
- const fetchImpl = config.fetchImpl ?? fetch;
139
- const baseUrl = config.baseUrl?.replace(/\/+$/, "") ?? "";
140
- const maxRetries = config.maxRetries ?? 2;
141
- const requestIdFactory = config.requestIdFactory ?? (() => generatePortableRequestId());
142
- async function resolveAuthHeaders() {
143
- if (!config.getAuthHeaders) {
144
- return {};
145
- }
146
- return await config.getAuthHeaders();
147
- }
148
- async function fetchWithTimeout(url, init, timeoutMs) {
149
- const controller = new AbortController();
150
- const timer = setTimeout(() => controller.abort(), timeoutMs);
151
- try {
152
- return await fetchImpl(url, { ...init, signal: controller.signal });
153
- } catch (error) {
154
- if (controller.signal.aborted) {
155
- throw timeoutError(timeoutMs);
156
- }
157
- throw error;
158
- } finally {
159
- clearTimeout(timer);
160
- }
161
- }
162
- async function parsePayload(response) {
163
- const text = await response.text();
164
- if (!text) {
165
- return null;
166
- }
167
- try {
168
- return JSON.parse(text);
169
- } catch {
170
- return null;
171
- }
172
- }
173
- function resolveTimeoutMs(method, requestTimeoutMs) {
174
- if (typeof requestTimeoutMs === "number") {
175
- return requestTimeoutMs;
176
- }
177
- const methodTimeoutMs = config.timeoutMsByMethod?.[method];
178
- if (typeof methodTimeoutMs === "number") {
179
- return methodTimeoutMs;
180
- }
181
- return config.timeoutMs ?? 15e3;
182
- }
183
- function buildApiError(args) {
184
- const failure = args.failure;
185
- const legacyError = failure && typeof failure.error === "object" && failure.error !== null ? failure.error : failure?.legacyError;
186
- const correlationId = failure?.correlationId ?? args.response.headers.get("x-lucern-correlation-id")?.trim() ?? args.requestId;
187
- const policyTraceId = failure?.policyTraceId ?? args.response.headers.get("x-lucern-policy-trace-id")?.trim() ?? null;
188
- const details = failure?.details ?? legacyError?.details;
189
- const policySummary = readPolicySummaryFromDetails(details);
190
- return new LucernApiError({
191
- code: failure?.code ?? legacyError?.code ?? fallbackErrorCode(args.response.status),
192
- message: policySummary ?? (typeof failure?.error === "string" ? failure.error : legacyError?.message ?? (args.response.ok ? "Platform API returned an invalid success payload." : "Platform API request failed.")),
193
- status: args.response.status,
194
- invariant: failure?.invariant,
195
- suggestion: failure?.suggestion,
196
- details,
197
- requestId: args.requestId,
198
- correlationId,
199
- policyTraceId
200
- });
201
- }
202
- async function request(args) {
203
- const authHeaders = await resolveAuthHeaders();
204
- const method = args.method ?? "GET";
205
- const timeoutMs = resolveTimeoutMs(method, args.timeoutMs);
206
- const headers = new Headers({
207
- "content-type": "application/json",
208
- ...authHeaders
209
- });
210
- if (args.idempotencyKey) {
211
- headers.set("idempotency-key", args.idempotencyKey);
212
- }
213
- const requestId = headers.get("x-correlation-id")?.trim() || headers.get("x-request-id")?.trim() || args.requestId || requestIdFactory();
214
- if (!headers.has("x-correlation-id") && !headers.has("x-request-id")) {
215
- headers.set("x-correlation-id", requestId);
216
- }
217
- const url = `${baseUrl}${args.path}`;
218
- const serializedBody = args.body ? JSON.stringify(args.body) : void 0;
219
- const init = {
220
- method,
221
- headers,
222
- body: serializedBody
223
- };
224
- let lastError;
225
- for (let attempt = 0; attempt <= maxRetries; attempt++) {
226
- const hookRequestContext = {
227
- requestId,
228
- attempt,
229
- maxRetries,
230
- method,
231
- path: args.path,
232
- url,
233
- headers: new Headers(headers),
234
- body: serializedBody,
235
- timeoutMs
236
- };
237
- await config.onRequest?.(hookRequestContext);
238
- const startedAt = Date.now();
239
- try {
240
- const response = await fetchWithTimeout(url, init, timeoutMs);
241
- const responseClone = response.clone();
242
- const payload = await parsePayload(response);
243
- const retryAfterMs = parseRetryAfterMs(
244
- response.headers.get("Retry-After")
245
- );
246
- if (!response.ok || !payload?.success) {
247
- const failure = payload && !payload.success ? payload : null;
248
- const apiError = buildApiError({
249
- requestId,
250
- response,
251
- failure
252
- });
253
- const willRetry = attempt < maxRetries && isRetryableStatus(response.status);
254
- await config.onResponse?.({
255
- ...hookRequestContext,
256
- durationMs: Date.now() - startedAt,
257
- status: response.status,
258
- response: responseClone,
259
- error: apiError,
260
- correlationId: apiError.correlationId ?? requestId,
261
- policyTraceId: apiError.policyTraceId ?? null,
262
- retryAfterMs,
263
- willRetry
264
- });
265
- if (willRetry) {
266
- lastError = apiError;
267
- await delay(
268
- computeRetryDelayMs({
269
- attempt,
270
- status: response.status,
271
- retryAfterMs
272
- })
273
- );
274
- continue;
275
- }
276
- throw apiError;
277
- }
278
- const successPayload = payload;
279
- await config.onResponse?.({
280
- ...hookRequestContext,
281
- durationMs: Date.now() - startedAt,
282
- status: response.status,
283
- response: responseClone,
284
- correlationId: successPayload.correlationId ?? response.headers.get("x-lucern-correlation-id")?.trim() ?? requestId,
285
- policyTraceId: successPayload.policyTraceId ?? response.headers.get("x-lucern-policy-trace-id")?.trim() ?? null,
286
- idempotentReplay: successPayload.idempotentReplay,
287
- retryAfterMs,
288
- willRetry: false
289
- });
290
- return successPayload;
291
- } catch (fetchError) {
292
- if (fetchError instanceof LucernApiError) {
293
- throw fetchError;
294
- }
295
- const willRetry = attempt < maxRetries;
296
- await config.onResponse?.({
297
- ...hookRequestContext,
298
- durationMs: Date.now() - startedAt,
299
- error: fetchError,
300
- correlationId: requestId,
301
- policyTraceId: null,
302
- willRetry
303
- });
304
- lastError = fetchError;
305
- if (willRetry) {
306
- await delay(computeRetryDelayMs({ attempt }));
307
- }
308
- }
309
- }
310
- throw lastError instanceof Error ? lastError : new Error("Platform API request failed after retries.");
311
- }
312
- return {
313
- request
314
- };
315
- }
316
-
317
- // src/opinion.ts
318
- function clamp01(value) {
319
- if (!Number.isFinite(value)) {
320
- return 0;
321
- }
322
- return Math.max(0, Math.min(1, value));
323
- }
324
- function vacuous(baseRate = 0.5) {
325
- return { b: 0, d: 0, u: 1, a: clamp01(baseRate) };
326
- }
327
- function dogmatic(probability, baseRate = 0.5) {
328
- const p = clamp01(probability);
329
- return { b: p, d: 1 - p, u: 0, a: clamp01(baseRate) };
330
- }
331
- function opinionFromBaseRate(probability) {
332
- return vacuous(clamp01(probability));
333
- }
334
- function opinionFromDogmatic(probability, baseRate = 0.5) {
335
- return dogmatic(clamp01(probability), clamp01(baseRate));
336
- }
337
- function opinionFromProjected(probability, uncertainty, baseRate = 0.5) {
338
- const p = clamp01(probability);
339
- const u = clamp01(uncertainty);
340
- const remainingMass = 1 - u;
341
- return {
342
- b: p * remainingMass,
343
- d: (1 - p) * remainingMass,
344
- u,
345
- a: clamp01(baseRate)
346
- };
347
- }
348
-
349
- // src/sdkSurface.ts
350
- function cleanString(value) {
351
- return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
352
- }
353
- function normalizeVerificationStatus(value) {
354
- const status = cleanString(value);
355
- if (!status) {
356
- return void 0;
357
- }
358
- if (status === "verified") {
359
- return "human_verified";
360
- }
361
- if (status === "rejected") {
362
- return "contradicted";
363
- }
364
- return status;
365
- }
366
- function resolveTopicId(value) {
367
- return cleanString(value.topicId);
368
- }
369
- function resolveText(value) {
370
- return cleanString(value.text) ?? cleanString(value.canonicalText);
371
- }
372
- function normalizeNodeWriteInput(value) {
373
- const topicId = resolveTopicId(value);
374
- const text = resolveText(value);
375
- const verificationStatus = normalizeVerificationStatus(value.verificationStatus);
376
- const next = { ...value };
377
- if (topicId) {
378
- next.topicId = topicId;
379
- }
380
- if (text) {
381
- next.text = text;
382
- next.canonicalText = text;
383
- }
384
- if (verificationStatus) {
385
- next.verificationStatus = verificationStatus;
386
- }
387
- return next;
388
- }
389
-
390
- // src/beliefsClient.ts
391
- function asRecord(value) {
392
- return value && typeof value === "object" && !Array.isArray(value) ? value : {};
393
- }
394
- function readString(value) {
395
- if (typeof value !== "string") {
396
- return void 0;
397
- }
398
- const normalized = value.trim();
399
- return normalized.length > 0 ? normalized : void 0;
400
- }
401
- function readNumber(value) {
402
- return typeof value === "number" && Number.isFinite(value) ? value : void 0;
403
- }
404
- function clamp012(value) {
405
- return Math.max(0, Math.min(1, value));
406
- }
407
- function normalizeOpinionTuple(record) {
408
- const opinion = asRecord(record.opinion);
409
- const rawBelief = readNumber(opinion.b) ?? readNumber(record.belief);
410
- const rawDisbelief = readNumber(opinion.d) ?? readNumber(record.disbelief);
411
- const rawUncertainty = readNumber(opinion.u) ?? readNumber(record.uncertainty);
412
- const rawBaseRate = readNumber(opinion.a) ?? readNumber(record.baseRate);
413
- if (rawBelief === void 0 && rawDisbelief === void 0 && rawUncertainty === void 0) {
414
- const projected = clamp012(readNumber(record.confidence) ?? 0);
415
- return {
416
- b: projected,
417
- d: 1 - projected,
418
- u: 0,
419
- a: 0.5
420
- };
421
- }
422
- return {
423
- b: clamp012(rawBelief ?? 0),
424
- d: clamp012(rawDisbelief ?? 0),
425
- u: clamp012(rawUncertainty ?? 0),
426
- a: clamp012(rawBaseRate ?? 0.5)
427
- };
428
- }
429
- function mapOpinionHistoryEntriesFromGatewayData(payload) {
430
- const entries = Array.isArray(payload.entries) ? payload.entries : [];
431
- return entries.map((value) => {
432
- const record = asRecord(value);
433
- const tuple = normalizeOpinionTuple(record);
434
- const projected = readNumber(record.confidence) ?? clamp012(tuple.b + tuple.a * tuple.u);
435
- const triggeringEvidenceId = readString(record.triggeringEvidenceId);
436
- const triggeringWorktreeId = readString(record.triggeringWorktreeId);
437
- return {
438
- t: readNumber(record.timestamp) ?? readNumber(record.assessedAt) ?? 0,
439
- b: tuple.b,
440
- d: tuple.d,
441
- u: tuple.u,
442
- a: tuple.a,
443
- P: clamp012(projected),
444
- trigger: readString(record.trigger) ?? "manual",
445
- ...triggeringEvidenceId ? {
446
- triggeringRef: {
447
- kind: "evidence",
448
- id: triggeringEvidenceId
449
- }
450
- } : triggeringWorktreeId ? {
451
- triggeringRef: {
452
- kind: "worktree",
453
- id: triggeringWorktreeId
454
- }
455
- } : {},
456
- ...readString(record.rationale) ? { rationale: readString(record.rationale) } : {},
457
- ...readString(record.userId) ? { userId: readString(record.userId) } : {},
458
- ...readString(record.slOperator) ? { slOperator: readString(record.slOperator) } : {}
459
- };
460
- }).sort((left, right) => left.t - right.t);
461
- }
462
- function normalizeModulateConfidenceInput(input) {
463
- const opinion = "opinion" in input ? input.opinion : input.interpretation === "base_rate" ? opinionFromBaseRate(input.confidence) : input.interpretation === "dogmatic" ? opinionFromDogmatic(input.confidence, input.baseRate) : opinionFromProjected(
464
- input.confidence,
465
- input.uncertainty,
466
- input.baseRate
467
- );
468
- return {
469
- belief: opinion.b,
470
- disbelief: opinion.d,
471
- uncertainty: opinion.u,
472
- baseRate: opinion.a,
473
- trigger: input.trigger,
474
- rationale: input.rationale,
475
- maxInlinePropagationTargets: input.maxInlinePropagationTargets
476
- };
477
- }
478
- function createBeliefsClient(config = {}) {
479
- const gateway = createGatewayRequestClient(config);
480
- function requireBaseRate(value) {
481
- const baseRate = readNumber(value);
482
- if (baseRate === void 0) {
483
- throw new Error("baseRate is required for belief creation.");
484
- }
485
- if (baseRate < 0 || baseRate > 1) {
486
- throw new Error("baseRate must be within [0, 1].");
487
- }
488
- return baseRate;
489
- }
490
- const modulateConfidence = async (beliefId, input, idempotencyKey) => gateway.request({
491
- path: `/api/platform/v1/beliefs/${encodeURIComponent(beliefId)}/confidence`,
492
- method: "POST",
493
- body: normalizeModulateConfidenceInput(input),
494
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
495
- });
496
- async function getOpinionHistory(beliefId) {
497
- const response = await gateway.request({
498
- path: `/api/platform/v1/beliefs/${encodeURIComponent(beliefId)}/confidence-history`
499
- });
500
- return mapOpinionHistoryEntriesFromGatewayData(response.data);
501
- }
502
- return {
503
- /**
504
- * Create a belief within a topic scope.
505
- */
506
- async createBelief(input, idempotencyKey) {
507
- const baseRate = requireBaseRate(input.baseRate);
508
- return gateway.request({
509
- path: "/api/platform/v1/beliefs",
510
- method: "POST",
511
- body: {
512
- ...normalizeNodeWriteInput(input),
513
- baseRate
514
- },
515
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
516
- });
517
- },
518
- /**
519
- * Refine a draft belief in place.
520
- */
521
- async refineBelief(beliefId, input, idempotencyKey) {
522
- return gateway.request({
523
- path: `/api/platform/v1/beliefs/${encodeURIComponent(beliefId)}`,
524
- method: "PATCH",
525
- body: normalizeNodeWriteInput(input),
526
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
527
- });
528
- },
529
- /**
530
- * Record a confidence change for an existing belief.
531
- */
532
- modulateConfidence,
533
- /**
534
- * Returns the belief's confidence trajectory as a chronological array.
535
- *
536
- * Canonical UI trend shape (what every trend component consumes):
537
- * { t: number, b: number, d: number, u: number, a: number, P: number, trigger: string, triggeringRef?: { kind: "evidence" | "worktree"; id: string } }[]
538
- *
539
- * Where:
540
- * t = assessedAt (epoch ms)
541
- * b, d, u, a = Opinion 4-tuple components
542
- * P = projected probability = b + a*u (precomputed for UI convenience)
543
- * trigger = cause of the score change
544
- * triggeringRef = optional pointer to the evidence or worktree that drove the change
545
- */
546
- async getOpinionHistory(beliefId) {
547
- return getOpinionHistory(beliefId);
548
- },
549
- /** @deprecated Use getOpinionHistory(). */
550
- async getConfidenceHistory(beliefId) {
551
- return getOpinionHistory(beliefId);
552
- },
553
- /**
554
- * Fork a scored belief into a new formulation.
555
- */
556
- async forkBelief(beliefId, input, idempotencyKey) {
557
- return gateway.request({
558
- path: `/api/platform/v1/beliefs/${encodeURIComponent(beliefId)}/fork`,
559
- method: "POST",
560
- body: input,
561
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
562
- });
563
- },
564
- /**
565
- * Update a belief's lifecycle status.
566
- */
567
- async updateBeliefStatus(input, idempotencyKey) {
568
- return gateway.request({
569
- path: "/api/platform/v1/beliefs/update-status",
570
- method: "POST",
571
- body: input,
572
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
573
- });
574
- },
575
- /**
576
- * Update a belief's rationale without changing its text.
577
- */
578
- async updateBeliefRationale(input, idempotencyKey) {
579
- return gateway.request({
580
- path: "/api/platform/v1/beliefs/update-rationale",
581
- method: "POST",
582
- body: input,
583
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
584
- });
585
- },
586
- /**
587
- * Create a typed relationship between two beliefs.
588
- */
589
- async linkBeliefs(input, idempotencyKey) {
590
- return gateway.request({
591
- path: "/api/platform/v1/beliefs/link",
592
- method: "POST",
593
- body: input,
594
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
595
- });
596
- },
597
- /**
598
- * Remove an evidence attachment from a belief.
599
- */
600
- async unlinkBeliefEvidence(input, idempotencyKey) {
601
- return gateway.request({
602
- path: "/api/platform/v1/beliefs/unlink-evidence",
603
- method: "POST",
604
- body: input,
605
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
606
- });
607
- },
608
- /**
609
- * Update a belief's criticality metadata.
610
- */
611
- async updateBeliefCriticality(input, idempotencyKey) {
612
- return gateway.request({
613
- path: "/api/platform/v1/beliefs/update-criticality",
614
- method: "POST",
615
- body: input,
616
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
617
- });
618
- },
619
- /**
620
- * Update multiple beliefs' criticality in one mutation.
621
- */
622
- async batchUpdateBeliefCriticality(input, idempotencyKey) {
623
- return gateway.request({
624
- path: "/api/platform/v1/beliefs/batch-update-criticality",
625
- method: "POST",
626
- body: input,
627
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
628
- });
629
- },
630
- /**
631
- * Reassign beliefs to a different topic scope.
632
- */
633
- async reassignBeliefsTopic(input, idempotencyKey) {
634
- return gateway.request({
635
- path: "/api/platform/v1/beliefs/reassign-topic",
636
- method: "POST",
637
- body: input,
638
- idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
639
- });
640
- }
641
- };
642
- }
643
-
644
- export { LucernApiError, createBeliefsClient, mapOpinionHistoryEntriesFromGatewayData };
645
- //# sourceMappingURL=beliefsClient.js.map
646
- //# sourceMappingURL=beliefsClient.js.map