agentcheck-sdk 0.6.0 → 0.7.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/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export { DelegationDashboard } from "./dashboard";
7
7
  export { quickStart } from "./quickstart";
8
8
  export { templates } from "./templates";
9
9
  export { TelemetryPlugin } from "./telemetry";
10
+ export { ScopeEngine, buildScope } from "./scope-engine";
10
11
  export type { WebhookEvent } from "./webhook";
11
12
  export type { ScopeVerifier, DelegationProviderConfig } from "./provider";
12
13
  export type { GuardConfig } from "./guard";
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.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.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; } });
@@ -21,6 +21,9 @@ var templates_1 = require("./templates");
21
21
  Object.defineProperty(exports, "templates", { enumerable: true, get: function () { return templates_1.templates; } });
22
22
  var telemetry_1 = require("./telemetry");
23
23
  Object.defineProperty(exports, "TelemetryPlugin", { enumerable: true, get: function () { return telemetry_1.TelemetryPlugin; } });
24
+ var scope_engine_1 = require("./scope-engine");
25
+ Object.defineProperty(exports, "ScopeEngine", { enumerable: true, get: function () { return scope_engine_1.ScopeEngine; } });
26
+ Object.defineProperty(exports, "buildScope", { enumerable: true, get: function () { return scope_engine_1.buildScope; } });
24
27
  var errors_1 = require("./errors");
25
28
  Object.defineProperty(exports, "AgentCheckError", { enumerable: true, get: function () { return errors_1.AgentCheckError; } });
26
29
  Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_1.AuthenticationError; } });
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Scope Engine - Structured scope verification.
3
+ *
4
+ * Automatic action verification when scope is structured JSON.
5
+ * Free-text scope: customers verify themselves.
6
+ * Structured scope: this engine verifies automatically.
7
+ */
8
+ export interface StructuredScope {
9
+ allowed?: string[];
10
+ denied?: string[];
11
+ limits?: Record<string, {
12
+ max_amount?: number;
13
+ currency?: string;
14
+ max_count_per_day?: number;
15
+ }>;
16
+ schedule?: {
17
+ timezone?: string;
18
+ allowed_hours?: [number, number];
19
+ allowed_days?: number[];
20
+ };
21
+ require_approval_above?: {
22
+ amount: number;
23
+ };
24
+ }
25
+ export interface VerificationResult {
26
+ allowed: boolean;
27
+ reason: string;
28
+ details?: Record<string, unknown>;
29
+ }
30
+ export declare class ScopeEngine {
31
+ /** Parse scope string. Returns structured object or raw string. */
32
+ parse(scopeStr: string): StructuredScope | string;
33
+ /** Verify if an action is allowed by the scope. */
34
+ verify(scope: StructuredScope | string, action: string, opts?: {
35
+ amount?: number;
36
+ timestamp?: Date;
37
+ }): VerificationResult;
38
+ }
39
+ /** Build a structured scope JSON string. */
40
+ export declare function buildScope(opts: StructuredScope): string;
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ /**
3
+ * Scope Engine - Structured scope verification.
4
+ *
5
+ * Automatic action verification when scope is structured JSON.
6
+ * Free-text scope: customers verify themselves.
7
+ * Structured scope: this engine verifies automatically.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.ScopeEngine = void 0;
11
+ exports.buildScope = buildScope;
12
+ class ScopeEngine {
13
+ /** Parse scope string. Returns structured object or raw string. */
14
+ parse(scopeStr) {
15
+ try {
16
+ const parsed = JSON.parse(scopeStr);
17
+ if (typeof parsed === "object" && ("allowed" in parsed || "denied" in parsed)) {
18
+ return parsed;
19
+ }
20
+ }
21
+ catch { }
22
+ return scopeStr;
23
+ }
24
+ /** Verify if an action is allowed by the scope. */
25
+ verify(scope, action, opts = {}) {
26
+ if (typeof scope === "string") {
27
+ return {
28
+ allowed: true,
29
+ reason: "Free-text scope: automatic verification not available. Verify manually.",
30
+ details: { scope_type: "free-text" },
31
+ };
32
+ }
33
+ // Denied list (highest priority)
34
+ if (scope.denied?.includes(action)) {
35
+ return { allowed: false, reason: `Action '${action}' is in denied list` };
36
+ }
37
+ // Allowed list
38
+ if (scope.allowed?.length && !scope.allowed.includes(action)) {
39
+ return { allowed: false, reason: `Action '${action}' not in allowed list: ${scope.allowed.join(", ")}` };
40
+ }
41
+ // Amount limits
42
+ if (opts.amount !== undefined && scope.limits?.[action]) {
43
+ const limit = scope.limits[action];
44
+ if (limit.max_amount !== undefined && opts.amount > limit.max_amount) {
45
+ return {
46
+ allowed: false,
47
+ reason: `Amount ${opts.amount} exceeds limit ${limit.max_amount} ${limit.currency || ""}`,
48
+ details: { limit: limit.max_amount, actual: opts.amount },
49
+ };
50
+ }
51
+ }
52
+ // Escalation threshold
53
+ if (opts.amount !== undefined && scope.require_approval_above) {
54
+ if (opts.amount > scope.require_approval_above.amount) {
55
+ return {
56
+ allowed: false,
57
+ reason: `Amount ${opts.amount} requires additional approval (threshold: ${scope.require_approval_above.amount})`,
58
+ details: { threshold: scope.require_approval_above.amount, actual: opts.amount },
59
+ };
60
+ }
61
+ }
62
+ // Schedule check
63
+ if (opts.timestamp && scope.schedule) {
64
+ const hours = scope.schedule.allowed_hours;
65
+ if (hours && (opts.timestamp.getHours() < hours[0] || opts.timestamp.getHours() >= hours[1])) {
66
+ return { allowed: false, reason: `Action not allowed at hour ${opts.timestamp.getHours()} (allowed: ${hours[0]}-${hours[1]})` };
67
+ }
68
+ const days = scope.schedule.allowed_days;
69
+ const day = opts.timestamp.getDay() || 7; // Sunday=7
70
+ if (days && !days.includes(day)) {
71
+ return { allowed: false, reason: `Action not allowed on day ${day}` };
72
+ }
73
+ }
74
+ return { allowed: true, reason: "Action verified: within scope" };
75
+ }
76
+ }
77
+ exports.ScopeEngine = ScopeEngine;
78
+ /** Build a structured scope JSON string. */
79
+ function buildScope(opts) {
80
+ return JSON.stringify(opts);
81
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentcheck-sdk",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Record what your AI agent is allowed to do",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",