@lucern/sdk 0.2.0-alpha.6 → 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.
Files changed (206) hide show
  1. package/.turbo/turbo-build.log +7 -0
  2. package/.turbo/turbo-typecheck.log +4 -0
  3. package/CHANGELOG.md +13 -0
  4. package/examples/README.md +69 -0
  5. package/examples/contradiction.ts +94 -0
  6. package/examples/investigation-context.ts +118 -0
  7. package/examples/questions-and-tasks.ts +55 -0
  8. package/examples/quickstart.ts +97 -0
  9. package/examples/shared.ts +318 -0
  10. package/examples/strict-public-types.ts +143 -0
  11. package/examples/worktree-lifecycle.ts +79 -0
  12. package/package.json +16 -58
  13. package/src/README.md +6 -0
  14. package/src/adminClient.ts +789 -0
  15. package/{dist/lib/platform/sdk/answersClient.d.ts → src/answersClient.ts} +17 -4
  16. package/src/audiencesClient.ts +209 -0
  17. package/src/auditClient.ts +50 -0
  18. package/src/beliefsClient.ts +319 -0
  19. package/src/client.ts +2647 -0
  20. package/src/contextClient.ts +130 -0
  21. package/{dist/lib/platform/sdk/contextFacade.d.ts → src/contextFacade.ts} +6 -1
  22. package/src/contextPackCompiler.ts +828 -0
  23. package/src/contextPackSchema.ts +251 -0
  24. package/src/contextTypes.ts +153 -0
  25. package/src/contracts/api-enums.contract.ts +202 -0
  26. package/src/contracts/auth-session.contract.ts +109 -0
  27. package/src/contracts/context-pack.contract.ts +700 -0
  28. package/src/contracts/contextPack.ts +1 -0
  29. package/src/contracts/index.ts +10 -0
  30. package/src/contracts/lens-filter.contract.ts +183 -0
  31. package/src/contracts/lens-workflow.contract.ts +162 -0
  32. package/src/contracts/lensFilter.ts +1 -0
  33. package/src/contracts/lensWorkflow.ts +1 -0
  34. package/src/contracts/mcp-tools.contract.ts +3636 -0
  35. package/src/contracts/mcpTools.ts +1 -0
  36. package/src/contracts/prompt.contract.ts +50 -0
  37. package/src/contracts/prompt.ts +1 -0
  38. package/src/contracts/sdk-tools.contract.ts +1457 -0
  39. package/src/contracts/sdkTools.ts +1 -0
  40. package/src/contracts/workflow-runtime.contract.ts +440 -0
  41. package/src/contracts/workflowRuntime.ts +1 -0
  42. package/src/controlObjectOwnership.ts +286 -0
  43. package/src/coreClient.ts +570 -0
  44. package/src/customTools.ts +398 -0
  45. package/src/decisionsClient.ts +286 -0
  46. package/src/domainContext.ts +15 -0
  47. package/src/events.ts +531 -0
  48. package/src/eventsCore.ts +168 -0
  49. package/src/facade/beliefs.ts +83 -0
  50. package/src/facade/context.ts +110 -0
  51. package/src/facade/contradictions.ts +29 -0
  52. package/src/facade/edges.ts +30 -0
  53. package/src/facade/events.ts +23 -0
  54. package/src/facade/evidence.ts +41 -0
  55. package/src/facade/graph.ts +38 -0
  56. package/src/facade/identity.ts +16 -0
  57. package/src/facade/ontologies.ts +34 -0
  58. package/src/facade/questions.ts +59 -0
  59. package/src/facade/search.ts +16 -0
  60. package/src/facade/tasks.ts +37 -0
  61. package/src/facade/topics.ts +42 -0
  62. package/src/facade/webhooks.ts +58 -0
  63. package/src/facade/worktrees.ts +51 -0
  64. package/src/gatewayFacades.ts +1666 -0
  65. package/src/graphClient.ts +529 -0
  66. package/src/harnessClient.ts +585 -0
  67. package/src/identityClient.ts +278 -0
  68. package/src/learningClient.ts +95 -0
  69. package/src/mcpParityClient.ts +240 -0
  70. package/src/mcpParitySurface.ts +70 -0
  71. package/src/ontologyClient.ts +275 -0
  72. package/src/packRuntime.ts +3 -0
  73. package/src/packsClient.ts +260 -0
  74. package/src/policyClient.ts +572 -0
  75. package/src/realtime/index.ts +51 -0
  76. package/src/realtime/refs.ts +17 -0
  77. package/src/reportsClient.ts +99 -0
  78. package/src/schemaClient.ts +129 -0
  79. package/src/sdkSurface.ts +190 -0
  80. package/src/topicsClient.ts +243 -0
  81. package/src/types.ts +807 -0
  82. package/src/workflowClient.ts +826 -0
  83. package/tsconfig.json +9 -0
  84. package/dist/.generated +0 -2
  85. package/dist/index.d.ts +0 -3
  86. package/dist/index.js +0 -3
  87. package/dist/lib/platform/auth/credentials.d.ts +0 -5
  88. package/dist/lib/platform/auth/credentials.js +0 -40
  89. package/dist/lib/platform/sdk/adminClient.d.ts +0 -404
  90. package/dist/lib/platform/sdk/adminClient.js +0 -384
  91. package/dist/lib/platform/sdk/answersClient.js +0 -21
  92. package/dist/lib/platform/sdk/audiencesClient.d.ts +0 -93
  93. package/dist/lib/platform/sdk/audiencesClient.js +0 -111
  94. package/dist/lib/platform/sdk/auditClient.d.ts +0 -24
  95. package/dist/lib/platform/sdk/auditClient.js +0 -21
  96. package/dist/lib/platform/sdk/beliefsClient.d.ts +0 -157
  97. package/dist/lib/platform/sdk/beliefsClient.js +0 -124
  98. package/dist/lib/platform/sdk/client.d.ts +0 -2369
  99. package/dist/lib/platform/sdk/client.js +0 -1831
  100. package/dist/lib/platform/sdk/contextClient.d.ts +0 -21
  101. package/dist/lib/platform/sdk/contextClient.js +0 -86
  102. package/dist/lib/platform/sdk/contextFacade.js +0 -10
  103. package/dist/lib/platform/sdk/contextPackCompiler.d.ts +0 -100
  104. package/dist/lib/platform/sdk/contextPackCompiler.js +0 -534
  105. package/dist/lib/platform/sdk/contextTypes.d.ts +0 -133
  106. package/dist/lib/platform/sdk/contextTypes.js +0 -1
  107. package/dist/lib/platform/sdk/controlObjectOwnership.d.ts +0 -308
  108. package/dist/lib/platform/sdk/controlObjectOwnership.js +0 -220
  109. package/dist/lib/platform/sdk/coreClient.d.ts +0 -139
  110. package/dist/lib/platform/sdk/coreClient.js +0 -366
  111. package/dist/lib/platform/sdk/customTools.d.ts +0 -83
  112. package/dist/lib/platform/sdk/customTools.js +0 -247
  113. package/dist/lib/platform/sdk/decisionsClient.d.ts +0 -106
  114. package/dist/lib/platform/sdk/decisionsClient.js +0 -129
  115. package/dist/lib/platform/sdk/domainContext.d.ts +0 -1
  116. package/dist/lib/platform/sdk/domainContext.js +0 -1
  117. package/dist/lib/platform/sdk/events.d.ts +0 -176
  118. package/dist/lib/platform/sdk/events.js +0 -261
  119. package/dist/lib/platform/sdk/eventsCore.d.ts +0 -13
  120. package/dist/lib/platform/sdk/eventsCore.js +0 -13
  121. package/dist/lib/platform/sdk/gatewayFacades.d.ts +0 -586
  122. package/dist/lib/platform/sdk/gatewayFacades.js +0 -845
  123. package/dist/lib/platform/sdk/graphClient.d.ts +0 -266
  124. package/dist/lib/platform/sdk/graphClient.js +0 -235
  125. package/dist/lib/platform/sdk/harnessClient.d.ts +0 -309
  126. package/dist/lib/platform/sdk/harnessClient.js +0 -219
  127. package/dist/lib/platform/sdk/identityClient.d.ts +0 -134
  128. package/dist/lib/platform/sdk/identityClient.js +0 -131
  129. package/dist/lib/platform/sdk/index.js +0 -49
  130. package/dist/lib/platform/sdk/learningClient.d.ts +0 -40
  131. package/dist/lib/platform/sdk/learningClient.js +0 -53
  132. package/dist/lib/platform/sdk/mcpParityClient.d.ts +0 -69
  133. package/dist/lib/platform/sdk/mcpParityClient.js +0 -196
  134. package/dist/lib/platform/sdk/mcpParitySurface.d.ts +0 -10
  135. package/dist/lib/platform/sdk/mcpParitySurface.js +0 -57
  136. package/dist/lib/platform/sdk/ontologyClient.d.ts +0 -131
  137. package/dist/lib/platform/sdk/ontologyClient.js +0 -161
  138. package/dist/lib/platform/sdk/packRuntime.d.ts +0 -1
  139. package/dist/lib/platform/sdk/packRuntime.js +0 -1
  140. package/dist/lib/platform/sdk/packsClient.d.ts +0 -126
  141. package/dist/lib/platform/sdk/packsClient.js +0 -157
  142. package/dist/lib/platform/sdk/policyClient.d.ts +0 -293
  143. package/dist/lib/platform/sdk/policyClient.js +0 -277
  144. package/dist/lib/platform/sdk/promptCatalog.js +0 -1
  145. package/dist/lib/platform/sdk/reportsClient.d.ts +0 -34
  146. package/dist/lib/platform/sdk/reportsClient.js +0 -64
  147. package/dist/lib/platform/sdk/schemaClient.d.ts +0 -59
  148. package/dist/lib/platform/sdk/schemaClient.js +0 -71
  149. package/dist/lib/platform/sdk/sdkSurface.d.ts +0 -56
  150. package/dist/lib/platform/sdk/sdkSurface.js +0 -140
  151. package/dist/lib/platform/sdk/topicsClient.d.ts +0 -78
  152. package/dist/lib/platform/sdk/topicsClient.js +0 -118
  153. package/dist/lib/platform/sdk/types.d.ts +0 -692
  154. package/dist/lib/platform/sdk/types.js +0 -1
  155. package/dist/lib/platform/sdk/version.d.ts +0 -2
  156. package/dist/lib/platform/sdk/workflowClient.d.ts +0 -313
  157. package/dist/lib/platform/sdk/workflowClient.js +0 -366
  158. package/dist/lucern/contracts/src/api-enums.contract.d.ts +0 -58
  159. package/dist/lucern/contracts/src/api-enums.contract.js +0 -147
  160. package/dist/lucern/contracts/src/auth-context.contract.d.ts +0 -8
  161. package/dist/lucern/contracts/src/auth-context.contract.js +0 -8
  162. package/dist/lucern/contracts/src/auth-session.contract.d.ts +0 -8
  163. package/dist/lucern/contracts/src/auth-session.contract.js +0 -8
  164. package/dist/lucern/contracts/src/auth.contract.d.ts +0 -88
  165. package/dist/lucern/contracts/src/auth.contract.js +0 -57
  166. package/dist/lucern/contracts/src/context-pack.contract.d.ts +0 -494
  167. package/dist/lucern/contracts/src/context-pack.contract.js +0 -169
  168. package/dist/lucern/contracts/src/convex-admin.contract.d.ts +0 -5
  169. package/dist/lucern/contracts/src/convex-admin.contract.js +0 -1
  170. package/dist/lucern/contracts/src/events-types.contract.d.ts +0 -8
  171. package/dist/lucern/contracts/src/events-types.contract.js +0 -8
  172. package/dist/lucern/contracts/src/events.contract.d.ts +0 -176
  173. package/dist/lucern/contracts/src/events.contract.js +0 -159
  174. package/dist/lucern/contracts/src/gateway.contract.d.ts +0 -74
  175. package/dist/lucern/contracts/src/gateway.contract.js +0 -19
  176. package/dist/lucern/contracts/src/ids.contract.d.ts +0 -7
  177. package/dist/lucern/contracts/src/ids.contract.js +0 -24
  178. package/dist/lucern/contracts/src/index.d.ts +0 -29
  179. package/dist/lucern/contracts/src/index.js +0 -29
  180. package/dist/lucern/contracts/src/lens-filter.contract.d.ts +0 -70
  181. package/dist/lucern/contracts/src/lens-filter.contract.js +0 -95
  182. package/dist/lucern/contracts/src/lens-workflow.contract.d.ts +0 -84
  183. package/dist/lucern/contracts/src/lens-workflow.contract.js +0 -54
  184. package/dist/lucern/contracts/src/mcp-tools.contract.d.ts +0 -151
  185. package/dist/lucern/contracts/src/mcp-tools.contract.js +0 -3281
  186. package/dist/lucern/contracts/src/ontology-matching.contract.d.ts +0 -8
  187. package/dist/lucern/contracts/src/ontology-matching.contract.js +0 -8
  188. package/dist/lucern/contracts/src/prompt.contract.d.ts +0 -24
  189. package/dist/lucern/contracts/src/prompt.contract.js +0 -24
  190. package/dist/lucern/contracts/src/sdk-methods.contract.d.ts +0 -358
  191. package/dist/lucern/contracts/src/sdk-methods.contract.js +0 -19
  192. package/dist/lucern/contracts/src/sdk-tools.contract.d.ts +0 -92
  193. package/dist/lucern/contracts/src/sdk-tools.contract.js +0 -1398
  194. package/dist/lucern/contracts/src/text-matching.contract.d.ts +0 -53
  195. package/dist/lucern/contracts/src/text-matching.contract.js +0 -277
  196. package/dist/lucern/contracts/src/topic-scope.contract.d.ts +0 -8
  197. package/dist/lucern/contracts/src/topic-scope.contract.js +0 -8
  198. package/dist/lucern/contracts/src/workflow-runtime.contract.d.ts +0 -161
  199. package/dist/lucern/contracts/src/workflow-runtime.contract.js +0 -257
  200. package/dist/realtime-refs.d.ts +0 -1
  201. package/dist/realtime-refs.js +0 -1
  202. package/dist/realtime.d.ts +0 -1
  203. package/dist/realtime.js +0 -1
  204. /package/{dist/lib/platform/sdk/index.d.ts → src/index.ts} +0 -0
  205. /package/{dist/lib/platform/sdk/promptCatalog.d.ts → src/promptCatalog.ts} +0 -0
  206. /package/{dist/lib/platform/sdk/version.js → src/version.ts} +0 -0
