@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,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
+ );
@@ -0,0 +1,275 @@
1
+ import {
2
+ createGatewayRequestClient,
3
+ type GatewayClientConfig,
4
+ type GatewayScope,
5
+ randomIdempotencyKey,
6
+ toQueryString,
7
+ } from "./coreClient";
8
+ import { createListResult, mapGatewayData } from "./sdkSurface";
9
+ import type { JsonObject } from "./types";
10
+
11
+ /** Configuration for the ontology client. */
12
+ export type OntologyClientConfig = GatewayClientConfig;
13
+
14
+ /** Input for binding an ontology to a topic. */
15
+ export type OntologyBindingInput = GatewayScope & {
16
+ ontologyId: string;
17
+ topicId: string;
18
+ };
19
+
20
+ /** Input for creating an ontology definition. */
21
+ export type OntologyDefinitionInput = GatewayScope & {
22
+ ontologyKey: string;
23
+ name: string;
24
+ description?: string;
25
+ tenantId?: string;
26
+ tier?: "platform" | "pack" | "tenant";
27
+ };
28
+
29
+ /** Input for updating mutable fields on an ontology definition. */
30
+ export type OntologyDefinitionUpdateInput = GatewayScope & {
31
+ name?: string;
32
+ description?: string;
33
+ status?: "draft" | "active" | "deprecated";
34
+ };
35
+
36
+ /** Input for creating a versioned snapshot of entity and edge type definitions. */
37
+ export type OntologyVersionInput = GatewayScope & {
38
+ version: string;
39
+ entityTypes: Array<{
40
+ value: string;
41
+ label: string;
42
+ description?: string;
43
+ schema?: JsonObject;
44
+ subtypes?: Array<{ value: string; label: string; description?: string }>;
45
+ }>;
46
+ edgeTypes: Array<{
47
+ value: string;
48
+ label: string;
49
+ description?: string;
50
+ sourceTypes?: string[];
51
+ targetTypes?: string[];
52
+ constraintSeverity?: "warn" | "info";
53
+ }>;
54
+ releaseNotes?: string;
55
+ };
56
+
57
+ /**
58
+ * Create the ontology client for ontology definitions and versions.
59
+ * @param config - Gateway transport configuration.
60
+ * @returns An object with methods to manage ontology definitions, versions, and bindings.
61
+ */
62
+ export function createOntologyClient(config: OntologyClientConfig = {}) {
63
+ const gateway = createGatewayRequestClient(config);
64
+
65
+ return {
66
+ /**
67
+ * List ontology definitions matching optional filters.
68
+ */
69
+ async list(
70
+ filters: GatewayScope & {
71
+ tenantId?: string;
72
+ tier?: string;
73
+ status?: string;
74
+ } = {}
75
+ ) {
76
+ return gateway
77
+ .request<unknown>({
78
+ path: `/api/platform/v1/ontologies${toQueryString(filters)}`,
79
+ })
80
+ .then((response) =>
81
+ mapGatewayData(response, (data) => {
82
+ const record =
83
+ data && typeof data === "object" && !Array.isArray(data)
84
+ ? (data as Record<string, unknown>)
85
+ : {};
86
+ const ontologies = Array.isArray(record.ontologies)
87
+ ? record.ontologies
88
+ : Array.isArray(record.definitions)
89
+ ? record.definitions
90
+ : Array.isArray(data)
91
+ ? data
92
+ : [];
93
+ const total =
94
+ typeof record.total === "number" && Number.isFinite(record.total)
95
+ ? record.total
96
+ : ontologies.length;
97
+ return {
98
+ ...record,
99
+ ...createListResult(ontologies, "definitions"),
100
+ ontologies,
101
+ total,
102
+ };
103
+ })
104
+ );
105
+ },
106
+
107
+ /**
108
+ * Get an ontology definition by identifier.
109
+ */
110
+ async get(id: string) {
111
+ return gateway.request<unknown>({
112
+ path: `/api/platform/v1/ontologies/${encodeURIComponent(id)}`,
113
+ });
114
+ },
115
+
116
+ /**
117
+ * Bind an ontology definition to a topic.
118
+ */
119
+ async bind(input: OntologyBindingInput, idempotencyKey?: string) {
120
+ return gateway.request<unknown>({
121
+ path: `/api/platform/v1/ontologies/${encodeURIComponent(input.ontologyId)}/bind`,
122
+ method: "POST",
123
+ body: {
124
+ topicId: input.topicId,
125
+ },
126
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
127
+ });
128
+ },
129
+
130
+ /**
131
+ * List ontology definitions.
132
+ */
133
+ async listDefinitions(
134
+ filters: GatewayScope & {
135
+ tenantId?: string;
136
+ tier?: string;
137
+ status?: string;
138
+ } = {}
139
+ ) {
140
+ return this.list(filters);
141
+ },
142
+
143
+ /**
144
+ * Get an ontology definition.
145
+ */
146
+ async getDefinition(id: string) {
147
+ return this.get(id);
148
+ },
149
+
150
+ /**
151
+ * Create an ontology definition.
152
+ */
153
+ async createDefinition(
154
+ input: OntologyDefinitionInput,
155
+ idempotencyKey?: string
156
+ ) {
157
+ return gateway.request<unknown>({
158
+ path: "/api/platform/v1/ontologies",
159
+ method: "POST",
160
+ body: input,
161
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
162
+ });
163
+ },
164
+
165
+ /**
166
+ * Update an ontology definition.
167
+ */
168
+ async updateDefinition(
169
+ id: string,
170
+ input: OntologyDefinitionUpdateInput,
171
+ idempotencyKey?: string
172
+ ) {
173
+ return gateway.request<unknown>({
174
+ path: `/api/platform/v1/ontologies/${encodeURIComponent(id)}`,
175
+ method: "PATCH",
176
+ body: input,
177
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
178
+ });
179
+ },
180
+
181
+ /**
182
+ * Archive an ontology definition.
183
+ */
184
+ async archiveDefinition(id: string, idempotencyKey?: string) {
185
+ return gateway.request<unknown>({
186
+ path: `/api/platform/v1/ontologies/${encodeURIComponent(id)}`,
187
+ method: "DELETE",
188
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
189
+ });
190
+ },
191
+
192
+ /**
193
+ * List versions for an ontology definition.
194
+ */
195
+ async listVersions(
196
+ ontologyId: string,
197
+ filters: GatewayScope & { status?: string } = {}
198
+ ) {
199
+ return gateway.request<unknown>({
200
+ path: `/api/platform/v1/ontologies/${encodeURIComponent(ontologyId)}/versions${toQueryString(filters)}`,
201
+ }).then((response) =>
202
+ mapGatewayData(response, (data) =>
203
+ createListResult(Array.isArray(data) ? data : [], "versions")
204
+ )
205
+ );
206
+ },
207
+
208
+ /**
209
+ * Create an ontology version.
210
+ */
211
+ async createVersion(
212
+ ontologyId: string,
213
+ input: OntologyVersionInput,
214
+ idempotencyKey?: string
215
+ ) {
216
+ return gateway.request<unknown>({
217
+ path: `/api/platform/v1/ontologies/${encodeURIComponent(ontologyId)}/versions`,
218
+ method: "POST",
219
+ body: input,
220
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
221
+ });
222
+ },
223
+
224
+ /**
225
+ * Publish an ontology version.
226
+ */
227
+ async publishVersion(
228
+ ontologyId: string,
229
+ versionId: string,
230
+ idempotencyKey?: string
231
+ ) {
232
+ return gateway.request<unknown>({
233
+ path: `/api/platform/v1/ontologies/${encodeURIComponent(ontologyId)}/versions/${encodeURIComponent(versionId)}/publish`,
234
+ method: "POST",
235
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
236
+ });
237
+ },
238
+
239
+ /**
240
+ * Deprecate an ontology version.
241
+ */
242
+ async deprecateVersion(
243
+ ontologyId: string,
244
+ versionId: string,
245
+ idempotencyKey?: string
246
+ ) {
247
+ return gateway.request<unknown>({
248
+ path: `/api/platform/v1/ontologies/${encodeURIComponent(ontologyId)}/versions/${encodeURIComponent(versionId)}/deprecate`,
249
+ method: "POST",
250
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
251
+ });
252
+ },
253
+
254
+ /**
255
+ * List topics directly bound to a specific ontology definition.
256
+ * Uses the topics gateway with ontologyId filter.
257
+ */
258
+ async listTopics(ontologyId: string) {
259
+ return gateway.request<unknown>({
260
+ path: `/api/platform/v1/topics?ontologyId=${encodeURIComponent(ontologyId)}`,
261
+ }).then((response) =>
262
+ mapGatewayData(response, (data) =>
263
+ createListResult(Array.isArray(data) ? data : [], "topics")
264
+ )
265
+ );
266
+ },
267
+
268
+ /**
269
+ * @deprecated Use listTopics.
270
+ */
271
+ async listTopicsByOntology(ontologyId: string) {
272
+ return this.listTopics(ontologyId);
273
+ },
274
+ };
275
+ }
@@ -0,0 +1,3 @@
1
+ // TODO(exfill): restore package-backed pack runtime exports after the legacy
2
+ // STACKOS lib/platform/packs surface is migrated into Lucern packages.
3
+ export {};
@@ -0,0 +1,260 @@
1
+ import {
2
+ createGatewayRequestClient,
3
+ type GatewayClientConfig,
4
+ type GatewayScope,
5
+ LucernApiError,
6
+ randomIdempotencyKey,
7
+ toQueryString,
8
+ } from "./coreClient";
9
+ import { createListResult, mapGatewayData } from "./sdkSurface";
10
+ import type { JsonObject } from "./types";
11
+
12
+ export { LucernApiError };
13
+ export type { GatewayScope, PlatformGatewaySuccess } from "./coreClient";
14
+
15
+ /** Configuration for the packs client. */
16
+ export type PacksClientConfig = GatewayClientConfig;
17
+
18
+ /** Input for installing a pack into a tenant or workspace scope. */
19
+ export type PackInstallInput = GatewayScope & {
20
+ packKey: string;
21
+ version?: string;
22
+ autoEnable?: boolean;
23
+ metadata?: JsonObject;
24
+ };
25
+
26
+ /** Input for enabling a previously installed pack. */
27
+ export type PackEnableInput = GatewayScope & {
28
+ packKey: string;
29
+ metadata?: JsonObject;
30
+ };
31
+
32
+ /** Input for disabling an active pack. */
33
+ export type PackDisableInput = GatewayScope & {
34
+ packKey: string;
35
+ force?: boolean;
36
+ metadata?: JsonObject;
37
+ };
38
+
39
+ /** Input for uninstalling a pack from a tenant or workspace scope. */
40
+ export type PackUninstallInput = GatewayScope & {
41
+ packKey: string;
42
+ metadata?: JsonObject;
43
+ };
44
+
45
+ /** Input for upgrading a pack through the prepare/canary/commit/rollback lifecycle. */
46
+ export type PackUpgradeInput = GatewayScope & {
47
+ packKey: string;
48
+ mode: "prepare" | "canary" | "commit" | "rollback";
49
+ targetVersion?: string;
50
+ metadata?: JsonObject;
51
+ };
52
+
53
+ /** Input for creating or updating a pack entitlement record. */
54
+ export type PackEntitlementInput = GatewayScope & {
55
+ packKey: string;
56
+ status: "active" | "disabled" | "revoked";
57
+ allowedLifecycles?: Array<"active" | "beta" | "experimental">;
58
+ minVersion?: string;
59
+ maxVersion?: string;
60
+ metadata?: JsonObject;
61
+ };
62
+
63
+ /**
64
+ * Create the packs client for pack catalog, state, and entitlement operations.
65
+ * @param config - Gateway transport configuration.
66
+ * @returns An object with methods to manage pack lifecycle, telemetry, and entitlements.
67
+ */
68
+ export function createPacksClient(config: PacksClientConfig = {}) {
69
+ const gateway = createGatewayRequestClient(config);
70
+
71
+ return {
72
+ /**
73
+ * List catalog entries for available packs.
74
+ */
75
+ async listCatalog() {
76
+ return gateway.request<unknown>({
77
+ path: "/api/platform/v1/packs/catalog",
78
+ }).then((response) =>
79
+ mapGatewayData(response, (data) =>
80
+ createListResult(Array.isArray(data) ? data : [], "catalog")
81
+ )
82
+ );
83
+ },
84
+
85
+ /**
86
+ * @deprecated Use listCatalog.
87
+ */
88
+ async getCatalog() {
89
+ return this.listCatalog();
90
+ },
91
+
92
+ /**
93
+ * Get the discovery catalog for packs.
94
+ */
95
+ async getDiscoveryCatalog() {
96
+ return gateway.request<unknown>({
97
+ path: "/api/platform/v1/packs/discovery",
98
+ });
99
+ },
100
+
101
+ /**
102
+ * Get discovery details for a specific pack.
103
+ */
104
+ async getDiscoveryDetail(packKey: string) {
105
+ return gateway.request<unknown>({
106
+ path: `/api/platform/v1/packs/discovery/${encodeURIComponent(packKey)}`,
107
+ });
108
+ },
109
+
110
+ /**
111
+ * List pack states for the current scope.
112
+ */
113
+ async listStates(query: GatewayScope = {}) {
114
+ return gateway.request<unknown>({
115
+ path: `/api/platform/v1/packs/states${toQueryString(query)}`,
116
+ }).then((response) =>
117
+ mapGatewayData(response, (data) =>
118
+ createListResult(Array.isArray(data) ? data : [], "states")
119
+ )
120
+ );
121
+ },
122
+
123
+ /**
124
+ * @deprecated Use listStates.
125
+ */
126
+ async getStates(query: GatewayScope = {}) {
127
+ return this.listStates(query);
128
+ },
129
+
130
+ /**
131
+ * Get health details for a pack.
132
+ */
133
+ async getHealth(packKey: string, query: GatewayScope = {}) {
134
+ return gateway.request<unknown>({
135
+ path: `/api/platform/v1/packs/${encodeURIComponent(packKey)}/health${toQueryString(
136
+ query
137
+ )}`,
138
+ });
139
+ },
140
+
141
+ /**
142
+ * List pack telemetry entries.
143
+ */
144
+ async listTelemetry(
145
+ query: GatewayScope & { lookbackHours?: number; limit?: number } = {}
146
+ ) {
147
+ return gateway.request<unknown>({
148
+ path: `/api/platform/v1/packs/telemetry${toQueryString(query)}`,
149
+ }).then((response) =>
150
+ mapGatewayData(response, (data) =>
151
+ createListResult(Array.isArray(data) ? data : [], "telemetry")
152
+ )
153
+ );
154
+ },
155
+
156
+ /**
157
+ * @deprecated Use listTelemetry.
158
+ */
159
+ async getTelemetry(
160
+ query: GatewayScope & { lookbackHours?: number; limit?: number } = {}
161
+ ) {
162
+ return this.listTelemetry(query);
163
+ },
164
+
165
+ /**
166
+ * Create a pack entitlement.
167
+ */
168
+ async createEntitlement(
169
+ input: PackEntitlementInput,
170
+ idempotencyKey?: string
171
+ ) {
172
+ return gateway.request<unknown>({
173
+ path: "/api/platform/v1/packs/entitlements",
174
+ method: "POST",
175
+ body: input,
176
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
177
+ });
178
+ },
179
+
180
+ /**
181
+ * Update a pack entitlement.
182
+ */
183
+ async updateEntitlement(
184
+ input: PackEntitlementInput,
185
+ idempotencyKey?: string
186
+ ) {
187
+ return this.createEntitlement(input, idempotencyKey);
188
+ },
189
+
190
+ /**
191
+ * @deprecated Use createEntitlement or updateEntitlement.
192
+ */
193
+ async upsertEntitlement(
194
+ input: PackEntitlementInput,
195
+ idempotencyKey?: string
196
+ ) {
197
+ return this.createEntitlement(input, idempotencyKey);
198
+ },
199
+
200
+ /**
201
+ * Install a pack.
202
+ */
203
+ async install(input: PackInstallInput, idempotencyKey?: string) {
204
+ return gateway.request<unknown>({
205
+ path: "/api/platform/v1/packs/install",
206
+ method: "POST",
207
+ body: input,
208
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
209
+ });
210
+ },
211
+
212
+ /**
213
+ * Enable a pack.
214
+ */
215
+ async enable(input: PackEnableInput, idempotencyKey?: string) {
216
+ return gateway.request<unknown>({
217
+ path: "/api/platform/v1/packs/enable",
218
+ method: "POST",
219
+ body: input,
220
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
221
+ });
222
+ },
223
+
224
+ /**
225
+ * Disable a pack.
226
+ */
227
+ async disable(input: PackDisableInput, idempotencyKey?: string) {
228
+ return gateway.request<unknown>({
229
+ path: "/api/platform/v1/packs/disable",
230
+ method: "POST",
231
+ body: input,
232
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
233
+ });
234
+ },
235
+
236
+ /**
237
+ * Uninstall a pack.
238
+ */
239
+ async uninstall(input: PackUninstallInput, idempotencyKey?: string) {
240
+ return gateway.request<unknown>({
241
+ path: "/api/platform/v1/packs/uninstall",
242
+ method: "POST",
243
+ body: input,
244
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
245
+ });
246
+ },
247
+
248
+ /**
249
+ * Upgrade a pack.
250
+ */
251
+ async upgrade(input: PackUpgradeInput, idempotencyKey?: string) {
252
+ return gateway.request<unknown>({
253
+ path: "/api/platform/v1/packs/upgrade",
254
+ method: "POST",
255
+ body: input,
256
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
257
+ });
258
+ },
259
+ };
260
+ }