@lucern/sdk 0.2.0-alpha.1 → 0.2.0-alpha.11
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.
- package/CHANGELOG.md +13 -0
- package/README.md +691 -61
- package/dist/adminClient.d.ts +409 -0
- package/dist/adminClient.js +755 -0
- package/dist/adminClient.js.map +1 -0
- package/dist/answersClient.d.ts +23 -0
- package/dist/answersClient.js +333 -0
- package/dist/answersClient.js.map +1 -0
- package/dist/audience/index.d.ts +38 -0
- package/dist/audience/index.js +110 -0
- package/dist/audience/index.js.map +1 -0
- package/dist/{packages/sdk/src/audiencesClient.d.ts → audiencesClient.d.ts} +30 -18
- package/dist/audiencesClient.js +472 -0
- package/dist/audiencesClient.js.map +1 -0
- package/dist/auditClient.d.ts +29 -0
- package/dist/auditClient.js +386 -0
- package/dist/auditClient.js.map +1 -0
- package/dist/beliefs/index.d.ts +465 -0
- package/dist/beliefs/index.js +6433 -0
- package/dist/beliefs/index.js.map +1 -0
- package/dist/beliefs/lifecycle.d.ts +24 -0
- package/dist/beliefs/lifecycle.js +98 -0
- package/dist/beliefs/lifecycle.js.map +1 -0
- package/dist/beliefsClient.d.ts +241 -0
- package/dist/beliefsClient.js +646 -0
- package/dist/beliefsClient.js.map +1 -0
- package/dist/client.d.ts +2398 -0
- package/dist/client.js +6411 -0
- package/dist/client.js.map +1 -0
- package/dist/contextClient.d.ts +27 -0
- package/dist/contextClient.js +396 -0
- package/dist/contextClient.js.map +1 -0
- package/dist/contextFacade.d.ts +2 -0
- package/dist/contextFacade.js +73 -0
- package/dist/contextFacade.js.map +1 -0
- package/dist/{lucern/packages/domain-context/src/context-pack-compiler.d.ts → contextPackCompiler.d.ts} +11 -10
- package/dist/contextPackCompiler.js +1091 -0
- package/dist/contextPackCompiler.js.map +1 -0
- package/dist/contextPackPolicy.d.ts +84 -0
- package/dist/contextPackPolicy.js +347 -0
- package/dist/contextPackPolicy.js.map +1 -0
- package/dist/contextPackSchema.d.ts +7 -0
- package/dist/contextPackSchema.js +203 -0
- package/dist/contextPackSchema.js.map +1 -0
- package/dist/contextTypes.d.ts +135 -0
- package/dist/contextTypes.js +3 -0
- package/dist/contextTypes.js.map +1 -0
- package/dist/contracts/api-enums.contract.d.ts +81 -0
- package/dist/contracts/api-enums.contract.js +98 -0
- package/dist/contracts/api-enums.contract.js.map +1 -0
- package/dist/{lucern/contracts/src → contracts}/auth-session.contract.d.ts +14 -12
- package/dist/contracts/auth-session.contract.js +48 -0
- package/dist/contracts/auth-session.contract.js.map +1 -0
- package/dist/{lucern/contracts/src → contracts}/context-pack.contract.d.ts +56 -58
- package/dist/contracts/context-pack.contract.js +98 -0
- package/dist/contracts/context-pack.contract.js.map +1 -0
- package/dist/contracts/contextPack.d.ts +1 -0
- package/dist/contracts/contextPack.js +98 -0
- package/dist/contracts/contextPack.js.map +1 -0
- package/dist/contracts/index.d.ts +9 -0
- package/dist/contracts/index.js +4928 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/{lucern/contracts/src → contracts}/lens-filter.contract.d.ts +10 -8
- package/dist/contracts/lens-filter.contract.js +71 -0
- package/dist/contracts/lens-filter.contract.js.map +1 -0
- package/dist/contracts/lens-workflow.contract.d.ts +87 -0
- package/dist/contracts/lens-workflow.contract.js +123 -0
- package/dist/contracts/lens-workflow.contract.js.map +1 -0
- package/dist/contracts/lensFilter.d.ts +1 -0
- package/dist/contracts/lensFilter.js +71 -0
- package/dist/contracts/lensFilter.js.map +1 -0
- package/dist/contracts/lensWorkflow.d.ts +2 -0
- package/dist/contracts/lensWorkflow.js +123 -0
- package/dist/contracts/lensWorkflow.js.map +1 -0
- package/dist/contracts/mcp-tools.contract.d.ts +1 -0
- package/dist/contracts/mcp-tools.contract.js +3016 -0
- package/dist/contracts/mcp-tools.contract.js.map +1 -0
- package/dist/contracts/mcpTools.d.ts +1 -0
- package/dist/contracts/mcpTools.js +3016 -0
- package/dist/contracts/mcpTools.js.map +1 -0
- package/dist/contracts/prompt.contract.d.ts +26 -0
- package/dist/contracts/prompt.contract.js +12 -0
- package/dist/contracts/prompt.contract.js.map +1 -0
- package/dist/contracts/prompt.d.ts +1 -0
- package/dist/contracts/prompt.js +12 -0
- package/dist/contracts/prompt.js.map +1 -0
- package/dist/contracts/sdk-tools.contract.d.ts +2 -0
- package/dist/contracts/sdk-tools.contract.js +4164 -0
- package/dist/contracts/sdk-tools.contract.js.map +1 -0
- package/dist/contracts/sdkTools.d.ts +2 -0
- package/dist/contracts/sdkTools.js +4164 -0
- package/dist/contracts/sdkTools.js.map +1 -0
- package/dist/contracts/workflow-runtime.contract.d.ts +163 -0
- package/dist/contracts/workflow-runtime.contract.js +245 -0
- package/dist/contracts/workflow-runtime.contract.js.map +1 -0
- package/dist/contracts/workflowRuntime.d.ts +1 -0
- package/dist/contracts/workflowRuntime.js +245 -0
- package/dist/contracts/workflowRuntime.js.map +1 -0
- package/dist/contradictions/index.d.ts +158 -0
- package/dist/contradictions/index.js +6427 -0
- package/dist/contradictions/index.js.map +1 -0
- package/dist/{packages/sdk/src/controlObjectOwnership.d.ts → controlObjectOwnership.d.ts} +35 -18
- package/dist/controlObjectOwnership.js +215 -0
- package/dist/controlObjectOwnership.js.map +1 -0
- package/dist/{packages/sdk/src/coreClient.d.ts → coreClient.d.ts} +38 -14
- package/dist/coreClient.js +339 -0
- package/dist/coreClient.js.map +1 -0
- package/dist/customTools.d.ts +88 -0
- package/dist/customTools.js +248 -0
- package/dist/customTools.js.map +1 -0
- package/dist/decisions/index.d.ts +68 -0
- package/dist/decisions/index.js +6429 -0
- package/dist/decisions/index.js.map +1 -0
- package/dist/decisionsClient.d.ts +111 -0
- package/dist/decisionsClient.js +522 -0
- package/dist/decisionsClient.js.map +1 -0
- package/dist/domainContext.d.ts +1 -0
- package/dist/domainContext.js +3 -0
- package/dist/domainContext.js.map +1 -0
- package/dist/edges/index.d.ts +204 -0
- package/dist/edges/index.js +6428 -0
- package/dist/edges/index.js.map +1 -0
- package/dist/events.d.ts +178 -0
- package/dist/events.js +251 -0
- package/dist/events.js.map +1 -0
- package/dist/eventsCore.d.ts +49 -0
- package/dist/eventsCore.js +429 -0
- package/dist/eventsCore.js.map +1 -0
- package/dist/evidence/index.d.ts +295 -0
- package/dist/evidence/index.js +6428 -0
- package/dist/evidence/index.js.map +1 -0
- package/dist/evidenceClient.d.ts +119 -0
- package/dist/evidenceClient.js +350 -0
- package/dist/evidenceClient.js.map +1 -0
- package/dist/facade/context.d.ts +18 -0
- package/dist/facade/context.js +73 -0
- package/dist/facade/context.js.map +1 -0
- package/dist/gatewayFacades.d.ts +589 -0
- package/dist/gatewayFacades.js +2006 -0
- package/dist/gatewayFacades.js.map +1 -0
- package/dist/graphClient.d.ts +271 -0
- package/dist/graphClient.js +698 -0
- package/dist/graphClient.js.map +1 -0
- package/dist/{packages/sdk/src/harnessClient.d.ts → harnessClient.d.ts} +127 -35
- package/dist/harnessClient.js +607 -0
- package/dist/harnessClient.js.map +1 -0
- package/dist/identityClient.d.ts +140 -0
- package/dist/identityClient.js +497 -0
- package/dist/identityClient.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +5284 -2568
- package/dist/index.js.map +1 -1
- package/dist/learningClient.d.ts +46 -0
- package/dist/learningClient.js +409 -0
- package/dist/learningClient.js.map +1 -0
- package/dist/lenses/index.d.ts +194 -0
- package/dist/lenses/index.js +6427 -0
- package/dist/lenses/index.js.map +1 -0
- package/dist/{packages/sdk/src/mcpParityClient.d.ts → mcpParityClient.d.ts} +11 -5
- package/dist/mcpParityClient.js +516 -0
- package/dist/mcpParityClient.js.map +1 -0
- package/dist/mcpParitySurface.d.ts +12 -0
- package/dist/mcpParitySurface.js +65 -0
- package/dist/mcpParitySurface.js.map +1 -0
- package/dist/mcpTools-DPZxowDX.d.ts +254 -0
- package/dist/nodes/index.d.ts +62 -0
- package/dist/nodes/index.js +6429 -0
- package/dist/nodes/index.js.map +1 -0
- package/dist/ontologies/index.d.ts +178 -0
- package/dist/ontologies/index.js +6430 -0
- package/dist/ontologies/index.js.map +1 -0
- package/dist/{packages/sdk/src/ontologyClient.d.ts → ontologyClient.d.ts} +44 -22
- package/dist/ontologyClient.js +513 -0
- package/dist/ontologyClient.js.map +1 -0
- package/dist/opinion.d.ts +11 -0
- package/dist/opinion.js +35 -0
- package/dist/opinion.js.map +1 -0
- package/dist/packRuntime.d.ts +2 -0
- package/dist/packRuntime.js +3 -0
- package/dist/packRuntime.js.map +1 -0
- package/dist/packsClient.d.ts +131 -0
- package/dist/packsClient.js +525 -0
- package/dist/packsClient.js.map +1 -0
- package/dist/{packages/sdk/src/policyClient.d.ts → policyClient.d.ts} +113 -18
- package/dist/policyClient.js +625 -0
- package/dist/policyClient.js.map +1 -0
- package/dist/questions/index.d.ts +297 -0
- package/dist/questions/index.js +6430 -0
- package/dist/questions/index.js.map +1 -0
- package/dist/realtime/index.d.ts +29 -0
- package/dist/realtime/index.js +23 -0
- package/dist/realtime/index.js.map +1 -0
- package/dist/realtime/refs.d.ts +17 -0
- package/dist/realtime/refs.js +9 -0
- package/dist/realtime/refs.js.map +1 -0
- package/dist/reportsClient.d.ts +41 -0
- package/dist/reportsClient.js +418 -0
- package/dist/reportsClient.js.map +1 -0
- package/dist/schemaClient.d.ts +64 -0
- package/dist/schemaClient.js +434 -0
- package/dist/schemaClient.js.map +1 -0
- package/dist/sdkSurface.d.ts +61 -0
- package/dist/sdkSurface.js +112 -0
- package/dist/sdkSurface.js.map +1 -0
- package/dist/sdkTools-CwXJDACb.d.ts +150 -0
- package/dist/sourcesClient.d.ts +24 -0
- package/dist/sourcesClient.js +339 -0
- package/dist/sourcesClient.js.map +1 -0
- package/dist/topics/index.d.ts +68 -0
- package/dist/topics/index.js +6428 -0
- package/dist/topics/index.js.map +1 -0
- package/dist/topicsClient.d.ts +84 -0
- package/dist/topicsClient.js +492 -0
- package/dist/topicsClient.js.map +1 -0
- package/dist/types.d.ts +715 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +4 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/dist/workflowClient.d.ts +316 -0
- package/dist/workflowClient.js +830 -0
- package/dist/workflowClient.js.map +1 -0
- package/dist/worktrees/index.d.ts +210 -0
- package/dist/worktrees/index.js +6430 -0
- package/dist/worktrees/index.js.map +1 -0
- package/package.json +92 -37
- package/dist/lucern/contracts/src/lens-workflow.contract.d.ts +0 -84
- package/dist/lucern/contracts/src/mcp-tools.contract.d.ts +0 -151
- package/dist/lucern/contracts/src/workflow-runtime.contract.d.ts +0 -161
- package/dist/lucern/mcp-server/src/context-pack-policy.d.ts +0 -119
- package/dist/lucern/mcp-server/src/context-pack-schema.d.ts +0 -18
- package/dist/lucern/modules/graph-primitives/src/ontology-matching.d.ts +0 -78
- package/dist/lucern/modules/graph-primitives/src/text-matching.d.ts +0 -53
- package/dist/lucern/packages/client-core/src/beliefs.d.ts +0 -30
- package/dist/lucern/packages/client-core/src/context.d.ts +0 -29
- package/dist/lucern/packages/client-core/src/contradictions.d.ts +0 -11
- package/dist/lucern/packages/client-core/src/edges.d.ts +0 -11
- package/dist/lucern/packages/client-core/src/events.d.ts +0 -9
- package/dist/lucern/packages/client-core/src/evidence.d.ts +0 -21
- package/dist/lucern/packages/client-core/src/graph.d.ts +0 -17
- package/dist/lucern/packages/client-core/src/identity.d.ts +0 -7
- package/dist/lucern/packages/client-core/src/ids.d.ts +0 -7
- package/dist/lucern/packages/client-core/src/ontologies.d.ts +0 -13
- package/dist/lucern/packages/client-core/src/questions.d.ts +0 -39
- package/dist/lucern/packages/client-core/src/search.d.ts +0 -7
- package/dist/lucern/packages/client-core/src/tasks.d.ts +0 -13
- package/dist/lucern/packages/client-core/src/topics.d.ts +0 -17
- package/dist/lucern/packages/client-core/src/webhooks.d.ts +0 -35
- package/dist/lucern/packages/client-core/src/worktrees.d.ts +0 -17
- package/dist/lucern/packages/domain-beliefs/src/beliefs.d.ts +0 -283
- package/dist/lucern/packages/domain-beliefs/src/index.d.ts +0 -1
- package/dist/lucern/packages/domain-context/src/compile.d.ts +0 -11
- package/dist/lucern/packages/domain-context/src/index.d.ts +0 -4
- package/dist/lucern/packages/domain-context/src/ports.d.ts +0 -58
- package/dist/lucern/packages/domain-context/src/public-types.d.ts +0 -1
- package/dist/lucern/packages/domain-edges/src/contradictions.d.ts +0 -59
- package/dist/lucern/packages/domain-edges/src/edges.d.ts +0 -91
- package/dist/lucern/packages/domain-edges/src/index.d.ts +0 -2
- package/dist/lucern/packages/domain-evidence/src/evidence.d.ts +0 -115
- package/dist/lucern/packages/domain-evidence/src/index.d.ts +0 -1
- package/dist/lucern/packages/domain-graph/src/graph.d.ts +0 -150
- package/dist/lucern/packages/domain-identity/src/index.d.ts +0 -1
- package/dist/lucern/packages/domain-identity/src/whoami.d.ts +0 -13
- package/dist/lucern/packages/domain-ontologies/src/ontologies.d.ts +0 -123
- package/dist/lucern/packages/domain-questions/src/index.d.ts +0 -1
- package/dist/lucern/packages/domain-questions/src/questions.d.ts +0 -147
- package/dist/lucern/packages/domain-search/src/search.d.ts +0 -97
- package/dist/lucern/packages/domain-tasks/src/index.d.ts +0 -1
- package/dist/lucern/packages/domain-tasks/src/tasks.d.ts +0 -102
- package/dist/lucern/packages/domain-topics/src/index.d.ts +0 -1
- package/dist/lucern/packages/domain-topics/src/topics.d.ts +0 -147
- package/dist/lucern/packages/domain-worktrees/src/index.d.ts +0 -1
- package/dist/lucern/packages/domain-worktrees/src/worktrees.d.ts +0 -185
- package/dist/lucern/packages/events/src/index.d.ts +0 -4
- package/dist/lucern/packages/events/src/matching.d.ts +0 -3
- package/dist/lucern/packages/events/src/outbox.d.ts +0 -15
- package/dist/lucern/packages/events/src/types.d.ts +0 -151
- package/dist/lucern/packages/events/src/webhooks.d.ts +0 -9
- package/dist/lucern/packages/sdk-typescript/src/facade/beliefs.d.ts +0 -15
- package/dist/lucern/packages/sdk-typescript/src/facade/context.d.ts +0 -12
- package/dist/lucern/packages/sdk-typescript/src/facade/contradictions.d.ts +0 -7
- package/dist/lucern/packages/sdk-typescript/src/facade/edges.d.ts +0 -7
- package/dist/lucern/packages/sdk-typescript/src/facade/events.d.ts +0 -6
- package/dist/lucern/packages/sdk-typescript/src/facade/evidence.d.ts +0 -21
- package/dist/lucern/packages/sdk-typescript/src/facade/graph.d.ts +0 -10
- package/dist/lucern/packages/sdk-typescript/src/facade/identity.d.ts +0 -5
- package/dist/lucern/packages/sdk-typescript/src/facade/ontologies.d.ts +0 -8
- package/dist/lucern/packages/sdk-typescript/src/facade/questions.d.ts +0 -39
- package/dist/lucern/packages/sdk-typescript/src/facade/search.d.ts +0 -5
- package/dist/lucern/packages/sdk-typescript/src/facade/tasks.d.ts +0 -8
- package/dist/lucern/packages/sdk-typescript/src/facade/topics.d.ts +0 -10
- package/dist/lucern/packages/sdk-typescript/src/facade/webhooks.d.ts +0 -16
- package/dist/lucern/packages/sdk-typescript/src/facade/worktrees.d.ts +0 -10
- package/dist/lucern/packages/sdk-typescript/src/index.d.ts +0 -28
- package/dist/packages/sdk/src/adminClient.d.ts +0 -89
- package/dist/packages/sdk/src/answersClient.d.ts +0 -5
- package/dist/packages/sdk/src/auditClient.d.ts +0 -23
- package/dist/packages/sdk/src/beliefsClient.d.ts +0 -54
- package/dist/packages/sdk/src/client.d.ts +0 -1610
- package/dist/packages/sdk/src/contextClient.d.ts +0 -9
- package/dist/packages/sdk/src/contracts/api-enums.contract.d.ts +0 -58
- package/dist/packages/sdk/src/customTools.d.ts +0 -65
- package/dist/packages/sdk/src/decisionsClient.d.ts +0 -110
- package/dist/packages/sdk/src/graphClient.d.ts +0 -209
- package/dist/packages/sdk/src/identityClient.d.ts +0 -104
- package/dist/packages/sdk/src/index.d.ts +0 -28
- package/dist/packages/sdk/src/learningClient.d.ts +0 -43
- package/dist/packages/sdk/src/mcpParitySurface.d.ts +0 -8
- package/dist/packages/sdk/src/packsClient.d.ts +0 -101
- package/dist/packages/sdk/src/reportsClient.d.ts +0 -31
- package/dist/packages/sdk/src/schemaClient.d.ts +0 -54
- package/dist/packages/sdk/src/sdkSurface.d.ts +0 -56
- package/dist/packages/sdk/src/topicsClient.d.ts +0 -45
- package/dist/packages/sdk/src/types.d.ts +0 -489
- package/dist/packages/sdk/src/version.d.ts +0 -2
- package/dist/packages/sdk/src/workflowClient.d.ts +0 -274
|
@@ -0,0 +1,646 @@
|
|
|
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
|