@lucern/sdk 0.2.0-alpha.5 → 0.2.0-alpha.7
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/.turbo/turbo-build.log +7 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/CHANGELOG.md +13 -0
- package/examples/README.md +69 -0
- package/examples/contradiction.ts +94 -0
- package/examples/investigation-context.ts +118 -0
- package/examples/questions-and-tasks.ts +55 -0
- package/examples/quickstart.ts +97 -0
- package/examples/shared.ts +318 -0
- package/examples/strict-public-types.ts +143 -0
- package/examples/worktree-lifecycle.ts +79 -0
- package/package.json +16 -59
- package/src/README.md +6 -0
- package/src/adminClient.ts +789 -0
- package/{dist/lib/platform/sdk/answersClient.d.ts → src/answersClient.ts} +17 -4
- package/src/audiencesClient.ts +209 -0
- package/src/auditClient.ts +50 -0
- package/src/beliefsClient.ts +319 -0
- package/src/client.ts +2647 -0
- package/src/contextClient.ts +130 -0
- package/src/contextFacade.ts +15 -0
- package/src/contextPackCompiler.ts +828 -0
- package/src/contextPackSchema.ts +251 -0
- package/src/contextTypes.ts +153 -0
- package/src/contracts/api-enums.contract.ts +202 -0
- package/src/contracts/auth-session.contract.ts +109 -0
- package/src/contracts/context-pack.contract.ts +700 -0
- package/src/contracts/contextPack.ts +1 -0
- package/src/contracts/index.ts +10 -0
- package/src/contracts/lens-filter.contract.ts +183 -0
- package/src/contracts/lens-workflow.contract.ts +162 -0
- package/src/contracts/lensFilter.ts +1 -0
- package/src/contracts/lensWorkflow.ts +1 -0
- package/src/contracts/mcp-tools.contract.ts +3636 -0
- package/src/contracts/mcpTools.ts +1 -0
- package/src/contracts/prompt.contract.ts +50 -0
- package/src/contracts/prompt.ts +1 -0
- package/src/contracts/sdk-tools.contract.ts +1457 -0
- package/src/contracts/sdkTools.ts +1 -0
- package/src/contracts/workflow-runtime.contract.ts +440 -0
- package/src/contracts/workflowRuntime.ts +1 -0
- package/src/controlObjectOwnership.ts +286 -0
- package/src/coreClient.ts +570 -0
- package/src/customTools.ts +398 -0
- package/src/decisionsClient.ts +286 -0
- package/src/domainContext.ts +15 -0
- package/src/events.ts +531 -0
- package/src/eventsCore.ts +168 -0
- package/src/facade/beliefs.ts +83 -0
- package/src/facade/context.ts +110 -0
- package/src/facade/contradictions.ts +29 -0
- package/src/facade/edges.ts +30 -0
- package/src/facade/events.ts +23 -0
- package/src/facade/evidence.ts +41 -0
- package/src/facade/graph.ts +38 -0
- package/src/facade/identity.ts +16 -0
- package/src/facade/ontologies.ts +34 -0
- package/src/facade/questions.ts +59 -0
- package/src/facade/search.ts +16 -0
- package/src/facade/tasks.ts +37 -0
- package/src/facade/topics.ts +42 -0
- package/src/facade/webhooks.ts +58 -0
- package/src/facade/worktrees.ts +51 -0
- package/src/gatewayFacades.ts +1666 -0
- package/src/graphClient.ts +529 -0
- package/src/harnessClient.ts +585 -0
- package/src/identityClient.ts +278 -0
- package/{dist/lib/platform/sdk/index.d.ts → src/index.ts} +3 -0
- package/src/learningClient.ts +95 -0
- package/src/mcpParityClient.ts +240 -0
- package/src/mcpParitySurface.ts +70 -0
- package/src/ontologyClient.ts +275 -0
- package/src/packRuntime.ts +3 -0
- package/src/packsClient.ts +260 -0
- package/src/policyClient.ts +572 -0
- package/src/promptCatalog.ts +1 -0
- package/src/realtime/index.ts +51 -0
- package/src/realtime/refs.ts +17 -0
- package/src/reportsClient.ts +99 -0
- package/src/schemaClient.ts +129 -0
- package/src/sdkSurface.ts +190 -0
- package/src/topicsClient.ts +243 -0
- package/src/types.ts +807 -0
- package/src/workflowClient.ts +826 -0
- package/tsconfig.json +9 -0
- package/dist/.generated +0 -2
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/dist/lib/platform/auth/credentials.d.ts +0 -5
- package/dist/lib/platform/auth/credentials.js +0 -40
- package/dist/lib/platform/sdk/adminClient.d.ts +0 -404
- package/dist/lib/platform/sdk/adminClient.js +0 -384
- package/dist/lib/platform/sdk/answersClient.js +0 -21
- package/dist/lib/platform/sdk/audiencesClient.d.ts +0 -93
- package/dist/lib/platform/sdk/audiencesClient.js +0 -111
- package/dist/lib/platform/sdk/auditClient.d.ts +0 -24
- package/dist/lib/platform/sdk/auditClient.js +0 -21
- package/dist/lib/platform/sdk/beliefsClient.d.ts +0 -157
- package/dist/lib/platform/sdk/beliefsClient.js +0 -124
- package/dist/lib/platform/sdk/client.d.ts +0 -2369
- package/dist/lib/platform/sdk/client.js +0 -1831
- package/dist/lib/platform/sdk/contextClient.d.ts +0 -21
- package/dist/lib/platform/sdk/contextClient.js +0 -86
- package/dist/lib/platform/sdk/contextPackCompiler.d.ts +0 -100
- package/dist/lib/platform/sdk/contextPackCompiler.js +0 -534
- package/dist/lib/platform/sdk/contextTypes.d.ts +0 -133
- package/dist/lib/platform/sdk/contextTypes.js +0 -1
- package/dist/lib/platform/sdk/controlObjectOwnership.d.ts +0 -308
- package/dist/lib/platform/sdk/controlObjectOwnership.js +0 -220
- package/dist/lib/platform/sdk/coreClient.d.ts +0 -139
- package/dist/lib/platform/sdk/coreClient.js +0 -366
- package/dist/lib/platform/sdk/customTools.d.ts +0 -83
- package/dist/lib/platform/sdk/customTools.js +0 -247
- package/dist/lib/platform/sdk/decisionsClient.d.ts +0 -106
- package/dist/lib/platform/sdk/decisionsClient.js +0 -129
- package/dist/lib/platform/sdk/domainContext.d.ts +0 -1
- package/dist/lib/platform/sdk/domainContext.js +0 -1
- package/dist/lib/platform/sdk/events.d.ts +0 -176
- package/dist/lib/platform/sdk/events.js +0 -261
- package/dist/lib/platform/sdk/gatewayFacades.d.ts +0 -586
- package/dist/lib/platform/sdk/gatewayFacades.js +0 -845
- package/dist/lib/platform/sdk/graphClient.d.ts +0 -266
- package/dist/lib/platform/sdk/graphClient.js +0 -235
- package/dist/lib/platform/sdk/harnessClient.d.ts +0 -309
- package/dist/lib/platform/sdk/harnessClient.js +0 -219
- package/dist/lib/platform/sdk/identityClient.d.ts +0 -134
- package/dist/lib/platform/sdk/identityClient.js +0 -131
- package/dist/lib/platform/sdk/index.js +0 -46
- package/dist/lib/platform/sdk/learningClient.d.ts +0 -40
- package/dist/lib/platform/sdk/learningClient.js +0 -53
- package/dist/lib/platform/sdk/mcpParityClient.d.ts +0 -69
- package/dist/lib/platform/sdk/mcpParityClient.js +0 -196
- package/dist/lib/platform/sdk/mcpParitySurface.d.ts +0 -10
- package/dist/lib/platform/sdk/mcpParitySurface.js +0 -57
- package/dist/lib/platform/sdk/ontologyClient.d.ts +0 -131
- package/dist/lib/platform/sdk/ontologyClient.js +0 -161
- package/dist/lib/platform/sdk/packRuntime.d.ts +0 -1
- package/dist/lib/platform/sdk/packRuntime.js +0 -1
- package/dist/lib/platform/sdk/packsClient.d.ts +0 -126
- package/dist/lib/platform/sdk/packsClient.js +0 -157
- package/dist/lib/platform/sdk/policyClient.d.ts +0 -293
- package/dist/lib/platform/sdk/policyClient.js +0 -277
- package/dist/lib/platform/sdk/promptCatalog.d.ts +0 -1
- package/dist/lib/platform/sdk/promptCatalog.js +0 -1
- package/dist/lib/platform/sdk/reportsClient.d.ts +0 -34
- package/dist/lib/platform/sdk/reportsClient.js +0 -64
- package/dist/lib/platform/sdk/schemaClient.d.ts +0 -59
- package/dist/lib/platform/sdk/schemaClient.js +0 -71
- package/dist/lib/platform/sdk/sdkSurface.d.ts +0 -56
- package/dist/lib/platform/sdk/sdkSurface.js +0 -140
- package/dist/lib/platform/sdk/topicsClient.d.ts +0 -78
- package/dist/lib/platform/sdk/topicsClient.js +0 -118
- package/dist/lib/platform/sdk/types.d.ts +0 -692
- package/dist/lib/platform/sdk/types.js +0 -1
- package/dist/lib/platform/sdk/version.d.ts +0 -2
- package/dist/lib/platform/sdk/workflowClient.d.ts +0 -313
- package/dist/lib/platform/sdk/workflowClient.js +0 -366
- package/dist/lucern/contracts/src/api-enums.contract.d.ts +0 -58
- package/dist/lucern/contracts/src/api-enums.contract.js +0 -147
- package/dist/lucern/contracts/src/lens-filter.contract.d.ts +0 -70
- package/dist/lucern/contracts/src/lens-filter.contract.js +0 -95
- package/dist/lucern/contracts/src/lens-workflow.contract.d.ts +0 -84
- package/dist/lucern/contracts/src/lens-workflow.contract.js +0 -54
- package/dist/lucern/contracts/src/mcp-tools.contract.d.ts +0 -151
- package/dist/lucern/contracts/src/mcp-tools.contract.js +0 -3281
- /package/{dist/lib/platform/sdk/version.js → src/version.ts} +0 -0
|
@@ -0,0 +1,318 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
});
|
package/package.json
CHANGED
|
@@ -1,70 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucern/sdk",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
4
|
-
"description": "Lucern reasoning platform SDK. Install this one package, provide your API key, and start building in 10 minutes.",
|
|
5
|
-
"license": "UNLICENSED",
|
|
3
|
+
"version": "0.2.0-alpha.7",
|
|
6
4
|
"type": "module",
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"types": "./dist/packages/sdk/src/index.d.ts",
|
|
10
|
-
"files": [
|
|
11
|
-
"dist",
|
|
12
|
-
"README.md"
|
|
13
|
-
],
|
|
14
|
-
"exports": {
|
|
15
|
-
".": {
|
|
16
|
-
"types": "./dist/packages/sdk/src/index.d.ts",
|
|
17
|
-
"import": "./dist/index.js"
|
|
18
|
-
},
|
|
19
|
-
"./realtime": {
|
|
20
|
-
"types": "./dist/packages/sdk/src/realtime/index.d.ts",
|
|
21
|
-
"import": "./dist/realtime.js"
|
|
22
|
-
},
|
|
23
|
-
"./realtime/refs": {
|
|
24
|
-
"types": "./dist/packages/sdk/src/realtime/refs.d.ts",
|
|
25
|
-
"import": "./dist/realtime-refs.js"
|
|
26
|
-
}
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "restricted"
|
|
27
7
|
},
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
8
|
+
"main": "src/index.ts",
|
|
9
|
+
"types": "src/index.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": "./src/index.ts",
|
|
12
|
+
"./contracts/*": "./src/contracts/*.ts",
|
|
13
|
+
"./*": "./src/*.ts"
|
|
31
14
|
},
|
|
32
15
|
"scripts": {
|
|
33
|
-
"build": "
|
|
34
|
-
"
|
|
35
|
-
"build:dts": "tsc --project tsconfig.bundle.json --declaration --emitDeclarationOnly --outDir dist",
|
|
36
|
-
"pack:dry-run": "npm pack --dry-run",
|
|
37
|
-
"prepack": "npm run build",
|
|
38
|
-
"typecheck": "tsc --project tsconfig.json --noEmit"
|
|
39
|
-
},
|
|
40
|
-
"dependencies": {},
|
|
41
|
-
"peerDependencies": {
|
|
42
|
-
"convex": ">=1.0.0",
|
|
43
|
-
"react": "^18.0.0 || ^19.0.0-0 || ^19.0.0"
|
|
16
|
+
"build": "tsup src/index.ts --format esm --dts",
|
|
17
|
+
"typecheck": "tsc --noEmit"
|
|
44
18
|
},
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"react": {
|
|
50
|
-
"optional": true
|
|
51
|
-
}
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@lucern/contracts": "workspace:*",
|
|
21
|
+
"@lucern/reasoning-kernel": "workspace:*",
|
|
22
|
+
"zod": "^3.25.76"
|
|
52
23
|
},
|
|
53
24
|
"devDependencies": {
|
|
54
|
-
"tsup": "^8.5.0",
|
|
55
25
|
"typescript": "^5.7.0"
|
|
56
|
-
}
|
|
57
|
-
"publishConfig": {
|
|
58
|
-
"access": "restricted"
|
|
59
|
-
},
|
|
60
|
-
"keywords": [
|
|
61
|
-
"lucern",
|
|
62
|
-
"reasoning",
|
|
63
|
-
"epistemic",
|
|
64
|
-
"beliefs",
|
|
65
|
-
"knowledge-graph",
|
|
66
|
-
"sdk",
|
|
67
|
-
"ai",
|
|
68
|
-
"agents"
|
|
69
|
-
]
|
|
26
|
+
}
|
|
70
27
|
}
|