fastgrc-openclaw 1.0.5 → 1.0.6

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/index.d.mts CHANGED
@@ -1,3 +1,4 @@
1
+ declare function resolveApiKey(explicit?: string): string | undefined;
1
2
  interface FastGRCPluginOptions {
2
3
  /**
3
4
  * Your FastGRC API key (fgrc_k1_...).
@@ -75,4 +76,4 @@ declare function evaluate(payload: {
75
76
  }): Promise<EvaluateResponse | null>;
76
77
  declare function FastGRCPlugin(options: FastGRCPluginOptions): OpenClawPlugin;
77
78
 
78
- export { FastGRCApprovalRequiredError, FastGRCBlockedError, FastGRCPlugin, type FastGRCPluginOptions, evaluate };
79
+ export { FastGRCApprovalRequiredError, FastGRCBlockedError, FastGRCPlugin, type FastGRCPluginOptions, evaluate, resolveApiKey };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ declare function resolveApiKey(explicit?: string): string | undefined;
1
2
  interface FastGRCPluginOptions {
2
3
  /**
3
4
  * Your FastGRC API key (fgrc_k1_...).
@@ -75,4 +76,4 @@ declare function evaluate(payload: {
75
76
  }): Promise<EvaluateResponse | null>;
76
77
  declare function FastGRCPlugin(options: FastGRCPluginOptions): OpenClawPlugin;
77
78
 
78
- export { FastGRCApprovalRequiredError, FastGRCBlockedError, FastGRCPlugin, type FastGRCPluginOptions, evaluate };
79
+ export { FastGRCApprovalRequiredError, FastGRCBlockedError, FastGRCPlugin, type FastGRCPluginOptions, evaluate, resolveApiKey };
package/dist/index.js CHANGED
@@ -33,7 +33,8 @@ __export(index_exports, {
33
33
  FastGRCApprovalRequiredError: () => FastGRCApprovalRequiredError,
34
34
  FastGRCBlockedError: () => FastGRCBlockedError,
35
35
  FastGRCPlugin: () => FastGRCPlugin,
36
- evaluate: () => evaluate
36
+ evaluate: () => evaluate,
37
+ resolveApiKey: () => resolveApiKey
37
38
  });
38
39
  module.exports = __toCommonJS(index_exports);
39
40
  var fs = __toESM(require("fs"));
@@ -177,5 +178,6 @@ function FastGRCPlugin(options) {
177
178
  FastGRCApprovalRequiredError,
178
179
  FastGRCBlockedError,
179
180
  FastGRCPlugin,
180
- evaluate
181
+ evaluate,
182
+ resolveApiKey
181
183
  });
package/dist/index.mjs CHANGED
@@ -139,5 +139,6 @@ export {
139
139
  FastGRCApprovalRequiredError,
140
140
  FastGRCBlockedError,
141
141
  FastGRCPlugin,
142
- evaluate
142
+ evaluate,
143
+ resolveApiKey
143
144
  };
@@ -0,0 +1,22 @@
1
+ interface AgentContext {
2
+ id?: string;
3
+ name?: string;
4
+ type?: string;
5
+ [key: string]: unknown;
6
+ }
7
+ type BeforeToolCallResult = {
8
+ block: true;
9
+ blockReason: string;
10
+ } | {
11
+ requireApproval: {
12
+ timeoutBehavior: 'allow' | 'deny';
13
+ };
14
+ } | undefined;
15
+ declare const plugin: {
16
+ name: string;
17
+ hooks: {
18
+ before_tool_call(toolName: string, args: unknown, context: AgentContext): Promise<BeforeToolCallResult>;
19
+ };
20
+ };
21
+
22
+ export { plugin as default };
@@ -0,0 +1,22 @@
1
+ interface AgentContext {
2
+ id?: string;
3
+ name?: string;
4
+ type?: string;
5
+ [key: string]: unknown;
6
+ }
7
+ type BeforeToolCallResult = {
8
+ block: true;
9
+ blockReason: string;
10
+ } | {
11
+ requireApproval: {
12
+ timeoutBehavior: 'allow' | 'deny';
13
+ };
14
+ } | undefined;
15
+ declare const plugin: {
16
+ name: string;
17
+ hooks: {
18
+ before_tool_call(toolName: string, args: unknown, context: AgentContext): Promise<BeforeToolCallResult>;
19
+ };
20
+ };
21
+
22
+ export { plugin as default };
package/dist/plugin.js ADDED
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/plugin.ts
31
+ var plugin_exports = {};
32
+ __export(plugin_exports, {
33
+ default: () => plugin_default
34
+ });
35
+ module.exports = __toCommonJS(plugin_exports);
36
+
37
+ // src/index.ts
38
+ var fs = __toESM(require("fs"));
39
+ var os = __toESM(require("os"));
40
+ var path = __toESM(require("path"));
41
+ var DEFAULT_BASE_URL = "https://app.fastgrc.ai";
42
+ var DEFAULT_TIMEOUT_MS = 3e3;
43
+ function resolveApiKey(explicit) {
44
+ if (explicit) return explicit;
45
+ if (process.env.FASTGRC_API_KEY) return process.env.FASTGRC_API_KEY;
46
+ try {
47
+ const cfg = JSON.parse(fs.readFileSync(path.join(os.homedir(), ".fastgrc.json"), "utf8"));
48
+ if (cfg.apiKey) return cfg.apiKey;
49
+ } catch {
50
+ }
51
+ return void 0;
52
+ }
53
+ async function evaluate(payload) {
54
+ const {
55
+ toolName,
56
+ args,
57
+ agentId,
58
+ agentType,
59
+ agentName,
60
+ apiKey: apiKey2,
61
+ policyId,
62
+ baseUrl = DEFAULT_BASE_URL,
63
+ timeoutMs = DEFAULT_TIMEOUT_MS
64
+ } = payload;
65
+ const evalUrl = `${baseUrl.replace(/\/$/, "")}/api/v1/policy-router/evaluate`;
66
+ const content = `tool_name: ${toolName}
67
+ args: ${JSON.stringify(args)}`;
68
+ try {
69
+ const controller = new AbortController();
70
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
71
+ const res = await fetch(evalUrl, {
72
+ method: "POST",
73
+ headers: {
74
+ "Authorization": `Bearer ${apiKey2}`,
75
+ "Content-Type": "application/json"
76
+ },
77
+ body: JSON.stringify({
78
+ subjectContent: content,
79
+ subjectType: "tool_argument",
80
+ direction: "ingress",
81
+ agentId,
82
+ agentType,
83
+ agentName,
84
+ ...policyId ? { policyId } : {}
85
+ }),
86
+ signal: controller.signal
87
+ });
88
+ clearTimeout(timer);
89
+ if (!res.ok) {
90
+ console.warn(`[fastgrc] Evaluate returned ${res.status} \u2014 failing open`);
91
+ return null;
92
+ }
93
+ return await res.json();
94
+ } catch (err) {
95
+ const reason = err instanceof Error && err.name === "AbortError" ? "timeout" : String(err);
96
+ console.warn(`[fastgrc] Evaluate failed (${reason}) \u2014 failing open`);
97
+ return null;
98
+ }
99
+ }
100
+
101
+ // src/plugin.ts
102
+ var DEFAULT_BASE_URL2 = "https://app.fastgrc.ai";
103
+ var DEFAULT_TIMEOUT_MS2 = 3e3;
104
+ var apiKey = resolveApiKey();
105
+ if (!apiKey) {
106
+ console.warn(
107
+ "[fastgrc] No API key found \u2014 all tool calls will proceed unchecked.\n\n Run once to connect:\n fastgrc-hook set-key fgrc_k1_your_key_here\n\n Get a key at: https://app.fastgrc.ai/connect\n Manage keys at: https://app.fastgrc.ai/dashboard/settings"
108
+ );
109
+ }
110
+ var plugin = {
111
+ name: "fastgrc",
112
+ hooks: {
113
+ async before_tool_call(toolName, args, context) {
114
+ if (!apiKey) return void 0;
115
+ const result = await evaluate({
116
+ toolName,
117
+ args,
118
+ agentId: context.id,
119
+ agentType: context.type,
120
+ agentName: context.name,
121
+ apiKey,
122
+ baseUrl: DEFAULT_BASE_URL2,
123
+ timeoutMs: DEFAULT_TIMEOUT_MS2
124
+ });
125
+ if (!result) return void 0;
126
+ const { decision, reasoning, policyContext, reasonTags } = result;
127
+ const matchedRule = policyContext?.matchedRule ?? "policy rule";
128
+ if (decision === "block") {
129
+ return {
130
+ block: true,
131
+ blockReason: `[${matchedRule}] ${reasoning}`
132
+ };
133
+ }
134
+ if (decision === "require_approval") {
135
+ return {
136
+ requireApproval: { timeoutBehavior: "deny" }
137
+ };
138
+ }
139
+ if (Array.isArray(reasonTags) && reasonTags.includes("override_block_active")) {
140
+ const msg = policyContext?.matchedRule ? `[FastGRC] Observability mode \u2014 would have blocked: [${policyContext.matchedRule}] ${reasoning}` : `[FastGRC] Observability mode \u2014 would have blocked: ${reasoning}`;
141
+ console.warn(msg);
142
+ }
143
+ return void 0;
144
+ }
145
+ }
146
+ };
147
+ var plugin_default = plugin;
@@ -0,0 +1,114 @@
1
+ // src/index.ts
2
+ import * as fs from "fs";
3
+ import * as os from "os";
4
+ import * as path from "path";
5
+ var DEFAULT_BASE_URL = "https://app.fastgrc.ai";
6
+ var DEFAULT_TIMEOUT_MS = 3e3;
7
+ function resolveApiKey(explicit) {
8
+ if (explicit) return explicit;
9
+ if (process.env.FASTGRC_API_KEY) return process.env.FASTGRC_API_KEY;
10
+ try {
11
+ const cfg = JSON.parse(fs.readFileSync(path.join(os.homedir(), ".fastgrc.json"), "utf8"));
12
+ if (cfg.apiKey) return cfg.apiKey;
13
+ } catch {
14
+ }
15
+ return void 0;
16
+ }
17
+ async function evaluate(payload) {
18
+ const {
19
+ toolName,
20
+ args,
21
+ agentId,
22
+ agentType,
23
+ agentName,
24
+ apiKey: apiKey2,
25
+ policyId,
26
+ baseUrl = DEFAULT_BASE_URL,
27
+ timeoutMs = DEFAULT_TIMEOUT_MS
28
+ } = payload;
29
+ const evalUrl = `${baseUrl.replace(/\/$/, "")}/api/v1/policy-router/evaluate`;
30
+ const content = `tool_name: ${toolName}
31
+ args: ${JSON.stringify(args)}`;
32
+ try {
33
+ const controller = new AbortController();
34
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
35
+ const res = await fetch(evalUrl, {
36
+ method: "POST",
37
+ headers: {
38
+ "Authorization": `Bearer ${apiKey2}`,
39
+ "Content-Type": "application/json"
40
+ },
41
+ body: JSON.stringify({
42
+ subjectContent: content,
43
+ subjectType: "tool_argument",
44
+ direction: "ingress",
45
+ agentId,
46
+ agentType,
47
+ agentName,
48
+ ...policyId ? { policyId } : {}
49
+ }),
50
+ signal: controller.signal
51
+ });
52
+ clearTimeout(timer);
53
+ if (!res.ok) {
54
+ console.warn(`[fastgrc] Evaluate returned ${res.status} \u2014 failing open`);
55
+ return null;
56
+ }
57
+ return await res.json();
58
+ } catch (err) {
59
+ const reason = err instanceof Error && err.name === "AbortError" ? "timeout" : String(err);
60
+ console.warn(`[fastgrc] Evaluate failed (${reason}) \u2014 failing open`);
61
+ return null;
62
+ }
63
+ }
64
+
65
+ // src/plugin.ts
66
+ var DEFAULT_BASE_URL2 = "https://app.fastgrc.ai";
67
+ var DEFAULT_TIMEOUT_MS2 = 3e3;
68
+ var apiKey = resolveApiKey();
69
+ if (!apiKey) {
70
+ console.warn(
71
+ "[fastgrc] No API key found \u2014 all tool calls will proceed unchecked.\n\n Run once to connect:\n fastgrc-hook set-key fgrc_k1_your_key_here\n\n Get a key at: https://app.fastgrc.ai/connect\n Manage keys at: https://app.fastgrc.ai/dashboard/settings"
72
+ );
73
+ }
74
+ var plugin = {
75
+ name: "fastgrc",
76
+ hooks: {
77
+ async before_tool_call(toolName, args, context) {
78
+ if (!apiKey) return void 0;
79
+ const result = await evaluate({
80
+ toolName,
81
+ args,
82
+ agentId: context.id,
83
+ agentType: context.type,
84
+ agentName: context.name,
85
+ apiKey,
86
+ baseUrl: DEFAULT_BASE_URL2,
87
+ timeoutMs: DEFAULT_TIMEOUT_MS2
88
+ });
89
+ if (!result) return void 0;
90
+ const { decision, reasoning, policyContext, reasonTags } = result;
91
+ const matchedRule = policyContext?.matchedRule ?? "policy rule";
92
+ if (decision === "block") {
93
+ return {
94
+ block: true,
95
+ blockReason: `[${matchedRule}] ${reasoning}`
96
+ };
97
+ }
98
+ if (decision === "require_approval") {
99
+ return {
100
+ requireApproval: { timeoutBehavior: "deny" }
101
+ };
102
+ }
103
+ if (Array.isArray(reasonTags) && reasonTags.includes("override_block_active")) {
104
+ const msg = policyContext?.matchedRule ? `[FastGRC] Observability mode \u2014 would have blocked: [${policyContext.matchedRule}] ${reasoning}` : `[FastGRC] Observability mode \u2014 would have blocked: ${reasoning}`;
105
+ console.warn(msg);
106
+ }
107
+ return void 0;
108
+ }
109
+ }
110
+ };
111
+ var plugin_default = plugin;
112
+ export {
113
+ plugin_default as default
114
+ };
@@ -0,0 +1,6 @@
1
+ {
2
+ "id": "fastgrc",
3
+ "name": "FastGRC Policy Router",
4
+ "description": "Evaluate every tool call against your FastGRC compliance policy before it executes. Blocks violations, flags drift, builds an audit trail.",
5
+ "extensions": ["./dist/plugin.js"]
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastgrc-openclaw",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "FastGRC agent compliance plugin for OpenClaw — evaluates every tool call against your policy before it executes",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -10,14 +10,23 @@
10
10
  "types": "./dist/index.d.ts",
11
11
  "import": "./dist/index.mjs",
12
12
  "require": "./dist/index.js"
13
+ },
14
+ "./plugin": {
15
+ "types": "./dist/plugin.d.ts",
16
+ "import": "./dist/plugin.mjs",
17
+ "require": "./dist/plugin.js"
13
18
  }
14
19
  },
20
+ "openclaw": {
21
+ "extensions": ["./dist/plugin.js"]
22
+ },
15
23
  "bin": {
16
24
  "fastgrc-hook": "./dist/bin.js"
17
25
  },
18
26
  "files": [
19
27
  "dist",
20
- "README.md"
28
+ "README.md",
29
+ "openclaw.plugin.json"
21
30
  ],
22
31
  "scripts": {
23
32
  "build": "tsup && node -e \"require('fs').chmodSync('dist/bin.js', '755')\"",