@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.
Files changed (166) 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 -59
  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/src/contextFacade.ts +15 -0
  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/{dist/lib/platform/sdk/index.d.ts → src/index.ts} +3 -0
  69. package/src/learningClient.ts +95 -0
  70. package/src/mcpParityClient.ts +240 -0
  71. package/src/mcpParitySurface.ts +70 -0
  72. package/src/ontologyClient.ts +275 -0
  73. package/src/packRuntime.ts +3 -0
  74. package/src/packsClient.ts +260 -0
  75. package/src/policyClient.ts +572 -0
  76. package/src/promptCatalog.ts +1 -0
  77. package/src/realtime/index.ts +51 -0
  78. package/src/realtime/refs.ts +17 -0
  79. package/src/reportsClient.ts +99 -0
  80. package/src/schemaClient.ts +129 -0
  81. package/src/sdkSurface.ts +190 -0
  82. package/src/topicsClient.ts +243 -0
  83. package/src/types.ts +807 -0
  84. package/src/workflowClient.ts +826 -0
  85. package/tsconfig.json +9 -0
  86. package/dist/.generated +0 -2
  87. package/dist/index.d.ts +0 -3
  88. package/dist/index.js +0 -3
  89. package/dist/lib/platform/auth/credentials.d.ts +0 -5
  90. package/dist/lib/platform/auth/credentials.js +0 -40
  91. package/dist/lib/platform/sdk/adminClient.d.ts +0 -404
  92. package/dist/lib/platform/sdk/adminClient.js +0 -384
  93. package/dist/lib/platform/sdk/answersClient.js +0 -21
  94. package/dist/lib/platform/sdk/audiencesClient.d.ts +0 -93
  95. package/dist/lib/platform/sdk/audiencesClient.js +0 -111
  96. package/dist/lib/platform/sdk/auditClient.d.ts +0 -24
  97. package/dist/lib/platform/sdk/auditClient.js +0 -21
  98. package/dist/lib/platform/sdk/beliefsClient.d.ts +0 -157
  99. package/dist/lib/platform/sdk/beliefsClient.js +0 -124
  100. package/dist/lib/platform/sdk/client.d.ts +0 -2369
  101. package/dist/lib/platform/sdk/client.js +0 -1831
  102. package/dist/lib/platform/sdk/contextClient.d.ts +0 -21
  103. package/dist/lib/platform/sdk/contextClient.js +0 -86
  104. package/dist/lib/platform/sdk/contextPackCompiler.d.ts +0 -100
  105. package/dist/lib/platform/sdk/contextPackCompiler.js +0 -534
  106. package/dist/lib/platform/sdk/contextTypes.d.ts +0 -133
  107. package/dist/lib/platform/sdk/contextTypes.js +0 -1
  108. package/dist/lib/platform/sdk/controlObjectOwnership.d.ts +0 -308
  109. package/dist/lib/platform/sdk/controlObjectOwnership.js +0 -220
  110. package/dist/lib/platform/sdk/coreClient.d.ts +0 -139
  111. package/dist/lib/platform/sdk/coreClient.js +0 -366
  112. package/dist/lib/platform/sdk/customTools.d.ts +0 -83
  113. package/dist/lib/platform/sdk/customTools.js +0 -247
  114. package/dist/lib/platform/sdk/decisionsClient.d.ts +0 -106
  115. package/dist/lib/platform/sdk/decisionsClient.js +0 -129
  116. package/dist/lib/platform/sdk/domainContext.d.ts +0 -1
  117. package/dist/lib/platform/sdk/domainContext.js +0 -1
  118. package/dist/lib/platform/sdk/events.d.ts +0 -176
  119. package/dist/lib/platform/sdk/events.js +0 -261
  120. package/dist/lib/platform/sdk/gatewayFacades.d.ts +0 -586
  121. package/dist/lib/platform/sdk/gatewayFacades.js +0 -845
  122. package/dist/lib/platform/sdk/graphClient.d.ts +0 -266
  123. package/dist/lib/platform/sdk/graphClient.js +0 -235
  124. package/dist/lib/platform/sdk/harnessClient.d.ts +0 -309
  125. package/dist/lib/platform/sdk/harnessClient.js +0 -219
  126. package/dist/lib/platform/sdk/identityClient.d.ts +0 -134
  127. package/dist/lib/platform/sdk/identityClient.js +0 -131
  128. package/dist/lib/platform/sdk/index.js +0 -46
  129. package/dist/lib/platform/sdk/learningClient.d.ts +0 -40
  130. package/dist/lib/platform/sdk/learningClient.js +0 -53
  131. package/dist/lib/platform/sdk/mcpParityClient.d.ts +0 -69
  132. package/dist/lib/platform/sdk/mcpParityClient.js +0 -196
  133. package/dist/lib/platform/sdk/mcpParitySurface.d.ts +0 -10
  134. package/dist/lib/platform/sdk/mcpParitySurface.js +0 -57
  135. package/dist/lib/platform/sdk/ontologyClient.d.ts +0 -131
  136. package/dist/lib/platform/sdk/ontologyClient.js +0 -161
  137. package/dist/lib/platform/sdk/packRuntime.d.ts +0 -1
  138. package/dist/lib/platform/sdk/packRuntime.js +0 -1
  139. package/dist/lib/platform/sdk/packsClient.d.ts +0 -126
  140. package/dist/lib/platform/sdk/packsClient.js +0 -157
  141. package/dist/lib/platform/sdk/policyClient.d.ts +0 -293
  142. package/dist/lib/platform/sdk/policyClient.js +0 -277
  143. package/dist/lib/platform/sdk/promptCatalog.d.ts +0 -1
  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/lens-filter.contract.d.ts +0 -70
  161. package/dist/lucern/contracts/src/lens-filter.contract.js +0 -95
  162. package/dist/lucern/contracts/src/lens-workflow.contract.d.ts +0 -84
  163. package/dist/lucern/contracts/src/lens-workflow.contract.js +0 -54
  164. package/dist/lucern/contracts/src/mcp-tools.contract.d.ts +0 -151
  165. package/dist/lucern/contracts/src/mcp-tools.contract.js +0 -3281
  166. /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
+ }
@@ -12,6 +12,7 @@ export * from "./audiencesClient";
12
12
  export * from "./auditClient";
13
13
  export * from "./beliefsClient";
14
14
  export * from "./client";
15
+ export * from "./contextFacade";
15
16
  export * from "./contextPackCompiler";
16
17
  export * from "./controlObjectOwnership";
17
18
  export * from "./coreClient";
@@ -28,11 +29,13 @@ export * from "./domainContext";
28
29
  export * from "./customTools";
29
30
  export * from "./decisionsClient";
30
31
  export * from "./events";
32
+ export * from "./eventsCore";
31
33
  export * from "./graphClient";
32
34
  export * from "./harnessClient";
33
35
  export * from "./identityClient";
34
36
  export * from "./learningClient";
35
37
  export * from "./mcpParityClient";
38
+ export * from "./mcpParitySurface";
36
39
  export * from "./ontologyClient";
37
40
  export * from "./packRuntime";
38
41
  export * from "./packsClient";
@@ -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
+ }