UNPKG

@agentdao/core

Version:

Core functionality, skills, and ready-made UI components for AgentDAO - Web3 subscriptions, content generation, social media, help support, live chat, RSS fetching, web search, and agent pricing integration

254 lines (253 loc) 7.26 kB
import { Web3SubscriptionSkill } from './Web3SubscriptionSkill'; import { Web3SubscriptionConfig, Subscription, SubscriptionStatus, BillingPeriod, RevenueStats } from './types'; export interface EnhancedWeb3SubscriptionConfig extends Web3SubscriptionConfig { mode?: 'basic' | 'advanced'; chains?: { [chainId: number]: { name: string; rpcUrl: string; explorer: string; nativeToken: string; gasLimit?: number; gasPrice?: string; }; }; tokens?: { [tokenAddress: string]: { name: string; symbol: string; decimals: number; chainId: number; logo?: string; priceFeed?: string; }; }; enhancedAnalytics?: { trackRevenue: boolean; trackUsage: boolean; exportData: boolean; realTimeMetrics: boolean; customEvents?: string[]; }; webhooks?: { subscriptionCreated?: string; subscriptionCancelled?: string; paymentProcessed?: string; refundIssued?: string; subscriptionUpgraded?: string; subscriptionDowngraded?: string; trialStarted?: string; trialEnded?: string; }; refunds?: { enabled: boolean; gracePeriod: number; autoRefund: boolean; refundPolicy: 'full' | 'prorated' | 'none'; requireApproval: boolean; }; subscriptionManagement?: { allowUpgrades: boolean; allowDowngrades: boolean; prorationEnabled: boolean; trialPeriod: number; gracePeriod: number; autoRenewal: boolean; }; platformFee?: { percentage: number; safeAddress: string; autoTransfer: boolean; }; } export interface PaymentMethod { type: 'token' | 'native'; address: string; symbol: string; decimals: number; chainId: number; balance: number; priceUSD?: number; } export interface EnhancedSubscription extends Subscription { paymentMethod: PaymentMethod; chainId: number; transactionHash?: string; refundHistory?: RefundRecord[]; upgradeHistory?: UpgradeRecord[]; analytics?: SubscriptionAnalytics; } export interface RefundRecord { id: string; amount: number; reason: string; status: 'pending' | 'approved' | 'rejected' | 'processed'; timestamp: Date; transactionHash?: string; } export interface UpgradeRecord { id: string; fromPlan: string; toPlan: string; fromPeriod: BillingPeriod; toPeriod: BillingPeriod; proratedAmount: number; timestamp: Date; transactionHash?: string; } export interface SubscriptionAnalytics { totalPayments: number; totalRevenue: number; averageSessionDuration: number; featureUsage: { [feature: string]: number; }; churnRate: number; lifetimeValue: number; } export interface WebhookPayload { event: string; subscriptionId: string; userAddress: string; data: any; timestamp: Date; signature?: string; } export interface EnhancedRevenueStats extends RevenueStats { byChain: { [chainId: number]: number; }; byToken: { [tokenAddress: string]: number; }; byPeriod: { [period: string]: number; }; churnRate: number; averageLifetimeValue: number; refundRate: number; upgradeRate: number; } export declare class EnhancedWeb3SubscriptionSkill extends Web3SubscriptionSkill { private enhancedConfig; private webhookQueue; private analyticsCache; /** * Get default configuration for basic mode */ static getDefaultConfig(agentId: string): EnhancedWeb3SubscriptionConfig; constructor(config: EnhancedWeb3SubscriptionConfig); /** * Check if the subscription skill is ready for use */ isReady(): boolean; /** * Check if signer is set */ hasSigner(): boolean; /** * Check if plans are configured */ hasPlans(): boolean; /** * Check if provider is configured */ hasProvider(): boolean; /** * Check if ADAO token is configured */ hasADaoToken(): boolean; /** * Get readiness status with details */ getReadinessStatus(): { ready: boolean; hasSigner: boolean; hasPlans: boolean; hasProvider: boolean; hasADaoToken: boolean; planCount: number; availablePlans: string[]; }; /** * Validate plan exists before processing */ validatePlan(planId: string): boolean; /** * Validate billing period */ validateBillingPeriod(billingPeriod: string): boolean; /** * Validate user address format */ validateUserAddress(userAddress: string): boolean; /** * Enhanced createSubscription with comprehensive validation */ createSubscription(userAddress: string, planId: string, billingPeriod: BillingPeriod): Promise<Subscription>; /** * Enhanced checkSubscription with validation */ checkSubscription(userAddress: string): Promise<SubscriptionStatus>; /** * Get health status with detailed feedback */ getHealthStatus(): { timestamp: string; skill: { ready: boolean; hasSigner: boolean; hasPlans: boolean; hasProvider: boolean; hasADaoToken: boolean; }; config: { agentId: string; agentName: string; mode: "basic" | "advanced"; planCount: number; availablePlans: string[]; }; status: string; missingConfig: string[]; recommendations: string[]; }; /** * Async initialization method for better error handling */ initialize(): Promise<boolean>; /** * Get available payment methods for a user across all chains */ getPaymentMethods(userAddress: string): Promise<PaymentMethod[]>; /** * Create subscription with enhanced features */ createEnhancedSubscription(userAddress: string, planId: string, billingPeriod: BillingPeriod, paymentMethod: PaymentMethod): Promise<EnhancedSubscription>; /** * Upgrade subscription to a higher plan */ upgradeSubscription(userAddress: string, newPlanId: string, newPeriod?: BillingPeriod): Promise<EnhancedSubscription>; /** * Downgrade subscription to a lower plan */ downgradeSubscription(userAddress: string, newPlanId: string, newPeriod?: BillingPeriod): Promise<EnhancedSubscription>; /** * Process refund for a subscription */ processRefund(userAddress: string, amount: number, reason: string): Promise<RefundRecord>; /** * Get enhanced analytics for a subscription */ getEnhancedAnalytics(userAddress: string): Promise<SubscriptionAnalytics>; /** * Get enhanced revenue statistics */ getEnhancedRevenueStats(): Promise<EnhancedRevenueStats>; private sendWebhook; private trackAnalytics; private getDefaultPaymentMethod; private calculateProratedUpgrade; private calculateDowngradeCredit; private calculateEnhancedMonthlyPrice; }