@criticalbridge/brain-client 1.0.0

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 (126) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +23 -0
  3. package/dist/auth.d.ts +2 -0
  4. package/dist/auth.js +21 -0
  5. package/dist/auth.js.map +1 -0
  6. package/dist/client.d.ts +604 -0
  7. package/dist/client.js +1197 -0
  8. package/dist/client.js.map +1 -0
  9. package/dist/errors.d.ts +17 -0
  10. package/dist/errors.js +44 -0
  11. package/dist/errors.js.map +1 -0
  12. package/dist/index.d.ts +52 -0
  13. package/dist/index.js +95 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/types/a2a.types.d.ts +42 -0
  16. package/dist/types/a2a.types.js +3 -0
  17. package/dist/types/a2a.types.js.map +1 -0
  18. package/dist/types/agent-skill-lifecycle.types.d.ts +46 -0
  19. package/dist/types/agent-skill-lifecycle.types.js +22 -0
  20. package/dist/types/agent-skill-lifecycle.types.js.map +1 -0
  21. package/dist/types/agent.types.d.ts +117 -0
  22. package/dist/types/agent.types.js +3 -0
  23. package/dist/types/agent.types.js.map +1 -0
  24. package/dist/types/ai-knowledge.types.d.ts +180 -0
  25. package/dist/types/ai-knowledge.types.js +3 -0
  26. package/dist/types/ai-knowledge.types.js.map +1 -0
  27. package/dist/types/api.types.d.ts +550 -0
  28. package/dist/types/api.types.js +3 -0
  29. package/dist/types/api.types.js.map +1 -0
  30. package/dist/types/approval-events.types.d.ts +43 -0
  31. package/dist/types/approval-events.types.js +7 -0
  32. package/dist/types/approval-events.types.js.map +1 -0
  33. package/dist/types/best-practices-kg.types.d.ts +112 -0
  34. package/dist/types/best-practices-kg.types.js +3 -0
  35. package/dist/types/best-practices-kg.types.js.map +1 -0
  36. package/dist/types/bias-threshold-policy.types.d.ts +37 -0
  37. package/dist/types/bias-threshold-policy.types.js +3 -0
  38. package/dist/types/bias-threshold-policy.types.js.map +1 -0
  39. package/dist/types/change-approval-gate.types.d.ts +110 -0
  40. package/dist/types/change-approval-gate.types.js +53 -0
  41. package/dist/types/change-approval-gate.types.js.map +1 -0
  42. package/dist/types/connection.types.d.ts +100 -0
  43. package/dist/types/connection.types.js +3 -0
  44. package/dist/types/connection.types.js.map +1 -0
  45. package/dist/types/connector-manifest.types.d.ts +889 -0
  46. package/dist/types/connector-manifest.types.js +118 -0
  47. package/dist/types/connector-manifest.types.js.map +1 -0
  48. package/dist/types/control-profile.types.d.ts +69 -0
  49. package/dist/types/control-profile.types.js +10 -0
  50. package/dist/types/control-profile.types.js.map +1 -0
  51. package/dist/types/corpus.types.d.ts +2584 -0
  52. package/dist/types/corpus.types.js +120 -0
  53. package/dist/types/corpus.types.js.map +1 -0
  54. package/dist/types/credentials.types.d.ts +18 -0
  55. package/dist/types/credentials.types.js +3 -0
  56. package/dist/types/credentials.types.js.map +1 -0
  57. package/dist/types/dashboard.types.d.ts +205 -0
  58. package/dist/types/dashboard.types.js +3 -0
  59. package/dist/types/dashboard.types.js.map +1 -0
  60. package/dist/types/document-ingestion.types.d.ts +30 -0
  61. package/dist/types/document-ingestion.types.js +3 -0
  62. package/dist/types/document-ingestion.types.js.map +1 -0
  63. package/dist/types/domain-event.types.d.ts +21 -0
  64. package/dist/types/domain-event.types.js +3 -0
  65. package/dist/types/domain-event.types.js.map +1 -0
  66. package/dist/types/drift-dashboard.types.d.ts +17 -0
  67. package/dist/types/drift-dashboard.types.js +3 -0
  68. package/dist/types/drift-dashboard.types.js.map +1 -0
  69. package/dist/types/effective-control-profile.types.d.ts +39 -0
  70. package/dist/types/effective-control-profile.types.js +39 -0
  71. package/dist/types/effective-control-profile.types.js.map +1 -0
  72. package/dist/types/entity-kg.types.d.ts +140 -0
  73. package/dist/types/entity-kg.types.js +3 -0
  74. package/dist/types/entity-kg.types.js.map +1 -0
  75. package/dist/types/entity-model-graph.types.d.ts +63 -0
  76. package/dist/types/entity-model-graph.types.js +3 -0
  77. package/dist/types/entity-model-graph.types.js.map +1 -0
  78. package/dist/types/entity-model-sources.types.d.ts +117 -0
  79. package/dist/types/entity-model-sources.types.js +3 -0
  80. package/dist/types/entity-model-sources.types.js.map +1 -0
  81. package/dist/types/entity.types.d.ts +6 -0
  82. package/dist/types/entity.types.js +3 -0
  83. package/dist/types/entity.types.js.map +1 -0
  84. package/dist/types/failure.types.d.ts +22 -0
  85. package/dist/types/failure.types.js +3 -0
  86. package/dist/types/failure.types.js.map +1 -0
  87. package/dist/types/harvest.types.d.ts +662 -0
  88. package/dist/types/harvest.types.js +52 -0
  89. package/dist/types/harvest.types.js.map +1 -0
  90. package/dist/types/incident.types.d.ts +105 -0
  91. package/dist/types/incident.types.js +3 -0
  92. package/dist/types/incident.types.js.map +1 -0
  93. package/dist/types/introspection.types.d.ts +46 -0
  94. package/dist/types/introspection.types.js +3 -0
  95. package/dist/types/introspection.types.js.map +1 -0
  96. package/dist/types/kb-kg.types.d.ts +38 -0
  97. package/dist/types/kb-kg.types.js +3 -0
  98. package/dist/types/kb-kg.types.js.map +1 -0
  99. package/dist/types/managed-agent.types.d.ts +59 -0
  100. package/dist/types/managed-agent.types.js +11 -0
  101. package/dist/types/managed-agent.types.js.map +1 -0
  102. package/dist/types/object-store.types.d.ts +25 -0
  103. package/dist/types/object-store.types.js +8 -0
  104. package/dist/types/object-store.types.js.map +1 -0
  105. package/dist/types/pipeline.types.d.ts +39 -0
  106. package/dist/types/pipeline.types.js +3 -0
  107. package/dist/types/pipeline.types.js.map +1 -0
  108. package/dist/types/policy.types.d.ts +32 -0
  109. package/dist/types/policy.types.js +3 -0
  110. package/dist/types/policy.types.js.map +1 -0
  111. package/dist/types/risk-classification.types.d.ts +71 -0
  112. package/dist/types/risk-classification.types.js +3 -0
  113. package/dist/types/risk-classification.types.js.map +1 -0
  114. package/dist/types/skill-draft.types.d.ts +271 -0
  115. package/dist/types/skill-draft.types.js +48 -0
  116. package/dist/types/skill-draft.types.js.map +1 -0
  117. package/dist/types/source-mapping.types.d.ts +69 -0
  118. package/dist/types/source-mapping.types.js +3 -0
  119. package/dist/types/source-mapping.types.js.map +1 -0
  120. package/dist/types/synthesize.types.d.ts +90 -0
  121. package/dist/types/synthesize.types.js +41 -0
  122. package/dist/types/synthesize.types.js.map +1 -0
  123. package/dist/types/wizard-assistant.types.d.ts +25 -0
  124. package/dist/types/wizard-assistant.types.js +3 -0
  125. package/dist/types/wizard-assistant.types.js.map +1 -0
  126. package/package.json +55 -0
