@lucern/sdk 0.3.0-alpha.1 → 0.3.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 +3 -0
- package/README.md +51 -4
- package/dist/accessControl.d.ts +78 -0
- package/dist/accessControl.js +1118 -0
- package/dist/accessControl.js.map +1 -0
- package/dist/adminClient.d.ts +10 -8
- package/dist/adminClient.js +242 -39
- package/dist/adminClient.js.map +1 -1
- package/dist/answersClient.d.ts +2 -0
- package/dist/answersClient.js +221 -11
- package/dist/answersClient.js.map +1 -1
- package/dist/audience/index.d.ts +2 -1
- package/dist/audience/index.js +1 -3
- package/dist/audience/index.js.map +1 -1
- package/dist/audiencesClient.d.ts +18 -16
- package/dist/audiencesClient.js +297 -90
- package/dist/audiencesClient.js.map +1 -1
- package/dist/auditClient.d.ts +2 -0
- package/dist/auditClient.js +227 -15
- package/dist/auditClient.js.map +1 -1
- package/dist/authContext.d.ts +56 -0
- package/dist/authContext.js +170 -0
- package/dist/authContext.js.map +1 -0
- package/dist/authDeviceClient.d.ts +49 -0
- package/dist/authDeviceClient.js +121 -0
- package/dist/authDeviceClient.js.map +1 -0
- package/dist/beliefs/index.d.ts +26 -5
- package/dist/beliefs/index.js +3625 -1140
- package/dist/beliefs/index.js.map +1 -1
- package/dist/beliefsClient.d.ts +4 -2
- package/dist/beliefsClient.js +230 -26
- package/dist/beliefsClient.js.map +1 -1
- package/dist/boundaryClientSurface.d.ts +20 -0
- package/dist/boundaryClientSurface.js +73 -0
- package/dist/boundaryClientSurface.js.map +1 -0
- package/dist/client.d.ts +2988 -27
- package/dist/client.js +3625 -1140
- package/dist/client.js.map +1 -1
- package/dist/clientHelpers.d.ts +48 -0
- package/dist/clientHelpers.js +137 -0
- package/dist/clientHelpers.js.map +1 -0
- package/dist/contextClient.d.ts +6 -3
- package/dist/contextClient.js +252 -30
- package/dist/contextClient.js.map +1 -1
- package/dist/contextFacade.js +25 -16
- package/dist/contextFacade.js.map +1 -1
- package/dist/contextPackCompiler.js +19 -30
- package/dist/contextPackCompiler.js.map +1 -1
- package/dist/contextPackPolicy.js +7 -17
- package/dist/contextPackPolicy.js.map +1 -1
- package/dist/contextTypes.d.ts +2 -0
- package/dist/contracts/api-enums.contract.d.ts +2 -2
- package/dist/contracts/api-enums.contract.js +6 -1
- package/dist/contracts/api-enums.contract.js.map +1 -1
- package/dist/contracts/index.d.ts +1 -0
- package/dist/contracts/index.js +120 -5
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/lens-filter.contract.js +4 -3
- package/dist/contracts/lens-filter.contract.js.map +1 -1
- package/dist/contracts/lens-workflow.contract.js +4 -3
- package/dist/contracts/lens-workflow.contract.js.map +1 -1
- package/dist/contracts/lensFilter.js +4 -3
- package/dist/contracts/lensFilter.js.map +1 -1
- package/dist/contracts/lensWorkflow.js +4 -3
- package/dist/contracts/lensWorkflow.js.map +1 -1
- package/dist/contracts/mcpTools.d.ts +46 -1
- package/dist/contracts/mcpTools.js +108 -0
- package/dist/contracts/mcpTools.js.map +1 -1
- package/dist/contradictions/index.d.ts +25 -4
- package/dist/contradictions/index.js +3625 -1140
- package/dist/contradictions/index.js.map +1 -1
- package/dist/coreClient.d.ts +11 -1
- package/dist/coreClient.js +222 -14
- package/dist/coreClient.js.map +1 -1
- package/dist/decisions/index.d.ts +35 -14
- package/dist/decisions/index.js +3625 -1140
- package/dist/decisions/index.js.map +1 -1
- package/dist/decisionsClient.d.ts +6 -12
- package/dist/decisionsClient.js +235 -37
- package/dist/decisionsClient.js.map +1 -1
- package/dist/edges/index.d.ts +48 -87
- package/dist/edges/index.js +3625 -1140
- package/dist/edges/index.js.map +1 -1
- package/dist/embeddingsClient.d.ts +106 -0
- package/dist/embeddingsClient.js +731 -0
- package/dist/embeddingsClient.js.map +1 -0
- package/dist/eventingClient.d.ts +96 -0
- package/dist/eventingClient.js +728 -0
- package/dist/eventingClient.js.map +1 -0
- package/dist/events.js +6 -3
- package/dist/events.js.map +1 -1
- package/dist/eventsCore.d.ts +3 -1
- package/dist/eventsCore.js +222 -14
- package/dist/eventsCore.js.map +1 -1
- package/dist/evidence/index.d.ts +25 -4
- package/dist/evidence/index.js +3625 -1140
- package/dist/evidence/index.js.map +1 -1
- package/dist/evidenceClient.d.ts +2 -0
- package/dist/evidenceClient.js +222 -14
- package/dist/evidenceClient.js.map +1 -1
- package/dist/facade/context.d.ts +2 -1
- package/dist/facade/context.js +25 -16
- package/dist/facade/context.js.map +1 -1
- package/dist/functionSurface.d.ts +143 -0
- package/dist/functionSurface.js +1204 -0
- package/dist/functionSurface.js.map +1 -0
- package/dist/functionSurfaceClient.d.ts +8 -0
- package/dist/functionSurfaceClient.js +1204 -0
- package/dist/functionSurfaceClient.js.map +1 -0
- package/dist/gatewayFacades.d.ts +64 -46
- package/dist/gatewayFacades.js +461 -128
- package/dist/gatewayFacades.js.map +1 -1
- package/dist/graphAnalysisClient.d.ts +192 -0
- package/dist/graphAnalysisClient.js +799 -0
- package/dist/graphAnalysisClient.js.map +1 -0
- package/dist/graphClient.d.ts +8 -13
- package/dist/graphClient.js +244 -45
- package/dist/graphClient.js.map +1 -1
- package/dist/graphIntel.d.ts +4 -0
- package/dist/graphIntel.js +3 -0
- package/dist/graphIntel.js.map +1 -0
- package/dist/graphIntelligence.d.ts +2 -0
- package/dist/graphIntelligence.js +47 -0
- package/dist/graphIntelligence.js.map +1 -0
- package/dist/graphRecommendationsClient.d.ts +56 -0
- package/dist/graphRecommendationsClient.js +664 -0
- package/dist/graphRecommendationsClient.js.map +1 -0
- package/dist/graphStateClassifierClient.d.ts +73 -0
- package/dist/graphStateClassifierClient.js +716 -0
- package/dist/graphStateClassifierClient.js.map +1 -0
- package/dist/harnessClient.d.ts +15 -24
- package/dist/harnessClient.js +235 -42
- package/dist/harnessClient.js.map +1 -1
- package/dist/identityClient.d.ts +97 -11
- package/dist/identityClient.js +409 -33
- package/dist/identityClient.js.map +1 -1
- package/dist/index.d.ts +30 -5
- package/dist/index.js +4272 -1225
- package/dist/index.js.map +1 -1
- package/dist/infisicalRuntime.d.ts +43 -0
- package/dist/infisicalRuntime.js +346 -0
- package/dist/infisicalRuntime.js.map +1 -0
- package/dist/jobsClient.d.ts +98 -0
- package/dist/jobsClient.js +726 -0
- package/dist/jobsClient.js.map +1 -0
- package/dist/learningClient.d.ts +8 -6
- package/dist/learningClient.js +252 -44
- package/dist/learningClient.js.map +1 -1
- package/dist/lenses/index.d.ts +77 -38
- package/dist/lenses/index.js +3625 -1140
- package/dist/lenses/index.js.map +1 -1
- package/dist/mcpClient.d.ts +28 -0
- package/dist/mcpClient.js +669 -0
- package/dist/mcpClient.js.map +1 -0
- package/dist/modelRuntimeClient.d.ts +72 -0
- package/dist/modelRuntimeClient.js +704 -0
- package/dist/modelRuntimeClient.js.map +1 -0
- package/dist/nodes/index.d.ts +64 -21
- package/dist/nodes/index.js +3625 -1140
- package/dist/nodes/index.js.map +1 -1
- package/dist/ontologies/index.d.ts +54 -32
- package/dist/ontologies/index.js +3625 -1140
- package/dist/ontologies/index.js.map +1 -1
- package/dist/ontologyClient.d.ts +19 -25
- package/dist/ontologyClient.js +258 -40
- package/dist/ontologyClient.js.map +1 -1
- package/dist/ontologyLinksClient.d.ts +71 -0
- package/dist/ontologyLinksClient.js +697 -0
- package/dist/ontologyLinksClient.js.map +1 -0
- package/dist/orgGraphSearchClient.d.ts +85 -0
- package/dist/orgGraphSearchClient.js +672 -0
- package/dist/orgGraphSearchClient.js.map +1 -0
- package/dist/packsClient.d.ts +11 -23
- package/dist/packsClient.js +234 -46
- package/dist/packsClient.js.map +1 -1
- package/dist/policyClient.d.ts +13 -10
- package/dist/policyClient.js +243 -25
- package/dist/policyClient.js.map +1 -1
- package/dist/questions/index.d.ts +25 -4
- package/dist/questions/index.js +3625 -1140
- package/dist/questions/index.js.map +1 -1
- package/dist/realtime/index.d.ts +1 -1
- package/dist/reportsClient.d.ts +9 -7
- package/dist/reportsClient.js +281 -53
- package/dist/reportsClient.js.map +1 -1
- package/dist/schemaClient.d.ts +5 -3
- package/dist/schemaClient.js +235 -29
- package/dist/schemaClient.js.map +1 -1
- package/dist/sdkSurface.d.ts +8 -3
- package/dist/sdkSurface.js +10 -6
- package/dist/sdkSurface.js.map +1 -1
- package/dist/secrets.d.ts +1 -0
- package/dist/secrets.js +3 -0
- package/dist/secrets.js.map +1 -0
- package/dist/sourcesClient.d.ts +2 -0
- package/dist/sourcesClient.js +222 -14
- package/dist/sourcesClient.js.map +1 -1
- package/dist/telemetryClient.d.ts +94 -0
- package/dist/telemetryClient.js +741 -0
- package/dist/telemetryClient.js.map +1 -0
- package/dist/toolRegistryClient.d.ts +115 -0
- package/dist/toolRegistryClient.js +767 -0
- package/dist/toolRegistryClient.js.map +1 -0
- package/dist/topics/index.d.ts +36 -9
- package/dist/topics/index.js +3627 -1140
- package/dist/topics/index.js.map +1 -1
- package/dist/topicsClient.d.ts +4 -0
- package/dist/topicsClient.js +237 -24
- package/dist/topicsClient.js.map +1 -1
- package/dist/types.d.ts +5 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/dist/workflowClient.d.ts +58 -40
- package/dist/workflowClient.js +243 -58
- package/dist/workflowClient.js.map +1 -1
- package/dist/worktrees/index.d.ts +70 -33
- package/dist/worktrees/index.js +3625 -1140
- package/dist/worktrees/index.js.map +1 -1
- package/package.json +13 -3
- package/dist/client-B6aWUUwp.d.ts +0 -2552
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { JsonObject, PlatformGraphEdge, PlatformGraphNode } from './types.js';
|
|
2
|
+
import './contracts/workflow-runtime.contract.js';
|
|
3
|
+
import './contracts/lens-workflow.contract.js';
|
|
4
|
+
import './contracts/lens-filter.contract.js';
|
|
5
|
+
|
|
6
|
+
type NodeLike = PlatformGraphNode;
|
|
7
|
+
type EdgeLike = PlatformGraphEdge;
|
|
8
|
+
type CustomToolInput = JsonObject;
|
|
9
|
+
type BeliefsRefineInput = string | {
|
|
10
|
+
text: string;
|
|
11
|
+
rationale?: string;
|
|
12
|
+
};
|
|
13
|
+
type BeliefsArchiveInput = {
|
|
14
|
+
reason?: string;
|
|
15
|
+
rationale?: string;
|
|
16
|
+
} | string;
|
|
17
|
+
declare function normalizeCustomNamespace(namespace: string): string;
|
|
18
|
+
declare function normalizeCustomToolPayload(input: unknown): CustomToolInput;
|
|
19
|
+
declare function resolveCustomToolFullName(name: string): string;
|
|
20
|
+
declare function buildBeliefsRefinePayload(textOrInput: BeliefsRefineInput, rationale?: string): {
|
|
21
|
+
text: string;
|
|
22
|
+
rationale?: string;
|
|
23
|
+
};
|
|
24
|
+
declare function buildBeliefsArchivePayload(input?: BeliefsArchiveInput): {
|
|
25
|
+
reason?: string;
|
|
26
|
+
} | undefined;
|
|
27
|
+
declare function asNodeArray(data: unknown): NodeLike[];
|
|
28
|
+
declare function asEdgeArray(data: unknown): EdgeLike[];
|
|
29
|
+
declare function requireTopicId(args: {
|
|
30
|
+
topicId?: string;
|
|
31
|
+
}): string;
|
|
32
|
+
declare function requireTopicOrProjectId(args: {
|
|
33
|
+
topicId?: string;
|
|
34
|
+
projectId?: string;
|
|
35
|
+
}): string;
|
|
36
|
+
declare function matchesAuditNodeReference(value: unknown, nodeId: string): boolean;
|
|
37
|
+
declare function requireText(args: {
|
|
38
|
+
text?: string;
|
|
39
|
+
canonicalText?: string;
|
|
40
|
+
formulation?: string;
|
|
41
|
+
newFormulation?: string;
|
|
42
|
+
}): string;
|
|
43
|
+
declare function requireBaseRate(args: {
|
|
44
|
+
baseRate?: number;
|
|
45
|
+
}): number;
|
|
46
|
+
declare function sdkQueryString(input: Record<string, unknown>): string;
|
|
47
|
+
|
|
48
|
+
export { type BeliefsArchiveInput, type BeliefsRefineInput, type CustomToolInput, type EdgeLike, type NodeLike, asEdgeArray, asNodeArray, buildBeliefsArchivePayload, buildBeliefsRefinePayload, matchesAuditNodeReference, normalizeCustomNamespace, normalizeCustomToolPayload, requireBaseRate, requireText, requireTopicId, requireTopicOrProjectId, resolveCustomToolFullName, sdkQueryString };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// src/sdkSurface.ts
|
|
2
|
+
function isRecord(value) {
|
|
3
|
+
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function asRecord(value) {
|
|
6
|
+
return isRecord(value) ? value : {};
|
|
7
|
+
}
|
|
8
|
+
function cleanString(value) {
|
|
9
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
10
|
+
}
|
|
11
|
+
function resolveTopicId(value) {
|
|
12
|
+
return cleanString(value.topicId);
|
|
13
|
+
}
|
|
14
|
+
function resolveText(value) {
|
|
15
|
+
return cleanString(value.text) ?? cleanString(value.canonicalText);
|
|
16
|
+
}
|
|
17
|
+
function asListItems(data, legacyKey) {
|
|
18
|
+
if (Array.isArray(data)) {
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
const record = asRecord(data);
|
|
22
|
+
if (Array.isArray(record.items)) {
|
|
23
|
+
return record.items;
|
|
24
|
+
}
|
|
25
|
+
if (legacyKey && Array.isArray(record[legacyKey])) {
|
|
26
|
+
return record[legacyKey];
|
|
27
|
+
}
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/clientHelpers.ts
|
|
32
|
+
function normalizeCustomNamespace(namespace) {
|
|
33
|
+
return namespace.trim() || "custom";
|
|
34
|
+
}
|
|
35
|
+
function normalizeCustomToolPayload(input) {
|
|
36
|
+
return input && typeof input === "object" && !Array.isArray(input) ? input : {};
|
|
37
|
+
}
|
|
38
|
+
function resolveCustomToolFullName(name) {
|
|
39
|
+
return name.includes(".") ? name : `custom.${name}`;
|
|
40
|
+
}
|
|
41
|
+
function buildBeliefsRefinePayload(textOrInput, rationale) {
|
|
42
|
+
return typeof textOrInput === "string" ? { text: textOrInput, rationale } : { text: textOrInput.text, rationale: textOrInput.rationale };
|
|
43
|
+
}
|
|
44
|
+
function buildBeliefsArchivePayload(input) {
|
|
45
|
+
return typeof input === "string" ? { reason: input } : input ? { reason: input.reason ?? input.rationale } : void 0;
|
|
46
|
+
}
|
|
47
|
+
function asNodeArray(data) {
|
|
48
|
+
const rows = asListItems(data, "nodes");
|
|
49
|
+
if (rows.length > 0) {
|
|
50
|
+
return rows.filter(
|
|
51
|
+
(value) => Boolean(value) && typeof value === "object"
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
if (data && typeof data === "object") {
|
|
55
|
+
return [data];
|
|
56
|
+
}
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
function asEdgeArray(data) {
|
|
60
|
+
const rows = asListItems(data, "edges");
|
|
61
|
+
if (rows.length > 0) {
|
|
62
|
+
return rows.filter(
|
|
63
|
+
(value) => Boolean(value) && typeof value === "object"
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
if (data && typeof data === "object") {
|
|
67
|
+
return [data];
|
|
68
|
+
}
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
function requireTopicId(args) {
|
|
72
|
+
const topicId = resolveTopicId(args);
|
|
73
|
+
if (!topicId) {
|
|
74
|
+
throw new Error("topicId is required");
|
|
75
|
+
}
|
|
76
|
+
return topicId;
|
|
77
|
+
}
|
|
78
|
+
function requireTopicOrProjectId(args) {
|
|
79
|
+
const topicId = args.topicId?.trim() || args.projectId?.trim() || void 0;
|
|
80
|
+
if (!topicId) {
|
|
81
|
+
throw new Error("topicId is required");
|
|
82
|
+
}
|
|
83
|
+
return topicId;
|
|
84
|
+
}
|
|
85
|
+
var AUDIT_NODE_REFERENCE_KEY_PATTERN = /(^|_)(id|nodeid|beliefid|resourceid|targetid|sourceid|subjectid|globalid|entityid|recordid|fromnodeid|tonodeid|linkednodeid|linkedbeliefid|nodeids|beliefids|resourceids)$/i;
|
|
86
|
+
function matchesAuditNodeReference(value, nodeId) {
|
|
87
|
+
if (Array.isArray(value)) {
|
|
88
|
+
return value.some((entry) => matchesAuditNodeReference(entry, nodeId));
|
|
89
|
+
}
|
|
90
|
+
if (!value || typeof value !== "object") {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return Object.entries(value).some(([key, entry]) => {
|
|
94
|
+
if (typeof entry === "string" && entry === nodeId && AUDIT_NODE_REFERENCE_KEY_PATTERN.test(key)) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
if (Array.isArray(entry) && AUDIT_NODE_REFERENCE_KEY_PATTERN.test(key) && entry.some((item) => item === nodeId)) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
return matchesAuditNodeReference(entry, nodeId);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function requireText(args) {
|
|
104
|
+
const text = resolveText(args);
|
|
105
|
+
if (!text) {
|
|
106
|
+
throw new Error("text is required");
|
|
107
|
+
}
|
|
108
|
+
return text;
|
|
109
|
+
}
|
|
110
|
+
function requireBaseRate(args) {
|
|
111
|
+
const baseRate = typeof args.baseRate === "number" && Number.isFinite(args.baseRate) ? args.baseRate : 0.5;
|
|
112
|
+
if (baseRate < 0 || baseRate > 1) {
|
|
113
|
+
throw new Error("baseRate must be within [0, 1].");
|
|
114
|
+
}
|
|
115
|
+
return baseRate;
|
|
116
|
+
}
|
|
117
|
+
function sdkQueryString(input) {
|
|
118
|
+
const params = new URLSearchParams();
|
|
119
|
+
for (const [key, value] of Object.entries(input)) {
|
|
120
|
+
if (value === void 0 || value === null) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (Array.isArray(value)) {
|
|
124
|
+
if (value.length > 0) {
|
|
125
|
+
params.set(key, value.join(","));
|
|
126
|
+
}
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
params.set(key, String(value));
|
|
130
|
+
}
|
|
131
|
+
const serialized = params.toString();
|
|
132
|
+
return serialized ? `?${serialized}` : "";
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export { asEdgeArray, asNodeArray, buildBeliefsArchivePayload, buildBeliefsRefinePayload, matchesAuditNodeReference, normalizeCustomNamespace, normalizeCustomToolPayload, requireBaseRate, requireText, requireTopicId, requireTopicOrProjectId, resolveCustomToolFullName, sdkQueryString };
|
|
136
|
+
//# sourceMappingURL=clientHelpers.js.map
|
|
137
|
+
//# sourceMappingURL=clientHelpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sdkSurface.ts","../src/clientHelpers.ts"],"names":[],"mappings":";AAcO,SAAS,SAAS,KAAA,EAAoC;AAC3D,EAAA,OAAO,OAAA,CAAQ,KAAK,CAAA,IAAK,OAAO,UAAU,QAAA,IAAY,CAAC,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA;AAC5E;AAEO,SAAS,SAAS,KAAA,EAA2B;AAClD,EAAA,OAAO,QAAA,CAAS,KAAK,CAAA,GAAI,KAAA,GAAQ,EAAC;AACpC;AAEA,SAAS,YAAY,KAAA,EAAoC;AACvD,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,CAAM,IAAA,GAAO,MAAA,GAAS,CAAA,GACtD,KAAA,CAAM,IAAA,EAAK,GACX,MAAA;AACN;AAuBO,SAAS,eAAe,KAAA,EAA6C;AAC1E,EAAA,OAAO,WAAA,CAAY,MAAM,OAAO,CAAA;AAClC;AAKO,SAAS,YAAY,KAAA,EAA4C;AACtE,EAAA,OAAO,YAAY,KAAA,CAAM,IAAI,CAAA,IAAK,WAAA,CAAY,MAAM,aAAa,CAAA;AACnE;AAuEO,SAAS,WAAA,CAAe,MAAe,SAAA,EAAyB;AACrE,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,IAAI,CAAA,EAAG;AACvB,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,MAAM,MAAA,GAAS,SAAS,IAAI,CAAA;AAC5B,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,MAAA,CAAO,KAAK,CAAA,EAAG;AAC/B,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AAA;AACT;AAEO,SAAS,eAAe,KAAA,EAAwC;AACrE,EAAA,MAAM,MAAA,GAAS,IAAI,eAAA,EAAgB;AACnC,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,IAAA,IAAI,KAAA,KAAU,MAAA,IAAa,KAAA,KAAU,IAAA,EAAM;AACzC,MAAA;AAAA,IACF;AACA,IAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACxB,MAAA,IAAI,KAAA,CAAM,SAAS,CAAA,EAAG;AACpB,QAAA,MAAA,CAAO,GAAA,CAAI,GAAA,EAAK,KAAA,CAAM,IAAA,CAAK,GAAG,CAAC,CAAA;AAAA,MACjC;AACA,MAAA;AAAA,IACF;AACA,IAAA,MAAA,CAAO,GAAA,CAAI,GAAA,EAAK,MAAA,CAAO,KAAK,CAAC,CAAA;AAAA,EAC/B;AACA,EAAA,MAAM,UAAA,GAAa,OAAO,QAAA,EAAS;AACnC,EAAA,OAAO,UAAA,GAAa,CAAA,CAAA,EAAI,UAAU,CAAA,CAAA,GAAK,EAAA;AACzC","file":"clientHelpers.js","sourcesContent":["import type { PlatformGatewaySuccess } from \"./coreClient\";\nimport type { JsonObject, ListResult } from \"./types\";\n\ntype TopicScopedValue = {\n topicId?: string;\n};\n\ntype TextScopedValue = {\n text?: string;\n canonicalText?: string;\n};\n\ntype AnyRecord = Record<string, unknown>;\n\nexport function isRecord(value: unknown): value is AnyRecord {\n return Boolean(value) && typeof value === \"object\" && !Array.isArray(value);\n}\n\nexport function asRecord(value: unknown): AnyRecord {\n return isRecord(value) ? value : {};\n}\n\nfunction cleanString(value: unknown): string | undefined {\n return typeof value === \"string\" && value.trim().length > 0\n ? value.trim()\n : undefined;\n}\n\nfunction normalizeVerificationStatus(value: unknown): string | undefined {\n const status = cleanString(value);\n if (!status) {\n return undefined;\n }\n if (status === \"verified\") {\n return \"human_verified\";\n }\n if (status === \"rejected\") {\n return \"contradicted\";\n }\n return status;\n}\n\nfunction cloneWith<T extends AnyRecord>(value: T, patch: AnyRecord): T {\n return { ...value, ...patch } as T;\n}\n\n/**\n * Resolve the canonical topic identifier.\n */\nexport function resolveTopicId(value: TopicScopedValue): string | undefined {\n return cleanString(value.topicId);\n}\n\n/**\n * Resolve the canonical text field from text-first or legacy canonicalText-first inputs.\n */\nexport function resolveText(value: TextScopedValue): string | undefined {\n return cleanString(value.text) ?? cleanString(value.canonicalText);\n}\n\n/**\n * Attach the topicId to a record.\n */\nexport function withTopicAlias<T extends AnyRecord>(value: T): T {\n const topicId = cleanString(value.topicId) ?? undefined;\n if (!topicId) {\n return value;\n }\n return cloneWith(value, { topicId });\n}\n\n/**\n * Attach the text/canonicalText alias pair to a record.\n */\nexport function withTextAlias<T extends AnyRecord>(value: T): T {\n const text =\n cleanString(value.text) ?? cleanString(value.canonicalText) ?? undefined;\n if (!text) {\n return value;\n }\n return cloneWith(value, { text, canonicalText: text });\n}\n\n/**\n * Attach topic and text aliases to SDK node-like records.\n */\nexport function withSdkAliases<T extends AnyRecord>(value: T): T {\n return withTopicAlias(withTextAlias(value));\n}\n\n/**\n * Normalize a belief/question/evidence write payload to the canonical gateway shape.\n */\nexport function normalizeNodeWriteInput<T extends JsonObject>(value: T): T {\n const topicId = resolveTopicId(value);\n const text = resolveText(value);\n const verificationStatus = normalizeVerificationStatus(value.verificationStatus);\n const next = { ...value } as JsonObject;\n\n if (topicId) {\n next.topicId = topicId;\n }\n if (text) {\n next.text = text;\n next.canonicalText = text;\n }\n if (verificationStatus) {\n next.verificationStatus = verificationStatus;\n }\n\n return next as T;\n}\n\nexport const normalizeNodeVerificationStatus = normalizeVerificationStatus;\n\n/**\n * Build a topic-aware query object.\n */\nexport function normalizeTopicQuery<T extends JsonObject>(value: T): T {\n const topicId = cleanString(value.topicId);\n if (!topicId) {\n return value;\n }\n return { ...value, topicId } as T;\n}\n\n/**\n * Extract list items from array or list-envelope payloads.\n */\nexport function asListItems<T>(data: unknown, legacyKey?: string): T[] {\n if (Array.isArray(data)) {\n return data;\n }\n\n const record = asRecord(data);\n if (Array.isArray(record.items)) {\n return record.items;\n }\n if (legacyKey && Array.isArray(record[legacyKey])) {\n return record[legacyKey];\n }\n\n return [];\n}\n\n/**\n * Standardize list data to { items, total } while retaining an optional legacy array key.\n */\nexport function createListResult<T, LegacyKey extends string>(\n items: T[],\n legacyKey?: LegacyKey\n): ListResult<T, LegacyKey> {\n const result = {\n items,\n total: items.length,\n } as ListResult<T, LegacyKey>;\n\n if (legacyKey) {\n return {\n ...result,\n [legacyKey]: items,\n } as ListResult<T, LegacyKey>;\n }\n\n return result;\n}\n\n/**\n * Map a gateway success envelope's data while preserving the transport metadata.\n */\nexport function mapGatewayData<T, U>(\n response: PlatformGatewaySuccess<T>,\n mapper: (data: T) => U\n): PlatformGatewaySuccess<U> {\n return {\n ...response,\n data: mapper(response.data),\n };\n}\n\n/**\n * Apply SDK aliases across all items in a list-like payload.\n */\nexport function mapAliasedList<\n TItem extends AnyRecord,\n LegacyKey extends string,\n>(\n data: unknown,\n legacyKey?: LegacyKey\n): ListResult<TItem, LegacyKey> {\n const items = asListItems<TItem>(data, legacyKey).map((item) =>\n withSdkAliases(item)\n );\n return createListResult(items, legacyKey);\n}\n","import { asListItems, resolveText, resolveTopicId } from \"./sdkSurface\";\nimport type { JsonObject, PlatformGraphEdge, PlatformGraphNode } from \"./types\";\n\nexport type NodeLike = PlatformGraphNode;\nexport type EdgeLike = PlatformGraphEdge;\nexport type CustomToolInput = JsonObject;\nexport type BeliefsRefineInput =\n | string\n | { text: string; rationale?: string };\nexport type BeliefsArchiveInput = { reason?: string; rationale?: string } | string;\n\nexport function normalizeCustomNamespace(namespace: string): string {\n return namespace.trim() || \"custom\";\n}\n\nexport function normalizeCustomToolPayload(input: unknown): CustomToolInput {\n return input && typeof input === \"object\" && !Array.isArray(input)\n ? (input as CustomToolInput)\n : {};\n}\n\nexport function resolveCustomToolFullName(name: string): string {\n return name.includes(\".\") ? name : `custom.${name}`;\n}\n\nexport function buildBeliefsRefinePayload(\n textOrInput: BeliefsRefineInput,\n rationale?: string\n): { text: string; rationale?: string } {\n return typeof textOrInput === \"string\"\n ? { text: textOrInput, rationale }\n : { text: textOrInput.text, rationale: textOrInput.rationale };\n}\n\nexport function buildBeliefsArchivePayload(\n input?: BeliefsArchiveInput\n): { reason?: string } | undefined {\n return typeof input === \"string\"\n ? { reason: input }\n : input\n ? { reason: input.reason ?? input.rationale }\n : undefined;\n}\n\nexport function asNodeArray(data: unknown): NodeLike[] {\n const rows = asListItems<NodeLike>(data, \"nodes\");\n if (rows.length > 0) {\n return rows.filter(\n (value): value is NodeLike => Boolean(value) && typeof value === \"object\"\n );\n }\n if (data && typeof data === \"object\") {\n return [data as NodeLike];\n }\n return [];\n}\n\nexport function asEdgeArray(data: unknown): EdgeLike[] {\n const rows = asListItems<EdgeLike>(data, \"edges\");\n if (rows.length > 0) {\n return rows.filter(\n (value): value is EdgeLike => Boolean(value) && typeof value === \"object\"\n );\n }\n if (data && typeof data === \"object\") {\n return [data as EdgeLike];\n }\n return [];\n}\n\nexport function requireTopicId(args: { topicId?: string }): string {\n const topicId = resolveTopicId(args);\n if (!topicId) {\n throw new Error(\"topicId is required\");\n }\n return topicId;\n}\n\nexport function requireTopicOrProjectId(args: {\n topicId?: string;\n projectId?: string;\n}): string {\n const topicId =\n args.topicId?.trim() || args.projectId?.trim() || undefined;\n if (!topicId) {\n throw new Error(\"topicId is required\");\n }\n return topicId;\n}\n\nconst AUDIT_NODE_REFERENCE_KEY_PATTERN =\n /(^|_)(id|nodeid|beliefid|resourceid|targetid|sourceid|subjectid|globalid|entityid|recordid|fromnodeid|tonodeid|linkednodeid|linkedbeliefid|nodeids|beliefids|resourceids)$/i;\n\nexport function matchesAuditNodeReference(\n value: unknown,\n nodeId: string\n): boolean {\n if (Array.isArray(value)) {\n return value.some((entry) => matchesAuditNodeReference(entry, nodeId));\n }\n\n if (!value || typeof value !== \"object\") {\n return false;\n }\n\n return Object.entries(value as Record<string, unknown>).some(([key, entry]) => {\n if (\n typeof entry === \"string\" &&\n entry === nodeId &&\n AUDIT_NODE_REFERENCE_KEY_PATTERN.test(key)\n ) {\n return true;\n }\n\n if (\n Array.isArray(entry) &&\n AUDIT_NODE_REFERENCE_KEY_PATTERN.test(key) &&\n entry.some((item) => item === nodeId)\n ) {\n return true;\n }\n\n return matchesAuditNodeReference(entry, nodeId);\n });\n}\n\nexport function requireText(args: {\n text?: string;\n canonicalText?: string;\n formulation?: string;\n newFormulation?: string;\n}): string {\n const text = resolveText(args);\n if (!text) {\n throw new Error(\"text is required\");\n }\n return text;\n}\n\nexport function requireBaseRate(args: { baseRate?: number }): number {\n const baseRate =\n typeof args.baseRate === \"number\" && Number.isFinite(args.baseRate)\n ? args.baseRate\n : 0.5;\n if (baseRate < 0 || baseRate > 1) {\n throw new Error(\"baseRate must be within [0, 1].\");\n }\n return baseRate;\n}\n\nexport function sdkQueryString(input: Record<string, unknown>): string {\n const params = new URLSearchParams();\n for (const [key, value] of Object.entries(input)) {\n if (value === undefined || value === null) {\n continue;\n }\n if (Array.isArray(value)) {\n if (value.length > 0) {\n params.set(key, value.join(\",\"));\n }\n continue;\n }\n params.set(key, String(value));\n }\n const serialized = params.toString();\n return serialized ? `?${serialized}` : \"\";\n}\n"]}
|
package/dist/contextClient.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { GatewayClientConfig, PlatformGatewaySuccess } from './coreClient.js';
|
|
2
2
|
import { PublicCompiledContext, CompileContextInput } from './contextTypes.js';
|
|
3
|
+
import './authContext.js';
|
|
4
|
+
import './contracts/auth-session.contract.js';
|
|
3
5
|
import './types.js';
|
|
4
6
|
import './contracts/workflow-runtime.contract.js';
|
|
5
7
|
import './contracts/lens-workflow.contract.js';
|
|
@@ -16,12 +18,13 @@ type CompileContextResponse = PublicCompiledContext;
|
|
|
16
18
|
*/
|
|
17
19
|
declare function createContextClient(config?: ContextClientConfig): {
|
|
18
20
|
/**
|
|
19
|
-
* Compile a focused reasoning context pack
|
|
20
|
-
* @param
|
|
21
|
+
* Compile a focused reasoning context pack.
|
|
22
|
+
* @param topicIdOrInput - Optional topic ID, or compile input for query-first resolution.
|
|
21
23
|
* @param input - Optional compile parameters (query, budget, ranking, etc.).
|
|
22
24
|
* @returns The compiled context payload with beliefs, questions, and evidence.
|
|
23
25
|
*/
|
|
24
|
-
compile(
|
|
26
|
+
compile(topicIdOrInput?: string | CompileContextInput, input?: CompileContextInput): Promise<PlatformGatewaySuccess<PublicCompiledContext>>;
|
|
27
|
+
compileByQuery(input?: CompileContextInput): Promise<PlatformGatewaySuccess<PublicCompiledContext>>;
|
|
25
28
|
};
|
|
26
29
|
|
|
27
30
|
export { CompileContextInput, type CompileContextResponse, type ContextClientConfig, PublicCompiledContext, createContextClient };
|
package/dist/contextClient.js
CHANGED
|
@@ -1,3 +1,170 @@
|
|
|
1
|
+
// src/authContext.ts
|
|
2
|
+
var LucernSdkAuthContextError = class extends Error {
|
|
3
|
+
reason;
|
|
4
|
+
constructor(reason, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "LucernSdkAuthContextError";
|
|
7
|
+
this.reason = reason;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
function cleanString(value) {
|
|
11
|
+
const normalized = value?.trim();
|
|
12
|
+
return normalized ? normalized : void 0;
|
|
13
|
+
}
|
|
14
|
+
function cleanStringList(values) {
|
|
15
|
+
if (!values) {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
return values.map((value) => value.trim()).filter(
|
|
19
|
+
(value, index, list) => value.length > 0 && list.indexOf(value) === index
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
function requireString(value, reason, label) {
|
|
23
|
+
const normalized = cleanString(value);
|
|
24
|
+
if (!normalized) {
|
|
25
|
+
throw new LucernSdkAuthContextError(
|
|
26
|
+
reason,
|
|
27
|
+
`Canonical Lucern SDK auth context is missing ${label}.`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return normalized;
|
|
31
|
+
}
|
|
32
|
+
function requirePrincipalType(principalType) {
|
|
33
|
+
if (!principalType) {
|
|
34
|
+
throw new LucernSdkAuthContextError(
|
|
35
|
+
"principal_missing",
|
|
36
|
+
"Canonical Lucern SDK auth context is missing principalType."
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return principalType;
|
|
40
|
+
}
|
|
41
|
+
function requireAuthMode(authMode) {
|
|
42
|
+
if (!authMode) {
|
|
43
|
+
throw new LucernSdkAuthContextError(
|
|
44
|
+
"principal_missing",
|
|
45
|
+
"Canonical Lucern SDK auth context is missing authMode."
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return authMode;
|
|
49
|
+
}
|
|
50
|
+
function ensurePermitMatch(args) {
|
|
51
|
+
const actual = cleanString(args.actual);
|
|
52
|
+
if (actual && actual !== args.expected) {
|
|
53
|
+
throw new LucernSdkAuthContextError(
|
|
54
|
+
"policy_denied",
|
|
55
|
+
`Canonical Lucern SDK auth context has conflicting Permit ${args.field}.`
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function normalizeCanonicalLucernAuthContext(input) {
|
|
60
|
+
if (!input) {
|
|
61
|
+
throw new LucernSdkAuthContextError(
|
|
62
|
+
"principal_missing",
|
|
63
|
+
"Canonical Lucern SDK auth context is required."
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
if (input.policyDecision === "deny") {
|
|
67
|
+
throw new LucernSdkAuthContextError(
|
|
68
|
+
"policy_denied",
|
|
69
|
+
"Canonical Lucern SDK auth context carries a denied policy decision."
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
const principalId = requireString(
|
|
73
|
+
input.principalId,
|
|
74
|
+
"principal_missing",
|
|
75
|
+
"principalId"
|
|
76
|
+
);
|
|
77
|
+
const tenantId = requireString(input.tenantId, "tenant_missing", "tenantId");
|
|
78
|
+
const workspaceId = requireString(
|
|
79
|
+
input.workspaceId,
|
|
80
|
+
"workspace_missing",
|
|
81
|
+
"workspaceId"
|
|
82
|
+
);
|
|
83
|
+
const roles = cleanStringList(input.roles);
|
|
84
|
+
const scopes = cleanStringList(input.scopes);
|
|
85
|
+
const principalType = requirePrincipalType(input.principalType);
|
|
86
|
+
const authMode = requireAuthMode(input.authMode);
|
|
87
|
+
const roleBasedInteractiveAuth = authMode === "interactive_user" && roles.length > 0;
|
|
88
|
+
if (roles.length === 0 || scopes.length === 0 && !roleBasedInteractiveAuth) {
|
|
89
|
+
throw new LucernSdkAuthContextError(
|
|
90
|
+
"membership_missing",
|
|
91
|
+
"Canonical Lucern SDK auth context requires non-empty roles and scopes."
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
const subject = cleanString(input.permit?.subject) ?? principalId;
|
|
95
|
+
const tenant = cleanString(input.permit?.tenant) ?? tenantId;
|
|
96
|
+
const workspace = cleanString(input.permit?.workspace) ?? workspaceId;
|
|
97
|
+
ensurePermitMatch({
|
|
98
|
+
field: "subject",
|
|
99
|
+
expected: principalId,
|
|
100
|
+
actual: subject
|
|
101
|
+
});
|
|
102
|
+
ensurePermitMatch({ field: "tenant", expected: tenantId, actual: tenant });
|
|
103
|
+
ensurePermitMatch({
|
|
104
|
+
field: "workspace",
|
|
105
|
+
expected: workspaceId,
|
|
106
|
+
actual: workspace
|
|
107
|
+
});
|
|
108
|
+
const context = input.permit?.context ? { ...input.permit.context } : void 0;
|
|
109
|
+
return {
|
|
110
|
+
clerkId: cleanString(input.clerkId),
|
|
111
|
+
principalId,
|
|
112
|
+
tenantId,
|
|
113
|
+
workspaceId,
|
|
114
|
+
principalType,
|
|
115
|
+
authMode,
|
|
116
|
+
roles,
|
|
117
|
+
scopes,
|
|
118
|
+
delegationChain: input.delegationChain ? [...input.delegationChain] : [],
|
|
119
|
+
policyTraceId: cleanString(input.policyTraceId),
|
|
120
|
+
correlationId: cleanString(input.correlationId),
|
|
121
|
+
membershipId: cleanString(input.membershipId),
|
|
122
|
+
permit: {
|
|
123
|
+
subject,
|
|
124
|
+
tenant,
|
|
125
|
+
workspace,
|
|
126
|
+
resource: cleanString(input.permit?.resource),
|
|
127
|
+
action: cleanString(input.permit?.action),
|
|
128
|
+
relation: cleanString(input.permit?.relation),
|
|
129
|
+
context
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function createCanonicalAuthHeaders(authContext) {
|
|
134
|
+
const headers = {
|
|
135
|
+
"x-lucern-principal-id": authContext.principalId,
|
|
136
|
+
"x-lucern-principal-type": authContext.principalType,
|
|
137
|
+
"x-lucern-tenant": authContext.tenantId,
|
|
138
|
+
"x-lucern-tenant-id": authContext.tenantId,
|
|
139
|
+
"x-lucern-workspace": authContext.workspaceId,
|
|
140
|
+
"x-lucern-workspace-id": authContext.workspaceId,
|
|
141
|
+
"x-lucern-auth-mode": authContext.authMode,
|
|
142
|
+
"x-lucern-roles": authContext.roles.join(","),
|
|
143
|
+
"x-lucern-scopes": authContext.scopes.join(","),
|
|
144
|
+
"x-lucern-permit-context": JSON.stringify(authContext.permit)
|
|
145
|
+
};
|
|
146
|
+
if (authContext.clerkId) {
|
|
147
|
+
headers["x-lucern-clerk-id"] = authContext.clerkId;
|
|
148
|
+
headers["x-lucern-user-id"] = authContext.clerkId;
|
|
149
|
+
}
|
|
150
|
+
if (authContext.delegationChain.length > 0) {
|
|
151
|
+
headers["x-lucern-delegation-chain"] = JSON.stringify(
|
|
152
|
+
authContext.delegationChain
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
if (authContext.policyTraceId) {
|
|
156
|
+
headers["x-lucern-policy-trace-id"] = authContext.policyTraceId;
|
|
157
|
+
}
|
|
158
|
+
if (authContext.correlationId) {
|
|
159
|
+
headers["x-correlation-id"] = authContext.correlationId;
|
|
160
|
+
headers["x-lucern-correlation-id"] = authContext.correlationId;
|
|
161
|
+
}
|
|
162
|
+
if (authContext.membershipId) {
|
|
163
|
+
headers["x-lucern-membership-id"] = authContext.membershipId;
|
|
164
|
+
}
|
|
165
|
+
return headers;
|
|
166
|
+
}
|
|
167
|
+
|
|
1
168
|
// src/coreClient.ts
|
|
2
169
|
var LucernApiError = class extends Error {
|
|
3
170
|
code;
|
|
@@ -109,8 +276,11 @@ function timeoutError(timeoutMs) {
|
|
|
109
276
|
error.name = "AbortError";
|
|
110
277
|
return error;
|
|
111
278
|
}
|
|
279
|
+
function isRecord(value) {
|
|
280
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
281
|
+
}
|
|
112
282
|
function readPolicySummaryFromDetails(details) {
|
|
113
|
-
if (!
|
|
283
|
+
if (!isRecord(details)) {
|
|
114
284
|
return null;
|
|
115
285
|
}
|
|
116
286
|
const directSummary = details.summary;
|
|
@@ -118,11 +288,11 @@ function readPolicySummaryFromDetails(details) {
|
|
|
118
288
|
return directSummary.trim();
|
|
119
289
|
}
|
|
120
290
|
const policy = details.policy;
|
|
121
|
-
if (!
|
|
291
|
+
if (!isRecord(policy)) {
|
|
122
292
|
return null;
|
|
123
293
|
}
|
|
124
294
|
const explanation = policy.explanation;
|
|
125
|
-
if (!
|
|
295
|
+
if (!isRecord(explanation)) {
|
|
126
296
|
return null;
|
|
127
297
|
}
|
|
128
298
|
const nestedSummary = explanation.summary;
|
|
@@ -131,16 +301,41 @@ function readPolicySummaryFromDetails(details) {
|
|
|
131
301
|
}
|
|
132
302
|
return null;
|
|
133
303
|
}
|
|
304
|
+
async function resolveConfiguredAuthContext(authContext) {
|
|
305
|
+
if (typeof authContext === "function") {
|
|
306
|
+
return await authContext();
|
|
307
|
+
}
|
|
308
|
+
return authContext;
|
|
309
|
+
}
|
|
310
|
+
function mergeHeaderRecord(base, addition) {
|
|
311
|
+
const headers = new Headers(base);
|
|
312
|
+
for (const [key, value] of Object.entries(addition)) {
|
|
313
|
+
const existing = headers.get(key);
|
|
314
|
+
if (existing !== null && existing !== value) {
|
|
315
|
+
throw new LucernSdkAuthContextError(
|
|
316
|
+
"policy_denied",
|
|
317
|
+
`Canonical Lucern SDK auth context conflicts with existing ${key} header.`
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
headers.set(key, value);
|
|
321
|
+
}
|
|
322
|
+
return Object.fromEntries(headers.entries());
|
|
323
|
+
}
|
|
134
324
|
function createGatewayRequestClient(config = {}) {
|
|
135
325
|
const fetchImpl = config.fetchImpl ?? fetch;
|
|
136
326
|
const baseUrl = config.baseUrl?.replace(/\/+$/, "") ?? "";
|
|
137
327
|
const maxRetries = config.maxRetries ?? 2;
|
|
138
328
|
const requestIdFactory = config.requestIdFactory ?? (() => generatePortableRequestId());
|
|
139
329
|
async function resolveAuthHeaders() {
|
|
140
|
-
|
|
141
|
-
|
|
330
|
+
const base = config.getAuthHeaders ? await config.getAuthHeaders() : {};
|
|
331
|
+
const authContextInput = await resolveConfiguredAuthContext(
|
|
332
|
+
config.authContext
|
|
333
|
+
);
|
|
334
|
+
if (!authContextInput && !config.requireCanonicalAuthContext) {
|
|
335
|
+
return base;
|
|
142
336
|
}
|
|
143
|
-
|
|
337
|
+
const authContext = normalizeCanonicalLucernAuthContext(authContextInput);
|
|
338
|
+
return mergeHeaderRecord(base, createCanonicalAuthHeaders(authContext));
|
|
144
339
|
}
|
|
145
340
|
async function fetchWithTimeout(url, init, timeoutMs) {
|
|
146
341
|
const controller = new AbortController();
|
|
@@ -161,11 +356,11 @@ function createGatewayRequestClient(config = {}) {
|
|
|
161
356
|
if (!text) {
|
|
162
357
|
return null;
|
|
163
358
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
} catch {
|
|
359
|
+
const parsed = tryParseGatewayEnvelopeJson(text);
|
|
360
|
+
if (!parsed.ok) {
|
|
167
361
|
return null;
|
|
168
362
|
}
|
|
363
|
+
return isRecord(parsed.value) ? parsed.value : null;
|
|
169
364
|
}
|
|
170
365
|
function resolveTimeoutMs(method, requestTimeoutMs) {
|
|
171
366
|
if (typeof requestTimeoutMs === "number") {
|
|
@@ -177,16 +372,31 @@ function createGatewayRequestClient(config = {}) {
|
|
|
177
372
|
}
|
|
178
373
|
return config.timeoutMs ?? 15e3;
|
|
179
374
|
}
|
|
375
|
+
function tryParseGatewayEnvelopeJson(text) {
|
|
376
|
+
const trimmed = text.trim();
|
|
377
|
+
if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) {
|
|
378
|
+
return { ok: false, reason: "non-json" };
|
|
379
|
+
}
|
|
380
|
+
try {
|
|
381
|
+
return { ok: true, value: JSON.parse(trimmed) };
|
|
382
|
+
} catch (error) {
|
|
383
|
+
if (error instanceof SyntaxError) {
|
|
384
|
+
return { ok: false, reason: "invalid-json", error };
|
|
385
|
+
}
|
|
386
|
+
throw error;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
180
389
|
function buildApiError(args) {
|
|
181
390
|
const failure = args.failure;
|
|
182
|
-
const legacyError = failure &&
|
|
391
|
+
const legacyError = failure && isRecord(failure.error) ? failure.error : failure?.legacyError;
|
|
183
392
|
const correlationId = failure?.correlationId ?? args.response.headers.get("x-lucern-correlation-id")?.trim() ?? args.requestId;
|
|
184
393
|
const policyTraceId = failure?.policyTraceId ?? args.response.headers.get("x-lucern-policy-trace-id")?.trim() ?? null;
|
|
185
394
|
const details = failure?.details ?? legacyError?.details;
|
|
186
395
|
const policySummary = readPolicySummaryFromDetails(details);
|
|
396
|
+
const failureMessage = typeof failure?.error === "string" ? failure.error : legacyError?.message;
|
|
187
397
|
return new LucernApiError({
|
|
188
398
|
code: failure?.code ?? legacyError?.code ?? fallbackErrorCode(args.response.status),
|
|
189
|
-
message: policySummary ??
|
|
399
|
+
message: policySummary ?? failureMessage ?? (args.response.ok ? "Platform API returned an invalid success payload." : "Platform API request failed."),
|
|
190
400
|
status: args.response.status,
|
|
191
401
|
invariant: failure?.invariant,
|
|
192
402
|
suggestion: failure?.suggestion,
|
|
@@ -312,7 +522,7 @@ function createGatewayRequestClient(config = {}) {
|
|
|
312
522
|
}
|
|
313
523
|
|
|
314
524
|
// src/contextClient.ts
|
|
315
|
-
function
|
|
525
|
+
function cleanString2(value) {
|
|
316
526
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
|
|
317
527
|
}
|
|
318
528
|
function cleanNumber(value) {
|
|
@@ -321,50 +531,55 @@ function cleanNumber(value) {
|
|
|
321
531
|
function cleanBoolean(value) {
|
|
322
532
|
return typeof value === "boolean" ? value : void 0;
|
|
323
533
|
}
|
|
324
|
-
function buildCompileContextRequest(
|
|
325
|
-
const
|
|
326
|
-
const
|
|
534
|
+
function buildCompileContextRequest(topicIdOrInput = {}, input = {}) {
|
|
535
|
+
const effectiveInput = typeof topicIdOrInput === "string" ? input : topicIdOrInput;
|
|
536
|
+
const payload = {};
|
|
537
|
+
const topicId = typeof topicIdOrInput === "string" ? cleanString2(topicIdOrInput) : cleanString2(effectiveInput.topicId);
|
|
538
|
+
if (topicId) {
|
|
539
|
+
payload.topicId = topicId;
|
|
540
|
+
}
|
|
541
|
+
const query = cleanString2(effectiveInput.query);
|
|
327
542
|
if (query) {
|
|
328
543
|
payload.query = query;
|
|
329
544
|
}
|
|
330
|
-
const budget = cleanNumber(
|
|
545
|
+
const budget = cleanNumber(effectiveInput.budget) ?? cleanNumber(effectiveInput.tokenBudget);
|
|
331
546
|
if (budget !== void 0) {
|
|
332
547
|
payload.budget = budget;
|
|
333
548
|
}
|
|
334
|
-
const ranking =
|
|
549
|
+
const ranking = cleanString2(effectiveInput.ranking) ?? cleanString2(effectiveInput.rankingProfile);
|
|
335
550
|
if (ranking) {
|
|
336
551
|
payload.ranking = ranking;
|
|
337
552
|
}
|
|
338
|
-
const limit = cleanNumber(
|
|
553
|
+
const limit = cleanNumber(effectiveInput.limit);
|
|
339
554
|
if (limit !== void 0) {
|
|
340
555
|
payload.limit = limit;
|
|
341
556
|
}
|
|
342
|
-
const maxDepth = cleanNumber(
|
|
557
|
+
const maxDepth = cleanNumber(effectiveInput.maxDepth);
|
|
343
558
|
if (maxDepth !== void 0) {
|
|
344
559
|
payload.maxDepth = maxDepth;
|
|
345
560
|
}
|
|
346
|
-
const includeEntities = cleanBoolean(
|
|
561
|
+
const includeEntities = cleanBoolean(effectiveInput.includeEntities);
|
|
347
562
|
if (includeEntities !== void 0) {
|
|
348
563
|
payload.includeEntities = includeEntities;
|
|
349
564
|
}
|
|
350
|
-
const mode =
|
|
565
|
+
const mode = cleanString2(effectiveInput.mode);
|
|
351
566
|
if (mode) {
|
|
352
567
|
payload.mode = mode;
|
|
353
568
|
}
|
|
354
|
-
const includeFailures = cleanBoolean(
|
|
569
|
+
const includeFailures = cleanBoolean(effectiveInput.includeFailures);
|
|
355
570
|
if (includeFailures !== void 0) {
|
|
356
571
|
payload.includeFailures = includeFailures;
|
|
357
572
|
}
|
|
358
|
-
const worktreeId =
|
|
573
|
+
const worktreeId = cleanString2(effectiveInput.worktreeId);
|
|
359
574
|
if (worktreeId) {
|
|
360
575
|
payload.worktreeId = worktreeId;
|
|
361
576
|
}
|
|
362
|
-
const sessionId =
|
|
577
|
+
const sessionId = cleanString2(effectiveInput.sessionId);
|
|
363
578
|
if (sessionId) {
|
|
364
579
|
payload.sessionId = sessionId;
|
|
365
580
|
}
|
|
366
|
-
if (Array.isArray(
|
|
367
|
-
payload.packWeightOverrides =
|
|
581
|
+
if (Array.isArray(effectiveInput.packWeightOverrides) && effectiveInput.packWeightOverrides.length > 0) {
|
|
582
|
+
payload.packWeightOverrides = effectiveInput.packWeightOverrides;
|
|
368
583
|
}
|
|
369
584
|
return {
|
|
370
585
|
path: "/api/platform/v1/context/compile",
|
|
@@ -376,13 +591,20 @@ function createContextClient(config = {}) {
|
|
|
376
591
|
const gateway = createGatewayRequestClient(config);
|
|
377
592
|
return {
|
|
378
593
|
/**
|
|
379
|
-
* Compile a focused reasoning context pack
|
|
380
|
-
* @param
|
|
594
|
+
* Compile a focused reasoning context pack.
|
|
595
|
+
* @param topicIdOrInput - Optional topic ID, or compile input for query-first resolution.
|
|
381
596
|
* @param input - Optional compile parameters (query, budget, ranking, etc.).
|
|
382
597
|
* @returns The compiled context payload with beliefs, questions, and evidence.
|
|
383
598
|
*/
|
|
384
|
-
async compile(
|
|
385
|
-
const request = buildCompileContextRequest(
|
|
599
|
+
async compile(topicIdOrInput = {}, input = {}) {
|
|
600
|
+
const request = buildCompileContextRequest(topicIdOrInput, input);
|
|
601
|
+
return gateway.request({
|
|
602
|
+
...request,
|
|
603
|
+
body: request.body
|
|
604
|
+
});
|
|
605
|
+
},
|
|
606
|
+
async compileByQuery(input = {}) {
|
|
607
|
+
const request = buildCompileContextRequest(input);
|
|
386
608
|
return gateway.request({
|
|
387
609
|
...request,
|
|
388
610
|
body: request.body
|