@lucern/sdk 0.2.0-alpha.9 → 0.3.0-alpha.1
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/README.md +33 -15
- package/dist/adminClient.d.ts +15 -9
- package/dist/adminClient.js.map +1 -1
- 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/beliefs/index.d.ts +463 -0
- package/dist/beliefs/index.js +6695 -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 +76 -12
- package/dist/beliefsClient.js +139 -7
- package/dist/beliefsClient.js.map +1 -1
- package/dist/client-B6aWUUwp.d.ts +2552 -0
- package/dist/client.d.ts +31 -2377
- package/dist/client.js +802 -263
- package/dist/client.js.map +1 -1
- package/dist/contracts/api-enums.contract.d.ts +1 -1
- package/dist/contracts/api-enums.contract.js +8 -2
- package/dist/contracts/api-enums.contract.js.map +1 -1
- package/dist/contracts/index.d.ts +4 -2
- package/dist/contracts/index.js +119 -4283
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/mcpTools.d.ts +2 -1
- package/dist/contracts/mcpTools.js +22 -2981
- package/dist/contracts/mcpTools.js.map +1 -1
- package/dist/contracts/sdk-tools.contract.d.ts +1 -2
- package/dist/contracts/sdk-tools.contract.js +1 -4132
- package/dist/contracts/sdk-tools.contract.js.map +1 -1
- package/dist/contracts/sdkTools.d.ts +1 -2
- package/dist/contracts/sdkTools.js +20 -4127
- package/dist/contracts/sdkTools.js.map +1 -1
- package/dist/contracts/tool-contracts.d.ts +1 -0
- package/dist/contracts/tool-contracts.js +3 -0
- package/dist/contracts/tool-contracts.js.map +1 -0
- package/dist/contracts/workflow-runtime.contract.js +1 -1
- package/dist/contracts/workflow-runtime.contract.js.map +1 -1
- package/dist/contracts/workflowRuntime.js +1 -1
- package/dist/contracts/workflowRuntime.js.map +1 -1
- package/dist/contradictions/index.d.ts +156 -0
- package/dist/contradictions/index.js +6689 -0
- package/dist/contradictions/index.js.map +1 -0
- package/dist/customTools.d.ts +1 -1
- package/dist/decisions/index.d.ts +66 -0
- package/dist/decisions/index.js +6691 -0
- package/dist/decisions/index.js.map +1 -0
- package/dist/edges/index.d.ts +202 -0
- package/dist/edges/index.js +6690 -0
- package/dist/edges/index.js.map +1 -0
- package/dist/events.js +7 -5
- package/dist/events.js.map +1 -1
- package/dist/evidence/index.d.ts +294 -0
- package/dist/evidence/index.js +6690 -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/gatewayFacades.d.ts +25 -15
- package/dist/gatewayFacades.js +39 -5
- package/dist/gatewayFacades.js.map +1 -1
- package/dist/identityClient.d.ts +3 -3
- package/dist/identityClient.js.map +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/index.js +1145 -3313
- package/dist/index.js.map +1 -1
- package/dist/lenses/index.d.ts +194 -0
- package/dist/lenses/index.js +6689 -0
- package/dist/lenses/index.js.map +1 -0
- package/dist/nodes/index.d.ts +61 -0
- package/dist/nodes/index.js +6691 -0
- package/dist/nodes/index.js.map +1 -0
- package/dist/ontologies/index.d.ts +179 -0
- package/dist/ontologies/index.js +6692 -0
- package/dist/ontologies/index.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/questions/index.d.ts +295 -0
- package/dist/questions/index.js +6692 -0
- package/dist/questions/index.js.map +1 -0
- package/dist/sdk-tools.contract-B4c1Zr1o.d.ts +22 -0
- package/dist/sourcesClient.d.ts +24 -0
- package/dist/{mcpParityClient.js → sourcesClient.js} +15 -192
- package/dist/sourcesClient.js.map +1 -0
- package/dist/tool-contracts-BUiL9P6z.d.ts +22 -0
- package/dist/topics/index.d.ts +66 -0
- package/dist/topics/index.js +6690 -0
- package/dist/topics/index.js.map +1 -0
- package/dist/types.d.ts +27 -8
- package/dist/workflowClient.d.ts +18 -5
- package/dist/workflowClient.js +19 -7
- package/dist/workflowClient.js.map +1 -1
- package/dist/worktrees/index.d.ts +211 -0
- package/dist/worktrees/index.js +6692 -0
- package/dist/worktrees/index.js.map +1 -0
- package/package.json +56 -3
- package/dist/contracts/mcp-tools.contract.d.ts +0 -1
- package/dist/contracts/mcp-tools.contract.js +0 -2986
- package/dist/contracts/mcp-tools.contract.js.map +0 -1
- package/dist/mcpParityClient.d.ts +0 -74
- package/dist/mcpParityClient.js.map +0 -1
- package/dist/mcpParitySurface.d.ts +0 -12
- package/dist/mcpParitySurface.js +0 -65
- package/dist/mcpParitySurface.js.map +0 -1
- package/dist/mcpTools-DPZxowDX.d.ts +0 -254
- package/dist/sdkTools-CwXJDACb.d.ts +0 -150
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type BeliefLifecycleStatus = "assumption" | "hypothesis" | "belief" | "fact";
|
|
2
|
+
declare function isBeliefLifecycleStatus(value: unknown): value is BeliefLifecycleStatus;
|
|
3
|
+
declare function isResolvedByConfidence(confidence: unknown): boolean;
|
|
4
|
+
declare function hasResolvedPredictionOutcome(predictionMeta: unknown): boolean;
|
|
5
|
+
declare function shouldTreatBeliefAsFact(opts: {
|
|
6
|
+
confidence?: unknown;
|
|
7
|
+
predictionMeta?: unknown;
|
|
8
|
+
metadata?: Record<string, unknown>;
|
|
9
|
+
}): boolean;
|
|
10
|
+
declare function resolveBeliefLifecycleStatus(opts: {
|
|
11
|
+
beliefStatus?: unknown;
|
|
12
|
+
confidence?: unknown;
|
|
13
|
+
predictionMeta?: unknown;
|
|
14
|
+
metadata?: Record<string, unknown>;
|
|
15
|
+
}): BeliefLifecycleStatus;
|
|
16
|
+
declare function isPreValidationBeliefStatus(status: BeliefLifecycleStatus): boolean;
|
|
17
|
+
declare function isPropagationEligibleBeliefStatus(status: BeliefLifecycleStatus): boolean;
|
|
18
|
+
declare function promoteBeliefStatusAfterScoring(status: BeliefLifecycleStatus, opts?: {
|
|
19
|
+
confidence?: unknown;
|
|
20
|
+
predictionMeta?: unknown;
|
|
21
|
+
metadata?: Record<string, unknown>;
|
|
22
|
+
}): BeliefLifecycleStatus;
|
|
23
|
+
|
|
24
|
+
export { type BeliefLifecycleStatus, hasResolvedPredictionOutcome, isBeliefLifecycleStatus, isPreValidationBeliefStatus, isPropagationEligibleBeliefStatus, isResolvedByConfidence, promoteBeliefStatusAfterScoring, resolveBeliefLifecycleStatus, shouldTreatBeliefAsFact };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// src/beliefs/lifecycle.ts
|
|
2
|
+
var BELIEF_STATUS_VALUES = [
|
|
3
|
+
"assumption",
|
|
4
|
+
"hypothesis",
|
|
5
|
+
"belief",
|
|
6
|
+
"fact"
|
|
7
|
+
];
|
|
8
|
+
var RESOLVED_PREDICTION_OUTCOMES = [
|
|
9
|
+
"confirmed",
|
|
10
|
+
"disconfirmed",
|
|
11
|
+
"partial",
|
|
12
|
+
"expired"
|
|
13
|
+
];
|
|
14
|
+
function isBeliefLifecycleStatus(value) {
|
|
15
|
+
return typeof value === "string" && BELIEF_STATUS_VALUES.includes(value);
|
|
16
|
+
}
|
|
17
|
+
function normalizeBeliefConfidence(confidence) {
|
|
18
|
+
if (typeof confidence !== "number" || !Number.isFinite(confidence)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
if (confidence >= 0 && confidence <= 1) {
|
|
22
|
+
return confidence;
|
|
23
|
+
}
|
|
24
|
+
if (confidence > 1 && confidence <= 100) {
|
|
25
|
+
return confidence / 100;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
function isResolvedByConfidence(confidence) {
|
|
30
|
+
const normalized = normalizeBeliefConfidence(confidence);
|
|
31
|
+
if (normalized === null) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return normalized <= 0 || normalized >= 1;
|
|
35
|
+
}
|
|
36
|
+
function hasResolvedPredictionOutcome(predictionMeta) {
|
|
37
|
+
if (!predictionMeta || typeof predictionMeta !== "object") {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const outcome = predictionMeta.outcome;
|
|
41
|
+
return typeof outcome === "string" && RESOLVED_PREDICTION_OUTCOMES.includes(outcome);
|
|
42
|
+
}
|
|
43
|
+
function getPredictionMetaFromMetadata(metadata) {
|
|
44
|
+
return metadata?.predictionMeta;
|
|
45
|
+
}
|
|
46
|
+
function shouldTreatBeliefAsFact(opts) {
|
|
47
|
+
if (isResolvedByConfidence(opts.confidence)) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
if (hasResolvedPredictionOutcome(opts.predictionMeta)) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
if (hasResolvedPredictionOutcome(getPredictionMetaFromMetadata(opts.metadata))) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
function resolveBeliefLifecycleStatus(opts) {
|
|
59
|
+
if (shouldTreatBeliefAsFact(opts)) {
|
|
60
|
+
return "fact";
|
|
61
|
+
}
|
|
62
|
+
const direct = opts.beliefStatus;
|
|
63
|
+
if (isBeliefLifecycleStatus(direct)) {
|
|
64
|
+
const normalized = normalizeBeliefConfidence(opts.confidence);
|
|
65
|
+
if (normalized !== null && isPreValidationBeliefStatus(direct)) {
|
|
66
|
+
return "belief";
|
|
67
|
+
}
|
|
68
|
+
return direct;
|
|
69
|
+
}
|
|
70
|
+
const metaStatus = opts.metadata?.beliefStatus;
|
|
71
|
+
if (isBeliefLifecycleStatus(metaStatus)) {
|
|
72
|
+
const normalized = normalizeBeliefConfidence(opts.confidence);
|
|
73
|
+
if (normalized !== null && isPreValidationBeliefStatus(metaStatus)) {
|
|
74
|
+
return "belief";
|
|
75
|
+
}
|
|
76
|
+
return metaStatus;
|
|
77
|
+
}
|
|
78
|
+
return "assumption";
|
|
79
|
+
}
|
|
80
|
+
function isPreValidationBeliefStatus(status) {
|
|
81
|
+
return status === "assumption" || status === "hypothesis";
|
|
82
|
+
}
|
|
83
|
+
function isPropagationEligibleBeliefStatus(status) {
|
|
84
|
+
return status === "belief" || status === "fact";
|
|
85
|
+
}
|
|
86
|
+
function promoteBeliefStatusAfterScoring(status, opts) {
|
|
87
|
+
if (shouldTreatBeliefAsFact({ ...opts })) {
|
|
88
|
+
return "fact";
|
|
89
|
+
}
|
|
90
|
+
if (isPreValidationBeliefStatus(status)) {
|
|
91
|
+
return "belief";
|
|
92
|
+
}
|
|
93
|
+
return status === "fact" ? "fact" : "belief";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export { hasResolvedPredictionOutcome, isBeliefLifecycleStatus, isPreValidationBeliefStatus, isPropagationEligibleBeliefStatus, isResolvedByConfidence, promoteBeliefStatusAfterScoring, resolveBeliefLifecycleStatus, shouldTreatBeliefAsFact };
|
|
97
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
98
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/beliefs/lifecycle.ts"],"names":[],"mappings":";AAaA,IAAM,oBAAA,GAAyD;AAAA,EAC7D,YAAA;AAAA,EACA,YAAA;AAAA,EACA,QAAA;AAAA,EACA;AACF,CAAA;AAEA,IAAM,4BAAA,GAA6D;AAAA,EACjE,WAAA;AAAA,EACA,cAAA;AAAA,EACA,SAAA;AAAA,EACA;AACF,CAAA;AAEO,SAAS,wBACd,KAAA,EACgC;AAChC,EAAA,OACE,OAAO,KAAA,KAAU,QAAA,IACjB,oBAAA,CAAqB,SAAS,KAA8B,CAAA;AAEhE;AAEA,SAAS,0BAA0B,UAAA,EAAoC;AACrE,EAAA,IAAI,OAAO,UAAA,KAAe,QAAA,IAAY,CAAC,MAAA,CAAO,QAAA,CAAS,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":"lifecycle.js","sourcesContent":["export type BeliefLifecycleStatus =\n | \"assumption\"\n | \"hypothesis\"\n | \"belief\"\n | \"fact\";\n\ntype PredictionOutcome =\n | \"pending\"\n | \"confirmed\"\n | \"disconfirmed\"\n | \"partial\"\n | \"expired\";\n\nconst BELIEF_STATUS_VALUES: readonly BeliefLifecycleStatus[] = [\n \"assumption\",\n \"hypothesis\",\n \"belief\",\n \"fact\",\n];\n\nconst RESOLVED_PREDICTION_OUTCOMES: readonly PredictionOutcome[] = [\n \"confirmed\",\n \"disconfirmed\",\n \"partial\",\n \"expired\",\n];\n\nexport function isBeliefLifecycleStatus(\n value: unknown\n): value is BeliefLifecycleStatus {\n return (\n typeof value === \"string\" &&\n BELIEF_STATUS_VALUES.includes(value as BeliefLifecycleStatus)\n );\n}\n\nfunction normalizeBeliefConfidence(confidence: unknown): number | null {\n if (typeof confidence !== \"number\" || !Number.isFinite(confidence)) {\n return null;\n }\n if (confidence >= 0 && confidence <= 1) {\n return confidence;\n }\n if (confidence > 1 && confidence <= 100) {\n return confidence / 100;\n }\n return null;\n}\n\nexport function isResolvedByConfidence(confidence: unknown): boolean {\n const normalized = normalizeBeliefConfidence(confidence);\n if (normalized === null) {\n return false;\n }\n return normalized <= 0 || normalized >= 1;\n}\n\nexport function hasResolvedPredictionOutcome(predictionMeta: unknown): boolean {\n if (!predictionMeta || typeof predictionMeta !== \"object\") {\n return false;\n }\n const outcome = (predictionMeta as { outcome?: unknown }).outcome;\n return (\n typeof outcome === \"string\" &&\n RESOLVED_PREDICTION_OUTCOMES.includes(outcome as PredictionOutcome)\n );\n}\n\nfunction getPredictionMetaFromMetadata(\n metadata: Record<string, unknown> | undefined\n): unknown {\n return metadata?.predictionMeta;\n}\n\nexport function shouldTreatBeliefAsFact(opts: {\n confidence?: unknown;\n predictionMeta?: unknown;\n metadata?: Record<string, unknown>;\n}): boolean {\n if (isResolvedByConfidence(opts.confidence)) {\n return true;\n }\n if (hasResolvedPredictionOutcome(opts.predictionMeta)) {\n return true;\n }\n if (\n hasResolvedPredictionOutcome(getPredictionMetaFromMetadata(opts.metadata))\n ) {\n return true;\n }\n return false;\n}\n\nexport function resolveBeliefLifecycleStatus(opts: {\n beliefStatus?: unknown;\n confidence?: unknown;\n predictionMeta?: unknown;\n metadata?: Record<string, unknown>;\n}): BeliefLifecycleStatus {\n if (shouldTreatBeliefAsFact(opts)) {\n return \"fact\";\n }\n\n const direct = opts.beliefStatus;\n if (isBeliefLifecycleStatus(direct)) {\n const normalized = normalizeBeliefConfidence(opts.confidence);\n if (normalized !== null && isPreValidationBeliefStatus(direct)) {\n return \"belief\";\n }\n return direct;\n }\n\n const metaStatus = opts.metadata?.beliefStatus;\n if (isBeliefLifecycleStatus(metaStatus)) {\n const normalized = normalizeBeliefConfidence(opts.confidence);\n if (normalized !== null && isPreValidationBeliefStatus(metaStatus)) {\n return \"belief\";\n }\n return metaStatus;\n }\n\n return \"assumption\";\n}\n\nexport function isPreValidationBeliefStatus(\n status: BeliefLifecycleStatus\n): boolean {\n return status === \"assumption\" || status === \"hypothesis\";\n}\n\nexport function isPropagationEligibleBeliefStatus(\n status: BeliefLifecycleStatus\n): boolean {\n return status === \"belief\" || status === \"fact\";\n}\n\nexport function promoteBeliefStatusAfterScoring(\n status: BeliefLifecycleStatus,\n opts?: {\n confidence?: unknown;\n predictionMeta?: unknown;\n metadata?: Record<string, unknown>;\n }\n): BeliefLifecycleStatus {\n if (shouldTreatBeliefAsFact({ ...opts })) {\n return \"fact\";\n }\n if (isPreValidationBeliefStatus(status)) {\n return \"belief\";\n }\n return status === \"fact\" ? \"fact\" : \"belief\";\n}\n"]}
|
package/dist/beliefsClient.d.ts
CHANGED
|
@@ -1,19 +1,39 @@
|
|
|
1
|
-
import { GatewayClientConfig, PlatformGatewaySuccess } from './coreClient.js';
|
|
2
|
-
export { LucernApiError } from './coreClient.js';
|
|
3
1
|
import { JsonObject, PlatformBeliefRecord, ModulateConfidenceResponse, ForkBeliefResponse } from './types.js';
|
|
4
2
|
export { CreateBeliefResponse } from './types.js';
|
|
3
|
+
import { GatewayClientConfig, PlatformGatewaySuccess } from './coreClient.js';
|
|
4
|
+
export { LucernApiError } from './coreClient.js';
|
|
5
|
+
import { Opinion } from './opinion.js';
|
|
5
6
|
import './contracts/workflow-runtime.contract.js';
|
|
6
7
|
import './contracts/lens-workflow.contract.js';
|
|
7
8
|
import './contracts/lens-filter.contract.js';
|
|
8
9
|
|
|
9
10
|
/** Configuration for the beliefs client. Inherits gateway transport settings. */
|
|
10
11
|
type BeliefsClientConfig = GatewayClientConfig;
|
|
12
|
+
type OpinionHistoryEntry = {
|
|
13
|
+
t: number;
|
|
14
|
+
b: number;
|
|
15
|
+
d: number;
|
|
16
|
+
u: number;
|
|
17
|
+
a: number;
|
|
18
|
+
P: number;
|
|
19
|
+
trigger: string;
|
|
20
|
+
triggeringRef?: {
|
|
21
|
+
kind: "evidence" | "question" | "answer" | "contradiction" | "worktree";
|
|
22
|
+
id: string;
|
|
23
|
+
};
|
|
24
|
+
rationale?: string;
|
|
25
|
+
userId?: string;
|
|
26
|
+
slOperator?: string;
|
|
27
|
+
};
|
|
28
|
+
type GatewayRecord = Record<string, unknown>;
|
|
29
|
+
declare function mapOpinionHistoryEntriesFromGatewayData(payload: GatewayRecord): OpinionHistoryEntry[];
|
|
11
30
|
/**
|
|
12
31
|
* Input for creating a new belief within a topic scope.
|
|
13
32
|
*
|
|
14
33
|
* Use `text` as the canonical belief statement.
|
|
15
34
|
* `canonicalText` remains available as a legacy alias for backwards compatibility.
|
|
16
|
-
* Beliefs start as
|
|
35
|
+
* Beliefs start as drafts with a vacuous prior `(0, 0, 1, a)`. When omitted,
|
|
36
|
+
* `baseRate` defaults to the canonical neutral prior `0.5`.
|
|
17
37
|
*/
|
|
18
38
|
type CreateBeliefInput = {
|
|
19
39
|
topicId?: string;
|
|
@@ -30,20 +50,44 @@ type CreateBeliefInput = {
|
|
|
30
50
|
title?: string;
|
|
31
51
|
subtype?: string;
|
|
32
52
|
confidence?: number;
|
|
53
|
+
baseRate?: number;
|
|
33
54
|
tags?: string[];
|
|
34
55
|
metadata?: JsonObject;
|
|
35
56
|
verificationStatus?: "unverified" | "verified" | "rejected";
|
|
36
57
|
};
|
|
37
58
|
/**
|
|
38
|
-
* Input for
|
|
39
|
-
*
|
|
59
|
+
* Input for refining an existing draft belief.
|
|
60
|
+
*
|
|
61
|
+
* Use `text` as the canonical belief statement.
|
|
62
|
+
* `canonicalText` remains available as a legacy alias for backwards compatibility.
|
|
40
63
|
*/
|
|
41
|
-
type
|
|
42
|
-
|
|
43
|
-
|
|
64
|
+
type RefineBeliefInput = {
|
|
65
|
+
/** Preferred belief statement alias. */
|
|
66
|
+
text?: string;
|
|
67
|
+
/** @deprecated Use text. */
|
|
68
|
+
canonicalText?: string;
|
|
69
|
+
rationale?: string;
|
|
70
|
+
title?: string;
|
|
71
|
+
};
|
|
72
|
+
type BeliefConfidenceTrigger = "evidence_added" | "evidence_removed" | "contradiction_detected" | "contradiction_resolved" | "agent_assessment" | "worktree_outcome" | "worktree_completed" | "fusion" | "discount" | "deduction";
|
|
73
|
+
type ModulateConfidenceInputBase = {
|
|
74
|
+
trigger: BeliefConfidenceTrigger;
|
|
44
75
|
rationale: string;
|
|
45
|
-
|
|
76
|
+
triggeringEvidenceId?: string;
|
|
77
|
+
triggeringQuestionId?: string;
|
|
78
|
+
triggeringAnswerId?: string;
|
|
79
|
+
triggeringContradictionId?: string;
|
|
80
|
+
triggeringWorktreeId?: string;
|
|
81
|
+
maxInlinePropagationTargets?: number;
|
|
46
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* Record an append-only confidence change using an explicit subjective-logic
|
|
85
|
+
* opinion tuple.
|
|
86
|
+
*/
|
|
87
|
+
type ModulateConfidenceOpinionInput = ModulateConfidenceInputBase & {
|
|
88
|
+
opinion: Opinion;
|
|
89
|
+
};
|
|
90
|
+
type ModulateConfidenceInput = ModulateConfidenceOpinionInput;
|
|
47
91
|
/**
|
|
48
92
|
* Input for forking a scored belief into a new formulation.
|
|
49
93
|
* Scored beliefs are immutable — fork to evolve understanding.
|
|
@@ -114,17 +158,37 @@ type ReassignBeliefsTopicInput = {
|
|
|
114
158
|
* Create the beliefs client for belief lifecycle operations.
|
|
115
159
|
*
|
|
116
160
|
* @param config - Gateway transport configuration.
|
|
117
|
-
* @returns An object with `createBelief`, `modulateConfidence`, and `forkBelief` methods.
|
|
161
|
+
* @returns An object with `createBelief`, `refineBelief`, `modulateConfidence`, and `forkBelief` methods.
|
|
118
162
|
*/
|
|
119
163
|
declare function createBeliefsClient(config?: BeliefsClientConfig): {
|
|
120
164
|
/**
|
|
121
165
|
* Create a belief within a topic scope.
|
|
122
166
|
*/
|
|
123
167
|
createBelief(input: CreateBeliefInput, idempotencyKey?: string): Promise<PlatformGatewaySuccess<PlatformBeliefRecord>>;
|
|
168
|
+
/**
|
|
169
|
+
* Refine a draft belief in place.
|
|
170
|
+
*/
|
|
171
|
+
refineBelief(beliefId: string, input: RefineBeliefInput, idempotencyKey?: string): Promise<PlatformGatewaySuccess<PlatformBeliefRecord>>;
|
|
124
172
|
/**
|
|
125
173
|
* Record a confidence change for an existing belief.
|
|
126
174
|
*/
|
|
127
|
-
modulateConfidence(beliefId: string, input:
|
|
175
|
+
modulateConfidence: (beliefId: string, input: ModulateConfidenceOpinionInput, idempotencyKey?: string) => Promise<PlatformGatewaySuccess<ModulateConfidenceResponse>>;
|
|
176
|
+
/**
|
|
177
|
+
* Returns the belief's confidence trajectory as a chronological array.
|
|
178
|
+
*
|
|
179
|
+
* Canonical UI trend shape (what every trend component consumes):
|
|
180
|
+
* { t: number, b: number, d: number, u: number, a: number, P: number, trigger: string, triggeringRef?: { kind: "evidence" | "worktree"; id: string } }[]
|
|
181
|
+
*
|
|
182
|
+
* Where:
|
|
183
|
+
* t = assessedAt (epoch ms)
|
|
184
|
+
* b, d, u, a = Opinion 4-tuple components
|
|
185
|
+
* P = projected probability = b + a*u (precomputed for UI convenience)
|
|
186
|
+
* trigger = cause of the score change
|
|
187
|
+
* triggeringRef = optional pointer to the evidence or worktree that drove the change
|
|
188
|
+
*/
|
|
189
|
+
getOpinionHistory(beliefId: string): Promise<OpinionHistoryEntry[]>;
|
|
190
|
+
/** @deprecated Use getOpinionHistory(). */
|
|
191
|
+
getConfidenceHistory(beliefId: string): Promise<OpinionHistoryEntry[]>;
|
|
128
192
|
/**
|
|
129
193
|
* Fork a scored belief into a new formulation.
|
|
130
194
|
*/
|
|
@@ -159,4 +223,4 @@ declare function createBeliefsClient(config?: BeliefsClientConfig): {
|
|
|
159
223
|
reassignBeliefsTopic(input: ReassignBeliefsTopicInput, idempotencyKey?: string): Promise<PlatformGatewaySuccess<Record<string, unknown>>>;
|
|
160
224
|
};
|
|
161
225
|
|
|
162
|
-
export { type BatchUpdateBeliefCriticalityInput, type BeliefsClientConfig, type CreateBeliefInput, type ForkBeliefInput, ForkBeliefResponse, type LinkBeliefsInput, type ModulateConfidenceInput, ModulateConfidenceResponse, PlatformGatewaySuccess, type ReassignBeliefsTopicInput, type UnlinkBeliefEvidenceInput, type UpdateBeliefCriticalityInput, type UpdateBeliefRationaleInput, type UpdateBeliefStatusInput, createBeliefsClient };
|
|
226
|
+
export { type BatchUpdateBeliefCriticalityInput, type BeliefsClientConfig, type CreateBeliefInput, type ForkBeliefInput, ForkBeliefResponse, type LinkBeliefsInput, type ModulateConfidenceInput, type ModulateConfidenceOpinionInput, ModulateConfidenceResponse, Opinion, type OpinionHistoryEntry, PlatformGatewaySuccess, type ReassignBeliefsTopicInput, type RefineBeliefInput, type UnlinkBeliefEvidenceInput, type UpdateBeliefCriticalityInput, type UpdateBeliefRationaleInput, type UpdateBeliefStatusInput, createBeliefsClient, mapOpinionHistoryEntriesFromGatewayData };
|
package/dist/beliefsClient.js
CHANGED
|
@@ -356,31 +356,163 @@ function normalizeNodeWriteInput(value) {
|
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
// src/beliefsClient.ts
|
|
359
|
+
function asRecord(value) {
|
|
360
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
361
|
+
}
|
|
362
|
+
function readString(value) {
|
|
363
|
+
if (typeof value !== "string") {
|
|
364
|
+
return void 0;
|
|
365
|
+
}
|
|
366
|
+
const normalized = value.trim();
|
|
367
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
368
|
+
}
|
|
369
|
+
function readNumber(value) {
|
|
370
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
371
|
+
}
|
|
372
|
+
function clamp01(value) {
|
|
373
|
+
return Math.max(0, Math.min(1, value));
|
|
374
|
+
}
|
|
375
|
+
function normalizeOpinionTuple(record) {
|
|
376
|
+
const opinion = asRecord(record.opinion);
|
|
377
|
+
const rawBelief = readNumber(opinion.b) ?? readNumber(record.belief);
|
|
378
|
+
const rawDisbelief = readNumber(opinion.d) ?? readNumber(record.disbelief);
|
|
379
|
+
const rawUncertainty = readNumber(opinion.u) ?? readNumber(record.uncertainty);
|
|
380
|
+
const rawBaseRate = readNumber(opinion.a) ?? readNumber(record.baseRate);
|
|
381
|
+
if (rawBelief === void 0 || rawDisbelief === void 0 || rawUncertainty === void 0 || rawBaseRate === void 0) {
|
|
382
|
+
throw new Error(
|
|
383
|
+
"Gateway opinion history entries must include belief, disbelief, uncertainty, and baseRate."
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
return {
|
|
387
|
+
b: clamp01(rawBelief),
|
|
388
|
+
d: clamp01(rawDisbelief),
|
|
389
|
+
u: clamp01(rawUncertainty),
|
|
390
|
+
a: clamp01(rawBaseRate)
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
function mapOpinionHistoryEntriesFromGatewayData(payload) {
|
|
394
|
+
const entries = Array.isArray(payload.entries) ? payload.entries : [];
|
|
395
|
+
return entries.map((value) => {
|
|
396
|
+
const record = asRecord(value);
|
|
397
|
+
const tuple = normalizeOpinionTuple(record);
|
|
398
|
+
const projected = readNumber(record.confidence) ?? clamp01(tuple.b + tuple.a * tuple.u);
|
|
399
|
+
const triggeringEvidenceId = readString(record.triggeringEvidenceId);
|
|
400
|
+
const triggeringQuestionId = readString(record.triggeringQuestionId);
|
|
401
|
+
const triggeringAnswerId = readString(record.triggeringAnswerId);
|
|
402
|
+
const triggeringContradictionId = readString(
|
|
403
|
+
record.triggeringContradictionId
|
|
404
|
+
);
|
|
405
|
+
const triggeringWorktreeId = readString(record.triggeringWorktreeId);
|
|
406
|
+
const triggeringRef = triggeringEvidenceId ? { kind: "evidence", id: triggeringEvidenceId } : triggeringQuestionId ? { kind: "question", id: triggeringQuestionId } : triggeringAnswerId ? { kind: "answer", id: triggeringAnswerId } : triggeringContradictionId ? { kind: "contradiction", id: triggeringContradictionId } : triggeringWorktreeId ? { kind: "worktree", id: triggeringWorktreeId } : void 0;
|
|
407
|
+
const trigger = readString(record.trigger);
|
|
408
|
+
if (!trigger) {
|
|
409
|
+
throw new Error("Gateway opinion history entries must include trigger.");
|
|
410
|
+
}
|
|
411
|
+
return {
|
|
412
|
+
t: readNumber(record.timestamp) ?? readNumber(record.assessedAt) ?? 0,
|
|
413
|
+
b: tuple.b,
|
|
414
|
+
d: tuple.d,
|
|
415
|
+
u: tuple.u,
|
|
416
|
+
a: tuple.a,
|
|
417
|
+
P: clamp01(projected),
|
|
418
|
+
trigger,
|
|
419
|
+
...triggeringRef ? { triggeringRef } : {},
|
|
420
|
+
...readString(record.rationale) ? { rationale: readString(record.rationale) } : {},
|
|
421
|
+
...readString(record.userId) ? { userId: readString(record.userId) } : {},
|
|
422
|
+
...readString(record.slOperator) ? { slOperator: readString(record.slOperator) } : {}
|
|
423
|
+
};
|
|
424
|
+
}).sort((left, right) => left.t - right.t);
|
|
425
|
+
}
|
|
426
|
+
function normalizeModulateConfidenceInput(input) {
|
|
427
|
+
const opinion = input.opinion;
|
|
428
|
+
return {
|
|
429
|
+
belief: opinion.b,
|
|
430
|
+
disbelief: opinion.d,
|
|
431
|
+
uncertainty: opinion.u,
|
|
432
|
+
baseRate: opinion.a,
|
|
433
|
+
trigger: input.trigger,
|
|
434
|
+
rationale: input.rationale,
|
|
435
|
+
triggeringEvidenceId: input.triggeringEvidenceId,
|
|
436
|
+
triggeringQuestionId: input.triggeringQuestionId,
|
|
437
|
+
triggeringAnswerId: input.triggeringAnswerId,
|
|
438
|
+
triggeringContradictionId: input.triggeringContradictionId,
|
|
439
|
+
triggeringWorktreeId: input.triggeringWorktreeId,
|
|
440
|
+
maxInlinePropagationTargets: input.maxInlinePropagationTargets
|
|
441
|
+
};
|
|
442
|
+
}
|
|
359
443
|
function createBeliefsClient(config = {}) {
|
|
360
444
|
const gateway = createGatewayRequestClient(config);
|
|
445
|
+
function normalizeBaseRate(value) {
|
|
446
|
+
const baseRate = readNumber(value);
|
|
447
|
+
const normalized = baseRate ?? 0.5;
|
|
448
|
+
if (normalized < 0 || normalized > 1) {
|
|
449
|
+
throw new Error("baseRate must be within [0, 1].");
|
|
450
|
+
}
|
|
451
|
+
return normalized;
|
|
452
|
+
}
|
|
453
|
+
const modulateConfidence = async (beliefId, input, idempotencyKey) => gateway.request({
|
|
454
|
+
path: `/api/platform/v1/beliefs/${encodeURIComponent(beliefId)}/confidence`,
|
|
455
|
+
method: "POST",
|
|
456
|
+
body: normalizeModulateConfidenceInput(input),
|
|
457
|
+
idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
|
|
458
|
+
});
|
|
459
|
+
async function getOpinionHistory(beliefId) {
|
|
460
|
+
const response = await gateway.request({
|
|
461
|
+
path: `/api/platform/v1/beliefs/${encodeURIComponent(beliefId)}/confidence-history`
|
|
462
|
+
});
|
|
463
|
+
return mapOpinionHistoryEntriesFromGatewayData(response.data);
|
|
464
|
+
}
|
|
361
465
|
return {
|
|
362
466
|
/**
|
|
363
467
|
* Create a belief within a topic scope.
|
|
364
468
|
*/
|
|
365
469
|
async createBelief(input, idempotencyKey) {
|
|
470
|
+
const baseRate = normalizeBaseRate(input.baseRate);
|
|
366
471
|
return gateway.request({
|
|
367
472
|
path: "/api/platform/v1/beliefs",
|
|
368
473
|
method: "POST",
|
|
369
|
-
body:
|
|
474
|
+
body: {
|
|
475
|
+
...normalizeNodeWriteInput(input),
|
|
476
|
+
baseRate
|
|
477
|
+
},
|
|
370
478
|
idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
|
|
371
479
|
});
|
|
372
480
|
},
|
|
373
481
|
/**
|
|
374
|
-
*
|
|
482
|
+
* Refine a draft belief in place.
|
|
375
483
|
*/
|
|
376
|
-
async
|
|
484
|
+
async refineBelief(beliefId, input, idempotencyKey) {
|
|
377
485
|
return gateway.request({
|
|
378
|
-
path: `/api/platform/v1/beliefs/${encodeURIComponent(beliefId)}
|
|
379
|
-
method: "
|
|
380
|
-
body: input,
|
|
486
|
+
path: `/api/platform/v1/beliefs/${encodeURIComponent(beliefId)}`,
|
|
487
|
+
method: "PATCH",
|
|
488
|
+
body: normalizeNodeWriteInput(input),
|
|
381
489
|
idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
|
|
382
490
|
});
|
|
383
491
|
},
|
|
492
|
+
/**
|
|
493
|
+
* Record a confidence change for an existing belief.
|
|
494
|
+
*/
|
|
495
|
+
modulateConfidence,
|
|
496
|
+
/**
|
|
497
|
+
* Returns the belief's confidence trajectory as a chronological array.
|
|
498
|
+
*
|
|
499
|
+
* Canonical UI trend shape (what every trend component consumes):
|
|
500
|
+
* { t: number, b: number, d: number, u: number, a: number, P: number, trigger: string, triggeringRef?: { kind: "evidence" | "worktree"; id: string } }[]
|
|
501
|
+
*
|
|
502
|
+
* Where:
|
|
503
|
+
* t = assessedAt (epoch ms)
|
|
504
|
+
* b, d, u, a = Opinion 4-tuple components
|
|
505
|
+
* P = projected probability = b + a*u (precomputed for UI convenience)
|
|
506
|
+
* trigger = cause of the score change
|
|
507
|
+
* triggeringRef = optional pointer to the evidence or worktree that drove the change
|
|
508
|
+
*/
|
|
509
|
+
async getOpinionHistory(beliefId) {
|
|
510
|
+
return getOpinionHistory(beliefId);
|
|
511
|
+
},
|
|
512
|
+
/** @deprecated Use getOpinionHistory(). */
|
|
513
|
+
async getConfidenceHistory(beliefId) {
|
|
514
|
+
return getOpinionHistory(beliefId);
|
|
515
|
+
},
|
|
384
516
|
/**
|
|
385
517
|
* Fork a scored belief into a new formulation.
|
|
386
518
|
*/
|
|
@@ -472,6 +604,6 @@ function createBeliefsClient(config = {}) {
|
|
|
472
604
|
};
|
|
473
605
|
}
|
|
474
606
|
|
|
475
|
-
export { LucernApiError, createBeliefsClient };
|
|
607
|
+
export { LucernApiError, createBeliefsClient, mapOpinionHistoryEntriesFromGatewayData };
|
|
476
608
|
//# sourceMappingURL=beliefsClient.js.map
|
|
477
609
|
//# sourceMappingURL=beliefsClient.js.map
|