package/dist/client.js ADDED
@@ -0,0 +1,1197 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BrainAPIClient = exports.INSURANCE_COMPLIANCE_COLLECTIONS = exports.HEALTHCARE_COMPLIANCE_COLLECTIONS = exports.ENTITY_ADMIN_CONFIG_KINDS = void 0;
4
+ exports.createBrainClient = createBrainClient;
5
+ const auth_1 = require("./auth");
6
+ const errors_1 = require("./errors");
7
+ const object_store_types_1 = require("./types/object-store.types");
8
+ const API_PATH_PREFIX = '/api/brain';
9
+ exports.ENTITY_ADMIN_CONFIG_KINDS = ['sso', 'ldap', 'log-streaming', 'rules-engine'];
10
+ exports.HEALTHCARE_COMPLIANCE_COLLECTIONS = [
11
+ 'access-log',
12
+ 'consents',
13
+ 'relationships',
14
+ 'purpose-permissions',
15
+ 'hipaa-checklist',
16
+ ];
17
+ exports.INSURANCE_COMPLIANCE_COLLECTIONS = [
18
+ 'user-tiers',
19
+ 'claims',
20
+ 'siu-investigations',
21
+ 'underwriting',
22
+ 'regulatory-status',
23
+ 'policyholders',
24
+ ];
25
+ const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
26
+ class BrainAPIClient {
27
+ baseUrl;
28
+ entityId;
29
+ apiKey;
30
+ getAccessToken;
31
+ fetchImpl;
32
+ requestTimeoutMs;
33
+ constructor(config) {
34
+ if (!config.baseUrl) {
35
+ throw new Error('BrainAPIClient: baseUrl is required');
36
+ }
37
+ if (!config.entityId) {
38
+ throw new Error('BrainAPIClient: entityId is required');
39
+ }
40
+ this.baseUrl = config.baseUrl.replace(/\/+$/, '');
41
+ this.entityId = config.entityId;
42
+ this.apiKey = config.apiKey;
43
+ this.getAccessToken = config.getAccessToken;
44
+ this.fetchImpl = config.fetchImpl ?? defaultFetch();
45
+ this.requestTimeoutMs = config.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
46
+ }
47
+ getEntityId() {
48
+ return this.entityId;
49
+ }
50
+ async getEntityInfo() {
51
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/info`);
52
+ }
53
+ async registerAgent(body) {
54
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/agents`, {
55
+ method: 'POST',
56
+ body: JSON.stringify(body),
57
+ });
58
+ }
59
+ async resolveTenant() {
60
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/resolve-tenant`, { method: 'POST' });
61
+ }
62
+ async getMyRbacRoles() {
63
+ return this.request('/rbac/my-roles');
64
+ }
65
+ async getUserRbacRoles(userId) {
66
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/rbac/users/${encodeURIComponent(userId)}/roles`);
67
+ }
68
+ async assignRbacRole(userId, roleName) {
69
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/rbac/users/${encodeURIComponent(userId)}/roles`, { method: 'POST', body: JSON.stringify({ roleName }) });
70
+ }
71
+ async removeRbacRole(userId, roleName) {
72
+ await this.request(`/entities/${encodeURIComponent(this.entityId)}/rbac/users/${encodeURIComponent(userId)}/roles/${encodeURIComponent(roleName)}`, { method: 'DELETE' });
73
+ }
74
+ async createDelegation(userId, roleName, expiresAt) {
75
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/rbac/users/${encodeURIComponent(userId)}/delegations`, { method: 'POST', body: JSON.stringify({ roleName, expiresAt }) });
76
+ }
77
+ async revokeDelegation(userId, roleName) {
78
+ await this.request(`/entities/${encodeURIComponent(this.entityId)}/rbac/users/${encodeURIComponent(userId)}/delegations/${encodeURIComponent(roleName)}`, { method: 'DELETE' });
79
+ }
80
+ async getDelegations(userId) {
81
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/rbac/users/${encodeURIComponent(userId)}/delegations`);
82
+ }
83
+ async grantSuperUser(userId, body) {
84
+ return this.request(`/rbac/super-users/${encodeURIComponent(userId)}`, {
85
+ method: 'POST',
86
+ body: JSON.stringify(body),
87
+ });
88
+ }
89
+ async revokeSuperUser(userId, reason) {
90
+ await this.request(`/rbac/super-users/${encodeURIComponent(userId)}`, {
91
+ method: 'DELETE',
92
+ body: JSON.stringify({ reason }),
93
+ });
94
+ }
95
+ async listSuperUsers() {
96
+ return this.request('/rbac/super-users');
97
+ }
98
+ async getSelfSuperUserAccess() {
99
+ return this.request('/rbac/super-users/me');
100
+ }
101
+ async getUserEntities() {
102
+ const { roles } = await this.getMyRbacRoles();
103
+ return roles;
104
+ }
105
+ async getEntityMetadata() {
106
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/rbac/entity-metadata`);
107
+ }
108
+ async bootstrapRbacLogin() {
109
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/rbac/bootstrap-login`, { method: 'POST' });
110
+ }
111
+ async getAgent(agentId) {
112
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/agents/${encodeURIComponent(agentId)}`);
113
+ }
114
+ async getDriftDashboard() {
115
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/drift/dashboard`);
116
+ }
117
+ async deleteAgent(agentId) {
118
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/agents/${encodeURIComponent(agentId)}`, { method: 'DELETE' });
119
+ }
120
+ async updateAgent(agentId, body) {
121
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/agents/${encodeURIComponent(agentId)}`, {
122
+ method: 'PATCH',
123
+ body: JSON.stringify(body.patch),
124
+ });
125
+ }
126
+ async listAgents(params) {
127
+ const url = params?.stages
128
+ ? `/entities/${encodeURIComponent(this.entityId)}/agents?stages=${encodeURIComponent(params.stages.join(','))}`
129
+ : `/entities/${encodeURIComponent(this.entityId)}/agents`;
130
+ return this.request(url);
131
+ }
132
+ async listUsers() {
133
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/users`);
134
+ }
135
+ async assignAgent(agentId, params) {
136
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/agents/${encodeURIComponent(agentId)}/assign`, {
137
+ method: 'POST',
138
+ body: JSON.stringify(params),
139
+ });
140
+ }
141
+ async unassignAgent(agentId) {
142
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/agents/${encodeURIComponent(agentId)}/assign`, { method: 'DELETE' });
143
+ }
144
+ async getAgentAssignment(agentId) {
145
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/agents/${encodeURIComponent(agentId)}/assignment`);
146
+ }
147
+ async listProcessInstances(params) {
148
+ const base = `/entities/${encodeURIComponent(this.entityId)}/processes`;
149
+ const url = params?.status ? `${base}?status=${encodeURIComponent(params.status)}` : base;
150
+ return this.request(url);
151
+ }
152
+ async listEvents(params) {
153
+ const search = new URLSearchParams();
154
+ if (typeof params?.limit === 'number' && Number.isFinite(params.limit)) {
155
+ search.set('limit', String(Math.floor(params.limit)));
156
+ }
157
+ if (params?.domainPackId) {
158
+ search.set('domainPackId', params.domainPackId);
159
+ }
160
+ if (params?.eventType) {
161
+ search.set('eventType', params.eventType);
162
+ }
163
+ const qs = search.toString();
164
+ const base = `/entities/${encodeURIComponent(this.entityId)}/events`;
165
+ return this.request(qs ? `${base}?${qs}` : base);
166
+ }
167
+ async getProcessStages(processId) {
168
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/processes/${encodeURIComponent(processId)}/stages`);
169
+ }
170
+ async advanceStage(processId, stageId, body) {
171
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/processes/${encodeURIComponent(processId)}/stages/${encodeURIComponent(stageId)}/decision`, {
172
+ method: 'POST',
173
+ body: JSON.stringify(body),
174
+ });
175
+ }
176
+ async getDashboardMetrics() {
177
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/metrics/summary`);
178
+ }
179
+ async getRecentActivity(limit) {
180
+ const base = `/entities/${encodeURIComponent(this.entityId)}/activity`;
181
+ const url = typeof limit === 'number' ? `${base}?limit=${limit}` : base;
182
+ return this.request(url);
183
+ }
184
+ async getQueueDepths() {
185
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/dashboard/queue-depths`);
186
+ }
187
+ async getRecentFailures(opts = {}) {
188
+ const params = new URLSearchParams();
189
+ if (opts.limit !== undefined)
190
+ params.set('limit', String(opts.limit));
191
+ if (opts.since !== undefined)
192
+ params.set('since', opts.since);
193
+ if (opts.agentId !== undefined)
194
+ params.set('agentId', opts.agentId);
195
+ const query = params.toString();
196
+ const suffix = query ? `?${query}` : '';
197
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/dashboard/failures${suffix}`);
198
+ }
199
+ async getRunVolume(opts) {
200
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/dashboard/run-volume?window=${opts.window}&bucket=${opts.bucket}`);
201
+ }
202
+ async getLatencySeries(opts) {
203
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/dashboard/latency?window=${opts.window}&bucket=${opts.bucket}`);
204
+ }
205
+ async getTopCapabilities(opts = {}) {
206
+ const params = new URLSearchParams();
207
+ if (opts.window)
208
+ params.set('window', opts.window);
209
+ if (opts.limit !== undefined)
210
+ params.set('limit', String(opts.limit));
211
+ const query = params.toString();
212
+ const suffix = query ? `?${query}` : '';
213
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/dashboard/top-capabilities${suffix}`);
214
+ }
215
+ async getEntityLicenseUsage() {
216
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/licenses`);
217
+ }
218
+ async getLicensePool() {
219
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/licenses/pool`);
220
+ }
221
+ async getSeatLicenses() {
222
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/licenses/seats`);
223
+ }
224
+ async createSeatLicense(body) {
225
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/licenses/seats`, {
226
+ method: 'POST',
227
+ body: JSON.stringify(body),
228
+ });
229
+ }
230
+ async updateSeatLicense(seatId, body) {
231
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/licenses/seats/${encodeURIComponent(seatId)}`, {
232
+ method: 'PATCH',
233
+ body: JSON.stringify(body),
234
+ });
235
+ }
236
+ async deleteSeatLicense(seatId) {
237
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/licenses/seats/${encodeURIComponent(seatId)}`, { method: 'DELETE' });
238
+ }
239
+ async getLicenseUsageHistory(period) {
240
+ const base = `/entities/${encodeURIComponent(this.entityId)}/licenses/history`;
241
+ const url = period ? `${base}?${new URLSearchParams({ period }).toString()}` : base;
242
+ return this.request(url);
243
+ }
244
+ async getLicenseAwareUtilization() {
245
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/licenses/utilization`);
246
+ }
247
+ async listAgentGroups() {
248
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/groups`);
249
+ }
250
+ async getSeatLicenseUsage(seatLicenseId) {
251
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/seats/${encodeURIComponent(seatLicenseId)}/license`);
252
+ }
253
+ async listDispatches() {
254
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/dispatches`);
255
+ }
256
+ async getDispatch(dispatchId) {
257
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/dispatches/${encodeURIComponent(dispatchId)}`);
258
+ }
259
+ async cancelDispatch(dispatchId) {
260
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/dispatch/${encodeURIComponent(dispatchId)}/cancel`, { method: 'POST' });
261
+ }
262
+ async listMeshSubscriptionHealth() {
263
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/mesh/subscriptions`);
264
+ }
265
+ async stopAgent(agentId) {
266
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/agents/${encodeURIComponent(agentId)}/stop`, { method: 'POST' });
267
+ }
268
+ async restartAgent(agentId) {
269
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/agents/${encodeURIComponent(agentId)}/restart`, { method: 'POST' });
270
+ }
271
+ async dispatch(body) {
272
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/dispatch`, {
273
+ method: 'POST',
274
+ body: JSON.stringify(body),
275
+ });
276
+ }
277
+ async getAgentWorkItems(agentId, params) {
278
+ const base = `/entities/${encodeURIComponent(this.entityId)}/agents/${encodeURIComponent(agentId)}/work-items`;
279
+ const query = new URLSearchParams();
280
+ if (typeof params?.limit === 'number') {
281
+ query.set('limit', String(params.limit));
282
+ }
283
+ if (typeof params?.offset === 'number') {
284
+ query.set('offset', String(params.offset));
285
+ }
286
+ const qs = query.toString();
287
+ return this.request(qs ? `${base}?${qs}` : base);
288
+ }
289
+ async enqueueWorkItem(agentId, body) {
290
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/agents/${encodeURIComponent(agentId)}/work-items/enqueue`, {
291
+ method: 'POST',
292
+ body: JSON.stringify(body),
293
+ });
294
+ }
295
+ async reassignWorkItem(agentId, workItemId, body = {}) {
296
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/agents/${encodeURIComponent(agentId)}/work-items/${encodeURIComponent(workItemId)}/reassign`, {
297
+ method: 'POST',
298
+ body: JSON.stringify(body),
299
+ });
300
+ }
301
+ async listOperatorSignals(params) {
302
+ const url = params?.since
303
+ ? `/entities/${encodeURIComponent(this.entityId)}/operator-signals?since=${encodeURIComponent(params.since)}`
304
+ : `/entities/${encodeURIComponent(this.entityId)}/operator-signals`;
305
+ return this.request(url);
306
+ }
307
+ async getSystemHealth() {
308
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/system-health`);
309
+ }
310
+ async getPolicyCatalog() {
311
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/policies`);
312
+ }
313
+ async getAgentPolicyHistory(agentId, params) {
314
+ const base = `/entities/${encodeURIComponent(this.entityId)}/agents/${encodeURIComponent(agentId)}/policy-history`;
315
+ const url = params?.window ? `${base}?window=${encodeURIComponent(params.window)}` : base;
316
+ return this.request(url);
317
+ }
318
+ async listControlProfiles() {
319
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/control-profiles`);
320
+ }
321
+ async getControlProfile(tier) {
322
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/control-profiles/${encodeURIComponent(tier)}`);
323
+ }
324
+ async getControlProfileAudit(tier, opts = {}) {
325
+ const query = [];
326
+ if (opts.limit !== undefined)
327
+ query.push(`limit=${String(opts.limit)}`);
328
+ if (opts.offset !== undefined)
329
+ query.push(`offset=${String(opts.offset)}`);
330
+ const qs = query.length > 0 ? `?${query.join('&')}` : '';
331
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/control-profiles/${encodeURIComponent(tier)}/audit${qs}`);
332
+ }
333
+ async setControlProfileOverride(tier, body) {
334
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/control-profiles/${encodeURIComponent(tier)}`, { method: 'PUT', body: JSON.stringify(body) });
335
+ }
336
+ async clearControlProfileOverride(tier, body) {
337
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/control-profiles/${encodeURIComponent(tier)}`, { method: 'DELETE', body: JSON.stringify(body) });
338
+ }
339
+ async listChangeApprovalPolicies() {
340
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/change-approval/policies`);
341
+ }
342
+ async getChangeApprovalPolicy(tier) {
343
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/change-approval/policies/${encodeURIComponent(tier)}`);
344
+ }
345
+ async getChangeApprovalPolicyAudit(tier) {
346
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/change-approval/policies/${encodeURIComponent(tier)}/audit`);
347
+ }
348
+ async setChangeApprovalPolicyOverride(tier, body) {
349
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/change-approval/policies/${encodeURIComponent(tier)}`, { method: 'PUT', body: JSON.stringify(body) });
350
+ }
351
+ async clearChangeApprovalPolicyOverride(tier, body) {
352
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/change-approval/policies/${encodeURIComponent(tier)}`, { method: 'DELETE', body: JSON.stringify(body) });
353
+ }
354
+ async recordChangeApprovalDecision(changeId, body) {
355
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/change-approval/changes/${encodeURIComponent(changeId)}/decisions`, { method: 'POST', body: JSON.stringify(body) });
356
+ }
357
+ async listChangeApprovalDecisions(changeId) {
358
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/change-approval/changes/${encodeURIComponent(changeId)}/decisions`);
359
+ }
360
+ async getChangeApprovalVerdict(changeId, tier) {
361
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/change-approval/changes/${encodeURIComponent(changeId)}/verdict?tier=${encodeURIComponent(tier)}`);
362
+ }
363
+ async wizardAssistantTurn(agentId, body) {
364
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/agents/${encodeURIComponent(agentId)}/wizard-assistant/turn`, { method: 'POST', body: JSON.stringify(body) });
365
+ }
366
+ async transitionLifecycle(entityKind, targetId, body) {
367
+ const segment = entityKind === 'agent' ? 'agents' : 'skills';
368
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/${segment}/${encodeURIComponent(targetId)}/lifecycle/transition`, { method: 'POST', body: JSON.stringify(body) });
369
+ }
370
+ async getLifecycleStatus(entityKind, targetId) {
371
+ const segment = entityKind === 'agent' ? 'agents' : 'skills';
372
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/${segment}/${encodeURIComponent(targetId)}/lifecycle/status`);
373
+ }
374
+ async classifyAgent(agentId, body) {
375
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/agents/${encodeURIComponent(agentId)}/risk-classification`, { method: 'POST', body: JSON.stringify(body) });
376
+ }
377
+ async getEffectiveControlProfile(agentId) {
378
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/agents/${encodeURIComponent(agentId)}/effective-control-profile`, { method: 'GET' });
379
+ }
380
+ async getBiasThresholdPolicy() {
381
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/bias-threshold-policy`, { method: 'GET' });
382
+ }
383
+ async updateBiasThresholdPolicy(body) {
384
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/bias-threshold-policy`, { method: 'PUT', body: JSON.stringify(body) });
385
+ }
386
+ async getWorkAssignmentEvents(params) {
387
+ const base = `/entities/${encodeURIComponent(this.entityId)}/work-assignments/events`;
388
+ const query = new URLSearchParams();
389
+ if (params?.agentId)
390
+ query.set('agentId', params.agentId);
391
+ if (params?.userSub)
392
+ query.set('userSub', params.userSub);
393
+ if (params?.workItemId)
394
+ query.set('workItemId', params.workItemId);
395
+ if (params?.since)
396
+ query.set('since', params.since);
397
+ if (typeof params?.limit === 'number')
398
+ query.set('limit', String(params.limit));
399
+ const qs = query.toString();
400
+ return this.request(qs ? `${base}?${qs}` : base);
401
+ }
402
+ async getDecisionLineage(signalId) {
403
+ if (!signalId) {
404
+ throw new Error('BrainAPIClient.getDecisionLineage: signalId is required');
405
+ }
406
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/signals/${encodeURIComponent(signalId)}/decision-lineage`);
407
+ }
408
+ async recordDecisionLineage(signalId, body) {
409
+ if (!signalId) {
410
+ throw new Error('BrainAPIClient.recordDecisionLineage: signalId is required');
411
+ }
412
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/signals/${encodeURIComponent(signalId)}/decision-lineage`, {
413
+ method: 'POST',
414
+ body: JSON.stringify(body),
415
+ });
416
+ }
417
+ async listDecisionLineage(params) {
418
+ const base = `/entities/${encodeURIComponent(this.entityId)}/decision-lineage`;
419
+ const query = new URLSearchParams();
420
+ if (params?.decisionId)
421
+ query.set('decisionId', params.decisionId);
422
+ if (params?.consumerRef)
423
+ query.set('consumerRef', params.consumerRef);
424
+ if (params?.skill)
425
+ query.set('skill', params.skill);
426
+ if (params?.skillVersion)
427
+ query.set('skillVersion', params.skillVersion);
428
+ if (params?.modelProvider)
429
+ query.set('modelProvider', params.modelProvider);
430
+ if (params?.modelName)
431
+ query.set('modelName', params.modelName);
432
+ if (params?.riskTier)
433
+ query.set('riskTier', params.riskTier);
434
+ if (params?.consumerImpacting !== undefined) {
435
+ query.set('consumerImpacting', String(params.consumerImpacting));
436
+ }
437
+ if (params?.hitlApprovalRequired !== undefined) {
438
+ query.set('hitlApprovalRequired', String(params.hitlApprovalRequired));
439
+ }
440
+ if (params?.startDate)
441
+ query.set('from', params.startDate);
442
+ if (params?.endDate)
443
+ query.set('to', params.endDate);
444
+ if (typeof params?.limit === 'number')
445
+ query.set('limit', String(params.limit));
446
+ if (typeof params?.offset === 'number')
447
+ query.set('offset', String(params.offset));
448
+ const qs = query.toString();
449
+ return this.request(qs ? `${base}?${qs}` : base);
450
+ }
451
+ async listEntityPipelines() {
452
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/pipelines`);
453
+ }
454
+ async listPipelineRuns(pipelineId, options = {}) {
455
+ if (!pipelineId) {
456
+ throw new Error('BrainAPIClient.listPipelineRuns: pipelineId is required');
457
+ }
458
+ const params = new URLSearchParams();
459
+ if (options.limit !== undefined) {
460
+ params.set('limit', String(options.limit));
461
+ }
462
+ const query = params.toString();
463
+ const suffix = query ? `?${query}` : '';
464
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/pipelines/${encodeURIComponent(pipelineId)}/runs${suffix}`);
465
+ }
466
+ async deletePipeline(pipelineId) {
467
+ if (!pipelineId) {
468
+ throw new Error('BrainAPIClient.deletePipeline: pipelineId is required');
469
+ }
470
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/pipelines/${encodeURIComponent(pipelineId)}`, { method: 'DELETE' });
471
+ }
472
+ async listIncidents(filter) {
473
+ const base = `/entities/${encodeURIComponent(this.entityId)}/incidents`;
474
+ const query = new URLSearchParams();
475
+ if (filter?.status)
476
+ query.set('status', filter.status);
477
+ if (filter?.severity)
478
+ query.set('severity', filter.severity);
479
+ if (filter?.triggerType)
480
+ query.set('triggerType', filter.triggerType);
481
+ if (filter?.agentId)
482
+ query.set('agentId', filter.agentId);
483
+ const qs = query.toString();
484
+ return this.request(qs ? `${base}?${qs}` : base);
485
+ }
486
+ async getIncident(incidentId) {
487
+ if (!incidentId) {
488
+ throw new Error('BrainAPIClient.getIncident: incidentId is required');
489
+ }
490
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/incidents/${encodeURIComponent(incidentId)}`);
491
+ }
492
+ async createIncident(body) {
493
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/incidents`, {
494
+ method: 'POST',
495
+ body: JSON.stringify({ ...body, entityId: this.entityId }),
496
+ });
497
+ }
498
+ async ackIncident(incidentId, body) {
499
+ if (!incidentId) {
500
+ throw new Error('BrainAPIClient.ackIncident: incidentId is required');
501
+ }
502
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/incidents/${encodeURIComponent(incidentId)}/ack`, {
503
+ method: 'POST',
504
+ body: JSON.stringify(body),
505
+ });
506
+ }
507
+ async assignIncident(incidentId, body) {
508
+ if (!incidentId) {
509
+ throw new Error('BrainAPIClient.assignIncident: incidentId is required');
510
+ }
511
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/incidents/${encodeURIComponent(incidentId)}/assign`, {
512
+ method: 'POST',
513
+ body: JSON.stringify(body),
514
+ });
515
+ }
516
+ async resolveIncident(incidentId, body) {
517
+ if (!incidentId) {
518
+ throw new Error('BrainAPIClient.resolveIncident: incidentId is required');
519
+ }
520
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/incidents/${encodeURIComponent(incidentId)}/resolve`, {
521
+ method: 'POST',
522
+ body: JSON.stringify(body),
523
+ });
524
+ }
525
+ async listA2AVendors() {
526
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/a2a/vendors`);
527
+ }
528
+ async registerA2AVendor(req) {
529
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/a2a/vendors`, {
530
+ method: 'POST',
531
+ body: JSON.stringify(req),
532
+ });
533
+ }
534
+ async suspendA2AVendor(vendor) {
535
+ await this.request(`/entities/${encodeURIComponent(this.entityId)}/a2a/vendors/${encodeURIComponent(vendor)}`, { method: 'DELETE' });
536
+ }
537
+ async getProvenanceMix() {
538
+ const response = await this.listA2AVendors();
539
+ return response.provenanceMix;
540
+ }
541
+ async listA2AAgents() {
542
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/a2a/agents`);
543
+ }
544
+ async listConnections() {
545
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/connections`);
546
+ }
547
+ async getConnection(connectionId) {
548
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/connections/${encodeURIComponent(connectionId)}`);
549
+ }
550
+ async createConnection(body) {
551
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/connections`, { method: 'POST', body: JSON.stringify(body) });
552
+ }
553
+ async updateConnection(connectionId, body) {
554
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/connections/${encodeURIComponent(connectionId)}`, { method: 'PUT', body: JSON.stringify(body) });
555
+ }
556
+ async deleteConnection(connectionId) {
557
+ await this.request(`/entities/${encodeURIComponent(this.entityId)}/connections/${encodeURIComponent(connectionId)}`, { method: 'DELETE' });
558
+ }
559
+ async putCredential(connectionId, secret) {
560
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/credentials/${encodeURIComponent(connectionId)}`, { method: 'PUT', body: JSON.stringify(secret) });
561
+ }
562
+ async deleteCredential(connectionId) {
563
+ await this.request(`/entities/${encodeURIComponent(this.entityId)}/credentials/${encodeURIComponent(connectionId)}`, { method: 'DELETE' });
564
+ }
565
+ async mintScopedCredential(connectionId) {
566
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/credentials/${encodeURIComponent(connectionId)}/mint-scoped`, { method: 'POST' });
567
+ }
568
+ async persistRefreshedCredential(connectionId, refreshedCredential) {
569
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/credentials/${encodeURIComponent(connectionId)}/refresh`, {
570
+ method: 'POST',
571
+ body: JSON.stringify(refreshedCredential),
572
+ });
573
+ }
574
+ async introspectListTables(connectionId) {
575
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/introspect/list-tables`, { method: 'POST', body: JSON.stringify({ connectionId }) });
576
+ }
577
+ async introspectTable(body) {
578
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/introspect/introspect-table`, { method: 'POST', body: JSON.stringify(body) });
579
+ }
580
+ async introspectSampleValues(body) {
581
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/introspect/sample-values`, { method: 'POST', body: JSON.stringify(body) });
582
+ }
583
+ async listSourceDefinitions() {
584
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/source-mappings/sources`);
585
+ }
586
+ async getSourceDefinition(sourceId) {
587
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/source-mappings/sources/${encodeURIComponent(sourceId)}`);
588
+ }
589
+ async putSourceDefinition(sourceId, body) {
590
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/source-mappings/sources/${encodeURIComponent(sourceId)}`, { method: 'PUT', body: JSON.stringify(body) });
591
+ }
592
+ async deleteSourceDefinition(sourceId) {
593
+ await this.request(`/entities/${encodeURIComponent(this.entityId)}/source-mappings/sources/${encodeURIComponent(sourceId)}`, { method: 'DELETE' });
594
+ }
595
+ async listMappingConfigs() {
596
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/source-mappings/configs`);
597
+ }
598
+ async getMappingConfig(configId) {
599
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/source-mappings/configs/${encodeURIComponent(configId)}`);
600
+ }
601
+ async putMappingConfig(configId, body) {
602
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/source-mappings/configs/${encodeURIComponent(configId)}`, { method: 'PUT', body: JSON.stringify(body) });
603
+ }
604
+ async deleteMappingConfig(configId) {
605
+ await this.request(`/entities/${encodeURIComponent(this.entityId)}/source-mappings/configs/${encodeURIComponent(configId)}`, { method: 'DELETE' });
606
+ }
607
+ async listEntityModels() {
608
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/entity-models`);
609
+ }
610
+ async getEntityModel(modelId) {
611
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/entity-models/${encodeURIComponent(modelId)}`);
612
+ }
613
+ async upsertEntityModelType(modelId, entityType) {
614
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/entity-models/${encodeURIComponent(modelId)}/entity-types`, { method: 'POST', body: JSON.stringify(entityType) });
615
+ }
616
+ async deleteEntityModelType(modelId, entityTypeId) {
617
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/entity-models/${encodeURIComponent(modelId)}/entity-types/${encodeURIComponent(entityTypeId)}`, { method: 'DELETE' });
618
+ }
619
+ async upsertEntityModelRelationship(modelId, relationship) {
620
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/entity-models/${encodeURIComponent(modelId)}/relationships`, { method: 'POST', body: JSON.stringify(relationship) });
621
+ }
622
+ async deleteEntityModelRelationship(modelId, relationshipId) {
623
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/entity-models/${encodeURIComponent(modelId)}/relationships/${encodeURIComponent(relationshipId)}`, { method: 'DELETE' });
624
+ }
625
+ async aiKnowledge(op, body) {
626
+ const res = await this.request(`/entities/${encodeURIComponent(this.entityId)}/ai-knowledge/${op}`, { method: 'POST', body: JSON.stringify(body) });
627
+ return res.result;
628
+ }
629
+ aiSimilarWorkflows(body) {
630
+ return this.aiKnowledge('similar-workflows', body);
631
+ }
632
+ aiSuggestNextNodes(body) {
633
+ return this.aiKnowledge('suggest-next-nodes', body);
634
+ }
635
+ aiParameterSuggestions(body) {
636
+ return this.aiKnowledge('parameter-suggestions', body);
637
+ }
638
+ aiSmartDefaults(body) {
639
+ return this.aiKnowledge('smart-defaults', body);
640
+ }
641
+ aiScoreQuality(body) {
642
+ return this.aiKnowledge('score-quality', body);
643
+ }
644
+ async aiLearnFromImport(body) {
645
+ await this.aiKnowledge('learn-from-import', body);
646
+ }
647
+ async aiRecordNodeUsage(body) {
648
+ await this.aiKnowledge('record-node-usage', body);
649
+ }
650
+ async bestPracticesKg(op, body) {
651
+ const res = await this.request(`/entities/${encodeURIComponent(this.entityId)}/best-practices-kg/${op}`, { method: 'POST', body: JSON.stringify(body) });
652
+ return res.result;
653
+ }
654
+ bpkgStatistics() {
655
+ return this.bestPracticesKg('statistics', {});
656
+ }
657
+ bpkgTraverse(body) {
658
+ return this.bestPracticesKg('traverse', body);
659
+ }
660
+ bpkgRelationshipsForPractice(body) {
661
+ return this.bestPracticesKg('relationships-for-practice', body);
662
+ }
663
+ bpkgRecommendations(body) {
664
+ return this.bestPracticesKg('recommendations', body);
665
+ }
666
+ bpkgShortestPath(body) {
667
+ return this.bestPracticesKg('shortest-path', body);
668
+ }
669
+ bpkgDetectConflicts(body) {
670
+ return this.bestPracticesKg('detect-conflicts', body);
671
+ }
672
+ async kbKg(op, body) {
673
+ const res = await this.request(`/entities/${encodeURIComponent(this.entityId)}/kb-kg/${op}`, { method: 'POST', body: JSON.stringify(body) });
674
+ return res.result;
675
+ }
676
+ kbKgFindRelated(body) {
677
+ return this.kbKg('find-related', body);
678
+ }
679
+ kbKgFindByEntity(body) {
680
+ return this.kbKg('find-by-entity', body);
681
+ }
682
+ kbKgStatistics() {
683
+ return this.kbKg('statistics', {});
684
+ }
685
+ async entityKg(op, body) {
686
+ const res = await this.request(`/entities/${encodeURIComponent(this.entityId)}/entity-kg/${op}`, { method: 'POST', body: JSON.stringify(body) });
687
+ return res.result;
688
+ }
689
+ entityKgHealthCheck() {
690
+ return this.entityKg('health-check', {});
691
+ }
692
+ entityKgStatistics() {
693
+ return this.entityKg('statistics', {});
694
+ }
695
+ entityKgGetEntity(body) {
696
+ return this.entityKg('get-entity', body);
697
+ }
698
+ entityKgFindEntities(body) {
699
+ return this.entityKg('find-entities', body);
700
+ }
701
+ entityKgSearchEntities(body) {
702
+ return this.entityKg('search-entities', body);
703
+ }
704
+ entityKgGetEntityRelationships(body) {
705
+ return this.entityKg('get-entity-relationships', body);
706
+ }
707
+ entityKgRelationshipsByEntityIds(body) {
708
+ return this.entityKg('relationships-by-entity-ids', body);
709
+ }
710
+ entityKgTraverse(body) {
711
+ return this.entityKg('traverse', body);
712
+ }
713
+ entityKgFindPath(body) {
714
+ return this.entityKg('find-path', body);
715
+ }
716
+ async entityKgRawReadQuery(body) {
717
+ const res = await this.request(`/entities/${encodeURIComponent(this.entityId)}/entity-kg/raw-read-query`, { method: 'POST', body: JSON.stringify(body) });
718
+ return res.rows;
719
+ }
720
+ async listEntityModelSources() {
721
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/entity-model-sources/sources`);
722
+ }
723
+ async getEntityModelSource(sourceId) {
724
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/entity-model-sources/sources/${encodeURIComponent(sourceId)}`);
725
+ }
726
+ async createEntityModelSource(body) {
727
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/entity-model-sources/sources`, { method: 'POST', body: JSON.stringify(body) });
728
+ }
729
+ async updateEntityModelSource(sourceId, body) {
730
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/entity-model-sources/sources/${encodeURIComponent(sourceId)}`, { method: 'PUT', body: JSON.stringify(body) });
731
+ }
732
+ async deleteEntityModelSource(sourceId) {
733
+ await this.request(`/entities/${encodeURIComponent(this.entityId)}/entity-model-sources/sources/${encodeURIComponent(sourceId)}`, { method: 'DELETE' });
734
+ }
735
+ async syncEntityModelSource(sourceId) {
736
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/entity-model-sources/sources/${encodeURIComponent(sourceId)}/sync`, { method: 'POST' });
737
+ }
738
+ async checkEntityModelSourceReferences(sourceId) {
739
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/entity-model-sources/sources/${encodeURIComponent(sourceId)}/references`);
740
+ }
741
+ async discoverEntityModelSourceEntities(sourceId) {
742
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/entity-model-sources/sources/${encodeURIComponent(sourceId)}/discover-entities`, { method: 'POST' });
743
+ }
744
+ async testEntityModelSourceConnection(sourceId) {
745
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/entity-model-sources/sources/${encodeURIComponent(sourceId)}/test-connection`, { method: 'POST' });
746
+ }
747
+ async triggerDocumentIngestion(input) {
748
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/document-ingestion`, { method: 'POST', body: JSON.stringify(input) });
749
+ }
750
+ async getDocumentIngestionStatus(jobId) {
751
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/document-ingestion/${encodeURIComponent(jobId)}`);
752
+ }
753
+ async appendDomainEvent(event) {
754
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/event-log`, { method: 'POST', body: JSON.stringify(event) });
755
+ }
756
+ async appendDomainEventBatch(events) {
757
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/event-log/batch`, { method: 'POST', body: JSON.stringify({ events }) });
758
+ }
759
+ async getDomainEvent(eventId) {
760
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/event-log/${encodeURIComponent(eventId)}`);
761
+ }
762
+ objectsPath(objectPath) {
763
+ const encoded = objectPath
764
+ .split('/')
765
+ .map((seg) => encodeURIComponent(seg))
766
+ .join('/');
767
+ return `/entities/${encodeURIComponent(this.entityId)}/objects/${encoded}`;
768
+ }
769
+ async getObject(bucket, objectPath) {
770
+ const response = await this.rawFetch(this.objectsPath(objectPath), {
771
+ method: 'GET',
772
+ headers: { [object_store_types_1.OBJECT_BUCKET_HEADER]: bucket },
773
+ });
774
+ const data = Buffer.from(await response.arrayBuffer());
775
+ return {
776
+ data,
777
+ contentType: response.headers.get('content-type') ?? 'application/octet-stream',
778
+ };
779
+ }
780
+ async putObject(bucket, objectPath, data, opts) {
781
+ const headers = {
782
+ [object_store_types_1.OBJECT_BUCKET_HEADER]: bucket,
783
+ 'Content-Type': opts?.contentType ?? 'application/octet-stream',
784
+ };
785
+ if (opts?.cacheControl)
786
+ headers['Cache-Control'] = opts.cacheControl;
787
+ if (opts?.ifNotExists)
788
+ headers['If-None-Match'] = '*';
789
+ await this.rawFetch(this.objectsPath(objectPath), {
790
+ method: 'PUT',
791
+ headers,
792
+ body: Buffer.from(data),
793
+ });
794
+ }
795
+ async deleteObject(bucket, objectPath) {
796
+ await this.rawFetch(this.objectsPath(objectPath), {
797
+ method: 'DELETE',
798
+ headers: { [object_store_types_1.OBJECT_BUCKET_HEADER]: bucket },
799
+ });
800
+ }
801
+ async headObject(bucket, objectPath) {
802
+ const response = await this.rawFetch(this.objectsPath(objectPath), {
803
+ method: 'HEAD',
804
+ headers: { [object_store_types_1.OBJECT_BUCKET_HEADER]: bucket },
805
+ });
806
+ const sizeHeader = response.headers.get('x-object-size') ?? response.headers.get('content-length');
807
+ return {
808
+ size: Number(sizeHeader ?? '0'),
809
+ updated: response.headers.get('x-object-updated') ?? new Date(0).toISOString(),
810
+ checksum: response.headers.get('x-object-checksum') ?? '',
811
+ contentType: response.headers.get('content-type') ?? undefined,
812
+ };
813
+ }
814
+ async listObjects(bucket, prefix) {
815
+ return this.request(`${this.objectsPath(prefix)}?list=1`, {
816
+ method: 'GET',
817
+ headers: { [object_store_types_1.OBJECT_BUCKET_HEADER]: bucket },
818
+ });
819
+ }
820
+ async signObjectUrl(bucket, body) {
821
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/objects:sign`, { method: 'POST', headers: { [object_store_types_1.OBJECT_BUCKET_HEADER]: bucket }, body: JSON.stringify(body) });
822
+ }
823
+ async rawFetch(endpoint, init = {}) {
824
+ const url = `${this.baseUrl}${API_PATH_PREFIX}${endpoint}`;
825
+ const headers = new Headers(init.headers);
826
+ const authHeader = await (0, auth_1.resolveAuthorizationHeader)(this.getAccessToken);
827
+ if (authHeader) {
828
+ headers.set('Authorization', authHeader);
829
+ }
830
+ else if (this.apiKey) {
831
+ headers.set('X-API-Key', this.apiKey);
832
+ }
833
+ const controller = new AbortController();
834
+ const callerSignal = init.signal;
835
+ if (callerSignal) {
836
+ if (callerSignal.aborted) {
837
+ controller.abort(callerSignal.reason);
838
+ }
839
+ else {
840
+ callerSignal.addEventListener('abort', () => controller.abort(callerSignal.reason));
841
+ }
842
+ }
843
+ let timeoutHandle;
844
+ if (this.requestTimeoutMs > 0) {
845
+ timeoutHandle = setTimeout(() => controller.abort(new Error('request-timeout')), this.requestTimeoutMs);
846
+ }
847
+ let response;
848
+ try {
849
+ response = await this.fetchImpl(url, { ...init, headers, signal: controller.signal });
850
+ }
851
+ catch (err) {
852
+ const errAsObj = err;
853
+ const errName = typeof errAsObj?.name === 'string' ? errAsObj.name : '';
854
+ const errMessage = typeof errAsObj?.message === 'string' ? errAsObj.message : '';
855
+ const isAbort = errName === 'AbortError' || /aborted|abort/i.test(errMessage);
856
+ if (isAbort && (!callerSignal || !callerSignal.aborted)) {
857
+ throw new errors_1.BrainAPIError({
858
+ status: 408,
859
+ url,
860
+ method: init.method ?? 'GET',
861
+ body: { error: `Request timed out after ${this.requestTimeoutMs}ms` },
862
+ message: `Brain API request timed out after ${this.requestTimeoutMs}ms: ${init.method ?? 'GET'} ${url}`,
863
+ });
864
+ }
865
+ throw err;
866
+ }
867
+ finally {
868
+ if (timeoutHandle !== undefined) {
869
+ clearTimeout(timeoutHandle);
870
+ }
871
+ }
872
+ if (!response.ok) {
873
+ let body;
874
+ try {
875
+ body = await response.json();
876
+ }
877
+ catch {
878
+ body = undefined;
879
+ }
880
+ throw new errors_1.BrainAPIError({
881
+ status: response.status,
882
+ url,
883
+ method: init.method ?? 'GET',
884
+ body,
885
+ });
886
+ }
887
+ return response;
888
+ }
889
+ async getEntityAdminConfig(kind) {
890
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/admin-config/${encodeURIComponent(kind)}`);
891
+ }
892
+ async putEntityAdminConfig(kind, config) {
893
+ await this.request(`/entities/${encodeURIComponent(this.entityId)}/admin-config/${encodeURIComponent(kind)}`, { method: 'PUT', body: JSON.stringify(config) });
894
+ }
895
+ async getExternalSecretsConfig() {
896
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/external-secrets`);
897
+ }
898
+ async putExternalSecretsConfig(config) {
899
+ await this.request(`/entities/${encodeURIComponent(this.entityId)}/external-secrets`, {
900
+ method: 'PUT',
901
+ body: JSON.stringify(config),
902
+ });
903
+ }
904
+ async testExternalSecretsProvider(providerId) {
905
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/external-secrets/` +
906
+ `${encodeURIComponent(providerId)}/test`, { method: 'POST', body: JSON.stringify({}) });
907
+ }
908
+ async rotateExternalSecretsProvider(providerId) {
909
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/external-secrets/` +
910
+ `${encodeURIComponent(providerId)}/rotate`, { method: 'POST', body: JSON.stringify({}) });
911
+ }
912
+ async getExternalAdapterConfig() {
913
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/external-adapter-config`);
914
+ }
915
+ async putExternalAdapterConfig(config) {
916
+ await this.request(`/entities/${encodeURIComponent(this.entityId)}/external-adapter-config`, {
917
+ method: 'PUT',
918
+ body: JSON.stringify(config),
919
+ });
920
+ }
921
+ async getFieldSecurityPolicies() {
922
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/field-security/policies`);
923
+ }
924
+ async putFieldSecurityPolicies(config) {
925
+ await this.request(`/entities/${encodeURIComponent(this.entityId)}/field-security/policies`, {
926
+ method: 'PUT',
927
+ body: JSON.stringify(config),
928
+ });
929
+ }
930
+ async applyFieldSecurityPolicyChange(body) {
931
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/field-security/policies/actions/change`, {
932
+ method: 'POST',
933
+ body: JSON.stringify(body),
934
+ });
935
+ }
936
+ healthcarePath(suffix) {
937
+ return `/entities/${encodeURIComponent(this.entityId)}/compliance/healthcare${suffix}`;
938
+ }
939
+ async getHealthcareComplianceCollection(collection) {
940
+ return this.request(this.healthcarePath(`/${collection}`));
941
+ }
942
+ async accessHealthcarePHI(request) {
943
+ return this.request(this.healthcarePath('/phi-access'), {
944
+ method: 'POST',
945
+ body: JSON.stringify(request),
946
+ });
947
+ }
948
+ async createHealthcareRelationship(params) {
949
+ return this.request(this.healthcarePath('/relationships'), {
950
+ method: 'POST',
951
+ body: JSON.stringify(params),
952
+ });
953
+ }
954
+ async toggleHealthcareRelationship(relationshipId, active) {
955
+ await this.request(this.healthcarePath(`/relationships/${encodeURIComponent(relationshipId)}/toggle`), {
956
+ method: 'POST',
957
+ body: JSON.stringify({ active }),
958
+ });
959
+ }
960
+ async revokeHealthcareConsent(consentId) {
961
+ await this.request(this.healthcarePath(`/consents/${encodeURIComponent(consentId)}/revoke`), {
962
+ method: 'POST',
963
+ body: JSON.stringify({}),
964
+ });
965
+ }
966
+ async grantHealthcarePurpose(params) {
967
+ return this.request(this.healthcarePath('/purpose-permissions'), {
968
+ method: 'POST',
969
+ body: JSON.stringify(params),
970
+ });
971
+ }
972
+ async revokeHealthcarePurpose(permissionId) {
973
+ await this.request(this.healthcarePath(`/purpose-permissions/${encodeURIComponent(permissionId)}/revoke`), { method: 'POST', body: JSON.stringify({}) });
974
+ }
975
+ async getFinanceComplianceDoc() {
976
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/compliance/finance`);
977
+ }
978
+ async putFinanceComplianceDoc(config) {
979
+ await this.request(`/entities/${encodeURIComponent(this.entityId)}/compliance/finance`, {
980
+ method: 'PUT',
981
+ body: JSON.stringify(config),
982
+ });
983
+ }
984
+ async getComplianceSettings() {
985
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/compliance/settings`);
986
+ }
987
+ async putComplianceSettings(config, opts = {}) {
988
+ const res = await this.request(`/entities/${encodeURIComponent(this.entityId)}/compliance/settings`, {
989
+ method: 'PUT',
990
+ ...(opts.ifGenerationMatch !== undefined
991
+ ? { headers: { 'If-Match': String(opts.ifGenerationMatch) } }
992
+ : {}),
993
+ body: JSON.stringify(config),
994
+ });
995
+ return { generation: res.generation };
996
+ }
997
+ async financeAccessPCI(request) {
998
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/compliance/finance/access-pci`, { method: 'POST', body: JSON.stringify(request) });
999
+ }
1000
+ async insuranceAccessPolicyholder(request) {
1001
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/compliance/insurance/access-policyholder`, { method: 'POST', body: JSON.stringify(request) });
1002
+ }
1003
+ async getComplianceAuditLogs(query = {}) {
1004
+ const params = new URLSearchParams();
1005
+ for (const [key, value] of Object.entries(query)) {
1006
+ if (value !== undefined)
1007
+ params.set(key, String(value));
1008
+ }
1009
+ const qs = params.toString();
1010
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/compliance/audit/logs${qs ? `?${qs}` : ''}`);
1011
+ }
1012
+ async putComplianceAuditLog(doc) {
1013
+ await this.request(`/entities/${encodeURIComponent(this.entityId)}/compliance/audit/logs`, {
1014
+ method: 'PUT',
1015
+ body: JSON.stringify(doc),
1016
+ });
1017
+ }
1018
+ async verifyComplianceAuditChain() {
1019
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/compliance/audit/verify-chain`);
1020
+ }
1021
+ async exportComplianceAuditCsv(query = {}) {
1022
+ const params = new URLSearchParams();
1023
+ for (const [key, value] of Object.entries(query)) {
1024
+ if (value !== undefined)
1025
+ params.set(key, String(value));
1026
+ }
1027
+ const qs = params.toString();
1028
+ return this.rawFetch(`/entities/${encodeURIComponent(this.entityId)}/compliance/audit/export.csv${qs ? `?${qs}` : ''}`, { method: 'GET' });
1029
+ }
1030
+ async getComplianceDashboardOverview() {
1031
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/compliance/dashboard/overview`);
1032
+ }
1033
+ async putComplianceDashboardOverview(config) {
1034
+ await this.request(`/entities/${encodeURIComponent(this.entityId)}/compliance/dashboard/overview`, { method: 'PUT', body: JSON.stringify(config) });
1035
+ }
1036
+ async financeAccessSOX(request) {
1037
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/compliance/finance/access-sox`, { method: 'POST', body: JSON.stringify(request) });
1038
+ }
1039
+ async financeVerifySoD(request) {
1040
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/compliance/finance/verify-sod`, { method: 'POST', body: JSON.stringify(request) });
1041
+ }
1042
+ async getInsuranceComplianceDoc(collection) {
1043
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/compliance/insurance/` +
1044
+ encodeURIComponent(collection));
1045
+ }
1046
+ async putInsuranceComplianceDoc(collection, config, opts) {
1047
+ await this.request(`/entities/${encodeURIComponent(this.entityId)}/compliance/insurance/` +
1048
+ encodeURIComponent(collection), {
1049
+ method: 'PUT',
1050
+ body: JSON.stringify(config),
1051
+ ...(opts?.ifGenerationMatch !== undefined
1052
+ ? { headers: { 'If-Match': String(opts.ifGenerationMatch) } }
1053
+ : {}),
1054
+ });
1055
+ }
1056
+ async requestBreakGlassAccess(body) {
1057
+ return this.request(`${this.breakGlassBase()}/grants`, {
1058
+ method: 'POST',
1059
+ body: JSON.stringify(body),
1060
+ });
1061
+ }
1062
+ async getActiveBreakGlassGrants() {
1063
+ return this.request(`${this.breakGlassBase()}/grants/active`);
1064
+ }
1065
+ async getBreakGlassPendingReviews() {
1066
+ return this.request(`${this.breakGlassBase()}/grants/pending-reviews`);
1067
+ }
1068
+ async revokeBreakGlassGrant(grantId, revokedBy) {
1069
+ await this.request(`${this.breakGlassBase()}/grants/${encodeURIComponent(grantId)}/revoke`, {
1070
+ method: 'POST',
1071
+ body: JSON.stringify(revokedBy === undefined ? {} : { revokedBy }),
1072
+ });
1073
+ }
1074
+ async approveBreakGlassPostHoc(grantId, body) {
1075
+ await this.request(`${this.breakGlassBase()}/grants/${encodeURIComponent(grantId)}/approve-post-hoc`, { method: 'POST', body: JSON.stringify(body) });
1076
+ }
1077
+ async recordIntegrityHash(body) {
1078
+ return this.request(`${this.breakGlassBase()}/integrity/hashes`, {
1079
+ method: 'POST',
1080
+ body: JSON.stringify(body),
1081
+ });
1082
+ }
1083
+ async getRecordIntegrityHash(recordType, recordId) {
1084
+ return this.request(`${this.breakGlassBase()}/integrity/${encodeURIComponent(recordType)}/${encodeURIComponent(recordId)}/hash`);
1085
+ }
1086
+ async verifyRecordIntegrity(body) {
1087
+ return this.request(`${this.breakGlassBase()}/integrity/verify-record`, {
1088
+ method: 'POST',
1089
+ body: JSON.stringify(body),
1090
+ });
1091
+ }
1092
+ async verifyRecordIntegrityChain(body) {
1093
+ return this.request(`${this.breakGlassBase()}/integrity/verify-chain`, {
1094
+ method: 'POST',
1095
+ body: JSON.stringify(body),
1096
+ });
1097
+ }
1098
+ breakGlassBase() {
1099
+ return `/entities/${encodeURIComponent(this.entityId)}/compliance/break-glass`;
1100
+ }
1101
+ async getRulesEngineConfig() {
1102
+ return this.getEntityAdminConfig('rules-engine');
1103
+ }
1104
+ async putRulesEngineConfig(config) {
1105
+ await this.putEntityAdminConfig('rules-engine', config);
1106
+ }
1107
+ async triggerRulesEngineConnectionTest(opts) {
1108
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/admin-config/rules-engine/test-connection`, {
1109
+ method: 'POST',
1110
+ body: JSON.stringify({ connectionId: opts.connectionId }),
1111
+ });
1112
+ }
1113
+ async createSSOProvider(body) {
1114
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/admin-config/sso/providers`, { method: 'POST', body: JSON.stringify(body) });
1115
+ }
1116
+ async updateSSOProvider(providerId, patch) {
1117
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/admin-config/sso/providers/${encodeURIComponent(providerId)}`, { method: 'PUT', body: JSON.stringify(patch) });
1118
+ }
1119
+ async deleteSSOProvider(providerId) {
1120
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/admin-config/sso/providers/${encodeURIComponent(providerId)}`, { method: 'DELETE' });
1121
+ }
1122
+ async getLdapConfig() {
1123
+ return this.getEntityAdminConfig('ldap');
1124
+ }
1125
+ async putLdapConfig(config) {
1126
+ await this.putEntityAdminConfig('ldap', config);
1127
+ }
1128
+ async triggerLdapSync(opts) {
1129
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/admin-config/ldap/sync`, {
1130
+ method: 'POST',
1131
+ body: JSON.stringify({ syncType: opts?.syncType ?? 'manual' }),
1132
+ });
1133
+ }
1134
+ async getLogStreamingConfig() {
1135
+ return this.getEntityAdminConfig('log-streaming');
1136
+ }
1137
+ async putLogStreamingConfig(config) {
1138
+ await this.putEntityAdminConfig('log-streaming', config);
1139
+ }
1140
+ async testLogStreamingDestination(destinationId) {
1141
+ return this.request(`/entities/${encodeURIComponent(this.entityId)}/admin-config/log-streaming/test`, {
1142
+ method: 'POST',
1143
+ body: JSON.stringify({ destinationId }),
1144
+ });
1145
+ }
1146
+ async getLicensePlatformDoc(subPath) {
1147
+ return this.request(`/platform-config/license/${subPath}`);
1148
+ }
1149
+ async putLicensePlatformDoc(subPath, config) {
1150
+ await this.request(`/platform-config/license/${subPath}`, {
1151
+ method: 'PUT',
1152
+ body: JSON.stringify(config),
1153
+ });
1154
+ }
1155
+ async listLicenseTierHistory(tier, limit) {
1156
+ return this.request(`/platform-config/license/tiers/${encodeURIComponent(tier)}/history?limit=${limit}`);
1157
+ }
1158
+ async appendLicenseTierHistory(tier, entry) {
1159
+ await this.request(`/platform-config/license/tiers/${encodeURIComponent(tier)}/history`, {
1160
+ method: 'POST',
1161
+ body: JSON.stringify(entry),
1162
+ });
1163
+ }
1164
+ async getAdminSecret(key) {
1165
+ return this.request(`/platform-config/admin-secrets/${encodeURIComponent(key)}`);
1166
+ }
1167
+ async putAdminSecret(key, config) {
1168
+ await this.request(`/platform-config/admin-secrets/${encodeURIComponent(key)}`, {
1169
+ method: 'PUT',
1170
+ body: JSON.stringify(config),
1171
+ });
1172
+ }
1173
+ async request(endpoint, init = {}) {
1174
+ const headers = new Headers({
1175
+ 'Content-Type': 'application/json',
1176
+ ...init.headers,
1177
+ });
1178
+ const response = await this.rawFetch(endpoint, { ...init, headers });
1179
+ const text = await response.text();
1180
+ if (!text) {
1181
+ return undefined;
1182
+ }
1183
+ return JSON.parse(text);
1184
+ }
1185
+ }
1186
+ exports.BrainAPIClient = BrainAPIClient;
1187
+ function defaultFetch() {
1188
+ if (typeof globalThis.fetch === 'function') {
1189
+ return globalThis.fetch.bind(globalThis);
1190
+ }
1191
+ throw new Error('BrainAPIClient: no global `fetch` available. Pass `config.fetchImpl` ' +
1192
+ "(e.g. `import { fetch } from 'undici'`) — required on Node < 18.");
1193
+ }
1194
+ function createBrainClient(config) {
1195
+ return new BrainAPIClient(config);
1196
+ }
1197
+ //# sourceMappingURL=client.js.map