@kya-os/mcp-i-cloudflare 1.5.8-canary.1 → 1.5.8-canary.10

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.
Files changed (40) hide show
  1. package/dist/__tests__/e2e/test-config.d.ts +37 -0
  2. package/dist/__tests__/e2e/test-config.d.ts.map +1 -0
  3. package/dist/__tests__/e2e/test-config.js +62 -0
  4. package/dist/__tests__/e2e/test-config.js.map +1 -0
  5. package/dist/adapter.d.ts.map +1 -1
  6. package/dist/adapter.js +74 -28
  7. package/dist/adapter.js.map +1 -1
  8. package/dist/app.d.ts.map +1 -1
  9. package/dist/app.js +14 -0
  10. package/dist/app.js.map +1 -1
  11. package/dist/config.d.ts.map +1 -1
  12. package/dist/config.js +36 -2
  13. package/dist/config.js.map +1 -1
  14. package/dist/runtime/oauth-handler.d.ts.map +1 -1
  15. package/dist/runtime/oauth-handler.js +0 -92
  16. package/dist/runtime/oauth-handler.js.map +1 -1
  17. package/dist/runtime.d.ts +12 -0
  18. package/dist/runtime.d.ts.map +1 -1
  19. package/dist/runtime.js +36 -1
  20. package/dist/runtime.js.map +1 -1
  21. package/dist/server.d.ts +0 -4
  22. package/dist/server.d.ts.map +1 -1
  23. package/dist/server.js +48 -49
  24. package/dist/server.js.map +1 -1
  25. package/dist/services/admin.service.d.ts.map +1 -1
  26. package/dist/services/admin.service.js +15 -1
  27. package/dist/services/admin.service.js.map +1 -1
  28. package/dist/services/consent-audit.service.d.ts +91 -0
  29. package/dist/services/consent-audit.service.d.ts.map +1 -0
  30. package/dist/services/consent-audit.service.js +241 -0
  31. package/dist/services/consent-audit.service.js.map +1 -0
  32. package/dist/services/consent.service.d.ts +53 -0
  33. package/dist/services/consent.service.d.ts.map +1 -1
  34. package/dist/services/consent.service.js +1419 -40
  35. package/dist/services/consent.service.js.map +1 -1
  36. package/dist/services/proof.service.d.ts +5 -3
  37. package/dist/services/proof.service.d.ts.map +1 -1
  38. package/dist/services/proof.service.js +19 -6
  39. package/dist/services/proof.service.js.map +1 -1
  40. package/package.json +8 -5
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Consent Audit Service
3
+ *
4
+ * Handles audit logging for consent-related events.
5
+ * These events bypass session deduplication to allow multiple events per session.
6
+ */
7
+ import type { ProofService } from './proof.service';
8
+ import type { AuditLogger } from '@kya-os/mcp-i/runtime';
9
+ import { CloudflareProofGenerator } from '../proof-generator';
10
+ import type { CloudflareRuntimeConfig } from '../config';
11
+ import type { CloudflareRuntime } from '../runtime';
12
+ export declare class ConsentAuditService {
13
+ private proofService;
14
+ private auditLogger;
15
+ private proofGenerator;
16
+ private config;
17
+ private runtime;
18
+ private logger;
19
+ constructor(proofService: ProofService, auditLogger: AuditLogger, proofGenerator: CloudflareProofGenerator, config: CloudflareRuntimeConfig, runtime: CloudflareRuntime);
20
+ /**
21
+ * Create a minimal SessionContext for audit logging
22
+ * Only sessionId and audience are used by logEvent, but TypeScript requires full SessionContext
23
+ */
24
+ private createSessionContext;
25
+ /**
26
+ * Log consent page view event
27
+ */
28
+ logConsentPageView(event: {
29
+ sessionId: string;
30
+ agentDid: string;
31
+ targetTools: string[];
32
+ scopes: string[];
33
+ projectId: string;
34
+ }): Promise<void>;
35
+ /**
36
+ * Log consent approval event
37
+ */
38
+ logConsentApproval(event: {
39
+ sessionId: string;
40
+ userDid?: string;
41
+ agentDid: string;
42
+ targetTools: string[];
43
+ scopes: string[];
44
+ delegationId: string;
45
+ projectId: string;
46
+ termsAccepted: boolean;
47
+ oauthIdentity?: {
48
+ provider: string;
49
+ identifier: string;
50
+ };
51
+ }): Promise<void>;
52
+ /**
53
+ * Log when user needs credentials before delegation
54
+ */
55
+ logCredentialRequired(event: {
56
+ sessionId: string;
57
+ agentDid: string;
58
+ targetTools: string[];
59
+ scopes: string[];
60
+ projectId: string;
61
+ oauthProvider?: string;
62
+ }): Promise<void>;
63
+ /**
64
+ * Log delegation creation
65
+ */
66
+ logDelegationCreated(event: {
67
+ sessionId: string;
68
+ delegationId: string;
69
+ agentDid: string;
70
+ userDid?: string;
71
+ targetTools: string[];
72
+ scopes: string[];
73
+ projectId: string;
74
+ }): Promise<void>;
75
+ /**
76
+ * Generate proof for consent event
77
+ *
78
+ * IMPORTANT: Consent events use synthetic canonical request/response forms
79
+ * since they represent system events, not actual HTTP requests. The MCP-I
80
+ * proof spec allows synthetic forms for system-generated events that don't
81
+ * correspond to actual HTTP requests.
82
+ *
83
+ * ✅ FIXED: Added nonce generation, fixed SessionContext structure
84
+ */
85
+ private generateConsentProof;
86
+ /**
87
+ * Get server's actual identity (NO FALLBACK)
88
+ */
89
+ private getServerIdentity;
90
+ }
91
+ //# sourceMappingURL=consent-audit.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consent-audit.service.d.ts","sourceRoot":"","sources":["../../src/services/consent-audit.service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAI9D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGpD,qBAAa,mBAAmB;IAS5B,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,cAAc;IACtB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,OAAO;IAZjB,OAAO,CAAC,MAAM,CAKZ;gBAGQ,YAAY,EAAE,YAAY,EAC1B,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,wBAAwB,EACxC,MAAM,EAAE,uBAAuB,EAC/B,OAAO,EAAE,iBAAiB;IAGpC;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IAe5B;;OAEG;IACG,kBAAkB,CAAC,KAAK,EAAE;Q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CAAC;IA+BjB;;;;;;;;;OASG;YACW,oBAAoB;IAuDlC;;OAEG;YACW,iBAAiB;CAkBhC"}
@@ -0,0 +1,241 @@
1
+ /**
2
+ * Consent Audit Service
3
+ *
4
+ * Handles audit logging for consent-related events.
5
+ * These events bypass session deduplication to allow multiple events per session.
6
+ */
7
+ export class ConsentAuditService {
8
+ proofService;
9
+ auditLogger;
10
+ proofGenerator;
11
+ config;
12
+ runtime;
13
+ logger = {
14
+ error: (message, meta) => {
15
+ console.error(`[ConsentAuditService] ${message}`, meta);
16
+ // TODO: Send to error tracking service
17
+ }
18
+ };
19
+ constructor(proofService, auditLogger, proofGenerator, config, runtime // REQUIRED for identity
20
+ ) {
21
+ this.proofService = proofService;
22
+ this.auditLogger = auditLogger;
23
+ this.proofGenerator = proofGenerator;
24
+ this.config = config;
25
+ this.runtime = runtime;
26
+ }
27
+ /**
28
+ * Create a minimal SessionContext for audit logging
29
+ * Only sessionId and audience are used by logEvent, but TypeScript requires full SessionContext
30
+ */
31
+ createSessionContext(sessionId) {
32
+ const now = Math.floor(Date.now() / 1000);
33
+ // Audience is typically from the handshake, but for consent events we use a default
34
+ const audience = "https://kya.vouched.id";
35
+ return {
36
+ sessionId,
37
+ audience,
38
+ nonce: '', // Not used by logEvent, but required by type
39
+ timestamp: now,
40
+ createdAt: now,
41
+ lastActivity: now,
42
+ ttlMinutes: 30,
43
+ };
44
+ }
45
+ /**
46
+ * Log consent page view event
47
+ */
48
+ async logConsentPageView(event) {
49
+ const timestamp = Date.now();
50
+ const identity = await this.getServerIdentity();
51
+ // Log to audit system (bypasses session deduplication)
52
+ await this.auditLogger.logEvent({
53
+ eventType: "consent:page_viewed",
54
+ identity,
55
+ session: this.createSessionContext(event.sessionId),
56
+ eventData: event
57
+ });
58
+ // Generate proof for dashboard
59
+ const proof = await this.generateConsentProof("consent:page_viewed", event, timestamp);
60
+ await this.proofService.submitProof(proof, {
61
+ session: { id: event.sessionId },
62
+ consentEvent: {
63
+ eventType: "consent:page_viewed",
64
+ timestamp,
65
+ sessionId: event.sessionId,
66
+ agentDid: event.agentDid,
67
+ targetTools: event.targetTools,
68
+ scopes: event.scopes,
69
+ projectId: event.projectId
70
+ }
71
+ });
72
+ }
73
+ /**
74
+ * Log consent approval event
75
+ */
76
+ async logConsentApproval(event) {
77
+ const timestamp = Date.now();
78
+ const identity = await this.getServerIdentity();
79
+ // Log to audit system
80
+ await this.auditLogger.logEvent({
81
+ eventType: "consent:approved",
82
+ identity,
83
+ session: this.createSessionContext(event.sessionId),
84
+ eventData: event
85
+ });
86
+ // Generate proof
87
+ const proof = await this.generateConsentProof("consent:approved", event, timestamp);
88
+ await this.proofService.submitProof(proof, {
89
+ session: { id: event.sessionId },
90
+ consentEvent: {
91
+ eventType: "consent:approved",
92
+ timestamp,
93
+ sessionId: event.sessionId,
94
+ userDid: event.userDid,
95
+ agentDid: event.agentDid,
96
+ targetTools: event.targetTools,
97
+ scopes: event.scopes,
98
+ delegationId: event.delegationId,
99
+ projectId: event.projectId,
100
+ termsAccepted: event.termsAccepted,
101
+ oauthIdentity: event.oauthIdentity
102
+ }
103
+ });
104
+ }
105
+ /**
106
+ * Log when user needs credentials before delegation
107
+ */
108
+ async logCredentialRequired(event) {
109
+ const timestamp = Date.now();
110
+ const identity = await this.getServerIdentity();
111
+ // Log to audit system
112
+ await this.auditLogger.logEvent({
113
+ eventType: "consent:credential_required",
114
+ identity,
115
+ session: this.createSessionContext(event.sessionId),
116
+ eventData: event
117
+ });
118
+ // Generate proof
119
+ const proof = await this.generateConsentProof("consent:credential_required", event, timestamp);
120
+ await this.proofService.submitProof(proof, {
121
+ session: { id: event.sessionId },
122
+ consentEvent: {
123
+ eventType: "consent:credential_required",
124
+ timestamp,
125
+ sessionId: event.sessionId,
126
+ agentDid: event.agentDid,
127
+ targetTools: event.targetTools,
128
+ scopes: event.scopes,
129
+ projectId: event.projectId,
130
+ credentialStatus: "required",
131
+ oauthIdentity: event.oauthProvider ? {
132
+ provider: event.oauthProvider,
133
+ identifier: ""
134
+ } : undefined
135
+ }
136
+ });
137
+ }
138
+ /**
139
+ * Log delegation creation
140
+ */
141
+ async logDelegationCreated(event) {
142
+ const timestamp = Date.now();
143
+ const identity = await this.getServerIdentity();
144
+ // Log to audit system
145
+ await this.auditLogger.logEvent({
146
+ eventType: "consent:delegation_created",
147
+ identity,
148
+ session: this.createSessionContext(event.sessionId),
149
+ eventData: event
150
+ });
151
+ // Generate proof
152
+ const proof = await this.generateConsentProof("consent:delegation_created", event, timestamp);
153
+ await this.proofService.submitProof(proof, {
154
+ session: { id: event.sessionId },
155
+ consentEvent: {
156
+ eventType: "consent:delegation_created",
157
+ timestamp,
158
+ sessionId: event.sessionId,
159
+ delegationId: event.delegationId,
160
+ agentDid: event.agentDid,
161
+ userDid: event.userDid,
162
+ targetTools: event.targetTools,
163
+ scopes: event.scopes,
164
+ projectId: event.projectId
165
+ }
166
+ });
167
+ }
168
+ /**
169
+ * Generate proof for consent event
170
+ *
171
+ * IMPORTANT: Consent events use synthetic canonical request/response forms
172
+ * since they represent system events, not actual HTTP requests. The MCP-I
173
+ * proof spec allows synthetic forms for system-generated events that don't
174
+ * correspond to actual HTTP requests.
175
+ *
176
+ * ✅ FIXED: Added nonce generation, fixed SessionContext structure
177
+ */
178
+ async generateConsentProof(eventType, event, timestamp) {
179
+ const identity = await this.getServerIdentity();
180
+ // ✅ CRITICAL: Generate nonce for this session (REQUIRED by SessionContext)
181
+ const nonce = await this.runtime.issueNonce(event.sessionId);
182
+ // Synthetic canonical forms for consent events
183
+ // Use ToolRequest/ToolResponse format expected by CloudflareProofGenerator
184
+ const canonicalRequest = {
185
+ method: "POST",
186
+ params: {
187
+ eventType,
188
+ timestamp,
189
+ ...event
190
+ }
191
+ };
192
+ const canonicalResponse = {
193
+ data: {
194
+ success: true,
195
+ eventType,
196
+ timestamp,
197
+ serverDid: identity.did
198
+ }
199
+ };
200
+ // ✅ FIXED: Build SessionContext with all required fields
201
+ // ✅ FIXED: Remove agentDid and clientDid from SessionContext (not part of spec)
202
+ // ✅ FIXED: Move clientDid to ProofOptions
203
+ const now = Math.floor(Date.now() / 1000);
204
+ const sessionContext = {
205
+ sessionId: event.sessionId,
206
+ nonce, // ✅ REQUIRED - was missing!
207
+ audience: "https://kya.vouched.id",
208
+ timestamp: now,
209
+ createdAt: now,
210
+ lastActivity: now,
211
+ ttlMinutes: 30,
212
+ };
213
+ return await this.proofGenerator.generateProof(canonicalRequest, canonicalResponse, sessionContext, // Only nonce, audience, sessionId
214
+ {
215
+ scopeId: eventType,
216
+ clientDid: event.userDid // ✅ clientDid belongs in options, not session
217
+ });
218
+ }
219
+ /**
220
+ * Get server's actual identity (NO FALLBACK)
221
+ */
222
+ async getServerIdentity() {
223
+ if (!this.runtime) {
224
+ throw new Error("Runtime required for consent audit - cannot use fallback identity");
225
+ }
226
+ try {
227
+ const identity = await this.runtime.getIdentity();
228
+ if (!identity) {
229
+ throw new Error("No active identity available");
230
+ }
231
+ return identity;
232
+ }
233
+ catch (error) {
234
+ this.logger.error("Failed to get server identity", {
235
+ error: error instanceof Error ? error.message : String(error)
236
+ });
237
+ throw new Error("Server identity required for consent audit logging");
238
+ }
239
+ }
240
+ }
241
+ //# sourceMappingURL=consent-audit.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consent-audit.service.js","sourceRoot":"","sources":["../../src/services/consent-audit.service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAYH,MAAM,OAAO,mBAAmB;IASpB;IACA;IACA;IACA;IACA;IAZF,MAAM,GAAG;QACf,KAAK,EAAE,CAAC,OAAe,EAAE,IAAyB,EAAE,EAAE;YACpD,OAAO,CAAC,KAAK,CAAC,yBAAyB,OAAO,EAAE,EAAE,IAAI,CAAC,CAAC;YACxD,uCAAuC;QACzC,CAAC;KACF,CAAC;IAEF,YACU,YAA0B,EAC1B,WAAwB,EACxB,cAAwC,EACxC,MAA+B,EAC/B,OAA0B,CAAC,wBAAwB;;QAJnD,iBAAY,GAAZ,YA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E;gBACjD,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;aAC9D,CAAC,CAAC;YACH,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACxE,CAAC;IACH,CAAC;CACF"}
@@ -15,7 +15,40 @@ export declare class ConsentService {
15
15
  private env;
16
16
  private runtime?;
17
17
  private userDidManager?;
18
+ private auditService?;
19
+ private auditInitPromise?;
20
+ /**
21
+ * ✅ FIXED: Constructor takes env: CloudflareEnv, not config
22
+ */
18
23
  constructor(env: CloudflareEnv, runtime?: CloudflareRuntime);
24
+ /**
25
+ * Get or initialize audit service (lazy initialization)
26
+ *
27
+ * Fetches config from remote API when projectId is available.
28
+ * Uses promise caching to prevent race conditions.
29
+ *
30
+ * @param projectId - Project ID from consent request (required for config fetch)
31
+ */
32
+ private getAuditService;
33
+ /**
34
+ * Initialize audit service - fetches config from remote API
35
+ *
36
+ * ⚠️ CRITICAL: Fetches config from remote API using fetchRemoteConfig()
37
+ * This is the ONLY way to get CloudflareRuntimeConfig per requirement.
38
+ */
39
+ private initializeAuditService;
40
+ /**
41
+ * Fetch CloudflareRuntimeConfig from remote API (AgentShield)
42
+ *
43
+ * ⚠️ CRITICAL: Config MUST be fetched from remote API, not constructed from env.
44
+ *
45
+ * Uses existing `fetchRemoteConfig()` from `@kya-os/mcp-i-core/config/remote-config`
46
+ * which handles caching, error handling, and API communication.
47
+ *
48
+ * @param projectId - Project ID from consent request
49
+ * @returns Runtime config or undefined if unavailable
50
+ */
51
+ private getConfigFromRemoteAPI;
19
52
  /**
20
53
  * Get or generate User DID for a session
21
54
  *
@@ -94,6 +127,16 @@ export declare class ConsentService {
94
127
  * @returns HTML response
95
128
  */
96
129
  private renderConsentPage;
130
+ /**
131
+ * Parse request body from JSON or FormData
132
+ *
133
+ * Handles both JSON and FormData/multipart requests, converting
134
+ * FormData fields to the correct format for ConsentApprovalRequest.
135
+ *
136
+ * @param request - Request to parse
137
+ * @returns Parsed body object
138
+ */
139
+ private parseRequestBody;
97
140
  /**
98
141
  * Handle consent approval
99
142
  *
@@ -152,6 +195,13 @@ export declare class ConsentService {
152
195
  private isValidUUID;
153
196
  /**
154
197
  * Build simplified format request with proper field name
198
+ *
199
+ * CRITICAL: This method MUST NOT include session_id or project_id in the request body.
200
+ * These fields are NOT part of AgentShield's createDelegationSchema:
201
+ * - project_id is extracted from API key context by AgentShield middleware
202
+ * - session_id is not needed for delegation creation
203
+ *
204
+ * Including these fields will cause validation errors (400 Bad Request).
155
205
  */
156
206
  private buildSimplifiedFormatRequest;
157
207
  /**
@@ -160,6 +210,9 @@ export declare class ConsentService {
160
210
  private tryAPICall;
161
211
  /**
162
212
  * Make API call and parse response
213
+ *
214
+ * CRITICAL: This method ensures session_id and project_id are never sent to AgentShield.
215
+ * These fields are NOT part of the createDelegationSchema and will cause validation errors.
163
216
  */
164
217
  private makeAPICall;
165
218
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"consent.service.d.ts","sourceRoot":"","sources":["../../src/services/consent.service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAWpD,OAAO,KAAK,EAIV,aAAa,EACd,MAAM,2BAA2B,CAAC;AAenC,qBAAa,cAAc;IACzB,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,GAAG,CAAgB;IAC3B,OAAO,CAAC,OAAO,CAAC,CAAoB;IACpC,OAAO,CAAC,cAAc,CAAC,CAAiB;gBAE5B,GAAG,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,iBAAiB;IAO3D;;;;;;;;;OASG;YACW,oBAAoB;IA4GlC;;;;;;;;;;;OAWG;IACG,eAAe,CACnB,SAAS,E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