@lucern/sdk 0.2.0-alpha.9 → 0.3.0-alpha.0
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 +6 -0
- 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 +6694 -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 +91 -12
- package/dist/beliefsClient.js +176 -7
- package/dist/beliefsClient.js.map +1 -1
- package/dist/client-DAuKnDlx.d.ts +2547 -0
- package/dist/client.d.ts +31 -2377
- package/dist/client.js +783 -245
- 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 +118 -4282
- 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/contradictions/index.d.ts +156 -0
- package/dist/contradictions/index.js +6688 -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 +6690 -0
- package/dist/decisions/index.js.map +1 -0
- package/dist/edges/index.d.ts +202 -0
- package/dist/edges/index.js +6689 -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 +293 -0
- package/dist/evidence/index.js +6689 -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 +8 -10
- package/dist/gatewayFacades.js +54 -1
- 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 +1092 -3294
- package/dist/index.js.map +1 -1
- package/dist/lenses/index.d.ts +192 -0
- package/dist/lenses/index.js +6688 -0
- package/dist/lenses/index.js.map +1 -0
- package/dist/nodes/index.d.ts +61 -0
- package/dist/nodes/index.js +6690 -0
- package/dist/nodes/index.js.map +1 -0
- package/dist/ontologies/index.d.ts +179 -0
- package/dist/ontologies/index.js +6691 -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 +6691 -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 +6689 -0
- package/dist/topics/index.js.map +1 -0
- package/dist/types.d.ts +20 -1
- package/dist/worktrees/index.d.ts +208 -0
- package/dist/worktrees/index.js +6691 -0
- package/dist/worktrees/index.js.map +1 -0
- package/package.json +55 -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":"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","file":"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" | "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 but must carry a prior via `baseRate`, which is
|
|
36
|
+
* stored as the vacuous opinion `(0, 0, 1, a)` at creation time.
|
|
17
37
|
*/
|
|
18
38
|
type CreateBeliefInput = {
|
|
19
39
|
topicId?: string;
|
|
@@ -30,20 +50,56 @@ 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" | "manual" | "decay" | "agent_assessment" | "worktree_outcome" | "worktree_completed" | "fusion" | "discount" | "deduction";
|
|
73
|
+
type ModulateConfidenceInputBase = {
|
|
74
|
+
trigger?: BeliefConfidenceTrigger;
|
|
44
75
|
rationale: string;
|
|
45
|
-
|
|
76
|
+
maxInlinePropagationTargets?: number;
|
|
46
77
|
};
|
|
78
|
+
/**
|
|
79
|
+
* Record an append-only confidence change using an explicit subjective-logic
|
|
80
|
+
* opinion tuple.
|
|
81
|
+
*/
|
|
82
|
+
type ModulateConfidenceOpinionInput = ModulateConfidenceInputBase & {
|
|
83
|
+
opinion: Opinion;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* @deprecated Prefer passing `opinion` directly or call an `opinionFrom*`
|
|
87
|
+
* helper before invoking `modulateConfidence`.
|
|
88
|
+
*/
|
|
89
|
+
type ModulateConfidenceScalarInput = (ModulateConfidenceInputBase & {
|
|
90
|
+
confidence: number;
|
|
91
|
+
interpretation: "base_rate";
|
|
92
|
+
}) | (ModulateConfidenceInputBase & {
|
|
93
|
+
confidence: number;
|
|
94
|
+
interpretation: "dogmatic";
|
|
95
|
+
baseRate?: number;
|
|
96
|
+
}) | (ModulateConfidenceInputBase & {
|
|
97
|
+
confidence: number;
|
|
98
|
+
interpretation: "projected";
|
|
99
|
+
uncertainty: number;
|
|
100
|
+
baseRate?: number;
|
|
101
|
+
});
|
|
102
|
+
type ModulateConfidenceInput = ModulateConfidenceOpinionInput | ModulateConfidenceScalarInput;
|
|
47
103
|
/**
|
|
48
104
|
* Input for forking a scored belief into a new formulation.
|
|
49
105
|
* Scored beliefs are immutable — fork to evolve understanding.
|
|
@@ -114,17 +170,40 @@ type ReassignBeliefsTopicInput = {
|
|
|
114
170
|
* Create the beliefs client for belief lifecycle operations.
|
|
115
171
|
*
|
|
116
172
|
* @param config - Gateway transport configuration.
|
|
117
|
-
* @returns An object with `createBelief`, `modulateConfidence`, and `forkBelief` methods.
|
|
173
|
+
* @returns An object with `createBelief`, `refineBelief`, `modulateConfidence`, and `forkBelief` methods.
|
|
118
174
|
*/
|
|
119
175
|
declare function createBeliefsClient(config?: BeliefsClientConfig): {
|
|
120
176
|
/**
|
|
121
177
|
* Create a belief within a topic scope.
|
|
122
178
|
*/
|
|
123
179
|
createBelief(input: CreateBeliefInput, idempotencyKey?: string): Promise<PlatformGatewaySuccess<PlatformBeliefRecord>>;
|
|
180
|
+
/**
|
|
181
|
+
* Refine a draft belief in place.
|
|
182
|
+
*/
|
|
183
|
+
refineBelief(beliefId: string, input: RefineBeliefInput, idempotencyKey?: string): Promise<PlatformGatewaySuccess<PlatformBeliefRecord>>;
|
|
124
184
|
/**
|
|
125
185
|
* Record a confidence change for an existing belief.
|
|
126
186
|
*/
|
|
127
|
-
modulateConfidence
|
|
187
|
+
modulateConfidence: {
|
|
188
|
+
(beliefId: string, input: ModulateConfidenceOpinionInput, idempotencyKey?: string): Promise<PlatformGatewaySuccess<ModulateConfidenceResponse>>;
|
|
189
|
+
(beliefId: string, input: ModulateConfidenceScalarInput, idempotencyKey?: string): Promise<PlatformGatewaySuccess<ModulateConfidenceResponse>>;
|
|
190
|
+
};
|
|
191
|
+
/**
|
|
192
|
+
* Returns the belief's confidence trajectory as a chronological array.
|
|
193
|
+
*
|
|
194
|
+
* Canonical UI trend shape (what every trend component consumes):
|
|
195
|
+
* { t: number, b: number, d: number, u: number, a: number, P: number, trigger: string, triggeringRef?: { kind: "evidence" | "worktree"; id: string } }[]
|
|
196
|
+
*
|
|
197
|
+
* Where:
|
|
198
|
+
* t = assessedAt (epoch ms)
|
|
199
|
+
* b, d, u, a = Opinion 4-tuple components
|
|
200
|
+
* P = projected probability = b + a*u (precomputed for UI convenience)
|
|
201
|
+
* trigger = cause of the score change
|
|
202
|
+
* triggeringRef = optional pointer to the evidence or worktree that drove the change
|
|
203
|
+
*/
|
|
204
|
+
getOpinionHistory(beliefId: string): Promise<OpinionHistoryEntry[]>;
|
|
205
|
+
/** @deprecated Use getOpinionHistory(). */
|
|
206
|
+
getConfidenceHistory(beliefId: string): Promise<OpinionHistoryEntry[]>;
|
|
128
207
|
/**
|
|
129
208
|
* Fork a scored belief into a new formulation.
|
|
130
209
|
*/
|
|
@@ -159,4 +238,4 @@ declare function createBeliefsClient(config?: BeliefsClientConfig): {
|
|
|
159
238
|
reassignBeliefsTopic(input: ReassignBeliefsTopicInput, idempotencyKey?: string): Promise<PlatformGatewaySuccess<Record<string, unknown>>>;
|
|
160
239
|
};
|
|
161
240
|
|
|
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 };
|
|
241
|
+
export { type BatchUpdateBeliefCriticalityInput, type BeliefsClientConfig, type CreateBeliefInput, type ForkBeliefInput, ForkBeliefResponse, type LinkBeliefsInput, type ModulateConfidenceInput, type ModulateConfidenceOpinionInput, ModulateConfidenceResponse, type ModulateConfidenceScalarInput, Opinion, type OpinionHistoryEntry, PlatformGatewaySuccess, type ReassignBeliefsTopicInput, type RefineBeliefInput, type UnlinkBeliefEvidenceInput, type UpdateBeliefCriticalityInput, type UpdateBeliefRationaleInput, type UpdateBeliefStatusInput, createBeliefsClient, mapOpinionHistoryEntriesFromGatewayData };
|
package/dist/beliefsClient.js
CHANGED
|
@@ -314,6 +314,38 @@ function createGatewayRequestClient(config = {}) {
|
|
|
314
314
|
};
|
|
315
315
|
}
|
|
316
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
|
+
|
|
317
349
|
// src/sdkSurface.ts
|
|
318
350
|
function cleanString(value) {
|
|
319
351
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
@@ -356,31 +388,168 @@ function normalizeNodeWriteInput(value) {
|
|
|
356
388
|
}
|
|
357
389
|
|
|
358
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
|
+
}
|
|
359
478
|
function createBeliefsClient(config = {}) {
|
|
360
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
|
+
}
|
|
361
502
|
return {
|
|
362
503
|
/**
|
|
363
504
|
* Create a belief within a topic scope.
|
|
364
505
|
*/
|
|
365
506
|
async createBelief(input, idempotencyKey) {
|
|
507
|
+
const baseRate = requireBaseRate(input.baseRate);
|
|
366
508
|
return gateway.request({
|
|
367
509
|
path: "/api/platform/v1/beliefs",
|
|
368
510
|
method: "POST",
|
|
369
|
-
body:
|
|
511
|
+
body: {
|
|
512
|
+
...normalizeNodeWriteInput(input),
|
|
513
|
+
baseRate
|
|
514
|
+
},
|
|
370
515
|
idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
|
|
371
516
|
});
|
|
372
517
|
},
|
|
373
518
|
/**
|
|
374
|
-
*
|
|
519
|
+
* Refine a draft belief in place.
|
|
375
520
|
*/
|
|
376
|
-
async
|
|
521
|
+
async refineBelief(beliefId, input, idempotencyKey) {
|
|
377
522
|
return gateway.request({
|
|
378
|
-
path: `/api/platform/v1/beliefs/${encodeURIComponent(beliefId)}
|
|
379
|
-
method: "
|
|
380
|
-
body: input,
|
|
523
|
+
path: `/api/platform/v1/beliefs/${encodeURIComponent(beliefId)}`,
|
|
524
|
+
method: "PATCH",
|
|
525
|
+
body: normalizeNodeWriteInput(input),
|
|
381
526
|
idempotencyKey: idempotencyKey ?? randomIdempotencyKey()
|
|
382
527
|
});
|
|
383
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
|
+
},
|
|
384
553
|
/**
|
|
385
554
|
* Fork a scored belief into a new formulation.
|
|
386
555
|
*/
|
|
@@ -472,6 +641,6 @@ function createBeliefsClient(config = {}) {
|
|
|
472
641
|
};
|
|
473
642
|
}
|
|
474
643
|
|
|
475
|
-
export { LucernApiError, createBeliefsClient };
|
|
644
|
+
export { LucernApiError, createBeliefsClient, mapOpinionHistoryEntriesFromGatewayData };
|
|
476
645
|
//# sourceMappingURL=beliefsClient.js.map
|
|
477
646
|
//# sourceMappingURL=beliefsClient.js.map
|