@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.
Files changed (257) hide show
  1. package/dist/adminClient.d.ts +409 -0
  2. package/dist/adminClient.js +755 -0
  3. package/dist/adminClient.js.map +1 -0
  4. package/dist/answersClient.d.ts +23 -0
  5. package/dist/answersClient.js +333 -0
  6. package/dist/answersClient.js.map +1 -0
  7. package/dist/audiencesClient.d.ts +99 -0
  8. package/dist/audiencesClient.js +472 -0
  9. package/dist/audiencesClient.js.map +1 -0
  10. package/dist/auditClient.d.ts +29 -0
  11. package/dist/auditClient.js +386 -0
  12. package/dist/auditClient.js.map +1 -0
  13. package/dist/beliefsClient.d.ts +162 -0
  14. package/dist/beliefsClient.js +477 -0
  15. package/dist/beliefsClient.js.map +1 -0
  16. package/dist/client.d.ts +2378 -0
  17. package/dist/client.js +6134 -0
  18. package/dist/client.js.map +1 -0
  19. package/dist/contextClient.d.ts +27 -0
  20. package/dist/contextClient.js +396 -0
  21. package/dist/contextClient.js.map +1 -0
  22. package/dist/contextFacade.d.ts +2 -0
  23. package/dist/contextFacade.js +73 -0
  24. package/dist/contextFacade.js.map +1 -0
  25. package/dist/contextPackCompiler.d.ts +102 -0
  26. package/dist/contextPackCompiler.js +1091 -0
  27. package/dist/contextPackCompiler.js.map +1 -0
  28. package/dist/contextPackPolicy.d.ts +84 -0
  29. package/dist/contextPackPolicy.js +347 -0
  30. package/dist/contextPackPolicy.js.map +1 -0
  31. package/dist/contextPackSchema.d.ts +7 -0
  32. package/{src/contextPackSchema.ts → dist/contextPackSchema.js} +22 -70
  33. package/dist/contextPackSchema.js.map +1 -0
  34. package/dist/contextTypes.d.ts +135 -0
  35. package/dist/contextTypes.js +3 -0
  36. package/dist/contextTypes.js.map +1 -0
  37. package/dist/contracts/api-enums.contract.d.ts +81 -0
  38. package/dist/contracts/api-enums.contract.js +92 -0
  39. package/dist/contracts/api-enums.contract.js.map +1 -0
  40. package/dist/contracts/auth-session.contract.d.ts +55 -0
  41. package/dist/contracts/auth-session.contract.js +48 -0
  42. package/dist/contracts/auth-session.contract.js.map +1 -0
  43. package/dist/contracts/context-pack.contract.d.ts +492 -0
  44. package/dist/contracts/context-pack.contract.js +98 -0
  45. package/dist/contracts/context-pack.contract.js.map +1 -0
  46. package/dist/contracts/contextPack.d.ts +1 -0
  47. package/dist/contracts/contextPack.js +98 -0
  48. package/dist/contracts/contextPack.js.map +1 -0
  49. package/dist/contracts/index.d.ts +9 -0
  50. package/dist/contracts/index.js +4892 -0
  51. package/dist/contracts/index.js.map +1 -0
  52. package/dist/contracts/lens-filter.contract.d.ts +72 -0
  53. package/dist/contracts/lens-filter.contract.js +71 -0
  54. package/dist/contracts/lens-filter.contract.js.map +1 -0
  55. package/dist/contracts/lens-workflow.contract.d.ts +87 -0
  56. package/dist/contracts/lens-workflow.contract.js +123 -0
  57. package/dist/contracts/lens-workflow.contract.js.map +1 -0
  58. package/dist/contracts/lensFilter.d.ts +1 -0
  59. package/dist/contracts/lensFilter.js +71 -0
  60. package/dist/contracts/lensFilter.js.map +1 -0
  61. package/dist/contracts/lensWorkflow.d.ts +2 -0
  62. package/dist/contracts/lensWorkflow.js +123 -0
  63. package/dist/contracts/lensWorkflow.js.map +1 -0
  64. package/dist/contracts/mcp-tools.contract.d.ts +1 -0
  65. package/dist/contracts/mcp-tools.contract.js +2986 -0
  66. package/dist/contracts/mcp-tools.contract.js.map +1 -0
  67. package/dist/contracts/mcpTools.d.ts +1 -0
  68. package/dist/contracts/mcpTools.js +2986 -0
  69. package/dist/contracts/mcpTools.js.map +1 -0
  70. package/dist/contracts/prompt.contract.d.ts +26 -0
  71. package/dist/contracts/prompt.contract.js +12 -0
  72. package/dist/contracts/prompt.contract.js.map +1 -0
  73. package/dist/contracts/prompt.d.ts +1 -0
  74. package/dist/contracts/prompt.js +12 -0
  75. package/dist/contracts/prompt.js.map +1 -0
  76. package/dist/contracts/sdk-tools.contract.d.ts +2 -0
  77. package/dist/contracts/sdk-tools.contract.js +4134 -0
  78. package/dist/contracts/sdk-tools.contract.js.map +1 -0
  79. package/dist/contracts/sdkTools.d.ts +2 -0
  80. package/dist/contracts/sdkTools.js +4134 -0
  81. package/dist/contracts/sdkTools.js.map +1 -0
  82. package/dist/contracts/workflow-runtime.contract.d.ts +163 -0
  83. package/dist/contracts/workflow-runtime.contract.js +245 -0
  84. package/dist/contracts/workflow-runtime.contract.js.map +1 -0
  85. package/dist/contracts/workflowRuntime.d.ts +1 -0
  86. package/dist/contracts/workflowRuntime.js +245 -0
  87. package/dist/contracts/workflowRuntime.js.map +1 -0
  88. package/dist/controlObjectOwnership.d.ts +310 -0
  89. package/{src/controlObjectOwnership.ts → dist/controlObjectOwnership.js} +53 -124
  90. package/dist/controlObjectOwnership.js.map +1 -0
  91. package/dist/coreClient.d.ts +144 -0
  92. package/dist/coreClient.js +339 -0
  93. package/dist/coreClient.js.map +1 -0
  94. package/dist/customTools.d.ts +88 -0
  95. package/dist/customTools.js +248 -0
  96. package/dist/customTools.js.map +1 -0
  97. package/dist/decisionsClient.d.ts +111 -0
  98. package/dist/decisionsClient.js +522 -0
  99. package/dist/decisionsClient.js.map +1 -0
  100. package/dist/domainContext.d.ts +1 -0
  101. package/dist/domainContext.js +3 -0
  102. package/dist/domainContext.js.map +1 -0
  103. package/dist/events.d.ts +178 -0
  104. package/dist/events.js +249 -0
  105. package/dist/events.js.map +1 -0
  106. package/dist/eventsCore.d.ts +49 -0
  107. package/dist/eventsCore.js +429 -0
  108. package/dist/eventsCore.js.map +1 -0
  109. package/dist/facade/context.d.ts +18 -0
  110. package/dist/facade/context.js +73 -0
  111. package/dist/facade/context.js.map +1 -0
  112. package/dist/gatewayFacades.d.ts +591 -0
  113. package/dist/gatewayFacades.js +1953 -0
  114. package/dist/gatewayFacades.js.map +1 -0
  115. package/dist/graphClient.d.ts +271 -0
  116. package/dist/graphClient.js +698 -0
  117. package/dist/graphClient.js.map +1 -0
  118. package/dist/harnessClient.d.ts +314 -0
  119. package/dist/harnessClient.js +607 -0
  120. package/dist/harnessClient.js.map +1 -0
  121. package/dist/identityClient.d.ts +140 -0
  122. package/dist/identityClient.js +497 -0
  123. package/dist/identityClient.js.map +1 -0
  124. package/dist/index.d.ts +42 -0
  125. package/dist/index.js +11381 -0
  126. package/dist/index.js.map +1 -0
  127. package/dist/learningClient.d.ts +46 -0
  128. package/dist/learningClient.js +409 -0
  129. package/dist/learningClient.js.map +1 -0
  130. package/dist/mcpParityClient.d.ts +74 -0
  131. package/dist/mcpParityClient.js +516 -0
  132. package/dist/mcpParityClient.js.map +1 -0
  133. package/dist/mcpParitySurface.d.ts +12 -0
  134. package/{src/mcpParitySurface.ts → dist/mcpParitySurface.js} +9 -14
  135. package/dist/mcpParitySurface.js.map +1 -0
  136. package/dist/mcpTools-DPZxowDX.d.ts +254 -0
  137. package/dist/ontologyClient.d.ts +137 -0
  138. package/dist/ontologyClient.js +513 -0
  139. package/dist/ontologyClient.js.map +1 -0
  140. package/dist/packRuntime.d.ts +2 -0
  141. package/dist/packRuntime.js +3 -0
  142. package/dist/packRuntime.js.map +1 -0
  143. package/dist/packsClient.d.ts +131 -0
  144. package/dist/packsClient.js +525 -0
  145. package/dist/packsClient.js.map +1 -0
  146. package/dist/policyClient.d.ts +299 -0
  147. package/dist/policyClient.js +625 -0
  148. package/dist/policyClient.js.map +1 -0
  149. package/dist/realtime/index.d.ts +29 -0
  150. package/dist/realtime/index.js +23 -0
  151. package/dist/realtime/index.js.map +1 -0
  152. package/{src/realtime/refs.ts → dist/realtime/refs.d.ts} +5 -5
  153. package/dist/realtime/refs.js +9 -0
  154. package/dist/realtime/refs.js.map +1 -0
  155. package/dist/reportsClient.d.ts +41 -0
  156. package/dist/reportsClient.js +418 -0
  157. package/dist/reportsClient.js.map +1 -0
  158. package/dist/schemaClient.d.ts +64 -0
  159. package/dist/schemaClient.js +434 -0
  160. package/dist/schemaClient.js.map +1 -0
  161. package/dist/sdkSurface.d.ts +61 -0
  162. package/dist/sdkSurface.js +112 -0
  163. package/dist/sdkSurface.js.map +1 -0
  164. package/dist/sdkTools-CwXJDACb.d.ts +150 -0
  165. package/dist/topicsClient.d.ts +84 -0
  166. package/dist/topicsClient.js +492 -0
  167. package/dist/topicsClient.js.map +1 -0
  168. package/dist/types.d.ts +696 -0
  169. package/dist/types.js +3 -0
  170. package/dist/types.js.map +1 -0
  171. package/dist/version.d.ts +4 -0
  172. package/dist/version.js +6 -0
  173. package/dist/version.js.map +1 -0
  174. package/dist/workflowClient.d.ts +316 -0
  175. package/dist/workflowClient.js +830 -0
  176. package/dist/workflowClient.js.map +1 -0
  177. package/package.json +31 -7
  178. package/.turbo/turbo-build.log +0 -7
  179. package/.turbo/turbo-typecheck.log +0 -4
  180. package/examples/README.md +0 -69
  181. package/examples/contradiction.ts +0 -94
  182. package/examples/investigation-context.ts +0 -118
  183. package/examples/questions-and-tasks.ts +0 -55
  184. package/examples/quickstart.ts +0 -97
  185. package/examples/shared.ts +0 -318
  186. package/examples/strict-public-types.ts +0 -143
  187. package/examples/worktree-lifecycle.ts +0 -79
  188. package/src/README.md +0 -6
  189. package/src/adminClient.ts +0 -789
  190. package/src/answersClient.ts +0 -29
  191. package/src/audiencesClient.ts +0 -209
  192. package/src/auditClient.ts +0 -50
  193. package/src/beliefsClient.ts +0 -319
  194. package/src/client.ts +0 -2647
  195. package/src/contextClient.ts +0 -130
  196. package/src/contextFacade.ts +0 -15
  197. package/src/contextPackCompiler.ts +0 -828
  198. package/src/contextTypes.ts +0 -153
  199. package/src/contracts/api-enums.contract.ts +0 -202
  200. package/src/contracts/auth-session.contract.ts +0 -109
  201. package/src/contracts/context-pack.contract.ts +0 -700
  202. package/src/contracts/contextPack.ts +0 -1
  203. package/src/contracts/index.ts +0 -10
  204. package/src/contracts/lens-filter.contract.ts +0 -183
  205. package/src/contracts/lens-workflow.contract.ts +0 -162
  206. package/src/contracts/lensFilter.ts +0 -1
  207. package/src/contracts/lensWorkflow.ts +0 -1
  208. package/src/contracts/mcp-tools.contract.ts +0 -3636
  209. package/src/contracts/mcpTools.ts +0 -1
  210. package/src/contracts/prompt.contract.ts +0 -50
  211. package/src/contracts/prompt.ts +0 -1
  212. package/src/contracts/sdk-tools.contract.ts +0 -1457
  213. package/src/contracts/sdkTools.ts +0 -1
  214. package/src/contracts/workflow-runtime.contract.ts +0 -440
  215. package/src/contracts/workflowRuntime.ts +0 -1
  216. package/src/coreClient.ts +0 -570
  217. package/src/customTools.ts +0 -398
  218. package/src/decisionsClient.ts +0 -286
  219. package/src/domainContext.ts +0 -15
  220. package/src/events.ts +0 -531
  221. package/src/eventsCore.ts +0 -168
  222. package/src/facade/beliefs.ts +0 -83
  223. package/src/facade/context.ts +0 -110
  224. package/src/facade/contradictions.ts +0 -29
  225. package/src/facade/edges.ts +0 -30
  226. package/src/facade/events.ts +0 -23
  227. package/src/facade/evidence.ts +0 -41
  228. package/src/facade/graph.ts +0 -38
  229. package/src/facade/identity.ts +0 -16
  230. package/src/facade/ontologies.ts +0 -34
  231. package/src/facade/questions.ts +0 -59
  232. package/src/facade/search.ts +0 -16
  233. package/src/facade/tasks.ts +0 -37
  234. package/src/facade/topics.ts +0 -42
  235. package/src/facade/webhooks.ts +0 -58
  236. package/src/facade/worktrees.ts +0 -51
  237. package/src/gatewayFacades.ts +0 -1666
  238. package/src/graphClient.ts +0 -529
  239. package/src/harnessClient.ts +0 -585
  240. package/src/identityClient.ts +0 -278
  241. package/src/index.ts +0 -49
  242. package/src/learningClient.ts +0 -95
  243. package/src/mcpParityClient.ts +0 -240
  244. package/src/ontologyClient.ts +0 -275
  245. package/src/packRuntime.ts +0 -3
  246. package/src/packsClient.ts +0 -260
  247. package/src/policyClient.ts +0 -572
  248. package/src/promptCatalog.ts +0 -1
  249. package/src/realtime/index.ts +0 -51
  250. package/src/reportsClient.ts +0 -99
  251. package/src/schemaClient.ts +0 -129
  252. package/src/sdkSurface.ts +0 -190
  253. package/src/topicsClient.ts +0 -243
  254. package/src/types.ts +0 -807
  255. package/src/version.ts +0 -2
  256. package/src/workflowClient.ts +0 -826
  257. package/tsconfig.json +0 -9
@@ -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
- });
@@ -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
- });
package/src/README.md DELETED
@@ -1,6 +0,0 @@
1
- # @lucern/sdk
2
-
3
- Official TypeScript SDK for the Lucern reasoning platform.
4
-
5
- Generated from and validated against `@lucern/contracts`.
6
- Migrates from `front-end/lucern/packages/sdk/`.