@lucern/sdk 0.2.0-alpha.7 → 0.2.0-alpha.8
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/dist/adminClient.d.ts +409 -0
- package/dist/adminClient.js +755 -0
- package/dist/adminClient.js.map +1 -0
- package/dist/answersClient.d.ts +23 -0
- package/dist/answersClient.js +333 -0
- package/dist/answersClient.js.map +1 -0
- package/dist/audiencesClient.d.ts +99 -0
- package/dist/audiencesClient.js +472 -0
- package/dist/audiencesClient.js.map +1 -0
- package/dist/auditClient.d.ts +29 -0
- package/dist/auditClient.js +386 -0
- package/dist/auditClient.js.map +1 -0
- package/dist/beliefsClient.d.ts +162 -0
- package/dist/beliefsClient.js +477 -0
- package/dist/beliefsClient.js.map +1 -0
- package/dist/client.d.ts +2378 -0
- package/dist/client.js +6134 -0
- package/dist/client.js.map +1 -0
- package/dist/contextClient.d.ts +27 -0
- package/dist/contextClient.js +396 -0
- package/dist/contextClient.js.map +1 -0
- package/dist/contextFacade.d.ts +2 -0
- package/dist/contextFacade.js +73 -0
- package/dist/contextFacade.js.map +1 -0
- package/dist/contextPackCompiler.d.ts +102 -0
- package/dist/contextPackCompiler.js +1091 -0
- package/dist/contextPackCompiler.js.map +1 -0
- package/dist/contextPackPolicy.d.ts +84 -0
- package/dist/contextPackPolicy.js +347 -0
- package/dist/contextPackPolicy.js.map +1 -0
- package/dist/contextPackSchema.d.ts +7 -0
- package/{src/contextPackSchema.ts → dist/contextPackSchema.js} +22 -70
- package/dist/contextPackSchema.js.map +1 -0
- package/dist/contextTypes.d.ts +135 -0
- package/dist/contextTypes.js +3 -0
- package/dist/contextTypes.js.map +1 -0
- package/dist/contracts/api-enums.contract.d.ts +81 -0
- package/dist/contracts/api-enums.contract.js +92 -0
- package/dist/contracts/api-enums.contract.js.map +1 -0
- package/dist/contracts/auth-session.contract.d.ts +55 -0
- package/dist/contracts/auth-session.contract.js +48 -0
- package/dist/contracts/auth-session.contract.js.map +1 -0
- package/dist/contracts/context-pack.contract.d.ts +492 -0
- package/dist/contracts/context-pack.contract.js +98 -0
- package/dist/contracts/context-pack.contract.js.map +1 -0
- package/dist/contracts/contextPack.d.ts +1 -0
- package/dist/contracts/contextPack.js +98 -0
- package/dist/contracts/contextPack.js.map +1 -0
- package/dist/contracts/index.d.ts +9 -0
- package/dist/contracts/index.js +4892 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/contracts/lens-filter.contract.d.ts +72 -0
- package/dist/contracts/lens-filter.contract.js +71 -0
- package/dist/contracts/lens-filter.contract.js.map +1 -0
- package/dist/contracts/lens-workflow.contract.d.ts +87 -0
- package/dist/contracts/lens-workflow.contract.js +123 -0
- package/dist/contracts/lens-workflow.contract.js.map +1 -0
- package/dist/contracts/lensFilter.d.ts +1 -0
- package/dist/contracts/lensFilter.js +71 -0
- package/dist/contracts/lensFilter.js.map +1 -0
- package/dist/contracts/lensWorkflow.d.ts +2 -0
- package/dist/contracts/lensWorkflow.js +123 -0
- package/dist/contracts/lensWorkflow.js.map +1 -0
- package/dist/contracts/mcp-tools.contract.d.ts +1 -0
- package/dist/contracts/mcp-tools.contract.js +2986 -0
- package/dist/contracts/mcp-tools.contract.js.map +1 -0
- package/dist/contracts/mcpTools.d.ts +1 -0
- package/dist/contracts/mcpTools.js +2986 -0
- package/dist/contracts/mcpTools.js.map +1 -0
- package/dist/contracts/prompt.contract.d.ts +26 -0
- package/dist/contracts/prompt.contract.js +12 -0
- package/dist/contracts/prompt.contract.js.map +1 -0
- package/dist/contracts/prompt.d.ts +1 -0
- package/dist/contracts/prompt.js +12 -0
- package/dist/contracts/prompt.js.map +1 -0
- package/dist/contracts/sdk-tools.contract.d.ts +2 -0
- package/dist/contracts/sdk-tools.contract.js +4134 -0
- package/dist/contracts/sdk-tools.contract.js.map +1 -0
- package/dist/contracts/sdkTools.d.ts +2 -0
- package/dist/contracts/sdkTools.js +4134 -0
- package/dist/contracts/sdkTools.js.map +1 -0
- package/dist/contracts/workflow-runtime.contract.d.ts +163 -0
- package/dist/contracts/workflow-runtime.contract.js +245 -0
- package/dist/contracts/workflow-runtime.contract.js.map +1 -0
- package/dist/contracts/workflowRuntime.d.ts +1 -0
- package/dist/contracts/workflowRuntime.js +245 -0
- package/dist/contracts/workflowRuntime.js.map +1 -0
- package/dist/controlObjectOwnership.d.ts +310 -0
- package/{src/controlObjectOwnership.ts → dist/controlObjectOwnership.js} +53 -124
- package/dist/controlObjectOwnership.js.map +1 -0
- package/dist/coreClient.d.ts +144 -0
- package/dist/coreClient.js +339 -0
- package/dist/coreClient.js.map +1 -0
- package/dist/customTools.d.ts +88 -0
- package/dist/customTools.js +248 -0
- package/dist/customTools.js.map +1 -0
- package/dist/decisionsClient.d.ts +111 -0
- package/dist/decisionsClient.js +522 -0
- package/dist/decisionsClient.js.map +1 -0
- package/dist/domainContext.d.ts +1 -0
- package/dist/domainContext.js +3 -0
- package/dist/domainContext.js.map +1 -0
- package/dist/events.d.ts +178 -0
- package/dist/events.js +249 -0
- package/dist/events.js.map +1 -0
- package/dist/eventsCore.d.ts +49 -0
- package/dist/eventsCore.js +429 -0
- package/dist/eventsCore.js.map +1 -0
- package/dist/facade/context.d.ts +18 -0
- package/dist/facade/context.js +73 -0
- package/dist/facade/context.js.map +1 -0
- package/dist/gatewayFacades.d.ts +591 -0
- package/dist/gatewayFacades.js +1953 -0
- package/dist/gatewayFacades.js.map +1 -0
- package/dist/graphClient.d.ts +271 -0
- package/dist/graphClient.js +698 -0
- package/dist/graphClient.js.map +1 -0
- package/dist/harnessClient.d.ts +314 -0
- package/dist/harnessClient.js +607 -0
- package/dist/harnessClient.js.map +1 -0
- package/dist/identityClient.d.ts +140 -0
- package/dist/identityClient.js +497 -0
- package/dist/identityClient.js.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +11381 -0
- package/dist/index.js.map +1 -0
- package/dist/learningClient.d.ts +46 -0
- package/dist/learningClient.js +409 -0
- package/dist/learningClient.js.map +1 -0
- package/dist/mcpParityClient.d.ts +74 -0
- package/dist/mcpParityClient.js +516 -0
- package/dist/mcpParityClient.js.map +1 -0
- package/dist/mcpParitySurface.d.ts +12 -0
- package/{src/mcpParitySurface.ts → dist/mcpParitySurface.js} +9 -14
- package/dist/mcpParitySurface.js.map +1 -0
- package/dist/mcpTools-DPZxowDX.d.ts +254 -0
- package/dist/ontologyClient.d.ts +137 -0
- package/dist/ontologyClient.js +513 -0
- package/dist/ontologyClient.js.map +1 -0
- package/dist/packRuntime.d.ts +2 -0
- package/dist/packRuntime.js +3 -0
- package/dist/packRuntime.js.map +1 -0
- package/dist/packsClient.d.ts +131 -0
- package/dist/packsClient.js +525 -0
- package/dist/packsClient.js.map +1 -0
- package/dist/policyClient.d.ts +299 -0
- package/dist/policyClient.js +625 -0
- package/dist/policyClient.js.map +1 -0
- package/dist/realtime/index.d.ts +29 -0
- package/dist/realtime/index.js +23 -0
- package/dist/realtime/index.js.map +1 -0
- package/{src/realtime/refs.ts → dist/realtime/refs.d.ts} +5 -5
- package/dist/realtime/refs.js +9 -0
- package/dist/realtime/refs.js.map +1 -0
- package/dist/reportsClient.d.ts +41 -0
- package/dist/reportsClient.js +418 -0
- package/dist/reportsClient.js.map +1 -0
- package/dist/schemaClient.d.ts +64 -0
- package/dist/schemaClient.js +434 -0
- package/dist/schemaClient.js.map +1 -0
- package/dist/sdkSurface.d.ts +61 -0
- package/dist/sdkSurface.js +112 -0
- package/dist/sdkSurface.js.map +1 -0
- package/dist/sdkTools-CwXJDACb.d.ts +150 -0
- package/dist/topicsClient.d.ts +84 -0
- package/dist/topicsClient.js +492 -0
- package/dist/topicsClient.js.map +1 -0
- package/dist/types.d.ts +696 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +4 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/dist/workflowClient.d.ts +316 -0
- package/dist/workflowClient.js +830 -0
- package/dist/workflowClient.js.map +1 -0
- package/package.json +31 -7
- package/.turbo/turbo-build.log +0 -7
- package/.turbo/turbo-typecheck.log +0 -4
- package/examples/README.md +0 -69
- package/examples/contradiction.ts +0 -94
- package/examples/investigation-context.ts +0 -118
- package/examples/questions-and-tasks.ts +0 -55
- package/examples/quickstart.ts +0 -97
- package/examples/shared.ts +0 -318
- package/examples/strict-public-types.ts +0 -143
- package/examples/worktree-lifecycle.ts +0 -79
- package/src/README.md +0 -6
- package/src/adminClient.ts +0 -789
- package/src/answersClient.ts +0 -29
- package/src/audiencesClient.ts +0 -209
- package/src/auditClient.ts +0 -50
- package/src/beliefsClient.ts +0 -319
- package/src/client.ts +0 -2647
- package/src/contextClient.ts +0 -130
- package/src/contextFacade.ts +0 -15
- package/src/contextPackCompiler.ts +0 -828
- package/src/contextTypes.ts +0 -153
- package/src/contracts/api-enums.contract.ts +0 -202
- package/src/contracts/auth-session.contract.ts +0 -109
- package/src/contracts/context-pack.contract.ts +0 -700
- package/src/contracts/contextPack.ts +0 -1
- package/src/contracts/index.ts +0 -10
- package/src/contracts/lens-filter.contract.ts +0 -183
- package/src/contracts/lens-workflow.contract.ts +0 -162
- package/src/contracts/lensFilter.ts +0 -1
- package/src/contracts/lensWorkflow.ts +0 -1
- package/src/contracts/mcp-tools.contract.ts +0 -3636
- package/src/contracts/mcpTools.ts +0 -1
- package/src/contracts/prompt.contract.ts +0 -50
- package/src/contracts/prompt.ts +0 -1
- package/src/contracts/sdk-tools.contract.ts +0 -1457
- package/src/contracts/sdkTools.ts +0 -1
- package/src/contracts/workflow-runtime.contract.ts +0 -440
- package/src/contracts/workflowRuntime.ts +0 -1
- package/src/coreClient.ts +0 -570
- package/src/customTools.ts +0 -398
- package/src/decisionsClient.ts +0 -286
- package/src/domainContext.ts +0 -15
- package/src/events.ts +0 -531
- package/src/eventsCore.ts +0 -168
- package/src/facade/beliefs.ts +0 -83
- package/src/facade/context.ts +0 -110
- package/src/facade/contradictions.ts +0 -29
- package/src/facade/edges.ts +0 -30
- package/src/facade/events.ts +0 -23
- package/src/facade/evidence.ts +0 -41
- package/src/facade/graph.ts +0 -38
- package/src/facade/identity.ts +0 -16
- package/src/facade/ontologies.ts +0 -34
- package/src/facade/questions.ts +0 -59
- package/src/facade/search.ts +0 -16
- package/src/facade/tasks.ts +0 -37
- package/src/facade/topics.ts +0 -42
- package/src/facade/webhooks.ts +0 -58
- package/src/facade/worktrees.ts +0 -51
- package/src/gatewayFacades.ts +0 -1666
- package/src/graphClient.ts +0 -529
- package/src/harnessClient.ts +0 -585
- package/src/identityClient.ts +0 -278
- package/src/index.ts +0 -49
- package/src/learningClient.ts +0 -95
- package/src/mcpParityClient.ts +0 -240
- package/src/ontologyClient.ts +0 -275
- package/src/packRuntime.ts +0 -3
- package/src/packsClient.ts +0 -260
- package/src/policyClient.ts +0 -572
- package/src/promptCatalog.ts +0 -1
- package/src/realtime/index.ts +0 -51
- package/src/reportsClient.ts +0 -99
- package/src/schemaClient.ts +0 -129
- package/src/sdkSurface.ts +0 -190
- package/src/topicsClient.ts +0 -243
- package/src/types.ts +0 -807
- package/src/version.ts +0 -2
- package/src/workflowClient.ts +0 -826
- package/tsconfig.json +0 -9
package/examples/quickstart.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createExampleTopic,
|
|
3
|
-
printJson,
|
|
4
|
-
requireStringField,
|
|
5
|
-
runExample,
|
|
6
|
-
} from "./shared.js";
|
|
7
|
-
|
|
8
|
-
if (process.argv.includes("--dry-run")) {
|
|
9
|
-
printJson({
|
|
10
|
-
example: "quickstart",
|
|
11
|
-
mode: "dry-run",
|
|
12
|
-
steps: [
|
|
13
|
-
"create topic",
|
|
14
|
-
"create belief with text alias",
|
|
15
|
-
"add evidence",
|
|
16
|
-
"modulate confidence",
|
|
17
|
-
"fork belief",
|
|
18
|
-
"search beliefs",
|
|
19
|
-
],
|
|
20
|
-
});
|
|
21
|
-
process.exit(0);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
runExample("quickstart", async (context) => {
|
|
25
|
-
const topic = await createExampleTopic(context, "quickstart");
|
|
26
|
-
|
|
27
|
-
const belief = await context.lucern.beliefs.create({
|
|
28
|
-
metadata: {
|
|
29
|
-
example: "quickstart",
|
|
30
|
-
source: "lucern/packages/sdk/examples/quickstart.ts",
|
|
31
|
-
},
|
|
32
|
-
text: "Time-to-first-belief drops when the SDK ships a concrete quickstart that exercises the core lifecycle end to end.",
|
|
33
|
-
topicId: topic.topicId,
|
|
34
|
-
});
|
|
35
|
-
const beliefId = requireStringField(
|
|
36
|
-
belief.data,
|
|
37
|
-
["nodeId", "globalId"],
|
|
38
|
-
"beliefId"
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const evidence = await context.lucern.evidence.add({
|
|
42
|
-
sourceUrl: "https://example.invalid/sdk-quickstart-signal",
|
|
43
|
-
supports: {
|
|
44
|
-
nodeId: beliefId,
|
|
45
|
-
reasoning:
|
|
46
|
-
"Example-driven onboarding reduces the amount of guesswork before a first successful write.",
|
|
47
|
-
weight: 0.81,
|
|
48
|
-
},
|
|
49
|
-
text: "A runnable example moved the first successful belief write into the first five minutes for a new developer.",
|
|
50
|
-
topicId: topic.topicId,
|
|
51
|
-
});
|
|
52
|
-
const evidenceId = requireStringField(
|
|
53
|
-
evidence,
|
|
54
|
-
["nodeId", "globalId"],
|
|
55
|
-
"evidenceId"
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
await context.lucern.beliefs.modulateConfidence(beliefId, {
|
|
59
|
-
confidence: 0.79,
|
|
60
|
-
rationale:
|
|
61
|
-
"The quickstart now demonstrates a complete create → evidence → confidence → fork path.",
|
|
62
|
-
trigger: "evidence_added",
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const fork = await context.lucern.beliefs.fork(beliefId, {
|
|
66
|
-
forkReason: "refinement",
|
|
67
|
-
newFormulation:
|
|
68
|
-
"Time-to-first-belief drops below five minutes when the SDK ships a concrete quickstart that exercises the core lifecycle end to end.",
|
|
69
|
-
rationale: "Narrow the claim to the under-five-minute onboarding target.",
|
|
70
|
-
});
|
|
71
|
-
const forkId = requireStringField(
|
|
72
|
-
fork.data,
|
|
73
|
-
["nodeId", "forkedNodeId", "globalId"],
|
|
74
|
-
"forkId"
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
const search = await context.lucern.beliefs.search({
|
|
78
|
-
limit: 5,
|
|
79
|
-
query: "time-to-first-belief",
|
|
80
|
-
topicId: topic.topicId,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
quickstart: {
|
|
85
|
-
beliefId,
|
|
86
|
-
evidenceId,
|
|
87
|
-
forkId,
|
|
88
|
-
resultCount: search.results.length,
|
|
89
|
-
searchResults: search.results.map((result) => ({
|
|
90
|
-
canonicalText: result.canonicalText,
|
|
91
|
-
confidence: result.confidence,
|
|
92
|
-
nodeId: result.nodeId,
|
|
93
|
-
})),
|
|
94
|
-
},
|
|
95
|
-
topic,
|
|
96
|
-
};
|
|
97
|
-
});
|
package/examples/shared.ts
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
3
|
-
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
4
|
-
import {
|
|
5
|
-
createGatewayRequestClient,
|
|
6
|
-
createLucernClient,
|
|
7
|
-
LucernApiError,
|
|
8
|
-
} from "../src/index.js";
|
|
9
|
-
|
|
10
|
-
type AnyRecord = Record<string, unknown>;
|
|
11
|
-
|
|
12
|
-
export type ExampleEnv = {
|
|
13
|
-
apiKey: string;
|
|
14
|
-
baseTopicId: string;
|
|
15
|
-
baseUrl: string;
|
|
16
|
-
environment: "production" | "sandbox";
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export type ExampleContext = {
|
|
20
|
-
env: ExampleEnv;
|
|
21
|
-
gateway: ReturnType<typeof createGatewayRequestClient>;
|
|
22
|
-
lucern: ReturnType<typeof createLucernClient>;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
function asRecord(value: unknown): AnyRecord {
|
|
26
|
-
return value && typeof value === "object" ? (value as AnyRecord) : {};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function normalizeEnvironment(
|
|
30
|
-
value: string | undefined
|
|
31
|
-
): "production" | "sandbox" {
|
|
32
|
-
const normalized = value?.trim().toLowerCase();
|
|
33
|
-
if (
|
|
34
|
-
normalized === "sandbox" ||
|
|
35
|
-
normalized === "preview" ||
|
|
36
|
-
normalized === "development"
|
|
37
|
-
) {
|
|
38
|
-
return "sandbox";
|
|
39
|
-
}
|
|
40
|
-
return "production";
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function readEnv(...names: string[]): string | undefined {
|
|
44
|
-
for (const name of names) {
|
|
45
|
-
const value = process.env[name];
|
|
46
|
-
if (typeof value === "string" && value.trim().length > 0) {
|
|
47
|
-
return value.trim();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function requireEnv(label: string, ...names: string[]): string {
|
|
54
|
-
const value = readEnv(...names);
|
|
55
|
-
if (!value) {
|
|
56
|
-
throw new Error(
|
|
57
|
-
`Missing required env var for ${label}: ${names.join(" or ")}`
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
return value;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function parseMcpPayload(result: unknown): unknown {
|
|
64
|
-
const record = asRecord(result);
|
|
65
|
-
const content = Array.isArray(record.content) ? record.content : [];
|
|
66
|
-
const first = content[0];
|
|
67
|
-
const text =
|
|
68
|
-
typeof asRecord(first).text === "string"
|
|
69
|
-
? String(asRecord(first).text)
|
|
70
|
-
: "";
|
|
71
|
-
if (!text) {
|
|
72
|
-
return result;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
return JSON.parse(text) as unknown;
|
|
77
|
-
} catch {
|
|
78
|
-
return text;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function slugify(value: string): string {
|
|
83
|
-
return value
|
|
84
|
-
.toLowerCase()
|
|
85
|
-
.replace(/[^a-z0-9]+/g, "-")
|
|
86
|
-
.replace(/^-+|-+$/g, "")
|
|
87
|
-
.slice(0, 48);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function loadExampleEnv(): ExampleEnv {
|
|
91
|
-
return {
|
|
92
|
-
apiKey: requireEnv("API key", "LUCERN_API_KEY", "LUCERN_KEY"),
|
|
93
|
-
baseTopicId: requireEnv(
|
|
94
|
-
"base topic",
|
|
95
|
-
"LUCERN_TOPIC_ID",
|
|
96
|
-
"LUCERN_PROJECT_ID"
|
|
97
|
-
),
|
|
98
|
-
baseUrl: requireEnv(
|
|
99
|
-
"deployment URL",
|
|
100
|
-
"LUCERN_BASE_URL",
|
|
101
|
-
"LUCERN_API_BASE_URL"
|
|
102
|
-
),
|
|
103
|
-
environment: normalizeEnvironment(
|
|
104
|
-
readEnv("LUCERN_ENVIRONMENT", "LUCERN_API_ENVIRONMENT")
|
|
105
|
-
),
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function createExampleContext(): ExampleContext {
|
|
110
|
-
const env = loadExampleEnv();
|
|
111
|
-
const getAuthHeaders = async () => ({
|
|
112
|
-
"x-lucern-environment": env.environment,
|
|
113
|
-
"x-lucern-key": env.apiKey,
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
env,
|
|
118
|
-
gateway: createGatewayRequestClient({
|
|
119
|
-
baseUrl: env.baseUrl,
|
|
120
|
-
getAuthHeaders,
|
|
121
|
-
}),
|
|
122
|
-
lucern: createLucernClient({
|
|
123
|
-
apiKey: env.apiKey,
|
|
124
|
-
baseUrl: env.baseUrl,
|
|
125
|
-
environment: env.environment,
|
|
126
|
-
}),
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function listItems<T = AnyRecord>(
|
|
131
|
-
value: unknown,
|
|
132
|
-
legacyKey?: string
|
|
133
|
-
): T[] {
|
|
134
|
-
if (Array.isArray(value)) {
|
|
135
|
-
return value as T[];
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const record = asRecord(value);
|
|
139
|
-
if (Array.isArray(record.items)) {
|
|
140
|
-
return record.items as T[];
|
|
141
|
-
}
|
|
142
|
-
if (legacyKey && Array.isArray(record[legacyKey])) {
|
|
143
|
-
return record[legacyKey] as T[];
|
|
144
|
-
}
|
|
145
|
-
return [];
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export function readStringField(
|
|
149
|
-
value: unknown,
|
|
150
|
-
keys: string[]
|
|
151
|
-
): string | undefined {
|
|
152
|
-
const record = asRecord(value);
|
|
153
|
-
for (const key of keys) {
|
|
154
|
-
const candidate = record[key];
|
|
155
|
-
if (typeof candidate === "string" && candidate.trim().length > 0) {
|
|
156
|
-
return candidate.trim();
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export function requireStringField(
|
|
163
|
-
value: unknown,
|
|
164
|
-
keys: string[],
|
|
165
|
-
label: string
|
|
166
|
-
): string {
|
|
167
|
-
const resolved = readStringField(value, keys);
|
|
168
|
-
if (!resolved) {
|
|
169
|
-
throw new Error(`Unable to resolve ${label} from response payload.`);
|
|
170
|
-
}
|
|
171
|
-
return resolved;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export function summarizeError(error: unknown): AnyRecord {
|
|
175
|
-
if (error instanceof LucernApiError) {
|
|
176
|
-
return {
|
|
177
|
-
type: error.name,
|
|
178
|
-
code: error.code,
|
|
179
|
-
status: error.status,
|
|
180
|
-
message: error.message,
|
|
181
|
-
invariant: error.invariant ?? null,
|
|
182
|
-
suggestion: error.suggestion ?? null,
|
|
183
|
-
correlationId: error.correlationId ?? null,
|
|
184
|
-
policyTraceId: error.policyTraceId ?? null,
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (error instanceof Error) {
|
|
189
|
-
return {
|
|
190
|
-
type: error.name,
|
|
191
|
-
message: error.message,
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return {
|
|
196
|
-
type: "UnknownError",
|
|
197
|
-
message: String(error),
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export function printJson(payload: unknown): void {
|
|
202
|
-
console.log(JSON.stringify(payload, null, 2));
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export async function createExampleTopic(
|
|
206
|
-
context: ExampleContext,
|
|
207
|
-
label: string
|
|
208
|
-
): Promise<{
|
|
209
|
-
name: string;
|
|
210
|
-
parentTopicId: string;
|
|
211
|
-
raw: unknown;
|
|
212
|
-
topicId: string;
|
|
213
|
-
}> {
|
|
214
|
-
const suffix = `${slugify(label)}-${randomUUID().slice(0, 8)}`;
|
|
215
|
-
const response = await context.gateway.request<AnyRecord>({
|
|
216
|
-
path: "/api/platform/v1/topics",
|
|
217
|
-
method: "POST",
|
|
218
|
-
body: {
|
|
219
|
-
description: `Created by lucern/packages/sdk/examples/${slugify(label)}.ts`,
|
|
220
|
-
name: `SDK Example ${suffix}`,
|
|
221
|
-
parentTopicId: context.env.baseTopicId,
|
|
222
|
-
type: "project",
|
|
223
|
-
},
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
const topicId = requireStringField(
|
|
227
|
-
response.data,
|
|
228
|
-
["topicId", "_id", "id"],
|
|
229
|
-
"topicId"
|
|
230
|
-
);
|
|
231
|
-
|
|
232
|
-
return {
|
|
233
|
-
topicId,
|
|
234
|
-
name: readStringField(response.data, ["name"]) ?? `SDK Example ${suffix}`,
|
|
235
|
-
parentTopicId: context.env.baseTopicId,
|
|
236
|
-
raw: response.data,
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
export async function callHostedMcpTool(
|
|
241
|
-
context: ExampleContext,
|
|
242
|
-
name: string,
|
|
243
|
-
args: Record<string, unknown>
|
|
244
|
-
): Promise<{
|
|
245
|
-
endpoint: string;
|
|
246
|
-
ok: boolean;
|
|
247
|
-
payload: unknown;
|
|
248
|
-
raw: unknown;
|
|
249
|
-
}> {
|
|
250
|
-
const endpoint = new URL("/api/platform/mcp", context.env.baseUrl);
|
|
251
|
-
const transport = new StreamableHTTPClientTransport(endpoint, {
|
|
252
|
-
requestInit: {
|
|
253
|
-
headers: {
|
|
254
|
-
"x-lucern-environment": context.env.environment,
|
|
255
|
-
"x-lucern-key": context.env.apiKey,
|
|
256
|
-
},
|
|
257
|
-
},
|
|
258
|
-
});
|
|
259
|
-
const client = new Client({
|
|
260
|
-
name: `sdk-example-${slugify(name)}`,
|
|
261
|
-
version: "0.1.0",
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
try {
|
|
265
|
-
await client.connect(transport);
|
|
266
|
-
const result = await client.callTool({
|
|
267
|
-
name,
|
|
268
|
-
arguments: args,
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
return {
|
|
272
|
-
endpoint: endpoint.toString(),
|
|
273
|
-
ok: result.isError !== true,
|
|
274
|
-
payload: parseMcpPayload(result),
|
|
275
|
-
raw: result,
|
|
276
|
-
};
|
|
277
|
-
} catch (error) {
|
|
278
|
-
return {
|
|
279
|
-
endpoint: endpoint.toString(),
|
|
280
|
-
ok: false,
|
|
281
|
-
payload: summarizeError(error),
|
|
282
|
-
raw: null,
|
|
283
|
-
};
|
|
284
|
-
} finally {
|
|
285
|
-
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional swallow on cleanup
|
|
286
|
-
await client.close().catch(() => {});
|
|
287
|
-
// biome-ignore lint/suspicious/noEmptyBlockStatements: intentional swallow on cleanup
|
|
288
|
-
await transport.close().catch(() => {});
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
export async function runExample(
|
|
293
|
-
name: string,
|
|
294
|
-
executor: (context: ExampleContext) => Promise<AnyRecord>
|
|
295
|
-
): Promise<void> {
|
|
296
|
-
const startedAt = Date.now();
|
|
297
|
-
const context = createExampleContext();
|
|
298
|
-
|
|
299
|
-
try {
|
|
300
|
-
const result = await executor(context);
|
|
301
|
-
printJson({
|
|
302
|
-
example: name,
|
|
303
|
-
status: "ok",
|
|
304
|
-
durationMs: Date.now() - startedAt,
|
|
305
|
-
environment: context.env.environment,
|
|
306
|
-
...result,
|
|
307
|
-
});
|
|
308
|
-
} catch (error) {
|
|
309
|
-
printJson({
|
|
310
|
-
example: name,
|
|
311
|
-
status: "error",
|
|
312
|
-
durationMs: Date.now() - startedAt,
|
|
313
|
-
environment: context.env.environment,
|
|
314
|
-
error: summarizeError(error),
|
|
315
|
-
});
|
|
316
|
-
process.exit(1);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AudienceGrantInput,
|
|
3
|
-
CreateBeliefInput,
|
|
4
|
-
CreateEdgeInput,
|
|
5
|
-
CreateNodeInput,
|
|
6
|
-
HarnessAgentWriteInput,
|
|
7
|
-
HarnessRunReportInput,
|
|
8
|
-
PackInstallInput,
|
|
9
|
-
PlatformBeliefRecord,
|
|
10
|
-
PlatformGraphEdge,
|
|
11
|
-
PlatformGraphNode,
|
|
12
|
-
WorkflowWorktreeRecord,
|
|
13
|
-
} from "../src";
|
|
14
|
-
|
|
15
|
-
type HasUnknownStringIndex<T> = string extends keyof T
|
|
16
|
-
? unknown extends T[string]
|
|
17
|
-
? true
|
|
18
|
-
: false
|
|
19
|
-
: false;
|
|
20
|
-
|
|
21
|
-
type AssertFalse<T extends false> = T;
|
|
22
|
-
|
|
23
|
-
type _platformBeliefRecordHasNoUnknownIndex = AssertFalse<
|
|
24
|
-
HasUnknownStringIndex<PlatformBeliefRecord>
|
|
25
|
-
>;
|
|
26
|
-
type _platformGraphNodeHasNoUnknownIndex = AssertFalse<
|
|
27
|
-
HasUnknownStringIndex<PlatformGraphNode>
|
|
28
|
-
>;
|
|
29
|
-
type _platformGraphEdgeHasNoUnknownIndex = AssertFalse<
|
|
30
|
-
HasUnknownStringIndex<PlatformGraphEdge>
|
|
31
|
-
>;
|
|
32
|
-
type _workflowWorktreeRecordHasNoUnknownIndex = AssertFalse<
|
|
33
|
-
HasUnknownStringIndex<WorkflowWorktreeRecord>
|
|
34
|
-
>;
|
|
35
|
-
type _createBeliefInputHasNoUnknownIndex = AssertFalse<
|
|
36
|
-
HasUnknownStringIndex<CreateBeliefInput>
|
|
37
|
-
>;
|
|
38
|
-
type _createNodeInputHasNoUnknownIndex = AssertFalse<
|
|
39
|
-
HasUnknownStringIndex<CreateNodeInput>
|
|
40
|
-
>;
|
|
41
|
-
type _createEdgeInputHasNoUnknownIndex = AssertFalse<
|
|
42
|
-
HasUnknownStringIndex<CreateEdgeInput>
|
|
43
|
-
>;
|
|
44
|
-
type _packInstallInputHasNoUnknownIndex = AssertFalse<
|
|
45
|
-
HasUnknownStringIndex<PackInstallInput>
|
|
46
|
-
>;
|
|
47
|
-
type _audienceGrantInputHasNoUnknownIndex = AssertFalse<
|
|
48
|
-
HasUnknownStringIndex<AudienceGrantInput>
|
|
49
|
-
>;
|
|
50
|
-
type _harnessAgentWriteInputHasNoUnknownIndex = AssertFalse<
|
|
51
|
-
HasUnknownStringIndex<HarnessAgentWriteInput>
|
|
52
|
-
>;
|
|
53
|
-
type _harnessRunReportInputHasNoUnknownIndex = AssertFalse<
|
|
54
|
-
HasUnknownStringIndex<HarnessRunReportInput>
|
|
55
|
-
>;
|
|
56
|
-
|
|
57
|
-
const createBeliefInput: CreateBeliefInput = {
|
|
58
|
-
canonicalText: "Strict SDK public types compile against JSON metadata.",
|
|
59
|
-
topicId: "topic_123",
|
|
60
|
-
metadata: {
|
|
61
|
-
source: "sdk",
|
|
62
|
-
tags: ["strict", "types"],
|
|
63
|
-
nested: {
|
|
64
|
-
enabled: true,
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const createNodeInput: CreateNodeInput = {
|
|
70
|
-
canonicalText: "Belief node",
|
|
71
|
-
nodeType: "belief",
|
|
72
|
-
metadata: {
|
|
73
|
-
scope: "sdk",
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const createEdgeInput: CreateEdgeInput = {
|
|
78
|
-
fromNodeId: "node_a",
|
|
79
|
-
toNodeId: "node_b",
|
|
80
|
-
edgeType: "tests",
|
|
81
|
-
weight: 0.75,
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const packInstallInput: PackInstallInput = {
|
|
85
|
-
tenantId: "tenant_123",
|
|
86
|
-
packKey: "strict-types",
|
|
87
|
-
metadata: {
|
|
88
|
-
actor: "sdk",
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const audienceGrantInput: AudienceGrantInput = {
|
|
93
|
-
audienceKey: "developers",
|
|
94
|
-
principalId: "principal_123",
|
|
95
|
-
metadata: {
|
|
96
|
-
source: "sdk",
|
|
97
|
-
},
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const harnessAgentInput: HarnessAgentWriteInput = {
|
|
101
|
-
tenantId: "tenant_123",
|
|
102
|
-
agentKey: "sdk-audit",
|
|
103
|
-
displayName: "SDK Audit",
|
|
104
|
-
description: "Compile-time type contract audit",
|
|
105
|
-
version: "0.0.1",
|
|
106
|
-
executionAdapter: "sdk_invocation",
|
|
107
|
-
parameterSchema: {
|
|
108
|
-
type: "object",
|
|
109
|
-
},
|
|
110
|
-
exampleInvocations: [
|
|
111
|
-
{
|
|
112
|
-
input: {
|
|
113
|
-
query: "strict types",
|
|
114
|
-
},
|
|
115
|
-
expectedOutput: {
|
|
116
|
-
ok: true,
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
const harnessRunReportInput: HarnessRunReportInput = {
|
|
123
|
-
reportingToken: "token_123",
|
|
124
|
-
type: "tool_call",
|
|
125
|
-
toolName: "search_beliefs",
|
|
126
|
-
input: {
|
|
127
|
-
query: "strict types",
|
|
128
|
-
},
|
|
129
|
-
result: {
|
|
130
|
-
success: true,
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
// Export type-check fixtures so the compiler verifies them without void expressions
|
|
135
|
-
export {
|
|
136
|
-
createBeliefInput,
|
|
137
|
-
createNodeInput,
|
|
138
|
-
createEdgeInput,
|
|
139
|
-
packInstallInput,
|
|
140
|
-
audienceGrantInput,
|
|
141
|
-
harnessAgentInput,
|
|
142
|
-
harnessRunReportInput,
|
|
143
|
-
};
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createExampleTopic,
|
|
3
|
-
listItems,
|
|
4
|
-
requireStringField,
|
|
5
|
-
runExample,
|
|
6
|
-
slugify,
|
|
7
|
-
} from "./shared.js";
|
|
8
|
-
|
|
9
|
-
runExample("worktree-lifecycle", async (context) => {
|
|
10
|
-
const topic = await createExampleTopic(context, "worktree-lifecycle");
|
|
11
|
-
|
|
12
|
-
const branchName = `sdk-example-${slugify(topic.name)}-${Date.now()}`;
|
|
13
|
-
const branch = await context.lucern.worktrees.createBranch({
|
|
14
|
-
description: "Branch for the SDK worktree lifecycle example.",
|
|
15
|
-
name: branchName,
|
|
16
|
-
topicId: topic.topicId,
|
|
17
|
-
});
|
|
18
|
-
const branchId = requireStringField(
|
|
19
|
-
branch.data,
|
|
20
|
-
["branchId", "nodeId"],
|
|
21
|
-
"branchId"
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
const belief = await context.lucern.beliefs.create({
|
|
25
|
-
text: "A short-lived worktree lets SDK adopters test a belief without mutating scored state.",
|
|
26
|
-
topicId: topic.topicId,
|
|
27
|
-
});
|
|
28
|
-
const beliefId = requireStringField(
|
|
29
|
-
belief.data,
|
|
30
|
-
["nodeId", "globalId"],
|
|
31
|
-
"beliefId"
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
const worktree = await context.lucern.worktrees.create({
|
|
35
|
-
beliefIds: [beliefId],
|
|
36
|
-
branchId,
|
|
37
|
-
gate: "gate:sdk-example-worktree",
|
|
38
|
-
hypothesis:
|
|
39
|
-
"A lightweight worktree example makes the draft-to-merge lifecycle concrete.",
|
|
40
|
-
objective: "Demonstrate worktree creation from the public SDK surface.",
|
|
41
|
-
title: "SDK Example Worktree Lifecycle",
|
|
42
|
-
topicId: topic.topicId,
|
|
43
|
-
});
|
|
44
|
-
const worktreeId = requireStringField(
|
|
45
|
-
worktree.data,
|
|
46
|
-
["worktreeId", "nodeId"],
|
|
47
|
-
"worktreeId"
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const activation = await context.lucern.worktrees.activate(worktreeId);
|
|
51
|
-
|
|
52
|
-
const listed = await context.lucern.worktrees.list({
|
|
53
|
-
topicId: topic.topicId,
|
|
54
|
-
});
|
|
55
|
-
const visibleWorktrees = listItems<Record<string, unknown>>(
|
|
56
|
-
listed.data,
|
|
57
|
-
"worktrees"
|
|
58
|
-
)
|
|
59
|
-
.filter((entry) => entry.worktreeId === worktreeId)
|
|
60
|
-
.map((entry) => ({
|
|
61
|
-
status: typeof entry.status === "string" ? entry.status : null,
|
|
62
|
-
title: typeof entry.title === "string" ? entry.title : null,
|
|
63
|
-
worktreeId:
|
|
64
|
-
typeof entry.worktreeId === "string" ? entry.worktreeId : worktreeId,
|
|
65
|
-
}));
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
activation: activation.data,
|
|
69
|
-
branch: {
|
|
70
|
-
branchId,
|
|
71
|
-
name: branchName,
|
|
72
|
-
},
|
|
73
|
-
topic,
|
|
74
|
-
worktree: {
|
|
75
|
-
visibleWorktrees,
|
|
76
|
-
worktreeId,
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
});
|