agentcheck-sdk 1.0.1 → 2.0.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/cache.d.ts +78 -0
- package/dist/cache.js +155 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +24 -1
- package/dist/integrations/autogen.d.ts +50 -0
- package/dist/integrations/autogen.js +93 -0
- package/dist/integrations/crewai.d.ts +49 -0
- package/dist/integrations/crewai.js +107 -0
- package/dist/integrations/index.d.ts +8 -0
- package/dist/integrations/index.js +17 -0
- package/dist/integrations/langchain.d.ts +63 -0
- package/dist/integrations/langchain.js +104 -0
- package/dist/pipeline.d.ts +24 -0
- package/dist/pipeline.js +84 -48
- package/dist/pqc/dsse.d.ts +47 -0
- package/dist/pqc/dsse.js +113 -0
- package/dist/pqc/index.d.ts +11 -0
- package/dist/pqc/index.js +18 -0
- package/dist/pqc/signer.d.ts +44 -0
- package/dist/pqc/signer.js +97 -0
- package/dist/pqc/verifier.d.ts +49 -0
- package/dist/pqc/verifier.js +93 -0
- package/dist/router.d.ts +78 -0
- package/dist/router.js +102 -0
- package/dist/safety.d.ts +66 -7
- package/dist/safety.js +85 -1
- package/dist/semantic.d.ts +14 -2
- package/dist/semantic.js +22 -10
- package/dist/templates.d.ts +130 -1
- package/dist/templates.js +275 -12
- package/dist/trust.d.ts +97 -0
- package/dist/trust.js +146 -0
- package/package.json +2 -2
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LRU Cache with TTL support.
|
|
3
|
+
*
|
|
4
|
+
* O(1) get/put/evict via Map (insertion-order preserved in V8) plus a
|
|
5
|
+
* doubly-linked list for O(1) head/tail manipulation.
|
|
6
|
+
* No threading concerns in single-threaded JS; Map operations are synchronous.
|
|
7
|
+
*
|
|
8
|
+
* @template V Value type stored in the cache.
|
|
9
|
+
*/
|
|
10
|
+
export interface CacheStats {
|
|
11
|
+
hits: number;
|
|
12
|
+
misses: number;
|
|
13
|
+
evictions: number;
|
|
14
|
+
size: number;
|
|
15
|
+
hitRate: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* LRU Cache with optional per-entry TTL.
|
|
19
|
+
*
|
|
20
|
+
* Uses a doubly-linked list (head = LRU, tail = MRU) combined with a Map
|
|
21
|
+
* for O(1) lookup, insertion, and eviction.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* const cache = new LRUCache<string>(500, 60_000);
|
|
26
|
+
* cache.put("key", "value");
|
|
27
|
+
* const v = cache.get("key"); // "value" or undefined if expired/missing
|
|
28
|
+
* console.log(cache.stats()); // { hits, misses, evictions, size, hitRate }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class LRUCache<V> {
|
|
32
|
+
private readonly maxSize;
|
|
33
|
+
private readonly defaultTtlMs;
|
|
34
|
+
private readonly map;
|
|
35
|
+
private readonly head;
|
|
36
|
+
private readonly tail;
|
|
37
|
+
private hitCount;
|
|
38
|
+
private missCount;
|
|
39
|
+
private evictionCount;
|
|
40
|
+
/**
|
|
41
|
+
* @param maxSize Maximum entries before LRU eviction. Must be >= 1.
|
|
42
|
+
* @param ttlMs Default TTL in milliseconds. Pass 0 for no expiry.
|
|
43
|
+
*/
|
|
44
|
+
constructor(maxSize?: number, ttlMs?: number);
|
|
45
|
+
/**
|
|
46
|
+
* Retrieve a cached value.
|
|
47
|
+
*
|
|
48
|
+
* Returns `undefined` if the key is missing or the entry has expired.
|
|
49
|
+
* An expired entry is removed lazily on access.
|
|
50
|
+
*
|
|
51
|
+
* @param key Cache key.
|
|
52
|
+
*/
|
|
53
|
+
get(key: string): V | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* Insert or update a cache entry.
|
|
56
|
+
*
|
|
57
|
+
* If the cache is full, the least-recently-used entry is evicted.
|
|
58
|
+
*
|
|
59
|
+
* @param key Cache key.
|
|
60
|
+
* @param value Value to store.
|
|
61
|
+
* @param ttlMs Per-entry TTL override in milliseconds.
|
|
62
|
+
* Uses the instance default when undefined.
|
|
63
|
+
* Pass 0 to store without expiry.
|
|
64
|
+
*/
|
|
65
|
+
put(key: string, value: V, ttlMs?: number): void;
|
|
66
|
+
/**
|
|
67
|
+
* Return cache performance statistics.
|
|
68
|
+
*/
|
|
69
|
+
stats(): CacheStats;
|
|
70
|
+
/**
|
|
71
|
+
* Remove all entries and reset statistics.
|
|
72
|
+
*/
|
|
73
|
+
clear(): void;
|
|
74
|
+
/** Current number of entries in the cache. */
|
|
75
|
+
get size(): number;
|
|
76
|
+
private removeNode;
|
|
77
|
+
private insertBeforeTail;
|
|
78
|
+
}
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* LRU Cache with TTL support.
|
|
4
|
+
*
|
|
5
|
+
* O(1) get/put/evict via Map (insertion-order preserved in V8) plus a
|
|
6
|
+
* doubly-linked list for O(1) head/tail manipulation.
|
|
7
|
+
* No threading concerns in single-threaded JS; Map operations are synchronous.
|
|
8
|
+
*
|
|
9
|
+
* @template V Value type stored in the cache.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LRUCache = void 0;
|
|
13
|
+
/**
|
|
14
|
+
* LRU Cache with optional per-entry TTL.
|
|
15
|
+
*
|
|
16
|
+
* Uses a doubly-linked list (head = LRU, tail = MRU) combined with a Map
|
|
17
|
+
* for O(1) lookup, insertion, and eviction.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const cache = new LRUCache<string>(500, 60_000);
|
|
22
|
+
* cache.put("key", "value");
|
|
23
|
+
* const v = cache.get("key"); // "value" or undefined if expired/missing
|
|
24
|
+
* console.log(cache.stats()); // { hits, misses, evictions, size, hitRate }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
class LRUCache {
|
|
28
|
+
/**
|
|
29
|
+
* @param maxSize Maximum entries before LRU eviction. Must be >= 1.
|
|
30
|
+
* @param ttlMs Default TTL in milliseconds. Pass 0 for no expiry.
|
|
31
|
+
*/
|
|
32
|
+
constructor(maxSize = 1000, ttlMs = 300000) {
|
|
33
|
+
this.map = new Map();
|
|
34
|
+
this.hitCount = 0;
|
|
35
|
+
this.missCount = 0;
|
|
36
|
+
this.evictionCount = 0;
|
|
37
|
+
if (maxSize < 1)
|
|
38
|
+
throw new RangeError("maxSize must be >= 1");
|
|
39
|
+
this.maxSize = maxSize;
|
|
40
|
+
this.defaultTtlMs = ttlMs;
|
|
41
|
+
// Sentinel nodes simplify boundary conditions
|
|
42
|
+
this.head = { key: "", value: null, expireAt: 0, prev: null, next: null };
|
|
43
|
+
this.tail = { key: "", value: null, expireAt: 0, prev: null, next: null };
|
|
44
|
+
this.head.next = this.tail;
|
|
45
|
+
this.tail.prev = this.head;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Retrieve a cached value.
|
|
49
|
+
*
|
|
50
|
+
* Returns `undefined` if the key is missing or the entry has expired.
|
|
51
|
+
* An expired entry is removed lazily on access.
|
|
52
|
+
*
|
|
53
|
+
* @param key Cache key.
|
|
54
|
+
*/
|
|
55
|
+
get(key) {
|
|
56
|
+
const node = this.map.get(key);
|
|
57
|
+
if (!node) {
|
|
58
|
+
this.missCount++;
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
if (node.expireAt > 0 && Date.now() > node.expireAt) {
|
|
62
|
+
this.removeNode(node);
|
|
63
|
+
this.map.delete(key);
|
|
64
|
+
this.missCount++;
|
|
65
|
+
this.evictionCount++;
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
// Promote to MRU
|
|
69
|
+
this.removeNode(node);
|
|
70
|
+
this.insertBeforeTail(node);
|
|
71
|
+
this.hitCount++;
|
|
72
|
+
return node.value;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Insert or update a cache entry.
|
|
76
|
+
*
|
|
77
|
+
* If the cache is full, the least-recently-used entry is evicted.
|
|
78
|
+
*
|
|
79
|
+
* @param key Cache key.
|
|
80
|
+
* @param value Value to store.
|
|
81
|
+
* @param ttlMs Per-entry TTL override in milliseconds.
|
|
82
|
+
* Uses the instance default when undefined.
|
|
83
|
+
* Pass 0 to store without expiry.
|
|
84
|
+
*/
|
|
85
|
+
put(key, value, ttlMs) {
|
|
86
|
+
const effectiveTtl = ttlMs !== undefined ? ttlMs : this.defaultTtlMs;
|
|
87
|
+
const expireAt = effectiveTtl > 0 ? Date.now() + effectiveTtl : 0;
|
|
88
|
+
const existing = this.map.get(key);
|
|
89
|
+
if (existing) {
|
|
90
|
+
existing.value = value;
|
|
91
|
+
existing.expireAt = expireAt;
|
|
92
|
+
this.removeNode(existing);
|
|
93
|
+
this.insertBeforeTail(existing);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (this.map.size >= this.maxSize) {
|
|
97
|
+
// Evict LRU: node immediately after head sentinel
|
|
98
|
+
const lru = this.head.next;
|
|
99
|
+
this.removeNode(lru);
|
|
100
|
+
this.map.delete(lru.key);
|
|
101
|
+
this.evictionCount++;
|
|
102
|
+
}
|
|
103
|
+
const node = { key, value, expireAt, prev: null, next: null };
|
|
104
|
+
this.map.set(key, node);
|
|
105
|
+
this.insertBeforeTail(node);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Return cache performance statistics.
|
|
109
|
+
*/
|
|
110
|
+
stats() {
|
|
111
|
+
const total = this.hitCount + this.missCount;
|
|
112
|
+
return {
|
|
113
|
+
hits: this.hitCount,
|
|
114
|
+
misses: this.missCount,
|
|
115
|
+
evictions: this.evictionCount,
|
|
116
|
+
size: this.map.size,
|
|
117
|
+
hitRate: total > 0 ? this.hitCount / total : 0,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Remove all entries and reset statistics.
|
|
122
|
+
*/
|
|
123
|
+
clear() {
|
|
124
|
+
this.map.clear();
|
|
125
|
+
this.head.next = this.tail;
|
|
126
|
+
this.tail.prev = this.head;
|
|
127
|
+
this.hitCount = 0;
|
|
128
|
+
this.missCount = 0;
|
|
129
|
+
this.evictionCount = 0;
|
|
130
|
+
}
|
|
131
|
+
/** Current number of entries in the cache. */
|
|
132
|
+
get size() {
|
|
133
|
+
return this.map.size;
|
|
134
|
+
}
|
|
135
|
+
// ------------------------------------------------------------------
|
|
136
|
+
// Doubly-linked list helpers
|
|
137
|
+
// ------------------------------------------------------------------
|
|
138
|
+
removeNode(node) {
|
|
139
|
+
const { prev, next } = node;
|
|
140
|
+
if (prev)
|
|
141
|
+
prev.next = next;
|
|
142
|
+
if (next)
|
|
143
|
+
next.prev = prev;
|
|
144
|
+
node.prev = null;
|
|
145
|
+
node.next = null;
|
|
146
|
+
}
|
|
147
|
+
insertBeforeTail(node) {
|
|
148
|
+
const prev = this.tail.prev;
|
|
149
|
+
prev.next = node;
|
|
150
|
+
node.prev = prev;
|
|
151
|
+
node.next = this.tail;
|
|
152
|
+
this.tail.prev = node;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
exports.LRUCache = LRUCache;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,20 @@ export { ScopeEngine, buildScope } from "./scope-engine";
|
|
|
11
11
|
export { SafetyStack, BudgetTracker, PatternMonitor, HumanEscalation } from "./safety";
|
|
12
12
|
export { SemanticVerifier, ClaudeProvider, OpenAIProvider } from "./semantic";
|
|
13
13
|
export { VerificationPipeline } from "./pipeline";
|
|
14
|
+
export { LRUCache } from "./cache";
|
|
15
|
+
export { TrustEngine } from "./trust";
|
|
16
|
+
export { LayerRouter } from "./router";
|
|
17
|
+
export type { TrustScore, OutcomeDetails } from "./trust";
|
|
18
|
+
export type { RoutingRules, LayerRouterConfig } from "./router";
|
|
19
|
+
export type { SafetyStackConfig, CheckOpts } from "./safety";
|
|
14
20
|
export type { LLMProvider, SemanticResult } from "./semantic";
|
|
21
|
+
export type { CacheStats } from "./cache";
|
|
22
|
+
export type { PipelineConfig, PipelineResult, CheckResult } from "./pipeline";
|
|
23
|
+
export { DsseEnvelope, DsseSignature, PqcVerifier, PqcSigner, DSSE_PAYLOAD_TYPE } from "./pqc";
|
|
24
|
+
export type { DsseEnvelopeData, DsseSignatureData } from "./pqc";
|
|
25
|
+
export { AgentCheckToolkit, AgentCheckCallbackHandler } from "./integrations/langchain";
|
|
26
|
+
export { wrapCrewTools, AgentCheckCrewCallback } from "./integrations/crewai";
|
|
27
|
+
export { functionGuard, AgentCheckAssistant } from "./integrations/autogen";
|
|
15
28
|
export type { WebhookEvent } from "./webhook";
|
|
16
29
|
export type { ScopeVerifier, DelegationProviderConfig } from "./provider";
|
|
17
30
|
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.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;
|
|
3
|
+
exports.RateLimitError = exports.ValidationError = exports.NotFoundError = exports.AuthenticationError = exports.AgentCheckError = exports.AgentCheckAssistant = exports.functionGuard = exports.AgentCheckCrewCallback = exports.wrapCrewTools = exports.AgentCheckCallbackHandler = exports.AgentCheckToolkit = exports.DSSE_PAYLOAD_TYPE = exports.PqcSigner = exports.PqcVerifier = exports.DsseSignature = exports.DsseEnvelope = exports.LayerRouter = exports.TrustEngine = exports.LRUCache = 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; } });
|
|
@@ -35,6 +35,29 @@ Object.defineProperty(exports, "ClaudeProvider", { enumerable: true, get: functi
|
|
|
35
35
|
Object.defineProperty(exports, "OpenAIProvider", { enumerable: true, get: function () { return semantic_1.OpenAIProvider; } });
|
|
36
36
|
var pipeline_1 = require("./pipeline");
|
|
37
37
|
Object.defineProperty(exports, "VerificationPipeline", { enumerable: true, get: function () { return pipeline_1.VerificationPipeline; } });
|
|
38
|
+
var cache_1 = require("./cache");
|
|
39
|
+
Object.defineProperty(exports, "LRUCache", { enumerable: true, get: function () { return cache_1.LRUCache; } });
|
|
40
|
+
var trust_1 = require("./trust");
|
|
41
|
+
Object.defineProperty(exports, "TrustEngine", { enumerable: true, get: function () { return trust_1.TrustEngine; } });
|
|
42
|
+
var router_1 = require("./router");
|
|
43
|
+
Object.defineProperty(exports, "LayerRouter", { enumerable: true, get: function () { return router_1.LayerRouter; } });
|
|
44
|
+
// PQC (Post-Quantum Cryptography) module
|
|
45
|
+
var pqc_1 = require("./pqc");
|
|
46
|
+
Object.defineProperty(exports, "DsseEnvelope", { enumerable: true, get: function () { return pqc_1.DsseEnvelope; } });
|
|
47
|
+
Object.defineProperty(exports, "DsseSignature", { enumerable: true, get: function () { return pqc_1.DsseSignature; } });
|
|
48
|
+
Object.defineProperty(exports, "PqcVerifier", { enumerable: true, get: function () { return pqc_1.PqcVerifier; } });
|
|
49
|
+
Object.defineProperty(exports, "PqcSigner", { enumerable: true, get: function () { return pqc_1.PqcSigner; } });
|
|
50
|
+
Object.defineProperty(exports, "DSSE_PAYLOAD_TYPE", { enumerable: true, get: function () { return pqc_1.DSSE_PAYLOAD_TYPE; } });
|
|
51
|
+
// Framework integrations
|
|
52
|
+
var langchain_2 = require("./integrations/langchain");
|
|
53
|
+
Object.defineProperty(exports, "AgentCheckToolkit", { enumerable: true, get: function () { return langchain_2.AgentCheckToolkit; } });
|
|
54
|
+
Object.defineProperty(exports, "AgentCheckCallbackHandler", { enumerable: true, get: function () { return langchain_2.AgentCheckCallbackHandler; } });
|
|
55
|
+
var crewai_1 = require("./integrations/crewai");
|
|
56
|
+
Object.defineProperty(exports, "wrapCrewTools", { enumerable: true, get: function () { return crewai_1.wrapCrewTools; } });
|
|
57
|
+
Object.defineProperty(exports, "AgentCheckCrewCallback", { enumerable: true, get: function () { return crewai_1.AgentCheckCrewCallback; } });
|
|
58
|
+
var autogen_1 = require("./integrations/autogen");
|
|
59
|
+
Object.defineProperty(exports, "functionGuard", { enumerable: true, get: function () { return autogen_1.functionGuard; } });
|
|
60
|
+
Object.defineProperty(exports, "AgentCheckAssistant", { enumerable: true, get: function () { return autogen_1.AgentCheckAssistant; } });
|
|
38
61
|
var errors_1 = require("./errors");
|
|
39
62
|
Object.defineProperty(exports, "AgentCheckError", { enumerable: true, get: function () { return errors_1.AgentCheckError; } });
|
|
40
63
|
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return errors_1.AuthenticationError; } });
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AutoGen integration for AgentCheck (TypeScript).
|
|
3
|
+
*
|
|
4
|
+
* Provides a decorator-style function guard for AutoGen function calls and
|
|
5
|
+
* a wrapper class around AssistantAgent with delegation governance.
|
|
6
|
+
*
|
|
7
|
+
* Note: AutoGen's TypeScript support is limited. This module uses duck-typing.
|
|
8
|
+
*
|
|
9
|
+
* Tier: Molecule (be-mol-agentcheck-autogen-ts) - composes Client + AutoGen pattern.
|
|
10
|
+
*/
|
|
11
|
+
import type { AgentCheckClient } from "../client";
|
|
12
|
+
/** Minimal AutoGen AssistantAgent shape. */
|
|
13
|
+
interface AutoGenAssistant {
|
|
14
|
+
initiate_chat: (...args: unknown[]) => Promise<unknown>;
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Wrap an async function with delegation checking.
|
|
19
|
+
*
|
|
20
|
+
* Usage:
|
|
21
|
+
* const guardedFn = functionGuard(client, delegationId, myFunction);
|
|
22
|
+
* await guardedFn(arg1, arg2);
|
|
23
|
+
*
|
|
24
|
+
* @param client AgentCheck Client used to verify the delegation.
|
|
25
|
+
* @param delegationId The agreement ID that must be active.
|
|
26
|
+
* @param fn The async function to guard.
|
|
27
|
+
* @returns A wrapped function that checks delegation before executing.
|
|
28
|
+
*/
|
|
29
|
+
export declare function functionGuard<TArgs extends unknown[], TReturn>(client: AgentCheckClient, delegationId: string, fn: (...args: TArgs) => Promise<TReturn>): (...args: TArgs) => Promise<TReturn>;
|
|
30
|
+
export declare class AgentCheckAssistant {
|
|
31
|
+
private readonly client;
|
|
32
|
+
private readonly delegationId;
|
|
33
|
+
private readonly assistant;
|
|
34
|
+
/**
|
|
35
|
+
* @param client AgentCheck Client used to verify delegations.
|
|
36
|
+
* @param delegationId The agreement ID authorizing this assistant.
|
|
37
|
+
* @param assistant An AutoGen AssistantAgent instance.
|
|
38
|
+
*/
|
|
39
|
+
constructor(client: AgentCheckClient, delegationId: string, assistant: AutoGenAssistant);
|
|
40
|
+
/**
|
|
41
|
+
* Initiate a chat, verifying delegation first.
|
|
42
|
+
*
|
|
43
|
+
* @param args Arguments forwarded to the underlying AssistantAgent.initiate_chat.
|
|
44
|
+
* @returns Chat result from the underlying AssistantAgent.
|
|
45
|
+
*/
|
|
46
|
+
initiateChat(...args: unknown[]): Promise<unknown>;
|
|
47
|
+
/** Retrieve an attribute from the wrapped assistant by name. */
|
|
48
|
+
getAttr(prop: string): unknown;
|
|
49
|
+
}
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AutoGen integration for AgentCheck (TypeScript).
|
|
4
|
+
*
|
|
5
|
+
* Provides a decorator-style function guard for AutoGen function calls and
|
|
6
|
+
* a wrapper class around AssistantAgent with delegation governance.
|
|
7
|
+
*
|
|
8
|
+
* Note: AutoGen's TypeScript support is limited. This module uses duck-typing.
|
|
9
|
+
*
|
|
10
|
+
* Tier: Molecule (be-mol-agentcheck-autogen-ts) - composes Client + AutoGen pattern.
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.AgentCheckAssistant = void 0;
|
|
14
|
+
exports.functionGuard = functionGuard;
|
|
15
|
+
/**
|
|
16
|
+
* Wrap an async function with delegation checking.
|
|
17
|
+
*
|
|
18
|
+
* Usage:
|
|
19
|
+
* const guardedFn = functionGuard(client, delegationId, myFunction);
|
|
20
|
+
* await guardedFn(arg1, arg2);
|
|
21
|
+
*
|
|
22
|
+
* @param client AgentCheck Client used to verify the delegation.
|
|
23
|
+
* @param delegationId The agreement ID that must be active.
|
|
24
|
+
* @param fn The async function to guard.
|
|
25
|
+
* @returns A wrapped function that checks delegation before executing.
|
|
26
|
+
*/
|
|
27
|
+
function functionGuard(client, delegationId, fn) {
|
|
28
|
+
return async (...args) => {
|
|
29
|
+
await checkDelegation(client, delegationId);
|
|
30
|
+
try {
|
|
31
|
+
const result = await fn(...args);
|
|
32
|
+
await logExecution(client, delegationId, fn.name || "unknown", "success");
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
await logExecution(client, delegationId, fn.name || "unknown", "error", String(err));
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
class AgentCheckAssistant {
|
|
42
|
+
/**
|
|
43
|
+
* @param client AgentCheck Client used to verify delegations.
|
|
44
|
+
* @param delegationId The agreement ID authorizing this assistant.
|
|
45
|
+
* @param assistant An AutoGen AssistantAgent instance.
|
|
46
|
+
*/
|
|
47
|
+
constructor(client, delegationId, assistant) {
|
|
48
|
+
this.client = client;
|
|
49
|
+
this.delegationId = delegationId;
|
|
50
|
+
this.assistant = assistant;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Initiate a chat, verifying delegation first.
|
|
54
|
+
*
|
|
55
|
+
* @param args Arguments forwarded to the underlying AssistantAgent.initiate_chat.
|
|
56
|
+
* @returns Chat result from the underlying AssistantAgent.
|
|
57
|
+
*/
|
|
58
|
+
async initiateChat(...args) {
|
|
59
|
+
await checkDelegation(this.client, this.delegationId);
|
|
60
|
+
return this.assistant.initiate_chat(...args);
|
|
61
|
+
}
|
|
62
|
+
/** Retrieve an attribute from the wrapped assistant by name. */
|
|
63
|
+
getAttr(prop) {
|
|
64
|
+
return this.assistant[prop];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.AgentCheckAssistant = AgentCheckAssistant;
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
// Internal helpers
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
async function checkDelegation(client, delegationId) {
|
|
72
|
+
const agreement = await client.get(delegationId);
|
|
73
|
+
if (agreement.status !== "approved") {
|
|
74
|
+
throw new Error(`Delegation ${delegationId} is not approved (status=${agreement.status})`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async function logExecution(client, delegationId, action, result, error) {
|
|
78
|
+
try {
|
|
79
|
+
const metadata = {};
|
|
80
|
+
if (error)
|
|
81
|
+
metadata.error = error;
|
|
82
|
+
await client.request("POST", "/api/v1/executions", {
|
|
83
|
+
agent: "autogen",
|
|
84
|
+
action,
|
|
85
|
+
agreement_id: delegationId,
|
|
86
|
+
result,
|
|
87
|
+
metadata,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// Best-effort logging
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CrewAI integration for AgentCheck (TypeScript).
|
|
3
|
+
*
|
|
4
|
+
* Wraps CrewAI-style tools with delegation checking and provides a step
|
|
5
|
+
* callback that logs each crew step to the AgentCheck audit trail.
|
|
6
|
+
*
|
|
7
|
+
* Note: CrewAI does not have an official TypeScript package.
|
|
8
|
+
* This module uses duck-typing to work with any compatible tool shape.
|
|
9
|
+
*
|
|
10
|
+
* Tier: Molecule (be-mol-agentcheck-crewai-ts) - composes Client + CrewAI pattern.
|
|
11
|
+
*/
|
|
12
|
+
import type { AgentCheckClient } from "../client";
|
|
13
|
+
/** Minimal shape of a CrewAI-compatible tool. */
|
|
14
|
+
interface CrewTool {
|
|
15
|
+
name?: string;
|
|
16
|
+
run?: (...args: unknown[]) => unknown | Promise<unknown>;
|
|
17
|
+
_run?: (...args: unknown[]) => unknown | Promise<unknown>;
|
|
18
|
+
[key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Wrap CrewAI tools with delegation checking.
|
|
22
|
+
*
|
|
23
|
+
* Each wrapped tool checks that the delegation is still active before
|
|
24
|
+
* executing, using duck-typing on run/_run methods.
|
|
25
|
+
*
|
|
26
|
+
* @param client AgentCheck Client used to verify delegations.
|
|
27
|
+
* @param delegationId The agreement ID authorizing these tool calls.
|
|
28
|
+
* @param tools Array of CrewAI tool objects.
|
|
29
|
+
* @returns Array of wrapped tools.
|
|
30
|
+
*/
|
|
31
|
+
export declare function wrapCrewTools<T extends CrewTool>(client: AgentCheckClient, delegationId: string, tools: T[]): T[];
|
|
32
|
+
export declare class AgentCheckCrewCallback {
|
|
33
|
+
private readonly client;
|
|
34
|
+
private readonly delegationId;
|
|
35
|
+
/**
|
|
36
|
+
* @param client AgentCheck Client used for logging.
|
|
37
|
+
* @param delegationId The agreement ID to associate steps with.
|
|
38
|
+
*/
|
|
39
|
+
constructor(client: AgentCheckClient, delegationId: string);
|
|
40
|
+
/**
|
|
41
|
+
* Log a crew step to AgentCheck. Called after each step.
|
|
42
|
+
*
|
|
43
|
+
* Compatible with CrewAI's step_callback pattern.
|
|
44
|
+
*
|
|
45
|
+
* @param stepOutput The output from the completed crew step.
|
|
46
|
+
*/
|
|
47
|
+
call(stepOutput: unknown): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CrewAI integration for AgentCheck (TypeScript).
|
|
4
|
+
*
|
|
5
|
+
* Wraps CrewAI-style tools with delegation checking and provides a step
|
|
6
|
+
* callback that logs each crew step to the AgentCheck audit trail.
|
|
7
|
+
*
|
|
8
|
+
* Note: CrewAI does not have an official TypeScript package.
|
|
9
|
+
* This module uses duck-typing to work with any compatible tool shape.
|
|
10
|
+
*
|
|
11
|
+
* Tier: Molecule (be-mol-agentcheck-crewai-ts) - composes Client + CrewAI pattern.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.AgentCheckCrewCallback = void 0;
|
|
15
|
+
exports.wrapCrewTools = wrapCrewTools;
|
|
16
|
+
/**
|
|
17
|
+
* Wrap CrewAI tools with delegation checking.
|
|
18
|
+
*
|
|
19
|
+
* Each wrapped tool checks that the delegation is still active before
|
|
20
|
+
* executing, using duck-typing on run/_run methods.
|
|
21
|
+
*
|
|
22
|
+
* @param client AgentCheck Client used to verify delegations.
|
|
23
|
+
* @param delegationId The agreement ID authorizing these tool calls.
|
|
24
|
+
* @param tools Array of CrewAI tool objects.
|
|
25
|
+
* @returns Array of wrapped tools.
|
|
26
|
+
*/
|
|
27
|
+
function wrapCrewTools(client, delegationId, tools) {
|
|
28
|
+
return tools.map((tool) => wrapSingleCrewTool(client, delegationId, tool));
|
|
29
|
+
}
|
|
30
|
+
function wrapSingleCrewTool(client, delegationId, tool) {
|
|
31
|
+
const check = () => checkDelegation(client, delegationId);
|
|
32
|
+
if (typeof tool._run === "function") {
|
|
33
|
+
const original = tool._run.bind(tool);
|
|
34
|
+
tool._run = async (...args) => {
|
|
35
|
+
await check();
|
|
36
|
+
return original(...args);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
else if (typeof tool.run === "function") {
|
|
40
|
+
const original = tool.run.bind(tool);
|
|
41
|
+
tool.run = async (...args) => {
|
|
42
|
+
await check();
|
|
43
|
+
return original(...args);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return tool;
|
|
47
|
+
}
|
|
48
|
+
class AgentCheckCrewCallback {
|
|
49
|
+
/**
|
|
50
|
+
* @param client AgentCheck Client used for logging.
|
|
51
|
+
* @param delegationId The agreement ID to associate steps with.
|
|
52
|
+
*/
|
|
53
|
+
constructor(client, delegationId) {
|
|
54
|
+
this.client = client;
|
|
55
|
+
this.delegationId = delegationId;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Log a crew step to AgentCheck. Called after each step.
|
|
59
|
+
*
|
|
60
|
+
* Compatible with CrewAI's step_callback pattern.
|
|
61
|
+
*
|
|
62
|
+
* @param stepOutput The output from the completed crew step.
|
|
63
|
+
*/
|
|
64
|
+
async call(stepOutput) {
|
|
65
|
+
try {
|
|
66
|
+
let action = "crew_step";
|
|
67
|
+
let metadata = {};
|
|
68
|
+
if (stepOutput && typeof stepOutput === "object") {
|
|
69
|
+
const step = stepOutput;
|
|
70
|
+
if ("return_values" in step) {
|
|
71
|
+
action = "crew_finish";
|
|
72
|
+
metadata = { return_values: String(step.return_values).slice(0, 200) };
|
|
73
|
+
}
|
|
74
|
+
else if ("observation" in step) {
|
|
75
|
+
action = "crew_action";
|
|
76
|
+
metadata = { observation: String(step.observation).slice(0, 200) };
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
metadata = { output: JSON.stringify(stepOutput).slice(0, 200) };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
metadata = { output: String(stepOutput).slice(0, 200) };
|
|
84
|
+
}
|
|
85
|
+
await this.client.request("POST", "/api/v1/executions", {
|
|
86
|
+
agent: "crewai",
|
|
87
|
+
action,
|
|
88
|
+
agreement_id: this.delegationId,
|
|
89
|
+
result: "success",
|
|
90
|
+
metadata,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// Best-effort logging - do not propagate errors
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.AgentCheckCrewCallback = AgentCheckCrewCallback;
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
// Internal helpers
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
async function checkDelegation(client, delegationId) {
|
|
103
|
+
const agreement = await client.get(delegationId);
|
|
104
|
+
if (agreement.status !== "approved") {
|
|
105
|
+
throw new Error(`Delegation ${delegationId} is not approved (status=${agreement.status})`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentCheck framework integrations (TypeScript).
|
|
3
|
+
*
|
|
4
|
+
* Re-exports all integration classes and utilities.
|
|
5
|
+
*/
|
|
6
|
+
export { AgentCheckToolkit, AgentCheckCallbackHandler } from "./langchain";
|
|
7
|
+
export { wrapCrewTools, AgentCheckCrewCallback } from "./crewai";
|
|
8
|
+
export { functionGuard, AgentCheckAssistant } from "./autogen";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AgentCheck framework integrations (TypeScript).
|
|
4
|
+
*
|
|
5
|
+
* Re-exports all integration classes and utilities.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.AgentCheckAssistant = exports.functionGuard = exports.AgentCheckCrewCallback = exports.wrapCrewTools = exports.AgentCheckCallbackHandler = exports.AgentCheckToolkit = void 0;
|
|
9
|
+
var langchain_1 = require("./langchain");
|
|
10
|
+
Object.defineProperty(exports, "AgentCheckToolkit", { enumerable: true, get: function () { return langchain_1.AgentCheckToolkit; } });
|
|
11
|
+
Object.defineProperty(exports, "AgentCheckCallbackHandler", { enumerable: true, get: function () { return langchain_1.AgentCheckCallbackHandler; } });
|
|
12
|
+
var crewai_1 = require("./crewai");
|
|
13
|
+
Object.defineProperty(exports, "wrapCrewTools", { enumerable: true, get: function () { return crewai_1.wrapCrewTools; } });
|
|
14
|
+
Object.defineProperty(exports, "AgentCheckCrewCallback", { enumerable: true, get: function () { return crewai_1.AgentCheckCrewCallback; } });
|
|
15
|
+
var autogen_1 = require("./autogen");
|
|
16
|
+
Object.defineProperty(exports, "functionGuard", { enumerable: true, get: function () { return autogen_1.functionGuard; } });
|
|
17
|
+
Object.defineProperty(exports, "AgentCheckAssistant", { enumerable: true, get: function () { return autogen_1.AgentCheckAssistant; } });
|