@connexum/govern 0.0.0-stage → 0.1.0-beta.1
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/README.md +33 -2
- package/dist/index.d.ts +112 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +146 -0
- package/dist/index.js.map +1 -0
- package/package.json +14 -4
package/README.md
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @connexum/govern
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
One entry for all three My-CC layers around any agent (end-state D1, task 655).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { govern, GovernBlocked, GovernPaused } from '@connexum/govern'
|
|
7
|
+
import { LocalGate } from '@connexum/typescript-sdk'
|
|
8
|
+
|
|
9
|
+
const agent = govern({
|
|
10
|
+
agentId, passportId, governanceServerUrl: 'https://api.my-cc.io', token, // the agent's own service token
|
|
11
|
+
localGate, // optional: enforcing mode decides locally
|
|
12
|
+
sources: [{ sourceId: 'orders-db', tools: ['orders.'] }],
|
|
13
|
+
verification: { engine, tenantId, consumer, options: { leakageDenylist } },
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
await agent.tool('orders.update', input, (i) => updateOrder(i), { writes: true })
|
|
17
|
+
const answer = agent.release(modelResponse) // secrets and PHI blocked (or redacted) before use
|
|
18
|
+
const result = await agent.verify(claims, { snapshot }) // grounded, contradicted or unsupported
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Every tool call goes readiness, then runtime, then the tool body:
|
|
22
|
+
|
|
23
|
+
- **Readiness**: the source the tool reads (by tool-name prefix) must give this agent's passport access, from the
|
|
24
|
+
organization's sealed scans on My-CC. `none` blocks; `read_only` blocks a writing tool; an unscanned source, or an
|
|
25
|
+
unreachable My-CC with no earlier answer, blocks. Only the source id and passport id are sent.
|
|
26
|
+
- **Runtime**: a `LocalGate` in enforcing mode decides locally (approval-required actions park until a person decides,
|
|
27
|
+
task 465); otherwise the governance server's check-action decides.
|
|
28
|
+
- A no throws `GovernBlocked { layer, tool, reason }` or `GovernPaused { parkId, approvalId }`; the body never runs.
|
|
29
|
+
|
|
30
|
+
`release()` applies the model response check (task 466): `'block'` by default when the local gate is enforcing.
|
|
31
|
+
`verify()` hands the claims to your `VerificationEngine` (`@connexum/verification`).
|
|
32
|
+
|
|
33
|
+
Not yet: stack adapters (LangGraph, CrewAI, OpenAI Agents SDK, Claude Agent SDK, n8n) and the Python twin. Design:
|
|
34
|
+
`docs/specs/2026-10-21-govern-655-design.md`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @connexum/govern (task 655, end-state D1): one entry that puts any agent under all three My-CC layers.
|
|
3
|
+
*
|
|
4
|
+
* readiness before a tool reads a source: the source's access for this agent's passport (the organization's scans on
|
|
5
|
+
* My-CC); none blocks, read_only blocks a writing tool, an unscanned or unknown source blocks.
|
|
6
|
+
* runtime during: the customer's LocalGate in enforcing mode decides locally (park, release, fail closed);
|
|
7
|
+
* otherwise the governance server's check-action decides (advisory).
|
|
8
|
+
* correctness after: the agent's claims are checked by the consumer's VerificationEngine against a source snapshot.
|
|
9
|
+
*
|
|
10
|
+
* A layer that says no throws GovernBlocked (or GovernPaused); nothing runs after a no. Design:
|
|
11
|
+
* docs/specs/2026-10-21-govern-655-design.md.
|
|
12
|
+
*/
|
|
13
|
+
import { type ResponseCheckMode } from '@connexum/typescript-sdk';
|
|
14
|
+
export type GovernLayer = 'readiness' | 'runtime' | 'response';
|
|
15
|
+
export declare class GovernBlocked extends Error {
|
|
16
|
+
readonly layer: GovernLayer;
|
|
17
|
+
readonly tool: string;
|
|
18
|
+
readonly reason: string;
|
|
19
|
+
constructor(layer: GovernLayer, tool: string, reason: string);
|
|
20
|
+
}
|
|
21
|
+
export declare class GovernPaused extends Error {
|
|
22
|
+
readonly tool: string;
|
|
23
|
+
readonly reason: string;
|
|
24
|
+
readonly parkId?: string | undefined;
|
|
25
|
+
readonly approvalId?: string | undefined;
|
|
26
|
+
constructor(tool: string, reason: string, parkId?: string | undefined, approvalId?: string | undefined);
|
|
27
|
+
}
|
|
28
|
+
/** The LocalGate surface govern uses (LocalGate in @connexum/typescript-sdk 0.1.0-beta.5 or later). */
|
|
29
|
+
export interface GovernLocalGate {
|
|
30
|
+
effective(): {
|
|
31
|
+
mode: 'advisory' | 'enforcing';
|
|
32
|
+
};
|
|
33
|
+
decide(action: {
|
|
34
|
+
toolName: string;
|
|
35
|
+
input?: Record<string, unknown>;
|
|
36
|
+
runId?: string;
|
|
37
|
+
}): {
|
|
38
|
+
decision: 'ALLOW' | 'DENY' | 'QUEUE' | 'PAUSE';
|
|
39
|
+
reason: string;
|
|
40
|
+
detail: string;
|
|
41
|
+
parkId?: string;
|
|
42
|
+
approvalId?: string;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/** The VerificationEngine surface govern uses (@connexum/verification). */
|
|
46
|
+
export interface GovernVerifier {
|
|
47
|
+
verify(req: {
|
|
48
|
+
tenantId: string;
|
|
49
|
+
consumer: unknown;
|
|
50
|
+
claims: unknown[];
|
|
51
|
+
snapshot?: unknown;
|
|
52
|
+
source?: unknown;
|
|
53
|
+
options?: Record<string, unknown>;
|
|
54
|
+
}): Promise<unknown>;
|
|
55
|
+
}
|
|
56
|
+
export interface GovernSource {
|
|
57
|
+
sourceId: string;
|
|
58
|
+
/** Tool name prefixes that read this source (e.g. 'orders.'). */
|
|
59
|
+
tools: string[];
|
|
60
|
+
}
|
|
61
|
+
export interface GovernOptions {
|
|
62
|
+
agentId: string;
|
|
63
|
+
agentName?: string;
|
|
64
|
+
/** The agent's passport id: readiness scans name the passports a source is exposed to. */
|
|
65
|
+
passportId: string;
|
|
66
|
+
governanceServerUrl: string;
|
|
67
|
+
/** The agent's own service token (or an operator token of its organization). */
|
|
68
|
+
token: string;
|
|
69
|
+
localGate?: GovernLocalGate;
|
|
70
|
+
sources?: GovernSource[];
|
|
71
|
+
/** options: engine options sent on every verify (for example the tenant's leakageDenylist of client names). */
|
|
72
|
+
verification?: {
|
|
73
|
+
engine: GovernVerifier;
|
|
74
|
+
tenantId: string;
|
|
75
|
+
consumer: unknown;
|
|
76
|
+
options?: Record<string, unknown>;
|
|
77
|
+
};
|
|
78
|
+
/** Model response check (466). Default: 'block' when the local gate is in enforcing mode, otherwise 'off'. */
|
|
79
|
+
responseCheck?: ResponseCheckMode;
|
|
80
|
+
/** How long a readiness answer is reused. Default 60 s. */
|
|
81
|
+
accessTtlMs?: number;
|
|
82
|
+
/** Server check-action behaviour when the server is unreachable (advisory runtime path). Default 'fail-closed'. */
|
|
83
|
+
onServerUnreachable?: 'fail-open' | 'fail-closed';
|
|
84
|
+
timeoutMs?: number;
|
|
85
|
+
fetch?: typeof fetch;
|
|
86
|
+
now?: () => number;
|
|
87
|
+
}
|
|
88
|
+
export interface GovernBlockRecord {
|
|
89
|
+
at: string;
|
|
90
|
+
layer: GovernLayer;
|
|
91
|
+
tool: string;
|
|
92
|
+
reason: string;
|
|
93
|
+
}
|
|
94
|
+
export interface Governed {
|
|
95
|
+
/** Readiness, then runtime, then the tool body. Throws GovernBlocked or GovernPaused instead of calling it. */
|
|
96
|
+
tool<T>(name: string, input: Record<string, unknown>, fn: (input: Record<string, unknown>) => Promise<T> | T, opts?: {
|
|
97
|
+
writes?: boolean;
|
|
98
|
+
runId?: string;
|
|
99
|
+
}): Promise<T>;
|
|
100
|
+
/** Check a model response before it is used (466). Throws GovernBlocked in block mode; returns a redacted copy in redact mode. */
|
|
101
|
+
release<T>(response: T): T;
|
|
102
|
+
/** Correctness after: verify the agent's claims with the configured engine. */
|
|
103
|
+
verify(claims: unknown[], from: {
|
|
104
|
+
snapshot?: unknown;
|
|
105
|
+
source?: unknown;
|
|
106
|
+
options?: Record<string, unknown>;
|
|
107
|
+
}): Promise<unknown>;
|
|
108
|
+
/** Recent blocks, newest first (for the caller's own display). */
|
|
109
|
+
blocks(): GovernBlockRecord[];
|
|
110
|
+
}
|
|
111
|
+
export declare function govern(opts: GovernOptions): Governed;
|
|
112
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAA4C,KAAK,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE5G,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,SAAS,GAAG,UAAU,CAAC;AAE/D,qBAAa,aAAc,SAAQ,KAAK;IAC1B,QAAQ,CAAC,KAAK,EAAE,WAAW;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM;gBAAlE,KAAK,EAAE,WAAW,EAAW,IAAI,EAAE,MAAM,EAAW,MAAM,EAAE,MAAM;CAIxF;AAED,qBAAa,YAAa,SAAQ,KAAK;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;IAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM;gBAA7F,IAAI,EAAE,MAAM,EAAW,MAAM,EAAE,MAAM,EAAW,MAAM,CAAC,EAAE,MAAM,YAAA,EAAW,UAAU,CAAC,EAAE,MAAM,YAAA;CAInH;AAED,uGAAuG;AACvG,MAAM,WAAW,eAAe;IAC9B,SAAS,IAAI;QAAE,IAAI,EAAE,UAAU,GAAG,WAAW,CAAA;KAAE,CAAC;IAChD,MAAM,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG;QAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,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js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GovernPaused = exports.GovernBlocked = void 0;
|
|
4
|
+
exports.govern = govern;
|
|
5
|
+
/**
|
|
6
|
+
* @connexum/govern (task 655, end-state D1): one entry that puts any agent under all three My-CC layers.
|
|
7
|
+
*
|
|
8
|
+
* readiness before a tool reads a source: the source's access for this agent's passport (the organization's scans on
|
|
9
|
+
* My-CC); none blocks, read_only blocks a writing tool, an unscanned or unknown source blocks.
|
|
10
|
+
* runtime during: the customer's LocalGate in enforcing mode decides locally (park, release, fail closed);
|
|
11
|
+
* otherwise the governance server's check-action decides (advisory).
|
|
12
|
+
* correctness after: the agent's claims are checked by the consumer's VerificationEngine against a source snapshot.
|
|
13
|
+
*
|
|
14
|
+
* A layer that says no throws GovernBlocked (or GovernPaused); nothing runs after a no. Design:
|
|
15
|
+
* docs/specs/2026-10-21-govern-655-design.md.
|
|
16
|
+
*/
|
|
17
|
+
const typescript_sdk_1 = require("@connexum/typescript-sdk");
|
|
18
|
+
class GovernBlocked extends Error {
|
|
19
|
+
layer;
|
|
20
|
+
tool;
|
|
21
|
+
reason;
|
|
22
|
+
constructor(layer, tool, reason) {
|
|
23
|
+
super(`[${layer}] ${tool}: ${reason}`);
|
|
24
|
+
this.layer = layer;
|
|
25
|
+
this.tool = tool;
|
|
26
|
+
this.reason = reason;
|
|
27
|
+
this.name = 'GovernBlocked';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.GovernBlocked = GovernBlocked;
|
|
31
|
+
class GovernPaused extends Error {
|
|
32
|
+
tool;
|
|
33
|
+
reason;
|
|
34
|
+
parkId;
|
|
35
|
+
approvalId;
|
|
36
|
+
constructor(tool, reason, parkId, approvalId) {
|
|
37
|
+
super(`[runtime] ${tool} paused: ${reason}`);
|
|
38
|
+
this.tool = tool;
|
|
39
|
+
this.reason = reason;
|
|
40
|
+
this.parkId = parkId;
|
|
41
|
+
this.approvalId = approvalId;
|
|
42
|
+
this.name = 'GovernPaused';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.GovernPaused = GovernPaused;
|
|
46
|
+
function govern(opts) {
|
|
47
|
+
const fetchFn = opts.fetch ?? fetch;
|
|
48
|
+
const now = opts.now ?? Date.now;
|
|
49
|
+
const ttl = opts.accessTtlMs ?? 60_000;
|
|
50
|
+
const base = opts.governanceServerUrl.replace(/\/$/, '');
|
|
51
|
+
const access = new Map();
|
|
52
|
+
const blocks = [];
|
|
53
|
+
const server = new typescript_sdk_1.GovernanceHttpClient({
|
|
54
|
+
governanceServerUrl: base, licenseKey: opts.token,
|
|
55
|
+
onServerUnreachable: opts.onServerUnreachable ?? 'fail-closed',
|
|
56
|
+
...(opts.timeoutMs !== undefined ? { timeoutMs: opts.timeoutMs } : {}),
|
|
57
|
+
defaultAgent: { name: opts.agentName ?? opts.agentId, role: 'governed-agent' },
|
|
58
|
+
});
|
|
59
|
+
const block = (layer, tool, reason) => {
|
|
60
|
+
blocks.push({ at: new Date(now()).toISOString(), layer, tool, reason });
|
|
61
|
+
if (blocks.length > 500)
|
|
62
|
+
blocks.shift();
|
|
63
|
+
throw new GovernBlocked(layer, tool, reason);
|
|
64
|
+
};
|
|
65
|
+
async function accessFor(sourceId) {
|
|
66
|
+
const hit = access.get(sourceId);
|
|
67
|
+
if (hit && now() - hit.at < ttl)
|
|
68
|
+
return hit;
|
|
69
|
+
try {
|
|
70
|
+
const r = await fetchFn(`${base}/api/v1/readiness/access?sourceId=${encodeURIComponent(sourceId)}&passportId=${encodeURIComponent(opts.passportId)}`, {
|
|
71
|
+
headers: { authorization: `Bearer ${opts.token}` }, signal: AbortSignal.timeout(opts.timeoutMs ?? 5000),
|
|
72
|
+
});
|
|
73
|
+
const b = (await r.json().catch(() => ({})));
|
|
74
|
+
if (r.ok && (b.access === 'full' || b.access === 'read_only' || b.access === 'none')) {
|
|
75
|
+
const answer = { access: b.access, reason: b.reason ?? 'enforcement', at: now() };
|
|
76
|
+
access.set(sourceId, answer);
|
|
77
|
+
return answer;
|
|
78
|
+
}
|
|
79
|
+
return hit ?? { access: 'none', reason: `readiness answer unavailable (http ${r.status})` };
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
// Fail closed: an unreachable My-CC with no earlier answer gives no access; an earlier answer is reused.
|
|
83
|
+
return hit ?? { access: 'none', reason: `readiness answer unavailable: ${e.message.slice(0, 80)}` };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const responseMode = () => {
|
|
87
|
+
if (opts.responseCheck)
|
|
88
|
+
return opts.responseCheck;
|
|
89
|
+
try {
|
|
90
|
+
return opts.localGate?.effective().mode === 'enforcing' ? 'block' : 'off';
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return 'block';
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
return {
|
|
97
|
+
async tool(name, input, fn, o = {}) {
|
|
98
|
+
// 1. Readiness: the source this tool reads, if any.
|
|
99
|
+
const src = (opts.sources ?? []).find((s) => s.tools.some((p) => name.startsWith(p)));
|
|
100
|
+
if (src) {
|
|
101
|
+
const a = await accessFor(src.sourceId);
|
|
102
|
+
if (a.access === 'none')
|
|
103
|
+
block('readiness', name, `source ${src.sourceId} gives this agent no access (${a.reason})`);
|
|
104
|
+
if (a.access === 'read_only' && o.writes)
|
|
105
|
+
block('readiness', name, `source ${src.sourceId} is read-only for this agent (${a.reason}); ${name} writes`);
|
|
106
|
+
}
|
|
107
|
+
// 2. Runtime: the local gate in enforcing mode, otherwise the governance server.
|
|
108
|
+
const local = opts.localGate;
|
|
109
|
+
if (local && local.effective().mode === 'enforcing') {
|
|
110
|
+
const d = local.decide({ toolName: name, input, ...(o.runId ? { runId: o.runId } : {}) });
|
|
111
|
+
if (d.decision === 'PAUSE' || d.decision === 'QUEUE') {
|
|
112
|
+
blocks.push({ at: new Date(now()).toISOString(), layer: 'runtime', tool: name, reason: `${d.reason}: ${d.detail}` });
|
|
113
|
+
throw new GovernPaused(name, `${d.reason}: ${d.detail}`, d.parkId, d.approvalId);
|
|
114
|
+
}
|
|
115
|
+
if (d.decision === 'DENY')
|
|
116
|
+
block('runtime', name, `${d.reason}: ${d.detail}`);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
const r = await server.check({ toolName: name, input, metadata: { agentId: opts.agentId, passportId: opts.passportId, source: '@connexum/govern', ...(o.runId ? { runId: o.runId } : {}) } });
|
|
120
|
+
if (r.decision === 'REQUIRE_APPROVAL') {
|
|
121
|
+
blocks.push({ at: new Date(now()).toISOString(), layer: 'runtime', tool: name, reason: r.reason ?? 'approval required' });
|
|
122
|
+
throw new GovernPaused(name, r.reason ?? 'approval required', undefined, r.approvalId);
|
|
123
|
+
}
|
|
124
|
+
if (r.decision !== 'ALLOW')
|
|
125
|
+
block('runtime', name, r.reason ?? 'denied by governance');
|
|
126
|
+
}
|
|
127
|
+
// 3. The tool body.
|
|
128
|
+
return fn(input);
|
|
129
|
+
},
|
|
130
|
+
release(response) {
|
|
131
|
+
const r = (0, typescript_sdk_1.checkModelResponse)(response, responseMode());
|
|
132
|
+
if (r.decision === 'BLOCK')
|
|
133
|
+
block('response', 'model', `local output guards matched ${r.guards.join(', ')}`);
|
|
134
|
+
return r.response;
|
|
135
|
+
},
|
|
136
|
+
async verify(claims, from) {
|
|
137
|
+
if (!opts.verification)
|
|
138
|
+
throw new Error('govern: no verification engine configured');
|
|
139
|
+
const { engine, tenantId, consumer } = opts.verification;
|
|
140
|
+
const options = { ...(opts.verification.options ?? {}), ...(from.options ?? {}) };
|
|
141
|
+
return engine.verify({ tenantId, consumer, claims, options, ...(from.snapshot !== undefined ? { snapshot: from.snapshot } : {}), ...(from.source !== undefined ? { source: from.source } : {}) });
|
|
142
|
+
},
|
|
143
|
+
blocks() { return blocks.slice().reverse(); },
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=index.js.map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,CAAC,EAAE,CAAC;YAClF,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACpM,CAAC;QAED,MAAM,KAAK,OAAO,MAAM,CAAC,KAAK,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;KAC9C,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@connexum/govern",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "One entry for all three My-CC layers around any agent: data readiness before a tool reads a source, the runtime gate during (the local enforcing gate or the governance server), and correctness after (verification of the agent's claims). Thin stack adapters wrap it; the agent's own code calls govern().tool(), .release() and .verify().",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": { "build": "tsc", "typecheck": "tsc --noEmit", "test": "npx tsx --test --test-force-exit --test-timeout=120000 tests/*.test.mts" },
|
|
9
|
+
"dependencies": { "@connexum/typescript-sdk": "^0.1.0-beta.9" },
|
|
10
|
+
"devDependencies": { "@connexum/verification": "0.1.0-beta.4", "@types/node": "^20.0.0", "tsx": "^4.19.0", "typescript": "^5.4.0" },
|
|
11
|
+
"engines": { "node": ">=20.0.0" },
|
|
12
|
+
"license": "SEE LICENSE IN ../../LICENSE.md",
|
|
13
|
+
"files": ["dist", "README.md"],
|
|
14
|
+
"publishConfig": { "access": "public" },
|
|
15
|
+
"repository": { "type": "git", "url": "https://github.com/Glasgowlad1/AI-Agents-GS.git", "directory": "packages/govern" }
|
|
16
|
+
}
|