agentcheck-sdk 0.9.0 → 1.0.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/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/dist/pipeline.d.ts +49 -0
- package/dist/pipeline.js +126 -0
- package/dist/safety.js +4 -2
- package/dist/scope-engine.js +2 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { TelemetryPlugin } from "./telemetry";
|
|
|
10
10
|
export { ScopeEngine, buildScope } from "./scope-engine";
|
|
11
11
|
export { SafetyStack, BudgetTracker, PatternMonitor, HumanEscalation } from "./safety";
|
|
12
12
|
export { SemanticVerifier, ClaudeProvider, OpenAIProvider } from "./semantic";
|
|
13
|
+
export { VerificationPipeline } from "./pipeline";
|
|
13
14
|
export type { LLMProvider, SemanticResult } from "./semantic";
|
|
14
15
|
export type { WebhookEvent } from "./webhook";
|
|
15
16
|
export type { ScopeVerifier, DelegationProviderConfig } from "./provider";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RateLimitError = exports.ValidationError = exports.NotFoundError = exports.AuthenticationError = exports.AgentCheckError = exports.OpenAIProvider = exports.ClaudeProvider = exports.SemanticVerifier = exports.HumanEscalation = exports.PatternMonitor = exports.BudgetTracker = exports.SafetyStack = exports.buildScope = exports.ScopeEngine = exports.TelemetryPlugin = exports.templates = exports.quickStart = exports.DelegationDashboard = exports.AgentToolChecker = exports.delegationGuard = exports.DelegationProvider = exports.WebhookHandler = exports.AgentCheckClient = void 0;
|
|
3
|
+
exports.RateLimitError = exports.ValidationError = exports.NotFoundError = exports.AuthenticationError = exports.AgentCheckError = exports.VerificationPipeline = exports.OpenAIProvider = exports.ClaudeProvider = exports.SemanticVerifier = exports.HumanEscalation = exports.PatternMonitor = exports.BudgetTracker = exports.SafetyStack = exports.buildScope = exports.ScopeEngine = exports.TelemetryPlugin = exports.templates = exports.quickStart = exports.DelegationDashboard = exports.AgentToolChecker = exports.delegationGuard = exports.DelegationProvider = exports.WebhookHandler = exports.AgentCheckClient = void 0;
|
|
4
4
|
// Individual commands (basic menu)
|
|
5
5
|
var client_1 = require("./client");
|
|
6
6
|
Object.defineProperty(exports, "AgentCheckClient", { enumerable: true, get: function () { return client_1.AgentCheckClient; } });
|
|
@@ -33,6 +33,8 @@ var semantic_1 = require("./semantic");
|
|
|
33
33
|
Object.defineProperty(exports, "SemanticVerifier", { enumerable: true, get: function () { return semantic_1.SemanticVerifier; } });
|
|
34
34
|
Object.defineProperty(exports, "ClaudeProvider", { enumerable: true, get: function () { return semantic_1.ClaudeProvider; } });
|
|
35
35
|
Object.defineProperty(exports, "OpenAIProvider", { enumerable: true, get: function () { return semantic_1.OpenAIProvider; } });
|
|
36
|
+
var pipeline_1 = require("./pipeline");
|
|
37
|
+
Object.defineProperty(exports, "VerificationPipeline", { enumerable: true, get: function () { return pipeline_1.VerificationPipeline; } });
|
|
36
38
|
var errors_1 = require("./errors");
|
|
37
39
|
Object.defineProperty(exports, "AgentCheckError", { enumerable: true, get: function () { return errors_1.AgentCheckError; } });
|
|
38
40
|
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_1.AuthenticationError; } });
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verification Pipeline - Complete delegation verification flow.
|
|
3
|
+
*
|
|
4
|
+
* Connects all modules into a single chain:
|
|
5
|
+
* delegation check -> scope -> semantic(LLM) -> budget -> pattern -> human -> execute -> log
|
|
6
|
+
*/
|
|
7
|
+
import { AgentCheckClient } from "./client";
|
|
8
|
+
import { BudgetTracker, HumanEscalation, PatternMonitor } from "./safety";
|
|
9
|
+
import { LLMProvider } from "./semantic";
|
|
10
|
+
export interface CheckResult {
|
|
11
|
+
layer: string;
|
|
12
|
+
passed: boolean;
|
|
13
|
+
reason: string;
|
|
14
|
+
durationMs: number;
|
|
15
|
+
}
|
|
16
|
+
export interface PipelineResult {
|
|
17
|
+
allowed: boolean;
|
|
18
|
+
executed: boolean;
|
|
19
|
+
action: string;
|
|
20
|
+
agent: string;
|
|
21
|
+
checks: CheckResult[];
|
|
22
|
+
executionResult?: unknown;
|
|
23
|
+
error?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface PipelineConfig {
|
|
26
|
+
llm?: LLMProvider;
|
|
27
|
+
budget?: BudgetTracker;
|
|
28
|
+
pattern?: PatternMonitor;
|
|
29
|
+
escalation?: HumanEscalation;
|
|
30
|
+
semanticThreshold?: number;
|
|
31
|
+
}
|
|
32
|
+
export declare class VerificationPipeline {
|
|
33
|
+
private client;
|
|
34
|
+
private scopeEngine;
|
|
35
|
+
private semantic?;
|
|
36
|
+
private budget?;
|
|
37
|
+
private pattern;
|
|
38
|
+
private escalation?;
|
|
39
|
+
constructor(client: AgentCheckClient, config?: PipelineConfig);
|
|
40
|
+
verify(agent: string, action: string, opts?: {
|
|
41
|
+
amount?: number;
|
|
42
|
+
context?: Record<string, unknown>;
|
|
43
|
+
}): Promise<PipelineResult>;
|
|
44
|
+
verifyAndExecute<T>(agent: string, action: string, executeFn: () => Promise<T>, opts?: {
|
|
45
|
+
amount?: number;
|
|
46
|
+
context?: Record<string, unknown>;
|
|
47
|
+
}): Promise<PipelineResult>;
|
|
48
|
+
private logExecution;
|
|
49
|
+
}
|
package/dist/pipeline.js
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Verification Pipeline - Complete delegation verification flow.
|
|
4
|
+
*
|
|
5
|
+
* Connects all modules into a single chain:
|
|
6
|
+
* delegation check -> scope -> semantic(LLM) -> budget -> pattern -> human -> execute -> log
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.VerificationPipeline = void 0;
|
|
10
|
+
const safety_1 = require("./safety");
|
|
11
|
+
const scope_engine_1 = require("./scope-engine");
|
|
12
|
+
const semantic_1 = require("./semantic");
|
|
13
|
+
class VerificationPipeline {
|
|
14
|
+
constructor(client, config = {}) {
|
|
15
|
+
this.client = client;
|
|
16
|
+
this.scopeEngine = new scope_engine_1.ScopeEngine();
|
|
17
|
+
this.semantic = config.llm ? new semantic_1.SemanticVerifier(config.llm) : undefined;
|
|
18
|
+
this.budget = config.budget;
|
|
19
|
+
this.pattern = config.pattern || new safety_1.PatternMonitor();
|
|
20
|
+
this.escalation = config.escalation;
|
|
21
|
+
}
|
|
22
|
+
async verify(agent, action, opts = {}) {
|
|
23
|
+
const checks = [];
|
|
24
|
+
const amount = opts.amount || 0;
|
|
25
|
+
// Layer 1: Delegation exists
|
|
26
|
+
let agreement;
|
|
27
|
+
let t = Date.now();
|
|
28
|
+
try {
|
|
29
|
+
const list = await this.client.list({ agent, status: "approved" });
|
|
30
|
+
if (!list.records.length) {
|
|
31
|
+
checks.push({ layer: "delegation_check", passed: false, reason: "No active delegation found", durationMs: Date.now() - t });
|
|
32
|
+
return { allowed: false, executed: false, action, agent, checks, error: "No active delegation" };
|
|
33
|
+
}
|
|
34
|
+
agreement = list.records[0];
|
|
35
|
+
checks.push({ layer: "delegation_check", passed: true, reason: `Active delegation: ${agreement.id}`, durationMs: Date.now() - t });
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
checks.push({ layer: "delegation_check", passed: false, reason: `Server error: ${e.message}`, durationMs: Date.now() - t });
|
|
39
|
+
return { allowed: false, executed: false, action, agent, checks, error: e.message };
|
|
40
|
+
}
|
|
41
|
+
// Layer 2: Scope rules
|
|
42
|
+
t = Date.now();
|
|
43
|
+
const scope = this.scopeEngine.parse(agreement.scope);
|
|
44
|
+
const scopeResult = this.scopeEngine.verify(scope, action, { amount });
|
|
45
|
+
checks.push({ layer: "scope_engine", passed: scopeResult.allowed, reason: scopeResult.reason, durationMs: Date.now() - t });
|
|
46
|
+
if (!scopeResult.allowed) {
|
|
47
|
+
return { allowed: false, executed: false, action, agent, checks, error: scopeResult.reason };
|
|
48
|
+
}
|
|
49
|
+
// Layer 3: Semantic (LLM) - only for free-text scope
|
|
50
|
+
if (this.semantic && typeof scope === "string") {
|
|
51
|
+
t = Date.now();
|
|
52
|
+
const sem = await this.semantic.verify(agreement.scope, action, opts.context || { amount });
|
|
53
|
+
const isOk = sem.assessment !== "denied";
|
|
54
|
+
checks.push({
|
|
55
|
+
layer: "semantic_verifier",
|
|
56
|
+
passed: isOk,
|
|
57
|
+
reason: `[${sem.assessment}] ${sem.reasoning} (confidence: ${(sem.confidence * 100).toFixed(0)}%)`,
|
|
58
|
+
durationMs: Date.now() - t,
|
|
59
|
+
});
|
|
60
|
+
if (sem.assessment === "denied") {
|
|
61
|
+
return { allowed: false, executed: false, action, agent, checks, error: sem.reasoning };
|
|
62
|
+
}
|
|
63
|
+
if (sem.assessment === "suspicious") {
|
|
64
|
+
checks.push({ layer: "semantic_flag", passed: true, reason: "LLM flagged suspicious - recommend human review", durationMs: 0 });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Layer 4: Budget
|
|
68
|
+
if (this.budget) {
|
|
69
|
+
t = Date.now();
|
|
70
|
+
const br = this.budget.check(action, amount);
|
|
71
|
+
checks.push({ layer: "budget_tracker", passed: br.allowed, reason: br.reason, durationMs: Date.now() - t });
|
|
72
|
+
if (!br.allowed) {
|
|
73
|
+
return { allowed: false, executed: false, action, agent, checks, error: br.reason };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// Layer 5: Pattern
|
|
77
|
+
t = Date.now();
|
|
78
|
+
const alerts = this.pattern.check(action, amount);
|
|
79
|
+
const hasCritical = alerts.some(a => a.level === "critical");
|
|
80
|
+
const patternMsg = alerts.length ? alerts.map(a => a.message).join("; ") : "Normal pattern";
|
|
81
|
+
checks.push({ layer: "pattern_monitor", passed: !hasCritical, reason: patternMsg, durationMs: Date.now() - t });
|
|
82
|
+
if (hasCritical) {
|
|
83
|
+
return { allowed: false, executed: false, action, agent, checks, error: alerts[0].message };
|
|
84
|
+
}
|
|
85
|
+
// Layer 6: Human escalation
|
|
86
|
+
if (this.escalation) {
|
|
87
|
+
t = Date.now();
|
|
88
|
+
const er = this.escalation.check(action, amount);
|
|
89
|
+
checks.push({ layer: "human_escalation", passed: er.allowed, reason: er.reason, durationMs: Date.now() - t });
|
|
90
|
+
if (!er.allowed) {
|
|
91
|
+
return { allowed: false, executed: false, action, agent, checks, error: er.reason };
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return { allowed: true, executed: false, action, agent, checks };
|
|
95
|
+
}
|
|
96
|
+
async verifyAndExecute(agent, action, executeFn, opts = {}) {
|
|
97
|
+
const result = await this.verify(agent, action, opts);
|
|
98
|
+
if (!result.allowed) {
|
|
99
|
+
this.logExecution(agent, action, opts.amount || 0, "blocked", result.error);
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
result.executionResult = await executeFn();
|
|
104
|
+
result.executed = true;
|
|
105
|
+
result.checks.push({ layer: "execution", passed: true, reason: "Executed successfully", durationMs: 0 });
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
result.executed = false;
|
|
109
|
+
result.error = e.message;
|
|
110
|
+
result.checks.push({ layer: "execution", passed: false, reason: `Failed: ${e.message}`, durationMs: 0 });
|
|
111
|
+
}
|
|
112
|
+
this.budget?.recordUsage(action, opts.amount || 0);
|
|
113
|
+
this.pattern.record(action, opts.amount || 0);
|
|
114
|
+
this.logExecution(agent, action, opts.amount || 0, result.executed ? "success" : "failed", result.error);
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
async logExecution(agent, action, amount, outcome, error) {
|
|
118
|
+
try {
|
|
119
|
+
await this.client.request("POST", "/api/v1/executions", {
|
|
120
|
+
agent, action, result: outcome, metadata: { amount, error },
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
catch { }
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
exports.VerificationPipeline = VerificationPipeline;
|
package/dist/safety.js
CHANGED
|
@@ -26,13 +26,13 @@ class BudgetTracker {
|
|
|
26
26
|
if (this.dailyCountLimit && (this.dailyCounts[dayKey] || 0) >= this.dailyCountLimit) {
|
|
27
27
|
return { allowed: false, reason: `Daily action count limit reached (${this.dailyCountLimit})` };
|
|
28
28
|
}
|
|
29
|
-
if (this.dailyLimit && amount > 0) {
|
|
29
|
+
if (this.dailyLimit !== undefined && amount > 0) {
|
|
30
30
|
const projected = (this.dailyTotals[dayKey] || 0) + amount;
|
|
31
31
|
if (projected > this.dailyLimit) {
|
|
32
32
|
return { allowed: false, reason: `Daily budget exceeded: ${projected} > ${this.dailyLimit}` };
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
if (this.monthlyLimit && amount > 0) {
|
|
35
|
+
if (this.monthlyLimit !== undefined && amount > 0) {
|
|
36
36
|
const projected = (this.monthlyTotals[monthKey] || 0) + amount;
|
|
37
37
|
if (projected > this.monthlyLimit) {
|
|
38
38
|
return { allowed: false, reason: `Monthly budget exceeded: ${projected} > ${this.monthlyLimit}` };
|
|
@@ -41,6 +41,8 @@ class BudgetTracker {
|
|
|
41
41
|
return { allowed: true, reason: "Within budget" };
|
|
42
42
|
}
|
|
43
43
|
recordUsage(action, amount = 0) {
|
|
44
|
+
if (amount < 0)
|
|
45
|
+
return; // Prevent budget gaming via negative amounts
|
|
44
46
|
const dayKey = new Date().toISOString().slice(0, 10);
|
|
45
47
|
const monthKey = dayKey.slice(0, 7);
|
|
46
48
|
this.dailyTotals[dayKey] = (this.dailyTotals[dayKey] || 0) + amount;
|
package/dist/scope-engine.js
CHANGED
|
@@ -34,8 +34,8 @@ class ScopeEngine {
|
|
|
34
34
|
if (scope.denied?.includes(action)) {
|
|
35
35
|
return { allowed: false, reason: `Action '${action}' is in denied list` };
|
|
36
36
|
}
|
|
37
|
-
// Allowed list
|
|
38
|
-
if (scope.allowed
|
|
37
|
+
// Allowed list (empty array = nothing allowed, undefined = no whitelist)
|
|
38
|
+
if (scope.allowed !== undefined && !scope.allowed.includes(action)) {
|
|
39
39
|
return { allowed: false, reason: `Action '${action}' not in allowed list: ${scope.allowed.join(", ")}` };
|
|
40
40
|
}
|
|
41
41
|
// Amount limits
|