/** Smart service discovery + payment routing with fallback. * * Combines discoverServices → fetch402 into one operation with automatic * fallback to alternative services on failure. This is a pure routing layer — * reputation feedback is handled by AzethKit, which has access to the * SmartAccountClient required for on-chain opinion submission. */ import type { PublicClient, WalletClient, Chain, Transport, Account } from 'viem'; import { type RegistryEntry, type EntityType, type SupportedChainName } from '@azeth/common'; import { type Fetch402Options, type Fetch402Result } from './x402.js'; import { type ResolvedCatalogEntry } from './catalog-resolve.js'; /** Options for smartFetch402 */ export interface SmartFetch402Options extends Fetch402Options { /** Minimum reputation score to consider (0-100). Default: 0 */ minReputation?: number; /** Maximum services to try before giving up. Default: 3 */ maxRetries?: number; /** Whether to submit reputation feedback after the call. Default: true. * Only effective when called via AzethKit (which owns the SmartAccountClient). */ autoFeedback?: boolean; /** Entity type filter (e.g., 'service'). Default: undefined (any) */ entityType?: EntityType; /** Preferred service tokenId — tried first if available in results */ preferredService?: bigint; /** Loose intent tokens for catalog navigation (e.g. ["bitcoin"]). When a discovered provider * serves a catalog, these are matched deterministically against the catalog's param value * enums to pick the concrete priced route — no model in the loop. (F6) */ intent?: string[]; /** Structured param overrides for catalog navigation (e.g. {coinId:"bitcoin"}); precise, and * take precedence over `intent`. (F6) */ params?: Record; } /** Result from smartFetch402 including routing metadata */ export interface SmartFetch402Result extends Fetch402Result { /** The service that was successfully called */ service: RegistryEntry; /** Number of services attempted before success */ attemptsCount: number; /** Services that failed (for debugging) */ failedServices?: Array<{ service: RegistryEntry; error: string; }>; /** When catalog navigation resolved an intent to a concrete priced route, the receipt of what * was bought (the entry, the bound params, the concrete URL). (F6) */ resolved?: ResolvedCatalogEntry; } /** Compute reputation feedback value from response time. * * Maps response latency to a 0-100 quality score: * - < 200ms → 90 (excellent) * - < 500ms → 70 (good) * - < 2000ms → 50 (acceptable) * - >= 2000ms → 30 (slow) */ export declare function computeFeedbackValue(responseTimeMs: number): number; /** Penalty value for services that failed outright */ export declare const FAILURE_PENALTY_VALUE = -20; /** Would paying this NON-CATALOG provider's fixed route satisfy the agent's intent? (N1) * * A provider without a catalog exposes a single fixed priced route (e.g. `/pricing/ethereum`). * We can only pay it if the asset the agent named is actually encoded in the route being paid — * matched against the endpoint's PATH and query values (NOT the free-text description, which may * advertise many assets the fixed endpoint does not serve — that conflation is exactly what made * smart_pay buy Ethereum for a "dogecoin" intent). At least one intent/param word must overlap * the route. No overlap → never pay (the agent gets options instead). This keeps the fix UNIVERSAL: * a non-catalog `/pricing/ethereum` is paid for intent "ethereum", but never for "dogecoin". */ export declare function intentMatchesProvider(intent: string[] | undefined, params: Record | undefined, service: Pick): boolean; /** Smart discovery and payment routing with fallback. * * This is a pure routing function — it discovers services, tries them in * reputation order, and falls back on failure. It does NOT submit reputation * feedback (that requires a SmartAccountClient, which only AzethKit owns). * * @param publicClient - viem public client for chain reads * @param walletClient - viem wallet client for signing * @param account - EOA address * @param serverUrl - Azeth server URL for discovery * @param capability - Service capability to discover (e.g., 'price-feed') * @param options - Smart fetch options * @returns SmartFetch402Result with the successful service and attempt metadata */ export declare function smartFetch402(publicClient: PublicClient, walletClient: WalletClient, account: `0x${string}`, serverUrl: string, capability: string, options?: SmartFetch402Options, /** Chain name for on-chain fallback discovery */ chainName?: SupportedChainName): Promise; //# sourceMappingURL=smart-fetch.d.ts.map