@aumos/cowork-governance 0.1.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.
- package/dist/client.d.ts +122 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +149 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +278 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/package.json +34 -0
- package/src/client.ts +369 -0
- package/src/index.ts +37 -0
- package/src/types.ts +349 -0
- package/tsconfig.json +25 -0
package/src/client.ts
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for the AumOS cowork-governance policy enforcement API.
|
|
3
|
+
*
|
|
4
|
+
* Uses the Fetch API (available natively in Node 18+, browsers, and Deno).
|
|
5
|
+
* No external dependencies required.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createCoworkGovernanceClient } from "@aumos/cowork-governance";
|
|
10
|
+
*
|
|
11
|
+
* const client = createCoworkGovernanceClient({ baseUrl: "http://localhost:8094" });
|
|
12
|
+
*
|
|
13
|
+
* const result = await client.checkPolicy({
|
|
14
|
+
* action_context: { action: "file_read", path: "/etc/passwd" },
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* if (result.ok && !result.data.allowed) {
|
|
18
|
+
* console.log("Blocked by:", result.data.blocking_policy);
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import type {
|
|
24
|
+
ApiError,
|
|
25
|
+
ApiResult,
|
|
26
|
+
CompliancePolicy,
|
|
27
|
+
GovernanceConstitution,
|
|
28
|
+
GovernanceDashboard,
|
|
29
|
+
PendingApprovals,
|
|
30
|
+
PolicyEvaluationResult,
|
|
31
|
+
ValidateWorkflowRequest,
|
|
32
|
+
} from "./types.js";
|
|
33
|
+
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Client configuration
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
/** Configuration options for the CoworkGovernanceClient. */
|
|
39
|
+
export interface CoworkGovernanceClientConfig {
|
|
40
|
+
/** Base URL of the cowork-governance server (e.g. "http://localhost:8094"). */
|
|
41
|
+
readonly baseUrl: string;
|
|
42
|
+
/** Optional request timeout in milliseconds (default: 30000). */
|
|
43
|
+
readonly timeoutMs?: number;
|
|
44
|
+
/** Optional extra HTTP headers sent with every request. */
|
|
45
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
// Internal helpers
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
|
|
52
|
+
async function fetchJson<T>(
|
|
53
|
+
url: string,
|
|
54
|
+
init: RequestInit,
|
|
55
|
+
timeoutMs: number,
|
|
56
|
+
): Promise<ApiResult<T>> {
|
|
57
|
+
const controller = new AbortController();
|
|
58
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const response = await fetch(url, { ...init, signal: controller.signal });
|
|
62
|
+
clearTimeout(timeoutId);
|
|
63
|
+
|
|
64
|
+
const body = await response.json() as unknown;
|
|
65
|
+
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
const errorBody = body as Partial<ApiError>;
|
|
68
|
+
return {
|
|
69
|
+
ok: false,
|
|
70
|
+
error: {
|
|
71
|
+
error: errorBody.error ?? "Unknown error",
|
|
72
|
+
detail: errorBody.detail ?? "",
|
|
73
|
+
},
|
|
74
|
+
status: response.status,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return { ok: true, data: body as T };
|
|
79
|
+
} catch (err: unknown) {
|
|
80
|
+
clearTimeout(timeoutId);
|
|
81
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
82
|
+
return {
|
|
83
|
+
ok: false,
|
|
84
|
+
error: { error: "Network error", detail: message },
|
|
85
|
+
status: 0,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function buildHeaders(
|
|
91
|
+
extraHeaders: Readonly<Record<string, string>> | undefined,
|
|
92
|
+
): Record<string, string> {
|
|
93
|
+
return {
|
|
94
|
+
"Content-Type": "application/json",
|
|
95
|
+
Accept: "application/json",
|
|
96
|
+
...extraHeaders,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
// Client interface
|
|
102
|
+
// ---------------------------------------------------------------------------
|
|
103
|
+
|
|
104
|
+
/** Typed HTTP client for the cowork-governance server. */
|
|
105
|
+
export interface CoworkGovernanceClient {
|
|
106
|
+
/**
|
|
107
|
+
* Evaluate an action context against all loaded governance policies.
|
|
108
|
+
*
|
|
109
|
+
* The first BLOCK policy that matches terminates evaluation and sets
|
|
110
|
+
* allowed=false. APPROVE policies set requires_approval=true without blocking.
|
|
111
|
+
*
|
|
112
|
+
* @param request - The action context to evaluate and optional agent scope.
|
|
113
|
+
* @returns A PolicyEvaluationResult with allowed/blocked decision and per-policy results.
|
|
114
|
+
*/
|
|
115
|
+
checkPolicy(
|
|
116
|
+
request: ValidateWorkflowRequest,
|
|
117
|
+
): Promise<ApiResult<PolicyEvaluationResult>>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Retrieve all policy violations recorded within the given time window.
|
|
121
|
+
*
|
|
122
|
+
* @param options - Optional filter parameters for agent, time range, and severity.
|
|
123
|
+
* @returns Array of PolicyViolation records for matched policies.
|
|
124
|
+
*/
|
|
125
|
+
getViolations(options?: {
|
|
126
|
+
readonly agentId?: string;
|
|
127
|
+
readonly since?: string;
|
|
128
|
+
readonly limit?: number;
|
|
129
|
+
}): Promise<ApiResult<readonly PolicyEvaluationResult[]>>;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Retrieve the governance dashboard health summary and aggregate statistics.
|
|
133
|
+
*
|
|
134
|
+
* @returns A GovernanceDashboard with health status, counts, and cost summary.
|
|
135
|
+
*/
|
|
136
|
+
getDashboard(): Promise<ApiResult<GovernanceDashboard>>;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Validate an agent workflow action against all governance policies.
|
|
140
|
+
*
|
|
141
|
+
* Equivalent to checkPolicy but returns a richer validation object
|
|
142
|
+
* suitable for pre-execution workflow gates.
|
|
143
|
+
*
|
|
144
|
+
* @param request - The workflow action to validate.
|
|
145
|
+
* @returns A PolicyEvaluationResult indicating whether the workflow may proceed.
|
|
146
|
+
*/
|
|
147
|
+
validateWorkflow(
|
|
148
|
+
request: ValidateWorkflowRequest,
|
|
149
|
+
): Promise<ApiResult<PolicyEvaluationResult>>;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Retrieve the active governance constitution for the specified team.
|
|
153
|
+
*
|
|
154
|
+
* @param teamName - The team whose constitution to retrieve (default: "default").
|
|
155
|
+
* @returns The GovernanceConstitution defining roles, constraints, and escalation rules.
|
|
156
|
+
*/
|
|
157
|
+
getConstitution(teamName?: string): Promise<ApiResult<GovernanceConstitution>>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Upload or replace the governance constitution for a team.
|
|
161
|
+
*
|
|
162
|
+
* @param constitution - The full constitution document to activate.
|
|
163
|
+
* @returns The stored GovernanceConstitution as confirmed by the server.
|
|
164
|
+
*/
|
|
165
|
+
setConstitution(
|
|
166
|
+
constitution: GovernanceConstitution,
|
|
167
|
+
): Promise<ApiResult<GovernanceConstitution>>;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Retrieve all currently loaded governance policies.
|
|
171
|
+
*
|
|
172
|
+
* @returns Array of CompliancePolicy records in declaration order.
|
|
173
|
+
*/
|
|
174
|
+
getPolicies(): Promise<ApiResult<readonly CompliancePolicy[]>>;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Retrieve all pending approval requests awaiting human review.
|
|
178
|
+
*
|
|
179
|
+
* @returns A PendingApprovals object with pending requests and total count.
|
|
180
|
+
*/
|
|
181
|
+
getPendingApprovals(): Promise<ApiResult<PendingApprovals>>;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Approve a pending governance request.
|
|
185
|
+
*
|
|
186
|
+
* @param requestId - The approval request identifier to approve.
|
|
187
|
+
* @param approvedBy - Identifier of the human or system approving the request.
|
|
188
|
+
* @returns An empty object on successful approval.
|
|
189
|
+
*/
|
|
190
|
+
approveRequest(
|
|
191
|
+
requestId: string,
|
|
192
|
+
approvedBy: string,
|
|
193
|
+
): Promise<ApiResult<Readonly<Record<string, never>>>>;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Reject a pending governance request.
|
|
197
|
+
*
|
|
198
|
+
* @param requestId - The approval request identifier to reject.
|
|
199
|
+
* @param rejectedBy - Identifier of the human or system rejecting the request.
|
|
200
|
+
* @param reason - Optional human-readable reason for the rejection.
|
|
201
|
+
* @returns An empty object on successful rejection.
|
|
202
|
+
*/
|
|
203
|
+
rejectRequest(
|
|
204
|
+
requestId: string,
|
|
205
|
+
rejectedBy: string,
|
|
206
|
+
reason?: string,
|
|
207
|
+
): Promise<ApiResult<Readonly<Record<string, never>>>>;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// ---------------------------------------------------------------------------
|
|
211
|
+
// Client factory
|
|
212
|
+
// ---------------------------------------------------------------------------
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Create a typed HTTP client for the cowork-governance server.
|
|
216
|
+
*
|
|
217
|
+
* @param config - Client configuration including base URL.
|
|
218
|
+
* @returns A CoworkGovernanceClient instance.
|
|
219
|
+
*/
|
|
220
|
+
export function createCoworkGovernanceClient(
|
|
221
|
+
config: CoworkGovernanceClientConfig,
|
|
222
|
+
): CoworkGovernanceClient {
|
|
223
|
+
const { baseUrl, timeoutMs = 30_000, headers: extraHeaders } = config;
|
|
224
|
+
const baseHeaders = buildHeaders(extraHeaders);
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
async checkPolicy(
|
|
228
|
+
request: ValidateWorkflowRequest,
|
|
229
|
+
): Promise<ApiResult<PolicyEvaluationResult>> {
|
|
230
|
+
return fetchJson<PolicyEvaluationResult>(
|
|
231
|
+
`${baseUrl}/policies/check`,
|
|
232
|
+
{
|
|
233
|
+
method: "POST",
|
|
234
|
+
headers: baseHeaders,
|
|
235
|
+
body: JSON.stringify(request),
|
|
236
|
+
},
|
|
237
|
+
timeoutMs,
|
|
238
|
+
);
|
|
239
|
+
},
|
|
240
|
+
|
|
241
|
+
async getViolations(options?: {
|
|
242
|
+
readonly agentId?: string;
|
|
243
|
+
readonly since?: string;
|
|
244
|
+
readonly limit?: number;
|
|
245
|
+
}): Promise<ApiResult<readonly PolicyEvaluationResult[]>> {
|
|
246
|
+
const params = new URLSearchParams();
|
|
247
|
+
if (options?.agentId !== undefined) {
|
|
248
|
+
params.set("agent_id", options.agentId);
|
|
249
|
+
}
|
|
250
|
+
if (options?.since !== undefined) {
|
|
251
|
+
params.set("since", options.since);
|
|
252
|
+
}
|
|
253
|
+
if (options?.limit !== undefined) {
|
|
254
|
+
params.set("limit", String(options.limit));
|
|
255
|
+
}
|
|
256
|
+
const queryString = params.toString();
|
|
257
|
+
const url = queryString
|
|
258
|
+
? `${baseUrl}/violations?${queryString}`
|
|
259
|
+
: `${baseUrl}/violations`;
|
|
260
|
+
return fetchJson<readonly PolicyEvaluationResult[]>(
|
|
261
|
+
url,
|
|
262
|
+
{ method: "GET", headers: baseHeaders },
|
|
263
|
+
timeoutMs,
|
|
264
|
+
);
|
|
265
|
+
},
|
|
266
|
+
|
|
267
|
+
async getDashboard(): Promise<ApiResult<GovernanceDashboard>> {
|
|
268
|
+
return fetchJson<GovernanceDashboard>(
|
|
269
|
+
`${baseUrl}/dashboard`,
|
|
270
|
+
{ method: "GET", headers: baseHeaders },
|
|
271
|
+
timeoutMs,
|
|
272
|
+
);
|
|
273
|
+
},
|
|
274
|
+
|
|
275
|
+
async validateWorkflow(
|
|
276
|
+
request: ValidateWorkflowRequest,
|
|
277
|
+
): Promise<ApiResult<PolicyEvaluationResult>> {
|
|
278
|
+
return fetchJson<PolicyEvaluationResult>(
|
|
279
|
+
`${baseUrl}/workflow/validate`,
|
|
280
|
+
{
|
|
281
|
+
method: "POST",
|
|
282
|
+
headers: baseHeaders,
|
|
283
|
+
body: JSON.stringify(request),
|
|
284
|
+
},
|
|
285
|
+
timeoutMs,
|
|
286
|
+
);
|
|
287
|
+
},
|
|
288
|
+
|
|
289
|
+
async getConstitution(
|
|
290
|
+
teamName?: string,
|
|
291
|
+
): Promise<ApiResult<GovernanceConstitution>> {
|
|
292
|
+
const params = new URLSearchParams();
|
|
293
|
+
if (teamName !== undefined) {
|
|
294
|
+
params.set("team", teamName);
|
|
295
|
+
}
|
|
296
|
+
const queryString = params.toString();
|
|
297
|
+
const url = queryString
|
|
298
|
+
? `${baseUrl}/constitution?${queryString}`
|
|
299
|
+
: `${baseUrl}/constitution`;
|
|
300
|
+
return fetchJson<GovernanceConstitution>(
|
|
301
|
+
url,
|
|
302
|
+
{ method: "GET", headers: baseHeaders },
|
|
303
|
+
timeoutMs,
|
|
304
|
+
);
|
|
305
|
+
},
|
|
306
|
+
|
|
307
|
+
async setConstitution(
|
|
308
|
+
constitution: GovernanceConstitution,
|
|
309
|
+
): Promise<ApiResult<GovernanceConstitution>> {
|
|
310
|
+
return fetchJson<GovernanceConstitution>(
|
|
311
|
+
`${baseUrl}/constitution`,
|
|
312
|
+
{
|
|
313
|
+
method: "PUT",
|
|
314
|
+
headers: baseHeaders,
|
|
315
|
+
body: JSON.stringify(constitution),
|
|
316
|
+
},
|
|
317
|
+
timeoutMs,
|
|
318
|
+
);
|
|
319
|
+
},
|
|
320
|
+
|
|
321
|
+
async getPolicies(): Promise<ApiResult<readonly CompliancePolicy[]>> {
|
|
322
|
+
return fetchJson<readonly CompliancePolicy[]>(
|
|
323
|
+
`${baseUrl}/policies`,
|
|
324
|
+
{ method: "GET", headers: baseHeaders },
|
|
325
|
+
timeoutMs,
|
|
326
|
+
);
|
|
327
|
+
},
|
|
328
|
+
|
|
329
|
+
async getPendingApprovals(): Promise<ApiResult<PendingApprovals>> {
|
|
330
|
+
return fetchJson<PendingApprovals>(
|
|
331
|
+
`${baseUrl}/approvals/pending`,
|
|
332
|
+
{ method: "GET", headers: baseHeaders },
|
|
333
|
+
timeoutMs,
|
|
334
|
+
);
|
|
335
|
+
},
|
|
336
|
+
|
|
337
|
+
async approveRequest(
|
|
338
|
+
requestId: string,
|
|
339
|
+
approvedBy: string,
|
|
340
|
+
): Promise<ApiResult<Readonly<Record<string, never>>>> {
|
|
341
|
+
return fetchJson<Readonly<Record<string, never>>>(
|
|
342
|
+
`${baseUrl}/approvals/${encodeURIComponent(requestId)}/approve`,
|
|
343
|
+
{
|
|
344
|
+
method: "POST",
|
|
345
|
+
headers: baseHeaders,
|
|
346
|
+
body: JSON.stringify({ approved_by: approvedBy }),
|
|
347
|
+
},
|
|
348
|
+
timeoutMs,
|
|
349
|
+
);
|
|
350
|
+
},
|
|
351
|
+
|
|
352
|
+
async rejectRequest(
|
|
353
|
+
requestId: string,
|
|
354
|
+
rejectedBy: string,
|
|
355
|
+
reason?: string,
|
|
356
|
+
): Promise<ApiResult<Readonly<Record<string, never>>>> {
|
|
357
|
+
return fetchJson<Readonly<Record<string, never>>>(
|
|
358
|
+
`${baseUrl}/approvals/${encodeURIComponent(requestId)}/reject`,
|
|
359
|
+
{
|
|
360
|
+
method: "POST",
|
|
361
|
+
headers: baseHeaders,
|
|
362
|
+
body: JSON.stringify({ rejected_by: rejectedBy, reason: reason ?? "" }),
|
|
363
|
+
},
|
|
364
|
+
timeoutMs,
|
|
365
|
+
);
|
|
366
|
+
},
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @aumos/cowork-governance
|
|
3
|
+
*
|
|
4
|
+
* TypeScript client for the AumOS cowork-governance library.
|
|
5
|
+
* Provides HTTP client and governance type definitions for multi-agent
|
|
6
|
+
* policy enforcement, workflow validation, and constitutional governance.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// Client and configuration
|
|
10
|
+
export type { CoworkGovernanceClient, CoworkGovernanceClientConfig } from "./client.js";
|
|
11
|
+
export { createCoworkGovernanceClient } from "./client.js";
|
|
12
|
+
|
|
13
|
+
// Core types
|
|
14
|
+
export type {
|
|
15
|
+
PolicyAction,
|
|
16
|
+
Permission,
|
|
17
|
+
ConflictStrategy,
|
|
18
|
+
ConstraintType,
|
|
19
|
+
PolicyCondition,
|
|
20
|
+
CompliancePolicy,
|
|
21
|
+
PolicyViolation,
|
|
22
|
+
PolicyEvaluationResult,
|
|
23
|
+
RoleDefinition,
|
|
24
|
+
GovernanceConstraint,
|
|
25
|
+
EscalationRule,
|
|
26
|
+
ConstitutionRule,
|
|
27
|
+
GovernanceConstitution,
|
|
28
|
+
WorkflowGuardianConfig,
|
|
29
|
+
AuditSummary,
|
|
30
|
+
CostSummary,
|
|
31
|
+
GovernanceDashboard,
|
|
32
|
+
ApprovalRequest,
|
|
33
|
+
PendingApprovals,
|
|
34
|
+
ValidateWorkflowRequest,
|
|
35
|
+
ApiError,
|
|
36
|
+
ApiResult,
|
|
37
|
+
} from "./types.js";
|