refactor: restructure project directories for better modularity

- Delete llm/ dead code (3 files, zero references)
- Split mcp/ into sub-packages: mcp/provider/ (8 providers) and
  mcp/payment/ (4 payment clients) with registry pattern
- Export Client internal fields and ClientHooks interface for
  sub-package access
- Split api/server.go (3892 lines) into 8 domain-specific handler files
- Split trader/auto_trader.go (2296 lines) into 5 focused files
- Reorganize web/src/components/ flat files into auth/, charts/,
  trader/, common/, modals/, backtest/ subdirectories
- Update all consumer imports to use registry-based provider creation
This commit is contained in:
tinkle-community
2026-03-11 23:58:13 +08:00
parent 6a30e11ee5
commit 8e294a5eed
103 changed files with 6391 additions and 8984 deletions

37
mcp/hooks.go Normal file
View File

@@ -0,0 +1,37 @@
package mcp
import "net/http"
// ClientHooks is the dispatch interface used to implement per-provider
// polymorphism without Go's lack of virtual methods.
//
// Each method can be overridden by an embedding struct (e.g. provider.ClaudeClient).
// The base *Client provides OpenAI-compatible defaults; providers with a
// different wire format (Anthropic, Gemini native, etc.) override only what
// differs. All call-path methods in client.go invoke these via c.Hooks so
// that the override is always picked up at runtime.
type ClientHooks interface {
// ── Simple CallWithMessages path ────────────────────────────────────────
Call(systemPrompt, userPrompt string) (string, error)
BuildMCPRequestBody(systemPrompt, userPrompt string) map[string]any
// ── Shared request plumbing ─────────────────────────────────────────────
BuildUrl() string
BuildRequest(url string, jsonData []byte) (*http.Request, error)
SetAuthHeader(reqHeaders http.Header)
MarshalRequestBody(requestBody map[string]any) ([]byte, error)
// ── Advanced (Request-object) path ──────────────────────────────────────
// BuildRequestBodyFromRequest converts a *Request into the provider's
// native wire-format map.
BuildRequestBodyFromRequest(req *Request) map[string]any
// ParseMCPResponse extracts the plain-text reply from a non-streaming
// response body.
ParseMCPResponse(body []byte) (string, error)
// ParseMCPResponseFull extracts both text and tool calls.
ParseMCPResponseFull(body []byte) (*LLMResponse, error)
IsRetryableError(err error) bool
}