@kya-os/mcp-i
Version:
The TypeScript MCP framework with identity features built-in
121 lines (120 loc) • 3.25 kB
TypeScript
/**
* Proof Batch Queue
*
* Collects proofs in memory and submits them in batches to KTA and AgentShield.
* This prevents blocking tool execution while ensuring proofs are eventually submitted.
*
* Performance:
* - Batch size: 10 proofs (configurable)
* - Flush interval: 5 seconds (configurable)
* - Fire-and-forget submission (doesn't block tool execution)
*
* Retry Strategy:
* - Exponential backoff: 1s, 2s, 4s, 8s, 16s
* - Max retries: 5
* - Failed proofs logged and dropped after max retries
*
* Related: PHASE_1_XMCP_I_SERVER.md Epic 3 (Proof Batching)
*/
import { DetachedProof } from '@kya-os/contracts/proof';
/**
* Proof submission destination
*/
export interface ProofDestination {
/** Destination name (for logging) */
name: string;
/** Submit batch of proofs */
submit(proofs: DetachedProof[]): Promise<void>;
}
/**
* KTA proof submission destination
*/
export declare class KTAProofDestination implements ProofDestination {
name: string;
private apiUrl;
private apiKey?;
constructor(apiUrl: string, apiKey?: string);
submit(proofs: DetachedProof[]): Promise<void>;
}
/**
* AgentShield proof submission destination
*
* Submits proofs to AgentShield's /api/v1/bouncer/proofs endpoint
* with proper authentication and session grouping.
*/
export declare class AgentShieldProofDestination implements ProofDestination {
name: string;
private apiUrl;
private apiKey;
constructor(apiUrl: string, apiKey: string);
submit(proofs: DetachedProof[]): Promise<void>;
}
/**
* Proof batch queue configuration
*/
export interface ProofBatchQueueConfig {
/** Destinations to submit proofs to */
destinations: ProofDestination[];
/** Maximum batch size (default: 10) */
maxBatchSize?: number;
/** Flush interval in milliseconds (default: 5000 = 5 seconds) */
flushIntervalMs?: number;
/** Maximum retries per batch (default: 5) */
maxRetries?: number;
/** Enable debug logging */
debug?: boolean;
}
/**
* Proof Batch Queue
*
* Collects proofs and submits them in batches to multiple destinations
*/
export declare class ProofBatchQueue {
private queue;
private pendingBatches;
private config;
private flushTimer?;
private retryTimer?;
private closed;
private stats;
constructor(config: ProofBatchQueueConfig);
/**
* Add proof to queue
*/
enqueue(proof: DetachedProof): void;
/**
* Flush queue immediately (submit all queued proofs)
*/
flush(): Promise<void>;
/**
* Submit batch to destination (with retries)
*/
private submitBatch;
/**
* Start flush timer
*/
private startFlushTimer;
/**
* Start retry timer
*/
private startRetryTimer;
/**
* Close queue and flush remaining proofs
*/
close(): Promise<void>;
/**
* Get queue statistics
*/
getStats(): {
queueSize: number;
pendingBatches: number;
queued: number;
submitted: number;
failed: number;
batchesSubmitted: number;
};
}
/**
* Create proof batch queue from config
*/
export declare function createProofBatchQueue(config: ProofBatchQueueConfig): ProofBatchQueue;