@lucern/sdk 0.2.0-alpha.3 → 0.2.0-alpha.5

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 (155) hide show
  1. package/README.md +615 -112
  2. package/dist/.generated +2 -0
  3. package/dist/index.d.ts +3 -0
  4. package/dist/index.js +3 -8894
  5. package/dist/lib/platform/auth/credentials.d.ts +5 -0
  6. package/dist/lib/platform/auth/credentials.js +40 -0
  7. package/dist/lib/platform/sdk/adminClient.d.ts +404 -0
  8. package/dist/lib/platform/sdk/adminClient.js +384 -0
  9. package/dist/lib/platform/sdk/answersClient.d.ts +16 -0
  10. package/dist/lib/platform/sdk/answersClient.js +21 -0
  11. package/dist/{packages/sdk/src → lib/platform/sdk}/audiencesClient.d.ts +6 -0
  12. package/dist/lib/platform/sdk/audiencesClient.js +111 -0
  13. package/dist/{packages/sdk/src → lib/platform/sdk}/auditClient.d.ts +3 -0
  14. package/dist/lib/platform/sdk/auditClient.js +21 -0
  15. package/dist/lib/platform/sdk/beliefsClient.d.ts +157 -0
  16. package/dist/lib/platform/sdk/beliefsClient.js +124 -0
  17. package/dist/{packages/sdk/src → lib/platform/sdk}/client.d.ts +957 -146
  18. package/dist/lib/platform/sdk/client.js +1831 -0
  19. package/dist/lib/platform/sdk/contextClient.d.ts +21 -0
  20. package/dist/lib/platform/sdk/contextClient.js +86 -0
  21. package/dist/{lucern/packages/domain-context/src/context-pack-compiler.d.ts → lib/platform/sdk/contextPackCompiler.d.ts} +2 -3
  22. package/dist/lib/platform/sdk/contextPackCompiler.js +534 -0
  23. package/dist/lib/platform/sdk/contextTypes.d.ts +133 -0
  24. package/dist/lib/platform/sdk/contextTypes.js +1 -0
  25. package/dist/{packages/sdk/src → lib/platform/sdk}/controlObjectOwnership.d.ts +15 -0
  26. package/dist/lib/platform/sdk/controlObjectOwnership.js +220 -0
  27. package/dist/{packages/sdk/src → lib/platform/sdk}/coreClient.d.ts +19 -0
  28. package/dist/lib/platform/sdk/coreClient.js +366 -0
  29. package/dist/{packages/sdk/src → lib/platform/sdk}/customTools.d.ts +21 -3
  30. package/dist/lib/platform/sdk/customTools.js +247 -0
  31. package/dist/{packages/sdk/src → lib/platform/sdk}/decisionsClient.d.ts +9 -0
  32. package/dist/lib/platform/sdk/decisionsClient.js +129 -0
  33. package/dist/lib/platform/sdk/domainContext.d.ts +1 -0
  34. package/dist/lib/platform/sdk/domainContext.js +1 -0
  35. package/dist/{lucern/packages/events/src/types.d.ts → lib/platform/sdk/events.d.ts} +25 -0
  36. package/dist/lib/platform/sdk/events.js +261 -0
  37. package/dist/lib/platform/sdk/gatewayFacades.d.ts +586 -0
  38. package/dist/lib/platform/sdk/gatewayFacades.js +845 -0
  39. package/dist/{packages/sdk/src → lib/platform/sdk}/graphClient.d.ts +75 -0
  40. package/dist/lib/platform/sdk/graphClient.js +235 -0
  41. package/dist/{packages/sdk/src → lib/platform/sdk}/harnessClient.d.ts +90 -1
  42. package/dist/lib/platform/sdk/harnessClient.js +219 -0
  43. package/dist/{packages/sdk/src → lib/platform/sdk}/identityClient.d.ts +45 -15
  44. package/dist/lib/platform/sdk/identityClient.js +131 -0
  45. package/dist/{packages/sdk/src → lib/platform/sdk}/index.d.ts +21 -3
  46. package/dist/lib/platform/sdk/index.js +46 -0
  47. package/dist/{packages/sdk/src → lib/platform/sdk}/learningClient.d.ts +3 -0
  48. package/dist/lib/platform/sdk/learningClient.js +53 -0
  49. package/dist/{packages/sdk/src → lib/platform/sdk}/mcpParityClient.d.ts +1 -0
  50. package/dist/lib/platform/sdk/mcpParityClient.js +196 -0
  51. package/dist/{packages/sdk/src → lib/platform/sdk}/mcpParitySurface.d.ts +2 -0
  52. package/dist/lib/platform/sdk/mcpParitySurface.js +57 -0
  53. package/dist/{packages/sdk/src → lib/platform/sdk}/ontologyClient.d.ts +16 -0
  54. package/dist/lib/platform/sdk/ontologyClient.js +161 -0
  55. package/dist/lib/platform/sdk/packRuntime.d.ts +1 -0
  56. package/dist/lib/platform/sdk/packRuntime.js +1 -0
  57. package/dist/{packages/sdk/src → lib/platform/sdk}/packsClient.d.ts +25 -0
  58. package/dist/lib/platform/sdk/packsClient.js +157 -0
  59. package/dist/{packages/sdk/src → lib/platform/sdk}/policyClient.d.ts +90 -1
  60. package/dist/lib/platform/sdk/policyClient.js +277 -0
  61. package/dist/lib/platform/sdk/promptCatalog.d.ts +1 -0
  62. package/dist/lib/platform/sdk/promptCatalog.js +1 -0
  63. package/dist/{packages/sdk/src → lib/platform/sdk}/reportsClient.d.ts +3 -0
  64. package/dist/lib/platform/sdk/reportsClient.js +64 -0
  65. package/dist/{packages/sdk/src → lib/platform/sdk}/schemaClient.d.ts +5 -0
  66. package/dist/lib/platform/sdk/schemaClient.js +71 -0
  67. package/dist/{packages/sdk/src → lib/platform/sdk}/sdkSurface.d.ts +1 -0
  68. package/dist/lib/platform/sdk/sdkSurface.js +140 -0
  69. package/dist/{packages/sdk/src → lib/platform/sdk}/topicsClient.d.ts +33 -0
  70. package/dist/lib/platform/sdk/topicsClient.js +118 -0
  71. package/dist/{packages/sdk/src → lib/platform/sdk}/types.d.ts +224 -2
  72. package/dist/lib/platform/sdk/types.js +1 -0
  73. package/dist/lib/platform/sdk/version.js +2 -0
  74. package/dist/{packages/sdk/src → lib/platform/sdk}/workflowClient.d.ts +63 -2
  75. package/dist/lib/platform/sdk/workflowClient.js +366 -0
  76. package/dist/lucern/contracts/src/api-enums.contract.d.ts +58 -0
  77. package/dist/lucern/contracts/src/api-enums.contract.js +147 -0
  78. package/dist/lucern/contracts/src/lens-filter.contract.js +95 -0
  79. package/dist/lucern/contracts/src/lens-workflow.contract.js +54 -0
  80. package/dist/lucern/contracts/src/mcp-tools.contract.js +3281 -0
  81. package/package.json +17 -3
  82. package/dist/index.js.map +0 -1
  83. package/dist/lucern/contracts/src/auth-session.contract.d.ts +0 -53
  84. package/dist/lucern/contracts/src/context-pack.contract.d.ts +0 -494
  85. package/dist/lucern/contracts/src/workflow-runtime.contract.d.ts +0 -161
  86. package/dist/lucern/mcp-server/src/context-pack-policy.d.ts +0 -119
  87. package/dist/lucern/mcp-server/src/context-pack-schema.d.ts +0 -18
  88. package/dist/lucern/modules/graph-primitives/src/ontology-matching.d.ts +0 -78
  89. package/dist/lucern/modules/graph-primitives/src/text-matching.d.ts +0 -53
  90. package/dist/lucern/packages/client-core/src/beliefs.d.ts +0 -30
  91. package/dist/lucern/packages/client-core/src/context.d.ts +0 -29
  92. package/dist/lucern/packages/client-core/src/contradictions.d.ts +0 -11
  93. package/dist/lucern/packages/client-core/src/edges.d.ts +0 -11
  94. package/dist/lucern/packages/client-core/src/events.d.ts +0 -9
  95. package/dist/lucern/packages/client-core/src/evidence.d.ts +0 -21
  96. package/dist/lucern/packages/client-core/src/graph.d.ts +0 -17
  97. package/dist/lucern/packages/client-core/src/identity.d.ts +0 -7
  98. package/dist/lucern/packages/client-core/src/ids.d.ts +0 -7
  99. package/dist/lucern/packages/client-core/src/ontologies.d.ts +0 -13
  100. package/dist/lucern/packages/client-core/src/questions.d.ts +0 -39
  101. package/dist/lucern/packages/client-core/src/search.d.ts +0 -7
  102. package/dist/lucern/packages/client-core/src/tasks.d.ts +0 -13
  103. package/dist/lucern/packages/client-core/src/topics.d.ts +0 -17
  104. package/dist/lucern/packages/client-core/src/webhooks.d.ts +0 -35
  105. package/dist/lucern/packages/client-core/src/worktrees.d.ts +0 -17
  106. package/dist/lucern/packages/domain-beliefs/src/beliefs.d.ts +0 -283
  107. package/dist/lucern/packages/domain-beliefs/src/index.d.ts +0 -1
  108. package/dist/lucern/packages/domain-context/src/compile.d.ts +0 -11
  109. package/dist/lucern/packages/domain-context/src/index.d.ts +0 -4
  110. package/dist/lucern/packages/domain-context/src/ports.d.ts +0 -58
  111. package/dist/lucern/packages/domain-context/src/public-types.d.ts +0 -1
  112. package/dist/lucern/packages/domain-edges/src/contradictions.d.ts +0 -59
  113. package/dist/lucern/packages/domain-edges/src/edges.d.ts +0 -91
  114. package/dist/lucern/packages/domain-edges/src/index.d.ts +0 -2
  115. package/dist/lucern/packages/domain-evidence/src/evidence.d.ts +0 -115
  116. package/dist/lucern/packages/domain-evidence/src/index.d.ts +0 -1
  117. package/dist/lucern/packages/domain-graph/src/graph.d.ts +0 -150
  118. package/dist/lucern/packages/domain-identity/src/index.d.ts +0 -1
  119. package/dist/lucern/packages/domain-identity/src/whoami.d.ts +0 -13
  120. package/dist/lucern/packages/domain-ontologies/src/ontologies.d.ts +0 -123
  121. package/dist/lucern/packages/domain-questions/src/index.d.ts +0 -1
  122. package/dist/lucern/packages/domain-questions/src/questions.d.ts +0 -147
  123. package/dist/lucern/packages/domain-search/src/search.d.ts +0 -97
  124. package/dist/lucern/packages/domain-tasks/src/index.d.ts +0 -1
  125. package/dist/lucern/packages/domain-tasks/src/tasks.d.ts +0 -102
  126. package/dist/lucern/packages/domain-topics/src/index.d.ts +0 -1
  127. package/dist/lucern/packages/domain-topics/src/topics.d.ts +0 -147
  128. package/dist/lucern/packages/domain-worktrees/src/index.d.ts +0 -1
  129. package/dist/lucern/packages/domain-worktrees/src/worktrees.d.ts +0 -185
  130. package/dist/lucern/packages/events/src/index.d.ts +0 -4
  131. package/dist/lucern/packages/events/src/matching.d.ts +0 -3
  132. package/dist/lucern/packages/events/src/outbox.d.ts +0 -15
  133. package/dist/lucern/packages/events/src/webhooks.d.ts +0 -9
  134. package/dist/lucern/packages/sdk-typescript/src/facade/beliefs.d.ts +0 -15
  135. package/dist/lucern/packages/sdk-typescript/src/facade/context.d.ts +0 -12
  136. package/dist/lucern/packages/sdk-typescript/src/facade/contradictions.d.ts +0 -7
  137. package/dist/lucern/packages/sdk-typescript/src/facade/edges.d.ts +0 -7
  138. package/dist/lucern/packages/sdk-typescript/src/facade/events.d.ts +0 -6
  139. package/dist/lucern/packages/sdk-typescript/src/facade/evidence.d.ts +0 -21
  140. package/dist/lucern/packages/sdk-typescript/src/facade/graph.d.ts +0 -10
  141. package/dist/lucern/packages/sdk-typescript/src/facade/identity.d.ts +0 -5
  142. package/dist/lucern/packages/sdk-typescript/src/facade/ontologies.d.ts +0 -8
  143. package/dist/lucern/packages/sdk-typescript/src/facade/questions.d.ts +0 -39
  144. package/dist/lucern/packages/sdk-typescript/src/facade/search.d.ts +0 -5
  145. package/dist/lucern/packages/sdk-typescript/src/facade/tasks.d.ts +0 -8
  146. package/dist/lucern/packages/sdk-typescript/src/facade/topics.d.ts +0 -10
  147. package/dist/lucern/packages/sdk-typescript/src/facade/webhooks.d.ts +0 -16
  148. package/dist/lucern/packages/sdk-typescript/src/facade/worktrees.d.ts +0 -10
  149. package/dist/lucern/packages/sdk-typescript/src/index.d.ts +0 -28
  150. package/dist/packages/sdk/src/adminClient.d.ts +0 -89
  151. package/dist/packages/sdk/src/answersClient.d.ts +0 -5
  152. package/dist/packages/sdk/src/beliefsClient.d.ts +0 -52
  153. package/dist/packages/sdk/src/contextClient.d.ts +0 -9
  154. package/dist/packages/sdk/src/contracts/api-enums.contract.d.ts +0 -79
  155. /package/dist/{packages/sdk/src → lib/platform/sdk}/version.d.ts +0 -0
