fix: increase x402 payment timeout to 5min and add 402 re-sign logic

AI inference (especially DeepSeek) often exceeds the default 120s HTTP
timeout, causing the client to disconnect while the server completes
successfully — resulting in repeated payments on each retry.

Changes:
- Set X402Timeout = 5min for all x402 providers (Claw402, BlockRunBase, BlockRunSol)
- Handle 402 during payment retry by re-extracting Payment-Required
  header and re-signing instead of failing immediately
- Increase payment retry attempts from 3 to 5 for unstable gateways
This commit is contained in:
tinkle-community
2026-03-12 14:06:28 +08:00
parent fcda921d41
commit b5061d1b8f
4 changed files with 42 additions and 9 deletions

View File

@@ -52,6 +52,7 @@ func NewBlockRunSolClientWithOptions(opts ...mcp.ClientOption) mcp.AIClient {
mcp.WithProvider(mcp.ProviderBlockRunSol),
mcp.WithModel(DefaultBlockRunModel),
mcp.WithBaseURL(DefaultBlockRunSolURL),
mcp.WithTimeout(X402Timeout),
}
allOpts := append(baseOpts, opts...)
baseClient := mcp.NewClient(allOpts...).(*mcp.Client)