@@ -0,0 +1,278 @@
1
+ import {
2
+ createGatewayRequestClient,
3
+ type GatewayClientConfig,
4
+ type GatewayScope,
5
+ type PlatformGatewaySuccess,
6
+ LucernApiError,
7
+ randomIdempotencyKey,
8
+ toQueryString,
9
+ } from "./coreClient";
10
+ import { createListResult, mapGatewayData } from "./sdkSurface";
11
+ import type { JsonObject, SdkPrincipalContext } from "./types";
12
+
13
+ /** Summary of the currently authenticated principal and their scopes. */
14
+ export type IdentitySummary = SdkPrincipalContext;
15
+
16
+ /** Gateway response wrapping an identity summary payload. */
17
+ export type IdentityWhoamiResponse = PlatformGatewaySuccess<IdentitySummary>;
18
+
19
+ function createIdentityWhoamiClient(
20
+ config: GatewayClientConfig = {}
21
+ ) {
22
+ const gateway = createGatewayRequestClient(config);
23
+
24
+ return {
25
+ async whoami(): Promise<IdentityWhoamiResponse> {
26
+ return gateway.request<SdkPrincipalContext>({
27
+ path: "/api/platform/v1/identity/whoami",
28
+ });
29
+ },
30
+ };
31
+ }
32
+
33
+ export { LucernApiError };
34
+ export type { GatewayScope, PlatformGatewaySuccess } from "./coreClient";
35
+
36
+ /** Configuration for the identity client. */
37
+ export type IdentityClientConfig = GatewayClientConfig;
38
+
39
+ export type ClerkUserSearchResult = {
40
+ clerkId: string;
41
+ email: string | null;
42
+ firstName: string | null;
43
+ lastName: string | null;
44
+ displayName: string | null;
45
+ imageUrl: string | null;
46
+ };
47
+
48
+ /**
49
+ * Create the identity client for principals and API keys.
50
+ * @param config - Gateway transport configuration.
51
+ * @returns An object with methods for whoami, principal management, and key management.
52
+ */
53
+ export function createIdentityClient(config: IdentityClientConfig = {}) {
54
+ const gateway = createGatewayRequestClient(config);
55
+ const whoamiClient = createIdentityWhoamiClient(config);
56
+
57
+ const requestPrincipalWrite = (
58
+ method: "POST" | "PATCH",
59
+ input: GatewayScope & {
60
+ principalId: string;
61
+ principalType: "user" | "group" | "service" | "external_viewer";
62
+ clerkId?: string;
63
+ email?: string;
64
+ displayName?: string;
65
+ status?: "active" | "disabled" | "revoked";
66
+ metadata?: JsonObject;
67
+ },
68
+ idempotencyKey?: string
69
+ ) =>
70
+ gateway.request<unknown>({
71
+ path: "/api/platform/v1/identity/principals",
72
+ method,
73
+ body: input,
74
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
75
+ });
76
+
77
+ return {
78
+ /**
79
+ * Resolve the current authenticated identity summary.
80
+ */
81
+ async whoami() {
82
+ return whoamiClient.whoami().then((response) =>
83
+ mapGatewayData(response, (data) => ({
84
+ principalId: data.principalId,
85
+ principalType: data.principalType,
86
+ tenantId: data.tenantId ?? null,
87
+ workspaceId: data.workspaceId ?? null,
88
+ scopes: Array.isArray(data.scopes) ? data.scopes : [],
89
+ roles: Array.isArray(data.roles) ? data.roles : [],
90
+ isPlatformAdmin: data.isPlatformAdmin === true,
91
+ isTenantAdmin: data.isTenantAdmin === true,
92
+ isWorkspaceAdmin: data.isWorkspaceAdmin === true,
93
+ authMode: data.authMode,
94
+ sessionId: data.sessionId,
95
+ delegatedBy: data.delegatedBy,
96
+ expiresAt: data.expiresAt,
97
+ }))
98
+ );
99
+ },
100
+
101
+ /**
102
+ * List principals in the current identity scope.
103
+ */
104
+ async listPrincipals(
105
+ query: GatewayScope & {
106
+ status?: string;
107
+ principalType?: string;
108
+ query?: string;
109
+ limit?: number;
110
+ } = {}
111
+ ) {
112
+ return gateway.request<unknown>({
113
+ path: `/api/platform/v1/identity/principals${toQueryString(query)}`,
114
+ }).then((response) =>
115
+ mapGatewayData(response, (data) =>
116
+ createListResult(
117
+ Array.isArray(data) ? data : [],
118
+ "principals"
119
+ )
120
+ )
121
+ );
122
+ },
123
+
124
+ /**
125
+ * Create a principal.
126
+ */
127
+ async createPrincipal(
128
+ input: GatewayScope & {
129
+ principalId: string;
130
+ principalType: "user" | "group" | "service" | "external_viewer";
131
+ clerkId?: string;
132
+ email?: string;
133
+ displayName?: string;
134
+ status?: "active" | "disabled" | "revoked";
135
+ metadata?: JsonObject;
136
+ },
137
+ idempotencyKey?: string
138
+ ) {
139
+ return requestPrincipalWrite("POST", input, idempotencyKey);
140
+ },
141
+
142
+ /**
143
+ * Update a principal.
144
+ */
145
+ async updatePrincipal(
146
+ input: GatewayScope & {
147
+ principalId: string;
148
+ principalType: "user" | "group" | "service" | "external_viewer";
149
+ clerkId?: string;
150
+ email?: string;
151
+ displayName?: string;
152
+ status?: "active" | "disabled" | "revoked";
153
+ metadata?: JsonObject;
154
+ },
155
+ idempotencyKey?: string
156
+ ) {
157
+ return requestPrincipalWrite("PATCH", input, idempotencyKey);
158
+ },
159
+
160
+ /**
161
+ * @deprecated Use createPrincipal or updatePrincipal.
162
+ */
163
+ async upsertPrincipal(
164
+ input: GatewayScope & {
165
+ principalId: string;
166
+ principalType: "user" | "group" | "service" | "external_viewer";
167
+ clerkId?: string;
168
+ email?: string;
169
+ displayName?: string;
170
+ status?: "active" | "disabled" | "revoked";
171
+ metadata?: JsonObject;
172
+ },
173
+ idempotencyKey?: string
174
+ ) {
175
+ return requestPrincipalWrite("PATCH", input, idempotencyKey);
176
+ },
177
+
178
+ /**
179
+ * List keys in the current identity scope.
180
+ */
181
+ async listKeys(
182
+ query: GatewayScope & {
183
+ principalId?: string;
184
+ status?: string;
185
+ limit?: number;
186
+ } = {}
187
+ ) {
188
+ return gateway.request<unknown>({
189
+ path: `/api/platform/v1/identity/keys${toQueryString(query)}`,
190
+ }).then((response) =>
191
+ mapGatewayData(response, (data) =>
192
+ createListResult(Array.isArray(data) ? data : [], "keys")
193
+ )
194
+ );
195
+ },
196
+
197
+ /**
198
+ * Create an API key.
199
+ */
200
+ async createKey(
201
+ input: GatewayScope & {
202
+ principalId: string;
203
+ keyId?: string;
204
+ token?: string;
205
+ scopes?: string[];
206
+ environment?: "sandbox" | "production";
207
+ expiresInDays?: number;
208
+ rateLimitTier?: "free" | "developer" | "partner";
209
+ metadata?: JsonObject;
210
+ },
211
+ idempotencyKey?: string
212
+ ) {
213
+ return gateway.request<unknown>({
214
+ path: "/api/platform/v1/identity/keys",
215
+ method: "POST",
216
+ body: input,
217
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
218
+ });
219
+ },
220
+
221
+ /**
222
+ * Rotate an API key.
223
+ */
224
+ async rotateKey(
225
+ keyId: string,
226
+ input: {
227
+ replacementKeyId?: string;
228
+ replacementToken?: string;
229
+ replacementExpiresInDays?: number;
230
+ gracePeriodHours?: number;
231
+ } = {},
232
+ idempotencyKey?: string
233
+ ) {
234
+ return gateway.request<unknown>({
235
+ path: `/api/platform/v1/identity/keys/${encodeURIComponent(keyId)}/rotate`,
236
+ method: "POST",
237
+ body: input,
238
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
239
+ });
240
+ },
241
+
242
+ /**
243
+ * Delete an API key by revoking it.
244
+ */
245
+ async deleteKey(
246
+ keyId: string,
247
+ input: { reason?: string } = {},
248
+ idempotencyKey?: string
249
+ ) {
250
+ return gateway.request<unknown>({
251
+ path: `/api/platform/v1/identity/keys/${encodeURIComponent(keyId)}/revoke`,
252
+ method: "POST",
253
+ body: input,
254
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
255
+ });
256
+ },
257
+
258
+ /**
259
+ * @deprecated Use deleteKey.
260
+ */
261
+ async revokeKey(
262
+ keyId: string,
263
+ input: { reason?: string } = {},
264
+ idempotencyKey?: string
265
+ ) {
266
+ return this.deleteKey(keyId, input, idempotencyKey);
267
+ },
268
+
269
+ /**
270
+ * Search Clerk users by email or display attributes.
271
+ */
272
+ async searchClerkUsers(q: string) {
273
+ return gateway.request<ClerkUserSearchResult[]>({
274
+ path: `/api/platform/v1/identity/clerk-users${toQueryString({ q })}`,
275
+ });
276
+ },
277
+ };
278
+ }
@@ -0,0 +1,95 @@
1
+ import {
2
+ createGatewayRequestClient,
3
+ type GatewayClientConfig,
4
+ toQueryString,
5
+ } from "./coreClient";
6
+ import { createListResult, mapGatewayData, normalizeTopicQuery } from "./sdkSurface";
7
+ import type { TopicIdentifierInput } from "./types";
8
+
9
+ /** Configuration for the learning client. */
10
+ export type LearningClientConfig = GatewayClientConfig;
11
+
12
+ /**
13
+ * Create the learning client for execution telemetry reads.
14
+ * @param config - Gateway transport configuration.
15
+ * @returns An object with methods to list executions and retrieve stats.
16
+ */
17
+ export function createLearningClient(config: LearningClientConfig = {}) {
18
+ const gateway = createGatewayRequestClient(config);
19
+
20
+ return {
21
+ /**
22
+ * List recent execution records.
23
+ */
24
+ async listRecentExecutions(
25
+ args: {
26
+ namespace?: string;
27
+ topicId?: string;
28
+ audienceMode?: string;
29
+ success?: boolean;
30
+ limit?: number;
31
+ } & TopicIdentifierInput = {}
32
+ ) {
33
+ return gateway.request<unknown>({
34
+ path: `/api/platform/v1/learning/executions/recent${toQueryString({
35
+ ...normalizeTopicQuery(args),
36
+ namespace: args.namespace,
37
+ audienceMode: args.audienceMode,
38
+ success:
39
+ typeof args.success === "boolean"
40
+ ? args.success
41
+ ? "true"
42
+ : "false"
43
+ : undefined,
44
+ limit:
45
+ typeof args.limit === "number" && Number.isFinite(args.limit)
46
+ ? String(args.limit)
47
+ : undefined,
48
+ })}`,
49
+ }).then((response) =>
50
+ mapGatewayData(response, (data) =>
51
+ createListResult(Array.isArray(data) ? data : [], "executions")
52
+ )
53
+ );
54
+ },
55
+
56
+ /**
57
+ * @deprecated Use listRecentExecutions.
58
+ */
59
+ async getRecentExecutions(
60
+ args: {
61
+ namespace?: string;
62
+ topicId?: string;
63
+ audienceMode?: string;
64
+ success?: boolean;
65
+ limit?: number;
66
+ } & TopicIdentifierInput = {}
67
+ ) {
68
+ return this.listRecentExecutions(args);
69
+ },
70
+
71
+ /**
72
+ * Get aggregate execution statistics.
73
+ */
74
+ async getExecutionStats(
75
+ args: {
76
+ namespace?: string;
77
+ topicId?: string;
78
+ audienceMode?: string;
79
+ hours?: number;
80
+ } & TopicIdentifierInput = {}
81
+ ) {
82
+ return gateway.request<unknown>({
83
+ path: `/api/platform/v1/learning/executions/stats${toQueryString({
84
+ ...normalizeTopicQuery(args),
85
+ namespace: args.namespace,
86
+ audienceMode: args.audienceMode,
87
+ hours:
88
+ typeof args.hours === "number" && Number.isFinite(args.hours)
89
+ ? String(args.hours)
90
+ : undefined,
91
+ })}`,
92
+ });
93
+ },
94
+ };
95
+ }
@@ -0,0 +1,240 @@
1
+ import {
2
+ createGatewayRequestClient,
3
+ type GatewayClientConfig,
4
+ randomIdempotencyKey,
5
+ type PlatformGatewaySuccess,
6
+ } from "./coreClient";
7
+ import type { JsonObject } from "./types";
8
+
9
+ /** Configuration for the MCP parity client. Inherits gateway transport settings. */
10
+ export type McpParityClientConfig = GatewayClientConfig;
11
+
12
+ type ToolArgs = JsonObject;
13
+
14
+ type ToolResult<T = unknown> = Promise<PlatformGatewaySuccess<T>>;
15
+
16
+ function withSdkSessionId(args: ToolArgs | undefined, sessionId: string): ToolArgs {
17
+ return {
18
+ ...(args ?? {}),
19
+ __sdkSessionId: sessionId,
20
+ };
21
+ }
22
+
23
+ /**
24
+ * Thin typed bridge for MCP-only SDK parity methods.
25
+ *
26
+ * These methods map 1:1 to the Lucern MCP handlers and execute through the
27
+ * platform gateway so the SDK can cover the full control-plane surface.
28
+ */
29
+ export function createMcpParityClient(config: McpParityClientConfig = {}) {
30
+ const gateway = createGatewayRequestClient(config);
31
+ const sessionId = crypto.randomUUID();
32
+
33
+ function executeRead<T = unknown>(
34
+ toolName: string,
35
+ args?: ToolArgs
36
+ ): ToolResult<T> {
37
+ return gateway.request<T>({
38
+ path: `/api/platform/v1/mcp-tools/${encodeURIComponent(toolName)}`,
39
+ method: "POST",
40
+ body: withSdkSessionId(args, sessionId),
41
+ });
42
+ }
43
+
44
+ function executeMutation<T = unknown>(
45
+ toolName: string,
46
+ args?: ToolArgs,
47
+ idempotencyKey?: string
48
+ ): ToolResult<T> {
49
+ return gateway.request<T>({
50
+ path: `/api/platform/v1/mcp-tools/${encodeURIComponent(toolName)}`,
51
+ method: "POST",
52
+ body: withSdkSessionId(args, sessionId),
53
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
54
+ });
55
+ }
56
+
57
+ return {
58
+ sessionId,
59
+
60
+ listTopics(args: ToolArgs = {}) {
61
+ return executeRead("list_topics", args);
62
+ },
63
+ createTopic(args: ToolArgs, idempotencyKey?: string) {
64
+ return executeMutation("create_topic", args, idempotencyKey);
65
+ },
66
+ getTopic(args: ToolArgs) {
67
+ return executeRead("get_topic", args);
68
+ },
69
+ getTopicTree(args: ToolArgs) {
70
+ return executeRead("get_topic_tree", args);
71
+ },
72
+
73
+ activateWorktree(args: ToolArgs, idempotencyKey?: string) {
74
+ return executeMutation("activate_worktree", args, idempotencyKey);
75
+ },
76
+ updateWorktreeMetadata(args: ToolArgs, idempotencyKey?: string) {
77
+ return executeMutation("update_worktree_metadata", args, idempotencyKey);
78
+ },
79
+ updateWorktreeTargets(args: ToolArgs, idempotencyKey?: string) {
80
+ return executeMutation("update_worktree_targets", args, idempotencyKey);
81
+ },
82
+ listAllWorktrees(args: ToolArgs = {}) {
83
+ return executeRead("list_all_worktrees", args);
84
+ },
85
+ pipelineSnapshot(args: ToolArgs) {
86
+ return executeRead("pipeline_snapshot", args);
87
+ },
88
+ recordScopeLearning(args: ToolArgs, idempotencyKey?: string) {
89
+ return executeMutation("record_scope_learning", args, idempotencyKey);
90
+ },
91
+ discover(args: ToolArgs) {
92
+ return executeRead("discover", args);
93
+ },
94
+ analyzeTopicDensity(args: ToolArgs) {
95
+ return executeRead("analyze_topic_density", args);
96
+ },
97
+ applyAutoBranching(args: ToolArgs, idempotencyKey?: string) {
98
+ return executeMutation("apply_auto_branching", args, idempotencyKey);
99
+ },
100
+ seedBeliefLattice(args: ToolArgs = {}, idempotencyKey?: string) {
101
+ return executeMutation("seed_belief_lattice", args, idempotencyKey);
102
+ },
103
+ getLatticeCoverage(args: ToolArgs = {}) {
104
+ return executeRead("get_lattice_coverage", args);
105
+ },
106
+ matchEntityType(args: ToolArgs) {
107
+ return executeRead("match_entity_type", args);
108
+ },
109
+ discoverEntityConnections(args: ToolArgs) {
110
+ return executeRead("discover_entity_connections", args);
111
+ },
112
+ triggerBeliefReview(args: ToolArgs, idempotencyKey?: string) {
113
+ return executeMutation("trigger_belief_review", args, idempotencyKey);
114
+ },
115
+
116
+ listOntologies(args: ToolArgs = {}) {
117
+ return executeRead("list_ontologies", args);
118
+ },
119
+ getOntology(args: ToolArgs) {
120
+ return executeRead("get_ontology", args);
121
+ },
122
+ applyOntology(args: ToolArgs, idempotencyKey?: string) {
123
+ return executeMutation("apply_ontology", args, idempotencyKey);
124
+ },
125
+ createOntology(args: ToolArgs, idempotencyKey?: string) {
126
+ return executeMutation("create_ontology", args, idempotencyKey);
127
+ },
128
+ updateOntology(args: ToolArgs, idempotencyKey?: string) {
129
+ return executeMutation("update_ontology", args, idempotencyKey);
130
+ },
131
+ archiveOntology(args: ToolArgs, idempotencyKey?: string) {
132
+ return executeMutation("archive_ontology", args, idempotencyKey);
133
+ },
134
+ createOntologyVersion(args: ToolArgs, idempotencyKey?: string) {
135
+ return executeMutation("create_ontology_version", args, idempotencyKey);
136
+ },
137
+ publishOntologyVersion(args: ToolArgs, idempotencyKey?: string) {
138
+ return executeMutation("publish_ontology_version", args, idempotencyKey);
139
+ },
140
+ deprecateOntologyVersion(args: ToolArgs, idempotencyKey?: string) {
141
+ return executeMutation(
142
+ "deprecate_ontology_version",
143
+ args,
144
+ idempotencyKey
145
+ );
146
+ },
147
+ resolveEffectiveOntology(args: ToolArgs) {
148
+ return executeRead("resolve_effective_ontology", args);
149
+ },
150
+
151
+ registerSession(args: ToolArgs = {}, idempotencyKey?: string) {
152
+ return executeMutation("register_session", args, idempotencyKey);
153
+ },
154
+ heartbeatSession(args: ToolArgs = {}, idempotencyKey?: string) {
155
+ return executeMutation("heartbeat_session", args, idempotencyKey);
156
+ },
157
+ endSession(args: ToolArgs = {}, idempotencyKey?: string) {
158
+ return executeMutation("end_session", args, idempotencyKey);
159
+ },
160
+ listActiveSessions(args: ToolArgs = {}) {
161
+ return executeRead("list_active_sessions", args);
162
+ },
163
+ sendAgentMessage(args: ToolArgs, idempotencyKey?: string) {
164
+ return executeMutation("send_agent_message", args, idempotencyKey);
165
+ },
166
+ broadcastMessage(args: ToolArgs, idempotencyKey?: string) {
167
+ return executeMutation("broadcast_message", args, idempotencyKey);
168
+ },
169
+ getAgentInbox(args: ToolArgs = {}) {
170
+ return executeRead("get_agent_inbox", args);
171
+ },
172
+ claimFiles(args: ToolArgs, idempotencyKey?: string) {
173
+ return executeMutation("claim_files", args, idempotencyKey);
174
+ },
175
+
176
+ listTasks(args: ToolArgs) {
177
+ return executeRead("list_tasks", args);
178
+ },
179
+ createAnswer(args: ToolArgs, idempotencyKey?: string) {
180
+ return executeMutation("create_answer", args, idempotencyKey);
181
+ },
182
+ getAnswer(args: ToolArgs) {
183
+ return executeRead("get_answer", args);
184
+ },
185
+ flagContradiction(args: ToolArgs, idempotencyKey?: string) {
186
+ return executeMutation("flag_contradiction", args, idempotencyKey);
187
+ },
188
+
189
+ ingestObservation(args: ToolArgs, idempotencyKey?: string) {
190
+ return executeMutation("ingest_observation", args, idempotencyKey);
191
+ },
192
+ getObservationContext(args: ToolArgs) {
193
+ return executeRead("get_observation_context", args);
194
+ },
195
+
196
+ getCodeContext(args: ToolArgs) {
197
+ return executeRead("get_code_context", args);
198
+ },
199
+ getChangeHistory(args: ToolArgs) {
200
+ return executeRead("get_change_history", args);
201
+ },
202
+ recordAttempt(args: ToolArgs, idempotencyKey?: string) {
203
+ return executeMutation("record_attempt", args, idempotencyKey);
204
+ },
205
+ getFailureLog(args: ToolArgs) {
206
+ return executeRead("get_failure_log", args);
207
+ },
208
+
209
+ createEpistemicContract(args: ToolArgs, idempotencyKey?: string) {
210
+ return executeMutation(
211
+ "create_epistemic_contract",
212
+ args,
213
+ idempotencyKey
214
+ );
215
+ },
216
+ evaluateContract(args: ToolArgs, idempotencyKey?: string) {
217
+ return executeMutation("evaluate_contract", args, idempotencyKey);
218
+ },
219
+ getContractStatus(args: ToolArgs) {
220
+ return executeRead("get_contract_status", args);
221
+ },
222
+
223
+ checkPermission(args: ToolArgs) {
224
+ return executeRead("check_permission", args);
225
+ },
226
+ filterByPermission(args: ToolArgs) {
227
+ return executeRead("filter_by_permission", args);
228
+ },
229
+
230
+ manageWritePolicy(args: ToolArgs, idempotencyKey?: string) {
231
+ return args.action === "set"
232
+ ? executeMutation("manage_write_policy", args, idempotencyKey)
233
+ : executeRead("manage_write_policy", args);
234
+ },
235
+
236
+ generateSessionHandoff(args: ToolArgs) {
237
+ return executeRead("generate_session_handoff", args);
238
+ },
239
+ };
240
+ }
@@ -0,0 +1,70 @@
1
+ /** Descriptor mapping an MCP tool name to its SDK method path and read/mutation classification. */
2
+ export type McpParityMethod = {
3
+ toolName: string;
4
+ methodPath: string;
5
+ kind: "read" | "mutation";
6
+ };
7
+
8
+ /** Complete registry of MCP tools with SDK parity, mapping tool names to SDK method paths. */
9
+ export const SDK_MCP_PARITY_METHODS: readonly McpParityMethod[] = [
10
+ { toolName: "activate_worktree", methodPath: "worktrees.activate", kind: "mutation" },
11
+ { toolName: "update_worktree_metadata", methodPath: "worktrees.updateMetadata", kind: "mutation" },
12
+ { toolName: "update_worktree_targets", methodPath: "worktrees.updateTargets", kind: "mutation" },
13
+ { toolName: "list_all_worktrees", methodPath: "worktrees.listAll", kind: "read" },
14
+ { toolName: "pipeline_snapshot", methodPath: "worktrees.pipelineSnapshot", kind: "read" },
15
+ { toolName: "record_scope_learning", methodPath: "context.recordScopeLearning", kind: "mutation" },
16
+ { toolName: "discover", methodPath: "context.discover", kind: "read" },
17
+ { toolName: "analyze_topic_density", methodPath: "context.analyzeTopicDensity", kind: "read" },
18
+ { toolName: "apply_auto_branching", methodPath: "context.applyAutoBranching", kind: "mutation" },
19
+ { toolName: "seed_belief_lattice", methodPath: "context.seedBeliefLattice", kind: "mutation" },
20
+ { toolName: "get_lattice_coverage", methodPath: "context.getLatticeCoverage", kind: "read" },
21
+ { toolName: "match_entity_type", methodPath: "context.matchEntityType", kind: "read" },
22
+ { toolName: "discover_entity_connections", methodPath: "context.discoverEntityConnections", kind: "read" },
23
+ { toolName: "trigger_belief_review", methodPath: "context.triggerBeliefReview", kind: "mutation" },
24
+ { toolName: "list_ontologies", methodPath: "ontologies.list", kind: "read" },
25
+ { toolName: "get_ontology", methodPath: "ontologies.get", kind: "read" },
26
+ { toolName: "apply_ontology", methodPath: "ontologies.bind", kind: "mutation" },
27
+ { toolName: "create_ontology", methodPath: "ontologies.create", kind: "mutation" },
28
+ { toolName: "update_ontology", methodPath: "ontologies.update", kind: "mutation" },
29
+ { toolName: "archive_ontology", methodPath: "ontologies.archive", kind: "mutation" },
30
+ { toolName: "create_ontology_version", methodPath: "ontologies.createVersion", kind: "mutation" },
31
+ { toolName: "publish_ontology_version", methodPath: "ontologies.publishVersion", kind: "mutation" },
32
+ { toolName: "deprecate_ontology_version", methodPath: "ontologies.deprecateVersion", kind: "mutation" },
33
+ { toolName: "resolve_effective_ontology", methodPath: "ontologies.resolveEffective", kind: "read" },
34
+ { toolName: "register_session", methodPath: "coordination.registerSession", kind: "mutation" },
35
+ { toolName: "heartbeat_session", methodPath: "coordination.heartbeatSession", kind: "mutation" },
36
+ { toolName: "end_session", methodPath: "coordination.endSession", kind: "mutation" },
37
+ { toolName: "list_active_sessions", methodPath: "coordination.listActiveSessions", kind: "read" },
38
+ { toolName: "send_agent_message", methodPath: "coordination.sendAgentMessage", kind: "mutation" },
39
+ { toolName: "broadcast_message", methodPath: "coordination.broadcastMessage", kind: "mutation" },
40
+ { toolName: "get_agent_inbox", methodPath: "coordination.getInbox", kind: "read" },
41
+ { toolName: "claim_files", methodPath: "coordination.claimFiles", kind: "mutation" },
42
+ { toolName: "create_topic", methodPath: "topics.create", kind: "mutation" },
43
+ { toolName: "get_topic", methodPath: "topics.get", kind: "read" },
44
+ { toolName: "get_topic_tree", methodPath: "topics.getTree", kind: "read" },
45
+ { toolName: "list_tasks", methodPath: "tasks.list", kind: "read" },
46
+ { toolName: "create_answer", methodPath: "answers.create", kind: "mutation" },
47
+ { toolName: "get_answer", methodPath: "answers.get", kind: "read" },
48
+ { toolName: "flag_contradiction", methodPath: "contradictions.flag", kind: "mutation" },
49
+ { toolName: "ingest_observation", methodPath: "observations.ingest", kind: "mutation" },
50
+ { toolName: "get_observation_context", methodPath: "observations.getContext", kind: "read" },
51
+ { toolName: "get_code_context", methodPath: "coding.getCodeContext", kind: "read" },
52
+ { toolName: "get_change_history", methodPath: "coding.getChangeHistory", kind: "read" },
53
+ { toolName: "record_attempt", methodPath: "coding.recordAttempt", kind: "mutation" },
54
+ { toolName: "get_failure_log", methodPath: "coding.getFailureLog", kind: "read" },
55
+ { toolName: "create_epistemic_contract", methodPath: "contracts.create", kind: "mutation" },
56
+ { toolName: "evaluate_contract", methodPath: "contracts.evaluate", kind: "mutation" },
57
+ { toolName: "get_contract_status", methodPath: "contracts.getStatus", kind: "read" },
58
+ { toolName: "check_permission", methodPath: "policy.checkPermission", kind: "read" },
59
+ { toolName: "filter_by_permission", methodPath: "policy.filterByPermission", kind: "read" },
60
+ { toolName: "manage_write_policy", methodPath: "policy.manageWritePolicy", kind: "mutation" },
61
+ { toolName: "generate_session_handoff", methodPath: "bootstrap.generateSessionHandoff", kind: "read" },
62
+ ];
63
+
64
+ export const SDK_MCP_PARITY_METHOD_PATHS = SDK_MCP_PARITY_METHODS.map(
65
+ (entry) => entry.methodPath
66
+ );
67
+
68
+ export const SDK_MCP_PARITY_TOOL_NAMES = SDK_MCP_PARITY_METHODS.map(
69
+ (entry) => entry.toolName
70
+ );