@hivetechs/hive-ai
Version:
Real-time streaming AI consensus platform with HTTP+SSE MCP integration for Claude Code, VS Code, Cursor, and Windsurf - powered by OpenRouter's unified API
103 lines (102 loc) • 3.12 kB
TypeScript
/**
* Conversation Gateway - D1 Backend Communication
*
* Handles secure communication with Cloudflare D1 backend for:
* - Pre-conversation authorization and usage validation
* - Post-conversation verification and usage reporting
* - License key validation and user profile fetching
*/
export interface ConversationAuthorization {
conversationToken: string;
questionHash: string;
userId: string;
remaining: number;
limit: number;
expiresAt: Date;
}
export interface UserProfile {
userId: string;
email: string;
tier: string;
dailyLimit: number;
features: string[];
isValid: boolean;
}
export interface ConversationVerification {
verified: boolean;
remainingConversations: number;
usageUpdated: boolean;
}
/**
* Gateway for secure D1 backend communication
*/
export declare class ConversationGateway {
private apiUrl;
constructor();
/**
* Request conversation authorization from D1 backend
* This is called BEFORE starting any consensus pipeline
*/
requestConversationAuthorization(question: string): Promise<ConversationAuthorization>;
/**
* Report conversation completion to D1 backend
* This is called AFTER successful consensus pipeline completion
*/
reportConversationCompletion(conversationToken: string, conversationId: string, questionHash: string): Promise<ConversationVerification>;
/**
* Validate license key against D1 backend and fetch user profile
* This is called during license configuration
*/
validateLicenseKey(licenseKey: string): Promise<UserProfile>;
/**
* Get quick usage status without full authorization
* Used for status displays
*/
getQuickUsageStatus(): Promise<{
remaining: number;
limit: number;
} | null>;
/**
* Generate a hash of the question for verification
*/
private generateQuestionHash;
/**
* Generate HMAC proof of conversation completion
*/
private generateUsageProof;
/**
* Check if a conversation token is expired
*/
isTokenExpired(expiresAt: Date | string): boolean;
/**
* Get installation ID from device/machine fingerprinting
*/
private getInstallationId;
/**
* Get device fingerprint for security validation
*/
private getDeviceFingerprint;
}
/**
* Custom error class for conversation gateway failures
*/
export declare class ConversationGatewayError extends Error {
code: string;
details: any;
constructor(message: string, code: string, details?: any);
}
/**
* Custom error class for usage limit exceeded
*/
export declare class UsageLimitExceededError extends Error {
used: number;
limit: number;
plan: string;
constructor(message: string, used: number, limit: number, plan: string);
getFormattedMessage(): string;
/**
* Attempt automatic license refresh before showing error
*/
static handleWithAutoRefresh(error: UsageLimitExceededError): Promise<'retry' | 'show_error'>;
}
export declare const conversationGateway: ConversationGateway;