meshguard 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/LICENSE +21 -0
- package/README.md +293 -0
- package/dist/cjs/client.d.ts +92 -0
- package/dist/cjs/client.d.ts.map +1 -0
- package/dist/cjs/client.js +314 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/exceptions.d.ts +33 -0
- package/dist/cjs/exceptions.d.ts.map +1 -0
- package/dist/cjs/exceptions.js +60 -0
- package/dist/cjs/exceptions.js.map +1 -0
- package/dist/cjs/index.d.ts +23 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +32 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/langchain.d.ts +106 -0
- package/dist/cjs/langchain.d.ts.map +1 -0
- package/dist/cjs/langchain.js +157 -0
- package/dist/cjs/langchain.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types.d.ts +91 -0
- package/dist/cjs/types.d.ts.map +1 -0
- package/dist/cjs/types.js +6 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/client.d.ts +92 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +310 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/exceptions.d.ts +33 -0
- package/dist/esm/exceptions.d.ts.map +1 -0
- package/dist/esm/exceptions.js +53 -0
- package/dist/esm/exceptions.js.map +1 -0
- package/dist/esm/index.d.ts +23 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +24 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/langchain.d.ts +106 -0
- package/dist/esm/langchain.d.ts.map +1 -0
- package/dist/esm/langchain.js +151 -0
- package/dist/esm/langchain.js.map +1 -0
- package/dist/esm/types.d.ts +91 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +5 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MeshGuard LangChain.js Integration
|
|
4
|
+
*
|
|
5
|
+
* Provides wrappers for governing LangChain tools with MeshGuard policy.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { MeshGuardClient } from "meshguard";
|
|
10
|
+
* import { GovernedTool, GovernedToolkit } from "meshguard/langchain";
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.GovernedToolkit = exports.GovernedTool = void 0;
|
|
15
|
+
exports.governedTool = governedTool;
|
|
16
|
+
const exceptions_js_1 = require("./exceptions.js");
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// governedTool — functional wrapper
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
/**
|
|
21
|
+
* Wrap a LangChain tool so every invocation is governed by MeshGuard policy.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { DuckDuckGoSearch } from "@langchain/community/tools/duckduckgo";
|
|
26
|
+
* import { MeshGuardClient } from "meshguard";
|
|
27
|
+
* import { governedTool } from "meshguard/langchain";
|
|
28
|
+
*
|
|
29
|
+
* const client = new MeshGuardClient();
|
|
30
|
+
* const search = governedTool("read:web_search", client, new DuckDuckGoSearch());
|
|
31
|
+
*
|
|
32
|
+
* const result = await search.invoke("TypeScript SDK patterns");
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
function governedTool(action, client, tool, onDeny) {
|
|
36
|
+
// Create a proxy that intercepts invoke / call
|
|
37
|
+
return new Proxy(tool, {
|
|
38
|
+
get(target, prop, receiver) {
|
|
39
|
+
if (prop === "invoke" || prop === "call") {
|
|
40
|
+
return async (...args) => {
|
|
41
|
+
try {
|
|
42
|
+
await client.enforce(action);
|
|
43
|
+
const fn = Reflect.get(target, prop, receiver);
|
|
44
|
+
return fn.apply(target, args);
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
if (err instanceof exceptions_js_1.PolicyDeniedError && onDeny) {
|
|
48
|
+
return onDeny(err, ...args);
|
|
49
|
+
}
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return Reflect.get(target, prop, receiver);
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
// GovernedTool — class wrapper (mirrors Python GovernedTool)
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
/**
|
|
62
|
+
* Wraps an existing LangChain tool with MeshGuard governance.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* const governed = new GovernedTool({
|
|
67
|
+
* tool: myTool,
|
|
68
|
+
* action: "read:web_search",
|
|
69
|
+
* client,
|
|
70
|
+
* });
|
|
71
|
+
* const result = await governed.invoke("query");
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
class GovernedTool {
|
|
75
|
+
name;
|
|
76
|
+
description;
|
|
77
|
+
action;
|
|
78
|
+
tool;
|
|
79
|
+
client;
|
|
80
|
+
onDeny;
|
|
81
|
+
constructor(options) {
|
|
82
|
+
this.tool = options.tool;
|
|
83
|
+
this.action = options.action;
|
|
84
|
+
this.client = options.client;
|
|
85
|
+
this.onDeny = options.onDeny;
|
|
86
|
+
this.name = this.tool.name;
|
|
87
|
+
this.description = this.tool.description;
|
|
88
|
+
}
|
|
89
|
+
/** Invoke the tool with governance. */
|
|
90
|
+
async invoke(input, config) {
|
|
91
|
+
try {
|
|
92
|
+
await this.client.enforce(this.action);
|
|
93
|
+
return this.tool.invoke(input, config);
|
|
94
|
+
}
|
|
95
|
+
catch (err) {
|
|
96
|
+
if (err instanceof exceptions_js_1.PolicyDeniedError && this.onDeny) {
|
|
97
|
+
return this.onDeny(err, input, config);
|
|
98
|
+
}
|
|
99
|
+
throw err;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** Legacy call method. */
|
|
103
|
+
async call(input, config) {
|
|
104
|
+
return this.invoke(input, config);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.GovernedTool = GovernedTool;
|
|
108
|
+
// ---------------------------------------------------------------------------
|
|
109
|
+
// GovernedToolkit — govern multiple tools at once
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
/**
|
|
112
|
+
* Govern a collection of LangChain tools with MeshGuard policies.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* const toolkit = new GovernedToolkit({
|
|
117
|
+
* tools: [searchTool, calcTool],
|
|
118
|
+
* client,
|
|
119
|
+
* actionMap: {
|
|
120
|
+
* "search": "read:web_search",
|
|
121
|
+
* "calculator": "execute:math",
|
|
122
|
+
* },
|
|
123
|
+
* defaultAction: "execute:tool",
|
|
124
|
+
* });
|
|
125
|
+
*
|
|
126
|
+
* const governedTools = toolkit.getTools();
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
class GovernedToolkit {
|
|
130
|
+
tools;
|
|
131
|
+
client;
|
|
132
|
+
actionMap;
|
|
133
|
+
defaultAction;
|
|
134
|
+
onDeny;
|
|
135
|
+
constructor(options) {
|
|
136
|
+
this.tools = options.tools;
|
|
137
|
+
this.client = options.client;
|
|
138
|
+
this.actionMap = options.actionMap ?? {};
|
|
139
|
+
this.defaultAction = options.defaultAction ?? "execute:tool";
|
|
140
|
+
this.onDeny = options.onDeny;
|
|
141
|
+
}
|
|
142
|
+
/** Get the MeshGuard action for a tool. */
|
|
143
|
+
getAction(tool) {
|
|
144
|
+
return this.actionMap[tool.name] ?? this.defaultAction;
|
|
145
|
+
}
|
|
146
|
+
/** Return governed versions of all tools. */
|
|
147
|
+
getTools() {
|
|
148
|
+
return this.tools.map((tool) => new GovernedTool({
|
|
149
|
+
tool,
|
|
150
|
+
action: this.getAction(tool),
|
|
151
|
+
client: this.client,
|
|
152
|
+
onDeny: this.onDeny,
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
exports.GovernedToolkit = GovernedToolkit;
|
|
157
|
+
//# sourceMappingURL=langchain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langchain.js","sourceRoot":"","sources":["../../src/langchain.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;AA0CH,oCA4BC;AAnED,mDAAoD;AAoBpD,8EAA8E;AAC9E,oCAAoC;AACpC,8EAA8E;AAE9E;;;;;;;;;;;;;;GAcG;AACH,SAAgB,YAAY,CAC1B,MAAc,EACd,MAAuB,EACvB,IAAO,EACP,MAAoB;IAEpB,+CAA+C;IAC/C,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE;QACrB,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;YACxB,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;gBACzC,OAAO,KAAK,EAAE,GAAG,IAAe,EAAE,EAAE;oBAClC,IAAI,CAAC;wBACH,MAAM,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;wBAC7B,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAExB,CAAC;wBACtB,OAAO,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;oBAChC,CAAC;oBAAC,OAAO,GAAG,EAAE,CAAC;wBACb,IAAI,GAAG,YAAY,iCAAiB,IAAI,MAAM,EAAE,CAAC;4BAC/C,OAAO,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;wBAC9B,CAAC;wBACD,MAAM,GAAG,CAAC;oBACZ,CAAC;gBACH,CAAC,CAAC;YACJ,CAAC;YACD,OAAO,OAAO,CAAC,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shGuard client. */
|
|
5
|
+
export interface MeshGuardOptions {
|
|
6
|
+
/** MeshGuard gateway URL. Falls back to MESHGUARD_GATEWAY_URL env var. */
|
|
7
|
+
gatewayUrl?: string;
|
|
8
|
+
/** Agent JWT token. Falls back to MESHGUARD_AGENT_TOKEN env var. */
|
|
9
|
+
agentToken?: string;
|
|
10
|
+
/** Admin token for management APIs. Falls back to MESHGUARD_ADMIN_TOKEN env var. */
|
|
11
|
+
adminToken?: string;
|
|
12
|
+
/** Request timeout in milliseconds. Default: 30000. */
|
|
13
|
+
timeout?: number;
|
|
14
|
+
/** Optional trace ID for request correlation. Auto-generated if omitted. */
|
|
15
|
+
traceId?: string;
|
|
16
|
+
}
|
|
17
|
+
/** Result of a policy evaluation. */
|
|
18
|
+
export interface PolicyDecision {
|
|
19
|
+
/** Whether the action is allowed. */
|
|
20
|
+
allowed: boolean;
|
|
21
|
+
/** The action that was checked. */
|
|
22
|
+
action: string;
|
|
23
|
+
/** The decision result: "allow" or "deny". */
|
|
24
|
+
decision: "allow" | "deny";
|
|
25
|
+
/** The policy that produced this decision. */
|
|
26
|
+
policy?: string;
|
|
27
|
+
/** The specific rule that matched. */
|
|
28
|
+
rule?: string;
|
|
29
|
+
/** Human-readable reason for the decision. */
|
|
30
|
+
reason?: string;
|
|
31
|
+
/** Trace ID for request correlation. */
|
|
32
|
+
traceId?: string;
|
|
33
|
+
}
|
|
34
|
+
/** A MeshGuard agent identity. */
|
|
35
|
+
export interface Agent {
|
|
36
|
+
/** Unique agent identifier. */
|
|
37
|
+
id: string;
|
|
38
|
+
/** Display name. */
|
|
39
|
+
name: string;
|
|
40
|
+
/** Trust tier (e.g., "verified", "untrusted"). */
|
|
41
|
+
trustTier: string;
|
|
42
|
+
/** Tags associated with this agent. */
|
|
43
|
+
tags: string[];
|
|
44
|
+
/** Organization ID. */
|
|
45
|
+
orgId?: string;
|
|
46
|
+
}
|
|
47
|
+
/** Options for creating an agent. */
|
|
48
|
+
export interface CreateAgentOptions {
|
|
49
|
+
/** Agent display name. */
|
|
50
|
+
name: string;
|
|
51
|
+
/** Trust tier. Default: "verified". */
|
|
52
|
+
trustTier?: string;
|
|
53
|
+
/** Tags to assign. */
|
|
54
|
+
tags?: string[];
|
|
55
|
+
}
|
|
56
|
+
/** An entry in the audit log. */
|
|
57
|
+
export interface AuditEntry {
|
|
58
|
+
/** Unique entry ID. */
|
|
59
|
+
id: string;
|
|
60
|
+
/** Timestamp of the entry. */
|
|
61
|
+
timestamp: string;
|
|
62
|
+
/** The action that was evaluated. */
|
|
63
|
+
action: string;
|
|
64
|
+
/** The decision: "allow" or "deny". */
|
|
65
|
+
decision: string;
|
|
66
|
+
/** Agent ID that performed the action. */
|
|
67
|
+
agentId?: string;
|
|
68
|
+
/** Policy that was evaluated. */
|
|
69
|
+
policy?: string;
|
|
70
|
+
/** Additional metadata. */
|
|
71
|
+
[key: string]: unknown;
|
|
72
|
+
}
|
|
73
|
+
/** Options for querying the audit log. */
|
|
74
|
+
export interface AuditLogOptions {
|
|
75
|
+
/** Maximum number of entries to return. Default: 50. */
|
|
76
|
+
limit?: number;
|
|
77
|
+
/** Filter by decision ("allow" or "deny"). */
|
|
78
|
+
decision?: string;
|
|
79
|
+
}
|
|
80
|
+
/** Gateway health status. */
|
|
81
|
+
export interface HealthStatus {
|
|
82
|
+
status: string;
|
|
83
|
+
[key: string]: unknown;
|
|
84
|
+
}
|
|
85
|
+
/** A policy definition. */
|
|
86
|
+
export interface Policy {
|
|
87
|
+
id: string;
|
|
88
|
+
name: string;
|
|
89
|
+
[key: string]: unknown;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,sDAAsD;AACtD,MAAM,WAAW,gBAAgB;IAC/B,0EAA0E;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,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AAM,CAAC;IACf,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,2BAA2B;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,0CAA0C;AAC1C,MAAM,WAAW,eAAe;IAC9B,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,6BAA6B;AAC7B,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,2BAA2B;AAC3B,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";AAAA;;GAEG"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MeshGuard Client
|
|
3
|
+
*
|
|
4
|
+
* Core client for interacting with the MeshGuard gateway.
|
|
5
|
+
*/
|
|
6
|
+
import type { MeshGuardOptions, PolicyDecision, Agent, CreateAgentOptions, AuditEntry, AuditLogOptions, HealthStatus, Policy } from "./types.js";
|
|
7
|
+
/**
|
|
8
|
+
* Client for the MeshGuard governance gateway.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const client = new MeshGuardClient({
|
|
13
|
+
* gatewayUrl: "https://dashboard.meshguard.app",
|
|
14
|
+
* agentToken: "your-agent-token",
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Check if an action is allowed
|
|
18
|
+
* const decision = await client.check("read:contacts");
|
|
19
|
+
* if (decision.allowed) {
|
|
20
|
+
* // proceed
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* // Or enforce (throws on deny)
|
|
24
|
+
* await client.enforce("read:contacts");
|
|
25
|
+
*
|
|
26
|
+
* // Or govern a function
|
|
27
|
+
* const result = await client.govern("read:contacts", async () => {
|
|
28
|
+
* return fetchContacts();
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class MeshGuardClient {
|
|
33
|
+
readonly gatewayUrl: string;
|
|
34
|
+
readonly agentToken?: string;
|
|
35
|
+
readonly adminToken?: string;
|
|
36
|
+
readonly timeout: number;
|
|
37
|
+
readonly traceId: string;
|
|
38
|
+
constructor(options?: MeshGuardOptions);
|
|
39
|
+
private headers;
|
|
40
|
+
private adminHeaders;
|
|
41
|
+
private handleResponse;
|
|
42
|
+
private safeJson;
|
|
43
|
+
private fetch;
|
|
44
|
+
/**
|
|
45
|
+
* Check if an action is allowed by policy.
|
|
46
|
+
*
|
|
47
|
+
* Returns a {@link PolicyDecision} — never throws on deny.
|
|
48
|
+
*/
|
|
49
|
+
check(action: string, resource?: string): Promise<PolicyDecision>;
|
|
50
|
+
/**
|
|
51
|
+
* Enforce policy — throws {@link PolicyDeniedError} if the action is denied.
|
|
52
|
+
*/
|
|
53
|
+
enforce(action: string, resource?: string): Promise<PolicyDecision>;
|
|
54
|
+
/**
|
|
55
|
+
* Execute a function only if the action is allowed by policy.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const contacts = await client.govern("read:contacts", async () => {
|
|
60
|
+
* return db.contacts.findAll();
|
|
61
|
+
* });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
govern<T>(action: string, fn: () => T | Promise<T>, resource?: string): Promise<T>;
|
|
65
|
+
/**
|
|
66
|
+
* Make a governed request through the MeshGuard proxy.
|
|
67
|
+
*/
|
|
68
|
+
request(method: string, path: string, action: string, init?: RequestInit): Promise<Response>;
|
|
69
|
+
/** GET through the governance proxy. */
|
|
70
|
+
get(path: string, action: string, init?: RequestInit): Promise<Response>;
|
|
71
|
+
/** POST through the governance proxy. */
|
|
72
|
+
post(path: string, action: string, init?: RequestInit): Promise<Response>;
|
|
73
|
+
/** PUT through the governance proxy. */
|
|
74
|
+
put(path: string, action: string, init?: RequestInit): Promise<Response>;
|
|
75
|
+
/** DELETE through the governance proxy. */
|
|
76
|
+
delete(path: string, action: string, init?: RequestInit): Promise<Response>;
|
|
77
|
+
/** Check gateway health. */
|
|
78
|
+
health(): Promise<HealthStatus>;
|
|
79
|
+
/** Quick boolean health check. */
|
|
80
|
+
isHealthy(): Promise<boolean>;
|
|
81
|
+
/** List all agents (requires admin token). */
|
|
82
|
+
listAgents(): Promise<Agent[]>;
|
|
83
|
+
/** Create a new agent (requires admin token). */
|
|
84
|
+
createAgent(options: CreateAgentOptions): Promise<Record<string, unknown>>;
|
|
85
|
+
/** Revoke an agent (requires admin token). */
|
|
86
|
+
revokeAgent(agentId: string): Promise<void>;
|
|
87
|
+
/** List all policies (requires admin token). */
|
|
88
|
+
listPolicies(): Promise<Policy[]>;
|
|
89
|
+
/** Get audit log entries (requires admin token). */
|
|
90
|
+
getAuditLog(options?: AuditLogOptions): Promise<AuditEntry[]>;
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,KAAK,EACL,kBAAkB,EAClB,UAAU,EACV,eAAe,EACf,YAAY,EACZ,MAAM,EACP,MAAM,YAAY,CAAC;AASpB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,eAAe;IAC1B,Q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AAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAI9E,2CAA2C;IACrC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAQjF,4BAA4B;IACtB,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC;IAKrC,kCAAkC;IAC5B,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAanC,8CAA8C;IACxC,UAAU,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IAepC,iDAAiD;IAC3C,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAgBhF,8CAA8C;IACxC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQjD,gDAAgD;IAC1C,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAQvC,oDAAoD;IAC9C,WAAW,CAAC,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;CAYxE"}
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MeshGuard Client
|
|
3
|
+
*
|
|
4
|
+
* Core client for interacting with the MeshGuard gateway.
|
|
5
|
+
*/
|
|
6
|
+
import { MeshGuardError, AuthenticationError, PolicyDeniedError, RateLimitError, } from "./exceptions.js";
|
|
7
|
+
/**
|
|
8
|
+
* Client for the MeshGuard governance gateway.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const client = new MeshGuardClient({
|
|
13
|
+
* gatewayUrl: "https://dashboard.meshguard.app",
|
|
14
|
+
* agentToken: "your-agent-token",
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Check if an action is allowed
|
|
18
|
+
* const decision = await client.check("read:contacts");
|
|
19
|
+
* if (decision.allowed) {
|
|
20
|
+
* // proceed
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* // Or enforce (throws on deny)
|
|
24
|
+
* await client.enforce("read:contacts");
|
|
25
|
+
*
|
|
26
|
+
* // Or govern a function
|
|
27
|
+
* const result = await client.govern("read:contacts", async () => {
|
|
28
|
+
* return fetchContacts();
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export class MeshGuardClient {
|
|
33
|
+
gatewayUrl;
|
|
34
|
+
agentToken;
|
|
35
|
+
adminToken;
|
|
36
|
+
timeout;
|
|
37
|
+
traceId;
|
|
38
|
+
constructor(options = {}) {
|
|
39
|
+
this.gatewayUrl = (options.gatewayUrl ??
|
|
40
|
+
process.env.MESHGUARD_GATEWAY_URL ??
|
|
41
|
+
"http://localhost:3100").replace(/\/+$/, "");
|
|
42
|
+
this.agentToken =
|
|
43
|
+
options.agentToken ?? process.env.MESHGUARD_AGENT_TOKEN;
|
|
44
|
+
this.adminToken =
|
|
45
|
+
options.adminToken ?? process.env.MESHGUARD_ADMIN_TOKEN;
|
|
46
|
+
this.timeout = options.timeout ?? 30_000;
|
|
47
|
+
this.traceId = options.traceId ?? crypto.randomUUID();
|
|
48
|
+
}
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// Internal helpers
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
headers(includeAuth = true) {
|
|
53
|
+
const h = {
|
|
54
|
+
"X-MeshGuard-Trace-ID": this.traceId,
|
|
55
|
+
};
|
|
56
|
+
if (includeAuth && this.agentToken) {
|
|
57
|
+
h["Authorization"] = `Bearer ${this.agentToken}`;
|
|
58
|
+
}
|
|
59
|
+
return h;
|
|
60
|
+
}
|
|
61
|
+
adminHeaders() {
|
|
62
|
+
if (!this.adminToken) {
|
|
63
|
+
throw new AuthenticationError("Admin token required for this operation");
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
"X-Admin-Token": this.adminToken,
|
|
67
|
+
"X-MeshGuard-Trace-ID": this.traceId,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async handleResponse(response) {
|
|
71
|
+
if (response.status === 401) {
|
|
72
|
+
throw new AuthenticationError("Invalid or expired token");
|
|
73
|
+
}
|
|
74
|
+
if (response.status === 403) {
|
|
75
|
+
const data = await this.safeJson(response);
|
|
76
|
+
throw new PolicyDeniedError({
|
|
77
|
+
action: data.action ?? "unknown",
|
|
78
|
+
policy: data.policy,
|
|
79
|
+
rule: data.rule,
|
|
80
|
+
reason: data.message ?? "Access denied by policy",
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (response.status === 429) {
|
|
84
|
+
throw new RateLimitError("Rate limit exceeded");
|
|
85
|
+
}
|
|
86
|
+
if (response.status >= 400) {
|
|
87
|
+
const text = await response.text();
|
|
88
|
+
throw new MeshGuardError(`Request failed: ${response.status} ${text}`);
|
|
89
|
+
}
|
|
90
|
+
return this.safeJson(response);
|
|
91
|
+
}
|
|
92
|
+
async safeJson(response) {
|
|
93
|
+
const text = await response.text();
|
|
94
|
+
if (!text)
|
|
95
|
+
return {};
|
|
96
|
+
try {
|
|
97
|
+
return JSON.parse(text);
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return {};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async fetch(url, init = {}) {
|
|
104
|
+
const controller = new AbortController();
|
|
105
|
+
const timer = setTimeout(() => controller.abort(), this.timeout);
|
|
106
|
+
try {
|
|
107
|
+
return await fetch(url, { ...init, signal: controller.signal });
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
clearTimeout(timer);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// ---------------------------------------------------------------------------
|
|
114
|
+
// Core Governance
|
|
115
|
+
// ---------------------------------------------------------------------------
|
|
116
|
+
/**
|
|
117
|
+
* Check if an action is allowed by policy.
|
|
118
|
+
*
|
|
119
|
+
* Returns a {@link PolicyDecision} — never throws on deny.
|
|
120
|
+
*/
|
|
121
|
+
async check(action, resource) {
|
|
122
|
+
const h = this.headers();
|
|
123
|
+
h["X-MeshGuard-Action"] = action;
|
|
124
|
+
if (resource)
|
|
125
|
+
h["X-MeshGuard-Resource"] = resource;
|
|
126
|
+
try {
|
|
127
|
+
const response = await this.fetch(`${this.gatewayUrl}/proxy/check`, {
|
|
128
|
+
method: "GET",
|
|
129
|
+
headers: h,
|
|
130
|
+
});
|
|
131
|
+
if (response.status === 403) {
|
|
132
|
+
const data = await this.safeJson(response);
|
|
133
|
+
return {
|
|
134
|
+
allowed: false,
|
|
135
|
+
action,
|
|
136
|
+
decision: "deny",
|
|
137
|
+
policy: data.policy,
|
|
138
|
+
rule: data.rule,
|
|
139
|
+
reason: data.message,
|
|
140
|
+
traceId: this.traceId,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
const data = await this.handleResponse(response);
|
|
144
|
+
return {
|
|
145
|
+
allowed: true,
|
|
146
|
+
action,
|
|
147
|
+
decision: "allow",
|
|
148
|
+
policy: data.policy,
|
|
149
|
+
traceId: this.traceId,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
if (err instanceof PolicyDeniedError) {
|
|
154
|
+
return {
|
|
155
|
+
allowed: false,
|
|
156
|
+
action,
|
|
157
|
+
decision: "deny",
|
|
158
|
+
policy: err.policy,
|
|
159
|
+
rule: err.rule,
|
|
160
|
+
reason: err.reason,
|
|
161
|
+
traceId: this.traceId,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Enforce policy — throws {@link PolicyDeniedError} if the action is denied.
|
|
169
|
+
*/
|
|
170
|
+
async enforce(action, resource) {
|
|
171
|
+
const decision = await this.check(action, resource);
|
|
172
|
+
if (!decision.allowed) {
|
|
173
|
+
throw new PolicyDeniedError({
|
|
174
|
+
action,
|
|
175
|
+
policy: decision.policy,
|
|
176
|
+
rule: decision.rule,
|
|
177
|
+
reason: decision.reason,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return decision;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Execute a function only if the action is allowed by policy.
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```ts
|
|
187
|
+
* const contacts = await client.govern("read:contacts", async () => {
|
|
188
|
+
* return db.contacts.findAll();
|
|
189
|
+
* });
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
async govern(action, fn, resource) {
|
|
193
|
+
await this.enforce(action, resource);
|
|
194
|
+
return fn();
|
|
195
|
+
}
|
|
196
|
+
// ---------------------------------------------------------------------------
|
|
197
|
+
// Proxy Requests
|
|
198
|
+
// ---------------------------------------------------------------------------
|
|
199
|
+
/**
|
|
200
|
+
* Make a governed request through the MeshGuard proxy.
|
|
201
|
+
*/
|
|
202
|
+
async request(method, path, action, init = {}) {
|
|
203
|
+
const h = {
|
|
204
|
+
...this.headers(),
|
|
205
|
+
"X-MeshGuard-Action": action,
|
|
206
|
+
};
|
|
207
|
+
// Merge any caller-provided headers
|
|
208
|
+
if (init.headers) {
|
|
209
|
+
const extra = init.headers instanceof Headers
|
|
210
|
+
? Object.fromEntries(init.headers.entries())
|
|
211
|
+
: init.headers;
|
|
212
|
+
Object.assign(h, extra);
|
|
213
|
+
}
|
|
214
|
+
const response = await this.fetch(`${this.gatewayUrl}/proxy/${path.replace(/^\/+/, "")}`, { ...init, method, headers: h });
|
|
215
|
+
await this.handleResponse(response);
|
|
216
|
+
return response;
|
|
217
|
+
}
|
|
218
|
+
/** GET through the governance proxy. */
|
|
219
|
+
async get(path, action, init) {
|
|
220
|
+
return this.request("GET", path, action, init);
|
|
221
|
+
}
|
|
222
|
+
/** POST through the governance proxy. */
|
|
223
|
+
async post(path, action, init) {
|
|
224
|
+
return this.request("POST", path, action, init);
|
|
225
|
+
}
|
|
226
|
+
/** PUT through the governance proxy. */
|
|
227
|
+
async put(path, action, init) {
|
|
228
|
+
return this.request("PUT", path, action, init);
|
|
229
|
+
}
|
|
230
|
+
/** DELETE through the governance proxy. */
|
|
231
|
+
async delete(path, action, init) {
|
|
232
|
+
return this.request("DELETE", path, action, init);
|
|
233
|
+
}
|
|
234
|
+
// ---------------------------------------------------------------------------
|
|
235
|
+
// Health & Info
|
|
236
|
+
// ---------------------------------------------------------------------------
|
|
237
|
+
/** Check gateway health. */
|
|
238
|
+
async health() {
|
|
239
|
+
const response = await this.fetch(`${this.gatewayUrl}/health`);
|
|
240
|
+
return (await response.json());
|
|
241
|
+
}
|
|
242
|
+
/** Quick boolean health check. */
|
|
243
|
+
async isHealthy() {
|
|
244
|
+
try {
|
|
245
|
+
const h = await this.health();
|
|
246
|
+
return h.status === "healthy";
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
// ---------------------------------------------------------------------------
|
|
253
|
+
// Admin Operations
|
|
254
|
+
// ---------------------------------------------------------------------------
|
|
255
|
+
/** List all agents (requires admin token). */
|
|
256
|
+
async listAgents() {
|
|
257
|
+
const response = await this.fetch(`${this.gatewayUrl}/admin/agents`, {
|
|
258
|
+
headers: this.adminHeaders(),
|
|
259
|
+
});
|
|
260
|
+
const data = await this.handleResponse(response);
|
|
261
|
+
const agents = data.agents ?? [];
|
|
262
|
+
return agents.map((a) => ({
|
|
263
|
+
id: a.id,
|
|
264
|
+
name: a.name,
|
|
265
|
+
trustTier: a.trustTier,
|
|
266
|
+
tags: a.tags ?? [],
|
|
267
|
+
orgId: a.orgId,
|
|
268
|
+
}));
|
|
269
|
+
}
|
|
270
|
+
/** Create a new agent (requires admin token). */
|
|
271
|
+
async createAgent(options) {
|
|
272
|
+
const response = await this.fetch(`${this.gatewayUrl}/admin/agents`, {
|
|
273
|
+
method: "POST",
|
|
274
|
+
headers: {
|
|
275
|
+
...this.adminHeaders(),
|
|
276
|
+
"Content-Type": "application/json",
|
|
277
|
+
},
|
|
278
|
+
body: JSON.stringify({
|
|
279
|
+
name: options.name,
|
|
280
|
+
trustTier: options.trustTier ?? "verified",
|
|
281
|
+
tags: options.tags ?? [],
|
|
282
|
+
}),
|
|
283
|
+
});
|
|
284
|
+
return this.handleResponse(response);
|
|
285
|
+
}
|
|
286
|
+
/** Revoke an agent (requires admin token). */
|
|
287
|
+
async revokeAgent(agentId) {
|
|
288
|
+
const response = await this.fetch(`${this.gatewayUrl}/admin/agents/${agentId}`, { method: "DELETE", headers: this.adminHeaders() });
|
|
289
|
+
await this.handleResponse(response);
|
|
290
|
+
}
|
|
291
|
+
/** List all policies (requires admin token). */
|
|
292
|
+
async listPolicies() {
|
|
293
|
+
const response = await this.fetch(`${this.gatewayUrl}/admin/policies`, {
|
|
294
|
+
headers: this.adminHeaders(),
|
|
295
|
+
});
|
|
296
|
+
const data = await this.handleResponse(response);
|
|
297
|
+
return data.policies ?? [];
|
|
298
|
+
}
|
|
299
|
+
/** Get audit log entries (requires admin token). */
|
|
300
|
+
async getAuditLog(options = {}) {
|
|
301
|
+
const params = new URLSearchParams();
|
|
302
|
+
params.set("limit", String(options.limit ?? 50));
|
|
303
|
+
if (options.decision)
|
|
304
|
+
params.set("decision", options.decision);
|
|
305
|
+
const response = await this.fetch(`${this.gatewayUrl}/admin/audit?${params}`, { headers: this.adminHeaders() });
|
|
306
|
+
const data = await this.handleResponse(response);
|
|
307
|
+
return data.entries ?? [];
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
//# sourceMappingURL=client.js.map
|