@mandatedev/agent 0.1.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.
@@ -0,0 +1,275 @@
1
+ type AgentFramework = 'openai-assistants' | 'langchain' | 'autogen' | 'crewai' | 'anthropic' | 'custom';
2
+ type AgentEnvironment = 'production' | 'staging' | 'development';
3
+ type AgentRiskTier = 'LOW' | 'STANDARD' | 'HIGH' | 'CRITICAL';
4
+ type DegradationTier = 'NOMINAL' | 'DEGRADED' | 'ISOLATED' | 'GRACE_STD' | 'GRACE_HIGH';
5
+ type PolicyDecision = 'ALLOW' | 'DENY' | 'ESCALATE' | 'THROTTLE';
6
+ type ResponseLevel = 1 | 2 | 3 | 4 | 5;
7
+ interface IntentContext {
8
+ agentId: string;
9
+ sessionId: string;
10
+ environment: AgentEnvironment;
11
+ stepInChain: number;
12
+ framework: AgentFramework;
13
+ timestamp: number;
14
+ }
15
+ interface AgentIntent {
16
+ toolName: string;
17
+ args: Record<string, unknown>;
18
+ context: IntentContext;
19
+ }
20
+ interface EvaluationResult {
21
+ decision: PolicyDecision;
22
+ reason: string;
23
+ latencyMs: number;
24
+ ruleMatched?: string;
25
+ anomalyScore?: number;
26
+ responseLevel?: ResponseLevel;
27
+ }
28
+ type ConditionOperator = 'eq' | 'neq' | 'lt' | 'lte' | 'gt' | 'gte' | 'in' | 'nin' | 'startsWith' | 'endsWith' | 'contains';
29
+ interface PolicyCondition {
30
+ field: string;
31
+ operator: ConditionOperator;
32
+ value: unknown;
33
+ }
34
+ interface PolicyRule {
35
+ tool: string;
36
+ conditions?: PolicyCondition[];
37
+ }
38
+ interface PolicyIdentity {
39
+ org: string;
40
+ env: AgentEnvironment;
41
+ framework?: string;
42
+ }
43
+ interface AnomalyThresholds {
44
+ alert: number;
45
+ throttle: number;
46
+ }
47
+ interface LocalAutonomyConfig {
48
+ gracePeriodMs: number;
49
+ postGrace: 'PAUSE' | 'STOP';
50
+ }
51
+ interface MandatePolicy {
52
+ agentId: string;
53
+ version: string;
54
+ policyHash: string;
55
+ identity: PolicyIdentity;
56
+ allow: PolicyRule[];
57
+ deny: PolicyRule[];
58
+ anomalyThresholds: AnomalyThresholds;
59
+ localAutonomy: LocalAutonomyConfig;
60
+ }
61
+ interface AuditEvent {
62
+ eventId: string;
63
+ prevHash: string;
64
+ eventHash: string;
65
+ timestamp: number;
66
+ source: 'REALTIME' | 'BUFFER_SYNC';
67
+ agentId: string;
68
+ orgId: string;
69
+ policyHash: string;
70
+ degradationTier: DegradationTier;
71
+ toolName: string;
72
+ toolArgs: Record<string, unknown>;
73
+ intentContext: IntentContext;
74
+ anomalyScore: number;
75
+ blastRadiusEst?: string;
76
+ policyDecision: PolicyDecision;
77
+ responseLevel: ResponseLevel;
78
+ evalLatencyMs: number;
79
+ tokensUsed?: number;
80
+ costUsd?: number;
81
+ }
82
+ interface MandateConfig {
83
+ agentId: string;
84
+ orgId: string;
85
+ apiKey?: string;
86
+ controlPlaneUrl?: string;
87
+ policy: MandatePolicy;
88
+ framework: AgentFramework;
89
+ environment: AgentEnvironment;
90
+ auditLevel: 'full' | 'minimal' | 'off';
91
+ riskTier?: AgentRiskTier;
92
+ onViolation?: (intent: AgentIntent, result: EvaluationResult) => void;
93
+ onAlert?: (intent: AgentIntent, score: number) => void;
94
+ onDegradation?: (from: DegradationTier, to: DegradationTier) => void;
95
+ }
96
+
97
+ declare class JSPolicyEvaluator {
98
+ private policy;
99
+ constructor(policy: MandatePolicy);
100
+ evaluate(intent: AgentIntent): EvaluationResult;
101
+ updatePolicy(policy: MandatePolicy): void;
102
+ getPolicyHash(): string;
103
+ private matchesRule;
104
+ private matchesToolPattern;
105
+ private evaluateCondition;
106
+ private resolveField;
107
+ private result;
108
+ }
109
+
110
+ interface BufferOptions {
111
+ maxSize?: number;
112
+ flushCallback?: (events: AuditEvent[]) => Promise<void>;
113
+ }
114
+ interface AppendInput {
115
+ timestamp: number;
116
+ source: 'REALTIME' | 'BUFFER_SYNC';
117
+ agentId: string;
118
+ orgId: string;
119
+ policyHash: string;
120
+ degradationTier: DegradationTier;
121
+ toolName: string;
122
+ toolArgs: Record<string, unknown>;
123
+ intentContext: AuditEvent['intentContext'];
124
+ anomalyScore: number;
125
+ policyDecision: PolicyDecision;
126
+ responseLevel: AuditEvent['responseLevel'];
127
+ evalLatencyMs: number;
128
+ blastRadiusEst?: string;
129
+ tokensUsed?: number;
130
+ costUsd?: number;
131
+ }
132
+ interface VerifyResult {
133
+ valid: boolean;
134
+ corruptedAt?: number;
135
+ }
136
+ declare class AuditBuffer {
137
+ private buffer;
138
+ private lastHash;
139
+ private maxSize;
140
+ private flushCallback?;
141
+ constructor(options?: BufferOptions);
142
+ append(input: AppendInput): AuditEvent;
143
+ flush(): Promise<AuditEvent[]>;
144
+ verify(): VerifyResult;
145
+ size(): number;
146
+ getLastHash(): string;
147
+ private sha256;
148
+ private generateId;
149
+ }
150
+
151
+ interface DegradationOptions {
152
+ gracePeriodMs?: number;
153
+ riskTier?: AgentRiskTier;
154
+ onTierChange?: (from: DegradationTier, to: DegradationTier) => void;
155
+ }
156
+ declare class DegradationManager {
157
+ private state;
158
+ private gracePeriodMs;
159
+ private riskTier;
160
+ private onTierChange?;
161
+ private graceTimer?;
162
+ constructor(options?: DegradationOptions);
163
+ onControlPlaneLatency(latencyMs: number): void;
164
+ onControlPlaneUnreachable(): void;
165
+ onControlPlaneReconnected(): void;
166
+ getCurrentTier(): DegradationTier;
167
+ shouldContinue(): boolean;
168
+ getIsolationDurationMs(): number;
169
+ private startGraceTimer;
170
+ private transition;
171
+ }
172
+
173
+ interface OpenAIFunctionCall {
174
+ name: string;
175
+ arguments: string;
176
+ }
177
+ interface OpenAIToolCall {
178
+ id: string;
179
+ type: 'function';
180
+ function: OpenAIFunctionCall;
181
+ }
182
+ interface InterceptResult$1 {
183
+ allowed: OpenAIToolCall[];
184
+ blocked: Array<{
185
+ toolCall: OpenAIToolCall;
186
+ result: EvaluationResult;
187
+ }>;
188
+ }
189
+ declare class MandateOpenAIHook {
190
+ private evaluator;
191
+ private buffer;
192
+ private degradation;
193
+ private config;
194
+ private sessionId;
195
+ constructor(config: MandateConfig, evaluator: JSPolicyEvaluator, buffer: AuditBuffer, degradation: DegradationManager);
196
+ interceptToolCalls(toolCalls: OpenAIToolCall[], stepInChain?: number): Promise<InterceptResult$1>;
197
+ private buildIntent;
198
+ private logToBuffer;
199
+ private generateSessionId;
200
+ private delay;
201
+ }
202
+
203
+ interface LangChainToolCall {
204
+ name: string;
205
+ args: Record<string, unknown>;
206
+ id?: string;
207
+ }
208
+ declare class MandateLangChainHook {
209
+ private evaluator;
210
+ private buffer;
211
+ private degradation;
212
+ private config;
213
+ private sessionId;
214
+ private stepCounter;
215
+ constructor(config: MandateConfig, evaluator: JSPolicyEvaluator, buffer: AuditBuffer, degradation: DegradationManager);
216
+ getBeforeToolCallHook(): (toolCall: LangChainToolCall) => Promise<LangChainToolCall | null>;
217
+ interceptToolCall(toolCall: LangChainToolCall): Promise<{
218
+ allowed: boolean;
219
+ result: EvaluationResult;
220
+ }>;
221
+ private buildIntent;
222
+ private logToBuffer;
223
+ private delay;
224
+ }
225
+
226
+ interface AnthropicToolUse {
227
+ type: 'tool_use';
228
+ id: string;
229
+ name: string;
230
+ input: Record<string, unknown>;
231
+ }
232
+ interface InterceptResult {
233
+ allowed: AnthropicToolUse[];
234
+ blocked: Array<{
235
+ block: AnthropicToolUse;
236
+ result: EvaluationResult;
237
+ }>;
238
+ }
239
+ declare class MandateAnthropicHook {
240
+ private evaluator;
241
+ private buffer;
242
+ private degradation;
243
+ private config;
244
+ private sessionId;
245
+ private stepCounter;
246
+ constructor(config: MandateConfig, evaluator: JSPolicyEvaluator, buffer: AuditBuffer, degradation: DegradationManager);
247
+ interceptToolUse(toolUseBlocks: AnthropicToolUse[]): Promise<InterceptResult>;
248
+ private buildIntent;
249
+ private logToBuffer;
250
+ private delay;
251
+ }
252
+
253
+ declare class MandateAgent {
254
+ private config;
255
+ private evaluator;
256
+ private buffer;
257
+ private degradation;
258
+ readonly openai: MandateOpenAIHook;
259
+ readonly langchain: MandateLangChainHook;
260
+ readonly anthropic: MandateAnthropicHook;
261
+ constructor(config: MandateConfig);
262
+ evaluate(intent: AgentIntent): EvaluationResult;
263
+ flushAuditBuffer(): Promise<AuditEvent[]>;
264
+ verifyAuditChain(): {
265
+ valid: boolean;
266
+ corruptedAt?: number;
267
+ };
268
+ getDegradationTier(): DegradationTier;
269
+ getBufferSize(): number;
270
+ updatePolicy(policy: MandatePolicy): void;
271
+ private sendToControlPlane;
272
+ }
273
+ declare function createMandateAgent(config: MandateConfig): MandateAgent;
274
+
275
+ export { type AgentEnvironment, type AgentFramework, type AgentIntent, type AgentRiskTier, type AuditEvent, type DegradationTier, type EvaluationResult, MandateAgent, type MandateConfig, type MandatePolicy, type PolicyCondition, type PolicyDecision, type PolicyRule, type ResponseLevel, createMandateAgent };
@@ -0,0 +1,275 @@
1
+ type AgentFramework = 'openai-assistants' | 'langchain' | 'autogen' | 'crewai' | 'anthropic' | 'custom';
2
+ type AgentEnvironment = 'production' | 'staging' | 'development';
3
+ type AgentRiskTier = 'LOW' | 'STANDARD' | 'HIGH' | 'CRITICAL';
4
+ type DegradationTier = 'NOMINAL' | 'DEGRADED' | 'ISOLATED' | 'GRACE_STD' | 'GRACE_HIGH';
5
+ type PolicyDecision = 'ALLOW' | 'DENY' | 'ESCALATE' | 'THROTTLE';
6
+ type ResponseLevel = 1 | 2 | 3 | 4 | 5;
7
+ interface IntentContext {
8
+ agentId: string;
9
+ sessionId: string;
10
+ environment: AgentEnvironment;
11
+ stepInChain: number;
12
+ framework: AgentFramework;
13
+ timestamp: number;
14
+ }
15
+ interface AgentIntent {
16
+ toolName: string;
17
+ args: Record<string, unknown>;
18
+ context: IntentContext;
19
+ }
20
+ interface EvaluationResult {
21
+ decision: PolicyDecision;
22
+ reason: string;
23
+ latencyMs: number;
24
+ ruleMatched?: string;
25
+ anomalyScore?: number;
26
+ responseLevel?: ResponseLevel;
27
+ }
28
+ type ConditionOperator = 'eq' | 'neq' | 'lt' | 'lte' | 'gt' | 'gte' | 'in' | 'nin' | 'startsWith' | 'endsWith' | 'contains';
29
+ interface PolicyCondition {
30
+ field: string;
31
+ operator: ConditionOperator;
32
+ value: unknown;
33
+ }
34
+ interface PolicyRule {
35
+ tool: string;
36
+ conditions?: PolicyCondition[];
37
+ }
38
+ interface PolicyIdentity {
39
+ org: string;
40
+ env: AgentEnvironment;
41
+ framework?: string;
42
+ }
43
+ interface AnomalyThresholds {
44
+ alert: number;
45
+ throttle: number;
46
+ }
47
+ interface LocalAutonomyConfig {
48
+ gracePeriodMs: number;
49
+ postGrace: 'PAUSE' | 'STOP';
50
+ }
51
+ interface MandatePolicy {
52
+ agentId: string;
53
+ version: string;
54
+ policyHash: string;
55
+ identity: PolicyIdentity;
56
+ allow: PolicyRule[];
57
+ deny: PolicyRule[];
58
+ anomalyThresholds: AnomalyThresholds;
59
+ localAutonomy: LocalAutonomyConfig;
60
+ }
61
+ interface AuditEvent {
62
+ eventId: string;
63
+ prevHash: string;
64
+ eventHash: string;
65
+ timestamp: number;
66
+ source: 'REALTIME' | 'BUFFER_SYNC';
67
+ agentId: string;
68
+ orgId: string;
69
+ policyHash: string;
70
+ degradationTier: DegradationTier;
71
+ toolName: string;
72
+ toolArgs: Record<string, unknown>;
73
+ intentContext: IntentContext;
74
+ anomalyScore: number;
75
+ blastRadiusEst?: string;
76
+ policyDecision: PolicyDecision;
77
+ responseLevel: ResponseLevel;
78
+ evalLatencyMs: number;
79
+ tokensUsed?: number;
80
+ costUsd?: number;
81
+ }
82
+ interface MandateConfig {
83
+ agentId: string;
84
+ orgId: string;
85
+ apiKey?: string;
86
+ controlPlaneUrl?: string;
87
+ policy: MandatePolicy;
88
+ framework: AgentFramework;
89
+ environment: AgentEnvironment;
90
+ auditLevel: 'full' | 'minimal' | 'off';
91
+ riskTier?: AgentRiskTier;
92
+ onViolation?: (intent: AgentIntent, result: EvaluationResult) => void;
93
+ onAlert?: (intent: AgentIntent, score: number) => void;
94
+ onDegradation?: (from: DegradationTier, to: DegradationTier) => void;
95
+ }
96
+
97
+ declare class JSPolicyEvaluator {
98
+ private policy;
99
+ constructor(policy: MandatePolicy);
100
+ evaluate(intent: AgentIntent): EvaluationResult;
101
+ updatePolicy(policy: MandatePolicy): void;
102
+ getPolicyHash(): string;
103
+ private matchesRule;
104
+ private matchesToolPattern;
105
+ private evaluateCondition;
106
+ private resolveField;
107
+ private result;
108
+ }
109
+
110
+ interface BufferOptions {
111
+ maxSize?: number;
112
+ flushCallback?: (events: AuditEvent[]) => Promise<void>;
113
+ }
114
+ interface AppendInput {
115
+ timestamp: number;
116
+ source: 'REALTIME' | 'BUFFER_SYNC';
117
+ agentId: string;
118
+ orgId: string;
119
+ policyHash: string;
120
+ degradationTier: DegradationTier;
121
+ toolName: string;
122
+ toolArgs: Record<string, unknown>;
123
+ intentContext: AuditEvent['intentContext'];
124
+ anomalyScore: number;
125
+ policyDecision: PolicyDecision;
126
+ responseLevel: AuditEvent['responseLevel'];
127
+ evalLatencyMs: number;
128
+ blastRadiusEst?: string;
129
+ tokensUsed?: number;
130
+ costUsd?: number;
131
+ }
132
+ interface VerifyResult {
133
+ valid: boolean;
134
+ corruptedAt?: number;
135
+ }
136
+ declare class AuditBuffer {
137
+ private buffer;
138
+ private lastHash;
139
+ private maxSize;
140
+ private flushCallback?;
141
+ constructor(options?: BufferOptions);
142
+ append(input: AppendInput): AuditEvent;
143
+ flush(): Promise<AuditEvent[]>;
144
+ verify(): VerifyResult;
145
+ size(): number;
146
+ getLastHash(): string;
147
+ private sha256;
148
+ private generateId;
149
+ }
150
+
151
+ interface DegradationOptions {
152
+ gracePeriodMs?: number;
153
+ riskTier?: AgentRiskTier;
154
+ onTierChange?: (from: DegradationTier, to: DegradationTier) => void;
155
+ }
156
+ declare class DegradationManager {
157
+ private state;
158
+ private gracePeriodMs;
159
+ private riskTier;
160
+ private onTierChange?;
161
+ private graceTimer?;
162
+ constructor(options?: DegradationOptions);
163
+ onControlPlaneLatency(latencyMs: number): void;
164
+ onControlPlaneUnreachable(): void;
165
+ onControlPlaneReconnected(): void;
166
+ getCurrentTier(): DegradationTier;
167
+ shouldContinue(): boolean;
168
+ getIsolationDurationMs(): number;
169
+ private startGraceTimer;
170
+ private transition;
171
+ }
172
+
173
+ interface OpenAIFunctionCall {
174
+ name: string;
175
+ arguments: string;
176
+ }
177
+ interface OpenAIToolCall {
178
+ id: string;
179
+ type: 'function';
180
+ function: OpenAIFunctionCall;
181
+ }
182
+ interface InterceptResult$1 {
183
+ allowed: OpenAIToolCall[];
184
+ blocked: Array<{
185
+ toolCall: OpenAIToolCall;
186
+ result: EvaluationResult;
187
+ }>;
188
+ }
189
+ declare class MandateOpenAIHook {
190
+ private evaluator;
191
+ private buffer;
192
+ private degradation;
193
+ private config;
194
+ private sessionId;
195
+ constructor(config: MandateConfig, evaluator: JSPolicyEvaluator, buffer: AuditBuffer, degradation: DegradationManager);
196
+ interceptToolCalls(toolCalls: OpenAIToolCall[], stepInChain?: number): Promise<InterceptResult$1>;
197
+ private buildIntent;
198
+ private logToBuffer;
199
+ private generateSessionId;
200
+ private delay;
201
+ }
202
+
203
+ interface LangChainToolCall {
204
+ name: string;
205
+ args: Record<string, unknown>;
206
+ id?: string;
207
+ }
208
+ declare class MandateLangChainHook {
209
+ private evaluator;
210
+ private buffer;
211
+ private degradation;
212
+ private config;
213
+ private sessionId;
214
+ private stepCounter;
215
+ constructor(config: MandateConfig, evaluator: JSPolicyEvaluator, buffer: AuditBuffer, degradation: DegradationManager);
216
+ getBeforeToolCallHook(): (toolCall: LangChainToolCall) => Promise<LangChainToolCall | null>;
217
+ interceptToolCall(toolCall: LangChainToolCall): Promise<{
218
+ allowed: boolean;
219
+ result: EvaluationResult;
220
+ }>;
221
+ private buildIntent;
222
+ private logToBuffer;
223
+ private delay;
224
+ }
225
+
226
+ interface AnthropicToolUse {
227
+ type: 'tool_use';
228
+ id: string;
229
+ name: string;
230
+ input: Record<string, unknown>;
231
+ }
232
+ interface InterceptResult {
233
+ allowed: AnthropicToolUse[];
234
+ blocked: Array<{
235
+ block: AnthropicToolUse;
236
+ result: EvaluationResult;
237
+ }>;
238
+ }
239
+ declare class MandateAnthropicHook {
240
+ private evaluator;
241
+ private buffer;
242
+ private degradation;
243
+ private config;
244
+ private sessionId;
245
+ private stepCounter;
246
+ constructor(config: MandateConfig, evaluator: JSPolicyEvaluator, buffer: AuditBuffer, degradation: DegradationManager);
247
+ interceptToolUse(toolUseBlocks: AnthropicToolUse[]): Promise<InterceptResult>;
248
+ private buildIntent;
249
+ private logToBuffer;
250
+ private delay;
251
+ }
252
+
253
+ declare class MandateAgent {
254
+ private config;
255
+ private evaluator;
256
+ private buffer;
257
+ private degradation;
258
+ readonly openai: MandateOpenAIHook;
259
+ readonly langchain: MandateLangChainHook;
260
+ readonly anthropic: MandateAnthropicHook;
261
+ constructor(config: MandateConfig);
262
+ evaluate(intent: AgentIntent): EvaluationResult;
263
+ flushAuditBuffer(): Promise<AuditEvent[]>;
264
+ verifyAuditChain(): {
265
+ valid: boolean;
266
+ corruptedAt?: number;
267
+ };
268
+ getDegradationTier(): DegradationTier;
269
+ getBufferSize(): number;
270
+ updatePolicy(policy: MandatePolicy): void;
271
+ private sendToControlPlane;
272
+ }
273
+ declare function createMandateAgent(config: MandateConfig): MandateAgent;
274
+
275
+ export { type AgentEnvironment, type AgentFramework, type AgentIntent, type AgentRiskTier, type AuditEvent, type DegradationTier, type EvaluationResult, MandateAgent, type MandateConfig, type MandatePolicy, type PolicyCondition, type PolicyDecision, type PolicyRule, type ResponseLevel, createMandateAgent };