@agent-trust/gateway 1.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.
@@ -0,0 +1,183 @@
1
+ import { Request } from 'express';
2
+ export interface GatewayConfig {
3
+ /** URL of the Agent Trust Station (e.g., "https://station.example.com") */
4
+ stationUrl: string;
5
+ /** Unique identifier for this gateway (e.g., "my-ecommerce-site") */
6
+ gatewayId: string;
7
+ /** Developer API key for authenticating with the station */
8
+ stationApiKey: string;
9
+ /** Map of action names to their definitions */
10
+ actions: Record<string, ActionDefinition>;
11
+ /** How often to refresh the station's public key, in ms (default: 3600000 = 1 hour) */
12
+ publicKeyRefreshInterval?: number;
13
+ /** Behavioral tracking configuration (optional — enabled by default) */
14
+ behavior?: BehaviorConfig;
15
+ }
16
+ export interface BehaviorConfig {
17
+ /** Enable/disable behavioral tracking (default: true) */
18
+ enabled?: boolean;
19
+ /** Session timeout in ms — sessions expire after this idle time (default: 300000 = 5 min) */
20
+ sessionTimeout?: number;
21
+ /** Max actions per minute before flagging as rapid-fire (default: 30) */
22
+ maxActionsPerMinute?: number;
23
+ /** Max failed actions before flagging as probing (default: 5) */
24
+ maxFailuresBeforeFlag?: number;
25
+ /** Max unique action types per minute before flagging as enumeration (default: 10) */
26
+ maxUniqueActionsPerMinute?: number;
27
+ /** Max repeated identical actions per minute before flagging as automation (default: 10) */
28
+ maxRepeatedActionsPerMinute?: number;
29
+ /** Score penalty for each behavioral violation (0-100, default: 10) */
30
+ violationPenalty?: number;
31
+ /** Score threshold below which the agent is blocked mid-session (default: 20) */
32
+ blockThreshold?: number;
33
+ /** Callback when suspicious behavior is detected */
34
+ onSuspiciousActivity?: (event: BehaviorEvent) => void;
35
+ }
36
+ export interface ActionDefinition {
37
+ /** Human-readable description of what this action does */
38
+ description: string;
39
+ /** Minimum reputation score required to use this action (0-100) */
40
+ minScore: number;
41
+ /** Parameter schema for this action */
42
+ parameters: Record<string, ParameterDefinition>;
43
+ /** Handler function that executes the action */
44
+ handler: ActionHandler;
45
+ }
46
+ export interface ParameterDefinition {
47
+ /** Parameter type */
48
+ type: 'string' | 'number' | 'boolean' | 'object' | 'array';
49
+ /** Whether this parameter is required */
50
+ required: boolean;
51
+ /** Human-readable description */
52
+ description?: string;
53
+ }
54
+ /** The handler function receives validated params and agent context */
55
+ export type ActionHandler = (params: Record<string, unknown>, agent: AgentContext) => Promise<unknown>;
56
+ export interface AgentContext {
57
+ /** Internal agent UUID (from certificate "sub" claim) */
58
+ agentId: string;
59
+ /** Agent's external ID as registered by the developer */
60
+ externalId: string;
61
+ /** Developer ID who owns this agent */
62
+ developerId: string;
63
+ /** Agent's reputation score at time of certificate issuance */
64
+ score: number;
65
+ /** Whether the agent's identity has been verified */
66
+ identityVerified: boolean;
67
+ }
68
+ export interface ActionResult {
69
+ success: boolean;
70
+ data?: unknown;
71
+ error?: string;
72
+ }
73
+ export interface PublicActionInfo {
74
+ description: string;
75
+ minScore: number;
76
+ parameters: Record<string, ParameterDefinition>;
77
+ }
78
+ export interface DiscoveryPayload {
79
+ gatewayId: string;
80
+ actions: Record<string, PublicActionInfo>;
81
+ certificateIssuer: string;
82
+ version: string;
83
+ }
84
+ export interface CertificatePayload {
85
+ sub: string;
86
+ agentExternalId: string;
87
+ developerId: string;
88
+ score: number;
89
+ identityVerified: boolean;
90
+ status: string;
91
+ totalActions: number;
92
+ successRate: number | null;
93
+ iat: number;
94
+ exp: number;
95
+ iss: string;
96
+ jti: string;
97
+ }
98
+ export interface GatewayReportPayload {
99
+ agentId: string;
100
+ gatewayId: string;
101
+ actions: Array<{
102
+ actionType: string;
103
+ outcome: 'success' | 'failure';
104
+ metadata?: Record<string, unknown>;
105
+ performedAt: string;
106
+ }>;
107
+ certificateJti: string;
108
+ }
109
+ /** Express request with attached agent certificate and behavior data */
110
+ export interface GatewayRequest extends Request {
111
+ agentCertificate?: CertificatePayload;
112
+ agentToken?: string;
113
+ /** Live behavioral score for this agent session */
114
+ behaviorScore?: number;
115
+ /** Behavioral flags detected in this session */
116
+ behaviorFlags?: BehaviorFlag[];
117
+ }
118
+ export type BehaviorFlag = 'rapid_fire' | 'high_failure_rate' | 'action_enumeration' | 'repeated_action' | 'scope_violation' | 'session_anomaly' | 'burst_detected';
119
+ export interface BehaviorEvent {
120
+ /** The agent ID */
121
+ agentId: string;
122
+ /** The agent's external ID */
123
+ externalId: string;
124
+ /** Which flag was triggered */
125
+ flag: BehaviorFlag;
126
+ /** Human-readable description */
127
+ description: string;
128
+ /** The behavioral score at time of event */
129
+ behaviorScore: number;
130
+ /** Session stats at time of event */
131
+ sessionStats: SessionStats;
132
+ /** Timestamp */
133
+ timestamp: string;
134
+ }
135
+ export interface SessionStats {
136
+ /** Total actions in this session */
137
+ totalActions: number;
138
+ /** Successful actions */
139
+ successfulActions: number;
140
+ /** Failed actions */
141
+ failedActions: number;
142
+ /** Actions in the last 60 seconds */
143
+ actionsLastMinute: number;
144
+ /** Unique action types in the last 60 seconds */
145
+ uniqueActionsLastMinute: number;
146
+ /** How long the session has been active (ms) */
147
+ sessionDuration: number;
148
+ /** Number of scope violations (tried actions above their score) */
149
+ scopeViolations: number;
150
+ /** Number of behavioral flags triggered */
151
+ flagsTriggered: BehaviorFlag[];
152
+ }
153
+ export interface AgentSession {
154
+ /** The agent's internal ID (from certificate sub) */
155
+ agentId: string;
156
+ /** The agent's external ID */
157
+ externalId: string;
158
+ /** Session start time */
159
+ startedAt: number;
160
+ /** Last activity time */
161
+ lastActivityAt: number;
162
+ /** Current behavioral score (starts at 100, decreases with violations) */
163
+ behaviorScore: number;
164
+ /** All actions performed in this session */
165
+ actions: SessionAction[];
166
+ /** Flags that have been triggered */
167
+ flags: Set<BehaviorFlag>;
168
+ /** Whether the agent has been blocked mid-session */
169
+ blocked: boolean;
170
+ }
171
+ export interface SessionAction {
172
+ /** Action name */
173
+ actionName: string;
174
+ /** Action parameters (hashed for comparison) */
175
+ paramsHash: string;
176
+ /** Whether it succeeded */
177
+ success: boolean;
178
+ /** Whether it was a scope violation */
179
+ scopeViolation: boolean;
180
+ /** Timestamp */
181
+ timestamp: number;
182
+ }
183
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAIlC,MAAM,WAAW,aAAa;IAC5B,2EAA2E;IAC3E,UAAU,EAAE,MAAM,CAAC;IAEnB,qEAAqE;IACrE,SAAS,EAAE,MAAM,CAAC;IAElB,4DAA4D;IAC5D,aAAa,EAAE,MAAM,CAAC;IAEtB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IAE1C,uFAAuF;IACvF,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAElC,wEAAwE;IACxE,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAID,MAAM,WAAW,cAAc;IAC7B,yDAAyD;IACzD,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB,6FAA6F;IAC7F,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,yEAAyE;IACzE,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAE7B,iEAAiE;IACjE,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B,sFAAsF;IACtF,yBAAyB,CAAC,EAAE,MAAM,CAAC;IAEnC,4FAA4F;IAC5F,2BAA2B,CAAC,EAAE,MAAM,CAAC;IAErC,uEAAuE;IACvE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,iFAAiF;IACjF,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,oDAAoD;IACpD,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;CACvD;AAID,MAAM,WAAW,gBAAgB;IAC/B,0DAA0D;IAC1D,WAAW,EAAE,MAAM,CAAC;IAEpB,mEAAmE;IACnE,QAAQ,EAA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AO,CAAC;IACjB,uCAAuC;IACvC,cAAc,EAAE,OAAO,CAAC;IACxB,gBAAgB;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@agent-trust/gateway",
3
+ "version": "1.0.0",
4
+ "description": "Express middleware that lets trusted AI agents interact with your website. Verifies cryptographic certificates, checks reputation scores, and reports behavior.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "dev": "tsc --watch"
10
+ },
11
+ "keywords": [
12
+ "ai",
13
+ "agent",
14
+ "gateway",
15
+ "trust",
16
+ "middleware",
17
+ "express",
18
+ "jwt",
19
+ "certificate",
20
+ "reputation",
21
+ "ai-agents",
22
+ "agenttrust"
23
+ ],
24
+ "author": "AgentTrust",
25
+ "license": "MIT",
26
+ "homepage": "https://github.com/mmsadek96/agentgateway/tree/main/packages/gateway#readme",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/mmsadek96/agentgateway.git",
30
+ "directory": "packages/gateway"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/mmsadek96/agentgateway/issues"
34
+ },
35
+ "peerDependencies": {
36
+ "express": "^4.18.0"
37
+ },
38
+ "dependencies": {
39
+ "jsonwebtoken": "^9.0.2"
40
+ },
41
+ "devDependencies": {
42
+ "@types/express": "^4.17.21",
43
+ "@types/jsonwebtoken": "^9.0.6",
44
+ "typescript": "^5.3.3"
45
+ },
46
+ "engines": {
47
+ "node": ">=18.0.0"
48
+ }
49
+ }