feat(hermes): dynamically load provider registry in setup & dashboard (Step 2)

Wire the new Rust `hermes_list_providers` command into the frontend and
replace the hardcoded OpenClaw PROVIDER_PRESETS usage with the
authoritative Hermes registry. Closes the G4 gap from the v3 design.

New module `src/engines/hermes/lib/providers.js`:
- Async `loadHermesProviders()` with per-session cache.
- `groupProviders()` buckets by authType + region: apiKeyIntl,
  apiKeyCn, aggregators, oauth, externalProc, custom.
- Lookup helpers: `findProviderById`, `inferProviderByBaseUrl`,
  `defaultModelFor`, plus cache reset for hot-reload scenarios.
- Exported auth_type / transport string constants mirroring Rust.

Refactored `src/engines/hermes/pages/setup.js`:
- Drops `PROVIDER_PRESETS` import; loads registry before first paint.
- Provider buttons are grouped under labeled sections (International,
  China, Aggregators), with an OAuth hint block listing the CLI
  commands users must run (e.g. `hermes auth login nous`).
- Selected provider detail panel now shows target env var
  (`ANTHROPIC_API_KEY`, `DEEPSEEK_API_KEY`, etc.) and model catalog
  size.
- `doSaveConfig` sends the provider id (not preset key) through
  `api.configureHermes`; falls back to `custom` when the base URL
  doesn't match any registered provider.
- `doFetchModels` maps provider.transport → apiType.
- Graceful fallback: when the registry is empty (Web mode), UI
  degrades to manual Base URL + API Key entry.

Refactored `src/engines/hermes/pages/dashboard.js`:
- Loads provider registry in parallel with gateway refresh.
- Preset buttons filter out the `custom` placeholder and source
  data from the async-loaded list.
- Uses `inferProviderByBaseUrl` consistently for highlight / fetch /
  save flows.

Frontend API wiring:
- `src/lib/tauri-api.js`:
  - Added `hermesListProviders` (10-minute cache).
  - Extended `hermesFetchModels` and `hermesUpdateModel` with
    optional `provider` param.
- `scripts/dev-api.js`:
  - `hermes_list_providers`: Web-mode stub returning [] (triggers
    frontend fallback UI).
  - `hermes_fetch_models` / `hermes_update_model` accept provider
    param (no-op in fetch; full YAML rewrite in update_model matching
    Rust behavior).

Verified: `npm run build` green (1.04s). Setup chunk 24.34 kB,
dashboard chunk 24.30 kB. No new warnings.
This commit is contained in:
晴天
2026-04-24 20:41:06 +08:00
parent 17759fc1e6
commit 42d6758eb4
5 changed files with 363 additions and 46 deletions

View File

@@ -398,8 +398,9 @@ export const api = {
hermesApiProxy: (method, path, body, headers) => invoke('hermes_api_proxy', { method, path, body: body || null, headers: headers || null }),
hermesAgentRun: (input, sessionId, conversationHistory, instructions) => invoke('hermes_agent_run', { input, sessionId: sessionId || null, conversationHistory: conversationHistory || null, instructions: instructions || null }),
hermesReadConfig: () => invoke('hermes_read_config'),
hermesFetchModels: (baseUrl, apiKey, apiType) => invoke('hermes_fetch_models', { baseUrl, apiKey, apiType: apiType || null }),
hermesUpdateModel: (model) => invoke('hermes_update_model', { model }),
hermesFetchModels: (baseUrl, apiKey, apiType, provider) => invoke('hermes_fetch_models', { baseUrl, apiKey, apiType: apiType || null, provider: provider || null }),
hermesUpdateModel: (model, provider) => invoke('hermes_update_model', { model, provider: provider || null }),
hermesListProviders: () => cachedInvoke('hermes_list_providers', {}, 600000),
hermesDetectEnvironments: () => invoke('hermes_detect_environments'),
hermesSetGatewayUrl: (url) => invoke('hermes_set_gateway_url', { url: url || null }),
updateHermes: () => invoke('update_hermes'),