@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
@@ -1,16 +1,29 @@
1
- import { type GatewayClientConfig } from "./coreClient";
1
+ import {
2
+ createGatewayRequestClient,
3
+ type GatewayClientConfig,
4
+ } from "./coreClient";
5
+
2
6
  /** Configuration for the answers client. */
3
7
  export type AnswersClientConfig = GatewayClientConfig;
8
+
4
9
  /**
5
10
  * Create the answers client for retrieving question answers.
6
11
  * @param config - Gateway transport configuration.
7
12
  * @returns An object with a `get` method to fetch the answer for a question.
8
13
  */
9
- export declare function createAnswersClient(config?: AnswersClientConfig): {
14
+ export function createAnswersClient(config: AnswersClientConfig = {}) {
15
+ const gateway = createGatewayRequestClient(config);
16
+
17
+ return {
10
18
  /**
11
19
  * Get the current answer for a question.
12
20
  * @param questionId - The question node identifier.
13
21
  * @returns The answer record for the given question.
14
22
  */
15
- get(questionId: string): Promise<import("./coreClient").PlatformGatewaySuccess<Record<string, unknown>>>;
16
- };
23
+ async get(questionId: string) {
24
+ return gateway.request<Record<string, unknown>>({
25
+ path: `/api/platform/v1/questions/${encodeURIComponent(questionId)}/answer`,
26
+ });
27
+ },
28
+ };
29
+ }
@@ -0,0 +1,209 @@
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 audiences client. */
12
+ export type AudiencesClientConfig = GatewayClientConfig;
13
+
14
+ /** Input for creating or updating an audience registry entry. */
15
+ export type AudienceRegistryInput = GatewayScope & {
16
+ audienceKey: string;
17
+ audienceLabel: string;
18
+ audienceClass: "internal" | "restricted_external" | "public";
19
+ status?: "active" | "disabled" | "archived";
20
+ description?: string;
21
+ metadata?: JsonObject;
22
+ };
23
+
24
+ /** Input for creating an audience access grant. */
25
+ export type AudienceGrantInput = GatewayScope & {
26
+ audienceKey: string;
27
+ audienceClass?: "internal" | "restricted_external" | "public";
28
+ principalId?: string;
29
+ groupId?: string;
30
+ expiresAt?: number;
31
+ metadata?: JsonObject;
32
+ };
33
+
34
+ /** Input for revoking an audience grant by its identifier. */
35
+ export type AudienceGrantRevokeInput = GatewayScope & {
36
+ grantId: string;
37
+ };
38
+
39
+ /**
40
+ * Create the audiences client for registry entries and grants.
41
+ * @param config - Gateway transport configuration.
42
+ * @returns An object with methods to manage audience registry entries and grants.
43
+ */
44
+ export function createAudiencesClient(config: AudiencesClientConfig = {}) {
45
+ const gateway = createGatewayRequestClient(config);
46
+
47
+ return {
48
+ /**
49
+ * List audience registry entries.
50
+ */
51
+ async listRegistry(
52
+ query: GatewayScope & {
53
+ effective?: boolean;
54
+ status?: "active" | "disabled" | "archived";
55
+ } = {}
56
+ ) {
57
+ return gateway.request<unknown>({
58
+ path: `/api/platform/v1/audiences/registry${toQueryString({
59
+ ...query,
60
+ effective:
61
+ typeof query.effective === "boolean"
62
+ ? query.effective
63
+ ? "true"
64
+ : "false"
65
+ : undefined,
66
+ status: query.status,
67
+ })}`,
68
+ }).then((response) =>
69
+ mapGatewayData(response, (data) =>
70
+ createListResult(
71
+ Array.isArray(data) ? data : [],
72
+ "registryEntries"
73
+ )
74
+ )
75
+ );
76
+ },
77
+
78
+ /**
79
+ * @deprecated Use listRegistry.
80
+ */
81
+ async getRegistry(
82
+ query: GatewayScope & {
83
+ effective?: boolean;
84
+ status?: "active" | "disabled" | "archived";
85
+ } = {}
86
+ ) {
87
+ return this.listRegistry(query);
88
+ },
89
+
90
+ /**
91
+ * Create an audience registry entry.
92
+ */
93
+ async createRegistryEntry(
94
+ input: AudienceRegistryInput,
95
+ idempotencyKey?: string
96
+ ) {
97
+ return gateway.request<unknown>({
98
+ path: "/api/platform/v1/audiences/registry",
99
+ method: "POST",
100
+ body: input,
101
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
102
+ });
103
+ },
104
+
105
+ /**
106
+ * Update an audience registry entry.
107
+ */
108
+ async updateRegistryEntry(
109
+ input: AudienceRegistryInput,
110
+ idempotencyKey?: string
111
+ ) {
112
+ return this.createRegistryEntry(input, idempotencyKey);
113
+ },
114
+
115
+ /**
116
+ * @deprecated Use createRegistryEntry or updateRegistryEntry.
117
+ */
118
+ async upsertRegistry(
119
+ input: AudienceRegistryInput,
120
+ idempotencyKey?: string
121
+ ) {
122
+ return this.createRegistryEntry(input, idempotencyKey);
123
+ },
124
+
125
+ /**
126
+ * List audience grants.
127
+ */
128
+ async listGrants(
129
+ query: GatewayScope & {
130
+ audienceKey?: string;
131
+ principalId?: string;
132
+ groupId?: string;
133
+ status?: "active" | "revoked" | "expired";
134
+ } = {}
135
+ ) {
136
+ return gateway.request<unknown>({
137
+ path: `/api/platform/v1/audiences/grants${toQueryString({
138
+ ...query,
139
+ audienceKey: query.audienceKey,
140
+ principalId: query.principalId,
141
+ groupId: query.groupId,
142
+ status: query.status,
143
+ })}`,
144
+ }).then((response) =>
145
+ mapGatewayData(response, (data) =>
146
+ createListResult(Array.isArray(data) ? data : [], "grants")
147
+ )
148
+ );
149
+ },
150
+
151
+ /**
152
+ * @deprecated Use listGrants.
153
+ */
154
+ async getGrants(
155
+ query: GatewayScope & {
156
+ audienceKey?: string;
157
+ principalId?: string;
158
+ groupId?: string;
159
+ status?: "active" | "revoked" | "expired";
160
+ } = {}
161
+ ) {
162
+ return this.listGrants(query);
163
+ },
164
+
165
+ /**
166
+ * Create an audience grant.
167
+ */
168
+ async createGrant(input: AudienceGrantInput, idempotencyKey?: string) {
169
+ return gateway.request<unknown>({
170
+ path: "/api/platform/v1/audiences/grants",
171
+ method: "POST",
172
+ body: input,
173
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
174
+ });
175
+ },
176
+
177
+ /**
178
+ * @deprecated Use createGrant.
179
+ */
180
+ async grant(input: AudienceGrantInput, idempotencyKey?: string) {
181
+ return this.createGrant(input, idempotencyKey);
182
+ },
183
+
184
+ /**
185
+ * Delete an audience grant by revoking it.
186
+ */
187
+ async deleteGrant(
188
+ input: AudienceGrantRevokeInput,
189
+ idempotencyKey?: string
190
+ ) {
191
+ return gateway.request<unknown>({
192
+ path: "/api/platform/v1/audiences/grants/revoke",
193
+ method: "POST",
194
+ body: input,
195
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
196
+ });
197
+ },
198
+
199
+ /**
200
+ * @deprecated Use deleteGrant.
201
+ */
202
+ async revokeGrant(
203
+ input: AudienceGrantRevokeInput,
204
+ idempotencyKey?: string
205
+ ) {
206
+ return this.deleteGrant(input, idempotencyKey);
207
+ },
208
+ };
209
+ }
@@ -0,0 +1,50 @@
1
+ import {
2
+ createGatewayRequestClient,
3
+ type GatewayClientConfig,
4
+ type GatewayScope,
5
+ LucernApiError,
6
+ toQueryString,
7
+ } from "./coreClient";
8
+ import { createListResult, mapGatewayData, normalizeTopicQuery } from "./sdkSurface";
9
+ import type { TopicIdentifierInput } from "./types";
10
+
11
+ export { LucernApiError };
12
+ export type { GatewayScope, PlatformGatewaySuccess } from "./coreClient";
13
+
14
+ /** Configuration for the audit client. */
15
+ export type AuditClientConfig = GatewayClientConfig;
16
+
17
+ /**
18
+ * Create the audit client for transport-level audit event reads.
19
+ * @param config - Gateway transport configuration.
20
+ * @returns An object with methods to list audit events.
21
+ */
22
+ export function createAuditClient(config: AuditClientConfig = {}) {
23
+ const gateway = createGatewayRequestClient(config);
24
+
25
+ return {
26
+ /**
27
+ * List audit events for the current scope.
28
+ */
29
+ async listEvents(
30
+ query: GatewayScope & {
31
+ action?: string;
32
+ decision?: string;
33
+ traceId?: string;
34
+ principalId?: string;
35
+ topicId?: string;
36
+ limit?: number;
37
+ } & TopicIdentifierInput = {}
38
+ ) {
39
+ return gateway.request<unknown>({
40
+ path: `/api/platform/v1/audit/events${toQueryString(
41
+ normalizeTopicQuery(query)
42
+ )}`,
43
+ }).then((response) =>
44
+ mapGatewayData(response, (data) =>
45
+ createListResult(Array.isArray(data) ? data : [], "events")
46
+ )
47
+ );
48
+ },
49
+ };
50
+ }
@@ -0,0 +1,319 @@
1
+ import {
2
+ createGatewayRequestClient,
3
+ type GatewayClientConfig,
4
+ LucernApiError,
5
+ randomIdempotencyKey,
6
+ } from "./coreClient";
7
+ import { normalizeNodeWriteInput } from "./sdkSurface";
8
+ import type {
9
+ CreateBeliefResponse,
10
+ ForkBeliefResponse,
11
+ JsonObject,
12
+ ModulateConfidenceResponse,
13
+ } from "./types";
14
+
15
+ export { LucernApiError };
16
+ export type { PlatformGatewaySuccess } from "./coreClient";
17
+ export type {
18
+ CreateBeliefResponse,
19
+ ForkBeliefResponse,
20
+ ModulateConfidenceResponse,
21
+ } from "./types";
22
+
23
+ /** Configuration for the beliefs client. Inherits gateway transport settings. */
24
+ export type BeliefsClientConfig = GatewayClientConfig;
25
+
26
+ /**
27
+ * Input for creating a new belief within a topic scope.
28
+ *
29
+ * Use `text` as the canonical belief statement.
30
+ * `canonicalText` remains available as a legacy alias for backwards compatibility.
31
+ * Beliefs start as unscored drafts and can be scored via confidence modulation.
32
+ */
33
+ export type CreateBeliefInput = {
34
+ topicId?: string;
35
+ /** Preferred belief statement alias. */
36
+ text?: string;
37
+ /** @deprecated Use text. */
38
+ canonicalText?: string;
39
+ layer?: "L1" | "L2" | "L3" | "L4";
40
+ domain?: string;
41
+ sourceType?: "human" | "ai" | "agent" | "imported";
42
+ content?: string;
43
+ contentHash?: string;
44
+ globalId?: string;
45
+ title?: string;
46
+ subtype?: string;
47
+ confidence?: number;
48
+ tags?: string[];
49
+ metadata?: JsonObject;
50
+ verificationStatus?: "unverified" | "verified" | "rejected";
51
+ };
52
+
53
+ /**
54
+ * Input for recording a confidence change on a belief.
55
+ * Confidence modulation is append-only — each call adds a new credence history entry.
56
+ */
57
+ export type ModulateConfidenceInput = {
58
+ confidence: number;
59
+ trigger?:
60
+ | "evidence_added"
61
+ | "evidence_removed"
62
+ | "contradiction_detected"
63
+ | "contradiction_resolved"
64
+ | "manual"
65
+ | "decay"
66
+ | "agent_assessment"
67
+ | "merge_outcome"
68
+ | "worktree_outcome"
69
+ | "worktree_completed";
70
+ rationale: string;
71
+ certainty?: number;
72
+ };
73
+
74
+ /**
75
+ * Input for forking a scored belief into a new formulation.
76
+ * Scored beliefs are immutable — fork to evolve understanding.
77
+ */
78
+ export type ForkBeliefInput = {
79
+ newFormulation: string;
80
+ forkReason?:
81
+ | "refinement"
82
+ | "contradiction_response"
83
+ | "scope_change"
84
+ | "confidence_collapse"
85
+ | "manual";
86
+ rationale?: string;
87
+ };
88
+
89
+ /** Input for changing a belief's lifecycle status. */
90
+ export type UpdateBeliefStatusInput = {
91
+ id?: string;
92
+ nodeId?: string;
93
+ beliefId?: string;
94
+ status: "active" | "superseded" | "archived";
95
+ reason?: string;
96
+ };
97
+
98
+ /** Input for updating a belief's rationale without refining its text. */
99
+ export type UpdateBeliefRationaleInput = {
100
+ id?: string;
101
+ nodeId?: string;
102
+ beliefId?: string;
103
+ rationale?: string;
104
+ };
105
+
106
+ /** Input for creating a belief-to-belief reasoning edge. */
107
+ export type LinkBeliefsInput = {
108
+ fromNodeId: string;
109
+ toNodeId: string;
110
+ edgeType: string;
111
+ weight?: number;
112
+ context?: string;
113
+ };
114
+
115
+ /** Input for unlinking a belief from an attached evidence item. */
116
+ export type UnlinkBeliefEvidenceInput = {
117
+ beliefNodeId?: string;
118
+ beliefId?: string;
119
+ nodeId?: string;
120
+ insightId?: string;
121
+ evidenceId?: string;
122
+ };
123
+
124
+ /** Input for updating a belief's criticality classification. */
125
+ export type UpdateBeliefCriticalityInput = {
126
+ id?: string;
127
+ nodeId?: string;
128
+ beliefId?: string;
129
+ criticality:
130
+ | "blocking"
131
+ | "important"
132
+ | "supporting"
133
+ | "essential"
134
+ | "nice_to_have";
135
+ };
136
+
137
+ /** Input for bulk-updating multiple beliefs' criticality. */
138
+ export type BatchUpdateBeliefCriticalityInput = {
139
+ updates: Array<{
140
+ beliefId: string;
141
+ criticality:
142
+ | "blocking"
143
+ | "important"
144
+ | "supporting"
145
+ | "essential"
146
+ | "nice_to_have";
147
+ ifFalseImpact?: string;
148
+ triagePriority?: number;
149
+ reasoning?: string;
150
+ dependentBeliefIds?: string[];
151
+ blockedByBeliefIds?: string[];
152
+ }>;
153
+ };
154
+
155
+ /** Input for moving beliefs into a different topic scope. */
156
+ export type ReassignBeliefsTopicInput = {
157
+ beliefNodeIds?: string[];
158
+ beliefIds?: string[];
159
+ targetTopicId: string;
160
+ reason?: string;
161
+ };
162
+
163
+ /**
164
+ * Create the beliefs client for belief lifecycle operations.
165
+ *
166
+ * @param config - Gateway transport configuration.
167
+ * @returns An object with `createBelief`, `modulateConfidence`, and `forkBelief` methods.
168
+ */
169
+ export function createBeliefsClient(config: BeliefsClientConfig = {}) {
170
+ const gateway = createGatewayRequestClient(config);
171
+
172
+ return {
173
+ /**
174
+ * Create a belief within a topic scope.
175
+ */
176
+ async createBelief(input: CreateBeliefInput, idempotencyKey?: string) {
177
+ return gateway.request<CreateBeliefResponse>({
178
+ path: "/api/platform/v1/beliefs",
179
+ method: "POST",
180
+ body: normalizeNodeWriteInput(input),
181
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
182
+ });
183
+ },
184
+
185
+ /**
186
+ * Record a confidence change for an existing belief.
187
+ */
188
+ async modulateConfidence(
189
+ beliefId: string,
190
+ input: ModulateConfidenceInput,
191
+ idempotencyKey?: string
192
+ ) {
193
+ return gateway.request<ModulateConfidenceResponse>({
194
+ path: `/api/platform/v1/beliefs/${encodeURIComponent(beliefId)}/confidence`,
195
+ method: "POST",
196
+ body: input,
197
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
198
+ });
199
+ },
200
+
201
+ /**
202
+ * Fork a scored belief into a new formulation.
203
+ */
204
+ async forkBelief(
205
+ beliefId: string,
206
+ input: ForkBeliefInput,
207
+ idempotencyKey?: string
208
+ ) {
209
+ return gateway.request<ForkBeliefResponse>({
210
+ path: `/api/platform/v1/beliefs/${encodeURIComponent(beliefId)}/fork`,
211
+ method: "POST",
212
+ body: input,
213
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
214
+ });
215
+ },
216
+
217
+ /**
218
+ * Update a belief's lifecycle status.
219
+ */
220
+ async updateBeliefStatus(
221
+ input: UpdateBeliefStatusInput,
222
+ idempotencyKey?: string
223
+ ) {
224
+ return gateway.request<Record<string, unknown>>({
225
+ path: "/api/platform/v1/beliefs/update-status",
226
+ method: "POST",
227
+ body: input as JsonObject,
228
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
229
+ });
230
+ },
231
+
232
+ /**
233
+ * Update a belief's rationale without changing its text.
234
+ */
235
+ async updateBeliefRationale(
236
+ input: UpdateBeliefRationaleInput,
237
+ idempotencyKey?: string
238
+ ) {
239
+ return gateway.request<Record<string, unknown>>({
240
+ path: "/api/platform/v1/beliefs/update-rationale",
241
+ method: "POST",
242
+ body: input as JsonObject,
243
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
244
+ });
245
+ },
246
+
247
+ /**
248
+ * Create a typed relationship between two beliefs.
249
+ */
250
+ async linkBeliefs(input: LinkBeliefsInput, idempotencyKey?: string) {
251
+ return gateway.request<Record<string, unknown>>({
252
+ path: "/api/platform/v1/beliefs/link",
253
+ method: "POST",
254
+ body: input as JsonObject,
255
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
256
+ });
257
+ },
258
+
259
+ /**
260
+ * Remove an evidence attachment from a belief.
261
+ */
262
+ async unlinkBeliefEvidence(
263
+ input: UnlinkBeliefEvidenceInput,
264
+ idempotencyKey?: string
265
+ ) {
266
+ return gateway.request<Record<string, unknown>>({
267
+ path: "/api/platform/v1/beliefs/unlink-evidence",
268
+ method: "POST",
269
+ body: input as JsonObject,
270
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
271
+ });
272
+ },
273
+
274
+ /**
275
+ * Update a belief's criticality metadata.
276
+ */
277
+ async updateBeliefCriticality(
278
+ input: UpdateBeliefCriticalityInput,
279
+ idempotencyKey?: string
280
+ ) {
281
+ return gateway.request<Record<string, unknown>>({
282
+ path: "/api/platform/v1/beliefs/update-criticality",
283
+ method: "POST",
284
+ body: input as JsonObject,
285
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
286
+ });
287
+ },
288
+
289
+ /**
290
+ * Update multiple beliefs' criticality in one mutation.
291
+ */
292
+ async batchUpdateBeliefCriticality(
293
+ input: BatchUpdateBeliefCriticalityInput,
294
+ idempotencyKey?: string
295
+ ) {
296
+ return gateway.request<Record<string, unknown>>({
297
+ path: "/api/platform/v1/beliefs/batch-update-criticality",
298
+ method: "POST",
299
+ body: input as JsonObject,
300
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
301
+ });
302
+ },
303
+
304
+ /**
305
+ * Reassign beliefs to a different topic scope.
306
+ */
307
+ async reassignBeliefsTopic(
308
+ input: ReassignBeliefsTopicInput,
309
+ idempotencyKey?: string
310
+ ) {
311
+ return gateway.request<Record<string, unknown>>({
312
+ path: "/api/platform/v1/beliefs/reassign-topic",
313
+ method: "POST",
314
+ body: input as JsonObject,
315
+ idempotencyKey: idempotencyKey ?? randomIdempotencyKey(),
316
+ });
317
+ },
318
+ };
319
+ }