@kya-os/contracts 1.5.3-canary.2 → 1.5.3-canary.20
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/.turbo/turbo-build.log +17 -0
- package/.turbo/turbo-test$colon$coverage.log +85 -0
- package/.turbo/turbo-test.log +32 -0
- package/coverage/coverage-final.json +38 -0
- package/dist/agentshield-api/admin-schemas.d.ts +2 -2
- package/dist/agentshield-api/index.d.ts +1 -1
- package/dist/agentshield-api/schemas.d.ts +150 -48
- package/dist/agentshield-api/schemas.js +32 -4
- package/dist/agentshield-api/types.d.ts +31 -4
- package/dist/audit/index.d.ts +193 -0
- package/dist/audit/index.js +100 -0
- package/dist/config/identity.d.ts +205 -2
- package/dist/config/identity.js +28 -0
- package/dist/config/index.d.ts +2 -1
- package/dist/config/tool-context.d.ts +34 -0
- package/dist/config/tool-context.js +13 -0
- package/dist/consent/schemas.d.ts +119 -93
- package/dist/consent/schemas.js +111 -64
- package/dist/dashboard-config/schemas.d.ts +1949 -693
- package/dist/handshake.d.ts +14 -14
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/tool-protection/index.d.ts +430 -2
- package/dist/tool-protection/index.js +62 -2
- package/dist/verifier/index.d.ts +1 -0
- package/dist/verifier/index.js +18 -0
- package/dist/well-known/index.d.ts +2 -2
- package/package.json +43 -122
- package/schemas/cli/register-output/v1.0.0.json +69 -0
- package/schemas/identity/v1.0.0.json +46 -0
- package/schemas/proof/v1.0.0.json +80 -0
- package/schemas/registry/receipt-v1.0.0.json +60 -0
- package/schemas/verifier/verify-page/v1.0.0.json +94 -0
- package/schemas/well-known/agent/v1.0.0.json +67 -0
- package/schemas/well-known/did/v1.0.0.json +174 -0
- package/scripts/emit-schemas.js +11 -0
- package/src/agentshield-api/admin-schemas.ts +31 -0
- package/src/agentshield-api/admin-types.ts +47 -0
- package/src/agentshield-api/endpoints.ts +60 -0
- package/src/agentshield-api/index.ts +70 -0
- package/src/agentshield-api/schemas.ts +304 -0
- package/src/agentshield-api/types.ts +317 -0
- package/src/audit/index.ts +128 -0
- package/src/cli.ts +156 -0
- package/src/config/base.ts +107 -0
- package/src/config/builder.ts +97 -0
- package/src/config/delegation.ts +232 -0
- package/src/config/identity.ts +252 -0
- package/src/config/index.ts +78 -0
- package/src/config/proofing.ts +138 -0
- package/src/config/tool-context.ts +41 -0
- package/src/config/tool-protection.ts +174 -0
- package/src/consent/index.ts +32 -0
- package/src/consent/schemas.ts +334 -0
- package/src/consent/types.ts +199 -0
- package/src/dashboard-config/default-config.json +86 -0
- package/src/dashboard-config/default-config.ts +266 -0
- package/src/dashboard-config/index.ts +48 -0
- package/src/dashboard-config/schemas.ts +286 -0
- package/src/dashboard-config/types.ts +404 -0
- package/src/delegation/constraints.ts +267 -0
- package/src/delegation/index.ts +8 -0
- package/src/delegation/schemas.ts +595 -0
- package/src/did/index.ts +9 -0
- package/src/did/resolve-contract.ts +255 -0
- package/src/did/schemas.ts +190 -0
- package/src/did/types.ts +224 -0
- package/src/env/constants.ts +70 -0
- package/src/env/index.ts +5 -0
- package/src/handshake.ts +125 -0
- package/src/index.ts +45 -0
- package/src/proof/index.ts +31 -0
- package/src/proof/proof-record.ts +163 -0
- package/src/proof/signing-spec.ts +146 -0
- package/src/proof.ts +99 -0
- package/src/registry.ts +146 -0
- package/src/runtime/errors.ts +153 -0
- package/src/runtime/headers.ts +136 -0
- package/src/runtime/index.ts +6 -0
- package/src/test.ts +143 -0
- package/src/tlkrc/index.ts +5 -0
- package/src/tlkrc/rotation.ts +153 -0
- package/src/tool-protection/index.ts +343 -0
- package/src/utils/validation.ts +93 -0
- package/src/vc/index.ts +8 -0
- package/src/vc/schemas.ts +277 -0
- package/src/vc/statuslist.ts +279 -0
- package/src/verifier/index.ts +2 -0
- package/src/verifier.ts +92 -0
- package/src/well-known/index.ts +237 -0
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentShield/Bouncer API Zod Validation Schemas
|
|
3
|
+
*
|
|
4
|
+
* Runtime validation schemas matching the API contract types.
|
|
5
|
+
* These schemas ensure request/response validation before sending/receiving.
|
|
6
|
+
*
|
|
7
|
+
* @package @kya-os/contracts/agentshield-api
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { DetachedProofSchema } from "../proof.js";
|
|
12
|
+
import { DelegationRecordSchema } from "../delegation/index.js";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Standard error schema
|
|
16
|
+
*/
|
|
17
|
+
export const agentShieldAPIErrorSchema = z.object({
|
|
18
|
+
code: z.string(),
|
|
19
|
+
message: z.string(),
|
|
20
|
+
details: z.record(z.unknown()).optional(),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Standard API response wrapper schema
|
|
25
|
+
*/
|
|
26
|
+
export const agentShieldAPIResponseSchema = <T extends z.ZodTypeAny>(
|
|
27
|
+
dataSchema: T
|
|
28
|
+
) =>
|
|
29
|
+
z.object({
|
|
30
|
+
success: z.boolean(),
|
|
31
|
+
data: dataSchema,
|
|
32
|
+
metadata: z
|
|
33
|
+
.object({
|
|
34
|
+
requestId: z.string(),
|
|
35
|
+
timestamp: z.string(),
|
|
36
|
+
})
|
|
37
|
+
.optional(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// ============================================================================
|
|
41
|
+
// Proof Submission Schemas
|
|
42
|
+
// ============================================================================
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Tool Call Context Schema (AgentShield Extension)
|
|
46
|
+
* Optional plaintext context for dashboard enrichment
|
|
47
|
+
*/
|
|
48
|
+
const toolCallContextSchema = z.object({
|
|
49
|
+
tool: z.string().min(1, "Tool name is required"),
|
|
50
|
+
args: z.record(z.unknown()),
|
|
51
|
+
result: z.unknown().optional(),
|
|
52
|
+
scopeId: z.string().min(1, "scopeId is required to link context to proof"),
|
|
53
|
+
userIdentifier: z.string().optional(),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Consent Event Context Schema
|
|
58
|
+
* Represents consent-related events for audit tracking
|
|
59
|
+
*/
|
|
60
|
+
const consentEventContextSchema = z.object({
|
|
61
|
+
eventType: z.enum([
|
|
62
|
+
"consent:page_viewed",
|
|
63
|
+
"consent:approved",
|
|
64
|
+
"consent:delegation_created",
|
|
65
|
+
"consent:credential_required"
|
|
66
|
+
]),
|
|
67
|
+
timestamp: z.number().int().positive(),
|
|
68
|
+
sessionId: z.string().min(1),
|
|
69
|
+
userDid: z.string().optional(),
|
|
70
|
+
agentDid: z.string().min(1),
|
|
71
|
+
targetTools: z.array(z.string()).min(1), // ALWAYS array
|
|
72
|
+
scopes: z.array(z.string()).min(0),
|
|
73
|
+
delegationId: z.string().uuid().optional(),
|
|
74
|
+
projectId: z.string().uuid(),
|
|
75
|
+
termsAccepted: z.boolean().optional(),
|
|
76
|
+
credentialStatus: z.enum(["present", "required", "obtained"]).optional(),
|
|
77
|
+
oauthIdentity: z.object({
|
|
78
|
+
provider: z.string(),
|
|
79
|
+
identifier: z.string(),
|
|
80
|
+
}).optional(),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Proof submission request schema
|
|
85
|
+
*/
|
|
86
|
+
export const proofSubmissionRequestSchema = z.object({
|
|
87
|
+
session_id: z.string().max(100), // AgentShield session ID (may differ from MCP-I sessionId)
|
|
88
|
+
delegation_id: z.string().uuid().nullish(),
|
|
89
|
+
proofs: z.array(DetachedProofSchema).min(1),
|
|
90
|
+
// AgentShield extension: Optional context for dashboard enrichment
|
|
91
|
+
context: z
|
|
92
|
+
.object({
|
|
93
|
+
toolCalls: z.array(toolCallContextSchema).optional(),
|
|
94
|
+
consentEvents: z.array(consentEventContextSchema).optional(), // NEW: Consent events for audit tracking
|
|
95
|
+
mcpServerUrl: z.string().url().optional(), // MCP server URL for tool discovery
|
|
96
|
+
})
|
|
97
|
+
.optional(),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Proof submission response schema
|
|
102
|
+
*/
|
|
103
|
+
export const proofSubmissionResponseSchema = z.object({
|
|
104
|
+
success: z.boolean(),
|
|
105
|
+
accepted: z.number().int().min(0),
|
|
106
|
+
rejected: z.number().int().min(0),
|
|
107
|
+
outcomes: z.record(z.string(), z.number().int().min(0)).optional(), // Record<BouncerOutcome, number> - Optional because API may return empty object or omit it
|
|
108
|
+
errors: z
|
|
109
|
+
.array(
|
|
110
|
+
z.object({
|
|
111
|
+
proof_index: z.number().int().min(0),
|
|
112
|
+
error: z.object({
|
|
113
|
+
code: z.string(),
|
|
114
|
+
message: z.string(),
|
|
115
|
+
details: z.record(z.unknown()).optional(),
|
|
116
|
+
}),
|
|
117
|
+
})
|
|
118
|
+
)
|
|
119
|
+
.optional(),
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
// ============================================================================
|
|
123
|
+
// Delegation Verification Schemas
|
|
124
|
+
// ============================================================================
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Delegation credential schema
|
|
128
|
+
*/
|
|
129
|
+
export const delegationCredentialSchema = z.object({
|
|
130
|
+
agent_did: z.string(),
|
|
131
|
+
user_id: z.string().optional(),
|
|
132
|
+
user_identifier: z.string().optional(),
|
|
133
|
+
scopes: z.array(z.string()),
|
|
134
|
+
constraints: z.record(z.unknown()).optional(),
|
|
135
|
+
issued_at: z.number().int().positive(),
|
|
136
|
+
created_at: z.number().int().positive(),
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Delegation verification request schema
|
|
141
|
+
*/
|
|
142
|
+
export const verifyDelegationRequestSchema = z.object({
|
|
143
|
+
agent_did: z.string(),
|
|
144
|
+
credential_jwt: z.string().optional(), // Optional, omit (don't set to empty string) when not available for OAuth flow
|
|
145
|
+
delegation_token: z.string().optional(), // Optional, for stateless MCP servers
|
|
146
|
+
scopes: z.array(z.string()).optional(), // Optional, can be empty array
|
|
147
|
+
timestamp: z.number().int().positive().optional(),
|
|
148
|
+
client_info: z
|
|
149
|
+
.object({
|
|
150
|
+
ip_address: z.string().ip().optional(),
|
|
151
|
+
origin: z.string().url().optional(),
|
|
152
|
+
user_agent: z.string().optional(),
|
|
153
|
+
})
|
|
154
|
+
.optional(),
|
|
155
|
+
}).partial({ scopes: true }); // Make scopes truly optional by using partial
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Delegation verification response schema
|
|
159
|
+
*/
|
|
160
|
+
export const verifyDelegationResponseSchema = z.object({
|
|
161
|
+
valid: z.boolean(),
|
|
162
|
+
delegation: DelegationRecordSchema.optional(),
|
|
163
|
+
delegation_id: z.string().uuid().optional(),
|
|
164
|
+
credential: delegationCredentialSchema.optional(),
|
|
165
|
+
error: agentShieldAPIErrorSchema.optional(),
|
|
166
|
+
reason: z.string().optional(),
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Wrapped verification response schema
|
|
171
|
+
*/
|
|
172
|
+
export const verifyDelegationAPIResponseSchema = agentShieldAPIResponseSchema(
|
|
173
|
+
verifyDelegationResponseSchema
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
// ============================================================================
|
|
177
|
+
// Tool Protection Configuration Schemas
|
|
178
|
+
// ============================================================================
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* AgentShield tool protection schema (supports both snake_case and camelCase)
|
|
182
|
+
* This is the API-specific format, not the MCP-I spec schema
|
|
183
|
+
*/
|
|
184
|
+
export const agentShieldToolProtectionSchema = z
|
|
185
|
+
.object({
|
|
186
|
+
scopes: z.array(z.string()),
|
|
187
|
+
requires_delegation: z.boolean().optional(),
|
|
188
|
+
requiresDelegation: z.boolean().optional(),
|
|
189
|
+
required_scopes: z.array(z.string()).optional(),
|
|
190
|
+
})
|
|
191
|
+
.passthrough(); // Allow additional properties
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Tool protection config response schema
|
|
195
|
+
*/
|
|
196
|
+
export const toolProtectionConfigResponseSchema = z.object({
|
|
197
|
+
agent_did: z.string(),
|
|
198
|
+
tools: z.record(z.string(), agentShieldToolProtectionSchema),
|
|
199
|
+
reputation_threshold: z.number().min(0).max(1).optional(),
|
|
200
|
+
denied_agents: z.array(z.string()).optional(),
|
|
201
|
+
crisp_budget: z
|
|
202
|
+
.object({
|
|
203
|
+
max_tokens: z.number(),
|
|
204
|
+
max_cost: z.number(),
|
|
205
|
+
currency: z.string(),
|
|
206
|
+
time_window: z.string(),
|
|
207
|
+
})
|
|
208
|
+
.optional(),
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Wrapped config response schema
|
|
213
|
+
*/
|
|
214
|
+
export const toolProtectionConfigAPIResponseSchema =
|
|
215
|
+
agentShieldAPIResponseSchema(toolProtectionConfigResponseSchema);
|
|
216
|
+
|
|
217
|
+
// ============================================================================
|
|
218
|
+
// Delegation Management Schemas
|
|
219
|
+
// ============================================================================
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Create delegation request schema
|
|
223
|
+
*
|
|
224
|
+
* Note: AgentShield API accepts a simplified format, not the full DelegationRecord.
|
|
225
|
+
* The API accepts: agent_did, scopes, expires_in_days, expires_at, session_id, project_id, user_identifier, custom_fields
|
|
226
|
+
*
|
|
227
|
+
* IMPORTANT: expires_in_days and expires_at are mutually exclusive - use one or the other, not both.
|
|
228
|
+
*/
|
|
229
|
+
export const createDelegationRequestSchema = z
|
|
230
|
+
.object({
|
|
231
|
+
agent_did: z.string().min(1),
|
|
232
|
+
scopes: z.array(z.string()).min(1),
|
|
233
|
+
expires_in_days: z.number().int().positive().optional(),
|
|
234
|
+
expires_at: z.string().datetime().optional(),
|
|
235
|
+
session_id: z.string().optional(),
|
|
236
|
+
project_id: z.string().uuid().optional(),
|
|
237
|
+
user_identifier: z.string().max(200).optional(), // Matches AgentShield's max(200)
|
|
238
|
+
custom_fields: z.record(z.unknown()).optional(),
|
|
239
|
+
})
|
|
240
|
+
.passthrough()
|
|
241
|
+
.refine(
|
|
242
|
+
(data) => {
|
|
243
|
+
// expires_in_days and expires_at are mutually exclusive
|
|
244
|
+
const hasExpiresInDays = data.expires_in_days !== undefined;
|
|
245
|
+
const hasExpiresAt = data.expires_at !== undefined;
|
|
246
|
+
return !(hasExpiresInDays && hasExpiresAt);
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
message:
|
|
250
|
+
"expires_in_days and expires_at are mutually exclusive - use one or the other, not both",
|
|
251
|
+
path: ["expires_in_days", "expires_at"],
|
|
252
|
+
}
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Create delegation response schema
|
|
257
|
+
*
|
|
258
|
+
* Canonical format returned by POST /api/v1/bouncer/delegations
|
|
259
|
+
*
|
|
260
|
+
* IMPORTANT: delegation_token is NOT returned by this endpoint.
|
|
261
|
+
* delegation_token is only available via OAuth callback flow (/api/v1/bouncer/oauth/callback)
|
|
262
|
+
* and is passed as a URL parameter, not in the API response body.
|
|
263
|
+
*/
|
|
264
|
+
export const createDelegationResponseSchema = z.object({
|
|
265
|
+
delegation_id: z.string().uuid(),
|
|
266
|
+
agent_did: z.string().min(1),
|
|
267
|
+
user_id: z.string().optional(),
|
|
268
|
+
user_identifier: z.string().optional(),
|
|
269
|
+
scopes: z.array(z.string()),
|
|
270
|
+
status: z.enum(['active', 'expired', 'revoked']), // Matches AgentShield's actual API behavior
|
|
271
|
+
issued_at: z.string().datetime(),
|
|
272
|
+
expires_at: z.string().datetime().nullable().optional(), // AgentShield allows null values
|
|
273
|
+
created_at: z.string().datetime(),
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Wrapped creation response schema
|
|
278
|
+
*/
|
|
279
|
+
export const createDelegationAPIResponseSchema = agentShieldAPIResponseSchema(
|
|
280
|
+
createDelegationResponseSchema
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Revoke delegation request schema
|
|
285
|
+
*/
|
|
286
|
+
export const revokeDelegationRequestSchema = z.object({
|
|
287
|
+
reason: z.string().optional(),
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Revoke delegation response schema
|
|
292
|
+
*/
|
|
293
|
+
export const revokeDelegationResponseSchema = z.object({
|
|
294
|
+
delegation_id: z.string().uuid(),
|
|
295
|
+
revoked: z.boolean(),
|
|
296
|
+
revoked_at: z.number().int().positive(),
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Wrapped revocation response schema
|
|
301
|
+
*/
|
|
302
|
+
export const revokeDelegationAPIResponseSchema = agentShieldAPIResponseSchema(
|
|
303
|
+
revokeDelegationResponseSchema
|
|
304
|
+
);
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentShield/Bouncer API Type Definitions
|
|
3
|
+
*
|
|
4
|
+
* TypeScript interfaces matching the AgentShield dashboard API contract.
|
|
5
|
+
* These types ensure parity between xmcp-i clients and the AgentShield service.
|
|
6
|
+
*
|
|
7
|
+
* @package @kya-os/contracts/agentshield-api
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { DetachedProof } from "../proof.js";
|
|
11
|
+
import type { DelegationRecord } from "../delegation/index.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Standard AgentShield API response wrapper
|
|
15
|
+
*/
|
|
16
|
+
export interface AgentShieldAPIResponse<T> {
|
|
17
|
+
success: boolean;
|
|
18
|
+
data: T;
|
|
19
|
+
metadata?: {
|
|
20
|
+
requestId: string;
|
|
21
|
+
timestamp: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Standard AgentShield API error response structure
|
|
27
|
+
* (Use AgentShieldAPIError class for runtime errors)
|
|
28
|
+
*/
|
|
29
|
+
export interface AgentShieldAPIErrorResponse {
|
|
30
|
+
code: string;
|
|
31
|
+
message: string;
|
|
32
|
+
details?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ============================================================================
|
|
36
|
+
// Proof Submission API
|
|
37
|
+
// ============================================================================
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Tool Call Context (AgentShield Extension to MCP-I)
|
|
41
|
+
*
|
|
42
|
+
* Optional plaintext context for dashboard enrichment.
|
|
43
|
+
* Links to MCP-I proof via scopeId.
|
|
44
|
+
*/
|
|
45
|
+
export interface ToolCallContext {
|
|
46
|
+
tool: string; // Tool name (e.g., "greet", "searchProducts")
|
|
47
|
+
args: Record<string, unknown>; // Tool arguments from canonical request
|
|
48
|
+
result?: unknown; // Tool result from canonical response (optional)
|
|
49
|
+
scopeId: string; // Links to proof.meta.scopeId
|
|
50
|
+
userIdentifier?: string; // User context (optional)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Consent Event Context
|
|
55
|
+
*
|
|
56
|
+
* Represents consent-related events that occur during the consent flow.
|
|
57
|
+
* These events are logged separately from tool executions and allow
|
|
58
|
+
* multiple events per session (unlike regular audit logs).
|
|
59
|
+
*/
|
|
60
|
+
export interface ConsentEventContext {
|
|
61
|
+
eventType: "consent:page_viewed" | "consent:approved" | "consent:delegation_created" | "consent:credential_required";
|
|
62
|
+
timestamp: number;
|
|
63
|
+
sessionId: string;
|
|
64
|
+
userDid?: string;
|
|
65
|
+
agentDid: string;
|
|
66
|
+
targetTools: string[]; // ALWAYS array, even for single tool
|
|
67
|
+
scopes: string[];
|
|
68
|
+
delegationId?: string;
|
|
69
|
+
projectId: string;
|
|
70
|
+
termsAccepted?: boolean;
|
|
71
|
+
credentialStatus?: "present" | "required" | "obtained";
|
|
72
|
+
oauthIdentity?: {
|
|
73
|
+
provider: string;
|
|
74
|
+
identifier: string;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Request body for proof submission endpoint
|
|
80
|
+
* POST /api/v1/bouncer/proofs
|
|
81
|
+
*/
|
|
82
|
+
export interface ProofSubmissionRequest {
|
|
83
|
+
/** Delegation ID (nullable, optional - null if no delegation context) */
|
|
84
|
+
delegation_id?: string | null;
|
|
85
|
+
|
|
86
|
+
/** Session ID for grouping proofs (AgentShield session ID, may differ from MCP-I sessionId) */
|
|
87
|
+
session_id: string;
|
|
88
|
+
|
|
89
|
+
/** Array of proofs to submit */
|
|
90
|
+
proofs: DetachedProof[];
|
|
91
|
+
|
|
92
|
+
/** AgentShield extension: Optional context for dashboard enrichment */
|
|
93
|
+
context?: {
|
|
94
|
+
toolCalls?: ToolCallContext[];
|
|
95
|
+
consentEvents?: ConsentEventContext[]; // NEW: Consent events for audit tracking
|
|
96
|
+
mcpServerUrl?: string; // MCP server URL for tool discovery
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Bouncer outcome types
|
|
102
|
+
*/
|
|
103
|
+
export type BouncerOutcome = "success" | "failed" | "blocked" | "error";
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Response from proof submission endpoint
|
|
107
|
+
*/
|
|
108
|
+
export interface ProofSubmissionResponse {
|
|
109
|
+
success: boolean;
|
|
110
|
+
accepted: number;
|
|
111
|
+
rejected: number;
|
|
112
|
+
outcomes?: Record<BouncerOutcome, number>; // Optional - API may omit or return empty object
|
|
113
|
+
errors?: Array<{
|
|
114
|
+
proof_index: number;
|
|
115
|
+
error: {
|
|
116
|
+
code: string;
|
|
117
|
+
message: string;
|
|
118
|
+
details?: Record<string, unknown>;
|
|
119
|
+
};
|
|
120
|
+
}>;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// ============================================================================
|
|
124
|
+
// Delegation Verification API
|
|
125
|
+
// ============================================================================
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Request body for delegation verification endpoint
|
|
129
|
+
* POST /api/v1/bouncer/delegations/verify
|
|
130
|
+
*/
|
|
131
|
+
export interface VerifyDelegationRequest {
|
|
132
|
+
/** Agent DID to verify */
|
|
133
|
+
agent_did: string;
|
|
134
|
+
|
|
135
|
+
/** Credential JWT (optional, defaults to empty string for OAuth flow) */
|
|
136
|
+
credential_jwt?: string;
|
|
137
|
+
|
|
138
|
+
/** Delegation token from OAuth flow (optional, for stateless MCP servers) */
|
|
139
|
+
delegation_token?: string;
|
|
140
|
+
|
|
141
|
+
/** Required scopes (optional, can be empty array) */
|
|
142
|
+
scopes?: string[];
|
|
143
|
+
|
|
144
|
+
/** Optional timestamp for verification */
|
|
145
|
+
timestamp?: number;
|
|
146
|
+
|
|
147
|
+
/** Optional client info for IP/origin checking */
|
|
148
|
+
client_info?: {
|
|
149
|
+
ip_address?: string;
|
|
150
|
+
origin?: string;
|
|
151
|
+
user_agent?: string;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Credential information returned in verification response
|
|
157
|
+
*/
|
|
158
|
+
export interface DelegationCredential {
|
|
159
|
+
agent_did: string;
|
|
160
|
+
user_id?: string;
|
|
161
|
+
user_identifier?: string;
|
|
162
|
+
scopes: string[];
|
|
163
|
+
constraints?: Record<string, unknown>;
|
|
164
|
+
issued_at: number;
|
|
165
|
+
created_at: number;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Response from delegation verification endpoint
|
|
170
|
+
*/
|
|
171
|
+
export interface VerifyDelegationResponse {
|
|
172
|
+
valid: boolean;
|
|
173
|
+
delegation?: DelegationRecord;
|
|
174
|
+
delegation_id?: string;
|
|
175
|
+
credential?: DelegationCredential;
|
|
176
|
+
error?: AgentShieldAPIErrorResponse;
|
|
177
|
+
reason?: string;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Wrapped verification response (AgentShield wraps in success/data)
|
|
182
|
+
*/
|
|
183
|
+
export type VerifyDelegationAPIResponse =
|
|
184
|
+
AgentShieldAPIResponse<VerifyDelegationResponse>;
|
|
185
|
+
|
|
186
|
+
// ============================================================================
|
|
187
|
+
// Tool Protection Configuration API
|
|
188
|
+
// ============================================================================
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* AgentShield API tool protection format for a single tool
|
|
192
|
+
* This is the API-specific format, not the MCP-I spec type
|
|
193
|
+
*/
|
|
194
|
+
export interface AgentShieldToolProtection {
|
|
195
|
+
scopes: string[];
|
|
196
|
+
requires_delegation?: boolean;
|
|
197
|
+
requiresDelegation?: boolean; // Support both snake_case and camelCase
|
|
198
|
+
required_scopes?: string[]; // Alternative naming
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Response from tool protection config endpoint
|
|
203
|
+
* GET /api/v1/bouncer/projects/{projectId}/config
|
|
204
|
+
*/
|
|
205
|
+
export interface ToolProtectionConfigResponse {
|
|
206
|
+
agent_did: string;
|
|
207
|
+
tools: Record<string, AgentShieldToolProtection>;
|
|
208
|
+
reputation_threshold?: number;
|
|
209
|
+
denied_agents?: string[];
|
|
210
|
+
crisp_budget?: {
|
|
211
|
+
max_tokens: number;
|
|
212
|
+
max_cost: number;
|
|
213
|
+
currency: string;
|
|
214
|
+
time_window: string;
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Wrapped config response
|
|
220
|
+
*/
|
|
221
|
+
export type ToolProtectionConfigAPIResponse =
|
|
222
|
+
AgentShieldAPIResponse<ToolProtectionConfigResponse>;
|
|
223
|
+
|
|
224
|
+
// ============================================================================
|
|
225
|
+
// Delegation Management API
|
|
226
|
+
// ============================================================================
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Request body for creating a delegation
|
|
230
|
+
* POST /api/v1/bouncer/delegations
|
|
231
|
+
*
|
|
232
|
+
* Note: AgentShield API accepts a simplified format, not the full DelegationRecord.
|
|
233
|
+
* The API accepts: agent_did, scopes, expires_in_days, expires_at, session_id, project_id, user_identifier, custom_fields
|
|
234
|
+
*
|
|
235
|
+
* IMPORTANT: expires_in_days and expires_at are mutually exclusive - use one or the other, not both.
|
|
236
|
+
*/
|
|
237
|
+
export interface CreateDelegationRequest {
|
|
238
|
+
agent_did: string;
|
|
239
|
+
scopes: string[];
|
|
240
|
+
/** Number of days until expiration (1-365). Mutually exclusive with expires_at. */
|
|
241
|
+
expires_in_days?: number;
|
|
242
|
+
/** ISO 8601 datetime when delegation expires. Mutually exclusive with expires_in_days. */
|
|
243
|
+
expires_at?: string;
|
|
244
|
+
session_id?: string;
|
|
245
|
+
project_id?: string; // Usually extracted from API key, but can be provided
|
|
246
|
+
/** User identifier string, max 200 chars, optional */
|
|
247
|
+
user_identifier?: string;
|
|
248
|
+
custom_fields?: Record<string, unknown>;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Response from delegation creation endpoint
|
|
253
|
+
*
|
|
254
|
+
* Canonical format returned by POST /api/v1/bouncer/delegations
|
|
255
|
+
*
|
|
256
|
+
* IMPORTANT: delegation_token is NOT returned by this endpoint.
|
|
257
|
+
* delegation_token is only available via OAuth callback flow (/api/v1/bouncer/oauth/callback)
|
|
258
|
+
* and is passed as a URL parameter, not in the API response body.
|
|
259
|
+
*/
|
|
260
|
+
export interface CreateDelegationResponse {
|
|
261
|
+
delegation_id: string;
|
|
262
|
+
agent_did: string;
|
|
263
|
+
user_id?: string;
|
|
264
|
+
user_identifier?: string;
|
|
265
|
+
scopes: string[];
|
|
266
|
+
status: "active" | "expired" | "revoked"; // Matches AgentShield's actual API behavior
|
|
267
|
+
issued_at: string; // ISO 8601 datetime
|
|
268
|
+
expires_at?: string | null; // ISO 8601 datetime, nullable
|
|
269
|
+
created_at: string; // ISO 8601 datetime
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Wrapped creation response
|
|
274
|
+
*/
|
|
275
|
+
export type CreateDelegationAPIResponse =
|
|
276
|
+
AgentShieldAPIResponse<CreateDelegationResponse>;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Request body for revoking a delegation
|
|
280
|
+
* POST /api/v1/bouncer/delegations/{id}/revoke
|
|
281
|
+
*/
|
|
282
|
+
export interface RevokeDelegationRequest {
|
|
283
|
+
reason?: string;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Response from delegation revocation endpoint
|
|
288
|
+
*/
|
|
289
|
+
export interface RevokeDelegationResponse {
|
|
290
|
+
delegation_id: string;
|
|
291
|
+
revoked: boolean;
|
|
292
|
+
revoked_at: number;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Wrapped revocation response
|
|
297
|
+
*/
|
|
298
|
+
export type RevokeDelegationAPIResponse =
|
|
299
|
+
AgentShieldAPIResponse<RevokeDelegationResponse>;
|
|
300
|
+
|
|
301
|
+
// ============================================================================
|
|
302
|
+
// Error Types
|
|
303
|
+
// ============================================================================
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* AgentShield API error class
|
|
307
|
+
*/
|
|
308
|
+
export class AgentShieldAPIError extends Error {
|
|
309
|
+
constructor(
|
|
310
|
+
public readonly code: string,
|
|
311
|
+
message: string,
|
|
312
|
+
public readonly details?: Record<string, unknown>
|
|
313
|
+
) {
|
|
314
|
+
super(message);
|
|
315
|
+
this.name = "AgentShieldAPIError";
|
|
316
|
+
}
|
|
317
|
+
}
|