@guardiojs/guardio 0.0.2 → 0.0.3
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 +6 -7
- package/dist/cli.js +2 -2
- package/dist/config/PluginManager.d.ts.map +1 -1
- package/dist/config/PluginManager.js +52 -59
- package/dist/config/PluginManager.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/types.d.ts +6 -21
- package/dist/config/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -4
package/README.md
CHANGED
|
@@ -98,17 +98,16 @@ Each **plugins** entry has:
|
|
|
98
98
|
|
|
99
99
|
When using **`--config /path/to/guardio.config.json`**, the **server** block above is used automatically; you don’t pass the MCP server command on the command line.
|
|
100
100
|
|
|
101
|
-
###
|
|
101
|
+
### Custom plugins (path in config)
|
|
102
102
|
|
|
103
|
-
|
|
103
|
+
Use a **`path`** on a plugin entry to load a custom plugin from a directory (relative to the config file or absolute). That directory must contain **`index.js`** or **`index.mjs`** (compile from `index.ts` with your build script). The module's **default export must be the plugin instance** (no descriptor).
|
|
104
104
|
|
|
105
|
-
- **
|
|
106
|
-
- **
|
|
107
|
-
- **Descriptor**: The entry
|
|
105
|
+
- **Policy**: `{ "type": "policy", "name": "my-policy", "path": "./plugins/my-policy" }` — default export must implement **`PolicyPluginInterface`** (name, evaluate).
|
|
106
|
+
- **Intervention** (path): In each subdirectory Guardio looks for **`index.js`** or **`index.mjs`** (compiled output). Write your plugin in TypeScript (`index.ts`) and **compile** it with the project’s build script (e.g. `npm run build`).
|
|
107
|
+
- **Descriptor**: The entry module must **default-export a descriptor** `{ type, name, create }`:
|
|
108
108
|
- **Policy**: `type: "policy"`, `name: string`, `create: (config) => instance` where the instance implements **`PolicyPluginInterface`** (readonly `name`, method `evaluate(context) => "allowed" | "blocked" | "require_approval"`).
|
|
109
109
|
- **Intervention**: `type: "intervention"`, `name: string`, `create: (config) => instance` where the instance implements **`InterventionPluginInterface`** (readonly `name`, method `act(context) => void | boolean | Promise<...>`).
|
|
110
|
-
|
|
111
|
-
- **TypeScript**: Guardio loads `index.ts` via **ts-node** (optional dependency; install it for local plugins to work).
|
|
110
|
+
Import types from `@guardiojs/guardio`.’s Run your build so the directory has `index.js` or `index.mjs` before Guardio.
|
|
112
111
|
|
|
113
112
|
## Running Guardio (CLI)
|
|
114
113
|
|
package/dist/cli.js
CHANGED
|
@@ -32,7 +32,7 @@ async function main() {
|
|
|
32
32
|
? process.env.GUARDIO_ARGS.split(",").map((s) => s.trim())
|
|
33
33
|
: process.env.MCP_REAL_TOOL_ARGS
|
|
34
34
|
? process.env.MCP_REAL_TOOL_ARGS.split(",").map((s) => s.trim())
|
|
35
|
-
: ["/path/to/your/actual-mcp-server/index.
|
|
35
|
+
: ["/path/to/your/actual-mcp-server/index.ts"];
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
@@ -58,7 +58,7 @@ async function main() {
|
|
|
58
58
|
? process.env.GUARDIO_ARGS.split(",").map((s) => s.trim())
|
|
59
59
|
: process.env.MCP_REAL_TOOL_ARGS
|
|
60
60
|
? process.env.MCP_REAL_TOOL_ARGS.split(",").map((s) => s.trim())
|
|
61
|
-
: ["/path/to/your/actual-mcp-server/index.
|
|
61
|
+
: ["/path/to/your/actual-mcp-server/index.ts"];
|
|
62
62
|
}
|
|
63
63
|
const core = new GuardioCore({
|
|
64
64
|
command,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../src/config/PluginManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../src/config/PluginManager.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,aAAa,EAGd,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,q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C"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { readFileSync, existsSync
|
|
2
|
-
import { join, dirname } from "node:path";
|
|
1
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
2
|
+
import { join, dirname, resolve } from "node:path";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
|
-
import { createRequire } from "node:module";
|
|
5
4
|
import { DefaultPolicyPlugin, RegexPolicyPlugin, } from "../plugins/policy/index.js";
|
|
6
5
|
import { DefaultInterventionPlugin, HttpInterventionPlugin, } from "../plugins/intervention/index.js";
|
|
7
6
|
const policyRegistry = {
|
|
@@ -12,60 +11,31 @@ const interventionRegistry = {
|
|
|
12
11
|
default: (config) => new DefaultInterventionPlugin(config),
|
|
13
12
|
http: (config) => new HttpInterventionPlugin(config),
|
|
14
13
|
};
|
|
15
|
-
/** Entry
|
|
16
|
-
const
|
|
14
|
+
/** Entry filenames to load from a plugin directory (first found wins). */
|
|
15
|
+
const PLUGIN_ENTRY_NAMES = ["index.js", "index.mjs"];
|
|
17
16
|
/**
|
|
18
|
-
*
|
|
19
|
-
* Each plugin is a subdirectory with index.ts (or index.js/mjs/cjs); default export must be a descriptor.
|
|
17
|
+
* Resolve plugin directory to an entry file (index.js or index.mjs). Path is relative to configDir or absolute.
|
|
20
18
|
*/
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return;
|
|
28
|
-
const entries = readdirSync(pluginsDir, { withFileTypes: true });
|
|
29
|
-
for (const dirent of entries) {
|
|
30
|
-
if (!dirent.isDirectory())
|
|
31
|
-
continue;
|
|
32
|
-
const entryPath = join(pluginsDir, dirent.name, PLUGIN_ENTRY_NAME);
|
|
33
|
-
if (!existsSync(entryPath))
|
|
34
|
-
continue;
|
|
35
|
-
const mod = await loadPluginModule(entryPath);
|
|
36
|
-
const raw = mod?.default ?? mod;
|
|
37
|
-
if (!raw || typeof raw !== "object")
|
|
38
|
-
continue;
|
|
39
|
-
const descriptor = raw;
|
|
40
|
-
if (descriptor.type !== "policy" && descriptor.type !== "intervention")
|
|
41
|
-
continue;
|
|
42
|
-
if (typeof descriptor.name !== "string" ||
|
|
43
|
-
typeof descriptor.create !== "function") {
|
|
44
|
-
throw new Error(`Local plugin at ${entryPath}: default export must be { type, name, create } (name string, create function).`);
|
|
45
|
-
}
|
|
46
|
-
const desc = descriptor;
|
|
47
|
-
if (desc.type === "policy") {
|
|
48
|
-
pluginManager.registerPolicyPlugin(desc.name, (config) => desc.create(config ?? {}));
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
pluginManager.registerInterventionPlugin(desc.name, (config) => desc.create(config ?? {}));
|
|
52
|
-
}
|
|
19
|
+
function resolvePluginEntryPath(pluginPath, configDir) {
|
|
20
|
+
const dir = resolve(configDir, pluginPath);
|
|
21
|
+
for (const name of PLUGIN_ENTRY_NAMES) {
|
|
22
|
+
const p = join(dir, name);
|
|
23
|
+
if (existsSync(p))
|
|
24
|
+
return p;
|
|
53
25
|
}
|
|
26
|
+
throw new Error(`Plugin at ${pluginPath} must contain index.js or index.mjs (run build to compile index.ts).`);
|
|
54
27
|
}
|
|
55
28
|
/**
|
|
56
|
-
* Load
|
|
29
|
+
* Load plugin instance from a directory: import index.js/index.mjs, return default export (the instance).
|
|
57
30
|
*/
|
|
58
|
-
async function
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
catch (e) {
|
|
66
|
-
const msg = e instanceof Error ? e.message : String(e);
|
|
67
|
-
throw new Error(`Failed to load TypeScript plugin ${entryPath}. Install ts-node (e.g. npm install ts-node). ${msg}`);
|
|
31
|
+
async function loadPluginInstance(entryPath) {
|
|
32
|
+
const url = pathToFileURL(entryPath).href;
|
|
33
|
+
const mod = await import(url);
|
|
34
|
+
const instance = mod?.default ?? mod;
|
|
35
|
+
if (!instance || typeof instance !== "object") {
|
|
36
|
+
throw new Error(`Plugin at ${entryPath}: default export must be the plugin instance.`);
|
|
68
37
|
}
|
|
38
|
+
return instance;
|
|
69
39
|
}
|
|
70
40
|
/**
|
|
71
41
|
* Resolves path to config file: first .js, then .ts, then .json (from cwd).
|
|
@@ -132,7 +102,6 @@ export class PluginManager {
|
|
|
132
102
|
this.config = await loadConfigFromPath(path);
|
|
133
103
|
this.policyPlugins = null;
|
|
134
104
|
this.interventionPlugins = null;
|
|
135
|
-
await loadLocalPlugins(this, path);
|
|
136
105
|
return this.config;
|
|
137
106
|
}
|
|
138
107
|
/**
|
|
@@ -144,12 +113,24 @@ export class PluginManager {
|
|
|
144
113
|
return this.policyPlugins;
|
|
145
114
|
const plugins = (this.config.plugins ?? []).filter((p) => p.type === "policy");
|
|
146
115
|
const instances = [];
|
|
116
|
+
const configDir = dirname(this.configPath);
|
|
147
117
|
for (const entry of plugins) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
118
|
+
if (entry.path) {
|
|
119
|
+
const entryPath = resolvePluginEntryPath(entry.path, configDir);
|
|
120
|
+
const instance = await loadPluginInstance(entryPath);
|
|
121
|
+
if (typeof instance.name !== "string" ||
|
|
122
|
+
typeof instance.evaluate !== "function") {
|
|
123
|
+
throw new Error(`Plugin at ${entry.path}: default export must be a policy instance (name, evaluate).`);
|
|
124
|
+
}
|
|
125
|
+
instances.push(instance);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
const factory = policyRegistry[entry.name];
|
|
129
|
+
if (!factory) {
|
|
130
|
+
throw new Error(`Unknown policy plugin name: "${entry.name}". Registered: ${Object.keys(policyRegistry).join(", ")}`);
|
|
131
|
+
}
|
|
132
|
+
instances.push(factory(entry.config ?? {}));
|
|
151
133
|
}
|
|
152
|
-
instances.push(factory(entry.config ?? {}));
|
|
153
134
|
}
|
|
154
135
|
this.policyPlugins = instances;
|
|
155
136
|
return instances;
|
|
@@ -173,12 +154,24 @@ export class PluginManager {
|
|
|
173
154
|
return this.interventionPlugins;
|
|
174
155
|
const plugins = (this.config.plugins ?? []).filter((p) => p.type === "intervention");
|
|
175
156
|
const instances = [];
|
|
157
|
+
const configDir = dirname(this.configPath);
|
|
176
158
|
for (const entry of plugins) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
159
|
+
if (entry.path) {
|
|
160
|
+
const entryPath = resolvePluginEntryPath(entry.path, configDir);
|
|
161
|
+
const instance = await loadPluginInstance(entryPath);
|
|
162
|
+
if (typeof instance.name !== "string" ||
|
|
163
|
+
typeof instance.act !== "function") {
|
|
164
|
+
throw new Error(`Plugin at ${entry.path}: default export must be an intervention instance (name, act).`);
|
|
165
|
+
}
|
|
166
|
+
instances.push(instance);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
const factory = interventionRegistry[entry.name];
|
|
170
|
+
if (!factory) {
|
|
171
|
+
throw new Error(`Unknown intervention plugin name: "${entry.name}". Registered: ${Object.keys(interventionRegistry).join(", ")}`);
|
|
172
|
+
}
|
|
173
|
+
instances.push(factory(entry.config ?? {}));
|
|
180
174
|
}
|
|
181
|
-
instances.push(factory(entry.config ?? {}));
|
|
182
175
|
}
|
|
183
176
|
this.interventionPlugins = instances;
|
|
184
177
|
return instances;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginManager.js","sourceRoot":"","sources":["../../src/config/PluginManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"PluginManager.js","sourceRoot":"","sources":["../../src/config/PluginManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAQzC,OAAO,EACL,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;A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BACJ,CAAC;gBACD,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC3B,CAAC;iBAAM,CAAC;gBACN,MAAM,OAAO,GAAG,oBAAoB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBACjD,IAAI,CAAC,OAAO,EAAE,CAAC;oBACb,MAAM,IAAI,KAAK,CACb,sCACE,KAAK,CAAC,IACR,kBAAkB,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACjE,CAAC;gBACJ,CAAC;gBACD,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;QAED,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;QACrC,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { PluginManager, loadConfigFromPath } from "./PluginManager.js";
|
|
2
2
|
export type { PolicyPluginFactory } from "./PluginManager.js";
|
|
3
|
-
export type { GuardioConfig, GuardioServerConfig, PolicyPluginConfigEntry, InterventionPluginConfigEntry, PluginConfigEntry,
|
|
3
|
+
export type { GuardioConfig, GuardioServerConfig, PolicyPluginConfigEntry, InterventionPluginConfigEntry, PluginConfigEntry, } from "./types.js";
|
|
4
4
|
export type { InterventionPluginFactory } from "./PluginManager.js";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACvE,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,6BAA6B,EAC7B,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACvE,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,YAAY,EACV,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,6BAA6B,EAC7B,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/config/types.d.ts
CHANGED
|
@@ -1,44 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Policy plugin entry in guardio config.
|
|
3
|
+
* Use "path" for a custom plugin (directory with index.js/index.mjs; default export = instance).
|
|
3
4
|
*/
|
|
4
5
|
export interface PolicyPluginConfigEntry {
|
|
5
6
|
type: "policy";
|
|
6
7
|
name: string;
|
|
8
|
+
/** Directory to custom plugin (relative to config file or absolute). Must contain index.js or index.mjs with default export = policy instance. */
|
|
9
|
+
path?: string;
|
|
7
10
|
config?: Record<string, unknown>;
|
|
8
11
|
}
|
|
9
12
|
/**
|
|
10
13
|
* Intervention plugin entry in guardio config.
|
|
14
|
+
* Use "path" for a custom plugin (directory with index.js/index.mjs; default export = instance).
|
|
11
15
|
*/
|
|
12
16
|
export interface InterventionPluginConfigEntry {
|
|
13
17
|
type: "intervention";
|
|
14
18
|
name: string;
|
|
19
|
+
/** Directory to custom plugin (relative to config file or absolute). Must contain index.js or index.mjs with default export = intervention instance. */
|
|
20
|
+
path?: string;
|
|
15
21
|
config?: Record<string, unknown>;
|
|
16
22
|
}
|
|
17
23
|
/**
|
|
18
24
|
* Any plugin entry in guardio config.
|
|
19
25
|
*/
|
|
20
26
|
export type PluginConfigEntry = PolicyPluginConfigEntry | InterventionPluginConfigEntry;
|
|
21
|
-
/**
|
|
22
|
-
* Descriptor default export for a local plugin (plugins/<name>/index.ts or index.js).
|
|
23
|
-
* create() must return an instance implementing PolicyPluginInterface or InterventionPluginInterface.
|
|
24
|
-
*/
|
|
25
|
-
export interface PolicyPluginDescriptor {
|
|
26
|
-
type: "policy";
|
|
27
|
-
name: string;
|
|
28
|
-
create: (config: Record<string, unknown>) => {
|
|
29
|
-
name: string;
|
|
30
|
-
evaluate: (context: unknown) => "allowed" | "blocked" | "require_approval";
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
export interface InterventionPluginDescriptor {
|
|
34
|
-
type: "intervention";
|
|
35
|
-
name: string;
|
|
36
|
-
create: (config: Record<string, unknown>) => {
|
|
37
|
-
name: string;
|
|
38
|
-
act: (context: unknown) => void | boolean | Promise<void> | Promise<boolean>;
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export type LocalPluginDescriptor = PolicyPluginDescriptor | InterventionPluginDescriptor;
|
|
42
27
|
/**
|
|
43
28
|
* MCP server to proxy to (spawn command).
|
|
44
29
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,kJAAkJ;IAClJ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;;GAGG;AACH,MAAM,WAAW,6BAA6B;IAC5C,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,wJAAwJ;IACxJ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,uBAAuB,GACvB,6BAA6B,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,2EAA2E;IAC3E,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,OAAO,EAAE,iBAAiB,EAAE,CAAC;CAC9B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { GuardioCore } from "./core/index.js";
|
|
2
2
|
export type { GuardioCoreConfig, JsonRpcRequest, JsonRpcResponse, } from "./core/index.js";
|
|
3
3
|
export { PluginManager, loadConfigFromPath } from "./config/index.js";
|
|
4
|
-
export type { PolicyPluginFactory, InterventionPluginFactory, GuardioConfig, GuardioServerConfig, PolicyPluginConfigEntry, InterventionPluginConfigEntry, PluginConfigEntry,
|
|
4
|
+
export type { PolicyPluginFactory, InterventionPluginFactory, GuardioConfig, GuardioServerConfig, PolicyPluginConfigEntry, InterventionPluginConfigEntry, PluginConfigEntry, } from "./config/index.js";
|
|
5
5
|
export type { PolicyPluginInterface, NotificationPluginInterface, InterventionPluginInterface, InterventionResult, PolicyRequestContext, PolicyResult, InterventionRequestContext, } from "./interfaces/index.js";
|
|
6
6
|
export { DefaultPolicyPlugin, RegexPolicyPlugin, type DefaultPolicyPluginConfig, type RegexPolicyPluginConfig, type RegexPolicyRule, type RegexPolicyRuleResult, } from "./plugins/policy/index.js";
|
|
7
7
|
export { DefaultNotificationPlugin } from "./plugins/notification/index.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACtE,YAAY,EACV,mBAAmB,EACnB,yBAAyB,EACzB,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,6BAA6B,EAC7B,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACtE,YAAY,EACV,mBAAmB,EACnB,yBAAyB,EACzB,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,6BAA6B,EAC7B,iBAAiB,GAClB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EACV,qBAAqB,EACrB,2BAA2B,EAC3B,2BAA2B,EAC3B,kBAAkB,EAClB,oBAAoB,EACpB,YAAY,EACZ,0BAA0B,GAC3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,eAAe,EACpB,KAAK,qBAAqB,GAC3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACtB,KAAK,4BAA4B,GAClC,MAAM,iCAAiC,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAM9C,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAM9C,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAmBtE,OAAO,EACL,mBAAmB,EACnB,iBAAiB,GAKlB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EACL,yBAAyB,EACzB,sBAAsB,GAEvB,MAAM,iCAAiC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guardiojs/guardio",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Security layer for MCP servers and AI Agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -33,9 +33,6 @@
|
|
|
33
33
|
"pino": "^9.5.0",
|
|
34
34
|
"pino-pretty": "^13.0.0"
|
|
35
35
|
},
|
|
36
|
-
"optionalDependencies": {
|
|
37
|
-
"ts-node": "^10.9.2"
|
|
38
|
-
},
|
|
39
36
|
"devDependencies": {
|
|
40
37
|
"@types/node": "^22.0.0",
|
|
41
38
|
"tsx": "^4.19.0",
|