@@ -2,13 +2,16 @@ import { type GatewayClientConfig, type GatewayScope, LucernApiError } from "./c
2
2
  import type { JsonObject } from "./types";
3
3
  export { LucernApiError };
4
4
  export type { GatewayScope, PlatformGatewaySuccess } from "./coreClient";
5
+ /** Configuration for the schema client. */
5
6
  export type SchemaClientConfig = GatewayClientConfig;
7
+ /** Input for installing a schema pack into a tenant scope. */
6
8
  export type SchemaPackInstallInput = GatewayScope & {
7
9
  packKey: string;
8
10
  version?: string;
9
11
  autoEnable?: boolean;
10
12
  metadata?: JsonObject;
11
13
  };
14
+ /** Input for creating or updating a schema entitlement record. */
12
15
  export type SchemaEntitlementInput = GatewayScope & {
13
16
  packKey: string;
14
17
  status: "active" | "disabled" | "revoked";
@@ -19,6 +22,8 @@ export type SchemaEntitlementInput = GatewayScope & {
19
22
  };
20
23
  /**
21
24
  * Create the schema client for pack catalog and entitlement operations.
25
+ * @param config - Gateway transport configuration.
26
+ * @returns An object with methods to manage schema packs and entitlements.
22
27
  */
23
28
  export declare function createSchemaClient(config?: SchemaClientConfig): {
24
29
  /**
@@ -0,0 +1,71 @@
1
+ import { createGatewayRequestClient, LucernApiError, randomIdempotencyKey, toQueryString, } from "./coreClient.js";
2
+ import { createListResult, mapGatewayData } from "./sdkSurface.js";
3
+ export { LucernApiError };
4
+ /**
5
+ * Create the schema client for pack catalog and entitlement operations.
6
+ * @param config - Gateway transport configuration.
7
+ * @returns An object with methods to manage schema packs and entitlements.
8
+ */
9
+ export function createSchemaClient(config = {}) {
10
+ const gateway = createGatewayRequestClient(config);
11
+ return {
12
+ /**
13
+ * List schema packs.
14
+ */
15
+ async listPacks(scope = {}) {
16
+ return gateway.request({
17
+ path: `/api/platform/v1/schema/packs${toQueryString(scope)}`,
18
+ }).then((response) => mapGatewayData(response, (data) => createListResult(Array.isArray(data) ? data : [], "packs")));
19
+ },
20
+ /**
21
+ * Install a schema pack.
22
+ */
23
+ async installPack(input, idempotencyKey) {
24
+ return gateway.request({
25
+ path: "/api/platform/v1/schema/packs",
26
+ method: "POST",
27
+ body: input,
28
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
29
+ });
30
+ },
31
+ /**
32
+ * Get a schema pack by identifier.
33
+ */
34
+ async getPack(packId, scope = {}) {
35
+ return gateway.request({
36
+ path: `/api/platform/v1/schema/packs/${encodeURIComponent(packId)}${toQueryString(scope)}`,
37
+ });
38
+ },
39
+ /**
40
+ * List schema entitlements.
41
+ */
42
+ async listEntitlements(scope = {}) {
43
+ return gateway.request({
44
+ path: `/api/platform/v1/schema/entitlements${toQueryString(scope)}`,
45
+ }).then((response) => mapGatewayData(response, (data) => createListResult(Array.isArray(data) ? data : [], "entitlements")));
46
+ },
47
+ /**
48
+ * Create a schema entitlement.
49
+ */
50
+ async createEntitlement(input, idempotencyKey) {
51
+ return gateway.request({
52
+ path: "/api/platform/v1/schema/entitlements",
53
+ method: "POST",
54
+ body: input,
55
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
56
+ });
57
+ },
58
+ /**
59
+ * Update a schema entitlement.
60
+ */
61
+ async updateEntitlement(input, idempotencyKey) {
62
+ return this.createEntitlement(input, idempotencyKey);
63
+ },
64
+ /**
65
+ * @deprecated Use createEntitlement or updateEntitlement.
66
+ */
67
+ async upsertEntitlement(input, idempotencyKey) {
68
+ return this.createEntitlement(input, idempotencyKey);
69
+ },
70
+ };
71
+ }
@@ -32,6 +32,7 @@ export declare function withSdkAliases<T extends AnyRecord>(value: T): T;
32
32
  * Normalize a belief/question/evidence write payload to the canonical gateway shape.
33
33
  */
34
34
  export declare function normalizeNodeWriteInput<T extends JsonObject>(value: T): T;
35
+ export declare function normalizeNodeVerificationStatus(value: unknown): string | undefined;
35
36
  /**
36
37
  * Build a topic-aware query object.
37
38
  */
@@ -0,0 +1,140 @@
1
+ function asRecord(value) {
2
+ return value && typeof value === "object" ? value : {};
3
+ }
4
+ function cleanString(value) {
5
+ return typeof value === "string" && value.trim().length > 0
6
+ ? value.trim()
7
+ : undefined;
8
+ }
9
+ function normalizeVerificationStatus(value) {
10
+ const status = cleanString(value);
11
+ if (!status) {
12
+ return undefined;
13
+ }
14
+ if (status === "verified") {
15
+ return "human_verified";
16
+ }
17
+ if (status === "rejected") {
18
+ return "contradicted";
19
+ }
20
+ return status;
21
+ }
22
+ function cloneWith(value, patch) {
23
+ return { ...value, ...patch };
24
+ }
25
+ /**
26
+ * Resolve the canonical topic identifier.
27
+ */
28
+ export function resolveTopicId(value) {
29
+ return cleanString(value.topicId);
30
+ }
31
+ /**
32
+ * Resolve the canonical text field from text-first or legacy canonicalText-first inputs.
33
+ */
34
+ export function resolveText(value) {
35
+ return cleanString(value.text) ?? cleanString(value.canonicalText);
36
+ }
37
+ /**
38
+ * Attach the topicId to a record.
39
+ */
40
+ export function withTopicAlias(value) {
41
+ const topicId = cleanString(value.topicId) ?? undefined;
42
+ if (!topicId) {
43
+ return value;
44
+ }
45
+ return cloneWith(value, { topicId });
46
+ }
47
+ /**
48
+ * Attach the text/canonicalText alias pair to a record.
49
+ */
50
+ export function withTextAlias(value) {
51
+ const text = cleanString(value.text) ?? cleanString(value.canonicalText) ?? undefined;
52
+ if (!text) {
53
+ return value;
54
+ }
55
+ return cloneWith(value, { text, canonicalText: text });
56
+ }
57
+ /**
58
+ * Attach topic and text aliases to SDK node-like records.
59
+ */
60
+ export function withSdkAliases(value) {
61
+ return withTopicAlias(withTextAlias(value));
62
+ }
63
+ /**
64
+ * Normalize a belief/question/evidence write payload to the canonical gateway shape.
65
+ */
66
+ export function normalizeNodeWriteInput(value) {
67
+ const topicId = resolveTopicId(value);
68
+ const text = resolveText(value);
69
+ const verificationStatus = normalizeVerificationStatus(value.verificationStatus);
70
+ const next = { ...value };
71
+ if (topicId) {
72
+ next.topicId = topicId;
73
+ }
74
+ if (text) {
75
+ next.text = text;
76
+ next.canonicalText = text;
77
+ }
78
+ if (verificationStatus) {
79
+ next.verificationStatus = verificationStatus;
80
+ }
81
+ return next;
82
+ }
83
+ export function normalizeNodeVerificationStatus(value) {
84
+ return normalizeVerificationStatus(value);
85
+ }
86
+ /**
87
+ * Build a topic-aware query object.
88
+ */
89
+ export function normalizeTopicQuery(value) {
90
+ const topicId = cleanString(value.topicId);
91
+ if (!topicId) {
92
+ return value;
93
+ }
94
+ return { ...value, topicId };
95
+ }
96
+ /**
97
+ * Extract list items from array or list-envelope payloads.
98
+ */
99
+ export function asListItems(data, legacyKey) {
100
+ if (Array.isArray(data)) {
101
+ return data;
102
+ }
103
+ const record = asRecord(data);
104
+ if (Array.isArray(record.items)) {
105
+ return record.items;
106
+ }
107
+ if (legacyKey && Array.isArray(record[legacyKey])) {
108
+ return record[legacyKey];
109
+ }
110
+ return [];
111
+ }
112
+ /**
113
+ * Standardize list data to { items, total } while retaining an optional legacy array key.
114
+ */
115
+ export function createListResult(items, legacyKey) {
116
+ const result = {
117
+ items,
118
+ total: items.length,
119
+ };
120
+ if (legacyKey) {
121
+ result[legacyKey] = items;
122
+ }
123
+ return result;
124
+ }
125
+ /**
126
+ * Map a gateway success envelope's data while preserving the transport metadata.
127
+ */
128
+ export function mapGatewayData(response, mapper) {
129
+ return {
130
+ ...response,
131
+ data: mapper(response.data),
132
+ };
133
+ }
134
+ /**
135
+ * Apply SDK aliases across all items in a list-like payload.
136
+ */
137
+ export function mapAliasedList(data, legacyKey) {
138
+ const items = asListItems(data, legacyKey).map((item) => withSdkAliases(item));
139
+ return createListResult(items, legacyKey);
140
+ }
@@ -1,12 +1,15 @@
1
1
  import { type GatewayClientConfig } from "./coreClient";
2
2
  import type { JsonObject, TopicCoverageResponse, TopicIdentifierInput, TopicListResponse, TopicRecord, TopicTreeResponse } from "./types";
3
+ /** Configuration for the topics client. Inherits gateway transport settings. */
3
4
  export type TopicsClientConfig = GatewayClientConfig;
5
+ /** Filters for listing topics within a scope. */
4
6
  export type TopicListInput = TopicIdentifierInput & {
5
7
  ontologyId?: string;
6
8
  parentTopicId?: string;
7
9
  status?: string;
8
10
  type?: string;
9
11
  };
12
+ /** Input for creating a new topic. Name is required; all other fields are optional. */
10
13
  export type TopicCreateInput = TopicIdentifierInput & {
11
14
  name: string;
12
15
  description?: string;
@@ -19,6 +22,7 @@ export type TopicCreateInput = TopicIdentifierInput & {
19
22
  createdBy?: string;
20
23
  metadata?: JsonObject;
21
24
  };
25
+ /** Input for updating an existing topic's metadata. All fields are optional. */
22
26
  export type TopicUpdateInput = TopicIdentifierInput & {
23
27
  name?: string;
24
28
  description?: string;
@@ -28,13 +32,40 @@ export type TopicUpdateInput = TopicIdentifierInput & {
28
32
  status?: "active" | "archived" | "watching";
29
33
  visibility?: "private" | "team" | "firm" | "external" | "public";
30
34
  };
35
+ /** Options for retrieving the topic hierarchy. */
31
36
  export type TopicTreeQuery = {
32
37
  maxDepth?: number;
33
38
  };
39
+ /** Options for retrieving belief/question/evidence coverage across a topic tree. */
34
40
  export type TopicCoverageQuery = {
35
41
  includeDescendants?: boolean;
36
42
  maxDepth?: number;
37
43
  };
44
+ /** Input for batch-creating topics. */
45
+ export type TopicBulkCreateInput = {
46
+ topics: Array<TopicIdentifierInput & {
47
+ globalId?: string;
48
+ name: string;
49
+ description?: string;
50
+ type: string;
51
+ parentTopicId?: string;
52
+ depth?: number;
53
+ path?: string[];
54
+ tenantId?: string;
55
+ workspaceId?: string;
56
+ graphScopeProjectId?: string;
57
+ status?: "active" | "archived" | "watching";
58
+ visibility?: "private" | "team" | "firm" | "external" | "public";
59
+ metadata?: JsonObject;
60
+ createdBy?: string;
61
+ }>;
62
+ };
63
+ /**
64
+ * Create the topics client for managing hierarchical knowledge containers.
65
+ *
66
+ * @param config - Gateway transport configuration.
67
+ * @returns An object with `list`, `get`, `create`, `update`, `getTree`, and `getCoverage` methods.
68
+ */
38
69
  export declare function createTopicsClient(config?: TopicsClientConfig): {
39
70
  list(query?: TopicListInput): Promise<import("./coreClient").PlatformGatewaySuccess<TopicListResponse>>;
40
71
  get(topicId: string): Promise<import("./coreClient").PlatformGatewaySuccess<TopicRecord>>;
@@ -42,4 +73,6 @@ export declare function createTopicsClient(config?: TopicsClientConfig): {
42
73
  update(topicId: string, input: TopicUpdateInput, idempotencyKey?: string): Promise<import("./coreClient").PlatformGatewaySuccess<TopicRecord>>;
43
74
  getTree(topicId: string, query?: TopicTreeQuery): Promise<import("./coreClient").PlatformGatewaySuccess<TopicTreeResponse>>;
44
75
  getCoverage(topicId: string, query?: TopicCoverageQuery): Promise<import("./coreClient").PlatformGatewaySuccess<TopicCoverageResponse>>;
76
+ remove(topicId: string, idempotencyKey?: string): Promise<import("./coreClient").PlatformGatewaySuccess<Record<string, unknown>>>;
77
+ bulkCreate(input: TopicBulkCreateInput, idempotencyKey?: string): Promise<import("./coreClient").PlatformGatewaySuccess<Record<string, unknown>>>;
45
78
  };
@@ -0,0 +1,118 @@
1
+ import { createGatewayRequestClient, randomIdempotencyKey, toQueryString, } from "./coreClient.js";
2
+ import { createListResult, mapGatewayData, resolveTopicId, withTopicAlias, } from "./sdkSurface.js";
3
+ function asRecord(value) {
4
+ return value && typeof value === "object"
5
+ ? value
6
+ : {};
7
+ }
8
+ function cleanString(value) {
9
+ return typeof value === "string" && value.trim().length > 0
10
+ ? value.trim()
11
+ : undefined;
12
+ }
13
+ function normalizeTopicRecord(value) {
14
+ const record = asRecord(value);
15
+ const topicId = cleanString(record.topicId) ??
16
+ cleanString(record.id) ??
17
+ cleanString(record._id);
18
+ return withTopicAlias({
19
+ ...record,
20
+ ...(topicId ? { topicId } : {}),
21
+ });
22
+ }
23
+ function normalizeTopicTreeNode(value) {
24
+ return normalizeTopicRecord(value);
25
+ }
26
+ /**
27
+ * Create the topics client for managing hierarchical knowledge containers.
28
+ *
29
+ * @param config - Gateway transport configuration.
30
+ * @returns An object with `list`, `get`, `create`, `update`, `getTree`, and `getCoverage` methods.
31
+ */
32
+ export function createTopicsClient(config = {}) {
33
+ const gateway = createGatewayRequestClient(config);
34
+ return {
35
+ async list(query = {}) {
36
+ const topicId = resolveTopicId(query);
37
+ return gateway.request({
38
+ path: `/api/platform/v1/topics${toQueryString({
39
+ ...(topicId ? { topicId } : {}),
40
+ ontologyId: query.ontologyId,
41
+ parentTopicId: query.parentTopicId,
42
+ status: query.status,
43
+ type: query.type,
44
+ })}`,
45
+ }).then((response) => mapGatewayData(response, (data) => {
46
+ const record = asRecord(data);
47
+ const items = Array.isArray(record.topics)
48
+ ? record.topics.map(normalizeTopicRecord)
49
+ : [];
50
+ return {
51
+ ...createListResult(items, "topics"),
52
+ ...record,
53
+ topics: items,
54
+ total: typeof record.total === "number" ? record.total : items.length,
55
+ };
56
+ }));
57
+ },
58
+ async get(topicId) {
59
+ return gateway.request({
60
+ path: `/api/platform/v1/topics/${encodeURIComponent(topicId)}`,
61
+ }).then((response) => mapGatewayData(response, (data) => normalizeTopicRecord(asRecord(data).topic ?? data)));
62
+ },
63
+ async create(input, idempotencyKey) {
64
+ const topicId = resolveTopicId(input);
65
+ return gateway.request({
66
+ path: "/api/platform/v1/topics",
67
+ method: "POST",
68
+ body: {
69
+ ...input,
70
+ ...(topicId ? { topicId } : {}),
71
+ type: input.type ?? "theme",
72
+ },
73
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
74
+ }).then((response) => mapGatewayData(response, (data) => normalizeTopicRecord(data)));
75
+ },
76
+ async update(topicId, input, idempotencyKey) {
77
+ return gateway.request({
78
+ path: `/api/platform/v1/topics/${encodeURIComponent(topicId)}`,
79
+ method: "PATCH",
80
+ body: input,
81
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
82
+ }).then((response) => mapGatewayData(response, (data) => normalizeTopicRecord(data)));
83
+ },
84
+ async getTree(topicId, query = {}) {
85
+ return gateway.request({
86
+ path: `/api/platform/v1/topics/${encodeURIComponent(topicId)}/tree${toQueryString(query)}`,
87
+ }).then((response) => mapGatewayData(response, (data) => {
88
+ const record = asRecord(data);
89
+ return {
90
+ tree: Array.isArray(record.tree)
91
+ ? record.tree.map(normalizeTopicTreeNode)
92
+ : [],
93
+ };
94
+ }));
95
+ },
96
+ async getCoverage(topicId, query = {}) {
97
+ return gateway.request({
98
+ path: `/api/platform/v1/topics/${encodeURIComponent(topicId)}/coverage${toQueryString(query)}`,
99
+ });
100
+ },
101
+ async remove(topicId, idempotencyKey) {
102
+ return gateway.request({
103
+ path: "/api/platform/v1/topics/remove",
104
+ method: "POST",
105
+ body: { id: topicId },
106
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
107
+ });
108
+ },
109
+ async bulkCreate(input, idempotencyKey) {
110
+ return gateway.request({
111
+ path: "/api/platform/v1/topics/bulk",
112
+ method: "POST",
113
+ body: input,
114
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
115
+ });
116
+ },
117
+ };
118
+ }