@kya-os/mcp-i-cloudflare 1.4.1-canary.1 → 1.4.1-canary.11

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 (54) hide show
  1. package/README.md +120 -1
  2. package/dist/adapter.d.ts +6 -0
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/adapter.js +29 -0
  5. package/dist/adapter.js.map +1 -1
  6. package/dist/agent.d.ts.map +1 -1
  7. package/dist/agent.js +13 -0
  8. package/dist/agent.js.map +1 -1
  9. package/dist/app.d.ts +6 -3
  10. package/dist/app.d.ts.map +1 -1
  11. package/dist/app.js +14 -1
  12. package/dist/app.js.map +1 -1
  13. package/dist/config.d.ts.map +1 -1
  14. package/dist/config.js +19 -2
  15. package/dist/config.js.map +1 -1
  16. package/dist/index.d.ts +3 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +5 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/runtime.d.ts +22 -8
  21. package/dist/runtime.d.ts.map +1 -1
  22. package/dist/runtime.js +130 -28
  23. package/dist/runtime.js.map +1 -1
  24. package/dist/server.d.ts.map +1 -1
  25. package/dist/server.js +23 -4
  26. package/dist/server.js.map +1 -1
  27. package/dist/services/admin.service.d.ts.map +1 -1
  28. package/dist/services/admin.service.js +36 -3
  29. package/dist/services/admin.service.js.map +1 -1
  30. package/dist/services/consent-config.service.d.ts +46 -0
  31. package/dist/services/consent-config.service.d.ts.map +1 -0
  32. package/dist/services/consent-config.service.js +157 -0
  33. package/dist/services/consent-config.service.js.map +1 -0
  34. package/dist/services/consent-page-renderer.d.ts +137 -0
  35. package/dist/services/consent-page-renderer.d.ts.map +1 -0
  36. package/dist/services/consent-page-renderer.js +539 -0
  37. package/dist/services/consent-page-renderer.js.map +1 -0
  38. package/dist/services/consent.service.d.ts +58 -3
  39. package/dist/services/consent.service.d.ts.map +1 -1
  40. package/dist/services/consent.service.js +373 -18
  41. package/dist/services/consent.service.js.map +1 -1
  42. package/dist/services/proof-batch-queue.d.ts +104 -0
  43. package/dist/services/proof-batch-queue.d.ts.map +1 -0
  44. package/dist/services/proof-batch-queue.js +209 -0
  45. package/dist/services/proof-batch-queue.js.map +1 -0
  46. package/dist/services/proof.service.d.ts +38 -1
  47. package/dist/services/proof.service.d.ts.map +1 -1
  48. package/dist/services/proof.service.js +214 -21
  49. package/dist/services/proof.service.js.map +1 -1
  50. package/dist/services/transport.service.d.ts +47 -0
  51. package/dist/services/transport.service.d.ts.map +1 -0
  52. package/dist/services/transport.service.js +76 -0
  53. package/dist/services/transport.service.js.map +1 -0
  54. package/package.json +2 -2
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Proof Batch Queue (Cloudflare Workers Implementation)
3
+ *
4
+ * Platform-agnostic proof batching for Cloudflare Workers.
5
+ * Copied from @kya-os/mcp-i to avoid pulling in @swc/core dependency.
6
+ *
7
+ * Collects proofs in memory and submits them in batches to AgentShield.
8
+ * This prevents blocking tool execution while ensuring proofs are eventually submitted.
9
+ *
10
+ * Performance:
11
+ * - Batch size: 10 proofs (configurable)
12
+ * - Flush interval: 5 seconds (configurable)
13
+ * - Fire-and-forget submission (doesn't block tool execution)
14
+ *
15
+ * Retry Strategy:
16
+ * - Exponential backoff: 1s, 2s, 4s, 8s, 16s
17
+ * - Max retries: 5
18
+ * - Failed proofs logged and dropped after max retries
19
+ */
20
+ /**
21
+ * AgentShield proof submission destination
22
+ *
23
+ * Submits proofs to AgentShield's /api/v1/bouncer/proofs endpoint
24
+ * with proper authentication and session grouping.
25
+ */
26
+ export class AgentShieldProofDestination {
27
+ name = 'AgentShield';
28
+ apiUrl;
29
+ apiKey;
30
+ constructor(apiUrl, apiKey) {
31
+ this.apiUrl = apiUrl.replace(/\/$/, '');
32
+ this.apiKey = apiKey;
33
+ }
34
+ async submit(proofs) {
35
+ if (proofs.length === 0) {
36
+ return;
37
+ }
38
+ // Extract session_id from first proof for AgentShield session grouping
39
+ // AgentShield uses this for analytics and detection monitoring
40
+ const sessionId = proofs[0]?.meta?.sessionId || 'unknown';
41
+ // AgentShield API format requires delegation_id and session_id wrapper
42
+ const requestBody = {
43
+ delegation_id: null, // null for proofs without delegation context
44
+ session_id: sessionId, // AgentShield session grouping (same as meta.sessionId)
45
+ proofs: proofs
46
+ };
47
+ const response = await fetch(`${this.apiUrl}/api/v1/bouncer/proofs`, {
48
+ method: 'POST',
49
+ headers: {
50
+ 'Content-Type': 'application/json',
51
+ 'Authorization': `Bearer ${this.apiKey}`, // Bearer token format
52
+ },
53
+ body: JSON.stringify(requestBody),
54
+ });
55
+ if (!response.ok) {
56
+ // Include response body in error for debugging
57
+ const errorBody = await response.text().catch(() => 'Unable to read error body');
58
+ throw new Error(`AgentShield proof submission failed: ${response.status} ${response.statusText}\n${errorBody}`);
59
+ }
60
+ }
61
+ }
62
+ /**
63
+ * Proof Batch Queue
64
+ *
65
+ * Collects proofs and submits them in batches to multiple destinations.
66
+ *
67
+ * Note: In Cloudflare Workers, timers don't persist across requests,
68
+ * so automatic flush timers are disabled. Use manual flush() calls via cron jobs.
69
+ */
70
+ export class ProofBatchQueue {
71
+ queue = [];
72
+ pendingBatches = [];
73
+ config;
74
+ closed = false;
75
+ // Stats
76
+ stats = {
77
+ queued: 0,
78
+ submitted: 0,
79
+ failed: 0,
80
+ batchesSubmitted: 0,
81
+ };
82
+ constructor(config) {
83
+ this.config = {
84
+ destinations: config.destinations,
85
+ maxBatchSize: config.maxBatchSize || 10,
86
+ flushIntervalMs: config.flushIntervalMs || 5000,
87
+ maxRetries: config.maxRetries || 5,
88
+ debug: config.debug || false,
89
+ };
90
+ // Note: Timers are disabled in Cloudflare Workers
91
+ // Flush must be called manually via cron jobs
92
+ }
93
+ /**
94
+ * Add proof to queue
95
+ */
96
+ enqueue(proof) {
97
+ if (this.closed) {
98
+ console.warn('[ProofBatchQueue] Queue is closed, dropping proof');
99
+ return;
100
+ }
101
+ this.queue.push(proof);
102
+ this.stats.queued++;
103
+ if (this.config.debug) {
104
+ console.log(`[ProofBatchQueue] Enqueued proof (queue size: ${this.queue.length})`);
105
+ }
106
+ // Flush immediately if batch size reached (Cloudflare Workers compatible)
107
+ if (this.queue.length >= this.config.maxBatchSize) {
108
+ this.flush();
109
+ }
110
+ }
111
+ /**
112
+ * Flush queue immediately (submit all queued proofs)
113
+ */
114
+ async flush() {
115
+ if (this.queue.length === 0) {
116
+ return;
117
+ }
118
+ const proofs = this.queue.splice(0, this.config.maxBatchSize);
119
+ if (this.config.debug) {
120
+ console.log(`[ProofBatchQueue] Flushing ${proofs.length} proofs to ${this.config.destinations.length} destinations`);
121
+ }
122
+ // Submit to all destinations
123
+ for (const destination of this.config.destinations) {
124
+ const batch = {
125
+ proofs: [...proofs], // Copy proofs for each destination
126
+ destination,
127
+ retryCount: 0,
128
+ };
129
+ this.submitBatch(batch); // Fire-and-forget
130
+ }
131
+ }
132
+ /**
133
+ * Submit batch to destination (with retries)
134
+ */
135
+ async submitBatch(batch) {
136
+ try {
137
+ await batch.destination.submit(batch.proofs);
138
+ this.stats.submitted += batch.proofs.length;
139
+ this.stats.batchesSubmitted++;
140
+ if (this.config.debug) {
141
+ console.log(`[ProofBatchQueue] Successfully submitted ${batch.proofs.length} proofs to ${batch.destination.name}`);
142
+ }
143
+ }
144
+ catch (error) {
145
+ console.error(`[ProofBatchQueue] Failed to submit to ${batch.destination.name}:`, error);
146
+ // Retry with exponential backoff
147
+ if (batch.retryCount < this.config.maxRetries) {
148
+ batch.retryCount++;
149
+ const backoffMs = Math.min(1000 * Math.pow(2, batch.retryCount - 1), 16000);
150
+ batch.nextRetryAt = Date.now() + backoffMs;
151
+ this.pendingBatches.push(batch);
152
+ if (this.config.debug) {
153
+ console.log(`[ProofBatchQueue] Scheduling retry ${batch.retryCount}/${this.config.maxRetries} in ${backoffMs}ms`);
154
+ }
155
+ }
156
+ else {
157
+ // Max retries exceeded, drop batch
158
+ this.stats.failed += batch.proofs.length;
159
+ console.error(`[ProofBatchQueue] Max retries exceeded for ${batch.destination.name}, dropping ${batch.proofs.length} proofs`);
160
+ }
161
+ }
162
+ }
163
+ /**
164
+ * Retry pending batches that are ready
165
+ * Called by cron job or manually
166
+ */
167
+ async retryPending() {
168
+ const now = Date.now();
169
+ const retryBatches = this.pendingBatches.filter((batch) => batch.nextRetryAt && batch.nextRetryAt <= now);
170
+ if (retryBatches.length > 0) {
171
+ // Remove from pending
172
+ this.pendingBatches = this.pendingBatches.filter((batch) => !retryBatches.includes(batch));
173
+ // Retry each batch
174
+ for (const batch of retryBatches) {
175
+ this.submitBatch(batch); // Fire-and-forget
176
+ }
177
+ }
178
+ }
179
+ /**
180
+ * Close queue and flush remaining proofs
181
+ */
182
+ async close() {
183
+ if (this.closed) {
184
+ return;
185
+ }
186
+ this.closed = true;
187
+ // Flush remaining proofs
188
+ if (this.queue.length > 0) {
189
+ await this.flush();
190
+ }
191
+ // Wait for pending batches (with timeout)
192
+ const timeout = 5000; // 5 seconds
193
+ const startTime = Date.now();
194
+ while (this.pendingBatches.length > 0 && Date.now() - startTime < timeout) {
195
+ await this.retryPending();
196
+ await new Promise((resolve) => setTimeout(resolve, 100));
197
+ }
198
+ if (this.pendingBatches.length > 0) {
199
+ console.warn(`[ProofBatchQueue] Closing with ${this.pendingBatches.length} pending batches (timed out)`);
200
+ }
201
+ }
202
+ /**
203
+ * Get queue statistics
204
+ */
205
+ getStats() {
206
+ return { ...this.stats };
207
+ }
208
+ }
209
+ //# sourceMappingURL=proof-batch-queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proof-batch-queue.js","sourceRoot":"","sources":["../../src/services/proof-batch-queue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAeH;;;;;GAKG;AACH,MAAM,OAAO,2BAA2B;IACtC,IAAI,GAAG,aAAa,CAAC;IACb,MAAM,CAAS;IACf,MAAM,CAAS;IAEvB,YAAY,MAAc,EAAE,MAAc;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,OAA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
5
  * for dashboard integration.
6
+ *
7
+ * Supports both direct submission and batch queue submission.
6
8
  */
7
9
  import type { DetachedProof } from '@kya-os/contracts/proof';
8
10
  import type { CloudflareRuntimeConfig } from '../config';
@@ -19,14 +21,49 @@ export interface ProofSubmissionContext {
19
21
  export declare class ProofService {
20
22
  private config;
21
23
  private runtime?;
24
+ private batchQueue?;
25
+ private firstProofSubmitted;
22
26
  constructor(config: CloudflareRuntimeConfig, runtime?: CloudflareRuntime);
23
27
  /**
24
28
  * Submit proof to AgentShield API
25
- * Uses the proof.jws directly (full JWS format from CloudflareRuntime)
29
+ * Uses batch queue if available, otherwise falls back to direct submission.
26
30
  *
27
31
  * Also submits optional context for AgentShield dashboard integration.
28
32
  * Context provides plaintext tool/args data while proof provides cryptographic verification.
33
+ *
34
+ * IMPORTANT: First proof is submitted immediately (not batched) to ensure
35
+ * dashboard setup detection works correctly.
29
36
  */
30
37
  submitProof(proof: DetachedProof, context: ProofSubmissionContext): Promise<void>;
38
+ /**
39
+ * Direct proof submission (fallback when batch queue not available)
40
+ */
41
+ private submitProofDirect;
42
+ /**
43
+ * Flush pending proofs in batch queue
44
+ *
45
+ * Called by scheduled cron job (configured in wrangler.toml).
46
+ *
47
+ * Cron Configuration:
48
+ * Add this to your wrangler.toml to enable automatic proof flushing:
49
+ *
50
+ * [triggers.crons]
51
+ * cron = "every 5 minutes" # Flush proof batches every 5 minutes
52
+ *
53
+ * The cron job will call the scheduled handler exported from your Worker,
54
+ * which routes to MCPICloudflareServer.handleScheduled(), which then calls
55
+ * this flush() method.
56
+ *
57
+ * Why cron instead of timers?
58
+ * - Cloudflare Workers are stateless and don't persist timers across requests
59
+ * - Cron jobs provide reliable cross-request batching
60
+ * - Proofs are still batched within requests (auto-flush when batch size reached)
61
+ *
62
+ * Flush frequency:
63
+ * - Default: Every minute (adjustable in wrangler.toml)
64
+ * - Proofs are also flushed immediately when batch size is reached
65
+ * - Failed proofs are retried with exponential backoff
66
+ */
67
+ flush(): Promise<void>;
31
68
  }
32
69
  //# sourceMappingURL=proof.service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"proof.service.d.ts","sourceRoot":"","sources":["../../src/services/proof.service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAmB,MAAM,YAAY,CAAC;AAGrE,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,OAAO,CAAC,CAAoB;gBAExB,MAAM,EAAE,uBAAuB,EAAE,OAAO,CAAC,EAAE,iBAAiB;IAKxE;;;;;;OAMG;IACG,WAAW,CACf,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,IAAI,CAAC;CA6FjB"}
1
+ {"version":3,"file":"proof.service.d.ts","sourceRoot":"","sources":["../../src/services/proof.service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,KAAK,EAAE,iBAAiB,EAAmB,MAAM,YAAY,CAAC;AAIrE,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,OAAO,CAAC,CAAoB;IACpC,OAAO,CAAC,UAAU,CAAC,CAAkB;IACrC,OAAO,CAAC,mBAAmB,CAAS;gBAExB,MAAM,EAAE,uBAAuB,EAAE,OAAO,CAAC,EAAE,iBAAiB;IAkFxE;;;;;;;;;OASG;IACG,WAAW,CACf,KAAK,EAAE,aAAa,EACpB,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,IAAI,CAAC;IA0ChB;;OAEG;YACW,iBAAiB;IAmI/B;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ7B"}
@@ -3,26 +3,141 @@
3
3
  *
4
4
  * Handles proof submission to AgentShield API with optional context
5
5
  * for dashboard integration.
6
+ *
7
+ * Supports both direct submission and batch queue submission.
6
8
  */
9
+ import { ProofBatchQueue, AgentShieldProofDestination } from './proof-batch-queue';
7
10
  export class ProofService {
8
11
  config;
9
12
  runtime;
13
+ batchQueue;
14
+ firstProofSubmitted = false; // Track if first proof has been submitted
10
15
  constructor(config, runtime) {
11
16
  this.config = config;
12
17
  this.runtime = runtime;
18
+ // Log service creation for debugging
19
+ const proofingConfig = this.config.proofing;
20
+ const hasApiKey = proofingConfig?.batchQueue?.destinations?.some((dest) => dest.type === 'agentshield' && dest.apiKey);
21
+ console.log('[ProofService] Initialized:', {
22
+ proofingEnabled: proofingConfig?.enabled || false,
23
+ hasApiKey: !!hasApiKey,
24
+ hasDestinations: !!(proofingConfig?.batchQueue?.destinations?.length),
25
+ destinationCount: proofingConfig?.batchQueue?.destinations?.length || 0,
26
+ apiKeyPresent: !!proofingConfig?.batchQueue?.destinations?.[0]?.apiKey,
27
+ apiUrl: proofingConfig?.batchQueue?.destinations?.[0]?.apiUrl || 'not-set',
28
+ });
29
+ // Warn if proofing is enabled but no API key is configured
30
+ if (proofingConfig?.enabled && !hasApiKey) {
31
+ console.warn('[ProofService] ⚠️ Proofing is enabled but AGENTSHIELD_API_KEY is not set!');
32
+ console.warn('[ProofService] To enable proof submission:');
33
+ console.warn('[ProofService] 1. Set AGENTSHIELD_API_KEY in .dev.vars (for local dev)');
34
+ console.warn('[ProofService] 2. Run: wrangler secret put AGENTSHIELD_API_KEY (for production)');
35
+ }
36
+ // Initialize batch queue if configured
37
+ // Note: In Cloudflare Workers, timers don't persist across requests,
38
+ // so we rely on manual flush() calls via cron jobs instead of automatic timers
39
+ if (proofingConfig?.enabled && proofingConfig.batchQueue?.destinations?.length) {
40
+ try {
41
+ const destinations = [];
42
+ for (const destConfig of proofingConfig.batchQueue.destinations) {
43
+ if (destConfig.type === 'agentshield') {
44
+ // Only create destination if API key is present and not empty
45
+ if (destConfig.apiKey?.length && destConfig.apiUrl?.length) {
46
+ destinations.push(new AgentShieldProofDestination(destConfig.apiUrl, destConfig.apiKey));
47
+ console.log('[ProofService] Added AgentShield destination:', {
48
+ apiUrl: destConfig.apiUrl,
49
+ hasApiKey: !!destConfig.apiKey,
50
+ });
51
+ }
52
+ else {
53
+ console.warn('[ProofService] Skipping AgentShield destination - missing API key or URL:', {
54
+ hasApiKey: !!destConfig.apiKey,
55
+ hasApiUrl: !!destConfig.apiUrl,
56
+ });
57
+ }
58
+ }
59
+ }
60
+ if (destinations.length > 0) {
61
+ // Create batch queue without timers (Cloudflare Workers compatible)
62
+ // Timers won't work in Workers, so we rely on manual flush() via cron
63
+ this.batchQueue = new ProofBatchQueue({
64
+ destinations,
65
+ maxBatchSize: proofingConfig.batchQueue.maxBatchSize || 10,
66
+ flushIntervalMs: proofingConfig.batchQueue.flushIntervalMs || 5000,
67
+ maxRetries: proofingConfig.batchQueue.maxRetries || 3,
68
+ debug: proofingConfig.batchQueue.debug || false,
69
+ });
70
+ console.log('[ProofService] Batch queue initialized (Cloudflare Workers mode - manual flush via cron):', {
71
+ maxBatchSize: proofingConfig.batchQueue.maxBatchSize || 10,
72
+ flushIntervalMs: proofingConfig.batchQueue.flushIntervalMs || 5000,
73
+ destinations: destinations.length,
74
+ });
75
+ }
76
+ else {
77
+ console.warn('[ProofService] No valid destinations configured - batch queue not initialized');
78
+ // Warn in production if no API key configured
79
+ if (this.config.environment === 'production') {
80
+ console.warn('[ProofService] No AGENTSHIELD_API_KEY configured - proofs will not be submitted');
81
+ }
82
+ }
83
+ }
84
+ catch (error) {
85
+ console.error('[ProofService] Failed to initialize batch queue:', error);
86
+ }
87
+ }
13
88
  }
14
89
  /**
15
90
  * Submit proof to AgentShield API
16
- * Uses the proof.jws directly (full JWS format from CloudflareRuntime)
91
+ * Uses batch queue if available, otherwise falls back to direct submission.
17
92
  *
18
93
  * Also submits optional context for AgentShield dashboard integration.
19
94
  * Context provides plaintext tool/args data while proof provides cryptographic verification.
95
+ *
96
+ * IMPORTANT: First proof is submitted immediately (not batched) to ensure
97
+ * dashboard setup detection works correctly.
20
98
  */
21
99
  async submitProof(proof, context) {
22
100
  if (!proof.jws || !proof.meta) {
23
101
  console.warn('[ProofService] Proof missing jws or meta, skipping submission');
24
102
  return;
25
103
  }
104
+ // Submit first proof immediately for dashboard setup detection
105
+ // This ensures the dashboard can detect the server and tools immediately
106
+ if (!this.firstProofSubmitted && this.batchQueue) {
107
+ console.log('[ProofService] Submitting first proof immediately for dashboard setup detection');
108
+ this.firstProofSubmitted = true;
109
+ // Submit first proof directly, then use batching for subsequent proofs
110
+ await this.submitProofDirect(proof, context);
111
+ return;
112
+ }
113
+ // Use batch queue if available (recommended for batching)
114
+ // Note: In Cloudflare Workers, the queue batches within request context
115
+ // but relies on cron jobs for cross-request flushing
116
+ if (this.batchQueue) {
117
+ try {
118
+ console.log('[ProofService] Enqueuing proof to batch queue:', {
119
+ did: proof.meta.did,
120
+ sessionId: proof.meta.sessionId,
121
+ toolName: context.toolName,
122
+ scopeId: proof.meta.scopeId,
123
+ mcpServerUrl: context.mcpServerUrl || 'not-set',
124
+ });
125
+ // Enqueue proof - batch queue will auto-flush when batch size is reached
126
+ this.batchQueue.enqueue(proof);
127
+ return;
128
+ }
129
+ catch (error) {
130
+ console.error('[ProofService] Failed to enqueue proof, falling back to direct submission:', error);
131
+ // Fall through to direct submission
132
+ }
133
+ }
134
+ // Fallback to direct submission if batch queue not available
135
+ await this.submitProofDirect(proof, context);
136
+ }
137
+ /**
138
+ * Direct proof submission (fallback when batch queue not available)
139
+ */
140
+ async submitProofDirect(proof, context) {
26
141
  // Get AgentShield config from proofing config
27
142
  const proofingConfig = this.config.proofing;
28
143
  if (!proofingConfig?.enabled || !proofingConfig.batchQueue?.destinations) {
@@ -32,11 +147,22 @@ export class ProofService {
32
147
  // Find AgentShield destination
33
148
  const agentShieldDest = proofingConfig.batchQueue.destinations.find((dest) => dest.type === 'agentshield' && dest.apiKey);
34
149
  if (!agentShieldDest || !agentShieldDest.apiKey || !agentShieldDest.apiUrl) {
35
- console.log('[ProofService] No AgentShield destination configured');
150
+ console.log('[ProofService] No AgentShield destination configured:', {
151
+ hasDestinations: !!(proofingConfig.batchQueue.destinations?.length),
152
+ foundDest: !!agentShieldDest,
153
+ hasApiKey: !!agentShieldDest?.apiKey,
154
+ hasApiUrl: !!agentShieldDest?.apiUrl,
155
+ });
36
156
  return;
37
157
  }
38
158
  const apiUrl = agentShieldDest.apiUrl;
39
159
  const apiKey = agentShieldDest.apiKey;
160
+ // Log API key presence (not value) for debugging
161
+ console.log('[ProofService] Direct submission config:', {
162
+ apiUrl,
163
+ hasApiKey: !!apiKey,
164
+ apiKeyLength: apiKey?.length || 0,
165
+ });
40
166
  // Get tool call context from runtime (if available)
41
167
  const toolCallContext = this.runtime?.getLastToolCallContext();
42
168
  // Proof already has correct format from CloudflareRuntime
@@ -67,28 +193,95 @@ export class ProofService {
67
193
  jwsFormat: proof.jws.split('.').length === 3 ? 'valid (3 parts)' : 'invalid',
68
194
  contextTool: requestBody.context.toolCalls[0]?.tool,
69
195
  contextScopeId: requestBody.context.toolCalls[0]?.scopeId,
70
- mcpServerUrl: requestBody.context.mcpServerUrl || 'not-set'
196
+ mcpServerUrl: requestBody.context.mcpServerUrl || 'not-set',
197
+ requestBodySize: JSON.stringify(requestBody).length,
71
198
  });
72
- const response = await fetch(`${apiUrl}/api/v1/bouncer/proofs`, {
73
- method: 'POST',
74
- headers: {
75
- 'Content-Type': 'application/json',
76
- 'Authorization': `Bearer ${apiKey}`
77
- },
78
- body: JSON.stringify(requestBody)
79
- });
80
- if (!response.ok) {
81
- const errorText = await response.text();
82
- console.error('[ProofService] Submission failed:', response.status, errorText);
83
- throw new Error(`AgentShield error: ${response.status}`);
199
+ try {
200
+ const response = await fetch(`${apiUrl}/api/v1/bouncer/proofs`, {
201
+ method: 'POST',
202
+ headers: {
203
+ 'Content-Type': 'application/json',
204
+ 'Authorization': `Bearer ${apiKey}`
205
+ },
206
+ body: JSON.stringify(requestBody)
207
+ });
208
+ const responseText = await response.text();
209
+ if (!response.ok) {
210
+ console.error('[ProofService] Submission failed:', {
211
+ status: response.status,
212
+ statusText: response.statusText,
213
+ response: responseText.substring(0, 500), // Limit response size in logs
214
+ });
215
+ throw new Error(`AgentShield error: ${response.status}`);
216
+ }
217
+ let responseData;
218
+ try {
219
+ responseData = JSON.parse(responseText);
220
+ }
221
+ catch (parseError) {
222
+ console.error('[ProofService] Failed to parse response:', {
223
+ responseText: responseText.substring(0, 500),
224
+ error: parseError,
225
+ });
226
+ throw new Error('Invalid JSON response from AgentShield');
227
+ }
228
+ console.log('[ProofService] Response:', {
229
+ success: responseData.success,
230
+ received: responseData.received,
231
+ processed: responseData.processed,
232
+ accepted: responseData.accepted,
233
+ rejected: responseData.rejected,
234
+ errors: responseData.errors?.length || 0,
235
+ });
236
+ if (responseData.accepted) {
237
+ console.log('[ProofService] ✅ Proofs accepted:', responseData.accepted);
238
+ }
239
+ if (responseData.rejected) {
240
+ console.log('[ProofService] ❌ Proofs rejected:', responseData.rejected);
241
+ }
242
+ if (responseData.errors && responseData.errors.length > 0) {
243
+ console.error('[ProofService] Proof errors:', responseData.errors);
244
+ }
84
245
  }
85
- const responseData = await response.json();
86
- console.log('[ProofService] Response:', responseData);
87
- if (responseData.accepted) {
88
- console.log('[ProofService] Proofs accepted:', responseData.accepted);
246
+ catch (error) {
247
+ console.error('[ProofService] Submission error:', {
248
+ error: error instanceof Error ? error.message : String(error),
249
+ stack: error instanceof Error ? error.stack : undefined,
250
+ });
251
+ throw error;
89
252
  }
90
- if (responseData.rejected) {
91
- console.log('[ProofService] ❌ Proofs rejected:', responseData.rejected);
253
+ }
254
+ /**
255
+ * Flush pending proofs in batch queue
256
+ *
257
+ * Called by scheduled cron job (configured in wrangler.toml).
258
+ *
259
+ * Cron Configuration:
260
+ * Add this to your wrangler.toml to enable automatic proof flushing:
261
+ *
262
+ * [triggers.crons]
263
+ * cron = "every 5 minutes" # Flush proof batches every 5 minutes
264
+ *
265
+ * The cron job will call the scheduled handler exported from your Worker,
266
+ * which routes to MCPICloudflareServer.handleScheduled(), which then calls
267
+ * this flush() method.
268
+ *
269
+ * Why cron instead of timers?
270
+ * - Cloudflare Workers are stateless and don't persist timers across requests
271
+ * - Cron jobs provide reliable cross-request batching
272
+ * - Proofs are still batched within requests (auto-flush when batch size reached)
273
+ *
274
+ * Flush frequency:
275
+ * - Default: Every minute (adjustable in wrangler.toml)
276
+ * - Proofs are also flushed immediately when batch size is reached
277
+ * - Failed proofs are retried with exponential backoff
278
+ */
279
+ async flush() {
280
+ if (this.batchQueue) {
281
+ console.log('[ProofService] Flushing batch queue...');
282
+ await this.batchQueue.flush();
283
+ // Also retry any pending batches
284
+ await this.batchQueue.retryPending();
92
285
  }
93
286
  }
94
287
  }
@@ -1 +1 @@
1
- {"version":3,"file":"proof.service.js","sourceRoot":"","sources":["../../src/services/proof.service.ts"],"names":[],"mappings":"AAAA;;;;;GAKG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,MAAM,CAAC,CAAC;YACrE,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE;gBAChD,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC7D,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;aACxD,CAAC,CAAC;YACH,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,OAAO,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;YACtD,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;YAC9B,iCAAiC;YACjC,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC;QACvC,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Transport Detection Service
3
+ *
4
+ * Detects the transport type (HTTP, SSE, STDIO) and determines the appropriate
5
+ * consent strategy (server-hosted vs dashboard-hosted).
6
+ *
7
+ * Related Spec: MCP-I Phase 0 Implementation Plan, Task B.2
8
+ */
9
+ export type TransportType = 'http' | 'sse' | 'stdio';
10
+ export type ConsentStrategy = 'server-hosted' | 'dashboard-hosted';
11
+ /**
12
+ * Transport Service
13
+ *
14
+ * Provides utilities for detecting transport type and determining consent strategy
15
+ */
16
+ export declare class TransportService {
17
+ /**
18
+ * Detect the current transport type
19
+ *
20
+ * Detection logic:
21
+ * - Cloudflare Workers: Always HTTP capable (Request/Response available)
22
+ * - STDIO transport: process.stdin/stdout available (no HTTP server)
23
+ * - Default: HTTP (most common)
24
+ *
25
+ * @returns Detected transport type
26
+ */
27
+ static detectTransport(): TransportType;
28
+ /**
29
+ * Get consent strategy based on transport type
30
+ *
31
+ * Strategy selection:
32
+ * - STDIO: dashboard-hosted (can't serve HTTP pages)
33
+ * - HTTP/SSE: server-hosted (can serve consent pages)
34
+ *
35
+ * @param transport - Optional transport type (auto-detected if not provided)
36
+ * @returns Consent strategy
37
+ */
38
+ static getConsentStrategy(transport?: TransportType): ConsentStrategy;
39
+ /**
40
+ * Check if server-hosted consent is available
41
+ *
42
+ * @param transport - Optional transport type (auto-detected if not provided)
43
+ * @returns true if server-hosted consent is available
44
+ */
45
+ static canServeConsentPage(transport?: TransportType): boolean;
46
+ }
47
+ //# sourceMappingURL=transport.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.service.d.ts","sourceRoot":"","sources":["../../src/services/transport.service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC;AACrD,MAAM,MAAM,eAAe,GAAG,eAAe,GAAG,kBAAkB,CAAC;AAEnE;;;;GAIG;AACH,qBAAa,gBAAgB;IAC3B;;;;;;;;;OASG;IACH,MAAM,CAAC,eAAe,IAAI,aAAa;IA2BvC;;;;;;;;;OASG;IACH,MAAM,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAAE,aAAa,GAAG,eAAe;IAYrE;;;;;OAKG;IACH,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE,aAAa,GAAG,OAAO;CAG/D"}